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 (runtime->sample_bits) {
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 |
417 static void rsnd_ssi_pointer_init(struct rsnd_mod *mod,
418 struct rsnd_dai_stream *io)
420 struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
421 struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io);
425 ssi->byte_per_period = runtime->period_size *
427 samples_to_bytes(runtime, 1);
428 ssi->next_period_byte = ssi->byte_per_period;
431 static int rsnd_ssi_pointer_offset(struct rsnd_mod *mod,
432 struct rsnd_dai_stream *io,
435 struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
436 struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io);
437 int pos = ssi->byte_pos + additional;
439 pos %= (runtime->periods * ssi->byte_per_period);
444 static bool rsnd_ssi_pointer_update(struct rsnd_mod *mod,
445 struct rsnd_dai_stream *io,
448 struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
450 ssi->byte_pos += byte;
452 if (ssi->byte_pos >= ssi->next_period_byte) {
453 struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io);
456 ssi->next_period_byte += ssi->byte_per_period;
458 if (ssi->period_pos >= runtime->periods) {
461 ssi->next_period_byte = ssi->byte_per_period;
471 * SSI mod common functions
473 static int rsnd_ssi_init(struct rsnd_mod *mod,
474 struct rsnd_dai_stream *io,
475 struct rsnd_priv *priv)
477 struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
480 if (!rsnd_ssi_is_run_mods(mod, io))
483 rsnd_ssi_pointer_init(mod, io);
487 rsnd_mod_power_on(mod);
489 ret = rsnd_ssi_master_clk_start(mod, io);
493 rsnd_ssi_config_init(mod, io);
495 rsnd_ssi_register_setup(mod);
497 /* clear error status */
498 rsnd_ssi_status_clear(mod);
503 static int rsnd_ssi_quit(struct rsnd_mod *mod,
504 struct rsnd_dai_stream *io,
505 struct rsnd_priv *priv)
507 struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
508 struct device *dev = rsnd_priv_to_dev(priv);
510 if (!rsnd_ssi_is_run_mods(mod, io))
514 dev_err(dev, "%s[%d] usrcnt error\n",
515 rsnd_mod_name(mod), rsnd_mod_id(mod));
519 if (!rsnd_ssi_is_parent(mod, io))
522 rsnd_ssi_master_clk_stop(mod, io);
524 rsnd_mod_power_off(mod);
531 static int rsnd_ssi_hw_params(struct rsnd_mod *mod,
532 struct rsnd_dai_stream *io,
533 struct snd_pcm_substream *substream,
534 struct snd_pcm_hw_params *params)
536 struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
537 int chan = params_channels(params);
540 * snd_pcm_ops::hw_params will be called *before*
541 * snd_soc_dai_ops::trigger. Thus, ssi->usrcnt is 0
547 * It will happen if SSI has parent/child connection.
548 * it is error if child <-> parent SSI uses
549 * different channels.
551 if (ssi->chan != chan)
560 static int rsnd_ssi_start(struct rsnd_mod *mod,
561 struct rsnd_dai_stream *io,
562 struct rsnd_priv *priv)
564 struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
566 if (!rsnd_ssi_is_run_mods(mod, io))
570 * EN will be set via SSIU :: SSI_CONTROL
571 * if Multi channel mode
573 if (rsnd_ssi_multi_slaves_runtime(io))
577 * EN is for data output.
578 * SSI parent EN is not needed.
580 if (rsnd_ssi_is_parent(mod, io))
585 rsnd_mod_write(mod, SSICR, ssi->cr_own |
593 static int rsnd_ssi_stop(struct rsnd_mod *mod,
594 struct rsnd_dai_stream *io,
595 struct rsnd_priv *priv)
597 struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
600 if (!rsnd_ssi_is_run_mods(mod, io))
603 if (rsnd_ssi_is_parent(mod, io))
611 * Playback: Wait all data was sent
612 * Capture: It might not receave data. Do nothing
614 if (rsnd_io_is_play(io)) {
615 rsnd_mod_write(mod, SSICR, cr | EN);
616 rsnd_ssi_status_check(mod, DIRQ);
621 * and, wait idle state
623 rsnd_mod_write(mod, SSICR, cr); /* disabled all */
624 rsnd_ssi_status_check(mod, IIRQ);
631 static int rsnd_ssi_irq(struct rsnd_mod *mod,
632 struct rsnd_dai_stream *io,
633 struct rsnd_priv *priv,
638 if (rsnd_is_gen1(priv))
641 if (rsnd_ssi_is_parent(mod, io))
644 if (!rsnd_ssi_is_run_mods(mod, io))
648 val = rsnd_ssi_is_dma_mode(mod) ? 0x0e000000 : 0x0f000000;
650 rsnd_mod_write(mod, SSI_INT_ENABLE, val);
655 static void __rsnd_ssi_interrupt(struct rsnd_mod *mod,
656 struct rsnd_dai_stream *io)
658 struct rsnd_priv *priv = rsnd_mod_to_priv(mod);
659 int is_dma = rsnd_ssi_is_dma_mode(mod);
661 bool elapsed = false;
664 spin_lock(&priv->lock);
666 /* ignore all cases if not working */
667 if (!rsnd_io_is_working(io))
668 goto rsnd_ssi_interrupt_out;
670 status = rsnd_ssi_status_get(mod);
673 if (!is_dma && (status & DIRQ)) {
674 struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io);
675 u32 *buf = (u32 *)(runtime->dma_area +
676 rsnd_ssi_pointer_offset(mod, io, 0));
679 switch (runtime->sample_bits) {
686 * 8/16/32 data can be assesse to TDR/RDR register
687 * directly as 32bit data
688 * see rsnd_ssi_init()
690 if (rsnd_io_is_play(io))
691 rsnd_mod_write(mod, SSITDR, (*buf) << shift);
693 *buf = (rsnd_mod_read(mod, SSIRDR) >> shift);
695 elapsed = rsnd_ssi_pointer_update(mod, io, sizeof(*buf));
699 if (is_dma && (status & (UIRQ | OIRQ)))
702 rsnd_ssi_status_clear(mod);
703 rsnd_ssi_interrupt_out:
704 spin_unlock(&priv->lock);
707 rsnd_dai_period_elapsed(io);
710 snd_pcm_stop_xrun(io->substream);
714 static irqreturn_t rsnd_ssi_interrupt(int irq, void *data)
716 struct rsnd_mod *mod = data;
718 rsnd_mod_interrupt(mod, __rsnd_ssi_interrupt);
726 static void rsnd_ssi_parent_attach(struct rsnd_mod *mod,
727 struct rsnd_dai_stream *io)
729 struct rsnd_dai *rdai = rsnd_io_to_rdai(io);
730 struct rsnd_priv *priv = rsnd_mod_to_priv(mod);
732 if (!__rsnd_ssi_is_pin_sharing(mod))
735 if (!rsnd_rdai_is_clk_master(rdai))
738 switch (rsnd_mod_id(mod)) {
741 rsnd_dai_connect(rsnd_ssi_mod_get(priv, 0), io, RSND_MOD_SSIP);
744 rsnd_dai_connect(rsnd_ssi_mod_get(priv, 3), io, RSND_MOD_SSIP);
747 rsnd_dai_connect(rsnd_ssi_mod_get(priv, 7), io, RSND_MOD_SSIP);
752 static int rsnd_ssi_pcm_new(struct rsnd_mod *mod,
753 struct rsnd_dai_stream *io,
754 struct snd_soc_pcm_runtime *rtd)
757 * rsnd_rdai_is_clk_master() will be enabled after set_fmt,
758 * and, pcm_new will be called after it.
759 * This function reuse pcm_new at this point.
761 rsnd_ssi_parent_attach(mod, io);
766 static int rsnd_ssi_common_probe(struct rsnd_mod *mod,
767 struct rsnd_dai_stream *io,
768 struct rsnd_priv *priv)
770 struct device *dev = rsnd_priv_to_dev(priv);
771 struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
775 * SSIP/SSIU/IRQ are not needed on
778 if (rsnd_ssi_is_multi_slave(mod, io))
782 * It can't judge ssi parent at this point
783 * see rsnd_ssi_pcm_new()
786 ret = rsnd_ssiu_attach(io, mod);
791 * SSI might be called again as PIO fallback
792 * It is easy to manual handling for IRQ request/free
794 * OTOH, this function might be called many times if platform is
795 * using MIX. It needs xxx_attach() many times on xxx_probe().
796 * Because of it, we can't control .probe/.remove calling count by
798 * But it don't need to call request_irq() many times.
799 * Let's control it by RSND_SSI_PROBED flag.
801 if (!rsnd_flags_has(ssi, RSND_SSI_PROBED)) {
802 ret = request_irq(ssi->irq,
807 rsnd_flags_set(ssi, RSND_SSI_PROBED);
813 static int rsnd_ssi_common_remove(struct rsnd_mod *mod,
814 struct rsnd_dai_stream *io,
815 struct rsnd_priv *priv)
817 struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
818 struct rsnd_mod *pure_ssi_mod = rsnd_io_to_mod_ssi(io);
820 /* Do nothing if non SSI (= SSI parent, multi SSI) mod */
821 if (pure_ssi_mod != mod)
824 /* PIO will request IRQ again */
825 if (rsnd_flags_has(ssi, RSND_SSI_PROBED)) {
826 free_irq(ssi->irq, mod);
828 rsnd_flags_del(ssi, RSND_SSI_PROBED);
834 static int rsnd_ssi_pointer(struct rsnd_mod *mod,
835 struct rsnd_dai_stream *io,
836 snd_pcm_uframes_t *pointer)
838 struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
839 struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io);
841 *pointer = bytes_to_frames(runtime, ssi->byte_pos);
846 static struct rsnd_mod_ops rsnd_ssi_pio_ops = {
848 .probe = rsnd_ssi_common_probe,
849 .remove = rsnd_ssi_common_remove,
850 .init = rsnd_ssi_init,
851 .quit = rsnd_ssi_quit,
852 .start = rsnd_ssi_start,
853 .stop = rsnd_ssi_stop,
855 .pointer= rsnd_ssi_pointer,
856 .pcm_new = rsnd_ssi_pcm_new,
857 .hw_params = rsnd_ssi_hw_params,
860 static int rsnd_ssi_dma_probe(struct rsnd_mod *mod,
861 struct rsnd_dai_stream *io,
862 struct rsnd_priv *priv)
864 struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
868 * SSIP/SSIU/IRQ/DMA are not needed on
871 if (rsnd_ssi_is_multi_slave(mod, io))
874 ret = rsnd_ssi_common_probe(mod, io, priv);
878 /* SSI probe might be called many times in MUX multi path */
879 ret = rsnd_dma_attach(io, mod, &ssi->dma);
884 static int rsnd_ssi_fallback(struct rsnd_mod *mod,
885 struct rsnd_dai_stream *io,
886 struct rsnd_priv *priv)
888 struct device *dev = rsnd_priv_to_dev(priv);
893 * SSI .probe might be called again.
895 * rsnd_rdai_continuance_probe()
897 mod->ops = &rsnd_ssi_pio_ops;
899 dev_info(dev, "%s[%d] fallback to PIO mode\n",
900 rsnd_mod_name(mod), rsnd_mod_id(mod));
905 static struct dma_chan *rsnd_ssi_dma_req(struct rsnd_dai_stream *io,
906 struct rsnd_mod *mod)
908 struct rsnd_priv *priv = rsnd_mod_to_priv(mod);
909 int is_play = rsnd_io_is_play(io);
912 if (rsnd_ssi_use_busif(io))
913 name = is_play ? "rxu" : "txu";
915 name = is_play ? "rx" : "tx";
917 return rsnd_dma_request_channel(rsnd_ssi_of_node(priv),
921 static struct rsnd_mod_ops rsnd_ssi_dma_ops = {
923 .dma_req = rsnd_ssi_dma_req,
924 .probe = rsnd_ssi_dma_probe,
925 .remove = rsnd_ssi_common_remove,
926 .init = rsnd_ssi_init,
927 .quit = rsnd_ssi_quit,
928 .start = rsnd_ssi_start,
929 .stop = rsnd_ssi_stop,
931 .pcm_new = rsnd_ssi_pcm_new,
932 .fallback = rsnd_ssi_fallback,
933 .hw_params = rsnd_ssi_hw_params,
936 int rsnd_ssi_is_dma_mode(struct rsnd_mod *mod)
938 return mod->ops == &rsnd_ssi_dma_ops;
945 static void rsnd_ssi_connect(struct rsnd_mod *mod,
946 struct rsnd_dai_stream *io)
948 struct rsnd_dai *rdai = rsnd_io_to_rdai(io);
949 enum rsnd_mod_type types[] = {
955 enum rsnd_mod_type type;
958 /* try SSI -> SSIM1 -> SSIM2 -> SSIM3 */
959 for (i = 0; i < ARRAY_SIZE(types); i++) {
961 if (!rsnd_io_to_mod(io, type)) {
962 rsnd_dai_connect(mod, io, type);
963 rsnd_rdai_channels_set(rdai, (i + 1) * 2);
964 rsnd_rdai_ssi_lane_set(rdai, (i + 1));
970 void rsnd_parse_connect_ssi(struct rsnd_dai *rdai,
971 struct device_node *playback,
972 struct device_node *capture)
974 struct rsnd_priv *priv = rsnd_rdai_to_priv(rdai);
975 struct device_node *node;
976 struct device_node *np;
977 struct rsnd_mod *mod;
980 node = rsnd_ssi_of_node(priv);
985 for_each_child_of_node(node, np) {
986 mod = rsnd_ssi_mod_get(priv, i);
988 rsnd_ssi_connect(mod, &rdai->playback);
990 rsnd_ssi_connect(mod, &rdai->capture);
997 static void __rsnd_ssi_parse_hdmi_connection(struct rsnd_priv *priv,
998 struct rsnd_dai_stream *io,
999 struct device_node *remote_ep)
1001 struct device *dev = rsnd_priv_to_dev(priv);
1002 struct rsnd_mod *mod = rsnd_io_to_mod_ssi(io);
1003 struct rsnd_ssi *ssi;
1008 ssi = rsnd_mod_to_ssi(mod);
1010 if (strstr(remote_ep->full_name, "hdmi0")) {
1011 rsnd_flags_set(ssi, RSND_SSI_HDMI0);
1012 dev_dbg(dev, "%s[%d] connected to HDMI0\n",
1013 rsnd_mod_name(mod), rsnd_mod_id(mod));
1016 if (strstr(remote_ep->full_name, "hdmi1")) {
1017 rsnd_flags_set(ssi, RSND_SSI_HDMI1);
1018 dev_dbg(dev, "%s[%d] connected to HDMI1\n",
1019 rsnd_mod_name(mod), rsnd_mod_id(mod));
1023 void rsnd_ssi_parse_hdmi_connection(struct rsnd_priv *priv,
1024 struct device_node *endpoint,
1027 struct rsnd_dai *rdai = rsnd_rdai_get(priv, dai_i);
1028 struct device_node *remote_ep;
1030 remote_ep = of_graph_get_remote_endpoint(endpoint);
1034 __rsnd_ssi_parse_hdmi_connection(priv, &rdai->playback, remote_ep);
1035 __rsnd_ssi_parse_hdmi_connection(priv, &rdai->capture, remote_ep);
1038 struct rsnd_mod *rsnd_ssi_mod_get(struct rsnd_priv *priv, int id)
1040 if (WARN_ON(id < 0 || id >= rsnd_ssi_nr(priv)))
1043 return rsnd_mod_get(rsnd_ssi_get(priv, id));
1046 int __rsnd_ssi_is_pin_sharing(struct rsnd_mod *mod)
1048 struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
1050 return !!(rsnd_flags_has(ssi, RSND_SSI_CLK_PIN_SHARE));
1053 static u32 *rsnd_ssi_get_status(struct rsnd_dai_stream *io,
1054 struct rsnd_mod *mod,
1055 enum rsnd_mod_type type)
1058 * SSIP (= SSI parent) needs to be special, otherwise,
1059 * 2nd SSI might doesn't start. see also rsnd_mod_call()
1061 * We can't include parent SSI status on SSI, because we don't know
1062 * how many SSI requests parent SSI. Thus, it is localed on "io" now.
1065 * Capture : SSI1 (needs SSI0)
1067 * 1) start Capture -> SSI0/SSI1 are started.
1068 * 2) start Playback -> SSI0 doesn't work, because it is already
1069 * marked as "started" on 1)
1071 * OTOH, using each mod's status is good for MUX case.
1072 * It doesn't need to start in 2nd start
1074 * IO-0: SRC0 -> CTU1 -+-> MUX -> DVC -> SSIU -> SSI0
1076 * IO-1: SRC1 -> CTU2 -+
1078 * 1) start IO-0 -> start SSI0
1079 * 2) start IO-1 -> SSI0 doesn't need to start, because it is
1080 * already started on 1)
1082 if (type == RSND_MOD_SSIP)
1083 return &io->parent_ssi_status;
1085 return rsnd_mod_get_status(io, mod, type);
1088 int rsnd_ssi_probe(struct rsnd_priv *priv)
1090 struct device_node *node;
1091 struct device_node *np;
1092 struct device *dev = rsnd_priv_to_dev(priv);
1093 struct rsnd_mod_ops *ops;
1095 struct rsnd_ssi *ssi;
1096 char name[RSND_SSI_NAME_SIZE];
1099 node = rsnd_ssi_of_node(priv);
1103 nr = of_get_child_count(node);
1106 goto rsnd_ssi_probe_done;
1109 ssi = devm_kzalloc(dev, sizeof(*ssi) * nr, GFP_KERNEL);
1112 goto rsnd_ssi_probe_done;
1119 for_each_child_of_node(node, np) {
1120 if (!of_device_is_available(np))
1123 ssi = rsnd_ssi_get(priv, i);
1125 snprintf(name, RSND_SSI_NAME_SIZE, "%s.%d",
1128 clk = devm_clk_get(dev, name);
1132 goto rsnd_ssi_probe_done;
1135 if (of_get_property(np, "shared-pin", NULL))
1136 rsnd_flags_set(ssi, RSND_SSI_CLK_PIN_SHARE);
1138 if (of_get_property(np, "no-busif", NULL))
1139 rsnd_flags_set(ssi, RSND_SSI_NO_BUSIF);
1141 ssi->irq = irq_of_parse_and_map(np, 0);
1145 goto rsnd_ssi_probe_done;
1148 if (of_property_read_bool(np, "pio-transfer"))
1149 ops = &rsnd_ssi_pio_ops;
1151 ops = &rsnd_ssi_dma_ops;
1153 ret = rsnd_mod_init(priv, rsnd_mod_get(ssi), ops, clk,
1154 rsnd_ssi_get_status, RSND_MOD_SSI, i);
1157 goto rsnd_ssi_probe_done;
1165 rsnd_ssi_probe_done:
1171 void rsnd_ssi_remove(struct rsnd_priv *priv)
1173 struct rsnd_ssi *ssi;
1176 for_each_rsnd_ssi(ssi, priv, i) {
1177 rsnd_mod_quit(rsnd_mod_get(ssi));