summaryrefslogtreecommitdiff
path: root/driver
diff options
context:
space:
mode:
Diffstat (limited to 'driver')
-rw-r--r--driver/bc12/max14637.c17
-rw-r--r--driver/bc12/mt6360.c55
-rw-r--r--driver/bc12/pi3usb9201.c183
-rw-r--r--driver/bc12/pi3usb9281.c73
-rw-r--r--driver/charger/bd9995x.c9
-rw-r--r--driver/charger/rt946x.c6
-rw-r--r--driver/charger/rt9490.c75
-rw-r--r--driver/ppc/rt1739.c53
-rw-r--r--driver/tcpm/rt1718s.c50
9 files changed, 257 insertions, 264 deletions
diff --git a/driver/bc12/max14637.c b/driver/bc12/max14637.c
index a176d79674..60e9be8054 100644
--- a/driver/bc12/max14637.c
+++ b/driver/bc12/max14637.c
@@ -174,9 +174,8 @@ static void detect_or_power_down_ic(const int port)
}
}
-static void max14637_usb_charger_task(const int port)
+static void max14637_usb_charger_task_init(const int port)
{
- uint32_t evt;
const struct max14637_config_t * const cfg = &max14637_config[port];
ASSERT(port >= 0 && port < CONFIG_USB_PD_PORT_MAX_COUNT);
@@ -188,13 +187,12 @@ static void max14637_usb_charger_task(const int port)
activate_chip_enable(cfg, 1);
/* Check whether bc1.2 client mode detection needs to be triggered */
detect_or_power_down_ic(port);
+}
- while (1) {
- evt = task_wait_event(-1);
-
- if (evt & USB_CHG_EVENT_VBUS)
- detect_or_power_down_ic(port);
- }
+static void max14637_usb_charger_task_event(const int port, uint32_t evt)
+{
+ if (evt & USB_CHG_EVENT_VBUS)
+ detect_or_power_down_ic(port);
}
#if defined(CONFIG_CHARGE_RAMP_SW) || defined(CONFIG_CHARGE_RAMP_HW)
@@ -236,7 +234,8 @@ DECLARE_HOOK(HOOK_CHIPSET_STARTUP, bc12_chipset_startup, HOOK_PRIO_DEFAULT);
DECLARE_HOOK(HOOK_CHIPSET_RESUME, bc12_chipset_startup, HOOK_PRIO_DEFAULT);
const struct bc12_drv max14637_drv = {
- .usb_charger_task = max14637_usb_charger_task,
+ .usb_charger_task_init = max14637_usb_charger_task_init,
+ .usb_charger_task_event = max14637_usb_charger_task_event,
#if defined(CONFIG_CHARGE_RAMP_SW) || defined(CONFIG_CHARGE_RAMP_HW)
.ramp_allowed = max14637_ramp_allowed,
.ramp_max = max14637_ramp_max,
diff --git a/driver/bc12/mt6360.c b/driver/bc12/mt6360.c
index 5addba7a0c..487883ec62 100644
--- a/driver/bc12/mt6360.c
+++ b/driver/bc12/mt6360.c
@@ -156,41 +156,37 @@ static void mt6360_handle_bc12_irq(int port)
mt6360_write8(MT6360_REG_DPDMIRQ, reg);
}
-static void mt6360_usb_charger_task(const int port)
+static void mt6360_usb_charger_task_init(const int port)
{
mt6360_clr_bit(MT6360_REG_DPDM_MASK1,
MT6360_REG_DPDM_MASK1_CHGDET_DONEI_M);
mt6360_enable_bc12_detection(0);
+}
- while (1) {
- uint32_t evt = task_wait_event(-1);
-
- /* vbus change, start bc12 detection */
- if (evt & USB_CHG_EVENT_VBUS) {
- bool is_sink = pd_get_power_role(port) == PD_ROLE_SINK;
- bool is_non_pd_sink = !pd_capable(port) &&
- is_sink &&
- pd_snk_is_vbus_provided(port);
-
- if (is_sink)
- mt6360_clr_bit(MT6360_REG_CHG_CTRL1,
- MT6360_MASK_HZ);
- else
- mt6360_set_bit(MT6360_REG_CHG_CTRL1,
- MT6360_MASK_HZ);
+static void mt6360_usb_charger_task_event(const int port, uint32_t evt)
+{
+ /* vbus change, start bc12 detection */
+ if (evt & USB_CHG_EVENT_VBUS) {
+ bool is_sink = pd_get_power_role(port) == PD_ROLE_SINK;
+ bool is_non_pd_sink = !pd_capable(port) &&
+ is_sink &&
+ pd_snk_is_vbus_provided(port);
+
+ if (is_sink)
+ mt6360_clr_bit(MT6360_REG_CHG_CTRL1, MT6360_MASK_HZ);
+ else
+ mt6360_set_bit(MT6360_REG_CHG_CTRL1, MT6360_MASK_HZ);
- if (is_non_pd_sink)
- mt6360_enable_bc12_detection(1);
- else
- mt6360_update_charge_manager(
- 0, CHARGE_SUPPLIER_NONE);
- }
+ if (is_non_pd_sink)
+ mt6360_enable_bc12_detection(1);
+ else
+ mt6360_update_charge_manager(0, CHARGE_SUPPLIER_NONE);
+ }
- /* detection done, update charge_manager and stop detection */
- if (evt & USB_CHG_EVENT_BC12) {
- mt6360_handle_bc12_irq(port);
- mt6360_enable_bc12_detection(0);
- }
+ /* detection done, update charge_manager and stop detection */
+ if (evt & USB_CHG_EVENT_BC12) {
+ mt6360_handle_bc12_irq(port);
+ mt6360_enable_bc12_detection(0);
}
}
@@ -576,7 +572,8 @@ int mt6360_led_set_brightness(enum mt6360_led_id led_id, int brightness)
}
const struct bc12_drv mt6360_drv = {
- .usb_charger_task = mt6360_usb_charger_task,
+ .usb_charger_task_init = mt6360_usb_charger_task_init,
+ .usb_charger_task_event = mt6360_usb_charger_task_event,
};
#ifdef CONFIG_BC12_SINGLE_DRIVER
diff --git a/driver/bc12/pi3usb9201.c b/driver/bc12/pi3usb9201.c
index 040729aae0..6d47ed5d04 100644
--- a/driver/bc12/pi3usb9201.c
+++ b/driver/bc12/pi3usb9201.c
@@ -226,10 +226,8 @@ static void bc12_power_up(int port)
pi3usb9201_interrupt_mask(port, 1);
}
-static void pi3usb9201_usb_charger_task(const int port)
+static void pi3usb9201_usb_charger_task_init(const int port)
{
- uint32_t evt;
-
/*
* Set most recent bc1.2 detection supplier result to
* CHARGE_SUPPLIER_NONE for the port.
@@ -241,112 +239,106 @@ static void pi3usb9201_usb_charger_task(const int port)
* than enabling the interrupt mask.
*/
pi3usb9201_interrupt_mask(port, 1);
+}
- while (1) {
- /* Wait for interrupt */
- evt = task_wait_event(-1);
-
- /* Interrupt from the Pericom chip, determine charger type */
- if (evt & USB_CHG_EVENT_BC12) {
- int client;
- int host;
- int rv;
-
- rv = pi3usb9201_get_status(port, &client, &host);
- if (!rv && client)
- /*
- * Any bit set in client status register
- * indicates that BC1.2 detection has
- * completed.
- */
- bc12_update_charge_manager(port, client);
- if (!rv && host) {
- /*
- * Switch to SDP after device is plugged in to
- * avoid noise (pulse on D-) causing USB
- * disconnect (b/156014140).
- */
- if (host & PI3USB9201_REG_HOST_STS_DEV_PLUG)
- pi3usb9201_set_mode(port,
- PI3USB9201_SDP_HOST_MODE);
- /*
- * Switch to CDP after device is unplugged so
- * we advertise higher power available for next
- * device.
- */
- if (host & PI3USB9201_REG_HOST_STS_DEV_UNPLUG)
- pi3usb9201_set_mode(port,
- PI3USB9201_CDP_HOST_MODE);
- }
+static void pi3usb9201_usb_charger_task_event(const int port, uint32_t evt)
+{
+ /* Interrupt from the Pericom chip, determine charger type */
+ if (evt & USB_CHG_EVENT_BC12) {
+ int client;
+ int host;
+ int rv;
+
+ rv = pi3usb9201_get_status(port, &client, &host);
+ if (!rv && client)
+ /*
+ * Any bit set in client status register indicates that
+ * BC1.2 detection has completed.
+ */
+ bc12_update_charge_manager(port, client);
+ if (!rv && host) {
+ /*
+ * Switch to SDP after device is plugged in to avoid
+ * noise (pulse on D-) causing USB disconnect
+ * (b/156014140).
+ */
+ if (host & PI3USB9201_REG_HOST_STS_DEV_PLUG)
+ pi3usb9201_set_mode(port,
+ PI3USB9201_SDP_HOST_MODE);
/*
- * TODO(b/124061702): Use host status to allocate power
- * more intelligently.
+ * Switch to CDP after device is unplugged so we
+ * advertise higher power available for next device.
*/
+ if (host & PI3USB9201_REG_HOST_STS_DEV_UNPLUG)
+ pi3usb9201_set_mode(port,
+ PI3USB9201_CDP_HOST_MODE);
}
+ /*
+ * TODO(b/124061702): Use host status to allocate power more
+ * intelligently.
+ */
+ }
-#ifndef CONFIG_USB_PD_VBUS_DETECT_TCPC
- if (evt & USB_CHG_EVENT_VBUS)
- CPRINTS("VBUS p%d %d", port,
- pd_snk_is_vbus_provided(port));
-#endif
+ if (!IS_ENABLED(CONFIG_USB_PD_VBUS_DETECT_TCPC) &&
+ (evt & USB_CHG_EVENT_VBUS))
+ CPRINTS("VBUS p%d %d", port,
+ pd_snk_is_vbus_provided(port));
- if (evt & USB_CHG_EVENT_DR_UFP) {
- bc12_power_up(port);
- if (bc12_detect_start(port)) {
- struct charge_port_info new_chg;
-
- /*
- * VBUS is present, but starting bc1.2 detection
- * failed for some reason. So limit charge
- * current to default 500 mA for this case.
- */
-
- new_chg.voltage = USB_CHARGER_VOLTAGE_MV;
- new_chg.current = USB_CHARGER_MIN_CURR_MA;
- /* Save supplier type and notify chg manager */
- bc12_update_supplier(CHARGE_SUPPLIER_OTHER,
- port, &new_chg);
- CPRINTS("pi3usb9201[p%d]: bc1.2 failed use "
- "defaults", port);
- }
+ if (evt & USB_CHG_EVENT_DR_UFP) {
+ bc12_power_up(port);
+ if (bc12_detect_start(port)) {
+ struct charge_port_info new_chg;
+
+ /*
+ * VBUS is present, but starting bc1.2 detection failed
+ * for some reason. So limit charge current to default
+ * 500 mA for this case.
+ */
+
+ new_chg.voltage = USB_CHARGER_VOLTAGE_MV;
+ new_chg.current = USB_CHARGER_MIN_CURR_MA;
+ /* Save supplier type and notify chg manager */
+ bc12_update_supplier(CHARGE_SUPPLIER_OTHER,
+ port, &new_chg);
+ CPRINTS("pi3usb9201[p%d]: bc1.2 failed use defaults",
+ port);
}
+ }
- if (evt & USB_CHG_EVENT_DR_DFP) {
- int mode;
- int rv;
+ if (evt & USB_CHG_EVENT_DR_DFP) {
+ int mode;
+ int rv;
+ /*
+ * Update the charge manager if bc1.2 client mode is currently
+ * active.
+ */
+ bc12_update_supplier(CHARGE_SUPPLIER_NONE, port, NULL);
+ /*
+ * If the port is in DFP mode, then need to set mode to
+ * CDP_HOST which will auto close D+/D- switches.
+ */
+ bc12_power_up(port);
+ rv = pi3usb9201_get_mode(port, &mode);
+ if (!rv && (mode != PI3USB9201_CDP_HOST_MODE)) {
+ CPRINTS("pi3usb9201[p%d]: CDP_HOST mode", port);
/*
- * Update the charge manager if bc1.2 client mode is
- * currently active.
+ * Read both status registers to ensure that all
+ * interrupt indications are cleared prior to starting
+ * DFP CDP host mode.
*/
- bc12_update_supplier(CHARGE_SUPPLIER_NONE, port, NULL);
+ pi3usb9201_get_status(port, NULL, NULL);
+ pi3usb9201_set_mode(port, PI3USB9201_CDP_HOST_MODE);
/*
- * If the port is in DFP mode, then need to set mode to
- * CDP_HOST which will auto close D+/D- switches.
+ * Unmask interrupt to wake task when host status
+ * changes.
*/
- bc12_power_up(port);
- rv = pi3usb9201_get_mode(port, &mode);
- if (!rv && (mode != PI3USB9201_CDP_HOST_MODE)) {
- CPRINTS("pi3usb9201[p%d]: CDP_HOST mode", port);
- /*
- * Read both status registers to ensure that all
- * interrupt indications are cleared prior to
- * starting DFP CDP host mode.
- */
- pi3usb9201_get_status(port, NULL, NULL);
- pi3usb9201_set_mode(port,
- PI3USB9201_CDP_HOST_MODE);
- /*
- * Unmask interrupt to wake task when host
- * status changes.
- */
- pi3usb9201_interrupt_mask(port, 0);
- }
+ pi3usb9201_interrupt_mask(port, 0);
}
-
- if (evt & USB_CHG_EVENT_CC_OPEN)
- bc12_power_down(port);
}
+
+ if (evt & USB_CHG_EVENT_CC_OPEN)
+ bc12_power_down(port);
}
#if defined(CONFIG_CHARGE_RAMP_SW) || defined(CONFIG_CHARGE_RAMP_HW)
@@ -381,7 +373,8 @@ static int pi3usb9201_ramp_max(int supplier, int sup_curr)
#endif /* CONFIG_CHARGE_RAMP_SW || CONFIG_CHARGE_RAMP_HW */
const struct bc12_drv pi3usb9201_drv = {
- .usb_charger_task = pi3usb9201_usb_charger_task,
+ .usb_charger_task_init = pi3usb9201_usb_charger_task_init,
+ .usb_charger_task_event = pi3usb9201_usb_charger_task_event,
#if defined(CONFIG_CHARGE_RAMP_SW) || defined(CONFIG_CHARGE_RAMP_HW)
.ramp_allowed = pi3usb9201_ramp_allowed,
.ramp_max = pi3usb9201_ramp_max,
diff --git a/driver/bc12/pi3usb9281.c b/driver/bc12/pi3usb9281.c
index 912fb80764..3c3a0a7256 100644
--- a/driver/bc12/pi3usb9281.c
+++ b/driver/bc12/pi3usb9281.c
@@ -416,49 +416,47 @@ static uint32_t bc12_detect(int port)
return evt;
}
-static void pi3usb9281_usb_charger_task(const int port)
+static void pi3usb9281_usb_charger_task_event(const int port, uint32_t evt)
{
- uint32_t evt;
- /* Initialize chip and enable interrupts */
- pi3usb9281_init(port);
+ /* Interrupt from the Pericom chip, determine charger type */
+ if (evt & USB_CHG_EVENT_BC12) {
+ /* Read interrupt register to clear on chip */
+ pi3usb9281_get_interrupts(port);
+ evt = bc12_detect(port);
+ } else if (evt & USB_CHG_EVENT_INTR) {
+ /* USB_CHG_EVENT_INTR & _BC12 are mutually exclusive */
+ /* Check the interrupt register, and clear on chip */
+ if (pi3usb9281_get_interrupts(port) &
+ PI3USB9281_INT_ATTACH_DETACH)
+ evt = bc12_detect(port);
+ }
- evt = bc12_detect(port);
+ if (evt & USB_CHG_EVENT_MUX)
+ pi3usb9281_set_switches_impl(port, usb_switch_state[port]);
- while (1) {
- /* Interrupt from the Pericom chip, determine charger type */
- if (evt & USB_CHG_EVENT_BC12) {
- /* Read interrupt register to clear on chip */
- pi3usb9281_get_interrupts(port);
- evt = bc12_detect(port);
- } else if (evt & USB_CHG_EVENT_INTR) {
- /* USB_CHG_EVENT_INTR & _BC12 are mutually exclusive */
- /* Check the interrupt register, and clear on chip */
- if (pi3usb9281_get_interrupts(port) &
- PI3USB9281_INT_ATTACH_DETACH)
- evt = bc12_detect(port);
- }
+ /*
+ * Re-enable interrupts on pericom charger detector since the chip may
+ * periodically reset itself, and come back up with registers in
+ * default state. TODO(crosbug.com/p/33823): Fix these unwanted resets.
+ */
+ if (evt & USB_CHG_EVENT_VBUS) {
+ pi3usb9281_enable_interrupts(port);
+ if (!IS_ENABLED(CONFIG_USB_PD_VBUS_DETECT_TCPC))
+ CPRINTS("VBUS p%d %d", port, pd_snk_is_vbus_provided(port));
+ }
+}
- if (evt & USB_CHG_EVENT_MUX)
- pi3usb9281_set_switches_impl(
- port, usb_switch_state[port]);
+static void pi3usb9281_usb_charger_task_init(const int port)
+{
+ uint32_t evt;
- /*
- * Re-enable interrupts on pericom charger detector since the
- * chip may periodically reset itself, and come back up with
- * registers in default state. TODO(crosbug.com/p/33823): Fix
- * these unwanted resets.
- */
- if (evt & USB_CHG_EVENT_VBUS) {
- pi3usb9281_enable_interrupts(port);
-#ifndef CONFIG_USB_PD_VBUS_DETECT_TCPC
- CPRINTS("VBUS p%d %d", port,
- pd_snk_is_vbus_provided(port));
-#endif
- }
+ /* Initialize chip and enable interrupts */
+ pi3usb9281_init(port);
- evt = task_wait_event(-1);
- }
+ /* Set the initial state */
+ evt = bc12_detect(port);
+ pi3usb9281_usb_charger_task_event(port, evt);
}
#if defined(CONFIG_CHARGE_RAMP_SW) || defined(CONFIG_CHARGE_RAMP_HW)
@@ -487,7 +485,8 @@ static int pi3usb9281_ramp_max(int supplier, int sup_curr)
#endif /* CONFIG_CHARGE_RAMP_SW || CONFIG_CHARGE_RAMP_HW */
const struct bc12_drv pi3usb9281_drv = {
- .usb_charger_task = pi3usb9281_usb_charger_task,
+ .usb_charger_task_init = pi3usb9281_usb_charger_task_init,
+ .usb_charger_task_event = pi3usb9281_usb_charger_task_event,
.set_switches = pi3usb9281_set_switches,
#if defined(CONFIG_CHARGE_RAMP_SW) || defined(CONFIG_CHARGE_RAMP_HW)
.ramp_allowed = pi3usb9281_ramp_allowed,
diff --git a/driver/charger/bd9995x.c b/driver/charger/bd9995x.c
index bf8dfb4c5d..8fee94ad7b 100644
--- a/driver/charger/bd9995x.c
+++ b/driver/charger/bd9995x.c
@@ -1301,7 +1301,7 @@ void bd9995x_vbus_interrupt(enum gpio_signal signal)
task_wake(TASK_ID_USB_CHG);
}
-static void bd9995x_usb_charger_task(const int unused)
+static void bd9995x_usb_charger_task_init(const int unused)
{
static int initialized;
int changed, port, interrupts;
@@ -1742,7 +1742,9 @@ const struct charger_drv bd9995x_drv = {
struct bc12_config bc12_ports[BD9995X_CHARGE_PORT_COUNT] = {
{
.drv = &(const struct bc12_drv) {
- .usb_charger_task = bd9995x_usb_charger_task,
+ .usb_charger_task_init = bd9995x_usb_charger_task_init,
+ /* events handled in init */
+ .usb_charger_task_event = NULL,
.set_switches = bd9995x_set_switches,
#if defined(CONFIG_CHARGE_RAMP_SW)
.ramp_allowed = bd9995x_ramp_allowed,
@@ -1753,7 +1755,8 @@ struct bc12_config bc12_ports[BD9995X_CHARGE_PORT_COUNT] = {
{
.drv = &(const struct bc12_drv) {
/* bd9995x uses a single task thread for both ports */
- .usb_charger_task = NULL,
+ .usb_charger_task_init = NULL,
+ .usb_charger_task_event = NULL,
.set_switches = bd9995x_set_switches,
#if defined(CONFIG_CHARGE_RAMP_SW)
.ramp_allowed = bd9995x_ramp_allowed,
diff --git a/driver/charger/rt946x.c b/driver/charger/rt946x.c
index a4cfa5d2eb..1f932b87f5 100644
--- a/driver/charger/rt946x.c
+++ b/driver/charger/rt946x.c
@@ -1528,7 +1528,7 @@ static void rt946x_bc12_workaround(void)
}
DECLARE_DEFERRED(rt946x_bc12_workaround);
-static void rt946x_usb_charger_task(const int unused)
+static void rt946x_usb_charger_task_init(const int unused_port)
{
struct charge_port_info chg;
int bc12_type = CHARGE_SUPPLIER_NONE;
@@ -1911,7 +1911,9 @@ const struct charger_drv rt946x_drv = {
#ifdef HAS_TASK_USB_CHG
const struct bc12_drv rt946x_bc12_drv = {
- .usb_charger_task = rt946x_usb_charger_task,
+ .usb_charger_task_init = rt946x_usb_charger_task_init,
+ /* events handled in init */
+ .usb_charger_task_event = NULL,
.ramp_allowed = rt946x_ramp_allowed,
.ramp_max = rt946x_ramp_max,
};
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
diff --git a/driver/ppc/rt1739.c b/driver/ppc/rt1739.c
index cd968258d7..7b08faac83 100644
--- a/driver/ppc/rt1739.c
+++ b/driver/ppc/rt1739.c
@@ -362,36 +362,36 @@ static enum charge_supplier rt1739_bc12_get_device_type(int port)
}
}
-static void rt1739_usb_charger_task(const int port)
+static void rt1739_usb_charger_task_init(const int port)
{
rt1739_enable_bc12_detection(port, false);
+}
- while (1) {
- uint32_t evt = task_wait_event(-1);
- 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)
- rt1739_enable_bc12_detection(port, true);
- else
- rt1739_update_charge_manager(
- port, CHARGE_SUPPLIER_NONE);
- }
+static void rt1739_usb_charger_task_event(const int port, uint32_t evt)
+{
+ 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)
+ rt1739_enable_bc12_detection(port, true);
+ else
+ rt1739_update_charge_manager(
+ port, CHARGE_SUPPLIER_NONE);
+ }
- /* detection done, update charge_manager and stop detection */
- if (evt & USB_CHG_EVENT_BC12) {
- enum charge_supplier supplier;
+ /* detection done, update charge_manager and stop detection */
+ if (evt & USB_CHG_EVENT_BC12) {
+ enum charge_supplier supplier;
- if (is_non_pd_sink)
- supplier = rt1739_bc12_get_device_type(port);
- else
- supplier = CHARGE_SUPPLIER_NONE;
- rt1739_update_charge_manager(port, supplier);
- rt1739_enable_bc12_detection(port, false);
- }
+ if (is_non_pd_sink)
+ supplier = rt1739_bc12_get_device_type(port);
+ else
+ supplier = CHARGE_SUPPLIER_NONE;
+ rt1739_update_charge_manager(port, supplier);
+ rt1739_enable_bc12_detection(port, false);
}
}
@@ -457,7 +457,8 @@ const struct ppc_drv rt1739_ppc_drv = {
};
const struct bc12_drv rt1739_bc12_drv = {
- .usb_charger_task = rt1739_usb_charger_task,
+ .usb_charger_task_init = rt1739_usb_charger_task_init,
+ .usb_charger_task_event = rt1739_usb_charger_task_event,
};
#ifdef CONFIG_BC12_SINGLE_DRIVER
diff --git a/driver/tcpm/rt1718s.c b/driver/tcpm/rt1718s.c
index bf87478bf0..d90e09805d 100644
--- a/driver/tcpm/rt1718s.c
+++ b/driver/tcpm/rt1718s.c
@@ -343,38 +343,37 @@ static void rt1718s_update_charge_manager(int port,
}
}
-static void rt1718s_bc12_usb_charger_task(const int port)
+static void rt1718s_bc12_usb_charger_task_init(const int port)
{
rt1718s_enable_bc12_sink(port, false);
+}
- while (1) {
- uint32_t evt = task_wait_event(-1);
- bool is_non_pd_sink = !pd_capable(port) &&
- !usb_charger_port_is_sourcing_vbus(port) &&
- pd_check_vbus_level(port, VBUS_PRESENT);
+static void rt1718s_bc12_usb_charger_task_event(const int port, uint32_t evt)
+{
+ bool is_non_pd_sink = !pd_capable(port) &&
+ !usb_charger_port_is_sourcing_vbus(port) &&
+ pd_check_vbus_level(port, VBUS_PRESENT);
- if (evt & USB_CHG_EVENT_VBUS) {
+ if (evt & USB_CHG_EVENT_VBUS) {
- if (is_non_pd_sink)
- rt1718s_enable_bc12_sink(port, true);
- else
- rt1718s_update_charge_manager(
- port, CHARGE_SUPPLIER_NONE);
- }
+ if (is_non_pd_sink)
+ rt1718s_enable_bc12_sink(port, true);
+ else
+ rt1718s_update_charge_manager(
+ port, CHARGE_SUPPLIER_NONE);
+ }
- /* detection done, update charge_manager and stop detection */
- if (evt & USB_CHG_EVENT_BC12) {
- int type;
+ /* detection done, update charge_manager and stop detection */
+ if (evt & USB_CHG_EVENT_BC12) {
+ int type;
- if (is_non_pd_sink)
- type = rt1718s_get_bc12_type(port);
- else
- type = CHARGE_SUPPLIER_NONE;
+ if (is_non_pd_sink)
+ type = rt1718s_get_bc12_type(port);
+ else
+ type = CHARGE_SUPPLIER_NONE;
- rt1718s_update_charge_manager(
- port, type);
- rt1718s_enable_bc12_sink(port, false);
- }
+ rt1718s_update_charge_manager(port, type);
+ rt1718s_enable_bc12_sink(port, false);
}
}
@@ -762,5 +761,6 @@ const struct tcpm_drv rt1718s_tcpm_drv = {
};
const struct bc12_drv rt1718s_bc12_drv = {
- .usb_charger_task = rt1718s_bc12_usb_charger_task,
+ .usb_charger_task_init = rt1718s_bc12_usb_charger_task_init,
+ .usb_charger_task_event = rt1718s_bc12_usb_charger_task_event,
};