All of lore.kernel.org
 help / color / mirror / Atom feed
From: Chris Morgan <macroalpha82@gmail.com>
To: linux-rockchip@lists.infradead.org
Cc: linux-pm@vger.kernel.org, devicetree@vger.kernel.org,
	jagan@edgeble.ai, andyshrk@163.com, jonas@kwiboo.se,
	sre@kernel.org, t.schramm@manjaro.org, heiko@sntech.de,
	conor+dt@kernel.org, krzk+dt@kernel.org, robh@kernel.org,
	Chris Morgan <macromorgan@hotmail.com>
Subject: [PATCH 2/5] power: supply: cw2015: Add support for dual-cell configurations
Date: Fri, 26 Jul 2024 14:49:45 -0500	[thread overview]
Message-ID: <20240726194948.109326-3-macroalpha82@gmail.com> (raw)
In-Reply-To: <20240726194948.109326-1-macroalpha82@gmail.com>

From: Chris Morgan <macromorgan@hotmail.com>

The Cellwise cw2015 datasheet reports that it can handle two cells
in a series configuration. Allow a device tree parameter to note
this condition so that the driver reports the correct voltage values
to userspace.

Signed-off-by: Chris Morgan <macromorgan@hotmail.com>
---
 drivers/power/supply/cw2015_battery.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/drivers/power/supply/cw2015_battery.c b/drivers/power/supply/cw2015_battery.c
index f63c3c410451..b23a6d4fa4fa 100644
--- a/drivers/power/supply/cw2015_battery.c
+++ b/drivers/power/supply/cw2015_battery.c
@@ -77,6 +77,8 @@ struct cw_battery {
 	u32 poll_interval_ms;
 	u8 alert_level;
 
+	bool dual_cell;
+
 	unsigned int read_errors;
 	unsigned int charge_stuck_cnt;
 };
@@ -325,6 +327,9 @@ static int cw_get_voltage(struct cw_battery *cw_bat)
 	 */
 	voltage_mv = avg * 312 / 1024;
 
+	if (cw_bat->dual_cell)
+		voltage_mv *= 2;
+
 	dev_dbg(cw_bat->dev, "Read voltage: %d mV, raw=0x%04x\n",
 		voltage_mv, reg_val);
 	return voltage_mv;
@@ -587,6 +592,8 @@ static int cw2015_parse_properties(struct cw_battery *cw_bat)
 			return ret;
 	}
 
+	cw_bat->dual_cell = device_property_read_bool(dev, "cellwise,dual-cell");
+
 	ret = device_property_read_u32(dev, "cellwise,monitor-interval-ms",
 				       &cw_bat->poll_interval_ms);
 	if (ret) {
-- 
2.34.1


WARNING: multiple messages have this Message-ID (diff)
From: Chris Morgan <macroalpha82@gmail.com>
To: linux-rockchip@lists.infradead.org
Cc: linux-pm@vger.kernel.org, devicetree@vger.kernel.org,
	jagan@edgeble.ai, andyshrk@163.com, jonas@kwiboo.se,
	sre@kernel.org, t.schramm@manjaro.org, heiko@sntech.de,
	conor+dt@kernel.org, krzk+dt@kernel.org, robh@kernel.org,
	Chris Morgan <macromorgan@hotmail.com>
Subject: [PATCH 2/5] power: supply: cw2015: Add support for dual-cell configurations
Date: Fri, 26 Jul 2024 14:49:45 -0500	[thread overview]
Message-ID: <20240726194948.109326-3-macroalpha82@gmail.com> (raw)
In-Reply-To: <20240726194948.109326-1-macroalpha82@gmail.com>

From: Chris Morgan <macromorgan@hotmail.com>

The Cellwise cw2015 datasheet reports that it can handle two cells
in a series configuration. Allow a device tree parameter to note
this condition so that the driver reports the correct voltage values
to userspace.

Signed-off-by: Chris Morgan <macromorgan@hotmail.com>
---
 drivers/power/supply/cw2015_battery.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/drivers/power/supply/cw2015_battery.c b/drivers/power/supply/cw2015_battery.c
index f63c3c410451..b23a6d4fa4fa 100644
--- a/drivers/power/supply/cw2015_battery.c
+++ b/drivers/power/supply/cw2015_battery.c
@@ -77,6 +77,8 @@ struct cw_battery {
 	u32 poll_interval_ms;
 	u8 alert_level;
 
+	bool dual_cell;
+
 	unsigned int read_errors;
 	unsigned int charge_stuck_cnt;
 };
@@ -325,6 +327,9 @@ static int cw_get_voltage(struct cw_battery *cw_bat)
 	 */
 	voltage_mv = avg * 312 / 1024;
 
+	if (cw_bat->dual_cell)
+		voltage_mv *= 2;
+
 	dev_dbg(cw_bat->dev, "Read voltage: %d mV, raw=0x%04x\n",
 		voltage_mv, reg_val);
 	return voltage_mv;
@@ -587,6 +592,8 @@ static int cw2015_parse_properties(struct cw_battery *cw_bat)
 			return ret;
 	}
 
+	cw_bat->dual_cell = device_property_read_bool(dev, "cellwise,dual-cell");
+
 	ret = device_property_read_u32(dev, "cellwise,monitor-interval-ms",
 				       &cw_bat->poll_interval_ms);
 	if (ret) {
-- 
2.34.1


_______________________________________________
Linux-rockchip mailing list
Linux-rockchip@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-rockchip

  parent reply	other threads:[~2024-07-26 19:52 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-07-26 19:49 [PATCH 0/5] Add GameForce Ace Chris Morgan
2024-07-26 19:49 ` Chris Morgan
2024-07-26 19:49 ` [PATCH 1/5] dt-bindings: power: supply: add dual-cell for cw2015 Chris Morgan
2024-07-26 19:49   ` Chris Morgan
2024-07-30 16:36   ` Rob Herring
2024-07-30 16:36     ` Rob Herring
2024-07-26 19:49 ` Chris Morgan [this message]
2024-07-26 19:49   ` [PATCH 2/5] power: supply: cw2015: Add support for dual-cell configurations Chris Morgan
2024-07-26 21:06   ` Sebastian Reichel
2024-07-26 21:06     ` Sebastian Reichel
2024-07-31 16:02     ` Chris Morgan
2024-07-31 16:02       ` Chris Morgan
2024-07-31 17:02       ` Sebastian Reichel
2024-07-31 17:02         ` Sebastian Reichel
2024-07-31 17:14         ` Chris Morgan
2024-07-31 17:14           ` Chris Morgan
2024-08-02 21:39         ` Dragan Simic
2024-08-02 21:39           ` Dragan Simic
2024-08-04 16:29           ` Sebastian Reichel
2024-08-04 16:29             ` Sebastian Reichel
2024-08-04 16:42             ` Dragan Simic
2024-08-04 16:42               ` Dragan Simic
2024-07-26 19:49 ` [PATCH 3/5] arm64: dts: rockchip: Pull up sdio pins on RK3588 Chris Morgan
2024-07-26 19:49   ` Chris Morgan
2024-07-26 21:42   ` Heiko Stübner
2024-07-26 21:42     ` Heiko Stübner
2024-07-31 15:30     ` Chris Morgan
2024-07-31 15:30       ` Chris Morgan
2024-07-26 19:49 ` [PATCH 4/5] dt-bindings: arm: rockchip: Add GameForce Ace Chris Morgan
2024-07-26 19:49   ` Chris Morgan
2024-07-27  9:09   ` Krzysztof Kozlowski
2024-07-27  9:09     ` Krzysztof Kozlowski
2024-07-26 19:49 ` [PATCH 5/5] arm64: dts: " Chris Morgan
2024-07-26 19:49   ` Chris Morgan
2024-07-29 18:52 ` [PATCH 0/5] " Rob Herring (Arm)
2024-07-29 18:52   ` Rob Herring (Arm)
2024-07-31 15:32   ` Chris Morgan
2024-07-31 15:32     ` Chris Morgan

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=20240726194948.109326-3-macroalpha82@gmail.com \
    --to=macroalpha82@gmail.com \
    --cc=andyshrk@163.com \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=heiko@sntech.de \
    --cc=jagan@edgeble.ai \
    --cc=jonas@kwiboo.se \
    --cc=krzk+dt@kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=linux-rockchip@lists.infradead.org \
    --cc=macromorgan@hotmail.com \
    --cc=robh@kernel.org \
    --cc=sre@kernel.org \
    --cc=t.schramm@manjaro.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.