1 // SPDX-License-Identifier: GPL-2.0+
3 // OWL composite clock driver
5 // Copyright (c) 2014 Actions Semi Inc.
6 // Author: David Liu <liuwei@actions-semi.com>
8 // Copyright (c) 2018 Linaro Ltd.
9 // Author: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
11 #include <linux/clk-provider.h>
12 #include <linux/regmap.h>
14 #include "owl-composite.h"
16 static u8
owl_comp_get_parent(struct clk_hw
*hw
)
18 struct owl_composite
*comp
= hw_to_owl_comp(hw
);
20 return owl_mux_helper_get_parent(&comp
->common
, &comp
->mux_hw
);
23 static int owl_comp_set_parent(struct clk_hw
*hw
, u8 index
)
25 struct owl_composite
*comp
= hw_to_owl_comp(hw
);
27 return owl_mux_helper_set_parent(&comp
->common
, &comp
->mux_hw
, index
);
30 static void owl_comp_disable(struct clk_hw
*hw
)
32 struct owl_composite
*comp
= hw_to_owl_comp(hw
);
33 struct owl_clk_common
*common
= &comp
->common
;
35 owl_gate_set(common
, &comp
->gate_hw
, false);
38 static int owl_comp_enable(struct clk_hw
*hw
)
40 struct owl_composite
*comp
= hw_to_owl_comp(hw
);
41 struct owl_clk_common
*common
= &comp
->common
;
43 owl_gate_set(common
, &comp
->gate_hw
, true);
48 static int owl_comp_is_enabled(struct clk_hw
*hw
)
50 struct owl_composite
*comp
= hw_to_owl_comp(hw
);
51 struct owl_clk_common
*common
= &comp
->common
;
53 return owl_gate_clk_is_enabled(common
, &comp
->gate_hw
);
56 static int owl_comp_div_determine_rate(struct clk_hw
*hw
,
57 struct clk_rate_request
*req
)
59 struct owl_composite
*comp
= hw_to_owl_comp(hw
);
62 rate
= owl_divider_helper_round_rate(&comp
->common
, &comp
->rate
.div_hw
,
63 req
->rate
, &req
->best_parent_rate
);
71 static unsigned long owl_comp_div_recalc_rate(struct clk_hw
*hw
,
72 unsigned long parent_rate
)
74 struct owl_composite
*comp
= hw_to_owl_comp(hw
);
76 return owl_divider_helper_recalc_rate(&comp
->common
, &comp
->rate
.div_hw
,
80 static int owl_comp_div_set_rate(struct clk_hw
*hw
, unsigned long rate
,
81 unsigned long parent_rate
)
83 struct owl_composite
*comp
= hw_to_owl_comp(hw
);
85 return owl_divider_helper_set_rate(&comp
->common
, &comp
->rate
.div_hw
,
89 static int owl_comp_fact_determine_rate(struct clk_hw
*hw
,
90 struct clk_rate_request
*req
)
92 struct owl_composite
*comp
= hw_to_owl_comp(hw
);
95 rate
= owl_factor_helper_round_rate(&comp
->common
,
96 &comp
->rate
.factor_hw
,
97 req
->rate
, &req
->best_parent_rate
);
105 static unsigned long owl_comp_fact_recalc_rate(struct clk_hw
*hw
,
106 unsigned long parent_rate
)
108 struct owl_composite
*comp
= hw_to_owl_comp(hw
);
110 return owl_factor_helper_recalc_rate(&comp
->common
,
111 &comp
->rate
.factor_hw
,
115 static int owl_comp_fact_set_rate(struct clk_hw
*hw
, unsigned long rate
,
116 unsigned long parent_rate
)
118 struct owl_composite
*comp
= hw_to_owl_comp(hw
);
120 return owl_factor_helper_set_rate(&comp
->common
,
121 &comp
->rate
.factor_hw
,
125 static long owl_comp_fix_fact_round_rate(struct clk_hw
*hw
, unsigned long rate
,
126 unsigned long *parent_rate
)
128 struct owl_composite
*comp
= hw_to_owl_comp(hw
);
129 struct clk_fixed_factor
*fix_fact_hw
= &comp
->rate
.fix_fact_hw
;
131 return comp
->fix_fact_ops
->round_rate(&fix_fact_hw
->hw
, rate
, parent_rate
);
134 static unsigned long owl_comp_fix_fact_recalc_rate(struct clk_hw
*hw
,
135 unsigned long parent_rate
)
137 struct owl_composite
*comp
= hw_to_owl_comp(hw
);
138 struct clk_fixed_factor
*fix_fact_hw
= &comp
->rate
.fix_fact_hw
;
140 return comp
->fix_fact_ops
->recalc_rate(&fix_fact_hw
->hw
, parent_rate
);
144 static int owl_comp_fix_fact_set_rate(struct clk_hw
*hw
, unsigned long rate
,
145 unsigned long parent_rate
)
148 * We must report success but we can do so unconditionally because
149 * owl_comp_fix_fact_round_rate returns values that ensure this call is
156 const struct clk_ops owl_comp_div_ops
= {
158 .get_parent
= owl_comp_get_parent
,
159 .set_parent
= owl_comp_set_parent
,
162 .disable
= owl_comp_disable
,
163 .enable
= owl_comp_enable
,
164 .is_enabled
= owl_comp_is_enabled
,
167 .determine_rate
= owl_comp_div_determine_rate
,
168 .recalc_rate
= owl_comp_div_recalc_rate
,
169 .set_rate
= owl_comp_div_set_rate
,
173 const struct clk_ops owl_comp_fact_ops
= {
175 .get_parent
= owl_comp_get_parent
,
176 .set_parent
= owl_comp_set_parent
,
179 .disable
= owl_comp_disable
,
180 .enable
= owl_comp_enable
,
181 .is_enabled
= owl_comp_is_enabled
,
184 .determine_rate
= owl_comp_fact_determine_rate
,
185 .recalc_rate
= owl_comp_fact_recalc_rate
,
186 .set_rate
= owl_comp_fact_set_rate
,
189 const struct clk_ops owl_comp_fix_fact_ops
= {
191 .disable
= owl_comp_disable
,
192 .enable
= owl_comp_enable
,
193 .is_enabled
= owl_comp_is_enabled
,
196 .round_rate
= owl_comp_fix_fact_round_rate
,
197 .recalc_rate
= owl_comp_fix_fact_recalc_rate
,
198 .set_rate
= owl_comp_fix_fact_set_rate
,
202 const struct clk_ops owl_comp_pass_ops
= {
204 .determine_rate
= clk_hw_determine_rate_no_reparent
,
205 .get_parent
= owl_comp_get_parent
,
206 .set_parent
= owl_comp_set_parent
,
209 .disable
= owl_comp_disable
,
210 .enable
= owl_comp_enable
,
211 .is_enabled
= owl_comp_is_enabled
,