Skip to content

Commit 73bccbf

Browse files
Josh-Tsaiquinchou77
authored andcommitted
fwk: modified the UCSI code to support one PD chip
Remove the hard code and use the for-loop to check the pd read tunnel status. BRANCH=fwk-main BUG=None TEST=UCSI is workable on the Marigold unit TEST=UCSI driver does not display the yellow bang TEST=After resuming from sleep, the pending event will be processed Signed-off-by: Josh-Tsai <josh_tsai@compal.com> (cherry picked from commit cb40672)
1 parent 438eb72 commit 73bccbf

2 files changed

Lines changed: 58 additions & 26 deletions

File tree

zephyr/program/framework/include/cypress_pd_common.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -632,6 +632,7 @@ struct pd_battery_status_t {
632632
*/
633633
extern struct pd_chip_config_t pd_chip_config[];
634634
extern struct pd_port_current_state_t pd_port_states[];
635+
extern struct pd_chip_ucsi_info_t pd_chip_ucsi_info[];
635636

636637
/**
637638
* cypress i2c write functions

zephyr/program/framework/src/ucsi.c

Lines changed: 57 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
#define CCI_ERROR_FLAG BIT(30)
3333
#define CCI_COMPLETE_FLAG BIT(31)
3434

35-
static struct pd_chip_ucsi_info_t pd_chip_ucsi_info[] = {
35+
struct pd_chip_ucsi_info_t pd_chip_ucsi_info[] = {
3636
[PD_CHIP_0] = {
3737

3838
},
@@ -109,8 +109,8 @@ int ucsi_write_tunnel(void)
109109
CPRINTS("UCSI PPM_RESET");
110110
}
111111

112-
pd_chip_ucsi_info[0].read_tunnel_complete = 0;
113-
pd_chip_ucsi_info[1].read_tunnel_complete = 0;
112+
for (i = 0; i < PD_CHIP_COUNT; i++)
113+
pd_chip_ucsi_info[i].read_tunnel_complete = 0;
114114

115115
switch (*command) {
116116
case UCSI_CMD_GET_CONNECTOR_STATUS:
@@ -207,6 +207,8 @@ void record_ucsi_connector_change_event(int controller, int port)
207207
{
208208
int cci_port = (controller << 1) + port + 1;
209209

210+
__ASSERT(controller < PD_CHIP_COUNT, "Invalid PD chip controller id in %s.", __func__);
211+
210212
if (!chipset_in_state(CHIPSET_STATE_ON) && !chipset_in_state(CHIPSET_STATE_ANY_OFF))
211213
s0ix_connector_change_indicator |= BIT(cci_port);
212214
}
@@ -271,6 +273,41 @@ static void resend_ucsi_connector_change_event(void)
271273
}
272274
DECLARE_HOOK(HOOK_CHIPSET_RESUME, resend_ucsi_connector_change_event, HOOK_PRIO_DEFAULT);
273275

276+
#define OPERATOR_AND 1
277+
#define OPERATOR_OR 0
278+
279+
static int ucsi_check_all_pd_status(int operator)
280+
{
281+
int controller;
282+
283+
/* or operator = 0; and operator = 1 */
284+
if (operator) {
285+
for (controller = 0; controller < PD_CHIP_COUNT; controller++) {
286+
/**
287+
* In the and operator condition,
288+
* if one pd chip does not complete the read tunnel, return false
289+
*/
290+
if (!pd_chip_ucsi_info[controller].read_tunnel_complete)
291+
return false;
292+
}
293+
294+
/* If all pd chips have completed the read tunnel, return true */
295+
return true;
296+
}
297+
298+
for (controller = 0; controller < PD_CHIP_COUNT; controller++) {
299+
/**
300+
* In the or operator condition,
301+
* if one pd chip has completed the read tunnel, return true
302+
*/
303+
if (!pd_chip_ucsi_info[controller].read_tunnel_complete)
304+
return true;
305+
}
306+
307+
/* If all pd chips have not completed the read tunnel, return false */
308+
return false;
309+
}
310+
274311
int ucsi_read_tunnel(int controller)
275312
{
276313
int rv;
@@ -350,8 +387,7 @@ int ucsi_read_tunnel(int controller)
350387
case UCSI_CMD_SET_NOTIFICATION_ENABLE:
351388
case UCSI_CMD_GET_CAPABILITY:
352389
/* Those command need to wait two pd chip to response completed */
353-
if (pd_chip_ucsi_info[0].read_tunnel_complete &&
354-
pd_chip_ucsi_info[1].read_tunnel_complete)
390+
if (ucsi_check_all_pd_status(OPERATOR_AND))
355391
read_complete = 1;
356392
else
357393
read_complete = 0;
@@ -365,8 +401,7 @@ int ucsi_read_tunnel(int controller)
365401

366402
break;
367403
case UCSI_CMD_ACK_CC_CI:
368-
if (pd_chip_ucsi_info[0].read_tunnel_complete &&
369-
pd_chip_ucsi_info[1].read_tunnel_complete) {
404+
if (ucsi_check_all_pd_status(OPERATOR_AND)) {
370405
read_complete = 1;
371406

372407
/* workaround for linux driver */
@@ -377,8 +412,7 @@ int ucsi_read_tunnel(int controller)
377412
read_complete = 0;
378413
break;
379414
default:
380-
if (pd_chip_ucsi_info[0].read_tunnel_complete ||
381-
pd_chip_ucsi_info[1].read_tunnel_complete)
415+
if (ucsi_check_all_pd_status(OPERATOR_OR))
382416
read_complete = 1;
383417
else
384418
read_complete = 0;
@@ -471,14 +505,12 @@ void check_ucsi_event_from_host(void)
471505
CPRINTS("%s Complete",
472506
command_names(*host_get_memmap(EC_CUSTOMIZED_MEMMAP_UCSI_COMMAND)));
473507
}
474-
if (pd_chip_ucsi_info[0].read_tunnel_complete) {
475-
message_in = pd_chip_ucsi_info[0].message_in;
476-
cci = &pd_chip_ucsi_info[0].cci;
477-
}
478508

479-
if (pd_chip_ucsi_info[1].read_tunnel_complete) {
480-
message_in = pd_chip_ucsi_info[1].message_in;
481-
cci = &pd_chip_ucsi_info[1].cci;
509+
for (i = 0; i < PD_CHIP_COUNT; i++) {
510+
if (pd_chip_ucsi_info[i].read_tunnel_complete) {
511+
message_in = pd_chip_ucsi_info[i].message_in;
512+
cci = &pd_chip_ucsi_info[i].cci;
513+
}
482514
}
483515
read_complete = false;
484516

@@ -489,14 +521,13 @@ void check_ucsi_event_from_host(void)
489521
* so choose this response as a priority when we get an ack from
490522
* both controllers
491523
*/
492-
if (pd_chip_ucsi_info[1].read_tunnel_complete &&
493-
pd_chip_ucsi_info[0].read_tunnel_complete) {
494-
if (pd_chip_ucsi_info[0].cci & 0xFE) {
495-
message_in = pd_chip_ucsi_info[0].message_in;
496-
cci = &pd_chip_ucsi_info[0].cci;
497-
} else if (pd_chip_ucsi_info[1].cci & 0xFE) {
498-
message_in = pd_chip_ucsi_info[1].message_in;
499-
cci = &pd_chip_ucsi_info[1].cci;
524+
if (ucsi_check_all_pd_status(OPERATOR_AND)) {
525+
for (i = 0; i < PD_CHIP_COUNT; i++) {
526+
if (pd_chip_ucsi_info[i].cci & 0xFE) {
527+
message_in = pd_chip_ucsi_info[i].message_in;
528+
cci = &pd_chip_ucsi_info[i].cci;
529+
break;
530+
}
500531
}
501532
}
502533

@@ -521,8 +552,8 @@ void check_ucsi_event_from_host(void)
521552
if (*host_get_memmap(EC_CUSTOMIZED_MEMMAP_UCSI_COMMAND) == UCSI_CMD_GET_CAPABILITY)
522553
*host_get_memmap(EC_CUSTOMIZED_MEMMAP_UCSI_MESSAGE_IN + 4) = PD_PORT_COUNT;
523554

524-
pd_chip_ucsi_info[0].read_tunnel_complete = 0;
525-
pd_chip_ucsi_info[1].read_tunnel_complete = 0;
555+
for (i = 0; i < PD_CHIP_COUNT; i++)
556+
pd_chip_ucsi_info[i].read_tunnel_complete = 0;
526557

527558
/* clear the UCSI command if busy flag is not set */
528559
if (0 == (*cci & CCI_BUSY_FLAG)) {

0 commit comments

Comments
 (0)