summaryrefslogtreecommitdiff
path: root/chip/stm32
diff options
context:
space:
mode:
authorMary Ruthven <mruthven@chromium.org>2016-02-23 14:56:28 -0800
committerchrome-bot <chrome-bot@chromium.org>2016-02-26 21:22:07 -0800
commit9b4f662a8e139a75dc1557d4ccbf6348b43630d8 (patch)
tree44ffc60123897ac0adc0df028814b74a171cea05 /chip/stm32
parent60552e57b61d036edbb628fcd1debbf0ec087e6e (diff)
downloadchrome-ec-9b4f662a8e139a75dc1557d4ccbf6348b43630d8.tar.gz
lucid: add support to detect BC1.2 suppliers
Use built-in USB periperal to detect BC1.2 suppliers and update the charge manager. BUG=chrome-os-partner:48658 BRANCH=None TEST=manual for lucid. Use a samus as the supplier, and insert the charger into Lucid. Verify that it identifies it as SDP. Use a wall charger and verify that Lucid identifies it as DCP. Change-Id: I7842e9f75874f727837df5bfc28690662caf821c Signed-off-by: Mary Ruthven <mruthven@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/329236 Reviewed-by: Shawn N <shawnn@chromium.org>
Diffstat (limited to 'chip/stm32')
-rw-r--r--chip/stm32/build.mk1
-rw-r--r--chip/stm32/charger_detect.c55
-rw-r--r--chip/stm32/registers.h9
3 files changed, 65 insertions, 0 deletions
diff --git a/chip/stm32/build.mk b/chip/stm32/build.mk
index 53b48b6ab5..6878c76065 100644
--- a/chip/stm32/build.mk
+++ b/chip/stm32/build.mk
@@ -50,6 +50,7 @@ chip-$(CHIP_FAMILY_STM32F0)+=flash-f.o
chip-$(CHIP_FAMILY_STM32F3)+=flash-f.o
endif
chip-$(CONFIG_ADC)+=adc-$(CHIP_FAMILY).o
+chip-$(CONFIG_STM32_CHARGER_DETECT)+=charger_detect.o
chip-$(CONFIG_DEBUG_PRINTF)+=debug_printf.o
chip-$(CONFIG_PWM)+=pwm.o
chip-$(CONFIG_USB)+=usb.o usb-$(CHIP_FAMILY).o usb_endpoints.o
diff --git a/chip/stm32/charger_detect.c b/chip/stm32/charger_detect.c
new file mode 100644
index 0000000000..b32b9f3ac0
--- /dev/null
+++ b/chip/stm32/charger_detect.c
@@ -0,0 +1,55 @@
+/* Copyright 2016 The Chromium OS Authors. All rights reserved.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+/* Detect what adapter is connected */
+
+#include "charge_manager.h"
+#include "hooks.h"
+#include "registers.h"
+#include "timer.h"
+
+static void enable_usb(void)
+{
+ /* Enable USB device clock. */
+ STM32_RCC_APB1ENR |= STM32_RCC_PB1_USB;
+}
+DECLARE_HOOK(HOOK_INIT, enable_usb, HOOK_PRIO_DEFAULT);
+
+static void disable_usb(void)
+{
+ /* Disable USB device clock. */
+ STM32_RCC_APB1ENR &= ~STM32_RCC_PB1_USB;
+}
+DECLARE_HOOK(HOOK_SYSJUMP, disable_usb, HOOK_PRIO_DEFAULT);
+
+static uint16_t detect_type(uint16_t det_type)
+{
+ STM32_USB_BCDR &= 0;
+ usleep(1);
+ STM32_USB_BCDR |= (STM32_USB_BCDR_BCDEN | det_type);
+ usleep(1);
+ STM32_USB_BCDR &= ~(STM32_USB_BCDR_BCDEN | det_type);
+ return STM32_USB_BCDR;
+}
+
+
+int charger_detect_get_device_type(void)
+{
+ uint16_t pdet_result;
+
+ if (!(detect_type(STM32_USB_BCDR_DCDEN) & STM32_USB_BCDR_DCDET))
+ return CHARGE_SUPPLIER_PD;
+
+ pdet_result = detect_type(STM32_USB_BCDR_PDEN);
+ /* TODO: add support for detecting proprietary chargers. */
+ if (pdet_result & STM32_USB_BCDR_PDET) {
+ if (detect_type(STM32_USB_BCDR_SDEN) & STM32_USB_BCDR_SDET)
+ return CHARGE_SUPPLIER_BC12_DCP;
+ else
+ return CHARGE_SUPPLIER_BC12_CDP;
+ } else if (pdet_result & STM32_USB_BCDR_PS2DET)
+ return CHARGE_SUPPLIER_PROPRIETARY;
+ else
+ return CHARGE_SUPPLIER_BC12_SDP;
+}
diff --git a/chip/stm32/registers.h b/chip/stm32/registers.h
index 57fb2a9ec0..283fd44498 100644
--- a/chip/stm32/registers.h
+++ b/chip/stm32/registers.h
@@ -1327,6 +1327,15 @@ typedef volatile struct stm32_dma_regs stm32_dma_regs_t;
#define STM32_USB_LPMCSR REG16(STM32_USB_FS_BASE + 0x54)
#define STM32_USB_BCDR REG16(STM32_USB_FS_BASE + 0x58)
+#define STM32_USB_BCDR_BCDEN (1 << 0)
+#define STM32_USB_BCDR_DCDEN (1 << 1)
+#define STM32_USB_BCDR_PDEN (1 << 2)
+#define STM32_USB_BCDR_SDEN (1 << 3)
+#define STM32_USB_BCDR_DCDET (1 << 4)
+#define STM32_USB_BCDR_PDET (1 << 5)
+#define STM32_USB_BCDR_SDET (1 << 6)
+#define STM32_USB_BCDR_PS2DET (1 << 7)
+
#define EP_MASK 0x0F0F
#define EP_TX_DTOG 0x0040
#define EP_TX_MASK 0x0030