1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (c) 2016 Icenowy Zheng <icenowy@aosc.xyz>
6 #include <linux/clk-provider.h>
7 #include <linux/of_address.h>
8 #include <linux/platform_device.h>
10 #include "ccu_common.h"
11 #include "ccu_reset.h"
18 #include "ccu-sun8i-r.h"
20 static const struct clk_parent_data ar100_parents
[] = {
21 { .fw_name
= "losc" },
22 { .fw_name
= "hosc" },
23 { .fw_name
= "pll-periph" },
24 { .fw_name
= "iosc" },
27 static const struct ccu_mux_var_prediv ar100_predivs
[] = {
28 { .index
= 2, .shift
= 8, .width
= 5 },
31 static struct ccu_div ar100_clk
= {
32 .div
= _SUNXI_CCU_DIV_FLAGS(4, 2, CLK_DIVIDER_POWER_OF_TWO
),
38 .var_predivs
= ar100_predivs
,
39 .n_var_predivs
= ARRAY_SIZE(ar100_predivs
),
44 .features
= CCU_FEATURE_VARIABLE_PREDIV
,
45 .hw
.init
= CLK_HW_INIT_PARENTS_DATA("ar100",
52 static CLK_FIXED_FACTOR_HW(ahb0_clk
, "ahb0", &ar100_clk
.common
.hw
, 1, 1, 0);
54 static SUNXI_CCU_M(apb0_clk
, "apb0", "ahb0", 0x0c, 0, 2, 0);
57 * Define the parent as an array that can be reused to save space
58 * instead of having compound literals for each gate. Also have it
59 * non-const so we can change it on the A83T.
61 static const struct clk_hw
*apb0_gate_parent
[] = { &apb0_clk
.common
.hw
};
62 static SUNXI_CCU_GATE_HWS(apb0_pio_clk
, "apb0-pio",
63 apb0_gate_parent
, 0x28, BIT(0), 0);
64 static SUNXI_CCU_GATE_HWS(apb0_ir_clk
, "apb0-ir",
65 apb0_gate_parent
, 0x28, BIT(1), 0);
66 static SUNXI_CCU_GATE_HWS(apb0_timer_clk
, "apb0-timer",
67 apb0_gate_parent
, 0x28, BIT(2), 0);
68 static SUNXI_CCU_GATE_HWS(apb0_rsb_clk
, "apb0-rsb",
69 apb0_gate_parent
, 0x28, BIT(3), 0);
70 static SUNXI_CCU_GATE_HWS(apb0_uart_clk
, "apb0-uart",
71 apb0_gate_parent
, 0x28, BIT(4), 0);
72 static SUNXI_CCU_GATE_HWS(apb0_i2c_clk
, "apb0-i2c",
73 apb0_gate_parent
, 0x28, BIT(6), 0);
74 static SUNXI_CCU_GATE_HWS(apb0_twd_clk
, "apb0-twd",
75 apb0_gate_parent
, 0x28, BIT(7), 0);
77 static const char * const r_mod0_default_parents
[] = { "osc32k", "osc24M" };
78 static SUNXI_CCU_MP_WITH_MUX_GATE(ir_clk
, "ir",
79 r_mod0_default_parents
, 0x54,
86 static const struct clk_parent_data a83t_r_mod0_parents
[] = {
87 { .fw_name
= "iosc" },
88 { .fw_name
= "hosc" },
90 static const struct ccu_mux_fixed_prediv a83t_ir_predivs
[] = {
91 { .index
= 0, .div
= 16 },
93 static struct ccu_mp a83t_ir_clk
= {
96 .m
= _SUNXI_CCU_DIV(0, 4),
97 .p
= _SUNXI_CCU_DIV(16, 2),
102 .fixed_predivs
= a83t_ir_predivs
,
103 .n_predivs
= ARRAY_SIZE(a83t_ir_predivs
),
108 .features
= CCU_FEATURE_VARIABLE_PREDIV
,
109 .hw
.init
= CLK_HW_INIT_PARENTS_DATA("ir",
116 static struct ccu_common
*sun8i_a83t_r_ccu_clks
[] = {
119 &apb0_pio_clk
.common
,
121 &apb0_timer_clk
.common
,
122 &apb0_rsb_clk
.common
,
123 &apb0_uart_clk
.common
,
124 &apb0_i2c_clk
.common
,
125 &apb0_twd_clk
.common
,
129 static struct ccu_common
*sun8i_h3_r_ccu_clks
[] = {
132 &apb0_pio_clk
.common
,
134 &apb0_timer_clk
.common
,
135 &apb0_uart_clk
.common
,
136 &apb0_i2c_clk
.common
,
137 &apb0_twd_clk
.common
,
141 static struct ccu_common
*sun50i_a64_r_ccu_clks
[] = {
144 &apb0_pio_clk
.common
,
146 &apb0_timer_clk
.common
,
147 &apb0_rsb_clk
.common
,
148 &apb0_uart_clk
.common
,
149 &apb0_i2c_clk
.common
,
150 &apb0_twd_clk
.common
,
154 static struct clk_hw_onecell_data sun8i_a83t_r_hw_clks
= {
156 [CLK_AR100
] = &ar100_clk
.common
.hw
,
157 [CLK_AHB0
] = &ahb0_clk
.hw
,
158 [CLK_APB0
] = &apb0_clk
.common
.hw
,
159 [CLK_APB0_PIO
] = &apb0_pio_clk
.common
.hw
,
160 [CLK_APB0_IR
] = &apb0_ir_clk
.common
.hw
,
161 [CLK_APB0_TIMER
] = &apb0_timer_clk
.common
.hw
,
162 [CLK_APB0_RSB
] = &apb0_rsb_clk
.common
.hw
,
163 [CLK_APB0_UART
] = &apb0_uart_clk
.common
.hw
,
164 [CLK_APB0_I2C
] = &apb0_i2c_clk
.common
.hw
,
165 [CLK_APB0_TWD
] = &apb0_twd_clk
.common
.hw
,
166 [CLK_IR
] = &a83t_ir_clk
.common
.hw
,
171 static struct clk_hw_onecell_data sun8i_h3_r_hw_clks
= {
173 [CLK_AR100
] = &ar100_clk
.common
.hw
,
174 [CLK_AHB0
] = &ahb0_clk
.hw
,
175 [CLK_APB0
] = &apb0_clk
.common
.hw
,
176 [CLK_APB0_PIO
] = &apb0_pio_clk
.common
.hw
,
177 [CLK_APB0_IR
] = &apb0_ir_clk
.common
.hw
,
178 [CLK_APB0_TIMER
] = &apb0_timer_clk
.common
.hw
,
179 [CLK_APB0_UART
] = &apb0_uart_clk
.common
.hw
,
180 [CLK_APB0_I2C
] = &apb0_i2c_clk
.common
.hw
,
181 [CLK_APB0_TWD
] = &apb0_twd_clk
.common
.hw
,
182 [CLK_IR
] = &ir_clk
.common
.hw
,
187 static struct clk_hw_onecell_data sun50i_a64_r_hw_clks
= {
189 [CLK_AR100
] = &ar100_clk
.common
.hw
,
190 [CLK_AHB0
] = &ahb0_clk
.hw
,
191 [CLK_APB0
] = &apb0_clk
.common
.hw
,
192 [CLK_APB0_PIO
] = &apb0_pio_clk
.common
.hw
,
193 [CLK_APB0_IR
] = &apb0_ir_clk
.common
.hw
,
194 [CLK_APB0_TIMER
] = &apb0_timer_clk
.common
.hw
,
195 [CLK_APB0_RSB
] = &apb0_rsb_clk
.common
.hw
,
196 [CLK_APB0_UART
] = &apb0_uart_clk
.common
.hw
,
197 [CLK_APB0_I2C
] = &apb0_i2c_clk
.common
.hw
,
198 [CLK_APB0_TWD
] = &apb0_twd_clk
.common
.hw
,
199 [CLK_IR
] = &ir_clk
.common
.hw
,
204 static struct ccu_reset_map sun8i_a83t_r_ccu_resets
[] = {
205 [RST_APB0_IR
] = { 0xb0, BIT(1) },
206 [RST_APB0_TIMER
] = { 0xb0, BIT(2) },
207 [RST_APB0_RSB
] = { 0xb0, BIT(3) },
208 [RST_APB0_UART
] = { 0xb0, BIT(4) },
209 [RST_APB0_I2C
] = { 0xb0, BIT(6) },
212 static struct ccu_reset_map sun8i_h3_r_ccu_resets
[] = {
213 [RST_APB0_IR
] = { 0xb0, BIT(1) },
214 [RST_APB0_TIMER
] = { 0xb0, BIT(2) },
215 [RST_APB0_UART
] = { 0xb0, BIT(4) },
216 [RST_APB0_I2C
] = { 0xb0, BIT(6) },
219 static struct ccu_reset_map sun50i_a64_r_ccu_resets
[] = {
220 [RST_APB0_IR
] = { 0xb0, BIT(1) },
221 [RST_APB0_TIMER
] = { 0xb0, BIT(2) },
222 [RST_APB0_RSB
] = { 0xb0, BIT(3) },
223 [RST_APB0_UART
] = { 0xb0, BIT(4) },
224 [RST_APB0_I2C
] = { 0xb0, BIT(6) },
227 static const struct sunxi_ccu_desc sun8i_a83t_r_ccu_desc
= {
228 .ccu_clks
= sun8i_a83t_r_ccu_clks
,
229 .num_ccu_clks
= ARRAY_SIZE(sun8i_a83t_r_ccu_clks
),
231 .hw_clks
= &sun8i_a83t_r_hw_clks
,
233 .resets
= sun8i_a83t_r_ccu_resets
,
234 .num_resets
= ARRAY_SIZE(sun8i_a83t_r_ccu_resets
),
237 static const struct sunxi_ccu_desc sun8i_h3_r_ccu_desc
= {
238 .ccu_clks
= sun8i_h3_r_ccu_clks
,
239 .num_ccu_clks
= ARRAY_SIZE(sun8i_h3_r_ccu_clks
),
241 .hw_clks
= &sun8i_h3_r_hw_clks
,
243 .resets
= sun8i_h3_r_ccu_resets
,
244 .num_resets
= ARRAY_SIZE(sun8i_h3_r_ccu_resets
),
247 static const struct sunxi_ccu_desc sun50i_a64_r_ccu_desc
= {
248 .ccu_clks
= sun50i_a64_r_ccu_clks
,
249 .num_ccu_clks
= ARRAY_SIZE(sun50i_a64_r_ccu_clks
),
251 .hw_clks
= &sun50i_a64_r_hw_clks
,
253 .resets
= sun50i_a64_r_ccu_resets
,
254 .num_resets
= ARRAY_SIZE(sun50i_a64_r_ccu_resets
),
257 static void __init
sunxi_r_ccu_init(struct device_node
*node
,
258 const struct sunxi_ccu_desc
*desc
)
262 reg
= of_io_request_and_map(node
, 0, of_node_full_name(node
));
264 pr_err("%pOF: Could not map the clock registers\n", node
);
268 sunxi_ccu_probe(node
, reg
, desc
);
271 static void __init
sun8i_a83t_r_ccu_setup(struct device_node
*node
)
273 sunxi_r_ccu_init(node
, &sun8i_a83t_r_ccu_desc
);
275 CLK_OF_DECLARE(sun8i_a83t_r_ccu
, "allwinner,sun8i-a83t-r-ccu",
276 sun8i_a83t_r_ccu_setup
);
278 static void __init
sun8i_h3_r_ccu_setup(struct device_node
*node
)
280 sunxi_r_ccu_init(node
, &sun8i_h3_r_ccu_desc
);
282 CLK_OF_DECLARE(sun8i_h3_r_ccu
, "allwinner,sun8i-h3-r-ccu",
283 sun8i_h3_r_ccu_setup
);
285 static void __init
sun50i_a64_r_ccu_setup(struct device_node
*node
)
287 sunxi_r_ccu_init(node
, &sun50i_a64_r_ccu_desc
);
289 CLK_OF_DECLARE(sun50i_a64_r_ccu
, "allwinner,sun50i-a64-r-ccu",
290 sun50i_a64_r_ccu_setup
);