xref: /linux/arch/m68k/coldfire/m5441x.c (revision 007f84ede6e3ea893b1a68724e8796c45fa98d85)
1b2441318SGreg Kroah-Hartman // SPDX-License-Identifier: GPL-2.0
2f86b9e03SGreg Ungerer /*
3f86b9e03SGreg Ungerer  *	m5441x.c -- support for Coldfire m5441x processors
4f86b9e03SGreg Ungerer  *
5f86b9e03SGreg Ungerer  *	(C) Copyright Steven King <sfking@fdwdc.com>
6f86b9e03SGreg Ungerer  */
7f86b9e03SGreg Ungerer 
8*007f84edSArnd Bergmann #include <linux/clkdev.h>
9f86b9e03SGreg Ungerer #include <linux/kernel.h>
10f86b9e03SGreg Ungerer #include <linux/param.h>
11f86b9e03SGreg Ungerer #include <linux/init.h>
12f86b9e03SGreg Ungerer #include <linux/io.h>
13f86b9e03SGreg Ungerer #include <linux/clk.h>
14f86b9e03SGreg Ungerer #include <asm/machdep.h>
15f86b9e03SGreg Ungerer #include <asm/coldfire.h>
16f86b9e03SGreg Ungerer #include <asm/mcfsim.h>
17f86b9e03SGreg Ungerer #include <asm/mcfuart.h>
18f86b9e03SGreg Ungerer #include <asm/mcfdma.h>
19f86b9e03SGreg Ungerer #include <asm/mcfclk.h>
20f86b9e03SGreg Ungerer 
21f86b9e03SGreg Ungerer DEFINE_CLK(0, "flexbus", 2, MCF_CLK);
22f86b9e03SGreg Ungerer DEFINE_CLK(0, "mcfcan.0", 8, MCF_CLK);
23f86b9e03SGreg Ungerer DEFINE_CLK(0, "mcfcan.1", 9, MCF_CLK);
242d24b532SSteven King DEFINE_CLK(0, "imx1-i2c.1", 14, MCF_CLK);
25f86b9e03SGreg Ungerer DEFINE_CLK(0, "mcfdspi.1", 15, MCF_CLK);
26f86b9e03SGreg Ungerer DEFINE_CLK(0, "edma", 17, MCF_CLK);
27f86b9e03SGreg Ungerer DEFINE_CLK(0, "intc.0", 18, MCF_CLK);
28f86b9e03SGreg Ungerer DEFINE_CLK(0, "intc.1", 19, MCF_CLK);
29f86b9e03SGreg Ungerer DEFINE_CLK(0, "intc.2", 20, MCF_CLK);
302d24b532SSteven King DEFINE_CLK(0, "imx1-i2c.0", 22, MCF_CLK);
3108fe92e2SAngelo Dureghello DEFINE_CLK(0, "fsl-dspi.0", 23, MCF_CLK);
32f86b9e03SGreg Ungerer DEFINE_CLK(0, "mcfuart.0", 24, MCF_BUSCLK);
33f86b9e03SGreg Ungerer DEFINE_CLK(0, "mcfuart.1", 25, MCF_BUSCLK);
34f86b9e03SGreg Ungerer DEFINE_CLK(0, "mcfuart.2", 26, MCF_BUSCLK);
35f86b9e03SGreg Ungerer DEFINE_CLK(0, "mcfuart.3", 27, MCF_BUSCLK);
36f86b9e03SGreg Ungerer DEFINE_CLK(0, "mcftmr.0", 28, MCF_CLK);
37f86b9e03SGreg Ungerer DEFINE_CLK(0, "mcftmr.1", 29, MCF_CLK);
38f86b9e03SGreg Ungerer DEFINE_CLK(0, "mcftmr.2", 30, MCF_CLK);
39f86b9e03SGreg Ungerer DEFINE_CLK(0, "mcftmr.3", 31, MCF_CLK);
40f86b9e03SGreg Ungerer DEFINE_CLK(0, "mcfpit.0", 32, MCF_CLK);
41f86b9e03SGreg Ungerer DEFINE_CLK(0, "mcfpit.1", 33, MCF_CLK);
42f86b9e03SGreg Ungerer DEFINE_CLK(0, "mcfpit.2", 34, MCF_CLK);
43f86b9e03SGreg Ungerer DEFINE_CLK(0, "mcfpit.3", 35, MCF_CLK);
44f86b9e03SGreg Ungerer DEFINE_CLK(0, "mcfeport.0", 37, MCF_CLK);
45f86b9e03SGreg Ungerer DEFINE_CLK(0, "mcfadc.0", 38, MCF_CLK);
46f86b9e03SGreg Ungerer DEFINE_CLK(0, "mcfdac.0", 39, MCF_CLK);
47f86b9e03SGreg Ungerer DEFINE_CLK(0, "mcfrtc.0", 42, MCF_CLK);
48f86b9e03SGreg Ungerer DEFINE_CLK(0, "mcfsim.0", 43, MCF_CLK);
49f86b9e03SGreg Ungerer DEFINE_CLK(0, "mcfusb-otg.0", 44, MCF_CLK);
50f86b9e03SGreg Ungerer DEFINE_CLK(0, "mcfusb-host.0", 45, MCF_CLK);
51f86b9e03SGreg Ungerer DEFINE_CLK(0, "mcfddr-sram.0", 46, MCF_CLK);
52f86b9e03SGreg Ungerer DEFINE_CLK(0, "mcfssi.0", 47, MCF_CLK);
53f86b9e03SGreg Ungerer DEFINE_CLK(0, "pll.0", 48, MCF_CLK);
54f86b9e03SGreg Ungerer DEFINE_CLK(0, "mcfrng.0", 49, MCF_CLK);
55f86b9e03SGreg Ungerer DEFINE_CLK(0, "mcfssi.1", 50, MCF_CLK);
56991f5c4dSAngelo Dureghello DEFINE_CLK(0, "sdhci-esdhc-mcf.0", 51, MCF_CLK);
57f86b9e03SGreg Ungerer DEFINE_CLK(0, "enet-fec.0", 53, MCF_CLK);
58f86b9e03SGreg Ungerer DEFINE_CLK(0, "enet-fec.1", 54, MCF_CLK);
59f86b9e03SGreg Ungerer DEFINE_CLK(0, "switch.0", 55, MCF_CLK);
60f86b9e03SGreg Ungerer DEFINE_CLK(0, "switch.1", 56, MCF_CLK);
61f86b9e03SGreg Ungerer DEFINE_CLK(0, "nand.0", 63, MCF_CLK);
62f86b9e03SGreg Ungerer 
63f86b9e03SGreg Ungerer DEFINE_CLK(1, "mcfow.0", 2, MCF_CLK);
642d24b532SSteven King DEFINE_CLK(1, "imx1-i2c.2", 4, MCF_CLK);
652d24b532SSteven King DEFINE_CLK(1, "imx1-i2c.3", 5, MCF_CLK);
662d24b532SSteven King DEFINE_CLK(1, "imx1-i2c.4", 6, MCF_CLK);
672d24b532SSteven King DEFINE_CLK(1, "imx1-i2c.5", 7, MCF_CLK);
68f86b9e03SGreg Ungerer DEFINE_CLK(1, "mcfuart.4", 24, MCF_BUSCLK);
69f86b9e03SGreg Ungerer DEFINE_CLK(1, "mcfuart.5", 25, MCF_BUSCLK);
70f86b9e03SGreg Ungerer DEFINE_CLK(1, "mcfuart.6", 26, MCF_BUSCLK);
71f86b9e03SGreg Ungerer DEFINE_CLK(1, "mcfuart.7", 27, MCF_BUSCLK);
72f86b9e03SGreg Ungerer DEFINE_CLK(1, "mcfuart.8", 28, MCF_BUSCLK);
73f86b9e03SGreg Ungerer DEFINE_CLK(1, "mcfuart.9", 29, MCF_BUSCLK);
74f86b9e03SGreg Ungerer DEFINE_CLK(1, "mcfpwm.0", 34, MCF_BUSCLK);
75f86b9e03SGreg Ungerer DEFINE_CLK(1, "sys.0", 36, MCF_BUSCLK);
76f86b9e03SGreg Ungerer DEFINE_CLK(1, "gpio.0", 37, MCF_BUSCLK);
77f86b9e03SGreg Ungerer 
78991f5c4dSAngelo Dureghello DEFINE_CLK(2, "ipg.0", 0, MCF_CLK);
79991f5c4dSAngelo Dureghello DEFINE_CLK(2, "ahb.0", 1, MCF_CLK);
80991f5c4dSAngelo Dureghello DEFINE_CLK(2, "per.0", 2, MCF_CLK);
81991f5c4dSAngelo Dureghello 
82*007f84edSArnd Bergmann static struct clk_lookup m5411x_clk_lookup[] = {
83*007f84edSArnd Bergmann 	CLKDEV_INIT("flexbus", NULL, &__clk_0_2),
84*007f84edSArnd Bergmann 	CLKDEV_INIT("mcfcan.0", NULL, &__clk_0_8),
85*007f84edSArnd Bergmann 	CLKDEV_INIT("mcfcan.1", NULL, &__clk_0_9),
86*007f84edSArnd Bergmann 	CLKDEV_INIT("imx1-i2c.1", NULL, &__clk_0_14),
87*007f84edSArnd Bergmann 	CLKDEV_INIT("mcfdspi.1", NULL, &__clk_0_15),
88*007f84edSArnd Bergmann 	CLKDEV_INIT("edma", NULL, &__clk_0_17),
89*007f84edSArnd Bergmann 	CLKDEV_INIT("intc.0", NULL, &__clk_0_18),
90*007f84edSArnd Bergmann 	CLKDEV_INIT("intc.1", NULL, &__clk_0_19),
91*007f84edSArnd Bergmann 	CLKDEV_INIT("intc.2", NULL, &__clk_0_20),
92*007f84edSArnd Bergmann 	CLKDEV_INIT("imx1-i2c.0", NULL, &__clk_0_22),
93*007f84edSArnd Bergmann 	CLKDEV_INIT("fsl-dspi.0", NULL, &__clk_0_23),
94*007f84edSArnd Bergmann 	CLKDEV_INIT("mcfuart.0", NULL, &__clk_0_24),
95*007f84edSArnd Bergmann 	CLKDEV_INIT("mcfuart.1", NULL, &__clk_0_25),
96*007f84edSArnd Bergmann 	CLKDEV_INIT("mcfuart.2", NULL, &__clk_0_26),
97*007f84edSArnd Bergmann 	CLKDEV_INIT("mcfuart.3", NULL, &__clk_0_27),
98*007f84edSArnd Bergmann 	CLKDEV_INIT("mcftmr.0", NULL, &__clk_0_28),
99*007f84edSArnd Bergmann 	CLKDEV_INIT("mcftmr.1", NULL, &__clk_0_29),
100*007f84edSArnd Bergmann 	CLKDEV_INIT("mcftmr.2", NULL, &__clk_0_30),
101*007f84edSArnd Bergmann 	CLKDEV_INIT("mcftmr.3", NULL, &__clk_0_31),
102*007f84edSArnd Bergmann 	CLKDEV_INIT("mcfpit.0", NULL, &__clk_0_32),
103*007f84edSArnd Bergmann 	CLKDEV_INIT("mcfpit.1", NULL, &__clk_0_33),
104*007f84edSArnd Bergmann 	CLKDEV_INIT("mcfpit.2", NULL, &__clk_0_34),
105*007f84edSArnd Bergmann 	CLKDEV_INIT("mcfpit.3", NULL, &__clk_0_35),
106*007f84edSArnd Bergmann 	CLKDEV_INIT("mcfeport.0", NULL, &__clk_0_37),
107*007f84edSArnd Bergmann 	CLKDEV_INIT("mcfadc.0", NULL, &__clk_0_38),
108*007f84edSArnd Bergmann 	CLKDEV_INIT("mcfdac.0", NULL, &__clk_0_39),
109*007f84edSArnd Bergmann 	CLKDEV_INIT("mcfrtc.0", NULL, &__clk_0_42),
110*007f84edSArnd Bergmann 	CLKDEV_INIT("mcfsim.0", NULL, &__clk_0_43),
111*007f84edSArnd Bergmann 	CLKDEV_INIT("mcfusb-otg.0", NULL, &__clk_0_44),
112*007f84edSArnd Bergmann 	CLKDEV_INIT("mcfusb-host.0", NULL, &__clk_0_45),
113*007f84edSArnd Bergmann 	CLKDEV_INIT("mcfddr-sram.0", NULL, &__clk_0_46),
114*007f84edSArnd Bergmann 	CLKDEV_INIT("mcfssi.0", NULL, &__clk_0_47),
115*007f84edSArnd Bergmann 	CLKDEV_INIT(NULL, "pll.0", &__clk_0_48),
116*007f84edSArnd Bergmann 	CLKDEV_INIT("mcfrng.0", NULL, &__clk_0_49),
117*007f84edSArnd Bergmann 	CLKDEV_INIT("mcfssi.1", NULL, &__clk_0_50),
118*007f84edSArnd Bergmann 	CLKDEV_INIT("sdhci-esdhc-mcf.0", NULL, &__clk_0_51),
119*007f84edSArnd Bergmann 	CLKDEV_INIT("enet-fec.0", NULL, &__clk_0_53),
120*007f84edSArnd Bergmann 	CLKDEV_INIT("enet-fec.1", NULL, &__clk_0_54),
121*007f84edSArnd Bergmann 	CLKDEV_INIT("switch.0", NULL, &__clk_0_55),
122*007f84edSArnd Bergmann 	CLKDEV_INIT("switch.1", NULL, &__clk_0_56),
123*007f84edSArnd Bergmann 	CLKDEV_INIT("nand.0", NULL, &__clk_0_63),
124*007f84edSArnd Bergmann 	CLKDEV_INIT("mcfow.0", NULL, &__clk_1_2),
125*007f84edSArnd Bergmann 	CLKDEV_INIT("imx1-i2c.2", NULL, &__clk_1_4),
126*007f84edSArnd Bergmann 	CLKDEV_INIT("imx1-i2c.3", NULL, &__clk_1_5),
127*007f84edSArnd Bergmann 	CLKDEV_INIT("imx1-i2c.4", NULL, &__clk_1_6),
128*007f84edSArnd Bergmann 	CLKDEV_INIT("imx1-i2c.5", NULL, &__clk_1_7),
129*007f84edSArnd Bergmann 	CLKDEV_INIT("mcfuart.4", NULL, &__clk_1_24),
130*007f84edSArnd Bergmann 	CLKDEV_INIT("mcfuart.5", NULL, &__clk_1_25),
131*007f84edSArnd Bergmann 	CLKDEV_INIT("mcfuart.6", NULL, &__clk_1_26),
132*007f84edSArnd Bergmann 	CLKDEV_INIT("mcfuart.7", NULL, &__clk_1_27),
133*007f84edSArnd Bergmann 	CLKDEV_INIT("mcfuart.8", NULL, &__clk_1_28),
134*007f84edSArnd Bergmann 	CLKDEV_INIT("mcfuart.9", NULL, &__clk_1_29),
135*007f84edSArnd Bergmann 	CLKDEV_INIT("mcfpwm.0", NULL, &__clk_1_34),
136*007f84edSArnd Bergmann 	CLKDEV_INIT(NULL, "sys.0", &__clk_1_36),
137*007f84edSArnd Bergmann 	CLKDEV_INIT("gpio.0", NULL, &__clk_1_37),
138*007f84edSArnd Bergmann 	CLKDEV_INIT("ipg.0", NULL, &__clk_2_0),
139*007f84edSArnd Bergmann 	CLKDEV_INIT("ahb.0", NULL, &__clk_2_1),
140*007f84edSArnd Bergmann 	CLKDEV_INIT("per.0", NULL, &__clk_2_2),
141f86b9e03SGreg Ungerer };
142f86b9e03SGreg Ungerer 
143f86b9e03SGreg Ungerer static struct clk * const enable_clks[] __initconst = {
144f86b9e03SGreg Ungerer 	/* make sure these clocks are enabled */
145d7e9d01aSAngelo Dureghello 	&__clk_0_15, /* dspi.1 */
146d7e9d01aSAngelo Dureghello 	&__clk_0_17, /* eDMA */
147f86b9e03SGreg Ungerer 	&__clk_0_18, /* intc0 */
148f86b9e03SGreg Ungerer 	&__clk_0_19, /* intc0 */
149f86b9e03SGreg Ungerer 	&__clk_0_20, /* intc0 */
15008fe92e2SAngelo Dureghello 	&__clk_0_23, /* dspi.0 */
151f86b9e03SGreg Ungerer 	&__clk_0_24, /* uart0 */
152f86b9e03SGreg Ungerer 	&__clk_0_25, /* uart1 */
153f86b9e03SGreg Ungerer 	&__clk_0_26, /* uart2 */
154f86b9e03SGreg Ungerer 	&__clk_0_27, /* uart3 */
155f86b9e03SGreg Ungerer 
156f86b9e03SGreg Ungerer 	&__clk_0_33, /* pit.1 */
157f86b9e03SGreg Ungerer 	&__clk_0_37, /* eport */
158f86b9e03SGreg Ungerer 	&__clk_0_48, /* pll */
159991f5c4dSAngelo Dureghello 	&__clk_0_51, /* esdhc */
160f86b9e03SGreg Ungerer 
161f86b9e03SGreg Ungerer 	&__clk_1_36, /* CCM/reset module/Power management */
162f86b9e03SGreg Ungerer 	&__clk_1_37, /* gpio */
163f86b9e03SGreg Ungerer };
164f86b9e03SGreg Ungerer static struct clk * const disable_clks[] __initconst = {
165f86b9e03SGreg Ungerer 	&__clk_0_8, /* can.0 */
166f86b9e03SGreg Ungerer 	&__clk_0_9, /* can.1 */
167f86b9e03SGreg Ungerer 	&__clk_0_14, /* i2c.1 */
168f86b9e03SGreg Ungerer 	&__clk_0_22, /* i2c.0 */
169f86b9e03SGreg Ungerer 	&__clk_0_23, /* dspi.0 */
170f86b9e03SGreg Ungerer 	&__clk_0_28, /* tmr.1 */
171f86b9e03SGreg Ungerer 	&__clk_0_29, /* tmr.2 */
172f86b9e03SGreg Ungerer 	&__clk_0_30, /* tmr.2 */
173f86b9e03SGreg Ungerer 	&__clk_0_31, /* tmr.3 */
174f86b9e03SGreg Ungerer 	&__clk_0_32, /* pit.0 */
175f86b9e03SGreg Ungerer 	&__clk_0_34, /* pit.2 */
176f86b9e03SGreg Ungerer 	&__clk_0_35, /* pit.3 */
177f86b9e03SGreg Ungerer 	&__clk_0_38, /* adc */
178f86b9e03SGreg Ungerer 	&__clk_0_39, /* dac */
179f86b9e03SGreg Ungerer 	&__clk_0_44, /* usb otg */
180f86b9e03SGreg Ungerer 	&__clk_0_45, /* usb host */
181f86b9e03SGreg Ungerer 	&__clk_0_47, /* ssi.0 */
182f86b9e03SGreg Ungerer 	&__clk_0_49, /* rng */
183f86b9e03SGreg Ungerer 	&__clk_0_50, /* ssi.1 */
184f86b9e03SGreg Ungerer 	&__clk_0_51, /* eSDHC */
185f86b9e03SGreg Ungerer 	&__clk_0_53, /* enet-fec */
186f86b9e03SGreg Ungerer 	&__clk_0_54, /* enet-fec */
187f86b9e03SGreg Ungerer 	&__clk_0_55, /* switch.0 */
188f86b9e03SGreg Ungerer 	&__clk_0_56, /* switch.1 */
189f86b9e03SGreg Ungerer 
190f86b9e03SGreg Ungerer 	&__clk_1_2, /* 1-wire */
191f86b9e03SGreg Ungerer 	&__clk_1_4, /* i2c.2 */
192f86b9e03SGreg Ungerer 	&__clk_1_5, /* i2c.3 */
193f86b9e03SGreg Ungerer 	&__clk_1_6, /* i2c.4 */
194f86b9e03SGreg Ungerer 	&__clk_1_7, /* i2c.5 */
195f86b9e03SGreg Ungerer 	&__clk_1_24, /* uart 4 */
196f86b9e03SGreg Ungerer 	&__clk_1_25, /* uart 5 */
197f86b9e03SGreg Ungerer 	&__clk_1_26, /* uart 6 */
198f86b9e03SGreg Ungerer 	&__clk_1_27, /* uart 7 */
199f86b9e03SGreg Ungerer 	&__clk_1_28, /* uart 8 */
200f86b9e03SGreg Ungerer 	&__clk_1_29, /* uart 9 */
201f86b9e03SGreg Ungerer };
202f86b9e03SGreg Ungerer 
20391132078SAngelo Dureghello static void __clk_enable2(struct clk *clk)
20491132078SAngelo Dureghello {
20591132078SAngelo Dureghello 	__raw_writel(__raw_readl(MCFSDHC_CLK) | (1 << clk->slot), MCFSDHC_CLK);
20691132078SAngelo Dureghello }
20791132078SAngelo Dureghello 
20891132078SAngelo Dureghello static void __clk_disable2(struct clk *clk)
20991132078SAngelo Dureghello {
21091132078SAngelo Dureghello 	__raw_writel(__raw_readl(MCFSDHC_CLK) & ~(1 << clk->slot), MCFSDHC_CLK);
21191132078SAngelo Dureghello }
21291132078SAngelo Dureghello 
21391132078SAngelo Dureghello struct clk_ops clk_ops2 = {
21491132078SAngelo Dureghello 	.enable		= __clk_enable2,
21591132078SAngelo Dureghello 	.disable	= __clk_disable2,
21691132078SAngelo Dureghello };
21791132078SAngelo Dureghello 
218f86b9e03SGreg Ungerer static void __init m5441x_clk_init(void)
219f86b9e03SGreg Ungerer {
220f86b9e03SGreg Ungerer 	unsigned i;
221f86b9e03SGreg Ungerer 
222f86b9e03SGreg Ungerer 	for (i = 0; i < ARRAY_SIZE(enable_clks); ++i)
223f86b9e03SGreg Ungerer 		__clk_init_enabled(enable_clks[i]);
224f86b9e03SGreg Ungerer 	/* make sure these clocks are disabled */
225f86b9e03SGreg Ungerer 	for (i = 0; i < ARRAY_SIZE(disable_clks); ++i)
226f86b9e03SGreg Ungerer 		__clk_init_disabled(disable_clks[i]);
227*007f84edSArnd Bergmann 
228*007f84edSArnd Bergmann 	clkdev_add_table(m5411x_clk_lookup, ARRAY_SIZE(m5411x_clk_lookup));
229f86b9e03SGreg Ungerer }
230f86b9e03SGreg Ungerer 
231f86b9e03SGreg Ungerer static void __init m5441x_uarts_init(void)
232f86b9e03SGreg Ungerer {
233f86b9e03SGreg Ungerer 	__raw_writeb(0x0f, MCFGPIO_PAR_UART0);
234f86b9e03SGreg Ungerer 	__raw_writeb(0x00, MCFGPIO_PAR_UART1);
235f86b9e03SGreg Ungerer 	__raw_writeb(0x00, MCFGPIO_PAR_UART2);
236f86b9e03SGreg Ungerer }
237f86b9e03SGreg Ungerer 
238f86b9e03SGreg Ungerer static void __init m5441x_fec_init(void)
239f86b9e03SGreg Ungerer {
240f86b9e03SGreg Ungerer 	__raw_writeb(0x03, MCFGPIO_PAR_FEC);
241f86b9e03SGreg Ungerer }
242f86b9e03SGreg Ungerer 
243f86b9e03SGreg Ungerer void __init config_BSP(char *commandp, int size)
244f86b9e03SGreg Ungerer {
245f86b9e03SGreg Ungerer 	m5441x_clk_init();
246f86b9e03SGreg Ungerer 	mach_sched_init = hw_timer_init;
247f86b9e03SGreg Ungerer 	m5441x_uarts_init();
248f86b9e03SGreg Ungerer 	m5441x_fec_init();
249f86b9e03SGreg Ungerer }
250