diff mbox series

input: sun4i-lradc-keys: Add wakup support

Message ID 20191028221502.3503543-1-megous@megous.com (mailing list archive)
State New, archived
Headers show
Series input: sun4i-lradc-keys: Add wakup support | expand

Commit Message

Ondřej Jirman Oct. 28, 2019, 10:15 p.m. UTC
Allow the driver to wakeup the system on key press.

Signed-off-by: Ondrej Jirman <megous@megous.com>
---
 drivers/input/keyboard/sun4i-lradc-keys.c | 22 ++++++++++++++++++----
 1 file changed, 18 insertions(+), 4 deletions(-)

Comments

Dmitry Torokhov Oct. 28, 2019, 11:38 p.m. UTC | #1
Hi Ondrej,

On Mon, Oct 28, 2019 at 11:15:02PM +0100, Ondrej Jirman wrote:
> Allow the driver to wakeup the system on key press.
> 
> Signed-off-by: Ondrej Jirman <megous@megous.com>
> ---
>  drivers/input/keyboard/sun4i-lradc-keys.c | 22 ++++++++++++++++++----
>  1 file changed, 18 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/input/keyboard/sun4i-lradc-keys.c b/drivers/input/keyboard/sun4i-lradc-keys.c
> index 4a796bed48ac..bba679d7b54b 100644
> --- a/drivers/input/keyboard/sun4i-lradc-keys.c
> +++ b/drivers/input/keyboard/sun4i-lradc-keys.c
> @@ -22,6 +22,8 @@
>  #include <linux/module.h>
>  #include <linux/of_platform.h>
>  #include <linux/platform_device.h>
> +#include <linux/pm_wakeirq.h>
> +#include <linux/pm_wakeup.h>
>  #include <linux/regulator/consumer.h>
>  #include <linux/slab.h>
>  
> @@ -226,8 +228,7 @@ static int sun4i_lradc_probe(struct platform_device *pdev)
>  {
>  	struct sun4i_lradc_data *lradc;
>  	struct device *dev = &pdev->dev;
> -	int i;
> -	int error;
> +	int i, error, irq;
>  
>  	lradc = devm_kzalloc(dev, sizeof(struct sun4i_lradc_data), GFP_KERNEL);
>  	if (!lradc)
> @@ -272,8 +273,13 @@ static int sun4i_lradc_probe(struct platform_device *pdev)
>  	if (IS_ERR(lradc->base))
>  		return PTR_ERR(lradc->base);
>  
> -	error = devm_request_irq(dev, platform_get_irq(pdev, 0),
> -				 sun4i_lradc_irq, 0,
> +	irq = platform_get_irq(pdev, 0);
> +	if (irq < 0) {
> +		dev_err(&pdev->dev, "Failed to get IRQ\n");
> +		return irq;
> +	}
> +
> +	error = devm_request_irq(dev, irq, sun4i_lradc_irq, 0,
>  				 "sun4i-a10-lradc-keys", lradc);
>  	if (error)
>  		return error;
> @@ -282,6 +288,14 @@ static int sun4i_lradc_probe(struct platform_device *pdev)
>  	if (error)
>  		return error;
>  
> +	device_init_wakeup(dev, true);

I do not think we want to do this unconditionally. Can we maybe key off
"wakeup-source" device property.

> +
> +	error = dev_pm_set_wake_irq(dev, irq);
> +	if (error) {
> +		dev_err(dev, "Could not set wake IRQ\n");
> +		return error;
> +	}
> +

I wonder if we could teach platform driver core to handle this for us.

Thanks.
Ondřej Jirman Oct. 28, 2019, 11:56 p.m. UTC | #2
Hello Dmitry,

On Mon, Oct 28, 2019 at 04:38:28PM -0700, Dmitry Torokhov wrote:
> Hi Ondrej,
> 
> On Mon, Oct 28, 2019 at 11:15:02PM +0100, Ondrej Jirman wrote:
> > Allow the driver to wakeup the system on key press.
> > 
> > Signed-off-by: Ondrej Jirman <megous@megous.com>
> > ---
> >  drivers/input/keyboard/sun4i-lradc-keys.c | 22 ++++++++++++++++++----
> >  1 file changed, 18 insertions(+), 4 deletions(-)
> > 
> > diff --git a/drivers/input/keyboard/sun4i-lradc-keys.c b/drivers/input/keyboard/sun4i-lradc-keys.c
> > index 4a796bed48ac..bba679d7b54b 100644
> > --- a/drivers/input/keyboard/sun4i-lradc-keys.c
> > +++ b/drivers/input/keyboard/sun4i-lradc-keys.c
> > @@ -22,6 +22,8 @@
> >  #include <linux/module.h>
> >  #include <linux/of_platform.h>
> >  #include <linux/platform_device.h>
> > +#include <linux/pm_wakeirq.h>
> > +#include <linux/pm_wakeup.h>
> >  #include <linux/regulator/consumer.h>
> >  #include <linux/slab.h>
> >  
> > @@ -226,8 +228,7 @@ static int sun4i_lradc_probe(struct platform_device *pdev)
> >  {
> >  	struct sun4i_lradc_data *lradc;
> >  	struct device *dev = &pdev->dev;
> > -	int i;
> > -	int error;
> > +	int i, error, irq;
> >  
> >  	lradc = devm_kzalloc(dev, sizeof(struct sun4i_lradc_data), GFP_KERNEL);
> >  	if (!lradc)
> > @@ -272,8 +273,13 @@ static int sun4i_lradc_probe(struct platform_device *pdev)
> >  	if (IS_ERR(lradc->base))
> >  		return PTR_ERR(lradc->base);
> >  
> > -	error = devm_request_irq(dev, platform_get_irq(pdev, 0),
> > -				 sun4i_lradc_irq, 0,
> > +	irq = platform_get_irq(pdev, 0);
> > +	if (irq < 0) {
> > +		dev_err(&pdev->dev, "Failed to get IRQ\n");
> > +		return irq;
> > +	}
> > +
> > +	error = devm_request_irq(dev, irq, sun4i_lradc_irq, 0,
> >  				 "sun4i-a10-lradc-keys", lradc);
> >  	if (error)
> >  		return error;
> > @@ -282,6 +288,14 @@ static int sun4i_lradc_probe(struct platform_device *pdev)
> >  	if (error)
> >  		return error;
> >  
> > +	device_init_wakeup(dev, true);
> 
> I do not think we want to do this unconditionally. Can we maybe key off
> "wakeup-source" device property.

Sure thing.

> > +
> > +	error = dev_pm_set_wake_irq(dev, irq);
> > +	if (error) {
> > +		dev_err(dev, "Could not set wake IRQ\n");
> > +		return error;
> > +	}
> > +
> 
> I wonder if we could teach platform driver core to handle this for us.

Not sure, some drivers do enable/disable wake_irq by hand in suspend/resume
callbacks, so it would probably need to be opt-in somehow. I guess calling the
function like this is one way to make it opt-in.

The other way may be by passing a flag somewhere, like to
request_threaded_irq. Did you have something more concrete in mind?

regards,
	o.

> Thanks.
> 
> -- 
> Dmitry
Dmitry Torokhov Oct. 29, 2019, 12:12 a.m. UTC | #3
On Tue, Oct 29, 2019 at 12:56:26AM +0100, Ondřej Jirman wrote:
> Hello Dmitry,
> 
> On Mon, Oct 28, 2019 at 04:38:28PM -0700, Dmitry Torokhov wrote:
> > Hi Ondrej,
> > 
> > On Mon, Oct 28, 2019 at 11:15:02PM +0100, Ondrej Jirman wrote:
> > > Allow the driver to wakeup the system on key press.
> > > 
> > > Signed-off-by: Ondrej Jirman <megous@megous.com>
> > > ---
> > >  drivers/input/keyboard/sun4i-lradc-keys.c | 22 ++++++++++++++++++----
> > >  1 file changed, 18 insertions(+), 4 deletions(-)
> > > 
> > > diff --git a/drivers/input/keyboard/sun4i-lradc-keys.c b/drivers/input/keyboard/sun4i-lradc-keys.c
> > > index 4a796bed48ac..bba679d7b54b 100644
> > > --- a/drivers/input/keyboard/sun4i-lradc-keys.c
> > > +++ b/drivers/input/keyboard/sun4i-lradc-keys.c
> > > @@ -22,6 +22,8 @@
> > >  #include <linux/module.h>
> > >  #include <linux/of_platform.h>
> > >  #include <linux/platform_device.h>
> > > +#include <linux/pm_wakeirq.h>
> > > +#include <linux/pm_wakeup.h>
> > >  #include <linux/regulator/consumer.h>
> > >  #include <linux/slab.h>
> > >  
> > > @@ -226,8 +228,7 @@ static int sun4i_lradc_probe(struct platform_device *pdev)
> > >  {
> > >  	struct sun4i_lradc_data *lradc;
> > >  	struct device *dev = &pdev->dev;
> > > -	int i;
> > > -	int error;
> > > +	int i, error, irq;
> > >  
> > >  	lradc = devm_kzalloc(dev, sizeof(struct sun4i_lradc_data), GFP_KERNEL);
> > >  	if (!lradc)
> > > @@ -272,8 +273,13 @@ static int sun4i_lradc_probe(struct platform_device *pdev)
> > >  	if (IS_ERR(lradc->base))
> > >  		return PTR_ERR(lradc->base);
> > >  
> > > -	error = devm_request_irq(dev, platform_get_irq(pdev, 0),
> > > -				 sun4i_lradc_irq, 0,
> > > +	irq = platform_get_irq(pdev, 0);
> > > +	if (irq < 0) {
> > > +		dev_err(&pdev->dev, "Failed to get IRQ\n");
> > > +		return irq;
> > > +	}
> > > +
> > > +	error = devm_request_irq(dev, irq, sun4i_lradc_irq, 0,
> > >  				 "sun4i-a10-lradc-keys", lradc);
> > >  	if (error)
> > >  		return error;
> > > @@ -282,6 +288,14 @@ static int sun4i_lradc_probe(struct platform_device *pdev)
> > >  	if (error)
> > >  		return error;
> > >  
> > > +	device_init_wakeup(dev, true);
> > 
> > I do not think we want to do this unconditionally. Can we maybe key off
> > "wakeup-source" device property.
> 
> Sure thing.
> 
> > > +
> > > +	error = dev_pm_set_wake_irq(dev, irq);
> > > +	if (error) {
> > > +		dev_err(dev, "Could not set wake IRQ\n");
> > > +		return error;
> > > +	}
> > > +
> > 
> > I wonder if we could teach platform driver core to handle this for us.
> 
> Not sure, some drivers do enable/disable wake_irq by hand in suspend/resume
> callbacks, so it would probably need to be opt-in somehow. I guess calling the
> function like this is one way to make it opt-in.
> 
> The other way may be by passing a flag somewhere, like to
> request_threaded_irq. Did you have something more concrete in mind?

I think it is perfectly fine to continue using enable_irq_wake and
disable_irq_wake from the driver while marking irq as being wake irq
form the core.

Thanks.
Ondřej Jirman Oct. 29, 2019, 1:45 a.m. UTC | #4
On Mon, Oct 28, 2019 at 05:12:50PM -0700, Dmitry Torokhov wrote:
> On Tue, Oct 29, 2019 at 12:56:26AM +0100, Ondřej Jirman wrote:
> > On Mon, Oct 28, 2019 at 04:38:28PM -0700, Dmitry Torokhov wrote:
> > > > +
> > > > +	error = dev_pm_set_wake_irq(dev, irq);
> > > > +	if (error) {
> > > > +		dev_err(dev, "Could not set wake IRQ\n");
> > > > +		return error;
> > > > +	}
> > > > +
> > > 
> > > I wonder if we could teach platform driver core to handle this for us.
> > 
> > Not sure, some drivers do enable/disable wake_irq by hand in suspend/resume
> > callbacks, so it would probably need to be opt-in somehow. I guess calling the
> > function like this is one way to make it opt-in.
> > 
> > The other way may be by passing a flag somewhere, like to
> > request_threaded_irq. Did you have something more concrete in mind?
> 
> I think it is perfectly fine to continue using enable_irq_wake and
> disable_irq_wake from the driver while marking irq as being wake irq
> form the core.

I see, it looks like irq_set_irq_wake will track the calls via wake_depth

https://elixir.bootlin.com/linux/latest/source/kernel/irq/manage.c#L714

But all irqs are not necessarily wake irqs, no? So it still may need to be
opt-in somehow.

Anyway, I'm no PM expert. I started looking at PM code about two weeks ago, and
I really don't feel like I can contribute much to these kinds of decisions with
my current level of understanding, right now.

regards,
	o.

> Thanks.
> 
> -- 
> Dmitry
> 
> -- 
> You received this message because you are subscribed to the Google Groups "linux-sunxi" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to linux-sunxi+unsubscribe@googlegroups.com.
> To view this discussion on the web, visit https://groups.google.com/d/msgid/linux-sunxi/20191029001250.GB57214%40dtor-ws.
Dmitry Torokhov Oct. 29, 2019, 4:18 a.m. UTC | #5
On Tue, Oct 29, 2019 at 02:45:59AM +0100, Ondřej Jirman wrote:
> On Mon, Oct 28, 2019 at 05:12:50PM -0700, Dmitry Torokhov wrote:
> > On Tue, Oct 29, 2019 at 12:56:26AM +0100, Ondřej Jirman wrote:
> > > On Mon, Oct 28, 2019 at 04:38:28PM -0700, Dmitry Torokhov wrote:
> > > > > +
> > > > > +	error = dev_pm_set_wake_irq(dev, irq);
> > > > > +	if (error) {
> > > > > +		dev_err(dev, "Could not set wake IRQ\n");
> > > > > +		return error;
> > > > > +	}
> > > > > +
> > > > 
> > > > I wonder if we could teach platform driver core to handle this for us.
> > > 
> > > Not sure, some drivers do enable/disable wake_irq by hand in suspend/resume
> > > callbacks, so it would probably need to be opt-in somehow. I guess calling the
> > > function like this is one way to make it opt-in.
> > > 
> > > The other way may be by passing a flag somewhere, like to
> > > request_threaded_irq. Did you have something more concrete in mind?
> > 
> > I think it is perfectly fine to continue using enable_irq_wake and
> > disable_irq_wake from the driver while marking irq as being wake irq
> > form the core.
> 
> I see, it looks like irq_set_irq_wake will track the calls via wake_depth
> 
> https://elixir.bootlin.com/linux/latest/source/kernel/irq/manage.c#L714
> 
> But all irqs are not necessarily wake irqs, no? So it still may need to be
> opt-in somehow.

I thought we'd do that for IRQ named "wakeirq" or the very first IRQ if
there is no named IRQ, and when we have the "wakeup-source" property,
similarly to what we do in I2C bus.

Thanks.
Ondřej Jirman Oct. 29, 2019, 12:43 p.m. UTC | #6
On Mon, Oct 28, 2019 at 09:18:04PM -0700, Dmitry Torokhov wrote:
> On Tue, Oct 29, 2019 at 02:45:59AM +0100, Ondřej Jirman wrote:
> > On Mon, Oct 28, 2019 at 05:12:50PM -0700, Dmitry Torokhov wrote:
> > > On Tue, Oct 29, 2019 at 12:56:26AM +0100, Ondřej Jirman wrote:
> > > > On Mon, Oct 28, 2019 at 04:38:28PM -0700, Dmitry Torokhov wrote:
> > > > > > +
> > > > > > +	error = dev_pm_set_wake_irq(dev, irq);
> > > > > > +	if (error) {
> > > > > > +		dev_err(dev, "Could not set wake IRQ\n");
> > > > > > +		return error;
> > > > > > +	}
> > > > > > +
> > > > > 
> > > > > I wonder if we could teach platform driver core to handle this for us.
> > > > 
> > > > Not sure, some drivers do enable/disable wake_irq by hand in suspend/resume
> > > > callbacks, so it would probably need to be opt-in somehow. I guess calling the
> > > > function like this is one way to make it opt-in.
> > > > 
> > > > The other way may be by passing a flag somewhere, like to
> > > > request_threaded_irq. Did you have something more concrete in mind?
> > > 
> > > I think it is perfectly fine to continue using enable_irq_wake and
> > > disable_irq_wake from the driver while marking irq as being wake irq
> > > form the core.
> > 
> > I see, it looks like irq_set_irq_wake will track the calls via wake_depth
> > 
> > https://elixir.bootlin.com/linux/latest/source/kernel/irq/manage.c#L714
> > 
> > But all irqs are not necessarily wake irqs, no? So it still may need to be
> > opt-in somehow.
> 
> I thought we'd do that for IRQ named "wakeirq" or the very first IRQ if
> there is no named IRQ, and when we have the "wakeup-source" property,
> similarly to what we do in I2C bus.

I see. I've looked at drivers using dev_pm_set_wake_irq and
dev_pm_set_dedicated_wake_irq and not many platform drivers would potentially
benefit (~25 out of 2300), of those only some use OF and are platform
drivers, maybe 15-20:

https://elixir.bootlin.com/linux/latest/ident/dev_pm_set_wake_irq
https://elixir.bootlin.com/linux/latest/ident/dev_pm_set_dedicated_wake_irq

I don't think it's worth it.

regards,
	o.

> Thanks.
> 
> -- 
> Dmitry
> 
> _______________________________________________
> linux-arm-kernel mailing list
> linux-arm-kernel@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
diff mbox series

Patch

diff --git a/drivers/input/keyboard/sun4i-lradc-keys.c b/drivers/input/keyboard/sun4i-lradc-keys.c
index 4a796bed48ac..bba679d7b54b 100644
--- a/drivers/input/keyboard/sun4i-lradc-keys.c
+++ b/drivers/input/keyboard/sun4i-lradc-keys.c
@@ -22,6 +22,8 @@ 
 #include <linux/module.h>
 #include <linux/of_platform.h>
 #include <linux/platform_device.h>
+#include <linux/pm_wakeirq.h>
+#include <linux/pm_wakeup.h>
 #include <linux/regulator/consumer.h>
 #include <linux/slab.h>
 
@@ -226,8 +228,7 @@  static int sun4i_lradc_probe(struct platform_device *pdev)
 {
 	struct sun4i_lradc_data *lradc;
 	struct device *dev = &pdev->dev;
-	int i;
-	int error;
+	int i, error, irq;
 
 	lradc = devm_kzalloc(dev, sizeof(struct sun4i_lradc_data), GFP_KERNEL);
 	if (!lradc)
@@ -272,8 +273,13 @@  static int sun4i_lradc_probe(struct platform_device *pdev)
 	if (IS_ERR(lradc->base))
 		return PTR_ERR(lradc->base);
 
-	error = devm_request_irq(dev, platform_get_irq(pdev, 0),
-				 sun4i_lradc_irq, 0,
+	irq = platform_get_irq(pdev, 0);
+	if (irq < 0) {
+		dev_err(&pdev->dev, "Failed to get IRQ\n");
+		return irq;
+	}
+
+	error = devm_request_irq(dev, irq, sun4i_lradc_irq, 0,
 				 "sun4i-a10-lradc-keys", lradc);
 	if (error)
 		return error;
@@ -282,6 +288,14 @@  static int sun4i_lradc_probe(struct platform_device *pdev)
 	if (error)
 		return error;
 
+	device_init_wakeup(dev, true);
+
+	error = dev_pm_set_wake_irq(dev, irq);
+	if (error) {
+		dev_err(dev, "Could not set wake IRQ\n");
+		return error;
+	}
+
 	return 0;
 }