Skip to content

Commit b9ef11d

Browse files
barnas-michalcarlescufi
authored andcommitted
usbc: add event-driven handling of CC lines changes in ps8815 driver
Add bool value that stores the CC change information received in the interrupt of TCPC alert line. In sink role when in disconnected state, polling the CC lines causes the chip to be awaken from sleep mode increasing the power usage. When partner is connected, or any other CC lines change happens, the chip informs about it with alert. It can be cached and used instead of asking the chip directly. Signed-off-by: Michał Barnaś <[email protected]>
1 parent 82a6e9f commit b9ef11d

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

drivers/usb_c/tcpc/ps8xxx.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ struct ps8xxx_data {
4646
/** Polarity of CC lines for PD and VCONN */
4747
enum tc_cc_polarity cc_polarity;
4848

49+
/** Boolean value if there was a change on the CC lines since last check */
50+
bool cc_changed;
4951
/** State of CC1 line */
5052
enum tc_cc_voltage_state cc1;
5153
/** State of CC2 line */
@@ -107,6 +109,15 @@ int ps8xxx_tcpc_get_cc(const struct device *dev, enum tc_cc_voltage_state *cc1,
107109
return -EIO;
108110
}
109111

112+
if (IS_ENABLED(CONFIG_USBC_CSM_SINK_ONLY) && !data->cc_changed) {
113+
*cc1 = data->cc1;
114+
*cc2 = data->cc2;
115+
116+
return 0;
117+
}
118+
119+
data->cc_changed = false;
120+
110121
ret = tcpci_tcpm_get_cc(&cfg->bus, cc1, cc2);
111122

112123
if (IS_ENABLED(CONFIG_USBC_CSM_SINK_ONLY) || *cc1 != data->cc1 || *cc2 != data->cc2) {
@@ -123,6 +134,8 @@ int ps8xxx_tcpc_select_rp_value(const struct device *dev, enum tc_rp_value rp)
123134
const struct ps8xxx_cfg *cfg = dev->config;
124135
struct ps8xxx_data *data = dev->data;
125136

137+
data->cc_changed = true;
138+
126139
return tcpci_update_reg8(&cfg->bus, TCPC_REG_ROLE_CTRL, TCPC_REG_ROLE_CTRL_RP_MASK,
127140
TCPC_REG_ROLE_CTRL_SET(0, rp, 0, 0));
128141
}
@@ -148,6 +161,8 @@ int ps8xxx_tcpc_set_cc(const struct device *dev, enum tc_cc_pull pull)
148161
return -EIO;
149162
}
150163

164+
data->cc_changed = true;
165+
151166
return tcpci_update_reg8(&cfg->bus, TCPC_REG_ROLE_CTRL,
152167
TCPC_REG_ROLE_CTRL_CC1_MASK | TCPC_REG_ROLE_CTRL_CC2_MASK,
153168
TCPC_REG_ROLE_CTRL_SET(0, 0, pull, pull));
@@ -188,6 +203,7 @@ int ps8xxx_tcpc_set_vconn(const struct device *dev, bool enable)
188203
return -EIO;
189204
}
190205

206+
data->cc_changed = true;
191207
ret = tcpci_update_reg8(&cfg->bus, TCPC_REG_POWER_CTRL, TCPC_REG_POWER_CTRL_VCONN_EN,
192208
enable ? TCPC_REG_POWER_CTRL_VCONN_EN : 0);
193209

@@ -309,6 +325,7 @@ int ps8xxx_tcpc_set_cc_polarity(const struct device *dev, enum tc_cc_polarity po
309325
return ret;
310326
}
311327

328+
data->cc_changed = true;
312329
data->cc_polarity = polarity;
313330
return 0;
314331
}
@@ -589,6 +606,7 @@ void ps8xxx_alert_work_cb(struct k_work *work)
589606
if (alert_type == TCPC_ALERT_HARD_RESET_RECEIVED) {
590607
LOG_DBG("PS8xxx hard rst received");
591608
tcpci_init_alert_mask(dev);
609+
data->cc_changed = true;
592610
} else if (alert_type == TCPC_ALERT_FAULT_STATUS) {
593611
uint8_t fault;
594612

@@ -602,6 +620,7 @@ void ps8xxx_alert_work_cb(struct k_work *work)
602620
tcpci_read_reg8(&cfg->bus, TCPC_REG_EXT_STATUS, &ext_status);
603621
tcpci_write_reg8(&cfg->bus, TCPC_REG_EXT_STATUS, ext_status);
604622

623+
data->cc_changed = true;
605624
LOG_DBG("PS8xxx ext status: %02x", ext_status);
606625
} else if (alert_type == TCPC_ALERT_POWER_STATUS) {
607626
uint8_t pwr_status;
@@ -619,6 +638,8 @@ void ps8xxx_alert_work_cb(struct k_work *work)
619638
LOG_DBG("PS8xxx ext alert: %02x", alert_status);
620639
} else if (alert_type == TCPC_ALERT_MSG_STATUS) {
621640
data->msg_pending = true;
641+
} else if (alert_type == TCPC_ALERT_CC_STATUS) {
642+
data->cc_changed = true;
622643
}
623644

624645
if (data->alert_handler != NULL) {
@@ -711,6 +732,7 @@ static int ps8xxx_dev_init(const struct device *dev)
711732
{ \
712733
.dev = DEVICE_DT_GET(node), \
713734
.init_retries = 0, \
735+
.cc_changed = true, \
714736
}
715737

716738
#define PS8XXX_DRIVER_CFG_INIT(node) \

0 commit comments

Comments
 (0)