diff options
Diffstat (limited to 'zephyr/projects/nissa/src')
19 files changed, 118 insertions, 1799 deletions
diff --git a/zephyr/projects/nissa/src/board_power.c b/zephyr/projects/nissa/src/board_power.c index 8180b2c8af..d7fb4aeffe 100644 --- a/zephyr/projects/nissa/src/board_power.c +++ b/zephyr/projects/nissa/src/board_power.c @@ -1,4 +1,4 @@ -/* Copyright 2022 The Chromium OS Authors. All rights reserved. +/* Copyright 2022 The ChromiumOS Authors * Use of this source code is governed by a BSD-style license that can be * found in the LICENSE file. */ @@ -19,7 +19,7 @@ LOG_MODULE_DECLARE(ap_pwrseq, LOG_LEVEL_INF); -#define X86_NON_DSX_ADLP_NONPWRSEQ_FORCE_SHUTDOWN_TO_MS 5 +#define X86_NON_DSX_ADLP_NONPWRSEQ_FORCE_SHUTDOWN_TO_MS 5 static bool s0_stable; @@ -44,11 +44,11 @@ void board_ap_power_force_shutdown(void) power_signal_enable(PWR_PG_PP1P05); } - power_signal_set(PWR_EC_PCH_RSMRST, 0); power_signal_set(PWR_EC_SOC_DSW_PWROK, 0); + power_signal_set(PWR_EC_PCH_RSMRST, 0); while (power_signal_get(PWR_RSMRST) == 0 && - power_signal_get(PWR_SLP_SUS) == 0 && timeout_ms > 0) { + power_signal_get(PWR_SLP_SUS) == 0 && timeout_ms > 0) { k_msleep(1); timeout_ms--; } @@ -88,10 +88,9 @@ void board_ap_power_action_g3_s5(void) power_signal_set(PWR_EN_PP3300_A, 1); power_wait_signals_timeout(IN_PGOOD_ALL_CORE, - AP_PWRSEQ_DT_VALUE(wait_signal_timeout)); + AP_PWRSEQ_DT_VALUE(wait_signal_timeout)); - generate_ec_soc_dsw_pwrok_handler( - AP_PWRSEQ_DT_VALUE(dsw_pwrok_delay)); + generate_ec_soc_dsw_pwrok_handler(AP_PWRSEQ_DT_VALUE(dsw_pwrok_delay)); s0_stable = false; } @@ -132,8 +131,8 @@ int board_ap_power_assert_pch_power_ok(void) bool board_ap_power_check_power_rails_enabled(void) { return power_signal_get(PWR_EN_PP3300_A) && - power_signal_get(PWR_EN_PP5000_A) && - power_signal_get(PWR_EC_SOC_DSW_PWROK); + power_signal_get(PWR_EN_PP5000_A) && + power_signal_get(PWR_EC_SOC_DSW_PWROK); } int board_power_signal_get(enum power_signal signal) @@ -154,7 +153,7 @@ int board_power_signal_get(enum power_signal signal) return 0; } if (!gpio_pin_get_dt( - GPIO_DT_FROM_NODELABEL(gpio_all_sys_pwrgd))) { + GPIO_DT_FROM_NODELABEL(gpio_all_sys_pwrgd))) { return 0; } if (!power_signal_get(PWR_PG_PP1P05)) { diff --git a/zephyr/projects/nissa/src/common.c b/zephyr/projects/nissa/src/common.c index e1e7aaf7e9..fe25d1374d 100644 --- a/zephyr/projects/nissa/src/common.c +++ b/zephyr/projects/nissa/src/common.c @@ -1,4 +1,4 @@ -/* Copyright 2022 The Chromium OS Authors. All rights reserved. +/* Copyright 2022 The ChromiumOS Authors * Use of this source code is governed by a BSD-style license that can be * found in the LICENSE file. */ @@ -81,8 +81,8 @@ static void board_setup_init(void) */ DECLARE_HOOK(HOOK_INIT, board_setup_init, HOOK_PRIO_INIT_I2C); -void board_set_charge_limit(int port, int supplier, int charge_ma, - int max_ma, int charge_mv) +void board_set_charge_limit(int port, int supplier, int charge_ma, int max_ma, + int charge_mv) { int icl = MAX(charge_ma, CONFIG_CHARGER_INPUT_CURRENT); @@ -124,7 +124,7 @@ enum nissa_sub_board_type nissa_get_sb_type(void) if (sb != NISSA_SB_UNKNOWN) return sb; - sb = NISSA_SB_NONE; /* Defaults to none */ + sb = NISSA_SB_NONE; /* Defaults to none */ ret = cros_cbi_get_fw_config(FW_SUB_BOARD, &val); if (ret != 0) { LOG_WRN("Error retrieving CBI FW_CONFIG field %d", diff --git a/zephyr/projects/nissa/src/craask/charger.c b/zephyr/projects/nissa/src/craask/charger.c deleted file mode 100644 index 3fbbabec6b..0000000000 --- a/zephyr/projects/nissa/src/craask/charger.c +++ /dev/null @@ -1,56 +0,0 @@ -/* Copyright 2022 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 <zephyr/logging/log.h> - -#include "battery.h" -#include "charger.h" -#include "charger/isl923x_public.h" -#include "console.h" -#include "extpower.h" -#include "usb_pd.h" -#include "nissa_common.h" - -LOG_MODULE_DECLARE(nissa, CONFIG_NISSA_LOG_LEVEL); - -int extpower_is_present(void) -{ - int port; - int rv; - bool acok; - - for (port = 0; port < board_get_usb_pd_port_count(); port++) { - rv = raa489000_is_acok(port, &acok); - if ((rv == EC_SUCCESS) && acok) - return 1; - } - - return 0; -} - -/* - * Craask does not have a GPIO indicating whether extpower is present, - * so detect using the charger(s). - */ -__override void board_check_extpower(void) -{ - static int last_extpower_present; - int extpower_present = extpower_is_present(); - - if (last_extpower_present ^ extpower_present) - extpower_handle_update(extpower_present); - - last_extpower_present = extpower_present; -} - -__override void board_hibernate(void) -{ - /* Shut down the chargers */ - if (board_get_usb_pd_port_count() == 2) - raa489000_hibernate(CHARGER_SECONDARY, true); - raa489000_hibernate(CHARGER_PRIMARY, true); - LOG_INF("Charger(s) hibernated"); - cflush(); -} diff --git a/zephyr/projects/nissa/src/craask/led.c b/zephyr/projects/nissa/src/craask/led.c deleted file mode 100644 index a0c0447419..0000000000 --- a/zephyr/projects/nissa/src/craask/led.c +++ /dev/null @@ -1,47 +0,0 @@ -/* Copyright 2022 The ChromiumOS Authors. - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - * - * Battery LED control for nissa - */ -#include "common.h" -#include "ec_commands.h" -#include "led_common.h" -#include "led_onoff_states.h" -#include "led_pwm.h" - -__override const int led_charge_lvl_1 = 5; -__override const int led_charge_lvl_2 = 97; -__override struct led_descriptor - led_bat_state_table[LED_NUM_STATES][LED_NUM_PHASES] = { - [STATE_CHARGING_LVL_1] = {{EC_LED_COLOR_AMBER, LED_INDEFINITE} }, - [STATE_CHARGING_LVL_2] = {{EC_LED_COLOR_AMBER, LED_INDEFINITE} }, - [STATE_CHARGING_FULL_CHARGE] = {{EC_LED_COLOR_BLUE, LED_INDEFINITE} }, - [STATE_DISCHARGE_S0] = {{EC_LED_COLOR_BLUE, LED_INDEFINITE} }, - [STATE_DISCHARGE_S0_BAT_LOW] = {{EC_LED_COLOR_AMBER, LED_INDEFINITE} }, - [STATE_DISCHARGE_S3] = {{EC_LED_COLOR_AMBER, 1 * LED_ONE_SEC}, - {LED_OFF, 3 * LED_ONE_SEC} }, - [STATE_DISCHARGE_S5] = {{LED_OFF, LED_INDEFINITE} }, - [STATE_BATTERY_ERROR] = {{EC_LED_COLOR_AMBER, 1 * LED_ONE_SEC}, - {LED_OFF, 1 * LED_ONE_SEC} }, - [STATE_FACTORY_TEST] = {{EC_LED_COLOR_AMBER, 2 * LED_ONE_SEC}, - {EC_LED_COLOR_BLUE, 2 * LED_ONE_SEC} }, -}; - -__override void led_set_color_battery(enum ec_led_colors color) -{ - switch (color) { - case EC_LED_COLOR_RED: - set_pwm_led_color(EC_LED_ID_BATTERY_LED, EC_LED_COLOR_RED); - break; - case EC_LED_COLOR_BLUE: - set_pwm_led_color(EC_LED_ID_BATTERY_LED, EC_LED_COLOR_BLUE); - break; - case EC_LED_COLOR_AMBER: - set_pwm_led_color(EC_LED_ID_BATTERY_LED, EC_LED_COLOR_AMBER); - break; - default: /* LED_OFF and other unsupported colors */ - set_pwm_led_color(EC_LED_ID_BATTERY_LED, -1); - break; - } -} diff --git a/zephyr/projects/nissa/src/craask/usbc.c b/zephyr/projects/nissa/src/craask/usbc.c deleted file mode 100644 index 32a390e502..0000000000 --- a/zephyr/projects/nissa/src/craask/usbc.c +++ /dev/null @@ -1,281 +0,0 @@ -/* Copyright 2022 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 <zephyr/logging/log.h> - -#include "charge_state_v2.h" -#include "chipset.h" -#include "hooks.h" -#include "usb_mux.h" -#include "system.h" -#include "driver/charger/isl923x_public.h" -#include "driver/retimer/anx7483_public.h" -#include "driver/tcpm/tcpci.h" -#include "driver/tcpm/raa489000.h" - -#include "nissa_common.h" - -LOG_MODULE_DECLARE(nissa, CONFIG_NISSA_LOG_LEVEL); - -struct tcpc_config_t tcpc_config[CONFIG_USB_PD_PORT_MAX_COUNT] = { - { - .bus_type = EC_BUS_TYPE_I2C, - .i2c_info = { - .port = I2C_PORT_USB_C0_TCPC, - .addr_flags = RAA489000_TCPC0_I2C_FLAGS, - }, - .drv = &raa489000_tcpm_drv, - /* RAA489000 implements TCPCI 2.0 */ - .flags = TCPC_FLAGS_TCPCI_REV2_0 | - TCPC_FLAGS_VBUS_MONITOR, - }, - { /* sub-board */ - .bus_type = EC_BUS_TYPE_I2C, - .i2c_info = { - .port = I2C_PORT_USB_C1_TCPC, - .addr_flags = RAA489000_TCPC0_I2C_FLAGS, - }, - .drv = &raa489000_tcpm_drv, - /* RAA489000 implements TCPCI 2.0 */ - .flags = TCPC_FLAGS_TCPCI_REV2_0 | - TCPC_FLAGS_VBUS_MONITOR, - }, -}; - -int board_is_sourcing_vbus(int port) -{ - int regval; - - tcpc_read(port, TCPC_REG_POWER_STATUS, ®val); - return !!(regval & TCPC_REG_POWER_STATUS_SOURCING_VBUS); -} - -int board_set_active_charge_port(int port) -{ - int is_real_port = (port >= 0 && - port < CONFIG_USB_PD_PORT_MAX_COUNT); - int i; - int old_port; - - if (!is_real_port && port != CHARGE_PORT_NONE) - return EC_ERROR_INVAL; - - old_port = charge_manager_get_active_charge_port(); - - LOG_INF("New chg p%d", port); - - /* Disable all ports. */ - if (port == CHARGE_PORT_NONE) { - for (i = 0; i < CONFIG_USB_PD_PORT_MAX_COUNT; i++) { - tcpc_write(i, TCPC_REG_COMMAND, - TCPC_REG_COMMAND_SNK_CTRL_LOW); - raa489000_enable_asgate(i, false); - } - - return EC_SUCCESS; - } - - /* Check if port is sourcing VBUS. */ - if (board_is_sourcing_vbus(port)) { - LOG_WRN("Skip enable p%d", port); - return EC_ERROR_INVAL; - } - - /* - * Turn off the other ports' sink path FETs, before enabling the - * requested charge port. - */ - for (i = 0; i < CONFIG_USB_PD_PORT_MAX_COUNT; i++) { - if (i == port) - continue; - - if (tcpc_write(i, TCPC_REG_COMMAND, - TCPC_REG_COMMAND_SNK_CTRL_LOW)) - LOG_WRN("p%d: sink path disable failed.", i); - raa489000_enable_asgate(i, false); - } - - /* - * Stop the charger IC from switching while changing ports. Otherwise, - * we can overcurrent the adapter we're switching to. (crbug.com/926056) - */ - if (old_port != CHARGE_PORT_NONE) - charger_discharge_on_ac(1); - - /* Enable requested charge port. */ - if (raa489000_enable_asgate(port, true) || - tcpc_write(port, TCPC_REG_COMMAND, - TCPC_REG_COMMAND_SNK_CTRL_HIGH)) { - LOG_WRN("p%d: sink path enable failed.", port); - charger_discharge_on_ac(0); - return EC_ERROR_UNKNOWN; - } - - /* Allow the charger IC to begin/continue switching. */ - charger_discharge_on_ac(0); - - return EC_SUCCESS; -} - -uint16_t tcpc_get_alert_status(void) -{ - uint16_t status = 0; - int regval; - - /* - * The interrupt line is shared between the TCPC and BC1.2 detector IC. - * Therefore, go out and actually read the alert registers to report the - * alert status. - */ - if (!gpio_pin_get_dt(GPIO_DT_FROM_NODELABEL(gpio_usb_c0_int_odl))) { - if (!tcpc_read16(0, TCPC_REG_ALERT, ®val)) { - /* The TCPCI Rev 1.0 spec says to ignore bits 14:12. */ - if (!(tcpc_config[0].flags & TCPC_FLAGS_TCPCI_REV2_0)) - regval &= ~((1 << 14) | (1 << 13) | (1 << 12)); - - if (regval) - status |= PD_STATUS_TCPC_ALERT_0; - } - } - - if (board_get_usb_pd_port_count() == 2 && - !gpio_pin_get_dt(GPIO_DT_FROM_ALIAS(gpio_usb_c1_int_odl))) { - if (!tcpc_read16(1, TCPC_REG_ALERT, ®val)) { - /* TCPCI spec Rev 1.0 says to ignore bits 14:12. */ - if (!(tcpc_config[1].flags & TCPC_FLAGS_TCPCI_REV2_0)) - regval &= ~((1 << 14) | (1 << 13) | (1 << 12)); - - if (regval) - status |= PD_STATUS_TCPC_ALERT_1; - } - } - - return status; -} - -void pd_power_supply_reset(int port) -{ - /* Disable VBUS */ - tcpc_write(port, TCPC_REG_COMMAND, TCPC_REG_COMMAND_SRC_CTRL_LOW); - - /* Notify host of power info change. */ - pd_send_host_event(PD_EVENT_POWER_CHANGE); -} - -__override void typec_set_source_current_limit(int port, enum tcpc_rp_value rp) -{ - if (port < 0 || port >= CONFIG_USB_PD_PORT_MAX_COUNT) - return; - - raa489000_set_output_current(port, rp); -} - -int pd_set_power_supply_ready(int port) -{ - int rv; - - if (port >= CONFIG_USB_PD_PORT_MAX_COUNT) - return EC_ERROR_INVAL; - - /* Disable charging. */ - rv = tcpc_write(port, TCPC_REG_COMMAND, TCPC_REG_COMMAND_SNK_CTRL_LOW); - if (rv) - return rv; - - /* Our policy is not to source VBUS when the AP is off. */ - if (chipset_in_state(CHIPSET_STATE_ANY_OFF)) - return EC_ERROR_NOT_POWERED; - - /* Provide Vbus. */ - rv = tcpc_write(port, TCPC_REG_COMMAND, TCPC_REG_COMMAND_SRC_CTRL_HIGH); - if (rv) - return rv; - - rv = raa489000_enable_asgate(port, true); - if (rv) - return rv; - - /* Notify host of power info change. */ - pd_send_host_event(PD_EVENT_POWER_CHANGE); - - return EC_SUCCESS; -} - -void board_reset_pd_mcu(void) -{ - /* - * TODO(b:147316511): could send a reset command to the TCPC here - * if needed. - */ -} - -/* - * Because the TCPCs and BC1.2 chips share interrupt lines, it's possible - * for an interrupt to be lost if one asserts the IRQ, the other does the same - * then the first releases it: there will only be one falling edge to trigger - * the interrupt, and the line will be held low. We handle this by running a - * deferred check after a falling edge to see whether the IRQ is still being - * asserted. If it is, we assume an interrupt may have been lost and we need - * to poll each chip for events again. - */ -#define USBC_INT_POLL_DELAY_US 5000 - -static void poll_c0_int(void); -DECLARE_DEFERRED(poll_c0_int); -static void poll_c1_int(void); -DECLARE_DEFERRED(poll_c1_int); - -static void usbc_interrupt_trigger(int port) -{ - schedule_deferred_pd_interrupt(port); - usb_charger_task_set_event(port, USB_CHG_EVENT_BC12); -} - -static inline void poll_usb_gpio(int port, - const struct gpio_dt_spec *gpio, - const struct deferred_data *ud) -{ - if (!gpio_pin_get_dt(gpio)) { - usbc_interrupt_trigger(port); - hook_call_deferred(ud, USBC_INT_POLL_DELAY_US); - } -} - -static void poll_c0_int (void) -{ - poll_usb_gpio(0, - GPIO_DT_FROM_NODELABEL(gpio_usb_c0_int_odl), - &poll_c0_int_data); -} - -static void poll_c1_int (void) -{ - poll_usb_gpio(1, - GPIO_DT_FROM_ALIAS(gpio_usb_c1_int_odl), - &poll_c1_int_data); -} - -void usb_interrupt(enum gpio_signal signal) -{ - int port; - const struct deferred_data *ud; - - if (signal == GPIO_SIGNAL(DT_NODELABEL(gpio_usb_c0_int_odl))) { - port = 0; - ud = &poll_c0_int_data; - } else { - port = 1; - ud = &poll_c1_int_data; - } - /* - * We've just been called from a falling edge, so there's definitely - * no lost IRQ right now. Cancel any pending check. - */ - hook_call_deferred(ud, -1); - /* Trigger polling of TCPC and BC1.2 in respective tasks */ - usbc_interrupt_trigger(port); - /* Check for lost interrupts in a bit */ - hook_call_deferred(ud, USBC_INT_POLL_DELAY_US); -} diff --git a/zephyr/projects/nissa/src/led.c b/zephyr/projects/nissa/src/led.c index 27c78f8051..2617d0092d 100644 --- a/zephyr/projects/nissa/src/led.c +++ b/zephyr/projects/nissa/src/led.c @@ -1,4 +1,4 @@ -/* Copyright 2022 The Chromium OS Authors. All rights reserved. +/* Copyright 2022 The ChromiumOS Authors * Use of this source code is governed by a BSD-style license that can be * found in the LICENSE file. * @@ -13,20 +13,25 @@ __override const int led_charge_lvl_1 = 5; __override const int led_charge_lvl_2 = 97; __override struct led_descriptor - led_bat_state_table[LED_NUM_STATES][LED_NUM_PHASES] = { - [STATE_CHARGING_LVL_1] = {{EC_LED_COLOR_RED, LED_INDEFINITE} }, - [STATE_CHARGING_LVL_2] = {{EC_LED_COLOR_AMBER, LED_INDEFINITE} }, - [STATE_CHARGING_FULL_CHARGE] = {{EC_LED_COLOR_GREEN, LED_INDEFINITE} }, - [STATE_DISCHARGE_S0] = {{LED_OFF, LED_INDEFINITE} }, - [STATE_DISCHARGE_S0_BAT_LOW] = {{EC_LED_COLOR_AMBER, 1 * LED_ONE_SEC}, - {LED_OFF, 3 * LED_ONE_SEC} }, - [STATE_DISCHARGE_S3] = {{LED_OFF, LED_INDEFINITE} }, - [STATE_DISCHARGE_S5] = {{LED_OFF, LED_INDEFINITE} }, - [STATE_BATTERY_ERROR] = {{EC_LED_COLOR_RED, 1 * LED_ONE_SEC}, - {LED_OFF, 1 * LED_ONE_SEC} }, - [STATE_FACTORY_TEST] = {{EC_LED_COLOR_RED, 2 * LED_ONE_SEC}, - {EC_LED_COLOR_GREEN, 2 * LED_ONE_SEC} }, -}; + led_bat_state_table[LED_NUM_STATES][LED_NUM_PHASES] = { + [STATE_CHARGING_LVL_1] = { { EC_LED_COLOR_RED, + LED_INDEFINITE } }, + [STATE_CHARGING_LVL_2] = { { EC_LED_COLOR_AMBER, + LED_INDEFINITE } }, + [STATE_CHARGING_FULL_CHARGE] = { { EC_LED_COLOR_GREEN, + LED_INDEFINITE } }, + [STATE_DISCHARGE_S0] = { { LED_OFF, LED_INDEFINITE } }, + [STATE_DISCHARGE_S0_BAT_LOW] = { { EC_LED_COLOR_AMBER, + 1 * LED_ONE_SEC }, + { LED_OFF, 3 * LED_ONE_SEC } }, + [STATE_DISCHARGE_S3] = { { LED_OFF, LED_INDEFINITE } }, + [STATE_DISCHARGE_S5] = { { LED_OFF, LED_INDEFINITE } }, + [STATE_BATTERY_ERROR] = { { EC_LED_COLOR_RED, 1 * LED_ONE_SEC }, + { LED_OFF, 1 * LED_ONE_SEC } }, + [STATE_FACTORY_TEST] = { { EC_LED_COLOR_RED, 2 * LED_ONE_SEC }, + { EC_LED_COLOR_GREEN, + 2 * LED_ONE_SEC } }, + }; __override void led_set_color_battery(enum ec_led_colors color) { diff --git a/zephyr/projects/nissa/src/nereid/charger.c b/zephyr/projects/nissa/src/nereid/charger.c deleted file mode 100644 index a494988951..0000000000 --- a/zephyr/projects/nissa/src/nereid/charger.c +++ /dev/null @@ -1,56 +0,0 @@ -/* Copyright 2022 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 <zephyr/logging/log.h> - -#include "battery.h" -#include "charger.h" -#include "console.h" -#include "driver/charger/sm5803.h" -#include "extpower.h" -#include "usb_pd.h" -#include "nissa_common.h" - -LOG_MODULE_DECLARE(nissa, CONFIG_NISSA_LOG_LEVEL); - -int extpower_is_present(void) -{ - int port; - int rv; - bool acok; - - for (port = 0; port < board_get_usb_pd_port_count(); port++) { - rv = sm5803_is_acok(port, &acok); - if ((rv == EC_SUCCESS) && acok) - return 1; - } - - return 0; -} - -/* - * Nereid does not have a GPIO indicating whether extpower is present, - * so detect using the charger(s). - */ -__override void board_check_extpower(void) -{ - static int last_extpower_present; - int extpower_present = extpower_is_present(); - - if (last_extpower_present ^ extpower_present) - extpower_handle_update(extpower_present); - - last_extpower_present = extpower_present; -} - -__override void board_hibernate(void) -{ - /* Shut down the chargers */ - if (board_get_usb_pd_port_count() == 2) - sm5803_hibernate(CHARGER_SECONDARY); - sm5803_hibernate(CHARGER_PRIMARY); - LOG_INF("Charger(s) hibernated"); - cflush(); -} diff --git a/zephyr/projects/nissa/src/nereid/keyboard.c b/zephyr/projects/nissa/src/nereid/keyboard.c deleted file mode 100644 index d0d1406307..0000000000 --- a/zephyr/projects/nissa/src/nereid/keyboard.c +++ /dev/null @@ -1,29 +0,0 @@ -/* Copyright 2022 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 "ec_commands.h" - -static const struct ec_response_keybd_config nereid_kb_legacy = { - .num_top_row_keys = 10, - .action_keys = { - TK_BACK, /* T1 */ - TK_FORWARD, /* T2 */ - TK_REFRESH, /* T3 */ - TK_FULLSCREEN, /* T4 */ - TK_OVERVIEW, /* T5 */ - TK_BRIGHTNESS_DOWN, /* T6 */ - TK_BRIGHTNESS_UP, /* T7 */ - TK_VOL_MUTE, /* T8 */ - TK_VOL_DOWN, /* T9 */ - TK_VOL_UP, /* T10 */ - }, - .capabilities = KEYBD_CAP_SCRNLOCK_KEY, -}; - -__override const struct ec_response_keybd_config -*board_vivaldi_keybd_config(void) -{ - return &nereid_kb_legacy; -} diff --git a/zephyr/projects/nissa/src/nereid/usbc.c b/zephyr/projects/nissa/src/nereid/usbc.c deleted file mode 100644 index eeab449c32..0000000000 --- a/zephyr/projects/nissa/src/nereid/usbc.c +++ /dev/null @@ -1,404 +0,0 @@ -/* Copyright 2022 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 <zephyr/logging/log.h> -#include <ap_power/ap_power.h> - -#include "charge_state_v2.h" -#include "chipset.h" -#include "hooks.h" -#include "usb_mux.h" -#include "system.h" -#include "driver/charger/sm5803.h" -#include "driver/tcpm/it83xx_pd.h" -#include "driver/tcpm/ps8xxx_public.h" -#include "driver/tcpm/tcpci.h" - -#include "nissa_common.h" - -LOG_MODULE_DECLARE(nissa, CONFIG_NISSA_LOG_LEVEL); - -struct tcpc_config_t tcpc_config[CONFIG_USB_PD_PORT_MAX_COUNT] = { - { - .bus_type = EC_BUS_TYPE_EMBEDDED, - /* TCPC is embedded within EC so no i2c config needed */ - .drv = &it8xxx2_tcpm_drv, - /* Alert is active-low, push-pull */ - .flags = 0, - }, - { - /* - * Sub-board: optional PS8745 TCPC+redriver. Behaves the same - * as PS8815. - */ - .bus_type = EC_BUS_TYPE_I2C, - .i2c_info = { - .port = I2C_PORT_USB_C1_TCPC, - .addr_flags = PS8XXX_I2C_ADDR1_FLAGS, - }, - .drv = &ps8xxx_tcpm_drv, - /* PS8745 implements TCPCI 2.0 */ - .flags = TCPC_FLAGS_TCPCI_REV2_0, - }, -}; - -/* Vconn control for integrated ITE TCPC */ -void board_pd_vconn_ctrl(int port, enum usbpd_cc_pin cc_pin, int enabled) -{ - /* Vconn control is only for port 0 */ - if (port) - return; - - if (cc_pin == USBPD_CC_PIN_1) - gpio_pin_set_dt( - GPIO_DT_FROM_NODELABEL(gpio_en_usb_c0_cc1_vconn), - !!enabled); - else - gpio_pin_set_dt( - GPIO_DT_FROM_NODELABEL(gpio_en_usb_c0_cc2_vconn), - !!enabled); -} - -__override bool pd_check_vbus_level(int port, enum vbus_level level) -{ - int vbus_voltage; - - /* If we're unable to speak to the charger, best to guess false */ - if (charger_get_vbus_voltage(port, &vbus_voltage)) { - return false; - } - - if (level == VBUS_SAFE0V) - return vbus_voltage < PD_V_SAFE0V_MAX; - else if (level == VBUS_PRESENT) - return vbus_voltage > PD_V_SAFE5V_MIN; - else - return vbus_voltage < PD_V_SINK_DISCONNECT_MAX; -} - -/* - * Putting chargers into LPM when in suspend reduces power draw by about 8mW - * per charger, but also seems critical to correct operation in source mode: - * if chargers are not in LPM when a sink is first connected, VBUS sourcing - * works even if the partner is later removed (causing LPM entry) and - * reconnected (causing LPM exit). If in LPM initially, sourcing VBUS - * consistently causes the charger to report (apparently spurious) overcurrent - * failures. - * - * In short, this is important to making things work correctly but we don't - * understand why. - */ -static void board_chargers_suspend(struct ap_power_ev_callback *const cb, - const struct ap_power_ev_data data) -{ - void (*fn)(int chgnum); - - switch (data.event) { - case AP_POWER_SUSPEND: - fn = sm5803_enable_low_power_mode; - break; - case AP_POWER_RESUME: - fn = sm5803_disable_low_power_mode; - break; - default: - LOG_WRN("%s: power event %d is not recognized", - __func__, data.event); - return; - } - - fn(CHARGER_PRIMARY); - if (board_get_charger_chip_count() > 1) - fn(CHARGER_SECONDARY); -} - -static int board_chargers_suspend_init(const struct device *unused) -{ - static struct ap_power_ev_callback cb = { - .handler = board_chargers_suspend, - .events = AP_POWER_SUSPEND | AP_POWER_RESUME, - }; - ap_power_ev_add_callback(&cb); - return 0; -} -SYS_INIT(board_chargers_suspend_init, APPLICATION, 0); - -int board_set_active_charge_port(int port) -{ - int is_real_port = (port >= 0 && port < board_get_usb_pd_port_count()); - int i; - int old_port; - int rv; - - if (!is_real_port && port != CHARGE_PORT_NONE) - return EC_ERROR_INVAL; - - old_port = charge_manager_get_active_charge_port(); - LOG_INF("Charge update: p%d -> p%d", old_port, port); - - /* Check if port is sourcing VBUS. */ - if (port != CHARGE_PORT_NONE && charger_is_sourcing_otg_power(port)) { - LOG_WRN("Skip enable p%d: already sourcing", port); - return EC_ERROR_INVAL; - } - - /* Disable sinking on all ports except the desired one */ - for (i = 0; i < board_get_usb_pd_port_count(); i++) { - if (i == port) - continue; - - if (sm5803_vbus_sink_enable(i, 0)) - /* - * Do not early-return because this can fail during - * power-on which would put us into a loop. - */ - LOG_WRN("p%d: sink path disable failed.", i); - } - - /* Don't enable anything (stop here) if no ports were requested */ - if (port == CHARGE_PORT_NONE) - return EC_SUCCESS; - - /* - * Stop the charger IC from switching while changing ports. Otherwise, - * we can overcurrent the adapter we're switching to. (crbug.com/926056) - */ - if (old_port != CHARGE_PORT_NONE) - charger_discharge_on_ac(1); - - /* Enable requested charge port. */ - rv = sm5803_vbus_sink_enable(port, 1); - if (rv) - LOG_WRN("p%d: sink path enable failed: code %d", port, rv); - - /* Allow the charger IC to begin/continue switching. */ - charger_discharge_on_ac(0); - - return rv; -} - -uint16_t tcpc_get_alert_status(void) -{ - /* - * TCPC 0 is embedded in the EC and processes interrupts in the chip - * code (it83xx/intc.c). This function only needs to poll port C1 if - * present. - */ - uint16_t status = 0; - int regval; - - /* Is the C1 port present and its IRQ line asserted? */ - if (board_get_usb_pd_port_count() == 2 && - !gpio_pin_get_dt(GPIO_DT_FROM_ALIAS(gpio_usb_c1_int_odl))) { - /* - * C1 IRQ is shared between BC1.2 and TCPC; poll TCPC to see if - * it asserted the IRQ. - */ - if (!tcpc_read16(1, TCPC_REG_ALERT, ®val)) { - if (regval) - status = PD_STATUS_TCPC_ALERT_1; - } - } - - return status; -} - -void pd_power_supply_reset(int port) -{ - int prev_en; - - if (port < 0 || port >= board_get_usb_pd_port_count()) - return; - - prev_en = charger_is_sourcing_otg_power(port); - - /* Disable Vbus */ - charger_enable_otg_power(port, 0); - - /* Discharge Vbus if previously enabled */ - if (prev_en) - sm5803_set_vbus_disch(port, 1); - - /* Notify host of power info change. */ - pd_send_host_event(PD_EVENT_POWER_CHANGE); -} - -int pd_set_power_supply_ready(int port) -{ - enum ec_error_list rv; - - if (port < 0 || port > board_get_usb_pd_port_count()) { - LOG_WRN("Port C%d does not exist, cannot enable VBUS", port); - return EC_ERROR_INVAL; - } - - /* Disable sinking */ - rv = sm5803_vbus_sink_enable(port, 0); - if (rv) { - LOG_WRN("C%d failed to disable sinking: %d", port, rv); - return rv; - } - - /* Disable Vbus discharge */ - rv = sm5803_set_vbus_disch(port, 0); - if (rv) { - LOG_WRN("C%d failed to clear VBUS discharge: %d", port, rv); - return rv; - } - - /* Provide Vbus */ - rv = charger_enable_otg_power(port, 1); - if (rv) { - LOG_WRN("C%d failed to enable VBUS sourcing: %d", port, rv); - return rv; - } - - /* Notify host of power info change. */ - pd_send_host_event(PD_EVENT_POWER_CHANGE); - - return EC_SUCCESS; -} - -__override void typec_set_source_current_limit(int port, enum tcpc_rp_value rp) -{ - int rv; - const int current = rp == TYPEC_RP_3A0 ? 3000 : 1500; - - rv = charger_set_otg_current_voltage(port, current, 5000); - if (rv != EC_SUCCESS) { - LOG_WRN("Failed to set source ilimit on port %d to %d: %d", - port, current, rv); - } -} - -void board_reset_pd_mcu(void) -{ - /* - * Do nothing. The integrated TCPC for C0 lacks a dedicated reset - * command, and C1 (if present) doesn't have a reset pin connected - * to the EC. - */ -} - -#define INT_RECHECK_US 5000 - -/* C0 interrupt line shared by BC 1.2 and charger */ - -static void check_c0_line(void); -DECLARE_DEFERRED(check_c0_line); - -static void notify_c0_chips(void) -{ - usb_charger_task_set_event(0, USB_CHG_EVENT_BC12); - sm5803_interrupt(0); -} - -static void check_c0_line(void) -{ - /* - * If line is still being held low, see if there's more to process from - * one of the chips - */ - if (!gpio_pin_get_dt(GPIO_DT_FROM_NODELABEL(gpio_usb_c0_int_odl))) { - notify_c0_chips(); - hook_call_deferred(&check_c0_line_data, INT_RECHECK_US); - } -} - -void usb_c0_interrupt(enum gpio_signal s) -{ - /* Cancel any previous calls to check the interrupt line */ - hook_call_deferred(&check_c0_line_data, -1); - - /* Notify all chips using this line that an interrupt came in */ - notify_c0_chips(); - - /* Check the line again in 5ms */ - hook_call_deferred(&check_c0_line_data, INT_RECHECK_US); -} - -/* C1 interrupt line shared by BC 1.2, TCPC, and charger */ -static void check_c1_line(void); -DECLARE_DEFERRED(check_c1_line); - -static void notify_c1_chips(void) -{ - schedule_deferred_pd_interrupt(1); - usb_charger_task_set_event(1, USB_CHG_EVENT_BC12); - /* Charger is handled in board_process_pd_alert */ -} - -static void check_c1_line(void) -{ - /* - * If line is still being held low, see if there's more to process from - * one of the chips. - */ - if (!gpio_pin_get_dt(GPIO_DT_FROM_ALIAS(gpio_usb_c1_int_odl))) { - notify_c1_chips(); - hook_call_deferred(&check_c1_line_data, INT_RECHECK_US); - } -} - -void usb_c1_interrupt(enum gpio_signal s) -{ - /* Cancel any previous calls to check the interrupt line */ - hook_call_deferred(&check_c1_line_data, -1); - - /* Notify all chips using this line that an interrupt came in */ - notify_c1_chips(); - - /* Check the line again in 5ms */ - hook_call_deferred(&check_c1_line_data, INT_RECHECK_US); -} - -/* - * Check state of IRQ lines at startup, ensuring an IRQ that happened before - * the EC started up won't get lost (leaving the IRQ line asserted and blocking - * any further interrupts on the port). - * - * Although the PD task will check for pending TCPC interrupts on startup, - * the charger sharing the IRQ will not be polled automatically. - */ -void board_handle_initial_typec_irq(void) -{ - check_c0_line(); - check_c1_line(); -} -/* - * This must run after sub-board detection (which happens in EC main()), - * but isn't depended on by anything else either. - */ -DECLARE_HOOK(HOOK_INIT, board_handle_initial_typec_irq, HOOK_PRIO_LAST); - -/* - * Handle charger interrupts in the PD task. Not doing so can lead to a priority - * inversion where we fail to respond to TCPC alerts quickly enough because we - * don't get another edge on a shared IRQ until the charger interrupt is cleared - * (or the IRQ is polled again), which happens in the low-priority charger task: - * the high-priority type-C handler is thus blocked on the lower-priority - * charger. - * - * To avoid that, we run charger interrupts at the same priority. - */ -void board_process_pd_alert(int port) -{ - /* - * Port 0 doesn't use an external TCPC, so its interrupts don't need - * this special handling. - */ - if (port == 1 && - !gpio_pin_get_dt(GPIO_DT_FROM_ALIAS(gpio_usb_c1_int_odl))) { - sm5803_handle_interrupt(port); - } -} - -int pd_snk_is_vbus_provided(int port) -{ - int chg_det = 0; - - sm5803_get_chg_det(port, &chg_det); - - return chg_det; -} diff --git a/zephyr/projects/nissa/src/nivviks/charger.c b/zephyr/projects/nissa/src/nivviks/charger.c deleted file mode 100644 index 5a8bbe0e7a..0000000000 --- a/zephyr/projects/nissa/src/nivviks/charger.c +++ /dev/null @@ -1,56 +0,0 @@ -/* 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. - */ - -#include <zephyr/logging/log.h> - -#include "battery.h" -#include "charger.h" -#include "charger/isl923x_public.h" -#include "console.h" -#include "extpower.h" -#include "usb_pd.h" -#include "nissa_common.h" - -LOG_MODULE_DECLARE(nissa, CONFIG_NISSA_LOG_LEVEL); - -int extpower_is_present(void) -{ - int port; - int rv; - bool acok; - - for (port = 0; port < board_get_usb_pd_port_count(); port++) { - rv = raa489000_is_acok(port, &acok); - if ((rv == EC_SUCCESS) && acok) - return 1; - } - - return 0; -} - -/* - * Nivviks does not have a GPIO indicating whether extpower is present, - * so detect using the charger(s). - */ -__override void board_check_extpower(void) -{ - static int last_extpower_present; - int extpower_present = extpower_is_present(); - - if (last_extpower_present ^ extpower_present) - extpower_handle_update(extpower_present); - - last_extpower_present = extpower_present; -} - -__override void board_hibernate(void) -{ - /* Shut down the chargers */ - if (board_get_usb_pd_port_count() == 2) - raa489000_hibernate(CHARGER_SECONDARY, true); - raa489000_hibernate(CHARGER_PRIMARY, true); - LOG_INF("Charger(s) hibernated"); - cflush(); -} diff --git a/zephyr/projects/nissa/src/nivviks/fan.c b/zephyr/projects/nissa/src/nivviks/fan.c deleted file mode 100644 index b177c6eab1..0000000000 --- a/zephyr/projects/nissa/src/nivviks/fan.c +++ /dev/null @@ -1,45 +0,0 @@ -/* Copyright 2022 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 <zephyr/devicetree.h> -#include <zephyr/drivers/gpio.h> -#include <zephyr/logging/log.h> - -#include "cros_cbi.h" -#include "fan.h" -#include "gpio/gpio.h" -#include "hooks.h" - -#include "nissa_common.h" - -LOG_MODULE_DECLARE(nissa, CONFIG_NISSA_LOG_LEVEL); - -/* - * Nirwen fan support - */ -static void fan_init(void) -{ - int ret; - uint32_t val; - /* - * Retrieve the fan config. - */ - ret = cros_cbi_get_fw_config(FW_FAN, &val); - if (ret != 0) { - LOG_ERR("Error retrieving CBI FW_CONFIG field %d", - FW_FAN); - return; - } - if (val != FW_FAN_PRESENT) { - /* Disable the fan */ - fan_set_count(0); - } else { - /* Configure the fan enable GPIO */ - gpio_pin_configure_dt( - GPIO_DT_FROM_NODELABEL(gpio_fan_enable), - GPIO_OUTPUT); - } -} -DECLARE_HOOK(HOOK_INIT, fan_init, HOOK_PRIO_POST_FIRST); diff --git a/zephyr/projects/nissa/src/nivviks/form_factor.c b/zephyr/projects/nissa/src/nivviks/form_factor.c deleted file mode 100644 index 16132e4a6c..0000000000 --- a/zephyr/projects/nissa/src/nivviks/form_factor.c +++ /dev/null @@ -1,47 +0,0 @@ -/* Copyright 2022 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 <zephyr/devicetree.h> -#include <zephyr/logging/log.h> - -#include "accelgyro.h" -#include "cros_cbi.h" -#include "hooks.h" -#include "motionsense_sensors.h" - -#include "nissa_common.h" - -LOG_MODULE_DECLARE(nissa, CONFIG_NISSA_LOG_LEVEL); - -/* - * Mainboard orientation support. - */ - -#define ALT_MAT SENSOR_ROT_STD_REF_NAME(DT_NODELABEL(base_rot_inverted)) -#define BASE_SENSOR SENSOR_ID(DT_NODELABEL(base_accel)) -#define BASE_GYRO SENSOR_ID(DT_NODELABEL(base_gyro)) - -static void form_factor_init(void) -{ - int ret; - uint32_t val; - /* - * If the firmware config indicates - * an inverted form factor, use the alternative - * rotation matrix. - */ - ret = cros_cbi_get_fw_config(FW_BASE_INVERSION, &val); - if (ret != 0) { - LOG_ERR("Error retrieving CBI FW_CONFIG field %d", - FW_BASE_INVERSION); - return; - } - if (val == FW_BASE_INVERTED) { - LOG_INF("Switching to inverted base"); - motion_sensors[BASE_SENSOR].rot_standard_ref = &ALT_MAT; - motion_sensors[BASE_GYRO].rot_standard_ref = &ALT_MAT; - } -} -DECLARE_HOOK(HOOK_INIT, form_factor_init, HOOK_PRIO_POST_I2C); diff --git a/zephyr/projects/nissa/src/nivviks/keyboard.c b/zephyr/projects/nissa/src/nivviks/keyboard.c deleted file mode 100644 index dc5c42e33a..0000000000 --- a/zephyr/projects/nissa/src/nivviks/keyboard.c +++ /dev/null @@ -1,29 +0,0 @@ -/* Copyright 2022 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 "ec_commands.h" - -static const struct ec_response_keybd_config nivviks_kb = { - .num_top_row_keys = 10, - .action_keys = { - TK_BACK, /* T1 */ - TK_REFRESH, /* T2 */ - TK_FULLSCREEN, /* T3 */ - TK_OVERVIEW, /* T4 */ - TK_SNAPSHOT, /* T5 */ - TK_BRIGHTNESS_DOWN, /* T6 */ - TK_BRIGHTNESS_UP, /* T7 */ - TK_VOL_MUTE, /* T8 */ - TK_VOL_DOWN, /* T9 */ - TK_VOL_UP, /* T10 */ - }, - .capabilities = KEYBD_CAP_SCRNLOCK_KEY, -}; - -__override const struct ec_response_keybd_config -*board_vivaldi_keybd_config(void) -{ - return &nivviks_kb; -} diff --git a/zephyr/projects/nissa/src/nivviks/usbc.c b/zephyr/projects/nissa/src/nivviks/usbc.c deleted file mode 100644 index c068eba6f4..0000000000 --- a/zephyr/projects/nissa/src/nivviks/usbc.c +++ /dev/null @@ -1,281 +0,0 @@ -/* 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. - */ - -#include <zephyr/logging/log.h> - -#include "charge_state_v2.h" -#include "chipset.h" -#include "hooks.h" -#include "usb_mux.h" -#include "system.h" -#include "driver/charger/isl923x_public.h" -#include "driver/retimer/anx7483_public.h" -#include "driver/tcpm/tcpci.h" -#include "driver/tcpm/raa489000.h" - -#include "nissa_common.h" - -LOG_MODULE_DECLARE(nissa, CONFIG_NISSA_LOG_LEVEL); - -struct tcpc_config_t tcpc_config[CONFIG_USB_PD_PORT_MAX_COUNT] = { - { - .bus_type = EC_BUS_TYPE_I2C, - .i2c_info = { - .port = I2C_PORT_USB_C0_TCPC, - .addr_flags = RAA489000_TCPC0_I2C_FLAGS, - }, - .drv = &raa489000_tcpm_drv, - /* RAA489000 implements TCPCI 2.0 */ - .flags = TCPC_FLAGS_TCPCI_REV2_0 | - TCPC_FLAGS_VBUS_MONITOR, - }, - { /* sub-board */ - .bus_type = EC_BUS_TYPE_I2C, - .i2c_info = { - .port = I2C_PORT_USB_C1_TCPC, - .addr_flags = RAA489000_TCPC0_I2C_FLAGS, - }, - .drv = &raa489000_tcpm_drv, - /* RAA489000 implements TCPCI 2.0 */ - .flags = TCPC_FLAGS_TCPCI_REV2_0 | - TCPC_FLAGS_VBUS_MONITOR, - }, -}; - -int board_is_sourcing_vbus(int port) -{ - int regval; - - tcpc_read(port, TCPC_REG_POWER_STATUS, ®val); - return !!(regval & TCPC_REG_POWER_STATUS_SOURCING_VBUS); -} - -int board_set_active_charge_port(int port) -{ - int is_real_port = (port >= 0 && - port < CONFIG_USB_PD_PORT_MAX_COUNT); - int i; - int old_port; - - if (!is_real_port && port != CHARGE_PORT_NONE) - return EC_ERROR_INVAL; - - old_port = charge_manager_get_active_charge_port(); - - LOG_INF("New chg p%d", port); - - /* Disable all ports. */ - if (port == CHARGE_PORT_NONE) { - for (i = 0; i < CONFIG_USB_PD_PORT_MAX_COUNT; i++) { - tcpc_write(i, TCPC_REG_COMMAND, - TCPC_REG_COMMAND_SNK_CTRL_LOW); - raa489000_enable_asgate(i, false); - } - - return EC_SUCCESS; - } - - /* Check if port is sourcing VBUS. */ - if (board_is_sourcing_vbus(port)) { - LOG_WRN("Skip enable p%d", port); - return EC_ERROR_INVAL; - } - - /* - * Turn off the other ports' sink path FETs, before enabling the - * requested charge port. - */ - for (i = 0; i < CONFIG_USB_PD_PORT_MAX_COUNT; i++) { - if (i == port) - continue; - - if (tcpc_write(i, TCPC_REG_COMMAND, - TCPC_REG_COMMAND_SNK_CTRL_LOW)) - LOG_WRN("p%d: sink path disable failed.", i); - raa489000_enable_asgate(i, false); - } - - /* - * Stop the charger IC from switching while changing ports. Otherwise, - * we can overcurrent the adapter we're switching to. (crbug.com/926056) - */ - if (old_port != CHARGE_PORT_NONE) - charger_discharge_on_ac(1); - - /* Enable requested charge port. */ - if (raa489000_enable_asgate(port, true) || - tcpc_write(port, TCPC_REG_COMMAND, - TCPC_REG_COMMAND_SNK_CTRL_HIGH)) { - LOG_WRN("p%d: sink path enable failed.", port); - charger_discharge_on_ac(0); - return EC_ERROR_UNKNOWN; - } - - /* Allow the charger IC to begin/continue switching. */ - charger_discharge_on_ac(0); - - return EC_SUCCESS; -} - -uint16_t tcpc_get_alert_status(void) -{ - uint16_t status = 0; - int regval; - - /* - * The interrupt line is shared between the TCPC and BC1.2 detector IC. - * Therefore, go out and actually read the alert registers to report the - * alert status. - */ - if (!gpio_pin_get_dt(GPIO_DT_FROM_NODELABEL(gpio_usb_c0_int_odl))) { - if (!tcpc_read16(0, TCPC_REG_ALERT, ®val)) { - /* The TCPCI Rev 1.0 spec says to ignore bits 14:12. */ - if (!(tcpc_config[0].flags & TCPC_FLAGS_TCPCI_REV2_0)) - regval &= ~((1 << 14) | (1 << 13) | (1 << 12)); - - if (regval) - status |= PD_STATUS_TCPC_ALERT_0; - } - } - - if (board_get_usb_pd_port_count() == 2 && - !gpio_pin_get_dt(GPIO_DT_FROM_ALIAS(gpio_usb_c1_int_odl))) { - if (!tcpc_read16(1, TCPC_REG_ALERT, ®val)) { - /* TCPCI spec Rev 1.0 says to ignore bits 14:12. */ - if (!(tcpc_config[1].flags & TCPC_FLAGS_TCPCI_REV2_0)) - regval &= ~((1 << 14) | (1 << 13) | (1 << 12)); - - if (regval) - status |= PD_STATUS_TCPC_ALERT_1; - } - } - - return status; -} - -void pd_power_supply_reset(int port) -{ - /* Disable VBUS */ - tcpc_write(port, TCPC_REG_COMMAND, TCPC_REG_COMMAND_SRC_CTRL_LOW); - - /* Notify host of power info change. */ - pd_send_host_event(PD_EVENT_POWER_CHANGE); -} - -__override void typec_set_source_current_limit(int port, enum tcpc_rp_value rp) -{ - if (port < 0 || port >= CONFIG_USB_PD_PORT_MAX_COUNT) - return; - - raa489000_set_output_current(port, rp); -} - -int pd_set_power_supply_ready(int port) -{ - int rv; - - if (port >= CONFIG_USB_PD_PORT_MAX_COUNT) - return EC_ERROR_INVAL; - - /* Disable charging. */ - rv = tcpc_write(port, TCPC_REG_COMMAND, TCPC_REG_COMMAND_SNK_CTRL_LOW); - if (rv) - return rv; - - /* Our policy is not to source VBUS when the AP is off. */ - if (chipset_in_state(CHIPSET_STATE_ANY_OFF)) - return EC_ERROR_NOT_POWERED; - - /* Provide Vbus. */ - rv = tcpc_write(port, TCPC_REG_COMMAND, TCPC_REG_COMMAND_SRC_CTRL_HIGH); - if (rv) - return rv; - - rv = raa489000_enable_asgate(port, true); - if (rv) - return rv; - - /* Notify host of power info change. */ - pd_send_host_event(PD_EVENT_POWER_CHANGE); - - return EC_SUCCESS; -} - -void board_reset_pd_mcu(void) -{ - /* - * TODO(b:147316511): could send a reset command to the TCPC here - * if needed. - */ -} - -/* - * Because the TCPCs and BC1.2 chips share interrupt lines, it's possible - * for an interrupt to be lost if one asserts the IRQ, the other does the same - * then the first releases it: there will only be one falling edge to trigger - * the interrupt, and the line will be held low. We handle this by running a - * deferred check after a falling edge to see whether the IRQ is still being - * asserted. If it is, we assume an interrupt may have been lost and we need - * to poll each chip for events again. - */ -#define USBC_INT_POLL_DELAY_US 5000 - -static void poll_c0_int(void); -DECLARE_DEFERRED(poll_c0_int); -static void poll_c1_int(void); -DECLARE_DEFERRED(poll_c1_int); - -static void usbc_interrupt_trigger(int port) -{ - schedule_deferred_pd_interrupt(port); - usb_charger_task_set_event(port, USB_CHG_EVENT_BC12); -} - -static inline void poll_usb_gpio(int port, - const struct gpio_dt_spec *gpio, - const struct deferred_data *ud) -{ - if (!gpio_pin_get_dt(gpio)) { - usbc_interrupt_trigger(port); - hook_call_deferred(ud, USBC_INT_POLL_DELAY_US); - } -} - -static void poll_c0_int (void) -{ - poll_usb_gpio(0, - GPIO_DT_FROM_NODELABEL(gpio_usb_c0_int_odl), - &poll_c0_int_data); -} - -static void poll_c1_int (void) -{ - poll_usb_gpio(1, - GPIO_DT_FROM_ALIAS(gpio_usb_c1_int_odl), - &poll_c1_int_data); -} - -void usb_interrupt(enum gpio_signal signal) -{ - int port; - const struct deferred_data *ud; - - if (signal == GPIO_SIGNAL(DT_NODELABEL(gpio_usb_c0_int_odl))) { - port = 0; - ud = &poll_c0_int_data; - } else { - port = 1; - ud = &poll_c1_int_data; - } - /* - * We've just been called from a falling edge, so there's definitely - * no lost IRQ right now. Cancel any pending check. - */ - hook_call_deferred(ud, -1); - /* Trigger polling of TCPC and BC1.2 in respective tasks */ - usbc_interrupt_trigger(port); - /* Check for lost interrupts in a bit */ - hook_call_deferred(ud, USBC_INT_POLL_DELAY_US); -} diff --git a/zephyr/projects/nissa/src/pujjo/charger.c b/zephyr/projects/nissa/src/pujjo/charger.c deleted file mode 100644 index c6209bdf75..0000000000 --- a/zephyr/projects/nissa/src/pujjo/charger.c +++ /dev/null @@ -1,56 +0,0 @@ -/* Copyright 2022 The ChromiumOS Authors. - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#include <zephyr/logging/log.h> - -#include "battery.h" -#include "charger.h" -#include "charger/isl923x_public.h" -#include "console.h" -#include "extpower.h" -#include "usb_pd.h" -#include "nissa_common.h" - -LOG_MODULE_DECLARE(nissa, CONFIG_NISSA_LOG_LEVEL); - -int extpower_is_present(void) -{ - int port; - int rv; - bool acok; - - for (port = 0; port < board_get_usb_pd_port_count(); port++) { - rv = raa489000_is_acok(port, &acok); - if ((rv == EC_SUCCESS) && acok) - return 1; - } - - return 0; -} - -/* - * Pujjo does not have a GPIO indicating whether extpower is present, - * so detect using the charger(s). - */ -__override void board_check_extpower(void) -{ - static int last_extpower_present; - int extpower_present = extpower_is_present(); - - if (last_extpower_present ^ extpower_present) - extpower_handle_update(extpower_present); - - last_extpower_present = extpower_present; -} - -__override void board_hibernate(void) -{ - /* Shut down the chargers */ - if (board_get_usb_pd_port_count() == 2) - raa489000_hibernate(CHARGER_SECONDARY, true); - raa489000_hibernate(CHARGER_PRIMARY, true); - LOG_INF("Charger(s) hibernated"); - cflush(); -} diff --git a/zephyr/projects/nissa/src/pujjo/fan.c b/zephyr/projects/nissa/src/pujjo/fan.c deleted file mode 100644 index 8914774452..0000000000 --- a/zephyr/projects/nissa/src/pujjo/fan.c +++ /dev/null @@ -1,45 +0,0 @@ -/* Copyright 2022 The ChromiumOS Authors. - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#include <zephyr/devicetree.h> -#include <zephyr/drivers/gpio.h> -#include <zephyr/logging/log.h> - -#include "cros_cbi.h" -#include "fan.h" -#include "gpio/gpio.h" -#include "hooks.h" - -#include "nissa_common.h" - -LOG_MODULE_DECLARE(nissa, CONFIG_NISSA_LOG_LEVEL); - -/* - * Pujjo fan support - */ -static void fan_init(void) -{ - int ret; - uint32_t val; - /* - * Retrieve the fan config. - */ - ret = cros_cbi_get_fw_config(FW_FAN, &val); - if (ret != 0) { - LOG_ERR("Error retrieving CBI FW_CONFIG field %d", - FW_FAN); - return; - } - if (val != FW_FAN_PRESENT) { - /* Disable the fan */ - fan_set_count(0); - } else { - /* Configure the fan enable GPIO */ - gpio_pin_configure_dt( - GPIO_DT_FROM_NODELABEL(gpio_fan_enable), - GPIO_OUTPUT); - } -} -DECLARE_HOOK(HOOK_INIT, fan_init, HOOK_PRIO_POST_FIRST); diff --git a/zephyr/projects/nissa/src/pujjo/keyboard.c b/zephyr/projects/nissa/src/pujjo/keyboard.c deleted file mode 100644 index e6d819e348..0000000000 --- a/zephyr/projects/nissa/src/pujjo/keyboard.c +++ /dev/null @@ -1,29 +0,0 @@ -/* Copyright 2022 The ChromiumOS Authors. - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#include "ec_commands.h" - -static const struct ec_response_keybd_config pujjo_kb = { - .num_top_row_keys = 10, - .action_keys = { - TK_BACK, /* T1 */ - TK_REFRESH, /* T2 */ - TK_FULLSCREEN, /* T3 */ - TK_OVERVIEW, /* T4 */ - TK_SNAPSHOT, /* T5 */ - TK_BRIGHTNESS_DOWN, /* T6 */ - TK_BRIGHTNESS_UP, /* T7 */ - TK_VOL_MUTE, /* T8 */ - TK_VOL_DOWN, /* T9 */ - TK_VOL_UP, /* T10 */ - }, - .capabilities = KEYBD_CAP_SCRNLOCK_KEY, -}; - -__override const struct ec_response_keybd_config -*board_vivaldi_keybd_config(void) -{ - return &pujjo_kb; -} diff --git a/zephyr/projects/nissa/src/pujjo/usbc.c b/zephyr/projects/nissa/src/pujjo/usbc.c deleted file mode 100644 index 020f78dbdd..0000000000 --- a/zephyr/projects/nissa/src/pujjo/usbc.c +++ /dev/null @@ -1,281 +0,0 @@ -/* Copyright 2022 The ChromiumOS Authors. - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#include <zephyr/logging/log.h> - -#include "charge_state_v2.h" -#include "chipset.h" -#include "hooks.h" -#include "usb_mux.h" -#include "system.h" -#include "driver/charger/isl923x_public.h" -#include "driver/retimer/anx7483_public.h" -#include "driver/tcpm/tcpci.h" -#include "driver/tcpm/raa489000.h" - -#include "nissa_common.h" - -LOG_MODULE_DECLARE(nissa, CONFIG_NISSA_LOG_LEVEL); - -struct tcpc_config_t tcpc_config[CONFIG_USB_PD_PORT_MAX_COUNT] = { - { - .bus_type = EC_BUS_TYPE_I2C, - .i2c_info = { - .port = I2C_PORT_USB_C0_TCPC, - .addr_flags = RAA489000_TCPC0_I2C_FLAGS, - }, - .drv = &raa489000_tcpm_drv, - /* RAA489000 implements TCPCI 2.0 */ - .flags = TCPC_FLAGS_TCPCI_REV2_0 | - TCPC_FLAGS_VBUS_MONITOR, - }, - { /* sub-board */ - .bus_type = EC_BUS_TYPE_I2C, - .i2c_info = { - .port = I2C_PORT_USB_C1_TCPC, - .addr_flags = RAA489000_TCPC0_I2C_FLAGS, - }, - .drv = &raa489000_tcpm_drv, - /* RAA489000 implements TCPCI 2.0 */ - .flags = TCPC_FLAGS_TCPCI_REV2_0 | - TCPC_FLAGS_VBUS_MONITOR, - }, -}; - -int board_is_sourcing_vbus(int port) -{ - int regval; - - tcpc_read(port, TCPC_REG_POWER_STATUS, ®val); - return !!(regval & TCPC_REG_POWER_STATUS_SOURCING_VBUS); -} - -int board_set_active_charge_port(int port) -{ - int is_real_port = (port >= 0 && - port < CONFIG_USB_PD_PORT_MAX_COUNT); - int i; - int old_port; - - if (!is_real_port && port != CHARGE_PORT_NONE) - return EC_ERROR_INVAL; - - old_port = charge_manager_get_active_charge_port(); - - LOG_INF("New chg p%d", port); - - /* Disable all ports. */ - if (port == CHARGE_PORT_NONE) { - for (i = 0; i < CONFIG_USB_PD_PORT_MAX_COUNT; i++) { - tcpc_write(i, TCPC_REG_COMMAND, - TCPC_REG_COMMAND_SNK_CTRL_LOW); - raa489000_enable_asgate(i, false); - } - - return EC_SUCCESS; - } - - /* Check if port is sourcing VBUS. */ - if (board_is_sourcing_vbus(port)) { - LOG_WRN("Skip enable p%d", port); - return EC_ERROR_INVAL; - } - - /* - * Turn off the other ports' sink path FETs, before enabling the - * requested charge port. - */ - for (i = 0; i < CONFIG_USB_PD_PORT_MAX_COUNT; i++) { - if (i == port) - continue; - - if (tcpc_write(i, TCPC_REG_COMMAND, - TCPC_REG_COMMAND_SNK_CTRL_LOW)) - LOG_WRN("p%d: sink path disable failed.", i); - raa489000_enable_asgate(i, false); - } - - /* - * Stop the charger IC from switching while changing ports. Otherwise, - * we can overcurrent the adapter we're switching to. (crbug.com/926056) - */ - if (old_port != CHARGE_PORT_NONE) - charger_discharge_on_ac(1); - - /* Enable requested charge port. */ - if (raa489000_enable_asgate(port, true) || - tcpc_write(port, TCPC_REG_COMMAND, - TCPC_REG_COMMAND_SNK_CTRL_HIGH)) { - LOG_WRN("p%d: sink path enable failed.", port); - charger_discharge_on_ac(0); - return EC_ERROR_UNKNOWN; - } - - /* Allow the charger IC to begin/continue switching. */ - charger_discharge_on_ac(0); - - return EC_SUCCESS; -} - -uint16_t tcpc_get_alert_status(void) -{ - uint16_t status = 0; - int regval; - - /* - * The interrupt line is shared between the TCPC and BC1.2 detector IC. - * Therefore, go out and actually read the alert registers to report the - * alert status. - */ - if (!gpio_pin_get_dt(GPIO_DT_FROM_NODELABEL(gpio_usb_c0_int_odl))) { - if (!tcpc_read16(0, TCPC_REG_ALERT, ®val)) { - /* The TCPCI Rev 1.0 spec says to ignore bits 14:12. */ - if (!(tcpc_config[0].flags & TCPC_FLAGS_TCPCI_REV2_0)) - regval &= ~((1 << 14) | (1 << 13) | (1 << 12)); - - if (regval) - status |= PD_STATUS_TCPC_ALERT_0; - } - } - - if (board_get_usb_pd_port_count() == 2 && - !gpio_pin_get_dt(GPIO_DT_FROM_ALIAS(gpio_usb_c1_int_odl))) { - if (!tcpc_read16(1, TCPC_REG_ALERT, ®val)) { - /* TCPCI spec Rev 1.0 says to ignore bits 14:12. */ - if (!(tcpc_config[1].flags & TCPC_FLAGS_TCPCI_REV2_0)) - regval &= ~((1 << 14) | (1 << 13) | (1 << 12)); - - if (regval) - status |= PD_STATUS_TCPC_ALERT_1; - } - } - - return status; -} - -void pd_power_supply_reset(int port) -{ - /* Disable VBUS */ - tcpc_write(port, TCPC_REG_COMMAND, TCPC_REG_COMMAND_SRC_CTRL_LOW); - - /* Notify host of power info change. */ - pd_send_host_event(PD_EVENT_POWER_CHANGE); -} - -__override void typec_set_source_current_limit(int port, enum tcpc_rp_value rp) -{ - if (port < 0 || port >= CONFIG_USB_PD_PORT_MAX_COUNT) - return; - - raa489000_set_output_current(port, rp); -} - -int pd_set_power_supply_ready(int port) -{ - int rv; - - if (port >= CONFIG_USB_PD_PORT_MAX_COUNT) - return EC_ERROR_INVAL; - - /* Disable charging. */ - rv = tcpc_write(port, TCPC_REG_COMMAND, TCPC_REG_COMMAND_SNK_CTRL_LOW); - if (rv) - return rv; - - /* Our policy is not to source VBUS when the AP is off. */ - if (chipset_in_state(CHIPSET_STATE_ANY_OFF)) - return EC_ERROR_NOT_POWERED; - - /* Provide Vbus. */ - rv = tcpc_write(port, TCPC_REG_COMMAND, TCPC_REG_COMMAND_SRC_CTRL_HIGH); - if (rv) - return rv; - - rv = raa489000_enable_asgate(port, true); - if (rv) - return rv; - - /* Notify host of power info change. */ - pd_send_host_event(PD_EVENT_POWER_CHANGE); - - return EC_SUCCESS; -} - -void board_reset_pd_mcu(void) -{ - /* - * TODO(b:147316511): could send a reset command to the TCPC here - * if needed. - */ -} - -/* - * Because the TCPCs and BC1.2 chips share interrupt lines, it's possible - * for an interrupt to be lost if one asserts the IRQ, the other does the same - * then the first releases it: there will only be one falling edge to trigger - * the interrupt, and the line will be held low. We handle this by running a - * deferred check after a falling edge to see whether the IRQ is still being - * asserted. If it is, we assume an interrupt may have been lost and we need - * to poll each chip for events again. - */ -#define USBC_INT_POLL_DELAY_US 5000 - -static void poll_c0_int(void); -DECLARE_DEFERRED(poll_c0_int); -static void poll_c1_int(void); -DECLARE_DEFERRED(poll_c1_int); - -static void usbc_interrupt_trigger(int port) -{ - schedule_deferred_pd_interrupt(port); - usb_charger_task_set_event(port, USB_CHG_EVENT_BC12); -} - -static inline void poll_usb_gpio(int port, - const struct gpio_dt_spec *gpio, - const struct deferred_data *ud) -{ - if (!gpio_pin_get_dt(gpio)) { - usbc_interrupt_trigger(port); - hook_call_deferred(ud, USBC_INT_POLL_DELAY_US); - } -} - -static void poll_c0_int (void) -{ - poll_usb_gpio(0, - GPIO_DT_FROM_NODELABEL(gpio_usb_c0_int_odl), - &poll_c0_int_data); -} - -static void poll_c1_int (void) -{ - poll_usb_gpio(1, - GPIO_DT_FROM_ALIAS(gpio_usb_c1_int_odl), - &poll_c1_int_data); -} - -void usb_interrupt(enum gpio_signal signal) -{ - int port; - const struct deferred_data *ud; - - if (signal == GPIO_SIGNAL(DT_NODELABEL(gpio_usb_c0_int_odl))) { - port = 0; - ud = &poll_c0_int_data; - } else { - port = 1; - ud = &poll_c1_int_data; - } - /* - * We've just been called from a falling edge, so there's definitely - * no lost IRQ right now. Cancel any pending check. - */ - hook_call_deferred(ud, -1); - /* Trigger polling of TCPC and BC1.2 in respective tasks */ - usbc_interrupt_trigger(port); - /* Check for lost interrupts in a bit */ - hook_call_deferred(ud, USBC_INT_POLL_DELAY_US); -} diff --git a/zephyr/projects/nissa/src/sub_board.c b/zephyr/projects/nissa/src/sub_board.c index 2a3333bab9..89a9954037 100644 --- a/zephyr/projects/nissa/src/sub_board.c +++ b/zephyr/projects/nissa/src/sub_board.c @@ -1,4 +1,4 @@ -/* Copyright 2022 The Chromium OS Authors. All rights reserved. +/* Copyright 2022 The ChromiumOS Authors * Use of this source code is governed by a BSD-style license that can be * found in the LICENSE file. */ @@ -7,25 +7,30 @@ #include <ap_power/ap_power.h> #include <zephyr/drivers/gpio.h> +#include <zephyr/drivers/pinctrl.h> #include <zephyr/init.h> #include <zephyr/kernel.h> #include <zephyr/sys/printk.h> +#include "cros_board_info.h" #include "driver/tcpm/tcpci.h" #include "gpio/gpio_int.h" #include "hooks.h" #include "usb_charge.h" #include "usb_pd.h" +#include "usbc/usb_muxes.h" #include "task.h" #include "nissa_common.h" +#include "nissa_hdmi.h" LOG_MODULE_DECLARE(nissa, CONFIG_NISSA_LOG_LEVEL); +#if NISSA_BOARD_HAS_HDMI_SUPPORT static void hdmi_power_handler(struct ap_power_ev_callback *cb, struct ap_power_ev_data data) { - /* Enable rails for S3 */ + /* Enable VCC on the HDMI port. */ const struct gpio_dt_spec *s3_rail = GPIO_DT_FROM_ALIAS(gpio_hdmi_en_odl); /* Connect AP's DDC to sub-board (default is USB-C aux) */ @@ -65,8 +70,54 @@ static void hdmi_hpd_interrupt(const struct device *device, LOG_DBG("HDMI HPD changed state to %d", state); } +void nissa_configure_hdmi_rails(void) +{ +#if DT_NODE_EXISTS(GPIO_DT_FROM_ALIAS(gpio_en_rails_odl)) + gpio_pin_configure_dt(GPIO_DT_FROM_ALIAS(gpio_en_rails_odl), + GPIO_OUTPUT_INACTIVE | GPIO_OPEN_DRAIN | + GPIO_PULL_UP | GPIO_ACTIVE_LOW); +#endif +} + +void nissa_configure_hdmi_vcc(void) +{ + gpio_pin_configure_dt(GPIO_DT_FROM_ALIAS(gpio_hdmi_en_odl), + GPIO_OUTPUT_INACTIVE | GPIO_OPEN_DRAIN | + GPIO_ACTIVE_LOW); +} + +__overridable void nissa_configure_hdmi_power_gpios(void) +{ + nissa_configure_hdmi_rails(); +} + +#ifdef CONFIG_SOC_IT8XXX2 +/* + * On it8xxx2, the below condition will break the EC to enter deep doze mode + * (b:237717730): + * Enhance i2c (GPE0/E7, GPH1/GPH2 or GPA4/GPA5) is enabled and its clock and + * data pins aren't both at high level. + * + * Since HDMI+type A SKU doesn't use i2c4, disable it for better power number. + */ +#define I2C4_NODE DT_NODELABEL(i2c4) +#if DT_NODE_EXISTS(I2C4_NODE) +PINCTRL_DT_DEFINE(I2C4_NODE); + +/* disable i2c4 alternate function */ +static void soc_it8xxx2_disable_i2c4_alt(void) +{ + const struct pinctrl_dev_config *pcfg = + PINCTRL_DT_DEV_CONFIG_GET(I2C4_NODE); + + pinctrl_apply_state(pcfg, PINCTRL_STATE_SLEEP); +} +#endif /* DT_NODE_EXISTS(I2C4_NODE) */ +#endif /* CONFIG_SOC_IT8XXX2 */ +#endif /* NISSA_BOARD_HAS_HDMI_SUPPORT */ + static void lte_power_handler(struct ap_power_ev_callback *cb, - struct ap_power_ev_data data) + struct ap_power_ev_data data) { /* Enable rails for S5 */ const struct gpio_dt_spec *s5_rail = @@ -76,7 +127,7 @@ static void lte_power_handler(struct ap_power_ev_callback *cb, LOG_DBG("Enabling LTE sub-board power rails"); gpio_pin_set_dt(s5_rail, 1); break; - case AP_POWER_SHUTDOWN: + case AP_POWER_HARD_OFF: LOG_DBG("Disabling LTE sub-board power rails"); gpio_pin_set_dt(s5_rail, 0); break; @@ -105,38 +156,37 @@ static void nereid_subboard_config(void) */ if (sb == NISSA_SB_C_A || sb == NISSA_SB_HDMI_A) { /* Configure VBUS enable, default off */ - gpio_pin_configure_dt( - GPIO_DT_FROM_ALIAS(gpio_en_usb_a1_vbus), - GPIO_OUTPUT_LOW); + gpio_pin_configure_dt(GPIO_DT_FROM_ALIAS(gpio_en_usb_a1_vbus), + GPIO_OUTPUT_LOW); } else { /* Turn off unused pins */ gpio_pin_configure_dt( GPIO_DT_FROM_NODELABEL(gpio_sub_usb_a1_ilimit_sdp), GPIO_DISCONNECTED); - gpio_pin_configure_dt( - GPIO_DT_FROM_ALIAS(gpio_en_usb_a1_vbus), - GPIO_DISCONNECTED); + gpio_pin_configure_dt(GPIO_DT_FROM_ALIAS(gpio_en_usb_a1_vbus), + GPIO_DISCONNECTED); /* Disable second USB-A port enable GPIO */ __ASSERT(USB_PORT_ENABLE_COUNT == 2, - "USB A port count != 2 (%d)", USB_PORT_ENABLE_COUNT); + "USB A port count != 2 (%d)", USB_PORT_ENABLE_COUNT); usb_port_enable[1] = -1; } /* * USB-C port: the default configuration has I2C on the I2C pins, * but the interrupt line needs to be configured. */ +#if CONFIG_USB_PD_PORT_MAX_COUNT > 1 if (sb == NISSA_SB_C_A || sb == NISSA_SB_C_LTE) { /* Configure interrupt input */ - gpio_pin_configure_dt( - GPIO_DT_FROM_ALIAS(gpio_usb_c1_int_odl), - GPIO_INPUT | GPIO_PULL_UP); + gpio_pin_configure_dt(GPIO_DT_FROM_ALIAS(gpio_usb_c1_int_odl), + GPIO_INPUT | GPIO_PULL_UP); } else { - /* Disable the port 1 charger task */ - task_disable_task(TASK_ID_USB_CHG_P1); - usb_muxes[1].next_mux = NULL; + /* Port doesn't exist, doesn't need muxing */ + USB_MUX_ENABLE_ALTERNATIVE(usb_mux_chain_1_no_mux); } +#endif switch (sb) { +#if NISSA_BOARD_HAS_HDMI_SUPPORT case NISSA_SB_HDMI_A: { /* * HDMI: two outputs control power which must be configured to @@ -148,14 +198,18 @@ static void nereid_subboard_config(void) static struct gpio_callback hdmi_hpd_cb; int rv, irq_key; - /* HDMI power enable outputs */ - gpio_pin_configure_dt(GPIO_DT_FROM_ALIAS(gpio_en_rails_odl), - GPIO_OUTPUT_INACTIVE | GPIO_OPEN_DRAIN | - GPIO_PULL_UP | GPIO_ACTIVE_LOW); - gpio_pin_configure_dt(GPIO_DT_FROM_ALIAS(gpio_hdmi_en_odl), - GPIO_OUTPUT_INACTIVE | GPIO_OPEN_DRAIN | - GPIO_ACTIVE_LOW); - /* Control HDMI power in concert with AP */ + nissa_configure_hdmi_power_gpios(); + +#if CONFIG_SOC_IT8XXX2 && DT_NODE_EXISTS(I2C4_NODE) + /* disable i2c4 alternate function for better power number */ + soc_it8xxx2_disable_i2c4_alt(); +#endif + + /* + * Control HDMI power according to AP power state. Some events + * won't do anything if the corresponding pin isn't configured, + * but that's okay. + */ ap_power_ev_init_callback( &power_cb, hdmi_power_handler, AP_POWER_PRE_INIT | AP_POWER_HARD_OFF | @@ -187,6 +241,7 @@ static void nereid_subboard_config(void) irq_unlock(irq_key); break; } +#endif case NISSA_SB_C_LTE: /* * LTE: Set up callbacks for enabling/disabling @@ -197,9 +252,9 @@ static void nereid_subboard_config(void) /* Control LTE power when CPU entering or * exiting S5 state. */ - ap_power_ev_init_callback( - &power_cb, lte_power_handler, - AP_POWER_SHUTDOWN | AP_POWER_PRE_INIT); + ap_power_ev_init_callback(&power_cb, lte_power_handler, + AP_POWER_HARD_OFF | + AP_POWER_PRE_INIT); ap_power_ev_add_callback(&power_cb); break; @@ -218,8 +273,10 @@ static void board_init(void) * Enable USB-C interrupts. */ gpio_enable_dt_interrupt(GPIO_INT_FROM_NODELABEL(int_usb_c0)); +#if CONFIG_USB_PD_PORT_MAX_COUNT > 1 if (board_get_usb_pd_port_count() == 2) gpio_enable_dt_interrupt(GPIO_INT_FROM_NODELABEL(int_usb_c1)); +#endif } DECLARE_HOOK(HOOK_INIT, board_init, HOOK_PRIO_DEFAULT); |