summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShawn Nematbakhsh <shawnn@chromium.org>2015-01-20 18:40:05 -0800
committerChromeOS Commit Bot <chromeos-commit-bot@chromium.org>2015-01-21 06:44:41 +0000
commit2f6f8b35480857a96ac77162155297cb80c9480d (patch)
tree63fa8b9237069cc5f4e606c4204dc1eb816374fb
parent194bde63670528c456bcc3b5701d64fd01f8fc1d (diff)
downloadchrome-ec-2f6f8b35480857a96ac77162155297cb80c9480d.tar.gz
pi3usb9281: Lock access to MUX GPIO while in use
Lock access to the MUX GPIO to prevent other tasks from toggling away from our active chip while in use. BUG=chrome-os-partner:35567 TEST=Manual on samus_pd. Boot system, verify that no "write failed" print is seen. Also verify that charger detection functions as expected. BRANCH=Samus Change-Id: Ica02b8fbd8f9ee04f6389ce0b0e5bd58104ff698 Signed-off-by: Shawn Nematbakhsh <shawnn@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/242125 Reviewed-by: Alec Berg <alecaberg@chromium.org>
-rw-r--r--driver/usb_switch_pi3usb9281.c14
1 files changed, 14 insertions, 0 deletions
diff --git a/driver/usb_switch_pi3usb9281.c b/driver/usb_switch_pi3usb9281.c
index fd7eecd4d4..d04ea09b8a 100644
--- a/driver/usb_switch_pi3usb9281.c
+++ b/driver/usb_switch_pi3usb9281.c
@@ -9,6 +9,7 @@
#include "gpio.h"
#include "hooks.h"
#include "i2c.h"
+#include "task.h"
#include "timer.h"
#include "pi3usb9281.h"
#include "util.h"
@@ -25,13 +26,22 @@
#ifdef CONFIG_USB_SWITCH_PI3USB9281_MUX_GPIO
#define PI3USB9281_COUNT 2
+struct mutex mux_lock;
static inline void select_chip(uint8_t chip_idx)
{
+ mutex_lock(&mux_lock);
gpio_set_level(CONFIG_USB_SWITCH_PI3USB9281_MUX_GPIO, chip_idx);
}
+
+static inline void unselect_chip(void)
+{
+ /* Just release the mutex, no need to change the mux gpio */
+ mutex_unlock(&mux_lock);
+}
#else
#define PI3USB9281_COUNT 1
#define select_chip(x)
+#define unselect_chip()
#endif
static int saved_interrupts[PI3USB9281_COUNT];
@@ -42,6 +52,8 @@ uint8_t pi3usb9281_read(uint8_t chip_idx, uint8_t reg)
select_chip(chip_idx);
res = i2c_read8(I2C_PORT_MASTER, PI3USB9281_I2C_ADDR, reg, &val);
+ unselect_chip();
+
if (res)
return 0xee;
@@ -54,6 +66,8 @@ int pi3usb9281_write(uint8_t chip_idx, uint8_t reg, uint8_t val)
select_chip(chip_idx);
res = i2c_write8(I2C_PORT_MASTER, PI3USB9281_I2C_ADDR, reg, val);
+ unselect_chip();
+
if (res)
CPRINTS("PI3USB9281 I2C write failed");
return res;