Skip to contentSkip to conversation

Input: add event codes for lap and palmreset proximity switches

PATCH In review Mark Pearson 2 participants 4 messages Oct 26, 2020

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH v3 1/3 Input: add event codes for lap and palmreset proximity switches

Add infrastructure needed to support lap and palmrest proximity sensors.

These sensors are used for identifying thermal mode changes and modifying WWAN transmitter power.

---
Changes in v2:
- Update Input message
Changes in v3:
- Added missing patch history notes

 include/linux/mod_devicetable.h        | 2 +-
 include/uapi/linux/input-event-codes.h | 4 +++-
 2 files changed, 4 insertions(+), 2 deletions(-)
include/linux/mod_devicetable.h +1 -1
index 5b08a473cdba..897f5a3e7721 100644
@@ -320,7 +320,7 @@ struct pcmcia_device_id {
 #define INPUT_DEVICE_ID_LED_MAX		0x0f
 #define INPUT_DEVICE_ID_SND_MAX		0x07
 #define INPUT_DEVICE_ID_FF_MAX		0x7f
-#define INPUT_DEVICE_ID_SW_MAX		0x10
+#define INPUT_DEVICE_ID_SW_MAX		0x12
 #define INPUT_DEVICE_ID_PROP_MAX	0x1f
 
 #define INPUT_DEVICE_ID_MATCH_BUS	1
include/uapi/linux/input-event-codes.h +3 -1
index 0c2e27d28e0a..26f71a9a6936 100644
@@ -889,7 +889,9 @@
 #define SW_MUTE_DEVICE		0x0e  /* set = device disabled */
 #define SW_PEN_INSERTED		0x0f  /* set = pen inserted */
 #define SW_MACHINE_COVER	0x10  /* set = cover closed */
-#define SW_MAX			0x10
+#define SW_LAP_PROXIMITY        0x11  /* set = lap proximity sensor active */
+#define SW_PALMREST_PROXIMITY   0x12  /* set = palmrest proximity sensor active */
+#define SW_MAX			0x12
 #define SW_CNT			(SW_MAX+1)
 
 /*
Signature · 1 line
2.28.0
#1 lore raw

PATCH v3 2/3 platform/x86: thinkpad_acpi: Add support for palm sensor

Use input device event support for notifying userspace of palm sensor state changes

---
Changes in V2:
- Update commit message to be correct

Changes in V3:
- remove unnecessary global state variable
- clean up error handling code
- set dangling pointer to null

 drivers/platform/x86/thinkpad_acpi.c | 95 +++++++++++++++++++++++++++-
 1 file changed, 93 insertions(+), 2 deletions(-)
drivers/platform/x86/thinkpad_acpi.c +93 -2
index eae3579f106f..3cb07c12a705 100644
@@ -4013,6 +4013,7 @@ static bool hotkey_notify_usrevent(const u32 hkey,
 }
 
 static void thermal_dump_all_sensors(void);
+static void palmsensor_refresh(void);
 
 static bool hotkey_notify_6xxx(const u32 hkey,
 				 bool *send_acpi_ev,
@@ -4079,8 +4080,8 @@ static bool hotkey_notify_6xxx(const u32 hkey,
 
 	case TP_HKEY_EV_PALM_DETECTED:
 	case TP_HKEY_EV_PALM_UNDETECTED:
-		/* palm detected hovering the keyboard, forward to user-space
-		 * via netlink for consumption */
+		/* palm detected  - pass on to event handler */
+		palmsensor_refresh();
 		return true;
 
 	default:
@@ -9918,6 +9919,92 @@ static struct ibm_struct dytc_driver_data = {
 	.exit = dytc_exit,
 };
 
+/*************************************************************************
+ * Proximity sensor subdriver
+ */
+
+#define PALMSENSOR_PRESENT_BIT 0 /* Determine if psensor present */
+#define PALMSENSOR_ON_BIT      1 /* psensor status */
+
+struct input_dev *tpacpi_sw_dev;
+bool has_palmsensor;
+
+static int palmsensor_get(bool *present, bool *state)
+{
+	acpi_handle psensor_handle;
+	int output;
+
+	if (ACPI_FAILURE(acpi_get_handle(hkey_handle, "GPSS", &psensor_handle)))
+		return -ENODEV;
+	if (!acpi_evalf(psensor_handle, &output, NULL, "d"))
+		return -EIO;
+
+	*present = output & BIT(PALMSENSOR_PRESENT_BIT) ? true : false;
+	*state = output & BIT(PALMSENSOR_ON_BIT) ? true : false;
+	return 0;
+}
+
+static void palmsensor_refresh(void)
+{
+	bool state;
+	int err;
+
+	if (has_palmsensor) {
+		err = palmsensor_get(&has_palmsensor, &state);
+		if (err)
+			return;
+		input_report_switch(tpacpi_sw_dev, SW_PALMREST_PROXIMITY, state);
+		input_sync(tpacpi_sw_dev);
+	}
+}
+
+static int tpacpi_proxsensor_init(struct ibm_init_struct *iibm)
+{
+	int palm_err, err;
+	bool palm_state;
+
+	palm_err = palmsensor_get(&has_palmsensor, &palm_state);
+	/* If support isn't available (ENODEV) then quit, but don't return an error */
+	if (palm_err == -ENODEV)
+		return 1;
+
+	/* Otherwise, if there was an error return it */
+	if (palm_err && (palm_err != ENODEV))
+		return palm_err;
+
+	if (has_palmsensor) {
+		tpacpi_sw_dev = input_allocate_device();
+		if (!tpacpi_sw_dev)
+			return -ENOMEM;
+		tpacpi_sw_dev->name = "Thinkpad proximity switches";
+		tpacpi_sw_dev->phys = TPACPI_DRVR_NAME "/input1";
+		tpacpi_sw_dev->id.bustype = BUS_HOST;
+		tpacpi_sw_dev->id.vendor = thinkpad_id.vendor;
+		tpacpi_sw_dev->id.product = TPACPI_HKEY_INPUT_PRODUCT;
+		tpacpi_sw_dev->id.version = TPACPI_HKEY_INPUT_VERSION;
+		tpacpi_sw_dev->dev.parent = &tpacpi_pdev->dev;
+
+		input_set_capability(tpacpi_sw_dev, EV_SW, SW_PALMREST_PROXIMITY);
+		input_report_switch(tpacpi_sw_dev, SW_PALMREST_PROXIMITY, palm_state);
+		err = input_register_device(tpacpi_sw_dev);
+		if (err) {
+			input_free_device(tpacpi_sw_dev);
+			tpacpi_sw_dev = NULL;
+			return 0;
+		}
+	}
+	return 1;
+}
+
+static void proxsensor_exit(void)
+{
+	input_unregister_device(tpacpi_sw_dev);
+}
+
+static struct ibm_struct proxsensor_driver_data = {
+	.name = "proximity-sensor",
+	.exit = proxsensor_exit,
+};
 /****************************************************************************
  ****************************************************************************
  *
@@ -10411,6 +10498,10 @@ static struct ibm_init_struct ibms_init[] __initdata = {
 		.init = tpacpi_dytc_init,
 		.data = &dytc_driver_data,
 	},
+	{
+		.init = tpacpi_proxsensor_init,
+		.data = &proxsensor_driver_data,
+	},
 };
 
 static int __init set_ibm_param(const char *val, const struct kernel_param *kp)
Signature · 1 line
2.28.0
#2 lore raw

PATCH v3 3/3 platform/x86: thinkpad_acpi: Add support for lap sensor

In reply to Mark Pearson

Use input device event support for notifying userspace of lap mode sensor state changes.

---
Changes in V2:
- Update commit message to be correct

Changes in V3:
- Update lap sensor code with same fixes applied to palm sensor code.
- Correct error handling in init so returns an error if one encountered.

 drivers/platform/x86/thinkpad_acpi.c | 61 ++++++++++++++++++++++++----
 1 file changed, 52 insertions(+), 9 deletions(-)
drivers/platform/x86/thinkpad_acpi.c +52 -9
index 3cb07c12a705..fe438a5e1dbe 100644
@@ -9928,6 +9928,22 @@ static struct ibm_struct dytc_driver_data = {
 
 struct input_dev *tpacpi_sw_dev;
 bool has_palmsensor;
+bool has_lapsensor;
+
+static int lapsensor_get(bool *present, bool *state)
+{
+	acpi_handle dytc_handle;
+	int output;
+
+	*present = false;
+	if (ACPI_FAILURE(acpi_get_handle(hkey_handle, "DYTC", &dytc_handle)))
+		return -ENODEV;
+	if (!acpi_evalf(dytc_handle, &output, NULL, "dd", DYTC_CMD_GET))
+		return -EIO;
+	*present = true; /*If we get his far, we have lapmode support*/
+	*state = output & BIT(DYTC_GET_LAPMODE_BIT) ? true : false;
+	return 0;
+}
 
 static int palmsensor_get(bool *present, bool *state)
 {
@@ -9958,21 +9974,40 @@ static void palmsensor_refresh(void)
 	}
 }
 
+static void lapsensor_refresh(void)
+{
+	bool state;
+	int err;
+
+	if (has_lapsensor) {
+		err = lapsensor_get(&has_lapsensor, &state);
+		if (err)
+			return;
+		input_report_switch(tpacpi_sw_dev, SW_LAP_PROXIMITY, state);
+		input_sync(tpacpi_sw_dev);
+	}
+}
+
 static int tpacpi_proxsensor_init(struct ibm_init_struct *iibm)
 {
-	int palm_err, err;
-	bool palm_state;
+	int palm_err, lap_err, err;
+	bool palm_state, lap_state;
 
 	palm_err = palmsensor_get(&has_palmsensor, &palm_state);
-	/* If support isn't available (ENODEV) then quit, but don't return an error */
-	if (palm_err == -ENODEV)
+	lap_err = lapsensor_get(&has_lapsensor, &lap_state);
+	/*
+	 * If support isn't available (ENODEV) for both devices then quit, but
+	 * don't return an error.
+	 */
+	if ((palm_err == -ENODEV) && (lap_err == -ENODEV))
 		return 1;
-
 	/* Otherwise, if there was an error return it */
 	if (palm_err && (palm_err != ENODEV))
 		return palm_err;
+	if (lap_err && (lap_err != ENODEV))
+		return lap_err;
 
-	if (has_palmsensor) {
+	if (has_palmsensor || has_lapsensor) {
 		tpacpi_sw_dev = input_allocate_device();
 		if (!tpacpi_sw_dev)
 			return -ENOMEM;
@@ -9984,8 +10019,14 @@ static int tpacpi_proxsensor_init(struct ibm_init_struct *iibm)
 		tpacpi_sw_dev->id.version = TPACPI_HKEY_INPUT_VERSION;
 		tpacpi_sw_dev->dev.parent = &tpacpi_pdev->dev;
 
-		input_set_capability(tpacpi_sw_dev, EV_SW, SW_PALMREST_PROXIMITY);
-		input_report_switch(tpacpi_sw_dev, SW_PALMREST_PROXIMITY, palm_state);
+		if (has_palmsensor) {
+			input_set_capability(tpacpi_sw_dev, EV_SW, SW_PALMREST_PROXIMITY);
+			input_report_switch(tpacpi_sw_dev, SW_PALMREST_PROXIMITY, palm_state);
+		}
+		if (has_lapsensor) {
+			input_set_capability(tpacpi_sw_dev, EV_SW, SW_LAP_PROXIMITY);
+			input_report_switch(tpacpi_sw_dev, SW_LAP_PROXIMITY, lap_state);
+		}
 		err = input_register_device(tpacpi_sw_dev);
 		if (err) {
 			input_free_device(tpacpi_sw_dev);
@@ -10053,8 +10094,10 @@ static void tpacpi_driver_event(const unsigned int hkey_event)
 		mutex_unlock(&kbdlight_mutex);
 	}
 
-	if (hkey_event == TP_HKEY_EV_THM_CSM_COMPLETED)
+	if (hkey_event == TP_HKEY_EV_THM_CSM_COMPLETED) {
 		dytc_lapmode_refresh();
+		lapsensor_refresh();
+	}
 
 }
 
Signature · 1 line
2.28.0
Reviewed-by on v3 1/3
#3 lore raw
In reply to Mark Pearson

Hi,

Quoted 7 lines · Mark Pearson

Add infrastructure needed to support lap and palmrest proximity sensors.

These sensors are used for identifying thermal mode changes and modifying WWAN transmitter power.

The entire series looks good to me and is:

Dmitry: FYI I have take over drivers/platform/x86
maintainership from Andy.

Dmitry, since the first patch adds new evdev switch event-codes, it is probably best if you merge this entire series through the input tree. You hereby have my ack (as the new pdx86 maintainer) for doing this.

Regards,

Hans

Quoted 39 lines

---
Changes in v2:
- Update Input message
Changes in v3:
- Added missing patch history notes

 include/linux/mod_devicetable.h        | 2 +-
 include/uapi/linux/input-event-codes.h | 4 +++-
 2 files changed, 4 insertions(+), 2 deletions(-)
include/linux/mod_devicetable.h +1 -1
index 5b08a473cdba..897f5a3e7721 100644
@@ -320,7 +320,7 @@ struct pcmcia_device_id {
 #define INPUT_DEVICE_ID_LED_MAX		0x0f
 #define INPUT_DEVICE_ID_SND_MAX		0x07
 #define INPUT_DEVICE_ID_FF_MAX		0x7f
-#define INPUT_DEVICE_ID_SW_MAX		0x10
+#define INPUT_DEVICE_ID_SW_MAX		0x12
 #define INPUT_DEVICE_ID_PROP_MAX	0x1f
 
 #define INPUT_DEVICE_ID_MATCH_BUS	1
include/uapi/linux/input-event-codes.h +3 -1
index 0c2e27d28e0a..26f71a9a6936 100644
@@ -889,7 +889,9 @@
 #define SW_MUTE_DEVICE		0x0e  /* set = device disabled */
 #define SW_PEN_INSERTED		0x0f  /* set = pen inserted */
 #define SW_MACHINE_COVER	0x10  /* set = cover closed */
-#define SW_MAX			0x10
+#define SW_LAP_PROXIMITY        0x11  /* set = lap proximity sensor active */
+#define SW_PALMREST_PROXIMITY   0x12  /* set = palmrest proximity sensor active */
+#define SW_MAX			0x12
 #define SW_CNT			(SW_MAX+1)
 
 /*