summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTing Shen <phoenixshen@google.com>2020-07-13 14:14:40 +0800
committerCommit Bot <commit-bot@chromium.org>2020-08-19 12:35:27 +0000
commit2be6fecd9749b47f7302a2ea31ba8a25cfa911f6 (patch)
treeef7575035ae8712ada5af94d02e1c6b1a844dcf2
parenta9b7744a5dcac7bc78c29a072216bc890840cb61 (diff)
downloadchrome-ec-2be6fecd9749b47f7302a2ea31ba8a25cfa911f6.tar.gz
mt6360: revise vbus presence detection logic
In Asurada rev1, BC1.2 detection enable pin (EN_USB_C0_BC12_DET) is connected directly to VBUS. Thus, two thing changed in software side: 1. Don't need CONFIG_MT6360_BC12_GPIO anymore. The config is still kept to support rev0. 2. VBUS detach won't trigger BC1.2 detection. Driver implementation for rev0 board triggers BC1.2 detection even if we already know charger is removed. And wait for MT6360 return "no charger" result to update charge manager. This CL changes its behavior to skip BC1.2 detection when possible. BUG=b:159583342 TEST=manually BRANCH=master Signed-off-by: Ting Shen <phoenixshen@google.com> Change-Id: Ifa5366a592bc7199df85ea5489eab5010322448f Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2294533 Reviewed-by: Nicolas Boichat <drinkcat@chromium.org> Commit-Queue: Ting Shen <phoenixshen@chromium.org> Tested-by: Ting Shen <phoenixshen@chromium.org>
-rw-r--r--board/asurada/board.h1
-rw-r--r--driver/bc12/mt6360.c40
2 files changed, 29 insertions, 12 deletions
diff --git a/board/asurada/board.h b/board/asurada/board.h
index 13e0f3bcb7..7ea3048408 100644
--- a/board/asurada/board.h
+++ b/board/asurada/board.h
@@ -41,6 +41,7 @@
#define CONFIG_BC12_DETECT_MT6360
#define CONFIG_BC12_DETECT_PI3USB9201
#undef CONFIG_BC12_SINGLE_DRIVER
+/* TODO(b/159583342): remove after rev0 deprecated */
#define CONFIG_MT6360_BC12_GPIO
#define CONFIG_USB_CHARGER
diff --git a/driver/bc12/mt6360.c b/driver/bc12/mt6360.c
index ed4029cb63..49de200f52 100644
--- a/driver/bc12/mt6360.c
+++ b/driver/bc12/mt6360.c
@@ -112,16 +112,10 @@ static int mt6360_enable_bc12_detection(int en)
return rv;
}
-static void mt6360_update_charge_manager(int port)
+static void mt6360_update_charge_manager(int port,
+ enum charge_supplier new_bc12_type)
{
- static int current_bc12_type = CHARGE_SUPPLIER_NONE;
- int reg;
- int new_bc12_type = CHARGE_SUPPLIER_NONE;
-
- mt6360_read8(MT6360_REG_DPDMIRQ, &reg);
-
- if (pd_snk_is_vbus_provided(port) && (reg & MT6360_MASK_DPDMIRQ_ATTACH))
- new_bc12_type = mt6360_get_bc12_device_type();
+ static enum charge_supplier current_bc12_type = CHARGE_SUPPLIER_NONE;
if (new_bc12_type != current_bc12_type) {
charge_manager_update_charge(current_bc12_type, port, NULL);
@@ -137,6 +131,23 @@ static void mt6360_update_charge_manager(int port)
current_bc12_type = new_bc12_type;
}
+}
+
+static void mt6360_handle_bc12_irq(int port)
+{
+ int reg;
+
+ mt6360_read8(MT6360_REG_DPDMIRQ, &reg);
+
+ if (reg & MT6360_MASK_DPDMIRQ_ATTACH) {
+ /* Check vbus again to avoid timing issue */
+ if (pd_snk_is_vbus_provided(port))
+ mt6360_update_charge_manager(
+ port, mt6360_get_bc12_device_type());
+ else
+ mt6360_update_charge_manager(
+ 0, CHARGE_SUPPLIER_NONE);
+ }
/* write clear */
mt6360_write8(MT6360_REG_DPDMIRQ, reg);
@@ -152,12 +163,17 @@ static void mt6360_usb_charger_task(const int port)
uint32_t evt = task_wait_event(-1);
/* vbus change, start bc12 detection */
- if (evt & USB_CHG_EVENT_VBUS)
- mt6360_enable_bc12_detection(1);
+ if (evt & USB_CHG_EVENT_VBUS) {
+ if (pd_snk_is_vbus_provided(port))
+ 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_update_charge_manager(port);
+ mt6360_handle_bc12_irq(port);
mt6360_enable_bc12_detection(0);
}
}