Zephyr API Documentation  3.6.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
USB Type-C Port Controller API

USB Type-C Port Controller API. More...

Data Structures

struct  tcpc_chip_info
 TCPC Chip Information. More...
 
struct  tcpc_driver_api
 

Typedefs

typedef int(* tcpc_vconn_control_cb_t) (const struct device *dev, enum tc_cc_polarity pol, bool enable)
 
typedef int(* tcpc_vconn_discharge_cb_t) (const struct device *dev, enum tc_cc_polarity pol, bool enable)
 
typedef void(* tcpc_alert_handler_cb_t) (const struct device *dev, void *data, enum tcpc_alert alert)
 

Enumerations

enum  tcpc_alert {
  TCPC_ALERT_CC_STATUS , TCPC_ALERT_POWER_STATUS , TCPC_ALERT_MSG_STATUS , TCPC_ALERT_HARD_RESET_RECEIVED ,
  TCPC_ALERT_TRANSMIT_MSG_FAILED , TCPC_ALERT_TRANSMIT_MSG_DISCARDED , TCPC_ALERT_TRANSMIT_MSG_SUCCESS , TCPC_ALERT_VBUS_ALARM_HI ,
  TCPC_ALERT_VBUS_ALARM_LO , TCPC_ALERT_FAULT_STATUS , TCPC_ALERT_RX_BUFFER_OVERFLOW , TCPC_ALERT_VBUS_SNK_DISCONNECT ,
  TCPC_ALERT_BEGINNING_MSG_STATUS , TCPC_ALERT_EXTENDED_STATUS , TCPC_ALERT_EXTENDED , TCPC_ALERT_VENDOR_DEFINED
}
 TCPC Alert bits. More...
 
enum  tcpc_status_reg {
  TCPC_CC_STATUS , TCPC_POWER_STATUS , TCPC_FAULT_STATUS , TCPC_EXTENDED_STATUS ,
  TCPC_EXTENDED_ALERT_STATUS , TCPC_VENDOR_DEFINED_STATUS
}
 TCPC Status register. More...
 

Functions

static int tcpc_is_cc_rp (enum tc_cc_voltage_state cc)
 Returns whether the sink has detected a Rp resistor on the other side.
 
static int tcpc_is_cc_open (enum tc_cc_voltage_state cc1, enum tc_cc_voltage_state cc2)
 Returns true if both CC lines are completely open.
 
static int tcpc_is_cc_snk_dbg_acc (enum tc_cc_voltage_state cc1, enum tc_cc_voltage_state cc2)
 Returns true if we detect the port partner is a snk debug accessory.
 
static int tcpc_is_cc_src_dbg_acc (enum tc_cc_voltage_state cc1, enum tc_cc_voltage_state cc2)
 Returns true if we detect the port partner is a src debug accessory.
 
static int tcpc_is_cc_audio_acc (enum tc_cc_voltage_state cc1, enum tc_cc_voltage_state cc2)
 Returns true if the port partner is an audio accessory.
 
static int tcpc_is_cc_at_least_one_rd (enum tc_cc_voltage_state cc1, enum tc_cc_voltage_state cc2)
 Returns true if the port partner is presenting at least one Rd.
 
static int tcpc_is_cc_only_one_rd (enum tc_cc_voltage_state cc1, enum tc_cc_voltage_state cc2)
 Returns true if the port partner is presenting Rd on only one CC line.
 
static int tcpc_init (const struct device *dev)
 Initializes the TCPC.
 
static int tcpc_get_cc (const struct device *dev, enum tc_cc_voltage_state *cc1, enum tc_cc_voltage_state *cc2)
 Reads the status of the CC lines.
 
static int tcpc_select_rp_value (const struct device *dev, enum tc_rp_value rp)
 Sets the value of CC pull up resistor used when operating as a Source.
 
static int tcpc_get_rp_value (const struct device *dev, enum tc_rp_value *rp)
 Gets the value of the CC pull up resistor used when operating as a Source.
 
static int tcpc_set_cc (const struct device *dev, enum tc_cc_pull pull)
 Sets the CC pull resistor and sets the role as either Source or Sink.
 
static void tcpc_set_vconn_cb (const struct device *dev, tcpc_vconn_control_cb_t vconn_cb)
 Sets a callback that can enable or disable VCONN if the TCPC is unable to or the system is configured in a way that does not use the VCONN control capabilities of the TCPC.
 
static void tcpc_set_vconn_discharge_cb (const struct device *dev, tcpc_vconn_discharge_cb_t cb)
 Sets a callback that can enable or discharge VCONN if the TCPC is unable to or the system is configured in a way that does not use the VCONN control capabilities of the TCPC.
 
static int tcpc_vconn_discharge (const struct device *dev, bool enable)
 Discharges VCONN.
 
static int tcpc_set_vconn (const struct device *dev, bool enable)
 Enables or disables VCONN.
 
static int tcpc_set_roles (const struct device *dev, enum tc_power_role power_role, enum tc_data_role data_role)
 Sets the Power and Data Role of the PD message header.
 
static int tcpc_get_rx_pending_msg (const struct device *dev, struct pd_msg *buf)
 Retrieves the Power Delivery message from the TCPC.
 
static int tcpc_set_rx_enable (const struct device *dev, bool enable)
 Enables the reception of SOP* message types.
 
static int tcpc_set_cc_polarity (const struct device *dev, enum tc_cc_polarity polarity)
 Sets the polarity of the CC lines.
 
static int tcpc_transmit_data (const struct device *dev, struct pd_msg *msg)
 Transmits a Power Delivery message.
 
static int tcpc_dump_std_reg (const struct device *dev)
 Dump a set of TCPC registers.
 
static int tcpc_set_alert_handler_cb (const struct device *dev, tcpc_alert_handler_cb_t handler, void *data)
 Sets the alert function that's called when an interrupt is triggered due to an alert bit.
 
static int tcpc_get_status_register (const struct device *dev, enum tcpc_status_reg reg, int32_t *status)
 Gets a status register.
 
static int tcpc_clear_status_register (const struct device *dev, enum tcpc_status_reg reg, uint32_t mask)
 Clears a TCPC status register.
 
static int tcpc_mask_status_register (const struct device *dev, enum tcpc_status_reg reg, uint32_t mask)
 Sets the mask of a TCPC status register.
 
static int tcpc_set_debug_accessory (const struct device *dev, bool enable)
 Manual control of TCPC DebugAccessory control.
 
static int tcpc_set_debug_detach (const struct device *dev)
 Detach from a debug connection.
 
static int tcpc_set_drp_toggle (const struct device *dev, bool enable)
 Enable TCPC auto dual role toggle.
 
static int tcpc_get_snk_ctrl (const struct device *dev)
 Queries the current sinking state of the TCPC.
 
static int tcpc_get_src_ctrl (const struct device *dev)
 Queries the current sourcing state of the TCPC.
 
static int tcpc_set_bist_test_mode (const struct device *dev, bool enable)
 Controls the BIST Mode of the TCPC.
 
static int tcpc_get_chip_info (const struct device *dev, struct tcpc_chip_info *chip_info)
 Gets the TCPC firmware version.
 
static int tcpc_set_low_power_mode (const struct device *dev, bool enable)
 Instructs the TCPC to enter or exit low power mode.
 
static int tcpc_sop_prime_enable (const struct device *dev, bool enable)
 Enables the reception of SOP Prime messages.
 

Detailed Description

USB Type-C Port Controller API.

Since
3.1
Version
0.1.0

Typedef Documentation

◆ tcpc_alert_handler_cb_t

typedef void(* tcpc_alert_handler_cb_t) (const struct device *dev, void *data, enum tcpc_alert alert)

◆ tcpc_vconn_control_cb_t

typedef int(* tcpc_vconn_control_cb_t) (const struct device *dev, enum tc_cc_polarity pol, bool enable)

◆ tcpc_vconn_discharge_cb_t

typedef int(* tcpc_vconn_discharge_cb_t) (const struct device *dev, enum tc_cc_polarity pol, bool enable)

Enumeration Type Documentation

◆ tcpc_alert

enum tcpc_alert

#include <zephyr/drivers/usb_c/usbc_tcpc.h>

TCPC Alert bits.

Enumerator
TCPC_ALERT_CC_STATUS 

CC status changed.

TCPC_ALERT_POWER_STATUS 

Power status changed.

TCPC_ALERT_MSG_STATUS 

Receive Buffer register changed.

TCPC_ALERT_HARD_RESET_RECEIVED 

Received Hard Reset message.

TCPC_ALERT_TRANSMIT_MSG_FAILED 

SOP* message transmission not successful.

TCPC_ALERT_TRANSMIT_MSG_DISCARDED 

Reset or SOP* message transmission not sent due to an incoming receive message.

TCPC_ALERT_TRANSMIT_MSG_SUCCESS 

Reset or SOP* message transmission successful.

TCPC_ALERT_VBUS_ALARM_HI 

A high-voltage alarm has occurred.

TCPC_ALERT_VBUS_ALARM_LO 

A low-voltage alarm has occurred.

TCPC_ALERT_FAULT_STATUS 

A fault has occurred.

Read the FAULT_STATUS register

TCPC_ALERT_RX_BUFFER_OVERFLOW 

TCPC RX buffer has overflowed.

TCPC_ALERT_VBUS_SNK_DISCONNECT 

The TCPC in Attached.SNK state has detected a sink disconnect.

TCPC_ALERT_BEGINNING_MSG_STATUS 

Receive buffer register changed.

TCPC_ALERT_EXTENDED_STATUS 

Extended status changed.

TCPC_ALERT_EXTENDED 

An extended interrupt event has occurred.

Read the alert_extended register

TCPC_ALERT_VENDOR_DEFINED 

A vendor defined alert has been detected.

◆ tcpc_status_reg

#include <zephyr/drivers/usb_c/usbc_tcpc.h>

TCPC Status register.

Enumerator
TCPC_CC_STATUS 

The CC Status register.

TCPC_POWER_STATUS 

The Power Status register.

TCPC_FAULT_STATUS 

The Fault Status register.

TCPC_EXTENDED_STATUS 

The Extended Status register.

TCPC_EXTENDED_ALERT_STATUS 

The Extended Alert Status register.

TCPC_VENDOR_DEFINED_STATUS 

The Vendor Defined Status register.

Function Documentation

◆ tcpc_clear_status_register()

static int tcpc_clear_status_register ( const struct device dev,
enum tcpc_status_reg  reg,
uint32_t  mask 
)
inlinestatic

#include <zephyr/drivers/usb_c/usbc_tcpc.h>

Clears a TCPC status register.

Parameters
devRuntime device structure
regThe status register to read
maskA bit mask of the status register to clear. A status bit is cleared when it's set to 1.
Return values
0on success
-EIOon failure
-ENOSYSif not implemented

◆ tcpc_dump_std_reg()

static int tcpc_dump_std_reg ( const struct device dev)
inlinestatic

#include <zephyr/drivers/usb_c/usbc_tcpc.h>

Dump a set of TCPC registers.

Parameters
devRuntime device structure
Return values
0on success
-EIOon failure
-ENOSYSif not implemented

◆ tcpc_get_cc()

static int tcpc_get_cc ( const struct device dev,
enum tc_cc_voltage_state cc1,
enum tc_cc_voltage_state cc2 
)
inlinestatic

#include <zephyr/drivers/usb_c/usbc_tcpc.h>

Reads the status of the CC lines.

Parameters
devRuntime device structure
cc1A pointer where the CC1 status is written
cc2A pointer where the CC2 status is written
Return values
0on success
-EIOon failure
-ENOSYSif not implemented

◆ tcpc_get_chip_info()

static int tcpc_get_chip_info ( const struct device dev,
struct tcpc_chip_info chip_info 
)
inlinestatic

#include <zephyr/drivers/usb_c/usbc_tcpc.h>

Gets the TCPC firmware version.

Parameters
devRuntime device structure
chip_infoPointer to TCPC chip info where the version is stored
Return values
0on success
-EIOon failure
-ENOSYSif not implemented

◆ tcpc_get_rp_value()

static int tcpc_get_rp_value ( const struct device dev,
enum tc_rp_value rp 
)
inlinestatic

#include <zephyr/drivers/usb_c/usbc_tcpc.h>

Gets the value of the CC pull up resistor used when operating as a Source.

Parameters
devRuntime device structure
rppointer where the value of the Pull-Up Resistor is stored
Return values
0on success
-ENOSYS
-EIOon failure

◆ tcpc_get_rx_pending_msg()

static int tcpc_get_rx_pending_msg ( const struct device dev,
struct pd_msg buf 
)
inlinestatic

#include <zephyr/drivers/usb_c/usbc_tcpc.h>

Retrieves the Power Delivery message from the TCPC.

If buf is NULL, then only the status is returned, where 0 means there is a message pending and -ENODATA means there is no pending message.

Parameters
devRuntime device structure
bufpointer where the pd_buf pointer is written, NULL if only checking the status
Return values
Greateror equal to 0 is the number of bytes received if buf parameter is provided
0if there is a message pending and buf parameter is NULL
-EIOon failure
-ENODATAif no message is pending

◆ tcpc_get_snk_ctrl()

static int tcpc_get_snk_ctrl ( const struct device dev)
inlinestatic

#include <zephyr/drivers/usb_c/usbc_tcpc.h>

Queries the current sinking state of the TCPC.

Parameters
devRuntime device structure
Return values
trueif sinking power
falseif not sinking power
-ENOSYSif not implemented

◆ tcpc_get_src_ctrl()

static int tcpc_get_src_ctrl ( const struct device dev)
inlinestatic

#include <zephyr/drivers/usb_c/usbc_tcpc.h>

Queries the current sourcing state of the TCPC.

Parameters
devRuntime device structure
Return values
trueif sourcing power
falseif not sourcing power
-ENOSYSif not implemented

◆ tcpc_get_status_register()

static int tcpc_get_status_register ( const struct device dev,
enum tcpc_status_reg  reg,
int32_t status 
)
inlinestatic

#include <zephyr/drivers/usb_c/usbc_tcpc.h>

Gets a status register.

Parameters
devRuntime device structure
regThe status register to read
statusPointer where the status is stored
Return values
0on success
-EIOon failure
-ENOSYSif not implemented

◆ tcpc_init()

static int tcpc_init ( const struct device dev)
inlinestatic

#include <zephyr/drivers/usb_c/usbc_tcpc.h>

Initializes the TCPC.

Parameters
devRuntime device structure
Return values
0on success
-EIOon failure
-EAGAINif initialization should be postponed

◆ tcpc_is_cc_at_least_one_rd()

static int tcpc_is_cc_at_least_one_rd ( enum tc_cc_voltage_state  cc1,
enum tc_cc_voltage_state  cc2 
)
inlinestatic

#include <zephyr/drivers/usb_c/usbc_tcpc.h>

Returns true if the port partner is presenting at least one Rd.

◆ tcpc_is_cc_audio_acc()

static int tcpc_is_cc_audio_acc ( enum tc_cc_voltage_state  cc1,
enum tc_cc_voltage_state  cc2 
)
inlinestatic

#include <zephyr/drivers/usb_c/usbc_tcpc.h>

Returns true if the port partner is an audio accessory.

◆ tcpc_is_cc_only_one_rd()

static int tcpc_is_cc_only_one_rd ( enum tc_cc_voltage_state  cc1,
enum tc_cc_voltage_state  cc2 
)
inlinestatic

#include <zephyr/drivers/usb_c/usbc_tcpc.h>

Returns true if the port partner is presenting Rd on only one CC line.

◆ tcpc_is_cc_open()

static int tcpc_is_cc_open ( enum tc_cc_voltage_state  cc1,
enum tc_cc_voltage_state  cc2 
)
inlinestatic

#include <zephyr/drivers/usb_c/usbc_tcpc.h>

Returns true if both CC lines are completely open.

◆ tcpc_is_cc_rp()

static int tcpc_is_cc_rp ( enum tc_cc_voltage_state  cc)
inlinestatic

#include <zephyr/drivers/usb_c/usbc_tcpc.h>

Returns whether the sink has detected a Rp resistor on the other side.

◆ tcpc_is_cc_snk_dbg_acc()

static int tcpc_is_cc_snk_dbg_acc ( enum tc_cc_voltage_state  cc1,
enum tc_cc_voltage_state  cc2 
)
inlinestatic

#include <zephyr/drivers/usb_c/usbc_tcpc.h>

Returns true if we detect the port partner is a snk debug accessory.

◆ tcpc_is_cc_src_dbg_acc()

static int tcpc_is_cc_src_dbg_acc ( enum tc_cc_voltage_state  cc1,
enum tc_cc_voltage_state  cc2 
)
inlinestatic

#include <zephyr/drivers/usb_c/usbc_tcpc.h>

Returns true if we detect the port partner is a src debug accessory.

◆ tcpc_mask_status_register()

static int tcpc_mask_status_register ( const struct device dev,
enum tcpc_status_reg  reg,
uint32_t  mask 
)
inlinestatic

#include <zephyr/drivers/usb_c/usbc_tcpc.h>

Sets the mask of a TCPC status register.

Parameters
devRuntime device structure
regThe status register to read
maskA bit mask of the status register to mask. The status bit is masked if it's 0, else it's unmasked.
Return values
0on success
-EIOon failure
-ENOSYSif not implemented

◆ tcpc_select_rp_value()

static int tcpc_select_rp_value ( const struct device dev,
enum tc_rp_value  rp 
)
inlinestatic

#include <zephyr/drivers/usb_c/usbc_tcpc.h>

Sets the value of CC pull up resistor used when operating as a Source.

Parameters
devRuntime device structure
rpValue of the Pull-Up Resistor.
Return values
0on success
-ENOSYS
-EIOon failure

◆ tcpc_set_alert_handler_cb()

static int tcpc_set_alert_handler_cb ( const struct device dev,
tcpc_alert_handler_cb_t  handler,
void *  data 
)
inlinestatic

#include <zephyr/drivers/usb_c/usbc_tcpc.h>

Sets the alert function that's called when an interrupt is triggered due to an alert bit.

Calling this function enables the particular alert bit

Parameters
devRuntime device structure
handlerThe callback function called when the bit is set
datauser data passed to the callback
Return values
0on success
-EINVALon failure

◆ tcpc_set_bist_test_mode()

static int tcpc_set_bist_test_mode ( const struct device dev,
bool  enable 
)
inlinestatic

#include <zephyr/drivers/usb_c/usbc_tcpc.h>

Controls the BIST Mode of the TCPC.

It disables RX alerts while the mode is active.

Parameters
devRuntime device structure
enableThe TCPC enters BIST TEST Mode when true
Return values
0on success
-EIOon failure
-ENOSYSif not implemented

◆ tcpc_set_cc()

static int tcpc_set_cc ( const struct device dev,
enum tc_cc_pull  pull 
)
inlinestatic

#include <zephyr/drivers/usb_c/usbc_tcpc.h>

Sets the CC pull resistor and sets the role as either Source or Sink.

Parameters
devRuntime device structure
pullThe pull resistor to set
Return values
0on success
-EIOon failure

◆ tcpc_set_cc_polarity()

static int tcpc_set_cc_polarity ( const struct device dev,
enum tc_cc_polarity  polarity 
)
inlinestatic

#include <zephyr/drivers/usb_c/usbc_tcpc.h>

Sets the polarity of the CC lines.

Parameters
devRuntime device structure
polarityPolarity of the cc line
Return values
0on success
-EIOon failure

◆ tcpc_set_debug_accessory()

static int tcpc_set_debug_accessory ( const struct device dev,
bool  enable 
)
inlinestatic

#include <zephyr/drivers/usb_c/usbc_tcpc.h>

Manual control of TCPC DebugAccessory control.

Parameters
devRuntime device structure
enableEnable Debug Accessory when true, else it's disabled
Return values
0on success
-EIOon failure
-ENOSYSif not implemented

◆ tcpc_set_debug_detach()

static int tcpc_set_debug_detach ( const struct device dev)
inlinestatic

#include <zephyr/drivers/usb_c/usbc_tcpc.h>

Detach from a debug connection.

Parameters
devRuntime device structure
Return values
0on success
-EIOon failure
-ENOSYSif not implemented

◆ tcpc_set_drp_toggle()

static int tcpc_set_drp_toggle ( const struct device dev,
bool  enable 
)
inlinestatic

#include <zephyr/drivers/usb_c/usbc_tcpc.h>

Enable TCPC auto dual role toggle.

Parameters
devRuntime device structure
enableAuto dual role toggle is active when true, else it's disabled
Return values
0on success
-EIOon failure
-ENOSYSif not implemented

◆ tcpc_set_low_power_mode()

static int tcpc_set_low_power_mode ( const struct device dev,
bool  enable 
)
inlinestatic

#include <zephyr/drivers/usb_c/usbc_tcpc.h>

Instructs the TCPC to enter or exit low power mode.

Parameters
devRuntime device structure
enableThe TCPC enters low power mode when true, else it exits it
Return values
0on success
-EIOon failure
-ENOSYSif not implemented

◆ tcpc_set_roles()

static int tcpc_set_roles ( const struct device dev,
enum tc_power_role  power_role,
enum tc_data_role  data_role 
)
inlinestatic

#include <zephyr/drivers/usb_c/usbc_tcpc.h>

Sets the Power and Data Role of the PD message header.

This function only needs to be called once per data / power role change

Parameters
devRuntime device structure
power_rolecurrent power role
data_rolecurrent data role
Return values
0on success
-EIOon failure
-ENOSYSif not implemented

◆ tcpc_set_rx_enable()

static int tcpc_set_rx_enable ( const struct device dev,
bool  enable 
)
inlinestatic

#include <zephyr/drivers/usb_c/usbc_tcpc.h>

Enables the reception of SOP* message types.

Parameters
devRuntime device structure
enableEnable Power Delivery when true, else it's disabled
Return values
0on success
-EIOon failure
-ENOSYSif not implemented

◆ tcpc_set_vconn()

static int tcpc_set_vconn ( const struct device dev,
bool  enable 
)
inlinestatic

#include <zephyr/drivers/usb_c/usbc_tcpc.h>

Enables or disables VCONN.

This function uses the TCPC to measure VCONN if possible or calls the callback function set by tcpc_set_vconn_cb

Parameters
devRuntime device structure
enableVCONN is enabled when true, it's disabled
Return values
0on success
-EIOon failure
-ENOSYSif not implemented

◆ tcpc_set_vconn_cb()

static void tcpc_set_vconn_cb ( const struct device dev,
tcpc_vconn_control_cb_t  vconn_cb 
)
inlinestatic

#include <zephyr/drivers/usb_c/usbc_tcpc.h>

Sets a callback that can enable or disable VCONN if the TCPC is unable to or the system is configured in a way that does not use the VCONN control capabilities of the TCPC.

The callback is called in the tcpc_set_vconn function if vconn_cb isn't NULL

Parameters
devRuntime device structure
vconn_cbpointer to the callback function that controls vconn

◆ tcpc_set_vconn_discharge_cb()

static void tcpc_set_vconn_discharge_cb ( const struct device dev,
tcpc_vconn_discharge_cb_t  cb 
)
inlinestatic

#include <zephyr/drivers/usb_c/usbc_tcpc.h>

Sets a callback that can enable or discharge VCONN if the TCPC is unable to or the system is configured in a way that does not use the VCONN control capabilities of the TCPC.

The callback is called in the tcpc_vconn_discharge function if cb isn't NULL

Parameters
devRuntime device structure
cbpointer to the callback function that discharges vconn

◆ tcpc_sop_prime_enable()

static int tcpc_sop_prime_enable ( const struct device dev,
bool  enable 
)
inlinestatic

#include <zephyr/drivers/usb_c/usbc_tcpc.h>

Enables the reception of SOP Prime messages.

Parameters
devRuntime device structure
enableCan receive SOP Prime messages when true, else it can not
Return values
0on success
-EIOon failure
-ENOSYSif not implemented

◆ tcpc_transmit_data()

static int tcpc_transmit_data ( const struct device dev,
struct pd_msg msg 
)
inlinestatic

#include <zephyr/drivers/usb_c/usbc_tcpc.h>

Transmits a Power Delivery message.

Parameters
devRuntime device structure
msgPower Delivery message to transmit
Return values
0on success
-EIOon failure
-ENOSYSif not implemented

◆ tcpc_vconn_discharge()

static int tcpc_vconn_discharge ( const struct device dev,
bool  enable 
)
inlinestatic

#include <zephyr/drivers/usb_c/usbc_tcpc.h>

Discharges VCONN.

This function uses the TCPC to discharge VCONN if possible or calls the callback function set by tcpc_set_vconn_cb

Parameters
devRuntime device structure
enableVCONN discharge is enabled when true, it's disabled
Return values
0on success
-EIOon failure
-ENOSYSif not implemented