diff options
author | Stephen Boyd <sboyd@codeaurora.org> | 2014-01-15 13:47:26 -0500 |
---|---|---|
committer | Mike Turquette <mturquette@linaro.org> | 2014-01-16 15:01:01 -0500 |
commit | 6e0ad1b6c1c9809a8ea9ca647cbc0471e8b4164d (patch) | |
tree | c6e6357fa0d38b8cab82030f0c997afe5058598f /drivers | |
parent | bcd61c0f535a04a2aaa3f3ba27e60fae681fc88f (diff) |
clk: qcom: Add support for branches/gate clocks
Signed-off-by: Stephen Boyd <sboyd@codeaurora.org>
Signed-off-by: Mike Turquette <mturquette@linaro.org>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/clk/qcom/Makefile | 1 | ||||
-rw-r--r-- | drivers/clk/qcom/clk-branch.c | 159 | ||||
-rw-r--r-- | drivers/clk/qcom/clk-branch.h | 56 |
3 files changed, 216 insertions, 0 deletions
diff --git a/drivers/clk/qcom/Makefile b/drivers/clk/qcom/Makefile index 5d0a6e0ac01f..1b4f75f58031 100644 --- a/drivers/clk/qcom/Makefile +++ b/drivers/clk/qcom/Makefile | |||
@@ -4,3 +4,4 @@ clk-qcom-$(CONFIG_COMMON_CLK_QCOM) += clk-regmap.o | |||
4 | clk-qcom-$(CONFIG_COMMON_CLK_QCOM) += clk-pll.o | 4 | clk-qcom-$(CONFIG_COMMON_CLK_QCOM) += clk-pll.o |
5 | clk-qcom-$(CONFIG_COMMON_CLK_QCOM) += clk-rcg.o | 5 | clk-qcom-$(CONFIG_COMMON_CLK_QCOM) += clk-rcg.o |
6 | clk-qcom-$(CONFIG_COMMON_CLK_QCOM) += clk-rcg2.o | 6 | clk-qcom-$(CONFIG_COMMON_CLK_QCOM) += clk-rcg2.o |
7 | clk-qcom-$(CONFIG_COMMON_CLK_QCOM) += clk-branch.o | ||
diff --git a/drivers/clk/qcom/clk-branch.c b/drivers/clk/qcom/clk-branch.c new file mode 100644 index 000000000000..6b4d2bcb1a53 --- /dev/null +++ b/drivers/clk/qcom/clk-branch.c | |||
@@ -0,0 +1,159 @@ | |||
1 | /* | ||
2 | * Copyright (c) 2013, The Linux Foundation. All rights reserved. | ||
3 | * | ||
4 | * This software is licensed under the terms of the GNU General Public | ||
5 | * License version 2, as published by the Free Software Foundation, and | ||
6 | * may be copied, distributed, and modified under those terms. | ||
7 | * | ||
8 | * This program is distributed in the hope that it will be useful, | ||
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
11 | * GNU General Public License for more details. | ||
12 | */ | ||
13 | |||
14 | #include <linux/kernel.h> | ||
15 | #include <linux/bitops.h> | ||
16 | #include <linux/err.h> | ||
17 | #include <linux/delay.h> | ||
18 | #include <linux/export.h> | ||
19 | #include <linux/clk-provider.h> | ||
20 | #include <linux/regmap.h> | ||
21 | |||
22 | #include "clk-branch.h" | ||
23 | |||
24 | static bool clk_branch_in_hwcg_mode(const struct clk_branch *br) | ||
25 | { | ||
26 | u32 val; | ||
27 | |||
28 | if (!br->hwcg_reg) | ||
29 | return 0; | ||
30 | |||
31 | regmap_read(br->clkr.regmap, br->hwcg_reg, &val); | ||
32 | |||
33 | return !!(val & BIT(br->hwcg_bit)); | ||
34 | } | ||
35 | |||
36 | static bool clk_branch_check_halt(const struct clk_branch *br, bool enabling) | ||
37 | { | ||
38 | bool invert = (br->halt_check == BRANCH_HALT_ENABLE); | ||
39 | u32 val; | ||
40 | |||
41 | regmap_read(br->clkr.regmap, br->halt_reg, &val); | ||
42 | |||
43 | val &= BIT(br->halt_bit); | ||
44 | if (invert) | ||
45 | val = !val; | ||
46 | |||
47 | return !!val == !enabling; | ||
48 | } | ||
49 | |||
50 | #define BRANCH_CLK_OFF BIT(31) | ||
51 | #define BRANCH_NOC_FSM_STATUS_SHIFT 28 | ||
52 | #define BRANCH_NOC_FSM_STATUS_MASK 0x7 | ||
53 | #define BRANCH_NOC_FSM_STATUS_ON (0x2 << BRANCH_NOC_FSM_STATUS_SHIFT) | ||
54 | |||
55 | static bool clk_branch2_check_halt(const struct clk_branch *br, bool enabling) | ||
56 | { | ||
57 | u32 val; | ||
58 | u32 mask; | ||
59 | |||
60 | mask = BRANCH_NOC_FSM_STATUS_MASK << BRANCH_NOC_FSM_STATUS_SHIFT; | ||
61 | mask |= BRANCH_CLK_OFF; | ||
62 | |||
63 | regmap_read(br->clkr.regmap, br->halt_reg, &val); | ||
64 | |||
65 | if (enabling) { | ||
66 | val &= mask; | ||
67 | return (val & BRANCH_CLK_OFF) == 0 || | ||
68 | val == BRANCH_NOC_FSM_STATUS_ON; | ||
69 | } else { | ||
70 | return val & BRANCH_CLK_OFF; | ||
71 | } | ||
72 | } | ||
73 | |||
74 | static int clk_branch_wait(const struct clk_branch *br, bool enabling, | ||
75 | bool (check_halt)(const struct clk_branch *, bool)) | ||
76 | { | ||
77 | bool voted = br->halt_check & BRANCH_VOTED; | ||
78 | const char *name = __clk_get_name(br->clkr.hw.clk); | ||
79 | |||
80 | /* Skip checking halt bit if the clock is in hardware gated mode */ | ||
81 | if (clk_branch_in_hwcg_mode(br)) | ||
82 | return 0; | ||
83 | |||
84 | if (br->halt_check == BRANCH_HALT_DELAY || (!enabling && voted)) { | ||
85 | udelay(10); | ||
86 | } else if (br->halt_check == BRANCH_HALT_ENABLE || | ||
87 | br->halt_check == BRANCH_HALT || | ||
88 | (enabling && voted)) { | ||
89 | int count = 200; | ||
90 | |||
91 | while (count-- > 0) { | ||
92 | if (check_halt(br, enabling)) | ||
93 | return 0; | ||
94 | udelay(1); | ||
95 | } | ||
96 | WARN(1, "%s status stuck at 'o%s'", name, | ||
97 | enabling ? "ff" : "n"); | ||
98 | return -EBUSY; | ||
99 | } | ||
100 | return 0; | ||
101 | } | ||
102 | |||
103 | static int clk_branch_toggle(struct clk_hw *hw, bool en, | ||
104 | bool (check_halt)(const struct clk_branch *, bool)) | ||
105 | { | ||
106 | struct clk_branch *br = to_clk_branch(hw); | ||
107 | int ret; | ||
108 | |||
109 | if (en) { | ||
110 | ret = clk_enable_regmap(hw); | ||
111 | if (ret) | ||
112 | return ret; | ||
113 | } else { | ||
114 | clk_disable_regmap(hw); | ||
115 | } | ||
116 | |||
117 | return clk_branch_wait(br, en, check_halt); | ||
118 | } | ||
119 | |||
120 | static int clk_branch_enable(struct clk_hw *hw) | ||
121 | { | ||
122 | return clk_branch_toggle(hw, true, clk_branch_check_halt); | ||
123 | } | ||
124 | |||
125 | static void clk_branch_disable(struct clk_hw *hw) | ||
126 | { | ||
127 | clk_branch_toggle(hw, false, clk_branch_check_halt); | ||
128 | } | ||
129 | |||
130 | const struct clk_ops clk_branch_ops = { | ||
131 | .enable = clk_branch_enable, | ||
132 | .disable = clk_branch_disable, | ||
133 | .is_enabled = clk_is_enabled_regmap, | ||
134 | }; | ||
135 | EXPORT_SYMBOL_GPL(clk_branch_ops); | ||
136 | |||
137 | static int clk_branch2_enable(struct clk_hw *hw) | ||
138 | { | ||
139 | return clk_branch_toggle(hw, true, clk_branch2_check_halt); | ||
140 | } | ||
141 | |||
142 | static void clk_branch2_disable(struct clk_hw *hw) | ||
143 | { | ||
144 | clk_branch_toggle(hw, false, clk_branch2_check_halt); | ||
145 | } | ||
146 | |||
147 | const struct clk_ops clk_branch2_ops = { | ||
148 | .enable = clk_branch2_enable, | ||
149 | .disable = clk_branch2_disable, | ||
150 | .is_enabled = clk_is_enabled_regmap, | ||
151 | }; | ||
152 | EXPORT_SYMBOL_GPL(clk_branch2_ops); | ||
153 | |||
154 | const struct clk_ops clk_branch_simple_ops = { | ||
155 | .enable = clk_enable_regmap, | ||
156 | .disable = clk_disable_regmap, | ||
157 | .is_enabled = clk_is_enabled_regmap, | ||
158 | }; | ||
159 | EXPORT_SYMBOL_GPL(clk_branch_simple_ops); | ||
diff --git a/drivers/clk/qcom/clk-branch.h b/drivers/clk/qcom/clk-branch.h new file mode 100644 index 000000000000..284df3f3c55f --- /dev/null +++ b/drivers/clk/qcom/clk-branch.h | |||
@@ -0,0 +1,56 @@ | |||
1 | /* | ||
2 | * Copyright (c) 2013, The Linux Foundation. All rights reserved. | ||
3 | * | ||
4 | * This software is licensed under the terms of the GNU General Public | ||
5 | * License version 2, as published by the Free Software Foundation, and | ||
6 | * may be copied, distributed, and modified under those terms. | ||
7 | * | ||
8 | * This program is distributed in the hope that it will be useful, | ||
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
11 | * GNU General Public License for more details. | ||
12 | */ | ||
13 | |||
14 | #ifndef __QCOM_CLK_BRANCH_H__ | ||
15 | #define __QCOM_CLK_BRANCH_H__ | ||
16 | |||
17 | #include <linux/clk-provider.h> | ||
18 | |||
19 | #include "clk-regmap.h" | ||
20 | |||
21 | /** | ||
22 | * struct clk_branch - gating clock with status bit and dynamic hardware gating | ||
23 | * | ||
24 | * @hwcg_reg: dynamic hardware clock gating register | ||
25 | * @hwcg_bit: ORed with @hwcg_reg to enable dynamic hardware clock gating | ||
26 | * @halt_reg: halt register | ||
27 | * @halt_bit: ANDed with @halt_reg to test for clock halted | ||
28 | * @halt_check: type of halt checking to perform | ||
29 | * @clkr: handle between common and hardware-specific interfaces | ||
30 | * | ||
31 | * Clock which can gate its output. | ||
32 | */ | ||
33 | struct clk_branch { | ||
34 | u32 hwcg_reg; | ||
35 | u32 halt_reg; | ||
36 | u8 hwcg_bit; | ||
37 | u8 halt_bit; | ||
38 | u8 halt_check; | ||
39 | #define BRANCH_VOTED BIT(7) /* Delay on disable */ | ||
40 | #define BRANCH_HALT 0 /* pol: 1 = halt */ | ||
41 | #define BRANCH_HALT_VOTED (BRANCH_HALT | BRANCH_VOTED) | ||
42 | #define BRANCH_HALT_ENABLE 1 /* pol: 0 = halt */ | ||
43 | #define BRANCH_HALT_ENABLE_VOTED (BRANCH_HALT_ENABLE | BRANCH_VOTED) | ||
44 | #define BRANCH_HALT_DELAY 2 /* No bit to check; just delay */ | ||
45 | |||
46 | struct clk_regmap clkr; | ||
47 | }; | ||
48 | |||
49 | extern const struct clk_ops clk_branch_ops; | ||
50 | extern const struct clk_ops clk_branch2_ops; | ||
51 | extern const struct clk_ops clk_branch_simple_ops; | ||
52 | |||
53 | #define to_clk_branch(_hw) \ | ||
54 | container_of(to_clk_regmap(_hw), struct clk_branch, clkr) | ||
55 | |||
56 | #endif | ||