18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-or-later
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * Keymile km82xx support
48c2ecf20Sopenharmony_ci * Copyright 2008-2011 DENX Software Engineering GmbH
58c2ecf20Sopenharmony_ci * Author: Heiko Schocher <hs@denx.de>
68c2ecf20Sopenharmony_ci *
78c2ecf20Sopenharmony_ci * based on code from:
88c2ecf20Sopenharmony_ci * Copyright 2007 Freescale Semiconductor, Inc.
98c2ecf20Sopenharmony_ci * Author: Scott Wood <scottwood@freescale.com>
108c2ecf20Sopenharmony_ci */
118c2ecf20Sopenharmony_ci
128c2ecf20Sopenharmony_ci#include <linux/init.h>
138c2ecf20Sopenharmony_ci#include <linux/interrupt.h>
148c2ecf20Sopenharmony_ci#include <linux/fsl_devices.h>
158c2ecf20Sopenharmony_ci#include <linux/of_platform.h>
168c2ecf20Sopenharmony_ci
178c2ecf20Sopenharmony_ci#include <linux/io.h>
188c2ecf20Sopenharmony_ci#include <asm/cpm2.h>
198c2ecf20Sopenharmony_ci#include <asm/udbg.h>
208c2ecf20Sopenharmony_ci#include <asm/machdep.h>
218c2ecf20Sopenharmony_ci#include <linux/time.h>
228c2ecf20Sopenharmony_ci#include <asm/mpc8260.h>
238c2ecf20Sopenharmony_ci#include <asm/prom.h>
248c2ecf20Sopenharmony_ci
258c2ecf20Sopenharmony_ci#include <sysdev/fsl_soc.h>
268c2ecf20Sopenharmony_ci#include <sysdev/cpm2_pic.h>
278c2ecf20Sopenharmony_ci
288c2ecf20Sopenharmony_ci#include "pq2.h"
298c2ecf20Sopenharmony_ci
308c2ecf20Sopenharmony_cistatic void __init km82xx_pic_init(void)
318c2ecf20Sopenharmony_ci{
328c2ecf20Sopenharmony_ci	struct device_node *np = of_find_compatible_node(NULL, NULL,
338c2ecf20Sopenharmony_ci							"fsl,pq2-pic");
348c2ecf20Sopenharmony_ci	if (!np) {
358c2ecf20Sopenharmony_ci		pr_err("PIC init: can not find cpm-pic node\n");
368c2ecf20Sopenharmony_ci		return;
378c2ecf20Sopenharmony_ci	}
388c2ecf20Sopenharmony_ci
398c2ecf20Sopenharmony_ci	cpm2_pic_init(np);
408c2ecf20Sopenharmony_ci	of_node_put(np);
418c2ecf20Sopenharmony_ci}
428c2ecf20Sopenharmony_ci
438c2ecf20Sopenharmony_cistruct cpm_pin {
448c2ecf20Sopenharmony_ci	int port, pin, flags;
458c2ecf20Sopenharmony_ci};
468c2ecf20Sopenharmony_ci
478c2ecf20Sopenharmony_cistatic __initdata struct cpm_pin km82xx_pins[] = {
488c2ecf20Sopenharmony_ci	/* SMC1 */
498c2ecf20Sopenharmony_ci	{2, 4, CPM_PIN_INPUT | CPM_PIN_PRIMARY},
508c2ecf20Sopenharmony_ci	{2, 5, CPM_PIN_OUTPUT | CPM_PIN_PRIMARY},
518c2ecf20Sopenharmony_ci
528c2ecf20Sopenharmony_ci	/* SMC2 */
538c2ecf20Sopenharmony_ci	{0, 8, CPM_PIN_INPUT | CPM_PIN_PRIMARY},
548c2ecf20Sopenharmony_ci	{0, 9, CPM_PIN_OUTPUT | CPM_PIN_PRIMARY},
558c2ecf20Sopenharmony_ci
568c2ecf20Sopenharmony_ci	/* SCC1 */
578c2ecf20Sopenharmony_ci	{2, 21, CPM_PIN_INPUT | CPM_PIN_PRIMARY},
588c2ecf20Sopenharmony_ci	{2, 15, CPM_PIN_INPUT | CPM_PIN_PRIMARY},
598c2ecf20Sopenharmony_ci	{3, 31, CPM_PIN_INPUT | CPM_PIN_PRIMARY},
608c2ecf20Sopenharmony_ci	{3, 30, CPM_PIN_OUTPUT | CPM_PIN_SECONDARY},
618c2ecf20Sopenharmony_ci
628c2ecf20Sopenharmony_ci	/* SCC4 */
638c2ecf20Sopenharmony_ci	{2, 25, CPM_PIN_INPUT | CPM_PIN_PRIMARY},
648c2ecf20Sopenharmony_ci	{2, 24, CPM_PIN_INPUT | CPM_PIN_PRIMARY},
658c2ecf20Sopenharmony_ci	{2,  9, CPM_PIN_INPUT | CPM_PIN_PRIMARY},
668c2ecf20Sopenharmony_ci	{2,  8, CPM_PIN_INPUT | CPM_PIN_PRIMARY},
678c2ecf20Sopenharmony_ci	{3, 22, CPM_PIN_INPUT | CPM_PIN_PRIMARY},
688c2ecf20Sopenharmony_ci	{3, 21, CPM_PIN_OUTPUT | CPM_PIN_PRIMARY},
698c2ecf20Sopenharmony_ci
708c2ecf20Sopenharmony_ci	/* FCC1 */
718c2ecf20Sopenharmony_ci	{0, 14, CPM_PIN_INPUT | CPM_PIN_PRIMARY},
728c2ecf20Sopenharmony_ci	{0, 15, CPM_PIN_INPUT | CPM_PIN_PRIMARY},
738c2ecf20Sopenharmony_ci	{0, 16, CPM_PIN_INPUT | CPM_PIN_PRIMARY},
748c2ecf20Sopenharmony_ci	{0, 17, CPM_PIN_INPUT | CPM_PIN_PRIMARY},
758c2ecf20Sopenharmony_ci	{0, 18, CPM_PIN_OUTPUT | CPM_PIN_PRIMARY},
768c2ecf20Sopenharmony_ci	{0, 19, CPM_PIN_OUTPUT | CPM_PIN_PRIMARY},
778c2ecf20Sopenharmony_ci	{0, 20, CPM_PIN_OUTPUT | CPM_PIN_PRIMARY},
788c2ecf20Sopenharmony_ci	{0, 21, CPM_PIN_OUTPUT | CPM_PIN_PRIMARY},
798c2ecf20Sopenharmony_ci	{0, 26, CPM_PIN_INPUT | CPM_PIN_SECONDARY},
808c2ecf20Sopenharmony_ci	{0, 27, CPM_PIN_INPUT | CPM_PIN_SECONDARY},
818c2ecf20Sopenharmony_ci	{0, 28, CPM_PIN_OUTPUT | CPM_PIN_SECONDARY},
828c2ecf20Sopenharmony_ci	{0, 29, CPM_PIN_OUTPUT | CPM_PIN_SECONDARY},
838c2ecf20Sopenharmony_ci	{0, 30, CPM_PIN_INPUT | CPM_PIN_SECONDARY},
848c2ecf20Sopenharmony_ci	{0, 31, CPM_PIN_INPUT | CPM_PIN_SECONDARY},
858c2ecf20Sopenharmony_ci
868c2ecf20Sopenharmony_ci	{2, 22, CPM_PIN_INPUT | CPM_PIN_PRIMARY},
878c2ecf20Sopenharmony_ci	{2, 23, CPM_PIN_INPUT | CPM_PIN_PRIMARY},
888c2ecf20Sopenharmony_ci
898c2ecf20Sopenharmony_ci	/* FCC2 */
908c2ecf20Sopenharmony_ci	{1, 18, CPM_PIN_INPUT | CPM_PIN_PRIMARY},
918c2ecf20Sopenharmony_ci	{1, 19, CPM_PIN_INPUT | CPM_PIN_PRIMARY},
928c2ecf20Sopenharmony_ci	{1, 20, CPM_PIN_INPUT | CPM_PIN_PRIMARY},
938c2ecf20Sopenharmony_ci	{1, 21, CPM_PIN_INPUT | CPM_PIN_PRIMARY},
948c2ecf20Sopenharmony_ci	{1, 22, CPM_PIN_OUTPUT | CPM_PIN_PRIMARY},
958c2ecf20Sopenharmony_ci	{1, 23, CPM_PIN_OUTPUT | CPM_PIN_PRIMARY},
968c2ecf20Sopenharmony_ci	{1, 24, CPM_PIN_OUTPUT | CPM_PIN_PRIMARY},
978c2ecf20Sopenharmony_ci	{1, 25, CPM_PIN_OUTPUT | CPM_PIN_PRIMARY},
988c2ecf20Sopenharmony_ci	{1, 26, CPM_PIN_INPUT | CPM_PIN_PRIMARY},
998c2ecf20Sopenharmony_ci	{1, 27, CPM_PIN_INPUT | CPM_PIN_PRIMARY},
1008c2ecf20Sopenharmony_ci	{1, 28, CPM_PIN_INPUT | CPM_PIN_PRIMARY},
1018c2ecf20Sopenharmony_ci	{1, 29, CPM_PIN_OUTPUT | CPM_PIN_SECONDARY},
1028c2ecf20Sopenharmony_ci	{1, 30, CPM_PIN_INPUT | CPM_PIN_PRIMARY},
1038c2ecf20Sopenharmony_ci	{1, 31, CPM_PIN_OUTPUT | CPM_PIN_PRIMARY},
1048c2ecf20Sopenharmony_ci
1058c2ecf20Sopenharmony_ci	{2, 18, CPM_PIN_INPUT | CPM_PIN_PRIMARY},
1068c2ecf20Sopenharmony_ci	{2, 19, CPM_PIN_INPUT | CPM_PIN_PRIMARY},
1078c2ecf20Sopenharmony_ci
1088c2ecf20Sopenharmony_ci	/* MDC */
1098c2ecf20Sopenharmony_ci	{0, 13, CPM_PIN_OUTPUT | CPM_PIN_GPIO},
1108c2ecf20Sopenharmony_ci
1118c2ecf20Sopenharmony_ci#if defined(CONFIG_I2C_CPM)
1128c2ecf20Sopenharmony_ci	/* I2C */
1138c2ecf20Sopenharmony_ci	{3, 14, CPM_PIN_INPUT | CPM_PIN_SECONDARY | CPM_PIN_OPENDRAIN},
1148c2ecf20Sopenharmony_ci	{3, 15, CPM_PIN_INPUT | CPM_PIN_SECONDARY | CPM_PIN_OPENDRAIN},
1158c2ecf20Sopenharmony_ci#endif
1168c2ecf20Sopenharmony_ci
1178c2ecf20Sopenharmony_ci	/* USB */
1188c2ecf20Sopenharmony_ci	{0, 10, CPM_PIN_OUTPUT | CPM_PIN_GPIO},    /* FULL_SPEED */
1198c2ecf20Sopenharmony_ci	{0, 11, CPM_PIN_OUTPUT | CPM_PIN_GPIO},    /*/SLAVE */
1208c2ecf20Sopenharmony_ci	{2, 10, CPM_PIN_INPUT  | CPM_PIN_PRIMARY}, /* RXN */
1218c2ecf20Sopenharmony_ci	{2, 11, CPM_PIN_INPUT  | CPM_PIN_PRIMARY}, /* RXP */
1228c2ecf20Sopenharmony_ci	{2, 20, CPM_PIN_OUTPUT | CPM_PIN_PRIMARY}, /* /OE */
1238c2ecf20Sopenharmony_ci	{2, 27, CPM_PIN_INPUT  | CPM_PIN_PRIMARY}, /* RXCLK */
1248c2ecf20Sopenharmony_ci	{3, 23, CPM_PIN_OUTPUT | CPM_PIN_PRIMARY}, /* TXP */
1258c2ecf20Sopenharmony_ci	{3, 24, CPM_PIN_OUTPUT | CPM_PIN_PRIMARY}, /* TXN */
1268c2ecf20Sopenharmony_ci	{3, 25, CPM_PIN_INPUT  | CPM_PIN_PRIMARY}, /* RXD */
1278c2ecf20Sopenharmony_ci
1288c2ecf20Sopenharmony_ci	/* SPI */
1298c2ecf20Sopenharmony_ci	{3, 16, CPM_PIN_INPUT | CPM_PIN_SECONDARY},/* SPI_MISO PD16 */
1308c2ecf20Sopenharmony_ci	{3, 17, CPM_PIN_INPUT | CPM_PIN_SECONDARY},/* SPI_MOSI PD17 */
1318c2ecf20Sopenharmony_ci	{3, 18, CPM_PIN_INPUT | CPM_PIN_SECONDARY},/* SPI_CLK PD18 */
1328c2ecf20Sopenharmony_ci};
1338c2ecf20Sopenharmony_ci
1348c2ecf20Sopenharmony_cistatic void __init init_ioports(void)
1358c2ecf20Sopenharmony_ci{
1368c2ecf20Sopenharmony_ci	int i;
1378c2ecf20Sopenharmony_ci
1388c2ecf20Sopenharmony_ci	for (i = 0; i < ARRAY_SIZE(km82xx_pins); i++) {
1398c2ecf20Sopenharmony_ci		const struct cpm_pin *pin = &km82xx_pins[i];
1408c2ecf20Sopenharmony_ci		cpm2_set_pin(pin->port, pin->pin, pin->flags);
1418c2ecf20Sopenharmony_ci	}
1428c2ecf20Sopenharmony_ci
1438c2ecf20Sopenharmony_ci	cpm2_smc_clk_setup(CPM_CLK_SMC2, CPM_BRG8);
1448c2ecf20Sopenharmony_ci	cpm2_smc_clk_setup(CPM_CLK_SMC1, CPM_BRG7);
1458c2ecf20Sopenharmony_ci	cpm2_clk_setup(CPM_CLK_SCC1, CPM_CLK11, CPM_CLK_RX);
1468c2ecf20Sopenharmony_ci	cpm2_clk_setup(CPM_CLK_SCC1, CPM_CLK11, CPM_CLK_TX);
1478c2ecf20Sopenharmony_ci	cpm2_clk_setup(CPM_CLK_SCC3, CPM_CLK5, CPM_CLK_RTX);
1488c2ecf20Sopenharmony_ci	cpm2_clk_setup(CPM_CLK_SCC4, CPM_CLK7, CPM_CLK_RX);
1498c2ecf20Sopenharmony_ci	cpm2_clk_setup(CPM_CLK_SCC4, CPM_CLK8, CPM_CLK_TX);
1508c2ecf20Sopenharmony_ci	cpm2_clk_setup(CPM_CLK_FCC1, CPM_CLK10, CPM_CLK_RX);
1518c2ecf20Sopenharmony_ci	cpm2_clk_setup(CPM_CLK_FCC1, CPM_CLK9,  CPM_CLK_TX);
1528c2ecf20Sopenharmony_ci	cpm2_clk_setup(CPM_CLK_FCC2, CPM_CLK13, CPM_CLK_RX);
1538c2ecf20Sopenharmony_ci	cpm2_clk_setup(CPM_CLK_FCC2, CPM_CLK14, CPM_CLK_TX);
1548c2ecf20Sopenharmony_ci
1558c2ecf20Sopenharmony_ci	/* Force USB FULL SPEED bit to '1' */
1568c2ecf20Sopenharmony_ci	setbits32(&cpm2_immr->im_ioport.iop_pdata, 1 << (31 - 10));
1578c2ecf20Sopenharmony_ci	/* clear USB_SLAVE */
1588c2ecf20Sopenharmony_ci	clrbits32(&cpm2_immr->im_ioport.iop_pdata, 1 << (31 - 11));
1598c2ecf20Sopenharmony_ci}
1608c2ecf20Sopenharmony_ci
1618c2ecf20Sopenharmony_cistatic void __init km82xx_setup_arch(void)
1628c2ecf20Sopenharmony_ci{
1638c2ecf20Sopenharmony_ci	if (ppc_md.progress)
1648c2ecf20Sopenharmony_ci		ppc_md.progress("km82xx_setup_arch()", 0);
1658c2ecf20Sopenharmony_ci
1668c2ecf20Sopenharmony_ci	cpm2_reset();
1678c2ecf20Sopenharmony_ci
1688c2ecf20Sopenharmony_ci	/* When this is set, snooping CPM DMA from RAM causes
1698c2ecf20Sopenharmony_ci	 * machine checks.  See erratum SIU18.
1708c2ecf20Sopenharmony_ci	 */
1718c2ecf20Sopenharmony_ci	clrbits32(&cpm2_immr->im_siu_conf.siu_82xx.sc_bcr, MPC82XX_BCR_PLDP);
1728c2ecf20Sopenharmony_ci
1738c2ecf20Sopenharmony_ci	init_ioports();
1748c2ecf20Sopenharmony_ci
1758c2ecf20Sopenharmony_ci	if (ppc_md.progress)
1768c2ecf20Sopenharmony_ci		ppc_md.progress("km82xx_setup_arch(), finish", 0);
1778c2ecf20Sopenharmony_ci}
1788c2ecf20Sopenharmony_ci
1798c2ecf20Sopenharmony_cistatic const struct of_device_id of_bus_ids[] __initconst = {
1808c2ecf20Sopenharmony_ci	{ .compatible = "simple-bus", },
1818c2ecf20Sopenharmony_ci	{},
1828c2ecf20Sopenharmony_ci};
1838c2ecf20Sopenharmony_ci
1848c2ecf20Sopenharmony_cistatic int __init declare_of_platform_devices(void)
1858c2ecf20Sopenharmony_ci{
1868c2ecf20Sopenharmony_ci	of_platform_bus_probe(NULL, of_bus_ids, NULL);
1878c2ecf20Sopenharmony_ci
1888c2ecf20Sopenharmony_ci	return 0;
1898c2ecf20Sopenharmony_ci}
1908c2ecf20Sopenharmony_cimachine_device_initcall(km82xx, declare_of_platform_devices);
1918c2ecf20Sopenharmony_ci
1928c2ecf20Sopenharmony_ci/*
1938c2ecf20Sopenharmony_ci * Called very early, device-tree isn't unflattened
1948c2ecf20Sopenharmony_ci */
1958c2ecf20Sopenharmony_cistatic int __init km82xx_probe(void)
1968c2ecf20Sopenharmony_ci{
1978c2ecf20Sopenharmony_ci	return of_machine_is_compatible("keymile,km82xx");
1988c2ecf20Sopenharmony_ci}
1998c2ecf20Sopenharmony_ci
2008c2ecf20Sopenharmony_cidefine_machine(km82xx)
2018c2ecf20Sopenharmony_ci{
2028c2ecf20Sopenharmony_ci	.name = "Keymile km82xx",
2038c2ecf20Sopenharmony_ci	.probe = km82xx_probe,
2048c2ecf20Sopenharmony_ci	.setup_arch = km82xx_setup_arch,
2058c2ecf20Sopenharmony_ci	.init_IRQ = km82xx_pic_init,
2068c2ecf20Sopenharmony_ci	.get_irq = cpm2_get_irq,
2078c2ecf20Sopenharmony_ci	.calibrate_decr = generic_calibrate_decr,
2088c2ecf20Sopenharmony_ci	.restart = pq2_restart,
2098c2ecf20Sopenharmony_ci	.progress = udbg_progress,
2108c2ecf20Sopenharmony_ci};
211