Lines Matching +full:tdm +full:- +full:sync +full:- +full:mode

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>
23 #define DRV_NAME "rockchip-i2s-tdm"
91 clk_disable_unprepare(i2s_tdm->mclk_tx); in i2s_tdm_disable_unprepare_mclk()
92 clk_disable_unprepare(i2s_tdm->mclk_rx); in i2s_tdm_disable_unprepare_mclk()
96 * i2s_tdm_prepare_enable_mclk - prepare to enable all mclks, disable them on
109 ret = clk_prepare_enable(i2s_tdm->mclk_tx); in i2s_tdm_prepare_enable_mclk()
112 ret = clk_prepare_enable(i2s_tdm->mclk_rx); in i2s_tdm_prepare_enable_mclk()
119 clk_disable_unprepare(i2s_tdm->mclk_tx); in i2s_tdm_prepare_enable_mclk()
128 regcache_cache_only(i2s_tdm->regmap, true); in i2s_tdm_runtime_suspend()
131 clk_disable_unprepare(i2s_tdm->hclk); in i2s_tdm_runtime_suspend()
141 ret = clk_prepare_enable(i2s_tdm->hclk); in i2s_tdm_runtime_resume()
149 regcache_cache_only(i2s_tdm->regmap, false); in i2s_tdm_runtime_resume()
150 regcache_mark_dirty(i2s_tdm->regmap); in i2s_tdm_runtime_resume()
152 ret = regcache_sync(i2s_tdm->regmap); in i2s_tdm_runtime_resume()
161 clk_disable_unprepare(i2s_tdm->hclk); in i2s_tdm_runtime_resume()
172 * Makes sure that both tx and rx are reset at the same time to sync lrck
177 /* This is technically race-y. in rockchip_snd_xfer_sync_reset()
195 reset_control_assert(i2s_tdm->tx_reset); in rockchip_snd_xfer_sync_reset()
196 reset_control_assert(i2s_tdm->rx_reset); in rockchip_snd_xfer_sync_reset()
198 reset_control_deassert(i2s_tdm->tx_reset); in rockchip_snd_xfer_sync_reset()
199 reset_control_deassert(i2s_tdm->rx_reset); in rockchip_snd_xfer_sync_reset()
233 regmap_update_bits(i2s_tdm->regmap, I2S_XFER, xfer_mask, xfer_val); in rockchip_snd_xfer_clear()
235 regmap_update_bits(i2s_tdm->regmap, I2S_CLR, clr, clr); in rockchip_snd_xfer_clear()
237 regmap_read(i2s_tdm->regmap, I2S_CLR, &val); in rockchip_snd_xfer_clear()
241 regmap_read(i2s_tdm->regmap, I2S_CLR, &val); in rockchip_snd_xfer_clear()
242 retry--; in rockchip_snd_xfer_clear()
244 dev_warn(i2s_tdm->dev, "clear failed, reset %s%s\n", in rockchip_snd_xfer_clear()
249 rockchip_snd_reset(i2s_tdm->tx_reset); in rockchip_snd_xfer_clear()
251 rockchip_snd_reset(i2s_tdm->rx_reset); in rockchip_snd_xfer_clear()
288 spin_lock_irqsave(&i2s_tdm->lock, flags); in rockchip_snd_txrxctrl()
290 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) in rockchip_snd_txrxctrl()
291 rockchip_enable_tde(i2s_tdm->regmap); in rockchip_snd_txrxctrl()
293 rockchip_enable_rde(i2s_tdm->regmap); in rockchip_snd_txrxctrl()
295 if (++i2s_tdm->refcount == 1) { in rockchip_snd_txrxctrl()
297 regmap_update_bits(i2s_tdm->regmap, I2S_XFER, in rockchip_snd_txrxctrl()
304 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) in rockchip_snd_txrxctrl()
305 rockchip_disable_tde(i2s_tdm->regmap); in rockchip_snd_txrxctrl()
307 rockchip_disable_rde(i2s_tdm->regmap); in rockchip_snd_txrxctrl()
309 if (--i2s_tdm->refcount == 0) { in rockchip_snd_txrxctrl()
314 spin_unlock_irqrestore(&i2s_tdm->lock, flags); in rockchip_snd_txrxctrl()
320 rockchip_enable_tde(i2s_tdm->regmap); in rockchip_snd_txctrl()
322 regmap_update_bits(i2s_tdm->regmap, I2S_XFER, in rockchip_snd_txctrl()
326 rockchip_disable_tde(i2s_tdm->regmap); in rockchip_snd_txctrl()
335 rockchip_enable_rde(i2s_tdm->regmap); in rockchip_snd_rxctrl()
337 regmap_update_bits(i2s_tdm->regmap, I2S_XFER, in rockchip_snd_rxctrl()
341 rockchip_disable_rde(i2s_tdm->regmap); in rockchip_snd_rxctrl()
353 bool is_tdm = i2s_tdm->tdm_mode; in rockchip_i2s_tdm_set_fmt()
355 ret = pm_runtime_resume_and_get(cpu_dai->dev); in rockchip_i2s_tdm_set_fmt()
356 if (ret < 0 && ret != -EACCES) in rockchip_i2s_tdm_set_fmt()
363 i2s_tdm->is_master_mode = true; in rockchip_i2s_tdm_set_fmt()
367 i2s_tdm->is_master_mode = false; in rockchip_i2s_tdm_set_fmt()
370 ret = -EINVAL; in rockchip_i2s_tdm_set_fmt()
374 regmap_update_bits(i2s_tdm->regmap, I2S_CKR, mask, val); in rockchip_i2s_tdm_set_fmt()
399 ret = -EINVAL; in rockchip_i2s_tdm_set_fmt()
403 regmap_update_bits(i2s_tdm->regmap, I2S_CKR, mask, val); in rockchip_i2s_tdm_set_fmt()
418 case SND_SOC_DAIFMT_DSP_A: /* PCM delay 1 mode */ in rockchip_i2s_tdm_set_fmt()
422 case SND_SOC_DAIFMT_DSP_B: /* PCM no delay mode */ in rockchip_i2s_tdm_set_fmt()
427 ret = -EINVAL; in rockchip_i2s_tdm_set_fmt()
432 regmap_update_bits(i2s_tdm->regmap, I2S_TXCR, mask, txcr_val); in rockchip_i2s_tdm_set_fmt()
435 regmap_update_bits(i2s_tdm->regmap, I2S_RXCR, mask, rxcr_val); in rockchip_i2s_tdm_set_fmt()
460 ret = -EINVAL; in rockchip_i2s_tdm_set_fmt()
468 regmap_update_bits(i2s_tdm->regmap, I2S_TXCR, mask, val); in rockchip_i2s_tdm_set_fmt()
469 regmap_update_bits(i2s_tdm->regmap, I2S_RXCR, mask, val); in rockchip_i2s_tdm_set_fmt()
473 regmap_update_bits(i2s_tdm->regmap, I2S_TDM_TXCR, in rockchip_i2s_tdm_set_fmt()
475 regmap_update_bits(i2s_tdm->regmap, I2S_TDM_RXCR, in rockchip_i2s_tdm_set_fmt()
480 pm_runtime_put(cpu_dai->dev); in rockchip_i2s_tdm_set_fmt()
490 stream = SNDRV_PCM_STREAM_LAST - substream->stream; in rockchip_i2s_tdm_xfer_pause()
492 rockchip_disable_tde(i2s_tdm->regmap); in rockchip_i2s_tdm_xfer_pause()
494 rockchip_disable_rde(i2s_tdm->regmap); in rockchip_i2s_tdm_xfer_pause()
504 stream = SNDRV_PCM_STREAM_LAST - substream->stream; in rockchip_i2s_tdm_xfer_resume()
506 rockchip_enable_tde(i2s_tdm->regmap); in rockchip_i2s_tdm_xfer_resume()
508 rockchip_enable_rde(i2s_tdm->regmap); in rockchip_i2s_tdm_xfer_resume()
510 regmap_update_bits(i2s_tdm->regmap, I2S_XFER, in rockchip_i2s_tdm_xfer_resume()
551 if (!i2s_tdm->io_multiplex) in rockchip_i2s_io_multiplex()
554 if (IS_ERR_OR_NULL(i2s_tdm->grf)) { in rockchip_i2s_io_multiplex()
555 dev_err(i2s_tdm->dev, in rockchip_i2s_io_multiplex()
557 return -EINVAL; in rockchip_i2s_io_multiplex()
560 if (substream->stream == SNDRV_PCM_STREAM_CAPTURE) { in rockchip_i2s_io_multiplex()
562 &substream->pcm->streams[SNDRV_PCM_STREAM_PLAYBACK]; in rockchip_i2s_io_multiplex()
564 if (playback_str->substream_opened) { in rockchip_i2s_io_multiplex()
565 regmap_read(i2s_tdm->regmap, I2S_TXCR, &val); in rockchip_i2s_io_multiplex()
567 usable_chs = MULTIPLEX_CH_MAX - to_ch_num(val); in rockchip_i2s_io_multiplex()
570 regmap_read(i2s_tdm->regmap, I2S_RXCR, &val); in rockchip_i2s_io_multiplex()
574 dev_err(i2s_tdm->dev, in rockchip_i2s_io_multiplex()
577 return -EINVAL; in rockchip_i2s_io_multiplex()
583 &substream->pcm->streams[SNDRV_PCM_STREAM_CAPTURE]; in rockchip_i2s_io_multiplex()
585 if (capture_str->substream_opened) { in rockchip_i2s_io_multiplex()
586 regmap_read(i2s_tdm->regmap, I2S_RXCR, &val); in rockchip_i2s_io_multiplex()
588 usable_chs = MULTIPLEX_CH_MAX - to_ch_num(val); in rockchip_i2s_io_multiplex()
591 regmap_read(i2s_tdm->regmap, I2S_TXCR, &val); in rockchip_i2s_io_multiplex()
595 dev_err(i2s_tdm->dev, in rockchip_i2s_io_multiplex()
598 return -EINVAL; in rockchip_i2s_io_multiplex()
602 val <<= i2s_tdm->soc_data->grf_shift; in rockchip_i2s_io_multiplex()
603 val |= (I2S_IO_DIRECTION_MASK << i2s_tdm->soc_data->grf_shift) << 16; in rockchip_i2s_io_multiplex()
604 regmap_write(i2s_tdm->grf, i2s_tdm->soc_data->grf_reg_offset, val); in rockchip_i2s_io_multiplex()
618 if (!i2s_tdm->clk_trcm) in rockchip_i2s_trcm_mode()
621 spin_lock_irqsave(&i2s_tdm->lock, flags); in rockchip_i2s_trcm_mode()
622 if (i2s_tdm->refcount) in rockchip_i2s_trcm_mode()
625 regmap_update_bits(i2s_tdm->regmap, I2S_CLKDIV, in rockchip_i2s_trcm_mode()
628 regmap_update_bits(i2s_tdm->regmap, I2S_CKR, in rockchip_i2s_trcm_mode()
632 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) in rockchip_i2s_trcm_mode()
633 regmap_update_bits(i2s_tdm->regmap, I2S_TXCR, in rockchip_i2s_trcm_mode()
637 regmap_update_bits(i2s_tdm->regmap, I2S_RXCR, in rockchip_i2s_trcm_mode()
641 if (i2s_tdm->refcount) in rockchip_i2s_trcm_mode()
643 spin_unlock_irqrestore(&i2s_tdm->lock, flags); in rockchip_i2s_trcm_mode()
657 if (i2s_tdm->is_master_mode) { in rockchip_i2s_tdm_hw_params()
660 if (i2s_tdm->clk_trcm == TRCM_TX) { in rockchip_i2s_tdm_hw_params()
661 mclk = i2s_tdm->mclk_tx; in rockchip_i2s_tdm_hw_params()
662 } else if (i2s_tdm->clk_trcm == TRCM_RX) { in rockchip_i2s_tdm_hw_params()
663 mclk = i2s_tdm->mclk_rx; in rockchip_i2s_tdm_hw_params()
664 } else if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { in rockchip_i2s_tdm_hw_params()
665 mclk = i2s_tdm->mclk_tx; in rockchip_i2s_tdm_hw_params()
667 mclk = i2s_tdm->mclk_rx; in rockchip_i2s_tdm_hw_params()
675 bclk_rate = i2s_tdm->frame_width * params_rate(params); in rockchip_i2s_tdm_hw_params()
677 return -EINVAL; in rockchip_i2s_tdm_hw_params()
700 return -EINVAL; in rockchip_i2s_tdm_hw_params()
717 return -EINVAL; in rockchip_i2s_tdm_hw_params()
720 if (i2s_tdm->clk_trcm) { in rockchip_i2s_tdm_hw_params()
722 } else if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { in rockchip_i2s_tdm_hw_params()
723 regmap_update_bits(i2s_tdm->regmap, I2S_CLKDIV, in rockchip_i2s_tdm_hw_params()
726 regmap_update_bits(i2s_tdm->regmap, I2S_CKR, in rockchip_i2s_tdm_hw_params()
729 regmap_update_bits(i2s_tdm->regmap, I2S_TXCR, in rockchip_i2s_tdm_hw_params()
733 regmap_update_bits(i2s_tdm->regmap, I2S_CLKDIV, in rockchip_i2s_tdm_hw_params()
736 regmap_update_bits(i2s_tdm->regmap, I2S_CKR, in rockchip_i2s_tdm_hw_params()
739 regmap_update_bits(i2s_tdm->regmap, I2S_RXCR, in rockchip_i2s_tdm_hw_params()
756 if (i2s_tdm->clk_trcm) in rockchip_i2s_tdm_trigger()
758 else if (substream->stream == SNDRV_PCM_STREAM_CAPTURE) in rockchip_i2s_tdm_trigger()
766 if (i2s_tdm->clk_trcm) in rockchip_i2s_tdm_trigger()
768 else if (substream->stream == SNDRV_PCM_STREAM_CAPTURE) in rockchip_i2s_tdm_trigger()
774 return -EINVAL; in rockchip_i2s_tdm_trigger()
784 if (i2s_tdm->has_capture) in rockchip_i2s_tdm_dai_probe()
785 snd_soc_dai_dma_data_set_capture(dai, &i2s_tdm->capture_dma_data); in rockchip_i2s_tdm_dai_probe()
786 if (i2s_tdm->has_playback) in rockchip_i2s_tdm_dai_probe()
787 snd_soc_dai_dma_data_set_playback(dai, &i2s_tdm->playback_dma_data); in rockchip_i2s_tdm_dai_probe()
799 i2s_tdm->tdm_mode = true; in rockchip_dai_tdm_slot()
800 i2s_tdm->frame_width = slots * slot_width; in rockchip_dai_tdm_slot()
804 regmap_update_bits(i2s_tdm->regmap, I2S_TDM_TXCR, in rockchip_dai_tdm_slot()
806 regmap_update_bits(i2s_tdm->regmap, I2S_TDM_RXCR, in rockchip_dai_tdm_slot()
818 return -EINVAL; in rockchip_i2s_tdm_set_bclk_ratio()
820 i2s_tdm->frame_width = ratio; in rockchip_i2s_tdm_set_bclk_ratio()
933 const struct txrx_config *configs = i2s_tdm->soc_data->configs; in common_soc_init()
934 u32 reg = 0, val = 0, trcm = i2s_tdm->clk_trcm; in common_soc_init()
940 if (IS_ERR_OR_NULL(i2s_tdm->grf)) { in common_soc_init()
941 dev_err(i2s_tdm->dev, in common_soc_init()
942 "no grf present but non-txrx TRCM specified\n"); in common_soc_init()
943 return -EINVAL; in common_soc_init()
946 for (i = 0; i < i2s_tdm->soc_data->config_count; i++) { in common_soc_init()
956 regmap_write(i2s_tdm->grf, reg, val); in common_soc_init()
1026 { .compatible = "rockchip,px30-i2s-tdm", .data = &px30_i2s_soc_data },
1027 { .compatible = "rockchip,rk1808-i2s-tdm", .data = &rk1808_i2s_soc_data },
1028 { .compatible = "rockchip,rk3308-i2s-tdm", .data = &rk3308_i2s_soc_data },
1029 { .compatible = "rockchip,rk3568-i2s-tdm", .data = &rk3568_i2s_soc_data },
1030 { .compatible = "rockchip,rk3588-i2s-tdm" },
1031 { .compatible = "rockchip,rv1126-i2s-tdm", .data = &rv1126_i2s_soc_data },
1047 struct device_node *node = i2s_tdm->dev->of_node; in rockchip_i2s_tdm_init_dai()
1049 of_property_for_each_string(node, "dma-names", dma_names, dma_name) { in rockchip_i2s_tdm_init_dai()
1051 i2s_tdm->has_playback = true; in rockchip_i2s_tdm_init_dai()
1053 i2s_tdm->has_capture = true; in rockchip_i2s_tdm_init_dai()
1056 dai = devm_kmemdup(i2s_tdm->dev, &i2s_tdm_dai, in rockchip_i2s_tdm_init_dai()
1059 return -ENOMEM; in rockchip_i2s_tdm_init_dai()
1061 if (i2s_tdm->has_playback) { in rockchip_i2s_tdm_init_dai()
1062 dai->playback.stream_name = "Playback"; in rockchip_i2s_tdm_init_dai()
1063 dai->playback.channels_min = 2; in rockchip_i2s_tdm_init_dai()
1064 dai->playback.channels_max = 8; in rockchip_i2s_tdm_init_dai()
1065 dai->playback.rates = SNDRV_PCM_RATE_8000_192000; in rockchip_i2s_tdm_init_dai()
1066 dai->playback.formats = formats; in rockchip_i2s_tdm_init_dai()
1069 if (i2s_tdm->has_capture) { in rockchip_i2s_tdm_init_dai()
1070 dai->capture.stream_name = "Capture"; in rockchip_i2s_tdm_init_dai()
1071 dai->capture.channels_min = 2; in rockchip_i2s_tdm_init_dai()
1072 dai->capture.channels_max = 8; in rockchip_i2s_tdm_init_dai()
1073 dai->capture.rates = SNDRV_PCM_RATE_8000_192000; in rockchip_i2s_tdm_init_dai()
1074 dai->capture.formats = formats; in rockchip_i2s_tdm_init_dai()
1077 if (i2s_tdm->clk_trcm != TRCM_TXRX) in rockchip_i2s_tdm_init_dai()
1078 dai->symmetric_rate = 1; in rockchip_i2s_tdm_init_dai()
1080 i2s_tdm->dai = dai; in rockchip_i2s_tdm_init_dai()
1093 i2s_data = i2s_tdm->i2s_sdis; in rockchip_i2s_tdm_path_check()
1095 i2s_data = i2s_tdm->i2s_sdos; in rockchip_i2s_tdm_path_check()
1098 if (i2s_data[i] > CH_GRP_MAX - 1) { in rockchip_i2s_tdm_path_check()
1099 dev_err(i2s_tdm->dev, in rockchip_i2s_tdm_path_check()
1103 return -EINVAL; in rockchip_i2s_tdm_path_check()
1111 dev_err(i2s_tdm->dev, in rockchip_i2s_tdm_path_check()
1116 return -EINVAL; in rockchip_i2s_tdm_path_check()
1130 regmap_update_bits(i2s_tdm->regmap, I2S_TXCR, in rockchip_i2s_tdm_tx_path_config()
1132 I2S_TXCR_PATH(idx, i2s_tdm->i2s_sdos[idx])); in rockchip_i2s_tdm_tx_path_config()
1142 regmap_update_bits(i2s_tdm->regmap, I2S_RXCR, in rockchip_i2s_tdm_rx_path_config()
1144 I2S_RXCR_PATH(idx, i2s_tdm->i2s_sdis[idx])); in rockchip_i2s_tdm_rx_path_config()
1161 char *i2s_tx_path_prop = "rockchip,i2s-tx-route"; in rockchip_i2s_tdm_path_prepare()
1162 char *i2s_rx_path_prop = "rockchip,i2s-rx-route"; in rockchip_i2s_tdm_path_prepare()
1169 i2s_data = i2s_tdm->i2s_sdis; in rockchip_i2s_tdm_path_prepare()
1172 i2s_data = i2s_tdm->i2s_sdos; in rockchip_i2s_tdm_path_prepare()
1177 if (num != -ENOENT) { in rockchip_i2s_tdm_path_prepare()
1178 dev_err(i2s_tdm->dev, in rockchip_i2s_tdm_path_prepare()
1185 dev_err(i2s_tdm->dev, in rockchip_i2s_tdm_path_prepare()
1187 return -EINVAL; in rockchip_i2s_tdm_path_prepare()
1193 dev_err(i2s_tdm->dev, in rockchip_i2s_tdm_path_prepare()
1201 dev_err(i2s_tdm->dev, in rockchip_i2s_tdm_path_prepare()
1225 struct device_node *node = pdev->dev.of_node; in rockchip_i2s_tdm_probe()
1231 i2s_tdm = devm_kzalloc(&pdev->dev, sizeof(*i2s_tdm), GFP_KERNEL); in rockchip_i2s_tdm_probe()
1233 return -ENOMEM; in rockchip_i2s_tdm_probe()
1235 i2s_tdm->dev = &pdev->dev; in rockchip_i2s_tdm_probe()
1237 spin_lock_init(&i2s_tdm->lock); in rockchip_i2s_tdm_probe()
1238 i2s_tdm->soc_data = device_get_match_data(&pdev->dev); in rockchip_i2s_tdm_probe()
1239 i2s_tdm->frame_width = 64; in rockchip_i2s_tdm_probe()
1241 i2s_tdm->clk_trcm = TRCM_TXRX; in rockchip_i2s_tdm_probe()
1242 if (of_property_read_bool(node, "rockchip,trcm-sync-tx-only")) in rockchip_i2s_tdm_probe()
1243 i2s_tdm->clk_trcm = TRCM_TX; in rockchip_i2s_tdm_probe()
1244 if (of_property_read_bool(node, "rockchip,trcm-sync-rx-only")) { in rockchip_i2s_tdm_probe()
1245 if (i2s_tdm->clk_trcm) { in rockchip_i2s_tdm_probe()
1246 dev_err(i2s_tdm->dev, "invalid trcm-sync configuration\n"); in rockchip_i2s_tdm_probe()
1247 return -EINVAL; in rockchip_i2s_tdm_probe()
1249 i2s_tdm->clk_trcm = TRCM_RX; in rockchip_i2s_tdm_probe()
1256 i2s_tdm->grf = syscon_regmap_lookup_by_phandle(node, "rockchip,grf"); in rockchip_i2s_tdm_probe()
1257 i2s_tdm->tx_reset = devm_reset_control_get_optional_exclusive(&pdev->dev, in rockchip_i2s_tdm_probe()
1258 "tx-m"); in rockchip_i2s_tdm_probe()
1259 if (IS_ERR(i2s_tdm->tx_reset)) { in rockchip_i2s_tdm_probe()
1260 ret = PTR_ERR(i2s_tdm->tx_reset); in rockchip_i2s_tdm_probe()
1261 return dev_err_probe(i2s_tdm->dev, ret, in rockchip_i2s_tdm_probe()
1262 "Error in tx-m reset control\n"); in rockchip_i2s_tdm_probe()
1265 i2s_tdm->rx_reset = devm_reset_control_get_optional_exclusive(&pdev->dev, in rockchip_i2s_tdm_probe()
1266 "rx-m"); in rockchip_i2s_tdm_probe()
1267 if (IS_ERR(i2s_tdm->rx_reset)) { in rockchip_i2s_tdm_probe()
1268 ret = PTR_ERR(i2s_tdm->rx_reset); in rockchip_i2s_tdm_probe()
1269 return dev_err_probe(i2s_tdm->dev, ret, in rockchip_i2s_tdm_probe()
1270 "Error in rx-m reset control\n"); in rockchip_i2s_tdm_probe()
1273 i2s_tdm->hclk = devm_clk_get(&pdev->dev, "hclk"); in rockchip_i2s_tdm_probe()
1274 if (IS_ERR(i2s_tdm->hclk)) { in rockchip_i2s_tdm_probe()
1275 return dev_err_probe(i2s_tdm->dev, PTR_ERR(i2s_tdm->hclk), in rockchip_i2s_tdm_probe()
1279 i2s_tdm->mclk_tx = devm_clk_get(&pdev->dev, "mclk_tx"); in rockchip_i2s_tdm_probe()
1280 if (IS_ERR(i2s_tdm->mclk_tx)) { in rockchip_i2s_tdm_probe()
1281 return dev_err_probe(i2s_tdm->dev, PTR_ERR(i2s_tdm->mclk_tx), in rockchip_i2s_tdm_probe()
1285 i2s_tdm->mclk_rx = devm_clk_get(&pdev->dev, "mclk_rx"); in rockchip_i2s_tdm_probe()
1286 if (IS_ERR(i2s_tdm->mclk_rx)) { in rockchip_i2s_tdm_probe()
1287 return dev_err_probe(i2s_tdm->dev, PTR_ERR(i2s_tdm->mclk_rx), in rockchip_i2s_tdm_probe()
1291 i2s_tdm->io_multiplex = in rockchip_i2s_tdm_probe()
1292 of_property_read_bool(node, "rockchip,io-multiplex"); in rockchip_i2s_tdm_probe()
1296 return dev_err_probe(i2s_tdm->dev, PTR_ERR(regs), in rockchip_i2s_tdm_probe()
1300 i2s_tdm->regmap = devm_regmap_init_mmio(&pdev->dev, regs, in rockchip_i2s_tdm_probe()
1302 if (IS_ERR(i2s_tdm->regmap)) { in rockchip_i2s_tdm_probe()
1303 return dev_err_probe(i2s_tdm->dev, PTR_ERR(i2s_tdm->regmap), in rockchip_i2s_tdm_probe()
1307 if (i2s_tdm->has_playback) { in rockchip_i2s_tdm_probe()
1308 i2s_tdm->playback_dma_data.addr = res->start + I2S_TXDR; in rockchip_i2s_tdm_probe()
1309 i2s_tdm->playback_dma_data.addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES; in rockchip_i2s_tdm_probe()
1310 i2s_tdm->playback_dma_data.maxburst = 8; in rockchip_i2s_tdm_probe()
1313 if (i2s_tdm->has_capture) { in rockchip_i2s_tdm_probe()
1314 i2s_tdm->capture_dma_data.addr = res->start + I2S_RXDR; in rockchip_i2s_tdm_probe()
1315 i2s_tdm->capture_dma_data.addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES; in rockchip_i2s_tdm_probe()
1316 i2s_tdm->capture_dma_data.maxburst = 8; in rockchip_i2s_tdm_probe()
1321 dev_err(&pdev->dev, "I2S TX path prepare failed: %d\n", ret); in rockchip_i2s_tdm_probe()
1327 dev_err(&pdev->dev, "I2S RX path prepare failed: %d\n", ret); in rockchip_i2s_tdm_probe()
1331 dev_set_drvdata(&pdev->dev, i2s_tdm); in rockchip_i2s_tdm_probe()
1333 ret = clk_prepare_enable(i2s_tdm->hclk); in rockchip_i2s_tdm_probe()
1335 return dev_err_probe(i2s_tdm->dev, ret, in rockchip_i2s_tdm_probe()
1341 ret = dev_err_probe(i2s_tdm->dev, ret, in rockchip_i2s_tdm_probe()
1346 pm_runtime_enable(&pdev->dev); in rockchip_i2s_tdm_probe()
1348 regmap_update_bits(i2s_tdm->regmap, I2S_DMACR, I2S_DMACR_TDL_MASK, in rockchip_i2s_tdm_probe()
1350 regmap_update_bits(i2s_tdm->regmap, I2S_DMACR, I2S_DMACR_RDL_MASK, in rockchip_i2s_tdm_probe()
1352 regmap_update_bits(i2s_tdm->regmap, I2S_CKR, I2S_CKR_TRCM_MASK, in rockchip_i2s_tdm_probe()
1353 i2s_tdm->clk_trcm << I2S_CKR_TRCM_SHIFT); in rockchip_i2s_tdm_probe()
1355 if (i2s_tdm->soc_data && i2s_tdm->soc_data->init) in rockchip_i2s_tdm_probe()
1356 i2s_tdm->soc_data->init(&pdev->dev, res->start); in rockchip_i2s_tdm_probe()
1358 ret = devm_snd_soc_register_component(&pdev->dev, in rockchip_i2s_tdm_probe()
1360 i2s_tdm->dai, 1); in rockchip_i2s_tdm_probe()
1363 dev_err(&pdev->dev, "Could not register DAI\n"); in rockchip_i2s_tdm_probe()
1367 ret = devm_snd_dmaengine_pcm_register(&pdev->dev, NULL, 0); in rockchip_i2s_tdm_probe()
1369 dev_err(&pdev->dev, "Could not register PCM\n"); in rockchip_i2s_tdm_probe()
1376 if (!pm_runtime_status_suspended(&pdev->dev)) in rockchip_i2s_tdm_probe()
1377 i2s_tdm_runtime_suspend(&pdev->dev); in rockchip_i2s_tdm_probe()
1378 pm_runtime_disable(&pdev->dev); in rockchip_i2s_tdm_probe()
1381 clk_disable_unprepare(i2s_tdm->hclk); in rockchip_i2s_tdm_probe()
1388 if (!pm_runtime_status_suspended(&pdev->dev)) in rockchip_i2s_tdm_remove()
1389 i2s_tdm_runtime_suspend(&pdev->dev); in rockchip_i2s_tdm_remove()
1391 pm_runtime_disable(&pdev->dev); in rockchip_i2s_tdm_remove()
1398 regcache_mark_dirty(i2s_tdm->regmap); in rockchip_i2s_tdm_suspend()
1411 ret = regcache_sync(i2s_tdm->regmap); in rockchip_i2s_tdm_resume()
1435 MODULE_DESCRIPTION("ROCKCHIP I2S/TDM ASoC Interface");
1436 MODULE_AUTHOR("Sugar Zhang <sugar.zhang@rock-chips.com>");