summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaisuke Nojiri <dnojiri@chromium.org>2019-05-02 17:58:39 -0700
committerCommit Bot <commit-bot@chromium.org>2019-05-23 16:35:36 +0000
commit22bcd682511db4c323514fd9ffd046b9f780273f (patch)
treeea493ef322b66ba32c91038588b896a83d1c3985
parent58240c64498ae68f9d6801b4126af345b6d015a4 (diff)
downloadchrome-ec-22bcd682511db4c323514fd9ffd046b9f780273f.tar.gz
PI3USB9281: Serialize mux setting and BC12 detection
Currently a PD task and a USB charger task can talk to PI3USB9281 to update mux setting and to get BC12 information interleavingly. We suspect this causes unreliable BC12 detection including detach detection. This patch makes the usb_charger_set_switches API schedule a mux update instead of changing the mux setting by itself wakes up a USB charger task. A USB charger task solely handles BC12 detection and mux setting. Signed-off-by: Daisuke Nojiri <dnojiri@chromium.org> BUG=b/125176293 BRANCH=nami TEST=Verify BC1.2 and PD charger can be detected correctly and power_supply_info prints 'Discharging' when they're disconnected on Syndra. Change-Id: Iadaf9087be74a4ba0412dd08b95a40eac4e69ce1 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1594332 Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org> Commit-Queue: Daisuke Nojiri <dnojiri@chromium.org> Tested-by: Daisuke Nojiri <dnojiri@chromium.org>
-rw-r--r--driver/bc12/pi3usb9281.c12
-rw-r--r--include/usb_charge.h7
2 files changed, 9 insertions, 10 deletions
diff --git a/driver/bc12/pi3usb9281.c b/driver/bc12/pi3usb9281.c
index eb4e6a8b6d..0c43bb199b 100644
--- a/driver/bc12/pi3usb9281.c
+++ b/driver/bc12/pi3usb9281.c
@@ -37,7 +37,6 @@
/* Store the state of our USB data switches so that they can be restored. */
static int usb_switch_state[CONFIG_USB_PD_PORT_COUNT];
-static struct mutex usb_switch_lock[CONFIG_USB_PD_PORT_COUNT];
static int pi3usb9281_reset(int port);
static int pi3usb9281_get_interrupts(int port);
@@ -278,14 +277,10 @@ void usb_charger_set_switches(int port, enum usb_switch setting)
/* If switch is not changing then return */
if (setting == usb_switch_state[port])
return;
-
- mutex_lock(&usb_switch_lock[port]);
if (setting != USB_SWITCH_RESTORE)
usb_switch_state[port] = setting;
-
- pi3usb9281_set_switches(port, usb_switch_state[port]);
-
- mutex_unlock(&usb_switch_lock[port]);
+ CPRINTS("USB MUX %d", usb_switch_state[port]);
+ task_set_event(TASK_ID_USB_CHG_P0 + port, USB_CHG_EVENT_MUX, 0);
}
static int pc3usb9281_read_interrupt(int port)
@@ -438,6 +433,9 @@ void usb_charger_task(void *u)
evt = bc12_detect(port);
}
+ if (evt & USB_CHG_EVENT_MUX)
+ pi3usb9281_set_switches(port, usb_switch_state[port]);
+
/*
* Re-enable interrupts on pericom charger detector since the
* chip may periodically reset itself, and come back up with
diff --git a/include/usb_charge.h b/include/usb_charge.h
index e7de9a0b3f..ed19b742fa 100644
--- a/include/usb_charge.h
+++ b/include/usb_charge.h
@@ -40,9 +40,10 @@ enum usb_charge_mode {
int usb_charge_set_mode(int usb_port_id, enum usb_charge_mode mode);
#ifdef HAS_TASK_USB_CHG_P0
-#define USB_CHG_EVENT_BC12 TASK_EVENT_CUSTOM(1)
-#define USB_CHG_EVENT_VBUS TASK_EVENT_CUSTOM(2)
-#define USB_CHG_EVENT_INTR TASK_EVENT_CUSTOM(4)
+#define USB_CHG_EVENT_BC12 TASK_EVENT_CUSTOM(1 << 0)
+#define USB_CHG_EVENT_VBUS TASK_EVENT_CUSTOM(1 << 1)
+#define USB_CHG_EVENT_INTR TASK_EVENT_CUSTOM(1 << 2)
+#define USB_CHG_EVENT_MUX TASK_EVENT_CUSTOM(1 << 3)
#endif
/*