Lines Matching +full:pclk +full:- +full:sample
1 // SPDX-License-Identifier: GPL-2.0-only
29 * ---- I2S Controller Register map ----
44 * ---- Control Register (Write-only) ----
55 * ---- Mode Register (Read/Write) ----
96 /* x sample transmitted when underrun */
98 #define ATMEL_I2SC_MR_TXSAME_ZERO (0 << 14) /* Zero sample */
99 #define ATMEL_I2SC_MR_TXSAME_PREVIOUS (1 << 14) /* Previous sample */
124 * ---- Status Registers ----
143 * ---- Interrupt Enable/Disable/Mask Registers ----
196 struct clk *pclk; member
212 regmap_read(dev->regmap, ATMEL_I2SC_SR, &sr); in atmel_i2s_interrupt()
213 regmap_read(dev->regmap, ATMEL_I2SC_IMR, &imr); in atmel_i2s_interrupt()
225 dev_err(dev->dev, in atmel_i2s_interrupt()
229 regmap_write(dev->regmap, ATMEL_I2SC_SCR, mask); in atmel_i2s_interrupt()
239 dev_err(dev->dev, in atmel_i2s_interrupt()
243 regmap_write(dev->regmap, ATMEL_I2SC_SCR, mask); in atmel_i2s_interrupt()
264 dev->fmt = fmt; in atmel_i2s_set_dai_fmt()
272 bool is_playback = (substream->stream == SNDRV_PCM_STREAM_PLAYBACK); in atmel_i2s_prepare()
276 regmap_read(dev->regmap, ATMEL_I2SC_SR, &sr); in atmel_i2s_prepare()
283 dev_dbg(dev->dev, "RXRDY is set\n"); in atmel_i2s_prepare()
284 regmap_read(dev->regmap, ATMEL_I2SC_RHR, &rhr); in atmel_i2s_prepare()
295 if (!dev->gclk) { in atmel_i2s_get_gck_param()
296 dev_err(dev->dev, "cannot generate the I2S Master Clock\n"); in atmel_i2s_get_gck_param()
297 return -EINVAL; in atmel_i2s_get_gck_param()
304 dev->gck_param = NULL; in atmel_i2s_get_gck_param()
308 int val = abs(fs - gck_param->fs); in atmel_i2s_get_gck_param()
312 dev->gck_param = gck_param; in atmel_i2s_get_gck_param()
324 bool is_playback = (substream->stream == SNDRV_PCM_STREAM_PLAYBACK); in atmel_i2s_hw_params()
335 switch (dev->fmt & SND_SOC_DAIFMT_FORMAT_MASK) { in atmel_i2s_hw_params()
341 dev_err(dev->dev, "unsupported bus format\n"); in atmel_i2s_hw_params()
342 return -EINVAL; in atmel_i2s_hw_params()
345 switch (dev->fmt & SND_SOC_DAIFMT_CLOCK_PROVIDER_MASK) { in atmel_i2s_hw_params()
357 dev->gck_param = NULL; in atmel_i2s_hw_params()
361 dev_err(dev->dev, "unsupported master/slave mode\n"); in atmel_i2s_hw_params()
362 return -EINVAL; in atmel_i2s_hw_params()
375 dev_err(dev->dev, "unsupported number of audio channels\n"); in atmel_i2s_hw_params()
376 return -EINVAL; in atmel_i2s_hw_params()
409 dev_err(dev->dev, "unsupported size/endianness for audio samples\n"); in atmel_i2s_hw_params()
410 return -EINVAL; in atmel_i2s_hw_params()
413 return regmap_update_bits(dev->regmap, ATMEL_I2SC_MR, mr_mask, mr); in atmel_i2s_hw_params()
430 ret = regmap_write(dev->regmap, ATMEL_I2SC_CR, in atmel_i2s_switch_mck_generator()
436 ret = regmap_update_bits(dev->regmap, ATMEL_I2SC_MR, in atmel_i2s_switch_mck_generator()
442 clk_disable_unprepare(dev->gclk); in atmel_i2s_switch_mck_generator()
447 if (!dev->gck_param) in atmel_i2s_switch_mck_generator()
448 return -EINVAL; in atmel_i2s_switch_mck_generator()
450 gclk_rate = dev->gck_param->mck * (dev->gck_param->imckdiv + 1); in atmel_i2s_switch_mck_generator()
452 ret = clk_set_rate(dev->gclk, gclk_rate); in atmel_i2s_switch_mck_generator()
456 ret = clk_prepare_enable(dev->gclk); in atmel_i2s_switch_mck_generator()
461 mr |= ATMEL_I2SC_MR_IMCKDIV(dev->gck_param->imckdiv); in atmel_i2s_switch_mck_generator()
462 mr |= ATMEL_I2SC_MR_IMCKFS(dev->gck_param->imckfs); in atmel_i2s_switch_mck_generator()
464 ret = regmap_update_bits(dev->regmap, ATMEL_I2SC_MR, mr_mask, mr); in atmel_i2s_switch_mck_generator()
469 return regmap_write(dev->regmap, ATMEL_I2SC_CR, in atmel_i2s_switch_mck_generator()
477 bool is_playback = (substream->stream == SNDRV_PCM_STREAM_PLAYBACK); in atmel_i2s_trigger()
496 return -EINVAL; in atmel_i2s_trigger()
500 err = regmap_read(dev->regmap, ATMEL_I2SC_MR, &mr); in atmel_i2s_trigger()
507 if (!dev->clk_use_no) { in atmel_i2s_trigger()
512 dev->clk_use_no++; in atmel_i2s_trigger()
515 err = regmap_write(dev->regmap, ATMEL_I2SC_CR, cr); in atmel_i2s_trigger()
521 if (dev->clk_use_no == 1) { in atmel_i2s_trigger()
526 dev->clk_use_no--; in atmel_i2s_trigger()
543 snd_soc_dai_init_dma_data(dai, &dev->playback, &dev->capture); in atmel_i2s_dai_probe()
567 .name = "atmel-i2s",
577 if (!dev->gclk) in atmel_i2s_sama5d2_mck_init()
581 muxclk = devm_clk_get(dev->dev, "muxclk"); in atmel_i2s_sama5d2_mck_init()
584 if (err == -EPROBE_DEFER) in atmel_i2s_sama5d2_mck_init()
585 return -EPROBE_DEFER; in atmel_i2s_sama5d2_mck_init()
586 dev_dbg(dev->dev, in atmel_i2s_sama5d2_mck_init()
591 return clk_set_parent(muxclk, dev->gclk); in atmel_i2s_sama5d2_mck_init()
600 .compatible = "atmel,sama5d2-i2s",
611 struct device_node *np = pdev->dev.of_node; in atmel_i2s_probe()
623 dev = devm_kzalloc(&pdev->dev, sizeof(*dev), GFP_KERNEL); in atmel_i2s_probe()
625 return -ENOMEM; in atmel_i2s_probe()
630 dev->caps = match->data; in atmel_i2s_probe()
637 regmap = devm_regmap_init_mmio(&pdev->dev, base, in atmel_i2s_probe()
647 err = devm_request_irq(&pdev->dev, irq, atmel_i2s_interrupt, 0, in atmel_i2s_probe()
648 dev_name(&pdev->dev), dev); in atmel_i2s_probe()
653 dev->pclk = devm_clk_get(&pdev->dev, "pclk"); in atmel_i2s_probe()
654 if (IS_ERR(dev->pclk)) { in atmel_i2s_probe()
655 err = PTR_ERR(dev->pclk); in atmel_i2s_probe()
656 dev_err(&pdev->dev, in atmel_i2s_probe()
662 dev->gclk = devm_clk_get(&pdev->dev, "gclk"); in atmel_i2s_probe()
663 if (IS_ERR(dev->gclk)) { in atmel_i2s_probe()
664 if (PTR_ERR(dev->gclk) == -EPROBE_DEFER) in atmel_i2s_probe()
665 return -EPROBE_DEFER; in atmel_i2s_probe()
667 dev->gclk = NULL; in atmel_i2s_probe()
669 dev->dev = &pdev->dev; in atmel_i2s_probe()
670 dev->regmap = regmap; in atmel_i2s_probe()
674 if (dev->caps && dev->caps->mck_init) { in atmel_i2s_probe()
675 err = dev->caps->mck_init(dev, np); in atmel_i2s_probe()
681 err = clk_prepare_enable(dev->pclk); in atmel_i2s_probe()
686 regmap_read(dev->regmap, ATMEL_I2SC_VERSION, &version); in atmel_i2s_probe()
687 dev_info(&pdev->dev, "hw version: %#x\n", version); in atmel_i2s_probe()
690 regmap_write(dev->regmap, ATMEL_I2SC_IER, in atmel_i2s_probe()
693 err = devm_snd_soc_register_component(&pdev->dev, in atmel_i2s_probe()
697 dev_err(&pdev->dev, "failed to register DAI: %d\n", err); in atmel_i2s_probe()
698 clk_disable_unprepare(dev->pclk); in atmel_i2s_probe()
703 dev->playback.addr = (dma_addr_t)mem->start + ATMEL_I2SC_THR; in atmel_i2s_probe()
704 dev->playback.maxburst = 1; in atmel_i2s_probe()
705 dev->capture.addr = (dma_addr_t)mem->start + ATMEL_I2SC_RHR; in atmel_i2s_probe()
706 dev->capture.maxburst = 1; in atmel_i2s_probe()
708 if (of_property_match_string(np, "dma-names", "rx-tx") == 0) in atmel_i2s_probe()
710 err = devm_snd_dmaengine_pcm_register(&pdev->dev, NULL, pcm_flags); in atmel_i2s_probe()
712 dev_err(&pdev->dev, "failed to register PCM: %d\n", err); in atmel_i2s_probe()
713 clk_disable_unprepare(dev->pclk); in atmel_i2s_probe()
724 clk_disable_unprepare(dev->pclk); in atmel_i2s_remove()