Skip to content

Commit d18308c

Browse files
recalcikartben
authored andcommitted
usbc: tcpc: Add generic TCPCI related functions
Add generic functions that will be common to TCPCI compliant drivers. Signed-off-by: Jianxiong Gu <[email protected]>
1 parent a4cf7d1 commit d18308c

File tree

2 files changed

+109
-0
lines changed

2 files changed

+109
-0
lines changed

drivers/usb_c/tcpc/tcpci.c

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -684,3 +684,54 @@ int tcpci_tcpm_mask_status_register(const struct i2c_dt_spec *bus, enum tcpc_sta
684684
return -EINVAL;
685685
}
686686
}
687+
688+
int tcpci_tcpm_set_snk_ctrl(const struct i2c_dt_spec *bus, bool enable)
689+
{
690+
return tcpci_write_reg8(bus, TCPC_REG_COMMAND,
691+
enable ? TCPC_REG_COMMAND_SNK_CTRL_HIGH : TCPC_REG_COMMAND_SNK_CTRL_LOW);
692+
}
693+
694+
int tcpci_tcpm_set_src_ctrl(const struct i2c_dt_spec *bus, bool enable)
695+
{
696+
return tcpci_write_reg8(bus, TCPC_REG_COMMAND,
697+
enable ? TCPC_REG_COMMAND_SRC_CTRL_DEF : TCPC_REG_COMMAND_SRC_CTRL_LOW);
698+
}
699+
700+
int tcpci_tcpm_get_snk_ctrl(const struct i2c_dt_spec *bus, bool *sinking)
701+
{
702+
uint16_t reg;
703+
int ret;
704+
705+
ret = tcpci_tcpm_get_status_register(bus, TCPC_REG_POWER_STATUS, &reg);
706+
if (ret == 0) {
707+
*sinking = reg & TCPC_REG_POWER_STATUS_SINKING_VBUS;
708+
}
709+
710+
return ret;
711+
}
712+
713+
int tcpci_tcpm_get_src_ctrl(const struct i2c_dt_spec *bus, bool *sourcing)
714+
{
715+
uint16_t reg;
716+
int ret;
717+
718+
ret = tcpci_tcpm_get_status_register(bus, TCPC_REG_POWER_STATUS, &reg);
719+
if (ret == 0) {
720+
*sourcing = reg & TCPC_REG_POWER_STATUS_SOURCING_VBUS;
721+
}
722+
723+
return ret;
724+
}
725+
726+
int tcpci_tcpm_set_debug_accessory(const struct i2c_dt_spec *bus, bool enable)
727+
{
728+
return tcpci_update_reg8(bus, TCPC_REG_CONFIG_STD_OUTPUT,
729+
TCPC_REG_CONFIG_STD_OUTPUT_DBG_ACC_CONN_N,
730+
enable ? 0 : TCPC_REG_CONFIG_STD_OUTPUT_DBG_ACC_CONN_N);
731+
}
732+
733+
int tcpci_tcpm_set_low_power_mode(const struct i2c_dt_spec *bus, bool enable)
734+
{
735+
return tcpci_write_reg8(bus, TCPC_REG_COMMAND,
736+
enable ? TCPC_REG_COMMAND_I2CIDLE : TCPC_REG_COMMAND_WAKE_I2C);
737+
}

include/zephyr/drivers/usb_c/tcpci_priv.h

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,4 +262,62 @@ int tcpci_tcpm_clear_status_register(const struct i2c_dt_spec *bus, enum tcpc_st
262262
int tcpci_tcpm_mask_status_register(const struct i2c_dt_spec *bus, enum tcpc_status_reg reg,
263263
uint16_t mask);
264264

265+
/**
266+
* @brief Queries the current sinking state of the TCPCI.
267+
*
268+
* This function checks if the device is sinking VBUS to the system load.
269+
*
270+
* @param bus I2C bus
271+
* @param sinking Pointer to variable where sinking state will be stored
272+
* @return int Status of I2C operation, 0 in case of success
273+
*/
274+
int tcpci_tcpm_get_snk_ctrl(const struct i2c_dt_spec *bus, bool *sinking);
275+
276+
/**
277+
* @brief Queries the current sourcing state of the TCPCI.
278+
*
279+
* This function checks if the device is sourcing VBUS.
280+
*
281+
* @param bus I2C bus
282+
* @param sourcing Pointer to variable where sourcing state will be stored
283+
* @return int Status of I2C operation, 0 in case of success
284+
*/
285+
int tcpci_tcpm_get_src_ctrl(const struct i2c_dt_spec *bus, bool *sourcing);
286+
287+
/**
288+
* @brief Function to enable or disable sinking power over VBUS.
289+
*
290+
* @param bus I2C bus
291+
* @param enable Boolean flag to enable (true) or disable (false) sinking power
292+
* @return int Status of I2C operation, 0 in case of success
293+
*/
294+
int tcpci_tcpm_set_snk_ctrl(const struct i2c_dt_spec *bus, bool enable);
295+
296+
/**
297+
* @brief Function to enable or disable sourcing power over VBUS.
298+
*
299+
* @param bus I2C bus
300+
* @param enable Boolean flag to enable (true) or disable (false) sourcing power
301+
* @return int Status of I2C operation, 0 in case of success
302+
*/
303+
int tcpci_tcpm_set_src_ctrl(const struct i2c_dt_spec *bus, bool enable);
304+
305+
/**
306+
* @brief Function to enable or disable the debug accessory mode.
307+
*
308+
* @param bus I2C bus
309+
* @param enable Boolean flag to enable (true) or disable (false) debug accessory mode
310+
* @return int Status of I2C operation, 0 in case of success
311+
*/
312+
int tcpci_tcpm_set_debug_accessory(const struct i2c_dt_spec *bus, bool enable);
313+
314+
/**
315+
* @brief Function to enable or disable the low power mode.
316+
*
317+
* @param bus I2C bus
318+
* @param enable Boolean flag to enable (true) or disable (false) low power mode
319+
* @return int Status of I2C operation, 0 in case of success
320+
*/
321+
int tcpci_tcpm_set_low_power_mode(const struct i2c_dt_spec *bus, bool enable);
322+
265323
#endif /* ZEPHYR_INCLUDE_DRIVERS_USBC_TCPCI_PRIV_H_ */

0 commit comments

Comments
 (0)