Skip to contentSkip to conversation

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

PATCH In review Hans de Goede 3 participants 28 messages Apr 30, 2023 – May 9, 2023

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

v2 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 ?

Changes in v2:
- Address Andy's review remarks
- Error-exit handling fixes in yogabook_pdev_probe() and yogabook_module_init()
- Explicitly turn off keyboard backlight on suspend

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     | 585 +++++++++++++++++++++
 drivers/pwm/core.c                         |   2 +
 5 files changed, 591 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 v2 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 v2 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")

---
Changes in v2:
- Drop no longer used include <linux/devm-helpers.h>

---
 drivers/platform/x86/lenovo-yogabook-wmi.c | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)
drivers/platform/x86/lenovo-yogabook-wmi.c +10 -10
index 5f4bd1eec38a..3a6de4ab74a4 100644
@@ -2,7 +2,6 @@
 /* WMI driver for Lenovo Yoga Book YB1-X90* / -X91* tablets */
 
 #include <linux/acpi.h>
-#include <linux/devm-helpers.h>
 #include <linux/gpio/consumer.h>
 #include <linux/gpio/machine.h>
 #include <linux/interrupt.h>
@@ -248,10 +247,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 +295,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 +313,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 +333,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 v2 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 3a6de4ab74a4..5948ffa74acd 100644
@@ -332,9 +332,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 v2 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 5948ffa74acd..d57fcc838851 100644
@@ -295,6 +295,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 v2 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 d57fcc838851..0b49c7a54bfc 100644
@@ -227,11 +227,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;
@@ -275,13 +270,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 v2 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 0b49c7a54bfc..2a46e19893e8 100644
@@ -346,7 +346,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);
@@ -362,7 +362,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);
@@ -391,13 +391,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 v2 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 2a46e19893e8..1bbdc48aef5b 100644
@@ -29,7 +29,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;
@@ -42,14 +42,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);
@@ -57,7 +57,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;
 	}
@@ -71,21 +71,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;
@@ -96,7 +95,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;
 	}
 
@@ -107,7 +106,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;
 
@@ -130,13 +128,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);
 	}
@@ -144,18 +142,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);
 	}
 }
@@ -206,7 +204,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;
@@ -216,7 +213,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 = {
@@ -238,7 +235,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);
@@ -287,7 +284,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,
@@ -338,7 +335,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);
@@ -348,7 +345,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);
@@ -357,24 +353,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 v2 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.

While at it also move the dev_set_drvdata() call to the end of probe().

---
Changes in v2:
- Move the dev_set_drvdata() call to the end of probe()

---
 drivers/platform/x86/lenovo-yogabook-wmi.c | 24 +++++++++++-----------
 1 file changed, 12 insertions(+), 12 deletions(-)
drivers/platform/x86/lenovo-yogabook-wmi.c +12 -12
index 1bbdc48aef5b..4f2624eba210 100644
@@ -226,16 +226,15 @@ 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);
-
-	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);
@@ -243,13 +242,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;
 	}
@@ -267,18 +266,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;
@@ -290,7 +289,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;
 	}
 
@@ -301,12 +300,13 @@ 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;
 	}
 
+	dev_set_drvdata(dev, data);
 	return 0;
 
 error_free_irq:
Signature · 1 line
2.39.2
#9 lore raw

PATCH v2 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 4f2624eba210..68057150f465 100644
@@ -11,11 +11,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
 
@@ -34,6 +29,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;
@@ -42,31 +38,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).
@@ -134,7 +105,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);
 	}
@@ -153,7 +124,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);
 	}
 }
@@ -217,13 +188,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;
@@ -265,6 +240,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);
@@ -350,11 +337,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;
 }
 
@@ -368,9 +350,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
#10 lore raw

PATCH v2 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.

---
Changes in v2:
- Use "return dev_err_probe(...);" in several places to simplify error-exits in the new yogabook_probe() function

---
 drivers/platform/x86/lenovo-yogabook-wmi.c | 118 ++++++++++++---------
 1 file changed, 65 insertions(+), 53 deletions(-)
drivers/platform/x86/lenovo-yogabook-wmi.c +65 -53
index 68057150f465..e583ae146323 100644
@@ -199,74 +199,38 @@ 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;
-
 	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);
 	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");
 	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;
-	}
+	if (IS_ERR(data->pen_led))
+		return dev_err_probe(dev, PTR_ERR(data->pen_led), "Getting pen icon LED\n");
 
 	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);
 
-	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;
-	}
+	if (IS_ERR(data->backside_hall_gpio))
+		return dev_err_probe(dev, PTR_ERR(data->backside_hall_gpio),
+				     "Getting backside_hall_sw GPIO\n");
 
 	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;
-	}
+	if (r < 0)
+		return dev_err_probe(dev, r, "Getting backside_hall_sw IRQ\n");
+
 	data->backside_hall_irq = r;
 
 	/* Set default brightness before enabling the IRQ */
@@ -275,14 +239,12 @@ static int yogabook_wmi_probe(struct wmi_device *wdev, const void *context)
 	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(dev, r, "Requesting backside_hall_sw IRQ\n");
-		goto error_put_devs;
-	}
+	if (r)
+		return dev_err_probe(dev, r, "Requesting backside_hall_sw IRQ\n");
 
 	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;
@@ -299,6 +261,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);
@@ -307,9 +313,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);
@@ -323,6 +328,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
#11 lore raw

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

Quoted 7 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.

...

Quoted 3 lines

Changes in v2:
- Use "return dev_err_probe(...);" in several places to simplify error-exits in the new yogabook_probe() function

I'm not sure you have changed previous patches where it makes sense to use dev_err_probe(). Neither it's done (in full) here (in case you wanted to split replacement to a separate change). See below.

...

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

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;

Here...

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

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;

...and here.

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

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

Hi,

Quoted 9 lines · Andy Shevchenko
Quoted 7 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.

Quoted 8 lines

...

Quoted 3 lines

Changes in v2:
- Use "return dev_err_probe(...);" in several places to simplify error-exits in the new yogabook_probe() function

I'm not sure you have changed previous patches where it makes sense to use dev_err_probe().

Actually the 2 cases you point out below are the 2 last regular dev_err() calls in the probe() path of the driver.

Quoted 12 lines

Neither it's done (in full) here (in case you wanted to split replacement to a separate change). See below.

...

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

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;

Here...

Quoted 8 lines

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

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;

...and here.

Ack I've fixed these both up while merging this series.

Regards,

Hans

#13 lore raw

PATCH v2 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 e583ae146323..7c7a945ed80d 100644
@@ -50,13 +50,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;
 
@@ -181,7 +179,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);
@@ -356,11 +354,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
#14 lore raw

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

In reply to Hans de Goede

Abstract kbd backlight setting.

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.

---
Changes in v2:
- Keep uint8_t for level / brightness values

---
 drivers/platform/x86/lenovo-yogabook-wmi.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)
drivers/platform/x86/lenovo-yogabook-wmi.c +8 -5
index 7c7a945ed80d..addc4ee457be 100644
@@ -31,6 +31,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, uint8_t level);
 	int backside_hall_irq;
 	struct work_struct work;
 	struct led_classdev kbd_bl_led;
@@ -97,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);
 	}
@@ -113,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);
 	}
 
@@ -182,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 = {
@@ -232,7 +233,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,
@@ -297,6 +298,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;
@@ -355,7 +358,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
#15 lore raw

PATCH v2 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 addc4ee457be..87bea6987681 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
#16 lore raw

PATCH v2 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.

---
Changes in v2:
- Add kbd_led_to_yogabook() macro

---
 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 87bea6987681..f1876c587757 100644
@@ -23,7 +23,7 @@ enum {
 	YB_SUSPENDED,
 };
 
-struct yogabook_wmi {
+struct yogabook_data {
 	struct device *dev;
 	struct acpi_device *kbd_adev;
 	struct acpi_device *dig_adev;
@@ -31,7 +31,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, uint8_t level);
+	int (*set_kbd_backlight)(struct yogabook_data *data, uint8_t level);
 	int backside_hall_irq;
 	struct work_struct work;
 	struct led_classdev kbd_bl_led;
@@ -43,7 +43,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,
+static int yogabook_wmi_set_kbd_backlight(struct yogabook_data *data,
 					  uint8_t level)
 {
 	struct acpi_buffer output = { ACPI_ALLOCATE_BUFFER, NULL };
@@ -73,9 +73,9 @@ static int yogabook_wmi_set_kbd_backlight(struct yogabook_wmi *data,
 	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);
@@ -164,10 +164,11 @@ static irqreturn_t yogabook_backside_hall_irq(int irq, void *_data)
 	return IRQ_HANDLED;
 }
 
+#define kbd_led_to_yogabook(cdev) container_of(cdev, struct yogabook_data, kbd_bl_led)
+
 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 = kbd_led_to_yogabook(cdev);
 
 	return data->brightness;
 }
@@ -175,8 +176,7 @@ 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 = kbd_led_to_yogabook(cdev);
 
 	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;
@@ -210,7 +210,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);
@@ -220,10 +220,10 @@ static int yogabook_probe(struct device *dev, struct yogabook_wmi *data,
 	if (IS_ERR(data->pen_led))
 		return dev_err_probe(dev, PTR_ERR(data->pen_led), "Getting pen icon LED\n");
 
-	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))
 		return dev_err_probe(dev, PTR_ERR(data->backside_hall_gpio),
@@ -269,7 +269,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);
@@ -317,7 +317,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;
 
@@ -336,7 +336,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);
 
@@ -348,7 +348,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);
 
@@ -358,7 +358,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
#17 lore raw

PATCH v2 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 | 162 ++++++++++-----------
 1 file changed, 81 insertions(+), 81 deletions(-)
drivers/platform/x86/lenovo-yogabook-wmi.c +81 -81
index f1876c587757..c0c6997b9f61 100644
@@ -39,40 +39,6 @@ struct yogabook_data {
 	uint8_t 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,
-					  uint8_t 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 +111,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;
@@ -266,6 +227,84 @@ 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,
+					  uint8_t 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;
@@ -317,23 +356,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);
@@ -346,29 +368,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[] = {
@@ -377,8 +379,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 = {
@@ -393,7 +394,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
#18 lore raw

PATCH v2 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 c0c6997b9f61..f413af41e3c0 100644
@@ -12,7 +12,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 {
@@ -139,7 +140,7 @@ static int kbd_brightness_set(struct led_classdev *cdev,
 {
 	struct yogabook_data *data = kbd_led_to_yogabook(cdev);
 
-	if ((value < 0) || (value > 255))
+	if ((value < 0) || (value > YB_KBD_BL_MAX))
 		return -EINVAL;
 
 	data->brightness = value;
@@ -210,7 +211,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) {
@@ -292,7 +293,7 @@ static int yogabook_wmi_set_kbd_backlight(struct yogabook_data *data,
 	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
#19 lore raw

PATCH v2 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.

---
Changes in v2:
- Use r = dev_err_probe(...) in various places
- Error-exit handling fixes in yogabook_pdev_probe() and yogabook_module_init()

---
 drivers/platform/x86/lenovo-yogabook-wmi.c | 164 ++++++++++++++++++++-
 1 file changed, 160 insertions(+), 4 deletions(-)
drivers/platform/x86/lenovo-yogabook-wmi.c +160 -4
index f413af41e3c0..0183b75a47e8 100644
@@ -1,12 +1,24 @@
 // 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 capacitive
+ * 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/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>
 
@@ -15,6 +27,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,
@@ -31,8 +45,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, uint8_t level);
+	int pen_touch_irq;
 	int backside_hall_irq;
 	struct work_struct work;
 	struct led_classdev kbd_bl_led;
@@ -272,6 +289,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).
@@ -393,8 +412,145 @@ 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 = dev_err_probe(dev, PTR_ERR(data->pen_touch_event),
+				  "Getting pen_touch_event GPIO\n");
+		goto error_put_devs;
+	}
+
+	if (IS_ERR(data->kbd_bl_led_enable)) {
+		r = dev_err_probe(dev, PTR_ERR(data->kbd_bl_led_enable),
+				  "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");
+		goto error_put_devs;
+	}
+	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 pen_touch_event IRQ\n");
+		goto error_put_devs;
+	}
+
+	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;
+
+	r = platform_driver_register(&yogabook_pdev_driver);
+	if (r)
+		wmi_driver_unregister(&yogabook_wmi_driver);
+
+	return r;
+}
+
+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
#20 lore raw

PATCH v2 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.

The Android model also requires explicitly turning the backlight off on suspend, which on the Windows model was done automatically.

---
Changes in v2:
- Use YB_KBD_BL_PWM_PERIOD define in yogabook_pdev_pwm_lookup[]
- Turn off keyboard backlight on suspend

---
 drivers/platform/x86/lenovo-yogabook-wmi.c | 31 +++++++++++++++++++++-
 1 file changed, 30 insertions(+), 1 deletion(-)
drivers/platform/x86/lenovo-yogabook-wmi.c +30 -1
index 0183b75a47e8..b49109d91ec3 100644
@@ -19,6 +19,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>
 
@@ -26,6 +27,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"
 
@@ -48,6 +50,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, uint8_t level);
 	int pen_touch_irq;
 	int backside_hall_irq;
@@ -267,8 +270,11 @@ 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);
+
+	if (test_bit(YB_KBD_IS_ON, &data->flags))
+		data->set_kbd_backlight(data, 0);
+
 	return 0;
 }
 
@@ -424,8 +430,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",
+			       YB_KBD_BL_PWM_PERIOD, 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;
 }
@@ -475,6 +494,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 = dev_err_probe(dev, PTR_ERR(data->kbd_bl_pwm),
+				  "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
#21 lore raw

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

Hello,

Quoted 83 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.

The Android model also requires explicitly turning the backlight off on suspend, which on the Windows model was done automatically.

---
Changes in v2:
- Use YB_KBD_BL_PWM_PERIOD define in yogabook_pdev_pwm_lookup[]
- Turn off keyboard backlight on suspend

---
 drivers/platform/x86/lenovo-yogabook-wmi.c | 31 +++++++++++++++++++++-
 1 file changed, 30 insertions(+), 1 deletion(-)
drivers/platform/x86/lenovo-yogabook-wmi.c +20 -1
index 0183b75a47e8..b49109d91ec3 100644
@@ -19,6 +19,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>
 
@@ -26,6 +27,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"
 
@@ -48,6 +50,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, uint8_t level);
 	int pen_touch_irq;
 	int backside_hall_irq;
@@ -267,8 +270,11 @@ 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);
+
+	if (test_bit(YB_KBD_IS_ON, &data->flags))
+		data->set_kbd_backlight(data, 0);
+
 	return 0;
 }
 
@@ -424,8 +430,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",
+			       YB_KBD_BL_PWM_PERIOD, 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;
 }

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

Quoted 6 lines
drivers/platform/x86/lenovo-yogabook-wmi.c +3 -0
@@ -475,6 +494,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));

Keeping the table added just long enough to call devm_pwm_get() looks very creative to me. Why don't you keep the table around while the device is available? Also note that a given table must only ever be added once using pwm_add_table(). If there happen to be two yogabook devices and .probe() is called a second time, the list of tables might be corrupted.

I don't know much about x86, but I think the table belongs to where this "80862289:00" device is created.

Best regards
Uwe

Signature · 2 lines
Pengutronix e.K.                           | Uwe Kleine-König            |
Industrial Linux Solutions                 | https://www.pengutronix.de/ |
#22 lore raw

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

Quoted 1 line · Uwe Kleine-König

On Sun, Apr 30, 2023 at 06:58:06PM +0200, Hans de Goede wrote:

...

Quoted 2 lines

I don't know much about x86, but I think the table belongs to where this "80862289:00" device is created.

Just for your information, it's in drivers/acpi/acpi_lpss.c.

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

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

Quoted 10 lines · Andy Shevchenko
Quoted 1 line · Uwe Kleine-König

On Sun, Apr 30, 2023 at 06:58:06PM +0200, Hans de Goede wrote:

...

Quoted 2 lines

I don't know much about x86, but I think the table belongs to where this "80862289:00" device is created.

Just for your information, it's in drivers/acpi/acpi_lpss.c.

Compared to drivers/platform/x86/lenovo-yogabook-wmi.c this file is never compiled as a module and so patch #1 would become unnecessary.

That file also already has a pwm_lookup table.

Best regards
Uwe

Signature · 2 lines
Pengutronix e.K.                           | Uwe Kleine-König            |
Industrial Linux Solutions                 | https://www.pengutronix.de/ |
#24 lore raw

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

Quoted 4 lines · Uwe Kleine-König
Quoted 3 lines · Andy Shevchenko
Quoted 1 line · Uwe Kleine-König

On Sun, Apr 30, 2023 at 06:58:06PM +0200, Hans de Goede wrote:

...

Quoted 9 lines
Quoted 4 lines
Quoted 2 lines

I don't know much about x86, but I think the table belongs to where this "80862289:00" device is created.

Just for your information, it's in drivers/acpi/acpi_lpss.c.

Compared to drivers/platform/x86/lenovo-yogabook-wmi.c this file is never compiled as a module and so patch #1 would become unnecessary.

That file also already has a pwm_lookup table.

TBH, Hans knows nowadays much better what those drivers do and why the split was done this way. If he thinks that it's needed, I will trust his word.

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

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

In reply to Uwe Kleine-König

Hi Uwe, Andy,

Quoted 10 lines · Uwe Kleine-König
Quoted 9 lines · Andy Shevchenko
Quoted 1 line · Uwe Kleine-König

On Sun, Apr 30, 2023 at 06:58:06PM +0200, Hans de Goede wrote:

...

Quoted 2 lines

I don't know much about x86, but I think the table belongs to where this "80862289:00" device is created.

Quoted 6 lines
Quoted 1 line

Just for your information, it's in drivers/acpi/acpi_lpss.c.

Compared to drivers/platform/x86/lenovo-yogabook-wmi.c this file is never compiled as a module and so patch #1 would become unnecessary.

That file also already has a pwm_lookup table.

Right, the Cherry Trail SoCs in question have 2 PWM controllers the first controller is pretty much always used to control the brightness of the LCD screen. So we have a fixed pwm_lookup table for it there using the SoC's builtin display controller's device_name() as consumer-device-name.

The second PWM controller however is different it is mostly unused I'm aware of 2 cases where it is used and in both cases it is used to control the brightness of a backlight for fixed (etched into the glass) touch controls.

The problem is that in these cases there will be 2 totally different consumer devices. Looking at the lookup tabel checks in pwm_get() I see that it is possible to add a lookup which matches only by dev_id. So I could use this here and this would then also be in place for when I get around to writing a driver for the second case (that I'm ware of) which needs access to the second PWM controller.

So this then just leaves the question of what to name the con-id, since we won't be specifying a consumer-device-name I think it is best to keep the con_id quite generic, e.g.:

"pwm_soc_lpss_2"

to match with the existing:

"pwm_soc_backlight"

for the first PWM controller.

Uwe, Andy, is using a pwm_lookup with only a con_id match on "pwm_soc_lpss_2" ok with you ?

Regards,
Hans

#26 lore raw

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

Hi,

Quoted 44 lines · Hans de Goede

Hi Uwe, Andy,

Quoted 10 lines · Uwe Kleine-König
Quoted 9 lines · Andy Shevchenko
Quoted 1 line · Uwe Kleine-König

On Sun, Apr 30, 2023 at 06:58:06PM +0200, Hans de Goede wrote:

...

Quoted 2 lines

I don't know much about x86, but I think the table belongs to where this "80862289:00" device is created.

Quoted 6 lines
Quoted 1 line

Just for your information, it's in drivers/acpi/acpi_lpss.c.

Compared to drivers/platform/x86/lenovo-yogabook-wmi.c this file is never compiled as a module and so patch #1 would become unnecessary.

That file also already has a pwm_lookup table.

Right, the Cherry Trail SoCs in question have 2 PWM controllers the first controller is pretty much always used to control the brightness of the LCD screen. So we have a fixed pwm_lookup table for it there using the SoC's builtin display controller's device_name() as consumer-device-name.

The second PWM controller however is different it is mostly unused I'm aware of 2 cases where it is used and in both cases it is used to control the brightness of a backlight for fixed (etched into the glass) touch controls.

The problem is that in these cases there will be 2 totally different consumer devices. Looking at the lookup tabel checks in pwm_get() I see that it is possible to add a lookup which matches only by dev_id. So I could use this here and this would then also be in place for when I get around to writing a driver for the second case (that I'm ware of) which needs access to the second PWM controller.

So this then just leaves the question of what to name the con-id, since we won't be specifying a consumer-device-name I think it is best to keep the con_id quite generic, e.g.:

"pwm_soc_lpss_2"

Quoted 8 lines

to match with the existing:

"pwm_soc_backlight"

for the first PWM controller.

Uwe, Andy, is using a pwm_lookup with only a con_id match on "pwm_soc_lpss_2" ok with you ?

I've decided to go ahead and go this route.

So I've modified this patch to drop the pwm_lookup_table from it and changed the con_id passed to pwm_get() to:
"pwm_soc_lpss_2".

And then merged patches 2-19 (1) into the pdx86/review-hans (2).

I'll also submit an acpi_lpss.c patch soon to add a lookup-table entry for the "pwm_soc_lpss_2" con_id there.

Regards,

Hans

1) All the patches except for patch 1 which exported pwm_add_table() / pwm_remove_table()

2) Patches pending for pdx86/for-next

#27 lore raw

PATCH v2 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