1 // SPDX-License-Identifier: GPL-2.0-only
7 #include <linux/clk-provider.h>
8 #include <linux/module.h>
9 #include <linux/of_device.h>
10 #include <linux/platform_device.h>
11 #include <linux/reset.h>
13 #include "ccu_common.h"
16 #include "ccu_reset.h"
18 #include "ccu-sun8i-de2.h"
20 static SUNXI_CCU_GATE(bus_mixer0_clk, "bus-mixer0", "bus-de",
22 static SUNXI_CCU_GATE(bus_mixer1_clk, "bus-mixer1", "bus-de",
24 static SUNXI_CCU_GATE(bus_wb_clk, "bus-wb", "bus-de",
26 static SUNXI_CCU_GATE(bus_rot_clk, "bus-rot", "bus-de",
29 static SUNXI_CCU_GATE(mixer0_clk, "mixer0", "mixer0-div",
30 0x00, BIT(0), CLK_SET_RATE_PARENT);
31 static SUNXI_CCU_GATE(mixer1_clk, "mixer1", "mixer1-div",
32 0x00, BIT(1), CLK_SET_RATE_PARENT);
33 static SUNXI_CCU_GATE(wb_clk, "wb", "wb-div",
34 0x00, BIT(2), CLK_SET_RATE_PARENT);
35 static SUNXI_CCU_GATE(rot_clk, "rot", "rot-div",
36 0x00, BIT(3), CLK_SET_RATE_PARENT);
38 static SUNXI_CCU_M(mixer0_div_clk, "mixer0-div", "de", 0x0c, 0, 4,
40 static SUNXI_CCU_M(mixer1_div_clk, "mixer1-div", "de", 0x0c, 4, 4,
42 static SUNXI_CCU_M(wb_div_clk, "wb-div", "de", 0x0c, 8, 4,
44 static SUNXI_CCU_M(rot_div_clk, "rot-div", "de", 0x0c, 0x0c, 4,
47 static SUNXI_CCU_M(mixer0_div_a83_clk, "mixer0-div", "pll-de", 0x0c, 0, 4,
49 static SUNXI_CCU_M(mixer1_div_a83_clk, "mixer1-div", "pll-de", 0x0c, 4, 4,
51 static SUNXI_CCU_M(wb_div_a83_clk, "wb-div", "pll-de", 0x0c, 8, 4,
53 static SUNXI_CCU_M(rot_div_a83_clk, "rot-div", "pll-de", 0x0c, 0x0c, 4,
56 static struct ccu_common *sun8i_de2_ccu_clks[] = {
62 &bus_mixer0_clk.common,
63 &bus_mixer1_clk.common,
67 &mixer0_div_clk.common,
68 &mixer1_div_clk.common,
72 &mixer0_div_a83_clk.common,
73 &mixer1_div_a83_clk.common,
74 &wb_div_a83_clk.common,
75 &rot_div_a83_clk.common,
78 static struct clk_hw_onecell_data sun8i_a83t_de2_hw_clks = {
80 [CLK_MIXER0] = &mixer0_clk.common.hw,
81 [CLK_MIXER1] = &mixer1_clk.common.hw,
82 [CLK_WB] = &wb_clk.common.hw,
83 [CLK_ROT] = &rot_clk.common.hw,
85 [CLK_BUS_MIXER0] = &bus_mixer0_clk.common.hw,
86 [CLK_BUS_MIXER1] = &bus_mixer1_clk.common.hw,
87 [CLK_BUS_WB] = &bus_wb_clk.common.hw,
88 [CLK_BUS_ROT] = &bus_rot_clk.common.hw,
90 [CLK_MIXER0_DIV] = &mixer0_div_a83_clk.common.hw,
91 [CLK_MIXER1_DIV] = &mixer1_div_a83_clk.common.hw,
92 [CLK_WB_DIV] = &wb_div_a83_clk.common.hw,
93 [CLK_ROT_DIV] = &rot_div_a83_clk.common.hw,
95 .num = CLK_NUMBER_WITH_ROT,
98 static struct clk_hw_onecell_data sun8i_h3_de2_hw_clks = {
100 [CLK_MIXER0] = &mixer0_clk.common.hw,
101 [CLK_MIXER1] = &mixer1_clk.common.hw,
102 [CLK_WB] = &wb_clk.common.hw,
104 [CLK_BUS_MIXER0] = &bus_mixer0_clk.common.hw,
105 [CLK_BUS_MIXER1] = &bus_mixer1_clk.common.hw,
106 [CLK_BUS_WB] = &bus_wb_clk.common.hw,
108 [CLK_MIXER0_DIV] = &mixer0_div_clk.common.hw,
109 [CLK_MIXER1_DIV] = &mixer1_div_clk.common.hw,
110 [CLK_WB_DIV] = &wb_div_clk.common.hw,
112 .num = CLK_NUMBER_WITHOUT_ROT,
115 static struct clk_hw_onecell_data sun8i_v3s_de2_hw_clks = {
117 [CLK_MIXER0] = &mixer0_clk.common.hw,
118 [CLK_WB] = &wb_clk.common.hw,
120 [CLK_BUS_MIXER0] = &bus_mixer0_clk.common.hw,
121 [CLK_BUS_WB] = &bus_wb_clk.common.hw,
123 [CLK_MIXER0_DIV] = &mixer0_div_clk.common.hw,
124 [CLK_WB_DIV] = &wb_div_clk.common.hw,
126 .num = CLK_NUMBER_WITHOUT_ROT,
129 static struct clk_hw_onecell_data sun50i_a64_de2_hw_clks = {
131 [CLK_MIXER0] = &mixer0_clk.common.hw,
132 [CLK_MIXER1] = &mixer1_clk.common.hw,
133 [CLK_WB] = &wb_clk.common.hw,
134 [CLK_ROT] = &rot_clk.common.hw,
136 [CLK_BUS_MIXER0] = &bus_mixer0_clk.common.hw,
137 [CLK_BUS_MIXER1] = &bus_mixer1_clk.common.hw,
138 [CLK_BUS_WB] = &bus_wb_clk.common.hw,
139 [CLK_BUS_ROT] = &bus_rot_clk.common.hw,
141 [CLK_MIXER0_DIV] = &mixer0_div_clk.common.hw,
142 [CLK_MIXER1_DIV] = &mixer1_div_clk.common.hw,
143 [CLK_WB_DIV] = &wb_div_clk.common.hw,
144 [CLK_ROT_DIV] = &rot_div_clk.common.hw,
146 .num = CLK_NUMBER_WITH_ROT,
149 static struct ccu_reset_map sun8i_a83t_de2_resets[] = {
150 [RST_MIXER0] = { 0x08, BIT(0) },
152 * Mixer1 reset line is shared with wb, so only RST_WB is
155 [RST_WB] = { 0x08, BIT(2) },
156 [RST_ROT] = { 0x08, BIT(3) },
159 static struct ccu_reset_map sun8i_h3_de2_resets[] = {
160 [RST_MIXER0] = { 0x08, BIT(0) },
162 * Mixer1 reset line is shared with wb, so only RST_WB is
164 * V3s doesn't have mixer1, so it also shares this struct.
166 [RST_WB] = { 0x08, BIT(2) },
169 static struct ccu_reset_map sun50i_a64_de2_resets[] = {
170 [RST_MIXER0] = { 0x08, BIT(0) },
171 [RST_MIXER1] = { 0x08, BIT(1) },
172 [RST_WB] = { 0x08, BIT(2) },
173 [RST_ROT] = { 0x08, BIT(3) },
176 static struct ccu_reset_map sun50i_h5_de2_resets[] = {
177 [RST_MIXER0] = { 0x08, BIT(0) },
178 [RST_MIXER1] = { 0x08, BIT(1) },
179 [RST_WB] = { 0x08, BIT(2) },
182 static const struct sunxi_ccu_desc sun8i_a83t_de2_clk_desc = {
183 .ccu_clks = sun8i_de2_ccu_clks,
184 .num_ccu_clks = ARRAY_SIZE(sun8i_de2_ccu_clks),
186 .hw_clks = &sun8i_a83t_de2_hw_clks,
188 .resets = sun8i_a83t_de2_resets,
189 .num_resets = ARRAY_SIZE(sun8i_a83t_de2_resets),
192 static const struct sunxi_ccu_desc sun8i_h3_de2_clk_desc = {
193 .ccu_clks = sun8i_de2_ccu_clks,
194 .num_ccu_clks = ARRAY_SIZE(sun8i_de2_ccu_clks),
196 .hw_clks = &sun8i_h3_de2_hw_clks,
198 .resets = sun8i_h3_de2_resets,
199 .num_resets = ARRAY_SIZE(sun8i_h3_de2_resets),
202 static const struct sunxi_ccu_desc sun8i_r40_de2_clk_desc = {
203 .ccu_clks = sun8i_de2_ccu_clks,
204 .num_ccu_clks = ARRAY_SIZE(sun8i_de2_ccu_clks),
206 .hw_clks = &sun50i_a64_de2_hw_clks,
208 .resets = sun8i_a83t_de2_resets,
209 .num_resets = ARRAY_SIZE(sun8i_a83t_de2_resets),
212 static const struct sunxi_ccu_desc sun8i_v3s_de2_clk_desc = {
213 .ccu_clks = sun8i_de2_ccu_clks,
214 .num_ccu_clks = ARRAY_SIZE(sun8i_de2_ccu_clks),
216 .hw_clks = &sun8i_v3s_de2_hw_clks,
218 .resets = sun8i_a83t_de2_resets,
219 .num_resets = ARRAY_SIZE(sun8i_a83t_de2_resets),
222 static const struct sunxi_ccu_desc sun50i_a64_de2_clk_desc = {
223 .ccu_clks = sun8i_de2_ccu_clks,
224 .num_ccu_clks = ARRAY_SIZE(sun8i_de2_ccu_clks),
226 .hw_clks = &sun50i_a64_de2_hw_clks,
228 .resets = sun50i_a64_de2_resets,
229 .num_resets = ARRAY_SIZE(sun50i_a64_de2_resets),
232 static const struct sunxi_ccu_desc sun50i_h5_de2_clk_desc = {
233 .ccu_clks = sun8i_de2_ccu_clks,
234 .num_ccu_clks = ARRAY_SIZE(sun8i_de2_ccu_clks),
236 .hw_clks = &sun8i_h3_de2_hw_clks,
238 .resets = sun50i_h5_de2_resets,
239 .num_resets = ARRAY_SIZE(sun50i_h5_de2_resets),
242 static int sunxi_de2_clk_probe(struct platform_device *pdev)
244 struct clk *bus_clk, *mod_clk;
245 struct reset_control *rstc;
247 const struct sunxi_ccu_desc *ccu_desc;
250 ccu_desc = of_device_get_match_data(&pdev->dev);
254 reg = devm_platform_ioremap_resource(pdev, 0);
258 bus_clk = devm_clk_get(&pdev->dev, "bus");
259 if (IS_ERR(bus_clk)) {
260 ret = PTR_ERR(bus_clk);
261 if (ret != -EPROBE_DEFER)
262 dev_err(&pdev->dev, "Couldn't get bus clk: %d\n", ret);
266 mod_clk = devm_clk_get(&pdev->dev, "mod");
267 if (IS_ERR(mod_clk)) {
268 ret = PTR_ERR(mod_clk);
269 if (ret != -EPROBE_DEFER)
270 dev_err(&pdev->dev, "Couldn't get mod clk: %d\n", ret);
274 rstc = devm_reset_control_get_exclusive(&pdev->dev, NULL);
277 if (ret != -EPROBE_DEFER)
279 "Couldn't get reset control: %d\n", ret);
283 /* The clocks need to be enabled for us to access the registers */
284 ret = clk_prepare_enable(bus_clk);
286 dev_err(&pdev->dev, "Couldn't enable bus clk: %d\n", ret);
290 ret = clk_prepare_enable(mod_clk);
292 dev_err(&pdev->dev, "Couldn't enable mod clk: %d\n", ret);
293 goto err_disable_bus_clk;
296 /* The reset control needs to be asserted for the controls to work */
297 ret = reset_control_deassert(rstc);
300 "Couldn't deassert reset control: %d\n", ret);
301 goto err_disable_mod_clk;
304 ret = devm_sunxi_ccu_probe(&pdev->dev, reg, ccu_desc);
306 goto err_assert_reset;
311 reset_control_assert(rstc);
313 clk_disable_unprepare(mod_clk);
315 clk_disable_unprepare(bus_clk);
319 static const struct of_device_id sunxi_de2_clk_ids[] = {
321 .compatible = "allwinner,sun8i-a83t-de2-clk",
322 .data = &sun8i_a83t_de2_clk_desc,
325 .compatible = "allwinner,sun8i-h3-de2-clk",
326 .data = &sun8i_h3_de2_clk_desc,
329 .compatible = "allwinner,sun8i-r40-de2-clk",
330 .data = &sun8i_r40_de2_clk_desc,
333 .compatible = "allwinner,sun8i-v3s-de2-clk",
334 .data = &sun8i_v3s_de2_clk_desc,
337 .compatible = "allwinner,sun50i-a64-de2-clk",
338 .data = &sun50i_a64_de2_clk_desc,
341 .compatible = "allwinner,sun50i-h5-de2-clk",
342 .data = &sun50i_h5_de2_clk_desc,
345 .compatible = "allwinner,sun50i-h6-de3-clk",
346 .data = &sun50i_h5_de2_clk_desc,
351 static struct platform_driver sunxi_de2_clk_driver = {
352 .probe = sunxi_de2_clk_probe,
354 .name = "sunxi-de2-clks",
355 .of_match_table = sunxi_de2_clk_ids,
358 module_platform_driver(sunxi_de2_clk_driver);
360 MODULE_IMPORT_NS(SUNXI_CCU);
361 MODULE_LICENSE("GPL");