Shelley Chen has uploaded this change for review. ( https://review.coreboot.org/21771
Change subject: chromeec: Add function to retrieve usb c charger info ......................................................................
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_CONTROL 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 --- M src/ec/google/chromeec/ec.c M src/ec/google/chromeec/ec.h 2 files changed, 31 insertions(+), 0 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/71/21771/1
diff --git a/src/ec/google/chromeec/ec.c b/src/ec/google/chromeec/ec.c index 03d4c3b..47bd5a3 100644 --- a/src/ec/google/chromeec/ec.c +++ b/src/ec/google/chromeec/ec.c @@ -622,6 +622,36 @@ return google_chromeec_command(&cmd); }
+/* Get charger power info in Watts */ +int google_chromeec_get_usb_pd_power_info(void) +{ + 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; + + google_chromeec_command(&cmd); + + m = rsp.meas; + + if (rsp.type == USB_CHG_TYPE_PD) { + /* values are given in milliAmps and milliVolts */ + return (m.current_max * m.voltage_max)/1000000; + } + /* If barrel jack, then just return 0 */ + 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 3a7cadd..47760fb 100644 --- a/src/ec/google/chromeec/ec.h +++ b/src/ec/google/chromeec/ec.h @@ -89,6 +89,7 @@ }; 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); +int google_chromeec_get_usb_pd_power_info(void);
/* internal structure to send a command to the EC and wait for response. */ struct chromeec_command {