diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2012-05-26 15:42:29 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2012-05-26 15:42:29 -0400 |
commit | 27953437059c64d14086196eb96f43c78caa9db3 (patch) | |
tree | 0cfd5fb21262a6db3de0c64462847b4c0c43e9df /arch/arm/mach-imx/clk-pfd.c | |
parent | 2c757fd5d1a92086f225a75a8fac7cab242d11b0 (diff) | |
parent | 3c0dec5f58b3c7b3627715126d1bf9b030a076f0 (diff) |
Merge tag 'clock' of git://git.kernel.org/pub/scm/linux/kernel/git/arm/arm-soc
Pull arm-soc clock driver changes from Olof Johansson:
"The new clock subsystem was merged in linux-3.4 without any users,
this now moves the first three platforms over to it: imx, mxs and
spear.
The series also contains the changes for the clock subsystem itself,
since Mike preferred to have it together with the platforms that
require these changes, in order to avoid interdependencies and
conflicts."
Fix up trivial conflicts in arch/arm/mach-kirkwood/common.c (code
removed in one branch, added OF support in another) and
drivers/dma/imx-sdma.c (independent changes next to each other).
* tag 'clock' of git://git.kernel.org/pub/scm/linux/kernel/git/arm/arm-soc: (97 commits)
clk: Fix CLK_SET_RATE_GATE flag validation in clk_set_rate().
clk: Provide dummy clk_unregister()
SPEAr: Update defconfigs
SPEAr: Add SMI NOR partition info in dts files
SPEAr: Switch to common clock framework
SPEAr: Call clk_prepare() before calling clk_enable
SPEAr: clk: Add General Purpose Timer Synthesizer clock
SPEAr: clk: Add Fractional Synthesizer clock
SPEAr: clk: Add Auxiliary Synthesizer clock
SPEAr: clk: Add VCO-PLL Synthesizer clock
SPEAr: Add DT bindings for SPEAr's timer
ARM i.MX: remove now unused clock files
ARM: i.MX6: implement clocks using common clock framework
ARM i.MX35: implement clocks using common clock framework
ARM i.MX5: implement clocks using common clock framework
ARM: Kirkwood: Replace clock gating
ARM: Orion: Audio: Add clk/clkdev support
ARM: Orion: PCIE: Add support for clk
ARM: Orion: XOR: Add support for clk
ARM: Orion: CESA: Add support for clk
...
Diffstat (limited to 'arch/arm/mach-imx/clk-pfd.c')
-rw-r--r-- | arch/arm/mach-imx/clk-pfd.c | 147 |
1 files changed, 147 insertions, 0 deletions
diff --git a/arch/arm/mach-imx/clk-pfd.c b/arch/arm/mach-imx/clk-pfd.c new file mode 100644 index 000000000000..e2ed4160f329 --- /dev/null +++ b/arch/arm/mach-imx/clk-pfd.c | |||
@@ -0,0 +1,147 @@ | |||
1 | /* | ||
2 | * Copyright 2012 Freescale Semiconductor, Inc. | ||
3 | * Copyright 2012 Linaro Ltd. | ||
4 | * | ||
5 | * The code contained herein is licensed under the GNU General Public | ||
6 | * License. You may obtain a copy of the GNU General Public License | ||
7 | * Version 2 or later at the following locations: | ||
8 | * | ||
9 | * http://www.opensource.org/licenses/gpl-license.html | ||
10 | * http://www.gnu.org/copyleft/gpl.html | ||
11 | */ | ||
12 | |||
13 | #include <linux/clk.h> | ||
14 | #include <linux/clk-provider.h> | ||
15 | #include <linux/io.h> | ||
16 | #include <linux/slab.h> | ||
17 | #include <linux/err.h> | ||
18 | #include "clk.h" | ||
19 | |||
20 | /** | ||
21 | * struct clk_pfd - IMX PFD clock | ||
22 | * @clk_hw: clock source | ||
23 | * @reg: PFD register address | ||
24 | * @idx: the index of PFD encoded in the register | ||
25 | * | ||
26 | * PFD clock found on i.MX6 series. Each register for PFD has 4 clk_pfd | ||
27 | * data encoded, and member idx is used to specify the one. And each | ||
28 | * register has SET, CLR and TOG registers at offset 0x4 0x8 and 0xc. | ||
29 | */ | ||
30 | struct clk_pfd { | ||
31 | struct clk_hw hw; | ||
32 | void __iomem *reg; | ||
33 | u8 idx; | ||
34 | }; | ||
35 | |||
36 | #define to_clk_pfd(_hw) container_of(_hw, struct clk_pfd, hw) | ||
37 | |||
38 | #define SET 0x4 | ||
39 | #define CLR 0x8 | ||
40 | #define OTG 0xc | ||
41 | |||
42 | static int clk_pfd_enable(struct clk_hw *hw) | ||
43 | { | ||
44 | struct clk_pfd *pfd = to_clk_pfd(hw); | ||
45 | |||
46 | writel_relaxed(1 << ((pfd->idx + 1) * 8 - 1), pfd->reg + CLR); | ||
47 | |||
48 | return 0; | ||
49 | } | ||
50 | |||
51 | static void clk_pfd_disable(struct clk_hw *hw) | ||
52 | { | ||
53 | struct clk_pfd *pfd = to_clk_pfd(hw); | ||
54 | |||
55 | writel_relaxed(1 << ((pfd->idx + 1) * 8 - 1), pfd->reg + SET); | ||
56 | } | ||
57 | |||
58 | static unsigned long clk_pfd_recalc_rate(struct clk_hw *hw, | ||
59 | unsigned long parent_rate) | ||
60 | { | ||
61 | struct clk_pfd *pfd = to_clk_pfd(hw); | ||
62 | u64 tmp = parent_rate; | ||
63 | u8 frac = (readl_relaxed(pfd->reg) >> (pfd->idx * 8)) & 0x3f; | ||
64 | |||
65 | tmp *= 18; | ||
66 | do_div(tmp, frac); | ||
67 | |||
68 | return tmp; | ||
69 | } | ||
70 | |||
71 | static long clk_pfd_round_rate(struct clk_hw *hw, unsigned long rate, | ||
72 | unsigned long *prate) | ||
73 | { | ||
74 | u64 tmp = *prate; | ||
75 | u8 frac; | ||
76 | |||
77 | tmp = tmp * 18 + rate / 2; | ||
78 | do_div(tmp, rate); | ||
79 | frac = tmp; | ||
80 | if (frac < 12) | ||
81 | frac = 12; | ||
82 | else if (frac > 35) | ||
83 | frac = 35; | ||
84 | tmp = *prate; | ||
85 | tmp *= 18; | ||
86 | do_div(tmp, frac); | ||
87 | |||
88 | return tmp; | ||
89 | } | ||
90 | |||
91 | static int clk_pfd_set_rate(struct clk_hw *hw, unsigned long rate, | ||
92 | unsigned long parent_rate) | ||
93 | { | ||
94 | struct clk_pfd *pfd = to_clk_pfd(hw); | ||
95 | u64 tmp = parent_rate; | ||
96 | u8 frac; | ||
97 | |||
98 | tmp = tmp * 18 + rate / 2; | ||
99 | do_div(tmp, rate); | ||
100 | frac = tmp; | ||
101 | if (frac < 12) | ||
102 | frac = 12; | ||
103 | else if (frac > 35) | ||
104 | frac = 35; | ||
105 | |||
106 | writel_relaxed(0x3f << (pfd->idx * 8), pfd->reg + CLR); | ||
107 | writel_relaxed(frac << (pfd->idx * 8), pfd->reg + SET); | ||
108 | |||
109 | return 0; | ||
110 | } | ||
111 | |||
112 | static const struct clk_ops clk_pfd_ops = { | ||
113 | .enable = clk_pfd_enable, | ||
114 | .disable = clk_pfd_disable, | ||
115 | .recalc_rate = clk_pfd_recalc_rate, | ||
116 | .round_rate = clk_pfd_round_rate, | ||
117 | .set_rate = clk_pfd_set_rate, | ||
118 | }; | ||
119 | |||
120 | struct clk *imx_clk_pfd(const char *name, const char *parent_name, | ||
121 | void __iomem *reg, u8 idx) | ||
122 | { | ||
123 | struct clk_pfd *pfd; | ||
124 | struct clk *clk; | ||
125 | struct clk_init_data init; | ||
126 | |||
127 | pfd = kzalloc(sizeof(*pfd), GFP_KERNEL); | ||
128 | if (!pfd) | ||
129 | return ERR_PTR(-ENOMEM); | ||
130 | |||
131 | pfd->reg = reg; | ||
132 | pfd->idx = idx; | ||
133 | |||
134 | init.name = name; | ||
135 | init.ops = &clk_pfd_ops; | ||
136 | init.flags = 0; | ||
137 | init.parent_names = &parent_name; | ||
138 | init.num_parents = 1; | ||
139 | |||
140 | pfd->hw.init = &init; | ||
141 | |||
142 | clk = clk_register(NULL, &pfd->hw); | ||
143 | if (IS_ERR(clk)) | ||
144 | kfree(pfd); | ||
145 | |||
146 | return clk; | ||
147 | } | ||