Lines Matching +full:ssi +full:-
1 // SPDX-License-Identifier: GPL-2.0
3 // Renesas R-Car SSIU/SSI support
13 * SSI interrupt status debug message when debugging
63 #define EN (1 << 0) /* SSI Module Enable */
79 #define SSI_NAME "ssi"
103 #define RSND_SSI_NO_BUSIF (1 << 1) /* SSI+DMA without BUSIF */
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))
125 struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
131 if (!(rsnd_flags_has(ssi, RSND_SSI_NO_BUSIF)))
272 struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
294 if (ssi->usrcnt > 0) {
295 if (ssi->rate != rate) {
296 dev_err(dev, "SSI parent/child should use same rate\n");
297 return -EINVAL;
300 if (ssi->chan != chan) {
301 dev_err(dev, "SSI parent/child should use same chan\n");
302 return -EINVAL;
308 ret = -EIO;
318 * SSI clock will be output contiguously
322 * for SSI parent
327 ssi->cr_clk = FORCE | rsnd_rdai_width_to_swl(rdai) |
329 ssi->wsr = CONT;
330 ssi->rate = rate;
331 ssi->chan = chan;
348 struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
356 if (ssi->usrcnt > 1)
359 ssi->cr_clk = 0;
360 ssi->rate = 0;
361 ssi->chan = 0;
373 struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
374 u32 cr_own = ssi->cr_own;
375 u32 cr_mode = ssi->cr_mode;
376 u32 wsr = ssi->wsr;
390 if (rdai->bit_clk_inv)
392 if (rdai->frm_clk_inv && !is_tdm)
394 if (rdai->data_alignment)
396 if (rdai->sys_delay)
420 width = snd_pcm_format_width(runtime->format);
423 * The SWL and DWL bits in SSICR should be fixed at 32-bit
454 ssi->cr_own = cr_own;
455 ssi->cr_mode = cr_mode;
456 ssi->wsr = wsr;
461 struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
463 rsnd_mod_write(mod, SSIWSR, ssi->wsr);
464 rsnd_mod_write(mod, SSICR, ssi->cr_own |
465 ssi->cr_clk |
466 ssi->cr_mode |
467 ssi->cr_en);
471 * SSI mod common functions
477 struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
487 ssi->usrcnt++;
507 struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
513 if (!ssi->usrcnt) {
515 return -EIO;
522 ssi->usrcnt--;
524 if (!ssi->usrcnt) {
525 ssi->cr_own = 0;
526 ssi->cr_mode = 0;
527 ssi->wsr = 0;
541 if (fmt_width > rdai->chan_width) {
545 dev_err(dev, "invalid combination of slot-width and format-data-width\n");
546 return -EINVAL;
556 struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
570 * SSI parent EN is not needed.
575 ssi->cr_en = EN;
577 rsnd_mod_write(mod, SSICR, ssi->cr_own |
578 ssi->cr_clk |
579 ssi->cr_mode |
580 ssi->cr_en);
589 struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
598 cr = ssi->cr_own |
599 ssi->cr_clk;
607 rsnd_mod_write(mod, SSICR, cr | ssi->cr_en);
611 /* In multi-SSI mode, stop is performed by setting ssi0129 in
618 * disable SSI,
624 ssi->cr_en = 0;
683 scoped_guard(spinlock, &priv->lock) {
709 snd_pcm_period_elapsed(io->substream);
712 snd_pcm_stop_xrun(io->substream);
730 * SSIP (= SSI parent) needs to be special, otherwise,
731 * 2nd SSI might doesn't start. see also rsnd_mod_call()
733 * We can't include parent SSI status on SSI, because we don't know
734 * how many SSI requests parent SSI. Thus, it is localed on "io" now.
739 * 1) start Capture -> SSI0/SSI1 are started.
740 * 2) start Playback -> SSI0 doesn't work, because it is already
746 * IO-0: SRC0 -> CTU1 -+-> MUX -> DVC -> SSIU -> SSI0
748 * IO-1: SRC1 -> CTU2 -+
750 * 1) start IO-0 -> start SSI0
751 * 2) start IO-1 -> SSI0 doesn't need to start, because it is
755 return &io->parent_ssi_status;
761 * SSI PIO
812 struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
817 * SSI Multi secondaries
823 * It can't judge ssi parent at this point
828 * SSI might be called again as PIO fallback
834 * mod->status.
838 if (!rsnd_flags_has(ssi, RSND_SSI_PROBED)) {
839 ret = request_irq(ssi->irq,
844 rsnd_flags_set(ssi, RSND_SSI_PROBED);
854 struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
857 /* Do nothing if non SSI (= SSI parent, multi SSI) mod */
862 if (rsnd_flags_has(ssi, RSND_SSI_PROBED)) {
863 free_irq(ssi->irq, mod);
865 rsnd_flags_del(ssi, RSND_SSI_PROBED);
872 * SSI PIO functions
878 struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
879 u32 *buf = (u32 *)(runtime->dma_area + ssi->byte_pos);
884 if (snd_pcm_format_width(runtime->format) == 24)
897 byte_pos = ssi->byte_pos + sizeof(*buf);
899 if (byte_pos >= ssi->next_period_byte) {
900 int period_pos = byte_pos / ssi->byte_per_period;
902 if (period_pos >= runtime->periods) {
907 ssi->next_period_byte = (period_pos + 1) * ssi->byte_per_period;
912 WRITE_ONCE(ssi->byte_pos, byte_pos);
922 struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
925 ssi->byte_pos = 0;
926 ssi->byte_per_period = runtime->period_size *
927 runtime->channels *
929 ssi->next_period_byte = ssi->byte_per_period;
939 struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
942 *pointer = bytes_to_frames(runtime, READ_ONCE(ssi->byte_pos));
970 * SSI Multi secondaries
979 /* SSI probe might be called many times in MUX multi path */
980 ret = rsnd_dma_attach(io, mod, &io->dma);
994 * SSI .probe might be called again.
998 mod->ops = &rsnd_ssi_pio_ops;
1017 * If not, "rcar_sound.ssi" will be used.
1038 struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
1042 seq_printf(m, "bit_clk_inv: %d\n", rdai->bit_clk_inv);
1043 seq_printf(m, "frm_clk_inv: %d\n", rdai->frm_clk_inv);
1049 seq_printf(m, "chan: %d\n", ssi->chan);
1050 seq_printf(m, "user: %d\n", ssi->usrcnt);
1079 return mod->ops == &rsnd_ssi_dma_ops;
1083 * ssi mod function
1098 /* try SSI -> SSIM1 -> SSIM2 -> SSIM3 */
1134 rsnd_ssi_connect(mod, &rdai->playback);
1136 rsnd_ssi_connect(mod, &rdai->capture);
1165 struct rsnd_ssi *ssi;
1171 return -EINVAL;
1175 ret = -EINVAL;
1179 ssi = devm_kcalloc(dev, nr, sizeof(*ssi), GFP_KERNEL);
1180 if (!ssi) {
1181 ret = -ENOMEM;
1185 priv->ssi = ssi;
1186 priv->ssi_nr = nr;
1195 ret = -EINVAL;
1199 ssi = rsnd_ssi_get(priv, i);
1210 if (of_property_read_bool(np, "shared-pin"))
1211 rsnd_flags_set(ssi, RSND_SSI_CLK_PIN_SHARE);
1213 if (of_property_read_bool(np, "no-busif"))
1214 rsnd_flags_set(ssi, RSND_SSI_NO_BUSIF);
1216 ssi->irq = irq_of_parse_and_map(np, 0);
1217 if (!ssi->irq) {
1218 ret = -EINVAL;
1222 if (of_property_read_bool(np, "pio-transfer"))
1227 ret = rsnd_mod_init(priv, rsnd_mod_get(ssi), ops, clk,
1246 struct rsnd_ssi *ssi;
1249 for_each_rsnd_ssi(ssi, priv, i) {
1250 rsnd_mod_quit(rsnd_mod_get(ssi));