2 * linux/sound/pxa2xx-ac97.c -- AC97 support for the Intel PXA2xx chip.
4 * Author: Nicolas Pitre
5 * Created: Dec 02, 2004
6 * Copyright: MontaVista Software Inc.
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.
13 #include <linux/init.h>
15 #include <linux/module.h>
16 #include <linux/platform_device.h>
17 #include <linux/dmaengine.h>
18 #include <linux/dma/pxa-dma.h>
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>
26 #include <mach/hardware.h>
27 #include <mach/regs-ac97.h>
28 #include <mach/audio.h>
30 static void pxa2xx_ac97_warm_reset(struct snd_ac97 *ac97)
32 pxa2xx_ac97_try_warm_reset(ac97);
34 pxa2xx_ac97_finish_reset(ac97);
37 static void pxa2xx_ac97_cold_reset(struct snd_ac97 *ac97)
39 pxa2xx_ac97_try_cold_reset(ac97);
41 pxa2xx_ac97_finish_reset(ac97);
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,
51 static struct pxad_param pxa2xx_ac97_pcm_stereo_in_req = {
52 .prio = PXAD_PRIO_LOWEST,
56 static struct snd_dmaengine_dai_dma_data pxa2xx_ac97_pcm_stereo_in = {
58 .addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES,
60 .filter_data = &pxa2xx_ac97_pcm_stereo_in_req,
63 static struct pxad_param pxa2xx_ac97_pcm_stereo_out_req = {
64 .prio = PXAD_PRIO_LOWEST,
68 static struct snd_dmaengine_dai_dma_data pxa2xx_ac97_pcm_stereo_out = {
70 .addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES,
72 .filter_data = &pxa2xx_ac97_pcm_stereo_out_req,
75 static struct pxad_param pxa2xx_ac97_pcm_aux_mono_out_req = {
76 .prio = PXAD_PRIO_LOWEST,
79 static struct snd_dmaengine_dai_dma_data pxa2xx_ac97_pcm_aux_mono_out = {
81 .addr_width = DMA_SLAVE_BUSWIDTH_2_BYTES,
83 .filter_data = &pxa2xx_ac97_pcm_aux_mono_out_req,
86 static struct pxad_param pxa2xx_ac97_pcm_aux_mono_in_req = {
87 .prio = PXAD_PRIO_LOWEST,
90 static struct snd_dmaengine_dai_dma_data pxa2xx_ac97_pcm_aux_mono_in = {
92 .addr_width = DMA_SLAVE_BUSWIDTH_2_BYTES,
94 .filter_data = &pxa2xx_ac97_pcm_aux_mono_in_req,
97 static struct pxad_param pxa2xx_ac97_pcm_aux_mic_mono_req = {
98 .prio = PXAD_PRIO_LOWEST,
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,
105 .filter_data = &pxa2xx_ac97_pcm_aux_mic_mono_req,
108 static int pxa2xx_ac97_hifi_startup(struct snd_pcm_substream *substream,
109 struct snd_soc_dai *cpu_dai)
111 struct snd_dmaengine_dai_dma_data *dma_data;
113 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
114 dma_data = &pxa2xx_ac97_pcm_stereo_out;
116 dma_data = &pxa2xx_ac97_pcm_stereo_in;
118 snd_soc_dai_set_dma_data(cpu_dai, substream, dma_data);
123 static int pxa2xx_ac97_aux_startup(struct snd_pcm_substream *substream,
124 struct snd_soc_dai *cpu_dai)
126 struct snd_dmaengine_dai_dma_data *dma_data;
128 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
129 dma_data = &pxa2xx_ac97_pcm_aux_mono_out;
131 dma_data = &pxa2xx_ac97_pcm_aux_mono_in;
133 snd_soc_dai_set_dma_data(cpu_dai, substream, dma_data);
138 static int pxa2xx_ac97_mic_startup(struct snd_pcm_substream *substream,
139 struct snd_soc_dai *cpu_dai)
141 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
144 snd_soc_dai_set_dma_data(cpu_dai, substream,
145 &pxa2xx_ac97_pcm_mic_mono_in);
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)
154 static const struct snd_soc_dai_ops pxa_ac97_hifi_dai_ops = {
155 .startup = pxa2xx_ac97_hifi_startup,
158 static const struct snd_soc_dai_ops pxa_ac97_aux_dai_ops = {
159 .startup = pxa2xx_ac97_aux_startup,
162 static const struct snd_soc_dai_ops pxa_ac97_mic_dai_ops = {
163 .startup = pxa2xx_ac97_mic_startup,
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.
170 static struct snd_soc_dai_driver pxa_ac97_dai_driver[] = {
172 .name = "pxa2xx-ac97",
175 .stream_name = "AC97 Playback",
178 .rates = PXA2XX_AC97_RATES,
179 .formats = SNDRV_PCM_FMTBIT_S16_LE,},
181 .stream_name = "AC97 Capture",
184 .rates = PXA2XX_AC97_RATES,
185 .formats = SNDRV_PCM_FMTBIT_S16_LE,},
186 .ops = &pxa_ac97_hifi_dai_ops,
189 .name = "pxa2xx-ac97-aux",
192 .stream_name = "AC97 Aux Playback",
195 .rates = PXA2XX_AC97_RATES,
196 .formats = SNDRV_PCM_FMTBIT_S16_LE,},
198 .stream_name = "AC97 Aux Capture",
201 .rates = PXA2XX_AC97_RATES,
202 .formats = SNDRV_PCM_FMTBIT_S16_LE,},
203 .ops = &pxa_ac97_aux_dai_ops,
206 .name = "pxa2xx-ac97-mic",
209 .stream_name = "AC97 Mic Capture",
212 .rates = PXA2XX_AC97_RATES,
213 .formats = SNDRV_PCM_FMTBIT_S16_LE,},
214 .ops = &pxa_ac97_mic_dai_ops,
218 static const struct snd_soc_component_driver pxa_ac97_component = {
222 static int pxa2xx_ac97_dev_probe(struct platform_device *pdev)
226 if (pdev->id != -1) {
227 dev_err(&pdev->dev, "PXA2xx has only one AC97 port.\n");
231 ret = pxa2xx_ac97_hw_probe(pdev);
233 dev_err(&pdev->dev, "PXA2xx AC97 hw probe error (%d)\n", ret);
237 ret = snd_soc_set_ac97_ops(&pxa2xx_ac97_ops);
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
245 return snd_soc_register_component(&pdev->dev, &pxa_ac97_component,
246 pxa_ac97_dai_driver, ARRAY_SIZE(pxa_ac97_dai_driver));
249 static int pxa2xx_ac97_dev_remove(struct platform_device *pdev)
251 snd_soc_unregister_component(&pdev->dev);
252 snd_soc_set_ac97_ops(NULL);
253 pxa2xx_ac97_hw_remove(pdev);
257 #ifdef CONFIG_PM_SLEEP
258 static int pxa2xx_ac97_dev_suspend(struct device *dev)
260 return pxa2xx_ac97_hw_suspend();
263 static int pxa2xx_ac97_dev_resume(struct device *dev)
265 return pxa2xx_ac97_hw_resume();
268 static SIMPLE_DEV_PM_OPS(pxa2xx_ac97_pm_ops,
269 pxa2xx_ac97_dev_suspend, pxa2xx_ac97_dev_resume);
272 static struct platform_driver pxa2xx_ac97_driver = {
273 .probe = pxa2xx_ac97_dev_probe,
274 .remove = pxa2xx_ac97_dev_remove,
276 .name = "pxa2xx-ac97",
277 #ifdef CONFIG_PM_SLEEP
278 .pm = &pxa2xx_ac97_pm_ops,
283 module_platform_driver(pxa2xx_ac97_driver);
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");