xref: /OK3568_Linux_fs/kernel/arch/mips/lantiq/prom.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun // SPDX-License-Identifier: GPL-2.0-only
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun  *
4*4882a593Smuzhiyun  * Copyright (C) 2010 John Crispin <john@phrozen.org>
5*4882a593Smuzhiyun  */
6*4882a593Smuzhiyun 
7*4882a593Smuzhiyun #include <linux/export.h>
8*4882a593Smuzhiyun #include <linux/clk.h>
9*4882a593Smuzhiyun #include <linux/memblock.h>
10*4882a593Smuzhiyun #include <linux/of_fdt.h>
11*4882a593Smuzhiyun 
12*4882a593Smuzhiyun #include <asm/bootinfo.h>
13*4882a593Smuzhiyun #include <asm/time.h>
14*4882a593Smuzhiyun #include <asm/prom.h>
15*4882a593Smuzhiyun 
16*4882a593Smuzhiyun #include <lantiq.h>
17*4882a593Smuzhiyun 
18*4882a593Smuzhiyun #include "prom.h"
19*4882a593Smuzhiyun #include "clk.h"
20*4882a593Smuzhiyun 
21*4882a593Smuzhiyun /* access to the ebu needs to be locked between different drivers */
22*4882a593Smuzhiyun DEFINE_SPINLOCK(ebu_lock);
23*4882a593Smuzhiyun EXPORT_SYMBOL_GPL(ebu_lock);
24*4882a593Smuzhiyun 
25*4882a593Smuzhiyun /*
26*4882a593Smuzhiyun  * This is needed by the VPE loader code, just set it to 0 and assume
27*4882a593Smuzhiyun  * that the firmware hardcodes this value to something useful.
28*4882a593Smuzhiyun  */
29*4882a593Smuzhiyun unsigned long physical_memsize = 0L;
30*4882a593Smuzhiyun 
31*4882a593Smuzhiyun /*
32*4882a593Smuzhiyun  * this struct is filled by the soc specific detection code and holds
33*4882a593Smuzhiyun  * information about the specific soc type, revision and name
34*4882a593Smuzhiyun  */
35*4882a593Smuzhiyun static struct ltq_soc_info soc_info;
36*4882a593Smuzhiyun 
get_system_type(void)37*4882a593Smuzhiyun const char *get_system_type(void)
38*4882a593Smuzhiyun {
39*4882a593Smuzhiyun 	return soc_info.sys_type;
40*4882a593Smuzhiyun }
41*4882a593Smuzhiyun 
ltq_soc_type(void)42*4882a593Smuzhiyun int ltq_soc_type(void)
43*4882a593Smuzhiyun {
44*4882a593Smuzhiyun 	return soc_info.type;
45*4882a593Smuzhiyun }
46*4882a593Smuzhiyun 
prom_free_prom_memory(void)47*4882a593Smuzhiyun void __init prom_free_prom_memory(void)
48*4882a593Smuzhiyun {
49*4882a593Smuzhiyun }
50*4882a593Smuzhiyun 
prom_init_cmdline(void)51*4882a593Smuzhiyun static void __init prom_init_cmdline(void)
52*4882a593Smuzhiyun {
53*4882a593Smuzhiyun 	int argc = fw_arg0;
54*4882a593Smuzhiyun 	char **argv = (char **) KSEG1ADDR(fw_arg1);
55*4882a593Smuzhiyun 	int i;
56*4882a593Smuzhiyun 
57*4882a593Smuzhiyun 	arcs_cmdline[0] = '\0';
58*4882a593Smuzhiyun 
59*4882a593Smuzhiyun 	for (i = 0; i < argc; i++) {
60*4882a593Smuzhiyun 		char *p = (char *) KSEG1ADDR(argv[i]);
61*4882a593Smuzhiyun 
62*4882a593Smuzhiyun 		if (CPHYSADDR(p) && *p) {
63*4882a593Smuzhiyun 			strlcat(arcs_cmdline, p, sizeof(arcs_cmdline));
64*4882a593Smuzhiyun 			strlcat(arcs_cmdline, " ", sizeof(arcs_cmdline));
65*4882a593Smuzhiyun 		}
66*4882a593Smuzhiyun 	}
67*4882a593Smuzhiyun }
68*4882a593Smuzhiyun 
plat_mem_setup(void)69*4882a593Smuzhiyun void __init plat_mem_setup(void)
70*4882a593Smuzhiyun {
71*4882a593Smuzhiyun 	void *dtb;
72*4882a593Smuzhiyun 
73*4882a593Smuzhiyun 	ioport_resource.start = IOPORT_RESOURCE_START;
74*4882a593Smuzhiyun 	ioport_resource.end = IOPORT_RESOURCE_END;
75*4882a593Smuzhiyun 	iomem_resource.start = IOMEM_RESOURCE_START;
76*4882a593Smuzhiyun 	iomem_resource.end = IOMEM_RESOURCE_END;
77*4882a593Smuzhiyun 
78*4882a593Smuzhiyun 	set_io_port_base((unsigned long) KSEG1);
79*4882a593Smuzhiyun 
80*4882a593Smuzhiyun 	if (fw_passed_dtb) /* UHI interface */
81*4882a593Smuzhiyun 		dtb = (void *)fw_passed_dtb;
82*4882a593Smuzhiyun 	else if (&__dtb_start != &__dtb_end)
83*4882a593Smuzhiyun 		dtb = (void *)__dtb_start;
84*4882a593Smuzhiyun 	else
85*4882a593Smuzhiyun 		panic("no dtb found");
86*4882a593Smuzhiyun 
87*4882a593Smuzhiyun 	/*
88*4882a593Smuzhiyun 	 * Load the devicetree. This causes the chosen node to be
89*4882a593Smuzhiyun 	 * parsed resulting in our memory appearing
90*4882a593Smuzhiyun 	 */
91*4882a593Smuzhiyun 	__dt_setup_arch(dtb);
92*4882a593Smuzhiyun }
93*4882a593Smuzhiyun 
device_tree_init(void)94*4882a593Smuzhiyun void __init device_tree_init(void)
95*4882a593Smuzhiyun {
96*4882a593Smuzhiyun 	unflatten_and_copy_device_tree();
97*4882a593Smuzhiyun }
98*4882a593Smuzhiyun 
prom_init(void)99*4882a593Smuzhiyun void __init prom_init(void)
100*4882a593Smuzhiyun {
101*4882a593Smuzhiyun 	/* call the soc specific detetcion code and get it to fill soc_info */
102*4882a593Smuzhiyun 	ltq_soc_detect(&soc_info);
103*4882a593Smuzhiyun 	snprintf(soc_info.sys_type, LTQ_SYS_TYPE_LEN - 1, "%s rev %s",
104*4882a593Smuzhiyun 		soc_info.name, soc_info.rev_type);
105*4882a593Smuzhiyun 	soc_info.sys_type[LTQ_SYS_TYPE_LEN - 1] = '\0';
106*4882a593Smuzhiyun 	pr_info("SoC: %s\n", soc_info.sys_type);
107*4882a593Smuzhiyun 	prom_init_cmdline();
108*4882a593Smuzhiyun 
109*4882a593Smuzhiyun #if defined(CONFIG_MIPS_MT_SMP)
110*4882a593Smuzhiyun 	if (register_vsmp_smp_ops())
111*4882a593Smuzhiyun 		panic("failed to register_vsmp_smp_ops()");
112*4882a593Smuzhiyun #endif
113*4882a593Smuzhiyun }
114