From c0be4409522bc53447940ac88aff455a6844427c Mon Sep 17 00:00:00 2001 From: Shawn Nematbakhsh Date: Thu, 5 Feb 2015 10:00:05 -0800 Subject: pi3usb9281: Fix handling of REG_CONTROL (02H) reserved bits REG_CONTROL has two sets of reserved bits: - Bits 5 thru 7 are read x, write 0. - Bits 1 and 3 have undocumented function and should not be changed from read value. BUG=chrome-os-partner:36360 TEST=Manual on Samus. Cold boot unit and insert 2.4A charger. Verify that charger is correctly detected. BRANCH=Samus Change-Id: I240d352817910eda404b72be13e2c913a4b76079 Signed-off-by: Shawn Nematbakhsh Reviewed-on: https://chromium-review.googlesource.com/246560 Reviewed-by: Alec Berg --- driver/pi3usb9281.h | 4 +++- driver/usb_switch_pi3usb9281.c | 33 +++++++++++++++++++-------------- 2 files changed, 22 insertions(+), 15 deletions(-) diff --git a/driver/pi3usb9281.h b/driver/pi3usb9281.h index f07575cc71..49a078ee6f 100644 --- a/driver/pi3usb9281.h +++ b/driver/pi3usb9281.h @@ -21,9 +21,11 @@ #define PI3USB9281_DEV_ID 0x10 #define PI3USB9281_DEV_ID_A 0x18 -#define PI3USB9281_CTRL_INT_MASK (1 << 0) +#define PI3USB9281_CTRL_INT_DIS (1 << 0) #define PI3USB9281_CTRL_AUTO (1 << 2) #define PI3USB9281_CTRL_SWITCH_AUTO (1 << 4) +/* Bits 5 thru 7 are read X, write 0 */ +#define PI3USB9281_CTRL_MASK 0x1f #define PI3USB9281_PIN_MANUAL_VBUS (3 << 0) #define PI3USB9281_PIN_MANUAL_DP (1 << 2) diff --git a/driver/usb_switch_pi3usb9281.c b/driver/usb_switch_pi3usb9281.c index d04ea09b8a..2c69d2471e 100644 --- a/driver/usb_switch_pi3usb9281.c +++ b/driver/usb_switch_pi3usb9281.c @@ -75,24 +75,27 @@ int pi3usb9281_write(uint8_t chip_idx, uint8_t reg, uint8_t val) int pi3usb9281_enable_interrupts(uint8_t chip_idx) { - int ctrl = pi3usb9281_read(chip_idx, PI3USB9281_REG_CONTROL); + uint8_t ctrl = pi3usb9281_read(chip_idx, PI3USB9281_REG_CONTROL); if (ctrl == 0xee) return EC_ERROR_UNKNOWN; - return pi3usb9281_write(chip_idx, PI3USB9281_REG_CONTROL, ctrl & 0x14); + return pi3usb9281_write(chip_idx, PI3USB9281_REG_CONTROL, + ctrl & ~PI3USB9281_CTRL_INT_DIS & + PI3USB9281_CTRL_MASK); } int pi3usb9281_disable_interrupts(uint8_t chip_idx) { - int ctrl = pi3usb9281_read(chip_idx, PI3USB9281_REG_CONTROL); + uint8_t ctrl = pi3usb9281_read(chip_idx, PI3USB9281_REG_CONTROL); int rv; if (ctrl == 0xee) return EC_ERROR_UNKNOWN; rv = pi3usb9281_write(chip_idx, PI3USB9281_REG_CONTROL, - (ctrl | PI3USB9281_CTRL_INT_MASK) & 0x15); + (ctrl | PI3USB9281_CTRL_INT_DIS) & + PI3USB9281_CTRL_MASK); pi3usb9281_get_interrupts(chip_idx); return rv; } @@ -177,21 +180,18 @@ int pi3usb9281_reset(uint8_t chip_idx) int pi3usb9281_set_switch_manual(uint8_t chip_idx, int val) { - int ctrl; - int rv; + uint8_t ctrl = pi3usb9281_read(chip_idx, PI3USB9281_REG_CONTROL); - ctrl = pi3usb9281_read(chip_idx, PI3USB9281_REG_CONTROL); if (ctrl == 0xee) return EC_ERROR_UNKNOWN; if (val) - rv = pi3usb9281_write(chip_idx, PI3USB9281_REG_CONTROL, - ctrl & ~PI3USB9281_CTRL_AUTO); + ctrl &= ~PI3USB9281_CTRL_AUTO; else - rv = pi3usb9281_write(chip_idx, PI3USB9281_REG_CONTROL, - ctrl | PI3USB9281_CTRL_AUTO); + ctrl |= PI3USB9281_CTRL_AUTO; - return rv; + return pi3usb9281_write(chip_idx, PI3USB9281_REG_CONTROL, + ctrl & PI3USB9281_CTRL_MASK); } int pi3usb9281_set_pins(uint8_t chip_idx, uint8_t val) @@ -201,13 +201,18 @@ int pi3usb9281_set_pins(uint8_t chip_idx, uint8_t val) int pi3usb9281_set_switches(uint8_t chip_idx, int open) { - uint8_t ctrl = pi3usb9281_read(chip_idx, PI3USB9281_REG_CONTROL) & 0x15; + uint8_t ctrl = pi3usb9281_read(chip_idx, PI3USB9281_REG_CONTROL); + + if (ctrl == 0xee) + return EC_ERROR_UNKNOWN; + if (open) ctrl &= ~PI3USB9281_CTRL_SWITCH_AUTO; else ctrl |= PI3USB9281_CTRL_SWITCH_AUTO; - return pi3usb9281_write(chip_idx, PI3USB9281_REG_CONTROL, ctrl); + return pi3usb9281_write(chip_idx, PI3USB9281_REG_CONTROL, + ctrl & PI3USB9281_CTRL_MASK); } static void pi3usb9281_init(void) -- cgit v1.2.1