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();
34 pxa2xx_ac97_finish_reset();
37 static void pxa2xx_ac97_cold_reset(struct snd_ac97
*ac97
)
39 pxa2xx_ac97_try_cold_reset();
41 pxa2xx_ac97_finish_reset();
44 static unsigned short pxa2xx_ac97_legacy_read(struct snd_ac97
*ac97
,
49 ret
= pxa2xx_ac97_read(ac97
->num
, reg
);
53 return (unsigned short)(ret
& 0xffff);
56 static void pxa2xx_ac97_legacy_write(struct snd_ac97
*ac97
,
57 unsigned short reg
, unsigned short val
)
61 ret
= pxa2xx_ac97_write(ac97
->num
, reg
, val
);
64 static struct snd_ac97_bus_ops pxa2xx_ac97_ops
= {
65 .read
= pxa2xx_ac97_legacy_read
,
66 .write
= pxa2xx_ac97_legacy_write
,
67 .warm_reset
= pxa2xx_ac97_warm_reset
,
68 .reset
= pxa2xx_ac97_cold_reset
,
71 static struct pxad_param pxa2xx_ac97_pcm_stereo_in_req
= {
72 .prio
= PXAD_PRIO_LOWEST
,
76 static struct snd_dmaengine_dai_dma_data pxa2xx_ac97_pcm_stereo_in
= {
78 .addr_width
= DMA_SLAVE_BUSWIDTH_4_BYTES
,
80 .filter_data
= &pxa2xx_ac97_pcm_stereo_in_req
,
83 static struct pxad_param pxa2xx_ac97_pcm_stereo_out_req
= {
84 .prio
= PXAD_PRIO_LOWEST
,
88 static struct snd_dmaengine_dai_dma_data pxa2xx_ac97_pcm_stereo_out
= {
90 .addr_width
= DMA_SLAVE_BUSWIDTH_4_BYTES
,
92 .filter_data
= &pxa2xx_ac97_pcm_stereo_out_req
,
95 static struct pxad_param pxa2xx_ac97_pcm_aux_mono_out_req
= {
96 .prio
= PXAD_PRIO_LOWEST
,
99 static struct snd_dmaengine_dai_dma_data pxa2xx_ac97_pcm_aux_mono_out
= {
100 .addr
= __PREG(MODR
),
101 .addr_width
= DMA_SLAVE_BUSWIDTH_2_BYTES
,
103 .filter_data
= &pxa2xx_ac97_pcm_aux_mono_out_req
,
106 static struct pxad_param pxa2xx_ac97_pcm_aux_mono_in_req
= {
107 .prio
= PXAD_PRIO_LOWEST
,
110 static struct snd_dmaengine_dai_dma_data pxa2xx_ac97_pcm_aux_mono_in
= {
111 .addr
= __PREG(MODR
),
112 .addr_width
= DMA_SLAVE_BUSWIDTH_2_BYTES
,
114 .filter_data
= &pxa2xx_ac97_pcm_aux_mono_in_req
,
117 static struct pxad_param pxa2xx_ac97_pcm_aux_mic_mono_req
= {
118 .prio
= PXAD_PRIO_LOWEST
,
121 static struct snd_dmaengine_dai_dma_data pxa2xx_ac97_pcm_mic_mono_in
= {
122 .addr
= __PREG(MCDR
),
123 .addr_width
= DMA_SLAVE_BUSWIDTH_2_BYTES
,
125 .filter_data
= &pxa2xx_ac97_pcm_aux_mic_mono_req
,
128 static int pxa2xx_ac97_hifi_startup(struct snd_pcm_substream
*substream
,
129 struct snd_soc_dai
*cpu_dai
)
131 struct snd_dmaengine_dai_dma_data
*dma_data
;
133 if (substream
->stream
== SNDRV_PCM_STREAM_PLAYBACK
)
134 dma_data
= &pxa2xx_ac97_pcm_stereo_out
;
136 dma_data
= &pxa2xx_ac97_pcm_stereo_in
;
138 snd_soc_dai_set_dma_data(cpu_dai
, substream
, dma_data
);
143 static int pxa2xx_ac97_aux_startup(struct snd_pcm_substream
*substream
,
144 struct snd_soc_dai
*cpu_dai
)
146 struct snd_dmaengine_dai_dma_data
*dma_data
;
148 if (substream
->stream
== SNDRV_PCM_STREAM_PLAYBACK
)
149 dma_data
= &pxa2xx_ac97_pcm_aux_mono_out
;
151 dma_data
= &pxa2xx_ac97_pcm_aux_mono_in
;
153 snd_soc_dai_set_dma_data(cpu_dai
, substream
, dma_data
);
158 static int pxa2xx_ac97_mic_startup(struct snd_pcm_substream
*substream
,
159 struct snd_soc_dai
*cpu_dai
)
161 if (substream
->stream
== SNDRV_PCM_STREAM_PLAYBACK
)
163 snd_soc_dai_set_dma_data(cpu_dai
, substream
,
164 &pxa2xx_ac97_pcm_mic_mono_in
);
169 #define PXA2XX_AC97_RATES (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_11025 |\
170 SNDRV_PCM_RATE_16000 | SNDRV_PCM_RATE_22050 | SNDRV_PCM_RATE_44100 | \
171 SNDRV_PCM_RATE_48000)
173 static const struct snd_soc_dai_ops pxa_ac97_hifi_dai_ops
= {
174 .startup
= pxa2xx_ac97_hifi_startup
,
177 static const struct snd_soc_dai_ops pxa_ac97_aux_dai_ops
= {
178 .startup
= pxa2xx_ac97_aux_startup
,
181 static const struct snd_soc_dai_ops pxa_ac97_mic_dai_ops
= {
182 .startup
= pxa2xx_ac97_mic_startup
,
186 * There is only 1 physical AC97 interface for pxa2xx, but it
187 * has extra fifo's that can be used for aux DACs and ADCs.
189 static struct snd_soc_dai_driver pxa_ac97_dai_driver
[] = {
191 .name
= "pxa2xx-ac97",
194 .stream_name
= "AC97 Playback",
197 .rates
= PXA2XX_AC97_RATES
,
198 .formats
= SNDRV_PCM_FMTBIT_S16_LE
,},
200 .stream_name
= "AC97 Capture",
203 .rates
= PXA2XX_AC97_RATES
,
204 .formats
= SNDRV_PCM_FMTBIT_S16_LE
,},
205 .ops
= &pxa_ac97_hifi_dai_ops
,
208 .name
= "pxa2xx-ac97-aux",
211 .stream_name
= "AC97 Aux Playback",
214 .rates
= PXA2XX_AC97_RATES
,
215 .formats
= SNDRV_PCM_FMTBIT_S16_LE
,},
217 .stream_name
= "AC97 Aux Capture",
220 .rates
= PXA2XX_AC97_RATES
,
221 .formats
= SNDRV_PCM_FMTBIT_S16_LE
,},
222 .ops
= &pxa_ac97_aux_dai_ops
,
225 .name
= "pxa2xx-ac97-mic",
228 .stream_name
= "AC97 Mic Capture",
231 .rates
= PXA2XX_AC97_RATES
,
232 .formats
= SNDRV_PCM_FMTBIT_S16_LE
,},
233 .ops
= &pxa_ac97_mic_dai_ops
,
237 static const struct snd_soc_component_driver pxa_ac97_component
= {
241 static int pxa2xx_ac97_dev_probe(struct platform_device
*pdev
)
245 if (pdev
->id
!= -1) {
246 dev_err(&pdev
->dev
, "PXA2xx has only one AC97 port.\n");
250 ret
= pxa2xx_ac97_hw_probe(pdev
);
252 dev_err(&pdev
->dev
, "PXA2xx AC97 hw probe error (%d)\n", ret
);
256 ret
= snd_soc_set_ac97_ops(&pxa2xx_ac97_ops
);
260 /* Punt most of the init to the SoC probe; we may need the machine
261 * driver to do interesting things with the clocking to get us up
264 return snd_soc_register_component(&pdev
->dev
, &pxa_ac97_component
,
265 pxa_ac97_dai_driver
, ARRAY_SIZE(pxa_ac97_dai_driver
));
268 static int pxa2xx_ac97_dev_remove(struct platform_device
*pdev
)
270 snd_soc_unregister_component(&pdev
->dev
);
271 snd_soc_set_ac97_ops(NULL
);
272 pxa2xx_ac97_hw_remove(pdev
);
276 #ifdef CONFIG_PM_SLEEP
277 static int pxa2xx_ac97_dev_suspend(struct device
*dev
)
279 return pxa2xx_ac97_hw_suspend();
282 static int pxa2xx_ac97_dev_resume(struct device
*dev
)
284 return pxa2xx_ac97_hw_resume();
287 static SIMPLE_DEV_PM_OPS(pxa2xx_ac97_pm_ops
,
288 pxa2xx_ac97_dev_suspend
, pxa2xx_ac97_dev_resume
);
291 static struct platform_driver pxa2xx_ac97_driver
= {
292 .probe
= pxa2xx_ac97_dev_probe
,
293 .remove
= pxa2xx_ac97_dev_remove
,
295 .name
= "pxa2xx-ac97",
296 #ifdef CONFIG_PM_SLEEP
297 .pm
= &pxa2xx_ac97_pm_ops
,
302 module_platform_driver(pxa2xx_ac97_driver
);
304 MODULE_AUTHOR("Nicolas Pitre");
305 MODULE_DESCRIPTION("AC97 driver for the Intel PXA2xx chip");
306 MODULE_LICENSE("GPL");
307 MODULE_ALIAS("platform:pxa2xx-ac97");