From patchwork Thu May 19 18:28:24 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rob Herring X-Patchwork-Id: 799252 Received: from bombadil.infradead.org (bombadil.infradead.org [18.85.46.34]) by demeter1.kernel.org (8.14.4/8.14.3) with ESMTP id p4JIVUpJ022737 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Thu, 19 May 2011 18:31:51 GMT Received: from canuck.infradead.org ([2001:4978:20e::1]) by bombadil.infradead.org with esmtps (Exim 4.76 #1 (Red Hat Linux)) id 1QN7ya-00006N-JD; Thu, 19 May 2011 18:29:36 +0000 Received: from localhost ([127.0.0.1] helo=canuck.infradead.org) by canuck.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1QN7yY-0007t8-No; Thu, 19 May 2011 18:29:34 +0000 Received: from mail-gy0-f177.google.com ([209.85.160.177]) by canuck.infradead.org with esmtps (Exim 4.76 #1 (Red Hat Linux)) id 1QN7y2-0007rb-TE for linux-arm-kernel@lists.infradead.org; Thu, 19 May 2011 18:29:04 +0000 Received: by gyh20 with SMTP id 20so1211607gyh.36 for ; Thu, 19 May 2011 11:29:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:from:to:cc:subject:date:message-id:x-mailer :in-reply-to:references; bh=9u06LEwRFc/BFHRILTv/Mv+s1OcCLnJVTXOZKKWzYR8=; b=n8OVUOGEklux8yJ1gJrX9Anl2zkcOQ6tcAOZcJ9nxYTxGfAKrzcwJw7uN54Ptowkx1 IXafqEjKoZbAOiIo0nfefQ1yMM88qwZBm5QoM89B41RMezd9bIsUn7+7t/zLvIg2LzEB zEMEGTvqVBtMWImooygLpjbSZ8gtjXU5dUbjU= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references; b=fLgEiGIXNi6Qac7oJvwaQYYo+ylhAhgadGLf2rgyDEyeONetzz6VpHiP7hYB+DPY4y oTCT0nuwjInBOWiGOIRBgmgV8sS/4xhzq2F0wyrJ40qYS6IVC7/s9cmKGJC45liKgDZb NWZU/zjy83pfaegdjc5fC51EdVDJzmTU9E40E= Received: by 10.147.136.18 with SMTP id o18mr2656449yan.29.1305829741316; Thu, 19 May 2011 11:29:01 -0700 (PDT) Received: from rob-laptop.i.smooth-stone.com ([173.226.190.126]) by mx.google.com with ESMTPS id s36sm2007672ano.27.2011.05.19.11.28.59 (version=SSLv3 cipher=OTHER); Thu, 19 May 2011 11:29:00 -0700 (PDT) From: Rob Herring To: devicetree-discuss@lists.ozlabs.org, linux-arm-kernel@lists.infradead.org, grant.likely@secretlab.ca Subject: [PATCH 2/2] drivers/amba: probe via device tree Date: Thu, 19 May 2011 13:28:24 -0500 Message-Id: <1305829704-11774-3-git-send-email-robherring2@gmail.com> X-Mailer: git-send-email 1.7.4.1 In-Reply-To: <1305829704-11774-1-git-send-email-robherring2@gmail.com> References: <1305829704-11774-1-git-send-email-robherring2@gmail.com> X-CRM114-Version: 20090807-BlameThorstenAndJenny ( TRE 0.7.6 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20110519_142903_214194_DF2E3342 X-CRM114-Status: GOOD ( 19.65 ) X-Spam-Score: 1.4 (+) X-Spam-Report: SpamAssassin version 3.3.1 on canuck.infradead.org summary: Content analysis details: (1.4 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [209.85.160.177 listed in list.dnswl.org] 0.0 FREEMAIL_FROM Sender email is freemail (robherring2[at]gmail.com) 2.2 FREEMAIL_ENVFROM_END_DIGIT Envelope-from freemail username ends in digit (robherring2[at]gmail.com) -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.0 RFC_ABUSE_POST Both abuse and postmaster missing on sender domain 0.0 T_TO_NO_BRKTS_FREEMAIL T_TO_NO_BRKTS_FREEMAIL Cc: Jeremy Kerr , Rob Herring X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: linux-arm-kernel-bounces@lists.infradead.org Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter1.kernel.org [140.211.167.41]); Thu, 19 May 2011 18:31:51 +0000 (UTC) From: Rob Herring 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 Cc: Grant Likely Signed-off-by: Rob Herring --- 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 #include #include +#include +#include +#include +#include +#include #include #include #include @@ -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