1 // SPDX-License-Identifier: GPL-2.0-only
3 * Carsten Langgaard, carstenl@mips.com
4 * Copyright (C) 1999,2000 MIPS Technologies, Inc. All rights reserved.
6 * Putting things on the screen/serial line using YAMONs facilities.
8 #include <linux/init.h>
9 #include <linux/kernel.h>
10 #include <linux/serial_reg.h>
11 #include <linux/spinlock.h>
12 #include <linux/export.h>
13 #include <linux/string.h>
15 #include <asm/bootinfo.h>
16 #include <asm/setup.h>
18 #include <asm/mach-ar7/ar7.h>
19 #include <asm/mach-ar7/prom.h>
28 static struct env_var adam2_env[MAX_ENTRY];
30 char *prom_getenv(const char *name)
34 for (i = 0; (i < MAX_ENTRY) && adam2_env[i].name; i++)
35 if (!strcmp(name, adam2_env[i].name))
36 return adam2_env[i].value;
40 EXPORT_SYMBOL(prom_getenv);
42 static void __init ar7_init_cmdline(int argc, char *argv[])
46 for (i = 1; i < argc; i++) {
47 strlcat(arcs_cmdline, argv[i], COMMAND_LINE_SIZE);
49 strlcat(arcs_cmdline, " ", COMMAND_LINE_SIZE);
61 static const char psp_env_version[] __initconst = "TIENV0.8";
63 struct psp_env_chunk {
71 struct psp_var_map_entry {
76 static const struct psp_var_map_entry psp_var_map[] = {
77 { 1, "cpufrequency" },
84 { 28, "sysfrequency" },
85 { 38, "mipsfrequency" },
90 Well-known variable (num is looked up in table above for matching variable name)
91 Example: cpufrequency=211968000
92 +----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+---
93 | 01 |CTRL|CHECKSUM | 01 | _2 | _1 | _1 | _9 | _6 | _8 | _0 | _0 | _0 | \0 | FF
94 +----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+---
96 Name=Value pair in a single chunk
98 +----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+---
99 | 00 |CTRL|CHECKSUM | 01 | _N | _A | _M | _E | _0 | _V | _A | _L | _U | _E | \0
100 +----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+---
102 Name=Value pair in 2 chunks (len is the number of chunks)
103 Example: bootloaderVersion=1.3.7.15
104 +----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+---
105 | 00 |CTRL|CHECKSUM | 02 | _b | _o | _o | _t | _l | _o | _a | _d | _e | _r | _V
106 +----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+---
107 | _e | _r | _s | _i | _o | _n | \0 | _1 | _. | _3 | _. | _7 | _. | _1 | _5 | \0
108 +----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+---
110 Data is padded with 0xFF
114 #define PSP_ENV_SIZE 4096
116 static char psp_env_data[PSP_ENV_SIZE] = { 0, };
118 static char * __init lookup_psp_var_map(u8 num)
122 for (i = 0; i < ARRAY_SIZE(psp_var_map); i++)
123 if (psp_var_map[i].num == num)
124 return psp_var_map[i].value;
129 static void __init add_adam2_var(char *name, char *value)
133 for (i = 0; i < MAX_ENTRY; i++) {
134 if (!adam2_env[i].name) {
135 adam2_env[i].name = name;
136 adam2_env[i].value = value;
138 } else if (!strcmp(adam2_env[i].name, name)) {
139 adam2_env[i].value = value;
145 static int __init parse_psp_env(void *psp_env_base)
149 struct psp_env_chunk *chunks = (struct psp_env_chunk *)psp_env_data;
151 memcpy_fromio(chunks, psp_env_base, PSP_ENV_SIZE);
154 n = PSP_ENV_SIZE / sizeof(struct psp_env_chunk);
156 if ((chunks[i].num == 0xff) || ((i + chunks[i].len) > n))
158 value = chunks[i].data;
160 name = lookup_psp_var_map(chunks[i].num);
163 value += strlen(name) + 1;
166 add_adam2_var(name, value);
172 static void __init ar7_init_env(struct env_var *env)
175 struct psbl_rec *psbl = (struct psbl_rec *)(KSEG1ADDR(0x14000300));
176 void *psp_env = (void *)KSEG1ADDR(psbl->env_base);
178 if (strcmp(psp_env, psp_env_version) == 0) {
179 parse_psp_env(psp_env);
181 for (i = 0; i < MAX_ENTRY; i++, env++)
183 add_adam2_var(env->name, env->value);
187 static void __init console_config(void)
189 #ifdef CONFIG_SERIAL_8250_CONSOLE
190 char console_string[40];
192 char parity = '\0', bits = '\0', flow = '\0';
195 if (strstr(arcs_cmdline, "console="))
198 s = prom_getenv("modetty0");
200 baud = simple_strtoul(s, &p, 10);
218 if (parity != 'n' && parity != 'o' && parity != 'e')
220 if (bits != '7' && bits != '8')
224 sprintf(console_string, " console=ttyS0,%d%c%c%c", baud,
227 sprintf(console_string, " console=ttyS0,%d%c%c", baud, parity,
229 strlcat(arcs_cmdline, console_string, COMMAND_LINE_SIZE);
233 void __init prom_init(void)
235 ar7_init_cmdline(fw_arg0, (char **)fw_arg1);
236 ar7_init_env((struct env_var *)fw_arg2);
240 #define PORT(offset) (KSEG1ADDR(AR7_REGS_UART0 + (offset * 4)))
241 static inline unsigned int serial_in(int offset)
243 return readl((void *)PORT(offset));
246 static inline void serial_out(int offset, int value)
248 writel(value, (void *)PORT(offset));
251 void prom_putchar(char c)
253 while ((serial_in(UART_LSR) & UART_LSR_TEMT) == 0)
255 serial_out(UART_TX, c);