Patchwork sparc,leon: Added support for AMBAPP bus.

login
register
mail settings
Submitter Konrad Eisele
Date June 22, 2009, 10:02 a.m.
Message ID <1245664973-11520-4-git-send-email-konrad@gaisler.com>
Download mbox | patch
Permalink /patch/28986/
State Superseded
Delegated to: David Miller
Headers show

Comments

Konrad Eisele - June 22, 2009, 10:02 a.m.
From: Konrad Eisele <konrad@gaisler.com>

The device is a AMBA bus if it is a child of prom node
"ambapp" (AMBA plug and play). Two functions
leon_trans_init() and leon_node_init() (defined in
sparc/kernel/leon_kernel.c) are called in the prom_build_tree()
path if CONFIG_SPARC_LEON is defined. leon_node_init() will
build up the device tree using AMBA plug and play.

Signed-off-by: Konrad Eisele <konrad@gaisler.com>
---
 arch/sparc/kernel/of_device_32.c |   37 +++++++++++++++++++++++++++++++++++++
 arch/sparc/kernel/prom_32.c      |   33 +++++++++++++++++++++++++++++++++
 arch/sparc/kernel/prom_common.c  |   10 ++++++++--
 3 files changed, 78 insertions(+), 2 deletions(-)
Sam Ravnborg - June 22, 2009, 9:16 p.m.
On Mon, Jun 22, 2009 at 12:02:52PM +0200, konrad@gaisler.com wrote:
> From: Konrad Eisele <konrad@gaisler.com>
> 
> The device is a AMBA bus if it is a child of prom node
> "ambapp" (AMBA plug and play). Two functions
> leon_trans_init() and leon_node_init() (defined in
> sparc/kernel/leon_kernel.c) are called in the prom_build_tree()
> path if CONFIG_SPARC_LEON is defined. leon_node_init() will
> build up the device tree using AMBA plug and play.
> 
> Signed-off-by: Konrad Eisele <konrad@gaisler.com>
> ---
>  arch/sparc/kernel/of_device_32.c |   37 +++++++++++++++++++++++++++++++++++++
>  arch/sparc/kernel/prom_32.c      |   33 +++++++++++++++++++++++++++++++++
>  arch/sparc/kernel/prom_common.c  |   10 ++++++++--
>  3 files changed, 78 insertions(+), 2 deletions(-)
> 
> diff --git a/arch/sparc/kernel/of_device_32.c b/arch/sparc/kernel/of_device_32.c
> index 9039670..87feba6 100644
> --- a/arch/sparc/kernel/of_device_32.c
> +++ b/arch/sparc/kernel/of_device_32.c
> @@ -9,6 +9,7 @@
>  #include <linux/irq.h>
>  #include <linux/of_device.h>
>  #include <linux/of_platform.h>
> +#include <asm/leon.h>

Also include leon_amba so we get the externs in the headers
typechecked.

> diff --git a/arch/sparc/kernel/prom_common.c b/arch/sparc/kernel/prom_common.c
> index 0fb5789..522c17c 100644
> --- a/arch/sparc/kernel/prom_common.c
> +++ b/arch/sparc/kernel/prom_common.c
> @@ -22,9 +22,12 @@
>  #include <linux/of.h>
>  #include <asm/prom.h>
>  #include <asm/oplib.h>
> +#include <asm/leon.h>
>  
>  #include "prom.h"
>  
> +void (*prom_build_more)(struct device_node *dp, struct device_node ***nextp);
> +
>  struct device_node *of_console_device;
>  EXPORT_SYMBOL(of_console_device);
>  
> @@ -161,7 +164,7 @@ static struct property * __init build_one_prop(phandle node, char *prev,
>  			name = prom_nextprop(node, prev, p->name);
>  		}
>  
> -		if (strlen(name) == 0) {
> +		if (!name || strlen(name) == 0) {

Are this change justified in the chagelog?
If it is a bugfix submit it as a separate patch.

	Sam
--
To unsubscribe from this list: send the line "unsubscribe sparclinux" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Konrad Eisele - June 23, 2009, 8:55 a.m.
> 
> Are this change justified in the chagelog?
> If it is a bugfix submit it as a separate patch.
> 

Have added comment to changelog

-- Konrad
--
To unsubscribe from this list: send the line "unsubscribe sparclinux" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Patch

diff --git a/arch/sparc/kernel/of_device_32.c b/arch/sparc/kernel/of_device_32.c
index 9039670..87feba6 100644
--- a/arch/sparc/kernel/of_device_32.c
+++ b/arch/sparc/kernel/of_device_32.c
@@ -9,6 +9,7 @@ 
 #include <linux/irq.h>
 #include <linux/of_device.h>
 #include <linux/of_platform.h>
+#include <asm/leon.h>
 
 #include "of_device_common.h"
 
@@ -97,6 +98,33 @@  static unsigned long of_bus_sbus_get_flags(const u32 *addr, unsigned long flags)
 	return IORESOURCE_MEM;
 }
 
+ /*
+ * AMBAPP bus specific translator
+ */
+
+int of_bus_ambapp_match(struct device_node *np)
+{
+	return !strcmp(np->name, "ambapp");
+}
+
+void of_bus_ambapp_count_cells(struct device_node *child,
+				      int *addrc, int *sizec)
+{
+	if (addrc)
+		*addrc = 1;
+	if (sizec)
+		*sizec = 1;
+}
+
+int of_bus_ambapp_map(u32 *addr, const u32 *range, int na, int ns, int pna)
+{
+	return of_bus_default_map(addr, range, na, ns, pna);
+}
+
+unsigned long of_bus_ambapp_get_flags(const u32 *addr, unsigned long flags)
+{
+	return IORESOURCE_MEM;
+}
 
 /*
  * Array of bus specific translators
@@ -121,6 +149,15 @@  static struct of_bus of_busses[] = {
 		.map = of_bus_default_map,
 		.get_flags = of_bus_sbus_get_flags,
 	},
+	/* AMBA */
+	{
+		.name = "ambapp",
+		.addr_prop_name = "reg",
+		.match = of_bus_ambapp_match,
+		.count_cells = of_bus_ambapp_count_cells,
+		.map = of_bus_ambapp_map,
+		.get_flags = of_bus_ambapp_get_flags,
+	},
 	/* Default */
 	{
 		.name = "default",
diff --git a/arch/sparc/kernel/prom_32.c b/arch/sparc/kernel/prom_32.c
index fe43e80..0a37e8c 100644
--- a/arch/sparc/kernel/prom_32.c
+++ b/arch/sparc/kernel/prom_32.c
@@ -24,6 +24,8 @@ 
 
 #include <asm/prom.h>
 #include <asm/oplib.h>
+#include <asm/leon.h>
+#include <asm/leon_amba.h>
 
 #include "prom.h"
 
@@ -131,6 +133,35 @@  static void __init ebus_path_component(struct device_node *dp, char *tmp_buf)
 		regs->which_io, regs->phys_addr);
 }
 
+/* "name:vendor:device@irq,addrlo" */
+static void __init ambapp_path_component(struct device_node *dp, char *tmp_buf)
+{
+	struct amba_prom_registers *regs; unsigned int *intr;
+	unsigned int *device, *vendor;
+	struct property *prop;
+
+	prop = of_find_property(dp, "reg", NULL);
+	if (!prop)
+		return;
+	regs = prop->value;
+	prop = of_find_property(dp, "interrupts", NULL);
+	if (!prop)
+		return;
+	intr = prop->value;
+	prop = of_find_property(dp, "vendor", NULL);
+	if (!prop)
+		return;
+	vendor = prop->value;
+	prop = of_find_property(dp, "device", NULL);
+	if (!prop)
+		return;
+	device = prop->value;
+
+	sprintf(tmp_buf, "%s:%d:%d@%x,%x",
+		dp->name, *vendor, *device,
+		*intr, regs->phys_addr);
+}
+
 static void __init __build_path_component(struct device_node *dp, char *tmp_buf)
 {
 	struct device_node *parent = dp->parent;
@@ -143,6 +174,8 @@  static void __init __build_path_component(struct device_node *dp, char *tmp_buf)
 			return sbus_path_component(dp, tmp_buf);
 		if (!strcmp(parent->type, "ebus"))
 			return ebus_path_component(dp, tmp_buf);
+		if (!strcmp(parent->type, "ambapp"))
+			return ambapp_path_component(dp, tmp_buf);
 
 		/* "isa" is handled with platform naming */
 	}
diff --git a/arch/sparc/kernel/prom_common.c b/arch/sparc/kernel/prom_common.c
index 0fb5789..522c17c 100644
--- a/arch/sparc/kernel/prom_common.c
+++ b/arch/sparc/kernel/prom_common.c
@@ -22,9 +22,12 @@ 
 #include <linux/of.h>
 #include <asm/prom.h>
 #include <asm/oplib.h>
+#include <asm/leon.h>
 
 #include "prom.h"
 
+void (*prom_build_more)(struct device_node *dp, struct device_node ***nextp);
+
 struct device_node *of_console_device;
 EXPORT_SYMBOL(of_console_device);
 
@@ -161,7 +164,7 @@  static struct property * __init build_one_prop(phandle node, char *prev,
 			name = prom_nextprop(node, prev, p->name);
 		}
 
-		if (strlen(name) == 0) {
+		if (!name || strlen(name) == 0) {
 			tmp = p;
 			return NULL;
 		}
@@ -242,7 +245,7 @@  static struct device_node * __init prom_create_node(phandle node,
 	return dp;
 }
 
-static char * __init build_full_name(struct device_node *dp)
+char * __init build_full_name(struct device_node *dp)
 {
 	int len, ourlen, plen;
 	char *n;
@@ -289,6 +292,9 @@  static struct device_node * __init prom_build_tree(struct device_node *parent,
 
 		dp->child = prom_build_tree(dp, prom_getchild(node), nextp);
 
+		if (prom_build_more)
+			prom_build_more(dp, nextp);
+		
 		node = prom_getsibling(node);
 	}