summaryrefslogtreecommitdiff
path: root/driver
diff options
context:
space:
mode:
authorJett Rink <jettrink@chromium.org>2018-12-13 07:12:00 -0700
committerchrome-bot <chrome-bot@chromium.org>2018-12-18 00:42:57 -0800
commitf0998e9a4bbd7f77c9574f9e27e7e8b8bcc65a18 (patch)
tree3c7b77184f66d9eca8b2140c52e65539d6374744 /driver
parent16c9d6d25326a011b518753cf40a782c738391a1 (diff)
downloadchrome-ec-f0998e9a4bbd7f77c9574f9e27e7e8b8bcc65a18.tar.gz
tcpc: wait for TCPC wake up upon first access
Previously we tried to perform i2c communication with the TCPC when it was in low power mode and only if the i2c transaction failed did we wait for the device to wake up. Now that the PS8751 will respond to i2c transaction (ACK them) when it is in LPM, ensure the init happers before we start talking to the device to handle an interrupt. BRANCH=none BUG=b:118063849,b:121109893 TEST=verify that plug and unplug for PS8751, ANX3429, and ANX3447 LPM still works. Change-Id: I8c18195e55ee6d04af7d4ff24230a3bd2d147d53 Signed-off-by: Jett Rink <jettrink@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/1375102 Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com> Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org> Reviewed-by: Edward Hill <ecgh@chromium.org>
Diffstat (limited to 'driver')
-rw-r--r--driver/tcpm/tcpci.c101
1 files changed, 49 insertions, 52 deletions
diff --git a/driver/tcpm/tcpci.c b/driver/tcpm/tcpci.c
index 00067c18d6..e3c266a478 100644
--- a/driver/tcpm/tcpci.c
+++ b/driver/tcpm/tcpci.c
@@ -32,80 +32,78 @@ static int selected_rp[CONFIG_USB_PD_PORT_COUNT];
#ifdef CONFIG_USB_PD_TCPC_LOW_POWER
int tcpc_write(int port, int reg, int val)
{
- int rv = i2c_write8(tcpc_config[port].i2c_host_port,
- tcpc_config[port].i2c_slave_addr, reg, val);
- if (rv && pd_device_in_low_power(port)) {
- pd_wait_for_wakeup(port);
- rv = i2c_write8(tcpc_config[port].i2c_host_port,
- tcpc_config[port].i2c_slave_addr, reg, val);
- }
+ int rv;
+
+ pd_wait_exit_low_power(port);
+
+ rv = i2c_write8(tcpc_config[port].i2c_host_port,
+ tcpc_config[port].i2c_slave_addr, reg, val);
+
pd_device_accessed(port);
return rv;
}
int tcpc_write16(int port, int reg, int val)
{
- int rv = i2c_write16(tcpc_config[port].i2c_host_port,
- tcpc_config[port].i2c_slave_addr, reg, val);
- if (rv && pd_device_in_low_power(port)) {
- pd_wait_for_wakeup(port);
- rv = i2c_write16(tcpc_config[port].i2c_host_port,
- tcpc_config[port].i2c_slave_addr, reg, val);
- }
+ int rv;
+
+ pd_wait_exit_low_power(port);
+
+ rv = i2c_write16(tcpc_config[port].i2c_host_port,
+ tcpc_config[port].i2c_slave_addr, reg, val);
+
pd_device_accessed(port);
return rv;
}
int tcpc_read(int port, int reg, int *val)
{
- int rv = i2c_read8(tcpc_config[port].i2c_host_port,
- tcpc_config[port].i2c_slave_addr, reg, val);
- if (rv && pd_device_in_low_power(port)) {
- pd_wait_for_wakeup(port);
- rv = i2c_read8(tcpc_config[port].i2c_host_port,
- tcpc_config[port].i2c_slave_addr, reg, val);
- }
+ int rv;
+
+ pd_wait_exit_low_power(port);
+
+ rv = i2c_read8(tcpc_config[port].i2c_host_port,
+ tcpc_config[port].i2c_slave_addr, reg, val);
+
pd_device_accessed(port);
return rv;
}
int tcpc_read16(int port, int reg, int *val)
{
- int rv = i2c_read16(tcpc_config[port].i2c_host_port,
- tcpc_config[port].i2c_slave_addr, reg, val);
- if (rv && pd_device_in_low_power(port)) {
- pd_wait_for_wakeup(port);
- rv = i2c_read16(tcpc_config[port].i2c_host_port,
- tcpc_config[port].i2c_slave_addr, reg, val);
- }
+ int rv;
+
+ pd_wait_exit_low_power(port);
+
+ rv = i2c_read16(tcpc_config[port].i2c_host_port,
+ tcpc_config[port].i2c_slave_addr, reg, val);
+
pd_device_accessed(port);
return rv;
}
int tcpc_read_block(int port, int reg, uint8_t *in, int size)
{
- int rv = i2c_read_block(tcpc_config[port].i2c_host_port,
+ int rv;
+
+ pd_wait_exit_low_power(port);
+
+ rv = i2c_read_block(tcpc_config[port].i2c_host_port,
tcpc_config[port].i2c_slave_addr, reg, in, size);
- if (rv && pd_device_in_low_power(port)) {
- pd_wait_for_wakeup(port);
- rv = i2c_read_block(tcpc_config[port].i2c_host_port,
- tcpc_config[port].i2c_slave_addr, reg,
- in, size);
- }
+
pd_device_accessed(port);
return rv;
}
int tcpc_write_block(int port, int reg, const uint8_t *out, int size)
{
- int rv = i2c_write_block(tcpc_config[port].i2c_host_port,
- tcpc_config[port].i2c_slave_addr, reg, out, size);
- if (rv && pd_device_in_low_power(port)) {
- pd_wait_for_wakeup(port);
- rv = i2c_write_block(tcpc_config[port].i2c_host_port,
- tcpc_config[port].i2c_slave_addr, reg,
- out, size);
- }
+ int rv;
+
+ pd_wait_exit_low_power(port);
+
+ rv = i2c_write_block(tcpc_config[port].i2c_host_port,
+ tcpc_config[port].i2c_slave_addr, reg, out, size);
+
pd_device_accessed(port);
return rv;
}
@@ -125,15 +123,14 @@ 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 rv = i2c_xfer_unlocked(tcpc_config[port].i2c_host_port,
- tcpc_config[port].i2c_slave_addr, out, out_size,
- in, in_size, flags);
- if (rv && pd_device_in_low_power(port)) {
- pd_wait_for_wakeup(port);
- rv = i2c_xfer_unlocked(tcpc_config[port].i2c_host_port,
- tcpc_config[port].i2c_slave_addr, out, out_size,
- in, in_size, flags);
- }
+ int rv;
+
+ pd_wait_exit_low_power(port);
+
+ rv = i2c_xfer_unlocked(tcpc_config[port].i2c_host_port,
+ tcpc_config[port].i2c_slave_addr, out,
+ out_size, in, in_size, flags);
+
pd_device_accessed(port);
return rv;
}