power: supply: qti_battery_charger: Keep device awake during notification

With charger mode enabled in android, device boots into charger
mode when it is powered on with USB insertion. In this mode,
health HAL and charger service handles the power supply uevents
sent from power supply framework to take certain actions. For
example, when the USB or travel adapter (TA) is removed, device
would shut down in 10 seconds.

With a TA connected, device can enter suspend whenever possible
during charging. When the TA is removed after the device has
entered suspend, device comes out of suspend upon the notification
received from charger firmware (CHGFW) over PMIC Glink. Battery
charger driver handles this and calls power_supply_changed on one
of the power supply devices. However, before this uevent is
received and handled by charger service in the userspace, device
can enter suspend immediately.

In a low power discharging state, device stays in this state for
minutes until it gets another notification from CHGFW for battery
power supply, a periodic event which makes charger service to
initiate a shutdown. This conflicts with the user expectation
where the device has to shutdown in 10 seconds upon TA removal.

Workaround this problem by keeping the device awake for at least
50 ms when a notification is received from CHGFW. This way,
userspace process like charger could get a chance to receive and
handle the power supply uevents.

Change-Id: I9ea78eb6565988ffac0e6c5eee1ccae8dc7e3e3a
Signed-off-by: Subbaraman Narayanamurthy <subbaram@codeaurora.org>
This commit is contained in:
Subbaraman Narayanamurthy 2020-07-16 16:11:14 -07:00 committed by Anjelique Melendez
parent 640c25fb23
commit 4540348af3

View File

@ -15,6 +15,7 @@
#include <linux/reboot.h>
#include <linux/rpmsg.h>
#include <linux/mutex.h>
#include <linux/pm_wakeup.h>
#include <linux/power_supply.h>
#include <linux/soc/qcom/pmic_glink.h>
#include <linux/soc/qcom/battery_charger.h>
@ -622,8 +623,18 @@ static void handle_notification(struct battery_chg_dev *bcdev, void *data,
break;
}
if (pst && pst->psy)
if (pst && pst->psy) {
/*
* For charger mode, keep the device awake at least for 50 ms
* so that device won't enter suspend when a non-SDP charger
* is removed. This would allow the userspace process like
* "charger" to be able to read power supply uevents to take
* appropriate actions (e.g. shutting down when the charger is
* unplugged).
*/
power_supply_changed(pst->psy);
pm_wakeup_dev_event(bcdev->dev, 50, true);
}
}
static int battery_chg_callback(void *priv, void *data, size_t len)