mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2026-06-21 15:43:21 +02:00
d3d959404e
Add support to enable TCPM to negotiate with USB PD Standard Power Range Adjustable Voltage Supply (SPR AVS) when acting as a power sink. * Added support to the tcpm power supply properties, allowing userspace to enable and control the dynamic limits (voltage and current) specific to the SPR AVS contract. * Implemented tcpm_pd_select_spr_avs_apdo() to select the appropriate APDO and validate the requested voltage/current against both the Source and Sink capabilities. * Implemented tcpm_pd_build_spr_avs_request() to construct the Request Data Object (RDO) for SPR AVS. * Added SNK_NEGOTIATE_SPR_AVS_CAPABILITIES state to the state machine to handle negotiation for SPR AVS. * Updated the SNK_TRANSITION_SINK state to implement the SPR AVS-specific VBUS transition rules, including reducing current draw to PD_I_SNK_STBY_MA for large voltage changes, as required by USB PD spec. Log stub captured when enabling AVS: $ echo 3 > /sys/class/power_supply/tcpm-source-psy-1-0025/online $ cat /d/usb/tcpm-1-0025/log [ 358.895775] request to set AVS online [ 358.895792] AMS POWER_NEGOTIATION start [ 358.895806] state change SNK_READY -> AMS_START [rev3 POWER_NEGOTIATION] [ 358.895850] state change AMS_START -> SNK_NEGOTIATE_SPR_AVS_CAPABILITIES [rev3 POWER_NEGOTIATION] [ 358.895866] SPR AVS src_pdo_index:4 snk_pdo_index:2 req_op_curr_ma roundup:2200 req_out_volt_mv roundup:9000 [ 358.895880] Requesting APDO SPR AVS 4: 9000 mV, 2200 mA [ 358.896405] set_auto_vbus_discharge_threshold mode:0 pps_active:n vbus:0 pps_apdo_min_volt:0 ret:0 [ 358.896422] PD TX, header: 0x1a82 [ 358.900158] PD TX complete, status: 0 [ 358.900205] pending state change SNK_NEGOTIATE_SPR_AVS_CAPABILITIES -> HARD_RESET_SEND @ 60 ms [rev3 POWER_NEGOTIATION] [ 358.904832] PD RX, header: 0x1a3 [1] [ 358.904854] state change SNK_NEGOTIATE_SPR_AVS_CAPABILITIES -> SNK_TRANSITION_SINK [rev3 POWER_NEGOTIATION] [ 358.904888] pending state change SNK_TRANSITION_SINK -> HARD_RESET_SEND @ 700 ms [rev3 POWER_NEGOTIATION] [ 359.021530] PD RX, header: 0x3a6 [1] [ 359.021546] Setting voltage/current limit 9000 mV 2200 mA [ 359.023035] set_auto_vbus_discharge_threshold mode:3 pps_active:n vbus:9000 pps_apdo_min_volt:0 ret:0 [ 359.023053] state change SNK_TRANSITION_SINK -> SNK_READY [rev3 POWER_NEGOTIATION] [ 359.023090] AMS POWER_NEGOTIATION finished $ cat /sys/class/power_supply/tcpm-source-psy-1-0025/online 3 Log stub captured when increasing voltage: $ echo 9100000 > /sys/class/power_supply/tcpm-source-psy-1-0025/voltage_now $ cat /d/usb/tcpm-1-0025/log [ 632.116714] AMS POWER_NEGOTIATION start [ 632.116728] state change SNK_READY -> AMS_START [rev3 POWER_NEGOTIATION] [ 632.116779] state change AMS_START -> SNK_NEGOTIATE_SPR_AVS_CAPABILITIES [rev3 POWER_NEGOTIATION] [ 632.116798] SPR AVS src_pdo_index:4 snk_pdo_index:2 req_op_curr_ma roundup:2200 req_out_volt_mv roundup:9100 [ 632.116811] Requesting APDO SPR AVS 4: 9100 mV, 2200 mA [ 632.117315] set_auto_vbus_discharge_threshold mode:0 pps_active:n vbus:0 pps_apdo_min_volt:0 ret:0 [ 632.117328] PD TX, header: 0x1c82 [ 632.121007] PD TX complete, status: 0 [ 632.121052] pending state change SNK_NEGOTIATE_SPR_AVS_CAPABILITIES -> HARD_RESET_SEND @ 60 ms [rev3 POWER_NEGOTIATION] [ 632.124572] PD RX, header: 0x5a3 [1] [ 632.124594] state change SNK_NEGOTIATE_SPR_AVS_CAPABILITIES -> SNK_TRANSITION_SINK [rev3 POWER_NEGOTIATION] [ 632.124623] pending state change SNK_TRANSITION_SINK -> HARD_RESET_SEND @ 700 ms [rev3 POWER_NEGOTIATION] [ 632.149256] PD RX, header: 0x7a6 [1] [ 632.149271] Setting voltage/current limit 9100 mV 2200 mA [ 632.150770] set_auto_vbus_discharge_threshold mode:3 pps_active:n vbus:9100 pps_apdo_min_volt:0 ret:0 [ 632.150787] state change SNK_TRANSITION_SINK -> SNK_READY [rev3 POWER_NEGOTIATION] [ 632.150823] AMS POWER_NEGOTIATION finished $ cat /sys/class/power_supply/tcpm-source-psy-1-0025/voltage_now 9100000 Signed-off-by: Badhri Jagan Sridharan <badhri@google.com> Reviewed-by: Amit Sunil Dhamne <amitsd@google.com> Acked-by: Heikki Krogerus <heikki.krogerus@linux.intel.com> Link: https://patch.msgid.link/20260316150301.3892223-4-badhri@google.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
196 lines
7.7 KiB
C
196 lines
7.7 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,
|
|
};
|
|
|
|
/* Collision Avoidance */
|
|
#define SINK_TX_NG TYPEC_CC_RP_1_5
|
|
#define SINK_TX_OK 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_AUG_PSY_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
|
|
* @apply_rc: Optional; Needed to move TCPCI based chipset to APPLY_RC state
|
|
* as stated by the TCPCI specification.
|
|
* @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.
|
|
* @frs_sourcing_vbus:
|
|
* Optional; Called to notify that vbus is now being sourced.
|
|
* Low level drivers can perform chip specific operations, if any.
|
|
* @enable_auto_vbus_discharge:
|
|
* Optional; TCPCI spec based TCPC implementations can optionally
|
|
* support hardware to autonomously dischrge vbus upon disconnecting
|
|
* as sink or source. TCPM signals TCPC to enable the mechanism upon
|
|
* entering connected state and signals disabling upon disconnect.
|
|
* @set_auto_vbus_discharge_threshold:
|
|
* Mandatory when enable_auto_vbus_discharge is implemented. TCPM
|
|
* calls this function to allow lower levels drivers to program the
|
|
* vbus threshold voltage below which the vbus discharge circuit
|
|
* will be turned on. requested_vbus_voltage is set to 0 when vbus
|
|
* is going to disappear knowingly i.e. during PR_SWAP and
|
|
* HARD_RESET etc.
|
|
* @is_vbus_vsafe0v:
|
|
* Optional; TCPCI spec based TCPC implementations are expected to
|
|
* detect VSAFE0V voltage level at vbus. When detection of VSAFE0V
|
|
* is supported by TCPC, set this callback for TCPM to query
|
|
* whether vbus is at VSAFE0V when needed.
|
|
* Returns true when vbus is at VSAFE0V, false otherwise.
|
|
* @set_partner_usb_comm_capable:
|
|
* Optional; The USB Communications Capable bit indicates if port
|
|
* partner is capable of communication over the USB data lines
|
|
* (e.g. D+/- or SS Tx/Rx). Called to notify the status of the bit.
|
|
* @check_contaminant:
|
|
* Optional; The callback is called when CC pins report open status
|
|
* at the end of the deboumce period or when the port is still
|
|
* toggling. Chip level drivers are expected to check for contaminant
|
|
* and call tcpm_clean_port when the port is clean.
|
|
* @cable_comm_capable
|
|
* Optional; Returns whether cable communication over SOP' is supported
|
|
* by the tcpc
|
|
* @attempt_vconn_swap_discovery:
|
|
* Optional; The callback is called by the TCPM when the result of
|
|
* a Discover Identity request indicates that the port partner is
|
|
* a receptacle capable of modal operation. Chip level TCPCI drivers
|
|
* can implement their own policy to determine if and when a Vconn
|
|
* swap following Discover Identity on SOP' occurs.
|
|
* Return true when the TCPM is allowed to request a Vconn swap
|
|
* after Discovery Identity on SOP.
|
|
*/
|
|
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 (*apply_rc)(struct tcpc_dev *dev, enum typec_cc_status cc,
|
|
enum typec_cc_polarity polarity);
|
|
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_orientation)(struct tcpc_dev *dev,
|
|
enum typec_orientation orientation);
|
|
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, unsigned int negotiated_rev);
|
|
int (*set_bist_data)(struct tcpc_dev *dev, bool on);
|
|
int (*enable_frs)(struct tcpc_dev *dev, bool enable);
|
|
void (*frs_sourcing_vbus)(struct tcpc_dev *dev);
|
|
int (*enable_auto_vbus_discharge)(struct tcpc_dev *dev, bool enable);
|
|
int (*set_auto_vbus_discharge_threshold)(struct tcpc_dev *dev, enum typec_pwr_opmode mode,
|
|
bool pps_active, u32 requested_vbus_voltage,
|
|
u32 pps_apdo_min_voltage);
|
|
bool (*is_vbus_vsafe0v)(struct tcpc_dev *dev);
|
|
void (*set_partner_usb_comm_capable)(struct tcpc_dev *dev, bool enable);
|
|
void (*check_contaminant)(struct tcpc_dev *dev);
|
|
bool (*cable_comm_capable)(struct tcpc_dev *dev);
|
|
bool (*attempt_vconn_swap_discovery)(struct tcpc_dev *dev);
|
|
};
|
|
|
|
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,
|
|
enum tcpm_transmit_type rx_sop_type);
|
|
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);
|
|
void tcpm_port_clean(struct tcpm_port *port);
|
|
bool tcpm_port_is_toggling(struct tcpm_port *port);
|
|
void tcpm_port_error_recovery(struct tcpm_port *port);
|
|
|
|
#endif /* __LINUX_USB_TCPM_H */
|