18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0 28c2ecf20Sopenharmony_ci// 38c2ecf20Sopenharmony_ci// mt8183-afe-clk.c -- Mediatek 8183 afe clock ctrl 48c2ecf20Sopenharmony_ci// 58c2ecf20Sopenharmony_ci// Copyright (c) 2018 MediaTek Inc. 68c2ecf20Sopenharmony_ci// Author: KaiChieh Chuang <kaichieh.chuang@mediatek.com> 78c2ecf20Sopenharmony_ci 88c2ecf20Sopenharmony_ci#include <linux/clk.h> 98c2ecf20Sopenharmony_ci 108c2ecf20Sopenharmony_ci#include "mt8183-afe-common.h" 118c2ecf20Sopenharmony_ci#include "mt8183-afe-clk.h" 128c2ecf20Sopenharmony_ci#include "mt8183-reg.h" 138c2ecf20Sopenharmony_ci 148c2ecf20Sopenharmony_cienum { 158c2ecf20Sopenharmony_ci CLK_AFE = 0, 168c2ecf20Sopenharmony_ci CLK_TML, 178c2ecf20Sopenharmony_ci CLK_APLL22M, 188c2ecf20Sopenharmony_ci CLK_APLL24M, 198c2ecf20Sopenharmony_ci CLK_APLL1_TUNER, 208c2ecf20Sopenharmony_ci CLK_APLL2_TUNER, 218c2ecf20Sopenharmony_ci CLK_I2S1_BCLK_SW, 228c2ecf20Sopenharmony_ci CLK_I2S2_BCLK_SW, 238c2ecf20Sopenharmony_ci CLK_I2S3_BCLK_SW, 248c2ecf20Sopenharmony_ci CLK_I2S4_BCLK_SW, 258c2ecf20Sopenharmony_ci CLK_INFRA_SYS_AUDIO, 268c2ecf20Sopenharmony_ci CLK_MUX_AUDIO, 278c2ecf20Sopenharmony_ci CLK_MUX_AUDIOINTBUS, 288c2ecf20Sopenharmony_ci CLK_TOP_SYSPLL_D2_D4, 298c2ecf20Sopenharmony_ci /* apll related mux */ 308c2ecf20Sopenharmony_ci CLK_TOP_MUX_AUD_1, 318c2ecf20Sopenharmony_ci CLK_TOP_APLL1_CK, 328c2ecf20Sopenharmony_ci CLK_TOP_MUX_AUD_2, 338c2ecf20Sopenharmony_ci CLK_TOP_APLL2_CK, 348c2ecf20Sopenharmony_ci CLK_TOP_MUX_AUD_ENG1, 358c2ecf20Sopenharmony_ci CLK_TOP_APLL1_D8, 368c2ecf20Sopenharmony_ci CLK_TOP_MUX_AUD_ENG2, 378c2ecf20Sopenharmony_ci CLK_TOP_APLL2_D8, 388c2ecf20Sopenharmony_ci CLK_TOP_I2S0_M_SEL, 398c2ecf20Sopenharmony_ci CLK_TOP_I2S1_M_SEL, 408c2ecf20Sopenharmony_ci CLK_TOP_I2S2_M_SEL, 418c2ecf20Sopenharmony_ci CLK_TOP_I2S3_M_SEL, 428c2ecf20Sopenharmony_ci CLK_TOP_I2S4_M_SEL, 438c2ecf20Sopenharmony_ci CLK_TOP_I2S5_M_SEL, 448c2ecf20Sopenharmony_ci CLK_TOP_APLL12_DIV0, 458c2ecf20Sopenharmony_ci CLK_TOP_APLL12_DIV1, 468c2ecf20Sopenharmony_ci CLK_TOP_APLL12_DIV2, 478c2ecf20Sopenharmony_ci CLK_TOP_APLL12_DIV3, 488c2ecf20Sopenharmony_ci CLK_TOP_APLL12_DIV4, 498c2ecf20Sopenharmony_ci CLK_TOP_APLL12_DIVB, 508c2ecf20Sopenharmony_ci CLK_CLK26M, 518c2ecf20Sopenharmony_ci CLK_NUM 528c2ecf20Sopenharmony_ci}; 538c2ecf20Sopenharmony_ci 548c2ecf20Sopenharmony_cistatic const char *aud_clks[CLK_NUM] = { 558c2ecf20Sopenharmony_ci [CLK_AFE] = "aud_afe_clk", 568c2ecf20Sopenharmony_ci [CLK_TML] = "aud_tml_clk", 578c2ecf20Sopenharmony_ci [CLK_APLL22M] = "aud_apll22m_clk", 588c2ecf20Sopenharmony_ci [CLK_APLL24M] = "aud_apll24m_clk", 598c2ecf20Sopenharmony_ci [CLK_APLL1_TUNER] = "aud_apll1_tuner_clk", 608c2ecf20Sopenharmony_ci [CLK_APLL2_TUNER] = "aud_apll2_tuner_clk", 618c2ecf20Sopenharmony_ci [CLK_I2S1_BCLK_SW] = "aud_i2s1_bclk_sw", 628c2ecf20Sopenharmony_ci [CLK_I2S2_BCLK_SW] = "aud_i2s2_bclk_sw", 638c2ecf20Sopenharmony_ci [CLK_I2S3_BCLK_SW] = "aud_i2s3_bclk_sw", 648c2ecf20Sopenharmony_ci [CLK_I2S4_BCLK_SW] = "aud_i2s4_bclk_sw", 658c2ecf20Sopenharmony_ci [CLK_INFRA_SYS_AUDIO] = "aud_infra_clk", 668c2ecf20Sopenharmony_ci [CLK_MUX_AUDIO] = "top_mux_audio", 678c2ecf20Sopenharmony_ci [CLK_MUX_AUDIOINTBUS] = "top_mux_aud_intbus", 688c2ecf20Sopenharmony_ci [CLK_TOP_SYSPLL_D2_D4] = "top_syspll_d2_d4", 698c2ecf20Sopenharmony_ci [CLK_TOP_MUX_AUD_1] = "top_mux_aud_1", 708c2ecf20Sopenharmony_ci [CLK_TOP_APLL1_CK] = "top_apll1_ck", 718c2ecf20Sopenharmony_ci [CLK_TOP_MUX_AUD_2] = "top_mux_aud_2", 728c2ecf20Sopenharmony_ci [CLK_TOP_APLL2_CK] = "top_apll2_ck", 738c2ecf20Sopenharmony_ci [CLK_TOP_MUX_AUD_ENG1] = "top_mux_aud_eng1", 748c2ecf20Sopenharmony_ci [CLK_TOP_APLL1_D8] = "top_apll1_d8", 758c2ecf20Sopenharmony_ci [CLK_TOP_MUX_AUD_ENG2] = "top_mux_aud_eng2", 768c2ecf20Sopenharmony_ci [CLK_TOP_APLL2_D8] = "top_apll2_d8", 778c2ecf20Sopenharmony_ci [CLK_TOP_I2S0_M_SEL] = "top_i2s0_m_sel", 788c2ecf20Sopenharmony_ci [CLK_TOP_I2S1_M_SEL] = "top_i2s1_m_sel", 798c2ecf20Sopenharmony_ci [CLK_TOP_I2S2_M_SEL] = "top_i2s2_m_sel", 808c2ecf20Sopenharmony_ci [CLK_TOP_I2S3_M_SEL] = "top_i2s3_m_sel", 818c2ecf20Sopenharmony_ci [CLK_TOP_I2S4_M_SEL] = "top_i2s4_m_sel", 828c2ecf20Sopenharmony_ci [CLK_TOP_I2S5_M_SEL] = "top_i2s5_m_sel", 838c2ecf20Sopenharmony_ci [CLK_TOP_APLL12_DIV0] = "top_apll12_div0", 848c2ecf20Sopenharmony_ci [CLK_TOP_APLL12_DIV1] = "top_apll12_div1", 858c2ecf20Sopenharmony_ci [CLK_TOP_APLL12_DIV2] = "top_apll12_div2", 868c2ecf20Sopenharmony_ci [CLK_TOP_APLL12_DIV3] = "top_apll12_div3", 878c2ecf20Sopenharmony_ci [CLK_TOP_APLL12_DIV4] = "top_apll12_div4", 888c2ecf20Sopenharmony_ci [CLK_TOP_APLL12_DIVB] = "top_apll12_divb", 898c2ecf20Sopenharmony_ci [CLK_CLK26M] = "top_clk26m_clk", 908c2ecf20Sopenharmony_ci}; 918c2ecf20Sopenharmony_ci 928c2ecf20Sopenharmony_ciint mt8183_init_clock(struct mtk_base_afe *afe) 938c2ecf20Sopenharmony_ci{ 948c2ecf20Sopenharmony_ci struct mt8183_afe_private *afe_priv = afe->platform_priv; 958c2ecf20Sopenharmony_ci int i; 968c2ecf20Sopenharmony_ci 978c2ecf20Sopenharmony_ci afe_priv->clk = devm_kcalloc(afe->dev, CLK_NUM, sizeof(*afe_priv->clk), 988c2ecf20Sopenharmony_ci GFP_KERNEL); 998c2ecf20Sopenharmony_ci if (!afe_priv->clk) 1008c2ecf20Sopenharmony_ci return -ENOMEM; 1018c2ecf20Sopenharmony_ci 1028c2ecf20Sopenharmony_ci for (i = 0; i < CLK_NUM; i++) { 1038c2ecf20Sopenharmony_ci afe_priv->clk[i] = devm_clk_get(afe->dev, aud_clks[i]); 1048c2ecf20Sopenharmony_ci if (IS_ERR(afe_priv->clk[i])) { 1058c2ecf20Sopenharmony_ci dev_err(afe->dev, "%s(), devm_clk_get %s fail, ret %ld\n", 1068c2ecf20Sopenharmony_ci __func__, aud_clks[i], 1078c2ecf20Sopenharmony_ci PTR_ERR(afe_priv->clk[i])); 1088c2ecf20Sopenharmony_ci return PTR_ERR(afe_priv->clk[i]); 1098c2ecf20Sopenharmony_ci } 1108c2ecf20Sopenharmony_ci } 1118c2ecf20Sopenharmony_ci 1128c2ecf20Sopenharmony_ci return 0; 1138c2ecf20Sopenharmony_ci} 1148c2ecf20Sopenharmony_ci 1158c2ecf20Sopenharmony_ciint mt8183_afe_enable_clock(struct mtk_base_afe *afe) 1168c2ecf20Sopenharmony_ci{ 1178c2ecf20Sopenharmony_ci struct mt8183_afe_private *afe_priv = afe->platform_priv; 1188c2ecf20Sopenharmony_ci int ret; 1198c2ecf20Sopenharmony_ci 1208c2ecf20Sopenharmony_ci ret = clk_prepare_enable(afe_priv->clk[CLK_INFRA_SYS_AUDIO]); 1218c2ecf20Sopenharmony_ci if (ret) { 1228c2ecf20Sopenharmony_ci dev_err(afe->dev, "%s(), clk_prepare_enable %s fail %d\n", 1238c2ecf20Sopenharmony_ci __func__, aud_clks[CLK_INFRA_SYS_AUDIO], ret); 1248c2ecf20Sopenharmony_ci goto CLK_INFRA_SYS_AUDIO_ERR; 1258c2ecf20Sopenharmony_ci } 1268c2ecf20Sopenharmony_ci 1278c2ecf20Sopenharmony_ci ret = clk_prepare_enable(afe_priv->clk[CLK_MUX_AUDIO]); 1288c2ecf20Sopenharmony_ci if (ret) { 1298c2ecf20Sopenharmony_ci dev_err(afe->dev, "%s(), clk_prepare_enable %s fail %d\n", 1308c2ecf20Sopenharmony_ci __func__, aud_clks[CLK_MUX_AUDIO], ret); 1318c2ecf20Sopenharmony_ci goto CLK_MUX_AUDIO_ERR; 1328c2ecf20Sopenharmony_ci } 1338c2ecf20Sopenharmony_ci 1348c2ecf20Sopenharmony_ci ret = clk_set_parent(afe_priv->clk[CLK_MUX_AUDIO], 1358c2ecf20Sopenharmony_ci afe_priv->clk[CLK_CLK26M]); 1368c2ecf20Sopenharmony_ci if (ret) { 1378c2ecf20Sopenharmony_ci dev_err(afe->dev, "%s(), clk_set_parent %s-%s fail %d\n", 1388c2ecf20Sopenharmony_ci __func__, aud_clks[CLK_MUX_AUDIO], 1398c2ecf20Sopenharmony_ci aud_clks[CLK_CLK26M], ret); 1408c2ecf20Sopenharmony_ci goto CLK_MUX_AUDIO_ERR; 1418c2ecf20Sopenharmony_ci } 1428c2ecf20Sopenharmony_ci 1438c2ecf20Sopenharmony_ci ret = clk_prepare_enable(afe_priv->clk[CLK_MUX_AUDIOINTBUS]); 1448c2ecf20Sopenharmony_ci if (ret) { 1458c2ecf20Sopenharmony_ci dev_err(afe->dev, "%s(), clk_prepare_enable %s fail %d\n", 1468c2ecf20Sopenharmony_ci __func__, aud_clks[CLK_MUX_AUDIOINTBUS], ret); 1478c2ecf20Sopenharmony_ci goto CLK_MUX_AUDIO_INTBUS_ERR; 1488c2ecf20Sopenharmony_ci } 1498c2ecf20Sopenharmony_ci 1508c2ecf20Sopenharmony_ci ret = clk_set_parent(afe_priv->clk[CLK_MUX_AUDIOINTBUS], 1518c2ecf20Sopenharmony_ci afe_priv->clk[CLK_TOP_SYSPLL_D2_D4]); 1528c2ecf20Sopenharmony_ci if (ret) { 1538c2ecf20Sopenharmony_ci dev_err(afe->dev, "%s(), clk_set_parent %s-%s fail %d\n", 1548c2ecf20Sopenharmony_ci __func__, aud_clks[CLK_MUX_AUDIOINTBUS], 1558c2ecf20Sopenharmony_ci aud_clks[CLK_TOP_SYSPLL_D2_D4], ret); 1568c2ecf20Sopenharmony_ci goto CLK_MUX_AUDIO_INTBUS_ERR; 1578c2ecf20Sopenharmony_ci } 1588c2ecf20Sopenharmony_ci 1598c2ecf20Sopenharmony_ci ret = clk_prepare_enable(afe_priv->clk[CLK_AFE]); 1608c2ecf20Sopenharmony_ci if (ret) { 1618c2ecf20Sopenharmony_ci dev_err(afe->dev, "%s clk_prepare_enable %s fail %d\n", 1628c2ecf20Sopenharmony_ci __func__, aud_clks[CLK_AFE], ret); 1638c2ecf20Sopenharmony_ci goto CLK_AFE_ERR; 1648c2ecf20Sopenharmony_ci } 1658c2ecf20Sopenharmony_ci 1668c2ecf20Sopenharmony_ci ret = clk_prepare_enable(afe_priv->clk[CLK_I2S1_BCLK_SW]); 1678c2ecf20Sopenharmony_ci if (ret) { 1688c2ecf20Sopenharmony_ci dev_err(afe->dev, "%s clk_prepare_enable %s fail %d\n", 1698c2ecf20Sopenharmony_ci __func__, aud_clks[CLK_I2S1_BCLK_SW], ret); 1708c2ecf20Sopenharmony_ci goto CLK_I2S1_BCLK_SW_ERR; 1718c2ecf20Sopenharmony_ci } 1728c2ecf20Sopenharmony_ci 1738c2ecf20Sopenharmony_ci ret = clk_prepare_enable(afe_priv->clk[CLK_I2S2_BCLK_SW]); 1748c2ecf20Sopenharmony_ci if (ret) { 1758c2ecf20Sopenharmony_ci dev_err(afe->dev, "%s clk_prepare_enable %s fail %d\n", 1768c2ecf20Sopenharmony_ci __func__, aud_clks[CLK_I2S2_BCLK_SW], ret); 1778c2ecf20Sopenharmony_ci goto CLK_I2S2_BCLK_SW_ERR; 1788c2ecf20Sopenharmony_ci } 1798c2ecf20Sopenharmony_ci 1808c2ecf20Sopenharmony_ci ret = clk_prepare_enable(afe_priv->clk[CLK_I2S3_BCLK_SW]); 1818c2ecf20Sopenharmony_ci if (ret) { 1828c2ecf20Sopenharmony_ci dev_err(afe->dev, "%s clk_prepare_enable %s fail %d\n", 1838c2ecf20Sopenharmony_ci __func__, aud_clks[CLK_I2S3_BCLK_SW], ret); 1848c2ecf20Sopenharmony_ci goto CLK_I2S3_BCLK_SW_ERR; 1858c2ecf20Sopenharmony_ci } 1868c2ecf20Sopenharmony_ci 1878c2ecf20Sopenharmony_ci ret = clk_prepare_enable(afe_priv->clk[CLK_I2S4_BCLK_SW]); 1888c2ecf20Sopenharmony_ci if (ret) { 1898c2ecf20Sopenharmony_ci dev_err(afe->dev, "%s clk_prepare_enable %s fail %d\n", 1908c2ecf20Sopenharmony_ci __func__, aud_clks[CLK_I2S4_BCLK_SW], ret); 1918c2ecf20Sopenharmony_ci goto CLK_I2S4_BCLK_SW_ERR; 1928c2ecf20Sopenharmony_ci } 1938c2ecf20Sopenharmony_ci 1948c2ecf20Sopenharmony_ci return 0; 1958c2ecf20Sopenharmony_ci 1968c2ecf20Sopenharmony_ciCLK_I2S4_BCLK_SW_ERR: 1978c2ecf20Sopenharmony_ci clk_disable_unprepare(afe_priv->clk[CLK_I2S3_BCLK_SW]); 1988c2ecf20Sopenharmony_ciCLK_I2S3_BCLK_SW_ERR: 1998c2ecf20Sopenharmony_ci clk_disable_unprepare(afe_priv->clk[CLK_I2S2_BCLK_SW]); 2008c2ecf20Sopenharmony_ciCLK_I2S2_BCLK_SW_ERR: 2018c2ecf20Sopenharmony_ci clk_disable_unprepare(afe_priv->clk[CLK_I2S1_BCLK_SW]); 2028c2ecf20Sopenharmony_ciCLK_I2S1_BCLK_SW_ERR: 2038c2ecf20Sopenharmony_ci clk_disable_unprepare(afe_priv->clk[CLK_AFE]); 2048c2ecf20Sopenharmony_ciCLK_AFE_ERR: 2058c2ecf20Sopenharmony_ci clk_disable_unprepare(afe_priv->clk[CLK_MUX_AUDIOINTBUS]); 2068c2ecf20Sopenharmony_ciCLK_MUX_AUDIO_INTBUS_ERR: 2078c2ecf20Sopenharmony_ci clk_disable_unprepare(afe_priv->clk[CLK_MUX_AUDIO]); 2088c2ecf20Sopenharmony_ciCLK_MUX_AUDIO_ERR: 2098c2ecf20Sopenharmony_ci clk_disable_unprepare(afe_priv->clk[CLK_INFRA_SYS_AUDIO]); 2108c2ecf20Sopenharmony_ciCLK_INFRA_SYS_AUDIO_ERR: 2118c2ecf20Sopenharmony_ci return ret; 2128c2ecf20Sopenharmony_ci} 2138c2ecf20Sopenharmony_ci 2148c2ecf20Sopenharmony_ciint mt8183_afe_disable_clock(struct mtk_base_afe *afe) 2158c2ecf20Sopenharmony_ci{ 2168c2ecf20Sopenharmony_ci struct mt8183_afe_private *afe_priv = afe->platform_priv; 2178c2ecf20Sopenharmony_ci 2188c2ecf20Sopenharmony_ci clk_disable_unprepare(afe_priv->clk[CLK_I2S4_BCLK_SW]); 2198c2ecf20Sopenharmony_ci clk_disable_unprepare(afe_priv->clk[CLK_I2S3_BCLK_SW]); 2208c2ecf20Sopenharmony_ci clk_disable_unprepare(afe_priv->clk[CLK_I2S2_BCLK_SW]); 2218c2ecf20Sopenharmony_ci clk_disable_unprepare(afe_priv->clk[CLK_I2S1_BCLK_SW]); 2228c2ecf20Sopenharmony_ci clk_disable_unprepare(afe_priv->clk[CLK_AFE]); 2238c2ecf20Sopenharmony_ci clk_disable_unprepare(afe_priv->clk[CLK_MUX_AUDIOINTBUS]); 2248c2ecf20Sopenharmony_ci clk_disable_unprepare(afe_priv->clk[CLK_MUX_AUDIO]); 2258c2ecf20Sopenharmony_ci clk_disable_unprepare(afe_priv->clk[CLK_INFRA_SYS_AUDIO]); 2268c2ecf20Sopenharmony_ci 2278c2ecf20Sopenharmony_ci return 0; 2288c2ecf20Sopenharmony_ci} 2298c2ecf20Sopenharmony_ci 2308c2ecf20Sopenharmony_ci/* apll */ 2318c2ecf20Sopenharmony_cistatic int apll1_mux_setting(struct mtk_base_afe *afe, bool enable) 2328c2ecf20Sopenharmony_ci{ 2338c2ecf20Sopenharmony_ci struct mt8183_afe_private *afe_priv = afe->platform_priv; 2348c2ecf20Sopenharmony_ci int ret; 2358c2ecf20Sopenharmony_ci 2368c2ecf20Sopenharmony_ci if (enable) { 2378c2ecf20Sopenharmony_ci ret = clk_prepare_enable(afe_priv->clk[CLK_TOP_MUX_AUD_1]); 2388c2ecf20Sopenharmony_ci if (ret) { 2398c2ecf20Sopenharmony_ci dev_err(afe->dev, "%s clk_prepare_enable %s fail %d\n", 2408c2ecf20Sopenharmony_ci __func__, aud_clks[CLK_TOP_MUX_AUD_1], ret); 2418c2ecf20Sopenharmony_ci goto ERR_ENABLE_CLK_TOP_MUX_AUD_1; 2428c2ecf20Sopenharmony_ci } 2438c2ecf20Sopenharmony_ci ret = clk_set_parent(afe_priv->clk[CLK_TOP_MUX_AUD_1], 2448c2ecf20Sopenharmony_ci afe_priv->clk[CLK_TOP_APLL1_CK]); 2458c2ecf20Sopenharmony_ci if (ret) { 2468c2ecf20Sopenharmony_ci dev_err(afe->dev, "%s clk_set_parent %s-%s fail %d\n", 2478c2ecf20Sopenharmony_ci __func__, aud_clks[CLK_TOP_MUX_AUD_1], 2488c2ecf20Sopenharmony_ci aud_clks[CLK_TOP_APLL1_CK], ret); 2498c2ecf20Sopenharmony_ci goto ERR_SELECT_CLK_TOP_MUX_AUD_1; 2508c2ecf20Sopenharmony_ci } 2518c2ecf20Sopenharmony_ci 2528c2ecf20Sopenharmony_ci /* 180.6336 / 8 = 22.5792MHz */ 2538c2ecf20Sopenharmony_ci ret = clk_prepare_enable(afe_priv->clk[CLK_TOP_MUX_AUD_ENG1]); 2548c2ecf20Sopenharmony_ci if (ret) { 2558c2ecf20Sopenharmony_ci dev_err(afe->dev, "%s clk_prepare_enable %s fail %d\n", 2568c2ecf20Sopenharmony_ci __func__, aud_clks[CLK_TOP_MUX_AUD_ENG1], ret); 2578c2ecf20Sopenharmony_ci goto ERR_ENABLE_CLK_TOP_MUX_AUD_ENG1; 2588c2ecf20Sopenharmony_ci } 2598c2ecf20Sopenharmony_ci ret = clk_set_parent(afe_priv->clk[CLK_TOP_MUX_AUD_ENG1], 2608c2ecf20Sopenharmony_ci afe_priv->clk[CLK_TOP_APLL1_D8]); 2618c2ecf20Sopenharmony_ci if (ret) { 2628c2ecf20Sopenharmony_ci dev_err(afe->dev, "%s clk_set_parent %s-%s fail %d\n", 2638c2ecf20Sopenharmony_ci __func__, aud_clks[CLK_TOP_MUX_AUD_ENG1], 2648c2ecf20Sopenharmony_ci aud_clks[CLK_TOP_APLL1_D8], ret); 2658c2ecf20Sopenharmony_ci goto ERR_SELECT_CLK_TOP_MUX_AUD_ENG1; 2668c2ecf20Sopenharmony_ci } 2678c2ecf20Sopenharmony_ci } else { 2688c2ecf20Sopenharmony_ci ret = clk_set_parent(afe_priv->clk[CLK_TOP_MUX_AUD_ENG1], 2698c2ecf20Sopenharmony_ci afe_priv->clk[CLK_CLK26M]); 2708c2ecf20Sopenharmony_ci if (ret) { 2718c2ecf20Sopenharmony_ci dev_err(afe->dev, "%s clk_set_parent %s-%s fail %d\n", 2728c2ecf20Sopenharmony_ci __func__, aud_clks[CLK_TOP_MUX_AUD_ENG1], 2738c2ecf20Sopenharmony_ci aud_clks[CLK_CLK26M], ret); 2748c2ecf20Sopenharmony_ci goto EXIT; 2758c2ecf20Sopenharmony_ci } 2768c2ecf20Sopenharmony_ci clk_disable_unprepare(afe_priv->clk[CLK_TOP_MUX_AUD_ENG1]); 2778c2ecf20Sopenharmony_ci 2788c2ecf20Sopenharmony_ci ret = clk_set_parent(afe_priv->clk[CLK_TOP_MUX_AUD_1], 2798c2ecf20Sopenharmony_ci afe_priv->clk[CLK_CLK26M]); 2808c2ecf20Sopenharmony_ci if (ret) { 2818c2ecf20Sopenharmony_ci dev_err(afe->dev, "%s clk_set_parent %s-%s fail %d\n", 2828c2ecf20Sopenharmony_ci __func__, aud_clks[CLK_TOP_MUX_AUD_1], 2838c2ecf20Sopenharmony_ci aud_clks[CLK_CLK26M], ret); 2848c2ecf20Sopenharmony_ci goto EXIT; 2858c2ecf20Sopenharmony_ci } 2868c2ecf20Sopenharmony_ci clk_disable_unprepare(afe_priv->clk[CLK_TOP_MUX_AUD_1]); 2878c2ecf20Sopenharmony_ci } 2888c2ecf20Sopenharmony_ci 2898c2ecf20Sopenharmony_ci return 0; 2908c2ecf20Sopenharmony_ci 2918c2ecf20Sopenharmony_ciERR_SELECT_CLK_TOP_MUX_AUD_ENG1: 2928c2ecf20Sopenharmony_ci clk_set_parent(afe_priv->clk[CLK_TOP_MUX_AUD_ENG1], 2938c2ecf20Sopenharmony_ci afe_priv->clk[CLK_CLK26M]); 2948c2ecf20Sopenharmony_ci clk_disable_unprepare(afe_priv->clk[CLK_TOP_MUX_AUD_ENG1]); 2958c2ecf20Sopenharmony_ciERR_ENABLE_CLK_TOP_MUX_AUD_ENG1: 2968c2ecf20Sopenharmony_ciERR_SELECT_CLK_TOP_MUX_AUD_1: 2978c2ecf20Sopenharmony_ci clk_set_parent(afe_priv->clk[CLK_TOP_MUX_AUD_1], 2988c2ecf20Sopenharmony_ci afe_priv->clk[CLK_CLK26M]); 2998c2ecf20Sopenharmony_ci clk_disable_unprepare(afe_priv->clk[CLK_TOP_MUX_AUD_1]); 3008c2ecf20Sopenharmony_ciERR_ENABLE_CLK_TOP_MUX_AUD_1: 3018c2ecf20Sopenharmony_ciEXIT: 3028c2ecf20Sopenharmony_ci return ret; 3038c2ecf20Sopenharmony_ci} 3048c2ecf20Sopenharmony_ci 3058c2ecf20Sopenharmony_cistatic int apll2_mux_setting(struct mtk_base_afe *afe, bool enable) 3068c2ecf20Sopenharmony_ci{ 3078c2ecf20Sopenharmony_ci struct mt8183_afe_private *afe_priv = afe->platform_priv; 3088c2ecf20Sopenharmony_ci int ret; 3098c2ecf20Sopenharmony_ci 3108c2ecf20Sopenharmony_ci if (enable) { 3118c2ecf20Sopenharmony_ci ret = clk_prepare_enable(afe_priv->clk[CLK_TOP_MUX_AUD_2]); 3128c2ecf20Sopenharmony_ci if (ret) { 3138c2ecf20Sopenharmony_ci dev_err(afe->dev, "%s clk_prepare_enable %s fail %d\n", 3148c2ecf20Sopenharmony_ci __func__, aud_clks[CLK_TOP_MUX_AUD_2], ret); 3158c2ecf20Sopenharmony_ci goto ERR_ENABLE_CLK_TOP_MUX_AUD_2; 3168c2ecf20Sopenharmony_ci } 3178c2ecf20Sopenharmony_ci ret = clk_set_parent(afe_priv->clk[CLK_TOP_MUX_AUD_2], 3188c2ecf20Sopenharmony_ci afe_priv->clk[CLK_TOP_APLL2_CK]); 3198c2ecf20Sopenharmony_ci if (ret) { 3208c2ecf20Sopenharmony_ci dev_err(afe->dev, "%s clk_set_parent %s-%s fail %d\n", 3218c2ecf20Sopenharmony_ci __func__, aud_clks[CLK_TOP_MUX_AUD_2], 3228c2ecf20Sopenharmony_ci aud_clks[CLK_TOP_APLL2_CK], ret); 3238c2ecf20Sopenharmony_ci goto ERR_SELECT_CLK_TOP_MUX_AUD_2; 3248c2ecf20Sopenharmony_ci } 3258c2ecf20Sopenharmony_ci 3268c2ecf20Sopenharmony_ci /* 196.608 / 8 = 24.576MHz */ 3278c2ecf20Sopenharmony_ci ret = clk_prepare_enable(afe_priv->clk[CLK_TOP_MUX_AUD_ENG2]); 3288c2ecf20Sopenharmony_ci if (ret) { 3298c2ecf20Sopenharmony_ci dev_err(afe->dev, "%s clk_prepare_enable %s fail %d\n", 3308c2ecf20Sopenharmony_ci __func__, aud_clks[CLK_TOP_MUX_AUD_ENG2], ret); 3318c2ecf20Sopenharmony_ci goto ERR_ENABLE_CLK_TOP_MUX_AUD_ENG2; 3328c2ecf20Sopenharmony_ci } 3338c2ecf20Sopenharmony_ci ret = clk_set_parent(afe_priv->clk[CLK_TOP_MUX_AUD_ENG2], 3348c2ecf20Sopenharmony_ci afe_priv->clk[CLK_TOP_APLL2_D8]); 3358c2ecf20Sopenharmony_ci if (ret) { 3368c2ecf20Sopenharmony_ci dev_err(afe->dev, "%s clk_set_parent %s-%s fail %d\n", 3378c2ecf20Sopenharmony_ci __func__, aud_clks[CLK_TOP_MUX_AUD_ENG2], 3388c2ecf20Sopenharmony_ci aud_clks[CLK_TOP_APLL2_D8], ret); 3398c2ecf20Sopenharmony_ci goto ERR_SELECT_CLK_TOP_MUX_AUD_ENG2; 3408c2ecf20Sopenharmony_ci } 3418c2ecf20Sopenharmony_ci } else { 3428c2ecf20Sopenharmony_ci ret = clk_set_parent(afe_priv->clk[CLK_TOP_MUX_AUD_ENG2], 3438c2ecf20Sopenharmony_ci afe_priv->clk[CLK_CLK26M]); 3448c2ecf20Sopenharmony_ci if (ret) { 3458c2ecf20Sopenharmony_ci dev_err(afe->dev, "%s clk_set_parent %s-%s fail %d\n", 3468c2ecf20Sopenharmony_ci __func__, aud_clks[CLK_TOP_MUX_AUD_ENG2], 3478c2ecf20Sopenharmony_ci aud_clks[CLK_CLK26M], ret); 3488c2ecf20Sopenharmony_ci goto EXIT; 3498c2ecf20Sopenharmony_ci } 3508c2ecf20Sopenharmony_ci clk_disable_unprepare(afe_priv->clk[CLK_TOP_MUX_AUD_ENG2]); 3518c2ecf20Sopenharmony_ci 3528c2ecf20Sopenharmony_ci ret = clk_set_parent(afe_priv->clk[CLK_TOP_MUX_AUD_2], 3538c2ecf20Sopenharmony_ci afe_priv->clk[CLK_CLK26M]); 3548c2ecf20Sopenharmony_ci if (ret) { 3558c2ecf20Sopenharmony_ci dev_err(afe->dev, "%s clk_set_parent %s-%s fail %d\n", 3568c2ecf20Sopenharmony_ci __func__, aud_clks[CLK_TOP_MUX_AUD_2], 3578c2ecf20Sopenharmony_ci aud_clks[CLK_CLK26M], ret); 3588c2ecf20Sopenharmony_ci goto EXIT; 3598c2ecf20Sopenharmony_ci } 3608c2ecf20Sopenharmony_ci clk_disable_unprepare(afe_priv->clk[CLK_TOP_MUX_AUD_2]); 3618c2ecf20Sopenharmony_ci } 3628c2ecf20Sopenharmony_ci 3638c2ecf20Sopenharmony_ci return 0; 3648c2ecf20Sopenharmony_ci 3658c2ecf20Sopenharmony_ciERR_SELECT_CLK_TOP_MUX_AUD_ENG2: 3668c2ecf20Sopenharmony_ci clk_set_parent(afe_priv->clk[CLK_TOP_MUX_AUD_ENG2], 3678c2ecf20Sopenharmony_ci afe_priv->clk[CLK_CLK26M]); 3688c2ecf20Sopenharmony_ci clk_disable_unprepare(afe_priv->clk[CLK_TOP_MUX_AUD_ENG2]); 3698c2ecf20Sopenharmony_ciERR_ENABLE_CLK_TOP_MUX_AUD_ENG2: 3708c2ecf20Sopenharmony_ciERR_SELECT_CLK_TOP_MUX_AUD_2: 3718c2ecf20Sopenharmony_ci clk_set_parent(afe_priv->clk[CLK_TOP_MUX_AUD_2], 3728c2ecf20Sopenharmony_ci afe_priv->clk[CLK_CLK26M]); 3738c2ecf20Sopenharmony_ci clk_disable_unprepare(afe_priv->clk[CLK_TOP_MUX_AUD_2]); 3748c2ecf20Sopenharmony_ciERR_ENABLE_CLK_TOP_MUX_AUD_2: 3758c2ecf20Sopenharmony_ciEXIT: 3768c2ecf20Sopenharmony_ci return ret; 3778c2ecf20Sopenharmony_ci} 3788c2ecf20Sopenharmony_ci 3798c2ecf20Sopenharmony_ciint mt8183_apll1_enable(struct mtk_base_afe *afe) 3808c2ecf20Sopenharmony_ci{ 3818c2ecf20Sopenharmony_ci struct mt8183_afe_private *afe_priv = afe->platform_priv; 3828c2ecf20Sopenharmony_ci int ret; 3838c2ecf20Sopenharmony_ci 3848c2ecf20Sopenharmony_ci /* setting for APLL */ 3858c2ecf20Sopenharmony_ci apll1_mux_setting(afe, true); 3868c2ecf20Sopenharmony_ci 3878c2ecf20Sopenharmony_ci ret = clk_prepare_enable(afe_priv->clk[CLK_APLL22M]); 3888c2ecf20Sopenharmony_ci if (ret) { 3898c2ecf20Sopenharmony_ci dev_err(afe->dev, "%s clk_prepare_enable %s fail %d\n", 3908c2ecf20Sopenharmony_ci __func__, aud_clks[CLK_APLL22M], ret); 3918c2ecf20Sopenharmony_ci goto ERR_CLK_APLL22M; 3928c2ecf20Sopenharmony_ci } 3938c2ecf20Sopenharmony_ci 3948c2ecf20Sopenharmony_ci ret = clk_prepare_enable(afe_priv->clk[CLK_APLL1_TUNER]); 3958c2ecf20Sopenharmony_ci if (ret) { 3968c2ecf20Sopenharmony_ci dev_err(afe->dev, "%s clk_prepare_enable %s fail %d\n", 3978c2ecf20Sopenharmony_ci __func__, aud_clks[CLK_APLL1_TUNER], ret); 3988c2ecf20Sopenharmony_ci goto ERR_CLK_APLL1_TUNER; 3998c2ecf20Sopenharmony_ci } 4008c2ecf20Sopenharmony_ci 4018c2ecf20Sopenharmony_ci regmap_update_bits(afe->regmap, AFE_APLL1_TUNER_CFG, 4028c2ecf20Sopenharmony_ci 0x0000FFF7, 0x00000832); 4038c2ecf20Sopenharmony_ci regmap_update_bits(afe->regmap, AFE_APLL1_TUNER_CFG, 0x1, 0x1); 4048c2ecf20Sopenharmony_ci 4058c2ecf20Sopenharmony_ci regmap_update_bits(afe->regmap, AFE_HD_ENGEN_ENABLE, 4068c2ecf20Sopenharmony_ci AFE_22M_ON_MASK_SFT, 4078c2ecf20Sopenharmony_ci 0x1 << AFE_22M_ON_SFT); 4088c2ecf20Sopenharmony_ci 4098c2ecf20Sopenharmony_ci return 0; 4108c2ecf20Sopenharmony_ci 4118c2ecf20Sopenharmony_ciERR_CLK_APLL1_TUNER: 4128c2ecf20Sopenharmony_ci clk_disable_unprepare(afe_priv->clk[CLK_APLL22M]); 4138c2ecf20Sopenharmony_ciERR_CLK_APLL22M: 4148c2ecf20Sopenharmony_ci return ret; 4158c2ecf20Sopenharmony_ci} 4168c2ecf20Sopenharmony_ci 4178c2ecf20Sopenharmony_civoid mt8183_apll1_disable(struct mtk_base_afe *afe) 4188c2ecf20Sopenharmony_ci{ 4198c2ecf20Sopenharmony_ci struct mt8183_afe_private *afe_priv = afe->platform_priv; 4208c2ecf20Sopenharmony_ci 4218c2ecf20Sopenharmony_ci regmap_update_bits(afe->regmap, AFE_HD_ENGEN_ENABLE, 4228c2ecf20Sopenharmony_ci AFE_22M_ON_MASK_SFT, 4238c2ecf20Sopenharmony_ci 0x0 << AFE_22M_ON_SFT); 4248c2ecf20Sopenharmony_ci 4258c2ecf20Sopenharmony_ci regmap_update_bits(afe->regmap, AFE_APLL1_TUNER_CFG, 0x1, 0x0); 4268c2ecf20Sopenharmony_ci 4278c2ecf20Sopenharmony_ci clk_disable_unprepare(afe_priv->clk[CLK_APLL1_TUNER]); 4288c2ecf20Sopenharmony_ci clk_disable_unprepare(afe_priv->clk[CLK_APLL22M]); 4298c2ecf20Sopenharmony_ci 4308c2ecf20Sopenharmony_ci apll1_mux_setting(afe, false); 4318c2ecf20Sopenharmony_ci} 4328c2ecf20Sopenharmony_ci 4338c2ecf20Sopenharmony_ciint mt8183_apll2_enable(struct mtk_base_afe *afe) 4348c2ecf20Sopenharmony_ci{ 4358c2ecf20Sopenharmony_ci struct mt8183_afe_private *afe_priv = afe->platform_priv; 4368c2ecf20Sopenharmony_ci int ret; 4378c2ecf20Sopenharmony_ci 4388c2ecf20Sopenharmony_ci /* setting for APLL */ 4398c2ecf20Sopenharmony_ci apll2_mux_setting(afe, true); 4408c2ecf20Sopenharmony_ci 4418c2ecf20Sopenharmony_ci ret = clk_prepare_enable(afe_priv->clk[CLK_APLL24M]); 4428c2ecf20Sopenharmony_ci if (ret) { 4438c2ecf20Sopenharmony_ci dev_err(afe->dev, "%s clk_prepare_enable %s fail %d\n", 4448c2ecf20Sopenharmony_ci __func__, aud_clks[CLK_APLL24M], ret); 4458c2ecf20Sopenharmony_ci goto ERR_CLK_APLL24M; 4468c2ecf20Sopenharmony_ci } 4478c2ecf20Sopenharmony_ci 4488c2ecf20Sopenharmony_ci ret = clk_prepare_enable(afe_priv->clk[CLK_APLL2_TUNER]); 4498c2ecf20Sopenharmony_ci if (ret) { 4508c2ecf20Sopenharmony_ci dev_err(afe->dev, "%s clk_prepare_enable %s fail %d\n", 4518c2ecf20Sopenharmony_ci __func__, aud_clks[CLK_APLL2_TUNER], ret); 4528c2ecf20Sopenharmony_ci goto ERR_CLK_APLL2_TUNER; 4538c2ecf20Sopenharmony_ci } 4548c2ecf20Sopenharmony_ci 4558c2ecf20Sopenharmony_ci regmap_update_bits(afe->regmap, AFE_APLL2_TUNER_CFG, 4568c2ecf20Sopenharmony_ci 0x0000FFF7, 0x00000634); 4578c2ecf20Sopenharmony_ci regmap_update_bits(afe->regmap, AFE_APLL2_TUNER_CFG, 0x1, 0x1); 4588c2ecf20Sopenharmony_ci 4598c2ecf20Sopenharmony_ci regmap_update_bits(afe->regmap, AFE_HD_ENGEN_ENABLE, 4608c2ecf20Sopenharmony_ci AFE_24M_ON_MASK_SFT, 4618c2ecf20Sopenharmony_ci 0x1 << AFE_24M_ON_SFT); 4628c2ecf20Sopenharmony_ci 4638c2ecf20Sopenharmony_ci return 0; 4648c2ecf20Sopenharmony_ci 4658c2ecf20Sopenharmony_ciERR_CLK_APLL2_TUNER: 4668c2ecf20Sopenharmony_ci clk_disable_unprepare(afe_priv->clk[CLK_APLL24M]); 4678c2ecf20Sopenharmony_ciERR_CLK_APLL24M: 4688c2ecf20Sopenharmony_ci return ret; 4698c2ecf20Sopenharmony_ci} 4708c2ecf20Sopenharmony_ci 4718c2ecf20Sopenharmony_civoid mt8183_apll2_disable(struct mtk_base_afe *afe) 4728c2ecf20Sopenharmony_ci{ 4738c2ecf20Sopenharmony_ci struct mt8183_afe_private *afe_priv = afe->platform_priv; 4748c2ecf20Sopenharmony_ci 4758c2ecf20Sopenharmony_ci regmap_update_bits(afe->regmap, AFE_HD_ENGEN_ENABLE, 4768c2ecf20Sopenharmony_ci AFE_24M_ON_MASK_SFT, 4778c2ecf20Sopenharmony_ci 0x0 << AFE_24M_ON_SFT); 4788c2ecf20Sopenharmony_ci 4798c2ecf20Sopenharmony_ci regmap_update_bits(afe->regmap, AFE_APLL2_TUNER_CFG, 0x1, 0x0); 4808c2ecf20Sopenharmony_ci 4818c2ecf20Sopenharmony_ci clk_disable_unprepare(afe_priv->clk[CLK_APLL2_TUNER]); 4828c2ecf20Sopenharmony_ci clk_disable_unprepare(afe_priv->clk[CLK_APLL24M]); 4838c2ecf20Sopenharmony_ci 4848c2ecf20Sopenharmony_ci apll2_mux_setting(afe, false); 4858c2ecf20Sopenharmony_ci} 4868c2ecf20Sopenharmony_ci 4878c2ecf20Sopenharmony_ciint mt8183_get_apll_rate(struct mtk_base_afe *afe, int apll) 4888c2ecf20Sopenharmony_ci{ 4898c2ecf20Sopenharmony_ci return (apll == MT8183_APLL1) ? 180633600 : 196608000; 4908c2ecf20Sopenharmony_ci} 4918c2ecf20Sopenharmony_ci 4928c2ecf20Sopenharmony_ciint mt8183_get_apll_by_rate(struct mtk_base_afe *afe, int rate) 4938c2ecf20Sopenharmony_ci{ 4948c2ecf20Sopenharmony_ci return ((rate % 8000) == 0) ? MT8183_APLL2 : MT8183_APLL1; 4958c2ecf20Sopenharmony_ci} 4968c2ecf20Sopenharmony_ci 4978c2ecf20Sopenharmony_ciint mt8183_get_apll_by_name(struct mtk_base_afe *afe, const char *name) 4988c2ecf20Sopenharmony_ci{ 4998c2ecf20Sopenharmony_ci if (strcmp(name, APLL1_W_NAME) == 0) 5008c2ecf20Sopenharmony_ci return MT8183_APLL1; 5018c2ecf20Sopenharmony_ci else 5028c2ecf20Sopenharmony_ci return MT8183_APLL2; 5038c2ecf20Sopenharmony_ci} 5048c2ecf20Sopenharmony_ci 5058c2ecf20Sopenharmony_ci/* mck */ 5068c2ecf20Sopenharmony_cistruct mt8183_mck_div { 5078c2ecf20Sopenharmony_ci int m_sel_id; 5088c2ecf20Sopenharmony_ci int div_clk_id; 5098c2ecf20Sopenharmony_ci}; 5108c2ecf20Sopenharmony_ci 5118c2ecf20Sopenharmony_cistatic const struct mt8183_mck_div mck_div[MT8183_MCK_NUM] = { 5128c2ecf20Sopenharmony_ci [MT8183_I2S0_MCK] = { 5138c2ecf20Sopenharmony_ci .m_sel_id = CLK_TOP_I2S0_M_SEL, 5148c2ecf20Sopenharmony_ci .div_clk_id = CLK_TOP_APLL12_DIV0, 5158c2ecf20Sopenharmony_ci }, 5168c2ecf20Sopenharmony_ci [MT8183_I2S1_MCK] = { 5178c2ecf20Sopenharmony_ci .m_sel_id = CLK_TOP_I2S1_M_SEL, 5188c2ecf20Sopenharmony_ci .div_clk_id = CLK_TOP_APLL12_DIV1, 5198c2ecf20Sopenharmony_ci }, 5208c2ecf20Sopenharmony_ci [MT8183_I2S2_MCK] = { 5218c2ecf20Sopenharmony_ci .m_sel_id = CLK_TOP_I2S2_M_SEL, 5228c2ecf20Sopenharmony_ci .div_clk_id = CLK_TOP_APLL12_DIV2, 5238c2ecf20Sopenharmony_ci }, 5248c2ecf20Sopenharmony_ci [MT8183_I2S3_MCK] = { 5258c2ecf20Sopenharmony_ci .m_sel_id = CLK_TOP_I2S3_M_SEL, 5268c2ecf20Sopenharmony_ci .div_clk_id = CLK_TOP_APLL12_DIV3, 5278c2ecf20Sopenharmony_ci }, 5288c2ecf20Sopenharmony_ci [MT8183_I2S4_MCK] = { 5298c2ecf20Sopenharmony_ci .m_sel_id = CLK_TOP_I2S4_M_SEL, 5308c2ecf20Sopenharmony_ci .div_clk_id = CLK_TOP_APLL12_DIV4, 5318c2ecf20Sopenharmony_ci }, 5328c2ecf20Sopenharmony_ci [MT8183_I2S4_BCK] = { 5338c2ecf20Sopenharmony_ci .m_sel_id = -1, 5348c2ecf20Sopenharmony_ci .div_clk_id = CLK_TOP_APLL12_DIVB, 5358c2ecf20Sopenharmony_ci }, 5368c2ecf20Sopenharmony_ci [MT8183_I2S5_MCK] = { 5378c2ecf20Sopenharmony_ci .m_sel_id = -1, 5388c2ecf20Sopenharmony_ci .div_clk_id = -1, 5398c2ecf20Sopenharmony_ci }, 5408c2ecf20Sopenharmony_ci}; 5418c2ecf20Sopenharmony_ci 5428c2ecf20Sopenharmony_ciint mt8183_mck_enable(struct mtk_base_afe *afe, int mck_id, int rate) 5438c2ecf20Sopenharmony_ci{ 5448c2ecf20Sopenharmony_ci struct mt8183_afe_private *afe_priv = afe->platform_priv; 5458c2ecf20Sopenharmony_ci int apll = mt8183_get_apll_by_rate(afe, rate); 5468c2ecf20Sopenharmony_ci int apll_clk_id = apll == MT8183_APLL1 ? 5478c2ecf20Sopenharmony_ci CLK_TOP_MUX_AUD_1 : CLK_TOP_MUX_AUD_2; 5488c2ecf20Sopenharmony_ci int m_sel_id = mck_div[mck_id].m_sel_id; 5498c2ecf20Sopenharmony_ci int div_clk_id = mck_div[mck_id].div_clk_id; 5508c2ecf20Sopenharmony_ci int ret; 5518c2ecf20Sopenharmony_ci 5528c2ecf20Sopenharmony_ci /* i2s5 mck not support */ 5538c2ecf20Sopenharmony_ci if (mck_id == MT8183_I2S5_MCK) 5548c2ecf20Sopenharmony_ci return 0; 5558c2ecf20Sopenharmony_ci 5568c2ecf20Sopenharmony_ci /* select apll */ 5578c2ecf20Sopenharmony_ci if (m_sel_id >= 0) { 5588c2ecf20Sopenharmony_ci ret = clk_prepare_enable(afe_priv->clk[m_sel_id]); 5598c2ecf20Sopenharmony_ci if (ret) { 5608c2ecf20Sopenharmony_ci dev_err(afe->dev, "%s(), clk_prepare_enable %s fail %d\n", 5618c2ecf20Sopenharmony_ci __func__, aud_clks[m_sel_id], ret); 5628c2ecf20Sopenharmony_ci goto ERR_ENABLE_MCLK; 5638c2ecf20Sopenharmony_ci } 5648c2ecf20Sopenharmony_ci ret = clk_set_parent(afe_priv->clk[m_sel_id], 5658c2ecf20Sopenharmony_ci afe_priv->clk[apll_clk_id]); 5668c2ecf20Sopenharmony_ci if (ret) { 5678c2ecf20Sopenharmony_ci dev_err(afe->dev, "%s(), clk_set_parent %s-%s fail %d\n", 5688c2ecf20Sopenharmony_ci __func__, aud_clks[m_sel_id], 5698c2ecf20Sopenharmony_ci aud_clks[apll_clk_id], ret); 5708c2ecf20Sopenharmony_ci goto ERR_SELECT_MCLK; 5718c2ecf20Sopenharmony_ci } 5728c2ecf20Sopenharmony_ci } 5738c2ecf20Sopenharmony_ci 5748c2ecf20Sopenharmony_ci /* enable div, set rate */ 5758c2ecf20Sopenharmony_ci ret = clk_prepare_enable(afe_priv->clk[div_clk_id]); 5768c2ecf20Sopenharmony_ci if (ret) { 5778c2ecf20Sopenharmony_ci dev_err(afe->dev, "%s(), clk_prepare_enable %s fail %d\n", 5788c2ecf20Sopenharmony_ci __func__, aud_clks[div_clk_id], ret); 5798c2ecf20Sopenharmony_ci goto ERR_ENABLE_MCLK_DIV; 5808c2ecf20Sopenharmony_ci } 5818c2ecf20Sopenharmony_ci ret = clk_set_rate(afe_priv->clk[div_clk_id], rate); 5828c2ecf20Sopenharmony_ci if (ret) { 5838c2ecf20Sopenharmony_ci dev_err(afe->dev, "%s(), clk_set_rate %s, rate %d, fail %d\n", 5848c2ecf20Sopenharmony_ci __func__, aud_clks[div_clk_id], 5858c2ecf20Sopenharmony_ci rate, ret); 5868c2ecf20Sopenharmony_ci goto ERR_SET_MCLK_RATE; 5878c2ecf20Sopenharmony_ci return ret; 5888c2ecf20Sopenharmony_ci } 5898c2ecf20Sopenharmony_ci 5908c2ecf20Sopenharmony_ci return 0; 5918c2ecf20Sopenharmony_ci 5928c2ecf20Sopenharmony_ciERR_SET_MCLK_RATE: 5938c2ecf20Sopenharmony_ci clk_disable_unprepare(afe_priv->clk[div_clk_id]); 5948c2ecf20Sopenharmony_ciERR_ENABLE_MCLK_DIV: 5958c2ecf20Sopenharmony_ciERR_SELECT_MCLK: 5968c2ecf20Sopenharmony_ci if (m_sel_id >= 0) 5978c2ecf20Sopenharmony_ci clk_disable_unprepare(afe_priv->clk[m_sel_id]); 5988c2ecf20Sopenharmony_ciERR_ENABLE_MCLK: 5998c2ecf20Sopenharmony_ci return ret; 6008c2ecf20Sopenharmony_ci} 6018c2ecf20Sopenharmony_ci 6028c2ecf20Sopenharmony_civoid mt8183_mck_disable(struct mtk_base_afe *afe, int mck_id) 6038c2ecf20Sopenharmony_ci{ 6048c2ecf20Sopenharmony_ci struct mt8183_afe_private *afe_priv = afe->platform_priv; 6058c2ecf20Sopenharmony_ci int m_sel_id = mck_div[mck_id].m_sel_id; 6068c2ecf20Sopenharmony_ci int div_clk_id = mck_div[mck_id].div_clk_id; 6078c2ecf20Sopenharmony_ci 6088c2ecf20Sopenharmony_ci /* i2s5 mck not support */ 6098c2ecf20Sopenharmony_ci if (mck_id == MT8183_I2S5_MCK) 6108c2ecf20Sopenharmony_ci return; 6118c2ecf20Sopenharmony_ci 6128c2ecf20Sopenharmony_ci clk_disable_unprepare(afe_priv->clk[div_clk_id]); 6138c2ecf20Sopenharmony_ci if (m_sel_id >= 0) 6148c2ecf20Sopenharmony_ci clk_disable_unprepare(afe_priv->clk[m_sel_id]); 6158c2ecf20Sopenharmony_ci} 616