3535static int ucsi_debug_enable ;
3636static uint8_t s0ix_connector_change_indicator ;
3737static bool read_complete ;
38+ static int pd_ucsi_port_map [PD_PORT_COUNT ];
3839
3940void ucsi_set_debug (bool enable )
4041{
@@ -85,7 +86,7 @@ int ucsi_write_tunnel(void)
8586 uint8_t * message_out = host_get_memmap (EC_CUSTOMIZED_MEMMAP_UCSI_MESSAGE_OUT );
8687 uint8_t * command = host_get_memmap (EC_CUSTOMIZED_MEMMAP_UCSI_COMMAND );
8788 uint8_t change_connector_indicator = 0 ;
88- int i ;
89+ int controller ;
8990 int offset = 0 ;
9091 int rv = EC_SUCCESS ;
9192
@@ -100,7 +101,7 @@ int ucsi_write_tunnel(void)
100101 CPRINTS ("UCSI PPM_RESET" );
101102 }
102103
103- for (i = 0 ; i < PD_CHIP_COUNT ; i ++ )
104+ for (int i = 0 ; i < PD_CHIP_COUNT ; i ++ )
104105 pd_chip_ucsi_info [i ].read_tunnel_complete = 0 ;
105106
106107 switch (* command ) {
@@ -131,24 +132,19 @@ int ucsi_write_tunnel(void)
131132 change_connector_indicator =
132133 * host_get_memmap (EC_CUSTOMIZED_MEMMAP_UCSI_CTR_SPECIFIC + offset ) & 0x7f ;
133134
134- if (change_connector_indicator > 0x02 ) {
135- /*
136- * Port 3 (b011) should be controller 1 UCSI port 1
137- * Port 4 (b100) should be controller 1 UCSI port 2
138- */
135+ if (change_connector_indicator > 0 && change_connector_indicator !=
136+ ucsi_pd_port_map [change_connector_indicator - 1 ].pd_controller_port ) {
139137 * host_get_memmap (EC_CUSTOMIZED_MEMMAP_UCSI_CTR_SPECIFIC + offset ) =
140- ((* host_get_memmap (EC_CUSTOMIZED_MEMMAP_UCSI_CTR_SPECIFIC + offset )
141- & 0x80 ) | (change_connector_indicator >> 1 ));
142- i = 1 ;
143- } else
144- i = 0 ;
138+ ucsi_pd_port_map [change_connector_indicator - 1 ].pd_controller_port ;
139+ }
140+ controller = ucsi_pd_port_map [change_connector_indicator - 1 ].pd_controller ;
145141
146- pd_chip_ucsi_info [i ].wait_ack = 1 ;
147- rv = cypd_write_reg_block (i , CCG_MESSAGE_OUT_REG , message_out , 16 );
148- rv = cypd_write_reg_block (i , CCG_CONTROL_REG , command , 8 );
142+ pd_chip_ucsi_info [controller ].wait_ack = 1 ;
143+ rv = cypd_write_reg_block (controller , CCG_MESSAGE_OUT_REG , message_out , 16 );
144+ rv = cypd_write_reg_block (controller , CCG_CONTROL_REG , command , 8 );
149145 break ;
150146 default :
151- for (i = 0 ; i < PD_CHIP_COUNT ; i ++ ) {
147+ for (int i = 0 ; i < PD_CHIP_COUNT ; i ++ ) {
152148
153149 /**
154150 * If the controller does not needs to respond ACK,
@@ -314,13 +310,11 @@ int ucsi_read_tunnel(int controller)
314310 if (rv != EC_SUCCESS )
315311 CPRINTS ("CCI_REG failed" );
316312 /* we need to offset the pd connector number to correct number */
317- if (controller == 1 && (pd_chip_ucsi_info [controller ].cci & 0xFE ))
318- /*
319- * Port 3 (b011) should be controller 1 UCSI port 1 (b001)
320- * Port 4 (b100) should be controller 1 UCSI port 2 (b010)
321- * CCI connector change indicate offset bit 1, so need to add 0x04 (0x2 << 1)
322- */
323- pd_chip_ucsi_info [controller ].cci += 0x04 ;
313+ if (pd_chip_ucsi_info [controller ].cci & 0xFE ) {
314+ pd_chip_ucsi_info [controller ].cci = (pd_chip_ucsi_info [controller ].cci & 0xFFFFFF01 )
315+ | (pd_ucsi_port_map [controller * 2 + ((pd_chip_ucsi_info [controller ].cci & 0xFE )>>1 )- 1 ]
316+ << 1 );
317+ }
324318
325319 /* If data length is non zero, then get data */
326320 if (pd_chip_ucsi_info [controller ].cci & 0xFF00 ) {
@@ -554,3 +548,19 @@ void check_ucsi_event_from_host(void)
554548 host_set_single_event (EC_HOST_EVENT_UCSI );
555549 }
556550}
551+
552+ /**
553+ * Map the UCSI port to the PD port, so that we can use the PD port_id
554+ * to find the UCSI port number
555+ */
556+ static void ucsi_pd_port_mapping (void )
557+ {
558+ int port_idx ;
559+
560+ for (int i = 0 ; i < PD_PORT_COUNT ; i ++ ) {
561+ port_idx = (ucsi_pd_port_map [i ].pd_controller * 2 ) +
562+ ucsi_pd_port_map [i ].pd_controller_port ;
563+ pd_ucsi_port_map [port_idx - 1 ] = i + 1 ;
564+ }
565+ }
566+ DECLARE_HOOK (HOOK_INIT , ucsi_pd_port_mapping , HOOK_PRIO_DEFAULT );
0 commit comments