From: Rob Herring <robherring2-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> To: devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ@public.gmane.org, linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org, grant.likely-s3s/WqlpOiPyB63q8FvJNQ@public.gmane.org Cc: Jeremy Kerr <jeremy.kerr-Z7WLFzj8eWMS+FvcfC7Uqw@public.gmane.org>, Rob Herring <rob.herring-bsGFqQB8/DxBDgjK7y7TUQ@public.gmane.org> Subject: [PATCH 2/2] drivers/amba: probe via device tree Date: Thu, 19 May 2011 13:28:24 -0500 [thread overview] Message-ID: <1305829704-11774-3-git-send-email-robherring2@gmail.com> (raw) In-Reply-To: <1305829704-11774-1-git-send-email-robherring2-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> From: Rob Herring <rob.herring-bsGFqQB8/DxBDgjK7y7TUQ@public.gmane.org> Add functions to parse the AMBA bus through the device tree. Based on the original version by Jeremy Kerr. This reworks the original amba bus device tree probing to be more inline with how platform bus probing via device tree is done using a match table. Cc: Jeremy Kerr <jeremy.kerr-Z7WLFzj8eWMS+FvcfC7Uqw@public.gmane.org> Cc: Grant Likely <grant.likely-s3s/WqlpOiPyB63q8FvJNQ@public.gmane.org> Signed-off-by: Rob Herring <rob.herring-bsGFqQB8/DxBDgjK7y7TUQ@public.gmane.org> --- drivers/amba/bus.c | 133 ++++++++++++++++++++++++++++++++++++++++++++++ include/linux/amba/bus.h | 7 +++ 2 files changed, 140 insertions(+), 0 deletions(-) diff --git a/drivers/amba/bus.c b/drivers/amba/bus.c index 7025593..8e55754 100644 --- a/drivers/amba/bus.c +++ b/drivers/amba/bus.c @@ -13,6 +13,11 @@ #include <linux/string.h> #include <linux/slab.h> #include <linux/io.h> +#include <linux/of.h> +#include <linux/of_irq.h> +#include <linux/of_address.h> +#include <linux/of_device.h> +#include <linux/of_platform.h> #include <linux/pm.h> #include <linux/pm_runtime.h> #include <linux/amba/bus.h> @@ -780,3 +785,131 @@ EXPORT_SYMBOL(amba_device_unregister); EXPORT_SYMBOL(amba_find_device); EXPORT_SYMBOL(amba_request_regions); EXPORT_SYMBOL(amba_release_regions); + +#ifdef CONFIG_OF +int of_amba_device_create(struct device_node *node,struct device *parent) +{ + struct amba_device *dev; + const void *prop; + int i, ret; + + dev = kzalloc(sizeof(*dev), GFP_KERNEL); + if (!dev) + return -ENOMEM; + + /* setup generic device info */ + dev->dev.coherent_dma_mask = ~0; + dev->dev.of_node = node; + dev->dev.parent = parent; + of_device_make_bus_id(&dev->dev); + + /* setup amba-specific device info */ + dev->dma_mask = ~0; + + /* Decode the IRQs and address ranges */ + for (i = 0; i < AMBA_NR_IRQS; i++) + dev->irq[i] = irq_of_parse_and_map(node, i); + + ret = of_address_to_resource(node, 0, &dev->res); + if (ret) + goto err_free; + + ret = amba_device_register(dev, &iomem_resource); + if (ret) + goto err_free; + + /* Sanity check the arm,amba-deviceid value */ + prop = of_get_property(node, "arm,amba-deviceid", NULL); + if (!prop) + dev_warn(&dev->dev, "arm,amba-deviceid property missing; " + "probe gives 0x%08x.\n", dev->periphid); + + if (prop && (dev->periphid != of_read_ulong(prop, 1))) + dev_warn(&dev->dev, "arm,amba-deviceid value (0x%08lx) and " + "probed value (0x%08x) don't agree.", + of_read_ulong(prop, 1), dev->periphid); + + return 0; + +err_free: + kfree(dev); + return ret; +} + +/** + * of_amba_bus_create() - Create a device for a node and its children. + * @bus: device node of the bus to instantiate + * @matches: match table for bus nodes + * disallow recursive creation of child buses + * @parent: parent for new device, or NULL for top level. + * + * Recursively create devices for all the child nodes. + */ +static int of_amba_bus_create(struct device_node *bus, + const struct of_device_id *matches, + struct device *parent) +{ + struct of_platform_prepare_data *prep; + struct device_node *child; + struct platform_device *dev; + int rc = 0; + + /* Make sure it has a compatible property */ + if (!of_get_property(bus, "compatible", NULL)) { + pr_debug("%s() - skipping %s, no compatible prop\n", + __func__, bus->full_name); + return 0; + } + + if (!of_match_node(matches, bus)) + return 0; + + dev = of_platform_device_create(bus, NULL, parent); + if (!dev) + return 0; + + for_each_child_of_node(bus, child) { + pr_debug(" create child: %s\n", child->full_name); + if (of_device_is_compatible(child, "arm,amba-device")) + of_amba_device_create(child, &dev->dev); + else + rc = of_amba_bus_create(child, matches, &dev->dev); + if (rc) { + of_node_put(child); + break; + } + } + return rc; +} + +/** + * of_amba_bus_populate() - Probe the device-tree for amba buses + * @root: parent of the first level to probe or NULL for the root of the tree + * @matches: match table for bus nodes + * @parent: parent to hook devices from, NULL for toplevel + * + * Returns 0 on success, < 0 on failure. + */ +int of_amba_bus_populate(struct device_node *root, + const struct of_device_id *matches, + struct device *parent) +{ + struct device_node *child; + int rc = 0; + + root = root ? of_node_get(root) : of_find_node_by_path("/"); + if (!root) + return -EINVAL; + + for_each_child_of_node(root, child) { + rc = of_amba_bus_create(child, matches, parent); + if (rc) + break; + } + + of_node_put(root); + return rc; +} +EXPORT_SYMBOL(of_amba_bus_populate); + +#endif /* CONFIG_OF */ diff --git a/include/linux/amba/bus.h b/include/linux/amba/bus.h index fcbbe71..9968354 100644 --- a/include/linux/amba/bus.h +++ b/include/linux/amba/bus.h @@ -94,4 +94,11 @@ void amba_release_regions(struct amba_device *); #define amba_manf(d) AMBA_MANF_BITS((d)->periphid) #define amba_part(d) AMBA_PART_BITS((d)->periphid) +#ifdef CONFIG_OF +struct device_node; +int of_amba_bus_populate(struct device_node *root, + const struct of_device_id *matches, + struct device *parent); +#endif + #endif -- 1.7.4.1
WARNING: multiple messages have this Message-ID (diff)
From: robherring2@gmail.com (Rob Herring) To: linux-arm-kernel@lists.infradead.org Subject: [PATCH 2/2] drivers/amba: probe via device tree Date: Thu, 19 May 2011 13:28:24 -0500 [thread overview] Message-ID: <1305829704-11774-3-git-send-email-robherring2@gmail.com> (raw) In-Reply-To: <1305829704-11774-1-git-send-email-robherring2@gmail.com> From: Rob Herring <rob.herring@calxeda.com> Add functions to parse the AMBA bus through the device tree. Based on the original version by Jeremy Kerr. This reworks the original amba bus device tree probing to be more inline with how platform bus probing via device tree is done using a match table. Cc: Jeremy Kerr <jeremy.kerr@canonical.com> Cc: Grant Likely <grant.likely@secretlab.ca> Signed-off-by: Rob Herring <rob.herring@calxeda.com> --- drivers/amba/bus.c | 133 ++++++++++++++++++++++++++++++++++++++++++++++ include/linux/amba/bus.h | 7 +++ 2 files changed, 140 insertions(+), 0 deletions(-) diff --git a/drivers/amba/bus.c b/drivers/amba/bus.c index 7025593..8e55754 100644 --- a/drivers/amba/bus.c +++ b/drivers/amba/bus.c @@ -13,6 +13,11 @@ #include <linux/string.h> #include <linux/slab.h> #include <linux/io.h> +#include <linux/of.h> +#include <linux/of_irq.h> +#include <linux/of_address.h> +#include <linux/of_device.h> +#include <linux/of_platform.h> #include <linux/pm.h> #include <linux/pm_runtime.h> #include <linux/amba/bus.h> @@ -780,3 +785,131 @@ EXPORT_SYMBOL(amba_device_unregister); EXPORT_SYMBOL(amba_find_device); EXPORT_SYMBOL(amba_request_regions); EXPORT_SYMBOL(amba_release_regions); + +#ifdef CONFIG_OF +int of_amba_device_create(struct device_node *node,struct device *parent) +{ + struct amba_device *dev; + const void *prop; + int i, ret; + + dev = kzalloc(sizeof(*dev), GFP_KERNEL); + if (!dev) + return -ENOMEM; + + /* setup generic device info */ + dev->dev.coherent_dma_mask = ~0; + dev->dev.of_node = node; + dev->dev.parent = parent; + of_device_make_bus_id(&dev->dev); + + /* setup amba-specific device info */ + dev->dma_mask = ~0; + + /* Decode the IRQs and address ranges */ + for (i = 0; i < AMBA_NR_IRQS; i++) + dev->irq[i] = irq_of_parse_and_map(node, i); + + ret = of_address_to_resource(node, 0, &dev->res); + if (ret) + goto err_free; + + ret = amba_device_register(dev, &iomem_resource); + if (ret) + goto err_free; + + /* Sanity check the arm,amba-deviceid value */ + prop = of_get_property(node, "arm,amba-deviceid", NULL); + if (!prop) + dev_warn(&dev->dev, "arm,amba-deviceid property missing; " + "probe gives 0x%08x.\n", dev->periphid); + + if (prop && (dev->periphid != of_read_ulong(prop, 1))) + dev_warn(&dev->dev, "arm,amba-deviceid value (0x%08lx) and " + "probed value (0x%08x) don't agree.", + of_read_ulong(prop, 1), dev->periphid); + + return 0; + +err_free: + kfree(dev); + return ret; +} + +/** + * of_amba_bus_create() - Create a device for a node and its children. + * @bus: device node of the bus to instantiate + * @matches: match table for bus nodes + * disallow recursive creation of child buses + * @parent: parent for new device, or NULL for top level. + * + * Recursively create devices for all the child nodes. + */ +static int of_amba_bus_create(struct device_node *bus, + const struct of_device_id *matches, + struct device *parent) +{ + struct of_platform_prepare_data *prep; + struct device_node *child; + struct platform_device *dev; + int rc = 0; + + /* Make sure it has a compatible property */ + if (!of_get_property(bus, "compatible", NULL)) { + pr_debug("%s() - skipping %s, no compatible prop\n", + __func__, bus->full_name); + return 0; + } + + if (!of_match_node(matches, bus)) + return 0; + + dev = of_platform_device_create(bus, NULL, parent); + if (!dev) + return 0; + + for_each_child_of_node(bus, child) { + pr_debug(" create child: %s\n", child->full_name); + if (of_device_is_compatible(child, "arm,amba-device")) + of_amba_device_create(child, &dev->dev); + else + rc = of_amba_bus_create(child, matches, &dev->dev); + if (rc) { + of_node_put(child); + break; + } + } + return rc; +} + +/** + * of_amba_bus_populate() - Probe the device-tree for amba buses + * @root: parent of the first level to probe or NULL for the root of the tree + * @matches: match table for bus nodes + * @parent: parent to hook devices from, NULL for toplevel + * + * Returns 0 on success, < 0 on failure. + */ +int of_amba_bus_populate(struct device_node *root, + const struct of_device_id *matches, + struct device *parent) +{ + struct device_node *child; + int rc = 0; + + root = root ? of_node_get(root) : of_find_node_by_path("/"); + if (!root) + return -EINVAL; + + for_each_child_of_node(root, child) { + rc = of_amba_bus_create(child, matches, parent); + if (rc) + break; + } + + of_node_put(root); + return rc; +} +EXPORT_SYMBOL(of_amba_bus_populate); + +#endif /* CONFIG_OF */ diff --git a/include/linux/amba/bus.h b/include/linux/amba/bus.h index fcbbe71..9968354 100644 --- a/include/linux/amba/bus.h +++ b/include/linux/amba/bus.h @@ -94,4 +94,11 @@ void amba_release_regions(struct amba_device *); #define amba_manf(d) AMBA_MANF_BITS((d)->periphid) #define amba_part(d) AMBA_PART_BITS((d)->periphid) +#ifdef CONFIG_OF +struct device_node; +int of_amba_bus_populate(struct device_node *root, + const struct of_device_id *matches, + struct device *parent); +#endif + #endif -- 1.7.4.1
next prev parent reply other threads:[~2011-05-19 18:28 UTC|newest] Thread overview: 70+ messages / expand[flat|nested] mbox.gz Atom feed top 2011-05-19 18:28 [PATCH v2 0/2] amba bus device tree probing Rob Herring 2011-05-19 18:28 ` Rob Herring [not found] ` <1305829704-11774-1-git-send-email-robherring2-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> 2011-05-19 18:28 ` [PATCH 1/2] dt: check for devices already created fron DT scan Rob Herring 2011-05-19 18:28 ` Rob Herring [not found] ` <1305829704-11774-2-git-send-email-robherring2-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> 2011-05-19 19:54 ` Grant Likely 2011-05-19 19:54 ` Grant Likely 2011-05-19 18:28 ` Rob Herring [this message] 2011-05-19 18:28 ` [PATCH 2/2] drivers/amba: probe via device tree Rob Herring [not found] ` <1305829704-11774-3-git-send-email-robherring2-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> 2011-05-19 20:01 ` Grant Likely 2011-05-19 20:01 ` Grant Likely [not found] ` <20110519200158.GW5109-e0URQFbLeQY2iJbIjFUEsiwD8/FfD2ys@public.gmane.org> 2011-05-19 23:30 ` Rob Herring 2011-05-19 23:30 ` Rob Herring 2011-05-19 23:39 ` Grant Likely 2011-05-19 23:39 ` Grant Likely [not found] ` <20110519233958.GB18181-e0URQFbLeQY2iJbIjFUEsiwD8/FfD2ys@public.gmane.org> 2011-05-20 13:24 ` Rob Herring 2011-05-20 13:24 ` Rob Herring [not found] ` <4DD66B8A.5040404-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> 2011-05-20 14:21 ` Arnd Bergmann 2011-05-20 14:21 ` Arnd Bergmann [not found] ` <201105201621.03801.arnd-r2nGTMty4D4@public.gmane.org> 2011-05-20 15:17 ` Rob Herring 2011-05-20 15:17 ` Rob Herring [not found] ` <4DD68614.6090209-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> 2011-05-20 16:08 ` Stephen Neuendorffer 2011-05-20 16:08 ` Stephen Neuendorffer 2011-05-21 17:42 ` Grant Likely 2011-05-21 17:42 ` Grant Likely 2011-05-21 23:47 ` Russell King - ARM Linux 2011-05-21 23:47 ` Russell King - ARM Linux 2011-05-21 23:47 ` Russell King - ARM Linux 2011-05-22 10:00 ` Rafael J. Wysocki 2011-05-22 10:00 ` Rafael J. Wysocki 2011-05-22 10:00 ` Rafael J. Wysocki 2011-05-22 15:46 ` Rob Herring 2011-05-22 15:46 ` Rob Herring 2011-05-22 15:46 ` Rob Herring 2011-05-23 15:23 ` Grant Likely 2011-05-23 15:23 ` Grant Likely 2011-05-22 10:03 ` Arnd Bergmann 2011-05-22 10:03 ` Arnd Bergmann 2011-05-22 10:03 ` Arnd Bergmann 2011-05-25 9:03 ` Linus Walleij 2011-05-25 9:03 ` Linus Walleij 2011-05-23 9:37 ` Kristoffer Glembo 2011-05-23 9:37 ` Kristoffer Glembo 2011-05-23 9:37 ` Kristoffer Glembo 2011-05-23 9:58 ` Russell King - ARM Linux 2011-05-23 9:58 ` Russell King - ARM Linux 2011-05-23 15:09 ` Grant Likely 2011-05-23 15:09 ` Grant Likely 2011-05-23 15:09 ` Grant Likely 2011-05-24 15:03 ` Rob Herring 2011-05-24 15:03 ` Rob Herring 2011-05-24 15:03 ` Rob Herring 2011-05-25 3:02 ` Shawn Guo 2011-05-25 3:02 ` Shawn Guo 2011-05-25 3:02 ` Shawn Guo 2011-05-25 9:07 ` Linus Walleij 2011-05-25 9:07 ` Linus Walleij [not found] ` <a42f0c27-2811-4b68-bedf-7dfaa7bff6ff-+Ck8Kgl/v0/6UOWq+LNw4LjjLBE8jN/0@public.gmane.org> 2011-05-21 23:35 ` Russell King - ARM Linux 2011-05-21 23:35 ` Russell King - ARM Linux [not found] ` <20110521233558.GA17672-l+eeeJia6m9vn6HldHNs0ANdhmdF6hFW@public.gmane.org> 2011-05-23 15:00 ` Stephen Neuendorffer 2011-05-23 15:00 ` Stephen Neuendorffer [not found] ` <1007bcf2-7786-4f03-bff7-8d8af83939f1-+Ck8Kgl/v0+GljRhoabY2LjjLBE8jN/0@public.gmane.org> 2011-05-23 15:47 ` Russell King - ARM Linux 2011-05-23 15:47 ` Russell King - ARM Linux 2011-05-21 4:00 ` Segher Boessenkool 2011-05-21 4:00 ` Segher Boessenkool [not found] ` <80f20ac921a33e9f0bf3e249f539a8ef-XVmvHMARGAS8U2dJNN8I7kB+6BGkLq7r@public.gmane.org> 2011-05-21 14:55 ` Rob Herring 2011-05-21 14:55 ` Rob Herring [not found] ` <4DD7D24D.2070604-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> 2011-05-21 15:18 ` Segher Boessenkool 2011-05-21 15:18 ` Segher Boessenkool [not found] ` <ad5605c2a3d4b36f63f36f52afe89cfd-XVmvHMARGAS8U2dJNN8I7kB+6BGkLq7r@public.gmane.org> 2011-05-21 17:43 ` Grant Likely 2011-05-21 17:43 ` Grant Likely
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=1305829704-11774-3-git-send-email-robherring2@gmail.com \ --to=robherring2-re5jqeeqqe8avxtiumwx3w@public.gmane.org \ --cc=devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ@public.gmane.org \ --cc=grant.likely-s3s/WqlpOiPyB63q8FvJNQ@public.gmane.org \ --cc=jeremy.kerr-Z7WLFzj8eWMS+FvcfC7Uqw@public.gmane.org \ --cc=linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org \ --cc=rob.herring-bsGFqQB8/DxBDgjK7y7TUQ@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: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.