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

Anatolij Gustschin agust at denx.de
Fri Jan 9 18:05:35 CET 2015


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,
Anatolij


More information about the U-Boot mailing list