summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaisuke Nojiri <dnojiri@chromium.org>2019-03-13 09:28:31 -0700
committerchrome-bot <chrome-bot@chromium.org>2019-04-18 19:51:08 -0700
commitfc2ab5234189258cabc64590b1433545e2cf94fb (patch)
treede73e3abad8446aac398de6ee234f2c3cc0fe485
parent8bd447af96dcbf7d714ad23f65835d09332fcfc1 (diff)
downloadchrome-ec-fc2ab5234189258cabc64590b1433545e2cf94fb.tar.gz
Flapjack: Cut off battery when USB-C board isn't connected
Currently, when a battery is connected, the device boots immediately. This makes assembly process unreliable. This patch makes EC cut off a battery at start-up if USBC_THERM reads about the pull-up voltage because that indicates a USB-C board isn't connected, which means the devices is being assembled. Signed-off-by: Daisuke Nojiri <dnojiri@chromium.org> BUG=b/124540674 BRANCH=none TEST=Verify a battery is cut off when a USB-C board isn't connected. Verify a battery isn't cut off when a USB-C board is connected. TEST=Verify ADC reads 715 mV even when the thermistor is iced. Change-Id: Iadc756f8705abe083a5d56b5d8ad080dbff15b6a Reviewed-on: https://chromium-review.googlesource.com/1520950 Commit-Ready: Daisuke Nojiri <dnojiri@chromium.org> Tested-by: Daisuke Nojiri <dnojiri@chromium.org> Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org>
-rw-r--r--board/flapjack/board.c26
1 files changed, 25 insertions, 1 deletions
diff --git a/board/flapjack/board.c b/board/flapjack/board.c
index 02d0538363..a1a83e4e22 100644
--- a/board/flapjack/board.c
+++ b/board/flapjack/board.c
@@ -161,7 +161,8 @@ const struct adc_t adc_channels[] = {
[ADC_LCM_ID] = {"LCM_ID", 3300, 4096, 0, STM32_AIN(10)},
[ADC_EC_SKU_ID] = {"EC_SKU_ID", 3300, 4096, 0, STM32_AIN(8)},
[ADC_BATT_ID] = {"BATT_ID", 3300, 4096, 0, STM32_AIN(7)},
- [ADC_USBC_THERM] = {"USBC_THERM", 3300, 4096, 0, STM32_AIN(14)},
+ [ADC_USBC_THERM] = {"USBC_THERM", 3300, 4096, 0, STM32_AIN(14),
+ STM32_ADC_SMPR_239_5_CY},
};
BUILD_ASSERT(ARRAY_SIZE(adc_channels) == ADC_CH_COUNT);
@@ -292,8 +293,31 @@ int pd_snk_is_vbus_provided(int port)
return rt946x_is_vbus_ready();
}
+/*
+ * Threshold to detect USB-C board. If the USB-C board isn't connected,
+ * USBC_THERM is floating thus the ADC pin should read about the pull-up
+ * voltage. If it's connected, the voltage is capped by the resistor (429k)
+ * place in parallel to the thermistor. 3.3V x 429k/(39k + 429k) = 3.025V
+ */
+#define USBC_THERM_THRESHOLD 3025
+
static void board_init(void)
{
+#ifdef SECTION_IS_RO
+ /* If USB-C board isn't connected, the device is being assembled.
+ * We cut off the battery until the assembly is done for better yield.
+ * Timing is ok because STM32F0 initializes ADC on demand. */
+ if (board_version > 0x02) {
+ int mv = adc_read_channel(ADC_USBC_THERM);
+ if (mv == ADC_READ_ERROR)
+ mv = adc_read_channel(ADC_USBC_THERM);
+ CPRINTS("USBC_THERM=%d", mv);
+ if (mv > USBC_THERM_THRESHOLD) {
+ cflush();
+ board_cut_off_battery();
+ }
+ }
+#endif
/* Set SPI1 PB13/14/15 pins to high speed */
STM32_GPIO_OSPEEDR(GPIO_B) |= 0xfc000000;