xref: /linux/drivers/clk/sunxi-ng/ccu-sun8i-r.c (revision cdb8b80b60935515b86cfe534f69934b13937052)
1*cdb8b80bSIcenowy Zheng /*
2*cdb8b80bSIcenowy Zheng  * Copyright (c) 2016 Icenowy Zheng <icenowy@aosc.xyz>
3*cdb8b80bSIcenowy Zheng  *
4*cdb8b80bSIcenowy Zheng  * This software is licensed under the terms of the GNU General Public
5*cdb8b80bSIcenowy Zheng  * License version 2, as published by the Free Software Foundation, and
6*cdb8b80bSIcenowy Zheng  * may be copied, distributed, and modified under those terms.
7*cdb8b80bSIcenowy Zheng  *
8*cdb8b80bSIcenowy Zheng  * This program is distributed in the hope that it will be useful,
9*cdb8b80bSIcenowy Zheng  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10*cdb8b80bSIcenowy Zheng  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11*cdb8b80bSIcenowy Zheng  * GNU General Public License for more details.
12*cdb8b80bSIcenowy Zheng  */
13*cdb8b80bSIcenowy Zheng 
14*cdb8b80bSIcenowy Zheng #include <linux/clk-provider.h>
15*cdb8b80bSIcenowy Zheng #include <linux/of_address.h>
16*cdb8b80bSIcenowy Zheng #include <linux/platform_device.h>
17*cdb8b80bSIcenowy Zheng 
18*cdb8b80bSIcenowy Zheng #include "ccu_common.h"
19*cdb8b80bSIcenowy Zheng #include "ccu_reset.h"
20*cdb8b80bSIcenowy Zheng 
21*cdb8b80bSIcenowy Zheng #include "ccu_div.h"
22*cdb8b80bSIcenowy Zheng #include "ccu_gate.h"
23*cdb8b80bSIcenowy Zheng #include "ccu_mp.h"
24*cdb8b80bSIcenowy Zheng #include "ccu_nm.h"
25*cdb8b80bSIcenowy Zheng 
26*cdb8b80bSIcenowy Zheng #include "ccu-sun8i-r.h"
27*cdb8b80bSIcenowy Zheng 
28*cdb8b80bSIcenowy Zheng static const char * const ar100_parents[] = { "osc32k", "osc24M",
29*cdb8b80bSIcenowy Zheng 					     "pll-periph0", "iosc" };
30*cdb8b80bSIcenowy Zheng 
31*cdb8b80bSIcenowy Zheng static struct ccu_div ar100_clk = {
32*cdb8b80bSIcenowy Zheng 	.div		= _SUNXI_CCU_DIV_FLAGS(4, 2, CLK_DIVIDER_POWER_OF_TWO),
33*cdb8b80bSIcenowy Zheng 
34*cdb8b80bSIcenowy Zheng 	.mux		= {
35*cdb8b80bSIcenowy Zheng 		.shift	= 16,
36*cdb8b80bSIcenowy Zheng 		.width	= 2,
37*cdb8b80bSIcenowy Zheng 
38*cdb8b80bSIcenowy Zheng 		.variable_prediv	= {
39*cdb8b80bSIcenowy Zheng 			.index	= 2,
40*cdb8b80bSIcenowy Zheng 			.shift	= 8,
41*cdb8b80bSIcenowy Zheng 			.width	= 5,
42*cdb8b80bSIcenowy Zheng 		},
43*cdb8b80bSIcenowy Zheng 	},
44*cdb8b80bSIcenowy Zheng 
45*cdb8b80bSIcenowy Zheng 	.common		= {
46*cdb8b80bSIcenowy Zheng 		.reg		= 0x00,
47*cdb8b80bSIcenowy Zheng 		.features	= CCU_FEATURE_VARIABLE_PREDIV,
48*cdb8b80bSIcenowy Zheng 		.hw.init	= CLK_HW_INIT_PARENTS("ar100",
49*cdb8b80bSIcenowy Zheng 						      ar100_parents,
50*cdb8b80bSIcenowy Zheng 						      &ccu_div_ops,
51*cdb8b80bSIcenowy Zheng 						      0),
52*cdb8b80bSIcenowy Zheng 	},
53*cdb8b80bSIcenowy Zheng };
54*cdb8b80bSIcenowy Zheng 
55*cdb8b80bSIcenowy Zheng static CLK_FIXED_FACTOR(ahb0_clk, "ahb0", "ar100", 1, 1, 0);
56*cdb8b80bSIcenowy Zheng 
57*cdb8b80bSIcenowy Zheng static struct ccu_div apb0_clk = {
58*cdb8b80bSIcenowy Zheng 	.div		= _SUNXI_CCU_DIV_FLAGS(0, 2, CLK_DIVIDER_POWER_OF_TWO),
59*cdb8b80bSIcenowy Zheng 
60*cdb8b80bSIcenowy Zheng 	.common		= {
61*cdb8b80bSIcenowy Zheng 		.reg		= 0x0c,
62*cdb8b80bSIcenowy Zheng 		.hw.init	= CLK_HW_INIT("apb0",
63*cdb8b80bSIcenowy Zheng 					      "ahb0",
64*cdb8b80bSIcenowy Zheng 					      &ccu_div_ops,
65*cdb8b80bSIcenowy Zheng 					      0),
66*cdb8b80bSIcenowy Zheng 	},
67*cdb8b80bSIcenowy Zheng };
68*cdb8b80bSIcenowy Zheng 
69*cdb8b80bSIcenowy Zheng static SUNXI_CCU_GATE(apb0_pio_clk,	"apb0-pio",	"apb0",
70*cdb8b80bSIcenowy Zheng 		      0x28, BIT(0), 0);
71*cdb8b80bSIcenowy Zheng static SUNXI_CCU_GATE(apb0_ir_clk,	"apb0-ir",	"apb0",
72*cdb8b80bSIcenowy Zheng 		      0x28, BIT(1), 0);
73*cdb8b80bSIcenowy Zheng static SUNXI_CCU_GATE(apb0_timer_clk,	"apb0-timer",	"apb0",
74*cdb8b80bSIcenowy Zheng 		      0x28, BIT(2), 0);
75*cdb8b80bSIcenowy Zheng static SUNXI_CCU_GATE(apb0_rsb_clk,	"apb0-rsb",	"apb0",
76*cdb8b80bSIcenowy Zheng 		      0x28, BIT(3), 0);
77*cdb8b80bSIcenowy Zheng static SUNXI_CCU_GATE(apb0_uart_clk,	"apb0-uart",	"apb0",
78*cdb8b80bSIcenowy Zheng 		      0x28, BIT(4), 0);
79*cdb8b80bSIcenowy Zheng static SUNXI_CCU_GATE(apb0_i2c_clk,	"apb0-i2c",	"apb0",
80*cdb8b80bSIcenowy Zheng 		      0x28, BIT(6), 0);
81*cdb8b80bSIcenowy Zheng static SUNXI_CCU_GATE(apb0_twd_clk,	"apb0-twd",	"apb0",
82*cdb8b80bSIcenowy Zheng 		      0x28, BIT(7), 0);
83*cdb8b80bSIcenowy Zheng 
84*cdb8b80bSIcenowy Zheng static const char * const r_mod0_default_parents[] = { "osc32K", "osc24M" };
85*cdb8b80bSIcenowy Zheng static SUNXI_CCU_MP_WITH_MUX_GATE(ir_clk, "ir",
86*cdb8b80bSIcenowy Zheng 				  r_mod0_default_parents, 0x54,
87*cdb8b80bSIcenowy Zheng 				  0, 4,		/* M */
88*cdb8b80bSIcenowy Zheng 				  16, 2,	/* P */
89*cdb8b80bSIcenowy Zheng 				  24, 2,	/* mux */
90*cdb8b80bSIcenowy Zheng 				  BIT(31),	/* gate */
91*cdb8b80bSIcenowy Zheng 				  0);
92*cdb8b80bSIcenowy Zheng 
93*cdb8b80bSIcenowy Zheng static struct ccu_common *sun8i_h3_r_ccu_clks[] = {
94*cdb8b80bSIcenowy Zheng 	&ar100_clk.common,
95*cdb8b80bSIcenowy Zheng 	&apb0_clk.common,
96*cdb8b80bSIcenowy Zheng 	&apb0_pio_clk.common,
97*cdb8b80bSIcenowy Zheng 	&apb0_ir_clk.common,
98*cdb8b80bSIcenowy Zheng 	&apb0_timer_clk.common,
99*cdb8b80bSIcenowy Zheng 	&apb0_uart_clk.common,
100*cdb8b80bSIcenowy Zheng 	&apb0_i2c_clk.common,
101*cdb8b80bSIcenowy Zheng 	&apb0_twd_clk.common,
102*cdb8b80bSIcenowy Zheng 	&ir_clk.common,
103*cdb8b80bSIcenowy Zheng };
104*cdb8b80bSIcenowy Zheng 
105*cdb8b80bSIcenowy Zheng static struct ccu_common *sun50i_a64_r_ccu_clks[] = {
106*cdb8b80bSIcenowy Zheng 	&ar100_clk.common,
107*cdb8b80bSIcenowy Zheng 	&apb0_clk.common,
108*cdb8b80bSIcenowy Zheng 	&apb0_pio_clk.common,
109*cdb8b80bSIcenowy Zheng 	&apb0_ir_clk.common,
110*cdb8b80bSIcenowy Zheng 	&apb0_timer_clk.common,
111*cdb8b80bSIcenowy Zheng 	&apb0_rsb_clk.common,
112*cdb8b80bSIcenowy Zheng 	&apb0_uart_clk.common,
113*cdb8b80bSIcenowy Zheng 	&apb0_i2c_clk.common,
114*cdb8b80bSIcenowy Zheng 	&apb0_twd_clk.common,
115*cdb8b80bSIcenowy Zheng 	&ir_clk.common,
116*cdb8b80bSIcenowy Zheng };
117*cdb8b80bSIcenowy Zheng 
118*cdb8b80bSIcenowy Zheng static struct clk_hw_onecell_data sun8i_h3_r_hw_clks = {
119*cdb8b80bSIcenowy Zheng 	.hws	= {
120*cdb8b80bSIcenowy Zheng 		[CLK_AR100]		= &ar100_clk.common.hw,
121*cdb8b80bSIcenowy Zheng 		[CLK_AHB0]		= &ahb0_clk.hw,
122*cdb8b80bSIcenowy Zheng 		[CLK_APB0]		= &apb0_clk.common.hw,
123*cdb8b80bSIcenowy Zheng 		[CLK_APB0_PIO]		= &apb0_pio_clk.common.hw,
124*cdb8b80bSIcenowy Zheng 		[CLK_APB0_IR]		= &apb0_ir_clk.common.hw,
125*cdb8b80bSIcenowy Zheng 		[CLK_APB0_TIMER]	= &apb0_timer_clk.common.hw,
126*cdb8b80bSIcenowy Zheng 		[CLK_APB0_UART]		= &apb0_uart_clk.common.hw,
127*cdb8b80bSIcenowy Zheng 		[CLK_APB0_I2C]		= &apb0_i2c_clk.common.hw,
128*cdb8b80bSIcenowy Zheng 		[CLK_APB0_TWD]		= &apb0_twd_clk.common.hw,
129*cdb8b80bSIcenowy Zheng 		[CLK_IR]		= &ir_clk.common.hw,
130*cdb8b80bSIcenowy Zheng 	},
131*cdb8b80bSIcenowy Zheng 	.num	= CLK_NUMBER,
132*cdb8b80bSIcenowy Zheng };
133*cdb8b80bSIcenowy Zheng 
134*cdb8b80bSIcenowy Zheng static struct clk_hw_onecell_data sun50i_a64_r_hw_clks = {
135*cdb8b80bSIcenowy Zheng 	.hws	= {
136*cdb8b80bSIcenowy Zheng 		[CLK_AR100]		= &ar100_clk.common.hw,
137*cdb8b80bSIcenowy Zheng 		[CLK_AHB0]		= &ahb0_clk.hw,
138*cdb8b80bSIcenowy Zheng 		[CLK_APB0]		= &apb0_clk.common.hw,
139*cdb8b80bSIcenowy Zheng 		[CLK_APB0_PIO]		= &apb0_pio_clk.common.hw,
140*cdb8b80bSIcenowy Zheng 		[CLK_APB0_IR]		= &apb0_ir_clk.common.hw,
141*cdb8b80bSIcenowy Zheng 		[CLK_APB0_TIMER]	= &apb0_timer_clk.common.hw,
142*cdb8b80bSIcenowy Zheng 		[CLK_APB0_RSB]		= &apb0_rsb_clk.common.hw,
143*cdb8b80bSIcenowy Zheng 		[CLK_APB0_UART]		= &apb0_uart_clk.common.hw,
144*cdb8b80bSIcenowy Zheng 		[CLK_APB0_I2C]		= &apb0_i2c_clk.common.hw,
145*cdb8b80bSIcenowy Zheng 		[CLK_APB0_TWD]		= &apb0_twd_clk.common.hw,
146*cdb8b80bSIcenowy Zheng 		[CLK_IR]		= &ir_clk.common.hw,
147*cdb8b80bSIcenowy Zheng 	},
148*cdb8b80bSIcenowy Zheng 	.num	= CLK_NUMBER,
149*cdb8b80bSIcenowy Zheng };
150*cdb8b80bSIcenowy Zheng 
151*cdb8b80bSIcenowy Zheng static struct ccu_reset_map sun8i_h3_r_ccu_resets[] = {
152*cdb8b80bSIcenowy Zheng 	[RST_APB0_IR]		=  { 0xb0, BIT(1) },
153*cdb8b80bSIcenowy Zheng 	[RST_APB0_TIMER]	=  { 0xb0, BIT(2) },
154*cdb8b80bSIcenowy Zheng 	[RST_APB0_UART]		=  { 0xb0, BIT(4) },
155*cdb8b80bSIcenowy Zheng 	[RST_APB0_I2C]		=  { 0xb0, BIT(6) },
156*cdb8b80bSIcenowy Zheng };
157*cdb8b80bSIcenowy Zheng 
158*cdb8b80bSIcenowy Zheng static struct ccu_reset_map sun50i_a64_r_ccu_resets[] = {
159*cdb8b80bSIcenowy Zheng 	[RST_APB0_IR]		=  { 0xb0, BIT(1) },
160*cdb8b80bSIcenowy Zheng 	[RST_APB0_TIMER]	=  { 0xb0, BIT(2) },
161*cdb8b80bSIcenowy Zheng 	[RST_APB0_RSB]		=  { 0xb0, BIT(3) },
162*cdb8b80bSIcenowy Zheng 	[RST_APB0_UART]		=  { 0xb0, BIT(4) },
163*cdb8b80bSIcenowy Zheng 	[RST_APB0_I2C]		=  { 0xb0, BIT(6) },
164*cdb8b80bSIcenowy Zheng };
165*cdb8b80bSIcenowy Zheng 
166*cdb8b80bSIcenowy Zheng static const struct sunxi_ccu_desc sun8i_h3_r_ccu_desc = {
167*cdb8b80bSIcenowy Zheng 	.ccu_clks	= sun8i_h3_r_ccu_clks,
168*cdb8b80bSIcenowy Zheng 	.num_ccu_clks	= ARRAY_SIZE(sun8i_h3_r_ccu_clks),
169*cdb8b80bSIcenowy Zheng 
170*cdb8b80bSIcenowy Zheng 	.hw_clks	= &sun8i_h3_r_hw_clks,
171*cdb8b80bSIcenowy Zheng 
172*cdb8b80bSIcenowy Zheng 	.resets		= sun8i_h3_r_ccu_resets,
173*cdb8b80bSIcenowy Zheng 	.num_resets	= ARRAY_SIZE(sun8i_h3_r_ccu_resets),
174*cdb8b80bSIcenowy Zheng };
175*cdb8b80bSIcenowy Zheng 
176*cdb8b80bSIcenowy Zheng static const struct sunxi_ccu_desc sun50i_a64_r_ccu_desc = {
177*cdb8b80bSIcenowy Zheng 	.ccu_clks	= sun50i_a64_r_ccu_clks,
178*cdb8b80bSIcenowy Zheng 	.num_ccu_clks	= ARRAY_SIZE(sun50i_a64_r_ccu_clks),
179*cdb8b80bSIcenowy Zheng 
180*cdb8b80bSIcenowy Zheng 	.hw_clks	= &sun50i_a64_r_hw_clks,
181*cdb8b80bSIcenowy Zheng 
182*cdb8b80bSIcenowy Zheng 	.resets		= sun50i_a64_r_ccu_resets,
183*cdb8b80bSIcenowy Zheng 	.num_resets	= ARRAY_SIZE(sun50i_a64_r_ccu_resets),
184*cdb8b80bSIcenowy Zheng };
185*cdb8b80bSIcenowy Zheng 
186*cdb8b80bSIcenowy Zheng static void __init sunxi_r_ccu_init(struct device_node *node,
187*cdb8b80bSIcenowy Zheng 				    const struct sunxi_ccu_desc *desc)
188*cdb8b80bSIcenowy Zheng {
189*cdb8b80bSIcenowy Zheng 	void __iomem *reg;
190*cdb8b80bSIcenowy Zheng 
191*cdb8b80bSIcenowy Zheng 	reg = of_io_request_and_map(node, 0, of_node_full_name(node));
192*cdb8b80bSIcenowy Zheng 	if (IS_ERR(reg)) {
193*cdb8b80bSIcenowy Zheng 		pr_err("%s: Could not map the clock registers\n",
194*cdb8b80bSIcenowy Zheng 		       of_node_full_name(node));
195*cdb8b80bSIcenowy Zheng 		return;
196*cdb8b80bSIcenowy Zheng 	}
197*cdb8b80bSIcenowy Zheng 
198*cdb8b80bSIcenowy Zheng 	sunxi_ccu_probe(node, reg, desc);
199*cdb8b80bSIcenowy Zheng }
200*cdb8b80bSIcenowy Zheng 
201*cdb8b80bSIcenowy Zheng static void __init sun8i_h3_r_ccu_setup(struct device_node *node)
202*cdb8b80bSIcenowy Zheng {
203*cdb8b80bSIcenowy Zheng 	sunxi_r_ccu_init(node, &sun8i_h3_r_ccu_desc);
204*cdb8b80bSIcenowy Zheng }
205*cdb8b80bSIcenowy Zheng CLK_OF_DECLARE(sun8i_h3_r_ccu, "allwinner,sun8i-h3-r-ccu",
206*cdb8b80bSIcenowy Zheng 	       sun8i_h3_r_ccu_setup);
207*cdb8b80bSIcenowy Zheng 
208*cdb8b80bSIcenowy Zheng static void __init sun50i_a64_r_ccu_setup(struct device_node *node)
209*cdb8b80bSIcenowy Zheng {
210*cdb8b80bSIcenowy Zheng 	sunxi_r_ccu_init(node, &sun50i_a64_r_ccu_desc);
211*cdb8b80bSIcenowy Zheng }
212*cdb8b80bSIcenowy Zheng CLK_OF_DECLARE(sun50i_a64_r_ccu, "allwinner,sun50i-a64-r-ccu",
213*cdb8b80bSIcenowy Zheng 	       sun50i_a64_r_ccu_setup);
214