1b2441318SGreg Kroah-Hartman // SPDX-License-Identifier: GPL-2.0
2f86b9e03SGreg Ungerer /***************************************************************************/
3f86b9e03SGreg Ungerer
4f86b9e03SGreg Ungerer /*
5ece9ae65SGreg Ungerer * m520x.c -- platform support for ColdFire 520x based boards
6f86b9e03SGreg Ungerer *
7f86b9e03SGreg Ungerer * Copyright (C) 2005, Freescale (www.freescale.com)
8f86b9e03SGreg Ungerer * Copyright (C) 2005, Intec Automation (mike@steroidmicros.com)
9f86b9e03SGreg Ungerer * Copyright (C) 1999-2007, Greg Ungerer (gerg@snapgear.com)
10f86b9e03SGreg Ungerer * Copyright (C) 2001-2003, SnapGear Inc. (www.snapgear.com)
11f86b9e03SGreg Ungerer */
12f86b9e03SGreg Ungerer
13f86b9e03SGreg Ungerer /***************************************************************************/
14f86b9e03SGreg Ungerer
15*007f84edSArnd Bergmann #include <linux/clkdev.h>
16f86b9e03SGreg Ungerer #include <linux/kernel.h>
17f86b9e03SGreg Ungerer #include <linux/param.h>
18f86b9e03SGreg Ungerer #include <linux/init.h>
19f86b9e03SGreg Ungerer #include <linux/io.h>
20f86b9e03SGreg Ungerer #include <asm/machdep.h>
21f86b9e03SGreg Ungerer #include <asm/coldfire.h>
22f86b9e03SGreg Ungerer #include <asm/mcfsim.h>
23f86b9e03SGreg Ungerer #include <asm/mcfuart.h>
24f86b9e03SGreg Ungerer #include <asm/mcfclk.h>
25f86b9e03SGreg Ungerer
26f86b9e03SGreg Ungerer /***************************************************************************/
27f86b9e03SGreg Ungerer
28f86b9e03SGreg Ungerer DEFINE_CLK(0, "flexbus", 2, MCF_CLK);
29f86b9e03SGreg Ungerer DEFINE_CLK(0, "fec.0", 12, MCF_CLK);
30f86b9e03SGreg Ungerer DEFINE_CLK(0, "edma", 17, MCF_CLK);
31f86b9e03SGreg Ungerer DEFINE_CLK(0, "intc.0", 18, MCF_CLK);
32f86b9e03SGreg Ungerer DEFINE_CLK(0, "iack.0", 21, MCF_CLK);
332d24b532SSteven King DEFINE_CLK(0, "imx1-i2c.0", 22, MCF_CLK);
34f86b9e03SGreg Ungerer DEFINE_CLK(0, "mcfqspi.0", 23, MCF_CLK);
35f86b9e03SGreg Ungerer DEFINE_CLK(0, "mcfuart.0", 24, MCF_BUSCLK);
36f86b9e03SGreg Ungerer DEFINE_CLK(0, "mcfuart.1", 25, MCF_BUSCLK);
37f86b9e03SGreg Ungerer DEFINE_CLK(0, "mcfuart.2", 26, MCF_BUSCLK);
38f86b9e03SGreg Ungerer DEFINE_CLK(0, "mcftmr.0", 28, MCF_CLK);
39f86b9e03SGreg Ungerer DEFINE_CLK(0, "mcftmr.1", 29, MCF_CLK);
40f86b9e03SGreg Ungerer DEFINE_CLK(0, "mcftmr.2", 30, MCF_CLK);
41f86b9e03SGreg Ungerer DEFINE_CLK(0, "mcftmr.3", 31, MCF_CLK);
42f86b9e03SGreg Ungerer
43f86b9e03SGreg Ungerer DEFINE_CLK(0, "mcfpit.0", 32, MCF_CLK);
44f86b9e03SGreg Ungerer DEFINE_CLK(0, "mcfpit.1", 33, MCF_CLK);
45f86b9e03SGreg Ungerer DEFINE_CLK(0, "mcfeport.0", 34, MCF_CLK);
46f86b9e03SGreg Ungerer DEFINE_CLK(0, "mcfwdt.0", 35, MCF_CLK);
47f86b9e03SGreg Ungerer DEFINE_CLK(0, "pll.0", 36, MCF_CLK);
48f86b9e03SGreg Ungerer DEFINE_CLK(0, "sys.0", 40, MCF_BUSCLK);
49f86b9e03SGreg Ungerer DEFINE_CLK(0, "gpio.0", 41, MCF_BUSCLK);
50f86b9e03SGreg Ungerer DEFINE_CLK(0, "sdram.0", 42, MCF_CLK);
51f86b9e03SGreg Ungerer
52*007f84edSArnd Bergmann static struct clk_lookup m520x_clk_lookup[] = {
53*007f84edSArnd Bergmann CLKDEV_INIT(NULL, "flexbus", &__clk_0_2),
54*007f84edSArnd Bergmann CLKDEV_INIT("fec.0", NULL, &__clk_0_12),
55*007f84edSArnd Bergmann CLKDEV_INIT("edma", NULL, &__clk_0_17),
56*007f84edSArnd Bergmann CLKDEV_INIT("intc.0", NULL, &__clk_0_18),
57*007f84edSArnd Bergmann CLKDEV_INIT("iack.0", NULL, &__clk_0_21),
58*007f84edSArnd Bergmann CLKDEV_INIT("imx1-i2c.0", NULL, &__clk_0_22),
59*007f84edSArnd Bergmann CLKDEV_INIT("mcfqspi.0", NULL, &__clk_0_23),
60*007f84edSArnd Bergmann CLKDEV_INIT("mcfuart.0", NULL, &__clk_0_24),
61*007f84edSArnd Bergmann CLKDEV_INIT("mcfuart.1", NULL, &__clk_0_25),
62*007f84edSArnd Bergmann CLKDEV_INIT("mcfuart.2", NULL, &__clk_0_26),
63*007f84edSArnd Bergmann CLKDEV_INIT("mcftmr.0", NULL, &__clk_0_28),
64*007f84edSArnd Bergmann CLKDEV_INIT("mcftmr.1", NULL, &__clk_0_29),
65*007f84edSArnd Bergmann CLKDEV_INIT("mcftmr.2", NULL, &__clk_0_30),
66*007f84edSArnd Bergmann CLKDEV_INIT("mcftmr.3", NULL, &__clk_0_31),
67*007f84edSArnd Bergmann CLKDEV_INIT("mcfpit.0", NULL, &__clk_0_32),
68*007f84edSArnd Bergmann CLKDEV_INIT("mcfpit.1", NULL, &__clk_0_33),
69*007f84edSArnd Bergmann CLKDEV_INIT("mcfeport.0", NULL, &__clk_0_34),
70*007f84edSArnd Bergmann CLKDEV_INIT("mcfwdt.0", NULL, &__clk_0_35),
71*007f84edSArnd Bergmann CLKDEV_INIT(NULL, "pll.0", &__clk_0_36),
72*007f84edSArnd Bergmann CLKDEV_INIT(NULL, "sys.0", &__clk_0_40),
73*007f84edSArnd Bergmann CLKDEV_INIT("gpio.0", NULL, &__clk_0_41),
74*007f84edSArnd Bergmann CLKDEV_INIT("sdram.0", NULL, &__clk_0_42),
75f86b9e03SGreg Ungerer };
76f86b9e03SGreg Ungerer
77f86b9e03SGreg Ungerer static struct clk * const enable_clks[] __initconst = {
78f86b9e03SGreg Ungerer &__clk_0_2, /* flexbus */
79f86b9e03SGreg Ungerer &__clk_0_18, /* intc.0 */
80f86b9e03SGreg Ungerer &__clk_0_21, /* iack.0 */
81f86b9e03SGreg Ungerer &__clk_0_24, /* mcfuart.0 */
82f86b9e03SGreg Ungerer &__clk_0_25, /* mcfuart.1 */
83f86b9e03SGreg Ungerer &__clk_0_26, /* mcfuart.2 */
84f86b9e03SGreg Ungerer
85f86b9e03SGreg Ungerer &__clk_0_32, /* mcfpit.0 */
86f86b9e03SGreg Ungerer &__clk_0_33, /* mcfpit.1 */
87f86b9e03SGreg Ungerer &__clk_0_34, /* mcfeport.0 */
88f86b9e03SGreg Ungerer &__clk_0_36, /* pll.0 */
89f86b9e03SGreg Ungerer &__clk_0_40, /* sys.0 */
90f86b9e03SGreg Ungerer &__clk_0_41, /* gpio.0 */
91f86b9e03SGreg Ungerer &__clk_0_42, /* sdram.0 */
92f86b9e03SGreg Ungerer };
93f86b9e03SGreg Ungerer
94f86b9e03SGreg Ungerer static struct clk * const disable_clks[] __initconst = {
95f86b9e03SGreg Ungerer &__clk_0_12, /* fec.0 */
96f86b9e03SGreg Ungerer &__clk_0_17, /* edma */
972d24b532SSteven King &__clk_0_22, /* imx1-i2c.0 */
98f86b9e03SGreg Ungerer &__clk_0_23, /* mcfqspi.0 */
99f86b9e03SGreg Ungerer &__clk_0_28, /* mcftmr.0 */
100f86b9e03SGreg Ungerer &__clk_0_29, /* mcftmr.1 */
101f86b9e03SGreg Ungerer &__clk_0_30, /* mcftmr.2 */
102f86b9e03SGreg Ungerer &__clk_0_31, /* mcftmr.3 */
103f86b9e03SGreg Ungerer &__clk_0_35, /* mcfwdt.0 */
104f86b9e03SGreg Ungerer };
105f86b9e03SGreg Ungerer
106f86b9e03SGreg Ungerer
m520x_clk_init(void)107f86b9e03SGreg Ungerer static void __init m520x_clk_init(void)
108f86b9e03SGreg Ungerer {
109f86b9e03SGreg Ungerer unsigned i;
110f86b9e03SGreg Ungerer
111f86b9e03SGreg Ungerer /* make sure these clocks are enabled */
112f86b9e03SGreg Ungerer for (i = 0; i < ARRAY_SIZE(enable_clks); ++i)
113f86b9e03SGreg Ungerer __clk_init_enabled(enable_clks[i]);
114f86b9e03SGreg Ungerer /* make sure these clocks are disabled */
115f86b9e03SGreg Ungerer for (i = 0; i < ARRAY_SIZE(disable_clks); ++i)
116f86b9e03SGreg Ungerer __clk_init_disabled(disable_clks[i]);
117*007f84edSArnd Bergmann
118*007f84edSArnd Bergmann clkdev_add_table(m520x_clk_lookup, ARRAY_SIZE(m520x_clk_lookup));
119f86b9e03SGreg Ungerer }
120f86b9e03SGreg Ungerer
121f86b9e03SGreg Ungerer /***************************************************************************/
122f86b9e03SGreg Ungerer
m520x_qspi_init(void)123f86b9e03SGreg Ungerer static void __init m520x_qspi_init(void)
124f86b9e03SGreg Ungerer {
125f86b9e03SGreg Ungerer #if IS_ENABLED(CONFIG_SPI_COLDFIRE_QSPI)
126f86b9e03SGreg Ungerer u16 par;
127f86b9e03SGreg Ungerer /* setup Port QS for QSPI with gpio CS control */
128f86b9e03SGreg Ungerer writeb(0x3f, MCF_GPIO_PAR_QSPI);
129f86b9e03SGreg Ungerer /* make U1CTS and U2RTS gpio for cs_control */
130f86b9e03SGreg Ungerer par = readw(MCF_GPIO_PAR_UART);
131f86b9e03SGreg Ungerer par &= 0x00ff;
132f86b9e03SGreg Ungerer writew(par, MCF_GPIO_PAR_UART);
133f86b9e03SGreg Ungerer #endif /* IS_ENABLED(CONFIG_SPI_COLDFIRE_QSPI) */
134f86b9e03SGreg Ungerer }
135f86b9e03SGreg Ungerer
136f86b9e03SGreg Ungerer /***************************************************************************/
137f86b9e03SGreg Ungerer
m520x_i2c_init(void)1382d24b532SSteven King static void __init m520x_i2c_init(void)
1392d24b532SSteven King {
1402d24b532SSteven King #if IS_ENABLED(CONFIG_I2C_IMX)
1412d24b532SSteven King u8 par;
1422d24b532SSteven King
1432d24b532SSteven King /* setup Port FECI2C Pin Assignment Register for I2C */
1442d24b532SSteven King /* set PAR_SCL to SCL and PAR_SDA to SDA */
1452d24b532SSteven King par = readb(MCF_GPIO_PAR_FECI2C);
1462d24b532SSteven King par |= 0x0f;
1472d24b532SSteven King writeb(par, MCF_GPIO_PAR_FECI2C);
1482d24b532SSteven King #endif /* IS_ENABLED(CONFIG_I2C_IMX) */
1492d24b532SSteven King }
1502d24b532SSteven King
1512d24b532SSteven King /***************************************************************************/
1522d24b532SSteven King
m520x_uarts_init(void)153f86b9e03SGreg Ungerer static void __init m520x_uarts_init(void)
154f86b9e03SGreg Ungerer {
155f86b9e03SGreg Ungerer u16 par;
156f86b9e03SGreg Ungerer u8 par2;
157f86b9e03SGreg Ungerer
158f86b9e03SGreg Ungerer /* UART0 and UART1 GPIO pin setup */
159f86b9e03SGreg Ungerer par = readw(MCF_GPIO_PAR_UART);
160f86b9e03SGreg Ungerer par |= MCF_GPIO_PAR_UART_PAR_UTXD0 | MCF_GPIO_PAR_UART_PAR_URXD0;
161f86b9e03SGreg Ungerer par |= MCF_GPIO_PAR_UART_PAR_UTXD1 | MCF_GPIO_PAR_UART_PAR_URXD1;
162f86b9e03SGreg Ungerer writew(par, MCF_GPIO_PAR_UART);
163f86b9e03SGreg Ungerer
164f86b9e03SGreg Ungerer /* UART1 GPIO pin setup */
165f86b9e03SGreg Ungerer par2 = readb(MCF_GPIO_PAR_FECI2C);
166f86b9e03SGreg Ungerer par2 &= ~0x0F;
167f86b9e03SGreg Ungerer par2 |= MCF_GPIO_PAR_FECI2C_PAR_SCL_UTXD2 |
168f86b9e03SGreg Ungerer MCF_GPIO_PAR_FECI2C_PAR_SDA_URXD2;
169f86b9e03SGreg Ungerer writeb(par2, MCF_GPIO_PAR_FECI2C);
170f86b9e03SGreg Ungerer }
171f86b9e03SGreg Ungerer
172f86b9e03SGreg Ungerer /***************************************************************************/
173f86b9e03SGreg Ungerer
m520x_fec_init(void)174f86b9e03SGreg Ungerer static void __init m520x_fec_init(void)
175f86b9e03SGreg Ungerer {
176f86b9e03SGreg Ungerer u8 v;
177f86b9e03SGreg Ungerer
178f86b9e03SGreg Ungerer /* Set multi-function pins to ethernet mode */
179f86b9e03SGreg Ungerer v = readb(MCF_GPIO_PAR_FEC);
180f86b9e03SGreg Ungerer writeb(v | 0xf0, MCF_GPIO_PAR_FEC);
181f86b9e03SGreg Ungerer
182f86b9e03SGreg Ungerer v = readb(MCF_GPIO_PAR_FECI2C);
183f86b9e03SGreg Ungerer writeb(v | 0x0f, MCF_GPIO_PAR_FECI2C);
184f86b9e03SGreg Ungerer }
185f86b9e03SGreg Ungerer
186f86b9e03SGreg Ungerer /***************************************************************************/
187f86b9e03SGreg Ungerer
config_BSP(char * commandp,int size)188f86b9e03SGreg Ungerer void __init config_BSP(char *commandp, int size)
189f86b9e03SGreg Ungerer {
190f86b9e03SGreg Ungerer mach_sched_init = hw_timer_init;
191f86b9e03SGreg Ungerer m520x_clk_init();
192f86b9e03SGreg Ungerer m520x_uarts_init();
193f86b9e03SGreg Ungerer m520x_fec_init();
194f86b9e03SGreg Ungerer m520x_qspi_init();
1952d24b532SSteven King m520x_i2c_init();
196f86b9e03SGreg Ungerer }
197f86b9e03SGreg Ungerer
198f86b9e03SGreg Ungerer /***************************************************************************/
199