Lines Matching full:ssi
28 /* SSI REGISTER BITS */
85 int fifo_sample_size; /* sample capacity of SSI FIFO */
97 int (*transfer)(struct rz_ssi_priv *ssi, struct rz_ssi_stream *strm);
117 * The SSI supports full-duplex transmission and reception.
166 static inline bool rz_ssi_stream_is_play(struct rz_ssi_priv *ssi, in rz_ssi_stream_is_play() argument
173 rz_ssi_stream_get(struct rz_ssi_priv *ssi, struct snd_pcm_substream *substream) in rz_ssi_stream_get() argument
175 struct rz_ssi_stream *stream = &ssi->playback; in rz_ssi_stream_get()
178 stream = &ssi->capture; in rz_ssi_stream_get()
183 static inline bool rz_ssi_is_dma_enabled(struct rz_ssi_priv *ssi) in rz_ssi_is_dma_enabled() argument
185 return (ssi->playback.dma_ch && (ssi->dma_rt || ssi->capture.dma_ch)); in rz_ssi_is_dma_enabled()
191 struct rz_ssi_priv *ssi = strm->priv; in rz_ssi_set_substream() local
194 spin_lock_irqsave(&ssi->lock, flags); in rz_ssi_set_substream()
196 spin_unlock_irqrestore(&ssi->lock, flags); in rz_ssi_set_substream()
199 static bool rz_ssi_stream_is_valid(struct rz_ssi_priv *ssi, in rz_ssi_stream_is_valid() argument
205 spin_lock_irqsave(&ssi->lock, flags); in rz_ssi_stream_is_valid()
207 spin_unlock_irqrestore(&ssi->lock, flags); in rz_ssi_stream_is_valid()
231 static void rz_ssi_stream_quit(struct rz_ssi_priv *ssi, in rz_ssi_stream_quit() argument
245 static int rz_ssi_clk_setup(struct rz_ssi_priv *ssi, unsigned int rate, in rz_ssi_clk_setup() argument
257 rz_ssi_reg_writel(ssi, SSIFCR, 0); in rz_ssi_clk_setup()
260 rz_ssi_reg_writel(ssi, SSIOFR, SSIOFR_LRCONT); in rz_ssi_clk_setup()
261 if (ssi->audio_clk_1 && ssi->audio_clk_2) { in rz_ssi_clk_setup()
262 if (ssi->audio_clk_1 % bclk_rate) in rz_ssi_clk_setup()
263 ssi->audio_mck = ssi->audio_clk_2; in rz_ssi_clk_setup()
265 ssi->audio_mck = ssi->audio_clk_1; in rz_ssi_clk_setup()
270 if (ssi->audio_mck == ssi->audio_clk_1) in rz_ssi_clk_setup()
272 if (ssi->bckp_rise) in rz_ssi_clk_setup()
274 if (ssi->lrckp_fsync_fall) in rz_ssi_clk_setup()
279 div = ssi->audio_mck / bclk_rate; in rz_ssi_clk_setup()
289 dev_err(ssi->dev, "Rate not divisible by audio clock source\n"); in rz_ssi_clk_setup()
299 rz_ssi_reg_writel(ssi, SSICR, ssicr); in rz_ssi_clk_setup()
300 rz_ssi_reg_writel(ssi, SSIFCR, in rz_ssi_clk_setup()
306 static int rz_ssi_start(struct rz_ssi_priv *ssi, struct rz_ssi_stream *strm) in rz_ssi_start() argument
308 bool is_play = rz_ssi_stream_is_play(ssi, strm->substream); in rz_ssi_start()
311 ssicr = rz_ssi_reg_readl(ssi, SSICR); in rz_ssi_start()
312 ssifcr = rz_ssi_reg_readl(ssi, SSIFCR) & ~0xF; in rz_ssi_start()
315 if (rz_ssi_is_dma_enabled(ssi)) in rz_ssi_start()
316 rz_ssi_reg_writel(ssi, SSISCR, 0); in rz_ssi_start()
318 rz_ssi_reg_writel(ssi, SSISCR, in rz_ssi_start()
331 rz_ssi_reg_writel(ssi, SSICR, ssicr); in rz_ssi_start()
332 rz_ssi_reg_writel(ssi, SSIFCR, ssifcr); in rz_ssi_start()
335 rz_ssi_reg_mask_setl(ssi, SSISR, in rz_ssi_start()
341 rz_ssi_reg_writel(ssi, SSICR, ssicr); in rz_ssi_start()
346 static int rz_ssi_stop(struct rz_ssi_priv *ssi, struct rz_ssi_stream *strm) in rz_ssi_stop() argument
353 rz_ssi_reg_mask_setl(ssi, SSICR, SSICR_TEN | SSICR_REN, 0); in rz_ssi_stop()
356 if (rz_ssi_is_dma_enabled(ssi)) in rz_ssi_stop()
360 rz_ssi_reg_mask_setl(ssi, SSICR, SSICR_TUIEN | SSICR_TOIEN | in rz_ssi_stop()
362 rz_ssi_reg_mask_setl(ssi, SSIFCR, SSIFCR_TIE | SSIFCR_RIE, 0); in rz_ssi_stop()
365 rz_ssi_reg_mask_setl(ssi, SSISR, in rz_ssi_stop()
372 if (rz_ssi_reg_readl(ssi, SSISR) & SSISR_IIRQ) in rz_ssi_stop()
378 dev_info(ssi->dev, "timeout waiting for SSI idle\n"); in rz_ssi_stop()
381 rz_ssi_reg_mask_setl(ssi, SSIFCR, 0, in rz_ssi_stop()
411 static int rz_ssi_pio_recv(struct rz_ssi_priv *ssi, struct rz_ssi_stream *strm) in rz_ssi_pio_recv() argument
421 if (!rz_ssi_stream_is_valid(ssi, strm)) in rz_ssi_pio_recv()
434 fifo_samples = (rz_ssi_reg_readl(ssi, SSIFSR) >> in rz_ssi_pio_recv()
455 *buf++ = (u16)(rz_ssi_reg_readl(ssi, SSIFRDR) >> 16); in rz_ssi_pio_recv()
457 rz_ssi_reg_mask_setl(ssi, SSIFSR, SSIFSR_RDF, 0); in rz_ssi_pio_recv()
464 static int rz_ssi_pio_send(struct rz_ssi_priv *ssi, struct rz_ssi_stream *strm) in rz_ssi_pio_send() argument
475 if (!rz_ssi_stream_is_valid(ssi, strm)) in rz_ssi_pio_send()
485 ssifsr = rz_ssi_reg_readl(ssi, SSIFSR); in rz_ssi_pio_send()
507 rz_ssi_reg_writel(ssi, SSIFTDR, ((u32)(*buf++) << 16)); in rz_ssi_pio_send()
509 rz_ssi_reg_mask_setl(ssi, SSIFSR, SSIFSR_TDE, 0); in rz_ssi_pio_send()
518 struct rz_ssi_priv *ssi = data; in rz_ssi_interrupt() local
519 u32 ssisr = rz_ssi_reg_readl(ssi, SSISR); in rz_ssi_interrupt()
521 if (ssi->playback.substream) in rz_ssi_interrupt()
522 strm = &ssi->playback; in rz_ssi_interrupt()
523 else if (ssi->capture.substream) in rz_ssi_interrupt()
524 strm = &ssi->capture; in rz_ssi_interrupt()
528 if (irq == ssi->irq_int) { /* error or idle */ in rz_ssi_interrupt()
542 rz_ssi_stop(ssi, strm); in rz_ssi_interrupt()
545 rz_ssi_reg_mask_setl(ssi, SSISR, SSISR_TOIRQ | in rz_ssi_interrupt()
550 strm->transfer(ssi, strm); in rz_ssi_interrupt()
553 rz_ssi_start(ssi, strm); in rz_ssi_interrupt()
561 if (irq == ssi->irq_tx) in rz_ssi_interrupt()
562 strm->transfer(ssi, &ssi->playback); in rz_ssi_interrupt()
565 if (irq == ssi->irq_rx) { in rz_ssi_interrupt()
566 strm->transfer(ssi, &ssi->capture); in rz_ssi_interrupt()
567 rz_ssi_reg_mask_setl(ssi, SSIFSR, SSIFSR_RDF, 0); in rz_ssi_interrupt()
570 if (irq == ssi->irq_rt) { in rz_ssi_interrupt()
573 if (rz_ssi_stream_is_play(ssi, substream)) { in rz_ssi_interrupt()
574 strm->transfer(ssi, &ssi->playback); in rz_ssi_interrupt()
576 strm->transfer(ssi, &ssi->capture); in rz_ssi_interrupt()
577 rz_ssi_reg_mask_setl(ssi, SSIFSR, SSIFSR_RDF, 0); in rz_ssi_interrupt()
584 static int rz_ssi_dma_slave_config(struct rz_ssi_priv *ssi, in rz_ssi_dma_slave_config() argument
592 cfg.dst_addr = ssi->phys + SSIFTDR; in rz_ssi_dma_slave_config()
593 cfg.src_addr = ssi->phys + SSIFRDR; in rz_ssi_dma_slave_config()
600 static int rz_ssi_dma_transfer(struct rz_ssi_priv *ssi, in rz_ssi_dma_transfer() argument
610 if (!rz_ssi_stream_is_valid(ssi, strm)) in rz_ssi_dma_transfer()
622 dir = rz_ssi_stream_is_play(ssi, substream) ? DMA_MEM_TO_DEV : DMA_DEV_TO_MEM; in rz_ssi_dma_transfer()
635 dev_err(ssi->dev, "dmaengine_prep_slave_single() fail\n"); in rz_ssi_dma_transfer()
643 dev_err(ssi->dev, "dmaengine_submit() fail\n"); in rz_ssi_dma_transfer()
672 static void rz_ssi_release_dma_channels(struct rz_ssi_priv *ssi) in rz_ssi_release_dma_channels() argument
674 if (ssi->playback.dma_ch) { in rz_ssi_release_dma_channels()
675 dma_release_channel(ssi->playback.dma_ch); in rz_ssi_release_dma_channels()
676 ssi->playback.dma_ch = NULL; in rz_ssi_release_dma_channels()
677 if (ssi->dma_rt) in rz_ssi_release_dma_channels()
678 ssi->dma_rt = false; in rz_ssi_release_dma_channels()
681 if (ssi->capture.dma_ch) { in rz_ssi_release_dma_channels()
682 dma_release_channel(ssi->capture.dma_ch); in rz_ssi_release_dma_channels()
683 ssi->capture.dma_ch = NULL; in rz_ssi_release_dma_channels()
687 static int rz_ssi_dma_request(struct rz_ssi_priv *ssi, struct device *dev) in rz_ssi_dma_request() argument
689 ssi->playback.dma_ch = dma_request_chan(dev, "tx"); in rz_ssi_dma_request()
690 if (IS_ERR(ssi->playback.dma_ch)) in rz_ssi_dma_request()
691 ssi->playback.dma_ch = NULL; in rz_ssi_dma_request()
693 ssi->capture.dma_ch = dma_request_chan(dev, "rx"); in rz_ssi_dma_request()
694 if (IS_ERR(ssi->capture.dma_ch)) in rz_ssi_dma_request()
695 ssi->capture.dma_ch = NULL; in rz_ssi_dma_request()
697 if (!ssi->playback.dma_ch && !ssi->capture.dma_ch) { in rz_ssi_dma_request()
698 ssi->playback.dma_ch = dma_request_chan(dev, "rt"); in rz_ssi_dma_request()
699 if (IS_ERR(ssi->playback.dma_ch)) { in rz_ssi_dma_request()
700 ssi->playback.dma_ch = NULL; in rz_ssi_dma_request()
704 ssi->dma_rt = true; in rz_ssi_dma_request()
707 if (!rz_ssi_is_dma_enabled(ssi)) in rz_ssi_dma_request()
710 if (ssi->playback.dma_ch && in rz_ssi_dma_request()
711 (rz_ssi_dma_slave_config(ssi, ssi->playback.dma_ch, true) < 0)) in rz_ssi_dma_request()
714 if (ssi->capture.dma_ch && in rz_ssi_dma_request()
715 (rz_ssi_dma_slave_config(ssi, ssi->capture.dma_ch, false) < 0)) in rz_ssi_dma_request()
721 rz_ssi_release_dma_channels(ssi); in rz_ssi_dma_request()
729 struct rz_ssi_priv *ssi = snd_soc_dai_get_drvdata(dai); in rz_ssi_dai_trigger() local
730 struct rz_ssi_stream *strm = rz_ssi_stream_get(ssi, substream); in rz_ssi_dai_trigger()
736 rz_ssi_reg_mask_setl(ssi, SSIFCR, 0, SSIFCR_SSIRST); in rz_ssi_dai_trigger()
737 rz_ssi_reg_mask_setl(ssi, SSIFCR, SSIFCR_SSIRST, 0); in rz_ssi_dai_trigger()
742 if (ssi->dma_rt) { in rz_ssi_dai_trigger()
745 is_playback = rz_ssi_stream_is_play(ssi, substream); in rz_ssi_dai_trigger()
746 ret = rz_ssi_dma_slave_config(ssi, ssi->playback.dma_ch, in rz_ssi_dai_trigger()
750 ssi->playback.transfer = rz_ssi_pio_send; in rz_ssi_dai_trigger()
751 ssi->capture.transfer = rz_ssi_pio_recv; in rz_ssi_dai_trigger()
752 rz_ssi_release_dma_channels(ssi); in rz_ssi_dai_trigger()
757 if (rz_ssi_is_dma_enabled(ssi)) in rz_ssi_dai_trigger()
761 ret = strm->transfer(ssi, strm); in rz_ssi_dai_trigger()
766 ret = rz_ssi_start(ssi, strm); in rz_ssi_dai_trigger()
769 rz_ssi_stop(ssi, strm); in rz_ssi_dai_trigger()
770 rz_ssi_stream_quit(ssi, strm); in rz_ssi_dai_trigger()
780 struct rz_ssi_priv *ssi = snd_soc_dai_get_drvdata(dai); in rz_ssi_dai_set_fmt() local
786 dev_err(ssi->dev, "Codec should be clk and frame consumer\n"); in rz_ssi_dai_set_fmt()
798 ssi->bckp_rise = false; in rz_ssi_dai_set_fmt()
799 ssi->lrckp_fsync_fall = false; in rz_ssi_dai_set_fmt()
802 ssi->bckp_rise = false; in rz_ssi_dai_set_fmt()
803 ssi->lrckp_fsync_fall = true; in rz_ssi_dai_set_fmt()
806 ssi->bckp_rise = true; in rz_ssi_dai_set_fmt()
807 ssi->lrckp_fsync_fall = false; in rz_ssi_dai_set_fmt()
810 ssi->bckp_rise = true; in rz_ssi_dai_set_fmt()
811 ssi->lrckp_fsync_fall = true; in rz_ssi_dai_set_fmt()
822 dev_err(ssi->dev, "Only I2S mode is supported.\n"); in rz_ssi_dai_set_fmt()
833 struct rz_ssi_priv *ssi = snd_soc_dai_get_drvdata(dai); in rz_ssi_dai_hw_params() local
839 dev_err(ssi->dev, "Unsupported sample width: %d\n", in rz_ssi_dai_hw_params()
845 dev_err(ssi->dev, "Number of channels not matched: %d\n", in rz_ssi_dai_hw_params()
850 return rz_ssi_clk_setup(ssi, params_rate(params), in rz_ssi_dai_hw_params()
887 struct rz_ssi_priv *ssi = snd_soc_dai_get_drvdata(dai); in rz_ssi_pcm_pointer() local
888 struct rz_ssi_stream *strm = rz_ssi_stream_get(ssi, substream); in rz_ssi_pcm_pointer()
904 .name = "rz-ssi-dai",
922 .name = "rz-ssi",
931 struct rz_ssi_priv *ssi; in rz_ssi_probe() local
936 ssi = devm_kzalloc(&pdev->dev, sizeof(*ssi), GFP_KERNEL); in rz_ssi_probe()
937 if (!ssi) in rz_ssi_probe()
940 ssi->pdev = pdev; in rz_ssi_probe()
941 ssi->dev = &pdev->dev; in rz_ssi_probe()
942 ssi->base = devm_platform_get_and_ioremap_resource(pdev, 0, &res); in rz_ssi_probe()
943 if (IS_ERR(ssi->base)) in rz_ssi_probe()
944 return PTR_ERR(ssi->base); in rz_ssi_probe()
946 ssi->phys = res->start; in rz_ssi_probe()
947 ssi->clk = devm_clk_get(&pdev->dev, "ssi"); in rz_ssi_probe()
948 if (IS_ERR(ssi->clk)) in rz_ssi_probe()
949 return PTR_ERR(ssi->clk); in rz_ssi_probe()
951 ssi->sfr_clk = devm_clk_get(&pdev->dev, "ssi_sfr"); in rz_ssi_probe()
952 if (IS_ERR(ssi->sfr_clk)) in rz_ssi_probe()
953 return PTR_ERR(ssi->sfr_clk); in rz_ssi_probe()
960 ssi->audio_clk_1 = clk_get_rate(audio_clk); in rz_ssi_probe()
966 ssi->audio_clk_2 = clk_get_rate(audio_clk); in rz_ssi_probe()
967 if (!(ssi->audio_clk_1 || ssi->audio_clk_2)) in rz_ssi_probe()
971 ssi->audio_mck = ssi->audio_clk_1 ? ssi->audio_clk_1 : ssi->audio_clk_2; in rz_ssi_probe()
974 ret = rz_ssi_dma_request(ssi, &pdev->dev); in rz_ssi_probe()
977 ssi->playback.transfer = rz_ssi_pio_send; in rz_ssi_probe()
978 ssi->capture.transfer = rz_ssi_pio_recv; in rz_ssi_probe()
981 ssi->playback.transfer = rz_ssi_dma_transfer; in rz_ssi_probe()
982 ssi->capture.transfer = rz_ssi_dma_transfer; in rz_ssi_probe()
985 ssi->playback.priv = ssi; in rz_ssi_probe()
986 ssi->capture.priv = ssi; in rz_ssi_probe()
988 spin_lock_init(&ssi->lock); in rz_ssi_probe()
989 dev_set_drvdata(&pdev->dev, ssi); in rz_ssi_probe()
992 ssi->irq_int = platform_get_irq_byname(pdev, "int_req"); in rz_ssi_probe()
993 if (ssi->irq_int < 0) { in rz_ssi_probe()
994 rz_ssi_release_dma_channels(ssi); in rz_ssi_probe()
995 return ssi->irq_int; in rz_ssi_probe()
998 ret = devm_request_irq(&pdev->dev, ssi->irq_int, &rz_ssi_interrupt, in rz_ssi_probe()
999 0, dev_name(&pdev->dev), ssi); in rz_ssi_probe()
1001 rz_ssi_release_dma_channels(ssi); in rz_ssi_probe()
1006 if (!rz_ssi_is_dma_enabled(ssi)) { in rz_ssi_probe()
1008 ssi->irq_tx = platform_get_irq_byname(pdev, "dma_tx"); in rz_ssi_probe()
1009 ssi->irq_rx = platform_get_irq_byname(pdev, "dma_rx"); in rz_ssi_probe()
1010 if (ssi->irq_tx == -ENXIO && ssi->irq_rx == -ENXIO) { in rz_ssi_probe()
1011 ssi->irq_rt = platform_get_irq_byname(pdev, "dma_rt"); in rz_ssi_probe()
1012 if (ssi->irq_rt < 0) in rz_ssi_probe()
1013 return ssi->irq_rt; in rz_ssi_probe()
1015 ret = devm_request_irq(&pdev->dev, ssi->irq_rt, in rz_ssi_probe()
1017 dev_name(&pdev->dev), ssi); in rz_ssi_probe()
1022 if (ssi->irq_tx < 0) in rz_ssi_probe()
1023 return ssi->irq_tx; in rz_ssi_probe()
1025 if (ssi->irq_rx < 0) in rz_ssi_probe()
1026 return ssi->irq_rx; in rz_ssi_probe()
1028 ret = devm_request_irq(&pdev->dev, ssi->irq_tx, in rz_ssi_probe()
1030 dev_name(&pdev->dev), ssi); in rz_ssi_probe()
1035 ret = devm_request_irq(&pdev->dev, ssi->irq_rx, in rz_ssi_probe()
1037 dev_name(&pdev->dev), ssi); in rz_ssi_probe()
1044 ssi->rstc = devm_reset_control_get_exclusive(&pdev->dev, NULL); in rz_ssi_probe()
1045 if (IS_ERR(ssi->rstc)) { in rz_ssi_probe()
1046 ret = PTR_ERR(ssi->rstc); in rz_ssi_probe()
1050 reset_control_deassert(ssi->rstc); in rz_ssi_probe()
1069 pm_runtime_put(ssi->dev); in rz_ssi_probe()
1071 pm_runtime_disable(ssi->dev); in rz_ssi_probe()
1072 reset_control_assert(ssi->rstc); in rz_ssi_probe()
1074 rz_ssi_release_dma_channels(ssi); in rz_ssi_probe()
1081 struct rz_ssi_priv *ssi = dev_get_drvdata(&pdev->dev); in rz_ssi_remove() local
1083 rz_ssi_release_dma_channels(ssi); in rz_ssi_remove()
1085 pm_runtime_put(ssi->dev); in rz_ssi_remove()
1086 pm_runtime_disable(ssi->dev); in rz_ssi_remove()
1087 reset_control_assert(ssi->rstc); in rz_ssi_remove()
1091 { .compatible = "renesas,rz-ssi", },
1098 .name = "rz-ssi-pcm-audio",