2 * pxa2xx-i2s.c -- ALSA Soc Audio Layer
4 * Copyright 2005 Wolfson Microelectronics PLC.
5 * Author: Liam Girdwood
6 * liam.girdwood@wolfsonmicro.com or linux@wolfsonmicro.com
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the
10 * Free Software Foundation; either version 2 of the License, or (at your
11 * option) any later version.
14 * 12th Aug 2005 Initial version.
17 #include <linux/init.h>
18 #include <linux/module.h>
19 #include <linux/device.h>
20 #include <linux/delay.h>
21 #include <sound/core.h>
22 #include <sound/pcm.h>
23 #include <sound/initval.h>
24 #include <sound/soc.h>
26 #include <asm/hardware.h>
27 #include <asm/arch/pxa-regs.h>
28 #include <asm/arch/pxa2xx-gpio.h>
29 #include <asm/arch/audio.h>
31 #include "pxa2xx-pcm.h"
32 #include "pxa2xx-i2s.h"
42 static struct pxa_i2s_port pxa_i2s;
44 static struct pxa2xx_pcm_dma_params pxa2xx_i2s_pcm_stereo_out = {
45 .name = "I2S PCM Stereo out",
46 .dev_addr = __PREG(SADR),
47 .drcmr = &DRCMRTXSADR,
48 .dcmd = DCMD_INCSRCADDR | DCMD_FLOWTRG |
49 DCMD_BURST32 | DCMD_WIDTH4,
52 static struct pxa2xx_pcm_dma_params pxa2xx_i2s_pcm_stereo_in = {
53 .name = "I2S PCM Stereo in",
54 .dev_addr = __PREG(SADR),
55 .drcmr = &DRCMRRXSADR,
56 .dcmd = DCMD_INCTRGADDR | DCMD_FLOWSRC |
57 DCMD_BURST32 | DCMD_WIDTH4,
60 static struct pxa2xx_gpio gpio_bus[] = {
62 .rx = GPIO29_SDATA_IN_I2S_MD,
63 .tx = GPIO30_SDATA_OUT_I2S_MD,
64 .clk = GPIO28_BITCLK_IN_I2S_MD,
65 .frm = GPIO31_SYNC_I2S_MD,
67 { /* I2S SoC Master */
69 .sys = GPIO113_I2S_SYSCLK_MD,
71 .sys = GPIO32_SYSCLK_I2S_MD,
73 .rx = GPIO29_SDATA_IN_I2S_MD,
74 .tx = GPIO30_SDATA_OUT_I2S_MD,
75 .clk = GPIO28_BITCLK_OUT_I2S_MD,
76 .frm = GPIO31_SYNC_I2S_MD,
80 static int pxa2xx_i2s_startup(struct snd_pcm_substream *substream)
82 struct snd_soc_pcm_runtime *rtd = substream->private_data;
83 struct snd_soc_cpu_dai *cpu_dai = rtd->dai->cpu_dai;
85 if (!cpu_dai->active) {
93 /* wait for I2S controller to be ready */
94 static int pxa_i2s_wait(void)
98 /* flush the Rx FIFO */
99 for(i = 0; i < 16; i++)
104 static int pxa2xx_i2s_set_dai_fmt(struct snd_soc_cpu_dai *cpu_dai,
107 /* interface format */
108 switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
109 case SND_SOC_DAIFMT_I2S:
112 case SND_SOC_DAIFMT_LEFT_J:
113 pxa_i2s.fmt = SACR1_AMSL;
117 switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
118 case SND_SOC_DAIFMT_CBS_CFS:
121 case SND_SOC_DAIFMT_CBM_CFS:
130 static int pxa2xx_i2s_set_dai_sysclk(struct snd_soc_cpu_dai *cpu_dai,
131 int clk_id, unsigned int freq, int dir)
133 if (clk_id != PXA2XX_I2S_SYSCLK)
136 if (pxa_i2s.master && dir == SND_SOC_CLOCK_OUT)
137 pxa_gpio_mode(gpio_bus[pxa_i2s.master].sys);
142 static int pxa2xx_i2s_hw_params(struct snd_pcm_substream *substream,
143 struct snd_pcm_hw_params *params)
145 struct snd_soc_pcm_runtime *rtd = substream->private_data;
146 struct snd_soc_cpu_dai *cpu_dai = rtd->dai->cpu_dai;
148 pxa_gpio_mode(gpio_bus[pxa_i2s.master].rx);
149 pxa_gpio_mode(gpio_bus[pxa_i2s.master].tx);
150 pxa_gpio_mode(gpio_bus[pxa_i2s.master].frm);
151 pxa_gpio_mode(gpio_bus[pxa_i2s.master].clk);
152 pxa_set_cken(CKEN_I2S, 1);
155 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
156 cpu_dai->dma_data = &pxa2xx_i2s_pcm_stereo_out;
158 cpu_dai->dma_data = &pxa2xx_i2s_pcm_stereo_in;
160 /* is port used by another stream */
161 if (!(SACR0 & SACR0_ENB)) {
168 SACR0 |= SACR0_RFTH(14) | SACR0_TFTH(1);
169 SACR1 |= pxa_i2s.fmt;
171 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
176 switch (params_rate(params)) {
195 case 96000: /* not in manual and possibly slightly inaccurate */
203 static int pxa2xx_i2s_trigger(struct snd_pcm_substream *substream, int cmd)
208 case SNDRV_PCM_TRIGGER_START:
211 case SNDRV_PCM_TRIGGER_RESUME:
212 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
213 case SNDRV_PCM_TRIGGER_STOP:
214 case SNDRV_PCM_TRIGGER_SUSPEND:
215 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
224 static void pxa2xx_i2s_shutdown(struct snd_pcm_substream *substream)
226 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
234 if (SACR1 & (SACR1_DREC | SACR1_DRPL)) {
237 pxa_set_cken(CKEN_I2S, 0);
242 static int pxa2xx_i2s_suspend(struct platform_device *dev,
243 struct snd_soc_cpu_dai *dai)
248 /* store registers */
249 pxa_i2s.sacr0 = SACR0;
250 pxa_i2s.sacr1 = SACR1;
251 pxa_i2s.saimr = SAIMR;
252 pxa_i2s.sadiv = SADIV;
254 /* deactivate link */
260 static int pxa2xx_i2s_resume(struct platform_device *pdev,
261 struct snd_soc_cpu_dai *dai)
268 SACR0 = pxa_i2s.sacr0 &= ~SACR0_ENB;
269 SACR1 = pxa_i2s.sacr1;
270 SAIMR = pxa_i2s.saimr;
271 SADIV = pxa_i2s.sadiv;
278 #define pxa2xx_i2s_suspend NULL
279 #define pxa2xx_i2s_resume NULL
282 #define PXA2XX_I2S_RATES (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_11025 |\
283 SNDRV_PCM_RATE_16000 | SNDRV_PCM_RATE_22050 | SNDRV_PCM_RATE_44100 | \
284 SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_96000)
286 struct snd_soc_cpu_dai pxa_i2s_dai = {
287 .name = "pxa2xx-i2s",
289 .type = SND_SOC_DAI_I2S,
290 .suspend = pxa2xx_i2s_suspend,
291 .resume = pxa2xx_i2s_resume,
295 .rates = PXA2XX_I2S_RATES,
296 .formats = SNDRV_PCM_FMTBIT_S16_LE,},
300 .rates = PXA2XX_I2S_RATES,
301 .formats = SNDRV_PCM_FMTBIT_S16_LE,},
303 .startup = pxa2xx_i2s_startup,
304 .shutdown = pxa2xx_i2s_shutdown,
305 .trigger = pxa2xx_i2s_trigger,
306 .hw_params = pxa2xx_i2s_hw_params,},
308 .set_fmt = pxa2xx_i2s_set_dai_fmt,
309 .set_sysclk = pxa2xx_i2s_set_dai_sysclk,
313 EXPORT_SYMBOL_GPL(pxa_i2s_dai);
315 /* Module information */
316 MODULE_AUTHOR("Liam Girdwood, liam.girdwood@wolfsonmicro.com, www.wolfsonmicro.com");
317 MODULE_DESCRIPTION("pxa2xx I2S SoC Interface");
318 MODULE_LICENSE("GPL");