diff mbox

[RFC,v3,1/3] gpio: dt-bindings: add basic-mmio-gpio bindings

Message ID 7e8845e6b6384c6b5673532ebef79c8730ed7748.1461710784.git.chunkeey@googlemail.com
State Changes Requested, archived
Headers show

Commit Message

Christian Lamparter April 26, 2016, 10:51 p.m. UTC
From: Álvaro Fernández Rojas <noltari@gmail.com>

This patch adds the device tree bindings for the basic-mmio-gpio.
The basic-mmio-gpio is already part of a the GPIO generic library
and shares its compatible with the platform device.

Signed-off-by: Álvaro Fernández Rojas <noltari@gmail.com>
Signed-off-by: Christian Lamparter <chunkeey@googlemail.com>
---
 .../devicetree/bindings/gpio/basic-mmio-gpio.txt   | 73 ++++++++++++++++++++++
 1 file changed, 73 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/gpio/basic-mmio-gpio.txt

Comments

Rob Herring April 27, 2016, 2:06 a.m. UTC | #1
On Tue, Apr 26, 2016 at 5:51 PM, Christian Lamparter
<chunkeey@googlemail.com> wrote:
> From: Álvaro Fernández Rojas <noltari@gmail.com>
>
> This patch adds the device tree bindings for the basic-mmio-gpio.
> The basic-mmio-gpio is already part of a the GPIO generic library
> and shares its compatible with the platform device.

These things always start out "simple", "basic" or "generic". Then
people extend them a property or 2 at a time until they are no longer
basic. Make a bunch of GPIO drivers use a generic driver then maybe
I'll be convinced this is a good idea. The concepts of generic code
and generic bindings don't have to be coupled.

Rob
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Rob Herring April 27, 2016, 3:08 p.m. UTC | #2
On Wed, Apr 27, 2016 at 5:15 AM, Christian Lamparter
<chunkeey@googlemail.com> wrote:
> On Tuesday, April 26, 2016 09:06:14 PM Rob Herring wrote:
>> On Tue, Apr 26, 2016 at 5:51 PM, Christian Lamparter
>> <chunkeey@googlemail.com> wrote:
>> > From: Álvaro Fernández Rojas <noltari@gmail.com>
>> >
>> > This patch adds the device tree bindings for the basic-mmio-gpio.
>> > The basic-mmio-gpio is already part of a the GPIO generic library
>> > and shares its compatible with the platform device.
>>
>> These things always start out "simple", "basic" or "generic". Then
>> people extend them a property or 2 at a time until they are no longer
>> basic. Make a bunch of GPIO drivers use a generic driver then maybe
>> I'll be convinced this is a good idea.
> Well, I mentioned brcm63xx (MIPS) and MyBook Live (PPC). But OK, if you
> want me to look at the existing code in the kernel. I found the following
> candidates.

What I meant was convert the drivers, not the dts files to a generic
driver. There is no benefit here from a dts perspective. It is driver
consolidation that would make all this worthwhile.

> 1. MOXA ART: "moxa,moxart-gpio"
> http://lxr.free-electrons.com/source/drivers/gpio/gpio-moxart.c
> This driver is used by the:
> arch/arm/boot/dts/moxart.dtsi
>
> ---
> diff --git a/arch/arm/boot/dts/moxart.dtsi b/arch/arm/boot/dts/moxart.dtsi
> index 1fd27ed..26707d0 100644
> --- a/arch/arm/boot/dts/moxart.dtsi
> +++ b/arch/arm/boot/dts/moxart.dtsi
> @@ -66,8 +66,11 @@
>                 gpio: gpio@98700000 {
>                         gpio-controller;
>                         #gpio-cells = <2>;
> -                       compatible = "moxa,moxart-gpio";
> -                       reg = <0x98700000 0xC>;
> +                       compatible = "basic-mmio-gpio";
> +                       reg = <0x98700000 0x4
> +                              0x98700004 0x4
> +                              0x98700008 0x4>;
> +                       reg-names = "set dat dirout";

This is not a compatible change. You can't remove the old drivers as
they are needed to work with old dtbs, so there is no gain.

You would need to match on existing compatibles such as
moxa,moxart-gpio and provide a match data struct that has all the info
you are adding here (e.g. data register offset). Then additionally you
could add "basic-mmio-gpio" (I would drop "basic" part) and the
additional data associated with it. But it has to be new properties,
not changing properties. Changing the reg values doesn't work.


> 2. GE FPGA based GPIO: "ge,imp3a-gpio", "gef,sbc310-gpio", "gef,sbc610-gpio"
> 3. CLPS711X GPIO driver: "cirrus,clps711x-gpio"
> 4. GPIO driver for the TS-4800 board: "technologic,ts4800-gpio"
>
> What do you think. There's a total of six devices that can make use
> of the "basic-mmio-gpio". If this gives me your go-ahead, I'll include
> them in the series as proper patches.

Those are a good start. My other worry about this is next someone will
want to add interrupt registers which is probably a majority of GPIO
controllers.

Of course, I'm sure Linus has an opinion on all of this.

Rob
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Alexandre Courbot April 28, 2016, 6:20 a.m. UTC | #3
On Thu, Apr 28, 2016 at 12:08 AM, Rob Herring <robh+dt@kernel.org> wrote:
> On Wed, Apr 27, 2016 at 5:15 AM, Christian Lamparter
> <chunkeey@googlemail.com> wrote:
>> On Tuesday, April 26, 2016 09:06:14 PM Rob Herring wrote:
>>> On Tue, Apr 26, 2016 at 5:51 PM, Christian Lamparter
>>> <chunkeey@googlemail.com> wrote:
>>> > From: Álvaro Fernández Rojas <noltari@gmail.com>
>>> >
>>> > This patch adds the device tree bindings for the basic-mmio-gpio.
>>> > The basic-mmio-gpio is already part of a the GPIO generic library
>>> > and shares its compatible with the platform device.
>>>
>>> These things always start out "simple", "basic" or "generic". Then
>>> people extend them a property or 2 at a time until they are no longer
>>> basic. Make a bunch of GPIO drivers use a generic driver then maybe
>>> I'll be convinced this is a good idea.
>> Well, I mentioned brcm63xx (MIPS) and MyBook Live (PPC). But OK, if you
>> want me to look at the existing code in the kernel. I found the following
>> candidates.
>
> What I meant was convert the drivers, not the dts files to a generic
> driver. There is no benefit here from a dts perspective. It is driver
> consolidation that would make all this worthwhile.
>
>> 1. MOXA ART: "moxa,moxart-gpio"
>> http://lxr.free-electrons.com/source/drivers/gpio/gpio-moxart.c
>> This driver is used by the:
>> arch/arm/boot/dts/moxart.dtsi
>>
>> ---
>> diff --git a/arch/arm/boot/dts/moxart.dtsi b/arch/arm/boot/dts/moxart.dtsi
>> index 1fd27ed..26707d0 100644
>> --- a/arch/arm/boot/dts/moxart.dtsi
>> +++ b/arch/arm/boot/dts/moxart.dtsi
>> @@ -66,8 +66,11 @@
>>                 gpio: gpio@98700000 {
>>                         gpio-controller;
>>                         #gpio-cells = <2>;
>> -                       compatible = "moxa,moxart-gpio";
>> -                       reg = <0x98700000 0xC>;
>> +                       compatible = "basic-mmio-gpio";
>> +                       reg = <0x98700000 0x4
>> +                              0x98700004 0x4
>> +                              0x98700008 0x4>;
>> +                       reg-names = "set dat dirout";
>
> This is not a compatible change. You can't remove the old drivers as
> they are needed to work with old dtbs, so there is no gain.
>
> You would need to match on existing compatibles such as
> moxa,moxart-gpio and provide a match data struct that has all the info
> you are adding here (e.g. data register offset). Then additionally you
> could add "basic-mmio-gpio" (I would drop "basic" part) and the
> additional data associated with it. But it has to be new properties,
> not changing properties. Changing the reg values doesn't work.
>
>
>> 2. GE FPGA based GPIO: "ge,imp3a-gpio", "gef,sbc310-gpio", "gef,sbc610-gpio"
>> 3. CLPS711X GPIO driver: "cirrus,clps711x-gpio"
>> 4. GPIO driver for the TS-4800 board: "technologic,ts4800-gpio"
>>
>> What do you think. There's a total of six devices that can make use
>> of the "basic-mmio-gpio". If this gives me your go-ahead, I'll include
>> them in the series as proper patches.
>
> Those are a good start. My other worry about this is next someone will
> want to add interrupt registers which is probably a majority of GPIO
> controllers.
>
> Of course, I'm sure Linus has an opinion on all of this.

I'm not Linus, but after a quick look at the drivers mentioned by
Christian I see little room for improvement (but still some - see
below). Like Rob mentioned we want the DT's compatible property to
describe the hardware as precisely as possible. "basic-mmio-gpio" is
not precise and not backward-compatible. The examples listed by
Christian are already all using the generic MMIO driver and are thus
already quite short.

However, they all repeat the same basic sequence to initialize the
generic IOMMU driver, and maybe this could be consolidated in a single
file, with each matching chip having the arguments passed to
bgpio_init() encoded as data (a bit like the simple-panel driver does
- see the platform_of_match member of
drivers/gpu/drm/panel/panel-simple.c)

This would reduce the amount of code that basically does the same
thing, and remove a few files from drivers/gpio. Even there I see that
gpio-clps711x.c has some specifics compared to the other drivers, but
maybe Christian can iron them out.

So without touching the DT I think consolidating the bgpio users in a
fashion similar to what simple-panel does would be worthwhile.
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Christian Lamparter April 28, 2016, 8:48 a.m. UTC | #4
On Thursday, April 28, 2016 03:20:39 PM Alexandre Courbot wrote:
> On Thu, Apr 28, 2016 at 12:08 AM, Rob Herring <robh+dt@kernel.org> wrote:
> > On Wed, Apr 27, 2016 at 5:15 AM, Christian Lamparter
> > What I meant was convert the drivers, not the dts files to a generic
> > driver. There is no benefit here from a dts perspective. It is driver
> > consolidation that would make all this worthwhile.
> > [...]
> > My other worry about this is next someone will want to add interrupt
> > registers which is probably a majority of GPIO controllers.
> >
> > Of course, I'm sure Linus has an opinion on all of this.
> 
> I'm not Linus, but after a quick look at the drivers mentioned by
> Christian I see little room for improvement (but still some - see
> below). Like Rob mentioned we want the DT's compatible property to
> describe the hardware as precisely as possible. "basic-mmio-gpio" is
> not precise and not backward-compatible. The examples listed by
> Christian are already all using the generic MMIO driver and are thus
> already quite short.
> [...]
> So without touching the DT I think consolidating the bgpio users in a
> fashion similar to what simple-panel does would be worthwhile.
I'm getting ready to update my series with a patch like that. I would
like to consolidate the gpio drivers into a single file. But for the
v4 series at least the parsers are still residing in their original files
(I hoped this would make the transition from the _probe to the parser
less painless but the diff came out pretty much unreadable). 
I think this would be just a matter of what's preferred.
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/Documentation/devicetree/bindings/gpio/basic-mmio-gpio.txt b/Documentation/devicetree/bindings/gpio/basic-mmio-gpio.txt
new file mode 100644
index 0000000..5efb155
--- /dev/null
+++ b/Documentation/devicetree/bindings/gpio/basic-mmio-gpio.txt
@@ -0,0 +1,73 @@ 
+Bindings for the generic driver for memory-mapped GPIO controllers.
+
+Required properties:
+	- compatible: should be "basic-mmio-gpio"
+	- reg-names: must contain
+		"dat" - data register
+		may contain
+		"set" - data set register
+		"clr" - data clear register
+		"dirout" - direction output register
+		"dirin" - direction input 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
+	- gpio-controller: Marks the device node as a gpio controller.
+
+Optional properties:
+	- ngpio: specifies the number of gpio mapped in the register.
+	- big-endian: force big endian register accesses.
+	- big-endian-byte-order: assign GPIOs in reverse order.
+	- unreadable-reg-set: data set register is not readable.
+	- read-output-reg-set: cache value set for reads.
+	- unreadable-reg-dir: dirout/dirin register is not readable.
+	- no-output: GPIOs are read-only.
+
+The GPIO generic library provides support for basic memory-mapped GPIO
+controllers. The configuration is detected by which resources are present.
+The simplest form of a GPIO controller that the driver support is just a
+single "dat" register, where GPIO state can be read and/or written.
+However, the driver supports far more:
+	- 8/16/32/64 bits registers. The number of GPIOs is automatically
+	  determined by the width of the registers.
+	- GPIO controllers with clear/set registers.
+	- GPIO controllers with a single "dat" register.
+	- Big endian bits/GPIOs ordering.
+
+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").
+
+For setting the GPIO direction, there are three configurations:
+	a. simple bidirection GPIO 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.
+
+Examples:
+
+	/* Configuration for single input/output register
+	 * for eight simple bidirection GPIOs.
+	 */
+	gpio_a_1 {
+		compatible = "basic-mmio-gpio";
+		reg = <0x18000000 0x1>;
+		reg-names = "dat";
+		#gpio-cells = <2>;
+		gpio-controller;
+	};
+
+	/* Configuration for set/clear pair registers with
+	 * 32 output direction register GPIOs.
+	 */
+	gpio_b_2 {
+		compatible = "basic-mmio-gpio";
+		reg = <0x18000000 0x4>, <0x18000010 0x4>,
+		      <0x18000004 0x4>, <0x18000008 0x4>;
+		reg-names = "dat", "set", "clr", "dirout";
+		#gpio-cells = <2>;
+		gpio-controller;
+	};