From: Elia Devito <eliadevito@gmail.com>
To: unlisted-recipients:; (no To-header on input)
Cc: Elia Devito <eliadevito@gmail.com>,
Alex Hung <alex.hung@canonical.com>,
Hans de Goede <hdegoede@redhat.com>,
Mark Gross <mgross@linux.intel.com>,
platform-driver-x86@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: [PATCH v3 1/2] intel-hid: add support for SW_TABLET_MODE
Date: Fri, 4 Dec 2020 17:01:22 +0100 [thread overview]
Message-ID: <20201204160121.36703-1-elia@xvalue.it> (raw)
In-Reply-To: <20201203212000.35898-1-eliadevito@gmail.com>
From: Elia Devito <eliadevito@gmail.com>
Some convertible use the intel-hid ACPI interface to report SW_TABLET_MODE,
implement this with DMI based allow-list to be sure to activate support
only on models that effectively have it.
Signed-off-by: Elia Devito <eliadevito@gmail.com>
---
v2:
patch reworked according to received feedbacks
v3:
improved code according to received feedbacks
drivers/platform/x86/intel-hid.c | 95 ++++++++++++++++++++++++++++++++
1 file changed, 95 insertions(+)
diff --git a/drivers/platform/x86/intel-hid.c b/drivers/platform/x86/intel-hid.c
index 86261970bd8f..d2f892665ec6 100644
--- a/drivers/platform/x86/intel-hid.c
+++ b/drivers/platform/x86/intel-hid.c
@@ -15,6 +15,9 @@
#include <linux/platform_device.h>
#include <linux/suspend.h>
+/* When NOT in tablet mode, VGBS returns with the flag 0x40 */
+#define TABLET_MODE_FLAG BIT(6)
+
MODULE_LICENSE("GPL");
MODULE_AUTHOR("Alex Hung");
@@ -89,9 +92,26 @@ static const struct dmi_system_id button_array_table[] = {
{ }
};
+/*
+ * Some convertible use the intel-hid ACPI interface to report SW_TABLET_MODE,
+ * these need to be compared via a DMI based authorization list because some
+ * models have unreliable VGBS return which could cause incorrect
+ * SW_TABLET_MODE report.
+ */
+static const struct dmi_system_id dmi_vgbs_allow_list[] = {
+ {
+ .matches = {
+ DMI_MATCH(DMI_SYS_VENDOR, "HP"),
+ DMI_MATCH(DMI_PRODUCT_NAME, "HP Spectre x360 Convertible 15-df0xxx"),
+ },
+ },
+ { }
+};
+
struct intel_hid_priv {
struct input_dev *input_dev;
struct input_dev *array;
+ struct input_dev *switches;
bool wakeup_mode;
};
@@ -347,6 +367,57 @@ static int intel_button_array_input_setup(struct platform_device *device)
return input_register_device(priv->array);
}
+static int intel_hid_switches_setup(struct platform_device *device)
+{
+ struct intel_hid_priv *priv = dev_get_drvdata(&device->dev);
+
+ /* Setup input device for switches */
+ priv->switches = devm_input_allocate_device(&device->dev);
+ if (!priv->switches)
+ return -ENOMEM;
+
+ __set_bit(EV_SW, priv->switches->evbit);
+ __set_bit(SW_TABLET_MODE, priv->switches->swbit);
+
+ priv->switches->name = "Intel HID switches";
+ priv->switches->id.bustype = BUS_HOST;
+ return input_register_device(priv->switches);
+}
+
+static void report_tablet_mode_state(struct platform_device *device)
+{
+ struct intel_hid_priv *priv = dev_get_drvdata(&device->dev);
+ acpi_handle handle = ACPI_HANDLE(&device->dev);
+ unsigned long long vgbs;
+ int m;
+
+ if (!intel_hid_evaluate_method(handle, INTEL_HID_DSM_VGBS_FN, &vgbs))
+ return;
+
+ m = !(vgbs & TABLET_MODE_FLAG);
+ input_report_switch(priv->switches, SW_TABLET_MODE, m);
+ input_sync(priv->switches);
+}
+
+static bool report_tablet_mode_event(struct input_dev *input_dev, u32 event)
+{
+ if (!input_dev)
+ return false;
+
+ switch (event) {
+ case 0xcc:
+ input_report_switch(input_dev, SW_TABLET_MODE, 1);
+ input_sync(input_dev);
+ return true;
+ case 0xcd:
+ input_report_switch(input_dev, SW_TABLET_MODE, 0);
+ input_sync(input_dev);
+ return true;
+ default:
+ return false;
+ }
+}
+
static void notify_handler(acpi_handle handle, u32 event, void *context)
{
struct platform_device *device = context;
@@ -363,6 +434,13 @@ static void notify_handler(acpi_handle handle, u32 event, void *context)
if (event == 0xce)
goto wakeup;
+ /*
+ * Switch events will wake the device and report the new switch
+ * position to the input subsystem.
+ */
+ if (priv->switches && (event == 0xcc || event == 0xcd))
+ goto wakeup;
+
/* Wake up on 5-button array events only. */
if (event == 0xc0 || !priv->array)
return;
@@ -374,6 +452,10 @@ static void notify_handler(acpi_handle handle, u32 event, void *context)
wakeup:
pm_wakeup_hard_event(&device->dev);
+
+ if (report_tablet_mode_event(priv->switches, event))
+ return;
+
return;
}
@@ -398,6 +480,9 @@ static void notify_handler(acpi_handle handle, u32 event, void *context)
}
}
+ if (report_tablet_mode_event(priv->switches, event))
+ return;
+
/* 0xC0 is for HID events, other values are for 5 button array */
if (event != 0xc0) {
if (!priv->array ||
@@ -485,6 +570,16 @@ static int intel_hid_probe(struct platform_device *device)
pr_err("Failed to setup Intel 5 button array hotkeys\n");
}
+ /* Setup switches for devices that we know VGBS return correctly */
+ if (dmi_check_system(dmi_vgbs_allow_list)) {
+ dev_info(&device->dev, "platform supports switches\n");
+ err = intel_hid_switches_setup(device);
+ if (err)
+ pr_err("Failed to setup Intel HID switches\n");
+ else
+ report_tablet_mode_state(device);
+ }
+
status = acpi_install_notify_handler(handle,
ACPI_DEVICE_NOTIFY,
notify_handler,
--
2.28.0
next prev parent reply other threads:[~2020-12-04 16:03 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-12-01 19:55 [PATCH 1/3] intel-hid: add support for SW_TABLET_MODE Elia Devito
2020-12-01 21:23 ` Hans de Goede
2020-12-03 21:20 ` [PATCH v2 1/2] " Elia Devito
2020-12-04 16:01 ` Elia Devito [this message]
2020-12-07 16:49 ` [PATCH v3 " Hans de Goede
2020-12-04 16:02 ` [PATCH v3 2/2] intel-hid: add alternative method to enable switches Elia Devito
2020-12-03 21:21 ` [PATCH v2 " Elia Devito
2020-12-03 23:45 ` Barnabás Pőcze
2020-12-03 23:52 ` Barnabás Pőcze
2020-12-04 15:22 ` Elia Devito
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20201204160121.36703-1-elia@xvalue.it \
--to=eliadevito@gmail.com \
--cc=alex.hung@canonical.com \
--cc=hdegoede@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mgross@linux.intel.com \
--cc=platform-driver-x86@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).