summaryrefslogtreecommitdiff
path: root/driver
diff options
context:
space:
mode:
authorMarco Chen <marcochen@google.com>2021-01-27 18:07:18 +0800
committerCommit Bot <commit-bot@chromium.org>2021-01-28 05:20:51 +0000
commit8928ffebbb11cc652678458023fff83a04a4c45c (patch)
tree26508054967fcc53af50b6f3e7e9f5391bd61ebb /driver
parent14828a6cb4cef03608261fd05659c90d90ccca5b (diff)
downloadchrome-ec-8928ffebbb11cc652678458023fff83a04a4c45c.tar.gz
max14637: call bc12_detect in VBUS off can't update charge as available
Originally bc12_detect function not only detects BC12 status but also update result to charge manager. Now bc12_detect can be called not only when VBUS is on but also off because of CL:2626791. The result is that charge manager would report charging available even if VBUS is off. As a result, we split charger manager update from bc12_detect as the single function so bc12_detect can be called when VBUS is on or off but charger manager update for available charging will be triggered when VBUS is on. BUG=b:177845650, b:177265749, b:178509655 BRANCH=octopus TEST=make buildall -j 8 TEST=check online parameter in /sys/class/power_supply can report correct value when PD adapter or BC12 charger is plugged in/out. TEST=check `ectool usbpdpower` can report correct values for PD adapter and BC12 charger. Change-Id: Ifc4f23edb9272177a6b3637b812b86cf9bef2378 Signed-off-by: Marco Chen <marcochen@chromium.org> Signed-off-by: Marco Chen <marcochen@google.com> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2652112 Reviewed-by: Aseda Aboagye <aaboagye@chromium.org> (cherry picked from commit 302eff661a321bee4bb6420c490f6610e8e48c23) Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2654669 Reviewed-by: Henry Sun <henrysun@google.com>
Diffstat (limited to 'driver')
-rw-r--r--driver/bc12/max14637.c64
1 files changed, 43 insertions, 21 deletions
diff --git a/driver/bc12/max14637.c b/driver/bc12/max14637.c
index 52d7391974..dfa5075705 100644
--- a/driver/bc12/max14637.c
+++ b/driver/bc12/max14637.c
@@ -59,15 +59,45 @@ static void activate_chip_enable(
}
/**
- * Perform BC1.2 detection and update charge manager.
+ * Update BC1.2 detected status to charge manager.
*
* @param port: The Type-C port where VBUS is present.
*/
-static void bc12_detect(const int port)
+static void update_bc12_status_to_charger_manager(const int port)
{
const struct max14637_config_t * const cfg = &max14637_config[port];
struct charge_port_info new_chg;
+ new_chg.voltage = USB_CHARGER_VOLTAGE_MV;
+#if defined(CONFIG_CHARGE_RAMP_SW) || defined(CONFIG_CHARGE_RAMP_HW)
+ /*
+ * The driver assumes that CHG_AL_N and SW_OPEN are not connected,
+ * therefore an activated CHG_DET indicates whether the source is NOT a
+ * low-power standard downstream port (SDP). The system will have to
+ * ramp the current to determine the limit.
+ */
+ new_chg.current = is_chg_det_activated(cfg) ? 2400 : 500;
+#else
+ /*
+ * If the board doesn't support charge ramping, then assume the lowest
+ * denominator; that is assume the charger detected is a weak dedicated
+ * charging port (DCP) which can only supply 500mA.
+ */
+ new_chg.current = 500;
+#endif /* !defined(CONFIG_CHARGE_RAMP_SW && CONFIG_CHARGE_RAMP_HW) */
+
+ charge_manager_update_charge(CHARGE_SUPPLIER_OTHER, port, &new_chg);
+}
+
+/**
+ * Perform BC1.2 detection.
+ *
+ * @param port: The Type-C port where VBUS is present.
+ */
+static void bc12_detect(const int port)
+{
+ const struct max14637_config_t * const cfg = &max14637_config[port];
+
/*
* Enable the IC to begin detection and connect switches if
* necessary. This is only necessary if the port power role is a
@@ -84,31 +114,13 @@ static void bc12_detect(const int port)
msleep(CONFIG_BC12_MAX14637_DELAY_FROM_OFF_TO_ON_MS);
activate_chip_enable(cfg, 1);
- new_chg.voltage = USB_CHARGER_VOLTAGE_MV;
#if defined(CONFIG_CHARGE_RAMP_SW) || defined(CONFIG_CHARGE_RAMP_HW)
/*
* Apple or TomTom charger detection can take as long as 600ms. Wait a
* little bit longer for margin.
*/
msleep(630);
-
- /*
- * The driver assumes that CHG_AL_N and SW_OPEN are not connected,
- * therefore an activated CHG_DET indicates whether the source is NOT a
- * low-power standard downstream port (SDP). The system will have to
- * ramp the current to determine the limit.
- */
- new_chg.current = is_chg_det_activated(cfg) ? 2400 : 500;
-#else
- /*
- * If the board doesn't support charge ramping, then assume the lowest
- * denominator; that is assume the charger detected is a weak dedicated
- * charging port (DCP) which can only supply 500mA.
- */
- new_chg.current = 500;
#endif /* !defined(CONFIG_CHARGE_RAMP_SW && CONFIG_CHARGE_RAMP_HW) */
-
- charge_manager_update_charge(CHARGE_SUPPLIER_OTHER, port, &new_chg);
}
/**
@@ -135,11 +147,21 @@ static void detect_or_power_down_ic(const int port)
/* Turn on the 5V rail to allow the chip to be powered. */
power_5v_enable(task_get_current(), 1);
#endif
- if (pd_get_role(port) == PD_ROLE_SINK)
+ if (pd_get_role(port) == PD_ROLE_SINK) {
bc12_detect(port);
+ update_bc12_status_to_charger_manager(port);
+ }
} else {
/* Let charge manager know there's no more charge available. */
charge_manager_update_charge(CHARGE_SUPPLIER_OTHER, port, NULL);
+ /*
+ * If latest attached charger is PD Adapter then it would be
+ * detected as DCP and data switch of USB2.0 would be open which
+ * prevents USB 2.0 data path from working later. As a result,
+ * bc12_detect() is called again here and SCP would be detected
+ * due to D+/D- are NC (open) if nothing is attached then data
+ * switch of USB2.0 can be kept close from now on.
+ */
bc12_detect(port);
#if defined(CONFIG_POWER_PP5000_CONTROL) && defined(HAS_TASK_CHIPSET)
/* Issue a request to turn off the rail. */