1 // SPDX-License-Identifier: GPL-2.0-only
3 * linux/sound/pxa2xx-ac97.c -- AC97 support for the Intel PXA2xx chip.
5 * Author: Nicolas Pitre
6 * Created: Dec 02, 2004
7 * Copyright: MontaVista Software Inc.
10 #include <linux/init.h>
12 #include <linux/module.h>
13 #include <linux/platform_device.h>
14 #include <linux/dmaengine.h>
15 #include <linux/dma/pxa-dma.h>
17 #include <sound/ac97/controller.h>
18 #include <sound/core.h>
19 #include <sound/ac97_codec.h>
20 #include <sound/soc.h>
21 #include <sound/pxa2xx-lib.h>
22 #include <sound/dmaengine_pcm.h>
24 #include <linux/platform_data/asoc-pxa.h>
26 #define PCDR 0x0040 /* PCM FIFO Data Register */
27 #define MODR 0x0140 /* Modem FIFO Data Register */
28 #define MCDR 0x0060 /* Mic-in FIFO Data Register */
30 static void pxa2xx_ac97_warm_reset(struct ac97_controller *adrv)
32 pxa2xx_ac97_try_warm_reset();
34 pxa2xx_ac97_finish_reset();
37 static void pxa2xx_ac97_cold_reset(struct ac97_controller *adrv)
39 pxa2xx_ac97_try_cold_reset();
41 pxa2xx_ac97_finish_reset();
44 static int pxa2xx_ac97_read_actrl(struct ac97_controller *adrv, int slot,
47 return pxa2xx_ac97_read(slot, reg);
50 static int pxa2xx_ac97_write_actrl(struct ac97_controller *adrv, int slot,
51 unsigned short reg, unsigned short val)
53 return pxa2xx_ac97_write(slot, reg, val);
56 static struct ac97_controller_ops pxa2xx_ac97_ops = {
57 .read = pxa2xx_ac97_read_actrl,
58 .write = pxa2xx_ac97_write_actrl,
59 .warm_reset = pxa2xx_ac97_warm_reset,
60 .reset = pxa2xx_ac97_cold_reset,
63 static struct snd_dmaengine_dai_dma_data pxa2xx_ac97_pcm_stereo_in = {
64 .addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES,
65 .chan_name = "pcm_pcm_stereo_in",
69 static struct snd_dmaengine_dai_dma_data pxa2xx_ac97_pcm_stereo_out = {
70 .addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES,
71 .chan_name = "pcm_pcm_stereo_out",
75 static struct snd_dmaengine_dai_dma_data pxa2xx_ac97_pcm_aux_mono_out = {
76 .addr_width = DMA_SLAVE_BUSWIDTH_2_BYTES,
77 .chan_name = "pcm_aux_mono_out",
81 static struct snd_dmaengine_dai_dma_data pxa2xx_ac97_pcm_aux_mono_in = {
82 .addr_width = DMA_SLAVE_BUSWIDTH_2_BYTES,
83 .chan_name = "pcm_aux_mono_in",
87 static struct snd_dmaengine_dai_dma_data pxa2xx_ac97_pcm_mic_mono_in = {
88 .addr_width = DMA_SLAVE_BUSWIDTH_2_BYTES,
89 .chan_name = "pcm_aux_mic_mono",
93 static int pxa2xx_ac97_hifi_startup(struct snd_pcm_substream *substream,
94 struct snd_soc_dai *cpu_dai)
96 struct snd_dmaengine_dai_dma_data *dma_data;
98 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
99 dma_data = &pxa2xx_ac97_pcm_stereo_out;
101 dma_data = &pxa2xx_ac97_pcm_stereo_in;
103 snd_soc_dai_set_dma_data(cpu_dai, substream, dma_data);
108 static int pxa2xx_ac97_aux_startup(struct snd_pcm_substream *substream,
109 struct snd_soc_dai *cpu_dai)
111 struct snd_dmaengine_dai_dma_data *dma_data;
113 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
114 dma_data = &pxa2xx_ac97_pcm_aux_mono_out;
116 dma_data = &pxa2xx_ac97_pcm_aux_mono_in;
118 snd_soc_dai_set_dma_data(cpu_dai, substream, dma_data);
123 static int pxa2xx_ac97_mic_startup(struct snd_pcm_substream *substream,
124 struct snd_soc_dai *cpu_dai)
126 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
128 snd_soc_dai_set_dma_data(cpu_dai, substream,
129 &pxa2xx_ac97_pcm_mic_mono_in);
134 #define PXA2XX_AC97_RATES (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_11025 |\
135 SNDRV_PCM_RATE_16000 | SNDRV_PCM_RATE_22050 | SNDRV_PCM_RATE_44100 | \
136 SNDRV_PCM_RATE_48000)
138 static const struct snd_soc_dai_ops pxa_ac97_hifi_dai_ops = {
139 .startup = pxa2xx_ac97_hifi_startup,
142 static const struct snd_soc_dai_ops pxa_ac97_aux_dai_ops = {
143 .startup = pxa2xx_ac97_aux_startup,
146 static const struct snd_soc_dai_ops pxa_ac97_mic_dai_ops = {
147 .startup = pxa2xx_ac97_mic_startup,
151 * There is only 1 physical AC97 interface for pxa2xx, but it
152 * has extra fifo's that can be used for aux DACs and ADCs.
154 static struct snd_soc_dai_driver pxa_ac97_dai_driver[] = {
156 .name = "pxa2xx-ac97",
158 .stream_name = "AC97 Playback",
161 .rates = PXA2XX_AC97_RATES,
162 .formats = SNDRV_PCM_FMTBIT_S16_LE,},
164 .stream_name = "AC97 Capture",
167 .rates = PXA2XX_AC97_RATES,
168 .formats = SNDRV_PCM_FMTBIT_S16_LE,},
169 .ops = &pxa_ac97_hifi_dai_ops,
172 .name = "pxa2xx-ac97-aux",
174 .stream_name = "AC97 Aux Playback",
177 .rates = PXA2XX_AC97_RATES,
178 .formats = SNDRV_PCM_FMTBIT_S16_LE,},
180 .stream_name = "AC97 Aux Capture",
183 .rates = PXA2XX_AC97_RATES,
184 .formats = SNDRV_PCM_FMTBIT_S16_LE,},
185 .ops = &pxa_ac97_aux_dai_ops,
188 .name = "pxa2xx-ac97-mic",
190 .stream_name = "AC97 Mic Capture",
193 .rates = PXA2XX_AC97_RATES,
194 .formats = SNDRV_PCM_FMTBIT_S16_LE,},
195 .ops = &pxa_ac97_mic_dai_ops,
199 static const struct snd_soc_component_driver pxa_ac97_component = {
201 .pcm_construct = pxa2xx_soc_pcm_new,
202 .open = pxa2xx_soc_pcm_open,
203 .close = pxa2xx_soc_pcm_close,
204 .hw_params = pxa2xx_soc_pcm_hw_params,
205 .prepare = pxa2xx_soc_pcm_prepare,
206 .trigger = pxa2xx_soc_pcm_trigger,
207 .pointer = pxa2xx_soc_pcm_pointer,
211 static const struct of_device_id pxa2xx_ac97_dt_ids[] = {
212 { .compatible = "marvell,pxa250-ac97", },
213 { .compatible = "marvell,pxa270-ac97", },
214 { .compatible = "marvell,pxa300-ac97", },
217 MODULE_DEVICE_TABLE(of, pxa2xx_ac97_dt_ids);
221 static int pxa2xx_ac97_dev_probe(struct platform_device *pdev)
224 struct ac97_controller *ctrl;
225 pxa2xx_audio_ops_t *pdata = pdev->dev.platform_data;
226 struct resource *regs;
229 if (pdev->id != -1) {
230 dev_err(&pdev->dev, "PXA2xx has only one AC97 port.\n");
234 regs = platform_get_resource(pdev, IORESOURCE_MEM, 0);
238 pxa2xx_ac97_pcm_stereo_in.addr = regs->start + PCDR;
239 pxa2xx_ac97_pcm_stereo_out.addr = regs->start + PCDR;
240 pxa2xx_ac97_pcm_aux_mono_out.addr = regs->start + MODR;
241 pxa2xx_ac97_pcm_aux_mono_in.addr = regs->start + MODR;
242 pxa2xx_ac97_pcm_mic_mono_in.addr = regs->start + MCDR;
244 ret = pxa2xx_ac97_hw_probe(pdev);
246 dev_err(&pdev->dev, "PXA2xx AC97 hw probe error (%d)\n", ret);
250 codecs_pdata = pdata ? pdata->codec_pdata : NULL;
251 ctrl = snd_ac97_controller_register(&pxa2xx_ac97_ops, &pdev->dev,
252 AC97_SLOTS_AVAILABLE_ALL,
255 return PTR_ERR(ctrl);
257 platform_set_drvdata(pdev, ctrl);
258 /* Punt most of the init to the SoC probe; we may need the machine
259 * driver to do interesting things with the clocking to get us up
262 return devm_snd_soc_register_component(&pdev->dev, &pxa_ac97_component,
263 pxa_ac97_dai_driver, ARRAY_SIZE(pxa_ac97_dai_driver));
266 static void pxa2xx_ac97_dev_remove(struct platform_device *pdev)
268 struct ac97_controller *ctrl = platform_get_drvdata(pdev);
270 snd_ac97_controller_unregister(ctrl);
271 pxa2xx_ac97_hw_remove(pdev);
274 #ifdef CONFIG_PM_SLEEP
275 static int pxa2xx_ac97_dev_suspend(struct device *dev)
277 return pxa2xx_ac97_hw_suspend();
280 static int pxa2xx_ac97_dev_resume(struct device *dev)
282 return pxa2xx_ac97_hw_resume();
285 static SIMPLE_DEV_PM_OPS(pxa2xx_ac97_pm_ops,
286 pxa2xx_ac97_dev_suspend, pxa2xx_ac97_dev_resume);
289 static struct platform_driver pxa2xx_ac97_driver = {
290 .probe = pxa2xx_ac97_dev_probe,
291 .remove_new = pxa2xx_ac97_dev_remove,
293 .name = "pxa2xx-ac97",
294 #ifdef CONFIG_PM_SLEEP
295 .pm = &pxa2xx_ac97_pm_ops,
297 .of_match_table = of_match_ptr(pxa2xx_ac97_dt_ids),
301 module_platform_driver(pxa2xx_ac97_driver);
303 MODULE_AUTHOR("Nicolas Pitre");
304 MODULE_DESCRIPTION("AC97 driver for the Intel PXA2xx chip");
305 MODULE_LICENSE("GPL");
306 MODULE_ALIAS("platform:pxa2xx-ac97");