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