25 #include <linux/slab.h>
26 #include <linux/module.h>
28 #include <asm/clock.h>
37 #if defined(CONFIG_CPU_SUBTYPE_SH7722)
38 # define SIU_MAX_VOLUME 0x1000
40 # define SIU_MAX_VOLUME 0x7fff
43 #define PRAM_SIZE 0x2000
44 #define XRAM_SIZE 0x800
45 #define YRAM_SIZE 0x800
47 #define XRAM_OFFSET 0x4000
48 #define YRAM_OFFSET 0x6000
49 #define REG_OFFSET 0xc000
51 #define PLAYBACK_ENABLED 1
52 #define CAPTURE_ENABLED 2
54 #define VOLUME_CAPTURE 0
55 #define VOLUME_PLAYBACK 1
56 #define DFLT_VOLUME_LEVEL 0x08000800
77 static struct port_flag siu_flags[SIU_PORT_NUM] = {
108 static void siu_dai_start(
struct siu_port *
port_info)
113 dev_dbg(port_info->pcm->card->dev,
"%s\n", __func__);
116 siu_write32(base + SIU_SRCTL, 0);
121 port_info->stfifo = 0;
122 port_info->trdat = 0;
125 siu_write32(base + SIU_SRCTL, 0x301);
128 siu_write32(base + SIU_CKCTL, 0x40400000);
131 siu_write32(base + SIU_BRGASEL, 0);
132 siu_write32(base + SIU_BRRA, 0);
135 siu_write32(base + SIU_BRGBSEL, 1);
136 siu_write32(base + SIU_BRRB, 0);
138 siu_write32(base + SIU_IFCTL, 0x44440000);
141 siu_write32(base + SIU_SFORM, 0x0c0c0000);
147 siu_write32(base + SIU_SBDVCA, port_info->playback.volume);
148 siu_write32(base + SIU_SBDVCB, port_info->capture.volume);
151 static void siu_dai_stop(
struct siu_port *
port_info)
157 siu_write32(base + SIU_SRCTL, 0);
160 static void siu_dai_spbAselect(
struct siu_port *
port_info)
174 (fw->
spbpar[idx].ab0a << 8) |
176 ydef[1] = fw->
yram0[1];
177 ydef[2] = (16 / 2) << 24;
178 ydef[3] = fw->
yram0[3];
179 ydef[4] = fw->
yram0[4];
181 port_info->stfifo |= fw->
spbpar[
idx].stfifo;
182 port_info->trdat |= fw->
spbpar[
idx].trdat;
185 static void siu_dai_spbBselect(
struct siu_port *port_info)
199 (fw->
spbpar[idx].ab0a << 8) | 1;
201 port_info->stfifo |= fw->
spbpar[
idx].stfifo;
202 port_info->trdat |= fw->
spbpar[
idx].trdat;
205 static void siu_dai_open(
struct siu_stream *siu_stream)
211 srctl = siu_read32(base + SIU_SRCTL);
212 ifctl = siu_read32(base + SIU_IFCTL);
214 switch (info->port_id) {
227 siu_write32(base + SIU_SRCTL, srctl);
229 siu_write32(base + SIU_IFCTL, ifctl);
236 static void siu_dai_pcmdatapack(
struct siu_stream *siu_stream)
242 dpak = siu_read32(base + SIU_DPAK);
244 switch (info->port_id) {
253 siu_write32(base + SIU_DPAK, dpak);
256 static int siu_dai_spbstart(
struct siu_port *port_info)
269 for (cnt = 0; cnt <
PRAM0_SIZE; cnt++, add++, ptr++)
270 siu_write32(add, *ptr);
273 add = info->pram + (0x0100 /
sizeof(
u32));
274 for (cnt = 0; cnt <
PRAM1_SIZE; cnt++, add++, ptr++)
275 siu_write32(add, *ptr);
285 siu_write32(add, ydef[cnt]);
288 add = info->yram + (0x0200 /
sizeof(
u32));
293 add = info->yram + (0x0600 /
sizeof(
u32));
297 siu_write32(base + SIU_TRDAT, port_info->trdat);
298 port_info->trdat = 0x0;
302 siu_write32(base + SIU_SBACTIV, 0);
304 siu_write32(base + SIU_SBCTL, 0xc0000000);
307 while (--cnt && siu_read32(base + SIU_SBCTL) != 0x80000000)
314 siu_write32(base + SIU_SBPSET, 0x00400000);
316 siu_write32(base + SIU_SBACTIV, 0xc0000000);
321 static void siu_dai_spbstop(
struct siu_port *port_info)
326 siu_write32(base + SIU_SBACTIV, 0);
328 siu_write32(base + SIU_SBCTL, 0);
330 port_info->stfifo = 0;
338 .formats = SNDRV_PCM_FMTBIT_S16,
344 .buffer_bytes_max = SIU_BUFFER_BYTES_MAX,
345 .period_bytes_min = SIU_PERIOD_BYTES_MIN,
346 .period_bytes_max = SIU_PERIOD_BYTES_MAX,
347 .periods_min = SIU_PERIODS_MIN,
348 .periods_max = SIU_PERIODS_MAX,
351 static int siu_dai_info_volume(
struct snd_kcontrol *kctrl,
356 dev_dbg(port_info->pcm->card->dev,
"%s\n", __func__);
366 static int siu_dai_get_volume(
struct snd_kcontrol *kctrl,
370 struct device *
dev = port_info->pcm->card->dev;
373 dev_dbg(dev,
"%s\n", __func__);
378 vol = port_info->playback.volume;
379 ucontrol->
value.integer.value[0] = vol & 0xffff;
380 ucontrol->
value.integer.value[1] = vol >> 16 & 0xffff;
384 vol = port_info->capture.volume;
385 ucontrol->
value.integer.value[0] = vol & 0xffff;
386 ucontrol->
value.integer.value[1] = vol >> 16 & 0xffff;
389 dev_err(dev,
"%s() invalid private_value=%ld\n",
397 static int siu_dai_put_volume(
struct snd_kcontrol *kctrl,
401 struct device *dev = port_info->pcm->card->dev;
407 dev_dbg(dev,
"%s\n", __func__);
409 if (ucontrol->
value.integer.value[0] < 0 ||
411 ucontrol->
value.integer.value[1] < 0 ||
415 new_vol = ucontrol->
value.integer.value[0] |
416 ucontrol->
value.integer.value[1] << 16;
422 cur_vol = port_info->playback.volume;
423 siu_write32(base + SIU_SBDVCA, new_vol);
424 port_info->playback.volume = new_vol;
428 cur_vol = port_info->capture.volume;
429 siu_write32(base + SIU_SBDVCB, new_vol);
430 port_info->capture.volume = new_vol;
433 dev_err(dev,
"%s() invalid private_value=%ld\n",
438 if (cur_vol != new_vol)
446 .name =
"PCM Playback Volume",
448 .info = siu_dai_info_volume,
449 .get = siu_dai_get_volume,
450 .put = siu_dai_put_volume,
456 .name =
"PCM Capture Volume",
458 .info = siu_dai_info_volume,
459 .get = siu_dai_get_volume,
460 .put = siu_dai_put_volume,
470 *port_info = kzalloc(
sizeof(**port_info),
GFP_KERNEL);
474 dev_dbg(dev,
"%s: port #%d@%p\n", __func__, port, *port_info);
489 "failed to add playback controls %p port=%d err=%d\n",
496 "failed to add capture controls %p port=%d err=%d\n",
510 struct siu_info *info = snd_soc_dai_get_drvdata(dai);
512 struct siu_port *port_info = siu_port_info(substream);
515 dev_dbg(substream->
pcm->card->dev,
"%s: port=%d@%p\n", __func__,
516 info->port_id, port_info);
524 siu_dai_start(port_info);
532 struct siu_info *info = snd_soc_dai_get_drvdata(dai);
533 struct siu_port *port_info = siu_port_info(substream);
535 dev_dbg(substream->
pcm->card->dev,
"%s: port=%d@%p\n", __func__,
536 info->port_id, port_info);
544 if (!port_info->play_cap) {
546 BUG_ON(port_info->playback.rw_flg || port_info->capture.rw_flg);
547 siu_dai_spbstop(port_info);
548 siu_dai_stop(port_info);
556 struct siu_info *info = snd_soc_dai_get_drvdata(dai);
558 struct siu_port *port_info = siu_port_info(substream);
559 struct siu_stream *siu_stream;
563 "%s: port %d, active streams %lx, %d channels\n",
564 __func__, info->port_id, port_info->play_cap, rt->
channels);
568 siu_stream = &port_info->playback;
571 siu_stream = &port_info->capture;
575 if (!port_info->play_cap) {
576 siu_stream->rw_flg = 0;
578 siu_dai_spbAselect(port_info);
579 siu_dai_spbBselect(port_info);
581 siu_dai_open(siu_stream);
583 siu_dai_pcmdatapack(siu_stream);
585 ret = siu_dai_spbstart(port_info);
592 port_info->play_cap |=
self;
602 static int siu_dai_set_fmt(
struct snd_soc_dai *dai,
605 struct siu_info *info = snd_soc_dai_get_drvdata(dai);
609 dev_dbg(dai->
dev,
"%s: fmt 0x%x on port %d\n",
610 __func__, fmt, info->port_id);
612 if (info->port_id < 0)
618 ifctl = siu_flags[info->port_id].
playback.i2s |
619 siu_flags[info->port_id].
capture.i2s;
622 ifctl = siu_flags[info->port_id].
playback.pcm |
623 siu_flags[info->port_id].
capture.pcm;
630 ifctl |= ~(siu_flags[info->port_id].
playback.mask |
631 siu_flags[info->port_id].
capture.mask) &
632 siu_read32(base + SIU_IFCTL);
633 siu_write32(base + SIU_IFCTL, ifctl);
638 static int siu_dai_set_sysclk(
struct snd_soc_dai *dai,
int clk_id,
639 unsigned int freq,
int dir)
641 struct clk *siu_clk, *parent_clk;
642 char *siu_name, *parent_name;
648 dev_dbg(dai->
dev,
"%s: using clock %d\n", __func__, clk_id);
652 siu_name =
"siua_clk";
653 parent_name =
"pll_clk";
656 siu_name =
"siua_clk";
657 parent_name =
"siumcka_clk";
660 siu_name =
"siub_clk";
661 parent_name =
"pll_clk";
664 siu_name =
"siub_clk";
665 parent_name =
"siumckb_clk";
672 if (IS_ERR(siu_clk)) {
673 dev_err(dai->
dev,
"%s: cannot get a SIU clock: %ld\n", __func__,
675 return PTR_ERR(siu_clk);
679 if (IS_ERR(parent_clk)) {
680 ret = PTR_ERR(parent_clk);
681 dev_err(dai->
dev,
"cannot get a SIU clock parent: %d\n", ret);
687 dev_err(dai->
dev,
"cannot reparent the SIU clock: %d\n", ret);
693 dev_err(dai->
dev,
"cannot set SIU clock rate: %d\n", ret);
705 .startup = siu_dai_startup,
706 .shutdown = siu_dai_shutdown,
707 .prepare = siu_dai_prepare,
708 .set_sysclk = siu_dai_set_sysclk,
709 .set_fmt = siu_dai_set_fmt,
713 .name =
"siu-i2s-dai",
717 .formats = SNDRV_PCM_FMTBIT_S16,
723 .formats = SNDRV_PCM_FMTBIT_S16,
733 struct siu_info *
info;
740 info->dev = &pdev->
dev;
763 dev_err(&pdev->
dev,
"SIU region already claimed\n");
823 pm_runtime_disable(&pdev->
dev);
843 .name =
"siu-pcm-audio",