From a25d675bc00fdbde0f30b31af4a58a9616aa8eed Mon Sep 17 00:00:00 2001 From: Vic Yang Date: Mon, 18 Aug 2014 10:16:21 -0700 Subject: [PATCH] samus_pd: Enable both comparator at the same time We use window mode to share the non-inverting input of the two comparators. If COMP1 is not enabled, it causes problem on the operation of COMP2. Fix this by enabling both comparator at the same time. BUG=chrome-os-partner:31400 TEST=Reboot PD MCU, and plug into port 1. See SNK_READY state. BRANCH=None Change-Id: Icb7e7acdb8a09e094c24839c1d7b398b2c3fb9c0 Signed-off-by: Vic Yang Reviewed-on: https://chromium-review.googlesource.com/212921 Reviewed-by: Alec Berg --- board/samus_pd/usb_pd_config.h | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/board/samus_pd/usb_pd_config.h b/board/samus_pd/usb_pd_config.h index 60925b3077..c6ec62e2cf 100644 --- a/board/samus_pd/usb_pd_config.h +++ b/board/samus_pd/usb_pd_config.h @@ -162,19 +162,21 @@ static inline void pd_tx_disable(int port, int polarity) /* we know the plug polarity, do the right configuration */ static inline void pd_select_polarity(int port, int polarity) { + uint32_t val = STM32_COMP_CSR; + + /* Use window mode so that COMP1 and COMP2 share non-inverting input */ + val |= STM32_COMP_CMP1EN | STM32_COMP_CMP2EN | STM32_COMP_WNDWEN; + if (port == 0) { /* use the right comparator inverted input for COMP1 */ - STM32_COMP_CSR = (STM32_COMP_CSR & ~STM32_COMP_CMP1INSEL_MASK) - | STM32_COMP_CMP1EN - | (polarity ? STM32_COMP_CMP1INSEL_INM4 - : STM32_COMP_CMP1INSEL_INM6); + STM32_COMP_CSR = (val & ~STM32_COMP_CMP1INSEL_MASK) | + (polarity ? STM32_COMP_CMP1INSEL_INM4 + : STM32_COMP_CMP1INSEL_INM6); } else { /* use the right comparator inverted input for COMP2 */ - /* use window mode on COMP2 to use COMP1 non-inverting input */ - STM32_COMP_CSR = (STM32_COMP_CSR & ~STM32_COMP_CMP2INSEL_MASK) - | STM32_COMP_CMP2EN | STM32_COMP_WNDWEN - | (polarity ? STM32_COMP_CMP2INSEL_INM5 - : STM32_COMP_CMP2INSEL_INM6); + STM32_COMP_CSR = (val & ~STM32_COMP_CMP2INSEL_MASK) | + (polarity ? STM32_COMP_CMP2INSEL_INM5 + : STM32_COMP_CMP2INSEL_INM6); } }