2 * Renesas R-Car SSIU/SSI support
4 * Copyright (C) 2013 Renesas Solutions Corp.
5 * Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
8 * Kuninori Morimoto <morimoto.kuninori@renesas.com>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2 as
12 * published by the Free Software Foundation.
14 #include <sound/simple_card_utils.h>
15 #include <linux/delay.h>
17 #define RSND_SSI_NAME_SIZE 16
22 #define FORCE (1 << 31) /* Fixed */
23 #define DMEN (1 << 28) /* DMA Enable */
24 #define UIEN (1 << 27) /* Underflow Interrupt Enable */
25 #define OIEN (1 << 26) /* Overflow Interrupt Enable */
26 #define IIEN (1 << 25) /* Idle Mode Interrupt Enable */
27 #define DIEN (1 << 24) /* Data Interrupt Enable */
28 #define CHNL_4 (1 << 22) /* Channels */
29 #define CHNL_6 (2 << 22) /* Channels */
30 #define CHNL_8 (3 << 22) /* Channels */
31 #define DWL_8 (0 << 19) /* Data Word Length */
32 #define DWL_16 (1 << 19) /* Data Word Length */
33 #define DWL_18 (2 << 19) /* Data Word Length */
34 #define DWL_20 (3 << 19) /* Data Word Length */
35 #define DWL_22 (4 << 19) /* Data Word Length */
36 #define DWL_24 (5 << 19) /* Data Word Length */
37 #define DWL_32 (6 << 19) /* Data Word Length */
39 #define SWL_32 (3 << 16) /* R/W System Word Length */
40 #define SCKD (1 << 15) /* Serial Bit Clock Direction */
41 #define SWSD (1 << 14) /* Serial WS Direction */
42 #define SCKP (1 << 13) /* Serial Bit Clock Polarity */
43 #define SWSP (1 << 12) /* Serial WS Polarity */
44 #define SDTA (1 << 10) /* Serial Data Alignment */
45 #define PDTA (1 << 9) /* Parallel Data Alignment */
46 #define DEL (1 << 8) /* Serial Data Delay */
47 #define CKDV(v) (v << 4) /* Serial Clock Division Ratio */
48 #define TRMD (1 << 1) /* Transmit/Receive Mode Select */
49 #define EN (1 << 0) /* SSI Module Enable */
54 #define UIRQ (1 << 27) /* Underflow Error Interrupt Status */
55 #define OIRQ (1 << 26) /* Overflow Error Interrupt Status */
56 #define IIRQ (1 << 25) /* Idle Mode Interrupt Status */
57 #define DIRQ (1 << 24) /* Data Interrupt Status Flag */
62 #define CONT (1 << 8) /* WS Continue Function */
63 #define WS_MODE (1 << 0) /* WS Mode */
65 #define SSI_NAME "ssi"
89 #define RSND_SSI_CLK_PIN_SHARE (1 << 0)
90 #define RSND_SSI_NO_BUSIF (1 << 1) /* SSI+DMA without BUSIF */
91 #define RSND_SSI_HDMI0 (1 << 2) /* for HDMI0 */
92 #define RSND_SSI_HDMI1 (1 << 3) /* for HDMI1 */
93 #define RSND_SSI_PROBED (1 << 4)
95 #define for_each_rsnd_ssi(pos, priv, i) \
97 (i < rsnd_ssi_nr(priv)) && \
98 ((pos) = ((struct rsnd_ssi *)(priv)->ssi + i)); \
101 #define rsnd_ssi_get(priv, id) ((struct rsnd_ssi *)(priv->ssi) + id)
102 #define rsnd_ssi_to_dma(mod) ((ssi)->dma)
103 #define rsnd_ssi_nr(priv) ((priv)->ssi_nr)
104 #define rsnd_mod_to_ssi(_mod) container_of((_mod), struct rsnd_ssi, mod)
105 #define rsnd_ssi_flags_has(p, f) ((p)->flags & f)
106 #define rsnd_ssi_flags_set(p, f) ((p)->flags |= f)
107 #define rsnd_ssi_flags_del(p, f) ((p)->flags = ((p)->flags & ~f))
108 #define rsnd_ssi_is_parent(ssi, io) ((ssi) == rsnd_io_to_mod_ssip(io))
109 #define rsnd_ssi_is_multi_slave(mod, io) \
110 (rsnd_ssi_multi_slaves(io) & (1 << rsnd_mod_id(mod)))
111 #define rsnd_ssi_is_run_mods(mod, io) \
112 (rsnd_ssi_run_mods(io) & (1 << rsnd_mod_id(mod)))
113 #define rsnd_ssi_can_output_clk(mod) (!__rsnd_ssi_is_pin_sharing(mod))
115 int rsnd_ssi_hdmi_port(struct rsnd_dai_stream *io)
117 struct rsnd_mod *mod = rsnd_io_to_mod_ssi(io);
118 struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
120 if (rsnd_ssi_flags_has(ssi, RSND_SSI_HDMI0))
121 return RSND_SSI_HDMI_PORT0;
123 if (rsnd_ssi_flags_has(ssi, RSND_SSI_HDMI1))
124 return RSND_SSI_HDMI_PORT1;
129 int rsnd_ssi_use_busif(struct rsnd_dai_stream *io)
131 struct rsnd_mod *mod = rsnd_io_to_mod_ssi(io);
132 struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
135 if (!rsnd_ssi_is_dma_mode(mod))
138 if (!(rsnd_ssi_flags_has(ssi, RSND_SSI_NO_BUSIF)))
140 if (rsnd_io_to_mod_src(io))
146 static void rsnd_ssi_status_clear(struct rsnd_mod *mod)
148 rsnd_mod_write(mod, SSISR, 0);
151 static u32 rsnd_ssi_status_get(struct rsnd_mod *mod)
153 return rsnd_mod_read(mod, SSISR);
156 static void rsnd_ssi_status_check(struct rsnd_mod *mod,
159 struct rsnd_priv *priv = rsnd_mod_to_priv(mod);
160 struct device *dev = rsnd_priv_to_dev(priv);
164 for (i = 0; i < 1024; i++) {
165 status = rsnd_ssi_status_get(mod);
172 dev_warn(dev, "%s[%d] status check failed\n",
173 rsnd_mod_name(mod), rsnd_mod_id(mod));
176 static u32 rsnd_ssi_multi_slaves(struct rsnd_dai_stream *io)
178 struct rsnd_mod *mod;
179 enum rsnd_mod_type types[] = {
187 for (i = 0; i < ARRAY_SIZE(types); i++) {
188 mod = rsnd_io_to_mod(io, types[i]);
192 mask |= 1 << rsnd_mod_id(mod);
198 static u32 rsnd_ssi_run_mods(struct rsnd_dai_stream *io)
200 struct rsnd_mod *ssi_mod = rsnd_io_to_mod_ssi(io);
201 struct rsnd_mod *ssi_parent_mod = rsnd_io_to_mod_ssip(io);
203 return rsnd_ssi_multi_slaves_runtime(io) |
204 1 << rsnd_mod_id(ssi_mod) |
205 1 << rsnd_mod_id(ssi_parent_mod);
208 u32 rsnd_ssi_multi_slaves_runtime(struct rsnd_dai_stream *io)
210 if (rsnd_runtime_is_ssi_multi(io))
211 return rsnd_ssi_multi_slaves(io);
216 unsigned int rsnd_ssi_clk_query(struct rsnd_priv *priv,
217 int param1, int param2, int *idx)
219 int ssi_clk_mul_table[] = {
220 1, 2, 4, 8, 16, 6, 12,
223 unsigned int main_rate;
225 for (j = 0; j < ARRAY_SIZE(ssi_clk_mul_table); j++) {
228 * It will set SSIWSR.CONT here, but SSICR.CKDV = 000
229 * with it is not allowed. (SSIWSR.WS_MODE with
230 * SSICR.CKDV = 000 is not allowed either).
231 * Skip it. See SSICR.CKDV
237 * this driver is assuming that
238 * system word is 32bit x chan
239 * see rsnd_ssi_init()
241 main_rate = 32 * param1 * param2 * ssi_clk_mul_table[j];
243 ret = rsnd_adg_clk_query(priv, main_rate);
256 static int rsnd_ssi_master_clk_start(struct rsnd_mod *mod,
257 struct rsnd_dai_stream *io)
259 struct rsnd_priv *priv = rsnd_io_to_priv(io);
260 struct device *dev = rsnd_priv_to_dev(priv);
261 struct rsnd_dai *rdai = rsnd_io_to_rdai(io);
262 struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
263 int chan = rsnd_runtime_channel_for_ssi(io);
265 unsigned int main_rate;
266 unsigned int rate = rsnd_io_is_play(io) ?
267 rsnd_src_get_out_rate(priv, io) :
268 rsnd_src_get_in_rate(priv, io);
270 if (!rsnd_rdai_is_clk_master(rdai))
273 if (!rsnd_ssi_can_output_clk(mod))
276 if (rsnd_ssi_is_multi_slave(mod, io))
279 if (ssi->usrcnt > 1) {
280 if (ssi->rate != rate) {
281 dev_err(dev, "SSI parent/child should use same rate\n");
288 main_rate = rsnd_ssi_clk_query(priv, rate, chan, &idx);
290 dev_err(dev, "unsupported clock rate\n");
294 ret = rsnd_adg_ssi_clk_try_start(mod, main_rate);
299 * SSI clock will be output contiguously
301 * This means, rsnd_ssi_master_clk_start()
302 * and rsnd_ssi_register_setup() are necessary
305 * SSICR : FORCE, SCKD, SWSD
308 ssi->cr_clk = FORCE | SWL_32 | SCKD | SWSD | CKDV(idx);
312 dev_dbg(dev, "%s[%d] outputs %u Hz\n",
314 rsnd_mod_id(mod), rate);
319 static void rsnd_ssi_master_clk_stop(struct rsnd_mod *mod,
320 struct rsnd_dai_stream *io)
322 struct rsnd_dai *rdai = rsnd_io_to_rdai(io);
323 struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
325 if (!rsnd_rdai_is_clk_master(rdai))
328 if (!rsnd_ssi_can_output_clk(mod))
337 rsnd_adg_ssi_clk_stop(mod);
340 static void rsnd_ssi_config_init(struct rsnd_mod *mod,
341 struct rsnd_dai_stream *io)
343 struct rsnd_dai *rdai = rsnd_io_to_rdai(io);
344 struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io);
345 struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
351 if (rsnd_ssi_is_parent(mod, io))
354 is_tdm = rsnd_runtime_is_ssi_tdm(io);
357 * always use 32bit system word.
358 * see also rsnd_ssi_master_clk_enable()
360 cr_own = FORCE | SWL_32;
362 if (rdai->bit_clk_inv)
364 if (rdai->frm_clk_inv ^ is_tdm)
366 if (rdai->data_alignment)
370 if (rsnd_io_is_play(io))
373 switch (runtime->sample_bits) {
382 if (rsnd_ssi_is_dma_mode(mod)) {
383 cr_mode = UIEN | OIEN | /* over/under run */
384 DMEN; /* DMA : enable DMA */
386 cr_mode = DIEN; /* PIO : enable Data interrupt */
392 * rsnd_ssiu_init_gen2()
400 ssi->cr_own = cr_own;
401 ssi->cr_mode = cr_mode;
405 static void rsnd_ssi_register_setup(struct rsnd_mod *mod)
407 struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
409 rsnd_mod_write(mod, SSIWSR, ssi->wsr);
410 rsnd_mod_write(mod, SSICR, ssi->cr_own |
416 static void rsnd_ssi_pointer_init(struct rsnd_mod *mod,
417 struct rsnd_dai_stream *io)
419 struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
420 struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io);
424 ssi->byte_per_period = runtime->period_size *
426 samples_to_bytes(runtime, 1);
427 ssi->next_period_byte = ssi->byte_per_period;
430 static int rsnd_ssi_pointer_offset(struct rsnd_mod *mod,
431 struct rsnd_dai_stream *io,
434 struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
435 struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io);
436 int pos = ssi->byte_pos + additional;
438 pos %= (runtime->periods * ssi->byte_per_period);
443 static bool rsnd_ssi_pointer_update(struct rsnd_mod *mod,
444 struct rsnd_dai_stream *io,
447 struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
449 ssi->byte_pos += byte;
451 if (ssi->byte_pos >= ssi->next_period_byte) {
452 struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io);
455 ssi->next_period_byte += ssi->byte_per_period;
457 if (ssi->period_pos >= runtime->periods) {
460 ssi->next_period_byte = ssi->byte_per_period;
470 * SSI mod common functions
472 static int rsnd_ssi_init(struct rsnd_mod *mod,
473 struct rsnd_dai_stream *io,
474 struct rsnd_priv *priv)
476 struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
479 if (!rsnd_ssi_is_run_mods(mod, io))
482 rsnd_ssi_pointer_init(mod, io);
486 rsnd_mod_power_on(mod);
488 ret = rsnd_ssi_master_clk_start(mod, io);
492 rsnd_ssi_config_init(mod, io);
494 rsnd_ssi_register_setup(mod);
496 /* clear error status */
497 rsnd_ssi_status_clear(mod);
502 static int rsnd_ssi_quit(struct rsnd_mod *mod,
503 struct rsnd_dai_stream *io,
504 struct rsnd_priv *priv)
506 struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
507 struct device *dev = rsnd_priv_to_dev(priv);
509 if (!rsnd_ssi_is_run_mods(mod, io))
513 dev_err(dev, "%s[%d] usrcnt error\n",
514 rsnd_mod_name(mod), rsnd_mod_id(mod));
518 if (!rsnd_ssi_is_parent(mod, io))
521 rsnd_ssi_master_clk_stop(mod, io);
523 rsnd_mod_power_off(mod);
530 static int rsnd_ssi_hw_params(struct rsnd_mod *mod,
531 struct rsnd_dai_stream *io,
532 struct snd_pcm_substream *substream,
533 struct snd_pcm_hw_params *params)
535 struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
536 int chan = params_channels(params);
539 * snd_pcm_ops::hw_params will be called *before*
540 * snd_soc_dai_ops::trigger. Thus, ssi->usrcnt is 0
546 * It will happen if SSI has parent/child connection.
547 * it is error if child <-> parent SSI uses
548 * different channels.
550 if (ssi->chan != chan)
559 static int rsnd_ssi_start(struct rsnd_mod *mod,
560 struct rsnd_dai_stream *io,
561 struct rsnd_priv *priv)
563 struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
565 if (!rsnd_ssi_is_run_mods(mod, io))
569 * EN will be set via SSIU :: SSI_CONTROL
570 * if Multi channel mode
572 if (rsnd_ssi_multi_slaves_runtime(io))
576 * EN is for data output.
577 * SSI parent EN is not needed.
579 if (rsnd_ssi_is_parent(mod, io))
584 rsnd_mod_write(mod, SSICR, ssi->cr_own |
592 static int rsnd_ssi_stop(struct rsnd_mod *mod,
593 struct rsnd_dai_stream *io,
594 struct rsnd_priv *priv)
596 struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
599 if (!rsnd_ssi_is_run_mods(mod, io))
602 if (rsnd_ssi_is_parent(mod, io))
607 * and, wait all data was sent
612 rsnd_mod_write(mod, SSICR, cr | EN);
613 rsnd_ssi_status_check(mod, DIRQ);
617 * and, wait idle state
619 rsnd_mod_write(mod, SSICR, cr); /* disabled all */
620 rsnd_ssi_status_check(mod, IIRQ);
627 static int rsnd_ssi_irq(struct rsnd_mod *mod,
628 struct rsnd_dai_stream *io,
629 struct rsnd_priv *priv,
634 if (rsnd_is_gen1(priv))
637 if (rsnd_ssi_is_parent(mod, io))
640 if (!rsnd_ssi_is_run_mods(mod, io))
644 val = rsnd_ssi_is_dma_mode(mod) ? 0x0e000000 : 0x0f000000;
646 rsnd_mod_write(mod, SSI_INT_ENABLE, val);
651 static void __rsnd_ssi_interrupt(struct rsnd_mod *mod,
652 struct rsnd_dai_stream *io)
654 struct rsnd_priv *priv = rsnd_mod_to_priv(mod);
655 int is_dma = rsnd_ssi_is_dma_mode(mod);
657 bool elapsed = false;
660 spin_lock(&priv->lock);
662 /* ignore all cases if not working */
663 if (!rsnd_io_is_working(io))
664 goto rsnd_ssi_interrupt_out;
666 status = rsnd_ssi_status_get(mod);
669 if (!is_dma && (status & DIRQ)) {
670 struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io);
671 u32 *buf = (u32 *)(runtime->dma_area +
672 rsnd_ssi_pointer_offset(mod, io, 0));
675 switch (runtime->sample_bits) {
682 * 8/16/32 data can be assesse to TDR/RDR register
683 * directly as 32bit data
684 * see rsnd_ssi_init()
686 if (rsnd_io_is_play(io))
687 rsnd_mod_write(mod, SSITDR, (*buf) << shift);
689 *buf = (rsnd_mod_read(mod, SSIRDR) >> shift);
691 elapsed = rsnd_ssi_pointer_update(mod, io, sizeof(*buf));
695 if (is_dma && (status & (UIRQ | OIRQ)))
698 rsnd_ssi_status_clear(mod);
699 rsnd_ssi_interrupt_out:
700 spin_unlock(&priv->lock);
703 rsnd_dai_period_elapsed(io);
706 snd_pcm_stop_xrun(io->substream);
710 static irqreturn_t rsnd_ssi_interrupt(int irq, void *data)
712 struct rsnd_mod *mod = data;
714 rsnd_mod_interrupt(mod, __rsnd_ssi_interrupt);
722 static void rsnd_ssi_parent_attach(struct rsnd_mod *mod,
723 struct rsnd_dai_stream *io)
725 struct rsnd_dai *rdai = rsnd_io_to_rdai(io);
726 struct rsnd_priv *priv = rsnd_mod_to_priv(mod);
728 if (!__rsnd_ssi_is_pin_sharing(mod))
731 if (!rsnd_rdai_is_clk_master(rdai))
734 switch (rsnd_mod_id(mod)) {
737 rsnd_dai_connect(rsnd_ssi_mod_get(priv, 0), io, RSND_MOD_SSIP);
740 rsnd_dai_connect(rsnd_ssi_mod_get(priv, 3), io, RSND_MOD_SSIP);
743 rsnd_dai_connect(rsnd_ssi_mod_get(priv, 7), io, RSND_MOD_SSIP);
748 static int rsnd_ssi_pcm_new(struct rsnd_mod *mod,
749 struct rsnd_dai_stream *io,
750 struct snd_soc_pcm_runtime *rtd)
753 * rsnd_rdai_is_clk_master() will be enabled after set_fmt,
754 * and, pcm_new will be called after it.
755 * This function reuse pcm_new at this point.
757 rsnd_ssi_parent_attach(mod, io);
762 static int rsnd_ssi_common_probe(struct rsnd_mod *mod,
763 struct rsnd_dai_stream *io,
764 struct rsnd_priv *priv)
766 struct device *dev = rsnd_priv_to_dev(priv);
767 struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
771 * SSIP/SSIU/IRQ are not needed on
774 if (rsnd_ssi_is_multi_slave(mod, io))
778 * It can't judge ssi parent at this point
779 * see rsnd_ssi_pcm_new()
782 ret = rsnd_ssiu_attach(io, mod);
787 * SSI might be called again as PIO fallback
788 * It is easy to manual handling for IRQ request/free
790 * OTOH, this function might be called many times if platform is
791 * using MIX. It needs xxx_attach() many times on xxx_probe().
792 * Because of it, we can't control .probe/.remove calling count by
794 * But it don't need to call request_irq() many times.
795 * Let's control it by RSND_SSI_PROBED flag.
797 if (!rsnd_ssi_flags_has(ssi, RSND_SSI_PROBED)) {
798 ret = request_irq(ssi->irq,
803 rsnd_ssi_flags_set(ssi, RSND_SSI_PROBED);
809 static int rsnd_ssi_common_remove(struct rsnd_mod *mod,
810 struct rsnd_dai_stream *io,
811 struct rsnd_priv *priv)
813 struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
814 struct rsnd_mod *pure_ssi_mod = rsnd_io_to_mod_ssi(io);
816 /* Do nothing if non SSI (= SSI parent, multi SSI) mod */
817 if (pure_ssi_mod != mod)
820 /* PIO will request IRQ again */
821 if (rsnd_ssi_flags_has(ssi, RSND_SSI_PROBED)) {
822 free_irq(ssi->irq, mod);
824 rsnd_ssi_flags_del(ssi, RSND_SSI_PROBED);
830 static int rsnd_ssi_pointer(struct rsnd_mod *mod,
831 struct rsnd_dai_stream *io,
832 snd_pcm_uframes_t *pointer)
834 struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
835 struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io);
837 *pointer = bytes_to_frames(runtime, ssi->byte_pos);
842 static struct rsnd_mod_ops rsnd_ssi_pio_ops = {
844 .probe = rsnd_ssi_common_probe,
845 .remove = rsnd_ssi_common_remove,
846 .init = rsnd_ssi_init,
847 .quit = rsnd_ssi_quit,
848 .start = rsnd_ssi_start,
849 .stop = rsnd_ssi_stop,
851 .pointer= rsnd_ssi_pointer,
852 .pcm_new = rsnd_ssi_pcm_new,
853 .hw_params = rsnd_ssi_hw_params,
856 static int rsnd_ssi_dma_probe(struct rsnd_mod *mod,
857 struct rsnd_dai_stream *io,
858 struct rsnd_priv *priv)
860 struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
864 * SSIP/SSIU/IRQ/DMA are not needed on
867 if (rsnd_ssi_is_multi_slave(mod, io))
870 ret = rsnd_ssi_common_probe(mod, io, priv);
874 /* SSI probe might be called many times in MUX multi path */
875 ret = rsnd_dma_attach(io, mod, &ssi->dma);
880 static int rsnd_ssi_fallback(struct rsnd_mod *mod,
881 struct rsnd_dai_stream *io,
882 struct rsnd_priv *priv)
884 struct device *dev = rsnd_priv_to_dev(priv);
889 * SSI .probe might be called again.
891 * rsnd_rdai_continuance_probe()
893 mod->ops = &rsnd_ssi_pio_ops;
895 dev_info(dev, "%s[%d] fallback to PIO mode\n",
896 rsnd_mod_name(mod), rsnd_mod_id(mod));
901 static struct dma_chan *rsnd_ssi_dma_req(struct rsnd_dai_stream *io,
902 struct rsnd_mod *mod)
904 struct rsnd_priv *priv = rsnd_mod_to_priv(mod);
905 int is_play = rsnd_io_is_play(io);
908 if (rsnd_ssi_use_busif(io))
909 name = is_play ? "rxu" : "txu";
911 name = is_play ? "rx" : "tx";
913 return rsnd_dma_request_channel(rsnd_ssi_of_node(priv),
917 static struct rsnd_mod_ops rsnd_ssi_dma_ops = {
919 .dma_req = rsnd_ssi_dma_req,
920 .probe = rsnd_ssi_dma_probe,
921 .remove = rsnd_ssi_common_remove,
922 .init = rsnd_ssi_init,
923 .quit = rsnd_ssi_quit,
924 .start = rsnd_ssi_start,
925 .stop = rsnd_ssi_stop,
927 .pcm_new = rsnd_ssi_pcm_new,
928 .fallback = rsnd_ssi_fallback,
929 .hw_params = rsnd_ssi_hw_params,
932 int rsnd_ssi_is_dma_mode(struct rsnd_mod *mod)
934 return mod->ops == &rsnd_ssi_dma_ops;
941 static void rsnd_ssi_connect(struct rsnd_mod *mod,
942 struct rsnd_dai_stream *io)
944 struct rsnd_dai *rdai = rsnd_io_to_rdai(io);
945 enum rsnd_mod_type types[] = {
951 enum rsnd_mod_type type;
954 /* try SSI -> SSIM1 -> SSIM2 -> SSIM3 */
955 for (i = 0; i < ARRAY_SIZE(types); i++) {
957 if (!rsnd_io_to_mod(io, type)) {
958 rsnd_dai_connect(mod, io, type);
959 rsnd_rdai_channels_set(rdai, (i + 1) * 2);
960 rsnd_rdai_ssi_lane_set(rdai, (i + 1));
966 void rsnd_parse_connect_ssi(struct rsnd_dai *rdai,
967 struct device_node *playback,
968 struct device_node *capture)
970 struct rsnd_priv *priv = rsnd_rdai_to_priv(rdai);
971 struct device_node *node;
972 struct device_node *np;
973 struct rsnd_mod *mod;
976 node = rsnd_ssi_of_node(priv);
981 for_each_child_of_node(node, np) {
982 mod = rsnd_ssi_mod_get(priv, i);
984 rsnd_ssi_connect(mod, &rdai->playback);
986 rsnd_ssi_connect(mod, &rdai->capture);
993 static void __rsnd_ssi_parse_hdmi_connection(struct rsnd_priv *priv,
994 struct rsnd_dai_stream *io,
995 struct device_node *remote_ep)
997 struct device *dev = rsnd_priv_to_dev(priv);
998 struct rsnd_mod *mod = rsnd_io_to_mod_ssi(io);
999 struct rsnd_ssi *ssi;
1004 ssi = rsnd_mod_to_ssi(mod);
1006 if (strstr(remote_ep->full_name, "hdmi0")) {
1007 rsnd_ssi_flags_set(ssi, RSND_SSI_HDMI0);
1008 dev_dbg(dev, "%s[%d] connected to HDMI0\n",
1009 rsnd_mod_name(mod), rsnd_mod_id(mod));
1012 if (strstr(remote_ep->full_name, "hdmi1")) {
1013 rsnd_ssi_flags_set(ssi, RSND_SSI_HDMI1);
1014 dev_dbg(dev, "%s[%d] connected to HDMI1\n",
1015 rsnd_mod_name(mod), rsnd_mod_id(mod));
1019 void rsnd_ssi_parse_hdmi_connection(struct rsnd_priv *priv,
1020 struct device_node *endpoint,
1023 struct rsnd_dai *rdai = rsnd_rdai_get(priv, dai_i);
1024 struct device_node *remote_ep;
1026 remote_ep = of_graph_get_remote_endpoint(endpoint);
1030 __rsnd_ssi_parse_hdmi_connection(priv, &rdai->playback, remote_ep);
1031 __rsnd_ssi_parse_hdmi_connection(priv, &rdai->capture, remote_ep);
1034 struct rsnd_mod *rsnd_ssi_mod_get(struct rsnd_priv *priv, int id)
1036 if (WARN_ON(id < 0 || id >= rsnd_ssi_nr(priv)))
1039 return rsnd_mod_get(rsnd_ssi_get(priv, id));
1042 int __rsnd_ssi_is_pin_sharing(struct rsnd_mod *mod)
1044 struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
1046 return !!(rsnd_ssi_flags_has(ssi, RSND_SSI_CLK_PIN_SHARE));
1049 static u32 *rsnd_ssi_get_status(struct rsnd_dai_stream *io,
1050 struct rsnd_mod *mod,
1051 enum rsnd_mod_type type)
1054 * SSIP (= SSI parent) needs to be special, otherwise,
1055 * 2nd SSI might doesn't start. see also rsnd_mod_call()
1057 * We can't include parent SSI status on SSI, because we don't know
1058 * how many SSI requests parent SSI. Thus, it is localed on "io" now.
1061 * Capture : SSI1 (needs SSI0)
1063 * 1) start Capture -> SSI0/SSI1 are started.
1064 * 2) start Playback -> SSI0 doesn't work, because it is already
1065 * marked as "started" on 1)
1067 * OTOH, using each mod's status is good for MUX case.
1068 * It doesn't need to start in 2nd start
1070 * IO-0: SRC0 -> CTU1 -+-> MUX -> DVC -> SSIU -> SSI0
1072 * IO-1: SRC1 -> CTU2 -+
1074 * 1) start IO-0 -> start SSI0
1075 * 2) start IO-1 -> SSI0 doesn't need to start, because it is
1076 * already started on 1)
1078 if (type == RSND_MOD_SSIP)
1079 return &io->parent_ssi_status;
1081 return rsnd_mod_get_status(io, mod, type);
1084 int rsnd_ssi_probe(struct rsnd_priv *priv)
1086 struct device_node *node;
1087 struct device_node *np;
1088 struct device *dev = rsnd_priv_to_dev(priv);
1089 struct rsnd_mod_ops *ops;
1091 struct rsnd_ssi *ssi;
1092 char name[RSND_SSI_NAME_SIZE];
1095 node = rsnd_ssi_of_node(priv);
1099 nr = of_get_child_count(node);
1102 goto rsnd_ssi_probe_done;
1105 ssi = devm_kzalloc(dev, sizeof(*ssi) * nr, GFP_KERNEL);
1108 goto rsnd_ssi_probe_done;
1115 for_each_child_of_node(node, np) {
1116 ssi = rsnd_ssi_get(priv, i);
1118 snprintf(name, RSND_SSI_NAME_SIZE, "%s.%d",
1121 clk = devm_clk_get(dev, name);
1125 goto rsnd_ssi_probe_done;
1128 if (of_get_property(np, "shared-pin", NULL))
1129 rsnd_ssi_flags_set(ssi, RSND_SSI_CLK_PIN_SHARE);
1131 if (of_get_property(np, "no-busif", NULL))
1132 rsnd_ssi_flags_set(ssi, RSND_SSI_NO_BUSIF);
1134 ssi->irq = irq_of_parse_and_map(np, 0);
1138 goto rsnd_ssi_probe_done;
1141 if (of_property_read_bool(np, "pio-transfer"))
1142 ops = &rsnd_ssi_pio_ops;
1144 ops = &rsnd_ssi_dma_ops;
1146 ret = rsnd_mod_init(priv, rsnd_mod_get(ssi), ops, clk,
1147 rsnd_ssi_get_status, RSND_MOD_SSI, i);
1150 goto rsnd_ssi_probe_done;
1158 rsnd_ssi_probe_done:
1164 void rsnd_ssi_remove(struct rsnd_priv *priv)
1166 struct rsnd_ssi *ssi;
1169 for_each_rsnd_ssi(ssi, priv, i) {
1170 rsnd_mod_quit(rsnd_mod_get(ssi));