All of lore.kernel.org
 help / color / mirror / Atom feed
From: Hans de Goede <hansg@kernel.org>
To: Sebastian Reichel <sre@kernel.org>
Cc: Hans de Goede <hansg@kernel.org>, Mark Brown <broonie@kernel.org>,
	AngeloGioacchino Del Regno
	<angelogioacchino.delregno@collabora.com>,
	Linus Walleij <linus.walleij@linaro.org>,
	linux-pm@vger.kernel.org
Subject: [PATCH 08/10] power: supply: ug3105_battery: Use psy->battery_info
Date: Sun,  8 Jun 2025 22:40:08 +0200	[thread overview]
Message-ID: <20250608204010.37482-9-hansg@kernel.org> (raw)
In-Reply-To: <20250608204010.37482-1-hansg@kernel.org>

For POWER_SUPPLY_TYPE_BATTERY power-supplies the core already
calls power_supply_get_battery_info() and stores the result in
psy->battery_info.

Use psy->battery_info instead of having the driver call
power_supply_get_battery_info() itself.

Signed-off-by: Hans de Goede <hansg@kernel.org>
---
 drivers/power/supply/ug3105_battery.c | 17 +++++++----------
 1 file changed, 7 insertions(+), 10 deletions(-)

diff --git a/drivers/power/supply/ug3105_battery.c b/drivers/power/supply/ug3105_battery.c
index 38e23bdd4603..806f6892e189 100644
--- a/drivers/power/supply/ug3105_battery.c
+++ b/drivers/power/supply/ug3105_battery.c
@@ -69,7 +69,6 @@
 struct ug3105_chip {
 	struct i2c_client *client;
 	struct power_supply *psy;
-	struct power_supply_battery_info *info;
 	struct delayed_work work;
 	struct mutex lock;
 	int ocv[UG3105_MOV_AVG_WINDOW];		/* micro-volt */
@@ -103,7 +102,8 @@ static int ug3105_read_word(struct i2c_client *client, u8 reg)
 
 static int ug3105_get_status(struct ug3105_chip *chip)
 {
-	int full = chip->info->constant_charge_voltage_max_uv - UG3105_FULL_BAT_HYST_UV;
+	int full = chip->psy->battery_info->constant_charge_voltage_max_uv -
+		   UG3105_FULL_BAT_HYST_UV;
 
 	if (chip->curr > UG3105_CURR_HYST_UA)
 		return POWER_SUPPLY_STATUS_CHARGING;
@@ -164,7 +164,7 @@ static int ug3105_get_capacity(struct ug3105_chip *chip)
 		ocv_diff = ocv_capacity_tbl[i] - chip->ocv_avg;
 		ocv_step = ocv_capacity_tbl[i] - ocv_capacity_tbl[i - 1];
 		/* scale 0-110% down to 0-100% for LiPo HV */
-		if (chip->info->constant_charge_voltage_max_uv >= 4300000)
+		if (chip->psy->battery_info->constant_charge_voltage_max_uv >= 4300000)
 			return (i * 500 - ocv_diff * 500 / ocv_step) / 110;
 		else
 			return i * 5 - ocv_diff * 5 / ocv_step;
@@ -401,12 +401,9 @@ static int ug3105_probe(struct i2c_client *client)
 	if (IS_ERR(psy))
 		return PTR_ERR(psy);
 
-	ret = power_supply_get_battery_info(psy, &chip->info);
-	if (ret)
-		return ret;
-
-	if (chip->info->factory_internal_resistance_uohm == -EINVAL ||
-	    chip->info->constant_charge_voltage_max_uv == -EINVAL) {
+	if (!psy->battery_info ||
+	    psy->battery_info->factory_internal_resistance_uohm == -EINVAL ||
+	    psy->battery_info->constant_charge_voltage_max_uv == -EINVAL) {
 		dev_err(dev, "error required properties are missing\n");
 		return -ENODEV;
 	}
@@ -422,7 +419,7 @@ static int ug3105_probe(struct i2c_client *client)
 	chip->ua_per_unit = 8100000 / curr_sense_res_uohm;
 
 	/* Use provided internal resistance as start point (in milli-ohm) */
-	chip->intern_res_avg = chip->info->factory_internal_resistance_uohm / 1000;
+	chip->intern_res_avg = psy->battery_info->factory_internal_resistance_uohm / 1000;
 	/* Also add it to the internal resistance moving average window */
 	chip->intern_res[0] = chip->intern_res_avg;
 	chip->intern_res_avg_index = 1;
-- 
2.49.0


  parent reply	other threads:[~2025-06-08 20:40 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-06-08 20:40 [PATCH 00/10] power: supply: ug3105_battery: Switch to power_supply_batinfo_ocv2cap() Hans de Goede
2025-06-08 20:40 ` [PATCH 01/10] regulator: act8865-regulator: switch psy_cfg from of_node to fwnode Hans de Goede
2025-06-08 20:40 ` [PATCH 02/10] power: supply: core: remove of_node from power_supply_config Hans de Goede
2025-06-08 20:40 ` [PATCH 03/10] power: supply: core: battery-info: fully switch to fwnode Hans de Goede
2025-06-08 20:40 ` [PATCH 04/10] fixup! " Hans de Goede
2025-06-08 20:40 ` [PATCH 05/10] " Hans de Goede
2025-06-08 20:40 ` [PATCH 06/10] power: supply: core: convert to fwnnode Hans de Goede
2025-06-08 20:40 ` [PATCH 07/10] power: supply: core: rename power_supply_get_by_phandle to power_supply_get_by_reference Hans de Goede
2025-06-08 20:40 ` Hans de Goede [this message]
2025-06-08 20:40 ` [PATCH 09/10] power: supply: ug3105_battery: Switch to power_supply_batinfo_ocv2cap() Hans de Goede
2025-06-08 20:40 ` [PATCH 10/10] power: supply: bq24190: Free battery_info Hans de Goede
2025-06-22  0:10 ` (subset) [PATCH 00/10] power: supply: ug3105_battery: Switch to power_supply_batinfo_ocv2cap() Sebastian Reichel
2025-06-22  1:09   ` Sebastian Reichel
2025-06-26 23:31     ` Mark Brown
2025-07-06 23:36       ` 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=20250608204010.37482-9-hansg@kernel.org \
    --to=hansg@kernel.org \
    --cc=angelogioacchino.delregno@collabora.com \
    --cc=broonie@kernel.org \
    --cc=linus.walleij@linaro.org \
    --cc=linux-pm@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.