diff options
author | Sam Hurst <shurst@google.com> | 2020-05-26 10:20:53 -0700 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2020-07-31 20:54:02 +0000 |
commit | ef839e580d6b7f0107d74dd33fc9ecf05a3c0d0e (patch) | |
tree | eec9decd35a9a15af19145081dc10b41371a02b2 | |
parent | 610ea5b5cbba18dcb01fd47e38d945b324da71fd (diff) | |
download | chrome-ec-ef839e580d6b7f0107d74dd33fc9ecf05a3c0d0e.tar.gz |
servo_v4p1: Add DUT Charge Through functionality
This functionality is only available in RO and
enables the servo V4.1 to charge the DUT.
BRANCH=none
BUG=b:146793000
TEST=make -j buildall
Signed-off-by: Sam Hurst <shurst@google.com>
Change-Id: I317d02081b935d69af712c6189634496f56110f0
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2216404
Reviewed-by: Wai-Hong Tam <waihong@google.com>
(cherry picked from commit 48a55c8b351bc10e5637e90814293a4b7869ac84)
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2332242
-rw-r--r-- | board/servo_v4p1/board.c | 4 | ||||
-rw-r--r-- | board/servo_v4p1/build.mk | 1 | ||||
-rw-r--r-- | board/servo_v4p1/chg_control.c | 78 | ||||
-rw-r--r-- | board/servo_v4p1/chg_control.h | 42 |
4 files changed, 125 insertions, 0 deletions
diff --git a/board/servo_v4p1/board.c b/board/servo_v4p1/board.c index cc6629547d..e8763766cb 100644 --- a/board/servo_v4p1/board.c +++ b/board/servo_v4p1/board.c @@ -7,6 +7,7 @@ #include "adc.h" #include "adc_chip.h" #include "ccd_measure_sbu.h" +#include "chg_control.h" #include "common.h" #include "console.h" #include "ec_version.h" @@ -330,6 +331,9 @@ static void board_init(void) gpio_enable_interrupt(GPIO_USBH_I2C_BUSY_INT); gpio_enable_interrupt(GPIO_BC12_INT_ODL); + /* Disable power to DUT by default */ + chg_power_select(CHG_POWER_OFF); + /* Start SuzyQ detection */ start_ccd_meas_sbu_cycle(); #endif /* SECTION_IS_RO */ diff --git a/board/servo_v4p1/build.mk b/board/servo_v4p1/build.mk index 321c911871..c3161a9c67 100644 --- a/board/servo_v4p1/build.mk +++ b/board/servo_v4p1/build.mk @@ -20,5 +20,6 @@ board-y+=ioexpanders.o # These files are compiled into RO only board-ro+=ccd_measure_sbu.o board-ro+=pathsel.o +board-ro+=chg_control.o all_deps=$(patsubst ro,,$(def_all_deps)) diff --git a/board/servo_v4p1/chg_control.c b/board/servo_v4p1/chg_control.c new file mode 100644 index 0000000000..cddd8efc69 --- /dev/null +++ b/board/servo_v4p1/chg_control.c @@ -0,0 +1,78 @@ +/* Copyright 2020 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. + */ + +#include "chg_control.h" +#include "gpio.h" +#include "ioexpanders.h" +#include "registers.h" +#include "timer.h" + +#define CHG_P5V_POWER 0 +#define CHG_VBUS_POWER 1 + +void chg_reset(void) +{ + /* Disconnect DUT Power */ + chg_power_select(CHG_POWER_OFF); + + /* Disconnect CHG CC1(Rd) and CC2(Rd) */ + chg_attach_cc_rds(0); + + msleep(100); + + /* Connect CHG CC1(Rd) and CC2(Rd) to detect charger */ + chg_attach_cc_rds(1); +} + +void chg_power_select(enum chg_power_select_t type) +{ + switch (type) { + case CHG_POWER_OFF: + dut_chg_en(0); + vbus_dischrg_en(1); + break; + case CHG_POWER_PP5000: + vbus_dischrg_en(0); + host_or_chg_ctl(CHG_P5V_POWER); + dut_chg_en(1); + break; + case CHG_POWER_VBUS: + vbus_dischrg_en(0); + host_or_chg_ctl(CHG_VBUS_POWER); + dut_chg_en(1); + break; + } +} + +void chg_attach_cc_rds(bool en) +{ + if (en) { + /* + * Configure USB_CHG_CC1_MCU and USB_CHG_CC2_MCU as + * ANALOG input + */ + STM32_GPIO_MODER(GPIO_A) = (STM32_GPIO_MODER(GPIO_A) + | (3 << (2*2)) | /* PA2 in ANALOG mode */ + (3 << (2*4))); /* PA4 in ANALOG mode */ + } else { + /* + * Configure USB_CHG_CC1_MCU and USB_CHG_CC2_MCU as GPIO and + * drive high to trigger disconnect. + * NOTE: The CC line has an external fixed Rd pull-down. + * Driving the CC line High overrides the pull down and this + * triggers a disconnection. + */ + /* Set level high */ + gpio_set_level(GPIO_USB_CHG_CC1_MCU, 1); + gpio_set_level(GPIO_USB_CHG_CC2_MCU, 1); + + /* Disable Analog mode and Enable GPO */ + STM32_GPIO_MODER(GPIO_A) = (STM32_GPIO_MODER(GPIO_A) + & ~(3 << (2*2) | /* PA2 disable ADC */ + 3 << (2*4))) /* PA4 disable ADC */ + | (1 << (2*2) | /* Set as GPO */ + 1 << (2*4)); /* Set as GPO */ + } +} diff --git a/board/servo_v4p1/chg_control.h b/board/servo_v4p1/chg_control.h new file mode 100644 index 0000000000..8b81708ccc --- /dev/null +++ b/board/servo_v4p1/chg_control.h @@ -0,0 +1,42 @@ +/* Copyright 2020 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. + */ + +#ifndef __CROS_EC_CHG_CONTROL_H +#define __CROS_EC_CHG_CONTROL_H + +#include <stdbool.h> + +enum chg_cc_t { + CHG_OPEN, + CHG_CC1, + CHG_CC2 +}; + +enum chg_power_select_t { + CHG_POWER_OFF, + CHG_POWER_PP5000, + CHG_POWER_VBUS, +}; + +/* + * Triggers a disconnect and reconnect on the DUT Charger port + */ +void chg_reset(void); + +/* + * Disables or selects the DUT Charger Power source + * + * @param type Power source used for DUT + */ +void chg_power_select(enum chg_power_select_t type); + +/* + * Attaches or Removes the DUT Charger Ports CC1 and CC2 Rd resistors + * + * @param en True the CC RDs are attached else they are removed + */ +void chg_attach_cc_rds(bool en); + +#endif /* __CROS_EC_CHG_CONTROL_H */ |