13 #include <linux/slab.h>
25 #define to_clk_factor(hw) container_of(hw, struct clk_factor, hw)
34 static long clk_factor_round_rate(
struct clk_hw *
hw,
unsigned long drate,
38 unsigned long rate = 0, prev_rate;
41 for (i = 0; i < factor->
ftbl_cnt; i++) {
43 rate = (((*prate / 10000) * factor->
ftbl[i].num) /
44 (factor->
ftbl[
i].den * factor->
masks->factor)) * 10000;
54 static unsigned long clk_factor_recalc_rate(
struct clk_hw *hw,
55 unsigned long parent_rate)
72 return (((parent_rate / 10000) * den) /
73 (num * factor->
masks->factor)) * 10000;
77 static int clk_factor_set_rate(
struct clk_hw *hw,
unsigned long drate,
84 unsigned long prev_rate, rate = 0;
86 for (i = 0; i < factor->
ftbl_cnt; i++) {
88 rate = (((prate / 10000) * factor->
ftbl[i].num) /
89 (factor->
ftbl[
i].den * factor->
masks->factor)) * 10000;
104 writel_relaxed(val, factor->
base);
109 static struct clk_ops clk_factor_ops = {
110 .recalc_rate = clk_factor_recalc_rate,
111 .round_rate = clk_factor_round_rate,
112 .set_rate = clk_factor_set_rate,
118 unsigned int ftbl_cnt)
121 struct clk_init_data init;
125 pr_err(
"%s: must pass a clk_factor_mask\n", __func__);
129 factor = kzalloc(
sizeof(*factor),
GFP_KERNEL);
131 pr_err(
"%s: could not allocate factor clk\n", __func__);
137 factor->
masks = masks;
143 init.ops = &clk_factor_ops;
145 init.parent_names = &parent_name;
146 init.num_parents = 1;
149 if (IS_ERR_OR_NULL(clk))