linux/include/linux/usb/pd_vdo.h

/* SPDX-License-Identifier: GPL-2.0-or-later */
/*
 * Copyright 2015-2017 Google, Inc
 */

#ifndef __LINUX_USB_PD_VDO_H
#define __LINUX_USB_PD_VDO_H

#include "pd.h"
#include <linux/bitfield.h>

/*
 * VDO : Vendor Defined Message Object
 * VDM object is minimum of VDM header + 6 additional data objects.
 */

#define VDO_MAX_OBJECTS
#define VDO_MAX_SIZE

/*
 * VDM header
 * ----------
 * <31:16>  :: SVID
 * <15>     :: VDM type ( 1b == structured, 0b == unstructured )
 * <14:13>  :: Structured VDM version
 * <12:11>  :: reserved
 * <10:8>   :: object position (1-7 valid ... used for enter/exit mode only)
 * <7:6>    :: command type (SVDM only?)
 * <5>      :: reserved (SVDM), command type (UVDM)
 * <4:0>    :: command
 */
#define VDO(vid, type, ver, custom)

#define VDO_SVDM_TYPE
#define VDO_SVDM_VERS(x)
#define VDO_OPOS(x)
#define VDO_CMDT(x)
#define VDO_SVDM_VERS_MASK
#define VDO_OPOS_MASK
#define VDO_CMDT_MASK

#define CMDT_INIT
#define CMDT_RSP_ACK
#define CMDT_RSP_NAK
#define CMDT_RSP_BUSY

/* reserved for SVDM ... for Google UVDM */
#define VDO_SRC_INITIATOR
#define VDO_SRC_RESPONDER

#define CMD_DISCOVER_IDENT
#define CMD_DISCOVER_SVID
#define CMD_DISCOVER_MODES
#define CMD_ENTER_MODE
#define CMD_EXIT_MODE
#define CMD_ATTENTION

#define VDO_CMD_VENDOR(x)

/* ChromeOS specific commands */
#define VDO_CMD_VERSION
#define VDO_CMD_SEND_INFO
#define VDO_CMD_READ_INFO
#define VDO_CMD_REBOOT
#define VDO_CMD_FLASH_ERASE
#define VDO_CMD_FLASH_WRITE
#define VDO_CMD_ERASE_SIG
#define VDO_CMD_PING_ENABLE
#define VDO_CMD_CURRENT
#define VDO_CMD_FLIP
#define VDO_CMD_GET_LOG
#define VDO_CMD_CCD_EN

#define PD_VDO_VID(vdo)
#define PD_VDO_SVDM(vdo)
#define PD_VDO_SVDM_VER(vdo)
#define PD_VDO_OPOS(vdo)
#define PD_VDO_CMD(vdo)
#define PD_VDO_CMDT(vdo)

/*
 * SVDM Identity request -> response
 *
 * Request is simply properly formatted SVDM header
 *
 * Response is 4 data objects for Power Delivery 2.0 and Passive Cables for
 * Power Delivery 3.0. Active Cables in Power Delivery 3.0 have 5 data objects.
 * [0] :: SVDM header
 * [1] :: Identitiy header
 * [2] :: Cert Stat VDO
 * [3] :: (Product | Cable) VDO
 * [4] :: Cable VDO 1
 * [4] :: AMA VDO
 * [5] :: Cable VDO 2
 *
 */
#define VDO_INDEX_HDR
#define VDO_INDEX_IDH
#define VDO_INDEX_CSTAT
#define VDO_INDEX_CABLE
#define VDO_INDEX_PRODUCT
#define VDO_INDEX_AMA
#define VDO_INDEX_CABLE_1
#define VDO_INDEX_CABLE_2

/*
 * SVDM Identity Header
 * --------------------
 * <31>     :: data capable as a USB host
 * <30>     :: data capable as a USB device
 * <29:27>  :: product type (UFP / Cable / VPD)
 * <26>     :: modal operation supported (1b == yes)
 * <25:23>  :: product type (DFP) (SVDM version 2.0+ only; set to zero in version 1.0)
 * <22:21>  :: connector type (SVDM version 2.0+ only; set to zero in version 1.0)
 * <20:16>  :: Reserved, Shall be set to zero
 * <15:0>   :: USB-IF assigned VID for this cable vendor
 */

/* PD Rev2.0 definition */
#define IDH_PTYPE_UNDEF

/* SOP Product Type (UFP) */
#define IDH_PTYPE_NOT_UFP
#define IDH_PTYPE_HUB
#define IDH_PTYPE_PERIPH
#define IDH_PTYPE_PSD
#define IDH_PTYPE_AMA

/* SOP' Product Type (Cable Plug / VPD) */
#define IDH_PTYPE_NOT_CABLE
#define IDH_PTYPE_PCABLE
#define IDH_PTYPE_ACABLE
#define IDH_PTYPE_VPD

/* SOP Product Type (DFP) */
#define IDH_PTYPE_NOT_DFP
#define IDH_PTYPE_DFP_HUB
#define IDH_PTYPE_DFP_HOST
#define IDH_PTYPE_DFP_PB

/* ID Header Mask */
#define IDH_DFP_MASK
#define IDH_CONN_MASK

#define VDO_IDH(usbh, usbd, ufp_cable, is_modal, dfp, conn, vid)

#define PD_IDH_PTYPE(vdo)
#define PD_IDH_VID(vdo)
#define PD_IDH_MODAL_SUPP(vdo)
#define PD_IDH_DFP_PTYPE(vdo)
#define PD_IDH_CONN_TYPE(vdo)
#define PD_IDH_HOST_SUPP(vdo)

/*
 * Cert Stat VDO
 * -------------
 * <31:0>  : USB-IF assigned XID for this cable
 */
#define PD_CSTAT_XID(vdo)
#define VDO_CERT(xid)

/*
 * Product VDO
 * -----------
 * <31:16> : USB Product ID
 * <15:0>  : USB bcdDevice
 */
#define VDO_PRODUCT(pid, bcd)
#define PD_PRODUCT_PID(vdo)

/*
 * UFP VDO (PD Revision 3.0+ only)
 * --------
 * <31:29> :: UFP VDO version
 * <28>    :: Reserved
 * <27:24> :: Device capability
 * <23:22> :: Connector type (10b == receptacle, 11b == captive plug)
 * <21:11> :: Reserved
 * <10:8>  :: Vconn power (AMA only)
 * <7>     :: Vconn required (AMA only, 0b == no, 1b == yes)
 * <6>     :: Vbus required (AMA only, 0b == yes, 1b == no)
 * <5:3>   :: Alternate modes
 * <2:0>   :: USB highest speed
 */
#define PD_VDO_UFP_DEVCAP(vdo)

/* UFP VDO Version */
#define UFP_VDO_VER1_2

/* Device Capability */
#define DEV_USB2_CAPABLE
#define DEV_USB2_BILLBOARD
#define DEV_USB3_CAPABLE
#define DEV_USB4_CAPABLE

/* Connector Type */
#define UFP_RECEPTACLE
#define UFP_CAPTIVE

/* Vconn Power (AMA only, set to AMA_VCONN_NOT_REQ if Vconn is not required) */
#define AMA_VCONN_PWR_1W
#define AMA_VCONN_PWR_1W5
#define AMA_VCONN_PWR_2W
#define AMA_VCONN_PWR_3W
#define AMA_VCONN_PWR_4W
#define AMA_VCONN_PWR_5W
#define AMA_VCONN_PWR_6W

/* Vconn Required (AMA only) */
#define AMA_VCONN_NOT_REQ
#define AMA_VCONN_REQ

/* Vbus Required (AMA only) */
#define AMA_VBUS_REQ
#define AMA_VBUS_NOT_REQ

/* Alternate Modes */
#define UFP_ALTMODE_NOT_SUPP
#define UFP_ALTMODE_TBT3
#define UFP_ALTMODE_RECFG
#define UFP_ALTMODE_NO_RECFG

/* USB Highest Speed */
#define UFP_USB2_ONLY
#define UFP_USB32_GEN1
#define UFP_USB32_4_GEN2
#define UFP_USB4_GEN3

#define VDO_UFP(ver, cap, conn, vcpwr, vcr, vbr, alt, spd)

/*
 * DFP VDO (PD Revision 3.0+ only)
 * --------
 * <31:29> :: DFP VDO version
 * <28:27> :: Reserved
 * <26:24> :: Host capability
 * <23:22> :: Connector type (10b == receptacle, 11b == captive plug)
 * <21:5>  :: Reserved
 * <4:0>   :: Port number
 */
#define PD_VDO_DFP_HOSTCAP(vdo)

#define DFP_VDO_VER1_1
#define HOST_USB2_CAPABLE
#define HOST_USB3_CAPABLE
#define HOST_USB4_CAPABLE
#define DFP_RECEPTACLE
#define DFP_CAPTIVE

#define VDO_DFP(ver, cap, conn, pnum)

/*
 * Cable VDO (for both Passive and Active Cable VDO in PD Rev2.0)
 * ---------
 * <31:28> :: Cable HW version
 * <27:24> :: Cable FW version
 * <23:20> :: Reserved, Shall be set to zero
 * <19:18> :: type-C to Type-A/B/C/Captive (00b == A, 01 == B, 10 == C, 11 == Captive)
 * <17>    :: Reserved, Shall be set to zero
 * <16:13> :: cable latency (0001 == <10ns(~1m length))
 * <12:11> :: cable termination type (11b == both ends active VCONN req)
 * <10>    :: SSTX1 Directionality support (0b == fixed, 1b == cfgable)
 * <9>     :: SSTX2 Directionality support
 * <8>     :: SSRX1 Directionality support
 * <7>     :: SSRX2 Directionality support
 * <6:5>   :: Vbus current handling capability (01b == 3A, 10b == 5A)
 * <4>     :: Vbus through cable (0b == no, 1b == yes)
 * <3>     :: SOP" controller present? (0b == no, 1b == yes)
 * <2:0>   :: USB SS Signaling support
 *
 * Passive Cable VDO (PD Rev3.0+)
 * ---------
 * <31:28> :: Cable HW version
 * <27:24> :: Cable FW version
 * <23:21> :: VDO version
 * <20>    :: Reserved, Shall be set to zero
 * <19:18> :: Type-C to Type-C/Captive (10b == C, 11b == Captive)
 * <17>    :: Reserved, Shall be set to zero
 * <16:13> :: cable latency (0001 == <10ns(~1m length))
 * <12:11> :: cable termination type (10b == Vconn not req, 01b == Vconn req)
 * <10:9>  :: Maximum Vbus voltage (00b == 20V, 01b == 30V, 10b == 40V, 11b == 50V)
 * <8:7>   :: Reserved, Shall be set to zero
 * <6:5>   :: Vbus current handling capability (01b == 3A, 10b == 5A)
 * <4:3>   :: Reserved, Shall be set to zero
 * <2:0>   :: USB highest speed
 *
 * Active Cable VDO 1 (PD Rev3.0+)
 * ---------
 * <31:28> :: Cable HW version
 * <27:24> :: Cable FW version
 * <23:21> :: VDO version
 * <20>    :: Reserved, Shall be set to zero
 * <19:18> :: Connector type (10b == C, 11b == Captive)
 * <17>    :: Reserved, Shall be set to zero
 * <16:13> :: cable latency (0001 == <10ns(~1m length))
 * <12:11> :: cable termination type (10b == one end active, 11b == both ends active VCONN req)
 * <10:9>  :: Maximum Vbus voltage (00b == 20V, 01b == 30V, 10b == 40V, 11b == 50V)
 * <8>     :: SBU supported (0b == supported, 1b == not supported)
 * <7>     :: SBU type (0b == passive, 1b == active)
 * <6:5>   :: Vbus current handling capability (01b == 3A, 10b == 5A)
 * <4>     :: Vbus through cable (0b == no, 1b == yes)
 * <3>     :: SOP" controller present? (0b == no, 1b == yes)
 * <2:0>   :: USB highest speed
 */
/* Cable VDO Version */
#define CABLE_VDO_VER1_0
#define CABLE_VDO_VER1_3

/* Connector Type (_ATYPE and _BTYPE are for PD Rev2.0 only) */
#define CABLE_ATYPE
#define CABLE_BTYPE
#define CABLE_CTYPE
#define CABLE_CAPTIVE

/* Cable Latency */
#define CABLE_LATENCY_1M
#define CABLE_LATENCY_2M
#define CABLE_LATENCY_3M
#define CABLE_LATENCY_4M
#define CABLE_LATENCY_5M
#define CABLE_LATENCY_6M
#define CABLE_LATENCY_7M
#define CABLE_LATENCY_7M_PLUS

/* Cable Termination Type */
#define PCABLE_VCONN_NOT_REQ
#define PCABLE_VCONN_REQ
#define ACABLE_ONE_END
#define ACABLE_BOTH_END

/* Maximum Vbus Voltage */
#define CABLE_MAX_VBUS_20V
#define CABLE_MAX_VBUS_30V
#define CABLE_MAX_VBUS_40V
#define CABLE_MAX_VBUS_50V

/* Active Cable SBU Supported/Type */
#define ACABLE_SBU_SUPP
#define ACABLE_SBU_NOT_SUPP
#define ACABLE_SBU_PASSIVE
#define ACABLE_SBU_ACTIVE

/* Vbus Current Handling Capability */
#define CABLE_CURR_DEF
#define CABLE_CURR_3A
#define CABLE_CURR_5A

/* USB SuperSpeed Signaling Support (PD Rev2.0) */
#define CABLE_USBSS_U2_ONLY
#define CABLE_USBSS_U31_GEN1
#define CABLE_USBSS_U31_GEN2

/* USB Highest Speed */
#define CABLE_USB2_ONLY
#define CABLE_USB32_GEN1
#define CABLE_USB32_4_GEN2
#define CABLE_USB4_GEN3

#define VDO_CABLE(hw, fw, cbl, lat, term, tx1d, tx2d, rx1d, rx2d, cur, vps, sopp, usbss)
#define VDO_PCABLE(hw, fw, ver, conn, lat, term, vbm, cur, spd)
#define VDO_ACABLE1(hw, fw, ver, conn, lat, term, vbm, sbu, sbut, cur, vbt, sopp, spd)

#define VDO_TYPEC_CABLE_SPEED(vdo)
#define VDO_TYPEC_CABLE_TYPE(vdo)

/*
 * Active Cable VDO 2
 * ---------
 * <31:24> :: Maximum operating temperature
 * <23:16> :: Shutdown temperature
 * <15>    :: Reserved, Shall be set to zero
 * <14:12> :: U3/CLd power
 * <11>    :: U3 to U0 transition mode (0b == direct, 1b == through U3S)
 * <10>    :: Physical connection (0b == copper, 1b == optical)
 * <9>     :: Active element (0b == redriver, 1b == retimer)
 * <8>     :: USB4 supported (0b == yes, 1b == no)
 * <7:6>   :: USB2 hub hops consumed
 * <5>     :: USB2 supported (0b == yes, 1b == no)
 * <4>     :: USB3.2 supported (0b == yes, 1b == no)
 * <3>     :: USB lanes supported (0b == one lane, 1b == two lanes)
 * <2>     :: Optically isolated active cable (0b == no, 1b == yes)
 * <1>     :: Reserved, Shall be set to zero
 * <0>     :: USB gen (0b == gen1, 1b == gen2+)
 */
/* U3/CLd Power*/
#define ACAB2_U3_CLD_10MW_PLUS
#define ACAB2_U3_CLD_10MW
#define ACAB2_U3_CLD_5MW
#define ACAB2_U3_CLD_1MW
#define ACAB2_U3_CLD_500UW
#define ACAB2_U3_CLD_200UW
#define ACAB2_U3_CLD_50UW

/* Other Active Cable VDO 2 Fields */
#define ACAB2_U3U0_DIRECT
#define ACAB2_U3U0_U3S
#define ACAB2_PHY_COPPER
#define ACAB2_PHY_OPTICAL
#define ACAB2_REDRIVER
#define ACAB2_RETIMER
#define ACAB2_USB4_SUPP
#define ACAB2_USB4_NOT_SUPP
#define ACAB2_USB2_SUPP
#define ACAB2_USB2_NOT_SUPP
#define ACAB2_USB32_SUPP
#define ACAB2_USB32_NOT_SUPP
#define ACAB2_LANES_ONE
#define ACAB2_LANES_TWO
#define ACAB2_OPT_ISO_NO
#define ACAB2_OPT_ISO_YES
#define ACAB2_GEN_1
#define ACAB2_GEN_2_PLUS

#define VDO_ACABLE2(mtemp, stemp, u3p, trans, phy, ele, u4, hops, u2, u32, lane, iso, gen)

/*
 * AMA VDO (PD Rev2.0)
 * ---------
 * <31:28> :: Cable HW version
 * <27:24> :: Cable FW version
 * <23:12> :: Reserved, Shall be set to zero
 * <11>    :: SSTX1 Directionality support (0b == fixed, 1b == cfgable)
 * <10>    :: SSTX2 Directionality support
 * <9>     :: SSRX1 Directionality support
 * <8>     :: SSRX2 Directionality support
 * <7:5>   :: Vconn power
 * <4>     :: Vconn power required
 * <3>     :: Vbus power required
 * <2:0>   :: USB SS Signaling support
 */
#define VDO_AMA(hw, fw, tx1d, tx2d, rx1d, rx2d, vcpwr, vcr, vbr, usbss)

#define PD_VDO_AMA_VCONN_REQ(vdo)
#define PD_VDO_AMA_VBUS_REQ(vdo)

#define AMA_USBSS_U2_ONLY
#define AMA_USBSS_U31_GEN1
#define AMA_USBSS_U31_GEN2
#define AMA_USBSS_BBONLY

/*
 * VPD VDO
 * ---------
 * <31:28> :: HW version
 * <27:24> :: FW version
 * <23:21> :: VDO version
 * <20:17> :: Reserved, Shall be set to zero
 * <16:15> :: Maximum Vbus voltage (00b == 20V, 01b == 30V, 10b == 40V, 11b == 50V)
 * <14>    :: Charge through current support (0b == 3A, 1b == 5A)
 * <13>    :: Reserved, Shall be set to zero
 * <12:7>  :: Vbus impedance
 * <6:1>   :: Ground impedance
 * <0>     :: Charge through support (0b == no, 1b == yes)
 */
#define VPD_VDO_VER1_0
#define VPD_MAX_VBUS_20V
#define VPD_MAX_VBUS_30V
#define VPD_MAX_VBUS_40V
#define VPD_MAX_VBUS_50V
#define VPDCT_CURR_3A
#define VPDCT_CURR_5A
#define VPDCT_NOT_SUPP
#define VPDCT_SUPP

#define VDO_VPD(hw, fw, ver, vbm, curr, vbi, gi, ct)

/*
 * SVDM Discover SVIDs request -> response
 *
 * Request is properly formatted VDM Header with discover SVIDs command.
 * Response is a set of SVIDs of all supported SVIDs with all zero's to
 * mark the end of SVIDs.  If more than 12 SVIDs are supported command SHOULD be
 * repeated.
 */
#define VDO_SVID(svid0, svid1)
#define PD_VDO_SVID_SVID0(vdo)
#define PD_VDO_SVID_SVID1(vdo)

/* USB-IF SIDs */
#define USB_SID_PD
#define USB_SID_DISPLAYPORT
#define USB_SID_MHL

/* VDM command timeouts (in ms) */

#define PD_T_VDM_UNSTRUCTURED
#define PD_T_VDM_BUSY
#define PD_T_VDM_WAIT_MODE_E
#define PD_T_VDM_SNDR_RSP
#define PD_T_VDM_E_MODE
#define PD_T_VDM_RCVR_RSP

#endif /* __LINUX_USB_PD_VDO_H */