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+
3437struct 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
716734static 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 )) {
0 commit comments