2012-10-11 14:15:47

by Lee Jones

[permalink] [raw]
Subject: [PATCH 1/2] input: gpio-keys: Disable hardware on suspend

From: Jonas Aaberg <[email protected]>

Disable hardware if active when suspending if the hw can not
wake the system from suspend.

Cc: Dmitry Torokhov <[email protected]>
Cc: [email protected]
Acked-by: Lee Jones <[email protected]>
Signed-off-by: Jonas Aaberg <[email protected]>
Signed-off-by: Philippe Langlais <[email protected]>
Reviewed-by: Bengt Jonsson <[email protected]>
---
drivers/input/keyboard/gpio_keys.c | 13 +++++++++++++
1 file changed, 13 insertions(+)

diff --git a/drivers/input/keyboard/gpio_keys.c b/drivers/input/keyboard/gpio_keys.c
index cbb1add..7947315 100644
--- a/drivers/input/keyboard/gpio_keys.c
+++ b/drivers/input/keyboard/gpio_keys.c
@@ -46,6 +46,8 @@ struct gpio_keys_drvdata {
struct input_dev *input;
struct mutex disable_lock;
unsigned int n_buttons;
+ bool enabled;
+ bool enable_after_suspend;
int (*enable)(struct device *dev);
void (*disable)(struct device *dev);
struct gpio_button_data data[0];
@@ -524,6 +526,7 @@ static int gpio_keys_open(struct input_dev *input)
{
struct gpio_keys_drvdata *ddata = input_get_drvdata(input);

+ ddata->enabled = true;
return ddata->enable ? ddata->enable(input->dev.parent) : 0;
}

@@ -533,6 +536,7 @@ static void gpio_keys_close(struct input_dev *input)

if (ddata->disable)
ddata->disable(input->dev.parent);
+ ddata->enabled = false;
}

/*
@@ -674,6 +678,7 @@ static int __devinit gpio_keys_probe(struct platform_device *pdev)
ddata->n_buttons = pdata->nbuttons;
ddata->enable = pdata->enable;
ddata->disable = pdata->disable;
+ ddata->enabled = false;
mutex_init(&ddata->disable_lock);

platform_set_drvdata(pdev, ddata);
@@ -789,6 +794,10 @@ static int gpio_keys_suspend(struct device *dev)
if (bdata->button->wakeup)
enable_irq_wake(bdata->irq);
}
+ } else {
+ ddata->enable_after_suspend = ddata->enabled;
+ if (ddata->enabled)
+ gpio_keys_close(ddata->input);
}

return 0;
@@ -807,6 +816,10 @@ static int gpio_keys_resume(struct device *dev)
if (gpio_is_valid(bdata->button->gpio))
gpio_keys_gpio_report_event(bdata);
}
+
+ if (!device_may_wakeup(dev) && ddata->enable_after_suspend)
+ gpio_keys_open(ddata->input);
+
input_sync(ddata->input);

return 0;
--
1.7.9.5


2012-10-11 14:15:56

by Lee Jones

[permalink] [raw]
Subject: [PATCH 2/2] input: gpio-keys: Add runtime support

From: Jonas Aaberg <[email protected]>

Cc: Dmitry Torokhov <[email protected]>
Cc: [email protected]
Acked-by: Lee Jones <[email protected]>
Signed-off-by: Jonas Aaberg <[email protected]>
Signed-off-by: Philippe Langlais <[email protected]>
Reviewed-by: Bengt Jonsson <[email protected]>
---
drivers/input/keyboard/gpio_keys.c | 16 ++++++++++++----
1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/drivers/input/keyboard/gpio_keys.c b/drivers/input/keyboard/gpio_keys.c
index 7947315..78de557 100644
--- a/drivers/input/keyboard/gpio_keys.c
+++ b/drivers/input/keyboard/gpio_keys.c
@@ -29,6 +29,7 @@
#include <linux/of_platform.h>
#include <linux/of_gpio.h>
#include <linux/spinlock.h>
+#include <linux/pm_runtime.h>

struct gpio_button_data {
const struct gpio_keys_button *button;
@@ -526,6 +527,7 @@ static int gpio_keys_open(struct input_dev *input)
{
struct gpio_keys_drvdata *ddata = input_get_drvdata(input);

+ pm_runtime_get_sync(input->dev.parent);
ddata->enabled = true;
return ddata->enable ? ddata->enable(input->dev.parent) : 0;
}
@@ -537,6 +539,7 @@ static void gpio_keys_close(struct input_dev *input)
if (ddata->disable)
ddata->disable(input->dev.parent);
ddata->enabled = false;
+ pm_runtime_put(input->dev.parent);
}

/*
@@ -695,6 +698,8 @@ static int __devinit gpio_keys_probe(struct platform_device *pdev)
input->id.product = 0x0001;
input->id.version = 0x0100;

+ pm_runtime_enable(&pdev->dev);
+
/* Enable auto repeat feature of Linux input subsystem */
if (pdata->rep)
__set_bit(EV_REP, input->evbit);
@@ -760,6 +765,8 @@ static int __devexit gpio_keys_remove(struct platform_device *pdev)
struct input_dev *input = ddata->input;
int i;

+ pm_runtime_disable(&pdev->dev);
+
sysfs_remove_group(&pdev->dev.kobj, &gpio_keys_attr_group);

device_init_wakeup(&pdev->dev, 0);
@@ -796,8 +803,8 @@ static int gpio_keys_suspend(struct device *dev)
}
} else {
ddata->enable_after_suspend = ddata->enabled;
- if (ddata->enabled)
- gpio_keys_close(ddata->input);
+ if (ddata->enabled && ddata->disable)
+ ddata->disable(dev);
}

return 0;
@@ -817,8 +824,9 @@ static int gpio_keys_resume(struct device *dev)
gpio_keys_gpio_report_event(bdata);
}

- if (!device_may_wakeup(dev) && ddata->enable_after_suspend)
- gpio_keys_open(ddata->input);
+ if (!device_may_wakeup(dev) && ddata->enable_after_suspend
+ && ddata->enable)
+ ddata->enable(dev);

input_sync(ddata->input);

--
1.7.9.5

2012-10-11 14:22:14

by Shubhrajyoti Datta

[permalink] [raw]
Subject: Re: [PATCH 2/2] input: gpio-keys: Add runtime support

On Thu, Oct 11, 2012 at 7:45 PM, Lee Jones <[email protected]> wrote:
> From: Jonas Aaberg <[email protected]>
Some change logs would have helped.

>
> Cc: Dmitry Torokhov <[email protected]>
> Cc: [email protected]
> Acked-by: Lee Jones <[email protected]>
> Signed-off-by: Jonas Aaberg <[email protected]>
> Signed-off-by: Philippe Langlais <[email protected]>
> Reviewed-by: Bengt Jonsson <[email protected]>
> ---
> drivers/input/keyboard/gpio_keys.c | 16 ++++++++++++----
> 1 file changed, 12 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/input/keyboard/gpio_keys.c b/drivers/input/keyboard/gpio_keys.c
> index 7947315..78de557 100644
> --- a/drivers/input/keyboard/gpio_keys.c
> +++ b/drivers/input/keyboard/gpio_keys.c
> @@ -29,6 +29,7 @@
> #include <linux/of_platform.h>
> #include <linux/of_gpio.h>
> #include <linux/spinlock.h>
> +#include <linux/pm_runtime.h>
>
> struct gpio_button_data {
> const struct gpio_keys_button *button;
> @@ -526,6 +527,7 @@ static int gpio_keys_open(struct input_dev *input)
> {
> struct gpio_keys_drvdata *ddata = input_get_drvdata(input);
>
> + pm_runtime_get_sync(input->dev.parent);
I am not an expert of the runtime.

However would be grateful if you explain me what it actually do.

Also I did not see any runtime suspend/ resume handlers populated.

2012-10-11 15:21:37

by Lee Jones

[permalink] [raw]
Subject: Re: [PATCH 2/2] input: gpio-keys: Add runtime support

> > From: Jonas Aaberg <[email protected]>
> Some change logs would have helped.

Granted.

Hopefully Jonas will be happy to step forward and answer any of
your following questions.

> > Cc: Dmitry Torokhov <[email protected]>
> > Cc: [email protected]
> > Acked-by: Lee Jones <[email protected]>
> > Signed-off-by: Jonas Aaberg <[email protected]>
> > Signed-off-by: Philippe Langlais <[email protected]>
> > Reviewed-by: Bengt Jonsson <[email protected]>
> > ---
> > drivers/input/keyboard/gpio_keys.c | 16 ++++++++++++----
> > 1 file changed, 12 insertions(+), 4 deletions(-)
> >
> > diff --git a/drivers/input/keyboard/gpio_keys.c b/drivers/input/keyboard/gpio_keys.c
> > index 7947315..78de557 100644
> > --- a/drivers/input/keyboard/gpio_keys.c
> > +++ b/drivers/input/keyboard/gpio_keys.c
> > @@ -29,6 +29,7 @@
> > #include <linux/of_platform.h>
> > #include <linux/of_gpio.h>
> > #include <linux/spinlock.h>
> > +#include <linux/pm_runtime.h>
> >
> > struct gpio_button_data {
> > const struct gpio_keys_button *button;
> > @@ -526,6 +527,7 @@ static int gpio_keys_open(struct input_dev *input)
> > {
> > struct gpio_keys_drvdata *ddata = input_get_drvdata(input);
> >
> > + pm_runtime_get_sync(input->dev.parent);
> I am not an expert of the runtime.
>
> However would be grateful if you explain me what it actually do.
>
> Also I did not see any runtime suspend/ resume handlers populated.

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

2012-10-12 21:09:33

by Linus Walleij

[permalink] [raw]
Subject: Re: [PATCH 2/2] input: gpio-keys: Add runtime support

On Thu, Oct 11, 2012 at 4:22 PM, Shubhrajyoti Datta
<[email protected]> wrote:

>> @@ -526,6 +527,7 @@ static int gpio_keys_open(struct input_dev *input)
>> {
>> struct gpio_keys_drvdata *ddata = input_get_drvdata(input);
>>
>> + pm_runtime_get_sync(input->dev.parent);
>
> I am not an expert of the runtime.
>
> However would be grateful if you explain me what it actually do.

This increase the reference count of the runtime status container
for the device. _sync makes sure it happens now.

Consult:
Documentation/power/runtime_pm.txt

> Also I did not see any runtime suspend/ resume handlers populated.

It is not necessary to handle the power state at the driver level,
it can just as well be handled by the voltage/power domain,
or at the class, type or bus level.

But the individual driver has to notify the system upward if it
needs to be powered on or when it may or must be relaxed.

Yours,
Linus Walleij

2012-10-13 06:17:45

by Dmitry Torokhov

[permalink] [raw]
Subject: Re: [PATCH 1/2] input: gpio-keys: Disable hardware on suspend

Hi Lee,

On Thu, Oct 11, 2012 at 03:15:26PM +0100, Lee Jones wrote:
> From: Jonas Aaberg <[email protected]>
>
> Disable hardware if active when suspending if the hw can not
> wake the system from suspend.
>
> Cc: Dmitry Torokhov <[email protected]>
> Cc: [email protected]
> Acked-by: Lee Jones <[email protected]>

If you are sending the patch then it should be signed-off-by, not
acked-by, and it should be the very last entry.

> Signed-off-by: Jonas Aaberg <[email protected]>
> Signed-off-by: Philippe Langlais <[email protected]>
> Reviewed-by: Bengt Jonsson <[email protected]>
> ---
> drivers/input/keyboard/gpio_keys.c | 13 +++++++++++++
> 1 file changed, 13 insertions(+)
>
> diff --git a/drivers/input/keyboard/gpio_keys.c b/drivers/input/keyboard/gpio_keys.c
> index cbb1add..7947315 100644
> --- a/drivers/input/keyboard/gpio_keys.c
> +++ b/drivers/input/keyboard/gpio_keys.c
> @@ -46,6 +46,8 @@ struct gpio_keys_drvdata {
> struct input_dev *input;
> struct mutex disable_lock;
> unsigned int n_buttons;
> + bool enabled;
> + bool enable_after_suspend;
> int (*enable)(struct device *dev);
> void (*disable)(struct device *dev);
> struct gpio_button_data data[0];
> @@ -524,6 +526,7 @@ static int gpio_keys_open(struct input_dev *input)
> {
> struct gpio_keys_drvdata *ddata = input_get_drvdata(input);
>
> + ddata->enabled = true;
> return ddata->enable ? ddata->enable(input->dev.parent) : 0;
> }
>
> @@ -533,6 +536,7 @@ static void gpio_keys_close(struct input_dev *input)
>
> if (ddata->disable)
> ddata->disable(input->dev.parent);
> + ddata->enabled = false;
> }
>
> /*
> @@ -674,6 +678,7 @@ static int __devinit gpio_keys_probe(struct platform_device *pdev)
> ddata->n_buttons = pdata->nbuttons;
> ddata->enable = pdata->enable;
> ddata->disable = pdata->disable;
> + ddata->enabled = false;
> mutex_init(&ddata->disable_lock);
>
> platform_set_drvdata(pdev, ddata);
> @@ -789,6 +794,10 @@ static int gpio_keys_suspend(struct device *dev)
> if (bdata->button->wakeup)
> enable_irq_wake(bdata->irq);
> }
> + } else {
> + ddata->enable_after_suspend = ddata->enabled;
> + if (ddata->enabled)
> + gpio_keys_close(ddata->input);

I think it should take ddata->input->mutex to avoid races with
open/close and use ddata->input->users to figure out if device shoudl be
closed and re-opened later.

Thanks.

> }
>
> return 0;
> @@ -807,6 +816,10 @@ static int gpio_keys_resume(struct device *dev)
> if (gpio_is_valid(bdata->button->gpio))
> gpio_keys_gpio_report_event(bdata);
> }
> +
> + if (!device_may_wakeup(dev) && ddata->enable_after_suspend)
> + gpio_keys_open(ddata->input);
> +
> input_sync(ddata->input);
>
> return 0;
> --
> 1.7.9.5
>

--
Dmitry

2012-10-25 07:57:19

by Lee Jones

[permalink] [raw]
Subject: Re: [PATCH 2/2] input: gpio-keys: Add runtime support

On Fri, 12 Oct 2012, Linus Walleij wrote:

> On Thu, Oct 11, 2012 at 4:22 PM, Shubhrajyoti Datta
> <[email protected]> wrote:
>
> >> @@ -526,6 +527,7 @@ static int gpio_keys_open(struct input_dev *input)
> >> {
> >> struct gpio_keys_drvdata *ddata = input_get_drvdata(input);
> >>
> >> + pm_runtime_get_sync(input->dev.parent);
> >
> > I am not an expert of the runtime.
> >
> > However would be grateful if you explain me what it actually do.
>
> This increase the reference count of the runtime status container
> for the device. _sync makes sure it happens now.
>
> Consult:
> Documentation/power/runtime_pm.txt
>
> > Also I did not see any runtime suspend/ resume handlers populated.
>
> It is not necessary to handle the power state at the driver level,
> it can just as well be handled by the voltage/power domain,
> or at the class, type or bus level.
>
> But the individual driver has to notify the system upward if it
> needs to be powered on or when it may or must be relaxed.
>
> Yours,
> Linus Walleij

Friendly poke.

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

2012-10-25 08:01:38

by Linus Walleij

[permalink] [raw]
Subject: Re: [PATCH 2/2] input: gpio-keys: Add runtime support

On Thu, Oct 25, 2012 at 9:57 AM, Lee Jones <[email protected]> wrote:
> On Fri, 12 Oct 2012, Linus Walleij wrote:

>> Yours,
>> Linus Walleij
>
> Friendly poke.

This makes it look like you're poking me as I'm in the To: field but I suspect
the intent must be to poke Dmitry ... I was just providing background
for Shubhrajyoti's question.

Maybe this helps:
Reviewed-by: Linus Walleij <[email protected]>

Yours,
Linus Walleij

2012-10-25 08:21:58

by Lee Jones

[permalink] [raw]
Subject: Re: [PATCH 2/2] input: gpio-keys: Add runtime support

On Thu, 25 Oct 2012, Linus Walleij wrote:

> On Thu, Oct 25, 2012 at 9:57 AM, Lee Jones <[email protected]> wrote:
> > On Fri, 12 Oct 2012, Linus Walleij wrote:
>
> >> Yours,
> >> Linus Walleij
> >
> > Friendly poke.
>
> This makes it look like you're poking me as I'm in the To: field but I suspect
> the intent must be to poke Dmitry ... I was just providing background
> for Shubhrajyoti's question.
>
> Maybe this helps:
> Reviewed-by: Linus Walleij <[email protected]>

Yes, that was also the intention of the other poke. Sorry about
that, I should have moved you into Cc: instead.

Yes, the poke was for Dmitry.

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

2012-10-25 08:31:13

by Dmitry Torokhov

[permalink] [raw]
Subject: Re: [PATCH 2/2] input: gpio-keys: Add runtime support

On Thu, Oct 25, 2012 at 09:21:45AM +0100, Lee Jones wrote:
> On Thu, 25 Oct 2012, Linus Walleij wrote:
>
> > On Thu, Oct 25, 2012 at 9:57 AM, Lee Jones <[email protected]> wrote:
> > > On Fri, 12 Oct 2012, Linus Walleij wrote:
> >
> > >> Yours,
> > >> Linus Walleij
> > >
> > > Friendly poke.
> >
> > This makes it look like you're poking me as I'm in the To: field but I suspect
> > the intent must be to poke Dmitry ... I was just providing background
> > for Shubhrajyoti's question.
> >
> > Maybe this helps:
> > Reviewed-by: Linus Walleij <[email protected]>
>
> Yes, that was also the intention of the other poke. Sorry about
> that, I should have moved you into Cc: instead.
>
> Yes, the poke was for Dmitry.

Still do not have the right signoffs: person who sends me the patch needs
to put signed-off-by, not acked-by.

Thanks.

--
Dmitry

2012-10-25 09:47:49

by Lee Jones

[permalink] [raw]
Subject: Re: [PATCH 2/2] input: gpio-keys: Add runtime support

On Thu, 25 Oct 2012, Dmitry Torokhov wrote:

> On Thu, Oct 25, 2012 at 09:21:45AM +0100, Lee Jones wrote:
> > On Thu, 25 Oct 2012, Linus Walleij wrote:
> >
> > > On Thu, Oct 25, 2012 at 9:57 AM, Lee Jones <[email protected]> wrote:
> > > > On Fri, 12 Oct 2012, Linus Walleij wrote:
> > >
> > > >> Yours,
> > > >> Linus Walleij
> > > >
> > > > Friendly poke.
> > >
> > > This makes it look like you're poking me as I'm in the To: field but I suspect
> > > the intent must be to poke Dmitry ... I was just providing background
> > > for Shubhrajyoti's question.
> > >
> > > Maybe this helps:
> > > Reviewed-by: Linus Walleij <[email protected]>
> >
> > Yes, that was also the intention of the other poke. Sorry about
> > that, I should have moved you into Cc: instead.
> >
> > Yes, the poke was for Dmitry.
>
> Still do not have the right signoffs: person who sends me the patch needs
> to put signed-off-by, not acked-by.

My apologies.

Signed-off-by: Lee Jones <[email protected]>

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

2012-11-22 18:56:15

by Lee Jones

[permalink] [raw]
Subject: Re: [PATCH 2/2] input: gpio-keys: Add runtime support

Ignore this.

I've just rebased and the API has changed slightly.

Will fixup and resend.

> From: Jonas Aaberg <[email protected]>
>
> Cc: Dmitry Torokhov <[email protected]>
> Cc: [email protected]
> Signed-off-by: Lee Jones <[email protected]>
> Signed-off-by: Jonas Aaberg <[email protected]>
> Signed-off-by: Philippe Langlais <[email protected]>
> Reviewed-by: Bengt Jonsson <[email protected]>
> ---
> drivers/input/keyboard/gpio_keys.c | 17 +++++++++++++----
> 1 file changed, 13 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/input/keyboard/gpio_keys.c b/drivers/input/keyboard/gpio_keys.c
> index 2cf6757..cff548c 100644
> --- a/drivers/input/keyboard/gpio_keys.c
> +++ b/drivers/input/keyboard/gpio_keys.c
> @@ -29,6 +29,7 @@
> #include <linux/of_platform.h>
> #include <linux/of_gpio.h>
> #include <linux/spinlock.h>
> +#include <linux/pm_runtime.h>
>
> struct gpio_button_data {
> const struct gpio_keys_button *button;
> @@ -533,6 +534,7 @@ static int gpio_keys_open(struct input_dev *input)
> struct gpio_keys_drvdata *ddata = input_get_drvdata(input);
> const struct gpio_keys_platform_data *pdata = ddata->pdata;
>
> + pm_runtime_get_sync(input->dev.parent);
> ddata->enabled = true;
>
> return pdata->enable ? pdata->enable(input->dev.parent) : 0;
> @@ -547,6 +549,8 @@ static void gpio_keys_close(struct input_dev *input)
>
> if (pdata->disable)
> pdata->disable(input->dev.parent);
> +
> + pm_runtime_put(input->dev.parent);
> }
>
> /*
> @@ -708,6 +712,8 @@ static int __devinit gpio_keys_probe(struct platform_device *pdev)
> input->id.product = 0x0001;
> input->id.version = 0x0100;
>
> + pm_runtime_enable(&pdev->dev);
> +
> /* Enable auto repeat feature of Linux input subsystem */
> if (pdata->rep)
> __set_bit(EV_REP, input->evbit);
> @@ -773,6 +779,8 @@ static int __devexit gpio_keys_remove(struct platform_device *pdev)
> struct input_dev *input = ddata->input;
> int i;
>
> + pm_runtime_disable(&pdev->dev);
> +
> sysfs_remove_group(&pdev->dev.kobj, &gpio_keys_attr_group);
>
> device_init_wakeup(&pdev->dev, 0);
> @@ -805,8 +813,8 @@ static int gpio_keys_suspend(struct device *dev)
> }
> } else {
> ddata->enable_after_suspend = ddata->enabled;
> - if (ddata->enabled)
> - gpio_keys_close(ddata->input);
> + if (ddata->enabled && ddata->disable)
> + ddata->disable(dev);
> }
>
> return 0;
> @@ -826,8 +834,9 @@ static int gpio_keys_resume(struct device *dev)
> gpio_keys_gpio_report_event(bdata);
> }
>
> - if (!device_may_wakeup(dev) && ddata->enable_after_suspend)
> - gpio_keys_open(ddata->input);
> + if (!device_may_wakeup(dev) && ddata->enable_after_suspend
> + && ddata->enable)
> + ddata->enable(dev);
>
> input_sync(ddata->input);
>
> --
> 1.7.9.5
>

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