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