Lines Matching refs:ccu

129 static inline u32 __ccu_read(struct ccu_data *ccu, u32 reg_offset)  in __ccu_read()  argument
131 return readl(ccu->base + reg_offset); in __ccu_read()
136 __ccu_write(struct ccu_data *ccu, u32 reg_offset, u32 reg_val) in __ccu_write() argument
138 writel(reg_val, ccu->base + reg_offset); in __ccu_write()
141 static inline unsigned long ccu_lock(struct ccu_data *ccu) in ccu_lock() argument
145 spin_lock_irqsave(&ccu->lock, flags); in ccu_lock()
149 static inline void ccu_unlock(struct ccu_data *ccu, unsigned long flags) in ccu_unlock() argument
151 spin_unlock_irqrestore(&ccu->lock, flags); in ccu_unlock()
158 static inline void __ccu_write_enable(struct ccu_data *ccu) in __ccu_write_enable() argument
160 if (ccu->write_enabled) { in __ccu_write_enable()
162 ccu->name); in __ccu_write_enable()
165 ccu->write_enabled = true; in __ccu_write_enable()
166 __ccu_write(ccu, 0, CCU_ACCESS_PASSWORD | 1); in __ccu_write_enable()
169 static inline void __ccu_write_disable(struct ccu_data *ccu) in __ccu_write_disable() argument
171 if (!ccu->write_enabled) { in __ccu_write_disable()
173 ccu->name); in __ccu_write_disable()
177 __ccu_write(ccu, 0, CCU_ACCESS_PASSWORD); in __ccu_write_disable()
178 ccu->write_enabled = false; in __ccu_write_disable()
190 __ccu_wait_bit(struct ccu_data *ccu, u32 reg_offset, u32 bit, bool want) in __ccu_wait_bit() argument
199 val = __ccu_read(ccu, reg_offset); in __ccu_wait_bit()
206 ccu->name, reg_offset, bit, want ? "set" : "clear"); in __ccu_wait_bit()
213 static bool __ccu_policy_engine_start(struct ccu_data *ccu, bool sync) in __ccu_policy_engine_start() argument
215 struct bcm_policy_ctl *control = &ccu->policy.control; in __ccu_policy_engine_start()
229 ret = __ccu_wait_bit(ccu, offset, go_bit, false); in __ccu_policy_engine_start()
232 __func__, ccu->name); in __ccu_policy_engine_start()
256 __ccu_write(ccu, offset, mask); in __ccu_policy_engine_start()
259 ret = __ccu_wait_bit(ccu, offset, go_bit, false); in __ccu_policy_engine_start()
262 __func__, ccu->name); in __ccu_policy_engine_start()
267 static bool __ccu_policy_engine_stop(struct ccu_data *ccu) in __ccu_policy_engine_stop() argument
269 struct bcm_lvm_en *enable = &ccu->policy.enable; in __ccu_policy_engine_stop()
281 ret = __ccu_wait_bit(ccu, offset, enable_bit, false); in __ccu_policy_engine_stop()
284 __func__, ccu->name); in __ccu_policy_engine_stop()
289 __ccu_write(ccu, offset, (u32)1 << enable_bit); in __ccu_policy_engine_stop()
292 ret = __ccu_wait_bit(ccu, offset, enable_bit, false); in __ccu_policy_engine_stop()
295 __func__, ccu->name); in __ccu_policy_engine_stop()
309 static bool policy_init(struct ccu_data *ccu, struct bcm_clk_policy *policy) in policy_init() argument
323 if (!__ccu_policy_engine_stop(ccu)) { in policy_init()
325 __func__, ccu->name); in policy_init()
338 reg_val = __ccu_read(ccu, offset); in policy_init()
340 __ccu_write(ccu, offset, reg_val); in policy_init()
345 ret = __ccu_policy_engine_start(ccu, true); in policy_init()
348 __func__, ccu->name); in policy_init()
357 __is_clk_gate_enabled(struct ccu_data *ccu, struct bcm_clk_gate *gate) in __is_clk_gate_enabled() argument
367 reg_val = __ccu_read(ccu, gate->offset); in __is_clk_gate_enabled()
374 is_clk_gate_enabled(struct ccu_data *ccu, struct bcm_clk_gate *gate) in is_clk_gate_enabled() argument
383 flags = ccu_lock(ccu); in is_clk_gate_enabled()
384 ret = __is_clk_gate_enabled(ccu, gate); in is_clk_gate_enabled()
385 ccu_unlock(ccu, flags); in is_clk_gate_enabled()
395 __gate_commit(struct ccu_data *ccu, struct bcm_clk_gate *gate) in __gate_commit() argument
405 reg_val = __ccu_read(ccu, gate->offset); in __gate_commit()
430 __ccu_write(ccu, gate->offset, reg_val); in __gate_commit()
437 return __ccu_wait_bit(ccu, gate->offset, gate->status_bit, enabled); in __gate_commit()
446 static bool gate_init(struct ccu_data *ccu, struct bcm_clk_gate *gate) in gate_init() argument
450 return __gate_commit(ccu, gate); in gate_init()
460 __clk_gate(struct ccu_data *ccu, struct bcm_clk_gate *gate, bool enable) in __clk_gate() argument
477 ret = __gate_commit(ccu, gate); in __clk_gate()
485 static int clk_gate(struct ccu_data *ccu, const char *name, in clk_gate() argument
500 flags = ccu_lock(ccu); in clk_gate()
501 __ccu_write_enable(ccu); in clk_gate()
503 success = __clk_gate(ccu, gate, enable); in clk_gate()
505 __ccu_write_disable(ccu); in clk_gate()
506 ccu_unlock(ccu, flags); in clk_gate()
526 static bool hyst_init(struct ccu_data *ccu, struct bcm_clk_hyst *hyst) in hyst_init() argument
539 reg_val = __ccu_read(ccu, offset); in hyst_init()
541 __ccu_write(ccu, offset, reg_val); in hyst_init()
552 static bool __clk_trigger(struct ccu_data *ccu, struct bcm_clk_trig *trig) in __clk_trigger() argument
555 __ccu_write(ccu, trig->offset, 1 << trig->bit); in __clk_trigger()
557 return __ccu_wait_bit(ccu, trig->offset, trig->bit, false); in __clk_trigger()
563 static u64 divider_read_scaled(struct ccu_data *ccu, struct bcm_clk_div *div) in divider_read_scaled() argument
572 flags = ccu_lock(ccu); in divider_read_scaled()
573 reg_val = __ccu_read(ccu, div->u.s.offset); in divider_read_scaled()
574 ccu_unlock(ccu, flags); in divider_read_scaled()
590 static int __div_commit(struct ccu_data *ccu, struct bcm_clk_gate *gate, in __div_commit() argument
606 reg_val = __ccu_read(ccu, div->u.s.offset); in __div_commit()
618 enabled = __is_clk_gate_enabled(ccu, gate); in __div_commit()
619 if (!enabled && !__clk_gate(ccu, gate, true)) { in __div_commit()
625 reg_val = __ccu_read(ccu, div->u.s.offset); in __div_commit()
628 __ccu_write(ccu, div->u.s.offset, reg_val); in __div_commit()
631 if (!__clk_trigger(ccu, trig)) in __div_commit()
635 if (!enabled && !__clk_gate(ccu, gate, false)) in __div_commit()
646 static bool div_init(struct ccu_data *ccu, struct bcm_clk_gate *gate, in div_init() argument
651 return !__div_commit(ccu, gate, div, trig); in div_init()
654 static int divider_write(struct ccu_data *ccu, struct bcm_clk_gate *gate, in divider_write() argument
670 flags = ccu_lock(ccu); in divider_write()
671 __ccu_write_enable(ccu); in divider_write()
673 ret = __div_commit(ccu, gate, div, trig); in divider_write()
675 __ccu_write_disable(ccu); in divider_write()
676 ccu_unlock(ccu, flags); in divider_write()
692 static unsigned long clk_recalc_rate(struct ccu_data *ccu, in clk_recalc_rate() argument
720 scaled_div = divider_read_scaled(ccu, pre_div); in clk_recalc_rate()
732 scaled_div = divider_read_scaled(ccu, div); in clk_recalc_rate()
747 static long round_rate(struct ccu_data *ccu, struct bcm_clk_div *div, in round_rate() argument
779 scaled_pre_div = divider_read_scaled(ccu, pre_div); in round_rate()
801 best_scaled_div = divider_read_scaled(ccu, div); in round_rate()
839 static u8 selector_read_index(struct ccu_data *ccu, struct bcm_clk_sel *sel) in selector_read_index() argument
851 flags = ccu_lock(ccu); in selector_read_index()
852 reg_val = __ccu_read(ccu, sel->offset); in selector_read_index()
853 ccu_unlock(ccu, flags); in selector_read_index()
861 __func__, parent_sel, ccu->name, sel->offset); in selector_read_index()
873 __sel_commit(struct ccu_data *ccu, struct bcm_clk_gate *gate, in __sel_commit() argument
891 reg_val = __ccu_read(ccu, sel->offset); in __sel_commit()
905 enabled = __is_clk_gate_enabled(ccu, gate); in __sel_commit()
906 if (!enabled && !__clk_gate(ccu, gate, true)) in __sel_commit()
910 reg_val = __ccu_read(ccu, sel->offset); in __sel_commit()
912 __ccu_write(ccu, sel->offset, reg_val); in __sel_commit()
915 if (!__clk_trigger(ccu, trig)) in __sel_commit()
919 if (!enabled && !__clk_gate(ccu, gate, false)) in __sel_commit()
930 static bool sel_init(struct ccu_data *ccu, struct bcm_clk_gate *gate, in sel_init() argument
935 return !__sel_commit(ccu, gate, sel, trig); in sel_init()
943 static int selector_write(struct ccu_data *ccu, struct bcm_clk_gate *gate, in selector_write() argument
957 flags = ccu_lock(ccu); in selector_write()
958 __ccu_write_enable(ccu); in selector_write()
960 ret = __sel_commit(ccu, gate, sel, trig); in selector_write()
962 __ccu_write_disable(ccu); in selector_write()
963 ccu_unlock(ccu, flags); in selector_write()
978 return clk_gate(bcm_clk->ccu, bcm_clk->init_data.name, gate, true); in kona_peri_clk_enable()
986 (void)clk_gate(bcm_clk->ccu, bcm_clk->init_data.name, gate, false); in kona_peri_clk_disable()
994 return is_clk_gate_enabled(bcm_clk->ccu, gate) ? 1 : 0; in kona_peri_clk_is_enabled()
1003 return clk_recalc_rate(bcm_clk->ccu, &data->div, &data->pre_div, in kona_peri_clk_recalc_rate()
1017 return round_rate(bcm_clk->ccu, div, &bcm_clk->u.peri->pre_div, in kona_peri_clk_round_rate()
1103 ret = selector_write(bcm_clk->ccu, &data->gate, sel, trig, index); in kona_peri_clk_set_parent()
1123 index = selector_read_index(bcm_clk->ccu, &data->sel); in kona_peri_clk_get_parent()
1160 (void)round_rate(bcm_clk->ccu, div, &data->pre_div, in kona_peri_clk_set_rate()
1167 ret = divider_write(bcm_clk->ccu, &data->gate, &data->div, in kona_peri_clk_set_rate()
1195 struct ccu_data *ccu = bcm_clk->ccu; in __peri_clk_init() local
1202 if (!policy_init(ccu, &peri->policy)) { in __peri_clk_init()
1207 if (!gate_init(ccu, &peri->gate)) { in __peri_clk_init()
1211 if (!hyst_init(ccu, &peri->hyst)) { in __peri_clk_init()
1215 if (!div_init(ccu, &peri->gate, &peri->div, &peri->trig)) { in __peri_clk_init()
1228 if (!div_init(ccu, &peri->gate, &peri->pre_div, trig)) { in __peri_clk_init()
1234 if (!sel_init(ccu, &peri->gate, &peri->sel, trig)) { in __peri_clk_init()
1255 bool __init kona_ccu_init(struct ccu_data *ccu) in kona_ccu_init() argument
1259 struct kona_clk *kona_clks = ccu->kona_clks; in kona_ccu_init()
1262 flags = ccu_lock(ccu); in kona_ccu_init()
1263 __ccu_write_enable(ccu); in kona_ccu_init()
1265 for (which = 0; which < ccu->clk_num; which++) { in kona_ccu_init()
1268 if (!bcm_clk->ccu) in kona_ccu_init()
1274 __ccu_write_disable(ccu); in kona_ccu_init()
1275 ccu_unlock(ccu, flags); in kona_ccu_init()