1 /* 2 * linux/sound/pxa2xx-ac97.c -- AC97 support for the Intel PXA2xx chip. 3 * 4 * Author: Nicolas Pitre 5 * Created: Dec 02, 2004 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. 11 */ 12 13 #include <linux/init.h> 14 #include <linux/io.h> 15 #include <linux/module.h> 16 #include <linux/platform_device.h> 17 #include <linux/dmaengine.h> 18 #include <linux/dma/pxa-dma.h> 19 20 #include <sound/core.h> 21 #include <sound/ac97_codec.h> 22 #include <sound/soc.h> 23 #include <sound/pxa2xx-lib.h> 24 #include <sound/dmaengine_pcm.h> 25 26 #include <mach/hardware.h> 27 #include <mach/regs-ac97.h> 28 #include <mach/audio.h> 29 30 static void pxa2xx_ac97_warm_reset(struct snd_ac97 *ac97) 31 { 32 pxa2xx_ac97_try_warm_reset(ac97); 33 34 pxa2xx_ac97_finish_reset(ac97); 35 } 36 37 static void pxa2xx_ac97_cold_reset(struct snd_ac97 *ac97) 38 { 39 pxa2xx_ac97_try_cold_reset(ac97); 40 41 pxa2xx_ac97_finish_reset(ac97); 42 } 43 44 static struct snd_ac97_bus_ops pxa2xx_ac97_ops = { 45 .read = pxa2xx_ac97_read, 46 .write = pxa2xx_ac97_write, 47 .warm_reset = pxa2xx_ac97_warm_reset, 48 .reset = pxa2xx_ac97_cold_reset, 49 }; 50 51 static struct pxad_param pxa2xx_ac97_pcm_stereo_in_req = { 52 .prio = PXAD_PRIO_LOWEST, 53 .drcmr = 11, 54 }; 55 56 static struct snd_dmaengine_dai_dma_data pxa2xx_ac97_pcm_stereo_in = { 57 .addr = __PREG(PCDR), 58 .addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES, 59 .maxburst = 32, 60 .filter_data = &pxa2xx_ac97_pcm_stereo_in_req, 61 }; 62 63 static struct pxad_param pxa2xx_ac97_pcm_stereo_out_req = { 64 .prio = PXAD_PRIO_LOWEST, 65 .drcmr = 12, 66 }; 67 68 static struct snd_dmaengine_dai_dma_data pxa2xx_ac97_pcm_stereo_out = { 69 .addr = __PREG(PCDR), 70 .addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES, 71 .maxburst = 32, 72 .filter_data = &pxa2xx_ac97_pcm_stereo_out_req, 73 }; 74 75 static struct pxad_param pxa2xx_ac97_pcm_aux_mono_out_req = { 76 .prio = PXAD_PRIO_LOWEST, 77 .drcmr = 10, 78 }; 79 static struct snd_dmaengine_dai_dma_data pxa2xx_ac97_pcm_aux_mono_out = { 80 .addr = __PREG(MODR), 81 .addr_width = DMA_SLAVE_BUSWIDTH_2_BYTES, 82 .maxburst = 16, 83 .filter_data = &pxa2xx_ac97_pcm_aux_mono_out_req, 84 }; 85 86 static struct pxad_param pxa2xx_ac97_pcm_aux_mono_in_req = { 87 .prio = PXAD_PRIO_LOWEST, 88 .drcmr = 9, 89 }; 90 static struct snd_dmaengine_dai_dma_data pxa2xx_ac97_pcm_aux_mono_in = { 91 .addr = __PREG(MODR), 92 .addr_width = DMA_SLAVE_BUSWIDTH_2_BYTES, 93 .maxburst = 16, 94 .filter_data = &pxa2xx_ac97_pcm_aux_mono_in_req, 95 }; 96 97 static struct pxad_param pxa2xx_ac97_pcm_aux_mic_mono_req = { 98 .prio = PXAD_PRIO_LOWEST, 99 .drcmr = 8, 100 }; 101 static struct snd_dmaengine_dai_dma_data pxa2xx_ac97_pcm_mic_mono_in = { 102 .addr = __PREG(MCDR), 103 .addr_width = DMA_SLAVE_BUSWIDTH_2_BYTES, 104 .maxburst = 16, 105 .filter_data = &pxa2xx_ac97_pcm_aux_mic_mono_req, 106 }; 107 108 static int pxa2xx_ac97_hifi_startup(struct snd_pcm_substream *substream, 109 struct snd_soc_dai *cpu_dai) 110 { 111 struct snd_dmaengine_dai_dma_data *dma_data; 112 113 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) 114 dma_data = &pxa2xx_ac97_pcm_stereo_out; 115 else 116 dma_data = &pxa2xx_ac97_pcm_stereo_in; 117 118 snd_soc_dai_set_dma_data(cpu_dai, substream, dma_data); 119 120 return 0; 121 } 122 123 static int pxa2xx_ac97_aux_startup(struct snd_pcm_substream *substream, 124 struct snd_soc_dai *cpu_dai) 125 { 126 struct snd_dmaengine_dai_dma_data *dma_data; 127 128 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) 129 dma_data = &pxa2xx_ac97_pcm_aux_mono_out; 130 else 131 dma_data = &pxa2xx_ac97_pcm_aux_mono_in; 132 133 snd_soc_dai_set_dma_data(cpu_dai, substream, dma_data); 134 135 return 0; 136 } 137 138 static int pxa2xx_ac97_mic_startup(struct snd_pcm_substream *substream, 139 struct snd_soc_dai *cpu_dai) 140 { 141 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) 142 return -ENODEV; 143 else 144 snd_soc_dai_set_dma_data(cpu_dai, substream, 145 &pxa2xx_ac97_pcm_mic_mono_in); 146 147 return 0; 148 } 149 150 #define PXA2XX_AC97_RATES (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_11025 |\ 151 SNDRV_PCM_RATE_16000 | SNDRV_PCM_RATE_22050 | SNDRV_PCM_RATE_44100 | \ 152 SNDRV_PCM_RATE_48000) 153 154 static const struct snd_soc_dai_ops pxa_ac97_hifi_dai_ops = { 155 .startup = pxa2xx_ac97_hifi_startup, 156 }; 157 158 static const struct snd_soc_dai_ops pxa_ac97_aux_dai_ops = { 159 .startup = pxa2xx_ac97_aux_startup, 160 }; 161 162 static const struct snd_soc_dai_ops pxa_ac97_mic_dai_ops = { 163 .startup = pxa2xx_ac97_mic_startup, 164 }; 165 166 /* 167 * There is only 1 physical AC97 interface for pxa2xx, but it 168 * has extra fifo's that can be used for aux DACs and ADCs. 169 */ 170 static struct snd_soc_dai_driver pxa_ac97_dai_driver[] = { 171 { 172 .name = "pxa2xx-ac97", 173 .bus_control = true, 174 .playback = { 175 .stream_name = "AC97 Playback", 176 .channels_min = 2, 177 .channels_max = 2, 178 .rates = PXA2XX_AC97_RATES, 179 .formats = SNDRV_PCM_FMTBIT_S16_LE,}, 180 .capture = { 181 .stream_name = "AC97 Capture", 182 .channels_min = 2, 183 .channels_max = 2, 184 .rates = PXA2XX_AC97_RATES, 185 .formats = SNDRV_PCM_FMTBIT_S16_LE,}, 186 .ops = &pxa_ac97_hifi_dai_ops, 187 }, 188 { 189 .name = "pxa2xx-ac97-aux", 190 .bus_control = true, 191 .playback = { 192 .stream_name = "AC97 Aux Playback", 193 .channels_min = 1, 194 .channels_max = 1, 195 .rates = PXA2XX_AC97_RATES, 196 .formats = SNDRV_PCM_FMTBIT_S16_LE,}, 197 .capture = { 198 .stream_name = "AC97 Aux Capture", 199 .channels_min = 1, 200 .channels_max = 1, 201 .rates = PXA2XX_AC97_RATES, 202 .formats = SNDRV_PCM_FMTBIT_S16_LE,}, 203 .ops = &pxa_ac97_aux_dai_ops, 204 }, 205 { 206 .name = "pxa2xx-ac97-mic", 207 .bus_control = true, 208 .capture = { 209 .stream_name = "AC97 Mic Capture", 210 .channels_min = 1, 211 .channels_max = 1, 212 .rates = PXA2XX_AC97_RATES, 213 .formats = SNDRV_PCM_FMTBIT_S16_LE,}, 214 .ops = &pxa_ac97_mic_dai_ops, 215 }, 216 }; 217 218 static const struct snd_soc_component_driver pxa_ac97_component = { 219 .name = "pxa-ac97", 220 }; 221 222 static int pxa2xx_ac97_dev_probe(struct platform_device *pdev) 223 { 224 int ret; 225 226 if (pdev->id != -1) { 227 dev_err(&pdev->dev, "PXA2xx has only one AC97 port.\n"); 228 return -ENXIO; 229 } 230 231 ret = pxa2xx_ac97_hw_probe(pdev); 232 if (ret) { 233 dev_err(&pdev->dev, "PXA2xx AC97 hw probe error (%d)\n", ret); 234 return ret; 235 } 236 237 ret = snd_soc_set_ac97_ops(&pxa2xx_ac97_ops); 238 if (ret != 0) 239 return ret; 240 241 /* Punt most of the init to the SoC probe; we may need the machine 242 * driver to do interesting things with the clocking to get us up 243 * and running. 244 */ 245 return snd_soc_register_component(&pdev->dev, &pxa_ac97_component, 246 pxa_ac97_dai_driver, ARRAY_SIZE(pxa_ac97_dai_driver)); 247 } 248 249 static int pxa2xx_ac97_dev_remove(struct platform_device *pdev) 250 { 251 snd_soc_unregister_component(&pdev->dev); 252 snd_soc_set_ac97_ops(NULL); 253 pxa2xx_ac97_hw_remove(pdev); 254 return 0; 255 } 256 257 #ifdef CONFIG_PM_SLEEP 258 static int pxa2xx_ac97_dev_suspend(struct device *dev) 259 { 260 return pxa2xx_ac97_hw_suspend(); 261 } 262 263 static int pxa2xx_ac97_dev_resume(struct device *dev) 264 { 265 return pxa2xx_ac97_hw_resume(); 266 } 267 268 static SIMPLE_DEV_PM_OPS(pxa2xx_ac97_pm_ops, 269 pxa2xx_ac97_dev_suspend, pxa2xx_ac97_dev_resume); 270 #endif 271 272 static struct platform_driver pxa2xx_ac97_driver = { 273 .probe = pxa2xx_ac97_dev_probe, 274 .remove = pxa2xx_ac97_dev_remove, 275 .driver = { 276 .name = "pxa2xx-ac97", 277 #ifdef CONFIG_PM_SLEEP 278 .pm = &pxa2xx_ac97_pm_ops, 279 #endif 280 }, 281 }; 282 283 module_platform_driver(pxa2xx_ac97_driver); 284 285 MODULE_AUTHOR("Nicolas Pitre"); 286 MODULE_DESCRIPTION("AC97 driver for the Intel PXA2xx chip"); 287 MODULE_LICENSE("GPL"); 288 MODULE_ALIAS("platform:pxa2xx-ac97"); 289