Lines Matching +full:sama5d2 +full:- +full:classd

1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /* Atmel ALSA SoC Audio Class D Amplifier (CLASSD) driver
18 #include "atmel-classd.h"
40 .compatible = "atmel,sama5d2-classd",
49 struct device_node *np = dev->of_node; in atmel_classd_dt_init()
56 return ERR_PTR(-EINVAL); in atmel_classd_dt_init()
61 return ERR_PTR(-ENOMEM); in atmel_classd_dt_init()
63 ret = of_property_read_string(np, "atmel,pwm-type", &pwm_type_s); in atmel_classd_dt_init()
65 pdata->pwm_type = CLASSD_MR_PWMTYP_DIFF; in atmel_classd_dt_init()
67 pdata->pwm_type = CLASSD_MR_PWMTYP_SINGLE; in atmel_classd_dt_init()
70 "atmel,non-overlap-time", &pdata->non_overlap_time); in atmel_classd_dt_init()
72 pdata->non_overlap_enable = false; in atmel_classd_dt_init()
74 pdata->non_overlap_enable = true; in atmel_classd_dt_init()
76 ret = of_property_read_string(np, "atmel,model", &pdata->card_name); in atmel_classd_dt_init()
78 pdata->card_name = "CLASSD"; in atmel_classd_dt_init()
86 return ERR_PTR(-EINVAL); in atmel_classd_dt_init()
122 struct atmel_classd *dd = snd_soc_card_get_drvdata(rtd->card); in atmel_classd_cpu_dai_startup()
125 regmap_write(dd->regmap, CLASSD_THR, 0x0); in atmel_classd_cpu_dai_startup()
127 err = clk_prepare_enable(dd->pclk); in atmel_classd_cpu_dai_startup()
130 err = clk_prepare_enable(dd->gclk); in atmel_classd_cpu_dai_startup()
132 clk_disable_unprepare(dd->pclk); in atmel_classd_cpu_dai_startup()
145 struct atmel_classd *dd = snd_soc_card_get_drvdata(rtd->card); in atmel_classd_platform_configure_dma()
148 dev_err(dd->dev, in atmel_classd_platform_configure_dma()
149 "only supports 16-bit audio data\n"); in atmel_classd_platform_configure_dma()
150 return -EINVAL; in atmel_classd_platform_configure_dma()
154 slave_config->dst_addr_width = DMA_SLAVE_BUSWIDTH_2_BYTES; in atmel_classd_platform_configure_dma()
156 slave_config->dst_addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES; in atmel_classd_platform_configure_dma()
158 slave_config->direction = DMA_MEM_TO_DEV; in atmel_classd_platform_configure_dma()
159 slave_config->dst_addr = dd->phy_base + CLASSD_THR; in atmel_classd_platform_configure_dma()
160 slave_config->dst_maxburst = 1; in atmel_classd_platform_configure_dma()
161 slave_config->src_maxburst = 1; in atmel_classd_platform_configure_dma()
162 slave_config->device_fc = false; in atmel_classd_platform_configure_dma()
184 "Treble-12dB", "Treble-6dB",
185 "Medium-8dB", "Medium-3dB",
186 "Bass-12dB", "Bass-6dB",
207 static const DECLARE_TLV_DB_SCALE(classd_digital_tlv, -7800, 100, 1);
234 const struct atmel_classd_pdata *pdata = dd->pdata; in atmel_classd_component_probe()
238 val = pdata->pwm_type << CLASSD_MR_PWMTYP_SHIFT; in atmel_classd_component_probe()
241 if (pdata->non_overlap_enable) { in atmel_classd_component_probe()
246 switch (pdata->non_overlap_time) { in atmel_classd_component_probe()
266 dev_warn(component->dev, in atmel_classd_component_probe()
267 "non-overlapping value %d is invalid, the default value 10 is specified\n", in atmel_classd_component_probe()
268 pdata->non_overlap_time); in atmel_classd_component_probe()
275 dev_info(component->dev, in atmel_classd_component_probe()
276 "PWM modulation type is %s, non-overlapping is %s\n", in atmel_classd_component_probe()
277 pwm_type[pdata->pwm_type], in atmel_classd_component_probe()
278 pdata->non_overlap_enable?"enabled":"disabled"); in atmel_classd_component_probe()
288 return regcache_sync(dd->regmap); in atmel_classd_component_resume()
294 struct snd_soc_component *component = cpu_dai->component; in atmel_classd_cpu_dai_mute_stream()
342 struct atmel_classd *dd = snd_soc_card_get_drvdata(rtd->card); in atmel_classd_cpu_dai_hw_params()
343 struct snd_soc_component *component = cpu_dai->component; in atmel_classd_cpu_dai_hw_params()
351 best_val = abs(fs - sample_rates[0].rate); in atmel_classd_cpu_dai_hw_params()
354 cur_val = abs(fs - sample_rates[i].rate); in atmel_classd_cpu_dai_hw_params()
361 dev_dbg(component->dev, in atmel_classd_cpu_dai_hw_params()
365 clk_disable_unprepare(dd->gclk); in atmel_classd_cpu_dai_hw_params()
367 ret = clk_set_rate(dd->gclk, sample_rates[best].gclk_rate); in atmel_classd_cpu_dai_hw_params()
377 return clk_prepare_enable(dd->gclk); in atmel_classd_cpu_dai_hw_params()
385 struct atmel_classd *dd = snd_soc_card_get_drvdata(rtd->card); in atmel_classd_cpu_dai_shutdown()
387 clk_disable_unprepare(dd->gclk); in atmel_classd_cpu_dai_shutdown()
393 struct snd_soc_component *component = cpu_dai->component; in atmel_classd_cpu_dai_prepare()
406 struct snd_soc_component *component = cpu_dai->component; in atmel_classd_cpu_dai_trigger()
424 return -EINVAL; in atmel_classd_cpu_dai_trigger()
454 .name = "atmel-classd",
474 return -ENOMEM; in atmel_classd_asoc_card_init()
478 return -ENOMEM; in atmel_classd_asoc_card_init()
480 dai_link->cpus = &comp[0]; in atmel_classd_asoc_card_init()
481 dai_link->codecs = &snd_soc_dummy_dlc; in atmel_classd_asoc_card_init()
482 dai_link->platforms = &comp[1]; in atmel_classd_asoc_card_init()
484 dai_link->num_cpus = 1; in atmel_classd_asoc_card_init()
485 dai_link->num_codecs = 1; in atmel_classd_asoc_card_init()
486 dai_link->num_platforms = 1; in atmel_classd_asoc_card_init()
488 dai_link->name = "CLASSD"; in atmel_classd_asoc_card_init()
489 dai_link->stream_name = "CLASSD PCM"; in atmel_classd_asoc_card_init()
490 dai_link->cpus->dai_name = dev_name(dev); in atmel_classd_asoc_card_init()
491 dai_link->platforms->name = dev_name(dev); in atmel_classd_asoc_card_init()
493 card->dai_link = dai_link; in atmel_classd_asoc_card_init()
494 card->num_links = 1; in atmel_classd_asoc_card_init()
495 card->name = dd->pdata->card_name; in atmel_classd_asoc_card_init()
496 card->dev = dev; in atmel_classd_asoc_card_init()
520 struct device *dev = &pdev->dev; in atmel_classd_probe()
537 return -ENOMEM; in atmel_classd_probe()
539 dd->pdata = pdata; in atmel_classd_probe()
541 dd->irq = platform_get_irq(pdev, 0); in atmel_classd_probe()
542 if (dd->irq < 0) in atmel_classd_probe()
543 return dd->irq; in atmel_classd_probe()
545 dd->pclk = devm_clk_get(dev, "pclk"); in atmel_classd_probe()
546 if (IS_ERR(dd->pclk)) { in atmel_classd_probe()
547 ret = PTR_ERR(dd->pclk); in atmel_classd_probe()
552 dd->gclk = devm_clk_get(dev, "gclk"); in atmel_classd_probe()
553 if (IS_ERR(dd->gclk)) { in atmel_classd_probe()
554 ret = PTR_ERR(dd->gclk); in atmel_classd_probe()
563 dd->phy_base = res->start; in atmel_classd_probe()
564 dd->dev = dev; in atmel_classd_probe()
566 dd->regmap = devm_regmap_init_mmio(dev, io_base, in atmel_classd_probe()
568 if (IS_ERR(dd->regmap)) { in atmel_classd_probe()
569 ret = PTR_ERR(dd->regmap); in atmel_classd_probe()
593 ret = -ENOMEM; in atmel_classd_probe()
619 .name = "atmel-classd",
627 MODULE_DESCRIPTION("Atmel ClassD driver under ALSA SoC architecture");