1616 * of the SoC or supplied after the SoC characterization.
1717 *
1818 * The below implementation of the CPU clock allows the rate changes of the CPU
19- * clock and the corresponding rate changes of the auxillary clocks of the CPU
19+ * clock and the corresponding rate changes of the auxiliary clocks of the CPU
2020 * domain. The platform clock driver provides a clock register configuration
2121 * for each configurable rate which is then used to program the clock hardware
22- * registers to acheive a fast co-oridinated rate change for all the CPU domain
22+ * registers to achieve a fast coordinated rate change for all the CPU domain
2323 * clocks.
2424 *
2525 * On a rate change request for the CPU clock, the rate change is propagated
26- * upto the PLL supplying the clock to the CPU domain clock blocks. While the
26+ * up to the PLL supplying the clock to the CPU domain clock blocks. While the
2727 * CPU domain PLL is reconfigured, the CPU domain clocks are driven using an
2828 * alternate clock source. If required, the alternate clock source is divided
2929 * down in order to keep the output clock rate within the previous OPP limits.
30- */
30+ */
3131
3232#include <linux/errno.h>
3333#include <linux/io.h>
5050#define E5433_DIV_STAT_CPU0 0x500
5151#define E5433_DIV_STAT_CPU1 0x504
5252
53- #define E4210_DIV0_RATIO0_MASK 0x7
54- #define E4210_DIV1_HPM_MASK (0x7 << 4)
55- #define E4210_DIV1_COPY_MASK (0x7 << 0)
56- #define E4210_MUX_HPM_MASK (1 << 20)
53+ #define E4210_DIV0_RATIO0_MASK GENMASK(2, 0)
54+ #define E4210_DIV1_HPM_MASK GENMASK(6, 4)
55+ #define E4210_DIV1_COPY_MASK GENMASK(2, 0)
56+ #define E4210_MUX_HPM_MASK BIT( 20)
5757#define E4210_DIV0_ATB_SHIFT 16
5858#define E4210_DIV0_ATB_MASK (DIV_MASK << E4210_DIV0_ATB_SHIFT)
5959
60+ /* Divider stabilization time, msec */
61+ #define MAX_STAB_TIME 10
6062#define MAX_DIV 8
61- #define DIV_MASK 7
62- #define DIV_MASK_ALL 0xffffffff
63- #define MUX_MASK 7
63+ #define DIV_MASK GENMASK(2, 0)
64+ #define DIV_MASK_ALL GENMASK(31, 0)
65+ #define MUX_MASK GENMASK(2, 0)
6466
6567/*
6668 * Helper function to wait until divider(s) have stabilized after the divider
6769 * value has changed.
6870 */
6971static void wait_until_divider_stable (void __iomem * div_reg , unsigned long mask )
7072{
71- unsigned long timeout = jiffies + msecs_to_jiffies (10 );
73+ unsigned long timeout = jiffies + msecs_to_jiffies (MAX_STAB_TIME );
7274
7375 do {
7476 if (!(readl (div_reg ) & mask ))
@@ -86,9 +88,9 @@ static void wait_until_divider_stable(void __iomem *div_reg, unsigned long mask)
8688 * value was changed.
8789 */
8890static void wait_until_mux_stable (void __iomem * mux_reg , u32 mux_pos ,
89- unsigned long mux_value )
91+ unsigned long mux_value )
9092{
91- unsigned long timeout = jiffies + msecs_to_jiffies (10 );
93+ unsigned long timeout = jiffies + msecs_to_jiffies (MAX_STAB_TIME );
9294
9395 do {
9496 if (((readl (mux_reg ) >> mux_pos ) & MUX_MASK ) == mux_value )
@@ -101,18 +103,18 @@ static void wait_until_mux_stable(void __iomem *mux_reg, u32 mux_pos,
101103 pr_err ("%s: re-parenting mux timed-out\n" , __func__ );
102104}
103105
104- /* common round rate callback useable for all types of CPU clocks */
105- static long exynos_cpuclk_round_rate (struct clk_hw * hw ,
106- unsigned long drate , unsigned long * prate )
106+ /* common round rate callback usable for all types of CPU clocks */
107+ static long exynos_cpuclk_round_rate (struct clk_hw * hw , unsigned long drate ,
108+ unsigned long * prate )
107109{
108110 struct clk_hw * parent = clk_hw_get_parent (hw );
109111 * prate = clk_hw_round_rate (parent , drate );
110112 return * prate ;
111113}
112114
113- /* common recalc rate callback useable for all types of CPU clocks */
115+ /* common recalc rate callback usable for all types of CPU clocks */
114116static unsigned long exynos_cpuclk_recalc_rate (struct clk_hw * hw ,
115- unsigned long parent_rate )
117+ unsigned long parent_rate )
116118{
117119 /*
118120 * The CPU clock output (armclk) rate is the same as its parent
@@ -135,7 +137,7 @@ static const struct clk_ops exynos_cpuclk_clk_ops = {
135137 * dividers to be programmed.
136138 */
137139static void exynos_set_safe_div (void __iomem * base , unsigned long div ,
138- unsigned long mask )
140+ unsigned long mask )
139141{
140142 unsigned long div0 ;
141143
@@ -151,7 +153,6 @@ static int exynos_cpuclk_pre_rate_change(struct clk_notifier_data *ndata,
151153{
152154 const struct exynos_cpuclk_cfg_data * cfg_data = cpuclk -> cfg ;
153155 unsigned long alt_prate = clk_hw_get_rate (cpuclk -> alt_parent );
154- unsigned long alt_div = 0 , alt_div_mask = DIV_MASK ;
155156 unsigned long div0 , div1 = 0 , mux_reg ;
156157 unsigned long flags ;
157158
@@ -187,6 +188,7 @@ static int exynos_cpuclk_pre_rate_change(struct clk_notifier_data *ndata,
187188 */
188189 if (alt_prate > ndata -> old_rate || ndata -> old_rate > ndata -> new_rate ) {
189190 unsigned long tmp_rate = min (ndata -> old_rate , ndata -> new_rate );
191+ unsigned long alt_div , alt_div_mask = DIV_MASK ;
190192
191193 alt_div = DIV_ROUND_UP (alt_prate , tmp_rate ) - 1 ;
192194 WARN_ON (alt_div >= MAX_DIV );
@@ -215,7 +217,7 @@ static int exynos_cpuclk_pre_rate_change(struct clk_notifier_data *ndata,
215217 if (cpuclk -> flags & CLK_CPU_HAS_DIV1 ) {
216218 writel (div1 , base + E4210_DIV_CPU1 );
217219 wait_until_divider_stable (base + E4210_DIV_STAT_CPU1 ,
218- DIV_MASK_ALL );
220+ DIV_MASK_ALL );
219221 }
220222
221223 spin_unlock_irqrestore (cpuclk -> lock , flags );
@@ -263,7 +265,7 @@ static int exynos_cpuclk_post_rate_change(struct clk_notifier_data *ndata,
263265 * dividers to be programmed.
264266 */
265267static void exynos5433_set_safe_div (void __iomem * base , unsigned long div ,
266- unsigned long mask )
268+ unsigned long mask )
267269{
268270 unsigned long div0 ;
269271
@@ -279,7 +281,6 @@ static int exynos5433_cpuclk_pre_rate_change(struct clk_notifier_data *ndata,
279281{
280282 const struct exynos_cpuclk_cfg_data * cfg_data = cpuclk -> cfg ;
281283 unsigned long alt_prate = clk_hw_get_rate (cpuclk -> alt_parent );
282- unsigned long alt_div = 0 , alt_div_mask = DIV_MASK ;
283284 unsigned long div0 , div1 = 0 , mux_reg ;
284285 unsigned long flags ;
285286
@@ -309,6 +310,7 @@ static int exynos5433_cpuclk_pre_rate_change(struct clk_notifier_data *ndata,
309310 */
310311 if (alt_prate > ndata -> old_rate || ndata -> old_rate > ndata -> new_rate ) {
311312 unsigned long tmp_rate = min (ndata -> old_rate , ndata -> new_rate );
313+ unsigned long alt_div , alt_div_mask = DIV_MASK ;
312314
313315 alt_div = DIV_ROUND_UP (alt_prate , tmp_rate ) - 1 ;
314316 WARN_ON (alt_div >= MAX_DIV );
@@ -358,7 +360,7 @@ static int exynos5433_cpuclk_post_rate_change(struct clk_notifier_data *ndata,
358360 * notifications of the parent clock of cpuclk.
359361 */
360362static int exynos_cpuclk_notifier_cb (struct notifier_block * nb ,
361- unsigned long event , void * data )
363+ unsigned long event , void * data )
362364{
363365 struct clk_notifier_data * ndata = data ;
364366 struct exynos_cpuclk * cpuclk ;
@@ -381,7 +383,7 @@ static int exynos_cpuclk_notifier_cb(struct notifier_block *nb,
381383 * notifications of the parent clock of cpuclk.
382384 */
383385static int exynos5433_cpuclk_notifier_cb (struct notifier_block * nb ,
384- unsigned long event , void * data )
386+ unsigned long event , void * data )
385387{
386388 struct clk_notifier_data * ndata = data ;
387389 struct exynos_cpuclk * cpuclk ;
@@ -438,11 +440,10 @@ static int __init exynos_register_cpu_clock(struct samsung_clk_provider *ctx,
438440 else
439441 cpuclk -> clk_nb .notifier_call = exynos_cpuclk_notifier_cb ;
440442
441-
442443 ret = clk_notifier_register (parent -> clk , & cpuclk -> clk_nb );
443444 if (ret ) {
444445 pr_err ("%s: failed to register clock notifier for %s\n" ,
445- __func__ , name );
446+ __func__ , name );
446447 goto free_cpuclk ;
447448 }
448449
@@ -454,7 +455,7 @@ static int __init exynos_register_cpu_clock(struct samsung_clk_provider *ctx,
454455
455456 ret = clk_hw_register (NULL , & cpuclk -> hw );
456457 if (ret ) {
457- pr_err ("%s: could not register cpuclk %s\n" , __func__ , name );
458+ pr_err ("%s: could not register cpuclk %s\n" , __func__ , name );
458459 goto free_cpuclk_data ;
459460 }
460461
@@ -482,8 +483,8 @@ void __init samsung_clk_register_cpu(struct samsung_clk_provider *ctx,
482483 for (num_cfgs = 0 ; list -> cfg [num_cfgs ].prate != 0 ; )
483484 num_cfgs ++ ;
484485
485- exynos_register_cpu_clock (ctx , list -> id , list -> name , hws [ list -> parent_id ],
486- hws [list -> alt_parent_id ], list -> offset , list -> cfg , num_cfgs ,
487- list -> flags );
486+ exynos_register_cpu_clock (ctx , list -> id , list -> name ,
487+ hws [list -> parent_id ], hws [ list -> alt_parent_id ] ,
488+ list -> offset , list -> cfg , num_cfgs , list -> flags );
488489 }
489490}
0 commit comments