1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef __MACH_MMP_CLK_H
3 #define __MACH_MMP_CLK_H
5 #include <linux/clk-provider.h>
6 #include <linux/math.h>
7 #include <linux/pm_domain.h>
8 #include <linux/clkdev.h>
10 #define APBC_NO_BUS_CTRL BIT(0)
11 #define APBC_POWER_CTRL BIT(1)
14 /* Clock type "factor" */
15 struct mmp_clk_factor_masks
{
17 unsigned int num_mask
;
18 unsigned int den_mask
;
19 unsigned int num_shift
;
20 unsigned int den_shift
;
21 unsigned int enable_mask
;
24 struct mmp_clk_factor
{
27 struct mmp_clk_factor_masks
*masks
;
28 struct u32_fract
*ftbl
;
29 unsigned int ftbl_cnt
;
33 extern struct clk
*mmp_clk_register_factor(const char *name
,
34 const char *parent_name
, unsigned long flags
,
35 void __iomem
*base
, struct mmp_clk_factor_masks
*masks
,
36 struct u32_fract
*ftbl
, unsigned int ftbl_cnt
,
39 /* Clock type "mix" */
40 #define MMP_CLK_BITS_MASK(width, shift) \
41 (((1 << (width)) - 1) << (shift))
42 #define MMP_CLK_BITS_GET_VAL(data, width, shift) \
43 ((data & MMP_CLK_BITS_MASK(width, shift)) >> (shift))
44 #define MMP_CLK_BITS_SET_VAL(val, width, shift) \
45 (((val) << (shift)) & MMP_CLK_BITS_MASK(width, shift))
53 /* The register layout */
54 struct mmp_clk_mix_reg_info
{
55 void __iomem
*reg_clk_ctrl
;
56 void __iomem
*reg_clk_sel
;
64 /* The suggested clock table from user. */
65 struct mmp_clk_mix_clk_table
{
72 struct mmp_clk_mix_config
{
73 struct mmp_clk_mix_reg_info reg_info
;
74 struct mmp_clk_mix_clk_table
*table
;
75 unsigned int table_size
;
77 struct clk_div_table
*div_table
;
84 struct mmp_clk_mix_reg_info reg_info
;
85 struct mmp_clk_mix_clk_table
*table
;
87 struct clk_div_table
*div_table
;
88 unsigned int table_size
;
95 extern const struct clk_ops mmp_clk_mix_ops
;
96 extern struct clk
*mmp_clk_register_mix(struct device
*dev
,
98 const char * const *parent_names
,
101 struct mmp_clk_mix_config
*config
,
105 /* Clock type "gate". MMP private gate */
106 #define MMP_CLK_GATE_NEED_DELAY BIT(0)
108 struct mmp_clk_gate
{
118 extern const struct clk_ops mmp_clk_gate_ops
;
119 extern struct clk
*mmp_clk_register_gate(struct device
*dev
, const char *name
,
120 const char *parent_name
, unsigned long flags
,
121 void __iomem
*reg
, u32 mask
, u32 val_enable
,
122 u32 val_disable
, unsigned int gate_flags
,
125 extern struct clk
*mmp_clk_register_apbc(const char *name
,
126 const char *parent_name
, void __iomem
*base
,
127 unsigned int delay
, unsigned int apbc_flags
, spinlock_t
*lock
);
128 extern struct clk
*mmp_clk_register_apmu(const char *name
,
129 const char *parent_name
, void __iomem
*base
, u32 enable_mask
,
132 struct mmp_clk_unit
{
133 unsigned int nr_clks
;
134 struct clk
**clk_table
;
135 struct clk_onecell_data clk_data
;
138 struct mmp_param_fixed_rate_clk
{
141 const char *parent_name
;
143 unsigned long fixed_rate
;
145 void mmp_register_fixed_rate_clks(struct mmp_clk_unit
*unit
,
146 struct mmp_param_fixed_rate_clk
*clks
,
149 struct mmp_param_fixed_factor_clk
{
152 const char *parent_name
;
157 void mmp_register_fixed_factor_clks(struct mmp_clk_unit
*unit
,
158 struct mmp_param_fixed_factor_clk
*clks
,
161 struct mmp_param_general_gate_clk
{
164 const char *parent_name
;
166 unsigned long offset
;
171 void mmp_register_general_gate_clks(struct mmp_clk_unit
*unit
,
172 struct mmp_param_general_gate_clk
*clks
,
173 void __iomem
*base
, int size
);
175 struct mmp_param_gate_clk
{
178 const char *parent_name
;
180 unsigned long offset
;
184 unsigned int gate_flags
;
187 void mmp_register_gate_clks(struct mmp_clk_unit
*unit
,
188 struct mmp_param_gate_clk
*clks
,
189 void __iomem
*base
, int size
);
191 struct mmp_param_mux_clk
{
194 const char * const *parent_name
;
197 unsigned long offset
;
203 void mmp_register_mux_clks(struct mmp_clk_unit
*unit
,
204 struct mmp_param_mux_clk
*clks
,
205 void __iomem
*base
, int size
);
207 struct mmp_param_div_clk
{
210 const char *parent_name
;
212 unsigned long offset
;
218 void mmp_register_div_clks(struct mmp_clk_unit
*unit
,
219 struct mmp_param_div_clk
*clks
,
220 void __iomem
*base
, int size
);
222 struct mmp_param_pll_clk
{
225 unsigned long default_rate
;
226 unsigned long enable_offset
;
228 unsigned long offset
;
231 unsigned long input_rate
;
232 unsigned long postdiv_offset
;
233 unsigned long postdiv_shift
;
235 void mmp_register_pll_clks(struct mmp_clk_unit
*unit
,
236 struct mmp_param_pll_clk
*clks
,
237 void __iomem
*base
, int size
);
239 #define DEFINE_MIX_REG_INFO(w_d, s_d, w_m, s_m, fc) \
241 .width_div = (w_d), \
242 .shift_div = (s_d), \
243 .width_mux = (w_m), \
244 .shift_mux = (s_m), \
248 void mmp_clk_init(struct device_node
*np
, struct mmp_clk_unit
*unit
,
250 void mmp_clk_add(struct mmp_clk_unit
*unit
, unsigned int id
,
254 #define MMP_PM_DOMAIN_NO_DISABLE BIT(0)
256 struct generic_pm_domain
*mmp_pm_domain_register(const char *name
,
258 u32 power_on
, u32 reset
, u32 clock_enable
,
259 unsigned int flags
, spinlock_t
*lock
);