Bug 82347 - RFE: honour gpio input device shutdown keypresses
Summary: RFE: honour gpio input device shutdown keypresses
Status: RESOLVED FIXED
Alias: None
Product: systemd
Classification: Unclassified
Component: general (show other bugs)
Version: unspecified
Hardware: ARM Linux (All)
: medium normal
Assignee: systemd-bugs
QA Contact: systemd-bugs
URL: https://bugs.launchpad.net/ubuntu/+so...
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-08-08 13:01 UTC by dann frazier
Modified: 2016-02-01 18:03 UTC (History)
0 users

See Also:
i915 platform:
i915 features:


Attachments

Description dann frazier 2014-08-08 13:01:28 UTC
There are a couple of ARM-based server systems that use the gpio-keyboard and gpio-keyboard-polled drivers to send an event requesting a shutdown. The following rules DTRT, though obviously it'd be nice if a more generic (but still safe) rule could be devised.

SUBSYSTEM=="input", KERNEL=="event*", SUBSYSTEMS=="platform", KERNELS=="gpio-keys.6", PROGRAM="/bin/grep '^HP ProLiant m400 Server Cartridge$' /proc/device-tree/model", TAG+="power-switch"


SUBSYSTEM=="input", KERNEL=="event*", SUBSYSTEMS=="platform", KERNELS=="gpio_keys.12", ATTRS{keys}=="116", PROGRAM="/bin/cat /proc/device-tree/model", RESULT=="HP ProLiant m800 Server Cartridge", TAG+="power-switch"

You'll notice a couple of differences between the two. The m800 rule specifies a key attribute where the m400 rule does not. This is because the first uses a polled gpio via the gpio-keyboard-polled driver. This driver does not expose a "keys" attribute in sysfs. The m400 uses the gpio-keyboard driver, which does.

You'll also notice the grep vs. cat/RESULT methods. Not sure if upstream has a preference.

It might make sense to drop the model/pin matching of the m800 rule, and bind to any ATTR{keys}=="116" - this is defined as KEY_POWER in <linux/input.h>. Of course, that won't help the -polled variant.
Comment 1 dann frazier 2014-08-11 18:28:21 UTC
Note that, due to a firmware change, the m400 rule should use "gpio_keys" instead of "gpio-keys". Here is the new rule:

SUBSYSTEM=="input", KERNEL=="event*", SUBSYSTEMS=="platform", KERNELS=="gpio_keys.6", PROGRAM="/bin/grep '^HP ProLiant m400 Server Cartridge$' /proc/device-tree/model", TAG+="power-switch"
Comment 2 Kay Sievers 2014-08-11 19:58:01 UTC
(In reply to comment #1)
> Note that, due to a firmware change, the m400 rule should use "gpio_keys"
> instead of "gpio-keys". Here is the new rule:
> 
> SUBSYSTEM=="input", KERNEL=="event*", SUBSYSTEMS=="platform",
> KERNELS=="gpio_keys.6", PROGRAM="/bin/grep '^HP ProLiant m400 Server
> Cartridge$' /proc/device-tree/model", TAG+="power-switch"

That's a neat hack, but in no way upstreamable.

Upstream udev dev will not read the device information from /proc, and will
also not call any external tools like grep.

This all needs to be solved properly on the kernel side, to export real devices
and allow efficient and reliable matching from userspace tools.
Comment 3 dann frazier 2014-08-13 02:20:50 UTC
Right, that wasn't intended to be an upstream patch submittal, just a description of the problem.

My best guess at a "good" solution would be something like this:

SUBSYSTEM=="input", KERNEL=="event*", SUBSYSTEMS=="platform", ATTRS{keys}=="116", TAG+="power-switch"

Which would obviously require some new support in gpio-keyboard-polled to expose the ATTRS{keys}. But I don't know if it is safe to assume that KEY_POWER is always a graceful powerdown request.
Comment 4 Lennart Poettering 2014-08-13 12:24:38 UTC
I think the proper way to fix this is by waiting for this kernel patch to be applied:

http://www.spinics.net/lists/linux-input/msg33007.html

With that in place we can then update logind to make use of it, and then simply add the udev tag to all keyboards that are discovered, which would then implicitly include any gpio kbd devices.

Without that kernel patch I am a bit concerned about listening to all of the system's keypresses, as that might be a bit too much.
Comment 5 Lennart Poettering 2016-02-01 18:03:34 UTC
This has been implemented a while back, see 405e116f57b1cf33d4ca0294ab045a9f709bbc96


Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.