Skip to content

Commit 57a0636

Browse files
committed
Input: introduce notion of passive observers for input handlers
Sometimes it is useful to observe (and maybe modify) data coming from an input device, but only do that if there are other users of such input device. An example is touchpad switching functionality on Lenovo IdeaPad Z570 where it is desirable to suppress events coming from the touchpad if user toggles touchpad on/off button (on this laptop the firmware does not stop the device). Introduce notion of passive observers for input handlers to solve this issue. An input handler marked as passive observer behaves exactly like any other input handler or filter, but with one exception: it does not open/start underlying input device when attaching to it. Link: https://lore.kernel.org/r/ZxlEROX7bMo5cbZP@google.com Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
1 parent 6b6b40f commit 57a0636

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

drivers/input/input.c

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -605,6 +605,9 @@ int input_open_device(struct input_handle *handle)
605605

606606
handle->open++;
607607

608+
if (handle->handler->passive_observer)
609+
goto out;
610+
608611
if (dev->users++ || dev->inhibited) {
609612
/*
610613
* Device is already opened and/or inhibited,
@@ -668,11 +671,13 @@ void input_close_device(struct input_handle *handle)
668671

669672
__input_release_device(handle);
670673

671-
if (!--dev->users && !dev->inhibited) {
672-
if (dev->poller)
673-
input_dev_poller_stop(dev->poller);
674-
if (dev->close)
675-
dev->close(dev);
674+
if (!handle->handler->passive_observer) {
675+
if (!--dev->users && !dev->inhibited) {
676+
if (dev->poller)
677+
input_dev_poller_stop(dev->poller);
678+
if (dev->close)
679+
dev->close(dev);
680+
}
676681
}
677682

678683
if (!--handle->open) {

include/linux/input.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,10 @@ struct input_handle;
286286
* @start: starts handler for given handle. This function is called by
287287
* input core right after connect() method and also when a process
288288
* that "grabbed" a device releases it
289+
* @passive_observer: set to %true by drivers only interested in observing
290+
* data stream from devices if there are other users present. Such
291+
* drivers will not result in starting underlying hardware device
292+
* when input_open_device() is called for their handles
289293
* @legacy_minors: set to %true by drivers using legacy minor ranges
290294
* @minor: beginning of range of 32 legacy minors for devices this driver
291295
* can provide
@@ -321,6 +325,7 @@ struct input_handler {
321325
void (*disconnect)(struct input_handle *handle);
322326
void (*start)(struct input_handle *handle);
323327

328+
bool passive_observer;
324329
bool legacy_minors;
325330
int minor;
326331
const char *name;

0 commit comments

Comments
 (0)