diff options
author | Shawn Guo <shawn.guo@linaro.org> | 2012-04-28 12:02:34 -0400 |
---|---|---|
committer | Shawn Guo <shawn.guo@linaro.org> | 2012-05-08 12:02:35 -0400 |
commit | 23b5e15a2994fb0c1444f92b76f09a482f32843c (patch) | |
tree | 54695e5b39977bd1ed04dfd945c9052a85b57e0f /drivers/clk/mxs | |
parent | d48b97b403d23f6df0b990cee652bdf9a52337a3 (diff) |
clk: mxs: add mxs specific clocks
Add mxs specific clocks, pll, reference clock (PFD), integer divider
and fractional divider.
Signed-off-by: Shawn Guo <shawn.guo@linaro.org>
Diffstat (limited to 'drivers/clk/mxs')
-rw-r--r-- | drivers/clk/mxs/Makefile | 5 | ||||
-rw-r--r-- | drivers/clk/mxs/clk-div.c | 110 | ||||
-rw-r--r-- | drivers/clk/mxs/clk-frac.c | 139 | ||||
-rw-r--r-- | drivers/clk/mxs/clk-pll.c | 116 | ||||
-rw-r--r-- | drivers/clk/mxs/clk-ref.c | 154 | ||||
-rw-r--r-- | drivers/clk/mxs/clk.c | 28 | ||||
-rw-r--r-- | drivers/clk/mxs/clk.h | 66 |
7 files changed, 618 insertions, 0 deletions
diff --git a/drivers/clk/mxs/Makefile b/drivers/clk/mxs/Makefile new file mode 100644 index 000000000000..d9472a809bba --- /dev/null +++ b/drivers/clk/mxs/Makefile | |||
@@ -0,0 +1,5 @@ | |||
1 | # | ||
2 | # Makefile for mxs specific clk | ||
3 | # | ||
4 | |||
5 | obj-y += clk.o clk-pll.o clk-ref.o clk-div.o clk-frac.o | ||
diff --git a/drivers/clk/mxs/clk-div.c b/drivers/clk/mxs/clk-div.c new file mode 100644 index 000000000000..90e1da93877e --- /dev/null +++ b/drivers/clk/mxs/clk-div.c | |||
@@ -0,0 +1,110 @@ | |||
1 | /* | ||
2 | * Copyright 2012 Freescale Semiconductor, Inc. | ||
3 | * | ||
4 | * The code contained herein is licensed under the GNU General Public | ||
5 | * License. You may obtain a copy of the GNU General Public License | ||
6 | * Version 2 or later at the following locations: | ||
7 | * | ||
8 | * http://www.opensource.org/licenses/gpl-license.html | ||
9 | * http://www.gnu.org/copyleft/gpl.html | ||
10 | */ | ||
11 | |||
12 | #include <linux/clk.h> | ||
13 | #include <linux/clk-provider.h> | ||
14 | #include <linux/err.h> | ||
15 | #include <linux/slab.h> | ||
16 | #include "clk.h" | ||
17 | |||
18 | /** | ||
19 | * struct clk_div - mxs integer divider clock | ||
20 | * @divider: the parent class | ||
21 | * @ops: pointer to clk_ops of parent class | ||
22 | * @reg: register address | ||
23 | * @busy: busy bit shift | ||
24 | * | ||
25 | * The mxs divider clock is a subclass of basic clk_divider with an | ||
26 | * addtional busy bit. | ||
27 | */ | ||
28 | struct clk_div { | ||
29 | struct clk_divider divider; | ||
30 | const struct clk_ops *ops; | ||
31 | void __iomem *reg; | ||
32 | u8 busy; | ||
33 | }; | ||
34 | |||
35 | static inline struct clk_div *to_clk_div(struct clk_hw *hw) | ||
36 | { | ||
37 | struct clk_divider *divider = container_of(hw, struct clk_divider, hw); | ||
38 | |||
39 | return container_of(divider, struct clk_div, divider); | ||
40 | } | ||
41 | |||
42 | static unsigned long clk_div_recalc_rate(struct clk_hw *hw, | ||
43 | unsigned long parent_rate) | ||
44 | { | ||
45 | struct clk_div *div = to_clk_div(hw); | ||
46 | |||
47 | return div->ops->recalc_rate(&div->divider.hw, parent_rate); | ||
48 | } | ||
49 | |||
50 | static long clk_div_round_rate(struct clk_hw *hw, unsigned long rate, | ||
51 | unsigned long *prate) | ||
52 | { | ||
53 | struct clk_div *div = to_clk_div(hw); | ||
54 | |||
55 | return div->ops->round_rate(&div->divider.hw, rate, prate); | ||
56 | } | ||
57 | |||
58 | static int clk_div_set_rate(struct clk_hw *hw, unsigned long rate, | ||
59 | unsigned long parent_rate) | ||
60 | { | ||
61 | struct clk_div *div = to_clk_div(hw); | ||
62 | int ret; | ||
63 | |||
64 | ret = div->ops->set_rate(&div->divider.hw, rate, parent_rate); | ||
65 | if (!ret) | ||
66 | ret = mxs_clk_wait(div->reg, div->busy); | ||
67 | |||
68 | return ret; | ||
69 | } | ||
70 | |||
71 | static struct clk_ops clk_div_ops = { | ||
72 | .recalc_rate = clk_div_recalc_rate, | ||
73 | .round_rate = clk_div_round_rate, | ||
74 | .set_rate = clk_div_set_rate, | ||
75 | }; | ||
76 | |||
77 | struct clk *mxs_clk_div(const char *name, const char *parent_name, | ||
78 | void __iomem *reg, u8 shift, u8 width, u8 busy) | ||
79 | { | ||
80 | struct clk_div *div; | ||
81 | struct clk *clk; | ||
82 | struct clk_init_data init; | ||
83 | |||
84 | div = kzalloc(sizeof(*div), GFP_KERNEL); | ||
85 | if (!div) | ||
86 | return ERR_PTR(-ENOMEM); | ||
87 | |||
88 | init.name = name; | ||
89 | init.ops = &clk_div_ops; | ||
90 | init.flags = CLK_SET_RATE_PARENT; | ||
91 | init.parent_names = (parent_name ? &parent_name: NULL); | ||
92 | init.num_parents = (parent_name ? 1 : 0); | ||
93 | |||
94 | div->reg = reg; | ||
95 | div->busy = busy; | ||
96 | |||
97 | div->divider.reg = reg; | ||
98 | div->divider.shift = shift; | ||
99 | div->divider.width = width; | ||
100 | div->divider.flags = CLK_DIVIDER_ONE_BASED; | ||
101 | div->divider.lock = &mxs_lock; | ||
102 | div->divider.hw.init = &init; | ||
103 | div->ops = &clk_divider_ops; | ||
104 | |||
105 | clk = clk_register(NULL, &div->divider.hw); | ||
106 | if (IS_ERR(clk)) | ||
107 | kfree(div); | ||
108 | |||
109 | return clk; | ||
110 | } | ||
diff --git a/drivers/clk/mxs/clk-frac.c b/drivers/clk/mxs/clk-frac.c new file mode 100644 index 000000000000..e6aa6b567d68 --- /dev/null +++ b/drivers/clk/mxs/clk-frac.c | |||
@@ -0,0 +1,139 @@ | |||
1 | /* | ||
2 | * Copyright 2012 Freescale Semiconductor, Inc. | ||
3 | * | ||
4 | * The code contained herein is licensed under the GNU General Public | ||
5 | * License. You may obtain a copy of the GNU General Public License | ||
6 | * Version 2 or later at the following locations: | ||
7 | * | ||
8 | * http://www.opensource.org/licenses/gpl-license.html | ||
9 | * http://www.gnu.org/copyleft/gpl.html | ||
10 | */ | ||
11 | |||
12 | #include <linux/clk.h> | ||
13 | #include <linux/clk-provider.h> | ||
14 | #include <linux/err.h> | ||
15 | #include <linux/io.h> | ||
16 | #include <linux/slab.h> | ||
17 | #include "clk.h" | ||
18 | |||
19 | /** | ||
20 | * struct clk_frac - mxs fractional divider clock | ||
21 | * @hw: clk_hw for the fractional divider clock | ||
22 | * @reg: register address | ||
23 | * @shift: the divider bit shift | ||
24 | * @width: the divider bit width | ||
25 | * @busy: busy bit shift | ||
26 | * | ||
27 | * The clock is an adjustable fractional divider with a busy bit to wait | ||
28 | * when the divider is adjusted. | ||
29 | */ | ||
30 | struct clk_frac { | ||
31 | struct clk_hw hw; | ||
32 | void __iomem *reg; | ||
33 | u8 shift; | ||
34 | u8 width; | ||
35 | u8 busy; | ||
36 | }; | ||
37 | |||
38 | #define to_clk_frac(_hw) container_of(_hw, struct clk_frac, hw) | ||
39 | |||
40 | static unsigned long clk_frac_recalc_rate(struct clk_hw *hw, | ||
41 | unsigned long parent_rate) | ||
42 | { | ||
43 | struct clk_frac *frac = to_clk_frac(hw); | ||
44 | u32 div; | ||
45 | |||
46 | div = readl_relaxed(frac->reg) >> frac->shift; | ||
47 | div &= (1 << frac->width) - 1; | ||
48 | |||
49 | return (parent_rate >> frac->width) * div; | ||
50 | } | ||
51 | |||
52 | static long clk_frac_round_rate(struct clk_hw *hw, unsigned long rate, | ||
53 | unsigned long *prate) | ||
54 | { | ||
55 | struct clk_frac *frac = to_clk_frac(hw); | ||
56 | unsigned long parent_rate = *prate; | ||
57 | u32 div; | ||
58 | u64 tmp; | ||
59 | |||
60 | if (rate > parent_rate) | ||
61 | return -EINVAL; | ||
62 | |||
63 | tmp = rate; | ||
64 | tmp <<= frac->width; | ||
65 | do_div(tmp, parent_rate); | ||
66 | div = tmp; | ||
67 | |||
68 | if (!div) | ||
69 | return -EINVAL; | ||
70 | |||
71 | return (parent_rate >> frac->width) * div; | ||
72 | } | ||
73 | |||
74 | static int clk_frac_set_rate(struct clk_hw *hw, unsigned long rate, | ||
75 | unsigned long parent_rate) | ||
76 | { | ||
77 | struct clk_frac *frac = to_clk_frac(hw); | ||
78 | unsigned long flags; | ||
79 | u32 div, val; | ||
80 | u64 tmp; | ||
81 | |||
82 | if (rate > parent_rate) | ||
83 | return -EINVAL; | ||
84 | |||
85 | tmp = rate; | ||
86 | tmp <<= frac->width; | ||
87 | do_div(tmp, parent_rate); | ||
88 | div = tmp; | ||
89 | |||
90 | if (!div) | ||
91 | return -EINVAL; | ||
92 | |||
93 | spin_lock_irqsave(&mxs_lock, flags); | ||
94 | |||
95 | val = readl_relaxed(frac->reg); | ||
96 | val &= ~(((1 << frac->width) - 1) << frac->shift); | ||
97 | val |= div << frac->shift; | ||
98 | writel_relaxed(val, frac->reg); | ||
99 | |||
100 | spin_unlock_irqrestore(&mxs_lock, flags); | ||
101 | |||
102 | return mxs_clk_wait(frac->reg, frac->busy); | ||
103 | } | ||
104 | |||
105 | static struct clk_ops clk_frac_ops = { | ||
106 | .recalc_rate = clk_frac_recalc_rate, | ||
107 | .round_rate = clk_frac_round_rate, | ||
108 | .set_rate = clk_frac_set_rate, | ||
109 | }; | ||
110 | |||
111 | struct clk *mxs_clk_frac(const char *name, const char *parent_name, | ||
112 | void __iomem *reg, u8 shift, u8 width, u8 busy) | ||
113 | { | ||
114 | struct clk_frac *frac; | ||
115 | struct clk *clk; | ||
116 | struct clk_init_data init; | ||
117 | |||
118 | frac = kzalloc(sizeof(*frac), GFP_KERNEL); | ||
119 | if (!frac) | ||
120 | return ERR_PTR(-ENOMEM); | ||
121 | |||
122 | init.name = name; | ||
123 | init.ops = &clk_frac_ops; | ||
124 | init.flags = CLK_SET_RATE_PARENT; | ||
125 | init.parent_names = (parent_name ? &parent_name: NULL); | ||
126 | init.num_parents = (parent_name ? 1 : 0); | ||
127 | |||
128 | frac->reg = reg; | ||
129 | frac->shift = shift; | ||
130 | frac->width = width; | ||
131 | frac->busy = busy; | ||
132 | frac->hw.init = &init; | ||
133 | |||
134 | clk = clk_register(NULL, &frac->hw); | ||
135 | if (IS_ERR(clk)) | ||
136 | kfree(frac); | ||
137 | |||
138 | return clk; | ||
139 | } | ||
diff --git a/drivers/clk/mxs/clk-pll.c b/drivers/clk/mxs/clk-pll.c new file mode 100644 index 000000000000..fadae41833ec --- /dev/null +++ b/drivers/clk/mxs/clk-pll.c | |||
@@ -0,0 +1,116 @@ | |||
1 | /* | ||
2 | * Copyright 2012 Freescale Semiconductor, Inc. | ||
3 | * | ||
4 | * The code contained herein is licensed under the GNU General Public | ||
5 | * License. You may obtain a copy of the GNU General Public License | ||
6 | * Version 2 or later at the following locations: | ||
7 | * | ||
8 | * http://www.opensource.org/licenses/gpl-license.html | ||
9 | * http://www.gnu.org/copyleft/gpl.html | ||
10 | */ | ||
11 | |||
12 | #include <linux/clk.h> | ||
13 | #include <linux/clk-provider.h> | ||
14 | #include <linux/delay.h> | ||
15 | #include <linux/err.h> | ||
16 | #include <linux/io.h> | ||
17 | #include <linux/slab.h> | ||
18 | #include "clk.h" | ||
19 | |||
20 | /** | ||
21 | * struct clk_pll - mxs pll clock | ||
22 | * @hw: clk_hw for the pll | ||
23 | * @base: base address of the pll | ||
24 | * @power: the shift of power bit | ||
25 | * @rate: the clock rate of the pll | ||
26 | * | ||
27 | * The mxs pll is a fixed rate clock with power and gate control, | ||
28 | * and the shift of gate bit is always 31. | ||
29 | */ | ||
30 | struct clk_pll { | ||
31 | struct clk_hw hw; | ||
32 | void __iomem *base; | ||
33 | u8 power; | ||
34 | unsigned long rate; | ||
35 | }; | ||
36 | |||
37 | #define to_clk_pll(_hw) container_of(_hw, struct clk_pll, hw) | ||
38 | |||
39 | static int clk_pll_prepare(struct clk_hw *hw) | ||
40 | { | ||
41 | struct clk_pll *pll = to_clk_pll(hw); | ||
42 | |||
43 | writel_relaxed(1 << pll->power, pll->base + SET); | ||
44 | |||
45 | udelay(10); | ||
46 | |||
47 | return 0; | ||
48 | } | ||
49 | |||
50 | static void clk_pll_unprepare(struct clk_hw *hw) | ||
51 | { | ||
52 | struct clk_pll *pll = to_clk_pll(hw); | ||
53 | |||
54 | writel_relaxed(1 << pll->power, pll->base + CLR); | ||
55 | } | ||
56 | |||
57 | static int clk_pll_enable(struct clk_hw *hw) | ||
58 | { | ||
59 | struct clk_pll *pll = to_clk_pll(hw); | ||
60 | |||
61 | writel_relaxed(1 << 31, pll->base + CLR); | ||
62 | |||
63 | return 0; | ||
64 | } | ||
65 | |||
66 | static void clk_pll_disable(struct clk_hw *hw) | ||
67 | { | ||
68 | struct clk_pll *pll = to_clk_pll(hw); | ||
69 | |||
70 | writel_relaxed(1 << 31, pll->base + SET); | ||
71 | } | ||
72 | |||
73 | static unsigned long clk_pll_recalc_rate(struct clk_hw *hw, | ||
74 | unsigned long parent_rate) | ||
75 | { | ||
76 | struct clk_pll *pll = to_clk_pll(hw); | ||
77 | |||
78 | return pll->rate; | ||
79 | } | ||
80 | |||
81 | static const struct clk_ops clk_pll_ops = { | ||
82 | .prepare = clk_pll_prepare, | ||
83 | .unprepare = clk_pll_unprepare, | ||
84 | .enable = clk_pll_enable, | ||
85 | .disable = clk_pll_disable, | ||
86 | .recalc_rate = clk_pll_recalc_rate, | ||
87 | }; | ||
88 | |||
89 | struct clk *mxs_clk_pll(const char *name, const char *parent_name, | ||
90 | void __iomem *base, u8 power, unsigned long rate) | ||
91 | { | ||
92 | struct clk_pll *pll; | ||
93 | struct clk *clk; | ||
94 | struct clk_init_data init; | ||
95 | |||
96 | pll = kzalloc(sizeof(*pll), GFP_KERNEL); | ||
97 | if (!pll) | ||
98 | return ERR_PTR(-ENOMEM); | ||
99 | |||
100 | init.name = name; | ||
101 | init.ops = &clk_pll_ops; | ||
102 | init.flags = 0; | ||
103 | init.parent_names = (parent_name ? &parent_name: NULL); | ||
104 | init.num_parents = (parent_name ? 1 : 0); | ||
105 | |||
106 | pll->base = base; | ||
107 | pll->rate = rate; | ||
108 | pll->power = power; | ||
109 | pll->hw.init = &init; | ||
110 | |||
111 | clk = clk_register(NULL, &pll->hw); | ||
112 | if (IS_ERR(clk)) | ||
113 | kfree(pll); | ||
114 | |||
115 | return clk; | ||
116 | } | ||
diff --git a/drivers/clk/mxs/clk-ref.c b/drivers/clk/mxs/clk-ref.c new file mode 100644 index 000000000000..4adeed6c2f94 --- /dev/null +++ b/drivers/clk/mxs/clk-ref.c | |||
@@ -0,0 +1,154 @@ | |||
1 | /* | ||
2 | * Copyright 2012 Freescale Semiconductor, Inc. | ||
3 | * | ||
4 | * The code contained herein is licensed under the GNU General Public | ||
5 | * License. You may obtain a copy of the GNU General Public License | ||
6 | * Version 2 or later at the following locations: | ||
7 | * | ||
8 | * http://www.opensource.org/licenses/gpl-license.html | ||
9 | * http://www.gnu.org/copyleft/gpl.html | ||
10 | */ | ||
11 | |||
12 | #include <linux/clk.h> | ||
13 | #include <linux/clk-provider.h> | ||
14 | #include <linux/err.h> | ||
15 | #include <linux/io.h> | ||
16 | #include <linux/slab.h> | ||
17 | #include "clk.h" | ||
18 | |||
19 | /** | ||
20 | * struct clk_ref - mxs reference clock | ||
21 | * @hw: clk_hw for the reference clock | ||
22 | * @reg: register address | ||
23 | * @idx: the index of the reference clock within the same register | ||
24 | * | ||
25 | * The mxs reference clock sources from pll. Every 4 reference clocks share | ||
26 | * one register space, and @idx is used to identify them. Each reference | ||
27 | * clock has a gate control and a fractional * divider. The rate is calculated | ||
28 | * as pll rate * (18 / FRAC), where FRAC = 18 ~ 35. | ||
29 | */ | ||
30 | struct clk_ref { | ||
31 | struct clk_hw hw; | ||
32 | void __iomem *reg; | ||
33 | u8 idx; | ||
34 | }; | ||
35 | |||
36 | #define to_clk_ref(_hw) container_of(_hw, struct clk_ref, hw) | ||
37 | |||
38 | static int clk_ref_enable(struct clk_hw *hw) | ||
39 | { | ||
40 | struct clk_ref *ref = to_clk_ref(hw); | ||
41 | |||
42 | writel_relaxed(1 << ((ref->idx + 1) * 8 - 1), ref->reg + CLR); | ||
43 | |||
44 | return 0; | ||
45 | } | ||
46 | |||
47 | static void clk_ref_disable(struct clk_hw *hw) | ||
48 | { | ||
49 | struct clk_ref *ref = to_clk_ref(hw); | ||
50 | |||
51 | writel_relaxed(1 << ((ref->idx + 1) * 8 - 1), ref->reg + SET); | ||
52 | } | ||
53 | |||
54 | static unsigned long clk_ref_recalc_rate(struct clk_hw *hw, | ||
55 | unsigned long parent_rate) | ||
56 | { | ||
57 | struct clk_ref *ref = to_clk_ref(hw); | ||
58 | u64 tmp = parent_rate; | ||
59 | u8 frac = (readl_relaxed(ref->reg) >> (ref->idx * 8)) & 0x3f; | ||
60 | |||
61 | tmp *= 18; | ||
62 | do_div(tmp, frac); | ||
63 | |||
64 | return tmp; | ||
65 | } | ||
66 | |||
67 | static long clk_ref_round_rate(struct clk_hw *hw, unsigned long rate, | ||
68 | unsigned long *prate) | ||
69 | { | ||
70 | unsigned long parent_rate = *prate; | ||
71 | u64 tmp = parent_rate; | ||
72 | u8 frac; | ||
73 | |||
74 | tmp = tmp * 18 + rate / 2; | ||
75 | do_div(tmp, rate); | ||
76 | frac = tmp; | ||
77 | |||
78 | if (frac < 18) | ||
79 | frac = 18; | ||
80 | else if (frac > 35) | ||
81 | frac = 35; | ||
82 | |||
83 | tmp = parent_rate; | ||
84 | tmp *= 18; | ||
85 | do_div(tmp, frac); | ||
86 | |||
87 | return tmp; | ||
88 | } | ||
89 | |||
90 | static int clk_ref_set_rate(struct clk_hw *hw, unsigned long rate, | ||
91 | unsigned long parent_rate) | ||
92 | { | ||
93 | struct clk_ref *ref = to_clk_ref(hw); | ||
94 | unsigned long flags; | ||
95 | u64 tmp = parent_rate; | ||
96 | u32 val; | ||
97 | u8 frac, shift = ref->idx * 8; | ||
98 | |||
99 | tmp = tmp * 18 + rate / 2; | ||
100 | do_div(tmp, rate); | ||
101 | frac = tmp; | ||
102 | |||
103 | if (frac < 18) | ||
104 | frac = 18; | ||
105 | else if (frac > 35) | ||
106 | frac = 35; | ||
107 | |||
108 | spin_lock_irqsave(&mxs_lock, flags); | ||
109 | |||
110 | val = readl_relaxed(ref->reg); | ||
111 | val &= ~(0x3f << shift); | ||
112 | val |= frac << shift; | ||
113 | writel_relaxed(val, ref->reg); | ||
114 | |||
115 | spin_unlock_irqrestore(&mxs_lock, flags); | ||
116 | |||
117 | return 0; | ||
118 | } | ||
119 | |||
120 | static const struct clk_ops clk_ref_ops = { | ||
121 | .enable = clk_ref_enable, | ||
122 | .disable = clk_ref_disable, | ||
123 | .recalc_rate = clk_ref_recalc_rate, | ||
124 | .round_rate = clk_ref_round_rate, | ||
125 | .set_rate = clk_ref_set_rate, | ||
126 | }; | ||
127 | |||
128 | struct clk *mxs_clk_ref(const char *name, const char *parent_name, | ||
129 | void __iomem *reg, u8 idx) | ||
130 | { | ||
131 | struct clk_ref *ref; | ||
132 | struct clk *clk; | ||
133 | struct clk_init_data init; | ||
134 | |||
135 | ref = kzalloc(sizeof(*ref), GFP_KERNEL); | ||
136 | if (!ref) | ||
137 | return ERR_PTR(-ENOMEM); | ||
138 | |||
139 | init.name = name; | ||
140 | init.ops = &clk_ref_ops; | ||
141 | init.flags = 0; | ||
142 | init.parent_names = (parent_name ? &parent_name: NULL); | ||
143 | init.num_parents = (parent_name ? 1 : 0); | ||
144 | |||
145 | ref->reg = reg; | ||
146 | ref->idx = idx; | ||
147 | ref->hw.init = &init; | ||
148 | |||
149 | clk = clk_register(NULL, &ref->hw); | ||
150 | if (IS_ERR(clk)) | ||
151 | kfree(ref); | ||
152 | |||
153 | return clk; | ||
154 | } | ||
diff --git a/drivers/clk/mxs/clk.c b/drivers/clk/mxs/clk.c new file mode 100644 index 000000000000..b24d56067c80 --- /dev/null +++ b/drivers/clk/mxs/clk.c | |||
@@ -0,0 +1,28 @@ | |||
1 | /* | ||
2 | * Copyright 2012 Freescale Semiconductor, Inc. | ||
3 | * | ||
4 | * The code contained herein is licensed under the GNU General Public | ||
5 | * License. You may obtain a copy of the GNU General Public License | ||
6 | * Version 2 or later at the following locations: | ||
7 | * | ||
8 | * http://www.opensource.org/licenses/gpl-license.html | ||
9 | * http://www.gnu.org/copyleft/gpl.html | ||
10 | */ | ||
11 | |||
12 | #include <linux/err.h> | ||
13 | #include <linux/io.h> | ||
14 | #include <linux/jiffies.h> | ||
15 | #include <linux/spinlock.h> | ||
16 | |||
17 | DEFINE_SPINLOCK(mxs_lock); | ||
18 | |||
19 | int mxs_clk_wait(void __iomem *reg, u8 shift) | ||
20 | { | ||
21 | unsigned long timeout = jiffies + msecs_to_jiffies(10); | ||
22 | |||
23 | while (readl_relaxed(reg) & (1 << shift)) | ||
24 | if (time_after(jiffies, timeout)) | ||
25 | return -ETIMEDOUT; | ||
26 | |||
27 | return 0; | ||
28 | } | ||
diff --git a/drivers/clk/mxs/clk.h b/drivers/clk/mxs/clk.h new file mode 100644 index 000000000000..81421e28e69c --- /dev/null +++ b/drivers/clk/mxs/clk.h | |||
@@ -0,0 +1,66 @@ | |||
1 | /* | ||
2 | * Copyright 2012 Freescale Semiconductor, Inc. | ||
3 | * | ||
4 | * The code contained herein is licensed under the GNU General Public | ||
5 | * License. You may obtain a copy of the GNU General Public License | ||
6 | * Version 2 or later at the following locations: | ||
7 | * | ||
8 | * http://www.opensource.org/licenses/gpl-license.html | ||
9 | * http://www.gnu.org/copyleft/gpl.html | ||
10 | */ | ||
11 | |||
12 | #ifndef __MXS_CLK_H | ||
13 | #define __MXS_CLK_H | ||
14 | |||
15 | #include <linux/clk.h> | ||
16 | #include <linux/clk-provider.h> | ||
17 | #include <linux/spinlock.h> | ||
18 | |||
19 | #define SET 0x4 | ||
20 | #define CLR 0x8 | ||
21 | |||
22 | extern spinlock_t mxs_lock; | ||
23 | |||
24 | int mxs_clk_wait(void __iomem *reg, u8 shift); | ||
25 | |||
26 | struct clk *mxs_clk_pll(const char *name, const char *parent_name, | ||
27 | void __iomem *base, u8 power, unsigned long rate); | ||
28 | |||
29 | struct clk *mxs_clk_ref(const char *name, const char *parent_name, | ||
30 | void __iomem *reg, u8 idx); | ||
31 | |||
32 | struct clk *mxs_clk_div(const char *name, const char *parent_name, | ||
33 | void __iomem *reg, u8 shift, u8 width, u8 busy); | ||
34 | |||
35 | struct clk *mxs_clk_frac(const char *name, const char *parent_name, | ||
36 | void __iomem *reg, u8 shift, u8 width, u8 busy); | ||
37 | |||
38 | static inline struct clk *mxs_clk_fixed(const char *name, int rate) | ||
39 | { | ||
40 | return clk_register_fixed_rate(NULL, name, NULL, CLK_IS_ROOT, rate); | ||
41 | } | ||
42 | |||
43 | static inline struct clk *mxs_clk_gate(const char *name, | ||
44 | const char *parent_name, void __iomem *reg, u8 shift) | ||
45 | { | ||
46 | return clk_register_gate(NULL, name, parent_name, CLK_SET_RATE_PARENT, | ||
47 | reg, shift, CLK_GATE_SET_TO_DISABLE, | ||
48 | &mxs_lock); | ||
49 | } | ||
50 | |||
51 | static inline struct clk *mxs_clk_mux(const char *name, void __iomem *reg, | ||
52 | u8 shift, u8 width, const char **parent_names, int num_parents) | ||
53 | { | ||
54 | return clk_register_mux(NULL, name, parent_names, num_parents, | ||
55 | CLK_SET_RATE_PARENT, reg, shift, width, | ||
56 | 0, &mxs_lock); | ||
57 | } | ||
58 | |||
59 | static inline struct clk *mxs_clk_fixed_factor(const char *name, | ||
60 | const char *parent_name, unsigned int mult, unsigned int div) | ||
61 | { | ||
62 | return clk_register_fixed_factor(NULL, name, parent_name, | ||
63 | CLK_SET_RATE_PARENT, mult, div); | ||
64 | } | ||
65 | |||
66 | #endif /* __MXS_CLK_H */ | ||