Commit Graph

37 Commits

Author SHA1 Message Date
Petr Štetiar
d1c2b25212 gpio-button-hotplug: remove duplicate logging text
Removes one of the duplicate `gpio-keys` words found in the logs:

 gpio-keys gpio-keys: gpio-keysdoes not support key code:143

Signed-off-by: Petr Štetiar <ynezz@true.cz>
2020-03-08 15:10:55 +01:00
Tomasz Maciej Nowak
9c6b6abdcd kernel: replace SUBDIRS with M in package recipes
The SUBDIRS variable has been removed in kernel 5.4, and was deprecated
since the beginnig of kernel git history in favour of M or KBUILD_EXTMOD.

Signed-off-by: Tomasz Maciej Nowak <tomek_n@o2.pl>
2020-02-22 16:38:41 +01:00
Chuanhong Guo
11182349e1 gpio-button-hotplug: add volume button handling
This is used by PISEN WMB001N.

Signed-off-by: Chuanhong Guo <gch981213@gmail.com>
2019-08-08 21:00:59 +08:00
David Bauer
27f3f493de gpio-button-hotplug: unify polled and interrupt code
This patch unifies the polled and interrupt-driven gpio_keys code
paths as well implements consistent handling of the debounce
interval set for the GPIO buttons and switches.

Hotplug events will only be fired if

1. The input changes its state and remains stable for the duration
   of the debounce interval (default is 5 ms).

2. In the initial stable (no state-change for duration of the
   debounce interval) state once the driver module gets loaded.

   Switch type inputs will always report their stable state.
   Unpressed buttons will not trigger an event for the initial
   stable state. Whereas pressed buttons will trigger an event.
   This is consistent with upstream's gpio-key driver that uses
   the input subsystem (and dont use autorepeat).

Prior to this patch, this was handled inconsistently for interrupt-based
an polled gpio-keys. Hence this patch unifies the shared logic into the
gpio_keys_handle_button() function and modify both implementations to
handle the initial state properly.

The changes described in 2. ) . can have an impact on the
failsafe trigger. Up until now, the script checked for button
state changes. On the down side, this allowed to trigger the
failsafe by releasing a held button at the right time. On the
plus side, the button's polarity setting didn't matter.

Now, the failsafe will only engage when a button was pressed
at the right moment (same as before), but now it can
theoretically also trigger when the button was pressed the
whole time the kernel booted and well into the fast-blinking
preinit phase. However, the chances that this can happen are
really small. This is because the gpio-button module is usually
up and ready even before the preinit state is entered. So, the
initial pressed button event gets lost and most devices behave
as before.

Bisectors: If this patch causes a device to permanently go into
failsafe or experience weird behavior due to inputs, please
check the following:
 - the GPIO polarity setting for the button
 - the software-debounce value

Run-tested for 'gpio-keys' and 'gpio-keys-polled' on

 - devolo WiFi pro 1200e
 - devolo WiFi pro 1750c
 - devolo WiFi pro 1750x
 - Netgear WNDR4700
 - Meraki MR24
 - RT-AC58U

Signed-off-by: David Bauer <mail@david-bauer.net>
Signed-off-by: Christian Lamparter <chunkeey@gmail.com> [further
cleanups, simplification and unification]
2019-07-14 14:02:20 +02:00
Petr Štetiar
dd6d82112a gpio-button-hotplug: fix 4.19 build breakage on malta/be64
While testing 4.19 build on malta/be64, I've encountered following
error:

 gpio-button-hotplug/gpio-button-hotplug.c:529:18: error: implicit
 declaration of function 'gpio_to_desc'

which is caused by the missing include fixed by this patch.

Signed-off-by: Petr Štetiar <ynezz@true.cz>
2019-06-17 09:42:36 +02:00
Petr Štetiar
6c5bfaac84 gpio-button-hotplug: gpio-keys: fix always missing first event
Commit afc056d7dc ("gpio-button-hotplug: support interrupt
properties") changed the gpio-keys interrupt handling logic in a way,
that it always misses first event, which causes issues with rc.button
scripts, so this patch restores the previous behaviour.

Fixes: afc056d7dc ("gpio-button-hotplug: support interrupt properties")
Reported-by: Kristian Evensen <kristian.evensen@gmail.com>
Tested-by: Kuan-Yi Li <kyli.tw@gmail.com>
Signed-off-by: Petr Štetiar <ynezz@true.cz>
Signed-off-by: Christian Lamparter <chunkeey@gmail.com> [drop state check]
2019-06-09 14:51:47 +02:00
Petr Štetiar
27d234a345 gpio-button-hotplug: fix wrong initial seen value
Currently the generated event contains wrong seen value, when the button
is pressed for the first time:

 rmmod gpio_button_hotplug; modprobe gpio_button_hotplug
 [ pressing the wps key immediately after modprobe ]
 gpio-keys: create event, name=wps, seen=1088, pressed=1

So this patch adds a check for this corner case and makes seen=0 if the
button is pressed for the first time.

Tested-by: Kuan-Yi Li <kyli.tw@gmail.com>
Signed-off-by: Petr Štetiar <ynezz@true.cz>
2019-06-09 14:51:47 +02:00
Petr Štetiar
33ccfe0e14 gpio-button-hotplug: use pr_debug and pr_err
pr_debug can be used with dynamic debugging.

Tested-by: Kuan-Yi Li <kyli.tw@gmail.com>
Signed-off-by: Petr Štetiar <ynezz@true.cz>
2019-06-09 14:51:47 +02:00
Christian Lamparter
afc056d7dc gpio-button-hotplug: support interrupt properties
Upstream Linux's input gpio-keys driver supports
specifying a external interrupt for a gpio via the
'interrupts' properties as well as having support
for software debounce.

This patch ports these features to OpenWrt's event
version. Only the "pure" interrupt-driven support is
left behind, since this goes a bit against the "gpio"
in the "gpio-keys" and I don't have a real device to
test this with.

This patch also silences the generated warnings showing
up since 4.14 due to the 'constification' of the
struct gpio_keys_button *buttons variable in the
upstream struct gpio_keys_platform_data declaration.

gpio-button-hotplug.c: In function 'gpio_keys_get_devtree_pdata':
gpio-button-hotplug.c:392:10: warning: assignment discards 'const'
	qualifier from pointer target type [-Wdiscarded-qualifiers]
   button = &pdata->buttons[i++];
          ^
gpio-button-hotplug.c: In function 'gpio_keys_button_probe':
gpio-button-hotplug.c:537:12: warning: assignment discards 'const'
	qualifier from pointer target type [-Wdiscarded-qualifiers]
   bdata->b = &pdata->buttons[i];
            ^
gpio-button-hotplug.c: In function 'gpio_keys_probe':
gpio-button-hotplug.c:563:37: warning: initialization discards 'const'
	qualifier from pointer target type [-Wdiscarded-qualifiers]
   struct gpio_keys_button *button = &pdata->buttons[i];
                                   ^
Acked-by: Petr Štetiar <ynezz@true.cz>
Signed-off-by: Christian Lamparter <chunkeey@gmail.com>
2019-05-31 10:30:03 +02:00
Alan Swanson
5422fed787 gpio-button-hotplug: add KEY_POWER2 handling
For devices such as BTHOMEHUBV5A with both reset and restart buttons,
its easily accessible restart button has been assigned to KEY_POWER
power script to poweroff preventing accidental (or malicious) factory
resets by KEY_RESTART reset script. However an easily accessible button
immediately powering off the device is also undesirable.

As KEY_RESTART is already used for reset script (and there's no
KEY_REBOOT in Linux input events), use KEY_POWER2 for rebooting via new
reboot script with 5 second seen delay.

Fixes: FS#1965
Signed-off-by: Alan Swanson <reiver@improbability.net>
Signed-off-by: Petr Štetiar <ynezz@true.cz> [long line wrap]
2019-05-30 11:55:50 +02:00
Karl Vogel
76378c6b9f build: use KERNEL_MAKE_FLAGS for kernel file compilations
The build system already defines KERNEL_CROSS which defaults to TARGET_CROSS.
Make use of this variable for kernel makefiles.

Signed-off-by: Karl Vogel <karl.vogel@gmail.com>
2017-10-29 16:17:05 +01:00
Furong Xu
5a22df69e4 gpio-button-hotplug: leave platform_device.dev.platform_data untouched
get platform_data from gpio_keys_button_dev.pdata, and fix a illegal pointer
dereference like this:

[   51.143776] gpio-keys-polled gpio-keys-polled: missing poll_interval value
[   51.150852] gpio-keys-polled: probe of gpio-keys-polled failed with error -22
[  828.159993] gpio-keys-polled gpio-keys-polled: no memory for button data
[  828.166821] gpio-keys-polled: probe of gpio-keys-polled failed with error -12

Signed-off-by: Furong Xu <xfr@outlook.com>
2017-08-21 21:29:52 +02:00
Florian Eckert
4482063c34 treewide: add license tags
Add licence tags where missing.

Signed-off-by: Florian Eckert <fe@dev.tdt.de>
2017-06-24 22:36:38 +02:00
Mathias Kresin
d561b2f5ce gpio-button-hotplug: add more buttons
The keycodes are used by some boards.

Signed-off-by: Mathias Kresin <dev@kresin.me>
2016-11-27 15:34:23 +01:00
Alexandru Ardelean
a1236a30a0 kernel/gpio-button-hotplug: drop Build/Prepare rule in favor of default one
Signed-off-by: Alexandru Ardelean <ardeleanalex@gmail.com>
2016-10-15 11:36:52 +02:00
Felix Fietkau
7eeb254cc4 treewide: replace nbd@openwrt.org with nbd@nbd.name
Signed-off-by: Felix Fietkau <nbd@nbd.name>
2016-06-07 08:58:42 +02:00
John Crispin
4ac3411f09 kernel: gpio-button-hotplug: Add missing ONESHOT flag to threaded IRQ request
Without the IRQF_ONESHOT flag in devm_request_threaded_irq() call I get
following error:

  genirq: Threaded irq requested with handler=NULL and !ONESHOT for irq 56
  gpio-keys gpio-keys: failed to request irq:56 for gpio:20

>From kernel/irq/manage.c:

 The interrupt was requested with handler = NULL, so we use the default
 primary handler for it. But it does not have the oneshot flag set. In
 combination with level interrupts this is deadly, because the default
 primary handler just wakes the thread, then the irq lines is reenabled,
 but the device still has the level irq asserted. Rinse and repeat....

 While this works for edge type interrupts, we play it safe and reject
 unconditionally because we can't say for sure which type this interrupt
 really has. The type flags are unreliable as the underlying chip
 implementation can override them.

Signed-off-by: Petr Štetiar <ynezz@true.cz>

SVN-Revision: 48894
2016-03-03 20:24:47 +00:00
John Crispin
69517e88be kernel: gpio-button-hotplug: update to use threaded irq's
Many gpio controllers 'cansleep' due to the fact that they are behind busses
e.g. i2c etc.

Using threaded irq's allows for 'sleep-able' gpio's to be used.

Signed-off-by: Pushpal Sidhu <psidhu@gateworks.com>
Signed-off-by: Tim Harvey <tharvey@gateworks.com>

SVN-Revision: 48696
2016-02-12 08:29:11 +00:00
Hauke Mehrtens
886764657a gpio-button-hotplug: handle EPROBE_DEFER and other errors
of_get_gpio_flags() could return an error like EPROBE_DEFER which was
not handled before. This patch takes the code from gpio_keys_polled.c
for error handling and also improves some other unrelated small parts.

Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>

SVN-Revision: 46502
2015-07-26 15:52:17 +00:00
Felix Fietkau
3120c9c9c2 build: drop obsolete kernel version dependencies
Signed-off-by: Felix Fietkau <nbd@openwrt.org>

SVN-Revision: 44110
2015-01-24 20:02:09 +00:00
Felix Fietkau
6ee4d92e34 gpio-button-hotplug: remove #ifdef CONFIG_HOTPLUG, it is gone in newer kernels (fixes #16413)
Signed-off-by: Felix Fietkau <nbd@openwrt.org>

SVN-Revision: 40838
2014-05-23 22:13:10 +00:00
Hauke Mehrtens
a5ced8b408 gpio-button-hotplug: fix (and extend) package description
Signed-off-by: Rafał Miłecki <zajec5@gmail.com>

SVN-Revision: 40765
2014-05-14 10:22:48 +00:00
Florian Fainelli
0d92f34977 gpio-button-hotplug: don't build for 3.3 kernels
3.3 kernels do not have the required changes which would make
gpio-button-hotplug work, disallow building on those kernels for now.

Signed-off-by: Florian Fainelli <florian@openwrt.org>

SVN-Revision: 39903
2014-03-12 22:09:11 +00:00
Hauke Mehrtens
45e3898a11 gpio-button-hotplug: add wwan button
The wimax key will be used as a generic wwan key starting with Linux
3.13. The brcm47xx target uses this key for the 3g buttons. Also remove
the ifdef around KEY_WPS_BUTTON, this is in the kernel for a long time
now.

Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>

SVN-Revision: 39290
2014-01-14 23:11:10 +00:00
Jonas Gorski
5c2aee90ac gpio-button-hotplug: fix crash on remove
Don't call gpio_keys_remove recursively. Setting the platform
data to NULL triggered an oops on the second iteration, so there was
no infinate loop.

Signed-off-by: Jonas Gorski <jogo@openwrt.org>

SVN-Revision: 39124
2013-12-17 19:05:03 +00:00
John Crispin
bc76dec31f gpio-button-hotplug: add irq mode to driver
Signed-off-by: John Crispin <blogic@openwrt.org>

SVN-Revision: 39021
2013-12-09 17:29:39 +00:00
John Crispin
40031fdf9b gpio-button-hotplug: add support for sliding switches
Signed-off-by: John Crispin <blogic@openwrt.org>

SVN-Revision: 38725
2013-11-11 12:19:06 +00:00
John Crispin
14457da13f gpio-button-hotplug: add support for power buttons
Signed-off-by: John Crispin <blogic@openwrt.org>

SVN-Revision: 38557
2013-10-28 13:45:57 +00:00
Felix Fietkau
6743f2625b gpio-button-hotplug: debounce the initial button state, the first reads at boot time might be wrong
Signed-off-by: Felix Fietkau <nbd@openwrt.org>

SVN-Revision: 37702
2013-08-05 10:32:13 +00:00
Felix Fietkau
18e37d8caf gpio-button-hotplug: cleanup, fix compiler warning
Signed-off-by: Felix Fietkau <nbd@openwrt.org>

SVN-Revision: 37665
2013-08-03 11:56:27 +00:00
Felix Fietkau
4281026dda gpio-button-hotplug: fix active_low handling, possibly broken in r37643
Signed-off-by: Felix Fietkau <nbd@openwrt.org>

SVN-Revision: 37664
2013-08-03 11:49:50 +00:00
John Crispin
1eabf431df gpio-button-hotplug: use gpio_button_get_value() to initialize last_state.
TL-WR720N-v3 has a slider switch composed of 2 GPIO buttons which can be
used to swtich between 3 positions.  At leat 1 button is in pressed state
in any of those positions.  Initialize 'last_state' as 0 (released) will
cause the device to automatically enter failsafe mode on every bootup.

Signed-off-by: Yousong Zhou <yszhou4tech@gmail.com>

SVN-Revision: 37643
2013-08-01 14:31:28 +00:00
John Crispin
ef96422920 gpio-button-hotplug: use gpio_button_get_value() to fetch state.
Signed-off-by: Yousong Zhou <yszhou4tech@gmail.com>

SVN-Revision: 37642
2013-08-01 14:31:24 +00:00
John Crispin
2c19af6ac5 gpio-button-hotplug: add inline function gpio_button_get_value().
Signed-off-by: Yousong Zhou <yszhou4tech@gmail.com>

SVN-Revision: 37641
2013-08-01 14:31:20 +00:00
Luka Perkov
6988613f7a gpio-button-hotplug: add support for EV_SW
Signed-off-by: Luka Perkov <luka@openwrt.org>

SVN-Revision: 37130
2013-07-02 10:45:31 +00:00
Felix Fietkau
0f6e9c9fcc gpio-button-hotplug: improve gpio button debouncing, verify state changes over multiple polls. fixes spurious failsafe triggers (#13784)
Signed-off-by: Felix Fietkau <nbd@openwrt.org>

SVN-Revision: 37090
2013-06-29 19:01:49 +00:00
John Crispin
4ebf19b48f packages: clean up the package folder
Signed-off-by: John Crispin <blogic@openwrt.org>

SVN-Revision: 37007
2013-06-21 16:54:37 +00:00