summaryrefslogtreecommitdiff
path: root/common/charge_manager.c
diff options
context:
space:
mode:
authorAlec Berg <alecaberg@chromium.org>2015-04-03 10:47:48 -0700
committerChromeOS Commit Bot <chromeos-commit-bot@chromium.org>2015-05-01 03:44:19 +0000
commit6dce2424d99de40763a039eb099efcd5b0a52cb2 (patch)
treed54d49f41cb50889c7c00886c3bdfb45877d56d9 /common/charge_manager.c
parent62080646fe4312de930e4c4d766106438eae5efc (diff)
downloadchrome-ec-6dce2424d99de40763a039eb099efcd5b0a52cb2.tar.gz
charge_manager: modify PD power HC to give more info on current
Change the EC_CMD_USB_PD_POWER_INFO host command to report the input current limit and the max current theoretically possible given the charger. The input current limit field is useful for logging purposes and the max current field is useful to give to powerd to determine if we have a low power charger connected. The max current is determined by checking if the charge supplier is allowed to ramp. If the charge supplier is allowed to ramp and has not completed ramping yet, then max current is the max current that we are allowed to ramp up to. Once the ramp has completed, then max current is the stable charging current. If the charge supplier is not allowed to ramp, then max current is simply the max current as registered with charge_manager. The point here is to keep the max as high as possible until we know for sure it is lower to avoid showing the user the low power notification until we know for sure. This CL also adds a new charger type, USB_CHG_TYPE_UNKNOWN. For a short period after a charger is plugged in, the supplier type may change and PD negotiation is still in process, and therefore we tell the host we have an unknown charger type. This allows powerd to show the charging icon, but delay determining if this is a low power charger until we know for sure. BUG=chrome-os-partner:38548 BRANCH=samus TEST=tested with zinger, a DCP, an SDP, and a proprietary charger. tested that low power notification never pops up with zinger, even if you purposely wedge charge circuit with "charger voltage 7000" on EC console. tested that the other chargers all pop up low power notification once the supplier changes from UNKNOWN to the real supplier. used "ectool --name=cros_pd usbpdpower" to check current values. Change-Id: If8a9a1799504cc2a13238f4e6ec917d25d972b22 Signed-off-by: Alec Berg <alecaberg@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/265066 Reviewed-by: Sameer Nanda <snanda@chromium.org>
Diffstat (limited to 'common/charge_manager.c')
-rw-r--r--common/charge_manager.c33
1 files changed, 31 insertions, 2 deletions
diff --git a/common/charge_manager.c b/common/charge_manager.c
index 83b0582ddd..7e0600d8d9 100644
--- a/common/charge_manager.c
+++ b/common/charge_manager.c
@@ -192,11 +192,40 @@ static void charge_manager_fill_power_info(int port,
r->meas.voltage_max = available_charge[sup][port].voltage;
if (use_ramp_current) {
- r->meas.current_max = chg_ramp_get_current_limit();
+ /*
+ * If charge_ramp has not detected charger yet,
+ * then charger type is unknown.
+ */
+ if (!chg_ramp_is_detected())
+ r->type = USB_CHG_TYPE_UNKNOWN;
+
+ /* Current limit is output of ramp module */
+ r->meas.current_lim = chg_ramp_get_current_limit();
+
+ /*
+ * If ramp is allowed, then the max current depends
+ * on if ramp is stable. If ramp is stable, then
+ * max current is same as input current limit. If
+ * ramp is not stable, then we report the maximum
+ * current we could ramp up to for this supplier.
+ * If ramp is not allowed, max current is just the
+ * available charge current.
+ */
+ if (board_is_ramp_allowed(sup)) {
+ r->meas.current_max = chg_ramp_is_stable() ?
+ r->meas.current_lim :
+ board_get_ramp_current_limit(
+ sup,
+ available_charge[sup][port].current);
+ } else {
+ r->meas.current_max =
+ available_charge[sup][port].current;
+ }
+
r->max_power =
r->meas.current_max * r->meas.voltage_max;
} else {
- r->meas.current_max =
+ r->meas.current_max = r->meas.current_lim =
available_charge[sup][port].current;
r->max_power = POWER(available_charge[sup][port]);
}