Skip to content

Commit 56a48c1

Browse files
Icenowypdp7
authored andcommitted
clk: thead: add support for enabling/disabling PLLs
The 2nd control word of T-Head TH1520 PLLs contains a bit to put the VCO into reset state, which means disabling the PLL. Some PLLs are put to disabled state by the bootloader, and the clock driver should be able to enable them. Add support for enabling/disabling PLLs. PLLs other than DPU ones are set CLK_IS_CRITICAL to prevent killing the system -- they're meant to drive CPU or system buses (even the GMAC/Video ones are driving arbitrary buses). Signed-off-by: Icenowy Zheng <uwu@icenowy.me> Reviewed-by: Drew Fustini <fustini@kernel.org> Signed-off-by: Drew Fustini <fustini@kernel.org>
1 parent c51a37f commit 56a48c1

1 file changed

Lines changed: 33 additions & 5 deletions

File tree

drivers/clk/thead/clk-th1520-ap.c

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#define TH1520_PLL_FBDIV GENMASK(19, 8)
1919
#define TH1520_PLL_REFDIV GENMASK(5, 0)
2020
#define TH1520_PLL_BYPASS BIT(30)
21+
#define TH1520_PLL_VCO_RST BIT(29)
2122
#define TH1520_PLL_DSMPD BIT(24)
2223
#define TH1520_PLL_FRAC GENMASK(23, 0)
2324
#define TH1520_PLL_FRAC_BITS 24
@@ -236,6 +237,30 @@ static const struct clk_ops ccu_div_ops = {
236237
.determine_rate = clk_hw_determine_rate_no_reparent,
237238
};
238239

240+
static void ccu_pll_disable(struct clk_hw *hw)
241+
{
242+
struct ccu_pll *pll = hw_to_ccu_pll(hw);
243+
244+
regmap_set_bits(pll->common.map, pll->common.cfg1,
245+
TH1520_PLL_VCO_RST);
246+
}
247+
248+
static int ccu_pll_enable(struct clk_hw *hw)
249+
{
250+
struct ccu_pll *pll = hw_to_ccu_pll(hw);
251+
252+
return regmap_clear_bits(pll->common.map, pll->common.cfg1,
253+
TH1520_PLL_VCO_RST);
254+
}
255+
256+
static int ccu_pll_is_enabled(struct clk_hw *hw)
257+
{
258+
struct ccu_pll *pll = hw_to_ccu_pll(hw);
259+
260+
return !regmap_test_bits(pll->common.map, pll->common.cfg1,
261+
TH1520_PLL_VCO_RST);
262+
}
263+
239264
static unsigned long th1520_pll_vco_recalc_rate(struct clk_hw *hw,
240265
unsigned long parent_rate)
241266
{
@@ -293,6 +318,9 @@ static unsigned long ccu_pll_recalc_rate(struct clk_hw *hw,
293318
}
294319

295320
static const struct clk_ops clk_pll_ops = {
321+
.disable = ccu_pll_disable,
322+
.enable = ccu_pll_enable,
323+
.is_enabled = ccu_pll_is_enabled,
296324
.recalc_rate = ccu_pll_recalc_rate,
297325
};
298326

@@ -308,7 +336,7 @@ static struct ccu_pll cpu_pll0_clk = {
308336
.hw.init = CLK_HW_INIT_PARENTS_DATA("cpu-pll0",
309337
osc_24m_clk,
310338
&clk_pll_ops,
311-
0),
339+
CLK_IS_CRITICAL),
312340
},
313341
};
314342

@@ -320,7 +348,7 @@ static struct ccu_pll cpu_pll1_clk = {
320348
.hw.init = CLK_HW_INIT_PARENTS_DATA("cpu-pll1",
321349
osc_24m_clk,
322350
&clk_pll_ops,
323-
0),
351+
CLK_IS_CRITICAL),
324352
},
325353
};
326354

@@ -332,7 +360,7 @@ static struct ccu_pll gmac_pll_clk = {
332360
.hw.init = CLK_HW_INIT_PARENTS_DATA("gmac-pll",
333361
osc_24m_clk,
334362
&clk_pll_ops,
335-
0),
363+
CLK_IS_CRITICAL),
336364
},
337365
};
338366

@@ -352,7 +380,7 @@ static struct ccu_pll video_pll_clk = {
352380
.hw.init = CLK_HW_INIT_PARENTS_DATA("video-pll",
353381
osc_24m_clk,
354382
&clk_pll_ops,
355-
0),
383+
CLK_IS_CRITICAL),
356384
},
357385
};
358386

@@ -404,7 +432,7 @@ static struct ccu_pll tee_pll_clk = {
404432
.hw.init = CLK_HW_INIT_PARENTS_DATA("tee-pll",
405433
osc_24m_clk,
406434
&clk_pll_ops,
407-
0),
435+
CLK_IS_CRITICAL),
408436
},
409437
};
410438

0 commit comments

Comments
 (0)