aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Wahren <stefan.wahren@i2se.com>2015-01-30 14:20:10 -0500
committerMichael Turquette <mturquette@linaro.org>2015-02-03 16:08:05 -0500
commit039e5970750775f102b255de9bf914e04955c6da (patch)
tree894eff0d0882ee0c4d3304c7ad8b3b8fd0cbd907
parent6793a30a0646d2cc269e66782ca30c6025c92e1f (diff)
clk: mxs: Fix invalid 32-bit access to frac registers
According to i.MX23 and i.MX28 reference manual [1],[2] the fractional clock control register is 32-bit wide, but is separated in 4 parts. So write instructions must not apply to more than 1 part at once. The clk init for the i.MX28 violates this restriction and all the other accesses on that register suggest that there isn't such a restriction. This patch restricts the access to this register to byte instructions and extends the comment in the init functions. Btw the imx23 init now uses a R-M-W sequence just like imx28 init to avoid any clock glitches. The changes has been tested with a i.MX23 and a i.MX28 board. [1] - http://cache.freescale.com/files/dsp/doc/ref_manual/IMX23RM.pdf [2] - http://cache.freescale.com/files/dsp/doc/ref_manual/MCIMX28RM.pdf Signed-off-by: Stefan Wahren <stefan.wahren@i2se.com> Reviewed-by: Marek Vasut <marex@denx.de> Reviewed-by: Fabio Estevam <fabio.estevam@freescale.com> Signed-off-by: Michael Turquette <mturquette@linaro.org>
-rw-r--r--drivers/clk/mxs/clk-imx23.c11
-rw-r--r--drivers/clk/mxs/clk-imx28.c19
-rw-r--r--drivers/clk/mxs/clk-ref.c19
3 files changed, 31 insertions, 18 deletions
diff --git a/drivers/clk/mxs/clk-imx23.c b/drivers/clk/mxs/clk-imx23.c
index 9fc9359f5133..a084566cf7e2 100644
--- a/drivers/clk/mxs/clk-imx23.c
+++ b/drivers/clk/mxs/clk-imx23.c
@@ -46,11 +46,13 @@ static void __iomem *digctrl;
46#define BP_CLKSEQ_BYPASS_SAIF 0 46#define BP_CLKSEQ_BYPASS_SAIF 0
47#define BP_CLKSEQ_BYPASS_SSP 5 47#define BP_CLKSEQ_BYPASS_SSP 5
48#define BP_SAIF_DIV_FRAC_EN 16 48#define BP_SAIF_DIV_FRAC_EN 16
49#define BP_FRAC_IOFRAC 24 49
50#define FRAC_IO 3
50 51
51static void __init clk_misc_init(void) 52static void __init clk_misc_init(void)
52{ 53{
53 u32 val; 54 u32 val;
55 u8 frac;
54 56
55 /* Gate off cpu clock in WFI for power saving */ 57 /* Gate off cpu clock in WFI for power saving */
56 writel_relaxed(1 << BP_CPU_INTERRUPT_WAIT, CPU + SET); 58 writel_relaxed(1 << BP_CPU_INTERRUPT_WAIT, CPU + SET);
@@ -72,9 +74,12 @@ static void __init clk_misc_init(void)
72 /* 74 /*
73 * 480 MHz seems too high to be ssp clock source directly, 75 * 480 MHz seems too high to be ssp clock source directly,
74 * so set frac to get a 288 MHz ref_io. 76 * so set frac to get a 288 MHz ref_io.
77 * According to reference manual we must access frac bytewise.
75 */ 78 */
76 writel_relaxed(0x3f << BP_FRAC_IOFRAC, FRAC + CLR); 79 frac = readb_relaxed(FRAC + FRAC_IO);
77 writel_relaxed(30 << BP_FRAC_IOFRAC, FRAC + SET); 80 frac &= ~0x3f;
81 frac |= 30;
82 writeb_relaxed(frac, FRAC + FRAC_IO);
78} 83}
79 84
80static const char *sel_pll[] __initconst = { "pll", "ref_xtal", }; 85static const char *sel_pll[] __initconst = { "pll", "ref_xtal", };
diff --git a/drivers/clk/mxs/clk-imx28.c b/drivers/clk/mxs/clk-imx28.c
index a6c35010e4e5..c541377838a8 100644
--- a/drivers/clk/mxs/clk-imx28.c
+++ b/drivers/clk/mxs/clk-imx28.c
@@ -53,8 +53,9 @@ static void __iomem *clkctrl;
53#define BP_ENET_SLEEP 31 53#define BP_ENET_SLEEP 31
54#define BP_CLKSEQ_BYPASS_SAIF0 0 54#define BP_CLKSEQ_BYPASS_SAIF0 0
55#define BP_CLKSEQ_BYPASS_SSP0 3 55#define BP_CLKSEQ_BYPASS_SSP0 3
56#define BP_FRAC0_IO1FRAC 16 56
57#define BP_FRAC0_IO0FRAC 24 57#define FRAC0_IO1 2
58#define FRAC0_IO0 3
58 59
59static void __iomem *digctrl; 60static void __iomem *digctrl;
60#define DIGCTRL digctrl 61#define DIGCTRL digctrl
@@ -85,6 +86,7 @@ int mxs_saif_clkmux_select(unsigned int clkmux)
85static void __init clk_misc_init(void) 86static void __init clk_misc_init(void)
86{ 87{
87 u32 val; 88 u32 val;
89 u8 frac;
88 90
89 /* Gate off cpu clock in WFI for power saving */ 91 /* Gate off cpu clock in WFI for power saving */
90 writel_relaxed(1 << BP_CPU_INTERRUPT_WAIT, CPU + SET); 92 writel_relaxed(1 << BP_CPU_INTERRUPT_WAIT, CPU + SET);
@@ -118,11 +120,16 @@ static void __init clk_misc_init(void)
118 /* 120 /*
119 * 480 MHz seems too high to be ssp clock source directly, 121 * 480 MHz seems too high to be ssp clock source directly,
120 * so set frac0 to get a 288 MHz ref_io0 and ref_io1. 122 * so set frac0 to get a 288 MHz ref_io0 and ref_io1.
123 * According to reference manual we must access frac0 bytewise.
121 */ 124 */
122 val = readl_relaxed(FRAC0); 125 frac = readb_relaxed(FRAC0 + FRAC0_IO0);
123 val &= ~((0x3f << BP_FRAC0_IO0FRAC) | (0x3f << BP_FRAC0_IO1FRAC)); 126 frac &= ~0x3f;
124 val |= (30 << BP_FRAC0_IO0FRAC) | (30 << BP_FRAC0_IO1FRAC); 127 frac |= 30;
125 writel_relaxed(val, FRAC0); 128 writeb_relaxed(frac, FRAC0 + FRAC0_IO0);
129 frac = readb_relaxed(FRAC0 + FRAC0_IO1);
130 frac &= ~0x3f;
131 frac |= 30;
132 writeb_relaxed(frac, FRAC0 + FRAC0_IO1);
126} 133}
127 134
128static const char *sel_cpu[] __initconst = { "ref_cpu", "ref_xtal", }; 135static const char *sel_cpu[] __initconst = { "ref_cpu", "ref_xtal", };
diff --git a/drivers/clk/mxs/clk-ref.c b/drivers/clk/mxs/clk-ref.c
index 4adeed6c2f94..ad3851c93c90 100644
--- a/drivers/clk/mxs/clk-ref.c
+++ b/drivers/clk/mxs/clk-ref.c
@@ -16,6 +16,8 @@
16#include <linux/slab.h> 16#include <linux/slab.h>
17#include "clk.h" 17#include "clk.h"
18 18
19#define BF_CLKGATE BIT(7)
20
19/** 21/**
20 * struct clk_ref - mxs reference clock 22 * struct clk_ref - mxs reference clock
21 * @hw: clk_hw for the reference clock 23 * @hw: clk_hw for the reference clock
@@ -39,7 +41,7 @@ static int clk_ref_enable(struct clk_hw *hw)
39{ 41{
40 struct clk_ref *ref = to_clk_ref(hw); 42 struct clk_ref *ref = to_clk_ref(hw);
41 43
42 writel_relaxed(1 << ((ref->idx + 1) * 8 - 1), ref->reg + CLR); 44 writeb_relaxed(BF_CLKGATE, ref->reg + ref->idx + CLR);
43 45
44 return 0; 46 return 0;
45} 47}
@@ -48,7 +50,7 @@ static void clk_ref_disable(struct clk_hw *hw)
48{ 50{
49 struct clk_ref *ref = to_clk_ref(hw); 51 struct clk_ref *ref = to_clk_ref(hw);
50 52
51 writel_relaxed(1 << ((ref->idx + 1) * 8 - 1), ref->reg + SET); 53 writeb_relaxed(BF_CLKGATE, ref->reg + ref->idx + SET);
52} 54}
53 55
54static unsigned long clk_ref_recalc_rate(struct clk_hw *hw, 56static unsigned long clk_ref_recalc_rate(struct clk_hw *hw,
@@ -56,7 +58,7 @@ static unsigned long clk_ref_recalc_rate(struct clk_hw *hw,
56{ 58{
57 struct clk_ref *ref = to_clk_ref(hw); 59 struct clk_ref *ref = to_clk_ref(hw);
58 u64 tmp = parent_rate; 60 u64 tmp = parent_rate;
59 u8 frac = (readl_relaxed(ref->reg) >> (ref->idx * 8)) & 0x3f; 61 u8 frac = readb_relaxed(ref->reg + ref->idx) & 0x3f;
60 62
61 tmp *= 18; 63 tmp *= 18;
62 do_div(tmp, frac); 64 do_div(tmp, frac);
@@ -93,8 +95,7 @@ static int clk_ref_set_rate(struct clk_hw *hw, unsigned long rate,
93 struct clk_ref *ref = to_clk_ref(hw); 95 struct clk_ref *ref = to_clk_ref(hw);
94 unsigned long flags; 96 unsigned long flags;
95 u64 tmp = parent_rate; 97 u64 tmp = parent_rate;
96 u32 val; 98 u8 frac, val;
97 u8 frac, shift = ref->idx * 8;
98 99
99 tmp = tmp * 18 + rate / 2; 100 tmp = tmp * 18 + rate / 2;
100 do_div(tmp, rate); 101 do_div(tmp, rate);
@@ -107,10 +108,10 @@ static int clk_ref_set_rate(struct clk_hw *hw, unsigned long rate,
107 108
108 spin_lock_irqsave(&mxs_lock, flags); 109 spin_lock_irqsave(&mxs_lock, flags);
109 110
110 val = readl_relaxed(ref->reg); 111 val = readb_relaxed(ref->reg + ref->idx);
111 val &= ~(0x3f << shift); 112 val &= ~0x3f;
112 val |= frac << shift; 113 val |= frac;
113 writel_relaxed(val, ref->reg); 114 writeb_relaxed(val, ref->reg + ref->idx);
114 115
115 spin_unlock_irqrestore(&mxs_lock, flags); 116 spin_unlock_irqrestore(&mxs_lock, flags);
116 117