2019-11-16 14:02:10

by Paul Cercueil

[permalink] [raw]
Subject: [PATCH v3] power/supply: ingenic-battery: Don't change scale if there's only one

The ADC in the JZ4740 can work either in high-precision mode with a 2.5V
range, or in low-precision mode with a 7.5V range. The code in place in
this driver will select the proper scale according to the maximum
voltage of the battery.

The JZ4770 however only has one mode, with a 6.6V range. If only one
scale is available, there's no need to change it (and nothing to change
it to), and trying to do so will fail with -EINVAL.

Fixes: fb24ccfbe1e0 ("power: supply: add Ingenic JZ47xx battery driver.")

Signed-off-by: Paul Cercueil <[email protected]>
Cc: [email protected]
---

Notes:
v2: Rebased on v5.4-rc7
v3: Move code after check for max scale voltage

drivers/power/supply/ingenic-battery.c | 15 +++++++++++----
1 file changed, 11 insertions(+), 4 deletions(-)

diff --git a/drivers/power/supply/ingenic-battery.c b/drivers/power/supply/ingenic-battery.c
index 35816d4b3012..2748715c4c75 100644
--- a/drivers/power/supply/ingenic-battery.c
+++ b/drivers/power/supply/ingenic-battery.c
@@ -100,10 +100,17 @@ static int ingenic_battery_set_scale(struct ingenic_battery *bat)
return -EINVAL;
}

- return iio_write_channel_attribute(bat->channel,
- scale_raw[best_idx],
- scale_raw[best_idx + 1],
- IIO_CHAN_INFO_SCALE);
+ /* Only set scale if there is more than one (fractional) entry */
+ if (scale_len > 2) {
+ ret = iio_write_channel_attribute(bat->channel,
+ scale_raw[best_idx],
+ scale_raw[best_idx + 1],
+ IIO_CHAN_INFO_SCALE);
+ if (ret)
+ return ret;
+ }
+
+ return 0;
}

static enum power_supply_property ingenic_battery_properties[] = {
--
2.24.0


2019-11-16 14:10:20

by Artur Rojek

[permalink] [raw]
Subject: Re: [PATCH v3] power/supply: ingenic-battery: Don't change scale if there's only one

On 2019-11-16 14:56, Paul Cercueil wrote:
> The ADC in the JZ4740 can work either in high-precision mode with a
> 2.5V
> range, or in low-precision mode with a 7.5V range. The code in place in
> this driver will select the proper scale according to the maximum
> voltage of the battery.
>
> The JZ4770 however only has one mode, with a 6.6V range. If only one
> scale is available, there's no need to change it (and nothing to change
> it to), and trying to do so will fail with -EINVAL.
>
> Fixes: fb24ccfbe1e0 ("power: supply: add Ingenic JZ47xx battery
> driver.")
>
> Signed-off-by: Paul Cercueil <[email protected]>
> Cc: [email protected]

Looks good to me!

Acked-by: Artur Rojek <[email protected]>

> ---
>
> Notes:
> v2: Rebased on v5.4-rc7
> v3: Move code after check for max scale voltage
>
> drivers/power/supply/ingenic-battery.c | 15 +++++++++++----
> 1 file changed, 11 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/power/supply/ingenic-battery.c
> b/drivers/power/supply/ingenic-battery.c
> index 35816d4b3012..2748715c4c75 100644
> --- a/drivers/power/supply/ingenic-battery.c
> +++ b/drivers/power/supply/ingenic-battery.c
> @@ -100,10 +100,17 @@ static int ingenic_battery_set_scale(struct
> ingenic_battery *bat)
> return -EINVAL;
> }
>
> - return iio_write_channel_attribute(bat->channel,
> - scale_raw[best_idx],
> - scale_raw[best_idx + 1],
> - IIO_CHAN_INFO_SCALE);
> + /* Only set scale if there is more than one (fractional) entry */
> + if (scale_len > 2) {
> + ret = iio_write_channel_attribute(bat->channel,
> + scale_raw[best_idx],
> + scale_raw[best_idx + 1],
> + IIO_CHAN_INFO_SCALE);
> + if (ret)
> + return ret;
> + }
> +
> + return 0;
> }
>
> static enum power_supply_property ingenic_battery_properties[] = {

2019-12-19 00:19:58

by Sebastian Reichel

[permalink] [raw]
Subject: Re: [PATCH v3] power/supply: ingenic-battery: Don't change scale if there's only one

Hi,

On Sat, Nov 16, 2019 at 03:08:46PM +0100, Artur Rojek wrote:
> On 2019-11-16 14:56, Paul Cercueil wrote:
> > The ADC in the JZ4740 can work either in high-precision mode with a 2.5V
> > range, or in low-precision mode with a 7.5V range. The code in place in
> > this driver will select the proper scale according to the maximum
> > voltage of the battery.
> >
> > The JZ4770 however only has one mode, with a 6.6V range. If only one
> > scale is available, there's no need to change it (and nothing to change
> > it to), and trying to do so will fail with -EINVAL.
> >
> > Fixes: fb24ccfbe1e0 ("power: supply: add Ingenic JZ47xx battery
> > driver.")
> >
> > Signed-off-by: Paul Cercueil <[email protected]>
> > Cc: [email protected]
>
> Looks good to me!
>
> Acked-by: Artur Rojek <[email protected]>

Thanks, queued to power-supply's for-next branch.

-- Sebastian

> > ---
> >
> > Notes:
> > v2: Rebased on v5.4-rc7
> > v3: Move code after check for max scale voltage
> >
> > drivers/power/supply/ingenic-battery.c | 15 +++++++++++----
> > 1 file changed, 11 insertions(+), 4 deletions(-)
> >
> > diff --git a/drivers/power/supply/ingenic-battery.c
> > b/drivers/power/supply/ingenic-battery.c
> > index 35816d4b3012..2748715c4c75 100644
> > --- a/drivers/power/supply/ingenic-battery.c
> > +++ b/drivers/power/supply/ingenic-battery.c
> > @@ -100,10 +100,17 @@ static int ingenic_battery_set_scale(struct
> > ingenic_battery *bat)
> > return -EINVAL;
> > }
> >
> > - return iio_write_channel_attribute(bat->channel,
> > - scale_raw[best_idx],
> > - scale_raw[best_idx + 1],
> > - IIO_CHAN_INFO_SCALE);
> > + /* Only set scale if there is more than one (fractional) entry */
> > + if (scale_len > 2) {
> > + ret = iio_write_channel_attribute(bat->channel,
> > + scale_raw[best_idx],
> > + scale_raw[best_idx + 1],
> > + IIO_CHAN_INFO_SCALE);
> > + if (ret)
> > + return ret;
> > + }
> > +
> > + return 0;
> > }
> >
> > static enum power_supply_property ingenic_battery_properties[] = {


Attachments:
(No filename) (2.09 kB)
signature.asc (849.00 B)
Download all attachments