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