Skip to contentSkip to conversation

platform/x86: lenovo-yogabook: Modify to also work on Android version

PATCH Superseded Hans de Goede 3 participants 29 messages Apr 29, 2023 – May 3, 2023

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover platform/x86: lenovo-yogabook: Modify to also work on Android version

Hi All,

The Lenovo Yoga Book (yb1-x9*) is a yoga 2-in-1 where the keyboard half has a touch keyboard (with a backlit fixed key layout) to make it extra thin and light. The keyboard half can also be switched to an alternative wacom digitizer mode where it instead can be used to draw on. The backlight + switching is handled by
the lenovo-yogabook driver.

There are both Windows and Android versions with different BIOS-es / ACPI tables. This series extends the current Windows model only driver to also support the Android model.

On the Android yb1-x90f/l models there is not ACPI method to control the keyboard backlight brightness. Instead the second PWM controller is exposed directly to the OS there.

This requires adding a pwm_lookup table and the lenovo-yogabook code can (and typically is) build as a module. So the first patch in this series exports pwm_add_table() and pwm_remove_table() for use in modules.

I believe that it is easiest to just merge the entire series through the drivers/platform/x86 tree. Thierry, may I have your ack for patch 1/19 to merge it through the pdx86 tree ?

Regards,

Hans

Hans de Goede (19):
pwm: Export pwm_add_table() / pwm_remove_table() platform/x86: lenovo-yogabook: Fix work race on remove() platform/x86: lenovo-yogabook: Reprobe devices on remove() platform/x86: lenovo-yogabook: Set default keyboard backligh
brightness on probe()
platform/x86: lenovo-yogabook: Simplify gpio lookup table cleanup platform/x86: lenovo-yogabook: Switch to DEFINE_SIMPLE_DEV_PM_OPS() platform/x86: lenovo-yogabook: Store dev instead of wdev in drvdata
struct
platform/x86: lenovo-yogabook: Add dev local variable to probe() platform/x86: lenovo-yogabook: Use PMIC LED driver for pen icon LED
control
platform/x86: lenovo-yogabook: Split probe() into generic and WMI
specific parts
platform/x86: lenovo-yogabook: Stop checking adev->power.state platform/x86: lenovo-yogabook: Abstract kbd backlight setting platform/x86: lenovo-yogabook: Add a yogabook_toggle_digitizer_mode()
helper function
platform/x86: lenovo-yogabook: Drop _wmi_ from remaining generic
symbols
platform/x86: lenovo-yogabook: Group WMI specific code together platform/x86: lenovo-yogabook: Add YB_KBD_BL_MAX define platform/x86: lenovo-yogabook: Add platform driver support platform/x86: lenovo-yogabook: Add keyboard backlight control to
platform driver
platform/x86: lenovo-yogabook: Rename lenovo-yogabook-wmi to
lenovo-yogabook

 drivers/platform/x86/Kconfig               |   6 +-
 drivers/platform/x86/Makefile              |   2 +-
 drivers/platform/x86/lenovo-yogabook-wmi.c | 408 --------------
 drivers/platform/x86/lenovo-yogabook.c     | 587 +++++++++++++++++++++
 drivers/pwm/core.c                         |   2 +
 5 files changed, 593 insertions(+), 412 deletions(-)
 delete mode 100644 drivers/platform/x86/lenovo-yogabook-wmi.c
 create mode 100644 drivers/platform/x86/lenovo-yogabook.c
Signature · 1 line
2.39.2
#1 lore raw

PATCH 1/19 pwm: Export pwm_add_table() / pwm_remove_table()

Lenovo Yoga Book 1 (yb1-x90f/l) models have a backlit keyboard where the brightness is directly controlled by one of the Intel Cherry Trail SoCs PWM controllers.

To control the backlight the drivers/platform/lenovo-yogabook.c needs to add a pwm_lookup table entry so that it can call pwm_get() to get a reference to the PWM controller.

The lenovo-yogabook driver can be build as a module, export pwm_add_table() and pwm_remove_table() so that the lenovo-yogabook driver can use them when build as a module.

---
 drivers/pwm/core.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/pwm/core.c +2 -0
index 474725714a05..c66daac6154f 100644
@@ -881,6 +881,7 @@ void pwm_add_table(struct pwm_lookup *table, size_t num)
 
 	mutex_unlock(&pwm_lookup_lock);
 }
+EXPORT_SYMBOL_GPL(pwm_add_table);
 
 /**
  * pwm_remove_table() - unregister PWM device consumers
@@ -898,6 +899,7 @@ void pwm_remove_table(struct pwm_lookup *table, size_t num)
 
 	mutex_unlock(&pwm_lookup_lock);
 }
+EXPORT_SYMBOL_GPL(pwm_remove_table);
 
 /**
  * pwm_get() - look up and request a PWM device
Signature · 1 line
2.39.2
#2 lore raw

PATCH 2/19 platform/x86: lenovo-yogabook: Fix work race on remove()

In reply to Hans de Goede

When yogabook_wmi_remove() runs yogabook_wmi_work might still be running and using the devices which yogabook_wmi_remove() puts.

To avoid this move to explicitly cancelling the work rather then using devm_work_autocancel().

This requires also making the yogabook_backside_hall_irq handler non devm managed, so that it cannot re-queue the work while yogabook_wmi_remove() runs.

Fixes c0549b72d99d ("platform/x86: lenovo-yogabook-wmi: Add driver for Lenovo Yoga Book")
---
 drivers/platform/x86/lenovo-yogabook-wmi.c | 19 ++++++++++---------
 1 file changed, 10 insertions(+), 9 deletions(-)
drivers/platform/x86/lenovo-yogabook-wmi.c +10 -9
index 5f4bd1eec38a..c12486702f33 100644
@@ -248,10 +248,7 @@ static int yogabook_wmi_probe(struct wmi_device *wdev, const void *context)
 	data->brightness = YB_KBD_BL_DEFAULT;
 	set_bit(YB_KBD_IS_ON, &data->flags);
 	set_bit(YB_DIGITIZER_IS_ON, &data->flags);
-
-	r = devm_work_autocancel(&wdev->dev, &data->work, yogabook_wmi_work);
-	if (r)
-		return r;
+	INIT_WORK(&data->work, yogabook_wmi_work);
 
 	data->kbd_adev = acpi_dev_get_first_match_dev("GDIX1001", NULL, -1);
 	if (!data->kbd_adev) {
@@ -299,10 +296,9 @@ static int yogabook_wmi_probe(struct wmi_device *wdev, const void *context)
 	}
 	data->backside_hall_irq = r;
 
-	r = devm_request_irq(&wdev->dev, data->backside_hall_irq,
-			     yogabook_backside_hall_irq,
-			     IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING,
-			     "backside_hall_sw", data);
+	r = request_irq(data->backside_hall_irq, yogabook_backside_hall_irq,
+			IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING,
+			"backside_hall_sw", data);
 	if (r) {
 		dev_err_probe(&wdev->dev, r, "Requesting backside_hall_sw IRQ\n");
 		goto error_put_devs;
@@ -318,11 +314,14 @@ static int yogabook_wmi_probe(struct wmi_device *wdev, const void *context)
 	r = devm_led_classdev_register(&wdev->dev, &data->kbd_bl_led);
 	if (r < 0) {
 		dev_err_probe(&wdev->dev, r, "Registering backlight LED device\n");
-		goto error_put_devs;
+		goto error_free_irq;
 	}
 
 	return 0;
 
+error_free_irq:
+	free_irq(data->backside_hall_irq, data);
+	cancel_work_sync(&data->work);
 error_put_devs:
 	put_device(data->dig_dev);
 	put_device(data->kbd_dev);
@@ -335,6 +334,8 @@ static void yogabook_wmi_remove(struct wmi_device *wdev)
 {
 	struct yogabook_wmi *data = dev_get_drvdata(&wdev->dev);
 
+	free_irq(data->backside_hall_irq, data);
+	cancel_work_sync(&data->work);
 	put_device(data->dig_dev);
 	put_device(data->kbd_dev);
 	acpi_dev_put(data->dig_adev);
Signature · 1 line
2.39.2
#3 lore raw

PATCH 3/19 platform/x86: lenovo-yogabook: Reprobe devices on remove()

In reply to Hans de Goede

Ensure that both the keyboard touchscreen and the digitizer have their driver bound after remove(). Without this modprobing lenovo-yogabook-wmi after a rmmod fails because lenovo-yogabook-wmi defers probing until both devices have their driver bound.

Fixes c0549b72d99d ("platform/x86: lenovo-yogabook-wmi: Add driver for Lenovo Yoga Book")
---
 drivers/platform/x86/lenovo-yogabook-wmi.c | 11 +++++++++++
 1 file changed, 11 insertions(+)
drivers/platform/x86/lenovo-yogabook-wmi.c +11 -0
index c12486702f33..ed8015d6c582 100644
@@ -333,9 +333,20 @@ static int yogabook_wmi_probe(struct wmi_device *wdev, const void *context)
 static void yogabook_wmi_remove(struct wmi_device *wdev)
 {
 	struct yogabook_wmi *data = dev_get_drvdata(&wdev->dev);
+	int r = 0;
 
 	free_irq(data->backside_hall_irq, data);
 	cancel_work_sync(&data->work);
+
+	if (!test_bit(YB_KBD_IS_ON, &data->flags))
+		r |= device_reprobe(data->kbd_dev);
+
+	if (!test_bit(YB_DIGITIZER_IS_ON, &data->flags))
+		r |= device_reprobe(data->dig_dev);
+
+	if (r)
+		dev_warn(&wdev->dev, "Reprobe of devices failed\n");
+
 	put_device(data->dig_dev);
 	put_device(data->kbd_dev);
 	acpi_dev_put(data->dig_adev);
Signature · 1 line
2.39.2
#4 lore raw

PATCH 4/19 platform/x86: lenovo-yogabook: Set default keyboard backligh brightness on probe()

In reply to Hans de Goede

Set default keyboard backlight brightness on probe(), this fixes the backlight being off after a rmmod + modprobe.

Fixes c0549b72d99d ("platform/x86: lenovo-yogabook-wmi: Add driver for Lenovo Yoga Book")
---
 drivers/platform/x86/lenovo-yogabook-wmi.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/platform/x86/lenovo-yogabook-wmi.c +3 -0
index ed8015d6c582..727e3ae5e8f5 100644
@@ -296,6 +296,9 @@ static int yogabook_wmi_probe(struct wmi_device *wdev, const void *context)
 	}
 	data->backside_hall_irq = r;
 
+	/* Set default brightness before enabling the IRQ */
+	yogabook_wmi_set_kbd_backlight(data->wdev, YB_KBD_BL_DEFAULT);
+
 	r = request_irq(data->backside_hall_irq, yogabook_backside_hall_irq,
 			IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING,
 			"backside_hall_sw", data);
Signature · 1 line
2.39.2
#5 lore raw

PATCH 5/19 platform/x86: lenovo-yogabook: Simplify gpio lookup table cleanup

In reply to Hans de Goede

After the devm_gpiod_get("backside_hall_sw") call the gpio lookup table is no longer necessary.

Remove it directly after this call instead using a devm reset-action for this.

---
 drivers/platform/x86/lenovo-yogabook-wmi.c | 13 ++-----------
 1 file changed, 2 insertions(+), 11 deletions(-)
drivers/platform/x86/lenovo-yogabook-wmi.c +2 -11
index 727e3ae5e8f5..62db455218a5 100644
@@ -228,11 +228,6 @@ static struct gpiod_lookup_table yogabook_wmi_gpios = {
 	},
 };
 
-static void yogabook_wmi_rm_gpio_lookup(void *unused)
-{
-	gpiod_remove_lookup_table(&yogabook_wmi_gpios);
-}
-
 static int yogabook_wmi_probe(struct wmi_device *wdev, const void *context)
 {
 	struct yogabook_wmi *data;
@@ -276,13 +271,9 @@ static int yogabook_wmi_probe(struct wmi_device *wdev, const void *context)
 	}
 
 	gpiod_add_lookup_table(&yogabook_wmi_gpios);
+	data->backside_hall_gpio = devm_gpiod_get(&wdev->dev, "backside_hall_sw", GPIOD_IN);
+	gpiod_remove_lookup_table(&yogabook_wmi_gpios);
 
-	r = devm_add_action_or_reset(&wdev->dev, yogabook_wmi_rm_gpio_lookup, NULL);
-	if (r)
-		goto error_put_devs;
-
-	data->backside_hall_gpio =
-		devm_gpiod_get(&wdev->dev, "backside_hall_sw", GPIOD_IN);
 	if (IS_ERR(data->backside_hall_gpio)) {
 		r = PTR_ERR(data->backside_hall_gpio);
 		dev_err_probe(&wdev->dev, r, "Getting backside_hall_sw GPIO\n");
Signature · 1 line
2.39.2
#6 lore raw

PATCH 6/19 platform/x86: lenovo-yogabook: Switch to DEFINE_SIMPLE_DEV_PM_OPS()

In reply to Hans de Goede

Switch to DEFINE_SIMPLE_DEV_PM_OPS() so that the __maybe_unused can be dropped from the suspend/resume callbacks.

While at it also drop the _wmi_ part from the callback names in preparation for making lenovo-yogabook-wmi also work on the Android version of the Yoga Book 1 which does not have a WMI interface to deal with toggling the keyboard half between touch-keyboard and wacom-digitizer mode.

---
 drivers/platform/x86/lenovo-yogabook-wmi.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)
drivers/platform/x86/lenovo-yogabook-wmi.c +4 -5
index 62db455218a5..61076137a350 100644
@@ -347,7 +347,7 @@ static void yogabook_wmi_remove(struct wmi_device *wdev)
 	acpi_dev_put(data->kbd_adev);
 }
 
-static int __maybe_unused yogabook_wmi_suspend(struct device *dev)
+static int yogabook_suspend(struct device *dev)
 {
 	struct wmi_device *wdev = container_of(dev, struct wmi_device, dev);
 	struct yogabook_wmi *data = dev_get_drvdata(dev);
@@ -363,7 +363,7 @@ static int __maybe_unused yogabook_wmi_suspend(struct device *dev)
 	return 0;
 }
 
-static int __maybe_unused yogabook_wmi_resume(struct device *dev)
+static int yogabook_resume(struct device *dev)
 {
 	struct wmi_device *wdev = container_of(dev, struct wmi_device, dev);
 	struct yogabook_wmi *data = dev_get_drvdata(dev);
@@ -392,13 +392,12 @@ static const struct wmi_device_id yogabook_wmi_id_table[] = {
 	{ } /* Terminating entry */
 };
 
-static SIMPLE_DEV_PM_OPS(yogabook_wmi_pm_ops,
-			 yogabook_wmi_suspend, yogabook_wmi_resume);
+static DEFINE_SIMPLE_DEV_PM_OPS(yogabook_pm_ops, yogabook_suspend, yogabook_resume);
 
 static struct wmi_driver yogabook_wmi_driver = {
 	.driver = {
 		.name = "yogabook-wmi",
-		.pm = &yogabook_wmi_pm_ops,
+		.pm = pm_sleep_ptr(&yogabook_pm_ops),
 	},
 	.no_notify_data = true,
 	.id_table = yogabook_wmi_id_table,
Signature · 1 line
2.39.2
#7 lore raw

PATCH 7/19 platform/x86: lenovo-yogabook: Store dev instead of wdev in drvdata struct

In reply to Hans de Goede

Store a "struct device *dev" instead of a "struct wmi_device *wdev;" in the "struct yogabook_wmi" driver-data.

This is a preparation patch for making lenovo-yogabook-wmi also work on the Android version of the Yoga Book 1 which does not have a WMI interface to deal with toggling the keyboard half between touch-keyboard and wacom-digitizer mode.

---
 drivers/platform/x86/lenovo-yogabook-wmi.c | 47 ++++++++++------------
 1 file changed, 21 insertions(+), 26 deletions(-)
drivers/platform/x86/lenovo-yogabook-wmi.c +21 -26
index 61076137a350..2bf40930c51a 100644
@@ -30,7 +30,7 @@ enum {
 };
 
 struct yogabook_wmi {
-	struct wmi_device *wdev;
+	struct device *dev;
 	struct acpi_device *kbd_adev;
 	struct acpi_device *dig_adev;
 	struct device *kbd_dev;
@@ -43,14 +43,14 @@ struct yogabook_wmi {
 	uint8_t brightness;
 };
 
-static int yogabook_wmi_do_action(struct wmi_device *wdev, int action)
+static int yogabook_wmi_do_action(struct yogabook_wmi *data, int action)
 {
 	struct acpi_buffer output = { ACPI_ALLOCATE_BUFFER, NULL };
 	struct acpi_buffer input;
 	acpi_status status;
 	u32 dummy_arg = 0;
 
-	dev_dbg(&wdev->dev, "Do action: %d\n", action);
+	dev_dbg(data->dev, "Do action: %d\n", action);
 
 	input.pointer = &dummy_arg;
 	input.length = sizeof(dummy_arg);
@@ -58,7 +58,7 @@ static int yogabook_wmi_do_action(struct wmi_device *wdev, int action)
 	status = wmi_evaluate_method(YB_MBTN_METHOD_GUID, 0, action, &input,
 				     &output);
 	if (ACPI_FAILURE(status)) {
-		dev_err(&wdev->dev, "Calling WMI method failure: 0x%x\n",
+		dev_err(data->dev, "Calling WMI method failure: 0x%x\n",
 			status);
 		return status;
 	}
@@ -72,21 +72,20 @@ static int yogabook_wmi_do_action(struct wmi_device *wdev, int action)
  * To control keyboard backlight, call the method KBLC() of the TCS1 ACPI
  * device (Goodix touchpad acts as virtual sensor keyboard).
  */
-static int yogabook_wmi_set_kbd_backlight(struct wmi_device *wdev,
+static int yogabook_wmi_set_kbd_backlight(struct yogabook_wmi *data,
 					  uint8_t level)
 {
-	struct yogabook_wmi *data = dev_get_drvdata(&wdev->dev);
 	struct acpi_buffer output = { ACPI_ALLOCATE_BUFFER, NULL };
 	struct acpi_object_list input;
 	union acpi_object param;
 	acpi_status status;
 
 	if (data->kbd_adev->power.state != ACPI_STATE_D0) {
-		dev_warn(&wdev->dev, "keyboard touchscreen not in D0, cannot set brightness\n");
+		dev_warn(data->dev, "keyboard touchscreen not in D0, cannot set brightness\n");
 		return -ENXIO;
 	}
 
-	dev_dbg(&wdev->dev, "Set KBLC level to %u\n", level);
+	dev_dbg(data->dev, "Set KBLC level to %u\n", level);
 
 	input.count = 1;
 	input.pointer = &param;
@@ -97,7 +96,7 @@ static int yogabook_wmi_set_kbd_backlight(struct wmi_device *wdev,
 	status = acpi_evaluate_object(acpi_device_handle(data->kbd_adev), "KBLC",
 				      &input, &output);
 	if (ACPI_FAILURE(status)) {
-		dev_err(&wdev->dev, "Failed to call KBLC method: 0x%x\n", status);
+		dev_err(data->dev, "Failed to call KBLC method: 0x%x\n", status);
 		return status;
 	}
 
@@ -108,7 +107,6 @@ static int yogabook_wmi_set_kbd_backlight(struct wmi_device *wdev,
 static void yogabook_wmi_work(struct work_struct *work)
 {
 	struct yogabook_wmi *data = container_of(work, struct yogabook_wmi, work);
-	struct device *dev = &data->wdev->dev;
 	bool kbd_on, digitizer_on;
 	int r;
 
@@ -131,13 +129,13 @@ static void yogabook_wmi_work(struct work_struct *work)
 		 * Must be done before releasing the keyboard touchscreen driver,
 		 * so that the keyboard touchscreen dev is still in D0.
 		 */
-		yogabook_wmi_set_kbd_backlight(data->wdev, 0);
+		yogabook_wmi_set_kbd_backlight(data, 0);
 		device_release_driver(data->kbd_dev);
 		clear_bit(YB_KBD_IS_ON, &data->flags);
 	}
 
 	if (!digitizer_on && test_bit(YB_DIGITIZER_IS_ON, &data->flags)) {
-		yogabook_wmi_do_action(data->wdev, YB_PAD_DISABLE);
+		yogabook_wmi_do_action(data, YB_PAD_DISABLE);
 		device_release_driver(data->dig_dev);
 		clear_bit(YB_DIGITIZER_IS_ON, &data->flags);
 	}
@@ -145,18 +143,18 @@ static void yogabook_wmi_work(struct work_struct *work)
 	if (kbd_on && !test_bit(YB_KBD_IS_ON, &data->flags)) {
 		r = device_reprobe(data->kbd_dev);
 		if (r)
-			dev_warn(dev, "Reprobe of keyboard touchscreen failed: %d\n", r);
+			dev_warn(data->dev, "Reprobe of keyboard touchscreen failed: %d\n", r);
 
-		yogabook_wmi_set_kbd_backlight(data->wdev, data->brightness);
+		yogabook_wmi_set_kbd_backlight(data, data->brightness);
 		set_bit(YB_KBD_IS_ON, &data->flags);
 	}
 
 	if (digitizer_on && !test_bit(YB_DIGITIZER_IS_ON, &data->flags)) {
 		r = device_reprobe(data->dig_dev);
 		if (r)
-			dev_warn(dev, "Reprobe of digitizer failed: %d\n", r);
+			dev_warn(data->dev, "Reprobe of digitizer failed: %d\n", r);
 
-		yogabook_wmi_do_action(data->wdev, YB_PAD_ENABLE);
+		yogabook_wmi_do_action(data, YB_PAD_ENABLE);
 		set_bit(YB_DIGITIZER_IS_ON, &data->flags);
 	}
 }
@@ -207,7 +205,6 @@ static int kbd_brightness_set(struct led_classdev *cdev,
 {
 	struct yogabook_wmi *data =
 		container_of(cdev, struct yogabook_wmi, kbd_bl_led);
-	struct wmi_device *wdev = data->wdev;
 
 	if ((value < 0) || (value > 255))
 		return -EINVAL;
@@ -217,7 +214,7 @@ static int kbd_brightness_set(struct led_classdev *cdev,
 	if (data->kbd_adev->power.state != ACPI_STATE_D0)
 		return 0;
 
-	return yogabook_wmi_set_kbd_backlight(wdev, data->brightness);
+	return yogabook_wmi_set_kbd_backlight(data, data->brightness);
 }
 
 static struct gpiod_lookup_table yogabook_wmi_gpios = {
@@ -239,7 +236,7 @@ static int yogabook_wmi_probe(struct wmi_device *wdev, const void *context)
 
 	dev_set_drvdata(&wdev->dev, data);
 
-	data->wdev = wdev;
+	data->dev = &wdev->dev;
 	data->brightness = YB_KBD_BL_DEFAULT;
 	set_bit(YB_KBD_IS_ON, &data->flags);
 	set_bit(YB_DIGITIZER_IS_ON, &data->flags);
@@ -288,7 +285,7 @@ static int yogabook_wmi_probe(struct wmi_device *wdev, const void *context)
 	data->backside_hall_irq = r;
 
 	/* Set default brightness before enabling the IRQ */
-	yogabook_wmi_set_kbd_backlight(data->wdev, YB_KBD_BL_DEFAULT);
+	yogabook_wmi_set_kbd_backlight(data, YB_KBD_BL_DEFAULT);
 
 	r = request_irq(data->backside_hall_irq, yogabook_backside_hall_irq,
 			IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING,
@@ -339,7 +336,7 @@ static void yogabook_wmi_remove(struct wmi_device *wdev)
 		r |= device_reprobe(data->dig_dev);
 
 	if (r)
-		dev_warn(&wdev->dev, "Reprobe of devices failed\n");
+		dev_warn(data->dev, "Reprobe of devices failed\n");
 
 	put_device(data->dig_dev);
 	put_device(data->kbd_dev);
@@ -349,7 +346,6 @@ static void yogabook_wmi_remove(struct wmi_device *wdev)
 
 static int yogabook_suspend(struct device *dev)
 {
-	struct wmi_device *wdev = container_of(dev, struct wmi_device, dev);
 	struct yogabook_wmi *data = dev_get_drvdata(dev);
 
 	set_bit(YB_SUSPENDED, &data->flags);
@@ -358,24 +354,23 @@ static int yogabook_suspend(struct device *dev)
 
 	/* Turn off the pen button at sleep */
 	if (test_bit(YB_DIGITIZER_IS_ON, &data->flags))
-		yogabook_wmi_do_action(wdev, YB_PAD_DISABLE);
+		yogabook_wmi_do_action(data, YB_PAD_DISABLE);
 
 	return 0;
 }
 
 static int yogabook_resume(struct device *dev)
 {
-	struct wmi_device *wdev = container_of(dev, struct wmi_device, dev);
 	struct yogabook_wmi *data = dev_get_drvdata(dev);
 
 	if (test_bit(YB_KBD_IS_ON, &data->flags)) {
 		/* Ensure keyboard touchpad is on before we call KBLC() */
 		acpi_device_set_power(data->kbd_adev, ACPI_STATE_D0);
-		yogabook_wmi_set_kbd_backlight(wdev, data->brightness);
+		yogabook_wmi_set_kbd_backlight(data, data->brightness);
 	}
 
 	if (test_bit(YB_DIGITIZER_IS_ON, &data->flags))
-		yogabook_wmi_do_action(wdev, YB_PAD_ENABLE);
+		yogabook_wmi_do_action(data, YB_PAD_ENABLE);
 
 	clear_bit(YB_SUSPENDED, &data->flags);
 
Signature · 1 line
2.39.2
#8 lore raw

PATCH 8/19 platform/x86: lenovo-yogabook: Add dev local variable to probe()

In reply to Hans de Goede

Add a "struct device *dev" local variable to probe().

This is a preparation patch for making lenovo-yogabook-wmi also work on the Android version of the Yoga Book 1 which does not have a WMI interface to deal with toggling the keyboard half between touch-keyboard and wacom-digitizer mode.

---
 drivers/platform/x86/lenovo-yogabook-wmi.c | 23 +++++++++++-----------
 1 file changed, 12 insertions(+), 11 deletions(-)
drivers/platform/x86/lenovo-yogabook-wmi.c +12 -11
index 2bf40930c51a..b1d17ce9a46c 100644
@@ -227,16 +227,17 @@ static struct gpiod_lookup_table yogabook_wmi_gpios = {
 
 static int yogabook_wmi_probe(struct wmi_device *wdev, const void *context)
 {
+	struct device *dev = &wdev->dev;
 	struct yogabook_wmi *data;
 	int r;
 
-	data = devm_kzalloc(&wdev->dev, sizeof(struct yogabook_wmi), GFP_KERNEL);
+	data = devm_kzalloc(dev, sizeof(struct yogabook_wmi), GFP_KERNEL);
 	if (data == NULL)
 		return -ENOMEM;
 
-	dev_set_drvdata(&wdev->dev, data);
+	dev_set_drvdata(dev, data);
 
-	data->dev = &wdev->dev;
+	data->dev = dev;
 	data->brightness = YB_KBD_BL_DEFAULT;
 	set_bit(YB_KBD_IS_ON, &data->flags);
 	set_bit(YB_DIGITIZER_IS_ON, &data->flags);
@@ -244,13 +245,13 @@ static int yogabook_wmi_probe(struct wmi_device *wdev, const void *context)
 
 	data->kbd_adev = acpi_dev_get_first_match_dev("GDIX1001", NULL, -1);
 	if (!data->kbd_adev) {
-		dev_err(&wdev->dev, "Cannot find the touchpad device in ACPI tables\n");
+		dev_err(dev, "Cannot find the touchpad device in ACPI tables\n");
 		return -ENODEV;
 	}
 
 	data->dig_adev = acpi_dev_get_first_match_dev("WCOM0019", NULL, -1);
 	if (!data->dig_adev) {
-		dev_err(&wdev->dev, "Cannot find the digitizer device in ACPI tables\n");
+		dev_err(dev, "Cannot find the digitizer device in ACPI tables\n");
 		r = -ENODEV;
 		goto error_put_devs;
 	}
@@ -268,18 +269,18 @@ static int yogabook_wmi_probe(struct wmi_device *wdev, const void *context)
 	}
 
 	gpiod_add_lookup_table(&yogabook_wmi_gpios);
-	data->backside_hall_gpio = devm_gpiod_get(&wdev->dev, "backside_hall_sw", GPIOD_IN);
+	data->backside_hall_gpio = devm_gpiod_get(dev, "backside_hall_sw", GPIOD_IN);
 	gpiod_remove_lookup_table(&yogabook_wmi_gpios);
 
 	if (IS_ERR(data->backside_hall_gpio)) {
 		r = PTR_ERR(data->backside_hall_gpio);
-		dev_err_probe(&wdev->dev, r, "Getting backside_hall_sw GPIO\n");
+		dev_err_probe(dev, r, "Getting backside_hall_sw GPIO\n");
 		goto error_put_devs;
 	}
 
 	r = gpiod_to_irq(data->backside_hall_gpio);
 	if (r < 0) {
-		dev_err_probe(&wdev->dev, r, "Getting backside_hall_sw IRQ\n");
+		dev_err_probe(dev, r, "Getting backside_hall_sw IRQ\n");
 		goto error_put_devs;
 	}
 	data->backside_hall_irq = r;
@@ -291,7 +292,7 @@ static int yogabook_wmi_probe(struct wmi_device *wdev, const void *context)
 			IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING,
 			"backside_hall_sw", data);
 	if (r) {
-		dev_err_probe(&wdev->dev, r, "Requesting backside_hall_sw IRQ\n");
+		dev_err_probe(dev, r, "Requesting backside_hall_sw IRQ\n");
 		goto error_put_devs;
 	}
 
@@ -302,9 +303,9 @@ static int yogabook_wmi_probe(struct wmi_device *wdev, const void *context)
 	data->kbd_bl_led.brightness_get = kbd_brightness_get;
 	data->kbd_bl_led.max_brightness = 255;
 
-	r = devm_led_classdev_register(&wdev->dev, &data->kbd_bl_led);
+	r = devm_led_classdev_register(dev, &data->kbd_bl_led);
 	if (r < 0) {
-		dev_err_probe(&wdev->dev, r, "Registering backlight LED device\n");
+		dev_err_probe(dev, r, "Registering backlight LED device\n");
 		goto error_free_irq;
 	}
 
Signature · 1 line
2.39.2
#9 lore raw

Re: [PATCH 08/19] platform/x86: lenovo-yogabook: Add dev local variable to probe()

Quoted 7 lines · Hans de Goede

Add a "struct device *dev" local variable to probe().

This is a preparation patch for making lenovo-yogabook-wmi also work on the Android version of the Yoga Book 1 which does not have a WMI interface to deal with toggling the keyboard half between touch-keyboard and wacom-digitizer mode.

...

drivers/platform/x86/lenovo-yogabook-wmi.c static struct gpiod_lookup_table yogabook_wmi_gpios = { · line 238

Quoted 7 lines
drivers/platform/x86/lenovo-yogabook-wmi.c +2 -2
-       data = devm_kzalloc(&wdev->dev, sizeof(struct yogabook_wmi), GFP_KERNEL);
+       data = devm_kzalloc(dev, sizeof(struct yogabook_wmi), GFP_KERNEL);
        if (data == NULL)
                return -ENOMEM;
 
-       dev_set_drvdata(&wdev->dev, data);
+       dev_set_drvdata(dev, data);

For robustness' sake I would at the same time move this a bit down to have (some? at least dev seems to be important) fields in data to be initialized. Yes, this won't change anything, I hope.

Quoted 5 lines
drivers/platform/x86/lenovo-yogabook-wmi.c +1 -1
-       data->dev = &wdev->dev;
+       data->dev = dev;
        data->brightness = YB_KBD_BL_DEFAULT;
        set_bit(YB_KBD_IS_ON, &data->flags);
        set_bit(YB_DIGITIZER_IS_ON, &data->flags);
Signature · 2 lines
With Best Regards,
Andy Shevchenko
#10 lore raw

PATCH 9/19 platform/x86: lenovo-yogabook: Use PMIC LED driver for pen icon LED control

In reply to Hans de Goede

Use the (new) PMIC LED driver for pen icon LED control instead of using custom WMI calls for this.

This will also work on the Android version of the Lenovo Yoga Book 1, where there is no WMI interface for this.

The dev_id of the lookup is set using dev_name() so that it will also work for both the Windows YB1 WMI-device as well as the Android YB1 platform-device. While at it also move the gpio_lookup to using dev_name() for the dev_id.

Note this also removes the need to turn of the LED during suspend since the PMIC LED driver now already does that.

---
 drivers/platform/x86/lenovo-yogabook-wmi.c | 63 ++++++++--------------
 1 file changed, 21 insertions(+), 42 deletions(-)
drivers/platform/x86/lenovo-yogabook-wmi.c +21 -42
index b1d17ce9a46c..c5d103099ea9 100644
@@ -12,11 +12,6 @@
 #include <linux/workqueue.h>
 
 #define YB_MBTN_EVENT_GUID	"243FEC1D-1963-41C1-8100-06A9D82A94B4"
-#define YB_MBTN_METHOD_GUID	"742B0CA1-0B20-404B-9CAA-AEFCABF30CE0"
-
-#define YB_PAD_ENABLE	1
-#define YB_PAD_DISABLE	2
-#define YB_LIGHTUP_BTN	3
 
 #define YB_KBD_BL_DEFAULT 128
 
@@ -35,6 +30,7 @@ struct yogabook_wmi {
 	struct acpi_device *dig_adev;
 	struct device *kbd_dev;
 	struct device *dig_dev;
+	struct led_classdev *pen_led;
 	struct gpio_desc *backside_hall_gpio;
 	int backside_hall_irq;
 	struct work_struct work;
@@ -43,31 +39,6 @@ struct yogabook_wmi {
 	uint8_t brightness;
 };
 
-static int yogabook_wmi_do_action(struct yogabook_wmi *data, int action)
-{
-	struct acpi_buffer output = { ACPI_ALLOCATE_BUFFER, NULL };
-	struct acpi_buffer input;
-	acpi_status status;
-	u32 dummy_arg = 0;
-
-	dev_dbg(data->dev, "Do action: %d\n", action);
-
-	input.pointer = &dummy_arg;
-	input.length = sizeof(dummy_arg);
-
-	status = wmi_evaluate_method(YB_MBTN_METHOD_GUID, 0, action, &input,
-				     &output);
-	if (ACPI_FAILURE(status)) {
-		dev_err(data->dev, "Calling WMI method failure: 0x%x\n",
-			status);
-		return status;
-	}
-
-	kfree(output.pointer);
-
-	return 0;
-}
-
 /*
  * To control keyboard backlight, call the method KBLC() of the TCS1 ACPI
  * device (Goodix touchpad acts as virtual sensor keyboard).
@@ -135,7 +106,7 @@ static void yogabook_wmi_work(struct work_struct *work)
 	}
 
 	if (!digitizer_on && test_bit(YB_DIGITIZER_IS_ON, &data->flags)) {
-		yogabook_wmi_do_action(data, YB_PAD_DISABLE);
+		led_set_brightness(data->pen_led, LED_OFF);
 		device_release_driver(data->dig_dev);
 		clear_bit(YB_DIGITIZER_IS_ON, &data->flags);
 	}
@@ -154,7 +125,7 @@ static void yogabook_wmi_work(struct work_struct *work)
 		if (r)
 			dev_warn(data->dev, "Reprobe of digitizer failed: %d\n", r);
 
-		yogabook_wmi_do_action(data, YB_PAD_ENABLE);
+		led_set_brightness(data->pen_led, LED_FULL);
 		set_bit(YB_DIGITIZER_IS_ON, &data->flags);
 	}
 }
@@ -218,13 +189,17 @@ static int kbd_brightness_set(struct led_classdev *cdev,
 }
 
 static struct gpiod_lookup_table yogabook_wmi_gpios = {
-	.dev_id		= "243FEC1D-1963-41C1-8100-06A9D82A94B4",
-	.table		= {
+	.table = {
 		GPIO_LOOKUP("INT33FF:02", 18, "backside_hall_sw", GPIO_ACTIVE_LOW),
 		{}
 	},
 };
 
+static struct led_lookup_data yogabook_pen_led = {
+	.provider = "platform::indicator",
+	.con_id = "pen-icon-led",
+};
+
 static int yogabook_wmi_probe(struct wmi_device *wdev, const void *context)
 {
 	struct device *dev = &wdev->dev;
@@ -268,6 +243,18 @@ static int yogabook_wmi_probe(struct wmi_device *wdev, const void *context)
 		goto error_put_devs;
 	}
 
+	yogabook_pen_led.dev_id = dev_name(dev);
+	led_add_lookup(&yogabook_pen_led);
+	data->pen_led = devm_led_get(dev, "pen-icon-led");
+	led_remove_lookup(&yogabook_pen_led);
+
+	if (IS_ERR(data->pen_led)) {
+		r = PTR_ERR(data->pen_led);
+		dev_err_probe(dev, r, "Getting pen icon LED\n");
+		goto error_put_devs;
+	}
+
+	yogabook_wmi_gpios.dev_id = dev_name(dev);
 	gpiod_add_lookup_table(&yogabook_wmi_gpios);
 	data->backside_hall_gpio = devm_gpiod_get(dev, "backside_hall_sw", GPIOD_IN);
 	gpiod_remove_lookup_table(&yogabook_wmi_gpios);
@@ -352,11 +339,6 @@ static int yogabook_suspend(struct device *dev)
 	set_bit(YB_SUSPENDED, &data->flags);
 
 	flush_work(&data->work);
-
-	/* Turn off the pen button at sleep */
-	if (test_bit(YB_DIGITIZER_IS_ON, &data->flags))
-		yogabook_wmi_do_action(data, YB_PAD_DISABLE);
-
 	return 0;
 }
 
@@ -370,9 +352,6 @@ static int yogabook_resume(struct device *dev)
 		yogabook_wmi_set_kbd_backlight(data, data->brightness);
 	}
 
-	if (test_bit(YB_DIGITIZER_IS_ON, &data->flags))
-		yogabook_wmi_do_action(data, YB_PAD_ENABLE);
-
 	clear_bit(YB_SUSPENDED, &data->flags);
 
 	/* Check for YB_TABLET_MODE changes made during suspend */
Signature · 1 line
2.39.2
#11 lore raw

Re: [PATCH 09/19] platform/x86: lenovo-yogabook: Use PMIC LED driver for pen icon LED control

Quoted 14 lines · Hans de Goede

Use the (new) PMIC LED driver for pen icon LED control instead of using custom WMI calls for this.

This will also work on the Android version of the Lenovo Yoga Book 1, where there is no WMI interface for this.

The dev_id of the lookup is set using dev_name() so that it will also work for both the Windows YB1 WMI-device as well as the Android YB1 platform-device. While at it also move the gpio_lookup to using dev_name() for the dev_id.

Note this also removes the need to turn of the LED during suspend since the PMIC LED driver now already does that.

...

drivers/platform/x86/lenovo-yogabook-wmi.c static int yogabook_wmi_probe(struct wmi_device *wdev, const void *context) · line 249

Quoted 3 lines
drivers/platform/x86/lenovo-yogabook-wmi.c +3 -0
+       led_add_lookup(&yogabook_pen_led);
+       data->pen_led = devm_led_get(dev, "pen-icon-led");
+       led_remove_lookup(&yogabook_pen_led);

Wondering if we should start at some point helpers like

devm_led_get_with_table() which will do the above.

P.S. All the same probably makes sense to (ACPI) GPIO, PWM, etc calls.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#12 lore raw

PATCH 10/19 platform/x86: lenovo-yogabook: Split probe() into generic and WMI specific parts

In reply to Hans de Goede

Split probe() and remove() into generic and WMI specific parts.

This is a preparation patch for making lenovo-yogabook-wmi also work on the Android version of the Yoga Book 1 which does not have a WMI interface to deal with toggling the keyboard half between touch-keyboard and wacom-digitizer mode.

---
 drivers/platform/x86/lenovo-yogabook-wmi.c | 98 +++++++++++++---------
 1 file changed, 59 insertions(+), 39 deletions(-)
drivers/platform/x86/lenovo-yogabook-wmi.c +59 -39
index c5d103099ea9..4bcbf0f84732 100644
@@ -200,16 +200,11 @@ static struct led_lookup_data yogabook_pen_led = {
 	.con_id = "pen-icon-led",
 };
 
-static int yogabook_wmi_probe(struct wmi_device *wdev, const void *context)
+static int yogabook_probe(struct device *dev, struct yogabook_wmi *data,
+			  const char *kbd_bl_led_name)
 {
-	struct device *dev = &wdev->dev;
-	struct yogabook_wmi *data;
 	int r;
 
-	data = devm_kzalloc(dev, sizeof(struct yogabook_wmi), GFP_KERNEL);
-	if (data == NULL)
-		return -ENOMEM;
-
 	dev_set_drvdata(dev, data);
 
 	data->dev = dev;
@@ -218,31 +213,6 @@ static int yogabook_wmi_probe(struct wmi_device *wdev, const void *context)
 	set_bit(YB_DIGITIZER_IS_ON, &data->flags);
 	INIT_WORK(&data->work, yogabook_wmi_work);
 
-	data->kbd_adev = acpi_dev_get_first_match_dev("GDIX1001", NULL, -1);
-	if (!data->kbd_adev) {
-		dev_err(dev, "Cannot find the touchpad device in ACPI tables\n");
-		return -ENODEV;
-	}
-
-	data->dig_adev = acpi_dev_get_first_match_dev("WCOM0019", NULL, -1);
-	if (!data->dig_adev) {
-		dev_err(dev, "Cannot find the digitizer device in ACPI tables\n");
-		r = -ENODEV;
-		goto error_put_devs;
-	}
-
-	data->kbd_dev = get_device(acpi_get_first_physical_node(data->kbd_adev));
-	if (!data->kbd_dev || !data->kbd_dev->driver) {
-		r = -EPROBE_DEFER;
-		goto error_put_devs;
-	}
-
-	data->dig_dev = get_device(acpi_get_first_physical_node(data->dig_adev));
-	if (!data->dig_dev || !data->dig_dev->driver) {
-		r = -EPROBE_DEFER;
-		goto error_put_devs;
-	}
-
 	yogabook_pen_led.dev_id = dev_name(dev);
 	led_add_lookup(&yogabook_pen_led);
 	data->pen_led = devm_led_get(dev, "pen-icon-led");
@@ -251,7 +221,7 @@ static int yogabook_wmi_probe(struct wmi_device *wdev, const void *context)
 	if (IS_ERR(data->pen_led)) {
 		r = PTR_ERR(data->pen_led);
 		dev_err_probe(dev, r, "Getting pen icon LED\n");
-		goto error_put_devs;
+		return r;
 	}
 
 	yogabook_wmi_gpios.dev_id = dev_name(dev);
@@ -262,13 +232,13 @@ static int yogabook_wmi_probe(struct wmi_device *wdev, const void *context)
 	if (IS_ERR(data->backside_hall_gpio)) {
 		r = PTR_ERR(data->backside_hall_gpio);
 		dev_err_probe(dev, r, "Getting backside_hall_sw GPIO\n");
-		goto error_put_devs;
+		return r;
 	}
 
 	r = gpiod_to_irq(data->backside_hall_gpio);
 	if (r < 0) {
 		dev_err_probe(dev, r, "Getting backside_hall_sw IRQ\n");
-		goto error_put_devs;
+		return r;
 	}
 	data->backside_hall_irq = r;
 
@@ -280,12 +250,12 @@ static int yogabook_wmi_probe(struct wmi_device *wdev, const void *context)
 			"backside_hall_sw", data);
 	if (r) {
 		dev_err_probe(dev, r, "Requesting backside_hall_sw IRQ\n");
-		goto error_put_devs;
+		return r;
 	}
 
 	schedule_work(&data->work);
 
-	data->kbd_bl_led.name = "ybwmi::kbd_backlight";
+	data->kbd_bl_led.name = kbd_bl_led_name;
 	data->kbd_bl_led.brightness_set_blocking = kbd_brightness_set;
 	data->kbd_bl_led.brightness_get = kbd_brightness_get;
 	data->kbd_bl_led.max_brightness = 255;
@@ -301,6 +271,50 @@ static int yogabook_wmi_probe(struct wmi_device *wdev, const void *context)
 error_free_irq:
 	free_irq(data->backside_hall_irq, data);
 	cancel_work_sync(&data->work);
+	return r;
+}
+
+static int yogabook_wmi_probe(struct wmi_device *wdev, const void *context)
+{
+	struct device *dev = &wdev->dev;
+	struct yogabook_wmi *data;
+	int r;
+
+	data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL);
+	if (data == NULL)
+		return -ENOMEM;
+
+	data->kbd_adev = acpi_dev_get_first_match_dev("GDIX1001", NULL, -1);
+	if (!data->kbd_adev) {
+		dev_err(dev, "Cannot find the touchpad device in ACPI tables\n");
+		return -ENODEV;
+	}
+
+	data->dig_adev = acpi_dev_get_first_match_dev("WCOM0019", NULL, -1);
+	if (!data->dig_adev) {
+		dev_err(dev, "Cannot find the digitizer device in ACPI tables\n");
+		r = -ENODEV;
+		goto error_put_devs;
+	}
+
+	data->kbd_dev = get_device(acpi_get_first_physical_node(data->kbd_adev));
+	if (!data->kbd_dev || !data->kbd_dev->driver) {
+		r = -EPROBE_DEFER;
+		goto error_put_devs;
+	}
+
+	data->dig_dev = get_device(acpi_get_first_physical_node(data->dig_adev));
+	if (!data->dig_dev || !data->dig_dev->driver) {
+		r = -EPROBE_DEFER;
+		goto error_put_devs;
+	}
+
+	r = yogabook_probe(dev, data, "ybwmi::kbd_backlight");
+	if (r)
+		goto error_put_devs;
+
+	return 0;
+
 error_put_devs:
 	put_device(data->dig_dev);
 	put_device(data->kbd_dev);
@@ -309,9 +323,8 @@ static int yogabook_wmi_probe(struct wmi_device *wdev, const void *context)
 	return r;
 }
 
-static void yogabook_wmi_remove(struct wmi_device *wdev)
+static void yogabook_remove(struct yogabook_wmi *data)
 {
-	struct yogabook_wmi *data = dev_get_drvdata(&wdev->dev);
 	int r = 0;
 
 	free_irq(data->backside_hall_irq, data);
@@ -325,6 +338,13 @@ static void yogabook_wmi_remove(struct wmi_device *wdev)
 
 	if (r)
 		dev_warn(data->dev, "Reprobe of devices failed\n");
+}
+
+static void yogabook_wmi_remove(struct wmi_device *wdev)
+{
+	struct yogabook_wmi *data = dev_get_drvdata(&wdev->dev);
+
+	yogabook_remove(data);
 
 	put_device(data->dig_dev);
 	put_device(data->kbd_dev);
Signature · 1 line
2.39.2
#13 lore raw

Re: [PATCH 10/19] platform/x86: lenovo-yogabook: Split probe() into generic and WMI specific parts

Quoted 15 lines · Hans de Goede

Split probe() and remove() into generic and WMI specific parts.

This is a preparation patch for making lenovo-yogabook-wmi also work on the Android version of the Yoga Book 1 which does not have a WMI interface to deal with toggling the keyboard half between touch-keyboard and wacom-digitizer mode.

        if (IS_ERR(data->pen_led)) {
                r = PTR_ERR(data->pen_led);
                dev_err_probe(dev, r, "Getting pen icon LED\n");

drivers/platform/x86/lenovo-yogabook-wmi.c static int yogabook_wmi_probe(struct wmi_device *wdev, const void *context) · line 225

Quoted 3 lines
drivers/platform/x86/lenovo-yogabook-wmi.c +1 -1
-               goto error_put_devs;
+               return r;
        }

At the same time you may

return dev_err_probe(PTR_ERR());

Same to the rest of the modified places like this.

...

drivers/platform/x86/lenovo-yogabook-wmi.c static int yogabook_wmi_probe(struct wmi_device *wdev, const void *context) · line 290

Quoted 4 lines
drivers/platform/x86/lenovo-yogabook-wmi.c +4 -0
+       data->kbd_adev = acpi_dev_get_first_match_dev("GDIX1001", NULL, -1);
+       if (!data->kbd_adev) {
+               dev_err(dev, "Cannot find the touchpad device in ACPI tables\n");
+               return -ENODEV;

return dev_err_probe();

drivers/platform/x86/lenovo-yogabook-wmi.c static int yogabook_wmi_probe(struct wmi_device *wdev, const void *context) · line 296

Quoted 6 lines
drivers/platform/x86/lenovo-yogabook-wmi.c +6 -0
+       }
+
+       data->dig_adev = acpi_dev_get_first_match_dev("WCOM0019", NULL, -1);
+       if (!data->dig_adev) {
+               dev_err(dev, "Cannot find the digitizer device in ACPI tables\n");
+               r = -ENODEV;

r = dev_err_probe(); ?

Quoted 2 lines
(quoted diff) +2 -0
+               goto error_put_devs;
+       }
Signature · 2 lines
With Best Regards,
Andy Shevchenko
#14 lore raw

PATCH 11/19 platform/x86: lenovo-yogabook: Stop checking adev->power.state

In reply to Hans de Goede

lenovo-yogabook-wmi: controls the power-state itself and stores this in data->flags so there is no need to poke inside ACPI device internals.

This is a preparation patch for making lenovo-yogabook-wmi also work on the Android version of the Yoga Book 1 which does not have a WMI interface to deal with toggling the keyboard half between touch-keyboard and wacom-digitizer mode.

---
 drivers/platform/x86/lenovo-yogabook-wmi.c | 15 +++++----------
 1 file changed, 5 insertions(+), 10 deletions(-)
drivers/platform/x86/lenovo-yogabook-wmi.c +5 -10
index 4bcbf0f84732..8d461fb8eac3 100644
@@ -51,13 +51,11 @@ static int yogabook_wmi_set_kbd_backlight(struct yogabook_wmi *data,
 	union acpi_object param;
 	acpi_status status;
 
-	if (data->kbd_adev->power.state != ACPI_STATE_D0) {
-		dev_warn(data->dev, "keyboard touchscreen not in D0, cannot set brightness\n");
-		return -ENXIO;
-	}
-
 	dev_dbg(data->dev, "Set KBLC level to %u\n", level);
 
+	/* Ensure keyboard touchpad is on before we call KBLC() */
+	acpi_device_set_power(data->kbd_adev, ACPI_STATE_D0);
+
 	input.count = 1;
 	input.pointer = &param;
 
@@ -182,7 +180,7 @@ static int kbd_brightness_set(struct led_classdev *cdev,
 
 	data->brightness = value;
 
-	if (data->kbd_adev->power.state != ACPI_STATE_D0)
+	if (!test_bit(YB_KBD_IS_ON, &data->flags))
 		return 0;
 
 	return yogabook_wmi_set_kbd_backlight(data, data->brightness);
@@ -366,11 +364,8 @@ static int yogabook_resume(struct device *dev)
 {
 	struct yogabook_wmi *data = dev_get_drvdata(dev);
 
-	if (test_bit(YB_KBD_IS_ON, &data->flags)) {
-		/* Ensure keyboard touchpad is on before we call KBLC() */
-		acpi_device_set_power(data->kbd_adev, ACPI_STATE_D0);
+	if (test_bit(YB_KBD_IS_ON, &data->flags))
 		yogabook_wmi_set_kbd_backlight(data, data->brightness);
-	}
 
 	clear_bit(YB_SUSPENDED, &data->flags);
 
Signature · 1 line
2.39.2
#15 lore raw

PATCH 12/19 platform/x86: lenovo-yogabook: Abstract kbd backlight setting

In reply to Hans de Goede

Abstract kbd backlight setting. While at it also replace the ugly uint8_t type with u8.

This is a preparation patch for making lenovo-yogabook-wmi also work on the Android version of the Yoga Book 1 which does not have a WMI interface to deal with toggling the keyboard half between touch-keyboard and wacom-digitizer mode.

---
 drivers/platform/x86/lenovo-yogabook-wmi.c | 18 ++++++++++--------
 1 file changed, 10 insertions(+), 8 deletions(-)
drivers/platform/x86/lenovo-yogabook-wmi.c +10 -8
index 8d461fb8eac3..efdb20bfe8f5 100644
@@ -32,19 +32,19 @@ struct yogabook_wmi {
 	struct device *dig_dev;
 	struct led_classdev *pen_led;
 	struct gpio_desc *backside_hall_gpio;
+	int (*set_kbd_backlight)(struct yogabook_wmi *data, u8 level);
 	int backside_hall_irq;
 	struct work_struct work;
 	struct led_classdev kbd_bl_led;
 	unsigned long flags;
-	uint8_t brightness;
+	u8 brightness;
 };
 
 /*
  * To control keyboard backlight, call the method KBLC() of the TCS1 ACPI
  * device (Goodix touchpad acts as virtual sensor keyboard).
  */
-static int yogabook_wmi_set_kbd_backlight(struct yogabook_wmi *data,
-					  uint8_t level)
+static int yogabook_wmi_set_kbd_backlight(struct yogabook_wmi *data, u8 level)
 {
 	struct acpi_buffer output = { ACPI_ALLOCATE_BUFFER, NULL };
 	struct acpi_object_list input;
@@ -98,7 +98,7 @@ static void yogabook_wmi_work(struct work_struct *work)
 		 * Must be done before releasing the keyboard touchscreen driver,
 		 * so that the keyboard touchscreen dev is still in D0.
 		 */
-		yogabook_wmi_set_kbd_backlight(data, 0);
+		data->set_kbd_backlight(data, 0);
 		device_release_driver(data->kbd_dev);
 		clear_bit(YB_KBD_IS_ON, &data->flags);
 	}
@@ -114,7 +114,7 @@ static void yogabook_wmi_work(struct work_struct *work)
 		if (r)
 			dev_warn(data->dev, "Reprobe of keyboard touchscreen failed: %d\n", r);
 
-		yogabook_wmi_set_kbd_backlight(data, data->brightness);
+		data->set_kbd_backlight(data, data->brightness);
 		set_bit(YB_KBD_IS_ON, &data->flags);
 	}
 
@@ -183,7 +183,7 @@ static int kbd_brightness_set(struct led_classdev *cdev,
 	if (!test_bit(YB_KBD_IS_ON, &data->flags))
 		return 0;
 
-	return yogabook_wmi_set_kbd_backlight(data, data->brightness);
+	return data->set_kbd_backlight(data, data->brightness);
 }
 
 static struct gpiod_lookup_table yogabook_wmi_gpios = {
@@ -241,7 +241,7 @@ static int yogabook_probe(struct device *dev, struct yogabook_wmi *data,
 	data->backside_hall_irq = r;
 
 	/* Set default brightness before enabling the IRQ */
-	yogabook_wmi_set_kbd_backlight(data, YB_KBD_BL_DEFAULT);
+	data->set_kbd_backlight(data, YB_KBD_BL_DEFAULT);
 
 	r = request_irq(data->backside_hall_irq, yogabook_backside_hall_irq,
 			IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING,
@@ -307,6 +307,8 @@ static int yogabook_wmi_probe(struct wmi_device *wdev, const void *context)
 		goto error_put_devs;
 	}
 
+	data->set_kbd_backlight = yogabook_wmi_set_kbd_backlight;
+
 	r = yogabook_probe(dev, data, "ybwmi::kbd_backlight");
 	if (r)
 		goto error_put_devs;
@@ -365,7 +367,7 @@ static int yogabook_resume(struct device *dev)
 	struct yogabook_wmi *data = dev_get_drvdata(dev);
 
 	if (test_bit(YB_KBD_IS_ON, &data->flags))
-		yogabook_wmi_set_kbd_backlight(data, data->brightness);
+		data->set_kbd_backlight(data, data->brightness);
 
 	clear_bit(YB_SUSPENDED, &data->flags);
 
Signature · 1 line
2.39.2
#16 lore raw

Re: [PATCH 12/19] platform/x86: lenovo-yogabook: Abstract kbd backlight setting

Quoted 5 lines · Hans de Goede

Abstract kbd backlight setting.

While at it also replace the ugly
uint8_t type with u8.

I believe this is a fragile selling point. The more important one is do we have consistency in the code (i.e. u8 everywhere, or uint8_t everywhere)? If so, I don't see why uint8_t is ugly.

Quoted 4 lines

This is a preparation patch for making lenovo-yogabook-wmi also work on the Android version of the Yoga Book 1 which does not have a WMI interface to deal with toggling the keyboard half between touch-keyboard and wacom-digitizer mode.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#17 lore raw

PATCH 13/19 platform/x86: lenovo-yogabook: Add a yogabook_toggle_digitizer_mode() helper function

In reply to Hans de Goede

Add a yogabook_toggle_digitizer_mode() helper function.

This is a preparation patch for making lenovo-yogabook-wmi also work on the Android version of the Yoga Book 1 which does not have a WMI interface to deal with toggling the keyboard half between touch-keyboard and wacom-digitizer mode.

---
 drivers/platform/x86/lenovo-yogabook-wmi.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
drivers/platform/x86/lenovo-yogabook-wmi.c +6 -3
index efdb20bfe8f5..bbe4f2fb6fe9 100644
@@ -128,10 +128,8 @@ static void yogabook_wmi_work(struct work_struct *work)
 	}
 }
 
-static void yogabook_wmi_notify(struct wmi_device *wdev, union acpi_object *dummy)
+static void yogabook_toggle_digitizer_mode(struct yogabook_wmi *data)
 {
-	struct yogabook_wmi *data = dev_get_drvdata(&wdev->dev);
-
 	if (test_bit(YB_SUSPENDED, &data->flags))
 		return;
 
@@ -147,6 +145,11 @@ static void yogabook_wmi_notify(struct wmi_device *wdev, union acpi_object *dumm
 	schedule_work(&data->work);
 }
 
+static void yogabook_wmi_notify(struct wmi_device *wdev, union acpi_object *dummy)
+{
+	yogabook_toggle_digitizer_mode(dev_get_drvdata(&wdev->dev));
+}
+
 static irqreturn_t yogabook_backside_hall_irq(int irq, void *_data)
 {
 	struct yogabook_wmi *data = _data;
Signature · 1 line
2.39.2
#18 lore raw

PATCH 14/19 platform/x86: lenovo-yogabook: Drop _wmi_ from remaining generic symbols

In reply to Hans de Goede

Change the yogabook_wmi_ prefix of remaining generic (non WMI specific) symbols to yogabook_ .

This is a preparation patch for making lenovo-yogabook-wmi also work on the Android version of the Yoga Book 1 which does not have a WMI interface to deal with toggling the keyboard half between touch-keyboard and wacom-digitizer mode.

---
 drivers/platform/x86/lenovo-yogabook-wmi.c | 44 +++++++++++-----------
 1 file changed, 22 insertions(+), 22 deletions(-)
drivers/platform/x86/lenovo-yogabook-wmi.c +22 -22
index bbe4f2fb6fe9..9cfb2515740b 100644
@@ -24,7 +24,7 @@ enum {
 	YB_SUSPENDED,
 };
 
-struct yogabook_wmi {
+struct yogabook_data {
 	struct device *dev;
 	struct acpi_device *kbd_adev;
 	struct acpi_device *dig_adev;
@@ -32,7 +32,7 @@ struct yogabook_wmi {
 	struct device *dig_dev;
 	struct led_classdev *pen_led;
 	struct gpio_desc *backside_hall_gpio;
-	int (*set_kbd_backlight)(struct yogabook_wmi *data, u8 level);
+	int (*set_kbd_backlight)(struct yogabook_data *data, u8 level);
 	int backside_hall_irq;
 	struct work_struct work;
 	struct led_classdev kbd_bl_led;
@@ -44,7 +44,7 @@ struct yogabook_wmi {
  * To control keyboard backlight, call the method KBLC() of the TCS1 ACPI
  * device (Goodix touchpad acts as virtual sensor keyboard).
  */
-static int yogabook_wmi_set_kbd_backlight(struct yogabook_wmi *data, u8 level)
+static int yogabook_wmi_set_kbd_backlight(struct yogabook_data *data, u8 level)
 {
 	struct acpi_buffer output = { ACPI_ALLOCATE_BUFFER, NULL };
 	struct acpi_object_list input;
@@ -73,9 +73,9 @@ static int yogabook_wmi_set_kbd_backlight(struct yogabook_wmi *data, u8 level)
 	return 0;
 }
 
-static void yogabook_wmi_work(struct work_struct *work)
+static void yogabook_work(struct work_struct *work)
 {
-	struct yogabook_wmi *data = container_of(work, struct yogabook_wmi, work);
+	struct yogabook_data *data = container_of(work, struct yogabook_data, work);
 	bool kbd_on, digitizer_on;
 	int r;
 
@@ -128,7 +128,7 @@ static void yogabook_wmi_work(struct work_struct *work)
 	}
 }
 
-static void yogabook_toggle_digitizer_mode(struct yogabook_wmi *data)
+static void yogabook_toggle_digitizer_mode(struct yogabook_data *data)
 {
 	if (test_bit(YB_SUSPENDED, &data->flags))
 		return;
@@ -152,7 +152,7 @@ static void yogabook_wmi_notify(struct wmi_device *wdev, union acpi_object *dumm
 
 static irqreturn_t yogabook_backside_hall_irq(int irq, void *_data)
 {
-	struct yogabook_wmi *data = _data;
+	struct yogabook_data *data = _data;
 
 	if (gpiod_get_value(data->backside_hall_gpio))
 		set_bit(YB_TABLET_MODE, &data->flags);
@@ -166,8 +166,8 @@ static irqreturn_t yogabook_backside_hall_irq(int irq, void *_data)
 
 static enum led_brightness kbd_brightness_get(struct led_classdev *cdev)
 {
-	struct yogabook_wmi *data =
-		container_of(cdev, struct yogabook_wmi, kbd_bl_led);
+	struct yogabook_data *data =
+		container_of(cdev, struct yogabook_data, kbd_bl_led);
 
 	return data->brightness;
 }
@@ -175,8 +175,8 @@ static enum led_brightness kbd_brightness_get(struct led_classdev *cdev)
 static int kbd_brightness_set(struct led_classdev *cdev,
 			      enum led_brightness value)
 {
-	struct yogabook_wmi *data =
-		container_of(cdev, struct yogabook_wmi, kbd_bl_led);
+	struct yogabook_data *data =
+		container_of(cdev, struct yogabook_data, kbd_bl_led);
 
 	if ((value < 0) || (value > 255))
 		return -EINVAL;
@@ -189,7 +189,7 @@ static int kbd_brightness_set(struct led_classdev *cdev,
 	return data->set_kbd_backlight(data, data->brightness);
 }
 
-static struct gpiod_lookup_table yogabook_wmi_gpios = {
+static struct gpiod_lookup_table yogabook_gpios = {
 	.table = {
 		GPIO_LOOKUP("INT33FF:02", 18, "backside_hall_sw", GPIO_ACTIVE_LOW),
 		{}
@@ -201,7 +201,7 @@ static struct led_lookup_data yogabook_pen_led = {
 	.con_id = "pen-icon-led",
 };
 
-static int yogabook_probe(struct device *dev, struct yogabook_wmi *data,
+static int yogabook_probe(struct device *dev, struct yogabook_data *data,
 			  const char *kbd_bl_led_name)
 {
 	int r;
@@ -212,7 +212,7 @@ static int yogabook_probe(struct device *dev, struct yogabook_wmi *data,
 	data->brightness = YB_KBD_BL_DEFAULT;
 	set_bit(YB_KBD_IS_ON, &data->flags);
 	set_bit(YB_DIGITIZER_IS_ON, &data->flags);
-	INIT_WORK(&data->work, yogabook_wmi_work);
+	INIT_WORK(&data->work, yogabook_work);
 
 	yogabook_pen_led.dev_id = dev_name(dev);
 	led_add_lookup(&yogabook_pen_led);
@@ -225,10 +225,10 @@ static int yogabook_probe(struct device *dev, struct yogabook_wmi *data,
 		return r;
 	}
 
-	yogabook_wmi_gpios.dev_id = dev_name(dev);
-	gpiod_add_lookup_table(&yogabook_wmi_gpios);
+	yogabook_gpios.dev_id = dev_name(dev);
+	gpiod_add_lookup_table(&yogabook_gpios);
 	data->backside_hall_gpio = devm_gpiod_get(dev, "backside_hall_sw", GPIOD_IN);
-	gpiod_remove_lookup_table(&yogabook_wmi_gpios);
+	gpiod_remove_lookup_table(&yogabook_gpios);
 
 	if (IS_ERR(data->backside_hall_gpio)) {
 		r = PTR_ERR(data->backside_hall_gpio);
@@ -278,7 +278,7 @@ static int yogabook_probe(struct device *dev, struct yogabook_wmi *data,
 static int yogabook_wmi_probe(struct wmi_device *wdev, const void *context)
 {
 	struct device *dev = &wdev->dev;
-	struct yogabook_wmi *data;
+	struct yogabook_data *data;
 	int r;
 
 	data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL);
@@ -326,7 +326,7 @@ static int yogabook_wmi_probe(struct wmi_device *wdev, const void *context)
 	return r;
 }
 
-static void yogabook_remove(struct yogabook_wmi *data)
+static void yogabook_remove(struct yogabook_data *data)
 {
 	int r = 0;
 
@@ -345,7 +345,7 @@ static void yogabook_remove(struct yogabook_wmi *data)
 
 static void yogabook_wmi_remove(struct wmi_device *wdev)
 {
-	struct yogabook_wmi *data = dev_get_drvdata(&wdev->dev);
+	struct yogabook_data *data = dev_get_drvdata(&wdev->dev);
 
 	yogabook_remove(data);
 
@@ -357,7 +357,7 @@ static void yogabook_wmi_remove(struct wmi_device *wdev)
 
 static int yogabook_suspend(struct device *dev)
 {
-	struct yogabook_wmi *data = dev_get_drvdata(dev);
+	struct yogabook_data *data = dev_get_drvdata(dev);
 
 	set_bit(YB_SUSPENDED, &data->flags);
 
@@ -367,7 +367,7 @@ static int yogabook_suspend(struct device *dev)
 
 static int yogabook_resume(struct device *dev)
 {
-	struct yogabook_wmi *data = dev_get_drvdata(dev);
+	struct yogabook_data *data = dev_get_drvdata(dev);
 
 	if (test_bit(YB_KBD_IS_ON, &data->flags))
 		data->set_kbd_backlight(data, data->brightness);
Signature · 1 line
2.39.2
#19 lore raw

Re: [PATCH 14/19] platform/x86: lenovo-yogabook: Drop _wmi_ from remaining generic symbols

Quoted 8 lines · Hans de Goede

Change the yogabook_wmi_ prefix of remaining generic (non WMI specific) symbols to yogabook_ .

This is a preparation patch for making lenovo-yogabook-wmi also work on the Android version of the Yoga Book 1 which does not have a WMI interface to deal with toggling the keyboard half between touch-keyboard and wacom-digitizer mode.

...

Quoted 4 lines
drivers/platform/x86/lenovo-yogabook-wmi.c +2 -2
-       struct yogabook_wmi *data =
-               container_of(cdev, struct yogabook_wmi, kbd_bl_led);
+       struct yogabook_data *data =
+               container_of(cdev, struct yogabook_data, kbd_bl_led);

...

drivers/platform/x86/lenovo-yogabook-wmi.c static irqreturn_t yogabook_backside_hall_irq(int irq, void *_data) · line 170

Quoted 4 lines
drivers/platform/x86/lenovo-yogabook-wmi.c +2 -2
-       struct yogabook_wmi *data =
-               container_of(cdev, struct yogabook_wmi, kbd_bl_led);
+       struct yogabook_data *data =
+               container_of(cdev, struct yogabook_data, kbd_bl_led);

Perhaps a helper as many other drivers do?

#define ... container_of()

or even static inline. Also consider constification of the data passed here and there (if it makes sense).

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#20 lore raw

PATCH 15/19 platform/x86: lenovo-yogabook: Group WMI specific code together

In reply to Hans de Goede

Group WMI specific code together. Note this just moves a bunch of code-blocks around, not a single line is changed.

This is a preparation patch for making lenovo-yogabook-wmi also work on the Android version of the Yoga Book 1 which does not have a WMI interface to deal with toggling the keyboard half between touch-keyboard and wacom-digitizer mode.

---
 drivers/platform/x86/lenovo-yogabook-wmi.c | 160 ++++++++++-----------
 1 file changed, 80 insertions(+), 80 deletions(-)
drivers/platform/x86/lenovo-yogabook-wmi.c +80 -80
index 9cfb2515740b..cc280ec80b8c 100644
@@ -40,39 +40,6 @@ struct yogabook_data {
 	u8 brightness;
 };
 
-/*
- * To control keyboard backlight, call the method KBLC() of the TCS1 ACPI
- * device (Goodix touchpad acts as virtual sensor keyboard).
- */
-static int yogabook_wmi_set_kbd_backlight(struct yogabook_data *data, u8 level)
-{
-	struct acpi_buffer output = { ACPI_ALLOCATE_BUFFER, NULL };
-	struct acpi_object_list input;
-	union acpi_object param;
-	acpi_status status;
-
-	dev_dbg(data->dev, "Set KBLC level to %u\n", level);
-
-	/* Ensure keyboard touchpad is on before we call KBLC() */
-	acpi_device_set_power(data->kbd_adev, ACPI_STATE_D0);
-
-	input.count = 1;
-	input.pointer = &param;
-
-	param.type = ACPI_TYPE_INTEGER;
-	param.integer.value = 255 - level;
-
-	status = acpi_evaluate_object(acpi_device_handle(data->kbd_adev), "KBLC",
-				      &input, &output);
-	if (ACPI_FAILURE(status)) {
-		dev_err(data->dev, "Failed to call KBLC method: 0x%x\n", status);
-		return status;
-	}
-
-	kfree(output.pointer);
-	return 0;
-}
-
 static void yogabook_work(struct work_struct *work)
 {
 	struct yogabook_data *data = container_of(work, struct yogabook_data, work);
@@ -145,11 +112,6 @@ static void yogabook_toggle_digitizer_mode(struct yogabook_data *data)
 	schedule_work(&data->work);
 }
 
-static void yogabook_wmi_notify(struct wmi_device *wdev, union acpi_object *dummy)
-{
-	yogabook_toggle_digitizer_mode(dev_get_drvdata(&wdev->dev));
-}
-
 static irqreturn_t yogabook_backside_hall_irq(int irq, void *_data)
 {
 	struct yogabook_data *data = _data;
@@ -275,6 +237,83 @@ static int yogabook_probe(struct device *dev, struct yogabook_data *data,
 	return r;
 }
 
+static void yogabook_remove(struct yogabook_data *data)
+{
+	int r = 0;
+
+	free_irq(data->backside_hall_irq, data);
+	cancel_work_sync(&data->work);
+
+	if (!test_bit(YB_KBD_IS_ON, &data->flags))
+		r |= device_reprobe(data->kbd_dev);
+
+	if (!test_bit(YB_DIGITIZER_IS_ON, &data->flags))
+		r |= device_reprobe(data->dig_dev);
+
+	if (r)
+		dev_warn(data->dev, "Reprobe of devices failed\n");
+}
+
+static int yogabook_suspend(struct device *dev)
+{
+	struct yogabook_data *data = dev_get_drvdata(dev);
+
+	set_bit(YB_SUSPENDED, &data->flags);
+
+	flush_work(&data->work);
+	return 0;
+}
+
+static int yogabook_resume(struct device *dev)
+{
+	struct yogabook_data *data = dev_get_drvdata(dev);
+
+	if (test_bit(YB_KBD_IS_ON, &data->flags))
+		data->set_kbd_backlight(data, data->brightness);
+
+	clear_bit(YB_SUSPENDED, &data->flags);
+
+	/* Check for YB_TABLET_MODE changes made during suspend */
+	schedule_work(&data->work);
+
+	return 0;
+}
+
+static DEFINE_SIMPLE_DEV_PM_OPS(yogabook_pm_ops, yogabook_suspend, yogabook_resume);
+
+/*
+ * To control keyboard backlight, call the method KBLC() of the TCS1 ACPI
+ * device (Goodix touchpad acts as virtual sensor keyboard).
+ */
+static int yogabook_wmi_set_kbd_backlight(struct yogabook_data *data, u8 level)
+{
+	struct acpi_buffer output = { ACPI_ALLOCATE_BUFFER, NULL };
+	struct acpi_object_list input;
+	union acpi_object param;
+	acpi_status status;
+
+	dev_dbg(data->dev, "Set KBLC level to %u\n", level);
+
+	/* Ensure keyboard touchpad is on before we call KBLC() */
+	acpi_device_set_power(data->kbd_adev, ACPI_STATE_D0);
+
+	input.count = 1;
+	input.pointer = &param;
+
+	param.type = ACPI_TYPE_INTEGER;
+	param.integer.value = 255 - level;
+
+	status = acpi_evaluate_object(acpi_device_handle(data->kbd_adev), "KBLC",
+				      &input, &output);
+	if (ACPI_FAILURE(status)) {
+		dev_err(data->dev, "Failed to call KBLC method: 0x%x\n", status);
+		return status;
+	}
+
+	kfree(output.pointer);
+	return 0;
+}
+
 static int yogabook_wmi_probe(struct wmi_device *wdev, const void *context)
 {
 	struct device *dev = &wdev->dev;
@@ -326,23 +365,6 @@ static int yogabook_wmi_probe(struct wmi_device *wdev, const void *context)
 	return r;
 }
 
-static void yogabook_remove(struct yogabook_data *data)
-{
-	int r = 0;
-
-	free_irq(data->backside_hall_irq, data);
-	cancel_work_sync(&data->work);
-
-	if (!test_bit(YB_KBD_IS_ON, &data->flags))
-		r |= device_reprobe(data->kbd_dev);
-
-	if (!test_bit(YB_DIGITIZER_IS_ON, &data->flags))
-		r |= device_reprobe(data->dig_dev);
-
-	if (r)
-		dev_warn(data->dev, "Reprobe of devices failed\n");
-}
-
 static void yogabook_wmi_remove(struct wmi_device *wdev)
 {
 	struct yogabook_data *data = dev_get_drvdata(&wdev->dev);
@@ -355,29 +377,9 @@ static void yogabook_wmi_remove(struct wmi_device *wdev)
 	acpi_dev_put(data->kbd_adev);
 }
 
-static int yogabook_suspend(struct device *dev)
-{
-	struct yogabook_data *data = dev_get_drvdata(dev);
-
-	set_bit(YB_SUSPENDED, &data->flags);
-
-	flush_work(&data->work);
-	return 0;
-}
-
-static int yogabook_resume(struct device *dev)
+static void yogabook_wmi_notify(struct wmi_device *wdev, union acpi_object *dummy)
 {
-	struct yogabook_data *data = dev_get_drvdata(dev);
-
-	if (test_bit(YB_KBD_IS_ON, &data->flags))
-		data->set_kbd_backlight(data, data->brightness);
-
-	clear_bit(YB_SUSPENDED, &data->flags);
-
-	/* Check for YB_TABLET_MODE changes made during suspend */
-	schedule_work(&data->work);
-
-	return 0;
+	yogabook_toggle_digitizer_mode(dev_get_drvdata(&wdev->dev));
 }
 
 static const struct wmi_device_id yogabook_wmi_id_table[] = {
@@ -386,8 +388,7 @@ static const struct wmi_device_id yogabook_wmi_id_table[] = {
 	},
 	{ } /* Terminating entry */
 };
-
-static DEFINE_SIMPLE_DEV_PM_OPS(yogabook_pm_ops, yogabook_suspend, yogabook_resume);
+MODULE_DEVICE_TABLE(wmi, yogabook_wmi_id_table);
 
 static struct wmi_driver yogabook_wmi_driver = {
 	.driver = {
@@ -402,7 +403,6 @@ static struct wmi_driver yogabook_wmi_driver = {
 };
 module_wmi_driver(yogabook_wmi_driver);
 
-MODULE_DEVICE_TABLE(wmi, yogabook_wmi_id_table);
 MODULE_AUTHOR("Yauhen Kharuzhy");
 MODULE_DESCRIPTION("Lenovo Yoga Book WMI driver");
 MODULE_LICENSE("GPL v2");
Signature · 1 line
2.39.2
#21 lore raw

PATCH 16/19 platform/x86: lenovo-yogabook: Add YB_KBD_BL_MAX define

In reply to Hans de Goede

Add a define for the max brightness level instead of hardcoding this to 255 in multiple places.

---
 drivers/platform/x86/lenovo-yogabook-wmi.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
drivers/platform/x86/lenovo-yogabook-wmi.c +5 -4
index cc280ec80b8c..0c5475127ac2 100644
@@ -13,7 +13,8 @@
 
 #define YB_MBTN_EVENT_GUID	"243FEC1D-1963-41C1-8100-06A9D82A94B4"
 
-#define YB_KBD_BL_DEFAULT 128
+#define YB_KBD_BL_DEFAULT	128
+#define YB_KBD_BL_MAX		255
 
 /* flags */
 enum {
@@ -140,7 +141,7 @@ static int kbd_brightness_set(struct led_classdev *cdev,
 	struct yogabook_data *data =
 		container_of(cdev, struct yogabook_data, kbd_bl_led);
 
-	if ((value < 0) || (value > 255))
+	if ((value < 0) || (value > YB_KBD_BL_MAX))
 		return -EINVAL;
 
 	data->brightness = value;
@@ -221,7 +222,7 @@ static int yogabook_probe(struct device *dev, struct yogabook_data *data,
 	data->kbd_bl_led.name = kbd_bl_led_name;
 	data->kbd_bl_led.brightness_set_blocking = kbd_brightness_set;
 	data->kbd_bl_led.brightness_get = kbd_brightness_get;
-	data->kbd_bl_led.max_brightness = 255;
+	data->kbd_bl_led.max_brightness = YB_KBD_BL_MAX;
 
 	r = devm_led_classdev_register(dev, &data->kbd_bl_led);
 	if (r < 0) {
@@ -301,7 +302,7 @@ static int yogabook_wmi_set_kbd_backlight(struct yogabook_data *data, u8 level)
 	input.pointer = &param;
 
 	param.type = ACPI_TYPE_INTEGER;
-	param.integer.value = 255 - level;
+	param.integer.value = YB_KBD_BL_MAX - level;
 
 	status = acpi_evaluate_object(acpi_device_handle(data->kbd_adev), "KBLC",
 				      &input, &output);
Signature · 1 line
2.39.2
#22 lore raw

PATCH 17/19 platform/x86: lenovo-yogabook: Add platform driver support

In reply to Hans de Goede

The Lenovo Yoga Book 1 comes in 2 versions.

Version 1: The yb1-x91f/l currently supported by lenovo-yogabook-wmi, which has a WMI interface to deal with toggling the keyboard half between touch-keyboard and wacom-digitizer mode.

Version 2: The yb1-x90f/l which is the same hardware shipping with Android as factory OS. This version has a very different BIOS and ACPI tables which lack the WMI interface.

Instead the x86-android-tablets.ko code which does devices instantiation for devices missing from ACPI on various x86 Android tablets will instantiate a platform device for the keyboard half touch-kbd/digitizer toggle functionality.

This patch adds a platform driver to the lenovo-yogabook code which binds to the platform device instantiated by x86-android-tablets.ko offering touch-kbd/digitizer toggle functionality on the Android model.

---
 drivers/platform/x86/lenovo-yogabook-wmi.c | 160 ++++++++++++++++++++-
 1 file changed, 156 insertions(+), 4 deletions(-)
drivers/platform/x86/lenovo-yogabook-wmi.c +156 -4
index 0c5475127ac2..afb11d25abc8 100644
@@ -1,13 +1,25 @@
 // SPDX-License-Identifier: GPL-2.0
-/* WMI driver for Lenovo Yoga Book YB1-X90* / -X91* tablets */
+/*
+ * Platform driver for Lenovo Yoga Book YB1-X90F/L tablets (Android model)
+ * WMI driver for Lenovo Yoga Book YB1-X91F/L tablets (Windows model)
+ *
+ * The keyboard half of the YB1 models can function as both a capactive touch
+ * keyboard or as a Wacom digitizer, but not at the same time.
+ *
+ * This driver takes care of switching between the 2 functions.
+ *
+ * Copyright 2023 Hans de Goede <[email protected]>
+ */
 
 #include <linux/acpi.h>
 #include <linux/devm-helpers.h>
 #include <linux/gpio/consumer.h>
 #include <linux/gpio/machine.h>
+#include <linux/i2c.h>
 #include <linux/interrupt.h>
-#include <linux/module.h>
 #include <linux/leds.h>
+#include <linux/module.h>
+#include <linux/platform_device.h>
 #include <linux/wmi.h>
 #include <linux/workqueue.h>
 
@@ -16,6 +28,8 @@
 #define YB_KBD_BL_DEFAULT	128
 #define YB_KBD_BL_MAX		255
 
+#define YB_PDEV_NAME		"yogabook-touch-kbd-digitizer-switch"
+
 /* flags */
 enum {
 	YB_KBD_IS_ON,
@@ -32,8 +46,11 @@ struct yogabook_data {
 	struct device *kbd_dev;
 	struct device *dig_dev;
 	struct led_classdev *pen_led;
+	struct gpio_desc *pen_touch_event;
+	struct gpio_desc *kbd_bl_led_enable;
 	struct gpio_desc *backside_hall_gpio;
 	int (*set_kbd_backlight)(struct yogabook_data *data, u8 level);
+	int pen_touch_irq;
 	int backside_hall_irq;
 	struct work_struct work;
 	struct led_classdev kbd_bl_led;
@@ -282,6 +299,8 @@ static int yogabook_resume(struct device *dev)
 
 static DEFINE_SIMPLE_DEV_PM_OPS(yogabook_pm_ops, yogabook_suspend, yogabook_resume);
 
+/********** WMI driver code **********/
+
 /*
  * To control keyboard backlight, call the method KBLC() of the TCS1 ACPI
  * device (Goodix touchpad acts as virtual sensor keyboard).
@@ -402,8 +421,141 @@ static struct wmi_driver yogabook_wmi_driver = {
 	.remove = yogabook_wmi_remove,
 	.notify = yogabook_wmi_notify,
 };
-module_wmi_driver(yogabook_wmi_driver);
 
+/********** platform driver code **********/
+
+static struct gpiod_lookup_table yogabook_pdev_gpios = {
+	.dev_id = YB_PDEV_NAME,
+	.table = {
+		GPIO_LOOKUP("INT33FF:00", 95, "pen_touch_event", GPIO_ACTIVE_HIGH),
+		GPIO_LOOKUP("INT33FF:03", 52, "enable_keyboard_led", GPIO_ACTIVE_HIGH),
+		{}
+	},
+};
+
+static int yogabook_pdev_set_kbd_backlight(struct yogabook_data *data, u8 level)
+{
+	gpiod_set_value(data->kbd_bl_led_enable, level ? 1 : 0);
+	return 0;
+}
+
+static irqreturn_t yogabook_pen_touch_irq(int irq, void *data)
+{
+	yogabook_toggle_digitizer_mode(data);
+	return IRQ_HANDLED;
+}
+
+static int yogabook_pdev_probe(struct platform_device *pdev)
+{
+	struct device *dev = &pdev->dev;
+	struct yogabook_data *data;
+	int r;
+
+	data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL);
+	if (data == NULL)
+		return -ENOMEM;
+
+	data->kbd_dev = bus_find_device_by_name(&i2c_bus_type, NULL, "i2c-goodix_ts");
+	if (!data->kbd_dev || !data->kbd_dev->driver) {
+		r = -EPROBE_DEFER;
+		goto error_put_devs;
+	}
+
+	data->dig_dev = bus_find_device_by_name(&i2c_bus_type, NULL, "i2c-wacom");
+	if (!data->dig_dev || !data->dig_dev->driver) {
+		r = -EPROBE_DEFER;
+		goto error_put_devs;
+	}
+
+	gpiod_add_lookup_table(&yogabook_pdev_gpios);
+	data->pen_touch_event = devm_gpiod_get(dev, "pen_touch_event", GPIOD_IN);
+	data->kbd_bl_led_enable = devm_gpiod_get(dev, "enable_keyboard_led", GPIOD_OUT_HIGH);
+	gpiod_remove_lookup_table(&yogabook_pdev_gpios);
+
+	if (IS_ERR(data->pen_touch_event)) {
+		r = PTR_ERR(data->pen_touch_event);
+		dev_err_probe(dev, r, "Getting pen_touch_event GPIO\n");
+		goto error_put_devs;
+	}
+
+	if (IS_ERR(data->kbd_bl_led_enable)) {
+		r = PTR_ERR(data->kbd_bl_led_enable);
+		dev_err_probe(dev, r, "Getting enable_keyboard_led GPIO\n");
+		goto error_put_devs;
+	}
+
+	r = gpiod_to_irq(data->pen_touch_event);
+	if (r < 0) {
+		dev_err_probe(dev, r, "Getting pen_touch_event IRQ\n");
+		return r;
+	}
+	data->pen_touch_irq = r;
+
+	r = request_irq(data->pen_touch_irq, yogabook_pen_touch_irq, IRQF_TRIGGER_FALLING,
+			"pen_touch_event", data);
+	if (r) {
+		dev_err_probe(dev, r, "Requesting backside_hall_sw IRQ\n");
+		return r;
+	}
+
+	data->set_kbd_backlight = yogabook_pdev_set_kbd_backlight;
+
+	r = yogabook_probe(dev, data, "yogabook::kbd_backlight");
+	if (r)
+		goto error_free_irq;
+
+	return 0;
+
+error_free_irq:
+	free_irq(data->pen_touch_irq, data);
+	cancel_work_sync(&data->work);
+error_put_devs:
+	put_device(data->dig_dev);
+	put_device(data->kbd_dev);
+	return r;
+}
+
+static void yogabook_pdev_remove(struct platform_device *pdev)
+{
+	struct yogabook_data *data = platform_get_drvdata(pdev);
+
+	yogabook_remove(data);
+	free_irq(data->pen_touch_irq, data);
+	cancel_work_sync(&data->work);
+	put_device(data->dig_dev);
+	put_device(data->kbd_dev);
+}
+
+static struct platform_driver yogabook_pdev_driver = {
+	.probe = yogabook_pdev_probe,
+	.remove_new = yogabook_pdev_remove,
+	.driver = {
+		.name = YB_PDEV_NAME,
+		.pm = pm_sleep_ptr(&yogabook_pm_ops),
+	},
+};
+
+static int __init yogabook_module_init(void)
+{
+	int r;
+
+	r = wmi_driver_register(&yogabook_wmi_driver);
+	if (r)
+		return r;
+
+	return platform_driver_register(&yogabook_pdev_driver);
+}
+
+static void __exit yogabook_module_exit(void)
+{
+	platform_driver_unregister(&yogabook_pdev_driver);
+	wmi_driver_unregister(&yogabook_wmi_driver);
+}
+
+module_init(yogabook_module_init);
+module_exit(yogabook_module_exit);
+
+MODULE_ALIAS("platform:" YB_PDEV_NAME);
 MODULE_AUTHOR("Yauhen Kharuzhy");
-MODULE_DESCRIPTION("Lenovo Yoga Book WMI driver");
+MODULE_DESCRIPTION("Lenovo Yoga Book driver");
 MODULE_LICENSE("GPL v2");
Signature · 1 line
2.39.2
#23 lore raw

Re: [PATCH 17/19] platform/x86: lenovo-yogabook: Add platform driver support

Quoted 19 lines · Hans de Goede

The Lenovo Yoga Book 1 comes in 2 versions.

Version 1: The yb1-x91f/l currently supported by lenovo-yogabook-wmi, which has a WMI interface to deal with toggling the keyboard half between touch-keyboard and wacom-digitizer mode.

Version 2: The yb1-x90f/l which is the same hardware shipping with Android as factory OS. This version has a very different BIOS and ACPI tables which lack the WMI interface.

Instead the x86-android-tablets.ko code which does devices instantiation for devices missing from ACPI on various x86 Android tablets will instantiate a platform device for the keyboard half touch-kbd/digitizer toggle functionality.

This patch adds a platform driver to the lenovo-yogabook code which binds to the platform device instantiated by x86-android-tablets.ko offering touch-kbd/digitizer toggle functionality on the Android model.

...

Quoted 5 lines

+/*
+ * Platform driver for Lenovo Yoga Book YB1-X90F/L tablets (Android model)
+ * WMI driver for Lenovo Yoga Book YB1-X91F/L tablets (Windows model)
+ *
+ * The keyboard half of the YB1 models can function as both a capactive touch

capacitive ?

Quoted 6 lines

+ * keyboard or as a Wacom digitizer, but not at the same time.
+ *
+ * This driver takes care of switching between the 2 functions.
+ *
+ * Copyright 2023 Hans de Goede <[email protected]>
+ */

...

Quoted 1 line

#include <linux/devm-helpers.h>

Hmm.. TIL!

...

drivers/platform/x86/lenovo-yogabook-wmi.c static struct wmi_driver yogabook_wmi_driver = { · line 477

Quoted 3 lines
drivers/platform/x86/lenovo-yogabook-wmi.c +3 -0
+       if (IS_ERR(data->pen_touch_event)) {
+               r = PTR_ERR(data->pen_touch_event);
+               dev_err_probe(dev, r, "Getting pen_touch_event GPIO\n");

Combine them

  r = dev_err_probe(...);

drivers/platform/x86/lenovo-yogabook-wmi.c static struct wmi_driver yogabook_wmi_driver = { · line 483

Quoted 6 lines
drivers/platform/x86/lenovo-yogabook-wmi.c +6 -0
+               goto error_put_devs;
+       }
+
+       if (IS_ERR(data->kbd_bl_led_enable)) {
+               r = PTR_ERR(data->kbd_bl_led_enable);
+               dev_err_probe(dev, r, "Getting enable_keyboard_led GPIO\n");

Ditto.

Quoted 2 lines
(quoted diff) +2 -0
+               goto error_put_devs;
+       }

...

drivers/platform/x86/lenovo-yogabook-wmi.c static struct wmi_driver yogabook_wmi_driver = { · line 490

Quoted 4 lines
drivers/platform/x86/lenovo-yogabook-wmi.c +4 -0
+       r = gpiod_to_irq(data->pen_touch_event);
+       if (r < 0) {
+               dev_err_probe(dev, r, "Getting pen_touch_event IRQ\n");
+               return r;

return dev_err_probe();

drivers/platform/x86/lenovo-yogabook-wmi.c static struct wmi_driver yogabook_wmi_driver = { · line 498

Quoted 8 lines
drivers/platform/x86/lenovo-yogabook-wmi.c +8 -0
+       }
+       data->pen_touch_irq = r;
+
+       r = request_irq(data->pen_touch_irq, yogabook_pen_touch_irq, IRQF_TRIGGER_FALLING,
+                       "pen_touch_event", data);
+       if (r) {
+               dev_err_probe(dev, r, "Requesting backside_hall_sw IRQ\n");
+               return r;

Ditto.

Quoted 1 line

+ }

...

Quoted 1 line

+MODULE_ALIAS("platform:" YB_PDEV_NAME);

Hmm... Do we need this?

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#24 lore raw

Re: [PATCH 17/19] platform/x86: lenovo-yogabook: Add platform driver support

Hi Andy,

Thank you for all the reviews.

I agree with all your comments and I will fix them all for version 2 of this series.

On 4/30/23 12:49, Andy Shevchenko wrote:

<snip>

Quoted 16 lines

drivers/platform/x86/lenovo-yogabook-wmi.c static struct wmi_driver yogabook_wmi_driver = { · line 490

Quoted 4 lines
drivers/platform/x86/lenovo-yogabook-wmi.c +4 -0
+       r = gpiod_to_irq(data->pen_touch_event);
+       if (r < 0) {
+               dev_err_probe(dev, r, "Getting pen_touch_event IRQ\n");
+               return r;

return dev_err_probe();

drivers/platform/x86/lenovo-yogabook-wmi.c static struct wmi_driver yogabook_wmi_driver = { · line 498

Quoted 8 lines
drivers/platform/x86/lenovo-yogabook-wmi.c +8 -0
+       }
+       data->pen_touch_irq = r;
+
+       r = request_irq(data->pen_touch_irq, yogabook_pen_touch_irq, IRQF_TRIGGER_FALLING,
+                       "pen_touch_event", data);
+       if (r) {
+               dev_err_probe(dev, r, "Requesting backside_hall_sw IRQ\n");
+               return r;
Quoted 1 line

Ditto.

Actually this block has 2 copy and paste errors:

1. The second error message
2. Both "return r;" statements need to be replaced with goto error_put_devs.

I'll fix this both for version 2.

Quoted 8 lines
Quoted 2 lines

+ }

...

Quoted 1 line

+MODULE_ALIAS("platform:" YB_PDEV_NAME);

Hmm... Do we need this?

Yes simple platform_drivers like this one typically don't have a device-id table (they simply match by name) and thus they also don't have a MODULE_DEVICE_TABLE(platform, ...); statement so they need an explicit MODULE_ALIAS to correctly auto-load.

Regards,

Hans

Quoted 1 line
#25 lore raw

PATCH 18/19 platform/x86: lenovo-yogabook: Add keyboard backlight control to platform driver

In reply to Hans de Goede

On the Android yb1-x90f/l models there is not ACPI method to control the keyboard backlight brightness. Instead the second PWM controller is exposed directly to the OS there.

Add support for controlling keyboard backlight brightness on the Android model by using the PWM subsystem to directly control the PWM.

---
 drivers/platform/x86/lenovo-yogabook-wmi.c | 26 ++++++++++++++++++++++
 1 file changed, 26 insertions(+)
drivers/platform/x86/lenovo-yogabook-wmi.c +26 -0
index afb11d25abc8..8e12a625ee65 100644
@@ -20,6 +20,7 @@
 #include <linux/leds.h>
 #include <linux/module.h>
 #include <linux/platform_device.h>
+#include <linux/pwm.h>
 #include <linux/wmi.h>
 #include <linux/workqueue.h>
 
@@ -27,6 +28,7 @@
 
 #define YB_KBD_BL_DEFAULT	128
 #define YB_KBD_BL_MAX		255
+#define YB_KBD_BL_PWM_PERIOD	13333
 
 #define YB_PDEV_NAME		"yogabook-touch-kbd-digitizer-switch"
 
@@ -49,6 +51,7 @@ struct yogabook_data {
 	struct gpio_desc *pen_touch_event;
 	struct gpio_desc *kbd_bl_led_enable;
 	struct gpio_desc *backside_hall_gpio;
+	struct pwm_device *kbd_bl_pwm;
 	int (*set_kbd_backlight)(struct yogabook_data *data, u8 level);
 	int pen_touch_irq;
 	int backside_hall_irq;
@@ -433,8 +436,21 @@ static struct gpiod_lookup_table yogabook_pdev_gpios = {
 	},
 };
 
+static struct pwm_lookup yogabook_pdev_pwm_lookup[] = {
+	PWM_LOOKUP_WITH_MODULE("80862289:00", 0, YB_PDEV_NAME,
+			       "kbd_bl_pwm", 13333, PWM_POLARITY_NORMAL,
+			       "pwm-lpss-platform"),
+};
+
 static int yogabook_pdev_set_kbd_backlight(struct yogabook_data *data, u8 level)
 {
+	struct pwm_state state = {
+		.period = YB_KBD_BL_PWM_PERIOD,
+		.duty_cycle = YB_KBD_BL_PWM_PERIOD * level / YB_KBD_BL_MAX,
+		.enabled = level,
+	};
+
+	pwm_apply_state(data->kbd_bl_pwm, &state);
 	gpiod_set_value(data->kbd_bl_led_enable, level ? 1 : 0);
 	return 0;
 }
@@ -484,6 +500,16 @@ static int yogabook_pdev_probe(struct platform_device *pdev)
 		goto error_put_devs;
 	}
 
+	pwm_add_table(yogabook_pdev_pwm_lookup, ARRAY_SIZE(yogabook_pdev_pwm_lookup));
+	data->kbd_bl_pwm = devm_pwm_get(dev, "kbd_bl_pwm");
+	pwm_remove_table(yogabook_pdev_pwm_lookup, ARRAY_SIZE(yogabook_pdev_pwm_lookup));
+
+	if (IS_ERR(data->kbd_bl_pwm)) {
+		r = PTR_ERR(data->kbd_bl_pwm);
+		dev_err_probe(dev, r, "Getting keyboard backlight PWM\n");
+		goto error_put_devs;
+	}
+
 	r = gpiod_to_irq(data->pen_touch_event);
 	if (r < 0) {
 		dev_err_probe(dev, r, "Getting pen_touch_event IRQ\n");
Signature · 1 line
2.39.2
#26 lore raw

Re: [PATCH 18/19] platform/x86: lenovo-yogabook: Add keyboard backlight control to platform driver

Quoted 7 lines · Hans de Goede

On the Android yb1-x90f/l models there is not ACPI method to control the keyboard backlight brightness. Instead the second PWM controller is exposed directly to the OS there.

Add support for controlling keyboard backlight brightness on the Android model by using the PWM subsystem to directly control the PWM.

...

Quoted 1 line

+#define YB_KBD_BL_PWM_PERIOD 13333

Defined...

drivers/platform/x86/lenovo-yogabook-wmi.c static struct gpiod_lookup_table yogabook_pdev_gpios = { · line 441

Quoted 3 lines
drivers/platform/x86/lenovo-yogabook-wmi.c +3 -0
+static struct pwm_lookup yogabook_pdev_pwm_lookup[] = {
+       PWM_LOOKUP_WITH_MODULE("80862289:00", 0, YB_PDEV_NAME,
+                              "kbd_bl_pwm", 13333, PWM_POLARITY_NORMAL,

...but not used?

Quoted 2 lines
(quoted diff) +2 -0
+                              "pwm-lpss-platform"),
+};

...

drivers/platform/x86/lenovo-yogabook-wmi.c static int yogabook_pdev_probe(struct platform_device *pdev) · line 509

Quoted 3 lines
drivers/platform/x86/lenovo-yogabook-wmi.c +3 -0
+       if (IS_ERR(data->kbd_bl_pwm)) {
+               r = PTR_ERR(data->kbd_bl_pwm);
+               dev_err_probe(dev, r, "Getting keyboard backlight PWM\n");

r = dev_err_probe();

Quoted 2 lines
drivers/platform/x86/lenovo-yogabook-wmi.c +2 -0
+               goto error_put_devs;
+       }
Signature · 2 lines
With Best Regards,
Andy Shevchenko
#27 lore raw

PATCH 19/19 platform/x86: lenovo-yogabook: Rename lenovo-yogabook-wmi to lenovo-yogabook

In reply to Hans de Goede

The lenovo-yogabook-wmi.c code now consists of both a platform and a WMI driver and it does not use WMI at all when used on the Android model.

Rename the module from lenovo-yogabook-wmi to lenovo-yogabook to reflect this.

---
 drivers/platform/x86/Kconfig                                | 6 +++---
 drivers/platform/x86/Makefile                               | 2 +-
 .../x86/{lenovo-yogabook-wmi.c => lenovo-yogabook.c}        | 0
 3 files changed, 4 insertions(+), 4 deletions(-)
 rename drivers/platform/x86/{lenovo-yogabook-wmi.c => lenovo-yogabook.c} (100%)
drivers/platform/x86/Kconfig +3 -3
index 22052031c719..2039e3246e1b 100644
@@ -121,8 +121,8 @@ config GIGABYTE_WMI
 	  To compile this driver as a module, choose M here: the module will
 	  be called gigabyte-wmi.
 
-config YOGABOOK_WMI
-	tristate "Lenovo Yoga Book tablet WMI key driver"
+config YOGABOOK
+	tristate "Lenovo Yoga Book tablet key driver"
 	depends on ACPI_WMI
 	depends on INPUT
 	select LEDS_CLASS
@@ -132,7 +132,7 @@ config YOGABOOK_WMI
 	  control on the Lenovo Yoga Book tablets.
 
 	  To compile this driver as a module, choose M here: the module will
-	  be called lenovo-yogabook-wmi.
+	  be called lenovo-yogabook.
 
 config ACERHDF
 	tristate "Acer Aspire One temperature and fan driver"
drivers/platform/x86/Makefile +1 -1
index 2cafe51ec4d8..52dfdf574ac2 100644
@@ -14,7 +14,6 @@ obj-$(CONFIG_MXM_WMI)			+= mxm-wmi.o
 obj-$(CONFIG_NVIDIA_WMI_EC_BACKLIGHT)	+= nvidia-wmi-ec-backlight.o
 obj-$(CONFIG_XIAOMI_WMI)		+= xiaomi-wmi.o
 obj-$(CONFIG_GIGABYTE_WMI)		+= gigabyte-wmi.o
-obj-$(CONFIG_YOGABOOK_WMI)		+= lenovo-yogabook-wmi.o
 
 # Acer
 obj-$(CONFIG_ACERHDF)		+= acerhdf.o
@@ -66,6 +65,7 @@ obj-$(CONFIG_LENOVO_YMC)	+= lenovo-ymc.o
 obj-$(CONFIG_SENSORS_HDAPS)	+= hdaps.o
 obj-$(CONFIG_THINKPAD_ACPI)	+= thinkpad_acpi.o
 obj-$(CONFIG_THINKPAD_LMI)	+= think-lmi.o
+obj-$(CONFIG_YOGABOOK)		+= lenovo-yogabook.o
 
 # Intel
 obj-y				+= intel/
drivers/platform/x86/lenovo-yogabook.c renamed from drivers/platform/x86/lenovo-yogabook-wmi.c +0 -0
similarity index 100%
rename from drivers/platform/x86/lenovo-yogabook-wmi.c
rename to drivers/platform/x86/lenovo-yogabook.c
Signature · 1 line
2.39.2
#28 lore raw
In reply to Hans de Goede
Quoted 17 lines · Hans de Goede

Hi All,

The Lenovo Yoga Book (yb1-x9*) is a yoga 2-in-1 where the keyboard half has a touch keyboard (with a backlit fixed key layout) to make it extra thin and light. The keyboard half can also be switched to an alternative wacom digitizer mode where it instead can be used to draw on. The backlight + switching is handled by
the lenovo-yogabook driver.

There are both Windows and Android versions with different BIOS-es / ACPI tables. This series extends the current Windows model only driver to also support the Android model.

On the Android yb1-x90f/l models there is not ACPI method to control the keyboard backlight brightness. Instead the second PWM controller is exposed directly to the OS there.

Quoted 8 lines

This requires adding a pwm_lookup table and the lenovo-yogabook code can (and typically is) build as a module. So the first patch in this series exports pwm_add_table() and pwm_remove_table() for use in modules.

I believe that it is easiest to just merge the entire series through the drivers/platform/x86 tree. Thierry, may I have your ack for patch 1/19 to merge it through the pdx86 tree ?

Wow, great! I thought about ACPI table substitution by one taken from the Windows tablet but didn't try this. I'm glad if this works because ACPI tables in Android version looks like as a placeholder from the Intel's SDK, not a real thing.

There is instruction how to install Windows on Android version, maybe it will be useful for you:
https://web.archive.org/web/20220516142318/https://www.poz1.com/windows-on-android-lenovo-yogabook/

Quoted 47 lines

Regards,

Hans

Hans de Goede (19):
pwm: Export pwm_add_table() / pwm_remove_table() platform/x86: lenovo-yogabook: Fix work race on remove() platform/x86: lenovo-yogabook: Reprobe devices on remove() platform/x86: lenovo-yogabook: Set default keyboard backligh
brightness on probe()
platform/x86: lenovo-yogabook: Simplify gpio lookup table cleanup platform/x86: lenovo-yogabook: Switch to DEFINE_SIMPLE_DEV_PM_OPS() platform/x86: lenovo-yogabook: Store dev instead of wdev in drvdata
struct
platform/x86: lenovo-yogabook: Add dev local variable to probe() platform/x86: lenovo-yogabook: Use PMIC LED driver for pen icon LED
control
platform/x86: lenovo-yogabook: Split probe() into generic and WMI
specific parts
platform/x86: lenovo-yogabook: Stop checking adev->power.state platform/x86: lenovo-yogabook: Abstract kbd backlight setting platform/x86: lenovo-yogabook: Add a yogabook_toggle_digitizer_mode()
helper function
platform/x86: lenovo-yogabook: Drop _wmi_ from remaining generic
symbols
platform/x86: lenovo-yogabook: Group WMI specific code together platform/x86: lenovo-yogabook: Add YB_KBD_BL_MAX define platform/x86: lenovo-yogabook: Add platform driver support platform/x86: lenovo-yogabook: Add keyboard backlight control to
platform driver
platform/x86: lenovo-yogabook: Rename lenovo-yogabook-wmi to
lenovo-yogabook

 drivers/platform/x86/Kconfig               |   6 +-
 drivers/platform/x86/Makefile              |   2 +-
 drivers/platform/x86/lenovo-yogabook-wmi.c | 408 --------------
 drivers/platform/x86/lenovo-yogabook.c     | 587 +++++++++++++++++++++
 drivers/pwm/core.c                         |   2 +
 5 files changed, 593 insertions(+), 412 deletions(-)
 delete mode 100644 drivers/platform/x86/lenovo-yogabook-wmi.c
 create mode 100644 drivers/platform/x86/lenovo-yogabook.c
Signature · 1 line
2.39.2
Signature · 1 line
Yauhen Kharuzhy