Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-or-later
0002 /*
0003  * FSL SoC setup code
0004  *
0005  * Maintained by Kumar Gala (see MAINTAINERS for contact information)
0006  *
0007  * 2006 (c) MontaVista Software, Inc.
0008  * Vitaly Bordug <vbordug@ru.mvista.com>
0009  */
0010 
0011 #include <linux/stddef.h>
0012 #include <linux/kernel.h>
0013 #include <linux/init.h>
0014 #include <linux/errno.h>
0015 #include <linux/major.h>
0016 #include <linux/delay.h>
0017 #include <linux/irq.h>
0018 #include <linux/export.h>
0019 #include <linux/device.h>
0020 #include <linux/platform_device.h>
0021 #include <linux/of.h>
0022 #include <linux/of_platform.h>
0023 #include <linux/phy.h>
0024 #include <linux/spi/spi.h>
0025 #include <linux/fsl_devices.h>
0026 #include <linux/fs_enet_pd.h>
0027 #include <linux/fs_uart_pd.h>
0028 #include <linux/reboot.h>
0029 
0030 #include <linux/atomic.h>
0031 #include <asm/io.h>
0032 #include <asm/irq.h>
0033 #include <asm/time.h>
0034 #include <asm/machdep.h>
0035 #include <sysdev/fsl_soc.h>
0036 #include <mm/mmu_decl.h>
0037 #include <asm/cpm2.h>
0038 #include <asm/fsl_hcalls.h> /* For the Freescale hypervisor */
0039 
0040 extern void init_fcc_ioports(struct fs_platform_info*);
0041 extern void init_fec_ioports(struct fs_platform_info*);
0042 extern void init_smc_ioports(struct fs_uart_platform_info*);
0043 static phys_addr_t immrbase = -1;
0044 
0045 phys_addr_t get_immrbase(void)
0046 {
0047     struct device_node *soc;
0048 
0049     if (immrbase != -1)
0050         return immrbase;
0051 
0052     soc = of_find_node_by_type(NULL, "soc");
0053     if (soc) {
0054         int size;
0055         u32 naddr;
0056         const __be32 *prop = of_get_property(soc, "#address-cells", &size);
0057 
0058         if (prop && size == 4)
0059             naddr = be32_to_cpup(prop);
0060         else
0061             naddr = 2;
0062 
0063         prop = of_get_property(soc, "ranges", &size);
0064         if (prop)
0065             immrbase = of_translate_address(soc, prop + naddr);
0066 
0067         of_node_put(soc);
0068     }
0069 
0070     return immrbase;
0071 }
0072 
0073 EXPORT_SYMBOL(get_immrbase);
0074 
0075 u32 fsl_get_sys_freq(void)
0076 {
0077     static u32 sysfreq = -1;
0078     struct device_node *soc;
0079 
0080     if (sysfreq != -1)
0081         return sysfreq;
0082 
0083     soc = of_find_node_by_type(NULL, "soc");
0084     if (!soc)
0085         return -1;
0086 
0087     of_property_read_u32(soc, "clock-frequency", &sysfreq);
0088     if (sysfreq == -1 || !sysfreq)
0089         of_property_read_u32(soc, "bus-frequency", &sysfreq);
0090 
0091     of_node_put(soc);
0092     return sysfreq;
0093 }
0094 EXPORT_SYMBOL(fsl_get_sys_freq);
0095 
0096 #if defined(CONFIG_CPM) || defined(CONFIG_QUICC_ENGINE)
0097 
0098 u32 get_brgfreq(void)
0099 {
0100     static u32 brgfreq = -1;
0101     struct device_node *node;
0102 
0103     if (brgfreq != -1)
0104         return brgfreq;
0105 
0106     node = of_find_compatible_node(NULL, NULL, "fsl,cpm-brg");
0107     if (node) {
0108         of_property_read_u32(node, "clock-frequency", &brgfreq);
0109         of_node_put(node);
0110         return brgfreq;
0111     }
0112 
0113     /* Legacy device binding -- will go away when no users are left. */
0114     node = of_find_node_by_type(NULL, "cpm");
0115     if (!node)
0116         node = of_find_compatible_node(NULL, NULL, "fsl,qe");
0117     if (!node)
0118         node = of_find_node_by_type(NULL, "qe");
0119 
0120     if (node) {
0121         of_property_read_u32(node, "brg-frequency", &brgfreq);
0122         if (brgfreq == -1 || !brgfreq)
0123             if (!of_property_read_u32(node, "bus-frequency",
0124                           &brgfreq))
0125                 brgfreq /= 2;
0126         of_node_put(node);
0127     }
0128 
0129     return brgfreq;
0130 }
0131 
0132 EXPORT_SYMBOL(get_brgfreq);
0133 
0134 u32 get_baudrate(void)
0135 {
0136     static u32 fs_baudrate = -1;
0137     struct device_node *node;
0138 
0139     if (fs_baudrate != -1)
0140         return fs_baudrate;
0141 
0142     node = of_find_node_by_type(NULL, "serial");
0143     if (node) {
0144         of_property_read_u32(node, "current-speed", &fs_baudrate);
0145         of_node_put(node);
0146     }
0147 
0148     return fs_baudrate;
0149 }
0150 
0151 EXPORT_SYMBOL(get_baudrate);
0152 #endif /* CONFIG_CPM2 */
0153 
0154 #if defined(CONFIG_FSL_SOC_BOOKE) || defined(CONFIG_PPC_86xx)
0155 static __be32 __iomem *rstcr;
0156 
0157 static int fsl_rstcr_restart(struct notifier_block *this,
0158                  unsigned long mode, void *cmd)
0159 {
0160     local_irq_disable();
0161     /* set reset control register */
0162     out_be32(rstcr, 0x2);   /* HRESET_REQ */
0163 
0164     return NOTIFY_DONE;
0165 }
0166 
0167 static int __init setup_rstcr(void)
0168 {
0169     struct device_node *np;
0170 
0171     static struct notifier_block restart_handler = {
0172         .notifier_call = fsl_rstcr_restart,
0173         .priority = 128,
0174     };
0175 
0176     for_each_node_by_name(np, "global-utilities") {
0177         if ((of_get_property(np, "fsl,has-rstcr", NULL))) {
0178             rstcr = of_iomap(np, 0) + 0xb0;
0179             if (!rstcr) {
0180                 printk (KERN_ERR "Error: reset control "
0181                         "register not mapped!\n");
0182             } else {
0183                 register_restart_handler(&restart_handler);
0184             }
0185             break;
0186         }
0187     }
0188 
0189     of_node_put(np);
0190 
0191     return 0;
0192 }
0193 
0194 arch_initcall(setup_rstcr);
0195 
0196 #endif
0197 
0198 #if defined(CONFIG_FB_FSL_DIU) || defined(CONFIG_FB_FSL_DIU_MODULE)
0199 struct platform_diu_data_ops diu_ops;
0200 EXPORT_SYMBOL(diu_ops);
0201 #endif
0202 
0203 #ifdef CONFIG_EPAPR_PARAVIRT
0204 /*
0205  * Restart the current partition
0206  *
0207  * This function should be assigned to the ppc_md.restart function pointer,
0208  * to initiate a partition restart when we're running under the Freescale
0209  * hypervisor.
0210  */
0211 void __noreturn fsl_hv_restart(char *cmd)
0212 {
0213     pr_info("hv restart\n");
0214     fh_partition_restart(-1);
0215     while (1) ;
0216 }
0217 
0218 /*
0219  * Halt the current partition
0220  *
0221  * This function should be assigned to the pm_power_off and ppc_md.halt
0222  * function pointers, to shut down the partition when we're running under
0223  * the Freescale hypervisor.
0224  */
0225 void __noreturn fsl_hv_halt(void)
0226 {
0227     pr_info("hv exit\n");
0228     fh_partition_stop(-1);
0229     while (1) ;
0230 }
0231 #endif