diff options
author | johnwc_yeh <johnwc_yeh@compal.corp-partner.google.com> | 2022-05-06 17:23:21 +0800 |
---|---|---|
committer | Chromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com> | 2022-05-11 02:09:02 +0000 |
commit | 74aa410552225b76686a451941acefe66c238626 (patch) | |
tree | b50508577dc6c6253e73b67b7add9889c5cfe898 /board/mithrax/board.c | |
parent | 999b1a6384d259c1b8567e55dd8f84ed26854b82 (diff) | |
download | chrome-ec-74aa410552225b76686a451941acefe66c238626.tar.gz |
mithrax: Initial EC image
Copy the Felwinter reference board EC files into a new directory
name for the Mithrax variant.
(Copy from commit 60c5d955940500bd5c9ea29ed8814c2977adc266.)
BUG=b:223091246
BRANCH=None
TEST=make BOARD=mithrax
Signed-off-by: johnwc_yeh <johnwc_yeh@compal.corp-partner.google.com>
Change-Id: Ieea80fcf70f55e02755d32d065c90503a820d97c
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3631847
Reviewed-by: Ko Ko <ko_ko@compal.corp-partner.google.com>
Reviewed-by: Boris Mittelberg <bmbm@google.com>
Diffstat (limited to 'board/mithrax/board.c')
-rw-r--r-- | board/mithrax/board.c | 152 |
1 files changed, 108 insertions, 44 deletions
diff --git a/board/mithrax/board.c b/board/mithrax/board.c index 4ca53ffa48..892c4d85bd 100644 --- a/board/mithrax/board.c +++ b/board/mithrax/board.c @@ -1,4 +1,4 @@ -/* Copyright 2022 The Chromium OS Authors. All rights reserved. +/* Copyright 2021 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. */ @@ -15,7 +15,6 @@ #include "hooks.h" #include "driver/accel_lis2dw12.h" #include "driver/accelgyro_lsm6dso.h" -#include "driver/als_tcs3400.h" #include "fw_config.h" #include "hooks.h" #include "lid_switch.h" @@ -33,6 +32,16 @@ #define CPRINTF(format, args...) cprintf(CC_CHARGER, format, ## args) #define CPRINTS(format, args...) cprints(CC_CHARGER, format, ## args) +/******************************************************************************/ +/* USB-A charging control */ + +const int usb_port_enable[USB_PORT_COUNT] = { + GPIO_EN_PP5000_USBA_R, +}; +BUILD_ASSERT(ARRAY_SIZE(usb_port_enable) == USB_PORT_COUNT); + +/******************************************************************************/ + __override void board_cbi_init(void) { config_usb_db_type(); @@ -42,11 +51,7 @@ __override void board_cbi_init(void) static void board_chipset_resume(void) { /* Allow keyboard backlight to be enabled */ - - if (get_board_id() == 1) - gpio_set_level(GPIO_ID_1_EC_KB_BL_EN, 1); - else - gpio_set_level(GPIO_EC_KB_BL_EN_L, 0); + gpio_set_level(GPIO_EC_KB_BL_EN_L, 0); } DECLARE_HOOK(HOOK_CHIPSET_RESUME, board_chipset_resume, HOOK_PRIO_DEFAULT); @@ -54,55 +59,114 @@ DECLARE_HOOK(HOOK_CHIPSET_RESUME, board_chipset_resume, HOOK_PRIO_DEFAULT); static void board_chipset_suspend(void) { /* Turn off the keyboard backlight if it's on. */ - - if (get_board_id() == 1) - gpio_set_level(GPIO_ID_1_EC_KB_BL_EN, 0); - else - gpio_set_level(GPIO_EC_KB_BL_EN_L, 1); + gpio_set_level(GPIO_EC_KB_BL_EN_L, 1); } DECLARE_HOOK(HOOK_CHIPSET_SUSPEND, board_chipset_suspend, HOOK_PRIO_DEFAULT); +/* Called on AP S5 -> S3 transition */ +static void board_chipset_startup(void) +{ + pen_config(); +} +DECLARE_HOOK(HOOK_CHIPSET_STARTUP, board_chipset_startup, HOOK_PRIO_DEFAULT); + +#ifdef CONFIG_CHARGE_RAMP_SW + /* - * Explicitly apply the board ID 1 *gpio.inc settings to pins that - * were reassigned on current boards. + * TODO(b/181508008): tune this threshold */ -static void set_board_id_1_gpios(void) +#define BC12_MIN_VOLTAGE 4400 + +/** + * Return true if VBUS is too low + */ +int board_is_vbus_too_low(int port, enum chg_ramp_vbus_state ramp_state) { - if (get_board_id() != 1) - return; + int voltage; + + if (charger_get_vbus_voltage(port, &voltage)) + voltage = 0; + + if (voltage == 0) { + CPRINTS("%s: must be disconnected", __func__); + return 1; + } + + if (voltage < BC12_MIN_VOLTAGE) { + CPRINTS("%s: port %d: vbus %d lower than %d", __func__, + port, voltage, BC12_MIN_VOLTAGE); + return 1; + } - gpio_set_flags(GPIO_ID_1_EC_KB_BL_EN, GPIO_OUT_LOW); + return 0; } -DECLARE_HOOK(HOOK_INIT, set_board_id_1_gpios, HOOK_PRIO_FIRST); -/* - * Reclaim GPIO pins on board ID 1 that are used as ADC inputs on - * current boards. ALT function group MODULE_ADC pins are set in - * HOOK_PRIO_INIT_ADC and can be reclaimed right after the hook runs. - */ +#endif /* CONFIG_CHARGE_RAMP_SW */ + +enum battery_present battery_hw_present(void) +{ + enum gpio_signal batt_pres; + + batt_pres = GPIO_EC_BATT_PRES_ODL; -static void board_id_1_reclaim_adc(void) + /* The GPIO is low when the battery is physically present */ + return gpio_get_level(batt_pres) ? BP_NO : BP_YES; +} + +static void board_init(void) +{ + if (ec_cfg_usb_db_type() == DB_USB4_NCT3807) + db_update_usb4_config_from_config(); + + if (ec_cfg_usb_mb_type() == MB_USB4_TBT) + mb_update_usb4_tbt_config_from_config(); + + if (ec_cfg_stylus() == STYLUS_PRSENT) + gpio_enable_interrupt(GPIO_PEN_DET_ODL); +} +DECLARE_HOOK(HOOK_INIT, board_init, HOOK_PRIO_DEFAULT); + + +/** + * Deferred function to handle pen detect change + */ +static void pendetect_deferred(void) { - if (get_board_id() != 1) + static int debounced_pen_detect; + int pen_detect = !gpio_get_level(GPIO_PEN_DET_ODL); + + if (pen_detect == debounced_pen_detect) return; - /* - * GPIO_ID_1_USB_C0_C2_TCPC_RST_ODL is on GPIO34 - * - * The TCPC has already been reset by board_tcpc_init() executed - * from HOOK_PRIO_INIT_CHIPSET. Later, the pin gets set to ADC6 - * in HOOK_PRIO_INIT_ADC, so we simply need to set the pin back - * to GPIO34. - */ - gpio_set_flags(GPIO_ID_1_USB_C0_C2_TCPC_RST_ODL, GPIO_ODR_HIGH); - gpio_set_alternate_function(GPIO_PORT_3, BIT(4), GPIO_ALT_FUNC_NONE); - - /* - * The pin gets set to ADC7 in HOOK_PRIO_INIT_ADC, so we simply - * need to set it back to GPIOE1. - */ - gpio_set_flags(GPIO_ID_1_EC_BATT_PRES_ODL, GPIO_INPUT); - gpio_set_alternate_function(GPIO_PORT_E, BIT(1), GPIO_ALT_FUNC_NONE); + debounced_pen_detect = pen_detect; + + if (!chipset_in_state(CHIPSET_STATE_ANY_OFF)) + gpio_set_level(GPIO_EN_PP5000_PEN, debounced_pen_detect); +} +DECLARE_DEFERRED(pendetect_deferred); +DECLARE_HOOK(HOOK_INIT, pendetect_deferred, HOOK_PRIO_DEFAULT); + +void pen_detect_interrupt(enum gpio_signal s) +{ + /* Trigger deferred notification of pen detect change */ + hook_call_deferred(&pendetect_deferred_data, + 500 * MSEC); +} + +void pen_config(void) +{ + if (ec_cfg_stylus() == STYLUS_PRSENT) { + /* Make sure pen detection is triggered or not at resume */ + if (!gpio_get_level(GPIO_PEN_DET_ODL)) + gpio_set_level(GPIO_EN_PP5000_PEN, 1); + else + gpio_set_level(GPIO_EN_PP5000_PEN, 0); + } +} + +static void board_chipset_shutdown(void) +{ + gpio_set_level(GPIO_EN_PP5000_PEN, 0); } -DECLARE_HOOK(HOOK_INIT, board_id_1_reclaim_adc, HOOK_PRIO_INIT_ADC + 1); +DECLARE_HOOK(HOOK_CHIPSET_SHUTDOWN, board_chipset_shutdown, HOOK_PRIO_DEFAULT); |