Lines Matching refs:div
50 static inline u64 scaled_div_value(struct bcm_clk_div *div, u32 reg_div) in scaled_div_value() argument
52 return (u64)reg_div + ((u64)1 << div->u.s.frac_width); in scaled_div_value()
60 u64 scaled_div_build(struct bcm_clk_div *div, u32 div_value, u32 billionths) in scaled_div_build() argument
68 combined <<= div->u.s.frac_width; in scaled_div_build()
75 scaled_div_min(struct bcm_clk_div *div) in scaled_div_min() argument
77 if (divider_is_fixed(div)) in scaled_div_min()
78 return (u64)div->u.fixed; in scaled_div_min()
80 return scaled_div_value(div, 0); in scaled_div_min()
84 u64 scaled_div_max(struct bcm_clk_div *div) in scaled_div_max() argument
88 if (divider_is_fixed(div)) in scaled_div_max()
89 return (u64)div->u.fixed; in scaled_div_max()
91 reg_div = ((u32)1 << div->u.s.width) - 1; in scaled_div_max()
93 return scaled_div_value(div, reg_div); in scaled_div_max()
101 divider(struct bcm_clk_div *div, u64 scaled_div) in divider() argument
103 BUG_ON(scaled_div < scaled_div_min(div)); in divider()
104 BUG_ON(scaled_div > scaled_div_max(div)); in divider()
106 return (u32)(scaled_div - ((u64)1 << div->u.s.frac_width)); in divider()
111 scale_rate(struct bcm_clk_div *div, u32 rate) in scale_rate() argument
113 if (divider_is_fixed(div)) in scale_rate()
116 return (u64)rate << div->u.s.frac_width; in scale_rate()
556 static u64 divider_read_scaled(struct ccu_data *ccu, struct bcm_clk_div *div) in divider_read_scaled() argument
562 if (divider_is_fixed(div)) in divider_read_scaled()
563 return (u64)div->u.fixed; in divider_read_scaled()
566 reg_val = __ccu_read(ccu, div->u.s.offset); in divider_read_scaled()
570 reg_div = bitfield_extract(reg_val, div->u.s.shift, div->u.s.width); in divider_read_scaled()
573 return scaled_div_value(div, reg_div); in divider_read_scaled()
584 struct bcm_clk_div *div, struct bcm_clk_trig *trig) in __div_commit() argument
591 BUG_ON(divider_is_fixed(div)); in __div_commit()
598 if (div->u.s.scaled_div == BAD_SCALED_DIV_VALUE) { in __div_commit()
599 reg_val = __ccu_read(ccu, div->u.s.offset); in __div_commit()
600 reg_div = bitfield_extract(reg_val, div->u.s.shift, in __div_commit()
601 div->u.s.width); in __div_commit()
602 div->u.s.scaled_div = scaled_div_value(div, reg_div); in __div_commit()
608 reg_div = divider(div, div->u.s.scaled_div); in __div_commit()
618 reg_val = __ccu_read(ccu, div->u.s.offset); in __div_commit()
619 reg_val = bitfield_replace(reg_val, div->u.s.shift, div->u.s.width, in __div_commit()
621 __ccu_write(ccu, div->u.s.offset, reg_val); in __div_commit()
640 struct bcm_clk_div *div, struct bcm_clk_trig *trig) in div_init() argument
642 if (!divider_exists(div) || divider_is_fixed(div)) in div_init()
644 return !__div_commit(ccu, gate, div, trig); in div_init()
648 struct bcm_clk_div *div, struct bcm_clk_trig *trig, in divider_write() argument
655 BUG_ON(divider_is_fixed(div)); in divider_write()
657 previous = div->u.s.scaled_div; in divider_write()
661 div->u.s.scaled_div = scaled_div; in divider_write()
666 ret = __div_commit(ccu, gate, div, trig); in divider_write()
672 div->u.s.scaled_div = previous; /* Revert the change */ in divider_write()
686 struct bcm_clk_div *div, struct bcm_clk_div *pre_div, in clk_recalc_rate() argument
693 if (!divider_exists(div)) in clk_recalc_rate()
712 scaled_rate = scale_rate(div, scaled_rate); in clk_recalc_rate()
717 scaled_parent_rate = scale_rate(div, parent_rate); in clk_recalc_rate()
725 scaled_div = divider_read_scaled(ccu, div); in clk_recalc_rate()
740 static long round_rate(struct ccu_data *ccu, struct bcm_clk_div *div, in round_rate() argument
751 BUG_ON(!divider_exists(div)); in round_rate()
771 scaled_rate = scale_rate(div, scaled_rate); in round_rate()
776 scaled_parent_rate = scale_rate(div, parent_rate); in round_rate()
784 if (!divider_is_fixed(div)) { in round_rate()
787 min_scaled_div = scaled_div_min(div); in round_rate()
788 max_scaled_div = scaled_div_max(div); in round_rate()
794 best_scaled_div = divider_read_scaled(ccu, div); in round_rate()
996 return clk_recalc_rate(bcm_clk->ccu, &data->div, &data->pre_div, in kona_peri_clk_recalc_rate()
1004 struct bcm_clk_div *div = &bcm_clk->u.peri->div; in kona_peri_clk_round_rate() local
1006 if (!divider_exists(div)) in kona_peri_clk_round_rate()
1010 return round_rate(bcm_clk->ccu, div, &bcm_clk->u.peri->pre_div, in kona_peri_clk_round_rate()
1127 struct bcm_clk_div *div = &data->div; in kona_peri_clk_set_rate() local
1137 if (!divider_exists(div)) in kona_peri_clk_set_rate()
1145 if (divider_is_fixed(&data->div)) in kona_peri_clk_set_rate()
1153 (void)round_rate(bcm_clk->ccu, div, &data->pre_div, in kona_peri_clk_set_rate()
1160 ret = divider_write(bcm_clk->ccu, &data->gate, &data->div, in kona_peri_clk_set_rate()
1208 if (!div_init(ccu, &peri->gate, &peri->div, &peri->trig)) { in __peri_clk_init()