blob: aeea49cbe74a4f8d5a361910da6b13de806b8b2c [file] [log] [blame]
Ben Dooksdc854472009-03-04 00:49:30 +00001/* sound/soc/s3c24xx/s3c-i2c-v2.c
2 *
3 * ALSA Soc Audio Layer - I2S core for newer Samsung SoCs.
4 *
5 * Copyright (c) 2006 Wolfson Microelectronics PLC.
6 * Graeme Gregory graeme.gregory@wolfsonmicro.com
7 * linux@wolfsonmicro.com
8 *
9 * Copyright (c) 2008, 2007, 2004-2005 Simtec Electronics
10 * http://armlinux.simtec.co.uk/
11 * Ben Dooks <ben@simtec.co.uk>
12 *
13 * This program is free software; you can redistribute it and/or modify it
14 * under the terms of the GNU General Public License as published by the
15 * Free Software Foundation; either version 2 of the License, or (at your
16 * option) any later version.
17 */
18
19#include <linux/init.h>
20#include <linux/module.h>
21#include <linux/device.h>
22#include <linux/delay.h>
23#include <linux/clk.h>
24#include <linux/kernel.h>
25#include <linux/io.h>
26
27#include <sound/core.h>
28#include <sound/pcm.h>
29#include <sound/pcm_params.h>
30#include <sound/initval.h>
31#include <sound/soc.h>
32
33#include <plat/regs-s3c2412-iis.h>
34
35#include <plat/audio.h>
36#include <mach/dma.h>
37
38#include "s3c-i2s-v2.h"
39
40#define S3C2412_I2S_DEBUG_CON 0
Ben Dooksdc854472009-03-04 00:49:30 +000041
42static inline struct s3c_i2sv2_info *to_info(struct snd_soc_dai *cpu_dai)
43{
44 return cpu_dai->private_data;
45}
46
47#define bit_set(v, b) (((v) & (b)) ? 1 : 0)
48
49#if S3C2412_I2S_DEBUG_CON
50static void dbg_showcon(const char *fn, u32 con)
51{
52 printk(KERN_DEBUG "%s: LRI=%d, TXFEMPT=%d, RXFEMPT=%d, TXFFULL=%d, RXFFULL=%d\n", fn,
53 bit_set(con, S3C2412_IISCON_LRINDEX),
54 bit_set(con, S3C2412_IISCON_TXFIFO_EMPTY),
55 bit_set(con, S3C2412_IISCON_RXFIFO_EMPTY),
56 bit_set(con, S3C2412_IISCON_TXFIFO_FULL),
57 bit_set(con, S3C2412_IISCON_RXFIFO_FULL));
58
59 printk(KERN_DEBUG "%s: PAUSE: TXDMA=%d, RXDMA=%d, TXCH=%d, RXCH=%d\n",
60 fn,
61 bit_set(con, S3C2412_IISCON_TXDMA_PAUSE),
62 bit_set(con, S3C2412_IISCON_RXDMA_PAUSE),
63 bit_set(con, S3C2412_IISCON_TXCH_PAUSE),
64 bit_set(con, S3C2412_IISCON_RXCH_PAUSE));
65 printk(KERN_DEBUG "%s: ACTIVE: TXDMA=%d, RXDMA=%d, IIS=%d\n", fn,
66 bit_set(con, S3C2412_IISCON_TXDMA_ACTIVE),
67 bit_set(con, S3C2412_IISCON_RXDMA_ACTIVE),
68 bit_set(con, S3C2412_IISCON_IIS_ACTIVE));
69}
70#else
71static inline void dbg_showcon(const char *fn, u32 con)
72{
73}
74#endif
75
76
77/* Turn on or off the transmission path. */
78void s3c2412_snd_txctrl(struct s3c_i2sv2_info *i2s, int on)
79{
80 void __iomem *regs = i2s->regs;
81 u32 fic, con, mod;
82
Mark Brownee7d4762009-03-06 18:04:34 +000083 pr_debug("%s(%d)\n", __func__, on);
Ben Dooksdc854472009-03-04 00:49:30 +000084
85 fic = readl(regs + S3C2412_IISFIC);
86 con = readl(regs + S3C2412_IISCON);
87 mod = readl(regs + S3C2412_IISMOD);
88
Mark Brownee7d4762009-03-06 18:04:34 +000089 pr_debug("%s: IIS: CON=%x MOD=%x FIC=%x\n", __func__, con, mod, fic);
Ben Dooksdc854472009-03-04 00:49:30 +000090
91 if (on) {
92 con |= S3C2412_IISCON_TXDMA_ACTIVE | S3C2412_IISCON_IIS_ACTIVE;
93 con &= ~S3C2412_IISCON_TXDMA_PAUSE;
94 con &= ~S3C2412_IISCON_TXCH_PAUSE;
95
96 switch (mod & S3C2412_IISMOD_MODE_MASK) {
97 case S3C2412_IISMOD_MODE_TXONLY:
98 case S3C2412_IISMOD_MODE_TXRX:
99 /* do nothing, we are in the right mode */
100 break;
101
102 case S3C2412_IISMOD_MODE_RXONLY:
103 mod &= ~S3C2412_IISMOD_MODE_MASK;
104 mod |= S3C2412_IISMOD_MODE_TXRX;
105 break;
106
107 default:
Mark Brown5c556a62009-04-27 20:23:19 +0100108 dev_err(i2s->dev, "TXEN: Invalid MODE %x in IISMOD\n",
109 mod & S3C2412_IISMOD_MODE_MASK);
110 break;
Ben Dooksdc854472009-03-04 00:49:30 +0000111 }
112
113 writel(con, regs + S3C2412_IISCON);
114 writel(mod, regs + S3C2412_IISMOD);
115 } else {
116 /* Note, we do not have any indication that the FIFO problems
117 * tha the S3C2410/2440 had apply here, so we should be able
118 * to disable the DMA and TX without resetting the FIFOS.
119 */
120
121 con |= S3C2412_IISCON_TXDMA_PAUSE;
122 con |= S3C2412_IISCON_TXCH_PAUSE;
123 con &= ~S3C2412_IISCON_TXDMA_ACTIVE;
124
125 switch (mod & S3C2412_IISMOD_MODE_MASK) {
126 case S3C2412_IISMOD_MODE_TXRX:
127 mod &= ~S3C2412_IISMOD_MODE_MASK;
128 mod |= S3C2412_IISMOD_MODE_RXONLY;
129 break;
130
131 case S3C2412_IISMOD_MODE_TXONLY:
132 mod &= ~S3C2412_IISMOD_MODE_MASK;
133 con &= ~S3C2412_IISCON_IIS_ACTIVE;
134 break;
135
136 default:
Mark Brown5c556a62009-04-27 20:23:19 +0100137 dev_err(i2s->dev, "TXDIS: Invalid MODE %xin IISMOD\n",
138 mod & S3C2412_IISMOD_MODE_MASK);
139 break;
Ben Dooksdc854472009-03-04 00:49:30 +0000140 }
141
142 writel(mod, regs + S3C2412_IISMOD);
143 writel(con, regs + S3C2412_IISCON);
144 }
145
146 fic = readl(regs + S3C2412_IISFIC);
147 dbg_showcon(__func__, con);
Mark Brownee7d4762009-03-06 18:04:34 +0000148 pr_debug("%s: IIS: CON=%x MOD=%x FIC=%x\n", __func__, con, mod, fic);
Ben Dooksdc854472009-03-04 00:49:30 +0000149}
150EXPORT_SYMBOL_GPL(s3c2412_snd_txctrl);
151
152void s3c2412_snd_rxctrl(struct s3c_i2sv2_info *i2s, int on)
153{
154 void __iomem *regs = i2s->regs;
155 u32 fic, con, mod;
156
Mark Brownee7d4762009-03-06 18:04:34 +0000157 pr_debug("%s(%d)\n", __func__, on);
Ben Dooksdc854472009-03-04 00:49:30 +0000158
159 fic = readl(regs + S3C2412_IISFIC);
160 con = readl(regs + S3C2412_IISCON);
161 mod = readl(regs + S3C2412_IISMOD);
162
Mark Brownee7d4762009-03-06 18:04:34 +0000163 pr_debug("%s: IIS: CON=%x MOD=%x FIC=%x\n", __func__, con, mod, fic);
Ben Dooksdc854472009-03-04 00:49:30 +0000164
165 if (on) {
166 con |= S3C2412_IISCON_RXDMA_ACTIVE | S3C2412_IISCON_IIS_ACTIVE;
167 con &= ~S3C2412_IISCON_RXDMA_PAUSE;
168 con &= ~S3C2412_IISCON_RXCH_PAUSE;
169
170 switch (mod & S3C2412_IISMOD_MODE_MASK) {
171 case S3C2412_IISMOD_MODE_TXRX:
172 case S3C2412_IISMOD_MODE_RXONLY:
173 /* do nothing, we are in the right mode */
174 break;
175
176 case S3C2412_IISMOD_MODE_TXONLY:
177 mod &= ~S3C2412_IISMOD_MODE_MASK;
178 mod |= S3C2412_IISMOD_MODE_TXRX;
179 break;
180
181 default:
Mark Brown5c556a62009-04-27 20:23:19 +0100182 dev_err(i2s->dev, "RXEN: Invalid MODE %x in IISMOD\n",
183 mod & S3C2412_IISMOD_MODE_MASK);
Ben Dooksdc854472009-03-04 00:49:30 +0000184 }
185
186 writel(mod, regs + S3C2412_IISMOD);
187 writel(con, regs + S3C2412_IISCON);
188 } else {
189 /* See txctrl notes on FIFOs. */
190
191 con &= ~S3C2412_IISCON_RXDMA_ACTIVE;
192 con |= S3C2412_IISCON_RXDMA_PAUSE;
193 con |= S3C2412_IISCON_RXCH_PAUSE;
194
195 switch (mod & S3C2412_IISMOD_MODE_MASK) {
196 case S3C2412_IISMOD_MODE_RXONLY:
197 con &= ~S3C2412_IISCON_IIS_ACTIVE;
198 mod &= ~S3C2412_IISMOD_MODE_MASK;
199 break;
200
201 case S3C2412_IISMOD_MODE_TXRX:
202 mod &= ~S3C2412_IISMOD_MODE_MASK;
203 mod |= S3C2412_IISMOD_MODE_TXONLY;
204 break;
205
206 default:
Mark Brown5c556a62009-04-27 20:23:19 +0100207 dev_err(i2s->dev, "RXEN: Invalid MODE %x in IISMOD\n",
208 mod & S3C2412_IISMOD_MODE_MASK);
Ben Dooksdc854472009-03-04 00:49:30 +0000209 }
210
211 writel(con, regs + S3C2412_IISCON);
212 writel(mod, regs + S3C2412_IISMOD);
213 }
214
215 fic = readl(regs + S3C2412_IISFIC);
Mark Brownee7d4762009-03-06 18:04:34 +0000216 pr_debug("%s: IIS: CON=%x MOD=%x FIC=%x\n", __func__, con, mod, fic);
Ben Dooksdc854472009-03-04 00:49:30 +0000217}
218EXPORT_SYMBOL_GPL(s3c2412_snd_rxctrl);
219
220/*
221 * Wait for the LR signal to allow synchronisation to the L/R clock
222 * from the codec. May only be needed for slave mode.
223 */
224static int s3c2412_snd_lrsync(struct s3c_i2sv2_info *i2s)
225{
226 u32 iiscon;
227 unsigned long timeout = jiffies + msecs_to_jiffies(5);
228
Mark Brownee7d4762009-03-06 18:04:34 +0000229 pr_debug("Entered %s\n", __func__);
Ben Dooksdc854472009-03-04 00:49:30 +0000230
231 while (1) {
232 iiscon = readl(i2s->regs + S3C2412_IISCON);
233 if (iiscon & S3C2412_IISCON_LRINDEX)
234 break;
235
236 if (timeout < jiffies) {
237 printk(KERN_ERR "%s: timeout\n", __func__);
238 return -ETIMEDOUT;
239 }
240 }
241
242 return 0;
243}
244
245/*
246 * Set S3C2412 I2S DAI format
247 */
248static int s3c2412_i2s_set_fmt(struct snd_soc_dai *cpu_dai,
249 unsigned int fmt)
250{
251 struct s3c_i2sv2_info *i2s = to_info(cpu_dai);
252 u32 iismod;
253
Mark Brownee7d4762009-03-06 18:04:34 +0000254 pr_debug("Entered %s\n", __func__);
Ben Dooksdc854472009-03-04 00:49:30 +0000255
256 iismod = readl(i2s->regs + S3C2412_IISMOD);
Mark Brownee7d4762009-03-06 18:04:34 +0000257 pr_debug("hw_params r: IISMOD: %x \n", iismod);
Ben Dooksdc854472009-03-04 00:49:30 +0000258
259#if defined(CONFIG_CPU_S3C2412) || defined(CONFIG_CPU_S3C2413)
260#define IISMOD_MASTER_MASK S3C2412_IISMOD_MASTER_MASK
261#define IISMOD_SLAVE S3C2412_IISMOD_SLAVE
262#define IISMOD_MASTER S3C2412_IISMOD_MASTER_INTERNAL
263#endif
264
265#if defined(CONFIG_PLAT_S3C64XX)
266/* From Rev1.1 datasheet, we have two master and two slave modes:
267 * IMS[11:10]:
268 * 00 = master mode, fed from PCLK
269 * 01 = master mode, fed from CLKAUDIO
270 * 10 = slave mode, using PCLK
271 * 11 = slave mode, using I2SCLK
272 */
273#define IISMOD_MASTER_MASK (1 << 11)
274#define IISMOD_SLAVE (1 << 11)
275#define IISMOD_MASTER (0x0)
276#endif
277
278 switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
279 case SND_SOC_DAIFMT_CBM_CFM:
280 i2s->master = 0;
281 iismod &= ~IISMOD_MASTER_MASK;
282 iismod |= IISMOD_SLAVE;
283 break;
284 case SND_SOC_DAIFMT_CBS_CFS:
285 i2s->master = 1;
286 iismod &= ~IISMOD_MASTER_MASK;
287 iismod |= IISMOD_MASTER;
288 break;
289 default:
Mark Brown5c556a62009-04-27 20:23:19 +0100290 pr_err("unknwon master/slave format\n");
Ben Dooksdc854472009-03-04 00:49:30 +0000291 return -EINVAL;
292 }
293
294 iismod &= ~S3C2412_IISMOD_SDF_MASK;
295
296 switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
297 case SND_SOC_DAIFMT_RIGHT_J:
298 iismod |= S3C2412_IISMOD_SDF_MSB;
299 break;
300 case SND_SOC_DAIFMT_LEFT_J:
301 iismod |= S3C2412_IISMOD_SDF_LSB;
302 break;
303 case SND_SOC_DAIFMT_I2S:
304 iismod |= S3C2412_IISMOD_SDF_IIS;
305 break;
306 default:
Mark Brown5c556a62009-04-27 20:23:19 +0100307 pr_err("Unknown data format\n");
Ben Dooksdc854472009-03-04 00:49:30 +0000308 return -EINVAL;
309 }
310
311 writel(iismod, i2s->regs + S3C2412_IISMOD);
Mark Brownee7d4762009-03-06 18:04:34 +0000312 pr_debug("hw_params w: IISMOD: %x \n", iismod);
Ben Dooksdc854472009-03-04 00:49:30 +0000313 return 0;
314}
315
316static int s3c2412_i2s_hw_params(struct snd_pcm_substream *substream,
317 struct snd_pcm_hw_params *params,
318 struct snd_soc_dai *socdai)
319{
320 struct snd_soc_pcm_runtime *rtd = substream->private_data;
321 struct snd_soc_dai_link *dai = rtd->dai;
322 struct s3c_i2sv2_info *i2s = to_info(dai->cpu_dai);
323 u32 iismod;
324
Mark Brownee7d4762009-03-06 18:04:34 +0000325 pr_debug("Entered %s\n", __func__);
Ben Dooksdc854472009-03-04 00:49:30 +0000326
327 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
328 dai->cpu_dai->dma_data = i2s->dma_playback;
329 else
330 dai->cpu_dai->dma_data = i2s->dma_capture;
331
332 /* Working copies of register */
333 iismod = readl(i2s->regs + S3C2412_IISMOD);
Mark Brownee7d4762009-03-06 18:04:34 +0000334 pr_debug("%s: r: IISMOD: %x\n", __func__, iismod);
Ben Dooksdc854472009-03-04 00:49:30 +0000335
336 switch (params_format(params)) {
337 case SNDRV_PCM_FORMAT_S8:
338 iismod |= S3C2412_IISMOD_8BIT;
339 break;
340 case SNDRV_PCM_FORMAT_S16_LE:
341 iismod &= ~S3C2412_IISMOD_8BIT;
342 break;
343 }
344
345 writel(iismod, i2s->regs + S3C2412_IISMOD);
Mark Brownee7d4762009-03-06 18:04:34 +0000346 pr_debug("%s: w: IISMOD: %x\n", __func__, iismod);
Ben Dooksdc854472009-03-04 00:49:30 +0000347 return 0;
348}
349
350static int s3c2412_i2s_trigger(struct snd_pcm_substream *substream, int cmd,
351 struct snd_soc_dai *dai)
352{
353 struct snd_soc_pcm_runtime *rtd = substream->private_data;
354 struct s3c_i2sv2_info *i2s = to_info(rtd->dai->cpu_dai);
355 int capture = (substream->stream == SNDRV_PCM_STREAM_CAPTURE);
356 unsigned long irqs;
357 int ret = 0;
358
Mark Brownee7d4762009-03-06 18:04:34 +0000359 pr_debug("Entered %s\n", __func__);
Ben Dooksdc854472009-03-04 00:49:30 +0000360
361 switch (cmd) {
362 case SNDRV_PCM_TRIGGER_START:
363 /* On start, ensure that the FIFOs are cleared and reset. */
364
365 writel(capture ? S3C2412_IISFIC_RXFLUSH : S3C2412_IISFIC_TXFLUSH,
366 i2s->regs + S3C2412_IISFIC);
367
368 /* clear again, just in case */
369 writel(0x0, i2s->regs + S3C2412_IISFIC);
370
371 case SNDRV_PCM_TRIGGER_RESUME:
372 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
373 if (!i2s->master) {
374 ret = s3c2412_snd_lrsync(i2s);
375 if (ret)
376 goto exit_err;
377 }
378
379 local_irq_save(irqs);
380
381 if (capture)
382 s3c2412_snd_rxctrl(i2s, 1);
383 else
384 s3c2412_snd_txctrl(i2s, 1);
385
386 local_irq_restore(irqs);
387 break;
388
389 case SNDRV_PCM_TRIGGER_STOP:
390 case SNDRV_PCM_TRIGGER_SUSPEND:
391 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
392 local_irq_save(irqs);
393
394 if (capture)
395 s3c2412_snd_rxctrl(i2s, 0);
396 else
397 s3c2412_snd_txctrl(i2s, 0);
398
399 local_irq_restore(irqs);
400 break;
401 default:
402 ret = -EINVAL;
403 break;
404 }
405
406exit_err:
407 return ret;
408}
409
410/*
411 * Set S3C2412 Clock dividers
412 */
413static int s3c2412_i2s_set_clkdiv(struct snd_soc_dai *cpu_dai,
414 int div_id, int div)
415{
416 struct s3c_i2sv2_info *i2s = to_info(cpu_dai);
417 u32 reg;
418
Mark Brownee7d4762009-03-06 18:04:34 +0000419 pr_debug("%s(%p, %d, %d)\n", __func__, cpu_dai, div_id, div);
Ben Dooksdc854472009-03-04 00:49:30 +0000420
421 switch (div_id) {
422 case S3C_I2SV2_DIV_BCLK:
423 reg = readl(i2s->regs + S3C2412_IISMOD);
424 reg &= ~S3C2412_IISMOD_BCLK_MASK;
425 writel(reg | div, i2s->regs + S3C2412_IISMOD);
426
Mark Brownee7d4762009-03-06 18:04:34 +0000427 pr_debug("%s: MOD=%08x\n", __func__, readl(i2s->regs + S3C2412_IISMOD));
Ben Dooksdc854472009-03-04 00:49:30 +0000428 break;
429
430 case S3C_I2SV2_DIV_RCLK:
431 if (div > 3) {
432 /* convert value to bit field */
433
434 switch (div) {
435 case 256:
436 div = S3C2412_IISMOD_RCLK_256FS;
437 break;
438
439 case 384:
440 div = S3C2412_IISMOD_RCLK_384FS;
441 break;
442
443 case 512:
444 div = S3C2412_IISMOD_RCLK_512FS;
445 break;
446
447 case 768:
448 div = S3C2412_IISMOD_RCLK_768FS;
449 break;
450
451 default:
452 return -EINVAL;
453 }
454 }
455
456 reg = readl(i2s->regs + S3C2412_IISMOD);
457 reg &= ~S3C2412_IISMOD_RCLK_MASK;
458 writel(reg | div, i2s->regs + S3C2412_IISMOD);
Mark Brownee7d4762009-03-06 18:04:34 +0000459 pr_debug("%s: MOD=%08x\n", __func__, readl(i2s->regs + S3C2412_IISMOD));
Ben Dooksdc854472009-03-04 00:49:30 +0000460 break;
461
462 case S3C_I2SV2_DIV_PRESCALER:
463 if (div >= 0) {
464 writel((div << 8) | S3C2412_IISPSR_PSREN,
465 i2s->regs + S3C2412_IISPSR);
466 } else {
467 writel(0x0, i2s->regs + S3C2412_IISPSR);
468 }
Mark Brownee7d4762009-03-06 18:04:34 +0000469 pr_debug("%s: PSR=%08x\n", __func__, readl(i2s->regs + S3C2412_IISPSR));
Ben Dooksdc854472009-03-04 00:49:30 +0000470 break;
471
472 default:
473 return -EINVAL;
474 }
475
476 return 0;
477}
478
479/* default table of all avaialable root fs divisors */
480static unsigned int iis_fs_tab[] = { 256, 512, 384, 768 };
481
Ben Dooks1d2b7ae2009-04-16 10:32:23 +0100482int s3c_i2sv2_iis_calc_rate(struct s3c_i2sv2_rate_calc *info,
483 unsigned int *fstab,
484 unsigned int rate, struct clk *clk)
Ben Dooksdc854472009-03-04 00:49:30 +0000485{
486 unsigned long clkrate = clk_get_rate(clk);
487 unsigned int div;
488 unsigned int fsclk;
489 unsigned int actual;
490 unsigned int fs;
491 unsigned int fsdiv;
492 signed int deviation = 0;
493 unsigned int best_fs = 0;
494 unsigned int best_div = 0;
495 unsigned int best_rate = 0;
496 unsigned int best_deviation = INT_MAX;
497
498 if (fstab == NULL)
499 fstab = iis_fs_tab;
500
501 for (fs = 0; fs < ARRAY_SIZE(iis_fs_tab); fs++) {
502 fsdiv = iis_fs_tab[fs];
503
504 fsclk = clkrate / fsdiv;
505 div = fsclk / rate;
506
507 if ((fsclk % rate) > (rate / 2))
508 div++;
509
510 if (div <= 1)
511 continue;
512
513 actual = clkrate / (fsdiv * div);
514 deviation = actual - rate;
515
516 printk(KERN_DEBUG "%dfs: div %d => result %d, deviation %d\n",
517 fsdiv, div, actual, deviation);
518
519 deviation = abs(deviation);
520
521 if (deviation < best_deviation) {
522 best_fs = fsdiv;
523 best_div = div;
524 best_rate = actual;
525 best_deviation = deviation;
526 }
527
528 if (deviation == 0)
529 break;
530 }
531
532 printk(KERN_DEBUG "best: fs=%d, div=%d, rate=%d\n",
533 best_fs, best_div, best_rate);
534
535 info->fs_div = best_fs;
536 info->clk_div = best_div;
537
538 return 0;
539}
Ben Dooks1d2b7ae2009-04-16 10:32:23 +0100540EXPORT_SYMBOL_GPL(s3c_i2sv2_iis_calc_rate);
Ben Dooksdc854472009-03-04 00:49:30 +0000541
542int s3c_i2sv2_probe(struct platform_device *pdev,
543 struct snd_soc_dai *dai,
544 struct s3c_i2sv2_info *i2s,
545 unsigned long base)
546{
547 struct device *dev = &pdev->dev;
548
549 i2s->dev = dev;
550
551 /* record our i2s structure for later use in the callbacks */
552 dai->private_data = i2s;
553
554 i2s->regs = ioremap(base, 0x100);
555 if (i2s->regs == NULL) {
556 dev_err(dev, "cannot ioremap registers\n");
557 return -ENXIO;
558 }
559
560 i2s->iis_pclk = clk_get(dev, "iis");
561 if (i2s->iis_pclk == NULL) {
Mark Brownb52a5192009-03-06 18:13:43 +0000562 dev_err(dev, "failed to get iis_clock\n");
Ben Dooksdc854472009-03-04 00:49:30 +0000563 iounmap(i2s->regs);
564 return -ENOENT;
565 }
566
567 clk_enable(i2s->iis_pclk);
568
569 s3c2412_snd_txctrl(i2s, 0);
570 s3c2412_snd_rxctrl(i2s, 0);
571
572 return 0;
573}
574
575EXPORT_SYMBOL_GPL(s3c_i2sv2_probe);
576
577#ifdef CONFIG_PM
578static int s3c2412_i2s_suspend(struct snd_soc_dai *dai)
579{
580 struct s3c_i2sv2_info *i2s = to_info(dai);
581 u32 iismod;
582
583 if (dai->active) {
584 i2s->suspend_iismod = readl(i2s->regs + S3C2412_IISMOD);
585 i2s->suspend_iiscon = readl(i2s->regs + S3C2412_IISCON);
586 i2s->suspend_iispsr = readl(i2s->regs + S3C2412_IISPSR);
587
588 /* some basic suspend checks */
589
590 iismod = readl(i2s->regs + S3C2412_IISMOD);
591
592 if (iismod & S3C2412_IISCON_RXDMA_ACTIVE)
593 pr_warning("%s: RXDMA active?\n", __func__);
594
595 if (iismod & S3C2412_IISCON_TXDMA_ACTIVE)
596 pr_warning("%s: TXDMA active?\n", __func__);
597
598 if (iismod & S3C2412_IISCON_IIS_ACTIVE)
599 pr_warning("%s: IIS active\n", __func__);
600 }
601
602 return 0;
603}
604
605static int s3c2412_i2s_resume(struct snd_soc_dai *dai)
606{
607 struct s3c_i2sv2_info *i2s = to_info(dai);
608
609 pr_info("dai_active %d, IISMOD %08x, IISCON %08x\n",
610 dai->active, i2s->suspend_iismod, i2s->suspend_iiscon);
611
612 if (dai->active) {
613 writel(i2s->suspend_iiscon, i2s->regs + S3C2412_IISCON);
614 writel(i2s->suspend_iismod, i2s->regs + S3C2412_IISMOD);
615 writel(i2s->suspend_iispsr, i2s->regs + S3C2412_IISPSR);
616
617 writel(S3C2412_IISFIC_RXFLUSH | S3C2412_IISFIC_TXFLUSH,
618 i2s->regs + S3C2412_IISFIC);
619
620 ndelay(250);
621 writel(0x0, i2s->regs + S3C2412_IISFIC);
622 }
623
624 return 0;
625}
626#else
627#define s3c2412_i2s_suspend NULL
628#define s3c2412_i2s_resume NULL
629#endif
630
631int s3c_i2sv2_register_dai(struct snd_soc_dai *dai)
632{
Ben Dooks3715c6a2009-04-16 10:32:22 +0100633 struct snd_soc_dai_ops *ops = dai->ops;
634
635 ops->trigger = s3c2412_i2s_trigger;
636 ops->hw_params = s3c2412_i2s_hw_params;
637 ops->set_fmt = s3c2412_i2s_set_fmt;
638 ops->set_clkdiv = s3c2412_i2s_set_clkdiv;
Ben Dooksdc854472009-03-04 00:49:30 +0000639
640 dai->suspend = s3c2412_i2s_suspend;
641 dai->resume = s3c2412_i2s_resume;
642
643 return snd_soc_register_dai(dai);
644}
Ben Dooksdc854472009-03-04 00:49:30 +0000645EXPORT_SYMBOL_GPL(s3c_i2sv2_register_dai);
Mark Browna396e322009-04-23 15:43:45 +0100646
647MODULE_LICENSE("GPL");