Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-or-later */
0002 /*
0003  * Copyright 2015-2017 Google, Inc
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 /* Collision Avoidance */
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 /* Time to wait for TCPC to complete transmit */
0032 #define PD_T_TCPC_TX_TIMEOUT    100     /* in ms    */
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 /* Mux state attributes */
0054 #define TCPC_MUX_USB_ENABLED        BIT(0)  /* USB enabled */
0055 #define TCPC_MUX_DP_ENABLED     BIT(1)  /* DP enabled */
0056 #define TCPC_MUX_POLARITY_INVERTED  BIT(2)  /* Polarity inverted */
0057 
0058 /**
0059  * struct tcpc_dev - Port configuration and callback functions
0060  * @fwnode: Pointer to port fwnode
0061  * @get_vbus:   Called to read current VBUS state
0062  * @get_current_limit:
0063  *      Optional; called by the tcpm core when configured as a snk
0064  *      and cc=Rp-def. This allows the tcpm to provide a fallback
0065  *      current-limit detection method for the cc=Rp-def case.
0066  *      For example, some tcpcs may include BC1.2 charger detection
0067  *      and use that in this case.
0068  * @set_cc: Called to set value of CC pins
0069  * @apply_rc:   Optional; Needed to move TCPCI based chipset to APPLY_RC state
0070  *      as stated by the TCPCI specification.
0071  * @get_cc: Called to read current CC pin values
0072  * @set_polarity:
0073  *      Called to set polarity
0074  * @set_vconn:  Called to enable or disable VCONN
0075  * @set_vbus:   Called to enable or disable VBUS
0076  * @set_current_limit:
0077  *      Optional; called to set current limit as negotiated
0078  *      with partner.
0079  * @set_pd_rx:  Called to enable or disable reception of PD messages
0080  * @set_roles:  Called to set power and data roles
0081  * @start_toggling:
0082  *      Optional; if supported by hardware, called to start dual-role
0083  *      toggling or single-role connection detection. Toggling stops
0084  *      automatically if a connection is established.
0085  * @try_role:   Optional; called to set a preferred role
0086  * @pd_transmit:Called to transmit PD message
0087  * @set_bist_data: Turn on/off bist data mode for compliance testing
0088  * @enable_frs:
0089  *      Optional; Called to enable/disable PD 3.0 fast role swap.
0090  *      Enabling frs is accessory dependent as not all PD3.0
0091  *      accessories support fast role swap.
0092  * @frs_sourcing_vbus:
0093  *      Optional; Called to notify that vbus is now being sourced.
0094  *      Low level drivers can perform chip specific operations, if any.
0095  * @enable_auto_vbus_discharge:
0096  *      Optional; TCPCI spec based TCPC implementations can optionally
0097  *      support hardware to autonomously dischrge vbus upon disconnecting
0098  *      as sink or source. TCPM signals TCPC to enable the mechanism upon
0099  *      entering connected state and signals disabling upon disconnect.
0100  * @set_auto_vbus_discharge_threshold:
0101  *      Mandatory when enable_auto_vbus_discharge is implemented. TCPM
0102  *      calls this function to allow lower levels drivers to program the
0103  *      vbus threshold voltage below which the vbus discharge circuit
0104  *      will be turned on. requested_vbus_voltage is set to 0 when vbus
0105  *      is going to disappear knowingly i.e. during PR_SWAP and
0106  *      HARD_RESET etc.
0107  * @is_vbus_vsafe0v:
0108  *      Optional; TCPCI spec based TCPC implementations are expected to
0109  *      detect VSAFE0V voltage level at vbus. When detection of VSAFE0V
0110  *      is supported by TCPC, set this callback for TCPM to query
0111  *      whether vbus is at VSAFE0V when needed.
0112  *      Returns true when vbus is at VSAFE0V, false otherwise.
0113  * @set_partner_usb_comm_capable:
0114  *              Optional; The USB Communications Capable bit indicates if port
0115  *              partner is capable of communication over the USB data lines
0116  *              (e.g. D+/- or SS Tx/Rx). Called to notify the status of the bit.
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 /* __LINUX_USB_TCPM_H */