mirror of
https://github.com/AuxXxilium/linux_dsm_epyc7002.git
synced 2024-11-24 11:50:52 +07:00
8dc4bd0736
PD 3.0 spec defines a new mechanism for power role swap called Fast role swap. This change enables TCPM to support FRS when acting as sink. Once the explicit contract is negotiated, sink port is expected to query the source port for sink caps to determine whether the source is FRS capable. Bits 23 & 24 of fixed pdo of the sink caps from the source, when set, indicates the current needed by the source when fast role swap is in progress(Implicit contract phasae). 0 indicates that the source does not support Fast Role Swap. Upon receiving the FRS signal from the source, TCPC(TCPM_FRS_EVENT) informs TCPM to start the Fast role swap sequence. 1. TCPM sends FRS PD message: FR_SWAP_SEND 2. If response is not received within the expiry of SenderResponseTimer, Error recovery is triggered.: FR_SWAP_SEND_TIMEOUT 3. Upon receipt of the accept message, TCPM waits for PSSourceOffTimer for PS_READY message from the partner: FR_SWAP_SNK_SRC_NEW_SINK_READY. TCPC is expected to autonomously turn on vbus once the FRS signal is received and vbus voltage falls below vsafe5v within tSrcFrSwap. This is different from traditional power role swap where the vbus sourcing is turned on by TCPM. 4. By this time, TCPC most likely would have started to source vbus, TCPM waits for tSrcFrSwap to see if the lower level TCPC driver signals TCPM_SOURCING_VBUS event: FR_SWAP_SNK_SRC_SOURCE_VBUS_APPLIED. 5. When TCPC signals sourcing vbus, TCPM sends PS_READY msg and changes the CC pin from Rd to Rp. This is the end of fast role swap sequence and TCPM initiates the sequnce to negotiate explicit contract by transitioning into SRC_STARTUP after SwapSrcStart. The code is written based on the sequence described in "Figure 8-107: Dual-role Port in Sink to Source Fast Role Swap State Diagram" of USB Power Delivery Specification Revision 3.0, Version 1.2. Signed-off-by: Badhri Jagan Sridharan <badhri@google.com> Reviewed-by: Heikki Krogerus <heikki.krogerus@linux.intel.com> Link: https://lore.kernel.org/r/20201008061556.1402293-7-badhri@google.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
131 lines
4.3 KiB
C
131 lines
4.3 KiB
C
/* SPDX-License-Identifier: GPL-2.0-or-later */
|
|
/*
|
|
* Copyright 2015-2017 Google, Inc
|
|
*/
|
|
|
|
#ifndef __LINUX_USB_TCPM_H
|
|
#define __LINUX_USB_TCPM_H
|
|
|
|
#include <linux/bitops.h>
|
|
#include <linux/usb/typec.h>
|
|
#include "pd.h"
|
|
|
|
enum typec_cc_status {
|
|
TYPEC_CC_OPEN,
|
|
TYPEC_CC_RA,
|
|
TYPEC_CC_RD,
|
|
TYPEC_CC_RP_DEF,
|
|
TYPEC_CC_RP_1_5,
|
|
TYPEC_CC_RP_3_0,
|
|
};
|
|
|
|
enum typec_cc_polarity {
|
|
TYPEC_POLARITY_CC1,
|
|
TYPEC_POLARITY_CC2,
|
|
};
|
|
|
|
/* Time to wait for TCPC to complete transmit */
|
|
#define PD_T_TCPC_TX_TIMEOUT 100 /* in ms */
|
|
#define PD_ROLE_SWAP_TIMEOUT (MSEC_PER_SEC * 10)
|
|
#define PD_PPS_CTRL_TIMEOUT (MSEC_PER_SEC * 10)
|
|
|
|
enum tcpm_transmit_status {
|
|
TCPC_TX_SUCCESS = 0,
|
|
TCPC_TX_DISCARDED = 1,
|
|
TCPC_TX_FAILED = 2,
|
|
};
|
|
|
|
enum tcpm_transmit_type {
|
|
TCPC_TX_SOP = 0,
|
|
TCPC_TX_SOP_PRIME = 1,
|
|
TCPC_TX_SOP_PRIME_PRIME = 2,
|
|
TCPC_TX_SOP_DEBUG_PRIME = 3,
|
|
TCPC_TX_SOP_DEBUG_PRIME_PRIME = 4,
|
|
TCPC_TX_HARD_RESET = 5,
|
|
TCPC_TX_CABLE_RESET = 6,
|
|
TCPC_TX_BIST_MODE_2 = 7
|
|
};
|
|
|
|
/* Mux state attributes */
|
|
#define TCPC_MUX_USB_ENABLED BIT(0) /* USB enabled */
|
|
#define TCPC_MUX_DP_ENABLED BIT(1) /* DP enabled */
|
|
#define TCPC_MUX_POLARITY_INVERTED BIT(2) /* Polarity inverted */
|
|
|
|
/**
|
|
* struct tcpc_dev - Port configuration and callback functions
|
|
* @fwnode: Pointer to port fwnode
|
|
* @get_vbus: Called to read current VBUS state
|
|
* @get_current_limit:
|
|
* Optional; called by the tcpm core when configured as a snk
|
|
* and cc=Rp-def. This allows the tcpm to provide a fallback
|
|
* current-limit detection method for the cc=Rp-def case.
|
|
* For example, some tcpcs may include BC1.2 charger detection
|
|
* and use that in this case.
|
|
* @set_cc: Called to set value of CC pins
|
|
* @get_cc: Called to read current CC pin values
|
|
* @set_polarity:
|
|
* Called to set polarity
|
|
* @set_vconn: Called to enable or disable VCONN
|
|
* @set_vbus: Called to enable or disable VBUS
|
|
* @set_current_limit:
|
|
* Optional; called to set current limit as negotiated
|
|
* with partner.
|
|
* @set_pd_rx: Called to enable or disable reception of PD messages
|
|
* @set_roles: Called to set power and data roles
|
|
* @start_toggling:
|
|
* Optional; if supported by hardware, called to start dual-role
|
|
* toggling or single-role connection detection. Toggling stops
|
|
* automatically if a connection is established.
|
|
* @try_role: Optional; called to set a preferred role
|
|
* @pd_transmit:Called to transmit PD message
|
|
* @set_bist_data: Turn on/off bist data mode for compliance testing
|
|
* @enable_frs:
|
|
* Optional; Called to enable/disable PD 3.0 fast role swap.
|
|
* Enabling frs is accessory dependent as not all PD3.0
|
|
* accessories support fast role swap.
|
|
*/
|
|
struct tcpc_dev {
|
|
struct fwnode_handle *fwnode;
|
|
|
|
int (*init)(struct tcpc_dev *dev);
|
|
int (*get_vbus)(struct tcpc_dev *dev);
|
|
int (*get_current_limit)(struct tcpc_dev *dev);
|
|
int (*set_cc)(struct tcpc_dev *dev, enum typec_cc_status cc);
|
|
int (*get_cc)(struct tcpc_dev *dev, enum typec_cc_status *cc1,
|
|
enum typec_cc_status *cc2);
|
|
int (*set_polarity)(struct tcpc_dev *dev,
|
|
enum typec_cc_polarity polarity);
|
|
int (*set_vconn)(struct tcpc_dev *dev, bool on);
|
|
int (*set_vbus)(struct tcpc_dev *dev, bool on, bool charge);
|
|
int (*set_current_limit)(struct tcpc_dev *dev, u32 max_ma, u32 mv);
|
|
int (*set_pd_rx)(struct tcpc_dev *dev, bool on);
|
|
int (*set_roles)(struct tcpc_dev *dev, bool attached,
|
|
enum typec_role role, enum typec_data_role data);
|
|
int (*start_toggling)(struct tcpc_dev *dev,
|
|
enum typec_port_type port_type,
|
|
enum typec_cc_status cc);
|
|
int (*try_role)(struct tcpc_dev *dev, int role);
|
|
int (*pd_transmit)(struct tcpc_dev *dev, enum tcpm_transmit_type type,
|
|
const struct pd_message *msg);
|
|
int (*set_bist_data)(struct tcpc_dev *dev, bool on);
|
|
int (*enable_frs)(struct tcpc_dev *dev, bool enable);
|
|
};
|
|
|
|
struct tcpm_port;
|
|
|
|
struct tcpm_port *tcpm_register_port(struct device *dev, struct tcpc_dev *tcpc);
|
|
void tcpm_unregister_port(struct tcpm_port *port);
|
|
|
|
void tcpm_vbus_change(struct tcpm_port *port);
|
|
void tcpm_cc_change(struct tcpm_port *port);
|
|
void tcpm_sink_frs(struct tcpm_port *port);
|
|
void tcpm_sourcing_vbus(struct tcpm_port *port);
|
|
void tcpm_pd_receive(struct tcpm_port *port,
|
|
const struct pd_message *msg);
|
|
void tcpm_pd_transmit_complete(struct tcpm_port *port,
|
|
enum tcpm_transmit_status status);
|
|
void tcpm_pd_hard_reset(struct tcpm_port *port);
|
|
void tcpm_tcpc_reset(struct tcpm_port *port);
|
|
|
|
#endif /* __LINUX_USB_TCPM_H */
|