Skip to content

Commit cf6f1c1

Browse files
finley1226yihsin-hung
authored andcommitted
clk: rockchip: add safe frequency support
Change-Id: Ib03dc12414295fec8e5a71d2b57ebacbff8e04e3 Signed-off-by: Finley Xiao <finley.xiao@rock-chips.com>
1 parent b9b1227 commit cf6f1c1

3 files changed

Lines changed: 23 additions & 4 deletions

File tree

drivers/clk/rockchip/clk-pll.c

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@
3131
#define PLL_MODE_NORM 0x1
3232
#define PLL_MODE_DEEP 0x2
3333

34+
unsigned long apll_safefreq = ULONG_MAX;
35+
unsigned long apll_maxfreq;
36+
3437
struct rockchip_clk_pll {
3538
struct clk_hw hw;
3639

@@ -49,6 +52,7 @@ struct rockchip_clk_pll {
4952
spinlock_t *lock;
5053

5154
struct rockchip_clk_provider *ctx;
55+
u8 id;
5256
};
5357

5458
#define to_rockchip_clk_pll(_hw) container_of(_hw, struct rockchip_clk_pll, hw)
@@ -617,6 +621,9 @@ static unsigned long rockchip_rk3066_pll_recalc_rate(struct clk_hw *hw,
617621
return prate;
618622
}
619623

624+
if (pll->id == 1 && apll_maxfreq)
625+
return apll_maxfreq;
626+
620627
rockchip_rk3066_pll_get_params(pll, &cur);
621628

622629
rate64 *= cur.nf;
@@ -691,14 +698,19 @@ static int rockchip_rk3066_pll_set_rate(struct clk_hw *hw, unsigned long drate,
691698
struct rockchip_clk_pll *pll = to_rockchip_clk_pll(hw);
692699
const struct rockchip_pll_rate_table *rate;
693700
unsigned long old_rate = rockchip_rk3066_pll_recalc_rate(hw, prate);
701+
unsigned long temp_rate = drate;
694702
struct regmap *grf = rockchip_clk_get_grf(pll->ctx);
703+
int ret;
695704

696705
if (IS_ERR(grf)) {
697706
pr_debug("%s: grf regmap not available, aborting rate change\n",
698707
__func__);
699708
return PTR_ERR(grf);
700709
}
701710

711+
if (pll->id == 1 && drate > apll_safefreq)
712+
drate = apll_safefreq;
713+
702714
pr_debug("%s: changing %s from %lu to %lu with a parent rate of %lu\n",
703715
__func__, clk_hw_get_name(hw), old_rate, drate, prate);
704716

@@ -710,7 +722,13 @@ static int rockchip_rk3066_pll_set_rate(struct clk_hw *hw, unsigned long drate,
710722
return -EINVAL;
711723
}
712724

713-
return rockchip_rk3066_pll_set_params(pll, rate);
725+
ret = rockchip_rk3066_pll_set_params(pll, rate);
726+
if (!ret && pll->id == 1 && drate == apll_safefreq)
727+
apll_maxfreq = temp_rate;
728+
else
729+
apll_maxfreq = 0;
730+
731+
return ret;
714732
}
715733

716734
static int rockchip_rk3066_pll_enable(struct clk_hw *hw)
@@ -1224,7 +1242,7 @@ struct clk *rockchip_clk_register_pll(struct rockchip_clk_provider *ctx,
12241242
u8 num_parents, int con_offset, int grf_lock_offset,
12251243
int lock_shift, int mode_offset, int mode_shift,
12261244
struct rockchip_pll_rate_table *rate_table,
1227-
unsigned long flags, u8 clk_pll_flags)
1245+
unsigned long flags, u8 clk_pll_flags, u8 id)
12281246
{
12291247
const char *pll_parents[3];
12301248
struct clk_init_data init;
@@ -1340,6 +1358,7 @@ struct clk *rockchip_clk_register_pll(struct rockchip_clk_provider *ctx,
13401358
pll->flags = clk_pll_flags;
13411359
pll->lock = &ctx->lock;
13421360
pll->ctx = ctx;
1361+
pll->id = id;
13431362

13441363
pll_clk = clk_register(NULL, &pll->hw);
13451364
if (IS_ERR(pll_clk)) {

drivers/clk/rockchip/clk.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@ void __init rockchip_clk_register_plls(struct rockchip_clk_provider *ctx,
391391
list->con_offset, grf_lock_offset,
392392
list->lock_shift, list->mode_offset,
393393
list->mode_shift, list->rate_table,
394-
list->flags, list->pll_flags);
394+
list->flags, list->pll_flags, list->id);
395395
if (IS_ERR(clk)) {
396396
pr_err("%s: failed to register clock %s\n", __func__,
397397
list->name);

drivers/clk/rockchip/clk.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ struct clk *rockchip_clk_register_pll(struct rockchip_clk_provider *ctx,
242242
u8 num_parents, int con_offset, int grf_lock_offset,
243243
int lock_shift, int mode_offset, int mode_shift,
244244
struct rockchip_pll_rate_table *rate_table,
245-
unsigned long flags, u8 clk_pll_flags);
245+
unsigned long flags, u8 clk_pll_flags, u8 id);
246246

247247
struct rockchip_cpuclk_clksel {
248248
int reg;

0 commit comments

Comments
 (0)