Re: [PATCH 1/2] mfd: bq2415x charger driver

From: Felipe Contreras
Date: Mon Dec 05 2011 - 17:49:09 EST


On Wed, Mar 9, 2011 at 4:48 PM, <aliaksei.katovich@xxxxxxxxx> wrote:
> From: Aliaksei Katovich <aliaksei.katovich@xxxxxxxxx>
>
> Added driver to support TI bq24153/6 one-cell Li-Ion chargers.

I tried this driver and it didn't do anything. Some regulators are
registered, and I guess the right values are loaded, but that's all.

It doesn't get configured in any way, and I don't see the code for the
timer reset, without which the charging will stop right away (if it
had managed to start).

> +static inline int bq2415x_enable_otg(bool flag)
> +{
> + Â Â Â int res;
> +
> + Â Â Â res = bq2415x_i2c_read(bq2415x_cli, BQ2415X_BAT_CTL);
> + Â Â Â if (unlikely(res < 0))
> + Â Â Â Â Â Â Â return res;
> +
> + Â Â Â if (flag)
> + Â Â Â Â Â Â Â res |= BQ2415X_OTG_EN;
> + Â Â Â else
> + Â Â Â Â Â Â Â res &= ~BQ2415X_OTG_EN;
> +
> + Â Â Â return bq2415x_i2c_write(bq2415x_cli, BQ2415X_STS_CTL, res);

Wrong registry? BQ2415X_BAT_CTL.

> +}
> +
> +static inline int bq2415x_otg_high(bool flag)
> +{
> + Â Â Â int res;
> +
> + Â Â Â res = bq2415x_i2c_read(bq2415x_cli, BQ2415X_BAT_CTL);
> + Â Â Â if (unlikely(res < 0))
> + Â Â Â Â Â Â Â return res;
> +
> + Â Â Â if (flag)
> + Â Â Â Â Â Â Â res |= BQ2415X_OTG_PL;
> + Â Â Â else
> + Â Â Â Â Â Â Â res &= ~BQ2415X_OTG_PL;
> +
> + Â Â Â return bq2415x_i2c_write(bq2415x_cli, BQ2415X_STS_CTL, res);

Ditto.

> +/**
> + * bq2415x_exec - execute charger specific command
> + *
> + * Returns result of command execution upon success or negative otherwise
> + */
> +int bq2415x_exec(enum bq2415x_cmd cmd)

Who is supposed to call this? Why didn't you provide some examples?

> +static int
> +bq2415x_set_voltage(struct regulator_dev *rdev, int min_uV, int max_uV)
> +{
> + Â Â Â int i, res;
> + Â Â Â struct bq2415x_regulator *r = rdev_get_drvdata(rdev);
> +
> + Â Â Â i = bq2415x_vmap_index(max_uV, r->init.constraints.min_uV);
> + Â Â Â if (i >= r->desc.n_voltages)
> + Â Â Â Â Â Â Â return -EINVAL;
> +
> + Â Â Â res = bq2415x_i2c_read(r->cli, r->reg);
> + Â Â Â if (res < 0)
> + Â Â Â Â Â Â Â return res;

The bit mask should be cleared beforehand, no? Otherwise the on bits
will remain that way.

> + Â Â Â res |= bq2415x_vmap_calc(i, r->msk_summ, r->msk_mult);
> + Â Â Â return bq2415x_i2c_write(r->cli, r->reg, res);
> +}

...

> +static int
> +bq2415x_set_current_limit(struct regulator_dev *rdev, int min_uA, int max_uA)
> +{
> + Â Â Â int res;
> + Â Â Â struct bq2415x_regulator *r = rdev_get_drvdata(rdev);
> +
> + Â Â Â res = bq2415x_i2c_read(r->cli, r->reg);
> + Â Â Â if (res < 0)
> + Â Â Â Â Â Â Â return res;
> +
> + Â Â Â if (BQ2415X_IIN_LIMIT_100 <= min_uA && max_uA < BQ2415X_IIN_LIMIT_500)
> + Â Â Â Â Â Â Â res &= ~BQ2415X_IIN_LIMIT_UNLIM_MASK;

I think these bits should always be cleared.

> + Â Â Â else if (BQ2415X_IIN_LIMIT_500 <= min_uA &&
> + Â Â Â Â Â Â Â Â Â Â Â max_uA < BQ2415X_IIN_LIMIT_800)
> + Â Â Â Â Â Â Â res |= BQ2415X_IIN_LIMIT_500_MASK;
> + Â Â Â else if (BQ2415X_IIN_LIMIT_800 <= min_uA &&
> + Â Â Â Â Â Â Â Â Â Â Â max_uA < BQ2415X_IIN_LIMIT_UNLIM)
> + Â Â Â Â Â Â Â res |= BQ2415X_IIN_LIMIT_800_MASK;
> + Â Â Â else if (BQ2415X_IIN_LIMIT_UNLIM <= min_uA)
> + Â Â Â Â Â Â Â res |= BQ2415X_IIN_LIMIT_UNLIM_MASK;
> + Â Â Â else
> + Â Â Â Â Â Â Â return -EINVAL;
> +
> + Â Â Â return bq2415x_i2c_write(r->cli, r->reg, res);
> +}

> +/* regulator initialization */

...

> +static struct bq2415x_regulator bq2415x_regulator[] = {

I don't understand what these regulators are supposed to be doing, and
how other drivers are supposed to hook on them. Again, no examples.

Moreover, for example V_OREG is supposed to control the voltage from
3.5v to 4.4v, but you set the range from 20mv to 1260mv which is only
the additional voltage (and it starters from 0).

> +static void __init bq2415x_add_consumers(struct bq2415x_regulator *r,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Âstruct regulator_init_data *init)

I don't understand the purpose of this code at all.

> diff --git a/include/linux/mfd/bq2415x.h b/include/linux/mfd/bq2415x.h

There's no need for exporting a lot of this stuff.

--
Felipe Contreras
--
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/