summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenis Brockus <dbrockus@chromium.org>2019-12-05 10:12:37 -0700
committerCommit Bot <commit-bot@chromium.org>2019-12-10 01:42:15 +0000
commitf74ddb9de4f7e29402156904d3f16a8d01fb6df5 (patch)
tree7e76aca24c6f6b6b65ac9068b932930266311425
parentd3129132f6e05cbce0141b5549272731bafb034f (diff)
downloadchrome-ec-f74ddb9de4f7e29402156904d3f16a8d01fb6df5.tar.gz
tcpci: add tcpc_update routines for read/mod/write
BUG=none BRANCH=none TEST=verify TCPCI is still functioning Change-Id: I325b025bf65d3b0cb6e15cf8dab8488138cc76d5 Signed-off-by: Denis Brockus <dbrockus@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1953124 Reviewed-by: Jett Rink <jettrink@chromium.org> Commit-Queue: Jett Rink <jettrink@chromium.org>
-rw-r--r--driver/tcpm/tcpci.c102
-rw-r--r--driver/tcpm/tcpm.h23
2 files changed, 69 insertions, 56 deletions
diff --git a/driver/tcpm/tcpci.c b/driver/tcpm/tcpci.c
index 7e2f090ba4..35d60a1758 100644
--- a/driver/tcpm/tcpci.c
+++ b/driver/tcpm/tcpci.c
@@ -144,6 +144,38 @@ int tcpc_xfer_unlocked(int port, const uint8_t *out, int out_size,
pd_device_accessed(port);
return rv;
}
+
+int tcpc_update8(int port, int reg,
+ uint8_t mask,
+ enum mask_update_action action)
+{
+ int rv;
+
+ pd_wait_exit_low_power(port);
+
+ rv = i2c_update8(tcpc_config[port].i2c_info.port,
+ tcpc_config[port].i2c_info.addr_flags,
+ reg, mask, action);
+
+ pd_device_accessed(port);
+ return rv;
+}
+int tcpc_update16(int port, int reg,
+ uint16_t mask,
+ enum mask_update_action action)
+{
+ int rv;
+
+ pd_wait_exit_low_power(port);
+
+ rv = i2c_update16(tcpc_config[port].i2c_info.port,
+ tcpc_config[port].i2c_info.addr_flags,
+ reg, mask, action);
+
+ pd_device_accessed(port);
+ return rv;
+}
+
#endif /* CONFIG_USB_PD_TCPC_LOW_POWER */
static int init_alert_mask(int port)
@@ -244,17 +276,10 @@ int tcpci_tcpm_select_rp_value(int port, int rp)
void tcpci_tcpc_discharge_vbus(int port, int enable)
{
- int reg;
-
- if (tcpc_read(port, TCPC_REG_POWER_CTRL, &reg))
- return;
-
- if (enable)
- reg |= TCPC_REG_POWER_CTRL_FORCE_DISCHARGE;
- else
- reg &= ~TCPC_REG_POWER_CTRL_FORCE_DISCHARGE;
-
- tcpc_write(port, TCPC_REG_POWER_CTRL, reg);
+ tcpc_update8(port,
+ TCPC_REG_POWER_CTRL,
+ TCPC_REG_POWER_CTRL_FORCE_DISCHARGE,
+ (enable) ? MASK_SET : MASK_CLR);
}
/*
@@ -263,26 +288,10 @@ void tcpci_tcpc_discharge_vbus(int port, int enable)
*/
void tcpci_tcpc_connect_state_change(int port, int connected)
{
- int reg, oldreg, rv;
-
- rv = tcpc_read(port, TCPC_REG_POWER_CTRL, &oldreg);
- if (rv) {
- /* CPRINTS("%s: failed read POWER_CTRL", __func__); */
- return;
- }
-
- if (connected)
- reg = oldreg | TCPC_REG_POWER_CTRL_AUTO_DISCHARGE_DISCONNECT;
- else
- reg = oldreg & ~TCPC_REG_POWER_CTRL_AUTO_DISCHARGE_DISCONNECT;
-
- if (reg != oldreg) {
- rv = tcpc_write(port, TCPC_REG_POWER_CTRL, reg);
- if (rv) {
- /* CPRINTS("%s: failed write POWER_CTRL", __func__); */
- return;
- }
- }
+ tcpc_update8(port,
+ TCPC_REG_POWER_CTRL,
+ TCPC_REG_POWER_CTRL_AUTO_DISCHARGE_DISCONNECT,
+ (connected) ? MASK_SET : MASK_CLR);
}
static void connect_state_change(int port, int connected)
@@ -441,17 +450,10 @@ int tcpci_tcpm_set_rx_enable(int port, int enable)
#ifdef CONFIG_USB_TYPEC_PD_FAST_ROLE_SWAP
void tcpci_tcpc_fast_role_swap_enable(int port, int enable)
{
- int reg;
-
- if (tcpc_read(port, TCPC_REG_POWER_CTRL, &reg))
- return;
-
- if (enable)
- reg |= TCPC_REG_POWER_CTRL_FRS_ENABLE;
- else
- reg &= ~TCPC_REG_POWER_CTRL_FRS_ENABLE;
-
- tcpc_write(port, TCPC_REG_POWER_CTRL, reg);
+ tcpc_update8(port,
+ TCPC_REG_POWER_CTRL,
+ TCPC_REG_POWER_CTRL_FRS_ENABLE,
+ (enable) ? MASK_SET : MASK_CLR);
board_tcpc_fast_role_swap_enable(port, enable);
}
@@ -673,13 +675,7 @@ static int register_mask_reset(int port)
static int tcpci_get_fault(int port, int *fault)
{
- int rv;
-
- rv = tcpc_read(port, TCPC_REG_FAULT_STATUS, fault);
- if (rv)
- CPRINTS("C%d Reading FAULT failed, rv=%d", port, rv);
-
- return rv;
+ return tcpc_read(port, TCPC_REG_FAULT_STATUS, fault);
}
static int tcpci_handle_fault(int port, int fault)
@@ -690,13 +686,7 @@ static int tcpci_handle_fault(int port, int fault)
static int tcpci_clear_fault(int port, int fault)
{
- int rv;
-
- rv = tcpc_write(port, TCPC_REG_FAULT_STATUS, fault);
- if (rv)
- CPRINTS("C%d Writing FAULT failed, rv=%d", port, rv);
-
- return rv;
+ return tcpc_write(port, TCPC_REG_FAULT_STATUS, fault);
}
/*
diff --git a/driver/tcpm/tcpm.h b/driver/tcpm/tcpm.h
index 51b315fb77..7669135a31 100644
--- a/driver/tcpm/tcpm.h
+++ b/driver/tcpm/tcpm.h
@@ -82,6 +82,24 @@ static inline int tcpc_write_block(int port, int reg,
reg, out, size);
}
+static inline int tcpc_update8(int port, int reg,
+ uint8_t mask,
+ enum mask_update_action action)
+{
+ return i2c_update8(tcpc_config[port].i2c_info.port,
+ tcpc_config[port].i2c_info.addr_flags,
+ reg, mask, action);
+}
+static inline int tcpc_update16(int port, int reg,
+ uint16_t mask,
+ enum mask_update_action action)
+{
+ return i2c_update16(tcpc_config[port].i2c_info.port,
+ tcpc_config[port].i2c_info.addr_flags,
+ reg, mask, action);
+}
+
+
#else /* !CONFIG_USB_PD_TCPC_LOW_POWER */
int tcpc_addr_write(int port, int i2c_addr, int reg, int val);
int tcpc_write16(int port, int reg, int val);
@@ -94,6 +112,11 @@ int tcpc_xfer(int port, const uint8_t *out, int out_size,
int tcpc_xfer_unlocked(int port, const uint8_t *out, int out_size,
uint8_t *in, int in_size, int flags);
+int tcpc_update8(int port, int reg,
+ uint8_t mask, enum mask_update_action action);
+int tcpc_update16(int port, int reg,
+ uint16_t mask, enum mask_update_action action);
+
#endif /* CONFIG_USB_PD_TCPC_LOW_POWER */
static inline int tcpc_write(int port, int reg, int val)