Lines Matching refs:i2s
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()
667 static int rockchip_i2s_init_dai(struct rk_i2s_dev *i2s, struct resource *res, in rockchip_i2s_init_dai() argument
670 struct device_node *node = i2s->dev->of_node; in rockchip_i2s_init_dai()
678 i2s->has_playback = true; in rockchip_i2s_init_dai()
680 i2s->has_capture = true; in rockchip_i2s_init_dai()
683 dai = devm_kmemdup(i2s->dev, &rockchip_i2s_dai, in rockchip_i2s_init_dai()
688 if (i2s->has_playback) { in rockchip_i2s_init_dai()
699 i2s->playback_dma_data.addr = res->start + I2S_TXDR; in rockchip_i2s_init_dai()
700 i2s->playback_dma_data.addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES; in rockchip_i2s_init_dai()
701 i2s->playback_dma_data.maxburst = 8; in rockchip_i2s_init_dai()
709 if (i2s->has_capture) { in rockchip_i2s_init_dai()
720 i2s->capture_dma_data.addr = res->start + I2S_RXDR; in rockchip_i2s_init_dai()
721 i2s->capture_dma_data.addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES; in rockchip_i2s_init_dai()
722 i2s->capture_dma_data.maxburst = 8; in rockchip_i2s_init_dai()
740 struct rk_i2s_dev *i2s; in rockchip_i2s_probe() local
746 i2s = devm_kzalloc(&pdev->dev, sizeof(*i2s), GFP_KERNEL); in rockchip_i2s_probe()
747 if (!i2s) in rockchip_i2s_probe()
750 spin_lock_init(&i2s->lock); in rockchip_i2s_probe()
751 i2s->dev = &pdev->dev; in rockchip_i2s_probe()
753 i2s->grf = syscon_regmap_lookup_by_phandle(node, "rockchip,grf"); in rockchip_i2s_probe()
754 if (!IS_ERR(i2s->grf)) { in rockchip_i2s_probe()
759 i2s->pins = of_id->data; in rockchip_i2s_probe()
763 i2s->hclk = devm_clk_get(&pdev->dev, "i2s_hclk"); in rockchip_i2s_probe()
764 if (IS_ERR(i2s->hclk)) { in rockchip_i2s_probe()
766 return PTR_ERR(i2s->hclk); in rockchip_i2s_probe()
768 ret = clk_prepare_enable(i2s->hclk); in rockchip_i2s_probe()
770 dev_err(i2s->dev, "hclock enable failed %d\n", ret); in rockchip_i2s_probe()
774 i2s->mclk = devm_clk_get(&pdev->dev, "i2s_clk"); in rockchip_i2s_probe()
775 if (IS_ERR(i2s->mclk)) { in rockchip_i2s_probe()
777 ret = PTR_ERR(i2s->mclk); in rockchip_i2s_probe()
787 i2s->regmap = devm_regmap_init_mmio(&pdev->dev, regs, in rockchip_i2s_probe()
789 if (IS_ERR(i2s->regmap)) { in rockchip_i2s_probe()
792 ret = PTR_ERR(i2s->regmap); in rockchip_i2s_probe()
796 i2s->bclk_ratio = 64; in rockchip_i2s_probe()
797 i2s->pinctrl = devm_pinctrl_get(&pdev->dev); in rockchip_i2s_probe()
798 if (!IS_ERR(i2s->pinctrl)) { in rockchip_i2s_probe()
799 i2s->bclk_on = pinctrl_lookup_state(i2s->pinctrl, "bclk_on"); in rockchip_i2s_probe()
800 if (!IS_ERR_OR_NULL(i2s->bclk_on)) { in rockchip_i2s_probe()
801 i2s->bclk_off = pinctrl_lookup_state(i2s->pinctrl, "bclk_off"); in rockchip_i2s_probe()
802 if (IS_ERR_OR_NULL(i2s->bclk_off)) { in rockchip_i2s_probe()
812 i2s_pinctrl_select_bclk_off(i2s); in rockchip_i2s_probe()
814 dev_set_drvdata(&pdev->dev, i2s); in rockchip_i2s_probe()
823 ret = rockchip_i2s_init_dai(i2s, res, &dai); in rockchip_i2s_probe()
850 clk_disable_unprepare(i2s->hclk); in rockchip_i2s_probe()
856 struct rk_i2s_dev *i2s = dev_get_drvdata(&pdev->dev); in rockchip_i2s_remove() local
862 clk_disable_unprepare(i2s->hclk); in rockchip_i2s_remove()