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"
88 #define RSND_SSI_CLK_PIN_SHARE (1 << 0)
89 #define RSND_SSI_NO_BUSIF (1 << 1) /* SSI+DMA without BUSIF */
90 #define RSND_SSI_HDMI0 (1 << 2) /* for HDMI0 */
91 #define RSND_SSI_HDMI1 (1 << 3) /* for HDMI1 */
93 #define for_each_rsnd_ssi(pos, priv, i) \
95 (i < rsnd_ssi_nr(priv)) && \
96 ((pos) = ((struct rsnd_ssi *)(priv)->ssi + i)); \
99 #define rsnd_ssi_get(priv, id) ((struct rsnd_ssi *)(priv->ssi) + id)
100 #define rsnd_ssi_to_dma(mod) ((ssi)->dma)
101 #define rsnd_ssi_nr(priv) ((priv)->ssi_nr)
102 #define rsnd_mod_to_ssi(_mod) container_of((_mod), struct rsnd_ssi, mod)
103 #define rsnd_ssi_mode_flags(p) ((p)->flags)
104 #define rsnd_ssi_is_parent(ssi, io) ((ssi) == rsnd_io_to_mod_ssip(io))
105 #define rsnd_ssi_is_multi_slave(mod, io) \
106 (rsnd_ssi_multi_slaves(io) & (1 << rsnd_mod_id(mod)))
107 #define rsnd_ssi_is_run_mods(mod, io) \
108 (rsnd_ssi_run_mods(io) & (1 << rsnd_mod_id(mod)))
110 int rsnd_ssi_hdmi_port(struct rsnd_dai_stream *io)
112 struct rsnd_mod *mod = rsnd_io_to_mod_ssi(io);
113 struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
115 if (rsnd_ssi_mode_flags(ssi) & RSND_SSI_HDMI0)
116 return RSND_SSI_HDMI_PORT0;
118 if (rsnd_ssi_mode_flags(ssi) & RSND_SSI_HDMI1)
119 return RSND_SSI_HDMI_PORT1;
124 int rsnd_ssi_use_busif(struct rsnd_dai_stream *io)
126 struct rsnd_mod *mod = rsnd_io_to_mod_ssi(io);
127 struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
130 if (!rsnd_ssi_is_dma_mode(mod))
133 if (!(rsnd_ssi_mode_flags(ssi) & RSND_SSI_NO_BUSIF))
135 if (rsnd_io_to_mod_src(io))
141 static void rsnd_ssi_status_clear(struct rsnd_mod *mod)
143 rsnd_mod_write(mod, SSISR, 0);
146 static u32 rsnd_ssi_status_get(struct rsnd_mod *mod)
148 return rsnd_mod_read(mod, SSISR);
151 static void rsnd_ssi_status_check(struct rsnd_mod *mod,
154 struct rsnd_priv *priv = rsnd_mod_to_priv(mod);
155 struct device *dev = rsnd_priv_to_dev(priv);
159 for (i = 0; i < 1024; i++) {
160 status = rsnd_ssi_status_get(mod);
167 dev_warn(dev, "%s[%d] status check failed\n",
168 rsnd_mod_name(mod), rsnd_mod_id(mod));
171 static u32 rsnd_ssi_multi_slaves(struct rsnd_dai_stream *io)
173 struct rsnd_mod *mod;
174 enum rsnd_mod_type types[] = {
182 for (i = 0; i < ARRAY_SIZE(types); i++) {
183 mod = rsnd_io_to_mod(io, types[i]);
187 mask |= 1 << rsnd_mod_id(mod);
193 static u32 rsnd_ssi_run_mods(struct rsnd_dai_stream *io)
195 struct rsnd_mod *ssi_mod = rsnd_io_to_mod_ssi(io);
196 struct rsnd_mod *ssi_parent_mod = rsnd_io_to_mod_ssip(io);
198 return rsnd_ssi_multi_slaves_runtime(io) |
199 1 << rsnd_mod_id(ssi_mod) |
200 1 << rsnd_mod_id(ssi_parent_mod);
203 u32 rsnd_ssi_multi_slaves_runtime(struct rsnd_dai_stream *io)
205 if (rsnd_runtime_is_ssi_multi(io))
206 return rsnd_ssi_multi_slaves(io);
211 unsigned int rsnd_ssi_clk_query(struct rsnd_priv *priv,
212 int param1, int param2, int *idx)
214 int ssi_clk_mul_table[] = {
215 1, 2, 4, 8, 16, 6, 12,
218 unsigned int main_rate;
220 for (j = 0; j < ARRAY_SIZE(ssi_clk_mul_table); j++) {
223 * It will set SSIWSR.CONT here, but SSICR.CKDV = 000
224 * with it is not allowed. (SSIWSR.WS_MODE with
225 * SSICR.CKDV = 000 is not allowed either).
226 * Skip it. See SSICR.CKDV
232 * this driver is assuming that
233 * system word is 32bit x chan
234 * see rsnd_ssi_init()
236 main_rate = 32 * param1 * param2 * ssi_clk_mul_table[j];
238 ret = rsnd_adg_clk_query(priv, main_rate);
251 static int rsnd_ssi_master_clk_start(struct rsnd_mod *mod,
252 struct rsnd_dai_stream *io)
254 struct rsnd_priv *priv = rsnd_io_to_priv(io);
255 struct device *dev = rsnd_priv_to_dev(priv);
256 struct rsnd_dai *rdai = rsnd_io_to_rdai(io);
257 struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
258 struct rsnd_mod *ssi_parent_mod = rsnd_io_to_mod_ssip(io);
259 int chan = rsnd_runtime_channel_for_ssi(io);
261 unsigned int main_rate;
262 unsigned int rate = rsnd_io_is_play(io) ?
263 rsnd_src_get_out_rate(priv, io) :
264 rsnd_src_get_in_rate(priv, io);
266 if (!rsnd_rdai_is_clk_master(rdai))
269 if (ssi_parent_mod && !rsnd_ssi_is_parent(mod, io))
272 if (rsnd_ssi_is_multi_slave(mod, io))
275 if (ssi->usrcnt > 1) {
276 if (ssi->rate != rate) {
277 dev_err(dev, "SSI parent/child should use same rate\n");
284 main_rate = rsnd_ssi_clk_query(priv, rate, chan, &idx);
286 dev_err(dev, "unsupported clock rate\n");
290 ret = rsnd_adg_ssi_clk_try_start(mod, main_rate);
294 ssi->cr_clk = FORCE | SWL_32 | SCKD | SWSD | CKDV(idx);
298 dev_dbg(dev, "%s[%d] outputs %u Hz\n",
300 rsnd_mod_id(mod), rate);
305 static void rsnd_ssi_master_clk_stop(struct rsnd_mod *mod,
306 struct rsnd_dai_stream *io)
308 struct rsnd_dai *rdai = rsnd_io_to_rdai(io);
309 struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
310 struct rsnd_mod *ssi_parent_mod = rsnd_io_to_mod_ssip(io);
312 if (!rsnd_rdai_is_clk_master(rdai))
315 if (ssi_parent_mod && !rsnd_ssi_is_parent(mod, io))
324 rsnd_adg_ssi_clk_stop(mod);
327 static void rsnd_ssi_config_init(struct rsnd_mod *mod,
328 struct rsnd_dai_stream *io)
330 struct rsnd_dai *rdai = rsnd_io_to_rdai(io);
331 struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io);
332 struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
338 is_tdm = rsnd_runtime_is_ssi_tdm(io);
341 * always use 32bit system word.
342 * see also rsnd_ssi_master_clk_enable()
344 cr_own = FORCE | SWL_32;
346 if (rdai->bit_clk_inv)
348 if (rdai->frm_clk_inv ^ is_tdm)
350 if (rdai->data_alignment)
354 if (rsnd_io_is_play(io))
357 switch (runtime->sample_bits) {
366 if (rsnd_ssi_is_dma_mode(mod)) {
367 cr_mode = UIEN | OIEN | /* over/under run */
368 DMEN; /* DMA : enable DMA */
370 cr_mode = DIEN; /* PIO : enable Data interrupt */
376 * rsnd_ssiu_init_gen2()
384 ssi->cr_own = cr_own;
385 ssi->cr_mode = cr_mode;
389 static void rsnd_ssi_register_setup(struct rsnd_mod *mod)
391 struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
393 rsnd_mod_write(mod, SSIWSR, ssi->wsr);
394 rsnd_mod_write(mod, SSICR, ssi->cr_own |
396 ssi->cr_mode); /* without EN */
399 static void rsnd_ssi_pointer_init(struct rsnd_mod *mod,
400 struct rsnd_dai_stream *io)
402 struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
403 struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io);
407 ssi->byte_per_period = runtime->period_size *
409 samples_to_bytes(runtime, 1);
410 ssi->next_period_byte = ssi->byte_per_period;
413 static int rsnd_ssi_pointer_offset(struct rsnd_mod *mod,
414 struct rsnd_dai_stream *io,
417 struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
418 struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io);
419 int pos = ssi->byte_pos + additional;
421 pos %= (runtime->periods * ssi->byte_per_period);
426 static bool rsnd_ssi_pointer_update(struct rsnd_mod *mod,
427 struct rsnd_dai_stream *io,
430 struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
432 ssi->byte_pos += byte;
434 if (ssi->byte_pos >= ssi->next_period_byte) {
435 struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io);
438 ssi->next_period_byte += ssi->byte_per_period;
440 if (ssi->period_pos >= runtime->periods) {
443 ssi->next_period_byte = ssi->byte_per_period;
453 * SSI mod common functions
455 static int rsnd_ssi_init(struct rsnd_mod *mod,
456 struct rsnd_dai_stream *io,
457 struct rsnd_priv *priv)
459 struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
462 if (!rsnd_ssi_is_run_mods(mod, io))
465 rsnd_ssi_pointer_init(mod, io);
469 rsnd_mod_power_on(mod);
471 ret = rsnd_ssi_master_clk_start(mod, io);
475 if (!rsnd_ssi_is_parent(mod, io))
476 rsnd_ssi_config_init(mod, io);
478 rsnd_ssi_register_setup(mod);
480 /* clear error status */
481 rsnd_ssi_status_clear(mod);
486 static int rsnd_ssi_quit(struct rsnd_mod *mod,
487 struct rsnd_dai_stream *io,
488 struct rsnd_priv *priv)
490 struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
491 struct device *dev = rsnd_priv_to_dev(priv);
493 if (!rsnd_ssi_is_run_mods(mod, io))
497 dev_err(dev, "%s[%d] usrcnt error\n",
498 rsnd_mod_name(mod), rsnd_mod_id(mod));
502 if (!rsnd_ssi_is_parent(mod, io))
505 rsnd_ssi_master_clk_stop(mod, io);
507 rsnd_mod_power_off(mod);
514 static int rsnd_ssi_hw_params(struct rsnd_mod *mod,
515 struct rsnd_dai_stream *io,
516 struct snd_pcm_substream *substream,
517 struct snd_pcm_hw_params *params)
519 struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
520 int chan = params_channels(params);
523 * snd_pcm_ops::hw_params will be called *before*
524 * snd_soc_dai_ops::trigger. Thus, ssi->usrcnt is 0
530 * It will happen if SSI has parent/child connection.
531 * it is error if child <-> parent SSI uses
532 * different channels.
534 if (ssi->chan != chan)
543 static int rsnd_ssi_start(struct rsnd_mod *mod,
544 struct rsnd_dai_stream *io,
545 struct rsnd_priv *priv)
547 if (!rsnd_ssi_is_run_mods(mod, io))
551 * EN will be set via SSIU :: SSI_CONTROL
552 * if Multi channel mode
554 if (rsnd_ssi_multi_slaves_runtime(io))
557 rsnd_mod_bset(mod, SSICR, EN, EN);
562 static int rsnd_ssi_stop(struct rsnd_mod *mod,
563 struct rsnd_dai_stream *io,
564 struct rsnd_priv *priv)
566 struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
569 if (!rsnd_ssi_is_run_mods(mod, io))
573 * don't stop if not last user
583 * and, wait all data was sent
588 rsnd_mod_write(mod, SSICR, cr | EN);
589 rsnd_ssi_status_check(mod, DIRQ);
593 * and, wait idle state
595 rsnd_mod_write(mod, SSICR, cr); /* disabled all */
596 rsnd_ssi_status_check(mod, IIRQ);
601 static int rsnd_ssi_irq(struct rsnd_mod *mod,
602 struct rsnd_dai_stream *io,
603 struct rsnd_priv *priv,
608 if (rsnd_is_gen1(priv))
611 if (rsnd_ssi_is_parent(mod, io))
614 if (!rsnd_ssi_is_run_mods(mod, io))
618 val = rsnd_ssi_is_dma_mode(mod) ? 0x0e000000 : 0x0f000000;
620 rsnd_mod_write(mod, SSI_INT_ENABLE, val);
625 static void __rsnd_ssi_interrupt(struct rsnd_mod *mod,
626 struct rsnd_dai_stream *io)
628 struct rsnd_priv *priv = rsnd_mod_to_priv(mod);
629 int is_dma = rsnd_ssi_is_dma_mode(mod);
631 bool elapsed = false;
634 spin_lock(&priv->lock);
636 /* ignore all cases if not working */
637 if (!rsnd_io_is_working(io))
638 goto rsnd_ssi_interrupt_out;
640 status = rsnd_ssi_status_get(mod);
643 if (!is_dma && (status & DIRQ)) {
644 struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io);
645 u32 *buf = (u32 *)(runtime->dma_area +
646 rsnd_ssi_pointer_offset(mod, io, 0));
649 switch (runtime->sample_bits) {
656 * 8/16/32 data can be assesse to TDR/RDR register
657 * directly as 32bit data
658 * see rsnd_ssi_init()
660 if (rsnd_io_is_play(io))
661 rsnd_mod_write(mod, SSITDR, (*buf) << shift);
663 *buf = (rsnd_mod_read(mod, SSIRDR) >> shift);
665 elapsed = rsnd_ssi_pointer_update(mod, io, sizeof(*buf));
669 if (is_dma && (status & (UIRQ | OIRQ)))
672 rsnd_ssi_status_clear(mod);
673 rsnd_ssi_interrupt_out:
674 spin_unlock(&priv->lock);
677 rsnd_dai_period_elapsed(io);
680 snd_pcm_stop_xrun(io->substream);
684 static irqreturn_t rsnd_ssi_interrupt(int irq, void *data)
686 struct rsnd_mod *mod = data;
688 rsnd_mod_interrupt(mod, __rsnd_ssi_interrupt);
696 static void rsnd_ssi_parent_attach(struct rsnd_mod *mod,
697 struct rsnd_dai_stream *io)
699 struct rsnd_dai *rdai = rsnd_io_to_rdai(io);
700 struct rsnd_priv *priv = rsnd_mod_to_priv(mod);
702 if (!__rsnd_ssi_is_pin_sharing(mod))
705 if (!rsnd_rdai_is_clk_master(rdai))
708 switch (rsnd_mod_id(mod)) {
711 rsnd_dai_connect(rsnd_ssi_mod_get(priv, 0), io, RSND_MOD_SSIP);
714 rsnd_dai_connect(rsnd_ssi_mod_get(priv, 3), io, RSND_MOD_SSIP);
717 rsnd_dai_connect(rsnd_ssi_mod_get(priv, 7), io, RSND_MOD_SSIP);
722 static int rsnd_ssi_pcm_new(struct rsnd_mod *mod,
723 struct rsnd_dai_stream *io,
724 struct snd_soc_pcm_runtime *rtd)
727 * rsnd_rdai_is_clk_master() will be enabled after set_fmt,
728 * and, pcm_new will be called after it.
729 * This function reuse pcm_new at this point.
731 rsnd_ssi_parent_attach(mod, io);
736 static int rsnd_ssi_common_probe(struct rsnd_mod *mod,
737 struct rsnd_dai_stream *io,
738 struct rsnd_priv *priv)
740 struct device *dev = rsnd_priv_to_dev(priv);
741 struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
745 * SSIP/SSIU/IRQ are not needed on
748 if (rsnd_ssi_is_multi_slave(mod, io))
752 * It can't judge ssi parent at this point
753 * see rsnd_ssi_pcm_new()
756 ret = rsnd_ssiu_attach(io, mod);
761 * SSI might be called again as PIO fallback
762 * It is easy to manual handling for IRQ request/free
764 ret = request_irq(ssi->irq,
772 static int rsnd_ssi_pointer(struct rsnd_mod *mod,
773 struct rsnd_dai_stream *io,
774 snd_pcm_uframes_t *pointer)
776 struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
777 struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io);
779 *pointer = bytes_to_frames(runtime, ssi->byte_pos);
784 static struct rsnd_mod_ops rsnd_ssi_pio_ops = {
786 .probe = rsnd_ssi_common_probe,
787 .init = rsnd_ssi_init,
788 .quit = rsnd_ssi_quit,
789 .start = rsnd_ssi_start,
790 .stop = rsnd_ssi_stop,
792 .pointer= rsnd_ssi_pointer,
793 .pcm_new = rsnd_ssi_pcm_new,
794 .hw_params = rsnd_ssi_hw_params,
797 static int rsnd_ssi_dma_probe(struct rsnd_mod *mod,
798 struct rsnd_dai_stream *io,
799 struct rsnd_priv *priv)
801 struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
805 * SSIP/SSIU/IRQ/DMA are not needed on
808 if (rsnd_ssi_is_multi_slave(mod, io))
811 ret = rsnd_ssi_common_probe(mod, io, priv);
815 /* SSI probe might be called many times in MUX multi path */
816 ret = rsnd_dma_attach(io, mod, &ssi->dma);
821 static int rsnd_ssi_dma_remove(struct rsnd_mod *mod,
822 struct rsnd_dai_stream *io,
823 struct rsnd_priv *priv)
825 struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
826 struct rsnd_mod *ssi_parent_mod = rsnd_io_to_mod_ssip(io);
828 /* Do nothing for SSI parent mod */
829 if (ssi_parent_mod == mod)
832 /* PIO will request IRQ again */
833 free_irq(ssi->irq, mod);
838 static int rsnd_ssi_fallback(struct rsnd_mod *mod,
839 struct rsnd_dai_stream *io,
840 struct rsnd_priv *priv)
842 struct device *dev = rsnd_priv_to_dev(priv);
847 * SSI .probe might be called again.
849 * rsnd_rdai_continuance_probe()
851 mod->ops = &rsnd_ssi_pio_ops;
853 dev_info(dev, "%s[%d] fallback to PIO mode\n",
854 rsnd_mod_name(mod), rsnd_mod_id(mod));
859 static struct dma_chan *rsnd_ssi_dma_req(struct rsnd_dai_stream *io,
860 struct rsnd_mod *mod)
862 struct rsnd_priv *priv = rsnd_mod_to_priv(mod);
863 int is_play = rsnd_io_is_play(io);
866 if (rsnd_ssi_use_busif(io))
867 name = is_play ? "rxu" : "txu";
869 name = is_play ? "rx" : "tx";
871 return rsnd_dma_request_channel(rsnd_ssi_of_node(priv),
875 static struct rsnd_mod_ops rsnd_ssi_dma_ops = {
877 .dma_req = rsnd_ssi_dma_req,
878 .probe = rsnd_ssi_dma_probe,
879 .remove = rsnd_ssi_dma_remove,
880 .init = rsnd_ssi_init,
881 .quit = rsnd_ssi_quit,
882 .start = rsnd_ssi_start,
883 .stop = rsnd_ssi_stop,
885 .pcm_new = rsnd_ssi_pcm_new,
886 .fallback = rsnd_ssi_fallback,
887 .hw_params = rsnd_ssi_hw_params,
890 int rsnd_ssi_is_dma_mode(struct rsnd_mod *mod)
892 return mod->ops == &rsnd_ssi_dma_ops;
899 static void rsnd_ssi_connect(struct rsnd_mod *mod,
900 struct rsnd_dai_stream *io)
902 struct rsnd_dai *rdai = rsnd_io_to_rdai(io);
903 enum rsnd_mod_type types[] = {
909 enum rsnd_mod_type type;
912 /* try SSI -> SSIM1 -> SSIM2 -> SSIM3 */
913 for (i = 0; i < ARRAY_SIZE(types); i++) {
915 if (!rsnd_io_to_mod(io, type)) {
916 rsnd_dai_connect(mod, io, type);
917 rsnd_rdai_channels_set(rdai, (i + 1) * 2);
918 rsnd_rdai_ssi_lane_set(rdai, (i + 1));
924 void rsnd_parse_connect_ssi(struct rsnd_dai *rdai,
925 struct device_node *playback,
926 struct device_node *capture)
928 struct rsnd_priv *priv = rsnd_rdai_to_priv(rdai);
929 struct device_node *node;
930 struct device_node *np;
931 struct rsnd_mod *mod;
934 node = rsnd_ssi_of_node(priv);
939 for_each_child_of_node(node, np) {
940 mod = rsnd_ssi_mod_get(priv, i);
942 rsnd_ssi_connect(mod, &rdai->playback);
944 rsnd_ssi_connect(mod, &rdai->capture);
951 static void __rsnd_ssi_parse_hdmi_connection(struct rsnd_priv *priv,
952 struct rsnd_dai_stream *io,
953 struct device_node *remote_ep)
955 struct device *dev = rsnd_priv_to_dev(priv);
956 struct rsnd_mod *mod = rsnd_io_to_mod_ssi(io);
957 struct rsnd_ssi *ssi;
962 ssi = rsnd_mod_to_ssi(mod);
964 if (strstr(remote_ep->full_name, "hdmi0")) {
965 ssi->flags |= RSND_SSI_HDMI0;
966 dev_dbg(dev, "%s[%d] connected to HDMI0\n",
967 rsnd_mod_name(mod), rsnd_mod_id(mod));
970 if (strstr(remote_ep->full_name, "hdmi1")) {
971 ssi->flags |= RSND_SSI_HDMI1;
972 dev_dbg(dev, "%s[%d] connected to HDMI1\n",
973 rsnd_mod_name(mod), rsnd_mod_id(mod));
977 void rsnd_ssi_parse_hdmi_connection(struct rsnd_priv *priv,
978 struct device_node *endpoint,
981 struct rsnd_dai *rdai = rsnd_rdai_get(priv, dai_i);
982 struct device_node *remote_ep;
984 remote_ep = of_graph_get_remote_endpoint(endpoint);
988 __rsnd_ssi_parse_hdmi_connection(priv, &rdai->playback, remote_ep);
989 __rsnd_ssi_parse_hdmi_connection(priv, &rdai->capture, remote_ep);
992 struct rsnd_mod *rsnd_ssi_mod_get(struct rsnd_priv *priv, int id)
994 if (WARN_ON(id < 0 || id >= rsnd_ssi_nr(priv)))
997 return rsnd_mod_get(rsnd_ssi_get(priv, id));
1000 int __rsnd_ssi_is_pin_sharing(struct rsnd_mod *mod)
1002 struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
1004 return !!(rsnd_ssi_mode_flags(ssi) & RSND_SSI_CLK_PIN_SHARE);
1007 static u32 *rsnd_ssi_get_status(struct rsnd_dai_stream *io,
1008 struct rsnd_mod *mod,
1009 enum rsnd_mod_type type)
1012 * SSIP (= SSI parent) needs to be special, otherwise,
1013 * 2nd SSI might doesn't start. see also rsnd_mod_call()
1015 * We can't include parent SSI status on SSI, because we don't know
1016 * how many SSI requests parent SSI. Thus, it is localed on "io" now.
1019 * Capture : SSI1 (needs SSI0)
1021 * 1) start Capture -> SSI0/SSI1 are started.
1022 * 2) start Playback -> SSI0 doesn't work, because it is already
1023 * marked as "started" on 1)
1025 * OTOH, using each mod's status is good for MUX case.
1026 * It doesn't need to start in 2nd start
1028 * IO-0: SRC0 -> CTU1 -+-> MUX -> DVC -> SSIU -> SSI0
1030 * IO-1: SRC1 -> CTU2 -+
1032 * 1) start IO-0 -> start SSI0
1033 * 2) start IO-1 -> SSI0 doesn't need to start, because it is
1034 * already started on 1)
1036 if (type == RSND_MOD_SSIP)
1037 return &io->parent_ssi_status;
1039 return rsnd_mod_get_status(io, mod, type);
1042 int rsnd_ssi_probe(struct rsnd_priv *priv)
1044 struct device_node *node;
1045 struct device_node *np;
1046 struct device *dev = rsnd_priv_to_dev(priv);
1047 struct rsnd_mod_ops *ops;
1049 struct rsnd_ssi *ssi;
1050 char name[RSND_SSI_NAME_SIZE];
1053 node = rsnd_ssi_of_node(priv);
1057 nr = of_get_child_count(node);
1060 goto rsnd_ssi_probe_done;
1063 ssi = devm_kzalloc(dev, sizeof(*ssi) * nr, GFP_KERNEL);
1066 goto rsnd_ssi_probe_done;
1073 for_each_child_of_node(node, np) {
1074 ssi = rsnd_ssi_get(priv, i);
1076 snprintf(name, RSND_SSI_NAME_SIZE, "%s.%d",
1079 clk = devm_clk_get(dev, name);
1082 goto rsnd_ssi_probe_done;
1085 if (of_get_property(np, "shared-pin", NULL))
1086 ssi->flags |= RSND_SSI_CLK_PIN_SHARE;
1088 if (of_get_property(np, "no-busif", NULL))
1089 ssi->flags |= RSND_SSI_NO_BUSIF;
1091 ssi->irq = irq_of_parse_and_map(np, 0);
1094 goto rsnd_ssi_probe_done;
1097 if (of_property_read_bool(np, "pio-transfer"))
1098 ops = &rsnd_ssi_pio_ops;
1100 ops = &rsnd_ssi_dma_ops;
1102 ret = rsnd_mod_init(priv, rsnd_mod_get(ssi), ops, clk,
1103 rsnd_ssi_get_status, RSND_MOD_SSI, i);
1105 goto rsnd_ssi_probe_done;
1112 rsnd_ssi_probe_done:
1118 void rsnd_ssi_remove(struct rsnd_priv *priv)
1120 struct rsnd_ssi *ssi;
1123 for_each_rsnd_ssi(ssi, priv, i) {
1124 rsnd_mod_quit(rsnd_mod_get(ssi));