Vineet Gupta | 999159a | 2013-01-22 17:00:52 +0530 | [diff] [blame] | 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> |
Vineet Gupta | 450dd43 | 2013-01-18 15:12:20 +0530 | [diff] [blame] | 18 | #include <asm/clk.h> |
Vineet Gupta | 03a6d28 | 2013-01-18 15:12:26 +0530 | [diff] [blame^] | 19 | #include <asm/mach_desc.h> |
Vineet Gupta | 999159a | 2013-01-22 17:00:52 +0530 | [diff] [blame] | 20 | |
| 21 | /* called from unflatten_device_tree() to bootstrap devicetree itself */ |
| 22 | void * __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 Gupta | 03a6d28 | 2013-01-18 15:12:26 +0530 | [diff] [blame^] | 34 | struct machine_desc * __init setup_machine_fdt(void *dt) |
Vineet Gupta | 999159a | 2013-01-22 17:00:52 +0530 | [diff] [blame] | 35 | { |
| 36 | struct boot_param_header *devtree = dt; |
Vineet Gupta | 03a6d28 | 2013-01-18 15:12:26 +0530 | [diff] [blame^] | 37 | struct machine_desc *mdesc = NULL, *mdesc_best = NULL; |
| 38 | unsigned int score, mdesc_score = ~1; |
Vineet Gupta | 999159a | 2013-01-22 17:00:52 +0530 | [diff] [blame] | 39 | unsigned long dt_root; |
Vineet Gupta | 03a6d28 | 2013-01-18 15:12:26 +0530 | [diff] [blame^] | 40 | const char *model, *compat; |
Vineet Gupta | 450dd43 | 2013-01-18 15:12:20 +0530 | [diff] [blame] | 41 | void *clk; |
Vineet Gupta | 999159a | 2013-01-22 17:00:52 +0530 | [diff] [blame] | 42 | char manufacturer[16]; |
Vineet Gupta | 450dd43 | 2013-01-18 15:12:20 +0530 | [diff] [blame] | 43 | unsigned long len; |
Vineet Gupta | 999159a | 2013-01-22 17:00:52 +0530 | [diff] [blame] | 44 | |
| 45 | /* check device tree validity */ |
| 46 | if (be32_to_cpu(devtree->magic) != OF_DT_HEADER) |
Vineet Gupta | 03a6d28 | 2013-01-18 15:12:26 +0530 | [diff] [blame^] | 47 | return NULL; |
Vineet Gupta | 999159a | 2013-01-22 17:00:52 +0530 | [diff] [blame] | 48 | |
Vineet Gupta | 999159a | 2013-01-22 17:00:52 +0530 | [diff] [blame] | 49 | initial_boot_params = devtree; |
| 50 | dt_root = of_get_flat_dt_root(); |
| 51 | |
Vineet Gupta | 03a6d28 | 2013-01-18 15:12:26 +0530 | [diff] [blame^] | 52 | /* |
| 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 Gupta | 999159a | 2013-01-22 17:00:52 +0530 | [diff] [blame] | 83 | /* compat = "<manufacturer>,<model>" */ |
Vineet Gupta | 03a6d28 | 2013-01-18 15:12:26 +0530 | [diff] [blame^] | 84 | compat = mdesc_best->dt_compat[0]; |
Vineet Gupta | 999159a | 2013-01-22 17:00:52 +0530 | [diff] [blame] | 85 | |
| 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 Gupta | 450dd43 | 2013-01-18 15:12:20 +0530 | [diff] [blame] | 97 | /* 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 Gupta | 03a6d28 | 2013-01-18 15:12:26 +0530 | [diff] [blame^] | 107 | return mdesc_best; |
Vineet Gupta | 999159a | 2013-01-22 17:00:52 +0530 | [diff] [blame] | 108 | } |