18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0 28c2ecf20Sopenharmony_ci/***************************************************************************/ 38c2ecf20Sopenharmony_ci 48c2ecf20Sopenharmony_ci/* 58c2ecf20Sopenharmony_ci * m520x.c -- platform support for ColdFire 520x based boards 68c2ecf20Sopenharmony_ci * 78c2ecf20Sopenharmony_ci * Copyright (C) 2005, Freescale (www.freescale.com) 88c2ecf20Sopenharmony_ci * Copyright (C) 2005, Intec Automation (mike@steroidmicros.com) 98c2ecf20Sopenharmony_ci * Copyright (C) 1999-2007, Greg Ungerer (gerg@snapgear.com) 108c2ecf20Sopenharmony_ci * Copyright (C) 2001-2003, SnapGear Inc. (www.snapgear.com) 118c2ecf20Sopenharmony_ci */ 128c2ecf20Sopenharmony_ci 138c2ecf20Sopenharmony_ci/***************************************************************************/ 148c2ecf20Sopenharmony_ci 158c2ecf20Sopenharmony_ci#include <linux/kernel.h> 168c2ecf20Sopenharmony_ci#include <linux/param.h> 178c2ecf20Sopenharmony_ci#include <linux/init.h> 188c2ecf20Sopenharmony_ci#include <linux/io.h> 198c2ecf20Sopenharmony_ci#include <asm/machdep.h> 208c2ecf20Sopenharmony_ci#include <asm/coldfire.h> 218c2ecf20Sopenharmony_ci#include <asm/mcfsim.h> 228c2ecf20Sopenharmony_ci#include <asm/mcfuart.h> 238c2ecf20Sopenharmony_ci#include <asm/mcfclk.h> 248c2ecf20Sopenharmony_ci 258c2ecf20Sopenharmony_ci/***************************************************************************/ 268c2ecf20Sopenharmony_ci 278c2ecf20Sopenharmony_ciDEFINE_CLK(0, "flexbus", 2, MCF_CLK); 288c2ecf20Sopenharmony_ciDEFINE_CLK(0, "fec.0", 12, MCF_CLK); 298c2ecf20Sopenharmony_ciDEFINE_CLK(0, "edma", 17, MCF_CLK); 308c2ecf20Sopenharmony_ciDEFINE_CLK(0, "intc.0", 18, MCF_CLK); 318c2ecf20Sopenharmony_ciDEFINE_CLK(0, "iack.0", 21, MCF_CLK); 328c2ecf20Sopenharmony_ciDEFINE_CLK(0, "imx1-i2c.0", 22, MCF_CLK); 338c2ecf20Sopenharmony_ciDEFINE_CLK(0, "mcfqspi.0", 23, MCF_CLK); 348c2ecf20Sopenharmony_ciDEFINE_CLK(0, "mcfuart.0", 24, MCF_BUSCLK); 358c2ecf20Sopenharmony_ciDEFINE_CLK(0, "mcfuart.1", 25, MCF_BUSCLK); 368c2ecf20Sopenharmony_ciDEFINE_CLK(0, "mcfuart.2", 26, MCF_BUSCLK); 378c2ecf20Sopenharmony_ciDEFINE_CLK(0, "mcftmr.0", 28, MCF_CLK); 388c2ecf20Sopenharmony_ciDEFINE_CLK(0, "mcftmr.1", 29, MCF_CLK); 398c2ecf20Sopenharmony_ciDEFINE_CLK(0, "mcftmr.2", 30, MCF_CLK); 408c2ecf20Sopenharmony_ciDEFINE_CLK(0, "mcftmr.3", 31, MCF_CLK); 418c2ecf20Sopenharmony_ci 428c2ecf20Sopenharmony_ciDEFINE_CLK(0, "mcfpit.0", 32, MCF_CLK); 438c2ecf20Sopenharmony_ciDEFINE_CLK(0, "mcfpit.1", 33, MCF_CLK); 448c2ecf20Sopenharmony_ciDEFINE_CLK(0, "mcfeport.0", 34, MCF_CLK); 458c2ecf20Sopenharmony_ciDEFINE_CLK(0, "mcfwdt.0", 35, MCF_CLK); 468c2ecf20Sopenharmony_ciDEFINE_CLK(0, "pll.0", 36, MCF_CLK); 478c2ecf20Sopenharmony_ciDEFINE_CLK(0, "sys.0", 40, MCF_BUSCLK); 488c2ecf20Sopenharmony_ciDEFINE_CLK(0, "gpio.0", 41, MCF_BUSCLK); 498c2ecf20Sopenharmony_ciDEFINE_CLK(0, "sdram.0", 42, MCF_CLK); 508c2ecf20Sopenharmony_ci 518c2ecf20Sopenharmony_cistruct clk *mcf_clks[] = { 528c2ecf20Sopenharmony_ci &__clk_0_2, /* flexbus */ 538c2ecf20Sopenharmony_ci &__clk_0_12, /* fec.0 */ 548c2ecf20Sopenharmony_ci &__clk_0_17, /* edma */ 558c2ecf20Sopenharmony_ci &__clk_0_18, /* intc.0 */ 568c2ecf20Sopenharmony_ci &__clk_0_21, /* iack.0 */ 578c2ecf20Sopenharmony_ci &__clk_0_22, /* imx1-i2c.0 */ 588c2ecf20Sopenharmony_ci &__clk_0_23, /* mcfqspi.0 */ 598c2ecf20Sopenharmony_ci &__clk_0_24, /* mcfuart.0 */ 608c2ecf20Sopenharmony_ci &__clk_0_25, /* mcfuart.1 */ 618c2ecf20Sopenharmony_ci &__clk_0_26, /* mcfuart.2 */ 628c2ecf20Sopenharmony_ci &__clk_0_28, /* mcftmr.0 */ 638c2ecf20Sopenharmony_ci &__clk_0_29, /* mcftmr.1 */ 648c2ecf20Sopenharmony_ci &__clk_0_30, /* mcftmr.2 */ 658c2ecf20Sopenharmony_ci &__clk_0_31, /* mcftmr.3 */ 668c2ecf20Sopenharmony_ci 678c2ecf20Sopenharmony_ci &__clk_0_32, /* mcfpit.0 */ 688c2ecf20Sopenharmony_ci &__clk_0_33, /* mcfpit.1 */ 698c2ecf20Sopenharmony_ci &__clk_0_34, /* mcfeport.0 */ 708c2ecf20Sopenharmony_ci &__clk_0_35, /* mcfwdt.0 */ 718c2ecf20Sopenharmony_ci &__clk_0_36, /* pll.0 */ 728c2ecf20Sopenharmony_ci &__clk_0_40, /* sys.0 */ 738c2ecf20Sopenharmony_ci &__clk_0_41, /* gpio.0 */ 748c2ecf20Sopenharmony_ci &__clk_0_42, /* sdram.0 */ 758c2ecf20Sopenharmony_ci NULL, 768c2ecf20Sopenharmony_ci}; 778c2ecf20Sopenharmony_ci 788c2ecf20Sopenharmony_cistatic struct clk * const enable_clks[] __initconst = { 798c2ecf20Sopenharmony_ci &__clk_0_2, /* flexbus */ 808c2ecf20Sopenharmony_ci &__clk_0_18, /* intc.0 */ 818c2ecf20Sopenharmony_ci &__clk_0_21, /* iack.0 */ 828c2ecf20Sopenharmony_ci &__clk_0_24, /* mcfuart.0 */ 838c2ecf20Sopenharmony_ci &__clk_0_25, /* mcfuart.1 */ 848c2ecf20Sopenharmony_ci &__clk_0_26, /* mcfuart.2 */ 858c2ecf20Sopenharmony_ci 868c2ecf20Sopenharmony_ci &__clk_0_32, /* mcfpit.0 */ 878c2ecf20Sopenharmony_ci &__clk_0_33, /* mcfpit.1 */ 888c2ecf20Sopenharmony_ci &__clk_0_34, /* mcfeport.0 */ 898c2ecf20Sopenharmony_ci &__clk_0_36, /* pll.0 */ 908c2ecf20Sopenharmony_ci &__clk_0_40, /* sys.0 */ 918c2ecf20Sopenharmony_ci &__clk_0_41, /* gpio.0 */ 928c2ecf20Sopenharmony_ci &__clk_0_42, /* sdram.0 */ 938c2ecf20Sopenharmony_ci}; 948c2ecf20Sopenharmony_ci 958c2ecf20Sopenharmony_cistatic struct clk * const disable_clks[] __initconst = { 968c2ecf20Sopenharmony_ci &__clk_0_12, /* fec.0 */ 978c2ecf20Sopenharmony_ci &__clk_0_17, /* edma */ 988c2ecf20Sopenharmony_ci &__clk_0_22, /* imx1-i2c.0 */ 998c2ecf20Sopenharmony_ci &__clk_0_23, /* mcfqspi.0 */ 1008c2ecf20Sopenharmony_ci &__clk_0_28, /* mcftmr.0 */ 1018c2ecf20Sopenharmony_ci &__clk_0_29, /* mcftmr.1 */ 1028c2ecf20Sopenharmony_ci &__clk_0_30, /* mcftmr.2 */ 1038c2ecf20Sopenharmony_ci &__clk_0_31, /* mcftmr.3 */ 1048c2ecf20Sopenharmony_ci &__clk_0_35, /* mcfwdt.0 */ 1058c2ecf20Sopenharmony_ci}; 1068c2ecf20Sopenharmony_ci 1078c2ecf20Sopenharmony_ci 1088c2ecf20Sopenharmony_cistatic void __init m520x_clk_init(void) 1098c2ecf20Sopenharmony_ci{ 1108c2ecf20Sopenharmony_ci unsigned i; 1118c2ecf20Sopenharmony_ci 1128c2ecf20Sopenharmony_ci /* make sure these clocks are enabled */ 1138c2ecf20Sopenharmony_ci for (i = 0; i < ARRAY_SIZE(enable_clks); ++i) 1148c2ecf20Sopenharmony_ci __clk_init_enabled(enable_clks[i]); 1158c2ecf20Sopenharmony_ci /* make sure these clocks are disabled */ 1168c2ecf20Sopenharmony_ci for (i = 0; i < ARRAY_SIZE(disable_clks); ++i) 1178c2ecf20Sopenharmony_ci __clk_init_disabled(disable_clks[i]); 1188c2ecf20Sopenharmony_ci} 1198c2ecf20Sopenharmony_ci 1208c2ecf20Sopenharmony_ci/***************************************************************************/ 1218c2ecf20Sopenharmony_ci 1228c2ecf20Sopenharmony_cistatic void __init m520x_qspi_init(void) 1238c2ecf20Sopenharmony_ci{ 1248c2ecf20Sopenharmony_ci#if IS_ENABLED(CONFIG_SPI_COLDFIRE_QSPI) 1258c2ecf20Sopenharmony_ci u16 par; 1268c2ecf20Sopenharmony_ci /* setup Port QS for QSPI with gpio CS control */ 1278c2ecf20Sopenharmony_ci writeb(0x3f, MCF_GPIO_PAR_QSPI); 1288c2ecf20Sopenharmony_ci /* make U1CTS and U2RTS gpio for cs_control */ 1298c2ecf20Sopenharmony_ci par = readw(MCF_GPIO_PAR_UART); 1308c2ecf20Sopenharmony_ci par &= 0x00ff; 1318c2ecf20Sopenharmony_ci writew(par, MCF_GPIO_PAR_UART); 1328c2ecf20Sopenharmony_ci#endif /* IS_ENABLED(CONFIG_SPI_COLDFIRE_QSPI) */ 1338c2ecf20Sopenharmony_ci} 1348c2ecf20Sopenharmony_ci 1358c2ecf20Sopenharmony_ci/***************************************************************************/ 1368c2ecf20Sopenharmony_ci 1378c2ecf20Sopenharmony_cistatic void __init m520x_i2c_init(void) 1388c2ecf20Sopenharmony_ci{ 1398c2ecf20Sopenharmony_ci#if IS_ENABLED(CONFIG_I2C_IMX) 1408c2ecf20Sopenharmony_ci u8 par; 1418c2ecf20Sopenharmony_ci 1428c2ecf20Sopenharmony_ci /* setup Port FECI2C Pin Assignment Register for I2C */ 1438c2ecf20Sopenharmony_ci /* set PAR_SCL to SCL and PAR_SDA to SDA */ 1448c2ecf20Sopenharmony_ci par = readb(MCF_GPIO_PAR_FECI2C); 1458c2ecf20Sopenharmony_ci par |= 0x0f; 1468c2ecf20Sopenharmony_ci writeb(par, MCF_GPIO_PAR_FECI2C); 1478c2ecf20Sopenharmony_ci#endif /* IS_ENABLED(CONFIG_I2C_IMX) */ 1488c2ecf20Sopenharmony_ci} 1498c2ecf20Sopenharmony_ci 1508c2ecf20Sopenharmony_ci/***************************************************************************/ 1518c2ecf20Sopenharmony_ci 1528c2ecf20Sopenharmony_cistatic void __init m520x_uarts_init(void) 1538c2ecf20Sopenharmony_ci{ 1548c2ecf20Sopenharmony_ci u16 par; 1558c2ecf20Sopenharmony_ci u8 par2; 1568c2ecf20Sopenharmony_ci 1578c2ecf20Sopenharmony_ci /* UART0 and UART1 GPIO pin setup */ 1588c2ecf20Sopenharmony_ci par = readw(MCF_GPIO_PAR_UART); 1598c2ecf20Sopenharmony_ci par |= MCF_GPIO_PAR_UART_PAR_UTXD0 | MCF_GPIO_PAR_UART_PAR_URXD0; 1608c2ecf20Sopenharmony_ci par |= MCF_GPIO_PAR_UART_PAR_UTXD1 | MCF_GPIO_PAR_UART_PAR_URXD1; 1618c2ecf20Sopenharmony_ci writew(par, MCF_GPIO_PAR_UART); 1628c2ecf20Sopenharmony_ci 1638c2ecf20Sopenharmony_ci /* UART1 GPIO pin setup */ 1648c2ecf20Sopenharmony_ci par2 = readb(MCF_GPIO_PAR_FECI2C); 1658c2ecf20Sopenharmony_ci par2 &= ~0x0F; 1668c2ecf20Sopenharmony_ci par2 |= MCF_GPIO_PAR_FECI2C_PAR_SCL_UTXD2 | 1678c2ecf20Sopenharmony_ci MCF_GPIO_PAR_FECI2C_PAR_SDA_URXD2; 1688c2ecf20Sopenharmony_ci writeb(par2, MCF_GPIO_PAR_FECI2C); 1698c2ecf20Sopenharmony_ci} 1708c2ecf20Sopenharmony_ci 1718c2ecf20Sopenharmony_ci/***************************************************************************/ 1728c2ecf20Sopenharmony_ci 1738c2ecf20Sopenharmony_cistatic void __init m520x_fec_init(void) 1748c2ecf20Sopenharmony_ci{ 1758c2ecf20Sopenharmony_ci u8 v; 1768c2ecf20Sopenharmony_ci 1778c2ecf20Sopenharmony_ci /* Set multi-function pins to ethernet mode */ 1788c2ecf20Sopenharmony_ci v = readb(MCF_GPIO_PAR_FEC); 1798c2ecf20Sopenharmony_ci writeb(v | 0xf0, MCF_GPIO_PAR_FEC); 1808c2ecf20Sopenharmony_ci 1818c2ecf20Sopenharmony_ci v = readb(MCF_GPIO_PAR_FECI2C); 1828c2ecf20Sopenharmony_ci writeb(v | 0x0f, MCF_GPIO_PAR_FECI2C); 1838c2ecf20Sopenharmony_ci} 1848c2ecf20Sopenharmony_ci 1858c2ecf20Sopenharmony_ci/***************************************************************************/ 1868c2ecf20Sopenharmony_ci 1878c2ecf20Sopenharmony_civoid __init config_BSP(char *commandp, int size) 1888c2ecf20Sopenharmony_ci{ 1898c2ecf20Sopenharmony_ci mach_sched_init = hw_timer_init; 1908c2ecf20Sopenharmony_ci m520x_clk_init(); 1918c2ecf20Sopenharmony_ci m520x_uarts_init(); 1928c2ecf20Sopenharmony_ci m520x_fec_init(); 1938c2ecf20Sopenharmony_ci m520x_qspi_init(); 1948c2ecf20Sopenharmony_ci m520x_i2c_init(); 1958c2ecf20Sopenharmony_ci} 1968c2ecf20Sopenharmony_ci 1978c2ecf20Sopenharmony_ci/***************************************************************************/ 198