linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v10 0/2] gpio: add DT support for memory-mapped GPIOs
@ 2016-05-13 21:07 Christian Lamparter
  2016-05-13 21:07 ` [PATCH v10 1/2] gpio: mmio: " Christian Lamparter
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Christian Lamparter @ 2016-05-13 21:07 UTC (permalink / raw)
  To: linux-gpio, linux-kernel
  Cc: Christian Lamparter, Álvaro Fernández Rojas,
	Alexandre Courbot, Linus Walleij, Andy Shevchenko,
	Joachim Eastwood

This patch series adds device tree support for generic memory-mapped GPIOs.
The GPIO library already allows drivers and architecture support code to
reuse generic code for managing a GPIO chip. Currently, a developer has
to create a platform device "basic-mmio-gpio" and attach a bgpio_pdata
platform data structure to make use of it. However, for architectures
which rely on the device tree to enumerate devices, creating custom
platform devices is another extra step that can be avoided by having
direct support via a device tree binding.

I initially came across this patch [0] from Álvaro Fernández Rojas,
while looking for an easy way to add support for the GPIO of my
WD MyBook Live [1] (APM82181). His generic approach patch allowed
me to easily get the GPIO (and the connected LEDs, buttons, gpiohogs)
up and running. Even thought, Mr. Fernandez initially developed it
for his work on the brcm63xx [2].

There was a third patch which moved the gpio-clps711x, gpio-ge,
gpio-moxart and gpio-ts4800 into gpio-mmio.c. But it was dropped
from the series as the compat dt parser code became too dense and
complex.

Thanks!

[0] <https://patchwork.ozlabs.org/patch/422121/>
[1] <https://github.com/chunkeey/MBL-openwrt>
[2] <https://wiki.openwrt.org/doc/hardware/soc/soc.broadcom.bcm63xx>

changelog:

v9 -> v10:
	- split "gpio: mmio: add DT support for memory-mapped GPIOs"
	  into two parts.
		- PATCH 1/2 adds the DT infrastructure
		- PATCH 2/2 adds the "wd,mbl-gpio" driver binding and
		  property parser.
	- removed "move clps711x, moxart, ts4800 and gpio-ge into gpio-mmio"

v8 -> v9:
	- made dt match table grep-able
	- reorganized bgpio_dt_parse
	- dropped already applied patch (dt binding) from the series

v7 -> v8:
	- removed ngpio property parser and most flags parsers
	- converted clps711x to switch case for GPIO
	- retained original Kconfig syms which now select GPIO_GENERIC_PLATFORM

v6 -> v7:
	- finally made a PATCH series (based on linux-gpio devel branch)
	- added Rob Herring's ACK to the dt bindings
	- cc'd clps711x, gpio-ge, moxart and ts4800 authors for driver
	  changes.

v5 -> v6:
	- rewrote bindings and driver patch to fit the wd,mbl-gpio
	- unified parser code for gpio-ge, gpio-moxart and gpio-ts4800
	- fixed gpio chip's base being overwritten with bogus "0"
	- fixed compat driver crash when reload gpio-generic.ko module
	- dropped already applied patches from the series
	- rebased code on linus' devel tree
	- moved dt bindings patch to the top of the series

v4 -> v5:
	- reverted rename of gpio-mmio.c back to gpio-generic.c
	- fixed Andy Shevchenko's comments
	- consolidated changes from clps711x, gpio-ge, gpio-moxart and
	  gpio-ts4800 into one patch.

v3 -> v4:
	- renamed gpio-generic.c to gpio-mmio.c
	- changed compat. string to "linux,gpio-mmio"
	- integrated Cirrus clps711x driver
	- integrated GE FGPA gpio-ge driver
	- integrated MOXA ART GPIO driver
	- integrated TS4800 gpio driver
	- reshuffled patches, reworded commits, fixed spelling errors, etc.

Christian Lamparter (1):
  gpio: mmio: add MyBook Live GPIO support

Álvaro Fernández Rojas (1):
  gpio: mmio: add DT support for memory-mapped GPIOs

 drivers/gpio/gpio-mmio.c | 51 ++++++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 49 insertions(+), 2 deletions(-)

-- 
2.8.1

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH v10 1/2] gpio: mmio: add DT support for memory-mapped GPIOs
  2016-05-13 21:07 [PATCH v10 0/2] gpio: add DT support for memory-mapped GPIOs Christian Lamparter
@ 2016-05-13 21:07 ` Christian Lamparter
  2016-06-08  9:16   ` Linus Walleij
  2016-05-13 21:07 ` [PATCH v10 2/2] gpio: mmio: add MyBook Live GPIO support Christian Lamparter
  2016-05-24 10:43 ` [PATCH v10 0/2] gpio: add DT support for memory-mapped GPIOs Linus Walleij
  2 siblings, 1 reply; 7+ messages in thread
From: Christian Lamparter @ 2016-05-13 21:07 UTC (permalink / raw)
  To: linux-gpio, linux-kernel
  Cc: Álvaro Fernández Rojas, Alexandre Courbot,
	Linus Walleij, Andy Shevchenko, Joachim Eastwood,
	Christian Lamparter

From: Álvaro Fernández Rojas <noltari@gmail.com>

This patch adds support for defining memory-mapped GPIOs which
are compatible with the existing gpio-mmio interface. The generic
library provides support for many memory-mapped GPIO controllers
that are found in various on-board FPGA and ASIC solutions that
are used to control board's switches, LEDs, chip-selects,
Ethernet/USB PHY power, etc.

For setting GPIOs there are three configurations:
	1. single input/output register resource (named "dat"),
	2. set/clear pair (named "set" and "clr"),
	3. single output register resource and single input resource
	   ("set" and dat").

The configuration is detected by which resources are present.
For the single output register, this drives a 1 by setting a bit
and a zero by clearing a bit.  For the set clr pair, this drives
a 1 by setting a bit in the set register and clears it by setting
a bit in the clear register.

For setting the GPIO direction, there are three configurations:
	a. simple bidirectional GPIOs that requires no configuration.
	b. an output direction register (named "dirout")
	   where a 1 bit indicates the GPIO is an output.
	c. an input direction register (named "dirin")
	   where a 1 bit indicates the GPIO is an input.

Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
Signed-off-by: Álvaro Fernández Rojas <noltari@gmail.com>
Signed-off-by: Christian Lamparter <chunkeey@googlemail.com>
---
 drivers/gpio/gpio-mmio.c | 47 +++++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 45 insertions(+), 2 deletions(-)

diff --git a/drivers/gpio/gpio-mmio.c b/drivers/gpio/gpio-mmio.c
index 6c1cb3b..af583be 100644
--- a/drivers/gpio/gpio-mmio.c
+++ b/drivers/gpio/gpio-mmio.c
@@ -61,6 +61,8 @@ o        `                     ~~~~\___/~~~~    ` controller in FPGA is ,.`
 #include <linux/bitops.h>
 #include <linux/platform_device.h>
 #include <linux/mod_devicetable.h>
+#include <linux/of.h>
+#include <linux/of_device.h>
 
 static void bgpio_write8(void __iomem *reg, unsigned long data)
 {
@@ -569,6 +571,37 @@ static void __iomem *bgpio_map(struct platform_device *pdev,
 	return devm_ioremap_resource(&pdev->dev, r);
 }
 
+#ifdef CONFIG_OF
+static const struct of_device_id bgpio_of_match[] = {
+	{ }
+};
+MODULE_DEVICE_TABLE(of, bgpio_of_match);
+
+static struct bgpio_pdata *bgpio_parse_dt(struct platform_device *pdev,
+					  unsigned long *flags)
+{
+	struct bgpio_pdata *pdata;
+
+	if (!of_match_device(bgpio_of_match, &pdev->dev))
+		return NULL;
+
+	pdata = devm_kzalloc(&pdev->dev, sizeof(struct bgpio_pdata),
+			     GFP_KERNEL);
+	if (!pdata)
+		return ERR_PTR(-ENOMEM);
+
+	pdata->base = -1;
+
+	return pdata;
+}
+#else
+static struct bgpio_pdata *bgpio_parse_dt(struct platform_device *pdev,
+					  unsigned long *flags)
+{
+	return NULL;
+}
+#endif /* CONFIG_OF */
+
 static int bgpio_pdev_probe(struct platform_device *pdev)
 {
 	struct device *dev = &pdev->dev;
@@ -579,10 +612,19 @@ 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;
+	unsigned long flags = 0;
 	int err;
 	struct gpio_chip *gc;
-	struct bgpio_pdata *pdata = dev_get_platdata(dev);
+	struct bgpio_pdata *pdata;
+
+	pdata = bgpio_parse_dt(pdev, &flags);
+	if (IS_ERR(pdata))
+		return PTR_ERR(pdata);
+
+	if (!pdata) {
+		pdata = dev_get_platdata(dev);
+		flags = pdev->id_entry->driver_data;
+	}
 
 	r = platform_get_resource_byname(pdev, IORESOURCE_MEM, "dat");
 	if (!r)
@@ -646,6 +688,7 @@ MODULE_DEVICE_TABLE(platform, bgpio_id_table);
 static struct platform_driver bgpio_driver = {
 	.driver = {
 		.name = "basic-mmio-gpio",
+		.of_match_table = of_match_ptr(bgpio_of_match),
 	},
 	.id_table = bgpio_id_table,
 	.probe = bgpio_pdev_probe,
-- 
2.8.1

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH v10 2/2] gpio: mmio: add MyBook Live GPIO support
  2016-05-13 21:07 [PATCH v10 0/2] gpio: add DT support for memory-mapped GPIOs Christian Lamparter
  2016-05-13 21:07 ` [PATCH v10 1/2] gpio: mmio: " Christian Lamparter
@ 2016-05-13 21:07 ` Christian Lamparter
  2016-06-08  9:17   ` Linus Walleij
  2016-05-24 10:43 ` [PATCH v10 0/2] gpio: add DT support for memory-mapped GPIOs Linus Walleij
  2 siblings, 1 reply; 7+ messages in thread
From: Christian Lamparter @ 2016-05-13 21:07 UTC (permalink / raw)
  To: linux-gpio, linux-kernel
  Cc: Christian Lamparter, Álvaro Fernández Rojas,
	Alexandre Courbot, Linus Walleij, Andy Shevchenko,
	Joachim Eastwood

This patch adds support for the Western Digital's
MyBook Live memory-mapped GPIO controllers.

The GPIOs will be supported by the generic driver
for memory-mapped GPIO controllers.

Signed-off-by: Christian Lamparter <chunkeey@googlemail.com>
---
 drivers/gpio/gpio-mmio.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/drivers/gpio/gpio-mmio.c b/drivers/gpio/gpio-mmio.c
index af583be..6ec144b 100644
--- a/drivers/gpio/gpio-mmio.c
+++ b/drivers/gpio/gpio-mmio.c
@@ -573,6 +573,7 @@ static void __iomem *bgpio_map(struct platform_device *pdev,
 
 #ifdef CONFIG_OF
 static const struct of_device_id bgpio_of_match[] = {
+	{ .compatible = "wd,mbl-gpio" },
 	{ }
 };
 MODULE_DEVICE_TABLE(of, bgpio_of_match);
@@ -592,6 +593,9 @@ static struct bgpio_pdata *bgpio_parse_dt(struct platform_device *pdev,
 
 	pdata->base = -1;
 
+	if (of_property_read_bool(pdev->dev.of_node, "no-output"))
+		*flags |= BGPIOF_NO_OUTPUT;
+
 	return pdata;
 }
 #else
-- 
2.8.1

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v10 0/2] gpio: add DT support for memory-mapped GPIOs
  2016-05-13 21:07 [PATCH v10 0/2] gpio: add DT support for memory-mapped GPIOs Christian Lamparter
  2016-05-13 21:07 ` [PATCH v10 1/2] gpio: mmio: " Christian Lamparter
  2016-05-13 21:07 ` [PATCH v10 2/2] gpio: mmio: add MyBook Live GPIO support Christian Lamparter
@ 2016-05-24 10:43 ` Linus Walleij
  2016-06-07  3:49   ` Alexandre Courbot
  2 siblings, 1 reply; 7+ messages in thread
From: Linus Walleij @ 2016-05-24 10:43 UTC (permalink / raw)
  To: Christian Lamparter
  Cc: linux-gpio, linux-kernel, Álvaro Fernández Rojas,
	Alexandre Courbot, Andy Shevchenko, Joachim Eastwood

On Fri, May 13, 2016 at 11:07 PM, Christian Lamparter
<chunkeey@googlemail.com> wrote:

> v9 -> v10:
>         - split "gpio: mmio: add DT support for memory-mapped GPIOs"
>           into two parts.
>                 - PATCH 1/2 adds the DT infrastructure
>                 - PATCH 2/2 adds the "wd,mbl-gpio" driver binding and
>                   property parser.
>         - removed "move clps711x, moxart, ts4800 and gpio-ge into gpio-mmio"

This minimal patch set looks good to me, Alexandre is this OK with you?

Yours,
Linus Walleij

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v10 0/2] gpio: add DT support for memory-mapped GPIOs
  2016-05-24 10:43 ` [PATCH v10 0/2] gpio: add DT support for memory-mapped GPIOs Linus Walleij
@ 2016-06-07  3:49   ` Alexandre Courbot
  0 siblings, 0 replies; 7+ messages in thread
From: Alexandre Courbot @ 2016-06-07  3:49 UTC (permalink / raw)
  To: Linus Walleij
  Cc: Christian Lamparter, linux-gpio, linux-kernel,
	Álvaro Fernández Rojas, Andy Shevchenko,
	Joachim Eastwood

On Tue, May 24, 2016 at 7:43 PM, Linus Walleij <linus.walleij@linaro.org> wrote:
> On Fri, May 13, 2016 at 11:07 PM, Christian Lamparter
> <chunkeey@googlemail.com> wrote:
>
>> v9 -> v10:
>>         - split "gpio: mmio: add DT support for memory-mapped GPIOs"
>>           into two parts.
>>                 - PATCH 1/2 adds the DT infrastructure
>>                 - PATCH 2/2 adds the "wd,mbl-gpio" driver binding and
>>                   property parser.
>>         - removed "move clps711x, moxart, ts4800 and gpio-ge into gpio-mmio"
>
> This minimal patch set looks good to me, Alexandre is this OK with you?

Sorry! This look good to me, yes.

Acked-by: Alexandre Courbot <acourbot@nvidia.com>

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v10 1/2] gpio: mmio: add DT support for memory-mapped GPIOs
  2016-05-13 21:07 ` [PATCH v10 1/2] gpio: mmio: " Christian Lamparter
@ 2016-06-08  9:16   ` Linus Walleij
  0 siblings, 0 replies; 7+ messages in thread
From: Linus Walleij @ 2016-06-08  9:16 UTC (permalink / raw)
  To: Christian Lamparter
  Cc: linux-gpio, linux-kernel, Álvaro Fernández Rojas,
	Alexandre Courbot, Andy Shevchenko, Joachim Eastwood

On Fri, May 13, 2016 at 11:07 PM, Christian Lamparter
<chunkeey@googlemail.com> wrote:

> From: Álvaro Fernández Rojas <noltari@gmail.com>
>
> This patch adds support for defining memory-mapped GPIOs which
> are compatible with the existing gpio-mmio interface. The generic
> library provides support for many memory-mapped GPIO controllers
> that are found in various on-board FPGA and ASIC solutions that
> are used to control board's switches, LEDs, chip-selects,
> Ethernet/USB PHY power, etc.
>
> For setting GPIOs there are three configurations:
>         1. single input/output register resource (named "dat"),
>         2. set/clear pair (named "set" and "clr"),
>         3. single output register resource and single input resource
>            ("set" and dat").
>
> The configuration is detected by which resources are present.
> For the single output register, this drives a 1 by setting a bit
> and a zero by clearing a bit.  For the set clr pair, this drives
> a 1 by setting a bit in the set register and clears it by setting
> a bit in the clear register.
>
> For setting the GPIO direction, there are three configurations:
>         a. simple bidirectional GPIOs that requires no configuration.
>         b. an output direction register (named "dirout")
>            where a 1 bit indicates the GPIO is an output.
>         c. an input direction register (named "dirin")
>            where a 1 bit indicates the GPIO is an input.
>
> Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
> Signed-off-by: Álvaro Fernández Rojas <noltari@gmail.com>
> Signed-off-by: Christian Lamparter <chunkeey@googlemail.com>

Patch applied with Alex' ACK.

Yours,
Linus Walleij

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v10 2/2] gpio: mmio: add MyBook Live GPIO support
  2016-05-13 21:07 ` [PATCH v10 2/2] gpio: mmio: add MyBook Live GPIO support Christian Lamparter
@ 2016-06-08  9:17   ` Linus Walleij
  0 siblings, 0 replies; 7+ messages in thread
From: Linus Walleij @ 2016-06-08  9:17 UTC (permalink / raw)
  To: Christian Lamparter
  Cc: linux-gpio, linux-kernel, Álvaro Fernández Rojas,
	Alexandre Courbot, Andy Shevchenko, Joachim Eastwood

On Fri, May 13, 2016 at 11:07 PM, Christian Lamparter
<chunkeey@googlemail.com> wrote:

> This patch adds support for the Western Digital's
> MyBook Live memory-mapped GPIO controllers.
>
> The GPIOs will be supported by the generic driver
> for memory-mapped GPIO controllers.
>
> Signed-off-by: Christian Lamparter <chunkeey@googlemail.com>

Patch applied with Alex' ACK.

Yours,
Linus Walleij

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2016-06-08  9:17 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-05-13 21:07 [PATCH v10 0/2] gpio: add DT support for memory-mapped GPIOs Christian Lamparter
2016-05-13 21:07 ` [PATCH v10 1/2] gpio: mmio: " Christian Lamparter
2016-06-08  9:16   ` Linus Walleij
2016-05-13 21:07 ` [PATCH v10 2/2] gpio: mmio: add MyBook Live GPIO support Christian Lamparter
2016-06-08  9:17   ` Linus Walleij
2016-05-24 10:43 ` [PATCH v10 0/2] gpio: add DT support for memory-mapped GPIOs Linus Walleij
2016-06-07  3:49   ` Alexandre Courbot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).