Lines Matching full:i2s
3 * Xtfpga I2S controller driver
17 #define DRV_NAME "xtfpga-i2s"
46 * I2S controller operation:
76 unsigned (*tx_fn)(struct xtfpga_i2s *i2s,
126 * If I2S interface is configured with smaller sample resolution, only
131 struct xtfpga_i2s *i2s, struct snd_pcm_runtime *runtime, \
137 for (; i2s->tx_fifo_level < i2s->tx_fifo_high; \
138 i2s->tx_fifo_level += 2) { \
140 i2s->regs + XTFPGA_I2S_CHAN0_DATA); \
142 i2s->regs + XTFPGA_I2S_CHAN0_DATA); \
156 static bool xtfpga_pcm_push_tx(struct xtfpga_i2s *i2s) in xtfpga_pcm_push_tx() argument
162 tx_substream = rcu_dereference(i2s->tx_substream); in xtfpga_pcm_push_tx()
165 unsigned tx_ptr = READ_ONCE(i2s->tx_ptr); in xtfpga_pcm_push_tx()
166 unsigned new_tx_ptr = i2s->tx_fn(i2s, tx_substream->runtime, in xtfpga_pcm_push_tx()
169 cmpxchg(&i2s->tx_ptr, tx_ptr, new_tx_ptr); in xtfpga_pcm_push_tx()
176 static void xtfpga_pcm_refill_fifo(struct xtfpga_i2s *i2s) in xtfpga_pcm_refill_fifo() argument
181 regmap_read(i2s->regmap, XTFPGA_I2S_INT_STATUS, in xtfpga_pcm_refill_fifo()
185 bool tx_active = xtfpga_pcm_push_tx(i2s); in xtfpga_pcm_refill_fifo()
187 regmap_write(i2s->regmap, XTFPGA_I2S_INT_STATUS, in xtfpga_pcm_refill_fifo()
190 regmap_read(i2s->regmap, XTFPGA_I2S_INT_STATUS, in xtfpga_pcm_refill_fifo()
201 i2s->tx_fifo_level = i2s->tx_fifo_low; in xtfpga_pcm_refill_fifo()
205 regmap_write(i2s->regmap, XTFPGA_I2S_INT_MASK, in xtfpga_pcm_refill_fifo()
208 regmap_write(i2s->regmap, XTFPGA_I2S_INT_MASK, in xtfpga_pcm_refill_fifo()
212 regmap_update_bits(i2s->regmap, XTFPGA_I2S_CONFIG, in xtfpga_pcm_refill_fifo()
218 regmap_update_bits(i2s->regmap, XTFPGA_I2S_CONFIG, in xtfpga_pcm_refill_fifo()
225 struct xtfpga_i2s *i2s = dev_id; in xtfpga_i2s_threaded_irq_handler() local
229 regmap_read(i2s->regmap, XTFPGA_I2S_CONFIG, &config); in xtfpga_i2s_threaded_irq_handler()
230 regmap_read(i2s->regmap, XTFPGA_I2S_INT_MASK, &int_mask); in xtfpga_i2s_threaded_irq_handler()
231 regmap_read(i2s->regmap, XTFPGA_I2S_INT_STATUS, &int_status); in xtfpga_i2s_threaded_irq_handler()
241 i2s->tx_fifo_level = 0; in xtfpga_i2s_threaded_irq_handler()
242 regmap_update_bits(i2s->regmap, XTFPGA_I2S_CONFIG, in xtfpga_i2s_threaded_irq_handler()
248 i2s->tx_fifo_level = i2s->tx_fifo_low; in xtfpga_i2s_threaded_irq_handler()
252 tx_substream = rcu_dereference(i2s->tx_substream); in xtfpga_i2s_threaded_irq_handler()
257 dev_dbg_ratelimited(i2s->dev, "%s: underrun\n", in xtfpga_i2s_threaded_irq_handler()
265 xtfpga_pcm_refill_fifo(i2s); in xtfpga_i2s_threaded_irq_handler()
273 struct xtfpga_i2s *i2s = snd_soc_dai_get_drvdata(dai); in xtfpga_i2s_startup() local
275 snd_soc_dai_set_dma_data(dai, substream, i2s); in xtfpga_i2s_startup()
283 struct xtfpga_i2s *i2s = snd_soc_dai_get_drvdata(dai); in xtfpga_i2s_hw_params() local
291 regmap_update_bits(i2s->regmap, XTFPGA_I2S_CONFIG, in xtfpga_i2s_hw_params()
296 err = clk_set_rate(i2s->clk, freq); in xtfpga_i2s_hw_params()
300 /* ratio field of the config register controls MCLK->I2S clock in xtfpga_i2s_hw_params()
301 * derivation: I2S clock = MCLK / (2 * (ratio + 2)). in xtfpga_i2s_hw_params()
309 regmap_update_bits(i2s->regmap, XTFPGA_I2S_CONFIG, in xtfpga_i2s_hw_params()
313 i2s->tx_fifo_low = XTFPGA_I2S_FIFO_SIZE / 2; in xtfpga_i2s_hw_params()
317 i2s->tx_fifo_low / 2 >= period_size * 2 && in xtfpga_i2s_hw_params()
320 i2s->tx_fifo_low /= 2; in xtfpga_i2s_hw_params()
322 i2s->tx_fifo_high = 2 * i2s->tx_fifo_low; in xtfpga_i2s_hw_params()
324 regmap_update_bits(i2s->regmap, XTFPGA_I2S_CONFIG, in xtfpga_i2s_hw_params()
328 dev_dbg(i2s->dev, in xtfpga_i2s_hw_params()
331 dev_dbg(i2s->dev, "%s freq: %u, ratio: %u, level: %u\n", in xtfpga_i2s_hw_params()
394 struct xtfpga_i2s *i2s = runtime->private_data; in xtfpga_pcm_hw_params() local
409 i2s->tx_fn = (channels == 1) ? in xtfpga_pcm_hw_params()
415 i2s->tx_fn = (channels == 1) ? in xtfpga_pcm_hw_params()
432 struct xtfpga_i2s *i2s = runtime->private_data; in xtfpga_pcm_trigger() local
438 WRITE_ONCE(i2s->tx_ptr, 0); in xtfpga_pcm_trigger()
439 rcu_assign_pointer(i2s->tx_substream, substream); in xtfpga_pcm_trigger()
440 xtfpga_pcm_refill_fifo(i2s); in xtfpga_pcm_trigger()
446 rcu_assign_pointer(i2s->tx_substream, NULL); in xtfpga_pcm_trigger()
460 struct xtfpga_i2s *i2s = runtime->private_data; in xtfpga_pcm_pointer() local
461 snd_pcm_uframes_t pos = READ_ONCE(i2s->tx_ptr); in xtfpga_pcm_pointer()
496 .name = "xtfpga-i2s",
511 struct xtfpga_i2s *i2s = dev_get_drvdata(dev); in xtfpga_i2s_runtime_suspend() local
513 clk_disable_unprepare(i2s->clk); in xtfpga_i2s_runtime_suspend()
519 struct xtfpga_i2s *i2s = dev_get_drvdata(dev); in xtfpga_i2s_runtime_resume() local
522 ret = clk_prepare_enable(i2s->clk); in xtfpga_i2s_runtime_resume()
532 struct xtfpga_i2s *i2s; in xtfpga_i2s_probe() local
535 i2s = devm_kzalloc(&pdev->dev, sizeof(*i2s), GFP_KERNEL); in xtfpga_i2s_probe()
536 if (!i2s) { in xtfpga_i2s_probe()
540 platform_set_drvdata(pdev, i2s); in xtfpga_i2s_probe()
541 i2s->dev = &pdev->dev; in xtfpga_i2s_probe()
542 dev_dbg(&pdev->dev, "dev: %p, i2s: %p\n", &pdev->dev, i2s); in xtfpga_i2s_probe()
544 i2s->regs = devm_platform_ioremap_resource(pdev, 0); in xtfpga_i2s_probe()
545 if (IS_ERR(i2s->regs)) { in xtfpga_i2s_probe()
546 err = PTR_ERR(i2s->regs); in xtfpga_i2s_probe()
550 i2s->regmap = devm_regmap_init_mmio(&pdev->dev, i2s->regs, in xtfpga_i2s_probe()
552 if (IS_ERR(i2s->regmap)) { in xtfpga_i2s_probe()
554 err = PTR_ERR(i2s->regmap); in xtfpga_i2s_probe()
558 i2s->clk = devm_clk_get(&pdev->dev, NULL); in xtfpga_i2s_probe()
559 if (IS_ERR(i2s->clk)) { in xtfpga_i2s_probe()
561 err = PTR_ERR(i2s->clk); in xtfpga_i2s_probe()
565 regmap_write(i2s->regmap, XTFPGA_I2S_CONFIG, in xtfpga_i2s_probe()
567 regmap_write(i2s->regmap, XTFPGA_I2S_INT_STATUS, XTFPGA_I2S_INT_VALID); in xtfpga_i2s_probe()
568 regmap_write(i2s->regmap, XTFPGA_I2S_INT_MASK, XTFPGA_I2S_INT_UNDERRUN); in xtfpga_i2s_probe()
578 pdev->name, i2s); in xtfpga_i2s_probe()
610 struct xtfpga_i2s *i2s = dev_get_drvdata(&pdev->dev); in xtfpga_i2s_remove() local
612 if (i2s->regmap && !IS_ERR(i2s->regmap)) { in xtfpga_i2s_remove()
613 regmap_write(i2s->regmap, XTFPGA_I2S_CONFIG, 0); in xtfpga_i2s_remove()
614 regmap_write(i2s->regmap, XTFPGA_I2S_INT_MASK, 0); in xtfpga_i2s_remove()
615 regmap_write(i2s->regmap, XTFPGA_I2S_INT_STATUS, in xtfpga_i2s_remove()
626 { .compatible = "cdns,xtfpga-i2s", },
641 .name = "xtfpga-i2s",
650 MODULE_DESCRIPTION("xtfpga I2S controller driver");