Lines Matching defs:ccu

122 static inline u32 __ccu_read(struct ccu_data *ccu, u32 reg_offset)
124 return readl(ccu->base + reg_offset);
129 __ccu_write(struct ccu_data *ccu, u32 reg_offset, u32 reg_val)
131 writel(reg_val, ccu->base + reg_offset);
134 static inline unsigned long ccu_lock(struct ccu_data *ccu)
138 spin_lock_irqsave(&ccu->lock, flags);
142 static inline void ccu_unlock(struct ccu_data *ccu, unsigned long flags)
144 spin_unlock_irqrestore(&ccu->lock, flags);
151 static inline void __ccu_write_enable(struct ccu_data *ccu)
153 if (ccu->write_enabled) {
155 ccu->name);
158 ccu->write_enabled = true;
159 __ccu_write(ccu, 0, CCU_ACCESS_PASSWORD | 1);
162 static inline void __ccu_write_disable(struct ccu_data *ccu)
164 if (!ccu->write_enabled) {
166 ccu->name);
170 __ccu_write(ccu, 0, CCU_ACCESS_PASSWORD);
171 ccu->write_enabled = false;
183 __ccu_wait_bit(struct ccu_data *ccu, u32 reg_offset, u32 bit, bool want)
192 val = __ccu_read(ccu, reg_offset);
199 ccu->name, reg_offset, bit, want ? "set" : "clear");
206 static bool __ccu_policy_engine_start(struct ccu_data *ccu, bool sync)
208 struct bcm_policy_ctl *control = &ccu->policy.control;
222 ret = __ccu_wait_bit(ccu, offset, go_bit, false);
224 pr_err("%s: ccu %s policy engine wouldn't go idle\n",
225 __func__, ccu->name);
249 __ccu_write(ccu, offset, mask);
252 ret = __ccu_wait_bit(ccu, offset, go_bit, false);
254 pr_err("%s: ccu %s policy engine never started\n",
255 __func__, ccu->name);
260 static bool __ccu_policy_engine_stop(struct ccu_data *ccu)
262 struct bcm_lvm_en *enable = &ccu->policy.enable;
274 ret = __ccu_wait_bit(ccu, offset, enable_bit, false);
276 pr_err("%s: ccu %s policy engine already stopped\n",
277 __func__, ccu->name);
282 __ccu_write(ccu, offset, (u32)1 << enable_bit);
285 ret = __ccu_wait_bit(ccu, offset, enable_bit, false);
287 pr_err("%s: ccu %s policy engine never stopped\n",
288 __func__, ccu->name);
302 static bool policy_init(struct ccu_data *ccu, struct bcm_clk_policy *policy)
316 if (!__ccu_policy_engine_stop(ccu)) {
318 __func__, ccu->name);
331 reg_val = __ccu_read(ccu, offset);
333 __ccu_write(ccu, offset, reg_val);
338 ret = __ccu_policy_engine_start(ccu, true);
341 __func__, ccu->name);
350 __is_clk_gate_enabled(struct ccu_data *ccu, struct bcm_clk_gate *gate)
360 reg_val = __ccu_read(ccu, gate->offset);
367 is_clk_gate_enabled(struct ccu_data *ccu, struct bcm_clk_gate *gate)
376 flags = ccu_lock(ccu);
377 ret = __is_clk_gate_enabled(ccu, gate);
378 ccu_unlock(ccu, flags);
388 __gate_commit(struct ccu_data *ccu, struct bcm_clk_gate *gate)
398 reg_val = __ccu_read(ccu, gate->offset);
423 __ccu_write(ccu, gate->offset, reg_val);
430 return __ccu_wait_bit(ccu, gate->offset, gate->status_bit, enabled);
439 static bool gate_init(struct ccu_data *ccu, struct bcm_clk_gate *gate)
443 return __gate_commit(ccu, gate);
453 __clk_gate(struct ccu_data *ccu, struct bcm_clk_gate *gate, bool enable)
470 ret = __gate_commit(ccu, gate);
478 static int clk_gate(struct ccu_data *ccu, const char *name,
493 flags = ccu_lock(ccu);
494 __ccu_write_enable(ccu);
496 success = __clk_gate(ccu, gate, enable);
498 __ccu_write_disable(ccu);
499 ccu_unlock(ccu, flags);
519 static bool hyst_init(struct ccu_data *ccu, struct bcm_clk_hyst *hyst)
532 reg_val = __ccu_read(ccu, offset);
534 __ccu_write(ccu, offset, reg_val);
545 static bool __clk_trigger(struct ccu_data *ccu, struct bcm_clk_trig *trig)
548 __ccu_write(ccu, trig->offset, 1 << trig->bit);
550 return __ccu_wait_bit(ccu, trig->offset, trig->bit, false);
556 static u64 divider_read_scaled(struct ccu_data *ccu, struct bcm_clk_div *div)
565 flags = ccu_lock(ccu);
566 reg_val = __ccu_read(ccu, div->u.s.offset);
567 ccu_unlock(ccu, flags);
583 static int __div_commit(struct ccu_data *ccu, struct bcm_clk_gate *gate,
599 reg_val = __ccu_read(ccu, div->u.s.offset);
611 enabled = __is_clk_gate_enabled(ccu, gate);
612 if (!enabled && !__clk_gate(ccu, gate, true)) {
618 reg_val = __ccu_read(ccu, div->u.s.offset);
621 __ccu_write(ccu, div->u.s.offset, reg_val);
624 if (!__clk_trigger(ccu, trig))
628 if (!enabled && !__clk_gate(ccu, gate, false))
639 static bool div_init(struct ccu_data *ccu, struct bcm_clk_gate *gate,
644 return !__div_commit(ccu, gate, div, trig);
647 static int divider_write(struct ccu_data *ccu, struct bcm_clk_gate *gate,
663 flags = ccu_lock(ccu);
664 __ccu_write_enable(ccu);
666 ret = __div_commit(ccu, gate, div, trig);
668 __ccu_write_disable(ccu);
669 ccu_unlock(ccu, flags);
685 static unsigned long clk_recalc_rate(struct ccu_data *ccu,
713 scaled_div = divider_read_scaled(ccu, pre_div);
725 scaled_div = divider_read_scaled(ccu, div);
740 static long round_rate(struct ccu_data *ccu, struct bcm_clk_div *div,
772 scaled_pre_div = divider_read_scaled(ccu, pre_div);
794 best_scaled_div = divider_read_scaled(ccu, div);
832 static u8 selector_read_index(struct ccu_data *ccu, struct bcm_clk_sel *sel)
844 flags = ccu_lock(ccu);
845 reg_val = __ccu_read(ccu, sel->offset);
846 ccu_unlock(ccu, flags);
854 __func__, parent_sel, ccu->name, sel->offset);
866 __sel_commit(struct ccu_data *ccu, struct bcm_clk_gate *gate,
884 reg_val = __ccu_read(ccu, sel->offset);
898 enabled = __is_clk_gate_enabled(ccu, gate);
899 if (!enabled && !__clk_gate(ccu, gate, true))
903 reg_val = __ccu_read(ccu, sel->offset);
905 __ccu_write(ccu, sel->offset, reg_val);
908 if (!__clk_trigger(ccu, trig))
912 if (!enabled && !__clk_gate(ccu, gate, false))
923 static bool sel_init(struct ccu_data *ccu, struct bcm_clk_gate *gate,
928 return !__sel_commit(ccu, gate, sel, trig);
936 static int selector_write(struct ccu_data *ccu, struct bcm_clk_gate *gate,
950 flags = ccu_lock(ccu);
951 __ccu_write_enable(ccu);
953 ret = __sel_commit(ccu, gate, sel, trig);
955 __ccu_write_disable(ccu);
956 ccu_unlock(ccu, flags);
971 return clk_gate(bcm_clk->ccu, bcm_clk->init_data.name, gate, true);
979 (void)clk_gate(bcm_clk->ccu, bcm_clk->init_data.name, gate, false);
987 return is_clk_gate_enabled(bcm_clk->ccu, gate) ? 1 : 0;
996 return clk_recalc_rate(bcm_clk->ccu, &data->div, &data->pre_div,
1010 return round_rate(bcm_clk->ccu, div, &bcm_clk->u.peri->pre_div,
1096 ret = selector_write(bcm_clk->ccu, &data->gate, sel, trig, index);
1116 index = selector_read_index(bcm_clk->ccu, &data->sel);
1153 (void)round_rate(bcm_clk->ccu, div, &data->pre_div,
1160 ret = divider_write(bcm_clk->ccu, &data->gate, &data->div,
1188 struct ccu_data *ccu = bcm_clk->ccu;
1195 if (!policy_init(ccu, &peri->policy)) {
1200 if (!gate_init(ccu, &peri->gate)) {
1204 if (!hyst_init(ccu, &peri->hyst)) {
1208 if (!div_init(ccu, &peri->gate, &peri->div, &peri->trig)) {
1221 if (!div_init(ccu, &peri->gate, &peri->pre_div, trig)) {
1227 if (!sel_init(ccu, &peri->gate, &peri->sel, trig)) {
1248 bool __init kona_ccu_init(struct ccu_data *ccu)
1252 struct kona_clk *kona_clks = ccu->kona_clks;
1255 flags = ccu_lock(ccu);
1256 __ccu_write_enable(ccu);
1258 for (which = 0; which < ccu->clk_num; which++) {
1261 if (!bcm_clk->ccu)
1267 __ccu_write_disable(ccu);
1268 ccu_unlock(ccu, flags);