Re: [PATCH 10/13] power: supply: bq25890: Add support for registering the Vbus boost converter as a regulator

From: Andy Shevchenko
Date: Sat Oct 30 2021 - 18:14:40 EST


On Sat, Oct 30, 2021 at 9:28 PM Hans de Goede <hdegoede@xxxxxxxxxx> wrote:
>
> The bq25890_charger code supports enabling/disabling the boost converter
> based on usb-phy notifications. But the usb-phy framework is not used on
> all boards/platforms. At support for registering the Vbus boost converter
> as a standard regulator when there is no usb-phy on the board.
>
> Also add support for providing regulator_init_data through platform_data
> for use on boards where device-tree is not used and the platform code must
> thus provide the regulator_init_data.

...

> @@ -1018,6 +1059,21 @@ static int bq25890_probe(struct i2c_client *client,
> INIT_WORK(&bq->usb_work, bq25890_usb_work);
> bq->usb_nb.notifier_call = bq25890_usb_notifier;
> usb_register_notifier(bq->usb_phy, &bq->usb_nb);
> +#ifdef CONFIG_REGULATOR
> + } else {
> + struct bq25890_platform_data *pdata = dev_get_platdata(dev);
> + struct regulator_config cfg = { };
> + struct regulator_dev *reg;
> +
> + cfg.dev = dev;
> + cfg.driver_data = bq;
> + if (pdata)
> + cfg.init_data = pdata->regulator_init_data;
> +
> + reg = devm_regulator_register(dev, &bq25890_vbus_desc, &cfg);
> + if (IS_ERR(reg))
> + return dev_err_probe(dev, PTR_ERR(reg), "registering regulator");
> +#endif
> }

}
#ifdef
else {
...
}
#endif

is a bit better to maintain (less error prone in case of new code).

...

> +#ifndef _BQ25890_CHARGER_H_
> +#define _BQ25890_CHARGER_H_

> +#include <linux/regulator/machine.h>

struct regulator_init_data;

should be sufficient, no header is needed.

> +struct bq25890_platform_data {
> + const struct regulator_init_data *regulator_init_data;
> +};
> +
> +#endif

--
With Best Regards,
Andy Shevchenko