1 /* 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> 18 #include <asm/clk.h> 19 20 /* called from unflatten_device_tree() to bootstrap devicetree itself */ 21 void * __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 */ 33 int __init setup_machine_fdt(void *dt) 34 { 35 struct boot_param_header *devtree = dt; 36 unsigned long dt_root; 37 char *model, *compat; 38 void *clk; 39 char manufacturer[16]; 40 unsigned long len; 41 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 66 /* 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 76 return 0; 77 } 78