Lines Matching +full:div +full:- +full:clk
1 // SPDX-License-Identifier: GPL-2.0-only
9 #define pr_fmt(fmt) "clk-frac-synth: " fmt
11 #include <linux/clk-provider.h>
15 #include "clk.h"
24 * Fout= Fin/2*div (division factor)
25 * div is 17 bits:-
26 * 0-13 (fractional part)
27 * 14-16 (integer part)
28 * div is (16-14 bits).(13-0 bits) (in binary)
30 * Fout = Fin/(2 * div)
31 * Fout = ((Fin / 10000)/(2 * div)) * 10000
32 * Fout = (2^14 * (Fin / 10000)/(2^14 * (2 * div))) * 10000
33 * Fout = (((Fin / 10000) << 14)/(2 * (div << 14))) * 10000
35 * div << 14 simply 17 bit value written at register.
45 struct frac_rate_tbl *rtbl = frac->rtbl; in frac_calc_rate()
49 prate /= (2 * rtbl[index].div); in frac_calc_rate()
62 frac->rtbl_cnt, &unused); in clk_frac_round_rate()
70 unsigned int div = 1, val; in clk_frac_recalc_rate() local
72 if (frac->lock) in clk_frac_recalc_rate()
73 spin_lock_irqsave(frac->lock, flags); in clk_frac_recalc_rate()
75 val = readl_relaxed(frac->reg); in clk_frac_recalc_rate()
77 if (frac->lock) in clk_frac_recalc_rate()
78 spin_unlock_irqrestore(frac->lock, flags); in clk_frac_recalc_rate()
80 div = val & DIV_FACTOR_MASK; in clk_frac_recalc_rate()
82 if (!div) in clk_frac_recalc_rate()
87 parent_rate = (parent_rate << 14) / (2 * div); in clk_frac_recalc_rate()
96 struct frac_rate_tbl *rtbl = frac->rtbl; in clk_frac_set_rate()
100 clk_round_rate_index(hw, drate, prate, frac_calc_rate, frac->rtbl_cnt, in clk_frac_set_rate()
103 if (frac->lock) in clk_frac_set_rate()
104 spin_lock_irqsave(frac->lock, flags); in clk_frac_set_rate()
106 val = readl_relaxed(frac->reg) & ~DIV_FACTOR_MASK; in clk_frac_set_rate()
107 val |= rtbl[i].div & DIV_FACTOR_MASK; in clk_frac_set_rate()
108 writel_relaxed(val, frac->reg); in clk_frac_set_rate()
110 if (frac->lock) in clk_frac_set_rate()
111 spin_unlock_irqrestore(frac->lock, flags); in clk_frac_set_rate()
122 struct clk *clk_register_frac(const char *name, const char *parent_name, in clk_register_frac()
128 struct clk *clk; in clk_register_frac() local
132 return ERR_PTR(-EINVAL); in clk_register_frac()
137 return ERR_PTR(-ENOMEM); in clk_register_frac()
140 frac->reg = reg; in clk_register_frac()
141 frac->rtbl = rtbl; in clk_register_frac()
142 frac->rtbl_cnt = rtbl_cnt; in clk_register_frac()
143 frac->lock = lock; in clk_register_frac()
144 frac->hw.init = &init; in clk_register_frac()
152 clk = clk_register(NULL, &frac->hw); in clk_register_frac()
153 if (!IS_ERR_OR_NULL(clk)) in clk_register_frac()
154 return clk; in clk_register_frac()
156 pr_err("clk register failed\n"); in clk_register_frac()