summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEdward Hill <ecgh@chromium.org>2018-07-18 16:25:27 -0600
committerchrome-bot <chrome-bot@chromium.org>2018-07-20 05:31:38 -0700
commit5100b4c3d2059de5da41c75fc19347918eec87da (patch)
tree53193ffecdce5b9f80673744d8c89cfbf0ec34d0
parent4869d5fbdfae76563f02c413b05b05a68ed01c9c (diff)
downloadchrome-ec-stabilize-10895.56.B.tar.gz
aleena,liara: Add new grunt-family boards.stabilize-10895.Bstabilize-10895.56.Brelease-R69-10895.B
Add Aleena and Liara boards. These are initially just a copy of Careena. BUG=b:111606874,b:111607004 BRANCH=none TEST=build Change-Id: I2e2d0a375c4d0943e6c7506bcad639d45d5f1eb4 Signed-off-by: Edward Hill <ecgh@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/1142534 Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com> Reviewed-by: Jonathan Brandmeyer <jbrandmeyer@chromium.org>
-rw-r--r--board/aleena/battery.c153
-rw-r--r--board/aleena/board.c241
-rw-r--r--board/aleena/board.h43
-rw-r--r--board/aleena/build.mk15
-rw-r--r--board/aleena/ec.tasklist37
-rw-r--r--board/aleena/gpio.inc115
-rw-r--r--board/aleena/led.c153
-rw-r--r--board/liara/battery.c153
-rw-r--r--board/liara/board.c241
-rw-r--r--board/liara/board.h43
-rw-r--r--board/liara/build.mk15
-rw-r--r--board/liara/ec.tasklist37
-rw-r--r--board/liara/gpio.inc115
-rw-r--r--board/liara/led.c153
14 files changed, 1514 insertions, 0 deletions
diff --git a/board/aleena/battery.c b/board/aleena/battery.c
new file mode 100644
index 0000000000..e0cd82eb94
--- /dev/null
+++ b/board/aleena/battery.c
@@ -0,0 +1,153 @@
+/* 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_fuel_gauge.h"
+#include "common.h"
+#include "util.h"
+
+/*
+ * Battery info for all Aleena battery types. Note that the fields
+ * start_charging_min/max and charging_min/max are not used for the charger.
+ * The effective temperature limits are given by discharging_min/max_c.
+ *
+ * Fuel Gauge (FG) parameters which are used for determining if the battery
+ * is connected, the appropriate ship mode (battery cutoff) command, and the
+ * charge/discharge FETs status.
+ *
+ * Ship mode (battery cutoff) requires 2 writes to the appropriate smart battery
+ * register. For some batteries, the charge/discharge FET bits are set when
+ * charging/discharging is active, in other types, these bits set mean that
+ * charging/discharging is disabled. Therefore, in addition to the mask for
+ * these bits, a disconnect value must be specified. Note that for TI fuel
+ * gauge, the charge/discharge FET status is found in Operation Status (0x54),
+ * but a read of Manufacturer Access (0x00) will return the lower 16 bits of
+ * Operation status which contains the FET status bits.
+ *
+ * The assumption for battery types supported is that the charge/discharge FET
+ * status can be read with a sb_read() command and therefore, only the register
+ * address, mask, and disconnect value need to be provided.
+ */
+const struct board_batt_params board_battery_info[] = {
+ /* DynaPack Coslight Battery Information */
+ [BATTERY_DANAPACK_COS] = {
+ .fuel_gauge = {
+ .manuf_name = "333-2C-DA-A",
+ .ship_mode = {
+ .reg_addr = 0x00,
+ .reg_data = { 0x0010, 0x0010 },
+ },
+ .fet = {
+ .mfgacc_support = 1,
+ .reg_addr = 0x0,
+ .reg_mask = 0x6000,
+ .disconnect_val = 0x6000,
+ }
+ },
+ .batt_info = {
+ .voltage_max = 8800, /* mV */
+ .voltage_normal = 7600,
+ .voltage_min = 6000,
+ .precharge_current = 256, /* mA */
+ .start_charging_min_c = 0,
+ .start_charging_max_c = 45,
+ .charging_min_c = 0,
+ .charging_max_c = 45,
+ .discharging_min_c = 0,
+ .discharging_max_c = 60,
+ },
+ },
+
+ /* DynaPack ATL Battery Information */
+ [BATTERY_DANAPACK_ATL] = {
+ .fuel_gauge = {
+ .manuf_name = "333-27-DA-A",
+ .ship_mode = {
+ .reg_addr = 0x00,
+ .reg_data = { 0x0010, 0x0010 },
+ },
+ .fet = {
+ .mfgacc_support = 1,
+ .reg_addr = 0x0,
+ .reg_mask = 0x6000,
+ .disconnect_val = 0x6000,
+ }
+ },
+ .batt_info = {
+ .voltage_max = 8800, /* mV */
+ .voltage_normal = 7600,
+ .voltage_min = 6000,
+ .precharge_current = 256, /* mA */
+ .start_charging_min_c = 0,
+ .start_charging_max_c = 45,
+ .charging_min_c = 0,
+ .charging_max_c = 45,
+ .discharging_min_c = 0,
+ .discharging_max_c = 60,
+ },
+ },
+
+ /* DynaPack SDI Battery Information */
+ [BATTERY_DANAPACK_SDI] = {
+ .fuel_gauge = {
+ .manuf_name = "333-24-DA-A",
+ .ship_mode = {
+ .reg_addr = 0x00,
+ .reg_data = { 0x0010, 0x0010 },
+ },
+ .fet = {
+ .mfgacc_support = 1,
+ .reg_addr = 0x0,
+ .reg_mask = 0x6000,
+ .disconnect_val = 0x6000,
+ }
+ },
+ .batt_info = {
+ .voltage_max = 8800, /* mV */
+ .voltage_normal = 7600,
+ .voltage_min = 6000,
+ .precharge_current = 256, /* mA */
+ .start_charging_min_c = 0,
+ .start_charging_max_c = 45,
+ .charging_min_c = 0,
+ .charging_max_c = 45,
+ .discharging_min_c = 0,
+ .discharging_max_c = 60,
+ },
+ },
+
+ /* Samsung SDI Battery Information */
+ [BATTERY_SAMSUNG_SDI] = {
+ .fuel_gauge = {
+ .manuf_name = "333-54-DA-A",
+ .ship_mode = {
+ .reg_addr = 0x00,
+ .reg_data = { 0x0010, 0x0010 },
+ },
+ .fet = {
+ .mfgacc_support = 1,
+ .reg_addr = 0x0,
+ .reg_mask = 0x6000,
+ .disconnect_val = 0x6000,
+ }
+ },
+ .batt_info = {
+ .voltage_max = 8800, /* mV */
+ .voltage_normal = 7600,
+ .voltage_min = 6000,
+ .precharge_current = 256, /* mA */
+ .start_charging_min_c = 0,
+ .start_charging_max_c = 45,
+ .charging_min_c = 0,
+ .charging_max_c = 45,
+ .discharging_min_c = 0,
+ .discharging_max_c = 60,
+ },
+ },
+};
+BUILD_ASSERT(ARRAY_SIZE(board_battery_info) == BATTERY_TYPE_COUNT);
+
+const enum battery_type DEFAULT_BATTERY_TYPE = BATTERY_DANAPACK_COS;
diff --git a/board/aleena/board.c b/board/aleena/board.c
new file mode 100644
index 0000000000..65c9eb2d2f
--- /dev/null
+++ b/board/aleena/board.c
@@ -0,0 +1,241 @@
+/* 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.
+ */
+
+/* Aleena board-specific configuration */
+
+#include "adc.h"
+#include "adc_chip.h"
+#include "button.h"
+#include "charge_manager.h"
+#include "charge_state.h"
+#include "charge_state_v2.h"
+#include "common.h"
+#include "compile_time_macros.h"
+#include "console.h"
+#include "driver/accel_kionix.h"
+#include "driver/accel_kx022.h"
+#include "driver/accelgyro_bmi160.h"
+#include "driver/bc12/bq24392.h"
+#include "driver/led/lm3630a.h"
+#include "driver/ppc/sn5s330.h"
+#include "driver/tcpm/anx74xx.h"
+#include "driver/tcpm/ps8xxx.h"
+#include "driver/temp_sensor/sb_tsi.h"
+#include "ec_commands.h"
+#include "extpower.h"
+#include "gpio.h"
+#include "hooks.h"
+#include "i2c.h"
+#include "keyboard_scan.h"
+#include "lid_switch.h"
+#include "motion_sense.h"
+#include "power.h"
+#include "power_button.h"
+#include "pwm.h"
+#include "pwm_chip.h"
+#include "registers.h"
+#include "switch.h"
+#include "system.h"
+#include "task.h"
+#include "tcpci.h"
+#include "temp_sensor.h"
+#include "thermistor.h"
+#include "usb_mux.h"
+#include "usb_pd_tcpm.h"
+#include "usbc_ppc.h"
+#include "util.h"
+
+#define CPRINTS(format, args...) cprints(CC_USBCHARGE, format, ## args)
+#define CPRINTF(format, args...) cprintf(CC_USBCHARGE, format, ## args)
+
+static void tcpc_alert_event(enum gpio_signal signal)
+{
+ if ((signal == GPIO_USB_C0_PD_INT_ODL) &&
+ !gpio_get_level(GPIO_USB_C0_PD_RST_L))
+ return;
+
+ if ((signal == GPIO_USB_C1_PD_INT_ODL) &&
+ !gpio_get_level(GPIO_USB_C1_PD_RST_L))
+ return;
+
+#ifdef HAS_TASK_PDCMD
+ /* Exchange status with TCPCs */
+ host_command_pd_send_status(PD_CHARGE_NO_CHANGE);
+#endif
+}
+
+#ifdef CONFIG_USB_PD_TCPC_LOW_POWER
+static void anx74xx_cable_det_handler(void)
+{
+ int cable_det = gpio_get_level(GPIO_USB_C0_CABLE_DET);
+ int reset_n = gpio_get_level(GPIO_USB_C0_PD_RST_L);
+
+ /*
+ * A cable_det low->high transition was detected. If following the
+ * debounce time, cable_det is high, and reset_n is low, then ANX3429 is
+ * currently in standby mode and needs to be woken up. Set the
+ * TCPC_RESET event which will bring the ANX3429 out of standby
+ * mode. Setting this event is gated on reset_n being low because the
+ * ANX3429 will always set cable_det when transitioning to normal mode
+ * and if in normal mode, then there is no need to trigger a tcpc reset.
+ */
+ if (cable_det && !reset_n)
+ task_set_event(TASK_ID_PD_C0, PD_EVENT_TCPC_RESET, 0);
+}
+DECLARE_DEFERRED(anx74xx_cable_det_handler);
+
+void anx74xx_cable_det_interrupt(enum gpio_signal signal)
+{
+ /* debounce for 2 msec */
+ hook_call_deferred(&anx74xx_cable_det_handler_data, (2 * MSEC));
+}
+#endif
+
+static void ppc_interrupt(enum gpio_signal signal)
+{
+ int port = (signal == GPIO_USB_C0_SWCTL_INT_ODL) ? 0 : 1;
+
+ sn5s330_interrupt(port);
+}
+
+#include "gpio_list.h"
+
+/* I2C port map. */
+const struct i2c_port_t i2c_ports[] = {
+ {"power", I2C_PORT_POWER, 100, GPIO_I2C0_SCL, GPIO_I2C0_SDA},
+ {"tcpc0", I2C_PORT_TCPC0, 400, GPIO_I2C1_SCL, GPIO_I2C1_SDA},
+ {"tcpc1", I2C_PORT_TCPC1, 400, GPIO_I2C2_SCL, GPIO_I2C2_SDA},
+ {"thermal", I2C_PORT_THERMAL, 400, GPIO_I2C3_SCL, GPIO_I2C3_SDA},
+ {"sensor", I2C_PORT_SENSOR, 400, GPIO_I2C7_SCL, GPIO_I2C7_SDA},
+};
+const unsigned int i2c_ports_used = ARRAY_SIZE(i2c_ports);
+
+/* PWM channels. Must be in the exactly same order as in enum pwm_channel. */
+const struct pwm_t pwm_channels[] = {
+ [PWM_CH_KBLIGHT] = {
+ .channel = 5,
+ .flags = 0,
+ .freq = 100,
+ },
+};
+BUILD_ASSERT(ARRAY_SIZE(pwm_channels) == PWM_CH_COUNT);
+
+static void board_init(void)
+{
+ /* Enable Gyro interrupts */
+ gpio_enable_interrupt(GPIO_6AXIS_INT_L);
+}
+DECLARE_HOOK(HOOK_INIT, board_init, HOOK_PRIO_DEFAULT);
+
+void board_overcurrent_event(int port)
+{
+ enum gpio_signal signal = (port == 0) ? GPIO_USB_C0_OC_L
+ : GPIO_USB_C1_OC_L;
+
+ gpio_set_level(signal, 0);
+
+ CPRINTS("p%d: overcurrent!", port);
+}
+
+void board_tcpc_init(void)
+{
+ int port;
+
+ /* Only reset TCPC if not sysjump */
+ if (!system_jumped_to_this_image())
+ board_reset_pd_mcu();
+
+ /* Enable PPC interrupts. */
+ gpio_enable_interrupt(GPIO_USB_C0_SWCTL_INT_ODL);
+ gpio_enable_interrupt(GPIO_USB_C1_SWCTL_INT_ODL);
+
+ /* Enable TCPC interrupts. */
+ gpio_enable_interrupt(GPIO_USB_C0_PD_INT_ODL);
+ gpio_enable_interrupt(GPIO_USB_C1_PD_INT_ODL);
+
+#ifdef CONFIG_USB_PD_TCPC_LOW_POWER
+ /* Enable CABLE_DET interrupt for ANX3429 wake from standby */
+ gpio_enable_interrupt(GPIO_USB_C0_CABLE_DET);
+#endif
+ /*
+ * Initialize HPD to low; after sysjump SOC needs to see
+ * HPD pulse to enable video path
+ */
+ for (port = 0; port < CONFIG_USB_PD_PORT_COUNT; port++) {
+ const struct usb_mux *mux = &usb_muxes[port];
+
+ mux->hpd_update(port, 0, 0);
+ }
+}
+DECLARE_HOOK(HOOK_INIT, board_tcpc_init, HOOK_PRIO_INIT_I2C + 1);
+
+uint16_t tcpc_get_alert_status(void)
+{
+ uint16_t status = 0;
+
+ if (!gpio_get_level(GPIO_USB_C0_PD_INT_ODL)) {
+ if (gpio_get_level(GPIO_USB_C0_PD_RST_L))
+ status |= PD_STATUS_TCPC_ALERT_0;
+ }
+
+ if (!gpio_get_level(GPIO_USB_C1_PD_INT_ODL)) {
+ if (gpio_get_level(GPIO_USB_C1_PD_RST_L))
+ status |= PD_STATUS_TCPC_ALERT_1;
+ }
+
+ return status;
+}
+
+/**
+ * Power on (or off) a single TCPC.
+ * minimum on/off delays are included.
+ *
+ * @param port Port number of TCPC.
+ * @param mode 0: power off, 1: power on.
+ */
+void board_set_tcpc_power_mode(int port, int mode)
+{
+ if (port != USB_PD_PORT_ANX74XX)
+ return;
+
+ switch (mode) {
+ case ANX74XX_NORMAL_MODE:
+ gpio_set_level(GPIO_EN_USB_C0_TCPC_PWR, 1);
+ msleep(ANX74XX_PWR_H_RST_H_DELAY_MS);
+ gpio_set_level(GPIO_USB_C0_PD_RST_L, 1);
+ break;
+ case ANX74XX_STANDBY_MODE:
+ gpio_set_level(GPIO_USB_C0_PD_RST_L, 0);
+ msleep(ANX74XX_RST_L_PWR_L_DELAY_MS);
+ gpio_set_level(GPIO_EN_USB_C0_TCPC_PWR, 0);
+ msleep(ANX74XX_PWR_L_PWR_H_DELAY_MS);
+ break;
+ default:
+ break;
+ }
+}
+
+void board_reset_pd_mcu(void)
+{
+ /* Assert reset to TCPC1 (ps8751) */
+ gpio_set_level(GPIO_USB_C1_PD_RST_L, 0);
+
+ /* Assert reset to TCPC0 (anx3429) */
+ gpio_set_level(GPIO_USB_C0_PD_RST_L, 0);
+
+ /* TCPC1 (ps8751) requires 1ms reset down assertion */
+ msleep(MAX(1, ANX74XX_RST_L_PWR_L_DELAY_MS));
+
+ /* Deassert reset to TCPC1 */
+ gpio_set_level(GPIO_USB_C1_PD_RST_L, 1);
+ /* Disable TCPC0 power */
+ gpio_set_level(GPIO_EN_USB_C0_TCPC_PWR, 0);
+
+ /*
+ * anx3429 requires 10ms reset/power down assertion
+ */
+ msleep(ANX74XX_PWR_L_PWR_H_DELAY_MS);
+ board_set_tcpc_power_mode(USB_PD_PORT_ANX74XX, 1);
+}
diff --git a/board/aleena/board.h b/board/aleena/board.h
new file mode 100644
index 0000000000..53a404bd25
--- /dev/null
+++ b/board/aleena/board.h
@@ -0,0 +1,43 @@
+/* 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.
+ */
+
+/* Aleena board configuration */
+
+#ifndef __CROS_EC_BOARD_H
+#define __CROS_EC_BOARD_H
+
+#include "baseboard.h"
+
+/*
+ * By default, enable all console messages excepted HC, ACPI and event:
+ * The sensor stack is generating a lot of activity.
+ */
+#define CC_DEFAULT (CC_ALL & ~(CC_MASK(CC_EVENTS) | CC_MASK(CC_LPC)))
+#undef CONFIG_HOSTCMD_DEBUG_MODE
+#define CONFIG_HOSTCMD_DEBUG_MODE HCDEBUG_OFF
+
+#define CONFIG_SYSTEM_UNLOCKED /* Allow dangerous commands while in dev. */
+
+#define CONFIG_LED_COMMON
+#define CONFIG_CMD_LEDTEST
+
+#ifndef __ASSEMBLER__
+
+enum pwm_channel {
+ PWM_CH_KBLIGHT = 0,
+ PWM_CH_COUNT
+};
+
+enum battery_type {
+ BATTERY_DANAPACK_COS,
+ BATTERY_DANAPACK_ATL,
+ BATTERY_DANAPACK_SDI,
+ BATTERY_SAMSUNG_SDI,
+ BATTERY_TYPE_COUNT,
+};
+
+#endif /* !__ASSEMBLER__ */
+
+#endif /* __CROS_EC_BOARD_H */
diff --git a/board/aleena/build.mk b/board/aleena/build.mk
new file mode 100644
index 0000000000..c808e65aed
--- /dev/null
+++ b/board/aleena/build.mk
@@ -0,0 +1,15 @@
+# -*- makefile -*-
+# Copyright 2015 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.
+#
+# Board specific files build
+#
+
+CHIP:=npcx
+CHIP_FAMILY:=npcx7
+CHIP_VARIANT:=npcx7m6f
+BASEBOARD:=grunt
+
+board-y=board.o led.o
+board-$(CONFIG_BATTERY_SMART)+=battery.o
diff --git a/board/aleena/ec.tasklist b/board/aleena/ec.tasklist
new file mode 100644
index 0000000000..be1dbcc21f
--- /dev/null
+++ b/board/aleena/ec.tasklist
@@ -0,0 +1,37 @@
+/* Copyright 2017 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.
+ */
+
+/*
+ * List of enabled tasks in the priority order
+ *
+ * The first one has the lowest priority.
+ *
+ * For each task, use the macro TASK_ALWAYS(n, r, d, s) for base tasks and
+ * TASK_NOTEST(n, r, d, s) for tasks that can be excluded in test binaries,
+ * where :
+ * 'n' in the name of the task
+ * 'r' in the main routine of the task
+ * 'd' in an opaque parameter passed to the routine at startup
+ * 's' is the stack size in bytes; must be a multiple of 8
+ *
+ * For USB PD tasks, IDs must be in consecutive order and correspond to
+ * the port which they are for. See TASK_ID_TO_PD_PORT() macro.
+ */
+
+#define CONFIG_TASK_LIST \
+ TASK_ALWAYS(HOOKS, hook_task, NULL, LARGER_TASK_STACK_SIZE) \
+ TASK_ALWAYS(USB_CHG_P0, usb_charger_task, 0, TASK_STACK_SIZE) \
+ TASK_ALWAYS(USB_CHG_P1, usb_charger_task, 1, TASK_STACK_SIZE) \
+ TASK_ALWAYS(CHARGER, charger_task, NULL, LARGER_TASK_STACK_SIZE) \
+ TASK_ALWAYS(MOTIONSENSE, motion_sense_task, NULL, VENTI_TASK_STACK_SIZE) \
+ TASK_NOTEST(CHIPSET, chipset_task, NULL, LARGER_TASK_STACK_SIZE) \
+ TASK_NOTEST(KEYPROTO, keyboard_protocol_task, NULL, TASK_STACK_SIZE) \
+ TASK_NOTEST(PDCMD, pd_command_task, NULL, LARGER_TASK_STACK_SIZE) \
+ TASK_ALWAYS(HOSTCMD, host_command_task, NULL, LARGER_TASK_STACK_SIZE) \
+ TASK_ALWAYS(CONSOLE, console_task, NULL, VENTI_TASK_STACK_SIZE) \
+ TASK_ALWAYS(POWERBTN, power_button_task, NULL, LARGER_TASK_STACK_SIZE) \
+ TASK_NOTEST(KEYSCAN, keyboard_scan_task, NULL, TASK_STACK_SIZE) \
+ TASK_ALWAYS(PD_C0, pd_task, NULL, LARGER_TASK_STACK_SIZE) \
+ TASK_ALWAYS(PD_C1, pd_task, NULL, LARGER_TASK_STACK_SIZE)
diff --git a/board/aleena/gpio.inc b/board/aleena/gpio.inc
new file mode 100644
index 0000000000..344d2d6774
--- /dev/null
+++ b/board/aleena/gpio.inc
@@ -0,0 +1,115 @@
+/* -*- mode:c -*-
+ *
+ * Copyright 2017 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.
+ */
+
+/* Declare symbolic names for all the GPIOs that we care about.
+ * Note: Those with interrupt handlers must be declared first. */
+
+GPIO_INT(USB_C0_PD_INT_ODL, PIN(A, 0), GPIO_INT_FALLING, tcpc_alert_event)
+GPIO_INT(USB_C1_PD_INT_ODL, PIN(F, 5), GPIO_INT_FALLING, tcpc_alert_event)
+GPIO_INT(USB_C0_SWCTL_INT_ODL, PIN(0, 3), GPIO_INT_FALLING, ppc_interrupt)
+GPIO_INT(USB_C1_SWCTL_INT_ODL, PIN(D, 4), GPIO_INT_FALLING, ppc_interrupt)
+GPIO_INT(PCH_SLP_S3_L, PIN(A, 6), GPIO_INT_BOTH, power_signal_interrupt)
+GPIO_INT(PCH_SLP_S5_L, PIN(A, 3), GPIO_INT_BOTH, power_signal_interrupt)
+GPIO_INT(S0_PGOOD, PIN(F, 4), GPIO_INT_BOTH, power_signal_interrupt)
+GPIO_INT(S5_PGOOD, PIN(6, 3), GPIO_INT_BOTH | GPIO_PULL_UP, power_signal_interrupt)
+GPIO_INT(POWER_BUTTON_L, PIN(0, 1), GPIO_INT_BOTH, power_button_interrupt)
+GPIO_INT(LID_OPEN, PIN(D, 2), GPIO_INT_BOTH | GPIO_HIB_WAKE_HIGH | GPIO_PULL_UP, lid_interrupt)
+GPIO_INT(AC_PRESENT, PIN(0, 0), GPIO_INT_BOTH | GPIO_HIB_WAKE_HIGH, extpower_interrupt)
+GPIO_INT(WP_L, PIN(A, 1), GPIO_INT_BOTH, switch_interrupt)
+GPIO_INT(VOLUME_DOWN_L, PIN(7, 0), GPIO_INT_BOTH | GPIO_PULL_UP, button_interrupt)
+GPIO_INT(VOLUME_UP_L, PIN(7, 5), GPIO_INT_BOTH | GPIO_PULL_UP, button_interrupt)
+GPIO_INT(USB_C0_CABLE_DET, PIN(3, 7), GPIO_INT_RISING, anx74xx_cable_det_interrupt)
+GPIO_INT(6AXIS_INT_L, PIN(8, 6), GPIO_INT_FALLING | GPIO_SEL_1P8V, bmi160_interrupt)
+
+GPIO(EN_PWR_A, PIN(E, 2), GPIO_OUT_LOW) /* Enable Power */
+GPIO(EN_PP1800_SENSOR, PIN(6, 7), GPIO_OUT_LOW) /* Enable Power */
+GPIO(ENABLE_BACKLIGHT_L, PIN(D, 3), GPIO_OUT_HIGH) /* Enable Backlight */
+GPIO(PCH_RSMRST_L, PIN(C, 2), GPIO_OUT_LOW) /* RSMRST# to SOC */
+GPIO(PCH_PWRBTN_L, PIN(C, 1), GPIO_OUT_HIGH) /* Power Button to SOC */
+GPIO(PCH_WAKE_L, PIN(7, 4), GPIO_OUT_HIGH) /* Wake SOC */
+GPIO(SYS_RESET_L, PIN(3, 5), GPIO_ODR_HIGH) /* Cold Reset to SOC */
+GPIO(CCD_MODE_ODL, PIN(E, 3), GPIO_INPUT) /* Case Closed Debug Mode */
+GPIO(ENTERING_RW, PIN(E, 1), GPIO_OUT_LOW) /* EC Entering RW */
+GPIO(EC_BATT_PRES_L, PIN(E, 5), GPIO_INPUT | GPIO_PULL_UP) /* Battery Present */
+GPIO(PCH_SYS_PWROK, PIN(D, 6), GPIO_OUT_LOW) /* Power OK to SOC */
+GPIO(EC_APU_RST, PIN(E, 4), GPIO_INPUT) /* Reset to SOC */
+GPIO(CPU_PROCHOT, PIN(3, 4), GPIO_INPUT | GPIO_SEL_1P8V) /* PROCHOT to SOC */
+GPIO(APU_ALERT_L, PIN(A, 2), GPIO_INPUT) /* Alert to SOC */
+GPIO(3AXIS_INT_L, PIN(5, 0), GPIO_INPUT | GPIO_SEL_1P8V) /* 3 Axis Accel */
+
+/* We don't have 5V rail control but the BQ24392 driver expects the GPIO */
+UNIMPLEMENTED(EN_PP5000)
+
+GPIO(BAT_LED_AMBER_L, PIN(C, 3), GPIO_OUT_HIGH)
+GPIO(BAT_LED_WHITE_L, PIN(C, 4), GPIO_OUT_HIGH)
+
+/* I2C pins - these will be reconfigured for alternate function below */
+GPIO(I2C0_SCL, PIN(B, 5), GPIO_INPUT) /* EC_I2C_POWER_SCL */
+GPIO(I2C0_SDA, PIN(B, 4), GPIO_INPUT) /* EC_I2C_POWER_SDA */
+GPIO(I2C1_SCL, PIN(9, 0), GPIO_INPUT) /* EC_I2C_USB_C0_PD_SCL */
+GPIO(I2C1_SDA, PIN(8, 7), GPIO_INPUT) /* EC_I2C_USB_C0_PD_SDA */
+GPIO(I2C2_SCL, PIN(9, 2), GPIO_INPUT) /* EC_I2C_USB_C1_PD_SCL */
+GPIO(I2C2_SDA, PIN(9, 1), GPIO_INPUT) /* EC_I2C_USB_C1_PD_SDA */
+GPIO(I2C3_SCL, PIN(D, 1), GPIO_INPUT | GPIO_SEL_1P8V) /* APU_SIC */
+GPIO(I2C3_SDA, PIN(D, 0), GPIO_INPUT | GPIO_SEL_1P8V) /* APU_SID */
+GPIO(I2C7_SCL, PIN(B, 3), GPIO_INPUT | GPIO_SEL_1P8V) /* EC_I2C_SENSOR_SCL */
+GPIO(I2C7_SDA, PIN(B, 2), GPIO_INPUT | GPIO_SEL_1P8V) /* EC_I2C_SENSOR_SDA */
+
+/*
+ * The NPCX LPC driver configures and controls SCI and SMI,
+ * so PCH_SCI_ODL [PIN(7, 6)] and PCH_SMI_ODL [PIN(C, 6)] are
+ * not defined here as GPIOs.
+ */
+GPIO(PCH_SLP_S0_L, PIN(A, 4), GPIO_INPUT)
+
+GPIO(EN_USB_A0_5V, PIN(6, 1), GPIO_OUT_LOW) /* Enable A0 5V Charging */
+GPIO(EN_USB_A1_5V, PIN(C, 0), GPIO_OUT_LOW) /* Enable A1 5V Charging */
+GPIO(EN_USB_C0_TCPC_PWR, PIN(6, 0), GPIO_OUT_LOW) /* Enable C0 TCPC Power */
+GPIO(USB_C0_OC_L, PIN(7, 3), GPIO_OUT_HIGH) /* C0 Over Current */
+GPIO(USB_C1_OC_L, PIN(7, 2), GPIO_OUT_HIGH) /* C1 Over Current */
+GPIO(USB_C0_PD_RST_L, PIN(3, 2), GPIO_OUT_HIGH) /* C0 PD Reset */
+GPIO(USB_C1_PD_RST_L, PIN(D, 5), GPIO_OUT_HIGH) /* C1 PD Reset */
+GPIO(USB_C0_BC12_VBUS_ON_L, PIN(4, 0), GPIO_ODR_HIGH) /* C0 BC1.2 Power */
+GPIO(USB_C1_BC12_VBUS_ON_L, PIN(B, 1), GPIO_ODR_HIGH) /* C1 BC1.2 Power */
+GPIO(USB_C0_BC12_CHG_DET, PIN(6, 2), GPIO_INPUT) /* C0 BC1.2 Detect */
+GPIO(USB_C1_BC12_CHG_DET, PIN(8, 3), GPIO_INPUT) /* C1 BC1.2 Detect */
+GPIO(USB_C0_DP_HPD, PIN(9, 5), GPIO_OUT_LOW) /* C0 DP Hotplug Detect */
+GPIO(USB_C1_DP_HPD, PIN(9, 6), GPIO_OUT_LOW) /* C1 DP Hotplug Detect */
+
+/* Board ID */
+GPIO(BOARD_VERSION1, PIN(C, 7), GPIO_INPUT)
+GPIO(BOARD_VERSION2, PIN(9, 3), GPIO_INPUT)
+GPIO(BOARD_VERSION3, PIN(8, 0), GPIO_INPUT)
+GPIO(SKU_ID1, PIN(F, 0), GPIO_INPUT)
+GPIO(SKU_ID2, PIN(4, 1), GPIO_INPUT)
+
+/* Alternate functions GPIO definitions */
+/* Cr50 requires no pull-ups on UART pins. */
+ALTERNATE(PIN_MASK(6, 0x30), 0, MODULE_UART, 0) /* UART from EC to Servo */
+ALTERNATE(PIN_MASK(B, 0x30), 0, MODULE_I2C, 0) /* I2C0 */
+ALTERNATE(PIN_MASK(9, 0x07), 0, MODULE_I2C, 0) /* I2C1 SCL / I2C2 */
+ALTERNATE(PIN_MASK(8, 0x80), 0, MODULE_I2C, 0) /* I2C1 SDA */
+ALTERNATE(PIN_MASK(D, 0x03), 0, MODULE_I2C, 0) /* I2C3 */
+ALTERNATE(PIN_MASK(3, 0x48), 0, MODULE_I2C, 0) /* I2C5 */
+ALTERNATE(PIN_MASK(B, 0x0C), 0, MODULE_I2C, 0) /* I2C7 */
+ALTERNATE(PIN_MASK(4, 0x30), 0, MODULE_ADC, 0) /* ADC0-1 */
+ALTERNATE(PIN_MASK(4, 0x02), 0, MODULE_ADC, 0) /* ADC4 */
+ALTERNATE(PIN_MASK(F, 0x02), 0, MODULE_ADC, 0) /* ADC8 */
+ALTERNATE(PIN_MASK(F, 0x01), 0, MODULE_ADC, 0) /* ADC9 */
+ALTERNATE(PIN_MASK(B, 0x80), 0, MODULE_PWM, 0) /* KB Backlight */
+
+/* Keyboard Pins */
+ALTERNATE(PIN_MASK(3, 0x03), 0, MODULE_KEYBOARD_SCAN, GPIO_INPUT) /* KSI_00-01 */
+ALTERNATE(PIN_MASK(2, 0xFC), 0, MODULE_KEYBOARD_SCAN, GPIO_INPUT) /* KSI_02-07 */
+ALTERNATE(PIN_MASK(2, 0x03), 0, MODULE_KEYBOARD_SCAN, GPIO_ODR_HIGH) /* KSO_00-01 */
+GPIO(KBD_KSO2, PIN(1, 7), GPIO_OUT_LOW) /* KSO_02 inverted */
+ALTERNATE(PIN_MASK(1, 0x7F), 0, MODULE_KEYBOARD_SCAN, GPIO_ODR_HIGH) /* KSO_03-09 */
+ALTERNATE(PIN_MASK(0, 0xE0), 0, MODULE_KEYBOARD_SCAN, GPIO_ODR_HIGH) /* KSO_10-12 */
+
+/* Power Switch Logic (PSL) inputs */
+ALTERNATE(PIN_MASK(0, 0x03), 0, MODULE_PMU, 0) /* GPIO00, GPIO01 */
+ALTERNATE(PIN_MASK(D, 0x04), 0, MODULE_PMU, 0) /* GPIOD2 */
diff --git a/board/aleena/led.c b/board/aleena/led.c
new file mode 100644
index 0000000000..1b9c043043
--- /dev/null
+++ b/board/aleena/led.c
@@ -0,0 +1,153 @@
+/* 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.
+ *
+ * LED control for Aleena
+ */
+
+#include "battery.h"
+#include "charge_state.h"
+#include "chipset.h"
+#include "ec_commands.h"
+#include "extpower.h"
+#include "gpio.h"
+#include "hooks.h"
+#include "host_command.h"
+#include "led_common.h"
+#include "util.h"
+#include "system.h"
+
+#define BAT_LED_ON 0
+#define BAT_LED_OFF 1
+
+const enum ec_led_id supported_led_ids[] = {EC_LED_ID_BATTERY_LED};
+
+const int supported_led_ids_count = ARRAY_SIZE(supported_led_ids);
+
+enum led_color {
+ LED_OFF = 0,
+ LED_AMBER,
+ LED_WHITE,
+ LED_COLOR_COUNT /* Number of colors, not a color itself */
+};
+
+static int led_set_color_battery(enum led_color color)
+{
+ switch (color) {
+ case LED_OFF:
+ gpio_set_level(GPIO_BAT_LED_WHITE_L, BAT_LED_OFF);
+ gpio_set_level(GPIO_BAT_LED_AMBER_L, BAT_LED_OFF);
+ break;
+ case LED_WHITE:
+ gpio_set_level(GPIO_BAT_LED_WHITE_L, BAT_LED_ON);
+ gpio_set_level(GPIO_BAT_LED_AMBER_L, BAT_LED_OFF);
+ break;
+ case LED_AMBER:
+ gpio_set_level(GPIO_BAT_LED_WHITE_L, BAT_LED_OFF);
+ gpio_set_level(GPIO_BAT_LED_AMBER_L, BAT_LED_ON);
+ break;
+ default:
+ return EC_ERROR_UNKNOWN;
+ }
+ return EC_SUCCESS;
+}
+
+void led_get_brightness_range(enum ec_led_id led_id, uint8_t *brightness_range)
+{
+ brightness_range[EC_LED_COLOR_WHITE] = 1;
+ brightness_range[EC_LED_COLOR_AMBER] = 1;
+}
+
+static int led_set_color(enum ec_led_id led_id, enum led_color color)
+{
+ int rv;
+
+ switch (led_id) {
+ case EC_LED_ID_BATTERY_LED:
+ rv = led_set_color_battery(color);
+ break;
+ default:
+ return EC_ERROR_UNKNOWN;
+ }
+ return rv;
+}
+
+int led_set_brightness(enum ec_led_id led_id, const uint8_t *brightness)
+{
+ if (brightness[EC_LED_COLOR_WHITE] != 0)
+ led_set_color(led_id, LED_WHITE);
+ else if (brightness[EC_LED_COLOR_AMBER] != 0)
+ led_set_color(led_id, LED_AMBER);
+ else
+ led_set_color(led_id, LED_OFF);
+
+ return EC_SUCCESS;
+}
+
+static void led_set_battery(void)
+{
+ static int battery_ticks;
+ static int power_ticks;
+ uint32_t chflags = charge_get_flags();
+
+ battery_ticks++;
+
+ /* override battery led for system suspend */
+ if (chipset_in_state(CHIPSET_STATE_SUSPEND |
+ CHIPSET_STATE_STANDBY) &&
+ charge_get_state() != PWR_STATE_CHARGE) {
+ led_set_color_battery(power_ticks++ & 0x4 ?
+ LED_WHITE : LED_OFF);
+ return;
+ }
+
+ power_ticks = 0;
+
+ switch (charge_get_state()) {
+ case PWR_STATE_CHARGE:
+ led_set_color_battery(LED_AMBER);
+ break;
+ case PWR_STATE_DISCHARGE_FULL:
+ if (extpower_is_present()) {
+ led_set_color_battery(LED_WHITE);
+ break;
+ }
+ /* Intentional fall-through */
+ case PWR_STATE_DISCHARGE:
+ /*
+ * Blink white light (1 sec on, 1 sec off)
+ * when battery capacity is less than 10%
+ */
+ if (charge_get_percent() < 10)
+ led_set_color_battery(
+ (battery_ticks & 0x4) ? LED_WHITE : LED_OFF);
+ else
+ led_set_color_battery(LED_OFF);
+ break;
+ case PWR_STATE_ERROR:
+ led_set_color_battery(
+ (battery_ticks & 0x2) ? LED_WHITE : LED_OFF);
+ break;
+ case PWR_STATE_CHARGE_NEAR_FULL:
+ led_set_color_battery(LED_WHITE);
+ break;
+ case PWR_STATE_IDLE: /* External power connected in IDLE */
+ if (chflags & CHARGE_FLAG_FORCE_IDLE)
+ led_set_color_battery(
+ (battery_ticks & 0x4) ? LED_AMBER : LED_OFF);
+ else
+ led_set_color_battery(LED_WHITE);
+ break;
+ default:
+ /* Other states don't alter LED behavior */
+ break;
+ }
+}
+
+/* Called by hook task every TICK */
+static void led_tick(void)
+{
+ if (led_auto_control_is_enabled(EC_LED_ID_BATTERY_LED))
+ led_set_battery();
+}
+DECLARE_HOOK(HOOK_TICK, led_tick, HOOK_PRIO_DEFAULT);
diff --git a/board/liara/battery.c b/board/liara/battery.c
new file mode 100644
index 0000000000..6b0c24ca96
--- /dev/null
+++ b/board/liara/battery.c
@@ -0,0 +1,153 @@
+/* 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_fuel_gauge.h"
+#include "common.h"
+#include "util.h"
+
+/*
+ * Battery info for all Liara battery types. Note that the fields
+ * start_charging_min/max and charging_min/max are not used for the charger.
+ * The effective temperature limits are given by discharging_min/max_c.
+ *
+ * Fuel Gauge (FG) parameters which are used for determining if the battery
+ * is connected, the appropriate ship mode (battery cutoff) command, and the
+ * charge/discharge FETs status.
+ *
+ * Ship mode (battery cutoff) requires 2 writes to the appropriate smart battery
+ * register. For some batteries, the charge/discharge FET bits are set when
+ * charging/discharging is active, in other types, these bits set mean that
+ * charging/discharging is disabled. Therefore, in addition to the mask for
+ * these bits, a disconnect value must be specified. Note that for TI fuel
+ * gauge, the charge/discharge FET status is found in Operation Status (0x54),
+ * but a read of Manufacturer Access (0x00) will return the lower 16 bits of
+ * Operation status which contains the FET status bits.
+ *
+ * The assumption for battery types supported is that the charge/discharge FET
+ * status can be read with a sb_read() command and therefore, only the register
+ * address, mask, and disconnect value need to be provided.
+ */
+const struct board_batt_params board_battery_info[] = {
+ /* DynaPack Coslight Battery Information */
+ [BATTERY_DANAPACK_COS] = {
+ .fuel_gauge = {
+ .manuf_name = "333-2C-DA-A",
+ .ship_mode = {
+ .reg_addr = 0x00,
+ .reg_data = { 0x0010, 0x0010 },
+ },
+ .fet = {
+ .mfgacc_support = 1,
+ .reg_addr = 0x0,
+ .reg_mask = 0x6000,
+ .disconnect_val = 0x6000,
+ }
+ },
+ .batt_info = {
+ .voltage_max = 8800, /* mV */
+ .voltage_normal = 7600,
+ .voltage_min = 6000,
+ .precharge_current = 256, /* mA */
+ .start_charging_min_c = 0,
+ .start_charging_max_c = 45,
+ .charging_min_c = 0,
+ .charging_max_c = 45,
+ .discharging_min_c = 0,
+ .discharging_max_c = 60,
+ },
+ },
+
+ /* DynaPack ATL Battery Information */
+ [BATTERY_DANAPACK_ATL] = {
+ .fuel_gauge = {
+ .manuf_name = "333-27-DA-A",
+ .ship_mode = {
+ .reg_addr = 0x00,
+ .reg_data = { 0x0010, 0x0010 },
+ },
+ .fet = {
+ .mfgacc_support = 1,
+ .reg_addr = 0x0,
+ .reg_mask = 0x6000,
+ .disconnect_val = 0x6000,
+ }
+ },
+ .batt_info = {
+ .voltage_max = 8800, /* mV */
+ .voltage_normal = 7600,
+ .voltage_min = 6000,
+ .precharge_current = 256, /* mA */
+ .start_charging_min_c = 0,
+ .start_charging_max_c = 45,
+ .charging_min_c = 0,
+ .charging_max_c = 45,
+ .discharging_min_c = 0,
+ .discharging_max_c = 60,
+ },
+ },
+
+ /* DynaPack SDI Battery Information */
+ [BATTERY_DANAPACK_SDI] = {
+ .fuel_gauge = {
+ .manuf_name = "333-24-DA-A",
+ .ship_mode = {
+ .reg_addr = 0x00,
+ .reg_data = { 0x0010, 0x0010 },
+ },
+ .fet = {
+ .mfgacc_support = 1,
+ .reg_addr = 0x0,
+ .reg_mask = 0x6000,
+ .disconnect_val = 0x6000,
+ }
+ },
+ .batt_info = {
+ .voltage_max = 8800, /* mV */
+ .voltage_normal = 7600,
+ .voltage_min = 6000,
+ .precharge_current = 256, /* mA */
+ .start_charging_min_c = 0,
+ .start_charging_max_c = 45,
+ .charging_min_c = 0,
+ .charging_max_c = 45,
+ .discharging_min_c = 0,
+ .discharging_max_c = 60,
+ },
+ },
+
+ /* Samsung SDI Battery Information */
+ [BATTERY_SAMSUNG_SDI] = {
+ .fuel_gauge = {
+ .manuf_name = "333-54-DA-A",
+ .ship_mode = {
+ .reg_addr = 0x00,
+ .reg_data = { 0x0010, 0x0010 },
+ },
+ .fet = {
+ .mfgacc_support = 1,
+ .reg_addr = 0x0,
+ .reg_mask = 0x6000,
+ .disconnect_val = 0x6000,
+ }
+ },
+ .batt_info = {
+ .voltage_max = 8800, /* mV */
+ .voltage_normal = 7600,
+ .voltage_min = 6000,
+ .precharge_current = 256, /* mA */
+ .start_charging_min_c = 0,
+ .start_charging_max_c = 45,
+ .charging_min_c = 0,
+ .charging_max_c = 45,
+ .discharging_min_c = 0,
+ .discharging_max_c = 60,
+ },
+ },
+};
+BUILD_ASSERT(ARRAY_SIZE(board_battery_info) == BATTERY_TYPE_COUNT);
+
+const enum battery_type DEFAULT_BATTERY_TYPE = BATTERY_DANAPACK_COS;
diff --git a/board/liara/board.c b/board/liara/board.c
new file mode 100644
index 0000000000..3962ad6c67
--- /dev/null
+++ b/board/liara/board.c
@@ -0,0 +1,241 @@
+/* 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.
+ */
+
+/* Liara board-specific configuration */
+
+#include "adc.h"
+#include "adc_chip.h"
+#include "button.h"
+#include "charge_manager.h"
+#include "charge_state.h"
+#include "charge_state_v2.h"
+#include "common.h"
+#include "compile_time_macros.h"
+#include "console.h"
+#include "driver/accel_kionix.h"
+#include "driver/accel_kx022.h"
+#include "driver/accelgyro_bmi160.h"
+#include "driver/bc12/bq24392.h"
+#include "driver/led/lm3630a.h"
+#include "driver/ppc/sn5s330.h"
+#include "driver/tcpm/anx74xx.h"
+#include "driver/tcpm/ps8xxx.h"
+#include "driver/temp_sensor/sb_tsi.h"
+#include "ec_commands.h"
+#include "extpower.h"
+#include "gpio.h"
+#include "hooks.h"
+#include "i2c.h"
+#include "keyboard_scan.h"
+#include "lid_switch.h"
+#include "motion_sense.h"
+#include "power.h"
+#include "power_button.h"
+#include "pwm.h"
+#include "pwm_chip.h"
+#include "registers.h"
+#include "switch.h"
+#include "system.h"
+#include "task.h"
+#include "tcpci.h"
+#include "temp_sensor.h"
+#include "thermistor.h"
+#include "usb_mux.h"
+#include "usb_pd_tcpm.h"
+#include "usbc_ppc.h"
+#include "util.h"
+
+#define CPRINTS(format, args...) cprints(CC_USBCHARGE, format, ## args)
+#define CPRINTF(format, args...) cprintf(CC_USBCHARGE, format, ## args)
+
+static void tcpc_alert_event(enum gpio_signal signal)
+{
+ if ((signal == GPIO_USB_C0_PD_INT_ODL) &&
+ !gpio_get_level(GPIO_USB_C0_PD_RST_L))
+ return;
+
+ if ((signal == GPIO_USB_C1_PD_INT_ODL) &&
+ !gpio_get_level(GPIO_USB_C1_PD_RST_L))
+ return;
+
+#ifdef HAS_TASK_PDCMD
+ /* Exchange status with TCPCs */
+ host_command_pd_send_status(PD_CHARGE_NO_CHANGE);
+#endif
+}
+
+#ifdef CONFIG_USB_PD_TCPC_LOW_POWER
+static void anx74xx_cable_det_handler(void)
+{
+ int cable_det = gpio_get_level(GPIO_USB_C0_CABLE_DET);
+ int reset_n = gpio_get_level(GPIO_USB_C0_PD_RST_L);
+
+ /*
+ * A cable_det low->high transition was detected. If following the
+ * debounce time, cable_det is high, and reset_n is low, then ANX3429 is
+ * currently in standby mode and needs to be woken up. Set the
+ * TCPC_RESET event which will bring the ANX3429 out of standby
+ * mode. Setting this event is gated on reset_n being low because the
+ * ANX3429 will always set cable_det when transitioning to normal mode
+ * and if in normal mode, then there is no need to trigger a tcpc reset.
+ */
+ if (cable_det && !reset_n)
+ task_set_event(TASK_ID_PD_C0, PD_EVENT_TCPC_RESET, 0);
+}
+DECLARE_DEFERRED(anx74xx_cable_det_handler);
+
+void anx74xx_cable_det_interrupt(enum gpio_signal signal)
+{
+ /* debounce for 2 msec */
+ hook_call_deferred(&anx74xx_cable_det_handler_data, (2 * MSEC));
+}
+#endif
+
+static void ppc_interrupt(enum gpio_signal signal)
+{
+ int port = (signal == GPIO_USB_C0_SWCTL_INT_ODL) ? 0 : 1;
+
+ sn5s330_interrupt(port);
+}
+
+#include "gpio_list.h"
+
+/* I2C port map. */
+const struct i2c_port_t i2c_ports[] = {
+ {"power", I2C_PORT_POWER, 100, GPIO_I2C0_SCL, GPIO_I2C0_SDA},
+ {"tcpc0", I2C_PORT_TCPC0, 400, GPIO_I2C1_SCL, GPIO_I2C1_SDA},
+ {"tcpc1", I2C_PORT_TCPC1, 400, GPIO_I2C2_SCL, GPIO_I2C2_SDA},
+ {"thermal", I2C_PORT_THERMAL, 400, GPIO_I2C3_SCL, GPIO_I2C3_SDA},
+ {"sensor", I2C_PORT_SENSOR, 400, GPIO_I2C7_SCL, GPIO_I2C7_SDA},
+};
+const unsigned int i2c_ports_used = ARRAY_SIZE(i2c_ports);
+
+/* PWM channels. Must be in the exactly same order as in enum pwm_channel. */
+const struct pwm_t pwm_channels[] = {
+ [PWM_CH_KBLIGHT] = {
+ .channel = 5,
+ .flags = 0,
+ .freq = 100,
+ },
+};
+BUILD_ASSERT(ARRAY_SIZE(pwm_channels) == PWM_CH_COUNT);
+
+static void board_init(void)
+{
+ /* Enable Gyro interrupts */
+ gpio_enable_interrupt(GPIO_6AXIS_INT_L);
+}
+DECLARE_HOOK(HOOK_INIT, board_init, HOOK_PRIO_DEFAULT);
+
+void board_overcurrent_event(int port)
+{
+ enum gpio_signal signal = (port == 0) ? GPIO_USB_C0_OC_L
+ : GPIO_USB_C1_OC_L;
+
+ gpio_set_level(signal, 0);
+
+ CPRINTS("p%d: overcurrent!", port);
+}
+
+void board_tcpc_init(void)
+{
+ int port;
+
+ /* Only reset TCPC if not sysjump */
+ if (!system_jumped_to_this_image())
+ board_reset_pd_mcu();
+
+ /* Enable PPC interrupts. */
+ gpio_enable_interrupt(GPIO_USB_C0_SWCTL_INT_ODL);
+ gpio_enable_interrupt(GPIO_USB_C1_SWCTL_INT_ODL);
+
+ /* Enable TCPC interrupts. */
+ gpio_enable_interrupt(GPIO_USB_C0_PD_INT_ODL);
+ gpio_enable_interrupt(GPIO_USB_C1_PD_INT_ODL);
+
+#ifdef CONFIG_USB_PD_TCPC_LOW_POWER
+ /* Enable CABLE_DET interrupt for ANX3429 wake from standby */
+ gpio_enable_interrupt(GPIO_USB_C0_CABLE_DET);
+#endif
+ /*
+ * Initialize HPD to low; after sysjump SOC needs to see
+ * HPD pulse to enable video path
+ */
+ for (port = 0; port < CONFIG_USB_PD_PORT_COUNT; port++) {
+ const struct usb_mux *mux = &usb_muxes[port];
+
+ mux->hpd_update(port, 0, 0);
+ }
+}
+DECLARE_HOOK(HOOK_INIT, board_tcpc_init, HOOK_PRIO_INIT_I2C + 1);
+
+uint16_t tcpc_get_alert_status(void)
+{
+ uint16_t status = 0;
+
+ if (!gpio_get_level(GPIO_USB_C0_PD_INT_ODL)) {
+ if (gpio_get_level(GPIO_USB_C0_PD_RST_L))
+ status |= PD_STATUS_TCPC_ALERT_0;
+ }
+
+ if (!gpio_get_level(GPIO_USB_C1_PD_INT_ODL)) {
+ if (gpio_get_level(GPIO_USB_C1_PD_RST_L))
+ status |= PD_STATUS_TCPC_ALERT_1;
+ }
+
+ return status;
+}
+
+/**
+ * Power on (or off) a single TCPC.
+ * minimum on/off delays are included.
+ *
+ * @param port Port number of TCPC.
+ * @param mode 0: power off, 1: power on.
+ */
+void board_set_tcpc_power_mode(int port, int mode)
+{
+ if (port != USB_PD_PORT_ANX74XX)
+ return;
+
+ switch (mode) {
+ case ANX74XX_NORMAL_MODE:
+ gpio_set_level(GPIO_EN_USB_C0_TCPC_PWR, 1);
+ msleep(ANX74XX_PWR_H_RST_H_DELAY_MS);
+ gpio_set_level(GPIO_USB_C0_PD_RST_L, 1);
+ break;
+ case ANX74XX_STANDBY_MODE:
+ gpio_set_level(GPIO_USB_C0_PD_RST_L, 0);
+ msleep(ANX74XX_RST_L_PWR_L_DELAY_MS);
+ gpio_set_level(GPIO_EN_USB_C0_TCPC_PWR, 0);
+ msleep(ANX74XX_PWR_L_PWR_H_DELAY_MS);
+ break;
+ default:
+ break;
+ }
+}
+
+void board_reset_pd_mcu(void)
+{
+ /* Assert reset to TCPC1 (ps8751) */
+ gpio_set_level(GPIO_USB_C1_PD_RST_L, 0);
+
+ /* Assert reset to TCPC0 (anx3429) */
+ gpio_set_level(GPIO_USB_C0_PD_RST_L, 0);
+
+ /* TCPC1 (ps8751) requires 1ms reset down assertion */
+ msleep(MAX(1, ANX74XX_RST_L_PWR_L_DELAY_MS));
+
+ /* Deassert reset to TCPC1 */
+ gpio_set_level(GPIO_USB_C1_PD_RST_L, 1);
+ /* Disable TCPC0 power */
+ gpio_set_level(GPIO_EN_USB_C0_TCPC_PWR, 0);
+
+ /*
+ * anx3429 requires 10ms reset/power down assertion
+ */
+ msleep(ANX74XX_PWR_L_PWR_H_DELAY_MS);
+ board_set_tcpc_power_mode(USB_PD_PORT_ANX74XX, 1);
+}
diff --git a/board/liara/board.h b/board/liara/board.h
new file mode 100644
index 0000000000..690306a09a
--- /dev/null
+++ b/board/liara/board.h
@@ -0,0 +1,43 @@
+/* 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.
+ */
+
+/* Liara board configuration */
+
+#ifndef __CROS_EC_BOARD_H
+#define __CROS_EC_BOARD_H
+
+#include "baseboard.h"
+
+/*
+ * By default, enable all console messages excepted HC, ACPI and event:
+ * The sensor stack is generating a lot of activity.
+ */
+#define CC_DEFAULT (CC_ALL & ~(CC_MASK(CC_EVENTS) | CC_MASK(CC_LPC)))
+#undef CONFIG_HOSTCMD_DEBUG_MODE
+#define CONFIG_HOSTCMD_DEBUG_MODE HCDEBUG_OFF
+
+#define CONFIG_SYSTEM_UNLOCKED /* Allow dangerous commands while in dev. */
+
+#define CONFIG_LED_COMMON
+#define CONFIG_CMD_LEDTEST
+
+#ifndef __ASSEMBLER__
+
+enum pwm_channel {
+ PWM_CH_KBLIGHT = 0,
+ PWM_CH_COUNT
+};
+
+enum battery_type {
+ BATTERY_DANAPACK_COS,
+ BATTERY_DANAPACK_ATL,
+ BATTERY_DANAPACK_SDI,
+ BATTERY_SAMSUNG_SDI,
+ BATTERY_TYPE_COUNT,
+};
+
+#endif /* !__ASSEMBLER__ */
+
+#endif /* __CROS_EC_BOARD_H */
diff --git a/board/liara/build.mk b/board/liara/build.mk
new file mode 100644
index 0000000000..c808e65aed
--- /dev/null
+++ b/board/liara/build.mk
@@ -0,0 +1,15 @@
+# -*- makefile -*-
+# Copyright 2015 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.
+#
+# Board specific files build
+#
+
+CHIP:=npcx
+CHIP_FAMILY:=npcx7
+CHIP_VARIANT:=npcx7m6f
+BASEBOARD:=grunt
+
+board-y=board.o led.o
+board-$(CONFIG_BATTERY_SMART)+=battery.o
diff --git a/board/liara/ec.tasklist b/board/liara/ec.tasklist
new file mode 100644
index 0000000000..be1dbcc21f
--- /dev/null
+++ b/board/liara/ec.tasklist
@@ -0,0 +1,37 @@
+/* Copyright 2017 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.
+ */
+
+/*
+ * List of enabled tasks in the priority order
+ *
+ * The first one has the lowest priority.
+ *
+ * For each task, use the macro TASK_ALWAYS(n, r, d, s) for base tasks and
+ * TASK_NOTEST(n, r, d, s) for tasks that can be excluded in test binaries,
+ * where :
+ * 'n' in the name of the task
+ * 'r' in the main routine of the task
+ * 'd' in an opaque parameter passed to the routine at startup
+ * 's' is the stack size in bytes; must be a multiple of 8
+ *
+ * For USB PD tasks, IDs must be in consecutive order and correspond to
+ * the port which they are for. See TASK_ID_TO_PD_PORT() macro.
+ */
+
+#define CONFIG_TASK_LIST \
+ TASK_ALWAYS(HOOKS, hook_task, NULL, LARGER_TASK_STACK_SIZE) \
+ TASK_ALWAYS(USB_CHG_P0, usb_charger_task, 0, TASK_STACK_SIZE) \
+ TASK_ALWAYS(USB_CHG_P1, usb_charger_task, 1, TASK_STACK_SIZE) \
+ TASK_ALWAYS(CHARGER, charger_task, NULL, LARGER_TASK_STACK_SIZE) \
+ TASK_ALWAYS(MOTIONSENSE, motion_sense_task, NULL, VENTI_TASK_STACK_SIZE) \
+ TASK_NOTEST(CHIPSET, chipset_task, NULL, LARGER_TASK_STACK_SIZE) \
+ TASK_NOTEST(KEYPROTO, keyboard_protocol_task, NULL, TASK_STACK_SIZE) \
+ TASK_NOTEST(PDCMD, pd_command_task, NULL, LARGER_TASK_STACK_SIZE) \
+ TASK_ALWAYS(HOSTCMD, host_command_task, NULL, LARGER_TASK_STACK_SIZE) \
+ TASK_ALWAYS(CONSOLE, console_task, NULL, VENTI_TASK_STACK_SIZE) \
+ TASK_ALWAYS(POWERBTN, power_button_task, NULL, LARGER_TASK_STACK_SIZE) \
+ TASK_NOTEST(KEYSCAN, keyboard_scan_task, NULL, TASK_STACK_SIZE) \
+ TASK_ALWAYS(PD_C0, pd_task, NULL, LARGER_TASK_STACK_SIZE) \
+ TASK_ALWAYS(PD_C1, pd_task, NULL, LARGER_TASK_STACK_SIZE)
diff --git a/board/liara/gpio.inc b/board/liara/gpio.inc
new file mode 100644
index 0000000000..344d2d6774
--- /dev/null
+++ b/board/liara/gpio.inc
@@ -0,0 +1,115 @@
+/* -*- mode:c -*-
+ *
+ * Copyright 2017 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.
+ */
+
+/* Declare symbolic names for all the GPIOs that we care about.
+ * Note: Those with interrupt handlers must be declared first. */
+
+GPIO_INT(USB_C0_PD_INT_ODL, PIN(A, 0), GPIO_INT_FALLING, tcpc_alert_event)
+GPIO_INT(USB_C1_PD_INT_ODL, PIN(F, 5), GPIO_INT_FALLING, tcpc_alert_event)
+GPIO_INT(USB_C0_SWCTL_INT_ODL, PIN(0, 3), GPIO_INT_FALLING, ppc_interrupt)
+GPIO_INT(USB_C1_SWCTL_INT_ODL, PIN(D, 4), GPIO_INT_FALLING, ppc_interrupt)
+GPIO_INT(PCH_SLP_S3_L, PIN(A, 6), GPIO_INT_BOTH, power_signal_interrupt)
+GPIO_INT(PCH_SLP_S5_L, PIN(A, 3), GPIO_INT_BOTH, power_signal_interrupt)
+GPIO_INT(S0_PGOOD, PIN(F, 4), GPIO_INT_BOTH, power_signal_interrupt)
+GPIO_INT(S5_PGOOD, PIN(6, 3), GPIO_INT_BOTH | GPIO_PULL_UP, power_signal_interrupt)
+GPIO_INT(POWER_BUTTON_L, PIN(0, 1), GPIO_INT_BOTH, power_button_interrupt)
+GPIO_INT(LID_OPEN, PIN(D, 2), GPIO_INT_BOTH | GPIO_HIB_WAKE_HIGH | GPIO_PULL_UP, lid_interrupt)
+GPIO_INT(AC_PRESENT, PIN(0, 0), GPIO_INT_BOTH | GPIO_HIB_WAKE_HIGH, extpower_interrupt)
+GPIO_INT(WP_L, PIN(A, 1), GPIO_INT_BOTH, switch_interrupt)
+GPIO_INT(VOLUME_DOWN_L, PIN(7, 0), GPIO_INT_BOTH | GPIO_PULL_UP, button_interrupt)
+GPIO_INT(VOLUME_UP_L, PIN(7, 5), GPIO_INT_BOTH | GPIO_PULL_UP, button_interrupt)
+GPIO_INT(USB_C0_CABLE_DET, PIN(3, 7), GPIO_INT_RISING, anx74xx_cable_det_interrupt)
+GPIO_INT(6AXIS_INT_L, PIN(8, 6), GPIO_INT_FALLING | GPIO_SEL_1P8V, bmi160_interrupt)
+
+GPIO(EN_PWR_A, PIN(E, 2), GPIO_OUT_LOW) /* Enable Power */
+GPIO(EN_PP1800_SENSOR, PIN(6, 7), GPIO_OUT_LOW) /* Enable Power */
+GPIO(ENABLE_BACKLIGHT_L, PIN(D, 3), GPIO_OUT_HIGH) /* Enable Backlight */
+GPIO(PCH_RSMRST_L, PIN(C, 2), GPIO_OUT_LOW) /* RSMRST# to SOC */
+GPIO(PCH_PWRBTN_L, PIN(C, 1), GPIO_OUT_HIGH) /* Power Button to SOC */
+GPIO(PCH_WAKE_L, PIN(7, 4), GPIO_OUT_HIGH) /* Wake SOC */
+GPIO(SYS_RESET_L, PIN(3, 5), GPIO_ODR_HIGH) /* Cold Reset to SOC */
+GPIO(CCD_MODE_ODL, PIN(E, 3), GPIO_INPUT) /* Case Closed Debug Mode */
+GPIO(ENTERING_RW, PIN(E, 1), GPIO_OUT_LOW) /* EC Entering RW */
+GPIO(EC_BATT_PRES_L, PIN(E, 5), GPIO_INPUT | GPIO_PULL_UP) /* Battery Present */
+GPIO(PCH_SYS_PWROK, PIN(D, 6), GPIO_OUT_LOW) /* Power OK to SOC */
+GPIO(EC_APU_RST, PIN(E, 4), GPIO_INPUT) /* Reset to SOC */
+GPIO(CPU_PROCHOT, PIN(3, 4), GPIO_INPUT | GPIO_SEL_1P8V) /* PROCHOT to SOC */
+GPIO(APU_ALERT_L, PIN(A, 2), GPIO_INPUT) /* Alert to SOC */
+GPIO(3AXIS_INT_L, PIN(5, 0), GPIO_INPUT | GPIO_SEL_1P8V) /* 3 Axis Accel */
+
+/* We don't have 5V rail control but the BQ24392 driver expects the GPIO */
+UNIMPLEMENTED(EN_PP5000)
+
+GPIO(BAT_LED_AMBER_L, PIN(C, 3), GPIO_OUT_HIGH)
+GPIO(BAT_LED_WHITE_L, PIN(C, 4), GPIO_OUT_HIGH)
+
+/* I2C pins - these will be reconfigured for alternate function below */
+GPIO(I2C0_SCL, PIN(B, 5), GPIO_INPUT) /* EC_I2C_POWER_SCL */
+GPIO(I2C0_SDA, PIN(B, 4), GPIO_INPUT) /* EC_I2C_POWER_SDA */
+GPIO(I2C1_SCL, PIN(9, 0), GPIO_INPUT) /* EC_I2C_USB_C0_PD_SCL */
+GPIO(I2C1_SDA, PIN(8, 7), GPIO_INPUT) /* EC_I2C_USB_C0_PD_SDA */
+GPIO(I2C2_SCL, PIN(9, 2), GPIO_INPUT) /* EC_I2C_USB_C1_PD_SCL */
+GPIO(I2C2_SDA, PIN(9, 1), GPIO_INPUT) /* EC_I2C_USB_C1_PD_SDA */
+GPIO(I2C3_SCL, PIN(D, 1), GPIO_INPUT | GPIO_SEL_1P8V) /* APU_SIC */
+GPIO(I2C3_SDA, PIN(D, 0), GPIO_INPUT | GPIO_SEL_1P8V) /* APU_SID */
+GPIO(I2C7_SCL, PIN(B, 3), GPIO_INPUT | GPIO_SEL_1P8V) /* EC_I2C_SENSOR_SCL */
+GPIO(I2C7_SDA, PIN(B, 2), GPIO_INPUT | GPIO_SEL_1P8V) /* EC_I2C_SENSOR_SDA */
+
+/*
+ * The NPCX LPC driver configures and controls SCI and SMI,
+ * so PCH_SCI_ODL [PIN(7, 6)] and PCH_SMI_ODL [PIN(C, 6)] are
+ * not defined here as GPIOs.
+ */
+GPIO(PCH_SLP_S0_L, PIN(A, 4), GPIO_INPUT)
+
+GPIO(EN_USB_A0_5V, PIN(6, 1), GPIO_OUT_LOW) /* Enable A0 5V Charging */
+GPIO(EN_USB_A1_5V, PIN(C, 0), GPIO_OUT_LOW) /* Enable A1 5V Charging */
+GPIO(EN_USB_C0_TCPC_PWR, PIN(6, 0), GPIO_OUT_LOW) /* Enable C0 TCPC Power */
+GPIO(USB_C0_OC_L, PIN(7, 3), GPIO_OUT_HIGH) /* C0 Over Current */
+GPIO(USB_C1_OC_L, PIN(7, 2), GPIO_OUT_HIGH) /* C1 Over Current */
+GPIO(USB_C0_PD_RST_L, PIN(3, 2), GPIO_OUT_HIGH) /* C0 PD Reset */
+GPIO(USB_C1_PD_RST_L, PIN(D, 5), GPIO_OUT_HIGH) /* C1 PD Reset */
+GPIO(USB_C0_BC12_VBUS_ON_L, PIN(4, 0), GPIO_ODR_HIGH) /* C0 BC1.2 Power */
+GPIO(USB_C1_BC12_VBUS_ON_L, PIN(B, 1), GPIO_ODR_HIGH) /* C1 BC1.2 Power */
+GPIO(USB_C0_BC12_CHG_DET, PIN(6, 2), GPIO_INPUT) /* C0 BC1.2 Detect */
+GPIO(USB_C1_BC12_CHG_DET, PIN(8, 3), GPIO_INPUT) /* C1 BC1.2 Detect */
+GPIO(USB_C0_DP_HPD, PIN(9, 5), GPIO_OUT_LOW) /* C0 DP Hotplug Detect */
+GPIO(USB_C1_DP_HPD, PIN(9, 6), GPIO_OUT_LOW) /* C1 DP Hotplug Detect */
+
+/* Board ID */
+GPIO(BOARD_VERSION1, PIN(C, 7), GPIO_INPUT)
+GPIO(BOARD_VERSION2, PIN(9, 3), GPIO_INPUT)
+GPIO(BOARD_VERSION3, PIN(8, 0), GPIO_INPUT)
+GPIO(SKU_ID1, PIN(F, 0), GPIO_INPUT)
+GPIO(SKU_ID2, PIN(4, 1), GPIO_INPUT)
+
+/* Alternate functions GPIO definitions */
+/* Cr50 requires no pull-ups on UART pins. */
+ALTERNATE(PIN_MASK(6, 0x30), 0, MODULE_UART, 0) /* UART from EC to Servo */
+ALTERNATE(PIN_MASK(B, 0x30), 0, MODULE_I2C, 0) /* I2C0 */
+ALTERNATE(PIN_MASK(9, 0x07), 0, MODULE_I2C, 0) /* I2C1 SCL / I2C2 */
+ALTERNATE(PIN_MASK(8, 0x80), 0, MODULE_I2C, 0) /* I2C1 SDA */
+ALTERNATE(PIN_MASK(D, 0x03), 0, MODULE_I2C, 0) /* I2C3 */
+ALTERNATE(PIN_MASK(3, 0x48), 0, MODULE_I2C, 0) /* I2C5 */
+ALTERNATE(PIN_MASK(B, 0x0C), 0, MODULE_I2C, 0) /* I2C7 */
+ALTERNATE(PIN_MASK(4, 0x30), 0, MODULE_ADC, 0) /* ADC0-1 */
+ALTERNATE(PIN_MASK(4, 0x02), 0, MODULE_ADC, 0) /* ADC4 */
+ALTERNATE(PIN_MASK(F, 0x02), 0, MODULE_ADC, 0) /* ADC8 */
+ALTERNATE(PIN_MASK(F, 0x01), 0, MODULE_ADC, 0) /* ADC9 */
+ALTERNATE(PIN_MASK(B, 0x80), 0, MODULE_PWM, 0) /* KB Backlight */
+
+/* Keyboard Pins */
+ALTERNATE(PIN_MASK(3, 0x03), 0, MODULE_KEYBOARD_SCAN, GPIO_INPUT) /* KSI_00-01 */
+ALTERNATE(PIN_MASK(2, 0xFC), 0, MODULE_KEYBOARD_SCAN, GPIO_INPUT) /* KSI_02-07 */
+ALTERNATE(PIN_MASK(2, 0x03), 0, MODULE_KEYBOARD_SCAN, GPIO_ODR_HIGH) /* KSO_00-01 */
+GPIO(KBD_KSO2, PIN(1, 7), GPIO_OUT_LOW) /* KSO_02 inverted */
+ALTERNATE(PIN_MASK(1, 0x7F), 0, MODULE_KEYBOARD_SCAN, GPIO_ODR_HIGH) /* KSO_03-09 */
+ALTERNATE(PIN_MASK(0, 0xE0), 0, MODULE_KEYBOARD_SCAN, GPIO_ODR_HIGH) /* KSO_10-12 */
+
+/* Power Switch Logic (PSL) inputs */
+ALTERNATE(PIN_MASK(0, 0x03), 0, MODULE_PMU, 0) /* GPIO00, GPIO01 */
+ALTERNATE(PIN_MASK(D, 0x04), 0, MODULE_PMU, 0) /* GPIOD2 */
diff --git a/board/liara/led.c b/board/liara/led.c
new file mode 100644
index 0000000000..b5b0960647
--- /dev/null
+++ b/board/liara/led.c
@@ -0,0 +1,153 @@
+/* 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.
+ *
+ * LED control for Liara
+ */
+
+#include "battery.h"
+#include "charge_state.h"
+#include "chipset.h"
+#include "ec_commands.h"
+#include "extpower.h"
+#include "gpio.h"
+#include "hooks.h"
+#include "host_command.h"
+#include "led_common.h"
+#include "util.h"
+#include "system.h"
+
+#define BAT_LED_ON 0
+#define BAT_LED_OFF 1
+
+const enum ec_led_id supported_led_ids[] = {EC_LED_ID_BATTERY_LED};
+
+const int supported_led_ids_count = ARRAY_SIZE(supported_led_ids);
+
+enum led_color {
+ LED_OFF = 0,
+ LED_AMBER,
+ LED_WHITE,
+ LED_COLOR_COUNT /* Number of colors, not a color itself */
+};
+
+static int led_set_color_battery(enum led_color color)
+{
+ switch (color) {
+ case LED_OFF:
+ gpio_set_level(GPIO_BAT_LED_WHITE_L, BAT_LED_OFF);
+ gpio_set_level(GPIO_BAT_LED_AMBER_L, BAT_LED_OFF);
+ break;
+ case LED_WHITE:
+ gpio_set_level(GPIO_BAT_LED_WHITE_L, BAT_LED_ON);
+ gpio_set_level(GPIO_BAT_LED_AMBER_L, BAT_LED_OFF);
+ break;
+ case LED_AMBER:
+ gpio_set_level(GPIO_BAT_LED_WHITE_L, BAT_LED_OFF);
+ gpio_set_level(GPIO_BAT_LED_AMBER_L, BAT_LED_ON);
+ break;
+ default:
+ return EC_ERROR_UNKNOWN;
+ }
+ return EC_SUCCESS;
+}
+
+void led_get_brightness_range(enum ec_led_id led_id, uint8_t *brightness_range)
+{
+ brightness_range[EC_LED_COLOR_WHITE] = 1;
+ brightness_range[EC_LED_COLOR_AMBER] = 1;
+}
+
+static int led_set_color(enum ec_led_id led_id, enum led_color color)
+{
+ int rv;
+
+ switch (led_id) {
+ case EC_LED_ID_BATTERY_LED:
+ rv = led_set_color_battery(color);
+ break;
+ default:
+ return EC_ERROR_UNKNOWN;
+ }
+ return rv;
+}
+
+int led_set_brightness(enum ec_led_id led_id, const uint8_t *brightness)
+{
+ if (brightness[EC_LED_COLOR_WHITE] != 0)
+ led_set_color(led_id, LED_WHITE);
+ else if (brightness[EC_LED_COLOR_AMBER] != 0)
+ led_set_color(led_id, LED_AMBER);
+ else
+ led_set_color(led_id, LED_OFF);
+
+ return EC_SUCCESS;
+}
+
+static void led_set_battery(void)
+{
+ static int battery_ticks;
+ static int power_ticks;
+ uint32_t chflags = charge_get_flags();
+
+ battery_ticks++;
+
+ /* override battery led for system suspend */
+ if (chipset_in_state(CHIPSET_STATE_SUSPEND |
+ CHIPSET_STATE_STANDBY) &&
+ charge_get_state() != PWR_STATE_CHARGE) {
+ led_set_color_battery(power_ticks++ & 0x4 ?
+ LED_WHITE : LED_OFF);
+ return;
+ }
+
+ power_ticks = 0;
+
+ switch (charge_get_state()) {
+ case PWR_STATE_CHARGE:
+ led_set_color_battery(LED_AMBER);
+ break;
+ case PWR_STATE_DISCHARGE_FULL:
+ if (extpower_is_present()) {
+ led_set_color_battery(LED_WHITE);
+ break;
+ }
+ /* Intentional fall-through */
+ case PWR_STATE_DISCHARGE:
+ /*
+ * Blink white light (1 sec on, 1 sec off)
+ * when battery capacity is less than 10%
+ */
+ if (charge_get_percent() < 10)
+ led_set_color_battery(
+ (battery_ticks & 0x4) ? LED_WHITE : LED_OFF);
+ else
+ led_set_color_battery(LED_OFF);
+ break;
+ case PWR_STATE_ERROR:
+ led_set_color_battery(
+ (battery_ticks & 0x2) ? LED_WHITE : LED_OFF);
+ break;
+ case PWR_STATE_CHARGE_NEAR_FULL:
+ led_set_color_battery(LED_WHITE);
+ break;
+ case PWR_STATE_IDLE: /* External power connected in IDLE */
+ if (chflags & CHARGE_FLAG_FORCE_IDLE)
+ led_set_color_battery(
+ (battery_ticks & 0x4) ? LED_AMBER : LED_OFF);
+ else
+ led_set_color_battery(LED_WHITE);
+ break;
+ default:
+ /* Other states don't alter LED behavior */
+ break;
+ }
+}
+
+/* Called by hook task every TICK */
+static void led_tick(void)
+{
+ if (led_auto_control_is_enabled(EC_LED_ID_BATTERY_LED))
+ led_set_battery();
+}
+DECLARE_HOOK(HOOK_TICK, led_tick, HOOK_PRIO_DEFAULT);