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 <linux/clk.h>
22 #include <sound/core.h>
23 #include <sound/pcm.h>
24 #include <sound/initval.h>
25 #include <sound/soc.h>
27 #include <asm/hardware.h>
28 #include <asm/arch/pxa-regs.h>
29 #include <asm/arch/pxa2xx-gpio.h>
30 #include <asm/arch/audio.h>
32 #include "pxa2xx-pcm.h"
33 #include "pxa2xx-i2s.h"
43 static struct pxa_i2s_port pxa_i2s;
44 static struct clk *clk_i2s;
46 static struct pxa2xx_pcm_dma_params pxa2xx_i2s_pcm_stereo_out = {
47 .name = "I2S PCM Stereo out",
48 .dev_addr = __PREG(SADR),
49 .drcmr = &DRCMRTXSADR,
50 .dcmd = DCMD_INCSRCADDR | DCMD_FLOWTRG |
51 DCMD_BURST32 | DCMD_WIDTH4,
54 static struct pxa2xx_pcm_dma_params pxa2xx_i2s_pcm_stereo_in = {
55 .name = "I2S PCM Stereo in",
56 .dev_addr = __PREG(SADR),
57 .drcmr = &DRCMRRXSADR,
58 .dcmd = DCMD_INCTRGADDR | DCMD_FLOWSRC |
59 DCMD_BURST32 | DCMD_WIDTH4,
62 static struct pxa2xx_gpio gpio_bus[] = {
64 .rx = GPIO29_SDATA_IN_I2S_MD,
65 .tx = GPIO30_SDATA_OUT_I2S_MD,
66 .clk = GPIO28_BITCLK_IN_I2S_MD,
67 .frm = GPIO31_SYNC_I2S_MD,
69 { /* I2S SoC Master */
71 .sys = GPIO113_I2S_SYSCLK_MD,
73 .sys = GPIO32_SYSCLK_I2S_MD,
75 .rx = GPIO29_SDATA_IN_I2S_MD,
76 .tx = GPIO30_SDATA_OUT_I2S_MD,
77 .clk = GPIO28_BITCLK_OUT_I2S_MD,
78 .frm = GPIO31_SYNC_I2S_MD,
82 static int pxa2xx_i2s_startup(struct snd_pcm_substream *substream)
84 struct snd_soc_pcm_runtime *rtd = substream->private_data;
85 struct snd_soc_cpu_dai *cpu_dai = rtd->dai->cpu_dai;
87 clk_i2s = clk_get(NULL, "I2SCLK");
89 return PTR_ERR(clk_i2s);
91 if (!cpu_dai->active) {
99 /* wait for I2S controller to be ready */
100 static int pxa_i2s_wait(void)
104 /* flush the Rx FIFO */
105 for(i = 0; i < 16; i++)
110 static int pxa2xx_i2s_set_dai_fmt(struct snd_soc_cpu_dai *cpu_dai,
113 /* interface format */
114 switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
115 case SND_SOC_DAIFMT_I2S:
118 case SND_SOC_DAIFMT_LEFT_J:
119 pxa_i2s.fmt = SACR1_AMSL;
123 switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
124 case SND_SOC_DAIFMT_CBS_CFS:
127 case SND_SOC_DAIFMT_CBM_CFS:
136 static int pxa2xx_i2s_set_dai_sysclk(struct snd_soc_cpu_dai *cpu_dai,
137 int clk_id, unsigned int freq, int dir)
139 if (clk_id != PXA2XX_I2S_SYSCLK)
142 if (pxa_i2s.master && dir == SND_SOC_CLOCK_OUT)
143 pxa_gpio_mode(gpio_bus[pxa_i2s.master].sys);
148 static int pxa2xx_i2s_hw_params(struct snd_pcm_substream *substream,
149 struct snd_pcm_hw_params *params)
151 struct snd_soc_pcm_runtime *rtd = substream->private_data;
152 struct snd_soc_cpu_dai *cpu_dai = rtd->dai->cpu_dai;
154 pxa_gpio_mode(gpio_bus[pxa_i2s.master].rx);
155 pxa_gpio_mode(gpio_bus[pxa_i2s.master].tx);
156 pxa_gpio_mode(gpio_bus[pxa_i2s.master].frm);
157 pxa_gpio_mode(gpio_bus[pxa_i2s.master].clk);
161 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
162 cpu_dai->dma_data = &pxa2xx_i2s_pcm_stereo_out;
164 cpu_dai->dma_data = &pxa2xx_i2s_pcm_stereo_in;
166 /* is port used by another stream */
167 if (!(SACR0 & SACR0_ENB)) {
174 SACR0 |= SACR0_RFTH(14) | SACR0_TFTH(1);
175 SACR1 |= pxa_i2s.fmt;
177 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
182 switch (params_rate(params)) {
201 case 96000: /* not in manual and possibly slightly inaccurate */
209 static int pxa2xx_i2s_trigger(struct snd_pcm_substream *substream, int cmd)
214 case SNDRV_PCM_TRIGGER_START:
217 case SNDRV_PCM_TRIGGER_RESUME:
218 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
219 case SNDRV_PCM_TRIGGER_STOP:
220 case SNDRV_PCM_TRIGGER_SUSPEND:
221 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
230 static void pxa2xx_i2s_shutdown(struct snd_pcm_substream *substream)
232 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
240 if (SACR1 & (SACR1_DREC | SACR1_DRPL)) {
243 clk_disable(clk_i2s);
250 static int pxa2xx_i2s_suspend(struct platform_device *dev,
251 struct snd_soc_cpu_dai *dai)
256 /* store registers */
257 pxa_i2s.sacr0 = SACR0;
258 pxa_i2s.sacr1 = SACR1;
259 pxa_i2s.saimr = SAIMR;
260 pxa_i2s.sadiv = SADIV;
262 /* deactivate link */
268 static int pxa2xx_i2s_resume(struct platform_device *pdev,
269 struct snd_soc_cpu_dai *dai)
276 SACR0 = pxa_i2s.sacr0 &= ~SACR0_ENB;
277 SACR1 = pxa_i2s.sacr1;
278 SAIMR = pxa_i2s.saimr;
279 SADIV = pxa_i2s.sadiv;
286 #define pxa2xx_i2s_suspend NULL
287 #define pxa2xx_i2s_resume NULL
290 #define PXA2XX_I2S_RATES (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_11025 |\
291 SNDRV_PCM_RATE_16000 | SNDRV_PCM_RATE_22050 | SNDRV_PCM_RATE_44100 | \
292 SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_96000)
294 struct snd_soc_cpu_dai pxa_i2s_dai = {
295 .name = "pxa2xx-i2s",
297 .type = SND_SOC_DAI_I2S,
298 .suspend = pxa2xx_i2s_suspend,
299 .resume = pxa2xx_i2s_resume,
303 .rates = PXA2XX_I2S_RATES,
304 .formats = SNDRV_PCM_FMTBIT_S16_LE,},
308 .rates = PXA2XX_I2S_RATES,
309 .formats = SNDRV_PCM_FMTBIT_S16_LE,},
311 .startup = pxa2xx_i2s_startup,
312 .shutdown = pxa2xx_i2s_shutdown,
313 .trigger = pxa2xx_i2s_trigger,
314 .hw_params = pxa2xx_i2s_hw_params,},
316 .set_fmt = pxa2xx_i2s_set_dai_fmt,
317 .set_sysclk = pxa2xx_i2s_set_dai_sysclk,
321 EXPORT_SYMBOL_GPL(pxa_i2s_dai);
323 /* Module information */
324 MODULE_AUTHOR("Liam Girdwood, liam.girdwood@wolfsonmicro.com, www.wolfsonmicro.com");
325 MODULE_DESCRIPTION("pxa2xx I2S SoC Interface");
326 MODULE_LICENSE("GPL");