blob: 558c64bbed2e66f0c02d0ecd600605f2bfc1e3fa [file] [log] [blame]
Ben Dooksc1422a62007-02-14 13:17:49 +01001/*
2 * s3c24xx-i2s.c -- ALSA Soc Audio Layer
3 *
4 * (c) 2006 Wolfson Microelectronics PLC.
5 * Graeme Gregory graeme.gregory@wolfsonmicro.com or linux@wolfsonmicro.com
6 *
Ben Dooksc8efef12009-02-28 17:09:57 +00007 * Copyright 2004-2005 Simtec Electronics
Ben Dooksc1422a62007-02-14 13:17:49 +01008 * http://armlinux.simtec.co.uk/
9 * Ben Dooks <ben@simtec.co.uk>
10 *
11 * This program is free software; you can redistribute it and/or modify it
12 * under the terms of the GNU General Public License as published by the
13 * Free Software Foundation; either version 2 of the License, or (at your
14 * option) any later version.
Ben Dooksc1422a62007-02-14 13:17:49 +010015 */
16
Ben Dooksc1422a62007-02-14 13:17:49 +010017#include <linux/delay.h>
18#include <linux/clk.h>
Mark Brown40efc152008-04-23 15:09:31 +020019#include <linux/io.h>
Ben Dooksec976d62009-05-13 22:52:24 +010020#include <linux/gpio.h>
Paul Gortmakerda155d52011-07-15 12:38:28 -040021#include <linux/module.h>
Ben Dooksec976d62009-05-13 22:52:24 +010022
Ben Dooksc1422a62007-02-14 13:17:49 +010023#include <sound/soc.h>
Seungwhan Youn0378b6a2011-01-11 07:26:06 +090024#include <sound/pcm_params.h>
Ben Dooksc1422a62007-02-14 13:17:49 +010025
Russell Kinga09e64f2008-08-05 16:14:15 +010026#include <mach/regs-gpio.h>
Russell Kinga09e64f2008-08-05 16:14:15 +010027#include <mach/dma.h>
Ben Dooks8150bc82009-03-04 00:49:26 +000028#include <plat/regs-iis.h>
Harald Welteaa9673c2007-12-19 15:37:49 +010029
Jassi Brar4b640cf2010-11-22 15:35:57 +090030#include "dma.h"
Ben Dooksc1422a62007-02-14 13:17:49 +010031#include "s3c24xx-i2s.h"
32
Ben Dooksc1422a62007-02-14 13:17:49 +010033static struct s3c2410_dma_client s3c24xx_dma_client_out = {
34 .name = "I2S PCM Stereo out"
35};
36
37static struct s3c2410_dma_client s3c24xx_dma_client_in = {
38 .name = "I2S PCM Stereo in"
39};
40
Jassi Brarfaa31772009-11-17 16:53:23 +090041static struct s3c_dma_params s3c24xx_i2s_pcm_stereo_out = {
Ben Dooksc1422a62007-02-14 13:17:49 +010042 .client = &s3c24xx_dma_client_out,
43 .channel = DMACH_I2S_OUT,
Graeme Gregorye81208f2007-04-17 12:35:48 +020044 .dma_addr = S3C2410_PA_IIS + S3C2410_IISFIFO,
45 .dma_size = 2,
Ben Dooksc1422a62007-02-14 13:17:49 +010046};
47
Jassi Brarfaa31772009-11-17 16:53:23 +090048static struct s3c_dma_params s3c24xx_i2s_pcm_stereo_in = {
Ben Dooksc1422a62007-02-14 13:17:49 +010049 .client = &s3c24xx_dma_client_in,
50 .channel = DMACH_I2S_IN,
Graeme Gregorye81208f2007-04-17 12:35:48 +020051 .dma_addr = S3C2410_PA_IIS + S3C2410_IISFIFO,
52 .dma_size = 2,
Ben Dooksc1422a62007-02-14 13:17:49 +010053};
54
55struct s3c24xx_i2s_info {
56 void __iomem *regs;
57 struct clk *iis_clk;
Graeme Gregory5cd919a2008-01-10 14:44:58 +010058 u32 iiscon;
59 u32 iismod;
60 u32 iisfcon;
61 u32 iispsr;
Ben Dooksc1422a62007-02-14 13:17:49 +010062};
63static struct s3c24xx_i2s_info s3c24xx_i2s;
64
65static void s3c24xx_snd_txctrl(int on)
66{
67 u32 iisfcon;
68 u32 iiscon;
69 u32 iismod;
70
Mark Brownee7d4762009-03-06 18:04:34 +000071 pr_debug("Entered %s\n", __func__);
Ben Dooksc1422a62007-02-14 13:17:49 +010072
73 iisfcon = readl(s3c24xx_i2s.regs + S3C2410_IISFCON);
74 iiscon = readl(s3c24xx_i2s.regs + S3C2410_IISCON);
75 iismod = readl(s3c24xx_i2s.regs + S3C2410_IISMOD);
76
Mark Brown5314adc2009-03-11 16:28:29 +000077 pr_debug("r: IISCON: %x IISMOD: %x IISFCON: %x\n", iiscon, iismod, iisfcon);
Ben Dooksc1422a62007-02-14 13:17:49 +010078
79 if (on) {
80 iisfcon |= S3C2410_IISFCON_TXDMA | S3C2410_IISFCON_TXENABLE;
81 iiscon |= S3C2410_IISCON_TXDMAEN | S3C2410_IISCON_IISEN;
82 iiscon &= ~S3C2410_IISCON_TXIDLE;
83 iismod |= S3C2410_IISMOD_TXMODE;
84
85 writel(iismod, s3c24xx_i2s.regs + S3C2410_IISMOD);
86 writel(iisfcon, s3c24xx_i2s.regs + S3C2410_IISFCON);
87 writel(iiscon, s3c24xx_i2s.regs + S3C2410_IISCON);
88 } else {
89 /* note, we have to disable the FIFOs otherwise bad things
90 * seem to happen when the DMA stops. According to the
91 * Samsung supplied kernel, this should allow the DMA
92 * engine and FIFOs to reset. If this isn't allowed, the
93 * DMA engine will simply freeze randomly.
94 */
95
96 iisfcon &= ~S3C2410_IISFCON_TXENABLE;
97 iisfcon &= ~S3C2410_IISFCON_TXDMA;
98 iiscon |= S3C2410_IISCON_TXIDLE;
99 iiscon &= ~S3C2410_IISCON_TXDMAEN;
100 iismod &= ~S3C2410_IISMOD_TXMODE;
101
102 writel(iiscon, s3c24xx_i2s.regs + S3C2410_IISCON);
103 writel(iisfcon, s3c24xx_i2s.regs + S3C2410_IISFCON);
104 writel(iismod, s3c24xx_i2s.regs + S3C2410_IISMOD);
105 }
106
Mark Brown5314adc2009-03-11 16:28:29 +0000107 pr_debug("w: IISCON: %x IISMOD: %x IISFCON: %x\n", iiscon, iismod, iisfcon);
Ben Dooksc1422a62007-02-14 13:17:49 +0100108}
109
110static void s3c24xx_snd_rxctrl(int on)
111{
112 u32 iisfcon;
113 u32 iiscon;
114 u32 iismod;
115
Mark Brownee7d4762009-03-06 18:04:34 +0000116 pr_debug("Entered %s\n", __func__);
Ben Dooksc1422a62007-02-14 13:17:49 +0100117
118 iisfcon = readl(s3c24xx_i2s.regs + S3C2410_IISFCON);
119 iiscon = readl(s3c24xx_i2s.regs + S3C2410_IISCON);
120 iismod = readl(s3c24xx_i2s.regs + S3C2410_IISMOD);
121
Mark Brown5314adc2009-03-11 16:28:29 +0000122 pr_debug("r: IISCON: %x IISMOD: %x IISFCON: %x\n", iiscon, iismod, iisfcon);
Ben Dooksc1422a62007-02-14 13:17:49 +0100123
124 if (on) {
125 iisfcon |= S3C2410_IISFCON_RXDMA | S3C2410_IISFCON_RXENABLE;
126 iiscon |= S3C2410_IISCON_RXDMAEN | S3C2410_IISCON_IISEN;
127 iiscon &= ~S3C2410_IISCON_RXIDLE;
128 iismod |= S3C2410_IISMOD_RXMODE;
129
130 writel(iismod, s3c24xx_i2s.regs + S3C2410_IISMOD);
131 writel(iisfcon, s3c24xx_i2s.regs + S3C2410_IISFCON);
132 writel(iiscon, s3c24xx_i2s.regs + S3C2410_IISCON);
133 } else {
134 /* note, we have to disable the FIFOs otherwise bad things
135 * seem to happen when the DMA stops. According to the
136 * Samsung supplied kernel, this should allow the DMA
137 * engine and FIFOs to reset. If this isn't allowed, the
138 * DMA engine will simply freeze randomly.
139 */
140
Mark Brown0015e7d2008-04-23 15:09:57 +0200141 iisfcon &= ~S3C2410_IISFCON_RXENABLE;
142 iisfcon &= ~S3C2410_IISFCON_RXDMA;
143 iiscon |= S3C2410_IISCON_RXIDLE;
144 iiscon &= ~S3C2410_IISCON_RXDMAEN;
Ben Dooksc1422a62007-02-14 13:17:49 +0100145 iismod &= ~S3C2410_IISMOD_RXMODE;
146
147 writel(iisfcon, s3c24xx_i2s.regs + S3C2410_IISFCON);
148 writel(iiscon, s3c24xx_i2s.regs + S3C2410_IISCON);
149 writel(iismod, s3c24xx_i2s.regs + S3C2410_IISMOD);
150 }
151
Mark Brown5314adc2009-03-11 16:28:29 +0000152 pr_debug("w: IISCON: %x IISMOD: %x IISFCON: %x\n", iiscon, iismod, iisfcon);
Ben Dooksc1422a62007-02-14 13:17:49 +0100153}
154
155/*
156 * Wait for the LR signal to allow synchronisation to the L/R clock
157 * from the codec. May only be needed for slave mode.
158 */
159static int s3c24xx_snd_lrsync(void)
160{
161 u32 iiscon;
Werner Almesberger33e5b222008-04-14 14:26:44 +0200162 int timeout = 50; /* 5ms */
Ben Dooksc1422a62007-02-14 13:17:49 +0100163
Mark Brownee7d4762009-03-06 18:04:34 +0000164 pr_debug("Entered %s\n", __func__);
Ben Dooksc1422a62007-02-14 13:17:49 +0100165
166 while (1) {
167 iiscon = readl(s3c24xx_i2s.regs + S3C2410_IISCON);
168 if (iiscon & S3C2410_IISCON_LRINDEX)
169 break;
170
Werner Almesberger33e5b222008-04-14 14:26:44 +0200171 if (!timeout--)
Ben Dooksc1422a62007-02-14 13:17:49 +0100172 return -ETIMEDOUT;
Werner Almesberger33e5b222008-04-14 14:26:44 +0200173 udelay(100);
Ben Dooksc1422a62007-02-14 13:17:49 +0100174 }
175
176 return 0;
177}
178
179/*
180 * Check whether CPU is the master or slave
181 */
182static inline int s3c24xx_snd_is_clkmaster(void)
183{
Mark Brownee7d4762009-03-06 18:04:34 +0000184 pr_debug("Entered %s\n", __func__);
Ben Dooksc1422a62007-02-14 13:17:49 +0100185
186 return (readl(s3c24xx_i2s.regs + S3C2410_IISMOD) & S3C2410_IISMOD_SLAVE) ? 0:1;
187}
188
189/*
190 * Set S3C24xx I2S DAI format
191 */
Liam Girdwood1992a6f2008-07-07 16:08:24 +0100192static int s3c24xx_i2s_set_fmt(struct snd_soc_dai *cpu_dai,
Ben Dooksc1422a62007-02-14 13:17:49 +0100193 unsigned int fmt)
194{
195 u32 iismod;
196
Mark Brownee7d4762009-03-06 18:04:34 +0000197 pr_debug("Entered %s\n", __func__);
Ben Dooksc1422a62007-02-14 13:17:49 +0100198
199 iismod = readl(s3c24xx_i2s.regs + S3C2410_IISMOD);
Mark Brown5314adc2009-03-11 16:28:29 +0000200 pr_debug("hw_params r: IISMOD: %x \n", iismod);
Ben Dooksc1422a62007-02-14 13:17:49 +0100201
202 switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
203 case SND_SOC_DAIFMT_CBM_CFM:
204 iismod |= S3C2410_IISMOD_SLAVE;
205 break;
206 case SND_SOC_DAIFMT_CBS_CFS:
Davide Rizzo2c36eec2008-05-05 14:59:39 +0200207 iismod &= ~S3C2410_IISMOD_SLAVE;
Ben Dooksc1422a62007-02-14 13:17:49 +0100208 break;
209 default:
210 return -EINVAL;
211 }
212
213 switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
214 case SND_SOC_DAIFMT_LEFT_J:
215 iismod |= S3C2410_IISMOD_MSB;
216 break;
217 case SND_SOC_DAIFMT_I2S:
Davide Rizzo2c36eec2008-05-05 14:59:39 +0200218 iismod &= ~S3C2410_IISMOD_MSB;
Ben Dooksc1422a62007-02-14 13:17:49 +0100219 break;
220 default:
221 return -EINVAL;
222 }
223
224 writel(iismod, s3c24xx_i2s.regs + S3C2410_IISMOD);
Mark Brown5314adc2009-03-11 16:28:29 +0000225 pr_debug("hw_params w: IISMOD: %x \n", iismod);
Ben Dooksc1422a62007-02-14 13:17:49 +0100226 return 0;
227}
228
229static int s3c24xx_i2s_hw_params(struct snd_pcm_substream *substream,
Mark Browndee89c42008-11-18 22:11:38 +0000230 struct snd_pcm_hw_params *params,
231 struct snd_soc_dai *dai)
Ben Dooksc1422a62007-02-14 13:17:49 +0100232{
233 struct snd_soc_pcm_runtime *rtd = substream->private_data;
Daniel Mack5f712b22010-03-22 10:11:15 +0100234 struct s3c_dma_params *dma_data;
Ben Dooksc1422a62007-02-14 13:17:49 +0100235 u32 iismod;
236
Mark Brownee7d4762009-03-06 18:04:34 +0000237 pr_debug("Entered %s\n", __func__);
Ben Dooksc1422a62007-02-14 13:17:49 +0100238
239 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
Daniel Mack5f712b22010-03-22 10:11:15 +0100240 dma_data = &s3c24xx_i2s_pcm_stereo_out;
Ben Dooksc1422a62007-02-14 13:17:49 +0100241 else
Daniel Mack5f712b22010-03-22 10:11:15 +0100242 dma_data = &s3c24xx_i2s_pcm_stereo_in;
243
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000244 snd_soc_dai_set_dma_data(rtd->cpu_dai, substream, dma_data);
Ben Dooksc1422a62007-02-14 13:17:49 +0100245
246 /* Working copies of register */
247 iismod = readl(s3c24xx_i2s.regs + S3C2410_IISMOD);
Mark Brown5314adc2009-03-11 16:28:29 +0000248 pr_debug("hw_params r: IISMOD: %x\n", iismod);
Ben Dooksc1422a62007-02-14 13:17:49 +0100249
250 switch (params_format(params)) {
251 case SNDRV_PCM_FORMAT_S8:
Christian Pellegrin53599bb2008-11-08 08:44:16 +0100252 iismod &= ~S3C2410_IISMOD_16BIT;
Daniel Mack5f712b22010-03-22 10:11:15 +0100253 dma_data->dma_size = 1;
Ben Dooksc1422a62007-02-14 13:17:49 +0100254 break;
255 case SNDRV_PCM_FORMAT_S16_LE:
256 iismod |= S3C2410_IISMOD_16BIT;
Daniel Mack5f712b22010-03-22 10:11:15 +0100257 dma_data->dma_size = 2;
Ben Dooksc1422a62007-02-14 13:17:49 +0100258 break;
Christian Pellegrin53599bb2008-11-08 08:44:16 +0100259 default:
260 return -EINVAL;
Ben Dooksc1422a62007-02-14 13:17:49 +0100261 }
262
263 writel(iismod, s3c24xx_i2s.regs + S3C2410_IISMOD);
Mark Brown5314adc2009-03-11 16:28:29 +0000264 pr_debug("hw_params w: IISMOD: %x\n", iismod);
Ben Dooksc1422a62007-02-14 13:17:49 +0100265 return 0;
266}
267
Mark Browndee89c42008-11-18 22:11:38 +0000268static int s3c24xx_i2s_trigger(struct snd_pcm_substream *substream, int cmd,
269 struct snd_soc_dai *dai)
Ben Dooksc1422a62007-02-14 13:17:49 +0100270{
271 int ret = 0;
Daniel Mack5f712b22010-03-22 10:11:15 +0100272 struct s3c_dma_params *dma_data =
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000273 snd_soc_dai_get_dma_data(dai, substream);
Ben Dooksc1422a62007-02-14 13:17:49 +0100274
Mark Brownee7d4762009-03-06 18:04:34 +0000275 pr_debug("Entered %s\n", __func__);
Ben Dooksc1422a62007-02-14 13:17:49 +0100276
277 switch (cmd) {
278 case SNDRV_PCM_TRIGGER_START:
279 case SNDRV_PCM_TRIGGER_RESUME:
280 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
281 if (!s3c24xx_snd_is_clkmaster()) {
282 ret = s3c24xx_snd_lrsync();
283 if (ret)
284 goto exit_err;
285 }
286
287 if (substream->stream == SNDRV_PCM_STREAM_CAPTURE)
288 s3c24xx_snd_rxctrl(1);
289 else
290 s3c24xx_snd_txctrl(1);
Shine Liufaf907c2009-08-25 20:05:50 +0800291
Daniel Mack5f712b22010-03-22 10:11:15 +0100292 s3c2410_dma_ctrl(dma_data->channel, S3C2410_DMAOP_STARTED);
Ben Dooksc1422a62007-02-14 13:17:49 +0100293 break;
294 case SNDRV_PCM_TRIGGER_STOP:
295 case SNDRV_PCM_TRIGGER_SUSPEND:
296 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
297 if (substream->stream == SNDRV_PCM_STREAM_CAPTURE)
298 s3c24xx_snd_rxctrl(0);
299 else
300 s3c24xx_snd_txctrl(0);
301 break;
302 default:
303 ret = -EINVAL;
304 break;
305 }
306
307exit_err:
308 return ret;
309}
310
311/*
312 * Set S3C24xx Clock source
313 */
Liam Girdwood1992a6f2008-07-07 16:08:24 +0100314static int s3c24xx_i2s_set_sysclk(struct snd_soc_dai *cpu_dai,
Ben Dooksc1422a62007-02-14 13:17:49 +0100315 int clk_id, unsigned int freq, int dir)
316{
317 u32 iismod = readl(s3c24xx_i2s.regs + S3C2410_IISMOD);
318
Mark Brownee7d4762009-03-06 18:04:34 +0000319 pr_debug("Entered %s\n", __func__);
Ben Dooksc1422a62007-02-14 13:17:49 +0100320
321 iismod &= ~S3C2440_IISMOD_MPLL;
322
323 switch (clk_id) {
324 case S3C24XX_CLKSRC_PCLK:
325 break;
326 case S3C24XX_CLKSRC_MPLL:
327 iismod |= S3C2440_IISMOD_MPLL;
328 break;
329 default:
330 return -EINVAL;
331 }
332
333 writel(iismod, s3c24xx_i2s.regs + S3C2410_IISMOD);
334 return 0;
335}
336
337/*
338 * Set S3C24xx Clock dividers
339 */
Liam Girdwood1992a6f2008-07-07 16:08:24 +0100340static int s3c24xx_i2s_set_clkdiv(struct snd_soc_dai *cpu_dai,
Ben Dooksc1422a62007-02-14 13:17:49 +0100341 int div_id, int div)
342{
343 u32 reg;
344
Mark Brownee7d4762009-03-06 18:04:34 +0000345 pr_debug("Entered %s\n", __func__);
Ben Dooksc1422a62007-02-14 13:17:49 +0100346
347 switch (div_id) {
Matt Reimer82fb1592007-07-12 12:27:24 +0200348 case S3C24XX_DIV_BCLK:
Ben Dooksc1422a62007-02-14 13:17:49 +0100349 reg = readl(s3c24xx_i2s.regs + S3C2410_IISMOD) & ~S3C2410_IISMOD_FS_MASK;
350 writel(reg | div, s3c24xx_i2s.regs + S3C2410_IISMOD);
351 break;
Matt Reimer82fb1592007-07-12 12:27:24 +0200352 case S3C24XX_DIV_MCLK:
Ben Dooksc1422a62007-02-14 13:17:49 +0100353 reg = readl(s3c24xx_i2s.regs + S3C2410_IISMOD) & ~(S3C2410_IISMOD_384FS);
354 writel(reg | div, s3c24xx_i2s.regs + S3C2410_IISMOD);
355 break;
356 case S3C24XX_DIV_PRESCALER:
357 writel(div, s3c24xx_i2s.regs + S3C2410_IISPSR);
358 reg = readl(s3c24xx_i2s.regs + S3C2410_IISCON);
359 writel(reg | S3C2410_IISCON_PSCEN, s3c24xx_i2s.regs + S3C2410_IISCON);
360 break;
361 default:
362 return -EINVAL;
363 }
364
365 return 0;
366}
367
368/*
369 * To avoid duplicating clock code, allow machine driver to
370 * get the clockrate from here.
371 */
372u32 s3c24xx_i2s_get_clockrate(void)
373{
374 return clk_get_rate(s3c24xx_i2s.iis_clk);
375}
376EXPORT_SYMBOL_GPL(s3c24xx_i2s_get_clockrate);
377
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000378static int s3c24xx_i2s_probe(struct snd_soc_dai *dai)
Ben Dooksc1422a62007-02-14 13:17:49 +0100379{
Mark Brownee7d4762009-03-06 18:04:34 +0000380 pr_debug("Entered %s\n", __func__);
Ben Dooksc1422a62007-02-14 13:17:49 +0100381
382 s3c24xx_i2s.regs = ioremap(S3C2410_PA_IIS, 0x100);
383 if (s3c24xx_i2s.regs == NULL)
384 return -ENXIO;
385
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000386 s3c24xx_i2s.iis_clk = clk_get(dai->dev, "iis");
Axel Lin7803e322011-09-15 10:36:54 +0800387 if (IS_ERR(s3c24xx_i2s.iis_clk)) {
Mark Brownb52a5192009-03-06 18:13:43 +0000388 pr_err("failed to get iis_clock\n");
Scott Thompson8642a4b2007-08-01 13:38:59 +0200389 iounmap(s3c24xx_i2s.regs);
Axel Lin7803e322011-09-15 10:36:54 +0800390 return PTR_ERR(s3c24xx_i2s.iis_clk);
Ben Dooksc1422a62007-02-14 13:17:49 +0100391 }
392 clk_enable(s3c24xx_i2s.iis_clk);
393
394 /* Configure the I2S pins in correct mode */
395 s3c2410_gpio_cfgpin(S3C2410_GPE0, S3C2410_GPE0_I2SLRCK);
396 s3c2410_gpio_cfgpin(S3C2410_GPE1, S3C2410_GPE1_I2SSCLK);
397 s3c2410_gpio_cfgpin(S3C2410_GPE2, S3C2410_GPE2_CDCLK);
398 s3c2410_gpio_cfgpin(S3C2410_GPE3, S3C2410_GPE3_I2SSDI);
399 s3c2410_gpio_cfgpin(S3C2410_GPE4, S3C2410_GPE4_I2SSDO);
400
401 writel(S3C2410_IISCON_IISEN, s3c24xx_i2s.regs + S3C2410_IISCON);
402
403 s3c24xx_snd_txctrl(0);
404 s3c24xx_snd_rxctrl(0);
405
406 return 0;
407}
408
Graeme Gregory5cd919a2008-01-10 14:44:58 +0100409#ifdef CONFIG_PM
Mark Browndc7d7b82008-12-03 18:21:52 +0000410static int s3c24xx_i2s_suspend(struct snd_soc_dai *cpu_dai)
Graeme Gregory5cd919a2008-01-10 14:44:58 +0100411{
Mark Brownee7d4762009-03-06 18:04:34 +0000412 pr_debug("Entered %s\n", __func__);
Tim Niemeyer40920302008-04-22 18:26:59 +0200413
Graeme Gregory5cd919a2008-01-10 14:44:58 +0100414 s3c24xx_i2s.iiscon = readl(s3c24xx_i2s.regs + S3C2410_IISCON);
415 s3c24xx_i2s.iismod = readl(s3c24xx_i2s.regs + S3C2410_IISMOD);
416 s3c24xx_i2s.iisfcon = readl(s3c24xx_i2s.regs + S3C2410_IISFCON);
417 s3c24xx_i2s.iispsr = readl(s3c24xx_i2s.regs + S3C2410_IISPSR);
418
419 clk_disable(s3c24xx_i2s.iis_clk);
420
421 return 0;
422}
423
Mark Browndc7d7b82008-12-03 18:21:52 +0000424static int s3c24xx_i2s_resume(struct snd_soc_dai *cpu_dai)
Graeme Gregory5cd919a2008-01-10 14:44:58 +0100425{
Mark Brownee7d4762009-03-06 18:04:34 +0000426 pr_debug("Entered %s\n", __func__);
Graeme Gregory5cd919a2008-01-10 14:44:58 +0100427 clk_enable(s3c24xx_i2s.iis_clk);
428
429 writel(s3c24xx_i2s.iiscon, s3c24xx_i2s.regs + S3C2410_IISCON);
430 writel(s3c24xx_i2s.iismod, s3c24xx_i2s.regs + S3C2410_IISMOD);
431 writel(s3c24xx_i2s.iisfcon, s3c24xx_i2s.regs + S3C2410_IISFCON);
432 writel(s3c24xx_i2s.iispsr, s3c24xx_i2s.regs + S3C2410_IISPSR);
433
434 return 0;
435}
436#else
437#define s3c24xx_i2s_suspend NULL
438#define s3c24xx_i2s_resume NULL
439#endif
440
441
Ben Dooksc1422a62007-02-14 13:17:49 +0100442#define S3C24XX_I2S_RATES \
443 (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_11025 | SNDRV_PCM_RATE_16000 | \
444 SNDRV_PCM_RATE_22050 | SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_44100 | \
445 SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_88200 | SNDRV_PCM_RATE_96000)
446
Eric Miao6335d052009-03-03 09:41:00 +0800447static struct snd_soc_dai_ops s3c24xx_i2s_dai_ops = {
448 .trigger = s3c24xx_i2s_trigger,
449 .hw_params = s3c24xx_i2s_hw_params,
450 .set_fmt = s3c24xx_i2s_set_fmt,
451 .set_clkdiv = s3c24xx_i2s_set_clkdiv,
452 .set_sysclk = s3c24xx_i2s_set_sysclk,
453};
454
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000455static struct snd_soc_dai_driver s3c24xx_i2s_dai = {
Ben Dooksc1422a62007-02-14 13:17:49 +0100456 .probe = s3c24xx_i2s_probe,
Graeme Gregory5cd919a2008-01-10 14:44:58 +0100457 .suspend = s3c24xx_i2s_suspend,
458 .resume = s3c24xx_i2s_resume,
Ben Dooksc1422a62007-02-14 13:17:49 +0100459 .playback = {
460 .channels_min = 2,
461 .channels_max = 2,
462 .rates = S3C24XX_I2S_RATES,
463 .formats = SNDRV_PCM_FMTBIT_S8 | SNDRV_PCM_FMTBIT_S16_LE,},
464 .capture = {
465 .channels_min = 2,
466 .channels_max = 2,
467 .rates = S3C24XX_I2S_RATES,
468 .formats = SNDRV_PCM_FMTBIT_S8 | SNDRV_PCM_FMTBIT_S16_LE,},
Eric Miao6335d052009-03-03 09:41:00 +0800469 .ops = &s3c24xx_i2s_dai_ops,
Ben Dooksc1422a62007-02-14 13:17:49 +0100470};
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000471
472static __devinit int s3c24xx_iis_dev_probe(struct platform_device *pdev)
473{
474 return snd_soc_register_dai(&pdev->dev, &s3c24xx_i2s_dai);
475}
476
477static __devexit int s3c24xx_iis_dev_remove(struct platform_device *pdev)
478{
479 snd_soc_unregister_dai(&pdev->dev);
480 return 0;
481}
482
483static struct platform_driver s3c24xx_iis_driver = {
484 .probe = s3c24xx_iis_dev_probe,
Axel Linc4c58392011-10-02 11:20:13 +0800485 .remove = __devexit_p(s3c24xx_iis_dev_remove),
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000486 .driver = {
487 .name = "s3c24xx-iis",
488 .owner = THIS_MODULE,
489 },
490};
Ben Dooksc1422a62007-02-14 13:17:49 +0100491
Takashi Iwaic9b3a402008-12-10 07:47:22 +0100492static int __init s3c24xx_i2s_init(void)
Mark Brown3f4b7832008-12-03 19:26:35 +0000493{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000494 return platform_driver_register(&s3c24xx_iis_driver);
Mark Brown3f4b7832008-12-03 19:26:35 +0000495}
496module_init(s3c24xx_i2s_init);
497
498static void __exit s3c24xx_i2s_exit(void)
499{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000500 platform_driver_unregister(&s3c24xx_iis_driver);
Mark Brown3f4b7832008-12-03 19:26:35 +0000501}
502module_exit(s3c24xx_i2s_exit);
503
Ben Dooksc1422a62007-02-14 13:17:49 +0100504/* Module information */
505MODULE_AUTHOR("Ben Dooks, <ben@simtec.co.uk>");
506MODULE_DESCRIPTION("s3c24xx I2S SoC Interface");
507MODULE_LICENSE("GPL");
Mark Brown960d0692010-08-12 11:02:19 +0100508MODULE_ALIAS("platform:s3c24xx-iis");