Lines Matching +full:i2s +full:- +full:regs

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>
25 #define DRV_NAME "rockchip-i2s-tdm"
93 clk_disable_unprepare(i2s_tdm->mclk_tx); in i2s_tdm_disable_unprepare_mclk()
94 clk_disable_unprepare(i2s_tdm->mclk_rx); in i2s_tdm_disable_unprepare_mclk()
98 * i2s_tdm_prepare_enable_mclk - prepare to enable all mclks, disable them on
111 ret = clk_prepare_enable(i2s_tdm->mclk_tx); in i2s_tdm_prepare_enable_mclk()
114 ret = clk_prepare_enable(i2s_tdm->mclk_rx); in i2s_tdm_prepare_enable_mclk()
121 clk_disable_unprepare(i2s_tdm->mclk_tx); in i2s_tdm_prepare_enable_mclk()
130 regcache_cache_only(i2s_tdm->regmap, true); in i2s_tdm_runtime_suspend()
133 clk_disable_unprepare(i2s_tdm->hclk); in i2s_tdm_runtime_suspend()
143 ret = clk_prepare_enable(i2s_tdm->hclk); in i2s_tdm_runtime_resume()
151 regcache_cache_only(i2s_tdm->regmap, false); in i2s_tdm_runtime_resume()
152 regcache_mark_dirty(i2s_tdm->regmap); in i2s_tdm_runtime_resume()
154 ret = regcache_sync(i2s_tdm->regmap); in i2s_tdm_runtime_resume()
163 clk_disable_unprepare(i2s_tdm->hclk); in i2s_tdm_runtime_resume()
179 /* This is technically race-y. in rockchip_snd_xfer_sync_reset()
197 reset_control_assert(i2s_tdm->tx_reset); in rockchip_snd_xfer_sync_reset()
198 reset_control_assert(i2s_tdm->rx_reset); in rockchip_snd_xfer_sync_reset()
200 reset_control_deassert(i2s_tdm->tx_reset); in rockchip_snd_xfer_sync_reset()
201 reset_control_deassert(i2s_tdm->rx_reset); in rockchip_snd_xfer_sync_reset()
235 regmap_update_bits(i2s_tdm->regmap, I2S_XFER, xfer_mask, xfer_val); in rockchip_snd_xfer_clear()
237 regmap_update_bits(i2s_tdm->regmap, I2S_CLR, clr, clr); in rockchip_snd_xfer_clear()
239 regmap_read(i2s_tdm->regmap, I2S_CLR, &val); in rockchip_snd_xfer_clear()
243 regmap_read(i2s_tdm->regmap, I2S_CLR, &val); in rockchip_snd_xfer_clear()
244 retry--; in rockchip_snd_xfer_clear()
246 dev_warn(i2s_tdm->dev, "clear failed, reset %s%s\n", in rockchip_snd_xfer_clear()
251 rockchip_snd_reset(i2s_tdm->tx_reset); in rockchip_snd_xfer_clear()
253 rockchip_snd_reset(i2s_tdm->rx_reset); in rockchip_snd_xfer_clear()
290 spin_lock_irqsave(&i2s_tdm->lock, flags); in rockchip_snd_txrxctrl()
292 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) in rockchip_snd_txrxctrl()
293 rockchip_enable_tde(i2s_tdm->regmap); in rockchip_snd_txrxctrl()
295 rockchip_enable_rde(i2s_tdm->regmap); in rockchip_snd_txrxctrl()
297 if (++i2s_tdm->refcount == 1) { in rockchip_snd_txrxctrl()
299 regmap_update_bits(i2s_tdm->regmap, I2S_XFER, in rockchip_snd_txrxctrl()
306 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) in rockchip_snd_txrxctrl()
307 rockchip_disable_tde(i2s_tdm->regmap); in rockchip_snd_txrxctrl()
309 rockchip_disable_rde(i2s_tdm->regmap); in rockchip_snd_txrxctrl()
311 if (--i2s_tdm->refcount == 0) { in rockchip_snd_txrxctrl()
316 spin_unlock_irqrestore(&i2s_tdm->lock, flags); in rockchip_snd_txrxctrl()
322 rockchip_enable_tde(i2s_tdm->regmap); in rockchip_snd_txctrl()
324 regmap_update_bits(i2s_tdm->regmap, I2S_XFER, in rockchip_snd_txctrl()
328 rockchip_disable_tde(i2s_tdm->regmap); in rockchip_snd_txctrl()
337 rockchip_enable_rde(i2s_tdm->regmap); in rockchip_snd_rxctrl()
339 regmap_update_bits(i2s_tdm->regmap, I2S_XFER, in rockchip_snd_rxctrl()
343 rockchip_disable_rde(i2s_tdm->regmap); in rockchip_snd_rxctrl()
355 bool is_tdm = i2s_tdm->tdm_mode; in rockchip_i2s_tdm_set_fmt()
357 ret = pm_runtime_resume_and_get(cpu_dai->dev); in rockchip_i2s_tdm_set_fmt()
358 if (ret < 0 && ret != -EACCES) in rockchip_i2s_tdm_set_fmt()
365 i2s_tdm->is_master_mode = true; in rockchip_i2s_tdm_set_fmt()
369 i2s_tdm->is_master_mode = false; in rockchip_i2s_tdm_set_fmt()
372 ret = -EINVAL; in rockchip_i2s_tdm_set_fmt()
376 regmap_update_bits(i2s_tdm->regmap, I2S_CKR, mask, val); in rockchip_i2s_tdm_set_fmt()
401 ret = -EINVAL; in rockchip_i2s_tdm_set_fmt()
405 regmap_update_bits(i2s_tdm->regmap, I2S_CKR, mask, val); in rockchip_i2s_tdm_set_fmt()
429 ret = -EINVAL; in rockchip_i2s_tdm_set_fmt()
434 regmap_update_bits(i2s_tdm->regmap, I2S_TXCR, mask, txcr_val); in rockchip_i2s_tdm_set_fmt()
437 regmap_update_bits(i2s_tdm->regmap, I2S_RXCR, mask, rxcr_val); in rockchip_i2s_tdm_set_fmt()
462 ret = -EINVAL; in rockchip_i2s_tdm_set_fmt()
470 regmap_update_bits(i2s_tdm->regmap, I2S_TXCR, mask, val); in rockchip_i2s_tdm_set_fmt()
471 regmap_update_bits(i2s_tdm->regmap, I2S_RXCR, mask, val); in rockchip_i2s_tdm_set_fmt()
475 regmap_update_bits(i2s_tdm->regmap, I2S_TDM_TXCR, in rockchip_i2s_tdm_set_fmt()
477 regmap_update_bits(i2s_tdm->regmap, I2S_TDM_RXCR, in rockchip_i2s_tdm_set_fmt()
482 pm_runtime_put(cpu_dai->dev); in rockchip_i2s_tdm_set_fmt()
492 stream = SNDRV_PCM_STREAM_LAST - substream->stream; in rockchip_i2s_tdm_xfer_pause()
494 rockchip_disable_tde(i2s_tdm->regmap); in rockchip_i2s_tdm_xfer_pause()
496 rockchip_disable_rde(i2s_tdm->regmap); in rockchip_i2s_tdm_xfer_pause()
506 stream = SNDRV_PCM_STREAM_LAST - substream->stream; in rockchip_i2s_tdm_xfer_resume()
508 rockchip_enable_tde(i2s_tdm->regmap); in rockchip_i2s_tdm_xfer_resume()
510 rockchip_enable_rde(i2s_tdm->regmap); in rockchip_i2s_tdm_xfer_resume()
512 regmap_update_bits(i2s_tdm->regmap, I2S_XFER, in rockchip_i2s_tdm_xfer_resume()
553 if (!i2s_tdm->io_multiplex) in rockchip_i2s_io_multiplex()
556 if (IS_ERR_OR_NULL(i2s_tdm->grf)) { in rockchip_i2s_io_multiplex()
557 dev_err(i2s_tdm->dev, in rockchip_i2s_io_multiplex()
559 return -EINVAL; in rockchip_i2s_io_multiplex()
562 if (substream->stream == SNDRV_PCM_STREAM_CAPTURE) { in rockchip_i2s_io_multiplex()
564 &substream->pcm->streams[SNDRV_PCM_STREAM_PLAYBACK]; in rockchip_i2s_io_multiplex()
566 if (playback_str->substream_opened) { in rockchip_i2s_io_multiplex()
567 regmap_read(i2s_tdm->regmap, I2S_TXCR, &val); in rockchip_i2s_io_multiplex()
569 usable_chs = MULTIPLEX_CH_MAX - to_ch_num(val); in rockchip_i2s_io_multiplex()
572 regmap_read(i2s_tdm->regmap, I2S_RXCR, &val); in rockchip_i2s_io_multiplex()
576 dev_err(i2s_tdm->dev, in rockchip_i2s_io_multiplex()
579 return -EINVAL; in rockchip_i2s_io_multiplex()
585 &substream->pcm->streams[SNDRV_PCM_STREAM_CAPTURE]; in rockchip_i2s_io_multiplex()
587 if (capture_str->substream_opened) { in rockchip_i2s_io_multiplex()
588 regmap_read(i2s_tdm->regmap, I2S_RXCR, &val); in rockchip_i2s_io_multiplex()
590 usable_chs = MULTIPLEX_CH_MAX - to_ch_num(val); in rockchip_i2s_io_multiplex()
593 regmap_read(i2s_tdm->regmap, I2S_TXCR, &val); in rockchip_i2s_io_multiplex()
597 dev_err(i2s_tdm->dev, in rockchip_i2s_io_multiplex()
600 return -EINVAL; in rockchip_i2s_io_multiplex()
604 val <<= i2s_tdm->soc_data->grf_shift; in rockchip_i2s_io_multiplex()
605 val |= (I2S_IO_DIRECTION_MASK << i2s_tdm->soc_data->grf_shift) << 16; in rockchip_i2s_io_multiplex()
606 regmap_write(i2s_tdm->grf, i2s_tdm->soc_data->grf_reg_offset, val); in rockchip_i2s_io_multiplex()
620 if (!i2s_tdm->clk_trcm) in rockchip_i2s_trcm_mode()
623 spin_lock_irqsave(&i2s_tdm->lock, flags); in rockchip_i2s_trcm_mode()
624 if (i2s_tdm->refcount) in rockchip_i2s_trcm_mode()
627 regmap_update_bits(i2s_tdm->regmap, I2S_CLKDIV, in rockchip_i2s_trcm_mode()
630 regmap_update_bits(i2s_tdm->regmap, I2S_CKR, in rockchip_i2s_trcm_mode()
634 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) in rockchip_i2s_trcm_mode()
635 regmap_update_bits(i2s_tdm->regmap, I2S_TXCR, in rockchip_i2s_trcm_mode()
639 regmap_update_bits(i2s_tdm->regmap, I2S_RXCR, in rockchip_i2s_trcm_mode()
643 if (i2s_tdm->refcount) in rockchip_i2s_trcm_mode()
645 spin_unlock_irqrestore(&i2s_tdm->lock, flags); in rockchip_i2s_trcm_mode()
659 if (i2s_tdm->is_master_mode) { in rockchip_i2s_tdm_hw_params()
662 if (i2s_tdm->clk_trcm == TRCM_TX) { in rockchip_i2s_tdm_hw_params()
663 mclk = i2s_tdm->mclk_tx; in rockchip_i2s_tdm_hw_params()
664 } else if (i2s_tdm->clk_trcm == TRCM_RX) { in rockchip_i2s_tdm_hw_params()
665 mclk = i2s_tdm->mclk_rx; in rockchip_i2s_tdm_hw_params()
666 } else if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { in rockchip_i2s_tdm_hw_params()
667 mclk = i2s_tdm->mclk_tx; in rockchip_i2s_tdm_hw_params()
669 mclk = i2s_tdm->mclk_rx; in rockchip_i2s_tdm_hw_params()
677 bclk_rate = i2s_tdm->frame_width * params_rate(params); in rockchip_i2s_tdm_hw_params()
679 return -EINVAL; in rockchip_i2s_tdm_hw_params()
702 return -EINVAL; in rockchip_i2s_tdm_hw_params()
719 return -EINVAL; in rockchip_i2s_tdm_hw_params()
722 if (i2s_tdm->clk_trcm) { in rockchip_i2s_tdm_hw_params()
724 } else if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { in rockchip_i2s_tdm_hw_params()
725 regmap_update_bits(i2s_tdm->regmap, I2S_CLKDIV, in rockchip_i2s_tdm_hw_params()
728 regmap_update_bits(i2s_tdm->regmap, I2S_CKR, in rockchip_i2s_tdm_hw_params()
731 regmap_update_bits(i2s_tdm->regmap, I2S_TXCR, in rockchip_i2s_tdm_hw_params()
735 regmap_update_bits(i2s_tdm->regmap, I2S_CLKDIV, in rockchip_i2s_tdm_hw_params()
738 regmap_update_bits(i2s_tdm->regmap, I2S_CKR, in rockchip_i2s_tdm_hw_params()
741 regmap_update_bits(i2s_tdm->regmap, I2S_RXCR, in rockchip_i2s_tdm_hw_params()
758 if (i2s_tdm->clk_trcm) in rockchip_i2s_tdm_trigger()
760 else if (substream->stream == SNDRV_PCM_STREAM_CAPTURE) in rockchip_i2s_tdm_trigger()
768 if (i2s_tdm->clk_trcm) in rockchip_i2s_tdm_trigger()
770 else if (substream->stream == SNDRV_PCM_STREAM_CAPTURE) in rockchip_i2s_tdm_trigger()
776 return -EINVAL; in rockchip_i2s_tdm_trigger()
786 if (i2s_tdm->has_capture) in rockchip_i2s_tdm_dai_probe()
787 snd_soc_dai_dma_data_set_capture(dai, &i2s_tdm->capture_dma_data); in rockchip_i2s_tdm_dai_probe()
788 if (i2s_tdm->has_playback) in rockchip_i2s_tdm_dai_probe()
789 snd_soc_dai_dma_data_set_playback(dai, &i2s_tdm->playback_dma_data); in rockchip_i2s_tdm_dai_probe()
801 i2s_tdm->tdm_mode = true; in rockchip_dai_tdm_slot()
802 i2s_tdm->frame_width = slots * slot_width; in rockchip_dai_tdm_slot()
806 regmap_update_bits(i2s_tdm->regmap, I2S_TDM_TXCR, in rockchip_dai_tdm_slot()
808 regmap_update_bits(i2s_tdm->regmap, I2S_TDM_RXCR, in rockchip_dai_tdm_slot()
820 return -EINVAL; in rockchip_i2s_tdm_set_bclk_ratio()
822 i2s_tdm->frame_width = ratio; in rockchip_i2s_tdm_set_bclk_ratio()
935 const struct txrx_config *configs = i2s_tdm->soc_data->configs; in common_soc_init()
936 u32 reg = 0, val = 0, trcm = i2s_tdm->clk_trcm; in common_soc_init()
942 if (IS_ERR_OR_NULL(i2s_tdm->grf)) { in common_soc_init()
943 dev_err(i2s_tdm->dev, in common_soc_init()
944 "no grf present but non-txrx TRCM specified\n"); in common_soc_init()
945 return -EINVAL; in common_soc_init()
948 for (i = 0; i < i2s_tdm->soc_data->config_count; i++) { in common_soc_init()
958 regmap_write(i2s_tdm->grf, reg, val); in common_soc_init()
1028 { .compatible = "rockchip,px30-i2s-tdm", .data = &px30_i2s_soc_data },
1029 { .compatible = "rockchip,rk1808-i2s-tdm", .data = &rk1808_i2s_soc_data },
1030 { .compatible = "rockchip,rk3308-i2s-tdm", .data = &rk3308_i2s_soc_data },
1031 { .compatible = "rockchip,rk3568-i2s-tdm", .data = &rk3568_i2s_soc_data },
1032 { .compatible = "rockchip,rk3588-i2s-tdm" },
1033 { .compatible = "rockchip,rv1126-i2s-tdm", .data = &rv1126_i2s_soc_data },
1049 struct device_node *node = i2s_tdm->dev->of_node; in rockchip_i2s_tdm_init_dai()
1051 of_property_for_each_string(node, "dma-names", dma_names, dma_name) { in rockchip_i2s_tdm_init_dai()
1053 i2s_tdm->has_playback = true; in rockchip_i2s_tdm_init_dai()
1055 i2s_tdm->has_capture = true; in rockchip_i2s_tdm_init_dai()
1058 dai = devm_kmemdup(i2s_tdm->dev, &i2s_tdm_dai, in rockchip_i2s_tdm_init_dai()
1061 return -ENOMEM; in rockchip_i2s_tdm_init_dai()
1063 if (i2s_tdm->has_playback) { in rockchip_i2s_tdm_init_dai()
1064 dai->playback.stream_name = "Playback"; in rockchip_i2s_tdm_init_dai()
1065 dai->playback.channels_min = 2; in rockchip_i2s_tdm_init_dai()
1066 dai->playback.channels_max = 8; in rockchip_i2s_tdm_init_dai()
1067 dai->playback.rates = SNDRV_PCM_RATE_8000_192000; in rockchip_i2s_tdm_init_dai()
1068 dai->playback.formats = formats; in rockchip_i2s_tdm_init_dai()
1071 if (i2s_tdm->has_capture) { in rockchip_i2s_tdm_init_dai()
1072 dai->capture.stream_name = "Capture"; in rockchip_i2s_tdm_init_dai()
1073 dai->capture.channels_min = 2; in rockchip_i2s_tdm_init_dai()
1074 dai->capture.channels_max = 8; in rockchip_i2s_tdm_init_dai()
1075 dai->capture.rates = SNDRV_PCM_RATE_8000_192000; in rockchip_i2s_tdm_init_dai()
1076 dai->capture.formats = formats; in rockchip_i2s_tdm_init_dai()
1079 if (i2s_tdm->clk_trcm != TRCM_TXRX) in rockchip_i2s_tdm_init_dai()
1080 dai->symmetric_rate = 1; in rockchip_i2s_tdm_init_dai()
1082 i2s_tdm->dai = dai; in rockchip_i2s_tdm_init_dai()
1095 i2s_data = i2s_tdm->i2s_sdis; in rockchip_i2s_tdm_path_check()
1097 i2s_data = i2s_tdm->i2s_sdos; in rockchip_i2s_tdm_path_check()
1100 if (i2s_data[i] > CH_GRP_MAX - 1) { in rockchip_i2s_tdm_path_check()
1101 dev_err(i2s_tdm->dev, in rockchip_i2s_tdm_path_check()
1105 return -EINVAL; in rockchip_i2s_tdm_path_check()
1113 dev_err(i2s_tdm->dev, in rockchip_i2s_tdm_path_check()
1118 return -EINVAL; in rockchip_i2s_tdm_path_check()
1132 regmap_update_bits(i2s_tdm->regmap, I2S_TXCR, in rockchip_i2s_tdm_tx_path_config()
1134 I2S_TXCR_PATH(idx, i2s_tdm->i2s_sdos[idx])); in rockchip_i2s_tdm_tx_path_config()
1144 regmap_update_bits(i2s_tdm->regmap, I2S_RXCR, in rockchip_i2s_tdm_rx_path_config()
1146 I2S_RXCR_PATH(idx, i2s_tdm->i2s_sdis[idx])); in rockchip_i2s_tdm_rx_path_config()
1163 char *i2s_tx_path_prop = "rockchip,i2s-tx-route"; in rockchip_i2s_tdm_path_prepare()
1164 char *i2s_rx_path_prop = "rockchip,i2s-rx-route"; in rockchip_i2s_tdm_path_prepare()
1171 i2s_data = i2s_tdm->i2s_sdis; in rockchip_i2s_tdm_path_prepare()
1174 i2s_data = i2s_tdm->i2s_sdos; in rockchip_i2s_tdm_path_prepare()
1179 if (num != -ENOENT) { in rockchip_i2s_tdm_path_prepare()
1180 dev_err(i2s_tdm->dev, in rockchip_i2s_tdm_path_prepare()
1187 dev_err(i2s_tdm->dev, in rockchip_i2s_tdm_path_prepare()
1189 return -EINVAL; in rockchip_i2s_tdm_path_prepare()
1195 dev_err(i2s_tdm->dev, in rockchip_i2s_tdm_path_prepare()
1203 dev_err(i2s_tdm->dev, in rockchip_i2s_tdm_path_prepare()
1204 "Failed to check i2s data bus: %d\n", ret); in rockchip_i2s_tdm_path_prepare()
1227 struct device_node *node = pdev->dev.of_node; in rockchip_i2s_tdm_probe()
1231 void __iomem *regs; in rockchip_i2s_tdm_probe() local
1234 i2s_tdm = devm_kzalloc(&pdev->dev, sizeof(*i2s_tdm), GFP_KERNEL); in rockchip_i2s_tdm_probe()
1236 return -ENOMEM; in rockchip_i2s_tdm_probe()
1238 i2s_tdm->dev = &pdev->dev; in rockchip_i2s_tdm_probe()
1240 of_id = of_match_device(rockchip_i2s_tdm_match, &pdev->dev); in rockchip_i2s_tdm_probe()
1242 return -EINVAL; in rockchip_i2s_tdm_probe()
1244 spin_lock_init(&i2s_tdm->lock); in rockchip_i2s_tdm_probe()
1245 i2s_tdm->soc_data = (struct rk_i2s_soc_data *)of_id->data; in rockchip_i2s_tdm_probe()
1247 i2s_tdm->frame_width = 64; in rockchip_i2s_tdm_probe()
1249 i2s_tdm->clk_trcm = TRCM_TXRX; in rockchip_i2s_tdm_probe()
1250 if (of_property_read_bool(node, "rockchip,trcm-sync-tx-only")) in rockchip_i2s_tdm_probe()
1251 i2s_tdm->clk_trcm = TRCM_TX; in rockchip_i2s_tdm_probe()
1252 if (of_property_read_bool(node, "rockchip,trcm-sync-rx-only")) { in rockchip_i2s_tdm_probe()
1253 if (i2s_tdm->clk_trcm) { in rockchip_i2s_tdm_probe()
1254 dev_err(i2s_tdm->dev, "invalid trcm-sync configuration\n"); in rockchip_i2s_tdm_probe()
1255 return -EINVAL; in rockchip_i2s_tdm_probe()
1257 i2s_tdm->clk_trcm = TRCM_RX; in rockchip_i2s_tdm_probe()
1264 i2s_tdm->grf = syscon_regmap_lookup_by_phandle(node, "rockchip,grf"); in rockchip_i2s_tdm_probe()
1265 i2s_tdm->tx_reset = devm_reset_control_get_optional_exclusive(&pdev->dev, in rockchip_i2s_tdm_probe()
1266 "tx-m"); in rockchip_i2s_tdm_probe()
1267 if (IS_ERR(i2s_tdm->tx_reset)) { in rockchip_i2s_tdm_probe()
1268 ret = PTR_ERR(i2s_tdm->tx_reset); in rockchip_i2s_tdm_probe()
1269 return dev_err_probe(i2s_tdm->dev, ret, in rockchip_i2s_tdm_probe()
1270 "Error in tx-m reset control\n"); in rockchip_i2s_tdm_probe()
1273 i2s_tdm->rx_reset = devm_reset_control_get_optional_exclusive(&pdev->dev, in rockchip_i2s_tdm_probe()
1274 "rx-m"); in rockchip_i2s_tdm_probe()
1275 if (IS_ERR(i2s_tdm->rx_reset)) { in rockchip_i2s_tdm_probe()
1276 ret = PTR_ERR(i2s_tdm->rx_reset); in rockchip_i2s_tdm_probe()
1277 return dev_err_probe(i2s_tdm->dev, ret, in rockchip_i2s_tdm_probe()
1278 "Error in rx-m reset control\n"); in rockchip_i2s_tdm_probe()
1281 i2s_tdm->hclk = devm_clk_get(&pdev->dev, "hclk"); in rockchip_i2s_tdm_probe()
1282 if (IS_ERR(i2s_tdm->hclk)) { in rockchip_i2s_tdm_probe()
1283 return dev_err_probe(i2s_tdm->dev, PTR_ERR(i2s_tdm->hclk), in rockchip_i2s_tdm_probe()
1287 i2s_tdm->mclk_tx = devm_clk_get(&pdev->dev, "mclk_tx"); in rockchip_i2s_tdm_probe()
1288 if (IS_ERR(i2s_tdm->mclk_tx)) { in rockchip_i2s_tdm_probe()
1289 return dev_err_probe(i2s_tdm->dev, PTR_ERR(i2s_tdm->mclk_tx), in rockchip_i2s_tdm_probe()
1293 i2s_tdm->mclk_rx = devm_clk_get(&pdev->dev, "mclk_rx"); in rockchip_i2s_tdm_probe()
1294 if (IS_ERR(i2s_tdm->mclk_rx)) { in rockchip_i2s_tdm_probe()
1295 return dev_err_probe(i2s_tdm->dev, PTR_ERR(i2s_tdm->mclk_rx), in rockchip_i2s_tdm_probe()
1299 i2s_tdm->io_multiplex = in rockchip_i2s_tdm_probe()
1300 of_property_read_bool(node, "rockchip,io-multiplex"); in rockchip_i2s_tdm_probe()
1302 regs = devm_platform_get_and_ioremap_resource(pdev, 0, &res); in rockchip_i2s_tdm_probe()
1303 if (IS_ERR(regs)) { in rockchip_i2s_tdm_probe()
1304 return dev_err_probe(i2s_tdm->dev, PTR_ERR(regs), in rockchip_i2s_tdm_probe()
1308 i2s_tdm->regmap = devm_regmap_init_mmio(&pdev->dev, regs, in rockchip_i2s_tdm_probe()
1310 if (IS_ERR(i2s_tdm->regmap)) { in rockchip_i2s_tdm_probe()
1311 return dev_err_probe(i2s_tdm->dev, PTR_ERR(i2s_tdm->regmap), in rockchip_i2s_tdm_probe()
1315 if (i2s_tdm->has_playback) { in rockchip_i2s_tdm_probe()
1316 i2s_tdm->playback_dma_data.addr = res->start + I2S_TXDR; in rockchip_i2s_tdm_probe()
1317 i2s_tdm->playback_dma_data.addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES; in rockchip_i2s_tdm_probe()
1318 i2s_tdm->playback_dma_data.maxburst = 8; in rockchip_i2s_tdm_probe()
1321 if (i2s_tdm->has_capture) { in rockchip_i2s_tdm_probe()
1322 i2s_tdm->capture_dma_data.addr = res->start + I2S_RXDR; in rockchip_i2s_tdm_probe()
1323 i2s_tdm->capture_dma_data.addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES; in rockchip_i2s_tdm_probe()
1324 i2s_tdm->capture_dma_data.maxburst = 8; in rockchip_i2s_tdm_probe()
1329 dev_err(&pdev->dev, "I2S TX path prepare failed: %d\n", ret); in rockchip_i2s_tdm_probe()
1335 dev_err(&pdev->dev, "I2S RX path prepare failed: %d\n", ret); in rockchip_i2s_tdm_probe()
1339 dev_set_drvdata(&pdev->dev, i2s_tdm); in rockchip_i2s_tdm_probe()
1341 ret = clk_prepare_enable(i2s_tdm->hclk); in rockchip_i2s_tdm_probe()
1343 return dev_err_probe(i2s_tdm->dev, ret, in rockchip_i2s_tdm_probe()
1349 ret = dev_err_probe(i2s_tdm->dev, ret, in rockchip_i2s_tdm_probe()
1354 pm_runtime_enable(&pdev->dev); in rockchip_i2s_tdm_probe()
1356 regmap_update_bits(i2s_tdm->regmap, I2S_DMACR, I2S_DMACR_TDL_MASK, in rockchip_i2s_tdm_probe()
1358 regmap_update_bits(i2s_tdm->regmap, I2S_DMACR, I2S_DMACR_RDL_MASK, in rockchip_i2s_tdm_probe()
1360 regmap_update_bits(i2s_tdm->regmap, I2S_CKR, I2S_CKR_TRCM_MASK, in rockchip_i2s_tdm_probe()
1361 i2s_tdm->clk_trcm << I2S_CKR_TRCM_SHIFT); in rockchip_i2s_tdm_probe()
1363 if (i2s_tdm->soc_data && i2s_tdm->soc_data->init) in rockchip_i2s_tdm_probe()
1364 i2s_tdm->soc_data->init(&pdev->dev, res->start); in rockchip_i2s_tdm_probe()
1366 ret = devm_snd_soc_register_component(&pdev->dev, in rockchip_i2s_tdm_probe()
1368 i2s_tdm->dai, 1); in rockchip_i2s_tdm_probe()
1371 dev_err(&pdev->dev, "Could not register DAI\n"); in rockchip_i2s_tdm_probe()
1375 ret = devm_snd_dmaengine_pcm_register(&pdev->dev, NULL, 0); in rockchip_i2s_tdm_probe()
1377 dev_err(&pdev->dev, "Could not register PCM\n"); in rockchip_i2s_tdm_probe()
1384 if (!pm_runtime_status_suspended(&pdev->dev)) in rockchip_i2s_tdm_probe()
1385 i2s_tdm_runtime_suspend(&pdev->dev); in rockchip_i2s_tdm_probe()
1386 pm_runtime_disable(&pdev->dev); in rockchip_i2s_tdm_probe()
1389 clk_disable_unprepare(i2s_tdm->hclk); in rockchip_i2s_tdm_probe()
1396 if (!pm_runtime_status_suspended(&pdev->dev)) in rockchip_i2s_tdm_remove()
1397 i2s_tdm_runtime_suspend(&pdev->dev); in rockchip_i2s_tdm_remove()
1399 pm_runtime_disable(&pdev->dev); in rockchip_i2s_tdm_remove()
1408 regcache_mark_dirty(i2s_tdm->regmap); in rockchip_i2s_tdm_suspend()
1421 ret = regcache_sync(i2s_tdm->regmap); in rockchip_i2s_tdm_resume()
1445 MODULE_DESCRIPTION("ROCKCHIP I2S/TDM ASoC Interface");
1446 MODULE_AUTHOR("Sugar Zhang <sugar.zhang@rock-chips.com>");