0001
0002
0003
0004
0005
0006 #ifndef __LINUX_USB_TCPM_H
0007 #define __LINUX_USB_TCPM_H
0008
0009 #include <linux/bitops.h>
0010 #include <linux/usb/typec.h>
0011 #include "pd.h"
0012
0013 enum typec_cc_status {
0014 TYPEC_CC_OPEN,
0015 TYPEC_CC_RA,
0016 TYPEC_CC_RD,
0017 TYPEC_CC_RP_DEF,
0018 TYPEC_CC_RP_1_5,
0019 TYPEC_CC_RP_3_0,
0020 };
0021
0022
0023 #define SINK_TX_NG TYPEC_CC_RP_1_5
0024 #define SINK_TX_OK TYPEC_CC_RP_3_0
0025
0026 enum typec_cc_polarity {
0027 TYPEC_POLARITY_CC1,
0028 TYPEC_POLARITY_CC2,
0029 };
0030
0031
0032 #define PD_T_TCPC_TX_TIMEOUT 100
0033 #define PD_ROLE_SWAP_TIMEOUT (MSEC_PER_SEC * 10)
0034 #define PD_PPS_CTRL_TIMEOUT (MSEC_PER_SEC * 10)
0035
0036 enum tcpm_transmit_status {
0037 TCPC_TX_SUCCESS = 0,
0038 TCPC_TX_DISCARDED = 1,
0039 TCPC_TX_FAILED = 2,
0040 };
0041
0042 enum tcpm_transmit_type {
0043 TCPC_TX_SOP = 0,
0044 TCPC_TX_SOP_PRIME = 1,
0045 TCPC_TX_SOP_PRIME_PRIME = 2,
0046 TCPC_TX_SOP_DEBUG_PRIME = 3,
0047 TCPC_TX_SOP_DEBUG_PRIME_PRIME = 4,
0048 TCPC_TX_HARD_RESET = 5,
0049 TCPC_TX_CABLE_RESET = 6,
0050 TCPC_TX_BIST_MODE_2 = 7
0051 };
0052
0053
0054 #define TCPC_MUX_USB_ENABLED BIT(0)
0055 #define TCPC_MUX_DP_ENABLED BIT(1)
0056 #define TCPC_MUX_POLARITY_INVERTED BIT(2)
0057
0058
0059
0060
0061
0062
0063
0064
0065
0066
0067
0068
0069
0070
0071
0072
0073
0074
0075
0076
0077
0078
0079
0080
0081
0082
0083
0084
0085
0086
0087
0088
0089
0090
0091
0092
0093
0094
0095
0096
0097
0098
0099
0100
0101
0102
0103
0104
0105
0106
0107
0108
0109
0110
0111
0112
0113
0114
0115
0116
0117
0118 struct tcpc_dev {
0119 struct fwnode_handle *fwnode;
0120
0121 int (*init)(struct tcpc_dev *dev);
0122 int (*get_vbus)(struct tcpc_dev *dev);
0123 int (*get_current_limit)(struct tcpc_dev *dev);
0124 int (*set_cc)(struct tcpc_dev *dev, enum typec_cc_status cc);
0125 int (*apply_rc)(struct tcpc_dev *dev, enum typec_cc_status cc,
0126 enum typec_cc_polarity polarity);
0127 int (*get_cc)(struct tcpc_dev *dev, enum typec_cc_status *cc1,
0128 enum typec_cc_status *cc2);
0129 int (*set_polarity)(struct tcpc_dev *dev,
0130 enum typec_cc_polarity polarity);
0131 int (*set_vconn)(struct tcpc_dev *dev, bool on);
0132 int (*set_vbus)(struct tcpc_dev *dev, bool on, bool charge);
0133 int (*set_current_limit)(struct tcpc_dev *dev, u32 max_ma, u32 mv);
0134 int (*set_pd_rx)(struct tcpc_dev *dev, bool on);
0135 int (*set_roles)(struct tcpc_dev *dev, bool attached,
0136 enum typec_role role, enum typec_data_role data);
0137 int (*start_toggling)(struct tcpc_dev *dev,
0138 enum typec_port_type port_type,
0139 enum typec_cc_status cc);
0140 int (*try_role)(struct tcpc_dev *dev, int role);
0141 int (*pd_transmit)(struct tcpc_dev *dev, enum tcpm_transmit_type type,
0142 const struct pd_message *msg, unsigned int negotiated_rev);
0143 int (*set_bist_data)(struct tcpc_dev *dev, bool on);
0144 int (*enable_frs)(struct tcpc_dev *dev, bool enable);
0145 void (*frs_sourcing_vbus)(struct tcpc_dev *dev);
0146 int (*enable_auto_vbus_discharge)(struct tcpc_dev *dev, bool enable);
0147 int (*set_auto_vbus_discharge_threshold)(struct tcpc_dev *dev, enum typec_pwr_opmode mode,
0148 bool pps_active, u32 requested_vbus_voltage);
0149 bool (*is_vbus_vsafe0v)(struct tcpc_dev *dev);
0150 void (*set_partner_usb_comm_capable)(struct tcpc_dev *dev, bool enable);
0151 };
0152
0153 struct tcpm_port;
0154
0155 struct tcpm_port *tcpm_register_port(struct device *dev, struct tcpc_dev *tcpc);
0156 void tcpm_unregister_port(struct tcpm_port *port);
0157
0158 void tcpm_vbus_change(struct tcpm_port *port);
0159 void tcpm_cc_change(struct tcpm_port *port);
0160 void tcpm_sink_frs(struct tcpm_port *port);
0161 void tcpm_sourcing_vbus(struct tcpm_port *port);
0162 void tcpm_pd_receive(struct tcpm_port *port,
0163 const struct pd_message *msg);
0164 void tcpm_pd_transmit_complete(struct tcpm_port *port,
0165 enum tcpm_transmit_status status);
0166 void tcpm_pd_hard_reset(struct tcpm_port *port);
0167 void tcpm_tcpc_reset(struct tcpm_port *port);
0168
0169 #endif