2012-11-23 05:51:19

by Viresh Kumar

[permalink] [raw]
Subject: [PATCH] gpio: stmpe: Add DT support for stmpe gpio

From: Vipul Kumar Samar <[email protected]>

This patch allows the STMPE GPIO driver to be successfully probed and
initialised when Device Tree support is enabled. Bindings are mentioned in
Documentation too.

Signed-off-by: Vipul Kumar Samar <[email protected]>
Signed-off-by: Viresh Kumar <[email protected]>
---
Documentation/devicetree/bindings/gpio/gpio-stmpe.txt | 18 ++++++++++++++++++
drivers/gpio/gpio-stmpe.c | 15 ++++++++++++---
drivers/mfd/stmpe.c | 2 ++
3 files changed, 32 insertions(+), 3 deletions(-)
create mode 100644 Documentation/devicetree/bindings/gpio/gpio-stmpe.txt

diff --git a/Documentation/devicetree/bindings/gpio/gpio-stmpe.txt b/Documentation/devicetree/bindings/gpio/gpio-stmpe.txt
new file mode 100644
index 0000000..7f010e0
--- /dev/null
+++ b/Documentation/devicetree/bindings/gpio/gpio-stmpe.txt
@@ -0,0 +1,18 @@
+STMPE gpio
+----------
+
+Required properties:
+ - compatible: "st,stmpe-gpio"
+
+Optional properties:
+ - norequest-mask: bitmask specifying which GPIOs should _not_ be requestable
+ due to different usage (e.g. touch, keypad)
+
+Node name must be stmpe_gpio and should be child node of stmpe node to which it
+belongs.
+
+Example:
+ stmpe_gpio {
+ compatible = "st,stmpe-gpio";
+ st,norequest-mask = <0x20>; //gpio 5 can't be used
+ };
diff --git a/drivers/gpio/gpio-stmpe.c b/drivers/gpio/gpio-stmpe.c
index dce3472..91455d4 100644
--- a/drivers/gpio/gpio-stmpe.c
+++ b/drivers/gpio/gpio-stmpe.c
@@ -12,6 +12,7 @@
#include <linux/gpio.h>
#include <linux/irq.h>
#include <linux/interrupt.h>
+#include <linux/of.h>
#include <linux/mfd/stmpe.h>

/*
@@ -304,6 +305,7 @@ static void stmpe_gpio_irq_remove(struct stmpe_gpio *stmpe_gpio)
static int __devinit stmpe_gpio_probe(struct platform_device *pdev)
{
struct stmpe *stmpe = dev_get_drvdata(pdev->dev.parent);
+ struct device_node *np = pdev->dev.of_node;
struct stmpe_gpio_platform_data *pdata;
struct stmpe_gpio *stmpe_gpio;
int ret;
@@ -321,12 +323,19 @@ static int __devinit stmpe_gpio_probe(struct platform_device *pdev)

stmpe_gpio->dev = &pdev->dev;
stmpe_gpio->stmpe = stmpe;
- stmpe_gpio->norequest_mask = pdata ? pdata->norequest_mask : 0;
-
stmpe_gpio->chip = template_chip;
stmpe_gpio->chip.ngpio = stmpe->num_gpios;
stmpe_gpio->chip.dev = &pdev->dev;
- stmpe_gpio->chip.base = pdata ? pdata->gpio_base : -1;
+
+ if (pdata) {
+ stmpe_gpio->norequest_mask = pdata->norequest_mask;
+ stmpe_gpio->chip.base = pdata->gpio_base;
+ } else {
+ stmpe_gpio->chip.base = -1;
+ if (np)
+ of_property_read_u32(np, "st,norequest-mask",
+ &pdata->norequest_mask);
+ }

if (irq >= 0)
stmpe_gpio->irq_base = stmpe->irq_base + STMPE_INT_GPIO(0);
diff --git a/drivers/mfd/stmpe.c b/drivers/mfd/stmpe.c
index e2c0dda..c757ac3 100644
--- a/drivers/mfd/stmpe.c
+++ b/drivers/mfd/stmpe.c
@@ -298,12 +298,14 @@ static struct resource stmpe_gpio_resources[] = {

static struct mfd_cell stmpe_gpio_cell = {
.name = "stmpe-gpio",
+ .of_compatible = "st,stmpe-gpio",
.resources = stmpe_gpio_resources,
.num_resources = ARRAY_SIZE(stmpe_gpio_resources),
};

static struct mfd_cell stmpe_gpio_cell_noirq = {
.name = "stmpe-gpio",
+ .of_compatible = "st,stmpe-gpio",
/* gpio cell resources consist of an irq only so no resources here */
};

--
1.7.12.rc2.18.g61b472e


2012-11-23 10:34:09

by Lee Jones

[permalink] [raw]
Subject: Re: [PATCH] gpio: stmpe: Add DT support for stmpe gpio

On Fri, 23 Nov 2012, Viresh Kumar wrote:

> From: Vipul Kumar Samar <[email protected]>
>
> This patch allows the STMPE GPIO driver to be successfully probed and
> initialised when Device Tree support is enabled. Bindings are mentioned in
> Documentation too.
>
> Signed-off-by: Vipul Kumar Samar <[email protected]>
> Signed-off-by: Viresh Kumar <[email protected]>
> ---
> Documentation/devicetree/bindings/gpio/gpio-stmpe.txt | 18 ++++++++++++++++++
> drivers/gpio/gpio-stmpe.c | 15 ++++++++++++---
> drivers/mfd/stmpe.c | 2 ++
> 3 files changed, 32 insertions(+), 3 deletions(-)
> create mode 100644 Documentation/devicetree/bindings/gpio/gpio-stmpe.txt
>
> diff --git a/Documentation/devicetree/bindings/gpio/gpio-stmpe.txt b/Documentation/devicetree/bindings/gpio/gpio-stmpe.txt
> new file mode 100644
> index 0000000..7f010e0
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/gpio/gpio-stmpe.txt
> @@ -0,0 +1,18 @@
> +STMPE gpio
> +----------
> +
> +Required properties:
> + - compatible: "st,stmpe-gpio"
> +
> +Optional properties:
> + - norequest-mask: bitmask specifying which GPIOs should _not_ be requestable
> + due to different usage (e.g. touch, keypad)
> +
> +Node name must be stmpe_gpio and should be child node of stmpe node to which it
> +belongs.
> +
> +Example:
> + stmpe_gpio {
> + compatible = "st,stmpe-gpio";
> + st,norequest-mask = <0x20>; //gpio 5 can't be used
> + };
> diff --git a/drivers/gpio/gpio-stmpe.c b/drivers/gpio/gpio-stmpe.c
> index dce3472..91455d4 100644
> --- a/drivers/gpio/gpio-stmpe.c
> +++ b/drivers/gpio/gpio-stmpe.c
> @@ -12,6 +12,7 @@
> #include <linux/gpio.h>
> #include <linux/irq.h>
> #include <linux/interrupt.h>
> +#include <linux/of.h>
> #include <linux/mfd/stmpe.h>
>
> /*
> @@ -304,6 +305,7 @@ static void stmpe_gpio_irq_remove(struct stmpe_gpio *stmpe_gpio)
> static int __devinit stmpe_gpio_probe(struct platform_device *pdev)
> {
> struct stmpe *stmpe = dev_get_drvdata(pdev->dev.parent);
> + struct device_node *np = pdev->dev.of_node;
> struct stmpe_gpio_platform_data *pdata;
> struct stmpe_gpio *stmpe_gpio;
> int ret;
> @@ -321,12 +323,19 @@ static int __devinit stmpe_gpio_probe(struct platform_device *pdev)
>
> stmpe_gpio->dev = &pdev->dev;
> stmpe_gpio->stmpe = stmpe;
> - stmpe_gpio->norequest_mask = pdata ? pdata->norequest_mask : 0;
> -
> stmpe_gpio->chip = template_chip;
> stmpe_gpio->chip.ngpio = stmpe->num_gpios;
> stmpe_gpio->chip.dev = &pdev->dev;
> - stmpe_gpio->chip.base = pdata ? pdata->gpio_base : -1;

Why have you deleted this?

> +
> + if (pdata) {
> + stmpe_gpio->norequest_mask = pdata->norequest_mask;
> + stmpe_gpio->chip.base = pdata->gpio_base;

Then added this?

> + } else {
> + stmpe_gpio->chip.base = -1;

And this?

Just leave the top line in and it saves you lots of complecations.

> + if (np)
> + of_property_read_u32(np, "st,norequest-mask",
> + &pdata->norequest_mask);

Can you explain to me what this does?

> + }
>
> if (irq >= 0)
> stmpe_gpio->irq_base = stmpe->irq_base + STMPE_INT_GPIO(0);
> diff --git a/drivers/mfd/stmpe.c b/drivers/mfd/stmpe.c
> index e2c0dda..c757ac3 100644
> --- a/drivers/mfd/stmpe.c
> +++ b/drivers/mfd/stmpe.c
> @@ -298,12 +298,14 @@ static struct resource stmpe_gpio_resources[] = {
>
> static struct mfd_cell stmpe_gpio_cell = {
> .name = "stmpe-gpio",
> + .of_compatible = "st,stmpe-gpio",

There's no need for any of the STMPE to have their own compatible
string, as they are MFD devices. They are registered as platform
devices from the MFD subsystem.

> .resources = stmpe_gpio_resources,
> .num_resources = ARRAY_SIZE(stmpe_gpio_resources),
> };
>
> static struct mfd_cell stmpe_gpio_cell_noirq = {
> .name = "stmpe-gpio",
> + .of_compatible = "st,stmpe-gpio",
> /* gpio cell resources consist of an irq only so no resources here */
> };
>
> --
> 1.7.12.rc2.18.g61b472e
>

--
Lee Jones
Linaro ST-Ericsson Landing Team Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog

2012-11-23 10:41:47

by Lee Jones

[permalink] [raw]
Subject: Re: [PATCH] gpio: stmpe: Add DT support for stmpe gpio

> > static struct mfd_cell stmpe_gpio_cell = {
> > .name = "stmpe-gpio",
> > + .of_compatible = "st,stmpe-gpio",
>
> There's no need for any of the STMPE to have their own compatible
> string, as they are MFD devices. They are registered as platform
> devices from the MFD subsystem.

Whoops, I've written this in the wrong place.

Sorry, for the confusion. It does need to be here.

> > .resources = stmpe_gpio_resources,
> > .num_resources = ARRAY_SIZE(stmpe_gpio_resources),
> > };
> >
> > static struct mfd_cell stmpe_gpio_cell_noirq = {
> > .name = "stmpe-gpio",
> > + .of_compatible = "st,stmpe-gpio",

... and here.

> > +++ b/Documentation/devicetree/bindings/gpio/gpio-stmpe.txt
> > @@ -0,0 +1,18 @@
> > +STMPE gpio
> > +----------
> > +
> > +Required properties:
> > + - compatible: "st,stmpe-gpio"

... but this is wrong.

> > +Example:
> > + stmpe_gpio {
> > + compatible = "st,stmpe-gpio";
> > + st,norequest-mask = <0x20>; //gpio 5 can't be used
> > + };

As is the example.

So will be the the DT - if you've already written it.

--
Lee Jones
Linaro ST-Ericsson Landing Team Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog

2012-11-23 10:43:30

by Viresh Kumar

[permalink] [raw]
Subject: Re: [PATCH] gpio: stmpe: Add DT support for stmpe gpio

On 23 November 2012 16:04, Lee Jones <[email protected]> wrote:
> On Fri, 23 Nov 2012, Viresh Kumar wrote:
>> diff --git a/drivers/gpio/gpio-stmpe.c b/drivers/gpio/gpio-stmpe.c

>> static int __devinit stmpe_gpio_probe(struct platform_device *pdev)
>> {

>> - stmpe_gpio->chip.base = pdata ? pdata->gpio_base : -1;
>
> Why have you deleted this?
>
>> +
>> + if (pdata) {
>> + stmpe_gpio->norequest_mask = pdata->norequest_mask;
>> + stmpe_gpio->chip.base = pdata->gpio_base;
>
> Then added this?
>
>> + } else {
>> + stmpe_gpio->chip.base = -1;
>
> And this?

To group all non-DT assignments in a single if block, instead of two.

> Just leave the top line in and it saves you lots of complecations.

Sorry, Couldn't get this one.

>> + if (np)
>> + of_property_read_u32(np, "st,norequest-mask",
>> + &pdata->norequest_mask);
>
> Can you explain to me what this does?

You mean pdata->norequest_mask? It marks few gpios as unusable.
Because these pads might be used by other blocks of stmpe.

>> diff --git a/drivers/mfd/stmpe.c b/drivers/mfd/stmpe.c

>> static struct mfd_cell stmpe_gpio_cell = {
>> .name = "stmpe-gpio",
>> + .of_compatible = "st,stmpe-gpio",
>
> There's no need for any of the STMPE to have their own compatible
> string, as they are MFD devices. They are registered as platform
> devices from the MFD subsystem.

This is required by mfd-core.c, mfd_add_device() isn't it?

if (parent->of_node && cell->of_compatible) {
for_each_child_of_node(parent->of_node, np) {
if (of_device_is_compatible(np, cell->of_compatible)) {
pdev->dev.of_node = np;
break;
}
}
}

--
viresh

2012-11-23 10:47:13

by Viresh Kumar

[permalink] [raw]
Subject: Re: [PATCH] gpio: stmpe: Add DT support for stmpe gpio

On 23 November 2012 16:11, Lee Jones <[email protected]> wrote:
>> > +++ b/Documentation/devicetree/bindings/gpio/gpio-stmpe.txt
>> > @@ -0,0 +1,18 @@
>> > +STMPE gpio
>> > +----------
>> > +
>> > +Required properties:
>> > + - compatible: "st,stmpe-gpio"
>
> ... but this is wrong.
>
>> > +Example:
>> > + stmpe_gpio {
>> > + compatible = "st,stmpe-gpio";
>> > + st,norequest-mask = <0x20>; //gpio 5 can't be used
>> > + };
>
> As is the example.
>
> So will be the the DT - if you've already written it.

Again, I believe these are required by the code you wrote in mfd-core.c

if (parent->of_node && cell->of_compatible) {
for_each_child_of_node(parent->of_node, np) {
if (of_device_is_compatible(np, cell->of_compatible)) {
pdev->dev.of_node = np;
break;
}
}
}

This matches compatible of child node with compatible of cell. And that's
why you have added that in your keypad mappings as well.

--
viresh

2012-11-23 12:14:20

by Lee Jones

[permalink] [raw]
Subject: Re: [PATCH] gpio: stmpe: Add DT support for stmpe gpio

> >> - stmpe_gpio->chip.base = pdata ? pdata->gpio_base : -1;
> >
> > Why have you deleted this?
> >
> >> +
> >> + if (pdata) {
> >> + stmpe_gpio->norequest_mask = pdata->norequest_mask;
> >> + stmpe_gpio->chip.base = pdata->gpio_base;
> >
> > Then added this?
> >
> >> + } else {
> >> + stmpe_gpio->chip.base = -1;
> >
> > And this?
>
> To group all non-DT assignments in a single if block, instead of two.

That assignment has nothing to do with DT.

> > Just leave the top line in and it saves you lots of complecations.
>
> Sorry, Couldn't get this one.

I'm saying, just leave it where it is.

> >> + if (np)
> >> + of_property_read_u32(np, "st,norequest-mask",
> >> + &pdata->norequest_mask);
> >
> > Can you explain to me what this does?
>
> You mean pdata->norequest_mask? It marks few gpios as unusable.
> Because these pads might be used by other blocks of stmpe.

I'm not sure if that should be set with DT or not.

Second opinion anyone?

--
Lee Jones
Linaro ST-Ericsson Landing Team Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog

2012-11-23 12:25:31

by Viresh Kumar

[permalink] [raw]
Subject: Re: [PATCH] gpio: stmpe: Add DT support for stmpe gpio

On 23 November 2012 17:44, Lee Jones <[email protected]> wrote:
> I'm saying, just leave it where it is.

So you are suggesting this code:

stmpe_gpio->chip.base = pdata ? pdata->gpio_base : -1;

if (pdata)
stmpe_gpio->norequest_mask = pdata->norequest_mask;
else if (np)
of_property_read_u32(np, "st,norequest-mask",
&pdata->norequest_mask);

Right? Then yes i can do it.

>> >> + if (np)
>> >> + of_property_read_u32(np, "st,norequest-mask",
>> >> + &pdata->norequest_mask);
>> >
>> > Can you explain to me what this does?
>>
>> You mean pdata->norequest_mask? It marks few gpios as unusable.
>> Because these pads might be used by other blocks of stmpe.
>
> I'm not sure if that should be set with DT or not.
>
> Second opinion anyone?

Why i kept it in DT is because it is board dependent and there is no better
way of communicating this from board to driver.

--
viresh

2012-11-23 12:31:11

by Shiraz Hashim

[permalink] [raw]
Subject: Re: [PATCH] gpio: stmpe: Add DT support for stmpe gpio

On Fri, Nov 23, 2012 at 12:14:13PM +0000, Lee Jones wrote:
> > >> + if (np)
> > >> + of_property_read_u32(np, "st,norequest-mask",
> > >> + &pdata->norequest_mask);
> > >
> > > Can you explain to me what this does?
> >
> > You mean pdata->norequest_mask? It marks few gpios as unusable.
> > Because these pads might be used by other blocks of stmpe.
>
> I'm not sure if that should be set with DT or not.
>
> Second opinion anyone?

This is a board dependent parameter which just informs gpio driver
about pins, which must not be requested. It may happen for a stmpe
variant where such gpio pins are multiplexed with some other
function.

Hence it must be part of DT itself.

--
regards
Shiraz

2012-11-23 15:45:34

by Lee Jones

[permalink] [raw]
Subject: Re: [PATCH] gpio: stmpe: Add DT support for stmpe gpio

On Fri, 23 Nov 2012, Viresh Kumar wrote:

> On 23 November 2012 17:44, Lee Jones <[email protected]> wrote:
> > I'm saying, just leave it where it is.
>
> So you are suggesting this code:
>
> stmpe_gpio->chip.base = pdata ? pdata->gpio_base : -1;
>
> if (pdata)
> stmpe_gpio->norequest_mask = pdata->norequest_mask;
> else if (np)
> of_property_read_u32(np, "st,norequest-mask",
> &pdata->norequest_mask);
>
> Right? Then yes i can do it.

It would be better if you'd sent it as a diff, but yes, leave the
top line as it is and just add the norequest-mask stuff (if it's
required).

> >> >> + if (np)
> >> >> + of_property_read_u32(np, "st,norequest-mask",
> >> >> + &pdata->norequest_mask);
> >> >
> >> > Can you explain to me what this does?
> >>
> >> You mean pdata->norequest_mask? It marks few gpios as unusable.
> >> Because these pads might be used by other blocks of stmpe.
> >
> > I'm not sure if that should be set with DT or not.
> >
> > Second opinion anyone?
>
> Why i kept it in DT is because it is board dependent and there is no better
> way of communicating this from board to driver.

I can't comment, as I really don't know.

--
Lee Jones
Linaro ST-Ericsson Landing Team Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog

2012-11-26 11:28:30

by Lee Jones

[permalink] [raw]
Subject: Re: [PATCH] gpio: stmpe: Add DT support for stmpe gpio

On Fri, 23 Nov 2012, Shiraz Hashim wrote:

> On Fri, Nov 23, 2012 at 12:14:13PM +0000, Lee Jones wrote:
> > > >> + if (np)
> > > >> + of_property_read_u32(np, "st,norequest-mask",
> > > >> + &pdata->norequest_mask);
> > > >
> > > > Can you explain to me what this does?
> > >
> > > You mean pdata->norequest_mask? It marks few gpios as unusable.
> > > Because these pads might be used by other blocks of stmpe.
> >
> > I'm not sure if that should be set with DT or not.
> >
> > Second opinion anyone?
>
> This is a board dependent parameter which just informs gpio driver
> about pins, which must not be requested. It may happen for a stmpe
> variant where such gpio pins are multiplexed with some other
> function.
>
> Hence it must be part of DT itself.

Doesn't pinctrl normally handle this kind of stuff?

--
Lee Jones
Linaro ST-Ericsson Landing Team Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog

2012-11-26 11:32:51

by Shiraz Hashim

[permalink] [raw]
Subject: Re: [PATCH] gpio: stmpe: Add DT support for stmpe gpio

On Mon, Nov 26, 2012 at 11:28:23AM +0000, Lee Jones wrote:
> On Fri, 23 Nov 2012, Shiraz Hashim wrote:
>
> > On Fri, Nov 23, 2012 at 12:14:13PM +0000, Lee Jones wrote:
> > > > >> + if (np)
> > > > >> + of_property_read_u32(np, "st,norequest-mask",
> > > > >> + &pdata->norequest_mask);
> > > > >
> > > > > Can you explain to me what this does?
> > > >
> > > > You mean pdata->norequest_mask? It marks few gpios as unusable.
> > > > Because these pads might be used by other blocks of stmpe.
> > >
> > > I'm not sure if that should be set with DT or not.
> > >
> > > Second opinion anyone?
> >
> > This is a board dependent parameter which just informs gpio driver
> > about pins, which must not be requested. It may happen for a stmpe
> > variant where such gpio pins are multiplexed with some other
> > function.
> >
> > Hence it must be part of DT itself.
>
> Doesn't pinctrl normally handle this kind of stuff?

Yes, but I think it is only for managing the SoC and its pads.

--
regards
Shiraz