Skip to content

Commit 62ce9ef

Browse files
Marco Felschgregkh
authored andcommitted
usb: typec: tcpci: add support to set connector orientation
This add the support to set the optional connector orientation bit which is part of the optional CONFIG_STANDARD_OUTPUT register 0x18 [1]. This allows system designers to connect the tcpc orientation pin directly to the 2:1 ss-mux. [1] https://www.usb.org/sites/default/files/documents/usb-port_controller_specification_rev2.0_v1.0_0.pdf Signed-off-by: Marco Felsch <[email protected]> Reviewed-by: Heikki Krogerus <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 89b5a5a commit 62ce9ef

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed

drivers/usb/typec/tcpm/tcpci.c

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,18 @@ static int tcpci_write16(struct tcpci *tcpci, unsigned int reg, u16 val)
6767
return regmap_raw_write(tcpci->regmap, reg, &val, sizeof(u16));
6868
}
6969

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+
7082
static int tcpci_set_cc(struct tcpc_dev *tcpc, enum typec_cc_status cc)
7183
{
7284
struct tcpci *tcpci = tcpc_to_tcpci(tcpc);
@@ -301,6 +313,28 @@ static int tcpci_set_polarity(struct tcpc_dev *tcpc,
301313
TCPC_TCPC_CTRL_ORIENTATION : 0);
302314
}
303315

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+
304338
static void tcpci_set_partner_usb_comm_capable(struct tcpc_dev *tcpc, bool capable)
305339
{
306340
struct tcpci *tcpci = tcpc_to_tcpci(tcpc);
@@ -830,6 +864,9 @@ struct tcpci *tcpci_register_port(struct device *dev, struct tcpci_data *data)
830864
if (tcpci->data->vbus_vsafe0v)
831865
tcpci->tcpc.is_vbus_vsafe0v = tcpci_is_vbus_vsafe0v;
832866

867+
if (tcpci->data->set_orientation)
868+
tcpci->tcpc.set_orientation = tcpci_set_orientation;
869+
833870
err = tcpci_parse_config(tcpci);
834871
if (err < 0)
835872
return ERR_PTR(err);
@@ -873,6 +910,13 @@ static int tcpci_probe(struct i2c_client *client)
873910
if (err < 0)
874911
return err;
875912

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+
876920
chip->tcpci = tcpci_register_port(&client->dev, &chip->data);
877921
if (IS_ERR(chip->tcpci))
878922
return PTR_ERR(chip->tcpci);

include/linux/usb/tcpci.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@
4747
#define TCPC_SINK_FAST_ROLE_SWAP BIT(0)
4848

4949
#define TCPC_CONFIG_STD_OUTPUT 0x18
50+
#define TCPC_CONFIG_STD_OUTPUT_ORIENTATION_MASK BIT(0)
51+
#define TCPC_CONFIG_STD_OUTPUT_ORIENTATION_NORMAL 0
52+
#define TCPC_CONFIG_STD_OUTPUT_ORIENTATION_FLIPPED 1
5053

5154
#define TCPC_TCPC_CTRL 0x19
5255
#define TCPC_TCPC_CTRL_ORIENTATION BIT(0)
@@ -127,6 +130,7 @@
127130
#define TCPC_DEV_CAP_2 0x26
128131
#define TCPC_STD_INPUT_CAP 0x28
129132
#define TCPC_STD_OUTPUT_CAP 0x29
133+
#define TCPC_STD_OUTPUT_CAP_ORIENTATION BIT(0)
130134

131135
#define TCPC_MSG_HDR_INFO 0x2e
132136
#define TCPC_MSG_HDR_INFO_DATA_ROLE BIT(3)
@@ -209,13 +213,17 @@ struct tcpci;
209213
* swap following Discover Identity on SOP' occurs.
210214
* Return true when the TCPM is allowed to request a Vconn swap
211215
* after Discovery Identity on SOP.
216+
* @set_orientation:
217+
* Optional; Enable setting the connector orientation
218+
* CONFIG_STANDARD_OUTPUT (0x18) bit0.
212219
*/
213220
struct tcpci_data {
214221
struct regmap *regmap;
215222
unsigned char TX_BUF_BYTE_x_hidden:1;
216223
unsigned char auto_discharge_disconnect:1;
217224
unsigned char vbus_vsafe0v:1;
218225
unsigned char cable_comm_capable:1;
226+
unsigned char set_orientation:1;
219227

220228
int (*init)(struct tcpci *tcpci, struct tcpci_data *data);
221229
int (*set_vconn)(struct tcpci *tcpci, struct tcpci_data *data,

0 commit comments

Comments
 (0)