summaryrefslogtreecommitdiff
path: root/src/ec/google/chromeec
diff options
context:
space:
mode:
authorDaisuke Nojiri <dnojiri@chromium.org>2018-01-26 17:36:44 -0800
committerAaron Durbin <adurbin@chromium.org>2018-02-17 04:00:12 +0000
commit476c2c5808a77508f31d47ce871c32a97c6e6eeb (patch)
tree6a9768867464b015cafae87353e67c71d430b988 /src/ec/google/chromeec
parent3fe3f0409cd340112d62283bf79be9f106a6dff8 (diff)
downloadcoreboot-476c2c5808a77508f31d47ce871c32a97c6e6eeb.tar.xz
chromeec: Add google_chromeec_pd_get_amode
The google_chromeec_pd_get_amode API checks whether TCPM is in a specified alternate mode or not. BUG=b:72387533 BRANCH=none TEST=See 23746 "mb/google/fizz: Wait until display is ready" Change-Id: Ib9b4ad06b61326fa167c77758603e038d817f928 Signed-off-by: Daisuke Nojiri <dnojiri@chromium.org> Reviewed-on: https://review.coreboot.org/23744 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Julius Werner <jwerner@chromium.org> Reviewed-by: Furquan Shaikh <furquan@google.com>
Diffstat (limited to 'src/ec/google/chromeec')
-rw-r--r--src/ec/google/chromeec/ec.c48
-rw-r--r--src/ec/google/chromeec/ec.h1
2 files changed, 49 insertions, 0 deletions
diff --git a/src/ec/google/chromeec/ec.c b/src/ec/google/chromeec/ec.c
index 4bb7bb38cf..7fc360af64 100644
--- a/src/ec/google/chromeec/ec.c
+++ b/src/ec/google/chromeec/ec.c
@@ -936,3 +936,51 @@ int google_ec_running_ro(void)
#endif /* ! __SMM__ */
#endif /* ! __PRE_RAM__ */
+
+/**
+ * Check if EC/TCPM is in an alternate mode or not.
+ *
+ * @param svid SVID of the alternate mode to check
+ * @return 0: Not in the mode. -1: Error. 1: Yes.
+ */
+int google_chromeec_pd_get_amode(uint16_t svid)
+{
+ struct ec_response_usb_pd_ports r;
+ struct chromeec_command cmd;
+ int i;
+
+ cmd.cmd_code = EC_CMD_USB_PD_PORTS;
+ cmd.cmd_version = 0;
+ cmd.cmd_data_in = NULL;
+ cmd.cmd_size_in = 0;
+ cmd.cmd_data_out = &r;
+ cmd.cmd_size_out = sizeof(r);
+ cmd.cmd_dev_index = 0;
+ if (google_chromeec_command(&cmd) < 0)
+ return -1;
+
+ for (i = 0; i < r.num_ports; i++) {
+ struct ec_params_usb_pd_get_mode_request p;
+ struct ec_params_usb_pd_get_mode_response res;
+
+ p.port = i;
+ p.svid_idx = 0;
+ cmd.cmd_code = EC_CMD_USB_PD_GET_AMODE;
+ cmd.cmd_version = 0;
+ cmd.cmd_data_in = &p;
+ cmd.cmd_size_in = sizeof(p);
+ cmd.cmd_data_out = &res;
+ cmd.cmd_size_out = sizeof(res);
+ cmd.cmd_dev_index = 0;
+
+ do {
+ if (google_chromeec_command(&cmd) < 0)
+ return -1;
+ if (res.svid == svid)
+ return 1;
+ p.svid_idx++;
+ } while (res.svid);
+ }
+
+ return 0;
+}
diff --git a/src/ec/google/chromeec/ec.h b/src/ec/google/chromeec/ec.h
index c15a50641a..945e0b9891 100644
--- a/src/ec/google/chromeec/ec.h
+++ b/src/ec/google/chromeec/ec.h
@@ -36,6 +36,7 @@ u8 google_chromeec_get_event(void);
bool google_chromeec_is_uhepi_supported(void);
int google_ec_running_ro(void);
void google_chromeec_init(void);
+int google_chromeec_pd_get_amode(uint16_t svid);
/* Device events */
uint64_t google_chromeec_get_device_enabled_events(void);