18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0
28c2ecf20Sopenharmony_ci/***************************************************************************/
38c2ecf20Sopenharmony_ci
48c2ecf20Sopenharmony_ci/*
58c2ecf20Sopenharmony_ci *	m528x.c  -- platform support for ColdFire 528x based boards
68c2ecf20Sopenharmony_ci *
78c2ecf20Sopenharmony_ci *	Sub-architcture dependent initialization code for the Freescale
88c2ecf20Sopenharmony_ci *	5280, 5281 and 5282 CPUs.
98c2ecf20Sopenharmony_ci *
108c2ecf20Sopenharmony_ci *	Copyright (C) 1999-2003, Greg Ungerer (gerg@snapgear.com)
118c2ecf20Sopenharmony_ci *	Copyright (C) 2001-2003, SnapGear Inc. (www.snapgear.com)
128c2ecf20Sopenharmony_ci */
138c2ecf20Sopenharmony_ci
148c2ecf20Sopenharmony_ci/***************************************************************************/
158c2ecf20Sopenharmony_ci
168c2ecf20Sopenharmony_ci#include <linux/kernel.h>
178c2ecf20Sopenharmony_ci#include <linux/param.h>
188c2ecf20Sopenharmony_ci#include <linux/init.h>
198c2ecf20Sopenharmony_ci#include <linux/platform_device.h>
208c2ecf20Sopenharmony_ci#include <linux/io.h>
218c2ecf20Sopenharmony_ci#include <asm/machdep.h>
228c2ecf20Sopenharmony_ci#include <asm/coldfire.h>
238c2ecf20Sopenharmony_ci#include <asm/mcfsim.h>
248c2ecf20Sopenharmony_ci#include <asm/mcfuart.h>
258c2ecf20Sopenharmony_ci#include <asm/mcfclk.h>
268c2ecf20Sopenharmony_ci
278c2ecf20Sopenharmony_ci/***************************************************************************/
288c2ecf20Sopenharmony_ci
298c2ecf20Sopenharmony_ciDEFINE_CLK(pll, "pll.0", MCF_CLK);
308c2ecf20Sopenharmony_ciDEFINE_CLK(sys, "sys.0", MCF_BUSCLK);
318c2ecf20Sopenharmony_ciDEFINE_CLK(mcfpit0, "mcfpit.0", MCF_CLK);
328c2ecf20Sopenharmony_ciDEFINE_CLK(mcfpit1, "mcfpit.1", MCF_CLK);
338c2ecf20Sopenharmony_ciDEFINE_CLK(mcfpit2, "mcfpit.2", MCF_CLK);
348c2ecf20Sopenharmony_ciDEFINE_CLK(mcfpit3, "mcfpit.3", MCF_CLK);
358c2ecf20Sopenharmony_ciDEFINE_CLK(mcfuart0, "mcfuart.0", MCF_BUSCLK);
368c2ecf20Sopenharmony_ciDEFINE_CLK(mcfuart1, "mcfuart.1", MCF_BUSCLK);
378c2ecf20Sopenharmony_ciDEFINE_CLK(mcfuart2, "mcfuart.2", MCF_BUSCLK);
388c2ecf20Sopenharmony_ciDEFINE_CLK(mcfqspi0, "mcfqspi.0", MCF_BUSCLK);
398c2ecf20Sopenharmony_ciDEFINE_CLK(fec0, "fec.0", MCF_BUSCLK);
408c2ecf20Sopenharmony_ciDEFINE_CLK(mcfi2c0, "imx1-i2c.0", MCF_BUSCLK);
418c2ecf20Sopenharmony_ci
428c2ecf20Sopenharmony_cistruct clk *mcf_clks[] = {
438c2ecf20Sopenharmony_ci	&clk_pll,
448c2ecf20Sopenharmony_ci	&clk_sys,
458c2ecf20Sopenharmony_ci	&clk_mcfpit0,
468c2ecf20Sopenharmony_ci	&clk_mcfpit1,
478c2ecf20Sopenharmony_ci	&clk_mcfpit2,
488c2ecf20Sopenharmony_ci	&clk_mcfpit3,
498c2ecf20Sopenharmony_ci	&clk_mcfuart0,
508c2ecf20Sopenharmony_ci	&clk_mcfuart1,
518c2ecf20Sopenharmony_ci	&clk_mcfuart2,
528c2ecf20Sopenharmony_ci	&clk_mcfqspi0,
538c2ecf20Sopenharmony_ci	&clk_fec0,
548c2ecf20Sopenharmony_ci	&clk_mcfi2c0,
558c2ecf20Sopenharmony_ci	NULL
568c2ecf20Sopenharmony_ci};
578c2ecf20Sopenharmony_ci
588c2ecf20Sopenharmony_ci/***************************************************************************/
598c2ecf20Sopenharmony_ci
608c2ecf20Sopenharmony_cistatic void __init m528x_qspi_init(void)
618c2ecf20Sopenharmony_ci{
628c2ecf20Sopenharmony_ci#if IS_ENABLED(CONFIG_SPI_COLDFIRE_QSPI)
638c2ecf20Sopenharmony_ci	/* setup Port QS for QSPI with gpio CS control */
648c2ecf20Sopenharmony_ci	__raw_writeb(0x07, MCFGPIO_PQSPAR);
658c2ecf20Sopenharmony_ci#endif /* IS_ENABLED(CONFIG_SPI_COLDFIRE_QSPI) */
668c2ecf20Sopenharmony_ci}
678c2ecf20Sopenharmony_ci
688c2ecf20Sopenharmony_ci/***************************************************************************/
698c2ecf20Sopenharmony_ci
708c2ecf20Sopenharmony_cistatic void __init m528x_i2c_init(void)
718c2ecf20Sopenharmony_ci{
728c2ecf20Sopenharmony_ci#if IS_ENABLED(CONFIG_I2C_IMX)
738c2ecf20Sopenharmony_ci	u16 paspar;
748c2ecf20Sopenharmony_ci
758c2ecf20Sopenharmony_ci	/* setup Port AS Pin Assignment Register for I2C */
768c2ecf20Sopenharmony_ci	/*  set PASPA0 to SCL and PASPA1 to SDA */
778c2ecf20Sopenharmony_ci	paspar = readw(MCFGPIO_PASPAR);
788c2ecf20Sopenharmony_ci	paspar |= 0xF;
798c2ecf20Sopenharmony_ci	writew(paspar, MCFGPIO_PASPAR);
808c2ecf20Sopenharmony_ci#endif /* IS_ENABLED(CONFIG_I2C_IMX) */
818c2ecf20Sopenharmony_ci}
828c2ecf20Sopenharmony_ci
838c2ecf20Sopenharmony_ci/***************************************************************************/
848c2ecf20Sopenharmony_ci
858c2ecf20Sopenharmony_cistatic void __init m528x_uarts_init(void)
868c2ecf20Sopenharmony_ci{
878c2ecf20Sopenharmony_ci	u8 port;
888c2ecf20Sopenharmony_ci
898c2ecf20Sopenharmony_ci	/* make sure PUAPAR is set for UART0 and UART1 */
908c2ecf20Sopenharmony_ci	port = readb(MCFGPIO_PUAPAR);
918c2ecf20Sopenharmony_ci	port |= 0x03 | (0x03 << 2);
928c2ecf20Sopenharmony_ci	writeb(port, MCFGPIO_PUAPAR);
938c2ecf20Sopenharmony_ci}
948c2ecf20Sopenharmony_ci
958c2ecf20Sopenharmony_ci/***************************************************************************/
968c2ecf20Sopenharmony_ci
978c2ecf20Sopenharmony_cistatic void __init m528x_fec_init(void)
988c2ecf20Sopenharmony_ci{
998c2ecf20Sopenharmony_ci	u16 v16;
1008c2ecf20Sopenharmony_ci
1018c2ecf20Sopenharmony_ci	/* Set multi-function pins to ethernet mode for fec0 */
1028c2ecf20Sopenharmony_ci	v16 = readw(MCFGPIO_PASPAR);
1038c2ecf20Sopenharmony_ci	writew(v16 | 0xf00, MCFGPIO_PASPAR);
1048c2ecf20Sopenharmony_ci	writeb(0xc0, MCFGPIO_PEHLPAR);
1058c2ecf20Sopenharmony_ci}
1068c2ecf20Sopenharmony_ci
1078c2ecf20Sopenharmony_ci/***************************************************************************/
1088c2ecf20Sopenharmony_ci
1098c2ecf20Sopenharmony_ci#ifdef CONFIG_WILDFIRE
1108c2ecf20Sopenharmony_civoid wildfire_halt(void)
1118c2ecf20Sopenharmony_ci{
1128c2ecf20Sopenharmony_ci	writeb(0, 0x30000007);
1138c2ecf20Sopenharmony_ci	writeb(0x2, 0x30000007);
1148c2ecf20Sopenharmony_ci}
1158c2ecf20Sopenharmony_ci#endif
1168c2ecf20Sopenharmony_ci
1178c2ecf20Sopenharmony_ci#ifdef CONFIG_WILDFIREMOD
1188c2ecf20Sopenharmony_civoid wildfiremod_halt(void)
1198c2ecf20Sopenharmony_ci{
1208c2ecf20Sopenharmony_ci	printk(KERN_INFO "WildFireMod hibernating...\n");
1218c2ecf20Sopenharmony_ci
1228c2ecf20Sopenharmony_ci	/* Set portE.5 to Digital IO */
1238c2ecf20Sopenharmony_ci	writew(readw(MCFGPIO_PEPAR) & ~(1 << (5 * 2)), MCFGPIO_PEPAR);
1248c2ecf20Sopenharmony_ci
1258c2ecf20Sopenharmony_ci	/* Make portE.5 an output */
1268c2ecf20Sopenharmony_ci	writeb(readb(MCFGPIO_PDDR_E) | (1 << 5), MCFGPIO_PDDR_E);
1278c2ecf20Sopenharmony_ci
1288c2ecf20Sopenharmony_ci	/* Now toggle portE.5 from low to high */
1298c2ecf20Sopenharmony_ci	writeb(readb(MCFGPIO_PODR_E) & ~(1 << 5), MCFGPIO_PODR_E);
1308c2ecf20Sopenharmony_ci	writeb(readb(MCFGPIO_PODR_E) | (1 << 5), MCFGPIO_PODR_E);
1318c2ecf20Sopenharmony_ci
1328c2ecf20Sopenharmony_ci	printk(KERN_EMERG "Failed to hibernate. Halting!\n");
1338c2ecf20Sopenharmony_ci}
1348c2ecf20Sopenharmony_ci#endif
1358c2ecf20Sopenharmony_ci
1368c2ecf20Sopenharmony_civoid __init config_BSP(char *commandp, int size)
1378c2ecf20Sopenharmony_ci{
1388c2ecf20Sopenharmony_ci#ifdef CONFIG_WILDFIRE
1398c2ecf20Sopenharmony_ci	mach_halt = wildfire_halt;
1408c2ecf20Sopenharmony_ci#endif
1418c2ecf20Sopenharmony_ci#ifdef CONFIG_WILDFIREMOD
1428c2ecf20Sopenharmony_ci	mach_halt = wildfiremod_halt;
1438c2ecf20Sopenharmony_ci#endif
1448c2ecf20Sopenharmony_ci	mach_sched_init = hw_timer_init;
1458c2ecf20Sopenharmony_ci	m528x_uarts_init();
1468c2ecf20Sopenharmony_ci	m528x_fec_init();
1478c2ecf20Sopenharmony_ci	m528x_qspi_init();
1488c2ecf20Sopenharmony_ci	m528x_i2c_init();
1498c2ecf20Sopenharmony_ci}
1508c2ecf20Sopenharmony_ci
1518c2ecf20Sopenharmony_ci/***************************************************************************/
152