diff options
author | Ayushee <ayushee.shah@intel.com> | 2019-03-04 12:27:43 -0800 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2019-03-07 20:22:29 -0800 |
commit | f1b9abca8b287e18cfe63006b9b5d75c31501286 (patch) | |
tree | 5cb596bdda62544e4022af5048deff8786d35ef9 | |
parent | 19ffcaeb4176e26acf1a1c3f471ca3da9343a1ac (diff) | |
download | chrome-ec-f1b9abca8b287e18cfe63006b9b5d75c31501286.tar.gz |
usb_pd: Get current CC state
CC state has the information of type of device attached and it is
needed to configure the Intel virtual muxes hence returning the
current CC state in USB_PD_CONTROL host command.
BUG=None
BRANCH=None
TEST=Verified on Dragonegg, able to get correct CC state
Change-Id: I917321b599a17381e2ffbe5e813e676df03abd47
Signed-off-by: Ayushee <ayushee.shah@intel.com>
Reviewed-on: https://chromium-review.googlesource.com/1468049
Commit-Ready: Ayushee Shah <ayushee.shah@intel.com>
Tested-by: Ayushee Shah <ayushee.shah@intel.com>
Reviewed-by: Jett Rink <jettrink@chromium.org>
-rw-r--r-- | common/usb_pd_protocol.c | 29 | ||||
-rw-r--r-- | include/ec_commands.h | 16 | ||||
-rw-r--r-- | util/ectool.c | 23 |
3 files changed, 58 insertions, 10 deletions
diff --git a/common/usb_pd_protocol.c b/common/usb_pd_protocol.c index ee60a70381..1c6d7e699c 100644 --- a/common/usb_pd_protocol.c +++ b/common/usb_pd_protocol.c @@ -4878,6 +4878,7 @@ static const enum typec_mux typec_mux_map[USB_PD_CTRL_MUX_COUNT] = { static int hc_usb_pd_control(struct host_cmd_handler_args *args) { const struct ec_params_usb_pd_control *p = args->params; + struct ec_response_usb_pd_control_v2 *r_v2 = args->response; struct ec_response_usb_pd_control_v1 *r_v1 = args->response; struct ec_response_usb_pd_control *r = args->response; @@ -4915,21 +4916,24 @@ static int hc_usb_pd_control(struct host_cmd_handler_args *args) #endif #endif - if (args->version == 0) { + switch (args->version) { + case 0: r->enabled = pd_comm_is_enabled(p->port); r->role = pd[p->port].power_role; r->polarity = pd[p->port].polarity; r->state = pd[p->port].task_state; args->response_size = sizeof(*r); - } else { - r_v1->enabled = + break; + case 1: + case 2: + r_v2->enabled = (pd_comm_is_enabled(p->port) ? PD_CTRL_RESP_ENABLED_COMMS : 0) | (pd_is_connected(p->port) ? PD_CTRL_RESP_ENABLED_CONNECTED : 0) | ((pd[p->port].flags & PD_FLAGS_PREVIOUS_PD_CONN) ? PD_CTRL_RESP_ENABLED_PD_CAPABLE : 0); - r_v1->role = + r_v2->role = (pd[p->port].power_role ? PD_CTRL_RESP_ROLE_POWER : 0) | (pd[p->port].data_role ? PD_CTRL_RESP_ROLE_DATA : 0) | ((pd[p->port].flags & PD_FLAGS_VCONN_ON) ? @@ -4942,17 +4946,24 @@ static int hc_usb_pd_control(struct host_cmd_handler_args *args) PD_CTRL_RESP_ROLE_USB_COMM : 0) | ((pd[p->port].flags & PD_FLAGS_PARTNER_EXTPOWER) ? PD_CTRL_RESP_ROLE_EXT_POWERED : 0); - r_v1->polarity = pd[p->port].polarity; - strzcpy(r_v1->state, + r_v2->polarity = pd[p->port].polarity; + strzcpy(r_v2->state, pd_state_names[pd[p->port].task_state], - sizeof(r_v1->state)); - args->response_size = sizeof(*r_v1); + sizeof(r_v2->state)); + r_v2->cc_state = pd[p->port].cc_state; + if (args->version == 1) + args->response_size = sizeof(*r_v1); + else + args->response_size = sizeof(*r_v2); + break; + default: + return EC_RES_INVALID_PARAM; } return EC_RES_SUCCESS; } DECLARE_HOST_COMMAND(EC_CMD_USB_PD_CONTROL, hc_usb_pd_control, - EC_VER_MASK(0) | EC_VER_MASK(1)); + EC_VER_MASK(0) | EC_VER_MASK(1) | EC_VER_MASK(2)); static int hc_remote_flash(struct host_cmd_handler_args *args) { diff --git a/include/ec_commands.h b/include/ec_commands.h index fb33d7179e..93dd9b8736 100644 --- a/include/ec_commands.h +++ b/include/ec_commands.h @@ -4756,6 +4756,22 @@ struct ec_response_usb_pd_control_v1 { char state[32]; } __ec_align1; +/* Values representing usbc PD CC state */ +#define USBC_PD_CC_NONE 0 /* No accessory connected */ +#define USBC_PD_CC_NO_UFP 1 /* No UFP accessory connected */ +#define USBC_PD_CC_AUDIO_ACC 2 /* Audio accessory connected */ +#define USBC_PD_CC_DEBUG_ACC 3 /* Debug accessory connected */ +#define USBC_PD_CC_UFP_ATTACHED 4 /* UFP attached to usbc */ +#define USBC_PD_CC_DFP_ATTACHED 5 /* DPF attached to usbc */ + +struct ec_response_usb_pd_control_v2 { + uint8_t enabled; + uint8_t role; + uint8_t polarity; + char state[32]; + uint8_t cc_state; /* USBC_PD_CC_*Encoded cc state */ +} __ec_align1; + #define EC_CMD_USB_PD_PORTS 0x0102 /* Maximum number of PD ports on a device, num_ports will be <= this */ diff --git a/util/ectool.c b/util/ectool.c index 36fd2be7b7..d86233e33b 100644 --- a/util/ectool.c +++ b/util/ectool.c @@ -5002,6 +5002,8 @@ int cmd_usb_pd(int argc, char *argv[]) const char *mux_str[] = {"", "none", "usb", "dp", "dock", "auto"}; const char *swap_str[] = {"", "dr_swap", "pr_swap", "vconn_swap"}; struct ec_params_usb_pd_control p; + struct ec_response_usb_pd_control_v2 *r_v2 = + (struct ec_response_usb_pd_control_v2 *)ec_inbuf; struct ec_response_usb_pd_control_v1 *r_v1 = (struct ec_response_usb_pd_control_v1 *)ec_inbuf; struct ec_response_usb_pd_control *r = @@ -5009,7 +5011,7 @@ int cmd_usb_pd(int argc, char *argv[]) int rv, i, j; int option_ok; char *e; - int cmdver = 1; + int cmdver = 2; BUILD_ASSERT(ARRAY_SIZE(role_str) == USB_PD_CTRL_ROLE_COUNT); BUILD_ASSERT(ARRAY_SIZE(mux_str) == USB_PD_CTRL_MUX_COUNT); @@ -5121,6 +5123,25 @@ int cmd_usb_pd(int argc, char *argv[]) (r_v1->role & PD_CTRL_RESP_ROLE_VCONN) ? " VCONN" : "", r_v1->polarity + 1); + if (cmdver == 2) { + printf("CC State: %d:", r_v2->cc_state); + if (r_v2->cc_state == USBC_PD_CC_NONE) + printf("None"); + else if (r_v2->cc_state == USBC_PD_CC_NO_UFP) + printf("No UFP"); + else if (r_v2->cc_state == USBC_PD_CC_AUDIO_ACC) + printf("Audio accessory"); + else if (r_v2->cc_state == USBC_PD_CC_DEBUG_ACC) + printf("Debug accessory"); + else if (r_v2->cc_state == USBC_PD_CC_UFP_ATTACHED) + printf("UFP attached"); + else if (r_v2->cc_state == USBC_PD_CC_DFP_ATTACHED) + printf("DFP attached"); + else + printf("UNKNOWN"); + printf("\n"); + } + /* If connected to a PD device, then print port partner info */ if ((r_v1->enabled & PD_CTRL_RESP_ENABLED_CONNECTED) && (r_v1->enabled & PD_CTRL_RESP_ENABLED_PD_CAPABLE)) |