summaryrefslogtreecommitdiff
path: root/board/coffeecake
diff options
context:
space:
mode:
authorRong Chang <rongchang@chromium.org>2017-11-08 16:57:44 +0800
committerchrome-bot <chrome-bot@chromium.org>2017-11-29 04:04:14 -0800
commitd39678345b93b37ce83630ac41ddc7e9c35b64d0 (patch)
tree73f9ce870234d1905dec33372a52481297724954 /board/coffeecake
parent23292a8322e04459630c614f34d6ea11eb0cb7ad (diff)
downloadchrome-ec-d39678345b93b37ce83630ac41ddc7e9c35b64d0.tar.gz
coffeecake: Workaround P0 EN_USB_PD leakage
EN_USB_PD leaks ~1V to C0_VBUS. This change turns on PD_DISCHARGE when C0_VBUS is low. BRANCH=none BUG=b:67910512 TEST=manual load on coffeecake, boot into SRC mode, check C0_VBUS voltage. Change-Id: Ia650ee83c8fef4228d3bb2f7ec5f9eab3e16bf4d Signed-off-by: Rong Chang <rongchang@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/758318 Reviewed-by: Benson Leung <bleung@chromium.org>
Diffstat (limited to 'board/coffeecake')
-rw-r--r--board/coffeecake/board.c38
-rw-r--r--board/coffeecake/gpio.inc6
-rw-r--r--board/coffeecake/usb_pd_policy.c12
3 files changed, 39 insertions, 17 deletions
diff --git a/board/coffeecake/board.c b/board/coffeecake/board.c
index bc44f07a00..11b4180c0e 100644
--- a/board/coffeecake/board.c
+++ b/board/coffeecake/board.c
@@ -27,6 +27,7 @@ static volatile uint64_t hpd_prev_ts;
static volatile int hpd_prev_level;
void hpd_event(enum gpio_signal signal);
+void vbus_event(enum gpio_signal signal);
#include "gpio_list.h"
/* I2C ports */
@@ -102,6 +103,13 @@ void hpd_event(enum gpio_signal signal)
hpd_prev_level = level;
}
+/* Proto 0 workaround */
+void vbus_event(enum gpio_signal signal)
+{
+ /* Discharge VBUS on DET_L high */
+ gpio_set_level(GPIO_PD_DISCHARGE, gpio_get_level(signal));
+}
+
/* USB C VBUS output selection */
void board_set_usb_output_voltage(int mv)
{
@@ -111,15 +119,21 @@ void board_set_usb_output_voltage(int mv)
int dac_mv;
uint32_t dac_val;
- /* vbat = 1.0 * ra/rb + 1.0 - (vdac - 1.0) * ra/rc */
- dac_mv = 1000 + (1000 * rc / rb) + ((1000 - mv) * rc / ra);
- if (dac_mv < 0)
- dac_mv = 0;
-
- /* Set voltage Vout=Vdac with Vref = 3.3v */
- /* TODO: use Vdda instead */
- dac_val = dac_mv * 4096 / 3300;
- STM32_DAC_DHR12RD = dac_val | (dac_val << 16);
+ if (mv >= 0) {
+ /* vbat = 1.0 * ra/rb + 1.0 - (vdac - 1.0) * ra/rc */
+ dac_mv = 1000 + (1000 * rc / rb) + ((1000 - mv) * rc / ra);
+ if (dac_mv < 0)
+ dac_mv = 0;
+
+ /* Set voltage Vout=Vdac with Vref = 3.3v */
+ /* TODO: use Vdda instead */
+ dac_val = dac_mv * 4096 / 3300;
+ /* Start DAC channel 2 */
+ STM32_DAC_DHR12RD = dac_val << 16;
+ STM32_DAC_CR = STM32_DAC_CR_EN2;
+ } else {
+ STM32_DAC_CR = 0;
+ }
}
/* Initialize board. */
@@ -131,8 +145,6 @@ void board_config_pre_init(void)
STM32_RCC_APB1ENR |= (1 << 29);
/* Delay 1 APB clock cycle after the clock is enabled */
clock_wait_bus_cycles(BUS_APB, 1);
- /* Start DAC channel 1 & 2 */
- STM32_DAC_CR = STM32_DAC_CR_EN1 | STM32_DAC_CR_EN2;
/* Set 5Vsafe Vdac */
board_set_usb_output_voltage(5000);
/* Remap USART DMA to match the USART driver */
@@ -213,6 +225,10 @@ static void board_init(void)
hpd_prev_level = gpio_get_level(GPIO_DP_HPD);
hpd_prev_ts = now.val;
gpio_enable_interrupt(GPIO_DP_HPD);
+ gpio_enable_interrupt(GPIO_CHARGER_INT);
+ gpio_enable_interrupt(GPIO_USB_C_VBUS_DET_L);
+ /* Set PD_DISCHARGE initial state */
+ gpio_set_level(GPIO_PD_DISCHARGE, gpio_get_level(GPIO_USB_C_VBUS_DET_L));
/* Delay needed to allow HDMI MCU to boot. */
hook_call_deferred(&factory_validation_deferred_data, 200*MSEC);
diff --git a/board/coffeecake/gpio.inc b/board/coffeecake/gpio.inc
index bc0fea43e2..0c1665a5d9 100644
--- a/board/coffeecake/gpio.inc
+++ b/board/coffeecake/gpio.inc
@@ -8,8 +8,9 @@
/* Declare symbolic names for all the GPIOs that we care about.
* Note: Those with interrupt handlers must be declared first. */
-GPIO_INT(DP_HPD, PIN(A, 0), GPIO_INT_BOTH, hpd_event)
-GPIO_INT(CHARGER_INT, PIN(C, 13), GPIO_INT_FALLING, sy21612_int)
+GPIO_INT(DP_HPD, PIN(A, 0), GPIO_INT_BOTH, hpd_event)
+GPIO_INT(CHARGER_INT, PIN(C, 13), GPIO_INT_FALLING, sy21612_int)
+GPIO_INT(USB_C_VBUS_DET_L, PIN(C, 14), GPIO_INT_BOTH, vbus_event)
GPIO(USB_C_CC1_PD, PIN(A, 1), GPIO_ANALOG)
GPIO(VBUS_DIV4_MON, PIN(A, 2), GPIO_ANALOG)
@@ -35,7 +36,6 @@ GPIO(I2C0_SDA, PIN(B, 7), GPIO_INPUT)
GPIO(LED_ORANGE, PIN(B, 9), GPIO_OUT_LOW)
GPIO(PD_MCDP_SPI_CS_L, PIN(B, 12), GPIO_INPUT)
-GPIO(USB_C_VBUS_DET_L, PIN(C, 14), GPIO_INPUT)
GPIO(AC_PRESENT_L, PIN(C, 15), GPIO_INPUT)
GPIO(EN_PP5000, PIN(F, 0), GPIO_OUT_HIGH)
diff --git a/board/coffeecake/usb_pd_policy.c b/board/coffeecake/usb_pd_policy.c
index b0fb437bd6..660e45e90e 100644
--- a/board/coffeecake/usb_pd_policy.c
+++ b/board/coffeecake/usb_pd_policy.c
@@ -83,19 +83,25 @@ void pd_transition_voltage(int idx)
int pd_set_power_supply_ready(int port)
{
+ /* Turn on DAC and adjust feedback to get 5V output */
+ board_set_usb_output_voltage(5000);
+ /* Enable Vsys to USBC Vbus charging */
sy21612_set_sink_mode(1);
- sy21612_set_vbus_volt(SY21612_VBUS_9V);
sy21612_set_adc_mode(1);
sy21612_enable_adc(1);
- sy21612_set_vbus_discharge(1);
+ sy21612_set_vbus_discharge(0);
return EC_SUCCESS;
}
void pd_power_supply_reset(int port)
{
- board_set_usb_output_voltage(5000);
+ /* Turn off DAC output */
+ board_set_usb_output_voltage(-1);
+ /* Turn off USBC VBUS output */
sy21612_set_sink_mode(0);
+ /* Set boost Vsys output 9V */
sy21612_set_vbus_volt(SY21612_VBUS_9V);
+ /* Turn on buck-boost converter ADC */
sy21612_set_adc_mode(1);
sy21612_enable_adc(1);
sy21612_set_vbus_discharge(1);