summaryrefslogtreecommitdiff
path: root/driver/charger/rt9490.c
diff options
context:
space:
mode:
authorFabio Baltieri <fabiobaltieri@google.com>2022-05-16 10:27:08 +0000
committerChromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com>2022-05-27 15:55:43 +0000
commitbe7509a8ae5e8b9983f34b1d30d0e99275f09b97 (patch)
tree2ed88c72744d1c4b3d418aafdc1087a12d4a2d09 /driver/charger/rt9490.c
parent2024fc296cc799f75ab1ca502e73e09b6488269a (diff)
downloadchrome-ec-be7509a8ae5e8b9983f34b1d30d0e99275f09b97.tar.gz
bc12: split task handler in init and event
Split the bc12 internal API from a task loop handler to an init and event handler pair of functions, moving the loop on the caller. This is to allow handling the events from a single task on a followup patch. Current driver behavior should be unchanged, just bringing the loop and wait in the generic code. For a couple of drivers (bd9995x and rt946x) this was not quite possible as they would need some more work to fit in that model, but then those two runs in single task mode already anyway (HAS_TASK_USB_CHG), so no point converting them to fit the model anyway, just running the whole driver in the init() keeps the existing behavior, code will never reach the outer loop. BRANCH=none BUG=b:226411332 TEST=make buildall TEST=zmake testall TEST=cq dry run Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com> Change-Id: I8e28ad8b5b52b002587aefb68116a14b709729fe Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3663747 Reviewed-by: Jack Rosenthal <jrosenth@chromium.org>
Diffstat (limited to 'driver/charger/rt9490.c')
-rw-r--r--driver/charger/rt9490.c75
1 files changed, 37 insertions, 38 deletions
diff --git a/driver/charger/rt9490.c b/driver/charger/rt9490.c
index 8543d73329..2d69e843e9 100644
--- a/driver/charger/rt9490.c
+++ b/driver/charger/rt9490.c
@@ -643,49 +643,47 @@ static void rt9490_update_charge_manager(int port,
#error rt9490 bc1.2 driver only works in single charger mode.
#endif
-static void rt9490_usb_charger_task(const int port)
+static void rt9490_usb_charger_task_init(const int port)
{
rt9490_enable_chgdet_flow(CHARGER_SOLO, false);
+}
- while (1) {
- uint32_t evt = task_wait_event(-1);
- /*
- * b/193753475#comment33: don't trigger bc1.2 detection
- * after PRSwap/FRSwap.
- *
- * Note that the only scenario we want to catch is power
- * role swap. For other cases, `is_non_pd_sink` may have
- * false positive (e.g. pd_capable() is false during
- * initial PD negotiation). But it's okay to always
- * trigger bc1.2 detection for other cases.
- */
- bool is_non_pd_sink = !pd_capable(port) &&
- !usb_charger_port_is_sourcing_vbus(port) &&
- pd_check_vbus_level(port, VBUS_PRESENT);
-
- /* vbus change, start bc12 detection */
- if (evt & USB_CHG_EVENT_VBUS) {
-
- if (is_non_pd_sink)
- rt9490_enable_chgdet_flow(CHARGER_SOLO, true);
- else
- rt9490_update_charge_manager(
- port, CHARGE_SUPPLIER_NONE);
- }
+static void rt9490_usb_charger_task_event(const int port, uint32_t evt)
+{
+ /*
+ * b/193753475#comment33: don't trigger bc1.2 detection after
+ * PRSwap/FRSwap.
+ *
+ * Note that the only scenario we want to catch is power role swap. For
+ * other cases, `is_non_pd_sink` may have false positive (e.g.
+ * pd_capable() is false during initial PD negotiation). But it's okay
+ * to always trigger bc1.2 detection for other cases.
+ */
+ bool is_non_pd_sink = !pd_capable(port) &&
+ !usb_charger_port_is_sourcing_vbus(port) &&
+ pd_check_vbus_level(port, VBUS_PRESENT);
- /* detection done, update charge_manager and stop detection */
- if (evt & USB_CHG_EVENT_BC12) {
- enum charge_supplier supplier;
+ /* vbus change, start bc12 detection */
+ if (evt & USB_CHG_EVENT_VBUS) {
- if (is_non_pd_sink)
- supplier = rt9490_get_bc12_device_type(
- CHARGER_SOLO);
- else
- supplier = CHARGE_SUPPLIER_NONE;
+ if (is_non_pd_sink)
+ rt9490_enable_chgdet_flow(CHARGER_SOLO, true);
+ else
+ rt9490_update_charge_manager(
+ port, CHARGE_SUPPLIER_NONE);
+ }
- rt9490_update_charge_manager(port, supplier);
- rt9490_enable_chgdet_flow(CHARGER_SOLO, false);
- }
+ /* detection done, update charge_manager and stop detection */
+ if (evt & USB_CHG_EVENT_BC12) {
+ enum charge_supplier supplier;
+
+ if (is_non_pd_sink)
+ supplier = rt9490_get_bc12_device_type(CHARGER_SOLO);
+ else
+ supplier = CHARGE_SUPPLIER_NONE;
+
+ rt9490_update_charge_manager(port, supplier);
+ rt9490_enable_chgdet_flow(CHARGER_SOLO, false);
}
}
@@ -723,7 +721,8 @@ void rt9490_interrupt(int port)
}
const struct bc12_drv rt9490_bc12_drv = {
- .usb_charger_task = rt9490_usb_charger_task,
+ .usb_charger_task_init = rt9490_usb_charger_task_init,
+ .usb_charger_task_event = rt9490_usb_charger_task_event,
};
#ifdef CONFIG_BC12_SINGLE_DRIVER