From patchwork Wed May 25 21:31:12 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rob Herring X-Patchwork-Id: 818992 Received: from canuck.infradead.org (canuck.infradead.org [134.117.69.58]) by demeter1.kernel.org (8.14.4/8.14.3) with ESMTP id p4Q0BhWm007773 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Thu, 26 May 2011 00:12:09 GMT 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 1QPN3N-0000zr-AP; Wed, 25 May 2011 22:59:49 +0000 Received: from casper.infradead.org ([2001:770:15f::2]) by canuck.infradead.org with esmtps (Exim 4.76 #1 (Red Hat Linux)) id 1QPMzA-0000Sh-GY for linux-arm-kernel@canuck.infradead.org; Wed, 25 May 2011 22:55:28 +0000 Received: from mail-iw0-f177.google.com ([209.85.214.177]) by casper.infradead.org with esmtps (Exim 4.76 #1 (Red Hat Linux)) id 1QPLkD-00046G-15 for linux-arm-kernel@lists.infradead.org; Wed, 25 May 2011 21:35:58 +0000 Received: by iwn36 with SMTP id 36so77985iwn.36 for ; Wed, 25 May 2011 14:31:40 -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=9rX5Nt7hAZBviJssw33UGI9Y9Y2EHL92ROzhzim1hxg=; b=SAbB0sXxqzDyx+3yqXcBY0+TmloJma6uipHQRmGoNLKhGV577FtRXUi+EnZxNorox4 MV2DEMSPAI6c3hXaa3Dbn1AmW0dn8GvpMVA2nxAsUc+eYK48jCe3EEJAT5+l+s76OJFJ CpmzXLGj4S8RWyC5Cd+qHIf4wd9Yh0AdB1lpc= 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=l/IEZme8OL/D3xRaNMNy32WdxOzMafNv0G21UefliNe8hVR+r4y16LGQnQpdn6i7dZ xB6konINIcKEtZbDK9nnapSO/ixPqQfyLr0vkKqNqTWnkMH/tALHtdEQWNGDOqvRWOuO 0IxVDBHkzRk4myU+OJRakW1JkqutQNRWwA4H0= Received: by 10.231.121.216 with SMTP id i24mr92974ibr.5.1306359099866; Wed, 25 May 2011 14:31:39 -0700 (PDT) Received: from rob-laptop.i.smooth-stone.com ([173.226.190.126]) by mx.google.com with ESMTPS id d10sm19886ibb.66.2011.05.25.14.31.38 (version=SSLv3 cipher=OTHER); Wed, 25 May 2011 14:31:39 -0700 (PDT) From: Rob Herring To: devicetree-discuss@lists.ozlabs.org, linux-arm-kernel@lists.infradead.org Subject: [RFC PATCH v3 1/2] drivers/amba: create devices from device tree Date: Wed, 25 May 2011 16:31:12 -0500 Message-Id: <1306359073-16274-2-git-send-email-robherring2@gmail.com> X-Mailer: git-send-email 1.7.4.1 In-Reply-To: <1306359073-16274-1-git-send-email-robherring2@gmail.com> References: <1306359073-16274-1-git-send-email-robherring2@gmail.com> X-CRM114-Version: 20090807-BlameThorstenAndJenny ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20110525_223557_433352_633DC72B X-CRM114-Status: GOOD ( 19.11 ) X-Spam-Score: -1.1 (-) X-Spam-Report: SpamAssassin version 3.3.2-r929478 on casper.infradead.org summary: Content analysis details: (-1.1 points, 5.0 required) 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) -0.0 SPF_PASS SPF: sender matches SPF record 1.6 FREEMAIL_ENVFROM_END_DIGIT Envelope-from freemail username ends in digit (robherring2[at]gmail.com) -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] -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: linux@arm.linux.org.uk, arnd@arndb.de, Linus Walleij , Rob Herring , Grant Likely , Jeremy Kerr 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, 26 May 2011 00:12:09 +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 Cc: Linus Walleij Signed-off-by: Rob Herring Acked-by: Linus Walleij --- drivers/amba/bus.c | 51 ++++++++++++++++++++++++++++++++++++++++++++++ include/linux/amba/bus.h | 5 ++++ 2 files changed, 56 insertions(+), 0 deletions(-) diff --git a/drivers/amba/bus.c b/drivers/amba/bus.c index 7025593..6438ffd 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,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..08349c3 100644 --- a/include/linux/amba/bus.h +++ b/include/linux/amba/bus.h @@ -94,4 +94,9 @@ 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_device_create(struct device_node *node, struct device *parent); +#endif + #endif