Lines Matching +full:io +full:- +full:width

1 // SPDX-License-Identifier: GPL-2.0
3 // Renesas R-Car SSIU/SSI support
109 ((pos) = ((struct rsnd_ssi *)(priv)->ssi + i)); \
112 #define rsnd_ssi_get(priv, id) ((struct rsnd_ssi *)(priv->ssi) + id)
113 #define rsnd_ssi_nr(priv) ((priv)->ssi_nr)
115 #define rsnd_ssi_is_parent(ssi, io) ((ssi) == rsnd_io_to_mod_ssip(io)) argument
116 #define rsnd_ssi_is_multi_secondary(mod, io) \ argument
117 (rsnd_ssi_multi_secondaries(io) & (1 << rsnd_mod_id(mod)))
118 #define rsnd_ssi_is_run_mods(mod, io) \ argument
119 (rsnd_ssi_run_mods(io) & (1 << rsnd_mod_id(mod)))
122 int rsnd_ssi_use_busif(struct rsnd_dai_stream *io) in rsnd_ssi_use_busif() argument
124 struct rsnd_mod *mod = rsnd_io_to_mod_ssi(io); in rsnd_ssi_use_busif()
133 if (rsnd_io_to_mod_src(io)) in rsnd_ssi_use_busif()
168 static u32 rsnd_ssi_multi_secondaries(struct rsnd_dai_stream *io) in rsnd_ssi_multi_secondaries() argument
179 struct rsnd_mod *mod = rsnd_io_to_mod(io, types[i]); in rsnd_ssi_multi_secondaries()
190 static u32 rsnd_ssi_run_mods(struct rsnd_dai_stream *io) in rsnd_ssi_run_mods() argument
192 struct rsnd_mod *ssi_mod = rsnd_io_to_mod_ssi(io); in rsnd_ssi_run_mods()
193 struct rsnd_mod *ssi_parent_mod = rsnd_io_to_mod_ssip(io); in rsnd_ssi_run_mods()
196 mods = rsnd_ssi_multi_secondaries_runtime(io) | in rsnd_ssi_run_mods()
205 u32 rsnd_ssi_multi_secondaries_runtime(struct rsnd_dai_stream *io) in rsnd_ssi_multi_secondaries_runtime() argument
207 if (rsnd_runtime_is_multi_ssi(io)) in rsnd_ssi_multi_secondaries_runtime()
208 return rsnd_ssi_multi_secondaries(io); in rsnd_ssi_multi_secondaries_runtime()
217 int width = rsnd_rdai_width_get(rdai); in rsnd_rdai_width_to_swl() local
219 switch (width) { in rsnd_rdai_width_to_swl()
225 dev_err(dev, "unsupported slot width value: %d\n", width); in rsnd_rdai_width_to_swl()
238 int width = rsnd_rdai_width_get(rdai); in rsnd_ssi_clk_query() local
251 main_rate = width * param1 * param2 * ssi_clk_mul_table[j]; in rsnd_ssi_clk_query()
267 struct rsnd_dai_stream *io) in rsnd_ssi_master_clk_start() argument
269 struct rsnd_priv *priv = rsnd_io_to_priv(io); in rsnd_ssi_master_clk_start()
271 struct rsnd_dai *rdai = rsnd_io_to_rdai(io); in rsnd_ssi_master_clk_start()
273 int chan = rsnd_runtime_channel_for_ssi(io); in rsnd_ssi_master_clk_start()
276 unsigned int rate = rsnd_io_is_play(io) ? in rsnd_ssi_master_clk_start()
277 rsnd_src_get_out_rate(priv, io) : in rsnd_ssi_master_clk_start()
278 rsnd_src_get_in_rate(priv, io); in rsnd_ssi_master_clk_start()
286 if (rsnd_ssi_is_multi_secondary(mod, io)) in rsnd_ssi_master_clk_start()
289 if (rsnd_runtime_is_tdm_split(io)) in rsnd_ssi_master_clk_start()
290 chan = rsnd_io_converted_chan(io); in rsnd_ssi_master_clk_start()
294 if (ssi->usrcnt > 0) { in rsnd_ssi_master_clk_start()
295 if (ssi->rate != rate) { in rsnd_ssi_master_clk_start()
297 return -EINVAL; in rsnd_ssi_master_clk_start()
300 if (ssi->chan != chan) { in rsnd_ssi_master_clk_start()
302 return -EINVAL; in rsnd_ssi_master_clk_start()
308 ret = -EIO; in rsnd_ssi_master_clk_start()
327 ssi->cr_clk = FORCE | rsnd_rdai_width_to_swl(rdai) | in rsnd_ssi_master_clk_start()
329 ssi->wsr = CONT; in rsnd_ssi_master_clk_start()
330 ssi->rate = rate; in rsnd_ssi_master_clk_start()
331 ssi->chan = chan; in rsnd_ssi_master_clk_start()
344 struct rsnd_dai_stream *io) in rsnd_ssi_master_clk_stop() argument
346 struct rsnd_dai *rdai = rsnd_io_to_rdai(io); in rsnd_ssi_master_clk_stop()
355 if (ssi->usrcnt > 1) in rsnd_ssi_master_clk_stop()
358 ssi->cr_clk = 0; in rsnd_ssi_master_clk_stop()
359 ssi->rate = 0; in rsnd_ssi_master_clk_stop()
360 ssi->chan = 0; in rsnd_ssi_master_clk_stop()
366 struct rsnd_dai_stream *io) in rsnd_ssi_config_init() argument
368 struct rsnd_dai *rdai = rsnd_io_to_rdai(io); in rsnd_ssi_config_init()
371 struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io); in rsnd_ssi_config_init()
373 u32 cr_own = ssi->cr_own; in rsnd_ssi_config_init()
374 u32 cr_mode = ssi->cr_mode; in rsnd_ssi_config_init()
375 u32 wsr = ssi->wsr; in rsnd_ssi_config_init()
376 int width; in rsnd_ssi_config_init() local
379 is_tdm = rsnd_runtime_is_tdm(io); in rsnd_ssi_config_init()
380 is_tdm_split = rsnd_runtime_is_tdm_split(io); in rsnd_ssi_config_init()
389 if (rdai->bit_clk_inv) in rsnd_ssi_config_init()
391 if (rdai->frm_clk_inv && !is_tdm) in rsnd_ssi_config_init()
393 if (rdai->data_alignment) in rsnd_ssi_config_init()
395 if (rdai->sys_delay) in rsnd_ssi_config_init()
412 if (rsnd_ssi_is_parent(mod, io)) in rsnd_ssi_config_init()
415 if (rsnd_io_is_play(io)) in rsnd_ssi_config_init()
419 width = snd_pcm_format_width(runtime->format); in rsnd_ssi_config_init()
422 * The SWL and DWL bits in SSICR should be fixed at 32-bit in rsnd_ssi_config_init()
427 width = 32; in rsnd_ssi_config_init()
430 switch (width) { in rsnd_ssi_config_init()
453 ssi->cr_own = cr_own; in rsnd_ssi_config_init()
454 ssi->cr_mode = cr_mode; in rsnd_ssi_config_init()
455 ssi->wsr = wsr; in rsnd_ssi_config_init()
462 rsnd_mod_write(mod, SSIWSR, ssi->wsr); in rsnd_ssi_register_setup()
463 rsnd_mod_write(mod, SSICR, ssi->cr_own | in rsnd_ssi_register_setup()
464 ssi->cr_clk | in rsnd_ssi_register_setup()
465 ssi->cr_mode | in rsnd_ssi_register_setup()
466 ssi->cr_en); in rsnd_ssi_register_setup()
473 struct rsnd_dai_stream *io, in rsnd_ssi_init() argument
479 if (!rsnd_ssi_is_run_mods(mod, io)) in rsnd_ssi_init()
482 ret = rsnd_ssi_master_clk_start(mod, io); in rsnd_ssi_init()
486 ssi->usrcnt++; in rsnd_ssi_init()
492 rsnd_ssi_config_init(mod, io); in rsnd_ssi_init()
503 struct rsnd_dai_stream *io, in rsnd_ssi_quit() argument
509 if (!rsnd_ssi_is_run_mods(mod, io)) in rsnd_ssi_quit()
512 if (!ssi->usrcnt) { in rsnd_ssi_quit()
514 return -EIO; in rsnd_ssi_quit()
517 rsnd_ssi_master_clk_stop(mod, io); in rsnd_ssi_quit()
521 ssi->usrcnt--; in rsnd_ssi_quit()
523 if (!ssi->usrcnt) { in rsnd_ssi_quit()
524 ssi->cr_own = 0; in rsnd_ssi_quit()
525 ssi->cr_mode = 0; in rsnd_ssi_quit()
526 ssi->wsr = 0; in rsnd_ssi_quit()
533 struct rsnd_dai_stream *io, in rsnd_ssi_hw_params() argument
537 struct rsnd_dai *rdai = rsnd_io_to_rdai(io); in rsnd_ssi_hw_params()
540 if (fmt_width > rdai->chan_width) { in rsnd_ssi_hw_params()
541 struct rsnd_priv *priv = rsnd_io_to_priv(io); in rsnd_ssi_hw_params()
544 dev_err(dev, "invalid combination of slot-width and format-data-width\n"); in rsnd_ssi_hw_params()
545 return -EINVAL; in rsnd_ssi_hw_params()
552 struct rsnd_dai_stream *io, in rsnd_ssi_start() argument
557 if (!rsnd_ssi_is_run_mods(mod, io)) in rsnd_ssi_start()
564 if (rsnd_ssi_multi_secondaries_runtime(io)) in rsnd_ssi_start()
571 if (rsnd_ssi_is_parent(mod, io)) in rsnd_ssi_start()
574 ssi->cr_en = EN; in rsnd_ssi_start()
576 rsnd_mod_write(mod, SSICR, ssi->cr_own | in rsnd_ssi_start()
577 ssi->cr_clk | in rsnd_ssi_start()
578 ssi->cr_mode | in rsnd_ssi_start()
579 ssi->cr_en); in rsnd_ssi_start()
585 struct rsnd_dai_stream *io, in rsnd_ssi_stop() argument
591 if (!rsnd_ssi_is_run_mods(mod, io)) in rsnd_ssi_stop()
594 if (rsnd_ssi_is_parent(mod, io)) in rsnd_ssi_stop()
597 cr = ssi->cr_own | in rsnd_ssi_stop()
598 ssi->cr_clk; in rsnd_ssi_stop()
605 if (rsnd_io_is_play(io)) { in rsnd_ssi_stop()
606 rsnd_mod_write(mod, SSICR, cr | ssi->cr_en); in rsnd_ssi_stop()
610 /* In multi-SSI mode, stop is performed by setting ssi0129 in in rsnd_ssi_stop()
613 if (rsnd_ssi_multi_secondaries_runtime(io)) in rsnd_ssi_stop()
623 ssi->cr_en = 0; in rsnd_ssi_stop()
629 struct rsnd_dai_stream *io, in rsnd_ssi_irq() argument
637 is_tdm = rsnd_runtime_is_tdm(io); in rsnd_ssi_irq()
638 is_tdm_split = rsnd_runtime_is_tdm_split(io); in rsnd_ssi_irq()
643 if (rsnd_ssi_is_parent(mod, io)) in rsnd_ssi_irq()
646 if (!rsnd_ssi_is_run_mods(mod, io)) in rsnd_ssi_irq()
671 struct rsnd_dai_stream *io);
673 struct rsnd_dai_stream *io) in __rsnd_ssi_interrupt() argument
682 spin_lock(&priv->lock); in __rsnd_ssi_interrupt()
685 if (!rsnd_io_is_working(io)) in __rsnd_ssi_interrupt()
692 elapsed = rsnd_ssi_pio_interrupt(mod, io); in __rsnd_ssi_interrupt()
706 spin_unlock(&priv->lock); in __rsnd_ssi_interrupt()
709 snd_pcm_period_elapsed(io->substream); in __rsnd_ssi_interrupt()
712 snd_pcm_stop_xrun(io->substream); in __rsnd_ssi_interrupt()
726 struct rsnd_dai_stream *io, in rsnd_ssi_get_status() argument
734 * how many SSI requests parent SSI. Thus, it is localed on "io" now. in rsnd_ssi_get_status()
739 * 1) start Capture -> SSI0/SSI1 are started. in rsnd_ssi_get_status()
740 * 2) start Playback -> SSI0 doesn't work, because it is already in rsnd_ssi_get_status()
746 * IO-0: SRC0 -> CTU1 -+-> MUX -> DVC -> SSIU -> SSI0 in rsnd_ssi_get_status()
748 * IO-1: SRC1 -> CTU2 -+ in rsnd_ssi_get_status()
750 * 1) start IO-0 -> start SSI0 in rsnd_ssi_get_status()
751 * 2) start IO-1 -> SSI0 doesn't need to start, because it is in rsnd_ssi_get_status()
755 return &io->parent_ssi_status; in rsnd_ssi_get_status()
757 return rsnd_mod_get_status(mod, io, type); in rsnd_ssi_get_status()
764 struct rsnd_dai_stream *io) in rsnd_ssi_parent_attach() argument
766 struct rsnd_dai *rdai = rsnd_io_to_rdai(io); in rsnd_ssi_parent_attach()
775 if (rsnd_ssi_is_multi_secondary(mod, io)) in rsnd_ssi_parent_attach()
782 rsnd_dai_connect(rsnd_ssi_mod_get(priv, 0), io, RSND_MOD_SSIP); in rsnd_ssi_parent_attach()
785 rsnd_dai_connect(rsnd_ssi_mod_get(priv, 3), io, RSND_MOD_SSIP); in rsnd_ssi_parent_attach()
788 rsnd_dai_connect(rsnd_ssi_mod_get(priv, 7), io, RSND_MOD_SSIP); in rsnd_ssi_parent_attach()
794 struct rsnd_dai_stream *io, in rsnd_ssi_pcm_new() argument
802 rsnd_ssi_parent_attach(mod, io); in rsnd_ssi_pcm_new()
808 struct rsnd_dai_stream *io, in rsnd_ssi_common_probe() argument
819 if (rsnd_ssi_is_multi_secondary(mod, io)) in rsnd_ssi_common_probe()
834 * mod->status. in rsnd_ssi_common_probe()
839 ret = request_irq(ssi->irq, in rsnd_ssi_common_probe()
851 struct rsnd_dai_stream *io, in rsnd_ssi_common_remove() argument
855 struct rsnd_mod *pure_ssi_mod = rsnd_io_to_mod_ssi(io); in rsnd_ssi_common_remove()
863 free_irq(ssi->irq, mod); in rsnd_ssi_common_remove()
875 struct rsnd_dai_stream *io) in rsnd_ssi_pio_interrupt() argument
877 struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io); in rsnd_ssi_pio_interrupt()
879 u32 *buf = (u32 *)(runtime->dma_area + ssi->byte_pos); in rsnd_ssi_pio_interrupt()
884 if (snd_pcm_format_width(runtime->format) == 24) in rsnd_ssi_pio_interrupt()
892 if (rsnd_io_is_play(io)) in rsnd_ssi_pio_interrupt()
897 byte_pos = ssi->byte_pos + sizeof(*buf); in rsnd_ssi_pio_interrupt()
899 if (byte_pos >= ssi->next_period_byte) { in rsnd_ssi_pio_interrupt()
900 int period_pos = byte_pos / ssi->byte_per_period; in rsnd_ssi_pio_interrupt()
902 if (period_pos >= runtime->periods) { in rsnd_ssi_pio_interrupt()
907 ssi->next_period_byte = (period_pos + 1) * ssi->byte_per_period; in rsnd_ssi_pio_interrupt()
912 WRITE_ONCE(ssi->byte_pos, byte_pos); in rsnd_ssi_pio_interrupt()
918 struct rsnd_dai_stream *io, in rsnd_ssi_pio_init() argument
921 struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io); in rsnd_ssi_pio_init()
924 if (!rsnd_ssi_is_parent(mod, io)) { in rsnd_ssi_pio_init()
925 ssi->byte_pos = 0; in rsnd_ssi_pio_init()
926 ssi->byte_per_period = runtime->period_size * in rsnd_ssi_pio_init()
927 runtime->channels * in rsnd_ssi_pio_init()
929 ssi->next_period_byte = ssi->byte_per_period; in rsnd_ssi_pio_init()
932 return rsnd_ssi_init(mod, io, priv); in rsnd_ssi_pio_init()
936 struct rsnd_dai_stream *io, in rsnd_ssi_pio_pointer() argument
940 struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io); in rsnd_ssi_pio_pointer()
942 *pointer = bytes_to_frames(runtime, READ_ONCE(ssi->byte_pos)); in rsnd_ssi_pio_pointer()
963 struct rsnd_dai_stream *io, in rsnd_ssi_dma_probe() argument
972 if (rsnd_ssi_is_multi_secondary(mod, io)) in rsnd_ssi_dma_probe()
975 ret = rsnd_ssi_common_probe(mod, io, priv); in rsnd_ssi_dma_probe()
980 ret = rsnd_dma_attach(io, mod, &io->dma); in rsnd_ssi_dma_probe()
986 struct rsnd_dai_stream *io, in rsnd_ssi_fallback() argument
998 mod->ops = &rsnd_ssi_pio_ops; in rsnd_ssi_fallback()
1005 static struct dma_chan *rsnd_ssi_dma_req(struct rsnd_dai_stream *io, in rsnd_ssi_dma_req() argument
1009 int is_play = rsnd_io_is_play(io); in rsnd_ssi_dma_req()
1023 if (rsnd_ssi_use_busif(io)) in rsnd_ssi_dma_req()
1034 struct rsnd_dai_stream *io, in rsnd_ssi_debug_info() argument
1037 struct rsnd_dai *rdai = rsnd_io_to_rdai(io); in rsnd_ssi_debug_info()
1042 seq_printf(m, "bit_clk_inv: %d\n", rdai->bit_clk_inv); in rsnd_ssi_debug_info()
1043 seq_printf(m, "frm_clk_inv: %d\n", rdai->frm_clk_inv); in rsnd_ssi_debug_info()
1046 seq_printf(m, "multi secondary: %d\n", rsnd_ssi_is_multi_secondary(mod, io)); in rsnd_ssi_debug_info()
1047 seq_printf(m, "tdm: %d, %d\n", rsnd_runtime_is_tdm(io), in rsnd_ssi_debug_info()
1048 rsnd_runtime_is_tdm_split(io)); in rsnd_ssi_debug_info()
1049 seq_printf(m, "chan: %d\n", ssi->chan); in rsnd_ssi_debug_info()
1050 seq_printf(m, "user: %d\n", ssi->usrcnt); in rsnd_ssi_debug_info()
1079 return mod->ops == &rsnd_ssi_dma_ops; in rsnd_ssi_is_dma_mode()
1086 struct rsnd_dai_stream *io) in rsnd_ssi_connect() argument
1088 struct rsnd_dai *rdai = rsnd_io_to_rdai(io); in rsnd_ssi_connect()
1098 /* try SSI -> SSIM1 -> SSIM2 -> SSIM3 */ in rsnd_ssi_connect()
1101 if (!rsnd_io_to_mod(io, type)) { in rsnd_ssi_connect()
1102 rsnd_dai_connect(mod, io, type); in rsnd_ssi_connect()
1137 rsnd_ssi_connect(mod, &rdai->playback); in rsnd_parse_connect_ssi()
1139 rsnd_ssi_connect(mod, &rdai->capture); in rsnd_parse_connect_ssi()
1175 return -EINVAL; in rsnd_ssi_probe()
1179 ret = -EINVAL; in rsnd_ssi_probe()
1185 ret = -ENOMEM; in rsnd_ssi_probe()
1189 priv->ssi = ssi; in rsnd_ssi_probe()
1190 priv->ssi_nr = nr; in rsnd_ssi_probe()
1199 ret = -EINVAL; in rsnd_ssi_probe()
1216 if (of_property_read_bool(np, "shared-pin")) in rsnd_ssi_probe()
1219 if (of_property_read_bool(np, "no-busif")) in rsnd_ssi_probe()
1222 ssi->irq = irq_of_parse_and_map(np, 0); in rsnd_ssi_probe()
1223 if (!ssi->irq) { in rsnd_ssi_probe()
1224 ret = -EINVAL; in rsnd_ssi_probe()
1229 if (of_property_read_bool(np, "pio-transfer")) in rsnd_ssi_probe()