xref: /linux/arch/powerpc/sysdev/fsl_soc.c (revision 701ca3657d5d489add2bedce0c31938e521c7913)
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/phy.h>
23 #include <linux/spi/spi.h>
24 #include <linux/fsl_devices.h>
25 #include <linux/fs_enet_pd.h>
26 #include <linux/fs_uart_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 extern void init_smc_ioports(struct fs_uart_platform_info*);
42 static phys_addr_t immrbase = -1;
43 
44 phys_addr_t get_immrbase(void)
45 {
46 	struct device_node *soc;
47 
48 	if (immrbase != -1)
49 		return immrbase;
50 
51 	soc = of_find_node_by_type(NULL, "soc");
52 	if (soc) {
53 		struct resource res;
54 
55 		if (!of_range_to_resource(soc, 0, &res))
56 			immrbase = res.start;
57 
58 		of_node_put(soc);
59 	}
60 
61 	return immrbase;
62 }
63 
64 EXPORT_SYMBOL(get_immrbase);
65 
66 u32 fsl_get_sys_freq(void)
67 {
68 	static u32 sysfreq = -1;
69 	struct device_node *soc;
70 
71 	if (sysfreq != -1)
72 		return sysfreq;
73 
74 	soc = of_find_node_by_type(NULL, "soc");
75 	if (!soc)
76 		return -1;
77 
78 	of_property_read_u32(soc, "clock-frequency", &sysfreq);
79 	if (sysfreq == -1 || !sysfreq)
80 		of_property_read_u32(soc, "bus-frequency", &sysfreq);
81 
82 	of_node_put(soc);
83 	return sysfreq;
84 }
85 EXPORT_SYMBOL(fsl_get_sys_freq);
86 
87 #if defined(CONFIG_CPM) || defined(CONFIG_QUICC_ENGINE)
88 
89 u32 get_brgfreq(void)
90 {
91 	static u32 brgfreq = -1;
92 	struct device_node *node;
93 
94 	if (brgfreq != -1)
95 		return brgfreq;
96 
97 	node = of_find_compatible_node(NULL, NULL, "fsl,cpm-brg");
98 	if (node) {
99 		of_property_read_u32(node, "clock-frequency", &brgfreq);
100 		of_node_put(node);
101 		return brgfreq;
102 	}
103 
104 	/* Legacy device binding -- will go away when no users are left. */
105 	node = of_find_node_by_type(NULL, "cpm");
106 	if (!node)
107 		node = of_find_compatible_node(NULL, NULL, "fsl,qe");
108 	if (!node)
109 		node = of_find_node_by_type(NULL, "qe");
110 
111 	if (node) {
112 		of_property_read_u32(node, "brg-frequency", &brgfreq);
113 		if (brgfreq == -1 || !brgfreq)
114 			if (!of_property_read_u32(node, "bus-frequency",
115 						  &brgfreq))
116 				brgfreq /= 2;
117 		of_node_put(node);
118 	}
119 
120 	return brgfreq;
121 }
122 
123 EXPORT_SYMBOL(get_brgfreq);
124 
125 u32 get_baudrate(void)
126 {
127 	static u32 fs_baudrate = -1;
128 	struct device_node *node;
129 
130 	if (fs_baudrate != -1)
131 		return fs_baudrate;
132 
133 	node = of_find_node_by_type(NULL, "serial");
134 	if (node) {
135 		of_property_read_u32(node, "current-speed", &fs_baudrate);
136 		of_node_put(node);
137 	}
138 
139 	return fs_baudrate;
140 }
141 
142 EXPORT_SYMBOL(get_baudrate);
143 #endif /* CONFIG_CPM2 */
144 
145 #if defined(CONFIG_FSL_SOC_BOOKE) || defined(CONFIG_PPC_86xx)
146 static __be32 __iomem *rstcr;
147 
148 static int fsl_rstcr_restart(struct notifier_block *this,
149 			     unsigned long mode, void *cmd)
150 {
151 	local_irq_disable();
152 	/* set reset control register */
153 	out_be32(rstcr, 0x2);	/* HRESET_REQ */
154 
155 	return NOTIFY_DONE;
156 }
157 
158 static int __init setup_rstcr(void)
159 {
160 	struct device_node *np;
161 
162 	static struct notifier_block restart_handler = {
163 		.notifier_call = fsl_rstcr_restart,
164 		.priority = 128,
165 	};
166 
167 	for_each_node_by_name(np, "global-utilities") {
168 		if (of_property_read_bool(np, "fsl,has-rstcr")) {
169 			rstcr = of_iomap(np, 0) + 0xb0;
170 			if (!rstcr) {
171 				printk (KERN_ERR "Error: reset control "
172 						"register not mapped!\n");
173 			} else {
174 				register_restart_handler(&restart_handler);
175 			}
176 			break;
177 		}
178 	}
179 
180 	of_node_put(np);
181 
182 	return 0;
183 }
184 
185 arch_initcall(setup_rstcr);
186 
187 #endif
188 
189 #if defined(CONFIG_FB_FSL_DIU) || defined(CONFIG_FB_FSL_DIU_MODULE)
190 struct platform_diu_data_ops diu_ops;
191 EXPORT_SYMBOL(diu_ops);
192 #endif
193 
194 #ifdef CONFIG_EPAPR_PARAVIRT
195 /*
196  * Restart the current partition
197  *
198  * This function should be assigned to the ppc_md.restart function pointer,
199  * to initiate a partition restart when we're running under the Freescale
200  * hypervisor.
201  */
202 void __noreturn fsl_hv_restart(char *cmd)
203 {
204 	pr_info("hv restart\n");
205 	fh_partition_restart(-1);
206 	while (1) ;
207 }
208 
209 /*
210  * Halt the current partition
211  *
212  * This function should be assigned to the pm_power_off and ppc_md.halt
213  * function pointers, to shut down the partition when we're running under
214  * the Freescale hypervisor.
215  */
216 void __noreturn fsl_hv_halt(void)
217 {
218 	pr_info("hv exit\n");
219 	fh_partition_stop(-1);
220 	while (1) ;
221 }
222 #endif
223