Merge tag 'platform-drivers-x86-v4.19-1' of git://git.infradead.org/linux-platform...
[linux-2.6-block.git] / sound / soc / pxa / pxa2xx-ac97.c
CommitLineData
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
30static void pxa2xx_ac97_warm_reset(struct snd_ac97 *ac97)
31{
6f8acad6 32 pxa2xx_ac97_try_warm_reset();
75b41027 33
6f8acad6 34 pxa2xx_ac97_finish_reset();
75b41027
LG
35}
36
37static void pxa2xx_ac97_cold_reset(struct snd_ac97 *ac97)
38{
6f8acad6 39 pxa2xx_ac97_try_cold_reset();
7a22323b 40
6f8acad6
RJ
41 pxa2xx_ac97_finish_reset();
42}
43
44static unsigned short pxa2xx_ac97_legacy_read(struct snd_ac97 *ac97,
45 unsigned short reg)
46{
47 int ret;
48
49 ret = pxa2xx_ac97_read(ac97->num, reg);
50 if (ret < 0)
51 return 0;
52 else
53 return (unsigned short)(ret & 0xffff);
54}
55
56static void pxa2xx_ac97_legacy_write(struct snd_ac97 *ac97,
57 unsigned short reg, unsigned short val)
58{
59 int ret;
60
61 ret = pxa2xx_ac97_write(ac97->num, reg, val);
75b41027
LG
62}
63
b047e1cc 64static struct snd_ac97_bus_ops pxa2xx_ac97_ops = {
6f8acad6
RJ
65 .read = pxa2xx_ac97_legacy_read,
66 .write = pxa2xx_ac97_legacy_write,
75b41027
LG
67 .warm_reset = pxa2xx_ac97_warm_reset,
68 .reset = pxa2xx_ac97_cold_reset,
69};
70
d65a1458
DM
71static struct snd_dmaengine_dai_dma_data pxa2xx_ac97_pcm_stereo_in = {
72 .addr = __PREG(PCDR),
73 .addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES,
8f54061d 74 .chan_name = "pcm_pcm_stereo_in",
d65a1458 75 .maxburst = 32,
58ceb57e
DM
76};
77
d65a1458
DM
78static struct snd_dmaengine_dai_dma_data pxa2xx_ac97_pcm_stereo_out = {
79 .addr = __PREG(PCDR),
80 .addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES,
8f54061d 81 .chan_name = "pcm_pcm_stereo_out",
d65a1458 82 .maxburst = 32,
75b41027
LG
83};
84
d65a1458
DM
85static struct snd_dmaengine_dai_dma_data pxa2xx_ac97_pcm_aux_mono_out = {
86 .addr = __PREG(MODR),
87 .addr_width = DMA_SLAVE_BUSWIDTH_2_BYTES,
8f54061d 88 .chan_name = "pcm_aux_mono_out",
d65a1458 89 .maxburst = 16,
75b41027
LG
90};
91
d65a1458
DM
92static struct snd_dmaengine_dai_dma_data pxa2xx_ac97_pcm_aux_mono_in = {
93 .addr = __PREG(MODR),
94 .addr_width = DMA_SLAVE_BUSWIDTH_2_BYTES,
8f54061d 95 .chan_name = "pcm_aux_mono_in",
d65a1458 96 .maxburst = 16,
75b41027
LG
97};
98
d65a1458
DM
99static struct snd_dmaengine_dai_dma_data pxa2xx_ac97_pcm_mic_mono_in = {
100 .addr = __PREG(MCDR),
101 .addr_width = DMA_SLAVE_BUSWIDTH_2_BYTES,
8f54061d 102 .chan_name = "pcm_aux_mic_mono",
d65a1458 103 .maxburst = 16,
75b41027
LG
104};
105
58ceb57e
DM
106static int pxa2xx_ac97_hifi_startup(struct snd_pcm_substream *substream,
107 struct snd_soc_dai *cpu_dai)
75b41027 108{
d65a1458 109 struct snd_dmaengine_dai_dma_data *dma_data;
75b41027
LG
110
111 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
5f712b2b 112 dma_data = &pxa2xx_ac97_pcm_stereo_out;
75b41027 113 else
5f712b2b
DM
114 dma_data = &pxa2xx_ac97_pcm_stereo_in;
115
116 snd_soc_dai_set_dma_data(cpu_dai, substream, dma_data);
75b41027
LG
117
118 return 0;
119}
120
58ceb57e
DM
121static int pxa2xx_ac97_aux_startup(struct snd_pcm_substream *substream,
122 struct snd_soc_dai *cpu_dai)
75b41027 123{
d65a1458 124 struct snd_dmaengine_dai_dma_data *dma_data;
75b41027
LG
125
126 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
5f712b2b 127 dma_data = &pxa2xx_ac97_pcm_aux_mono_out;
75b41027 128 else
5f712b2b
DM
129 dma_data = &pxa2xx_ac97_pcm_aux_mono_in;
130
131 snd_soc_dai_set_dma_data(cpu_dai, substream, dma_data);
75b41027
LG
132
133 return 0;
134}
135
58ceb57e
DM
136static int pxa2xx_ac97_mic_startup(struct snd_pcm_substream *substream,
137 struct snd_soc_dai *cpu_dai)
75b41027 138{
75b41027
LG
139 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
140 return -ENODEV;
291aaff0
CG
141 snd_soc_dai_set_dma_data(cpu_dai, substream,
142 &pxa2xx_ac97_pcm_mic_mono_in);
75b41027
LG
143
144 return 0;
145}
146
596ce32b
LG
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)
150
85e7652d 151static const struct snd_soc_dai_ops pxa_ac97_hifi_dai_ops = {
58ceb57e 152 .startup = pxa2xx_ac97_hifi_startup,
6335d055
EM
153};
154
85e7652d 155static const struct snd_soc_dai_ops pxa_ac97_aux_dai_ops = {
58ceb57e 156 .startup = pxa2xx_ac97_aux_startup,
852fd9e5
MB
157};
158
85e7652d 159static const struct snd_soc_dai_ops pxa_ac97_mic_dai_ops = {
58ceb57e 160 .startup = pxa2xx_ac97_mic_startup,
852fd9e5
MB
161};
162
75b41027
LG
163/*
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.
166 */
a3874196 167static struct snd_soc_dai_driver pxa_ac97_dai_driver[] = {
75b41027
LG
168{
169 .name = "pxa2xx-ac97",
bc263214 170 .bus_control = true,
75b41027
LG
171 .playback = {
172 .stream_name = "AC97 Playback",
173 .channels_min = 2,
596ce32b
LG
174 .channels_max = 2,
175 .rates = PXA2XX_AC97_RATES,
176 .formats = SNDRV_PCM_FMTBIT_S16_LE,},
75b41027
LG
177 .capture = {
178 .stream_name = "AC97 Capture",
179 .channels_min = 2,
596ce32b
LG
180 .channels_max = 2,
181 .rates = PXA2XX_AC97_RATES,
182 .formats = SNDRV_PCM_FMTBIT_S16_LE,},
852fd9e5 183 .ops = &pxa_ac97_hifi_dai_ops,
75b41027
LG
184},
185{
186 .name = "pxa2xx-ac97-aux",
bc263214 187 .bus_control = true,
75b41027
LG
188 .playback = {
189 .stream_name = "AC97 Aux Playback",
190 .channels_min = 1,
596ce32b
LG
191 .channels_max = 1,
192 .rates = PXA2XX_AC97_RATES,
193 .formats = SNDRV_PCM_FMTBIT_S16_LE,},
75b41027
LG
194 .capture = {
195 .stream_name = "AC97 Aux Capture",
196 .channels_min = 1,
596ce32b
LG
197 .channels_max = 1,
198 .rates = PXA2XX_AC97_RATES,
199 .formats = SNDRV_PCM_FMTBIT_S16_LE,},
852fd9e5 200 .ops = &pxa_ac97_aux_dai_ops,
75b41027
LG
201},
202{
203 .name = "pxa2xx-ac97-mic",
bc263214 204 .bus_control = true,
75b41027
LG
205 .capture = {
206 .stream_name = "AC97 Mic Capture",
207 .channels_min = 1,
596ce32b
LG
208 .channels_max = 1,
209 .rates = PXA2XX_AC97_RATES,
210 .formats = SNDRV_PCM_FMTBIT_S16_LE,},
852fd9e5 211 .ops = &pxa_ac97_mic_dai_ops,
596ce32b 212},
75b41027
LG
213};
214
ad53232c
KM
215static const struct snd_soc_component_driver pxa_ac97_component = {
216 .name = "pxa-ac97",
d767d3ce
DM
217 .ops = &pxa2xx_pcm_ops,
218 .pcm_new = pxa2xx_soc_pcm_new,
219 .pcm_free = pxa2xx_pcm_free_dma_buffers,
ad53232c
KM
220};
221
a4519526
RJ
222#ifdef CONFIG_OF
223static const struct of_device_id pxa2xx_ac97_dt_ids[] = {
224 { .compatible = "marvell,pxa250-ac97", },
225 { .compatible = "marvell,pxa270-ac97", },
226 { .compatible = "marvell,pxa300-ac97", },
227 { }
228};
229MODULE_DEVICE_TABLE(of, pxa2xx_ac97_dt_ids);
230
231#endif
232
570f6fe1 233static int pxa2xx_ac97_dev_probe(struct platform_device *pdev)
3f4b783c 234{
7685e016
KH
235 int ret;
236
f0fba2ad 237 if (pdev->id != -1) {
4ac0478f
MV
238 dev_err(&pdev->dev, "PXA2xx has only one AC97 port.\n");
239 return -ENXIO;
240 }
241
f62aa9b6
DES
242 ret = pxa2xx_ac97_hw_probe(pdev);
243 if (ret) {
244 dev_err(&pdev->dev, "PXA2xx AC97 hw probe error (%d)\n", ret);
245 return ret;
246 }
247
b047e1cc
MB
248 ret = snd_soc_set_ac97_ops(&pxa2xx_ac97_ops);
249 if (ret != 0)
250 return ret;
251
6b849bcf
MB
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
254 * and running.
255 */
ad53232c
KM
256 return snd_soc_register_component(&pdev->dev, &pxa_ac97_component,
257 pxa_ac97_dai_driver, ARRAY_SIZE(pxa_ac97_dai_driver));
3f4b783c 258}
6b849bcf 259
570f6fe1 260static int pxa2xx_ac97_dev_remove(struct platform_device *pdev)
6b849bcf 261{
ad53232c 262 snd_soc_unregister_component(&pdev->dev);
b047e1cc 263 snd_soc_set_ac97_ops(NULL);
f62aa9b6 264 pxa2xx_ac97_hw_remove(pdev);
6b849bcf
MB
265 return 0;
266}
267
f62aa9b6
DES
268#ifdef CONFIG_PM_SLEEP
269static int pxa2xx_ac97_dev_suspend(struct device *dev)
270{
271 return pxa2xx_ac97_hw_suspend();
272}
273
274static int pxa2xx_ac97_dev_resume(struct device *dev)
275{
276 return pxa2xx_ac97_hw_resume();
277}
278
279static SIMPLE_DEV_PM_OPS(pxa2xx_ac97_pm_ops,
280 pxa2xx_ac97_dev_suspend, pxa2xx_ac97_dev_resume);
281#endif
282
6b849bcf
MB
283static struct platform_driver pxa2xx_ac97_driver = {
284 .probe = pxa2xx_ac97_dev_probe,
570f6fe1 285 .remove = pxa2xx_ac97_dev_remove,
6b849bcf
MB
286 .driver = {
287 .name = "pxa2xx-ac97",
f62aa9b6
DES
288#ifdef CONFIG_PM_SLEEP
289 .pm = &pxa2xx_ac97_pm_ops,
290#endif
a4519526 291 .of_match_table = of_match_ptr(pxa2xx_ac97_dt_ids),
6b849bcf
MB
292 },
293};
294
2f702a19 295module_platform_driver(pxa2xx_ac97_driver);
3f4b783c 296
75b41027
LG
297MODULE_AUTHOR("Nicolas Pitre");
298MODULE_DESCRIPTION("AC97 driver for the Intel PXA2xx chip");
299MODULE_LICENSE("GPL");
e5b7d71a 300MODULE_ALIAS("platform:pxa2xx-ac97");