Lines Matching +full:clock +full:- +full:name
1 // SPDX-License-Identifier: GPL-2.0-only
10 #include "clk-kona.h"
13 #define selector_clear_exists(sel) ((sel)->width = 0)
20 struct ccu_policy *ccu_policy = &ccu->policy; in ccu_data_offsets_valid()
23 limit = ccu->range - sizeof(u32); in ccu_data_offsets_valid()
26 if (ccu_policy->enable.offset > limit) { in ccu_data_offsets_valid()
29 ccu->name, ccu_policy->enable.offset, limit); in ccu_data_offsets_valid()
32 if (ccu_policy->control.offset > limit) { in ccu_data_offsets_valid()
35 ccu->name, ccu_policy->control.offset, limit); in ccu_data_offsets_valid()
45 struct peri_clk_data *peri = bcm_clk->u.peri; in clk_requires_trigger()
49 if (bcm_clk->type != bcm_clk_peri) in clk_requires_trigger()
52 sel = &peri->sel; in clk_requires_trigger()
53 if (sel->parent_count && selector_exists(sel)) in clk_requires_trigger()
56 div = &peri->div; in clk_requires_trigger()
64 div = &peri->pre_div; in clk_requires_trigger()
78 const char *name; in peri_clk_data_offsets_valid() local
82 BUG_ON(bcm_clk->type != bcm_clk_peri); in peri_clk_data_offsets_valid()
83 peri = bcm_clk->u.peri; in peri_clk_data_offsets_valid()
84 name = bcm_clk->init_data.name; in peri_clk_data_offsets_valid()
85 range = bcm_clk->ccu->range; in peri_clk_data_offsets_valid()
87 limit = range - sizeof(u32); in peri_clk_data_offsets_valid()
90 policy = &peri->policy; in peri_clk_data_offsets_valid()
92 if (policy->offset > limit) { in peri_clk_data_offsets_valid()
94 __func__, name, policy->offset, limit); in peri_clk_data_offsets_valid()
99 gate = &peri->gate; in peri_clk_data_offsets_valid()
100 hyst = &peri->hyst; in peri_clk_data_offsets_valid()
102 if (gate->offset > limit) { in peri_clk_data_offsets_valid()
104 __func__, name, gate->offset, limit); in peri_clk_data_offsets_valid()
109 if (hyst->offset > limit) { in peri_clk_data_offsets_valid()
112 name, hyst->offset, limit); in peri_clk_data_offsets_valid()
117 pr_err("%s: hysteresis but no gate for %s\n", __func__, name); in peri_clk_data_offsets_valid()
121 div = &peri->div; in peri_clk_data_offsets_valid()
123 if (div->u.s.offset > limit) { in peri_clk_data_offsets_valid()
125 __func__, name, div->u.s.offset, limit); in peri_clk_data_offsets_valid()
130 div = &peri->pre_div; in peri_clk_data_offsets_valid()
132 if (div->u.s.offset > limit) { in peri_clk_data_offsets_valid()
133 pr_err("%s: bad pre-divider offset for %s " in peri_clk_data_offsets_valid()
135 __func__, name, div->u.s.offset, limit); in peri_clk_data_offsets_valid()
140 sel = &peri->sel; in peri_clk_data_offsets_valid()
142 if (sel->offset > limit) { in peri_clk_data_offsets_valid()
144 __func__, name, sel->offset, limit); in peri_clk_data_offsets_valid()
149 trig = &peri->trig; in peri_clk_data_offsets_valid()
151 if (trig->offset > limit) { in peri_clk_data_offsets_valid()
153 __func__, name, trig->offset, limit); in peri_clk_data_offsets_valid()
158 trig = &peri->pre_trig; in peri_clk_data_offsets_valid()
160 if (trig->offset > limit) { in peri_clk_data_offsets_valid()
161 pr_err("%s: bad pre-trigger offset for %s (%u > %u)\n", in peri_clk_data_offsets_valid()
162 __func__, name, trig->offset, limit); in peri_clk_data_offsets_valid()
170 /* A bit position must be less than the number of bits in a 32-bit register. */
174 u32 limit = BITS_PER_BYTE * sizeof(u32) - 1; in bit_posn_valid()
185 * A bitfield must be at least 1 bit wide. Both the low-order and
186 * high-order bits must lie within a 32-bit register. We require
189 * is not well-defined by the C standard.
212 struct bcm_lvm_en *enable = &ccu_policy->enable; in ccu_policy_valid()
215 if (!bit_posn_valid(enable->bit, "policy enable", ccu_name)) in ccu_policy_valid()
218 control = &ccu_policy->control; in ccu_policy_valid()
219 if (!bit_posn_valid(control->go_bit, "policy control GO", ccu_name)) in ccu_policy_valid()
222 if (!bit_posn_valid(control->atl_bit, "policy control ATL", ccu_name)) in ccu_policy_valid()
225 if (!bit_posn_valid(control->ac_bit, "policy control AC", ccu_name)) in ccu_policy_valid()
233 if (!bit_posn_valid(policy->bit, "policy", clock_name)) in policy_valid()
240 * All gates, if defined, have a status bit, and for hardware-only
248 if (!bit_posn_valid(gate->status_bit, "gate status", clock_name)) in gate_valid()
252 if (!bit_posn_valid(gate->en_bit, "gate enable", clock_name)) in gate_valid()
256 if (!bit_posn_valid(gate->hw_sw_sel_bit, in gate_valid()
270 if (!bit_posn_valid(hyst->en_bit, "hysteresis enable", clock_name)) in hyst_valid()
273 if (!bit_posn_valid(hyst->val_bit, "hysteresis value", clock_name)) in hyst_valid()
286 if (!bitfield_valid(sel->shift, sel->width, field_name, clock_name)) in sel_valid()
289 if (sel->parent_count) { in sel_valid()
296 * clock only needs to have a selector defined if it in sel_valid()
301 max_sel = sel->parent_sel[sel->parent_count - 1]; in sel_valid()
302 limit = (1 << sel->width) - 1; in sel_valid()
307 sel->width); in sel_valid()
314 kfree(sel->parent_sel); in sel_valid()
315 sel->parent_sel = NULL; in sel_valid()
322 * A fixed divider just needs to be non-zero. A variable divider
332 if (div->u.fixed == 0) { in div_valid()
339 if (!bitfield_valid(div->u.s.shift, div->u.s.width, in div_valid()
344 if (div->u.s.frac_width > div->u.s.width) { in div_valid()
347 div->u.s.frac_width, div->u.s.width); in div_valid()
355 * If a clock has two dividers, the combined number of fractional
356 * bits must be representable in a 32-bit unsigned value. This
362 struct peri_clk_data *peri = bcm_clk->u.peri; in kona_dividers_valid()
367 BUG_ON(bcm_clk->type != bcm_clk_peri); in kona_dividers_valid()
369 if (!divider_exists(&peri->div) || !divider_exists(&peri->pre_div)) in kona_dividers_valid()
372 div = &peri->div; in kona_dividers_valid()
373 pre_div = &peri->pre_div; in kona_dividers_valid()
379 return div->u.s.frac_width + pre_div->u.s.frac_width <= limit; in kona_dividers_valid()
387 return bit_posn_valid(trig->bit, field_name, clock_name); in trig_valid()
390 /* Determine whether the set of peripheral clock registers are valid. */
402 const char *name; in peri_clk_data_valid() local
404 BUG_ON(bcm_clk->type != bcm_clk_peri); in peri_clk_data_valid()
414 peri = bcm_clk->u.peri; in peri_clk_data_valid()
415 name = bcm_clk->init_data.name; in peri_clk_data_valid()
417 policy = &peri->policy; in peri_clk_data_valid()
418 if (policy_exists(policy) && !policy_valid(policy, name)) in peri_clk_data_valid()
421 gate = &peri->gate; in peri_clk_data_valid()
422 if (gate_exists(gate) && !gate_valid(gate, "gate", name)) in peri_clk_data_valid()
425 hyst = &peri->hyst; in peri_clk_data_valid()
426 if (hyst_exists(hyst) && !hyst_valid(hyst, name)) in peri_clk_data_valid()
429 sel = &peri->sel; in peri_clk_data_valid()
431 if (!sel_valid(sel, "selector", name)) in peri_clk_data_valid()
434 } else if (sel->parent_count > 1) { in peri_clk_data_valid()
436 __func__, name); in peri_clk_data_valid()
441 div = &peri->div; in peri_clk_data_valid()
442 pre_div = &peri->pre_div; in peri_clk_data_valid()
444 if (!div_valid(div, "divider", name)) in peri_clk_data_valid()
448 if (!div_valid(pre_div, "pre-divider", name)) in peri_clk_data_valid()
451 pr_err("%s: pre-divider but no divider for %s\n", __func__, in peri_clk_data_valid()
452 name); in peri_clk_data_valid()
456 trig = &peri->trig; in peri_clk_data_valid()
458 if (!trig_valid(trig, "trigger", name)) in peri_clk_data_valid()
461 if (trigger_exists(&peri->pre_trig)) { in peri_clk_data_valid()
462 if (!trig_valid(trig, "pre-trigger", name)) { in peri_clk_data_valid()
468 __func__, name); in peri_clk_data_valid()
471 } else if (trigger_exists(&peri->pre_trig)) { in peri_clk_data_valid()
472 pr_err("%s: pre-trigger but no trigger for %s\n", __func__, in peri_clk_data_valid()
473 name); in peri_clk_data_valid()
477 name); in peri_clk_data_valid()
486 switch (bcm_clk->type) { in kona_clk_valid()
492 pr_err("%s: unrecognized clock type (%d)\n", __func__, in kona_clk_valid()
493 (int)bcm_clk->type); in kona_clk_valid()
500 * Scan an array of parent clock names to determine whether there
502 * placeholders for non-supported clocks. Keep track of the
503 * position of each clock name in the original array.
506 * non-null entries in the original array, and returns a pointer to
508 * clock with the common clock code. On successful return,
513 * for each (defined) parent clock. This is the value that
514 * represents this parent clock in the clock's source selector
515 * register. The position of the clock in the original parent array
519 * The array of selector values is returned. If the clock has no
522 * Returns a null pointer if the clock names array supplied was
525 * Returns a pointer-coded error if an error occurs.
532 const char **clock; in parent_process() local
545 * Count the number of names in the null-terminated array, in parent_process()
546 * and find out how many of those are actually clock names. in parent_process()
548 for (clock = clocks; *clock; clock++) in parent_process()
549 if (*clock == BAD_CLK_NAME) in parent_process()
551 orig_count = (u32)(clock - clocks); in parent_process()
552 parent_count = orig_count - bad_count; in parent_process()
554 /* If all clocks are unsupported, we treat it as no clock */ in parent_process()
558 /* Avoid exceeding our parent clock limit */ in parent_process()
562 return ERR_PTR(-EINVAL); in parent_process()
566 * There is one parent name for each defined parent clock. in parent_process()
568 * for each defined clock. If there's only one clock, the in parent_process()
575 return ERR_PTR(-ENOMEM); in parent_process()
583 return ERR_PTR(-ENOMEM); in parent_process()
609 * If a peripheral clock has multiple parents, the value in clk_sel_setup()
611 * by the parent clock's position in the "clocks" list. Some in clk_sel_setup()
617 * clocks when registering a clock though, so we use an in clk_sel_setup()
619 * indexes the common clock code uses and the selector in clk_sel_setup()
627 __func__, init_data->name, ret); in clk_sel_setup()
632 init_data->parent_names = parent_names; in clk_sel_setup()
633 init_data->num_parents = parent_count; in clk_sel_setup()
635 sel->parent_count = parent_count; in clk_sel_setup()
636 sel->parent_sel = parent_sel; in clk_sel_setup()
644 kfree(sel->parent_sel); in clk_sel_teardown()
645 sel->parent_sel = NULL; in clk_sel_teardown()
646 sel->parent_count = 0; in clk_sel_teardown()
648 init_data->num_parents = 0; in clk_sel_teardown()
649 kfree(init_data->parent_names); in clk_sel_teardown()
650 init_data->parent_names = NULL; in clk_sel_teardown()
656 clk_sel_teardown(&data->sel, init_data); in peri_clk_teardown()
661 * parent_sel[] arrays in the peripheral clock's "data" structure
662 * that can be assigned if the clock has one or more parent clocks
668 init_data->flags = CLK_IGNORE_UNUSED; in peri_clk_setup()
670 return clk_sel_setup(data->clocks, &data->sel, init_data); in peri_clk_setup()
675 switch (bcm_clk->type) { in bcm_clk_teardown()
677 peri_clk_teardown(bcm_clk->u.data, &bcm_clk->init_data); in bcm_clk_teardown()
682 bcm_clk->u.data = NULL; in bcm_clk_teardown()
683 bcm_clk->type = bcm_clk_none; in bcm_clk_teardown()
702 struct clk_init_data *init_data = &bcm_clk->init_data; in kona_clk_setup()
704 switch (bcm_clk->type) { in kona_clk_setup()
706 ret = peri_clk_setup(bcm_clk->u.data, init_data); in kona_clk_setup()
711 pr_err("%s: clock type %d invalid for %s\n", __func__, in kona_clk_setup()
712 (int)bcm_clk->type, init_data->name); in kona_clk_setup()
713 return -EINVAL; in kona_clk_setup()
718 pr_err("%s: clock data invalid for %s\n", __func__, in kona_clk_setup()
719 init_data->name); in kona_clk_setup()
720 ret = -EINVAL; in kona_clk_setup()
724 bcm_clk->hw.init = init_data; in kona_clk_setup()
725 ret = clk_hw_register(NULL, &bcm_clk->hw); in kona_clk_setup()
727 pr_err("%s: error registering clock %s (%d)\n", __func__, in kona_clk_setup()
728 init_data->name, ret); in kona_clk_setup()
743 for (i = 0; i < ccu->clk_num; i++) in ccu_clks_teardown()
744 kona_clk_teardown(&ccu->kona_clks[i].hw); in ccu_clks_teardown()
749 if (!ccu->base) in kona_ccu_teardown()
752 of_clk_del_provider(ccu->node); /* safe if never added */ in kona_ccu_teardown()
754 of_node_put(ccu->node); in kona_ccu_teardown()
755 ccu->node = NULL; in kona_ccu_teardown()
756 iounmap(ccu->base); in kona_ccu_teardown()
757 ccu->base = NULL; in kona_ccu_teardown()
767 ccu_policy = &ccu->policy; in ccu_data_valid()
769 if (!ccu_policy_valid(ccu_policy, ccu->name)) in ccu_data_valid()
779 unsigned int idx = clkspec->args[0]; in of_clk_kona_onecell_get()
781 if (idx >= ccu->clk_num) { in of_clk_kona_onecell_get()
783 return ERR_PTR(-EINVAL); in of_clk_kona_onecell_get()
786 return &ccu->kona_clks[idx].hw; in of_clk_kona_onecell_get()
815 ccu->range = (u32)range; in kona_dt_ccu_setup()
822 ccu->base = ioremap(res.start, ccu->range); in kona_dt_ccu_setup()
823 if (!ccu->base) { in kona_dt_ccu_setup()
828 ccu->node = of_node_get(node); in kona_dt_ccu_setup()
831 * Set up each defined kona clock and save the result in in kona_dt_ccu_setup()
832 * the clock framework clock array (in ccu->data). Then in kona_dt_ccu_setup()
835 for (i = 0; i < ccu->clk_num; i++) { in kona_dt_ccu_setup()
836 if (!ccu->kona_clks[i].ccu) in kona_dt_ccu_setup()
838 kona_clk_setup(&ccu->kona_clks[i]); in kona_dt_ccu_setup()