Re: [PATCH v2 10/20] power: supply: bq25890: Add bq25890_set_otg_cfg() helper

Yauhen Kharuzhy
2021-11-15T10:11:46Z

On Sun, Nov 14, 2021 at 06:03:25PM +0100, Hans de Goede wrote:
> Add a bq25890_set_otg_cfg() helper function, this is a preparation
> patch for adding regulator support.
>
> Signed-off-by: Hans de Goede <hdegoede@redhat.com>
> ---
> drivers/power/supply/bq25890_charger.c | 28 ++++++++++++++------------
> 1 file changed, 15 insertions(+), 13 deletions(-)
>
> diff --git a/drivers/power/supply/bq25890_charger.c b/drivers/power/supply/bq25890_charger.c
> index 2bdfb58cda75..3c41fe86b3d3 100644
> --- a/drivers/power/supply/bq25890_charger.c
> +++ b/drivers/power/supply/bq25890_charger.c
> @@ -801,6 +801,17 @@ static int bq25890_power_supply_init(struct bq25890_device *bq)
> return PTR_ERR_OR_ZERO(bq->charger);
> }
>
> +static int bq25890_set_otg_cfg(struct bq25890_device *bq, u8 val)
> +{
> + int ret;
> +
> + ret = bq25890_field_write(bq, F_OTG_CFG, val);
> + if (ret < 0)
> + dev_err(bq->dev, "Error switching to boost/charger mode: %d\n", ret);

Just a note: if a connected USB device has relative big capacitor
at power wires inside, then a starting current pulse may be enough to
overload the boost reguator and VBUS will not be powered. I met this
at Yoga Book: the firmware set boost current limit to 1.4 A (default
value for bq25892) but when USB hub connected, the BOOST_FAULT event
appeared.

To avoid this, Lenovo uses following trick in its kernel: set a boost
current limit to big value (2.1 A), wait some time (500 ms) and set
the current limit to right value (1.4A). This provides enough current to
charge capacitors in the connected device but saves desired long-time limit
to prevent overloading if the device consumes too much power itself.

--
Yauhen Kharuzhy