From: Hans de Goede <hdegoede@redhat.com>
To: "Thomas Weißschuh" <linux@weissschuh.net>,
linux-pm@vger.kernel.org, "Sebastian Reichel" <sre@kernel.org>,
ibm-acpi-devel@lists.sourceforge.net,
platform-driver-x86@vger.kernel.org,
"Mark Gross" <markgross@kernel.org>,
"Henrique de Moraes Holschuh" <hmh@hmh.eng.br>
Cc: linux-kernel@vger.kernel.org, linrunner@gmx.net,
bberg@redhat.com, hadess@hadess.net, markpearson@lenovo.com,
nicolopiazzalunga@gmail.com, njoshi1@lenovo.com,
smclt30p@gmail.com
Subject: Re: [PATCH 4/4] platform/x86: thinkpad_acpi: support inhibit-charge
Date: Tue, 16 Nov 2021 11:58:16 +0100 [thread overview]
Message-ID: <09a66da1-1a8b-a668-3179-81670303ea37@redhat.com> (raw)
In-Reply-To: <20211113104225.141333-5-linux@weissschuh.net>
Hi Thomas,
Thank you for working on this!
On 11/13/21 11:42, Thomas Weißschuh wrote:
> This adds support for the inhibit-charge charge_behaviour through the
> embedded controller of ThinkPads.
>
> Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
>
> ---
>
> This patch is based on https://lore.kernel.org/platform-driver-x86/d2808930-5840-6ffb-3a59-d235cdb1fe16@gmail.com/
> ---
> drivers/platform/x86/thinkpad_acpi.c | 55 +++++++++++++++++++++++++++-
> 1 file changed, 53 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
> index e8c98e9aff71..7cd6475240b2 100644
> --- a/drivers/platform/x86/thinkpad_acpi.c
> +++ b/drivers/platform/x86/thinkpad_acpi.c
> @@ -9321,6 +9321,8 @@ static struct ibm_struct mute_led_driver_data = {
> #define SET_STOP "BCSS"
> #define GET_DISCHARGE "BDSG"
> #define SET_DISCHARGE "BDSS"
> +#define GET_INHIBIT "PSSG"
> +#define SET_INHIBIT "BICS"
>
> enum {
> BAT_ANY = 0,
> @@ -9338,6 +9340,7 @@ enum {
> THRESHOLD_START,
> THRESHOLD_STOP,
> FORCE_DISCHARGE,
> + INHIBIT_CHARGE,
> };
>
> struct tpacpi_battery_data {
> @@ -9409,6 +9412,13 @@ static int tpacpi_battery_get(int what, int battery, int *ret)
> /* The force discharge status is in bit 0 */
> *ret = *ret & 0x01;
> return 0;
> + case INHIBIT_CHARGE:
> + /* This is actually reading peak shift state, like tpacpi-bat does */
> + if ACPI_FAILURE(tpacpi_battery_acpi_eval(GET_INHIBIT, ret, battery))
> + return -ENODEV;
> + /* The inhibit charge status is in bit 0 */
> + *ret = *ret & 0x01;
> + return 0;
> default:
> pr_crit("wrong parameter: %d", what);
> return -EINVAL;
> @@ -9447,6 +9457,22 @@ static int tpacpi_battery_set(int what, int battery, int value)
> return -ENODEV;
> }
> return 0;
> + case INHIBIT_CHARGE:
> + /* When setting inhibit charge, we set a default value of
> + * always breaking on AC detach and the effective time is set to
> + * be permanent.
> + * The battery ID is in bits 4-5, 2 bits,
> + * the effective time is in bits 8-23, 2 bytes.
> + * A time of FFFF indicates forever.
> + */
> + param = value;
> + param |= battery << 4;
> + param |= 0xFFFF << 8;
> + if (ACPI_FAILURE(tpacpi_battery_acpi_eval(SET_INHIBIT, &ret, param))) {
> + pr_err("failed to set inhibit charge on %d", battery);
> + return -ENODEV;
> + }
> + return 0;
> default:
> pr_crit("wrong parameter: %d", what);
> return -EINVAL;
> @@ -9467,6 +9493,8 @@ static int tpacpi_battery_probe(int battery)
> * 4) Check for support
> * 5) Get the current force discharge status
> * 6) Check for support
> + * 7) Get the current inhibit charge status
> + * 8) Check for support
> */
> if (acpi_has_method(hkey_handle, GET_START)) {
> if ACPI_FAILURE(tpacpi_battery_acpi_eval(GET_START, &ret, battery)) {
> @@ -9513,6 +9541,16 @@ static int tpacpi_battery_probe(int battery)
> battery_info.batteries[battery].charge_behaviours |=
> BIT(POWER_SUPPLY_CHARGE_BEHAVIOUR_FORCE_DISCHARGE);
> }
> + if (acpi_has_method(hkey_handle, GET_INHIBIT)) {
> + if (ACPI_FAILURE(tpacpi_battery_acpi_eval(GET_INHIBIT, &ret, battery))) {
> + pr_err("Error probing battery inhibit charge; %d\n", battery);
> + return -ENODEV;
> + }
> + /* Support is marked in bit 5 */
> + if (ret & BIT(5))
> + battery_info.batteries[battery].charge_behaviours |=
> + BIT(POWER_SUPPLY_CHARGE_BEHAVIOUR_INHIBIT_CHARGE);
> + }
>
> battery_info.batteries[battery].charge_behaviours |=
> BIT(POWER_SUPPLY_CHARGE_BEHAVIOUR_AUTO);
> @@ -9673,6 +9711,11 @@ static ssize_t charge_behaviour_show(struct device *dev,
> return -ENODEV;
> if (ret)
> active = POWER_SUPPLY_CHARGE_BEHAVIOUR_FORCE_DISCHARGE;
> + } else if (available & BIT(POWER_SUPPLY_CHARGE_BEHAVIOUR_INHIBIT_CHARGE)) {
The use of else-if here seems wrong, this suggests that batterys can never
support both force-discharge and inhibit-charge behavior, which they can, so this
means that active can now never get set to BEHAVIOUR_INHIBIT_CHARGE on
batteries which support both.
So AFAICT the else part of the else if should be dropped here, making this
a new stand alone if block.
For the other parts of the set lets wait and see what Sebastian has to say.
Regards,
Hans
> + if (tpacpi_battery_get(INHIBIT_CHARGE, battery, &ret))
> + return -ENODEV;
> + if (ret)
> + active = POWER_SUPPLY_CHARGE_BEHAVIOUR_INHIBIT_CHARGE;
> }
>
> return power_supply_charge_behaviour_show(dev, available, active, buf);
> @@ -9710,12 +9753,20 @@ static ssize_t charge_behaviour_store(struct device *dev,
> switch (selected) {
> case POWER_SUPPLY_CHARGE_BEHAVIOUR_AUTO:
> ret = tpacpi_battery_set(FORCE_DISCHARGE, battery, 0);
> - if (ret < 0)
> + ret = tpacpi_battery_set(INHIBIT_CHARGE, battery, 0) || ret;
> + if (ret)
> return ret;
> break;
> case POWER_SUPPLY_CHARGE_BEHAVIOUR_FORCE_DISCHARGE:
> ret = tpacpi_battery_set(FORCE_DISCHARGE, battery, 1);
> - if (ret < 0)
> + ret = tpacpi_battery_set(INHIBIT_CHARGE, battery, 0) || ret;
> + if (ret)
> + return ret;
> + break;
> + case POWER_SUPPLY_CHARGE_BEHAVIOUR_INHIBIT_CHARGE:
> + ret = tpacpi_battery_set(FORCE_DISCHARGE, battery, 0);
> + ret = tpacpi_battery_set(INHIBIT_CHARGE, battery, 1) || ret;
> + if (ret)
> return ret;
> break;
> default:
>
next prev parent reply other threads:[~2021-11-16 10:58 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-11-13 10:42 [PATCH 0/4] power: supply: add charge_behaviour property (force-discharge, inhibit-charge) Thomas Weißschuh
2021-11-13 10:42 ` [PATCH 1/4] power: supply: add charge_behaviour attributes Thomas Weißschuh
2021-11-13 10:42 ` [PATCH 2/4] power: supply: add helpers for charge_behaviour sysfs Thomas Weißschuh
2021-11-13 10:42 ` [PATCH 3/4] platform/x86: thinkpad_acpi: support force-discharge Thomas Weißschuh
2021-11-16 20:35 ` [External] " Mark Pearson
2021-11-13 10:42 ` [PATCH 4/4] platform/x86: thinkpad_acpi: support inhibit-charge Thomas Weißschuh
2021-11-16 10:58 ` Hans de Goede [this message]
2021-11-16 12:18 ` Thomas Weißschuh
2021-11-16 20:52 ` [External] " Mark Pearson
2021-11-16 23:44 ` Thomas Weißschuh
2021-11-17 15:09 ` Mark Pearson
2021-11-16 16:56 ` [PATCH 0/4] power: supply: add charge_behaviour property (force-discharge, inhibit-charge) Thomas Koch
2021-11-17 17:57 ` Thomas Weißschuh
2021-11-17 18:20 ` [External] " Mark Pearson
2021-11-17 18:36 ` Thomas Koch
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=09a66da1-1a8b-a668-3179-81670303ea37@redhat.com \
--to=hdegoede@redhat.com \
--cc=bberg@redhat.com \
--cc=hadess@hadess.net \
--cc=hmh@hmh.eng.br \
--cc=ibm-acpi-devel@lists.sourceforge.net \
--cc=linrunner@gmx.net \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=linux@weissschuh.net \
--cc=markgross@kernel.org \
--cc=markpearson@lenovo.com \
--cc=nicolopiazzalunga@gmail.com \
--cc=njoshi1@lenovo.com \
--cc=platform-driver-x86@vger.kernel.org \
--cc=smclt30p@gmail.com \
--cc=sre@kernel.org \
/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;
as well as URLs for NNTP newsgroup(s).