Lines Matching full:afe

3  * MediaTek 8365 ALSA SoC AFE platform driver
18 #include "mt8365-afe-common.h"
19 #include "mt8365-afe-clk.h"
21 #include "../common/mtk-base-afe.h"
22 #include "../common/mtk-afe-platform-driver.h"
23 #include "../common/mtk-afe-fe-dai.h"
190 int mt8365_dai_set_priv(struct mtk_base_afe *afe, int id, in mt8365_dai_set_priv() argument
193 struct mt8365_afe_private *afe_priv = afe->platform_priv; in mt8365_dai_set_priv()
196 temp_data = devm_kzalloc(afe->dev, priv_size, GFP_KERNEL); in mt8365_dai_set_priv()
208 static int mt8365_afe_irq_direction_enable(struct mtk_base_afe *afe, in mt8365_afe_irq_direction_enable() argument
216 irq = &afe->irqs[irq_id]; in mt8365_afe_irq_direction_enable()
219 regmap_update_bits(afe->regmap, AFE_IRQ_MCU_DSP_EN, in mt8365_afe_irq_direction_enable()
222 regmap_update_bits(afe->regmap, AFE_IRQ_MCU_EN, in mt8365_afe_irq_direction_enable()
226 regmap_update_bits(afe->regmap, AFE_IRQ_MCU_DSP_EN, in mt8365_afe_irq_direction_enable()
229 regmap_update_bits(afe->regmap, AFE_IRQ_MCU_EN, in mt8365_afe_irq_direction_enable()
233 regmap_update_bits(afe->regmap, AFE_IRQ_MCU_DSP_EN, in mt8365_afe_irq_direction_enable()
236 regmap_update_bits(afe->regmap, AFE_IRQ_MCU_EN, in mt8365_afe_irq_direction_enable()
272 static int mt8365_afe_cm2_mux_conn(struct mtk_base_afe *afe) in mt8365_afe_cm2_mux_conn() argument
274 struct mt8365_afe_private *afe_priv = afe->platform_priv; in mt8365_afe_cm2_mux_conn()
278 regmap_update_bits(afe->regmap, AFE_CM2_CONN0, in mt8365_afe_cm2_mux_conn()
281 regmap_update_bits(afe->regmap, AFE_CM2_CONN0, in mt8365_afe_cm2_mux_conn()
284 regmap_update_bits(afe->regmap, AFE_CM2_CONN0, in mt8365_afe_cm2_mux_conn()
287 regmap_update_bits(afe->regmap, AFE_CM2_CONN0, in mt8365_afe_cm2_mux_conn()
290 regmap_update_bits(afe->regmap, AFE_CM2_CONN0, in mt8365_afe_cm2_mux_conn()
293 regmap_update_bits(afe->regmap, AFE_CM2_CONN0, in mt8365_afe_cm2_mux_conn()
296 regmap_update_bits(afe->regmap, AFE_CM2_CONN1, in mt8365_afe_cm2_mux_conn()
299 regmap_update_bits(afe->regmap, AFE_CM2_CONN1, in mt8365_afe_cm2_mux_conn()
305 regmap_update_bits(afe->regmap, AFE_CM2_CONN1, in mt8365_afe_cm2_mux_conn()
308 regmap_update_bits(afe->regmap, AFE_CM2_CONN1, in mt8365_afe_cm2_mux_conn()
312 regmap_update_bits(afe->regmap, AFE_CM2_CONN1, in mt8365_afe_cm2_mux_conn()
315 regmap_update_bits(afe->regmap, AFE_CM2_CONN1, in mt8365_afe_cm2_mux_conn()
319 regmap_update_bits(afe->regmap, AFE_CM2_CONN1, in mt8365_afe_cm2_mux_conn()
322 regmap_update_bits(afe->regmap, AFE_CM2_CONN1, in mt8365_afe_cm2_mux_conn()
325 regmap_update_bits(afe->regmap, AFE_CM2_CONN1, in mt8365_afe_cm2_mux_conn()
328 regmap_update_bits(afe->regmap, AFE_CM2_CONN1, in mt8365_afe_cm2_mux_conn()
331 regmap_update_bits(afe->regmap, AFE_CM2_CONN2, in mt8365_afe_cm2_mux_conn()
334 regmap_update_bits(afe->regmap, AFE_CM2_CONN2, in mt8365_afe_cm2_mux_conn()
337 regmap_update_bits(afe->regmap, AFE_CM2_CONN2, in mt8365_afe_cm2_mux_conn()
340 regmap_update_bits(afe->regmap, AFE_CM2_CONN2, in mt8365_afe_cm2_mux_conn()
344 dev_err(afe->dev, "%s wrong CM2 input %d\n", __func__, input); in mt8365_afe_cm2_mux_conn()
351 static int mt8365_afe_get_cm_update_cnt(struct mtk_base_afe *afe, in mt8365_afe_get_cm_update_cnt() argument
396 regmap_update_bits(afe->regmap, cm_ctrl_reg[cmNum].con4, in mt8365_afe_get_cm_update_cnt()
403 regmap_update_bits(afe->regmap, cm_ctrl_reg[cmNum].con4, in mt8365_afe_get_cm_update_cnt()
410 regmap_update_bits(afe->regmap, cm_ctrl_reg[cmNum].con3, in mt8365_afe_get_cm_update_cnt()
417 regmap_update_bits(afe->regmap, cm_ctrl_reg[cmNum].con3, in mt8365_afe_get_cm_update_cnt()
424 regmap_update_bits(afe->regmap, cm_ctrl_reg[cmNum].con2, in mt8365_afe_get_cm_update_cnt()
431 regmap_update_bits(afe->regmap, cm_ctrl_reg[cmNum].con2, in mt8365_afe_get_cm_update_cnt()
438 regmap_update_bits(afe->regmap, cm_ctrl_reg[cmNum].con1, in mt8365_afe_get_cm_update_cnt()
445 regmap_update_bits(afe->regmap, cm_ctrl_reg[cmNum].con1, in mt8365_afe_get_cm_update_cnt()
456 static int mt8365_afe_configure_cm(struct mtk_base_afe *afe, in mt8365_afe_configure_cm() argument
487 mt8365_afe_cm2_mux_conn(afe); in mt8365_afe_configure_cm()
492 regmap_update_bits(afe->regmap, cm_ctrl_reg[cmNum].con0, mask, val); in mt8365_afe_configure_cm()
494 mt8365_afe_get_cm_update_cnt(afe, cmNum, rate, channels); in mt8365_afe_configure_cm()
503 struct mtk_base_afe *afe = snd_soc_dai_get_drvdata(dai); in mt8365_afe_fe_startup() local
506 struct mtk_base_afe_memif *memif = &afe->memif[memif_num]; in mt8365_afe_fe_startup()
514 snd_soc_set_runtime_hwparams(substream, afe->mtk_afe_hardware); in mt8365_afe_fe_startup()
518 dev_err(afe->dev, "snd_pcm_hw_constraint_integer failed\n"); in mt8365_afe_fe_startup()
520 mt8365_afe_enable_main_clk(afe); in mt8365_afe_fe_startup()
528 struct mtk_base_afe *afe = snd_soc_dai_get_drvdata(dai); in mt8365_afe_fe_shutdown() local
530 struct mtk_base_afe_memif *memif = &afe->memif[memif_num]; in mt8365_afe_fe_shutdown()
534 mt8365_afe_disable_main_clk(afe); in mt8365_afe_fe_shutdown()
542 struct mtk_base_afe *afe = snd_soc_dai_get_drvdata(dai); in mt8365_afe_fe_hw_params() local
543 struct mt8365_afe_private *afe_priv = afe->platform_priv; in mt8365_afe_fe_hw_params()
546 struct mtk_base_afe_memif *memif = &afe->memif[dai_id]; in mt8365_afe_fe_hw_params()
554 dev_info(afe->dev, "%s %s period = %d rate = %d channels = %d\n", in mt8365_afe_fe_hw_params()
561 mt8365_afe_configure_cm(afe, MT8365_CM1, in mt8365_afe_fe_hw_params()
564 regmap_update_bits(afe->regmap, AFE_CM1_CON0, in mt8365_afe_fe_hw_params()
570 mt8365_afe_configure_cm(afe, MT8365_CM2, in mt8365_afe_fe_hw_params()
573 regmap_update_bits(afe->regmap, AFE_CM2_CON0, in mt8365_afe_fe_hw_params()
583 dev_err(afe->dev, in mt8365_afe_fe_hw_params()
591 mt8365_afe_emi_clk_on(afe); in mt8365_afe_fe_hw_params()
609 regmap_write(afe->regmap, memif->data->reg_ofs_base, in mt8365_afe_fe_hw_params()
612 regmap_write(afe->regmap, in mt8365_afe_fe_hw_params()
621 dev_info(afe->dev, "%s mono_reg is NULL\n", __func__); in mt8365_afe_fe_hw_params()
623 regmap_update_bits(afe->regmap, memif->data->mono_reg, in mt8365_afe_fe_hw_params()
632 fs = afe->memif_fs(substream, params_rate(params)); in mt8365_afe_fe_hw_params()
638 dev_info(afe->dev, "%s fs_reg is NULL\n", __func__); in mt8365_afe_fe_hw_params()
640 regmap_update_bits(afe->regmap, memif->data->fs_reg, in mt8365_afe_fe_hw_params()
651 struct mtk_base_afe *afe = snd_soc_dai_get_drvdata(dai); in mt8365_afe_fe_hw_free() local
652 struct mt8365_afe_private *afe_priv = afe->platform_priv; in mt8365_afe_fe_hw_free()
662 mt8365_afe_emi_clk_off(afe); in mt8365_afe_fe_hw_free()
672 struct mtk_base_afe *afe = snd_soc_dai_get_drvdata(dai); in mt8365_afe_fe_prepare() local
674 struct mtk_base_afe_memif *memif = &afe->memif[dai_id]; in mt8365_afe_fe_prepare()
680 regmap_update_bits(afe->regmap, memif->data->hd_reg, in mt8365_afe_fe_prepare()
685 regmap_update_bits(afe->regmap, memif->data->hd_reg, in mt8365_afe_fe_prepare()
690 regmap_update_bits(afe->regmap, in mt8365_afe_fe_prepare()
694 regmap_update_bits(afe->regmap, in mt8365_afe_fe_prepare()
701 regmap_update_bits(afe->regmap, memif->data->hd_reg, in mt8365_afe_fe_prepare()
710 mt8365_afe_irq_direction_enable(afe, memif->irq_usage, in mt8365_afe_fe_prepare()
720 struct mtk_base_afe *afe = snd_soc_dai_get_drvdata(dai); in mt8365_afe_fe_trigger() local
721 struct mt8365_afe_private *afe_priv = afe->platform_priv; in mt8365_afe_fe_trigger()
731 regmap_update_bits(afe->regmap, AFE_CM1_CON0, in mt8365_afe_fe_trigger()
735 regmap_update_bits(afe->regmap, AFE_CM2_CON0, in mt8365_afe_fe_trigger()
744 regmap_update_bits(afe->regmap, AFE_CM1_CON0, in mt8365_afe_fe_trigger()
748 regmap_update_bits(afe->regmap, AFE_CM2_CON0, in mt8365_afe_fe_trigger()
762 struct mtk_base_afe *afe = snd_soc_dai_get_drvdata(dai); in mt8365_afe_hw_gain1_startup() local
764 mt8365_afe_enable_main_clk(afe); in mt8365_afe_hw_gain1_startup()
771 struct mtk_base_afe *afe = snd_soc_dai_get_drvdata(dai); in mt8365_afe_hw_gain1_shutdown() local
772 struct mt8365_afe_private *afe_priv = afe->platform_priv; in mt8365_afe_hw_gain1_shutdown()
777 regmap_update_bits(afe->regmap, AFE_GAIN1_CON0, in mt8365_afe_hw_gain1_shutdown()
781 mt8365_afe_disable_main_clk(afe); in mt8365_afe_hw_gain1_shutdown()
787 struct mtk_base_afe *afe = snd_soc_dai_get_drvdata(dai); in mt8365_afe_hw_gain1_prepare() local
788 struct mt8365_afe_private *afe_priv = afe->platform_priv; in mt8365_afe_hw_gain1_prepare()
796 dev_info(afe->dev, "%s prepared already\n", __func__); in mt8365_afe_hw_gain1_prepare()
801 regmap_update_bits(afe->regmap, AFE_GAIN1_CON0, in mt8365_afe_hw_gain1_prepare()
804 regmap_read(afe->regmap, AFE_GAIN1_CON1, &val1); in mt8365_afe_hw_gain1_prepare()
805 regmap_read(afe->regmap, AFE_GAIN1_CUR, &val2); in mt8365_afe_hw_gain1_prepare()
807 regmap_update_bits(afe->regmap, AFE_GAIN1_CUR, in mt8365_afe_hw_gain1_prepare()
810 regmap_update_bits(afe->regmap, AFE_GAIN1_CON0, in mt8365_afe_hw_gain1_prepare()
832 struct mtk_base_afe *afe = snd_soc_dai_get_drvdata(dai); in mtk_dai_hostless_startup() local
841 dev_err(afe->dev, "snd_pcm_hw_constraint_integer failed\n"); in mtk_dai_hostless_startup()
1262 struct mtk_base_afe *afe = snd_soc_component_get_drvdata(comp); in mt8365_afe_cm2_io_input_mux_put() local
1263 struct mt8365_afe_private *afe_priv = afe->platform_priv; in mt8365_afe_cm2_io_input_mux_put()
1915 struct mtk_base_afe *afe = dev_id; in mt8365_afe_irq_handler() local
1920 ret = regmap_read(afe->regmap, AFE_IRQ_MCU_STATUS, &reg_value); in mt8365_afe_irq_handler()
1922 dev_err_ratelimited(afe->dev, "%s irq status err\n", __func__); in mt8365_afe_irq_handler()
1927 ret = regmap_read(afe->regmap, AFE_IRQ_MCU_EN, &mcu_irq_mask); in mt8365_afe_irq_handler()
1929 dev_err_ratelimited(afe->dev, "%s irq mcu_en err\n", __func__); in mt8365_afe_irq_handler()
1938 struct mtk_base_afe_memif *memif = &afe->memif[i]; in mt8365_afe_irq_handler()
1944 mcu_irq = &afe->irqs[memif->irq_usage]; in mt8365_afe_irq_handler()
1954 regmap_write(afe->regmap, AFE_IRQ_MCU_CLR, in mt8365_afe_irq_handler()
1972 struct mtk_base_afe *afe = dev_get_drvdata(dev); in mt8365_afe_suspend() local
1973 struct regmap *regmap = afe->regmap; in mt8365_afe_suspend()
1976 mt8365_afe_enable_main_clk(afe); in mt8365_afe_suspend()
1978 if (!afe->reg_back_up) in mt8365_afe_suspend()
1979 afe->reg_back_up = in mt8365_afe_suspend()
1980 devm_kcalloc(dev, afe->reg_back_up_list_num, in mt8365_afe_suspend()
1983 for (i = 0; i < afe->reg_back_up_list_num; i++) in mt8365_afe_suspend()
1984 regmap_read(regmap, afe->reg_back_up_list[i], in mt8365_afe_suspend()
1985 &afe->reg_back_up[i]); in mt8365_afe_suspend()
1987 mt8365_afe_disable_main_clk(afe); in mt8365_afe_suspend()
1994 struct mtk_base_afe *afe = dev_get_drvdata(dev); in mt8365_afe_resume() local
1995 struct regmap *regmap = afe->regmap; in mt8365_afe_resume()
1998 if (!afe->reg_back_up) in mt8365_afe_resume()
2001 mt8365_afe_enable_main_clk(afe); in mt8365_afe_resume()
2003 for (i = 0; i < afe->reg_back_up_list_num; i++) in mt8365_afe_resume()
2004 regmap_write(regmap, afe->reg_back_up_list[i], in mt8365_afe_resume()
2005 afe->reg_back_up[i]); in mt8365_afe_resume()
2007 mt8365_afe_disable_main_clk(afe); in mt8365_afe_resume()
2014 struct mtk_base_afe *afe = dev_get_drvdata(dev); in mt8365_afe_dev_runtime_suspend() local
2016 if (pm_runtime_status_suspended(dev) || afe->suspended) in mt8365_afe_dev_runtime_suspend()
2020 afe->suspended = true; in mt8365_afe_dev_runtime_suspend()
2026 struct mtk_base_afe *afe = dev_get_drvdata(dev); in mt8365_afe_dev_runtime_resume() local
2028 if (pm_runtime_status_suspended(dev) || !afe->suspended) in mt8365_afe_dev_runtime_resume()
2032 afe->suspended = false; in mt8365_afe_dev_runtime_resume()
2036 static int mt8365_afe_init_registers(struct mtk_base_afe *afe) in mt8365_afe_init_registers() argument
2049 mt8365_afe_enable_main_clk(afe); in mt8365_afe_init_registers()
2052 regmap_update_bits(afe->regmap, init_regs[i].reg, in mt8365_afe_init_registers()
2055 mt8365_afe_disable_main_clk(afe); in mt8365_afe_init_registers()
2060 static int mt8365_dai_memif_register(struct mtk_base_afe *afe) in mt8365_dai_memif_register() argument
2064 dai = devm_kzalloc(afe->dev, sizeof(*dai), GFP_KERNEL); in mt8365_dai_memif_register()
2068 list_add(&dai->list, &afe->sub_dais); in mt8365_dai_memif_register()
2091 struct mtk_base_afe *afe; in mt8365_afe_pcm_dev_probe() local
2098 afe = devm_kzalloc(&pdev->dev, sizeof(*afe), GFP_KERNEL); in mt8365_afe_pcm_dev_probe()
2099 if (!afe) in mt8365_afe_pcm_dev_probe()
2101 platform_set_drvdata(pdev, afe); in mt8365_afe_pcm_dev_probe()
2103 afe->platform_priv = devm_kzalloc(&pdev->dev, sizeof(*afe_priv), in mt8365_afe_pcm_dev_probe()
2105 if (!afe->platform_priv) in mt8365_afe_pcm_dev_probe()
2108 afe_priv = afe->platform_priv; in mt8365_afe_pcm_dev_probe()
2109 afe->dev = &pdev->dev; in mt8365_afe_pcm_dev_probe()
2110 dev = afe->dev; in mt8365_afe_pcm_dev_probe()
2116 afe->base_addr = devm_ioremap_resource(&pdev->dev, res); in mt8365_afe_pcm_dev_probe()
2117 if (IS_ERR(afe->base_addr)) in mt8365_afe_pcm_dev_probe()
2118 return PTR_ERR(afe->base_addr); in mt8365_afe_pcm_dev_probe()
2131 ret = mt8365_afe_init_audio_clk(afe); in mt8365_afe_pcm_dev_probe()
2133 return dev_err_probe(afe->dev, ret, "mt8365_afe_init_audio_clk fail\n"); in mt8365_afe_pcm_dev_probe()
2135 afe->regmap = devm_regmap_init_mmio_clk(&pdev->dev, "top_audio_sel", in mt8365_afe_pcm_dev_probe()
2136 afe->base_addr, in mt8365_afe_pcm_dev_probe()
2138 if (IS_ERR(afe->regmap)) in mt8365_afe_pcm_dev_probe()
2139 return PTR_ERR(afe->regmap); in mt8365_afe_pcm_dev_probe()
2142 afe->memif_size = MT8365_AFE_MEMIF_NUM; in mt8365_afe_pcm_dev_probe()
2143 afe->memif = devm_kcalloc(afe->dev, afe->memif_size, in mt8365_afe_pcm_dev_probe()
2144 sizeof(*afe->memif), GFP_KERNEL); in mt8365_afe_pcm_dev_probe()
2145 if (!afe->memif) in mt8365_afe_pcm_dev_probe()
2148 afe->irqs_size = MT8365_AFE_IRQ_NUM; in mt8365_afe_pcm_dev_probe()
2149 afe->irqs = devm_kcalloc(afe->dev, afe->irqs_size, in mt8365_afe_pcm_dev_probe()
2150 sizeof(*afe->irqs), GFP_KERNEL); in mt8365_afe_pcm_dev_probe()
2151 if (!afe->irqs) in mt8365_afe_pcm_dev_probe()
2154 for (i = 0; i < afe->irqs_size; i++) in mt8365_afe_pcm_dev_probe()
2155 afe->irqs[i].irq_data = &irq_data[i]; in mt8365_afe_pcm_dev_probe()
2162 ret = devm_request_irq(afe->dev, irq_id, mt8365_afe_irq_handler, in mt8365_afe_pcm_dev_probe()
2163 0, "Afe_ISR_Handle", (void *)afe); in mt8365_afe_pcm_dev_probe()
2165 return dev_err_probe(afe->dev, ret, "could not request_irq\n"); in mt8365_afe_pcm_dev_probe()
2168 INIT_LIST_HEAD(&afe->sub_dais); in mt8365_afe_pcm_dev_probe()
2171 ret = dai_register_cbs[i](afe); in mt8365_afe_pcm_dev_probe()
2173 dev_warn(afe->dev, "dai register i %d fail, ret %d\n", in mt8365_afe_pcm_dev_probe()
2180 ret = mtk_afe_combine_sub_dai(afe); in mt8365_afe_pcm_dev_probe()
2182 dev_warn(afe->dev, "mtk_afe_combine_sub_dai fail, ret %d\n", in mt8365_afe_pcm_dev_probe()
2187 for (i = 0; i < afe->memif_size; i++) { in mt8365_afe_pcm_dev_probe()
2188 afe->memif[i].data = &memif_data[i]; in mt8365_afe_pcm_dev_probe()
2191 afe->memif[i].irq_usage = sel_irq; in mt8365_afe_pcm_dev_probe()
2192 afe->memif[i].const_irq = 1; in mt8365_afe_pcm_dev_probe()
2193 afe->irqs[sel_irq].irq_occupyed = true; in mt8365_afe_pcm_dev_probe()
2195 afe->memif[i].irq_usage = -1; in mt8365_afe_pcm_dev_probe()
2199 afe->mtk_afe_hardware = &mt8365_afe_hardware; in mt8365_afe_pcm_dev_probe()
2200 afe->memif_fs = mt8365_memif_fs; in mt8365_afe_pcm_dev_probe()
2201 afe->irq_fs = mt8365_irq_fs; in mt8365_afe_pcm_dev_probe()
2208 afe->reg_back_up_list = mt8365_afe_backup_list; in mt8365_afe_pcm_dev_probe()
2209 afe->reg_back_up_list_num = ARRAY_SIZE(mt8365_afe_backup_list); in mt8365_afe_pcm_dev_probe()
2210 afe->runtime_resume = mt8365_afe_runtime_resume; in mt8365_afe_pcm_dev_probe()
2211 afe->runtime_suspend = mt8365_afe_runtime_suspend; in mt8365_afe_pcm_dev_probe()
2213 /* open afe pdn for dapm read/write audio register */ in mt8365_afe_pcm_dev_probe()
2214 mt8365_afe_enable_top_cg(afe, MT8365_TOP_CG_AFE); in mt8365_afe_pcm_dev_probe()
2217 mt8365_afe_set_clk_parent(afe, in mt8365_afe_pcm_dev_probe()
2223 afe->dai_drivers, in mt8365_afe_pcm_dev_probe()
2224 afe->num_dai_drivers); in mt8365_afe_pcm_dev_probe()
2230 mt8365_afe_init_registers(afe); in mt8365_afe_pcm_dev_probe()
2237 struct mtk_base_afe *afe = platform_get_drvdata(pdev); in mt8365_afe_pcm_dev_remove() local
2239 mt8365_afe_disable_top_cg(afe, MT8365_TOP_CG_AFE); in mt8365_afe_pcm_dev_remove()
2247 { .compatible = "mediatek,mt8365-afe-pcm", },
2261 .name = "mt8365-afe-pcm",
2271 MODULE_DESCRIPTION("MediaTek ALSA SoC AFE platform driver");