* [PATCH v3 1/3] Input: add event codes for lap and palmreset proximity switches
@ 2020-10-26 14:45 Mark Pearson
2020-10-26 14:45 ` [PATCH v3 2/3] platform/x86: thinkpad_acpi: Add support for palm sensor Mark Pearson
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Mark Pearson @ 2020-10-26 14:45 UTC (permalink / raw)
To: markpearson
Cc: dmitry.torokhov, hdegoede, platform-driver-x86, linux-input,
jeff, anthony.wong, hadess, Nitin Joshi
Add infrastructure needed to support lap and palmrest proximity sensors.
These sensors are used for identifying thermal mode changes and modifying
WWAN transmitter power.
Reviewed-by: Nitin Joshi <njoshi1@lenovo.com>
Signed-off-by: Mark Pearson <markpearson@lenovo.com>
---
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(-)
diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h
index 5b08a473cdba..897f5a3e7721 100644
--- a/include/linux/mod_devicetable.h
+++ b/include/linux/mod_devicetable.h
@@ -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
diff --git a/include/uapi/linux/input-event-codes.h b/include/uapi/linux/input-event-codes.h
index 0c2e27d28e0a..26f71a9a6936 100644
--- a/include/uapi/linux/input-event-codes.h
+++ b/include/uapi/linux/input-event-codes.h
@@ -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)
/*
--
2.28.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH v3 2/3] platform/x86: thinkpad_acpi: Add support for palm sensor
2020-10-26 14:45 [PATCH v3 1/3] Input: add event codes for lap and palmreset proximity switches Mark Pearson
@ 2020-10-26 14:45 ` Mark Pearson
2020-10-26 14:45 ` [PATCH v3 3/3] platform/x86: thinkpad_acpi: Add support for lap sensor Mark Pearson
2020-10-26 14:57 ` [PATCH v3 1/3] Input: add event codes for lap and palmreset proximity switches Hans de Goede
2 siblings, 0 replies; 4+ messages in thread
From: Mark Pearson @ 2020-10-26 14:45 UTC (permalink / raw)
To: markpearson
Cc: dmitry.torokhov, hdegoede, platform-driver-x86, linux-input,
jeff, anthony.wong, hadess, Nitin Joshi
Use input device event support for notifying userspace of palm sensor
state changes
Co-developed-by: Nitin Joshi <njoshi1@lenovo.com>
Signed-off-by: Nitin Joshi <njoshi1@lenovo.com>
Signed-off-by: Mark Pearson <markpearson@lenovo.com>
---
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(-)
diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
index eae3579f106f..3cb07c12a705 100644
--- a/drivers/platform/x86/thinkpad_acpi.c
+++ b/drivers/platform/x86/thinkpad_acpi.c
@@ -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)
--
2.28.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH v3 3/3] platform/x86: thinkpad_acpi: Add support for lap sensor
2020-10-26 14:45 [PATCH v3 1/3] Input: add event codes for lap and palmreset proximity switches Mark Pearson
2020-10-26 14:45 ` [PATCH v3 2/3] platform/x86: thinkpad_acpi: Add support for palm sensor Mark Pearson
@ 2020-10-26 14:45 ` Mark Pearson
2020-10-26 14:57 ` [PATCH v3 1/3] Input: add event codes for lap and palmreset proximity switches Hans de Goede
2 siblings, 0 replies; 4+ messages in thread
From: Mark Pearson @ 2020-10-26 14:45 UTC (permalink / raw)
To: markpearson
Cc: dmitry.torokhov, hdegoede, platform-driver-x86, linux-input,
jeff, anthony.wong, hadess, Nitin Joshi
Use input device event support for notifying userspace of lap mode sensor
state changes.
Reviewed-by: Nitin Joshi <njoshi1@lenovo.com>
Signed-off-by: Mark Pearson <markpearson@lenovo.com>
---
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(-)
diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
index 3cb07c12a705..fe438a5e1dbe 100644
--- a/drivers/platform/x86/thinkpad_acpi.c
+++ b/drivers/platform/x86/thinkpad_acpi.c
@@ -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();
+ }
}
--
2.28.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH v3 1/3] Input: add event codes for lap and palmreset proximity switches
2020-10-26 14:45 [PATCH v3 1/3] Input: add event codes for lap and palmreset proximity switches Mark Pearson
2020-10-26 14:45 ` [PATCH v3 2/3] platform/x86: thinkpad_acpi: Add support for palm sensor Mark Pearson
2020-10-26 14:45 ` [PATCH v3 3/3] platform/x86: thinkpad_acpi: Add support for lap sensor Mark Pearson
@ 2020-10-26 14:57 ` Hans de Goede
2 siblings, 0 replies; 4+ messages in thread
From: Hans de Goede @ 2020-10-26 14:57 UTC (permalink / raw)
To: Mark Pearson
Cc: dmitry.torokhov, platform-driver-x86, linux-input, jeff,
anthony.wong, hadess, Nitin Joshi
Hi,
On 10/26/20 3:45 PM, Mark Pearson wrote:
> Add infrastructure needed to support lap and palmrest proximity sensors.
>
> These sensors are used for identifying thermal mode changes and modifying
> WWAN transmitter power.
>
> Reviewed-by: Nitin Joshi <njoshi1@lenovo.com>
> Signed-off-by: Mark Pearson <markpearson@lenovo.com>
The entire series looks good to me and is:
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
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
> ---
> 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(-)
>
> diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h
> index 5b08a473cdba..897f5a3e7721 100644
> --- a/include/linux/mod_devicetable.h
> +++ b/include/linux/mod_devicetable.h
> @@ -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
> diff --git a/include/uapi/linux/input-event-codes.h b/include/uapi/linux/input-event-codes.h
> index 0c2e27d28e0a..26f71a9a6936 100644
> --- a/include/uapi/linux/input-event-codes.h
> +++ b/include/uapi/linux/input-event-codes.h
> @@ -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)
>
> /*
>
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2020-10-26 14:58 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-26 14:45 [PATCH v3 1/3] Input: add event codes for lap and palmreset proximity switches Mark Pearson
2020-10-26 14:45 ` [PATCH v3 2/3] platform/x86: thinkpad_acpi: Add support for palm sensor Mark Pearson
2020-10-26 14:45 ` [PATCH v3 3/3] platform/x86: thinkpad_acpi: Add support for lap sensor Mark Pearson
2020-10-26 14:57 ` [PATCH v3 1/3] Input: add event codes for lap and palmreset proximity switches Hans de Goede
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).