From: "Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>
To: yahia <yahia.a.abdrabou@gmail.com>
Cc: platform-driver-x86@vger.kernel.org
Subject: Re: [PATCH v2] hp-wmi: add battery threshold support
Date: Mon, 8 Jun 2026 18:57:08 +0300 (EEST) [thread overview]
Message-ID: <41309386-12fb-71bf-3ced-8377bf8aaa8b@linux.intel.com> (raw)
In-Reply-To: <20260608153613.38780-1-yahia.a.abdrabou@gmail.com>
On Mon, 8 Jun 2026, yahia wrote:
> Hello, Ilpo
> Thanks for your review,
> This V2 patch implements Battery threshold support via ACPI methods
> SBCO and GBCO,This Implementation adds battery_get function to retrieve
> the current battery threshold mode and use it to identify capabilities
> to simplify code instead of another function specifically for detection
As already stated, please write proper English sentences.
Anything you want to say that isn't part of the changelog should appear
under --- line.
> Signed-off-by: yahia ahmed <yahia.a.abdrabou@gmail.com>
> ---
Missing version history.
> drivers/platform/x86/hp/hp-wmi.c | 61 ++++++++++++++++++++++++++++++++
> 1 file changed, 61 insertions(+)
>
> diff --git a/drivers/platform/x86/hp/hp-wmi.c b/drivers/platform/x86/hp/hp-wmi.c
> index f63bc00d9a9b..f2180b61b84e 100644
> --- a/drivers/platform/x86/hp/hp-wmi.c
> +++ b/drivers/platform/x86/hp/hp-wmi.c
> @@ -11,6 +11,7 @@
> * Copyright (C) 2005 Dmitry Torokhov <dtor@mail.ru>
> */
>
> #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
>
> #include <linux/acpi.h>
Eh?
> @@ -292,6 +293,18 @@ enum hp_wmi_event_ids {
> HPWMI_SMART_EXPERIENCE_APP = 0x21,
> };
>
> +/*
> + * Profiles for hp battery threshold profile 0x05 and 0x06 map to 4 and 5 respectively
> + */
> +enum hp_battery_modes {
> + HP_BATTERY_MODE_NORMAL = 0x00,
> + HP_BATTERY_MODE_ADAPTIVE = 0x02,
> + HP_BATTERY_THRESHOLD_4 = 0x05,
> + HP_BATTERY_THRESHOLD_5 = 0x06,
The values should be aligned.
> +};
> +
> +#define HPWMI_BATTERY_THRESHOLD_SBCO 0x2B // SBCO Command id
> +#define HPWMI_AC_REQUIRED 0x35 // obscure edge case where the bios requires the user to be charged while setting a profile
???
> /*
> * struct bios_args buffer is dynamically allocated. New WMI command types
> * were introduced that exceeds 128-byte data size. Changes to handle
> @@ -448,6 +461,7 @@ static struct notifier_block platform_power_source_nb;
> static enum platform_profile_option active_platform_profile;
> static bool platform_profile_support;
> static bool zero_insize_support;
> +static bool battery_threshold_support;
>
> static struct rfkill *wifi_rfkill;
> static struct rfkill *bluetooth_rfkill;
> @@ -1085,6 +1099,50 @@ static ssize_t postcode_store(struct device *dev, struct device_attribute *attr,
> return count;
> }
>
> +static int battery_get(void) {
> + struct acpi_buffer output = { ACPI_ALLOCATE_BUFFER, NULL };
> + int mode = -1;
> + if (ACPI_SUCCESS(acpi_evaluate_object(NULL, "\\_SB.WMID.GBCO", NULL, &output))) {
> + union acpi_object *obj = (union acpi_object *)output.pointer;
> + if (obj && obj->type == ACPI_TYPE_PACKAGE && obj->package.count >= 3) { // standard package sent by bios
> + mode = (int)obj->package.elements[2].buffer.pointer[0]; // bios returns the result in the third buffer
> + }
> + kfree(output.pointer);
> + } else
> + mode = -EIO;
> + return mode;
> +}
> +
> +static int battery_set(int profile)
> +{
> + if (!battery_threshold_support) {
> + pr_err("Battery threshold is not supported");
> + return -EOPNOTSUPP;
> + }
> + union acpi_object args[4];
> + acpi_status status;
> + struct acpi_object_list arg_list = { .count = 4, .pointer = args };
> + memset(args, 0, sizeof(args));
> + args[0].type = ACPI_TYPE_INTEGER;
> + args[0].integer.value = 0;
> + args[1].type = ACPI_TYPE_INTEGER;
> + args[1].integer.value = profile;
> + args[2].type = ACPI_TYPE_INTEGER; // padding required by bios
> + args[2].integer.value = 0;
> + args[3].type = ACPI_TYPE_INTEGER;
> + args[3].integer.value = 0;
> + status = acpi_evaluate_object(NULL, "\\_SB.WMID.SBCO", &arg_list, NULL);
> + if (unlikely(status == HPWMI_AC_REQUIRED)) {
> + pr_err("You have to be plugged in while setting a battery profile"); // random edge case in the bios
> + return -EIO;
> + }
> + if (ACPI_FAILURE(status)) {
> + pr_info("Write failed with Error code 0x%08x\n", status);
> + return -EIO;
> + }
> + return status;
> +}
> +
> static int camera_shutter_input_setup(void)
> {
> int err;
> @@ -2292,6 +2350,9 @@ static int __init hp_wmi_bios_setup(struct platform_device *device)
> if (err < 0)
> return err;
>
> + int ret = battery_get();
> + if (ret >= 0)
> + battery_threshold_support = true;
> thermal_profile_setup(device);
>
> return 0;
>
Unfortunately, this submission doesn't match kernel coding style
guidelines you can find under Documentation/.
Please review the patch yourself before submitting the next version and correct
all error you find before the submission.
--
i.
next prev parent reply other threads:[~2026-06-08 15:57 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-05 23:19 [PATCH] [PATCH] platform/x86: Add Battery Threshold support yahia
2026-06-08 12:35 ` Ilpo Järvinen
2026-06-08 15:36 ` [PATCH v2] hp-wmi: add battery threshold support yahia
2026-06-08 15:57 ` Ilpo Järvinen [this message]
2026-06-08 18:07 ` [PATCH v3] " yahia
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=41309386-12fb-71bf-3ced-8377bf8aaa8b@linux.intel.com \
--to=ilpo.jarvinen@linux.intel.com \
--cc=platform-driver-x86@vger.kernel.org \
--cc=yahia.a.abdrabou@gmail.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.