Merge tag 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mst/vhost
[cris-mirror.git] / sound / soc / pxa / pxa2xx-ac97.c
blob803818aabee98f03ffc6bd877830aa73f463392e
1 /*
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>
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>
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,
45 unsigned short reg)
47 int ret;
49 ret = pxa2xx_ac97_read(ac97->num, reg);
50 if (ret < 0)
51 return 0;
52 else
53 return (unsigned short)(ret & 0xffff);
56 static void pxa2xx_ac97_legacy_write(struct snd_ac97 *ac97,
57 unsigned short reg, unsigned short val)
59 int ret;
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,
73 .drcmr = 11,
76 static struct snd_dmaengine_dai_dma_data pxa2xx_ac97_pcm_stereo_in = {
77 .addr = __PREG(PCDR),
78 .addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES,
79 .maxburst = 32,
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,
85 .drcmr = 12,
88 static struct snd_dmaengine_dai_dma_data pxa2xx_ac97_pcm_stereo_out = {
89 .addr = __PREG(PCDR),
90 .addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES,
91 .maxburst = 32,
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,
97 .drcmr = 10,
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,
102 .maxburst = 16,
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,
108 .drcmr = 9,
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,
113 .maxburst = 16,
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,
119 .drcmr = 8,
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,
124 .maxburst = 16,
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;
135 else
136 dma_data = &pxa2xx_ac97_pcm_stereo_in;
138 snd_soc_dai_set_dma_data(cpu_dai, substream, dma_data);
140 return 0;
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;
150 else
151 dma_data = &pxa2xx_ac97_pcm_aux_mono_in;
153 snd_soc_dai_set_dma_data(cpu_dai, substream, dma_data);
155 return 0;
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)
162 return -ENODEV;
163 snd_soc_dai_set_dma_data(cpu_dai, substream,
164 &pxa2xx_ac97_pcm_mic_mono_in);
166 return 0;
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",
192 .bus_control = true,
193 .playback = {
194 .stream_name = "AC97 Playback",
195 .channels_min = 2,
196 .channels_max = 2,
197 .rates = PXA2XX_AC97_RATES,
198 .formats = SNDRV_PCM_FMTBIT_S16_LE,},
199 .capture = {
200 .stream_name = "AC97 Capture",
201 .channels_min = 2,
202 .channels_max = 2,
203 .rates = PXA2XX_AC97_RATES,
204 .formats = SNDRV_PCM_FMTBIT_S16_LE,},
205 .ops = &pxa_ac97_hifi_dai_ops,
208 .name = "pxa2xx-ac97-aux",
209 .bus_control = true,
210 .playback = {
211 .stream_name = "AC97 Aux Playback",
212 .channels_min = 1,
213 .channels_max = 1,
214 .rates = PXA2XX_AC97_RATES,
215 .formats = SNDRV_PCM_FMTBIT_S16_LE,},
216 .capture = {
217 .stream_name = "AC97 Aux Capture",
218 .channels_min = 1,
219 .channels_max = 1,
220 .rates = PXA2XX_AC97_RATES,
221 .formats = SNDRV_PCM_FMTBIT_S16_LE,},
222 .ops = &pxa_ac97_aux_dai_ops,
225 .name = "pxa2xx-ac97-mic",
226 .bus_control = true,
227 .capture = {
228 .stream_name = "AC97 Mic Capture",
229 .channels_min = 1,
230 .channels_max = 1,
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 = {
238 .name = "pxa-ac97",
241 static int pxa2xx_ac97_dev_probe(struct platform_device *pdev)
243 int ret;
245 if (pdev->id != -1) {
246 dev_err(&pdev->dev, "PXA2xx has only one AC97 port.\n");
247 return -ENXIO;
250 ret = pxa2xx_ac97_hw_probe(pdev);
251 if (ret) {
252 dev_err(&pdev->dev, "PXA2xx AC97 hw probe error (%d)\n", ret);
253 return ret;
256 ret = snd_soc_set_ac97_ops(&pxa2xx_ac97_ops);
257 if (ret != 0)
258 return ret;
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
262 * and running.
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);
273 return 0;
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);
289 #endif
291 static struct platform_driver pxa2xx_ac97_driver = {
292 .probe = pxa2xx_ac97_dev_probe,
293 .remove = pxa2xx_ac97_dev_remove,
294 .driver = {
295 .name = "pxa2xx-ac97",
296 #ifdef CONFIG_PM_SLEEP
297 .pm = &pxa2xx_ac97_pm_ops,
298 #endif
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");