13 #include <linux/slab.h>
18 #define to_clk_prcmu(_hw) container_of(_hw, struct clk_prcmu, hw)
28 static int clk_prcmu_prepare(
struct clk_hw *
hw)
31 return prcmu_request_clock(clk->
cg_sel,
true);
34 static void clk_prcmu_unprepare(
struct clk_hw *
hw)
37 if (prcmu_request_clock(clk->
cg_sel,
false))
38 pr_err(
"clk_prcmu: %s failed to disable %s.\n", __func__,
42 static int clk_prcmu_enable(
struct clk_hw *hw)
49 static void clk_prcmu_disable(
struct clk_hw *hw)
55 static int clk_prcmu_is_enabled(
struct clk_hw *hw)
61 static unsigned long clk_prcmu_recalc_rate(
struct clk_hw *hw,
62 unsigned long parent_rate)
68 static long clk_prcmu_round_rate(
struct clk_hw *hw,
unsigned long rate,
69 unsigned long *parent_rate)
75 static int clk_prcmu_set_rate(
struct clk_hw *hw,
unsigned long rate,
76 unsigned long parent_rate)
82 static int request_ape_opp100(
bool enable)
102 static int clk_prcmu_opp_prepare(
struct clk_hw *hw)
107 err = request_ape_opp100(
true);
109 pr_err(
"clk_prcmu: %s failed to request APE OPP100 for %s.\n",
110 __func__, hw->init->name);
114 err = prcmu_request_clock(clk->
cg_sel,
true);
116 request_ape_opp100(
false);
121 static void clk_prcmu_opp_unprepare(
struct clk_hw *hw)
125 if (prcmu_request_clock(clk->
cg_sel,
false))
127 if (request_ape_opp100(
false))
132 pr_err(
"clk_prcmu: %s failed to disable %s.\n", __func__,
136 static struct clk_ops clk_prcmu_scalable_ops = {
137 .prepare = clk_prcmu_prepare,
138 .unprepare = clk_prcmu_unprepare,
139 .enable = clk_prcmu_enable,
140 .disable = clk_prcmu_disable,
141 .is_enabled = clk_prcmu_is_enabled,
142 .recalc_rate = clk_prcmu_recalc_rate,
143 .round_rate = clk_prcmu_round_rate,
144 .set_rate = clk_prcmu_set_rate,
147 static struct clk_ops clk_prcmu_gate_ops = {
148 .prepare = clk_prcmu_prepare,
149 .unprepare = clk_prcmu_unprepare,
150 .enable = clk_prcmu_enable,
151 .disable = clk_prcmu_disable,
152 .is_enabled = clk_prcmu_is_enabled,
153 .recalc_rate = clk_prcmu_recalc_rate,
156 static struct clk_ops clk_prcmu_rate_ops = {
157 .is_enabled = clk_prcmu_is_enabled,
158 .recalc_rate = clk_prcmu_recalc_rate,
161 static struct clk_ops clk_prcmu_opp_gate_ops = {
162 .prepare = clk_prcmu_opp_prepare,
163 .unprepare = clk_prcmu_opp_unprepare,
164 .enable = clk_prcmu_enable,
165 .disable = clk_prcmu_disable,
166 .is_enabled = clk_prcmu_is_enabled,
167 .recalc_rate = clk_prcmu_recalc_rate,
170 static struct clk *clk_reg_prcmu(
const char *
name,
171 const char *parent_name,
178 struct clk_init_data clk_prcmu_init;
182 pr_err(
"clk_prcmu: %s invalid arguments passed\n", __func__);
188 pr_err(
"clk_prcmu: %s could not allocate clk\n", __func__);
198 clk_prcmu_init.name =
name;
199 clk_prcmu_init.ops = clk_prcmu_ops;
200 clk_prcmu_init.flags =
flags;
201 clk_prcmu_init.parent_names = (parent_name ? &parent_name :
NULL);
202 clk_prcmu_init.num_parents = (parent_name ? 1 : 0);
203 clk->
hw.init = &clk_prcmu_init;
206 if (IS_ERR_OR_NULL(clk_reg))
213 pr_err(
"clk_prcmu: %s failed to register clk\n", __func__);
218 const char *parent_name,
223 return clk_reg_prcmu(name, parent_name, cg_sel, rate, flags,
224 &clk_prcmu_scalable_ops);
228 const char *parent_name,
232 return clk_reg_prcmu(name, parent_name, cg_sel, 0, flags,
233 &clk_prcmu_gate_ops);
237 const char *parent_name,
241 return clk_reg_prcmu(name, parent_name, cg_sel, 0, flags,
242 &clk_prcmu_rate_ops);
246 const char *parent_name,
250 return clk_reg_prcmu(name, parent_name, cg_sel, 0, flags,
251 &clk_prcmu_opp_gate_ops);