1 // SPDX-License-Identifier: GPL-2.0-only << 2 /* 1 /* 3 * linux/sound/pxa2xx-ac97.c -- AC97 support f 2 * linux/sound/pxa2xx-ac97.c -- AC97 support for the Intel PXA2xx chip. 4 * 3 * 5 * Author: Nicolas Pitre 4 * Author: Nicolas Pitre 6 * Created: Dec 02, 2004 5 * Created: Dec 02, 2004 7 * Copyright: MontaVista Software Inc. 6 * Copyright: MontaVista Software Inc. >> 7 * >> 8 * This program is free software; you can redistribute it and/or modify >> 9 * it under the terms of the GNU General Public License version 2 as >> 10 * published by the Free Software Foundation. 8 */ 11 */ 9 12 10 #include <linux/init.h> 13 #include <linux/init.h> 11 #include <linux/io.h> 14 #include <linux/io.h> 12 #include <linux/module.h> 15 #include <linux/module.h> 13 #include <linux/platform_device.h> 16 #include <linux/platform_device.h> 14 #include <linux/dmaengine.h> 17 #include <linux/dmaengine.h> 15 #include <linux/dma/pxa-dma.h> 18 #include <linux/dma/pxa-dma.h> 16 19 17 #include <sound/ac97/controller.h> << 18 #include <sound/core.h> 20 #include <sound/core.h> 19 #include <sound/ac97_codec.h> 21 #include <sound/ac97_codec.h> 20 #include <sound/soc.h> 22 #include <sound/soc.h> 21 #include <sound/pxa2xx-lib.h> 23 #include <sound/pxa2xx-lib.h> 22 #include <sound/dmaengine_pcm.h> 24 #include <sound/dmaengine_pcm.h> 23 25 24 #include <linux/platform_data/asoc-pxa.h> !! 26 #include <mach/hardware.h> >> 27 #include <mach/regs-ac97.h> >> 28 #include <mach/audio.h> 25 29 26 #define PCDR 0x0040 /* PCM FIFO Data Regis !! 30 #include "pxa2xx-ac97.h" 27 #define MODR 0x0140 /* Modem FIFO Data Reg << 28 #define MCDR 0x0060 /* Mic-in FIFO Data Re << 29 31 30 static void pxa2xx_ac97_warm_reset(struct ac97 !! 32 static void pxa2xx_ac97_warm_reset(struct snd_ac97 *ac97) 31 { 33 { 32 pxa2xx_ac97_try_warm_reset(); !! 34 pxa2xx_ac97_try_warm_reset(ac97); 33 35 34 pxa2xx_ac97_finish_reset(); !! 36 pxa2xx_ac97_finish_reset(ac97); 35 } 37 } 36 38 37 static void pxa2xx_ac97_cold_reset(struct ac97 !! 39 static void pxa2xx_ac97_cold_reset(struct snd_ac97 *ac97) 38 { 40 { 39 pxa2xx_ac97_try_cold_reset(); !! 41 pxa2xx_ac97_try_cold_reset(ac97); 40 << 41 pxa2xx_ac97_finish_reset(); << 42 } << 43 42 44 static int pxa2xx_ac97_read_actrl(struct ac97_ !! 43 pxa2xx_ac97_finish_reset(ac97); 45 unsigned sho << 46 { << 47 return pxa2xx_ac97_read(slot, reg); << 48 } << 49 << 50 static int pxa2xx_ac97_write_actrl(struct ac97 << 51 unsigned sh << 52 { << 53 return pxa2xx_ac97_write(slot, reg, va << 54 } 44 } 55 45 56 static struct ac97_controller_ops pxa2xx_ac97_ !! 46 static struct snd_ac97_bus_ops pxa2xx_ac97_ops = { 57 .read = pxa2xx_ac97_read_actrl, !! 47 .read = pxa2xx_ac97_read, 58 .write = pxa2xx_ac97_write_actrl, !! 48 .write = pxa2xx_ac97_write, 59 .warm_reset = pxa2xx_ac97_warm_res 49 .warm_reset = pxa2xx_ac97_warm_reset, 60 .reset = pxa2xx_ac97_cold_reset, 50 .reset = pxa2xx_ac97_cold_reset, 61 }; 51 }; 62 52 >> 53 static struct pxad_param pxa2xx_ac97_pcm_stereo_in_req = { >> 54 .prio = PXAD_PRIO_LOWEST, >> 55 .drcmr = 11, >> 56 }; >> 57 63 static struct snd_dmaengine_dai_dma_data pxa2x 58 static struct snd_dmaengine_dai_dma_data pxa2xx_ac97_pcm_stereo_in = { >> 59 .addr = __PREG(PCDR), 64 .addr_width = DMA_SLAVE_BUSWIDTH_4 60 .addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES, 65 .chan_name = "pcm_pcm_stereo_in", << 66 .maxburst = 32, 61 .maxburst = 32, >> 62 .filter_data = &pxa2xx_ac97_pcm_stereo_in_req, >> 63 }; >> 64 >> 65 static struct pxad_param pxa2xx_ac97_pcm_stereo_out_req = { >> 66 .prio = PXAD_PRIO_LOWEST, >> 67 .drcmr = 12, 67 }; 68 }; 68 69 69 static struct snd_dmaengine_dai_dma_data pxa2x 70 static struct snd_dmaengine_dai_dma_data pxa2xx_ac97_pcm_stereo_out = { >> 71 .addr = __PREG(PCDR), 70 .addr_width = DMA_SLAVE_BUSWIDTH_4 72 .addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES, 71 .chan_name = "pcm_pcm_stereo_out" << 72 .maxburst = 32, 73 .maxburst = 32, >> 74 .filter_data = &pxa2xx_ac97_pcm_stereo_out_req, 73 }; 75 }; 74 76 >> 77 static struct pxad_param pxa2xx_ac97_pcm_aux_mono_out_req = { >> 78 .prio = PXAD_PRIO_LOWEST, >> 79 .drcmr = 10, >> 80 }; 75 static struct snd_dmaengine_dai_dma_data pxa2x 81 static struct snd_dmaengine_dai_dma_data pxa2xx_ac97_pcm_aux_mono_out = { >> 82 .addr = __PREG(MODR), 76 .addr_width = DMA_SLAVE_BUSWIDTH_2 83 .addr_width = DMA_SLAVE_BUSWIDTH_2_BYTES, 77 .chan_name = "pcm_aux_mono_out", << 78 .maxburst = 16, 84 .maxburst = 16, >> 85 .filter_data = &pxa2xx_ac97_pcm_aux_mono_out_req, 79 }; 86 }; 80 87 >> 88 static struct pxad_param pxa2xx_ac97_pcm_aux_mono_in_req = { >> 89 .prio = PXAD_PRIO_LOWEST, >> 90 .drcmr = 9, >> 91 }; 81 static struct snd_dmaengine_dai_dma_data pxa2x 92 static struct snd_dmaengine_dai_dma_data pxa2xx_ac97_pcm_aux_mono_in = { >> 93 .addr = __PREG(MODR), 82 .addr_width = DMA_SLAVE_BUSWIDTH_2 94 .addr_width = DMA_SLAVE_BUSWIDTH_2_BYTES, 83 .chan_name = "pcm_aux_mono_in", << 84 .maxburst = 16, 95 .maxburst = 16, >> 96 .filter_data = &pxa2xx_ac97_pcm_aux_mono_in_req, 85 }; 97 }; 86 98 >> 99 static struct pxad_param pxa2xx_ac97_pcm_aux_mic_mono_req = { >> 100 .prio = PXAD_PRIO_LOWEST, >> 101 .drcmr = 8, >> 102 }; 87 static struct snd_dmaengine_dai_dma_data pxa2x 103 static struct snd_dmaengine_dai_dma_data pxa2xx_ac97_pcm_mic_mono_in = { >> 104 .addr = __PREG(MCDR), 88 .addr_width = DMA_SLAVE_BUSWIDTH_2 105 .addr_width = DMA_SLAVE_BUSWIDTH_2_BYTES, 89 .chan_name = "pcm_aux_mic_mono", << 90 .maxburst = 16, 106 .maxburst = 16, >> 107 .filter_data = &pxa2xx_ac97_pcm_aux_mic_mono_req, 91 }; 108 }; 92 109 93 static int pxa2xx_ac97_hifi_startup(struct snd 110 static int pxa2xx_ac97_hifi_startup(struct snd_pcm_substream *substream, 94 struct snd 111 struct snd_soc_dai *cpu_dai) 95 { 112 { 96 struct snd_dmaengine_dai_dma_data *dma 113 struct snd_dmaengine_dai_dma_data *dma_data; 97 114 98 if (substream->stream == SNDRV_PCM_STR 115 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) 99 dma_data = &pxa2xx_ac97_pcm_st 116 dma_data = &pxa2xx_ac97_pcm_stereo_out; 100 else 117 else 101 dma_data = &pxa2xx_ac97_pcm_st 118 dma_data = &pxa2xx_ac97_pcm_stereo_in; 102 119 103 snd_soc_dai_set_dma_data(cpu_dai, subs 120 snd_soc_dai_set_dma_data(cpu_dai, substream, dma_data); 104 121 105 return 0; 122 return 0; 106 } 123 } 107 124 108 static int pxa2xx_ac97_aux_startup(struct snd_ 125 static int pxa2xx_ac97_aux_startup(struct snd_pcm_substream *substream, 109 struct snd_ 126 struct snd_soc_dai *cpu_dai) 110 { 127 { 111 struct snd_dmaengine_dai_dma_data *dma 128 struct snd_dmaengine_dai_dma_data *dma_data; 112 129 113 if (substream->stream == SNDRV_PCM_STR 130 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) 114 dma_data = &pxa2xx_ac97_pcm_au 131 dma_data = &pxa2xx_ac97_pcm_aux_mono_out; 115 else 132 else 116 dma_data = &pxa2xx_ac97_pcm_au 133 dma_data = &pxa2xx_ac97_pcm_aux_mono_in; 117 134 118 snd_soc_dai_set_dma_data(cpu_dai, subs 135 snd_soc_dai_set_dma_data(cpu_dai, substream, dma_data); 119 136 120 return 0; 137 return 0; 121 } 138 } 122 139 123 static int pxa2xx_ac97_mic_startup(struct snd_ 140 static int pxa2xx_ac97_mic_startup(struct snd_pcm_substream *substream, 124 struct snd_ 141 struct snd_soc_dai *cpu_dai) 125 { 142 { 126 if (substream->stream == SNDRV_PCM_STR 143 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) 127 return -ENODEV; 144 return -ENODEV; 128 snd_soc_dai_set_dma_data(cpu_dai, subs !! 145 else 129 &pxa2xx_ac97_ !! 146 snd_soc_dai_set_dma_data(cpu_dai, substream, >> 147 &pxa2xx_ac97_pcm_mic_mono_in); 130 148 131 return 0; 149 return 0; 132 } 150 } 133 151 134 #define PXA2XX_AC97_RATES (SNDRV_PCM_RATE_8000 152 #define PXA2XX_AC97_RATES (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_11025 |\ 135 SNDRV_PCM_RATE_16000 | SNDRV_P 153 SNDRV_PCM_RATE_16000 | SNDRV_PCM_RATE_22050 | SNDRV_PCM_RATE_44100 | \ 136 SNDRV_PCM_RATE_48000) 154 SNDRV_PCM_RATE_48000) 137 155 138 static const struct snd_soc_dai_ops pxa_ac97_h 156 static const struct snd_soc_dai_ops pxa_ac97_hifi_dai_ops = { 139 .startup = pxa2xx_ac97_hifi_sta 157 .startup = pxa2xx_ac97_hifi_startup, 140 }; 158 }; 141 159 142 static const struct snd_soc_dai_ops pxa_ac97_a 160 static const struct snd_soc_dai_ops pxa_ac97_aux_dai_ops = { 143 .startup = pxa2xx_ac97_aux_star 161 .startup = pxa2xx_ac97_aux_startup, 144 }; 162 }; 145 163 146 static const struct snd_soc_dai_ops pxa_ac97_m 164 static const struct snd_soc_dai_ops pxa_ac97_mic_dai_ops = { 147 .startup = pxa2xx_ac97_mic_star 165 .startup = pxa2xx_ac97_mic_startup, 148 }; 166 }; 149 167 150 /* 168 /* 151 * There is only 1 physical AC97 interface for 169 * There is only 1 physical AC97 interface for pxa2xx, but it 152 * has extra fifo's that can be used for aux D 170 * has extra fifo's that can be used for aux DACs and ADCs. 153 */ 171 */ 154 static struct snd_soc_dai_driver pxa_ac97_dai_ 172 static struct snd_soc_dai_driver pxa_ac97_dai_driver[] = { 155 { 173 { 156 .name = "pxa2xx-ac97", 174 .name = "pxa2xx-ac97", >> 175 .bus_control = true, 157 .playback = { 176 .playback = { 158 .stream_name = "AC97 Playback" 177 .stream_name = "AC97 Playback", 159 .channels_min = 2, 178 .channels_min = 2, 160 .channels_max = 2, 179 .channels_max = 2, 161 .rates = PXA2XX_AC97_RATES, 180 .rates = PXA2XX_AC97_RATES, 162 .formats = SNDRV_PCM_FMTBIT_S1 181 .formats = SNDRV_PCM_FMTBIT_S16_LE,}, 163 .capture = { 182 .capture = { 164 .stream_name = "AC97 Capture", 183 .stream_name = "AC97 Capture", 165 .channels_min = 2, 184 .channels_min = 2, 166 .channels_max = 2, 185 .channels_max = 2, 167 .rates = PXA2XX_AC97_RATES, 186 .rates = PXA2XX_AC97_RATES, 168 .formats = SNDRV_PCM_FMTBIT_S1 187 .formats = SNDRV_PCM_FMTBIT_S16_LE,}, 169 .ops = &pxa_ac97_hifi_dai_ops, 188 .ops = &pxa_ac97_hifi_dai_ops, 170 }, 189 }, 171 { 190 { 172 .name = "pxa2xx-ac97-aux", 191 .name = "pxa2xx-ac97-aux", >> 192 .bus_control = true, 173 .playback = { 193 .playback = { 174 .stream_name = "AC97 Aux Playb 194 .stream_name = "AC97 Aux Playback", 175 .channels_min = 1, 195 .channels_min = 1, 176 .channels_max = 1, 196 .channels_max = 1, 177 .rates = PXA2XX_AC97_RATES, 197 .rates = PXA2XX_AC97_RATES, 178 .formats = SNDRV_PCM_FMTBIT_S1 198 .formats = SNDRV_PCM_FMTBIT_S16_LE,}, 179 .capture = { 199 .capture = { 180 .stream_name = "AC97 Aux Captu 200 .stream_name = "AC97 Aux Capture", 181 .channels_min = 1, 201 .channels_min = 1, 182 .channels_max = 1, 202 .channels_max = 1, 183 .rates = PXA2XX_AC97_RATES, 203 .rates = PXA2XX_AC97_RATES, 184 .formats = SNDRV_PCM_FMTBIT_S1 204 .formats = SNDRV_PCM_FMTBIT_S16_LE,}, 185 .ops = &pxa_ac97_aux_dai_ops, 205 .ops = &pxa_ac97_aux_dai_ops, 186 }, 206 }, 187 { 207 { 188 .name = "pxa2xx-ac97-mic", 208 .name = "pxa2xx-ac97-mic", >> 209 .bus_control = true, 189 .capture = { 210 .capture = { 190 .stream_name = "AC97 Mic Captu 211 .stream_name = "AC97 Mic Capture", 191 .channels_min = 1, 212 .channels_min = 1, 192 .channels_max = 1, 213 .channels_max = 1, 193 .rates = PXA2XX_AC97_RATES, 214 .rates = PXA2XX_AC97_RATES, 194 .formats = SNDRV_PCM_FMTBIT_S1 215 .formats = SNDRV_PCM_FMTBIT_S16_LE,}, 195 .ops = &pxa_ac97_mic_dai_ops, 216 .ops = &pxa_ac97_mic_dai_ops, 196 }, 217 }, 197 }; 218 }; 198 219 199 static const struct snd_soc_component_driver p 220 static const struct snd_soc_component_driver pxa_ac97_component = { 200 .name = "pxa-ac97", 221 .name = "pxa-ac97", 201 .pcm_construct = pxa2xx_soc_pcm_new, << 202 .open = pxa2xx_soc_pcm_open, << 203 .close = pxa2xx_soc_pcm_close << 204 .hw_params = pxa2xx_soc_pcm_hw_pa << 205 .prepare = pxa2xx_soc_pcm_prepa << 206 .trigger = pxa2xx_soc_pcm_trigg << 207 .pointer = pxa2xx_soc_pcm_point << 208 }; << 209 << 210 #ifdef CONFIG_OF << 211 static const struct of_device_id pxa2xx_ac97_d << 212 { .compatible = "marvell,pxa250-ac97", << 213 { .compatible = "marvell,pxa270-ac97", << 214 { .compatible = "marvell,pxa300-ac97", << 215 { } << 216 }; 222 }; 217 MODULE_DEVICE_TABLE(of, pxa2xx_ac97_dt_ids); << 218 << 219 #endif << 220 223 221 static int pxa2xx_ac97_dev_probe(struct platfo 224 static int pxa2xx_ac97_dev_probe(struct platform_device *pdev) 222 { 225 { 223 int ret; 226 int ret; 224 struct ac97_controller *ctrl; << 225 pxa2xx_audio_ops_t *pdata = pdev->dev. << 226 struct resource *regs; << 227 void **codecs_pdata; << 228 227 229 if (pdev->id != -1) { 228 if (pdev->id != -1) { 230 dev_err(&pdev->dev, "PXA2xx ha 229 dev_err(&pdev->dev, "PXA2xx has only one AC97 port.\n"); 231 return -ENXIO; 230 return -ENXIO; 232 } 231 } 233 232 234 regs = platform_get_resource(pdev, IOR << 235 if (!regs) << 236 return -ENXIO; << 237 << 238 pxa2xx_ac97_pcm_stereo_in.addr = regs- << 239 pxa2xx_ac97_pcm_stereo_out.addr = regs << 240 pxa2xx_ac97_pcm_aux_mono_out.addr = re << 241 pxa2xx_ac97_pcm_aux_mono_in.addr = reg << 242 pxa2xx_ac97_pcm_mic_mono_in.addr = reg << 243 << 244 ret = pxa2xx_ac97_hw_probe(pdev); 233 ret = pxa2xx_ac97_hw_probe(pdev); 245 if (ret) { 234 if (ret) { 246 dev_err(&pdev->dev, "PXA2xx AC 235 dev_err(&pdev->dev, "PXA2xx AC97 hw probe error (%d)\n", ret); 247 return ret; 236 return ret; 248 } 237 } 249 238 250 codecs_pdata = pdata ? pdata->codec_pd !! 239 ret = snd_soc_set_ac97_ops(&pxa2xx_ac97_ops); 251 ctrl = snd_ac97_controller_register(&p !! 240 if (ret != 0) 252 AC !! 241 return ret; 253 co << 254 if (IS_ERR(ctrl)) << 255 return PTR_ERR(ctrl); << 256 242 257 platform_set_drvdata(pdev, ctrl); << 258 /* Punt most of the init to the SoC pr 243 /* Punt most of the init to the SoC probe; we may need the machine 259 * driver to do interesting things wit 244 * driver to do interesting things with the clocking to get us up 260 * and running. 245 * and running. 261 */ 246 */ 262 return devm_snd_soc_register_component !! 247 return snd_soc_register_component(&pdev->dev, &pxa_ac97_component, 263 pxa_ 248 pxa_ac97_dai_driver, ARRAY_SIZE(pxa_ac97_dai_driver)); 264 } 249 } 265 250 266 static void pxa2xx_ac97_dev_remove(struct plat !! 251 static int pxa2xx_ac97_dev_remove(struct platform_device *pdev) 267 { 252 { 268 struct ac97_controller *ctrl = platfor !! 253 snd_soc_unregister_component(&pdev->dev); 269 !! 254 snd_soc_set_ac97_ops(NULL); 270 snd_ac97_controller_unregister(ctrl); << 271 pxa2xx_ac97_hw_remove(pdev); 255 pxa2xx_ac97_hw_remove(pdev); >> 256 return 0; 272 } 257 } 273 258 >> 259 #ifdef CONFIG_PM_SLEEP 274 static int pxa2xx_ac97_dev_suspend(struct devi 260 static int pxa2xx_ac97_dev_suspend(struct device *dev) 275 { 261 { 276 return pxa2xx_ac97_hw_suspend(); 262 return pxa2xx_ac97_hw_suspend(); 277 } 263 } 278 264 279 static int pxa2xx_ac97_dev_resume(struct devic 265 static int pxa2xx_ac97_dev_resume(struct device *dev) 280 { 266 { 281 return pxa2xx_ac97_hw_resume(); 267 return pxa2xx_ac97_hw_resume(); 282 } 268 } 283 269 284 static DEFINE_SIMPLE_DEV_PM_OPS(pxa2xx_ac97_pm !! 270 static SIMPLE_DEV_PM_OPS(pxa2xx_ac97_pm_ops, 285 pxa2xx_ac97_dev_suspend, pxa2x 271 pxa2xx_ac97_dev_suspend, pxa2xx_ac97_dev_resume); >> 272 #endif 286 273 287 static struct platform_driver pxa2xx_ac97_driv 274 static struct platform_driver pxa2xx_ac97_driver = { 288 .probe = pxa2xx_ac97_dev_prob 275 .probe = pxa2xx_ac97_dev_probe, 289 .remove = pxa2xx_ac97_dev_remo 276 .remove = pxa2xx_ac97_dev_remove, 290 .driver = { 277 .driver = { 291 .name = "pxa2xx-ac97", 278 .name = "pxa2xx-ac97", >> 279 #ifdef CONFIG_PM_SLEEP 292 .pm = &pxa2xx_ac97_pm_ops, 280 .pm = &pxa2xx_ac97_pm_ops, 293 .of_match_table = of_match_ptr !! 281 #endif 294 }, 282 }, 295 }; 283 }; 296 284 297 module_platform_driver(pxa2xx_ac97_driver); 285 module_platform_driver(pxa2xx_ac97_driver); 298 286 299 MODULE_AUTHOR("Nicolas Pitre"); 287 MODULE_AUTHOR("Nicolas Pitre"); 300 MODULE_DESCRIPTION("AC97 driver for the Intel 288 MODULE_DESCRIPTION("AC97 driver for the Intel PXA2xx chip"); 301 MODULE_LICENSE("GPL"); 289 MODULE_LICENSE("GPL"); 302 MODULE_ALIAS("platform:pxa2xx-ac97"); 290 MODULE_ALIAS("platform:pxa2xx-ac97"); 303 291
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.