From patchwork Fri Jun 10 20:48:42 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rob Herring X-Patchwork-Id: 871532 Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) by demeter2.kernel.org (8.14.4/8.14.4) with ESMTP id p5BDBlMg027479 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Sat, 11 Jun 2011 13:12:08 GMT Received: from canuck.infradead.org ([2001:4978:20e::1]) by merlin.infradead.org with esmtps (Exim 4.76 #1 (Red Hat Linux)) id 1QVNyF-0000iD-7c; Sat, 11 Jun 2011 13:11:23 +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 1QVNyE-0006fq-Qr; Sat, 11 Jun 2011 13:11:22 +0000 Received: from mail-iw0-f177.google.com ([209.85.214.177]) by canuck.infradead.org with esmtps (Exim 4.76 #1 (Red Hat Linux)) id 1QVNyA-0006fX-71 for linux-arm-kernel@lists.infradead.org; Sat, 11 Jun 2011 13:11:19 +0000 Received: by iwn36 with SMTP id 36so3645341iwn.36 for ; Sat, 11 Jun 2011 06:11:14 -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=AKY7aIjk9mktWwuAdijDzbZVbB1ljLflBJbxluPuCH4=; b=O2ahO8f7c6aIzcVbmemBpYUTvMjaa2BnU1dhkXJbL5BlOpBGwvgvo1sooZ6wPUCSSV qAa4rFlWG9EED66+imPda4QwW5SJfonz1VUNqlc0lIIlKov3xmNF2ICMCH6nBf9a/isA RQyitdUmGv8Xh0ZQC+2q5DzJCdQ8DZKJWQ8uQ= 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=cKKJvpCgmHK8wKR8A8cxvDlyb3wrAW6xU3ivxB+noO1MXNbqILS6mfwPKqb7vFJAWC zpQt6eePodp905NGtxag2Wm+YYU4bcTxaDQyWg1hJu8yQukcl+s01IjAIxdPnvZWIgUc iAEszlJNua7G21ct9VjRRCD/Zr464SKGW8+eY= Received: by 10.42.217.138 with SMTP id hm10mr3129836icb.205.1307738948902; Fri, 10 Jun 2011 13:49:08 -0700 (PDT) Received: from rob-laptop.i.smooth-stone.com ([173.226.190.126]) by mx.google.com with ESMTPS id w8sm1487349ibh.1.2011.06.10.13.49.07 (version=SSLv3 cipher=OTHER); Fri, 10 Jun 2011 13:49:08 -0700 (PDT) From: Rob Herring To: devicetree-discuss@lists.ozlabs.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH v4 3/4] drivers/amba: create devices from device tree Date: Fri, 10 Jun 2011 15:48:42 -0500 Message-Id: <1307738923-7564-4-git-send-email-robherring2@gmail.com> X-Mailer: git-send-email 1.7.4.1 In-Reply-To: <1307738923-7564-1-git-send-email-robherring2@gmail.com> References: <1307738923-7564-1-git-send-email-robherring2@gmail.com> X-CRM114-Version: 20090807-BlameThorstenAndJenny ( TRE 0.7.6 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20110611_091118_697756_DCA74C9C X-CRM114-Status: GOOD ( 19.06 ) 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.214.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: Grant Likely , Jeremy Kerr , linux@arm.linux.org.uk, arnd@arndb.de, 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 (demeter2.kernel.org [140.211.167.43]); Sat, 11 Jun 2011 13:12:08 +0000 (UTC) From: Rob Herring Add a function to create amba bus devices (i.e. primecell peripherals) from device tree nodes. The device tree scanning is done by of_platform_probe/populate functions which can call of_amba_device_create based on a match table entry. Nodes with a "arm,amba-deviceid" property can override the h/w peripheral id value. Based on the original work by Jeremy Kerr. Cc: Jeremy Kerr Cc: Grant Likely Cc: linux@arm.linux.org.uk Cc: arnd@arndb.de Acked-by: Linus Walleij Signed-off-by: Rob Herring --- Documentation/devicetree/bindings/arm/amba.txt | 21 ++++++++++ drivers/amba/bus.c | 51 ++++++++++++++++++++++++ include/linux/amba/bus.h | 18 ++++++++ 3 files changed, 90 insertions(+), 0 deletions(-) create mode 100644 Documentation/devicetree/bindings/arm/amba.txt diff --git a/Documentation/devicetree/bindings/arm/amba.txt b/Documentation/devicetree/bindings/arm/amba.txt new file mode 100644 index 0000000..23fde7f --- /dev/null +++ b/Documentation/devicetree/bindings/arm/amba.txt @@ -0,0 +1,21 @@ +* ARM Primecell Peripherals + +ARM, Ltd. Primecell peripherals have a standard id register that can be used to +identify the peripheral type, vendor, and revision. This value can be used for +driver matching. + +Required properties: + +- compatible : should be a specific value for peripheral and "arm,amba-device" + +Optional properties: + +- arm,amba-deviceid : Value to override the h/w value with + +Example: + +serial@fff36000 { + compatible = "arm,pl011", "arm,amba-device"; + arm,amba-deviceid = <0x00341011>; +}; + diff --git a/drivers/amba/bus.c b/drivers/amba/bus.c index d74926e..19f712b 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 @@ -785,3 +790,49 @@ 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; + + /* Allow the arm,amba-deviceid value to override the h/w value */ + prop = of_get_property(node, "arm,amba-deviceid", NULL); + if (prop) + dev->periphid = of_read_ulong(prop, 1); + + /* 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; + + return 0; + +err_free: + kfree(dev); + return ret; +} + +#endif /* CONFIG_OF */ diff --git a/include/linux/amba/bus.h b/include/linux/amba/bus.h index fcbbe71..0177274 100644 --- a/include/linux/amba/bus.h +++ b/include/linux/amba/bus.h @@ -24,6 +24,7 @@ #define AMBA_CID 0xb105f00d struct clk; +struct device_node; struct amba_device { struct device dev; @@ -63,6 +64,7 @@ extern struct bus_type amba_bustype; #define amba_get_drvdata(d) dev_get_drvdata(&d->dev) #define amba_set_drvdata(d,p) dev_set_drvdata(&d->dev, p) +#ifdef CONFIG_ARM_AMBA int amba_driver_register(struct amba_driver *); void amba_driver_unregister(struct amba_driver *); int amba_device_register(struct amba_device *, struct resource *); @@ -94,4 +96,20 @@ 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 +int of_amba_device_create(struct device_node *node, struct device *parent); +#endif + +#else + +#ifdef CONFIG_OF +static inline int of_amba_device_create(struct device_node *node, + struct device *parent) +{ + return 0; +} +#endif + +#endif /* CONFIG_ARM_AMBA */ + #endif