summaryrefslogtreecommitdiff
path: root/board/kukui
diff options
context:
space:
mode:
authorTing Shen <phoenixshen@google.com>2019-07-10 19:23:09 +0800
committerCommit Bot <commit-bot@chromium.org>2019-07-30 07:45:24 +0000
commitb99b1b10c3f2070e3fbd8d5cb2d0927f04f642ea (patch)
treee56e7cbb2e431d833435b710acb7470db7e710f8 /board/kukui
parentf911ddd9d425c2159d21758ba9eb05051180969a (diff)
downloadchrome-ec-b99b1b10c3f2070e3fbd8d5cb2d0927f04f642ea.tar.gz
kukui: add baseboard/kukui
Create a baseboard to reduce the effort of forking and maintaining kukui derivatives. This CL is intended to just moving things around, with minimal changes to make compiler happy, complex logic changes will implement in subsequent CLs. BUG=b:137172860 TEST=build and deploy on a Krane BRANCH=master Change-Id: Ifd3ad5c3b03dce101cd15cbcec304f5e3a1081ac Signed-off-by: Ting Shen <phoenixshen@google.com> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1695562 Reviewed-by: Ting Shen <phoenixshen@chromium.org> Commit-Queue: Ting Shen <phoenixshen@chromium.org> Tested-by: Ting Shen <phoenixshen@chromium.org>
Diffstat (limited to 'board/kukui')
-rw-r--r--board/kukui/battery.c275
-rw-r--r--board/kukui/board.c100
-rw-r--r--board/kukui/board.h192
-rw-r--r--board/kukui/build.mk6
-rw-r--r--board/kukui/emmc.c391
-rw-r--r--board/kukui/usb_pd_policy.c447
6 files changed, 19 insertions, 1392 deletions
diff --git a/board/kukui/battery.c b/board/kukui/battery.c
deleted file mode 100644
index 62f73bfa34..0000000000
--- a/board/kukui/battery.c
+++ /dev/null
@@ -1,275 +0,0 @@
-/* Copyright 2018 The Chromium OS Authors. All rights reserved.
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- *
- * Battery pack vendor provided charging profile
- */
-
-#include "battery.h"
-#include "battery_smart.h"
-#include "charge_state.h"
-#include "console.h"
-#include "driver/charger/rt946x.h"
-#include "driver/tcpm/mt6370.h"
-#include "ec_commands.h"
-#include "extpower.h"
-#include "gpio.h"
-#include "hooks.h"
-#include "power.h"
-#include "usb_pd.h"
-#include "util.h"
-
-#if defined(CONFIG_BATTERY_MAX17055)
-#include "driver/battery/max17055.h"
-#elif defined(CONFIG_BATTERY_MM8013)
-#include "driver/battery/mm8013.h"
-#endif
-
-#define TEMP_OUT_OF_RANGE TEMP_ZONE_COUNT
-
-#if defined(BOARD_KRANE)
-#define BATT_ID 1
-#else
-#define BATT_ID 0
-#endif
-
-#define BAT_LEVEL_PD_LIMIT 85
-#define IBAT_PD_LIMIT 1000
-
-#define BATTERY_SIMPLO_CHARGE_MIN_TEMP 0
-#define BATTERY_SIMPLO_CHARGE_MAX_TEMP 60
-
-#define CPRINTS(format, args...) cprints(CC_CHARGER, format, ## args)
-
-enum battery_type {
- BATTERY_SIMPLO = 0,
- BATTERY_SCUD,
- BATTERY_COUNT
-};
-
-static const struct battery_info info[] = {
- [BATTERY_SIMPLO] = {
- .voltage_max = 4400,
- .voltage_normal = 3860,
- .voltage_min = 3000,
- .precharge_current = 256,
- .start_charging_min_c = 0,
- .start_charging_max_c = 45,
- .charging_min_c = 0,
- .charging_max_c = 60,
- .discharging_min_c = -20,
- .discharging_max_c = 60,
- },
- [BATTERY_SCUD] = {
- .voltage_max = 4400,
- .voltage_normal = 3850,
- .voltage_min = 3400,
- .precharge_current = 256,
- .start_charging_min_c = 0,
- .start_charging_max_c = 45,
- .charging_min_c = 0,
- .charging_max_c = 50,
- .discharging_min_c = -20,
- .discharging_max_c = 60,
- },
-};
-
-#ifdef CONFIG_BATTERY_MAX17055
-
-#if BATT_ID == 1
-#error "Battery profile for Mitsumi battery not available"
-#endif
-
-static const struct max17055_batt_profile batt_profile[] = {
- [BATTERY_SIMPLO] = {
- .is_ez_config = 1,
- .design_cap = MAX17055_DESIGNCAP_REG(6910),
- .ichg_term = MAX17055_ICHGTERM_REG(235),
- .v_empty_detect = MAX17055_VEMPTY_REG(3000, 3600),
- },
-};
-
-static const struct max17055_alert_profile alert_profile[] = {
- [BATTERY_SIMPLO] = {
- .v_alert_mxmn = VALRT_DISABLE,
- .t_alert_mxmn = MAX17055_TALRTTH_REG(
- BATTERY_SIMPLO_CHARGE_MAX_TEMP,
- BATTERY_SIMPLO_CHARGE_MIN_TEMP),
- .s_alert_mxmn = SALRT_DISABLE,
- .i_alert_mxmn = IALRT_DISABLE,
- },
-};
-
-const struct max17055_batt_profile *max17055_get_batt_profile(void)
-{
- return &batt_profile[BATT_ID];
-}
-
-const struct max17055_alert_profile *max17055_get_alert_profile(void)
-{
- return &alert_profile[BATT_ID];
-}
-#endif /* CONFIG_BATTERY_MAX17055 */
-
-const struct battery_info *battery_get_info(void)
-{
- return &info[BATT_ID];
-}
-
-int board_cut_off_battery(void)
-{
- /* The cut-off procedure is recommended by Richtek. b/116682788 */
- rt946x_por_reset();
- mt6370_vconn_discharge(0);
- rt946x_cutoff_battery();
-
- return EC_SUCCESS;
-}
-
-enum battery_disconnect_state battery_get_disconnect_state(void)
-{
- if (battery_is_present() == BP_YES)
- return BATTERY_NOT_DISCONNECTED;
- return BATTERY_DISCONNECTED;
-}
-
-int charger_profile_override(struct charge_state_data *curr)
-{
- static int previous_chg_limit_mv;
- int chg_limit_mv;
-#ifdef CONFIG_BATTERY_MAX17055
- /* battery temp in 0.1 deg C */
- int bat_temp_c = curr->batt.temperature - 2731;
-
- /*
- * Keep track of battery temperature range:
- *
- * ZONE_0 ZONE_1 ZONE_2
- * -----+--------+--------+------------+----- Temperature (C)
- * t0 t1 t2 t3
- */
- enum {
- TEMP_ZONE_0, /* t0 < bat_temp_c <= t1 */
- TEMP_ZONE_1, /* t1 < bat_temp_c <= t2 */
- TEMP_ZONE_2, /* t2 < bat_temp_c <= t3 */
- TEMP_ZONE_COUNT
- } temp_zone;
-
- static struct {
- int temp_min; /* 0.1 deg C */
- int temp_max; /* 0.1 deg C */
- int desired_current; /* mA */
- int desired_voltage; /* mV */
- } temp_zones[BATTERY_COUNT][TEMP_ZONE_COUNT] = {
- [BATTERY_SIMPLO] = {
- /* TEMP_ZONE_0 */
- {BATTERY_SIMPLO_CHARGE_MIN_TEMP * 10, 150, 1772, 4376},
- /* TEMP_ZONE_1 */
- {150, 450, 4020, 4376},
- /* TEMP_ZONE_2 */
- {450, BATTERY_SIMPLO_CHARGE_MAX_TEMP * 10, 3350, 4300},
- },
- [BATTERY_SCUD] = {
- /* unused */
- },
- };
- BUILD_ASSERT(ARRAY_SIZE(temp_zones[0]) == TEMP_ZONE_COUNT);
- BUILD_ASSERT(ARRAY_SIZE(temp_zones) == BATTERY_COUNT);
-
- if ((curr->batt.flags & BATT_FLAG_BAD_TEMPERATURE) ||
- (bat_temp_c < temp_zones[BATT_ID][0].temp_min) ||
- (bat_temp_c >= temp_zones[BATT_ID][TEMP_ZONE_COUNT - 1].temp_max))
- temp_zone = TEMP_OUT_OF_RANGE;
- else {
- for (temp_zone = 0; temp_zone < TEMP_ZONE_COUNT; temp_zone++) {
- if (bat_temp_c <
- temp_zones[BATT_ID][temp_zone].temp_max)
- break;
- }
- }
-
- if (curr->state != ST_CHARGE)
- return 0;
-
- switch (temp_zone) {
- case TEMP_ZONE_0:
- case TEMP_ZONE_1:
- case TEMP_ZONE_2:
- curr->requested_current =
- temp_zones[BATT_ID][temp_zone].desired_current;
- curr->requested_voltage =
- temp_zones[BATT_ID][temp_zone].desired_voltage;
- break;
- case TEMP_OUT_OF_RANGE:
- curr->requested_current = curr->requested_voltage = 0;
- curr->batt.flags &= ~BATT_FLAG_WANT_CHARGE;
- curr->state = ST_IDLE;
- break;
- }
-#endif /* CONFIG_BATTERY_MAX17055 */
- /* TODO(b:131284131): Add battery configs for krane. */
-
- /* Limit input (=VBUS) to 5V when soc > 85% and charge current < 1A. */
- if (!(curr->batt.flags & BATT_FLAG_BAD_CURRENT) &&
- charge_get_percent() > BAT_LEVEL_PD_LIMIT &&
- curr->batt.current < 1000) {
- chg_limit_mv = 5500;
- } else if (IS_ENABLED(BOARD_KRANE) &&
- board_get_version() == 3 &&
- power_get_state() == POWER_S0) {
- /*
- * TODO(b:134227872): limit power to 5V/2A in S0 to prevent
- * overheat
- */
- chg_limit_mv = 5500;
- curr->requested_current = 2000;
- } else {
- chg_limit_mv = PD_MAX_VOLTAGE_MV;
- }
-
- if (chg_limit_mv != previous_chg_limit_mv)
- CPRINTS("VBUS limited to %dmV", chg_limit_mv);
- previous_chg_limit_mv = chg_limit_mv;
-
- /* Pull down VBUS */
- if (pd_get_max_voltage() != chg_limit_mv)
- pd_set_external_voltage_limit(0, chg_limit_mv);
-
- /*
- * When the charger says it's done charging, even if fuel gauge says
- * SOC < BATTERY_LEVEL_NEAR_FULL, we'll overwrite SOC with
- * BATTERY_LEVEL_NEAR_FULL. So we can ensure both Chrome OS UI
- * and battery LED indicate full charge.
- */
- if (rt946x_is_charge_done()) {
- curr->batt.state_of_charge = MAX(BATTERY_LEVEL_NEAR_FULL,
- curr->batt.state_of_charge);
- }
-
- return 0;
-}
-
-static void board_charge_termination(void)
-{
- static uint8_t te;
- /* Enable charge termination when we are sure battery is present. */
- if (!te && battery_is_present() == BP_YES) {
- if (!rt946x_enable_charge_termination(1))
- te = 1;
- }
-}
-DECLARE_HOOK(HOOK_BATTERY_SOC_CHANGE,
- board_charge_termination,
- HOOK_PRIO_DEFAULT);
-
-enum ec_status charger_profile_override_get_param(uint32_t param,
- uint32_t *value)
-{
- return EC_RES_INVALID_PARAM;
-}
-
-enum ec_status charger_profile_override_set_param(uint32_t param,
- uint32_t value)
-{
- return EC_RES_INVALID_PARAM;
-}
diff --git a/board/kukui/board.c b/board/kukui/board.c
index e31e6092be..49d5e53cd0 100644
--- a/board/kukui/board.c
+++ b/board/kukui/board.c
@@ -5,7 +5,6 @@
#include "adc.h"
#include "adc_chip.h"
-#include "backlight.h"
#include "button.h"
#include "charge_manager.h"
#include "charge_ramp.h"
@@ -16,12 +15,10 @@
#include "console.h"
#include "driver/accelgyro_bmi160.h"
#include "driver/als_tcs3400.h"
-#include "driver/battery/max17055.h"
#include "driver/bc12/pi3usb9201.h"
#include "driver/charger/rt946x.h"
#include "driver/sync.h"
#include "driver/tcpm/mt6370.h"
-#include "ec_commands.h"
#include "extpower.h"
#include "gpio.h"
#include "hooks.h"
@@ -114,10 +111,6 @@ struct usb_mux usb_muxes[CONFIG_USB_PD_PORT_COUNT] = {
},
};
-void board_reset_pd_mcu(void)
-{
-}
-
uint16_t tcpc_get_alert_status(void)
{
uint16_t status = 0;
@@ -319,94 +312,6 @@ static void board_rev_init(void)
}
DECLARE_HOOK(HOOK_INIT, board_rev_init, HOOK_PRIO_INIT_ADC + 1);
-void board_config_pre_init(void)
-{
- STM32_RCC_AHBENR |= STM32_RCC_HB_DMA1;
- /*
- * Remap USART1 and SPI2 DMA:
- *
- * Ch4: USART1_TX / Ch5: USART1_RX (1000)
- * Ch6: SPI2_RX / Ch7: SPI2_TX (0011)
- */
- STM32_DMA_CSELR(STM32_DMAC_CH4) = (8 << 12) | (8 << 16) |
- (3 << 20) | (3 << 24);
-}
-
-enum kukui_board_version {
- BOARD_VERSION_UNKNOWN = -1,
- BOARD_VERSION_REV0 = 0,
- BOARD_VERSION_REV1 = 1,
- BOARD_VERSION_REV2 = 2,
- BOARD_VERSION_REV3 = 3,
- BOARD_VERSION_REV4 = 4,
- BOARD_VERSION_REV5 = 5,
- BOARD_VERSION_REV6 = 6,
- BOARD_VERSION_REV7 = 7,
- BOARD_VERSION_REV8 = 8,
- BOARD_VERSION_REV9 = 9,
- BOARD_VERSION_REV10 = 10,
- BOARD_VERSION_REV11 = 11,
- BOARD_VERSION_REV12 = 12,
- BOARD_VERSION_REV13 = 13,
- BOARD_VERSION_REV14 = 14,
- BOARD_VERSION_REV15 = 15,
- BOARD_VERSION_COUNT,
-};
-
-struct {
- enum kukui_board_version version;
- int expect_mv;
-} const kukui_boards[] = {
- { BOARD_VERSION_REV0, 109 }, /* 51.1K , 2.2K(gru 3.3K) ohm */
- { BOARD_VERSION_REV1, 211 }, /* 51.1k , 6.8K ohm */
- { BOARD_VERSION_REV2, 319 }, /* 51.1K , 11K ohm */
- { BOARD_VERSION_REV3, 427 }, /* 56K , 17.4K ohm */
- { BOARD_VERSION_REV4, 542 }, /* 51.1K , 22K ohm */
- { BOARD_VERSION_REV5, 666 }, /* 51.1K , 30K ohm */
- { BOARD_VERSION_REV6, 781 }, /* 51.1K , 39.2K ohm */
- { BOARD_VERSION_REV7, 900 }, /* 56K , 56K ohm */
- { BOARD_VERSION_REV8, 1023 }, /* 47K , 61.9K ohm */
- { BOARD_VERSION_REV9, 1137 }, /* 47K , 80.6K ohm */
- { BOARD_VERSION_REV10, 1240 }, /* 56K , 124K ohm */
- { BOARD_VERSION_REV11, 1343 }, /* 51.1K , 150K ohm */
- { BOARD_VERSION_REV12, 1457 }, /* 47K , 200K ohm */
- { BOARD_VERSION_REV13, 1576 }, /* 47K , 330K ohm */
- { BOARD_VERSION_REV14, 1684 }, /* 47K , 680K ohm */
- { BOARD_VERSION_REV15, 1800 }, /* 56K , NC */
-};
-BUILD_ASSERT(ARRAY_SIZE(kukui_boards) == BOARD_VERSION_COUNT);
-
-#define THRESHOLD_MV 56 /* Simply assume 1800/16/2 */
-
-int board_get_version(void)
-{
- static int version = BOARD_VERSION_UNKNOWN;
- int mv;
- int i;
-
- if (version != BOARD_VERSION_UNKNOWN)
- return version;
-
- gpio_set_level(GPIO_EC_BOARD_ID_EN_L, 0);
- /* Wait to allow cap charge */
- msleep(10);
- mv = adc_read_channel(ADC_BOARD_ID);
-
- if (mv == ADC_READ_ERROR)
- mv = adc_read_channel(ADC_BOARD_ID);
-
- gpio_set_level(GPIO_EC_BOARD_ID_EN_L, 1);
-
- for (i = 0; i < BOARD_VERSION_COUNT; ++i) {
- if (mv < kukui_boards[i].expect_mv + THRESHOLD_MV) {
- version = kukui_boards[i].version;
- break;
- }
- }
-
- return version;
-}
-
/* Motion sensors */
/* Mutexes */
#ifdef SECTION_IS_RW
@@ -577,11 +482,6 @@ const struct motion_sensor_t *motion_als_sensors[] = {
};
#endif /* SECTION_IS_RW */
-int board_allow_i2c_passthru(int port)
-{
- return (port == I2C_PORT_VIRTUAL_BATTERY);
-}
-
void usb_charger_set_switches(int port, enum usb_switch setting)
{
}
diff --git a/board/kukui/board.h b/board/kukui/board.h
index fe9b415b36..aa05ebc712 100644
--- a/board/kukui/board.h
+++ b/board/kukui/board.h
@@ -8,84 +8,29 @@
#ifndef __CROS_EC_BOARD_H
#define __CROS_EC_BOARD_H
-/* Optional modules */
-#define CONFIG_ADC
-#undef CONFIG_ADC_WATCHDOG
-#define CONFIG_CHIPSET_MT8183
-#define CONFIG_CMD_ACCELS
-#define CONFIG_EMULATED_SYSRQ
-#undef CONFIG_HIBERNATE
-#define CONFIG_I2C
-#define CONFIG_I2C_MASTER
-#define CONFIG_I2C_VIRTUAL_BATTERY
-#define CONFIG_I2C_PASSTHRU_RESTRICTED
-#define CONFIG_LED_COMMON
-#define CONFIG_LOW_POWER_IDLE
-#define CONFIG_POWER_COMMON
-#define CONFIG_SPI
-#define CONFIG_SPI_MASTER
-#define CONFIG_STM_HWTIMER32
-#define CONFIG_SWITCH
-#define CONFIG_WATCHDOG_HELP
+#include "baseboard.h"
-#define CONFIG_SYSTEM_UNLOCKED /* Allow dangerous commands for testing */
-
-#undef CONFIG_UART_CONSOLE
-#define CONFIG_UART_CONSOLE 1
-#define CONFIG_UART_RX_DMA
-
-/* Bootblock */
-#ifdef SECTION_IS_RO
-#define CONFIG_BOOTBLOCK
-
-#define EMMC_SPI_PORT 2
-#endif
-
-/* Optional features */
-#define CONFIG_BOARD_PRE_INIT
-#define CONFIG_BOARD_VERSION_CUSTOM
-#define CONFIG_BUTTON_TRIGGERED_RECOVERY
-#define CONFIG_CHARGER_ILIM_PIN_DISABLED
-#define CONFIG_FORCE_CONSOLE_RESUME
-#define CONFIG_HOST_COMMAND_STATUS
-#define CONFIG_CMD_AP_RESET_LOG
+#define CONFIG_CHARGER_MT6370
+#define CONFIG_CHARGER_OTG
+#define CONFIG_VOLUME_BUTTONS
-/* Required for FAFT */
-#define CONFIG_CMD_BUTTON
-#define CONFIG_CMD_CHARGEN
+/* Battery */
+#ifdef BOARD_KRANE
+#define CONFIG_BATTERY_MM8013
+#define BATTERY_DESIRED_CHARGING_CURRENT 3500 /* mA */
+#else
+#define CONFIG_BATTERY_MAX17055
+#define CONFIG_BATTERY_MAX17055_ALERT
+#define BATTERY_MAX17055_RSENSE 5 /* m-ohm */
+#define BATTERY_DESIRED_CHARGING_CURRENT 2000 /* mA */
+#endif /* BOARD_KRANE */
-/* By default, set hcdebug to off */
-#undef CONFIG_HOSTCMD_DEBUG_MODE
-#define CONFIG_HOSTCMD_DEBUG_MODE HCDEBUG_OFF
-#define CONFIG_LTO
-#define CONFIG_POWER_BUTTON
-#define CONFIG_POWER_BUTTON_IGNORE_LID
-#define CONFIG_POWER_TRACK_HOST_SLEEP_STATE
-#define CONFIG_SOFTWARE_PANIC
-#define CONFIG_VBOOT_HASH
-#define CONFIG_VOLUME_BUTTONS
+#ifdef BOARD_KRANE
+#define CONFIG_CHARGER_MT6370_BACKLIGHT
#undef CONFIG_DEDICATED_CHARGE_PORT_COUNT
#define CONFIG_DEDICATED_CHARGE_PORT_COUNT 1
#define DEDICATED_CHARGE_PORT 1
-
-#define CONFIG_CHARGE_RAMP_SW
-#define CONFIG_CHARGER
-#define CONFIG_CHARGER_MT6370
-#define CONFIG_CHARGER_INPUT_CURRENT 512
-#define CONFIG_CHARGER_V2
-#define CONFIG_CHARGER_MIN_BAT_PCT_FOR_POWER_ON 2
-#define CONFIG_CHARGER_LIMIT_POWER_THRESH_BAT_PCT 2
-#define CONFIG_CHARGER_LIMIT_POWER_THRESH_CHG_MW 15000
-#define CONFIG_CHARGER_PROFILE_OVERRIDE
-#define CONFIG_CHARGER_DISCHARGE_ON_AC
-#define CONFIG_CHARGER_DISCHARGE_ON_AC_CUSTOM
-#define CONFIG_CHARGER_OTG
-#define CONFIG_USB_CHARGER
-#define CONFIG_USB_MUX_VIRTUAL
-
-/* Increase tx buffer size, as we'd like to stream EC log to AP. */
-#undef CONFIG_UART_TX_BUF_SIZE
-#define CONFIG_UART_TX_BUF_SIZE 4096
+#endif /* BOARD_KRANE */
/* Motion Sensors */
#ifdef SECTION_IS_RW
@@ -114,103 +59,6 @@
TASK_EVENT_MOTION_SENSOR_INTERRUPT(VSYNC)
#endif /* SECTION_IS_RW */
-/* To be able to indicate the device is in tablet mode. */
-#define CONFIG_TABLET_MODE
-#define CONFIG_TABLET_MODE_SWITCH
-#define GPIO_LID_OPEN GPIO_HALL_INT_L
-
-/* FIFO size is in power of 2. */
-#define CONFIG_ACCEL_FIFO 256
-#define CONFIG_ACCEL_FIFO_THRES (CONFIG_ACCEL_FIFO / 3)
-
-/* USB PD config */
-#define CONFIG_CHARGE_MANAGER
-#define CONFIG_USB_POWER_DELIVERY
-#define CONFIG_USB_PD_ALT_MODE
-#define CONFIG_USB_PD_ALT_MODE_DFP
-#define CONFIG_USB_PD_DISCHARGE_TCPC
-#define CONFIG_USB_PD_DUAL_ROLE
-#define CONFIG_USB_PD_DUAL_ROLE_AUTO_TOGGLE
-#define CONFIG_USB_PD_LOGGING
-#define CONFIG_USB_PD_PORT_COUNT 1
-#define CONFIG_USB_PD_TCPC_LOW_POWER
-#define CONFIG_USB_PD_TCPM_MT6370
-#define CONFIG_USB_PD_TCPM_TCPCI
-#define CONFIG_USB_PD_VBUS_DETECT_TCPC
-#define CONFIG_USB_PD_5V_EN_CUSTOM
-#define CONFIG_USBC_SS_MUX
-#define CONFIG_USBC_VCONN
-#define CONFIG_USBC_VCONN_SWAP
-#define CONFIG_USB_PD_COMM_LOCKED
-
-#define CONFIG_BATTERY_CUT_OFF
-#define CONFIG_BATTERY_PRESENT_CUSTOM
-#define CONFIG_BATTERY_REVIVE_DISCONNECT
-#ifdef BOARD_KRANE
-#define CONFIG_BATTERY_MM8013
-#define CONFIG_CHARGER_MT6370_BACKLIGHT
-#else
-#define CONFIG_BATTERY_MAX17055
-#define CONFIG_BATTERY_MAX17055_ALERT
-#endif
-
-/* Battery parameters for max17055 ModelGauge m5 algorithm. */
-#define BATTERY_MAX17055_RSENSE 5 /* m-ohm */
-#ifdef BOARD_KRANE
-#define BATTERY_DESIRED_CHARGING_CURRENT 3500 /* mA */
-#else
-#define BATTERY_DESIRED_CHARGING_CURRENT 2000 /* mA */
-#endif
-
-#define PD_OPERATING_POWER_MW 15000
-#define PD_MAX_POWER_MW ((PD_MAX_VOLTAGE_MV * PD_MAX_CURRENT_MA) / 1000)
-#define PD_MAX_CURRENT_MA 3000
-
-/*
- * The Maximum input voltage is 13.5V, need another 5% tolerance.
- * 12.85V * 1.05 = 13.5V
- */
-#define PD_MAX_VOLTAGE_MV 12850
-
-#define PD_POWER_SUPPLY_TURN_ON_DELAY 30000 /* us */
-#define PD_POWER_SUPPLY_TURN_OFF_DELAY 50000 /* us */
-#define PD_VCONN_SWAP_DELAY 5000 /* us */
-
-/* Timer selection */
-#define TIM_CLOCK32 2
-#define TIM_WATCHDOG 7
-
-/* 48 MHz SYSCLK clock frequency */
-#define CPU_CLOCK 48000000
-
-/* Optional for testing */
-#undef CONFIG_PECI
-#undef CONFIG_PSTORE
-
-/* Modules we want to exclude */
-#undef CONFIG_CMD_BATTFAKE
-#undef CONFIG_CMD_FLASH
-#undef CONFIG_CMD_HASH
-#undef CONFIG_CMD_MD
-#undef CONFIG_CMD_POWERINDEBUG
-#undef CONFIG_CMD_TIMERINFO
-
-#ifdef SECTION_IS_RO
-#undef CONFIG_CMD_APTHROTTLE
-#undef CONFIG_CMD_MMAPINFO
-#undef CONFIG_CMD_PWR_AVG
-#undef CONFIG_CMD_REGULATOR
-#undef CONFIG_CMD_RW
-#undef CONFIG_CMD_SHMEM
-#undef CONFIG_CMD_SLEEPMASK
-#undef CONFIG_CMD_SLEEPMASK_SET
-#undef CONFIG_CMD_SYSLOCK
-#undef CONFIG_HOSTCMD_FLASHPD
-#undef CONFIG_HOSTCMD_RWHASHPD
-#endif
-
-#define CONFIG_TASK_PROFILING
-
/* I2C ports */
#define I2C_PORT_CHARGER 0
#define I2C_PORT_TCPC0 0
@@ -223,12 +71,6 @@
/* Route sbs host requests to virtual battery driver */
#define VIRTUAL_BATTERY_ADDR_FLAGS 0x0B
-/* Enable Accel over SPI */
-#define CONFIG_SPI_ACCEL_PORT 0 /* The first SPI master port (SPI2) */
-
-#define CONFIG_KEYBOARD_PROTOCOL_MKBP
-#define CONFIG_MKBP_EVENT
-#define CONFIG_MKBP_USE_GPIO
/* Define the host events which are allowed to wakeup AP in S3. */
#define CONFIG_MKBP_HOST_EVENT_WAKEUP_MASK \
(EC_HOST_EVENT_MASK(EC_HOST_EVENT_LID_OPEN) |\
diff --git a/board/kukui/build.mk b/board/kukui/build.mk
index 5c408de94a..337649bcb9 100644
--- a/board/kukui/build.mk
+++ b/board/kukui/build.mk
@@ -10,9 +10,7 @@
CHIP:=stm32
CHIP_FAMILY:=stm32f0
CHIP_VARIANT:=stm32f09x
+BASEBOARD:=kukui
-board-y=battery.o board.o usb_pd_policy.o led.o
-board-$(CONFIG_BOOTBLOCK)+=emmc.o
+board-y=board.o led.o
board-$(BOARD_KRANE)+=base_detect_krane.o
-
-$(out)/RO/board/$(BOARD)/emmc.o: $(out)/bootblock_data.h
diff --git a/board/kukui/emmc.c b/board/kukui/emmc.c
deleted file mode 100644
index 4735f4aea8..0000000000
--- a/board/kukui/emmc.c
+++ /dev/null
@@ -1,391 +0,0 @@
-/* Copyright 2018 The Chromium OS Authors. All rights reserved.
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- *
- * Transfer bootblock over SPI by emulating eMMC "Alternative Boot operation"
- * (section 6.3.4 of eMMC 5.0 specification, JESD84-B50).
- *
- * eMMC boot operation looks a lot like SPI: CMD is unidirectional MOSI, DAT is
- * unidirectional MISO. CLK is driven by the master. However, there is no
- * chip-select, and the clock is active for a long time before any command is
- * sent on the CMD line. From SPI perspective, this looks like a lot of '1'
- * are being sent from the master.
- *
- * To catch the commands, we setup DMA to write the data into a circular buffer
- * (in_msg), and monitor for a falling edge on CMD (emmc_cmd_interrupt). Once
- * an interrupt is received, we scan the circular buffer, in reverse, to
- * be as fast as possible and minimize chances of missing the command.
- *
- * We then figure out the bit-wise command alignment, decode it, and, upon
- * receiving BOOT_INITIATION command, setup DMA to respond with the data on the
- * DAT line. The data in bootblock_data.h is preprocessed to include necessary
- * eMMC headers: acknowledge boot mode, start of block, CRC, end of block, etc.
- * The host can only slow down transfer by stopping the clock, which is
- * compatible with SPI.
- *
- * In some cases (e.g. if the BootROM expects data over 8 lanes instead of 1),
- * the BootROM will quickly interrupt the transfer with an IDLE command. In this
- * case we interrupt the transfer, and the BootROM will try again.
- */
-
-#include "chipset.h"
-#include "clock.h"
-#include "console.h"
-#include "dma.h"
-#include "endian.h"
-#include "gpio.h"
-#include "hooks.h"
-#include "hwtimer.h"
-#include "system.h"
-#include "task.h"
-#include "timer.h"
-#include "util.h"
-
-#include "bootblock_data.h"
-
-#define CPRINTS(format, args...) cprints(CC_SPI, format, ## args)
-#define CPRINTF(format, args...) cprintf(CC_SPI, format, ## args)
-
-#if EMMC_SPI_PORT == 1
-#define STM32_SPI_EMMC_REGS STM32_SPI1_REGS
-#define STM32_DMAC_SPI_EMMC_TX STM32_DMAC_SPI1_TX
-#define STM32_DMAC_SPI_EMMC_RX STM32_DMAC_SPI1_RX
-#elif EMMC_SPI_PORT == 2
-#define STM32_SPI_EMMC_REGS STM32_SPI2_REGS
-#define STM32_DMAC_SPI_EMMC_TX STM32_DMAC_SPI2_TX
-#define STM32_DMAC_SPI_EMMC_RX STM32_DMAC_SPI2_RX
-#else
-#error "Please define EMMC_SPI_PORT in board.h."
-#endif
-
-/* Is eMMC emulation enabled? */
-static int emmc_enabled;
-
-/* Maximum amount of time to wait for AP to boot. */
-static timestamp_t boot_deadline;
-#define BOOT_TIMEOUT (5 * SECOND)
-#define EMMC_STATUS_CHECK_PERIOD (10 * MSEC)
-
-/* 1024 bytes circular buffer is enough for ~0.6ms @ 13Mhz. */
-#define SPI_RX_BUF_BYTES 1024
-#define SPI_RX_BUF_WORDS (SPI_RX_BUF_BYTES/4)
-static uint32_t in_msg[SPI_RX_BUF_WORDS];
-
-/* Macros to advance in the circular buffer. */
-#define RX_BUF_NEXT_32(i) (((i) + 1) & (SPI_RX_BUF_WORDS - 1))
-#define RX_BUF_DEC_32(i, j) (((i) - (j)) & (SPI_RX_BUF_WORDS - 1))
-#define RX_BUF_PREV_32(i) RX_BUF_DEC_32((i), 1)
-
-enum emmc_cmd {
- EMMC_ERROR = -1,
- EMMC_IDLE = 0,
- EMMC_PRE_IDLE,
- EMMC_BOOT,
-};
-
-static const struct dma_option dma_tx_option = {
- STM32_DMAC_SPI_EMMC_TX, (void *)&STM32_SPI_EMMC_REGS->dr,
- STM32_DMA_CCR_MSIZE_8_BIT | STM32_DMA_CCR_PSIZE_8_BIT
-};
-
-/* Circular RX buffer */
-static const struct dma_option dma_rx_option = {
- STM32_DMAC_SPI_EMMC_RX, (void *)&STM32_SPI_EMMC_REGS->dr,
- STM32_DMA_CCR_MSIZE_8_BIT | STM32_DMA_CCR_PSIZE_8_BIT |
- STM32_DMA_CCR_CIRC
-};
-
-/* Setup DMA to transfer bootblock. */
-static void bootblock_transfer(void)
-{
- static int transfer_try;
-
- dma_chan_t *txdma = dma_get_channel(STM32_DMAC_SPI_EMMC_TX);
-
- dma_prepare_tx(&dma_tx_option, sizeof(bootblock_raw_data),
- bootblock_raw_data);
- dma_go(txdma);
-
- CPRINTS("transfer %d", ++transfer_try);
-}
-
-/* Abort an ongoing transfer. */
-static void bootblock_stop(void)
-{
- const uint32_t timeout = 1 * MSEC;
- uint32_t start;
-
- dma_disable(STM32_DMAC_SPI_EMMC_TX);
-
- /*
- * Wait for SPI FIFO to become empty.
- * We timeout after 1 ms in case the bus is not clocked anymore.
- */
- start = __hw_clock_source_read();
- while (STM32_SPI_EMMC_REGS->sr & STM32_SPI_SR_FTLVL &&
- __hw_clock_source_read() - start < timeout)
- ;
-
- /* Then flush SPI FIFO, and make sure DAT line stays idle (high). */
- STM32_SPI_EMMC_REGS->dr = 0xff;
- STM32_SPI_EMMC_REGS->dr = 0xff;
- STM32_SPI_EMMC_REGS->dr = 0xff;
- STM32_SPI_EMMC_REGS->dr = 0xff;
-}
-
-static enum emmc_cmd emmc_parse_command(int index)
-{
- int32_t shift0;
- uint32_t data[3];
-
- if (in_msg[index] == 0xffffffff)
- return EMMC_ERROR;
-
- data[0] = htobe32(in_msg[index]);
- index = RX_BUF_NEXT_32(index);
- data[1] = htobe32(in_msg[index]);
- index = RX_BUF_NEXT_32(index);
- data[2] = htobe32(in_msg[index]);
-
- /* Figure out alignment (cmd starts with 01) */
-
- /* Number of leading ones. */
- shift0 = __builtin_clz(~data[0]);
-
- data[0] = (data[0] << shift0) | (data[1] >> (32-shift0));
- data[1] = (data[1] << shift0) | (data[2] >> (32-shift0));
-
- if (data[0] == 0x40000000 && data[1] == 0x0095ffff) {
- /* 400000000095 GO_IDLE_STATE */
- CPRINTS("goIdle");
- return EMMC_IDLE;
- }
-
- if (data[0] == 0x40f0f0f0 && data[1] == 0xf0fdffff) {
- /* 40f0f0f0f0fd GO_PRE_IDLE_STATE */
- CPRINTS("goPreIdle");
- return EMMC_PRE_IDLE;
- }
-
- if (data[0] == 0x40ffffff && data[1] == 0xfae5ffff) {
- /* 40fffffffae5 BOOT_INITIATION */
- CPRINTS("bootInit");
- return EMMC_BOOT;
- }
-
- CPRINTS("eMMC error");
- return EMMC_ERROR;
-}
-
-
-/*
- * Wake the EMMC task when there is a falling edge on the CMD line, so that we
- * can capture the command.
- */
-void emmc_cmd_interrupt(enum gpio_signal signal)
-{
- task_wake(TASK_ID_EMMC);
- CPRINTF("i");
-}
-
-static void emmc_init_spi(void)
-{
-#if EMMC_SPI_PORT == 1
- /* Reset SPI */
- STM32_RCC_APB2RSTR |= STM32_RCC_PB2_SPI1;
- STM32_RCC_APB2RSTR &= ~STM32_RCC_PB2_SPI1;
-
- /* Enable clocks to SPI module */
- STM32_RCC_APB2ENR |= STM32_RCC_PB2_SPI1;
-#elif EMMC_SPI_PORT == 2
- /* Reset SPI */
- STM32_RCC_APB1RSTR |= STM32_RCC_PB1_SPI2;
- STM32_RCC_APB1RSTR &= ~STM32_RCC_PB1_SPI2;
-
- /* Enable clocks to SPI module */
- STM32_RCC_APB1ENR |= STM32_RCC_PB1_SPI2;
-#else
-#error "Please define EMMC_SPI_PORT in board.h."
-#endif
- clock_wait_bus_cycles(BUS_APB, 1);
- gpio_config_module(MODULE_SPI_FLASH, 1);
-
- STM32_SPI_EMMC_REGS->cr2 =
- STM32_SPI_CR2_FRXTH | STM32_SPI_CR2_DATASIZE(8) |
- STM32_SPI_CR2_RXDMAEN | STM32_SPI_CR2_TXDMAEN;
-
- /* Manual CS, disable. */
- STM32_SPI_EMMC_REGS->cr1 = STM32_SPI_CR1_SSM | STM32_SPI_CR1_SSI;
-
- /* Flush SPI TX FIFO, and make sure DAT line stays idle (high). */
- STM32_SPI_EMMC_REGS->dr = 0xff;
- STM32_SPI_EMMC_REGS->dr = 0xff;
- STM32_SPI_EMMC_REGS->dr = 0xff;
- STM32_SPI_EMMC_REGS->dr = 0xff;
-
- /* Enable the SPI peripheral */
- STM32_SPI_EMMC_REGS->cr1 |= STM32_SPI_CR1_SPE;
-}
-DECLARE_HOOK(HOOK_INIT, emmc_init_spi, HOOK_PRIO_INIT_SPI);
-
-static void emmc_check_status(void);
-DECLARE_DEFERRED(emmc_check_status);
-
-static void emmc_enable_spi(void)
-{
- if (emmc_enabled)
- return;
-
- disable_sleep(SLEEP_MASK_EMMC);
-
- /* Start receiving in circular buffer in_msg. */
- dma_start_rx(&dma_rx_option, sizeof(in_msg), in_msg);
- /* Enable internal chip select. */
- STM32_SPI_EMMC_REGS->cr1 &= ~STM32_SPI_CR1_SSI;
- /*
- * EMMC_CMD and SPI1_NSS share EXTI15, make sure GPIO_EMMC_CMD is
- * selected.
- */
- gpio_disable_interrupt(GPIO_SPI1_NSS);
- gpio_enable_interrupt(GPIO_EMMC_CMD);
-
- emmc_enabled = 1;
- CPRINTS("emmc enabled");
-
- boot_deadline.val = get_time().val + BOOT_TIMEOUT;
-
- /* Check if AP has booted periodically. */
- hook_call_deferred(&emmc_check_status_data, EMMC_STATUS_CHECK_PERIOD);
-}
-DECLARE_HOOK(HOOK_CHIPSET_STARTUP, emmc_enable_spi, HOOK_PRIO_FIRST);
-
-static void emmc_disable_spi(void)
-{
- if (!emmc_enabled)
- return;
-
- /* Cancel check hook. */
- hook_call_deferred(&emmc_check_status_data, -1);
-
- gpio_disable_interrupt(GPIO_EMMC_CMD);
- /*
- * EMMC_CMD and SPI1_NSS share EXTI15, so re-enable interrupt on
- * SPI1_NSS to reconfigure the interrupt selection.
- */
- gpio_enable_interrupt(GPIO_SPI1_NSS);
- /* Disable TX DMA. */
- dma_disable(STM32_DMAC_SPI_EMMC_TX);
- /* Disable internal chip select. */
- STM32_SPI_EMMC_REGS->cr1 |= STM32_SPI_CR1_SSI;
- /* Disable RX DMA. */
- dma_disable(STM32_DMAC_SPI_EMMC_RX);
-
- /* Blank out buffer to make sure we do not look at old data. */
- memset(in_msg, 0xff, sizeof(in_msg));
-
- enable_sleep(SLEEP_MASK_EMMC);
-
- emmc_enabled = 0;
- CPRINTS("emmc disabled");
-}
-DECLARE_HOOK(HOOK_CHIPSET_SHUTDOWN, emmc_disable_spi, HOOK_PRIO_FIRST);
-
-static void emmc_check_status(void)
-{
- /* Bootblock switch disabled, switch off emulation */
- if (gpio_get_level(GPIO_BOOTBLOCK_EN_L) == 1) {
- emmc_disable_spi();
- return;
- }
-
- if (timestamp_expired(boot_deadline, NULL)) {
- CPRINTS("emmc: AP failed to boot.");
- chipset_force_shutdown(CHIPSET_SHUTDOWN_BOARD_CUSTOM);
- return;
- }
-
- /* Check if AP has booted again, next time. */
- hook_call_deferred(&emmc_check_status_data, EMMC_STATUS_CHECK_PERIOD);
-}
-
-void emmc_task(void *u)
-{
- int dma_pos, i;
- dma_chan_t *rxdma;
- enum emmc_cmd cmd;
- /* Are we currently transmitting data? */
- int tx = 0;
-
- rxdma = dma_get_channel(STM32_DMAC_SPI_EMMC_RX);
-
- while (1) {
- /* Wait for a command */
- task_wait_event(-1);
-
- dma_pos = dma_bytes_done(rxdma, sizeof(in_msg)) / 4;
- i = RX_BUF_PREV_32(dma_pos);
-
- /*
- * By now, bus should be idle again (it takes <10us to transmit
- * a command, less than is needed to process interrupt and wake
- * this task).
- */
- if (in_msg[i] != 0xffffffff) {
- CPRINTF("?");
- /* TODO(b:110907438): We should probably just retry. */
- continue;
- }
-
- /*
- * Find a command, looking from the end of the buffer to make
- * it faster.
- */
- while (i != dma_pos && in_msg[i] == 0xffffffff)
- i = RX_BUF_PREV_32(i);
-
- /*
- * We missed the command? That should not happen if we process
- * the buffer quickly enough (and the interrupt was real).
- */
- if (i == dma_pos) {
- CPRINTF("!");
- continue;
- }
-
- /*
- * We found the end of the command, now find the beginning
- * (commands are 6-byte long so the starting point is either 2
- * or 1 word before the end of the command).
- */
- i = RX_BUF_DEC_32(i, 2);
- if (in_msg[i] == 0xffffffff)
- i = RX_BUF_NEXT_32(i);
-
- cmd = emmc_parse_command(i);
-
- if (!tx) {
- /*
- * When not transferring, host will send GO_IDLE_STATE,
- * GO_PRE_IDLE_STATE, then BOOT_INITIATION commands. But
- * all we really care about is the BOOT_INITIATION
- * command: start the transfer.
- */
- if (cmd == EMMC_BOOT) {
- tx = 1;
- bootblock_transfer();
- }
- } else {
- /*
- * Host sends GO_IDLE_STATE to abort the transfer (e.g.
- * when an incorrect number of lanes is used) and when
- * the transfer is complete.
- * Also react to GO_PRE_IDLE_STATE in case we missed
- * GO_IDLE_STATE command.
- */
- if (cmd == EMMC_IDLE || cmd == EMMC_PRE_IDLE) {
- bootblock_stop();
- tx = 0;
- }
- }
- }
-}
diff --git a/board/kukui/usb_pd_policy.c b/board/kukui/usb_pd_policy.c
deleted file mode 100644
index 551fa18e1f..0000000000
--- a/board/kukui/usb_pd_policy.c
+++ /dev/null
@@ -1,447 +0,0 @@
-/* Copyright 2018 The Chromium OS Authors. All rights reserved.
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-#include "charger.h"
-#include "charge_manager.h"
-#include "common.h"
-#include "console.h"
-#include "driver/charger/rt946x.h"
-#include "gpio.h"
-#include "hooks.h"
-#include "host_command.h"
-#include "registers.h"
-#include "system.h"
-#include "task.h"
-#include "timer.h"
-#include "util.h"
-#include "usb_mux.h"
-#include "usb_pd.h"
-#include "usb_pd_tcpm.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_snk_pdo[] = {
- PDO_FIXED(5000, 500, PDO_FIXED_FLAGS),
- PDO_BATT(4750,
- (int)(PD_MAX_VOLTAGE_MV * 1.05),
- PD_OPERATING_POWER_MW),
- PDO_VAR(4750,
- (int)(PD_MAX_VOLTAGE_MV * 1.05),
- PD_MAX_CURRENT_MA),
-};
-const int pd_snk_pdo_cnt = ARRAY_SIZE(pd_snk_pdo);
-
-int pd_is_valid_input_voltage(int mv)
-{
- return 1;
-}
-
-void pd_transition_voltage(int idx)
-{
- /* No-operation: we are always 5V */
-}
-
-static int board_get_polarity(int port)
-{
- /* Krane's aux mux polarity is reversed. Workaround to flip it back. */
- if (IS_ENABLED(BOARD_KRANE) && board_get_version() == 3)
- return !pd_get_polarity(port);
-
- return pd_get_polarity(port);
-}
-
-static uint8_t vbus_en;
-
-int board_vbus_source_enabled(int port)
-{
- return vbus_en;
-}
-
-int board_is_sourcing_vbus(int port)
-{
- if (board_get_version() <= 1)
- return charger_is_sourcing_otg_power(port);
- else
- return board_vbus_source_enabled(port);
-}
-
-int pd_set_power_supply_ready(int port)
-{
- if (port != CHARGE_PORT_USB_C)
- return EC_ERROR_INVAL;
-
- pd_set_vbus_discharge(port, 0);
- /* Provide VBUS */
- vbus_en = 1;
-
- charger_enable_otg_power(1);
-
- gpio_set_level(GPIO_EN_USBC_CHARGE_L, 1);
- gpio_set_level(GPIO_EN_PP5000_USBC, 1);
-
- /* notify host of power info change */
- pd_send_host_event(PD_EVENT_POWER_CHANGE);
-
- return EC_SUCCESS; /* we are ready */
-}
-
-void pd_power_supply_reset(int port)
-{
- int prev_en;
-
- if (port != CHARGE_PORT_USB_C)
- return;
-
- prev_en = vbus_en;
- /* Disable VBUS */
- vbus_en = 0;
- /* Enable discharge if we were previously sourcing 5V */
- if (prev_en)
- pd_set_vbus_discharge(port, 1);
-
- charger_enable_otg_power(0);
- gpio_set_level(GPIO_EN_PP5000_USBC, 0);
-
- /* notify host of power info change */
- pd_send_host_event(PD_EVENT_POWER_CHANGE);
-}
-
-void typec_set_source_current_limit(int port, int rp)
-{
- /* No-operation */
-}
-
-int pd_board_checks(void)
-{
- return EC_SUCCESS;
-}
-
-int pd_check_power_swap(int port)
-{
- /*
- * Allow power swap as long as we are acting as a dual role device,
- * otherwise assume our role is fixed (not in S0 or console command
- * to fix our role).
- */
- return pd_get_dual_role(port) == PD_DRP_TOGGLE_ON ? 1 : 0;
-}
-
-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) ? 1 : 0;
-}
-
-int pd_check_vconn_swap(int port)
-{
- /*
- * VCONN is provided directly by the battery (PPVAR_SYS)
- * but use the same rules as power swap.
- */
- return pd_get_dual_role(port) == PD_DRP_TOGGLE_ON ? 1 : 0;
-}
-
-void pd_execute_data_swap(int port, int data_role)
-{
- /* Do nothing */
-}
-
-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);
- }
-}
-
-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);
-}
-/* ----------------- 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;
-
- /* 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]);
-
- 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_COUNT];
-/* DP Status VDM as returned by UFP */
-static uint32_t dp_status[CONFIG_USB_PD_PORT_COUNT];
-
-static void svdm_safe_dp_mode(int port)
-{
- /* make DP interface safe until configure */
- dp_flags[port] = 0;
- dp_status[port] = 0;
- usb_mux_set(port, TYPEC_MUX_NONE,
- USB_SWITCH_CONNECT, board_get_polarity(port));
-}
-
-static int svdm_enter_dp_mode(int port, uint32_t mode_caps)
-{
- /* Kukui doesn't support superspeed lanes. */
- const uint32_t support_pin_mode = MODE_DP_PIN_C | MODE_DP_PIN_E;
-
- /* Only enter mode if device is DFP_D and PIN_C, PIN_E capable */
- if ((mode_caps & MODE_DP_SNK) &&
- (mode_caps & (support_pin_mode << MODE_DP_DFP_PIN_SHIFT))) {
- svdm_safe_dp_mode(port);
- return 0;
- }
-
- CPRINTS("ERR:DP mode SNK or C&E missing! 0x%x", mode_caps);
- 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 int svdm_dp_config(int port, uint32_t *payload)
-{
- int opos = pd_alt_mode(port, USB_SID_DISPLAYPORT);
- /* Kukui doesn't support multi-function mode, mask it out. */
- int status = dp_status[port] & ~PD_VDO_DPSTS_MF_MASK;
- int pin_mode = pd_dfp_dp_get_pin_mode(port, status);
-
- if (!pin_mode)
- return 0;
-
- usb_mux_set(port, TYPEC_MUX_DP, USB_SWITCH_CONNECT,
- board_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_COUNT];
-
-static void svdm_dp_post_config(int port)
-{
- const struct usb_mux * const mux = &usb_muxes[port];
-
- dp_flags[port] |= DP_FLAGS_DP_ON;
- if (!(dp_flags[port] & DP_FLAGS_HPD_HI_PENDING))
- return;
-
- gpio_set_level(GPIO_USB_C0_HPD_OD, 1);
- gpio_set_level(GPIO_USB_C0_DP_OE_L, 0);
- gpio_set_level(GPIO_USB_C0_DP_POLARITY, board_get_polarity(port));
-
- /* 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 = gpio_get_level(GPIO_USB_C0_HPD_OD);
- int lvl = PD_VDO_DPSTS_HPD_LVL(payload[1]);
- int irq = PD_VDO_DPSTS_HPD_IRQ(payload[1]);
- const struct usb_mux * const mux = &usb_muxes[port];
-
- 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;
- }
-
- mux->hpd_update(port, lvl, irq);
-
- 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(GPIO_USB_C0_HPD_OD, 0);
- usleep(HPD_DSTREAM_DEBOUNCE_IRQ);
- gpio_set_level(GPIO_USB_C0_HPD_OD, 1);
-
- gpio_set_level(GPIO_USB_C0_DP_OE_L, 0);
- gpio_set_level(GPIO_USB_C0_DP_POLARITY,
- board_get_polarity(port));
-
- /* set the minimum time delay (2ms) for the next HPD IRQ */
- hpd_deadline[port] = get_time().val + HPD_USTREAM_DEBOUNCE_LVL;
- } else if (irq & !cur_lvl) {
- CPRINTF("ERR:HPD:IRQ&LOW\n");
- return 0; /* nak */
- } else {
- gpio_set_level(GPIO_USB_C0_HPD_OD, lvl);
- gpio_set_level(GPIO_USB_C0_DP_OE_L, !lvl);
- gpio_set_level(GPIO_USB_C0_DP_POLARITY,
- board_get_polarity(port));
- /* set the minimum time delay (2ms) for the next HPD IRQ */
- hpd_deadline[port] = get_time().val + HPD_USTREAM_DEBOUNCE_LVL;
- }
-
- /* ack */
- return 1;
-}
-
-static void svdm_exit_dp_mode(int port)
-{
- const struct usb_mux * const mux = &usb_muxes[port];
-
- svdm_safe_dp_mode(port);
- gpio_set_level(GPIO_USB_C0_HPD_OD, 0);
- gpio_set_level(GPIO_USB_C0_DP_OE_L, 1);
- 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 */