Lines Matching +full:mt8195 +full:- +full:audio
1 // SPDX-License-Identifier: GPL-2.0
11 #include <linux/dma-mapping.h>
20 #include "mt8195-afe-common.h"
21 #include "mt8195-afe-clk.h"
22 #include "mt8195-reg.h"
23 #include "../common/mtk-afe-platform-driver.h"
24 #include "../common/mtk-afe-fe-dai.h"
81 return -EINVAL; in mt8195_afe_fs_timing()
91 int id = snd_soc_rtd_to_cpu(rtd, 0)->id; in mt8195_memif_fs()
92 struct mtk_base_afe_memif *memif = &afe->memif[id]; in mt8195_memif_fs()
95 switch (memif->data->id) { in mt8195_memif_fs()
211 int id = -EINVAL; in mt8195_afe_found_cm()
213 if (mt8195_afe_memif_is_ul(dai->id) == 0) in mt8195_afe_found_cm()
216 switch (dai->id) { in mt8195_afe_found_cm()
231 dev_dbg(afe->dev, "%s, memif %d cannot find CM!\n", in mt8195_afe_found_cm()
232 __func__, dai->id); in mt8195_afe_found_cm()
244 return -EINVAL; in mt8195_afe_config_cm()
246 regmap_update_bits(afe->regmap, in mt8195_afe_config_cm()
247 cm->reg, in mt8195_afe_config_cm()
248 cm->sel_maskbit << cm->sel_shift, in mt8195_afe_config_cm()
249 cm->sel_default << cm->sel_shift); in mt8195_afe_config_cm()
251 regmap_update_bits(afe->regmap, in mt8195_afe_config_cm()
252 cm->reg, in mt8195_afe_config_cm()
253 cm->ch_num_maskbit << cm->ch_num_shift, in mt8195_afe_config_cm()
254 (channels - 1) << cm->ch_num_shift); in mt8195_afe_config_cm()
256 regmap_update_bits(afe->regmap, in mt8195_afe_config_cm()
257 cm->reg, in mt8195_afe_config_cm()
258 cm->update_cnt_maskbit << cm->update_cnt_shift, in mt8195_afe_config_cm()
259 cm->update_cnt_default << cm->update_cnt_shift); in mt8195_afe_config_cm()
269 return -EINVAL; in mt8195_afe_enable_cm()
271 regmap_update_bits(afe->regmap, in mt8195_afe_enable_cm()
272 cm->reg, in mt8195_afe_enable_cm()
273 cm->en_maskbit << cm->en_shift, in mt8195_afe_enable_cm()
274 enable << cm->en_shift); in mt8195_afe_enable_cm()
286 struct mt8195_afe_private *afe_priv = afe->platform_priv; in mt8195_afe_paired_memif_clk_prepare()
287 int id = snd_soc_rtd_to_cpu(rtd, 0)->id; in mt8195_afe_paired_memif_clk_prepare()
295 mt8195_afe_prepare_clk(afe, afe_priv->clk[clk_id]); in mt8195_afe_paired_memif_clk_prepare()
297 mt8195_afe_prepare_clk(afe, afe_priv->clk[clk_id]); in mt8195_afe_paired_memif_clk_prepare()
300 mt8195_afe_unprepare_clk(afe, afe_priv->clk[clk_id]); in mt8195_afe_paired_memif_clk_prepare()
302 mt8195_afe_unprepare_clk(afe, afe_priv->clk[clk_id]); in mt8195_afe_paired_memif_clk_prepare()
315 struct mt8195_afe_private *afe_priv = afe->platform_priv; in mt8195_afe_paired_memif_clk_enable()
316 int id = snd_soc_rtd_to_cpu(rtd, 0)->id; in mt8195_afe_paired_memif_clk_enable()
325 mt8195_afe_enable_clk_atomic(afe, afe_priv->clk[clk_id]); in mt8195_afe_paired_memif_clk_enable()
329 mt8195_afe_enable_clk_atomic(afe, afe_priv->clk[clk_id]); in mt8195_afe_paired_memif_clk_enable()
333 mt8195_afe_disable_clk_atomic(afe, afe_priv->clk[clk_id]); in mt8195_afe_paired_memif_clk_enable()
336 mt8195_afe_disable_clk_atomic(afe, afe_priv->clk[clk_id]); in mt8195_afe_paired_memif_clk_enable()
346 struct snd_pcm_runtime *runtime = substream->runtime; in mt8195_afe_fe_startup()
348 int id = snd_soc_rtd_to_cpu(rtd, 0)->id; in mt8195_afe_fe_startup()
367 dev_dbg(afe->dev, "hw_constraint_minmax failed\n"); in mt8195_afe_fe_startup()
385 int id = snd_soc_rtd_to_cpu(rtd, 0)->id; in mt8195_afe_fe_hw_params()
386 struct mtk_base_afe_memif *memif = &afe->memif[id]; in mt8195_afe_fe_hw_params()
387 const struct mtk_base_memif_data *data = memif->data; in mt8195_afe_fe_hw_params()
393 if (data->ch_num_reg >= 0) { in mt8195_afe_fe_hw_params()
394 regmap_update_bits(afe->regmap, data->ch_num_reg, in mt8195_afe_fe_hw_params()
395 data->ch_num_maskbit << data->ch_num_shift, in mt8195_afe_fe_hw_params()
396 ch_num << data->ch_num_shift); in mt8195_afe_fe_hw_params()
1466 struct mt8195_afe_private *afe_priv = afe->platform_priv; in mt8195_memif_1x_en_sel_put()
1468 unsigned int dai_id = kcontrol->id.device; in mt8195_memif_1x_en_sel_put()
1469 long val = ucontrol->value.integer.value[0]; in mt8195_memif_1x_en_sel_put()
1472 memif_priv = afe_priv->dai_priv[dai_id]; in mt8195_memif_1x_en_sel_put()
1474 if (val == memif_priv->asys_timing_sel) in mt8195_memif_1x_en_sel_put()
1479 memif_priv->asys_timing_sel = val; in mt8195_memif_1x_en_sel_put()
1490 struct mt8195_afe_private *afe_priv = afe->platform_priv; in mt8195_asys_irq_1x_en_sel_put()
1491 unsigned int id = kcontrol->id.device; in mt8195_asys_irq_1x_en_sel_put()
1492 long val = ucontrol->value.integer.value[0]; in mt8195_asys_irq_1x_en_sel_put()
1495 if (val == afe_priv->irq_priv[id].asys_timing_sel) in mt8195_asys_irq_1x_en_sel_put()
1500 afe_priv->irq_priv[id].asys_timing_sel = val; in mt8195_asys_irq_1x_en_sel_put()
1808 .mono_reg = -1,
1810 .int_odd_flag_reg = -1,
1835 .mono_reg = -1,
1837 .int_odd_flag_reg = -1,
1862 .mono_reg = -1,
1864 .int_odd_flag_reg = -1,
1886 .fs_reg = -1,
1889 .mono_reg = -1,
1891 .int_odd_flag_reg = -1,
1916 .mono_reg = -1,
1918 .int_odd_flag_reg = -1,
1924 .agent_disable_reg = -1,
1943 .mono_reg = -1,
1945 .int_odd_flag_reg = -1,
1951 .agent_disable_reg = -1,
1970 .mono_reg = -1,
1972 .int_odd_flag_reg = -1,
1994 .fs_reg = -1,
2007 .ch_num_reg = -1,
2034 .ch_num_reg = -1,
2061 .ch_num_reg = -1,
2088 .ch_num_reg = -1,
2115 .ch_num_reg = -1,
2129 .fs_reg = -1,
2142 .ch_num_reg = -1,
2169 .ch_num_reg = -1,
2196 .ch_num_reg = -1,
2223 .ch_num_reg = -1,
2236 .irq_cnt_reg = -1,
2239 .irq_fs_reg = -1,
2250 .irq_cnt_reg = -1,
2253 .irq_fs_reg = -1,
2267 .irq_fs_reg = -1,
2278 .irq_cnt_reg = -1,
2281 .irq_fs_reg = -1,
2295 .irq_fs_reg = -1,
2306 .irq_cnt_reg = -1,
2309 .irq_fs_reg = -1,
2565 /* these auto-gen reg has read-only bit, so put it as volatile */ in mt8195_is_volatile_reg()
2858 ret = regmap_read(afe->regmap, AFE_IRQ_STATUS, &val); in mt8195_afe_irq_handler()
2860 dev_info(afe->dev, "%s irq status err\n", __func__); in mt8195_afe_irq_handler()
2866 ret = regmap_read(afe->regmap, AFE_IRQ_MASK, &mcu_irq_mask); in mt8195_afe_irq_handler()
2868 dev_info(afe->dev, "%s read irq mask err\n", __func__); in mt8195_afe_irq_handler()
2878 struct mtk_base_afe_memif *memif = &afe->memif[i]; in mt8195_afe_irq_handler()
2881 if (memif->irq_usage < 0) in mt8195_afe_irq_handler()
2884 irq_data = afe->irqs[memif->irq_usage].irq_data; in mt8195_afe_irq_handler()
2886 irq_status_bits = BIT(irq_data->irq_status_shift); in mt8195_afe_irq_handler()
2887 irq_clr_bits = BIT(irq_data->irq_clr_shift); in mt8195_afe_irq_handler()
2892 if (irq_data->irq_clr_reg == ASYS_IRQ_CLR) in mt8195_afe_irq_handler()
2897 snd_pcm_period_elapsed(memif->substream); in mt8195_afe_irq_handler()
2903 regmap_write(afe->regmap, ASYS_IRQ_CLR, asys_irq_clr_bits); in mt8195_afe_irq_handler()
2905 regmap_write(afe->regmap, AFE_IRQ_MCU_CLR, afe_irq_clr_bits); in mt8195_afe_irq_handler()
2913 struct mt8195_afe_private *afe_priv = afe->platform_priv; in mt8195_afe_runtime_suspend()
2915 if (!afe->regmap || afe_priv->pm_runtime_bypass_reg_ctl) in mt8195_afe_runtime_suspend()
2920 regcache_cache_only(afe->regmap, true); in mt8195_afe_runtime_suspend()
2921 regcache_mark_dirty(afe->regmap); in mt8195_afe_runtime_suspend()
2932 struct mt8195_afe_private *afe_priv = afe->platform_priv; in mt8195_afe_runtime_resume()
2936 if (!afe->regmap || afe_priv->pm_runtime_bypass_reg_ctl) in mt8195_afe_runtime_resume()
2939 regcache_cache_only(afe->regmap, false); in mt8195_afe_runtime_resume()
2940 regcache_sync(afe->regmap); in mt8195_afe_runtime_resume()
2949 struct mt8195_afe_private *afe_priv = afe->platform_priv; in init_memif_priv_data()
2954 memif_priv = devm_kzalloc(afe->dev, in init_memif_priv_data()
2958 return -ENOMEM; in init_memif_priv_data()
2960 afe_priv->dai_priv[i] = memif_priv; in init_memif_priv_data()
2970 dai = devm_kzalloc(afe->dev, sizeof(*dai), GFP_KERNEL); in mt8195_dai_memif_register()
2972 return -ENOMEM; in mt8195_dai_memif_register()
2974 list_add(&dai->list, &afe->sub_dais); in mt8195_dai_memif_register()
2976 dai->dai_drivers = mt8195_memif_dai_driver; in mt8195_dai_memif_register()
2977 dai->num_dai_drivers = ARRAY_SIZE(mt8195_memif_dai_driver); in mt8195_dai_memif_register()
2979 dai->dapm_widgets = mt8195_memif_widgets; in mt8195_dai_memif_register()
2980 dai->num_dapm_widgets = ARRAY_SIZE(mt8195_memif_widgets); in mt8195_dai_memif_register()
2981 dai->dapm_routes = mt8195_memif_routes; in mt8195_dai_memif_register()
2982 dai->num_dapm_routes = ARRAY_SIZE(mt8195_memif_routes); in mt8195_dai_memif_register()
2983 dai->controls = mt8195_memif_controls; in mt8195_dai_memif_register()
2984 dai->num_controls = ARRAY_SIZE(mt8195_memif_controls); in mt8195_dai_memif_register()
3014 struct device *dev = &pdev->dev; in mt8195_afe_pcm_dev_probe()
3028 return -ENOMEM; in mt8195_afe_pcm_dev_probe()
3030 afe->platform_priv = devm_kzalloc(dev, sizeof(*afe_priv), in mt8195_afe_pcm_dev_probe()
3032 if (!afe->platform_priv) in mt8195_afe_pcm_dev_probe()
3033 return -ENOMEM; in mt8195_afe_pcm_dev_probe()
3035 afe_priv = afe->platform_priv; in mt8195_afe_pcm_dev_probe()
3036 afe->dev = &pdev->dev; in mt8195_afe_pcm_dev_probe()
3038 afe->base_addr = devm_platform_ioremap_resource(pdev, 0); in mt8195_afe_pcm_dev_probe()
3039 if (IS_ERR(afe->base_addr)) in mt8195_afe_pcm_dev_probe()
3040 return PTR_ERR(afe->base_addr); in mt8195_afe_pcm_dev_probe()
3042 /* initial audio related clock */ in mt8195_afe_pcm_dev_probe()
3047 /* reset controller to reset audio regs before regmap cache */ in mt8195_afe_pcm_dev_probe()
3054 return dev_err_probe(dev, ret, "failed to trigger audio reset\n"); in mt8195_afe_pcm_dev_probe()
3056 spin_lock_init(&afe_priv->afe_ctrl_lock); in mt8195_afe_pcm_dev_probe()
3058 mutex_init(&afe->irq_alloc_lock); in mt8195_afe_pcm_dev_probe()
3061 afe->irqs_size = MT8195_AFE_IRQ_NUM; in mt8195_afe_pcm_dev_probe()
3062 afe->irqs = devm_kcalloc(dev, afe->irqs_size, sizeof(*afe->irqs), in mt8195_afe_pcm_dev_probe()
3064 if (!afe->irqs) in mt8195_afe_pcm_dev_probe()
3065 return -ENOMEM; in mt8195_afe_pcm_dev_probe()
3067 for (i = 0; i < afe->irqs_size; i++) in mt8195_afe_pcm_dev_probe()
3068 afe->irqs[i].irq_data = &irq_data_array[i]; in mt8195_afe_pcm_dev_probe()
3071 afe->memif_size = MT8195_AFE_MEMIF_NUM; in mt8195_afe_pcm_dev_probe()
3072 afe->memif = devm_kcalloc(dev, afe->memif_size, sizeof(*afe->memif), in mt8195_afe_pcm_dev_probe()
3074 if (!afe->memif) in mt8195_afe_pcm_dev_probe()
3075 return -ENOMEM; in mt8195_afe_pcm_dev_probe()
3077 for (i = 0; i < afe->memif_size; i++) { in mt8195_afe_pcm_dev_probe()
3078 afe->memif[i].data = &memif_data[i]; in mt8195_afe_pcm_dev_probe()
3079 afe->memif[i].irq_usage = mt8195_afe_memif_const_irqs[i]; in mt8195_afe_pcm_dev_probe()
3080 afe->memif[i].const_irq = 1; in mt8195_afe_pcm_dev_probe()
3081 afe->irqs[afe->memif[i].irq_usage].irq_occupyed = true; in mt8195_afe_pcm_dev_probe()
3087 return -ENXIO; in mt8195_afe_pcm_dev_probe()
3090 IRQF_TRIGGER_NONE, "asys-isr", (void *)afe); in mt8195_afe_pcm_dev_probe()
3092 return dev_err_probe(dev, ret, "could not request_irq for asys-isr\n"); in mt8195_afe_pcm_dev_probe()
3095 INIT_LIST_HEAD(&afe->sub_dais); in mt8195_afe_pcm_dev_probe()
3108 afe->mtk_afe_hardware = &mt8195_afe_hardware; in mt8195_afe_pcm_dev_probe()
3109 afe->memif_fs = mt8195_memif_fs; in mt8195_afe_pcm_dev_probe()
3110 afe->irq_fs = mt8195_irq_fs; in mt8195_afe_pcm_dev_probe()
3112 afe->runtime_resume = mt8195_afe_runtime_resume; in mt8195_afe_pcm_dev_probe()
3113 afe->runtime_suspend = mt8195_afe_runtime_suspend; in mt8195_afe_pcm_dev_probe()
3117 afe_priv->topckgen = syscon_regmap_lookup_by_phandle(dev->of_node, "mediatek,topckgen"); in mt8195_afe_pcm_dev_probe()
3118 if (IS_ERR(afe_priv->topckgen)) in mt8195_afe_pcm_dev_probe()
3119 dev_dbg(afe->dev, "Cannot find topckgen controller: %ld\n", in mt8195_afe_pcm_dev_probe()
3120 PTR_ERR(afe_priv->topckgen)); in mt8195_afe_pcm_dev_probe()
3123 afe_priv->pm_runtime_bypass_reg_ctl = true; in mt8195_afe_pcm_dev_probe()
3133 afe->regmap = devm_regmap_init_mmio(&pdev->dev, afe->base_addr, in mt8195_afe_pcm_dev_probe()
3135 if (IS_ERR(afe->regmap)) { in mt8195_afe_pcm_dev_probe()
3136 ret = PTR_ERR(afe->regmap); in mt8195_afe_pcm_dev_probe()
3140 ret = regmap_register_patch(afe->regmap, mt8195_cg_patch, in mt8195_afe_pcm_dev_probe()
3149 afe->dai_drivers, afe->num_dai_drivers); in mt8195_afe_pcm_dev_probe()
3155 ret = regmap_multi_reg_write(afe->regmap, mt8195_afe_reg_defaults, in mt8195_afe_pcm_dev_probe()
3164 afe_priv->pm_runtime_bypass_reg_ctl = false; in mt8195_afe_pcm_dev_probe()
3166 regcache_cache_only(afe->regmap, true); in mt8195_afe_pcm_dev_probe()
3167 regcache_mark_dirty(afe->regmap); in mt8195_afe_pcm_dev_probe()
3179 pm_runtime_disable(&pdev->dev); in mt8195_afe_pcm_dev_remove()
3180 if (!pm_runtime_status_suspended(&pdev->dev)) in mt8195_afe_pcm_dev_remove()
3181 mt8195_afe_runtime_suspend(&pdev->dev); in mt8195_afe_pcm_dev_remove()
3185 {.compatible = "mediatek,mt8195-audio", },
3197 .name = "mt8195-audio",