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/clkdev.h>
8 #define APBC_NO_BUS_CTRL BIT(0)
9 #define APBC_POWER_CTRL BIT(1)
12 /* Clock type "factor" */
13 struct mmp_clk_factor_masks
{
15 unsigned int num_mask
;
16 unsigned int den_mask
;
17 unsigned int num_shift
;
18 unsigned int den_shift
;
21 struct mmp_clk_factor_tbl
{
26 struct mmp_clk_factor
{
29 struct mmp_clk_factor_masks
*masks
;
30 struct mmp_clk_factor_tbl
*ftbl
;
31 unsigned int ftbl_cnt
;
35 extern struct clk
*mmp_clk_register_factor(const char *name
,
36 const char *parent_name
, unsigned long flags
,
37 void __iomem
*base
, struct mmp_clk_factor_masks
*masks
,
38 struct mmp_clk_factor_tbl
*ftbl
, unsigned int ftbl_cnt
,
41 /* Clock type "mix" */
42 #define MMP_CLK_BITS_MASK(width, shift) \
43 (((1 << (width)) - 1) << (shift))
44 #define MMP_CLK_BITS_GET_VAL(data, width, shift) \
45 ((data & MMP_CLK_BITS_MASK(width, shift)) >> (shift))
46 #define MMP_CLK_BITS_SET_VAL(val, width, shift) \
47 (((val) << (shift)) & MMP_CLK_BITS_MASK(width, shift))
55 /* The register layout */
56 struct mmp_clk_mix_reg_info
{
57 void __iomem
*reg_clk_ctrl
;
58 void __iomem
*reg_clk_sel
;
66 /* The suggested clock table from user. */
67 struct mmp_clk_mix_clk_table
{
74 struct mmp_clk_mix_config
{
75 struct mmp_clk_mix_reg_info reg_info
;
76 struct mmp_clk_mix_clk_table
*table
;
77 unsigned int table_size
;
79 struct clk_div_table
*div_table
;
86 struct mmp_clk_mix_reg_info reg_info
;
87 struct mmp_clk_mix_clk_table
*table
;
89 struct clk_div_table
*div_table
;
90 unsigned int table_size
;
97 extern const struct clk_ops mmp_clk_mix_ops
;
98 extern struct clk
*mmp_clk_register_mix(struct device
*dev
,
100 const char **parent_names
,
103 struct mmp_clk_mix_config
*config
,
107 /* Clock type "gate". MMP private gate */
108 #define MMP_CLK_GATE_NEED_DELAY BIT(0)
110 struct mmp_clk_gate
{
120 extern const struct clk_ops mmp_clk_gate_ops
;
121 extern struct clk
*mmp_clk_register_gate(struct device
*dev
, const char *name
,
122 const char *parent_name
, unsigned long flags
,
123 void __iomem
*reg
, u32 mask
, u32 val_enable
,
124 u32 val_disable
, unsigned int gate_flags
,
128 extern struct clk
*mmp_clk_register_pll2(const char *name
,
129 const char *parent_name
, unsigned long flags
);
130 extern struct clk
*mmp_clk_register_apbc(const char *name
,
131 const char *parent_name
, void __iomem
*base
,
132 unsigned int delay
, unsigned int apbc_flags
, spinlock_t
*lock
);
133 extern struct clk
*mmp_clk_register_apmu(const char *name
,
134 const char *parent_name
, void __iomem
*base
, u32 enable_mask
,
137 struct mmp_clk_unit
{
138 unsigned int nr_clks
;
139 struct clk
**clk_table
;
140 struct clk_onecell_data clk_data
;
143 struct mmp_param_fixed_rate_clk
{
146 const char *parent_name
;
148 unsigned long fixed_rate
;
150 void mmp_register_fixed_rate_clks(struct mmp_clk_unit
*unit
,
151 struct mmp_param_fixed_rate_clk
*clks
,
154 struct mmp_param_fixed_factor_clk
{
157 const char *parent_name
;
162 void mmp_register_fixed_factor_clks(struct mmp_clk_unit
*unit
,
163 struct mmp_param_fixed_factor_clk
*clks
,
166 struct mmp_param_general_gate_clk
{
169 const char *parent_name
;
171 unsigned long offset
;
176 void mmp_register_general_gate_clks(struct mmp_clk_unit
*unit
,
177 struct mmp_param_general_gate_clk
*clks
,
178 void __iomem
*base
, int size
);
180 struct mmp_param_gate_clk
{
183 const char *parent_name
;
185 unsigned long offset
;
189 unsigned int gate_flags
;
192 void mmp_register_gate_clks(struct mmp_clk_unit
*unit
,
193 struct mmp_param_gate_clk
*clks
,
194 void __iomem
*base
, int size
);
196 struct mmp_param_mux_clk
{
199 const char **parent_name
;
202 unsigned long offset
;
208 void mmp_register_mux_clks(struct mmp_clk_unit
*unit
,
209 struct mmp_param_mux_clk
*clks
,
210 void __iomem
*base
, int size
);
212 struct mmp_param_div_clk
{
215 const char *parent_name
;
217 unsigned long offset
;
223 void mmp_register_div_clks(struct mmp_clk_unit
*unit
,
224 struct mmp_param_div_clk
*clks
,
225 void __iomem
*base
, int size
);
227 #define DEFINE_MIX_REG_INFO(w_d, s_d, w_m, s_m, fc) \
229 .width_div = (w_d), \
230 .shift_div = (s_d), \
231 .width_mux = (w_m), \
232 .shift_mux = (s_m), \
236 void mmp_clk_init(struct device_node
*np
, struct mmp_clk_unit
*unit
,
238 void mmp_clk_add(struct mmp_clk_unit
*unit
, unsigned int id
,