Lines Matching +full:sama5d2 +full:- +full:pdmic

1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /* Atmel PDMIC driver
18 #include "atmel-pdmic.h"
40 .compatible = "atmel,sama5d2-pdmic",
52 struct device_node *np = dev->of_node; in atmel_pdmic_dt_init()
57 return ERR_PTR(-EINVAL); in atmel_pdmic_dt_init()
62 return ERR_PTR(-ENOMEM); in atmel_pdmic_dt_init()
64 if (of_property_read_string(np, "atmel,model", &pdata->card_name)) in atmel_pdmic_dt_init()
65 pdata->card_name = "PDMIC"; in atmel_pdmic_dt_init()
67 if (of_property_read_u32(np, "atmel,mic-min-freq", in atmel_pdmic_dt_init()
68 &pdata->mic_min_freq)) { in atmel_pdmic_dt_init()
69 dev_err(dev, "failed to get mic-min-freq\n"); in atmel_pdmic_dt_init()
70 return ERR_PTR(-EINVAL); in atmel_pdmic_dt_init()
73 if (of_property_read_u32(np, "atmel,mic-max-freq", in atmel_pdmic_dt_init()
74 &pdata->mic_max_freq)) { in atmel_pdmic_dt_init()
75 dev_err(dev, "failed to get mic-max-freq\n"); in atmel_pdmic_dt_init()
76 return ERR_PTR(-EINVAL); in atmel_pdmic_dt_init()
79 if (pdata->mic_max_freq < pdata->mic_min_freq) { in atmel_pdmic_dt_init()
81 "mic-max-freq should not be less than mic-min-freq\n"); in atmel_pdmic_dt_init()
82 return ERR_PTR(-EINVAL); in atmel_pdmic_dt_init()
85 if (of_property_read_s32(np, "atmel,mic-offset", &pdata->mic_offset)) in atmel_pdmic_dt_init()
86 pdata->mic_offset = 0; in atmel_pdmic_dt_init()
88 if (pdata->mic_offset > PDMIC_OFFSET_MAX_VAL) { in atmel_pdmic_dt_init()
90 "mic-offset value %d is larger than the max value %d, the max value is specified\n", in atmel_pdmic_dt_init()
91 pdata->mic_offset, PDMIC_OFFSET_MAX_VAL); in atmel_pdmic_dt_init()
92 pdata->mic_offset = PDMIC_OFFSET_MAX_VAL; in atmel_pdmic_dt_init()
93 } else if (pdata->mic_offset < PDMIC_OFFSET_MIN_VAL) { in atmel_pdmic_dt_init()
95 "mic-offset value %d is less than the min value %d, the min value is specified\n", in atmel_pdmic_dt_init()
96 pdata->mic_offset, PDMIC_OFFSET_MIN_VAL); in atmel_pdmic_dt_init()
97 pdata->mic_offset = PDMIC_OFFSET_MIN_VAL; in atmel_pdmic_dt_init()
108 struct atmel_pdmic *dd = snd_soc_card_get_drvdata(rtd->card); in atmel_pdmic_cpu_dai_startup()
111 ret = clk_prepare_enable(dd->gclk); in atmel_pdmic_cpu_dai_startup()
115 ret = clk_prepare_enable(dd->pclk); in atmel_pdmic_cpu_dai_startup()
117 clk_disable_unprepare(dd->gclk); in atmel_pdmic_cpu_dai_startup()
122 regmap_write(dd->regmap, PDMIC_CR, 0); in atmel_pdmic_cpu_dai_startup()
124 dd->substream = substream; in atmel_pdmic_cpu_dai_startup()
127 regmap_write(dd->regmap, PDMIC_IER, PDMIC_IER_OVRE); in atmel_pdmic_cpu_dai_startup()
136 struct atmel_pdmic *dd = snd_soc_card_get_drvdata(rtd->card); in atmel_pdmic_cpu_dai_shutdown()
139 regmap_write(dd->regmap, PDMIC_IDR, PDMIC_IDR_OVRE); in atmel_pdmic_cpu_dai_shutdown()
141 clk_disable_unprepare(dd->gclk); in atmel_pdmic_cpu_dai_shutdown()
142 clk_disable_unprepare(dd->pclk); in atmel_pdmic_cpu_dai_shutdown()
149 struct atmel_pdmic *dd = snd_soc_card_get_drvdata(rtd->card); in atmel_pdmic_cpu_dai_prepare()
150 struct snd_soc_component *component = cpu_dai->component; in atmel_pdmic_cpu_dai_prepare()
154 /* Clean the PDMIC Converted Data Register */ in atmel_pdmic_cpu_dai_prepare()
155 ret = regmap_read(dd->regmap, PDMIC_CDR, &val); in atmel_pdmic_cpu_dai_prepare()
195 struct atmel_pdmic *dd = snd_soc_card_get_drvdata(rtd->card); in atmel_pdmic_platform_configure_dma()
201 dev_err(dd->dev, in atmel_pdmic_platform_configure_dma()
206 slave_config->src_addr = dd->phy_base + PDMIC_CDR; in atmel_pdmic_platform_configure_dma()
207 slave_config->src_maxburst = 1; in atmel_pdmic_platform_configure_dma()
208 slave_config->dst_maxburst = 1; in atmel_pdmic_platform_configure_dma()
221 /* Mic Gain = dgain * 2^(-scale) */
227 /* range from -90 dB to 90 dB */
229 { 1, 15}, { 1, 14}, /* -90, -84 dB */
230 { 3, 15}, { 1, 13}, { 3, 14}, { 1, 12}, /* -81, -78, -75, -72 dB */
231 { 5, 14}, { 13, 15}, /* -70, -68 dB */
232 { 9, 14}, { 21, 15}, { 23, 15}, { 13, 14}, /* -65 ~ -62 dB */
233 { 29, 15}, { 33, 15}, { 37, 15}, { 41, 15}, /* -61 ~ -58 dB */
234 { 23, 14}, { 13, 13}, { 58, 15}, { 65, 15}, /* -57 ~ -54 dB */
235 { 73, 15}, { 41, 14}, { 23, 13}, { 13, 12}, /* -53 ~ -50 dB */
236 { 29, 13}, { 65, 14}, { 73, 14}, { 41, 13}, /* -49 ~ -46 dB */
237 { 23, 12}, { 207, 15}, { 29, 12}, { 65, 13}, /* -45 ~ -42 dB */
238 { 73, 13}, { 41, 12}, { 23, 11}, { 413, 15}, /* -41 ~ -38 dB */
239 { 463, 15}, { 519, 15}, { 583, 15}, { 327, 14}, /* -37 ~ -34 dB */
240 { 367, 14}, { 823, 15}, { 231, 13}, { 1036, 15}, /* -33 ~ -30 dB */
241 { 1163, 15}, { 1305, 15}, { 183, 12}, { 1642, 15}, /* -29 ~ -26 dB */
242 { 1843, 15}, { 2068, 15}, { 145, 11}, { 2603, 15}, /* -25 ~ -22 dB */
243 { 365, 12}, { 3277, 15}, { 3677, 15}, { 4125, 15}, /* -21 ~ -18 dB */
244 { 4629, 15}, { 5193, 15}, { 5827, 15}, { 3269, 14}, /* -17 ~ -14 dB */
245 { 917, 12}, { 8231, 15}, { 9235, 15}, { 5181, 14}, /* -13 ~ -10 dB */
246 {11627, 15}, {13045, 15}, {14637, 15}, {16423, 15}, /* -9 ~ -6 dB */
247 {18427, 15}, {20675, 15}, { 5799, 13}, {26029, 15}, /* -5 ~ -2 dB */
248 { 7301, 13}, { 1, 0}, {18383, 14}, {10313, 13}, /* -1 ~ 2 dB */
274 0, 1, TLV_DB_SCALE_ITEM(-9000, 600, 0),
275 2, 5, TLV_DB_SCALE_ITEM(-8100, 300, 0),
276 6, 7, TLV_DB_SCALE_ITEM(-7000, 200, 0),
277 8, ARRAY_SIZE(mic_gain_table)-1, TLV_DB_SCALE_ITEM(-6500, 100, 0),
296 ucontrol->value.integer.value[0] = i; in pdmic_get_mic_volsw()
306 (struct soc_mixer_control *)kcontrol->private_value; in pdmic_put_mic_volsw()
308 int max = mc->max; in pdmic_put_mic_volsw()
312 val = ucontrol->value.integer.value[0]; in pdmic_put_mic_volsw()
315 return -EINVAL; in pdmic_put_mic_volsw()
332 ARRAY_SIZE(mic_gain_table)-1, 0,
347 (u32)(dd->pdata->mic_offset << PDMIC_DSPR1_OFFSET_SHIFT)); in atmel_pdmic_component_probe()
360 struct atmel_pdmic *dd = snd_soc_card_get_drvdata(rtd->card); in atmel_pdmic_cpu_dai_hw_params()
361 struct snd_soc_component *component = cpu_dai->component; in atmel_pdmic_cpu_dai_hw_params()
362 unsigned int rate_min = substream->runtime->hw.rate_min; in atmel_pdmic_cpu_dai_hw_params()
363 unsigned int rate_max = substream->runtime->hw.rate_max; in atmel_pdmic_cpu_dai_hw_params()
371 dev_err(component->dev, in atmel_pdmic_cpu_dai_hw_params()
373 return -EINVAL; in atmel_pdmic_cpu_dai_hw_params()
377 dev_err(component->dev, in atmel_pdmic_cpu_dai_hw_params()
381 return -EINVAL; in atmel_pdmic_cpu_dai_hw_params()
394 return -EINVAL; in atmel_pdmic_cpu_dai_hw_params()
405 pclk_rate = clk_get_rate(dd->pclk); in atmel_pdmic_cpu_dai_hw_params()
406 gclk_rate = clk_get_rate(dd->gclk); in atmel_pdmic_cpu_dai_hw_params()
408 /* PRESCAL = SELCK/(2*f_pdmic) - 1*/ in atmel_pdmic_cpu_dai_hw_params()
409 pclk_prescal = (u32)(pclk_rate/(f_pdmic << 1)) - 1; in atmel_pdmic_cpu_dai_hw_params()
410 gclk_prescal = (u32)(gclk_rate/(f_pdmic << 1)) - 1; in atmel_pdmic_cpu_dai_hw_params()
434 struct snd_soc_component *component = cpu_dai->component; in atmel_pdmic_cpu_dai_trigger()
449 return -EINVAL; in atmel_pdmic_cpu_dai_trigger()
478 .name = "atmel-pdmic",
497 return -ENOMEM; in atmel_pdmic_asoc_card_init()
501 return -ENOMEM; in atmel_pdmic_asoc_card_init()
503 dai_link->cpus = comp; in atmel_pdmic_asoc_card_init()
504 dai_link->codecs = &snd_soc_dummy_dlc; in atmel_pdmic_asoc_card_init()
506 dai_link->num_cpus = 1; in atmel_pdmic_asoc_card_init()
507 dai_link->num_codecs = 1; in atmel_pdmic_asoc_card_init()
509 dai_link->name = "PDMIC"; in atmel_pdmic_asoc_card_init()
510 dai_link->stream_name = "PDMIC PCM"; in atmel_pdmic_asoc_card_init()
511 dai_link->cpus->dai_name = dev_name(dev); in atmel_pdmic_asoc_card_init()
513 card->dai_link = dai_link; in atmel_pdmic_asoc_card_init()
514 card->num_links = 1; in atmel_pdmic_asoc_card_init()
515 card->name = dd->pdata->card_name; in atmel_pdmic_asoc_card_init()
516 card->dev = dev; in atmel_pdmic_asoc_card_init()
524 u32 mic_min_freq = dd->pdata->mic_min_freq; in atmel_pdmic_get_sample_rate()
525 u32 mic_max_freq = dd->pdata->mic_max_freq; in atmel_pdmic_get_sample_rate()
526 u32 clk_max_rate = (u32)(clk_get_rate(dd->pclk) >> 1); in atmel_pdmic_get_sample_rate()
527 u32 clk_min_rate = (u32)(clk_get_rate(dd->gclk) >> 8); in atmel_pdmic_get_sample_rate()
539 /* PDMIC interrupt handler */
546 regmap_read(dd->regmap, PDMIC_ISR, &pdmic_isr); in atmel_pdmic_interrupt()
549 regmap_update_bits(dd->regmap, PDMIC_CR, PDMIC_CR_ENPDM_MASK, in atmel_pdmic_interrupt()
552 snd_pcm_stop_xrun(dd->substream); in atmel_pdmic_interrupt()
571 struct device *dev = &pdev->dev; in atmel_pdmic_probe()
586 return -ENOMEM; in atmel_pdmic_probe()
588 dd->pdata = pdata; in atmel_pdmic_probe()
589 dd->dev = dev; in atmel_pdmic_probe()
591 dd->irq = platform_get_irq(pdev, 0); in atmel_pdmic_probe()
592 if (dd->irq < 0) in atmel_pdmic_probe()
593 return dd->irq; in atmel_pdmic_probe()
595 dd->pclk = devm_clk_get(dev, "pclk"); in atmel_pdmic_probe()
596 if (IS_ERR(dd->pclk)) { in atmel_pdmic_probe()
597 ret = PTR_ERR(dd->pclk); in atmel_pdmic_probe()
602 dd->gclk = devm_clk_get(dev, "gclk"); in atmel_pdmic_probe()
603 if (IS_ERR(dd->gclk)) { in atmel_pdmic_probe()
604 ret = PTR_ERR(dd->gclk); in atmel_pdmic_probe()
612 ret = clk_set_rate(dd->gclk, clk_get_rate(dd->pclk)/3); in atmel_pdmic_probe()
622 dd->phy_base = res->start; in atmel_pdmic_probe()
624 dd->regmap = devm_regmap_init_mmio(dev, io_base, in atmel_pdmic_probe()
626 if (IS_ERR(dd->regmap)) { in atmel_pdmic_probe()
627 ret = PTR_ERR(dd->regmap); in atmel_pdmic_probe()
632 ret = devm_request_irq(dev, dd->irq, atmel_pdmic_interrupt, 0, in atmel_pdmic_probe()
633 "PDMIC", (void *)dd); in atmel_pdmic_probe()
636 dd->irq, ret); in atmel_pdmic_probe()
666 ret = -ENOMEM; in atmel_pdmic_probe()
692 .name = "atmel-pdmic",
700 MODULE_DESCRIPTION("Atmel PDMIC driver under ALSA SoC architecture");