Skip to content

Commit 2c327a1

Browse files
laura-naobebarino
authored andcommitted
clk: mediatek: clk-pll: Add ops for PLLs using set/clr regs and FENC
MT8196 uses a combination of set/clr registers to control the PLL enable state, along with a FENC bit to check the preparation status. Add new set of PLL clock operations with support for set/clr enable and FENC status logic. Reviewed-by: Nícolas F. R. A. Prado <nfraprado@collabora.com> Reviewed-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com> Reviewed-by: Chen-Yu Tsai <wenst@chromium.org> Signed-off-by: Laura Nao <laura.nao@collabora.com> Signed-off-by: Stephen Boyd <sboyd@kernel.org>
1 parent aee9ffa commit 2c327a1

2 files changed

Lines changed: 44 additions & 1 deletion

File tree

drivers/clk/mediatek/clk-pll.c

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,13 @@ int mtk_pll_is_prepared(struct clk_hw *hw)
3737
return (readl(pll->en_addr) & BIT(pll->data->pll_en_bit)) != 0;
3838
}
3939

40+
static int mtk_pll_fenc_is_prepared(struct clk_hw *hw)
41+
{
42+
struct mtk_clk_pll *pll = to_mtk_clk_pll(hw);
43+
44+
return !!(readl(pll->fenc_addr) & BIT(pll->data->fenc_sta_bit));
45+
}
46+
4047
static unsigned long __mtk_pll_recalc_rate(struct mtk_clk_pll *pll, u32 fin,
4148
u32 pcw, int postdiv)
4249
{
@@ -274,6 +281,25 @@ void mtk_pll_unprepare(struct clk_hw *hw)
274281
writel(r, pll->pwr_addr);
275282
}
276283

284+
static int mtk_pll_prepare_setclr(struct clk_hw *hw)
285+
{
286+
struct mtk_clk_pll *pll = to_mtk_clk_pll(hw);
287+
288+
writel(BIT(pll->data->pll_en_bit), pll->en_set_addr);
289+
290+
/* Wait 20us after enable for the PLL to stabilize */
291+
udelay(20);
292+
293+
return 0;
294+
}
295+
296+
static void mtk_pll_unprepare_setclr(struct clk_hw *hw)
297+
{
298+
struct mtk_clk_pll *pll = to_mtk_clk_pll(hw);
299+
300+
writel(BIT(pll->data->pll_en_bit), pll->en_clr_addr);
301+
}
302+
277303
const struct clk_ops mtk_pll_ops = {
278304
.is_prepared = mtk_pll_is_prepared,
279305
.prepare = mtk_pll_prepare,
@@ -283,6 +309,16 @@ const struct clk_ops mtk_pll_ops = {
283309
.set_rate = mtk_pll_set_rate,
284310
};
285311

312+
const struct clk_ops mtk_pll_fenc_clr_set_ops = {
313+
.is_prepared = mtk_pll_fenc_is_prepared,
314+
.prepare = mtk_pll_prepare_setclr,
315+
.unprepare = mtk_pll_unprepare_setclr,
316+
.recalc_rate = mtk_pll_recalc_rate,
317+
.round_rate = mtk_pll_round_rate,
318+
.set_rate = mtk_pll_set_rate,
319+
};
320+
EXPORT_SYMBOL_GPL(mtk_pll_fenc_clr_set_ops);
321+
286322
struct clk_hw *mtk_clk_register_pll_ops(struct mtk_clk_pll *pll,
287323
const struct mtk_pll_data *data,
288324
void __iomem *base,
@@ -315,6 +351,8 @@ struct clk_hw *mtk_clk_register_pll_ops(struct mtk_clk_pll *pll,
315351
pll->hw.init = &init;
316352
pll->data = data;
317353

354+
pll->fenc_addr = base + data->fenc_sta_ofs;
355+
318356
init.name = data->name;
319357
init.flags = (data->flags & PLL_AO) ? CLK_IS_CRITICAL : 0;
320358
init.ops = pll_ops;
@@ -337,12 +375,13 @@ struct clk_hw *mtk_clk_register_pll(const struct mtk_pll_data *data,
337375
{
338376
struct mtk_clk_pll *pll;
339377
struct clk_hw *hw;
378+
const struct clk_ops *pll_ops = data->ops ? data->ops : &mtk_pll_ops;
340379

341380
pll = kzalloc(sizeof(*pll), GFP_KERNEL);
342381
if (!pll)
343382
return ERR_PTR(-ENOMEM);
344383

345-
hw = mtk_clk_register_pll_ops(pll, data, base, &mtk_pll_ops);
384+
hw = mtk_clk_register_pll_ops(pll, data, base, pll_ops);
346385
if (IS_ERR(hw))
347386
kfree(pll);
348387

drivers/clk/mediatek/clk-pll.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ struct mtk_pll_data {
2929
u32 reg;
3030
u32 pwr_reg;
3131
u32 en_mask;
32+
u32 fenc_sta_ofs;
3233
u32 pd_reg;
3334
u32 tuner_reg;
3435
u32 tuner_en_reg;
@@ -51,6 +52,7 @@ struct mtk_pll_data {
5152
u32 en_clr_reg;
5253
u8 pll_en_bit; /* Assume 0, indicates BIT(0) by default */
5354
u8 pcw_chg_bit;
55+
u8 fenc_sta_bit;
5456
};
5557

5658
/*
@@ -72,6 +74,7 @@ struct mtk_clk_pll {
7274
void __iomem *en_addr;
7375
void __iomem *en_set_addr;
7476
void __iomem *en_clr_addr;
77+
void __iomem *fenc_addr;
7578
const struct mtk_pll_data *data;
7679
};
7780

@@ -82,6 +85,7 @@ void mtk_clk_unregister_plls(const struct mtk_pll_data *plls, int num_plls,
8285
struct clk_hw_onecell_data *clk_data);
8386

8487
extern const struct clk_ops mtk_pll_ops;
88+
extern const struct clk_ops mtk_pll_fenc_clr_set_ops;
8589

8690
static inline struct mtk_clk_pll *to_mtk_clk_pll(struct clk_hw *hw)
8791
{

0 commit comments

Comments
 (0)