blob: 5712bb5322454f1a98d169e58490e77b62e149be [file] [log] [blame]
Dezhong Diaof2ffa5a2010-10-13 00:52:46 -06001/*
2 * MIPS support for CONFIG_OF device tree support
3 *
4 * Copyright (C) 2010 Cisco Systems Inc. <dediao@cisco.com>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 */
10
11#include <linux/init.h>
Paul Gortmaker73bc2562011-07-23 16:30:40 -040012#include <linux/export.h>
Dezhong Diaof2ffa5a2010-10-13 00:52:46 -060013#include <linux/errno.h>
14#include <linux/types.h>
15#include <linux/bootmem.h>
16#include <linux/initrd.h>
17#include <linux/debugfs.h>
18#include <linux/of.h>
19#include <linux/of_fdt.h>
20#include <linux/of_irq.h>
21#include <linux/of_platform.h>
22
23#include <asm/page.h>
24#include <asm/prom.h>
25
John Crispin9169a5d2013-04-11 05:34:59 +000026static char mips_machine_name[64] = "Unknown";
27
28__init void mips_set_machine_name(const char *name)
29{
30 if (name == NULL)
31 return;
32
33 strncpy(mips_machine_name, name, sizeof(mips_machine_name));
34 pr_info("MIPS: machine is %s\n", mips_get_machine_name());
35}
36
37char *mips_get_machine_name(void)
38{
39 return mips_machine_name;
40}
41
42#ifdef CONFIG_OF
Dezhong Diaof2ffa5a2010-10-13 00:52:46 -060043int __init early_init_dt_scan_memory_arch(unsigned long node,
44 const char *uname, int depth,
45 void *data)
46{
47 return early_init_dt_scan_memory(node, uname, depth, data);
48}
49
50void __init early_init_dt_add_memory_arch(u64 base, u64 size)
51{
52 return add_memory_region(base, size, BOOT_MEM_RAM);
53}
54
Grant Likely672c5442011-01-13 15:36:09 -070055void * __init early_init_dt_alloc_memory_arch(u64 size, u64 align)
Dezhong Diaof2ffa5a2010-10-13 00:52:46 -060056{
Grant Likely672c5442011-01-13 15:36:09 -070057 return __alloc_bootmem(size, align, __pa(MAX_DMA_ADDRESS));
Dezhong Diaof2ffa5a2010-10-13 00:52:46 -060058}
59
60#ifdef CONFIG_BLK_DEV_INITRD
61void __init early_init_dt_setup_initrd_arch(unsigned long start,
62 unsigned long end)
63{
64 initrd_start = (unsigned long)__va(start);
65 initrd_end = (unsigned long)__va(end);
66 initrd_below_start_ok = 1;
67}
68#endif
69
John Crispin9169a5d2013-04-11 05:34:59 +000070int __init early_init_dt_scan_model(unsigned long node, const char *uname,
71 int depth, void *data)
72{
73 if (!depth) {
74 char *model = of_get_flat_dt_prop(node, "model", NULL);
75
76 if (model)
77 mips_set_machine_name(model);
78 }
79 return 0;
80}
81
Dezhong Diaof2ffa5a2010-10-13 00:52:46 -060082void __init early_init_devtree(void *params)
83{
84 /* Setup flat device-tree pointer */
85 initial_boot_params = params;
86
87 /* Retrieve various informations from the /chosen node of the
88 * device-tree, including the platform type, initrd location and
89 * size, and more ...
90 */
Grant Likely85f60ae2011-04-29 00:18:16 -060091 of_scan_flat_dt(early_init_dt_scan_chosen, arcs_cmdline);
92
Dezhong Diaof2ffa5a2010-10-13 00:52:46 -060093
94 /* Scan memory nodes */
95 of_scan_flat_dt(early_init_dt_scan_root, NULL);
96 of_scan_flat_dt(early_init_dt_scan_memory_arch, NULL);
John Crispin9169a5d2013-04-11 05:34:59 +000097
98 /* try to load the mips machine name */
99 of_scan_flat_dt(early_init_dt_scan_model, NULL);
Dezhong Diaof2ffa5a2010-10-13 00:52:46 -0600100}
101
Ralf Baechle7d6168e2012-01-25 15:03:19 +0100102void __init __dt_setup_arch(struct boot_param_header *bph)
103{
104 if (be32_to_cpu(bph->magic) != OF_DT_HEADER) {
105 pr_err("DTB has bad magic, ignoring builtin OF DTB\n");
106
107 return;
108 }
109
110 initial_boot_params = bph;
John Crispin40e91ae2012-05-02 12:27:35 +0200111
112 early_init_devtree(initial_boot_params);
Ralf Baechle7d6168e2012-01-25 15:03:19 +0100113}
John Crispin9169a5d2013-04-11 05:34:59 +0000114#endif