From: sashiko-bot@kernel.org
To: "Chris Morgan" <macroalpha82@gmail.com>
Cc: devicetree@vger.kernel.org, robh@kernel.org, conor+dt@kernel.org
Subject: Re: [PATCH V3 2/3] power: supply: cw2217: Add support for Cellwise cw2217
Date: Mon, 23 Nov 2026 02:03:02 +0000 [thread overview]
Message-ID: <sashiko-outbox-228541@kernel.org> (raw)
In-Reply-To: <20261123015035.369192-3-macroalpha82@gmail.com>
Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Low] power: supply: cw2217: cw2217_active() wakes chip before
entering shutdown
- [Low] power: supply: cw2217: inaccurate writable and volatile regmap
ranges
--
commit 9be66fa8e5df716905efd0c61236d0fe980e4cc9
Author: Chris Morgan <macromorgan@hotmail.com>
power: supply: cw2217: Add support for Cellwise cw2217
This commit adds a power supply driver for the Cellwise CW2215, CW2217, and
CW2218 I2C battery fuel gauges.
> diff --git a/drivers/power/supply/cw2217_battery.c b/drivers/power/supply/cw2217_battery.c
> new file mode 100644
> index 0000000000000..a25803865943e
> --- /dev/null
> +++ b/drivers/power/supply/cw2217_battery.c
> @@ -0,0 +1,878 @@
[ ... ]
> +/*
> + * The CONFIG register is used for the host MCU to configure the fuel gauge IC.
> + * The default value is 0xF0, SLEEP and RESTART bits are set. To power up the
> + * IC, the host MCU needs to write 0x30 to exit shutdown mode, and then write
> + * 0x00 to restart the gauge to enter active mode. To reset the IC, the host
> + * MCU needs to write 0xF0, 0x30 and 0x00 in sequence to this register to
> + * complete the restart procedure. The CW2217 will reload relevant parameters
> + * and settings and restart SOC calculation. Note that the SOC may be a
> + * different value after reset operation since it is a brand-new calculation
> + * based on the latest battery status. The BSP driver slept 20ms after restart
> + * and 10ms after setting active, though no delays are documented in the
> + * datasheet.
> + */
> +static int cw2217_active(struct cw2217_battery *cw_bat, bool active)
> +{
> + int ret;
> +
> + ret = regmap_write(cw_bat->regmap, CW2217_CONFIG,
> + CW2217_CONFIG_RESTART);
> + if (ret)
> + return ret;
> +
> + fsleep(20000);
> +
> + if (active) {
> + ret = regmap_write(cw_bat->regmap, CW2217_CONFIG,
> + CW2217_CONFIG_ACTIVE);
> + if (ret)
> + return ret;
> + } else {
> + ret = regmap_write(cw_bat->regmap, CW2217_CONFIG,
> + CW2217_CONFIG_SLEEP | CW2217_CONFIG_RESTART);
> + if (ret)
> + return ret;
> + }
> +
> + fsleep(10000);
> +
> + return 0;
> +}
[Severity: Low]
Should writing CW2217_CONFIG_RESTART (0x30) only happen when active is
true?
Writing 0x30 unconditionally means cw2217_active(cw_bat, false) in
cw2217_update_config() first wakes the gauge out of shutdown mode for 20ms
before writing 0xF0 (CW2217_CONFIG_SLEEP | CW2217_CONFIG_RESTART), producing
a 0x30 -> 0xF0 -> 0x30 -> 0x00 sequence instead of the documented
0xF0 -> 0x30 -> 0x00 reset sequence.
[ ... ]
> +static const struct regmap_range cw2217_ranges_wr_yes[] = {
> + regmap_reg_range(CW2217_TEMP, CW2217_TEMP),
> + regmap_reg_range(CW2217_CONFIG, CW2217_CONFIG),
> + regmap_reg_range(CW2217_INT_CONF, CW2217_CURRENT_L),
> + regmap_reg_range(CW2217_BAT_PROFILE,
> + CW2217_BAT_PROFILE + CW2217_PROFILE_SZ - 1),
> + regmap_reg_range(CW2217_T_HOST_H, CW2217_USER_CONF),
> +};
> +
> +static const struct regmap_access_table cw2217_wr_table = {
> + .yes_ranges = cw2217_ranges_wr_yes,
> + .n_yes_ranges = ARRAY_SIZE(cw2217_ranges_wr_yes),
> +};
> +
> +static const struct regmap_range cw2217_ranges_vol_yes[] = {
> + regmap_reg_range(CW2217_VCELL_H, CW2217_TEMP),
> + regmap_reg_range(CW2217_INT_CONF, CW2217_SOC_ALERT),
> + regmap_reg_range(CW2217_CURRENT_H, CW2217_CURRENT_L),
> + regmap_reg_range(CW2217_CYCLECNT_H, CW2217_STB_CUR_L),
> +};
[Severity: Low]
Are the writable and volatile regmap ranges for CW2217_TEMP,
CW2217_CURRENT_H..CW2217_CURRENT_L, and CW2217_FW_VERSION intended?
CW2217_TEMP (0x06) and CW2217_CURRENT_H..CW2217_CURRENT_L (0x0E..0x0F) are
documented as read-only measurement registers, yet cw2217_ranges_wr_yes
marks CW2217_TEMP as writable and extends the CW2217_INT_CONF range through
CW2217_CURRENT_L instead of stopping at CW2217_TEMP_MIN (0x0D).
In addition, CW2217_FW_VERSION (0xAB) changes in hardware between 0x00 in
shutdown mode and the chip ID / firmware version in active mode, but it is
missing from cw2217_ranges_vol_yes while REGCACHE_MAPLE is enabled. If
CW2217_FW_VERSION is read while the chip is in shutdown mode (for example
via regmap debugfs), 0x00 is cached and subsequent reads in active mode will
return 0x00, causing cw2217_get_current() to fail with -EIO.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261123015035.369192-1-macroalpha82@gmail.com?part=2
next prev parent reply other threads:[~2026-11-23 2:03 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-23 1:50 [PATCH V3 0/3] Add Cellwise CW2217 Chris Morgan
2026-11-23 1:50 ` Chris Morgan
2026-11-23 1:50 ` [PATCH V3 1/3] dt-bindings: power: cw2015: add cw2215, cw2217, and cw2218 Chris Morgan
2026-11-23 1:50 ` Chris Morgan
2026-11-23 1:50 ` [PATCH V3 2/3] power: supply: cw2217: Add support for Cellwise cw2217 Chris Morgan
2026-11-23 1:50 ` Chris Morgan
2026-11-23 2:03 ` sashiko-bot [this message]
2026-11-23 1:50 ` [PATCH V3 3/3] arm64: dts: rockchip: Add Battery Gauge to Anbernic Vita-Pro Chris Morgan
2026-11-23 1:50 ` 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=sashiko-outbox-228541@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=macroalpha82@gmail.com \
--cc=robh@kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
/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.