@@ -101,8 +101,9 @@ int ucsi_write_tunnel(void)
101101 uint8_t * message_out = host_get_memmap (EC_CUSTOMIZED_MEMMAP_UCSI_MESSAGE_OUT );
102102 uint8_t * command = host_get_memmap (EC_CUSTOMIZED_MEMMAP_UCSI_COMMAND );
103103 uint8_t change_connector_indicator = 0 ;
104+ bool cmd_need_broadcast = false;
104105 int controller = 0 ;
105- int offset = 0 ;
106+ int connector_number_offset = 0 ;
106107 int rv = EC_SUCCESS ;
107108 int new_port = 0 ;
108109
@@ -120,59 +121,41 @@ int ucsi_write_tunnel(void)
120121 for (int i = 0 ; i < PD_CHIP_COUNT ; i ++ )
121122 pd_chip_ucsi_info [i ].read_tunnel_complete = 0 ;
122123
123- switch (* command ) {
124- case UCSI_CMD_GET_CONNECTOR_STATUS :
125- case UCSI_CMD_GET_CONNECTOR_CAPABILITY :
126- case UCSI_CMD_CONNECTOR_RESET :
127- case UCSI_CMD_SET_CCOM :
128- case UCSI_CMD_SET_UOR :
129- case UCSI_CMD_SET_PDR :
130- case UCSI_CMD_GET_CAM_SUPPORTED :
131- case UCSI_CMD_SET_NEW_CAM :
132- case UCSI_CMD_GET_PDOS :
133- case UCSI_CMD_GET_CABLE_PROPERTY :
134- case UCSI_CMD_GET_ALTERNATE_MODES :
135- case UCSI_CMD_GET_CURRENT_CAM :
136- case UCSI_CMD_GET_CAM_CS :
137- case UCSI_CMD_SET_POWER_LEVEL :
138- case UCSI_CMD_GET_PD_MESSAGE :
139- case UCSI_CMD_GET_ERROR_STATUS :
140- case UCSI_CMD_GET_ATTENTION_VDO :
141-
142- if (* command == UCSI_CMD_GET_ALTERNATE_MODES ) {
143- offset = 1 ;
144- }
145-
146- /**
147- * those command will control specific pd port,
148- * so we need to check the command connector number.
149- */
150- change_connector_indicator =
151- * host_get_memmap (EC_CUSTOMIZED_MEMMAP_UCSI_CTR_SPECIFIC + offset ) & 0x7f ;
152-
153- if (change_connector_indicator > PD_PORT_COUNT ||
154- change_connector_indicator == 0 ) {
155- /* Print the invalid port for debugging */
156- if (ucsi_debug_enable && change_connector_indicator > PD_PORT_COUNT )
157- CPRINTS ("UCSI write invalid type-c port:%d" ,
158- change_connector_indicator );
124+ /* The connector number offset is 24 bits in GET_ALTERNATE_MODES command */
125+ if (* command == UCSI_CMD_GET_ALTERNATE_MODES )
126+ connector_number_offset = 1 ;
127+
128+ change_connector_indicator =
129+ * host_get_memmap (EC_CUSTOMIZED_MEMMAP_UCSI_CTR_SPECIFIC +
130+ connector_number_offset ) & 0x7f ;
131+
132+ /* This command does not have a connector number field; it needs to broadcast. */
133+ if (* command == UCSI_CMD_SET_NOTIFICATION_ENABLE || * command == UCSI_CMD_ACK_CC_CI )
134+ change_connector_indicator = 0 ;
135+
136+ /* Print the invalid port for debugging */
137+ if (ucsi_debug_enable && change_connector_indicator > PD_PORT_COUNT )
138+ CPRINTS ("UCSI write invalid type-c port:%d" , change_connector_indicator );
139+ else {
140+ if (change_connector_indicator == 0 ) {
141+ /* The command should broadcast to all PD chips */
142+ cmd_need_broadcast = true;
159143 } else {
144+ /* Map the UCSI Port to the PD port */
160145 new_port =
161146 ucsi_pd_port_map [change_connector_indicator - 1 ].pd_controller_port ;
162147 if (new_port != change_connector_indicator ) {
163- * host_get_memmap (EC_CUSTOMIZED_MEMMAP_UCSI_CTR_SPECIFIC + offset ) =
164- (* host_get_memmap (EC_CUSTOMIZED_MEMMAP_UCSI_CTR_SPECIFIC + offset )
165- & 0x80 ) | new_port ;
148+ int connector_number = EC_CUSTOMIZED_MEMMAP_UCSI_CTR_SPECIFIC +
149+ connector_number_offset ;
150+ * host_get_memmap (connector_number ) =
151+ (* host_get_memmap (connector_number ) & 0x80 ) | new_port ;
166152 }
167153 controller = ucsi_pd_port_map [change_connector_indicator - 1 ].pd_controller ;
168154 }
155+ }
169156
170- pd_chip_ucsi_info [controller ].wait_ack = 1 ;
171- rv = cypd_write_reg_block (controller , ucsi_message_out_offset (), message_out , 16 );
172- rv = cypd_write_reg_block (controller , CCG_CONTROL_REG , command , 8 );
173- break ;
174- default :
175- for (int i = 0 ; i < PD_CHIP_COUNT ; i ++ ) {
157+ if (cmd_need_broadcast ) {
158+ for (int i = 0 ; i < PD_PORT_COUNT ; i ++ ) {
176159
177160 /**
178161 * If the controller does not needs to respond ACK,
@@ -197,19 +180,29 @@ int ucsi_write_tunnel(void)
197180 * ACK_CC_CI command is the end of the UCSI command,
198181 * does not need to wait ack.
199182 */
200- if (* command == UCSI_CMD_ACK_CC_CI )
183+ if (* command == UCSI_CMD_ACK_CC_CI || * command == UCSI_CMD_PPM_RESET )
201184 pd_chip_ucsi_info [i ].wait_ack = 0 ;
202185 else
203186 pd_chip_ucsi_info [i ].wait_ack = 1 ;
204187 }
205- break ;
188+ } else {
189+ rv = cypd_write_reg_block (controller , ucsi_message_out_offset (), message_out , 16 );
190+ rv = cypd_write_reg_block (controller , CCG_CONTROL_REG , command , 8 );
191+ pd_chip_ucsi_info [controller ].wait_ack = 1 ;
206192 }
207193
208194 if (ucsi_debug_enable ) {
209- CPRINTS ("UCSI Write P:%d Cmd 0x%016llx %s" ,
210- change_connector_indicator ,
211- * (uint64_t * )command ,
212- command_names (* command ));
195+ if (cmd_need_broadcast ) {
196+ CPRINTS ("UCSI Broadcast Cmd 0x%016llx %s" ,
197+ * (uint64_t * )command ,
198+ command_names (* command ));
199+ } else {
200+ CPRINTS ("UCSI Write Connector:%d Cmd 0x%016llx %s" ,
201+ change_connector_indicator ,
202+ * (uint64_t * )command ,
203+ command_names (* command ));
204+ }
205+
213206 if (command [1 ])
214207 cypd_print_buff ("UCSI Msg Out: " , message_out , 6 );
215208 }
@@ -427,14 +420,9 @@ int ucsi_read_tunnel(int controller)
427420
428421 break ;
429422 case UCSI_CMD_ACK_CC_CI :
430- if (ucsi_check_all_pd_status (OPERATOR_AND )) {
423+ if (ucsi_check_all_pd_status (OPERATOR_AND ))
431424 read_complete = 1 ;
432-
433- /* workaround for linux driver */
434- if ((pd_chip_ucsi_info [controller ].cci & CCI_ACKNOWLEDGE_FLAG ) !=
435- pd_chip_ucsi_info [controller ].cci )
436- pd_chip_ucsi_info [controller ].wait_ack = 1 ;
437- } else
425+ else
438426 read_complete = 0 ;
439427 break ;
440428 default :
@@ -490,6 +478,7 @@ void check_ucsi_event_from_host(void)
490478 void * message_in ;
491479 uint32_t * cci ;
492480 uint16_t * version = (uint16_t * )host_get_memmap (EC_CUSTOMIZED_MEMMAP_UCSI_VERSION );
481+ uint8_t command = * host_get_memmap (EC_CUSTOMIZED_MEMMAP_UCSI_COMMAND );
493482 int message_in_length ;
494483 int message_in_offset ;
495484 int i ;
@@ -530,12 +519,9 @@ void check_ucsi_event_from_host(void)
530519 }
531520
532521 if (read_complete ) {
533- if (ucsi_debug_enable ) {
534- CPRINTS ("%s Complete" ,
535- command_names (* host_get_memmap (EC_CUSTOMIZED_MEMMAP_UCSI_COMMAND )));
536- }
537522
538- for (i = 0 ; i < PD_CHIP_COUNT ; i ++ ) {
523+ /* The highest priority of the PD chip is pd 0 */
524+ for (i = (PD_PORT_COUNT - 1 ); i >= 0 ; i -- ) {
539525 if (pd_chip_ucsi_info [i ].read_tunnel_complete ) {
540526 message_in = pd_chip_ucsi_info [i ].message_in ;
541527 cci = & pd_chip_ucsi_info [i ].cci ;
@@ -551,17 +537,27 @@ void check_ucsi_event_from_host(void)
551537 * both controllers
552538 */
553539 if (ucsi_check_all_pd_status (OPERATOR_AND )) {
554- for (i = 0 ; i < PD_CHIP_COUNT ; i ++ ) {
555- if (pd_chip_ucsi_info [i ].cci & 0xFE ) {
556- message_in = pd_chip_ucsi_info [i ].message_in ;
557- cci = & pd_chip_ucsi_info [i ].cci ;
558- break ;
540+ for (i = 0 ; i < PD_PORT_COUNT ; i ++ ) {
541+ if (command == UCSI_CMD_GET_ERROR_STATUS ) {
542+ uint16_t error_information =
543+ (pd_chip_ucsi_info [i ].message_in [1 ] << 8 ) |
544+ pd_chip_ucsi_info [i ].message_in [1 ];
545+ if (error_information ) {
546+ message_in = pd_chip_ucsi_info [i ].message_in ;
547+ cci = & pd_chip_ucsi_info [i ].cci ;
548+ }
549+ } else {
550+ /* This will cause rear typec port fail */
551+ if (pd_chip_ucsi_info [i ].cci & 0xFE ) {
552+ message_in = pd_chip_ucsi_info [i ].message_in ;
553+ cci = & pd_chip_ucsi_info [i ].cci ;
554+ break ;
555+ }
559556 }
560557 }
561558 }
562559
563- if (* host_get_memmap (EC_CUSTOMIZED_MEMMAP_UCSI_COMMAND ) ==
564- UCSI_CMD_GET_CONNECTOR_STATUS &&
560+ if (command == UCSI_CMD_GET_CONNECTOR_STATUS &&
565561 (((uint8_t * )message_in )[8 ] & 0x03 ) > 1 ) {
566562 CPRINTS ("Overriding Slow charger status" );
567563 /* Override not charging value with nominal charging */
@@ -580,12 +576,8 @@ void check_ucsi_event_from_host(void)
580576 memcpy (host_get_memmap (message_in_offset ), message_in , message_in_length );
581577 memcpy (host_get_memmap (EC_CUSTOMIZED_MEMMAP_UCSI_CONN_CHANGE ), cci , 4 );
582578
583- /**
584- * TODO: process the two pd results for one response.
585- */
586-
587579 /* override bNumConnectors to the total number of connectors on the system */
588- if (* host_get_memmap ( EC_CUSTOMIZED_MEMMAP_UCSI_COMMAND ) == UCSI_CMD_GET_CAPABILITY )
580+ if (command == UCSI_CMD_GET_CAPABILITY )
589581 * host_get_memmap (message_in_offset + 4 ) = PD_PORT_COUNT ;
590582
591583 for (i = 0 ; i < PD_CHIP_COUNT ; i ++ )
@@ -596,6 +588,28 @@ void check_ucsi_event_from_host(void)
596588 if (!(* host_get_memmap (EC_CUSTOMIZED_MEMMAP_SYSTEM_FLAGS ) & UCSI_EVENT ))
597589 * host_get_memmap (EC_CUSTOMIZED_MEMMAP_UCSI_COMMAND ) = 0 ;
598590 }
591+
592+ if (ucsi_debug_enable ) {
593+ CPRINTS ("%s Complete" , command_names (command ));
594+
595+ CPRINTS ("CCI (Host): 0x%08x Port%d, %s%s%s%s%s%s%s" ,
596+ * cci ,
597+ (* cci >> 1 ) & 0x07F ,
598+ * cci & CCI_NOT_SUPPORTED_FLAG ? "Not Support " : "" ,
599+ * cci & CCI_CANCELED_FLAG ? "Canceled " : "" ,
600+ * cci & CCI_RESET_FLAG ? "Reset " : "" ,
601+ * cci & CCI_BUSY_FLAG ? "Busy " : "" ,
602+ * cci & CCI_ACKNOWLEDGE_FLAG ? "Acknowledge " : "" ,
603+ * cci & CCI_ERROR_FLAG ? "Error " : "" ,
604+ * cci & CCI_COMPLETE_FLAG ? "Complete " : ""
605+ );
606+ if (* cci & 0xFF00 ) {
607+ cypd_print_buff ("Message In (Host) " ,
608+ message_in ,
609+ message_in_length );
610+ }
611+ }
612+
599613 host_set_single_event (EC_HOST_EVENT_UCSI );
600614 }
601615}
0 commit comments