Handle new KBLED ACPI methods

The EC has been updated to detect if a white or RGB backlit keyboard is
attached at run-time instead of being set at compile-time. The ACPI
methods in coreboot have been updated to handle this new functionality.

Check for the new ACPI method `GKBK` "Get Keyboard Kind" to determine if
the module should use the new logic or the old logic.

Signed-off-by: Tim Crawford <tcrawford@system76.com>
This commit is contained in:
Tim Crawford 2023-05-23 10:21:59 -06:00 committed by Jeremy Soller
parent ed0112437f
commit aaf10e3dac
1 changed files with 64 additions and 14 deletions

View File

@ -25,6 +25,12 @@
#include <acpi/battery.h>
enum kbled_type {
KBLED_NONE,
KBLED_WHITE,
KBLED_RGB,
};
struct system76_data {
struct acpi_device *acpi_dev;
struct led_classdev ap_led;
@ -37,6 +43,7 @@ struct system76_data {
union acpi_object *ntmp;
struct input_dev *input;
bool has_open_ec;
enum kbled_type kbled_type;
};
static const struct acpi_device_id device_ids[] = {
@ -340,7 +347,11 @@ static int kb_led_set(struct led_classdev *led, enum led_brightness value)
data = container_of(led, struct system76_data, kb_led);
data->kb_brightness = value;
if (acpi_has_method(acpi_device_handle(data->acpi_dev), "GKBK")) {
return system76_set(data, "SKBB", (int)data->kb_brightness);
} else {
return system76_set(data, "SKBL", (int)data->kb_brightness);
}
}
// Get the last set keyboard LED color
@ -416,7 +427,12 @@ static void kb_led_hotkey_hardware(struct system76_data *data)
{
int value;
if (acpi_has_method(acpi_device_handle(data->acpi_dev), "GKBK")) {
value = system76_get(data, "GKBB");
} else {
value = system76_get(data, "GKBL");
}
if (value < 0)
return;
data->kb_brightness = value;
@ -700,6 +716,38 @@ static int system76_add(struct acpi_device *acpi_dev)
if (err)
return err;
if (acpi_has_method(acpi_device_handle(data->acpi_dev), "GKBK")) {
// Use the new ACPI methods
data->kbled_type = system76_get(data, "GKBK");
switch (data->kbled_type) {
case KBLED_NONE:
data->kb_led.max_brightness = 0;
data->kb_color = -1;
break;
case KBLED_WHITE:
data->kb_led.name = "system76_acpi::kbd_backlight";
data->kb_led.flags = LED_BRIGHT_HW_CHANGED | LED_CORE_SUSPENDRESUME;
data->kb_led.brightness_get = kb_led_get;
data->kb_led.brightness_set_blocking = kb_led_set;
data->kb_led.max_brightness = 255;
data->kb_toggle_brightness = 72;
data->kb_color = 0xffffff;
break;
case KBLED_RGB:
data->kb_led.name = "system76_acpi::kbd_backlight";
data->kb_led.flags = LED_BRIGHT_HW_CHANGED | LED_CORE_SUSPENDRESUME;
data->kb_led.brightness_get = kb_led_get;
data->kb_led.brightness_set_blocking = kb_led_set;
data->kb_led.max_brightness = 255;
data->kb_led.groups = system76_kb_led_color_groups;
data->kb_toggle_brightness = 72;
data->kb_color = 0xffffff;
system76_set(data, "SKBC", data->kb_color);
break;
}
} else {
// Use the old ACPI methods
data->kb_led.name = "system76_acpi::kbd_backlight";
data->kb_led.flags = LED_BRIGHT_HW_CHANGED | LED_CORE_SUSPENDRESUME;
data->kb_led.brightness_get = kb_led_get;
@ -714,6 +762,8 @@ static int system76_add(struct acpi_device *acpi_dev)
data->kb_led.max_brightness = 5;
data->kb_color = -1;
}
}
err = devm_led_classdev_register(&acpi_dev->dev, &data->kb_led);
if (err)
return err;