diff options
Diffstat (limited to 'baseboard/zork')
-rw-r--r-- | baseboard/zork/analyzestack.yaml | 2 | ||||
-rw-r--r-- | baseboard/zork/baseboard.c | 859 | ||||
-rw-r--r-- | baseboard/zork/baseboard.h | 313 | ||||
-rw-r--r-- | baseboard/zork/build.mk | 10 | ||||
-rw-r--r-- | baseboard/zork/usb_pd_policy.c | 484 |
5 files changed, 0 insertions, 1668 deletions
diff --git a/baseboard/zork/analyzestack.yaml b/baseboard/zork/analyzestack.yaml deleted file mode 100644 index 7ff5f39644..0000000000 --- a/baseboard/zork/analyzestack.yaml +++ /dev/null @@ -1,2 +0,0 @@ -remove: -- panic_assert_fail diff --git a/baseboard/zork/baseboard.c b/baseboard/zork/baseboard.c deleted file mode 100644 index 448403b072..0000000000 --- a/baseboard/zork/baseboard.c +++ /dev/null @@ -1,859 +0,0 @@ -/* Copyright 2019 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. - */ - -/* Zork family-specific configuration */ - -#include "adc.h" -#include "adc_chip.h" -#include "button.h" -#include "charge_manager.h" -#include "charge_state.h" -#include "charge_state_v2.h" -#include "common.h" -#include "compile_time_macros.h" -#include "console.h" -#include "cros_board_info.h" -#include "driver/accel_kionix.h" -#include "driver/accel_kx022.h" -#include "driver/accelgyro_bmi160.h" -#include "driver/bc12/pi3usb9201.h" -#include "driver/ppc/aoz1380.h" -#include "driver/ppc/nx20p348x.h" -#include "driver/retimer/pi3dpx1207.h" -#include "driver/tcpm/ps8xxx.h" -#include "driver/tcpm/nct38xx.h" -#include "driver/temp_sensor/sb_tsi.h" -#include "ec_commands.h" -#include "extpower.h" -#include "fan.h" -#include "fan_chip.h" -#include "gpio.h" -#include "hooks.h" -#include "ioexpander.h" -#include "ioexpander_nct38xx.h" -#include "i2c.h" -#include "keyboard_scan.h" -#include "lid_switch.h" -#include "motion_sense.h" -#include "power.h" -#include "power_button.h" -#include "pwm.h" -#include "pwm_chip.h" -#include "registers.h" -#include "switch.h" -#include "system.h" -#include "task.h" -#include "tcpci.h" -#include "temp_sensor.h" -#include "thermistor.h" -#include "usb_mux.h" -#include "usb_pd.h" -#include "usb_pd_tcpm.h" -#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) - -const enum gpio_signal hibernate_wake_pins[] = { - GPIO_LID_OPEN, - GPIO_AC_PRESENT, - GPIO_POWER_BUTTON_L, - GPIO_EC_RST_ODL, -}; -const int hibernate_wake_pins_used = ARRAY_SIZE(hibernate_wake_pins); - -const struct adc_t adc_channels[] = { - [ADC_TEMP_SENSOR_CHARGER] = { - .name = "CHARGER", - .input_ch = NPCX_ADC_CH2, - .factor_mul = ADC_MAX_VOLT, - .factor_div = ADC_READ_MAX + 1, - .shift = 0, - }, - [ADC_TEMP_SENSOR_SOC] = { - .name = "SOC", - .input_ch = NPCX_ADC_CH3, - .factor_mul = ADC_MAX_VOLT, - .factor_div = ADC_READ_MAX + 1, - .shift = 0, - }, -}; -BUILD_ASSERT(ARRAY_SIZE(adc_channels) == ADC_CH_COUNT); - -const struct power_signal_info power_signal_list[] = { - [X86_SLP_S3_N] = { - .gpio = GPIO_PCH_SLP_S3_L, - .flags = POWER_SIGNAL_ACTIVE_HIGH, - .name = "SLP_S3_DEASSERTED", - }, - [X86_SLP_S5_N] = { - .gpio = GPIO_PCH_SLP_S5_L, - .flags = POWER_SIGNAL_ACTIVE_HIGH, - .name = "SLP_S5_DEASSERTED", - }, - [X86_S0_PGOOD] = { - .gpio = GPIO_S0_PGOOD, - .flags = POWER_SIGNAL_ACTIVE_HIGH, - .name = "S0_PGOOD", - }, - [X86_S5_PGOOD] = { - .gpio = GPIO_S5_PGOOD, - .flags = POWER_SIGNAL_ACTIVE_HIGH, - .name = "S5_PGOOD", - }, -}; -BUILD_ASSERT(ARRAY_SIZE(power_signal_list) == POWER_SIGNAL_COUNT); - -const struct i2c_port_t i2c_ports[] = { - { - .name = "tcpc0", - .port = I2C_PORT_TCPC0, - .kbps = 400, - .scl = GPIO_EC_I2C_USB_A0_C0_SCL, - .sda = GPIO_EC_I2C_USB_A0_C0_SDA, - }, - { - .name = "tcpc1", - .port = I2C_PORT_TCPC1, - .kbps = 400, - .scl = GPIO_EC_I2C_USB_A1_C1_SCL, - .sda = GPIO_EC_I2C_USB_A1_C1_SDA, - }, - { - .name = "power", - .port = I2C_PORT_BATTERY, - .kbps = 100, - .scl = GPIO_EC_I2C_POWER_CBI_SCL, - .sda = GPIO_EC_I2C_POWER_CBI_SDA, - }, - { - .name = "mux", - .port = I2C_PORT_USB_MUX, - .kbps = 400, - .scl = GPIO_EC_I2C_USBC_AP_MUX_SCL, - .sda = GPIO_EC_I2C_USBC_AP_MUX_SDA, - }, - { - .name = "thermal", - .port = I2C_PORT_THERMAL, - .kbps = 400, - .scl = GPIO_FCH_SIC, - .sda = GPIO_FCH_SID, - }, - { - .name = "sensor", - .port = I2C_PORT_SENSOR, - .kbps = 400, - .scl = GPIO_EC_I2C_SENSOR_SCL, - .sda = GPIO_EC_I2C_SENSOR_SDA, - }, - { - .name = "ap_audio", - .port = I2C_PORT_AP_AUDIO, - .kbps = 400, - .scl = GPIO_FCH_I2C_AUDIO_SCL, - .sda = GPIO_FCH_I2C_AUDIO_SDA, - }, - { - .name = "ap_hdmi", - .port = I2C_PORT_AP_HDMI, - .kbps = 400, - .scl = GPIO_FCH_I2C_HDMI_HUB_3V3_SCL, - .sda = GPIO_FCH_I2C_HDMI_HUB_3V3_SDA, - }, -}; -const unsigned int i2c_ports_used = ARRAY_SIZE(i2c_ports); - -const struct pwm_t pwm_channels[] = { - [PWM_CH_KBLIGHT] = { - .channel = 3, - .flags = PWM_CONFIG_DSLEEP, - .freq = 100, - }, - [PWM_CH_FAN] = { - .channel = 2, - .flags = PWM_CONFIG_OPEN_DRAIN, - .freq = 25000, - }, -}; -BUILD_ASSERT(ARRAY_SIZE(pwm_channels) == PWM_CH_COUNT); - -/* Physical fans. These are logically separate from pwm_channels. */ -const struct fan_conf fan_conf_0 = { - .flags = FAN_USE_RPM_MODE, - .ch = MFT_CH_0, /* Use MFT id to control fan */ - .pgood_gpio = -1, - .enable_gpio = -1, -}; -const struct fan_rpm fan_rpm_0 = { - .rpm_min = 3100, - .rpm_start = 3100, - .rpm_max = 6900, -}; -const struct fan_t fans[] = { - [FAN_CH_0] = { - .conf = &fan_conf_0, - .rpm = &fan_rpm_0, - }, -}; -BUILD_ASSERT(ARRAY_SIZE(fans) == FAN_CH_COUNT); - -/* MFT channels. These are logically separate from pwm_channels. */ -const struct mft_t mft_channels[] = { - [MFT_CH_0] = { - .module = NPCX_MFT_MODULE_1, - .clk_src = TCKC_LFCLK, - .pwm_id = PWM_CH_FAN, - }, -}; -BUILD_ASSERT(ARRAY_SIZE(mft_channels) == MFT_CH_COUNT); - -struct ppc_config_t ppc_chips[] = { - [USBC_PORT_C0] = { - /* Device does not talk I2C */ - .drv = &aoz1380_drv - }, - - [USBC_PORT_C1] = { - .i2c_port = I2C_PORT_TCPC1, - .i2c_addr_flags = NX20P3483_ADDR1_FLAGS, - .drv = &nx20p348x_drv - }, -}; -BUILD_ASSERT(ARRAY_SIZE(ppc_chips) == USBC_PORT_COUNT); -unsigned int ppc_cnt = ARRAY_SIZE(ppc_chips); - -void ppc_interrupt(enum gpio_signal signal) -{ - switch (signal) { - case GPIO_USB_C0_PPC_FAULT_ODL: - aoz1380_interrupt(USBC_PORT_C0); - break; - - case GPIO_USB_C1_PPC_INT_ODL: - nx20p348x_interrupt(USBC_PORT_C1); - break; - - default: - break; - } -} - -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; -} - -const struct tcpc_config_t tcpc_config[] = { - [USBC_PORT_C0] = { - .bus_type = EC_BUS_TYPE_I2C, - .i2c_info = { - .port = I2C_PORT_TCPC0, - .addr_flags = NCT38XX_I2C_ADDR1_1_FLAGS, - }, - .drv = &nct38xx_tcpm_drv, - }, - [USBC_PORT_C1] = { - .bus_type = EC_BUS_TYPE_I2C, - .i2c_info = { - .port = I2C_PORT_TCPC1, - .addr_flags = NCT38XX_I2C_ADDR1_1_FLAGS, - }, - .drv = &nct38xx_tcpm_drv, - }, -}; -BUILD_ASSERT(ARRAY_SIZE(tcpc_config) == USBC_PORT_COUNT); -BUILD_ASSERT(CONFIG_USB_PD_PORT_MAX_COUNT == USBC_PORT_COUNT); - -const struct pi3usb9201_config_t pi3usb9201_bc12_chips[] = { - [USBC_PORT_C0] = { - .i2c_port = I2C_PORT_TCPC0, - .i2c_addr_flags = PI3USB9201_I2C_ADDR_3_FLAGS, - }, - - [USBC_PORT_C1] = { - .i2c_port = I2C_PORT_TCPC1, - .i2c_addr_flags = PI3USB9201_I2C_ADDR_3_FLAGS, - }, -}; -BUILD_ASSERT(ARRAY_SIZE(pi3usb9201_bc12_chips) == USBC_PORT_COUNT); - -void baseboard_tcpc_init(void) -{ - /* Enable PPC interrupts. */ - gpio_enable_interrupt(GPIO_USB_C0_PPC_FAULT_ODL); - gpio_enable_interrupt(GPIO_USB_C1_PPC_INT_ODL); - - /* Enable TCPC interrupts. */ - gpio_enable_interrupt(GPIO_USB_C0_TCPC_INT_ODL); - gpio_enable_interrupt(GPIO_USB_C1_TCPC_INT_ODL); - - /* Enable BC 1.2 interrupts */ - gpio_enable_interrupt(GPIO_USB_C0_BC12_INT_ODL); - gpio_enable_interrupt(GPIO_USB_C1_BC12_INT_ODL); -} -DECLARE_HOOK(HOOK_INIT, baseboard_tcpc_init, HOOK_PRIO_INIT_I2C + 1); - -/* - * In the AOZ1380 PPC, there are no programmable features. We use - * the attached NCT3807 to control a GPIO to indicate 1A5 or 3A0 - * current limits. - */ -int board_aoz1380_set_vbus_source_current_limit(int port, - enum tcpc_rp_value rp) -{ - int rv; - - /* Use the TCPC to set the current limit */ - rv = ioex_set_level(IOEX_USB_C0_PPC_ILIM_3A_EN, - (rp == TYPEC_RP_3A0) ? 1 : 0); - - return rv; -} - -int board_tcpc_fast_role_swap_enable(int port, int enable) -{ - int rv = EC_SUCCESS; - - /* Use the TCPC to enable fast switch when FRS included */ - if (port == USBC_PORT_C0) { - rv = ioex_set_level(IOEX_USB_C0_TCPC_FASTSW_CTL_EN, - !!enable); - } else { - rv = ioex_set_level(IOEX_USB_C1_TCPC_FASTSW_CTL_EN, - !!enable); - } - - return rv; -} - -static void reset_pd_port(int port, enum gpio_signal reset_gpio_l, - int hold_delay, int finish_delay) -{ - gpio_set_level(reset_gpio_l, 0); - msleep(hold_delay); - gpio_set_level(reset_gpio_l, 1); - if (finish_delay) - msleep(finish_delay); -} - -void board_reset_pd_mcu(void) -{ - /* Reset TCPC0 */ - reset_pd_port(USBC_PORT_C0, GPIO_USB_C0_TCPC_RST_L, - NCT38XX_RESET_HOLD_DELAY_MS, - NCT38XX_RESET_POST_DELAY_MS); - - /* Reset TCPC1 */ - reset_pd_port(USBC_PORT_C1, GPIO_USB_C1_TCPC_RST_L, - NCT38XX_RESET_HOLD_DELAY_MS, - NCT38XX_RESET_POST_DELAY_MS); -} - -uint16_t tcpc_get_alert_status(void) -{ - uint16_t status = 0; - - /* - * Check which port has the ALERT line set and ignore if that TCPC has - * its reset line active. - */ - if (!gpio_get_level(GPIO_USB_C0_TCPC_INT_ODL)) { - if (gpio_get_level(GPIO_USB_C0_TCPC_RST_L) != 0) - status |= PD_STATUS_TCPC_ALERT_0; - } - - if (!gpio_get_level(GPIO_USB_C1_TCPC_INT_ODL)) { - if (gpio_get_level(GPIO_USB_C1_TCPC_RST_L) != 0) - status |= PD_STATUS_TCPC_ALERT_1; - } - - return status; -} - -void tcpc_alert_event(enum gpio_signal signal) -{ - int port = -1; - - switch (signal) { - case GPIO_USB_C0_TCPC_INT_ODL: - port = 0; - break; - case GPIO_USB_C1_TCPC_INT_ODL: - port = 1; - break; - default: - return; - } - - schedule_deferred_pd_interrupt(port); -} - -void bc12_interrupt(enum gpio_signal signal) -{ - switch (signal) { - case GPIO_USB_C0_BC12_INT_ODL: - task_set_event(TASK_ID_USB_CHG_P0, USB_CHG_EVENT_BC12, 0); - break; - - case GPIO_USB_C1_BC12_INT_ODL: - task_set_event(TASK_ID_USB_CHG_P1, USB_CHG_EVENT_BC12, 0); - break; - - default: - break; - } -} - -struct usb_mux usb_muxes[] = { - [USBC_PORT_C0] = { - .driver = &amd_fp5_usb_mux_driver, - }, - [USBC_PORT_C1] = { - .driver = &tcpci_tcpm_usb_mux_driver, - .hpd_update = &ps8xxx_tcpc_update_hpd_status, - }, -}; -BUILD_ASSERT(ARRAY_SIZE(usb_muxes) == USBC_PORT_COUNT); - -struct usb_retimer usb_retimers[USBC_PORT_COUNT] = { - [USBC_PORT_C0] = { - .driver = &pi3dpx1207_usb_retimer, - .i2c_port = I2C_PORT_TCPC0, - .i2c_addr_flags = PI3DPX1207_I2C_ADDR_FLAGS, - .gpio_enable = IOEX_USB_C0_DATA_EN, - .gpio_dp_enable = GPIO_USB_C0_IN_HPD, - }, - [USBC_PORT_C1] = { - }, -}; - -struct ioexpander_config_t ioex_config[] = { - [USBC_PORT_C0] = { - .i2c_host_port = I2C_PORT_TCPC0, - .i2c_slave_addr = NCT38XX_I2C_ADDR1_1_FLAGS, - .drv = &nct38xx_ioexpander_drv, - }, - [USBC_PORT_C1] = { - .i2c_host_port = I2C_PORT_TCPC1, - .i2c_slave_addr = NCT38XX_I2C_ADDR1_1_FLAGS, - .drv = &nct38xx_ioexpander_drv, - }, -}; -BUILD_ASSERT(ARRAY_SIZE(ioex_config) == USBC_PORT_COUNT); -BUILD_ASSERT(CONFIG_IO_EXPANDER_PORT_COUNT == USBC_PORT_COUNT); - -const int usb_port_enable[USB_PORT_COUNT] = { - IOEX_EN_USB_A0_5V, - IOEX_EN_USB_A1_5V_DB, -}; - -static void baseboard_chipset_suspend(void) -{ - /* Disable display and keyboard backlights. */ - gpio_set_level(GPIO_ENABLE_BACKLIGHT_L, 1); - ioex_set_level(IOEX_KB_BL_EN, 0); -} -DECLARE_HOOK(HOOK_CHIPSET_SUSPEND, baseboard_chipset_suspend, - HOOK_PRIO_DEFAULT); - -static void baseboard_chipset_resume(void) -{ - /* Enable display and keyboard backlights. */ - gpio_set_level(GPIO_ENABLE_BACKLIGHT_L, 0); - ioex_set_level(IOEX_KB_BL_EN, 1); -} -DECLARE_HOOK(HOOK_CHIPSET_RESUME, baseboard_chipset_resume, HOOK_PRIO_DEFAULT); - -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); -} - -/* Keyboard scan setting */ -struct keyboard_scan_config keyscan_config = { - /* Extra delay when KSO2 is tied to Cr50. */ - .output_settle_us = 60, - .debounce_down_us = 6 * MSEC, - .debounce_up_us = 30 * MSEC, - .scan_period_us = 1500, - .min_post_scan_delay_us = 1000, - .poll_timeout_us = SECOND, - .actual_key_mask = { - 0x3c, 0xff, 0xff, 0xff, 0xff, 0xf5, 0xff, - 0xa4, 0xff, 0xfe, 0x55, 0xfa, 0xca /* full set */ - }, -}; - -/* - * We use 11 as the scaling factor so that the maximum mV value below (2761) - * can be compressed to fit in a uint8_t. - */ -#define THERMISTOR_SCALING_FACTOR 11 - -/* - * Values are calculated from the "Resistance VS. Temperature" table on the - * Murata page for part NCP15WB473F03RC. Vdd=3.3V, R=30.9Kohm. - */ -static const struct thermistor_data_pair thermistor_data[] = { - { 2761 / THERMISTOR_SCALING_FACTOR, 0}, - { 2492 / THERMISTOR_SCALING_FACTOR, 10}, - { 2167 / THERMISTOR_SCALING_FACTOR, 20}, - { 1812 / THERMISTOR_SCALING_FACTOR, 30}, - { 1462 / THERMISTOR_SCALING_FACTOR, 40}, - { 1146 / THERMISTOR_SCALING_FACTOR, 50}, - { 878 / THERMISTOR_SCALING_FACTOR, 60}, - { 665 / THERMISTOR_SCALING_FACTOR, 70}, - { 500 / THERMISTOR_SCALING_FACTOR, 80}, - { 434 / THERMISTOR_SCALING_FACTOR, 85}, - { 376 / THERMISTOR_SCALING_FACTOR, 90}, - { 326 / THERMISTOR_SCALING_FACTOR, 95}, - { 283 / THERMISTOR_SCALING_FACTOR, 100} -}; - -static const struct thermistor_info thermistor_info = { - .scaling_factor = THERMISTOR_SCALING_FACTOR, - .num_pairs = ARRAY_SIZE(thermistor_data), - .data = thermistor_data, -}; - -static int board_get_temp(int idx, int *temp_k) -{ - int mv; - int temp_c; - enum adc_channel channel; - - /* idx is the sensor index set below in temp_sensors[] */ - switch (idx) { - case TEMP_SENSOR_CHARGER: - /* TODO: b/143598098 - * Revision 1.6 of the schematic will put this - * thermistor on power rail EC_A instead of - * PP3300_A. This will make the charger circuit - * temperature available even when the AP is not - * powered and the check will no longer be needed - */ - - /* thermistor is not powered in G3 */ - if (chipset_in_state(CHIPSET_STATE_HARD_OFF)) - return EC_ERROR_NOT_POWERED; - - channel = ADC_TEMP_SENSOR_CHARGER; - break; - case TEMP_SENSOR_SOC: - /* thermistor is not powered in G3 */ - if (chipset_in_state(CHIPSET_STATE_HARD_OFF)) - return EC_ERROR_NOT_POWERED; - - channel = ADC_TEMP_SENSOR_SOC; - break; - default: - return EC_ERROR_INVAL; - } - - mv = adc_read_channel(channel); - if (mv < 0) - return EC_ERROR_INVAL; - - temp_c = thermistor_linear_interpolate(mv, &thermistor_info); - *temp_k = C_TO_K(temp_c); - return EC_SUCCESS; -} - -const struct temp_sensor_t temp_sensors[] = { - [TEMP_SENSOR_CHARGER] = { - .name = "Charger", - .type = TEMP_SENSOR_TYPE_BOARD, - .read = board_get_temp, - .idx = TEMP_SENSOR_CHARGER, - .action_delay_sec = 1, - }, - [TEMP_SENSOR_SOC] = { - .name = "SOC", - .type = TEMP_SENSOR_TYPE_BOARD, - .read = board_get_temp, - .idx = TEMP_SENSOR_SOC, - .action_delay_sec = 5, - }, - [TEMP_SENSOR_CPU] = { - .name = "CPU", - .type = TEMP_SENSOR_TYPE_CPU, - .read = sb_tsi_get_val, - .idx = 0, - .action_delay_sec = 4, - }, -}; -BUILD_ASSERT(ARRAY_SIZE(temp_sensors) == TEMP_SENSOR_COUNT); - -const static struct ec_thermal_config thermal_thermistor = { - .temp_host = { - [EC_TEMP_THRESH_HIGH] = C_TO_K(75), - [EC_TEMP_THRESH_HALT] = C_TO_K(80), - }, - .temp_host_release = { - [EC_TEMP_THRESH_HIGH] = C_TO_K(65), - }, - .temp_fan_off = C_TO_K(25), - .temp_fan_max = C_TO_K(50), -}; - -const static struct ec_thermal_config thermal_cpu = { - .temp_host = { - [EC_TEMP_THRESH_HIGH] = C_TO_K(85), - [EC_TEMP_THRESH_HALT] = C_TO_K(95), - }, - .temp_host_release = { - [EC_TEMP_THRESH_HIGH] = C_TO_K(65), - }, - .temp_fan_off = C_TO_K(25), - .temp_fan_max = C_TO_K(50), -}; - -struct ec_thermal_config thermal_params[TEMP_SENSOR_COUNT]; - -static void setup_fans(void) -{ - thermal_params[TEMP_SENSOR_CHARGER] = thermal_thermistor; - thermal_params[TEMP_SENSOR_SOC] = thermal_thermistor; - thermal_params[TEMP_SENSOR_CPU] = thermal_cpu; -} - -#ifdef HAS_TASK_MOTIONSENSE - -/* Motion sensors */ -static struct mutex g_lid_mutex; -static struct mutex g_base_mutex; - -mat33_fp_t zork_base_standard_ref = { - { FLOAT_TO_FP(1), 0, 0}, - { 0, FLOAT_TO_FP(1), 0}, - { 0, 0, FLOAT_TO_FP(1)} -}; - -mat33_fp_t lid_standard_ref = { - { FLOAT_TO_FP(1), 0, 0}, - { 0, FLOAT_TO_FP(1), 0}, - { 0, 0, FLOAT_TO_FP(1)} -}; - -/* sensor private data */ -static struct kionix_accel_data g_kx022_data; -static struct bmi160_drv_data_t g_bmi160_data; - -/* TODO(gcc >= 5.0) Remove the casts to const pointer at rot_standard_ref */ -struct motion_sensor_t motion_sensors[] = { - [LID_ACCEL] = { - .name = "Lid Accel", - .active_mask = SENSOR_ACTIVE_S0_S3, - .chip = MOTIONSENSE_CHIP_KX022, - .type = MOTIONSENSE_TYPE_ACCEL, - .location = MOTIONSENSE_LOC_LID, - .drv = &kionix_accel_drv, - .mutex = &g_lid_mutex, - .drv_data = &g_kx022_data, - .port = I2C_PORT_SENSOR, - .i2c_spi_addr_flags = KX022_ADDR1_FLAGS, - .rot_standard_ref = (const mat33_fp_t *)&lid_standard_ref, - .default_range = 2, /* g, enough for laptop. */ - .min_frequency = KX022_ACCEL_MIN_FREQ, - .max_frequency = KX022_ACCEL_MAX_FREQ, - .config = { - /* EC use accel for angle detection */ - [SENSOR_CONFIG_EC_S0] = { - .odr = 10000 | ROUND_UP_FLAG, - .ec_rate = 100, - }, - /* EC use accel for angle detection */ - [SENSOR_CONFIG_EC_S3] = { - .odr = 10000 | ROUND_UP_FLAG, - }, - }, - }, - - [BASE_ACCEL] = { - .name = "Base Accel", - .active_mask = SENSOR_ACTIVE_S0_S3, - .chip = MOTIONSENSE_CHIP_BMI160, - .type = MOTIONSENSE_TYPE_ACCEL, - .location = MOTIONSENSE_LOC_BASE, - .drv = &bmi160_drv, - .mutex = &g_base_mutex, - .drv_data = &g_bmi160_data, - .port = I2C_PORT_SENSOR, - .i2c_spi_addr_flags = BMI160_ADDR0_FLAGS, - .default_range = 2, /* g, enough for laptop */ - .rot_standard_ref = (const mat33_fp_t *)&zork_base_standard_ref, - .min_frequency = BMI160_ACCEL_MIN_FREQ, - .max_frequency = BMI160_ACCEL_MAX_FREQ, - .config = { - /* EC use accel for angle detection */ - [SENSOR_CONFIG_EC_S0] = { - .odr = 10000 | ROUND_UP_FLAG, - .ec_rate = 100, - }, - /* EC use accel for angle detection */ - [SENSOR_CONFIG_EC_S3] = { - .odr = 10000 | ROUND_UP_FLAG, - }, - }, - }, - - [BASE_GYRO] = { - .name = "Base Gyro", - .active_mask = SENSOR_ACTIVE_S0_S3, - .chip = MOTIONSENSE_CHIP_BMI160, - .type = MOTIONSENSE_TYPE_GYRO, - .location = MOTIONSENSE_LOC_BASE, - .drv = &bmi160_drv, - .mutex = &g_base_mutex, - .drv_data = &g_bmi160_data, - .port = I2C_PORT_SENSOR, - .i2c_spi_addr_flags = BMI160_ADDR0_FLAGS, - .default_range = 1000, /* dps */ - .rot_standard_ref = (const mat33_fp_t *)&zork_base_standard_ref, - .min_frequency = BMI160_GYRO_MIN_FREQ, - .max_frequency = BMI160_GYRO_MAX_FREQ, - }, -}; - -unsigned int motion_sensor_count = ARRAY_SIZE(motion_sensors); - -#endif /* HAS_TASK_MOTIONSENSE */ - -#ifndef TEST_BUILD -void lid_angle_peripheral_enable(int enable) -{ - if (board_is_convertible()) - keyboard_scan_enable(enable, KB_SCAN_DISABLE_LID_ANGLE); -} -#endif - -static uint32_t sku_id; - -static void cbi_init(void) -{ - uint32_t board_version = 0; - uint32_t val; - - if (cbi_get_board_version(&val) == EC_SUCCESS) - board_version = val; - ccprints("Board Version: %d (0x%x)", board_version, board_version); - - if (cbi_get_sku_id(&val) == EC_SUCCESS) - sku_id = val; - ccprints("SKU: %d (0x%x)", sku_id, sku_id); - -#ifdef HAS_TASK_MOTIONSENSE - board_update_sensor_config_from_sku(); -#endif - -} -DECLARE_HOOK(HOOK_INIT, cbi_init, HOOK_PRIO_INIT_I2C + 1); - -uint32_t system_get_sku_id(void) -{ - return sku_id; -} - -/* - * Returns 1 for boards that are convertible into tablet mode, and zero for - * clamshells. - */ -int board_is_convertible(void) -{ - /* TODO: Add convertible SKU values */ - return 0; -} - -int board_is_lid_angle_tablet_mode(void) -{ - return board_is_convertible(); -} - -uint32_t board_override_feature_flags0(uint32_t flags0) -{ - return flags0; -} - -uint32_t board_override_feature_flags1(uint32_t flags1) -{ - return flags1; -} - -void board_overcurrent_event(int port, int is_overcurrented) -{ - switch (port) { - case USBC_PORT_C0: - ioex_set_level(IOEX_USB_C0_FAULT_ODL, !is_overcurrented); - break; - - case USBC_PORT_C1: - ioex_set_level(IOEX_USB_C1_FAULT_ODL, !is_overcurrented); - break; - - default: - break; - } -} - -static void baseboard_init(void) -{ - /* Initialize Fans */ - setup_fans(); -} -DECLARE_HOOK(HOOK_INIT, baseboard_init, HOOK_PRIO_DEFAULT); diff --git a/baseboard/zork/baseboard.h b/baseboard/zork/baseboard.h deleted file mode 100644 index 74dd43b747..0000000000 --- a/baseboard/zork/baseboard.h +++ /dev/null @@ -1,313 +0,0 @@ -/* Copyright 2019 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. - */ - -/* Zork baseboard configuration */ - -#ifndef __CROS_EC_BASEBOARD_H -#define __CROS_EC_BASEBOARD_H - -/* NPCX7 config */ -#define NPCX_UART_MODULE2 1 /* GPIO64/65 are used as UART pins. */ -#define NPCX_TACH_SEL2 0 /* No tach. */ -#define NPCX7_PWM1_SEL 0 /* GPIO C2 is not used as PWM1. */ - -/* Internal SPI flash on NPCX7 */ -#define CONFIG_FLASH_SIZE (512 * 1024) -#define CONFIG_SPI_FLASH_REGS -#define CONFIG_SPI_FLASH_W25Q40 /* Internal SPI flash type. */ - -/* - * Enable 1 slot of secure temporary storage to support - * suspend/resume with read/write memory training. - */ -#define CONFIG_VSTORE -#define CONFIG_VSTORE_SLOT_COUNT 1 - -#define CONFIG_ADC -#define CONFIG_BACKLIGHT_LID -#define CONFIG_BACKLIGHT_LID_ACTIVE_LOW -#define CONFIG_CMD_AP_RESET_LOG -#define CONFIG_CPU_PROCHOT_ACTIVE_LOW -#define CONFIG_EC_FEATURE_BOARD_OVERRIDE -#define CONFIG_HIBERNATE_PSL -#define CONFIG_HOSTCMD_ESPI -#define CONFIG_HOSTCMD_SKUID -#define CONFIG_I2C -#define CONFIG_I2C_MASTER -#define CONFIG_LTO -#define CONFIG_PWM -#define CONFIG_PWM_KBLIGHT -#define CONFIG_TEMP_SENSOR -#define CONFIG_THERMISTOR_NCP15WB -#define CONFIG_VBOOT_HASH -#define CONFIG_VOLUME_BUTTONS - -/* CBI EEPROM for board version and SKU ID */ -#define CONFIG_CROS_BOARD_INFO -#define CONFIG_BOARD_VERSION_CBI -#define CONFIG_CRC8 - -#define CONFIG_BATTERY_CUT_OFF -#define CONFIG_BATTERY_FUEL_GAUGE -#define CONFIG_BATTERY_REVIVE_DISCONNECT -#define CONFIG_BATTERY_SMART - -#define CONFIG_BC12_DETECT_PI3USB9201 - -#define CONFIG_CHARGER -#define CONFIG_CHARGE_MANAGER -#define CONFIG_CHARGER_DISCHARGE_ON_AC -#define CONFIG_CHARGER_INPUT_CURRENT 512 -#define CONFIG_CHARGER_ISL9241 -#define CONFIG_CHARGER_SENSE_RESISTOR 10 -#define CONFIG_CHARGER_SENSE_RESISTOR_AC 20 -#define CONFIG_CHARGE_RAMP_HW - -#define CONFIG_CHIPSET_STONEY -#define CONFIG_CHIPSET_CAN_THROTTLE -#define CONFIG_CHIPSET_RESET_HOOK - -#undef CONFIG_EXTPOWER_DEBOUNCE_MS -#define CONFIG_EXTPOWER_DEBOUNCE_MS 200 -#define CONFIG_EXTPOWER_GPIO -#define CONFIG_POWER_COMMON -#define CONFIG_POWER_SHUTDOWN_PAUSE_IN_S5 -#define CONFIG_POWER_BUTTON -#define CONFIG_POWER_BUTTON_X86 - -#define CONFIG_FANS FAN_CH_COUNT -#undef CONFIG_FAN_INIT_SPEED -#define CONFIG_FAN_INIT_SPEED 50 -#define CONFIG_THROTTLE_AP - -#define CONFIG_LED_COMMON -#define CONFIG_CMD_LEDTEST -#define CONFIG_LED_ONOFF_STATES - -/* - * On power-on, H1 releases the EC from reset but then quickly asserts and - * releases the reset a second time. This means the EC sees 2 resets: - * (1) power-on reset, (2) reset-pin reset. If we add a delay between reset (1) - * and configuring GPIO output levels, then reset (2) will happen before the - * end of the delay so we avoid extra output toggles. - */ -#define CONFIG_GPIO_INIT_POWER_ON_DELAY_MS 100 - -#define CONFIG_IO_EXPANDER -#define CONFIG_IO_EXPANDER_NCT38XX -#define CONFIG_IO_EXPANDER_PORT_COUNT USBC_PORT_COUNT - -#define CONFIG_KEYBOARD_BOARD_CONFIG -#define CONFIG_KEYBOARD_COL2_INVERTED -#define CONFIG_KEYBOARD_PROTOCOL_8042 - -/* - * USB ID - * - * This is allocated specifically for Zork - * http://google3/hardware/standards/usb/ - */ -#define CONFIG_USB_PID 0x5040 - -/* TODO(b/142284905): Enable new PD stack */ -#if 0 -/* Enable the new USB-C PD stack */ -#define CONFIG_USB_PE_SM -#define CONFIG_USB_PRL_SM -#define CONFIG_USB_SM_FRAMEWORK -#define CONFIG_USB_TYPEC_SM -#define CONFIG_USB_TYPEC_DRP_ACC_TRYSRC -#define CONFIG_USB_TYPEC_PD_FAST_ROLE_SWAP -#endif - -#define CONFIG_CMD_PD_CONTROL -#define CONFIG_USB_CHARGER -#define CONFIG_USB_POWER_DELIVERY -#define CONFIG_USB_PD_ALT_MODE -#define CONFIG_USB_PD_ALT_MODE_DFP -#define CONFIG_USB_PD_COMM_LOCKED -#define CONFIG_USB_PD_DISCHARGE_PPC -#define CONFIG_USB_PD_DUAL_ROLE -#define CONFIG_USB_PD_DUAL_ROLE_AUTO_TOGGLE -#define CONFIG_USB_PD_LOGGING -#define CONFIG_USB_PD_MAX_SINGLE_SOURCE_CURRENT TYPEC_RP_3A0 -#define CONFIG_USB_PD_PORT_MAX_COUNT 2 -#define CONFIG_USB_PD_TCPC_LOW_POWER -#define CONFIG_USB_PD_TCPM_MUX -#define CONFIG_USB_PD_TCPM_NCT38XX -#define CONFIG_USB_PD_TCPM_PS8751 -#define CONFIG_USB_PD_TCPM_TCPCI -#define CONFIG_USB_PD_TRY_SRC -#define CONFIG_USB_PD_VBUS_DETECT_TCPC -#define CONFIG_USBC_PPC -#define CONFIG_USBC_PPC_SBU -#define CONFIG_USBC_PPC_AOZ1380 -#define CONFIG_USBC_PPC_NX20P3483 -#define CONFIG_USBC_RETIMER_PI3DPX1207 -#define CONFIG_USBC_SS_MUX -#define CONFIG_USBC_SS_MUX_DFP_ONLY -#define CONFIG_USBC_VCONN -#define CONFIG_USBC_VCONN_SWAP -#define CONFIG_USB_MUX_AMD_FP5 - -/* USB-A config */ -#define USB_PORT_COUNT 2 -#define CONFIG_USB_PORT_POWER_SMART -#define CONFIG_USB_PORT_POWER_SMART_CDP_SDP_ONLY -#define CONFIG_USB_PORT_POWER_SMART_DEFAULT_MODE USB_CHARGE_MODE_CDP -#define CONFIG_USB_PORT_POWER_SMART_INVERTED -#define GPIO_USB1_ILIM_SEL IOEX_USB_A0_CHARGE_EN_L -#define GPIO_USB2_ILIM_SEL IOEX_USB_A1_CHARGE_EN_DB_L - -#define PD_POWER_SUPPLY_TURN_ON_DELAY 30000 /* us */ -#define PD_POWER_SUPPLY_TURN_OFF_DELAY 30000 /* us */ -#define PD_VCONN_SWAP_DELAY 5000 /* us */ - -#define PD_OPERATING_POWER_MW 15000 -#define PD_MAX_POWER_MW 45000 -#define PD_MAX_CURRENT_MA 3000 -#define PD_MAX_VOLTAGE_MV 20000 - -/* - * Minimum conditions to start AP and perform swsync. Note that when the - * charger is connected via USB-PD analog signaling, the boot will proceed - * regardless. - */ -#define CONFIG_CHARGER_MIN_BAT_PCT_FOR_POWER_ON 3 - -/* - * Require PD negotiation to be complete when we are in a low-battery condition - * prior to releasing depthcharge to the kernel. - */ -#define CONFIG_CHARGER_LIMIT_POWER_THRESH_CHG_MW 15001 -#define CONFIG_CHARGER_LIMIT_POWER_THRESH_BAT_PCT 3 - -/* Increase length of history buffer for port80 messages. */ -#undef CONFIG_PORT80_HISTORY_LEN -#define CONFIG_PORT80_HISTORY_LEN 256 - -#define I2C_PORT_TCPC0 NPCX_I2C_PORT0_0 -#define I2C_PORT_TCPC1 NPCX_I2C_PORT1_0 -#define I2C_PORT_BATTERY NPCX_I2C_PORT2_0 -#define I2C_PORT_CHARGER NPCX_I2C_PORT2_0 -#define I2C_PORT_EEPROM NPCX_I2C_PORT2_0 -#define I2C_PORT_USB_MUX NPCX_I2C_PORT3_0 -#define I2C_PORT_THERMAL NPCX_I2C_PORT4_1 -#define I2C_PORT_SENSOR NPCX_I2C_PORT5_0 -#define I2C_PORT_ACCEL NPCX_I2C_PORT5_0 -#define I2C_PORT_AP_AUDIO NPCX_I2C_PORT6_1 -#define I2C_PORT_AP_HDMI NPCX_I2C_PORT7_0 - -#define I2C_ADDR_EEPROM_FLAGS 0x50 - -/* Sensors */ -#define CONFIG_MKBP_EVENT -#define CONFIG_DYNAMIC_MOTION_SENSOR_COUNT - -/* Thermal */ -#define CONFIG_TEMP_SENSOR_SB_TSI - -/* Enable sensor fifo, must also define the _SIZE and _THRES */ -#define CONFIG_ACCEL_FIFO -/* FIFO size is a power of 2. */ -#define CONFIG_ACCEL_FIFO_SIZE 256 -/* Depends on how fast the AP boots and typical ODRs. */ -#define CONFIG_ACCEL_FIFO_THRES (CONFIG_ACCEL_FIFO_SIZE / 3) - -#ifndef __ASSEMBLER__ - -#include "gpio_signal.h" -#include "math_util.h" -#include "registers.h" - -enum adc_channel { - ADC_TEMP_SENSOR_CHARGER, - ADC_TEMP_SENSOR_SOC, - ADC_CH_COUNT -}; - -enum power_signal { - X86_SLP_S3_N, - X86_SLP_S5_N, - X86_S0_PGOOD, - X86_S5_PGOOD, - POWER_SIGNAL_COUNT -}; - -enum temp_sensor_id { - TEMP_SENSOR_CHARGER = 0, - TEMP_SENSOR_SOC, - TEMP_SENSOR_CPU, - TEMP_SENSOR_COUNT -}; - -enum pwm_channel { - PWM_CH_KBLIGHT = 0, - PWM_CH_FAN, - PWM_CH_COUNT -}; - -enum fan_channel { - FAN_CH_0 = 0, - /* Number of FAN channels */ - FAN_CH_COUNT, -}; - -enum mft_channel { - MFT_CH_0 = 0, - /* Number of MFT channels */ - MFT_CH_COUNT, -}; - -enum usbc_port { - USBC_PORT_C0 = 0, - USBC_PORT_C1, - USBC_PORT_COUNT -}; - -enum sensor_id { - LID_ACCEL, - BASE_ACCEL, - BASE_GYRO, - SENSOR_COUNT, -}; - -/* - * Matrix to rotate accelerators into the standard reference frame. The default - * is the identity which is correct for the reference design. Variations of - * Zork may need to change it for manufacturability. - * For the lid: - * +x to the right - * +y up - * +z out of the page - * - * The principle axes of the body are aligned with the lid when the lid is in - * the 180 degree position (open, flat). - * - * Boards within the Zork family may need to modify this definition at - * board_init() time. - */ -extern mat33_fp_t zork_base_standard_ref; - -/* Sensors without hardware FIFO are in forced mode */ -#define CONFIG_ACCEL_FORCE_MODE_MASK (1 << LID_ACCEL) - -void board_reset_pd_mcu(void); - -/* Common definition for the USB PD interrupt handlers. */ -void tcpc_alert_event(enum gpio_signal signal); -void bc12_interrupt(enum gpio_signal signal); -void ppc_interrupt(enum gpio_signal signal); - -int board_is_convertible(void); -void board_update_sensor_config_from_sku(void); - -#ifdef CONFIG_USB_TYPEC_PD_FAST_ROLE_SWAP -int board_tcpc_fast_role_swap_enable(int port, int enable); -#endif - -#endif /* !__ASSEMBLER__ */ - -#endif /* __CROS_EC_BASEBOARD_H */ diff --git a/baseboard/zork/build.mk b/baseboard/zork/build.mk deleted file mode 100644 index c8ae965325..0000000000 --- a/baseboard/zork/build.mk +++ /dev/null @@ -1,10 +0,0 @@ -# -*- makefile -*- -# Copyright 2019 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. -# -# Baseboard specific files build -# - -baseboard-y=baseboard.o -baseboard-$(CONFIG_USB_POWER_DELIVERY)+=usb_pd_policy.o diff --git a/baseboard/zork/usb_pd_policy.c b/baseboard/zork/usb_pd_policy.c deleted file mode 100644 index 9c61a020db..0000000000 --- a/baseboard/zork/usb_pd_policy.c +++ /dev/null @@ -1,484 +0,0 @@ -/* Copyright 2019 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. - */ - -/* Shared USB-C policy for Zork boards */ - -#include "charge_manager.h" -#include "chipset.h" -#include "common.h" -#include "compile_time_macros.h" -#include "console.h" -#include "ec_commands.h" -#include "gpio.h" -#include "system.h" -#include "usb_mux.h" -#include "usb_pd.h" -#include "usbc_ppc.h" -#include "util.h" - -#define CPRINTF(format, args...) cprintf(CC_USBPD, format, ## args) -#define CPRINTS(format, args...) cprints(CC_USBPD, format, ## args) - -#define PDO_FIXED_FLAGS (PDO_FIXED_DUAL_ROLE | PDO_FIXED_DATA_SWAP |\ - PDO_FIXED_COMM_CAP) - -const uint32_t pd_src_pdo[] = { - PDO_FIXED(5000, 1500, PDO_FIXED_FLAGS), -}; -const int pd_src_pdo_cnt = ARRAY_SIZE(pd_src_pdo); -const uint32_t pd_src_pdo_max[] = { - PDO_FIXED(5000, 3000, PDO_FIXED_FLAGS), -}; -const int pd_src_pdo_max_cnt = ARRAY_SIZE(pd_src_pdo_max); - -const uint32_t pd_snk_pdo[] = { - PDO_FIXED(5000, 500, PDO_FIXED_FLAGS), - PDO_BATT(4750, 21000, 15000), - PDO_VAR(4750, 21000, 3000), -}; -const int pd_snk_pdo_cnt = ARRAY_SIZE(pd_snk_pdo); - -int pd_board_checks(void) -{ - return EC_SUCCESS; -} - -int pd_check_data_swap(int port, int data_role) -{ - /* Allow data swap if we are a UFP, otherwise don't allow. */ - return (data_role == PD_ROLE_UFP); -} - -void pd_check_dr_role(int port, int dr_role, int flags) -{ - /* If UFP, try to switch to DFP */ - if ((flags & PD_FLAGS_PARTNER_DR_DATA) && - dr_role == PD_ROLE_UFP) - pd_request_data_swap(port); -} - -int pd_check_power_swap(int port) -{ - /* - * Allow power swap if we are acting as a dual role device. If we are - * not acting as dual role (ex. suspended), then only allow power swap - * if we are sourcing when we could be sinking. - */ - if (pd_get_dual_role(port) == PD_DRP_TOGGLE_ON) - return 1; - else if (pd_get_role(port) == PD_ROLE_SOURCE) - return 1; - else - return 0; -} - -void pd_check_pr_role(int port, int pr_role, int flags) -{ - /* - * If partner is dual-role power and dualrole toggling is on, consider - * if a power swap is necessary. - */ - if ((flags & PD_FLAGS_PARTNER_DR_POWER) && - pd_get_dual_role(port) == PD_DRP_TOGGLE_ON) { - /* - * If we are a sink and partner is not externally powered, then - * swap to become a source. If we are source and partner is - * externally powered, swap to become a sink. - */ - int partner_extpower = flags & PD_FLAGS_PARTNER_EXTPOWER; - - if ((!partner_extpower && pr_role == PD_ROLE_SINK) || - (partner_extpower && pr_role == PD_ROLE_SOURCE)) - pd_request_power_swap(port); - } -} - -int pd_check_vconn_swap(int port) -{ - /* in G3, do not allow vconn swap since 5V rail is off */ - return gpio_get_level(GPIO_S5_PGOOD); -} - -void pd_execute_data_swap(int port, int data_role) -{ - /* Do nothing */ -} - -int pd_is_valid_input_voltage(int mv) -{ - return 1; -} - -void pd_power_supply_reset(int port) -{ - int prev_en; - - prev_en = ppc_is_sourcing_vbus(port); - - /* Disable VBUS. */ - ppc_vbus_source_enable(port, 0); - - /* Enable discharge if we were previously sourcing 5V */ - if (prev_en) - pd_set_vbus_discharge(port, 1); - -#ifdef CONFIG_USB_PD_MAX_SINGLE_SOURCE_CURRENT - /* Give back the current quota we are no longer using */ - charge_manager_source_port(port, 0); -#endif /* defined(CONFIG_USB_PD_MAX_SINGLE_SOURCE_CURRENT) */ - - /* Notify host of power info change. */ - pd_send_host_event(PD_EVENT_POWER_CHANGE); -} - -int pd_set_power_supply_ready(int port) -{ - int rv; - - /* Disable charging. */ - rv = ppc_vbus_sink_enable(port, 0); - if (rv) - return rv; - - pd_set_vbus_discharge(port, 0); - - /* Provide Vbus. */ - rv = ppc_vbus_source_enable(port, 1); - if (rv) - return rv; - -#ifdef CONFIG_USB_PD_MAX_SINGLE_SOURCE_CURRENT - /* Ensure we advertise the proper available current quota */ - charge_manager_source_port(port, 1); -#endif /* defined(CONFIG_USB_PD_MAX_SINGLE_SOURCE_CURRENT) */ - - /* Notify host of power info change. */ - pd_send_host_event(PD_EVENT_POWER_CHANGE); - - return EC_SUCCESS; -} - -void pd_transition_voltage(int idx) -{ - /* No-operation: we are always 5V */ -} - -int pd_snk_is_vbus_provided(int port) -{ - return ppc_is_vbus_present(port); -} - -void typec_set_source_current_limit(int port, enum tcpc_rp_value rp) -{ - ppc_set_vbus_source_current_limit(port, rp); -} - -int board_vbus_source_enabled(int port) -{ - return ppc_is_sourcing_vbus(port); -} - -/* ----------------- Vendor Defined Messages ------------------ */ -const struct svdm_response svdm_rsp = { - .identity = NULL, - .svids = NULL, - .modes = NULL, -}; - -int pd_custom_vdm(int port, int cnt, uint32_t *payload, - uint32_t **rpayload) -{ - int cmd = PD_VDO_CMD(payload[0]); - uint16_t dev_id = 0; - int is_rw, is_latest; - - /* make sure we have some payload */ - if (cnt == 0) - return 0; - - switch (cmd) { - case VDO_CMD_VERSION: - /* guarantee last byte of payload is null character */ - *(payload + cnt - 1) = 0; - CPRINTF("version: %s\n", (char *)(payload+1)); - break; - case VDO_CMD_READ_INFO: - case VDO_CMD_SEND_INFO: - /* copy hash */ - if (cnt == 7) { - dev_id = VDO_INFO_HW_DEV_ID(payload[6]); - is_rw = VDO_INFO_IS_RW(payload[6]); - - is_latest = pd_dev_store_rw_hash(port, - dev_id, - payload + 1, - is_rw ? - SYSTEM_IMAGE_RW : - SYSTEM_IMAGE_RO); - /* - * Send update host event unless our RW hash is - * already known to be the latest update RW. - */ - if (!is_rw || !is_latest) - pd_send_host_event(PD_EVENT_UPDATE_DEVICE); - - CPRINTF("DevId:%d.%d SW:%d RW:%d\n", - HW_DEV_ID_MAJ(dev_id), - HW_DEV_ID_MIN(dev_id), - VDO_INFO_SW_DBG_VER(payload[6]), - is_rw); - } else if (cnt == 6) { - /* really old devices don't have last byte */ - pd_dev_store_rw_hash(port, dev_id, payload + 1, - SYSTEM_IMAGE_UNKNOWN); - } - break; - case VDO_CMD_CURRENT: - CPRINTF("Current: %dmA\n", payload[1]); - break; - case VDO_CMD_FLIP: - usb_mux_flip(port); - break; -#ifdef CONFIG_USB_PD_LOGGING - case VDO_CMD_GET_LOG: - pd_log_recv_vdm(port, cnt, payload); - break; -#endif /* CONFIG_USB_PD_LOGGING */ - } - - return 0; -} - -#ifdef CONFIG_USB_PD_ALT_MODE_DFP -static int dp_flags[CONFIG_USB_PD_PORT_MAX_COUNT]; -static uint32_t dp_status[CONFIG_USB_PD_PORT_MAX_COUNT]; - -static int svdm_enter_dp_mode(int port, uint32_t mode_caps) -{ - dp_flags[port] = 0; - dp_status[port] = 0; - - /* - * Don't enter the mode if the SoC is off. - * - * There's no need to enter the mode while the SoC is off; we'll - * actually enter the mode on the chipset resume hook. Entering DP Alt - * Mode twice will confuse some monitors and require an unplug/replug - * to get them to work again. The DP Alt Mode on USB-C spec says that - * if we don't need to maintain HPD connectivity info in a low power - * mode, then we shall exit DP Alt Mode. (This is why we don't enter - * when the SoC is off as opposed to suspend where adding a display - * could cause a wake up.) - */ - if (chipset_in_state(CHIPSET_STATE_ANY_OFF)) - return -1; - - /* Only enter mode if device is DFP_D capable */ - if (mode_caps & MODE_DP_SNK) - return 0; - - return -1; -} - -static int svdm_dp_status(int port, uint32_t *payload) -{ - int opos = pd_alt_mode(port, USB_SID_DISPLAYPORT); - - payload[0] = VDO(USB_SID_DISPLAYPORT, 1, - CMD_DP_STATUS | VDO_OPOS(opos)); - payload[1] = VDO_DP_STATUS(0, /* HPD IRQ ... not applicable */ - 0, /* HPD level ... not applicable */ - 0, /* exit DP? ... no */ - 0, /* usb mode? ... no */ - 0, /* multi-function ... no */ - (!!(dp_flags[port] & DP_FLAGS_DP_ON)), - 0, /* power low? ... no */ - (!!(dp_flags[port] & DP_FLAGS_DP_ON))); - return 2; -}; - -static enum typec_mux svdm_dp_mux_mode(int port) -{ - int mf_pref = PD_VDO_DPSTS_MF_PREF(dp_status[port]); - int pin_mode = pd_dfp_dp_get_pin_mode(port, dp_status[port]); - /* - * Multi-function operation is only allowed if that pin config is - * supported. - */ - if ((pin_mode & MODE_DP_PIN_MF_MASK) && mf_pref) - return TYPEC_MUX_DOCK; - else - return TYPEC_MUX_DP; -} - -static int svdm_dp_config(int port, uint32_t *payload) -{ - int opos = pd_alt_mode(port, USB_SID_DISPLAYPORT); - int mf_pref = PD_VDO_DPSTS_MF_PREF(dp_status[port]); - int pin_mode = pd_dfp_dp_get_pin_mode(port, dp_status[port]); - enum typec_mux mux_mode = svdm_dp_mux_mode(port); - - if (!pin_mode) - return 0; - - CPRINTS("pin_mode: %x, mf: %d, mux: %d", pin_mode, mf_pref, mux_mode); - - /* - * Place the USB Type-C pins that are to be re-configured to DisplayPort - * Configuration into the Safe state. For TYPEC_MUX_DOCK, the superspeed - * signals can remain connected. For TYPEC_MUX_DP, disconnect the - * superspeed signals here, before the pins are re-configured to - * DisplayPort (in svdm_dp_post_config, when we receive the config ack). - */ - if (mux_mode == TYPEC_MUX_DP) - usb_mux_set(port, TYPEC_MUX_NONE, USB_SWITCH_CONNECT, - pd_get_polarity(port)); - - payload[0] = VDO(USB_SID_DISPLAYPORT, 1, - CMD_DP_CONFIG | VDO_OPOS(opos)); - payload[1] = VDO_DP_CFG(pin_mode, /* pin mode */ - 1, /* DPv1.3 signaling */ - 2); /* UFP connected */ - return 2; -}; - -/* - * timestamp of the next possible toggle to ensure the 2-ms spacing - * between IRQ_HPD. - */ -static uint64_t hpd_deadline[CONFIG_USB_PD_PORT_MAX_COUNT]; - -#define PORT_TO_HPD(port) ((port) ? GPIO_DP2_HPD : GPIO_USB_C0_HPD) -static void svdm_dp_post_config(int port) -{ - const struct usb_mux * const mux = &usb_muxes[port]; - - /* Connect the SBU and USB lines to the connector. */ - ppc_set_sbu(port, 1); - usb_mux_set(port, svdm_dp_mux_mode(port), USB_SWITCH_CONNECT, - pd_get_polarity(port)); - - dp_flags[port] |= DP_FLAGS_DP_ON; - if (!(dp_flags[port] & DP_FLAGS_HPD_HI_PENDING)) - return; - - gpio_set_level(PORT_TO_HPD(port), 1); - - /* set the minimum time delay (2ms) for the next HPD IRQ */ - hpd_deadline[port] = get_time().val + HPD_USTREAM_DEBOUNCE_LVL; - mux->hpd_update(port, 1, 0); -} - -static int svdm_dp_attention(int port, uint32_t *payload) -{ - int cur_lvl; - int lvl = PD_VDO_DPSTS_HPD_LVL(payload[1]); - int irq = PD_VDO_DPSTS_HPD_IRQ(payload[1]); - enum gpio_signal hpd = PORT_TO_HPD(port); - const struct usb_mux * const mux = &usb_muxes[port]; - - cur_lvl = gpio_get_level(hpd); - dp_status[port] = payload[1]; - - /* Its initial DP status message prior to config */ - if (!(dp_flags[port] & DP_FLAGS_DP_ON)) { - if (lvl) - dp_flags[port] |= DP_FLAGS_HPD_HI_PENDING; - return 1; /* ack */ - } - - if (irq && cur_lvl) { - uint64_t now = get_time().val; - /* wait for the minimum spacing between IRQ_HPD if needed */ - if (now < hpd_deadline[port]) - usleep(hpd_deadline[port] - now); - - /* generate IRQ_HPD pulse */ - gpio_set_level(hpd, 0); - usleep(HPD_DSTREAM_DEBOUNCE_IRQ); - gpio_set_level(hpd, 1); - - /* set the minimum time delay (2ms) for the next HPD IRQ */ - hpd_deadline[port] = get_time().val + HPD_USTREAM_DEBOUNCE_LVL; - } else if (irq && !lvl) { - /* - * IRQ can only be generated when the level is high, because - * the IRQ is signaled by a short low pulse from the high level. - */ - CPRINTF("ERR:HPD:IRQ&LOW\n"); - return 0; /* nak */ - } else { - gpio_set_level(hpd, lvl); - /* set the minimum time delay (2ms) for the next HPD IRQ */ - hpd_deadline[port] = get_time().val + HPD_USTREAM_DEBOUNCE_LVL; - } - mux->hpd_update(port, lvl, irq); - return 1; /* ack */ -} - -static void svdm_exit_dp_mode(int port) -{ - const struct usb_mux * const mux = &usb_muxes[port]; - - dp_flags[port] = 0; - dp_status[port] = 0; - - usb_mux_set(port, TYPEC_MUX_NONE, USB_SWITCH_CONNECT, - pd_get_polarity(port)); - gpio_set_level(PORT_TO_HPD(port), 0); - mux->hpd_update(port, 0, 0); -} - -static int svdm_enter_gfu_mode(int port, uint32_t mode_caps) -{ - /* Always enter GFU mode */ - return 0; -} - -static void svdm_exit_gfu_mode(int port) -{ -} - -static int svdm_gfu_status(int port, uint32_t *payload) -{ - /* - * This is called after enter mode is successful, send unstructured - * VDM to read info. - */ - pd_send_vdm(port, USB_VID_GOOGLE, VDO_CMD_READ_INFO, NULL, 0); - return 0; -} - -static int svdm_gfu_config(int port, uint32_t *payload) -{ - return 0; -} - -static int svdm_gfu_attention(int port, uint32_t *payload) -{ - return 0; -} - -const struct svdm_amode_fx supported_modes[] = { - { - .svid = USB_SID_DISPLAYPORT, - .enter = &svdm_enter_dp_mode, - .status = &svdm_dp_status, - .config = &svdm_dp_config, - .post_config = &svdm_dp_post_config, - .attention = &svdm_dp_attention, - .exit = &svdm_exit_dp_mode, - }, - { - .svid = USB_VID_GOOGLE, - .enter = &svdm_enter_gfu_mode, - .status = &svdm_gfu_status, - .config = &svdm_gfu_config, - .attention = &svdm_gfu_attention, - .exit = &svdm_exit_gfu_mode, - } -}; -const int supported_modes_cnt = ARRAY_SIZE(supported_modes); -#endif /* CONFIG_USB_PD_ALT_MODE_DFP */ |