Skip to content

Commit fbbc185

Browse files
author
Tero Kristo
committed
clk: ti: divider: cleanup _register_divider and ti_clk_get_div_table
Cleanup couple of TI divider clock internal APIs. These currently pass huge amount of parameters, which makes it difficult to track what is going on. Abstract most of these under struct clk_omap_div which gets passed over the APIs. Signed-off-by: Tero Kristo <[email protected]> Tested-by: Adam Ford <[email protected]>
1 parent ece3e46 commit fbbc185

File tree

1 file changed

+41
-72
lines changed

1 file changed

+41
-72
lines changed

drivers/clk/ti/divider.c

Lines changed: 41 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -310,47 +310,26 @@ const struct clk_ops ti_clk_divider_ops = {
310310
.restore_context = clk_divider_restore_context,
311311
};
312312

313-
static struct clk *_register_divider(struct device *dev, const char *name,
314-
const char *parent_name,
315-
unsigned long flags,
316-
struct clk_omap_reg *reg,
317-
u8 shift, u8 width, s8 latch,
318-
u8 clk_divider_flags,
319-
const struct clk_div_table *table)
313+
static struct clk *_register_divider(struct device_node *node,
314+
u32 flags,
315+
struct clk_omap_divider *div)
320316
{
321-
struct clk_omap_divider *div;
322317
struct clk *clk;
323318
struct clk_init_data init;
319+
const char *parent_name;
324320

325-
if (clk_divider_flags & CLK_DIVIDER_HIWORD_MASK) {
326-
if (width + shift > 16) {
327-
pr_warn("divider value exceeds LOWORD field\n");
328-
return ERR_PTR(-EINVAL);
329-
}
330-
}
331-
332-
/* allocate the divider */
333-
div = kzalloc(sizeof(*div), GFP_KERNEL);
334-
if (!div)
335-
return ERR_PTR(-ENOMEM);
321+
parent_name = of_clk_get_parent_name(node, 0);
336322

337-
init.name = name;
323+
init.name = node->name;
338324
init.ops = &ti_clk_divider_ops;
339325
init.flags = flags;
340326
init.parent_names = (parent_name ? &parent_name : NULL);
341327
init.num_parents = (parent_name ? 1 : 0);
342328

343-
/* struct clk_divider assignments */
344-
memcpy(&div->reg, reg, sizeof(*reg));
345-
div->shift = shift;
346-
div->width = width;
347-
div->latch = latch;
348-
div->flags = clk_divider_flags;
349329
div->hw.init = &init;
350-
div->table = table;
351330

352331
/* register the clock */
353-
clk = ti_clk_register(dev, &div->hw, name);
332+
clk = ti_clk_register(NULL, &div->hw, node->name);
354333

355334
if (IS_ERR(clk))
356335
kfree(div);
@@ -425,8 +404,8 @@ int ti_clk_parse_divider_data(int *div_table, int num_dividers, int max_div,
425404
return 0;
426405
}
427406

428-
static struct clk_div_table *
429-
__init ti_clk_get_div_table(struct device_node *node)
407+
static int __init ti_clk_get_div_table(struct device_node *node,
408+
struct clk_omap_divider *div)
430409
{
431410
struct clk_div_table *table;
432411
const __be32 *divspec;
@@ -438,7 +417,7 @@ __init ti_clk_get_div_table(struct device_node *node)
438417
divspec = of_get_property(node, "ti,dividers", &num_div);
439418

440419
if (!divspec)
441-
return NULL;
420+
return 0;
442421

443422
num_div /= 4;
444423

@@ -453,13 +432,12 @@ __init ti_clk_get_div_table(struct device_node *node)
453432

454433
if (!valid_div) {
455434
pr_err("no valid dividers for %pOFn table\n", node);
456-
return ERR_PTR(-EINVAL);
435+
return -EINVAL;
457436
}
458437

459438
table = kcalloc(valid_div + 1, sizeof(*table), GFP_KERNEL);
460-
461439
if (!table)
462-
return ERR_PTR(-ENOMEM);
440+
return -ENOMEM;
463441

464442
valid_div = 0;
465443

@@ -472,7 +450,9 @@ __init ti_clk_get_div_table(struct device_node *node)
472450
}
473451
}
474452

475-
return table;
453+
div->table = table;
454+
455+
return 0;
476456
}
477457

478458
static int _get_divider_width(struct device_node *node,
@@ -520,46 +500,43 @@ static int _get_divider_width(struct device_node *node,
520500
}
521501

522502
static int __init ti_clk_divider_populate(struct device_node *node,
523-
struct clk_omap_reg *reg, const struct clk_div_table **table,
524-
u32 *flags, u8 *div_flags, u8 *width, u8 *shift, s8 *latch)
503+
struct clk_omap_divider *div,
504+
u32 *flags)
525505
{
526506
u32 val;
527507
int ret;
528508

529-
ret = ti_clk_get_reg_addr(node, 0, reg);
509+
ret = ti_clk_get_reg_addr(node, 0, &div->reg);
530510
if (ret)
531511
return ret;
532512

533513
if (!of_property_read_u32(node, "ti,bit-shift", &val))
534-
*shift = val;
514+
div->shift = val;
535515
else
536-
*shift = 0;
516+
div->shift = 0;
537517

538-
if (latch) {
539-
if (!of_property_read_u32(node, "ti,latch-bit", &val))
540-
*latch = val;
541-
else
542-
*latch = -EINVAL;
543-
}
518+
if (!of_property_read_u32(node, "ti,latch-bit", &val))
519+
div->latch = val;
520+
else
521+
div->latch = -EINVAL;
544522

545523
*flags = 0;
546-
*div_flags = 0;
524+
div->flags = 0;
547525

548526
if (of_property_read_bool(node, "ti,index-starts-at-one"))
549-
*div_flags |= CLK_DIVIDER_ONE_BASED;
527+
div->flags |= CLK_DIVIDER_ONE_BASED;
550528

551529
if (of_property_read_bool(node, "ti,index-power-of-two"))
552-
*div_flags |= CLK_DIVIDER_POWER_OF_TWO;
530+
div->flags |= CLK_DIVIDER_POWER_OF_TWO;
553531

554532
if (of_property_read_bool(node, "ti,set-rate-parent"))
555533
*flags |= CLK_SET_RATE_PARENT;
556534

557-
*table = ti_clk_get_div_table(node);
558-
559-
if (IS_ERR(*table))
560-
return PTR_ERR(*table);
535+
ret = ti_clk_get_div_table(node, div);
536+
if (ret)
537+
return ret;
561538

562-
*width = _get_divider_width(node, *table, *div_flags);
539+
div->width = _get_divider_width(node, div->table, div->flags);
563540

564541
return 0;
565542
}
@@ -573,47 +550,39 @@ static int __init ti_clk_divider_populate(struct device_node *node,
573550
static void __init of_ti_divider_clk_setup(struct device_node *node)
574551
{
575552
struct clk *clk;
576-
const char *parent_name;
577-
struct clk_omap_reg reg;
578-
u8 clk_divider_flags = 0;
579-
u8 width = 0;
580-
u8 shift = 0;
581-
s8 latch = -EINVAL;
582-
const struct clk_div_table *table = NULL;
583553
u32 flags = 0;
554+
struct clk_omap_divider *div;
584555

585-
parent_name = of_clk_get_parent_name(node, 0);
556+
div = kzalloc(sizeof(*div), GFP_KERNEL);
557+
if (!div)
558+
return;
586559

587-
if (ti_clk_divider_populate(node, &reg, &table, &flags,
588-
&clk_divider_flags, &width, &shift, &latch))
560+
if (ti_clk_divider_populate(node, div, &flags))
589561
goto cleanup;
590562

591-
clk = _register_divider(NULL, node->name, parent_name, flags, &reg,
592-
shift, width, latch, clk_divider_flags, table);
593-
563+
clk = _register_divider(node, flags, div);
594564
if (!IS_ERR(clk)) {
595565
of_clk_add_provider(node, of_clk_src_simple_get, clk);
596566
of_ti_clk_autoidle_setup(node);
597567
return;
598568
}
599569

600570
cleanup:
601-
kfree(table);
571+
kfree(div->table);
572+
kfree(div);
602573
}
603574
CLK_OF_DECLARE(divider_clk, "ti,divider-clock", of_ti_divider_clk_setup);
604575

605576
static void __init of_ti_composite_divider_clk_setup(struct device_node *node)
606577
{
607578
struct clk_omap_divider *div;
608-
u32 val;
579+
u32 tmp;
609580

610581
div = kzalloc(sizeof(*div), GFP_KERNEL);
611582
if (!div)
612583
return;
613584

614-
if (ti_clk_divider_populate(node, &div->reg, &div->table, &val,
615-
&div->flags, &div->width, &div->shift,
616-
NULL) < 0)
585+
if (ti_clk_divider_populate(node, div, &tmp))
617586
goto cleanup;
618587

619588
if (!ti_clk_add_component(node, &div->hw, CLK_COMPONENT_TYPE_DIVIDER))

0 commit comments

Comments
 (0)