From patchwork Fri Jun 14 10:20:39 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Philip Avinash X-Patchwork-Id: 2721181 Return-Path: X-Original-To: patchwork-davinci@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 3558EC0AB1 for ; Fri, 14 Jun 2013 10:18:49 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 14145201D7 for ; Fri, 14 Jun 2013 10:18:48 +0000 (UTC) Received: from comal.ext.ti.com (comal.ext.ti.com [198.47.26.152]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 9FF62201D5 for ; Fri, 14 Jun 2013 10:18:46 +0000 (UTC) Received: from dlelxv90.itg.ti.com ([172.17.2.17]) by comal.ext.ti.com (8.13.7/8.13.7) with ESMTP id r5EAIjeh000672 for ; Fri, 14 Jun 2013 05:18:45 -0500 Received: from DFLE72.ent.ti.com (dfle72.ent.ti.com [128.247.5.109]) by dlelxv90.itg.ti.com (8.14.3/8.13.8) with ESMTP id r5EAIjt7023874 for ; Fri, 14 Jun 2013 05:18:45 -0500 Received: from dlelxv23.itg.ti.com (172.17.1.198) by DFLE72.ent.ti.com (128.247.5.109) with Microsoft SMTP Server id 14.2.342.3; Fri, 14 Jun 2013 05:18:45 -0500 Received: from linux.omap.com (dlelxs01.itg.ti.com [157.170.227.31]) by dlelxv23.itg.ti.com (8.13.8/8.13.8) with ESMTP id r5EAIj3g013184 for ; Fri, 14 Jun 2013 05:18:45 -0500 Received: from linux.omap.com (localhost [127.0.0.1]) by linux.omap.com (Postfix) with ESMTP id 899A680627 for ; Fri, 14 Jun 2013 05:18:45 -0500 (CDT) X-Original-To: davinci-linux-open-source@linux.davincidsp.com Delivered-To: davinci-linux-open-source@linux.davincidsp.com Received: from dlelxv90.itg.ti.com (dlelxv90.itg.ti.com [172.17.2.17]) by linux.omap.com (Postfix) with ESMTP id 2E4D980626 for ; Fri, 14 Jun 2013 05:18:37 -0500 (CDT) Received: from DLEE71.ent.ti.com (dlee71.ent.ti.com [157.170.170.114]) by dlelxv90.itg.ti.com (8.14.3/8.13.8) with ESMTP id r5EAIb69023494; Fri, 14 Jun 2013 05:18:37 -0500 Received: from dlelxv23.itg.ti.com (172.17.1.198) by DLEE71.ent.ti.com (157.170.170.114) with Microsoft SMTP Server id 14.2.342.3; Fri, 14 Jun 2013 05:18:36 -0500 Received: from ucmsshproxy.india.ext.ti.com (dbdp20.itg.ti.com [172.24.170.38]) by dlelxv23.itg.ti.com (8.13.8/8.13.8) with SMTP id r5EAIWUs012687; Fri, 14 Jun 2013 05:18:33 -0500 Received: from symphony.india.ext.ti.com (unknown [192.168.247.13]) by ucmsshproxy.india.ext.ti.com (Postfix) with ESMTP id 04A09158003; Fri, 14 Jun 2013 15:48:32 +0530 (IST) Received: from ubuntu-psp-linux.india.ext.ti.com (ubuntu-psp-linux [192.168.247.46]) by symphony.india.ext.ti.com (8.11.7p1+Sun/8.11.7) with ESMTP id r5EAISR07820; Fri, 14 Jun 2013 15:48:29 +0530 (IST) From: Philip Avinash To: , , , , , Subject: [PATCH v2 2/4] gpio: davinci: DT changes for driver Date: Fri, 14 Jun 2013 15:50:39 +0530 Message-ID: <1371205241-17205-3-git-send-email-avinashphilipk@gmail.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1371203020-15092-1-git-send-email-avinashphilip@ti.com> References: <1371203020-15092-1-git-send-email-avinashphilip@ti.com> MIME-Version: 1.0 CC: , , , , , X-BeenThere: davinci-linux-open-source@linux.davincidsp.com X-Mailman-Version: 2.1.12 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: Errors-To: davinci-linux-open-source-bounces+patchwork-davinci=patchwork.kernel.org@linux.davincidsp.com X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: KV Sujith - Add of_device_id for Davinci GPIO driver. - Add function to populate data from DT. - Modify the probe to read from DT if DT match is found. - Add DT binding documentation for Davinci GPIO properties in a new file gpio-davinci.txt located at Documentation/devicetree/bindings/gpio/. Signed-off-by: KV Sujith Signed-off-by: Philip Avinash Acked-by: Linus Walleij --- Changes since v1: - description for interrupts changed to reflecti interrupt array usage. .../devicetree/bindings/gpio/gpio-davinci.txt | 32 +++++++++++ drivers/gpio/gpio-davinci.c | 57 ++++++++++++++++++-- 2 files changed, 86 insertions(+), 3 deletions(-) diff --git a/Documentation/devicetree/bindings/gpio/gpio-davinci.txt b/Documentation/devicetree/bindings/gpio/gpio-davinci.txt new file mode 100644 index 0000000..1c31638 --- /dev/null +++ b/Documentation/devicetree/bindings/gpio/gpio-davinci.txt @@ -0,0 +1,32 @@ +Davinci GPIO controller bindings + +Required Properties: +- compatible:"ti,da830-gpio" + +- reg: Physical base address of the controller and length of memory mapped + region. + +- interrupts: Array of GPIO interrupt number. + +- ngpio: The number of GPIO pins supported + +- intc_irq_num: The number of IRQs supported by the Interrupt Controller + +- gpio_unbanked: The number of GPIOs that have an individual interrupt + line to processor. + +Example: +#include + +gpio: gpio@1e26000 { + compatible = "ti,da830-gpio"; + reg = <0x226000 0x1000>; + interrupts = <42 IRQ_TYPE_EDGE_BOTH 43 IRQ_TYPE_EDGE_BOTH + 44 IRQ_TYPE_EDGE_BOTH 45 IRQ_TYPE_EDGE_BOTH + 46 IRQ_TYPE_EDGE_BOTH 47 IRQ_TYPE_EDGE_BOTH + 48 IRQ_TYPE_EDGE_BOTH 49 IRQ_TYPE_EDGE_BOTH + 50 IRQ_TYPE_EDGE_BOTH>; + ngpio = <144>; + intc_irq_num = <101>; + gpio_unbanked = <0>; +}; diff --git a/drivers/gpio/gpio-davinci.c b/drivers/gpio/gpio-davinci.c index 475a5ece..cd2ed25 100644 --- a/drivers/gpio/gpio-davinci.c +++ b/drivers/gpio/gpio-davinci.c @@ -20,6 +20,8 @@ #include #include #include +#include +#include #include #include @@ -137,6 +139,50 @@ davinci_gpio_set(struct gpio_chip *chip, unsigned offset, int value) __raw_writel((1 << offset), value ? &g->set_data : &g->clr_data); } +static struct davinci_gpio_platform_data *davinci_gpio_set_pdata_of( + struct platform_device *pdev) +{ + struct device_node *dn = pdev->dev.of_node; + struct davinci_gpio_platform_data *pdata; + u32 val, ret; + + pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL); + if (pdata) { + ret = of_property_read_u32(dn, "ngpio", &val); + if (ret) + goto of_err; + + pdata->ngpio = val; + + ret = of_property_read_u32(dn, "gpio_unbanked", &val); + if (ret) + goto of_err; + + pdata->gpio_unbanked = val; + + ret = of_property_read_u32(dn, "intc_irq_num", &val); + if (ret) + goto of_err; + + pdata->intc_irq_num = val; + } + + return pdata; + +of_err: + dev_err(&pdev->dev, "Populating pdata from DT failed: err %d\n", ret); + return NULL; +} + +static const struct of_device_id davinci_gpio_ids[] = { + { + .compatible = "ti,da830-gpio", + }, + { }, +}; + +MODULE_DEVICE_TABLE(of, davinci_gpio_ids); + static int davinci_gpio_probe(struct platform_device *pdev) { int i, base; @@ -146,13 +192,17 @@ static int davinci_gpio_probe(struct platform_device *pdev) struct davinci_gpio_regs __iomem *regs; struct device *dev = &pdev->dev; struct resource *res; + const struct of_device_id *match = + of_match_device(of_match_ptr(davinci_gpio_ids), &pdev->dev); - pdata = dev->platform_data; + pdata = match ? davinci_gpio_set_pdata_of(pdev) : dev->platform_data; if (!pdata) { dev_err(dev, "No platform data found\n"); return -EINVAL; } + dev->platform_data = pdata; + /* * The gpio banks conceptually expose a segmented bitmap, * and "ngpio" is one more than the largest zero-based @@ -497,8 +547,9 @@ done: static struct platform_driver davinci_gpio_driver = { .probe = davinci_gpio_probe, .driver = { - .name = "davinci_gpio", - .owner = THIS_MODULE, + .name = "davinci_gpio", + .owner = THIS_MODULE, + .of_match_table = of_match_ptr(davinci_gpio_ids), }, };