Lines Matching +full:clk +full:- +full:div

12 #define pr_fmt(fmt) "clk-frac-synth: " fmt
14 #include <linux/clk-provider.h>
18 #include "clk.h"
27 * Fout= Fin/2*div (division factor)
28 * div is 17 bits:-
29 * 0-13 (fractional part)
30 * 14-16 (integer part)
31 * div is (16-14 bits).(13-0 bits) (in binary)
33 * Fout = Fin/(2 * div)
34 * Fout = ((Fin / 10000)/(2 * div)) * 10000
35 * Fout = (2^14 * (Fin / 10000)/(2^14 * (2 * div))) * 10000
36 * Fout = (((Fin / 10000) << 14)/(2 * (div << 14))) * 10000
38 * div << 14 simply 17 bit value written at register.
48 struct frac_rate_tbl *rtbl = frac->rtbl; in frac_calc_rate()
52 prate /= (2 * rtbl[index].div); in frac_calc_rate()
65 frac->rtbl_cnt, &unused); in clk_frac_round_rate()
73 unsigned int div = 1, val; in clk_frac_recalc_rate() local
75 if (frac->lock) in clk_frac_recalc_rate()
76 spin_lock_irqsave(frac->lock, flags); in clk_frac_recalc_rate()
78 val = readl_relaxed(frac->reg); in clk_frac_recalc_rate()
80 if (frac->lock) in clk_frac_recalc_rate()
81 spin_unlock_irqrestore(frac->lock, flags); in clk_frac_recalc_rate()
83 div = val & DIV_FACTOR_MASK; in clk_frac_recalc_rate()
85 if (!div) in clk_frac_recalc_rate()
90 parent_rate = (parent_rate << 14) / (2 * div); in clk_frac_recalc_rate()
99 struct frac_rate_tbl *rtbl = frac->rtbl; in clk_frac_set_rate()
103 clk_round_rate_index(hw, drate, prate, frac_calc_rate, frac->rtbl_cnt, in clk_frac_set_rate()
106 if (frac->lock) in clk_frac_set_rate()
107 spin_lock_irqsave(frac->lock, flags); in clk_frac_set_rate()
109 val = readl_relaxed(frac->reg) & ~DIV_FACTOR_MASK; in clk_frac_set_rate()
110 val |= rtbl[i].div & DIV_FACTOR_MASK; in clk_frac_set_rate()
111 writel_relaxed(val, frac->reg); in clk_frac_set_rate()
113 if (frac->lock) in clk_frac_set_rate()
114 spin_unlock_irqrestore(frac->lock, flags); in clk_frac_set_rate()
125 struct clk *clk_register_frac(const char *name, const char *parent_name, in clk_register_frac()
131 struct clk *clk; in clk_register_frac() local
135 return ERR_PTR(-EINVAL); in clk_register_frac()
140 return ERR_PTR(-ENOMEM); in clk_register_frac()
143 frac->reg = reg; in clk_register_frac()
144 frac->rtbl = rtbl; in clk_register_frac()
145 frac->rtbl_cnt = rtbl_cnt; in clk_register_frac()
146 frac->lock = lock; in clk_register_frac()
147 frac->hw.init = &init; in clk_register_frac()
155 clk = clk_register(NULL, &frac->hw); in clk_register_frac()
156 if (!IS_ERR_OR_NULL(clk)) in clk_register_frac()
157 return clk; in clk_register_frac()
159 pr_err("clk register failed\n"); in clk_register_frac()