linux-input.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/2] Implement notifier chain for lid switch events
@ 2025-10-30 14:10 Jonathan Denose
  2025-10-30 14:10 ` [PATCH 1/2] Input: Create input notifier chain in input.c Jonathan Denose
  2025-10-30 14:10 ` [PATCH 2/2] HID: multitouch: Toggle touch surface on Elan touchpad on lid event Jonathan Denose
  0 siblings, 2 replies; 6+ messages in thread
From: Jonathan Denose @ 2025-10-30 14:10 UTC (permalink / raw)
  To: Dmitry Torokhov, Jiri Kosina, Benjamin Tissoires
  Cc: linux-input, linux-kernel, Jonathan Denose

To circumvent a hardware issue where the touchpad is not physically
connected to the lid angle sensor, implement a notifier chain which
broadcasts lid switch events and a notifier_block which can be enabled
via a quirk to listen for those events turning the touchpad surface
on or off based on if the lid is open or closed. This will prevent
issues resulting from interference between the laptop lid and the
touchpad.

Signed-off-by: Jonathan Denose <jdenose@google.com>
---
Jonathan Denose (2):
      Input: Create input notifier chain in input.c
      HID: multitouch: Toggle touch surface on Elan touchpad on lid event

 drivers/hid/hid-multitouch.c | 32 +++++++++++++++++++++++++++++++-
 drivers/input/input.c        | 13 +++++++++++++
 include/linux/input.h        |  7 +++++++
 3 files changed, 51 insertions(+), 1 deletion(-)
---
base-commit: 3a8660878839faadb4f1a6dd72c3179c1df56787
change-id: 20251014-lid-switch-notifier-1cb9918d675d

Best regards,
-- 
Jonathan Denose <jdenose@google.com>


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

* [PATCH 1/2] Input: Create input notifier chain in input.c
  2025-10-30 14:10 [PATCH 0/2] Implement notifier chain for lid switch events Jonathan Denose
@ 2025-10-30 14:10 ` Jonathan Denose
  2025-11-05 21:55   ` Dmitry Torokhov
  2025-10-30 14:10 ` [PATCH 2/2] HID: multitouch: Toggle touch surface on Elan touchpad on lid event Jonathan Denose
  1 sibling, 1 reply; 6+ messages in thread
From: Jonathan Denose @ 2025-10-30 14:10 UTC (permalink / raw)
  To: Dmitry Torokhov, Jiri Kosina, Benjamin Tissoires
  Cc: linux-input, linux-kernel, Jonathan Denose

To expose input events to other kernel modules, add a blocking notifier
chain. Publish LID_SWITCH_OPEN/LID_SWITCH_CLOSE events through this
notifier chain when input_handle_event detects events signaling the lid
switch has opened or closed.

Additionally, export a function which allows other kernel modules to
register notifier_block structs against this notifier chain.

Signed-off-by: Jonathan Denose <jdenose@google.com>
---
 drivers/input/input.c | 13 +++++++++++++
 include/linux/input.h |  7 +++++++
 2 files changed, 20 insertions(+)

diff --git a/drivers/input/input.c b/drivers/input/input.c
index a500e1e276c211d1146dbfea421a3402084007f8..b342b1ff138ccc58d4623edcf1152bd85d7054bf 100644
--- a/drivers/input/input.c
+++ b/drivers/input/input.c
@@ -26,6 +26,7 @@
 #include <linux/kstrtox.h>
 #include <linux/mutex.h>
 #include <linux/rcupdate.h>
+#include <linux/notifier.h>
 #include "input-compat.h"
 #include "input-core-private.h"
 #include "input-poller.h"
@@ -62,6 +63,8 @@ static const unsigned int input_max_code[EV_CNT] = {
 	[EV_FF] = FF_MAX,
 };
 
+static struct blocking_notifier_head input_notifier_head;
+
 static inline int is_event_supported(unsigned int code,
 				     unsigned long *bm, unsigned int max)
 {
@@ -367,10 +370,20 @@ void input_handle_event(struct input_dev *dev,
 		if (type != EV_SYN)
 			add_input_randomness(type, code, value);
 
+		if (type == EV_SW && code == SW_LID && !value)
+			blocking_notifier_call_chain(&input_notifier_head, value ?
+				LID_SWITCH_CLOSE : LID_SWITCH_OPEN, dev);
+
 		input_event_dispose(dev, disposition, type, code, value);
 	}
 }
 
+int register_input_notifier(struct notifier_block *notifier)
+{
+	return blocking_notifier_chain_register(&input_notifier_head, notifier);
+}
+EXPORT_SYMBOL(register_input_notifier);
+
 /**
  * input_event() - report new input event
  * @dev: device that generated the event
diff --git a/include/linux/input.h b/include/linux/input.h
index 7d7cb0593a63e93c4906c49cde430188db2d1ab5..e940aff8843a0afc693c60a252d6b0dbcb3476c4 100644
--- a/include/linux/input.h
+++ b/include/linux/input.h
@@ -42,6 +42,11 @@ enum input_clock_type {
 	INPUT_CLK_MAX
 };
 
+enum input_notify_event_type {
+	LID_SWITCH_OPEN,
+	LID_SWITCH_CLOSE
+};
+
 /**
  * struct input_dev - represents an input device
  * @name: name of the device
@@ -431,6 +436,8 @@ int input_flush_device(struct input_handle *handle, struct file *file);
 void input_set_timestamp(struct input_dev *dev, ktime_t timestamp);
 ktime_t *input_get_timestamp(struct input_dev *dev);
 
+int register_input_notifier(struct notifier_block *notifier);
+
 void input_event(struct input_dev *dev, unsigned int type, unsigned int code, int value);
 void input_inject_event(struct input_handle *handle, unsigned int type, unsigned int code, int value);
 

-- 
2.51.1.851.g4ebd6896fd-goog


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

* [PATCH 2/2] HID: multitouch: Toggle touch surface on Elan touchpad on lid event
  2025-10-30 14:10 [PATCH 0/2] Implement notifier chain for lid switch events Jonathan Denose
  2025-10-30 14:10 ` [PATCH 1/2] Input: Create input notifier chain in input.c Jonathan Denose
@ 2025-10-30 14:10 ` Jonathan Denose
  1 sibling, 0 replies; 6+ messages in thread
From: Jonathan Denose @ 2025-10-30 14:10 UTC (permalink / raw)
  To: Dmitry Torokhov, Jiri Kosina, Benjamin Tissoires
  Cc: linux-input, linux-kernel, Jonathan Denose

Many touchpad modules have a pin which is expected to be connected to the
lid angle sensor in laptops. The pin sends a signal to the touchpad module
about the lid state and each touchpad vendor handles this notification in
their firmware.

The Elan touchpad with VID 323b does not always have this aforementioned
pin, which then causes interference between the lid and the touchpad when
the lid is closed. This interference causes a few seconds delay before the
touchpad works again, or it causes it to be come completely unresponsive.
To circumvent this hardware issue in software, implement a device quirk
which will allow the hid-multitouch driver to register a notifier_block
to listen for lid switch events and turn the touchpad surface on and off
triggering a recalibration of the touchpad. This recalibration resolves
interference issues when the lid is closed.

Signed-off-by: Jonathan Denose <jdenose@google.com>
---
 drivers/hid/hid-multitouch.c | 32 +++++++++++++++++++++++++++++++-
 1 file changed, 31 insertions(+), 1 deletion(-)

diff --git a/drivers/hid/hid-multitouch.c b/drivers/hid/hid-multitouch.c
index 2879e65cf303b1456311ac06115adda5a78a2600..feb0a0b65b6355cc412fcf8ea88132dc5bdc6a26 100644
--- a/drivers/hid/hid-multitouch.c
+++ b/drivers/hid/hid-multitouch.c
@@ -35,6 +35,7 @@
 #include <linux/device.h>
 #include <linux/hid.h>
 #include <linux/module.h>
+#include <linux/notifier.h>
 #include <linux/slab.h>
 #include <linux/input/mt.h>
 #include <linux/jiffies.h>
@@ -76,6 +77,7 @@ MODULE_LICENSE("GPL");
 #define MT_QUIRK_DISABLE_WAKEUP		BIT(21)
 #define MT_QUIRK_ORIENTATION_INVERT	BIT(22)
 #define MT_QUIRK_APPLE_TOUCHBAR		BIT(23)
+#define MT_QUIRK_REGISTER_INPUT_NOTIFIER BIT(24)
 
 #define MT_INPUTMODE_TOUCHSCREEN	0x02
 #define MT_INPUTMODE_TOUCHPAD		0x03
@@ -183,6 +185,8 @@ struct mt_device {
 	struct list_head reports;
 };
 
+static struct hid_device *lid_notify_hdev;
+
 static void mt_post_parse_default_settings(struct mt_device *td,
 					   struct mt_application *app);
 static void mt_post_parse(struct mt_device *td, struct mt_application *app);
@@ -227,6 +231,7 @@ static void mt_post_parse(struct mt_device *td, struct mt_application *app);
 #define MT_CLS_SMART_TECH			0x0113
 #define MT_CLS_APPLE_TOUCHBAR			0x0114
 #define MT_CLS_SIS				0x0457
+#define MT_CLS_REGISTER_INPUT_NOTIFIER 0x0115
 
 #define MT_DEFAULT_MAXCONTACT	10
 #define MT_MAX_MAXCONTACT	250
@@ -327,7 +332,9 @@ static const struct mt_class mt_classes[] = {
 			MT_QUIRK_CONTACT_CNT_ACCURATE |
 			MT_QUIRK_WIN8_PTP_BUTTONS,
 		.export_all_inputs = true },
-
+	{ .name = MT_CLS_REGISTER_INPUT_NOTIFIER,
+		.quirks = MT_QUIRK_REGISTER_INPUT_NOTIFIER,
+		.export_all_inputs = true },
 	/*
 	 * vendor specific classes
 	 */
@@ -1840,6 +1847,20 @@ static void mt_expired_timeout(struct timer_list *t)
 	clear_bit_unlock(MT_IO_FLAGS_RUNNING, &td->mt_io_flags);
 }
 
+static int mt_input_notifier(struct notifier_block *nb, unsigned long action, void *dev)
+{
+	if (action == LID_SWITCH_CLOSE)
+		mt_set_modes(lid_notify_hdev, HID_LATENCY_NORMAL, TOUCHPAD_REPORT_NONE);
+	else if (action == LID_SWITCH_OPEN)
+		mt_set_modes(lid_notify_hdev, HID_LATENCY_NORMAL, TOUCHPAD_REPORT_ALL);
+
+	return 0;
+}
+
+static struct notifier_block mt_notifier_block = {
+	.notifier_call = mt_input_notifier
+};
+
 static int mt_probe(struct hid_device *hdev, const struct hid_device_id *id)
 {
 	int ret, i;
@@ -1920,6 +1941,11 @@ static int mt_probe(struct hid_device *hdev, const struct hid_device_id *id)
 	if (hdev->vendor == USB_VENDOR_ID_SIS_TOUCH)
 		hdev->quirks |= HID_QUIRK_NOGET;
 
+	if (mtclass->quirks & MT_CLS_REGISTER_INPUT_NOTIFIER) {
+		lid_notify_hdev = hdev;
+		register_input_notifier(&mt_notifier_block);
+	}
+
 	ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT);
 	if (ret)
 		return ret;
@@ -2150,6 +2176,10 @@ static const struct hid_device_id mt_devices[] = {
 		HID_DEVICE(BUS_I2C, HID_GROUP_MULTITOUCH_WIN_8,
 			USB_VENDOR_ID_ELAN, 0x32ae) },
 
+	{ .driver_data = MT_CLS_REGISTER_INPUT_NOTIFIER,
+		HID_DEVICE(BUS_I2C, HID_GROUP_MULTITOUCH_WIN_8,
+			USB_VENDOR_ID_ELAN, 0x323b) },
+
 	/* Elitegroup panel */
 	{ .driver_data = MT_CLS_SERIAL,
 		MT_USB_DEVICE(USB_VENDOR_ID_ELITEGROUP,

-- 
2.51.1.851.g4ebd6896fd-goog


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

* Re: [PATCH 1/2] Input: Create input notifier chain in input.c
  2025-10-30 14:10 ` [PATCH 1/2] Input: Create input notifier chain in input.c Jonathan Denose
@ 2025-11-05 21:55   ` Dmitry Torokhov
  2025-11-05 22:40     ` Jonathan Denose
  0 siblings, 1 reply; 6+ messages in thread
From: Dmitry Torokhov @ 2025-11-05 21:55 UTC (permalink / raw)
  To: Jonathan Denose
  Cc: Jiri Kosina, Benjamin Tissoires, linux-input, linux-kernel

Hi Jonathan,

On Thu, Oct 30, 2025 at 02:10:40PM +0000, Jonathan Denose wrote:
> To expose input events to other kernel modules, add a blocking notifier
> chain. Publish LID_SWITCH_OPEN/LID_SWITCH_CLOSE events through this
> notifier chain when input_handle_event detects events signaling the lid
> switch has opened or closed.
> 
> Additionally, export a function which allows other kernel modules to
> register notifier_block structs against this notifier chain.
> 
> Signed-off-by: Jonathan Denose <jdenose@google.com>
> ---
>  drivers/input/input.c | 13 +++++++++++++
>  include/linux/input.h |  7 +++++++
>  2 files changed, 20 insertions(+)
> 
> diff --git a/drivers/input/input.c b/drivers/input/input.c
> index a500e1e276c211d1146dbfea421a3402084007f8..b342b1ff138ccc58d4623edcf1152bd85d7054bf 100644
> --- a/drivers/input/input.c
> +++ b/drivers/input/input.c
> @@ -26,6 +26,7 @@
>  #include <linux/kstrtox.h>
>  #include <linux/mutex.h>
>  #include <linux/rcupdate.h>
> +#include <linux/notifier.h>
>  #include "input-compat.h"
>  #include "input-core-private.h"
>  #include "input-poller.h"
> @@ -62,6 +63,8 @@ static const unsigned int input_max_code[EV_CNT] = {
>  	[EV_FF] = FF_MAX,
>  };
>  
> +static struct blocking_notifier_head input_notifier_head;
> +
>  static inline int is_event_supported(unsigned int code,
>  				     unsigned long *bm, unsigned int max)
>  {
> @@ -367,10 +370,20 @@ void input_handle_event(struct input_dev *dev,
>  		if (type != EV_SYN)
>  			add_input_randomness(type, code, value);
>  
> +		if (type == EV_SW && code == SW_LID && !value)
> +			blocking_notifier_call_chain(&input_notifier_head, value ?
> +				LID_SWITCH_CLOSE : LID_SWITCH_OPEN, dev);

I would prefer not having this directly in the input core but rather
have a lid handler that can then use notifier chain to forward the
events further.

Also, here you are running in atomic context, so you need atomic
notifier, not blocking (or you need to involve a workqueue). 

Thanks.

-- 
Dmitry

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

* Re: [PATCH 1/2] Input: Create input notifier chain in input.c
  2025-11-05 21:55   ` Dmitry Torokhov
@ 2025-11-05 22:40     ` Jonathan Denose
  2025-11-05 22:59       ` Dmitry Torokhov
  0 siblings, 1 reply; 6+ messages in thread
From: Jonathan Denose @ 2025-11-05 22:40 UTC (permalink / raw)
  To: Dmitry Torokhov
  Cc: Jiri Kosina, Benjamin Tissoires, linux-input, linux-kernel

Hi Dmitry,

Thanks for your feedback.

On Wed, Nov 5, 2025 at 3:55 PM Dmitry Torokhov
<dmitry.torokhov@gmail.com> wrote:
>
> Hi Jonathan,
>
> On Thu, Oct 30, 2025 at 02:10:40PM +0000, Jonathan Denose wrote:
> > To expose input events to other kernel modules, add a blocking notifier
> > chain. Publish LID_SWITCH_OPEN/LID_SWITCH_CLOSE events through this
> > notifier chain when input_handle_event detects events signaling the lid
> > switch has opened or closed.
> >
> > Additionally, export a function which allows other kernel modules to
> > register notifier_block structs against this notifier chain.
> >
> > Signed-off-by: Jonathan Denose <jdenose@google.com>
> > ---
> >  drivers/input/input.c | 13 +++++++++++++
> >  include/linux/input.h |  7 +++++++
> >  2 files changed, 20 insertions(+)
> >
> > diff --git a/drivers/input/input.c b/drivers/input/input.c
> > index a500e1e276c211d1146dbfea421a3402084007f8..b342b1ff138ccc58d4623edcf1152bd85d7054bf 100644
> > --- a/drivers/input/input.c
> > +++ b/drivers/input/input.c
> > @@ -26,6 +26,7 @@
> >  #include <linux/kstrtox.h>
> >  #include <linux/mutex.h>
> >  #include <linux/rcupdate.h>
> > +#include <linux/notifier.h>
> >  #include "input-compat.h"
> >  #include "input-core-private.h"
> >  #include "input-poller.h"
> > @@ -62,6 +63,8 @@ static const unsigned int input_max_code[EV_CNT] = {
> >       [EV_FF] = FF_MAX,
> >  };
> >
> > +static struct blocking_notifier_head input_notifier_head;
> > +
> >  static inline int is_event_supported(unsigned int code,
> >                                    unsigned long *bm, unsigned int max)
> >  {
> > @@ -367,10 +370,20 @@ void input_handle_event(struct input_dev *dev,
> >               if (type != EV_SYN)
> >                       add_input_randomness(type, code, value);
> >
> > +             if (type == EV_SW && code == SW_LID && !value)
> > +                     blocking_notifier_call_chain(&input_notifier_head, value ?
> > +                             LID_SWITCH_CLOSE : LID_SWITCH_OPEN, dev);
>
> I would prefer not having this directly in the input core but rather
> have a lid handler that can then use notifier chain to forward the
> events further.

Ok, that makes sense to me. In that case, do you have a recommendation
for where the lid handler should go?

It looks like drivers/acpi/button.c initializes and handles the lid switch, so
would it make sense for it to go there?

> Also, here you are running in atomic context, so you need atomic
> notifier, not blocking (or you need to involve a workqueue).

I'll use an atomic notifier in the next version.

> Thanks.
>
> --
> Dmitry
-- 
Jonathan

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

* Re: [PATCH 1/2] Input: Create input notifier chain in input.c
  2025-11-05 22:40     ` Jonathan Denose
@ 2025-11-05 22:59       ` Dmitry Torokhov
  0 siblings, 0 replies; 6+ messages in thread
From: Dmitry Torokhov @ 2025-11-05 22:59 UTC (permalink / raw)
  To: Jonathan Denose
  Cc: Jiri Kosina, Benjamin Tissoires, linux-input, linux-kernel

On Wed, Nov 05, 2025 at 04:40:29PM -0600, Jonathan Denose wrote:
> Hi Dmitry,
> 
> Thanks for your feedback.
> 
> On Wed, Nov 5, 2025 at 3:55 PM Dmitry Torokhov
> <dmitry.torokhov@gmail.com> wrote:
> >
> > Hi Jonathan,
> >
> > On Thu, Oct 30, 2025 at 02:10:40PM +0000, Jonathan Denose wrote:
> > > To expose input events to other kernel modules, add a blocking notifier
> > > chain. Publish LID_SWITCH_OPEN/LID_SWITCH_CLOSE events through this
> > > notifier chain when input_handle_event detects events signaling the lid
> > > switch has opened or closed.
> > >
> > > Additionally, export a function which allows other kernel modules to
> > > register notifier_block structs against this notifier chain.
> > >
> > > Signed-off-by: Jonathan Denose <jdenose@google.com>
> > > ---
> > >  drivers/input/input.c | 13 +++++++++++++
> > >  include/linux/input.h |  7 +++++++
> > >  2 files changed, 20 insertions(+)
> > >
> > > diff --git a/drivers/input/input.c b/drivers/input/input.c
> > > index a500e1e276c211d1146dbfea421a3402084007f8..b342b1ff138ccc58d4623edcf1152bd85d7054bf 100644
> > > --- a/drivers/input/input.c
> > > +++ b/drivers/input/input.c
> > > @@ -26,6 +26,7 @@
> > >  #include <linux/kstrtox.h>
> > >  #include <linux/mutex.h>
> > >  #include <linux/rcupdate.h>
> > > +#include <linux/notifier.h>
> > >  #include "input-compat.h"
> > >  #include "input-core-private.h"
> > >  #include "input-poller.h"
> > > @@ -62,6 +63,8 @@ static const unsigned int input_max_code[EV_CNT] = {
> > >       [EV_FF] = FF_MAX,
> > >  };
> > >
> > > +static struct blocking_notifier_head input_notifier_head;
> > > +
> > >  static inline int is_event_supported(unsigned int code,
> > >                                    unsigned long *bm, unsigned int max)
> > >  {
> > > @@ -367,10 +370,20 @@ void input_handle_event(struct input_dev *dev,
> > >               if (type != EV_SYN)
> > >                       add_input_randomness(type, code, value);
> > >
> > > +             if (type == EV_SW && code == SW_LID && !value)
> > > +                     blocking_notifier_call_chain(&input_notifier_head, value ?
> > > +                             LID_SWITCH_CLOSE : LID_SWITCH_OPEN, dev);
> >
> > I would prefer not having this directly in the input core but rather
> > have a lid handler that can then use notifier chain to forward the
> > events further.
> 
> Ok, that makes sense to me. In that case, do you have a recommendation
> for where the lid handler should go?
> 
> It looks like drivers/acpi/button.c initializes and handles the lid switch, so
> would it make sense for it to go there?

drivers/acpi/button.c is not the only source of SW_LID events (we also
have cros-ec-keyb.c and others), so I'd recommend putting it into
drivers/input, maybe as lid-notifier.c

> 
> > Also, here you are running in atomic context, so you need atomic
> > notifier, not blocking (or you need to involve a workqueue).
> 
> I'll use an atomic notifier in the next version.

Another option would be to schedule work and then use blocking notifier.

Thanks.

-- 
Dmitry

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

end of thread, other threads:[~2025-11-05 22:59 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-10-30 14:10 [PATCH 0/2] Implement notifier chain for lid switch events Jonathan Denose
2025-10-30 14:10 ` [PATCH 1/2] Input: Create input notifier chain in input.c Jonathan Denose
2025-11-05 21:55   ` Dmitry Torokhov
2025-11-05 22:40     ` Jonathan Denose
2025-11-05 22:59       ` Dmitry Torokhov
2025-10-30 14:10 ` [PATCH 2/2] HID: multitouch: Toggle touch surface on Elan touchpad on lid event Jonathan Denose

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).