Re: [PATCH 2/5] power: supply: bd71828: Fix current direction
Andy Shevchenko <[email protected]>
| Newsgroups | org.kernel.vger.linux-pm,org.kernel.vger.linux-kernel |
|---|---|
| Organization | Intel Finland Oy - BIC 0357606-4 - c/o Alberga Business Park, 6 krs, Bertel Jungin Aukio 5, 02600 Espoo |
| Message-ID | <[email protected]> |
On Wed, Aug 12, 2026 at 12:37:49PM +0300, Matti Vaittinen wrote: > On 12/08/2026 12:30, Andy Shevchenko wrote: > > On Wed, Aug 12, 2026 at 10:25:36AM +0200, Andreas Kemnade wrote: > > > On Wed, 12 Aug 2026 11:17:36 +0300 > > > Andy Shevchenko <[email protected]> wrote: > > > > On Wed, Aug 12, 2026 at 10:10:50AM +0200, Andreas Kemnade wrote: > > > > > On Mon, 10 Aug 2026 13:09:07 +0300 > > > > > Matti Vaittinen <[email protected]> wrote: ... > > > > > 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 > > > > > > > > Do you mean existing sign_extend32() from bitops.h? > > > > > > > > > > I don't think it does what is needed. Here we have > > > > > > 0000 0000 0000 0001 -> 1 > > > Usually we have > > > > > > 1111 1111 1111 1111 -> -1 > > > > > > but here > > > > > > 1000 0000 0000 0001 -> -1 > > > > I see, wouldn't this be then as simple as > > > > sign = $REGVAL & BIT(15 /* sign bit */); > > if (sign) > > $REGVAL = sign - $REGVAL; > > I find this more confusing than the current idea, which effectively is: > > if (sign) > val = val_without_sign * -1; > else > val = val_without_sign (* 1); If you have other use for val_wo_sign, then you can even drop multiplication. val = sign ? -val_wo_sing: val_wo_sign; More comprehensive view sign = $REGVAL & BIT(15 /* sign bit */); $REGVAL &= ~sign; val = sign ? -$REGVAL : $REGVAL; -- With Best Regards, Andy Shevchenko