* [PATCH] devicetree patches
@ 2013-04-22 7:27 Sascha Hauer
2013-04-22 7:27 ` [PATCH 1/6] of: parse phandles before probing devices Sascha Hauer
` (5 more replies)
0 siblings, 6 replies; 7+ messages in thread
From: Sascha Hauer @ 2013-04-22 7:27 UTC (permalink / raw)
To: barebox
Here are some improvements to the barebox devicetree support, like
multiple resources per device and named resources.
Sascha
----------------------------------------------------------------
Sascha Hauer (6):
of: parse phandles before probing devices
of: Add of_property_read_string_index()
of: Allow multiple resources in 'reg' property
of: read resource names from devicetree
of: partitions: pass struct cdev as argument
of: partitions: create bb device for nand flashes
drivers/of/base.c | 133 ++++++++++++++++++++++++++++++++++++++++---------
drivers/of/partition.c | 13 +++--
include/of.h | 10 ++--
3 files changed, 124 insertions(+), 32 deletions(-)
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH 1/6] of: parse phandles before probing devices
2013-04-22 7:27 [PATCH] devicetree patches Sascha Hauer
@ 2013-04-22 7:27 ` Sascha Hauer
2013-04-22 7:27 ` [PATCH 2/6] of: Add of_property_read_string_index() Sascha Hauer
` (4 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: Sascha Hauer @ 2013-04-22 7:27 UTC (permalink / raw)
To: barebox
The phandles have to be parsed completely before registering the devices
from the devicetree. Otherwise drivers can't rely on of_find_node_by_phandle
in their probe.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
drivers/of/base.c | 24 +++++++++++++++++-------
1 file changed, 17 insertions(+), 7 deletions(-)
diff --git a/drivers/of/base.c b/drivers/of/base.c
index d22031f..65d8171 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -873,15 +873,8 @@ static int add_of_device_resource(struct device_node *node)
u64 address, size;
struct resource *res;
struct device_d *dev;
- phandle phandle;
int ret;
- ret = of_property_read_u32(node, "phandle", &phandle);
- if (!ret) {
- node->phandle = phandle;
- list_add_tail(&node->phandles, &phandle_list);
- }
-
ret = of_add_memory(node, false);
if (ret != -ENXIO)
return ret;
@@ -975,6 +968,22 @@ static void __of_probe(struct device_node *node)
__of_probe(n);
}
+static void __of_parse_phandles(struct device_node *node)
+{
+ struct device_node *n;
+ phandle phandle;
+ int ret;
+
+ ret = of_property_read_u32(node, "phandle", &phandle);
+ if (!ret) {
+ node->phandle = phandle;
+ list_add_tail(&node->phandles, &phandle_list);
+ }
+
+ list_for_each_entry(n, &node->children, parent_list)
+ __of_parse_phandles(n);
+}
+
struct device_node *of_chosen;
const char *of_model;
@@ -991,6 +1000,7 @@ int of_probe(void)
of_chosen = of_find_node_by_path(root_node, "/chosen");
of_property_read_string(root_node, "model", &of_model);
+ __of_parse_phandles(root_node);
__of_probe(root_node);
return 0;
--
1.8.2.rc2
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH 2/6] of: Add of_property_read_string_index()
2013-04-22 7:27 [PATCH] devicetree patches Sascha Hauer
2013-04-22 7:27 ` [PATCH 1/6] of: parse phandles before probing devices Sascha Hauer
@ 2013-04-22 7:27 ` Sascha Hauer
2013-04-22 7:27 ` [PATCH 3/6] of: Allow multiple resources in 'reg' property Sascha Hauer
` (3 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: Sascha Hauer @ 2013-04-22 7:27 UTC (permalink / raw)
To: barebox
Directly imported from the Kernel
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
drivers/of/base.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++
include/of.h | 2 ++
2 files changed, 48 insertions(+)
diff --git a/drivers/of/base.c b/drivers/of/base.c
index 65d8171..c086f7e 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -579,6 +579,52 @@ int of_property_read_string(struct device_node *np, const char *propname,
}
EXPORT_SYMBOL_GPL(of_property_read_string);
+/**
+ * of_property_read_string_index - Find and read a string from a multiple
+ * strings property.
+ * @np: device node from which the property value is to be read.
+ * @propname: name of the property to be searched.
+ * @index: index of the string in the list of strings
+ * @out_string: pointer to null terminated return string, modified only if
+ * return value is 0.
+ *
+ * Search for a property in a device tree node and retrieve a null
+ * terminated string value (pointer to data, not a copy) in the list of strings
+ * contained in that property.
+ * Returns 0 on success, -EINVAL if the property does not exist, -ENODATA if
+ * property does not have a value, and -EILSEQ if the string is not
+ * null-terminated within the length of the property data.
+ *
+ * The out_string pointer is modified only if a valid string can be decoded.
+ */
+int of_property_read_string_index(struct device_node *np, const char *propname,
+ int index, const char **output)
+{
+ struct property *prop = of_find_property(np, propname);
+ int i = 0;
+ size_t l = 0, total = 0;
+ const char *p;
+
+ if (!prop)
+ return -EINVAL;
+ if (!prop->value)
+ return -ENODATA;
+ if (strnlen(prop->value, prop->length) >= prop->length)
+ return -EILSEQ;
+
+ p = prop->value;
+
+ for (i = 0; total < prop->length; total += l, p += l) {
+ l = strlen(p) + 1;
+ if (i++ == index) {
+ *output = p;
+ return 0;
+ }
+ }
+ return -ENODATA;
+}
+EXPORT_SYMBOL_GPL(of_property_read_string_index);
+
struct device_node *of_get_root_node(void)
{
return root_node;
diff --git a/include/of.h b/include/of.h
index 94ccfd8..852231e 100644
--- a/include/of.h
+++ b/include/of.h
@@ -160,6 +160,8 @@ void of_delete_property(struct property *pp);
int of_property_read_string(struct device_node *np, const char *propname,
const char **out_string);
+int of_property_read_string_index(struct device_node *np, const char *propname,
+ int index, const char **output);
int of_set_property(struct device_node *node, const char *p, const void *val, int len,
int create);
struct device_node *of_create_node(struct device_node *root, const char *path);
--
1.8.2.rc2
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH 3/6] of: Allow multiple resources in 'reg' property
2013-04-22 7:27 [PATCH] devicetree patches Sascha Hauer
2013-04-22 7:27 ` [PATCH 1/6] of: parse phandles before probing devices Sascha Hauer
2013-04-22 7:27 ` [PATCH 2/6] of: Add of_property_read_string_index() Sascha Hauer
@ 2013-04-22 7:27 ` Sascha Hauer
2013-04-22 7:27 ` [PATCH 4/6] of: read resource names from devicetree Sascha Hauer
` (2 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: Sascha Hauer @ 2013-04-22 7:27 UTC (permalink / raw)
To: barebox
Some devices need multiple resources in the reg property. This patch
adds support for it.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
drivers/of/base.c | 55 ++++++++++++++++++++++++++++++++++++++-----------------
include/of.h | 1 +
2 files changed, 39 insertions(+), 17 deletions(-)
diff --git a/drivers/of/base.c b/drivers/of/base.c
index c086f7e..b8c2e89 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -828,7 +828,7 @@ static struct device_d *add_of_platform_device(struct device_node *node)
dev->id = DEVICE_ID_SINGLE;
dev->resource = node->resource;
- dev->num_resources = 1;
+ dev->num_resources = node->num_resource;
dev->device_node = node;
node->device = dev;
@@ -915,25 +915,44 @@ int of_add_memory(struct device_node *node, bool dump)
static int add_of_device_resource(struct device_node *node)
{
- struct property *reg;
- u64 address, size;
- struct resource *res;
+ u64 address = 0, size;
+ struct resource *res, *resp;
struct device_d *dev;
- int ret;
+ const __be32 *endp, *reg;
+ int na, nc, n_resources;
+ int ret, len;
ret = of_add_memory(node, false);
if (ret != -ENXIO)
return ret;
- reg = of_find_property(node, "reg");
+ reg = of_get_property(node, "reg", &len);
if (!reg)
- return -ENODEV;
-
- address = of_translate_address(node, reg->value);
- if (address == OF_BAD_ADDR)
return -EINVAL;
- size = be32_to_cpu(((u32 *)reg->value)[1]);
+ of_bus_count_cells(node, &na, &nc);
+
+ n_resources = (len / sizeof(__be32)) / (na + nc);
+
+ res = resp = xzalloc(sizeof(*res) * n_resources);
+
+ endp = reg + (len / sizeof(__be32));
+
+ while ((endp - reg) >= (na + nc)) {
+ address = of_translate_address(node, reg);
+ if (address == OF_BAD_ADDR) {
+ ret = -EINVAL;
+ goto err_free;
+ }
+
+ reg += na;
+ size = dt_mem_next_cell(nc, ®);
+
+ resp->start = address;
+ resp->end = address + size - 1;
+ resp->flags = IORESOURCE_MEM;
+ resp++;
+ }
/*
* A device may already be registered as platform_device.
@@ -948,20 +967,22 @@ static int add_of_device_resource(struct device_node *node)
node->device = dev;
dev->device_node = node;
node->resource = dev->resource;
- return 0;
+ ret = 0;
+ goto err_free;
}
}
- res = xzalloc(sizeof(*res));
- res->start = address;
- res->end = address + size - 1;
- res->flags = IORESOURCE_MEM;
-
node->resource = res;
+ node->num_resource = n_resources;
add_of_device(node);
return 0;
+
+err_free:
+ free(res);
+
+ return ret;
}
void of_free(struct device_node *node)
diff --git a/include/of.h b/include/of.h
index 852231e..9349e6a 100644
--- a/include/of.h
+++ b/include/of.h
@@ -26,6 +26,7 @@ struct device_node {
struct list_head parent_list;
struct list_head list;
struct resource *resource;
+ int num_resource;
struct device_d *device;
struct list_head phandles;
phandle phandle;
--
1.8.2.rc2
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH 4/6] of: read resource names from devicetree
2013-04-22 7:27 [PATCH] devicetree patches Sascha Hauer
` (2 preceding siblings ...)
2013-04-22 7:27 ` [PATCH 3/6] of: Allow multiple resources in 'reg' property Sascha Hauer
@ 2013-04-22 7:27 ` Sascha Hauer
2013-04-22 7:27 ` [PATCH 5/6] of: partitions: pass struct cdev as argument Sascha Hauer
2013-04-22 7:27 ` [PATCH 6/6] of: partitions: create bb device for nand flashes Sascha Hauer
5 siblings, 0 replies; 7+ messages in thread
From: Sascha Hauer @ 2013-04-22 7:27 UTC (permalink / raw)
To: barebox
Resources can have names and these can also be specified in the
devicetree. Add support for it.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
drivers/of/base.c | 10 +++++++++-
1 file changed, 9 insertions(+), 1 deletion(-)
diff --git a/drivers/of/base.c b/drivers/of/base.c
index b8c2e89..fde91b3 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -919,8 +919,9 @@ static int add_of_device_resource(struct device_node *node)
struct resource *res, *resp;
struct device_d *dev;
const __be32 *endp, *reg;
+ const char *resname;
int na, nc, n_resources;
- int ret, len;
+ int ret, len, index;
ret = of_add_memory(node, false);
if (ret != -ENXIO)
@@ -938,6 +939,8 @@ static int add_of_device_resource(struct device_node *node)
endp = reg + (len / sizeof(__be32));
+ index = 0;
+
while ((endp - reg) >= (na + nc)) {
address = of_translate_address(node, reg);
if (address == OF_BAD_ADDR) {
@@ -950,8 +953,13 @@ static int add_of_device_resource(struct device_node *node)
resp->start = address;
resp->end = address + size - 1;
+ resname = NULL;
+ of_property_read_string_index(node, "reg-names", index, &resname);
+ if (resname)
+ resp->name = xstrdup(resname);
resp->flags = IORESOURCE_MEM;
resp++;
+ index++;
}
/*
--
1.8.2.rc2
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH 5/6] of: partitions: pass struct cdev as argument
2013-04-22 7:27 [PATCH] devicetree patches Sascha Hauer
` (3 preceding siblings ...)
2013-04-22 7:27 ` [PATCH 4/6] of: read resource names from devicetree Sascha Hauer
@ 2013-04-22 7:27 ` Sascha Hauer
2013-04-22 7:27 ` [PATCH 6/6] of: partitions: create bb device for nand flashes Sascha Hauer
5 siblings, 0 replies; 7+ messages in thread
From: Sascha Hauer @ 2013-04-22 7:27 UTC (permalink / raw)
To: barebox
pass a struct cdev instead of the cdev name to of_parse_partitions.
This is available to the caller anyway and makes it easier to use
additional stuff from the cdev (like knowing whether it's a mtd
device).
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
drivers/of/partition.c | 9 ++++-----
include/of.h | 7 ++++---
2 files changed, 8 insertions(+), 8 deletions(-)
diff --git a/drivers/of/partition.c b/drivers/of/partition.c
index 6a57a60..a78466b 100644
--- a/drivers/of/partition.c
+++ b/drivers/of/partition.c
@@ -22,8 +22,7 @@
#include <malloc.h>
#include <linux/mtd/mtd.h>
-int of_parse_partitions(const char *cdevname,
- struct device_node *node)
+int of_parse_partitions(struct cdev *cdev, struct device_node *node)
{
struct device_node *n;
const char *partname;
@@ -48,14 +47,14 @@ int of_parse_partitions(const char *cdevname,
partname = of_get_property(n, "name", &len);
name = (char *)partname;
- debug("add partition: %s.%s 0x%08lx 0x%08lx\n", cdevname, partname, offset, size);
+ debug("add partition: %s.%s 0x%08lx 0x%08lx\n", cdev->name, partname, offset, size);
if (of_get_property(n, "read-only", &len))
flags = DEVFS_PARTITION_READONLY;
- filename = asprintf("%s.%s", cdevname, partname);
+ filename = asprintf("%s.%s", cdev->name, partname);
- devfs_add_partition(cdevname, offset, size, flags, filename);
+ devfs_add_partition(cdev->name, offset, size, flags, filename);
free(filename);
}
diff --git a/include/of.h b/include/of.h
index 9349e6a..4dcf37e 100644
--- a/include/of.h
+++ b/include/of.h
@@ -170,9 +170,10 @@ struct device_node *of_create_node(struct device_node *root, const char *path);
struct device_node *of_get_root_node(void);
int of_set_root_node(struct device_node *);
+struct cdev;
+
#ifdef CONFIG_OFTREE
-int of_parse_partitions(const char *cdevname,
- struct device_node *node);
+int of_parse_partitions(struct cdev *cdev, struct device_node *node);
int of_alias_get_id(struct device_node *np, const char *stem);
int of_device_is_stdout_path(struct device_d *dev);
@@ -180,7 +181,7 @@ const char *of_get_model(void);
void *of_flatten_dtb(struct device_node *node);
int of_add_memory(struct device_node *node, bool dump);
#else
-static inline int of_parse_partitions(const char *cdevname,
+static inline int of_parse_partitions(struct cdev *cdev,
struct device_node *node)
{
return -EINVAL;
--
1.8.2.rc2
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH 6/6] of: partitions: create bb device for nand flashes
2013-04-22 7:27 [PATCH] devicetree patches Sascha Hauer
` (4 preceding siblings ...)
2013-04-22 7:27 ` [PATCH 5/6] of: partitions: pass struct cdev as argument Sascha Hauer
@ 2013-04-22 7:27 ` Sascha Hauer
5 siblings, 0 replies; 7+ messages in thread
From: Sascha Hauer @ 2013-04-22 7:27 UTC (permalink / raw)
To: barebox
For nand flashes automatically create a bb device for each partion.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
drivers/of/partition.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/drivers/of/partition.c b/drivers/of/partition.c
index a78466b..2d70cf5 100644
--- a/drivers/of/partition.c
+++ b/drivers/of/partition.c
@@ -21,6 +21,7 @@
#include <of.h>
#include <malloc.h>
#include <linux/mtd/mtd.h>
+#include <nand.h>
int of_parse_partitions(struct cdev *cdev, struct device_node *node)
{
@@ -56,6 +57,9 @@ int of_parse_partitions(struct cdev *cdev, struct device_node *node)
devfs_add_partition(cdev->name, offset, size, flags, filename);
+ if (cdev->mtd && cdev->mtd->type == MTD_NANDFLASH)
+ dev_add_bb_dev(filename, NULL);
+
free(filename);
}
--
1.8.2.rc2
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2013-04-22 7:27 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-04-22 7:27 [PATCH] devicetree patches Sascha Hauer
2013-04-22 7:27 ` [PATCH 1/6] of: parse phandles before probing devices Sascha Hauer
2013-04-22 7:27 ` [PATCH 2/6] of: Add of_property_read_string_index() Sascha Hauer
2013-04-22 7:27 ` [PATCH 3/6] of: Allow multiple resources in 'reg' property Sascha Hauer
2013-04-22 7:27 ` [PATCH 4/6] of: read resource names from devicetree Sascha Hauer
2013-04-22 7:27 ` [PATCH 5/6] of: partitions: pass struct cdev as argument Sascha Hauer
2013-04-22 7:27 ` [PATCH 6/6] of: partitions: create bb device for nand flashes Sascha Hauer
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox