board-sead3.c (0cce284537fb42d9c28b9b31038ffc9b464555f5) board-sead3.c (571b7e69f7f775c531ffaf73ae476b1e46150f41)
1/*
2 * Copyright (C) 2016 Imagination Technologies
3 * Author: Paul Burton <paul.burton@imgtec.com>
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; either version 2 of the License, or (at your
8 * option) any later version.
9 */
10
11#define pr_fmt(fmt) "sead3: " fmt
12
13#include <linux/errno.h>
14#include <linux/libfdt.h>
15#include <linux/printk.h>
16
17#include <asm/fw/fw.h>
18#include <asm/io.h>
19#include <asm/machine.h>
1/*
2 * Copyright (C) 2016 Imagination Technologies
3 * Author: Paul Burton <paul.burton@imgtec.com>
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; either version 2 of the License, or (at your
8 * option) any later version.
9 */
10
11#define pr_fmt(fmt) "sead3: " fmt
12
13#include <linux/errno.h>
14#include <linux/libfdt.h>
15#include <linux/printk.h>
16
17#include <asm/fw/fw.h>
18#include <asm/io.h>
19#include <asm/machine.h>
20#include <asm/yamon-dt.h>
20
21#define SEAD_CONFIG CKSEG1ADDR(0x1b100110)
22#define SEAD_CONFIG_GIC_PRESENT BIT(1)
23
24#define MIPS_REVISION CKSEG1ADDR(0x1fc00010)
25#define MIPS_REVISION_MACHINE (0xf << 4)
26#define MIPS_REVISION_MACHINE_SEAD3 (0x4 << 4)
27
28static __init bool sead3_detect(void)
29{
30 uint32_t rev;
31
32 rev = __raw_readl((void *)MIPS_REVISION);
33 return (rev & MIPS_REVISION_MACHINE) == MIPS_REVISION_MACHINE_SEAD3;
34}
35
21
22#define SEAD_CONFIG CKSEG1ADDR(0x1b100110)
23#define SEAD_CONFIG_GIC_PRESENT BIT(1)
24
25#define MIPS_REVISION CKSEG1ADDR(0x1fc00010)
26#define MIPS_REVISION_MACHINE (0xf << 4)
27#define MIPS_REVISION_MACHINE_SEAD3 (0x4 << 4)
28
29static __init bool sead3_detect(void)
30{
31 uint32_t rev;
32
33 rev = __raw_readl((void *)MIPS_REVISION);
34 return (rev & MIPS_REVISION_MACHINE) == MIPS_REVISION_MACHINE_SEAD3;
35}
36
36static __init int append_cmdline(void *fdt)
37{
38 int err, chosen_off;
39
40 /* find or add chosen node */
41 chosen_off = fdt_path_offset(fdt, "/chosen");
42 if (chosen_off == -FDT_ERR_NOTFOUND)
43 chosen_off = fdt_path_offset(fdt, "/chosen@0");
44 if (chosen_off == -FDT_ERR_NOTFOUND)
45 chosen_off = fdt_add_subnode(fdt, 0, "chosen");
46 if (chosen_off < 0) {
47 pr_err("Unable to find or add DT chosen node: %d\n",
48 chosen_off);
49 return chosen_off;
50 }
51
52 err = fdt_setprop_string(fdt, chosen_off, "bootargs", fw_getcmdline());
53 if (err) {
54 pr_err("Unable to set bootargs property: %d\n", err);
55 return err;
56 }
57
58 return 0;
59}
60
61static __init int append_memory(void *fdt)
62{
63 unsigned long phys_memsize, memsize;
64 __be32 mem_array[2];
65 int err, mem_off;
66 char *var;
67
68 /* find memory size from the bootloader environment */
69 var = fw_getenv("memsize");
70 if (var) {
71 err = kstrtoul(var, 0, &phys_memsize);
72 if (err) {
73 pr_err("Failed to read memsize env variable '%s'\n",
74 var);
75 return -EINVAL;
76 }
77 } else {
78 pr_warn("The bootloader didn't provide memsize: defaulting to 32MB\n");
79 phys_memsize = 32 << 20;
80 }
81
82 /* default to using all available RAM */
83 memsize = phys_memsize;
84
85 /* allow the user to override the usable memory */
86 var = strstr(arcs_cmdline, "memsize=");
87 if (var)
88 memsize = memparse(var + strlen("memsize="), NULL);
89
90 /* if the user says there's more RAM than we thought, believe them */
91 phys_memsize = max_t(unsigned long, phys_memsize, memsize);
92
93 /* find or add a memory node */
94 mem_off = fdt_path_offset(fdt, "/memory");
95 if (mem_off == -FDT_ERR_NOTFOUND)
96 mem_off = fdt_add_subnode(fdt, 0, "memory");
97 if (mem_off < 0) {
98 pr_err("Unable to find or add memory DT node: %d\n", mem_off);
99 return mem_off;
100 }
101
102 err = fdt_setprop_string(fdt, mem_off, "device_type", "memory");
103 if (err) {
104 pr_err("Unable to set memory node device_type: %d\n", err);
105 return err;
106 }
107
108 mem_array[0] = 0;
109 mem_array[1] = cpu_to_be32(phys_memsize);
110 err = fdt_setprop(fdt, mem_off, "reg", mem_array, sizeof(mem_array));
111 if (err) {
112 pr_err("Unable to set memory regs property: %d\n", err);
113 return err;
114 }
115
116 mem_array[0] = 0;
117 mem_array[1] = cpu_to_be32(memsize);
118 err = fdt_setprop(fdt, mem_off, "linux,usable-memory",
119 mem_array, sizeof(mem_array));
120 if (err) {
121 pr_err("Unable to set linux,usable-memory property: %d\n", err);
122 return err;
123 }
124
125 return 0;
126}
127
128static __init int remove_gic(void *fdt)
129{
130 const unsigned int cpu_ehci_int = 2;
131 const unsigned int cpu_uart_int = 4;
132 const unsigned int cpu_eth_int = 6;
133 int gic_off, cpu_off, uart_off, eth_off, ehci_off, err;
134 uint32_t cfg, cpu_phandle;
135

--- 73 unchanged lines hidden (view full) ---

209 if (err) {
210 pr_err("unable to set EHCI interrupts property: %d\n", err);
211 return err;
212 }
213
214 return 0;
215}
216
37static __init int remove_gic(void *fdt)
38{
39 const unsigned int cpu_ehci_int = 2;
40 const unsigned int cpu_uart_int = 4;
41 const unsigned int cpu_eth_int = 6;
42 int gic_off, cpu_off, uart_off, eth_off, ehci_off, err;
43 uint32_t cfg, cpu_phandle;
44

--- 73 unchanged lines hidden (view full) ---

118 if (err) {
119 pr_err("unable to set EHCI interrupts property: %d\n", err);
120 return err;
121 }
122
123 return 0;
124}
125
217static __init int serial_config(void *fdt)
218{
219 const char *yamontty, *mode_var;
220 char mode_var_name[9], path[18], parity;
221 unsigned int uart, baud, stop_bits;
222 bool hw_flow;
223 int chosen_off, err;
224
225 yamontty = fw_getenv("yamontty");
226 if (!yamontty || !strcmp(yamontty, "tty0")) {
227 uart = 0;
228 } else if (!strcmp(yamontty, "tty1")) {
229 uart = 1;
230 } else {
231 pr_warn("yamontty environment variable '%s' invalid\n",
232 yamontty);
233 uart = 0;
234 }
235
236 baud = stop_bits = 0;
237 parity = 0;
238 hw_flow = false;
239
240 snprintf(mode_var_name, sizeof(mode_var_name), "modetty%u", uart);
241 mode_var = fw_getenv(mode_var_name);
242 if (mode_var) {
243 while (mode_var[0] >= '0' && mode_var[0] <= '9') {
244 baud *= 10;
245 baud += mode_var[0] - '0';
246 mode_var++;
247 }
248 if (mode_var[0] == ',')
249 mode_var++;
250 if (mode_var[0])
251 parity = mode_var[0];
252 if (mode_var[0] == ',')
253 mode_var++;
254 if (mode_var[0])
255 stop_bits = mode_var[0] - '0';
256 if (mode_var[0] == ',')
257 mode_var++;
258 if (!strcmp(mode_var, "hw"))
259 hw_flow = true;
260 }
261
262 if (!baud)
263 baud = 38400;
264
265 if (parity != 'e' && parity != 'n' && parity != 'o')
266 parity = 'n';
267
268 if (stop_bits != 7 && stop_bits != 8)
269 stop_bits = 8;
270
271 WARN_ON(snprintf(path, sizeof(path), "uart%u:%u%c%u%s",
272 uart, baud, parity, stop_bits,
273 hw_flow ? "r" : "") >= sizeof(path));
274
275 /* find or add chosen node */
276 chosen_off = fdt_path_offset(fdt, "/chosen");
277 if (chosen_off == -FDT_ERR_NOTFOUND)
278 chosen_off = fdt_path_offset(fdt, "/chosen@0");
279 if (chosen_off == -FDT_ERR_NOTFOUND)
280 chosen_off = fdt_add_subnode(fdt, 0, "chosen");
281 if (chosen_off < 0) {
282 pr_err("Unable to find or add DT chosen node: %d\n",
283 chosen_off);
284 return chosen_off;
285 }
286
287 err = fdt_setprop_string(fdt, chosen_off, "stdout-path", path);
288 if (err) {
289 pr_err("Unable to set stdout-path property: %d\n", err);
290 return err;
291 }
292
293 return 0;
294}
295
296static __init const void *sead3_fixup_fdt(const void *fdt,
297 const void *match_data)
298{
299 static unsigned char fdt_buf[16 << 10] __initdata;
300 int err;
301
302 if (fdt_check_header(fdt))
303 panic("Corrupt DT");
304
305 /* if this isn't SEAD3, something went wrong */
306 BUG_ON(fdt_node_check_compatible(fdt, 0, "mti,sead-3"));
307
308 fw_init_cmdline();
309
310 err = fdt_open_into(fdt, fdt_buf, sizeof(fdt_buf));
311 if (err)
312 panic("Unable to open FDT: %d", err);
313
126static __init const void *sead3_fixup_fdt(const void *fdt,
127 const void *match_data)
128{
129 static unsigned char fdt_buf[16 << 10] __initdata;
130 int err;
131
132 if (fdt_check_header(fdt))
133 panic("Corrupt DT");
134
135 /* if this isn't SEAD3, something went wrong */
136 BUG_ON(fdt_node_check_compatible(fdt, 0, "mti,sead-3"));
137
138 fw_init_cmdline();
139
140 err = fdt_open_into(fdt, fdt_buf, sizeof(fdt_buf));
141 if (err)
142 panic("Unable to open FDT: %d", err);
143
314 err = append_cmdline(fdt_buf);
144 err = yamon_dt_append_cmdline(fdt_buf);
315 if (err)
316 panic("Unable to patch FDT: %d", err);
317
145 if (err)
146 panic("Unable to patch FDT: %d", err);
147
318 err = append_memory(fdt_buf);
148 err = yamon_dt_append_memory(fdt_buf);
319 if (err)
320 panic("Unable to patch FDT: %d", err);
321
322 err = remove_gic(fdt_buf);
323 if (err)
324 panic("Unable to patch FDT: %d", err);
325
149 if (err)
150 panic("Unable to patch FDT: %d", err);
151
152 err = remove_gic(fdt_buf);
153 if (err)
154 panic("Unable to patch FDT: %d", err);
155
326 err = serial_config(fdt_buf);
156 err = yamon_dt_serial_config(fdt_buf);
327 if (err)
328 panic("Unable to patch FDT: %d", err);
329
330 err = fdt_pack(fdt_buf);
331 if (err)
332 panic("Unable to pack FDT: %d\n", err);
333
334 return fdt_buf;

--- 42 unchanged lines hidden ---
157 if (err)
158 panic("Unable to patch FDT: %d", err);
159
160 err = fdt_pack(fdt_buf);
161 if (err)
162 panic("Unable to pack FDT: %d\n", err);
163
164 return fdt_buf;

--- 42 unchanged lines hidden ---