blob: a7d98b30358b25a6b3dbe611802ec422f07ef820 [file] [log] [blame]
Vineet Gupta999159a2013-01-22 17:00:52 +05301/*
2 * Copyright (C) 2012 Synopsys, Inc. (www.synopsys.com)
3 *
4 * Based on reduced version of METAG
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
12#include <linux/init.h>
13#include <linux/reboot.h>
14#include <linux/memblock.h>
15#include <linux/of.h>
16#include <linux/of_fdt.h>
17#include <asm/prom.h>
Vineet Gupta450dd432013-01-18 15:12:20 +053018#include <asm/clk.h>
Vineet Gupta03a6d282013-01-18 15:12:26 +053019#include <asm/mach_desc.h>
Vineet Gupta999159a2013-01-22 17:00:52 +053020
21/* called from unflatten_device_tree() to bootstrap devicetree itself */
22void * __init early_init_dt_alloc_memory_arch(u64 size, u64 align)
23{
24 return __va(memblock_alloc(size, align));
25}
26
27/**
28 * setup_machine_fdt - Machine setup when an dtb was passed to the kernel
29 * @dt: virtual address pointer to dt blob
30 *
31 * If a dtb was passed to the kernel, then use it to choose the correct
32 * machine_desc and to setup the system.
33 */
Vineet Gupta03a6d282013-01-18 15:12:26 +053034struct machine_desc * __init setup_machine_fdt(void *dt)
Vineet Gupta999159a2013-01-22 17:00:52 +053035{
36 struct boot_param_header *devtree = dt;
Vineet Gupta03a6d282013-01-18 15:12:26 +053037 struct machine_desc *mdesc = NULL, *mdesc_best = NULL;
38 unsigned int score, mdesc_score = ~1;
Vineet Gupta999159a2013-01-22 17:00:52 +053039 unsigned long dt_root;
Vineet Gupta03a6d282013-01-18 15:12:26 +053040 const char *model, *compat;
Vineet Gupta450dd432013-01-18 15:12:20 +053041 void *clk;
Vineet Gupta999159a2013-01-22 17:00:52 +053042 char manufacturer[16];
Vineet Gupta450dd432013-01-18 15:12:20 +053043 unsigned long len;
Vineet Gupta999159a2013-01-22 17:00:52 +053044
45 /* check device tree validity */
46 if (be32_to_cpu(devtree->magic) != OF_DT_HEADER)
Vineet Gupta03a6d282013-01-18 15:12:26 +053047 return NULL;
Vineet Gupta999159a2013-01-22 17:00:52 +053048
Vineet Gupta999159a2013-01-22 17:00:52 +053049 initial_boot_params = devtree;
50 dt_root = of_get_flat_dt_root();
51
Vineet Gupta03a6d282013-01-18 15:12:26 +053052 /*
53 * The kernel could be multi-platform enabled, thus could have many
54 * "baked-in" machine descriptors. Search thru all for the best
55 * "compatible" string match.
56 */
57 for_each_machine_desc(mdesc) {
58 score = of_flat_dt_match(dt_root, mdesc->dt_compat);
59 if (score > 0 && score < mdesc_score) {
60 mdesc_best = mdesc;
61 mdesc_score = score;
62 }
63 }
64 if (!mdesc_best) {
65 const char *prop;
66 long size;
67
68 pr_err("\n unrecognized device tree list:\n[ ");
69
70 prop = of_get_flat_dt_prop(dt_root, "compatible", &size);
71 if (prop) {
72 while (size > 0) {
73 printk("'%s' ", prop);
74 size -= strlen(prop) + 1;
75 prop += strlen(prop) + 1;
76 }
77 }
78 printk("]\n\n");
79
80 machine_halt();
81 }
82
Vineet Gupta999159a2013-01-22 17:00:52 +053083 /* compat = "<manufacturer>,<model>" */
Vineet Gupta03a6d282013-01-18 15:12:26 +053084 compat = mdesc_best->dt_compat[0];
Vineet Gupta999159a2013-01-22 17:00:52 +053085
86 model = strchr(compat, ',');
87 if (model)
88 model++;
89
90 strlcpy(manufacturer, compat, model ? model - compat : strlen(compat));
91
92 pr_info("Board \"%s\" from %s (Manufacturer)\n", model, manufacturer);
93
94 /* Retrieve various information from the /chosen node */
95 of_scan_flat_dt(early_init_dt_scan_chosen, boot_command_line);
96
Vineet Gupta450dd432013-01-18 15:12:20 +053097 /* Initialize {size,address}-cells info */
98 of_scan_flat_dt(early_init_dt_scan_root, NULL);
99
100 /* Setup memory, calling early_init_dt_add_memory_arch */
101 of_scan_flat_dt(early_init_dt_scan_memory, NULL);
102
103 clk = of_get_flat_dt_prop(dt_root, "clock-frequency", &len);
104 if (clk)
105 arc_set_core_freq(of_read_ulong(clk, len/4));
106
Vineet Gupta03a6d282013-01-18 15:12:26 +0530107 return mdesc_best;
Vineet Gupta999159a2013-01-22 17:00:52 +0530108}