162306a36Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0 262306a36Sopenharmony_ci/* 362306a36Sopenharmony_ci * mt8195-afe-clk.c -- Mediatek 8195 afe clock ctrl 462306a36Sopenharmony_ci * 562306a36Sopenharmony_ci * Copyright (c) 2021 MediaTek Inc. 662306a36Sopenharmony_ci * Author: Bicycle Tsai <bicycle.tsai@mediatek.com> 762306a36Sopenharmony_ci * Trevor Wu <trevor.wu@mediatek.com> 862306a36Sopenharmony_ci */ 962306a36Sopenharmony_ci 1062306a36Sopenharmony_ci#include <linux/clk.h> 1162306a36Sopenharmony_ci 1262306a36Sopenharmony_ci#include "mt8195-afe-common.h" 1362306a36Sopenharmony_ci#include "mt8195-afe-clk.h" 1462306a36Sopenharmony_ci#include "mt8195-reg.h" 1562306a36Sopenharmony_ci#include "mt8195-audsys-clk.h" 1662306a36Sopenharmony_ci 1762306a36Sopenharmony_cistatic const char *aud_clks[MT8195_CLK_NUM] = { 1862306a36Sopenharmony_ci /* xtal */ 1962306a36Sopenharmony_ci [MT8195_CLK_XTAL_26M] = "clk26m", 2062306a36Sopenharmony_ci /* divider */ 2162306a36Sopenharmony_ci [MT8195_CLK_TOP_APLL1] = "apll1_ck", 2262306a36Sopenharmony_ci [MT8195_CLK_TOP_APLL2] = "apll2_ck", 2362306a36Sopenharmony_ci [MT8195_CLK_TOP_APLL12_DIV0] = "apll12_div0", 2462306a36Sopenharmony_ci [MT8195_CLK_TOP_APLL12_DIV1] = "apll12_div1", 2562306a36Sopenharmony_ci [MT8195_CLK_TOP_APLL12_DIV2] = "apll12_div2", 2662306a36Sopenharmony_ci [MT8195_CLK_TOP_APLL12_DIV3] = "apll12_div3", 2762306a36Sopenharmony_ci [MT8195_CLK_TOP_APLL12_DIV9] = "apll12_div9", 2862306a36Sopenharmony_ci /* mux */ 2962306a36Sopenharmony_ci [MT8195_CLK_TOP_A1SYS_HP_SEL] = "a1sys_hp_sel", 3062306a36Sopenharmony_ci [MT8195_CLK_TOP_AUD_INTBUS_SEL] = "aud_intbus_sel", 3162306a36Sopenharmony_ci [MT8195_CLK_TOP_AUDIO_H_SEL] = "audio_h_sel", 3262306a36Sopenharmony_ci [MT8195_CLK_TOP_AUDIO_LOCAL_BUS_SEL] = "audio_local_bus_sel", 3362306a36Sopenharmony_ci [MT8195_CLK_TOP_DPTX_M_SEL] = "dptx_m_sel", 3462306a36Sopenharmony_ci [MT8195_CLK_TOP_I2SO1_M_SEL] = "i2so1_m_sel", 3562306a36Sopenharmony_ci [MT8195_CLK_TOP_I2SO2_M_SEL] = "i2so2_m_sel", 3662306a36Sopenharmony_ci [MT8195_CLK_TOP_I2SI1_M_SEL] = "i2si1_m_sel", 3762306a36Sopenharmony_ci [MT8195_CLK_TOP_I2SI2_M_SEL] = "i2si2_m_sel", 3862306a36Sopenharmony_ci /* clock gate */ 3962306a36Sopenharmony_ci [MT8195_CLK_INFRA_AO_AUDIO_26M_B] = "infra_ao_audio_26m_b", 4062306a36Sopenharmony_ci [MT8195_CLK_SCP_ADSP_AUDIODSP] = "scp_adsp_audiodsp", 4162306a36Sopenharmony_ci /* afe clock gate */ 4262306a36Sopenharmony_ci [MT8195_CLK_AUD_AFE] = "aud_afe", 4362306a36Sopenharmony_ci [MT8195_CLK_AUD_APLL1_TUNER] = "aud_apll1_tuner", 4462306a36Sopenharmony_ci [MT8195_CLK_AUD_APLL2_TUNER] = "aud_apll2_tuner", 4562306a36Sopenharmony_ci [MT8195_CLK_AUD_APLL] = "aud_apll", 4662306a36Sopenharmony_ci [MT8195_CLK_AUD_APLL2] = "aud_apll2", 4762306a36Sopenharmony_ci [MT8195_CLK_AUD_DAC] = "aud_dac", 4862306a36Sopenharmony_ci [MT8195_CLK_AUD_ADC] = "aud_adc", 4962306a36Sopenharmony_ci [MT8195_CLK_AUD_DAC_HIRES] = "aud_dac_hires", 5062306a36Sopenharmony_ci [MT8195_CLK_AUD_A1SYS_HP] = "aud_a1sys_hp", 5162306a36Sopenharmony_ci [MT8195_CLK_AUD_ADC_HIRES] = "aud_adc_hires", 5262306a36Sopenharmony_ci [MT8195_CLK_AUD_ADDA6_ADC] = "aud_adda6_adc", 5362306a36Sopenharmony_ci [MT8195_CLK_AUD_ADDA6_ADC_HIRES] = "aud_adda6_adc_hires", 5462306a36Sopenharmony_ci [MT8195_CLK_AUD_I2SIN] = "aud_i2sin", 5562306a36Sopenharmony_ci [MT8195_CLK_AUD_TDM_IN] = "aud_tdm_in", 5662306a36Sopenharmony_ci [MT8195_CLK_AUD_I2S_OUT] = "aud_i2s_out", 5762306a36Sopenharmony_ci [MT8195_CLK_AUD_TDM_OUT] = "aud_tdm_out", 5862306a36Sopenharmony_ci [MT8195_CLK_AUD_HDMI_OUT] = "aud_hdmi_out", 5962306a36Sopenharmony_ci [MT8195_CLK_AUD_ASRC11] = "aud_asrc11", 6062306a36Sopenharmony_ci [MT8195_CLK_AUD_ASRC12] = "aud_asrc12", 6162306a36Sopenharmony_ci [MT8195_CLK_AUD_A1SYS] = "aud_a1sys", 6262306a36Sopenharmony_ci [MT8195_CLK_AUD_A2SYS] = "aud_a2sys", 6362306a36Sopenharmony_ci [MT8195_CLK_AUD_PCMIF] = "aud_pcmif", 6462306a36Sopenharmony_ci [MT8195_CLK_AUD_MEMIF_UL1] = "aud_memif_ul1", 6562306a36Sopenharmony_ci [MT8195_CLK_AUD_MEMIF_UL2] = "aud_memif_ul2", 6662306a36Sopenharmony_ci [MT8195_CLK_AUD_MEMIF_UL3] = "aud_memif_ul3", 6762306a36Sopenharmony_ci [MT8195_CLK_AUD_MEMIF_UL4] = "aud_memif_ul4", 6862306a36Sopenharmony_ci [MT8195_CLK_AUD_MEMIF_UL5] = "aud_memif_ul5", 6962306a36Sopenharmony_ci [MT8195_CLK_AUD_MEMIF_UL6] = "aud_memif_ul6", 7062306a36Sopenharmony_ci [MT8195_CLK_AUD_MEMIF_UL8] = "aud_memif_ul8", 7162306a36Sopenharmony_ci [MT8195_CLK_AUD_MEMIF_UL9] = "aud_memif_ul9", 7262306a36Sopenharmony_ci [MT8195_CLK_AUD_MEMIF_UL10] = "aud_memif_ul10", 7362306a36Sopenharmony_ci [MT8195_CLK_AUD_MEMIF_DL2] = "aud_memif_dl2", 7462306a36Sopenharmony_ci [MT8195_CLK_AUD_MEMIF_DL3] = "aud_memif_dl3", 7562306a36Sopenharmony_ci [MT8195_CLK_AUD_MEMIF_DL6] = "aud_memif_dl6", 7662306a36Sopenharmony_ci [MT8195_CLK_AUD_MEMIF_DL7] = "aud_memif_dl7", 7762306a36Sopenharmony_ci [MT8195_CLK_AUD_MEMIF_DL8] = "aud_memif_dl8", 7862306a36Sopenharmony_ci [MT8195_CLK_AUD_MEMIF_DL10] = "aud_memif_dl10", 7962306a36Sopenharmony_ci [MT8195_CLK_AUD_MEMIF_DL11] = "aud_memif_dl11", 8062306a36Sopenharmony_ci}; 8162306a36Sopenharmony_ci 8262306a36Sopenharmony_cistruct mt8195_afe_tuner_cfg { 8362306a36Sopenharmony_ci unsigned int id; 8462306a36Sopenharmony_ci int apll_div_reg; 8562306a36Sopenharmony_ci unsigned int apll_div_shift; 8662306a36Sopenharmony_ci unsigned int apll_div_maskbit; 8762306a36Sopenharmony_ci unsigned int apll_div_default; 8862306a36Sopenharmony_ci int ref_ck_sel_reg; 8962306a36Sopenharmony_ci unsigned int ref_ck_sel_shift; 9062306a36Sopenharmony_ci unsigned int ref_ck_sel_maskbit; 9162306a36Sopenharmony_ci unsigned int ref_ck_sel_default; 9262306a36Sopenharmony_ci int tuner_en_reg; 9362306a36Sopenharmony_ci unsigned int tuner_en_shift; 9462306a36Sopenharmony_ci unsigned int tuner_en_maskbit; 9562306a36Sopenharmony_ci int upper_bound_reg; 9662306a36Sopenharmony_ci unsigned int upper_bound_shift; 9762306a36Sopenharmony_ci unsigned int upper_bound_maskbit; 9862306a36Sopenharmony_ci unsigned int upper_bound_default; 9962306a36Sopenharmony_ci spinlock_t ctrl_lock; /* lock for apll tuner ctrl*/ 10062306a36Sopenharmony_ci int ref_cnt; 10162306a36Sopenharmony_ci}; 10262306a36Sopenharmony_ci 10362306a36Sopenharmony_cistatic struct mt8195_afe_tuner_cfg mt8195_afe_tuner_cfgs[MT8195_AUD_PLL_NUM] = { 10462306a36Sopenharmony_ci [MT8195_AUD_PLL1] = { 10562306a36Sopenharmony_ci .id = MT8195_AUD_PLL1, 10662306a36Sopenharmony_ci .apll_div_reg = AFE_APLL_TUNER_CFG, 10762306a36Sopenharmony_ci .apll_div_shift = 4, 10862306a36Sopenharmony_ci .apll_div_maskbit = 0xf, 10962306a36Sopenharmony_ci .apll_div_default = 0x7, 11062306a36Sopenharmony_ci .ref_ck_sel_reg = AFE_APLL_TUNER_CFG, 11162306a36Sopenharmony_ci .ref_ck_sel_shift = 1, 11262306a36Sopenharmony_ci .ref_ck_sel_maskbit = 0x3, 11362306a36Sopenharmony_ci .ref_ck_sel_default = 0x2, 11462306a36Sopenharmony_ci .tuner_en_reg = AFE_APLL_TUNER_CFG, 11562306a36Sopenharmony_ci .tuner_en_shift = 0, 11662306a36Sopenharmony_ci .tuner_en_maskbit = 0x1, 11762306a36Sopenharmony_ci .upper_bound_reg = AFE_APLL_TUNER_CFG, 11862306a36Sopenharmony_ci .upper_bound_shift = 8, 11962306a36Sopenharmony_ci .upper_bound_maskbit = 0xff, 12062306a36Sopenharmony_ci .upper_bound_default = 0x3, 12162306a36Sopenharmony_ci }, 12262306a36Sopenharmony_ci [MT8195_AUD_PLL2] = { 12362306a36Sopenharmony_ci .id = MT8195_AUD_PLL2, 12462306a36Sopenharmony_ci .apll_div_reg = AFE_APLL_TUNER_CFG1, 12562306a36Sopenharmony_ci .apll_div_shift = 4, 12662306a36Sopenharmony_ci .apll_div_maskbit = 0xf, 12762306a36Sopenharmony_ci .apll_div_default = 0x7, 12862306a36Sopenharmony_ci .ref_ck_sel_reg = AFE_APLL_TUNER_CFG1, 12962306a36Sopenharmony_ci .ref_ck_sel_shift = 1, 13062306a36Sopenharmony_ci .ref_ck_sel_maskbit = 0x3, 13162306a36Sopenharmony_ci .ref_ck_sel_default = 0x1, 13262306a36Sopenharmony_ci .tuner_en_reg = AFE_APLL_TUNER_CFG1, 13362306a36Sopenharmony_ci .tuner_en_shift = 0, 13462306a36Sopenharmony_ci .tuner_en_maskbit = 0x1, 13562306a36Sopenharmony_ci .upper_bound_reg = AFE_APLL_TUNER_CFG1, 13662306a36Sopenharmony_ci .upper_bound_shift = 8, 13762306a36Sopenharmony_ci .upper_bound_maskbit = 0xff, 13862306a36Sopenharmony_ci .upper_bound_default = 0x3, 13962306a36Sopenharmony_ci }, 14062306a36Sopenharmony_ci [MT8195_AUD_PLL3] = { 14162306a36Sopenharmony_ci .id = MT8195_AUD_PLL3, 14262306a36Sopenharmony_ci .apll_div_reg = AFE_EARC_APLL_TUNER_CFG, 14362306a36Sopenharmony_ci .apll_div_shift = 4, 14462306a36Sopenharmony_ci .apll_div_maskbit = 0x3f, 14562306a36Sopenharmony_ci .apll_div_default = 0x3, 14662306a36Sopenharmony_ci .ref_ck_sel_reg = AFE_EARC_APLL_TUNER_CFG, 14762306a36Sopenharmony_ci .ref_ck_sel_shift = 24, 14862306a36Sopenharmony_ci .ref_ck_sel_maskbit = 0x3, 14962306a36Sopenharmony_ci .ref_ck_sel_default = 0x0, 15062306a36Sopenharmony_ci .tuner_en_reg = AFE_EARC_APLL_TUNER_CFG, 15162306a36Sopenharmony_ci .tuner_en_shift = 0, 15262306a36Sopenharmony_ci .tuner_en_maskbit = 0x1, 15362306a36Sopenharmony_ci .upper_bound_reg = AFE_EARC_APLL_TUNER_CFG, 15462306a36Sopenharmony_ci .upper_bound_shift = 12, 15562306a36Sopenharmony_ci .upper_bound_maskbit = 0xff, 15662306a36Sopenharmony_ci .upper_bound_default = 0x4, 15762306a36Sopenharmony_ci }, 15862306a36Sopenharmony_ci [MT8195_AUD_PLL4] = { 15962306a36Sopenharmony_ci .id = MT8195_AUD_PLL4, 16062306a36Sopenharmony_ci .apll_div_reg = AFE_SPDIFIN_APLL_TUNER_CFG, 16162306a36Sopenharmony_ci .apll_div_shift = 4, 16262306a36Sopenharmony_ci .apll_div_maskbit = 0x3f, 16362306a36Sopenharmony_ci .apll_div_default = 0x7, 16462306a36Sopenharmony_ci .ref_ck_sel_reg = AFE_SPDIFIN_APLL_TUNER_CFG1, 16562306a36Sopenharmony_ci .ref_ck_sel_shift = 8, 16662306a36Sopenharmony_ci .ref_ck_sel_maskbit = 0x1, 16762306a36Sopenharmony_ci .ref_ck_sel_default = 0, 16862306a36Sopenharmony_ci .tuner_en_reg = AFE_SPDIFIN_APLL_TUNER_CFG, 16962306a36Sopenharmony_ci .tuner_en_shift = 0, 17062306a36Sopenharmony_ci .tuner_en_maskbit = 0x1, 17162306a36Sopenharmony_ci .upper_bound_reg = AFE_SPDIFIN_APLL_TUNER_CFG, 17262306a36Sopenharmony_ci .upper_bound_shift = 12, 17362306a36Sopenharmony_ci .upper_bound_maskbit = 0xff, 17462306a36Sopenharmony_ci .upper_bound_default = 0x4, 17562306a36Sopenharmony_ci }, 17662306a36Sopenharmony_ci [MT8195_AUD_PLL5] = { 17762306a36Sopenharmony_ci .id = MT8195_AUD_PLL5, 17862306a36Sopenharmony_ci .apll_div_reg = AFE_LINEIN_APLL_TUNER_CFG, 17962306a36Sopenharmony_ci .apll_div_shift = 4, 18062306a36Sopenharmony_ci .apll_div_maskbit = 0x3f, 18162306a36Sopenharmony_ci .apll_div_default = 0x3, 18262306a36Sopenharmony_ci .ref_ck_sel_reg = AFE_LINEIN_APLL_TUNER_CFG, 18362306a36Sopenharmony_ci .ref_ck_sel_shift = 24, 18462306a36Sopenharmony_ci .ref_ck_sel_maskbit = 0x1, 18562306a36Sopenharmony_ci .ref_ck_sel_default = 0, 18662306a36Sopenharmony_ci .tuner_en_reg = AFE_LINEIN_APLL_TUNER_CFG, 18762306a36Sopenharmony_ci .tuner_en_shift = 0, 18862306a36Sopenharmony_ci .tuner_en_maskbit = 0x1, 18962306a36Sopenharmony_ci .upper_bound_reg = AFE_LINEIN_APLL_TUNER_CFG, 19062306a36Sopenharmony_ci .upper_bound_shift = 12, 19162306a36Sopenharmony_ci .upper_bound_maskbit = 0xff, 19262306a36Sopenharmony_ci .upper_bound_default = 0x4, 19362306a36Sopenharmony_ci }, 19462306a36Sopenharmony_ci}; 19562306a36Sopenharmony_ci 19662306a36Sopenharmony_cistatic struct mt8195_afe_tuner_cfg *mt8195_afe_found_apll_tuner(unsigned int id) 19762306a36Sopenharmony_ci{ 19862306a36Sopenharmony_ci if (id >= MT8195_AUD_PLL_NUM) 19962306a36Sopenharmony_ci return NULL; 20062306a36Sopenharmony_ci 20162306a36Sopenharmony_ci return &mt8195_afe_tuner_cfgs[id]; 20262306a36Sopenharmony_ci} 20362306a36Sopenharmony_ci 20462306a36Sopenharmony_cistatic int mt8195_afe_init_apll_tuner(unsigned int id) 20562306a36Sopenharmony_ci{ 20662306a36Sopenharmony_ci struct mt8195_afe_tuner_cfg *cfg = mt8195_afe_found_apll_tuner(id); 20762306a36Sopenharmony_ci 20862306a36Sopenharmony_ci if (!cfg) 20962306a36Sopenharmony_ci return -EINVAL; 21062306a36Sopenharmony_ci 21162306a36Sopenharmony_ci cfg->ref_cnt = 0; 21262306a36Sopenharmony_ci spin_lock_init(&cfg->ctrl_lock); 21362306a36Sopenharmony_ci 21462306a36Sopenharmony_ci return 0; 21562306a36Sopenharmony_ci} 21662306a36Sopenharmony_ci 21762306a36Sopenharmony_cistatic int mt8195_afe_setup_apll_tuner(struct mtk_base_afe *afe, 21862306a36Sopenharmony_ci unsigned int id) 21962306a36Sopenharmony_ci{ 22062306a36Sopenharmony_ci const struct mt8195_afe_tuner_cfg *cfg = mt8195_afe_found_apll_tuner(id); 22162306a36Sopenharmony_ci 22262306a36Sopenharmony_ci if (!cfg) 22362306a36Sopenharmony_ci return -EINVAL; 22462306a36Sopenharmony_ci 22562306a36Sopenharmony_ci regmap_update_bits(afe->regmap, cfg->apll_div_reg, 22662306a36Sopenharmony_ci cfg->apll_div_maskbit << cfg->apll_div_shift, 22762306a36Sopenharmony_ci cfg->apll_div_default << cfg->apll_div_shift); 22862306a36Sopenharmony_ci 22962306a36Sopenharmony_ci regmap_update_bits(afe->regmap, cfg->ref_ck_sel_reg, 23062306a36Sopenharmony_ci cfg->ref_ck_sel_maskbit << cfg->ref_ck_sel_shift, 23162306a36Sopenharmony_ci cfg->ref_ck_sel_default << cfg->ref_ck_sel_shift); 23262306a36Sopenharmony_ci 23362306a36Sopenharmony_ci regmap_update_bits(afe->regmap, cfg->upper_bound_reg, 23462306a36Sopenharmony_ci cfg->upper_bound_maskbit << cfg->upper_bound_shift, 23562306a36Sopenharmony_ci cfg->upper_bound_default << cfg->upper_bound_shift); 23662306a36Sopenharmony_ci 23762306a36Sopenharmony_ci return 0; 23862306a36Sopenharmony_ci} 23962306a36Sopenharmony_ci 24062306a36Sopenharmony_cistatic int mt8195_afe_enable_tuner_clk(struct mtk_base_afe *afe, 24162306a36Sopenharmony_ci unsigned int id) 24262306a36Sopenharmony_ci{ 24362306a36Sopenharmony_ci struct mt8195_afe_private *afe_priv = afe->platform_priv; 24462306a36Sopenharmony_ci 24562306a36Sopenharmony_ci switch (id) { 24662306a36Sopenharmony_ci case MT8195_AUD_PLL1: 24762306a36Sopenharmony_ci mt8195_afe_enable_clk(afe, afe_priv->clk[MT8195_CLK_AUD_APLL]); 24862306a36Sopenharmony_ci mt8195_afe_enable_clk(afe, afe_priv->clk[MT8195_CLK_AUD_APLL1_TUNER]); 24962306a36Sopenharmony_ci break; 25062306a36Sopenharmony_ci case MT8195_AUD_PLL2: 25162306a36Sopenharmony_ci mt8195_afe_enable_clk(afe, afe_priv->clk[MT8195_CLK_AUD_APLL2]); 25262306a36Sopenharmony_ci mt8195_afe_enable_clk(afe, afe_priv->clk[MT8195_CLK_AUD_APLL2_TUNER]); 25362306a36Sopenharmony_ci break; 25462306a36Sopenharmony_ci default: 25562306a36Sopenharmony_ci break; 25662306a36Sopenharmony_ci } 25762306a36Sopenharmony_ci 25862306a36Sopenharmony_ci return 0; 25962306a36Sopenharmony_ci} 26062306a36Sopenharmony_ci 26162306a36Sopenharmony_cistatic int mt8195_afe_disable_tuner_clk(struct mtk_base_afe *afe, 26262306a36Sopenharmony_ci unsigned int id) 26362306a36Sopenharmony_ci{ 26462306a36Sopenharmony_ci struct mt8195_afe_private *afe_priv = afe->platform_priv; 26562306a36Sopenharmony_ci 26662306a36Sopenharmony_ci switch (id) { 26762306a36Sopenharmony_ci case MT8195_AUD_PLL1: 26862306a36Sopenharmony_ci mt8195_afe_disable_clk(afe, afe_priv->clk[MT8195_CLK_AUD_APLL1_TUNER]); 26962306a36Sopenharmony_ci mt8195_afe_disable_clk(afe, afe_priv->clk[MT8195_CLK_AUD_APLL]); 27062306a36Sopenharmony_ci break; 27162306a36Sopenharmony_ci case MT8195_AUD_PLL2: 27262306a36Sopenharmony_ci mt8195_afe_disable_clk(afe, afe_priv->clk[MT8195_CLK_AUD_APLL2_TUNER]); 27362306a36Sopenharmony_ci mt8195_afe_disable_clk(afe, afe_priv->clk[MT8195_CLK_AUD_APLL2]); 27462306a36Sopenharmony_ci break; 27562306a36Sopenharmony_ci default: 27662306a36Sopenharmony_ci break; 27762306a36Sopenharmony_ci } 27862306a36Sopenharmony_ci 27962306a36Sopenharmony_ci return 0; 28062306a36Sopenharmony_ci} 28162306a36Sopenharmony_ci 28262306a36Sopenharmony_cistatic int mt8195_afe_enable_apll_tuner(struct mtk_base_afe *afe, 28362306a36Sopenharmony_ci unsigned int id) 28462306a36Sopenharmony_ci{ 28562306a36Sopenharmony_ci struct mt8195_afe_tuner_cfg *cfg = mt8195_afe_found_apll_tuner(id); 28662306a36Sopenharmony_ci unsigned long flags; 28762306a36Sopenharmony_ci int ret; 28862306a36Sopenharmony_ci 28962306a36Sopenharmony_ci if (!cfg) 29062306a36Sopenharmony_ci return -EINVAL; 29162306a36Sopenharmony_ci 29262306a36Sopenharmony_ci ret = mt8195_afe_setup_apll_tuner(afe, id); 29362306a36Sopenharmony_ci if (ret) 29462306a36Sopenharmony_ci return ret; 29562306a36Sopenharmony_ci 29662306a36Sopenharmony_ci ret = mt8195_afe_enable_tuner_clk(afe, id); 29762306a36Sopenharmony_ci if (ret) 29862306a36Sopenharmony_ci return ret; 29962306a36Sopenharmony_ci 30062306a36Sopenharmony_ci spin_lock_irqsave(&cfg->ctrl_lock, flags); 30162306a36Sopenharmony_ci 30262306a36Sopenharmony_ci cfg->ref_cnt++; 30362306a36Sopenharmony_ci if (cfg->ref_cnt == 1) 30462306a36Sopenharmony_ci regmap_update_bits(afe->regmap, 30562306a36Sopenharmony_ci cfg->tuner_en_reg, 30662306a36Sopenharmony_ci cfg->tuner_en_maskbit << cfg->tuner_en_shift, 30762306a36Sopenharmony_ci 1 << cfg->tuner_en_shift); 30862306a36Sopenharmony_ci 30962306a36Sopenharmony_ci spin_unlock_irqrestore(&cfg->ctrl_lock, flags); 31062306a36Sopenharmony_ci 31162306a36Sopenharmony_ci return 0; 31262306a36Sopenharmony_ci} 31362306a36Sopenharmony_ci 31462306a36Sopenharmony_cistatic int mt8195_afe_disable_apll_tuner(struct mtk_base_afe *afe, 31562306a36Sopenharmony_ci unsigned int id) 31662306a36Sopenharmony_ci{ 31762306a36Sopenharmony_ci struct mt8195_afe_tuner_cfg *cfg = mt8195_afe_found_apll_tuner(id); 31862306a36Sopenharmony_ci unsigned long flags; 31962306a36Sopenharmony_ci int ret; 32062306a36Sopenharmony_ci 32162306a36Sopenharmony_ci if (!cfg) 32262306a36Sopenharmony_ci return -EINVAL; 32362306a36Sopenharmony_ci 32462306a36Sopenharmony_ci spin_lock_irqsave(&cfg->ctrl_lock, flags); 32562306a36Sopenharmony_ci 32662306a36Sopenharmony_ci cfg->ref_cnt--; 32762306a36Sopenharmony_ci if (cfg->ref_cnt == 0) 32862306a36Sopenharmony_ci regmap_update_bits(afe->regmap, 32962306a36Sopenharmony_ci cfg->tuner_en_reg, 33062306a36Sopenharmony_ci cfg->tuner_en_maskbit << cfg->tuner_en_shift, 33162306a36Sopenharmony_ci 0 << cfg->tuner_en_shift); 33262306a36Sopenharmony_ci else if (cfg->ref_cnt < 0) 33362306a36Sopenharmony_ci cfg->ref_cnt = 0; 33462306a36Sopenharmony_ci 33562306a36Sopenharmony_ci spin_unlock_irqrestore(&cfg->ctrl_lock, flags); 33662306a36Sopenharmony_ci 33762306a36Sopenharmony_ci ret = mt8195_afe_disable_tuner_clk(afe, id); 33862306a36Sopenharmony_ci if (ret) 33962306a36Sopenharmony_ci return ret; 34062306a36Sopenharmony_ci 34162306a36Sopenharmony_ci return 0; 34262306a36Sopenharmony_ci} 34362306a36Sopenharmony_ci 34462306a36Sopenharmony_ciint mt8195_afe_get_mclk_source_clk_id(int sel) 34562306a36Sopenharmony_ci{ 34662306a36Sopenharmony_ci switch (sel) { 34762306a36Sopenharmony_ci case MT8195_MCK_SEL_26M: 34862306a36Sopenharmony_ci return MT8195_CLK_XTAL_26M; 34962306a36Sopenharmony_ci case MT8195_MCK_SEL_APLL1: 35062306a36Sopenharmony_ci return MT8195_CLK_TOP_APLL1; 35162306a36Sopenharmony_ci case MT8195_MCK_SEL_APLL2: 35262306a36Sopenharmony_ci return MT8195_CLK_TOP_APLL2; 35362306a36Sopenharmony_ci default: 35462306a36Sopenharmony_ci return -EINVAL; 35562306a36Sopenharmony_ci } 35662306a36Sopenharmony_ci} 35762306a36Sopenharmony_ci 35862306a36Sopenharmony_ciint mt8195_afe_get_mclk_source_rate(struct mtk_base_afe *afe, int apll) 35962306a36Sopenharmony_ci{ 36062306a36Sopenharmony_ci struct mt8195_afe_private *afe_priv = afe->platform_priv; 36162306a36Sopenharmony_ci int clk_id = mt8195_afe_get_mclk_source_clk_id(apll); 36262306a36Sopenharmony_ci 36362306a36Sopenharmony_ci if (clk_id < 0) { 36462306a36Sopenharmony_ci dev_dbg(afe->dev, "invalid clk id\n"); 36562306a36Sopenharmony_ci return 0; 36662306a36Sopenharmony_ci } 36762306a36Sopenharmony_ci 36862306a36Sopenharmony_ci return clk_get_rate(afe_priv->clk[clk_id]); 36962306a36Sopenharmony_ci} 37062306a36Sopenharmony_ci 37162306a36Sopenharmony_ciint mt8195_afe_get_default_mclk_source_by_rate(int rate) 37262306a36Sopenharmony_ci{ 37362306a36Sopenharmony_ci return ((rate % 8000) == 0) ? 37462306a36Sopenharmony_ci MT8195_MCK_SEL_APLL1 : MT8195_MCK_SEL_APLL2; 37562306a36Sopenharmony_ci} 37662306a36Sopenharmony_ci 37762306a36Sopenharmony_ciint mt8195_afe_init_clock(struct mtk_base_afe *afe) 37862306a36Sopenharmony_ci{ 37962306a36Sopenharmony_ci struct mt8195_afe_private *afe_priv = afe->platform_priv; 38062306a36Sopenharmony_ci int i, ret; 38162306a36Sopenharmony_ci 38262306a36Sopenharmony_ci mt8195_audsys_clk_register(afe); 38362306a36Sopenharmony_ci 38462306a36Sopenharmony_ci afe_priv->clk = 38562306a36Sopenharmony_ci devm_kcalloc(afe->dev, MT8195_CLK_NUM, sizeof(*afe_priv->clk), 38662306a36Sopenharmony_ci GFP_KERNEL); 38762306a36Sopenharmony_ci if (!afe_priv->clk) 38862306a36Sopenharmony_ci return -ENOMEM; 38962306a36Sopenharmony_ci 39062306a36Sopenharmony_ci for (i = 0; i < MT8195_CLK_NUM; i++) { 39162306a36Sopenharmony_ci afe_priv->clk[i] = devm_clk_get(afe->dev, aud_clks[i]); 39262306a36Sopenharmony_ci if (IS_ERR(afe_priv->clk[i])) { 39362306a36Sopenharmony_ci dev_dbg(afe->dev, "%s(), devm_clk_get %s fail, ret %ld\n", 39462306a36Sopenharmony_ci __func__, aud_clks[i], 39562306a36Sopenharmony_ci PTR_ERR(afe_priv->clk[i])); 39662306a36Sopenharmony_ci return PTR_ERR(afe_priv->clk[i]); 39762306a36Sopenharmony_ci } 39862306a36Sopenharmony_ci } 39962306a36Sopenharmony_ci 40062306a36Sopenharmony_ci /* initial tuner */ 40162306a36Sopenharmony_ci for (i = 0; i < MT8195_AUD_PLL_NUM; i++) { 40262306a36Sopenharmony_ci ret = mt8195_afe_init_apll_tuner(i); 40362306a36Sopenharmony_ci if (ret) { 40462306a36Sopenharmony_ci dev_dbg(afe->dev, "%s(), init apll_tuner%d failed", 40562306a36Sopenharmony_ci __func__, (i + 1)); 40662306a36Sopenharmony_ci return -EINVAL; 40762306a36Sopenharmony_ci } 40862306a36Sopenharmony_ci } 40962306a36Sopenharmony_ci 41062306a36Sopenharmony_ci return 0; 41162306a36Sopenharmony_ci} 41262306a36Sopenharmony_ci 41362306a36Sopenharmony_ciint mt8195_afe_enable_clk(struct mtk_base_afe *afe, struct clk *clk) 41462306a36Sopenharmony_ci{ 41562306a36Sopenharmony_ci int ret; 41662306a36Sopenharmony_ci 41762306a36Sopenharmony_ci if (clk) { 41862306a36Sopenharmony_ci ret = clk_prepare_enable(clk); 41962306a36Sopenharmony_ci if (ret) { 42062306a36Sopenharmony_ci dev_dbg(afe->dev, "%s(), failed to enable clk\n", 42162306a36Sopenharmony_ci __func__); 42262306a36Sopenharmony_ci return ret; 42362306a36Sopenharmony_ci } 42462306a36Sopenharmony_ci } else { 42562306a36Sopenharmony_ci dev_dbg(afe->dev, "NULL clk\n"); 42662306a36Sopenharmony_ci } 42762306a36Sopenharmony_ci return 0; 42862306a36Sopenharmony_ci} 42962306a36Sopenharmony_ciEXPORT_SYMBOL_GPL(mt8195_afe_enable_clk); 43062306a36Sopenharmony_ci 43162306a36Sopenharmony_civoid mt8195_afe_disable_clk(struct mtk_base_afe *afe, struct clk *clk) 43262306a36Sopenharmony_ci{ 43362306a36Sopenharmony_ci if (clk) 43462306a36Sopenharmony_ci clk_disable_unprepare(clk); 43562306a36Sopenharmony_ci else 43662306a36Sopenharmony_ci dev_dbg(afe->dev, "NULL clk\n"); 43762306a36Sopenharmony_ci} 43862306a36Sopenharmony_ciEXPORT_SYMBOL_GPL(mt8195_afe_disable_clk); 43962306a36Sopenharmony_ci 44062306a36Sopenharmony_ciint mt8195_afe_prepare_clk(struct mtk_base_afe *afe, struct clk *clk) 44162306a36Sopenharmony_ci{ 44262306a36Sopenharmony_ci int ret; 44362306a36Sopenharmony_ci 44462306a36Sopenharmony_ci if (clk) { 44562306a36Sopenharmony_ci ret = clk_prepare(clk); 44662306a36Sopenharmony_ci if (ret) { 44762306a36Sopenharmony_ci dev_dbg(afe->dev, "%s(), failed to prepare clk\n", 44862306a36Sopenharmony_ci __func__); 44962306a36Sopenharmony_ci return ret; 45062306a36Sopenharmony_ci } 45162306a36Sopenharmony_ci } else { 45262306a36Sopenharmony_ci dev_dbg(afe->dev, "NULL clk\n"); 45362306a36Sopenharmony_ci } 45462306a36Sopenharmony_ci return 0; 45562306a36Sopenharmony_ci} 45662306a36Sopenharmony_ci 45762306a36Sopenharmony_civoid mt8195_afe_unprepare_clk(struct mtk_base_afe *afe, struct clk *clk) 45862306a36Sopenharmony_ci{ 45962306a36Sopenharmony_ci if (clk) 46062306a36Sopenharmony_ci clk_unprepare(clk); 46162306a36Sopenharmony_ci else 46262306a36Sopenharmony_ci dev_dbg(afe->dev, "NULL clk\n"); 46362306a36Sopenharmony_ci} 46462306a36Sopenharmony_ci 46562306a36Sopenharmony_ciint mt8195_afe_enable_clk_atomic(struct mtk_base_afe *afe, struct clk *clk) 46662306a36Sopenharmony_ci{ 46762306a36Sopenharmony_ci int ret; 46862306a36Sopenharmony_ci 46962306a36Sopenharmony_ci if (clk) { 47062306a36Sopenharmony_ci ret = clk_enable(clk); 47162306a36Sopenharmony_ci if (ret) { 47262306a36Sopenharmony_ci dev_dbg(afe->dev, "%s(), failed to clk enable\n", 47362306a36Sopenharmony_ci __func__); 47462306a36Sopenharmony_ci return ret; 47562306a36Sopenharmony_ci } 47662306a36Sopenharmony_ci } else { 47762306a36Sopenharmony_ci dev_dbg(afe->dev, "NULL clk\n"); 47862306a36Sopenharmony_ci } 47962306a36Sopenharmony_ci return 0; 48062306a36Sopenharmony_ci} 48162306a36Sopenharmony_ci 48262306a36Sopenharmony_civoid mt8195_afe_disable_clk_atomic(struct mtk_base_afe *afe, struct clk *clk) 48362306a36Sopenharmony_ci{ 48462306a36Sopenharmony_ci if (clk) 48562306a36Sopenharmony_ci clk_disable(clk); 48662306a36Sopenharmony_ci else 48762306a36Sopenharmony_ci dev_dbg(afe->dev, "NULL clk\n"); 48862306a36Sopenharmony_ci} 48962306a36Sopenharmony_ci 49062306a36Sopenharmony_ciint mt8195_afe_set_clk_rate(struct mtk_base_afe *afe, struct clk *clk, 49162306a36Sopenharmony_ci unsigned int rate) 49262306a36Sopenharmony_ci{ 49362306a36Sopenharmony_ci int ret; 49462306a36Sopenharmony_ci 49562306a36Sopenharmony_ci if (clk) { 49662306a36Sopenharmony_ci ret = clk_set_rate(clk, rate); 49762306a36Sopenharmony_ci if (ret) { 49862306a36Sopenharmony_ci dev_dbg(afe->dev, "%s(), failed to set clk rate\n", 49962306a36Sopenharmony_ci __func__); 50062306a36Sopenharmony_ci return ret; 50162306a36Sopenharmony_ci } 50262306a36Sopenharmony_ci } 50362306a36Sopenharmony_ci 50462306a36Sopenharmony_ci return 0; 50562306a36Sopenharmony_ci} 50662306a36Sopenharmony_ci 50762306a36Sopenharmony_ciint mt8195_afe_set_clk_parent(struct mtk_base_afe *afe, struct clk *clk, 50862306a36Sopenharmony_ci struct clk *parent) 50962306a36Sopenharmony_ci{ 51062306a36Sopenharmony_ci int ret; 51162306a36Sopenharmony_ci 51262306a36Sopenharmony_ci if (clk && parent) { 51362306a36Sopenharmony_ci ret = clk_set_parent(clk, parent); 51462306a36Sopenharmony_ci if (ret) { 51562306a36Sopenharmony_ci dev_dbg(afe->dev, "%s(), failed to set clk parent\n", 51662306a36Sopenharmony_ci __func__); 51762306a36Sopenharmony_ci return ret; 51862306a36Sopenharmony_ci } 51962306a36Sopenharmony_ci } 52062306a36Sopenharmony_ci 52162306a36Sopenharmony_ci return 0; 52262306a36Sopenharmony_ci} 52362306a36Sopenharmony_ci 52462306a36Sopenharmony_cistatic unsigned int get_top_cg_reg(unsigned int cg_type) 52562306a36Sopenharmony_ci{ 52662306a36Sopenharmony_ci switch (cg_type) { 52762306a36Sopenharmony_ci case MT8195_TOP_CG_A1SYS_TIMING: 52862306a36Sopenharmony_ci case MT8195_TOP_CG_A2SYS_TIMING: 52962306a36Sopenharmony_ci case MT8195_TOP_CG_26M_TIMING: 53062306a36Sopenharmony_ci return ASYS_TOP_CON; 53162306a36Sopenharmony_ci default: 53262306a36Sopenharmony_ci return 0; 53362306a36Sopenharmony_ci } 53462306a36Sopenharmony_ci} 53562306a36Sopenharmony_ci 53662306a36Sopenharmony_cistatic unsigned int get_top_cg_mask(unsigned int cg_type) 53762306a36Sopenharmony_ci{ 53862306a36Sopenharmony_ci switch (cg_type) { 53962306a36Sopenharmony_ci case MT8195_TOP_CG_A1SYS_TIMING: 54062306a36Sopenharmony_ci return ASYS_TOP_CON_A1SYS_TIMING_ON; 54162306a36Sopenharmony_ci case MT8195_TOP_CG_A2SYS_TIMING: 54262306a36Sopenharmony_ci return ASYS_TOP_CON_A2SYS_TIMING_ON; 54362306a36Sopenharmony_ci case MT8195_TOP_CG_26M_TIMING: 54462306a36Sopenharmony_ci return ASYS_TOP_CON_26M_TIMING_ON; 54562306a36Sopenharmony_ci default: 54662306a36Sopenharmony_ci return 0; 54762306a36Sopenharmony_ci } 54862306a36Sopenharmony_ci} 54962306a36Sopenharmony_ci 55062306a36Sopenharmony_cistatic unsigned int get_top_cg_on_val(unsigned int cg_type) 55162306a36Sopenharmony_ci{ 55262306a36Sopenharmony_ci switch (cg_type) { 55362306a36Sopenharmony_ci case MT8195_TOP_CG_A1SYS_TIMING: 55462306a36Sopenharmony_ci case MT8195_TOP_CG_A2SYS_TIMING: 55562306a36Sopenharmony_ci case MT8195_TOP_CG_26M_TIMING: 55662306a36Sopenharmony_ci return get_top_cg_mask(cg_type); 55762306a36Sopenharmony_ci default: 55862306a36Sopenharmony_ci return 0; 55962306a36Sopenharmony_ci } 56062306a36Sopenharmony_ci} 56162306a36Sopenharmony_ci 56262306a36Sopenharmony_cistatic unsigned int get_top_cg_off_val(unsigned int cg_type) 56362306a36Sopenharmony_ci{ 56462306a36Sopenharmony_ci switch (cg_type) { 56562306a36Sopenharmony_ci case MT8195_TOP_CG_A1SYS_TIMING: 56662306a36Sopenharmony_ci case MT8195_TOP_CG_A2SYS_TIMING: 56762306a36Sopenharmony_ci case MT8195_TOP_CG_26M_TIMING: 56862306a36Sopenharmony_ci return 0; 56962306a36Sopenharmony_ci default: 57062306a36Sopenharmony_ci return get_top_cg_mask(cg_type); 57162306a36Sopenharmony_ci } 57262306a36Sopenharmony_ci} 57362306a36Sopenharmony_ci 57462306a36Sopenharmony_cistatic int mt8195_afe_enable_top_cg(struct mtk_base_afe *afe, unsigned int cg_type) 57562306a36Sopenharmony_ci{ 57662306a36Sopenharmony_ci unsigned int reg = get_top_cg_reg(cg_type); 57762306a36Sopenharmony_ci unsigned int mask = get_top_cg_mask(cg_type); 57862306a36Sopenharmony_ci unsigned int val = get_top_cg_on_val(cg_type); 57962306a36Sopenharmony_ci 58062306a36Sopenharmony_ci regmap_update_bits(afe->regmap, reg, mask, val); 58162306a36Sopenharmony_ci return 0; 58262306a36Sopenharmony_ci} 58362306a36Sopenharmony_ci 58462306a36Sopenharmony_cistatic int mt8195_afe_disable_top_cg(struct mtk_base_afe *afe, unsigned int cg_type) 58562306a36Sopenharmony_ci{ 58662306a36Sopenharmony_ci unsigned int reg = get_top_cg_reg(cg_type); 58762306a36Sopenharmony_ci unsigned int mask = get_top_cg_mask(cg_type); 58862306a36Sopenharmony_ci unsigned int val = get_top_cg_off_val(cg_type); 58962306a36Sopenharmony_ci 59062306a36Sopenharmony_ci regmap_update_bits(afe->regmap, reg, mask, val); 59162306a36Sopenharmony_ci return 0; 59262306a36Sopenharmony_ci} 59362306a36Sopenharmony_ci 59462306a36Sopenharmony_ciint mt8195_afe_enable_reg_rw_clk(struct mtk_base_afe *afe) 59562306a36Sopenharmony_ci{ 59662306a36Sopenharmony_ci struct mt8195_afe_private *afe_priv = afe->platform_priv; 59762306a36Sopenharmony_ci int i; 59862306a36Sopenharmony_ci static const unsigned int clk_array[] = { 59962306a36Sopenharmony_ci MT8195_CLK_SCP_ADSP_AUDIODSP, /* bus clock for infra */ 60062306a36Sopenharmony_ci MT8195_CLK_TOP_AUDIO_H_SEL, /* clock for ADSP bus */ 60162306a36Sopenharmony_ci MT8195_CLK_TOP_AUDIO_LOCAL_BUS_SEL, /* bus clock for DRAM access */ 60262306a36Sopenharmony_ci MT8195_CLK_TOP_AUD_INTBUS_SEL, /* bus clock for AFE SRAM access */ 60362306a36Sopenharmony_ci MT8195_CLK_INFRA_AO_AUDIO_26M_B, /* audio 26M clock */ 60462306a36Sopenharmony_ci MT8195_CLK_AUD_AFE, /* AFE HW master switch */ 60562306a36Sopenharmony_ci MT8195_CLK_AUD_A1SYS_HP, /* AFE HW clock*/ 60662306a36Sopenharmony_ci MT8195_CLK_AUD_A1SYS, /* AFE HW clock */ 60762306a36Sopenharmony_ci }; 60862306a36Sopenharmony_ci 60962306a36Sopenharmony_ci for (i = 0; i < ARRAY_SIZE(clk_array); i++) 61062306a36Sopenharmony_ci mt8195_afe_enable_clk(afe, afe_priv->clk[clk_array[i]]); 61162306a36Sopenharmony_ci 61262306a36Sopenharmony_ci return 0; 61362306a36Sopenharmony_ci} 61462306a36Sopenharmony_ci 61562306a36Sopenharmony_ciint mt8195_afe_disable_reg_rw_clk(struct mtk_base_afe *afe) 61662306a36Sopenharmony_ci{ 61762306a36Sopenharmony_ci struct mt8195_afe_private *afe_priv = afe->platform_priv; 61862306a36Sopenharmony_ci int i; 61962306a36Sopenharmony_ci static const unsigned int clk_array[] = { 62062306a36Sopenharmony_ci MT8195_CLK_AUD_A1SYS, 62162306a36Sopenharmony_ci MT8195_CLK_AUD_A1SYS_HP, 62262306a36Sopenharmony_ci MT8195_CLK_AUD_AFE, 62362306a36Sopenharmony_ci MT8195_CLK_INFRA_AO_AUDIO_26M_B, 62462306a36Sopenharmony_ci MT8195_CLK_TOP_AUD_INTBUS_SEL, 62562306a36Sopenharmony_ci MT8195_CLK_TOP_AUDIO_LOCAL_BUS_SEL, 62662306a36Sopenharmony_ci MT8195_CLK_TOP_AUDIO_H_SEL, 62762306a36Sopenharmony_ci MT8195_CLK_SCP_ADSP_AUDIODSP, 62862306a36Sopenharmony_ci }; 62962306a36Sopenharmony_ci 63062306a36Sopenharmony_ci for (i = 0; i < ARRAY_SIZE(clk_array); i++) 63162306a36Sopenharmony_ci mt8195_afe_disable_clk(afe, afe_priv->clk[clk_array[i]]); 63262306a36Sopenharmony_ci 63362306a36Sopenharmony_ci return 0; 63462306a36Sopenharmony_ci} 63562306a36Sopenharmony_ci 63662306a36Sopenharmony_cistatic int mt8195_afe_enable_afe_on(struct mtk_base_afe *afe) 63762306a36Sopenharmony_ci{ 63862306a36Sopenharmony_ci regmap_update_bits(afe->regmap, AFE_DAC_CON0, 0x1, 0x1); 63962306a36Sopenharmony_ci return 0; 64062306a36Sopenharmony_ci} 64162306a36Sopenharmony_ci 64262306a36Sopenharmony_cistatic int mt8195_afe_disable_afe_on(struct mtk_base_afe *afe) 64362306a36Sopenharmony_ci{ 64462306a36Sopenharmony_ci regmap_update_bits(afe->regmap, AFE_DAC_CON0, 0x1, 0x0); 64562306a36Sopenharmony_ci return 0; 64662306a36Sopenharmony_ci} 64762306a36Sopenharmony_ci 64862306a36Sopenharmony_cistatic int mt8195_afe_enable_timing_sys(struct mtk_base_afe *afe) 64962306a36Sopenharmony_ci{ 65062306a36Sopenharmony_ci struct mt8195_afe_private *afe_priv = afe->platform_priv; 65162306a36Sopenharmony_ci int i; 65262306a36Sopenharmony_ci static const unsigned int clk_array[] = { 65362306a36Sopenharmony_ci MT8195_CLK_AUD_A1SYS, 65462306a36Sopenharmony_ci MT8195_CLK_AUD_A2SYS, 65562306a36Sopenharmony_ci }; 65662306a36Sopenharmony_ci static const unsigned int cg_array[] = { 65762306a36Sopenharmony_ci MT8195_TOP_CG_A1SYS_TIMING, 65862306a36Sopenharmony_ci MT8195_TOP_CG_A2SYS_TIMING, 65962306a36Sopenharmony_ci MT8195_TOP_CG_26M_TIMING, 66062306a36Sopenharmony_ci }; 66162306a36Sopenharmony_ci 66262306a36Sopenharmony_ci for (i = 0; i < ARRAY_SIZE(clk_array); i++) 66362306a36Sopenharmony_ci mt8195_afe_enable_clk(afe, afe_priv->clk[clk_array[i]]); 66462306a36Sopenharmony_ci 66562306a36Sopenharmony_ci for (i = 0; i < ARRAY_SIZE(cg_array); i++) 66662306a36Sopenharmony_ci mt8195_afe_enable_top_cg(afe, cg_array[i]); 66762306a36Sopenharmony_ci 66862306a36Sopenharmony_ci return 0; 66962306a36Sopenharmony_ci} 67062306a36Sopenharmony_ci 67162306a36Sopenharmony_cistatic int mt8195_afe_disable_timing_sys(struct mtk_base_afe *afe) 67262306a36Sopenharmony_ci{ 67362306a36Sopenharmony_ci struct mt8195_afe_private *afe_priv = afe->platform_priv; 67462306a36Sopenharmony_ci int i; 67562306a36Sopenharmony_ci static const unsigned int clk_array[] = { 67662306a36Sopenharmony_ci MT8195_CLK_AUD_A2SYS, 67762306a36Sopenharmony_ci MT8195_CLK_AUD_A1SYS, 67862306a36Sopenharmony_ci }; 67962306a36Sopenharmony_ci static const unsigned int cg_array[] = { 68062306a36Sopenharmony_ci MT8195_TOP_CG_26M_TIMING, 68162306a36Sopenharmony_ci MT8195_TOP_CG_A2SYS_TIMING, 68262306a36Sopenharmony_ci MT8195_TOP_CG_A1SYS_TIMING, 68362306a36Sopenharmony_ci }; 68462306a36Sopenharmony_ci 68562306a36Sopenharmony_ci for (i = 0; i < ARRAY_SIZE(cg_array); i++) 68662306a36Sopenharmony_ci mt8195_afe_disable_top_cg(afe, cg_array[i]); 68762306a36Sopenharmony_ci 68862306a36Sopenharmony_ci for (i = 0; i < ARRAY_SIZE(clk_array); i++) 68962306a36Sopenharmony_ci mt8195_afe_disable_clk(afe, afe_priv->clk[clk_array[i]]); 69062306a36Sopenharmony_ci 69162306a36Sopenharmony_ci return 0; 69262306a36Sopenharmony_ci} 69362306a36Sopenharmony_ci 69462306a36Sopenharmony_ciint mt8195_afe_enable_main_clock(struct mtk_base_afe *afe) 69562306a36Sopenharmony_ci{ 69662306a36Sopenharmony_ci mt8195_afe_enable_timing_sys(afe); 69762306a36Sopenharmony_ci 69862306a36Sopenharmony_ci mt8195_afe_enable_afe_on(afe); 69962306a36Sopenharmony_ci 70062306a36Sopenharmony_ci mt8195_afe_enable_apll_tuner(afe, MT8195_AUD_PLL1); 70162306a36Sopenharmony_ci mt8195_afe_enable_apll_tuner(afe, MT8195_AUD_PLL2); 70262306a36Sopenharmony_ci 70362306a36Sopenharmony_ci return 0; 70462306a36Sopenharmony_ci} 70562306a36Sopenharmony_ci 70662306a36Sopenharmony_ciint mt8195_afe_disable_main_clock(struct mtk_base_afe *afe) 70762306a36Sopenharmony_ci{ 70862306a36Sopenharmony_ci mt8195_afe_disable_apll_tuner(afe, MT8195_AUD_PLL2); 70962306a36Sopenharmony_ci mt8195_afe_disable_apll_tuner(afe, MT8195_AUD_PLL1); 71062306a36Sopenharmony_ci 71162306a36Sopenharmony_ci mt8195_afe_disable_afe_on(afe); 71262306a36Sopenharmony_ci 71362306a36Sopenharmony_ci mt8195_afe_disable_timing_sys(afe); 71462306a36Sopenharmony_ci 71562306a36Sopenharmony_ci return 0; 71662306a36Sopenharmony_ci} 717