diff options
author | Simon Glass <sjg@chromium.org> | 2020-12-30 12:50:26 -0700 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2021-01-09 03:17:46 +0000 |
commit | 407a3cfc7c7423b3f03289b094bc1dfd2082a3c4 (patch) | |
tree | 97df1f94370c0a5675b7e06e9d0ed0ce0b4710bf /baseboard | |
parent | ba9df2aa09deeae5d851c59469d782b1a7a0efe4 (diff) | |
download | chrome-ec-407a3cfc7c7423b3f03289b094bc1dfd2082a3c4.tar.gz |
Split out some USB-C config into new files
The Zephyr build needs this information but cannot use the whole
board.c file. It is pretty big anyway, so let's move some of the USB-C
config info into a separate file.
Add a header file for the part specific to this config.
We can progressively move more as Zephyr is able to build it. This
requires the addition of many Kconfig options, so will be done in
stages.
BUG=b:175434113
BRANCH=none
TEST=make -j30 buildall
With a zephyr-chrome CL, build volteer on zephyr
Check for other boards:
for b in $(grep volteer board/*/build.mk |awk -F/ '{print $2}'); do \
echo $b; grep -A5 "enum usbc_port" board/$b/board.h; done
Signed-off-by: Simon Glass <sjg@chromium.org>
Change-Id: I2a4bb0af2b8571ce992cdbbc8362dec25176872e
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2605277
Reviewed-by: Keith Short <keithshort@chromium.org>
Diffstat (limited to 'baseboard')
-rw-r--r-- | baseboard/volteer/baseboard.c | 86 | ||||
-rw-r--r-- | baseboard/volteer/charger.c | 86 |
2 files changed, 90 insertions, 82 deletions
diff --git a/baseboard/volteer/baseboard.c b/baseboard/volteer/baseboard.c index 85af33a202..b08c5b4dd1 100644 --- a/baseboard/volteer/baseboard.c +++ b/baseboard/volteer/baseboard.c @@ -7,9 +7,8 @@ #include "adc_chip.h" #include "button.h" #include "cbi_ec_fw_config.h" -#include "charge_manager.h" +#include "charger.h" #include "charge_ramp.h" -#include "charge_state.h" #include "cros_board_info.h" #include "driver/charger/isl9241.h" #include "driver/tcpm/ps8xxx.h" @@ -22,15 +21,13 @@ #include "system.h" #include "task.h" #include "temp_sensor.h" -#include "usbc_ppc.h" -#include "util.h" +#ifdef CONFIG_ZEPHYR +#include "usbc_config.h" +#endif #define CPRINTS(format, args...) cprints(CC_CHIPSET, format, ## args) #define CPRINTF(format, args...) cprintf(CC_CHIPSET, format, ## args) -#define CPRINTSUSB(format, args...) cprints(CC_USBCHARGE, format, ## args) -#define CPRINTFUSB(format, args...) cprintf(CC_USBCHARGE, format, ## args) - /******************************************************************************/ /* ADC configuration */ const struct adc_t adc_channels[] = { @@ -176,81 +173,6 @@ void bc12_interrupt(enum gpio_signal signal) } } -int board_set_active_charge_port(int port) -{ - int is_valid_port = (port >= 0 && - port < CONFIG_USB_PD_PORT_MAX_COUNT); - int i; - - if (port == CHARGE_PORT_NONE) { - CPRINTSUSB("Disabling all charger ports"); - - /* Disable all ports. */ - for (i = 0; i < ppc_cnt; i++) { - /* - * Do not return early if one fails otherwise we can - * get into a boot loop assertion failure. - */ - if (ppc_vbus_sink_enable(i, 0)) - CPRINTSUSB("Disabling C%d as sink failed.", i); - } - - return EC_SUCCESS; - } else if (!is_valid_port) { - return EC_ERROR_INVAL; - } - - - /* Check if the port is sourcing VBUS. */ - if (ppc_is_sourcing_vbus(port)) { - CPRINTFUSB("Skip enable C%d", port); - return EC_ERROR_INVAL; - } - - CPRINTSUSB("New charge port: C%d", port); - - /* - * Turn off the other ports' sink path FETs, before enabling the - * requested charge port. - */ - for (i = 0; i < ppc_cnt; i++) { - if (i == port) - continue; - - if (ppc_vbus_sink_enable(i, 0)) - CPRINTSUSB("C%d: sink path disable failed.", i); - } - - /* Enable requested charge port. */ - if (ppc_vbus_sink_enable(port, 1)) { - CPRINTSUSB("C%d: sink path enable failed.", port); - return EC_ERROR_UNKNOWN; - } - - return EC_SUCCESS; -} - -__overridable void board_set_charge_limit(int port, int supplier, int charge_ma, - int max_ma, int charge_mv) -{ - charge_set_input_current_limit(MAX(charge_ma, - CONFIG_CHARGER_INPUT_CURRENT), - charge_mv); -} - -void board_overcurrent_event(int port, int is_overcurrented) -{ - /* Note that the level is inverted because the pin is active low. */ - switch (port) { - case USBC_PORT_C0: - gpio_set_level(GPIO_USB_C0_OC_ODL, !is_overcurrented); - break; - case USBC_PORT_C1: - gpio_set_level(GPIO_USB_C1_OC_ODL, !is_overcurrented); - break; - } -} - static void baseboard_init(void) { /* Enable monitoring of the PROCHOT input to the EC */ diff --git a/baseboard/volteer/charger.c b/baseboard/volteer/charger.c index aced8fc67b..a674b98f41 100644 --- a/baseboard/volteer/charger.c +++ b/baseboard/volteer/charger.c @@ -6,7 +6,18 @@ /* Volteer family-specific configuration */ #include "common.h" #include "charger.h" +#include "charge_manager.h" +#include "charge_state.h" #include "driver/charger/isl9241_public.h" +#include "gpio.h" +#ifdef CONFIG_ZEPHYR +#include "usbc_config.h" +#endif +#include "usbc_ppc.h" +#include "util.h" + +#define CPRINTSUSB(format, args...) cprints(CC_USBCHARGE, format, ## args) +#define CPRINTFUSB(format, args...) cprintf(CC_USBCHARGE, format, ## args) /* Charger Chip Configuration */ const struct charger_config_t chg_chips[] = { @@ -16,3 +27,78 @@ const struct charger_config_t chg_chips[] = { .drv = &isl9241_drv, }, }; + +int board_set_active_charge_port(int port) +{ + int is_valid_port = (port >= 0 && + port < CONFIG_USB_PD_PORT_MAX_COUNT); + int i; + + if (port == CHARGE_PORT_NONE) { + CPRINTSUSB("Disabling all charger ports"); + + /* Disable all ports. */ + for (i = 0; i < ppc_cnt; i++) { + /* + * Do not return early if one fails otherwise we can + * get into a boot loop assertion failure. + */ + if (ppc_vbus_sink_enable(i, 0)) + CPRINTSUSB("Disabling C%d as sink failed.", i); + } + + return EC_SUCCESS; + } else if (!is_valid_port) { + return EC_ERROR_INVAL; + } + + + /* Check if the port is sourcing VBUS. */ + if (ppc_is_sourcing_vbus(port)) { + CPRINTFUSB("Skip enable C%d", port); + return EC_ERROR_INVAL; + } + + CPRINTSUSB("New charge port: C%d", port); + + /* + * Turn off the other ports' sink path FETs, before enabling the + * requested charge port. + */ + for (i = 0; i < ppc_cnt; i++) { + if (i == port) + continue; + + if (ppc_vbus_sink_enable(i, 0)) + CPRINTSUSB("C%d: sink path disable failed.", i); + } + + /* Enable requested charge port. */ + if (ppc_vbus_sink_enable(port, 1)) { + CPRINTSUSB("C%d: sink path enable failed.", port); + return EC_ERROR_UNKNOWN; + } + + return EC_SUCCESS; +} + +__overridable void board_set_charge_limit(int port, int supplier, int charge_ma, + int max_ma, int charge_mv) +{ + charge_set_input_current_limit(MAX(charge_ma, + CONFIG_CHARGER_INPUT_CURRENT), + charge_mv); +} + +void board_overcurrent_event(int port, int is_overcurrented) +{ + /* Note that the level is inverted because the pin is active low. */ + switch (port) { + case USBC_PORT_C0: + gpio_set_level(GPIO_USB_C0_OC_ODL, !is_overcurrented); + break; + case USBC_PORT_C1: + gpio_set_level(GPIO_USB_C1_OC_ODL, !is_overcurrented); + break; + } +} |