Re: [PATCHv3 4/4] tps65912: add regulator driver

From: Mark Brown
Date: Sun May 15 2011 - 13:02:04 EST


On Fri, May 13, 2011 at 04:30:49PM -0500, Margarita Olaya wrote:
> The tps65912 consiste of 4 DCDCs and 10 LDOs. The output voltages can be
> configured by the SPI or I2C interface, they are meant to supply power
> to the main processor and other components.

Looks pretty good

Acked-by: Mark Brown <broonie@xxxxxxxxxxxxxxxxxxxxxxxxxxx>

though a few things that you could fix incrementally:

> +static unsigned int tps65912_get_mode(struct regulator_dev *dev)
> +{
> + struct tps65912_reg *pmic = rdev_get_drvdata(dev);
> + struct tps65912 *mfd = pmic->mfd;
> + int pwm_mode, eco, mode = 0, id = rdev_get_id(dev);
> +
> + switch (id) {
> + case TPS65912_REG_DCDC1:
> + pwm_mode = tps65912_reg_read(mfd, TPS65912_DCDC1_CTRL);
> + eco = tps65912_reg_read(mfd, TPS65912_DCDC1_AVS);
> + break;

This switch statement for the lookup could be factored out into a
separate function for sharing with set.

> +static int tps65912_get_voltage_dcdc(struct regulator_dev *dev)
> +{
> + struct tps65912_reg *pmic = rdev_get_drvdata(dev);
> + struct tps65912 *mfd = pmic->mfd;
> + int id = rdev_get_id(dev), voltage = 0, range;
> + int opvsel = 0, avsel = 0, sr, vsel;

You'd save code in this function if you made it into a get_voltage_sel()
- a large chunk of it is a selector to voltage lookup.

> +static int tps65912_get_voltage_ldo(struct regulator_dev *dev)
> +{
> + struct tps65912_reg *pmic = rdev_get_drvdata(dev);
> + struct tps65912 *mfd = pmic->mfd;
> + int id = rdev_get_id(dev);
> + int vsel = 0;
> + u8 reg;
> +
> + reg = tps65912_get_ldo_sel_register(pmic, id);
> + vsel = tps65912_reg_read(mfd, reg);
> + vsel &= 0x3F;
> +
> + return tps65912_vsel_to_uv_ldo(vsel);

This is just an open coded get_voltage_sel().
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/