Zephyr API Documentation 4.0.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
tcpci_priv.h File Reference

Helper functions to use by the TCPCI-compliant drivers. More...

#include <stdint.h>
#include <zephyr/drivers/i2c.h>
#include <zephyr/usb_c/usbc.h>

Go to the source code of this file.

Data Structures

struct  tcpci_reg_dump_map
 Structure used to bind the register address to name in registers dump. More...
 

Macros

#define TCPCI_STD_REGS_SIZE   38
 Size of the array containing the standard registers used by tcpci dump command.
 

Functions

int tcpci_read_reg8 (const struct i2c_dt_spec *bus, uint8_t reg, uint8_t *value)
 Function to read the 8-bit register of TCPCI device.
 
int tcpci_write_reg8 (const struct i2c_dt_spec *bus, uint8_t reg, uint8_t value)
 Function to write a value to the 8-bit register of TCPCI device.
 
int tcpci_update_reg8 (const struct i2c_dt_spec *bus, uint8_t reg, uint8_t mask, uint8_t value)
 Function to read and update part of the 8-bit register of TCPCI device The function is NOT performing this operation atomically.
 
int tcpci_read_reg16 (const struct i2c_dt_spec *bus, uint8_t reg, uint16_t *value)
 Function to read the 16-bit register of TCPCI device.
 
int tcpci_write_reg16 (const struct i2c_dt_spec *bus, uint8_t reg, uint16_t value)
 Function to write a value to the 16-bit register of TCPCI device.
 
enum tcpc_alert tcpci_alert_reg_to_enum (uint16_t reg)
 Function that converts the TCPCI alert register to the tcpc_alert enum The hard reset value takes priority, where the rest are returned in the bit order from least significant to most significant.
 
int tcpci_tcpm_get_cc (const struct i2c_dt_spec *bus, enum tc_cc_voltage_state *cc1, enum tc_cc_voltage_state *cc2)
 Function that reads the CC status registers and converts read values to enums representing voltages state and partner detection status.
 
int tcpci_tcpm_get_chip_info (const struct i2c_dt_spec *bus, struct tcpc_chip_info *chip_info)
 Function to retrieve information about the TCPCI chip.
 
int tcpci_tcpm_dump_std_reg (const struct i2c_dt_spec *bus)
 Function to dump the standard TCPCI registers.
 
int tcpci_tcpm_set_bist_test_mode (const struct i2c_dt_spec *bus, bool enable)
 Function to enable or disable the BIST (Built-In Self-Test) mode.
 
int tcpci_tcpm_transmit_data (const struct i2c_dt_spec *bus, struct pd_msg *msg, const uint8_t retries)
 Function to transmit a PD (Power Delivery) message.
 
int tcpci_tcpm_select_rp_value (const struct i2c_dt_spec *bus, enum tc_rp_value rp)
 Function to select the Rp (Pull-up Resistor) value.
 
int tcpci_tcpm_get_rp_value (const struct i2c_dt_spec *bus, enum tc_rp_value *rp)
 Function to get the currently selected Rp value.
 
int tcpci_tcpm_set_cc (const struct i2c_dt_spec *bus, enum tc_cc_pull pull)
 Function to set the CC pull resistor and set the role as either Source or Sink.
 
int tcpci_tcpm_set_drp_toggle (const struct i2c_dt_spec *bus, bool enable)
 Function to enable or disable TCPC auto dual role toggle.
 
int tcpci_tcpm_set_roles (const struct i2c_dt_spec *bus, enum pd_rev_type pd_rev, enum tc_power_role power_role, enum tc_data_role data_role)
 Function to set the power and data role of the PD message header.
 
int tcpci_tcpm_set_rx_type (const struct i2c_dt_spec *bus, uint8_t type)
 Function to set the RX type.
 
int tcpci_tcpm_set_cc_polarity (const struct i2c_dt_spec *bus, enum tc_cc_polarity polarity)
 Function to set the polarity of the CC lines.
 
int tcpci_tcpm_set_vconn (const struct i2c_dt_spec *bus, bool enable)
 Function to enable or disable VCONN.
 
int tcpci_tcpm_get_status_register (const struct i2c_dt_spec *bus, enum tcpc_status_reg reg, uint16_t *status)
 Function to get the status of a specific TCPCI status register.
 
int tcpci_tcpm_clear_status_register (const struct i2c_dt_spec *bus, enum tcpc_status_reg reg, uint16_t mask)
 Function to clear specific bits in a TCPCI status register.
 
int tcpci_tcpm_mask_status_register (const struct i2c_dt_spec *bus, enum tcpc_status_reg reg, uint16_t mask)
 Function to set the mask of a TCPCI status register.
 

Variables

const struct tcpci_reg_dump_map tcpci_std_regs [38]
 Array containing the standard TCPCI registers list.
 

Detailed Description

Helper functions to use by the TCPCI-compliant drivers.

This file contains generic TCPCI functions that may be used by the drivers to TCPCI-compliant devices that want to implement vendor-specific functionality without the need to reimplement the TCPCI generic functionality and register operations.

Macro Definition Documentation

◆ TCPCI_STD_REGS_SIZE

#define TCPCI_STD_REGS_SIZE   38

Size of the array containing the standard registers used by tcpci dump command.

Function Documentation

◆ tcpci_alert_reg_to_enum()

enum tcpc_alert tcpci_alert_reg_to_enum ( uint16_t reg)

Function that converts the TCPCI alert register to the tcpc_alert enum The hard reset value takes priority, where the rest are returned in the bit order from least significant to most significant.

Parameters
regValue of the TCPCI alert register. This parameter must have value other than zero.
Returns
enum tcpc_alert Value of one of the flags being set in the alert register

◆ tcpci_read_reg16()

int tcpci_read_reg16 ( const struct i2c_dt_spec * bus,
uint8_t reg,
uint16_t * value )

Function to read the 16-bit register of TCPCI device.

Parameters
busI2C bus
regAddress of TCPCI register
valuePointer to variable that will store the register value
Returns
int Status of I2C operation, 0 in case of success

◆ tcpci_read_reg8()

int tcpci_read_reg8 ( const struct i2c_dt_spec * bus,
uint8_t reg,
uint8_t * value )

Function to read the 8-bit register of TCPCI device.

Parameters
busI2C bus
regAddress of TCPCI register
valuePointer to variable that will store the register value
Returns
int Status of I2C operation, 0 in case of success

◆ tcpci_tcpm_clear_status_register()

int tcpci_tcpm_clear_status_register ( const struct i2c_dt_spec * bus,
enum tcpc_status_reg reg,
uint16_t mask )

Function to clear specific bits in a TCPCI status register.

Parameters
busI2C bus
regEnum representing the status register to be cleared
maskBitmask specifying which bits to clear
Returns
int Status of I2C operation, 0 in case of success

◆ tcpci_tcpm_dump_std_reg()

int tcpci_tcpm_dump_std_reg ( const struct i2c_dt_spec * bus)

Function to dump the standard TCPCI registers.

Parameters
busI2C bus
Returns
int Status of I2C operation, 0 in case of success

◆ tcpci_tcpm_get_cc()

int tcpci_tcpm_get_cc ( const struct i2c_dt_spec * bus,
enum tc_cc_voltage_state * cc1,
enum tc_cc_voltage_state * cc2 )

Function that reads the CC status registers and converts read values to enums representing voltages state and partner detection status.

Parameters
busI2C bus
cc1Pointer to variable where detected CC1 voltage state will be stored
cc2Pointer to variable where detected CC2 voltage state will be stored
Returns
-EINVAL if cc1 or cc2 pointer is NULL
int Status of I2C operation, 0 in case of success

◆ tcpci_tcpm_get_chip_info()

int tcpci_tcpm_get_chip_info ( const struct i2c_dt_spec * bus,
struct tcpc_chip_info * chip_info )

Function to retrieve information about the TCPCI chip.

Parameters
busI2C bus
chip_infoPointer to the structure where the chip information will be stored
Returns
int Status of I2C operation, 0 in case of success

◆ tcpci_tcpm_get_rp_value()

int tcpci_tcpm_get_rp_value ( const struct i2c_dt_spec * bus,
enum tc_rp_value * rp )

Function to get the currently selected Rp value.

Parameters
busI2C bus
rpPointer to the variable where the Rp value will be stored
Returns
int Status of I2C operation, 0 in case of success

◆ tcpci_tcpm_get_status_register()

int tcpci_tcpm_get_status_register ( const struct i2c_dt_spec * bus,
enum tcpc_status_reg reg,
uint16_t * status )

Function to get the status of a specific TCPCI status register.

Parameters
busI2C bus
regEnum representing the status register to be read
statusPointer to the variable where the status will be stored
Returns
int Status of I2C operation, 0 in case of success

◆ tcpci_tcpm_mask_status_register()

int tcpci_tcpm_mask_status_register ( const struct i2c_dt_spec * bus,
enum tcpc_status_reg reg,
uint16_t mask )

Function to set the mask of a TCPCI status register.

Parameters
busI2C bus
regEnum representing the status register to be masked
maskBitmask specifying which bits to mask
Returns
int Status of I2C operation, 0 in case of success

◆ tcpci_tcpm_select_rp_value()

int tcpci_tcpm_select_rp_value ( const struct i2c_dt_spec * bus,
enum tc_rp_value rp )

Function to select the Rp (Pull-up Resistor) value.

Parameters
busI2C bus
rpEnum representing the Rp value to be set
Returns
int Status of I2C operation, 0 in case of success

◆ tcpci_tcpm_set_bist_test_mode()

int tcpci_tcpm_set_bist_test_mode ( const struct i2c_dt_spec * bus,
bool enable )

Function to enable or disable the BIST (Built-In Self-Test) mode.

Parameters
busI2C bus
enableBoolean flag to enable (true) or disable (false) BIST mode
Returns
int Status of I2C operation, 0 in case of success

◆ tcpci_tcpm_set_cc()

int tcpci_tcpm_set_cc ( const struct i2c_dt_spec * bus,
enum tc_cc_pull pull )

Function to set the CC pull resistor and set the role as either Source or Sink.

Parameters
busI2C bus
pullEnum representing the CC pull resistor to be set
Returns
int Status of I2C operation, 0 in case of success

◆ tcpci_tcpm_set_cc_polarity()

int tcpci_tcpm_set_cc_polarity ( const struct i2c_dt_spec * bus,
enum tc_cc_polarity polarity )

Function to set the polarity of the CC lines.

Parameters
busI2C bus
polarityEnum representing the CC polarity to be set
Returns
int Status of I2C operation, 0 in case of success

◆ tcpci_tcpm_set_drp_toggle()

int tcpci_tcpm_set_drp_toggle ( const struct i2c_dt_spec * bus,
bool enable )

Function to enable or disable TCPC auto dual role toggle.

Parameters
busI2C bus
enableBoolean flag to enable (true) or disable (false) DRP toggle mode
Returns
int Status of I2C operation, 0 in case of success

◆ tcpci_tcpm_set_roles()

int tcpci_tcpm_set_roles ( const struct i2c_dt_spec * bus,
enum pd_rev_type pd_rev,
enum tc_power_role power_role,
enum tc_data_role data_role )

Function to set the power and data role of the PD message header.

Parameters
busI2C bus
pd_revEnum representing the USB−PD Specification Revision to be set
power_roleEnum representing the power role to be set
data_roleEnum representing the data role to be set
Returns
int Status of I2C operation, 0 in case of success

◆ tcpci_tcpm_set_rx_type()

int tcpci_tcpm_set_rx_type ( const struct i2c_dt_spec * bus,
uint8_t type )

Function to set the RX type.

Parameters
busI2C bus
typeValue representing the RX type to be set
Returns
int Status of I2C operation, 0 in case of success

◆ tcpci_tcpm_set_vconn()

int tcpci_tcpm_set_vconn ( const struct i2c_dt_spec * bus,
bool enable )

Function to enable or disable VCONN.

Parameters
busI2C bus
enableBoolean flag to enable (true) or disable (false) VCONN
Returns
int Status of I2C operation, 0 in case of success

◆ tcpci_tcpm_transmit_data()

int tcpci_tcpm_transmit_data ( const struct i2c_dt_spec * bus,
struct pd_msg * msg,
const uint8_t retries )

Function to transmit a PD (Power Delivery) message.

The message is transmitted with a specified number of retries in case of failure.

Parameters
busI2C bus
msgPointer to the PD message structure to be transmitted
retriesNumber of retries in case of transmission failure
Returns
int Status of I2C operation, 0 in case of success

◆ tcpci_update_reg8()

int tcpci_update_reg8 ( const struct i2c_dt_spec * bus,
uint8_t reg,
uint8_t mask,
uint8_t value )

Function to read and update part of the 8-bit register of TCPCI device The function is NOT performing this operation atomically.

Parameters
busI2C bus
regAddress of TCPCI register
maskBitmask specifying which bits of the device register will be modified
valueValue that will be written to the device register after being ANDed with mask
Returns
int Status of I2C operation, 0 in case of success

◆ tcpci_write_reg16()

int tcpci_write_reg16 ( const struct i2c_dt_spec * bus,
uint8_t reg,
uint16_t value )

Function to write a value to the 16-bit register of TCPCI device.

Parameters
busI2C bus
regAddress of TCPCI register
valueValue that will be written to the device register
Returns
int Status of I2C operation, 0 in case of success

◆ tcpci_write_reg8()

int tcpci_write_reg8 ( const struct i2c_dt_spec * bus,
uint8_t reg,
uint8_t value )

Function to write a value to the 8-bit register of TCPCI device.

Parameters
busI2C bus
regAddress of TCPCI register
valueValue that will be written to the device register
Returns
int Status of I2C operation, 0 in case of success

Variable Documentation

◆ tcpci_std_regs

const struct tcpci_reg_dump_map tcpci_std_regs[38]
extern

Array containing the standard TCPCI registers list.

If the TCPC driver contain any vendor-specific registers, it may override the TCPCI dump_std_reg function tp dump them and should also dump the standard registers using this array.