Lines Matching +full:dmic +full:- +full:sample +full:- +full:rate

1 // SPDX-License-Identifier: GPL-2.0-or-later
3 // This driver supports the DMIC in Allwinner's H6 SoCs.
93 if (substream->stream != SNDRV_PCM_STREAM_CAPTURE)
94 return -EINVAL;
96 regmap_update_bits(host->regmap, SUN50I_DMIC_RXFIFO_CTL,
99 regmap_write(host->regmap, SUN50I_DMIC_CNT, SUN50I_DMIC_CNT_N);
109 unsigned long rate = params_rate(params);
112 unsigned int chan_en = (1 << channels) - 1;
115 /* DMIC num is N+1 */
116 regmap_update_bits(host->regmap, SUN50I_DMIC_CH_NUM,
118 SUN50I_DMIC_CH_NUM_N(channels - 1));
119 regmap_write(host->regmap, SUN50I_DMIC_HPF_CTRL, chan_en);
120 regmap_update_bits(host->regmap, SUN50I_DMIC_EN_CTL,
126 regmap_update_bits(host->regmap, SUN50I_DMIC_RXFIFO_CTL,
131 regmap_update_bits(host->regmap, SUN50I_DMIC_RXFIFO_CTL,
136 dev_err(cpu_dai->dev, "Invalid format!\n");
137 return -EINVAL;
139 /* The hardware supports FIFO mode 1 for 24-bit samples */
140 regmap_update_bits(host->regmap, SUN50I_DMIC_RXFIFO_CTL,
144 switch (rate) {
159 dev_err(cpu_dai->dev, "Invalid rate!\n");
160 return -EINVAL;
163 if (clk_set_rate(host->dmic_clk, mclk)) {
164 dev_err(cpu_dai->dev, "mclk : %u not support\n", mclk);
165 return -EINVAL;
169 if (dmic_rate_s[i].samplerate == rate) {
170 regmap_update_bits(host->regmap, SUN50I_DMIC_SR,
179 host->dma_params_rx.addr_width = DMA_SLAVE_BUSWIDTH_2_BYTES;
182 host->dma_params_rx.addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES;
185 dev_err(cpu_dai->dev, "Unsupported physical sample width: %d\n",
187 return -EINVAL;
192 regmap_update_bits(host->regmap, SUN50I_DMIC_CTL,
196 regmap_update_bits(host->regmap, SUN50I_DMIC_CTL,
208 if (substream->stream != SNDRV_PCM_STREAM_CAPTURE)
209 return -EINVAL;
216 regmap_update_bits(host->regmap, SUN50I_DMIC_INTC,
220 regmap_update_bits(host->regmap, SUN50I_DMIC_EN_CTL,
228 regmap_update_bits(host->regmap, SUN50I_DMIC_INTC,
231 regmap_update_bits(host->regmap, SUN50I_DMIC_EN_CTL,
235 ret = -EINVAL;
245 snd_soc_dai_init_dma_data(dai, NULL, &host->dma_params_rx);
277 .name = "dmic",
282 .compatible = "allwinner,sun50i-h6-dmic",
288 static const SNDRV_CTL_TLVD_DECLARE_DB_SCALE(sun50i_dmic_vol_scale, -12000, 75, 1);
292 SOC_DOUBLE_TLV("DMIC Channel 0 Capture Volume", SUN50I_DMIC_D0D1_VOL_CTR,
295 SOC_DOUBLE_TLV("DMIC Channel 1 Capture Volume", SUN50I_DMIC_D0D1_VOL_CTR,
298 SOC_DOUBLE_TLV("DMIC Channel 2 Capture Volume", SUN50I_DMIC_D2D3_VOL_CTR,
301 SOC_DOUBLE_TLV("DMIC Channel 3 Capture Volume", SUN50I_DMIC_D2D3_VOL_CTR,
309 .name = "sun50i-dmic",
318 clk_disable_unprepare(host->dmic_clk);
319 clk_disable_unprepare(host->bus_clk);
329 ret = clk_prepare_enable(host->dmic_clk);
333 ret = clk_prepare_enable(host->bus_clk);
335 clk_disable_unprepare(host->dmic_clk);
349 host = devm_kzalloc(&pdev->dev, sizeof(*host), GFP_KERNEL);
351 return -ENOMEM;
356 return dev_err_probe(&pdev->dev, PTR_ERR(base),
359 host->regmap = devm_regmap_init_mmio(&pdev->dev, base,
363 host->bus_clk = devm_clk_get(&pdev->dev, "bus");
364 if (IS_ERR(host->bus_clk))
365 return dev_err_probe(&pdev->dev, PTR_ERR(host->bus_clk),
368 host->dmic_clk = devm_clk_get(&pdev->dev, "mod");
369 if (IS_ERR(host->dmic_clk))
370 return dev_err_probe(&pdev->dev, PTR_ERR(host->dmic_clk),
371 "failed to get dmic clock.\n");
373 host->dma_params_rx.addr = res->start + SUN50I_DMIC_DATA;
374 host->dma_params_rx.maxburst = 8;
378 host->rst = devm_reset_control_get_optional_exclusive(&pdev->dev, NULL);
379 if (IS_ERR(host->rst))
380 return dev_err_probe(&pdev->dev, PTR_ERR(host->rst),
382 reset_control_deassert(host->rst);
384 ret = devm_snd_soc_register_component(&pdev->dev, &sun50i_dmic_component,
387 return dev_err_probe(&pdev->dev, ret,
390 pm_runtime_enable(&pdev->dev);
391 if (!pm_runtime_enabled(&pdev->dev)) {
392 ret = sun50i_dmic_runtime_resume(&pdev->dev);
397 ret = devm_snd_dmaengine_pcm_register(&pdev->dev, NULL, 0);
403 if (!pm_runtime_status_suspended(&pdev->dev))
404 sun50i_dmic_runtime_suspend(&pdev->dev);
406 pm_runtime_disable(&pdev->dev);
412 pm_runtime_disable(&pdev->dev);
413 if (!pm_runtime_status_suspended(&pdev->dev))
414 sun50i_dmic_runtime_suspend(&pdev->dev);
424 .name = "sun50i-dmic",
434 MODULE_DESCRIPTION("Allwinner sun50i DMIC SoC Interface");
437 MODULE_ALIAS("platform:sun50i-dmic");