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 ----
199 struct clk *pclk; member
215 regmap_read(dev->regmap, ATMEL_I2SC_SR, &sr); in atmel_i2s_interrupt()
216 regmap_read(dev->regmap, ATMEL_I2SC_IMR, &imr); in atmel_i2s_interrupt()
228 dev_err(dev->dev, in atmel_i2s_interrupt()
232 regmap_write(dev->regmap, ATMEL_I2SC_SCR, mask); in atmel_i2s_interrupt()
242 dev_err(dev->dev, in atmel_i2s_interrupt()
246 regmap_write(dev->regmap, ATMEL_I2SC_SCR, mask); in atmel_i2s_interrupt()
267 dev->fmt = fmt; in atmel_i2s_set_dai_fmt()
275 bool is_playback = (substream->stream == SNDRV_PCM_STREAM_PLAYBACK); in atmel_i2s_prepare()
279 regmap_read(dev->regmap, ATMEL_I2SC_SR, &sr); in atmel_i2s_prepare()
286 dev_dbg(dev->dev, "RXRDY is set\n"); in atmel_i2s_prepare()
287 regmap_read(dev->regmap, ATMEL_I2SC_RHR, &rhr); in atmel_i2s_prepare()
298 if (!dev->gclk) { in atmel_i2s_get_gck_param()
299 dev_err(dev->dev, "cannot generate the I2S Master Clock\n"); in atmel_i2s_get_gck_param()
300 return -EINVAL; in atmel_i2s_get_gck_param()
307 dev->gck_param = NULL; in atmel_i2s_get_gck_param()
311 int val = abs(fs - gck_param->fs); in atmel_i2s_get_gck_param()
315 dev->gck_param = gck_param; in atmel_i2s_get_gck_param()
327 bool is_playback = (substream->stream == SNDRV_PCM_STREAM_PLAYBACK); in atmel_i2s_hw_params()
338 switch (dev->fmt & SND_SOC_DAIFMT_FORMAT_MASK) { in atmel_i2s_hw_params()
344 dev_err(dev->dev, "unsupported bus format\n"); in atmel_i2s_hw_params()
345 return -EINVAL; in atmel_i2s_hw_params()
348 switch (dev->fmt & SND_SOC_DAIFMT_CLOCK_PROVIDER_MASK) { in atmel_i2s_hw_params()
360 dev->gck_param = NULL; in atmel_i2s_hw_params()
364 dev_err(dev->dev, "unsupported master/slave mode\n"); in atmel_i2s_hw_params()
365 return -EINVAL; in atmel_i2s_hw_params()
378 dev_err(dev->dev, "unsupported number of audio channels\n"); in atmel_i2s_hw_params()
379 return -EINVAL; in atmel_i2s_hw_params()
412 dev_err(dev->dev, "unsupported size/endianness for audio samples\n"); in atmel_i2s_hw_params()
413 return -EINVAL; in atmel_i2s_hw_params()
416 return regmap_update_bits(dev->regmap, ATMEL_I2SC_MR, mr_mask, mr); in atmel_i2s_hw_params()
433 ret = regmap_write(dev->regmap, ATMEL_I2SC_CR, in atmel_i2s_switch_mck_generator()
439 ret = regmap_update_bits(dev->regmap, ATMEL_I2SC_MR, in atmel_i2s_switch_mck_generator()
445 clk_disable_unprepare(dev->gclk); in atmel_i2s_switch_mck_generator()
450 if (!dev->gck_param) in atmel_i2s_switch_mck_generator()
451 return -EINVAL; in atmel_i2s_switch_mck_generator()
453 gclk_rate = dev->gck_param->mck * (dev->gck_param->imckdiv + 1); in atmel_i2s_switch_mck_generator()
455 ret = clk_set_rate(dev->gclk, gclk_rate); in atmel_i2s_switch_mck_generator()
459 ret = clk_prepare_enable(dev->gclk); in atmel_i2s_switch_mck_generator()
464 mr |= ATMEL_I2SC_MR_IMCKDIV(dev->gck_param->imckdiv); in atmel_i2s_switch_mck_generator()
465 mr |= ATMEL_I2SC_MR_IMCKFS(dev->gck_param->imckfs); in atmel_i2s_switch_mck_generator()
467 ret = regmap_update_bits(dev->regmap, ATMEL_I2SC_MR, mr_mask, mr); in atmel_i2s_switch_mck_generator()
472 return regmap_write(dev->regmap, ATMEL_I2SC_CR, in atmel_i2s_switch_mck_generator()
480 bool is_playback = (substream->stream == SNDRV_PCM_STREAM_PLAYBACK); in atmel_i2s_trigger()
499 return -EINVAL; in atmel_i2s_trigger()
503 err = regmap_read(dev->regmap, ATMEL_I2SC_MR, &mr); in atmel_i2s_trigger()
510 if (!dev->clk_use_no) { in atmel_i2s_trigger()
515 dev->clk_use_no++; in atmel_i2s_trigger()
518 err = regmap_write(dev->regmap, ATMEL_I2SC_CR, cr); in atmel_i2s_trigger()
524 if (dev->clk_use_no == 1) { in atmel_i2s_trigger()
529 dev->clk_use_no--; in atmel_i2s_trigger()
539 snd_soc_dai_init_dma_data(dai, &dev->playback, &dev->capture); in atmel_i2s_dai_probe()
570 .name = "atmel-i2s",
580 if (!dev->gclk) in atmel_i2s_sama5d2_mck_init()
584 muxclk = devm_clk_get(dev->dev, "muxclk"); in atmel_i2s_sama5d2_mck_init()
587 if (err == -EPROBE_DEFER) in atmel_i2s_sama5d2_mck_init()
588 return -EPROBE_DEFER; in atmel_i2s_sama5d2_mck_init()
589 dev_dbg(dev->dev, in atmel_i2s_sama5d2_mck_init()
594 return clk_set_parent(muxclk, dev->gclk); in atmel_i2s_sama5d2_mck_init()
603 .compatible = "atmel,sama5d2-i2s",
614 struct device_node *np = pdev->dev.of_node; in atmel_i2s_probe()
626 dev = devm_kzalloc(&pdev->dev, sizeof(*dev), GFP_KERNEL); in atmel_i2s_probe()
628 return -ENOMEM; in atmel_i2s_probe()
633 dev->caps = match->data; in atmel_i2s_probe()
640 regmap = devm_regmap_init_mmio(&pdev->dev, base, in atmel_i2s_probe()
650 err = devm_request_irq(&pdev->dev, irq, atmel_i2s_interrupt, 0, in atmel_i2s_probe()
651 dev_name(&pdev->dev), dev); in atmel_i2s_probe()
656 dev->pclk = devm_clk_get(&pdev->dev, "pclk"); in atmel_i2s_probe()
657 if (IS_ERR(dev->pclk)) { in atmel_i2s_probe()
658 err = PTR_ERR(dev->pclk); in atmel_i2s_probe()
659 dev_err(&pdev->dev, in atmel_i2s_probe()
665 dev->gclk = devm_clk_get(&pdev->dev, "gclk"); in atmel_i2s_probe()
666 if (IS_ERR(dev->gclk)) { in atmel_i2s_probe()
667 if (PTR_ERR(dev->gclk) == -EPROBE_DEFER) in atmel_i2s_probe()
668 return -EPROBE_DEFER; in atmel_i2s_probe()
670 dev->gclk = NULL; in atmel_i2s_probe()
672 dev->dev = &pdev->dev; in atmel_i2s_probe()
673 dev->regmap = regmap; in atmel_i2s_probe()
677 if (dev->caps && dev->caps->mck_init) { in atmel_i2s_probe()
678 err = dev->caps->mck_init(dev, np); in atmel_i2s_probe()
684 err = clk_prepare_enable(dev->pclk); in atmel_i2s_probe()
689 regmap_read(dev->regmap, ATMEL_I2SC_VERSION, &version); in atmel_i2s_probe()
690 dev_info(&pdev->dev, "hw version: %#x\n", version); in atmel_i2s_probe()
693 regmap_write(dev->regmap, ATMEL_I2SC_IER, in atmel_i2s_probe()
696 err = devm_snd_soc_register_component(&pdev->dev, in atmel_i2s_probe()
700 dev_err(&pdev->dev, "failed to register DAI: %d\n", err); in atmel_i2s_probe()
701 clk_disable_unprepare(dev->pclk); in atmel_i2s_probe()
706 dev->playback.addr = (dma_addr_t)mem->start + ATMEL_I2SC_THR; in atmel_i2s_probe()
707 dev->playback.maxburst = 1; in atmel_i2s_probe()
708 dev->capture.addr = (dma_addr_t)mem->start + ATMEL_I2SC_RHR; in atmel_i2s_probe()
709 dev->capture.maxburst = 1; in atmel_i2s_probe()
711 if (of_property_match_string(np, "dma-names", "rx-tx") == 0) in atmel_i2s_probe()
713 err = devm_snd_dmaengine_pcm_register(&pdev->dev, NULL, pcm_flags); in atmel_i2s_probe()
715 dev_err(&pdev->dev, "failed to register PCM: %d\n", err); in atmel_i2s_probe()
716 clk_disable_unprepare(dev->pclk); in atmel_i2s_probe()
727 clk_disable_unprepare(dev->pclk); in atmel_i2s_remove()