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_flags_has(p, f) ((p)->flags & f)
105 #define rsnd_ssi_flags_set(p, f) ((p)->flags |= f)
106 #define rsnd_ssi_flags_del(p, f) ((p)->flags = ((p)->flags & ~f))
107 #define rsnd_ssi_is_parent(ssi, io) ((ssi) == rsnd_io_to_mod_ssip(io))
108 #define rsnd_ssi_is_multi_slave(mod, io) \
109 (rsnd_ssi_multi_slaves(io) & (1 << rsnd_mod_id(mod)))
110 #define rsnd_ssi_is_run_mods(mod, io) \
111 (rsnd_ssi_run_mods(io) & (1 << rsnd_mod_id(mod)))
112 #define rsnd_ssi_can_output_clk(mod) (!__rsnd_ssi_is_pin_sharing(mod))
114 int rsnd_ssi_hdmi_port(struct rsnd_dai_stream
*io
)
116 struct rsnd_mod
*mod
= rsnd_io_to_mod_ssi(io
);
117 struct rsnd_ssi
*ssi
= rsnd_mod_to_ssi(mod
);
119 if (rsnd_ssi_flags_has(ssi
, RSND_SSI_HDMI0
))
120 return RSND_SSI_HDMI_PORT0
;
122 if (rsnd_ssi_flags_has(ssi
, RSND_SSI_HDMI1
))
123 return RSND_SSI_HDMI_PORT1
;
128 int rsnd_ssi_use_busif(struct rsnd_dai_stream
*io
)
130 struct rsnd_mod
*mod
= rsnd_io_to_mod_ssi(io
);
131 struct rsnd_ssi
*ssi
= rsnd_mod_to_ssi(mod
);
134 if (!rsnd_ssi_is_dma_mode(mod
))
137 if (!(rsnd_ssi_flags_has(ssi
, RSND_SSI_NO_BUSIF
)))
139 if (rsnd_io_to_mod_src(io
))
145 static void rsnd_ssi_status_clear(struct rsnd_mod
*mod
)
147 rsnd_mod_write(mod
, SSISR
, 0);
150 static u32
rsnd_ssi_status_get(struct rsnd_mod
*mod
)
152 return rsnd_mod_read(mod
, SSISR
);
155 static void rsnd_ssi_status_check(struct rsnd_mod
*mod
,
158 struct rsnd_priv
*priv
= rsnd_mod_to_priv(mod
);
159 struct device
*dev
= rsnd_priv_to_dev(priv
);
163 for (i
= 0; i
< 1024; i
++) {
164 status
= rsnd_ssi_status_get(mod
);
171 dev_warn(dev
, "%s[%d] status check failed\n",
172 rsnd_mod_name(mod
), rsnd_mod_id(mod
));
175 static u32
rsnd_ssi_multi_slaves(struct rsnd_dai_stream
*io
)
177 struct rsnd_mod
*mod
;
178 enum rsnd_mod_type types
[] = {
186 for (i
= 0; i
< ARRAY_SIZE(types
); i
++) {
187 mod
= rsnd_io_to_mod(io
, types
[i
]);
191 mask
|= 1 << rsnd_mod_id(mod
);
197 static u32
rsnd_ssi_run_mods(struct rsnd_dai_stream
*io
)
199 struct rsnd_mod
*ssi_mod
= rsnd_io_to_mod_ssi(io
);
200 struct rsnd_mod
*ssi_parent_mod
= rsnd_io_to_mod_ssip(io
);
203 mods
= rsnd_ssi_multi_slaves_runtime(io
) |
204 1 << rsnd_mod_id(ssi_mod
);
207 mods
|= 1 << rsnd_mod_id(ssi_parent_mod
);
212 u32
rsnd_ssi_multi_slaves_runtime(struct rsnd_dai_stream
*io
)
214 if (rsnd_runtime_is_ssi_multi(io
))
215 return rsnd_ssi_multi_slaves(io
);
220 unsigned int rsnd_ssi_clk_query(struct rsnd_priv
*priv
,
221 int param1
, int param2
, int *idx
)
223 int ssi_clk_mul_table
[] = {
224 1, 2, 4, 8, 16, 6, 12,
227 unsigned int main_rate
;
229 for (j
= 0; j
< ARRAY_SIZE(ssi_clk_mul_table
); j
++) {
232 * It will set SSIWSR.CONT here, but SSICR.CKDV = 000
233 * with it is not allowed. (SSIWSR.WS_MODE with
234 * SSICR.CKDV = 000 is not allowed either).
235 * Skip it. See SSICR.CKDV
241 * this driver is assuming that
242 * system word is 32bit x chan
243 * see rsnd_ssi_init()
245 main_rate
= 32 * param1
* param2
* ssi_clk_mul_table
[j
];
247 ret
= rsnd_adg_clk_query(priv
, main_rate
);
260 static int rsnd_ssi_master_clk_start(struct rsnd_mod
*mod
,
261 struct rsnd_dai_stream
*io
)
263 struct rsnd_priv
*priv
= rsnd_io_to_priv(io
);
264 struct device
*dev
= rsnd_priv_to_dev(priv
);
265 struct rsnd_dai
*rdai
= rsnd_io_to_rdai(io
);
266 struct rsnd_ssi
*ssi
= rsnd_mod_to_ssi(mod
);
267 int chan
= rsnd_runtime_channel_for_ssi(io
);
269 unsigned int main_rate
;
270 unsigned int rate
= rsnd_io_is_play(io
) ?
271 rsnd_src_get_out_rate(priv
, io
) :
272 rsnd_src_get_in_rate(priv
, io
);
274 if (!rsnd_rdai_is_clk_master(rdai
))
277 if (!rsnd_ssi_can_output_clk(mod
))
280 if (rsnd_ssi_is_multi_slave(mod
, io
))
283 if (ssi
->usrcnt
> 0) {
284 if (ssi
->rate
!= rate
) {
285 dev_err(dev
, "SSI parent/child should use same rate\n");
292 main_rate
= rsnd_ssi_clk_query(priv
, rate
, chan
, &idx
);
294 dev_err(dev
, "unsupported clock rate\n");
298 ret
= rsnd_adg_ssi_clk_try_start(mod
, main_rate
);
303 * SSI clock will be output contiguously
305 * This means, rsnd_ssi_master_clk_start()
306 * and rsnd_ssi_register_setup() are necessary
309 * SSICR : FORCE, SCKD, SWSD
312 ssi
->cr_clk
= FORCE
| SWL_32
| SCKD
| SWSD
| CKDV(idx
);
316 dev_dbg(dev
, "%s[%d] outputs %u Hz\n",
318 rsnd_mod_id(mod
), rate
);
323 static void rsnd_ssi_master_clk_stop(struct rsnd_mod
*mod
,
324 struct rsnd_dai_stream
*io
)
326 struct rsnd_dai
*rdai
= rsnd_io_to_rdai(io
);
327 struct rsnd_ssi
*ssi
= rsnd_mod_to_ssi(mod
);
329 if (!rsnd_rdai_is_clk_master(rdai
))
332 if (!rsnd_ssi_can_output_clk(mod
))
341 rsnd_adg_ssi_clk_stop(mod
);
344 static void rsnd_ssi_config_init(struct rsnd_mod
*mod
,
345 struct rsnd_dai_stream
*io
)
347 struct rsnd_dai
*rdai
= rsnd_io_to_rdai(io
);
348 struct snd_pcm_runtime
*runtime
= rsnd_io_to_runtime(io
);
349 struct rsnd_ssi
*ssi
= rsnd_mod_to_ssi(mod
);
355 if (rsnd_ssi_is_parent(mod
, io
))
358 is_tdm
= rsnd_runtime_is_ssi_tdm(io
);
361 * always use 32bit system word.
362 * see also rsnd_ssi_master_clk_enable()
364 cr_own
= FORCE
| SWL_32
;
366 if (rdai
->bit_clk_inv
)
368 if (rdai
->frm_clk_inv
^ is_tdm
)
370 if (rdai
->data_alignment
)
374 if (rsnd_io_is_play(io
))
377 switch (runtime
->sample_bits
) {
386 if (rsnd_ssi_is_dma_mode(mod
)) {
387 cr_mode
= UIEN
| OIEN
| /* over/under run */
388 DMEN
; /* DMA : enable DMA */
390 cr_mode
= DIEN
; /* PIO : enable Data interrupt */
396 * rsnd_ssiu_init_gen2()
404 ssi
->cr_own
= cr_own
;
405 ssi
->cr_mode
= cr_mode
;
409 static void rsnd_ssi_register_setup(struct rsnd_mod
*mod
)
411 struct rsnd_ssi
*ssi
= rsnd_mod_to_ssi(mod
);
413 rsnd_mod_write(mod
, SSIWSR
, ssi
->wsr
);
414 rsnd_mod_write(mod
, SSICR
, ssi
->cr_own
|
420 static void rsnd_ssi_pointer_init(struct rsnd_mod
*mod
,
421 struct rsnd_dai_stream
*io
)
423 struct rsnd_ssi
*ssi
= rsnd_mod_to_ssi(mod
);
424 struct snd_pcm_runtime
*runtime
= rsnd_io_to_runtime(io
);
428 ssi
->byte_per_period
= runtime
->period_size
*
430 samples_to_bytes(runtime
, 1);
431 ssi
->next_period_byte
= ssi
->byte_per_period
;
434 static int rsnd_ssi_pointer_offset(struct rsnd_mod
*mod
,
435 struct rsnd_dai_stream
*io
,
438 struct rsnd_ssi
*ssi
= rsnd_mod_to_ssi(mod
);
439 struct snd_pcm_runtime
*runtime
= rsnd_io_to_runtime(io
);
440 int pos
= ssi
->byte_pos
+ additional
;
442 pos
%= (runtime
->periods
* ssi
->byte_per_period
);
447 static bool rsnd_ssi_pointer_update(struct rsnd_mod
*mod
,
448 struct rsnd_dai_stream
*io
,
451 struct rsnd_ssi
*ssi
= rsnd_mod_to_ssi(mod
);
455 byte_pos
= ssi
->byte_pos
+ byte
;
457 if (byte_pos
>= ssi
->next_period_byte
) {
458 struct snd_pcm_runtime
*runtime
= rsnd_io_to_runtime(io
);
461 ssi
->next_period_byte
+= ssi
->byte_per_period
;
463 if (ssi
->period_pos
>= runtime
->periods
) {
466 ssi
->next_period_byte
= ssi
->byte_per_period
;
472 WRITE_ONCE(ssi
->byte_pos
, byte_pos
);
478 * SSI mod common functions
480 static int rsnd_ssi_init(struct rsnd_mod
*mod
,
481 struct rsnd_dai_stream
*io
,
482 struct rsnd_priv
*priv
)
484 struct rsnd_ssi
*ssi
= rsnd_mod_to_ssi(mod
);
486 if (!rsnd_ssi_is_run_mods(mod
, io
))
489 rsnd_ssi_pointer_init(mod
, io
);
493 rsnd_mod_power_on(mod
);
495 rsnd_ssi_config_init(mod
, io
);
497 rsnd_ssi_register_setup(mod
);
499 /* clear error status */
500 rsnd_ssi_status_clear(mod
);
505 static int rsnd_ssi_quit(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
);
510 struct device
*dev
= rsnd_priv_to_dev(priv
);
512 if (!rsnd_ssi_is_run_mods(mod
, io
))
516 dev_err(dev
, "%s[%d] usrcnt error\n",
517 rsnd_mod_name(mod
), rsnd_mod_id(mod
));
521 if (!rsnd_ssi_is_parent(mod
, io
))
524 rsnd_ssi_master_clk_stop(mod
, io
);
526 rsnd_mod_power_off(mod
);
533 static int rsnd_ssi_hw_params(struct rsnd_mod
*mod
,
534 struct rsnd_dai_stream
*io
,
535 struct snd_pcm_substream
*substream
,
536 struct snd_pcm_hw_params
*params
)
538 struct rsnd_ssi
*ssi
= rsnd_mod_to_ssi(mod
);
539 int chan
= params_channels(params
);
542 * snd_pcm_ops::hw_params will be called *before*
543 * snd_soc_dai_ops::trigger. Thus, ssi->usrcnt is 0
549 * It will happen if SSI has parent/child connection.
550 * it is error if child <-> parent SSI uses
551 * different channels.
553 if (ssi
->chan
!= chan
)
562 static int rsnd_ssi_start(struct rsnd_mod
*mod
,
563 struct rsnd_dai_stream
*io
,
564 struct rsnd_priv
*priv
)
566 struct rsnd_ssi
*ssi
= rsnd_mod_to_ssi(mod
);
568 if (!rsnd_ssi_is_run_mods(mod
, io
))
572 * EN will be set via SSIU :: SSI_CONTROL
573 * if Multi channel mode
575 if (rsnd_ssi_multi_slaves_runtime(io
))
579 * EN is for data output.
580 * SSI parent EN is not needed.
582 if (rsnd_ssi_is_parent(mod
, io
))
587 rsnd_mod_write(mod
, SSICR
, ssi
->cr_own
|
595 static int rsnd_ssi_stop(struct rsnd_mod
*mod
,
596 struct rsnd_dai_stream
*io
,
597 struct rsnd_priv
*priv
)
599 struct rsnd_ssi
*ssi
= rsnd_mod_to_ssi(mod
);
602 if (!rsnd_ssi_is_run_mods(mod
, io
))
605 if (rsnd_ssi_is_parent(mod
, io
))
610 * and, wait all data was sent
615 rsnd_mod_write(mod
, SSICR
, cr
| EN
);
616 rsnd_ssi_status_check(mod
, DIRQ
);
620 * and, wait idle state
622 rsnd_mod_write(mod
, SSICR
, cr
); /* disabled all */
623 rsnd_ssi_status_check(mod
, IIRQ
);
630 static int rsnd_ssi_irq(struct rsnd_mod
*mod
,
631 struct rsnd_dai_stream
*io
,
632 struct rsnd_priv
*priv
,
637 if (rsnd_is_gen1(priv
))
640 if (rsnd_ssi_is_parent(mod
, io
))
643 if (!rsnd_ssi_is_run_mods(mod
, io
))
647 val
= rsnd_ssi_is_dma_mode(mod
) ? 0x0e000000 : 0x0f000000;
649 rsnd_mod_write(mod
, SSI_INT_ENABLE
, val
);
654 static void __rsnd_ssi_interrupt(struct rsnd_mod
*mod
,
655 struct rsnd_dai_stream
*io
)
657 struct rsnd_priv
*priv
= rsnd_mod_to_priv(mod
);
658 int is_dma
= rsnd_ssi_is_dma_mode(mod
);
660 bool elapsed
= false;
663 spin_lock(&priv
->lock
);
665 /* ignore all cases if not working */
666 if (!rsnd_io_is_working(io
))
667 goto rsnd_ssi_interrupt_out
;
669 status
= rsnd_ssi_status_get(mod
);
672 if (!is_dma
&& (status
& DIRQ
)) {
673 struct snd_pcm_runtime
*runtime
= rsnd_io_to_runtime(io
);
674 u32
*buf
= (u32
*)(runtime
->dma_area
+
675 rsnd_ssi_pointer_offset(mod
, io
, 0));
678 switch (runtime
->sample_bits
) {
685 * 8/16/32 data can be assesse to TDR/RDR register
686 * directly as 32bit data
687 * see rsnd_ssi_init()
689 if (rsnd_io_is_play(io
))
690 rsnd_mod_write(mod
, SSITDR
, (*buf
) << shift
);
692 *buf
= (rsnd_mod_read(mod
, SSIRDR
) >> shift
);
694 elapsed
= rsnd_ssi_pointer_update(mod
, io
, sizeof(*buf
));
698 if (is_dma
&& (status
& (UIRQ
| OIRQ
)))
701 rsnd_ssi_status_clear(mod
);
702 rsnd_ssi_interrupt_out
:
703 spin_unlock(&priv
->lock
);
706 rsnd_dai_period_elapsed(io
);
709 snd_pcm_stop_xrun(io
->substream
);
713 static irqreturn_t
rsnd_ssi_interrupt(int irq
, void *data
)
715 struct rsnd_mod
*mod
= data
;
717 rsnd_mod_interrupt(mod
, __rsnd_ssi_interrupt
);
725 static void rsnd_ssi_parent_attach(struct rsnd_mod
*mod
,
726 struct rsnd_dai_stream
*io
)
728 struct rsnd_dai
*rdai
= rsnd_io_to_rdai(io
);
729 struct rsnd_priv
*priv
= rsnd_mod_to_priv(mod
);
731 if (!__rsnd_ssi_is_pin_sharing(mod
))
734 if (!rsnd_rdai_is_clk_master(rdai
))
737 switch (rsnd_mod_id(mod
)) {
740 rsnd_dai_connect(rsnd_ssi_mod_get(priv
, 0), io
, RSND_MOD_SSIP
);
743 rsnd_dai_connect(rsnd_ssi_mod_get(priv
, 3), io
, RSND_MOD_SSIP
);
746 rsnd_dai_connect(rsnd_ssi_mod_get(priv
, 7), io
, RSND_MOD_SSIP
);
751 static int rsnd_ssi_pcm_new(struct rsnd_mod
*mod
,
752 struct rsnd_dai_stream
*io
,
753 struct snd_soc_pcm_runtime
*rtd
)
756 * rsnd_rdai_is_clk_master() will be enabled after set_fmt,
757 * and, pcm_new will be called after it.
758 * This function reuse pcm_new at this point.
760 rsnd_ssi_parent_attach(mod
, io
);
765 static int rsnd_ssi_common_probe(struct rsnd_mod
*mod
,
766 struct rsnd_dai_stream
*io
,
767 struct rsnd_priv
*priv
)
769 struct device
*dev
= rsnd_priv_to_dev(priv
);
770 struct rsnd_ssi
*ssi
= rsnd_mod_to_ssi(mod
);
774 * SSIP/SSIU/IRQ are not needed on
777 if (rsnd_ssi_is_multi_slave(mod
, io
))
781 * It can't judge ssi parent at this point
782 * see rsnd_ssi_pcm_new()
785 ret
= rsnd_ssiu_attach(io
, mod
);
790 * SSI might be called again as PIO fallback
791 * It is easy to manual handling for IRQ request/free
793 * OTOH, this function might be called many times if platform is
794 * using MIX. It needs xxx_attach() many times on xxx_probe().
795 * Because of it, we can't control .probe/.remove calling count by
797 * But it don't need to call request_irq() many times.
798 * Let's control it by RSND_SSI_PROBED flag.
800 if (!rsnd_ssi_flags_has(ssi
, RSND_SSI_PROBED
)) {
801 ret
= request_irq(ssi
->irq
,
806 rsnd_ssi_flags_set(ssi
, RSND_SSI_PROBED
);
812 static int rsnd_ssi_common_remove(struct rsnd_mod
*mod
,
813 struct rsnd_dai_stream
*io
,
814 struct rsnd_priv
*priv
)
816 struct rsnd_ssi
*ssi
= rsnd_mod_to_ssi(mod
);
817 struct rsnd_mod
*pure_ssi_mod
= rsnd_io_to_mod_ssi(io
);
819 /* Do nothing if non SSI (= SSI parent, multi SSI) mod */
820 if (pure_ssi_mod
!= mod
)
823 /* PIO will request IRQ again */
824 if (rsnd_ssi_flags_has(ssi
, RSND_SSI_PROBED
)) {
825 free_irq(ssi
->irq
, mod
);
827 rsnd_ssi_flags_del(ssi
, RSND_SSI_PROBED
);
833 static int rsnd_ssi_pointer(struct rsnd_mod
*mod
,
834 struct rsnd_dai_stream
*io
,
835 snd_pcm_uframes_t
*pointer
)
837 struct rsnd_ssi
*ssi
= rsnd_mod_to_ssi(mod
);
838 struct snd_pcm_runtime
*runtime
= rsnd_io_to_runtime(io
);
840 *pointer
= bytes_to_frames(runtime
, READ_ONCE(ssi
->byte_pos
));
845 static int rsnd_ssi_prepare(struct rsnd_mod
*mod
,
846 struct rsnd_dai_stream
*io
,
847 struct rsnd_priv
*priv
)
849 return rsnd_ssi_master_clk_start(mod
, io
);
852 static struct rsnd_mod_ops rsnd_ssi_pio_ops
= {
854 .probe
= rsnd_ssi_common_probe
,
855 .remove
= rsnd_ssi_common_remove
,
856 .init
= rsnd_ssi_init
,
857 .quit
= rsnd_ssi_quit
,
858 .start
= rsnd_ssi_start
,
859 .stop
= rsnd_ssi_stop
,
861 .pointer
= rsnd_ssi_pointer
,
862 .pcm_new
= rsnd_ssi_pcm_new
,
863 .hw_params
= rsnd_ssi_hw_params
,
864 .prepare
= rsnd_ssi_prepare
,
867 static int rsnd_ssi_dma_probe(struct rsnd_mod
*mod
,
868 struct rsnd_dai_stream
*io
,
869 struct rsnd_priv
*priv
)
871 struct rsnd_ssi
*ssi
= rsnd_mod_to_ssi(mod
);
875 * SSIP/SSIU/IRQ/DMA are not needed on
878 if (rsnd_ssi_is_multi_slave(mod
, io
))
881 ret
= rsnd_ssi_common_probe(mod
, io
, priv
);
885 /* SSI probe might be called many times in MUX multi path */
886 ret
= rsnd_dma_attach(io
, mod
, &ssi
->dma
);
891 static int rsnd_ssi_fallback(struct rsnd_mod
*mod
,
892 struct rsnd_dai_stream
*io
,
893 struct rsnd_priv
*priv
)
895 struct device
*dev
= rsnd_priv_to_dev(priv
);
900 * SSI .probe might be called again.
902 * rsnd_rdai_continuance_probe()
904 mod
->ops
= &rsnd_ssi_pio_ops
;
906 dev_info(dev
, "%s[%d] fallback to PIO mode\n",
907 rsnd_mod_name(mod
), rsnd_mod_id(mod
));
912 static struct dma_chan
*rsnd_ssi_dma_req(struct rsnd_dai_stream
*io
,
913 struct rsnd_mod
*mod
)
915 struct rsnd_priv
*priv
= rsnd_mod_to_priv(mod
);
916 int is_play
= rsnd_io_is_play(io
);
919 if (rsnd_ssi_use_busif(io
))
920 name
= is_play
? "rxu" : "txu";
922 name
= is_play
? "rx" : "tx";
924 return rsnd_dma_request_channel(rsnd_ssi_of_node(priv
),
928 static struct rsnd_mod_ops rsnd_ssi_dma_ops
= {
930 .dma_req
= rsnd_ssi_dma_req
,
931 .probe
= rsnd_ssi_dma_probe
,
932 .remove
= rsnd_ssi_common_remove
,
933 .init
= rsnd_ssi_init
,
934 .quit
= rsnd_ssi_quit
,
935 .start
= rsnd_ssi_start
,
936 .stop
= rsnd_ssi_stop
,
938 .pcm_new
= rsnd_ssi_pcm_new
,
939 .fallback
= rsnd_ssi_fallback
,
940 .hw_params
= rsnd_ssi_hw_params
,
941 .prepare
= rsnd_ssi_prepare
,
944 int rsnd_ssi_is_dma_mode(struct rsnd_mod
*mod
)
946 return mod
->ops
== &rsnd_ssi_dma_ops
;
953 static void rsnd_ssi_connect(struct rsnd_mod
*mod
,
954 struct rsnd_dai_stream
*io
)
956 struct rsnd_dai
*rdai
= rsnd_io_to_rdai(io
);
957 enum rsnd_mod_type types
[] = {
963 enum rsnd_mod_type type
;
966 /* try SSI -> SSIM1 -> SSIM2 -> SSIM3 */
967 for (i
= 0; i
< ARRAY_SIZE(types
); i
++) {
969 if (!rsnd_io_to_mod(io
, type
)) {
970 rsnd_dai_connect(mod
, io
, type
);
971 rsnd_rdai_channels_set(rdai
, (i
+ 1) * 2);
972 rsnd_rdai_ssi_lane_set(rdai
, (i
+ 1));
978 void rsnd_parse_connect_ssi(struct rsnd_dai
*rdai
,
979 struct device_node
*playback
,
980 struct device_node
*capture
)
982 struct rsnd_priv
*priv
= rsnd_rdai_to_priv(rdai
);
983 struct device_node
*node
;
984 struct device_node
*np
;
985 struct rsnd_mod
*mod
;
988 node
= rsnd_ssi_of_node(priv
);
993 for_each_child_of_node(node
, np
) {
994 mod
= rsnd_ssi_mod_get(priv
, i
);
996 rsnd_ssi_connect(mod
, &rdai
->playback
);
998 rsnd_ssi_connect(mod
, &rdai
->capture
);
1005 static void __rsnd_ssi_parse_hdmi_connection(struct rsnd_priv
*priv
,
1006 struct rsnd_dai_stream
*io
,
1007 struct device_node
*remote_ep
)
1009 struct device
*dev
= rsnd_priv_to_dev(priv
);
1010 struct rsnd_mod
*mod
= rsnd_io_to_mod_ssi(io
);
1011 struct rsnd_ssi
*ssi
;
1016 ssi
= rsnd_mod_to_ssi(mod
);
1018 if (strstr(remote_ep
->full_name
, "hdmi0")) {
1019 rsnd_ssi_flags_set(ssi
, RSND_SSI_HDMI0
);
1020 dev_dbg(dev
, "%s[%d] connected to HDMI0\n",
1021 rsnd_mod_name(mod
), rsnd_mod_id(mod
));
1024 if (strstr(remote_ep
->full_name
, "hdmi1")) {
1025 rsnd_ssi_flags_set(ssi
, RSND_SSI_HDMI1
);
1026 dev_dbg(dev
, "%s[%d] connected to HDMI1\n",
1027 rsnd_mod_name(mod
), rsnd_mod_id(mod
));
1031 void rsnd_ssi_parse_hdmi_connection(struct rsnd_priv
*priv
,
1032 struct device_node
*endpoint
,
1035 struct rsnd_dai
*rdai
= rsnd_rdai_get(priv
, dai_i
);
1036 struct device_node
*remote_ep
;
1038 remote_ep
= of_graph_get_remote_endpoint(endpoint
);
1042 __rsnd_ssi_parse_hdmi_connection(priv
, &rdai
->playback
, remote_ep
);
1043 __rsnd_ssi_parse_hdmi_connection(priv
, &rdai
->capture
, remote_ep
);
1046 struct rsnd_mod
*rsnd_ssi_mod_get(struct rsnd_priv
*priv
, int id
)
1048 if (WARN_ON(id
< 0 || id
>= rsnd_ssi_nr(priv
)))
1051 return rsnd_mod_get(rsnd_ssi_get(priv
, id
));
1054 int __rsnd_ssi_is_pin_sharing(struct rsnd_mod
*mod
)
1056 struct rsnd_ssi
*ssi
= rsnd_mod_to_ssi(mod
);
1058 return !!(rsnd_ssi_flags_has(ssi
, RSND_SSI_CLK_PIN_SHARE
));
1061 static u32
*rsnd_ssi_get_status(struct rsnd_dai_stream
*io
,
1062 struct rsnd_mod
*mod
,
1063 enum rsnd_mod_type type
)
1066 * SSIP (= SSI parent) needs to be special, otherwise,
1067 * 2nd SSI might doesn't start. see also rsnd_mod_call()
1069 * We can't include parent SSI status on SSI, because we don't know
1070 * how many SSI requests parent SSI. Thus, it is localed on "io" now.
1073 * Capture : SSI1 (needs SSI0)
1075 * 1) start Capture -> SSI0/SSI1 are started.
1076 * 2) start Playback -> SSI0 doesn't work, because it is already
1077 * marked as "started" on 1)
1079 * OTOH, using each mod's status is good for MUX case.
1080 * It doesn't need to start in 2nd start
1082 * IO-0: SRC0 -> CTU1 -+-> MUX -> DVC -> SSIU -> SSI0
1084 * IO-1: SRC1 -> CTU2 -+
1086 * 1) start IO-0 -> start SSI0
1087 * 2) start IO-1 -> SSI0 doesn't need to start, because it is
1088 * already started on 1)
1090 if (type
== RSND_MOD_SSIP
)
1091 return &io
->parent_ssi_status
;
1093 return rsnd_mod_get_status(io
, mod
, type
);
1096 int rsnd_ssi_probe(struct rsnd_priv
*priv
)
1098 struct device_node
*node
;
1099 struct device_node
*np
;
1100 struct device
*dev
= rsnd_priv_to_dev(priv
);
1101 struct rsnd_mod_ops
*ops
;
1103 struct rsnd_ssi
*ssi
;
1104 char name
[RSND_SSI_NAME_SIZE
];
1107 node
= rsnd_ssi_of_node(priv
);
1111 nr
= of_get_child_count(node
);
1114 goto rsnd_ssi_probe_done
;
1117 ssi
= devm_kzalloc(dev
, sizeof(*ssi
) * nr
, GFP_KERNEL
);
1120 goto rsnd_ssi_probe_done
;
1127 for_each_child_of_node(node
, np
) {
1128 ssi
= rsnd_ssi_get(priv
, i
);
1130 snprintf(name
, RSND_SSI_NAME_SIZE
, "%s.%d",
1133 clk
= devm_clk_get(dev
, name
);
1137 goto rsnd_ssi_probe_done
;
1140 if (of_get_property(np
, "shared-pin", NULL
))
1141 rsnd_ssi_flags_set(ssi
, RSND_SSI_CLK_PIN_SHARE
);
1143 if (of_get_property(np
, "no-busif", NULL
))
1144 rsnd_ssi_flags_set(ssi
, RSND_SSI_NO_BUSIF
);
1146 ssi
->irq
= irq_of_parse_and_map(np
, 0);
1150 goto rsnd_ssi_probe_done
;
1153 if (of_property_read_bool(np
, "pio-transfer"))
1154 ops
= &rsnd_ssi_pio_ops
;
1156 ops
= &rsnd_ssi_dma_ops
;
1158 ret
= rsnd_mod_init(priv
, rsnd_mod_get(ssi
), ops
, clk
,
1159 rsnd_ssi_get_status
, RSND_MOD_SSI
, i
);
1162 goto rsnd_ssi_probe_done
;
1170 rsnd_ssi_probe_done
:
1176 void rsnd_ssi_remove(struct rsnd_priv
*priv
)
1178 struct rsnd_ssi
*ssi
;
1181 for_each_rsnd_ssi(ssi
, priv
, i
) {
1182 rsnd_mod_quit(rsnd_mod_get(ssi
));