Linux Power Management development
 help / color / mirror / Atom feed
From: "Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>
To: Hans de Goede <hdegoede@redhat.com>
Cc: "Andy Shevchenko" <andy@kernel.org>,
	"Thomas Weißschuh" <linux@weissschuh.net>,
	"Sebastian Reichel" <sre@kernel.org>,
	"Jelle van der Waa" <jelle@vdwaa.nl>,
	platform-driver-x86@vger.kernel.org, linux-pm@vger.kernel.org
Subject: Re: [PATCH v4 4/4] platform/x86: dell-laptop: Use power_supply_charge_types_show/_parse() helpers
Date: Tue, 17 Dec 2024 14:01:08 +0200 (EET)	[thread overview]
Message-ID: <0030c3dd-c70c-d21b-de2b-ace0aeb4030d@linux.intel.com> (raw)
In-Reply-To: <20241211174451.355421-5-hdegoede@redhat.com>

[-- Attachment #1: Type: text/plain, Size: 4478 bytes --]

On Wed, 11 Dec 2024, Hans de Goede wrote:

> Make battery_modes a map between tokens and enum power_supply_charge_type
> values instead of between tokens and strings and use the new
> power_supply_charge_types_show/_parse() helpers for show()/store()
> to ensure that things are handled in the same way as in other drivers.
> 
> This also changes battery_supported_modes to be a bitmap of charge-types
> (enum power_supply_charge_type values) rather then a bitmap of indices
> into battery_modes[].
> 
> Reviewed-by: Thomas Weißschuh <linux@weissschuh.net>
> Signed-off-by: Hans de Goede <hdegoede@redhat.com>
> ---
>  drivers/platform/x86/dell/dell-laptop.c | 54 ++++++++++++-------------
>  1 file changed, 25 insertions(+), 29 deletions(-)
> 
> diff --git a/drivers/platform/x86/dell/dell-laptop.c b/drivers/platform/x86/dell/dell-laptop.c
> index 5671bd0deee7..9a4cfcb8bbe0 100644
> --- a/drivers/platform/x86/dell/dell-laptop.c
> +++ b/drivers/platform/x86/dell/dell-laptop.c
> @@ -103,15 +103,15 @@ static bool mute_led_registered;
>  
>  struct battery_mode_info {
>  	int token;
> -	const char *label;
> +	enum power_supply_charge_type charge_type;
>  };
>  
>  static const struct battery_mode_info battery_modes[] = {
> -	{ 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" },
> +	{ BAT_PRI_AC_MODE_TOKEN,   POWER_SUPPLY_CHARGE_TYPE_TRICKLE },
> +	{ BAT_EXPRESS_MODE_TOKEN,  POWER_SUPPLY_CHARGE_TYPE_FAST },
> +	{ BAT_STANDARD_MODE_TOKEN, POWER_SUPPLY_CHARGE_TYPE_STANDARD },
> +	{ BAT_ADAPTIVE_MODE_TOKEN, POWER_SUPPLY_CHARGE_TYPE_ADAPTIVE },
> +	{ BAT_CUSTOM_MODE_TOKEN,   POWER_SUPPLY_CHARGE_TYPE_CUSTOM },
>  };
>  static u32 battery_supported_modes;
>  
> @@ -2261,46 +2261,42 @@ static ssize_t charge_types_show(struct device *dev,
>  		struct device_attribute *attr,
>  		char *buf)
>  {
> -	ssize_t count = 0;
> +	enum power_supply_charge_type charge_type;
>  	int i;
>  
>  	for (i = 0; i < ARRAY_SIZE(battery_modes); i++) {
> -		bool active;
> +		charge_type = battery_modes[i].charge_type;
>  
> -		if (!(battery_supported_modes & BIT(i)))
> +		if (!(battery_supported_modes & BIT(charge_type)))
>  			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 (!dell_battery_mode_is_active(battery_modes[i].token))
> +			continue;
> +
> +		return power_supply_charge_types_show(dev, battery_supported_modes,
> +						      charge_type, buf);
>  	}
>  
> -	/* convert the last space to a newline */
> -	if (count > 0)
> -		count--;
> -	count += sysfs_emit_at(buf, count, "\n");
> -
> -	return count;
> +	/* No active mode found */
> +	return -EIO;
>  }
>  
>  static ssize_t charge_types_store(struct device *dev,
>  		struct device_attribute *attr,
>  		const char *buf, size_t size)
>  {
> -	bool matched = false;
> -	int err, i;
> +	int charge_type, err, i;
> +
> +	charge_type = power_supply_charge_types_parse(battery_supported_modes, buf);
> +	if (charge_type < 0)
> +		return charge_type;
>  
>  	for (i = 0; i < ARRAY_SIZE(battery_modes); i++) {
> -		if (!(battery_supported_modes & BIT(i)))
> -			continue;
> -
> -		if (sysfs_streq(battery_modes[i].label, buf)) {
> -			matched = true;
> +		if (battery_modes[i].charge_type == charge_type)
>  			break;
> -		}
>  	}
> -	if (!matched)
> -		return -EINVAL;
> +	if (i == ARRAY_SIZE(battery_modes))
> +		return -EIO;

Hi Hans,

Is this errno change helpful/correct? There is zero I/O done before 
reaching this point, just input validation, so why does it return errno 
that is "I/O error"? If you want to differentiate from -EINVAL, I suggest 
using -ENOENT (but I personally think -EINVAL would be fine as well 
because it's still an invalid argument even if it passed one stage of 
the input checks).

-- 
 i.


>  
>  	err = dell_battery_set_mode(battery_modes[i].token);
>  	if (err)
> @@ -2430,7 +2426,7 @@ static u32 __init battery_get_supported_modes(void)
>  
>  	for (i = 0; i < ARRAY_SIZE(battery_modes); i++) {
>  		if (dell_smbios_find_token(battery_modes[i].token))
> -			modes |= BIT(i);
> +			modes |= BIT(battery_modes[i].charge_type);
>  	}
>  
>  	return modes;
> 

  reply	other threads:[~2024-12-17 12:01 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-12-11 17:44 [PATCH v4 0/4] power: supply: Add new "charge_types" property Hans de Goede
2024-12-11 17:44 ` [PATCH v4 1/4] power: supply: power_supply_show_enum_with_available(): Replace spaces with '_' Hans de Goede
2024-12-11 17:44 ` [PATCH v4 2/4] power: supply: core: Add new "charge_types" property Hans de Goede
2024-12-11 19:27   ` Thomas Weißschuh
2024-12-11 17:44 ` [PATCH v4 3/4] power: supply: bq24190_charger: Add support for " Hans de Goede
2024-12-11 17:44 ` [PATCH v4 4/4] platform/x86: dell-laptop: Use power_supply_charge_types_show/_parse() helpers Hans de Goede
2024-12-17 12:01   ` Ilpo Järvinen [this message]
2024-12-17 15:18     ` Hans de Goede
2024-12-17 15:24       ` Ilpo Järvinen
2024-12-17 18:49       ` Thomas Weißschuh
2024-12-21 13:02         ` Hans de Goede
2024-12-20  0:07       ` Sebastian Reichel
2024-12-12 23:51 ` (subset) [PATCH v4 0/4] power: supply: Add new "charge_types" property Sebastian Reichel

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=0030c3dd-c70c-d21b-de2b-ace0aeb4030d@linux.intel.com \
    --to=ilpo.jarvinen@linux.intel.com \
    --cc=andy@kernel.org \
    --cc=hdegoede@redhat.com \
    --cc=jelle@vdwaa.nl \
    --cc=linux-pm@vger.kernel.org \
    --cc=linux@weissschuh.net \
    --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