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 snd_dmaengine_dai_dma_data pxa2xx_ac97_pcm_stereo_in = {
73 .addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES,
74 .chan_name = "pcm_pcm_stereo_in",
78 static struct snd_dmaengine_dai_dma_data pxa2xx_ac97_pcm_stereo_out = {
80 .addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES,
81 .chan_name = "pcm_pcm_stereo_out",
85 static struct snd_dmaengine_dai_dma_data pxa2xx_ac97_pcm_aux_mono_out = {
87 .addr_width = DMA_SLAVE_BUSWIDTH_2_BYTES,
88 .chan_name = "pcm_aux_mono_out",
92 static struct snd_dmaengine_dai_dma_data pxa2xx_ac97_pcm_aux_mono_in = {
94 .addr_width = DMA_SLAVE_BUSWIDTH_2_BYTES,
95 .chan_name = "pcm_aux_mono_in",
99 static struct snd_dmaengine_dai_dma_data pxa2xx_ac97_pcm_mic_mono_in = {
100 .addr = __PREG(MCDR),
101 .addr_width = DMA_SLAVE_BUSWIDTH_2_BYTES,
102 .chan_name = "pcm_aux_mic_mono",
106 static int pxa2xx_ac97_hifi_startup(struct snd_pcm_substream *substream,
107 struct snd_soc_dai *cpu_dai)
109 struct snd_dmaengine_dai_dma_data *dma_data;
111 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
112 dma_data = &pxa2xx_ac97_pcm_stereo_out;
114 dma_data = &pxa2xx_ac97_pcm_stereo_in;
116 snd_soc_dai_set_dma_data(cpu_dai, substream, dma_data);
121 static int pxa2xx_ac97_aux_startup(struct snd_pcm_substream *substream,
122 struct snd_soc_dai *cpu_dai)
124 struct snd_dmaengine_dai_dma_data *dma_data;
126 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
127 dma_data = &pxa2xx_ac97_pcm_aux_mono_out;
129 dma_data = &pxa2xx_ac97_pcm_aux_mono_in;
131 snd_soc_dai_set_dma_data(cpu_dai, substream, dma_data);
136 static int pxa2xx_ac97_mic_startup(struct snd_pcm_substream *substream,
137 struct snd_soc_dai *cpu_dai)
139 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
141 snd_soc_dai_set_dma_data(cpu_dai, substream,
142 &pxa2xx_ac97_pcm_mic_mono_in);
147 #define PXA2XX_AC97_RATES (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_11025 |\
148 SNDRV_PCM_RATE_16000 | SNDRV_PCM_RATE_22050 | SNDRV_PCM_RATE_44100 | \
149 SNDRV_PCM_RATE_48000)
151 static const struct snd_soc_dai_ops pxa_ac97_hifi_dai_ops = {
152 .startup = pxa2xx_ac97_hifi_startup,
155 static const struct snd_soc_dai_ops pxa_ac97_aux_dai_ops = {
156 .startup = pxa2xx_ac97_aux_startup,
159 static const struct snd_soc_dai_ops pxa_ac97_mic_dai_ops = {
160 .startup = pxa2xx_ac97_mic_startup,
164 * There is only 1 physical AC97 interface for pxa2xx, but it
165 * has extra fifo's that can be used for aux DACs and ADCs.
167 static struct snd_soc_dai_driver pxa_ac97_dai_driver[] = {
169 .name = "pxa2xx-ac97",
172 .stream_name = "AC97 Playback",
175 .rates = PXA2XX_AC97_RATES,
176 .formats = SNDRV_PCM_FMTBIT_S16_LE,},
178 .stream_name = "AC97 Capture",
181 .rates = PXA2XX_AC97_RATES,
182 .formats = SNDRV_PCM_FMTBIT_S16_LE,},
183 .ops = &pxa_ac97_hifi_dai_ops,
186 .name = "pxa2xx-ac97-aux",
189 .stream_name = "AC97 Aux Playback",
192 .rates = PXA2XX_AC97_RATES,
193 .formats = SNDRV_PCM_FMTBIT_S16_LE,},
195 .stream_name = "AC97 Aux Capture",
198 .rates = PXA2XX_AC97_RATES,
199 .formats = SNDRV_PCM_FMTBIT_S16_LE,},
200 .ops = &pxa_ac97_aux_dai_ops,
203 .name = "pxa2xx-ac97-mic",
206 .stream_name = "AC97 Mic Capture",
209 .rates = PXA2XX_AC97_RATES,
210 .formats = SNDRV_PCM_FMTBIT_S16_LE,},
211 .ops = &pxa_ac97_mic_dai_ops,
215 static const struct snd_soc_component_driver pxa_ac97_component = {
217 .ops = &pxa2xx_pcm_ops,
218 .pcm_new = pxa2xx_soc_pcm_new,
219 .pcm_free = pxa2xx_pcm_free_dma_buffers,
223 static const struct of_device_id pxa2xx_ac97_dt_ids[] = {
224 { .compatible = "marvell,pxa250-ac97", },
225 { .compatible = "marvell,pxa270-ac97", },
226 { .compatible = "marvell,pxa300-ac97", },
229 MODULE_DEVICE_TABLE(of, pxa2xx_ac97_dt_ids);
233 static int pxa2xx_ac97_dev_probe(struct platform_device *pdev)
237 if (pdev->id != -1) {
238 dev_err(&pdev->dev, "PXA2xx has only one AC97 port.\n");
242 ret = pxa2xx_ac97_hw_probe(pdev);
244 dev_err(&pdev->dev, "PXA2xx AC97 hw probe error (%d)\n", ret);
248 ret = snd_soc_set_ac97_ops(&pxa2xx_ac97_ops);
252 /* Punt most of the init to the SoC probe; we may need the machine
253 * driver to do interesting things with the clocking to get us up
256 return snd_soc_register_component(&pdev->dev, &pxa_ac97_component,
257 pxa_ac97_dai_driver, ARRAY_SIZE(pxa_ac97_dai_driver));
260 static int pxa2xx_ac97_dev_remove(struct platform_device *pdev)
262 snd_soc_unregister_component(&pdev->dev);
263 snd_soc_set_ac97_ops(NULL);
264 pxa2xx_ac97_hw_remove(pdev);
268 #ifdef CONFIG_PM_SLEEP
269 static int pxa2xx_ac97_dev_suspend(struct device *dev)
271 return pxa2xx_ac97_hw_suspend();
274 static int pxa2xx_ac97_dev_resume(struct device *dev)
276 return pxa2xx_ac97_hw_resume();
279 static SIMPLE_DEV_PM_OPS(pxa2xx_ac97_pm_ops,
280 pxa2xx_ac97_dev_suspend, pxa2xx_ac97_dev_resume);
283 static struct platform_driver pxa2xx_ac97_driver = {
284 .probe = pxa2xx_ac97_dev_probe,
285 .remove = pxa2xx_ac97_dev_remove,
287 .name = "pxa2xx-ac97",
288 #ifdef CONFIG_PM_SLEEP
289 .pm = &pxa2xx_ac97_pm_ops,
291 .of_match_table = of_match_ptr(pxa2xx_ac97_dt_ids),
295 module_platform_driver(pxa2xx_ac97_driver);
297 MODULE_AUTHOR("Nicolas Pitre");
298 MODULE_DESCRIPTION("AC97 driver for the Intel PXA2xx chip");
299 MODULE_LICENSE("GPL");
300 MODULE_ALIAS("platform:pxa2xx-ac97");