Linux Power Management development
 help / color / mirror / Atom feed
From: Arvid Norlander <lkml@vorpal.se>
To: platform-driver-x86@vger.kernel.org, linux-pm@vger.kernel.org
Cc: Sebastian Reichel <sre@kernel.org>,
	Hans de Goede <hdegoede@redhat.com>,
	Azael Avalos <coproscefalo@gmail.com>,
	Arvid Norlander <lkml@vorpal.se>
Subject: [PATCH v2 0/3] platform/x86: Battery charge mode in toshiba_acpi
Date: Fri,  2 Sep 2022 20:00:34 +0200	[thread overview]
Message-ID: <20220902180037.1728546-1-lkml@vorpal.se> (raw)

Hi,

Here we go again.

Note that this patch series edits in the same place as my patch series
adding HWMON support for the fan, so there will be a trivial merge
conflict, as both series insert new functions in the same location in the
file. Hopefully this is not a big issue, but if so I can rebase one on top
of the other.

Changelog
=========
v2:
  * Fix compiler warning discovered by "kernel test robot" in patch 2
    (real issue).
  * Added Acked-by in patch 3 (Thanks Sebastian Reichel).


Mostly original (from v1 of this series) cover letter follows:

Summary
=======

This patch series implements battery charge control for Toshiba Satellite
Z830 (and posssibly some other models). The full background is available
in the two emails linked below, but a short summary will follow, including
only what is relevant for battery charge control.

Background (from link 1)
==========

The Toshiba Satellite/Portege Z830 supports not charging the battery fully
in order to prolong battery life. Unlike for example ThinkPads where this
control is granular here it is just off/on. When off it charges to 100%.
When on it charges to about 80%.

According to the Windows program used to control the feature the setting
will not take effect until the battery has been discharged to around 50%.
However, in my testing it takes effect as soon as the charge drops below
80%. On Windows Toshiba branded this feature as "Eco charging"

In the following example ACPI calls I will use the following newly defined
constants:
#define HCI_BATTERY_CHARGE_MODE 0xba
#define BATTERY_CHARGE_FULL 0
#define BATTERY_CHARGE_80_PERCENT 1

To set the feature:
  {HCI_SET, HCI_BATTERY_CHARGE_MODE, charge_mode, 0, 0, 0}
To query for the existence of the feature:
  {HCI_GET, HCI_BATTERY_CHARGE_MODE, 0, 0, 0, 0}
To read the feature:
  {HCI_GET, HCI_BATTERY_CHARGE_MODE, 0, 0, 0, 1}

The read may need to be retried if TOS_DATA_NOT_AVAILABLE is returned as
the status code. This rarely happens (I have never observed it on Linux),
but I have seen it happen under Windows once, and the software did retry
it.


Improvements
============

As discussed in link 2 & 3 below, the original approach was suboptimal.

This patch series instead consists of two patches.

The first patch implements detecting the feature as well as internal
getter/setter methods.

The second patch adds battery hooks (heavily based on the code for this in
thinkpad_acpi) which creates the standard charge_control_end_threshold file
under /sys/class/power_supply/BAT1.

Side note: There is no BAT0 on this Toshiba, I'm not sure why the numbering
ends up starting from 1 instead of 0 here. This differs from my Thinkpads,
where the numbering starts from 0, with BAT1 being the second battery.
However, I haven't spent much effort investigating this, as it did not seem
important.

Patch 3 updates the ABI test documentation as suggested by Hans de Goede.
Note that only the charge_control_end_threshold is updated, as this is the
only limit supported by the Toshiba Z830. Possibly
charge_control_start_threshold should also be updated similarly, or would
it be better to wait for an actual example of this in the wild first?

Link (1): https://www.spinics.net/lists/platform-driver-x86/msg34314.html
Link (2): https://www.spinics.net/lists/platform-driver-x86/msg34354.html
Link (3): https://www.spinics.net/lists/platform-driver-x86/msg34320.html

Best regards,
Arvid Norlander


Arvid Norlander (3):
  platform/x86: Battery charge mode in toshiba_acpi (internals)
  platform/x86: Battery charge mode in toshiba_acpi (sysfs)
  docs: ABI: charge_control_end_threshold may not support all values

 Documentation/ABI/testing/sysfs-class-power |   5 +-
 drivers/platform/x86/toshiba_acpi.c         | 166 ++++++++++++++++++++
 2 files changed, 170 insertions(+), 1 deletion(-)


base-commit: b90cb1053190353cc30f0fef0ef1f378ccc063c5
-- 
2.37.3


             reply	other threads:[~2022-09-02 18:00 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-02 18:00 Arvid Norlander [this message]
2022-09-02 18:00 ` [PATCH 1/3] platform/x86: Battery charge mode in toshiba_acpi (internals) Arvid Norlander
2022-09-02 18:00 ` [PATCH v2 2/3] platform/x86: Battery charge mode in toshiba_acpi (sysfs) Arvid Norlander
2022-09-09 17:19   ` Hans de Goede
2022-09-02 18:00 ` [PATCH v2 3/3] docs: ABI: charge_control_end_threshold may not support all values Arvid Norlander
2022-09-09 17:25 ` [PATCH v2 0/3] platform/x86: Battery charge mode in toshiba_acpi 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=20220902180037.1728546-1-lkml@vorpal.se \
    --to=lkml@vorpal.se \
    --cc=coproscefalo@gmail.com \
    --cc=hdegoede@redhat.com \
    --cc=linux-pm@vger.kernel.org \
    --cc=platform-driver-x86@vger.kernel.org \
    --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