Linux 4.8-rc8
[linux/fpc-iii.git] / arch / nios2 / kernel / prom.c
blob367c5426157ba14dfe8799664c3f11dd6eb9c8a2
1 /*
2 * Device tree support
4 * Copyright (C) 2013, 2015 Altera Corporation
5 * Copyright (C) 2010 Thomas Chou <thomas@wytron.com.tw>
7 * Based on MIPS support for CONFIG_OF device tree support
9 * Copyright (C) 2010 Cisco Systems Inc. <dediao@cisco.com>
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program. If not, see <http://www.gnu.org/licenses/>.
26 #include <linux/init.h>
27 #include <linux/types.h>
28 #include <linux/bootmem.h>
29 #include <linux/of.h>
30 #include <linux/of_fdt.h>
31 #include <linux/io.h>
33 #include <asm/prom.h>
34 #include <asm/sections.h>
36 void __init early_init_dt_add_memory_arch(u64 base, u64 size)
38 u64 kernel_start = (u64)virt_to_phys(_text);
40 if (!memory_size &&
41 (kernel_start >= base) && (kernel_start < (base + size)))
42 memory_size = size;
46 void * __init early_init_dt_alloc_memory_arch(u64 size, u64 align)
48 return alloc_bootmem_align(size, align);
51 void __init early_init_devtree(void *params)
53 __be32 *dtb = (u32 *)__dtb_start;
54 #if defined(CONFIG_NIOS2_DTB_AT_PHYS_ADDR)
55 if (be32_to_cpup((__be32 *)CONFIG_NIOS2_DTB_PHYS_ADDR) ==
56 OF_DT_HEADER) {
57 params = (void *)CONFIG_NIOS2_DTB_PHYS_ADDR;
58 early_init_dt_scan(params);
59 return;
61 #endif
62 if (be32_to_cpu((__be32) *dtb) == OF_DT_HEADER)
63 params = (void *)__dtb_start;
65 early_init_dt_scan(params);
68 #ifdef CONFIG_EARLY_PRINTK
69 static int __init early_init_dt_scan_serial(unsigned long node,
70 const char *uname, int depth, void *data)
72 u64 *addr64 = (u64 *) data;
73 const char *p;
75 /* only consider serial nodes */
76 if (strncmp(uname, "serial", 6) != 0)
77 return 0;
79 p = of_get_flat_dt_prop(node, "compatible", NULL);
80 if (!p)
81 return 0;
84 * We found an altera_jtaguart but it wasn't configured for console, so
85 * skip it.
87 #ifndef CONFIG_SERIAL_ALTERA_JTAGUART_CONSOLE
88 if (strncmp(p, "altr,juart", 10) == 0)
89 return 0;
90 #endif
93 * Same for altera_uart.
95 #ifndef CONFIG_SERIAL_ALTERA_UART_CONSOLE
96 if (strncmp(p, "altr,uart", 9) == 0)
97 return 0;
98 #endif
100 *addr64 = of_flat_dt_translate_address(node);
102 return *addr64 == OF_BAD_ADDR ? 0 : 1;
105 unsigned long __init of_early_console(void)
107 u64 base = 0;
109 if (of_scan_flat_dt(early_init_dt_scan_serial, &base))
110 return (u32)ioremap(base, 32);
111 else
112 return 0;
114 #endif /* CONFIG_EARLY_PRINTK */