Skip to content

Commit 4a5917c

Browse files
committed
clk: ti: Improve clksel clock bit parsing for reg property
Because of legacy reasons, the TI clksel composite clocks can have overlapping reg properties, and use a custom ti,bit-shift property. For the clksel clocks we can start using of the standard reg property instead of the custom ti,bit-shift property. To do this, let's add a ti_clk_get_legacy_bit_shift() helper, and make ti_clk_get_reg_addr() populate the clock bit offset. This makes it possible to update the devicetree files to use the reg property one clock at a time. Acked-by: Stephen Boyd <[email protected]> Signed-off-by: Tony Lindgren <[email protected]>
1 parent 3516338 commit 4a5917c

File tree

8 files changed

+63
-33
lines changed

8 files changed

+63
-33
lines changed

drivers/clk/ti/apll.c

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -376,14 +376,9 @@ static void __init of_omap2_apll_setup(struct device_node *node)
376376
}
377377
clk_hw->fixed_rate = val;
378378

379-
if (of_property_read_u32(node, "ti,bit-shift", &val)) {
380-
pr_err("%pOFn missing bit-shift\n", node);
381-
goto cleanup;
382-
}
383-
384-
clk_hw->enable_bit = val;
385-
ad->enable_mask = 0x3 << val;
386-
ad->autoidle_mask = 0x3 << val;
379+
clk_hw->enable_bit = ti_clk_get_legacy_bit_shift(node);
380+
ad->enable_mask = 0x3 << clk_hw->enable_bit;
381+
ad->autoidle_mask = 0x3 << clk_hw->enable_bit;
387382

388383
if (of_property_read_u32(node, "ti,idlest-shift", &val)) {
389384
pr_err("%pOFn missing idlest-shift\n", node);

drivers/clk/ti/clk.c

Lines changed: 50 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include <linux/of.h>
1717
#include <linux/of_address.h>
1818
#include <linux/list.h>
19+
#include <linux/minmax.h>
1920
#include <linux/regmap.h>
2021
#include <linux/string_helpers.h>
2122
#include <linux/memblock.h>
@@ -307,8 +308,9 @@ int __init ti_clk_retry_init(struct device_node *node, void *user,
307308
int ti_clk_get_reg_addr(struct device_node *node, int index,
308309
struct clk_omap_reg *reg)
309310
{
310-
u32 val;
311-
int i;
311+
u32 clksel_addr, val;
312+
bool is_clksel = false;
313+
int i, err;
312314

313315
for (i = 0; i < CLK_MAX_MEMMAPS; i++) {
314316
if (clocks_node_ptr[i] == node->parent)
@@ -324,21 +326,62 @@ int ti_clk_get_reg_addr(struct device_node *node, int index,
324326

325327
reg->index = i;
326328

327-
if (of_property_read_u32_index(node, "reg", index, &val)) {
328-
if (of_property_read_u32_index(node->parent, "reg",
329-
index, &val)) {
330-
pr_err("%pOFn or parent must have reg[%d]!\n",
331-
node, index);
329+
if (of_device_is_compatible(node->parent, "ti,clksel")) {
330+
err = of_property_read_u32_index(node->parent, "reg", index, &clksel_addr);
331+
if (err) {
332+
pr_err("%pOFn parent clksel must have reg[%d]!\n", node, index);
332333
return -EINVAL;
333334
}
335+
is_clksel = true;
336+
}
337+
338+
err = of_property_read_u32_index(node, "reg", index, &val);
339+
if (err && is_clksel) {
340+
/* Legacy clksel with no reg and a possible ti,bit-shift property */
341+
reg->offset = clksel_addr;
342+
reg->bit = ti_clk_get_legacy_bit_shift(node);
343+
reg->ptr = NULL;
344+
345+
return 0;
334346
}
335347

348+
/* Updated clksel clock with a proper reg property */
349+
if (is_clksel) {
350+
reg->offset = clksel_addr;
351+
reg->bit = val;
352+
reg->ptr = NULL;
353+
return 0;
354+
}
355+
356+
/* Other clocks that may or may not have ti,bit-shift property */
336357
reg->offset = val;
358+
reg->bit = ti_clk_get_legacy_bit_shift(node);
337359
reg->ptr = NULL;
338360

339361
return 0;
340362
}
341363

364+
/**
365+
* ti_clk_get_legacy_bit_shift - get bit shift for a clock register
366+
* @node: device node for the clock
367+
*
368+
* Gets the clock register bit shift using the legacy ti,bit-shift
369+
* property. Only needed for legacy clock, and can be eventually
370+
* dropped once all the composite clocks use a clksel node with a
371+
* proper reg property.
372+
*/
373+
int ti_clk_get_legacy_bit_shift(struct device_node *node)
374+
{
375+
int err;
376+
u32 val;
377+
378+
err = of_property_read_u32(node, "ti,bit-shift", &val);
379+
if (!err && in_range(val, 0, 32))
380+
return val;
381+
382+
return 0;
383+
}
384+
342385
void ti_clk_latch(struct clk_omap_reg *reg, s8 shift)
343386
{
344387
u32 latch;

drivers/clk/ti/clock.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,7 @@ int ti_clk_parse_divider_data(int *div_table, int num_dividers, int max_div,
216216

217217
int ti_clk_get_reg_addr(struct device_node *node, int index,
218218
struct clk_omap_reg *reg);
219+
int ti_clk_get_legacy_bit_shift(struct device_node *node);
219220
void ti_dt_clocks_register(struct ti_dt_clk *oclks);
220221
int ti_clk_retry_init(struct device_node *node, void *user,
221222
ti_of_clk_init_cb_t func);

drivers/clk/ti/divider.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -477,10 +477,7 @@ static int __init ti_clk_divider_populate(struct device_node *node,
477477
if (ret)
478478
return ret;
479479

480-
if (!of_property_read_u32(node, "ti,bit-shift", &val))
481-
div->shift = val;
482-
else
483-
div->shift = 0;
480+
div->shift = div->reg.bit;
484481

485482
if (!of_property_read_u32(node, "ti,latch-bit", &val))
486483
div->latch = val;

drivers/clk/ti/gate.c

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -132,16 +132,14 @@ static void __init _of_ti_gate_clk_setup(struct device_node *node,
132132
struct clk_omap_reg reg;
133133
const char *name;
134134
u8 enable_bit = 0;
135-
u32 val;
136135
u32 flags = 0;
137136
u8 clk_gate_flags = 0;
138137

139138
if (ops != &omap_gate_clkdm_clk_ops) {
140139
if (ti_clk_get_reg_addr(node, 0, &reg))
141140
return;
142141

143-
if (!of_property_read_u32(node, "ti,bit-shift", &val))
144-
enable_bit = val;
142+
enable_bit = reg.bit;
145143
}
146144

147145
if (of_clk_get_parent_count(node) != 1) {
@@ -170,7 +168,6 @@ _of_ti_composite_gate_clk_setup(struct device_node *node,
170168
const struct clk_hw_omap_ops *hw_ops)
171169
{
172170
struct clk_hw_omap *gate;
173-
u32 val = 0;
174171

175172
gate = kzalloc(sizeof(*gate), GFP_KERNEL);
176173
if (!gate)
@@ -179,9 +176,7 @@ _of_ti_composite_gate_clk_setup(struct device_node *node,
179176
if (ti_clk_get_reg_addr(node, 0, &gate->enable_reg))
180177
goto cleanup;
181178

182-
of_property_read_u32(node, "ti,bit-shift", &val);
183-
184-
gate->enable_bit = val;
179+
gate->enable_bit = gate->enable_reg.bit;
185180
gate->ops = hw_ops;
186181

187182
if (!ti_clk_add_component(node, &gate->hw, CLK_COMPONENT_TYPE_GATE))

drivers/clk/ti/interface.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,11 @@ static void __init _of_ti_interface_clk_setup(struct device_node *node,
6666
struct clk_omap_reg reg;
6767
u8 enable_bit = 0;
6868
const char *name;
69-
u32 val;
7069

7170
if (ti_clk_get_reg_addr(node, 0, &reg))
7271
return;
7372

74-
if (!of_property_read_u32(node, "ti,bit-shift", &val))
75-
enable_bit = val;
73+
enable_bit = reg.bit;
7674

7775
parent_name = of_clk_get_parent_name(node, 0);
7876
if (!parent_name) {

drivers/clk/ti/mux.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ static void of_mux_clk_setup(struct device_node *node)
189189
if (ti_clk_get_reg_addr(node, 0, &reg))
190190
goto cleanup;
191191

192-
of_property_read_u32(node, "ti,bit-shift", &shift);
192+
shift = reg.bit;
193193

194194
of_property_read_u32(node, "ti,latch-bit", &latch);
195195

@@ -252,7 +252,6 @@ static void __init of_ti_composite_mux_clk_setup(struct device_node *node)
252252
{
253253
struct clk_omap_mux *mux;
254254
unsigned int num_parents;
255-
u32 val;
256255

257256
mux = kzalloc(sizeof(*mux), GFP_KERNEL);
258257
if (!mux)
@@ -261,8 +260,7 @@ static void __init of_ti_composite_mux_clk_setup(struct device_node *node)
261260
if (ti_clk_get_reg_addr(node, 0, &mux->reg))
262261
goto cleanup;
263262

264-
if (!of_property_read_u32(node, "ti,bit-shift", &val))
265-
mux->shift = val;
263+
mux->shift = mux->reg.bit;
266264

267265
if (of_property_read_bool(node, "ti,index-starts-at-one"))
268266
mux->flags |= CLK_MUX_INDEX_ONE;

include/linux/clk/ti.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,14 @@
1313
/**
1414
* struct clk_omap_reg - OMAP register declaration
1515
* @offset: offset from the master IP module base address
16+
* @bit: register bit offset
1617
* @index: index of the master IP module
18+
* @flags: flags
1719
*/
1820
struct clk_omap_reg {
1921
void __iomem *ptr;
2022
u16 offset;
23+
u8 bit;
2124
u8 index;
2225
u8 flags;
2326
};

0 commit comments

Comments
 (0)