Lines Matching refs:ccu

130 static inline u32 __ccu_read(struct ccu_data *ccu, u32 reg_offset)
132 return readl(ccu->base + reg_offset);
137 __ccu_write(struct ccu_data *ccu, u32 reg_offset, u32 reg_val)
139 writel(reg_val, ccu->base + reg_offset);
142 static inline unsigned long ccu_lock(struct ccu_data *ccu)
146 spin_lock_irqsave(&ccu->lock, flags);
150 static inline void ccu_unlock(struct ccu_data *ccu, unsigned long flags)
152 spin_unlock_irqrestore(&ccu->lock, flags);
159 static inline void __ccu_write_enable(struct ccu_data *ccu)
161 if (ccu->write_enabled) {
163 ccu->name);
166 ccu->write_enabled = true;
167 __ccu_write(ccu, 0, CCU_ACCESS_PASSWORD | 1);
170 static inline void __ccu_write_disable(struct ccu_data *ccu)
172 if (!ccu->write_enabled) {
174 ccu->name);
178 __ccu_write(ccu, 0, CCU_ACCESS_PASSWORD);
179 ccu->write_enabled = false;
191 __ccu_wait_bit(struct ccu_data *ccu, u32 reg_offset, u32 bit, bool want)
200 val = __ccu_read(ccu, reg_offset);
207 ccu->name, reg_offset, bit, want ? "set" : "clear");
214 static bool __ccu_policy_engine_start(struct ccu_data *ccu, bool sync)
216 struct bcm_policy_ctl *control = &ccu->policy.control;
230 ret = __ccu_wait_bit(ccu, offset, go_bit, false);
232 pr_err("%s: ccu %s policy engine wouldn't go idle\n",
233 __func__, ccu->name);
257 __ccu_write(ccu, offset, mask);
260 ret = __ccu_wait_bit(ccu, offset, go_bit, false);
262 pr_err("%s: ccu %s policy engine never started\n",
263 __func__, ccu->name);
268 static bool __ccu_policy_engine_stop(struct ccu_data *ccu)
270 struct bcm_lvm_en *enable = &ccu->policy.enable;
282 ret = __ccu_wait_bit(ccu, offset, enable_bit, false);
284 pr_err("%s: ccu %s policy engine already stopped\n",
285 __func__, ccu->name);
290 __ccu_write(ccu, offset, (u32)1 << enable_bit);
293 ret = __ccu_wait_bit(ccu, offset, enable_bit, false);
295 pr_err("%s: ccu %s policy engine never stopped\n",
296 __func__, ccu->name);
310 static bool policy_init(struct ccu_data *ccu, struct bcm_clk_policy *policy)
324 if (!__ccu_policy_engine_stop(ccu)) {
326 __func__, ccu->name);
339 reg_val = __ccu_read(ccu, offset);
341 __ccu_write(ccu, offset, reg_val);
346 ret = __ccu_policy_engine_start(ccu, true);
349 __func__, ccu->name);
358 __is_clk_gate_enabled(struct ccu_data *ccu, struct bcm_clk_gate *gate)
368 reg_val = __ccu_read(ccu, gate->offset);
375 is_clk_gate_enabled(struct ccu_data *ccu, struct bcm_clk_gate *gate)
384 flags = ccu_lock(ccu);
385 ret = __is_clk_gate_enabled(ccu, gate);
386 ccu_unlock(ccu, flags);
396 __gate_commit(struct ccu_data *ccu, struct bcm_clk_gate *gate)
406 reg_val = __ccu_read(ccu, gate->offset);
431 __ccu_write(ccu, gate->offset, reg_val);
438 return __ccu_wait_bit(ccu, gate->offset, gate->status_bit, enabled);
447 static bool gate_init(struct ccu_data *ccu, struct bcm_clk_gate *gate)
451 return __gate_commit(ccu, gate);
461 __clk_gate(struct ccu_data *ccu, struct bcm_clk_gate *gate, bool enable)
478 ret = __gate_commit(ccu, gate);
486 static int clk_gate(struct ccu_data *ccu, const char *name,
501 flags = ccu_lock(ccu);
502 __ccu_write_enable(ccu);
504 success = __clk_gate(ccu, gate, enable);
506 __ccu_write_disable(ccu);
507 ccu_unlock(ccu, flags);
527 static bool hyst_init(struct ccu_data *ccu, struct bcm_clk_hyst *hyst)
540 reg_val = __ccu_read(ccu, offset);
542 __ccu_write(ccu, offset, reg_val);
553 static bool __clk_trigger(struct ccu_data *ccu, struct bcm_clk_trig *trig)
556 __ccu_write(ccu, trig->offset, 1 << trig->bit);
558 return __ccu_wait_bit(ccu, trig->offset, trig->bit, false);
564 static u64 divider_read_scaled(struct ccu_data *ccu, struct bcm_clk_div *div)
573 flags = ccu_lock(ccu);
574 reg_val = __ccu_read(ccu, div->u.s.offset);
575 ccu_unlock(ccu, flags);
591 static int __div_commit(struct ccu_data *ccu, struct bcm_clk_gate *gate,
607 reg_val = __ccu_read(ccu, div->u.s.offset);
619 enabled = __is_clk_gate_enabled(ccu, gate);
620 if (!enabled && !__clk_gate(ccu, gate, true)) {
626 reg_val = __ccu_read(ccu, div->u.s.offset);
629 __ccu_write(ccu, div->u.s.offset, reg_val);
632 if (!__clk_trigger(ccu, trig))
636 if (!enabled && !__clk_gate(ccu, gate, false))
647 static bool div_init(struct ccu_data *ccu, struct bcm_clk_gate *gate,
652 return !__div_commit(ccu, gate, div, trig);
655 static int divider_write(struct ccu_data *ccu, struct bcm_clk_gate *gate,
671 flags = ccu_lock(ccu);
672 __ccu_write_enable(ccu);
674 ret = __div_commit(ccu, gate, div, trig);
676 __ccu_write_disable(ccu);
677 ccu_unlock(ccu, flags);
693 static unsigned long clk_recalc_rate(struct ccu_data *ccu,
721 scaled_div = divider_read_scaled(ccu, pre_div);
733 scaled_div = divider_read_scaled(ccu, div);
748 static long round_rate(struct ccu_data *ccu, struct bcm_clk_div *div,
780 scaled_pre_div = divider_read_scaled(ccu, pre_div);
802 best_scaled_div = divider_read_scaled(ccu, div);
840 static u8 selector_read_index(struct ccu_data *ccu, struct bcm_clk_sel *sel)
852 flags = ccu_lock(ccu);
853 reg_val = __ccu_read(ccu, sel->offset);
854 ccu_unlock(ccu, flags);
862 __func__, parent_sel, ccu->name, sel->offset);
874 __sel_commit(struct ccu_data *ccu, struct bcm_clk_gate *gate,
892 reg_val = __ccu_read(ccu, sel->offset);
906 enabled = __is_clk_gate_enabled(ccu, gate);
907 if (!enabled && !__clk_gate(ccu, gate, true))
911 reg_val = __ccu_read(ccu, sel->offset);
913 __ccu_write(ccu, sel->offset, reg_val);
916 if (!__clk_trigger(ccu, trig))
920 if (!enabled && !__clk_gate(ccu, gate, false))
931 static bool sel_init(struct ccu_data *ccu, struct bcm_clk_gate *gate,
936 return !__sel_commit(ccu, gate, sel, trig);
944 static int selector_write(struct ccu_data *ccu, struct bcm_clk_gate *gate,
958 flags = ccu_lock(ccu);
959 __ccu_write_enable(ccu);
961 ret = __sel_commit(ccu, gate, sel, trig);
963 __ccu_write_disable(ccu);
964 ccu_unlock(ccu, flags);
979 return clk_gate(bcm_clk->ccu, bcm_clk->init_data.name, gate, true);
987 (void)clk_gate(bcm_clk->ccu, bcm_clk->init_data.name, gate, false);
995 return is_clk_gate_enabled(bcm_clk->ccu, gate) ? 1 : 0;
1004 return clk_recalc_rate(bcm_clk->ccu, &data->div, &data->pre_div,
1018 return round_rate(bcm_clk->ccu, div, &bcm_clk->u.peri->pre_div,
1104 ret = selector_write(bcm_clk->ccu, &data->gate, sel, trig, index);
1124 index = selector_read_index(bcm_clk->ccu, &data->sel);
1161 (void)round_rate(bcm_clk->ccu, div, &data->pre_div,
1168 ret = divider_write(bcm_clk->ccu, &data->gate, &data->div,
1196 struct ccu_data *ccu = bcm_clk->ccu;
1203 if (!policy_init(ccu, &peri->policy)) {
1208 if (!gate_init(ccu, &peri->gate)) {
1212 if (!hyst_init(ccu, &peri->hyst)) {
1216 if (!div_init(ccu, &peri->gate, &peri->div, &peri->trig)) {
1229 if (!div_init(ccu, &peri->gate, &peri->pre_div, trig)) {
1235 if (!sel_init(ccu, &peri->gate, &peri->sel, trig)) {
1256 bool __init kona_ccu_init(struct ccu_data *ccu)
1260 struct kona_clk *kona_clks = ccu->kona_clks;
1263 flags = ccu_lock(ccu);
1264 __ccu_write_enable(ccu);
1266 for (which = 0; which < ccu->clk_num; which++) {
1269 if (!bcm_clk->ccu)
1275 __ccu_write_disable(ccu);
1276 ccu_unlock(ccu, flags);