Lines Matching +full:ssi +full:- +full:all
1 // SPDX-License-Identifier: GPL-2.0
3 // Renesas RZ/G2L ASoC Serial Sound Interface (SSIF-2) Driver
28 /* SSI REGISTER BITS */
74 #define SSI_RATES SNDRV_PCM_RATE_8000_48000 /* 8k-44.1kHz */
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.
120 * So it is better to use as half-duplex (playing and recording
140 writel(data, (priv->base + reg)); in rz_ssi_reg_writel()
145 return readl(priv->base + reg); in rz_ssi_reg_readl()
153 val = readl(priv->base + reg); in rz_ssi_reg_mask_setl()
155 writel(val, (priv->base + reg)); in rz_ssi_reg_mask_setl()
166 static inline bool rz_ssi_stream_is_play(struct rz_ssi_priv *ssi, in rz_ssi_stream_is_play() argument
169 return substream->stream == SNDRV_PCM_STREAM_PLAYBACK; in rz_ssi_stream_is_play()
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()
177 if (substream->stream != SNDRV_PCM_STREAM_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()
195 strm->substream = substream; 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()
206 ret = strm->substream && strm->substream->runtime; in rz_ssi_stream_is_valid()
207 spin_unlock_irqrestore(&ssi->lock, flags); in rz_ssi_stream_is_valid()
215 struct snd_pcm_runtime *runtime = substream->runtime; in rz_ssi_stream_init()
218 strm->sample_width = samples_to_bytes(runtime, 1); in rz_ssi_stream_init()
219 strm->dma_buffer_pos = 0; in rz_ssi_stream_init()
220 strm->period_counter = 0; in rz_ssi_stream_init()
221 strm->buffer_pos = 0; in rz_ssi_stream_init()
223 strm->oerr_num = 0; in rz_ssi_stream_init()
224 strm->uerr_num = 0; in rz_ssi_stream_init()
225 strm->running = 0; in rz_ssi_stream_init()
228 strm->fifo_sample_size = SSI_FIFO_DEPTH; in rz_ssi_stream_init()
231 static void rz_ssi_stream_quit(struct rz_ssi_priv *ssi, in rz_ssi_stream_quit() argument
234 struct snd_soc_dai *dai = rz_ssi_get_dai(strm->substream); in rz_ssi_stream_quit()
238 if (strm->oerr_num > 0) in rz_ssi_stream_quit()
239 dev_info(dai->dev, "overrun = %d\n", strm->oerr_num); in rz_ssi_stream_quit()
241 if (strm->uerr_num > 0) in rz_ssi_stream_quit()
242 dev_info(dai->dev, "underrun = %d\n", strm->uerr_num); in rz_ssi_stream_quit()
245 static int rz_ssi_clk_setup(struct rz_ssi_priv *ssi, unsigned int rate, in rz_ssi_clk_setup() argument
249 6, 12, 24, 48, 96, -1, -1, -1 }; in rz_ssi_clk_setup()
258 rz_ssi_reg_writel(ssi, SSIFCR, 0); in rz_ssi_clk_setup()
261 rz_ssi_reg_writel(ssi, SSIOFR, SSIOFR_LRCONT); in rz_ssi_clk_setup()
262 if (ssi->audio_clk_1 && ssi->audio_clk_2) { in rz_ssi_clk_setup()
263 if (ssi->audio_clk_1 % bclk_rate) in rz_ssi_clk_setup()
264 ssi->audio_mck = ssi->audio_clk_2; in rz_ssi_clk_setup()
266 ssi->audio_mck = ssi->audio_clk_1; in rz_ssi_clk_setup()
271 if (ssi->audio_mck == ssi->audio_clk_1) in rz_ssi_clk_setup()
273 if (ssi->bckp_rise) in rz_ssi_clk_setup()
275 if (ssi->lrckp_fsync_fall) in rz_ssi_clk_setup()
280 div = ssi->audio_mck / bclk_rate; in rz_ssi_clk_setup()
290 dev_err(ssi->dev, "Rate not divisible by audio clock source\n"); in rz_ssi_clk_setup()
291 return -EINVAL; in rz_ssi_clk_setup()
300 rz_ssi_reg_writel(ssi, SSICR, ssicr); in rz_ssi_clk_setup()
301 rz_ssi_reg_writel(ssi, SSIFCR, in rz_ssi_clk_setup()
307 static int rz_ssi_start(struct rz_ssi_priv *ssi, struct rz_ssi_stream *strm) in rz_ssi_start() argument
309 bool is_play = rz_ssi_stream_is_play(ssi, strm->substream); in rz_ssi_start()
312 ssicr = rz_ssi_reg_readl(ssi, SSICR); in rz_ssi_start()
313 ssifcr = rz_ssi_reg_readl(ssi, SSIFCR) & ~0xF; in rz_ssi_start()
316 if (rz_ssi_is_dma_enabled(ssi)) in rz_ssi_start()
317 rz_ssi_reg_writel(ssi, SSISCR, 0); in rz_ssi_start()
319 rz_ssi_reg_writel(ssi, SSISCR, in rz_ssi_start()
320 SSISCR_TDES(strm->fifo_sample_size / 2 - 1) | in rz_ssi_start()
332 rz_ssi_reg_writel(ssi, SSICR, ssicr); in rz_ssi_start()
333 rz_ssi_reg_writel(ssi, SSIFCR, ssifcr); in rz_ssi_start()
335 /* Clear all error flags */ in rz_ssi_start()
336 rz_ssi_reg_mask_setl(ssi, SSISR, in rz_ssi_start()
340 strm->running = 1; in rz_ssi_start()
342 rz_ssi_reg_writel(ssi, SSICR, ssicr); in rz_ssi_start()
347 static int rz_ssi_stop(struct rz_ssi_priv *ssi, struct rz_ssi_stream *strm) in rz_ssi_stop() argument
351 strm->running = 0; in rz_ssi_stop()
354 rz_ssi_reg_mask_setl(ssi, SSICR, SSICR_TEN | SSICR_REN, 0); in rz_ssi_stop()
356 /* Cancel all remaining DMA transactions */ in rz_ssi_stop()
357 if (rz_ssi_is_dma_enabled(ssi)) in rz_ssi_stop()
358 dmaengine_terminate_async(strm->dma_ch); in rz_ssi_stop()
361 rz_ssi_reg_mask_setl(ssi, SSICR, SSICR_TUIEN | SSICR_TOIEN | in rz_ssi_stop()
363 rz_ssi_reg_mask_setl(ssi, SSIFCR, SSIFCR_TIE | SSIFCR_RIE, 0); in rz_ssi_stop()
365 /* Clear all error flags */ in rz_ssi_stop()
366 rz_ssi_reg_mask_setl(ssi, SSISR, in rz_ssi_stop()
372 while (--timeout) { in rz_ssi_stop()
373 if (rz_ssi_reg_readl(ssi, SSISR) & SSISR_IIRQ) in rz_ssi_stop()
379 dev_info(ssi->dev, "timeout waiting for SSI idle\n"); in rz_ssi_stop()
382 rz_ssi_reg_mask_setl(ssi, SSIFCR, 0, in rz_ssi_stop()
390 struct snd_pcm_substream *substream = strm->substream; in rz_ssi_pointer_update()
394 if (!strm->running || !substream || !substream->runtime) in rz_ssi_pointer_update()
397 runtime = substream->runtime; in rz_ssi_pointer_update()
398 strm->buffer_pos += frames; in rz_ssi_pointer_update()
399 WARN_ON(strm->buffer_pos > runtime->buffer_size); in rz_ssi_pointer_update()
402 if (strm->buffer_pos == runtime->buffer_size) in rz_ssi_pointer_update()
403 strm->buffer_pos = 0; in rz_ssi_pointer_update()
405 current_period = strm->buffer_pos / runtime->period_size; in rz_ssi_pointer_update()
406 if (strm->period_counter != current_period) { in rz_ssi_pointer_update()
407 snd_pcm_period_elapsed(strm->substream); in rz_ssi_pointer_update()
408 strm->period_counter = current_period; in rz_ssi_pointer_update()
412 static int rz_ssi_pio_recv(struct rz_ssi_priv *ssi, struct rz_ssi_stream *strm) in rz_ssi_pio_recv() argument
414 struct snd_pcm_substream *substream = strm->substream; in rz_ssi_pio_recv()
422 if (!rz_ssi_stream_is_valid(ssi, strm)) in rz_ssi_pio_recv()
423 return -EINVAL; in rz_ssi_pio_recv()
425 runtime = substream->runtime; in rz_ssi_pio_recv()
429 frames_left = runtime->period_size - in rz_ssi_pio_recv()
430 (strm->buffer_pos % runtime->period_size); in rz_ssi_pio_recv()
432 frames_left = runtime->period_size; in rz_ssi_pio_recv()
435 fifo_samples = (rz_ssi_reg_readl(ssi, SSIFSR) >> in rz_ssi_pio_recv()
440 while (frames_left && (fifo_samples >= runtime->channels)) { in rz_ssi_pio_recv()
441 samples += runtime->channels; in rz_ssi_pio_recv()
442 fifo_samples -= runtime->channels; in rz_ssi_pio_recv()
443 frames_left--; in rz_ssi_pio_recv()
451 buf = (u16 *)runtime->dma_area; in rz_ssi_pio_recv()
452 buf += strm->buffer_pos * runtime->channels; in rz_ssi_pio_recv()
454 /* Note, only supports 16-bit samples */ in rz_ssi_pio_recv()
456 *buf++ = (u16)(rz_ssi_reg_readl(ssi, SSIFRDR) >> 16); in rz_ssi_pio_recv()
458 rz_ssi_reg_mask_setl(ssi, SSIFSR, SSIFSR_RDF, 0); in rz_ssi_pio_recv()
459 rz_ssi_pointer_update(strm, samples / runtime->channels); in rz_ssi_pio_recv()
460 } while (!frames_left && fifo_samples >= runtime->channels); in rz_ssi_pio_recv()
465 static int rz_ssi_pio_send(struct rz_ssi_priv *ssi, struct rz_ssi_stream *strm) in rz_ssi_pio_send() argument
467 struct snd_pcm_substream *substream = strm->substream; in rz_ssi_pio_send()
468 struct snd_pcm_runtime *runtime = substream->runtime; in rz_ssi_pio_send()
476 if (!rz_ssi_stream_is_valid(ssi, strm)) in rz_ssi_pio_send()
477 return -EINVAL; in rz_ssi_pio_send()
480 frames_left = runtime->period_size - (strm->buffer_pos % in rz_ssi_pio_send()
481 runtime->period_size); in rz_ssi_pio_send()
483 frames_left = runtime->period_size; in rz_ssi_pio_send()
485 sample_space = strm->fifo_sample_size; in rz_ssi_pio_send()
486 ssifsr = rz_ssi_reg_readl(ssi, SSIFSR); in rz_ssi_pio_send()
487 sample_space -= (ssifsr >> SSIFSR_TDC_SHIFT) & SSIFSR_TDC_MASK; in rz_ssi_pio_send()
490 while (frames_left && (sample_space >= runtime->channels)) { in rz_ssi_pio_send()
491 samples += runtime->channels; in rz_ssi_pio_send()
492 sample_space -= runtime->channels; in rz_ssi_pio_send()
493 frames_left--; in rz_ssi_pio_send()
501 buf = (u16 *)(runtime->dma_area); in rz_ssi_pio_send()
502 buf += strm->buffer_pos * runtime->channels; in rz_ssi_pio_send()
504 /* Note, only supports 16-bit samples */ in rz_ssi_pio_send()
506 rz_ssi_reg_writel(ssi, SSIFTDR, ((u32)(*buf++) << 16)); in rz_ssi_pio_send()
508 rz_ssi_reg_mask_setl(ssi, SSIFSR, SSIFSR_TDE, 0); in rz_ssi_pio_send()
509 rz_ssi_pointer_update(strm, samples / runtime->channels); in rz_ssi_pio_send()
517 struct rz_ssi_priv *ssi = data; in rz_ssi_interrupt() local
518 u32 ssisr = rz_ssi_reg_readl(ssi, SSISR); in rz_ssi_interrupt()
520 if (ssi->playback.substream) in rz_ssi_interrupt()
521 strm = &ssi->playback; in rz_ssi_interrupt()
522 else if (ssi->capture.substream) in rz_ssi_interrupt()
523 strm = &ssi->capture; in rz_ssi_interrupt()
527 if (irq == ssi->irq_int) { /* error or idle */ in rz_ssi_interrupt()
529 strm->uerr_num++; in rz_ssi_interrupt()
531 strm->oerr_num++; in rz_ssi_interrupt()
533 strm->uerr_num++; in rz_ssi_interrupt()
535 strm->oerr_num++; in rz_ssi_interrupt()
541 rz_ssi_stop(ssi, strm); in rz_ssi_interrupt()
543 /* Clear all flags */ in rz_ssi_interrupt()
544 rz_ssi_reg_mask_setl(ssi, SSISR, SSISR_TOIRQ | in rz_ssi_interrupt()
549 strm->transfer(ssi, strm); in rz_ssi_interrupt()
552 rz_ssi_start(ssi, strm); in rz_ssi_interrupt()
556 if (!strm->running) in rz_ssi_interrupt()
560 if (irq == ssi->irq_tx) in rz_ssi_interrupt()
561 strm->transfer(ssi, &ssi->playback); in rz_ssi_interrupt()
564 if (irq == ssi->irq_rx) { in rz_ssi_interrupt()
565 strm->transfer(ssi, &ssi->capture); in rz_ssi_interrupt()
566 rz_ssi_reg_mask_setl(ssi, SSIFSR, SSIFSR_RDF, 0); in rz_ssi_interrupt()
569 if (irq == ssi->irq_rt) { in rz_ssi_interrupt()
570 struct snd_pcm_substream *substream = strm->substream; in rz_ssi_interrupt()
572 if (rz_ssi_stream_is_play(ssi, substream)) { in rz_ssi_interrupt()
573 strm->transfer(ssi, &ssi->playback); in rz_ssi_interrupt()
575 strm->transfer(ssi, &ssi->capture); in rz_ssi_interrupt()
576 rz_ssi_reg_mask_setl(ssi, SSIFSR, SSIFSR_RDF, 0); in rz_ssi_interrupt()
583 static int rz_ssi_dma_slave_config(struct rz_ssi_priv *ssi, in rz_ssi_dma_slave_config() argument
591 cfg.dst_addr = ssi->phys + SSIFTDR; in rz_ssi_dma_slave_config()
592 cfg.src_addr = ssi->phys + SSIFRDR; in rz_ssi_dma_slave_config()
599 static int rz_ssi_dma_transfer(struct rz_ssi_priv *ssi, in rz_ssi_dma_transfer() argument
602 struct snd_pcm_substream *substream = strm->substream; in rz_ssi_dma_transfer()
609 if (!rz_ssi_stream_is_valid(ssi, strm)) in rz_ssi_dma_transfer()
610 return -EINVAL; in rz_ssi_dma_transfer()
612 runtime = substream->runtime; in rz_ssi_dma_transfer()
613 if (runtime->state == SNDRV_PCM_STATE_DRAINING) in rz_ssi_dma_transfer()
621 dir = rz_ssi_stream_is_play(ssi, substream) ? DMA_MEM_TO_DEV : DMA_DEV_TO_MEM; in rz_ssi_dma_transfer()
624 amount = runtime->period_size; in rz_ssi_dma_transfer()
627 dma_paddr = runtime->dma_addr + frames_to_bytes(runtime, in rz_ssi_dma_transfer()
628 strm->dma_buffer_pos); in rz_ssi_dma_transfer()
630 desc = dmaengine_prep_slave_single(strm->dma_ch, dma_paddr, dma_size, in rz_ssi_dma_transfer()
634 dev_err(ssi->dev, "dmaengine_prep_slave_single() fail\n"); in rz_ssi_dma_transfer()
635 return -ENOMEM; in rz_ssi_dma_transfer()
638 desc->callback = rz_ssi_dma_complete; in rz_ssi_dma_transfer()
639 desc->callback_param = strm; in rz_ssi_dma_transfer()
642 dev_err(ssi->dev, "dmaengine_submit() fail\n"); in rz_ssi_dma_transfer()
643 return -EIO; in rz_ssi_dma_transfer()
647 strm->dma_buffer_pos += amount; in rz_ssi_dma_transfer()
648 if (strm->dma_buffer_pos >= runtime->buffer_size) in rz_ssi_dma_transfer()
649 strm->dma_buffer_pos = 0; in rz_ssi_dma_transfer()
652 dma_async_issue_pending(strm->dma_ch); in rz_ssi_dma_transfer()
661 if (!strm->running || !strm->substream || !strm->substream->runtime) in rz_ssi_dma_complete()
665 rz_ssi_pointer_update(strm, strm->substream->runtime->period_size); in rz_ssi_dma_complete()
668 rz_ssi_dma_transfer(strm->priv, strm); in rz_ssi_dma_complete()
671 static void rz_ssi_release_dma_channels(struct rz_ssi_priv *ssi) in rz_ssi_release_dma_channels() argument
673 if (ssi->playback.dma_ch) { in rz_ssi_release_dma_channels()
674 dma_release_channel(ssi->playback.dma_ch); in rz_ssi_release_dma_channels()
675 ssi->playback.dma_ch = NULL; in rz_ssi_release_dma_channels()
676 if (ssi->dma_rt) in rz_ssi_release_dma_channels()
677 ssi->dma_rt = false; in rz_ssi_release_dma_channels()
680 if (ssi->capture.dma_ch) { in rz_ssi_release_dma_channels()
681 dma_release_channel(ssi->capture.dma_ch); in rz_ssi_release_dma_channels()
682 ssi->capture.dma_ch = NULL; in rz_ssi_release_dma_channels()
686 static int rz_ssi_dma_request(struct rz_ssi_priv *ssi, struct device *dev) in rz_ssi_dma_request() argument
688 ssi->playback.dma_ch = dma_request_chan(dev, "tx"); in rz_ssi_dma_request()
689 if (IS_ERR(ssi->playback.dma_ch)) in rz_ssi_dma_request()
690 ssi->playback.dma_ch = NULL; in rz_ssi_dma_request()
692 ssi->capture.dma_ch = dma_request_chan(dev, "rx"); in rz_ssi_dma_request()
693 if (IS_ERR(ssi->capture.dma_ch)) in rz_ssi_dma_request()
694 ssi->capture.dma_ch = NULL; in rz_ssi_dma_request()
696 if (!ssi->playback.dma_ch && !ssi->capture.dma_ch) { in rz_ssi_dma_request()
697 ssi->playback.dma_ch = dma_request_chan(dev, "rt"); in rz_ssi_dma_request()
698 if (IS_ERR(ssi->playback.dma_ch)) { in rz_ssi_dma_request()
699 ssi->playback.dma_ch = NULL; in rz_ssi_dma_request()
703 ssi->dma_rt = true; in rz_ssi_dma_request()
706 if (!rz_ssi_is_dma_enabled(ssi)) in rz_ssi_dma_request()
709 if (ssi->playback.dma_ch && in rz_ssi_dma_request()
710 (rz_ssi_dma_slave_config(ssi, ssi->playback.dma_ch, true) < 0)) in rz_ssi_dma_request()
713 if (ssi->capture.dma_ch && in rz_ssi_dma_request()
714 (rz_ssi_dma_slave_config(ssi, ssi->capture.dma_ch, false) < 0)) in rz_ssi_dma_request()
720 rz_ssi_release_dma_channels(ssi); in rz_ssi_dma_request()
722 return -ENODEV; in rz_ssi_dma_request()
728 struct rz_ssi_priv *ssi = snd_soc_dai_get_drvdata(dai); in rz_ssi_dai_trigger() local
729 struct rz_ssi_stream *strm = rz_ssi_stream_get(ssi, substream); in rz_ssi_dai_trigger()
735 rz_ssi_reg_mask_setl(ssi, SSIFCR, 0, SSIFCR_SSIRST); in rz_ssi_dai_trigger()
736 rz_ssi_reg_mask_setl(ssi, SSIFCR, SSIFCR_SSIRST, 0); in rz_ssi_dai_trigger()
741 if (ssi->dma_rt) { in rz_ssi_dai_trigger()
744 is_playback = rz_ssi_stream_is_play(ssi, substream); in rz_ssi_dai_trigger()
745 ret = rz_ssi_dma_slave_config(ssi, ssi->playback.dma_ch, in rz_ssi_dai_trigger()
749 ssi->playback.transfer = rz_ssi_pio_send; in rz_ssi_dai_trigger()
750 ssi->capture.transfer = rz_ssi_pio_recv; in rz_ssi_dai_trigger()
751 rz_ssi_release_dma_channels(ssi); in rz_ssi_dai_trigger()
756 if (rz_ssi_is_dma_enabled(ssi)) in rz_ssi_dai_trigger()
760 ret = strm->transfer(ssi, strm); in rz_ssi_dai_trigger()
765 ret = rz_ssi_start(ssi, strm); in rz_ssi_dai_trigger()
768 rz_ssi_stop(ssi, strm); in rz_ssi_dai_trigger()
769 rz_ssi_stream_quit(ssi, strm); in rz_ssi_dai_trigger()
779 struct rz_ssi_priv *ssi = snd_soc_dai_get_drvdata(dai); in rz_ssi_dai_set_fmt() local
785 dev_err(ssi->dev, "Codec should be clk and frame consumer\n"); in rz_ssi_dai_set_fmt()
786 return -EINVAL; in rz_ssi_dai_set_fmt()
797 ssi->bckp_rise = false; in rz_ssi_dai_set_fmt()
798 ssi->lrckp_fsync_fall = false; in rz_ssi_dai_set_fmt()
801 ssi->bckp_rise = false; in rz_ssi_dai_set_fmt()
802 ssi->lrckp_fsync_fall = true; in rz_ssi_dai_set_fmt()
805 ssi->bckp_rise = true; in rz_ssi_dai_set_fmt()
806 ssi->lrckp_fsync_fall = false; in rz_ssi_dai_set_fmt()
809 ssi->bckp_rise = true; in rz_ssi_dai_set_fmt()
810 ssi->lrckp_fsync_fall = true; in rz_ssi_dai_set_fmt()
813 return -EINVAL; in rz_ssi_dai_set_fmt()
821 dev_err(ssi->dev, "Only I2S mode is supported.\n"); in rz_ssi_dai_set_fmt()
822 return -EINVAL; in rz_ssi_dai_set_fmt()
832 struct rz_ssi_priv *ssi = snd_soc_dai_get_drvdata(dai); in rz_ssi_dai_hw_params() local
834 SNDRV_PCM_HW_PARAM_SAMPLE_BITS)->min; in rz_ssi_dai_hw_params()
838 dev_err(ssi->dev, "Unsupported sample width: %d\n", in rz_ssi_dai_hw_params()
840 return -EINVAL; in rz_ssi_dai_hw_params()
844 dev_err(ssi->dev, "Number of channels not matched: %d\n", in rz_ssi_dai_hw_params()
846 return -EINVAL; in rz_ssi_dai_hw_params()
849 return rz_ssi_clk_setup(ssi, params_rate(params), in rz_ssi_dai_hw_params()
878 return snd_pcm_hw_constraint_integer(substream->runtime, in rz_ssi_pcm_open()
886 struct rz_ssi_priv *ssi = snd_soc_dai_get_drvdata(dai); in rz_ssi_pcm_pointer() local
887 struct rz_ssi_stream *strm = rz_ssi_stream_get(ssi, substream); in rz_ssi_pcm_pointer()
889 return strm->buffer_pos; in rz_ssi_pcm_pointer()
895 snd_pcm_set_managed_buffer_all(rtd->pcm, SNDRV_DMA_TYPE_DEV, in rz_ssi_pcm_new()
896 rtd->card->snd_card->dev, in rz_ssi_pcm_new()
903 .name = "rz-ssi-dai",
921 .name = "rz-ssi",
930 struct rz_ssi_priv *ssi; in rz_ssi_probe() local
935 ssi = devm_kzalloc(&pdev->dev, sizeof(*ssi), GFP_KERNEL); in rz_ssi_probe()
936 if (!ssi) in rz_ssi_probe()
937 return -ENOMEM; in rz_ssi_probe()
939 ssi->pdev = pdev; in rz_ssi_probe()
940 ssi->dev = &pdev->dev; in rz_ssi_probe()
941 ssi->base = devm_platform_get_and_ioremap_resource(pdev, 0, &res); in rz_ssi_probe()
942 if (IS_ERR(ssi->base)) in rz_ssi_probe()
943 return PTR_ERR(ssi->base); in rz_ssi_probe()
945 ssi->phys = res->start; in rz_ssi_probe()
946 ssi->clk = devm_clk_get(&pdev->dev, "ssi"); in rz_ssi_probe()
947 if (IS_ERR(ssi->clk)) in rz_ssi_probe()
948 return PTR_ERR(ssi->clk); in rz_ssi_probe()
950 ssi->sfr_clk = devm_clk_get(&pdev->dev, "ssi_sfr"); in rz_ssi_probe()
951 if (IS_ERR(ssi->sfr_clk)) in rz_ssi_probe()
952 return PTR_ERR(ssi->sfr_clk); in rz_ssi_probe()
954 audio_clk = devm_clk_get(&pdev->dev, "audio_clk1"); in rz_ssi_probe()
956 return dev_err_probe(&pdev->dev, PTR_ERR(audio_clk), in rz_ssi_probe()
959 ssi->audio_clk_1 = clk_get_rate(audio_clk); in rz_ssi_probe()
960 audio_clk = devm_clk_get(&pdev->dev, "audio_clk2"); in rz_ssi_probe()
962 return dev_err_probe(&pdev->dev, PTR_ERR(audio_clk), in rz_ssi_probe()
965 ssi->audio_clk_2 = clk_get_rate(audio_clk); in rz_ssi_probe()
966 if (!(ssi->audio_clk_1 || ssi->audio_clk_2)) in rz_ssi_probe()
967 return dev_err_probe(&pdev->dev, -EINVAL, in rz_ssi_probe()
970 ssi->audio_mck = ssi->audio_clk_1 ? ssi->audio_clk_1 : ssi->audio_clk_2; in rz_ssi_probe()
973 ret = rz_ssi_dma_request(ssi, &pdev->dev); in rz_ssi_probe()
975 dev_warn(&pdev->dev, "DMA not available, using PIO\n"); in rz_ssi_probe()
976 ssi->playback.transfer = rz_ssi_pio_send; in rz_ssi_probe()
977 ssi->capture.transfer = rz_ssi_pio_recv; in rz_ssi_probe()
979 dev_info(&pdev->dev, "DMA enabled"); in rz_ssi_probe()
980 ssi->playback.transfer = rz_ssi_dma_transfer; in rz_ssi_probe()
981 ssi->capture.transfer = rz_ssi_dma_transfer; in rz_ssi_probe()
984 ssi->playback.priv = ssi; in rz_ssi_probe()
985 ssi->capture.priv = ssi; in rz_ssi_probe()
987 spin_lock_init(&ssi->lock); in rz_ssi_probe()
988 dev_set_drvdata(&pdev->dev, ssi); in rz_ssi_probe()
991 ssi->irq_int = platform_get_irq_byname(pdev, "int_req"); in rz_ssi_probe()
992 if (ssi->irq_int < 0) { in rz_ssi_probe()
993 rz_ssi_release_dma_channels(ssi); in rz_ssi_probe()
994 return ssi->irq_int; in rz_ssi_probe()
997 ret = devm_request_irq(&pdev->dev, ssi->irq_int, &rz_ssi_interrupt, in rz_ssi_probe()
998 0, dev_name(&pdev->dev), ssi); in rz_ssi_probe()
1000 rz_ssi_release_dma_channels(ssi); in rz_ssi_probe()
1001 return dev_err_probe(&pdev->dev, ret, in rz_ssi_probe()
1005 if (!rz_ssi_is_dma_enabled(ssi)) { in rz_ssi_probe()
1007 ssi->irq_tx = platform_get_irq_byname(pdev, "dma_tx"); in rz_ssi_probe()
1008 ssi->irq_rx = platform_get_irq_byname(pdev, "dma_rx"); in rz_ssi_probe()
1009 if (ssi->irq_tx == -ENXIO && ssi->irq_rx == -ENXIO) { in rz_ssi_probe()
1010 ssi->irq_rt = platform_get_irq_byname(pdev, "dma_rt"); in rz_ssi_probe()
1011 if (ssi->irq_rt < 0) in rz_ssi_probe()
1012 return ssi->irq_rt; in rz_ssi_probe()
1014 ret = devm_request_irq(&pdev->dev, ssi->irq_rt, in rz_ssi_probe()
1016 dev_name(&pdev->dev), ssi); in rz_ssi_probe()
1018 return dev_err_probe(&pdev->dev, ret, in rz_ssi_probe()
1021 if (ssi->irq_tx < 0) in rz_ssi_probe()
1022 return ssi->irq_tx; in rz_ssi_probe()
1024 if (ssi->irq_rx < 0) in rz_ssi_probe()
1025 return ssi->irq_rx; in rz_ssi_probe()
1027 ret = devm_request_irq(&pdev->dev, ssi->irq_tx, in rz_ssi_probe()
1029 dev_name(&pdev->dev), ssi); in rz_ssi_probe()
1031 return dev_err_probe(&pdev->dev, ret, in rz_ssi_probe()
1034 ret = devm_request_irq(&pdev->dev, ssi->irq_rx, in rz_ssi_probe()
1036 dev_name(&pdev->dev), ssi); in rz_ssi_probe()
1038 return dev_err_probe(&pdev->dev, ret, in rz_ssi_probe()
1043 ssi->rstc = devm_reset_control_get_exclusive(&pdev->dev, NULL); in rz_ssi_probe()
1044 if (IS_ERR(ssi->rstc)) { in rz_ssi_probe()
1045 ret = PTR_ERR(ssi->rstc); in rz_ssi_probe()
1049 reset_control_deassert(ssi->rstc); in rz_ssi_probe()
1050 pm_runtime_enable(&pdev->dev); in rz_ssi_probe()
1051 ret = pm_runtime_resume_and_get(&pdev->dev); in rz_ssi_probe()
1053 dev_err(&pdev->dev, "pm_runtime_resume_and_get failed\n"); in rz_ssi_probe()
1057 ret = devm_snd_soc_register_component(&pdev->dev, &rz_ssi_soc_component, in rz_ssi_probe()
1061 dev_err(&pdev->dev, "failed to register snd component\n"); in rz_ssi_probe()
1068 pm_runtime_put(ssi->dev); in rz_ssi_probe()
1070 pm_runtime_disable(ssi->dev); in rz_ssi_probe()
1071 reset_control_assert(ssi->rstc); in rz_ssi_probe()
1073 rz_ssi_release_dma_channels(ssi); in rz_ssi_probe()
1080 struct rz_ssi_priv *ssi = dev_get_drvdata(&pdev->dev); in rz_ssi_remove() local
1082 rz_ssi_release_dma_channels(ssi); in rz_ssi_remove()
1084 pm_runtime_put(ssi->dev); in rz_ssi_remove()
1085 pm_runtime_disable(ssi->dev); in rz_ssi_remove()
1086 reset_control_assert(ssi->rstc); in rz_ssi_remove()
1090 { .compatible = "renesas,rz-ssi", },
1097 .name = "rz-ssi-pcm-audio",