summaryrefslogtreecommitdiff
path: root/baseboard/kukui
diff options
context:
space:
mode:
Diffstat (limited to 'baseboard/kukui')
-rw-r--r--baseboard/kukui/base_detect_kukui.c231
-rw-r--r--baseboard/kukui/baseboard.c222
-rw-r--r--baseboard/kukui/baseboard.h357
-rw-r--r--baseboard/kukui/battery_bq27541.c225
-rw-r--r--baseboard/kukui/battery_max17055.c188
-rw-r--r--baseboard/kukui/battery_mm8013.c141
-rw-r--r--baseboard/kukui/battery_smart.c138
-rw-r--r--baseboard/kukui/build.mk28
-rw-r--r--baseboard/kukui/charger_mt6370.c366
-rw-r--r--baseboard/kukui/charger_mt6370.h21
-rw-r--r--baseboard/kukui/emmc.c400
-rw-r--r--baseboard/kukui/emmc_ite.c205
-rw-r--r--baseboard/kukui/usb_pd_policy.c298
-rw-r--r--baseboard/kukui/usb_pd_policy.h13
14 files changed, 0 insertions, 2833 deletions
diff --git a/baseboard/kukui/base_detect_kukui.c b/baseboard/kukui/base_detect_kukui.c
deleted file mode 100644
index 68542b4fb6..0000000000
--- a/baseboard/kukui/base_detect_kukui.c
+++ /dev/null
@@ -1,231 +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.
- */
-
-#include "adc.h"
-#include "base_state.h"
-#include "board.h"
-#include "charge_manager.h"
-#include "console.h"
-#include "gpio.h"
-#include "hooks.h"
-#include "timer.h"
-#include "usb_pd.h"
-#include "util.h"
-
-#define CPRINTS(format, args...) cprints(CC_USB, format, ## args)
-
-/* Krane base detection code */
-
-/* Base detection and debouncing */
-#define BASE_DETECT_DEBOUNCE_US (20 * MSEC)
-
-/*
- * If the base status is unclear (i.e. not within expected ranges, read
- * the ADC value again every 500ms.
- */
-#define BASE_DETECT_RETRY_US (500 * MSEC)
-
-enum kukui_pogo_device_type {
- DEVICE_TYPE_ERROR = -2,
- DEVICE_TYPE_UNKNOWN = -1,
- DEVICE_TYPE_DETACHED = 0,
-#ifdef VARIANT_KUKUI_POGO_DOCK
- DEVICE_TYPE_DOCK,
-#endif
- DEVICE_TYPE_KEYBOARD,
- DEVICE_TYPE_COUNT,
-};
-
-struct {
- int mv_low, mv_high;
-} static const pogo_detect_table[] = {
- [DEVICE_TYPE_DETACHED] = {2700, 3500}, /* 10K, NC, around 3.3V */
-#ifdef VARIANT_KUKUI_POGO_DOCK
- [DEVICE_TYPE_DOCK] = {141, 173}, /* 10K, 0.5K ohm */
-#endif
- [DEVICE_TYPE_KEYBOARD] = {270, 400}, /* 10K, 1K ohm */
-};
-BUILD_ASSERT(ARRAY_SIZE(pogo_detect_table) == DEVICE_TYPE_COUNT);
-
-static uint64_t base_detect_debounce_time;
-static enum kukui_pogo_device_type pogo_type;
-
-int kukui_pogo_extpower_present(void)
-{
-#ifdef VARIANT_KUKUI_POGO_DOCK
- return pogo_type == DEVICE_TYPE_DOCK &&
- gpio_get_level(GPIO_POGO_VBUS_PRESENT);
-#else
- return 0;
-#endif
-}
-
-static enum kukui_pogo_device_type get_device_type(int mv)
-{
- int i;
-
- if (mv == ADC_READ_ERROR)
- return DEVICE_TYPE_ERROR;
-
- for (i = 0; i < DEVICE_TYPE_COUNT; i++) {
- if (pogo_detect_table[i].mv_low <= mv &&
- mv <= pogo_detect_table[i].mv_high)
- return i;
- }
-
- return DEVICE_TYPE_UNKNOWN;
-}
-
-static void enable_charge(int enable)
-{
-#ifdef VARIANT_KUKUI_POGO_DOCK
- if (enable) {
- struct charge_port_info info = {
- .voltage = 5000, .current = 1500};
- /*
- * Set supplier type to PD to have same priority as type c
- * port.
- */
- charge_manager_update_charge(
- CHARGE_SUPPLIER_DEDICATED, CHARGE_PORT_POGO, &info);
- } else {
- charge_manager_update_charge(
- CHARGE_SUPPLIER_DEDICATED, CHARGE_PORT_POGO, NULL);
- }
- pd_send_host_event(PD_EVENT_POWER_CHANGE);
-#endif
-}
-
-static void enable_power_supply(int enable)
-{
- gpio_set_level(GPIO_EN_PP3300_POGO, enable);
-}
-
-static void base_detect_deferred(void);
-DECLARE_DEFERRED(base_detect_deferred);
-
-static void base_set_device_type(enum kukui_pogo_device_type device_type)
-{
- switch (device_type) {
- case DEVICE_TYPE_ERROR:
- case DEVICE_TYPE_UNKNOWN:
- hook_call_deferred(&base_detect_deferred_data,
- BASE_DETECT_RETRY_US);
- break;
-
- case DEVICE_TYPE_DETACHED:
- enable_power_supply(0);
- enable_charge(0);
- base_set_state(0);
- break;
-
-#ifdef VARIANT_KUKUI_POGO_DOCK
- case DEVICE_TYPE_DOCK:
- enable_power_supply(0);
- enable_charge(1);
- base_set_state(1);
- break;
-#endif
-
- case DEVICE_TYPE_KEYBOARD:
- enable_charge(0);
- enable_power_supply(1);
- base_set_state(1);
- break;
-
- case DEVICE_TYPE_COUNT:
- /* should not happen */
- break;
- }
-}
-
-static void base_detect_deferred(void)
-{
- uint64_t time_now = get_time().val;
- int mv;
-
- if (base_detect_debounce_time > time_now) {
- hook_call_deferred(&base_detect_deferred_data,
- base_detect_debounce_time - time_now);
- return;
- }
-
- /*
- * Disable interrupt first to prevent it triggered by value
- * changed from 1 to disabled state(=0).
- */
- gpio_disable_interrupt(GPIO_POGO_ADC_INT_L);
- gpio_set_flags(GPIO_POGO_ADC_INT_L, GPIO_ANALOG);
- mv = adc_read_channel(ADC_POGO_ADC_INT_L);
- /* restore the pin function */
- gpio_set_flags(GPIO_POGO_ADC_INT_L, GPIO_INT_BOTH);
- gpio_enable_interrupt(GPIO_POGO_ADC_INT_L);
-
- pogo_type = get_device_type(mv);
- CPRINTS("POGO: adc=%d, type=%d", mv, pogo_type);
-
- base_set_device_type(pogo_type);
-}
-
-void pogo_adc_interrupt(enum gpio_signal signal)
-{
- uint64_t time_now = get_time().val;
-
- if (base_detect_debounce_time <= time_now) {
- hook_call_deferred(&base_detect_deferred_data,
- BASE_DETECT_DEBOUNCE_US);
- }
-
- base_detect_debounce_time = time_now + BASE_DETECT_DEBOUNCE_US;
-}
-
-static void pogo_chipset_init(void)
-{
- /* Enable pogo interrupt */
- gpio_enable_interrupt(GPIO_POGO_ADC_INT_L);
-
- hook_call_deferred(&base_detect_deferred_data, 0);
-}
-DECLARE_HOOK(HOOK_INIT, pogo_chipset_init, HOOK_PRIO_DEFAULT);
-
-/* Called on AP S3 -> S5 transition */
-static void pogo_chipset_shutdown(void)
-{
- /* Disable pogo interrupt */
- gpio_disable_interrupt(GPIO_POGO_ADC_INT_L);
-
- enable_power_supply(0);
-}
-DECLARE_HOOK(HOOK_CHIPSET_SHUTDOWN, pogo_chipset_shutdown, HOOK_PRIO_DEFAULT);
-
-void base_force_state(enum ec_set_base_state_cmd state)
-{
- if (state >= EC_SET_BASE_STATE_RESET) {
- CPRINTS("BD forced reset");
- pogo_chipset_init();
- return;
- }
-
- gpio_disable_interrupt(GPIO_POGO_ADC_INT_L);
- pogo_type = (state == 1 ? DEVICE_TYPE_KEYBOARD : DEVICE_TYPE_DETACHED);
- base_set_device_type(state == EC_SET_BASE_STATE_ATTACH
- ? DEVICE_TYPE_KEYBOARD
- : DEVICE_TYPE_DETACHED);
- CPRINTS("BD forced %sconnected", state == EC_SET_BASE_STATE_ATTACH ?
- "" : "dis");
-}
-
-#ifdef VARIANT_KUKUI_POGO_DOCK
-static void board_pogo_charge_init(void)
-{
- int i;
-
- /* Initialize all charge suppliers to 0 */
- for (i = 0; i < CHARGE_SUPPLIER_COUNT; i++)
- charge_manager_update_charge(i, CHARGE_PORT_POGO, NULL);
-}
-DECLARE_HOOK(HOOK_INIT, board_pogo_charge_init,
- HOOK_PRIO_CHARGE_MANAGER_INIT + 1);
-#endif
diff --git a/baseboard/kukui/baseboard.c b/baseboard/kukui/baseboard.c
deleted file mode 100644
index 3f9a1c36c6..0000000000
--- a/baseboard/kukui/baseboard.c
+++ /dev/null
@@ -1,222 +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.
- */
-
-#include "adc.h"
-#include "charger.h"
-#include "chipset.h"
-#include "dma.h"
-#include "gpio.h"
-#include "hooks.h"
-#include "keyboard_scan.h"
-#include "registers.h"
-#include "timer.h"
-
-#define CPRINTS(format, args...) cprints(CC_USBCHARGE, format, ## args)
-#define CPRINTF(format, args...) cprintf(CC_USBCHARGE, format, ## args)
-
-#ifndef CONFIG_CHARGER_RUNTIME_CONFIG
-#if defined(VARIANT_KUKUI_CHARGER_MT6370)
-#include "driver/charger/rt946x.h"
-const struct charger_config_t chg_chips[] = {
- {
- .i2c_port = I2C_PORT_CHARGER,
- .i2c_addr_flags = RT946X_ADDR_FLAGS,
- .drv = &rt946x_drv,
- },
-};
-#elif defined(VARIANT_KUKUI_CHARGER_ISL9238)
-#include "driver/charger/isl923x.h"
-const struct charger_config_t chg_chips[] = {
- {
- .i2c_port = I2C_PORT_CHARGER,
- .i2c_addr_flags = ISL923X_ADDR_FLAGS,
- .drv = &isl923x_drv,
- },
-};
-#endif /* VARIANT_KUKUI_CHARGER_* */
-
-#endif /* CONFIG_CHARGER_RUNTIME_CONFIG */
-
-void board_reset_pd_mcu(void)
-{
-}
-
-void board_config_pre_init(void)
-{
-#ifdef VARIANT_KUKUI_EC_STM32F098
- 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);
-
-#elif defined(VARIANT_KUKUI_EC_STM32L431)
-#ifdef CONFIG_DMA
- dma_init();
-#endif
- /*
- * Remap USART1 and SPI2 DMA:
- *
- * DMA2_CH=DMA1_CH+8
- *
- * Ch6 (DMA2): USART1_TX / Ch7: USART1_RX (0010)
- * Ch4 (DMA1): SPI2_RX / Ch5: SPI2_TX (0010)
- *
- * (*((volatile unsigned long *)(0x400200A8UL))) = 0x00011000;
- * (*((volatile unsigned long *)(0x400204A8UL))) = 0x00200000;
- */
-
- STM32_DMA_CSELR(STM32_DMAC_CH4) = (1 << 12) | (1 << 16);
- STM32_DMA_CSELR(STM32_DMAC_CH14) = (2 << 20) | (2 << 24);
-#endif
-}
-
-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,
-};
-
-/* map from kukui_board_version to board id voltage in mv */
-#ifdef VARIANT_KUKUI_EC_IT81202
-const int16_t kukui_board_id_map[] = {
- 136, /* 51.1K , 2.2K(gru 3.3K) ohm */
- 388, /* 51.1k , 6.8K ohm */
- 584, /* 51.1K , 11K ohm */
- 785, /* 56K , 17.4K ohm */
- 993, /* 51.1K , 22K ohm */
- 1221, /* 51.1K , 30K ohm */
- 1433, /* 51.1K , 39.2K ohm */
- 1650, /* 56K , 56K ohm */
- 1876, /* 47K , 61.9K ohm */
- 2084, /* 47K , 80.6K ohm */
- 2273, /* 56K , 124K ohm */
- 2461, /* 51.1K , 150K ohm */
- 2672, /* 47K , 200K ohm */
- 2889, /* 47K , 330K ohm */
- 3086, /* 47K , 680K ohm */
- 3300, /* 56K , NC */
-};
-
-#define THRESHOLD_MV 103 /* Simply assume 3300/16/2 */
-#else
-const int16_t kukui_board_id_map[] = {
- 109, /* 51.1K , 2.2K(gru 3.3K) ohm */
- 211, /* 51.1k , 6.8K ohm */
- 319, /* 51.1K , 11K ohm */
- 427, /* 56K , 17.4K ohm */
- 542, /* 51.1K , 22K ohm */
- 666, /* 51.1K , 30K ohm */
- 781, /* 51.1K , 39.2K ohm */
- 900, /* 56K , 56K ohm */
- 1023, /* 47K , 61.9K ohm */
- 1137, /* 47K , 80.6K ohm */
- 1240, /* 56K , 124K ohm */
- 1343, /* 51.1K , 150K ohm */
- 1457, /* 47K , 200K ohm */
- 1576, /* 47K , 330K ohm */
- 1684, /* 47K , 680K ohm */
- 1800, /* 56K , NC */
-};
-
-#define THRESHOLD_MV 56 /* Simply assume 1800/16/2 */
-#endif /* VARIANT_KUKUI_EC_IT81202 */
-BUILD_ASSERT(ARRAY_SIZE(kukui_board_id_map) == BOARD_VERSION_COUNT);
-
-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(20);
- 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_board_id_map[i] + THRESHOLD_MV) {
- version = i;
- break;
- }
- }
-
-#ifdef VARIANT_KUKUI_EC_STM32F098
- /*
- * For devices without pogo, Disable ADC module after we detect the
- * board version, since this is the only thing ADC module needs to do
- * for this board.
- */
- if (CONFIG_DEDICATED_CHARGE_PORT_COUNT == 0 &&
- version != BOARD_VERSION_UNKNOWN)
- adc_disable();
-#endif
-
- return version;
-}
-
-static void baseboard_spi_init(void)
-{
-#if defined(VARIANT_KUKUI_EC_STM32F098) || defined(VARIANT_KUKUI_EC_STM32L431)
- /* Set SPI PA15,PB3/4/5/13/14/15 pins to high speed */
- STM32_GPIO_OSPEEDR(GPIO_A) |= 0xc0000000;
- STM32_GPIO_OSPEEDR(GPIO_B) |= 0xfc000fc0;
-#endif
-}
-DECLARE_HOOK(HOOK_INIT, baseboard_spi_init, HOOK_PRIO_INIT_SPI + 1);
-
-int board_allow_i2c_passthru(int port)
-{
- return (port == I2C_PORT_VIRTUAL_BATTERY);
-}
-
-/* Enable or disable input devices, based on chipset state and tablet mode */
-#ifdef VARIANT_KUKUI_JACUZZI
-__override void lid_angle_peripheral_enable(int enable)
-{
- int chipset_in_s0 = chipset_in_state(CHIPSET_STATE_ON);
-
- if (enable) {
- keyboard_scan_enable(1, KB_SCAN_DISABLE_LID_ANGLE);
- } else {
- /*
- * Ensure that the chipset is off before disabling the
- * keyboard. When the chipset is on, the EC keeps the
- * keyboard enabled and the AP decides whether to
- * ignore input devices or not.
- */
- if (!chipset_in_s0)
- keyboard_scan_enable(0,
- KB_SCAN_DISABLE_LID_ANGLE);
- }
-}
-#endif
diff --git a/baseboard/kukui/baseboard.h b/baseboard/kukui/baseboard.h
deleted file mode 100644
index 87ebeb40e1..0000000000
--- a/baseboard/kukui/baseboard.h
+++ /dev/null
@@ -1,357 +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.
- */
-
-/* Kukui board configuration */
-
-#ifndef __CROS_EC_BASEBOARD_H
-#define __CROS_EC_BASEBOARD_H
-
-/*
- * Variant battery defines, pick one:
- * VARIANT_KUKUI_BATTERY_MAX17055
- * VARIANT_KUKUI_BATTERY_MM8013
- * VARIANT_KUKUI_BATTERY_BQ27541
- * VARIANT_KUKUI_BATTERY_SMART
- */
-#if defined(VARIANT_KUKUI_BATTERY_MAX17055)
-#define CONFIG_BATTERY_MAX17055
-#define CONFIG_BATTERY_MAX17055_ALERT
-#define BATTERY_MAX17055_RSENSE 5 /* m-ohm */
-#elif defined(VARIANT_KUKUI_BATTERY_MM8013)
-#define CONFIG_BATTERY_MM8013
-#elif defined(VARIANT_KUKUI_BATTERY_BQ27541)
-#define CONFIG_BATTERY_BQ27541
-#elif defined(VARIANT_KUKUI_BATTERY_SMART)
-#define CONFIG_BATTERY_SMART
-#define CONFIG_BATTERY_FUEL_GAUGE
-#else
-#error Must define a VARIANT_KUKUI_BATTERY
-#endif /* VARIANT_KUKUI_BATTERY */
-
-/*
- * Variant charger defines, pick one:
- * VARIANT_KUKUI_CHARGER_MT6370
- * VARIANT_KUKUI_CHARGER_ISL9238
- */
-#if defined(VARIANT_KUKUI_CHARGER_MT6370)
-#define CONFIG_CHARGER_MT6370
-#define CONFIG_CHARGER_MT6370_BC12_GPIO
-#define CONFIG_CHARGE_RAMP_HW
-#define CONFIG_CHARGER_OTG
-#define CONFIG_CHARGER_PROFILE_OVERRIDE
-#define CONFIG_USB_PD_TCPM_MT6370
-#define CONFIG_USB_PD_TCPC_LOW_POWER
-#define CONFIG_USB_PD_DISCHARGE_TCPC
-#define CONFIG_USB_PD_DUAL_ROLE_AUTO_TOGGLE
-
-/* TCPC MT6370 */
-#define PD_POWER_SUPPLY_TURN_ON_DELAY 30000 /* us */
-#define PD_POWER_SUPPLY_TURN_OFF_DELAY 250000 /* us */
-
-/*
- * The Maximum input voltage is 13.5V, need another 5% tolerance.
- * 12.85V * 1.05 = 13.5V
- */
-#define PD_MAX_VOLTAGE_MV 12850
-#define CONFIG_USB_PD_PREFER_MV
-#elif defined(VARIANT_KUKUI_CHARGER_ISL9238)
-#define CONFIG_CHARGER_ISL9238C
-#define CONFIG_CHARGER_SENSE_RESISTOR_AC 20 /* BOARD_RS1 */
-#define CONFIG_CHARGER_SENSE_RESISTOR 10 /* BOARD_RS2 */
-#define CONFIG_CHARGER_OTG
-#define CONFIG_CHARGE_RAMP_HW
-
-/* TCPC FUSB302 */
-#define PD_POWER_SUPPLY_TURN_ON_DELAY 160000 /* us */
-#define PD_POWER_SUPPLY_TURN_OFF_DELAY 250000 /* us */
-
-/* b/2230219: 15V has better charging performance than 20V */
-#define PD_MAX_VOLTAGE_MV 15000
-#else
-#error Must define a VARIANT_KUKUI_CHARGER
-#endif /* VARIANT_KUKUI_CHARGER */
-
-/*
- * Variant pogo defines, if pick, VARIANT_KUKUI_POGO_KEYBOARD is mandatory
- * VARIANT_KUKUI_POGO_KEYBOARD
- * VARIANT_KUKUI_POGO_DOCK
- */
-#ifdef VARIANT_KUKUI_POGO_DOCK
-#ifndef VARIANT_KUKUI_POGO_KEYBOARD
-#error VARIANT_KUKUI_POGO_KEYBOARD is mandatory if use dock
-#endif /* !VARIANT_KUKUI_POGO_KEYBOARD */
-#undef CONFIG_DEDICATED_CHARGE_PORT_COUNT
-#define CONFIG_DEDICATED_CHARGE_PORT_COUNT 1
-#define DEDICATED_CHARGE_PORT 1
-#endif /* VARIANT_KUKUI_POGO_DOCK */
-
-#ifdef VARIANT_KUKUI_POGO_KEYBOARD
-#define CONFIG_DETACHABLE_BASE
-#define CONFIG_BASE_ATTACHED_SWITCH
-#endif
-
-/* define this if the board is jacuzzi family */
-#ifdef VARIANT_KUKUI_JACUZZI
-#define CONFIG_HOSTCMD_AP_SET_SKUID
-/*
- * IT81202 based boards are variant of jacuzzi and I/O expander isn't required
- * on them.
- */
-#if defined(VARIANT_KUKUI_EC_STM32F098) || defined(VARIANT_KUKUI_EC_STM32L431)
-#define CONFIG_IO_EXPANDER
-#define CONFIG_IO_EXPANDER_IT8801
-#define CONFIG_IO_EXPANDER_PORT_COUNT 1
-#define CONFIG_KEYBOARD_NOT_RAW
-
-#endif
-
-#define CONFIG_KEYBOARD_COL2_INVERTED
-
-#define CONFIG_GMR_TABLET_MODE
-#define GMR_TABLET_MODE_GPIO_L GPIO_TABLET_MODE_L
-#define CONFIG_TABLET_MODE
-#define CONFIG_TABLET_MODE_SWITCH
-
-#define PD_OPERATING_POWER_MW 30000
-
-#define CONFIG_MKBP_HOST_EVENT_WAKEUP_MASK \
- (EC_HOST_EVENT_MASK(EC_HOST_EVENT_LID_OPEN) |\
- EC_HOST_EVENT_MASK(EC_HOST_EVENT_POWER_BUTTON))
-
-#else /* !VARIANT_KUKUI_JACUZZI */
-
-#define CONFIG_MKBP_HOST_EVENT_WAKEUP_MASK \
- (EC_HOST_EVENT_MASK(EC_HOST_EVENT_LID_OPEN) |\
- EC_HOST_EVENT_MASK(EC_HOST_EVENT_POWER_BUTTON) |\
- EC_HOST_EVENT_MASK(EC_HOST_EVENT_MODE_CHANGE))
-
-#endif /* VARIANT_KUKUI_JACUZZI */
-
-#if defined(SECTION_IS_RW) || defined(VARIANT_KUKUI_EC_IT81202)
-#define CONFIG_POWER_SLEEP_FAILURE_DETECTION
-#define CONFIG_POWER_TRACK_HOST_SLEEP_STATE
-#endif
-
-/*
- * Define this flag if board controls dp mux via gpio pins USB_C0_DP_OE_L and
- * USB_C0_DP_POLARITY.
- *
- * board must provide function board_set_dp_mux_control(output_enable, polarity)
- *
- * #define VARIANT_KUKUI_DP_MUX_GPIO
- */
-
-/* Optional modules */
-#define CONFIG_ADC
-#undef CONFIG_ADC_WATCHDOG
-#define CONFIG_CHIPSET_MT8183
-#define CONFIG_CMD_ACCELS
-#define CONFIG_EMULATED_SYSRQ
-#define CONFIG_I2C
-#define CONFIG_I2C_CONTROLLER
-#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_SWITCH
-
-#ifdef SECTION_IS_RO
-#undef CONFIG_SYSTEM_UNLOCKED /* Disabled in RO to save space */
-#else
-#define CONFIG_SYSTEM_UNLOCKED /* Allow dangerous commands for testing */
-#endif
-
-/* Bootblock */
-#ifdef SECTION_IS_RO
-#define CONFIG_BOOTBLOCK
-
-#define EMMC_SPI_PORT 2
-#endif
-
-/* Optional features */
-#define CONFIG_BOARD_PRE_INIT
-#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_PRESERVE_LOGS
-
-/* Required for FAFT */
-#define CONFIG_CMD_BUTTON
-#define CONFIG_CMD_CHARGEN
-
-/* 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_CHARGER
-#define CONFIG_CHARGER_INPUT_CURRENT 512
-#define CONFIG_CHARGER_LIMIT_POWER_THRESH_BAT_PCT 2
-#define CONFIG_CHARGER_LIMIT_POWER_THRESH_CHG_MW 15000
-#define CONFIG_CHARGER_DISCHARGE_ON_AC
-#define CONFIG_CHARGER_DISCHARGE_ON_AC_CUSTOM
-#define CONFIG_USB_CHARGER
-
-/* 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
-
-#define GPIO_LID_OPEN GPIO_HALL_INT_L
-
-#ifndef VARIANT_KUKUI_NO_SENSORS
-#define CONFIG_ACCEL_FIFO
-/* FIFO size is in power of 2. */
-#define CONFIG_ACCEL_FIFO_SIZE 256
-#define CONFIG_ACCEL_FIFO_THRES (CONFIG_ACCEL_FIFO_SIZE / 3)
-#endif /* VARIANT_KUKUI_NO_SENSORS */
-
-#ifndef VARIANT_KUKUI_TABLET_PWRBTN
-#define POWERBTN_BOOT_DELAY 0
-#endif
-
-/* 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_DUAL_ROLE
-#define CONFIG_USB_PD_LOGGING
-#define CONFIG_USB_PD_PORT_MAX_COUNT 1
-#define CONFIG_USB_PD_TCPM_TCPCI
-#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_CRITICAL_SHUTDOWN_CUT_OFF
-#define CONFIG_BATTERY_CUT_OFF
-#define CONFIG_BATTERY_PRESENT_CUSTOM
-#define CONFIG_BATTERY_REVIVE_DISCONNECT
-
-#define PD_MAX_POWER_MW ((PD_MAX_VOLTAGE_MV * PD_MAX_CURRENT_MA) / 1000)
-#ifdef BOARD_KODAMA
-#define PD_MAX_CURRENT_MA 2000
-#else
-#define PD_MAX_CURRENT_MA 3000
-#endif
-
-/* Optional for testing */
-#undef CONFIG_PECI
-#undef CONFIG_PSTORE
-
-#define CONFIG_TASK_PROFILING
-#define CONFIG_MKBP_USE_GPIO
-
-/*
- * Variant EC defines. Pick one:
- * VARIANT_KUKUI_EC_STM32F098
- * VARIANT_KUKUI_EC_IT81202
- * VARIANT_KUKUI_EC_STM32L431
- */
-#if defined(VARIANT_KUKUI_EC_STM32F098) || defined(VARIANT_KUKUI_EC_STM32L431)
-/* Timer selection */
-#define TIM_CLOCK32 2
-#define TIM_WATCHDOG 7
-
-/* 48 MHz SYSCLK clock frequency */
-#ifdef VARIANT_KUKUI_EC_STM32L431
-#define CPU_CLOCK 80000000
-#else
-#define CPU_CLOCK 48000000
-#endif
-
-#undef CONFIG_HIBERNATE
-#define CONFIG_SPI_CONTROLLER
-#define CONFIG_STM_HWTIMER32
-#define CONFIG_WATCHDOG_HELP
-#undef CONFIG_UART_CONSOLE
-#define CONFIG_UART_CONSOLE 1
-#define CONFIG_UART_RX_DMA
-
-/* This option is limited to TCPMv1 */
-#define CONFIG_USB_PD_MAX_SINGLE_SOURCE_CURRENT TYPEC_RP_3A0
-/* STM32F098 based boards use TCPMv1 */
-#define CONFIG_USB_PD_TCPMV1
-#define CONFIG_USB_PD_VBUS_DETECT_TCPC
-
-/* Modules we want to exclude */
-#undef CONFIG_CMD_BATTFAKE
-#undef CONFIG_CMD_FLASH
-#undef CONFIG_CMD_FLASHINFO
-#undef CONFIG_CMD_HASH
-#undef CONFIG_CMD_MD
-#undef CONFIG_CMD_POWERINDEBUG
-#undef CONFIG_CMD_TIMERINFO
-
-/* save space at RO image */
-#ifdef SECTION_IS_RO
-#undef CONFIG_CMD_ADC
-#undef CONFIG_CMD_APTHROTTLE
-#undef CONFIG_CMD_CRASH
-#undef CONFIG_CMD_HCDEBUG
-#undef CONFIG_CMD_IDLE_STATS
-#undef CONFIG_CMD_MFALLOW
-#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_CMD_TYPEC
-#undef CONFIG_HOSTCMD_FLASHPD
-#undef CONFIG_HOSTCMD_RWHASHPD
-#undef CONFIG_CONSOLE_CMDHELP
-
-#undef CONFIG_HOSTCMD_GET_UPTIME_INFO
-#undef CONFIG_CMD_AP_RESET_LOG
-#undef CONFIG_CMD_I2C_SCAN
-#undef CONFIG_CMD_I2C_XFER
-
-/* free flash space */
-#undef CONFIG_USB_PD_DEBUG_LEVEL
-#define CONFIG_USB_PD_DEBUG_LEVEL 0
-#undef CONFIG_USB_PD_LOGGING
-#define CONFIG_COMMON_GPIO_SHORTNAMES
-#define CONFIG_DEBUG_ASSERT_BRIEF
-/* Exclude PD state names from RO image to save space */
-#undef CONFIG_USB_PD_TCPMV1_DEBUG
-#endif
-#elif defined(VARIANT_KUKUI_EC_IT81202)
-#define CONFIG_IT83XX_HARD_RESET_BY_GPG1
-#define CONFIG_IT83XX_VCC_1P8V
-
-/* IT81202 based boards use TCPMv2 */
-#define CONFIG_USB_DRP_ACC_TRYSRC
-#define CONFIG_USB_PD_DECODE_SOP
-#define CONFIG_USB_PD_ITE_ACTIVE_PORT_COUNT 1
-#define CONFIG_USB_PD_TCPMV2
-#else
-#error "Must define a VARIANT_KUKUI_EC_XXX!"
-#endif
-
-#ifndef __ASSEMBLER__
-#ifdef VARIANT_KUKUI_DP_MUX_GPIO
-void board_set_dp_mux_control(int output_enable, int polarity);
-#endif /* VARIANT_KUKUI_DP_MUX_GPIO */
-
-/* If POGO pin is providing power. */
-int kukui_pogo_extpower_present(void);
-
-#endif /* !__ASSEMBLER__ */
-
-#endif /* __CROS_EC_BASEBOARD_H */
diff --git a/baseboard/kukui/battery_bq27541.c b/baseboard/kukui/battery_bq27541.c
deleted file mode 100644
index 94f46b3326..0000000000
--- a/baseboard/kukui/battery_bq27541.c
+++ /dev/null
@@ -1,225 +0,0 @@
-/* Copyright 2020 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 "charge_state.h"
-#include "charger_mt6370.h"
-#include "console.h"
-#include "driver/tcpm/mt6370.h"
-#include "ec_commands.h"
-#include "util.h"
-
-#define TEMP_OUT_OF_RANGE TEMP_ZONE_COUNT
-
-#define BATT_ID 0
-
-#define BATTERY_CPT_CHARGE_MIN_TEMP 0
-#define BATTERY_CPT_CHARGE_MAX_TEMP 50
-
-#define CHARGER_LIMIT_TIMEOUT_HOURS 48
-#define CHARGER_LIMIT_TIMEOUT_HOURS_TEMP 2
-
-#define BAT_LEVEL_PD_LIMIT 85
-
-#define CPRINTS(format, args...) cprints(CC_CHARGER, format, ## args)
-
-enum battery_type {
- BATTERY_CPT = 0,
- BATTERY_COUNT
-};
-
-static const struct battery_info info[] = {
- [BATTERY_CPT] = {
- .voltage_max = 4400,
- .voltage_normal = 3850,
- .voltage_min = 3000,
- .precharge_voltage = 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,
- },
-};
-
-const struct battery_info *battery_get_info(void)
-{
- return &info[BATT_ID];
-}
-
-int charger_profile_override(struct charge_state_data *curr)
-{
- static timestamp_t deadline_48;
- static timestamp_t deadline_2;
- int cycle_count = 0, rv, val;
- unsigned char rcv = 0, rcv_cycle = 0, rcv_soh = 0;
- /* (FullCharge Capacity / Design Capacity) * 100 = SOH */
- int full_cap = 0, design_cap = 0, soh = 0;
- /* 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_3, /* t3 < bat_temp_c <= t4 */
- 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_CPT] = {
- /* TEMP_ZONE_0 */
- {BATTERY_CPT_CHARGE_MIN_TEMP * 10, 150, 1408, 4370},
- /* TEMP_ZONE_1 */
- {150, 430, 3520, 4370},
- /* TEMP_ZONE_2 */
- {430, 450, 2112, 4320},
- /* TEMP_ZONE_3 */
- {450, BATTERY_CPT_CHARGE_MAX_TEMP * 10, 1760, 4170},
- },
- };
- 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;
- }
- }
-
- switch (temp_zone) {
- case TEMP_ZONE_0:
- case TEMP_ZONE_1:
- case TEMP_ZONE_2:
- case TEMP_ZONE_3:
- 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;
- }
-
- /* Check cycle count to decrease charging voltage. */
- rv = battery_cycle_count(&val);
- if (!rv)
- cycle_count = val;
- if (cycle_count > 20 && cycle_count <= 50)
- rcv_cycle = 50;
- else if (cycle_count > 50 && cycle_count <= 300)
- rcv_cycle = 65;
- else if (cycle_count > 300 && cycle_count <= 600)
- rcv_cycle = 80;
- else if (cycle_count > 600 && cycle_count <= 1000)
- rcv_cycle = 100;
- else if (cycle_count > 1000)
- rcv_cycle = 150;
- /* Check SOH to decrease charging voltage. */
- if (!battery_full_charge_capacity(&full_cap) &&
- !battery_design_capacity(&design_cap))
- soh = ((full_cap * 100) / design_cap);
- if (soh > 70 && soh <= 75)
- rcv_soh = 50;
- else if (soh > 60 && soh <= 70)
- rcv_soh = 65;
- else if (soh > 55 && soh <= 60)
- rcv_soh = 80;
- else if (soh > 50 && soh <= 55)
- rcv_soh = 100;
- else if (soh <= 50)
- rcv_soh = 150;
- rcv = MAX(rcv_cycle, rcv_soh);
- curr->requested_voltage -= rcv;
-
- /* Should not keep charging voltage > 4250mV for 48hrs. */
- if ((curr->state == ST_DISCHARGE) ||
- curr->chg.voltage < 4250) {
- deadline_48.val = 0;
- /* Starting count 48hours */
- } else if (curr->state == ST_CHARGE ||
- curr->state == ST_PRECHARGE) {
- if (deadline_48.val == 0)
- deadline_48.val = get_time().val +
- CHARGER_LIMIT_TIMEOUT_HOURS * HOUR;
- /* If charging voltage keep > 4250 for 48hrs,
- * set charging voltage = 4250
- */
- else if (timestamp_expired(deadline_48, NULL))
- curr->requested_voltage = 4250;
- }
- /* Should not keeep battery voltage > 4100mV and
- * battery temperature > 45C for two hour
- */
- if (curr->state == ST_DISCHARGE ||
- curr->batt.voltage < 4100 ||
- bat_temp_c < 450) {
- deadline_2.val = 0;
- } else if (curr->state == ST_CHARGE ||
- curr->state == ST_PRECHARGE) {
- if (deadline_2.val == 0)
- deadline_2.val = get_time().val +
- CHARGER_LIMIT_TIMEOUT_HOURS_TEMP * HOUR;
- else if (timestamp_expired(deadline_2, NULL)) {
- /* Set discharge and charging voltage = 4100mV */
- if (curr->batt.voltage >= 4100) {
- curr->requested_current = 0;
- curr->requested_voltage = 4100;
- }
- }
- }
-
-#ifdef VARIANT_KUKUI_CHARGER_MT6370
- mt6370_charger_profile_override(curr);
-#endif /* CONFIG_CHARGER_MT6370 */
-
- return 0;
-}
-
-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;
-}
-
-int get_battery_manufacturer_name(char *dest, int size)
-{
- static const char * const name[] = {
- [BATTERY_CPT] = "AS1XXXD3Ka",
- };
- ASSERT(dest);
- strzcpy(dest, name[BATT_ID], size);
- return EC_SUCCESS;
-}
diff --git a/baseboard/kukui/battery_max17055.c b/baseboard/kukui/battery_max17055.c
deleted file mode 100644
index 6247f665aa..0000000000
--- a/baseboard/kukui/battery_max17055.c
+++ /dev/null
@@ -1,188 +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 "charge_state.h"
-#include "charger_mt6370.h"
-#include "console.h"
-#include "driver/battery/max17055.h"
-#include "ec_commands.h"
-#include "util.h"
-
-#define TEMP_OUT_OF_RANGE TEMP_ZONE_COUNT
-
-#define BATT_ID 0
-
-#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_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,
- },
-};
-
-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];
-}
-
-const struct battery_info *battery_get_info(void)
-{
- return &info[BATT_ID];
-}
-
-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)
-{
- /* 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_3, /* t3 < bat_temp_c <= t4 */
- 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] = {
- /* Add a empty range here to avoid TEMP_ZONE_COUNT mismatch. */
- /* TEMP_ZONE_0 */
- {BATTERY_SIMPLO_CHARGE_MIN_TEMP * 10,
- BATTERY_SIMPLO_CHARGE_MIN_TEMP * 10, 1772, 4376},
- /* TEMP_ZONE_1 */
- {BATTERY_SIMPLO_CHARGE_MIN_TEMP * 10, 150, 1772, 4376},
- /* TEMP_ZONE_2 */
- {150, 450, 4020, 4376},
- /* TEMP_ZONE_3 */
- {450, BATTERY_SIMPLO_CHARGE_MAX_TEMP * 10, 3350, 4300},
- },
- };
- BUILD_ASSERT(ARRAY_SIZE(temp_zones[BATT_ID]) == 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:
- case TEMP_ZONE_3:
- 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;
- }
-
-#ifdef VARIANT_KUKUI_CHARGER_MT6370
- mt6370_charger_profile_override(curr);
-#endif /* CONFIG_CHARGER_MT6370 */
-
- return 0;
-}
-
-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;
-}
-
-int get_battery_manufacturer_name(char *dest, int size)
-{
- static const char * const name[] = {
- [BATTERY_SIMPLO] = "SIMPLO",
- };
- ASSERT(dest);
- strzcpy(dest, name[BATT_ID], size);
- return EC_SUCCESS;
-}
-
diff --git a/baseboard/kukui/battery_mm8013.c b/baseboard/kukui/battery_mm8013.c
deleted file mode 100644
index e7f422e561..0000000000
--- a/baseboard/kukui/battery_mm8013.c
+++ /dev/null
@@ -1,141 +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 "charge_state.h"
-#include "charger_mt6370.h"
-#include "console.h"
-#include "driver/tcpm/mt6370.h"
-#include "ec_commands.h"
-#include "util.h"
-
-#define TEMP_OUT_OF_RANGE TEMP_ZONE_COUNT
-
-#define BATT_ID 0
-
-#define BATTERY_SCUD_CHARGE_MIN_TEMP 0
-#define BATTERY_SCUD_CHARGE_MAX_TEMP 50
-
-#define BAT_LEVEL_PD_LIMIT 85
-
-#define CPRINTS(format, args...) cprints(CC_CHARGER, format, ## args)
-
-enum battery_type {
- BATTERY_SCUD = 0,
- BATTERY_COUNT
-};
-
-static const struct battery_info info[] = {
- [BATTERY_SCUD] = {
- .voltage_max = 4400,
- .voltage_normal = 3850,
- .voltage_min = 3000,
- .precharge_voltage = 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 = 59,
- },
-};
-
-const struct battery_info *battery_get_info(void)
-{
- return &info[BATT_ID];
-}
-
-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)
-{
- /* 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_SCUD] = {
- /* TEMP_ZONE_0 */
- {BATTERY_SCUD_CHARGE_MIN_TEMP * 10, 150, 1400, 4400},
- /* TEMP_ZONE_1 */
- {150, 450, 3500, 4400},
- /* TEMP_ZONE_2 */
- {450, BATTERY_SCUD_CHARGE_MAX_TEMP * 10, 3500, 4200},
- },
- };
- 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;
- }
- }
-
- 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;
- }
-
-#ifdef VARIANT_KUKUI_CHARGER_MT6370
- mt6370_charger_profile_override(curr);
-#endif /* CONFIG_CHARGER_MT6370 */
-
- return 0;
-}
-
-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/baseboard/kukui/battery_smart.c b/baseboard/kukui/battery_smart.c
deleted file mode 100644
index ba2af17443..0000000000
--- a/baseboard/kukui/battery_smart.c
+++ /dev/null
@@ -1,138 +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.
- *
- * Battery pack vendor provided charging profile
- */
-
-#include "battery.h"
-#include "battery_fuel_gauge.h"
-#include "battery_smart.h"
-#include "timer.h"
-#include "util.h"
-
-enum battery_present batt_pres_prev = BP_NOT_SURE;
-
-/*
- * Physical detection of battery.
- */
-static enum battery_present battery_check_present_status(void)
-{
- enum battery_present batt_pres = BP_NOT_SURE;
-
-#ifdef CONFIG_BATTERY_HW_PRESENT_CUSTOM
- /* Get the physical hardware status */
- batt_pres = battery_hw_present();
-#endif
-
- /*
- * If the battery is not physically connected, then no need to perform
- * any more checks.
- */
- if (batt_pres == BP_NO)
- return batt_pres;
-
- /*
- * If the battery is present now and was present last time we checked,
- * return early.
- */
- if (batt_pres == batt_pres_prev)
- return batt_pres;
-
- /*
- * Check battery disconnect status. If we are unable to read battery
- * disconnect status, then return BP_NOT_SURE. Battery could be in ship
- * mode and might require pre-charge current to wake it up. BP_NO is not
- * returned here because charger state machine will not provide
- * pre-charge current assuming that battery is not present.
- */
- if (battery_get_disconnect_state() == BATTERY_DISCONNECT_ERROR)
- return BP_NOT_SURE;
-
- /* Ensure the battery is not in cutoff state */
- if (battery_is_cut_off() != BATTERY_CUTOFF_STATE_NORMAL)
- return BP_NO;
-
- return batt_pres;
-}
-
-enum battery_present battery_is_present(void)
-{
- batt_pres_prev = battery_check_present_status();
- return batt_pres_prev;
-}
-
-#ifdef CONFIG_I2C_BITBANG
-static void fix_single_param(int flag, int *cached, int *curr)
-{
- if (flag)
- *curr = *cached;
- else
- *cached = *curr;
-}
-
-#define CACHE_INVALIDATION_TIME_US (5 * SECOND)
-
-/*
- * b:144195782: bitbang fails randomly, and there's no way to
- * notify kernel side that bitbang read failed.
- * Thus, if any value in batt_params is bad, replace it with a cached
- * good value, to make sure we never send random numbers to kernel
- * side.
- */
-__override void board_battery_compensate_params(struct batt_params *batt)
-{
- static struct batt_params batt_cache = { 0 };
- static timestamp_t deadline;
-
- /*
- * If battery keeps failing for 5 seconds, stop hiding the error and
- * report back to host.
- */
- if (batt->flags & BATT_FLAG_BAD_ANY) {
- if (timestamp_expired(deadline, NULL))
- return;
- } else {
- deadline.val = get_time().val + CACHE_INVALIDATION_TIME_US;
- }
-
- /* return cached values for at most CACHE_INVALIDATION_TIME_US */
- fix_single_param(batt->flags & BATT_FLAG_BAD_STATE_OF_CHARGE,
- &batt_cache.state_of_charge,
- &batt->state_of_charge);
- fix_single_param(batt->flags & BATT_FLAG_BAD_VOLTAGE,
- &batt_cache.voltage,
- &batt->voltage);
- fix_single_param(batt->flags & BATT_FLAG_BAD_CURRENT,
- &batt_cache.current,
- &batt->current);
- fix_single_param(batt->flags & BATT_FLAG_BAD_DESIRED_VOLTAGE,
- &batt_cache.desired_voltage,
- &batt->desired_voltage);
- fix_single_param(batt->flags & BATT_FLAG_BAD_DESIRED_CURRENT,
- &batt_cache.desired_current,
- &batt->desired_current);
- fix_single_param(batt->flags & BATT_FLAG_BAD_REMAINING_CAPACITY,
- &batt_cache.remaining_capacity,
- &batt->remaining_capacity);
- fix_single_param(batt->flags & BATT_FLAG_BAD_FULL_CAPACITY,
- &batt_cache.full_capacity,
- &batt->full_capacity);
- fix_single_param(batt->flags & BATT_FLAG_BAD_STATUS,
- &batt_cache.status,
- &batt->status);
- fix_single_param(batt->flags & BATT_FLAG_BAD_TEMPERATURE,
- &batt_cache.temperature,
- &batt->temperature);
- /*
- * If battery_compensate_params() didn't calculate display_charge
- * for us, also update it with last good value.
- */
- fix_single_param(batt->display_charge == 0,
- &batt_cache.display_charge,
- &batt->display_charge);
-
- /* remove bad flags after applying cached values */
- batt->flags &= ~BATT_FLAG_BAD_ANY;
-}
-#endif /* CONFIG_I2C_BITBANG */
diff --git a/baseboard/kukui/build.mk b/baseboard/kukui/build.mk
deleted file mode 100644
index c64f6978c8..0000000000
--- a/baseboard/kukui/build.mk
+++ /dev/null
@@ -1,28 +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
-#
-
-# Select eMMC CMD0 driver.
-EMMC_CMD0_DRIVER=$(if $(CHIP_IT83XX),emmc_ite.o,emmc.o)
-
-baseboard-y=baseboard.o
-baseboard-$(CONFIG_USB_POWER_DELIVERY)+=usb_pd_policy.o
-baseboard-$(CONFIG_BOOTBLOCK)+=$(EMMC_CMD0_DRIVER)
-
-baseboard-$(VARIANT_KUKUI_BATTERY_MAX17055)+=battery_max17055.o
-baseboard-$(VARIANT_KUKUI_BATTERY_MM8013)+=battery_mm8013.o
-baseboard-$(VARIANT_KUKUI_BATTERY_BQ27541)+=battery_bq27541.o
-baseboard-$(VARIANT_KUKUI_BATTERY_SMART)+=battery_smart.o
-
-baseboard-$(VARIANT_KUKUI_CHARGER_MT6370)+=charger_mt6370.o
-
-baseboard-$(VARIANT_KUKUI_POGO_KEYBOARD)+=base_detect_kukui.o
-
-$(out)/RO/baseboard/$(BASEBOARD)/$(EMMC_CMD0_DRIVER): $(out)/bootblock_data.h
-
-# bootblock size from 12769.0
-DEFAULT_BOOTBLOCK_SIZE:=21504
diff --git a/baseboard/kukui/charger_mt6370.c b/baseboard/kukui/charger_mt6370.c
deleted file mode 100644
index 327b567db6..0000000000
--- a/baseboard/kukui/charger_mt6370.c
+++ /dev/null
@@ -1,366 +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.
- */
-
-#include "charge_manager.h"
-#include "charge_state_v2.h"
-#include "charger_mt6370.h"
-#include "console.h"
-#include "driver/charger/rt946x.h"
-#include "driver/tcpm/mt6370.h"
-#include "hooks.h"
-#include "power.h"
-#include "timer.h"
-#include "usb_common.h"
-#include "usb_pd.h"
-#include "util.h"
-
-#define BAT_LEVEL_PD_LIMIT 85
-#define SYSTEM_PLT_MW 3500
-/*
- * b/143318064: Prefer a voltage above 5V to force it picks a voltage
- * above 5V at first. If PREFER_MV is 5V, when desired power is around
- * 15W ~ 11W, it would pick 5V/3A initially, and mt6370 can only sink
- * around 10W, and cause a low charging efficiency.
- */
-#define PREVENT_CURRENT_DROP_MV 6000
-#define DEFAULT_PREFER_MV 5000
-/*
- * We empirically chose 300mA as the limit for when buck inefficiency is
- * noticeable.
- */
-#define STABLE_CURRENT_DELTA 300
-
-struct pd_pref_config_t pd_pref_config = {
- .mv = PREVENT_CURRENT_DROP_MV,
- .cv = 70,
- .plt_mw = SYSTEM_PLT_MW,
- .type = PD_PREFER_BUCK,
-};
-
-static void update_plt_suspend(void)
-{
- pd_pref_config.plt_mw = 0;
-}
-DECLARE_HOOK(HOOK_CHIPSET_SUSPEND, update_plt_suspend, HOOK_PRIO_DEFAULT);
-
-static void update_plt_resume(void)
-{
- pd_pref_config.plt_mw = SYSTEM_PLT_MW;
-}
-DECLARE_HOOK(HOOK_CHIPSET_RESUME, update_plt_resume, HOOK_PRIO_DEFAULT);
-
-#define CPRINTS(format, args...) cprints(CC_CHARGER, format, ## args)
-
-/* wait time to evaluate charger thermal status */
-static timestamp_t thermal_wait_until;
-/* input current bound when charger throttled */
-static int throttled_ma = PD_MAX_CURRENT_MA;
-/* charge_ma in last board_set_charge_limit call */
-static int prev_charge_limit;
-/* charge_mv in last board_set_charge_limit call */
-static int prev_charge_mv;
-
-#ifndef CONFIG_BATTERY_SMART
-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;
-}
-#endif
-
-static void board_set_charge_limit_throttle(int charge_ma, int charge_mv)
-{
- charge_set_input_current_limit(
- MIN(throttled_ma, MAX(charge_ma, CONFIG_CHARGER_INPUT_CURRENT)),
- charge_mv);
-}
-
-static void battery_thermal_control(struct charge_state_data *curr)
-{
- int input_current, jc_temp;
- static int skip_reset;
- /*
- * mt6370's input current setting is 50mA step, use 50 as well for
- * easy value mapping.
- */
- const int k_p = 50;
-
- if (charge_manager_get_charger_voltage() == 5000 ||
- curr->state != ST_CHARGE) {
- /* We already set the charge limit, do not reset it again. */
- if (skip_reset)
- return;
- skip_reset = 1;
- thermal_wait_until.val = 0;
- throttled_ma = PD_MAX_CURRENT_MA;
- board_set_charge_limit_throttle(prev_charge_limit,
- prev_charge_mv);
- return;
- }
-
- skip_reset = 0;
-
- if (thermal_wait_until.val == 0)
- goto thermal_exit;
-
- if (get_time().val < thermal_wait_until.val)
- return;
-
- /* If we fail to read adc, skip for this cycle. */
- if (rt946x_get_adc(MT6370_ADC_TEMP_JC, &jc_temp))
- return;
-
- /* If we fail to read input curr limit, skip for this cycle. */
- if (charger_get_input_current_limit(CHARGER_SOLO, &input_current))
- return;
-
- /*
- * If input current limit is maximum, and we are under thermal budget,
- * just skip.
- */
- if (input_current == PD_MAX_CURRENT_MA &&
- jc_temp < thermal_bound.target + thermal_bound.err)
- return;
-
- /* If the temp is within +- err, thermal is under control */
- if (jc_temp < thermal_bound.target + thermal_bound.err &&
- jc_temp > thermal_bound.target - thermal_bound.err)
- return;
-
- /*
- * PID algorithm (https://en.wikipedia.org/wiki/PID_controller),
- * and operates on only P value.
- */
- throttled_ma = MIN(
- PD_MAX_CURRENT_MA,
- /*
- * Should not pass the previously set input current by
- * charger manager. This value might be related the charger's
- * capability.
- */
- MIN(prev_charge_limit,
- input_current + k_p * (thermal_bound.target - jc_temp)));
-
- /* If the input current doesn't change, just skip. */
- if (throttled_ma != input_current)
- board_set_charge_limit_throttle(throttled_ma, prev_charge_mv);
-
-thermal_exit:
- thermal_wait_until.val = get_time().val + (3 * SECOND);
-}
-
-int command_jc(int argc, char **argv)
-{
- static int prev_jc_temp;
- int jc_temp;
-
- if (rt946x_get_adc(MT6370_ADC_TEMP_JC, &jc_temp))
- jc_temp = prev_jc_temp;
-
- ccprintf("JC Temp: %d\n", jc_temp);
- prev_jc_temp = jc_temp;
- return EC_SUCCESS;
-}
-DECLARE_CONSOLE_COMMAND(jc, command_jc, "", "mt6370 junction temp");
-
-/*
- * b/143318064: A workwround for mt6370 bad buck efficiency.
- * If the delta of VBUS and VBAT(on krane, desired voltage 4.4V) is too small
- * (i.e. < 500mV), the buck throughput will be bounded, and causing that we
- * can't drain 5V/3A when battery SoC above around 40%.
- * This function watches battery current. If we see battery current drops after
- * switching from high voltage to 5V (This will happen if we enable
- * CONFIG_USB_PD_PREFER_MV and set prefer votage to 5V), the charger will lost
- * power due to the inefficiency (e.g. switch from 9V/1.67A = 15W to 5V/3A,
- * but mt6370 would only sink less than 5V/2.4A = 12W), and we will request a
- * higher voltage PDO to prevent a slow charging time.
- */
-static void battery_desired_curr_dynamic(struct charge_state_data *curr)
-{
- static int prev_stable_current = CHARGE_CURRENT_UNINITIALIZED;
- static int prev_supply_voltage;
- int supply_voltage;
- int stable_current;
- int delta_current;
-
- if (curr->state != ST_CHARGE) {
- prev_supply_voltage = 0;
- prev_stable_current = CHARGE_CURRENT_UNINITIALIZED;
- /*
- * Always force higher voltage on first PD negotiation.
- * When desired power is around 15W ~ 11W, PD would pick
- * 5V/3A initially, but mt6370 can't drain that much, and
- * causes a low charging efficiency.
- */
- pd_pref_config.mv = PREVENT_CURRENT_DROP_MV;
- return;
- }
-
- supply_voltage = charge_manager_get_charger_voltage();
- stable_current = charge_get_stable_current();
-
- if (!charge_is_current_stable())
- return;
-
- if (!prev_supply_voltage)
- goto update_charge;
-
- delta_current = prev_stable_current - stable_current;
- if (curr->batt.state_of_charge >= pd_pref_config.cv &&
- supply_voltage == DEFAULT_PREFER_MV &&
- prev_supply_voltage > supply_voltage &&
- delta_current > STABLE_CURRENT_DELTA) {
- /* Raise perfer voltage above 5000mV */
- pd_pref_config.mv = PREVENT_CURRENT_DROP_MV;
- /*
- * Delay stable current evaluation for 5 mins if we see a
- * current drop. It's a reasonable waiting time since that
- * the battery desired current can't catch the gap that fast
- * in the period.
- */
- charge_reset_stable_current_us(5 * MINUTE);
- /* Rewrite the stable current to re-evalute desired watt */
- charge_set_stable_current(prev_stable_current);
-
- /*
- * do not alter current by thermal if we just raising PD
- * voltage
- */
- thermal_wait_until.val = get_time().val + (10 * SECOND);
- } else {
- pd_pref_config.mv = DEFAULT_PREFER_MV;
- /*
- * If the power supply is plugged while battery full,
- * the stable_current will always be 0 such that we are unable
- * to switch to 5V. We force evaluating PDO to switch to 5V.
- */
- if (prev_supply_voltage == supply_voltage && !stable_current &&
- !prev_stable_current &&
- supply_voltage != DEFAULT_PREFER_MV &&
- charge_manager_get_supplier() == CHARGE_SUPPLIER_PD)
- pd_set_new_power_request(
- charge_manager_get_active_charge_port());
- }
-
-update_charge:
- prev_supply_voltage = supply_voltage;
- prev_stable_current = stable_current;
-}
-
-#ifdef CONFIG_BATTERY_SMART
-static void charge_enable_eoc_and_te(void)
-{
- rt946x_enable_charge_eoc(1);
- rt946x_enable_charge_termination(1);
-}
-DECLARE_DEFERRED(charge_enable_eoc_and_te);
-#endif
-
-void mt6370_charger_profile_override(struct charge_state_data *curr)
-{
- static int previous_chg_limit_mv;
- int chg_limit_mv = pd_get_max_voltage();
-
- battery_desired_curr_dynamic(curr);
-
- battery_thermal_control(curr);
-
-#ifdef CONFIG_BATTERY_SMART
- /*
- * SMP battery uses HW pre-charge circuit and pre-charge current is
- * limited to ~50mA. Once the charge current is lower than IEOC level
- * within CHG_TEDG_EOC, and TE is enabled, the charging power path will
- * be turned off. Disable EOC and TE when battery stays over discharge
- * state, otherwise enable EOC and TE.
- */
- if (!(curr->batt.flags & BATT_FLAG_BAD_VOLTAGE)) {
- const struct battery_info *batt_info = battery_get_info();
- static int normal_charge_lock, over_discharge_lock;
-
- if (curr->batt.voltage < batt_info->voltage_min) {
- normal_charge_lock = 0;
-
- if (!over_discharge_lock && curr->state == ST_CHARGE) {
- over_discharge_lock = 1;
- rt946x_enable_charge_eoc(0);
- rt946x_enable_charge_termination(0);
- }
- } else {
- over_discharge_lock = 0;
-
- if (!normal_charge_lock) {
- normal_charge_lock = 1;
- /*
- * b/148045048: When the battery is activated
- * in shutdown mode, the adapter cannot boot
- * DUT automatically. It's a workaround to
- * delay 4.5 second to enable charger EOC
- * and TE function.
- */
- hook_call_deferred(
- &charge_enable_eoc_and_te_data,
- (4.5 * SECOND));
- }
- }
- }
-#endif
-
- /* 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 && power_get_state() != POWER_S0)
- chg_limit_mv = 5500;
- 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.
- *
- * Enable this hack on on-board gauge only (b/142097561)
- */
- if (IS_ENABLED(CONFIG_BATTERY_MAX17055) && rt946x_is_charge_done()) {
- curr->batt.state_of_charge = MAX(BATTERY_LEVEL_NEAR_FULL,
- curr->batt.state_of_charge);
- }
-
-}
-
-#ifndef CONFIG_BATTERY_SMART
-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);
-#endif
-
-void board_set_charge_limit(int port, int supplier, int charge_ma,
- int max_ma, int charge_mv)
-{
- prev_charge_limit = charge_ma;
- prev_charge_mv = charge_mv;
- board_set_charge_limit_throttle(charge_ma, charge_mv);
-}
diff --git a/baseboard/kukui/charger_mt6370.h b/baseboard/kukui/charger_mt6370.h
deleted file mode 100644
index 880b00a1a8..0000000000
--- a/baseboard/kukui/charger_mt6370.h
+++ /dev/null
@@ -1,21 +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.
- */
-
-#ifndef __CROS_EC_BASEBOARD_CHARGER_MT6370_H
-#define __CROS_EC_BASEBOARD_CHARGER_MT6370_H
-
-#include "charge_state.h"
-
-void mt6370_charger_profile_override(struct charge_state_data *curr);
-
-struct mt6370_thermal_bound {
- /* mt6370 junction's thermal target in Celsius degree */
- int target;
- /* mt6370 junction's thermal evaluation error in Celsius degree */
- int err;
-};
-
-extern struct mt6370_thermal_bound thermal_bound;
-#endif
diff --git a/baseboard/kukui/emmc.c b/baseboard/kukui/emmc.c
deleted file mode 100644
index 68953d8923..0000000000
--- a/baseboard/kukui/emmc.c
+++ /dev/null
@@ -1,400 +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
-#ifdef CHIP_FAMILY_STM32L4
- /* Reset SPI */
- STM32_RCC_APB1RSTR1 |= STM32_RCC_PB1_SPI2;
- STM32_RCC_APB1RSTR1 &= ~STM32_RCC_PB1_SPI2;
-
- /* Enable clocks to SPI module */
- STM32_RCC_APB1ENR1 |= STM32_RCC_PB1_SPI2;
-#else
- /* 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;
-#endif
-#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/baseboard/kukui/emmc_ite.c b/baseboard/kukui/emmc_ite.c
deleted file mode 100644
index 8c3e63064c..0000000000
--- a/baseboard/kukui/emmc_ite.c
+++ /dev/null
@@ -1,205 +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 "chipset.h"
-#include "console.h"
-#include "endian.h"
-#include "gpio.h"
-#include "hooks.h"
-#include "hwtimer.h"
-#include "intc.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)
-
-enum emmc_cmd {
- EMMC_ERROR = -1,
- EMMC_IDLE = 0,
- EMMC_PRE_IDLE,
- EMMC_BOOT,
-};
-
-static void emmc_reset_spi_tx(void)
-{
- /* Reset TX FIFO and count monitor */
- IT83XX_SPI_TXFCR = IT83XX_SPI_TXFR | IT83XX_SPI_TXFCMR;
- /* Send idle state (high/0xff) if master clocks in data. */
- IT83XX_SPI_FCR = 0;
-}
-
-static void emmc_reset_spi_rx(void)
-{
- /* End Rx FIFO access */
- IT83XX_SPI_TXRXFAR = 0;
- /* Reset RX FIFO and count monitor */
- IT83XX_SPI_FCR = IT83XX_SPI_RXFR | IT83XX_SPI_RXFCMR;
-}
-
-/*
- * Set SPI module work as eMMC Alternative Boot Mode.
- * (CS# pin isn't required, and dropping data until CMD goes low)
- */
-static void emmc_enable_spi(void)
-{
- /* Set SPI pin mux to eMMC (GPM2:CLK, GPM3:CMD, GPM6:DATA0) */
- IT83XX_GCTRL_PIN_MUX0 |= BIT(7);
- /* Enable eMMC Alternative Boot Mode */
- IT83XX_SPI_EMMCBMR |= IT83XX_SPI_EMMCABM;
- /* Reset TX and RX FIFO */
- emmc_reset_spi_tx();
- emmc_reset_spi_rx();
- /* Response idle state (high) */
- IT83XX_SPI_SPISRDR = 0xff;
- /* FIFO will be overwritten once it's full */
- IT83XX_SPI_GCR2 = 0;
- /* Write to clear pending interrupt bits */
- IT83XX_SPI_ISR = 0xff;
- IT83XX_SPI_RX_VLISR = IT83XX_SPI_RVLI;
- /* Enable RX fifo full interrupt */
- IT83XX_SPI_IMR = 0xff;
- IT83XX_SPI_RX_VLISMR |= IT83XX_SPI_RVLIM;
- IT83XX_SPI_IMR &= ~IT83XX_SPI_RX_FIFO_FULL;
- /*
- * Enable interrupt to detect AP's BOOTBLOCK_EN_L. So EC is able to
- * switch SPI module back to communication mode once BOOTBLOCK_EN_L
- * goes high (AP Jumped to bootloader).
- */
- gpio_clear_pending_interrupt(GPIO_BOOTBLOCK_EN_L);
- gpio_enable_interrupt(GPIO_BOOTBLOCK_EN_L);
-
- disable_sleep(SLEEP_MASK_EMMC);
- CPRINTS("eMMC emulation enabled");
-}
-DECLARE_HOOK(HOOK_CHIPSET_STARTUP, emmc_enable_spi, HOOK_PRIO_FIRST);
-
-static void emmc_init_spi(void)
-{
- /* Enable alternate function */
- gpio_config_module(MODULE_SPI_FLASH, 1);
-}
-DECLARE_HOOK(HOOK_INIT, emmc_init_spi, HOOK_PRIO_INIT_SPI + 1);
-
-static void emmc_send_data_over_spi(uint8_t *tx, int tx_size, int rst_tx)
-{
- int i;
-
- /* Reset TX FIFO and count monitor */
- if (rst_tx)
- IT83XX_SPI_TXFCR = IT83XX_SPI_TXFR | IT83XX_SPI_TXFCMR;
- /* CPU access TX FIFO1 and FIFO2 */
- IT83XX_SPI_TXRXFAR = IT83XX_SPI_CPUTFA;
-
- /* Write response data to TX FIFO */
- for (i = 0; i < tx_size; i += 4)
- IT83XX_SPI_CPUWTFDB0 = *(uint32_t *)(tx + i);
- /*
- * After writing data to TX FIFO is finished, this bit will
- * be to indicate the SPI slave controller.
- */
- IT83XX_SPI_TXFCR = IT83XX_SPI_TXFS;
- /* End CPU access TX FIFO */
- IT83XX_SPI_TXRXFAR = 0;
- /* SPI module access TX FIFO */
- IT83XX_SPI_FCR = IT83XX_SPI_SPISRTXF;
-}
-
-static void emmc_bootblock_transfer(void)
-{
- int tx_size, sent = 0, remaining = sizeof(bootblock_raw_data);
- uint8_t *raw = (uint8_t *)bootblock_raw_data;
- const uint32_t timeout_us = 200;
- uint32_t start;
-
- /*
- * HW will transmit the data of FIFO1 or FIFO2 in turn.
- * So when a FIFO is empty, we need to fill the FIFO out
- * immediately.
- */
- emmc_send_data_over_spi(&raw[sent], 256, 1);
- sent += 256;
-
- while (sent < remaining) {
- /* Wait for FIFO1 or FIFO2 have been transmitted */
- start = __hw_clock_source_read();
- while (!(IT83XX_SPI_TXFSR & BIT(0)) &&
- (__hw_clock_source_read() - start < timeout_us))
- ;
- /* Abort an ongoing transfer due to a command is received. */
- if (IT83XX_SPI_ISR & IT83XX_SPI_RX_FIFO_FULL)
- break;
- /* fill out next 128 bytes to FIFO1 or FIFO2 */
- tx_size = (remaining - sent) < 128 ? (remaining - sent) : 128;
- emmc_send_data_over_spi(&raw[sent], tx_size, 0);
- sent += tx_size;
- }
-}
-
-static enum emmc_cmd emmc_parse_command(int index, uint32_t *cmd0)
-{
- int32_t shift0;
- uint32_t data[3];
-
- data[0] = htobe32(cmd0[index]);
- data[1] = htobe32(cmd0[index+1]);
- data[2] = htobe32(cmd0[index+2]);
-
- if ((data[0] & 0xff000000) != 0x40000000) {
- /* 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;
-}
-
-void spi_emmc_cmd0_isr(uint32_t *cmd0_payload)
-{
- enum emmc_cmd cmd;
-
- for (int i = 0; i < 8; i++) {
- if (cmd0_payload[i] == 0xffffffff)
- continue;
-
- cmd = emmc_parse_command(i, &cmd0_payload[i]);
-
- if (cmd == EMMC_IDLE || cmd == EMMC_PRE_IDLE) {
- /* Abort an ongoing transfer. */
- emmc_reset_spi_tx();
- break;
- }
-
- if (cmd == EMMC_BOOT) {
- emmc_bootblock_transfer();
- break;
- }
- }
-}
diff --git a/baseboard/kukui/usb_pd_policy.c b/baseboard/kukui/usb_pd_policy.c
deleted file mode 100644
index 28ef005ee8..0000000000
--- a/baseboard/kukui/usb_pd_policy.c
+++ /dev/null
@@ -1,298 +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 "charge_manager.h"
-#include "charge_state_v2.h"
-#include "charger.h"
-#include "console.h"
-#include "gpio.h"
-#include "hooks.h"
-#include "system.h"
-#include "timer.h"
-#include "usb_mux.h"
-#include "usb_pd.h"
-#include "usb_pd_policy.h"
-#include "util.h"
-
-#define CPRINTF(format, args...) cprintf(CC_USBPD, format, ## args)
-#define CPRINTS(format, args...) cprints(CC_USBPD, format, ## args)
-
-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 !polarity_rm_dts(pd_get_polarity(port));
-
- return polarity_rm_dts(pd_get_polarity(port));
-}
-
-static uint8_t vbus_en;
-
-#define VBUS_EN_SYSJUMP_TAG 0x5645 /* VE */
-#define VBUS_EN_HOOK_VERSION 1
-
-static void vbus_en_preserve_state(void)
-{
- system_add_jump_tag(VBUS_EN_SYSJUMP_TAG, VBUS_EN_HOOK_VERSION,
- sizeof(vbus_en), &vbus_en);
-}
-DECLARE_HOOK(HOOK_SYSJUMP, vbus_en_preserve_state, HOOK_PRIO_DEFAULT);
-
-static void vbus_en_restore_state(void)
-{
- const uint8_t *prev_vbus_en;
- int size, version;
-
- prev_vbus_en = (const uint8_t *)system_get_jump_tag(
- VBUS_EN_SYSJUMP_TAG, &version, &size);
-
- if (prev_vbus_en && version == VBUS_EN_HOOK_VERSION &&
- size == sizeof(*prev_vbus_en)) {
- memcpy(&vbus_en, prev_vbus_en, sizeof(vbus_en));
- }
-}
-DECLARE_HOOK(HOOK_INIT, vbus_en_restore_state, HOOK_PRIO_DEFAULT);
-
-int board_vbus_source_enabled(int port)
-{
- return vbus_en;
-}
-
-int board_is_sourcing_vbus(int port)
-{
- if (IS_ENABLED(BOARD_KUKUI) && 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;
-
-#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) */
-
- if (IS_ENABLED(VARIANT_KUKUI_CHARGER_ISL9238))
- charge_set_output_current_limit(CHARGER_SOLO, 3300, 5000);
- else
- charger_enable_otg_power(CHARGER_SOLO, 1);
-
- gpio_set_level(GPIO_EN_USBC_CHARGE_L, 1);
- gpio_set_level(GPIO_EN_PP5000_USBC, 1);
- if (IS_ENABLED(CONFIG_CHARGER_OTG) && IS_ENABLED(CONFIG_CHARGER_ISL9238C))
- charger_set_current(CHARGER_SOLO, 0);
-
- /* 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);
-
-#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) */
-
- if (IS_ENABLED(VARIANT_KUKUI_CHARGER_ISL9238))
- charge_set_output_current_limit(CHARGER_SOLO, 0, 0);
- else
- charger_enable_otg_power(CHARGER_SOLO, 0);
-
- gpio_set_level(GPIO_EN_PP5000_USBC, 0);
-
- /* notify host of power info change */
- pd_send_host_event(PD_EVENT_POWER_CHANGE);
-}
-
-int pd_check_vconn_swap(int port)
-{
- /* always allow vconn swap, since PSYS sources VCONN */
- return 1;
-}
-
-/* ----------------- Vendor Defined Messages ------------------ */
-#ifdef CONFIG_USB_PD_ALT_MODE_DFP
-__overridable int board_has_virtual_mux(void)
-{
- return IS_ENABLED(CONFIG_USB_MUX_VIRTUAL);
-}
-
-static void board_usb_mux_set(int port, mux_state_t mux_mode,
- enum usb_switch usb_mode, int polarity)
-{
- usb_mux_set(port, mux_mode, usb_mode, polarity);
-
- if (!board_has_virtual_mux())
- /* b:149181702: Inform AP of DP status */
- host_set_single_event(EC_HOST_EVENT_USB_MUX);
-}
-
-__override void svdm_safe_dp_mode(int port)
-{
- /* make DP interface safe until configure */
- dp_flags[port] = 0;
- dp_status[port] = 0;
- board_usb_mux_set(port, USB_PD_MUX_NONE, USB_SWITCH_CONNECT,
- board_get_polarity(port));
-}
-
-__override int svdm_enter_dp_mode(int port, uint32_t mode_caps)
-{
- /* Kukui/Krane doesn't support superspeed lanes. */
- const uint32_t support_pin_mode = board_has_virtual_mux() ?
- (MODE_DP_PIN_C | MODE_DP_PIN_E) : MODE_DP_PIN_ALL;
-
- /**
- * Only enter mode if device is DFP_D (and PIN_C/E for Kukui/Krane)
- * capable
- */
- if ((mode_caps & MODE_DP_SNK) &&
- (mode_caps & ((support_pin_mode << MODE_DP_DFP_PIN_SHIFT) |
- (support_pin_mode << MODE_DP_UFP_PIN_SHIFT)))) {
- svdm_safe_dp_mode(port);
- return 0;
- }
-
- CPRINTS("ERR:DP mode SNK or C&E missing! 0x%x", mode_caps);
- return -1;
-}
-
-__override int svdm_dp_config(int port, uint32_t *payload)
-{
- int opos = pd_alt_mode(port, TCPCI_MSG_SOP, USB_SID_DISPLAYPORT);
- int status = dp_status[port];
- int mf_pref = PD_VDO_DPSTS_MF_PREF(dp_status[port]);
- int pin_mode;
-
- /* Kukui doesn't support multi-function mode, mask it out. */
- if (board_has_virtual_mux())
- status &= ~PD_VDO_DPSTS_MF_MASK;
-
- pin_mode = pd_dfp_dp_get_pin_mode(port, status);
-
- if (!pin_mode)
- return 0;
-
- if (board_has_virtual_mux())
- board_usb_mux_set(port, USB_PD_MUX_DP_ENABLED,
- USB_SWITCH_CONNECT, board_get_polarity(port));
- else
- board_usb_mux_set(
- port, mf_pref ? USB_PD_MUX_DOCK : USB_PD_MUX_DP_ENABLED,
- 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;
-};
-
-__override void svdm_dp_post_config(int 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);
-#ifdef VARIANT_KUKUI_DP_MUX_GPIO
- board_set_dp_mux_control(1, board_get_polarity(port));
-#endif
-
- /* set the minimum time delay (2ms) for the next HPD IRQ */
- svdm_hpd_deadline[port] = get_time().val + HPD_USTREAM_DEBOUNCE_LVL;
-
- usb_mux_hpd_update(port, USB_PD_MUX_HPD_LVL |
- USB_PD_MUX_HPD_IRQ_DEASSERTED);
-}
-
-__override 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]);
- mux_state_t mux_state;
-
- 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_state = (lvl ? USB_PD_MUX_HPD_LVL : USB_PD_MUX_HPD_LVL_DEASSERTED) |
- (irq ? USB_PD_MUX_HPD_IRQ : USB_PD_MUX_HPD_IRQ_DEASSERTED);
- usb_mux_hpd_update(port, mux_state);
-
- if (irq & cur_lvl) {
- uint64_t now = get_time().val;
- /* wait for the minimum spacing between IRQ_HPD if needed */
- if (now < svdm_hpd_deadline[port])
- usleep(svdm_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);
-
-#ifdef VARIANT_KUKUI_DP_MUX_GPIO
- board_set_dp_mux_control(1, board_get_polarity(port));
-#endif
-
- /* set the minimum time delay (2ms) for the next HPD IRQ */
- svdm_hpd_deadline[port] = get_time().val +
- HPD_USTREAM_DEBOUNCE_LVL;
- } else if (irq & !lvl) {
- CPRINTF("ERR:HPD:IRQ&LOW\n");
- return 0; /* nak */
- } else {
- gpio_set_level(GPIO_USB_C0_HPD_OD, lvl);
-#ifdef VARIANT_KUKUI_DP_MUX_GPIO
- board_set_dp_mux_control(lvl, board_get_polarity(port));
-#endif
- /* set the minimum time delay (2ms) for the next HPD IRQ */
- svdm_hpd_deadline[port] = get_time().val +
- HPD_USTREAM_DEBOUNCE_LVL;
- }
-
- /* ack */
- return 1;
-}
-
-__override void svdm_exit_dp_mode(int port)
-{
- gpio_set_level(GPIO_USB_C0_HPD_OD, 0);
-#ifdef VARIANT_KUKUI_DP_MUX_GPIO
- board_set_dp_mux_control(0, 0);
-#endif
- usb_mux_hpd_update(port, USB_PD_MUX_HPD_LVL_DEASSERTED |
- USB_PD_MUX_HPD_IRQ_DEASSERTED);
-}
-#endif /* CONFIG_USB_PD_ALT_MODE_DFP */
diff --git a/baseboard/kukui/usb_pd_policy.h b/baseboard/kukui/usb_pd_policy.h
deleted file mode 100644
index 78e0213f53..0000000000
--- a/baseboard/kukui/usb_pd_policy.h
+++ /dev/null
@@ -1,13 +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.
- */
-
-#ifndef __CROS_EC_BASEBOARD_USB_PD_POLICY_H
-#define __CROS_EC_BASEBOARD_USB_PD_POLICY_H
-
-#include "common.h"
-
-__override_proto int board_has_virtual_mux(void);
-
-#endif /* __CROS_EC_BASEBOARD_USB_PD_POLICY_H */