blob: 556e35f0ab7341416fbf6c30c38d713f3a709b92 [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
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>
Julia Lawallf11b7992008-01-07 13:33:45 +010022#include <linux/jiffies.h>
Mark Brown40efc152008-04-23 15:09:31 +020023#include <linux/io.h>
Ben Dooksec976d62009-05-13 22:52:24 +010024#include <linux/gpio.h>
25
Ben Dooksc1422a62007-02-14 13:17:49 +010026#include <sound/core.h>
27#include <sound/pcm.h>
28#include <sound/pcm_params.h>
29#include <sound/initval.h>
30#include <sound/soc.h>
31
Russell Kinga09e64f2008-08-05 16:14:15 +010032#include <mach/hardware.h>
33#include <mach/regs-gpio.h>
34#include <mach/regs-clock.h>
Ben Dooks899e6cf2009-03-04 00:49:28 +000035#include <plat/audio.h>
Ben Dooksc1422a62007-02-14 13:17:49 +010036#include <asm/dma.h>
Russell Kinga09e64f2008-08-05 16:14:15 +010037#include <mach/dma.h>
Ben Dooksc1422a62007-02-14 13:17:49 +010038
Ben Dooks8150bc82009-03-04 00:49:26 +000039#include <plat/regs-iis.h>
Harald Welteaa9673c2007-12-19 15:37:49 +010040
Ben Dooksc1422a62007-02-14 13:17:49 +010041#include "s3c24xx-pcm.h"
42#include "s3c24xx-i2s.h"
43
Ben Dooksc1422a62007-02-14 13:17:49 +010044static struct s3c2410_dma_client s3c24xx_dma_client_out = {
45 .name = "I2S PCM Stereo out"
46};
47
48static struct s3c2410_dma_client s3c24xx_dma_client_in = {
49 .name = "I2S PCM Stereo in"
50};
51
52static struct s3c24xx_pcm_dma_params s3c24xx_i2s_pcm_stereo_out = {
53 .client = &s3c24xx_dma_client_out,
54 .channel = DMACH_I2S_OUT,
Graeme Gregorye81208f2007-04-17 12:35:48 +020055 .dma_addr = S3C2410_PA_IIS + S3C2410_IISFIFO,
56 .dma_size = 2,
Ben Dooksc1422a62007-02-14 13:17:49 +010057};
58
59static struct s3c24xx_pcm_dma_params s3c24xx_i2s_pcm_stereo_in = {
60 .client = &s3c24xx_dma_client_in,
61 .channel = DMACH_I2S_IN,
Graeme Gregorye81208f2007-04-17 12:35:48 +020062 .dma_addr = S3C2410_PA_IIS + S3C2410_IISFIFO,
63 .dma_size = 2,
Ben Dooksc1422a62007-02-14 13:17:49 +010064};
65
66struct s3c24xx_i2s_info {
67 void __iomem *regs;
68 struct clk *iis_clk;
Graeme Gregory5cd919a2008-01-10 14:44:58 +010069 u32 iiscon;
70 u32 iismod;
71 u32 iisfcon;
72 u32 iispsr;
Ben Dooksc1422a62007-02-14 13:17:49 +010073};
74static struct s3c24xx_i2s_info s3c24xx_i2s;
75
76static void s3c24xx_snd_txctrl(int on)
77{
78 u32 iisfcon;
79 u32 iiscon;
80 u32 iismod;
81
Mark Brownee7d4762009-03-06 18:04:34 +000082 pr_debug("Entered %s\n", __func__);
Ben Dooksc1422a62007-02-14 13:17:49 +010083
84 iisfcon = readl(s3c24xx_i2s.regs + S3C2410_IISFCON);
85 iiscon = readl(s3c24xx_i2s.regs + S3C2410_IISCON);
86 iismod = readl(s3c24xx_i2s.regs + S3C2410_IISMOD);
87
Mark Brown5314adc2009-03-11 16:28:29 +000088 pr_debug("r: IISCON: %x IISMOD: %x IISFCON: %x\n", iiscon, iismod, iisfcon);
Ben Dooksc1422a62007-02-14 13:17:49 +010089
90 if (on) {
91 iisfcon |= S3C2410_IISFCON_TXDMA | S3C2410_IISFCON_TXENABLE;
92 iiscon |= S3C2410_IISCON_TXDMAEN | S3C2410_IISCON_IISEN;
93 iiscon &= ~S3C2410_IISCON_TXIDLE;
94 iismod |= S3C2410_IISMOD_TXMODE;
95
96 writel(iismod, s3c24xx_i2s.regs + S3C2410_IISMOD);
97 writel(iisfcon, s3c24xx_i2s.regs + S3C2410_IISFCON);
98 writel(iiscon, s3c24xx_i2s.regs + S3C2410_IISCON);
99 } else {
100 /* note, we have to disable the FIFOs otherwise bad things
101 * seem to happen when the DMA stops. According to the
102 * Samsung supplied kernel, this should allow the DMA
103 * engine and FIFOs to reset. If this isn't allowed, the
104 * DMA engine will simply freeze randomly.
105 */
106
107 iisfcon &= ~S3C2410_IISFCON_TXENABLE;
108 iisfcon &= ~S3C2410_IISFCON_TXDMA;
109 iiscon |= S3C2410_IISCON_TXIDLE;
110 iiscon &= ~S3C2410_IISCON_TXDMAEN;
111 iismod &= ~S3C2410_IISMOD_TXMODE;
112
113 writel(iiscon, s3c24xx_i2s.regs + S3C2410_IISCON);
114 writel(iisfcon, s3c24xx_i2s.regs + S3C2410_IISFCON);
115 writel(iismod, s3c24xx_i2s.regs + S3C2410_IISMOD);
116 }
117
Mark Brown5314adc2009-03-11 16:28:29 +0000118 pr_debug("w: IISCON: %x IISMOD: %x IISFCON: %x\n", iiscon, iismod, iisfcon);
Ben Dooksc1422a62007-02-14 13:17:49 +0100119}
120
121static void s3c24xx_snd_rxctrl(int on)
122{
123 u32 iisfcon;
124 u32 iiscon;
125 u32 iismod;
126
Mark Brownee7d4762009-03-06 18:04:34 +0000127 pr_debug("Entered %s\n", __func__);
Ben Dooksc1422a62007-02-14 13:17:49 +0100128
129 iisfcon = readl(s3c24xx_i2s.regs + S3C2410_IISFCON);
130 iiscon = readl(s3c24xx_i2s.regs + S3C2410_IISCON);
131 iismod = readl(s3c24xx_i2s.regs + S3C2410_IISMOD);
132
Mark Brown5314adc2009-03-11 16:28:29 +0000133 pr_debug("r: IISCON: %x IISMOD: %x IISFCON: %x\n", iiscon, iismod, iisfcon);
Ben Dooksc1422a62007-02-14 13:17:49 +0100134
135 if (on) {
136 iisfcon |= S3C2410_IISFCON_RXDMA | S3C2410_IISFCON_RXENABLE;
137 iiscon |= S3C2410_IISCON_RXDMAEN | S3C2410_IISCON_IISEN;
138 iiscon &= ~S3C2410_IISCON_RXIDLE;
139 iismod |= S3C2410_IISMOD_RXMODE;
140
141 writel(iismod, s3c24xx_i2s.regs + S3C2410_IISMOD);
142 writel(iisfcon, s3c24xx_i2s.regs + S3C2410_IISFCON);
143 writel(iiscon, s3c24xx_i2s.regs + S3C2410_IISCON);
144 } else {
145 /* note, we have to disable the FIFOs otherwise bad things
146 * seem to happen when the DMA stops. According to the
147 * Samsung supplied kernel, this should allow the DMA
148 * engine and FIFOs to reset. If this isn't allowed, the
149 * DMA engine will simply freeze randomly.
150 */
151
Mark Brown0015e7d2008-04-23 15:09:57 +0200152 iisfcon &= ~S3C2410_IISFCON_RXENABLE;
153 iisfcon &= ~S3C2410_IISFCON_RXDMA;
154 iiscon |= S3C2410_IISCON_RXIDLE;
155 iiscon &= ~S3C2410_IISCON_RXDMAEN;
Ben Dooksc1422a62007-02-14 13:17:49 +0100156 iismod &= ~S3C2410_IISMOD_RXMODE;
157
158 writel(iisfcon, s3c24xx_i2s.regs + S3C2410_IISFCON);
159 writel(iiscon, s3c24xx_i2s.regs + S3C2410_IISCON);
160 writel(iismod, s3c24xx_i2s.regs + S3C2410_IISMOD);
161 }
162
Mark Brown5314adc2009-03-11 16:28:29 +0000163 pr_debug("w: IISCON: %x IISMOD: %x IISFCON: %x\n", iiscon, iismod, iisfcon);
Ben Dooksc1422a62007-02-14 13:17:49 +0100164}
165
166/*
167 * Wait for the LR signal to allow synchronisation to the L/R clock
168 * from the codec. May only be needed for slave mode.
169 */
170static int s3c24xx_snd_lrsync(void)
171{
172 u32 iiscon;
Werner Almesberger33e5b222008-04-14 14:26:44 +0200173 int timeout = 50; /* 5ms */
Ben Dooksc1422a62007-02-14 13:17:49 +0100174
Mark Brownee7d4762009-03-06 18:04:34 +0000175 pr_debug("Entered %s\n", __func__);
Ben Dooksc1422a62007-02-14 13:17:49 +0100176
177 while (1) {
178 iiscon = readl(s3c24xx_i2s.regs + S3C2410_IISCON);
179 if (iiscon & S3C2410_IISCON_LRINDEX)
180 break;
181
Werner Almesberger33e5b222008-04-14 14:26:44 +0200182 if (!timeout--)
Ben Dooksc1422a62007-02-14 13:17:49 +0100183 return -ETIMEDOUT;
Werner Almesberger33e5b222008-04-14 14:26:44 +0200184 udelay(100);
Ben Dooksc1422a62007-02-14 13:17:49 +0100185 }
186
187 return 0;
188}
189
190/*
191 * Check whether CPU is the master or slave
192 */
193static inline int s3c24xx_snd_is_clkmaster(void)
194{
Mark Brownee7d4762009-03-06 18:04:34 +0000195 pr_debug("Entered %s\n", __func__);
Ben Dooksc1422a62007-02-14 13:17:49 +0100196
197 return (readl(s3c24xx_i2s.regs + S3C2410_IISMOD) & S3C2410_IISMOD_SLAVE) ? 0:1;
198}
199
200/*
201 * Set S3C24xx I2S DAI format
202 */
Liam Girdwood1992a6f2008-07-07 16:08:24 +0100203static int s3c24xx_i2s_set_fmt(struct snd_soc_dai *cpu_dai,
Ben Dooksc1422a62007-02-14 13:17:49 +0100204 unsigned int fmt)
205{
206 u32 iismod;
207
Mark Brownee7d4762009-03-06 18:04:34 +0000208 pr_debug("Entered %s\n", __func__);
Ben Dooksc1422a62007-02-14 13:17:49 +0100209
210 iismod = readl(s3c24xx_i2s.regs + S3C2410_IISMOD);
Mark Brown5314adc2009-03-11 16:28:29 +0000211 pr_debug("hw_params r: IISMOD: %x \n", iismod);
Ben Dooksc1422a62007-02-14 13:17:49 +0100212
213 switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
214 case SND_SOC_DAIFMT_CBM_CFM:
215 iismod |= S3C2410_IISMOD_SLAVE;
216 break;
217 case SND_SOC_DAIFMT_CBS_CFS:
Davide Rizzo2c36eec2008-05-05 14:59:39 +0200218 iismod &= ~S3C2410_IISMOD_SLAVE;
Ben Dooksc1422a62007-02-14 13:17:49 +0100219 break;
220 default:
221 return -EINVAL;
222 }
223
224 switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
225 case SND_SOC_DAIFMT_LEFT_J:
226 iismod |= S3C2410_IISMOD_MSB;
227 break;
228 case SND_SOC_DAIFMT_I2S:
Davide Rizzo2c36eec2008-05-05 14:59:39 +0200229 iismod &= ~S3C2410_IISMOD_MSB;
Ben Dooksc1422a62007-02-14 13:17:49 +0100230 break;
231 default:
232 return -EINVAL;
233 }
234
235 writel(iismod, s3c24xx_i2s.regs + S3C2410_IISMOD);
Mark Brown5314adc2009-03-11 16:28:29 +0000236 pr_debug("hw_params w: IISMOD: %x \n", iismod);
Ben Dooksc1422a62007-02-14 13:17:49 +0100237 return 0;
238}
239
240static int s3c24xx_i2s_hw_params(struct snd_pcm_substream *substream,
Mark Browndee89c42008-11-18 22:11:38 +0000241 struct snd_pcm_hw_params *params,
242 struct snd_soc_dai *dai)
Ben Dooksc1422a62007-02-14 13:17:49 +0100243{
244 struct snd_soc_pcm_runtime *rtd = substream->private_data;
245 u32 iismod;
246
Mark Brownee7d4762009-03-06 18:04:34 +0000247 pr_debug("Entered %s\n", __func__);
Ben Dooksc1422a62007-02-14 13:17:49 +0100248
249 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
250 rtd->dai->cpu_dai->dma_data = &s3c24xx_i2s_pcm_stereo_out;
251 else
252 rtd->dai->cpu_dai->dma_data = &s3c24xx_i2s_pcm_stereo_in;
253
254 /* Working copies of register */
255 iismod = readl(s3c24xx_i2s.regs + S3C2410_IISMOD);
Mark Brown5314adc2009-03-11 16:28:29 +0000256 pr_debug("hw_params r: IISMOD: %x\n", iismod);
Ben Dooksc1422a62007-02-14 13:17:49 +0100257
258 switch (params_format(params)) {
259 case SNDRV_PCM_FORMAT_S8:
Christian Pellegrin53599bb2008-11-08 08:44:16 +0100260 iismod &= ~S3C2410_IISMOD_16BIT;
261 ((struct s3c24xx_pcm_dma_params *)
262 rtd->dai->cpu_dai->dma_data)->dma_size = 1;
Ben Dooksc1422a62007-02-14 13:17:49 +0100263 break;
264 case SNDRV_PCM_FORMAT_S16_LE:
265 iismod |= S3C2410_IISMOD_16BIT;
Christian Pellegrin53599bb2008-11-08 08:44:16 +0100266 ((struct s3c24xx_pcm_dma_params *)
267 rtd->dai->cpu_dai->dma_data)->dma_size = 2;
Ben Dooksc1422a62007-02-14 13:17:49 +0100268 break;
Christian Pellegrin53599bb2008-11-08 08:44:16 +0100269 default:
270 return -EINVAL;
Ben Dooksc1422a62007-02-14 13:17:49 +0100271 }
272
273 writel(iismod, s3c24xx_i2s.regs + S3C2410_IISMOD);
Mark Brown5314adc2009-03-11 16:28:29 +0000274 pr_debug("hw_params w: IISMOD: %x\n", iismod);
Ben Dooksc1422a62007-02-14 13:17:49 +0100275 return 0;
276}
277
Mark Browndee89c42008-11-18 22:11:38 +0000278static int s3c24xx_i2s_trigger(struct snd_pcm_substream *substream, int cmd,
279 struct snd_soc_dai *dai)
Ben Dooksc1422a62007-02-14 13:17:49 +0100280{
281 int ret = 0;
282
Mark Brownee7d4762009-03-06 18:04:34 +0000283 pr_debug("Entered %s\n", __func__);
Ben Dooksc1422a62007-02-14 13:17:49 +0100284
285 switch (cmd) {
286 case SNDRV_PCM_TRIGGER_START:
287 case SNDRV_PCM_TRIGGER_RESUME:
288 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
289 if (!s3c24xx_snd_is_clkmaster()) {
290 ret = s3c24xx_snd_lrsync();
291 if (ret)
292 goto exit_err;
293 }
294
295 if (substream->stream == SNDRV_PCM_STREAM_CAPTURE)
296 s3c24xx_snd_rxctrl(1);
297 else
298 s3c24xx_snd_txctrl(1);
299 break;
300 case SNDRV_PCM_TRIGGER_STOP:
301 case SNDRV_PCM_TRIGGER_SUSPEND:
302 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
303 if (substream->stream == SNDRV_PCM_STREAM_CAPTURE)
304 s3c24xx_snd_rxctrl(0);
305 else
306 s3c24xx_snd_txctrl(0);
307 break;
308 default:
309 ret = -EINVAL;
310 break;
311 }
312
313exit_err:
314 return ret;
315}
316
317/*
318 * Set S3C24xx Clock source
319 */
Liam Girdwood1992a6f2008-07-07 16:08:24 +0100320static int s3c24xx_i2s_set_sysclk(struct snd_soc_dai *cpu_dai,
Ben Dooksc1422a62007-02-14 13:17:49 +0100321 int clk_id, unsigned int freq, int dir)
322{
323 u32 iismod = readl(s3c24xx_i2s.regs + S3C2410_IISMOD);
324
Mark Brownee7d4762009-03-06 18:04:34 +0000325 pr_debug("Entered %s\n", __func__);
Ben Dooksc1422a62007-02-14 13:17:49 +0100326
327 iismod &= ~S3C2440_IISMOD_MPLL;
328
329 switch (clk_id) {
330 case S3C24XX_CLKSRC_PCLK:
331 break;
332 case S3C24XX_CLKSRC_MPLL:
333 iismod |= S3C2440_IISMOD_MPLL;
334 break;
335 default:
336 return -EINVAL;
337 }
338
339 writel(iismod, s3c24xx_i2s.regs + S3C2410_IISMOD);
340 return 0;
341}
342
343/*
344 * Set S3C24xx Clock dividers
345 */
Liam Girdwood1992a6f2008-07-07 16:08:24 +0100346static int s3c24xx_i2s_set_clkdiv(struct snd_soc_dai *cpu_dai,
Ben Dooksc1422a62007-02-14 13:17:49 +0100347 int div_id, int div)
348{
349 u32 reg;
350
Mark Brownee7d4762009-03-06 18:04:34 +0000351 pr_debug("Entered %s\n", __func__);
Ben Dooksc1422a62007-02-14 13:17:49 +0100352
353 switch (div_id) {
Matt Reimer82fb1592007-07-12 12:27:24 +0200354 case S3C24XX_DIV_BCLK:
Ben Dooksc1422a62007-02-14 13:17:49 +0100355 reg = readl(s3c24xx_i2s.regs + S3C2410_IISMOD) & ~S3C2410_IISMOD_FS_MASK;
356 writel(reg | div, s3c24xx_i2s.regs + S3C2410_IISMOD);
357 break;
Matt Reimer82fb1592007-07-12 12:27:24 +0200358 case S3C24XX_DIV_MCLK:
Ben Dooksc1422a62007-02-14 13:17:49 +0100359 reg = readl(s3c24xx_i2s.regs + S3C2410_IISMOD) & ~(S3C2410_IISMOD_384FS);
360 writel(reg | div, s3c24xx_i2s.regs + S3C2410_IISMOD);
361 break;
362 case S3C24XX_DIV_PRESCALER:
363 writel(div, s3c24xx_i2s.regs + S3C2410_IISPSR);
364 reg = readl(s3c24xx_i2s.regs + S3C2410_IISCON);
365 writel(reg | S3C2410_IISCON_PSCEN, s3c24xx_i2s.regs + S3C2410_IISCON);
366 break;
367 default:
368 return -EINVAL;
369 }
370
371 return 0;
372}
373
374/*
375 * To avoid duplicating clock code, allow machine driver to
376 * get the clockrate from here.
377 */
378u32 s3c24xx_i2s_get_clockrate(void)
379{
380 return clk_get_rate(s3c24xx_i2s.iis_clk);
381}
382EXPORT_SYMBOL_GPL(s3c24xx_i2s_get_clockrate);
383
Mark Brownbdb92872008-06-11 13:47:10 +0100384static int s3c24xx_i2s_probe(struct platform_device *pdev,
Liam Girdwood1992a6f2008-07-07 16:08:24 +0100385 struct snd_soc_dai *dai)
Ben Dooksc1422a62007-02-14 13:17:49 +0100386{
Mark Brownee7d4762009-03-06 18:04:34 +0000387 pr_debug("Entered %s\n", __func__);
Ben Dooksc1422a62007-02-14 13:17:49 +0100388
389 s3c24xx_i2s.regs = ioremap(S3C2410_PA_IIS, 0x100);
390 if (s3c24xx_i2s.regs == NULL)
391 return -ENXIO;
392
Mark Brown0fe564a2008-04-23 15:10:28 +0200393 s3c24xx_i2s.iis_clk = clk_get(&pdev->dev, "iis");
Ben Dooksc1422a62007-02-14 13:17:49 +0100394 if (s3c24xx_i2s.iis_clk == NULL) {
Mark Brownb52a5192009-03-06 18:13:43 +0000395 pr_err("failed to get iis_clock\n");
Scott Thompson8642a4b2007-08-01 13:38:59 +0200396 iounmap(s3c24xx_i2s.regs);
Ben Dooksc1422a62007-02-14 13:17:49 +0100397 return -ENODEV;
398 }
399 clk_enable(s3c24xx_i2s.iis_clk);
400
401 /* Configure the I2S pins in correct mode */
402 s3c2410_gpio_cfgpin(S3C2410_GPE0, S3C2410_GPE0_I2SLRCK);
403 s3c2410_gpio_cfgpin(S3C2410_GPE1, S3C2410_GPE1_I2SSCLK);
404 s3c2410_gpio_cfgpin(S3C2410_GPE2, S3C2410_GPE2_CDCLK);
405 s3c2410_gpio_cfgpin(S3C2410_GPE3, S3C2410_GPE3_I2SSDI);
406 s3c2410_gpio_cfgpin(S3C2410_GPE4, S3C2410_GPE4_I2SSDO);
407
408 writel(S3C2410_IISCON_IISEN, s3c24xx_i2s.regs + S3C2410_IISCON);
409
410 s3c24xx_snd_txctrl(0);
411 s3c24xx_snd_rxctrl(0);
412
413 return 0;
414}
415
Graeme Gregory5cd919a2008-01-10 14:44:58 +0100416#ifdef CONFIG_PM
Mark Browndc7d7b82008-12-03 18:21:52 +0000417static int s3c24xx_i2s_suspend(struct snd_soc_dai *cpu_dai)
Graeme Gregory5cd919a2008-01-10 14:44:58 +0100418{
Mark Brownee7d4762009-03-06 18:04:34 +0000419 pr_debug("Entered %s\n", __func__);
Tim Niemeyer40920302008-04-22 18:26:59 +0200420
Graeme Gregory5cd919a2008-01-10 14:44:58 +0100421 s3c24xx_i2s.iiscon = readl(s3c24xx_i2s.regs + S3C2410_IISCON);
422 s3c24xx_i2s.iismod = readl(s3c24xx_i2s.regs + S3C2410_IISMOD);
423 s3c24xx_i2s.iisfcon = readl(s3c24xx_i2s.regs + S3C2410_IISFCON);
424 s3c24xx_i2s.iispsr = readl(s3c24xx_i2s.regs + S3C2410_IISPSR);
425
426 clk_disable(s3c24xx_i2s.iis_clk);
427
428 return 0;
429}
430
Mark Browndc7d7b82008-12-03 18:21:52 +0000431static int s3c24xx_i2s_resume(struct snd_soc_dai *cpu_dai)
Graeme Gregory5cd919a2008-01-10 14:44:58 +0100432{
Mark Brownee7d4762009-03-06 18:04:34 +0000433 pr_debug("Entered %s\n", __func__);
Graeme Gregory5cd919a2008-01-10 14:44:58 +0100434 clk_enable(s3c24xx_i2s.iis_clk);
435
436 writel(s3c24xx_i2s.iiscon, s3c24xx_i2s.regs + S3C2410_IISCON);
437 writel(s3c24xx_i2s.iismod, s3c24xx_i2s.regs + S3C2410_IISMOD);
438 writel(s3c24xx_i2s.iisfcon, s3c24xx_i2s.regs + S3C2410_IISFCON);
439 writel(s3c24xx_i2s.iispsr, s3c24xx_i2s.regs + S3C2410_IISPSR);
440
441 return 0;
442}
443#else
444#define s3c24xx_i2s_suspend NULL
445#define s3c24xx_i2s_resume NULL
446#endif
447
448
Ben Dooksc1422a62007-02-14 13:17:49 +0100449#define S3C24XX_I2S_RATES \
450 (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_11025 | SNDRV_PCM_RATE_16000 | \
451 SNDRV_PCM_RATE_22050 | SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_44100 | \
452 SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_88200 | SNDRV_PCM_RATE_96000)
453
Eric Miao6335d052009-03-03 09:41:00 +0800454static struct snd_soc_dai_ops s3c24xx_i2s_dai_ops = {
455 .trigger = s3c24xx_i2s_trigger,
456 .hw_params = s3c24xx_i2s_hw_params,
457 .set_fmt = s3c24xx_i2s_set_fmt,
458 .set_clkdiv = s3c24xx_i2s_set_clkdiv,
459 .set_sysclk = s3c24xx_i2s_set_sysclk,
460};
461
Liam Girdwood1992a6f2008-07-07 16:08:24 +0100462struct snd_soc_dai s3c24xx_i2s_dai = {
Ben Dooksc1422a62007-02-14 13:17:49 +0100463 .name = "s3c24xx-i2s",
464 .id = 0,
Ben Dooksc1422a62007-02-14 13:17:49 +0100465 .probe = s3c24xx_i2s_probe,
Graeme Gregory5cd919a2008-01-10 14:44:58 +0100466 .suspend = s3c24xx_i2s_suspend,
467 .resume = s3c24xx_i2s_resume,
Ben Dooksc1422a62007-02-14 13:17:49 +0100468 .playback = {
469 .channels_min = 2,
470 .channels_max = 2,
471 .rates = S3C24XX_I2S_RATES,
472 .formats = SNDRV_PCM_FMTBIT_S8 | SNDRV_PCM_FMTBIT_S16_LE,},
473 .capture = {
474 .channels_min = 2,
475 .channels_max = 2,
476 .rates = S3C24XX_I2S_RATES,
477 .formats = SNDRV_PCM_FMTBIT_S8 | SNDRV_PCM_FMTBIT_S16_LE,},
Eric Miao6335d052009-03-03 09:41:00 +0800478 .ops = &s3c24xx_i2s_dai_ops,
Ben Dooksc1422a62007-02-14 13:17:49 +0100479};
480EXPORT_SYMBOL_GPL(s3c24xx_i2s_dai);
481
Takashi Iwaic9b3a402008-12-10 07:47:22 +0100482static int __init s3c24xx_i2s_init(void)
Mark Brown3f4b7832008-12-03 19:26:35 +0000483{
484 return snd_soc_register_dai(&s3c24xx_i2s_dai);
485}
486module_init(s3c24xx_i2s_init);
487
488static void __exit s3c24xx_i2s_exit(void)
489{
490 snd_soc_unregister_dai(&s3c24xx_i2s_dai);
491}
492module_exit(s3c24xx_i2s_exit);
493
Ben Dooksc1422a62007-02-14 13:17:49 +0100494/* Module information */
495MODULE_AUTHOR("Ben Dooks, <ben@simtec.co.uk>");
496MODULE_DESCRIPTION("s3c24xx I2S SoC Interface");
497MODULE_LICENSE("GPL");