| .. | .. |
|---|
| 8 | 8 | #ifndef __LINUX_USB_TCPCI_H |
|---|
| 9 | 9 | #define __LINUX_USB_TCPCI_H |
|---|
| 10 | 10 | |
|---|
| 11 | +#include <linux/usb/typec.h> |
|---|
| 12 | + |
|---|
| 11 | 13 | #define TCPC_VENDOR_ID 0x0 |
|---|
| 12 | 14 | #define TCPC_PRODUCT_ID 0x2 |
|---|
| 13 | 15 | #define TCPC_BCD_DEV 0x4 |
|---|
| .. | .. |
|---|
| 16 | 18 | #define TCPC_PD_INT_REV 0xa |
|---|
| 17 | 19 | |
|---|
| 18 | 20 | #define TCPC_ALERT 0x10 |
|---|
| 21 | +#define TCPC_ALERT_EXTND BIT(14) |
|---|
| 22 | +#define TCPC_ALERT_EXTENDED_STATUS BIT(13) |
|---|
| 19 | 23 | #define TCPC_ALERT_VBUS_DISCNCT BIT(11) |
|---|
| 20 | 24 | #define TCPC_ALERT_RX_BUF_OVF BIT(10) |
|---|
| 21 | 25 | #define TCPC_ALERT_FAULT BIT(9) |
|---|
| .. | .. |
|---|
| 32 | 36 | #define TCPC_ALERT_MASK 0x12 |
|---|
| 33 | 37 | #define TCPC_POWER_STATUS_MASK 0x14 |
|---|
| 34 | 38 | #define TCPC_FAULT_STATUS_MASK 0x15 |
|---|
| 39 | + |
|---|
| 40 | +#define TCPC_EXTENDED_STATUS_MASK 0x16 |
|---|
| 41 | +#define TCPC_EXTENDED_STATUS_MASK_VSAFE0V BIT(0) |
|---|
| 42 | + |
|---|
| 43 | +#define TCPC_ALERT_EXTENDED_MASK 0x17 |
|---|
| 44 | +#define TCPC_SINK_FAST_ROLE_SWAP BIT(0) |
|---|
| 45 | + |
|---|
| 35 | 46 | #define TCPC_CONFIG_STD_OUTPUT 0x18 |
|---|
| 36 | 47 | |
|---|
| 37 | 48 | #define TCPC_TCPC_CTRL 0x19 |
|---|
| 38 | 49 | #define TCPC_TCPC_CTRL_ORIENTATION BIT(0) |
|---|
| 50 | +#define PLUG_ORNT_CC1 0 |
|---|
| 51 | +#define PLUG_ORNT_CC2 1 |
|---|
| 52 | +#define TCPC_TCPC_CTRL_BIST_TM BIT(1) |
|---|
| 53 | +#define TCPC_TCPC_CTRL_EN_LK4CONN_ALRT BIT(6) |
|---|
| 54 | + |
|---|
| 55 | +#define TCPC_EXTENDED_STATUS 0x20 |
|---|
| 56 | +#define TCPC_EXTENDED_STATUS_VSAFE0V BIT(0) |
|---|
| 39 | 57 | |
|---|
| 40 | 58 | #define TCPC_ROLE_CTRL 0x1a |
|---|
| 41 | 59 | #define TCPC_ROLE_CTRL_DRP BIT(6) |
|---|
| .. | .. |
|---|
| 57 | 75 | |
|---|
| 58 | 76 | #define TCPC_POWER_CTRL 0x1c |
|---|
| 59 | 77 | #define TCPC_POWER_CTRL_VCONN_ENABLE BIT(0) |
|---|
| 78 | +#define TCPC_POWER_CTRL_BLEED_DISCHARGE BIT(3) |
|---|
| 79 | +#define TCPC_POWER_CTRL_AUTO_DISCHARGE BIT(4) |
|---|
| 80 | +#define TCPC_DIS_VOLT_ALRM BIT(5) |
|---|
| 81 | +#define TCPC_POWER_CTRL_VBUS_VOLT_MON BIT(6) |
|---|
| 82 | +#define TCPC_FAST_ROLE_SWAP_EN BIT(7) |
|---|
| 60 | 83 | |
|---|
| 61 | 84 | #define TCPC_CC_STATUS 0x1d |
|---|
| 62 | 85 | #define TCPC_CC_STATUS_TOGGLING BIT(5) |
|---|
| 63 | 86 | #define TCPC_CC_STATUS_TERM BIT(4) |
|---|
| 87 | +#define TCPC_CC_STATUS_TERM_RP 0 |
|---|
| 88 | +#define TCPC_CC_STATUS_TERM_RD 1 |
|---|
| 89 | +#define TCPC_CC_STATE_SRC_OPEN 0 |
|---|
| 64 | 90 | #define TCPC_CC_STATUS_CC2_SHIFT 2 |
|---|
| 65 | 91 | #define TCPC_CC_STATUS_CC2_MASK 0x3 |
|---|
| 66 | 92 | #define TCPC_CC_STATUS_CC1_SHIFT 0 |
|---|
| 67 | 93 | #define TCPC_CC_STATUS_CC1_MASK 0x3 |
|---|
| 68 | 94 | |
|---|
| 69 | 95 | #define TCPC_POWER_STATUS 0x1e |
|---|
| 96 | +#define TCPC_POWER_STATUS_DBG_ACC_CON BIT(7) |
|---|
| 70 | 97 | #define TCPC_POWER_STATUS_UNINIT BIT(6) |
|---|
| 98 | +#define TCPC_POWER_STATUS_SOURCING_VBUS BIT(4) |
|---|
| 71 | 99 | #define TCPC_POWER_STATUS_VBUS_DET BIT(3) |
|---|
| 72 | 100 | #define TCPC_POWER_STATUS_VBUS_PRES BIT(2) |
|---|
| 101 | +#define TCPC_POWER_STATUS_VCONN_PRES BIT(1) |
|---|
| 102 | +#define TCPC_POWER_STATUS_SINKING_VBUS BIT(0) |
|---|
| 73 | 103 | |
|---|
| 74 | 104 | #define TCPC_FAULT_STATUS 0x1f |
|---|
| 105 | +#define TCPC_FAULT_STATUS_ALL_REG_RST_TO_DEFAULT BIT(7) |
|---|
| 106 | + |
|---|
| 107 | +#define TCPC_ALERT_EXTENDED 0x21 |
|---|
| 75 | 108 | |
|---|
| 76 | 109 | #define TCPC_COMMAND 0x23 |
|---|
| 77 | 110 | #define TCPC_CMD_WAKE_I2C 0x11 |
|---|
| .. | .. |
|---|
| 100 | 133 | #define TCPC_RX_DETECT 0x2f |
|---|
| 101 | 134 | #define TCPC_RX_DETECT_HARD_RESET BIT(5) |
|---|
| 102 | 135 | #define TCPC_RX_DETECT_SOP BIT(0) |
|---|
| 136 | +#define TCPC_RX_DETECT_SOP1 BIT(1) |
|---|
| 137 | +#define TCPC_RX_DETECT_SOP2 BIT(2) |
|---|
| 138 | +#define TCPC_RX_DETECT_DBG1 BIT(3) |
|---|
| 139 | +#define TCPC_RX_DETECT_DBG2 BIT(4) |
|---|
| 103 | 140 | |
|---|
| 104 | 141 | #define TCPC_RX_BYTE_CNT 0x30 |
|---|
| 105 | 142 | #define TCPC_RX_BUF_FRAME_TYPE 0x31 |
|---|
| 143 | +#define TCPC_RX_BUF_FRAME_TYPE_SOP 0 |
|---|
| 106 | 144 | #define TCPC_RX_HDR 0x32 |
|---|
| 107 | 145 | #define TCPC_RX_DATA 0x34 /* through 0x4f */ |
|---|
| 108 | 146 | |
|---|
| .. | .. |
|---|
| 117 | 155 | #define TCPC_TX_DATA 0x54 /* through 0x6f */ |
|---|
| 118 | 156 | |
|---|
| 119 | 157 | #define TCPC_VBUS_VOLTAGE 0x70 |
|---|
| 158 | +#define TCPC_VBUS_VOLTAGE_MASK 0x3ff |
|---|
| 159 | +#define TCPC_VBUS_VOLTAGE_LSB_MV 25 |
|---|
| 120 | 160 | #define TCPC_VBUS_SINK_DISCONNECT_THRESH 0x72 |
|---|
| 161 | +#define TCPC_VBUS_SINK_DISCONNECT_THRESH_LSB_MV 25 |
|---|
| 162 | +#define TCPC_VBUS_SINK_DISCONNECT_THRESH_MAX 0x3ff |
|---|
| 121 | 163 | #define TCPC_VBUS_STOP_DISCHARGE_THRESH 0x74 |
|---|
| 122 | 164 | #define TCPC_VBUS_VOLTAGE_ALARM_HI_CFG 0x76 |
|---|
| 123 | 165 | #define TCPC_VBUS_VOLTAGE_ALARM_LO_CFG 0x78 |
|---|
| 124 | 166 | |
|---|
| 167 | +/* I2C_WRITE_BYTE_COUNT + 1 when TX_BUF_BYTE_x is only accessible I2C_WRITE_BYTE_COUNT */ |
|---|
| 168 | +#define TCPC_TRANSMIT_BUFFER_MAX_LEN 31 |
|---|
| 169 | + |
|---|
| 125 | 170 | struct tcpci; |
|---|
| 171 | + |
|---|
| 172 | +/* |
|---|
| 173 | + * @TX_BUF_BYTE_x_hidden: |
|---|
| 174 | + * optional; Set when TX_BUF_BYTE_x can only be accessed through I2C_WRITE_BYTE_COUNT. |
|---|
| 175 | + * @frs_sourcing_vbus: |
|---|
| 176 | + * Optional; Callback to perform chip specific operations when FRS |
|---|
| 177 | + * is sourcing vbus. |
|---|
| 178 | + * @auto_discharge_disconnect: |
|---|
| 179 | + * Optional; Enables TCPC to autonously discharge vbus on disconnect. |
|---|
| 180 | + * @vbus_vsafe0v: |
|---|
| 181 | + * optional; Set when TCPC can detect whether vbus is at VSAFE0V. |
|---|
| 182 | + * @set_partner_usb_comm_capable: |
|---|
| 183 | + * Optional; The USB Communications Capable bit indicates if port |
|---|
| 184 | + * partner is capable of communication over the USB data lines |
|---|
| 185 | + * (e.g. D+/- or SS Tx/Rx). Called to notify the status of the bit. |
|---|
| 186 | + */ |
|---|
| 126 | 187 | struct tcpci_data { |
|---|
| 127 | 188 | struct regmap *regmap; |
|---|
| 189 | + unsigned char TX_BUF_BYTE_x_hidden:1; |
|---|
| 190 | + unsigned char auto_discharge_disconnect:1; |
|---|
| 191 | + unsigned char vbus_vsafe0v:1; |
|---|
| 192 | + |
|---|
| 128 | 193 | int (*init)(struct tcpci *tcpci, struct tcpci_data *data); |
|---|
| 129 | 194 | int (*set_vconn)(struct tcpci *tcpci, struct tcpci_data *data, |
|---|
| 130 | 195 | bool enable); |
|---|
| 131 | 196 | int (*start_drp_toggling)(struct tcpci *tcpci, struct tcpci_data *data, |
|---|
| 132 | 197 | enum typec_cc_status cc); |
|---|
| 198 | + int (*set_vbus)(struct tcpci *tcpci, struct tcpci_data *data, bool source, bool sink); |
|---|
| 199 | + void (*frs_sourcing_vbus)(struct tcpci *tcpci, struct tcpci_data *data); |
|---|
| 200 | + void (*set_partner_usb_comm_capable)(struct tcpci *tcpci, struct tcpci_data *data, |
|---|
| 201 | + bool capable); |
|---|
| 133 | 202 | }; |
|---|
| 134 | 203 | |
|---|
| 135 | 204 | struct tcpci *tcpci_register_port(struct device *dev, struct tcpci_data *data); |
|---|
| 136 | 205 | void tcpci_unregister_port(struct tcpci *tcpci); |
|---|
| 137 | 206 | irqreturn_t tcpci_irq(struct tcpci *tcpci); |
|---|
| 138 | 207 | |
|---|
| 208 | +struct tcpm_port; |
|---|
| 209 | +struct tcpm_port *tcpci_get_tcpm_port(struct tcpci *tcpci); |
|---|
| 139 | 210 | #endif /* __LINUX_USB_TCPCI_H */ |
|---|