power: supply: rk818-charger: Delay applying input current limit until first BC detection finishes

When the phone boots for the first time, we only want to react to
changes in charger power supply max current after the USB power supply
type detection finishes. This allows us to keep the limit set by
the bootloader, until we know better.

This is part of the workaround for Pinephone Pro boot loops on low battery.
The other part is bootloader raising the input current limit to 2A.

Signed-off-by: Ondrej Jirman <megi@xff.cz>
This commit is contained in:
Ondrej Jirman
2022-08-02 09:37:05 +02:00
committed by Mauro (mdrjr) Ribeiro
parent 2fe4f7f800
commit ad624b548a

View File

@@ -51,6 +51,8 @@ struct rk818_charger {
struct power_supply *usb_psy;
struct power_supply *charger_psy;
bool apply_ilim;
};
// {{{ USB supply
@@ -72,6 +74,8 @@ static int rk818_usb_set_input_current_max(struct rk818_charger *cg,
else
reg = 11;
dev_info(cg->dev, "applying input current limit %d mA\n", val / 1000);
ret = regmap_update_bits(cg->regmap, RK818_USB_CTRL_REG,
RK818_USB_CTRL_USB_ILIM_MASK, reg);
if (ret)
@@ -242,6 +246,19 @@ static void rk818_usb_power_external_power_changed(struct power_supply *psy)
if (ret)
return;
/*
* We only want to start applying input current limit after we get first
* non-0 value from the supplier. Until then, we keep the limit applied
* by the bootloader. If we lower the limit before the charger is properly
* detected, we risk boot failure due to insufficient power.
*/
if (!cg->apply_ilim) {
if (!val.intval)
return;
cg->apply_ilim = true;
}
if (val.intval < 500000)
val.intval = 500000;