Commit | Line | Data |
---|---|---|
75b41027 LG |
1 | /* |
2 | * linux/sound/pxa2xx-ac97.c -- AC97 support for the Intel PXA2xx chip. | |
3 | * | |
4 | * Author: Nicolas Pitre | |
5 | * Created: Dec 02, 2004 | |
6 | * Copyright: MontaVista Software Inc. | |
7 | * | |
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. | |
11 | */ | |
12 | ||
13 | #include <linux/init.h> | |
23019a73 | 14 | #include <linux/io.h> |
75b41027 LG |
15 | #include <linux/module.h> |
16 | #include <linux/platform_device.h> | |
d65a1458 | 17 | #include <linux/dmaengine.h> |
58ceb57e | 18 | #include <linux/dma/pxa-dma.h> |
75b41027 | 19 | |
75b41027 | 20 | #include <sound/core.h> |
75b41027 | 21 | #include <sound/ac97_codec.h> |
75b41027 | 22 | #include <sound/soc.h> |
9c636342 | 23 | #include <sound/pxa2xx-lib.h> |
d65a1458 | 24 | #include <sound/dmaengine_pcm.h> |
75b41027 | 25 | |
a09e64fb | 26 | #include <mach/hardware.h> |
1f017a99 | 27 | #include <mach/regs-ac97.h> |
4ac0478f | 28 | #include <mach/audio.h> |
75b41027 | 29 | |
596ce32b | 30 | #include "pxa2xx-ac97.h" |
75b41027 | 31 | |
75b41027 LG |
32 | static void pxa2xx_ac97_warm_reset(struct snd_ac97 *ac97) |
33 | { | |
9c636342 | 34 | pxa2xx_ac97_try_warm_reset(ac97); |
75b41027 | 35 | |
9c636342 | 36 | pxa2xx_ac97_finish_reset(ac97); |
75b41027 LG |
37 | } |
38 | ||
39 | static void pxa2xx_ac97_cold_reset(struct snd_ac97 *ac97) | |
40 | { | |
9c636342 | 41 | pxa2xx_ac97_try_cold_reset(ac97); |
7a22323b | 42 | |
9c636342 | 43 | pxa2xx_ac97_finish_reset(ac97); |
75b41027 LG |
44 | } |
45 | ||
b047e1cc | 46 | static struct snd_ac97_bus_ops pxa2xx_ac97_ops = { |
75b41027 LG |
47 | .read = pxa2xx_ac97_read, |
48 | .write = pxa2xx_ac97_write, | |
49 | .warm_reset = pxa2xx_ac97_warm_reset, | |
50 | .reset = pxa2xx_ac97_cold_reset, | |
51 | }; | |
52 | ||
58ceb57e DM |
53 | static struct pxad_param pxa2xx_ac97_pcm_stereo_in_req = { |
54 | .prio = PXAD_PRIO_LOWEST, | |
55 | .drcmr = 11, | |
56 | }; | |
57 | ||
d65a1458 DM |
58 | static struct snd_dmaengine_dai_dma_data pxa2xx_ac97_pcm_stereo_in = { |
59 | .addr = __PREG(PCDR), | |
60 | .addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES, | |
61 | .maxburst = 32, | |
62 | .filter_data = &pxa2xx_ac97_pcm_stereo_in_req, | |
75b41027 LG |
63 | }; |
64 | ||
58ceb57e DM |
65 | static struct pxad_param pxa2xx_ac97_pcm_stereo_out_req = { |
66 | .prio = PXAD_PRIO_LOWEST, | |
67 | .drcmr = 12, | |
68 | }; | |
69 | ||
d65a1458 DM |
70 | static struct snd_dmaengine_dai_dma_data pxa2xx_ac97_pcm_stereo_out = { |
71 | .addr = __PREG(PCDR), | |
72 | .addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES, | |
73 | .maxburst = 32, | |
74 | .filter_data = &pxa2xx_ac97_pcm_stereo_out_req, | |
75b41027 LG |
75 | }; |
76 | ||
58ceb57e DM |
77 | static struct pxad_param pxa2xx_ac97_pcm_aux_mono_out_req = { |
78 | .prio = PXAD_PRIO_LOWEST, | |
79 | .drcmr = 10, | |
80 | }; | |
d65a1458 DM |
81 | static struct snd_dmaengine_dai_dma_data pxa2xx_ac97_pcm_aux_mono_out = { |
82 | .addr = __PREG(MODR), | |
83 | .addr_width = DMA_SLAVE_BUSWIDTH_2_BYTES, | |
84 | .maxburst = 16, | |
85 | .filter_data = &pxa2xx_ac97_pcm_aux_mono_out_req, | |
75b41027 LG |
86 | }; |
87 | ||
58ceb57e DM |
88 | static struct pxad_param pxa2xx_ac97_pcm_aux_mono_in_req = { |
89 | .prio = PXAD_PRIO_LOWEST, | |
90 | .drcmr = 9, | |
91 | }; | |
d65a1458 DM |
92 | static struct snd_dmaengine_dai_dma_data pxa2xx_ac97_pcm_aux_mono_in = { |
93 | .addr = __PREG(MODR), | |
94 | .addr_width = DMA_SLAVE_BUSWIDTH_2_BYTES, | |
95 | .maxburst = 16, | |
96 | .filter_data = &pxa2xx_ac97_pcm_aux_mono_in_req, | |
75b41027 LG |
97 | }; |
98 | ||
58ceb57e DM |
99 | static struct pxad_param pxa2xx_ac97_pcm_aux_mic_mono_req = { |
100 | .prio = PXAD_PRIO_LOWEST, | |
101 | .drcmr = 8, | |
102 | }; | |
d65a1458 DM |
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, | |
106 | .maxburst = 16, | |
107 | .filter_data = &pxa2xx_ac97_pcm_aux_mic_mono_req, | |
75b41027 LG |
108 | }; |
109 | ||
58ceb57e DM |
110 | static int pxa2xx_ac97_hifi_startup(struct snd_pcm_substream *substream, |
111 | struct snd_soc_dai *cpu_dai) | |
75b41027 | 112 | { |
d65a1458 | 113 | struct snd_dmaengine_dai_dma_data *dma_data; |
75b41027 LG |
114 | |
115 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) | |
5f712b2b | 116 | dma_data = &pxa2xx_ac97_pcm_stereo_out; |
75b41027 | 117 | else |
5f712b2b DM |
118 | dma_data = &pxa2xx_ac97_pcm_stereo_in; |
119 | ||
120 | snd_soc_dai_set_dma_data(cpu_dai, substream, dma_data); | |
75b41027 LG |
121 | |
122 | return 0; | |
123 | } | |
124 | ||
58ceb57e DM |
125 | static int pxa2xx_ac97_aux_startup(struct snd_pcm_substream *substream, |
126 | struct snd_soc_dai *cpu_dai) | |
75b41027 | 127 | { |
d65a1458 | 128 | struct snd_dmaengine_dai_dma_data *dma_data; |
75b41027 LG |
129 | |
130 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) | |
5f712b2b | 131 | dma_data = &pxa2xx_ac97_pcm_aux_mono_out; |
75b41027 | 132 | else |
5f712b2b DM |
133 | dma_data = &pxa2xx_ac97_pcm_aux_mono_in; |
134 | ||
135 | snd_soc_dai_set_dma_data(cpu_dai, substream, dma_data); | |
75b41027 LG |
136 | |
137 | return 0; | |
138 | } | |
139 | ||
58ceb57e DM |
140 | static int pxa2xx_ac97_mic_startup(struct snd_pcm_substream *substream, |
141 | struct snd_soc_dai *cpu_dai) | |
75b41027 | 142 | { |
75b41027 LG |
143 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) |
144 | return -ENODEV; | |
145 | else | |
5f712b2b DM |
146 | snd_soc_dai_set_dma_data(cpu_dai, substream, |
147 | &pxa2xx_ac97_pcm_mic_mono_in); | |
75b41027 LG |
148 | |
149 | return 0; | |
150 | } | |
151 | ||
596ce32b LG |
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) | |
155 | ||
85e7652d | 156 | static const struct snd_soc_dai_ops pxa_ac97_hifi_dai_ops = { |
58ceb57e | 157 | .startup = pxa2xx_ac97_hifi_startup, |
6335d055 EM |
158 | }; |
159 | ||
85e7652d | 160 | static const struct snd_soc_dai_ops pxa_ac97_aux_dai_ops = { |
58ceb57e | 161 | .startup = pxa2xx_ac97_aux_startup, |
852fd9e5 MB |
162 | }; |
163 | ||
85e7652d | 164 | static const struct snd_soc_dai_ops pxa_ac97_mic_dai_ops = { |
58ceb57e | 165 | .startup = pxa2xx_ac97_mic_startup, |
852fd9e5 MB |
166 | }; |
167 | ||
75b41027 LG |
168 | /* |
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. | |
171 | */ | |
a3874196 | 172 | static struct snd_soc_dai_driver pxa_ac97_dai_driver[] = { |
75b41027 LG |
173 | { |
174 | .name = "pxa2xx-ac97", | |
bc263214 | 175 | .bus_control = true, |
75b41027 LG |
176 | .playback = { |
177 | .stream_name = "AC97 Playback", | |
178 | .channels_min = 2, | |
596ce32b LG |
179 | .channels_max = 2, |
180 | .rates = PXA2XX_AC97_RATES, | |
181 | .formats = SNDRV_PCM_FMTBIT_S16_LE,}, | |
75b41027 LG |
182 | .capture = { |
183 | .stream_name = "AC97 Capture", | |
184 | .channels_min = 2, | |
596ce32b LG |
185 | .channels_max = 2, |
186 | .rates = PXA2XX_AC97_RATES, | |
187 | .formats = SNDRV_PCM_FMTBIT_S16_LE,}, | |
852fd9e5 | 188 | .ops = &pxa_ac97_hifi_dai_ops, |
75b41027 LG |
189 | }, |
190 | { | |
191 | .name = "pxa2xx-ac97-aux", | |
bc263214 | 192 | .bus_control = true, |
75b41027 LG |
193 | .playback = { |
194 | .stream_name = "AC97 Aux Playback", | |
195 | .channels_min = 1, | |
596ce32b LG |
196 | .channels_max = 1, |
197 | .rates = PXA2XX_AC97_RATES, | |
198 | .formats = SNDRV_PCM_FMTBIT_S16_LE,}, | |
75b41027 LG |
199 | .capture = { |
200 | .stream_name = "AC97 Aux Capture", | |
201 | .channels_min = 1, | |
596ce32b LG |
202 | .channels_max = 1, |
203 | .rates = PXA2XX_AC97_RATES, | |
204 | .formats = SNDRV_PCM_FMTBIT_S16_LE,}, | |
852fd9e5 | 205 | .ops = &pxa_ac97_aux_dai_ops, |
75b41027 LG |
206 | }, |
207 | { | |
208 | .name = "pxa2xx-ac97-mic", | |
bc263214 | 209 | .bus_control = true, |
75b41027 LG |
210 | .capture = { |
211 | .stream_name = "AC97 Mic Capture", | |
212 | .channels_min = 1, | |
596ce32b LG |
213 | .channels_max = 1, |
214 | .rates = PXA2XX_AC97_RATES, | |
215 | .formats = SNDRV_PCM_FMTBIT_S16_LE,}, | |
852fd9e5 | 216 | .ops = &pxa_ac97_mic_dai_ops, |
596ce32b | 217 | }, |
75b41027 LG |
218 | }; |
219 | ||
ad53232c KM |
220 | static const struct snd_soc_component_driver pxa_ac97_component = { |
221 | .name = "pxa-ac97", | |
222 | }; | |
223 | ||
570f6fe1 | 224 | static int pxa2xx_ac97_dev_probe(struct platform_device *pdev) |
3f4b783c | 225 | { |
7685e016 KH |
226 | int ret; |
227 | ||
f0fba2ad | 228 | if (pdev->id != -1) { |
4ac0478f MV |
229 | dev_err(&pdev->dev, "PXA2xx has only one AC97 port.\n"); |
230 | return -ENXIO; | |
231 | } | |
232 | ||
f62aa9b6 DES |
233 | ret = pxa2xx_ac97_hw_probe(pdev); |
234 | if (ret) { | |
235 | dev_err(&pdev->dev, "PXA2xx AC97 hw probe error (%d)\n", ret); | |
236 | return ret; | |
237 | } | |
238 | ||
b047e1cc MB |
239 | ret = snd_soc_set_ac97_ops(&pxa2xx_ac97_ops); |
240 | if (ret != 0) | |
241 | return ret; | |
242 | ||
6b849bcf MB |
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 | |
245 | * and running. | |
246 | */ | |
ad53232c KM |
247 | return snd_soc_register_component(&pdev->dev, &pxa_ac97_component, |
248 | pxa_ac97_dai_driver, ARRAY_SIZE(pxa_ac97_dai_driver)); | |
3f4b783c | 249 | } |
6b849bcf | 250 | |
570f6fe1 | 251 | static int pxa2xx_ac97_dev_remove(struct platform_device *pdev) |
6b849bcf | 252 | { |
ad53232c | 253 | snd_soc_unregister_component(&pdev->dev); |
b047e1cc | 254 | snd_soc_set_ac97_ops(NULL); |
f62aa9b6 | 255 | pxa2xx_ac97_hw_remove(pdev); |
6b849bcf MB |
256 | return 0; |
257 | } | |
258 | ||
f62aa9b6 DES |
259 | #ifdef CONFIG_PM_SLEEP |
260 | static int pxa2xx_ac97_dev_suspend(struct device *dev) | |
261 | { | |
262 | return pxa2xx_ac97_hw_suspend(); | |
263 | } | |
264 | ||
265 | static int pxa2xx_ac97_dev_resume(struct device *dev) | |
266 | { | |
267 | return pxa2xx_ac97_hw_resume(); | |
268 | } | |
269 | ||
270 | static SIMPLE_DEV_PM_OPS(pxa2xx_ac97_pm_ops, | |
271 | pxa2xx_ac97_dev_suspend, pxa2xx_ac97_dev_resume); | |
272 | #endif | |
273 | ||
6b849bcf MB |
274 | static struct platform_driver pxa2xx_ac97_driver = { |
275 | .probe = pxa2xx_ac97_dev_probe, | |
570f6fe1 | 276 | .remove = pxa2xx_ac97_dev_remove, |
6b849bcf MB |
277 | .driver = { |
278 | .name = "pxa2xx-ac97", | |
f62aa9b6 DES |
279 | #ifdef CONFIG_PM_SLEEP |
280 | .pm = &pxa2xx_ac97_pm_ops, | |
281 | #endif | |
6b849bcf MB |
282 | }, |
283 | }; | |
284 | ||
2f702a19 | 285 | module_platform_driver(pxa2xx_ac97_driver); |
3f4b783c | 286 | |
75b41027 LG |
287 | MODULE_AUTHOR("Nicolas Pitre"); |
288 | MODULE_DESCRIPTION("AC97 driver for the Intel PXA2xx chip"); | |
289 | MODULE_LICENSE("GPL"); | |
e5b7d71a | 290 | MODULE_ALIAS("platform:pxa2xx-ac97"); |