blob: c8166dc02c38614fbf8c8a0686279f3fb0487f27 [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 Gupta999159a2013-01-22 17:00:52 +053019
20/* called from unflatten_device_tree() to bootstrap devicetree itself */
21void * __init early_init_dt_alloc_memory_arch(u64 size, u64 align)
22{
23 return __va(memblock_alloc(size, align));
24}
25
26/**
27 * setup_machine_fdt - Machine setup when an dtb was passed to the kernel
28 * @dt: virtual address pointer to dt blob
29 *
30 * If a dtb was passed to the kernel, then use it to choose the correct
31 * machine_desc and to setup the system.
32 */
33int __init setup_machine_fdt(void *dt)
34{
35 struct boot_param_header *devtree = dt;
36 unsigned long dt_root;
37 char *model, *compat;
Vineet Gupta450dd432013-01-18 15:12:20 +053038 void *clk;
Vineet Gupta999159a2013-01-22 17:00:52 +053039 char manufacturer[16];
Vineet Gupta450dd432013-01-18 15:12:20 +053040 unsigned long len;
Vineet Gupta999159a2013-01-22 17:00:52 +053041
42 /* check device tree validity */
43 if (be32_to_cpu(devtree->magic) != OF_DT_HEADER)
44 return 1;
45
46 /* Search the mdescs for the 'best' compatible value match */
47 initial_boot_params = devtree;
48 dt_root = of_get_flat_dt_root();
49
50 /* compat = "<manufacturer>,<model>" */
51 compat = of_get_flat_dt_prop(dt_root, "compatible", NULL);
52 if (!compat)
53 compat = "<unknown>";
54
55 model = strchr(compat, ',');
56 if (model)
57 model++;
58
59 strlcpy(manufacturer, compat, model ? model - compat : strlen(compat));
60
61 pr_info("Board \"%s\" from %s (Manufacturer)\n", model, manufacturer);
62
63 /* Retrieve various information from the /chosen node */
64 of_scan_flat_dt(early_init_dt_scan_chosen, boot_command_line);
65
Vineet Gupta450dd432013-01-18 15:12:20 +053066 /* Initialize {size,address}-cells info */
67 of_scan_flat_dt(early_init_dt_scan_root, NULL);
68
69 /* Setup memory, calling early_init_dt_add_memory_arch */
70 of_scan_flat_dt(early_init_dt_scan_memory, NULL);
71
72 clk = of_get_flat_dt_prop(dt_root, "clock-frequency", &len);
73 if (clk)
74 arc_set_core_freq(of_read_ulong(clk, len/4));
75
Vineet Gupta999159a2013-01-22 17:00:52 +053076 return 0;
77}