Tim Wawrzynczak has uploaded this change for review.

View Change

ec/google/chromeec: Add new wrappers for host commands

Add new functions to get (from the EC):
1) The number of USB-PD ports
2) The capabilities of each port (EC_CMD_GET_PD_PORT_CAPS)

BUG=b:146506369
BRANCH=none
TEST=Instrumented calls to these and verified the data

Change-Id: I57edbe1592cd28b005f01679ef8a8b5de3e1f586
Signed-off-by: Tim Wawrzynczak <twawrzynczak@chromium.org>
---
M src/ec/google/chromeec/ec.c
M src/ec/google/chromeec/ec.h
2 files changed, 86 insertions(+), 3 deletions(-)

git pull ssh://review.coreboot.org:29418/coreboot refs/changes/40/38540/1
diff --git a/src/ec/google/chromeec/ec.c b/src/ec/google/chromeec/ec.c
index 0b23034..7a4f27f 100644
--- a/src/ec/google/chromeec/ec.c
+++ b/src/ec/google/chromeec/ec.c
@@ -15,16 +15,21 @@

#include <stdint.h>
#include <string.h>
-#include <cbmem.h>
-#include <console/console.h>
+#include <arch/acpi.h>
+#include <arch/acpi_device.h>
+#include <arch/acpigen.h>
#include <assert.h>
#include <bootmode.h>
#include <bootstate.h>
+#include <cbmem.h>
+#include <console/console.h>
#include <delay.h>
+#include <device/device.h>
+#include <device/path.h>
#include <elog.h>
#include <rtc.h>
-#include <stdlib.h>
#include <security/vboot/vboot_common.h>
+#include <stdlib.h>
#include <timer.h>

#include "chip.h"
@@ -1419,6 +1424,60 @@
return ec_image_type;
}

+int google_chromeec_get_num_pd_ports(int *num_ports)
+{
+ struct ec_response_charge_port_count resp = {};
+ struct chromeec_command cmd = {
+ .cmd_code = EC_CMD_CHARGE_PORT_COUNT,
+ .cmd_version = 0,
+ .cmd_data_out = &resp,
+ .cmd_size_in = 0,
+ .cmd_size_out = sizeof(resp),
+ .cmd_dev_index = 0,
+ };
+ int rv;
+
+ rv = google_chromeec_command(&cmd);
+ if (rv)
+ return rv;
+
+ *num_ports = resp.port_count;
+ return 0;
+}
+
+int google_chromeec_get_pd_port_caps(int port,
+ enum ec_pd_power_role_caps *power_role_cap,
+ enum ec_pd_try_power_role_caps *try_power_role_cap,
+ enum ec_pd_data_role_caps *data_role_cap,
+ enum ec_pd_port_location *port_location)
+{
+ struct ec_params_get_pd_port_caps params = {
+ .port = port,
+ };
+ struct ec_response_get_pd_port_caps resp = {};
+ struct chromeec_command cmd = {
+ .cmd_code = EC_CMD_GET_PD_PORT_CAPS,
+ .cmd_version = 0,
+ .cmd_data_in = &params,
+ .cmd_size_in = sizeof(params),
+ .cmd_data_out = &resp,
+ .cmd_size_out = sizeof(resp),
+ .cmd_dev_index = 0,
+ };
+ int rv;
+
+ rv = google_chromeec_command(&cmd);
+ if (rv)
+ return rv;
+
+ *power_role_cap = resp.pd_power_role_cap;
+ *try_power_role_cap = resp.pd_try_power_role_cap;
+ *data_role_cap = resp.pd_data_role_cap;
+ *port_location = resp.pd_port_location;
+
+ return 0;
+}
+
void google_chromeec_init(void)
{
google_chromeec_log_uptimeinfo();
diff --git a/src/ec/google/chromeec/ec.h b/src/ec/google/chromeec/ec.h
index d90d24c..8051486 100644
--- a/src/ec/google/chromeec/ec.h
+++ b/src/ec/google/chromeec/ec.h
@@ -299,4 +299,28 @@
*/
int google_chromeec_get_cmd_versions(int command, uint32_t *pmask);

+/**
+ * Get number of PD-capable USB ports from EC.
+ *
+ * @param *num_ports If successful, num_ports is the number
+ * of PD-capable USB ports according to the EC.
+ * @return 0 on success, -1 on error
+ */
+int google_chromeec_get_num_pd_ports(int *num_ports);
+
+/**
+ * Get role-based capabilities for a USB-PD port
+ *
+ * @param port Which port to get information about
+ * @param *power_role_cap The power-role capabillity of the port
+ * @param *try_power_role_cap The Try-power-role capability of the port
+ * @param *data_role_cap The data role capability of the port
+ * @param *port_location Location of the port on the device
+ * @return 0 on success, -1 on error
+ */
+int google_chromeec_get_pd_port_caps(int port,
+ enum ec_pd_power_role_caps *power_role_cap,
+ enum ec_pd_try_power_role_caps *try_power_role_cap,
+ enum ec_pd_data_role_caps *data_role_cap,
+ enum ec_pd_port_location *port_location);
#endif /* _EC_GOOGLE_CHROMEEC_EC_H */

To view, visit change 38540. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: coreboot
Gerrit-Branch: master
Gerrit-Change-Id: I57edbe1592cd28b005f01679ef8a8b5de3e1f586
Gerrit-Change-Number: 38540
Gerrit-PatchSet: 1
Gerrit-Owner: Tim Wawrzynczak <twawrzynczak@chromium.org>
Gerrit-MessageType: newchange