18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-or-later
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * MPC8272 ADS board support
48c2ecf20Sopenharmony_ci *
58c2ecf20Sopenharmony_ci * Copyright 2007 Freescale Semiconductor, Inc.
68c2ecf20Sopenharmony_ci * Author: Scott Wood <scottwood@freescale.com>
78c2ecf20Sopenharmony_ci *
88c2ecf20Sopenharmony_ci * Based on code by Vitaly Bordug <vbordug@ru.mvista.com>
98c2ecf20Sopenharmony_ci * Copyright (c) 2006 MontaVista Software, Inc.
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_address.h>
168c2ecf20Sopenharmony_ci#include <linux/of_fdt.h>
178c2ecf20Sopenharmony_ci#include <linux/of_platform.h>
188c2ecf20Sopenharmony_ci#include <linux/io.h>
198c2ecf20Sopenharmony_ci
208c2ecf20Sopenharmony_ci#include <asm/cpm2.h>
218c2ecf20Sopenharmony_ci#include <asm/udbg.h>
228c2ecf20Sopenharmony_ci#include <asm/machdep.h>
238c2ecf20Sopenharmony_ci#include <asm/time.h>
248c2ecf20Sopenharmony_ci
258c2ecf20Sopenharmony_ci#include <platforms/82xx/pq2.h>
268c2ecf20Sopenharmony_ci
278c2ecf20Sopenharmony_ci#include <sysdev/fsl_soc.h>
288c2ecf20Sopenharmony_ci#include <sysdev/cpm2_pic.h>
298c2ecf20Sopenharmony_ci
308c2ecf20Sopenharmony_ci#include "pq2.h"
318c2ecf20Sopenharmony_ci
328c2ecf20Sopenharmony_cistatic void __init mpc8272_ads_pic_init(void)
338c2ecf20Sopenharmony_ci{
348c2ecf20Sopenharmony_ci	struct device_node *np = of_find_compatible_node(NULL, NULL,
358c2ecf20Sopenharmony_ci	                                                 "fsl,cpm2-pic");
368c2ecf20Sopenharmony_ci	if (!np) {
378c2ecf20Sopenharmony_ci		printk(KERN_ERR "PIC init: can not find fsl,cpm2-pic node\n");
388c2ecf20Sopenharmony_ci		return;
398c2ecf20Sopenharmony_ci	}
408c2ecf20Sopenharmony_ci
418c2ecf20Sopenharmony_ci	cpm2_pic_init(np);
428c2ecf20Sopenharmony_ci	of_node_put(np);
438c2ecf20Sopenharmony_ci
448c2ecf20Sopenharmony_ci	/* Initialize stuff for the 82xx CPLD IC and install demux  */
458c2ecf20Sopenharmony_ci	pq2ads_pci_init_irq();
468c2ecf20Sopenharmony_ci}
478c2ecf20Sopenharmony_ci
488c2ecf20Sopenharmony_cistruct cpm_pin {
498c2ecf20Sopenharmony_ci	int port, pin, flags;
508c2ecf20Sopenharmony_ci};
518c2ecf20Sopenharmony_ci
528c2ecf20Sopenharmony_cistatic struct cpm_pin mpc8272_ads_pins[] = {
538c2ecf20Sopenharmony_ci	/* SCC1 */
548c2ecf20Sopenharmony_ci	{3, 30, CPM_PIN_OUTPUT | CPM_PIN_SECONDARY},
558c2ecf20Sopenharmony_ci	{3, 31, CPM_PIN_INPUT | CPM_PIN_PRIMARY},
568c2ecf20Sopenharmony_ci
578c2ecf20Sopenharmony_ci	/* SCC4 */
588c2ecf20Sopenharmony_ci	{3, 21, CPM_PIN_OUTPUT | CPM_PIN_PRIMARY},
598c2ecf20Sopenharmony_ci	{3, 22, CPM_PIN_INPUT | CPM_PIN_PRIMARY},
608c2ecf20Sopenharmony_ci
618c2ecf20Sopenharmony_ci	/* FCC1 */
628c2ecf20Sopenharmony_ci	{0, 14, CPM_PIN_INPUT | CPM_PIN_PRIMARY},
638c2ecf20Sopenharmony_ci	{0, 15, CPM_PIN_INPUT | CPM_PIN_PRIMARY},
648c2ecf20Sopenharmony_ci	{0, 16, CPM_PIN_INPUT | CPM_PIN_PRIMARY},
658c2ecf20Sopenharmony_ci	{0, 17, CPM_PIN_INPUT | CPM_PIN_PRIMARY},
668c2ecf20Sopenharmony_ci	{0, 18, CPM_PIN_OUTPUT | CPM_PIN_PRIMARY},
678c2ecf20Sopenharmony_ci	{0, 19, CPM_PIN_OUTPUT | CPM_PIN_PRIMARY},
688c2ecf20Sopenharmony_ci	{0, 20, CPM_PIN_OUTPUT | CPM_PIN_PRIMARY},
698c2ecf20Sopenharmony_ci	{0, 21, CPM_PIN_OUTPUT | CPM_PIN_PRIMARY},
708c2ecf20Sopenharmony_ci	{0, 26, CPM_PIN_INPUT | CPM_PIN_SECONDARY},
718c2ecf20Sopenharmony_ci	{0, 27, CPM_PIN_INPUT | CPM_PIN_SECONDARY},
728c2ecf20Sopenharmony_ci	{0, 28, CPM_PIN_OUTPUT | CPM_PIN_SECONDARY},
738c2ecf20Sopenharmony_ci	{0, 29, CPM_PIN_OUTPUT | CPM_PIN_SECONDARY},
748c2ecf20Sopenharmony_ci	{0, 30, CPM_PIN_INPUT | CPM_PIN_SECONDARY},
758c2ecf20Sopenharmony_ci	{0, 31, CPM_PIN_INPUT | CPM_PIN_SECONDARY},
768c2ecf20Sopenharmony_ci	{2, 21, CPM_PIN_INPUT | CPM_PIN_PRIMARY},
778c2ecf20Sopenharmony_ci	{2, 22, CPM_PIN_INPUT | CPM_PIN_PRIMARY},
788c2ecf20Sopenharmony_ci
798c2ecf20Sopenharmony_ci	/* FCC2 */
808c2ecf20Sopenharmony_ci	{1, 18, CPM_PIN_INPUT | CPM_PIN_PRIMARY},
818c2ecf20Sopenharmony_ci	{1, 19, CPM_PIN_INPUT | CPM_PIN_PRIMARY},
828c2ecf20Sopenharmony_ci	{1, 20, CPM_PIN_INPUT | CPM_PIN_PRIMARY},
838c2ecf20Sopenharmony_ci	{1, 21, CPM_PIN_INPUT | CPM_PIN_PRIMARY},
848c2ecf20Sopenharmony_ci	{1, 22, CPM_PIN_OUTPUT | CPM_PIN_PRIMARY},
858c2ecf20Sopenharmony_ci	{1, 23, CPM_PIN_OUTPUT | CPM_PIN_PRIMARY},
868c2ecf20Sopenharmony_ci	{1, 24, CPM_PIN_OUTPUT | CPM_PIN_PRIMARY},
878c2ecf20Sopenharmony_ci	{1, 25, CPM_PIN_OUTPUT | CPM_PIN_PRIMARY},
888c2ecf20Sopenharmony_ci	{1, 26, CPM_PIN_INPUT | CPM_PIN_PRIMARY},
898c2ecf20Sopenharmony_ci	{1, 27, CPM_PIN_INPUT | CPM_PIN_PRIMARY},
908c2ecf20Sopenharmony_ci	{1, 28, CPM_PIN_INPUT | CPM_PIN_PRIMARY},
918c2ecf20Sopenharmony_ci	{1, 29, CPM_PIN_OUTPUT | CPM_PIN_SECONDARY},
928c2ecf20Sopenharmony_ci	{1, 30, CPM_PIN_INPUT | CPM_PIN_PRIMARY},
938c2ecf20Sopenharmony_ci	{1, 31, CPM_PIN_OUTPUT | CPM_PIN_PRIMARY},
948c2ecf20Sopenharmony_ci	{2, 16, CPM_PIN_INPUT | CPM_PIN_PRIMARY},
958c2ecf20Sopenharmony_ci	{2, 17, CPM_PIN_INPUT | CPM_PIN_PRIMARY},
968c2ecf20Sopenharmony_ci
978c2ecf20Sopenharmony_ci	/* I2C */
988c2ecf20Sopenharmony_ci	{3, 14, CPM_PIN_INPUT | CPM_PIN_SECONDARY | CPM_PIN_OPENDRAIN},
998c2ecf20Sopenharmony_ci	{3, 15, CPM_PIN_INPUT | CPM_PIN_SECONDARY | CPM_PIN_OPENDRAIN},
1008c2ecf20Sopenharmony_ci
1018c2ecf20Sopenharmony_ci	/* USB */
1028c2ecf20Sopenharmony_ci	{2, 10, CPM_PIN_INPUT | CPM_PIN_PRIMARY},
1038c2ecf20Sopenharmony_ci	{2, 11, CPM_PIN_INPUT | CPM_PIN_PRIMARY},
1048c2ecf20Sopenharmony_ci	{2, 20, CPM_PIN_OUTPUT | CPM_PIN_PRIMARY},
1058c2ecf20Sopenharmony_ci	{2, 24, CPM_PIN_INPUT | CPM_PIN_PRIMARY},
1068c2ecf20Sopenharmony_ci	{3, 23, CPM_PIN_OUTPUT | CPM_PIN_PRIMARY},
1078c2ecf20Sopenharmony_ci	{3, 24, CPM_PIN_OUTPUT | CPM_PIN_PRIMARY},
1088c2ecf20Sopenharmony_ci	{3, 25, CPM_PIN_INPUT | CPM_PIN_PRIMARY},
1098c2ecf20Sopenharmony_ci};
1108c2ecf20Sopenharmony_ci
1118c2ecf20Sopenharmony_cistatic void __init init_ioports(void)
1128c2ecf20Sopenharmony_ci{
1138c2ecf20Sopenharmony_ci	int i;
1148c2ecf20Sopenharmony_ci
1158c2ecf20Sopenharmony_ci	for (i = 0; i < ARRAY_SIZE(mpc8272_ads_pins); i++) {
1168c2ecf20Sopenharmony_ci		struct cpm_pin *pin = &mpc8272_ads_pins[i];
1178c2ecf20Sopenharmony_ci		cpm2_set_pin(pin->port, pin->pin, pin->flags);
1188c2ecf20Sopenharmony_ci	}
1198c2ecf20Sopenharmony_ci
1208c2ecf20Sopenharmony_ci	cpm2_clk_setup(CPM_CLK_SCC1, CPM_BRG1, CPM_CLK_RX);
1218c2ecf20Sopenharmony_ci	cpm2_clk_setup(CPM_CLK_SCC1, CPM_BRG1, CPM_CLK_TX);
1228c2ecf20Sopenharmony_ci	cpm2_clk_setup(CPM_CLK_SCC3, CPM_CLK8, CPM_CLK_RX);
1238c2ecf20Sopenharmony_ci	cpm2_clk_setup(CPM_CLK_SCC3, CPM_CLK8, CPM_CLK_TX);
1248c2ecf20Sopenharmony_ci	cpm2_clk_setup(CPM_CLK_SCC4, CPM_BRG4, CPM_CLK_RX);
1258c2ecf20Sopenharmony_ci	cpm2_clk_setup(CPM_CLK_SCC4, CPM_BRG4, CPM_CLK_TX);
1268c2ecf20Sopenharmony_ci	cpm2_clk_setup(CPM_CLK_FCC1, CPM_CLK11, CPM_CLK_RX);
1278c2ecf20Sopenharmony_ci	cpm2_clk_setup(CPM_CLK_FCC1, CPM_CLK10, CPM_CLK_TX);
1288c2ecf20Sopenharmony_ci	cpm2_clk_setup(CPM_CLK_FCC2, CPM_CLK15, CPM_CLK_RX);
1298c2ecf20Sopenharmony_ci	cpm2_clk_setup(CPM_CLK_FCC2, CPM_CLK16, CPM_CLK_TX);
1308c2ecf20Sopenharmony_ci}
1318c2ecf20Sopenharmony_ci
1328c2ecf20Sopenharmony_cistatic void __init mpc8272_ads_setup_arch(void)
1338c2ecf20Sopenharmony_ci{
1348c2ecf20Sopenharmony_ci	struct device_node *np;
1358c2ecf20Sopenharmony_ci	__be32 __iomem *bcsr;
1368c2ecf20Sopenharmony_ci
1378c2ecf20Sopenharmony_ci	if (ppc_md.progress)
1388c2ecf20Sopenharmony_ci		ppc_md.progress("mpc8272_ads_setup_arch()", 0);
1398c2ecf20Sopenharmony_ci
1408c2ecf20Sopenharmony_ci	cpm2_reset();
1418c2ecf20Sopenharmony_ci
1428c2ecf20Sopenharmony_ci	np = of_find_compatible_node(NULL, NULL, "fsl,mpc8272ads-bcsr");
1438c2ecf20Sopenharmony_ci	if (!np) {
1448c2ecf20Sopenharmony_ci		printk(KERN_ERR "No bcsr in device tree\n");
1458c2ecf20Sopenharmony_ci		return;
1468c2ecf20Sopenharmony_ci	}
1478c2ecf20Sopenharmony_ci
1488c2ecf20Sopenharmony_ci	bcsr = of_iomap(np, 0);
1498c2ecf20Sopenharmony_ci	of_node_put(np);
1508c2ecf20Sopenharmony_ci	if (!bcsr) {
1518c2ecf20Sopenharmony_ci		printk(KERN_ERR "Cannot map BCSR registers\n");
1528c2ecf20Sopenharmony_ci		return;
1538c2ecf20Sopenharmony_ci	}
1548c2ecf20Sopenharmony_ci
1558c2ecf20Sopenharmony_ci#define BCSR1_FETHIEN		0x08000000
1568c2ecf20Sopenharmony_ci#define BCSR1_FETH_RST		0x04000000
1578c2ecf20Sopenharmony_ci#define BCSR1_RS232_EN1		0x02000000
1588c2ecf20Sopenharmony_ci#define BCSR1_RS232_EN2		0x01000000
1598c2ecf20Sopenharmony_ci#define BCSR3_USB_nEN		0x80000000
1608c2ecf20Sopenharmony_ci#define BCSR3_FETHIEN2		0x10000000
1618c2ecf20Sopenharmony_ci#define BCSR3_FETH2_RST		0x08000000
1628c2ecf20Sopenharmony_ci
1638c2ecf20Sopenharmony_ci	clrbits32(&bcsr[1], BCSR1_RS232_EN1 | BCSR1_RS232_EN2 | BCSR1_FETHIEN);
1648c2ecf20Sopenharmony_ci	setbits32(&bcsr[1], BCSR1_FETH_RST);
1658c2ecf20Sopenharmony_ci
1668c2ecf20Sopenharmony_ci	clrbits32(&bcsr[3], BCSR3_FETHIEN2);
1678c2ecf20Sopenharmony_ci	setbits32(&bcsr[3], BCSR3_FETH2_RST);
1688c2ecf20Sopenharmony_ci
1698c2ecf20Sopenharmony_ci	clrbits32(&bcsr[3], BCSR3_USB_nEN);
1708c2ecf20Sopenharmony_ci
1718c2ecf20Sopenharmony_ci	iounmap(bcsr);
1728c2ecf20Sopenharmony_ci
1738c2ecf20Sopenharmony_ci	init_ioports();
1748c2ecf20Sopenharmony_ci	pq2_init_pci();
1758c2ecf20Sopenharmony_ci
1768c2ecf20Sopenharmony_ci	if (ppc_md.progress)
1778c2ecf20Sopenharmony_ci		ppc_md.progress("mpc8272_ads_setup_arch(), finish", 0);
1788c2ecf20Sopenharmony_ci}
1798c2ecf20Sopenharmony_ci
1808c2ecf20Sopenharmony_cistatic const struct of_device_id of_bus_ids[] __initconst = {
1818c2ecf20Sopenharmony_ci	{ .name = "soc", },
1828c2ecf20Sopenharmony_ci	{ .name = "cpm", },
1838c2ecf20Sopenharmony_ci	{ .name = "localbus", },
1848c2ecf20Sopenharmony_ci	{},
1858c2ecf20Sopenharmony_ci};
1868c2ecf20Sopenharmony_ci
1878c2ecf20Sopenharmony_cistatic int __init declare_of_platform_devices(void)
1888c2ecf20Sopenharmony_ci{
1898c2ecf20Sopenharmony_ci	/* Publish the QE devices */
1908c2ecf20Sopenharmony_ci	of_platform_bus_probe(NULL, of_bus_ids, NULL);
1918c2ecf20Sopenharmony_ci	return 0;
1928c2ecf20Sopenharmony_ci}
1938c2ecf20Sopenharmony_cimachine_device_initcall(mpc8272_ads, declare_of_platform_devices);
1948c2ecf20Sopenharmony_ci
1958c2ecf20Sopenharmony_ci/*
1968c2ecf20Sopenharmony_ci * Called very early, device-tree isn't unflattened
1978c2ecf20Sopenharmony_ci */
1988c2ecf20Sopenharmony_cistatic int __init mpc8272_ads_probe(void)
1998c2ecf20Sopenharmony_ci{
2008c2ecf20Sopenharmony_ci	return of_machine_is_compatible("fsl,mpc8272ads");
2018c2ecf20Sopenharmony_ci}
2028c2ecf20Sopenharmony_ci
2038c2ecf20Sopenharmony_cidefine_machine(mpc8272_ads)
2048c2ecf20Sopenharmony_ci{
2058c2ecf20Sopenharmony_ci	.name = "Freescale MPC8272 ADS",
2068c2ecf20Sopenharmony_ci	.probe = mpc8272_ads_probe,
2078c2ecf20Sopenharmony_ci	.setup_arch = mpc8272_ads_setup_arch,
2088c2ecf20Sopenharmony_ci	.init_IRQ = mpc8272_ads_pic_init,
2098c2ecf20Sopenharmony_ci	.get_irq = cpm2_get_irq,
2108c2ecf20Sopenharmony_ci	.calibrate_decr = generic_calibrate_decr,
2118c2ecf20Sopenharmony_ci	.restart = pq2_restart,
2128c2ecf20Sopenharmony_ci	.progress = udbg_progress,
2138c2ecf20Sopenharmony_ci};
214