^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-or-later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * FSL SoC setup code
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Maintained by Kumar Gala (see MAINTAINERS for contact information)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * 2006 (c) MontaVista Software, Inc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) * Vitaly Bordug <vbordug@ru.mvista.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/stddef.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/errno.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/major.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <linux/delay.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <linux/irq.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <linux/export.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <linux/device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include <linux/platform_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #include <linux/of.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #include <linux/of_platform.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #include <linux/phy.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #include <linux/spi/spi.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #include <linux/fsl_devices.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #include <linux/fs_enet_pd.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) #include <linux/fs_uart_pd.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) #include <linux/reboot.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) #include <linux/atomic.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) #include <asm/io.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) #include <asm/irq.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) #include <asm/time.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) #include <asm/prom.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) #include <asm/machdep.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) #include <sysdev/fsl_soc.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) #include <mm/mmu_decl.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) #include <asm/cpm2.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) #include <asm/fsl_hcalls.h> /* For the Freescale hypervisor */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) extern void init_fcc_ioports(struct fs_platform_info*);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) extern void init_fec_ioports(struct fs_platform_info*);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) extern void init_smc_ioports(struct fs_uart_platform_info*);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) static phys_addr_t immrbase = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) phys_addr_t get_immrbase(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) struct device_node *soc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) if (immrbase != -1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) return immrbase;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) soc = of_find_node_by_type(NULL, "soc");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) if (soc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) int size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) u32 naddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) const __be32 *prop = of_get_property(soc, "#address-cells", &size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) if (prop && size == 4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) naddr = be32_to_cpup(prop);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) naddr = 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) prop = of_get_property(soc, "ranges", &size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) if (prop)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) immrbase = of_translate_address(soc, prop + naddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) of_node_put(soc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) return immrbase;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) EXPORT_SYMBOL(get_immrbase);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) u32 fsl_get_sys_freq(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) static u32 sysfreq = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) struct device_node *soc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) if (sysfreq != -1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) return sysfreq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) soc = of_find_node_by_type(NULL, "soc");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) if (!soc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) of_property_read_u32(soc, "clock-frequency", &sysfreq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) if (sysfreq == -1 || !sysfreq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) of_property_read_u32(soc, "bus-frequency", &sysfreq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) of_node_put(soc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) return sysfreq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) EXPORT_SYMBOL(fsl_get_sys_freq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) #if defined(CONFIG_CPM) || defined(CONFIG_QUICC_ENGINE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) u32 get_brgfreq(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) static u32 brgfreq = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) struct device_node *node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) if (brgfreq != -1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) return brgfreq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) node = of_find_compatible_node(NULL, NULL, "fsl,cpm-brg");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) if (node) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) of_property_read_u32(node, "clock-frequency", &brgfreq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) of_node_put(node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) return brgfreq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) /* Legacy device binding -- will go away when no users are left. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) node = of_find_node_by_type(NULL, "cpm");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) if (!node)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) node = of_find_compatible_node(NULL, NULL, "fsl,qe");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) if (!node)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) node = of_find_node_by_type(NULL, "qe");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) if (node) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) of_property_read_u32(node, "brg-frequency", &brgfreq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) if (brgfreq == -1 || !brgfreq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) if (!of_property_read_u32(node, "bus-frequency",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) &brgfreq))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) brgfreq /= 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) of_node_put(node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) return brgfreq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) EXPORT_SYMBOL(get_brgfreq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) u32 get_baudrate(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) static u32 fs_baudrate = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) struct device_node *node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) if (fs_baudrate != -1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) return fs_baudrate;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) node = of_find_node_by_type(NULL, "serial");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) if (node) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) of_property_read_u32(node, "current-speed", &fs_baudrate);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) of_node_put(node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) return fs_baudrate;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) EXPORT_SYMBOL(get_baudrate);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) #endif /* CONFIG_CPM2 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) #if defined(CONFIG_FSL_SOC_BOOKE) || defined(CONFIG_PPC_86xx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) static __be32 __iomem *rstcr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) static int fsl_rstcr_restart(struct notifier_block *this,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) unsigned long mode, void *cmd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) local_irq_disable();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) /* set reset control register */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) out_be32(rstcr, 0x2); /* HRESET_REQ */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) return NOTIFY_DONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) static int __init setup_rstcr(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) struct device_node *np;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) static struct notifier_block restart_handler = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) .notifier_call = fsl_rstcr_restart,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) .priority = 128,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) for_each_node_by_name(np, "global-utilities") {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) if ((of_get_property(np, "fsl,has-rstcr", NULL))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) rstcr = of_iomap(np, 0) + 0xb0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) if (!rstcr) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) printk (KERN_ERR "Error: reset control "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) "register not mapped!\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) register_restart_handler(&restart_handler);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) of_node_put(np);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) arch_initcall(setup_rstcr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) #if defined(CONFIG_FB_FSL_DIU) || defined(CONFIG_FB_FSL_DIU_MODULE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) struct platform_diu_data_ops diu_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) EXPORT_SYMBOL(diu_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) #ifdef CONFIG_EPAPR_PARAVIRT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) * Restart the current partition
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) * This function should be assigned to the ppc_md.restart function pointer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) * to initiate a partition restart when we're running under the Freescale
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) * hypervisor.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) void __noreturn fsl_hv_restart(char *cmd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) pr_info("hv restart\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) fh_partition_restart(-1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) while (1) ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) * Halt the current partition
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) * This function should be assigned to the pm_power_off and ppc_md.halt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) * function pointers, to shut down the partition when we're running under
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) * the Freescale hypervisor.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) void __noreturn fsl_hv_halt(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) pr_info("hv exit\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) fh_partition_stop(-1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) while (1) ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) #endif