summaryrefslogtreecommitdiff
path: root/src/ec
diff options
context:
space:
mode:
authorShelley Chen <shchen@chromium.org>2017-09-29 14:15:11 -0700
committerAaron Durbin <adurbin@chromium.org>2017-10-20 22:49:31 +0000
commitebd533065f0dd7f00d6452e5019f685b769d5b0e (patch)
tree8f466db905b0748dc8aec71297f9269aa8d057c0 /src/ec
parentbd885c5bac425c589582a610bd2dc92dd3809e06 (diff)
downloadcoreboot-ebd533065f0dd7f00d6452e5019f685b769d5b0e.tar.xz
chromeec: Add function to retrieve usb c charger info
Add google_chromeec_get_usb_pd_power_info(), which will call the EC_CMD_USB_PD_POWER_INFO host command to retrieve the current and voltage info of the usb c charger. Returns power info in watts. BUG=b:37473486 BRANCH=None TEST=output debug info to make sure that correct power is returned. Change-Id: Ie14a0a6163e1c2699cb20b4422c8062164d92076 Signed-off-by: Shelley Chen <shchen@chromium.org> Reviewed-on: https://review.coreboot.org/21771 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Aaron Durbin <adurbin@chromium.org>
Diffstat (limited to 'src/ec')
-rw-r--r--src/ec/google/chromeec/ec.c29
-rw-r--r--src/ec/google/chromeec/ec.h9
2 files changed, 38 insertions, 0 deletions
diff --git a/src/ec/google/chromeec/ec.c b/src/ec/google/chromeec/ec.c
index 537fe25283..7ab9d6bdab 100644
--- a/src/ec/google/chromeec/ec.c
+++ b/src/ec/google/chromeec/ec.c
@@ -609,6 +609,35 @@ int google_chromeec_set_usb_charge_mode(u8 port_id, enum usb_charge_mode mode)
return google_chromeec_command(&cmd);
}
+/* Get charger power info in Watts. Also returns type of charger */
+int google_chromeec_get_usb_pd_power_info(enum usb_chg_type *type,
+ u32 *max_watts)
+{
+ struct ec_params_usb_pd_power_info req = {
+ .port = PD_POWER_CHARGING_PORT,
+ };
+ struct ec_response_usb_pd_power_info rsp;
+ struct chromeec_command cmd = {
+ .cmd_code = EC_CMD_USB_PD_POWER_INFO,
+ .cmd_version = 0,
+ .cmd_data_in = &req,
+ .cmd_size_in = sizeof(req),
+ .cmd_data_out = &rsp,
+ .cmd_size_out = sizeof(rsp),
+ .cmd_dev_index = 0,
+ };
+ struct usb_chg_measures m;
+ int rv = google_chromeec_command(&cmd);
+ if (rv != 0)
+ return rv;
+ /* values are given in milliAmps and milliVolts */
+ *type = rsp.type;
+ m = rsp.meas;
+ *max_watts = (m.current_max * m.voltage_max) / 1000000;
+
+ return 0;
+}
+
int google_chromeec_set_usb_pd_role(u8 port, enum usb_pd_control_role role)
{
struct ec_params_usb_pd_control req = {
diff --git a/src/ec/google/chromeec/ec.h b/src/ec/google/chromeec/ec.h
index e4ad0ffb05..25a90d756d 100644
--- a/src/ec/google/chromeec/ec.h
+++ b/src/ec/google/chromeec/ec.h
@@ -81,6 +81,15 @@ enum usb_charge_mode {
};
int google_chromeec_set_usb_charge_mode(u8 port_id, enum usb_charge_mode mode);
int google_chromeec_set_usb_pd_role(u8 port, enum usb_pd_control_role role);
+/*
+ * Retrieve the charger type and max wattage.
+ *
+ * @param type charger type
+ * @param max_watts charger max wattage
+ * @return non-zero for error, otherwise 0.
+ */
+int google_chromeec_get_usb_pd_power_info(enum usb_chg_type *type,
+ u32 *max_watts);
/* internal structure to send a command to the EC and wait for response. */
struct chromeec_command {