Lines Matching +full:tdm +full:- +full:data +full:- +full:delay

1 // SPDX-License-Identifier: GPL-2.0-only
2 // ALSA SoC Audio Layer - Rockchip I2S/TDM Controller driver
5 // Author: Sugar Zhang <sugar.zhang@rock-chips.com>
9 #include <linux/clk-provider.h>
10 #include <linux/delay.h>
25 #define DRV_NAME "rockchip-i2s-tdm"
30 #define CLK_PPM_MIN -1000
117 clk_disable_unprepare(i2s_tdm->mclk_tx); in i2s_tdm_disable_unprepare_mclk()
118 clk_disable_unprepare(i2s_tdm->mclk_rx); in i2s_tdm_disable_unprepare_mclk()
119 if (i2s_tdm->mclk_calibrate) { in i2s_tdm_disable_unprepare_mclk()
120 clk_disable_unprepare(i2s_tdm->mclk_tx_src); in i2s_tdm_disable_unprepare_mclk()
121 clk_disable_unprepare(i2s_tdm->mclk_rx_src); in i2s_tdm_disable_unprepare_mclk()
122 clk_disable_unprepare(i2s_tdm->mclk_root0); in i2s_tdm_disable_unprepare_mclk()
123 clk_disable_unprepare(i2s_tdm->mclk_root1); in i2s_tdm_disable_unprepare_mclk()
128 * i2s_tdm_prepare_enable_mclk - prepare to enable all mclks, disable them on
141 ret = clk_prepare_enable(i2s_tdm->mclk_tx); in i2s_tdm_prepare_enable_mclk()
144 ret = clk_prepare_enable(i2s_tdm->mclk_rx); in i2s_tdm_prepare_enable_mclk()
147 if (i2s_tdm->mclk_calibrate) { in i2s_tdm_prepare_enable_mclk()
148 ret = clk_prepare_enable(i2s_tdm->mclk_tx_src); in i2s_tdm_prepare_enable_mclk()
151 ret = clk_prepare_enable(i2s_tdm->mclk_rx_src); in i2s_tdm_prepare_enable_mclk()
154 ret = clk_prepare_enable(i2s_tdm->mclk_root0); in i2s_tdm_prepare_enable_mclk()
157 ret = clk_prepare_enable(i2s_tdm->mclk_root1); in i2s_tdm_prepare_enable_mclk()
165 clk_disable_unprepare(i2s_tdm->mclk_root0); in i2s_tdm_prepare_enable_mclk()
167 clk_disable_unprepare(i2s_tdm->mclk_rx_src); in i2s_tdm_prepare_enable_mclk()
169 clk_disable_unprepare(i2s_tdm->mclk_tx_src); in i2s_tdm_prepare_enable_mclk()
171 clk_disable_unprepare(i2s_tdm->mclk_tx); in i2s_tdm_prepare_enable_mclk()
180 regcache_cache_only(i2s_tdm->regmap, true); in i2s_tdm_runtime_suspend()
183 clk_disable_unprepare(i2s_tdm->hclk); in i2s_tdm_runtime_suspend()
193 ret = clk_prepare_enable(i2s_tdm->hclk); in i2s_tdm_runtime_resume()
201 regcache_cache_only(i2s_tdm->regmap, false); in i2s_tdm_runtime_resume()
202 regcache_mark_dirty(i2s_tdm->regmap); in i2s_tdm_runtime_resume()
204 ret = regcache_sync(i2s_tdm->regmap); in i2s_tdm_runtime_resume()
213 clk_disable_unprepare(i2s_tdm->hclk); in i2s_tdm_runtime_resume()
229 /* This is technically race-y. in rockchip_snd_xfer_sync_reset()
247 reset_control_assert(i2s_tdm->tx_reset); in rockchip_snd_xfer_sync_reset()
248 reset_control_assert(i2s_tdm->rx_reset); in rockchip_snd_xfer_sync_reset()
250 reset_control_deassert(i2s_tdm->tx_reset); in rockchip_snd_xfer_sync_reset()
251 reset_control_deassert(i2s_tdm->rx_reset); in rockchip_snd_xfer_sync_reset()
285 regmap_update_bits(i2s_tdm->regmap, I2S_XFER, xfer_mask, xfer_val); in rockchip_snd_xfer_clear()
287 regmap_update_bits(i2s_tdm->regmap, I2S_CLR, clr, clr); in rockchip_snd_xfer_clear()
289 regmap_read(i2s_tdm->regmap, I2S_CLR, &val); in rockchip_snd_xfer_clear()
293 regmap_read(i2s_tdm->regmap, I2S_CLR, &val); in rockchip_snd_xfer_clear()
294 retry--; in rockchip_snd_xfer_clear()
296 dev_warn(i2s_tdm->dev, "clear failed, reset %s%s\n", in rockchip_snd_xfer_clear()
301 rockchip_snd_reset(i2s_tdm->tx_reset); in rockchip_snd_xfer_clear()
303 rockchip_snd_reset(i2s_tdm->rx_reset); in rockchip_snd_xfer_clear()
340 spin_lock_irqsave(&i2s_tdm->lock, flags); in rockchip_snd_txrxctrl()
342 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) in rockchip_snd_txrxctrl()
343 rockchip_enable_tde(i2s_tdm->regmap); in rockchip_snd_txrxctrl()
345 rockchip_enable_rde(i2s_tdm->regmap); in rockchip_snd_txrxctrl()
347 if (++i2s_tdm->refcount == 1) { in rockchip_snd_txrxctrl()
349 regmap_update_bits(i2s_tdm->regmap, I2S_XFER, in rockchip_snd_txrxctrl()
356 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) in rockchip_snd_txrxctrl()
357 rockchip_disable_tde(i2s_tdm->regmap); in rockchip_snd_txrxctrl()
359 rockchip_disable_rde(i2s_tdm->regmap); in rockchip_snd_txrxctrl()
361 if (--i2s_tdm->refcount == 0) { in rockchip_snd_txrxctrl()
366 spin_unlock_irqrestore(&i2s_tdm->lock, flags); in rockchip_snd_txrxctrl()
372 rockchip_enable_tde(i2s_tdm->regmap); in rockchip_snd_txctrl()
374 regmap_update_bits(i2s_tdm->regmap, I2S_XFER, in rockchip_snd_txctrl()
378 rockchip_disable_tde(i2s_tdm->regmap); in rockchip_snd_txctrl()
387 rockchip_enable_rde(i2s_tdm->regmap); in rockchip_snd_rxctrl()
389 regmap_update_bits(i2s_tdm->regmap, I2S_XFER, in rockchip_snd_rxctrl()
393 rockchip_disable_rde(i2s_tdm->regmap); in rockchip_snd_rxctrl()
405 bool is_tdm = i2s_tdm->tdm_mode; in rockchip_i2s_tdm_set_fmt()
407 ret = pm_runtime_resume_and_get(cpu_dai->dev); in rockchip_i2s_tdm_set_fmt()
408 if (ret < 0 && ret != -EACCES) in rockchip_i2s_tdm_set_fmt()
415 i2s_tdm->is_master_mode = true; in rockchip_i2s_tdm_set_fmt()
419 i2s_tdm->is_master_mode = false; in rockchip_i2s_tdm_set_fmt()
422 ret = -EINVAL; in rockchip_i2s_tdm_set_fmt()
426 regmap_update_bits(i2s_tdm->regmap, I2S_CKR, mask, val); in rockchip_i2s_tdm_set_fmt()
451 ret = -EINVAL; in rockchip_i2s_tdm_set_fmt()
455 regmap_update_bits(i2s_tdm->regmap, I2S_CKR, mask, val); in rockchip_i2s_tdm_set_fmt()
470 case SND_SOC_DAIFMT_DSP_A: /* PCM delay 1 mode */ in rockchip_i2s_tdm_set_fmt()
474 case SND_SOC_DAIFMT_DSP_B: /* PCM no delay mode */ in rockchip_i2s_tdm_set_fmt()
479 ret = -EINVAL; in rockchip_i2s_tdm_set_fmt()
484 regmap_update_bits(i2s_tdm->regmap, I2S_TXCR, mask, txcr_val); in rockchip_i2s_tdm_set_fmt()
487 regmap_update_bits(i2s_tdm->regmap, I2S_RXCR, mask, rxcr_val); in rockchip_i2s_tdm_set_fmt()
512 ret = -EINVAL; in rockchip_i2s_tdm_set_fmt()
520 regmap_update_bits(i2s_tdm->regmap, I2S_TXCR, mask, val); in rockchip_i2s_tdm_set_fmt()
521 regmap_update_bits(i2s_tdm->regmap, I2S_RXCR, mask, val); in rockchip_i2s_tdm_set_fmt()
525 regmap_update_bits(i2s_tdm->regmap, I2S_TDM_TXCR, in rockchip_i2s_tdm_set_fmt()
527 regmap_update_bits(i2s_tdm->regmap, I2S_TDM_RXCR, in rockchip_i2s_tdm_set_fmt()
532 pm_runtime_put(cpu_dai->dev); in rockchip_i2s_tdm_set_fmt()
542 stream = SNDRV_PCM_STREAM_LAST - substream->stream; in rockchip_i2s_tdm_xfer_pause()
544 rockchip_disable_tde(i2s_tdm->regmap); in rockchip_i2s_tdm_xfer_pause()
546 rockchip_disable_rde(i2s_tdm->regmap); in rockchip_i2s_tdm_xfer_pause()
556 stream = SNDRV_PCM_STREAM_LAST - substream->stream; in rockchip_i2s_tdm_xfer_resume()
558 rockchip_enable_tde(i2s_tdm->regmap); in rockchip_i2s_tdm_xfer_resume()
560 rockchip_enable_rde(i2s_tdm->regmap); in rockchip_i2s_tdm_xfer_resume()
562 regmap_update_bits(i2s_tdm->regmap, I2S_XFER, in rockchip_i2s_tdm_xfer_resume()
576 if (ppm == i2s_tdm->clk_ppm) in rockchip_i2s_tdm_clk_set_rate()
580 delta = -1; in rockchip_i2s_tdm_clk_set_rate()
590 return -EINVAL; in rockchip_i2s_tdm_clk_set_rate()
596 i2s_tdm->clk_ppm = ppm; in rockchip_i2s_tdm_clk_set_rate()
614 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) in rockchip_i2s_tdm_calibrate_mclk()
615 mclk_parent = i2s_tdm->mclk_tx_src; in rockchip_i2s_tdm_calibrate_mclk()
617 mclk_parent = i2s_tdm->mclk_rx_src; in rockchip_i2s_tdm_calibrate_mclk()
628 mclk_root = i2s_tdm->mclk_root0; in rockchip_i2s_tdm_calibrate_mclk()
629 mclk_root_freq = i2s_tdm->mclk_root0_freq; in rockchip_i2s_tdm_calibrate_mclk()
630 mclk_root_initial_freq = i2s_tdm->mclk_root0_initial_freq; in rockchip_i2s_tdm_calibrate_mclk()
638 mclk_root = i2s_tdm->mclk_root1; in rockchip_i2s_tdm_calibrate_mclk()
639 mclk_root_freq = i2s_tdm->mclk_root1_freq; in rockchip_i2s_tdm_calibrate_mclk()
640 mclk_root_initial_freq = i2s_tdm->mclk_root1_initial_freq; in rockchip_i2s_tdm_calibrate_mclk()
644 dev_err(i2s_tdm->dev, "Invalid LRCK frequency: %u Hz\n", in rockchip_i2s_tdm_calibrate_mclk()
646 return -EINVAL; in rockchip_i2s_tdm_calibrate_mclk()
658 delta = abs(mclk_root_freq % mclk_parent_freq - mclk_parent_freq); in rockchip_i2s_tdm_calibrate_mclk()
664 return -EINVAL; in rockchip_i2s_tdm_calibrate_mclk()
672 i2s_tdm->mclk_root0_freq = clk_get_rate(i2s_tdm->mclk_root0); in rockchip_i2s_tdm_calibrate_mclk()
673 i2s_tdm->mclk_root1_freq = clk_get_rate(i2s_tdm->mclk_root1); in rockchip_i2s_tdm_calibrate_mclk()
686 if (i2s_tdm->clk_trcm) { in rockchip_i2s_tdm_set_mclk()
687 if (i2s_tdm->mclk_tx_freq != i2s_tdm->mclk_rx_freq) { in rockchip_i2s_tdm_set_mclk()
688 dev_err(i2s_tdm->dev, in rockchip_i2s_tdm_set_mclk()
690 i2s_tdm->mclk_tx_freq, in rockchip_i2s_tdm_set_mclk()
691 i2s_tdm->mclk_rx_freq); in rockchip_i2s_tdm_set_mclk()
692 return -EINVAL; in rockchip_i2s_tdm_set_mclk()
695 ret = clk_set_rate(i2s_tdm->mclk_tx, i2s_tdm->mclk_tx_freq); in rockchip_i2s_tdm_set_mclk()
699 ret = clk_set_rate(i2s_tdm->mclk_rx, i2s_tdm->mclk_rx_freq); in rockchip_i2s_tdm_set_mclk()
704 *mclk = i2s_tdm->mclk_tx; in rockchip_i2s_tdm_set_mclk()
706 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { in rockchip_i2s_tdm_set_mclk()
707 *mclk = i2s_tdm->mclk_tx; in rockchip_i2s_tdm_set_mclk()
708 mclk_freq = i2s_tdm->mclk_tx_freq; in rockchip_i2s_tdm_set_mclk()
710 *mclk = i2s_tdm->mclk_rx; in rockchip_i2s_tdm_set_mclk()
711 mclk_freq = i2s_tdm->mclk_rx_freq; in rockchip_i2s_tdm_set_mclk()
756 if (!i2s_tdm->io_multiplex) in rockchip_i2s_io_multiplex()
759 if (substream->stream == SNDRV_PCM_STREAM_CAPTURE) { in rockchip_i2s_io_multiplex()
761 &substream->pcm->streams[SNDRV_PCM_STREAM_PLAYBACK]; in rockchip_i2s_io_multiplex()
763 if (playback_str->substream_opened) { in rockchip_i2s_io_multiplex()
764 regmap_read(i2s_tdm->regmap, I2S_TXCR, &val); in rockchip_i2s_io_multiplex()
766 usable_chs = MULTIPLEX_CH_MAX - to_ch_num(val); in rockchip_i2s_io_multiplex()
769 regmap_read(i2s_tdm->regmap, I2S_RXCR, &val); in rockchip_i2s_io_multiplex()
773 dev_err(i2s_tdm->dev, in rockchip_i2s_io_multiplex()
776 return -EINVAL; in rockchip_i2s_io_multiplex()
782 &substream->pcm->streams[SNDRV_PCM_STREAM_CAPTURE]; in rockchip_i2s_io_multiplex()
784 if (capture_str->substream_opened) { in rockchip_i2s_io_multiplex()
785 regmap_read(i2s_tdm->regmap, I2S_RXCR, &val); in rockchip_i2s_io_multiplex()
787 usable_chs = MULTIPLEX_CH_MAX - to_ch_num(val); in rockchip_i2s_io_multiplex()
790 regmap_read(i2s_tdm->regmap, I2S_TXCR, &val); in rockchip_i2s_io_multiplex()
794 dev_err(i2s_tdm->dev, in rockchip_i2s_io_multiplex()
797 return -EINVAL; in rockchip_i2s_io_multiplex()
801 val <<= i2s_tdm->soc_data->grf_shift; in rockchip_i2s_io_multiplex()
802 val |= (I2S_IO_DIRECTION_MASK << i2s_tdm->soc_data->grf_shift) << 16; in rockchip_i2s_io_multiplex()
803 regmap_write(i2s_tdm->grf, i2s_tdm->soc_data->grf_reg_offset, val); in rockchip_i2s_io_multiplex()
817 if (!i2s_tdm->clk_trcm) in rockchip_i2s_trcm_mode()
820 spin_lock_irqsave(&i2s_tdm->lock, flags); in rockchip_i2s_trcm_mode()
821 if (i2s_tdm->refcount) in rockchip_i2s_trcm_mode()
824 regmap_update_bits(i2s_tdm->regmap, I2S_CLKDIV, in rockchip_i2s_trcm_mode()
827 regmap_update_bits(i2s_tdm->regmap, I2S_CKR, in rockchip_i2s_trcm_mode()
831 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) in rockchip_i2s_trcm_mode()
832 regmap_update_bits(i2s_tdm->regmap, I2S_TXCR, in rockchip_i2s_trcm_mode()
836 regmap_update_bits(i2s_tdm->regmap, I2S_RXCR, in rockchip_i2s_trcm_mode()
840 if (i2s_tdm->refcount) in rockchip_i2s_trcm_mode()
842 spin_unlock_irqrestore(&i2s_tdm->lock, flags); in rockchip_i2s_trcm_mode()
857 if (i2s_tdm->is_master_mode) { in rockchip_i2s_tdm_hw_params()
858 if (i2s_tdm->mclk_calibrate) in rockchip_i2s_tdm_hw_params()
867 bclk_rate = i2s_tdm->frame_width * params_rate(params); in rockchip_i2s_tdm_hw_params()
869 return -EINVAL; in rockchip_i2s_tdm_hw_params()
892 return -EINVAL; in rockchip_i2s_tdm_hw_params()
909 return -EINVAL; in rockchip_i2s_tdm_hw_params()
912 if (i2s_tdm->clk_trcm) { in rockchip_i2s_tdm_hw_params()
914 } else if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { in rockchip_i2s_tdm_hw_params()
915 regmap_update_bits(i2s_tdm->regmap, I2S_CLKDIV, in rockchip_i2s_tdm_hw_params()
918 regmap_update_bits(i2s_tdm->regmap, I2S_CKR, in rockchip_i2s_tdm_hw_params()
921 regmap_update_bits(i2s_tdm->regmap, I2S_TXCR, in rockchip_i2s_tdm_hw_params()
925 regmap_update_bits(i2s_tdm->regmap, I2S_CLKDIV, in rockchip_i2s_tdm_hw_params()
928 regmap_update_bits(i2s_tdm->regmap, I2S_CKR, in rockchip_i2s_tdm_hw_params()
931 regmap_update_bits(i2s_tdm->regmap, I2S_RXCR, in rockchip_i2s_tdm_hw_params()
948 if (i2s_tdm->clk_trcm) in rockchip_i2s_tdm_trigger()
950 else if (substream->stream == SNDRV_PCM_STREAM_CAPTURE) in rockchip_i2s_tdm_trigger()
958 if (i2s_tdm->clk_trcm) in rockchip_i2s_tdm_trigger()
960 else if (substream->stream == SNDRV_PCM_STREAM_CAPTURE) in rockchip_i2s_tdm_trigger()
966 return -EINVAL; in rockchip_i2s_tdm_trigger()
978 if (i2s_tdm->clk_trcm) { in rockchip_i2s_tdm_set_sysclk()
979 i2s_tdm->mclk_tx_freq = freq; in rockchip_i2s_tdm_set_sysclk()
980 i2s_tdm->mclk_rx_freq = freq; in rockchip_i2s_tdm_set_sysclk()
983 i2s_tdm->mclk_tx_freq = freq; in rockchip_i2s_tdm_set_sysclk()
985 i2s_tdm->mclk_rx_freq = freq; in rockchip_i2s_tdm_set_sysclk()
988 dev_dbg(i2s_tdm->dev, "The target mclk_%s freq is: %d\n", in rockchip_i2s_tdm_set_sysclk()
997 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; in rockchip_i2s_tdm_clk_compensation_info()
998 uinfo->count = 1; in rockchip_i2s_tdm_clk_compensation_info()
999 uinfo->value.integer.min = CLK_PPM_MIN; in rockchip_i2s_tdm_clk_compensation_info()
1000 uinfo->value.integer.max = CLK_PPM_MAX; in rockchip_i2s_tdm_clk_compensation_info()
1001 uinfo->value.integer.step = 1; in rockchip_i2s_tdm_clk_compensation_info()
1012 ucontrol->value.integer.value[0] = i2s_tdm->clk_ppm; in rockchip_i2s_tdm_clk_compensation_get()
1026 if (ucontrol->value.integer.value[0] < CLK_PPM_MIN || in rockchip_i2s_tdm_clk_compensation_put()
1027 ucontrol->value.integer.value[0] > CLK_PPM_MAX) in rockchip_i2s_tdm_clk_compensation_put()
1028 return -EINVAL; in rockchip_i2s_tdm_clk_compensation_put()
1030 ppm = ucontrol->value.integer.value[0]; in rockchip_i2s_tdm_clk_compensation_put()
1032 old_rate = clk_get_rate(i2s_tdm->mclk_root0); in rockchip_i2s_tdm_clk_compensation_put()
1033 ret = rockchip_i2s_tdm_clk_set_rate(i2s_tdm, i2s_tdm->mclk_root0, in rockchip_i2s_tdm_clk_compensation_put()
1034 i2s_tdm->mclk_root0_freq, ppm); in rockchip_i2s_tdm_clk_compensation_put()
1037 if (old_rate != clk_get_rate(i2s_tdm->mclk_root0)) in rockchip_i2s_tdm_clk_compensation_put()
1040 if (clk_is_match(i2s_tdm->mclk_root0, i2s_tdm->mclk_root1)) in rockchip_i2s_tdm_clk_compensation_put()
1043 old_rate = clk_get_rate(i2s_tdm->mclk_root1); in rockchip_i2s_tdm_clk_compensation_put()
1044 ret = rockchip_i2s_tdm_clk_set_rate(i2s_tdm, i2s_tdm->mclk_root1, in rockchip_i2s_tdm_clk_compensation_put()
1045 i2s_tdm->mclk_root1_freq, ppm); in rockchip_i2s_tdm_clk_compensation_put()
1048 if (old_rate != clk_get_rate(i2s_tdm->mclk_root1)) in rockchip_i2s_tdm_clk_compensation_put()
1066 if (i2s_tdm->has_capture) in rockchip_i2s_tdm_dai_probe()
1067 dai->capture_dma_data = &i2s_tdm->capture_dma_data; in rockchip_i2s_tdm_dai_probe()
1068 if (i2s_tdm->has_playback) in rockchip_i2s_tdm_dai_probe()
1069 dai->playback_dma_data = &i2s_tdm->playback_dma_data; in rockchip_i2s_tdm_dai_probe()
1071 if (i2s_tdm->mclk_calibrate) in rockchip_i2s_tdm_dai_probe()
1084 i2s_tdm->tdm_mode = true; in rockchip_dai_tdm_slot()
1085 i2s_tdm->frame_width = slots * slot_width; in rockchip_dai_tdm_slot()
1089 regmap_update_bits(i2s_tdm->regmap, I2S_TDM_TXCR, in rockchip_dai_tdm_slot()
1091 regmap_update_bits(i2s_tdm->regmap, I2S_TDM_RXCR, in rockchip_dai_tdm_slot()
1103 return -EINVAL; in rockchip_i2s_tdm_set_bclk_ratio()
1105 i2s_tdm->frame_width = ratio; in rockchip_i2s_tdm_set_bclk_ratio()
1218 const struct txrx_config *configs = i2s_tdm->soc_data->configs; in common_soc_init()
1219 u32 reg = 0, val = 0, trcm = i2s_tdm->clk_trcm; in common_soc_init()
1225 for (i = 0; i < i2s_tdm->soc_data->config_count; i++) { in common_soc_init()
1235 regmap_write(i2s_tdm->grf, reg, val); in common_soc_init()
1305 { .compatible = "rockchip,px30-i2s-tdm", .data = &px30_i2s_soc_data },
1306 { .compatible = "rockchip,rk1808-i2s-tdm", .data = &rk1808_i2s_soc_data },
1307 { .compatible = "rockchip,rk3308-i2s-tdm", .data = &rk3308_i2s_soc_data },
1308 { .compatible = "rockchip,rk3568-i2s-tdm", .data = &rk3568_i2s_soc_data },
1309 { .compatible = "rockchip,rv1126-i2s-tdm", .data = &rv1126_i2s_soc_data },
1326 struct device_node *node = i2s_tdm->dev->of_node; in rockchip_i2s_tdm_init_dai()
1328 of_property_for_each_string(node, "dma-names", dma_names, dma_name) { in rockchip_i2s_tdm_init_dai()
1330 i2s_tdm->has_playback = true; in rockchip_i2s_tdm_init_dai()
1332 i2s_tdm->has_capture = true; in rockchip_i2s_tdm_init_dai()
1335 dai = devm_kmemdup(i2s_tdm->dev, &i2s_tdm_dai, in rockchip_i2s_tdm_init_dai()
1338 return -ENOMEM; in rockchip_i2s_tdm_init_dai()
1340 if (i2s_tdm->has_playback) { in rockchip_i2s_tdm_init_dai()
1341 dai->playback.stream_name = "Playback"; in rockchip_i2s_tdm_init_dai()
1342 dai->playback.channels_min = 2; in rockchip_i2s_tdm_init_dai()
1343 dai->playback.channels_max = 8; in rockchip_i2s_tdm_init_dai()
1344 dai->playback.rates = SNDRV_PCM_RATE_8000_192000; in rockchip_i2s_tdm_init_dai()
1345 dai->playback.formats = formats; in rockchip_i2s_tdm_init_dai()
1348 if (i2s_tdm->has_capture) { in rockchip_i2s_tdm_init_dai()
1349 dai->capture.stream_name = "Capture"; in rockchip_i2s_tdm_init_dai()
1350 dai->capture.channels_min = 2; in rockchip_i2s_tdm_init_dai()
1351 dai->capture.channels_max = 8; in rockchip_i2s_tdm_init_dai()
1352 dai->capture.rates = SNDRV_PCM_RATE_8000_192000; in rockchip_i2s_tdm_init_dai()
1353 dai->capture.formats = formats; in rockchip_i2s_tdm_init_dai()
1356 if (i2s_tdm->clk_trcm != TRCM_TXRX) in rockchip_i2s_tdm_init_dai()
1357 dai->symmetric_rate = 1; in rockchip_i2s_tdm_init_dai()
1359 i2s_tdm->dai = dai; in rockchip_i2s_tdm_init_dai()
1372 i2s_data = i2s_tdm->i2s_sdis; in rockchip_i2s_tdm_path_check()
1374 i2s_data = i2s_tdm->i2s_sdos; in rockchip_i2s_tdm_path_check()
1377 if (i2s_data[i] > CH_GRP_MAX - 1) { in rockchip_i2s_tdm_path_check()
1378 dev_err(i2s_tdm->dev, in rockchip_i2s_tdm_path_check()
1382 return -EINVAL; in rockchip_i2s_tdm_path_check()
1390 dev_err(i2s_tdm->dev, in rockchip_i2s_tdm_path_check()
1395 return -EINVAL; in rockchip_i2s_tdm_path_check()
1409 regmap_update_bits(i2s_tdm->regmap, I2S_TXCR, in rockchip_i2s_tdm_tx_path_config()
1411 I2S_TXCR_PATH(idx, i2s_tdm->i2s_sdos[idx])); in rockchip_i2s_tdm_tx_path_config()
1421 regmap_update_bits(i2s_tdm->regmap, I2S_RXCR, in rockchip_i2s_tdm_rx_path_config()
1423 I2S_RXCR_PATH(idx, i2s_tdm->i2s_sdis[idx])); in rockchip_i2s_tdm_rx_path_config()
1440 i2s_tdm->mclk_tx_src = devm_clk_get(i2s_tdm->dev, "mclk_tx_src"); in rockchip_i2s_tdm_get_calibrate_mclks()
1441 if (!IS_ERR(i2s_tdm->mclk_tx_src)) in rockchip_i2s_tdm_get_calibrate_mclks()
1444 i2s_tdm->mclk_rx_src = devm_clk_get(i2s_tdm->dev, "mclk_rx_src"); in rockchip_i2s_tdm_get_calibrate_mclks()
1445 if (!IS_ERR(i2s_tdm->mclk_rx_src)) in rockchip_i2s_tdm_get_calibrate_mclks()
1448 i2s_tdm->mclk_root0 = devm_clk_get(i2s_tdm->dev, "mclk_root0"); in rockchip_i2s_tdm_get_calibrate_mclks()
1449 if (!IS_ERR(i2s_tdm->mclk_root0)) in rockchip_i2s_tdm_get_calibrate_mclks()
1452 i2s_tdm->mclk_root1 = devm_clk_get(i2s_tdm->dev, "mclk_root1"); in rockchip_i2s_tdm_get_calibrate_mclks()
1453 if (!IS_ERR(i2s_tdm->mclk_root1)) in rockchip_i2s_tdm_get_calibrate_mclks()
1457 return -ENOENT; in rockchip_i2s_tdm_get_calibrate_mclks()
1460 i2s_tdm->mclk_calibrate = 1; in rockchip_i2s_tdm_get_calibrate_mclks()
1469 char *i2s_tx_path_prop = "rockchip,i2s-tx-route"; in rockchip_i2s_tdm_path_prepare()
1470 char *i2s_rx_path_prop = "rockchip,i2s-rx-route"; in rockchip_i2s_tdm_path_prepare()
1477 i2s_data = i2s_tdm->i2s_sdis; in rockchip_i2s_tdm_path_prepare()
1480 i2s_data = i2s_tdm->i2s_sdos; in rockchip_i2s_tdm_path_prepare()
1485 if (num != -ENOENT) { in rockchip_i2s_tdm_path_prepare()
1486 dev_err(i2s_tdm->dev, in rockchip_i2s_tdm_path_prepare()
1493 dev_err(i2s_tdm->dev, in rockchip_i2s_tdm_path_prepare()
1495 return -EINVAL; in rockchip_i2s_tdm_path_prepare()
1501 dev_err(i2s_tdm->dev, in rockchip_i2s_tdm_path_prepare()
1509 dev_err(i2s_tdm->dev, in rockchip_i2s_tdm_path_prepare()
1510 "Failed to check i2s data bus: %d\n", ret); in rockchip_i2s_tdm_path_prepare()
1533 struct device_node *node = pdev->dev.of_node; in rockchip_i2s_tdm_probe()
1540 i2s_tdm = devm_kzalloc(&pdev->dev, sizeof(*i2s_tdm), GFP_KERNEL); in rockchip_i2s_tdm_probe()
1542 return -ENOMEM; in rockchip_i2s_tdm_probe()
1544 i2s_tdm->dev = &pdev->dev; in rockchip_i2s_tdm_probe()
1546 of_id = of_match_device(rockchip_i2s_tdm_match, &pdev->dev); in rockchip_i2s_tdm_probe()
1547 if (!of_id || !of_id->data) in rockchip_i2s_tdm_probe()
1548 return -EINVAL; in rockchip_i2s_tdm_probe()
1550 spin_lock_init(&i2s_tdm->lock); in rockchip_i2s_tdm_probe()
1551 i2s_tdm->soc_data = (struct rk_i2s_soc_data *)of_id->data; in rockchip_i2s_tdm_probe()
1553 i2s_tdm->frame_width = 64; in rockchip_i2s_tdm_probe()
1555 i2s_tdm->clk_trcm = TRCM_TXRX; in rockchip_i2s_tdm_probe()
1556 if (of_property_read_bool(node, "rockchip,trcm-sync-tx-only")) in rockchip_i2s_tdm_probe()
1557 i2s_tdm->clk_trcm = TRCM_TX; in rockchip_i2s_tdm_probe()
1558 if (of_property_read_bool(node, "rockchip,trcm-sync-rx-only")) { in rockchip_i2s_tdm_probe()
1559 if (i2s_tdm->clk_trcm) { in rockchip_i2s_tdm_probe()
1560 dev_err(i2s_tdm->dev, "invalid trcm-sync configuration\n"); in rockchip_i2s_tdm_probe()
1561 return -EINVAL; in rockchip_i2s_tdm_probe()
1563 i2s_tdm->clk_trcm = TRCM_RX; in rockchip_i2s_tdm_probe()
1570 i2s_tdm->grf = syscon_regmap_lookup_by_phandle(node, "rockchip,grf"); in rockchip_i2s_tdm_probe()
1571 if (IS_ERR(i2s_tdm->grf)) in rockchip_i2s_tdm_probe()
1572 return dev_err_probe(i2s_tdm->dev, PTR_ERR(i2s_tdm->grf), in rockchip_i2s_tdm_probe()
1575 i2s_tdm->tx_reset = devm_reset_control_get_optional_exclusive(&pdev->dev, in rockchip_i2s_tdm_probe()
1576 "tx-m"); in rockchip_i2s_tdm_probe()
1577 if (IS_ERR(i2s_tdm->tx_reset)) { in rockchip_i2s_tdm_probe()
1578 ret = PTR_ERR(i2s_tdm->tx_reset); in rockchip_i2s_tdm_probe()
1579 return dev_err_probe(i2s_tdm->dev, ret, in rockchip_i2s_tdm_probe()
1580 "Error in tx-m reset control\n"); in rockchip_i2s_tdm_probe()
1583 i2s_tdm->rx_reset = devm_reset_control_get_optional_exclusive(&pdev->dev, in rockchip_i2s_tdm_probe()
1584 "rx-m"); in rockchip_i2s_tdm_probe()
1585 if (IS_ERR(i2s_tdm->rx_reset)) { in rockchip_i2s_tdm_probe()
1586 ret = PTR_ERR(i2s_tdm->rx_reset); in rockchip_i2s_tdm_probe()
1587 return dev_err_probe(i2s_tdm->dev, ret, in rockchip_i2s_tdm_probe()
1588 "Error in rx-m reset control\n"); in rockchip_i2s_tdm_probe()
1591 i2s_tdm->hclk = devm_clk_get(&pdev->dev, "hclk"); in rockchip_i2s_tdm_probe()
1592 if (IS_ERR(i2s_tdm->hclk)) { in rockchip_i2s_tdm_probe()
1593 return dev_err_probe(i2s_tdm->dev, PTR_ERR(i2s_tdm->hclk), in rockchip_i2s_tdm_probe()
1597 i2s_tdm->mclk_tx = devm_clk_get(&pdev->dev, "mclk_tx"); in rockchip_i2s_tdm_probe()
1598 if (IS_ERR(i2s_tdm->mclk_tx)) { in rockchip_i2s_tdm_probe()
1599 return dev_err_probe(i2s_tdm->dev, PTR_ERR(i2s_tdm->mclk_tx), in rockchip_i2s_tdm_probe()
1603 i2s_tdm->mclk_rx = devm_clk_get(&pdev->dev, "mclk_rx"); in rockchip_i2s_tdm_probe()
1604 if (IS_ERR(i2s_tdm->mclk_rx)) { in rockchip_i2s_tdm_probe()
1605 return dev_err_probe(i2s_tdm->dev, PTR_ERR(i2s_tdm->mclk_rx), in rockchip_i2s_tdm_probe()
1609 i2s_tdm->io_multiplex = in rockchip_i2s_tdm_probe()
1610 of_property_read_bool(node, "rockchip,io-multiplex"); in rockchip_i2s_tdm_probe()
1614 return dev_err_probe(i2s_tdm->dev, ret, in rockchip_i2s_tdm_probe()
1615 "mclk-calibrate clocks missing"); in rockchip_i2s_tdm_probe()
1619 return dev_err_probe(i2s_tdm->dev, PTR_ERR(regs), in rockchip_i2s_tdm_probe()
1623 i2s_tdm->regmap = devm_regmap_init_mmio(&pdev->dev, regs, in rockchip_i2s_tdm_probe()
1625 if (IS_ERR(i2s_tdm->regmap)) { in rockchip_i2s_tdm_probe()
1626 return dev_err_probe(i2s_tdm->dev, PTR_ERR(i2s_tdm->regmap), in rockchip_i2s_tdm_probe()
1630 if (i2s_tdm->has_playback) { in rockchip_i2s_tdm_probe()
1631 i2s_tdm->playback_dma_data.addr = res->start + I2S_TXDR; in rockchip_i2s_tdm_probe()
1632 i2s_tdm->playback_dma_data.addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES; in rockchip_i2s_tdm_probe()
1633 i2s_tdm->playback_dma_data.maxburst = 8; in rockchip_i2s_tdm_probe()
1636 if (i2s_tdm->has_capture) { in rockchip_i2s_tdm_probe()
1637 i2s_tdm->capture_dma_data.addr = res->start + I2S_RXDR; in rockchip_i2s_tdm_probe()
1638 i2s_tdm->capture_dma_data.addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES; in rockchip_i2s_tdm_probe()
1639 i2s_tdm->capture_dma_data.maxburst = 8; in rockchip_i2s_tdm_probe()
1644 dev_err(&pdev->dev, "I2S TX path prepare failed: %d\n", ret); in rockchip_i2s_tdm_probe()
1650 dev_err(&pdev->dev, "I2S RX path prepare failed: %d\n", ret); in rockchip_i2s_tdm_probe()
1654 dev_set_drvdata(&pdev->dev, i2s_tdm); in rockchip_i2s_tdm_probe()
1656 ret = clk_prepare_enable(i2s_tdm->hclk); in rockchip_i2s_tdm_probe()
1658 return dev_err_probe(i2s_tdm->dev, ret, in rockchip_i2s_tdm_probe()
1664 ret = dev_err_probe(i2s_tdm->dev, ret, in rockchip_i2s_tdm_probe()
1669 if (i2s_tdm->mclk_calibrate) { in rockchip_i2s_tdm_probe()
1670 i2s_tdm->mclk_root0_initial_freq = clk_get_rate(i2s_tdm->mclk_root0); in rockchip_i2s_tdm_probe()
1671 i2s_tdm->mclk_root1_initial_freq = clk_get_rate(i2s_tdm->mclk_root1); in rockchip_i2s_tdm_probe()
1672 i2s_tdm->mclk_root0_freq = i2s_tdm->mclk_root0_initial_freq; in rockchip_i2s_tdm_probe()
1673 i2s_tdm->mclk_root1_freq = i2s_tdm->mclk_root1_initial_freq; in rockchip_i2s_tdm_probe()
1676 pm_runtime_enable(&pdev->dev); in rockchip_i2s_tdm_probe()
1678 regmap_update_bits(i2s_tdm->regmap, I2S_DMACR, I2S_DMACR_TDL_MASK, in rockchip_i2s_tdm_probe()
1680 regmap_update_bits(i2s_tdm->regmap, I2S_DMACR, I2S_DMACR_RDL_MASK, in rockchip_i2s_tdm_probe()
1682 regmap_update_bits(i2s_tdm->regmap, I2S_CKR, I2S_CKR_TRCM_MASK, in rockchip_i2s_tdm_probe()
1683 i2s_tdm->clk_trcm << I2S_CKR_TRCM_SHIFT); in rockchip_i2s_tdm_probe()
1685 if (i2s_tdm->soc_data && i2s_tdm->soc_data->init) in rockchip_i2s_tdm_probe()
1686 i2s_tdm->soc_data->init(&pdev->dev, res->start); in rockchip_i2s_tdm_probe()
1688 ret = devm_snd_soc_register_component(&pdev->dev, in rockchip_i2s_tdm_probe()
1690 i2s_tdm->dai, 1); in rockchip_i2s_tdm_probe()
1693 dev_err(&pdev->dev, "Could not register DAI\n"); in rockchip_i2s_tdm_probe()
1697 ret = devm_snd_dmaengine_pcm_register(&pdev->dev, NULL, 0); in rockchip_i2s_tdm_probe()
1699 dev_err(&pdev->dev, "Could not register PCM\n"); in rockchip_i2s_tdm_probe()
1706 if (!pm_runtime_status_suspended(&pdev->dev)) in rockchip_i2s_tdm_probe()
1707 i2s_tdm_runtime_suspend(&pdev->dev); in rockchip_i2s_tdm_probe()
1708 pm_runtime_disable(&pdev->dev); in rockchip_i2s_tdm_probe()
1711 clk_disable_unprepare(i2s_tdm->hclk); in rockchip_i2s_tdm_probe()
1718 if (!pm_runtime_status_suspended(&pdev->dev)) in rockchip_i2s_tdm_remove()
1719 i2s_tdm_runtime_suspend(&pdev->dev); in rockchip_i2s_tdm_remove()
1721 pm_runtime_disable(&pdev->dev); in rockchip_i2s_tdm_remove()
1730 regcache_mark_dirty(i2s_tdm->regmap); in rockchip_i2s_tdm_suspend()
1743 ret = regcache_sync(i2s_tdm->regmap); in rockchip_i2s_tdm_resume()
1767 MODULE_DESCRIPTION("ROCKCHIP I2S/TDM ASoC Interface");
1768 MODULE_AUTHOR("Sugar Zhang <sugar.zhang@rock-chips.com>");