From patchwork Thu Jun 11 10:32:15 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Romain Baeriswyl X-Patchwork-Id: 483051 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 753D014029E for ; Thu, 11 Jun 2015 20:32:36 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752772AbbFKKcf (ORCPT ); Thu, 11 Jun 2015 06:32:35 -0400 Received: from nopam.alitech.com ([202.3.176.31]:39145 "EHLO nopam.alitech.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932070AbbFKKcb (ORCPT ); Thu, 11 Jun 2015 06:32:31 -0400 Received: from localhost (localhost [127.0.0.1]) by nopam.alitech.com (Postfix) with ESMTP id A93B972C0D47; Thu, 11 Jun 2015 18:34:22 +0800 (CST) split_mail: 1 Received: from twalins2.ali.net (unknown [192.168.200.12]) by nopam.alitech.com (Postfix) with ESMTP id DD73372C0CEB; Thu, 11 Jun 2015 18:34:21 +0800 (CST) Received: from ab24.lan ([10.41.22.152]) by twalins2 (Lotus Domino Release 8.0.2FP6) with ESMTP id 2015061118345128-1803 ; Thu, 11 Jun 2015 18:34:51 +0800 From: Romain Baeriswyl To: Linus Walleij , Alexandre Courbot , linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, Christian Ruppert , Anton Vorontsov , Rojhalat Ibrahim , abdoulaye berthe , Anthony Fee , Alexander Shiyan , devicetree@vger.kernel.org Cc: Romain Baeriswyl Subject: [PATCH V2] added device tree support to gpio-generic driver Date: Thu, 11 Jun 2015 12:32:15 +0200 Message-Id: <1434018735-10176-1-git-send-email-romain.baeriswyl@alitech.com> X-Mailer: git-send-email 1.7.1 In-Reply-To: References: X-MIMETrack: =?Big5?B?SXRlbWl6ZSBieSBTTVRQIFNlcnZlciBvbiBUV0FMSU5TMi9BTElfVFBFL0FMaSg=?= =?Big5?B?UmVsZWFzZSA4LjAuMkZQNnxKdWx5IDE1LCAyMDEwKSBhdCAyMDE1LzA2LzExIKRV?= =?Big5?B?pMggMDY6MzQ6NTE=?=, =?Big5?B?U2VyaWFsaXplIGJ5IFJvdXRlciBvbiBUV0FMSU5TMi9BTElfVFBFL0FMaSg=?= =?Big5?B?UmVsZWFzZSA4LjAuMkZQNnxKdWx5IDE1LCAyMDEwKSBhdCAyMDE1LzA2LzExIKRV?= =?Big5?B?pMggMDY6MzQ6NTM=?=, =?Big5?B?U2VyaWFsaXplIGNvbXBsZXRlIGF0IDIwMTUvMDYvMTEgpFWkyCAwNjozNDo1Mw==?= X-TNEFEvaluated: 1 Sender: linux-gpio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org This patch adds support of device tree to the gpio-generic driver. Signed-off-by: Romain Baeriswyl --- .../devicetree/bindings/gpio/gpio-generic.txt | 17 +++++ drivers/gpio/gpio-generic.c | 72 +++++++++++++++---- include/linux/basic_mmio_gpio.h | 1 + 3 files changed, 75 insertions(+), 15 deletions(-) create mode 100644 Documentation/devicetree/bindings/gpio/gpio-generic.txt diff --git a/Documentation/devicetree/bindings/gpio/gpio-generic.txt b/Documentation/devicetree/bindings/gpio/gpio-generic.txt new file mode 100644 index 0000000..20e3727 --- /dev/null +++ b/Documentation/devicetree/bindings/gpio/gpio-generic.txt @@ -0,0 +1,17 @@ +Bindings for gpio-generic + +Required properties: +- compatible : should be "single-register-gpio" +- ngpios: specifies the number of gpio mapped in the register from bit 0 to + bit ngpios-1. The value is limited to the number of bits of the + LONG type. + +Optional property: +- big-endian: tells that register is big endian. + +Examples: + + gpio_a { + compatible = "single-register-gpio"; + ngpios = <32>; + }; diff --git a/drivers/gpio/gpio-generic.c b/drivers/gpio/gpio-generic.c index b92a690..8143c10 100644 --- a/drivers/gpio/gpio-generic.c +++ b/drivers/gpio/gpio-generic.c @@ -61,6 +61,8 @@ o ` ~~~~\___/~~~~ ` controller in FPGA is ,.` #include #include #include +#include +#include static void bgpio_write8(void __iomem *reg, unsigned long data) { @@ -564,6 +566,46 @@ static void __iomem *bgpio_map(struct platform_device *pdev, return ret; } +static const struct platform_device_id bgpio_id_table[] = { + { + "basic-mmio-gpio", + .driver_data = 0, + }, { + "basic-mmio-gpio-be", + .driver_data = BGPIOF_BIG_ENDIAN + }, + { }, +}; +MODULE_DEVICE_TABLE(platform, bgpio_id_table); + +static const struct of_device_id bgpio_dt_ids[] = { + { .compatible = "single-register-gpio" }, + { } +}; +MODULE_DEVICE_TABLE(of, bgpio_dt_ids); + +static int bgpio_parse_dt(struct device *dev) +{ + struct bgpio_pdata *pdata; + + pdata = devm_kzalloc(dev, sizeof(struct bgpio_pdata), + GFP_KERNEL); + if (!pdata) + return -ENOMEM; + + if (of_property_read_u32(dev->of_node, "ngpio", &pdata->ngpio)) { + dev_err(dev, "Failed to get field ngpio"); + return -EINVAL; + } + pdata->base = -1; + + if (of_device_is_big_endian(dev->of_node)) + pdata->flags = BGPIOF_BIG_ENDIAN; + + dev->platform_data = pdata; + return 0; +} + static int bgpio_pdev_probe(struct platform_device *pdev) { struct device *dev = &pdev->dev; @@ -574,10 +616,21 @@ static int bgpio_pdev_probe(struct platform_device *pdev) void __iomem *dirout; void __iomem *dirin; unsigned long sz; - unsigned long flags = pdev->id_entry->driver_data; int err; struct bgpio_chip *bgc; - struct bgpio_pdata *pdata = dev_get_platdata(dev); + struct bgpio_pdata *pdata; + + if (of_have_populated_dt()) { + err = bgpio_parse_dt(dev); + if (err < 0) { + dev_err(dev, "Failed to get DT data\n"); + return err; + } + } + pdata = dev_get_platdata(dev); + + if (!of_have_populated_dt()) + pdata->flags = pdev->id_entry->driver_data; r = platform_get_resource_byname(pdev, IORESOURCE_MEM, "dat"); if (!r) @@ -609,7 +662,8 @@ static int bgpio_pdev_probe(struct platform_device *pdev) if (!bgc) return -ENOMEM; - err = bgpio_init(bgc, dev, sz, dat, set, clr, dirout, dirin, flags); + err = bgpio_init(bgc, dev, sz, dat, set, clr, dirout, dirin, + pdata->flags); if (err) return err; @@ -633,18 +687,6 @@ static int bgpio_pdev_remove(struct platform_device *pdev) return bgpio_remove(bgc); } -static const struct platform_device_id bgpio_id_table[] = { - { - .name = "basic-mmio-gpio", - .driver_data = 0, - }, { - .name = "basic-mmio-gpio-be", - .driver_data = BGPIOF_BIG_ENDIAN, - }, - { } -}; -MODULE_DEVICE_TABLE(platform, bgpio_id_table); - static struct platform_driver bgpio_driver = { .driver = { .name = "basic-mmio-gpio", diff --git a/include/linux/basic_mmio_gpio.h b/include/linux/basic_mmio_gpio.h index 0e97856..d85d9ca 100644 --- a/include/linux/basic_mmio_gpio.h +++ b/include/linux/basic_mmio_gpio.h @@ -22,6 +22,7 @@ struct bgpio_pdata { const char *label; int base; int ngpio; + int flags; }; struct device;