Skip to content

Commit 11121c2

Browse files
Badhri Jagan Sridharangregkh
authored andcommitted
usb: typec: tcpci: Implement callbacks for FRS
Implement tcpc.enable_frs to enable TCPC to receive Fast role swap signal. Additionally set the sink disconnect threshold to 4v to prevent disconnect during Fast Role swap. Signed-off-by: Badhri Jagan Sridharan <[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 8dc4bd0 commit 11121c2

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

drivers/usb/typec/tcpm/tcpci.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,22 @@ static int tcpci_set_vconn(struct tcpc_dev *tcpc, bool enable)
268268
enable ? TCPC_POWER_CTRL_VCONN_ENABLE : 0);
269269
}
270270

271+
static int tcpci_enable_frs(struct tcpc_dev *dev, bool enable)
272+
{
273+
struct tcpci *tcpci = tcpc_to_tcpci(dev);
274+
int ret;
275+
276+
/* To prevent disconnect during FRS, set disconnect threshold to 3.5V */
277+
ret = tcpci_write16(tcpci, TCPC_VBUS_SINK_DISCONNECT_THRESH, enable ? 0 : 0x8c);
278+
if (ret < 0)
279+
return ret;
280+
281+
ret = regmap_update_bits(tcpci->regmap, TCPC_POWER_CTRL, TCPC_FAST_ROLE_SWAP_EN, enable ?
282+
TCPC_FAST_ROLE_SWAP_EN : 0);
283+
284+
return ret;
285+
}
286+
271287
static int tcpci_set_bist_data(struct tcpc_dev *tcpc, bool enable)
272288
{
273289
struct tcpci *tcpci = tcpc_to_tcpci(tcpc);
@@ -611,6 +627,7 @@ struct tcpci *tcpci_register_port(struct device *dev, struct tcpci_data *data)
611627
tcpci->tcpc.set_roles = tcpci_set_roles;
612628
tcpci->tcpc.pd_transmit = tcpci_pd_transmit;
613629
tcpci->tcpc.set_bist_data = tcpci_set_bist_data;
630+
tcpci->tcpc.enable_frs = tcpci_enable_frs;
614631

615632
err = tcpci_parse_config(tcpci);
616633
if (err < 0)

drivers/usb/typec/tcpm/tcpci.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#define TCPC_PD_INT_REV 0xa
1717

1818
#define TCPC_ALERT 0x10
19+
#define TCPC_ALERT_EXTND BIT(14)
1920
#define TCPC_ALERT_EXTENDED_STATUS BIT(13)
2021
#define TCPC_ALERT_VBUS_DISCNCT BIT(11)
2122
#define TCPC_ALERT_RX_BUF_OVF BIT(10)
@@ -37,6 +38,9 @@
3738
#define TCPC_EXTENDED_STATUS_MASK 0x16
3839
#define TCPC_EXTENDED_STATUS_MASK_VSAFE0V BIT(0)
3940

41+
#define TCPC_ALERT_EXTENDED_MASK 0x17
42+
#define TCPC_SINK_FAST_ROLE_SWAP BIT(0)
43+
4044
#define TCPC_CONFIG_STD_OUTPUT 0x18
4145

4246
#define TCPC_TCPC_CTRL 0x19
@@ -63,6 +67,7 @@
6367

6468
#define TCPC_POWER_CTRL 0x1c
6569
#define TCPC_POWER_CTRL_VCONN_ENABLE BIT(0)
70+
#define TCPC_FAST_ROLE_SWAP_EN BIT(7)
6671

6772
#define TCPC_CC_STATUS 0x1d
6873
#define TCPC_CC_STATUS_TOGGLING BIT(5)
@@ -74,11 +79,14 @@
7479

7580
#define TCPC_POWER_STATUS 0x1e
7681
#define TCPC_POWER_STATUS_UNINIT BIT(6)
82+
#define TCPC_POWER_STATUS_SOURCING_VBUS BIT(4)
7783
#define TCPC_POWER_STATUS_VBUS_DET BIT(3)
7884
#define TCPC_POWER_STATUS_VBUS_PRES BIT(2)
7985

8086
#define TCPC_FAULT_STATUS 0x1f
8187

88+
#define TCPC_ALERT_EXTENDED 0x21
89+
8290
#define TCPC_COMMAND 0x23
8391
#define TCPC_CMD_WAKE_I2C 0x11
8492
#define TCPC_CMD_DISABLE_VBUS_DETECT 0x22

0 commit comments

Comments
 (0)