From: Hans de Goede <hdegoede@redhat.com>
To: Andres Salomon <dilinger@queued.net>
Cc: linux-kernel@vger.kernel.org,
"Thomas Weißschuh" <linux@weissschuh.net>,
"Pali Rohár" <pali@kernel.org>,
platform-driver-x86@vger.kernel.org,
"Matthew Garrett" <mjg59@srcf.ucam.org>,
"Sebastian Reichel" <sre@kernel.org>,
"Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>,
linux-pm@vger.kernel.org, Dell.Client.Kernel@dell.com
Subject: Re: [PATCH v4 1/2] platform/x86:dell-laptop: Add knobs to change battery charge settings
Date: Wed, 4 Sep 2024 14:51:46 +0200 [thread overview]
Message-ID: <ea76c1a2-826a-42ea-87ec-40b5d0a8f364@redhat.com> (raw)
In-Reply-To: <a0bfd438-6d18-4334-aa79-b35aed43f3c7@redhat.com>
Hi,
On 8/27/24 9:04 PM, Hans de Goede wrote:
> Hi,
>
> On 8/27/24 8:24 PM, Andres Salomon wrote:
>> On Mon, 26 Aug 2024 16:44:35 +0200
>> Hans de Goede <hdegoede@redhat.com> wrote:
>>
>>> Hi Andres,
>>>
>>> On 8/20/24 9:30 AM, Andres Salomon wrote:
>> [...]
>>>> +
>>>> +static ssize_t charge_type_show(struct device *dev,
>>>> + struct device_attribute *attr,
>>>> + char *buf)
>>>> +{
>>>> + ssize_t count = 0;
>>>> + int i;
>>>> +
>>>> + for (i = 0; i < ARRAY_SIZE(battery_modes); i++) {
>>>> + bool active;
>>>> +
>>>> + if (!(battery_supported_modes & BIT(i)))
>>>> + continue;
>>>> +
>>>> + active = dell_battery_mode_is_active(battery_modes[i].token);
>>>> + count += sysfs_emit_at(buf, count, active ? "[%s] " : "%s ",
>>>> + battery_modes[i].label);
>>>> + }
>>>
>>> If you look at the way how charge_type is shown by the power_supply_sysfs.c
>>> file which is used for power-supply drivers which directly register
>>> a power-supply themselves rather then extending an existing driver, this
>>> is not the correct format.
>>>
>>> drivers/power/supply/power_supply_sysfs.c
>>>
>>> lists charge_type as:
>>>
>>> POWER_SUPPLY_ENUM_ATTR(CHARGE_TYPE),
>>>
>>> and ENUM type properties use the following for show() :
>>>
>>> default:
>>> if (ps_attr->text_values_len > 0 &&
>>> value.intval < ps_attr->text_values_len && value.intval >= 0) {
>>> ret = sysfs_emit(buf, "%s\n", ps_attr->text_values[value.intval]);
>>> } else {
>>> ret = sysfs_emit(buf, "%d\n", value.intval);
>>> }
>>> }
>>>
>>> with in this case text_values pointing to:
>>>
>>> static const char * const POWER_SUPPLY_CHARGE_TYPE_TEXT[] = {
>>> [POWER_SUPPLY_CHARGE_TYPE_UNKNOWN] = "Unknown",
>>> [POWER_SUPPLY_CHARGE_TYPE_NONE] = "N/A",
>>> [POWER_SUPPLY_CHARGE_TYPE_TRICKLE] = "Trickle",
>>> [POWER_SUPPLY_CHARGE_TYPE_FAST] = "Fast",
>>> [POWER_SUPPLY_CHARGE_TYPE_STANDARD] = "Standard",
>>> [POWER_SUPPLY_CHARGE_TYPE_ADAPTIVE] = "Adaptive",
>>> [POWER_SUPPLY_CHARGE_TYPE_CUSTOM] = "Custom",
>>> [POWER_SUPPLY_CHARGE_TYPE_LONGLIFE] = "Long Life",
>>> [POWER_SUPPLY_CHARGE_TYPE_BYPASS] = "Bypass",
>>> };
>>>
>>> So value.intval will be within the expected range hitting:
>>>
>>> ret = sysfs_emit(buf, "%s\n", ps_attr->text_values[value.intval]);
>>>
>>> IOW instead of outputting something like this:
>>>
>>> Fast [Standard] Long Life
>>>
>>> which is what your show() function does it outputs only
>>> the active value as a string, e.g.:
>>>
>>> Standard
>>>
>>> Yes not being able to see the supported values is annoying I actually
>>> wrote an email about that earlier today:
>>>
>>> https://lore.kernel.org/linux-pm/49993a42-aa91-46bf-acef-4a089db4c2db@redhat.com/
>>>
>>> but we need to make sure that the output is consistent between drivers otherwise
>>> userspace can never know how to use the API, so for charge_type the dell
>>> driver should only output the active type, not all the options.
>>
>> So should I just wait to make any changes until you hear back in that
>> thread?
>
> Yes that might be best.
>
>> I'm not overly excited about changing it to use the current
>> charge_type API, given that the only way to get a list of modes that the
>> hardware supports is to try setting them all and seeing what fails.
>>
>> I suppose another option is to rename it to charge_types in the dell
>> driver under the assumption that your proposed charge_types API (or
>> something like it) will be added..
>
> Right, if we get a favorable reaction to my charge_types suggestion
> then we can go ahead with the dell-laptop changes using charge_types
> instead of charge_type. I was already thinking along those lines
> myself too.
>
> So if my RFC gets a favorable response lets do that.
>
> In that case you don't even need to send a new version just
> renaming charge_type to charge_types is something which I can do
> while merging this.
Sebastian has acked the charge_types support. So I've done
s/charge_type/charge_types/ support and merged this.
Note that once charge_types get added to the power-supply
core (I hope to post patches for this soon-ish), then there
will be a power_supply_charge_types_show() helper which
will replace most of the body of charge_types_show() to make
sure that the output does not change when switching to this helper
I have changed the order of battery_modes:
--- a/drivers/platform/x86/dell/dell-laptop.c
+++ b/drivers/platform/x86/dell/dell-laptop.c
@@ -107,9 +107,9 @@ struct battery_mode_info {
};
static const struct battery_mode_info battery_modes[] = {
- { BAT_STANDARD_MODE_TOKEN, "Standard" },
- { BAT_EXPRESS_MODE_TOKEN, "Fast" },
{ BAT_PRI_AC_MODE_TOKEN, "Trickle" },
+ { BAT_EXPRESS_MODE_TOKEN, "Fast" },
+ { BAT_STANDARD_MODE_TOKEN, "Standard" },
{ BAT_ADAPTIVE_MODE_TOKEN, "Adaptive" },
{ BAT_CUSTOM_MODE_TOKEN, "Custom" },
};
Now it matches the order of the POWER_SUPPLY_CHARGE_TYPE_* values
in include/linux/power_supply.h and the future
power_supply_charge_types_show() helper will show the (available)
strings in that order.
Thank you for your patch-series, I've applied the series to my
review-hans branch:
https://git.kernel.org/pub/scm/linux/kernel/git/pdx86/platform-drivers-x86.git/log/?h=review-hans
Once I've run some tests on this branch the patches there will be
added to the platform-drivers-x86/for-next branch and eventually
will be included in the pdx86 pull-request to Linus for the next
merge-window.
Regards,
Hans
Regards,
Hans
next prev parent reply other threads:[~2024-09-04 12:51 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-08-20 7:30 Andres Salomon
2024-08-20 7:33 ` [PATCH v3 2/2] platform/x86:dell-laptop: remove duplicate code w/ battery function Andres Salomon
2024-08-26 14:44 ` [PATCH v4 1/2] platform/x86:dell-laptop: Add knobs to change battery charge settings Hans de Goede
2024-08-27 18:24 ` Andres Salomon
2024-08-27 19:04 ` Hans de Goede
2024-09-04 12:51 ` Hans de Goede [this message]
2024-08-27 20:50 ` Thomas Weißschuh
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=ea76c1a2-826a-42ea-87ec-40b5d0a8f364@redhat.com \
--to=hdegoede@redhat.com \
--cc=Dell.Client.Kernel@dell.com \
--cc=dilinger@queued.net \
--cc=ilpo.jarvinen@linux.intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=linux@weissschuh.net \
--cc=mjg59@srcf.ucam.org \
--cc=pali@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
all inboxes | Powered by JetHome®