Lines Matching +full:ssi +full:- +full:all
1 // SPDX-License-Identifier: GPL-2.0
3 // Renesas R-Car SSIU/SSI support
13 * SSI interrupt status debug message when debugging
61 #define EN (1 << 0) /* SSI Module Enable */
77 #define SSI_NAME "ssi"
101 #define RSND_SSI_NO_BUSIF (1 << 1) /* SSI+DMA without BUSIF */
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)
113 #define rsnd_ssi_is_parent(ssi, io) ((ssi) == rsnd_io_to_mod_ssip(io))
123 struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
129 if (!(rsnd_flags_has(ssi, RSND_SSI_NO_BUSIF)))
270 struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
292 if (ssi->usrcnt > 0) {
293 if (ssi->rate != rate) {
294 dev_err(dev, "SSI parent/child should use same rate\n");
295 return -EINVAL;
298 if (ssi->chan != chan) {
299 dev_err(dev, "SSI parent/child should use same chan\n");
300 return -EINVAL;
306 ret = -EIO;
316 * SSI clock will be output contiguously
320 * for SSI parent
325 ssi->cr_clk = FORCE | rsnd_rdai_width_to_swl(rdai) |
327 ssi->wsr = CONT;
328 ssi->rate = rate;
329 ssi->chan = chan;
346 struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
354 if (ssi->usrcnt > 1)
357 ssi->cr_clk = 0;
358 ssi->rate = 0;
359 ssi->chan = 0;
371 struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
372 u32 cr_own = ssi->cr_own;
373 u32 cr_mode = ssi->cr_mode;
374 u32 wsr = ssi->wsr;
388 if (rdai->bit_clk_inv)
390 if (rdai->frm_clk_inv && !is_tdm)
392 if (rdai->data_alignment)
394 if (rdai->sys_delay)
418 width = snd_pcm_format_width(runtime->format);
421 * The SWL and DWL bits in SSICR should be fixed at 32-bit
452 ssi->cr_own = cr_own;
453 ssi->cr_mode = cr_mode;
454 ssi->wsr = wsr;
459 struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
461 rsnd_mod_write(mod, SSIWSR, ssi->wsr);
462 rsnd_mod_write(mod, SSICR, ssi->cr_own |
463 ssi->cr_clk |
464 ssi->cr_mode |
465 ssi->cr_en);
469 * SSI mod common functions
475 struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
485 ssi->usrcnt++;
505 struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
511 if (!ssi->usrcnt) {
513 return -EIO;
520 ssi->usrcnt--;
522 if (!ssi->usrcnt) {
523 ssi->cr_own = 0;
524 ssi->cr_mode = 0;
525 ssi->wsr = 0;
539 if (fmt_width > rdai->chan_width) {
543 dev_err(dev, "invalid combination of slot-width and format-data-width\n");
544 return -EINVAL;
554 struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
568 * SSI parent EN is not needed.
573 ssi->cr_en = EN;
575 rsnd_mod_write(mod, SSICR, ssi->cr_own |
576 ssi->cr_clk |
577 ssi->cr_mode |
578 ssi->cr_en);
587 struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
596 cr = ssi->cr_own |
597 ssi->cr_clk;
600 * disable all IRQ,
601 * Playback: Wait all data was sent
605 rsnd_mod_write(mod, SSICR, cr | ssi->cr_en);
609 /* In multi-SSI mode, stop is performed by setting ssi0129 in
616 * disable SSI,
619 rsnd_mod_write(mod, SSICR, cr); /* disabled all */
622 ssi->cr_en = 0;
681 spin_lock(&priv->lock);
683 /* ignore all cases if not working */
705 spin_unlock(&priv->lock);
711 snd_pcm_stop_xrun(io->substream);
729 * SSIP (= SSI parent) needs to be special, otherwise,
730 * 2nd SSI might doesn't start. see also rsnd_mod_call()
732 * We can't include parent SSI status on SSI, because we don't know
733 * how many SSI requests parent SSI. Thus, it is localed on "io" now.
738 * 1) start Capture -> SSI0/SSI1 are started.
739 * 2) start Playback -> SSI0 doesn't work, because it is already
745 * IO-0: SRC0 -> CTU1 -+-> MUX -> DVC -> SSIU -> SSI0
747 * IO-1: SRC1 -> CTU2 -+
749 * 1) start IO-0 -> start SSI0
750 * 2) start IO-1 -> SSI0 doesn't need to start, because it is
754 return &io->parent_ssi_status;
760 * SSI PIO
811 struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
816 * SSI Multi secondaries
822 * It can't judge ssi parent at this point
827 * SSI might be called again as PIO fallback
833 * mod->status.
837 if (!rsnd_flags_has(ssi, RSND_SSI_PROBED)) {
838 ret = request_irq(ssi->irq,
843 rsnd_flags_set(ssi, RSND_SSI_PROBED);
853 struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
856 /* Do nothing if non SSI (= SSI parent, multi SSI) mod */
861 if (rsnd_flags_has(ssi, RSND_SSI_PROBED)) {
862 free_irq(ssi->irq, mod);
864 rsnd_flags_del(ssi, RSND_SSI_PROBED);
871 * SSI PIO functions
877 struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
878 u32 *buf = (u32 *)(runtime->dma_area + ssi->byte_pos);
883 if (snd_pcm_format_width(runtime->format) == 24)
896 byte_pos = ssi->byte_pos + sizeof(*buf);
898 if (byte_pos >= ssi->next_period_byte) {
899 int period_pos = byte_pos / ssi->byte_per_period;
901 if (period_pos >= runtime->periods) {
906 ssi->next_period_byte = (period_pos + 1) * ssi->byte_per_period;
911 WRITE_ONCE(ssi->byte_pos, byte_pos);
921 struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
924 ssi->byte_pos = 0;
925 ssi->byte_per_period = runtime->period_size *
926 runtime->channels *
928 ssi->next_period_byte = ssi->byte_per_period;
938 struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
941 *pointer = bytes_to_frames(runtime, READ_ONCE(ssi->byte_pos));
969 * SSI Multi secondaries
978 /* SSI probe might be called many times in MUX multi path */
979 ret = rsnd_dma_attach(io, mod, &io->dma);
993 * SSI .probe might be called again.
997 mod->ops = &rsnd_ssi_pio_ops;
1016 * If not, "rcar_sound.ssi" will be used.
1037 struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
1041 seq_printf(m, "bit_clk_inv: %d\n", rdai->bit_clk_inv);
1042 seq_printf(m, "frm_clk_inv: %d\n", rdai->frm_clk_inv);
1048 seq_printf(m, "chan: %d\n", ssi->chan);
1049 seq_printf(m, "user: %d\n", ssi->usrcnt);
1078 return mod->ops == &rsnd_ssi_dma_ops;
1082 * ssi mod function
1097 /* try SSI -> SSIM1 -> SSIM2 -> SSIM3 */
1136 rsnd_ssi_connect(mod, &rdai->playback);
1138 rsnd_ssi_connect(mod, &rdai->capture);
1168 struct rsnd_ssi *ssi;
1174 return -EINVAL;
1178 ret = -EINVAL;
1182 ssi = devm_kcalloc(dev, nr, sizeof(*ssi), GFP_KERNEL);
1183 if (!ssi) {
1184 ret = -ENOMEM;
1188 priv->ssi = ssi;
1189 priv->ssi_nr = nr;
1198 ret = -EINVAL;
1203 ssi = rsnd_ssi_get(priv, i);
1215 if (of_property_read_bool(np, "shared-pin"))
1216 rsnd_flags_set(ssi, RSND_SSI_CLK_PIN_SHARE);
1218 if (of_property_read_bool(np, "no-busif"))
1219 rsnd_flags_set(ssi, RSND_SSI_NO_BUSIF);
1221 ssi->irq = irq_of_parse_and_map(np, 0);
1222 if (!ssi->irq) {
1223 ret = -EINVAL;
1228 if (of_property_read_bool(np, "pio-transfer"))
1233 ret = rsnd_mod_init(priv, rsnd_mod_get(ssi), ops, clk,
1253 struct rsnd_ssi *ssi;
1256 for_each_rsnd_ssi(ssi, priv, i) {
1257 rsnd_mod_quit(rsnd_mod_get(ssi));