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)))
109 #define rsnd_ssi_can_output_clk(mod) (!__rsnd_ssi_is_pin_sharing(mod))
111 int rsnd_ssi_hdmi_port(struct rsnd_dai_stream *io)
113 struct rsnd_mod *mod = rsnd_io_to_mod_ssi(io);
114 struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
116 if (rsnd_ssi_mode_flags(ssi) & RSND_SSI_HDMI0)
117 return RSND_SSI_HDMI_PORT0;
119 if (rsnd_ssi_mode_flags(ssi) & RSND_SSI_HDMI1)
120 return RSND_SSI_HDMI_PORT1;
125 int rsnd_ssi_use_busif(struct rsnd_dai_stream *io)
127 struct rsnd_mod *mod = rsnd_io_to_mod_ssi(io);
128 struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
131 if (!rsnd_ssi_is_dma_mode(mod))
134 if (!(rsnd_ssi_mode_flags(ssi) & RSND_SSI_NO_BUSIF))
136 if (rsnd_io_to_mod_src(io))
142 static void rsnd_ssi_status_clear(struct rsnd_mod *mod)
144 rsnd_mod_write(mod, SSISR, 0);
147 static u32 rsnd_ssi_status_get(struct rsnd_mod *mod)
149 return rsnd_mod_read(mod, SSISR);
152 static void rsnd_ssi_status_check(struct rsnd_mod *mod,
155 struct rsnd_priv *priv = rsnd_mod_to_priv(mod);
156 struct device *dev = rsnd_priv_to_dev(priv);
160 for (i = 0; i < 1024; i++) {
161 status = rsnd_ssi_status_get(mod);
168 dev_warn(dev, "%s[%d] status check failed\n",
169 rsnd_mod_name(mod), rsnd_mod_id(mod));
172 static u32 rsnd_ssi_multi_slaves(struct rsnd_dai_stream *io)
174 struct rsnd_mod *mod;
175 enum rsnd_mod_type types[] = {
183 for (i = 0; i < ARRAY_SIZE(types); i++) {
184 mod = rsnd_io_to_mod(io, types[i]);
188 mask |= 1 << rsnd_mod_id(mod);
194 static u32 rsnd_ssi_run_mods(struct rsnd_dai_stream *io)
196 struct rsnd_mod *ssi_mod = rsnd_io_to_mod_ssi(io);
197 struct rsnd_mod *ssi_parent_mod = rsnd_io_to_mod_ssip(io);
199 return rsnd_ssi_multi_slaves_runtime(io) |
200 1 << rsnd_mod_id(ssi_mod) |
201 1 << rsnd_mod_id(ssi_parent_mod);
204 u32 rsnd_ssi_multi_slaves_runtime(struct rsnd_dai_stream *io)
206 if (rsnd_runtime_is_ssi_multi(io))
207 return rsnd_ssi_multi_slaves(io);
212 unsigned int rsnd_ssi_clk_query(struct rsnd_priv *priv,
213 int param1, int param2, int *idx)
215 int ssi_clk_mul_table[] = {
216 1, 2, 4, 8, 16, 6, 12,
219 unsigned int main_rate;
221 for (j = 0; j < ARRAY_SIZE(ssi_clk_mul_table); j++) {
224 * It will set SSIWSR.CONT here, but SSICR.CKDV = 000
225 * with it is not allowed. (SSIWSR.WS_MODE with
226 * SSICR.CKDV = 000 is not allowed either).
227 * Skip it. See SSICR.CKDV
233 * this driver is assuming that
234 * system word is 32bit x chan
235 * see rsnd_ssi_init()
237 main_rate = 32 * param1 * param2 * ssi_clk_mul_table[j];
239 ret = rsnd_adg_clk_query(priv, main_rate);
252 static int rsnd_ssi_master_clk_start(struct rsnd_mod *mod,
253 struct rsnd_dai_stream *io)
255 struct rsnd_priv *priv = rsnd_io_to_priv(io);
256 struct device *dev = rsnd_priv_to_dev(priv);
257 struct rsnd_dai *rdai = rsnd_io_to_rdai(io);
258 struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
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 (!rsnd_ssi_can_output_clk(mod))
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);
311 if (!rsnd_rdai_is_clk_master(rdai))
314 if (!rsnd_ssi_can_output_clk(mod))
323 rsnd_adg_ssi_clk_stop(mod);
326 static void rsnd_ssi_config_init(struct rsnd_mod *mod,
327 struct rsnd_dai_stream *io)
329 struct rsnd_dai *rdai = rsnd_io_to_rdai(io);
330 struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io);
331 struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
337 if (rsnd_ssi_is_parent(mod, io))
340 is_tdm = rsnd_runtime_is_ssi_tdm(io);
343 * always use 32bit system word.
344 * see also rsnd_ssi_master_clk_enable()
346 cr_own = FORCE | SWL_32;
348 if (rdai->bit_clk_inv)
350 if (rdai->frm_clk_inv ^ is_tdm)
352 if (rdai->data_alignment)
356 if (rsnd_io_is_play(io))
359 switch (runtime->sample_bits) {
368 if (rsnd_ssi_is_dma_mode(mod)) {
369 cr_mode = UIEN | OIEN | /* over/under run */
370 DMEN; /* DMA : enable DMA */
372 cr_mode = DIEN; /* PIO : enable Data interrupt */
378 * rsnd_ssiu_init_gen2()
386 ssi->cr_own = cr_own;
387 ssi->cr_mode = cr_mode;
391 static void rsnd_ssi_register_setup(struct rsnd_mod *mod)
393 struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
395 rsnd_mod_write(mod, SSIWSR, ssi->wsr);
396 rsnd_mod_write(mod, SSICR, ssi->cr_own |
398 ssi->cr_mode); /* without EN */
401 static void rsnd_ssi_pointer_init(struct rsnd_mod *mod,
402 struct rsnd_dai_stream *io)
404 struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
405 struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io);
409 ssi->byte_per_period = runtime->period_size *
411 samples_to_bytes(runtime, 1);
412 ssi->next_period_byte = ssi->byte_per_period;
415 static int rsnd_ssi_pointer_offset(struct rsnd_mod *mod,
416 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);
421 int pos = ssi->byte_pos + additional;
423 pos %= (runtime->periods * ssi->byte_per_period);
428 static bool rsnd_ssi_pointer_update(struct rsnd_mod *mod,
429 struct rsnd_dai_stream *io,
432 struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
434 ssi->byte_pos += byte;
436 if (ssi->byte_pos >= ssi->next_period_byte) {
437 struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io);
440 ssi->next_period_byte += ssi->byte_per_period;
442 if (ssi->period_pos >= runtime->periods) {
445 ssi->next_period_byte = ssi->byte_per_period;
455 * SSI mod common functions
457 static int rsnd_ssi_init(struct rsnd_mod *mod,
458 struct rsnd_dai_stream *io,
459 struct rsnd_priv *priv)
461 struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
464 if (!rsnd_ssi_is_run_mods(mod, io))
467 rsnd_ssi_pointer_init(mod, io);
471 rsnd_mod_power_on(mod);
473 ret = rsnd_ssi_master_clk_start(mod, io);
477 rsnd_ssi_config_init(mod, io);
479 rsnd_ssi_register_setup(mod);
481 /* clear error status */
482 rsnd_ssi_status_clear(mod);
487 static int rsnd_ssi_quit(struct rsnd_mod *mod,
488 struct rsnd_dai_stream *io,
489 struct rsnd_priv *priv)
491 struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
492 struct device *dev = rsnd_priv_to_dev(priv);
494 if (!rsnd_ssi_is_run_mods(mod, io))
498 dev_err(dev, "%s[%d] usrcnt error\n",
499 rsnd_mod_name(mod), rsnd_mod_id(mod));
503 if (!rsnd_ssi_is_parent(mod, io))
506 rsnd_ssi_master_clk_stop(mod, io);
508 rsnd_mod_power_off(mod);
515 static int rsnd_ssi_hw_params(struct rsnd_mod *mod,
516 struct rsnd_dai_stream *io,
517 struct snd_pcm_substream *substream,
518 struct snd_pcm_hw_params *params)
520 struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
521 int chan = params_channels(params);
524 * snd_pcm_ops::hw_params will be called *before*
525 * snd_soc_dai_ops::trigger. Thus, ssi->usrcnt is 0
531 * It will happen if SSI has parent/child connection.
532 * it is error if child <-> parent SSI uses
533 * different channels.
535 if (ssi->chan != chan)
544 static int rsnd_ssi_start(struct rsnd_mod *mod,
545 struct rsnd_dai_stream *io,
546 struct rsnd_priv *priv)
548 if (!rsnd_ssi_is_run_mods(mod, io))
552 * EN will be set via SSIU :: SSI_CONTROL
553 * if Multi channel mode
555 if (rsnd_ssi_multi_slaves_runtime(io))
558 rsnd_mod_bset(mod, SSICR, EN, EN);
563 static int rsnd_ssi_stop(struct rsnd_mod *mod,
564 struct rsnd_dai_stream *io,
565 struct rsnd_priv *priv)
567 struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
570 if (!rsnd_ssi_is_run_mods(mod, io))
574 * don't stop if not last user
584 * and, wait all data was sent
589 rsnd_mod_write(mod, SSICR, cr | EN);
590 rsnd_ssi_status_check(mod, DIRQ);
594 * and, wait idle state
596 rsnd_mod_write(mod, SSICR, cr); /* disabled all */
597 rsnd_ssi_status_check(mod, IIRQ);
602 static int rsnd_ssi_irq(struct rsnd_mod *mod,
603 struct rsnd_dai_stream *io,
604 struct rsnd_priv *priv,
609 if (rsnd_is_gen1(priv))
612 if (rsnd_ssi_is_parent(mod, io))
615 if (!rsnd_ssi_is_run_mods(mod, io))
619 val = rsnd_ssi_is_dma_mode(mod) ? 0x0e000000 : 0x0f000000;
621 rsnd_mod_write(mod, SSI_INT_ENABLE, val);
626 static void __rsnd_ssi_interrupt(struct rsnd_mod *mod,
627 struct rsnd_dai_stream *io)
629 struct rsnd_priv *priv = rsnd_mod_to_priv(mod);
630 int is_dma = rsnd_ssi_is_dma_mode(mod);
632 bool elapsed = false;
635 spin_lock(&priv->lock);
637 /* ignore all cases if not working */
638 if (!rsnd_io_is_working(io))
639 goto rsnd_ssi_interrupt_out;
641 status = rsnd_ssi_status_get(mod);
644 if (!is_dma && (status & DIRQ)) {
645 struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io);
646 u32 *buf = (u32 *)(runtime->dma_area +
647 rsnd_ssi_pointer_offset(mod, io, 0));
650 switch (runtime->sample_bits) {
657 * 8/16/32 data can be assesse to TDR/RDR register
658 * directly as 32bit data
659 * see rsnd_ssi_init()
661 if (rsnd_io_is_play(io))
662 rsnd_mod_write(mod, SSITDR, (*buf) << shift);
664 *buf = (rsnd_mod_read(mod, SSIRDR) >> shift);
666 elapsed = rsnd_ssi_pointer_update(mod, io, sizeof(*buf));
670 if (is_dma && (status & (UIRQ | OIRQ)))
673 rsnd_ssi_status_clear(mod);
674 rsnd_ssi_interrupt_out:
675 spin_unlock(&priv->lock);
678 rsnd_dai_period_elapsed(io);
681 snd_pcm_stop_xrun(io->substream);
685 static irqreturn_t rsnd_ssi_interrupt(int irq, void *data)
687 struct rsnd_mod *mod = data;
689 rsnd_mod_interrupt(mod, __rsnd_ssi_interrupt);
697 static void rsnd_ssi_parent_attach(struct rsnd_mod *mod,
698 struct rsnd_dai_stream *io)
700 struct rsnd_dai *rdai = rsnd_io_to_rdai(io);
701 struct rsnd_priv *priv = rsnd_mod_to_priv(mod);
703 if (!__rsnd_ssi_is_pin_sharing(mod))
706 if (!rsnd_rdai_is_clk_master(rdai))
709 switch (rsnd_mod_id(mod)) {
712 rsnd_dai_connect(rsnd_ssi_mod_get(priv, 0), io, RSND_MOD_SSIP);
715 rsnd_dai_connect(rsnd_ssi_mod_get(priv, 3), io, RSND_MOD_SSIP);
718 rsnd_dai_connect(rsnd_ssi_mod_get(priv, 7), io, RSND_MOD_SSIP);
723 static int rsnd_ssi_pcm_new(struct rsnd_mod *mod,
724 struct rsnd_dai_stream *io,
725 struct snd_soc_pcm_runtime *rtd)
728 * rsnd_rdai_is_clk_master() will be enabled after set_fmt,
729 * and, pcm_new will be called after it.
730 * This function reuse pcm_new at this point.
732 rsnd_ssi_parent_attach(mod, io);
737 static int rsnd_ssi_common_probe(struct rsnd_mod *mod,
738 struct rsnd_dai_stream *io,
739 struct rsnd_priv *priv)
741 struct device *dev = rsnd_priv_to_dev(priv);
742 struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
746 * SSIP/SSIU/IRQ are not needed on
749 if (rsnd_ssi_is_multi_slave(mod, io))
753 * It can't judge ssi parent at this point
754 * see rsnd_ssi_pcm_new()
757 ret = rsnd_ssiu_attach(io, mod);
762 * SSI might be called again as PIO fallback
763 * It is easy to manual handling for IRQ request/free
765 ret = request_irq(ssi->irq,
773 static int rsnd_ssi_pointer(struct rsnd_mod *mod,
774 struct rsnd_dai_stream *io,
775 snd_pcm_uframes_t *pointer)
777 struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
778 struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io);
780 *pointer = bytes_to_frames(runtime, ssi->byte_pos);
785 static struct rsnd_mod_ops rsnd_ssi_pio_ops = {
787 .probe = rsnd_ssi_common_probe,
788 .init = rsnd_ssi_init,
789 .quit = rsnd_ssi_quit,
790 .start = rsnd_ssi_start,
791 .stop = rsnd_ssi_stop,
793 .pointer= rsnd_ssi_pointer,
794 .pcm_new = rsnd_ssi_pcm_new,
795 .hw_params = rsnd_ssi_hw_params,
798 static int rsnd_ssi_dma_probe(struct rsnd_mod *mod,
799 struct rsnd_dai_stream *io,
800 struct rsnd_priv *priv)
802 struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
806 * SSIP/SSIU/IRQ/DMA are not needed on
809 if (rsnd_ssi_is_multi_slave(mod, io))
812 ret = rsnd_ssi_common_probe(mod, io, priv);
816 /* SSI probe might be called many times in MUX multi path */
817 ret = rsnd_dma_attach(io, mod, &ssi->dma);
822 static int rsnd_ssi_dma_remove(struct rsnd_mod *mod,
823 struct rsnd_dai_stream *io,
824 struct rsnd_priv *priv)
826 struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
827 struct rsnd_mod *ssi_parent_mod = rsnd_io_to_mod_ssip(io);
829 /* Do nothing for SSI parent mod */
830 if (ssi_parent_mod == mod)
833 /* PIO will request IRQ again */
834 free_irq(ssi->irq, mod);
839 static int rsnd_ssi_fallback(struct rsnd_mod *mod,
840 struct rsnd_dai_stream *io,
841 struct rsnd_priv *priv)
843 struct device *dev = rsnd_priv_to_dev(priv);
848 * SSI .probe might be called again.
850 * rsnd_rdai_continuance_probe()
852 mod->ops = &rsnd_ssi_pio_ops;
854 dev_info(dev, "%s[%d] fallback to PIO mode\n",
855 rsnd_mod_name(mod), rsnd_mod_id(mod));
860 static struct dma_chan *rsnd_ssi_dma_req(struct rsnd_dai_stream *io,
861 struct rsnd_mod *mod)
863 struct rsnd_priv *priv = rsnd_mod_to_priv(mod);
864 int is_play = rsnd_io_is_play(io);
867 if (rsnd_ssi_use_busif(io))
868 name = is_play ? "rxu" : "txu";
870 name = is_play ? "rx" : "tx";
872 return rsnd_dma_request_channel(rsnd_ssi_of_node(priv),
876 static struct rsnd_mod_ops rsnd_ssi_dma_ops = {
878 .dma_req = rsnd_ssi_dma_req,
879 .probe = rsnd_ssi_dma_probe,
880 .remove = rsnd_ssi_dma_remove,
881 .init = rsnd_ssi_init,
882 .quit = rsnd_ssi_quit,
883 .start = rsnd_ssi_start,
884 .stop = rsnd_ssi_stop,
886 .pcm_new = rsnd_ssi_pcm_new,
887 .fallback = rsnd_ssi_fallback,
888 .hw_params = rsnd_ssi_hw_params,
891 int rsnd_ssi_is_dma_mode(struct rsnd_mod *mod)
893 return mod->ops == &rsnd_ssi_dma_ops;
900 static void rsnd_ssi_connect(struct rsnd_mod *mod,
901 struct rsnd_dai_stream *io)
903 struct rsnd_dai *rdai = rsnd_io_to_rdai(io);
904 enum rsnd_mod_type types[] = {
910 enum rsnd_mod_type type;
913 /* try SSI -> SSIM1 -> SSIM2 -> SSIM3 */
914 for (i = 0; i < ARRAY_SIZE(types); i++) {
916 if (!rsnd_io_to_mod(io, type)) {
917 rsnd_dai_connect(mod, io, type);
918 rsnd_rdai_channels_set(rdai, (i + 1) * 2);
919 rsnd_rdai_ssi_lane_set(rdai, (i + 1));
925 void rsnd_parse_connect_ssi(struct rsnd_dai *rdai,
926 struct device_node *playback,
927 struct device_node *capture)
929 struct rsnd_priv *priv = rsnd_rdai_to_priv(rdai);
930 struct device_node *node;
931 struct device_node *np;
932 struct rsnd_mod *mod;
935 node = rsnd_ssi_of_node(priv);
940 for_each_child_of_node(node, np) {
941 mod = rsnd_ssi_mod_get(priv, i);
943 rsnd_ssi_connect(mod, &rdai->playback);
945 rsnd_ssi_connect(mod, &rdai->capture);
952 static void __rsnd_ssi_parse_hdmi_connection(struct rsnd_priv *priv,
953 struct rsnd_dai_stream *io,
954 struct device_node *remote_ep)
956 struct device *dev = rsnd_priv_to_dev(priv);
957 struct rsnd_mod *mod = rsnd_io_to_mod_ssi(io);
958 struct rsnd_ssi *ssi;
963 ssi = rsnd_mod_to_ssi(mod);
965 if (strstr(remote_ep->full_name, "hdmi0")) {
966 ssi->flags |= RSND_SSI_HDMI0;
967 dev_dbg(dev, "%s[%d] connected to HDMI0\n",
968 rsnd_mod_name(mod), rsnd_mod_id(mod));
971 if (strstr(remote_ep->full_name, "hdmi1")) {
972 ssi->flags |= RSND_SSI_HDMI1;
973 dev_dbg(dev, "%s[%d] connected to HDMI1\n",
974 rsnd_mod_name(mod), rsnd_mod_id(mod));
978 void rsnd_ssi_parse_hdmi_connection(struct rsnd_priv *priv,
979 struct device_node *endpoint,
982 struct rsnd_dai *rdai = rsnd_rdai_get(priv, dai_i);
983 struct device_node *remote_ep;
985 remote_ep = of_graph_get_remote_endpoint(endpoint);
989 __rsnd_ssi_parse_hdmi_connection(priv, &rdai->playback, remote_ep);
990 __rsnd_ssi_parse_hdmi_connection(priv, &rdai->capture, remote_ep);
993 struct rsnd_mod *rsnd_ssi_mod_get(struct rsnd_priv *priv, int id)
995 if (WARN_ON(id < 0 || id >= rsnd_ssi_nr(priv)))
998 return rsnd_mod_get(rsnd_ssi_get(priv, id));
1001 int __rsnd_ssi_is_pin_sharing(struct rsnd_mod *mod)
1003 struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
1005 return !!(rsnd_ssi_mode_flags(ssi) & RSND_SSI_CLK_PIN_SHARE);
1008 static u32 *rsnd_ssi_get_status(struct rsnd_dai_stream *io,
1009 struct rsnd_mod *mod,
1010 enum rsnd_mod_type type)
1013 * SSIP (= SSI parent) needs to be special, otherwise,
1014 * 2nd SSI might doesn't start. see also rsnd_mod_call()
1016 * We can't include parent SSI status on SSI, because we don't know
1017 * how many SSI requests parent SSI. Thus, it is localed on "io" now.
1020 * Capture : SSI1 (needs SSI0)
1022 * 1) start Capture -> SSI0/SSI1 are started.
1023 * 2) start Playback -> SSI0 doesn't work, because it is already
1024 * marked as "started" on 1)
1026 * OTOH, using each mod's status is good for MUX case.
1027 * It doesn't need to start in 2nd start
1029 * IO-0: SRC0 -> CTU1 -+-> MUX -> DVC -> SSIU -> SSI0
1031 * IO-1: SRC1 -> CTU2 -+
1033 * 1) start IO-0 -> start SSI0
1034 * 2) start IO-1 -> SSI0 doesn't need to start, because it is
1035 * already started on 1)
1037 if (type == RSND_MOD_SSIP)
1038 return &io->parent_ssi_status;
1040 return rsnd_mod_get_status(io, mod, type);
1043 int rsnd_ssi_probe(struct rsnd_priv *priv)
1045 struct device_node *node;
1046 struct device_node *np;
1047 struct device *dev = rsnd_priv_to_dev(priv);
1048 struct rsnd_mod_ops *ops;
1050 struct rsnd_ssi *ssi;
1051 char name[RSND_SSI_NAME_SIZE];
1054 node = rsnd_ssi_of_node(priv);
1058 nr = of_get_child_count(node);
1061 goto rsnd_ssi_probe_done;
1064 ssi = devm_kzalloc(dev, sizeof(*ssi) * nr, GFP_KERNEL);
1067 goto rsnd_ssi_probe_done;
1074 for_each_child_of_node(node, np) {
1075 ssi = rsnd_ssi_get(priv, i);
1077 snprintf(name, RSND_SSI_NAME_SIZE, "%s.%d",
1080 clk = devm_clk_get(dev, name);
1084 goto rsnd_ssi_probe_done;
1087 if (of_get_property(np, "shared-pin", NULL))
1088 ssi->flags |= RSND_SSI_CLK_PIN_SHARE;
1090 if (of_get_property(np, "no-busif", NULL))
1091 ssi->flags |= RSND_SSI_NO_BUSIF;
1093 ssi->irq = irq_of_parse_and_map(np, 0);
1097 goto rsnd_ssi_probe_done;
1100 if (of_property_read_bool(np, "pio-transfer"))
1101 ops = &rsnd_ssi_pio_ops;
1103 ops = &rsnd_ssi_dma_ops;
1105 ret = rsnd_mod_init(priv, rsnd_mod_get(ssi), ops, clk,
1106 rsnd_ssi_get_status, RSND_MOD_SSI, i);
1109 goto rsnd_ssi_probe_done;
1117 rsnd_ssi_probe_done:
1123 void rsnd_ssi_remove(struct rsnd_priv *priv)
1125 struct rsnd_ssi *ssi;
1128 for_each_rsnd_ssi(ssi, priv, i) {
1129 rsnd_mod_quit(rsnd_mod_get(ssi));