Skip to content

Commit b25bdc4

Browse files
recalcikartben
authored andcommitted
usbc: tcpc: Update set_drp_toggle function
Updated set_drp_toggle to handle differences in TCPCI revisions. Added a macro for TCPCI revision and read it from the chip register during initialization. Signed-off-by: Jianxiong Gu <[email protected]>
1 parent 3f48195 commit b25bdc4

File tree

3 files changed

+45
-5
lines changed

3 files changed

+45
-5
lines changed

drivers/usb_c/tcpc/rt1715.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ struct rt1715_data {
2626
int init_retries;
2727
/** Boolean value if chip was successfully initialized */
2828
bool initialized;
29+
/** TCPCI Specification Revision */
30+
uint8_t pd_int_rev;
2931

3032
/** Callback for alert GPIO */
3133
struct gpio_callback alert_cb;
@@ -414,8 +416,9 @@ static int rt1715_tcpc_mask_status_register(const struct device *dev, enum tcpc_
414416
static int rt1715_tcpc_set_drp_toggle(const struct device *dev, bool enable)
415417
{
416418
const struct rt1715_cfg *cfg = dev->config;
419+
const struct rt1715_data *data = dev->data;
417420

418-
return tcpci_tcpm_set_drp_toggle(&cfg->bus, enable);
421+
return tcpci_tcpm_set_drp_toggle(&cfg->bus, data->pd_int_rev, enable);
419422
}
420423

421424
static int rt1715_tcpc_get_chip_info(const struct device *dev, struct tcpc_chip_info *chip_info)
@@ -585,6 +588,7 @@ void rt1715_init_work_cb(struct k_work *work)
585588
const struct rt1715_cfg *cfg = data->dev->config;
586589
uint8_t power_reg, lp_reg = 0;
587590
struct tcpc_chip_info chip_info;
591+
uint16_t tcpci_rev;
588592
int ret;
589593

590594
LOG_INF("Initializing RT1715 chip: %s", data->dev->name);
@@ -608,6 +612,11 @@ void rt1715_init_work_cb(struct k_work *work)
608612
LOG_INF("Initialized chip is: %04x:%04x:%04x", chip_info.vendor_id, chip_info.product_id,
609613
chip_info.device_id);
610614

615+
/* get TCPCI Specification Revision */
616+
tcpci_read_reg16(&cfg->bus, TCPC_REG_PD_INT_REV, &tcpci_rev);
617+
data->pd_int_rev = TCPC_REG_PD_INT_REV_REV_MAJOR(tcpci_rev) << 4 |
618+
TCPC_REG_PD_INT_REV_REV_MINOR(tcpci_rev);
619+
611620
/* Exit shutdown mode & Enable ext messages */
612621
lp_reg = RT1715_REG_LP_CTRL_SHUTDOWN_OFF | RT1715_REG_LP_CTRL_ENEXTMSG;
613622
/* Disable idle mode */

drivers/usb_c/tcpc/tcpci.c

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -598,10 +598,36 @@ int tcpci_tcpm_set_roles(const struct i2c_dt_spec *bus, enum pd_rev_type pd_rev,
598598
TCPC_REG_MSG_HDR_INFO_SET(pd_rev, data_role, power_role));
599599
}
600600

601-
int tcpci_tcpm_set_drp_toggle(const struct i2c_dt_spec *bus, bool enable)
601+
int tcpci_tcpm_set_drp_toggle(const struct i2c_dt_spec *bus, uint8_t pd_int_rev, bool enable)
602602
{
603-
return tcpci_update_reg8(bus, TCPC_REG_ROLE_CTRL, TCPC_REG_ROLE_CTRL_DRP_MASK,
604-
TCPC_REG_ROLE_CTRL_SET(enable, 0, 0, 0));
603+
int ret;
604+
605+
/* Set auto drp toggle */
606+
ret = tcpci_update_reg8(bus, TCPC_REG_ROLE_CTRL, TCPC_REG_ROLE_CTRL_DRP_MASK,
607+
TCPC_REG_ROLE_CTRL_SET(enable, 0, 0, 0));
608+
if (ret != 0) {
609+
return ret;
610+
}
611+
612+
/*
613+
* For TCPCI Rev 2.0, unless the TCPM sets TCPC_REG_TCPC_CTRL_EN_LOOK4CONNECTION_ALERT,
614+
* TCPC by default masks Alert assertion when CC_STATUS_LOOK4CONNECTION changes state.
615+
*/
616+
if (pd_int_rev >= PD_INT_REV20) {
617+
ret = tcpci_update_reg8(bus, TCPC_REG_TCPC_CTRL,
618+
TCPC_REG_TCPC_CTRL_EN_LOOK4CONNECTION_ALERT,
619+
enable ? TCPC_REG_TCPC_CTRL_EN_LOOK4CONNECTION_ALERT : 0);
620+
if (ret != 0) {
621+
return ret;
622+
}
623+
}
624+
625+
if (enable) {
626+
/* Set Look4Connection command */
627+
return tcpci_write_reg8(bus, TCPC_REG_COMMAND, TCPC_REG_COMMAND_LOOK4CONNECTION);
628+
}
629+
630+
return 0;
605631
}
606632

607633
int tcpci_tcpm_set_rx_type(const struct i2c_dt_spec *bus, uint8_t rx_type)

include/zephyr/drivers/usb_c/tcpci_priv.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ struct tcpci_reg_dump_map {
4141
*/
4242
extern const struct tcpci_reg_dump_map tcpci_std_regs[TCPCI_STD_REGS_SIZE];
4343

44+
/** Type-C Port Controller Interface Specification Revision */
45+
#define PD_INT_REV10 0x10 /* Revision 1.0 */
46+
#define PD_INT_REV20 0x20 /* Revision 2.0 */
47+
4448
/**
4549
* @brief Function to read the 8-bit register of TCPCI device
4650
*
@@ -185,10 +189,11 @@ int tcpci_tcpm_set_cc(const struct i2c_dt_spec *bus, enum tc_cc_pull pull);
185189
* @brief Function to enable or disable TCPC auto dual role toggle.
186190
*
187191
* @param bus I2C bus
192+
* @param pd_int_rev Value of the TCPC_REG_PD_INT_REV bits [15..8]
188193
* @param enable Boolean flag to enable (true) or disable (false) DRP toggle mode
189194
* @return int Status of I2C operation, 0 in case of success
190195
*/
191-
int tcpci_tcpm_set_drp_toggle(const struct i2c_dt_spec *bus, bool enable);
196+
int tcpci_tcpm_set_drp_toggle(const struct i2c_dt_spec *bus, uint8_t pd_int_rev, bool enable);
192197

193198
/**
194199
* @brief Function to set the power and data role of the PD message header.

0 commit comments

Comments
 (0)