18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-only 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * PQ2FADS board support 48c2ecf20Sopenharmony_ci * 58c2ecf20Sopenharmony_ci * Copyright 2007 Freescale Semiconductor, Inc. 68c2ecf20Sopenharmony_ci * Author: Scott Wood <scottwood@freescale.com> 78c2ecf20Sopenharmony_ci * 88c2ecf20Sopenharmony_ci * Loosely based on mp82xx ADS support 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 198c2ecf20Sopenharmony_ci#include <asm/io.h> 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 <sysdev/fsl_soc.h> 268c2ecf20Sopenharmony_ci#include <sysdev/cpm2_pic.h> 278c2ecf20Sopenharmony_ci 288c2ecf20Sopenharmony_ci#include "pq2ads.h" 298c2ecf20Sopenharmony_ci#include "pq2.h" 308c2ecf20Sopenharmony_ci 318c2ecf20Sopenharmony_cistatic void __init pq2fads_pic_init(void) 328c2ecf20Sopenharmony_ci{ 338c2ecf20Sopenharmony_ci struct device_node *np = of_find_compatible_node(NULL, NULL, "fsl,cpm2-pic"); 348c2ecf20Sopenharmony_ci if (!np) { 358c2ecf20Sopenharmony_ci printk(KERN_ERR "PIC init: can not find fsl,cpm2-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 /* Initialize stuff for the 82xx CPLD IC and install demux */ 438c2ecf20Sopenharmony_ci pq2ads_pci_init_irq(); 448c2ecf20Sopenharmony_ci} 458c2ecf20Sopenharmony_ci 468c2ecf20Sopenharmony_cistruct cpm_pin { 478c2ecf20Sopenharmony_ci int port, pin, flags; 488c2ecf20Sopenharmony_ci}; 498c2ecf20Sopenharmony_ci 508c2ecf20Sopenharmony_cistatic struct cpm_pin pq2fads_pins[] = { 518c2ecf20Sopenharmony_ci /* SCC1 */ 528c2ecf20Sopenharmony_ci {3, 30, CPM_PIN_OUTPUT | CPM_PIN_SECONDARY}, 538c2ecf20Sopenharmony_ci {3, 31, CPM_PIN_INPUT | CPM_PIN_PRIMARY}, 548c2ecf20Sopenharmony_ci 558c2ecf20Sopenharmony_ci /* SCC2 */ 568c2ecf20Sopenharmony_ci {3, 27, CPM_PIN_OUTPUT | CPM_PIN_PRIMARY}, 578c2ecf20Sopenharmony_ci {3, 28, CPM_PIN_INPUT | CPM_PIN_PRIMARY}, 588c2ecf20Sopenharmony_ci 598c2ecf20Sopenharmony_ci /* FCC2 */ 608c2ecf20Sopenharmony_ci {1, 18, CPM_PIN_INPUT | CPM_PIN_PRIMARY}, 618c2ecf20Sopenharmony_ci {1, 19, CPM_PIN_INPUT | CPM_PIN_PRIMARY}, 628c2ecf20Sopenharmony_ci {1, 20, CPM_PIN_INPUT | CPM_PIN_PRIMARY}, 638c2ecf20Sopenharmony_ci {1, 21, CPM_PIN_INPUT | CPM_PIN_PRIMARY}, 648c2ecf20Sopenharmony_ci {1, 22, CPM_PIN_OUTPUT | CPM_PIN_PRIMARY}, 658c2ecf20Sopenharmony_ci {1, 23, CPM_PIN_OUTPUT | CPM_PIN_PRIMARY}, 668c2ecf20Sopenharmony_ci {1, 24, CPM_PIN_OUTPUT | CPM_PIN_PRIMARY}, 678c2ecf20Sopenharmony_ci {1, 25, CPM_PIN_OUTPUT | CPM_PIN_PRIMARY}, 688c2ecf20Sopenharmony_ci {1, 26, CPM_PIN_INPUT | CPM_PIN_PRIMARY}, 698c2ecf20Sopenharmony_ci {1, 27, CPM_PIN_INPUT | CPM_PIN_PRIMARY}, 708c2ecf20Sopenharmony_ci {1, 28, CPM_PIN_INPUT | CPM_PIN_PRIMARY}, 718c2ecf20Sopenharmony_ci {1, 29, CPM_PIN_OUTPUT | CPM_PIN_SECONDARY}, 728c2ecf20Sopenharmony_ci {1, 30, CPM_PIN_INPUT | CPM_PIN_PRIMARY}, 738c2ecf20Sopenharmony_ci {1, 31, CPM_PIN_OUTPUT | CPM_PIN_PRIMARY}, 748c2ecf20Sopenharmony_ci {2, 18, CPM_PIN_INPUT | CPM_PIN_PRIMARY}, 758c2ecf20Sopenharmony_ci {2, 19, CPM_PIN_INPUT | CPM_PIN_PRIMARY}, 768c2ecf20Sopenharmony_ci 778c2ecf20Sopenharmony_ci /* FCC3 */ 788c2ecf20Sopenharmony_ci {1, 4, CPM_PIN_OUTPUT | CPM_PIN_PRIMARY}, 798c2ecf20Sopenharmony_ci {1, 5, CPM_PIN_OUTPUT | CPM_PIN_PRIMARY}, 808c2ecf20Sopenharmony_ci {1, 6, CPM_PIN_OUTPUT | CPM_PIN_PRIMARY}, 818c2ecf20Sopenharmony_ci {1, 7, CPM_PIN_OUTPUT | CPM_PIN_PRIMARY}, 828c2ecf20Sopenharmony_ci {1, 8, CPM_PIN_INPUT | CPM_PIN_PRIMARY}, 838c2ecf20Sopenharmony_ci {1, 9, CPM_PIN_INPUT | CPM_PIN_PRIMARY}, 848c2ecf20Sopenharmony_ci {1, 10, CPM_PIN_INPUT | CPM_PIN_PRIMARY}, 858c2ecf20Sopenharmony_ci {1, 11, CPM_PIN_INPUT | CPM_PIN_PRIMARY}, 868c2ecf20Sopenharmony_ci {1, 12, CPM_PIN_INPUT | CPM_PIN_PRIMARY}, 878c2ecf20Sopenharmony_ci {1, 13, CPM_PIN_INPUT | CPM_PIN_PRIMARY}, 888c2ecf20Sopenharmony_ci {1, 14, CPM_PIN_OUTPUT | CPM_PIN_PRIMARY}, 898c2ecf20Sopenharmony_ci {1, 15, CPM_PIN_OUTPUT | CPM_PIN_PRIMARY}, 908c2ecf20Sopenharmony_ci {1, 16, CPM_PIN_INPUT | CPM_PIN_PRIMARY}, 918c2ecf20Sopenharmony_ci {1, 17, CPM_PIN_INPUT | CPM_PIN_PRIMARY}, 928c2ecf20Sopenharmony_ci {2, 16, CPM_PIN_INPUT | CPM_PIN_PRIMARY}, 938c2ecf20Sopenharmony_ci {2, 17, CPM_PIN_INPUT | CPM_PIN_PRIMARY}, 948c2ecf20Sopenharmony_ci}; 958c2ecf20Sopenharmony_ci 968c2ecf20Sopenharmony_cistatic void __init init_ioports(void) 978c2ecf20Sopenharmony_ci{ 988c2ecf20Sopenharmony_ci int i; 998c2ecf20Sopenharmony_ci 1008c2ecf20Sopenharmony_ci for (i = 0; i < ARRAY_SIZE(pq2fads_pins); i++) { 1018c2ecf20Sopenharmony_ci struct cpm_pin *pin = &pq2fads_pins[i]; 1028c2ecf20Sopenharmony_ci cpm2_set_pin(pin->port, pin->pin, pin->flags); 1038c2ecf20Sopenharmony_ci } 1048c2ecf20Sopenharmony_ci 1058c2ecf20Sopenharmony_ci cpm2_clk_setup(CPM_CLK_SCC1, CPM_BRG1, CPM_CLK_RX); 1068c2ecf20Sopenharmony_ci cpm2_clk_setup(CPM_CLK_SCC1, CPM_BRG1, CPM_CLK_TX); 1078c2ecf20Sopenharmony_ci cpm2_clk_setup(CPM_CLK_SCC2, CPM_BRG2, CPM_CLK_RX); 1088c2ecf20Sopenharmony_ci cpm2_clk_setup(CPM_CLK_SCC2, CPM_BRG2, CPM_CLK_TX); 1098c2ecf20Sopenharmony_ci cpm2_clk_setup(CPM_CLK_FCC2, CPM_CLK13, CPM_CLK_RX); 1108c2ecf20Sopenharmony_ci cpm2_clk_setup(CPM_CLK_FCC2, CPM_CLK14, CPM_CLK_TX); 1118c2ecf20Sopenharmony_ci cpm2_clk_setup(CPM_CLK_FCC3, CPM_CLK15, CPM_CLK_RX); 1128c2ecf20Sopenharmony_ci cpm2_clk_setup(CPM_CLK_FCC3, CPM_CLK16, CPM_CLK_TX); 1138c2ecf20Sopenharmony_ci} 1148c2ecf20Sopenharmony_ci 1158c2ecf20Sopenharmony_cistatic void __init pq2fads_setup_arch(void) 1168c2ecf20Sopenharmony_ci{ 1178c2ecf20Sopenharmony_ci struct device_node *np; 1188c2ecf20Sopenharmony_ci __be32 __iomem *bcsr; 1198c2ecf20Sopenharmony_ci 1208c2ecf20Sopenharmony_ci if (ppc_md.progress) 1218c2ecf20Sopenharmony_ci ppc_md.progress("pq2fads_setup_arch()", 0); 1228c2ecf20Sopenharmony_ci 1238c2ecf20Sopenharmony_ci cpm2_reset(); 1248c2ecf20Sopenharmony_ci 1258c2ecf20Sopenharmony_ci np = of_find_compatible_node(NULL, NULL, "fsl,pq2fads-bcsr"); 1268c2ecf20Sopenharmony_ci if (!np) { 1278c2ecf20Sopenharmony_ci printk(KERN_ERR "No fsl,pq2fads-bcsr in device tree\n"); 1288c2ecf20Sopenharmony_ci return; 1298c2ecf20Sopenharmony_ci } 1308c2ecf20Sopenharmony_ci 1318c2ecf20Sopenharmony_ci bcsr = of_iomap(np, 0); 1328c2ecf20Sopenharmony_ci of_node_put(np); 1338c2ecf20Sopenharmony_ci if (!bcsr) { 1348c2ecf20Sopenharmony_ci printk(KERN_ERR "Cannot map BCSR registers\n"); 1358c2ecf20Sopenharmony_ci return; 1368c2ecf20Sopenharmony_ci } 1378c2ecf20Sopenharmony_ci 1388c2ecf20Sopenharmony_ci /* Enable the serial and ethernet ports */ 1398c2ecf20Sopenharmony_ci 1408c2ecf20Sopenharmony_ci clrbits32(&bcsr[1], BCSR1_RS232_EN1 | BCSR1_RS232_EN2 | BCSR1_FETHIEN); 1418c2ecf20Sopenharmony_ci setbits32(&bcsr[1], BCSR1_FETH_RST); 1428c2ecf20Sopenharmony_ci 1438c2ecf20Sopenharmony_ci clrbits32(&bcsr[3], BCSR3_FETHIEN2); 1448c2ecf20Sopenharmony_ci setbits32(&bcsr[3], BCSR3_FETH2_RST); 1458c2ecf20Sopenharmony_ci 1468c2ecf20Sopenharmony_ci iounmap(bcsr); 1478c2ecf20Sopenharmony_ci 1488c2ecf20Sopenharmony_ci init_ioports(); 1498c2ecf20Sopenharmony_ci 1508c2ecf20Sopenharmony_ci /* Enable external IRQs */ 1518c2ecf20Sopenharmony_ci clrbits32(&cpm2_immr->im_siu_conf.siu_82xx.sc_siumcr, 0x0c000000); 1528c2ecf20Sopenharmony_ci 1538c2ecf20Sopenharmony_ci pq2_init_pci(); 1548c2ecf20Sopenharmony_ci 1558c2ecf20Sopenharmony_ci if (ppc_md.progress) 1568c2ecf20Sopenharmony_ci ppc_md.progress("pq2fads_setup_arch(), finish", 0); 1578c2ecf20Sopenharmony_ci} 1588c2ecf20Sopenharmony_ci 1598c2ecf20Sopenharmony_ci/* 1608c2ecf20Sopenharmony_ci * Called very early, device-tree isn't unflattened 1618c2ecf20Sopenharmony_ci */ 1628c2ecf20Sopenharmony_cistatic int __init pq2fads_probe(void) 1638c2ecf20Sopenharmony_ci{ 1648c2ecf20Sopenharmony_ci return of_machine_is_compatible("fsl,pq2fads"); 1658c2ecf20Sopenharmony_ci} 1668c2ecf20Sopenharmony_ci 1678c2ecf20Sopenharmony_cistatic const struct of_device_id of_bus_ids[] __initconst = { 1688c2ecf20Sopenharmony_ci { .name = "soc", }, 1698c2ecf20Sopenharmony_ci { .name = "cpm", }, 1708c2ecf20Sopenharmony_ci { .name = "localbus", }, 1718c2ecf20Sopenharmony_ci {}, 1728c2ecf20Sopenharmony_ci}; 1738c2ecf20Sopenharmony_ci 1748c2ecf20Sopenharmony_cistatic int __init declare_of_platform_devices(void) 1758c2ecf20Sopenharmony_ci{ 1768c2ecf20Sopenharmony_ci /* Publish the QE devices */ 1778c2ecf20Sopenharmony_ci of_platform_bus_probe(NULL, of_bus_ids, NULL); 1788c2ecf20Sopenharmony_ci return 0; 1798c2ecf20Sopenharmony_ci} 1808c2ecf20Sopenharmony_cimachine_device_initcall(pq2fads, declare_of_platform_devices); 1818c2ecf20Sopenharmony_ci 1828c2ecf20Sopenharmony_cidefine_machine(pq2fads) 1838c2ecf20Sopenharmony_ci{ 1848c2ecf20Sopenharmony_ci .name = "Freescale PQ2FADS", 1858c2ecf20Sopenharmony_ci .probe = pq2fads_probe, 1868c2ecf20Sopenharmony_ci .setup_arch = pq2fads_setup_arch, 1878c2ecf20Sopenharmony_ci .init_IRQ = pq2fads_pic_init, 1888c2ecf20Sopenharmony_ci .get_irq = cpm2_get_irq, 1898c2ecf20Sopenharmony_ci .calibrate_decr = generic_calibrate_decr, 1908c2ecf20Sopenharmony_ci .restart = pq2_restart, 1918c2ecf20Sopenharmony_ci .progress = udbg_progress, 1928c2ecf20Sopenharmony_ci}; 193