diff options
author | Jett Rink <jettrink@chromium.org> | 2018-03-08 13:45:23 -0700 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2018-03-09 20:05:12 -0800 |
commit | b593d1c05b150fdad68c474ef0e521d5d9c3acea (patch) | |
tree | 546dcfa832ba504bb4fed52d2fd6c2ea79edd2b2 | |
parent | bc766130becff13136baa53070749899dce687f6 (diff) | |
download | chrome-ec-b593d1c05b150fdad68c474ef0e521d5d9c3acea.tar.gz |
bc12: add support for active low/high on all gpio signals
yorp inverts both bc12 signals and the bc12 driver needs to handle
the inverted logic
BRANCH=none
BUG=b:74127309
TEST=none
Change-Id: I6848375fc652251aecb553c3f53d62a5f775bec4
Signed-off-by: Jett Rink <jettrink@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/956321
Reviewed-by: Aseda Aboagye <aaboagye@chromium.org>
-rw-r--r-- | board/grunt/board.c | 15 | ||||
-rw-r--r-- | board/yorp/board.c | 15 | ||||
-rw-r--r-- | board/yorp/board.h | 6 | ||||
-rw-r--r-- | board/zoombini/board.c | 20 | ||||
-rw-r--r-- | driver/bc12/bq24392.c | 59 | ||||
-rw-r--r-- | driver/bc12/bq24392.h | 31 |
6 files changed, 119 insertions, 27 deletions
diff --git a/board/grunt/board.c b/board/grunt/board.c index d87f074e09..597ff0fa10 100644 --- a/board/grunt/board.c +++ b/board/grunt/board.c @@ -17,6 +17,7 @@ #include "driver/accel_kionix.h" #include "driver/accel_kx022.h" #include "driver/accelgyro_bmi160.h" +#include "driver/bc12/bq24392.h" #include "driver/led/lm3630a.h" #include "driver/ppc/sn5s330.h" #include "driver/tcpm/anx74xx.h" @@ -200,6 +201,20 @@ const struct ppc_config_t ppc_chips[] = { }; const unsigned int ppc_cnt = ARRAY_SIZE(ppc_chips); +/* BC 1.2 chip Configuration */ +const struct bq24392_config_t bq24392_config[CONFIG_USB_PD_PORT_COUNT] = { + [USB_PD_PORT_ANX74XX] = { + .chip_enable_pin = GPIO_USB_C0_BC12_VBUS_ON_L, + .chg_det_pin = GPIO_USB_C0_BC12_CHG_DET, + .flags = BQ24392_FLAGS_ENABLE_ACTIVE_LOW, + }, + [USB_PD_PORT_PS8751] = { + .chip_enable_pin = GPIO_USB_C1_BC12_VBUS_ON_L, + .chg_det_pin = GPIO_USB_C1_BC12_CHG_DET, + .flags = BQ24392_FLAGS_ENABLE_ACTIVE_LOW, + }, +}; + const int usb_port_enable[CONFIG_USB_PORT_POWER_SMART_PORT_COUNT] = { GPIO_EN_USB_A0_5V, GPIO_EN_USB_A1_5V, diff --git a/board/yorp/board.c b/board/yorp/board.c index ef2ac11afa..2423998dac 100644 --- a/board/yorp/board.c +++ b/board/yorp/board.c @@ -8,6 +8,7 @@ #include "adc.h" #include "adc_chip.h" #include "common.h" +#include "driver/bc12/bq24392.h" #include "driver/charger/bd9995x.h" #include "driver/tcpm/anx74xx.h" #include "driver/tcpm/ps8xxx.h" @@ -197,3 +198,17 @@ const struct ppc_config_t ppc_chips[CONFIG_USB_PD_PORT_COUNT] = { }, }; const unsigned int ppc_cnt = ARRAY_SIZE(ppc_chips); + +/* BC 1.2 chip Configuration */ +const struct bq24392_config_t bq24392_config[CONFIG_USB_PD_PORT_COUNT] = { + [USB_PD_PORT_ANX74XX] = { + .chip_enable_pin = GPIO_USB_C0_BC12_VBUS_ON, + .chg_det_pin = GPIO_USB_C0_BC12_CHG_DET_L, + .flags = BQ24392_FLAGS_CHG_DET_ACTIVE_LOW, + }, + [USB_PD_PORT_PS8751] = { + .chip_enable_pin = GPIO_USB_C1_BC12_VBUS_ON, + .chg_det_pin = GPIO_USB_C1_BC12_CHG_DET_L, + .flags = BQ24392_FLAGS_CHG_DET_ACTIVE_LOW, + }, +}; diff --git a/board/yorp/board.h b/board/yorp/board.h index ffdc8c0b84..e0db5dbfe6 100644 --- a/board/yorp/board.h +++ b/board/yorp/board.h @@ -11,12 +11,6 @@ /* TODO, Fast follow: make a new config option that uses port */ #define ADC_VBUS ADC_VBUS_C0 -/* TODO, Fast follow: update BC 1.2 driver to handle inverted signals */ -#define GPIO_USB_C0_BC12_VBUS_ON_L GPIO_USB_C0_BC12_VBUS_ON -#define GPIO_USB_C0_BC12_CHG_DET GPIO_USB_C0_BC12_CHG_DET_L -#define GPIO_USB_C1_BC12_VBUS_ON_L GPIO_USB_C1_BC12_VBUS_ON -#define GPIO_USB_C1_BC12_CHG_DET GPIO_USB_C1_BC12_CHG_DET_L - /* Optional features */ #define CONFIG_SYSTEM_UNLOCKED /* Allow dangerous commands while in dev. */ diff --git a/board/zoombini/board.c b/board/zoombini/board.c index d8c8b11323..df89ca2d94 100644 --- a/board/zoombini/board.c +++ b/board/zoombini/board.c @@ -14,6 +14,7 @@ #include "console.h" #include "compile_time_macros.h" #include "driver/als_opt3001.h" +#include "driver/bc12/bq24392.h" #include "driver/led/lm3630a.h" #include "driver/pmic_tps650x30.h" #include "driver/ppc/sn5s330.h" @@ -269,6 +270,25 @@ const struct ppc_config_t ppc_chips[] = { const unsigned int ppc_cnt = ARRAY_SIZE(ppc_chips); #ifdef BOARD_ZOOMBINI +/* BC 1.2 chip Configuration */ +const struct bq24392_config_t bq24392_config[CONFIG_USB_PD_PORT_COUNT] = { + { + .chip_enable_pin = GPIO_USB_C0_BC12_VBUS_ON_L, + .chg_det_pin = GPIO_USB_C0_BC12_CHG_DET, + .flags = BQ24392_FLAGS_ENABLE_ACTIVE_LOW, + }, + { + .chip_enable_pin = GPIO_USB_C1_BC12_VBUS_ON_L, + .chg_det_pin = GPIO_USB_C1_BC12_CHG_DET, + .flags = BQ24392_FLAGS_ENABLE_ACTIVE_LOW, + }, + { + .chip_enable_pin = GPIO_USB_C2_BC12_VBUS_ON_L, + .chg_det_pin = GPIO_USB_C2_BC12_CHG_DET, + .flags = BQ24392_FLAGS_ENABLE_ACTIVE_LOW, + }, +}; + /* GPIO to enable/disable the USB Type-A port. */ const int usb_port_enable[CONFIG_USB_PORT_POWER_SMART_PORT_COUNT] = { GPIO_USB_A_5V_EN, diff --git a/driver/bc12/bq24392.c b/driver/bc12/bq24392.c index 8f97ad704f..354305883a 100644 --- a/driver/bc12/bq24392.c +++ b/driver/bc12/bq24392.c @@ -12,6 +12,7 @@ * the system will have to charge ramp. */ +#include "bq24392.h" #include "cannonlake.h" #include "charge_manager.h" #include "chipset.h" @@ -26,20 +27,35 @@ #include "usb_pd.h" #include "util.h" -struct bq24392_pins { - enum gpio_signal chip_enable_l; - enum gpio_signal chg_det; -}; +#define CPRINTS(format, args...) cprints(CC_USBPD, format, ## args) -static const struct bq24392_pins pin_tbl[] = { - { GPIO_USB_C0_BC12_VBUS_ON_L, GPIO_USB_C0_BC12_CHG_DET }, -#ifdef HAS_TASK_USB_CHG_P1 - { GPIO_USB_C1_BC12_VBUS_ON_L, GPIO_USB_C1_BC12_CHG_DET }, -#endif -#ifdef HAS_TASK_USB_CHG_P2 - { GPIO_USB_C2_BC12_VBUS_ON_L, GPIO_USB_C2_BC12_CHG_DET }, -#endif -}; +/** + * Returns true if the charger detect pin is activated. + * + * @parm cfg driver for chip to read the charger detect pin for. + * @return 1 if charger detect is activated (high when active high or + * low with active low), otherwise 0. + */ +static int is_chg_det_activated(const struct bq24392_config_t * const cfg) +{ + return !!gpio_get_level(cfg->chg_det_pin) ^ + !!(cfg->flags & BQ24392_FLAGS_CHG_DET_ACTIVE_LOW); +} + +/** + * Activates the Chip Enable GPIO based on the enabled value. + * + * @param cfg driver for chip that will set chip enable gpio. + * @param enable 1 to activate gpio (high for active high and low for active + * low). + */ +static void activate_chip_enable( + const struct bq24392_config_t * const cfg, const int enable) +{ + gpio_set_level( + cfg->chip_enable_pin, + !!enable ^ !!(cfg->flags & BQ24392_FLAGS_ENABLE_ACTIVE_LOW)); +} /** * Perform BC1.2 detection and update charge manager. @@ -48,13 +64,13 @@ static const struct bq24392_pins pin_tbl[] = { */ static void bc12_detect(const int port) { + const struct bq24392_config_t * const cfg = &bq24392_config[port]; struct charge_port_info new_chg; /* - * Enable the IC to begin detection and connect switches if - * necessary. Note, the value is 0 because the enable is active low. + * Enable the IC to begin detection and connect switches if necessary. */ - gpio_set_level(pin_tbl[port].chip_enable_l, 0); + activate_chip_enable(cfg, 1); new_chg.voltage = USB_CHARGER_VOLTAGE_MV; #if defined(CONFIG_CHARGE_RAMP_SW) || defined(CONFIG_CHARGE_RAMP_HW) @@ -66,11 +82,11 @@ static void bc12_detect(const int port) /* * The driver assumes that CHG_AL_N and SW_OPEN are not connected, - * therefore the value of CHG_DET indicates whether the source is NOT a - * low-power standard downstream port (SDP). The system will have to + * therefore an activated CHG_DET indicates whether the source is NOT a + * low-power standard downstream port (SDP). The system will have to * ramp the current to determine the limit. */ - new_chg.current = gpio_get_level(pin_tbl[port].chg_det) ? 2400 : 500; + new_chg.current = is_chg_det_activated(cfg) ? 2400 : 500; #else /* * If the board doesn't support charge ramping, then assume the lowest @@ -90,10 +106,11 @@ static void bc12_detect(const int port) */ static void power_down_ic(const int port) { + const struct bq24392_config_t * const cfg = &bq24392_config[port]; struct charge_port_info no_chg = { 0 }; /* Turn off the IC. */ - gpio_set_level(pin_tbl[port].chip_enable_l, 1); + activate_chip_enable(cfg, 0); /* Let charge manager know there's no more charge available. */ charge_manager_update_charge(CHARGE_SUPPLIER_OTHER, port, &no_chg); @@ -138,7 +155,7 @@ void usb_charger_task(void *u) const int port = (intptr_t)u; uint32_t evt; - ASSERT(port >= 0 && port <= 2); + ASSERT(port >= 0 && port < CONFIG_USB_PD_PORT_COUNT); detect_or_power_down_ic(port); diff --git a/driver/bc12/bq24392.h b/driver/bc12/bq24392.h new file mode 100644 index 0000000000..1d49814968 --- /dev/null +++ b/driver/bc12/bq24392.h @@ -0,0 +1,31 @@ +/* Copyright 2018 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. + */ + +/* BQ24392 USB BC 1.2 Charger Detector driver definitions */ + +#include "gpio.h" + +#define BQ24392_FLAGS_ENABLE_ACTIVE_LOW (1 << 0) +#define BQ24392_FLAGS_CHG_DET_ACTIVE_LOW (1 << 1) + +struct bq24392_config_t { + /* + * Enable signal to BC 1.2. Can be active high or low depending on + * BQ24392_FLAGS_ENABLE_ACTIVE_LOW flag bit. + */ + enum gpio_signal chip_enable_pin; + /* + * Charger detect signal from BC 1.2 chip. Can be active high or low + * depending on BQ24392_FLAGS_CHG_DET_ACTIVE_LOW flag bit. + */ + enum gpio_signal chg_det_pin; + /* Configuration flags with prefix BQ24392_FLAGS. */ + int flags; +}; + +/* + * Array that contains boards-specific configuration for BC 1.2 charging chips. + */ +extern const struct bq24392_config_t bq24392_config[CONFIG_USB_PD_PORT_COUNT]; |