[PATCH v3 0/2] platform/x86: Add driver for Yoga Tablet mode switch

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This driver maps the Lenovo Yoga tablet mode switch to a SW_TABLET_MODE input
device. This will make the tablet status available to desktop environments.

This patch series is the result of the discussion at
https://lore.kernel.org/r/CAG4kvq9US=-NjyXFMzJYu2zCJryJWtOc7FGZbrewpgCDjdAkbg@xxxxxxxxxxxxxx/

I decided to follow-up on the patch Gergo wrote and respond to the review
comments to get it merged and available for everyone.

Gergo and I have tested this on the Yoga 7 14ARB7, and the Yoga 7 14AIL7
respectively. Additionally, according to reports at
https://github.com/lukas-w/yoga-usage-mode, which uses the same WMI devices,
this driver should work with:
Yoga C940, Ideapad flex 14API, Yoga 9 14IAP7, Yoga 7 14ARB7, etc.

v1: https://lore.kernel.org/r/20230310041726.217447-1-kallmeyeras@xxxxxxxxx/
v2: https://lore.kernel.org/r/20230323025200.5462-1-kallmeyeras@xxxxxxxxx/
The diff since v2 is as follows:

--- a/drivers/platform/x86/lenovo-ymc.c
+++ b/drivers/platform/x86/lenovo-ymc.c
@@ -21,8 +21,8 @@
 #define LENOVO_YMC_QUERY_METHOD 0x01
 
 static bool ec_trigger __read_mostly;
-module_param(ec_trigger, bool, 0644);
-MODULE_PARM_DESC(ec_trigger, "Enable EC triggering to emit YMC events");
+module_param(ec_trigger, bool, 0444);
+MODULE_PARM_DESC(ec_trigger, "Enable EC triggering work-around to force emitting tablet mode events");
 
 static const struct dmi_system_id ec_trigger_quirk_dmi_table[] = {
 	{
@@ -43,8 +43,7 @@ struct lenovo_ymc_private {
 static void lenovo_ymc_trigger_ec(struct wmi_device *wdev, struct lenovo_ymc_private *priv)
 {
 	int err;
-
-	if (!ec_trigger || !priv || !priv->ec_acpi_dev)
+	if (!priv->ec_acpi_dev)
 		return;
 	err = write_ec_cmd(priv->ec_acpi_dev->handle, VPCCMD_W_YMC, 1);
 	if (err)
@@ -103,11 +102,7 @@ static void lenovo_ymc_notify(struct wmi_device *wdev, union acpi_object *data)
 	lenovo_ymc_trigger_ec(wdev, priv);
 }
 
-static void lenovo_ymc_remove(struct wmi_device *wdev)
-{
-	struct lenovo_ymc_private *priv = dev_get_drvdata(&wdev->dev);
-	acpi_dev_put(priv->ec_acpi_dev);
-}
+static void acpi_dev_put_helper(void *p) { acpi_dev_put(p); }
 
 static int lenovo_ymc_probe(struct wmi_device *wdev, const void *ctx)
 {
@@ -124,10 +119,18 @@ static int lenovo_ymc_probe(struct wmi_device *wdev, const void *ctx)
 	if (ec_trigger) {
 		pr_debug("Lenovo YMC enable EC triggering.\n");
 		priv->ec_acpi_dev = acpi_dev_get_first_match_dev("VPC2004", NULL, -1);
+
 		if (!priv->ec_acpi_dev) {
 			dev_err(&wdev->dev, "Could not find EC ACPI device.\n");
 			return -ENODEV;
 		}
+		err = devm_add_action_or_reset(&wdev->dev,
+				acpi_dev_put_helper, priv->ec_acpi_dev);
+		if (err) {
+			dev_err(&wdev->dev,
+				"Could not clean up EC ACPI device: %d\n", err);
+			return err;
+		}
 	}
 
 	input_dev = devm_input_allocate_device(&wdev->dev);
@@ -138,9 +141,6 @@ static int lenovo_ymc_probe(struct wmi_device *wdev, const void *ctx)
 	input_dev->phys = LENOVO_YMC_EVENT_GUID "/input0";
 	input_dev->id.bustype = BUS_HOST;
 	input_dev->dev.parent = &wdev->dev;
-
-	input_set_capability(input_dev, EV_SW, SW_TABLET_MODE);
-
 	err = sparse_keymap_setup(input_dev, lenovo_ymc_keymap, NULL);
 	if (err) {
 		dev_err(&wdev->dev,
@@ -177,7 +177,6 @@ static struct wmi_driver lenovo_ymc_driver = {
 	.id_table = lenovo_ymc_wmi_id_table,
 	.probe = lenovo_ymc_probe,
 	.notify = lenovo_ymc_notify,
-	.remove = lenovo_ymc_remove,
 };
 
 module_wmi_driver(lenovo_ymc_driver);

Andrew Kallmeyer (1):
  platform/x86: Move ideapad ACPI helpers to a new header

Gergo Koteles (1):
  platform/x86: Add driver for Yoga Tablet Mode switch

 drivers/platform/x86/Kconfig          |  10 ++
 drivers/platform/x86/Makefile         |   1 +
 drivers/platform/x86/ideapad-laptop.c | 135 +------------------
 drivers/platform/x86/ideapad-laptop.h | 152 +++++++++++++++++++++
 drivers/platform/x86/lenovo-ymc.c     | 185 ++++++++++++++++++++++++++
 5 files changed, 349 insertions(+), 134 deletions(-)
 create mode 100644 drivers/platform/x86/ideapad-laptop.h
 create mode 100644 drivers/platform/x86/lenovo-ymc.c

-- 
2.40.0




[Index of Archives]     [Linux Kernel Development]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux