xref: /linux/arch/mips/loongson32/common/prom.c (revision b8d312aa075f33282565467662c4628dae0a2aff)
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3  * Copyright (c) 2011 Zhang, Keguang <keguang.zhang@gmail.com>
4  *
5  * Modified from arch/mips/pnx833x/common/prom.c.
6  */
7 
8 #include <linux/serial_reg.h>
9 #include <asm/bootinfo.h>
10 
11 #include <loongson1.h>
12 #include <prom.h>
13 
14 int prom_argc;
15 char **prom_argv, **prom_envp;
16 unsigned long memsize, highmemsize;
17 
18 char *prom_getenv(char *envname)
19 {
20 	char **env = prom_envp;
21 	int i;
22 
23 	i = strlen(envname);
24 
25 	while (*env) {
26 		if (strncmp(envname, *env, i) == 0 && *(*env + i) == '=')
27 			return *env + i + 1;
28 		env++;
29 	}
30 
31 	return 0;
32 }
33 
34 static inline unsigned long env_or_default(char *env, unsigned long dfl)
35 {
36 	char *str = prom_getenv(env);
37 	return str ? simple_strtol(str, 0, 0) : dfl;
38 }
39 
40 void __init prom_init_cmdline(void)
41 {
42 	char *c = &(arcs_cmdline[0]);
43 	int i;
44 
45 	for (i = 1; i < prom_argc; i++) {
46 		strcpy(c, prom_argv[i]);
47 		c += strlen(prom_argv[i]);
48 		if (i < prom_argc - 1)
49 			*c++ = ' ';
50 	}
51 	*c = 0;
52 }
53 
54 void __init prom_init(void)
55 {
56 	void __iomem *uart_base;
57 	prom_argc = fw_arg0;
58 	prom_argv = (char **)fw_arg1;
59 	prom_envp = (char **)fw_arg2;
60 
61 	prom_init_cmdline();
62 
63 	memsize = env_or_default("memsize", DEFAULT_MEMSIZE);
64 	highmemsize = env_or_default("highmemsize", 0x0);
65 
66 	if (strstr(arcs_cmdline, "console=ttyS3"))
67 		uart_base = ioremap_nocache(LS1X_UART3_BASE, 0x0f);
68 	else if (strstr(arcs_cmdline, "console=ttyS2"))
69 		uart_base = ioremap_nocache(LS1X_UART2_BASE, 0x0f);
70 	else if (strstr(arcs_cmdline, "console=ttyS1"))
71 		uart_base = ioremap_nocache(LS1X_UART1_BASE, 0x0f);
72 	else
73 		uart_base = ioremap_nocache(LS1X_UART0_BASE, 0x0f);
74 	setup_8250_early_printk_port((unsigned long)uart_base, 0, 0);
75 }
76 
77 void __init prom_free_prom_memory(void)
78 {
79 }
80