diff options
author | Shawn Guo <shawn.guo@freescale.com> | 2014-04-18 22:58:22 -0400 |
---|---|---|
committer | Shawn Guo <shawn.guo@freescale.com> | 2014-05-12 10:58:48 -0400 |
commit | f9f28cdf21679792c30d9f5eebd01b7e04fe658f (patch) | |
tree | 6a1d608fd6eaeee70eeab2d00100394e0c95fb32 | |
parent | 94b5c0288299c7b962a7e2cb734293b77b96cffe (diff) |
ARM: imx: add shared gate clock support
It's quite common on i.MX that one gate bit controls the gating of
multiple clocks, i.e. this is a shared gate. The patch adds the
function imx_clk_gate2_shared() for such case. The clocks controlled
by the same gate bits should call this function with a pointer to a
single share count variable, so that the gate bits will only be
operated on the first enabling and the last disabling of these shared
gate clocks.
Thanks to Gerhard Sittig <gsi@denx.de> for this idea.
Signed-off-by: Shawn Guo <shawn.guo@freescale.com>
-rw-r--r-- | arch/arm/mach-imx/clk-gate2.c | 13 | ||||
-rw-r--r-- | arch/arm/mach-imx/clk.h | 13 |
2 files changed, 23 insertions, 3 deletions
diff --git a/arch/arm/mach-imx/clk-gate2.c b/arch/arm/mach-imx/clk-gate2.c index 0803df9d9c7e..4ba587da89d2 100644 --- a/arch/arm/mach-imx/clk-gate2.c +++ b/arch/arm/mach-imx/clk-gate2.c | |||
@@ -33,6 +33,7 @@ struct clk_gate2 { | |||
33 | u8 bit_idx; | 33 | u8 bit_idx; |
34 | u8 flags; | 34 | u8 flags; |
35 | spinlock_t *lock; | 35 | spinlock_t *lock; |
36 | unsigned int *share_count; | ||
36 | }; | 37 | }; |
37 | 38 | ||
38 | #define to_clk_gate2(_hw) container_of(_hw, struct clk_gate2, hw) | 39 | #define to_clk_gate2(_hw) container_of(_hw, struct clk_gate2, hw) |
@@ -45,10 +46,14 @@ static int clk_gate2_enable(struct clk_hw *hw) | |||
45 | 46 | ||
46 | spin_lock_irqsave(gate->lock, flags); | 47 | spin_lock_irqsave(gate->lock, flags); |
47 | 48 | ||
49 | if (gate->share_count && (*gate->share_count)++ > 0) | ||
50 | goto out; | ||
51 | |||
48 | reg = readl(gate->reg); | 52 | reg = readl(gate->reg); |
49 | reg |= 3 << gate->bit_idx; | 53 | reg |= 3 << gate->bit_idx; |
50 | writel(reg, gate->reg); | 54 | writel(reg, gate->reg); |
51 | 55 | ||
56 | out: | ||
52 | spin_unlock_irqrestore(gate->lock, flags); | 57 | spin_unlock_irqrestore(gate->lock, flags); |
53 | 58 | ||
54 | return 0; | 59 | return 0; |
@@ -62,10 +67,14 @@ static void clk_gate2_disable(struct clk_hw *hw) | |||
62 | 67 | ||
63 | spin_lock_irqsave(gate->lock, flags); | 68 | spin_lock_irqsave(gate->lock, flags); |
64 | 69 | ||
70 | if (gate->share_count && --(*gate->share_count) > 0) | ||
71 | goto out; | ||
72 | |||
65 | reg = readl(gate->reg); | 73 | reg = readl(gate->reg); |
66 | reg &= ~(3 << gate->bit_idx); | 74 | reg &= ~(3 << gate->bit_idx); |
67 | writel(reg, gate->reg); | 75 | writel(reg, gate->reg); |
68 | 76 | ||
77 | out: | ||
69 | spin_unlock_irqrestore(gate->lock, flags); | 78 | spin_unlock_irqrestore(gate->lock, flags); |
70 | } | 79 | } |
71 | 80 | ||
@@ -91,7 +100,8 @@ static struct clk_ops clk_gate2_ops = { | |||
91 | struct clk *clk_register_gate2(struct device *dev, const char *name, | 100 | struct clk *clk_register_gate2(struct device *dev, const char *name, |
92 | const char *parent_name, unsigned long flags, | 101 | const char *parent_name, unsigned long flags, |
93 | void __iomem *reg, u8 bit_idx, | 102 | void __iomem *reg, u8 bit_idx, |
94 | u8 clk_gate2_flags, spinlock_t *lock) | 103 | u8 clk_gate2_flags, spinlock_t *lock, |
104 | unsigned int *share_count) | ||
95 | { | 105 | { |
96 | struct clk_gate2 *gate; | 106 | struct clk_gate2 *gate; |
97 | struct clk *clk; | 107 | struct clk *clk; |
@@ -106,6 +116,7 @@ struct clk *clk_register_gate2(struct device *dev, const char *name, | |||
106 | gate->bit_idx = bit_idx; | 116 | gate->bit_idx = bit_idx; |
107 | gate->flags = clk_gate2_flags; | 117 | gate->flags = clk_gate2_flags; |
108 | gate->lock = lock; | 118 | gate->lock = lock; |
119 | gate->share_count = share_count; | ||
109 | 120 | ||
110 | init.name = name; | 121 | init.name = name; |
111 | init.ops = &clk_gate2_ops; | 122 | init.ops = &clk_gate2_ops; |
diff --git a/arch/arm/mach-imx/clk.h b/arch/arm/mach-imx/clk.h index 048c5ad8a80b..e29f6ebe9f39 100644 --- a/arch/arm/mach-imx/clk.h +++ b/arch/arm/mach-imx/clk.h | |||
@@ -28,7 +28,8 @@ struct clk *imx_clk_pllv3(enum imx_pllv3_type type, const char *name, | |||
28 | struct clk *clk_register_gate2(struct device *dev, const char *name, | 28 | struct clk *clk_register_gate2(struct device *dev, const char *name, |
29 | const char *parent_name, unsigned long flags, | 29 | const char *parent_name, unsigned long flags, |
30 | void __iomem *reg, u8 bit_idx, | 30 | void __iomem *reg, u8 bit_idx, |
31 | u8 clk_gate_flags, spinlock_t *lock); | 31 | u8 clk_gate_flags, spinlock_t *lock, |
32 | unsigned int *share_count); | ||
32 | 33 | ||
33 | struct clk * imx_obtain_fixed_clock( | 34 | struct clk * imx_obtain_fixed_clock( |
34 | const char *name, unsigned long rate); | 35 | const char *name, unsigned long rate); |
@@ -37,7 +38,15 @@ static inline struct clk *imx_clk_gate2(const char *name, const char *parent, | |||
37 | void __iomem *reg, u8 shift) | 38 | void __iomem *reg, u8 shift) |
38 | { | 39 | { |
39 | return clk_register_gate2(NULL, name, parent, CLK_SET_RATE_PARENT, reg, | 40 | return clk_register_gate2(NULL, name, parent, CLK_SET_RATE_PARENT, reg, |
40 | shift, 0, &imx_ccm_lock); | 41 | shift, 0, &imx_ccm_lock, NULL); |
42 | } | ||
43 | |||
44 | static inline struct clk *imx_clk_gate2_shared(const char *name, | ||
45 | const char *parent, void __iomem *reg, u8 shift, | ||
46 | unsigned int *share_count) | ||
47 | { | ||
48 | return clk_register_gate2(NULL, name, parent, CLK_SET_RATE_PARENT, reg, | ||
49 | shift, 0, &imx_ccm_lock, share_count); | ||
41 | } | 50 | } |
42 | 51 | ||
43 | struct clk *imx_clk_pfd(const char *name, const char *parent_name, | 52 | struct clk *imx_clk_pfd(const char *name, const char *parent_name, |