From patchwork Wed May 22 07:10:32 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: avinash philip X-Patchwork-Id: 2600741 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from casper.infradead.org (casper.infradead.org [85.118.1.10]) by patchwork1.kernel.org (Postfix) with ESMTP id 0A2D43FD2B for ; Wed, 22 May 2013 07:33:51 +0000 (UTC) Received: from merlin.infradead.org ([2001:4978:20e::2]) by casper.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1Uf3Ea-0000VI-9v; Wed, 22 May 2013 07:13:20 +0000 Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1Uf3DZ-0000nI-70; Wed, 22 May 2013 07:12:13 +0000 Received: from devils.ext.ti.com ([198.47.26.153]) by merlin.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1Uf3DW-0000m2-3J for linux-arm-kernel@lists.infradead.org; Wed, 22 May 2013 07:12:10 +0000 Received: from dflxv15.itg.ti.com ([128.247.5.124]) by devils.ext.ti.com (8.13.7/8.13.7) with ESMTP id r4M7BhFK012639; Wed, 22 May 2013 02:11:43 -0500 Received: from DLEE70.ent.ti.com (dlee70.ent.ti.com [157.170.170.113]) by dflxv15.itg.ti.com (8.14.3/8.13.8) with ESMTP id r4M7BhOq026074; Wed, 22 May 2013 02:11:43 -0500 Received: from dlelxv23.itg.ti.com (172.17.1.198) by DLEE70.ent.ti.com (157.170.170.113) with Microsoft SMTP Server id 14.2.342.3; Wed, 22 May 2013 02:11:43 -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 r4M7BcbN010793; Wed, 22 May 2013 02:11:39 -0500 Received: from symphony.india.ext.ti.com (unknown [192.168.247.13]) by ucmsshproxy.india.ext.ti.com (Postfix) with ESMTP id F3CDA158002; Wed, 22 May 2013 12:41:37 +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 r4M7BaR14844; Wed, 22 May 2013 12:41:36 +0530 (IST) From: Philip Avinash To: , , , , Subject: [PATCH 09/11] gpio: davinci: DT changes for driver Date: Wed, 22 May 2013 12:40:32 +0530 Message-ID: <1369206634-6778-10-git-send-email-avinashphilip@ti.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1369206634-6778-1-git-send-email-avinashphilip@ti.com> References: <1369206634-6778-1-git-send-email-avinashphilip@ti.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20130522_031210_258642_55597140 X-CRM114-Status: GOOD ( 18.24 ) X-Spam-Score: -8.0 (--------) X-Spam-Report: SpamAssassin version 3.3.2 on merlin.infradead.org summary: Content analysis details: (-8.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- -5.0 RCVD_IN_DNSWL_HI RBL: Sender listed at http://www.dnswl.org/, high trust [198.47.26.153 listed in list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record -1.1 RP_MATCHES_RCVD Envelope sender domain matches handover relay domain -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] Cc: davinci-linux-open-source@linux.davincidsp.com, linux-doc@vger.kernel.org, devicetree-discuss@lists.ozlabs.org, linux-kernel@vger.kernel.org, Rob Herring , KV Sujith , Philip Avinash , Rob Landley , linux-arm-kernel@lists.infradead.org X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org 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/. Cc: Grant Likely Cc: Rob Herring Cc: Rob Landley Cc: devicetree-discuss@lists.ozlabs.org Cc: linux-doc@vger.kernel.org Signed-off-by: KV Sujith Signed-off-by: Philip Avinash --- .../devicetree/bindings/gpio/gpio-davinci.txt | 26 +++++++++ drivers/gpio/gpio-davinci.c | 57 ++++++++++++++++++-- 2 files changed, 80 insertions(+), 3 deletions(-) create mode 100644 Documentation/devicetree/bindings/gpio/gpio-davinci.txt diff --git a/Documentation/devicetree/bindings/gpio/gpio-davinci.txt b/Documentation/devicetree/bindings/gpio/gpio-davinci.txt new file mode 100644 index 0000000..0d599d9 --- /dev/null +++ b/Documentation/devicetree/bindings/gpio/gpio-davinci.txt @@ -0,0 +1,26 @@ +Davinci GPIO controller bindings + +Required Properties: +- compatible:"ti,da830-gpio" + +- reg: Physical base address of the controller and length of memory mapped + region. + +- interrupts: The Starting IRQ number for GPIO + +- 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: +gpio: gpio@1e26000 { + compatible = "ti,da830-gpio"; + reg = <0x226000 0x1000>; + interrupts = <42>; + ngpio = <144>; + intc_irq_num = <101>; + gpio_unbanked = <0>; +}; diff --git a/drivers/gpio/gpio-davinci.c b/drivers/gpio/gpio-davinci.c index 08830aa..dbe3b83 100644 --- a/drivers/gpio/gpio-davinci.c +++ b/drivers/gpio/gpio-davinci.c @@ -19,6 +19,8 @@ #include #include #include +#include +#include #include #include #include @@ -133,6 +135,50 @@ static void davinci_gpio_set(struct gpio_chip *chip, unsigned offset, __raw_writel((1 << offset), value ? ®s->set_data : ®s->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; @@ -142,13 +188,17 @@ static int davinci_gpio_probe(struct platform_device *pdev) struct davinci_gpio_regs *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, "GPIO: No Platform Data Supplied\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 @@ -490,8 +540,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), }, };