Skip to content

Commit 62720a3

Browse files
Josh-Tsaiquinchou77
authored andcommitted
fwk: ucsi: support ucsi version 2.0
ucsi2.0 increase the data sizes and commands, this change add those commands in the EC code to support it BRANCH=fwk-main BUG=https://app.clickup.com/t/86equ4vr1 TEST=UCSI driver does not show the YB in the device manager (v1.1) Signed-off-by: Josh Tsai <Josh_Tsai@compal.com> (cherry picked from commit 419a868)
1 parent d439158 commit 62720a3

4 files changed

Lines changed: 65 additions & 31 deletions

File tree

zephyr/program/framework/include/customized_shared_memory.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,9 @@
6565
#define EC_CUSTOMIZED_MEMMAP_UCSI_COMMAND 0x118
6666
#define EC_CUSTOMIZED_MEMMAP_UCSI_CTR_DATA_LEN 0x119
6767
#define EC_CUSTOMIZED_MEMMAP_UCSI_CTR_SPECIFIC 0x11A
68-
#define EC_CUSTOMIZED_MEMMAP_UCSI_MESSAGE_IN 0x120
68+
#define EC_CUSTOMIZED_MEMMAP_UCSI_MESSAGE_IN_V1 0x120
6969
#define EC_CUSTOMIZED_MEMMAP_UCSI_MESSAGE_OUT 0x130
70+
#define EC_CUSTOMIZED_MEMMAP_UCSI_MESSAGE_IN_V2 0x171
7071

7172

7273
#define EC_CUSTOMIZED_MEMMAP_SERIAL_STRCUT_INFO 0x140

zephyr/program/framework/include/cypress_pd_common.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -537,8 +537,9 @@ struct pd_chip_ucsi_info_t {
537537
uint8_t data_len;
538538
uint8_t data[6];
539539
} control;
540-
uint8_t message_in[16];
540+
uint8_t message_in[34];
541541
uint8_t message_out[16];
542+
int message_in_length;
542543
int read_tunnel_complete;
543544
int write_tunnel_complete;
544545
int wait_ack;

zephyr/program/framework/include/ucsi.h

Lines changed: 38 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -20,29 +20,44 @@ enum ucsi_control {
2020
CYPD_UCSI_SIGNAL_CONNECT_EVENT_TO_OS = 0x04
2121
};
2222

23-
enum ucsi_command {
24-
UCSI_CMD_RESERVE,
25-
UCSI_CMD_PPM_RESET,
26-
UCSI_CMD_CANCEL,
27-
UCSI_CMD_CONNECTOR_RESET,
28-
UCSI_CMD_ACK_CC_CI,
29-
UCSI_CMD_SET_NOTIFICATION_ENABLE,
30-
UCSI_CMD_GET_CAPABILITY,
31-
UCSI_CMD_GET_CONNECTOR_CAPABILITY,
32-
UCSI_CMD_SET_UOM,
33-
UCSI_CMD_SET_UOR,
34-
UCSI_CMD_SET_PDM,
35-
UCSI_CMD_SET_PDR,
36-
UCSI_CMD_GET_ALTERNATE_MODES,
37-
UCSI_CMD_GET_CAM_SUPPORTED,
38-
UCSI_CMD_GET_CURRENT_CAM,
39-
UCSI_CMD_SET_NEW_CAM,
40-
UCSI_CMD_GET_PDOS,
41-
UCSI_CMD_GET_CABLE_PROPERTY,
42-
UCSI_CMD_GET_CONNECTOR_STATUS,
43-
UCSI_CMD_GET_ERROR_STATUS,
44-
UCSI_CMD_SET_POWER_LEVEL,
45-
UCSI_CMD_GET_PD_MESSAGE
23+
enum ucsi_commands {
24+
/* UCSI 1.x */
25+
UCSI_CMD_RESERVED = 0,
26+
UCSI_CMD_PPM_RESET = 0x01,
27+
UCSI_CMD_CANCEL = 0x02,
28+
UCSI_CMD_CONNECTOR_RESET = 0x03,
29+
UCSI_CMD_ACK_CC_CI = 0x04,
30+
UCSI_CMD_SET_NOTIFICATION_ENABLE = 0x05,
31+
UCSI_CMD_GET_CAPABILITY = 0x06,
32+
UCSI_CMD_GET_CONNECTOR_CAPABILITY = 0x07,
33+
UCSI_CMD_SET_CCOM = 0x08,
34+
UCSI_CMD_SET_UOR = 0x09,
35+
obsolete_UCSI_CMD_SET_PDM = 0x0A,
36+
UCSI_CMD_SET_PDR = 0x0B,
37+
UCSI_CMD_GET_ALTERNATE_MODES = 0x0C,
38+
UCSI_CMD_GET_CAM_SUPPORTED = 0x0D,
39+
UCSI_CMD_GET_CURRENT_CAM = 0x0E,
40+
UCSI_CMD_SET_NEW_CAM = 0x0F,
41+
UCSI_CMD_GET_PDOS = 0x10,
42+
UCSI_CMD_GET_CABLE_PROPERTY = 0x11,
43+
UCSI_CMD_GET_CONNECTOR_STATUS = 0x12,
44+
UCSI_CMD_GET_ERROR_STATUS = 0x13,
45+
UCSI_CMD_SET_POWER_LEVEL = 0x14,
46+
UCSI_CMD_GET_PD_MESSAGE = 0x15,
47+
/* UCSI 2.x */
48+
UCSI_CMD_GET_ATTENTION_VDO = 0x16,
49+
UCSI_CMD_reserved_0x17 = 0x17,
50+
UCSI_CMD_GET_CAM_CS = 0x18,
51+
UCSI_CMD_LPM_FW_UPDATE_REQUEST = 0x19,
52+
UCSI_CMD_SECURITY_REQUEST = 0x1A,
53+
UCSI_CMD_SET_RETIMER_MODE = 0x1B,
54+
UCSI_CMD_SET_SINK_PATH = 0x1C,
55+
/* UCSI 3.x */
56+
UCSI_CMD_SET_PDOS = 0x1D,
57+
UCSI_CMD_READ_POWER_LEVEL = 0x1E,
58+
UCSI_CMD_CHUNKING_SUPPORT = 0x1F,
59+
UCSI_CMD_VENDOR_CMD = 0x20,
60+
UCSI_CMD_MAX,
4661
};
4762

4863
/**

zephyr/program/framework/src/ucsi.c

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ int ucsi_write_tunnel(void)
108108
case UCSI_CMD_GET_CONNECTOR_STATUS:
109109
case UCSI_CMD_GET_CONNECTOR_CAPABILITY:
110110
case UCSI_CMD_CONNECTOR_RESET:
111-
case UCSI_CMD_SET_UOM:
111+
case UCSI_CMD_SET_CCOM:
112112
case UCSI_CMD_SET_UOR:
113113
case UCSI_CMD_SET_PDR:
114114
case UCSI_CMD_GET_CAM_SUPPORTED:
@@ -117,9 +117,11 @@ int ucsi_write_tunnel(void)
117117
case UCSI_CMD_GET_CABLE_PROPERTY:
118118
case UCSI_CMD_GET_ALTERNATE_MODES:
119119
case UCSI_CMD_GET_CURRENT_CAM:
120+
case UCSI_CMD_GET_CAM_CS:
120121
case UCSI_CMD_SET_POWER_LEVEL:
121122
case UCSI_CMD_GET_PD_MESSAGE:
122123
case UCSI_CMD_GET_ERROR_STATUS:
124+
case UCSI_CMD_GET_ATTENTION_VDO:
123125

124126
if (*command == UCSI_CMD_GET_ALTERNATE_MODES) {
125127
offset = 1;
@@ -303,6 +305,8 @@ static int ucsi_check_all_pd_status(int operator)
303305
int ucsi_read_tunnel(int controller)
304306
{
305307
int rv, port_indicator;
308+
int message_in_max_length;
309+
uint16_t *version = (uint16_t *)host_get_memmap(EC_CUSTOMIZED_MEMMAP_UCSI_VERSION);
306310

307311
if (ucsi_debug_enable && pd_chip_ucsi_info[controller].read_tunnel_complete == 1 &&
308312
(pd_chip_ucsi_info[controller].cci & CCI_BUSY_FLAG) == 0) {
@@ -325,15 +329,17 @@ int ucsi_read_tunnel(int controller)
325329
| (pd_ucsi_port_map[controller*2+port_indicator-1] << 1);
326330
}
327331

332+
message_in_max_length = (*version < 0x0200) ? 16 : 34;
333+
328334
/* If data length is non zero, then get data */
329335
if (pd_chip_ucsi_info[controller].cci & 0xFF00) {
330336
rv = cypd_read_reg_block(controller, CCG_MESSAGE_IN_REG,
331-
pd_chip_ucsi_info[controller].message_in, 16);
337+
pd_chip_ucsi_info[controller].message_in, message_in_max_length);
332338

333339
if (rv != EC_SUCCESS)
334340
CPRINTS("MESSAGE_IN_REG failed");
335341
} else {
336-
memset(pd_chip_ucsi_info[controller].message_in, 0, 16);
342+
memset(pd_chip_ucsi_info[controller].message_in, 0, message_in_max_length);
337343
}
338344

339345
if (ucsi_debug_enable) {
@@ -352,7 +358,8 @@ int ucsi_read_tunnel(int controller)
352358
cci_reg & CCI_COMPLETE_FLAG ? "Complete " : ""
353359
);
354360
if (cci_reg & 0xFF00) {
355-
cypd_print_buff("Message ", pd_chip_ucsi_info[controller].message_in, 16);
361+
cypd_print_buff("Message ", pd_chip_ucsi_info[controller].message_in,
362+
message_in_max_length);
356363
}
357364
}
358365

@@ -457,6 +464,9 @@ void check_ucsi_event_from_host(void)
457464
{
458465
void *message_in;
459466
uint32_t *cci;
467+
uint16_t *version = (uint16_t *)host_get_memmap(EC_CUSTOMIZED_MEMMAP_UCSI_VERSION);
468+
int message_in_length;
469+
int message_in_offset;
460470
int i;
461471
int rv;
462472

@@ -534,8 +544,15 @@ void check_ucsi_event_from_host(void)
534544
}
535545

536546
crec_msleep(2);
547+
if (*version < 0x0200) {
548+
message_in_offset = EC_CUSTOMIZED_MEMMAP_UCSI_MESSAGE_IN_V1;
549+
message_in_length = 16;
550+
} else {
551+
message_in_offset = EC_CUSTOMIZED_MEMMAP_UCSI_MESSAGE_IN_V2;
552+
message_in_length = 34;
553+
}
537554

538-
memcpy(host_get_memmap(EC_CUSTOMIZED_MEMMAP_UCSI_MESSAGE_IN), message_in, 16);
555+
memcpy(host_get_memmap(message_in_offset), message_in, message_in_length);
539556
memcpy(host_get_memmap(EC_CUSTOMIZED_MEMMAP_UCSI_CONN_CHANGE), cci, 4);
540557

541558
/**
@@ -544,7 +561,7 @@ void check_ucsi_event_from_host(void)
544561

545562
/* override bNumConnectors to the total number of connectors on the system */
546563
if (*host_get_memmap(EC_CUSTOMIZED_MEMMAP_UCSI_COMMAND) == UCSI_CMD_GET_CAPABILITY)
547-
*host_get_memmap(EC_CUSTOMIZED_MEMMAP_UCSI_MESSAGE_IN + 4) = PD_PORT_COUNT;
564+
*host_get_memmap(message_in_offset + 4) = PD_PORT_COUNT;
548565

549566
for (i = 0; i < PD_CHIP_COUNT; i++)
550567
pd_chip_ucsi_info[i].read_tunnel_complete = 0;

0 commit comments

Comments
 (0)