Re: [PATCH v3 14/16] power: axp20x_battery: Add constant charge current table

From: Andy Shevchenko
Date: Sun Jun 19 2022 - 07:30:33 EST


On Sat, Jun 18, 2022 at 11:40 PM Aidan MacDonald
<aidanmacdonald.0x0@xxxxxxxxx> wrote:
>
> Add a table-based lookup method for constant charge current,
> which is necessary when the setting cannot be represented as
> a linear range.
>
> This also replaces the hard-coded 300 mA default ccc setting
> if the DT-specified value is unsupported; the minimum value
> for the device is now set exactly instead of relying on the
> value being rounded down to a supported value.

...

> +static int axp20x_get_constant_charge_current_sel(struct axp20x_batt_ps *axp_batt,
> + int charge_current)
> +{
> + int i;
> +
> + if (axp_batt->data->ccc_table) {
> + for (i = AXP20X_CHRG_CTRL1_TGT_CURR; i >= 0; --i) {

i-- should give the same result.

> + if (axp_batt->data->ccc_table[i] <= charge_current)
> + return i;
> + }
> +
> + return -EINVAL;
> + }

> + i = (charge_current - axp_batt->data->ccc_offset) / axp_batt->data->ccc_scale;

> +

No need to have a blank line here.

> + if (i > AXP20X_CHRG_CTRL1_TGT_CURR || i < 0)
> + return -EINVAL;
> +
> + return i;
> +}

--
With Best Regards,
Andy Shevchenko