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_nr(priv) ((priv)->ssi_nr)
103 #define rsnd_mod_to_ssi(_mod) container_of((_mod), struct rsnd_ssi, mod)
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_flags_has(ssi, RSND_SSI_HDMI0))
117 return RSND_SSI_HDMI_PORT0;
119 if (rsnd_flags_has(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_flags_has(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);
200 mods = rsnd_ssi_multi_slaves_runtime(io) |
201 1 << rsnd_mod_id(ssi_mod);
204 mods |= 1 << rsnd_mod_id(ssi_parent_mod);
209 u32 rsnd_ssi_multi_slaves_runtime(struct rsnd_dai_stream *io)
211 if (rsnd_runtime_is_ssi_multi(io))
212 return rsnd_ssi_multi_slaves(io);
217 unsigned int rsnd_ssi_clk_query(struct rsnd_priv *priv,
218 int param1, int param2, int *idx)
220 int ssi_clk_mul_table[] = {
221 1, 2, 4, 8, 16, 6, 12,
224 unsigned int main_rate;
226 for (j = 0; j < ARRAY_SIZE(ssi_clk_mul_table); j++) {
229 * It will set SSIWSR.CONT here, but SSICR.CKDV = 000
230 * with it is not allowed. (SSIWSR.WS_MODE with
231 * SSICR.CKDV = 000 is not allowed either).
232 * Skip it. See SSICR.CKDV
238 * this driver is assuming that
239 * system word is 32bit x chan
240 * see rsnd_ssi_init()
242 main_rate = 32 * param1 * param2 * ssi_clk_mul_table[j];
244 ret = rsnd_adg_clk_query(priv, main_rate);
257 static int rsnd_ssi_master_clk_start(struct rsnd_mod *mod,
258 struct rsnd_dai_stream *io)
260 struct rsnd_priv *priv = rsnd_io_to_priv(io);
261 struct device *dev = rsnd_priv_to_dev(priv);
262 struct rsnd_dai *rdai = rsnd_io_to_rdai(io);
263 struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
264 int chan = rsnd_runtime_channel_for_ssi(io);
266 unsigned int main_rate;
267 unsigned int rate = rsnd_io_is_play(io) ?
268 rsnd_src_get_out_rate(priv, io) :
269 rsnd_src_get_in_rate(priv, io);
271 if (!rsnd_rdai_is_clk_master(rdai))
274 if (!rsnd_ssi_can_output_clk(mod))
277 if (rsnd_ssi_is_multi_slave(mod, io))
280 if (ssi->usrcnt > 1) {
281 if (ssi->rate != rate) {
282 dev_err(dev, "SSI parent/child should use same rate\n");
289 main_rate = rsnd_ssi_clk_query(priv, rate, chan, &idx);
291 dev_err(dev, "unsupported clock rate\n");
295 ret = rsnd_adg_ssi_clk_try_start(mod, main_rate);
300 * SSI clock will be output contiguously
302 * This means, rsnd_ssi_master_clk_start()
303 * and rsnd_ssi_register_setup() are necessary
306 * SSICR : FORCE, SCKD, SWSD
309 ssi->cr_clk = FORCE | SWL_32 | SCKD | SWSD | CKDV(idx);
313 dev_dbg(dev, "%s[%d] outputs %u Hz\n",
315 rsnd_mod_id(mod), rate);
320 static void rsnd_ssi_master_clk_stop(struct rsnd_mod *mod,
321 struct rsnd_dai_stream *io)
323 struct rsnd_dai *rdai = rsnd_io_to_rdai(io);
324 struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
326 if (!rsnd_rdai_is_clk_master(rdai))
329 if (!rsnd_ssi_can_output_clk(mod))
338 rsnd_adg_ssi_clk_stop(mod);
341 static void rsnd_ssi_config_init(struct rsnd_mod *mod,
342 struct rsnd_dai_stream *io)
344 struct rsnd_dai *rdai = rsnd_io_to_rdai(io);
345 struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io);
346 struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
352 if (rsnd_ssi_is_parent(mod, io))
355 is_tdm = rsnd_runtime_is_ssi_tdm(io);
358 * always use 32bit system word.
359 * see also rsnd_ssi_master_clk_enable()
361 cr_own = FORCE | SWL_32;
363 if (rdai->bit_clk_inv)
365 if (rdai->frm_clk_inv ^ is_tdm)
367 if (rdai->data_alignment)
371 if (rsnd_io_is_play(io))
374 switch (snd_pcm_format_width(runtime->format)) {
383 if (rsnd_ssi_is_dma_mode(mod)) {
384 cr_mode = UIEN | OIEN | /* over/under run */
385 DMEN; /* DMA : enable DMA */
387 cr_mode = DIEN; /* PIO : enable Data interrupt */
393 * rsnd_ssiu_init_gen2()
401 ssi->cr_own = cr_own;
402 ssi->cr_mode = cr_mode;
406 static void rsnd_ssi_register_setup(struct rsnd_mod *mod)
408 struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
410 rsnd_mod_write(mod, SSIWSR, ssi->wsr);
411 rsnd_mod_write(mod, SSICR, ssi->cr_own |
418 * SSI mod common functions
420 static int rsnd_ssi_init(struct rsnd_mod *mod,
421 struct rsnd_dai_stream *io,
422 struct rsnd_priv *priv)
424 struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
427 if (!rsnd_ssi_is_run_mods(mod, io))
432 rsnd_mod_power_on(mod);
434 ret = rsnd_ssi_master_clk_start(mod, io);
438 rsnd_ssi_config_init(mod, io);
440 rsnd_ssi_register_setup(mod);
442 /* clear error status */
443 rsnd_ssi_status_clear(mod);
448 static int rsnd_ssi_quit(struct rsnd_mod *mod,
449 struct rsnd_dai_stream *io,
450 struct rsnd_priv *priv)
452 struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
453 struct device *dev = rsnd_priv_to_dev(priv);
455 if (!rsnd_ssi_is_run_mods(mod, io))
459 dev_err(dev, "%s[%d] usrcnt error\n",
460 rsnd_mod_name(mod), rsnd_mod_id(mod));
464 if (!rsnd_ssi_is_parent(mod, io))
467 rsnd_ssi_master_clk_stop(mod, io);
469 rsnd_mod_power_off(mod);
476 static int rsnd_ssi_hw_params(struct rsnd_mod *mod,
477 struct rsnd_dai_stream *io,
478 struct snd_pcm_substream *substream,
479 struct snd_pcm_hw_params *params)
481 struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
482 int chan = params_channels(params);
485 * snd_pcm_ops::hw_params will be called *before*
486 * snd_soc_dai_ops::trigger. Thus, ssi->usrcnt is 0
492 * It will happen if SSI has parent/child connection.
493 * it is error if child <-> parent SSI uses
494 * different channels.
496 if (ssi->chan != chan)
505 static int rsnd_ssi_start(struct rsnd_mod *mod,
506 struct rsnd_dai_stream *io,
507 struct rsnd_priv *priv)
509 struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
511 if (!rsnd_ssi_is_run_mods(mod, io))
515 * EN will be set via SSIU :: SSI_CONTROL
516 * if Multi channel mode
518 if (rsnd_ssi_multi_slaves_runtime(io))
522 * EN is for data output.
523 * SSI parent EN is not needed.
525 if (rsnd_ssi_is_parent(mod, io))
530 rsnd_mod_write(mod, SSICR, ssi->cr_own |
538 static int rsnd_ssi_stop(struct rsnd_mod *mod,
539 struct rsnd_dai_stream *io,
540 struct rsnd_priv *priv)
542 struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
545 if (!rsnd_ssi_is_run_mods(mod, io))
548 if (rsnd_ssi_is_parent(mod, io))
556 * Playback: Wait all data was sent
557 * Capture: It might not receave data. Do nothing
559 if (rsnd_io_is_play(io)) {
560 rsnd_mod_write(mod, SSICR, cr | EN);
561 rsnd_ssi_status_check(mod, DIRQ);
566 * and, wait idle state
568 rsnd_mod_write(mod, SSICR, cr); /* disabled all */
569 rsnd_ssi_status_check(mod, IIRQ);
576 static int rsnd_ssi_irq(struct rsnd_mod *mod,
577 struct rsnd_dai_stream *io,
578 struct rsnd_priv *priv,
583 if (rsnd_is_gen1(priv))
586 if (rsnd_ssi_is_parent(mod, io))
589 if (!rsnd_ssi_is_run_mods(mod, io))
593 val = rsnd_ssi_is_dma_mode(mod) ? 0x0e000000 : 0x0f000000;
595 rsnd_mod_write(mod, SSI_INT_ENABLE, val);
600 static bool rsnd_ssi_pio_interrupt(struct rsnd_mod *mod,
601 struct rsnd_dai_stream *io);
602 static void __rsnd_ssi_interrupt(struct rsnd_mod *mod,
603 struct rsnd_dai_stream *io)
605 struct rsnd_priv *priv = rsnd_mod_to_priv(mod);
606 int is_dma = rsnd_ssi_is_dma_mode(mod);
608 bool elapsed = false;
611 spin_lock(&priv->lock);
613 /* ignore all cases if not working */
614 if (!rsnd_io_is_working(io))
615 goto rsnd_ssi_interrupt_out;
617 status = rsnd_ssi_status_get(mod);
620 if (!is_dma && (status & DIRQ))
621 elapsed = rsnd_ssi_pio_interrupt(mod, io);
624 if (is_dma && (status & (UIRQ | OIRQ)))
627 rsnd_ssi_status_clear(mod);
628 rsnd_ssi_interrupt_out:
629 spin_unlock(&priv->lock);
632 rsnd_dai_period_elapsed(io);
635 snd_pcm_stop_xrun(io->substream);
639 static irqreturn_t rsnd_ssi_interrupt(int irq, void *data)
641 struct rsnd_mod *mod = data;
643 rsnd_mod_interrupt(mod, __rsnd_ssi_interrupt);
651 static void rsnd_ssi_parent_attach(struct rsnd_mod *mod,
652 struct rsnd_dai_stream *io)
654 struct rsnd_dai *rdai = rsnd_io_to_rdai(io);
655 struct rsnd_priv *priv = rsnd_mod_to_priv(mod);
657 if (!__rsnd_ssi_is_pin_sharing(mod))
660 if (!rsnd_rdai_is_clk_master(rdai))
663 switch (rsnd_mod_id(mod)) {
666 rsnd_dai_connect(rsnd_ssi_mod_get(priv, 0), io, RSND_MOD_SSIP);
669 rsnd_dai_connect(rsnd_ssi_mod_get(priv, 3), io, RSND_MOD_SSIP);
672 rsnd_dai_connect(rsnd_ssi_mod_get(priv, 7), io, RSND_MOD_SSIP);
677 static int rsnd_ssi_pcm_new(struct rsnd_mod *mod,
678 struct rsnd_dai_stream *io,
679 struct snd_soc_pcm_runtime *rtd)
682 * rsnd_rdai_is_clk_master() will be enabled after set_fmt,
683 * and, pcm_new will be called after it.
684 * This function reuse pcm_new at this point.
686 rsnd_ssi_parent_attach(mod, io);
691 static int rsnd_ssi_common_probe(struct rsnd_mod *mod,
692 struct rsnd_dai_stream *io,
693 struct rsnd_priv *priv)
695 struct device *dev = rsnd_priv_to_dev(priv);
696 struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
700 * SSIP/SSIU/IRQ are not needed on
703 if (rsnd_ssi_is_multi_slave(mod, io))
707 * It can't judge ssi parent at this point
708 * see rsnd_ssi_pcm_new()
711 ret = rsnd_ssiu_attach(io, mod);
716 * SSI might be called again as PIO fallback
717 * It is easy to manual handling for IRQ request/free
719 * OTOH, this function might be called many times if platform is
720 * using MIX. It needs xxx_attach() many times on xxx_probe().
721 * Because of it, we can't control .probe/.remove calling count by
723 * But it don't need to call request_irq() many times.
724 * Let's control it by RSND_SSI_PROBED flag.
726 if (!rsnd_flags_has(ssi, RSND_SSI_PROBED)) {
727 ret = request_irq(ssi->irq,
732 rsnd_flags_set(ssi, RSND_SSI_PROBED);
738 static int rsnd_ssi_common_remove(struct rsnd_mod *mod,
739 struct rsnd_dai_stream *io,
740 struct rsnd_priv *priv)
742 struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
743 struct rsnd_mod *pure_ssi_mod = rsnd_io_to_mod_ssi(io);
745 /* Do nothing if non SSI (= SSI parent, multi SSI) mod */
746 if (pure_ssi_mod != mod)
749 /* PIO will request IRQ again */
750 if (rsnd_flags_has(ssi, RSND_SSI_PROBED)) {
751 free_irq(ssi->irq, mod);
753 rsnd_flags_del(ssi, RSND_SSI_PROBED);
762 static bool rsnd_ssi_pio_interrupt(struct rsnd_mod *mod,
763 struct rsnd_dai_stream *io)
765 struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io);
766 struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
767 u32 *buf = (u32 *)(runtime->dma_area + ssi->byte_pos);
770 bool elapsed = false;
772 if (snd_pcm_format_width(runtime->format) == 24)
776 * 8/16/32 data can be assesse to TDR/RDR register
777 * directly as 32bit data
778 * see rsnd_ssi_init()
780 if (rsnd_io_is_play(io))
781 rsnd_mod_write(mod, SSITDR, (*buf) << shift);
783 *buf = (rsnd_mod_read(mod, SSIRDR) >> shift);
785 byte_pos = ssi->byte_pos + sizeof(*buf);
787 if (byte_pos >= ssi->next_period_byte) {
788 int period_pos = byte_pos / ssi->byte_per_period;
790 if (period_pos >= runtime->periods) {
795 ssi->next_period_byte = (period_pos + 1) * ssi->byte_per_period;
800 WRITE_ONCE(ssi->byte_pos, byte_pos);
805 static int rsnd_ssi_pio_init(struct rsnd_mod *mod,
806 struct rsnd_dai_stream *io,
807 struct rsnd_priv *priv)
809 struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io);
810 struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
812 if (!rsnd_ssi_is_parent(mod, io)) {
814 ssi->byte_per_period = runtime->period_size *
816 samples_to_bytes(runtime, 1);
817 ssi->next_period_byte = ssi->byte_per_period;
820 return rsnd_ssi_init(mod, io, priv);
823 static int rsnd_ssi_pio_pointer(struct rsnd_mod *mod,
824 struct rsnd_dai_stream *io,
825 snd_pcm_uframes_t *pointer)
827 struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
828 struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io);
830 *pointer = bytes_to_frames(runtime, READ_ONCE(ssi->byte_pos));
835 static struct rsnd_mod_ops rsnd_ssi_pio_ops = {
837 .probe = rsnd_ssi_common_probe,
838 .remove = rsnd_ssi_common_remove,
839 .init = rsnd_ssi_pio_init,
840 .quit = rsnd_ssi_quit,
841 .start = rsnd_ssi_start,
842 .stop = rsnd_ssi_stop,
844 .pointer = rsnd_ssi_pio_pointer,
845 .pcm_new = rsnd_ssi_pcm_new,
846 .hw_params = rsnd_ssi_hw_params,
849 static int rsnd_ssi_dma_probe(struct rsnd_mod *mod,
850 struct rsnd_dai_stream *io,
851 struct rsnd_priv *priv)
853 struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
857 * SSIP/SSIU/IRQ/DMA are not needed on
860 if (rsnd_ssi_is_multi_slave(mod, io))
863 ret = rsnd_ssi_common_probe(mod, io, priv);
867 /* SSI probe might be called many times in MUX multi path */
868 ret = rsnd_dma_attach(io, mod, &ssi->dma);
873 static int rsnd_ssi_fallback(struct rsnd_mod *mod,
874 struct rsnd_dai_stream *io,
875 struct rsnd_priv *priv)
877 struct device *dev = rsnd_priv_to_dev(priv);
882 * SSI .probe might be called again.
884 * rsnd_rdai_continuance_probe()
886 mod->ops = &rsnd_ssi_pio_ops;
888 dev_info(dev, "%s[%d] fallback to PIO mode\n",
889 rsnd_mod_name(mod), rsnd_mod_id(mod));
894 static struct dma_chan *rsnd_ssi_dma_req(struct rsnd_dai_stream *io,
895 struct rsnd_mod *mod)
897 struct rsnd_priv *priv = rsnd_mod_to_priv(mod);
898 int is_play = rsnd_io_is_play(io);
901 if (rsnd_ssi_use_busif(io))
902 name = is_play ? "rxu" : "txu";
904 name = is_play ? "rx" : "tx";
906 return rsnd_dma_request_channel(rsnd_ssi_of_node(priv),
910 static struct rsnd_mod_ops rsnd_ssi_dma_ops = {
912 .dma_req = rsnd_ssi_dma_req,
913 .probe = rsnd_ssi_dma_probe,
914 .remove = rsnd_ssi_common_remove,
915 .init = rsnd_ssi_init,
916 .quit = rsnd_ssi_quit,
917 .start = rsnd_ssi_start,
918 .stop = rsnd_ssi_stop,
920 .pcm_new = rsnd_ssi_pcm_new,
921 .fallback = rsnd_ssi_fallback,
922 .hw_params = rsnd_ssi_hw_params,
925 int rsnd_ssi_is_dma_mode(struct rsnd_mod *mod)
927 return mod->ops == &rsnd_ssi_dma_ops;
934 static void rsnd_ssi_connect(struct rsnd_mod *mod,
935 struct rsnd_dai_stream *io)
937 struct rsnd_dai *rdai = rsnd_io_to_rdai(io);
938 enum rsnd_mod_type types[] = {
944 enum rsnd_mod_type type;
947 /* try SSI -> SSIM1 -> SSIM2 -> SSIM3 */
948 for (i = 0; i < ARRAY_SIZE(types); i++) {
950 if (!rsnd_io_to_mod(io, type)) {
951 rsnd_dai_connect(mod, io, type);
952 rsnd_rdai_channels_set(rdai, (i + 1) * 2);
953 rsnd_rdai_ssi_lane_set(rdai, (i + 1));
959 void rsnd_parse_connect_ssi(struct rsnd_dai *rdai,
960 struct device_node *playback,
961 struct device_node *capture)
963 struct rsnd_priv *priv = rsnd_rdai_to_priv(rdai);
964 struct device_node *node;
965 struct device_node *np;
966 struct rsnd_mod *mod;
969 node = rsnd_ssi_of_node(priv);
974 for_each_child_of_node(node, np) {
975 mod = rsnd_ssi_mod_get(priv, i);
977 rsnd_ssi_connect(mod, &rdai->playback);
979 rsnd_ssi_connect(mod, &rdai->capture);
986 static void __rsnd_ssi_parse_hdmi_connection(struct rsnd_priv *priv,
987 struct rsnd_dai_stream *io,
988 struct device_node *remote_ep)
990 struct device *dev = rsnd_priv_to_dev(priv);
991 struct rsnd_mod *mod = rsnd_io_to_mod_ssi(io);
992 struct rsnd_ssi *ssi;
997 ssi = rsnd_mod_to_ssi(mod);
999 if (strstr(remote_ep->full_name, "hdmi0")) {
1000 rsnd_flags_set(ssi, RSND_SSI_HDMI0);
1001 dev_dbg(dev, "%s[%d] connected to HDMI0\n",
1002 rsnd_mod_name(mod), rsnd_mod_id(mod));
1005 if (strstr(remote_ep->full_name, "hdmi1")) {
1006 rsnd_flags_set(ssi, RSND_SSI_HDMI1);
1007 dev_dbg(dev, "%s[%d] connected to HDMI1\n",
1008 rsnd_mod_name(mod), rsnd_mod_id(mod));
1012 void rsnd_ssi_parse_hdmi_connection(struct rsnd_priv *priv,
1013 struct device_node *endpoint,
1016 struct rsnd_dai *rdai = rsnd_rdai_get(priv, dai_i);
1017 struct device_node *remote_ep;
1019 remote_ep = of_graph_get_remote_endpoint(endpoint);
1023 __rsnd_ssi_parse_hdmi_connection(priv, &rdai->playback, remote_ep);
1024 __rsnd_ssi_parse_hdmi_connection(priv, &rdai->capture, remote_ep);
1027 struct rsnd_mod *rsnd_ssi_mod_get(struct rsnd_priv *priv, int id)
1029 if (WARN_ON(id < 0 || id >= rsnd_ssi_nr(priv)))
1032 return rsnd_mod_get(rsnd_ssi_get(priv, id));
1035 int __rsnd_ssi_is_pin_sharing(struct rsnd_mod *mod)
1037 struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
1039 return !!(rsnd_flags_has(ssi, RSND_SSI_CLK_PIN_SHARE));
1042 static u32 *rsnd_ssi_get_status(struct rsnd_dai_stream *io,
1043 struct rsnd_mod *mod,
1044 enum rsnd_mod_type type)
1047 * SSIP (= SSI parent) needs to be special, otherwise,
1048 * 2nd SSI might doesn't start. see also rsnd_mod_call()
1050 * We can't include parent SSI status on SSI, because we don't know
1051 * how many SSI requests parent SSI. Thus, it is localed on "io" now.
1054 * Capture : SSI1 (needs SSI0)
1056 * 1) start Capture -> SSI0/SSI1 are started.
1057 * 2) start Playback -> SSI0 doesn't work, because it is already
1058 * marked as "started" on 1)
1060 * OTOH, using each mod's status is good for MUX case.
1061 * It doesn't need to start in 2nd start
1063 * IO-0: SRC0 -> CTU1 -+-> MUX -> DVC -> SSIU -> SSI0
1065 * IO-1: SRC1 -> CTU2 -+
1067 * 1) start IO-0 -> start SSI0
1068 * 2) start IO-1 -> SSI0 doesn't need to start, because it is
1069 * already started on 1)
1071 if (type == RSND_MOD_SSIP)
1072 return &io->parent_ssi_status;
1074 return rsnd_mod_get_status(io, mod, type);
1077 int rsnd_ssi_probe(struct rsnd_priv *priv)
1079 struct device_node *node;
1080 struct device_node *np;
1081 struct device *dev = rsnd_priv_to_dev(priv);
1082 struct rsnd_mod_ops *ops;
1084 struct rsnd_ssi *ssi;
1085 char name[RSND_SSI_NAME_SIZE];
1088 node = rsnd_ssi_of_node(priv);
1092 nr = of_get_child_count(node);
1095 goto rsnd_ssi_probe_done;
1098 ssi = devm_kzalloc(dev, sizeof(*ssi) * nr, GFP_KERNEL);
1101 goto rsnd_ssi_probe_done;
1108 for_each_child_of_node(node, np) {
1109 if (!of_device_is_available(np))
1112 ssi = rsnd_ssi_get(priv, i);
1114 snprintf(name, RSND_SSI_NAME_SIZE, "%s.%d",
1117 clk = devm_clk_get(dev, name);
1121 goto rsnd_ssi_probe_done;
1124 if (of_get_property(np, "shared-pin", NULL))
1125 rsnd_flags_set(ssi, RSND_SSI_CLK_PIN_SHARE);
1127 if (of_get_property(np, "no-busif", NULL))
1128 rsnd_flags_set(ssi, RSND_SSI_NO_BUSIF);
1130 ssi->irq = irq_of_parse_and_map(np, 0);
1134 goto rsnd_ssi_probe_done;
1137 if (of_property_read_bool(np, "pio-transfer"))
1138 ops = &rsnd_ssi_pio_ops;
1140 ops = &rsnd_ssi_dma_ops;
1142 ret = rsnd_mod_init(priv, rsnd_mod_get(ssi), ops, clk,
1143 rsnd_ssi_get_status, RSND_MOD_SSI, i);
1146 goto rsnd_ssi_probe_done;
1154 rsnd_ssi_probe_done:
1160 void rsnd_ssi_remove(struct rsnd_priv *priv)
1162 struct rsnd_ssi *ssi;
1165 for_each_rsnd_ssi(ssi, priv, i) {
1166 rsnd_mod_quit(rsnd_mod_get(ssi));