1*125ab5d5SJiaxin Yu // SPDX-License-Identifier: GPL-2.0
2*125ab5d5SJiaxin Yu //
3*125ab5d5SJiaxin Yu // mt8192-afe-clk.c -- Mediatek 8192 afe clock ctrl
4*125ab5d5SJiaxin Yu //
5*125ab5d5SJiaxin Yu // Copyright (c) 2020 MediaTek Inc.
6*125ab5d5SJiaxin Yu // Author: Shane Chien <shane.chien@mediatek.com>
7*125ab5d5SJiaxin Yu //
8*125ab5d5SJiaxin Yu
9*125ab5d5SJiaxin Yu #include <linux/arm-smccc.h>
10*125ab5d5SJiaxin Yu #include <linux/clk.h>
11*125ab5d5SJiaxin Yu #include <linux/mfd/syscon.h>
12*125ab5d5SJiaxin Yu #include <linux/regmap.h>
13*125ab5d5SJiaxin Yu
14*125ab5d5SJiaxin Yu #include "mt8192-afe-clk.h"
15*125ab5d5SJiaxin Yu #include "mt8192-afe-common.h"
16*125ab5d5SJiaxin Yu
17*125ab5d5SJiaxin Yu static const char *aud_clks[CLK_NUM] = {
18*125ab5d5SJiaxin Yu [CLK_AFE] = "aud_afe_clk",
19*125ab5d5SJiaxin Yu [CLK_TML] = "aud_tml_clk",
20*125ab5d5SJiaxin Yu [CLK_APLL22M] = "aud_apll22m_clk",
21*125ab5d5SJiaxin Yu [CLK_APLL24M] = "aud_apll24m_clk",
22*125ab5d5SJiaxin Yu [CLK_APLL1_TUNER] = "aud_apll1_tuner_clk",
23*125ab5d5SJiaxin Yu [CLK_APLL2_TUNER] = "aud_apll2_tuner_clk",
24*125ab5d5SJiaxin Yu [CLK_NLE] = "aud_nle",
25*125ab5d5SJiaxin Yu [CLK_INFRA_SYS_AUDIO] = "aud_infra_clk",
26*125ab5d5SJiaxin Yu [CLK_INFRA_AUDIO_26M] = "aud_infra_26m_clk",
27*125ab5d5SJiaxin Yu [CLK_MUX_AUDIO] = "top_mux_audio",
28*125ab5d5SJiaxin Yu [CLK_MUX_AUDIOINTBUS] = "top_mux_audio_int",
29*125ab5d5SJiaxin Yu [CLK_TOP_MAINPLL_D4_D4] = "top_mainpll_d4_d4",
30*125ab5d5SJiaxin Yu [CLK_TOP_MUX_AUD_1] = "top_mux_aud_1",
31*125ab5d5SJiaxin Yu [CLK_TOP_APLL1_CK] = "top_apll1_ck",
32*125ab5d5SJiaxin Yu [CLK_TOP_MUX_AUD_2] = "top_mux_aud_2",
33*125ab5d5SJiaxin Yu [CLK_TOP_APLL2_CK] = "top_apll2_ck",
34*125ab5d5SJiaxin Yu [CLK_TOP_MUX_AUD_ENG1] = "top_mux_aud_eng1",
35*125ab5d5SJiaxin Yu [CLK_TOP_APLL1_D4] = "top_apll1_d4",
36*125ab5d5SJiaxin Yu [CLK_TOP_MUX_AUD_ENG2] = "top_mux_aud_eng2",
37*125ab5d5SJiaxin Yu [CLK_TOP_APLL2_D4] = "top_apll2_d4",
38*125ab5d5SJiaxin Yu [CLK_TOP_MUX_AUDIO_H] = "top_mux_audio_h",
39*125ab5d5SJiaxin Yu [CLK_TOP_I2S0_M_SEL] = "top_i2s0_m_sel",
40*125ab5d5SJiaxin Yu [CLK_TOP_I2S1_M_SEL] = "top_i2s1_m_sel",
41*125ab5d5SJiaxin Yu [CLK_TOP_I2S2_M_SEL] = "top_i2s2_m_sel",
42*125ab5d5SJiaxin Yu [CLK_TOP_I2S3_M_SEL] = "top_i2s3_m_sel",
43*125ab5d5SJiaxin Yu [CLK_TOP_I2S4_M_SEL] = "top_i2s4_m_sel",
44*125ab5d5SJiaxin Yu [CLK_TOP_I2S5_M_SEL] = "top_i2s5_m_sel",
45*125ab5d5SJiaxin Yu [CLK_TOP_I2S6_M_SEL] = "top_i2s6_m_sel",
46*125ab5d5SJiaxin Yu [CLK_TOP_I2S7_M_SEL] = "top_i2s7_m_sel",
47*125ab5d5SJiaxin Yu [CLK_TOP_I2S8_M_SEL] = "top_i2s8_m_sel",
48*125ab5d5SJiaxin Yu [CLK_TOP_I2S9_M_SEL] = "top_i2s9_m_sel",
49*125ab5d5SJiaxin Yu [CLK_TOP_APLL12_DIV0] = "top_apll12_div0",
50*125ab5d5SJiaxin Yu [CLK_TOP_APLL12_DIV1] = "top_apll12_div1",
51*125ab5d5SJiaxin Yu [CLK_TOP_APLL12_DIV2] = "top_apll12_div2",
52*125ab5d5SJiaxin Yu [CLK_TOP_APLL12_DIV3] = "top_apll12_div3",
53*125ab5d5SJiaxin Yu [CLK_TOP_APLL12_DIV4] = "top_apll12_div4",
54*125ab5d5SJiaxin Yu [CLK_TOP_APLL12_DIVB] = "top_apll12_divb",
55*125ab5d5SJiaxin Yu [CLK_TOP_APLL12_DIV5] = "top_apll12_div5",
56*125ab5d5SJiaxin Yu [CLK_TOP_APLL12_DIV6] = "top_apll12_div6",
57*125ab5d5SJiaxin Yu [CLK_TOP_APLL12_DIV7] = "top_apll12_div7",
58*125ab5d5SJiaxin Yu [CLK_TOP_APLL12_DIV8] = "top_apll12_div8",
59*125ab5d5SJiaxin Yu [CLK_TOP_APLL12_DIV9] = "top_apll12_div9",
60*125ab5d5SJiaxin Yu [CLK_CLK26M] = "top_clk26m_clk",
61*125ab5d5SJiaxin Yu };
62*125ab5d5SJiaxin Yu
mt8192_set_audio_int_bus_parent(struct mtk_base_afe * afe,int clk_id)63*125ab5d5SJiaxin Yu int mt8192_set_audio_int_bus_parent(struct mtk_base_afe *afe,
64*125ab5d5SJiaxin Yu int clk_id)
65*125ab5d5SJiaxin Yu {
66*125ab5d5SJiaxin Yu struct mt8192_afe_private *afe_priv = afe->platform_priv;
67*125ab5d5SJiaxin Yu int ret;
68*125ab5d5SJiaxin Yu
69*125ab5d5SJiaxin Yu ret = clk_set_parent(afe_priv->clk[CLK_MUX_AUDIOINTBUS],
70*125ab5d5SJiaxin Yu afe_priv->clk[clk_id]);
71*125ab5d5SJiaxin Yu if (ret) {
72*125ab5d5SJiaxin Yu dev_err(afe->dev, "%s clk_set_parent %s-%s fail %d\n",
73*125ab5d5SJiaxin Yu __func__, aud_clks[CLK_MUX_AUDIOINTBUS],
74*125ab5d5SJiaxin Yu aud_clks[clk_id], ret);
75*125ab5d5SJiaxin Yu }
76*125ab5d5SJiaxin Yu
77*125ab5d5SJiaxin Yu return ret;
78*125ab5d5SJiaxin Yu }
79*125ab5d5SJiaxin Yu
apll1_mux_setting(struct mtk_base_afe * afe,bool enable)80*125ab5d5SJiaxin Yu static int apll1_mux_setting(struct mtk_base_afe *afe, bool enable)
81*125ab5d5SJiaxin Yu {
82*125ab5d5SJiaxin Yu struct mt8192_afe_private *afe_priv = afe->platform_priv;
83*125ab5d5SJiaxin Yu int ret;
84*125ab5d5SJiaxin Yu
85*125ab5d5SJiaxin Yu if (enable) {
86*125ab5d5SJiaxin Yu ret = clk_prepare_enable(afe_priv->clk[CLK_TOP_MUX_AUD_1]);
87*125ab5d5SJiaxin Yu if (ret) {
88*125ab5d5SJiaxin Yu dev_err(afe->dev, "%s clk_prepare_enable %s fail %d\n",
89*125ab5d5SJiaxin Yu __func__, aud_clks[CLK_TOP_MUX_AUD_1], ret);
90*125ab5d5SJiaxin Yu goto EXIT;
91*125ab5d5SJiaxin Yu }
92*125ab5d5SJiaxin Yu ret = clk_set_parent(afe_priv->clk[CLK_TOP_MUX_AUD_1],
93*125ab5d5SJiaxin Yu afe_priv->clk[CLK_TOP_APLL1_CK]);
94*125ab5d5SJiaxin Yu if (ret) {
95*125ab5d5SJiaxin Yu dev_err(afe->dev, "%s clk_set_parent %s-%s fail %d\n",
96*125ab5d5SJiaxin Yu __func__, aud_clks[CLK_TOP_MUX_AUD_1],
97*125ab5d5SJiaxin Yu aud_clks[CLK_TOP_APLL1_CK], ret);
98*125ab5d5SJiaxin Yu goto EXIT;
99*125ab5d5SJiaxin Yu }
100*125ab5d5SJiaxin Yu
101*125ab5d5SJiaxin Yu /* 180.6336 / 4 = 45.1584MHz */
102*125ab5d5SJiaxin Yu ret = clk_prepare_enable(afe_priv->clk[CLK_TOP_MUX_AUD_ENG1]);
103*125ab5d5SJiaxin Yu if (ret) {
104*125ab5d5SJiaxin Yu dev_err(afe->dev, "%s clk_prepare_enable %s fail %d\n",
105*125ab5d5SJiaxin Yu __func__, aud_clks[CLK_TOP_MUX_AUD_ENG1], ret);
106*125ab5d5SJiaxin Yu goto EXIT;
107*125ab5d5SJiaxin Yu }
108*125ab5d5SJiaxin Yu ret = clk_set_parent(afe_priv->clk[CLK_TOP_MUX_AUD_ENG1],
109*125ab5d5SJiaxin Yu afe_priv->clk[CLK_TOP_APLL1_D4]);
110*125ab5d5SJiaxin Yu if (ret) {
111*125ab5d5SJiaxin Yu dev_err(afe->dev, "%s clk_set_parent %s-%s fail %d\n",
112*125ab5d5SJiaxin Yu __func__, aud_clks[CLK_TOP_MUX_AUD_ENG1],
113*125ab5d5SJiaxin Yu aud_clks[CLK_TOP_APLL1_D4], ret);
114*125ab5d5SJiaxin Yu goto EXIT;
115*125ab5d5SJiaxin Yu }
116*125ab5d5SJiaxin Yu } else {
117*125ab5d5SJiaxin Yu ret = clk_set_parent(afe_priv->clk[CLK_TOP_MUX_AUD_ENG1],
118*125ab5d5SJiaxin Yu afe_priv->clk[CLK_CLK26M]);
119*125ab5d5SJiaxin Yu if (ret) {
120*125ab5d5SJiaxin Yu dev_err(afe->dev, "%s clk_set_parent %s-%s fail %d\n",
121*125ab5d5SJiaxin Yu __func__, aud_clks[CLK_TOP_MUX_AUD_ENG1],
122*125ab5d5SJiaxin Yu aud_clks[CLK_CLK26M], ret);
123*125ab5d5SJiaxin Yu goto EXIT;
124*125ab5d5SJiaxin Yu }
125*125ab5d5SJiaxin Yu clk_disable_unprepare(afe_priv->clk[CLK_TOP_MUX_AUD_ENG1]);
126*125ab5d5SJiaxin Yu
127*125ab5d5SJiaxin Yu ret = clk_set_parent(afe_priv->clk[CLK_TOP_MUX_AUD_1],
128*125ab5d5SJiaxin Yu afe_priv->clk[CLK_CLK26M]);
129*125ab5d5SJiaxin Yu if (ret) {
130*125ab5d5SJiaxin Yu dev_err(afe->dev, "%s clk_set_parent %s-%s fail %d\n",
131*125ab5d5SJiaxin Yu __func__, aud_clks[CLK_TOP_MUX_AUD_1],
132*125ab5d5SJiaxin Yu aud_clks[CLK_CLK26M], ret);
133*125ab5d5SJiaxin Yu goto EXIT;
134*125ab5d5SJiaxin Yu }
135*125ab5d5SJiaxin Yu clk_disable_unprepare(afe_priv->clk[CLK_TOP_MUX_AUD_1]);
136*125ab5d5SJiaxin Yu }
137*125ab5d5SJiaxin Yu
138*125ab5d5SJiaxin Yu EXIT:
139*125ab5d5SJiaxin Yu return ret;
140*125ab5d5SJiaxin Yu }
141*125ab5d5SJiaxin Yu
apll2_mux_setting(struct mtk_base_afe * afe,bool enable)142*125ab5d5SJiaxin Yu static int apll2_mux_setting(struct mtk_base_afe *afe, bool enable)
143*125ab5d5SJiaxin Yu {
144*125ab5d5SJiaxin Yu struct mt8192_afe_private *afe_priv = afe->platform_priv;
145*125ab5d5SJiaxin Yu int ret;
146*125ab5d5SJiaxin Yu
147*125ab5d5SJiaxin Yu if (enable) {
148*125ab5d5SJiaxin Yu ret = clk_prepare_enable(afe_priv->clk[CLK_TOP_MUX_AUD_2]);
149*125ab5d5SJiaxin Yu if (ret) {
150*125ab5d5SJiaxin Yu dev_err(afe->dev, "%s clk_prepare_enable %s fail %d\n",
151*125ab5d5SJiaxin Yu __func__, aud_clks[CLK_TOP_MUX_AUD_2], ret);
152*125ab5d5SJiaxin Yu goto EXIT;
153*125ab5d5SJiaxin Yu }
154*125ab5d5SJiaxin Yu ret = clk_set_parent(afe_priv->clk[CLK_TOP_MUX_AUD_2],
155*125ab5d5SJiaxin Yu afe_priv->clk[CLK_TOP_APLL2_CK]);
156*125ab5d5SJiaxin Yu if (ret) {
157*125ab5d5SJiaxin Yu dev_err(afe->dev, "%s clk_set_parent %s-%s fail %d\n",
158*125ab5d5SJiaxin Yu __func__, aud_clks[CLK_TOP_MUX_AUD_2],
159*125ab5d5SJiaxin Yu aud_clks[CLK_TOP_APLL2_CK], ret);
160*125ab5d5SJiaxin Yu goto EXIT;
161*125ab5d5SJiaxin Yu }
162*125ab5d5SJiaxin Yu
163*125ab5d5SJiaxin Yu /* 196.608 / 4 = 49.152MHz */
164*125ab5d5SJiaxin Yu ret = clk_prepare_enable(afe_priv->clk[CLK_TOP_MUX_AUD_ENG2]);
165*125ab5d5SJiaxin Yu if (ret) {
166*125ab5d5SJiaxin Yu dev_err(afe->dev, "%s clk_prepare_enable %s fail %d\n",
167*125ab5d5SJiaxin Yu __func__, aud_clks[CLK_TOP_MUX_AUD_ENG2], ret);
168*125ab5d5SJiaxin Yu goto EXIT;
169*125ab5d5SJiaxin Yu }
170*125ab5d5SJiaxin Yu ret = clk_set_parent(afe_priv->clk[CLK_TOP_MUX_AUD_ENG2],
171*125ab5d5SJiaxin Yu afe_priv->clk[CLK_TOP_APLL2_D4]);
172*125ab5d5SJiaxin Yu if (ret) {
173*125ab5d5SJiaxin Yu dev_err(afe->dev, "%s clk_set_parent %s-%s fail %d\n",
174*125ab5d5SJiaxin Yu __func__, aud_clks[CLK_TOP_MUX_AUD_ENG2],
175*125ab5d5SJiaxin Yu aud_clks[CLK_TOP_APLL2_D4], ret);
176*125ab5d5SJiaxin Yu goto EXIT;
177*125ab5d5SJiaxin Yu }
178*125ab5d5SJiaxin Yu } else {
179*125ab5d5SJiaxin Yu ret = clk_set_parent(afe_priv->clk[CLK_TOP_MUX_AUD_ENG2],
180*125ab5d5SJiaxin Yu afe_priv->clk[CLK_CLK26M]);
181*125ab5d5SJiaxin Yu if (ret) {
182*125ab5d5SJiaxin Yu dev_err(afe->dev, "%s clk_set_parent %s-%s fail %d\n",
183*125ab5d5SJiaxin Yu __func__, aud_clks[CLK_TOP_MUX_AUD_ENG2],
184*125ab5d5SJiaxin Yu aud_clks[CLK_CLK26M], ret);
185*125ab5d5SJiaxin Yu goto EXIT;
186*125ab5d5SJiaxin Yu }
187*125ab5d5SJiaxin Yu clk_disable_unprepare(afe_priv->clk[CLK_TOP_MUX_AUD_ENG2]);
188*125ab5d5SJiaxin Yu
189*125ab5d5SJiaxin Yu ret = clk_set_parent(afe_priv->clk[CLK_TOP_MUX_AUD_2],
190*125ab5d5SJiaxin Yu afe_priv->clk[CLK_CLK26M]);
191*125ab5d5SJiaxin Yu if (ret) {
192*125ab5d5SJiaxin Yu dev_err(afe->dev, "%s clk_set_parent %s-%s fail %d\n",
193*125ab5d5SJiaxin Yu __func__, aud_clks[CLK_TOP_MUX_AUD_2],
194*125ab5d5SJiaxin Yu aud_clks[CLK_CLK26M], ret);
195*125ab5d5SJiaxin Yu goto EXIT;
196*125ab5d5SJiaxin Yu }
197*125ab5d5SJiaxin Yu clk_disable_unprepare(afe_priv->clk[CLK_TOP_MUX_AUD_2]);
198*125ab5d5SJiaxin Yu }
199*125ab5d5SJiaxin Yu
200*125ab5d5SJiaxin Yu EXIT:
201*125ab5d5SJiaxin Yu return ret;
202*125ab5d5SJiaxin Yu }
203*125ab5d5SJiaxin Yu
mt8192_afe_enable_clock(struct mtk_base_afe * afe)204*125ab5d5SJiaxin Yu int mt8192_afe_enable_clock(struct mtk_base_afe *afe)
205*125ab5d5SJiaxin Yu {
206*125ab5d5SJiaxin Yu struct mt8192_afe_private *afe_priv = afe->platform_priv;
207*125ab5d5SJiaxin Yu int ret;
208*125ab5d5SJiaxin Yu
209*125ab5d5SJiaxin Yu ret = clk_prepare_enable(afe_priv->clk[CLK_INFRA_SYS_AUDIO]);
210*125ab5d5SJiaxin Yu if (ret) {
211*125ab5d5SJiaxin Yu dev_err(afe->dev, "%s clk_prepare_enable %s fail %d\n",
212*125ab5d5SJiaxin Yu __func__, aud_clks[CLK_INFRA_SYS_AUDIO], ret);
213*125ab5d5SJiaxin Yu goto EXIT;
214*125ab5d5SJiaxin Yu }
215*125ab5d5SJiaxin Yu
216*125ab5d5SJiaxin Yu ret = clk_prepare_enable(afe_priv->clk[CLK_INFRA_AUDIO_26M]);
217*125ab5d5SJiaxin Yu if (ret) {
218*125ab5d5SJiaxin Yu dev_err(afe->dev, "%s clk_prepare_enable %s fail %d\n",
219*125ab5d5SJiaxin Yu __func__, aud_clks[CLK_INFRA_AUDIO_26M], ret);
220*125ab5d5SJiaxin Yu goto EXIT;
221*125ab5d5SJiaxin Yu }
222*125ab5d5SJiaxin Yu
223*125ab5d5SJiaxin Yu ret = clk_prepare_enable(afe_priv->clk[CLK_MUX_AUDIO]);
224*125ab5d5SJiaxin Yu if (ret) {
225*125ab5d5SJiaxin Yu dev_err(afe->dev, "%s clk_prepare_enable %s fail %d\n",
226*125ab5d5SJiaxin Yu __func__, aud_clks[CLK_MUX_AUDIO], ret);
227*125ab5d5SJiaxin Yu goto EXIT;
228*125ab5d5SJiaxin Yu }
229*125ab5d5SJiaxin Yu ret = clk_set_parent(afe_priv->clk[CLK_MUX_AUDIO],
230*125ab5d5SJiaxin Yu afe_priv->clk[CLK_CLK26M]);
231*125ab5d5SJiaxin Yu if (ret) {
232*125ab5d5SJiaxin Yu dev_err(afe->dev, "%s clk_set_parent %s-%s fail %d\n",
233*125ab5d5SJiaxin Yu __func__, aud_clks[CLK_MUX_AUDIO],
234*125ab5d5SJiaxin Yu aud_clks[CLK_CLK26M], ret);
235*125ab5d5SJiaxin Yu goto EXIT;
236*125ab5d5SJiaxin Yu }
237*125ab5d5SJiaxin Yu
238*125ab5d5SJiaxin Yu ret = clk_prepare_enable(afe_priv->clk[CLK_MUX_AUDIOINTBUS]);
239*125ab5d5SJiaxin Yu if (ret) {
240*125ab5d5SJiaxin Yu dev_err(afe->dev, "%s clk_prepare_enable %s fail %d\n",
241*125ab5d5SJiaxin Yu __func__, aud_clks[CLK_MUX_AUDIOINTBUS], ret);
242*125ab5d5SJiaxin Yu goto EXIT;
243*125ab5d5SJiaxin Yu }
244*125ab5d5SJiaxin Yu
245*125ab5d5SJiaxin Yu ret = mt8192_set_audio_int_bus_parent(afe, CLK_CLK26M);
246*125ab5d5SJiaxin Yu if (ret) {
247*125ab5d5SJiaxin Yu dev_err(afe->dev, "%s clk_set_parent %s-%s fail %d\n",
248*125ab5d5SJiaxin Yu __func__, aud_clks[CLK_MUX_AUDIOINTBUS],
249*125ab5d5SJiaxin Yu aud_clks[CLK_CLK26M], ret);
250*125ab5d5SJiaxin Yu goto EXIT;
251*125ab5d5SJiaxin Yu }
252*125ab5d5SJiaxin Yu
253*125ab5d5SJiaxin Yu ret = clk_set_parent(afe_priv->clk[CLK_TOP_MUX_AUDIO_H],
254*125ab5d5SJiaxin Yu afe_priv->clk[CLK_TOP_APLL2_CK]);
255*125ab5d5SJiaxin Yu if (ret) {
256*125ab5d5SJiaxin Yu dev_err(afe->dev, "%s clk_set_parent %s-%s fail %d\n",
257*125ab5d5SJiaxin Yu __func__, aud_clks[CLK_TOP_MUX_AUDIO_H],
258*125ab5d5SJiaxin Yu aud_clks[CLK_TOP_APLL2_CK], ret);
259*125ab5d5SJiaxin Yu goto EXIT;
260*125ab5d5SJiaxin Yu }
261*125ab5d5SJiaxin Yu
262*125ab5d5SJiaxin Yu ret = clk_prepare_enable(afe_priv->clk[CLK_AFE]);
263*125ab5d5SJiaxin Yu if (ret) {
264*125ab5d5SJiaxin Yu dev_err(afe->dev, "%s clk_prepare_enable %s fail %d\n",
265*125ab5d5SJiaxin Yu __func__, aud_clks[CLK_AFE], ret);
266*125ab5d5SJiaxin Yu goto EXIT;
267*125ab5d5SJiaxin Yu }
268*125ab5d5SJiaxin Yu
269*125ab5d5SJiaxin Yu EXIT:
270*125ab5d5SJiaxin Yu return ret;
271*125ab5d5SJiaxin Yu }
272*125ab5d5SJiaxin Yu
mt8192_afe_disable_clock(struct mtk_base_afe * afe)273*125ab5d5SJiaxin Yu void mt8192_afe_disable_clock(struct mtk_base_afe *afe)
274*125ab5d5SJiaxin Yu {
275*125ab5d5SJiaxin Yu struct mt8192_afe_private *afe_priv = afe->platform_priv;
276*125ab5d5SJiaxin Yu
277*125ab5d5SJiaxin Yu clk_disable_unprepare(afe_priv->clk[CLK_AFE]);
278*125ab5d5SJiaxin Yu mt8192_set_audio_int_bus_parent(afe, CLK_CLK26M);
279*125ab5d5SJiaxin Yu clk_disable_unprepare(afe_priv->clk[CLK_MUX_AUDIOINTBUS]);
280*125ab5d5SJiaxin Yu clk_disable_unprepare(afe_priv->clk[CLK_MUX_AUDIO]);
281*125ab5d5SJiaxin Yu clk_disable_unprepare(afe_priv->clk[CLK_INFRA_AUDIO_26M]);
282*125ab5d5SJiaxin Yu clk_disable_unprepare(afe_priv->clk[CLK_INFRA_SYS_AUDIO]);
283*125ab5d5SJiaxin Yu }
284*125ab5d5SJiaxin Yu
mt8192_apll1_enable(struct mtk_base_afe * afe)285*125ab5d5SJiaxin Yu int mt8192_apll1_enable(struct mtk_base_afe *afe)
286*125ab5d5SJiaxin Yu {
287*125ab5d5SJiaxin Yu struct mt8192_afe_private *afe_priv = afe->platform_priv;
288*125ab5d5SJiaxin Yu int ret;
289*125ab5d5SJiaxin Yu
290*125ab5d5SJiaxin Yu /* setting for APLL */
291*125ab5d5SJiaxin Yu apll1_mux_setting(afe, true);
292*125ab5d5SJiaxin Yu
293*125ab5d5SJiaxin Yu ret = clk_prepare_enable(afe_priv->clk[CLK_APLL22M]);
294*125ab5d5SJiaxin Yu if (ret) {
295*125ab5d5SJiaxin Yu dev_err(afe->dev, "%s clk_prepare_enable %s fail %d\n",
296*125ab5d5SJiaxin Yu __func__, aud_clks[CLK_APLL22M], ret);
297*125ab5d5SJiaxin Yu goto EXIT;
298*125ab5d5SJiaxin Yu }
299*125ab5d5SJiaxin Yu
300*125ab5d5SJiaxin Yu ret = clk_prepare_enable(afe_priv->clk[CLK_APLL1_TUNER]);
301*125ab5d5SJiaxin Yu if (ret) {
302*125ab5d5SJiaxin Yu dev_err(afe->dev, "%s clk_prepare_enable %s fail %d\n",
303*125ab5d5SJiaxin Yu __func__, aud_clks[CLK_APLL1_TUNER], ret);
304*125ab5d5SJiaxin Yu goto EXIT;
305*125ab5d5SJiaxin Yu }
306*125ab5d5SJiaxin Yu
307*125ab5d5SJiaxin Yu regmap_update_bits(afe->regmap, AFE_APLL1_TUNER_CFG,
308*125ab5d5SJiaxin Yu 0x0000FFF7, 0x00000832);
309*125ab5d5SJiaxin Yu regmap_update_bits(afe->regmap, AFE_APLL1_TUNER_CFG, 0x1, 0x1);
310*125ab5d5SJiaxin Yu
311*125ab5d5SJiaxin Yu regmap_update_bits(afe->regmap, AFE_HD_ENGEN_ENABLE,
312*125ab5d5SJiaxin Yu AFE_22M_ON_MASK_SFT,
313*125ab5d5SJiaxin Yu 0x1 << AFE_22M_ON_SFT);
314*125ab5d5SJiaxin Yu
315*125ab5d5SJiaxin Yu EXIT:
316*125ab5d5SJiaxin Yu return ret;
317*125ab5d5SJiaxin Yu }
318*125ab5d5SJiaxin Yu
mt8192_apll1_disable(struct mtk_base_afe * afe)319*125ab5d5SJiaxin Yu void mt8192_apll1_disable(struct mtk_base_afe *afe)
320*125ab5d5SJiaxin Yu {
321*125ab5d5SJiaxin Yu struct mt8192_afe_private *afe_priv = afe->platform_priv;
322*125ab5d5SJiaxin Yu
323*125ab5d5SJiaxin Yu regmap_update_bits(afe->regmap, AFE_HD_ENGEN_ENABLE,
324*125ab5d5SJiaxin Yu AFE_22M_ON_MASK_SFT,
325*125ab5d5SJiaxin Yu 0x0 << AFE_22M_ON_SFT);
326*125ab5d5SJiaxin Yu
327*125ab5d5SJiaxin Yu regmap_update_bits(afe->regmap, AFE_APLL1_TUNER_CFG, 0x1, 0x0);
328*125ab5d5SJiaxin Yu
329*125ab5d5SJiaxin Yu clk_disable_unprepare(afe_priv->clk[CLK_APLL1_TUNER]);
330*125ab5d5SJiaxin Yu clk_disable_unprepare(afe_priv->clk[CLK_APLL22M]);
331*125ab5d5SJiaxin Yu
332*125ab5d5SJiaxin Yu apll1_mux_setting(afe, false);
333*125ab5d5SJiaxin Yu }
334*125ab5d5SJiaxin Yu
mt8192_apll2_enable(struct mtk_base_afe * afe)335*125ab5d5SJiaxin Yu int mt8192_apll2_enable(struct mtk_base_afe *afe)
336*125ab5d5SJiaxin Yu {
337*125ab5d5SJiaxin Yu struct mt8192_afe_private *afe_priv = afe->platform_priv;
338*125ab5d5SJiaxin Yu int ret;
339*125ab5d5SJiaxin Yu
340*125ab5d5SJiaxin Yu /* setting for APLL */
341*125ab5d5SJiaxin Yu apll2_mux_setting(afe, true);
342*125ab5d5SJiaxin Yu
343*125ab5d5SJiaxin Yu ret = clk_prepare_enable(afe_priv->clk[CLK_APLL24M]);
344*125ab5d5SJiaxin Yu if (ret) {
345*125ab5d5SJiaxin Yu dev_err(afe->dev, "%s clk_prepare_enable %s fail %d\n",
346*125ab5d5SJiaxin Yu __func__, aud_clks[CLK_APLL24M], ret);
347*125ab5d5SJiaxin Yu goto EXIT;
348*125ab5d5SJiaxin Yu }
349*125ab5d5SJiaxin Yu
350*125ab5d5SJiaxin Yu ret = clk_prepare_enable(afe_priv->clk[CLK_APLL2_TUNER]);
351*125ab5d5SJiaxin Yu if (ret) {
352*125ab5d5SJiaxin Yu dev_err(afe->dev, "%s clk_prepare_enable %s fail %d\n",
353*125ab5d5SJiaxin Yu __func__, aud_clks[CLK_APLL2_TUNER], ret);
354*125ab5d5SJiaxin Yu goto EXIT;
355*125ab5d5SJiaxin Yu }
356*125ab5d5SJiaxin Yu
357*125ab5d5SJiaxin Yu regmap_update_bits(afe->regmap, AFE_APLL2_TUNER_CFG,
358*125ab5d5SJiaxin Yu 0x0000FFF7, 0x00000634);
359*125ab5d5SJiaxin Yu regmap_update_bits(afe->regmap, AFE_APLL2_TUNER_CFG, 0x1, 0x1);
360*125ab5d5SJiaxin Yu
361*125ab5d5SJiaxin Yu regmap_update_bits(afe->regmap, AFE_HD_ENGEN_ENABLE,
362*125ab5d5SJiaxin Yu AFE_24M_ON_MASK_SFT,
363*125ab5d5SJiaxin Yu 0x1 << AFE_24M_ON_SFT);
364*125ab5d5SJiaxin Yu
365*125ab5d5SJiaxin Yu EXIT:
366*125ab5d5SJiaxin Yu return ret;
367*125ab5d5SJiaxin Yu }
368*125ab5d5SJiaxin Yu
mt8192_apll2_disable(struct mtk_base_afe * afe)369*125ab5d5SJiaxin Yu void mt8192_apll2_disable(struct mtk_base_afe *afe)
370*125ab5d5SJiaxin Yu {
371*125ab5d5SJiaxin Yu struct mt8192_afe_private *afe_priv = afe->platform_priv;
372*125ab5d5SJiaxin Yu
373*125ab5d5SJiaxin Yu regmap_update_bits(afe->regmap, AFE_HD_ENGEN_ENABLE,
374*125ab5d5SJiaxin Yu AFE_24M_ON_MASK_SFT,
375*125ab5d5SJiaxin Yu 0x0 << AFE_24M_ON_SFT);
376*125ab5d5SJiaxin Yu
377*125ab5d5SJiaxin Yu regmap_update_bits(afe->regmap, AFE_APLL2_TUNER_CFG, 0x1, 0x0);
378*125ab5d5SJiaxin Yu
379*125ab5d5SJiaxin Yu clk_disable_unprepare(afe_priv->clk[CLK_APLL2_TUNER]);
380*125ab5d5SJiaxin Yu clk_disable_unprepare(afe_priv->clk[CLK_APLL24M]);
381*125ab5d5SJiaxin Yu
382*125ab5d5SJiaxin Yu apll2_mux_setting(afe, false);
383*125ab5d5SJiaxin Yu }
384*125ab5d5SJiaxin Yu
mt8192_get_apll_rate(struct mtk_base_afe * afe,int apll)385*125ab5d5SJiaxin Yu int mt8192_get_apll_rate(struct mtk_base_afe *afe, int apll)
386*125ab5d5SJiaxin Yu {
387*125ab5d5SJiaxin Yu return (apll == MT8192_APLL1) ? 180633600 : 196608000;
388*125ab5d5SJiaxin Yu }
389*125ab5d5SJiaxin Yu
mt8192_get_apll_by_rate(struct mtk_base_afe * afe,int rate)390*125ab5d5SJiaxin Yu int mt8192_get_apll_by_rate(struct mtk_base_afe *afe, int rate)
391*125ab5d5SJiaxin Yu {
392*125ab5d5SJiaxin Yu return ((rate % 8000) == 0) ? MT8192_APLL2 : MT8192_APLL1;
393*125ab5d5SJiaxin Yu }
394*125ab5d5SJiaxin Yu
mt8192_get_apll_by_name(struct mtk_base_afe * afe,const char * name)395*125ab5d5SJiaxin Yu int mt8192_get_apll_by_name(struct mtk_base_afe *afe, const char *name)
396*125ab5d5SJiaxin Yu {
397*125ab5d5SJiaxin Yu if (strcmp(name, APLL1_W_NAME) == 0)
398*125ab5d5SJiaxin Yu return MT8192_APLL1;
399*125ab5d5SJiaxin Yu else
400*125ab5d5SJiaxin Yu return MT8192_APLL2;
401*125ab5d5SJiaxin Yu }
402*125ab5d5SJiaxin Yu
403*125ab5d5SJiaxin Yu /* mck */
404*125ab5d5SJiaxin Yu struct mt8192_mck_div {
405*125ab5d5SJiaxin Yu int m_sel_id;
406*125ab5d5SJiaxin Yu int div_clk_id;
407*125ab5d5SJiaxin Yu /* below will be deprecated */
408*125ab5d5SJiaxin Yu int div_pdn_reg;
409*125ab5d5SJiaxin Yu int div_pdn_mask_sft;
410*125ab5d5SJiaxin Yu int div_reg;
411*125ab5d5SJiaxin Yu int div_mask_sft;
412*125ab5d5SJiaxin Yu int div_mask;
413*125ab5d5SJiaxin Yu int div_sft;
414*125ab5d5SJiaxin Yu int div_apll_sel_reg;
415*125ab5d5SJiaxin Yu int div_apll_sel_mask_sft;
416*125ab5d5SJiaxin Yu int div_apll_sel_sft;
417*125ab5d5SJiaxin Yu };
418*125ab5d5SJiaxin Yu
419*125ab5d5SJiaxin Yu static const struct mt8192_mck_div mck_div[MT8192_MCK_NUM] = {
420*125ab5d5SJiaxin Yu [MT8192_I2S0_MCK] = {
421*125ab5d5SJiaxin Yu .m_sel_id = CLK_TOP_I2S0_M_SEL,
422*125ab5d5SJiaxin Yu .div_clk_id = CLK_TOP_APLL12_DIV0,
423*125ab5d5SJiaxin Yu .div_pdn_reg = CLK_AUDDIV_0,
424*125ab5d5SJiaxin Yu .div_pdn_mask_sft = APLL12_DIV0_PDN_MASK_SFT,
425*125ab5d5SJiaxin Yu .div_reg = CLK_AUDDIV_2,
426*125ab5d5SJiaxin Yu .div_mask_sft = APLL12_CK_DIV0_MASK_SFT,
427*125ab5d5SJiaxin Yu .div_mask = APLL12_CK_DIV0_MASK,
428*125ab5d5SJiaxin Yu .div_sft = APLL12_CK_DIV0_SFT,
429*125ab5d5SJiaxin Yu .div_apll_sel_reg = CLK_AUDDIV_0,
430*125ab5d5SJiaxin Yu .div_apll_sel_mask_sft = APLL_I2S0_MCK_SEL_MASK_SFT,
431*125ab5d5SJiaxin Yu .div_apll_sel_sft = APLL_I2S0_MCK_SEL_SFT,
432*125ab5d5SJiaxin Yu },
433*125ab5d5SJiaxin Yu [MT8192_I2S1_MCK] = {
434*125ab5d5SJiaxin Yu .m_sel_id = CLK_TOP_I2S1_M_SEL,
435*125ab5d5SJiaxin Yu .div_clk_id = CLK_TOP_APLL12_DIV1,
436*125ab5d5SJiaxin Yu .div_pdn_reg = CLK_AUDDIV_0,
437*125ab5d5SJiaxin Yu .div_pdn_mask_sft = APLL12_DIV1_PDN_MASK_SFT,
438*125ab5d5SJiaxin Yu .div_reg = CLK_AUDDIV_2,
439*125ab5d5SJiaxin Yu .div_mask_sft = APLL12_CK_DIV1_MASK_SFT,
440*125ab5d5SJiaxin Yu .div_mask = APLL12_CK_DIV1_MASK,
441*125ab5d5SJiaxin Yu .div_sft = APLL12_CK_DIV1_SFT,
442*125ab5d5SJiaxin Yu .div_apll_sel_reg = CLK_AUDDIV_0,
443*125ab5d5SJiaxin Yu .div_apll_sel_mask_sft = APLL_I2S1_MCK_SEL_MASK_SFT,
444*125ab5d5SJiaxin Yu .div_apll_sel_sft = APLL_I2S1_MCK_SEL_SFT,
445*125ab5d5SJiaxin Yu },
446*125ab5d5SJiaxin Yu [MT8192_I2S2_MCK] = {
447*125ab5d5SJiaxin Yu .m_sel_id = CLK_TOP_I2S2_M_SEL,
448*125ab5d5SJiaxin Yu .div_clk_id = CLK_TOP_APLL12_DIV2,
449*125ab5d5SJiaxin Yu .div_pdn_reg = CLK_AUDDIV_0,
450*125ab5d5SJiaxin Yu .div_pdn_mask_sft = APLL12_DIV2_PDN_MASK_SFT,
451*125ab5d5SJiaxin Yu .div_reg = CLK_AUDDIV_2,
452*125ab5d5SJiaxin Yu .div_mask_sft = APLL12_CK_DIV2_MASK_SFT,
453*125ab5d5SJiaxin Yu .div_mask = APLL12_CK_DIV2_MASK,
454*125ab5d5SJiaxin Yu .div_sft = APLL12_CK_DIV2_SFT,
455*125ab5d5SJiaxin Yu .div_apll_sel_reg = CLK_AUDDIV_0,
456*125ab5d5SJiaxin Yu .div_apll_sel_mask_sft = APLL_I2S2_MCK_SEL_MASK_SFT,
457*125ab5d5SJiaxin Yu .div_apll_sel_sft = APLL_I2S2_MCK_SEL_SFT,
458*125ab5d5SJiaxin Yu },
459*125ab5d5SJiaxin Yu [MT8192_I2S3_MCK] = {
460*125ab5d5SJiaxin Yu .m_sel_id = CLK_TOP_I2S3_M_SEL,
461*125ab5d5SJiaxin Yu .div_clk_id = CLK_TOP_APLL12_DIV3,
462*125ab5d5SJiaxin Yu .div_pdn_reg = CLK_AUDDIV_0,
463*125ab5d5SJiaxin Yu .div_pdn_mask_sft = APLL12_DIV3_PDN_MASK_SFT,
464*125ab5d5SJiaxin Yu .div_reg = CLK_AUDDIV_2,
465*125ab5d5SJiaxin Yu .div_mask_sft = APLL12_CK_DIV3_MASK_SFT,
466*125ab5d5SJiaxin Yu .div_mask = APLL12_CK_DIV3_MASK,
467*125ab5d5SJiaxin Yu .div_sft = APLL12_CK_DIV3_SFT,
468*125ab5d5SJiaxin Yu .div_apll_sel_reg = CLK_AUDDIV_0,
469*125ab5d5SJiaxin Yu .div_apll_sel_mask_sft = APLL_I2S3_MCK_SEL_MASK_SFT,
470*125ab5d5SJiaxin Yu .div_apll_sel_sft = APLL_I2S3_MCK_SEL_SFT,
471*125ab5d5SJiaxin Yu },
472*125ab5d5SJiaxin Yu [MT8192_I2S4_MCK] = {
473*125ab5d5SJiaxin Yu .m_sel_id = CLK_TOP_I2S4_M_SEL,
474*125ab5d5SJiaxin Yu .div_clk_id = CLK_TOP_APLL12_DIV4,
475*125ab5d5SJiaxin Yu .div_pdn_reg = CLK_AUDDIV_0,
476*125ab5d5SJiaxin Yu .div_pdn_mask_sft = APLL12_DIV4_PDN_MASK_SFT,
477*125ab5d5SJiaxin Yu .div_reg = CLK_AUDDIV_3,
478*125ab5d5SJiaxin Yu .div_mask_sft = APLL12_CK_DIV4_MASK_SFT,
479*125ab5d5SJiaxin Yu .div_mask = APLL12_CK_DIV4_MASK,
480*125ab5d5SJiaxin Yu .div_sft = APLL12_CK_DIV4_SFT,
481*125ab5d5SJiaxin Yu .div_apll_sel_reg = CLK_AUDDIV_0,
482*125ab5d5SJiaxin Yu .div_apll_sel_mask_sft = APLL_I2S4_MCK_SEL_MASK_SFT,
483*125ab5d5SJiaxin Yu .div_apll_sel_sft = APLL_I2S4_MCK_SEL_SFT,
484*125ab5d5SJiaxin Yu },
485*125ab5d5SJiaxin Yu [MT8192_I2S4_BCK] = {
486*125ab5d5SJiaxin Yu .m_sel_id = -1,
487*125ab5d5SJiaxin Yu .div_clk_id = CLK_TOP_APLL12_DIVB,
488*125ab5d5SJiaxin Yu .div_pdn_reg = CLK_AUDDIV_0,
489*125ab5d5SJiaxin Yu .div_pdn_mask_sft = APLL12_DIVB_PDN_MASK_SFT,
490*125ab5d5SJiaxin Yu .div_reg = CLK_AUDDIV_2,
491*125ab5d5SJiaxin Yu .div_mask_sft = APLL12_CK_DIVB_MASK_SFT,
492*125ab5d5SJiaxin Yu .div_mask = APLL12_CK_DIVB_MASK,
493*125ab5d5SJiaxin Yu .div_sft = APLL12_CK_DIVB_SFT,
494*125ab5d5SJiaxin Yu },
495*125ab5d5SJiaxin Yu [MT8192_I2S5_MCK] = {
496*125ab5d5SJiaxin Yu .m_sel_id = CLK_TOP_I2S5_M_SEL,
497*125ab5d5SJiaxin Yu .div_clk_id = CLK_TOP_APLL12_DIV5,
498*125ab5d5SJiaxin Yu .div_pdn_reg = CLK_AUDDIV_0,
499*125ab5d5SJiaxin Yu .div_pdn_mask_sft = APLL12_DIV5_PDN_MASK_SFT,
500*125ab5d5SJiaxin Yu .div_reg = CLK_AUDDIV_3,
501*125ab5d5SJiaxin Yu .div_mask_sft = APLL12_CK_DIV5_MASK_SFT,
502*125ab5d5SJiaxin Yu .div_mask = APLL12_CK_DIV5_MASK,
503*125ab5d5SJiaxin Yu .div_sft = APLL12_CK_DIV5_SFT,
504*125ab5d5SJiaxin Yu .div_apll_sel_reg = CLK_AUDDIV_0,
505*125ab5d5SJiaxin Yu .div_apll_sel_mask_sft = APLL_I2S5_MCK_SEL_MASK_SFT,
506*125ab5d5SJiaxin Yu .div_apll_sel_sft = APLL_I2S5_MCK_SEL_SFT,
507*125ab5d5SJiaxin Yu },
508*125ab5d5SJiaxin Yu [MT8192_I2S6_MCK] = {
509*125ab5d5SJiaxin Yu .m_sel_id = CLK_TOP_I2S6_M_SEL,
510*125ab5d5SJiaxin Yu .div_clk_id = CLK_TOP_APLL12_DIV6,
511*125ab5d5SJiaxin Yu .div_pdn_reg = CLK_AUDDIV_0,
512*125ab5d5SJiaxin Yu .div_pdn_mask_sft = APLL12_DIV6_PDN_MASK_SFT,
513*125ab5d5SJiaxin Yu .div_reg = CLK_AUDDIV_3,
514*125ab5d5SJiaxin Yu .div_mask_sft = APLL12_CK_DIV6_MASK_SFT,
515*125ab5d5SJiaxin Yu .div_mask = APLL12_CK_DIV6_MASK,
516*125ab5d5SJiaxin Yu .div_sft = APLL12_CK_DIV6_SFT,
517*125ab5d5SJiaxin Yu .div_apll_sel_reg = CLK_AUDDIV_0,
518*125ab5d5SJiaxin Yu .div_apll_sel_mask_sft = APLL_I2S6_MCK_SEL_MASK_SFT,
519*125ab5d5SJiaxin Yu .div_apll_sel_sft = APLL_I2S6_MCK_SEL_SFT,
520*125ab5d5SJiaxin Yu },
521*125ab5d5SJiaxin Yu [MT8192_I2S7_MCK] = {
522*125ab5d5SJiaxin Yu .m_sel_id = CLK_TOP_I2S7_M_SEL,
523*125ab5d5SJiaxin Yu .div_clk_id = CLK_TOP_APLL12_DIV7,
524*125ab5d5SJiaxin Yu .div_pdn_reg = CLK_AUDDIV_0,
525*125ab5d5SJiaxin Yu .div_pdn_mask_sft = APLL12_DIV7_PDN_MASK_SFT,
526*125ab5d5SJiaxin Yu .div_reg = CLK_AUDDIV_4,
527*125ab5d5SJiaxin Yu .div_mask_sft = APLL12_CK_DIV7_MASK_SFT,
528*125ab5d5SJiaxin Yu .div_mask = APLL12_CK_DIV7_MASK,
529*125ab5d5SJiaxin Yu .div_sft = APLL12_CK_DIV7_SFT,
530*125ab5d5SJiaxin Yu .div_apll_sel_reg = CLK_AUDDIV_0,
531*125ab5d5SJiaxin Yu .div_apll_sel_mask_sft = APLL_I2S7_MCK_SEL_MASK_SFT,
532*125ab5d5SJiaxin Yu .div_apll_sel_sft = APLL_I2S7_MCK_SEL_SFT,
533*125ab5d5SJiaxin Yu },
534*125ab5d5SJiaxin Yu [MT8192_I2S8_MCK] = {
535*125ab5d5SJiaxin Yu .m_sel_id = CLK_TOP_I2S8_M_SEL,
536*125ab5d5SJiaxin Yu .div_clk_id = CLK_TOP_APLL12_DIV8,
537*125ab5d5SJiaxin Yu .div_pdn_reg = CLK_AUDDIV_0,
538*125ab5d5SJiaxin Yu .div_pdn_mask_sft = APLL12_DIV8_PDN_MASK_SFT,
539*125ab5d5SJiaxin Yu .div_reg = CLK_AUDDIV_4,
540*125ab5d5SJiaxin Yu .div_mask_sft = APLL12_CK_DIV8_MASK_SFT,
541*125ab5d5SJiaxin Yu .div_mask = APLL12_CK_DIV8_MASK,
542*125ab5d5SJiaxin Yu .div_sft = APLL12_CK_DIV8_SFT,
543*125ab5d5SJiaxin Yu .div_apll_sel_reg = CLK_AUDDIV_0,
544*125ab5d5SJiaxin Yu .div_apll_sel_mask_sft = APLL_I2S8_MCK_SEL_MASK_SFT,
545*125ab5d5SJiaxin Yu .div_apll_sel_sft = APLL_I2S8_MCK_SEL_SFT,
546*125ab5d5SJiaxin Yu },
547*125ab5d5SJiaxin Yu [MT8192_I2S9_MCK] = {
548*125ab5d5SJiaxin Yu .m_sel_id = CLK_TOP_I2S9_M_SEL,
549*125ab5d5SJiaxin Yu .div_clk_id = CLK_TOP_APLL12_DIV9,
550*125ab5d5SJiaxin Yu .div_pdn_reg = CLK_AUDDIV_0,
551*125ab5d5SJiaxin Yu .div_pdn_mask_sft = APLL12_DIV9_PDN_MASK_SFT,
552*125ab5d5SJiaxin Yu .div_reg = CLK_AUDDIV_4,
553*125ab5d5SJiaxin Yu .div_mask_sft = APLL12_CK_DIV9_MASK_SFT,
554*125ab5d5SJiaxin Yu .div_mask = APLL12_CK_DIV9_MASK,
555*125ab5d5SJiaxin Yu .div_sft = APLL12_CK_DIV9_SFT,
556*125ab5d5SJiaxin Yu .div_apll_sel_reg = CLK_AUDDIV_0,
557*125ab5d5SJiaxin Yu .div_apll_sel_mask_sft = APLL_I2S9_MCK_SEL_MASK_SFT,
558*125ab5d5SJiaxin Yu .div_apll_sel_sft = APLL_I2S9_MCK_SEL_SFT,
559*125ab5d5SJiaxin Yu },
560*125ab5d5SJiaxin Yu };
561*125ab5d5SJiaxin Yu
mt8192_mck_enable(struct mtk_base_afe * afe,int mck_id,int rate)562*125ab5d5SJiaxin Yu int mt8192_mck_enable(struct mtk_base_afe *afe, int mck_id, int rate)
563*125ab5d5SJiaxin Yu {
564*125ab5d5SJiaxin Yu struct mt8192_afe_private *afe_priv = afe->platform_priv;
565*125ab5d5SJiaxin Yu int apll = mt8192_get_apll_by_rate(afe, rate);
566*125ab5d5SJiaxin Yu int apll_clk_id = apll == MT8192_APLL1 ?
567*125ab5d5SJiaxin Yu CLK_TOP_MUX_AUD_1 : CLK_TOP_MUX_AUD_2;
568*125ab5d5SJiaxin Yu int m_sel_id = mck_div[mck_id].m_sel_id;
569*125ab5d5SJiaxin Yu int div_clk_id = mck_div[mck_id].div_clk_id;
570*125ab5d5SJiaxin Yu int ret;
571*125ab5d5SJiaxin Yu
572*125ab5d5SJiaxin Yu /* select apll */
573*125ab5d5SJiaxin Yu if (m_sel_id >= 0) {
574*125ab5d5SJiaxin Yu ret = clk_prepare_enable(afe_priv->clk[m_sel_id]);
575*125ab5d5SJiaxin Yu if (ret) {
576*125ab5d5SJiaxin Yu dev_err(afe->dev, "%s(), clk_prepare_enable %s fail %d\n",
577*125ab5d5SJiaxin Yu __func__, aud_clks[m_sel_id], ret);
578*125ab5d5SJiaxin Yu return ret;
579*125ab5d5SJiaxin Yu }
580*125ab5d5SJiaxin Yu ret = clk_set_parent(afe_priv->clk[m_sel_id],
581*125ab5d5SJiaxin Yu afe_priv->clk[apll_clk_id]);
582*125ab5d5SJiaxin Yu if (ret) {
583*125ab5d5SJiaxin Yu dev_err(afe->dev, "%s(), clk_set_parent %s-%s fail %d\n",
584*125ab5d5SJiaxin Yu __func__, aud_clks[m_sel_id],
585*125ab5d5SJiaxin Yu aud_clks[apll_clk_id], ret);
586*125ab5d5SJiaxin Yu return ret;
587*125ab5d5SJiaxin Yu }
588*125ab5d5SJiaxin Yu }
589*125ab5d5SJiaxin Yu
590*125ab5d5SJiaxin Yu /* enable div, set rate */
591*125ab5d5SJiaxin Yu ret = clk_prepare_enable(afe_priv->clk[div_clk_id]);
592*125ab5d5SJiaxin Yu if (ret) {
593*125ab5d5SJiaxin Yu dev_err(afe->dev, "%s(), clk_prepare_enable %s fail %d\n",
594*125ab5d5SJiaxin Yu __func__, aud_clks[div_clk_id], ret);
595*125ab5d5SJiaxin Yu return ret;
596*125ab5d5SJiaxin Yu }
597*125ab5d5SJiaxin Yu ret = clk_set_rate(afe_priv->clk[div_clk_id], rate);
598*125ab5d5SJiaxin Yu if (ret) {
599*125ab5d5SJiaxin Yu dev_err(afe->dev, "%s(), clk_set_rate %s, rate %d, fail %d\n",
600*125ab5d5SJiaxin Yu __func__, aud_clks[div_clk_id],
601*125ab5d5SJiaxin Yu rate, ret);
602*125ab5d5SJiaxin Yu return ret;
603*125ab5d5SJiaxin Yu }
604*125ab5d5SJiaxin Yu
605*125ab5d5SJiaxin Yu return 0;
606*125ab5d5SJiaxin Yu }
607*125ab5d5SJiaxin Yu
mt8192_mck_disable(struct mtk_base_afe * afe,int mck_id)608*125ab5d5SJiaxin Yu void mt8192_mck_disable(struct mtk_base_afe *afe, int mck_id)
609*125ab5d5SJiaxin Yu {
610*125ab5d5SJiaxin Yu struct mt8192_afe_private *afe_priv = afe->platform_priv;
611*125ab5d5SJiaxin Yu int m_sel_id = mck_div[mck_id].m_sel_id;
612*125ab5d5SJiaxin Yu int div_clk_id = mck_div[mck_id].div_clk_id;
613*125ab5d5SJiaxin Yu
614*125ab5d5SJiaxin Yu clk_disable_unprepare(afe_priv->clk[div_clk_id]);
615*125ab5d5SJiaxin Yu if (m_sel_id >= 0)
616*125ab5d5SJiaxin Yu clk_disable_unprepare(afe_priv->clk[m_sel_id]);
617*125ab5d5SJiaxin Yu }
618*125ab5d5SJiaxin Yu
mt8192_init_clock(struct mtk_base_afe * afe)619*125ab5d5SJiaxin Yu int mt8192_init_clock(struct mtk_base_afe *afe)
620*125ab5d5SJiaxin Yu {
621*125ab5d5SJiaxin Yu struct mt8192_afe_private *afe_priv = afe->platform_priv;
622*125ab5d5SJiaxin Yu struct device_node *of_node = afe->dev->of_node;
623*125ab5d5SJiaxin Yu int i = 0;
624*125ab5d5SJiaxin Yu
625*125ab5d5SJiaxin Yu afe_priv->clk = devm_kcalloc(afe->dev, CLK_NUM, sizeof(*afe_priv->clk),
626*125ab5d5SJiaxin Yu GFP_KERNEL);
627*125ab5d5SJiaxin Yu if (!afe_priv->clk)
628*125ab5d5SJiaxin Yu return -ENOMEM;
629*125ab5d5SJiaxin Yu
630*125ab5d5SJiaxin Yu for (i = 0; i < CLK_NUM; i++) {
631*125ab5d5SJiaxin Yu afe_priv->clk[i] = devm_clk_get(afe->dev, aud_clks[i]);
632*125ab5d5SJiaxin Yu if (IS_ERR(afe_priv->clk[i])) {
633*125ab5d5SJiaxin Yu dev_warn(afe->dev, "%s devm_clk_get %s fail, ret %ld\n",
634*125ab5d5SJiaxin Yu __func__,
635*125ab5d5SJiaxin Yu aud_clks[i], PTR_ERR(afe_priv->clk[i]));
636*125ab5d5SJiaxin Yu afe_priv->clk[i] = NULL;
637*125ab5d5SJiaxin Yu }
638*125ab5d5SJiaxin Yu }
639*125ab5d5SJiaxin Yu
640*125ab5d5SJiaxin Yu afe_priv->apmixedsys = syscon_regmap_lookup_by_phandle(of_node,
641*125ab5d5SJiaxin Yu "mediatek,apmixedsys");
642*125ab5d5SJiaxin Yu if (IS_ERR(afe_priv->apmixedsys)) {
643*125ab5d5SJiaxin Yu dev_err(afe->dev, "%s() Cannot find apmixedsys controller: %ld\n",
644*125ab5d5SJiaxin Yu __func__, PTR_ERR(afe_priv->apmixedsys));
645*125ab5d5SJiaxin Yu return PTR_ERR(afe_priv->apmixedsys);
646*125ab5d5SJiaxin Yu }
647*125ab5d5SJiaxin Yu
648*125ab5d5SJiaxin Yu afe_priv->topckgen = syscon_regmap_lookup_by_phandle(of_node,
649*125ab5d5SJiaxin Yu "mediatek,topckgen");
650*125ab5d5SJiaxin Yu if (IS_ERR(afe_priv->topckgen)) {
651*125ab5d5SJiaxin Yu dev_err(afe->dev, "%s() Cannot find topckgen controller: %ld\n",
652*125ab5d5SJiaxin Yu __func__, PTR_ERR(afe_priv->topckgen));
653*125ab5d5SJiaxin Yu return PTR_ERR(afe_priv->topckgen);
654*125ab5d5SJiaxin Yu }
655*125ab5d5SJiaxin Yu
656*125ab5d5SJiaxin Yu afe_priv->infracfg = syscon_regmap_lookup_by_phandle(of_node,
657*125ab5d5SJiaxin Yu "mediatek,infracfg");
658*125ab5d5SJiaxin Yu if (IS_ERR(afe_priv->infracfg)) {
659*125ab5d5SJiaxin Yu dev_err(afe->dev, "%s() Cannot find infracfg: %ld\n",
660*125ab5d5SJiaxin Yu __func__, PTR_ERR(afe_priv->infracfg));
661*125ab5d5SJiaxin Yu return PTR_ERR(afe_priv->infracfg);
662*125ab5d5SJiaxin Yu }
663*125ab5d5SJiaxin Yu
664*125ab5d5SJiaxin Yu return 0;
665*125ab5d5SJiaxin Yu }
666