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 */
94 #define for_each_rsnd_ssi(pos, priv, i) \
96 (i < rsnd_ssi_nr(priv)) && \
97 ((pos) = ((struct rsnd_ssi *)(priv)->ssi + i)); \
100 #define rsnd_ssi_get(priv, id) ((struct rsnd_ssi *)(priv->ssi) + id)
101 #define rsnd_ssi_to_dma(mod) ((ssi)->dma)
102 #define rsnd_ssi_nr(priv) ((priv)->ssi_nr)
103 #define rsnd_mod_to_ssi(_mod) container_of((_mod), struct rsnd_ssi, mod)
104 #define rsnd_ssi_mode_flags(p) ((p)->flags)
105 #define rsnd_ssi_is_parent(ssi, io) ((ssi) == rsnd_io_to_mod_ssip(io))
106 #define rsnd_ssi_is_multi_slave(mod, io) \
107 (rsnd_ssi_multi_slaves(io) & (1 << rsnd_mod_id(mod)))
108 #define rsnd_ssi_is_run_mods(mod, io) \
109 (rsnd_ssi_run_mods(io) & (1 << rsnd_mod_id(mod)))
110 #define rsnd_ssi_can_output_clk(mod) (!__rsnd_ssi_is_pin_sharing(mod))
112 int rsnd_ssi_hdmi_port(struct rsnd_dai_stream *io)
114 struct rsnd_mod *mod = rsnd_io_to_mod_ssi(io);
115 struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
117 if (rsnd_ssi_mode_flags(ssi) & RSND_SSI_HDMI0)
118 return RSND_SSI_HDMI_PORT0;
120 if (rsnd_ssi_mode_flags(ssi) & RSND_SSI_HDMI1)
121 return RSND_SSI_HDMI_PORT1;
126 int rsnd_ssi_use_busif(struct rsnd_dai_stream *io)
128 struct rsnd_mod *mod = rsnd_io_to_mod_ssi(io);
129 struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
132 if (!rsnd_ssi_is_dma_mode(mod))
135 if (!(rsnd_ssi_mode_flags(ssi) & RSND_SSI_NO_BUSIF))
137 if (rsnd_io_to_mod_src(io))
143 static void rsnd_ssi_status_clear(struct rsnd_mod *mod)
145 rsnd_mod_write(mod, SSISR, 0);
148 static u32 rsnd_ssi_status_get(struct rsnd_mod *mod)
150 return rsnd_mod_read(mod, SSISR);
153 static void rsnd_ssi_status_check(struct rsnd_mod *mod,
156 struct rsnd_priv *priv = rsnd_mod_to_priv(mod);
157 struct device *dev = rsnd_priv_to_dev(priv);
161 for (i = 0; i < 1024; i++) {
162 status = rsnd_ssi_status_get(mod);
169 dev_warn(dev, "%s[%d] status check failed\n",
170 rsnd_mod_name(mod), rsnd_mod_id(mod));
173 static u32 rsnd_ssi_multi_slaves(struct rsnd_dai_stream *io)
175 struct rsnd_mod *mod;
176 enum rsnd_mod_type types[] = {
184 for (i = 0; i < ARRAY_SIZE(types); i++) {
185 mod = rsnd_io_to_mod(io, types[i]);
189 mask |= 1 << rsnd_mod_id(mod);
195 static u32 rsnd_ssi_run_mods(struct rsnd_dai_stream *io)
197 struct rsnd_mod *ssi_mod = rsnd_io_to_mod_ssi(io);
198 struct rsnd_mod *ssi_parent_mod = rsnd_io_to_mod_ssip(io);
200 return rsnd_ssi_multi_slaves_runtime(io) |
201 1 << rsnd_mod_id(ssi_mod) |
202 1 << rsnd_mod_id(ssi_parent_mod);
205 u32 rsnd_ssi_multi_slaves_runtime(struct rsnd_dai_stream *io)
207 if (rsnd_runtime_is_ssi_multi(io))
208 return rsnd_ssi_multi_slaves(io);
213 unsigned int rsnd_ssi_clk_query(struct rsnd_priv *priv,
214 int param1, int param2, int *idx)
216 int ssi_clk_mul_table[] = {
217 1, 2, 4, 8, 16, 6, 12,
220 unsigned int main_rate;
222 for (j = 0; j < ARRAY_SIZE(ssi_clk_mul_table); j++) {
225 * It will set SSIWSR.CONT here, but SSICR.CKDV = 000
226 * with it is not allowed. (SSIWSR.WS_MODE with
227 * SSICR.CKDV = 000 is not allowed either).
228 * Skip it. See SSICR.CKDV
234 * this driver is assuming that
235 * system word is 32bit x chan
236 * see rsnd_ssi_init()
238 main_rate = 32 * param1 * param2 * ssi_clk_mul_table[j];
240 ret = rsnd_adg_clk_query(priv, main_rate);
253 static int rsnd_ssi_master_clk_start(struct rsnd_mod *mod,
254 struct rsnd_dai_stream *io)
256 struct rsnd_priv *priv = rsnd_io_to_priv(io);
257 struct device *dev = rsnd_priv_to_dev(priv);
258 struct rsnd_dai *rdai = rsnd_io_to_rdai(io);
259 struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
260 int chan = rsnd_runtime_channel_for_ssi(io);
262 unsigned int main_rate;
263 unsigned int rate = rsnd_io_is_play(io) ?
264 rsnd_src_get_out_rate(priv, io) :
265 rsnd_src_get_in_rate(priv, io);
267 if (!rsnd_rdai_is_clk_master(rdai))
270 if (!rsnd_ssi_can_output_clk(mod))
273 if (rsnd_ssi_is_multi_slave(mod, io))
276 if (ssi->usrcnt > 1) {
277 if (ssi->rate != rate) {
278 dev_err(dev, "SSI parent/child should use same rate\n");
285 main_rate = rsnd_ssi_clk_query(priv, rate, chan, &idx);
287 dev_err(dev, "unsupported clock rate\n");
291 ret = rsnd_adg_ssi_clk_try_start(mod, main_rate);
296 * SSI clock will be output contiguously
298 * This means, rsnd_ssi_master_clk_start()
299 * and rsnd_ssi_register_setup() are necessary
302 * SSICR : FORCE, SCKD, SWSD
305 ssi->cr_clk = FORCE | SWL_32 | SCKD | SWSD | CKDV(idx);
309 dev_dbg(dev, "%s[%d] outputs %u Hz\n",
311 rsnd_mod_id(mod), rate);
316 static void rsnd_ssi_master_clk_stop(struct rsnd_mod *mod,
317 struct rsnd_dai_stream *io)
319 struct rsnd_dai *rdai = rsnd_io_to_rdai(io);
320 struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
322 if (!rsnd_rdai_is_clk_master(rdai))
325 if (!rsnd_ssi_can_output_clk(mod))
334 rsnd_adg_ssi_clk_stop(mod);
337 static void rsnd_ssi_config_init(struct rsnd_mod *mod,
338 struct rsnd_dai_stream *io)
340 struct rsnd_dai *rdai = rsnd_io_to_rdai(io);
341 struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io);
342 struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
348 if (rsnd_ssi_is_parent(mod, io))
351 is_tdm = rsnd_runtime_is_ssi_tdm(io);
354 * always use 32bit system word.
355 * see also rsnd_ssi_master_clk_enable()
357 cr_own = FORCE | SWL_32;
359 if (rdai->bit_clk_inv)
361 if (rdai->frm_clk_inv ^ is_tdm)
363 if (rdai->data_alignment)
367 if (rsnd_io_is_play(io))
370 switch (runtime->sample_bits) {
379 if (rsnd_ssi_is_dma_mode(mod)) {
380 cr_mode = UIEN | OIEN | /* over/under run */
381 DMEN; /* DMA : enable DMA */
383 cr_mode = DIEN; /* PIO : enable Data interrupt */
389 * rsnd_ssiu_init_gen2()
397 ssi->cr_own = cr_own;
398 ssi->cr_mode = cr_mode;
402 static void rsnd_ssi_register_setup(struct rsnd_mod *mod)
404 struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
406 rsnd_mod_write(mod, SSIWSR, ssi->wsr);
407 rsnd_mod_write(mod, SSICR, ssi->cr_own |
413 static void rsnd_ssi_pointer_init(struct rsnd_mod *mod,
414 struct rsnd_dai_stream *io)
416 struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
417 struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io);
421 ssi->byte_per_period = runtime->period_size *
423 samples_to_bytes(runtime, 1);
424 ssi->next_period_byte = ssi->byte_per_period;
427 static int rsnd_ssi_pointer_offset(struct rsnd_mod *mod,
428 struct rsnd_dai_stream *io,
431 struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
432 struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io);
433 int pos = ssi->byte_pos + additional;
435 pos %= (runtime->periods * ssi->byte_per_period);
440 static bool rsnd_ssi_pointer_update(struct rsnd_mod *mod,
441 struct rsnd_dai_stream *io,
444 struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
446 ssi->byte_pos += byte;
448 if (ssi->byte_pos >= ssi->next_period_byte) {
449 struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io);
452 ssi->next_period_byte += ssi->byte_per_period;
454 if (ssi->period_pos >= runtime->periods) {
457 ssi->next_period_byte = ssi->byte_per_period;
467 * SSI mod common functions
469 static int rsnd_ssi_init(struct rsnd_mod *mod,
470 struct rsnd_dai_stream *io,
471 struct rsnd_priv *priv)
473 struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
476 if (!rsnd_ssi_is_run_mods(mod, io))
479 rsnd_ssi_pointer_init(mod, io);
483 rsnd_mod_power_on(mod);
485 ret = rsnd_ssi_master_clk_start(mod, io);
489 rsnd_ssi_config_init(mod, io);
491 rsnd_ssi_register_setup(mod);
493 /* clear error status */
494 rsnd_ssi_status_clear(mod);
499 static int rsnd_ssi_quit(struct rsnd_mod *mod,
500 struct rsnd_dai_stream *io,
501 struct rsnd_priv *priv)
503 struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
504 struct device *dev = rsnd_priv_to_dev(priv);
506 if (!rsnd_ssi_is_run_mods(mod, io))
510 dev_err(dev, "%s[%d] usrcnt error\n",
511 rsnd_mod_name(mod), rsnd_mod_id(mod));
515 if (!rsnd_ssi_is_parent(mod, io))
518 rsnd_ssi_master_clk_stop(mod, io);
520 rsnd_mod_power_off(mod);
527 static int rsnd_ssi_hw_params(struct rsnd_mod *mod,
528 struct rsnd_dai_stream *io,
529 struct snd_pcm_substream *substream,
530 struct snd_pcm_hw_params *params)
532 struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
533 int chan = params_channels(params);
536 * snd_pcm_ops::hw_params will be called *before*
537 * snd_soc_dai_ops::trigger. Thus, ssi->usrcnt is 0
543 * It will happen if SSI has parent/child connection.
544 * it is error if child <-> parent SSI uses
545 * different channels.
547 if (ssi->chan != chan)
556 static int rsnd_ssi_start(struct rsnd_mod *mod,
557 struct rsnd_dai_stream *io,
558 struct rsnd_priv *priv)
560 struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
562 if (!rsnd_ssi_is_run_mods(mod, io))
566 * EN will be set via SSIU :: SSI_CONTROL
567 * if Multi channel mode
569 if (rsnd_ssi_multi_slaves_runtime(io))
573 * EN is for data output.
574 * SSI parent EN is not needed.
576 if (rsnd_ssi_is_parent(mod, io))
581 rsnd_mod_write(mod, SSICR, ssi->cr_own |
589 static int rsnd_ssi_stop(struct rsnd_mod *mod,
590 struct rsnd_dai_stream *io,
591 struct rsnd_priv *priv)
593 struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
596 if (!rsnd_ssi_is_run_mods(mod, io))
599 if (rsnd_ssi_is_parent(mod, io))
604 * and, wait all data was sent
609 rsnd_mod_write(mod, SSICR, cr | EN);
610 rsnd_ssi_status_check(mod, DIRQ);
614 * and, wait idle state
616 rsnd_mod_write(mod, SSICR, cr); /* disabled all */
617 rsnd_ssi_status_check(mod, IIRQ);
624 static int rsnd_ssi_irq(struct rsnd_mod *mod,
625 struct rsnd_dai_stream *io,
626 struct rsnd_priv *priv,
631 if (rsnd_is_gen1(priv))
634 if (rsnd_ssi_is_parent(mod, io))
637 if (!rsnd_ssi_is_run_mods(mod, io))
641 val = rsnd_ssi_is_dma_mode(mod) ? 0x0e000000 : 0x0f000000;
643 rsnd_mod_write(mod, SSI_INT_ENABLE, val);
648 static void __rsnd_ssi_interrupt(struct rsnd_mod *mod,
649 struct rsnd_dai_stream *io)
651 struct rsnd_priv *priv = rsnd_mod_to_priv(mod);
652 int is_dma = rsnd_ssi_is_dma_mode(mod);
654 bool elapsed = false;
657 spin_lock(&priv->lock);
659 /* ignore all cases if not working */
660 if (!rsnd_io_is_working(io))
661 goto rsnd_ssi_interrupt_out;
663 status = rsnd_ssi_status_get(mod);
666 if (!is_dma && (status & DIRQ)) {
667 struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io);
668 u32 *buf = (u32 *)(runtime->dma_area +
669 rsnd_ssi_pointer_offset(mod, io, 0));
672 switch (runtime->sample_bits) {
679 * 8/16/32 data can be assesse to TDR/RDR register
680 * directly as 32bit data
681 * see rsnd_ssi_init()
683 if (rsnd_io_is_play(io))
684 rsnd_mod_write(mod, SSITDR, (*buf) << shift);
686 *buf = (rsnd_mod_read(mod, SSIRDR) >> shift);
688 elapsed = rsnd_ssi_pointer_update(mod, io, sizeof(*buf));
692 if (is_dma && (status & (UIRQ | OIRQ)))
695 rsnd_ssi_status_clear(mod);
696 rsnd_ssi_interrupt_out:
697 spin_unlock(&priv->lock);
700 rsnd_dai_period_elapsed(io);
703 snd_pcm_stop_xrun(io->substream);
707 static irqreturn_t rsnd_ssi_interrupt(int irq, void *data)
709 struct rsnd_mod *mod = data;
711 rsnd_mod_interrupt(mod, __rsnd_ssi_interrupt);
719 static void rsnd_ssi_parent_attach(struct rsnd_mod *mod,
720 struct rsnd_dai_stream *io)
722 struct rsnd_dai *rdai = rsnd_io_to_rdai(io);
723 struct rsnd_priv *priv = rsnd_mod_to_priv(mod);
725 if (!__rsnd_ssi_is_pin_sharing(mod))
728 if (!rsnd_rdai_is_clk_master(rdai))
731 switch (rsnd_mod_id(mod)) {
734 rsnd_dai_connect(rsnd_ssi_mod_get(priv, 0), io, RSND_MOD_SSIP);
737 rsnd_dai_connect(rsnd_ssi_mod_get(priv, 3), io, RSND_MOD_SSIP);
740 rsnd_dai_connect(rsnd_ssi_mod_get(priv, 7), io, RSND_MOD_SSIP);
745 static int rsnd_ssi_pcm_new(struct rsnd_mod *mod,
746 struct rsnd_dai_stream *io,
747 struct snd_soc_pcm_runtime *rtd)
750 * rsnd_rdai_is_clk_master() will be enabled after set_fmt,
751 * and, pcm_new will be called after it.
752 * This function reuse pcm_new at this point.
754 rsnd_ssi_parent_attach(mod, io);
759 static int rsnd_ssi_common_probe(struct rsnd_mod *mod,
760 struct rsnd_dai_stream *io,
761 struct rsnd_priv *priv)
763 struct device *dev = rsnd_priv_to_dev(priv);
764 struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
768 * SSIP/SSIU/IRQ are not needed on
771 if (rsnd_ssi_is_multi_slave(mod, io))
775 * It can't judge ssi parent at this point
776 * see rsnd_ssi_pcm_new()
779 ret = rsnd_ssiu_attach(io, mod);
784 * SSI might be called again as PIO fallback
785 * It is easy to manual handling for IRQ request/free
787 ret = request_irq(ssi->irq,
795 static int rsnd_ssi_pointer(struct rsnd_mod *mod,
796 struct rsnd_dai_stream *io,
797 snd_pcm_uframes_t *pointer)
799 struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
800 struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io);
802 *pointer = bytes_to_frames(runtime, ssi->byte_pos);
807 static struct rsnd_mod_ops rsnd_ssi_pio_ops = {
809 .probe = rsnd_ssi_common_probe,
810 .init = rsnd_ssi_init,
811 .quit = rsnd_ssi_quit,
812 .start = rsnd_ssi_start,
813 .stop = rsnd_ssi_stop,
815 .pointer= rsnd_ssi_pointer,
816 .pcm_new = rsnd_ssi_pcm_new,
817 .hw_params = rsnd_ssi_hw_params,
820 static int rsnd_ssi_dma_probe(struct rsnd_mod *mod,
821 struct rsnd_dai_stream *io,
822 struct rsnd_priv *priv)
824 struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
828 * SSIP/SSIU/IRQ/DMA are not needed on
831 if (rsnd_ssi_is_multi_slave(mod, io))
834 ret = rsnd_ssi_common_probe(mod, io, priv);
838 /* SSI probe might be called many times in MUX multi path */
839 ret = rsnd_dma_attach(io, mod, &ssi->dma);
844 static int rsnd_ssi_dma_remove(struct rsnd_mod *mod,
845 struct rsnd_dai_stream *io,
846 struct rsnd_priv *priv)
848 struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
849 struct rsnd_mod *pure_ssi_mod = rsnd_io_to_mod_ssi(io);
851 /* Do nothing if non SSI (= SSI parent, multi SSI) mod */
852 if (pure_ssi_mod != mod)
855 /* PIO will request IRQ again */
856 free_irq(ssi->irq, mod);
861 static int rsnd_ssi_fallback(struct rsnd_mod *mod,
862 struct rsnd_dai_stream *io,
863 struct rsnd_priv *priv)
865 struct device *dev = rsnd_priv_to_dev(priv);
870 * SSI .probe might be called again.
872 * rsnd_rdai_continuance_probe()
874 mod->ops = &rsnd_ssi_pio_ops;
876 dev_info(dev, "%s[%d] fallback to PIO mode\n",
877 rsnd_mod_name(mod), rsnd_mod_id(mod));
882 static struct dma_chan *rsnd_ssi_dma_req(struct rsnd_dai_stream *io,
883 struct rsnd_mod *mod)
885 struct rsnd_priv *priv = rsnd_mod_to_priv(mod);
886 int is_play = rsnd_io_is_play(io);
889 if (rsnd_ssi_use_busif(io))
890 name = is_play ? "rxu" : "txu";
892 name = is_play ? "rx" : "tx";
894 return rsnd_dma_request_channel(rsnd_ssi_of_node(priv),
898 static struct rsnd_mod_ops rsnd_ssi_dma_ops = {
900 .dma_req = rsnd_ssi_dma_req,
901 .probe = rsnd_ssi_dma_probe,
902 .remove = rsnd_ssi_dma_remove,
903 .init = rsnd_ssi_init,
904 .quit = rsnd_ssi_quit,
905 .start = rsnd_ssi_start,
906 .stop = rsnd_ssi_stop,
908 .pcm_new = rsnd_ssi_pcm_new,
909 .fallback = rsnd_ssi_fallback,
910 .hw_params = rsnd_ssi_hw_params,
913 int rsnd_ssi_is_dma_mode(struct rsnd_mod *mod)
915 return mod->ops == &rsnd_ssi_dma_ops;
922 static void rsnd_ssi_connect(struct rsnd_mod *mod,
923 struct rsnd_dai_stream *io)
925 struct rsnd_dai *rdai = rsnd_io_to_rdai(io);
926 enum rsnd_mod_type types[] = {
932 enum rsnd_mod_type type;
935 /* try SSI -> SSIM1 -> SSIM2 -> SSIM3 */
936 for (i = 0; i < ARRAY_SIZE(types); i++) {
938 if (!rsnd_io_to_mod(io, type)) {
939 rsnd_dai_connect(mod, io, type);
940 rsnd_rdai_channels_set(rdai, (i + 1) * 2);
941 rsnd_rdai_ssi_lane_set(rdai, (i + 1));
947 void rsnd_parse_connect_ssi(struct rsnd_dai *rdai,
948 struct device_node *playback,
949 struct device_node *capture)
951 struct rsnd_priv *priv = rsnd_rdai_to_priv(rdai);
952 struct device_node *node;
953 struct device_node *np;
954 struct rsnd_mod *mod;
957 node = rsnd_ssi_of_node(priv);
962 for_each_child_of_node(node, np) {
963 mod = rsnd_ssi_mod_get(priv, i);
965 rsnd_ssi_connect(mod, &rdai->playback);
967 rsnd_ssi_connect(mod, &rdai->capture);
974 static void __rsnd_ssi_parse_hdmi_connection(struct rsnd_priv *priv,
975 struct rsnd_dai_stream *io,
976 struct device_node *remote_ep)
978 struct device *dev = rsnd_priv_to_dev(priv);
979 struct rsnd_mod *mod = rsnd_io_to_mod_ssi(io);
980 struct rsnd_ssi *ssi;
985 ssi = rsnd_mod_to_ssi(mod);
987 if (strstr(remote_ep->full_name, "hdmi0")) {
988 ssi->flags |= RSND_SSI_HDMI0;
989 dev_dbg(dev, "%s[%d] connected to HDMI0\n",
990 rsnd_mod_name(mod), rsnd_mod_id(mod));
993 if (strstr(remote_ep->full_name, "hdmi1")) {
994 ssi->flags |= RSND_SSI_HDMI1;
995 dev_dbg(dev, "%s[%d] connected to HDMI1\n",
996 rsnd_mod_name(mod), rsnd_mod_id(mod));
1000 void rsnd_ssi_parse_hdmi_connection(struct rsnd_priv *priv,
1001 struct device_node *endpoint,
1004 struct rsnd_dai *rdai = rsnd_rdai_get(priv, dai_i);
1005 struct device_node *remote_ep;
1007 remote_ep = of_graph_get_remote_endpoint(endpoint);
1011 __rsnd_ssi_parse_hdmi_connection(priv, &rdai->playback, remote_ep);
1012 __rsnd_ssi_parse_hdmi_connection(priv, &rdai->capture, remote_ep);
1015 struct rsnd_mod *rsnd_ssi_mod_get(struct rsnd_priv *priv, int id)
1017 if (WARN_ON(id < 0 || id >= rsnd_ssi_nr(priv)))
1020 return rsnd_mod_get(rsnd_ssi_get(priv, id));
1023 int __rsnd_ssi_is_pin_sharing(struct rsnd_mod *mod)
1025 struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
1027 return !!(rsnd_ssi_mode_flags(ssi) & RSND_SSI_CLK_PIN_SHARE);
1030 static u32 *rsnd_ssi_get_status(struct rsnd_dai_stream *io,
1031 struct rsnd_mod *mod,
1032 enum rsnd_mod_type type)
1035 * SSIP (= SSI parent) needs to be special, otherwise,
1036 * 2nd SSI might doesn't start. see also rsnd_mod_call()
1038 * We can't include parent SSI status on SSI, because we don't know
1039 * how many SSI requests parent SSI. Thus, it is localed on "io" now.
1042 * Capture : SSI1 (needs SSI0)
1044 * 1) start Capture -> SSI0/SSI1 are started.
1045 * 2) start Playback -> SSI0 doesn't work, because it is already
1046 * marked as "started" on 1)
1048 * OTOH, using each mod's status is good for MUX case.
1049 * It doesn't need to start in 2nd start
1051 * IO-0: SRC0 -> CTU1 -+-> MUX -> DVC -> SSIU -> SSI0
1053 * IO-1: SRC1 -> CTU2 -+
1055 * 1) start IO-0 -> start SSI0
1056 * 2) start IO-1 -> SSI0 doesn't need to start, because it is
1057 * already started on 1)
1059 if (type == RSND_MOD_SSIP)
1060 return &io->parent_ssi_status;
1062 return rsnd_mod_get_status(io, mod, type);
1065 int rsnd_ssi_probe(struct rsnd_priv *priv)
1067 struct device_node *node;
1068 struct device_node *np;
1069 struct device *dev = rsnd_priv_to_dev(priv);
1070 struct rsnd_mod_ops *ops;
1072 struct rsnd_ssi *ssi;
1073 char name[RSND_SSI_NAME_SIZE];
1076 node = rsnd_ssi_of_node(priv);
1080 nr = of_get_child_count(node);
1083 goto rsnd_ssi_probe_done;
1086 ssi = devm_kzalloc(dev, sizeof(*ssi) * nr, GFP_KERNEL);
1089 goto rsnd_ssi_probe_done;
1096 for_each_child_of_node(node, np) {
1097 ssi = rsnd_ssi_get(priv, i);
1099 snprintf(name, RSND_SSI_NAME_SIZE, "%s.%d",
1102 clk = devm_clk_get(dev, name);
1106 goto rsnd_ssi_probe_done;
1109 if (of_get_property(np, "shared-pin", NULL))
1110 ssi->flags |= RSND_SSI_CLK_PIN_SHARE;
1112 if (of_get_property(np, "no-busif", NULL))
1113 ssi->flags |= RSND_SSI_NO_BUSIF;
1115 ssi->irq = irq_of_parse_and_map(np, 0);
1119 goto rsnd_ssi_probe_done;
1122 if (of_property_read_bool(np, "pio-transfer"))
1123 ops = &rsnd_ssi_pio_ops;
1125 ops = &rsnd_ssi_dma_ops;
1127 ret = rsnd_mod_init(priv, rsnd_mod_get(ssi), ops, clk,
1128 rsnd_ssi_get_status, RSND_MOD_SSI, i);
1131 goto rsnd_ssi_probe_done;
1139 rsnd_ssi_probe_done:
1145 void rsnd_ssi_remove(struct rsnd_priv *priv)
1147 struct rsnd_ssi *ssi;
1150 for_each_rsnd_ssi(ssi, priv, i) {
1151 rsnd_mod_quit(rsnd_mod_get(ssi));