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.
16 * you can enable below define if you don't need
17 * SSI interrupt status debug message when debugging
18 * see rsnd_dbg_irq_status()
20 * #define RSND_DEBUG_NO_IRQ_STATUS 1
23 #include <sound/simple_card_utils.h>
24 #include <linux/delay.h>
26 #define RSND_SSI_NAME_SIZE 16
31 #define FORCE (1 << 31) /* Fixed */
32 #define DMEN (1 << 28) /* DMA Enable */
33 #define UIEN (1 << 27) /* Underflow Interrupt Enable */
34 #define OIEN (1 << 26) /* Overflow Interrupt Enable */
35 #define IIEN (1 << 25) /* Idle Mode Interrupt Enable */
36 #define DIEN (1 << 24) /* Data Interrupt Enable */
37 #define CHNL_4 (1 << 22) /* Channels */
38 #define CHNL_6 (2 << 22) /* Channels */
39 #define CHNL_8 (3 << 22) /* Channels */
40 #define DWL_8 (0 << 19) /* Data Word Length */
41 #define DWL_16 (1 << 19) /* Data Word Length */
42 #define DWL_18 (2 << 19) /* Data Word Length */
43 #define DWL_20 (3 << 19) /* Data Word Length */
44 #define DWL_22 (4 << 19) /* Data Word Length */
45 #define DWL_24 (5 << 19) /* Data Word Length */
46 #define DWL_32 (6 << 19) /* Data Word Length */
48 #define SWL_32 (3 << 16) /* R/W System Word Length */
49 #define SCKD (1 << 15) /* Serial Bit Clock Direction */
50 #define SWSD (1 << 14) /* Serial WS Direction */
51 #define SCKP (1 << 13) /* Serial Bit Clock Polarity */
52 #define SWSP (1 << 12) /* Serial WS Polarity */
53 #define SDTA (1 << 10) /* Serial Data Alignment */
54 #define PDTA (1 << 9) /* Parallel Data Alignment */
55 #define DEL (1 << 8) /* Serial Data Delay */
56 #define CKDV(v) (v << 4) /* Serial Clock Division Ratio */
57 #define TRMD (1 << 1) /* Transmit/Receive Mode Select */
58 #define EN (1 << 0) /* SSI Module Enable */
63 #define UIRQ (1 << 27) /* Underflow Error Interrupt Status */
64 #define OIRQ (1 << 26) /* Overflow Error Interrupt Status */
65 #define IIRQ (1 << 25) /* Idle Mode Interrupt Status */
66 #define DIRQ (1 << 24) /* Data Interrupt Status Flag */
71 #define CONT (1 << 8) /* WS Continue Function */
72 #define WS_MODE (1 << 0) /* WS Mode */
74 #define SSI_NAME "ssi"
98 #define RSND_SSI_CLK_PIN_SHARE (1 << 0)
99 #define RSND_SSI_NO_BUSIF (1 << 1) /* SSI+DMA without BUSIF */
100 #define RSND_SSI_HDMI0 (1 << 2) /* for HDMI0 */
101 #define RSND_SSI_HDMI1 (1 << 3) /* for HDMI1 */
102 #define RSND_SSI_PROBED (1 << 4)
104 #define for_each_rsnd_ssi(pos, priv, i) \
106 (i < rsnd_ssi_nr(priv)) && \
107 ((pos) = ((struct rsnd_ssi *)(priv)->ssi + i)); \
110 #define rsnd_ssi_get(priv, id) ((struct rsnd_ssi *)(priv->ssi) + id)
111 #define rsnd_ssi_nr(priv) ((priv)->ssi_nr)
112 #define rsnd_mod_to_ssi(_mod) container_of((_mod), struct rsnd_ssi, mod)
113 #define rsnd_ssi_is_parent(ssi, io) ((ssi) == rsnd_io_to_mod_ssip(io))
114 #define rsnd_ssi_is_multi_slave(mod, io) \
115 (rsnd_ssi_multi_slaves(io) & (1 << rsnd_mod_id(mod)))
116 #define rsnd_ssi_is_run_mods(mod, io) \
117 (rsnd_ssi_run_mods(io) & (1 << rsnd_mod_id(mod)))
118 #define rsnd_ssi_can_output_clk(mod) (!__rsnd_ssi_is_pin_sharing(mod))
120 int rsnd_ssi_hdmi_port(struct rsnd_dai_stream *io)
122 struct rsnd_mod *mod = rsnd_io_to_mod_ssi(io);
123 struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
125 if (rsnd_flags_has(ssi, RSND_SSI_HDMI0))
126 return RSND_SSI_HDMI_PORT0;
128 if (rsnd_flags_has(ssi, RSND_SSI_HDMI1))
129 return RSND_SSI_HDMI_PORT1;
134 int rsnd_ssi_use_busif(struct rsnd_dai_stream *io)
136 struct rsnd_mod *mod = rsnd_io_to_mod_ssi(io);
137 struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
140 if (!rsnd_ssi_is_dma_mode(mod))
143 if (!(rsnd_flags_has(ssi, RSND_SSI_NO_BUSIF)))
145 if (rsnd_io_to_mod_src(io))
151 static void rsnd_ssi_status_clear(struct rsnd_mod *mod)
153 rsnd_mod_write(mod, SSISR, 0);
156 static u32 rsnd_ssi_status_get(struct rsnd_mod *mod)
158 return rsnd_mod_read(mod, SSISR);
161 static void rsnd_ssi_status_check(struct rsnd_mod *mod,
164 struct rsnd_priv *priv = rsnd_mod_to_priv(mod);
165 struct device *dev = rsnd_priv_to_dev(priv);
169 for (i = 0; i < 1024; i++) {
170 status = rsnd_ssi_status_get(mod);
177 dev_warn(dev, "%s[%d] status check failed\n",
178 rsnd_mod_name(mod), rsnd_mod_id(mod));
181 static u32 rsnd_ssi_multi_slaves(struct rsnd_dai_stream *io)
183 struct rsnd_mod *mod;
184 enum rsnd_mod_type types[] = {
192 for (i = 0; i < ARRAY_SIZE(types); i++) {
193 mod = rsnd_io_to_mod(io, types[i]);
197 mask |= 1 << rsnd_mod_id(mod);
203 static u32 rsnd_ssi_run_mods(struct rsnd_dai_stream *io)
205 struct rsnd_mod *ssi_mod = rsnd_io_to_mod_ssi(io);
206 struct rsnd_mod *ssi_parent_mod = rsnd_io_to_mod_ssip(io);
209 mods = rsnd_ssi_multi_slaves_runtime(io) |
210 1 << rsnd_mod_id(ssi_mod);
213 mods |= 1 << rsnd_mod_id(ssi_parent_mod);
218 u32 rsnd_ssi_multi_slaves_runtime(struct rsnd_dai_stream *io)
220 if (rsnd_runtime_is_ssi_multi(io))
221 return rsnd_ssi_multi_slaves(io);
226 unsigned int rsnd_ssi_clk_query(struct rsnd_priv *priv,
227 int param1, int param2, int *idx)
229 int ssi_clk_mul_table[] = {
230 1, 2, 4, 8, 16, 6, 12,
233 unsigned int main_rate;
235 for (j = 0; j < ARRAY_SIZE(ssi_clk_mul_table); j++) {
238 * It will set SSIWSR.CONT here, but SSICR.CKDV = 000
239 * with it is not allowed. (SSIWSR.WS_MODE with
240 * SSICR.CKDV = 000 is not allowed either).
241 * Skip it. See SSICR.CKDV
247 * this driver is assuming that
248 * system word is 32bit x chan
249 * see rsnd_ssi_init()
251 main_rate = 32 * param1 * param2 * ssi_clk_mul_table[j];
253 ret = rsnd_adg_clk_query(priv, main_rate);
266 static int rsnd_ssi_master_clk_start(struct rsnd_mod *mod,
267 struct rsnd_dai_stream *io)
269 struct rsnd_priv *priv = rsnd_io_to_priv(io);
270 struct device *dev = rsnd_priv_to_dev(priv);
271 struct rsnd_dai *rdai = rsnd_io_to_rdai(io);
272 struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
273 int chan = rsnd_runtime_channel_for_ssi(io);
275 unsigned int main_rate;
276 unsigned int rate = rsnd_io_is_play(io) ?
277 rsnd_src_get_out_rate(priv, io) :
278 rsnd_src_get_in_rate(priv, io);
280 if (!rsnd_rdai_is_clk_master(rdai))
283 if (!rsnd_ssi_can_output_clk(mod))
286 if (rsnd_ssi_is_multi_slave(mod, io))
289 if (ssi->usrcnt > 1) {
290 if (ssi->rate != rate) {
291 dev_err(dev, "SSI parent/child should use same rate\n");
298 main_rate = rsnd_ssi_clk_query(priv, rate, chan, &idx);
300 dev_err(dev, "unsupported clock rate\n");
304 ret = rsnd_adg_ssi_clk_try_start(mod, main_rate);
309 * SSI clock will be output contiguously
311 * This means, rsnd_ssi_master_clk_start()
312 * and rsnd_ssi_register_setup() are necessary
315 * SSICR : FORCE, SCKD, SWSD
318 ssi->cr_clk = FORCE | SWL_32 | SCKD | SWSD | CKDV(idx);
322 dev_dbg(dev, "%s[%d] outputs %u Hz\n",
324 rsnd_mod_id(mod), rate);
329 static void rsnd_ssi_master_clk_stop(struct rsnd_mod *mod,
330 struct rsnd_dai_stream *io)
332 struct rsnd_dai *rdai = rsnd_io_to_rdai(io);
333 struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
335 if (!rsnd_rdai_is_clk_master(rdai))
338 if (!rsnd_ssi_can_output_clk(mod))
347 rsnd_adg_ssi_clk_stop(mod);
350 static void rsnd_ssi_config_init(struct rsnd_mod *mod,
351 struct rsnd_dai_stream *io)
353 struct rsnd_dai *rdai = rsnd_io_to_rdai(io);
354 struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io);
355 struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
361 if (rsnd_ssi_is_parent(mod, io))
364 is_tdm = rsnd_runtime_is_ssi_tdm(io);
367 * always use 32bit system word.
368 * see also rsnd_ssi_master_clk_enable()
370 cr_own = FORCE | SWL_32;
372 if (rdai->bit_clk_inv)
374 if (rdai->frm_clk_inv ^ is_tdm)
376 if (rdai->data_alignment)
380 if (rsnd_io_is_play(io))
383 switch (snd_pcm_format_width(runtime->format)) {
392 if (rsnd_ssi_is_dma_mode(mod)) {
393 cr_mode = UIEN | OIEN | /* over/under run */
394 DMEN; /* DMA : enable DMA */
396 cr_mode = DIEN; /* PIO : enable Data interrupt */
402 * rsnd_ssiu_init_gen2()
410 ssi->cr_own = cr_own;
411 ssi->cr_mode = cr_mode;
415 static void rsnd_ssi_register_setup(struct rsnd_mod *mod)
417 struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
419 rsnd_mod_write(mod, SSIWSR, ssi->wsr);
420 rsnd_mod_write(mod, SSICR, ssi->cr_own |
427 * SSI mod common functions
429 static int rsnd_ssi_init(struct rsnd_mod *mod,
430 struct rsnd_dai_stream *io,
431 struct rsnd_priv *priv)
433 struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
436 if (!rsnd_ssi_is_run_mods(mod, io))
441 rsnd_mod_power_on(mod);
443 ret = rsnd_ssi_master_clk_start(mod, io);
447 rsnd_ssi_config_init(mod, io);
449 rsnd_ssi_register_setup(mod);
451 /* clear error status */
452 rsnd_ssi_status_clear(mod);
457 static int rsnd_ssi_quit(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);
462 struct device *dev = rsnd_priv_to_dev(priv);
464 if (!rsnd_ssi_is_run_mods(mod, io))
468 dev_err(dev, "%s[%d] usrcnt error\n",
469 rsnd_mod_name(mod), rsnd_mod_id(mod));
473 if (!rsnd_ssi_is_parent(mod, io))
476 rsnd_ssi_master_clk_stop(mod, io);
478 rsnd_mod_power_off(mod);
485 static int rsnd_ssi_hw_params(struct rsnd_mod *mod,
486 struct rsnd_dai_stream *io,
487 struct snd_pcm_substream *substream,
488 struct snd_pcm_hw_params *params)
490 struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
491 int chan = params_channels(params);
494 * snd_pcm_ops::hw_params will be called *before*
495 * snd_soc_dai_ops::trigger. Thus, ssi->usrcnt is 0
501 * It will happen if SSI has parent/child connection.
502 * it is error if child <-> parent SSI uses
503 * different channels.
505 if (ssi->chan != chan)
514 static int rsnd_ssi_start(struct rsnd_mod *mod,
515 struct rsnd_dai_stream *io,
516 struct rsnd_priv *priv)
518 struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
520 if (!rsnd_ssi_is_run_mods(mod, io))
524 * EN will be set via SSIU :: SSI_CONTROL
525 * if Multi channel mode
527 if (rsnd_ssi_multi_slaves_runtime(io))
531 * EN is for data output.
532 * SSI parent EN is not needed.
534 if (rsnd_ssi_is_parent(mod, io))
539 rsnd_mod_write(mod, SSICR, ssi->cr_own |
547 static int rsnd_ssi_stop(struct rsnd_mod *mod,
548 struct rsnd_dai_stream *io,
549 struct rsnd_priv *priv)
551 struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
554 if (!rsnd_ssi_is_run_mods(mod, io))
557 if (rsnd_ssi_is_parent(mod, io))
565 * Playback: Wait all data was sent
566 * Capture: It might not receave data. Do nothing
568 if (rsnd_io_is_play(io)) {
569 rsnd_mod_write(mod, SSICR, cr | EN);
570 rsnd_ssi_status_check(mod, DIRQ);
575 * and, wait idle state
577 rsnd_mod_write(mod, SSICR, cr); /* disabled all */
578 rsnd_ssi_status_check(mod, IIRQ);
585 static int rsnd_ssi_irq(struct rsnd_mod *mod,
586 struct rsnd_dai_stream *io,
587 struct rsnd_priv *priv,
592 if (rsnd_is_gen1(priv))
595 if (rsnd_ssi_is_parent(mod, io))
598 if (!rsnd_ssi_is_run_mods(mod, io))
602 val = rsnd_ssi_is_dma_mode(mod) ? 0x0e000000 : 0x0f000000;
604 rsnd_mod_write(mod, SSI_INT_ENABLE, val);
609 static bool rsnd_ssi_pio_interrupt(struct rsnd_mod *mod,
610 struct rsnd_dai_stream *io);
611 static void __rsnd_ssi_interrupt(struct rsnd_mod *mod,
612 struct rsnd_dai_stream *io)
614 struct rsnd_priv *priv = rsnd_mod_to_priv(mod);
615 struct device *dev = rsnd_priv_to_dev(priv);
616 int is_dma = rsnd_ssi_is_dma_mode(mod);
618 bool elapsed = false;
621 spin_lock(&priv->lock);
623 /* ignore all cases if not working */
624 if (!rsnd_io_is_working(io))
625 goto rsnd_ssi_interrupt_out;
627 status = rsnd_ssi_status_get(mod);
630 if (!is_dma && (status & DIRQ))
631 elapsed = rsnd_ssi_pio_interrupt(mod, io);
634 if (is_dma && (status & (UIRQ | OIRQ))) {
635 rsnd_dbg_irq_status(dev, "%s[%d] err status : 0x%08x\n",
636 rsnd_mod_name(mod), rsnd_mod_id(mod), status);
641 rsnd_ssi_status_clear(mod);
642 rsnd_ssi_interrupt_out:
643 spin_unlock(&priv->lock);
646 rsnd_dai_period_elapsed(io);
649 snd_pcm_stop_xrun(io->substream);
653 static irqreturn_t rsnd_ssi_interrupt(int irq, void *data)
655 struct rsnd_mod *mod = data;
657 rsnd_mod_interrupt(mod, __rsnd_ssi_interrupt);
665 static void rsnd_ssi_parent_attach(struct rsnd_mod *mod,
666 struct rsnd_dai_stream *io)
668 struct rsnd_dai *rdai = rsnd_io_to_rdai(io);
669 struct rsnd_priv *priv = rsnd_mod_to_priv(mod);
671 if (!__rsnd_ssi_is_pin_sharing(mod))
674 if (!rsnd_rdai_is_clk_master(rdai))
677 switch (rsnd_mod_id(mod)) {
680 rsnd_dai_connect(rsnd_ssi_mod_get(priv, 0), io, RSND_MOD_SSIP);
683 rsnd_dai_connect(rsnd_ssi_mod_get(priv, 3), io, RSND_MOD_SSIP);
686 rsnd_dai_connect(rsnd_ssi_mod_get(priv, 7), io, RSND_MOD_SSIP);
691 static int rsnd_ssi_pcm_new(struct rsnd_mod *mod,
692 struct rsnd_dai_stream *io,
693 struct snd_soc_pcm_runtime *rtd)
696 * rsnd_rdai_is_clk_master() will be enabled after set_fmt,
697 * and, pcm_new will be called after it.
698 * This function reuse pcm_new at this point.
700 rsnd_ssi_parent_attach(mod, io);
705 static int rsnd_ssi_common_probe(struct rsnd_mod *mod,
706 struct rsnd_dai_stream *io,
707 struct rsnd_priv *priv)
709 struct device *dev = rsnd_priv_to_dev(priv);
710 struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
714 * SSIP/SSIU/IRQ are not needed on
717 if (rsnd_ssi_is_multi_slave(mod, io))
721 * It can't judge ssi parent at this point
722 * see rsnd_ssi_pcm_new()
725 ret = rsnd_ssiu_attach(io, mod);
730 * SSI might be called again as PIO fallback
731 * It is easy to manual handling for IRQ request/free
733 * OTOH, this function might be called many times if platform is
734 * using MIX. It needs xxx_attach() many times on xxx_probe().
735 * Because of it, we can't control .probe/.remove calling count by
737 * But it don't need to call request_irq() many times.
738 * Let's control it by RSND_SSI_PROBED flag.
740 if (!rsnd_flags_has(ssi, RSND_SSI_PROBED)) {
741 ret = request_irq(ssi->irq,
746 rsnd_flags_set(ssi, RSND_SSI_PROBED);
752 static int rsnd_ssi_common_remove(struct rsnd_mod *mod,
753 struct rsnd_dai_stream *io,
754 struct rsnd_priv *priv)
756 struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
757 struct rsnd_mod *pure_ssi_mod = rsnd_io_to_mod_ssi(io);
759 /* Do nothing if non SSI (= SSI parent, multi SSI) mod */
760 if (pure_ssi_mod != mod)
763 /* PIO will request IRQ again */
764 if (rsnd_flags_has(ssi, RSND_SSI_PROBED)) {
765 free_irq(ssi->irq, mod);
767 rsnd_flags_del(ssi, RSND_SSI_PROBED);
776 static bool rsnd_ssi_pio_interrupt(struct rsnd_mod *mod,
777 struct rsnd_dai_stream *io)
779 struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io);
780 struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
781 u32 *buf = (u32 *)(runtime->dma_area + ssi->byte_pos);
784 bool elapsed = false;
786 if (snd_pcm_format_width(runtime->format) == 24)
790 * 8/16/32 data can be assesse to TDR/RDR register
791 * directly as 32bit data
792 * see rsnd_ssi_init()
794 if (rsnd_io_is_play(io))
795 rsnd_mod_write(mod, SSITDR, (*buf) << shift);
797 *buf = (rsnd_mod_read(mod, SSIRDR) >> shift);
799 byte_pos = ssi->byte_pos + sizeof(*buf);
801 if (byte_pos >= ssi->next_period_byte) {
802 int period_pos = byte_pos / ssi->byte_per_period;
804 if (period_pos >= runtime->periods) {
809 ssi->next_period_byte = (period_pos + 1) * ssi->byte_per_period;
814 WRITE_ONCE(ssi->byte_pos, byte_pos);
819 static int rsnd_ssi_pio_init(struct rsnd_mod *mod,
820 struct rsnd_dai_stream *io,
821 struct rsnd_priv *priv)
823 struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io);
824 struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
826 if (!rsnd_ssi_is_parent(mod, io)) {
828 ssi->byte_per_period = runtime->period_size *
830 samples_to_bytes(runtime, 1);
831 ssi->next_period_byte = ssi->byte_per_period;
834 return rsnd_ssi_init(mod, io, priv);
837 static int rsnd_ssi_pio_pointer(struct rsnd_mod *mod,
838 struct rsnd_dai_stream *io,
839 snd_pcm_uframes_t *pointer)
841 struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
842 struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io);
844 *pointer = bytes_to_frames(runtime, READ_ONCE(ssi->byte_pos));
849 static struct rsnd_mod_ops rsnd_ssi_pio_ops = {
851 .probe = rsnd_ssi_common_probe,
852 .remove = rsnd_ssi_common_remove,
853 .init = rsnd_ssi_pio_init,
854 .quit = rsnd_ssi_quit,
855 .start = rsnd_ssi_start,
856 .stop = rsnd_ssi_stop,
858 .pointer = rsnd_ssi_pio_pointer,
859 .pcm_new = rsnd_ssi_pcm_new,
860 .hw_params = rsnd_ssi_hw_params,
863 static int rsnd_ssi_dma_probe(struct rsnd_mod *mod,
864 struct rsnd_dai_stream *io,
865 struct rsnd_priv *priv)
867 struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
871 * SSIP/SSIU/IRQ/DMA are not needed on
874 if (rsnd_ssi_is_multi_slave(mod, io))
877 ret = rsnd_ssi_common_probe(mod, io, priv);
881 /* SSI probe might be called many times in MUX multi path */
882 ret = rsnd_dma_attach(io, mod, &ssi->dma);
887 static int rsnd_ssi_fallback(struct rsnd_mod *mod,
888 struct rsnd_dai_stream *io,
889 struct rsnd_priv *priv)
891 struct device *dev = rsnd_priv_to_dev(priv);
896 * SSI .probe might be called again.
898 * rsnd_rdai_continuance_probe()
900 mod->ops = &rsnd_ssi_pio_ops;
902 dev_info(dev, "%s[%d] fallback to PIO mode\n",
903 rsnd_mod_name(mod), rsnd_mod_id(mod));
908 static struct dma_chan *rsnd_ssi_dma_req(struct rsnd_dai_stream *io,
909 struct rsnd_mod *mod)
911 struct rsnd_priv *priv = rsnd_mod_to_priv(mod);
912 int is_play = rsnd_io_is_play(io);
915 if (rsnd_ssi_use_busif(io))
916 name = is_play ? "rxu" : "txu";
918 name = is_play ? "rx" : "tx";
920 return rsnd_dma_request_channel(rsnd_ssi_of_node(priv),
924 static struct rsnd_mod_ops rsnd_ssi_dma_ops = {
926 .dma_req = rsnd_ssi_dma_req,
927 .probe = rsnd_ssi_dma_probe,
928 .remove = rsnd_ssi_common_remove,
929 .init = rsnd_ssi_init,
930 .quit = rsnd_ssi_quit,
931 .start = rsnd_ssi_start,
932 .stop = rsnd_ssi_stop,
934 .pcm_new = rsnd_ssi_pcm_new,
935 .fallback = rsnd_ssi_fallback,
936 .hw_params = rsnd_ssi_hw_params,
939 int rsnd_ssi_is_dma_mode(struct rsnd_mod *mod)
941 return mod->ops == &rsnd_ssi_dma_ops;
948 static void rsnd_ssi_connect(struct rsnd_mod *mod,
949 struct rsnd_dai_stream *io)
951 struct rsnd_dai *rdai = rsnd_io_to_rdai(io);
952 enum rsnd_mod_type types[] = {
958 enum rsnd_mod_type type;
961 /* try SSI -> SSIM1 -> SSIM2 -> SSIM3 */
962 for (i = 0; i < ARRAY_SIZE(types); i++) {
964 if (!rsnd_io_to_mod(io, type)) {
965 rsnd_dai_connect(mod, io, type);
966 rsnd_rdai_channels_set(rdai, (i + 1) * 2);
967 rsnd_rdai_ssi_lane_set(rdai, (i + 1));
973 void rsnd_parse_connect_ssi(struct rsnd_dai *rdai,
974 struct device_node *playback,
975 struct device_node *capture)
977 struct rsnd_priv *priv = rsnd_rdai_to_priv(rdai);
978 struct device_node *node;
979 struct device_node *np;
980 struct rsnd_mod *mod;
983 node = rsnd_ssi_of_node(priv);
988 for_each_child_of_node(node, np) {
989 mod = rsnd_ssi_mod_get(priv, i);
991 rsnd_ssi_connect(mod, &rdai->playback);
993 rsnd_ssi_connect(mod, &rdai->capture);
1000 static void __rsnd_ssi_parse_hdmi_connection(struct rsnd_priv *priv,
1001 struct rsnd_dai_stream *io,
1002 struct device_node *remote_ep)
1004 struct device *dev = rsnd_priv_to_dev(priv);
1005 struct rsnd_mod *mod = rsnd_io_to_mod_ssi(io);
1006 struct rsnd_ssi *ssi;
1007 struct device_node *remote_node = of_graph_get_port_parent(remote_ep);
1009 /* support Gen3 only */
1010 if (!rsnd_is_gen3(priv))
1016 ssi = rsnd_mod_to_ssi(mod);
1019 if (strstr(remote_node->full_name, "hdmi@fead0000")) {
1020 rsnd_flags_set(ssi, RSND_SSI_HDMI0);
1021 dev_dbg(dev, "%s[%d] connected to HDMI0\n",
1022 rsnd_mod_name(mod), rsnd_mod_id(mod));
1026 if (strstr(remote_node->full_name, "hdmi@feae0000")) {
1027 rsnd_flags_set(ssi, RSND_SSI_HDMI1);
1028 dev_dbg(dev, "%s[%d] connected to HDMI1\n",
1029 rsnd_mod_name(mod), rsnd_mod_id(mod));
1033 void rsnd_ssi_parse_hdmi_connection(struct rsnd_priv *priv,
1034 struct device_node *endpoint,
1037 struct rsnd_dai *rdai = rsnd_rdai_get(priv, dai_i);
1038 struct device_node *remote_ep;
1040 remote_ep = of_graph_get_remote_endpoint(endpoint);
1044 __rsnd_ssi_parse_hdmi_connection(priv, &rdai->playback, remote_ep);
1045 __rsnd_ssi_parse_hdmi_connection(priv, &rdai->capture, remote_ep);
1048 struct rsnd_mod *rsnd_ssi_mod_get(struct rsnd_priv *priv, int id)
1050 if (WARN_ON(id < 0 || id >= rsnd_ssi_nr(priv)))
1053 return rsnd_mod_get(rsnd_ssi_get(priv, id));
1056 int __rsnd_ssi_is_pin_sharing(struct rsnd_mod *mod)
1061 return !!(rsnd_flags_has(rsnd_mod_to_ssi(mod), RSND_SSI_CLK_PIN_SHARE));
1064 static u32 *rsnd_ssi_get_status(struct rsnd_dai_stream *io,
1065 struct rsnd_mod *mod,
1066 enum rsnd_mod_type type)
1069 * SSIP (= SSI parent) needs to be special, otherwise,
1070 * 2nd SSI might doesn't start. see also rsnd_mod_call()
1072 * We can't include parent SSI status on SSI, because we don't know
1073 * how many SSI requests parent SSI. Thus, it is localed on "io" now.
1076 * Capture : SSI1 (needs SSI0)
1078 * 1) start Capture -> SSI0/SSI1 are started.
1079 * 2) start Playback -> SSI0 doesn't work, because it is already
1080 * marked as "started" on 1)
1082 * OTOH, using each mod's status is good for MUX case.
1083 * It doesn't need to start in 2nd start
1085 * IO-0: SRC0 -> CTU1 -+-> MUX -> DVC -> SSIU -> SSI0
1087 * IO-1: SRC1 -> CTU2 -+
1089 * 1) start IO-0 -> start SSI0
1090 * 2) start IO-1 -> SSI0 doesn't need to start, because it is
1091 * already started on 1)
1093 if (type == RSND_MOD_SSIP)
1094 return &io->parent_ssi_status;
1096 return rsnd_mod_get_status(io, mod, type);
1099 int rsnd_ssi_probe(struct rsnd_priv *priv)
1101 struct device_node *node;
1102 struct device_node *np;
1103 struct device *dev = rsnd_priv_to_dev(priv);
1104 struct rsnd_mod_ops *ops;
1106 struct rsnd_ssi *ssi;
1107 char name[RSND_SSI_NAME_SIZE];
1110 node = rsnd_ssi_of_node(priv);
1114 nr = of_get_child_count(node);
1117 goto rsnd_ssi_probe_done;
1120 ssi = devm_kzalloc(dev, sizeof(*ssi) * nr, GFP_KERNEL);
1123 goto rsnd_ssi_probe_done;
1130 for_each_child_of_node(node, np) {
1131 if (!of_device_is_available(np))
1134 ssi = rsnd_ssi_get(priv, i);
1136 snprintf(name, RSND_SSI_NAME_SIZE, "%s.%d",
1139 clk = devm_clk_get(dev, name);
1143 goto rsnd_ssi_probe_done;
1146 if (of_get_property(np, "shared-pin", NULL))
1147 rsnd_flags_set(ssi, RSND_SSI_CLK_PIN_SHARE);
1149 if (of_get_property(np, "no-busif", NULL))
1150 rsnd_flags_set(ssi, RSND_SSI_NO_BUSIF);
1152 ssi->irq = irq_of_parse_and_map(np, 0);
1156 goto rsnd_ssi_probe_done;
1159 if (of_property_read_bool(np, "pio-transfer"))
1160 ops = &rsnd_ssi_pio_ops;
1162 ops = &rsnd_ssi_dma_ops;
1164 ret = rsnd_mod_init(priv, rsnd_mod_get(ssi), ops, clk,
1165 rsnd_ssi_get_status, RSND_MOD_SSI, i);
1168 goto rsnd_ssi_probe_done;
1176 rsnd_ssi_probe_done:
1182 void rsnd_ssi_remove(struct rsnd_priv *priv)
1184 struct rsnd_ssi *ssi;
1187 for_each_rsnd_ssi(ssi, priv, i) {
1188 rsnd_mod_quit(rsnd_mod_get(ssi));