From: Andreas Kemnade <andreas@kemnade.info>
To: Matti Vaittinen <matti.vaittinen@linux.dev>
Cc: "Matti Vaittinen" <mazziesaccount@gmail.com>,
"Matti Vaittinen" <matti.vaittinen@fi.rohmeurope.com>,
"Sebastian Reichel" <sre@kernel.org>,
"Andy Shevchenko" <andriy.shevchenko@linux.intel.com>,
linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org,
"Kalle Niemi" <kaleposti@gmail.com>,
"Topi Sonkajärvi" <sonkajarvi@hotmail.com>,
"Mikko Mutanen" <mikko.mutanen@fi.rohmeurope.com>,
"Markus Laine" <markus.laine@fi.rohmeurope.com>
Subject: Re: [PATCH 2/5] power: supply: bd71828: Fix current direction
Date: Wed, 12 Aug 2026 10:10:50 +0200 [thread overview]
Message-ID: <20260812101050.575c9bfb@kemnade.info> (raw)
In-Reply-To: <22c6816204b3f2a8b50df8171e384937822d195b.1786356145.git.mazziesaccount@gmail.com>
On Mon, 10 Aug 2026 13:09:07 +0300
Matti Vaittinen <matti.vaittinen@linux.dev> wrote:
> From: Matti Vaittinen <mazziesaccount@gmail.com>
>
> Both the current and the average current registers contain same
> 'direction' -bit to denote the direction of the current. The code
> reading these registers incorrectly caches the direction read from the
> first register, and uses it also for the second.
>
> Fix this by initializing the direction bit for both register reads.
>
> Signed-off-by: Matti Vaittinen <mazziesaccount@gmail.com>
> Fixes: 5bff79dad20a ("power: supply: Add bd718(15/28/78) charger driver")
Weird. I reported that issue after you have submitted an RFC.
current_avg just changing direction after disconnecting power supply.
Then I had a fix to enable current_now property.
Somehow we thought that averaging current in the chip ist just weird.
But now it makes sense.
Tested-by: Andreas Kemnade <andreas@kemnade.info> # Kobo Clara 2e rev B
> ---
> drivers/power/supply/bd71828-power.c | 5 +++--
> 1 file changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/power/supply/bd71828-power.c b/drivers/power/supply/bd71828-power.c
> index e1ae5fe52e1d..9927a7e8934a 100644
> --- a/drivers/power/supply/bd71828-power.c
> +++ b/drivers/power/supply/bd71828-power.c
> @@ -192,12 +192,13 @@ static int bd71828_get_current_ds_adc(struct bd71828_power *pwr, int *curr, int
> {
> __be16 tmp_curr;
> char *tmp = (char *)&tmp_curr;
> - int dir = 1;
> int regs[] = { pwr->regs->ibat, pwr->regs->ibat_avg };
> int *vals[] = { curr, curr_avg };
> int ret, i;
>
> - for (dir = 1, i = 0; i < ARRAY_SIZE(regs); i++) {
> + for (i = 0; i < ARRAY_SIZE(regs); i++) {
> + int dir = 1;
> +
> ret = regmap_bulk_read(pwr->regmap, regs[i], &tmp_curr,
> sizeof(tmp_curr));
> if (ret)
That code is complicated. What about a generic 16bit non_2complemented sign
to 2-complemented sign function/macro. Such would have prevented the error
in the first places. So &vals[i] = signbit_to_2complement(be16_to_cpu(tmp_curr), 15) * pwr->curr_factor
Regards,
Andreas
next prev parent reply other threads:[~2026-08-12 8:10 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-10 10:08 [PATCH 0/5] ROHM bd71828 power-supply fixes Matti Vaittinen
2026-08-10 10:08 ` [PATCH 1/5] power: supply: bd71815: Fix temperature reading Matti Vaittinen
2026-08-10 10:09 ` [PATCH 2/5] power: supply: bd71828: Fix current direction Matti Vaittinen
2026-08-10 17:18 ` Andy Shevchenko
2026-08-11 8:46 ` Matti Vaittinen
2026-08-11 10:04 ` Andy Shevchenko
2026-08-12 8:10 ` Andreas Kemnade [this message]
2026-08-12 8:17 ` Andy Shevchenko
2026-08-12 8:25 ` Andreas Kemnade
2026-08-12 9:30 ` Andy Shevchenko
2026-08-12 9:37 ` Matti Vaittinen
2026-08-12 9:55 ` Andy Shevchenko
2026-08-12 9:40 ` Matti Vaittinen
2026-08-12 11:32 ` Andreas Kemnade
2026-08-10 10:09 ` [PATCH 3/5] power: supply: bd71828: Drop duplicate power-supply property Matti Vaittinen
2026-08-10 18:01 ` Andy Shevchenko
2026-08-10 10:09 ` [PATCH 4/5] power: supply: bd71828: Do not hide errors Matti Vaittinen
2026-08-10 10:10 ` [PATCH 5/5] power: supply: bd99954: Drop bad register fields Matti Vaittinen
2026-08-10 18:03 ` Andy Shevchenko
2026-08-12 6:59 ` [PATCH 0/5] ROHM bd71828 power-supply fixes Kalle Niemi
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=20260812101050.575c9bfb@kemnade.info \
--to=andreas@kemnade.info \
--cc=andriy.shevchenko@linux.intel.com \
--cc=kaleposti@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=markus.laine@fi.rohmeurope.com \
--cc=matti.vaittinen@fi.rohmeurope.com \
--cc=matti.vaittinen@linux.dev \
--cc=mazziesaccount@gmail.com \
--cc=mikko.mutanen@fi.rohmeurope.com \
--cc=sonkajarvi@hotmail.com \
--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