18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0
28c2ecf20Sopenharmony_ci/***************************************************************************/
38c2ecf20Sopenharmony_ci
48c2ecf20Sopenharmony_ci/*
58c2ecf20Sopenharmony_ci *	m527x.c  -- platform support for ColdFire 527x based boards
68c2ecf20Sopenharmony_ci *
78c2ecf20Sopenharmony_ci *	Sub-architcture dependent initialization code for the Freescale
88c2ecf20Sopenharmony_ci *	5270/5271 and 5274/5275 CPUs.
98c2ecf20Sopenharmony_ci *
108c2ecf20Sopenharmony_ci *	Copyright (C) 1999-2004, Greg Ungerer (gerg@snapgear.com)
118c2ecf20Sopenharmony_ci *	Copyright (C) 2001-2004, 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/io.h>
208c2ecf20Sopenharmony_ci#include <asm/machdep.h>
218c2ecf20Sopenharmony_ci#include <asm/coldfire.h>
228c2ecf20Sopenharmony_ci#include <asm/mcfsim.h>
238c2ecf20Sopenharmony_ci#include <asm/mcfuart.h>
248c2ecf20Sopenharmony_ci#include <asm/mcfclk.h>
258c2ecf20Sopenharmony_ci
268c2ecf20Sopenharmony_ci/***************************************************************************/
278c2ecf20Sopenharmony_ci
288c2ecf20Sopenharmony_ciDEFINE_CLK(pll, "pll.0", MCF_CLK);
298c2ecf20Sopenharmony_ciDEFINE_CLK(sys, "sys.0", MCF_BUSCLK);
308c2ecf20Sopenharmony_ciDEFINE_CLK(mcfpit0, "mcfpit.0", MCF_CLK);
318c2ecf20Sopenharmony_ciDEFINE_CLK(mcfpit1, "mcfpit.1", MCF_CLK);
328c2ecf20Sopenharmony_ciDEFINE_CLK(mcfpit2, "mcfpit.2", MCF_CLK);
338c2ecf20Sopenharmony_ciDEFINE_CLK(mcfpit3, "mcfpit.3", MCF_CLK);
348c2ecf20Sopenharmony_ciDEFINE_CLK(mcfuart0, "mcfuart.0", MCF_BUSCLK);
358c2ecf20Sopenharmony_ciDEFINE_CLK(mcfuart1, "mcfuart.1", MCF_BUSCLK);
368c2ecf20Sopenharmony_ciDEFINE_CLK(mcfuart2, "mcfuart.2", MCF_BUSCLK);
378c2ecf20Sopenharmony_ciDEFINE_CLK(mcfqspi0, "mcfqspi.0", MCF_BUSCLK);
388c2ecf20Sopenharmony_ciDEFINE_CLK(fec0, "fec.0", MCF_BUSCLK);
398c2ecf20Sopenharmony_ciDEFINE_CLK(fec1, "fec.1", 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_fec1,
558c2ecf20Sopenharmony_ci	&clk_mcfi2c0,
568c2ecf20Sopenharmony_ci	NULL
578c2ecf20Sopenharmony_ci};
588c2ecf20Sopenharmony_ci
598c2ecf20Sopenharmony_ci/***************************************************************************/
608c2ecf20Sopenharmony_ci
618c2ecf20Sopenharmony_cistatic void __init m527x_qspi_init(void)
628c2ecf20Sopenharmony_ci{
638c2ecf20Sopenharmony_ci#if IS_ENABLED(CONFIG_SPI_COLDFIRE_QSPI)
648c2ecf20Sopenharmony_ci#if defined(CONFIG_M5271)
658c2ecf20Sopenharmony_ci	u16 par;
668c2ecf20Sopenharmony_ci
678c2ecf20Sopenharmony_ci	/* setup QSPS pins for QSPI with gpio CS control */
688c2ecf20Sopenharmony_ci	writeb(0x1f, MCFGPIO_PAR_QSPI);
698c2ecf20Sopenharmony_ci	/* and CS2 & CS3 as gpio */
708c2ecf20Sopenharmony_ci	par = readw(MCFGPIO_PAR_TIMER);
718c2ecf20Sopenharmony_ci	par &= 0x3f3f;
728c2ecf20Sopenharmony_ci	writew(par, MCFGPIO_PAR_TIMER);
738c2ecf20Sopenharmony_ci#elif defined(CONFIG_M5275)
748c2ecf20Sopenharmony_ci	/* setup QSPS pins for QSPI with gpio CS control */
758c2ecf20Sopenharmony_ci	writew(0x003e, MCFGPIO_PAR_QSPI);
768c2ecf20Sopenharmony_ci#endif
778c2ecf20Sopenharmony_ci#endif /* IS_ENABLED(CONFIG_SPI_COLDFIRE_QSPI) */
788c2ecf20Sopenharmony_ci}
798c2ecf20Sopenharmony_ci
808c2ecf20Sopenharmony_ci/***************************************************************************/
818c2ecf20Sopenharmony_ci
828c2ecf20Sopenharmony_cistatic void __init m527x_i2c_init(void)
838c2ecf20Sopenharmony_ci{
848c2ecf20Sopenharmony_ci#if IS_ENABLED(CONFIG_I2C_IMX)
858c2ecf20Sopenharmony_ci#if defined(CONFIG_M5271)
868c2ecf20Sopenharmony_ci	u8 par;
878c2ecf20Sopenharmony_ci
888c2ecf20Sopenharmony_ci	/* setup Port FECI2C Pin Assignment Register for I2C */
898c2ecf20Sopenharmony_ci	/*  set PAR_SCL to SCL and PAR_SDA to SDA */
908c2ecf20Sopenharmony_ci	par = readb(MCFGPIO_PAR_FECI2C);
918c2ecf20Sopenharmony_ci	par |= 0x0f;
928c2ecf20Sopenharmony_ci	writeb(par, MCFGPIO_PAR_FECI2C);
938c2ecf20Sopenharmony_ci#elif defined(CONFIG_M5275)
948c2ecf20Sopenharmony_ci	u16 par;
958c2ecf20Sopenharmony_ci
968c2ecf20Sopenharmony_ci	/* setup Port FECI2C Pin Assignment Register for I2C */
978c2ecf20Sopenharmony_ci	/*  set PAR_SCL to SCL and PAR_SDA to SDA */
988c2ecf20Sopenharmony_ci	par = readw(MCFGPIO_PAR_FECI2C);
998c2ecf20Sopenharmony_ci	par |= 0x0f;
1008c2ecf20Sopenharmony_ci	writew(par, MCFGPIO_PAR_FECI2C);
1018c2ecf20Sopenharmony_ci#endif
1028c2ecf20Sopenharmony_ci#endif /* IS_ENABLED(CONFIG_I2C_IMX) */
1038c2ecf20Sopenharmony_ci}
1048c2ecf20Sopenharmony_ci
1058c2ecf20Sopenharmony_ci/***************************************************************************/
1068c2ecf20Sopenharmony_ci
1078c2ecf20Sopenharmony_cistatic void __init m527x_uarts_init(void)
1088c2ecf20Sopenharmony_ci{
1098c2ecf20Sopenharmony_ci	u16 sepmask;
1108c2ecf20Sopenharmony_ci
1118c2ecf20Sopenharmony_ci	/*
1128c2ecf20Sopenharmony_ci	 * External Pin Mask Setting & Enable External Pin for Interface
1138c2ecf20Sopenharmony_ci	 */
1148c2ecf20Sopenharmony_ci	sepmask = readw(MCFGPIO_PAR_UART);
1158c2ecf20Sopenharmony_ci	sepmask |= UART0_ENABLE_MASK | UART1_ENABLE_MASK | UART2_ENABLE_MASK;
1168c2ecf20Sopenharmony_ci	writew(sepmask, MCFGPIO_PAR_UART);
1178c2ecf20Sopenharmony_ci}
1188c2ecf20Sopenharmony_ci
1198c2ecf20Sopenharmony_ci/***************************************************************************/
1208c2ecf20Sopenharmony_ci
1218c2ecf20Sopenharmony_cistatic void __init m527x_fec_init(void)
1228c2ecf20Sopenharmony_ci{
1238c2ecf20Sopenharmony_ci	u8 v;
1248c2ecf20Sopenharmony_ci
1258c2ecf20Sopenharmony_ci	/* Set multi-function pins to ethernet mode for fec0 */
1268c2ecf20Sopenharmony_ci#if defined(CONFIG_M5271)
1278c2ecf20Sopenharmony_ci	v = readb(MCFGPIO_PAR_FECI2C);
1288c2ecf20Sopenharmony_ci	writeb(v | 0xf0, MCFGPIO_PAR_FECI2C);
1298c2ecf20Sopenharmony_ci#else
1308c2ecf20Sopenharmony_ci	u16 par;
1318c2ecf20Sopenharmony_ci
1328c2ecf20Sopenharmony_ci	par = readw(MCFGPIO_PAR_FECI2C);
1338c2ecf20Sopenharmony_ci	writew(par | 0xf00, MCFGPIO_PAR_FECI2C);
1348c2ecf20Sopenharmony_ci	v = readb(MCFGPIO_PAR_FEC0HL);
1358c2ecf20Sopenharmony_ci	writeb(v | 0xc0, MCFGPIO_PAR_FEC0HL);
1368c2ecf20Sopenharmony_ci
1378c2ecf20Sopenharmony_ci	/* Set multi-function pins to ethernet mode for fec1 */
1388c2ecf20Sopenharmony_ci	par = readw(MCFGPIO_PAR_FECI2C);
1398c2ecf20Sopenharmony_ci	writew(par | 0xa0, MCFGPIO_PAR_FECI2C);
1408c2ecf20Sopenharmony_ci	v = readb(MCFGPIO_PAR_FEC1HL);
1418c2ecf20Sopenharmony_ci	writeb(v | 0xc0, MCFGPIO_PAR_FEC1HL);
1428c2ecf20Sopenharmony_ci#endif
1438c2ecf20Sopenharmony_ci}
1448c2ecf20Sopenharmony_ci
1458c2ecf20Sopenharmony_ci/***************************************************************************/
1468c2ecf20Sopenharmony_ci
1478c2ecf20Sopenharmony_civoid __init config_BSP(char *commandp, int size)
1488c2ecf20Sopenharmony_ci{
1498c2ecf20Sopenharmony_ci	mach_sched_init = hw_timer_init;
1508c2ecf20Sopenharmony_ci	m527x_uarts_init();
1518c2ecf20Sopenharmony_ci	m527x_fec_init();
1528c2ecf20Sopenharmony_ci	m527x_qspi_init();
1538c2ecf20Sopenharmony_ci	m527x_i2c_init();
1548c2ecf20Sopenharmony_ci}
1558c2ecf20Sopenharmony_ci
1568c2ecf20Sopenharmony_ci/***************************************************************************/
157