Re: [PATCH v4 2/2] power: supply: mt6360_charger: add MT6360 charger support

From: Matti Vaittinen
Date: Thu May 27 2021 - 06:22:54 EST



On Thu, 2021-05-27 at 17:58 +0800, Gene Chen wrote:
> Matti Vaittinen <matti.vaittinen@xxxxxxxxxxxxxxxxx> 於 2021年5月27日 週四
> 下午12:25寫道:
> >
> > On Wed, 2021-05-26 at 17:40 +0800, Gene Chen wrote:
> > > Matti Vaittinen <matti.vaittinen@xxxxxxxxxxxxxxxxx> 於 2021年3月30日
> > > 週二
> > > 下午7:48寫道:
> > > > On Mon, 2021-01-18 at 20:41 +0800, Gene Chen wrote:
> > > > > From: Gene Chen <gene_chen@xxxxxxxxxxx>
> > > > >
> > > > > Add basic support for the battery charger for MT6360 PMIC
> > > > >
> > > > > Signed-off-by: Gene Chen <gene_chen@xxxxxxxxxxx>
> > > > > ---
> > > > > drivers/power/supply/Kconfig | 10 +
> > > > > drivers/power/supply/Makefile | 1 +
> > > > > drivers/power/supply/mt6360_charger.c | 914
> > > > > ++++++++++++++++++++++++++++++++++
> > > > > 3 files changed, 925 insertions(+)
> > > > > create mode 100644 drivers/power/supply/mt6360_charger.c
> > > > >
> > > >
> > > > Thanks for the contribution :)
> > > >
> > > > Few comments which I am not demanding to be 'fixed' - but which
> > > > might
> > > > be good to be checked. Eg, please consider my comments as
> > > > 'nit's.
> > > >
> > > > ...
> > > >
> > > > > +static unsigned int mt6360_map_reg_sel(u32 data, u32 min,
> > > > > u32
> > > > > max,
> > > > > u32 step)
> > > > > +{
> > > > > + u32 target = 0, max_sel;
> > > > > +
> > > > > + if (data >= min) {
> > > > > + target = (data - min) / step;
> > > > > + max_sel = (max - min) / step;
> > > > > + if (target > max_sel)
> > > > > + target = max_sel;
> > > > > + }
> > > > > + return target;
> > > > > +}
> > > >
> > > > lib/linear_ranges.c might already implement this ...
> > > >
> > >
> > > I found we are neither linear_range_get_selector_high or
> > > linear_range_get_selector_low.
> > > When value lower than min_value, choose min_sel. If higher than
> > > max_value, choose max_sel.
> >
> > Ah, correct.
> >
> > > Should I create linear_range_get_selector() for this?
> >
> > My suggestion would be yes, but I am not insisting on it.
> >
>
> Maybe this is a special choosing mechanism, I will keep it.
> Could I also keep mt6360_map_real_val?

I think adding generic function to linear range code for others to re-
use would be nice. But if you choose to keep the mt6360_map_reg_sel()
then it I agree that you should also keep the mt6360_map_real_val().

Best regards
Matti Vaittinen