aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/clk/ti/gate.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/clk/ti/gate.c')
-rw-r--r--drivers/clk/ti/gate.c163
1 files changed, 133 insertions, 30 deletions
diff --git a/drivers/clk/ti/gate.c b/drivers/clk/ti/gate.c
index b326d2797feb..d493307b73f4 100644
--- a/drivers/clk/ti/gate.c
+++ b/drivers/clk/ti/gate.c
@@ -22,6 +22,8 @@
22#include <linux/of_address.h> 22#include <linux/of_address.h>
23#include <linux/clk/ti.h> 23#include <linux/clk/ti.h>
24 24
25#include "clock.h"
26
25#define to_clk_divider(_hw) container_of(_hw, struct clk_divider, hw) 27#define to_clk_divider(_hw) container_of(_hw, struct clk_divider, hw)
26 28
27#undef pr_fmt 29#undef pr_fmt
@@ -90,63 +92,164 @@ static int omap36xx_gate_clk_enable_with_hsdiv_restore(struct clk_hw *clk)
90 return ret; 92 return ret;
91} 93}
92 94
93static void __init _of_ti_gate_clk_setup(struct device_node *node, 95static struct clk *_register_gate(struct device *dev, const char *name,
94 const struct clk_ops *ops, 96 const char *parent_name, unsigned long flags,
95 const struct clk_hw_omap_ops *hw_ops) 97 void __iomem *reg, u8 bit_idx,
98 u8 clk_gate_flags, const struct clk_ops *ops,
99 const struct clk_hw_omap_ops *hw_ops)
96{ 100{
97 struct clk *clk;
98 struct clk_init_data init = { NULL }; 101 struct clk_init_data init = { NULL };
99 struct clk_hw_omap *clk_hw; 102 struct clk_hw_omap *clk_hw;
100 const char *clk_name = node->name; 103 struct clk *clk;
101 const char *parent_name;
102 u32 val;
103 104
104 clk_hw = kzalloc(sizeof(*clk_hw), GFP_KERNEL); 105 clk_hw = kzalloc(sizeof(*clk_hw), GFP_KERNEL);
105 if (!clk_hw) 106 if (!clk_hw)
106 return; 107 return ERR_PTR(-ENOMEM);
107 108
108 clk_hw->hw.init = &init; 109 clk_hw->hw.init = &init;
109 110
110 init.name = clk_name; 111 init.name = name;
111 init.ops = ops; 112 init.ops = ops;
112 113
113 if (ops != &omap_gate_clkdm_clk_ops) { 114 clk_hw->enable_reg = reg;
114 clk_hw->enable_reg = ti_clk_get_reg_addr(node, 0); 115 clk_hw->enable_bit = bit_idx;
115 if (!clk_hw->enable_reg) 116 clk_hw->ops = hw_ops;
116 goto cleanup;
117 117
118 if (!of_property_read_u32(node, "ti,bit-shift", &val)) 118 clk_hw->flags = MEMMAP_ADDRESSING | clk_gate_flags;
119 clk_hw->enable_bit = val; 119
120 init.parent_names = &parent_name;
121 init.num_parents = 1;
122
123 init.flags = flags;
124
125 clk = clk_register(NULL, &clk_hw->hw);
126
127 if (IS_ERR(clk))
128 kfree(clk_hw);
129
130 return clk;
131}
132
133#if defined(CONFIG_ARCH_OMAP3) && defined(CONFIG_ATAGS)
134struct clk *ti_clk_register_gate(struct ti_clk *setup)
135{
136 const struct clk_ops *ops = &omap_gate_clk_ops;
137 const struct clk_hw_omap_ops *hw_ops = NULL;
138 u32 reg;
139 struct clk_omap_reg *reg_setup;
140 u32 flags = 0;
141 u8 clk_gate_flags = 0;
142 struct ti_clk_gate *gate;
143
144 gate = setup->data;
145
146 if (gate->flags & CLKF_INTERFACE)
147 return ti_clk_register_interface(setup);
148
149 reg_setup = (struct clk_omap_reg *)&reg;
150
151 if (gate->flags & CLKF_SET_RATE_PARENT)
152 flags |= CLK_SET_RATE_PARENT;
153
154 if (gate->flags & CLKF_SET_BIT_TO_DISABLE)
155 clk_gate_flags |= INVERT_ENABLE;
156
157 if (gate->flags & CLKF_HSDIV) {
158 ops = &omap_gate_clk_hsdiv_restore_ops;
159 hw_ops = &clkhwops_wait;
120 } 160 }
121 161
122 clk_hw->ops = hw_ops; 162 if (gate->flags & CLKF_DSS)
163 hw_ops = &clkhwops_omap3430es2_dss_usbhost_wait;
164
165 if (gate->flags & CLKF_WAIT)
166 hw_ops = &clkhwops_wait;
167
168 if (gate->flags & CLKF_CLKDM)
169 ops = &omap_gate_clkdm_clk_ops;
170
171 if (gate->flags & CLKF_AM35XX)
172 hw_ops = &clkhwops_am35xx_ipss_module_wait;
123 173
124 clk_hw->flags = MEMMAP_ADDRESSING; 174 reg_setup->index = gate->module;
175 reg_setup->offset = gate->reg;
176
177 return _register_gate(NULL, setup->name, gate->parent, flags,
178 (void __iomem *)reg, gate->bit_shift,
179 clk_gate_flags, ops, hw_ops);
180}
181
182struct clk_hw *ti_clk_build_component_gate(struct ti_clk_gate *setup)
183{
184 struct clk_hw_omap *gate;
185 struct clk_omap_reg *reg;
186 const struct clk_hw_omap_ops *ops = &clkhwops_wait;
187
188 if (!setup)
189 return NULL;
190
191 gate = kzalloc(sizeof(*gate), GFP_KERNEL);
192 if (!gate)
193 return ERR_PTR(-ENOMEM);
194
195 reg = (struct clk_omap_reg *)&gate->enable_reg;
196 reg->index = setup->module;
197 reg->offset = setup->reg;
198
199 gate->enable_bit = setup->bit_shift;
200
201 if (setup->flags & CLKF_NO_WAIT)
202 ops = NULL;
203
204 if (setup->flags & CLKF_INTERFACE)
205 ops = &clkhwops_iclk_wait;
206
207 gate->ops = ops;
208 gate->flags = MEMMAP_ADDRESSING;
209
210 return &gate->hw;
211}
212#endif
213
214static void __init _of_ti_gate_clk_setup(struct device_node *node,
215 const struct clk_ops *ops,
216 const struct clk_hw_omap_ops *hw_ops)
217{
218 struct clk *clk;
219 const char *parent_name;
220 void __iomem *reg = NULL;
221 u8 enable_bit = 0;
222 u32 val;
223 u32 flags = 0;
224 u8 clk_gate_flags = 0;
225
226 if (ops != &omap_gate_clkdm_clk_ops) {
227 reg = ti_clk_get_reg_addr(node, 0);
228 if (!reg)
229 return;
230
231 if (!of_property_read_u32(node, "ti,bit-shift", &val))
232 enable_bit = val;
233 }
125 234
126 if (of_clk_get_parent_count(node) != 1) { 235 if (of_clk_get_parent_count(node) != 1) {
127 pr_err("%s must have 1 parent\n", clk_name); 236 pr_err("%s must have 1 parent\n", node->name);
128 goto cleanup; 237 return;
129 } 238 }
130 239
131 parent_name = of_clk_get_parent_name(node, 0); 240 parent_name = of_clk_get_parent_name(node, 0);
132 init.parent_names = &parent_name;
133 init.num_parents = 1;
134 241
135 if (of_property_read_bool(node, "ti,set-rate-parent")) 242 if (of_property_read_bool(node, "ti,set-rate-parent"))
136 init.flags |= CLK_SET_RATE_PARENT; 243 flags |= CLK_SET_RATE_PARENT;
137 244
138 if (of_property_read_bool(node, "ti,set-bit-to-disable")) 245 if (of_property_read_bool(node, "ti,set-bit-to-disable"))
139 clk_hw->flags |= INVERT_ENABLE; 246 clk_gate_flags |= INVERT_ENABLE;
140 247
141 clk = clk_register(NULL, &clk_hw->hw); 248 clk = _register_gate(NULL, node->name, parent_name, flags, reg,
249 enable_bit, clk_gate_flags, ops, hw_ops);
142 250
143 if (!IS_ERR(clk)) { 251 if (!IS_ERR(clk))
144 of_clk_add_provider(node, of_clk_src_simple_get, clk); 252 of_clk_add_provider(node, of_clk_src_simple_get, clk);
145 return;
146 }
147
148cleanup:
149 kfree(clk_hw);
150} 253}
151 254
152static void __init 255static void __init