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 #include "pxa2xx-ac97.h"
32 static void pxa2xx_ac97_warm_reset(struct snd_ac97
*ac97
)
34 pxa2xx_ac97_try_warm_reset(ac97
);
36 pxa2xx_ac97_finish_reset(ac97
);
39 static void pxa2xx_ac97_cold_reset(struct snd_ac97
*ac97
)
41 pxa2xx_ac97_try_cold_reset(ac97
);
43 pxa2xx_ac97_finish_reset(ac97
);
46 static struct snd_ac97_bus_ops pxa2xx_ac97_ops
= {
47 .read
= pxa2xx_ac97_read
,
48 .write
= pxa2xx_ac97_write
,
49 .warm_reset
= pxa2xx_ac97_warm_reset
,
50 .reset
= pxa2xx_ac97_cold_reset
,
53 static struct pxad_param pxa2xx_ac97_pcm_stereo_in_req
= {
54 .prio
= PXAD_PRIO_LOWEST
,
58 static struct snd_dmaengine_dai_dma_data pxa2xx_ac97_pcm_stereo_in
= {
60 .addr_width
= DMA_SLAVE_BUSWIDTH_4_BYTES
,
62 .filter_data
= &pxa2xx_ac97_pcm_stereo_in_req
,
65 static struct pxad_param pxa2xx_ac97_pcm_stereo_out_req
= {
66 .prio
= PXAD_PRIO_LOWEST
,
70 static struct snd_dmaengine_dai_dma_data pxa2xx_ac97_pcm_stereo_out
= {
72 .addr_width
= DMA_SLAVE_BUSWIDTH_4_BYTES
,
74 .filter_data
= &pxa2xx_ac97_pcm_stereo_out_req
,
77 static struct pxad_param pxa2xx_ac97_pcm_aux_mono_out_req
= {
78 .prio
= PXAD_PRIO_LOWEST
,
81 static struct snd_dmaengine_dai_dma_data pxa2xx_ac97_pcm_aux_mono_out
= {
83 .addr_width
= DMA_SLAVE_BUSWIDTH_2_BYTES
,
85 .filter_data
= &pxa2xx_ac97_pcm_aux_mono_out_req
,
88 static struct pxad_param pxa2xx_ac97_pcm_aux_mono_in_req
= {
89 .prio
= PXAD_PRIO_LOWEST
,
92 static struct snd_dmaengine_dai_dma_data pxa2xx_ac97_pcm_aux_mono_in
= {
94 .addr_width
= DMA_SLAVE_BUSWIDTH_2_BYTES
,
96 .filter_data
= &pxa2xx_ac97_pcm_aux_mono_in_req
,
99 static struct pxad_param pxa2xx_ac97_pcm_aux_mic_mono_req
= {
100 .prio
= PXAD_PRIO_LOWEST
,
103 static struct snd_dmaengine_dai_dma_data pxa2xx_ac97_pcm_mic_mono_in
= {
104 .addr
= __PREG(MCDR
),
105 .addr_width
= DMA_SLAVE_BUSWIDTH_2_BYTES
,
107 .filter_data
= &pxa2xx_ac97_pcm_aux_mic_mono_req
,
110 static int pxa2xx_ac97_hifi_startup(struct snd_pcm_substream
*substream
,
111 struct snd_soc_dai
*cpu_dai
)
113 struct snd_dmaengine_dai_dma_data
*dma_data
;
115 if (substream
->stream
== SNDRV_PCM_STREAM_PLAYBACK
)
116 dma_data
= &pxa2xx_ac97_pcm_stereo_out
;
118 dma_data
= &pxa2xx_ac97_pcm_stereo_in
;
120 snd_soc_dai_set_dma_data(cpu_dai
, substream
, dma_data
);
125 static int pxa2xx_ac97_aux_startup(struct snd_pcm_substream
*substream
,
126 struct snd_soc_dai
*cpu_dai
)
128 struct snd_dmaengine_dai_dma_data
*dma_data
;
130 if (substream
->stream
== SNDRV_PCM_STREAM_PLAYBACK
)
131 dma_data
= &pxa2xx_ac97_pcm_aux_mono_out
;
133 dma_data
= &pxa2xx_ac97_pcm_aux_mono_in
;
135 snd_soc_dai_set_dma_data(cpu_dai
, substream
, dma_data
);
140 static int pxa2xx_ac97_mic_startup(struct snd_pcm_substream
*substream
,
141 struct snd_soc_dai
*cpu_dai
)
143 if (substream
->stream
== SNDRV_PCM_STREAM_PLAYBACK
)
146 snd_soc_dai_set_dma_data(cpu_dai
, substream
,
147 &pxa2xx_ac97_pcm_mic_mono_in
);
152 #define PXA2XX_AC97_RATES (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_11025 |\
153 SNDRV_PCM_RATE_16000 | SNDRV_PCM_RATE_22050 | SNDRV_PCM_RATE_44100 | \
154 SNDRV_PCM_RATE_48000)
156 static const struct snd_soc_dai_ops pxa_ac97_hifi_dai_ops
= {
157 .startup
= pxa2xx_ac97_hifi_startup
,
160 static const struct snd_soc_dai_ops pxa_ac97_aux_dai_ops
= {
161 .startup
= pxa2xx_ac97_aux_startup
,
164 static const struct snd_soc_dai_ops pxa_ac97_mic_dai_ops
= {
165 .startup
= pxa2xx_ac97_mic_startup
,
169 * There is only 1 physical AC97 interface for pxa2xx, but it
170 * has extra fifo's that can be used for aux DACs and ADCs.
172 static struct snd_soc_dai_driver pxa_ac97_dai_driver
[] = {
174 .name
= "pxa2xx-ac97",
177 .stream_name
= "AC97 Playback",
180 .rates
= PXA2XX_AC97_RATES
,
181 .formats
= SNDRV_PCM_FMTBIT_S16_LE
,},
183 .stream_name
= "AC97 Capture",
186 .rates
= PXA2XX_AC97_RATES
,
187 .formats
= SNDRV_PCM_FMTBIT_S16_LE
,},
188 .ops
= &pxa_ac97_hifi_dai_ops
,
191 .name
= "pxa2xx-ac97-aux",
194 .stream_name
= "AC97 Aux Playback",
197 .rates
= PXA2XX_AC97_RATES
,
198 .formats
= SNDRV_PCM_FMTBIT_S16_LE
,},
200 .stream_name
= "AC97 Aux Capture",
203 .rates
= PXA2XX_AC97_RATES
,
204 .formats
= SNDRV_PCM_FMTBIT_S16_LE
,},
205 .ops
= &pxa_ac97_aux_dai_ops
,
208 .name
= "pxa2xx-ac97-mic",
211 .stream_name
= "AC97 Mic Capture",
214 .rates
= PXA2XX_AC97_RATES
,
215 .formats
= SNDRV_PCM_FMTBIT_S16_LE
,},
216 .ops
= &pxa_ac97_mic_dai_ops
,
220 static const struct snd_soc_component_driver pxa_ac97_component
= {
224 static int pxa2xx_ac97_dev_probe(struct platform_device
*pdev
)
228 if (pdev
->id
!= -1) {
229 dev_err(&pdev
->dev
, "PXA2xx has only one AC97 port.\n");
233 ret
= pxa2xx_ac97_hw_probe(pdev
);
235 dev_err(&pdev
->dev
, "PXA2xx AC97 hw probe error (%d)\n", ret
);
239 ret
= snd_soc_set_ac97_ops(&pxa2xx_ac97_ops
);
243 /* Punt most of the init to the SoC probe; we may need the machine
244 * driver to do interesting things with the clocking to get us up
247 return snd_soc_register_component(&pdev
->dev
, &pxa_ac97_component
,
248 pxa_ac97_dai_driver
, ARRAY_SIZE(pxa_ac97_dai_driver
));
251 static int pxa2xx_ac97_dev_remove(struct platform_device
*pdev
)
253 snd_soc_unregister_component(&pdev
->dev
);
254 snd_soc_set_ac97_ops(NULL
);
255 pxa2xx_ac97_hw_remove(pdev
);
259 #ifdef CONFIG_PM_SLEEP
260 static int pxa2xx_ac97_dev_suspend(struct device
*dev
)
262 return pxa2xx_ac97_hw_suspend();
265 static int pxa2xx_ac97_dev_resume(struct device
*dev
)
267 return pxa2xx_ac97_hw_resume();
270 static SIMPLE_DEV_PM_OPS(pxa2xx_ac97_pm_ops
,
271 pxa2xx_ac97_dev_suspend
, pxa2xx_ac97_dev_resume
);
274 static struct platform_driver pxa2xx_ac97_driver
= {
275 .probe
= pxa2xx_ac97_dev_probe
,
276 .remove
= pxa2xx_ac97_dev_remove
,
278 .name
= "pxa2xx-ac97",
279 #ifdef CONFIG_PM_SLEEP
280 .pm
= &pxa2xx_ac97_pm_ops
,
285 module_platform_driver(pxa2xx_ac97_driver
);
287 MODULE_AUTHOR("Nicolas Pitre");
288 MODULE_DESCRIPTION("AC97 driver for the Intel PXA2xx chip");
289 MODULE_LICENSE("GPL");
290 MODULE_ALIAS("platform:pxa2xx-ac97");