From: Hans de Goede <hdegoede@redhat.com>
To: Tim Crawford <tcrawford@system76.com>,
platform-driver-x86@vger.kernel.org
Cc: productdev@system76.com
Subject: Re: [PATCH v2] platform/x86: system76: Handle new KBLED ACPI methods
Date: Tue, 25 Jul 2023 15:38:14 +0200 [thread overview]
Message-ID: <6ee963fb-e17c-e7f4-6772-d536ee571f9d@redhat.com> (raw)
In-Reply-To: <20230719181324.47035-1-tcrawford@system76.com>
Hi,
On 7/19/23 20:13, Tim Crawford wrote:
> System76 EC since system76/ec@9ac513128ad9 detects if the keyboard is
> white or RGB backlit via `RGBKB-DET#` at run-time instead of being set
> at compile-time. As part of this, the brightness of white-only backlit
> keyboards was also changed to behave more like the RGB-backlit
> keyboards: a value between 0 and 255 instead of a firmware-defined
> level.
>
> The EC ACPI methods in coreboot have been updated for this new
> functionality only, removing the old behavior.
>
> This should preserve behavior as we roll out new firmware with these
> changes included and users update to it.
>
> Ref: https://github.com/system76/ec/pull/357
> Ref: https://review.coreboot.org/c/coreboot/+/76152
> Signed-off-by: Tim Crawford <tcrawford@system76.com>
Thanks, patch looks good to me:
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
Regards,
Hans
> ---
> drivers/platform/x86/system76_acpi.c | 74 ++++++++++++++++++++++------
> 1 file changed, 59 insertions(+), 15 deletions(-)
>
> diff --git a/drivers/platform/x86/system76_acpi.c b/drivers/platform/x86/system76_acpi.c
> index fc4708fa6ebe..3da753b3d00d 100644
> --- a/drivers/platform/x86/system76_acpi.c
> +++ b/drivers/platform/x86/system76_acpi.c
> @@ -2,7 +2,7 @@
> /*
> * System76 ACPI Driver
> *
> - * Copyright (C) 2019 System76
> + * Copyright (C) 2023 System76
> *
> * This program is free software; you can redistribute it and/or modify
> * it under the terms of the GNU General Public License version 2 as
> @@ -24,6 +24,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;
> @@ -36,6 +42,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[] = {
> @@ -327,7 +334,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;
> - return system76_set(data, "SKBL", (int)data->kb_brightness);
> + 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
> @@ -399,7 +410,12 @@ static void kb_led_hotkey_hardware(struct system76_data *data)
> {
> int value;
>
> - value = system76_get(data, "GKBL");
> + 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;
> @@ -459,8 +475,9 @@ static void kb_led_hotkey_color(struct system76_data *data)
> {
> int i;
>
> - if (data->kb_color < 0)
> + if (data->kbled_type != KBLED_RGB)
> return;
> +
> if (data->kb_brightness > 0) {
> for (i = 0; i < ARRAY_SIZE(kb_colors); i++) {
> if (kb_colors[i] == data->kb_color)
> @@ -687,19 +704,46 @@ static int system76_add(struct acpi_device *acpi_dev)
> 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;
> - if (acpi_has_method(acpi_device_handle(data->acpi_dev), "SKBC")) {
> - 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);
> + 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:
> + // Nothing to do: Device will not be registered.
> + break;
> + case KBLED_WHITE:
> + data->kb_led.max_brightness = 255;
> + data->kb_toggle_brightness = 72;
> + break;
> + case KBLED_RGB:
> + 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 {
> - data->kb_led.max_brightness = 5;
> - data->kb_color = -1;
> + // Use the old ACPI methods
> + if (acpi_has_method(acpi_device_handle(data->acpi_dev), "SKBC")) {
> + data->kbled_type = KBLED_RGB;
> + 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);
> + } else {
> + data->kbled_type = KBLED_WHITE;
> + data->kb_led.max_brightness = 5;
> + }
> + }
> +
> + if (data->kbled_type != KBLED_NONE) {
> + err = devm_led_classdev_register(&acpi_dev->dev, &data->kb_led);
> + if (err)
> + return err;
> }
> - err = devm_led_classdev_register(&acpi_dev->dev, &data->kb_led);
> - if (err)
> - return err;
>
> data->input = devm_input_allocate_device(&acpi_dev->dev);
> if (!data->input)
next prev parent reply other threads:[~2023-07-25 13:39 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-07-19 18:13 [PATCH v2] platform/x86: system76: Handle new KBLED ACPI methods Tim Crawford
2023-07-25 13:38 ` Hans de Goede [this message]
2023-07-26 9:00 ` Hans de Goede
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=6ee963fb-e17c-e7f4-6772-d536ee571f9d@redhat.com \
--to=hdegoede@redhat.com \
--cc=platform-driver-x86@vger.kernel.org \
--cc=productdev@system76.com \
--cc=tcrawford@system76.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox