clk: sunxi-ng: Wait for lock when using fractional mode
authorJernej Škrabec <jernej.skrabec@siol.net>
Sun, 30 Jul 2017 16:41:50 +0000 (18:41 +0200)
committerChen-Yu Tsai <wens@csie.org>
Tue, 1 Aug 2017 02:18:23 +0000 (10:18 +0800)
Currently ccu_frac_helper_set_rate() doesn't wait for a lock bit to be
set before returning. Because of that, unstable clock may be used.

Add a wait for lock in the helper function.

Fixes: 89a3dfb78707 ("clk: sunxi-ng: Add fractional lib")
Signed-off-by: Jernej Skrabec <jernej.skrabec@siol.net>
Signed-off-by: Chen-Yu Tsai <wens@csie.org>
drivers/clk/sunxi-ng/ccu_frac.c
drivers/clk/sunxi-ng/ccu_frac.h
drivers/clk/sunxi-ng/ccu_mult.c
drivers/clk/sunxi-ng/ccu_nm.c

index ff9e72dc533729718ea15a2231bc1dba48ad1839..d1d168d4c4f00b2de8e30d1a9dc532e7fecc4578 100644 (file)
@@ -85,7 +85,7 @@ unsigned long ccu_frac_helper_read_rate(struct ccu_common *common,
 
 int ccu_frac_helper_set_rate(struct ccu_common *common,
                             struct ccu_frac_internal *cf,
-                            unsigned long rate)
+                            unsigned long rate, u32 lock)
 {
        unsigned long flags;
        u32 reg, sel;
@@ -106,5 +106,7 @@ int ccu_frac_helper_set_rate(struct ccu_common *common,
        writel(reg | sel, common->base + common->reg);
        spin_unlock_irqrestore(common->lock, flags);
 
+       ccu_helper_wait_for_lock(common, lock);
+
        return 0;
 }
index 7b1ee380156fa253b92bfbda098fe0f15b3050b5..efe2dd6bac01d6c7c788061c75164b14728b29e6 100644 (file)
@@ -48,6 +48,6 @@ unsigned long ccu_frac_helper_read_rate(struct ccu_common *common,
 
 int ccu_frac_helper_set_rate(struct ccu_common *common,
                             struct ccu_frac_internal *cf,
-                            unsigned long rate);
+                            unsigned long rate, u32 lock);
 
 #endif /* _CCU_FRAC_H_ */
index ee5e96222cb2f1d9240966fbde7a62b3ab2ada72..12e0783caee64332ddc335c67d3928d0caca8b14 100644 (file)
@@ -114,7 +114,8 @@ static int ccu_mult_set_rate(struct clk_hw *hw, unsigned long rate,
        if (ccu_frac_helper_has_rate(&cm->common, &cm->frac, rate)) {
                ccu_frac_helper_enable(&cm->common, &cm->frac);
 
-               return ccu_frac_helper_set_rate(&cm->common, &cm->frac, rate);
+               return ccu_frac_helper_set_rate(&cm->common, &cm->frac,
+                                               rate, cm->lock);
        } else {
                ccu_frac_helper_disable(&cm->common, &cm->frac);
        }
index c6ba866b99d3c0078bb5c25a337fc9ca9e4abf35..a32158e8f2e35a4fa89d5d21111e11e17a518ee8 100644 (file)
@@ -129,7 +129,8 @@ static int ccu_nm_set_rate(struct clk_hw *hw, unsigned long rate,
 
                ccu_frac_helper_enable(&nm->common, &nm->frac);
 
-               return ccu_frac_helper_set_rate(&nm->common, &nm->frac, rate);
+               return ccu_frac_helper_set_rate(&nm->common, &nm->frac,
+                                               rate, nm->lock);
        } else {
                ccu_frac_helper_disable(&nm->common, &nm->frac);
        }