From patchwork Wed Aug 24 13:09:14 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benoit Cousson X-Patchwork-Id: 1092382 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 p7ODEl5N011930 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Wed, 24 Aug 2011 13:15: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 1QwDGf-0005H6-G6; Wed, 24 Aug 2011 13:13:17 +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 1QwDGe-0004zi-QR; Wed, 24 Aug 2011 13:13:16 +0000 Received: from arroyo.ext.ti.com ([192.94.94.40]) by canuck.infradead.org with esmtps (Exim 4.76 #1 (Red Hat Linux)) id 1QwDEi-0004WA-9b for linux-arm-kernel@lists.infradead.org; Wed, 24 Aug 2011 13:11:18 +0000 Received: from dlep33.itg.ti.com ([157.170.170.112]) by arroyo.ext.ti.com (8.13.7/8.13.7) with ESMTP id p7ODBEwL020366 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Wed, 24 Aug 2011 08:11:15 -0500 Received: from dlep26.itg.ti.com (smtp-le.itg.ti.com [157.170.170.27]) by dlep33.itg.ti.com (8.13.7/8.13.8) with ESMTP id p7ODBE9P011891; Wed, 24 Aug 2011 08:11:14 -0500 (CDT) Received: from DLEE74.ent.ti.com (localhost [127.0.0.1]) by dlep26.itg.ti.com (8.13.8/8.13.8) with ESMTP id p7ODBERP027792; Wed, 24 Aug 2011 08:11:14 -0500 (CDT) Received: from dlelxv22.itg.ti.com (172.17.1.197) by DLEE74.ent.ti.com (157.170.170.8) with Microsoft SMTP Server id 14.1.323.3; Wed, 24 Aug 2011 08:11:14 -0500 Received: from localhost.localdomain (lncpu04.tif.ti.com [137.167.102.15]) by dlelxv22.itg.ti.com (8.13.8/8.13.8) with ESMTP id p7ODA8Hi023561; Wed, 24 Aug 2011 08:11:12 -0500 From: Benoit Cousson To: , Subject: [RFC PATCH 08/10] gpio/omap: Adapt GPIO driver to DT Date: Wed, 24 Aug 2011 15:09:14 +0200 Message-ID: <1314191356-10963-9-git-send-email-b-cousson@ti.com> X-Mailer: git-send-email 1.7.0.4 In-Reply-To: <1314191356-10963-1-git-send-email-b-cousson@ti.com> References: <1314191356-10963-1-git-send-email-b-cousson@ti.com> MIME-Version: 1.0 X-CRM114-Version: 20090807-BlameThorstenAndJenny ( TRE 0.7.6 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20110824_091116_708673_F4637D30 X-CRM114-Status: GOOD ( 18.37 ) X-Spam-Score: -2.8 (--) X-Spam-Report: SpamAssassin version 3.3.1 on canuck.infradead.org summary: Content analysis details: (-2.8 points) pts rule name description ---- ---------------------- -------------------------------------------------- -2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at http://www.dnswl.org/, medium trust [192.94.94.40 listed in list.dnswl.org] -0.5 RP_MATCHES_RCVD Envelope sender domain matches handover relay domain Cc: khilman@ti.com, Benoit Cousson , manjugk@ti.com, devicetree-discuss@lists.ozlabs.org, linux-omap@vger.kernel.org, Tarun Kanti DebBarma , linux-arm-kernel@lists.infradead.org, Charulatha V 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: , 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]); Wed, 24 Aug 2011 13:15:08 +0000 (UTC) Adapt the GPIO driver to retrieve information from a DT file. Note that since the driver is currently under cleanup, some hacks will have to be removed after. Signed-off-by: Benoit Cousson Cc: Grant Likely Cc: Charulatha V Cc: Tarun Kanti DebBarma --- drivers/gpio/gpio-omap.c | 103 ++++++++++++++++++++++++++++++++++++++++++---- 1 files changed, 94 insertions(+), 9 deletions(-) diff --git a/drivers/gpio/gpio-omap.c b/drivers/gpio/gpio-omap.c index 0599854..96d19d7 100644 --- a/drivers/gpio/gpio-omap.c +++ b/drivers/gpio/gpio-omap.c @@ -21,6 +21,7 @@ #include #include #include +#include #include #include @@ -521,7 +522,7 @@ static int _set_gpio_wakeup(struct gpio_bank *bank, int gpio, int enable) unsigned long flags; if (bank->non_wakeup_gpios & gpio_bit) { - dev_err(bank->dev, + dev_err(bank->dev, "Unable to modify wakeup on non-wakeup GPIO%d\n", gpio); return -EINVAL; } @@ -1150,6 +1151,8 @@ static void __devinit omap_gpio_chip_init(struct gpio_bank *bank) irq_set_handler_data(bank->irq, bank); } +static const struct of_device_id omap_gpio_match[]; + static int __devinit omap_gpio_probe(struct platform_device *pdev) { static int gpio_init_done; @@ -1157,11 +1160,25 @@ static int __devinit omap_gpio_probe(struct platform_device *pdev) struct resource *res; int id; struct gpio_bank *bank; + struct device_node *node = pdev->dev.of_node; + const struct of_device_id *match; + + match = of_match_device(omap_gpio_match, &pdev->dev); + if (match) { + pdata = match->data; + /* XXX: big hack until the bank_count is removed */ + of_property_read_u32(node, "bank_count", &gpio_bank_count); + if (of_property_read_u32(node, "id", &id)) + return -EINVAL; + /* XXX: maybe the id in DT should be zero based to avoid that */ + id -= 1; + } else { + if (!pdev->dev.platform_data) + return -EINVAL; - if (!pdev->dev.platform_data) - return -EINVAL; - - pdata = pdev->dev.platform_data; + pdata = pdev->dev.platform_data; + id = pdev->id; + } if (!gpio_init_done) { int ret; @@ -1171,7 +1188,6 @@ static int __devinit omap_gpio_probe(struct platform_device *pdev) return ret; } - id = pdev->id; bank = &gpio_bank[id]; res = platform_get_resource(pdev, IORESOURCE_IRQ, 0); @@ -1181,12 +1197,19 @@ static int __devinit omap_gpio_probe(struct platform_device *pdev) } bank->irq = res->start; - bank->virtual_irq_start = pdata->virtual_irq_start; bank->method = pdata->bank_type; bank->dev = &pdev->dev; - bank->dbck_flag = pdata->dbck_flag; bank->stride = pdata->bank_stride; - bank->width = pdata->bank_width; + if (match) { + of_property_read_u32(node, "bank_width", &bank->width); + if (of_get_property(node, "debounce", NULL)) + bank->dbck_flag = true; + bank->virtual_irq_start = IH_GPIO_BASE + 32 * id; + } else { + bank->width = pdata->bank_width; + bank->dbck_flag = pdata->dbck_flag; + bank->virtual_irq_start = pdata->virtual_irq_start; + } bank->regs = pdata->regs; @@ -1559,10 +1582,72 @@ void omap_gpio_restore_context(void) } #endif + +static struct omap_gpio_reg_offs omap2_gpio_regs = { + .revision = OMAP24XX_GPIO_REVISION, + .direction = OMAP24XX_GPIO_OE, + .datain = OMAP24XX_GPIO_DATAIN, + .dataout = OMAP24XX_GPIO_DATAOUT, + .set_dataout = OMAP24XX_GPIO_SETDATAOUT, + .clr_dataout = OMAP24XX_GPIO_CLEARDATAOUT, + .irqstatus = OMAP24XX_GPIO_IRQSTATUS1, + .irqstatus2 = OMAP24XX_GPIO_IRQSTATUS2, + .irqenable = OMAP24XX_GPIO_IRQENABLE1, + .set_irqenable = OMAP24XX_GPIO_SETIRQENABLE1, + .clr_irqenable = OMAP24XX_GPIO_CLEARIRQENABLE1, + .debounce = OMAP24XX_GPIO_DEBOUNCE_VAL, + .debounce_en = OMAP24XX_GPIO_DEBOUNCE_EN, +}; + +static struct omap_gpio_platform_data omap2_pdata = { + .bank_type = METHOD_GPIO_24XX, + .regs = &omap2_gpio_regs, +}; + +static struct omap_gpio_reg_offs omap4_gpio_regs = { + .revision = OMAP4_GPIO_REVISION, + .direction = OMAP4_GPIO_OE, + .datain = OMAP4_GPIO_DATAIN, + .dataout = OMAP4_GPIO_DATAOUT, + .set_dataout = OMAP4_GPIO_SETDATAOUT, + .clr_dataout = OMAP4_GPIO_CLEARDATAOUT, + .irqstatus = OMAP4_GPIO_IRQSTATUS1, + .irqstatus2 = OMAP4_GPIO_IRQSTATUS2, + .irqenable = OMAP4_GPIO_IRQENABLE1, + .set_irqenable = OMAP4_GPIO_SETIRQENABLE1, + .clr_irqenable = OMAP4_GPIO_CLEARIRQENABLE1, + .debounce = OMAP4_GPIO_DEBOUNCINGTIME, + .debounce_en = OMAP4_GPIO_DEBOUNCENABLE, +}; + +static struct omap_gpio_platform_data omap4_pdata = { + .bank_type = METHOD_GPIO_44XX, + .regs = &omap4_gpio_regs, +}; + + +#if defined(CONFIG_OF) + static const struct of_device_id omap_gpio_match[] = { + { + .compatible = "ti,omap4-gpio", + .data = &omap4_pdata, + }, + { + .compatible = "ti,omap2-gpio", + .data = &omap2_pdata, + }, + {}, +} +MODULE_DEVICE_TABLE(of, omap_gpio_match); +#else +#define omap_gpio_match NULL +#endif + static struct platform_driver omap_gpio_driver = { .probe = omap_gpio_probe, .driver = { .name = "omap_gpio", + .of_match_table = omap_gpio_match, }, };