[U-Boot] [PATCH 1/8] sunxi: axp221: Add ELDO[1-3] support

Siarhei Siamashka siarhei.siamashka at gmail.com
Sun Jan 11 13:05:08 CET 2015


On Fri, 9 Jan 2015 18:05:35 +0100
Anatolij Gustschin <agust at denx.de> wrote:

> On Fri,  9 Jan 2015 12:01:09 +0200
> Siarhei Siamashka <siarhei.siamashka at gmail.com> wrote:
> ...
> > +int axp221_set_eldo2(unsigned int mvolt)
> > +{
> > +	int ret;
> > +	u8 cfg = axp221_mvolt_to_cfg(mvolt, 700, 3300, 100);
> > +
> > +	if (mvolt == 0)
> > +		return axp221_clrbits(AXP221_OUTPUT_CTRL2,
> > +				      AXP221_OUTPUT_CTRL2_ELDO2_EN);
> > +
> > +	ret = pmic_bus_write(AXP221_ELDO2_CTRL, cfg);
> > +	if (ret)
> > +		return ret;
> > +
> > +	return axp221_setbits(AXP221_OUTPUT_CTRL2,
> > +			      AXP221_OUTPUT_CTRL2_ELDO2_EN);
> > +}
> > +
> > +int axp221_set_eldo3(unsigned int mvolt)
> > +{
> > +	int ret;
> > +	u8 cfg = axp221_mvolt_to_cfg(mvolt, 700, 3300, 100);
> > +
> > +	if (mvolt == 0)
> > +		return axp221_clrbits(AXP221_OUTPUT_CTRL2,
> > +				      AXP221_OUTPUT_CTRL2_ELDO3_EN);
> > +
> > +	ret = pmic_bus_write(AXP221_ELDO3_CTRL, cfg);
> > +	if (ret)
> > +		return ret;
> > +
> > +	return axp221_setbits(AXP221_OUTPUT_CTRL2,
> > +			      AXP221_OUTPUT_CTRL2_ELDO3_EN);
> > +}
> 
> Can we avoid code duplication here? I.e. only one function
> should be sufficient here:
> 
> int axp221_set_eldo(int eldo_num, unsigned int mvolt)
> {
>         int ret;
>         u8 cfg = axp221_mvolt_to_cfg(mvolt, 700, 3300, 100);
>         u8 addr, bits;
> 
>         switch (eldo_num) {
>         case 3:
>                 addr = AXP221_ELDO3_CTRL;
>                 bits = AXP221_OUTPUT_CTRL2_ELDO3_EN;
>                 break;
>         case 2:
>                 addr = AXP221_ELDO2_CTRL;
>                 bits = AXP221_OUTPUT_CTRL2_ELDO2_EN;
>                 break;
>         case 1:
>         default:
>                 addr = AXP221_ELDO1_CTRL;
>                 bits = AXP221_OUTPUT_CTRL2_ELDO1_EN;
>                 break;
>         }
> 
>         if (mvolt == 0)
>                 return axp221_clrbits(AXP221_OUTPUT_CTRL2, bits);
> 
>         ret = pmic_bus_write(addr, cfg);
>         if (ret)
>                 return ret;
> 
>         return axp221_setbits(AXP221_OUTPUT_CTRL2, bits);
> }

Thanks for the review.

Yes, I am not very happy about this code duplication either. But I just
made it so that it follows the same pattern as the rest of the code in
the axp221 source file for the other voltage regulators. Does it mean
that we want to change it all to have a consistent style?

This is a purely sunxi code and not directly related to video. And I
would like to know what sunxi custodians think about it.

-- 
Best regards,
Siarhei Siamashka


More information about the U-Boot mailing list