diff options
author | Heiko Stuebner <heiko@sntech.de> | 2015-07-05 05:00:14 -0400 |
---|---|---|
committer | Stephen Boyd <sboyd@codeaurora.org> | 2015-07-06 18:04:40 -0400 |
commit | 8a76f443a9ea6f7f72ede9f95fe0ca5b90f09a43 (patch) | |
tree | 3d15fd17c70ea1dd6e43efc55ac78a6fe6842b11 | |
parent | 6f085072534363b68c705d54b9dbbed0474ff357 (diff) |
clk: rockchip: add support for phase inverters
Most Rockchip socs have optional phase inverters connected to some
clocks that move the clock-phase by 180 degrees.
Signed-off-by: Heiko Stuebner <heiko@sntech.de>
[sboyd@codeaurora.org: Dropped lazy part of commit text]
Signed-off-by: Stephen Boyd <sboyd@codeaurora.org>
-rw-r--r-- | drivers/clk/rockchip/Makefile | 1 | ||||
-rw-r--r-- | drivers/clk/rockchip/clk-inverter.c | 116 | ||||
-rw-r--r-- | drivers/clk/rockchip/clk.c | 7 | ||||
-rw-r--r-- | drivers/clk/rockchip/clk.h | 20 |
4 files changed, 144 insertions, 0 deletions
diff --git a/drivers/clk/rockchip/Makefile b/drivers/clk/rockchip/Makefile index 2714097f90db..fd71c7df03d1 100644 --- a/drivers/clk/rockchip/Makefile +++ b/drivers/clk/rockchip/Makefile | |||
@@ -6,6 +6,7 @@ obj-y += clk-rockchip.o | |||
6 | obj-y += clk.o | 6 | obj-y += clk.o |
7 | obj-y += clk-pll.o | 7 | obj-y += clk-pll.o |
8 | obj-y += clk-cpu.o | 8 | obj-y += clk-cpu.o |
9 | obj-y += clk-inverter.o | ||
9 | obj-y += clk-mmc-phase.o | 10 | obj-y += clk-mmc-phase.o |
10 | obj-$(CONFIG_RESET_CONTROLLER) += softrst.o | 11 | obj-$(CONFIG_RESET_CONTROLLER) += softrst.o |
11 | 12 | ||
diff --git a/drivers/clk/rockchip/clk-inverter.c b/drivers/clk/rockchip/clk-inverter.c new file mode 100644 index 000000000000..8054fdb5effb --- /dev/null +++ b/drivers/clk/rockchip/clk-inverter.c | |||
@@ -0,0 +1,116 @@ | |||
1 | /* | ||
2 | * Copyright 2015 Heiko Stuebner <heiko@sntech.de> | ||
3 | * | ||
4 | * This program is free software; you can redistribute it and/or modify | ||
5 | * it under the terms of the GNU General Public License as published by | ||
6 | * the Free Software Foundation; either version 2 of the License, or | ||
7 | * (at your option) any later version. | ||
8 | * | ||
9 | * This program is distributed in the hope that it will be useful, | ||
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
12 | * GNU General Public License for more details. | ||
13 | */ | ||
14 | |||
15 | #include <linux/slab.h> | ||
16 | #include <linux/clk-provider.h> | ||
17 | #include <linux/io.h> | ||
18 | #include <linux/spinlock.h> | ||
19 | #include <linux/kernel.h> | ||
20 | #include "clk.h" | ||
21 | |||
22 | struct rockchip_inv_clock { | ||
23 | struct clk_hw hw; | ||
24 | void __iomem *reg; | ||
25 | int shift; | ||
26 | int flags; | ||
27 | spinlock_t *lock; | ||
28 | }; | ||
29 | |||
30 | #define to_inv_clock(_hw) container_of(_hw, struct rockchip_inv_clock, hw) | ||
31 | |||
32 | #define INVERTER_MASK 0x1 | ||
33 | |||
34 | static int rockchip_inv_get_phase(struct clk_hw *hw) | ||
35 | { | ||
36 | struct rockchip_inv_clock *inv_clock = to_inv_clock(hw); | ||
37 | u32 val; | ||
38 | |||
39 | val = readl(inv_clock->reg) >> inv_clock->shift; | ||
40 | val &= INVERTER_MASK; | ||
41 | return val ? 180 : 0; | ||
42 | } | ||
43 | |||
44 | static int rockchip_inv_set_phase(struct clk_hw *hw, int degrees) | ||
45 | { | ||
46 | struct rockchip_inv_clock *inv_clock = to_inv_clock(hw); | ||
47 | u32 val; | ||
48 | |||
49 | if (degrees % 180 == 0) { | ||
50 | val = !!degrees; | ||
51 | } else { | ||
52 | pr_err("%s: unsupported phase %d for %s\n", | ||
53 | __func__, degrees, __clk_get_name(hw->clk)); | ||
54 | return -EINVAL; | ||
55 | } | ||
56 | |||
57 | if (inv_clock->flags & ROCKCHIP_INVERTER_HIWORD_MASK) { | ||
58 | writel(HIWORD_UPDATE(val, INVERTER_MASK, inv_clock->shift), | ||
59 | inv_clock->reg); | ||
60 | } else { | ||
61 | unsigned long flags; | ||
62 | u32 reg; | ||
63 | |||
64 | spin_lock_irqsave(inv_clock->lock, flags); | ||
65 | |||
66 | reg = readl(inv_clock->reg); | ||
67 | reg &= ~BIT(inv_clock->shift); | ||
68 | reg |= val; | ||
69 | writel(reg, inv_clock->reg); | ||
70 | |||
71 | spin_unlock_irqrestore(inv_clock->lock, flags); | ||
72 | } | ||
73 | |||
74 | return 0; | ||
75 | } | ||
76 | |||
77 | static const struct clk_ops rockchip_inv_clk_ops = { | ||
78 | .get_phase = rockchip_inv_get_phase, | ||
79 | .set_phase = rockchip_inv_set_phase, | ||
80 | }; | ||
81 | |||
82 | struct clk *rockchip_clk_register_inverter(const char *name, | ||
83 | const char *const *parent_names, u8 num_parents, | ||
84 | void __iomem *reg, int shift, int flags, | ||
85 | spinlock_t *lock) | ||
86 | { | ||
87 | struct clk_init_data init; | ||
88 | struct rockchip_inv_clock *inv_clock; | ||
89 | struct clk *clk; | ||
90 | |||
91 | inv_clock = kmalloc(sizeof(*inv_clock), GFP_KERNEL); | ||
92 | if (!inv_clock) | ||
93 | return NULL; | ||
94 | |||
95 | init.name = name; | ||
96 | init.num_parents = num_parents; | ||
97 | init.flags = CLK_SET_RATE_PARENT; | ||
98 | init.parent_names = parent_names; | ||
99 | init.ops = &rockchip_inv_clk_ops; | ||
100 | |||
101 | inv_clock->hw.init = &init; | ||
102 | inv_clock->reg = reg; | ||
103 | inv_clock->shift = shift; | ||
104 | inv_clock->flags = flags; | ||
105 | inv_clock->lock = lock; | ||
106 | |||
107 | clk = clk_register(NULL, &inv_clock->hw); | ||
108 | if (IS_ERR(clk)) | ||
109 | goto err_free; | ||
110 | |||
111 | return clk; | ||
112 | |||
113 | err_free: | ||
114 | kfree(inv_clock); | ||
115 | return NULL; | ||
116 | } | ||
diff --git a/drivers/clk/rockchip/clk.c b/drivers/clk/rockchip/clk.c index 052b94db0ff9..24938815655f 100644 --- a/drivers/clk/rockchip/clk.c +++ b/drivers/clk/rockchip/clk.c | |||
@@ -277,6 +277,13 @@ void __init rockchip_clk_register_branches( | |||
277 | list->div_shift | 277 | list->div_shift |
278 | ); | 278 | ); |
279 | break; | 279 | break; |
280 | case branch_inverter: | ||
281 | clk = rockchip_clk_register_inverter( | ||
282 | list->name, list->parent_names, | ||
283 | list->num_parents, | ||
284 | reg_base + list->muxdiv_offset, | ||
285 | list->div_shift, list->div_flags, &clk_lock); | ||
286 | break; | ||
280 | } | 287 | } |
281 | 288 | ||
282 | /* none of the cases above matched */ | 289 | /* none of the cases above matched */ |
diff --git a/drivers/clk/rockchip/clk.h b/drivers/clk/rockchip/clk.h index 501f02ea9d4b..b72dad074a75 100644 --- a/drivers/clk/rockchip/clk.h +++ b/drivers/clk/rockchip/clk.h | |||
@@ -182,6 +182,13 @@ struct clk *rockchip_clk_register_mmc(const char *name, | |||
182 | const char *const *parent_names, u8 num_parents, | 182 | const char *const *parent_names, u8 num_parents, |
183 | void __iomem *reg, int shift); | 183 | void __iomem *reg, int shift); |
184 | 184 | ||
185 | #define ROCKCHIP_INVERTER_HIWORD_MASK BIT(0) | ||
186 | |||
187 | struct clk *rockchip_clk_register_inverter(const char *name, | ||
188 | const char *const *parent_names, u8 num_parents, | ||
189 | void __iomem *reg, int shift, int flags, | ||
190 | spinlock_t *lock); | ||
191 | |||
185 | #define PNAME(x) static const char *const x[] __initconst | 192 | #define PNAME(x) static const char *const x[] __initconst |
186 | 193 | ||
187 | enum rockchip_clk_branch_type { | 194 | enum rockchip_clk_branch_type { |
@@ -191,6 +198,7 @@ enum rockchip_clk_branch_type { | |||
191 | branch_fraction_divider, | 198 | branch_fraction_divider, |
192 | branch_gate, | 199 | branch_gate, |
193 | branch_mmc, | 200 | branch_mmc, |
201 | branch_inverter, | ||
194 | }; | 202 | }; |
195 | 203 | ||
196 | struct rockchip_clk_branch { | 204 | struct rockchip_clk_branch { |
@@ -414,6 +422,18 @@ struct rockchip_clk_branch { | |||
414 | .div_shift = shift, \ | 422 | .div_shift = shift, \ |
415 | } | 423 | } |
416 | 424 | ||
425 | #define INVERTER(_id, cname, pname, io, is, if) \ | ||
426 | { \ | ||
427 | .id = _id, \ | ||
428 | .branch_type = branch_inverter, \ | ||
429 | .name = cname, \ | ||
430 | .parent_names = (const char *[]){ pname }, \ | ||
431 | .num_parents = 1, \ | ||
432 | .muxdiv_offset = io, \ | ||
433 | .div_shift = is, \ | ||
434 | .div_flags = if, \ | ||
435 | } | ||
436 | |||
417 | void rockchip_clk_init(struct device_node *np, void __iomem *base, | 437 | void rockchip_clk_init(struct device_node *np, void __iomem *base, |
418 | unsigned long nr_clks); | 438 | unsigned long nr_clks); |
419 | struct regmap *rockchip_clk_get_grf(void); | 439 | struct regmap *rockchip_clk_get_grf(void); |