Lines Matching +full:jz4740 +full:- +full:codec

1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Copyright (C) 2010, Lars-Peter Clausen <lars@metafoo.de>
9 #include <linux/dma-mapping.h>
105 if (!i2s->soc_info->shared_fifo_flush) { in jz4740_i2s_startup()
106 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) in jz4740_i2s_startup()
107 regmap_set_bits(i2s->regmap, JZ_REG_AIC_CTRL, JZ_AIC_CTRL_TFLUSH); in jz4740_i2s_startup()
109 regmap_set_bits(i2s->regmap, JZ_REG_AIC_CTRL, JZ_AIC_CTRL_RFLUSH); in jz4740_i2s_startup()
121 if (i2s->soc_info->shared_fifo_flush) in jz4740_i2s_startup()
122 regmap_set_bits(i2s->regmap, JZ_REG_AIC_CTRL, JZ_AIC_CTRL_TFLUSH); in jz4740_i2s_startup()
124 ret = clk_prepare_enable(i2s->clk_i2s); in jz4740_i2s_startup()
128 regmap_set_bits(i2s->regmap, JZ_REG_AIC_CONF, JZ_AIC_CONF_ENABLE); in jz4740_i2s_startup()
140 regmap_clear_bits(i2s->regmap, JZ_REG_AIC_CONF, JZ_AIC_CONF_ENABLE); in jz4740_i2s_shutdown()
142 clk_disable_unprepare(i2s->clk_i2s); in jz4740_i2s_shutdown()
151 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) in jz4740_i2s_trigger()
160 regmap_set_bits(i2s->regmap, JZ_REG_AIC_CTRL, mask); in jz4740_i2s_trigger()
165 regmap_clear_bits(i2s->regmap, JZ_REG_AIC_CTRL, mask); in jz4740_i2s_trigger()
168 return -EINVAL; in jz4740_i2s_trigger()
195 return -EINVAL; in jz4740_i2s_set_fmt()
205 return -EINVAL; in jz4740_i2s_set_fmt()
212 return -EINVAL; in jz4740_i2s_set_fmt()
215 regmap_update_bits(i2s->regmap, JZ_REG_AIC_CONF, conf_mask, conf); in jz4740_i2s_set_fmt()
216 regmap_write(i2s->regmap, JZ_REG_AIC_I2S_FMT, format); in jz4740_i2s_set_fmt()
233 err1 = abs(rate1 - rate); in jz4740_i2s_get_i2sdiv()
234 err2 = abs(rate2 - rate); in jz4740_i2s_get_i2sdiv()
248 return -EINVAL; in jz4740_i2s_get_i2sdiv()
261 regmap_read(i2s->regmap, JZ_REG_AIC_CTRL, &ctrl); in jz4740_i2s_hw_params()
262 regmap_read(i2s->regmap, JZ_REG_AIC_CONF, &conf); in jz4740_i2s_hw_params()
278 return -EINVAL; in jz4740_i2s_hw_params()
281 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { in jz4740_i2s_hw_params()
290 div_field = i2s->field_i2sdiv_playback; in jz4740_i2s_hw_params()
291 i2sdiv_max = GENMASK(i2s->soc_info->field_i2sdiv_playback.msb, in jz4740_i2s_hw_params()
292 i2s->soc_info->field_i2sdiv_playback.lsb); in jz4740_i2s_hw_params()
297 div_field = i2s->field_i2sdiv_capture; in jz4740_i2s_hw_params()
298 i2sdiv_max = GENMASK(i2s->soc_info->field_i2sdiv_capture.msb, in jz4740_i2s_hw_params()
299 i2s->soc_info->field_i2sdiv_capture.lsb); in jz4740_i2s_hw_params()
304 * If the codec is supplying both clocks then the divider output is in jz4740_i2s_hw_params()
308 div = jz4740_i2s_get_i2sdiv(clk_get_rate(i2s->clk_i2s), in jz4740_i2s_hw_params()
314 regmap_write(i2s->regmap, JZ_REG_AIC_CTRL, ctrl); in jz4740_i2s_hw_params()
315 regmap_field_write(div_field, div - 1); in jz4740_i2s_hw_params()
324 snd_soc_dai_init_dma_data(dai, &i2s->playback_dma_data, in jz4740_i2s_dai_probe()
325 &i2s->capture_dma_data); in jz4740_i2s_dai_probe()
423 regmap_clear_bits(i2s->regmap, JZ_REG_AIC_CONF, JZ_AIC_CONF_ENABLE); in jz4740_i2s_suspend()
424 clk_disable_unprepare(i2s->clk_i2s); in jz4740_i2s_suspend()
427 clk_disable_unprepare(i2s->clk_aic); in jz4740_i2s_suspend()
437 ret = clk_prepare_enable(i2s->clk_aic); in jz4740_i2s_resume()
442 ret = clk_prepare_enable(i2s->clk_i2s); in jz4740_i2s_resume()
444 clk_disable_unprepare(i2s->clk_aic); in jz4740_i2s_resume()
448 regmap_set_bits(i2s->regmap, JZ_REG_AIC_CONF, JZ_AIC_CONF_ENABLE); in jz4740_i2s_resume()
459 ret = clk_prepare_enable(i2s->clk_aic); in jz4740_i2s_probe()
463 regmap_write(i2s->regmap, JZ_REG_AIC_CONF, JZ_AIC_CONF_RESET); in jz4740_i2s_probe()
465 regmap_write(i2s->regmap, JZ_REG_AIC_CONF, in jz4740_i2s_probe()
469 regmap_field_write(i2s->field_rx_fifo_thresh, 7); in jz4740_i2s_probe()
470 regmap_field_write(i2s->field_tx_fifo_thresh, 8); in jz4740_i2s_probe()
479 clk_disable_unprepare(i2s->clk_aic); in jz4740_i2s_remove()
483 .name = "jz4740-i2s",
492 { .compatible = "ingenic,jz4740-i2s", .data = &jz4740_i2s_soc_info },
493 { .compatible = "ingenic,jz4760-i2s", .data = &jz4760_i2s_soc_info },
494 { .compatible = "ingenic,jz4770-i2s", .data = &jz4770_i2s_soc_info },
495 { .compatible = "ingenic,jz4780-i2s", .data = &jz4780_i2s_soc_info },
496 { .compatible = "ingenic,x1000-i2s", .data = &x1000_i2s_soc_info },
504 i2s->field_rx_fifo_thresh = in jz4740_i2s_init_regmap_fields()
505 devm_regmap_field_alloc(dev, i2s->regmap, in jz4740_i2s_init_regmap_fields()
506 i2s->soc_info->field_rx_fifo_thresh); in jz4740_i2s_init_regmap_fields()
507 if (IS_ERR(i2s->field_rx_fifo_thresh)) in jz4740_i2s_init_regmap_fields()
508 return PTR_ERR(i2s->field_rx_fifo_thresh); in jz4740_i2s_init_regmap_fields()
510 i2s->field_tx_fifo_thresh = in jz4740_i2s_init_regmap_fields()
511 devm_regmap_field_alloc(dev, i2s->regmap, in jz4740_i2s_init_regmap_fields()
512 i2s->soc_info->field_tx_fifo_thresh); in jz4740_i2s_init_regmap_fields()
513 if (IS_ERR(i2s->field_tx_fifo_thresh)) in jz4740_i2s_init_regmap_fields()
514 return PTR_ERR(i2s->field_tx_fifo_thresh); in jz4740_i2s_init_regmap_fields()
516 i2s->field_i2sdiv_capture = in jz4740_i2s_init_regmap_fields()
517 devm_regmap_field_alloc(dev, i2s->regmap, in jz4740_i2s_init_regmap_fields()
518 i2s->soc_info->field_i2sdiv_capture); in jz4740_i2s_init_regmap_fields()
519 if (IS_ERR(i2s->field_i2sdiv_capture)) in jz4740_i2s_init_regmap_fields()
520 return PTR_ERR(i2s->field_i2sdiv_capture); in jz4740_i2s_init_regmap_fields()
522 i2s->field_i2sdiv_playback = in jz4740_i2s_init_regmap_fields()
523 devm_regmap_field_alloc(dev, i2s->regmap, in jz4740_i2s_init_regmap_fields()
524 i2s->soc_info->field_i2sdiv_playback); in jz4740_i2s_init_regmap_fields()
525 if (IS_ERR(i2s->field_i2sdiv_playback)) in jz4740_i2s_init_regmap_fields()
526 return PTR_ERR(i2s->field_i2sdiv_playback); in jz4740_i2s_init_regmap_fields()
540 struct device *dev = &pdev->dev; in jz4740_i2s_dev_probe()
548 return -ENOMEM; in jz4740_i2s_dev_probe()
550 i2s->soc_info = device_get_match_data(dev); in jz4740_i2s_dev_probe()
556 i2s->playback_dma_data.maxburst = 16; in jz4740_i2s_dev_probe()
557 i2s->playback_dma_data.addr = mem->start + JZ_REG_AIC_FIFO; in jz4740_i2s_dev_probe()
559 i2s->capture_dma_data.maxburst = 16; in jz4740_i2s_dev_probe()
560 i2s->capture_dma_data.addr = mem->start + JZ_REG_AIC_FIFO; in jz4740_i2s_dev_probe()
562 i2s->clk_aic = devm_clk_get(dev, "aic"); in jz4740_i2s_dev_probe()
563 if (IS_ERR(i2s->clk_aic)) in jz4740_i2s_dev_probe()
564 return PTR_ERR(i2s->clk_aic); in jz4740_i2s_dev_probe()
566 i2s->clk_i2s = devm_clk_get(dev, "i2s"); in jz4740_i2s_dev_probe()
567 if (IS_ERR(i2s->clk_i2s)) in jz4740_i2s_dev_probe()
568 return PTR_ERR(i2s->clk_i2s); in jz4740_i2s_dev_probe()
570 i2s->regmap = devm_regmap_init_mmio(&pdev->dev, regs, in jz4740_i2s_dev_probe()
572 if (IS_ERR(i2s->regmap)) in jz4740_i2s_dev_probe()
573 return PTR_ERR(i2s->regmap); in jz4740_i2s_dev_probe()
582 i2s->soc_info->dai, 1); in jz4740_i2s_dev_probe()
593 .name = "jz4740-i2s",
600 MODULE_AUTHOR("Lars-Peter Clausen, <lars@metafoo.de>");
601 MODULE_DESCRIPTION("Ingenic JZ4740 SoC I2S driver");
603 MODULE_ALIAS("platform:jz4740-i2s");