1 // SPDX-License-Identifier: GPL-2.0
3 * mt8195-afe-clk.c -- Mediatek 8195 afe clock ctrl
5 * Copyright (c) 2021 MediaTek Inc.
6 * Author: Bicycle Tsai <bicycle.tsai@mediatek.com>
7 * Trevor Wu <trevor.wu@mediatek.com>
10 #include <linux/clk.h>
12 #include "mt8195-afe-common.h"
13 #include "mt8195-afe-clk.h"
14 #include "mt8195-reg.h"
15 #include "mt8195-audsys-clk.h"
17 static const char *aud_clks
[MT8195_CLK_NUM
] = {
19 [MT8195_CLK_XTAL_26M
] = "clk26m",
21 [MT8195_CLK_TOP_APLL1
] = "apll1_ck",
22 [MT8195_CLK_TOP_APLL2
] = "apll2_ck",
23 [MT8195_CLK_TOP_APLL12_DIV0
] = "apll12_div0",
24 [MT8195_CLK_TOP_APLL12_DIV1
] = "apll12_div1",
25 [MT8195_CLK_TOP_APLL12_DIV2
] = "apll12_div2",
26 [MT8195_CLK_TOP_APLL12_DIV3
] = "apll12_div3",
27 [MT8195_CLK_TOP_APLL12_DIV9
] = "apll12_div9",
29 [MT8195_CLK_TOP_A1SYS_HP_SEL
] = "a1sys_hp_sel",
30 [MT8195_CLK_TOP_AUD_INTBUS_SEL
] = "aud_intbus_sel",
31 [MT8195_CLK_TOP_AUDIO_H_SEL
] = "audio_h_sel",
32 [MT8195_CLK_TOP_AUDIO_LOCAL_BUS_SEL
] = "audio_local_bus_sel",
33 [MT8195_CLK_TOP_DPTX_M_SEL
] = "dptx_m_sel",
34 [MT8195_CLK_TOP_I2SO1_M_SEL
] = "i2so1_m_sel",
35 [MT8195_CLK_TOP_I2SO2_M_SEL
] = "i2so2_m_sel",
36 [MT8195_CLK_TOP_I2SI1_M_SEL
] = "i2si1_m_sel",
37 [MT8195_CLK_TOP_I2SI2_M_SEL
] = "i2si2_m_sel",
39 [MT8195_CLK_INFRA_AO_AUDIO_26M_B
] = "infra_ao_audio_26m_b",
40 [MT8195_CLK_SCP_ADSP_AUDIODSP
] = "scp_adsp_audiodsp",
42 [MT8195_CLK_AUD_AFE
] = "aud_afe",
43 [MT8195_CLK_AUD_APLL1_TUNER
] = "aud_apll1_tuner",
44 [MT8195_CLK_AUD_APLL2_TUNER
] = "aud_apll2_tuner",
45 [MT8195_CLK_AUD_APLL
] = "aud_apll",
46 [MT8195_CLK_AUD_APLL2
] = "aud_apll2",
47 [MT8195_CLK_AUD_DAC
] = "aud_dac",
48 [MT8195_CLK_AUD_ADC
] = "aud_adc",
49 [MT8195_CLK_AUD_DAC_HIRES
] = "aud_dac_hires",
50 [MT8195_CLK_AUD_A1SYS_HP
] = "aud_a1sys_hp",
51 [MT8195_CLK_AUD_ADC_HIRES
] = "aud_adc_hires",
52 [MT8195_CLK_AUD_ADDA6_ADC
] = "aud_adda6_adc",
53 [MT8195_CLK_AUD_ADDA6_ADC_HIRES
] = "aud_adda6_adc_hires",
54 [MT8195_CLK_AUD_I2SIN
] = "aud_i2sin",
55 [MT8195_CLK_AUD_TDM_IN
] = "aud_tdm_in",
56 [MT8195_CLK_AUD_I2S_OUT
] = "aud_i2s_out",
57 [MT8195_CLK_AUD_TDM_OUT
] = "aud_tdm_out",
58 [MT8195_CLK_AUD_HDMI_OUT
] = "aud_hdmi_out",
59 [MT8195_CLK_AUD_ASRC11
] = "aud_asrc11",
60 [MT8195_CLK_AUD_ASRC12
] = "aud_asrc12",
61 [MT8195_CLK_AUD_A1SYS
] = "aud_a1sys",
62 [MT8195_CLK_AUD_A2SYS
] = "aud_a2sys",
63 [MT8195_CLK_AUD_PCMIF
] = "aud_pcmif",
64 [MT8195_CLK_AUD_MEMIF_UL1
] = "aud_memif_ul1",
65 [MT8195_CLK_AUD_MEMIF_UL2
] = "aud_memif_ul2",
66 [MT8195_CLK_AUD_MEMIF_UL3
] = "aud_memif_ul3",
67 [MT8195_CLK_AUD_MEMIF_UL4
] = "aud_memif_ul4",
68 [MT8195_CLK_AUD_MEMIF_UL5
] = "aud_memif_ul5",
69 [MT8195_CLK_AUD_MEMIF_UL6
] = "aud_memif_ul6",
70 [MT8195_CLK_AUD_MEMIF_UL8
] = "aud_memif_ul8",
71 [MT8195_CLK_AUD_MEMIF_UL9
] = "aud_memif_ul9",
72 [MT8195_CLK_AUD_MEMIF_UL10
] = "aud_memif_ul10",
73 [MT8195_CLK_AUD_MEMIF_DL2
] = "aud_memif_dl2",
74 [MT8195_CLK_AUD_MEMIF_DL3
] = "aud_memif_dl3",
75 [MT8195_CLK_AUD_MEMIF_DL6
] = "aud_memif_dl6",
76 [MT8195_CLK_AUD_MEMIF_DL7
] = "aud_memif_dl7",
77 [MT8195_CLK_AUD_MEMIF_DL8
] = "aud_memif_dl8",
78 [MT8195_CLK_AUD_MEMIF_DL10
] = "aud_memif_dl10",
79 [MT8195_CLK_AUD_MEMIF_DL11
] = "aud_memif_dl11",
82 struct mt8195_afe_tuner_cfg
{
85 unsigned int apll_div_shift
;
86 unsigned int apll_div_maskbit
;
87 unsigned int apll_div_default
;
89 unsigned int ref_ck_sel_shift
;
90 unsigned int ref_ck_sel_maskbit
;
91 unsigned int ref_ck_sel_default
;
93 unsigned int tuner_en_shift
;
94 unsigned int tuner_en_maskbit
;
96 unsigned int upper_bound_shift
;
97 unsigned int upper_bound_maskbit
;
98 unsigned int upper_bound_default
;
99 spinlock_t ctrl_lock
; /* lock for apll tuner ctrl*/
103 static struct mt8195_afe_tuner_cfg mt8195_afe_tuner_cfgs
[MT8195_AUD_PLL_NUM
] = {
104 [MT8195_AUD_PLL1
] = {
105 .id
= MT8195_AUD_PLL1
,
106 .apll_div_reg
= AFE_APLL_TUNER_CFG
,
108 .apll_div_maskbit
= 0xf,
109 .apll_div_default
= 0x7,
110 .ref_ck_sel_reg
= AFE_APLL_TUNER_CFG
,
111 .ref_ck_sel_shift
= 1,
112 .ref_ck_sel_maskbit
= 0x3,
113 .ref_ck_sel_default
= 0x2,
114 .tuner_en_reg
= AFE_APLL_TUNER_CFG
,
116 .tuner_en_maskbit
= 0x1,
117 .upper_bound_reg
= AFE_APLL_TUNER_CFG
,
118 .upper_bound_shift
= 8,
119 .upper_bound_maskbit
= 0xff,
120 .upper_bound_default
= 0x3,
122 [MT8195_AUD_PLL2
] = {
123 .id
= MT8195_AUD_PLL2
,
124 .apll_div_reg
= AFE_APLL_TUNER_CFG1
,
126 .apll_div_maskbit
= 0xf,
127 .apll_div_default
= 0x7,
128 .ref_ck_sel_reg
= AFE_APLL_TUNER_CFG1
,
129 .ref_ck_sel_shift
= 1,
130 .ref_ck_sel_maskbit
= 0x3,
131 .ref_ck_sel_default
= 0x1,
132 .tuner_en_reg
= AFE_APLL_TUNER_CFG1
,
134 .tuner_en_maskbit
= 0x1,
135 .upper_bound_reg
= AFE_APLL_TUNER_CFG1
,
136 .upper_bound_shift
= 8,
137 .upper_bound_maskbit
= 0xff,
138 .upper_bound_default
= 0x3,
140 [MT8195_AUD_PLL3
] = {
141 .id
= MT8195_AUD_PLL3
,
142 .apll_div_reg
= AFE_EARC_APLL_TUNER_CFG
,
144 .apll_div_maskbit
= 0x3f,
145 .apll_div_default
= 0x3,
146 .ref_ck_sel_reg
= AFE_EARC_APLL_TUNER_CFG
,
147 .ref_ck_sel_shift
= 24,
148 .ref_ck_sel_maskbit
= 0x3,
149 .ref_ck_sel_default
= 0x0,
150 .tuner_en_reg
= AFE_EARC_APLL_TUNER_CFG
,
152 .tuner_en_maskbit
= 0x1,
153 .upper_bound_reg
= AFE_EARC_APLL_TUNER_CFG
,
154 .upper_bound_shift
= 12,
155 .upper_bound_maskbit
= 0xff,
156 .upper_bound_default
= 0x4,
158 [MT8195_AUD_PLL4
] = {
159 .id
= MT8195_AUD_PLL4
,
160 .apll_div_reg
= AFE_SPDIFIN_APLL_TUNER_CFG
,
162 .apll_div_maskbit
= 0x3f,
163 .apll_div_default
= 0x7,
164 .ref_ck_sel_reg
= AFE_SPDIFIN_APLL_TUNER_CFG1
,
165 .ref_ck_sel_shift
= 8,
166 .ref_ck_sel_maskbit
= 0x1,
167 .ref_ck_sel_default
= 0,
168 .tuner_en_reg
= AFE_SPDIFIN_APLL_TUNER_CFG
,
170 .tuner_en_maskbit
= 0x1,
171 .upper_bound_reg
= AFE_SPDIFIN_APLL_TUNER_CFG
,
172 .upper_bound_shift
= 12,
173 .upper_bound_maskbit
= 0xff,
174 .upper_bound_default
= 0x4,
176 [MT8195_AUD_PLL5
] = {
177 .id
= MT8195_AUD_PLL5
,
178 .apll_div_reg
= AFE_LINEIN_APLL_TUNER_CFG
,
180 .apll_div_maskbit
= 0x3f,
181 .apll_div_default
= 0x3,
182 .ref_ck_sel_reg
= AFE_LINEIN_APLL_TUNER_CFG
,
183 .ref_ck_sel_shift
= 24,
184 .ref_ck_sel_maskbit
= 0x1,
185 .ref_ck_sel_default
= 0,
186 .tuner_en_reg
= AFE_LINEIN_APLL_TUNER_CFG
,
188 .tuner_en_maskbit
= 0x1,
189 .upper_bound_reg
= AFE_LINEIN_APLL_TUNER_CFG
,
190 .upper_bound_shift
= 12,
191 .upper_bound_maskbit
= 0xff,
192 .upper_bound_default
= 0x4,
196 static struct mt8195_afe_tuner_cfg
*mt8195_afe_found_apll_tuner(unsigned int id
)
198 if (id
>= MT8195_AUD_PLL_NUM
)
201 return &mt8195_afe_tuner_cfgs
[id
];
204 static int mt8195_afe_init_apll_tuner(unsigned int id
)
206 struct mt8195_afe_tuner_cfg
*cfg
= mt8195_afe_found_apll_tuner(id
);
212 spin_lock_init(&cfg
->ctrl_lock
);
217 static int mt8195_afe_setup_apll_tuner(struct mtk_base_afe
*afe
,
220 const struct mt8195_afe_tuner_cfg
*cfg
= mt8195_afe_found_apll_tuner(id
);
225 regmap_update_bits(afe
->regmap
, cfg
->apll_div_reg
,
226 cfg
->apll_div_maskbit
<< cfg
->apll_div_shift
,
227 cfg
->apll_div_default
<< cfg
->apll_div_shift
);
229 regmap_update_bits(afe
->regmap
, cfg
->ref_ck_sel_reg
,
230 cfg
->ref_ck_sel_maskbit
<< cfg
->ref_ck_sel_shift
,
231 cfg
->ref_ck_sel_default
<< cfg
->ref_ck_sel_shift
);
233 regmap_update_bits(afe
->regmap
, cfg
->upper_bound_reg
,
234 cfg
->upper_bound_maskbit
<< cfg
->upper_bound_shift
,
235 cfg
->upper_bound_default
<< cfg
->upper_bound_shift
);
240 static int mt8195_afe_enable_tuner_clk(struct mtk_base_afe
*afe
,
243 struct mt8195_afe_private
*afe_priv
= afe
->platform_priv
;
246 case MT8195_AUD_PLL1
:
247 mt8195_afe_enable_clk(afe
, afe_priv
->clk
[MT8195_CLK_AUD_APLL
]);
248 mt8195_afe_enable_clk(afe
, afe_priv
->clk
[MT8195_CLK_AUD_APLL1_TUNER
]);
250 case MT8195_AUD_PLL2
:
251 mt8195_afe_enable_clk(afe
, afe_priv
->clk
[MT8195_CLK_AUD_APLL2
]);
252 mt8195_afe_enable_clk(afe
, afe_priv
->clk
[MT8195_CLK_AUD_APLL2_TUNER
]);
261 static int mt8195_afe_disable_tuner_clk(struct mtk_base_afe
*afe
,
264 struct mt8195_afe_private
*afe_priv
= afe
->platform_priv
;
267 case MT8195_AUD_PLL1
:
268 mt8195_afe_disable_clk(afe
, afe_priv
->clk
[MT8195_CLK_AUD_APLL1_TUNER
]);
269 mt8195_afe_disable_clk(afe
, afe_priv
->clk
[MT8195_CLK_AUD_APLL
]);
271 case MT8195_AUD_PLL2
:
272 mt8195_afe_disable_clk(afe
, afe_priv
->clk
[MT8195_CLK_AUD_APLL2_TUNER
]);
273 mt8195_afe_disable_clk(afe
, afe_priv
->clk
[MT8195_CLK_AUD_APLL2
]);
282 static int mt8195_afe_enable_apll_tuner(struct mtk_base_afe
*afe
,
285 struct mt8195_afe_tuner_cfg
*cfg
= mt8195_afe_found_apll_tuner(id
);
292 ret
= mt8195_afe_setup_apll_tuner(afe
, id
);
296 ret
= mt8195_afe_enable_tuner_clk(afe
, id
);
300 spin_lock_irqsave(&cfg
->ctrl_lock
, flags
);
303 if (cfg
->ref_cnt
== 1)
304 regmap_update_bits(afe
->regmap
,
306 cfg
->tuner_en_maskbit
<< cfg
->tuner_en_shift
,
307 1 << cfg
->tuner_en_shift
);
309 spin_unlock_irqrestore(&cfg
->ctrl_lock
, flags
);
314 static int mt8195_afe_disable_apll_tuner(struct mtk_base_afe
*afe
,
317 struct mt8195_afe_tuner_cfg
*cfg
= mt8195_afe_found_apll_tuner(id
);
324 spin_lock_irqsave(&cfg
->ctrl_lock
, flags
);
327 if (cfg
->ref_cnt
== 0)
328 regmap_update_bits(afe
->regmap
,
330 cfg
->tuner_en_maskbit
<< cfg
->tuner_en_shift
,
331 0 << cfg
->tuner_en_shift
);
332 else if (cfg
->ref_cnt
< 0)
335 spin_unlock_irqrestore(&cfg
->ctrl_lock
, flags
);
337 ret
= mt8195_afe_disable_tuner_clk(afe
, id
);
344 int mt8195_afe_get_mclk_source_clk_id(int sel
)
347 case MT8195_MCK_SEL_26M
:
348 return MT8195_CLK_XTAL_26M
;
349 case MT8195_MCK_SEL_APLL1
:
350 return MT8195_CLK_TOP_APLL1
;
351 case MT8195_MCK_SEL_APLL2
:
352 return MT8195_CLK_TOP_APLL2
;
358 int mt8195_afe_get_mclk_source_rate(struct mtk_base_afe
*afe
, int apll
)
360 struct mt8195_afe_private
*afe_priv
= afe
->platform_priv
;
361 int clk_id
= mt8195_afe_get_mclk_source_clk_id(apll
);
364 dev_dbg(afe
->dev
, "invalid clk id\n");
368 return clk_get_rate(afe_priv
->clk
[clk_id
]);
371 int mt8195_afe_get_default_mclk_source_by_rate(int rate
)
373 return ((rate
% 8000) == 0) ?
374 MT8195_MCK_SEL_APLL1
: MT8195_MCK_SEL_APLL2
;
377 int mt8195_afe_init_clock(struct mtk_base_afe
*afe
)
379 struct mt8195_afe_private
*afe_priv
= afe
->platform_priv
;
382 mt8195_audsys_clk_register(afe
);
385 devm_kcalloc(afe
->dev
, MT8195_CLK_NUM
, sizeof(*afe_priv
->clk
),
390 for (i
= 0; i
< MT8195_CLK_NUM
; i
++) {
391 afe_priv
->clk
[i
] = devm_clk_get(afe
->dev
, aud_clks
[i
]);
392 if (IS_ERR(afe_priv
->clk
[i
])) {
393 dev_dbg(afe
->dev
, "%s(), devm_clk_get %s fail, ret %ld\n",
394 __func__
, aud_clks
[i
],
395 PTR_ERR(afe_priv
->clk
[i
]));
396 return PTR_ERR(afe_priv
->clk
[i
]);
401 for (i
= 0; i
< MT8195_AUD_PLL_NUM
; i
++) {
402 ret
= mt8195_afe_init_apll_tuner(i
);
404 dev_dbg(afe
->dev
, "%s(), init apll_tuner%d failed",
413 int mt8195_afe_enable_clk(struct mtk_base_afe
*afe
, struct clk
*clk
)
418 ret
= clk_prepare_enable(clk
);
420 dev_dbg(afe
->dev
, "%s(), failed to enable clk\n",
425 dev_dbg(afe
->dev
, "NULL clk\n");
429 EXPORT_SYMBOL_GPL(mt8195_afe_enable_clk
);
431 void mt8195_afe_disable_clk(struct mtk_base_afe
*afe
, struct clk
*clk
)
434 clk_disable_unprepare(clk
);
436 dev_dbg(afe
->dev
, "NULL clk\n");
438 EXPORT_SYMBOL_GPL(mt8195_afe_disable_clk
);
440 int mt8195_afe_prepare_clk(struct mtk_base_afe
*afe
, struct clk
*clk
)
445 ret
= clk_prepare(clk
);
447 dev_dbg(afe
->dev
, "%s(), failed to prepare clk\n",
452 dev_dbg(afe
->dev
, "NULL clk\n");
457 void mt8195_afe_unprepare_clk(struct mtk_base_afe
*afe
, struct clk
*clk
)
462 dev_dbg(afe
->dev
, "NULL clk\n");
465 int mt8195_afe_enable_clk_atomic(struct mtk_base_afe
*afe
, struct clk
*clk
)
470 ret
= clk_enable(clk
);
472 dev_dbg(afe
->dev
, "%s(), failed to clk enable\n",
477 dev_dbg(afe
->dev
, "NULL clk\n");
482 void mt8195_afe_disable_clk_atomic(struct mtk_base_afe
*afe
, struct clk
*clk
)
487 dev_dbg(afe
->dev
, "NULL clk\n");
490 int mt8195_afe_set_clk_rate(struct mtk_base_afe
*afe
, struct clk
*clk
,
496 ret
= clk_set_rate(clk
, rate
);
498 dev_dbg(afe
->dev
, "%s(), failed to set clk rate\n",
507 int mt8195_afe_set_clk_parent(struct mtk_base_afe
*afe
, struct clk
*clk
,
513 ret
= clk_set_parent(clk
, parent
);
515 dev_dbg(afe
->dev
, "%s(), failed to set clk parent\n",
524 static unsigned int get_top_cg_reg(unsigned int cg_type
)
527 case MT8195_TOP_CG_A1SYS_TIMING
:
528 case MT8195_TOP_CG_A2SYS_TIMING
:
529 case MT8195_TOP_CG_26M_TIMING
:
536 static unsigned int get_top_cg_mask(unsigned int cg_type
)
539 case MT8195_TOP_CG_A1SYS_TIMING
:
540 return ASYS_TOP_CON_A1SYS_TIMING_ON
;
541 case MT8195_TOP_CG_A2SYS_TIMING
:
542 return ASYS_TOP_CON_A2SYS_TIMING_ON
;
543 case MT8195_TOP_CG_26M_TIMING
:
544 return ASYS_TOP_CON_26M_TIMING_ON
;
550 static unsigned int get_top_cg_on_val(unsigned int cg_type
)
553 case MT8195_TOP_CG_A1SYS_TIMING
:
554 case MT8195_TOP_CG_A2SYS_TIMING
:
555 case MT8195_TOP_CG_26M_TIMING
:
556 return get_top_cg_mask(cg_type
);
562 static unsigned int get_top_cg_off_val(unsigned int cg_type
)
565 case MT8195_TOP_CG_A1SYS_TIMING
:
566 case MT8195_TOP_CG_A2SYS_TIMING
:
567 case MT8195_TOP_CG_26M_TIMING
:
570 return get_top_cg_mask(cg_type
);
574 static int mt8195_afe_enable_top_cg(struct mtk_base_afe
*afe
, unsigned int cg_type
)
576 unsigned int reg
= get_top_cg_reg(cg_type
);
577 unsigned int mask
= get_top_cg_mask(cg_type
);
578 unsigned int val
= get_top_cg_on_val(cg_type
);
580 regmap_update_bits(afe
->regmap
, reg
, mask
, val
);
584 static int mt8195_afe_disable_top_cg(struct mtk_base_afe
*afe
, unsigned int cg_type
)
586 unsigned int reg
= get_top_cg_reg(cg_type
);
587 unsigned int mask
= get_top_cg_mask(cg_type
);
588 unsigned int val
= get_top_cg_off_val(cg_type
);
590 regmap_update_bits(afe
->regmap
, reg
, mask
, val
);
594 int mt8195_afe_enable_reg_rw_clk(struct mtk_base_afe
*afe
)
596 struct mt8195_afe_private
*afe_priv
= afe
->platform_priv
;
598 static const unsigned int clk_array
[] = {
599 MT8195_CLK_SCP_ADSP_AUDIODSP
, /* bus clock for infra */
600 MT8195_CLK_TOP_AUDIO_H_SEL
, /* clock for ADSP bus */
601 MT8195_CLK_TOP_AUDIO_LOCAL_BUS_SEL
, /* bus clock for DRAM access */
602 MT8195_CLK_TOP_AUD_INTBUS_SEL
, /* bus clock for AFE SRAM access */
603 MT8195_CLK_INFRA_AO_AUDIO_26M_B
, /* audio 26M clock */
604 MT8195_CLK_AUD_AFE
, /* AFE HW master switch */
605 MT8195_CLK_AUD_A1SYS_HP
, /* AFE HW clock*/
606 MT8195_CLK_AUD_A1SYS
, /* AFE HW clock */
609 for (i
= 0; i
< ARRAY_SIZE(clk_array
); i
++)
610 mt8195_afe_enable_clk(afe
, afe_priv
->clk
[clk_array
[i
]]);
615 int mt8195_afe_disable_reg_rw_clk(struct mtk_base_afe
*afe
)
617 struct mt8195_afe_private
*afe_priv
= afe
->platform_priv
;
619 static const unsigned int clk_array
[] = {
620 MT8195_CLK_AUD_A1SYS
,
621 MT8195_CLK_AUD_A1SYS_HP
,
623 MT8195_CLK_INFRA_AO_AUDIO_26M_B
,
624 MT8195_CLK_TOP_AUD_INTBUS_SEL
,
625 MT8195_CLK_TOP_AUDIO_LOCAL_BUS_SEL
,
626 MT8195_CLK_TOP_AUDIO_H_SEL
,
627 MT8195_CLK_SCP_ADSP_AUDIODSP
,
630 for (i
= 0; i
< ARRAY_SIZE(clk_array
); i
++)
631 mt8195_afe_disable_clk(afe
, afe_priv
->clk
[clk_array
[i
]]);
636 static int mt8195_afe_enable_afe_on(struct mtk_base_afe
*afe
)
638 regmap_update_bits(afe
->regmap
, AFE_DAC_CON0
, 0x1, 0x1);
642 static int mt8195_afe_disable_afe_on(struct mtk_base_afe
*afe
)
644 regmap_update_bits(afe
->regmap
, AFE_DAC_CON0
, 0x1, 0x0);
648 static int mt8195_afe_enable_timing_sys(struct mtk_base_afe
*afe
)
650 struct mt8195_afe_private
*afe_priv
= afe
->platform_priv
;
652 static const unsigned int clk_array
[] = {
653 MT8195_CLK_AUD_A1SYS
,
654 MT8195_CLK_AUD_A2SYS
,
656 static const unsigned int cg_array
[] = {
657 MT8195_TOP_CG_A1SYS_TIMING
,
658 MT8195_TOP_CG_A2SYS_TIMING
,
659 MT8195_TOP_CG_26M_TIMING
,
662 for (i
= 0; i
< ARRAY_SIZE(clk_array
); i
++)
663 mt8195_afe_enable_clk(afe
, afe_priv
->clk
[clk_array
[i
]]);
665 for (i
= 0; i
< ARRAY_SIZE(cg_array
); i
++)
666 mt8195_afe_enable_top_cg(afe
, cg_array
[i
]);
671 static int mt8195_afe_disable_timing_sys(struct mtk_base_afe
*afe
)
673 struct mt8195_afe_private
*afe_priv
= afe
->platform_priv
;
675 static const unsigned int clk_array
[] = {
676 MT8195_CLK_AUD_A2SYS
,
677 MT8195_CLK_AUD_A1SYS
,
679 static const unsigned int cg_array
[] = {
680 MT8195_TOP_CG_26M_TIMING
,
681 MT8195_TOP_CG_A2SYS_TIMING
,
682 MT8195_TOP_CG_A1SYS_TIMING
,
685 for (i
= 0; i
< ARRAY_SIZE(cg_array
); i
++)
686 mt8195_afe_disable_top_cg(afe
, cg_array
[i
]);
688 for (i
= 0; i
< ARRAY_SIZE(clk_array
); i
++)
689 mt8195_afe_disable_clk(afe
, afe_priv
->clk
[clk_array
[i
]]);
694 int mt8195_afe_enable_main_clock(struct mtk_base_afe
*afe
)
696 mt8195_afe_enable_timing_sys(afe
);
698 mt8195_afe_enable_afe_on(afe
);
700 mt8195_afe_enable_apll_tuner(afe
, MT8195_AUD_PLL1
);
701 mt8195_afe_enable_apll_tuner(afe
, MT8195_AUD_PLL2
);
706 int mt8195_afe_disable_main_clock(struct mtk_base_afe
*afe
)
708 mt8195_afe_disable_apll_tuner(afe
, MT8195_AUD_PLL2
);
709 mt8195_afe_disable_apll_tuner(afe
, MT8195_AUD_PLL1
);
711 mt8195_afe_disable_afe_on(afe
);
713 mt8195_afe_disable_timing_sys(afe
);