Skip to contentSkip to conversation

Input: gpio-keys - expose wakeup keys in sysfs

PATCH In review Guido Günther 3 participants 5 messages May 9, 2024 – Jul 21, 2024 1 message not in the archive

Subsystems (2)
lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw

PATCH 1/1 Input: gpio-keys - expose wakeup keys in sysfs

This helps user space to figure out which keys should be used to unidle a device. E.g on phones the volume rocker should usually not unblank the screen.

---
 drivers/input/keyboard/gpio_keys.c | 23 ++++++++++++++++-------
 1 file changed, 16 insertions(+), 7 deletions(-)
drivers/input/keyboard/gpio_keys.c +16 -7
index 9f3bcd41cf67..84f43d1d4375 100644
@@ -198,7 +198,8 @@ static void gpio_keys_enable_button(struct gpio_button_data *bdata)
  */
 static ssize_t gpio_keys_attr_show_helper(struct gpio_keys_drvdata *ddata,
 					  char *buf, unsigned int type,
-					  bool only_disabled)
+					  bool only_disabled,
+					  bool only_wakeup)
 {
 	int n_events = get_n_events_by_type(type);
 	unsigned long *bits;
@@ -218,6 +219,9 @@ static ssize_t gpio_keys_attr_show_helper(struct gpio_keys_drvdata *ddata,
 		if (only_disabled && !bdata->disabled)
 			continue;
 
+		if (only_wakeup && !bdata->button->wakeup)
+			continue;
+
 		__set_bit(*bdata->code, bits);
 	}
 
@@ -297,7 +301,7 @@ static ssize_t gpio_keys_attr_store_helper(struct gpio_keys_drvdata *ddata,
 	return error;
 }
 
-#define ATTR_SHOW_FN(name, type, only_disabled)				\
+#define ATTR_SHOW_FN(name, type, only_disabled, only_wakeup)		\
 static ssize_t gpio_keys_show_##name(struct device *dev,		\
 				     struct device_attribute *attr,	\
 				     char *buf)				\
@@ -306,22 +310,26 @@ static ssize_t gpio_keys_show_##name(struct device *dev,		\
 	struct gpio_keys_drvdata *ddata = platform_get_drvdata(pdev);	\
 									\
 	return gpio_keys_attr_show_helper(ddata, buf,			\
-					  type, only_disabled);		\
+					  type, only_disabled,		\
+					  only_wakeup);			\
 }
 
-ATTR_SHOW_FN(keys, EV_KEY, false);
-ATTR_SHOW_FN(switches, EV_SW, false);
-ATTR_SHOW_FN(disabled_keys, EV_KEY, true);
-ATTR_SHOW_FN(disabled_switches, EV_SW, true);
+ATTR_SHOW_FN(keys, EV_KEY, false, false);
+ATTR_SHOW_FN(switches, EV_SW, false, false);
+ATTR_SHOW_FN(disabled_keys, EV_KEY, true, false);
+ATTR_SHOW_FN(disabled_switches, EV_SW, true, false);
+ATTR_SHOW_FN(wakeup_keys, EV_KEY, false, true);
 
 /*
  * ATTRIBUTES:
  *
  * /sys/devices/platform/gpio-keys/keys [ro]
  * /sys/devices/platform/gpio-keys/switches [ro]
+ * /sys/devices/platform/gpio-keys/wakeup_keys [ro]
  */
 static DEVICE_ATTR(keys, S_IRUGO, gpio_keys_show_keys, NULL);
 static DEVICE_ATTR(switches, S_IRUGO, gpio_keys_show_switches, NULL);
+static DEVICE_ATTR(wakeup_keys, S_IRUGO, gpio_keys_show_wakeup_keys, NULL);
 
 #define ATTR_STORE_FN(name, type)					\
 static ssize_t gpio_keys_store_##name(struct device *dev,		\
@@ -361,6 +369,7 @@ static struct attribute *gpio_keys_attrs[] = {
 	&dev_attr_switches.attr,
 	&dev_attr_disabled_keys.attr,
 	&dev_attr_disabled_switches.attr,
+	&dev_attr_wakeup_keys.attr,
 	NULL,
 };
 ATTRIBUTE_GROUPS(gpio_keys);
Signature · 1 line
2.43.0
Reviewed-by Tested-by on v1 1/1
#2 lore raw

Hi Guido,

Quoted 5 lines · Guido Günther

This helps user space to figure out which keys should be used to unidle a device. E.g on phones the volume rocker should usually not unblank the screen.

Thanks for your patch!
This is indeed a useful feature.

Gr{oetje,eeting}s,

Geert

Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds
maintainer
#3 lore raw
In reply to Guido Günther

Hi Guido,

Quoted 3 lines · Guido Günther

This helps user space to figure out which keys should be used to unidle a device. E.g on phones the volume rocker should usually not unblank the screen.

How exactly this is supposed to be used? We have "disabled" keys and switches attribute because this function can be controlled at runtime from userspace while wakeup control is a static device setting.

Kernel also does not really know if the screen should be unblanked or not, if a button or switch is configured for wake up the kernel will go through wakeup process all the same and then userspace can decide if it should stay woken up or not.

Thanks.

Signature · 1 line
Dmitry
#4 lore raw

Hi,

Quoted 10 lines · Dmitry Torokhov

Hi Guido,

Quoted 3 lines · Guido Günther

This helps user space to figure out which keys should be used to unidle a device. E.g on phones the volume rocker should usually not unblank the screen.

How exactly this is supposed to be used? We have "disabled" keys and switches attribute because this function can be controlled at runtime from userspace while wakeup control is a static device setting.

Current Linux userspace usually unblanks/unidles a device on every keypress. That is usually not the expected result on phones where often only the power button and e.g. some home buttons should do this.

These keys usually match the keys that are used as wakeup sources to bring a device out of suspend. So if we export the wakeup keys to userspace we can pick some sensible defaults (overridable via hwdb¹).

Quoted 4 lines

Kernel also does not really know if the screen should be unblanked or not, if a button or switch is configured for wake up the kernel will go through wakeup process all the same and then userspace can decide if it should stay woken up or not.

Yes, we merely want that as a hint to figure out sensible defaults in userspace (which might be a subset of the wakeup keys).

Cherrs,
-- Guido

¹) See https://gitlab.gnome.org/World/Phosh/gmobile/-/blob/main/data/61-gmobile-wakeup.hwdb?ref_type=heads#L57-L59

Quoted 6 lines

Thanks.

Signature · 1 line
Dmitry
#5 lore raw

Hi,

Quoted 21 lines · Guido Günther

Hi,

Quoted 10 lines · Dmitry Torokhov

Hi Guido,

Quoted 3 lines · Guido Günther

This helps user space to figure out which keys should be used to unidle a device. E.g on phones the volume rocker should usually not unblank the screen.

How exactly this is supposed to be used? We have "disabled" keys and switches attribute because this function can be controlled at runtime from userspace while wakeup control is a static device setting.

Current Linux userspace usually unblanks/unidles a device on every keypress. That is usually not the expected result on phones where often only the power button and e.g. some home buttons should do this.

These keys usually match the keys that are used as wakeup sources to bring a device out of suspend. So if we export the wakeup keys to userspace we can pick some sensible defaults (overridable via hwdb¹).

Quoted 7 lines
Quoted 4 lines

Kernel also does not really know if the screen should be unblanked or not, if a button or switch is configured for wake up the kernel will go through wakeup process all the same and then userspace can decide if it should stay woken up or not.

Yes, we merely want that as a hint to figure out sensible defaults in userspace (which might be a subset of the wakeup keys).

Is there anything I can do to get this applied (currently we play catchup per device when the wakup keys change) ?

Cheers,
-- Guido

Quoted 12 lines

Cherrs,
-- Guido

¹) See https://gitlab.gnome.org/World/Phosh/gmobile/-/blob/main/data/61-gmobile-wakeup.hwdb?ref_type=heads#L57-L59

Quoted 6 lines

Thanks.

Signature · 1 line
Dmitry