@@ -67,6 +67,18 @@ static int tcpci_write16(struct tcpci *tcpci, unsigned int reg, u16 val)
67
67
return regmap_raw_write (tcpci -> regmap , reg , & val , sizeof (u16 ));
68
68
}
69
69
70
+ static bool tcpci_check_std_output_cap (struct regmap * regmap , u8 mask )
71
+ {
72
+ unsigned int reg ;
73
+ int ret ;
74
+
75
+ ret = regmap_read (regmap , TCPC_STD_OUTPUT_CAP , & reg );
76
+ if (ret < 0 )
77
+ return ret ;
78
+
79
+ return (reg & mask ) == mask ;
80
+ }
81
+
70
82
static int tcpci_set_cc (struct tcpc_dev * tcpc , enum typec_cc_status cc )
71
83
{
72
84
struct tcpci * tcpci = tcpc_to_tcpci (tcpc );
@@ -301,6 +313,28 @@ static int tcpci_set_polarity(struct tcpc_dev *tcpc,
301
313
TCPC_TCPC_CTRL_ORIENTATION : 0 );
302
314
}
303
315
316
+ static int tcpci_set_orientation (struct tcpc_dev * tcpc ,
317
+ enum typec_orientation orientation )
318
+ {
319
+ struct tcpci * tcpci = tcpc_to_tcpci (tcpc );
320
+ unsigned int reg ;
321
+
322
+ switch (orientation ) {
323
+ case TYPEC_ORIENTATION_NONE :
324
+ /* We can't put a single output into high impedance */
325
+ fallthrough ;
326
+ case TYPEC_ORIENTATION_NORMAL :
327
+ reg = TCPC_CONFIG_STD_OUTPUT_ORIENTATION_NORMAL ;
328
+ break ;
329
+ case TYPEC_ORIENTATION_REVERSE :
330
+ reg = TCPC_CONFIG_STD_OUTPUT_ORIENTATION_FLIPPED ;
331
+ break ;
332
+ }
333
+
334
+ return regmap_update_bits (tcpci -> regmap , TCPC_CONFIG_STD_OUTPUT ,
335
+ TCPC_CONFIG_STD_OUTPUT_ORIENTATION_MASK , reg );
336
+ }
337
+
304
338
static void tcpci_set_partner_usb_comm_capable (struct tcpc_dev * tcpc , bool capable )
305
339
{
306
340
struct tcpci * tcpci = tcpc_to_tcpci (tcpc );
@@ -830,6 +864,9 @@ struct tcpci *tcpci_register_port(struct device *dev, struct tcpci_data *data)
830
864
if (tcpci -> data -> vbus_vsafe0v )
831
865
tcpci -> tcpc .is_vbus_vsafe0v = tcpci_is_vbus_vsafe0v ;
832
866
867
+ if (tcpci -> data -> set_orientation )
868
+ tcpci -> tcpc .set_orientation = tcpci_set_orientation ;
869
+
833
870
err = tcpci_parse_config (tcpci );
834
871
if (err < 0 )
835
872
return ERR_PTR (err );
@@ -873,6 +910,13 @@ static int tcpci_probe(struct i2c_client *client)
873
910
if (err < 0 )
874
911
return err ;
875
912
913
+ err = tcpci_check_std_output_cap (chip -> data .regmap ,
914
+ TCPC_STD_OUTPUT_CAP_ORIENTATION );
915
+ if (err < 0 )
916
+ return err ;
917
+
918
+ chip -> data .set_orientation = err ;
919
+
876
920
chip -> tcpci = tcpci_register_port (& client -> dev , & chip -> data );
877
921
if (IS_ERR (chip -> tcpci ))
878
922
return PTR_ERR (chip -> tcpci );
0 commit comments