Lines Matching +full:combined +full:- +full:power +full:- +full:req
15 #include "clk-kona.h"
20 #include <linux/clk-provider.h>
25 * "Normal", and "Turbo".) A lower policy number has lower power
35 /* Produces a mask of set bits covering a range of a 32-bit value */
38 return ((1 << width) - 1) << shift; in bitfield_mask()
60 return (u64)reg_div + ((u64)1 << div->u.s.frac_width); in scaled_div_value()
70 u64 combined; in scaled_div_build() local
75 combined = (u64)div_value * BILLION + billionths; in scaled_div_build()
76 combined <<= div->u.s.frac_width; in scaled_div_build()
78 return DIV_ROUND_CLOSEST_ULL(combined, BILLION); in scaled_div_build()
86 return (u64)div->u.fixed; in scaled_div_min()
97 return (u64)div->u.fixed; in scaled_div_max()
99 reg_div = ((u32)1 << div->u.s.width) - 1; in scaled_div_max()
114 return (u32)(scaled_div - ((u64)1 << div->u.s.frac_width)); in divider()
124 return (u64)rate << div->u.s.frac_width; in scale_rate()
129 /* Read a 32-bit register value from a CCU's address space. */
132 return readl(ccu->base + reg_offset); in __ccu_read()
135 /* Write a 32-bit register value into a CCU's address space. */
139 writel(reg_val, ccu->base + reg_offset); in __ccu_write()
146 spin_lock_irqsave(&ccu->lock, flags); in ccu_lock()
152 spin_unlock_irqrestore(&ccu->lock, flags); in ccu_unlock()
161 if (ccu->write_enabled) { in __ccu_write_enable()
163 ccu->name); in __ccu_write_enable()
166 ccu->write_enabled = true; in __ccu_write_enable()
172 if (!ccu->write_enabled) { in __ccu_write_disable()
174 ccu->name); in __ccu_write_disable()
179 ccu->write_enabled = false; in __ccu_write_disable()
207 ccu->name, reg_offset, bit, want ? "set" : "clear"); in __ccu_wait_bit()
216 struct bcm_policy_ctl *control = &ccu->policy.control; in __ccu_policy_engine_start()
226 offset = control->offset; in __ccu_policy_engine_start()
227 go_bit = control->go_bit; in __ccu_policy_engine_start()
233 __func__, ccu->name); in __ccu_policy_engine_start()
247 * (ATL bit clear) and setting the request auto-copy (AC bit in __ccu_policy_engine_start()
250 * Note, we do NOT read-modify-write this register. in __ccu_policy_engine_start()
254 mask |= 1 << control->atl_bit; in __ccu_policy_engine_start()
256 mask |= 1 << control->ac_bit; in __ccu_policy_engine_start()
263 __func__, ccu->name); in __ccu_policy_engine_start()
270 struct bcm_lvm_en *enable = &ccu->policy.enable; in __ccu_policy_engine_stop()
280 offset = enable->offset; in __ccu_policy_engine_stop()
281 enable_bit = enable->bit; in __ccu_policy_engine_stop()
285 __func__, ccu->name); in __ccu_policy_engine_stop()
289 /* Now set the bit to stop the engine (NO read-modify-write) */ in __ccu_policy_engine_stop()
296 __func__, ccu->name); in __ccu_policy_engine_stop()
307 * four registers, and the 32-bit registers are at consecutive
326 __func__, ccu->name); in policy_init()
334 offset = policy->offset; in policy_init()
335 mask = (u32)1 << policy->bit; in policy_init()
349 __func__, ccu->name); in policy_init()
367 bit_mask = 1 << gate->status_bit; in __is_clk_gate_enabled()
368 reg_val = __ccu_read(ccu, gate->offset); in __is_clk_gate_enabled()
406 reg_val = __ccu_read(ccu, gate->offset); in __gate_commit()
410 mask = (u32)1 << gate->hw_sw_sel_bit; in __gate_commit()
424 mask = (u32)1 << gate->en_bit; in __gate_commit()
431 __ccu_write(ccu, gate->offset, reg_val); in __gate_commit()
438 return __ccu_wait_bit(ccu, gate->offset, gate->status_bit, enabled); in __gate_commit()
485 /* Enable or disable a gate. Returns 0 if successful, -EIO otherwise */
515 return -EIO; in clk_gate()
521 * If a clock gate requires a turn-off delay it will have
536 offset = hyst->offset; in hyst_init()
537 mask = (u32)1 << hyst->en_bit; in hyst_init()
538 mask |= (u32)1 << hyst->val_bit; in hyst_init()
556 __ccu_write(ccu, trig->offset, 1 << trig->bit); in __clk_trigger()
558 return __ccu_wait_bit(ccu, trig->offset, trig->bit, false); in __clk_trigger()
571 return (u64)div->u.fixed; in divider_read_scaled()
574 reg_val = __ccu_read(ccu, div->u.s.offset); in divider_read_scaled()
578 reg_div = bitfield_extract(reg_val, div->u.s.shift, div->u.s.width); in divider_read_scaled()
588 * Returns 0 on success. Returns -EINVAL for invalid arguments.
589 * Returns -ENXIO if gating failed, and -EIO if a trigger failed.
606 if (div->u.s.scaled_div == BAD_SCALED_DIV_VALUE) { in __div_commit()
607 reg_val = __ccu_read(ccu, div->u.s.offset); in __div_commit()
608 reg_div = bitfield_extract(reg_val, div->u.s.shift, in __div_commit()
609 div->u.s.width); in __div_commit()
610 div->u.s.scaled_div = scaled_div_value(div, reg_div); in __div_commit()
616 reg_div = divider(div, div->u.s.scaled_div); in __div_commit()
621 ret = -ENXIO; in __div_commit()
626 reg_val = __ccu_read(ccu, div->u.s.offset); in __div_commit()
627 reg_val = bitfield_replace(reg_val, div->u.s.shift, div->u.s.width, in __div_commit()
629 __ccu_write(ccu, div->u.s.offset, reg_val); in __div_commit()
633 ret = -EIO; in __div_commit()
637 ret = ret ? ret : -ENXIO; /* return first error */ in __div_commit()
665 previous = div->u.s.scaled_div; in divider_write()
669 div->u.s.scaled_div = scaled_div; in divider_write()
680 div->u.s.scaled_div = previous; /* Revert the change */ in divider_write()
690 * into account a divider and an optional pre-divider. The
691 * pre-divider register pointer may be NULL.
708 * If there is a pre-divider, divide the scaled parent rate in clk_recalc_rate()
709 * by the pre-divider value first. In this case--to improve in clk_recalc_rate()
710 * accuracy--scale the parent rate by *both* the pre-divider in clk_recalc_rate()
712 * result of the pre-divider. in clk_recalc_rate()
741 * into two dividers. The pre-divider can be NULL, and even if it's
742 * non-null it may be nonexistent. It's also OK for the divider to
743 * be nonexistent, and in that case the pre-divider is also ignored.
745 * If scaled_div is non-null, it is used to return the scaled divisor
764 * If there is a pre-divider, divide the scaled parent rate in round_rate()
765 * by the pre-divider value first. In this case--to improve in round_rate()
766 * accuracy--scale the parent rate by *both* the pre-divider in round_rate()
768 * result of the pre-divider. in round_rate()
772 * For simplicity we treat the pre-divider as fixed (for now). in round_rate()
825 BUG_ON(sel->parent_count > (u32)U8_MAX); in parent_index()
826 for (i = 0; i < sel->parent_count; i++) in parent_index()
827 if (sel->parent_sel[i] == parent_sel) in parent_index()
853 reg_val = __ccu_read(ccu, sel->offset); in selector_read_index()
856 parent_sel = bitfield_extract(reg_val, sel->shift, sel->width); in selector_read_index()
861 pr_err("%s: out-of-range parent selector %u (%s 0x%04x)\n", in selector_read_index()
862 __func__, parent_sel, ccu->name, sel->offset); in selector_read_index()
870 * Returns 0 on success. Returns -EINVAL for invalid arguments.
871 * Returns -ENXIO if gating failed, and -EIO if a trigger failed.
889 if (sel->clk_index == BAD_CLK_INDEX) { in __sel_commit()
892 reg_val = __ccu_read(ccu, sel->offset); in __sel_commit()
893 parent_sel = bitfield_extract(reg_val, sel->shift, sel->width); in __sel_commit()
896 return -EINVAL; in __sel_commit()
897 sel->clk_index = index; in __sel_commit()
902 BUG_ON((u32)sel->clk_index >= sel->parent_count); in __sel_commit()
903 parent_sel = sel->parent_sel[sel->clk_index]; in __sel_commit()
908 return -ENXIO; in __sel_commit()
911 reg_val = __ccu_read(ccu, sel->offset); in __sel_commit()
912 reg_val = bitfield_replace(reg_val, sel->shift, sel->width, parent_sel); in __sel_commit()
913 __ccu_write(ccu, sel->offset, reg_val); in __sel_commit()
917 ret = -EIO; in __sel_commit()
921 ret = ret ? ret : -ENXIO; /* return first error */ in __sel_commit()
952 previous = sel->clk_index; in selector_write()
956 sel->clk_index = index; in selector_write()
967 sel->clk_index = previous; /* Revert the change */ in selector_write()
977 struct bcm_clk_gate *gate = &bcm_clk->u.peri->gate; in kona_peri_clk_enable()
979 return clk_gate(bcm_clk->ccu, bcm_clk->init_data.name, gate, true); in kona_peri_clk_enable()
985 struct bcm_clk_gate *gate = &bcm_clk->u.peri->gate; in kona_peri_clk_disable()
987 (void)clk_gate(bcm_clk->ccu, bcm_clk->init_data.name, gate, false); in kona_peri_clk_disable()
993 struct bcm_clk_gate *gate = &bcm_clk->u.peri->gate; in kona_peri_clk_is_enabled()
995 return is_clk_gate_enabled(bcm_clk->ccu, gate) ? 1 : 0; in kona_peri_clk_is_enabled()
1002 struct peri_clk_data *data = bcm_clk->u.peri; in kona_peri_clk_recalc_rate()
1004 return clk_recalc_rate(bcm_clk->ccu, &data->div, &data->pre_div, in kona_peri_clk_recalc_rate()
1012 struct bcm_clk_div *div = &bcm_clk->u.peri->div; in kona_peri_clk_round_rate()
1018 return round_rate(bcm_clk->ccu, div, &bcm_clk->u.peri->pre_div, in kona_peri_clk_round_rate()
1023 struct clk_rate_request *req) in kona_peri_clk_determine_rate() argument
1038 WARN_ON_ONCE(bcm_clk->init_data.flags & CLK_SET_RATE_NO_REPARENT); in kona_peri_clk_determine_rate()
1039 parent_count = (u32)bcm_clk->init_data.num_parents; in kona_peri_clk_determine_rate()
1041 rate = kona_peri_clk_round_rate(hw, req->rate, in kona_peri_clk_determine_rate()
1042 &req->best_parent_rate); in kona_peri_clk_determine_rate()
1046 req->rate = rate; in kona_peri_clk_determine_rate()
1053 best_rate = kona_peri_clk_round_rate(hw, req->rate, &parent_rate); in kona_peri_clk_determine_rate()
1054 best_delta = abs(best_rate - req->rate); in kona_peri_clk_determine_rate()
1068 other_rate = kona_peri_clk_round_rate(hw, req->rate, in kona_peri_clk_determine_rate()
1070 delta = abs(other_rate - req->rate); in kona_peri_clk_determine_rate()
1074 req->best_parent_hw = parent; in kona_peri_clk_determine_rate()
1075 req->best_parent_rate = parent_rate; in kona_peri_clk_determine_rate()
1079 req->rate = best_rate; in kona_peri_clk_determine_rate()
1086 struct peri_clk_data *data = bcm_clk->u.peri; in kona_peri_clk_set_parent()
1087 struct bcm_clk_sel *sel = &data->sel; in kona_peri_clk_set_parent()
1091 BUG_ON(index >= sel->parent_count); in kona_peri_clk_set_parent()
1099 * pre-trigger we want to use that instead. in kona_peri_clk_set_parent()
1101 trig = trigger_exists(&data->pre_trig) ? &data->pre_trig in kona_peri_clk_set_parent()
1102 : &data->trig; in kona_peri_clk_set_parent()
1104 ret = selector_write(bcm_clk->ccu, &data->gate, sel, trig, index); in kona_peri_clk_set_parent()
1105 if (ret == -ENXIO) { in kona_peri_clk_set_parent()
1107 bcm_clk->init_data.name); in kona_peri_clk_set_parent()
1108 ret = -EIO; /* Don't proliferate weird errors */ in kona_peri_clk_set_parent()
1109 } else if (ret == -EIO) { in kona_peri_clk_set_parent()
1111 trig == &data->pre_trig ? "pre-" : "", in kona_peri_clk_set_parent()
1112 bcm_clk->init_data.name); in kona_peri_clk_set_parent()
1121 struct peri_clk_data *data = bcm_clk->u.peri; in kona_peri_clk_get_parent()
1124 index = selector_read_index(bcm_clk->ccu, &data->sel); in kona_peri_clk_get_parent()
1126 /* Not all callers would handle an out-of-range value gracefully */ in kona_peri_clk_get_parent()
1134 struct peri_clk_data *data = bcm_clk->u.peri; in kona_peri_clk_set_rate()
1135 struct bcm_clk_div *div = &data->div; in kona_peri_clk_set_rate()
1140 return -EINVAL; in kona_peri_clk_set_rate()
1146 return rate == parent_rate ? 0 : -EINVAL; in kona_peri_clk_set_rate()
1150 * pre-divider be, but for now we never actually try to in kona_peri_clk_set_rate()
1151 * change that.) Tolerate a request for a no-op change. in kona_peri_clk_set_rate()
1153 if (divider_is_fixed(&data->div)) in kona_peri_clk_set_rate()
1154 return rate == parent_rate ? 0 : -EINVAL; in kona_peri_clk_set_rate()
1161 (void)round_rate(bcm_clk->ccu, div, &data->pre_div, in kona_peri_clk_set_rate()
1165 * We aren't updating any pre-divider at this point, so in kona_peri_clk_set_rate()
1168 ret = divider_write(bcm_clk->ccu, &data->gate, &data->div, in kona_peri_clk_set_rate()
1169 &data->trig, scaled_div); in kona_peri_clk_set_rate()
1170 if (ret == -ENXIO) { in kona_peri_clk_set_rate()
1172 bcm_clk->init_data.name); in kona_peri_clk_set_rate()
1173 ret = -EIO; /* Don't proliferate weird errors */ in kona_peri_clk_set_rate()
1174 } else if (ret == -EIO) { in kona_peri_clk_set_rate()
1176 bcm_clk->init_data.name); in kona_peri_clk_set_rate()
1196 struct ccu_data *ccu = bcm_clk->ccu; in __peri_clk_init()
1197 struct peri_clk_data *peri = bcm_clk->u.peri; in __peri_clk_init()
1198 const char *name = bcm_clk->init_data.name; in __peri_clk_init()
1201 BUG_ON(bcm_clk->type != bcm_clk_peri); in __peri_clk_init()
1203 if (!policy_init(ccu, &peri->policy)) { in __peri_clk_init()
1208 if (!gate_init(ccu, &peri->gate)) { in __peri_clk_init()
1212 if (!hyst_init(ccu, &peri->hyst)) { in __peri_clk_init()
1216 if (!div_init(ccu, &peri->gate, &peri->div, &peri->trig)) { in __peri_clk_init()
1223 * For the pre-divider and selector, the pre-trigger is used in __peri_clk_init()
1226 trig = trigger_exists(&peri->pre_trig) ? &peri->pre_trig in __peri_clk_init()
1227 : &peri->trig; in __peri_clk_init()
1229 if (!div_init(ccu, &peri->gate, &peri->pre_div, trig)) { in __peri_clk_init()
1230 pr_err("%s: error initializing pre-divider for %s\n", __func__, in __peri_clk_init()
1235 if (!sel_init(ccu, &peri->gate, &peri->sel, trig)) { in __peri_clk_init()
1246 switch (bcm_clk->type) { in __kona_clk_init()
1260 struct kona_clk *kona_clks = ccu->kona_clks; in kona_ccu_init()
1266 for (which = 0; which < ccu->clk_num; which++) { in kona_ccu_init()
1269 if (!bcm_clk->ccu) in kona_ccu_init()