1f6b02647STrevor Wu // SPDX-License-Identifier: GPL-2.0 2f6b02647STrevor Wu /* 3f6b02647STrevor Wu * mt8188-afe-clk.c -- MediaTek 8188 afe clock ctrl 4f6b02647STrevor Wu * 5f6b02647STrevor Wu * Copyright (c) 2022 MediaTek Inc. 6f6b02647STrevor Wu * Author: Bicycle Tsai <bicycle.tsai@mediatek.com> 7f6b02647STrevor Wu * Trevor Wu <trevor.wu@mediatek.com> 8f6b02647STrevor Wu * Chun-Chia Chiu <chun-chia.chiu@mediatek.com> 9f6b02647STrevor Wu */ 10f6b02647STrevor Wu 11f6b02647STrevor Wu #include <linux/clk.h> 12f6b02647STrevor Wu 13f6b02647STrevor Wu #include "mt8188-afe-common.h" 14f6b02647STrevor Wu #include "mt8188-afe-clk.h" 15f6b02647STrevor Wu #include "mt8188-audsys-clk.h" 16f6b02647STrevor Wu #include "mt8188-reg.h" 17f6b02647STrevor Wu 18f6b02647STrevor Wu static const char *aud_clks[MT8188_CLK_NUM] = { 19f6b02647STrevor Wu /* xtal */ 20f6b02647STrevor Wu [MT8188_CLK_XTAL_26M] = "clk26m", 21f6b02647STrevor Wu 22f6b02647STrevor Wu /* pll */ 23f6b02647STrevor Wu [MT8188_CLK_APMIXED_APLL1] = "apll1", 24f6b02647STrevor Wu [MT8188_CLK_APMIXED_APLL2] = "apll2", 25f6b02647STrevor Wu 26f6b02647STrevor Wu /* divider */ 279be0213aSTrevor Wu [MT8188_CLK_TOP_APLL1_D4] = "apll1_d4", 28*2e5c422aSTrevor Wu [MT8188_CLK_TOP_APLL2_D4] = "apll2_d4", 29f6b02647STrevor Wu [MT8188_CLK_TOP_APLL12_DIV0] = "apll12_div0", 30f6b02647STrevor Wu [MT8188_CLK_TOP_APLL12_DIV1] = "apll12_div1", 31f6b02647STrevor Wu [MT8188_CLK_TOP_APLL12_DIV2] = "apll12_div2", 32f6b02647STrevor Wu [MT8188_CLK_TOP_APLL12_DIV3] = "apll12_div3", 33*2e5c422aSTrevor Wu [MT8188_CLK_TOP_APLL12_DIV4] = "apll12_div4", 34f6b02647STrevor Wu [MT8188_CLK_TOP_APLL12_DIV9] = "apll12_div9", 35f6b02647STrevor Wu 36f6b02647STrevor Wu /* mux */ 37f6b02647STrevor Wu [MT8188_CLK_TOP_A1SYS_HP_SEL] = "top_a1sys_hp", 38*2e5c422aSTrevor Wu [MT8188_CLK_TOP_A2SYS_SEL] = "top_a2sys", 39*2e5c422aSTrevor Wu [MT8188_CLK_TOP_AUD_IEC_SEL] = "top_aud_iec", 40f6b02647STrevor Wu [MT8188_CLK_TOP_AUD_INTBUS_SEL] = "top_aud_intbus", 41f6b02647STrevor Wu [MT8188_CLK_TOP_AUDIO_H_SEL] = "top_audio_h", 42f6b02647STrevor Wu [MT8188_CLK_TOP_AUDIO_LOCAL_BUS_SEL] = "top_audio_local_bus", 43f6b02647STrevor Wu [MT8188_CLK_TOP_DPTX_M_SEL] = "top_dptx", 44f6b02647STrevor Wu [MT8188_CLK_TOP_I2SO1_M_SEL] = "top_i2so1", 45f6b02647STrevor Wu [MT8188_CLK_TOP_I2SO2_M_SEL] = "top_i2so2", 46f6b02647STrevor Wu [MT8188_CLK_TOP_I2SI1_M_SEL] = "top_i2si1", 47f6b02647STrevor Wu [MT8188_CLK_TOP_I2SI2_M_SEL] = "top_i2si2", 48f6b02647STrevor Wu 49f6b02647STrevor Wu /* clock gate */ 50f6b02647STrevor Wu [MT8188_CLK_ADSP_AUDIO_26M] = "adsp_audio_26m", 51f6b02647STrevor Wu /* afe clock gate */ 52f6b02647STrevor Wu [MT8188_CLK_AUD_AFE] = "aud_afe", 53f6b02647STrevor Wu [MT8188_CLK_AUD_APLL1_TUNER] = "aud_apll1_tuner", 54f6b02647STrevor Wu [MT8188_CLK_AUD_APLL2_TUNER] = "aud_apll2_tuner", 55f6b02647STrevor Wu [MT8188_CLK_AUD_APLL] = "aud_apll", 56f6b02647STrevor Wu [MT8188_CLK_AUD_APLL2] = "aud_apll2", 57f6b02647STrevor Wu [MT8188_CLK_AUD_DAC] = "aud_dac", 58f6b02647STrevor Wu [MT8188_CLK_AUD_ADC] = "aud_adc", 59f6b02647STrevor Wu [MT8188_CLK_AUD_DAC_HIRES] = "aud_dac_hires", 60f6b02647STrevor Wu [MT8188_CLK_AUD_A1SYS_HP] = "aud_a1sys_hp", 61f6b02647STrevor Wu [MT8188_CLK_AUD_ADC_HIRES] = "aud_adc_hires", 62f6b02647STrevor Wu [MT8188_CLK_AUD_I2SIN] = "aud_i2sin", 63f6b02647STrevor Wu [MT8188_CLK_AUD_TDM_IN] = "aud_tdm_in", 64f6b02647STrevor Wu [MT8188_CLK_AUD_I2S_OUT] = "aud_i2s_out", 65f6b02647STrevor Wu [MT8188_CLK_AUD_TDM_OUT] = "aud_tdm_out", 66f6b02647STrevor Wu [MT8188_CLK_AUD_HDMI_OUT] = "aud_hdmi_out", 67f6b02647STrevor Wu [MT8188_CLK_AUD_ASRC11] = "aud_asrc11", 68f6b02647STrevor Wu [MT8188_CLK_AUD_ASRC12] = "aud_asrc12", 69f6b02647STrevor Wu [MT8188_CLK_AUD_A1SYS] = "aud_a1sys", 70f6b02647STrevor Wu [MT8188_CLK_AUD_A2SYS] = "aud_a2sys", 71f6b02647STrevor Wu [MT8188_CLK_AUD_PCMIF] = "aud_pcmif", 72f6b02647STrevor Wu [MT8188_CLK_AUD_MEMIF_UL1] = "aud_memif_ul1", 73f6b02647STrevor Wu [MT8188_CLK_AUD_MEMIF_UL2] = "aud_memif_ul2", 74f6b02647STrevor Wu [MT8188_CLK_AUD_MEMIF_UL3] = "aud_memif_ul3", 75f6b02647STrevor Wu [MT8188_CLK_AUD_MEMIF_UL4] = "aud_memif_ul4", 76f6b02647STrevor Wu [MT8188_CLK_AUD_MEMIF_UL5] = "aud_memif_ul5", 77f6b02647STrevor Wu [MT8188_CLK_AUD_MEMIF_UL6] = "aud_memif_ul6", 78f6b02647STrevor Wu [MT8188_CLK_AUD_MEMIF_UL8] = "aud_memif_ul8", 79f6b02647STrevor Wu [MT8188_CLK_AUD_MEMIF_UL9] = "aud_memif_ul9", 80f6b02647STrevor Wu [MT8188_CLK_AUD_MEMIF_UL10] = "aud_memif_ul10", 81f6b02647STrevor Wu [MT8188_CLK_AUD_MEMIF_DL2] = "aud_memif_dl2", 82f6b02647STrevor Wu [MT8188_CLK_AUD_MEMIF_DL3] = "aud_memif_dl3", 83f6b02647STrevor Wu [MT8188_CLK_AUD_MEMIF_DL6] = "aud_memif_dl6", 84f6b02647STrevor Wu [MT8188_CLK_AUD_MEMIF_DL7] = "aud_memif_dl7", 85f6b02647STrevor Wu [MT8188_CLK_AUD_MEMIF_DL8] = "aud_memif_dl8", 86f6b02647STrevor Wu [MT8188_CLK_AUD_MEMIF_DL10] = "aud_memif_dl10", 87f6b02647STrevor Wu [MT8188_CLK_AUD_MEMIF_DL11] = "aud_memif_dl11", 88f6b02647STrevor Wu }; 89f6b02647STrevor Wu 90f6b02647STrevor Wu struct mt8188_afe_tuner_cfg { 91f6b02647STrevor Wu unsigned int id; 92f6b02647STrevor Wu int apll_div_reg; 93f6b02647STrevor Wu unsigned int apll_div_shift; 94f6b02647STrevor Wu unsigned int apll_div_maskbit; 95f6b02647STrevor Wu unsigned int apll_div_default; 96f6b02647STrevor Wu int ref_ck_sel_reg; 97f6b02647STrevor Wu unsigned int ref_ck_sel_shift; 98f6b02647STrevor Wu unsigned int ref_ck_sel_maskbit; 99f6b02647STrevor Wu unsigned int ref_ck_sel_default; 100f6b02647STrevor Wu int tuner_en_reg; 101f6b02647STrevor Wu unsigned int tuner_en_shift; 102f6b02647STrevor Wu unsigned int tuner_en_maskbit; 103f6b02647STrevor Wu int upper_bound_reg; 104f6b02647STrevor Wu unsigned int upper_bound_shift; 105f6b02647STrevor Wu unsigned int upper_bound_maskbit; 106f6b02647STrevor Wu unsigned int upper_bound_default; 107f6b02647STrevor Wu spinlock_t ctrl_lock; /* lock for apll tuner ctrl*/ 108f6b02647STrevor Wu int ref_cnt; 109f6b02647STrevor Wu }; 110f6b02647STrevor Wu 111f6b02647STrevor Wu static struct mt8188_afe_tuner_cfg 112f6b02647STrevor Wu mt8188_afe_tuner_cfgs[MT8188_AUD_PLL_NUM] = { 113f6b02647STrevor Wu [MT8188_AUD_PLL1] = { 114f6b02647STrevor Wu .id = MT8188_AUD_PLL1, 115f6b02647STrevor Wu .apll_div_reg = AFE_APLL_TUNER_CFG, 116f6b02647STrevor Wu .apll_div_shift = 4, 117f6b02647STrevor Wu .apll_div_maskbit = 0xf, 118f6b02647STrevor Wu .apll_div_default = 0x7, 119f6b02647STrevor Wu .ref_ck_sel_reg = AFE_APLL_TUNER_CFG, 120f6b02647STrevor Wu .ref_ck_sel_shift = 1, 121f6b02647STrevor Wu .ref_ck_sel_maskbit = 0x3, 122f6b02647STrevor Wu .ref_ck_sel_default = 0x2, 123f6b02647STrevor Wu .tuner_en_reg = AFE_APLL_TUNER_CFG, 124f6b02647STrevor Wu .tuner_en_shift = 0, 125f6b02647STrevor Wu .tuner_en_maskbit = 0x1, 126f6b02647STrevor Wu .upper_bound_reg = AFE_APLL_TUNER_CFG, 127f6b02647STrevor Wu .upper_bound_shift = 8, 128f6b02647STrevor Wu .upper_bound_maskbit = 0xff, 129f6b02647STrevor Wu .upper_bound_default = 0x3, 130f6b02647STrevor Wu }, 131f6b02647STrevor Wu [MT8188_AUD_PLL2] = { 132f6b02647STrevor Wu .id = MT8188_AUD_PLL2, 133f6b02647STrevor Wu .apll_div_reg = AFE_APLL_TUNER_CFG1, 134f6b02647STrevor Wu .apll_div_shift = 4, 135f6b02647STrevor Wu .apll_div_maskbit = 0xf, 136f6b02647STrevor Wu .apll_div_default = 0x7, 137f6b02647STrevor Wu .ref_ck_sel_reg = AFE_APLL_TUNER_CFG1, 138f6b02647STrevor Wu .ref_ck_sel_shift = 1, 139f6b02647STrevor Wu .ref_ck_sel_maskbit = 0x3, 140f6b02647STrevor Wu .ref_ck_sel_default = 0x1, 141f6b02647STrevor Wu .tuner_en_reg = AFE_APLL_TUNER_CFG1, 142f6b02647STrevor Wu .tuner_en_shift = 0, 143f6b02647STrevor Wu .tuner_en_maskbit = 0x1, 144f6b02647STrevor Wu .upper_bound_reg = AFE_APLL_TUNER_CFG1, 145f6b02647STrevor Wu .upper_bound_shift = 8, 146f6b02647STrevor Wu .upper_bound_maskbit = 0xff, 147f6b02647STrevor Wu .upper_bound_default = 0x3, 148f6b02647STrevor Wu }, 149f6b02647STrevor Wu [MT8188_AUD_PLL3] = { 150f6b02647STrevor Wu .id = MT8188_AUD_PLL3, 151f6b02647STrevor Wu .apll_div_reg = AFE_EARC_APLL_TUNER_CFG, 152f6b02647STrevor Wu .apll_div_shift = 4, 153f6b02647STrevor Wu .apll_div_maskbit = 0x3f, 154f6b02647STrevor Wu .apll_div_default = 0x3, 155f6b02647STrevor Wu .ref_ck_sel_reg = AFE_EARC_APLL_TUNER_CFG, 156f6b02647STrevor Wu .ref_ck_sel_shift = 24, 157f6b02647STrevor Wu .ref_ck_sel_maskbit = 0x3, 158f6b02647STrevor Wu .ref_ck_sel_default = 0x0, 159f6b02647STrevor Wu .tuner_en_reg = AFE_EARC_APLL_TUNER_CFG, 160f6b02647STrevor Wu .tuner_en_shift = 0, 161f6b02647STrevor Wu .tuner_en_maskbit = 0x1, 162f6b02647STrevor Wu .upper_bound_reg = AFE_EARC_APLL_TUNER_CFG, 163f6b02647STrevor Wu .upper_bound_shift = 12, 164f6b02647STrevor Wu .upper_bound_maskbit = 0xff, 165f6b02647STrevor Wu .upper_bound_default = 0x4, 166f6b02647STrevor Wu }, 167f6b02647STrevor Wu [MT8188_AUD_PLL4] = { 168f6b02647STrevor Wu .id = MT8188_AUD_PLL4, 169f6b02647STrevor Wu .apll_div_reg = AFE_SPDIFIN_APLL_TUNER_CFG, 170f6b02647STrevor Wu .apll_div_shift = 4, 171f6b02647STrevor Wu .apll_div_maskbit = 0x3f, 172f6b02647STrevor Wu .apll_div_default = 0x7, 173f6b02647STrevor Wu .ref_ck_sel_reg = AFE_SPDIFIN_APLL_TUNER_CFG1, 174f6b02647STrevor Wu .ref_ck_sel_shift = 8, 175f6b02647STrevor Wu .ref_ck_sel_maskbit = 0x1, 176f6b02647STrevor Wu .ref_ck_sel_default = 0, 177f6b02647STrevor Wu .tuner_en_reg = AFE_SPDIFIN_APLL_TUNER_CFG, 178f6b02647STrevor Wu .tuner_en_shift = 0, 179f6b02647STrevor Wu .tuner_en_maskbit = 0x1, 180f6b02647STrevor Wu .upper_bound_reg = AFE_SPDIFIN_APLL_TUNER_CFG, 181f6b02647STrevor Wu .upper_bound_shift = 12, 182f6b02647STrevor Wu .upper_bound_maskbit = 0xff, 183f6b02647STrevor Wu .upper_bound_default = 0x4, 184f6b02647STrevor Wu }, 185f6b02647STrevor Wu [MT8188_AUD_PLL5] = { 186f6b02647STrevor Wu .id = MT8188_AUD_PLL5, 187f6b02647STrevor Wu .apll_div_reg = AFE_LINEIN_APLL_TUNER_CFG, 188f6b02647STrevor Wu .apll_div_shift = 4, 189f6b02647STrevor Wu .apll_div_maskbit = 0x3f, 190f6b02647STrevor Wu .apll_div_default = 0x3, 191f6b02647STrevor Wu .ref_ck_sel_reg = AFE_LINEIN_APLL_TUNER_CFG, 192f6b02647STrevor Wu .ref_ck_sel_shift = 24, 193f6b02647STrevor Wu .ref_ck_sel_maskbit = 0x1, 194f6b02647STrevor Wu .ref_ck_sel_default = 0, 195f6b02647STrevor Wu .tuner_en_reg = AFE_LINEIN_APLL_TUNER_CFG, 196f6b02647STrevor Wu .tuner_en_shift = 0, 197f6b02647STrevor Wu .tuner_en_maskbit = 0x1, 198f6b02647STrevor Wu .upper_bound_reg = AFE_LINEIN_APLL_TUNER_CFG, 199f6b02647STrevor Wu .upper_bound_shift = 12, 200f6b02647STrevor Wu .upper_bound_maskbit = 0xff, 201f6b02647STrevor Wu .upper_bound_default = 0x4, 202f6b02647STrevor Wu }, 203f6b02647STrevor Wu }; 204f6b02647STrevor Wu 205f6b02647STrevor Wu static struct mt8188_afe_tuner_cfg *mt8188_afe_found_apll_tuner(unsigned int id) 206f6b02647STrevor Wu { 207f6b02647STrevor Wu if (id >= MT8188_AUD_PLL_NUM) 208f6b02647STrevor Wu return NULL; 209f6b02647STrevor Wu 210f6b02647STrevor Wu return &mt8188_afe_tuner_cfgs[id]; 211f6b02647STrevor Wu } 212f6b02647STrevor Wu 213f6b02647STrevor Wu static int mt8188_afe_init_apll_tuner(unsigned int id) 214f6b02647STrevor Wu { 215f6b02647STrevor Wu struct mt8188_afe_tuner_cfg *cfg = mt8188_afe_found_apll_tuner(id); 216f6b02647STrevor Wu 217f6b02647STrevor Wu if (!cfg) 218f6b02647STrevor Wu return -EINVAL; 219f6b02647STrevor Wu 220f6b02647STrevor Wu cfg->ref_cnt = 0; 221f6b02647STrevor Wu spin_lock_init(&cfg->ctrl_lock); 222f6b02647STrevor Wu 223f6b02647STrevor Wu return 0; 224f6b02647STrevor Wu } 225f6b02647STrevor Wu 226f6b02647STrevor Wu static int mt8188_afe_setup_apll_tuner(struct mtk_base_afe *afe, unsigned int id) 227f6b02647STrevor Wu { 228f6b02647STrevor Wu const struct mt8188_afe_tuner_cfg *cfg = mt8188_afe_found_apll_tuner(id); 229f6b02647STrevor Wu 230f6b02647STrevor Wu if (!cfg) 231f6b02647STrevor Wu return -EINVAL; 232f6b02647STrevor Wu 233f6b02647STrevor Wu regmap_update_bits(afe->regmap, 234f6b02647STrevor Wu cfg->apll_div_reg, 235f6b02647STrevor Wu cfg->apll_div_maskbit << cfg->apll_div_shift, 236f6b02647STrevor Wu cfg->apll_div_default << cfg->apll_div_shift); 237f6b02647STrevor Wu 238f6b02647STrevor Wu regmap_update_bits(afe->regmap, 239f6b02647STrevor Wu cfg->ref_ck_sel_reg, 240f6b02647STrevor Wu cfg->ref_ck_sel_maskbit << cfg->ref_ck_sel_shift, 241f6b02647STrevor Wu cfg->ref_ck_sel_default << cfg->ref_ck_sel_shift); 242f6b02647STrevor Wu 243f6b02647STrevor Wu regmap_update_bits(afe->regmap, 244f6b02647STrevor Wu cfg->upper_bound_reg, 245f6b02647STrevor Wu cfg->upper_bound_maskbit << cfg->upper_bound_shift, 246f6b02647STrevor Wu cfg->upper_bound_default << cfg->upper_bound_shift); 247f6b02647STrevor Wu 248f6b02647STrevor Wu return 0; 249f6b02647STrevor Wu } 250f6b02647STrevor Wu 251f6b02647STrevor Wu static int mt8188_afe_enable_tuner_clk(struct mtk_base_afe *afe, 252f6b02647STrevor Wu unsigned int id) 253f6b02647STrevor Wu { 254f6b02647STrevor Wu struct mt8188_afe_private *afe_priv = afe->platform_priv; 255f6b02647STrevor Wu 256f6b02647STrevor Wu switch (id) { 257f6b02647STrevor Wu case MT8188_AUD_PLL1: 258f6b02647STrevor Wu mt8188_afe_enable_clk(afe, afe_priv->clk[MT8188_CLK_AUD_APLL]); 259f6b02647STrevor Wu mt8188_afe_enable_clk(afe, afe_priv->clk[MT8188_CLK_AUD_APLL1_TUNER]); 260f6b02647STrevor Wu break; 261f6b02647STrevor Wu case MT8188_AUD_PLL2: 262f6b02647STrevor Wu mt8188_afe_enable_clk(afe, afe_priv->clk[MT8188_CLK_AUD_APLL2]); 263f6b02647STrevor Wu mt8188_afe_enable_clk(afe, afe_priv->clk[MT8188_CLK_AUD_APLL2_TUNER]); 264f6b02647STrevor Wu break; 265f6b02647STrevor Wu default: 266f6b02647STrevor Wu return -EINVAL; 267f6b02647STrevor Wu } 268f6b02647STrevor Wu 269f6b02647STrevor Wu return 0; 270f6b02647STrevor Wu } 271f6b02647STrevor Wu 272f6b02647STrevor Wu static int mt8188_afe_disable_tuner_clk(struct mtk_base_afe *afe, 273f6b02647STrevor Wu unsigned int id) 274f6b02647STrevor Wu { 275f6b02647STrevor Wu struct mt8188_afe_private *afe_priv = afe->platform_priv; 276f6b02647STrevor Wu 277f6b02647STrevor Wu switch (id) { 278f6b02647STrevor Wu case MT8188_AUD_PLL1: 279f6b02647STrevor Wu mt8188_afe_disable_clk(afe, afe_priv->clk[MT8188_CLK_AUD_APLL1_TUNER]); 280f6b02647STrevor Wu mt8188_afe_disable_clk(afe, afe_priv->clk[MT8188_CLK_AUD_APLL]); 281f6b02647STrevor Wu break; 282f6b02647STrevor Wu case MT8188_AUD_PLL2: 283f6b02647STrevor Wu mt8188_afe_disable_clk(afe, afe_priv->clk[MT8188_CLK_AUD_APLL2_TUNER]); 284f6b02647STrevor Wu mt8188_afe_disable_clk(afe, afe_priv->clk[MT8188_CLK_AUD_APLL2]); 285f6b02647STrevor Wu break; 286f6b02647STrevor Wu default: 287f6b02647STrevor Wu return -EINVAL; 288f6b02647STrevor Wu } 289f6b02647STrevor Wu 290f6b02647STrevor Wu return 0; 291f6b02647STrevor Wu } 292f6b02647STrevor Wu 293f6b02647STrevor Wu static int mt8188_afe_enable_apll_tuner(struct mtk_base_afe *afe, unsigned int id) 294f6b02647STrevor Wu { 295f6b02647STrevor Wu struct mt8188_afe_tuner_cfg *cfg = mt8188_afe_found_apll_tuner(id); 296f6b02647STrevor Wu unsigned long flags; 297f6b02647STrevor Wu int ret; 298f6b02647STrevor Wu 299f6b02647STrevor Wu if (!cfg) 300f6b02647STrevor Wu return -EINVAL; 301f6b02647STrevor Wu 302f6b02647STrevor Wu ret = mt8188_afe_setup_apll_tuner(afe, id); 303f6b02647STrevor Wu if (ret) 304f6b02647STrevor Wu return ret; 305f6b02647STrevor Wu 306f6b02647STrevor Wu ret = mt8188_afe_enable_tuner_clk(afe, id); 307f6b02647STrevor Wu if (ret) 308f6b02647STrevor Wu return ret; 309f6b02647STrevor Wu 310f6b02647STrevor Wu spin_lock_irqsave(&cfg->ctrl_lock, flags); 311f6b02647STrevor Wu 312f6b02647STrevor Wu cfg->ref_cnt++; 313f6b02647STrevor Wu if (cfg->ref_cnt == 1) 314f6b02647STrevor Wu regmap_update_bits(afe->regmap, 315f6b02647STrevor Wu cfg->tuner_en_reg, 316f6b02647STrevor Wu cfg->tuner_en_maskbit << cfg->tuner_en_shift, 317f6b02647STrevor Wu BIT(cfg->tuner_en_shift)); 318f6b02647STrevor Wu 319f6b02647STrevor Wu spin_unlock_irqrestore(&cfg->ctrl_lock, flags); 320f6b02647STrevor Wu 321f6b02647STrevor Wu return 0; 322f6b02647STrevor Wu } 323f6b02647STrevor Wu 324f6b02647STrevor Wu static int mt8188_afe_disable_apll_tuner(struct mtk_base_afe *afe, unsigned int id) 325f6b02647STrevor Wu { 326f6b02647STrevor Wu struct mt8188_afe_tuner_cfg *cfg = mt8188_afe_found_apll_tuner(id); 327f6b02647STrevor Wu unsigned long flags; 328f6b02647STrevor Wu int ret; 329f6b02647STrevor Wu 330f6b02647STrevor Wu if (!cfg) 331f6b02647STrevor Wu return -EINVAL; 332f6b02647STrevor Wu 333f6b02647STrevor Wu spin_lock_irqsave(&cfg->ctrl_lock, flags); 334f6b02647STrevor Wu 335f6b02647STrevor Wu cfg->ref_cnt--; 336f6b02647STrevor Wu if (cfg->ref_cnt == 0) 337f6b02647STrevor Wu regmap_update_bits(afe->regmap, 338f6b02647STrevor Wu cfg->tuner_en_reg, 339f6b02647STrevor Wu cfg->tuner_en_maskbit << cfg->tuner_en_shift, 340f6b02647STrevor Wu 0 << cfg->tuner_en_shift); 341f6b02647STrevor Wu else if (cfg->ref_cnt < 0) 342f6b02647STrevor Wu cfg->ref_cnt = 0; 343f6b02647STrevor Wu 344f6b02647STrevor Wu spin_unlock_irqrestore(&cfg->ctrl_lock, flags); 345f6b02647STrevor Wu 346f6b02647STrevor Wu ret = mt8188_afe_disable_tuner_clk(afe, id); 347f6b02647STrevor Wu if (ret) 348f6b02647STrevor Wu return ret; 349f6b02647STrevor Wu 350f6b02647STrevor Wu return 0; 351f6b02647STrevor Wu } 352f6b02647STrevor Wu 353f6b02647STrevor Wu int mt8188_afe_get_mclk_source_clk_id(int sel) 354f6b02647STrevor Wu { 355f6b02647STrevor Wu switch (sel) { 356f6b02647STrevor Wu case MT8188_MCK_SEL_26M: 357f6b02647STrevor Wu return MT8188_CLK_XTAL_26M; 358f6b02647STrevor Wu case MT8188_MCK_SEL_APLL1: 359f6b02647STrevor Wu return MT8188_CLK_APMIXED_APLL1; 360f6b02647STrevor Wu case MT8188_MCK_SEL_APLL2: 361f6b02647STrevor Wu return MT8188_CLK_APMIXED_APLL2; 362f6b02647STrevor Wu default: 363f6b02647STrevor Wu return -EINVAL; 364f6b02647STrevor Wu } 365f6b02647STrevor Wu } 366f6b02647STrevor Wu 367f6b02647STrevor Wu int mt8188_afe_get_mclk_source_rate(struct mtk_base_afe *afe, int apll) 368f6b02647STrevor Wu { 369f6b02647STrevor Wu struct mt8188_afe_private *afe_priv = afe->platform_priv; 370f6b02647STrevor Wu int clk_id = mt8188_afe_get_mclk_source_clk_id(apll); 371f6b02647STrevor Wu 372f6b02647STrevor Wu if (clk_id < 0) { 373f6b02647STrevor Wu dev_dbg(afe->dev, "invalid clk id\n"); 374f6b02647STrevor Wu return 0; 375f6b02647STrevor Wu } 376f6b02647STrevor Wu 377f6b02647STrevor Wu return clk_get_rate(afe_priv->clk[clk_id]); 378f6b02647STrevor Wu } 379f6b02647STrevor Wu 380f6b02647STrevor Wu int mt8188_afe_get_default_mclk_source_by_rate(int rate) 381f6b02647STrevor Wu { 382f6b02647STrevor Wu return ((rate % 8000) == 0) ? 383f6b02647STrevor Wu MT8188_MCK_SEL_APLL1 : MT8188_MCK_SEL_APLL2; 384f6b02647STrevor Wu } 385f6b02647STrevor Wu 3869be0213aSTrevor Wu int mt8188_get_apll_by_rate(struct mtk_base_afe *afe, int rate) 3879be0213aSTrevor Wu { 3889be0213aSTrevor Wu return ((rate % 8000) == 0) ? MT8188_AUD_PLL1 : MT8188_AUD_PLL2; 3899be0213aSTrevor Wu } 3909be0213aSTrevor Wu 3919be0213aSTrevor Wu int mt8188_get_apll_by_name(struct mtk_base_afe *afe, const char *name) 3929be0213aSTrevor Wu { 3939be0213aSTrevor Wu if (strcmp(name, APLL1_W_NAME) == 0) 3949be0213aSTrevor Wu return MT8188_AUD_PLL1; 3959be0213aSTrevor Wu 3969be0213aSTrevor Wu return MT8188_AUD_PLL2; 3979be0213aSTrevor Wu } 3989be0213aSTrevor Wu 399f6b02647STrevor Wu int mt8188_afe_init_clock(struct mtk_base_afe *afe) 400f6b02647STrevor Wu { 401f6b02647STrevor Wu struct mt8188_afe_private *afe_priv = afe->platform_priv; 402f6b02647STrevor Wu int i, ret; 403f6b02647STrevor Wu 404f6b02647STrevor Wu ret = mt8188_audsys_clk_register(afe); 405f6b02647STrevor Wu if (ret) { 406f6b02647STrevor Wu dev_err(afe->dev, "register audsys clk fail %d\n", ret); 407f6b02647STrevor Wu return ret; 408f6b02647STrevor Wu } 409f6b02647STrevor Wu 410f6b02647STrevor Wu afe_priv->clk = 411f6b02647STrevor Wu devm_kcalloc(afe->dev, MT8188_CLK_NUM, sizeof(*afe_priv->clk), 412f6b02647STrevor Wu GFP_KERNEL); 413f6b02647STrevor Wu if (!afe_priv->clk) 414f6b02647STrevor Wu return -ENOMEM; 415f6b02647STrevor Wu 416f6b02647STrevor Wu for (i = 0; i < MT8188_CLK_NUM; i++) { 417f6b02647STrevor Wu afe_priv->clk[i] = devm_clk_get(afe->dev, aud_clks[i]); 418f6b02647STrevor Wu if (IS_ERR(afe_priv->clk[i])) { 419f6b02647STrevor Wu dev_err(afe->dev, "%s(), devm_clk_get %s fail, ret %ld\n", 420f6b02647STrevor Wu __func__, aud_clks[i], 421f6b02647STrevor Wu PTR_ERR(afe_priv->clk[i])); 422f6b02647STrevor Wu return PTR_ERR(afe_priv->clk[i]); 423f6b02647STrevor Wu } 424f6b02647STrevor Wu } 425f6b02647STrevor Wu 426f6b02647STrevor Wu /* initial tuner */ 427f6b02647STrevor Wu for (i = 0; i < MT8188_AUD_PLL_NUM; i++) { 428f6b02647STrevor Wu ret = mt8188_afe_init_apll_tuner(i); 429f6b02647STrevor Wu if (ret) { 430f6b02647STrevor Wu dev_info(afe->dev, "%s(), init apll_tuner%d failed", 431f6b02647STrevor Wu __func__, (i + 1)); 432f6b02647STrevor Wu return -EINVAL; 433f6b02647STrevor Wu } 434f6b02647STrevor Wu } 435f6b02647STrevor Wu 436f6b02647STrevor Wu return 0; 437f6b02647STrevor Wu } 438f6b02647STrevor Wu 439f6b02647STrevor Wu void mt8188_afe_deinit_clock(void *priv) 440f6b02647STrevor Wu { 441f6b02647STrevor Wu struct mtk_base_afe *afe = priv; 442f6b02647STrevor Wu 443f6b02647STrevor Wu mt8188_audsys_clk_unregister(afe); 444f6b02647STrevor Wu } 445f6b02647STrevor Wu 446f6b02647STrevor Wu int mt8188_afe_enable_clk(struct mtk_base_afe *afe, struct clk *clk) 447f6b02647STrevor Wu { 448f6b02647STrevor Wu int ret; 449f6b02647STrevor Wu 450f6b02647STrevor Wu if (clk) { 451f6b02647STrevor Wu ret = clk_prepare_enable(clk); 452f6b02647STrevor Wu if (ret) { 453f6b02647STrevor Wu dev_dbg(afe->dev, "%s(), failed to enable clk\n", 454f6b02647STrevor Wu __func__); 455f6b02647STrevor Wu return ret; 456f6b02647STrevor Wu } 457f6b02647STrevor Wu } else { 458f6b02647STrevor Wu dev_dbg(afe->dev, "NULL clk\n"); 459f6b02647STrevor Wu } 460f6b02647STrevor Wu return 0; 461f6b02647STrevor Wu } 462f6b02647STrevor Wu EXPORT_SYMBOL_GPL(mt8188_afe_enable_clk); 463f6b02647STrevor Wu 464f6b02647STrevor Wu void mt8188_afe_disable_clk(struct mtk_base_afe *afe, struct clk *clk) 465f6b02647STrevor Wu { 466f6b02647STrevor Wu if (clk) 467f6b02647STrevor Wu clk_disable_unprepare(clk); 468f6b02647STrevor Wu else 469f6b02647STrevor Wu dev_dbg(afe->dev, "NULL clk\n"); 470f6b02647STrevor Wu } 471f6b02647STrevor Wu EXPORT_SYMBOL_GPL(mt8188_afe_disable_clk); 472f6b02647STrevor Wu 473f6b02647STrevor Wu int mt8188_afe_set_clk_rate(struct mtk_base_afe *afe, struct clk *clk, 474f6b02647STrevor Wu unsigned int rate) 475f6b02647STrevor Wu { 476f6b02647STrevor Wu int ret; 477f6b02647STrevor Wu 478f6b02647STrevor Wu if (clk) { 479f6b02647STrevor Wu ret = clk_set_rate(clk, rate); 480f6b02647STrevor Wu if (ret) { 481f6b02647STrevor Wu dev_dbg(afe->dev, "%s(), failed to set clk rate\n", 482f6b02647STrevor Wu __func__); 483f6b02647STrevor Wu return ret; 484f6b02647STrevor Wu } 485f6b02647STrevor Wu } 486f6b02647STrevor Wu 487f6b02647STrevor Wu return 0; 488f6b02647STrevor Wu } 489f6b02647STrevor Wu 490f6b02647STrevor Wu int mt8188_afe_set_clk_parent(struct mtk_base_afe *afe, struct clk *clk, 491f6b02647STrevor Wu struct clk *parent) 492f6b02647STrevor Wu { 493f6b02647STrevor Wu int ret; 494f6b02647STrevor Wu 495f6b02647STrevor Wu if (clk && parent) { 496f6b02647STrevor Wu ret = clk_set_parent(clk, parent); 497f6b02647STrevor Wu if (ret) { 4989be0213aSTrevor Wu dev_dbg(afe->dev, "%s(), failed to set clk parent %d\n", 4999be0213aSTrevor Wu __func__, ret); 500f6b02647STrevor Wu return ret; 501f6b02647STrevor Wu } 502f6b02647STrevor Wu } 503f6b02647STrevor Wu 504f6b02647STrevor Wu return 0; 505f6b02647STrevor Wu } 506f6b02647STrevor Wu 507f6b02647STrevor Wu static unsigned int get_top_cg_reg(unsigned int cg_type) 508f6b02647STrevor Wu { 509f6b02647STrevor Wu switch (cg_type) { 510f6b02647STrevor Wu case MT8188_TOP_CG_A1SYS_TIMING: 511f6b02647STrevor Wu case MT8188_TOP_CG_A2SYS_TIMING: 512f6b02647STrevor Wu case MT8188_TOP_CG_26M_TIMING: 513f6b02647STrevor Wu return ASYS_TOP_CON; 514f6b02647STrevor Wu default: 515f6b02647STrevor Wu return 0; 516f6b02647STrevor Wu } 517f6b02647STrevor Wu } 518f6b02647STrevor Wu 519f6b02647STrevor Wu static unsigned int get_top_cg_mask(unsigned int cg_type) 520f6b02647STrevor Wu { 521f6b02647STrevor Wu switch (cg_type) { 522f6b02647STrevor Wu case MT8188_TOP_CG_A1SYS_TIMING: 523f6b02647STrevor Wu return ASYS_TOP_CON_A1SYS_TIMING_ON; 524f6b02647STrevor Wu case MT8188_TOP_CG_A2SYS_TIMING: 525f6b02647STrevor Wu return ASYS_TOP_CON_A2SYS_TIMING_ON; 526f6b02647STrevor Wu case MT8188_TOP_CG_26M_TIMING: 527f6b02647STrevor Wu return ASYS_TOP_CON_26M_TIMING_ON; 528f6b02647STrevor Wu default: 529f6b02647STrevor Wu return 0; 530f6b02647STrevor Wu } 531f6b02647STrevor Wu } 532f6b02647STrevor Wu 533f6b02647STrevor Wu static unsigned int get_top_cg_on_val(unsigned int cg_type) 534f6b02647STrevor Wu { 535f6b02647STrevor Wu switch (cg_type) { 536f6b02647STrevor Wu case MT8188_TOP_CG_A1SYS_TIMING: 537f6b02647STrevor Wu case MT8188_TOP_CG_A2SYS_TIMING: 538f6b02647STrevor Wu case MT8188_TOP_CG_26M_TIMING: 539f6b02647STrevor Wu return get_top_cg_mask(cg_type); 540f6b02647STrevor Wu default: 541f6b02647STrevor Wu return 0; 542f6b02647STrevor Wu } 543f6b02647STrevor Wu } 544f6b02647STrevor Wu 545f6b02647STrevor Wu static unsigned int get_top_cg_off_val(unsigned int cg_type) 546f6b02647STrevor Wu { 547f6b02647STrevor Wu switch (cg_type) { 548f6b02647STrevor Wu case MT8188_TOP_CG_A1SYS_TIMING: 549f6b02647STrevor Wu case MT8188_TOP_CG_A2SYS_TIMING: 550f6b02647STrevor Wu case MT8188_TOP_CG_26M_TIMING: 551f6b02647STrevor Wu return 0; 552f6b02647STrevor Wu default: 553f6b02647STrevor Wu return get_top_cg_mask(cg_type); 554f6b02647STrevor Wu } 555f6b02647STrevor Wu } 556f6b02647STrevor Wu 557f6b02647STrevor Wu static int mt8188_afe_enable_top_cg(struct mtk_base_afe *afe, unsigned int cg_type) 558f6b02647STrevor Wu { 559f6b02647STrevor Wu unsigned int reg = get_top_cg_reg(cg_type); 560f6b02647STrevor Wu unsigned int mask = get_top_cg_mask(cg_type); 561f6b02647STrevor Wu unsigned int val = get_top_cg_on_val(cg_type); 562f6b02647STrevor Wu 563f6b02647STrevor Wu regmap_update_bits(afe->regmap, reg, mask, val); 564f6b02647STrevor Wu 565f6b02647STrevor Wu return 0; 566f6b02647STrevor Wu } 567f6b02647STrevor Wu 568f6b02647STrevor Wu static int mt8188_afe_disable_top_cg(struct mtk_base_afe *afe, unsigned int cg_type) 569f6b02647STrevor Wu { 570f6b02647STrevor Wu unsigned int reg = get_top_cg_reg(cg_type); 571f6b02647STrevor Wu unsigned int mask = get_top_cg_mask(cg_type); 572f6b02647STrevor Wu unsigned int val = get_top_cg_off_val(cg_type); 573f6b02647STrevor Wu 574f6b02647STrevor Wu regmap_update_bits(afe->regmap, reg, mask, val); 575f6b02647STrevor Wu 576f6b02647STrevor Wu return 0; 577f6b02647STrevor Wu } 578f6b02647STrevor Wu 579f6b02647STrevor Wu int mt8188_afe_enable_reg_rw_clk(struct mtk_base_afe *afe) 580f6b02647STrevor Wu { 581f6b02647STrevor Wu struct mt8188_afe_private *afe_priv = afe->platform_priv; 582f6b02647STrevor Wu 583f6b02647STrevor Wu /* bus clock for AFE external access, like DRAM */ 584f6b02647STrevor Wu mt8188_afe_enable_clk(afe, afe_priv->clk[MT8188_CLK_TOP_AUDIO_LOCAL_BUS_SEL]); 585f6b02647STrevor Wu 586f6b02647STrevor Wu /* bus clock for AFE internal access, like AFE SRAM */ 587f6b02647STrevor Wu mt8188_afe_enable_clk(afe, afe_priv->clk[MT8188_CLK_TOP_AUD_INTBUS_SEL]); 588f6b02647STrevor Wu 589f6b02647STrevor Wu /* audio 26m clock source */ 590f6b02647STrevor Wu mt8188_afe_enable_clk(afe, afe_priv->clk[MT8188_CLK_ADSP_AUDIO_26M]); 591f6b02647STrevor Wu 592f6b02647STrevor Wu /* AFE hw clock */ 593f6b02647STrevor Wu mt8188_afe_enable_clk(afe, afe_priv->clk[MT8188_CLK_AUD_AFE]); 594f6b02647STrevor Wu mt8188_afe_enable_clk(afe, afe_priv->clk[MT8188_CLK_AUD_A1SYS_HP]); 595f6b02647STrevor Wu mt8188_afe_enable_clk(afe, afe_priv->clk[MT8188_CLK_AUD_A1SYS]); 596f6b02647STrevor Wu 597f6b02647STrevor Wu return 0; 598f6b02647STrevor Wu } 599f6b02647STrevor Wu 600f6b02647STrevor Wu int mt8188_afe_disable_reg_rw_clk(struct mtk_base_afe *afe) 601f6b02647STrevor Wu { 602f6b02647STrevor Wu struct mt8188_afe_private *afe_priv = afe->platform_priv; 603f6b02647STrevor Wu 604f6b02647STrevor Wu mt8188_afe_disable_clk(afe, afe_priv->clk[MT8188_CLK_AUD_A1SYS]); 605f6b02647STrevor Wu mt8188_afe_disable_clk(afe, afe_priv->clk[MT8188_CLK_AUD_A1SYS_HP]); 606f6b02647STrevor Wu mt8188_afe_disable_clk(afe, afe_priv->clk[MT8188_CLK_AUD_AFE]); 607f6b02647STrevor Wu mt8188_afe_disable_clk(afe, afe_priv->clk[MT8188_CLK_ADSP_AUDIO_26M]); 608f6b02647STrevor Wu mt8188_afe_disable_clk(afe, afe_priv->clk[MT8188_CLK_TOP_AUD_INTBUS_SEL]); 609f6b02647STrevor Wu mt8188_afe_disable_clk(afe, afe_priv->clk[MT8188_CLK_TOP_AUDIO_LOCAL_BUS_SEL]); 610f6b02647STrevor Wu 611f6b02647STrevor Wu return 0; 612f6b02647STrevor Wu } 613f6b02647STrevor Wu 614f6b02647STrevor Wu static int mt8188_afe_enable_afe_on(struct mtk_base_afe *afe) 615f6b02647STrevor Wu { 616f6b02647STrevor Wu regmap_update_bits(afe->regmap, AFE_DAC_CON0, 0x1, 0x1); 617f6b02647STrevor Wu return 0; 618f6b02647STrevor Wu } 619f6b02647STrevor Wu 620f6b02647STrevor Wu static int mt8188_afe_disable_afe_on(struct mtk_base_afe *afe) 621f6b02647STrevor Wu { 622f6b02647STrevor Wu regmap_update_bits(afe->regmap, AFE_DAC_CON0, 0x1, 0x0); 623f6b02647STrevor Wu return 0; 624f6b02647STrevor Wu } 625f6b02647STrevor Wu 6269be0213aSTrevor Wu static int mt8188_afe_enable_a1sys(struct mtk_base_afe *afe) 6279be0213aSTrevor Wu { 6289be0213aSTrevor Wu struct mt8188_afe_private *afe_priv = afe->platform_priv; 6299be0213aSTrevor Wu int ret; 6309be0213aSTrevor Wu 6319be0213aSTrevor Wu ret = mt8188_afe_enable_clk(afe, afe_priv->clk[MT8188_CLK_AUD_A1SYS]); 6329be0213aSTrevor Wu if (ret) 6339be0213aSTrevor Wu return ret; 6349be0213aSTrevor Wu 6359be0213aSTrevor Wu return mt8188_afe_enable_top_cg(afe, MT8188_TOP_CG_A1SYS_TIMING); 6369be0213aSTrevor Wu } 6379be0213aSTrevor Wu 6389be0213aSTrevor Wu static int mt8188_afe_disable_a1sys(struct mtk_base_afe *afe) 639f6b02647STrevor Wu { 640f6b02647STrevor Wu struct mt8188_afe_private *afe_priv = afe->platform_priv; 641f6b02647STrevor Wu 6429be0213aSTrevor Wu mt8188_afe_disable_top_cg(afe, MT8188_TOP_CG_A1SYS_TIMING); 6439be0213aSTrevor Wu mt8188_afe_disable_clk(afe, afe_priv->clk[MT8188_CLK_AUD_A1SYS]); 6449be0213aSTrevor Wu return 0; 6459be0213aSTrevor Wu } 646f6b02647STrevor Wu 6479be0213aSTrevor Wu static int mt8188_afe_enable_a2sys(struct mtk_base_afe *afe) 6489be0213aSTrevor Wu { 6499be0213aSTrevor Wu struct mt8188_afe_private *afe_priv = afe->platform_priv; 6509be0213aSTrevor Wu int ret; 6519be0213aSTrevor Wu 6529be0213aSTrevor Wu ret = mt8188_afe_enable_clk(afe, afe_priv->clk[MT8188_CLK_AUD_A2SYS]); 6539be0213aSTrevor Wu if (ret) 6549be0213aSTrevor Wu return ret; 6559be0213aSTrevor Wu 6569be0213aSTrevor Wu return mt8188_afe_enable_top_cg(afe, MT8188_TOP_CG_A2SYS_TIMING); 6579be0213aSTrevor Wu } 6589be0213aSTrevor Wu 6599be0213aSTrevor Wu static int mt8188_afe_disable_a2sys(struct mtk_base_afe *afe) 6609be0213aSTrevor Wu { 6619be0213aSTrevor Wu struct mt8188_afe_private *afe_priv = afe->platform_priv; 6629be0213aSTrevor Wu 6639be0213aSTrevor Wu mt8188_afe_disable_top_cg(afe, MT8188_TOP_CG_A2SYS_TIMING); 6649be0213aSTrevor Wu mt8188_afe_disable_clk(afe, afe_priv->clk[MT8188_CLK_AUD_A2SYS]); 6659be0213aSTrevor Wu return 0; 6669be0213aSTrevor Wu } 6679be0213aSTrevor Wu 6689be0213aSTrevor Wu int mt8188_apll1_enable(struct mtk_base_afe *afe) 6699be0213aSTrevor Wu { 6709be0213aSTrevor Wu struct mt8188_afe_private *afe_priv = afe->platform_priv; 6719be0213aSTrevor Wu int ret; 6729be0213aSTrevor Wu 6739be0213aSTrevor Wu ret = mt8188_afe_enable_clk(afe, afe_priv->clk[MT8188_CLK_TOP_APLL1_D4]); 6749be0213aSTrevor Wu if (ret) 6759be0213aSTrevor Wu return ret; 6769be0213aSTrevor Wu 6779be0213aSTrevor Wu ret = mt8188_afe_set_clk_parent(afe, afe_priv->clk[MT8188_CLK_TOP_A1SYS_HP_SEL], 6789be0213aSTrevor Wu afe_priv->clk[MT8188_CLK_TOP_APLL1_D4]); 6799be0213aSTrevor Wu if (ret) 6809be0213aSTrevor Wu goto err_clk_parent; 6819be0213aSTrevor Wu 6829be0213aSTrevor Wu ret = mt8188_afe_enable_apll_tuner(afe, MT8188_AUD_PLL1); 6839be0213aSTrevor Wu if (ret) 6849be0213aSTrevor Wu goto err_apll_tuner; 6859be0213aSTrevor Wu 6869be0213aSTrevor Wu ret = mt8188_afe_enable_a1sys(afe); 6879be0213aSTrevor Wu if (ret) 6889be0213aSTrevor Wu goto err_a1sys; 6899be0213aSTrevor Wu 6909be0213aSTrevor Wu return 0; 6919be0213aSTrevor Wu 6929be0213aSTrevor Wu err_a1sys: 6939be0213aSTrevor Wu mt8188_afe_disable_apll_tuner(afe, MT8188_AUD_PLL1); 6949be0213aSTrevor Wu err_apll_tuner: 6959be0213aSTrevor Wu mt8188_afe_set_clk_parent(afe, afe_priv->clk[MT8188_CLK_TOP_A1SYS_HP_SEL], 6969be0213aSTrevor Wu afe_priv->clk[MT8188_CLK_XTAL_26M]); 6979be0213aSTrevor Wu err_clk_parent: 6989be0213aSTrevor Wu mt8188_afe_disable_clk(afe, afe_priv->clk[MT8188_CLK_TOP_APLL1_D4]); 6999be0213aSTrevor Wu 7009be0213aSTrevor Wu return ret; 7019be0213aSTrevor Wu } 7029be0213aSTrevor Wu 7039be0213aSTrevor Wu int mt8188_apll1_disable(struct mtk_base_afe *afe) 7049be0213aSTrevor Wu { 7059be0213aSTrevor Wu struct mt8188_afe_private *afe_priv = afe->platform_priv; 7069be0213aSTrevor Wu 7079be0213aSTrevor Wu mt8188_afe_disable_a1sys(afe); 7089be0213aSTrevor Wu mt8188_afe_disable_apll_tuner(afe, MT8188_AUD_PLL1); 7099be0213aSTrevor Wu mt8188_afe_set_clk_parent(afe, afe_priv->clk[MT8188_CLK_TOP_A1SYS_HP_SEL], 7109be0213aSTrevor Wu afe_priv->clk[MT8188_CLK_XTAL_26M]); 7119be0213aSTrevor Wu mt8188_afe_disable_clk(afe, afe_priv->clk[MT8188_CLK_TOP_APLL1_D4]); 712f6b02647STrevor Wu 713f6b02647STrevor Wu return 0; 714f6b02647STrevor Wu } 715f6b02647STrevor Wu 7169be0213aSTrevor Wu int mt8188_apll2_enable(struct mtk_base_afe *afe) 717f6b02647STrevor Wu { 7189be0213aSTrevor Wu int ret; 719f6b02647STrevor Wu 7209be0213aSTrevor Wu ret = mt8188_afe_enable_apll_tuner(afe, MT8188_AUD_PLL2); 7219be0213aSTrevor Wu if (ret) 7229be0213aSTrevor Wu return ret; 723f6b02647STrevor Wu 7249be0213aSTrevor Wu ret = mt8188_afe_enable_a2sys(afe); 7259be0213aSTrevor Wu if (ret) 7269be0213aSTrevor Wu goto err_a2sys; 727f6b02647STrevor Wu 728f6b02647STrevor Wu return 0; 7299be0213aSTrevor Wu err_a2sys: 7309be0213aSTrevor Wu mt8188_afe_disable_apll_tuner(afe, MT8188_AUD_PLL2); 7319be0213aSTrevor Wu 7329be0213aSTrevor Wu return ret; 7339be0213aSTrevor Wu } 7349be0213aSTrevor Wu 7359be0213aSTrevor Wu int mt8188_apll2_disable(struct mtk_base_afe *afe) 7369be0213aSTrevor Wu { 7379be0213aSTrevor Wu mt8188_afe_disable_a2sys(afe); 7389be0213aSTrevor Wu mt8188_afe_disable_apll_tuner(afe, MT8188_AUD_PLL2); 7399be0213aSTrevor Wu return 0; 740f6b02647STrevor Wu } 741f6b02647STrevor Wu 742f6b02647STrevor Wu int mt8188_afe_enable_main_clock(struct mtk_base_afe *afe) 743f6b02647STrevor Wu { 7449be0213aSTrevor Wu mt8188_afe_enable_top_cg(afe, MT8188_TOP_CG_26M_TIMING); 745f6b02647STrevor Wu mt8188_afe_enable_afe_on(afe); 746f6b02647STrevor Wu return 0; 747f6b02647STrevor Wu } 748f6b02647STrevor Wu 749f6b02647STrevor Wu int mt8188_afe_disable_main_clock(struct mtk_base_afe *afe) 750f6b02647STrevor Wu { 751f6b02647STrevor Wu mt8188_afe_disable_afe_on(afe); 7529be0213aSTrevor Wu mt8188_afe_disable_top_cg(afe, MT8188_TOP_CG_26M_TIMING); 753f6b02647STrevor Wu return 0; 754f6b02647STrevor Wu } 755