Linux Input Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH 1/3] Input: axp20x-pek - Remove unique wakeup event handling
@ 2020-01-13  3:20 Samuel Holland
  2020-01-13  3:20 ` [PATCH 2/3] Input: axp20x-pek - Respect userspace wakeup configuration Samuel Holland
                   ` (2 more replies)
  0 siblings, 3 replies; 14+ messages in thread
From: Samuel Holland @ 2020-01-13  3:20 UTC (permalink / raw)
  To: Dmitry Torokhov, Chen-Yu Tsai, Hans de Goede
  Cc: linux-input, linux-kernel, linux-sunxi, Samuel Holland

This driver attempts to avoid reporting wakeup events to userspace by
clearing a possible pending IRQ before IRQs are enabled during resume.
The assumption seems to be that userspace cannot cope with a KEY_POWER
press during resume. However, no other input driver does this, so it
would be a bug that such events are missing with this driver.

Furthermore, for PMICs connected via I2C or RSB, it is not possible to
update the regmap during the noirq resume phase, because the bus
controller drivers require IRQs to perform bus transactions. And the
resume hook cannot move to a later phase, because then it would race
with the power key IRQ handler.

So the best solution seems to be simply removing the hook.

Signed-off-by: Samuel Holland <samuel@sholland.org>
---
 drivers/input/misc/axp20x-pek.c | 25 -------------------------
 1 file changed, 25 deletions(-)

diff --git a/drivers/input/misc/axp20x-pek.c b/drivers/input/misc/axp20x-pek.c
index 17c1cca74498..7d0ee5bececb 100644
--- a/drivers/input/misc/axp20x-pek.c
+++ b/drivers/input/misc/axp20x-pek.c
@@ -352,30 +352,6 @@ static int axp20x_pek_probe(struct platform_device *pdev)
 	return 0;
 }
 
-static int __maybe_unused axp20x_pek_resume_noirq(struct device *dev)
-{
-	struct axp20x_pek *axp20x_pek = dev_get_drvdata(dev);
-
-	if (axp20x_pek->axp20x->variant != AXP288_ID)
-		return 0;
-
-	/*
-	 * Clear interrupts from button presses during suspend, to avoid
-	 * a wakeup power-button press getting reported to userspace.
-	 */
-	regmap_write(axp20x_pek->axp20x->regmap,
-		     AXP20X_IRQ1_STATE + AXP288_IRQ_POKN / 8,
-		     BIT(AXP288_IRQ_POKN % 8));
-
-	return 0;
-}
-
-static const struct dev_pm_ops axp20x_pek_pm_ops = {
-#ifdef CONFIG_PM_SLEEP
-	.resume_noirq = axp20x_pek_resume_noirq,
-#endif
-};
-
 static const struct platform_device_id axp_pek_id_match[] = {
 	{
 		.name = "axp20x-pek",
@@ -394,7 +370,6 @@ static struct platform_driver axp20x_pek_driver = {
 	.id_table	= axp_pek_id_match,
 	.driver		= {
 		.name		= "axp20x-pek",
-		.pm		= &axp20x_pek_pm_ops,
 		.dev_groups	= axp20x_groups,
 	},
 };
-- 
2.23.0


^ permalink raw reply	[flat|nested] 14+ messages in thread

* [PATCH 2/3] Input: axp20x-pek - Respect userspace wakeup configuration
  2020-01-13  3:20 [PATCH 1/3] Input: axp20x-pek - Remove unique wakeup event handling Samuel Holland
@ 2020-01-13  3:20 ` Samuel Holland
  2020-01-13  4:47   ` kbuild test robot
                     ` (2 more replies)
  2020-01-13  3:20 ` [PATCH 3/3] Input: axp20x-pek - Enable wakeup for all AXP variants Samuel Holland
  2020-01-13 10:41 ` [PATCH 1/3] Input: axp20x-pek - Remove unique wakeup event handling Hans de Goede
  2 siblings, 3 replies; 14+ messages in thread
From: Samuel Holland @ 2020-01-13  3:20 UTC (permalink / raw)
  To: Dmitry Torokhov, Chen-Yu Tsai, Hans de Goede
  Cc: linux-input, linux-kernel, linux-sunxi, Samuel Holland

Unlike most other power button drivers, this driver unconditionally
enables its wakeup IRQ. It should be using device_may_wakeup() to
respect the userspace configuration of wakeup sources.

Because the AXP20x MFD device uses regmap-irq, the AXP20x PEK IRQs are
nested off of regmap-irq's threaded interrupt handler. The device core
ignores such interrupts, so to actually disable wakeup, we must
explicitly disable all non-wakeup interrupts during suspend.

Signed-off-by: Samuel Holland <samuel@sholland.org>
---
 drivers/input/misc/axp20x-pek.c | 42 ++++++++++++++++++++++++++++++++-
 1 file changed, 41 insertions(+), 1 deletion(-)

diff --git a/drivers/input/misc/axp20x-pek.c b/drivers/input/misc/axp20x-pek.c
index 7d0ee5bececb..38cd4a4aeb65 100644
--- a/drivers/input/misc/axp20x-pek.c
+++ b/drivers/input/misc/axp20x-pek.c
@@ -280,7 +280,7 @@ static int axp20x_pek_probe_input_device(struct axp20x_pek *axp20x_pek,
 	}
 
 	if (axp20x_pek->axp20x->variant == AXP288_ID)
-		enable_irq_wake(axp20x_pek->irq_dbr);
+		device_init_wakeup(&pdev->dev, true);
 
 	return 0;
 }
@@ -352,6 +352,45 @@ static int axp20x_pek_probe(struct platform_device *pdev)
 	return 0;
 }
 
+#if CONFIG_PM_SLEEP
+static int axp20x_pek_suspend(struct device *dev)
+{
+	struct axp20x_pek *axp20x_pek = dev_get_drvdata(dev);
+
+	/*
+	 * Nested threaded interrupts are not automatically
+	 * disabled, so we must do it explicitly.
+	 */
+	if (device_may_wakeup(dev)) {
+		enable_irq_wake(axp20x_pek->irq_dbf);
+		enable_irq_wake(axp20x_pek->irq_dbr);
+	} else {
+		disable_irq(axp20x_pek->irq_dbf);
+		disable_irq(axp20x_pek->irq_dbr);
+	}
+
+	return 0;
+}
+
+static int axp20x_pek_resume(struct device *dev)
+{
+	struct axp20x_pek *axp20x_pek = dev_get_drvdata(dev);
+
+	if (device_may_wakeup(dev)) {
+		disable_irq_wake(axp20x_pek->irq_dbf);
+		disable_irq_wake(axp20x_pek->irq_dbr);
+	} else {
+		enable_irq(axp20x_pek->irq_dbf);
+		enable_irq(axp20x_pek->irq_dbr);
+	}
+
+	return 0;
+}
+#endif
+
+static SIMPLE_DEV_PM_OPS(axp20x_pek_pm_ops, axp20x_pek_suspend,
+					    axp20x_pek_resume);
+
 static const struct platform_device_id axp_pek_id_match[] = {
 	{
 		.name = "axp20x-pek",
@@ -371,6 +410,7 @@ static struct platform_driver axp20x_pek_driver = {
 	.driver		= {
 		.name		= "axp20x-pek",
 		.dev_groups	= axp20x_groups,
+		.pm		= &axp20x_pek_pm_ops,
 	},
 };
 module_platform_driver(axp20x_pek_driver);
-- 
2.23.0


^ permalink raw reply	[flat|nested] 14+ messages in thread

* [PATCH 3/3] Input: axp20x-pek - Enable wakeup for all AXP variants
  2020-01-13  3:20 [PATCH 1/3] Input: axp20x-pek - Remove unique wakeup event handling Samuel Holland
  2020-01-13  3:20 ` [PATCH 2/3] Input: axp20x-pek - Respect userspace wakeup configuration Samuel Holland
@ 2020-01-13  3:20 ` Samuel Holland
  2020-01-13 10:48   ` Hans de Goede
  2020-01-13 21:26   ` Dmitry Torokhov
  2020-01-13 10:41 ` [PATCH 1/3] Input: axp20x-pek - Remove unique wakeup event handling Hans de Goede
  2 siblings, 2 replies; 14+ messages in thread
From: Samuel Holland @ 2020-01-13  3:20 UTC (permalink / raw)
  To: Dmitry Torokhov, Chen-Yu Tsai, Hans de Goede
  Cc: linux-input, linux-kernel, linux-sunxi, Samuel Holland

There are many devices, including several mobile battery-powered
devices, using other AXP variants as their PMIC. Enable them to use
the power key as a wakeup source.

Signed-off-by: Samuel Holland <samuel@sholland.org>
---
 drivers/input/misc/axp20x-pek.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/input/misc/axp20x-pek.c b/drivers/input/misc/axp20x-pek.c
index 38cd4a4aeb65..b910c1798e4e 100644
--- a/drivers/input/misc/axp20x-pek.c
+++ b/drivers/input/misc/axp20x-pek.c
@@ -279,8 +279,7 @@ static int axp20x_pek_probe_input_device(struct axp20x_pek *axp20x_pek,
 		return error;
 	}
 
-	if (axp20x_pek->axp20x->variant == AXP288_ID)
-		device_init_wakeup(&pdev->dev, true);
+	device_init_wakeup(&pdev->dev, true);
 
 	return 0;
 }
-- 
2.23.0


^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH 2/3] Input: axp20x-pek - Respect userspace wakeup configuration
  2020-01-13  3:20 ` [PATCH 2/3] Input: axp20x-pek - Respect userspace wakeup configuration Samuel Holland
@ 2020-01-13  4:47   ` kbuild test robot
  2020-01-13 10:48   ` Hans de Goede
  2020-01-14  4:50   ` kbuild test robot
  2 siblings, 0 replies; 14+ messages in thread
From: kbuild test robot @ 2020-01-13  4:47 UTC (permalink / raw)
  To: Samuel Holland
  Cc: kbuild-all, Dmitry Torokhov, Chen-Yu Tsai, Hans de Goede,
	linux-input, linux-kernel, linux-sunxi, Samuel Holland

[-- Attachment #1: Type: text/plain, Size: 2059 bytes --]

Hi Samuel,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on input/next]
[also build test WARNING on v5.5-rc5 next-20200110]
[if your patch is applied to the wrong git tree, please drop us a note to help
improve the system. BTW, we also suggest to use '--base' option to specify the
base tree in git format-patch, please see https://stackoverflow.com/a/37406982]

url:    https://github.com/0day-ci/linux/commits/Samuel-Holland/Input-axp20x-pek-Remove-unique-wakeup-event-handling/20200113-112123
base:   https://git.kernel.org/pub/scm/linux/kernel/git/dtor/input.git next
config: m68k-allmodconfig (attached as .config)
compiler: m68k-linux-gcc (GCC) 7.5.0
reproduce:
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # save the attached .config to linux build tree
        GCC_VERSION=7.5.0 make.cross ARCH=m68k 

If you fix the issue, kindly add following tag
Reported-by: kbuild test robot <lkp@intel.com>

All warnings (new ones prefixed by >>):

>> drivers/input/misc/axp20x-pek.c:356:5: warning: "CONFIG_PM_SLEEP" is not defined, evaluates to 0 [-Wundef]
    #if CONFIG_PM_SLEEP
        ^~~~~~~~~~~~~~~

vim +/CONFIG_PM_SLEEP +356 drivers/input/misc/axp20x-pek.c

   355	
 > 356	#if CONFIG_PM_SLEEP
   357	static int axp20x_pek_suspend(struct device *dev)
   358	{
   359		struct axp20x_pek *axp20x_pek = dev_get_drvdata(dev);
   360	
   361		/*
   362		 * Nested threaded interrupts are not automatically
   363		 * disabled, so we must do it explicitly.
   364		 */
   365		if (device_may_wakeup(dev)) {
   366			enable_irq_wake(axp20x_pek->irq_dbf);
   367			enable_irq_wake(axp20x_pek->irq_dbr);
   368		} else {
   369			disable_irq(axp20x_pek->irq_dbf);
   370			disable_irq(axp20x_pek->irq_dbr);
   371		}
   372	
   373		return 0;
   374	}
   375	

---
0-DAY kernel test infrastructure                 Open Source Technology Center
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org Intel Corporation

[-- Attachment #2: .config.gz --]
[-- Type: application/gzip, Size: 51870 bytes --]

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH 1/3] Input: axp20x-pek - Remove unique wakeup event handling
  2020-01-13  3:20 [PATCH 1/3] Input: axp20x-pek - Remove unique wakeup event handling Samuel Holland
  2020-01-13  3:20 ` [PATCH 2/3] Input: axp20x-pek - Respect userspace wakeup configuration Samuel Holland
  2020-01-13  3:20 ` [PATCH 3/3] Input: axp20x-pek - Enable wakeup for all AXP variants Samuel Holland
@ 2020-01-13 10:41 ` Hans de Goede
  2020-01-13 10:58   ` Hans de Goede
  2 siblings, 1 reply; 14+ messages in thread
From: Hans de Goede @ 2020-01-13 10:41 UTC (permalink / raw)
  To: Samuel Holland, Dmitry Torokhov, Chen-Yu Tsai
  Cc: linux-input, linux-kernel, linux-sunxi

Hi,

On 13-01-2020 04:20, Samuel Holland wrote:
> This driver attempts to avoid reporting wakeup events to userspace by
> clearing a possible pending IRQ before IRQs are enabled during resume.
> The assumption seems to be that userspace cannot cope with a KEY_POWER
> press during resume. However, no other input driver does this, so it
> would be a bug that such events are missing with this driver.
> 
> Furthermore, for PMICs connected via I2C or RSB, it is not possible to
> update the regmap during the noirq resume phase, because the bus
> controller drivers require IRQs to perform bus transactions. And the
> resume hook cannot move to a later phase, because then it would race
> with the power key IRQ handler.
> 
> So the best solution seems to be simply removing the hook.

Hmm, I'm not sure this is a good idea, let me give you some background
info on this:

This hook was handled because on X86 systems/laptops when waking
them up typically the power-button does not send a KEY_POWER press event
when the system was woken up through the power-button.

So normal (e.g. Debian, Fedora) userspace does not expect this event
and will directly go to sleep again because that is the default behavior
on a KEY_POWER event.

On x86 axp20x-pek is only used for the power-button on Bay Trail devices
with a AXP288 PMIC. On Cherry Trail devices with an AXP288 PMIC the
power-button is also connected directly to a GPIO on the SoC and that
is used (also see the axp20x_pek_should_register_input function).

So after writing this patch, when doing hw-enablement for the power-button
on the Cherry Trail devices I learned that the gpio_keys driver does
send userspace a KEY_POWER event when woken up with the power-button.

I wrote a patch for gpio-keys to not do this, as that is what normal
Linux userspace expects, but that was nacked, because under e.g.
Android the KEY_POWER event is actually desirable / necessary to avoid
Android immediately re-suspending the system again. Since my "fix" to
the gpio-keys devices was nacked I have instead wroked around this in
userspace, but *only* for the GNOME3 desktop environment, by teaching
GNOME3 to ignore KEY_POWER events for the first couple of seconds after
a resume.

So your suggested change, which will cause KEY_POWER to be send on
Bay Trail devices after a wake-up by the power button, should be
fine for recent GNOME3 versions, but for other desktop environments
this may cause a regression where they respond to the new KEY_POWER
event by immediately going back to sleep again.

As for this not working with the i2c bus, it does on X86 because
the PMIC is also directly accessed by the power-management HW of
the SoC and to make this work the i2c-controller is never suspended
and its irq is marked IRQF_NO_SUSPEND. But this is X86 special
sauce.

Summarizing:

I'm personally fine with remove the magic I added to suppress
the KEY_POWER press reporting as in hindsight given the gpio-keys
story I should have never added it. But I'm worried about this
causing regressions for some Bay Trail users. OTOH making this
change would be good for Android X86 users.

Another IMHO better fix would be to drop the __maybe_unused and
instead wrap both the axp20x_pek_resume_noirq function and the
init of the  .resume_noirq struct member with:

#if defined X86 && defined CONFIG_PM_SLEEP

This keeps the current behavior on Bay Trail machines, while
I assume it should also fix the issues this was causing for
your setup.

Regards,

Hans








> Signed-off-by: Samuel Holland <samuel@sholland.org>
> ---
>   drivers/input/misc/axp20x-pek.c | 25 -------------------------
>   1 file changed, 25 deletions(-)
> 
> diff --git a/drivers/input/misc/axp20x-pek.c b/drivers/input/misc/axp20x-pek.c
> index 17c1cca74498..7d0ee5bececb 100644
> --- a/drivers/input/misc/axp20x-pek.c
> +++ b/drivers/input/misc/axp20x-pek.c
> @@ -352,30 +352,6 @@ static int axp20x_pek_probe(struct platform_device *pdev)
>   	return 0;
>   }
>   
> -static int __maybe_unused axp20x_pek_resume_noirq(struct device *dev)
> -{
> -	struct axp20x_pek *axp20x_pek = dev_get_drvdata(dev);
> -
> -	if (axp20x_pek->axp20x->variant != AXP288_ID)
> -		return 0;
> -
> -	/*
> -	 * Clear interrupts from button presses during suspend, to avoid
> -	 * a wakeup power-button press getting reported to userspace.
> -	 */
> -	regmap_write(axp20x_pek->axp20x->regmap,
> -		     AXP20X_IRQ1_STATE + AXP288_IRQ_POKN / 8,
> -		     BIT(AXP288_IRQ_POKN % 8));
> -
> -	return 0;
> -}
> -
> -static const struct dev_pm_ops axp20x_pek_pm_ops = {
> -#ifdef CONFIG_PM_SLEEP
> -	.resume_noirq = axp20x_pek_resume_noirq,
> -#endif
> -};
> -
>   static const struct platform_device_id axp_pek_id_match[] = {
>   	{
>   		.name = "axp20x-pek",
> @@ -394,7 +370,6 @@ static struct platform_driver axp20x_pek_driver = {
>   	.id_table	= axp_pek_id_match,
>   	.driver		= {
>   		.name		= "axp20x-pek",
> -		.pm		= &axp20x_pek_pm_ops,
>   		.dev_groups	= axp20x_groups,
>   	},
>   };
> 


^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH 2/3] Input: axp20x-pek - Respect userspace wakeup configuration
  2020-01-13  3:20 ` [PATCH 2/3] Input: axp20x-pek - Respect userspace wakeup configuration Samuel Holland
  2020-01-13  4:47   ` kbuild test robot
@ 2020-01-13 10:48   ` Hans de Goede
  2020-01-13 21:38     ` Dmitry Torokhov
  2020-01-14  4:50   ` kbuild test robot
  2 siblings, 1 reply; 14+ messages in thread
From: Hans de Goede @ 2020-01-13 10:48 UTC (permalink / raw)
  To: Samuel Holland, Dmitry Torokhov, Chen-Yu Tsai
  Cc: linux-input, linux-kernel, linux-sunxi

Hi,

On 13-01-2020 04:20, Samuel Holland wrote:
> Unlike most other power button drivers, this driver unconditionally
> enables its wakeup IRQ. It should be using device_may_wakeup() to
> respect the userspace configuration of wakeup sources.
> 
> Because the AXP20x MFD device uses regmap-irq, the AXP20x PEK IRQs are
> nested off of regmap-irq's threaded interrupt handler. The device core
> ignores such interrupts, so to actually disable wakeup, we must
> explicitly disable all non-wakeup interrupts during suspend.
> 
> Signed-off-by: Samuel Holland <samuel@sholland.org>
> ---
>   drivers/input/misc/axp20x-pek.c | 42 ++++++++++++++++++++++++++++++++-
>   1 file changed, 41 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/input/misc/axp20x-pek.c b/drivers/input/misc/axp20x-pek.c
> index 7d0ee5bececb..38cd4a4aeb65 100644
> --- a/drivers/input/misc/axp20x-pek.c
> +++ b/drivers/input/misc/axp20x-pek.c
> @@ -280,7 +280,7 @@ static int axp20x_pek_probe_input_device(struct axp20x_pek *axp20x_pek,
>   	}
>   
>   	if (axp20x_pek->axp20x->variant == AXP288_ID)
> -		enable_irq_wake(axp20x_pek->irq_dbr);
> +		device_init_wakeup(&pdev->dev, true);
>   
>   	return 0;
>   }
> @@ -352,6 +352,45 @@ static int axp20x_pek_probe(struct platform_device *pdev)
>   	return 0;
>   }
>   
> +#if CONFIG_PM_SLEEP

As the kbuild test robot pointed out, you need to use #ifdef here.

Otherwise this patch looks good to me:

Reviewed-by: Hans de Goede <hdegoede@redhat.com>

Regards,

Hans



> +static int axp20x_pek_suspend(struct device *dev)
> +{
> +	struct axp20x_pek *axp20x_pek = dev_get_drvdata(dev);
> +
> +	/*
> +	 * Nested threaded interrupts are not automatically
> +	 * disabled, so we must do it explicitly.
> +	 */
> +	if (device_may_wakeup(dev)) {
> +		enable_irq_wake(axp20x_pek->irq_dbf);
> +		enable_irq_wake(axp20x_pek->irq_dbr);
> +	} else {
> +		disable_irq(axp20x_pek->irq_dbf);
> +		disable_irq(axp20x_pek->irq_dbr);
> +	}
> +
> +	return 0;
> +}
> +
> +static int axp20x_pek_resume(struct device *dev)
> +{
> +	struct axp20x_pek *axp20x_pek = dev_get_drvdata(dev);
> +
> +	if (device_may_wakeup(dev)) {
> +		disable_irq_wake(axp20x_pek->irq_dbf);
> +		disable_irq_wake(axp20x_pek->irq_dbr);
> +	} else {
> +		enable_irq(axp20x_pek->irq_dbf);
> +		enable_irq(axp20x_pek->irq_dbr);
> +	}
> +
> +	return 0;
> +}
> +#endif
> +
> +static SIMPLE_DEV_PM_OPS(axp20x_pek_pm_ops, axp20x_pek_suspend,
> +					    axp20x_pek_resume);
> +
>   static const struct platform_device_id axp_pek_id_match[] = {
>   	{
>   		.name = "axp20x-pek",
> @@ -371,6 +410,7 @@ static struct platform_driver axp20x_pek_driver = {
>   	.driver		= {
>   		.name		= "axp20x-pek",
>   		.dev_groups	= axp20x_groups,
> +		.pm		= &axp20x_pek_pm_ops,
>   	},
>   };
>   module_platform_driver(axp20x_pek_driver);
> 


^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH 3/3] Input: axp20x-pek - Enable wakeup for all AXP variants
  2020-01-13  3:20 ` [PATCH 3/3] Input: axp20x-pek - Enable wakeup for all AXP variants Samuel Holland
@ 2020-01-13 10:48   ` Hans de Goede
  2020-01-13 21:26   ` Dmitry Torokhov
  1 sibling, 0 replies; 14+ messages in thread
From: Hans de Goede @ 2020-01-13 10:48 UTC (permalink / raw)
  To: Samuel Holland, Dmitry Torokhov, Chen-Yu Tsai
  Cc: linux-input, linux-kernel, linux-sunxi

Hi,

On 13-01-2020 04:20, Samuel Holland wrote:
> There are many devices, including several mobile battery-powered
> devices, using other AXP variants as their PMIC. Enable them to use
> the power key as a wakeup source.
> 
> Signed-off-by: Samuel Holland <samuel@sholland.org>


Patch looks good to me:

Reviewed-by: Hans de Goede <hdegoede@redhat.com>

Regards,

Hans

> ---
>   drivers/input/misc/axp20x-pek.c | 3 +--
>   1 file changed, 1 insertion(+), 2 deletions(-)
> 
> diff --git a/drivers/input/misc/axp20x-pek.c b/drivers/input/misc/axp20x-pek.c
> index 38cd4a4aeb65..b910c1798e4e 100644
> --- a/drivers/input/misc/axp20x-pek.c
> +++ b/drivers/input/misc/axp20x-pek.c
> @@ -279,8 +279,7 @@ static int axp20x_pek_probe_input_device(struct axp20x_pek *axp20x_pek,
>   		return error;
>   	}
>   
> -	if (axp20x_pek->axp20x->variant == AXP288_ID)
> -		device_init_wakeup(&pdev->dev, true);
> +	device_init_wakeup(&pdev->dev, true);
>   
>   	return 0;
>   }
> 


^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH 1/3] Input: axp20x-pek - Remove unique wakeup event handling
  2020-01-13 10:41 ` [PATCH 1/3] Input: axp20x-pek - Remove unique wakeup event handling Hans de Goede
@ 2020-01-13 10:58   ` Hans de Goede
  2020-01-15  4:29     ` [linux-sunxi] " Samuel Holland
  0 siblings, 1 reply; 14+ messages in thread
From: Hans de Goede @ 2020-01-13 10:58 UTC (permalink / raw)
  To: Samuel Holland, Dmitry Torokhov, Chen-Yu Tsai
  Cc: linux-input, linux-kernel, linux-sunxi

On 13-01-2020 11:41, Hans de Goede wrote:
> Hi,
> 
> On 13-01-2020 04:20, Samuel Holland wrote:
>> This driver attempts to avoid reporting wakeup events to userspace by
>> clearing a possible pending IRQ before IRQs are enabled during resume.
>> The assumption seems to be that userspace cannot cope with a KEY_POWER
>> press during resume. However, no other input driver does this, so it
>> would be a bug that such events are missing with this driver.
>>
>> Furthermore, for PMICs connected via I2C or RSB, it is not possible to
>> update the regmap during the noirq resume phase, because the bus
>> controller drivers require IRQs to perform bus transactions. And the
>> resume hook cannot move to a later phase, because then it would race
>> with the power key IRQ handler.
>>
>> So the best solution seems to be simply removing the hook.
> 
> Hmm, I'm not sure this is a good idea, let me give you some background
> info on this:
> 
> This hook was handled because on X86 systems/laptops when waking
> them up typically the power-button does not send a KEY_POWER press event
> when the system was woken up through the power-button.
> 
> So normal (e.g. Debian, Fedora) userspace does not expect this event
> and will directly go to sleep again because that is the default behavior
> on a KEY_POWER event.

p.s.

The main reason why typical userspace does not expect the KEY_POWER
event is because most of the devices which run mainline and have
suspend/resume working and are using the ACPI button driver for
the power-button: drivers/acpi/button.c, which has:

                         acpi_pm_wakeup_event(&device->dev);
                         if (button->suspended)
                                 break;

                         keycode = test_bit(KEY_SLEEP, input->keybit) ?
                                                 KEY_SLEEP : KEY_POWER;
                         input_report_key(input, keycode, 1);
                         input_sync(input);
                         input_report_key(input, keycode, 0);
                         input_sync(input);

And:

static int acpi_button_suspend(struct device *dev)
{
         struct acpi_device *device = to_acpi_device(dev);
         struct acpi_button *button = acpi_driver_data(device);

         button->suspended = true;
         return 0;
}

static int acpi_button_resume(struct device *dev)
{
         struct acpi_device *device = to_acpi_device(dev);
         struct acpi_button *button = acpi_driver_data(device);

         button->suspended = false;
         return 0;
}

So when the ACPI notify for the button runs on resume, suspended is
still true; and no KEY_POWER event is send...

Arguably to be consistent we should fix drivers/acpi/button.c to
send KEY_POWER on wakeup too, but that will break things for many
users with a likelyhood of breakage approaching 100%.

Note I'm not telling this to argue against your change, just as
background for why I added this behavior to the axp20x-pek code.

Oh and taking a second look, I see that the hook is already
written so as to only execute on the AXP288 PMIC, which means
it should effectively already only influence X86 machines.

So are you trying to get the KEY_POWER event after wakeup
by power-button to work on a X86 device ?  In that case please
be aware of the drivers/acpi/button.c issue...

I have the feeling that we may need a Kconfig option to configure
whether or not to send KEY_POWER on wakeup by power-button, because
as discussed in my previous mail Android wants this, KDE/MATE/GNOME
not so much...

Regards,

Hans



> 
> On x86 axp20x-pek is only used for the power-button on Bay Trail devices
> with a AXP288 PMIC. On Cherry Trail devices with an AXP288 PMIC the
> power-button is also connected directly to a GPIO on the SoC and that
> is used (also see the axp20x_pek_should_register_input function).
> 
> So after writing this patch, when doing hw-enablement for the power-button
> on the Cherry Trail devices I learned that the gpio_keys driver does
> send userspace a KEY_POWER event when woken up with the power-button.
> 
> I wrote a patch for gpio-keys to not do this, as that is what normal
> Linux userspace expects, but that was nacked, because under e.g.
> Android the KEY_POWER event is actually desirable / necessary to avoid
> Android immediately re-suspending the system again. Since my "fix" to
> the gpio-keys devices was nacked I have instead wroked around this in
> userspace, but *only* for the GNOME3 desktop environment, by teaching
> GNOME3 to ignore KEY_POWER events for the first couple of seconds after
> a resume.
> 
> So your suggested change, which will cause KEY_POWER to be send on
> Bay Trail devices after a wake-up by the power button, should be
> fine for recent GNOME3 versions, but for other desktop environments
> this may cause a regression where they respond to the new KEY_POWER
> event by immediately going back to sleep again.
> 
> As for this not working with the i2c bus, it does on X86 because
> the PMIC is also directly accessed by the power-management HW of
> the SoC and to make this work the i2c-controller is never suspended
> and its irq is marked IRQF_NO_SUSPEND. But this is X86 special
> sauce.
> 
> Summarizing:
> 
> I'm personally fine with remove the magic I added to suppress
> the KEY_POWER press reporting as in hindsight given the gpio-keys
> story I should have never added it. But I'm worried about this
> causing regressions for some Bay Trail users. OTOH making this
> change would be good for Android X86 users.
> 
> Another IMHO better fix would be to drop the __maybe_unused and
> instead wrap both the axp20x_pek_resume_noirq function and the
> init of the  .resume_noirq struct member with:
> 
> #if defined X86 && defined CONFIG_PM_SLEEP
> 
> This keeps the current behavior on Bay Trail machines, while
> I assume it should also fix the issues this was causing for
> your setup.
> 
> Regards,
> 
> Hans
> 
> 
> 
> 
> 
> 
> 
> 
>> Signed-off-by: Samuel Holland <samuel@sholland.org>
>> ---
>>   drivers/input/misc/axp20x-pek.c | 25 -------------------------
>>   1 file changed, 25 deletions(-)
>>
>> diff --git a/drivers/input/misc/axp20x-pek.c b/drivers/input/misc/axp20x-pek.c
>> index 17c1cca74498..7d0ee5bececb 100644
>> --- a/drivers/input/misc/axp20x-pek.c
>> +++ b/drivers/input/misc/axp20x-pek.c
>> @@ -352,30 +352,6 @@ static int axp20x_pek_probe(struct platform_device *pdev)
>>       return 0;
>>   }
>> -static int __maybe_unused axp20x_pek_resume_noirq(struct device *dev)
>> -{
>> -    struct axp20x_pek *axp20x_pek = dev_get_drvdata(dev);
>> -
>> -    if (axp20x_pek->axp20x->variant != AXP288_ID)
>> -        return 0;
>> -
>> -    /*
>> -     * Clear interrupts from button presses during suspend, to avoid
>> -     * a wakeup power-button press getting reported to userspace.
>> -     */
>> -    regmap_write(axp20x_pek->axp20x->regmap,
>> -             AXP20X_IRQ1_STATE + AXP288_IRQ_POKN / 8,
>> -             BIT(AXP288_IRQ_POKN % 8));
>> -
>> -    return 0;
>> -}
>> -
>> -static const struct dev_pm_ops axp20x_pek_pm_ops = {
>> -#ifdef CONFIG_PM_SLEEP
>> -    .resume_noirq = axp20x_pek_resume_noirq,
>> -#endif
>> -};
>> -
>>   static const struct platform_device_id axp_pek_id_match[] = {
>>       {
>>           .name = "axp20x-pek",
>> @@ -394,7 +370,6 @@ static struct platform_driver axp20x_pek_driver = {
>>       .id_table    = axp_pek_id_match,
>>       .driver        = {
>>           .name        = "axp20x-pek",
>> -        .pm        = &axp20x_pek_pm_ops,
>>           .dev_groups    = axp20x_groups,
>>       },
>>   };
>>


^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH 3/3] Input: axp20x-pek - Enable wakeup for all AXP variants
  2020-01-13  3:20 ` [PATCH 3/3] Input: axp20x-pek - Enable wakeup for all AXP variants Samuel Holland
  2020-01-13 10:48   ` Hans de Goede
@ 2020-01-13 21:26   ` Dmitry Torokhov
  2020-01-14  9:07     ` Hans de Goede
  1 sibling, 1 reply; 14+ messages in thread
From: Dmitry Torokhov @ 2020-01-13 21:26 UTC (permalink / raw)
  To: Samuel Holland
  Cc: Chen-Yu Tsai, Hans de Goede, linux-input, linux-kernel, linux-sunxi

Hi Samuel,

On Sun, Jan 12, 2020 at 09:20:32PM -0600, Samuel Holland wrote:
> There are many devices, including several mobile battery-powered
> devices, using other AXP variants as their PMIC. Enable them to use
> the power key as a wakeup source.

Are these X86 or ARM devices? If anything, I'd prefer individual drivers
not declare themselves as wakeup sources unconditionally. With devic
etree we have standard "wakeup-source" property, but I am not quite sure
what's the latest on X86...

Thanks.

-- 
Dmitry

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH 2/3] Input: axp20x-pek - Respect userspace wakeup configuration
  2020-01-13 10:48   ` Hans de Goede
@ 2020-01-13 21:38     ` Dmitry Torokhov
  0 siblings, 0 replies; 14+ messages in thread
From: Dmitry Torokhov @ 2020-01-13 21:38 UTC (permalink / raw)
  To: Hans de Goede
  Cc: Samuel Holland, Chen-Yu Tsai, linux-input, linux-kernel, linux-sunxi

On Mon, Jan 13, 2020 at 11:48:35AM +0100, Hans de Goede wrote:
> Hi,
> 
> On 13-01-2020 04:20, Samuel Holland wrote:
> > Unlike most other power button drivers, this driver unconditionally
> > enables its wakeup IRQ. It should be using device_may_wakeup() to
> > respect the userspace configuration of wakeup sources.
> > 
> > Because the AXP20x MFD device uses regmap-irq, the AXP20x PEK IRQs are
> > nested off of regmap-irq's threaded interrupt handler. The device core
> > ignores such interrupts, so to actually disable wakeup, we must
> > explicitly disable all non-wakeup interrupts during suspend.
> > 
> > Signed-off-by: Samuel Holland <samuel@sholland.org>
> > ---
> >   drivers/input/misc/axp20x-pek.c | 42 ++++++++++++++++++++++++++++++++-
> >   1 file changed, 41 insertions(+), 1 deletion(-)
> > 
> > diff --git a/drivers/input/misc/axp20x-pek.c b/drivers/input/misc/axp20x-pek.c
> > index 7d0ee5bececb..38cd4a4aeb65 100644
> > --- a/drivers/input/misc/axp20x-pek.c
> > +++ b/drivers/input/misc/axp20x-pek.c
> > @@ -280,7 +280,7 @@ static int axp20x_pek_probe_input_device(struct axp20x_pek *axp20x_pek,
> >   	}
> >   	if (axp20x_pek->axp20x->variant == AXP288_ID)
> > -		enable_irq_wake(axp20x_pek->irq_dbr);
> > +		device_init_wakeup(&pdev->dev, true);
> >   	return 0;
> >   }
> > @@ -352,6 +352,45 @@ static int axp20x_pek_probe(struct platform_device *pdev)
> >   	return 0;
> >   }
> > +#if CONFIG_PM_SLEEP
> 
> As the kbuild test robot pointed out, you need to use #ifdef here.

I prefer __maybe_unused as this gives more compile coverage.

Thanks.

-- 
Dmitry

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH 2/3] Input: axp20x-pek - Respect userspace wakeup configuration
  2020-01-13  3:20 ` [PATCH 2/3] Input: axp20x-pek - Respect userspace wakeup configuration Samuel Holland
  2020-01-13  4:47   ` kbuild test robot
  2020-01-13 10:48   ` Hans de Goede
@ 2020-01-14  4:50   ` kbuild test robot
  2 siblings, 0 replies; 14+ messages in thread
From: kbuild test robot @ 2020-01-14  4:50 UTC (permalink / raw)
  To: Samuel Holland
  Cc: kbuild-all, Dmitry Torokhov, Chen-Yu Tsai, Hans de Goede,
	linux-input, linux-kernel, linux-sunxi, Samuel Holland

[-- Attachment #1: Type: text/plain, Size: 3716 bytes --]

Hi Samuel,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on input/next]
[also build test WARNING on v5.5-rc6 next-20200110]
[if your patch is applied to the wrong git tree, please drop us a note to help
improve the system. BTW, we also suggest to use '--base' option to specify the
base tree in git format-patch, please see https://stackoverflow.com/a/37406982]

url:    https://github.com/0day-ci/linux/commits/Samuel-Holland/Input-axp20x-pek-Remove-unique-wakeup-event-handling/20200113-112123
base:   https://git.kernel.org/pub/scm/linux/kernel/git/dtor/input.git next
config: x86_64-randconfig-a001-20200112 (attached as .config)
compiler: gcc-5 (Ubuntu 5.5.0-12ubuntu1) 5.5.0 20171010
reproduce:
        # save the attached .config to linux build tree
        make ARCH=x86_64 

If you fix the issue, kindly add following tag
Reported-by: kbuild test robot <lkp@intel.com>

All warnings (new ones prefixed by >>):

>> drivers/input/misc/axp20x-pek.c:356:5: warning: "CONFIG_PM_SLEEP" is not defined [-Wundef]
    #if CONFIG_PM_SLEEP
        ^
   Cyclomatic Complexity 1 arch/x86/include/asm/bitops.h:ffs
   Cyclomatic Complexity 1 include/linux/pm_wakeup.h:device_set_wakeup_capable
   Cyclomatic Complexity 1 include/linux/pm_wakeup.h:device_set_wakeup_enable
   Cyclomatic Complexity 1 include/linux/pm_wakeup.h:device_init_wakeup
   Cyclomatic Complexity 1 include/linux/device.h:dev_get_drvdata
   Cyclomatic Complexity 1 include/linux/device.h:dev_set_drvdata
   Cyclomatic Complexity 1 include/linux/input.h:input_get_drvdata
   Cyclomatic Complexity 1 include/linux/input.h:input_set_drvdata
   Cyclomatic Complexity 1 include/linux/platform_device.h:platform_set_drvdata
   Cyclomatic Complexity 1 drivers/input/misc/axp20x-pek.c:axp20x_pek_should_register_input
   Cyclomatic Complexity 1 drivers/input/misc/axp20x-pek.c:axp20x_pek_driver_init
   Cyclomatic Complexity 22 drivers/input/misc/axp20x-pek.c:axp20x_store_attr
   Cyclomatic Complexity 1 drivers/input/misc/axp20x-pek.c:axp20x_store_attr_shutdown
   Cyclomatic Complexity 1 drivers/input/misc/axp20x-pek.c:axp20x_store_attr_startup
   Cyclomatic Complexity 8 drivers/input/misc/axp20x-pek.c:axp20x_show_attr
   Cyclomatic Complexity 1 drivers/input/misc/axp20x-pek.c:axp20x_show_attr_shutdown
   Cyclomatic Complexity 1 drivers/input/misc/axp20x-pek.c:axp20x_show_attr_startup
   Cyclomatic Complexity 1 include/linux/device.h:devm_kzalloc
   Cyclomatic Complexity 22 drivers/input/misc/axp20x-pek.c:axp20x_pek_probe_input_device
   Cyclomatic Complexity 12 drivers/input/misc/axp20x-pek.c:axp20x_pek_probe
   Cyclomatic Complexity 1 include/linux/input.h:input_report_key
   Cyclomatic Complexity 1 include/linux/input.h:input_sync
   Cyclomatic Complexity 7 drivers/input/misc/axp20x-pek.c:axp20x_pek_irq
   Cyclomatic Complexity 1 drivers/input/misc/axp20x-pek.c:axp20x_pek_driver_exit

vim +/CONFIG_PM_SLEEP +356 drivers/input/misc/axp20x-pek.c

   355	
 > 356	#if CONFIG_PM_SLEEP
   357	static int axp20x_pek_suspend(struct device *dev)
   358	{
   359		struct axp20x_pek *axp20x_pek = dev_get_drvdata(dev);
   360	
   361		/*
   362		 * Nested threaded interrupts are not automatically
   363		 * disabled, so we must do it explicitly.
   364		 */
   365		if (device_may_wakeup(dev)) {
   366			enable_irq_wake(axp20x_pek->irq_dbf);
   367			enable_irq_wake(axp20x_pek->irq_dbr);
   368		} else {
   369			disable_irq(axp20x_pek->irq_dbf);
   370			disable_irq(axp20x_pek->irq_dbr);
   371		}
   372	
   373		return 0;
   374	}
   375	

---
0-DAY kernel test infrastructure                 Open Source Technology Center
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org Intel Corporation

[-- Attachment #2: .config.gz --]
[-- Type: application/gzip, Size: 32888 bytes --]

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH 3/3] Input: axp20x-pek - Enable wakeup for all AXP variants
  2020-01-13 21:26   ` Dmitry Torokhov
@ 2020-01-14  9:07     ` Hans de Goede
  2020-01-15  4:45       ` Samuel Holland
  0 siblings, 1 reply; 14+ messages in thread
From: Hans de Goede @ 2020-01-14  9:07 UTC (permalink / raw)
  To: Dmitry Torokhov, Samuel Holland
  Cc: Chen-Yu Tsai, linux-input, linux-kernel, linux-sunxi

Hi,

On 13-01-2020 22:26, Dmitry Torokhov wrote:
> Hi Samuel,
> 
> On Sun, Jan 12, 2020 at 09:20:32PM -0600, Samuel Holland wrote:
>> There are many devices, including several mobile battery-powered
>> devices, using other AXP variants as their PMIC. Enable them to use
>> the power key as a wakeup source.
> 
> Are these X86 or ARM devices? If anything, I'd prefer individual drivers
> not declare themselves as wakeup sources unconditionally. With devic
> etree we have standard "wakeup-source" property, but I am not quite sure
> what's the latest on X86...

The AXP288 variant is X86, the other PMIC models are for ARM
(to the best of my knowledge).

Regards,

Hans


^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [linux-sunxi] Re: [PATCH 1/3] Input: axp20x-pek - Remove unique wakeup event handling
  2020-01-13 10:58   ` Hans de Goede
@ 2020-01-15  4:29     ` " Samuel Holland
  0 siblings, 0 replies; 14+ messages in thread
From: Samuel Holland @ 2020-01-15  4:29 UTC (permalink / raw)
  To: hdegoede, Dmitry Torokhov, Chen-Yu Tsai
  Cc: linux-input, linux-kernel, linux-sunxi

Hans,

Thank you for the detailed explanation! This is exactly the background I needed,
and it clears up my confusion.

On 1/13/20 4:58 AM, Hans de Goede wrote:
> On 13-01-2020 11:41, Hans de Goede wrote:
>> Hi,
>>
>> On 13-01-2020 04:20, Samuel Holland wrote:
>>> This driver attempts to avoid reporting wakeup events to userspace by
>>> clearing a possible pending IRQ before IRQs are enabled during resume.
>>> The assumption seems to be that userspace cannot cope with a KEY_POWER
>>> press during resume. However, no other input driver does this, so it
>>> would be a bug that such events are missing with this driver.
>>>
>>> Furthermore, for PMICs connected via I2C or RSB, it is not possible to
>>> update the regmap during the noirq resume phase, because the bus
>>> controller drivers require IRQs to perform bus transactions. And the
>>> resume hook cannot move to a later phase, because then it would race
>>> with the power key IRQ handler.
>>>
>>> So the best solution seems to be simply removing the hook.
>>
>> Hmm, I'm not sure this is a good idea, let me give you some background
>> info on this:
>>
>> This hook was handled because on X86 systems/laptops when waking
>> them up typically the power-button does not send a KEY_POWER press event
>> when the system was woken up through the power-button.
>>
>> So normal (e.g. Debian, Fedora) userspace does not expect this event
>> and will directly go to sleep again because that is the default behavior
>> on a KEY_POWER event.
> 
> p.s.
> 
> The main reason why typical userspace does not expect the KEY_POWER
> event is because most of the devices which run mainline and have
> suspend/resume working and are using the ACPI button driver for
> the power-button: drivers/acpi/button.c, which has:

Ah, that explains why I didn't see this driver: I was only looking in
drivers/input. I was surprised to find none of the other drivers having similar
hooks.

>                         acpi_pm_wakeup_event(&device->dev);
>                         if (button->suspended)
>                                 break;
> 
>                         keycode = test_bit(KEY_SLEEP, input->keybit) ?
>                                                 KEY_SLEEP : KEY_POWER;
>                         input_report_key(input, keycode, 1);
>                         input_sync(input);
>                         input_report_key(input, keycode, 0);
>                         input_sync(input);
> 
> And:
> 
> static int acpi_button_suspend(struct device *dev)
> {
>         struct acpi_device *device = to_acpi_device(dev);
>         struct acpi_button *button = acpi_driver_data(device);
> 
>         button->suspended = true;
>         return 0;
> }
> 
> static int acpi_button_resume(struct device *dev)
> {
>         struct acpi_device *device = to_acpi_device(dev);
>         struct acpi_button *button = acpi_driver_data(device);
> 
>         button->suspended = false;
>         return 0;
> }
> 
> So when the ACPI notify for the button runs on resume, suspended is
> still true; and no KEY_POWER event is send...

I tried to implement this same kind of logic for axp20x-pek, but I dropped it
because it's racy in my situation. regmap-irq uses a threaded IRQ, and the
RSB/I2C bus controllers use interrupts and completions. So if the ->resume()
hook gets called before we can read 3 IRQ status registers from the PMIC, we'd
get a spurious KEY_POWER event.

> Arguably to be consistent we should fix drivers/acpi/button.c to
> send KEY_POWER on wakeup too, but that will break things for many
> users with a likelyhood of breakage approaching 100%.
> 
> Note I'm not telling this to argue against your change, just as
> background for why I added this behavior to the axp20x-pek code.
> 
> Oh and taking a second look, I see that the hook is already
> written so as to only execute on the AXP288 PMIC, which means
> it should effectively already only influence X86 machines.

I wasn't sure if AXP288 was x86-only. Thanks for confirming this.

> So are you trying to get the KEY_POWER event after wakeup
> by power-button to work on a X86 device ?  In that case please
> be aware of the drivers/acpi/button.c issue...
> 
> I have the feeling that we may need a Kconfig option to configure
> whether or not to send KEY_POWER on wakeup by power-button, because
> as discussed in my previous mail Android wants this, KDE/MATE/GNOME
> not so much...

I'm working on the Allwinner sunxi platform (arm64) using AXP8xx. Specifically,
though, I'm working with the PinePhone, which is designed to run mainline Linux
and non-Android userspace, such as GNOME derivatives or KDE Plasma Mobile. Those
GUI environments might be expecting the x86 behavior.

> Regards,
> 
> Hans
> 
> 
> 
>>
>> On x86 axp20x-pek is only used for the power-button on Bay Trail devices
>> with a AXP288 PMIC. On Cherry Trail devices with an AXP288 PMIC the
>> power-button is also connected directly to a GPIO on the SoC and that
>> is used (also see the axp20x_pek_should_register_input function).
>>
>> So after writing this patch, when doing hw-enablement for the power-button
>> on the Cherry Trail devices I learned that the gpio_keys driver does
>> send userspace a KEY_POWER event when woken up with the power-button.
>>
>> I wrote a patch for gpio-keys to not do this, as that is what normal
>> Linux userspace expects, but that was nacked, because under e.g.
>> Android the KEY_POWER event is actually desirable / necessary to avoid
>> Android immediately re-suspending the system again. Since my "fix" to
>> the gpio-keys devices was nacked I have instead wroked around this in
>> userspace, but *only* for the GNOME3 desktop environment, by teaching
>> GNOME3 to ignore KEY_POWER events for the first couple of seconds after
>> a resume.
>>
>> So your suggested change, which will cause KEY_POWER to be send on
>> Bay Trail devices after a wake-up by the power button, should be
>> fine for recent GNOME3 versions, but for other desktop environments
>> this may cause a regression where they respond to the new KEY_POWER
>> event by immediately going back to sleep again.
>>
>> As for this not working with the i2c bus, it does on X86 because
>> the PMIC is also directly accessed by the power-management HW of
>> the SoC and to make this work the i2c-controller is never suspended
>> and its irq is marked IRQF_NO_SUSPEND. But this is X86 special
>> sauce.
>>
>> Summarizing:
>>
>> I'm personally fine with remove the magic I added to suppress
>> the KEY_POWER press reporting as in hindsight given the gpio-keys
>> story I should have never added it. But I'm worried about this
>> causing regressions for some Bay Trail users. OTOH making this
>> change would be good for Android X86 users.
>>
>> Another IMHO better fix would be to drop the __maybe_unused and
>> instead wrap both the axp20x_pek_resume_noirq function and the
>> init of the  .resume_noirq struct member with:
>>
>> #if defined X86 && defined CONFIG_PM_SLEEP
>>
>> This keeps the current behavior on Bay Trail machines, while
>> I assume it should also fix the issues this was causing for
>> your setup.

I think just dropping this patch will have the same effect, and it's what I plan
to do for v2. As you mentioned, AXP288 is x86 only, and the code works with the
i2c controller there. So as long as the hook applies only to AXP288, it should
be fine.

If receiving KEY_POWER during resume turns out to be an issue on other PMIC
variants, I'll look for a more generic solution then. Maybe the input core can
be taught to drop the first KEY_POWER event received during system resume.

Thanks again!
Samuel

>> Regards,
>>
>> Hans
>>
>>
>>
>>
>>
>>
>>
>>
>>> Signed-off-by: Samuel Holland <samuel@sholland.org>
>>> ---
>>>   drivers/input/misc/axp20x-pek.c | 25 -------------------------
>>>   1 file changed, 25 deletions(-)
>>>
>>> diff --git a/drivers/input/misc/axp20x-pek.c b/drivers/input/misc/axp20x-pek.c
>>> index 17c1cca74498..7d0ee5bececb 100644
>>> --- a/drivers/input/misc/axp20x-pek.c
>>> +++ b/drivers/input/misc/axp20x-pek.c
>>> @@ -352,30 +352,6 @@ static int axp20x_pek_probe(struct platform_device *pdev)
>>>       return 0;
>>>   }
>>> -static int __maybe_unused axp20x_pek_resume_noirq(struct device *dev)
>>> -{
>>> -    struct axp20x_pek *axp20x_pek = dev_get_drvdata(dev);
>>> -
>>> -    if (axp20x_pek->axp20x->variant != AXP288_ID)
>>> -        return 0;
>>> -
>>> -    /*
>>> -     * Clear interrupts from button presses during suspend, to avoid
>>> -     * a wakeup power-button press getting reported to userspace.
>>> -     */
>>> -    regmap_write(axp20x_pek->axp20x->regmap,
>>> -             AXP20X_IRQ1_STATE + AXP288_IRQ_POKN / 8,
>>> -             BIT(AXP288_IRQ_POKN % 8));
>>> -
>>> -    return 0;
>>> -}
>>> -
>>> -static const struct dev_pm_ops axp20x_pek_pm_ops = {
>>> -#ifdef CONFIG_PM_SLEEP
>>> -    .resume_noirq = axp20x_pek_resume_noirq,
>>> -#endif
>>> -};
>>> -
>>>   static const struct platform_device_id axp_pek_id_match[] = {
>>>       {
>>>           .name = "axp20x-pek",
>>> @@ -394,7 +370,6 @@ static struct platform_driver axp20x_pek_driver = {
>>>       .id_table    = axp_pek_id_match,
>>>       .driver        = {
>>>           .name        = "axp20x-pek",
>>> -        .pm        = &axp20x_pek_pm_ops,
>>>           .dev_groups    = axp20x_groups,
>>>       },
>>>   };
>>>
> 


^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH 3/3] Input: axp20x-pek - Enable wakeup for all AXP variants
  2020-01-14  9:07     ` Hans de Goede
@ 2020-01-15  4:45       ` Samuel Holland
  0 siblings, 0 replies; 14+ messages in thread
From: Samuel Holland @ 2020-01-15  4:45 UTC (permalink / raw)
  To: Hans de Goede, Dmitry Torokhov
  Cc: Chen-Yu Tsai, linux-input, linux-kernel, linux-sunxi

Hi,

On 1/14/20 3:07 AM, Hans de Goede wrote:
> Hi,
> 
> On 13-01-2020 22:26, Dmitry Torokhov wrote:
>> Hi Samuel,
>>
>> On Sun, Jan 12, 2020 at 09:20:32PM -0600, Samuel Holland wrote:
>>> There are many devices, including several mobile battery-powered
>>> devices, using other AXP variants as their PMIC. Enable them to use
>>> the power key as a wakeup source.
>>
>> Are these X86 or ARM devices? If anything, I'd prefer individual drivers
>> not declare themselves as wakeup sources unconditionally. With devic
>> etree we have standard "wakeup-source" property, but I am not quite sure
>> what's the latest on X86...

Currently wakeup is unconditional. After patch 2, even though it's enabled by
default, the wakeup source can be disabled by userspace:

-		enable_irq_wake(axp20x_pek->irq_dbr);
+		device_init_wakeup(&pdev->dev, true);

This is a platform driver for an MFD cell. It does not have its own device tree
node.

(I see a lot of drivers in drivers/input/misc that generate KEY_POWER, and zero
of them reference "wakeup-source". It's a driver for a power button. Being a
wakeup source is half the purpose of its existence.)

> The AXP288 variant is X86, the other PMIC models are for ARM
> (to the best of my knowledge).

That's also my understanding.

> Regards,
> 
> Hans

Regards,
Samuel

^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, back to index

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-01-13  3:20 [PATCH 1/3] Input: axp20x-pek - Remove unique wakeup event handling Samuel Holland
2020-01-13  3:20 ` [PATCH 2/3] Input: axp20x-pek - Respect userspace wakeup configuration Samuel Holland
2020-01-13  4:47   ` kbuild test robot
2020-01-13 10:48   ` Hans de Goede
2020-01-13 21:38     ` Dmitry Torokhov
2020-01-14  4:50   ` kbuild test robot
2020-01-13  3:20 ` [PATCH 3/3] Input: axp20x-pek - Enable wakeup for all AXP variants Samuel Holland
2020-01-13 10:48   ` Hans de Goede
2020-01-13 21:26   ` Dmitry Torokhov
2020-01-14  9:07     ` Hans de Goede
2020-01-15  4:45       ` Samuel Holland
2020-01-13 10:41 ` [PATCH 1/3] Input: axp20x-pek - Remove unique wakeup event handling Hans de Goede
2020-01-13 10:58   ` Hans de Goede
2020-01-15  4:29     ` [linux-sunxi] " Samuel Holland

Linux Input Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-input/0 linux-input/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-input linux-input/ https://lore.kernel.org/linux-input \
		linux-input@vger.kernel.org
	public-inbox-index linux-input

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-input


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git