Linux Power Management development
 help / color / mirror / Atom feed
From: Sebastian Reichel <sre@kernel.org>
To: Linus Walleij <linus.walleij@linaro.org>
Cc: Marcus Cooper <codekipper@gmail.com>, linux-pm@vger.kernel.org
Subject: Re: [PATCH 2/2 v2] power: supply: core: Parse battery type/technology
Date: Thu, 5 Aug 2021 18:04:14 +0200	[thread overview]
Message-ID: <20210805160414.xayo7pt4mzqtmlak@earth.universe> (raw)
In-Reply-To: <20210805085828.3451909-2-linus.walleij@linaro.org>

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

Hi,

On Thu, Aug 05, 2021 at 10:58:28AM +0200, Linus Walleij wrote:
> This extends the struct power_supply_battery_info with a
> "technology" field makes the core DT parser optionally obtain
> this from the device tree.
> 
> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
> ---

Reviewed-by: Sebastian Reichel <sebastian.reichel@collabora.com>

-- Sebastian

> ChangeLog v1->v2:
> - Drop the accidental double assignment of err as reported
>   by the kernel test robot et al.
> - Switch to "device-chemistry" instead of "battery-type"
>   to indicate the type.
> This is needed to migrate the STE AB8500 custom battery bindings
> and parser to the generic parser.
> ---
>  drivers/power/supply/power_supply_core.c | 20 ++++++++++++++++++++
>  include/linux/power_supply.h             |  1 +
>  2 files changed, 21 insertions(+)
> 
> diff --git a/drivers/power/supply/power_supply_core.c b/drivers/power/supply/power_supply_core.c
> index d99e2f11c183..dd62c871b2b5 100644
> --- a/drivers/power/supply/power_supply_core.c
> +++ b/drivers/power/supply/power_supply_core.c
> @@ -571,6 +571,7 @@ int power_supply_get_battery_info(struct power_supply *psy,
>  	int err, len, index;
>  	const __be32 *list;
>  
> +	info->technology                     = POWER_SUPPLY_TECHNOLOGY_UNKNOWN;
>  	info->energy_full_design_uwh         = -EINVAL;
>  	info->charge_full_design_uah         = -EINVAL;
>  	info->voltage_min_design_uv          = -EINVAL;
> @@ -618,6 +619,25 @@ int power_supply_get_battery_info(struct power_supply *psy,
>  	 * Documentation/power/power_supply_class.rst.
>  	 */
>  
> +	err = of_property_read_string(battery_np, "device-chemistry", &value);
> +	if (!err) {
> +		if (!strcmp("nickel-cadmium", value))
> +			info->technology = POWER_SUPPLY_TECHNOLOGY_NiCd;
> +		else if (!strcmp("nickel-metal-hydride", value))
> +			info->technology = POWER_SUPPLY_TECHNOLOGY_NiMH;
> +		else if (!strcmp("lithium-ion", value))
> +			/* Imprecise lithium-ion type */
> +			info->technology = POWER_SUPPLY_TECHNOLOGY_LION;
> +		else if (!strcmp("lithium-ion-polymer", value))
> +			info->technology = POWER_SUPPLY_TECHNOLOGY_LIPO;
> +		else if (!strcmp("lithium-ion-iron-phosphate", value))
> +			info->technology = POWER_SUPPLY_TECHNOLOGY_LiFe;
> +		else if (!strcmp("lithium-ion-manganese-oxide", value))
> +			info->technology = POWER_SUPPLY_TECHNOLOGY_LiMn;
> +		else
> +			dev_warn(&psy->dev, "%s unknown battery type\n", value);
> +	}
> +
>  	of_property_read_u32(battery_np, "energy-full-design-microwatt-hours",
>  			     &info->energy_full_design_uwh);
>  	of_property_read_u32(battery_np, "charge-full-design-microamp-hours",
> diff --git a/include/linux/power_supply.h b/include/linux/power_supply.h
> index be203985ecdd..9ca1f120a211 100644
> --- a/include/linux/power_supply.h
> +++ b/include/linux/power_supply.h
> @@ -352,6 +352,7 @@ struct power_supply_resistance_temp_table {
>   */
>  
>  struct power_supply_battery_info {
> +	unsigned int technology;	    /* from the enum above */
>  	int energy_full_design_uwh;	    /* microWatt-hours */
>  	int charge_full_design_uah;	    /* microAmp-hours */
>  	int voltage_min_design_uv;	    /* microVolts */
> -- 
> 2.31.1
> 

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

  reply	other threads:[~2021-08-05 16:04 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-05  8:58 [PATCH 1/2 v2] dt-bindings: power: Extend battery bindings with type Linus Walleij
2021-08-05  8:58 ` [PATCH 2/2 v2] power: supply: core: Parse battery type/technology Linus Walleij
2021-08-05 16:04   ` Sebastian Reichel [this message]
2021-08-05 16:03 ` [PATCH 1/2 v2] dt-bindings: power: Extend battery bindings with type Sebastian Reichel
2021-08-13 18:26 ` Rob Herring
2021-08-13 21:46   ` Linus Walleij
2021-08-14 10:55     ` 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=20210805160414.xayo7pt4mzqtmlak@earth.universe \
    --to=sre@kernel.org \
    --cc=codekipper@gmail.com \
    --cc=linus.walleij@linaro.org \
    --cc=linux-pm@vger.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