mirror of
https://github.com/Telecominfraproject/OpenCellular.git
synced 2025-12-30 18:41:11 +00:00
ec: add initial nautilus board
For now use the files from poppy. To be changed later on. BUG=b:66458931 TEST=emerge-nautilus chromeos-ec/make buildall -j Change-Id: If829d7307f834f1f30878934623c0e9ee77b907d Signed-off-by: Chris Wang <chriswang@ami.corp-partner.google.com> Reviewed-on: https://chromium-review.googlesource.com/701996 Commit-Ready: Grace Kao <grace.kao@intel.com> Tested-by: Grace Kao <grace.kao@intel.com> Reviewed-by: Philip Chen <philipchen@chromium.org>
This commit is contained in:
172
board/nautilus/battery.c
Normal file
172
board/nautilus/battery.c
Normal file
@@ -0,0 +1,172 @@
|
||||
/* Copyright 2016 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.
|
||||
*
|
||||
* Placeholder values for temporary battery pack.
|
||||
*/
|
||||
|
||||
#include "battery.h"
|
||||
#include "battery_smart.h"
|
||||
#include "charge_state.h"
|
||||
#include "console.h"
|
||||
#include "ec_commands.h"
|
||||
#include "extpower.h"
|
||||
#include "gpio.h"
|
||||
#include "util.h"
|
||||
|
||||
static enum battery_present batt_pres_prev = BP_NOT_SURE;
|
||||
|
||||
/* Shutdown mode parameter to write to manufacturer access register */
|
||||
#define SB_SHIP_MODE_REG SB_MANUFACTURER_ACCESS
|
||||
#define SB_SHUTDOWN_DATA 0x0010
|
||||
|
||||
static const struct battery_info info = {
|
||||
.voltage_max = 13200,
|
||||
.voltage_normal = 11550,
|
||||
.voltage_min = 9100,
|
||||
/* Pre-charge values. */
|
||||
.precharge_current = 256, /* mA */
|
||||
|
||||
.start_charging_min_c = 0,
|
||||
.start_charging_max_c = 50,
|
||||
.charging_min_c = 0,
|
||||
.charging_max_c = 60,
|
||||
.discharging_min_c = 0,
|
||||
.discharging_max_c = 60,
|
||||
};
|
||||
|
||||
const struct battery_info *battery_get_info(void)
|
||||
{
|
||||
return &info;
|
||||
}
|
||||
|
||||
int board_cut_off_battery(void)
|
||||
{
|
||||
int rv;
|
||||
|
||||
/* Ship mode command must be sent twice to take effect */
|
||||
rv = sb_write(SB_SHIP_MODE_REG, SB_SHUTDOWN_DATA);
|
||||
|
||||
if (rv != EC_SUCCESS)
|
||||
return rv;
|
||||
|
||||
return sb_write(SB_SHIP_MODE_REG, SB_SHUTDOWN_DATA);
|
||||
}
|
||||
|
||||
int charger_profile_override(struct charge_state_data *curr)
|
||||
{
|
||||
const struct battery_info *batt_info;
|
||||
int bat_temp_c;
|
||||
|
||||
batt_info = battery_get_info();
|
||||
|
||||
if ((curr->batt.flags & BATT_FLAG_BAD_ANY) == BATT_FLAG_BAD_ANY) {
|
||||
curr->requested_current = batt_info->precharge_current;
|
||||
curr->requested_voltage = batt_info->voltage_max;
|
||||
return 1000;
|
||||
}
|
||||
|
||||
/* battery temp in 0.1 deg C */
|
||||
bat_temp_c = curr->batt.temperature - 2731;
|
||||
|
||||
/* Don't charge if outside of allowable temperature range */
|
||||
if (bat_temp_c >= batt_info->charging_max_c * 10 ||
|
||||
bat_temp_c < batt_info->charging_min_c * 10) {
|
||||
curr->requested_current = 0;
|
||||
curr->requested_voltage = 0;
|
||||
curr->batt.flags &= ~BATT_FLAG_WANT_CHARGE;
|
||||
curr->state = ST_IDLE;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Customs options controllable by host command. */
|
||||
#define PARAM_FASTCHARGE (CS_PARAM_CUSTOM_PROFILE_MIN + 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;
|
||||
}
|
||||
|
||||
enum battery_present battery_hw_present(void)
|
||||
{
|
||||
/* The GPIO is low when the battery is physically present */
|
||||
return gpio_get_level(GPIO_BATTERY_PRESENT_L) ? BP_NO : BP_YES;
|
||||
}
|
||||
|
||||
static int battery_init(void)
|
||||
{
|
||||
int batt_status;
|
||||
|
||||
return battery_status(&batt_status) ? 0 :
|
||||
!!(batt_status & STATUS_INITIALIZED);
|
||||
}
|
||||
|
||||
/*
|
||||
* Check for case where both XCHG and XDSG bits are set indicating that even
|
||||
* though the FG can be read from the battery, the battery is not able to be
|
||||
* charged or discharged. This situation will happen if a battery disconnect was
|
||||
* intiaited via H1 setting the DISCONN signal to the battery. This will put the
|
||||
* battery pack into a sleep state and when power is reconnected, the FG can be
|
||||
* read, but the battery is still not able to provide power to the system. The
|
||||
* calling function returns batt_pres = BP_NO, which instructs the charging
|
||||
* state machine to prevent powering up the AP on battery alone which could lead
|
||||
* to a brownout event when the battery isn't able yet to provide power to the
|
||||
* system. .
|
||||
*/
|
||||
static int battery_check_disconnect(void)
|
||||
{
|
||||
int rv;
|
||||
uint8_t data[6];
|
||||
|
||||
/* Check if battery charging + discharging is disabled. */
|
||||
rv = sb_read_mfgacc(PARAM_OPERATION_STATUS,
|
||||
SB_ALT_MANUFACTURER_ACCESS, data, sizeof(data));
|
||||
if (rv)
|
||||
return BATTERY_DISCONNECT_ERROR;
|
||||
|
||||
if ((data[3] & (BATTERY_DISCHARGING_DISABLED |
|
||||
BATTERY_CHARGING_DISABLED)) ==
|
||||
(BATTERY_DISCHARGING_DISABLED | BATTERY_CHARGING_DISABLED))
|
||||
return BATTERY_DISCONNECTED;
|
||||
|
||||
return BATTERY_NOT_DISCONNECTED;
|
||||
}
|
||||
|
||||
enum battery_present battery_is_present(void)
|
||||
{
|
||||
enum battery_present batt_pres;
|
||||
|
||||
/* Get the physical hardware status */
|
||||
batt_pres = battery_hw_present();
|
||||
|
||||
/*
|
||||
* Make sure battery status is implemented, I2C transactions are
|
||||
* success & the battery status is Initialized to find out if it
|
||||
* is a working battery and it is not in the cut-off mode.
|
||||
*
|
||||
* If battery I2C fails but VBATT is high, battery is booting from
|
||||
* cut-off mode.
|
||||
*
|
||||
* FETs are turned off after Power Shutdown time.
|
||||
* The device will wake up when a voltage is applied to PACK.
|
||||
* Battery status will be inactive until it is initialized.
|
||||
*/
|
||||
if (batt_pres == BP_YES && batt_pres_prev != batt_pres &&
|
||||
(battery_is_cut_off() != BATTERY_CUTOFF_STATE_NORMAL ||
|
||||
battery_check_disconnect() != BATTERY_NOT_DISCONNECTED ||
|
||||
battery_init() == 0)) {
|
||||
batt_pres = BP_NO;
|
||||
}
|
||||
|
||||
batt_pres_prev = batt_pres;
|
||||
return batt_pres;
|
||||
}
|
||||
|
||||
1061
board/nautilus/board.c
Normal file
1061
board/nautilus/board.c
Normal file
File diff suppressed because it is too large
Load Diff
258
board/nautilus/board.h
Normal file
258
board/nautilus/board.h
Normal file
@@ -0,0 +1,258 @@
|
||||
/* Copyright 2016 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.
|
||||
*/
|
||||
|
||||
/* Eve board configuration */
|
||||
|
||||
#ifndef __CROS_EC_BOARD_H
|
||||
#define __CROS_EC_BOARD_H
|
||||
|
||||
/*
|
||||
* Allow dangerous commands.
|
||||
* TODO: Remove this config before production.
|
||||
*/
|
||||
#define CONFIG_SYSTEM_UNLOCKED
|
||||
|
||||
/* EC */
|
||||
#define CONFIG_ADC
|
||||
#define CONFIG_BACKLIGHT_LID
|
||||
#define CONFIG_BOARD_VERSION
|
||||
#define CONFIG_BOARD_SPECIFIC_VERSION
|
||||
#define CONFIG_BUTTON_COUNT 2
|
||||
#define CONFIG_BUTTON_RECOVERY
|
||||
#define CONFIG_CASE_CLOSED_DEBUG_EXTERNAL
|
||||
#define CONFIG_DPTF
|
||||
#define CONFIG_EMULATED_SYSRQ
|
||||
#define CONFIG_FLASH_SIZE 0x80000
|
||||
#define CONFIG_FPU
|
||||
#define CONFIG_I2C
|
||||
#define CONFIG_I2C_MASTER
|
||||
#define CONFIG_LED_COMMON
|
||||
#define CONFIG_LID_SWITCH
|
||||
#define CONFIG_LOW_POWER_IDLE
|
||||
#define CONFIG_LTO
|
||||
#define CONFIG_CHIP_PANIC_BACKUP
|
||||
#define CONFIG_SPI_FLASH_REGS
|
||||
#define CONFIG_SPI_FLASH_W25X40
|
||||
#define CONFIG_UART_HOST 0
|
||||
#define CONFIG_VBOOT_HASH
|
||||
#define CONFIG_SHA256_UNROLLED
|
||||
#define CONFIG_VSTORE
|
||||
#define CONFIG_VSTORE_SLOT_COUNT 1
|
||||
#define CONFIG_WATCHDOG_HELP
|
||||
#define CONFIG_WIRELESS
|
||||
#define CONFIG_WIRELESS_SUSPEND \
|
||||
(EC_WIRELESS_SWITCH_WLAN | EC_WIRELESS_SWITCH_WLAN_POWER)
|
||||
#define WIRELESS_GPIO_WLAN GPIO_WLAN_OFF_L
|
||||
#define WIRELESS_GPIO_WLAN_POWER GPIO_PP3300_DX_WLAN
|
||||
#define WIRELESS_GPIO_WWAN GPIO_PP3300_DX_LTE
|
||||
|
||||
/* EC console commands */
|
||||
#define CONFIG_CMD_ACCELS
|
||||
#define CONFIG_CMD_ACCEL_INFO
|
||||
#define CONFIG_CMD_BUTTON
|
||||
|
||||
/* SOC */
|
||||
#define CONFIG_CHIPSET_SKYLAKE
|
||||
#define CONFIG_CHIPSET_HAS_PLATFORM_PMIC_RESET
|
||||
#define CONFIG_CHIPSET_RESET_HOOK
|
||||
#define CONFIG_ESPI
|
||||
#define CONFIG_ESPI_VW_SIGNALS
|
||||
#define CONFIG_LPC
|
||||
#undef CONFIG_PECI
|
||||
|
||||
/* Battery */
|
||||
#define CONFIG_BATTERY_CUT_OFF
|
||||
#define CONFIG_BATTERY_DEVICE_CHEMISTRY "LION"
|
||||
#define CONFIG_BATTERY_SMART
|
||||
|
||||
/* Charger */
|
||||
#define CONFIG_CHARGE_MANAGER
|
||||
#define CONFIG_CHARGE_RAMP_HW /* This, or just RAMP? */
|
||||
|
||||
#define CONFIG_CHARGER
|
||||
#define CONFIG_CHARGER_V2
|
||||
#define CONFIG_CHARGER_ISL9238
|
||||
#define CONFIG_CHARGER_DISCHARGE_ON_AC
|
||||
#define CONFIG_CHARGER_INPUT_CURRENT 512
|
||||
#define CONFIG_CHARGER_MIN_BAT_PCT_FOR_POWER_ON 2
|
||||
#define CONFIG_CHARGER_NARROW_VDC
|
||||
#define CONFIG_CHARGER_PROFILE_OVERRIDE
|
||||
#define CONFIG_CHARGER_PSYS
|
||||
#define CONFIG_CHARGER_SENSE_RESISTOR 10
|
||||
#define CONFIG_CHARGER_SENSE_RESISTOR_AC 20
|
||||
#define CONFIG_CMD_CHARGER_ADC_AMON_BMON
|
||||
#define CONFIG_CMD_PD_CONTROL
|
||||
#define CONFIG_EXTPOWER_GPIO
|
||||
#undef CONFIG_EXTPOWER_DEBOUNCE_MS
|
||||
#define CONFIG_EXTPOWER_DEBOUNCE_MS 1000
|
||||
#define CONFIG_POWER_BUTTON
|
||||
#define CONFIG_POWER_BUTTON_X86
|
||||
#define CONFIG_POWER_COMMON
|
||||
#define CONFIG_POWER_SIGNAL_INTERRUPT_STORM_DETECT_THRESHOLD 30
|
||||
#define CONFIG_POWER_S0IX
|
||||
#define CONFIG_POWER_TRACK_HOST_SLEEP_STATE
|
||||
|
||||
/* Sensor */
|
||||
#define CONFIG_ALS
|
||||
#define CONFIG_ALS_OPT3001
|
||||
#define OPT3001_I2C_ADDR OPT3001_I2C_ADDR1
|
||||
#define CONFIG_TEMP_SENSOR
|
||||
#define CONFIG_TEMP_SENSOR_BD99992GW
|
||||
/* TODO(crosbug.com/p/61098): Is this the correct thermistor? */
|
||||
#define CONFIG_THERMISTOR_NCP15WB
|
||||
|
||||
#define CONFIG_KEYBOARD_PROTOCOL_MKBP
|
||||
#define CONFIG_MKBP_EVENT
|
||||
#define CONFIG_MKBP_USE_HOST_EVENT
|
||||
#define CONFIG_ACCELGYRO_BMI160
|
||||
#define CONFIG_MAG_BMI160_BMM150
|
||||
#define CONFIG_ACCEL_INTERRUPTS
|
||||
#define CONFIG_ACCELGYRO_BMI160_INT_EVENT TASK_EVENT_CUSTOM(4)
|
||||
#define BMM150_I2C_ADDRESS BMM150_ADDR0 /* 8-bit address */
|
||||
#define CONFIG_MAG_CALIBRATE
|
||||
|
||||
/* FIFO size is in power of 2. */
|
||||
#define CONFIG_ACCEL_FIFO 1024
|
||||
|
||||
/* Depends on how fast the AP boots and typical ODRs */
|
||||
#define CONFIG_ACCEL_FIFO_THRES (CONFIG_ACCEL_FIFO / 3)
|
||||
|
||||
#define CONFIG_TABLET_MODE
|
||||
#define CONFIG_TABLET_MODE_SWITCH
|
||||
|
||||
/* USB */
|
||||
#define CONFIG_USB_CHARGER
|
||||
#define CONFIG_USB_PD_ALT_MODE
|
||||
#define CONFIG_USB_PD_ALT_MODE_DFP
|
||||
#define CONFIG_USB_PD_CUSTOM_VDM
|
||||
#define CONFIG_USB_PD_DISCHARGE
|
||||
#define CONFIG_USB_PD_DISCHARGE_TCPC
|
||||
#define CONFIG_USB_PD_DUAL_ROLE
|
||||
#define CONFIG_USB_PD_DUAL_ROLE_AUTO_TOGGLE
|
||||
#define CONFIG_USB_PD_LOGGING
|
||||
#define CONFIG_USB_PD_MAX_SINGLE_SOURCE_CURRENT TYPEC_RP_3A0
|
||||
#define CONFIG_USB_PD_PORT_COUNT 2
|
||||
#define CONFIG_USB_PD_VBUS_DETECT_GPIO
|
||||
#define CONFIG_USB_PD_TCPC_LOW_POWER
|
||||
#define CONFIG_USB_PD_TCPM_MUX
|
||||
#define CONFIG_USB_PD_TCPM_ANX74XX
|
||||
#define CONFIG_USB_PD_TCPM_TCPCI
|
||||
#define CONFIG_USB_PD_TCPM_PS8751
|
||||
#define CONFIG_USB_PD_TRY_SRC
|
||||
#define CONFIG_USB_POWER_DELIVERY
|
||||
#define CONFIG_USBC_SS_MUX
|
||||
#define CONFIG_USBC_SS_MUX_DFP_ONLY
|
||||
#define CONFIG_USBC_VCONN
|
||||
#define CONFIG_USBC_VCONN_SWAP
|
||||
|
||||
/* BC 1.2 charger */
|
||||
#define CONFIG_BC12_DETECT_PI3USB9281
|
||||
#define CONFIG_BC12_DETECT_PI3USB9281_CHIP_COUNT 2
|
||||
|
||||
/* Optional feature to configure npcx chip */
|
||||
#define NPCX_UART_MODULE2 1 /* 1:GPIO64/65 as UART */
|
||||
#define NPCX_JTAG_MODULE2 0 /* 0:GPIO21/17/16/20 as JTAG */
|
||||
#define NPCX_TACH_SEL2 0 /* 0:GPIO40/73 as TACH */
|
||||
|
||||
/* I2C ports */
|
||||
#define I2C_PORT_TCPC0 NPCX_I2C_PORT0_0
|
||||
#define I2C_PORT_TCPC1 NPCX_I2C_PORT0_0
|
||||
#define I2C_PORT_ALS NPCX_I2C_PORT0_1
|
||||
#define I2C_PORT_USB_CHARGER_1 NPCX_I2C_PORT0_1
|
||||
#define I2C_PORT_USB_CHARGER_0 NPCX_I2C_PORT1
|
||||
#define I2C_PORT_CHARGER NPCX_I2C_PORT1
|
||||
#define I2C_PORT_BATTERY NPCX_I2C_PORT1
|
||||
#define I2C_PORT_PMIC NPCX_I2C_PORT2
|
||||
#define I2C_PORT_MP2949 NPCX_I2C_PORT2
|
||||
#define I2C_PORT_GYRO NPCX_I2C_PORT3
|
||||
#define I2C_PORT_BARO NPCX_I2C_PORT3
|
||||
#define I2C_PORT_ACCEL I2C_PORT_GYRO
|
||||
#define I2C_PORT_THERMAL I2C_PORT_PMIC
|
||||
|
||||
/* I2C addresses */
|
||||
#define I2C_ADDR_BD99992 0x60
|
||||
#define I2C_ADDR_MP2949 0x40
|
||||
|
||||
#ifndef __ASSEMBLER__
|
||||
|
||||
#include "gpio_signal.h"
|
||||
#include "registers.h"
|
||||
|
||||
enum power_signal {
|
||||
#ifdef CONFIG_POWER_S0IX
|
||||
X86_SLP_S0_DEASSERTED,
|
||||
#endif
|
||||
X86_SLP_S3_DEASSERTED,
|
||||
X86_SLP_S4_DEASSERTED,
|
||||
X86_SLP_SUS_DEASSERTED,
|
||||
X86_RSMRST_L_PGOOD,
|
||||
X86_PMIC_DPWROK,
|
||||
POWER_SIGNAL_COUNT
|
||||
};
|
||||
|
||||
enum temp_sensor_id {
|
||||
TEMP_SENSOR_BATTERY, /* BD99956GW TSENSE */
|
||||
TEMP_SENSOR_AMBIENT, /* BD99992GW SYSTHERM0 */
|
||||
TEMP_SENSOR_CHARGER, /* BD99992GW SYSTHERM1 */
|
||||
TEMP_SENSOR_DRAM, /* BD99992GW SYSTHERM2 */
|
||||
TEMP_SENSOR_EMMC, /* BD99992GW SYSTHERM3 */
|
||||
TEMP_SENSOR_COUNT
|
||||
};
|
||||
|
||||
enum als_id {
|
||||
ALS_OPT3001,
|
||||
ALS_COUNT
|
||||
};
|
||||
|
||||
/*
|
||||
* Motion sensors:
|
||||
* When reading through IO memory is set up for sensors (LPC is used),
|
||||
* the first 2 entries must be accelerometers, then gyroscope.
|
||||
* For BMI160, accel, gyro and compass sensors must be next to each other.
|
||||
*/
|
||||
enum sensor_id {
|
||||
LID_ACCEL = 0,
|
||||
LID_GYRO,
|
||||
LID_MAG,
|
||||
};
|
||||
|
||||
enum adc_channel {
|
||||
ADC_BASE_DET,
|
||||
ADC_VBUS,
|
||||
ADC_AMON_BMON,
|
||||
ADC_CH_COUNT
|
||||
};
|
||||
|
||||
enum button {
|
||||
BUTTON_VOLUME_DOWN = 0,
|
||||
BUTTON_VOLUME_UP = 1,
|
||||
BUTTON_COUNT
|
||||
};
|
||||
|
||||
/* TODO(crosbug.com/p/61098): Verify the numbers below. */
|
||||
/*
|
||||
* delay to turn on the power supply max is ~16ms.
|
||||
* delay to turn off the power supply max is about ~180ms.
|
||||
*/
|
||||
#define PD_POWER_SUPPLY_TURN_ON_DELAY 30000 /* us */
|
||||
#define PD_POWER_SUPPLY_TURN_OFF_DELAY 250000 /* us */
|
||||
|
||||
/* delay to turn on/off vconn */
|
||||
#define PD_VCONN_SWAP_DELAY 5000 /* us */
|
||||
|
||||
/* Define typical operating power and max power */
|
||||
#define PD_OPERATING_POWER_MW 15000
|
||||
#define PD_MAX_POWER_MW 45000
|
||||
#define PD_MAX_CURRENT_MA 3000
|
||||
#define PD_MAX_VOLTAGE_MV 20000
|
||||
|
||||
/* Board specific handlers */
|
||||
int board_get_version(void);
|
||||
void board_reset_pd_mcu(void);
|
||||
void board_set_tcpc_power_mode(int port, int mode);
|
||||
|
||||
#endif /* !__ASSEMBLER__ */
|
||||
|
||||
#endif /* __CROS_EC_BOARD_H */
|
||||
15
board/nautilus/build.mk
Normal file
15
board/nautilus/build.mk
Normal file
@@ -0,0 +1,15 @@
|
||||
# -*- makefile -*-
|
||||
# Copyright 2016 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_VARIANT:=npcx5m6g
|
||||
|
||||
board-y=board.o
|
||||
board-$(CONFIG_BATTERY_SMART)+=battery.o
|
||||
board-$(CONFIG_LED_COMMON)+=led.o
|
||||
board-$(CONFIG_USB_POWER_DELIVERY)+=usb_pd_policy.o
|
||||
36
board/nautilus/ec.tasklist
Normal file
36
board/nautilus/ec.tasklist
Normal file
@@ -0,0 +1,36 @@
|
||||
/* Copyright 2016 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(ALS, als_task, NULL, TASK_STACK_SIZE) \
|
||||
TASK_ALWAYS(USB_CHG_P0, usb_charger_task, NULL, TASK_STACK_SIZE) \
|
||||
TASK_ALWAYS(USB_CHG_P1, usb_charger_task, NULL, 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(PDCMD, pd_command_task, NULL, TASK_STACK_SIZE) \
|
||||
TASK_ALWAYS(HOSTCMD, host_command_task, NULL, LARGER_TASK_STACK_SIZE) \
|
||||
TASK_ALWAYS(CONSOLE, console_task, NULL, LARGER_TASK_STACK_SIZE) \
|
||||
TASK_ALWAYS(POWERBTN, power_button_task, NULL, LARGER_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)
|
||||
126
board/nautilus/gpio.inc
Normal file
126
board/nautilus/gpio.inc
Normal file
@@ -0,0 +1,126 @@
|
||||
/* -*- mode:c -*-
|
||||
*
|
||||
* Copyright 2016 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(3, 7), GPIO_INT_FALLING, tcpc_alert_event)
|
||||
GPIO_INT(USB_C1_PD_INT_ODL, PIN(C, 5), GPIO_INT_FALLING, tcpc_alert_event)
|
||||
#ifdef CONFIG_POWER_S0IX
|
||||
GPIO_INT(PCH_SLP_S0_L, PIN(7, 5), GPIO_INT_BOTH, power_signal_interrupt)
|
||||
#endif
|
||||
/* Use VW signals instead of GPIOs */
|
||||
#ifndef CONFIG_ESPI_VW_SIGNALS
|
||||
GPIO_INT(PCH_SLP_S3_L, PIN(7, 3), GPIO_INT_BOTH, power_signal_interrupt)
|
||||
GPIO_INT(PCH_SLP_S4_L, PIN(8, 6), GPIO_INT_BOTH, power_signal_interrupt)
|
||||
#endif
|
||||
GPIO_INT(PCH_SLP_SUS_L, PIN(6, 2), GPIO_INT_BOTH, power_signal_interrupt)
|
||||
GPIO_INT(RSMRST_L_PGOOD, PIN(B, 0), GPIO_INT_BOTH, power_signal_interrupt)
|
||||
GPIO_INT(PMIC_DPWROK, PIN(C, 7), GPIO_INT_BOTH, power_signal_interrupt)
|
||||
GPIO_INT(POWER_BUTTON_L, PIN(0, 4), GPIO_INT_BOTH | GPIO_PULL_UP, power_button_interrupt)
|
||||
GPIO_INT(LID_OPEN, PIN(6, 7), GPIO_INT_BOTH, lid_interrupt)
|
||||
/* TODO(b/35585396): Make use of reverse dock signal. */
|
||||
GPIO_INT(REVERSE_DOCK, PIN(B, 7), GPIO_INT_BOTH, lid_interrupt)
|
||||
GPIO_INT(VOLUME_DOWN_L, PIN(8, 3), GPIO_INT_BOTH | GPIO_PULL_UP, button_interrupt)
|
||||
GPIO_INT(VOLUME_UP_L, PIN(8, 2), GPIO_INT_BOTH | GPIO_PULL_UP, button_interrupt)
|
||||
GPIO_INT(WP_L, PIN(4, 0), GPIO_INT_BOTH, switch_interrupt)
|
||||
GPIO_INT(AC_PRESENT, PIN(C, 1), GPIO_INT_BOTH, extpower_interrupt)
|
||||
GPIO_INT(USB_C0_VBUS_WAKE_L, PIN(9, 3), GPIO_INT_BOTH | GPIO_PULL_UP, vbus0_evt)
|
||||
GPIO_INT(USB_C1_VBUS_WAKE_L, PIN(9, 7), GPIO_INT_BOTH | GPIO_PULL_UP, vbus1_evt)
|
||||
GPIO_INT(USB_C0_BC12_INT_L, PIN(D, 3), GPIO_INT_FALLING, usb0_evt)
|
||||
GPIO_INT(USB_C1_BC12_INT_L, PIN(3, 3), GPIO_INT_FALLING, usb1_evt)
|
||||
GPIO_INT(ACCELGYRO3_INT_L, PIN(3, 6), GPIO_INT_FALLING, bmi160_interrupt)
|
||||
GPIO_INT(BASE_DET_A, PIN(4, 5), GPIO_INT_BOTH, base_detect_interrupt)
|
||||
GPIO_INT(USB_C0_CABLE_DET, PIN(D, 2), GPIO_INT_RISING, anx74xx_cable_det_interrupt)
|
||||
|
||||
GPIO(PCH_RTCRST, PIN(2, 7), GPIO_OUT_LOW) /* RTCRST# to SOC (>= rev4) */
|
||||
GPIO(ENABLE_BACKLIGHT, PIN(2, 6), GPIO_OUT_LOW) /* Enable Backlight */
|
||||
GPIO(WLAN_OFF_L, PIN(7, 2), GPIO_OUT_LOW) /* Disable WLAN */
|
||||
GPIO(PP3300_DX_WLAN, PIN(A, 7), GPIO_OUT_LOW) /* Enable WLAN 3.3V Power */
|
||||
GPIO(CPU_PROCHOT, PIN(8, 1), GPIO_OUT_HIGH) /* PROCHOT# to SOC */
|
||||
GPIO(PCH_ACOK, PIN(5, 0), GPIO_ODR_LOW) /* ACOK to SOC */
|
||||
GPIO(PCH_WAKE_L, PIN(A, 3), GPIO_ODR_HIGH) /* Wake SOC */
|
||||
GPIO(PCH_RSMRST_L, PIN(7, 0), GPIO_OUT_LOW) /* RSMRST# to SOC */
|
||||
GPIO(PCH_PWRBTN_L, PIN(4, 1), GPIO_ODR_HIGH) /* Power Button to SOC */
|
||||
GPIO(EC_PLATFORM_RST, PIN(A, 6), GPIO_OUT_LOW) /* EC Reset to LDO_EN */
|
||||
GPIO(SYS_RESET_L, PIN(6, 1), GPIO_ODR_HIGH) /* Cold Reset to SOC */
|
||||
GPIO(PMIC_SLP_SUS_L, PIN(8, 5), GPIO_OUT_LOW) /* SLP_SUS# to PMIC */
|
||||
GPIO(BATTERY_PRESENT_L, PIN(3, 4), GPIO_INPUT) /* Battery Present */
|
||||
GPIO(CCD_MODE_ODL, PIN(6, 3), GPIO_INPUT) /* Case Closed Debug Mode */
|
||||
GPIO(EC_HAVEN_RESET_ODL, PIN(0, 2), GPIO_ODR_HIGH) /* H1 Reset */
|
||||
GPIO(ENTERING_RW, PIN(7, 6), GPIO_OUTPUT) /* EC Entering RW */
|
||||
GPIO(PMIC_INT_L, PIN(6, 0), GPIO_INPUT) /* PMIC interrupt */
|
||||
#ifndef CONFIG_POWER_S0IX
|
||||
GPIO(PCH_SLP_S0_L, PIN(7, 5), GPIO_INPUT)
|
||||
#endif
|
||||
|
||||
/* Sensor interrupts, not implemented yet */
|
||||
GPIO(ALS_INT_L, PIN(2, 5), GPIO_INPUT)
|
||||
|
||||
/* TODO(b/35585396): Make use of these GPIOs */
|
||||
GPIO(PP1800_DX_SENSOR, PIN(1, 4), GPIO_OUTPUT)
|
||||
GPIO(PP3300_DX_SENSOR, PIN(2, 1), GPIO_OUTPUT)
|
||||
GPIO(PP3300_USB_PD, PIN(2, 0), GPIO_OUTPUT)
|
||||
|
||||
GPIO(WLAN_PE_RST, PIN(1, 2), GPIO_OUTPUT)
|
||||
GPIO(PP3300_DX_LTE, PIN(0, 5), GPIO_OUT_LOW)
|
||||
GPIO(LTE_GPS_OFF_L, PIN(0, 0), GPIO_ODR_HIGH)
|
||||
GPIO(LTE_BODY_SAR_L, PIN(0, 1), GPIO_ODR_HIGH)
|
||||
GPIO(LTE_WAKE_L, PIN(7, 1), GPIO_INPUT)
|
||||
GPIO(LTE_OFF_ODL, PIN(8, 0), GPIO_ODR_LOW)
|
||||
/* end of TODO */
|
||||
|
||||
GPIO(PP3300_DX_BASE, PIN(1, 1), GPIO_OUT_LOW)
|
||||
|
||||
/* I2C pins - these will be reconfigured for alternate function below */
|
||||
GPIO(I2C0_0_SCL, PIN(B, 5), GPIO_INPUT) /* EC_I2C0_0_USBC_3V3_SCL */
|
||||
GPIO(I2C0_0_SDA, PIN(B, 4), GPIO_INPUT) /* EC_I2C0_0_USBC_3V3_SDA */
|
||||
GPIO(I2C0_1_SCL, PIN(B, 3), GPIO_INPUT) /* EC_I2C0_1_3V3_SCL */
|
||||
GPIO(I2C0_1_SDA, PIN(B, 2), GPIO_INPUT) /* EC_I2C0_1_3V3_SDA */
|
||||
GPIO(I2C1_SCL, PIN(9, 0), GPIO_INPUT) /* EC_I2C1_3V3_SCL */
|
||||
GPIO(I2C1_SDA, PIN(8, 7), GPIO_INPUT) /* EC_I2C1_3V3_SDA */
|
||||
GPIO(I2C2_SCL, PIN(9, 2), GPIO_INPUT) /* EC_I2C2_PMIC_3V3_SCL */
|
||||
GPIO(I2C2_SDA, PIN(9, 1), GPIO_INPUT) /* EC_I2C2_PMIC_3V3_SDA */
|
||||
GPIO(I2C3_SCL, PIN(D, 1), GPIO_INPUT) /* EC_I2C3_SENSOR_1V8_SCL */
|
||||
GPIO(I2C3_SDA, PIN(D, 0), GPIO_INPUT) /* EC_I2C3_SENSOR_1V8_SDA */
|
||||
|
||||
/* rev0: 5V enables: INPUT=1.5A, OUT_LOW=OFF, OUT_HIGH=3A */
|
||||
GPIO(USB_C0_5V_EN, PIN(4, 2), GPIO_OUT_LOW) /* C0 5V Enable */
|
||||
GPIO(USB_C0_3A_EN, PIN(6, 6), GPIO_OUT_LOW) /* C0 Enable 3A */
|
||||
GPIO(USB_C0_CHARGE_L, PIN(C, 0), GPIO_OUT_LOW) /* C0 Charge enable */
|
||||
GPIO(USB_C1_5V_EN, PIN(B, 1), GPIO_OUT_LOW) /* C1 5V Enable */
|
||||
GPIO(USB_C1_3A_EN, PIN(3, 5), GPIO_OUT_LOW) /* C1 3A Enable */
|
||||
GPIO(USB_C1_CHARGE_L, PIN(C, 3), GPIO_OUT_LOW) /* C1 Charge enable */
|
||||
GPIO(USB_C0_PD_RST_L, PIN(0, 3), GPIO_OUT_LOW) /* C0 PD Reset */
|
||||
GPIO(USB_C1_PD_RST_L, PIN(7, 4), GPIO_OUT_LOW) /* C1 PD Reset */
|
||||
GPIO(USB_C0_DP_HPD, PIN(9, 4), GPIO_INPUT) /* C0 DP Hotplug Detect */
|
||||
GPIO(USB_C1_DP_HPD, PIN(A, 5), GPIO_INPUT) /* C1 DP Hotplug Detect */
|
||||
GPIO(USB_C0_TCPC_PWR, PIN(8, 4), GPIO_OUT_LOW) /* Enable C0 TCPC Power */
|
||||
GPIO(USB2_OTG_ID, PIN(A, 1), GPIO_ODR_LOW) /* OTG ID */
|
||||
GPIO(USB2_OTG_VBUSSENSE, PIN(9, 5), GPIO_OUT_LOW) /* OTG VBUS Sense */
|
||||
|
||||
/* LEDs (2 colors on each port) */
|
||||
GPIO(LED_YELLOW_C0, PIN(2, 4), GPIO_OUT_LOW) /* This is from rev5 */
|
||||
GPIO(LED_YELLOW_C0_OLD, PIN(3, 2), GPIO_OUT_LOW) /* This is for rev1 to rev4 */
|
||||
GPIO(LED_WHITE_C0, PIN(C, 6), GPIO_OUT_LOW)
|
||||
GPIO(LED_YELLOW_C1, PIN(3, 1), GPIO_OUT_LOW)
|
||||
GPIO(LED_WHITE_C1, PIN(3, 0), GPIO_OUT_LOW)
|
||||
|
||||
/* Board ID */
|
||||
GPIO(BOARD_VERSION1, PIN(C, 4), GPIO_INPUT) /* Board ID bit0 */
|
||||
GPIO(BOARD_VERSION2, PIN(C, 2), GPIO_INPUT) /* Board ID bit1 */
|
||||
GPIO(BOARD_VERSION3, PIN(1, 3), GPIO_INPUT) /* Board ID bit2 */
|
||||
GPIO(BOARD_VERSION4, PIN(1, 7), GPIO_INPUT) /* Board ID strap 3 (ternary) */
|
||||
|
||||
/* Alternate functions GPIO definitions */
|
||||
ALTERNATE(PIN_MASK(6, 0x30), 1, MODULE_UART, 0) /* GPIO64-65 */ /* UART from EC to Servo */
|
||||
ALTERNATE(PIN_MASK(8, 0x80), 1, MODULE_I2C, 0) /* GPIO87 */ /* EC_I2C1_3V3_SDA */
|
||||
ALTERNATE(PIN_MASK(9, 0x01), 1, MODULE_I2C, 0) /* GPIO90 */ /* EC_I2C1_3V3_SCL */
|
||||
ALTERNATE(PIN_MASK(9, 0x06), 1, MODULE_I2C, 0) /* GPIO91-92 */ /* EC_I2C2_PMIC_3V3_SDA/SCL */
|
||||
ALTERNATE(PIN_MASK(B, 0x30), 1, MODULE_I2C, 0) /* GPIOB4-B5 */ /* EC_I2C0_0_USBC_3V3_SDA/SCL */
|
||||
ALTERNATE(PIN_MASK(B, 0x0C), 1, MODULE_I2C, 0) /* GPOPB2-B3 */ /* EC_I2C0_1_3V3_SDA/SCL */
|
||||
ALTERNATE(PIN_MASK(D, 0x03), 1, MODULE_I2C, 0) /* GPIOD0-D1 */ /* EC_I2C3_SENSOR_1V8_SDA/SCL */
|
||||
169
board/nautilus/led.c
Normal file
169
board/nautilus/led.c
Normal file
@@ -0,0 +1,169 @@
|
||||
/* 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.
|
||||
*
|
||||
* Power and battery LED control.
|
||||
*/
|
||||
|
||||
#include "battery.h"
|
||||
#include "charge_manager.h"
|
||||
#include "charge_state.h"
|
||||
#include "chipset.h"
|
||||
#include "ec_commands.h"
|
||||
#include "gpio.h"
|
||||
#include "hooks.h"
|
||||
#include "host_command.h"
|
||||
#include "led_common.h"
|
||||
#include "system.h"
|
||||
#include "util.h"
|
||||
|
||||
#define BAT_LED_ON 1
|
||||
#define BAT_LED_OFF 0
|
||||
|
||||
const enum ec_led_id supported_led_ids[] = {
|
||||
EC_LED_ID_LEFT_LED,
|
||||
EC_LED_ID_RIGHT_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 void side_led_set_color(int port, enum led_color color)
|
||||
{
|
||||
int yellow_c0 = (system_get_board_version() >= 5) ?
|
||||
GPIO_LED_YELLOW_C0 : GPIO_LED_YELLOW_C0_OLD;
|
||||
gpio_set_level(port ? GPIO_LED_YELLOW_C1 : yellow_c0,
|
||||
(color == LED_AMBER) ? BAT_LED_ON : BAT_LED_OFF);
|
||||
gpio_set_level(port ? GPIO_LED_WHITE_C1 : GPIO_LED_WHITE_C0,
|
||||
(color == LED_WHITE) ? BAT_LED_ON : BAT_LED_OFF);
|
||||
}
|
||||
|
||||
void led_get_brightness_range(enum ec_led_id led_id, uint8_t *brightness_range)
|
||||
{
|
||||
brightness_range[EC_LED_COLOR_AMBER] = 1;
|
||||
brightness_range[EC_LED_COLOR_WHITE] = 1;
|
||||
}
|
||||
|
||||
int led_set_brightness(enum ec_led_id led_id, const uint8_t *brightness)
|
||||
{
|
||||
int port;
|
||||
|
||||
switch (led_id) {
|
||||
case EC_LED_ID_LEFT_LED:
|
||||
port = 0;
|
||||
break;
|
||||
case EC_LED_ID_RIGHT_LED:
|
||||
port = 1;
|
||||
break;
|
||||
default:
|
||||
return EC_ERROR_PARAM1;
|
||||
}
|
||||
|
||||
if (brightness[EC_LED_COLOR_WHITE] != 0)
|
||||
side_led_set_color(port, LED_WHITE);
|
||||
else if (brightness[EC_LED_COLOR_AMBER] != 0)
|
||||
side_led_set_color(port, LED_AMBER);
|
||||
else
|
||||
side_led_set_color(port, LED_OFF);
|
||||
|
||||
return EC_SUCCESS;
|
||||
}
|
||||
|
||||
/*
|
||||
* Set active charge port color to the parameter, turn off all others.
|
||||
* If no port is active (-1), turn off all LEDs.
|
||||
*/
|
||||
static void set_active_port_color(enum led_color color)
|
||||
{
|
||||
int port = charge_manager_get_active_charge_port();
|
||||
|
||||
if (led_auto_control_is_enabled(EC_LED_ID_LEFT_LED))
|
||||
side_led_set_color(0, (port == 0) ? color : LED_OFF);
|
||||
if (led_auto_control_is_enabled(EC_LED_ID_RIGHT_LED))
|
||||
side_led_set_color(1, (port == 1) ? color : LED_OFF);
|
||||
}
|
||||
|
||||
static void board_led_set_battery(void)
|
||||
{
|
||||
static int battery_ticks;
|
||||
uint32_t chflags = charge_get_flags();
|
||||
|
||||
battery_ticks++;
|
||||
|
||||
switch (charge_get_state()) {
|
||||
case PWR_STATE_CHARGE:
|
||||
/* Always indicate when charging, even in suspend. */
|
||||
set_active_port_color(LED_AMBER);
|
||||
break;
|
||||
case PWR_STATE_DISCHARGE:
|
||||
/*
|
||||
* TODO(b/37970194): Do we really want to blink on low battery?
|
||||
* If yes, what's the threshold? In S0 only?
|
||||
*/
|
||||
if (led_auto_control_is_enabled(EC_LED_ID_LEFT_LED)) {
|
||||
if (charge_get_percent() < 12)
|
||||
side_led_set_color(0,
|
||||
(battery_ticks & 0x4) ? LED_WHITE : LED_OFF);
|
||||
else
|
||||
side_led_set_color(0, LED_OFF);
|
||||
}
|
||||
|
||||
if (led_auto_control_is_enabled(EC_LED_ID_RIGHT_LED))
|
||||
side_led_set_color(1, LED_OFF);
|
||||
break;
|
||||
case PWR_STATE_ERROR:
|
||||
set_active_port_color((battery_ticks & 0x2) ?
|
||||
LED_WHITE : LED_OFF);
|
||||
break;
|
||||
case PWR_STATE_CHARGE_NEAR_FULL:
|
||||
set_active_port_color(LED_WHITE);
|
||||
break;
|
||||
case PWR_STATE_IDLE: /* External power connected in IDLE */
|
||||
if (chflags & CHARGE_FLAG_FORCE_IDLE)
|
||||
set_active_port_color((battery_ticks & 0x4) ?
|
||||
LED_AMBER : LED_OFF);
|
||||
else
|
||||
set_active_port_color(LED_WHITE);
|
||||
break;
|
||||
default:
|
||||
/* Other states don't alter LED behavior */
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* Called by hook task every TICK */
|
||||
static void led_tick(void)
|
||||
{
|
||||
board_led_set_battery();
|
||||
}
|
||||
DECLARE_HOOK(HOOK_TICK, led_tick, HOOK_PRIO_DEFAULT);
|
||||
|
||||
void led_control(enum ec_led_id led_id, enum ec_led_state state)
|
||||
{
|
||||
enum led_color color;
|
||||
|
||||
if ((led_id != EC_LED_ID_RECOVERY_HW_REINIT_LED) &&
|
||||
(led_id != EC_LED_ID_SYSRQ_DEBUG_LED))
|
||||
return;
|
||||
|
||||
if (state == LED_STATE_RESET) {
|
||||
led_auto_control(EC_LED_ID_LEFT_LED, 1);
|
||||
led_auto_control(EC_LED_ID_RIGHT_LED, 1);
|
||||
board_led_set_battery();
|
||||
return;
|
||||
}
|
||||
|
||||
color = state ? LED_WHITE : LED_OFF;
|
||||
|
||||
led_auto_control(EC_LED_ID_LEFT_LED, 0);
|
||||
led_auto_control(EC_LED_ID_RIGHT_LED, 0);
|
||||
|
||||
side_led_set_color(0, color);
|
||||
side_led_set_color(1, color);
|
||||
}
|
||||
443
board/nautilus/usb_pd_policy.c
Normal file
443
board/nautilus/usb_pd_policy.c
Normal file
@@ -0,0 +1,443 @@
|
||||
/* Copyright 2016 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 "atomic.h"
|
||||
#include "extpower.h"
|
||||
#include "charge_manager.h"
|
||||
#include "common.h"
|
||||
#include "console.h"
|
||||
#include "driver/tcpm/anx74xx.h"
|
||||
#include "driver/tcpm/ps8xxx.h"
|
||||
#include "gpio.h"
|
||||
#include "hooks.h"
|
||||
#include "host_command.h"
|
||||
#include "registers.h"
|
||||
#include "system.h"
|
||||
#include "task.h"
|
||||
#include "timer.h"
|
||||
#include "util.h"
|
||||
#include "usb_mux.h"
|
||||
#include "usb_pd.h"
|
||||
#include "usb_pd_tcpm.h"
|
||||
|
||||
#define CPRINTF(format, args...) cprintf(CC_USBPD, format, ## args)
|
||||
#define CPRINTS(format, args...) cprints(CC_USBPD, format, ## args)
|
||||
|
||||
#define PDO_FIXED_FLAGS (PDO_FIXED_DUAL_ROLE | PDO_FIXED_DATA_SWAP |\
|
||||
PDO_FIXED_COMM_CAP)
|
||||
|
||||
/* TODO(crosbug.com/p/61098): fill in correct source and sink capabilities */
|
||||
const uint32_t pd_src_pdo[] = {
|
||||
PDO_FIXED(5000, 1500, PDO_FIXED_FLAGS),
|
||||
};
|
||||
const int pd_src_pdo_cnt = ARRAY_SIZE(pd_src_pdo);
|
||||
const uint32_t pd_src_pdo_max[] = {
|
||||
PDO_FIXED(5000, 3000, PDO_FIXED_FLAGS),
|
||||
};
|
||||
const int pd_src_pdo_max_cnt = ARRAY_SIZE(pd_src_pdo_max);
|
||||
|
||||
const uint32_t pd_snk_pdo[] = {
|
||||
PDO_FIXED(5000, 500, PDO_FIXED_FLAGS),
|
||||
PDO_BATT(4750, 21000, 15000),
|
||||
PDO_VAR(4750, 21000, 3000),
|
||||
};
|
||||
const int pd_snk_pdo_cnt = ARRAY_SIZE(pd_snk_pdo);
|
||||
|
||||
int pd_is_valid_input_voltage(int mv)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
void pd_transition_voltage(int idx)
|
||||
{
|
||||
/* No-operation: we are always 5V */
|
||||
}
|
||||
|
||||
static uint8_t vbus_en[CONFIG_USB_PD_PORT_COUNT];
|
||||
static uint8_t vbus_rp[CONFIG_USB_PD_PORT_COUNT] = {TYPEC_RP_1A5, TYPEC_RP_1A5};
|
||||
|
||||
int board_vbus_source_enabled(int port)
|
||||
{
|
||||
return vbus_en[port];
|
||||
}
|
||||
|
||||
static void board_vbus_update_source_current(int port)
|
||||
{
|
||||
enum gpio_signal gpio_5v_en = port ? GPIO_USB_C1_5V_EN :
|
||||
GPIO_USB_C0_5V_EN;
|
||||
enum gpio_signal gpio_3a_en = port ? GPIO_USB_C1_3A_EN :
|
||||
GPIO_USB_C0_3A_EN;
|
||||
|
||||
if (system_get_board_version() >= 1) {
|
||||
/*
|
||||
* For rev1 and beyond, 1.5 vs 3.0 A limit is controlled by a
|
||||
* dedicated gpio where high = 3.0A and low = 1.5A. VBUS on/off
|
||||
* is controlled by GPIO_USB_C0/1_5V_EN. Both of these signals
|
||||
* can remain outputs.
|
||||
*/
|
||||
gpio_set_level(gpio_3a_en, vbus_rp[port] == TYPEC_RP_3A0 ?
|
||||
1 : 0);
|
||||
gpio_set_level(gpio_5v_en, vbus_en[port]);
|
||||
} else {
|
||||
/*
|
||||
* Driving USB_Cx_5V_EN high, actually put a 16.5k resistance
|
||||
* (2x 33k in parallel) on the NX5P3290 load switch ILIM pin,
|
||||
* setting a minimum OCP current of 3186 mA.
|
||||
* Putting an internal pull-up on USB_Cx_5V_EN, effectively put
|
||||
* a 33k resistor on ILIM, setting a minimum OCP current of
|
||||
* 1505 mA.
|
||||
*/
|
||||
int flags = (vbus_rp[port] == TYPEC_RP_1A5 && vbus_en[port]) ?
|
||||
(GPIO_INPUT | GPIO_PULL_UP) :
|
||||
(GPIO_OUTPUT | GPIO_PULL_UP);
|
||||
gpio_set_level(gpio_5v_en, vbus_en[port]);
|
||||
gpio_set_flags(gpio_5v_en, flags);
|
||||
}
|
||||
}
|
||||
|
||||
void typec_set_source_current_limit(int port, int rp)
|
||||
{
|
||||
vbus_rp[port] = rp;
|
||||
|
||||
/* change the GPIO driving the load switch if needed */
|
||||
board_vbus_update_source_current(port);
|
||||
}
|
||||
|
||||
int pd_set_power_supply_ready(int port)
|
||||
{
|
||||
/* Disable charging */
|
||||
gpio_set_level(port ? GPIO_USB_C1_CHARGE_L :
|
||||
GPIO_USB_C0_CHARGE_L, 1);
|
||||
|
||||
/* Ensure we advertise the proper available current quota */
|
||||
charge_manager_source_port(port, 1);
|
||||
|
||||
/* Provide VBUS */
|
||||
vbus_en[port] = 1;
|
||||
board_vbus_update_source_current(port);
|
||||
|
||||
if (system_get_board_version() >= 2)
|
||||
pd_set_vbus_discharge(port, 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;
|
||||
|
||||
prev_en = vbus_en[port];
|
||||
|
||||
/* Disable VBUS */
|
||||
vbus_en[port] = 0;
|
||||
board_vbus_update_source_current(port);
|
||||
|
||||
/* Enable discharge if we were previously sourcing 5V */
|
||||
if (system_get_board_version() >= 2 && prev_en)
|
||||
pd_set_vbus_discharge(port, 1);
|
||||
|
||||
/* Give back the current quota we are no longer using */
|
||||
charge_manager_source_port(port, 0);
|
||||
|
||||
/* notify host of power info change */
|
||||
pd_send_host_event(PD_EVENT_POWER_CHANGE);
|
||||
}
|
||||
|
||||
int pd_snk_is_vbus_provided(int port)
|
||||
{
|
||||
return !gpio_get_level(port ? GPIO_USB_C1_VBUS_WAKE_L :
|
||||
GPIO_USB_C0_VBUS_WAKE_L);
|
||||
}
|
||||
|
||||
int pd_board_checks(void)
|
||||
{
|
||||
return EC_SUCCESS;
|
||||
}
|
||||
|
||||
int pd_check_power_swap(int port)
|
||||
{
|
||||
/*
|
||||
* Allow power swap as long as we are acting as a dual role device,
|
||||
* otherwise assume our role is fixed (not in S0 or console command
|
||||
* to fix our role).
|
||||
*/
|
||||
return pd_get_dual_role() == PD_DRP_TOGGLE_ON ? 1 : 0;
|
||||
}
|
||||
|
||||
int pd_check_data_swap(int port, int data_role)
|
||||
{
|
||||
/*
|
||||
* Allow data swap if we are a UFP, otherwise don't allow.
|
||||
*
|
||||
* When we are still in the Read-Only firmware, avoid swapping roles
|
||||
* so we don't jump in RW as a SNK/DFP and potentially confuse the
|
||||
* power supply by sending a soft-reset with wrong data role.
|
||||
*/
|
||||
return (data_role == PD_ROLE_UFP) &&
|
||||
(system_get_image_copy() != SYSTEM_IMAGE_RO) ? 1 : 0;
|
||||
}
|
||||
|
||||
int pd_check_vconn_swap(int port)
|
||||
{
|
||||
/* in G3, do not allow vconn swap since pp5000_A rail is off */
|
||||
return gpio_get_level(GPIO_PMIC_SLP_SUS_L);
|
||||
}
|
||||
|
||||
void pd_execute_data_swap(int port, int data_role)
|
||||
{
|
||||
/* Do nothing */
|
||||
}
|
||||
|
||||
void pd_check_pr_role(int port, int pr_role, int flags)
|
||||
{
|
||||
/*
|
||||
* If partner is dual-role power and dualrole toggling is on, consider
|
||||
* if a power swap is necessary.
|
||||
*/
|
||||
if ((flags & PD_FLAGS_PARTNER_DR_POWER) &&
|
||||
pd_get_dual_role() == PD_DRP_TOGGLE_ON) {
|
||||
/*
|
||||
* If we are a sink and partner is not externally powered, then
|
||||
* swap to become a source. If we are source and partner is
|
||||
* externally powered, swap to become a sink.
|
||||
*/
|
||||
int partner_extpower = flags & PD_FLAGS_PARTNER_EXTPOWER;
|
||||
|
||||
if ((!partner_extpower && pr_role == PD_ROLE_SINK) ||
|
||||
(partner_extpower && pr_role == PD_ROLE_SOURCE))
|
||||
pd_request_power_swap(port);
|
||||
}
|
||||
}
|
||||
|
||||
void pd_check_dr_role(int port, int dr_role, int flags)
|
||||
{
|
||||
/* If UFP, try to switch to DFP */
|
||||
if ((flags & PD_FLAGS_PARTNER_DR_DATA) &&
|
||||
dr_role == PD_ROLE_UFP &&
|
||||
system_get_image_copy() != SYSTEM_IMAGE_RO)
|
||||
pd_request_data_swap(port);
|
||||
}
|
||||
/* ----------------- Vendor Defined Messages ------------------ */
|
||||
const struct svdm_response svdm_rsp = {
|
||||
.identity = NULL,
|
||||
.svids = NULL,
|
||||
.modes = NULL,
|
||||
};
|
||||
|
||||
int pd_custom_vdm(int port, int cnt, uint32_t *payload,
|
||||
uint32_t **rpayload)
|
||||
{
|
||||
int cmd = PD_VDO_CMD(payload[0]);
|
||||
uint16_t dev_id = 0;
|
||||
int is_rw, is_latest;
|
||||
|
||||
/* make sure we have some payload */
|
||||
if (cnt == 0)
|
||||
return 0;
|
||||
|
||||
switch (cmd) {
|
||||
case VDO_CMD_VERSION:
|
||||
/* guarantee last byte of payload is null character */
|
||||
*(payload + cnt - 1) = 0;
|
||||
CPRINTF("version: %s\n", (char *)(payload+1));
|
||||
break;
|
||||
case VDO_CMD_READ_INFO:
|
||||
case VDO_CMD_SEND_INFO:
|
||||
/* copy hash */
|
||||
if (cnt == 7) {
|
||||
dev_id = VDO_INFO_HW_DEV_ID(payload[6]);
|
||||
is_rw = VDO_INFO_IS_RW(payload[6]);
|
||||
|
||||
is_latest = pd_dev_store_rw_hash(port,
|
||||
dev_id,
|
||||
payload + 1,
|
||||
is_rw ?
|
||||
SYSTEM_IMAGE_RW :
|
||||
SYSTEM_IMAGE_RO);
|
||||
/*
|
||||
* Send update host event unless our RW hash is
|
||||
* already known to be the latest update RW.
|
||||
*/
|
||||
if (!is_rw || !is_latest)
|
||||
pd_send_host_event(PD_EVENT_UPDATE_DEVICE);
|
||||
|
||||
CPRINTF("DevId:%d.%d SW:%d RW:%d\n",
|
||||
HW_DEV_ID_MAJ(dev_id),
|
||||
HW_DEV_ID_MIN(dev_id),
|
||||
VDO_INFO_SW_DBG_VER(payload[6]),
|
||||
is_rw);
|
||||
} else if (cnt == 6) {
|
||||
/* really old devices don't have last byte */
|
||||
pd_dev_store_rw_hash(port, dev_id, payload + 1,
|
||||
SYSTEM_IMAGE_UNKNOWN);
|
||||
}
|
||||
break;
|
||||
case VDO_CMD_CURRENT:
|
||||
CPRINTF("Current: %dmA\n", payload[1]);
|
||||
break;
|
||||
case VDO_CMD_FLIP:
|
||||
usb_mux_flip(port);
|
||||
break;
|
||||
#ifdef CONFIG_USB_PD_LOGGING
|
||||
case VDO_CMD_GET_LOG:
|
||||
pd_log_recv_vdm(port, cnt, payload);
|
||||
break;
|
||||
#endif /* CONFIG_USB_PD_LOGGING */
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifdef CONFIG_USB_PD_ALT_MODE_DFP
|
||||
static int dp_flags[CONFIG_USB_PD_PORT_COUNT];
|
||||
static uint32_t dp_status[CONFIG_USB_PD_PORT_COUNT];
|
||||
|
||||
static void svdm_safe_dp_mode(int port)
|
||||
{
|
||||
/* make DP interface safe until configure */
|
||||
dp_flags[port] = 0;
|
||||
dp_status[port] = 0;
|
||||
usb_mux_set(port, TYPEC_MUX_NONE,
|
||||
USB_SWITCH_CONNECT, pd_get_polarity(port));
|
||||
}
|
||||
|
||||
static int svdm_enter_dp_mode(int port, uint32_t mode_caps)
|
||||
{
|
||||
/* Only enter mode if device is DFP_D capable */
|
||||
if (mode_caps & MODE_DP_SNK) {
|
||||
svdm_safe_dp_mode(port);
|
||||
return 0;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
static int svdm_dp_status(int port, uint32_t *payload)
|
||||
{
|
||||
int opos = pd_alt_mode(port, USB_SID_DISPLAYPORT);
|
||||
|
||||
payload[0] = VDO(USB_SID_DISPLAYPORT, 1,
|
||||
CMD_DP_STATUS | VDO_OPOS(opos));
|
||||
payload[1] = VDO_DP_STATUS(0, /* HPD IRQ ... not applicable */
|
||||
0, /* HPD level ... not applicable */
|
||||
0, /* exit DP? ... no */
|
||||
0, /* usb mode? ... no */
|
||||
0, /* multi-function ... no */
|
||||
(!!(dp_flags[port] & DP_FLAGS_DP_ON)),
|
||||
0, /* power low? ... no */
|
||||
(!!(dp_flags[port] & DP_FLAGS_DP_ON)));
|
||||
return 2;
|
||||
};
|
||||
|
||||
static int svdm_dp_config(int port, uint32_t *payload)
|
||||
{
|
||||
int opos = pd_alt_mode(port, USB_SID_DISPLAYPORT);
|
||||
int mf_pref = PD_VDO_DPSTS_MF_PREF(dp_status[port]);
|
||||
int pin_mode = pd_dfp_dp_get_pin_mode(port, dp_status[port]);
|
||||
|
||||
if (!pin_mode)
|
||||
return 0;
|
||||
|
||||
usb_mux_set(port, mf_pref ? TYPEC_MUX_DOCK : TYPEC_MUX_DP,
|
||||
USB_SWITCH_CONNECT, pd_get_polarity(port));
|
||||
|
||||
payload[0] = VDO(USB_SID_DISPLAYPORT, 1,
|
||||
CMD_DP_CONFIG | VDO_OPOS(opos));
|
||||
payload[1] = VDO_DP_CFG(pin_mode, /* pin mode */
|
||||
1, /* DPv1.3 signaling */
|
||||
2); /* UFP connected */
|
||||
return 2;
|
||||
};
|
||||
|
||||
static void svdm_dp_post_config(int port)
|
||||
{
|
||||
const struct usb_mux *mux = &usb_muxes[port];
|
||||
|
||||
dp_flags[port] |= DP_FLAGS_DP_ON;
|
||||
if (!(dp_flags[port] & DP_FLAGS_HPD_HI_PENDING))
|
||||
return;
|
||||
mux->hpd_update(port, 1, 0);
|
||||
}
|
||||
|
||||
static int svdm_dp_attention(int port, uint32_t *payload)
|
||||
{
|
||||
int lvl = PD_VDO_DPSTS_HPD_LVL(payload[1]);
|
||||
int irq = PD_VDO_DPSTS_HPD_IRQ(payload[1]);
|
||||
const struct usb_mux *mux = &usb_muxes[port];
|
||||
|
||||
dp_status[port] = payload[1];
|
||||
if (!(dp_flags[port] & DP_FLAGS_DP_ON)) {
|
||||
if (lvl)
|
||||
dp_flags[port] |= DP_FLAGS_HPD_HI_PENDING;
|
||||
return 1;
|
||||
}
|
||||
mux->hpd_update(port, lvl, irq);
|
||||
|
||||
/* ack */
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void svdm_exit_dp_mode(int port)
|
||||
{
|
||||
const struct usb_mux *mux = &usb_muxes[port];
|
||||
|
||||
svdm_safe_dp_mode(port);
|
||||
mux->hpd_update(port, 0, 0);
|
||||
}
|
||||
|
||||
static int svdm_enter_gfu_mode(int port, uint32_t mode_caps)
|
||||
{
|
||||
/* Always enter GFU mode */
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void svdm_exit_gfu_mode(int port)
|
||||
{
|
||||
}
|
||||
|
||||
static int svdm_gfu_status(int port, uint32_t *payload)
|
||||
{
|
||||
/*
|
||||
* This is called after enter mode is successful, send unstructured
|
||||
* VDM to read info.
|
||||
*/
|
||||
pd_send_vdm(port, USB_VID_GOOGLE, VDO_CMD_READ_INFO, NULL, 0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int svdm_gfu_config(int port, uint32_t *payload)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int svdm_gfu_attention(int port, uint32_t *payload)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
const struct svdm_amode_fx supported_modes[] = {
|
||||
{
|
||||
.svid = USB_SID_DISPLAYPORT,
|
||||
.enter = &svdm_enter_dp_mode,
|
||||
.status = &svdm_dp_status,
|
||||
.config = &svdm_dp_config,
|
||||
.post_config = &svdm_dp_post_config,
|
||||
.attention = &svdm_dp_attention,
|
||||
.exit = &svdm_exit_dp_mode,
|
||||
},
|
||||
{
|
||||
.svid = USB_VID_GOOGLE,
|
||||
.enter = &svdm_enter_gfu_mode,
|
||||
.status = &svdm_gfu_status,
|
||||
.config = &svdm_gfu_config,
|
||||
.attention = &svdm_gfu_attention,
|
||||
.exit = &svdm_exit_gfu_mode,
|
||||
}
|
||||
};
|
||||
const int supported_modes_cnt = ARRAY_SIZE(supported_modes);
|
||||
#endif /* CONFIG_USB_PD_ALT_MODE_DFP */
|
||||
@@ -358,7 +358,9 @@ void system_check_reset_cause(void)
|
||||
|
||||
/* Use scratch bit to check power on reset or VCC1_RST reset */
|
||||
if (!IS_BIT_SET(NPCX_RSTCTL, NPCX_RSTCTL_VCC1_RST_SCRATCH)) {
|
||||
#if defined(BOARD_WHEATLEY) || defined(BOARD_EVE) || defined(BOARD_POPPY) || defined(BOARD_SORAKA)
|
||||
#if defined(BOARD_WHEATLEY) || defined(BOARD_EVE) || defined(BOARD_POPPY) || defined(BOARD_SORAKA)\
|
||||
|| defined(BOARD_NAUTILUS)
|
||||
|
||||
/* TODO(crosbug.com/p/61028): Remove workaround for Eve */
|
||||
flags |= RESET_FLAG_RESET_PIN;
|
||||
#else
|
||||
|
||||
@@ -113,6 +113,7 @@ BOARDS_NPCX_SPI=(
|
||||
glkrvp
|
||||
gru
|
||||
kevin
|
||||
nautilus
|
||||
nefario
|
||||
poppy
|
||||
reef
|
||||
@@ -150,6 +151,7 @@ BOARDS_RAIDEN=(
|
||||
fizz
|
||||
gru
|
||||
kevin
|
||||
nautilus
|
||||
nefario
|
||||
poppy
|
||||
reef
|
||||
|
||||
Reference in New Issue
Block a user