2 * Copyright (C) 2016 Imagination Technologies
3 * Author: Paul Burton <paul.burton@imgtec.com>
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; either version 2 of the License, or (at your
8 * option) any later version.
11 #define pr_fmt(fmt) "sead3-dtshim: " fmt
13 #include <linux/errno.h>
14 #include <linux/libfdt.h>
15 #include <linux/printk.h>
19 #define SEAD_CONFIG CKSEG1ADDR(0x1b100110)
20 #define SEAD_CONFIG_GIC_PRESENT BIT(1)
22 static unsigned char fdt_buf[16 << 10] __initdata;
24 static int remove_gic(void *fdt)
26 int gic_off, cpu_off, err;
27 uint32_t cfg, cpu_phandle;
29 /* leave the GIC node intact if a GIC is present */
30 cfg = __raw_readl((uint32_t *)SEAD_CONFIG);
31 if (cfg & SEAD_CONFIG_GIC_PRESENT)
34 gic_off = fdt_node_offset_by_compatible(fdt, -1, "mti,gic");
36 pr_err("unable to find DT GIC node: %d\n", gic_off);
40 err = fdt_nop_node(fdt, gic_off);
42 pr_err("unable to nop GIC node\n");
46 cpu_off = fdt_node_offset_by_compatible(fdt, -1,
47 "mti,cpu-interrupt-controller");
49 pr_err("unable to find CPU intc node: %d\n", cpu_off);
53 cpu_phandle = fdt_get_phandle(fdt, cpu_off);
55 pr_err("unable to get CPU intc phandle\n");
59 err = fdt_setprop_u32(fdt, 0, "interrupt-parent", cpu_phandle);
61 pr_err("unable to set root interrupt-parent: %d\n", err);
68 void __init *sead3_dt_shim(void *fdt)
72 if (fdt_check_header(fdt))
75 /* if this isn't SEAD3, leave the DT alone */
76 if (fdt_node_check_compatible(fdt, 0, "mti,sead-3"))
79 err = fdt_open_into(fdt, fdt_buf, sizeof(fdt_buf));
81 panic("Unable to open FDT: %d", err);
83 err = remove_gic(fdt_buf);
85 panic("Unable to patch FDT: %d", err);
87 err = fdt_pack(fdt_buf);
89 panic("Unable to pack FDT: %d\n", err);