gpio: add DT support for memory-mapped GPIOs
Subsystems (2)
v7 cover gpio: add DT support for memory-mapped GPIOs
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].
The drivers for gpio-clps711x, gpio-ge, gpio-moxart and gpio-ts4800 are now part of the gpio-mmio.c driver. The old driver files have been removed and the Kconfig, Makefile entries have been updated accordingly.
And finally, the most important stat about the series:
>>> 333 insertions(+), 411 deletions(-) <<< It still removes more lines than it adds!
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:
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 (2):
gpio: dt-bindings: add wd,mbl-gpio bindings
gpio: move clps711x, moxart, ts4800 and gpio-ge into gpio-mmio
?lvaro Fern?ndez Rojas (1):
gpio: mmio: add DT support for memory-mapped GPIOs
.../devicetree/bindings/gpio/wd,mbl-gpio.txt | 38 +++ drivers/gpio/Kconfig | 43 +-- drivers/gpio/Makefile | 4 - drivers/gpio/gpio-clps711x.c | 91 ------- drivers/gpio/gpio-ge.c | 114 -------- drivers/gpio/gpio-mmio.c | 289 ++++++++++++++++++++- drivers/gpio/gpio-moxart.c | 84 ------ drivers/gpio/gpio-ts4800.c | 81 ------ 8 files changed, 333 insertions(+), 411 deletions(-) create mode 100644 Documentation/devicetree/bindings/gpio/wd,mbl-gpio.txt delete mode 100644 drivers/gpio/gpio-clps711x.c delete mode 100644 drivers/gpio/gpio-ge.c delete mode 100644 drivers/gpio/gpio-moxart.c delete mode 100644 drivers/gpio/gpio-ts4800.c
Signature · 1 line
2.8.1
PATCH v7 1/3 gpio: dt-bindings: add wd,mbl-gpio bindings
This patch adds the device tree bindings for the Western Digital's MyBook Live memory-mapped GPIO controllers.
The gpios will be supported by gpio-mmio code of the GPIO generic library.
--- .../devicetree/bindings/gpio/wd,mbl-gpio.txt | 38 ++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 Documentation/devicetree/bindings/gpio/wd,mbl-gpio.txt
Documentation/devicetree/bindings/gpio/wd,mbl-gpio.txt new file +38 -0
@@ -0,0 +1,38 @@ +Bindings for the Western Digital's MyBook Live memory-mapped GPIO controllers. + +The Western Digital MyBook Live has two memory-mapped GPIO controllers. +Both GPIO controller only have a single 8-bit data register, where GPIO +state can be read and/or written. + +Required properties: + - compatible: should be "wd,mbl-gpio" + - reg-names: must contain + "dat" - data register + - reg: address + size pairs describing the GPIO register sets; + order must correspond with the order of entries in reg-names + - #gpio-cells: must be set to 2. The first cell is the pin number and + the second cell is used to specify the GPIO polarity: + 0 = active high + 1 = active low + - gpio-controller: marks the device node as a GPIO controller. + +Optional properties: + - no-output: GPIOs are read-only. + +Examples: + GPIO0: gpio0 at e0000000 { + compatible = "wd,mbl-gpio"; + reg-names = "dat"; + reg = <0xe0000000 0x1>; + #gpio-cells = <2>; + gpio-controller; + }; + + GPIO1: gpio1 at e0100000 { + compatible = "wd,mbl-gpio"; + reg-names = "dat"; + reg = <0xe0100000 0x1>; + #gpio-cells = <2>; + gpio-controller; + no-output; + };
Signature · 1 line
2.8.1
PATCH v7 2/3 gpio: mmio: add DT support for memory-mapped GPIOs
In reply to Christian LamparterFrom: ?lvaro Fern?ndez Rojas <[email protected]>
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 GPIO's 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. The configuration is detected by which resources are present.
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.
The first user for this binding is "wd,mbl-gpio".
--- drivers/gpio/gpio-mmio.c | 99 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 97 insertions(+), 2 deletions(-)
drivers/gpio/gpio-mmio.c +97 -2
@@ -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,89 @@ static void __iomem *bgpio_map(struct platform_device *pdev,return devm_ioremap_resource (&pdev->dev, r); } +#ifdef CONFIG_OF +static int bgpio_basic_mmio_parse_dt (struct platform_device *pdev, +struct bgpio_pdata *pdata, +unsigned long *flags) +{ +struct device *dev = &pdev->dev; +int err; + + pdata->base =-1 ; +/* If ngpio property is not specified, of_property_read_u32 +* will return -EINVAL. In this case the number of GPIOs is +* automatically determined by the register width. Any +* other error of of_property_read_u32 is due bad data and +* needs to be dealt with. +*/ + err =of_property_read_u32 (dev->of_node,"ngpio" , &pdata->ngpio); +if (err && err != -EINVAL ) +return err; + +if (of_device_is_big_endian (dev->of_node)) + *flags |=BGPIOF_BIG_ENDIAN_BYTE_ORDER ; + +if (of_property_read_bool (dev->of_node,"unreadable-reg-set" )) + *flags |=BGPIOF_UNREADABLE_REG_SET ; + +if (of_property_read_bool (dev->of_node,"unreadable-reg-dir" )) + *flags |=BGPIOF_UNREADABLE_REG_DIR ; + +if (of_property_read_bool (dev->of_node,"big-endian-byte-order" )) + *flags |=BGPIOF_BIG_ENDIAN ; + +if (of_property_read_bool (dev->of_node,"read-output-reg-set" )) + *flags |=BGPIOF_READ_OUTPUT_REG_SET ; + +if (of_property_read_bool (dev->of_node,"no-output" )) + *flags |=BGPIOF_NO_OUTPUT ; +return 0 ; +} + +#define ADD_GPIO_OF (_name, _func) { .compatible = _name, .data = _func } + +static const struct of_device_id bgpio_of_match[] = { +ADD_GPIO_OF ("wd,mbl-gpio" , bgpio_basic_mmio_parse_dt), + { } +}; +#undef ADD_GPIO_OF +MODULE_DEVICE_TABLE (of, bgpio_of_match); + +static struct bgpio_pdata *bgpio_parse_dt (struct platform_device *pdev, +unsigned long *flags) +{ +const int (*parse_dt)(struct platform_device *, +struct bgpio_pdata *,unsigned long *); +const struct device_node *node = pdev->dev.of_node; +const struct of_device_id *of_id; +struct bgpio_pdata *pdata; +int err = -ENODEV ; + + of_id =of_match_node (bgpio_of_match, node); +if (!of_id) +return NULL ; + + pdata =devm_kzalloc (&pdev->dev,sizeof (struct bgpio_pdata ), +GFP_KERNEL ); +if (!pdata) +return ERR_PTR (-ENOMEM ); + + parse_dt = (const void *)of_id->data; +if (parse_dt) + err =parse_dt (pdev, pdata, flags); +if (err) +return ERR_PTR (err); + +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 +664,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 +740,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,
Signature · 1 line
2.8.1
PATCH v7 3/3 gpio: move clps711x, moxart, ts4800 and gpio-ge into gpio-mmio
In reply to Christian LamparterThis patch integrates these GPIO drivers into gpio-mmio.
--- drivers/gpio/Kconfig | 43 ++-------- drivers/gpio/Makefile | 4 - drivers/gpio/gpio-clps711x.c | 91 --------------------- drivers/gpio/gpio-ge.c | 114 -------------------------- drivers/gpio/gpio-mmio.c | 190 +++++++++++++++++++++++++++++++++++++++++++ drivers/gpio/gpio-moxart.c | 84 ------------------- drivers/gpio/gpio-ts4800.c | 81 ------------------ 7 files changed, 198 insertions(+), 409 deletions(-) delete mode 100644 drivers/gpio/gpio-clps711x.c delete mode 100644 drivers/gpio/gpio-ge.c delete mode 100644 drivers/gpio/gpio-moxart.c delete mode 100644 drivers/gpio/gpio-ts4800.c
drivers/gpio/Kconfig +8 -35
@@ -151,13 +151,6 @@ config GPIO_BRCMSTB help Say yes here to enable GPIO support for Broadcom STB (BCM7XXX) SoCs. -config GPIO_CLPS711X - tristate "CLPS711X GPIO support" - depends on ARCH_CLPS711X || COMPILE_TEST - select GPIO_GENERIC - help - Say yes here to support GPIO on CLPS711X SoCs. - config GPIO_DAVINCI bool "TI Davinci/Keystone GPIO support" default y if ARCH_DAVINCI
@@ -193,22 +186,18 @@ config GPIO_ETRAXFS help Say yes here to support the GPIO controller on Axis ETRAX FS SoCs. -config GPIO_GE_FPGA - bool "GE FPGA based GPIO" - depends on GE_FPGA - select GPIO_GENERIC - help - Support for common GPIO functionality provided on some GE Single Board - Computers. - - This driver provides basic support (configure as input or output, read - and write pin state) for GPIO implemented in a number of GE single - board computers. - config GPIO_GENERIC_PLATFORM tristate "Generic memory-mapped GPIO controller support (MMIO platform device)" select GPIO_GENERIC help + Select this to support many generic memory-mapped GPIO controllers. + + This driver also includes support for the following GPIOs: + CLPS711X SoCs + MOXA ART SoC + TS-4800 FPGA DIO blocks and compatibles. + GPIOs found on some GE Single Board Computers. + Say yes here to support basic platform_device memory-mapped GPIO controllers. config GPIO_GRGPIO
@@ -285,14 +274,6 @@ config GPIO_MM_LANTIQ (EBU) found on Lantiq SoCs. The gpios are output only as they are created by attaching a 16bit latch to the bus. -config GPIO_MOXART - bool "MOXART GPIO support" - depends on ARCH_MOXART || COMPILE_TEST - select GPIO_GENERIC - help - Select this option to enable GPIO driver for - MOXA ART SoC devices. - config GPIO_MPC5200 def_bool y depends on PPC_MPC52xx
@@ -404,14 +385,6 @@ config GPIO_TEGRA default y depends on ARCH_TEGRA || COMPILE_TEST -config GPIO_TS4800 - tristate "TS-4800 DIO blocks and compatibles" - depends on OF_GPIO - depends on SOC_IMX51 || COMPILE_TEST - select GPIO_GENERIC - help - This driver support TS-4800 FPGA GPIO controllers. - config GPIO_TZ1090 bool "Toumaz Xenif TZ1090 GPIO support" depends on SOC_TZ1090
drivers/gpio/Makefile +0 -4
@@ -31,7 +31,6 @@ obj-$(CONFIG_GPIO_ATH79) += gpio-ath79.o obj-$(CONFIG_GPIO_BCM_KONA) += gpio-bcm-kona.o obj-$(CONFIG_GPIO_BRCMSTB) += gpio-brcmstb.o obj-$(CONFIG_GPIO_BT8XX) += gpio-bt8xx.o -obj-$(CONFIG_GPIO_CLPS711X) += gpio-clps711x.o obj-$(CONFIG_GPIO_CS5535) += gpio-cs5535.o obj-$(CONFIG_GPIO_CRYSTAL_COVE) += gpio-crystalcove.o obj-$(CONFIG_GPIO_DA9052) += gpio-da9052.o
@@ -43,7 +42,6 @@ obj-$(CONFIG_GPIO_EM) += gpio-em.o obj-$(CONFIG_GPIO_EP93XX) += gpio-ep93xx.o obj-$(CONFIG_GPIO_ETRAXFS) += gpio-etraxfs.o obj-$(CONFIG_GPIO_F7188X) += gpio-f7188x.o -obj-$(CONFIG_GPIO_GE_FPGA) += gpio-ge.o obj-$(CONFIG_GPIO_GRGPIO) += gpio-grgpio.o obj-$(CONFIG_GPIO_ICH) += gpio-ich.o obj-$(CONFIG_GPIO_IOP) += gpio-iop.o
@@ -68,7 +66,6 @@ obj-$(CONFIG_GPIO_MC9S08DZ60) += gpio-mc9s08dz60.o obj-$(CONFIG_GPIO_MCP23S08) += gpio-mcp23s08.o obj-$(CONFIG_GPIO_ML_IOH) += gpio-ml-ioh.o obj-$(CONFIG_GPIO_MM_LANTIQ) += gpio-mm-lantiq.o -obj-$(CONFIG_GPIO_MOXART) += gpio-moxart.o obj-$(CONFIG_GPIO_MPC5200) += gpio-mpc5200.o obj-$(CONFIG_GPIO_MPC8XXX) += gpio-mpc8xxx.o obj-$(CONFIG_GPIO_MSIC) += gpio-msic.o
@@ -107,7 +104,6 @@ obj-$(CONFIG_GPIO_TPS65218) += gpio-tps65218.o obj-$(CONFIG_GPIO_TPS6586X) += gpio-tps6586x.o obj-$(CONFIG_GPIO_TPS65910) += gpio-tps65910.o obj-$(CONFIG_GPIO_TPS65912) += gpio-tps65912.o -obj-$(CONFIG_GPIO_TS4800) += gpio-ts4800.o obj-$(CONFIG_GPIO_TS5500) += gpio-ts5500.o obj-$(CONFIG_GPIO_TWL4030) += gpio-twl4030.o obj-$(CONFIG_GPIO_TWL6040) += gpio-twl6040.o
drivers/gpio/gpio-clps711x.c deleted +0 -91
91 lines not on this page · raw message
drivers/gpio/gpio-ge.c deleted +0 -114
114 lines not on this page · raw message
drivers/gpio/gpio-mmio.c +190 -0
200 lines not on this page · raw message
drivers/gpio/gpio-moxart.c deleted +0 -84
84 lines not on this page · raw message
drivers/gpio/gpio-ts4800.c deleted +0 -81
81 lines not on this page · raw message
Signature · 1 line
2.8.1
Re: [PATCH v7 2/3] gpio: mmio: add DT support for memory-mapped GPIOs
In reply to Christian LamparterQuoted 22 lines · Christian Lamparter
From: ?lvaro Fern?ndez Rojas <[email protected]>
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 GPIO's 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. The configuration is detected by which resources are present.
Quoted 8 lines
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.The first user for this binding is "wd,mbl-gpio".
Some (mostly) style issues below.
drivers/gpio/gpio-mmio.c static void __iomem *bgpio_map(struct platform_device *pdev, · line 582
Quoted 13 lines
drivers/gpio/gpio-mmio.c +9
-0@@ -569,6 +571,89 @@ static void __iomem *bgpio_map(struct platform_device *pdev,return devm_ioremap_resource (&pdev->dev, r); } +#ifdef CONFIG_OF +static int bgpio_basic_mmio_parse_dt (struct platform_device *pdev, +struct bgpio_pdata *pdata, +unsigned long *flags) +{ +struct device *dev = &pdev->dev; +int err; + + pdata->base =-1 ;
+ empty line
drivers/gpio/gpio-mmio.c static void __iomem *bgpio_map(struct platform_device *pdev, · line 587
Quoted 5 lines
drivers/gpio/gpio-mmio.c +5
-0+/* If ngpio property is not specified, of_property_read_u32 +* will return -EINVAL. In this case the number of GPIOs is +* automatically determined by the register width. Any +* other error of of_property_read_u32 is due bad data and +* needs to be dealt with.
Couple style issues:
/*
* First sentence starts here. func() are going with parens. */
Quoted 33 lines
drivers/gpio/gpio-mmio.c +33
-0+*/ + err =of_property_read_u32 (dev->of_node,"ngpio" , &pdata->ngpio); +if (err && err != -EINVAL ) +return err; + +if (of_device_is_big_endian (dev->of_node)) + *flags |=BGPIOF_BIG_ENDIAN_BYTE_ORDER ; + +if (of_property_read_bool (dev->of_node,"unreadable-reg-set" )) + *flags |=BGPIOF_UNREADABLE_REG_SET ; + +if (of_property_read_bool (dev->of_node,"unreadable-reg-dir" )) + *flags |=BGPIOF_UNREADABLE_REG_DIR ; + +if (of_property_read_bool (dev->of_node,"big-endian-byte-order" )) + *flags |=BGPIOF_BIG_ENDIAN ; + +if (of_property_read_bool (dev->of_node,"read-output-reg-set" )) + *flags |=BGPIOF_READ_OUTPUT_REG_SET ; + +if (of_property_read_bool (dev->of_node,"no-output" )) + *flags |=BGPIOF_NO_OUTPUT ; +return 0 ; +} + +#define ADD_GPIO_OF (_name, _func) { .compatible = _name, .data = _func } + +static const struct of_device_id bgpio_of_match[] = { +ADD_GPIO_OF ("wd,mbl-gpio" , bgpio_basic_mmio_parse_dt), + { } +}; +#undef ADD_GPIO_OF +MODULE_DEVICE_TABLE (of, bgpio_of_match);
drivers/gpio/gpio-mmio.c static void __iomem *bgpio_map(struct platform_device *pdev, · line 630
Quoted 10 lines
drivers/gpio/gpio-mmio.c +10
-0+ +static struct bgpio_pdata *bgpio_parse_dt (struct platform_device *pdev, +unsigned long *flags) +{ +const int (*parse_dt)(struct platform_device *, +struct bgpio_pdata *,unsigned long *); +const struct device_node *node = pdev->dev.of_node; +const struct of_device_id *of_id; +struct bgpio_pdata *pdata; +int err = -ENODEV ;
(1)
drivers/gpio/gpio-mmio.c static void __iomem *bgpio_map(struct platform_device *pdev, · line 634
Quoted 4 lines
drivers/gpio/gpio-mmio.c +4
-0+ + of_id =of_match_node (bgpio_of_match, node); +if (!of_id) +return NULL ;
(2)
Why so?
Quoted 21 lines
drivers/gpio/gpio-mmio.c +21
-0+ + pdata =devm_kzalloc (&pdev->dev,sizeof (struct bgpio_pdata ), +GFP_KERNEL ); +if (!pdata) +return ERR_PTR (-ENOMEM ); + + parse_dt = (const void *)of_id->data; +if (parse_dt) + err =parse_dt (pdev, pdata, flags); +if (err) +return ERR_PTR (err); + + return pdata; +} +#else +static struct bgpio_pdata *bgpio_parse_dt (struct platform_device *pdev, +unsigned long *flags) +{ +return NULL ; +} +#endif /* CONFIG_OF */
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH v7 2/3] gpio: mmio: add DT support for memory-mapped GPIOs
In reply to Christian LamparterHi,
Quoted 27 lines · Christian Lamparter
drivers/gpio/gpio-mmio.c +27
-0+static int bgpio_basic_mmio_parse_dt (struct platform_device *pdev, +struct bgpio_pdata *pdata, +unsigned long *flags) +{ +struct device *dev = &pdev->dev; +int err; + + pdata->base =-1 ; +/* If ngpio property is not specified, of_property_read_u32 +* will return -EINVAL. In this case the number of GPIOs is +* automatically determined by the register width. Any +* other error of of_property_read_u32 is due bad data and +* needs to be dealt with. +*/ + err =of_property_read_u32 (dev->of_node,"ngpio" , &pdata->ngpio); +if (err && err != -EINVAL ) +return err; + +if (of_device_is_big_endian (dev->of_node)) + *flags |=BGPIOF_BIG_ENDIAN_BYTE_ORDER ; + +if (of_property_read_bool (dev->of_node,"unreadable-reg-set" )) + *flags |=BGPIOF_UNREADABLE_REG_SET ; + +if (of_property_read_bool (dev->of_node,"unreadable-reg-dir" )) + *flags |=BGPIOF_UNREADABLE_REG_DIR ; +
drivers/gpio/gpio-mmio.c static void __iomem *bgpio_map(struct platform_device *pdev, · line 611
Quoted 10 lines
drivers/gpio/gpio-mmio.c +10
-0+if (of_property_read_bool (dev->of_node,"big-endian-byte-order" )) + *flags |=BGPIOF_BIG_ENDIAN ; + +if (of_property_read_bool (dev->of_node,"read-output-reg-set" )) + *flags |=BGPIOF_READ_OUTPUT_REG_SET ; + +if (of_property_read_bool (dev->of_node,"no-output" )) + *flags |=BGPIOF_NO_OUTPUT ; +return 0 ; +}
Other than no-output, none of these are in the wd,mbl-gpio binding.
Please remove them for now. We can add them as/when other users of this binding appear and begin to need them.
Thanks,
Mark.
Re: [PATCH v7 3/3] gpio: move clps711x, moxart, ts4800 and gpio-ge into gpio-mmio
In reply to Christian LamparterQuoted 1 line · Christian Lamparter
This patch integrates these GPIO drivers into gpio-mmio.
Would be nice to repeat a list here.
Quoted 17 lines
config
GPIO_GENERIC_PLATFORM
tristate "Generic memory-mapped GPIO controller support (MMIO platform device)" selectGPIO_GENERIC
helpdrivers/gpio/Kconfig +8
-0+ Select this to support many generic memory-mapped GPIO controllers. + + This driver also includes support for the following GPIOs: + CLPS711X SoCs + MOXA ART SoC + TS-4800 FPGA DIO blocks and compatibles. + GPIOs found on some GE Single Board Computers. + Say yes here to support basic platform_device memory-mapped GPIO controllers. config GPIO_GRGPIO@@ -285,14 +274,6 @@ config GPIO_MM_LANTIQ (EBU) found on Lantiq SoCs. The gpios are output only as they are
drivers/gpio/Kconfig config GPIO_MM_LANTIQ · line 295
Quoted 10 lines
drivers/gpio/Kconfig +0
-8created by attaching a 16bit latch to the bus. -config GPIO_MOXART - bool "MOXART GPIO support" - depends on ARCH_MOXART || COMPILE_TEST - select GPIO_GENERIC - help - Select this option to enable GPIO driver for - MOXA ART SoC devices. -
Doesn't it change behaviour? So, as a user of old .config I expect to have driver enabled. How is it achieved now?
Quoted 14 lines
drivers/gpio/gpio-mmio.c +8
-0@@ -610,10 +610,200 @@ static int bgpio_basic_mmio_parse_dt(struct platform_device *pdev,return 0 ; } +static int clps711x_parse_dt (struct platform_device *pdev, +struct bgpio_pdata *pdata, +unsigned long *flags) +{ +struct device_node *np = pdev->dev.of_node; +struct resource *res; +const char *dir_reg_name; +int id = np ?of_alias_get_id (np,"gpio" ) : pdev->id;
drivers/gpio/gpio-mmio.c static int bgpio_basic_mmio_parse_dt(struct platform_device *pdev, · line 630
Quoted 10 lines
drivers/gpio/gpio-mmio.c +9
-0+ +if ((id <0 ) || (id >4 )) +return -ENODEV ; + +/* PORTE is 3 lines only */ + pdata->ngpio = (id ==4 ) ?3 :/* determined by register width */ 0 ; + +/* PORTD is inverted logic for direction register */ + dir_reg_name = (id == 3) ? "dirin" : "dirout",
Just a nit: possible to use switch case?
Quoted 41 lines
drivers/gpio/gpio-mmio.c +41
-0+ + pdata->base = id *8 ; + + res =platform_get_resource (pdev,IORESOURCE_MEM ,0 ); +if (!res) +return -EINVAL ; +if (!res->name ||strcmp ("dat" , res->name)) + res->name =devm_kstrdup (&pdev->dev,"dat" ,GFP_KERNEL ); + + res =platform_get_resource (pdev,IORESOURCE_MEM ,1 ); +if (!res) +return -EINVAL ; +if (!res->name ||strcmp (dir_reg_name, res->name)) + res->name =devm_kstrdup (&pdev->dev, dir_reg_name,GFP_KERNEL ); + +return 0 ; +} + +static int ge_dt_cb (struct platform_device *pdev, +struct bgpio_pdata *pdata, +unsigned long *flags) +{ +struct device_node *np = pdev->dev.of_node; + + pdata->label =devm_kstrdup (&pdev->dev, np->full_name,GFP_KERNEL ); +if (!pdata->label) +return -ENOMEM ; + +return 0 ; +} + +static int moxart_dt_cb (struct platform_device *pdev, +struct bgpio_pdata *pdata, +unsigned long *flags) +{ + pdata->base =0 ; + pdata->label ="moxart-gpio" ; +return 0 ; +} + +
drivers/gpio/gpio-mmio.c static int bgpio_basic_mmio_parse_dt(struct platform_device *pdev, · line 680
Quoted 10 lines
drivers/gpio/gpio-mmio.c +10
-0+static int ts4800_dt_cb (struct platform_device *pdev, +struct bgpio_pdata *pdata, +unsigned long *flags) +{ +int err; + + err =of_property_read_u32 (pdev->dev.of_node,"ngpios" , &pdata->ngpio); +if (err == -EINVAL ) { + pdata->ngpio =16 ; + err =0 ;
return 0; ? (Up to you)
Quoted 6 lines
drivers/gpio/gpio-mmio.c +6
-0+ } +return err; +} + +struct compat_gpio_device_data { +unsigned int expected_resource_size;
drivers/gpio/gpio-mmio.c static int bgpio_basic_mmio_parse_dt(struct platform_device *pdev, · line 696
Quoted 10 lines
drivers/gpio/gpio-mmio.c +10
-0+unsigned int ngpio; +resource_size_t register_width; +unsigned long flags; +int (*call_back)(struct platform_device *pdev, +struct bgpio_pdata *pdata, +unsigned long *flags); +struct resource_replacement { +resource_size_t start_offset; +const char *name; + } resources[5 ];
I would define magic number with a description what are those 5.
Quoted 1 line
drivers/gpio/gpio-mmio.c +1
-0+};
[...]
Quoted 15 lines
drivers/gpio/gpio-mmio.c +15
-0+static int compat_parse_dt (struct platform_device *pdev, +struct bgpio_pdata *pdata, +unsigned long *flags) +{ +const struct device_node *node = pdev->dev.of_node; +const struct compat_gpio_device_data *entry; +const struct of_device_id *of_id; +struct resource *res; +int err; + + of_id =of_match_node (compat_gpio_devices, node); +if (!of_id) +return -ENODEV ; + + entry = of_id->data;
drivers/gpio/gpio-mmio.c static int bgpio_basic_mmio_parse_dt(struct platform_device *pdev, · line 764
Quoted 10 lines
drivers/gpio/gpio-mmio.c +10
-0+if (!entry || !entry->resources[0 ].name) +return -EINVAL ; + + res =platform_get_resource (pdev,IORESOURCE_MEM ,0 ); +if (!res) +return -EINVAL ; + +if (!res->name ||strcmp (entry->resources[0 ].name, res->name)) { +struct resource nres[ARRAY_SIZE (entry->resources)]; +int i;
unsigned int i; ?
Quoted 31 lines
drivers/gpio/gpio-mmio.c +31
-0+ +if (resource_size (res) != entry->expected_resource_size) +return -EINVAL ; + +for (i =0 ; i <ARRAY_SIZE (entry->resources); i++) { +if (!entry->resources[i].name) +continue ; + + nres[i].name =devm_kstrdup (&pdev->dev, + entry->resources[i].name,GFP_KERNEL ); + nres[i].start = res->start + + entry->resources[i].start_offset; + nres[i].end = nres[i].start + + entry->register_width -1 ; + nres[i].flags =IORESOURCE_MEM ; + } + + err =platform_device_add_resources (pdev, nres, i); +if (err) +return err; + } + + pdata->base =-1 ; + pdata->ngpio = entry->ngpio; + *flags = entry->flags; + +if (entry->call_back) + err = entry->call_back (pdev, pdata, flags); + +return err; +}
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH v7 2/3] gpio: mmio: add DT support for memory-mapped GPIOs
In reply to Andy ShevchenkoQuoted 10 lines · Andy Shevchenko
drivers/gpio/gpio-mmio.c static void __iomem *bgpio_map(struct platform_device *pdev, · line 587
Quoted 5 lines
drivers/gpio/gpio-mmio.c +5
-0+/* If ngpio property is not specified, of_property_read_u32 +* will return -EINVAL. In this case the number of GPIOs is +* automatically determined by the register width. Any +* other error of of_property_read_u32 is due bad data and +* needs to be dealt with. Couple style issues:
/*
* First sentence starts here.func()are going with parens. */
Ack, I'm used to drivers/net. I have to remove the ngpio in a future version, so the comment is removed as well.
Quoted 13 lines
drivers/gpio/gpio-mmio.c static void __iomem *bgpio_map(struct platform_device *pdev, · line 630
Quoted 10 lines
drivers/gpio/gpio-mmio.c +10
-0+ +static struct bgpio_pdata *bgpio_parse_dt (struct platform_device *pdev, +unsigned long *flags) +{ +const int (*parse_dt)(struct platform_device *, +struct bgpio_pdata *,unsigned long *); +const struct device_node *node = pdev->dev.of_node; +const struct of_device_id *of_id; +struct bgpio_pdata *pdata; +int err = -ENODEV ;(1)
Quoted 8 lines
drivers/gpio/gpio-mmio.c static void __iomem *bgpio_map(struct platform_device *pdev, · line 634
Quoted 4 lines
drivers/gpio/gpio-mmio.c +4
-0+ + of_id =of_match_node (bgpio_of_match, node); +if (!of_id) +return NULL ;(2)
Why so?
This is because of existing arch code in /arch/arm/mach-clps711x/board-p720t.c. You remember there's a driver with a device-tree binding "cirrus,clps711x-gpio" for it. But the current kernel arch code still registers a platform_device and it doesn't look like it has any device tree support. So this is necessary for those partially converted archs to co-exist with the driver. I'll update the -ENODEV to -EINVAL.
Quoted 21 lines
Quoted 21 lines
drivers/gpio/gpio-mmio.c +21
-0+ + pdata =devm_kzalloc (&pdev->dev,sizeof (struct bgpio_pdata ), +GFP_KERNEL ); +if (!pdata) +return ERR_PTR (-ENOMEM ); + + parse_dt = (const void *)of_id->data; +if (parse_dt) + err =parse_dt (pdev, pdata, flags); +if (err) +return ERR_PTR (err); + + return pdata; +} +#else +static struct bgpio_pdata *bgpio_parse_dt (struct platform_device *pdev, +unsigned long *flags) +{ +return NULL ; +} +#endif /* CONFIG_OF */
Re: [PATCH v7 3/3] gpio: move clps711x, moxart, ts4800 and gpio-ge into gpio-mmio
In reply to Andy ShevchenkoQuoted 5 lines · Andy Shevchenko
Quoted 1 line · Christian Lamparter
This patch integrates these GPIO drivers into gpio-mmio.
Would be nice to repeat a list here.
Ok.
Quoted 4 lines
Quoted 4 lines
(quoted diff) +0
-0@@ -285,14 +274,6 @@ config GPIO_MM_LANTIQ (EBU) found on Lantiq SoCs. The gpios are output only as they are created by attaching a 16bit latch to the bus.
Quoted 11 lines
Review config GPIO_MM_LANTIQ · line 295
Quoted 8 lines
(quoted diff) +0
-8-config GPIO_MOXART - bool "MOXART GPIO support" - depends on ARCH_MOXART || COMPILE_TEST - select GPIO_GENERIC - help - Select this option to enable GPIO driver for - MOXA ART SoC devices. -Doesn't it change behaviour? So, as a user of old .config I expect to have driver enabled. How is it achieved now?
Ok, I'll restore the configs and let them select GPIO_GENERIC_PLATFORM.
Quoted 19 lines
Quoted 18 lines
drivers/gpio/gpio-mmio.c +12
-0@@ -610,10 +610,200 @@ static int bgpio_basic_mmio_parse_dt(struct platform_device *pdev,return 0 ; } +static int clps711x_parse_dt (struct platform_device *pdev, +struct bgpio_pdata *pdata, +unsigned long *flags) +{ +struct device_node *np = pdev->dev.of_node; +struct resource *res; +const char *dir_reg_name; +int id = np ?of_alias_get_id (np,"gpio" ) : pdev->id; + +if ((id <0 ) || (id >4 )) +return -ENODEV ; +
Quoted 5 lines
drivers/gpio/gpio-mmio.c static int bgpio_basic_mmio_parse_dt(struct platform_device *pdev, · line 629
Quoted 5 lines
drivers/gpio/gpio-mmio.c +5
-0+/* PORTE is 3 lines only */ + pdata->ngpio = (id ==4 ) ?3 :/* determined by register width */ 0 ; + +/* PORTD is inverted logic for direction register */ + dir_reg_name = (id == 3) ? "dirin" : "dirout",
Actually, the , should be a ; it compiled because , is an operator. But yes, fixed.
Quoted 1 line
Just a nit: possible to use switch case?
I think so. I've integrated the id < 0 || id > 4 check as well. I don't know, I liked the old version more, it was shorter
drivers/gpio/gpio-mmio.c +18 -8
@@ -619,14 +619,25 @@ static int clps711x_parse_dt(struct platform_device *pdev,const char *dir_reg_name;int id = np ?of_alias_get_id (np,"gpio" ) : pdev->id; -if ((id <0 ) || (id >4 )) +switch (id) { +case 0 : +case 1 : +case 2 : + pdata->ngpio =0 ;/* determined by register width */ + dir_reg_name ="dirout" ; +break ; +case 3 : + pdata->ngpio =0 ;/* determined by register width */ +/* PORTD is inverted logic for direction register */ + dir_reg_name ="dirin" ; +break ; +case 4 : + pdata->ngpio =3 ;/* PORTE is 3 lines only */ + dir_reg_name ="dirout" ; +break ; +default :return -ENODEV ; - -/* PORTE is 3 lines only */ - pdata->ngpio = (id ==4 ) ?3 :/* determined by register width */ 0 ; - -/* PORTD is inverted logic for direction register */ - dir_reg_name = (id ==3 ) ?"dirin" :"dirout" , + } pdata->base = id *8 ; ---
Quoted 17 lines
Quoted 17 lines
drivers/gpio/gpio-mmio.c +17
-0+ + pdata->base = id *8 ; + + res =platform_get_resource (pdev,IORESOURCE_MEM ,0 ); +if (!res) +return -EINVAL ; +if (!res->name ||strcmp ("dat" , res->name)) + res->name =devm_kstrdup (&pdev->dev,"dat" ,GFP_KERNEL ); + + res =platform_get_resource (pdev,IORESOURCE_MEM ,1 ); +if (!res) +return -EINVAL ; +if (!res->name ||strcmp (dir_reg_name, res->name)) + res->name =devm_kstrdup (&pdev->dev, dir_reg_name,GFP_KERNEL ); + +return 0 ; +}
[...]
Quoted 13 lines
drivers/gpio/gpio-mmio.c
Quoted 12 lines
drivers/gpio/gpio-mmio.c +12
-0+struct compat_gpio_device_data { +unsigned int expected_resource_size; +unsigned int ngpio; +resource_size_t register_width; +unsigned long flags; +int (*call_back)(struct platform_device *pdev, +struct bgpio_pdata *pdata, +unsigned long *flags); +struct resource_replacement { +resource_size_t start_offset; +const char *name; + } resources[5 ];
Quoted 1 line
I would define magic number with a description what are those 5.
Difficult, these are 5 placeholders for the named resources. There's particular order so a enum like
{
DAT,
SET,
CLR,
DIRIN,
DIROUT,
__NUM_RES
}might look nice but it has no purpose other than maybe confusing people why the entries aren't used.
Quoted 23 lines
Quoted 1 line
+};
[...]
Quoted 19 lines
drivers/gpio/gpio-mmio.c +19
-0+static int compat_parse_dt (struct platform_device *pdev, +struct bgpio_pdata *pdata, +unsigned long *flags) +{ +const struct device_node *node = pdev->dev.of_node; +const struct compat_gpio_device_data *entry; +const struct of_device_id *of_id; +struct resource *res; +int err; + + of_id =of_match_node (compat_gpio_devices, node); +if (!of_id) +return -ENODEV ; + + entry = of_id->data; +if (!entry || !entry->resources[0 ].name) +return -EINVAL ; + + res =platform_get_resource (pdev,IORESOURCE_MEM ,0 );
Quoted 8 lines
drivers/gpio/gpio-mmio.c
Quoted 6 lines
drivers/gpio/gpio-mmio.c +6
-0+if (!res) +return -EINVAL ; + +if (!res->name ||strcmp (entry->resources[0 ].name, res->name)) { +struct resource nres[ARRAY_SIZE (entry->resources)]; +int i;unsigned int i; ?
yes. I think I change it to size_t. ARRAY_SIZE uses sizeof internally.
Regards,
Christian
Re: [PATCH v7 3/3] gpio: move clps711x, moxart, ts4800 and gpio-ge into gpio-mmio
Quoted 32 lines · Christian Lamparter
Quoted 4 lines · Andy Shevchenko
On Fri, May 6, 2016 at 2:10 PM, Christian Lamparter <[email protected]> wrote:
Just a nit: possible to use switch case?
I think so. I've integrated the id < 0 || id > 4 check as well. I don't know, I liked the old version more, it was shorter
drivers/gpio/gpio-mmio.c +15
-1@@ -619,14 +619,25 @@ static int clps711x_parse_dt(struct platform_device *pdev,const char *dir_reg_name;int id = np ?of_alias_get_id (np,"gpio" ) : pdev->id; -if ((id <0 ) || (id >4 )) +switch (id) { +case 0 : +case 1 : +case 2 : + pdata->ngpio =0 ;/* determined by register width */ + dir_reg_name ="dirout" ; +break ; +case 3 : + pdata->ngpio =0 ;/* determined by register width */ +/* PORTD is inverted logic for direction register */ + dir_reg_name ="dirin" ; +break ; +case 4 : + pdata->ngpio =3 ;/* PORTE is 3 lines only */ + dir_reg_name ="dirout" ;
drivers/gpio/gpio-mmio.c static int clps711x_parse_dt(struct platform_device *pdev, · line 640
Quoted 10 lines
drivers/gpio/gpio-mmio.c +3
-6+break ; +default :return -ENODEV ; - -/* PORTE is 3 lines only */ - pdata->ngpio = (id ==4 ) ?3 :/* determined by register width */ 0 ; - -/* PORTD is inverted logic for direction register */ - dir_reg_name = (id == 3) ? "dirin" : "dirout", + }
For my personal taste the switch case more understandable / readable. But i'm not totally objecting the old model, just a subject to discuss.
Quoted 26 lines
drivers/gpio/gpio-mmio.c +0
-0> > +struct compat_gpio_device_data { > > + unsigned int expected_resource_size; > > + unsigned int ngpio;Quoted 11 lines
Review
Quoted 9 lines
(quoted diff) +9
-0+ resource_size_t register_width; + unsigned long flags; + int (*call_back)(struct platform_device *pdev, + struct bgpio_pdata *pdata, + unsigned long *flags); + struct resource_replacement { + resource_size_t start_offset; + const char *name; + } resources[5];I would define magic number with a description what are those 5.
Difficult, these are 5 placeholders for the named resources. There's particular order so a enum like
{ DAT, SET, CLR, DIRIN, DIROUT, __NUM_RES }
Quoted 2 lines
might look nice but it has no purpose other than maybe confusing people why the entries aren't used.
OK, might be just
#define ?_SUPPORTED_RES_MAX 5
?
} resources[_SUPPORTED_RES_MAX];
Signature · 2 lines
With Best Regards, Andy Shevchenko