Lines Matching full:i2s

4  * ALSA SoC Audio Layer - Rockchip I2S Controller driver
25 #define DRV_NAME "rockchip-i2s"
49 * I2S controller hopes to start the tx and rx together,
63 static int i2s_pinctrl_select_bclk_on(struct rk_i2s_dev *i2s) in i2s_pinctrl_select_bclk_on() argument
67 if (!IS_ERR(i2s->pinctrl) && !IS_ERR_OR_NULL(i2s->bclk_on)) in i2s_pinctrl_select_bclk_on()
68 ret = pinctrl_select_state(i2s->pinctrl, i2s->bclk_on); in i2s_pinctrl_select_bclk_on()
71 dev_err(i2s->dev, "bclk enable failed %d\n", ret); in i2s_pinctrl_select_bclk_on()
76 static int i2s_pinctrl_select_bclk_off(struct rk_i2s_dev *i2s) in i2s_pinctrl_select_bclk_off() argument
81 if (!IS_ERR(i2s->pinctrl) && !IS_ERR_OR_NULL(i2s->bclk_off)) in i2s_pinctrl_select_bclk_off()
82 ret = pinctrl_select_state(i2s->pinctrl, i2s->bclk_off); in i2s_pinctrl_select_bclk_off()
85 dev_err(i2s->dev, "bclk disable failed %d\n", ret); in i2s_pinctrl_select_bclk_off()
92 struct rk_i2s_dev *i2s = dev_get_drvdata(dev); in i2s_runtime_suspend() local
94 regcache_cache_only(i2s->regmap, true); in i2s_runtime_suspend()
95 clk_disable_unprepare(i2s->mclk); in i2s_runtime_suspend()
102 struct rk_i2s_dev *i2s = dev_get_drvdata(dev); in i2s_runtime_resume() local
105 ret = clk_prepare_enable(i2s->mclk); in i2s_runtime_resume()
107 dev_err(i2s->dev, "clock enable failed %d\n", ret); in i2s_runtime_resume()
111 regcache_cache_only(i2s->regmap, false); in i2s_runtime_resume()
112 regcache_mark_dirty(i2s->regmap); in i2s_runtime_resume()
114 ret = regcache_sync(i2s->regmap); in i2s_runtime_resume()
116 clk_disable_unprepare(i2s->mclk); in i2s_runtime_resume()
126 static int rockchip_snd_txctrl(struct rk_i2s_dev *i2s, int on) in rockchip_snd_txctrl() argument
131 spin_lock(&i2s->lock); in rockchip_snd_txctrl()
133 ret = regmap_update_bits(i2s->regmap, I2S_DMACR, in rockchip_snd_txctrl()
138 ret = regmap_update_bits(i2s->regmap, I2S_XFER, in rockchip_snd_txctrl()
143 i2s->tx_start = true; in rockchip_snd_txctrl()
145 i2s->tx_start = false; in rockchip_snd_txctrl()
147 ret = regmap_update_bits(i2s->regmap, I2S_DMACR, in rockchip_snd_txctrl()
153 if (!i2s->rx_start) { in rockchip_snd_txctrl()
154 ret = regmap_update_bits(i2s->regmap, I2S_XFER, in rockchip_snd_txctrl()
160 ret = regmap_update_bits(i2s->regmap, I2S_CLR, in rockchip_snd_txctrl()
165 ret = regmap_read_poll_timeout_atomic(i2s->regmap, in rockchip_snd_txctrl()
172 dev_warn(i2s->dev, "fail to clear: %d\n", ret); in rockchip_snd_txctrl()
176 spin_unlock(&i2s->lock); in rockchip_snd_txctrl()
178 dev_err(i2s->dev, "lrclk update failed\n"); in rockchip_snd_txctrl()
183 static int rockchip_snd_rxctrl(struct rk_i2s_dev *i2s, int on) in rockchip_snd_rxctrl() argument
188 spin_lock(&i2s->lock); in rockchip_snd_rxctrl()
190 ret = regmap_update_bits(i2s->regmap, I2S_DMACR, in rockchip_snd_rxctrl()
196 ret = regmap_update_bits(i2s->regmap, I2S_XFER, in rockchip_snd_rxctrl()
201 i2s->rx_start = true; in rockchip_snd_rxctrl()
203 i2s->rx_start = false; in rockchip_snd_rxctrl()
205 ret = regmap_update_bits(i2s->regmap, I2S_DMACR, in rockchip_snd_rxctrl()
211 if (!i2s->tx_start) { in rockchip_snd_rxctrl()
212 ret = regmap_update_bits(i2s->regmap, I2S_XFER, in rockchip_snd_rxctrl()
218 ret = regmap_update_bits(i2s->regmap, I2S_CLR, in rockchip_snd_rxctrl()
223 ret = regmap_read_poll_timeout_atomic(i2s->regmap, in rockchip_snd_rxctrl()
230 dev_warn(i2s->dev, "fail to clear: %d\n", ret); in rockchip_snd_rxctrl()
234 spin_unlock(&i2s->lock); in rockchip_snd_rxctrl()
236 dev_err(i2s->dev, "lrclk update failed\n"); in rockchip_snd_rxctrl()
244 struct rk_i2s_dev *i2s = to_info(cpu_dai); in rockchip_i2s_set_fmt() local
254 i2s->is_master_mode = true; in rockchip_i2s_set_fmt()
258 i2s->is_master_mode = false; in rockchip_i2s_set_fmt()
265 regmap_update_bits(i2s->regmap, I2S_CKR, mask, val); in rockchip_i2s_set_fmt()
294 regmap_update_bits(i2s->regmap, I2S_CKR, mask, val); in rockchip_i2s_set_fmt()
318 regmap_update_bits(i2s->regmap, I2S_TXCR, mask, val); in rockchip_i2s_set_fmt()
342 regmap_update_bits(i2s->regmap, I2S_RXCR, mask, val); in rockchip_i2s_set_fmt()
354 struct rk_i2s_dev *i2s = to_info(dai); in rockchip_i2s_hw_params() local
359 if (i2s->is_master_mode) { in rockchip_i2s_hw_params()
360 mclk_rate = clk_get_rate(i2s->mclk); in rockchip_i2s_hw_params()
361 bclk_rate = i2s->bclk_ratio * params_rate(params); in rockchip_i2s_hw_params()
367 regmap_update_bits(i2s->regmap, I2S_CKR, in rockchip_i2s_hw_params()
371 regmap_update_bits(i2s->regmap, I2S_CKR, in rockchip_i2s_hw_params()
412 dev_err(i2s->dev, "invalid channel: %d\n", in rockchip_i2s_hw_params()
418 regmap_update_bits(i2s->regmap, I2S_RXCR, in rockchip_i2s_hw_params()
422 regmap_update_bits(i2s->regmap, I2S_TXCR, in rockchip_i2s_hw_params()
426 if (!IS_ERR(i2s->grf) && i2s->pins) { in rockchip_i2s_hw_params()
427 regmap_read(i2s->regmap, I2S_TXCR, &val); in rockchip_i2s_hw_params()
445 val <<= i2s->pins->shift; in rockchip_i2s_hw_params()
446 val |= (I2S_IO_DIRECTION_MASK << i2s->pins->shift) << 16; in rockchip_i2s_hw_params()
447 regmap_write(i2s->grf, i2s->pins->reg_offset, val); in rockchip_i2s_hw_params()
450 regmap_update_bits(i2s->regmap, I2S_DMACR, I2S_DMACR_TDL_MASK, in rockchip_i2s_hw_params()
452 regmap_update_bits(i2s->regmap, I2S_DMACR, I2S_DMACR_RDL_MASK, in rockchip_i2s_hw_params()
459 regmap_update_bits(i2s->regmap, I2S_CKR, in rockchip_i2s_hw_params()
468 struct rk_i2s_dev *i2s = to_info(dai); in rockchip_i2s_trigger() local
476 ret = rockchip_snd_rxctrl(i2s, 1); in rockchip_i2s_trigger()
478 ret = rockchip_snd_txctrl(i2s, 1); in rockchip_i2s_trigger()
481 i2s_pinctrl_select_bclk_on(i2s); in rockchip_i2s_trigger()
487 if (!i2s->tx_start) in rockchip_i2s_trigger()
488 i2s_pinctrl_select_bclk_off(i2s); in rockchip_i2s_trigger()
489 ret = rockchip_snd_rxctrl(i2s, 0); in rockchip_i2s_trigger()
491 if (!i2s->rx_start) in rockchip_i2s_trigger()
492 i2s_pinctrl_select_bclk_off(i2s); in rockchip_i2s_trigger()
493 ret = rockchip_snd_txctrl(i2s, 0); in rockchip_i2s_trigger()
507 struct rk_i2s_dev *i2s = to_info(dai); in rockchip_i2s_set_bclk_ratio() local
509 i2s->bclk_ratio = ratio; in rockchip_i2s_set_bclk_ratio()
517 struct rk_i2s_dev *i2s = to_info(cpu_dai); in rockchip_i2s_set_sysclk() local
523 ret = clk_set_rate(i2s->mclk, freq); in rockchip_i2s_set_sysclk()
525 dev_err(i2s->dev, "Fail to set mclk %d\n", ret); in rockchip_i2s_set_sysclk()
532 struct rk_i2s_dev *i2s = snd_soc_dai_get_drvdata(dai); in rockchip_i2s_dai_probe() local
535 i2s->has_playback ? &i2s->playback_dma_data : NULL, in rockchip_i2s_dai_probe()
536 i2s->has_capture ? &i2s->capture_dma_data : NULL); in rockchip_i2s_dai_probe()
649 { .compatible = "rockchip,px30-i2s", },
650 { .compatible = "rockchip,rk1808-i2s", },
651 { .compatible = "rockchip,rk3036-i2s", },
652 { .compatible = "rockchip,rk3066-i2s", },
653 { .compatible = "rockchip,rk3128-i2s", },
654 { .compatible = "rockchip,rk3188-i2s", },
655 { .compatible = "rockchip,rk3228-i2s", },
656 { .compatible = "rockchip,rk3288-i2s", },
657 { .compatible = "rockchip,rk3308-i2s", },
658 { .compatible = "rockchip,rk3328-i2s", },
659 { .compatible = "rockchip,rk3366-i2s", },
660 { .compatible = "rockchip,rk3368-i2s", },
661 { .compatible = "rockchip,rk3399-i2s", .data = &rk3399_i2s_pins },
662 { .compatible = "rockchip,rv1126-i2s", },
666 static int rockchip_i2s_init_dai(struct rk_i2s_dev *i2s, struct resource *res, in rockchip_i2s_init_dai() argument
669 struct device_node *node = i2s->dev->of_node; in rockchip_i2s_init_dai()
677 i2s->has_playback = true; in rockchip_i2s_init_dai()
679 i2s->has_capture = true; in rockchip_i2s_init_dai()
682 dai = devm_kmemdup(i2s->dev, &rockchip_i2s_dai, in rockchip_i2s_init_dai()
687 if (i2s->has_playback) { in rockchip_i2s_init_dai()
698 i2s->playback_dma_data.addr = res->start + I2S_TXDR; in rockchip_i2s_init_dai()
699 i2s->playback_dma_data.addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES; in rockchip_i2s_init_dai()
700 i2s->playback_dma_data.maxburst = 8; in rockchip_i2s_init_dai()
708 if (i2s->has_capture) { in rockchip_i2s_init_dai()
719 i2s->capture_dma_data.addr = res->start + I2S_RXDR; in rockchip_i2s_init_dai()
720 i2s->capture_dma_data.addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES; in rockchip_i2s_init_dai()
721 i2s->capture_dma_data.maxburst = 8; in rockchip_i2s_init_dai()
739 struct rk_i2s_dev *i2s; in rockchip_i2s_probe() local
745 i2s = devm_kzalloc(&pdev->dev, sizeof(*i2s), GFP_KERNEL); in rockchip_i2s_probe()
746 if (!i2s) in rockchip_i2s_probe()
749 spin_lock_init(&i2s->lock); in rockchip_i2s_probe()
750 i2s->dev = &pdev->dev; in rockchip_i2s_probe()
752 i2s->grf = syscon_regmap_lookup_by_phandle(node, "rockchip,grf"); in rockchip_i2s_probe()
753 if (!IS_ERR(i2s->grf)) { in rockchip_i2s_probe()
758 i2s->pins = of_id->data; in rockchip_i2s_probe()
762 i2s->hclk = devm_clk_get(&pdev->dev, "i2s_hclk"); in rockchip_i2s_probe()
763 if (IS_ERR(i2s->hclk)) { in rockchip_i2s_probe()
764 dev_err(&pdev->dev, "Can't retrieve i2s bus clock\n"); in rockchip_i2s_probe()
765 return PTR_ERR(i2s->hclk); in rockchip_i2s_probe()
767 ret = clk_prepare_enable(i2s->hclk); in rockchip_i2s_probe()
769 dev_err(i2s->dev, "hclock enable failed %d\n", ret); in rockchip_i2s_probe()
773 i2s->mclk = devm_clk_get(&pdev->dev, "i2s_clk"); in rockchip_i2s_probe()
774 if (IS_ERR(i2s->mclk)) { in rockchip_i2s_probe()
775 dev_err(&pdev->dev, "Can't retrieve i2s master clock\n"); in rockchip_i2s_probe()
776 ret = PTR_ERR(i2s->mclk); in rockchip_i2s_probe()
786 i2s->regmap = devm_regmap_init_mmio(&pdev->dev, regs, in rockchip_i2s_probe()
788 if (IS_ERR(i2s->regmap)) { in rockchip_i2s_probe()
791 ret = PTR_ERR(i2s->regmap); in rockchip_i2s_probe()
795 i2s->bclk_ratio = 64; in rockchip_i2s_probe()
796 i2s->pinctrl = devm_pinctrl_get(&pdev->dev); in rockchip_i2s_probe()
797 if (!IS_ERR(i2s->pinctrl)) { in rockchip_i2s_probe()
798 i2s->bclk_on = pinctrl_lookup_state(i2s->pinctrl, "bclk_on"); in rockchip_i2s_probe()
799 if (!IS_ERR_OR_NULL(i2s->bclk_on)) { in rockchip_i2s_probe()
800 i2s->bclk_off = pinctrl_lookup_state(i2s->pinctrl, "bclk_off"); in rockchip_i2s_probe()
801 if (IS_ERR_OR_NULL(i2s->bclk_off)) { in rockchip_i2s_probe()
802 dev_err(&pdev->dev, "failed to find i2s bclk_off\n"); in rockchip_i2s_probe()
808 dev_dbg(&pdev->dev, "failed to find i2s pinctrl\n"); in rockchip_i2s_probe()
811 i2s_pinctrl_select_bclk_off(i2s); in rockchip_i2s_probe()
813 dev_set_drvdata(&pdev->dev, i2s); in rockchip_i2s_probe()
822 ret = rockchip_i2s_init_dai(i2s, res, &dai); in rockchip_i2s_probe()
849 clk_disable_unprepare(i2s->hclk); in rockchip_i2s_probe()
855 struct rk_i2s_dev *i2s = dev_get_drvdata(&pdev->dev); in rockchip_i2s_remove() local
861 clk_disable_unprepare(i2s->hclk); in rockchip_i2s_remove()