2 #include <linux/clk-provider.h>
3 #include <linux/slab.h>
5 #include <linux/of_address.h>
9 void mmp_clk_init(struct device_node
*np
, struct mmp_clk_unit
*unit
,
12 static struct clk
**clk_table
;
14 clk_table
= kcalloc(nr_clks
, sizeof(struct clk
*), GFP_KERNEL
);
18 unit
->clk_table
= clk_table
;
19 unit
->nr_clks
= nr_clks
;
20 unit
->clk_data
.clks
= clk_table
;
21 unit
->clk_data
.clk_num
= nr_clks
;
22 of_clk_add_provider(np
, of_clk_src_onecell_get
, &unit
->clk_data
);
25 void mmp_register_fixed_rate_clks(struct mmp_clk_unit
*unit
,
26 struct mmp_param_fixed_rate_clk
*clks
,
32 for (i
= 0; i
< size
; i
++) {
33 clk
= clk_register_fixed_rate(NULL
, clks
[i
].name
,
38 pr_err("%s: failed to register clock %s\n",
39 __func__
, clks
[i
].name
);
43 unit
->clk_table
[clks
[i
].id
] = clk
;
47 void mmp_register_fixed_factor_clks(struct mmp_clk_unit
*unit
,
48 struct mmp_param_fixed_factor_clk
*clks
,
54 for (i
= 0; i
< size
; i
++) {
55 clk
= clk_register_fixed_factor(NULL
, clks
[i
].name
,
57 clks
[i
].flags
, clks
[i
].mult
,
60 pr_err("%s: failed to register clock %s\n",
61 __func__
, clks
[i
].name
);
65 unit
->clk_table
[clks
[i
].id
] = clk
;
69 void mmp_register_general_gate_clks(struct mmp_clk_unit
*unit
,
70 struct mmp_param_general_gate_clk
*clks
,
71 void __iomem
*base
, int size
)
76 for (i
= 0; i
< size
; i
++) {
77 clk
= clk_register_gate(NULL
, clks
[i
].name
,
80 base
+ clks
[i
].offset
,
86 pr_err("%s: failed to register clock %s\n",
87 __func__
, clks
[i
].name
);
91 unit
->clk_table
[clks
[i
].id
] = clk
;
95 void mmp_register_gate_clks(struct mmp_clk_unit
*unit
,
96 struct mmp_param_gate_clk
*clks
,
97 void __iomem
*base
, int size
)
102 for (i
= 0; i
< size
; i
++) {
103 clk
= mmp_clk_register_gate(NULL
, clks
[i
].name
,
106 base
+ clks
[i
].offset
,
114 pr_err("%s: failed to register clock %s\n",
115 __func__
, clks
[i
].name
);
119 unit
->clk_table
[clks
[i
].id
] = clk
;
123 void mmp_register_mux_clks(struct mmp_clk_unit
*unit
,
124 struct mmp_param_mux_clk
*clks
,
125 void __iomem
*base
, int size
)
130 for (i
= 0; i
< size
; i
++) {
131 clk
= clk_register_mux(NULL
, clks
[i
].name
,
135 base
+ clks
[i
].offset
,
142 pr_err("%s: failed to register clock %s\n",
143 __func__
, clks
[i
].name
);
147 unit
->clk_table
[clks
[i
].id
] = clk
;
151 void mmp_register_div_clks(struct mmp_clk_unit
*unit
,
152 struct mmp_param_div_clk
*clks
,
153 void __iomem
*base
, int size
)
158 for (i
= 0; i
< size
; i
++) {
159 clk
= clk_register_divider(NULL
, clks
[i
].name
,
162 base
+ clks
[i
].offset
,
169 pr_err("%s: failed to register clock %s\n",
170 __func__
, clks
[i
].name
);
174 unit
->clk_table
[clks
[i
].id
] = clk
;
178 void mmp_clk_add(struct mmp_clk_unit
*unit
, unsigned int id
,
181 if (IS_ERR_OR_NULL(clk
)) {
182 pr_err("CLK %d has invalid pointer %p\n", id
, clk
);
185 if (id
> unit
->nr_clks
) {
186 pr_err("CLK %d is invalid\n", id
);
190 unit
->clk_table
[id
] = clk
;