19 #include <linux/module.h>
33 #undef S3C_IIS_V2_SUPPORTED
35 #if defined(CONFIG_CPU_S3C2412) || defined(CONFIG_CPU_S3C2413) \
36 || defined(CONFIG_CPU_S5PV210)
37 #define S3C_IIS_V2_SUPPORTED
40 #ifdef CONFIG_PLAT_S3C64XX
41 #define S3C_IIS_V2_SUPPORTED
44 #ifndef S3C_IIS_V2_SUPPORTED
45 #error Unsupported CPU model
48 #define S3C2412_I2S_DEBUG_CON 0
52 return snd_soc_dai_get_drvdata(cpu_dai);
55 #define bit_set(v, b) (((v) & (b)) ? 1 : 0)
57 #if S3C2412_I2S_DEBUG_CON
58 static void dbg_showcon(
const char *
fn,
u32 con)
60 printk(
KERN_DEBUG "%s: LRI=%d, TXFEMPT=%d, RXFEMPT=%d, TXFFULL=%d, RXFFULL=%d\n", fn,
79 static inline void dbg_showcon(
const char *
fn,
u32 con)
97 pr_debug(
"%s: IIS: CON=%x MOD=%x FIC=%x\n", __func__, con, mod, fic);
111 mod &= ~S3C2412_IISMOD_MODE_MASK;
116 dev_err(i2s->
dev,
"TXEN: Invalid MODE %x in IISMOD\n",
117 mod & S3C2412_IISMOD_MODE_MASK);
135 mod &= ~S3C2412_IISMOD_MODE_MASK;
140 mod &= ~S3C2412_IISMOD_MODE_MASK;
145 dev_err(i2s->
dev,
"TXDIS: Invalid MODE %x in IISMOD\n",
146 mod & S3C2412_IISMOD_MODE_MASK);
155 dbg_showcon(__func__, con);
156 pr_debug(
"%s: IIS: CON=%x MOD=%x FIC=%x\n", __func__, con, mod, fic);
159 static void s3c2412_snd_rxctrl(
struct s3c_i2sv2_info *i2s,
int on)
170 pr_debug(
"%s: IIS: CON=%x MOD=%x FIC=%x\n", __func__, con, mod, fic);
184 mod &= ~S3C2412_IISMOD_MODE_MASK;
189 dev_err(i2s->
dev,
"RXEN: Invalid MODE %x in IISMOD\n",
190 mod & S3C2412_IISMOD_MODE_MASK);
205 mod &= ~S3C2412_IISMOD_MODE_MASK;
209 mod &= ~S3C2412_IISMOD_MODE_MASK;
214 dev_err(i2s->
dev,
"RXDIS: Invalid MODE %x in IISMOD\n",
215 mod & S3C2412_IISMOD_MODE_MASK);
223 pr_debug(
"%s: IIS: CON=%x MOD=%x FIC=%x\n", __func__, con, mod, fic);
226 #define msecs_to_loops(t) (loops_per_jiffy / 1000 * HZ * t)
258 static int s3c2412_i2s_set_fmt(
struct snd_soc_dai *cpu_dai,
267 pr_debug(
"hw_params r: IISMOD: %x \n", iismod);
279 pr_err(
"unknwon master/slave format\n");
299 pr_err(
"Unknown data format\n");
304 pr_debug(
"hw_params w: IISMOD: %x \n", iismod);
323 snd_soc_dai_set_dma_data(dai, substream, dma_data);
327 pr_debug(
"%s: r: IISMOD: %x\n", __func__, iismod);
343 pr_debug(
"%s: w: IISMOD: %x\n", __func__, iismod);
348 static int s3c_i2sv2_set_sysclk(
struct snd_soc_dai *cpu_dai,
349 int clk_id,
unsigned int freq,
int dir)
355 pr_debug(
"%s r: IISMOD: %x\n", __func__, iismod);
388 pr_debug(
"%s w: IISMOD: %x\n", __func__, iismod);
402 snd_soc_dai_get_dma_data(rtd->
cpu_dai, substream);
419 ret = s3c2412_snd_lrsync(i2s);
427 s3c2412_snd_rxctrl(i2s, 1);
429 s3c2412_snd_txctrl(i2s, 1);
448 s3c2412_snd_rxctrl(i2s, 0);
450 s3c2412_snd_txctrl(i2s, 0);
466 static int s3c2412_i2s_set_clkdiv(
struct snd_soc_dai *cpu_dai,
472 pr_debug(
"%s(%p, %d, %d)\n", __func__, cpu_dai, div_id, div);
577 static unsigned int iis_fs_tab[] = { 256, 512, 384, 768 };
589 signed int deviation = 0;
590 unsigned int best_fs = 0;
591 unsigned int best_div = 0;
592 unsigned int best_rate = 0;
593 unsigned int best_deviation =
INT_MAX;
595 pr_debug(
"Input clock rate %ldHz\n", clkrate);
600 for (fs = 0; fs <
ARRAY_SIZE(iis_fs_tab); fs++) {
601 fsdiv = iis_fs_tab[
fs];
603 fsclk = clkrate / fsdiv;
606 if ((fsclk % rate) > (rate / 2))
612 actual = clkrate / (fsdiv *
div);
613 deviation = actual -
rate;
616 fsdiv, div, actual, deviation);
618 deviation =
abs(deviation);
620 if (deviation < best_deviation) {
624 best_deviation = deviation;
632 best_fs, best_div, best_rate);
651 snd_soc_dai_set_drvdata(dai, i2s);
655 dev_err(dev,
"cannot ioremap registers\n");
661 dev_err(dev,
"failed to get iis_clock\n");
673 s3c2412_snd_txctrl(i2s, 0);
674 s3c2412_snd_rxctrl(i2s, 0);
712 pr_info(
"dai_active %d, IISMOD %08x, IISCON %08x\n",
730 #define s3c2412_i2s_suspend NULL
731 #define s3c2412_i2s_resume NULL
739 ops->
trigger = s3c2412_i2s_trigger;
742 ops->
set_fmt = s3c2412_i2s_set_fmt;
748 ops->
delay = s3c2412_i2s_delay;