From patchwork Sun Jan 25 17:33:18 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?=C3=81lvaro_Fern=C3=A1ndez_Rojas?= X-Patchwork-Id: 432577 X-Patchwork-Delegate: jogo@openwrt.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from arrakis.dune.hu (arrakis.dune.hu [78.24.191.176]) (using TLSv1.1 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id A7B20140077 for ; Mon, 26 Jan 2015 04:33:40 +1100 (AEDT) Received: from arrakis.dune.hu (localhost [127.0.0.1]) by arrakis.dune.hu (Postfix) with ESMTP id 07F5728BE32; Sun, 25 Jan 2015 18:31:11 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on arrakis.dune.hu X-Spam-Level: X-Spam-Status: No, score=-1.5 required=5.0 tests=BAYES_00,FREEMAIL_FROM, T_DKIM_INVALID autolearn=unavailable version=3.3.2 Received: from arrakis.dune.hu (localhost [127.0.0.1]) by arrakis.dune.hu (Postfix) with ESMTP id CA8D028BE32 for ; Sun, 25 Jan 2015 18:31:03 +0100 (CET) X-policyd-weight: using cached result; rate: -8.5 Received: from mail-wg0-f43.google.com (mail-wg0-f43.google.com [74.125.82.43]) by arrakis.dune.hu (Postfix) with ESMTPS for ; Sun, 25 Jan 2015 18:31:02 +0100 (CET) Received: by mail-wg0-f43.google.com with SMTP id y19so5484212wgg.2 for ; Sun, 25 Jan 2015 09:33:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:subject:references :in-reply-to:content-type:content-transfer-encoding; bh=nmxubYAVRQAIvBBk18/La4TmorNA4iF2oGdC4ErAUvE=; b=w5wUtD16kFFswTMd/gIga1DBUsfHfQvNPYcIB87ob5N4a/IU+LY1+TBW1B0qAL7E2I njzmiCIxoDmdS0HuabhbluMGV1lOeFdoxZlaxq23cpeKH3fkTPBgkKD6MBGkdLoM6OQG StR0E2ce07qfrullTfUuct63Vu4ogKjoy907F6hmMdpLqqYogeuf96UKgfqRjkBJuofH 98HEuG4TyWujPmmlBewMerqdZGIVavG4Jvv+ybcC0o7brnk7f8W5Bc0hfiMf6LqOdu3m CIBO7+z4NnhuKz8oR4x3rvIxfIV+zXHVOTsaezhiBUlBo7djGVjnO3ZJ3/JeDI7j1CLX a/Lw== X-Received: by 10.194.104.196 with SMTP id gg4mr34893368wjb.31.1422207206317; Sun, 25 Jan 2015 09:33:26 -0800 (PST) Received: from [192.168.1.10] (240.Red-83-49-122.dynamicIP.rima-tde.net. [83.49.122.240]) by mx.google.com with ESMTPSA id gf9sm10951092wjc.0.2015.01.25.09.33.24 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 25 Jan 2015 09:33:24 -0800 (PST) Message-ID: <54C528DE.8030504@gmail.com> Date: Sun, 25 Jan 2015 18:33:18 +0100 From: =?windows-1252?Q?=C1lvaro_Fern=E1ndez_Rojas?= User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:31.0) Gecko/20100101 Thunderbird/31.4.0 MIME-Version: 1.0 To: OpenWrt Development List , Jonas Gorski References: <5488DC9C.3000504@gmail.com> In-Reply-To: <5488DC9C.3000504@gmail.com> Subject: [OpenWrt-Devel] [PATCH V3 1/5] brcm63xx: add basic-mmio-gpio DT support X-BeenThere: openwrt-devel@lists.openwrt.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: OpenWrt Development List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: openwrt-devel-bounces@lists.openwrt.org Sender: "openwrt-devel" Signed-off-by: Álvaro Fernández Rojas diff --git a/target/linux/brcm63xx/patches-3.14/374-GPIO-generic-pdata-add-label-backport.patch b/target/linux/brcm63xx/patches-3.14/374-GPIO-generic-pdata-add-label-backport.patch new file mode 100644 index 0000000..cba5a0a --- /dev/null +++ b/target/linux/brcm63xx/patches-3.14/374-GPIO-generic-pdata-add-label-backport.patch @@ -0,0 +1,21 @@ +--- a/drivers/gpio/gpio-generic.c ++++ b/drivers/gpio/gpio-generic.c +@@ -531,6 +531,8 @@ static int bgpio_pdev_probe(struct platf + return err; + + if (pdata) { ++ if (pdata->label) ++ bgc->gc.label = pdata->label; + bgc->gc.base = pdata->base; + if (pdata->ngpio > 0) + bgc->gc.ngpio = pdata->ngpio; +--- a/include/linux/basic_mmio_gpio.h ++++ b/include/linux/basic_mmio_gpio.h +@@ -19,6 +19,7 @@ + #include + + struct bgpio_pdata { ++ const char *label; + int base; + int ngpio; + }; diff --git a/target/linux/brcm63xx/patches-3.14/375-GPIO-generic-driver-flags-backport.patch b/target/linux/brcm63xx/patches-3.14/375-GPIO-generic-driver-flags-backport.patch new file mode 100644 index 0000000..3915d2c --- /dev/null +++ b/target/linux/brcm63xx/patches-3.14/375-GPIO-generic-driver-flags-backport.patch @@ -0,0 +1,39 @@ +--- a/drivers/gpio/gpio-generic.c ++++ b/drivers/gpio/gpio-generic.c +@@ -488,7 +488,7 @@ static int bgpio_pdev_probe(struct platf + void __iomem *dirout; + void __iomem *dirin; + unsigned long sz; +- unsigned long flags = 0; ++ unsigned long flags = pdev->id_entry->driver_data; + int err; + struct bgpio_chip *bgc; + struct bgpio_pdata *pdata = dev_get_platdata(dev); +@@ -519,9 +519,6 @@ static int bgpio_pdev_probe(struct platf + if (err) + return err; + +- if (!strcmp(platform_get_device_id(pdev)->name, "basic-mmio-gpio-be")) +- flags |= BGPIOF_BIG_ENDIAN; +- + bgc = devm_kzalloc(&pdev->dev, sizeof(*bgc), GFP_KERNEL); + if (!bgc) + return -ENOMEM; +@@ -551,9 +548,14 @@ static int bgpio_pdev_remove(struct plat + } + + static const struct platform_device_id bgpio_id_table[] = { +- { "basic-mmio-gpio", }, +- { "basic-mmio-gpio-be", }, +- {}, ++ { ++ .name = "basic-mmio-gpio", ++ .driver_data = 0, ++ }, { ++ .name = "basic-mmio-gpio-be", ++ .driver_data = BGPIOF_BIG_ENDIAN, ++ }, ++ { } + }; + MODULE_DEVICE_TABLE(platform, bgpio_id_table); + diff --git a/target/linux/brcm63xx/patches-3.14/376-DT-basic-mmio-gpio.patch b/target/linux/brcm63xx/patches-3.14/376-DT-basic-mmio-gpio.patch new file mode 100644 index 0000000..cda38b2 --- /dev/null +++ b/target/linux/brcm63xx/patches-3.14/376-DT-basic-mmio-gpio.patch @@ -0,0 +1,204 @@ +--- a/Documentation/devicetree/bindings/gpio/gpio.txt ++++ b/Documentation/devicetree/bindings/gpio/gpio.txt +@@ -153,3 +153,75 @@ Example 2: + Here, three GPIO ranges are defined wrt. two pin controllers. pinctrl1 GPIO + ranges are defined using pin numbers whereas the GPIO ranges wrt. pinctrl2 + are named "foo" and "bar". ++ ++3) Generic driver for memory-mapped GPIO controllers ++---------------------------------------------------- ++The GPIO generic library provides support for basic platform_device ++memory-mapped GPIO controllers, which can be accessed by selecting Kconfig ++symbol GPIO_GENERIC and using library functions provided by GPIO generic ++driver (see drivers/gpio/gpio-generic.c). ++The simplest form of a GPIO controller that the driver support is just a ++single "data" register, where GPIO state can be read and/or written. ++ ++The driver supports: ++- 8/16/32/64 bits registers. The number of GPIOs is determined by the width of ++ the registers. ++- GPIO controllers with clear/set registers. ++- GPIO controllers with a single "data" register. ++- Big endian bits/GPIOs ordering. ++ ++For setting GPIO's there are three supported configurations: ++- single input/output register resource (named "dat"). ++- set/clear pair (named "set" and "clr"). ++- single output register resource and single input resource ("set" and dat"). ++ ++For setting the GPIO direction, there are three supported configurations: ++- simple bidirection GPIO that requires no configuration. ++- an output direction register (named "dirout") where a 1 bit indicates the ++ GPIO is an output. ++- an input direction register (named "dirin") where a 1 bit indicates the GPIO ++ is an input. ++ ++Required properties: ++- compatible : Should be "basic-mmio-gpio". ++- reg : Address and length of the registers needed for the device. ++- reg-names : Names of the needed registers. ++- #gpio-cells : Should be two. The first cell is the pin number and ++ the second cell is used to specify optional parameters (currently ++ unused). ++- gpio-controller : Marks the device node as a gpio controller. ++ ++Optional properties: ++- num-gpios : Specify the number of configurable gpios. ++- bit-be : Use big endian order for pins. ++- byte-be : Use big endian byte order for registers. ++- regset-wo : set register is unreadable. ++- regdir-wo : dir register is unreadable. ++ ++Examples: ++ ++gpio0: gpio-controller@10000084 { ++ compatible = "brcm,brcm6368", "basic-mmio-gpio"; ++ reg = <0x10000084 0x4>, <0x1000008c 0x4>; ++ reg-names = "dirout", "dat"; ++ ++ gpio-controller; ++ #gpio-cells = <2>; ++ ++ num-gpios = <32>; ++ byte-be; ++}; ++ ++gpio1: gpio-controller@10000180 { ++ compatible = "foo,bar", "basic-mmio-gpio"; ++ reg = <0x10000180 0x4>, <0x10000184 0x4>, <0x10000188 0x4>; ++ reg-names = "dirin", "dirout", "dat"; ++ ++ gpio-controller; ++ #gpio-cells = <2>; ++ ++ num-gpios = <20>; ++ bit-be; ++ byte-be; ++ regdir-wo; ++}; +--- a/drivers/gpio/gpio-generic.c ++++ b/drivers/gpio/gpio-generic.c +@@ -61,6 +61,9 @@ o ` ~~~~\___/ + #include + #include + #include ++#include ++#include ++#include + + static void bgpio_write8(void __iomem *reg, unsigned long data) + { +@@ -478,8 +481,58 @@ static void __iomem *bgpio_map(struct pl + return ret; + } + ++#ifdef CONFIG_OF ++static const struct of_device_id bgpio_dt_ids[] = { ++ { .compatible = "basic-mmio-gpio" }, ++}; ++MODULE_DEVICE_TABLE(of, bgpio_dt_ids); ++ ++static int bgpio_probe_dt(struct platform_device *pdev) ++{ ++ u32 tmp; ++ struct bgpio_pdata *pdata; ++ struct device_node *np; ++ ++ np = pdev->dev.of_node; ++ if (!np) ++ return 0; ++ ++ pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL); ++ if (!pdata) ++ return -ENOMEM; ++ ++ pdata->label = dev_name(&pdev->dev); ++ pdata->base = -1; ++ if (of_find_property(np, "byte-be", NULL)) { ++ pdata->flags |= BGPIOF_BIG_ENDIAN_BYTE_ORDER; ++ } ++ if (of_find_property(np, "bit-be", NULL)) { ++ pdata->flags |= BGPIOF_BIG_ENDIAN; ++ } ++ if (of_find_property(np, "regset-wo", NULL)) { ++ pdata->flags |= BGPIOF_UNREADABLE_REG_SET; ++ } ++ if (of_find_property(np, "regdir-wo", NULL)) { ++ pdata->flags |= BGPIOF_UNREADABLE_REG_DIR; ++ } ++ if (!of_property_read_u32(np, "num-gpios", &tmp)) { ++ pdata->ngpio = tmp; ++ } ++ ++ pdev->dev.platform_data = pdata; ++ ++ return 1; ++} ++#else ++static inline int bgpio_probe_dt(struct platform_device *pdev) ++{ ++ return 0; ++} ++#endif ++ + static int bgpio_pdev_probe(struct platform_device *pdev) + { ++ int status; + struct device *dev = &pdev->dev; + struct resource *r; + void __iomem *dat; +@@ -488,10 +541,24 @@ static int bgpio_pdev_probe(struct platf + void __iomem *dirout; + void __iomem *dirin; + unsigned long sz; +- unsigned long flags = pdev->id_entry->driver_data; ++ unsigned long flags; + int err; + struct bgpio_chip *bgc; +- struct bgpio_pdata *pdata = dev_get_platdata(dev); ++ struct bgpio_pdata *pdata; ++ bool use_of = 0; ++ ++ status = bgpio_probe_dt(pdev); ++ if (status < 0) ++ return status; ++ if (status > 0) ++ use_of = 1; ++ ++ pdata = dev_get_platdata(dev); ++ ++ if (!use_of) ++ flags = pdev->id_entry->driver_data; ++ else if (pdata) ++ flags = pdata->flags; + + r = platform_get_resource_byname(pdev, IORESOURCE_MEM, "dat"); + if (!r) +@@ -537,6 +604,9 @@ static int bgpio_pdev_probe(struct platf + + platform_set_drvdata(pdev, bgc); + ++ if (use_of) ++ of_gpiochip_add(&bgc->gc); ++ + return gpiochip_add(&bgc->gc); + } + +@@ -562,6 +632,7 @@ MODULE_DEVICE_TABLE(platform, bgpio_id_t + static struct platform_driver bgpio_driver = { + .driver = { + .name = "basic-mmio-gpio", ++ .of_match_table = bgpio_dt_ids, + }, + .id_table = bgpio_id_table, + .probe = bgpio_pdev_probe, +--- 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; ++ unsigned long flags; + }; + + struct device; diff --git a/target/linux/brcm63xx/patches-3.18/374-DT-basic-mmio-gpio.patch b/target/linux/brcm63xx/patches-3.18/374-DT-basic-mmio-gpio.patch new file mode 100644 index 0000000..ba9f2ce --- /dev/null +++ b/target/linux/brcm63xx/patches-3.18/374-DT-basic-mmio-gpio.patch @@ -0,0 +1,204 @@ +--- a/Documentation/devicetree/bindings/gpio/gpio.txt ++++ b/Documentation/devicetree/bindings/gpio/gpio.txt +@@ -197,3 +197,75 @@ Example 2: + Here, three GPIO ranges are defined wrt. two pin controllers. pinctrl1 GPIO + ranges are defined using pin numbers whereas the GPIO ranges wrt. pinctrl2 + are named "foo" and "bar". ++ ++3) Generic driver for memory-mapped GPIO controllers ++---------------------------------------------------- ++The GPIO generic library provides support for basic platform_device ++memory-mapped GPIO controllers, which can be accessed by selecting Kconfig ++symbol GPIO_GENERIC and using library functions provided by GPIO generic ++driver (see drivers/gpio/gpio-generic.c). ++The simplest form of a GPIO controller that the driver support is just a ++single "data" register, where GPIO state can be read and/or written. ++ ++The driver supports: ++- 8/16/32/64 bits registers. The number of GPIOs is determined by the width of ++ the registers. ++- GPIO controllers with clear/set registers. ++- GPIO controllers with a single "data" register. ++- Big endian bits/GPIOs ordering. ++ ++For setting GPIO's there are three supported configurations: ++- single input/output register resource (named "dat"). ++- set/clear pair (named "set" and "clr"). ++- single output register resource and single input resource ("set" and dat"). ++ ++For setting the GPIO direction, there are three supported configurations: ++- simple bidirection GPIO that requires no configuration. ++- an output direction register (named "dirout") where a 1 bit indicates the ++ GPIO is an output. ++- an input direction register (named "dirin") where a 1 bit indicates the GPIO ++ is an input. ++ ++Required properties: ++- compatible : Should be "basic-mmio-gpio". ++- reg : Address and length of the registers needed for the device. ++- reg-names : Names of the needed registers. ++- #gpio-cells : Should be two. The first cell is the pin number and ++ the second cell is used to specify optional parameters (currently ++ unused). ++- gpio-controller : Marks the device node as a gpio controller. ++ ++Optional properties: ++- num-gpios : Specify the number of configurable gpios. ++- bit-be : Use big endian order for pins. ++- byte-be : Use big endian byte order for registers. ++- regset-wo : set register is unreadable. ++- regdir-wo : dir register is unreadable. ++ ++Examples: ++ ++gpio0: gpio-controller@10000084 { ++ compatible = "brcm,brcm6368", "basic-mmio-gpio"; ++ reg = <0x10000084 0x4>, <0x1000008c 0x4>; ++ reg-names = "dirout", "dat"; ++ ++ gpio-controller; ++ #gpio-cells = <2>; ++ ++ num-gpios = <32>; ++ byte-be; ++}; ++ ++gpio1: gpio-controller@10000180 { ++ compatible = "foo,bar", "basic-mmio-gpio"; ++ reg = <0x10000180 0x4>, <0x10000184 0x4>, <0x10000188 0x4>; ++ reg-names = "dirin", "dirout", "dat"; ++ ++ gpio-controller; ++ #gpio-cells = <2>; ++ ++ num-gpios = <20>; ++ bit-be; ++ byte-be; ++ regdir-wo; ++}; +--- a/drivers/gpio/gpio-generic.c ++++ b/drivers/gpio/gpio-generic.c +@@ -61,6 +61,9 @@ o ` ~~~~\___/ + #include + #include + #include ++#include ++#include ++#include + + static void bgpio_write8(void __iomem *reg, unsigned long data) + { +@@ -488,8 +491,58 @@ static void __iomem *bgpio_map(struct pl + return ret; + } + ++#ifdef CONFIG_OF ++static const struct of_device_id bgpio_dt_ids[] = { ++ { .compatible = "basic-mmio-gpio" }, ++}; ++MODULE_DEVICE_TABLE(of, bgpio_dt_ids); ++ ++static int bgpio_probe_dt(struct platform_device *pdev) ++{ ++ u32 tmp; ++ struct bgpio_pdata *pdata; ++ struct device_node *np; ++ ++ np = pdev->dev.of_node; ++ if (!np) ++ return 0; ++ ++ pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL); ++ if (!pdata) ++ return -ENOMEM; ++ ++ pdata->label = dev_name(&pdev->dev); ++ pdata->base = -1; ++ if (of_find_property(np, "byte-be", NULL)) { ++ pdata->flags |= BGPIOF_BIG_ENDIAN_BYTE_ORDER; ++ } ++ if (of_find_property(np, "bit-be", NULL)) { ++ pdata->flags |= BGPIOF_BIG_ENDIAN; ++ } ++ if (of_find_property(np, "regset-wo", NULL)) { ++ pdata->flags |= BGPIOF_UNREADABLE_REG_SET; ++ } ++ if (of_find_property(np, "regdir-wo", NULL)) { ++ pdata->flags |= BGPIOF_UNREADABLE_REG_DIR; ++ } ++ if (!of_property_read_u32(np, "num-gpios", &tmp)) { ++ pdata->ngpio = tmp; ++ } ++ ++ pdev->dev.platform_data = pdata; ++ ++ return 1; ++} ++#else ++static inline int bgpio_probe_dt(struct platform_device *pdev) ++{ ++ return 0; ++} ++#endif ++ + static int bgpio_pdev_probe(struct platform_device *pdev) + { ++ int status; + struct device *dev = &pdev->dev; + struct resource *r; + void __iomem *dat; +@@ -498,10 +551,24 @@ static int bgpio_pdev_probe(struct platf + void __iomem *dirout; + void __iomem *dirin; + unsigned long sz; +- unsigned long flags = pdev->id_entry->driver_data; ++ unsigned long flags; + int err; + struct bgpio_chip *bgc; +- struct bgpio_pdata *pdata = dev_get_platdata(dev); ++ struct bgpio_pdata *pdata; ++ bool use_of = 0; ++ ++ status = bgpio_probe_dt(pdev); ++ if (status < 0) ++ return status; ++ if (status > 0) ++ use_of = 1; ++ ++ pdata = dev_get_platdata(dev); ++ ++ if (!use_of) ++ flags = pdev->id_entry->driver_data; ++ else if (pdata) ++ flags = pdata->flags; + + r = platform_get_resource_byname(pdev, IORESOURCE_MEM, "dat"); + if (!r) +@@ -547,6 +614,9 @@ static int bgpio_pdev_probe(struct platf + + platform_set_drvdata(pdev, bgc); + ++ if (use_of) ++ of_gpiochip_add(&bgc->gc); ++ + return gpiochip_add(&bgc->gc); + } + +@@ -572,6 +642,7 @@ MODULE_DEVICE_TABLE(platform, bgpio_id_t + static struct platform_driver bgpio_driver = { + .driver = { + .name = "basic-mmio-gpio", ++ .of_match_table = bgpio_dt_ids, + }, + .id_table = bgpio_id_table, + .probe = bgpio_pdev_probe, +--- 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; ++ unsigned long flags; + }; + + struct device;