devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jonas Gorski <jonas.gorski-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
To: linux-mips-6z/3iImG2C8G8FEW9MqTrA@public.gmane.org
Cc: devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ@public.gmane.org,
	Kevin Cernekee <cernekee-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	Ralf Baechle <ralf-6z/3iImG2C8G8FEW9MqTrA@public.gmane.org>,
	Maxime Bizon <mbizon-MmRyKUhfbQ9GWvitb5QawA@public.gmane.org>,
	Florian Fainelli
	<florian-p3rKhJxN3npAfugRpC6u6w@public.gmane.org>
Subject: [RFC] MIPS: BCM63XX: add support for loading DTB
Date: Sun, 11 Nov 2012 13:50:35 +0100	[thread overview]
Message-ID: <1352638249-29298-2-git-send-email-jonas.gorski@gmail.com> (raw)
In-Reply-To: <1352638249-29298-1-git-send-email-jonas.gorski-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>

Add support for loading DTBs embedded into the kernel. Iterate through
all embedded ones until a match is found and use that.

Use the NVRAM provided board name for constructing the compatible
property for selecting the appropriate in-kernel DTB.

Signed-off-by: Jonas Gorski <jonas.gorski-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
---
 arch/mips/Kconfig              |    1 +
 arch/mips/bcm63xx/Kconfig      |    2 +
 arch/mips/bcm63xx/Makefile     |    1 +
 arch/mips/bcm63xx/dts/Kconfig  |    3 +
 arch/mips/bcm63xx/dts/Makefile |    2 +
 arch/mips/bcm63xx/setup.c      |   80 ++++++++++++++++++++++++++++++++++++++++
 6 files changed, 89 insertions(+), 0 deletions(-)
 create mode 100644 arch/mips/bcm63xx/dts/Kconfig
 create mode 100644 arch/mips/bcm63xx/dts/Makefile

diff --git a/arch/mips/Kconfig b/arch/mips/Kconfig
index 9934a46..168b0fc 100644
--- a/arch/mips/Kconfig
+++ b/arch/mips/Kconfig
@@ -132,6 +132,7 @@ config BCM63XX
 	select SWAP_IO_SPACE
 	select ARCH_REQUIRE_GPIOLIB
 	select HAVE_CLK
+	select USE_OF
 	help
 	 Support for BCM63XX based boards
 
diff --git a/arch/mips/bcm63xx/Kconfig b/arch/mips/bcm63xx/Kconfig
index d03e879..03d693b 100644
--- a/arch/mips/bcm63xx/Kconfig
+++ b/arch/mips/bcm63xx/Kconfig
@@ -31,3 +31,5 @@ config BCM63XX_CPU_6368
 endmenu
 
 source "arch/mips/bcm63xx/boards/Kconfig"
+
+source "arch/mips/bcm63xx/dts/Kconfig"
diff --git a/arch/mips/bcm63xx/Makefile b/arch/mips/bcm63xx/Makefile
index ac28073..30971a7 100644
--- a/arch/mips/bcm63xx/Makefile
+++ b/arch/mips/bcm63xx/Makefile
@@ -5,3 +5,4 @@ obj-y		+= clk.o cpu.o cs.o gpio.o irq.o nvram.o prom.o reset.o \
 obj-$(CONFIG_EARLY_PRINTK)	+= early_printk.o
 
 obj-y		+= boards/
+obj-y		+= dts/
diff --git a/arch/mips/bcm63xx/dts/Kconfig b/arch/mips/bcm63xx/dts/Kconfig
new file mode 100644
index 0000000..919f3f6
--- /dev/null
+++ b/arch/mips/bcm63xx/dts/Kconfig
@@ -0,0 +1,3 @@
+menu "Built-in Device Tree support"
+
+endmenu
diff --git a/arch/mips/bcm63xx/dts/Makefile b/arch/mips/bcm63xx/dts/Makefile
new file mode 100644
index 0000000..69c374b
--- /dev/null
+++ b/arch/mips/bcm63xx/dts/Makefile
@@ -0,0 +1,2 @@
+$(obj)/%.dtb: $(obj)/%.dts
+	$(call if_changed,dtc)
diff --git a/arch/mips/bcm63xx/setup.c b/arch/mips/bcm63xx/setup.c
index 314231b..8712354 100644
--- a/arch/mips/bcm63xx/setup.c
+++ b/arch/mips/bcm63xx/setup.c
@@ -4,6 +4,7 @@
  * for more details.
  *
  * Copyright (C) 2008 Maxime Bizon <mbizon-MmRyKUhfbQ9GWvitb5QawA@public.gmane.org>
+ * Copyright (C) 2012 Jonas Gorski <jonas.gorski-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
  */
 
 #include <linux/init.h>
@@ -12,6 +13,8 @@
 #include <linux/bootmem.h>
 #include <linux/ioport.h>
 #include <linux/pm.h>
+#include <linux/of_fdt.h>
+#include <linux/of_platform.h>
 #include <asm/bootinfo.h>
 #include <asm/time.h>
 #include <asm/reboot.h>
@@ -20,6 +23,7 @@
 #include <bcm63xx_cpu.h>
 #include <bcm63xx_regs.h>
 #include <bcm63xx_io.h>
+#include <bcm963xx_tag.h>
 
 void bcm63xx_machine_halt(void)
 {
@@ -152,6 +156,82 @@ void __init plat_mem_setup(void)
 	board_setup();
 }
 
+extern struct boot_param_header __dtb_start;
+extern struct boot_param_header __dtb_end;
+
+int __init bcm63xx_is_compatible(struct boot_param_header *devtree,
+				   const char *compat)
+{
+	unsigned long dt_root;
+	struct boot_param_header *old_ibp = initial_boot_params;
+	int ret;
+
+	initial_boot_params = devtree;
+
+	dt_root = of_get_flat_dt_root();
+	ret = of_flat_dt_is_compatible(dt_root, compat);
+
+	initial_boot_params = old_ibp;
+
+	return ret;
+}
+
+static struct of_device_id of_ids[] = {
+	{ /* will be filled at runtime */ },
+	{ .compatible = "simple-bus" },
+	{ },
+};
+
+static struct boot_param_header *find_compatible_tree(const char *compat)
+{
+	struct boot_param_header *curr = &__dtb_start;
+
+	while (curr < &__dtb_end) {
+		if (be32_to_cpu(curr->magic) != OF_DT_HEADER)
+			continue;
+
+		if (bcm63xx_is_compatible(curr, compat))
+			return curr;
+
+		/* in-kernel dtbs are aligned to 32 bytes */
+		curr = (void *)curr + roundup(be32_to_cpu(curr->totalsize), 32);
+	}
+
+	return NULL;
+}
+
+void __init device_tree_init(void)
+{
+	struct boot_param_header *devtree = NULL;
+	const char *name = board_get_name();
+
+	strncpy(of_ids[0].compatible, name, BOARDID_LEN);
+
+	devtree = find_compatible_tree(of_ids[0].compatible);
+	if (!devtree) {
+		pr_warn("no compatible device tree found for board %s\n"
+			of_ids[0].compatible);
+		return;
+	}
+
+	__dt_setup_arch(devtree);
+	reserve_bootmem(virt_to_phys(devtree), be32_to_cpu(devtree->totalsize),
+			BOOTMEM_DEFAULT);
+
+	unflatten_device_tree();
+}
+
+int __init bcm63xx_populate_device_tree(void)
+{
+	if (!of_have_populated_dt()) {
+		pr_warn("device tree not available\n");
+		return -ENODEV;
+	}
+
+	return of_platform_populate(NULL, of_ids, NULL, NULL);
+}
+arch_initcall(bcm63xx_populate_device_tree);
+
 int __init bcm63xx_register_devices(void)
 {
 	return board_register_devices();
-- 
1.7.2.5

  parent reply	other threads:[~2012-11-11 12:50 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-11-11 12:50 [RFC] MIPS: BCM63XX: add initial Device Tree support Jonas Gorski
2012-11-11 12:50 ` [RFC] MIPS: BCM63XX: add generic fallback device trees Jonas Gorski
2012-11-11 12:50 ` [RFC] MIPS: BCM63XX: add Device Tree glue code for IRQ handling Jonas Gorski
2012-11-13  5:00   ` Stephen Warren
2012-11-14 12:09     ` Jonas Gorski
2012-11-17  4:13       ` Stephen Warren
2012-11-11 12:50 ` [RFC] net: ethernet: bcm63xx_enet: use clk_{prepare_enable,disable_unprepare} Jonas Gorski
2012-11-11 12:50 ` [RFC] MIPS: BCM63XX: add Device Tree clock definitions Jonas Gorski
2012-11-13  5:02   ` Stephen Warren
2012-11-14 12:11     ` Jonas Gorski
2012-11-17  4:15       ` Stephen Warren
2012-11-11 12:50 ` [RFC] MIPS: BCM63XX: switch to common clock and Device Tree Jonas Gorski
2012-11-13  5:04   ` Stephen Warren
2012-11-14 12:12     ` Jonas Gorski
2012-11-11 12:50 ` [RFC] MIPS: BCM63XX: register GPIO controller through " Jonas Gorski
2012-11-13  5:06   ` Stephen Warren
2012-11-14 12:13     ` Jonas Gorski
2012-11-11 12:50 ` [RFC] serial: bcm63xx_uart: allow probing " Jonas Gorski
2012-11-11 12:50 ` [RFC] MIPS: BCM63XX: add serial blocks to Device Tree includes Jonas Gorski
2012-11-11 12:50 ` [RFC] MIPS: BCM63XX: add empty Device Trees for all supported boards Jonas Gorski
2012-11-13  5:12   ` Stephen Warren
2012-11-14 12:15     ` Jonas Gorski
2012-11-11 12:50 ` [RFC] MIPS: BCM63XX: enable serial through Device Tree Jonas Gorski
     [not found]   ` <1352638249-29298-16-git-send-email-jonas.gorski-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2012-11-13  5:13     ` Stephen Warren
     [not found]       ` <50A1D6ED.50001-3lzwWm7+Weoh9ZMKESR00Q@public.gmane.org>
2012-11-14 12:17         ` Jonas Gorski
     [not found] ` <1352638249-29298-1-git-send-email-jonas.gorski-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2012-11-11 12:50   ` Jonas Gorski [this message]
2012-11-11 12:50   ` [RFC] MIPS: BCM63XX: add simple Device Tree includes for all SoCs Jonas Gorski
2012-11-13  4:54     ` Stephen Warren
     [not found]       ` <50A1D290.3050409-3lzwWm7+Weoh9ZMKESR00Q@public.gmane.org>
2012-11-13 17:56         ` David Daney
2012-11-11 12:50   ` [RFC] SPI: spi-bcm63xx: use clk_{prepare_enable,disable_unprepare} Jonas Gorski
2012-11-11 12:50   ` [RFC] bcm63xx-rng: " Jonas Gorski
2012-11-11 12:50   ` [RFC] serial: bcm63xx_uart: remove unnecessary include Jonas Gorski
2012-11-11 12:59   ` [RFC] MIPS: BCM63XX: add initial Device Tree support Jonas Gorski
2012-11-12 11:18 ` Maxime Bizon
2012-11-14 12:07   ` Jonas Gorski
2012-11-14 14:47     ` Maxime Bizon

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1352638249-29298-2-git-send-email-jonas.gorski@gmail.com \
    --to=jonas.gorski-re5jqeeqqe8avxtiumwx3w@public.gmane.org \
    --cc=cernekee-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org \
    --cc=devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ@public.gmane.org \
    --cc=florian-p3rKhJxN3npAfugRpC6u6w@public.gmane.org \
    --cc=linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=linux-mips-6z/3iImG2C8G8FEW9MqTrA@public.gmane.org \
    --cc=mbizon-MmRyKUhfbQ9GWvitb5QawA@public.gmane.org \
    --cc=ralf-6z/3iImG2C8G8FEW9MqTrA@public.gmane.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).