Pyro: Create initial board

Create initial pyro EC code, by copy from reef

BUG=chrome-os-partner:58062
BRANCH=None
TEST=make buildall

Change-Id: Iaae8db11845675421b653d4762d235229bb7c50d
Signed-off-by: Bruce.Wan <Bruce.Wan@quantatw.com>
Reviewed-on: https://chromium-review.googlesource.com/393706
Commit-Ready: Keith Tzeng <keith.tzeng@quantatw.com>
Tested-by: Keith Tzeng <keith.tzeng@quantatw.com>
Reviewed-by: Shawn N <shawnn@chromium.org>
This commit is contained in:
Bruce
2016-10-05 17:53:54 +08:00
committed by chrome-bot
parent 16ab1b69c6
commit a465405302
9 changed files with 2503 additions and 0 deletions

329
board/pyro/battery.c Normal file
View File

@@ -0,0 +1,329 @@
/* 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.
*
* Battery pack vendor provided charging profile
*/
#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 "i2c.h"
#include "util.h"
/* Shutdown mode parameter to write to manufacturer access register */
#define PARAM_CUT_OFF_LOW 0x10
#define PARAM_CUT_OFF_HIGH 0x00
/* Battery info for BQ40Z55 */
static const struct battery_info info = {
/* FIXME(dhendrix): where do these values come from? */
.voltage_max = 8700, /* mV */
.voltage_normal = 7600,
.voltage_min = 6100,
.precharge_current = 256, /* mA */
.start_charging_min_c = 0,
.start_charging_max_c = 46,
.charging_min_c = 0,
.charging_max_c = 60,
.discharging_min_c = 0,
.discharging_max_c = 60,
};
#ifdef CONFIG_BATTERY_PRESENT_CUSTOM
static inline enum battery_present battery_hw_present(void)
{
/* The GPIO is low when the battery is physically present */
return gpio_get_level(GPIO_EC_BATT_PRES_L) ? BP_NO : BP_YES;
}
#endif
const struct battery_info *battery_get_info(void)
{
return &info;
}
int board_cut_off_battery(void)
{
int rv;
uint8_t buf[3];
/* Ship mode command must be sent twice to take effect */
buf[0] = SB_MANUFACTURER_ACCESS & 0xff;
buf[1] = PARAM_CUT_OFF_LOW;
buf[2] = PARAM_CUT_OFF_HIGH;
i2c_lock(I2C_PORT_BATTERY, 1);
rv = i2c_xfer(I2C_PORT_BATTERY, BATTERY_ADDR, buf, 3, NULL, 0,
I2C_XFER_SINGLE);
rv |= i2c_xfer(I2C_PORT_BATTERY, BATTERY_ADDR, buf, 3, NULL, 0,
I2C_XFER_SINGLE);
i2c_lock(I2C_PORT_BATTERY, 0);
return rv;
}
enum battery_disconnect_state battery_get_disconnect_state(void)
{
uint8_t data[6];
int rv;
/*
* Take note if we find that the battery isn't in disconnect state,
* and always return NOT_DISCONNECTED without probing the battery.
* This assumes the battery will not go to disconnect state during
* runtime.
*/
static int not_disconnected;
if (not_disconnected)
return BATTERY_NOT_DISCONNECTED;
if (extpower_is_present()) {
/* Check if battery charging + discharging is disabled. */
rv = sb_write(SB_MANUFACTURER_ACCESS,
PARAM_OPERATION_STATUS);
if (rv)
return BATTERY_DISCONNECT_ERROR;
rv = sb_read_string(I2C_PORT_BATTERY, BATTERY_ADDR,
SB_ALT_MANUFACTURER_ACCESS, data, 6);
if (rv || (~data[3] & (BATTERY_DISCHARGING_DISABLED |
BATTERY_CHARGING_DISABLED))) {
not_disconnected = 1;
return BATTERY_NOT_DISCONNECTED;
}
/*
* Battery is neither charging nor discharging. Verify that
* we didn't enter this state due to a safety fault.
*/
rv = sb_write(SB_MANUFACTURER_ACCESS, PARAM_SAFETY_STATUS);
if (rv)
return BATTERY_DISCONNECT_ERROR;
rv = sb_read_string(I2C_PORT_BATTERY, BATTERY_ADDR,
SB_ALT_MANUFACTURER_ACCESS, data, 6);
if (rv || data[2] || data[3] || data[4] || data[5])
return BATTERY_DISCONNECT_ERROR;
/*
* Battery is present and also the status is initialized and
* no safety fault, battery is disconnected.
*/
if (battery_is_present() == BP_YES)
return BATTERY_DISCONNECTED;
}
not_disconnected = 1;
return BATTERY_NOT_DISCONNECTED;
}
#ifdef CONFIG_CHARGER_PROFILE_OVERRIDE
static int fast_charging_allowed = 1;
/*
* This can override the smart battery's charging profile. To make a change,
* modify one or more of requested_voltage, requested_current, or state.
* Leave everything else unchanged.
*
* Return the next poll period in usec, or zero to use the default (which is
* state dependent).
*/
int charger_profile_override(struct charge_state_data *curr)
{
/* temp in 0.1 deg C */
int temp_c = curr->batt.temperature - 2731;
/* keep track of last temperature range for hysteresis */
static enum {
TEMP_RANGE_1,
TEMP_RANGE_2,
TEMP_RANGE_3,
TEMP_RANGE_4,
TEMP_RANGE_5,
} temp_range = TEMP_RANGE_3;
/* keep track of last voltage range for hysteresis */
static enum {
VOLTAGE_RANGE_LOW,
VOLTAGE_RANGE_HIGH,
} voltage_range = VOLTAGE_RANGE_LOW;
/* Current and previous battery voltage */
int batt_voltage;
static int prev_batt_voltage;
/*
* Determine temperature range. The five ranges are:
* < 10C
* 10-15C
* 15-23C
* 23-45C
* > 45C
*
* Add 0.2 degrees of hysteresis.
* If temp reading was bad, use last range.
*/
if (!(curr->batt.flags & BATT_FLAG_BAD_TEMPERATURE)) {
if (temp_c < 99)
temp_range = TEMP_RANGE_1;
else if (temp_c > 101 && temp_c < 149)
temp_range = TEMP_RANGE_2;
else if (temp_c > 151 && temp_c < 229)
temp_range = TEMP_RANGE_3;
else if (temp_c > 231 && temp_c < 449)
temp_range = TEMP_RANGE_4;
else if (temp_c > 451)
temp_range = TEMP_RANGE_5;
}
/*
* If battery voltage reading is bad, use the last reading. Otherwise,
* determine voltage range with hysteresis.
*/
if (curr->batt.flags & BATT_FLAG_BAD_VOLTAGE) {
batt_voltage = prev_batt_voltage;
} else {
batt_voltage = prev_batt_voltage = curr->batt.voltage;
if (batt_voltage < 8200)
voltage_range = VOLTAGE_RANGE_LOW;
else if (batt_voltage > 8300)
voltage_range = VOLTAGE_RANGE_HIGH;
}
/*
* If we are not charging or we aren't using fast charging profiles,
* then do not override desired current and voltage.
*/
if (curr->state != ST_CHARGE || !fast_charging_allowed)
return 0;
/*
* Okay, impose our custom will:
* When battery is 0-10C:
* CC at 486mA @ 8.7V
* CV at 8.7V
*
* When battery is <15C:
* CC at 1458mA @ 8.7V
* CV at 8.7V
*
* When battery is <23C:
* CC at 3402mA until 8.3V @ 8.7V
* CC at 2430mA @ 8.7V
* CV at 8.7V
*
* When battery is <45C:
* CC at 4860mA until 8.3V @ 8.7V
* CC at 2430mA @ 8.7V
* CV at 8.7V until current drops to 450mA
*
* When battery is >45C:
* CC at 2430mA @ 8.3V
* CV at 8.3V (when battery is hot we don't go to fully charged)
*/
switch (temp_range) {
case TEMP_RANGE_1:
curr->requested_current = 486;
curr->requested_voltage = 8700;
break;
case TEMP_RANGE_2:
curr->requested_current = 1458;
curr->requested_voltage = 8700;
break;
case TEMP_RANGE_3:
curr->requested_voltage = 8700;
if (voltage_range == VOLTAGE_RANGE_HIGH)
curr->requested_current = 2430;
else
curr->requested_current = 3402;
break;
case TEMP_RANGE_4:
curr->requested_voltage = 8700;
if (voltage_range == VOLTAGE_RANGE_HIGH)
curr->requested_current = 2430;
else
curr->requested_current = 4860;
break;
case TEMP_RANGE_5:
curr->requested_current = 2430;
curr->requested_voltage = 8300;
break;
}
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)
{
if (param == PARAM_FASTCHARGE) {
*value = fast_charging_allowed;
return EC_RES_SUCCESS;
}
return EC_RES_INVALID_PARAM;
}
enum ec_status charger_profile_override_set_param(uint32_t param,
uint32_t value)
{
if (param == PARAM_FASTCHARGE) {
fast_charging_allowed = value;
return EC_RES_SUCCESS;
}
return EC_RES_INVALID_PARAM;
}
static int command_fastcharge(int argc, char **argv)
{
if (argc > 1 && !parse_bool(argv[1], &fast_charging_allowed))
return EC_ERROR_PARAM1;
ccprintf("fastcharge %s\n", fast_charging_allowed ? "on" : "off");
return EC_SUCCESS;
}
DECLARE_CONSOLE_COMMAND(fastcharge, command_fastcharge,
"[on|off]",
"Get or set fast charging profile");
#endif /* CONFIG_CHARGER_PROFILE_OVERRIDE */
#ifdef CONFIG_BATTERY_PRESENT_CUSTOM
/*
* Physical detection of battery.
*/
enum battery_present battery_is_present(void)
{
enum battery_present batt_pres;
int batt_status;
/* 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.
*
* 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 && !battery_status(&batt_status))
if (!(batt_status & STATUS_INITIALIZED))
batt_pres = BP_NO;
return batt_pres;
}
#endif

1080
board/pyro/board.c Normal file

File diff suppressed because it is too large Load Diff

304
board/pyro/board.h Normal file
View File

@@ -0,0 +1,304 @@
/* 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.
*/
/* Pyro board configuration */
#ifndef __CROS_EC_BOARD_H
#define __CROS_EC_BOARD_H
/* FIXME: Gross hack. Remove it once proto boards are obsolete. */
#define IS_PROTO 0
/*
* Allow dangerous commands.
* TODO: Remove this config before production.
*/
#define CONFIG_SYSTEM_UNLOCKED
/*
* 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
/* EC console commands */
#define CONFIG_CMD_ACCELS
#define CONFIG_CMD_CHARGER_ADC_AMON_BMON
#define CONFIG_CHARGER_SENSE_RESISTOR 10
#define CONFIG_CHARGER_SENSE_RESISTOR_AC 10
#define BD9995X_IOUT_GAIN_SELECT \
BD9995X_CMD_PMON_IOUT_CTRL_SET_IOUT_GAIN_SET_20V
#define CONFIG_CMD_CHARGER_PSYS
#define BD9995X_PSYS_GAIN_SELECT \
BD9995X_CMD_PMON_IOUT_CTRL_SET_PMON_GAIN_SET_02UAW
#define CONFIG_CMD_I2C_STRESS_TEST
#define CONFIG_CMD_I2C_STRESS_TEST_ACCEL
#define CONFIG_CMD_I2C_STRESS_TEST_ALS
#define CONFIG_CMD_I2C_STRESS_TEST_BATTERY
#define CONFIG_CMD_I2C_STRESS_TEST_CHARGER
#define CONFIG_CMD_I2C_STRESS_TEST_TCPC
/* Battery */
#define CONFIG_BATTERY_DEVICE_CHEMISTRY "LION"
#define CONFIG_BATTERY_CUT_OFF
#define CONFIG_BATTERY_PRESENT_CUSTOM
#define CONFIG_BATTERY_REVIVE_DISCONNECT
#define CONFIG_BATTERY_SMART
/* Charger */
#define CONFIG_CHARGE_MANAGER
#define CONFIG_CHARGE_RAMP
#define CONFIG_CHARGER
#define CONFIG_CHARGER_V2
#define CONFIG_CHARGER_BD99956
#define CONFIG_CHARGER_DISCHARGE_ON_AC
#define CONFIG_CHARGER_INPUT_CURRENT 512
#define CONFIG_CHARGER_LIMIT_POWER_THRESH_BAT_PCT 1
#define CONFIG_CHARGER_LIMIT_POWER_THRESH_CHG_MW 15000
#define CONFIG_CHARGER_MIN_BAT_PCT_FOR_POWER_ON 1
#define CONFIG_CHARGER_NARROW_VDC
#define CONFIG_USB_CHARGER
#define CONFIG_CHARGE_MANAGER_EXTERNAL_POWER_LIMIT
/* USB-A config */
#define CONFIG_USB_PORT_POWER_SMART
#define CONFIG_USB_PORT_POWER_SMART_SIMPLE
#undef CONFIG_USB_PORT_POWER_SMART_PORT_COUNT
#define CONFIG_USB_PORT_POWER_SMART_PORT_COUNT 1
#define GPIO_USB_ILIM_SEL GPIO_USB_A_CHARGE_EN_L
#define GPIO_USB_CTL1 GPIO_EN_PP5000
/* USB PD config */
#define CONFIG_CASE_CLOSED_DEBUG_EXTERNAL
#define CONFIG_CMD_PD_CONTROL
#define CONFIG_USB_PD_ALT_MODE
#define CONFIG_USB_PD_ALT_MODE_DFP
#define CONFIG_USB_PD_CUSTOM_VDM
#define CONFIG_USB_PD_DUAL_ROLE
#define CONFIG_USB_PD_DISCHARGE
#define CONFIG_USB_PD_DISCHARGE_TCPC
#define CONFIG_USB_PD_LOGGING
#define CONFIG_USB_PD_LOG_SIZE 512
#define CONFIG_USB_PD_PORT_COUNT 2
#define CONFIG_USB_PD_QUIRK_SLOW_CC_STATUS
#define CONFIG_USB_PD_VBUS_DETECT_CHARGER
#define CONFIG_USB_PD_TCPC_FW_VERSION
#define CONFIG_USB_PD_TCPM_MUX /* for both PS8751 and ANX3429 */
#define CONFIG_USB_PD_TCPM_ANX74XX
#define CONFIG_USB_PD_TCPM_PS8751
#define CONFIG_USB_PD_TCPM_TCPCI
#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
/* SoC / PCH */
#define CONFIG_LPC
#define CONFIG_CHIPSET_APOLLOLAKE
#define CONFIG_CHIPSET_RESET_HOOK
#undef CONFIG_PECI
#define CONFIG_POWER_BUTTON
#define CONFIG_POWER_BUTTON_X86
#define CONFIG_POWER_COMMON
/* EC */
#define CONFIG_ADC
#define CONFIG_BOARD_VERSION
#define CONFIG_BOARD_SPECIFIC_VERSION
#define CONFIG_BUTTON_COUNT 2
#define CONFIG_EXTPOWER_GPIO
#undef CONFIG_EXTPOWER_DEBOUNCE_MS
#define CONFIG_EXTPOWER_DEBOUNCE_MS 1000
#define CONFIG_FPU
#define CONFIG_HOSTCMD_FLASH_SPI_INFO
#define CONFIG_I2C
#define CONFIG_I2C_MASTER
#define CONFIG_KEYBOARD_PROTOCOL_8042
#define CONFIG_KEYBOARD_COL2_INVERTED
#define CONFIG_KEYBOARD_PWRBTN_ASSERTS_KSI2
#define CONFIG_LED_COMMON
#define CONFIG_LID_SWITCH
/* #define CONFIG_LOW_POWER_IDLE */
#define CONFIG_LTO
#define CONFIG_POWER_SIGNAL_INTERRUPT_STORM_DETECT_THRESHOLD 30
#define CONFIG_PWM
#define CONFIG_TEMP_SENSOR
#define CONFIG_THERMISTOR_NCP15WB
#define CONFIG_DPTF
#define CONFIG_SCI_GPIO GPIO_PCH_SCI_L
#define CONFIG_UART_HOST 0
#define CONFIG_VBOOT_HASH
#define CONFIG_WIRELESS
#define CONFIG_WIRELESS_SUSPEND EC_WIRELESS_SWITCH_WLAN_POWER
#define CONFIG_WLAN_POWER_ACTIVE_LOW
#define WIRELESS_GPIO_WLAN_POWER GPIO_WIRELESS_GPIO_WLAN_POWER
#define CONFIG_FLASH_SIZE 524288
#define CONFIG_SPI_FLASH_W25Q40 /* FIXME: Should be GD25LQ40? */
/*
* Enable 1 slot of secure temporary storage to support
* suspend/resume with read/write memory training.
*/
#define CONFIG_VSTORE
#define CONFIG_VSTORE_SLOT_COUNT 1
/* Optional feature - used by nuvoton */
#define NPCX_UART_MODULE2 1 /* 0:GPIO10/11 1:GPIO64/65 as UART */
#define NPCX_JTAG_MODULE2 0 /* 0:GPIO21/17/16/20 1:GPIOD5/E2/D4/E5 as JTAG*/
/*
* FIXME(dhendrix): these pins are just normal GPIOs on Pyro. Do we need
* to change some other setting to put them in GPIO mode?
*/
#define NPCX_TACH_SEL2 0 /* 0:GPIO40/A4 1:GPIO93/D3 as TACH */
/* I2C ports */
#define I2C_PORT_GYRO NPCX_I2C_PORT1
#define I2C_PORT_LID_ACCEL NPCX_I2C_PORT2
#define I2C_PORT_ALS NPCX_I2C_PORT2
#define I2C_PORT_BARO NPCX_I2C_PORT2
#define I2C_PORT_BATTERY NPCX_I2C_PORT3
#define I2C_PORT_CHARGER NPCX_I2C_PORT3
/* Accelerometer and Gyroscope are the same device. */
#define I2C_PORT_ACCEL I2C_PORT_GYRO
/* Sensors */
#define CONFIG_MKBP_EVENT
#define CONFIG_MKBP_USE_HOST_EVENT
#define CONFIG_ACCELGYRO_BMI160
#define CONFIG_MAG_BMI160_BMM150
#define BMM150_I2C_ADDRESS BMM150_ADDR0 /* 8-bit address */
#define CONFIG_MAG_CALIBRATE
#define CONFIG_ACCEL_KX022
#define CONFIG_ALS
#define CONFIG_ALS_OPT3001
#define OPT3001_I2C_ADDR OPT3001_I2C_ADDR1
#define CONFIG_BARO_BMP280
/* #define CONFIG_LID_ANGLE */ /* FIXME(dhendrix): maybe? */
/* #define CONFIG_LID_ANGLE_SENSOR_BASE 0 */ /* FIXME(dhendrix): maybe? */
/* #define CONFIG_LID_ANGLE_SENSOR_LID 2 */ /* FIXME(dhendrix): maybe? */
/* 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)
#ifndef __ASSEMBLER__
#include "gpio_signal.h"
#include "registers.h"
/* ADC signal */
enum adc_channel {
ADC_TEMP_SENSOR_CHARGER, /* ADC0 */
ADC_TEMP_SENSOR_AMB, /* ADC1 */
ADC_BOARD_ID, /* ADC2 */
ADC_CH_COUNT
};
enum pwm_channel {
PWM_CH_LED_GREEN = 0,
PWM_CH_LED_RED,
/* Number of PWM channels */
PWM_CH_COUNT
};
enum power_signal {
X86_RSMRST_N = 0,
X86_SLP_S0_N,
X86_SLP_S3_N,
X86_SLP_S4_N,
X86_SUSPWRDNACK,
X86_ALL_SYS_PG, /* PMIC_EC_PWROK_OD */
X86_PGOOD_PP3300, /* GPIO_PP3300_PG */
X86_PGOOD_PP5000, /* GPIO_PP5000_PG */
/* Number of X86 signals */
POWER_SIGNAL_COUNT
};
enum temp_sensor_id {
TEMP_SENSOR_BATTERY = 0,
TEMP_SENSOR_AMBIENT,
TEMP_SENSOR_CHARGER,
TEMP_SENSOR_COUNT
};
/* Light sensors */
enum als_id {
ALS_OPT3001 = 0,
ALS_COUNT
};
/* Motion sensors */
enum sensor_id {
BASE_ACCEL = 0,
BASE_GYRO,
BASE_MAG,
LID_ACCEL,
BASE_BARO,
};
enum pyro_board_version {
BOARD_VERSION_UNKNOWN = -1,
BOARD_VERSION_1,
BOARD_VERSION_2,
BOARD_VERSION_3,
BOARD_VERSION_4,
BOARD_VERSION_5,
BOARD_VERSION_6,
BOARD_VERSION_7,
BOARD_VERSION_8,
BOARD_VERSION_COUNT,
};
/* start as a sink in case we have no other power supply/battery */
#define PD_DEFAULT_STATE PD_STATE_SNK_DISCONNECTED
/* TODO: determine the following board specific type-C power constants */
/* FIXME(dhendrix): verify all of the below PD_* numbers */
/*
* 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
/* Reset PD MCU */
void board_reset_pd_mcu(void);
int board_get_version(void);
void board_set_tcpc_power_mode(int port, int mode);
void board_print_tcpc_fw_version(int port);
/* Sensors without hardware FIFO are in forced mode */
#define CONFIG_ACCEL_FORCE_MODE_MASK \
((1 << LID_ACCEL) | (1 << BASE_BARO))
#endif /* !__ASSEMBLER__ */
#endif /* __CROS_EC_BOARD_H */

14
board/pyro/build.mk Normal file
View File

@@ -0,0 +1,14 @@
# -*- 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_VARIANT:=npcx5m6g
board-y=board.o led.o
board-$(CONFIG_BATTERY_SMART)+=battery.o
board-$(CONFIG_USB_POWER_DELIVERY)+=usb_pd_policy.o

39
board/pyro/ec.tasklist Normal file
View File

@@ -0,0 +1,39 @@
/* 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(CHG_RAMP, chg_ramp_task, NULL, TASK_STACK_SIZE) \
TASK_ALWAYS(USB_CHG, usb_charger_task, NULL, TASK_STACK_SIZE) \
TASK_ALWAYS(CHARGER, charger_task, NULL, LARGER_TASK_STACK_SIZE) \
TASK_NOTEST(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, 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)

186
board/pyro/gpio.inc Normal file
View File

@@ -0,0 +1,186 @@
/* -*- 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(CHARGER_INT_L, PIN(3, 3), GPIO_INT_FALLING, bd9995x_vbus_interrupt) /* CHARGER_EC_INT_ODL from BD99956 */
/*
* TODO: The pull ups for Parade TCPC interrupt line can be removed in versions
* of board following EVT in which daughter card (which has an external pull up)
* will always be inserted.
*/
#if IS_PROTO == 1
GPIO_INT(USB_C0_PD_INT_ODL, PIN(3, 7), GPIO_INT_RISING, tcpc_alert_event) /* from Analogix TCPC */
GPIO_INT(USB_C1_PD_INT_ODL, PIN(D, 2), GPIO_INT_FALLING | GPIO_PULL_UP, tcpc_alert_event) /* from Parade TCPC */
#else
GPIO_INT(USB_C0_PD_INT_ODL, PIN(3, 7), GPIO_INT_FALLING, tcpc_alert_event) /* from Analogix TCPC */
GPIO_INT(USB_C1_PD_INT_ODL, PIN(B, 1), GPIO_INT_FALLING | GPIO_PULL_UP, tcpc_alert_event) /* from Parade TCPC */
#endif
GPIO_INT(PCH_SLP_S4_L, PIN(8, 6), GPIO_INT_BOTH, power_signal_interrupt) /* SLP_S4_L */
GPIO_INT(PCH_SLP_S3_L, PIN(7, 3), GPIO_INT_BOTH, power_signal_interrupt) /* SLP_S3_L */
GPIO_INT(PCH_SLP_S0_L, PIN(7, 5), GPIO_INT_BOTH, power_signal_interrupt) /* SLP_S0_L */
GPIO_INT(SUSPWRNACK, PIN(7, 2), GPIO_INT_BOTH, power_signal_interrupt)
GPIO_INT(RSMRST_L_PGOOD, PIN(6, 0), GPIO_INT_BOTH, power_signal_interrupt) /* PMIC_EC_RSMRST_ODL */
GPIO_INT(ALL_SYS_PGOOD, PIN(5, 0), GPIO_INT_BOTH, power_signal_interrupt) /* PMIC_EC_PWROK_OD */
GPIO_INT(AC_PRESENT, PIN(C, 1), GPIO_INT_BOTH, extpower_interrupt) /* ACOK_OD from BD99956 */
/* TODO: We might remove external pull-up for POWER_BUTTON_L in EVT */
GPIO_INT(POWER_BUTTON_L, PIN(0, 4), GPIO_INT_BOTH, power_button_interrupt) /* MECH_PWR_BTN_ODL */
#if IS_PROTO == 1
GPIO_INT(LID_OPEN, PIN(6, 7), GPIO_INT_BOTH | GPIO_PULL_UP, lid_interrupt)
#else
GPIO_INT(LID_OPEN, PIN(6, 7), GPIO_INT_BOTH, lid_interrupt)
#endif
GPIO_INT(EC_VOLDN_BTN_ODL, PIN(8, 3), GPIO_INT_BOTH | GPIO_PULL_UP, button_interrupt)
GPIO_INT(EC_VOLUP_BTN_ODL, PIN(8, 2), GPIO_INT_BOTH | GPIO_PULL_UP, button_interrupt)
GPIO_INT(TABLET_MODE, PIN(3, 6), GPIO_INT_BOTH, tablet_mode_interrupt)
GPIO_INT(WP_L, PIN(4, 0), GPIO_INT_BOTH | GPIO_SEL_1P8V, switch_interrupt) /* EC_WP_ODL */
/* FIXME(dhendrix): Implement interrupt handlers for lid, tablet mode, etc. */
//GPIO_INT(BASE_SIXAXIS_INT_L, PIN(9, 3), GPIO_INT_LOW | GPIO_SEL_1P8V, gyro_interrupt)
GPIO(BASE_SIXAXIS_INT_L, PIN(9, 3), GPIO_INPUT | GPIO_SEL_1P8V)
//GPIO_INT(LID_ACCEL_INT_L, PIN(C, 7), GPIO_INT_LOW | GPIO_SEL_1P8V, lid_interrupt)
GPIO(LID_ACCEL_INT_L, PIN(C, 7), GPIO_INPUT | GPIO_SEL_1P8V)
/* I2C GPIOs will be set to alt. function later. */
GPIO(EC_I2C_GYRO_SDA, PIN(8, 7), GPIO_INPUT | GPIO_SEL_1P8V)
GPIO(EC_I2C_GYRO_SCL, PIN(9, 0), GPIO_INPUT | GPIO_SEL_1P8V)
GPIO(EC_I2C_SENSOR_SDA, PIN(9, 1), GPIO_INPUT | GPIO_SEL_1P8V)
GPIO(EC_I2C_SENSOR_SCL, PIN(9, 2), GPIO_INPUT | GPIO_SEL_1P8V)
GPIO(EC_I2C_USB_C0_PD_SDA, PIN(B, 4), GPIO_INPUT)
GPIO(EC_I2C_USB_C0_PD_SCL, PIN(B, 5), GPIO_INPUT)
GPIO(EC_I2C_USB_C1_PD_SDA, PIN(B, 2), GPIO_INPUT)
GPIO(EC_I2C_USB_C1_PD_SCL, PIN(B, 3), GPIO_INPUT)
GPIO(EC_I2C_POWER_SDA, PIN(D, 0), GPIO_INPUT)
GPIO(EC_I2C_POWER_SCL, PIN(D, 1), GPIO_INPUT)
/*
* LPC:
* Pins 46, 47, 51, 52, 53, 54, 55, default to LPC mode.
* Pin 56 (CLKRUN#) defaults to GPIO mode.
* Pin 57 (SER_IRQ) defaults to LPC mode, but we also have EC_PCH_KB_INT_ODL
* (Pin B0) in case it doesn't work (Set CONFIG_KEYBOARD_IRQ_GPIO in this case).
*
* See also the NO_LPC_ESPI bit in DEVALT1 and the CONFIG_HOSTCMD_SPS option.
*/
GPIO(PCH_SMI_L, PIN(A, 6), GPIO_ODR_HIGH | GPIO_SEL_1P8V) /* EC_SMI_ODL */
GPIO(PCH_SCI_L, PIN(A, 7), GPIO_ODR_HIGH | GPIO_SEL_1P8V) /* EC_SCI_ODL */
/*
* BRD_ID1 is a an ADC pin which will be used to measure multiple values.
* Assert EC_BRD_ID_EN_ODL and then read BRD_ID1.
*/
ALTERNATE(PIN_MASK(4, 0x08), 1, MODULE_ADC, 0)
GPIO(EC_BRD_ID_EN_ODL, PIN(3, 5), GPIO_INPUT)
GPIO(CCD_MODE_ODL, PIN(6, 3), GPIO_INPUT)
GPIO(EC_HAVEN_RESET_ODL, PIN(0, 2), GPIO_ODR_HIGH)
GPIO(ENTERING_RW, PIN(7, 6), GPIO_OUTPUT) /* EC_ENTERING_RW */
/*
* FIXME(dhendrix): Should this be an interrupt? It's a normal input on elm.
* ANX72xx programming guide section 6 suggests it should interrupt on both
* high and low edges and we should use it to set PWR_EN and RESET_N pins.
*/
GPIO(USB_C0_CABLE_DET, PIN(C, 5), GPIO_INPUT)
GPIO(PCH_RSMRST_L, PIN(7, 0), GPIO_OUT_LOW)
GPIO(EC_BATT_PRES_L, PIN(3, 4), GPIO_INPUT)
GPIO(PMIC_EN, PIN(8, 5), GPIO_OUT_LOW)
GPIO(EN_PP3300, PIN(C, 2), GPIO_OUT_LOW)
GPIO(PP3300_PG, PIN(6, 2), GPIO_INPUT)
GPIO(EN_PP5000, PIN(C, 6), GPIO_OUT_LOW)
GPIO(PP5000_PG, PIN(7, 1), GPIO_INPUT)
GPIO(EN_P3300_TRACKPAD_ODL, PIN(3, 2), GPIO_ODR_HIGH)
GPIO(PCH_SYS_PWROK, PIN(E, 7), GPIO_OUT_LOW) /* EC_PCH_PWROK */
GPIO(ENABLE_BACKLIGHT, PIN(9, 7), GPIO_ODR_HIGH | GPIO_SEL_1P8V) /* EC_BL_EN_OD */
GPIO(WIRELESS_GPIO_WLAN_POWER, PIN(6, 6), GPIO_ODR_HIGH) /* EN_PP3300_WLAN_ODL */
/*
* PCH_PROCHOT_ODL is primarily for monitoring the PROCHOT# signal which is
* normally driven by the PMIC. The EC can also drive this signal in the event
* that the ambient or charger temperature sensors exceeds their thresholds.
*/
GPIO(CPU_PROCHOT, PIN(A, 3), GPIO_INPUT | GPIO_SEL_1P8V) /* PCH_PROCHOT_ODL */
GPIO(PCH_PWRBTN_L, PIN(0, 1), GPIO_ODR_HIGH) /* EC_PCH_PWR_BTN_ODL */
GPIO(PCH_WAKE_L, PIN(8, 1), GPIO_ODR_HIGH) /* EC_PCH_WAKE_ODL */
GPIO(USB_C0_HPD_1P8_ODL, PIN(9, 4), GPIO_INPUT | GPIO_SEL_1P8V)
GPIO(USB_C1_HPD_1P8_ODL, PIN(A, 5), GPIO_INPUT | GPIO_SEL_1P8V)
GPIO(USB2_OTG_ID, PIN(A, 1), GPIO_OUTPUT) /* FIXME: what should this init to? */
GPIO(USB2_OTG_VBUSSENSE, PIN(9, 5), GPIO_OUTPUT)
/* EC_PCH_RTCRST is a sledgehammer for resetting SoC state and should rarely
* be used. Set as input for now, we'll set it as an output when we want to use
* it. Has external pull-down resistor. */
GPIO(EC_PCH_RTCRST, PIN(B, 7), GPIO_INPUT)
GPIO(PCH_RCIN_L, PIN(6, 1), GPIO_ODR_HIGH) /* SYS_RST_ODL */
/* FIXME: What, if anything, to do about EC_RST_ODL on VCC1_RST#? */
GPIO(CHARGER_RST_ODL, PIN(C, 0), GPIO_ODR_HIGH)
GPIO(USB_A_CHARGE_EN_L, PIN(4, 2), GPIO_OUT_HIGH)
GPIO(EN_USB_TCPC_PWR, PIN(C, 3), GPIO_OUT_LOW)
GPIO(USB1_ENABLE, PIN(4, 1), GPIO_OUT_LOW)
GPIO(USB_C0_PD_RST_L, PIN(0, 3), GPIO_OUT_LOW) /* USB_C0_PD_RST_L */
#if IS_PROTO == 0
GPIO(USB_C1_PD_RST_ODL, PIN(7, 4), GPIO_ODR_LOW)
#endif
#if IS_PROTO == 1
GPIO(USB_C0_5V_EN, PIN(D, 3), GPIO_OUT_LOW) /* EN_USB_C0_5V_OUT, Enable C0 */
GPIO(USB_C1_5V_EN, PIN(B, 1), GPIO_OUT_LOW) /* EN_USB_C1_5V_OUT, Enable C1 */
#else
/*
* Configure as input to enable @ 1.5A, output-low to turn off, or output-high
* to enable @ 3A.
*/
GPIO(USB_C0_5V_EN, PIN(D, 3), GPIO_OUT_LOW) /* EN_USB_C0_5V_OUT, Enable C0 */
GPIO(USB_C1_5V_EN, PIN(D, 2), GPIO_OUT_LOW) /* EN_USB_C1_5V_OUT, Enable C1 */
#endif
/* Clear for non-HDI breakout, must be pulled high */
GPIO(NC1, PIN(0, 0), GPIO_INPUT | GPIO_PULL_UP | GPIO_SEL_1P8V)
GPIO(NC2, PIN(8, 4), GPIO_INPUT | GPIO_PULL_UP | GPIO_SEL_1P8V)
GPIO(ENG_STRAP, PIN(B, 6), GPIO_INPUT)
GPIO(BAT_LED_BLUE, PIN(8, 0), GPIO_OUT_HIGH)
GPIO(BAT_LED_AMBER, PIN(C, 4), GPIO_OUT_HIGH)
/*
* Alternate function pins
*/
/* Keyboard pins */
#define GPIO_KB_INPUT (GPIO_INPUT | GPIO_PULL_UP)
#define GPIO_KB_OUTPUT (GPIO_ODR_HIGH)
#define GPIO_KB_OUTPUT_COL2 (GPIO_OUT_LOW)
ALTERNATE(PIN_MASK(3, 0x03), 0, MODULE_KEYBOARD_SCAN, GPIO_KB_INPUT)
ALTERNATE(PIN_MASK(2, 0xfc), 0, MODULE_KEYBOARD_SCAN, GPIO_KB_INPUT)
ALTERNATE(PIN_MASK(2, 0x03), 0, MODULE_KEYBOARD_SCAN, GPIO_KB_OUTPUT)
ALTERNATE(PIN_MASK(0, 0xe0), 0, MODULE_KEYBOARD_SCAN, GPIO_KB_OUTPUT)
ALTERNATE(PIN_MASK(1, 0x7f), 0, MODULE_KEYBOARD_SCAN, GPIO_KB_OUTPUT)
GPIO(KBD_KSO2, PIN(1, 7), GPIO_KB_OUTPUT_COL2)
ALTERNATE(PIN(4, 4), 6, MODULE_ADC, 0) /* TEMP_SENSOR_AMB (FIXME: alt function 6?) */
ALTERNATE(PIN(4, 5), 6, MODULE_ADC, 0) /* TEMP_SENSOR_CHARGER (FIXME: alt function?) */
ALTERNATE(PIN_MASK(8, 0x80), 1, MODULE_I2C, 0) /* GPIO87 for EC_I2C_GYRO_SDA */
ALTERNATE(PIN_MASK(9, 0x01), 1, MODULE_I2C, 0) /* GPIO90 for EC_I2C_GYRO_SCL */
ALTERNATE(PIN_MASK(9, 0x06), 1, MODULE_I2C, 0) /* GPIO92-91 for EC_I2C_SENSOR_SDA/SCL */
ALTERNATE(PIN_MASK(B, 0x30), 1, MODULE_I2C, 0) /* GPIOB5-B4 for EC_I2C_USB_C0_PD_SDA/SCL */
ALTERNATE(PIN_MASK(B, 0x0C), 1, MODULE_I2C, 0) /* GPOPB3-B2 for EC_I2C_USB_C1_PD_SDA/SCL */
ALTERNATE(PIN_MASK(D, 0x03), 1, MODULE_I2C, 0) /* GPIOD1-D0 for EC_I2C_POWER_SDA/SCL */
/* FIXME: Make UART RX an interrupt? */
ALTERNATE(PIN_MASK(6, 0x30), 0, MODULE_UART, 0) /* UART from EC to Servo */

174
board/pyro/led.c Normal file
View File

@@ -0,0 +1,174 @@
/* 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.
*
* Power and battery LED control for Pyro
*/
#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"
#define BAT_LED_ON 0
#define BAT_LED_OFF 1
#define CRITICAL_LOW_BATTERY_PERCENTAGE 3
#define LOW_BATTERY_PERCENTAGE 10
#define LED_TOTAL_4SECS_TICKS 4
#define LED_TOTAL_2SECS_TICKS 2
#define LED_ON_1SEC_TICKS 1
#define LED_ON_2SECS_TICKS 2
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_BLUE,
LED_AMBER,
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_BLUE, BAT_LED_OFF);
gpio_set_level(GPIO_BAT_LED_AMBER, BAT_LED_OFF);
break;
case LED_BLUE:
gpio_set_level(GPIO_BAT_LED_BLUE, BAT_LED_ON);
gpio_set_level(GPIO_BAT_LED_AMBER, BAT_LED_OFF);
break;
case LED_AMBER:
gpio_set_level(GPIO_BAT_LED_BLUE, BAT_LED_OFF);
gpio_set_level(GPIO_BAT_LED_AMBER, 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_BLUE] = 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_BLUE] != 0)
led_set_color(led_id, LED_BLUE);
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 suspend_ticks;
static int previous_state_suspend;
uint32_t chflags = charge_get_flags();
battery_ticks++;
suspend_ticks++;
switch (charge_get_state()) {
case PWR_STATE_CHARGE:
led_set_color_battery(LED_AMBER);
break;
case PWR_STATE_DISCHARGE:
/* Less than 3%, blink one second every two second */
if (!chipset_in_state(CHIPSET_STATE_ANY_OFF) &&
charge_get_percent() < CRITICAL_LOW_BATTERY_PERCENTAGE)
led_set_color_battery(
(battery_ticks % LED_TOTAL_2SECS_TICKS <
LED_ON_1SEC_TICKS) ? LED_AMBER : LED_OFF);
/* Less than 10%, blink one second every four seconds */
else if (!chipset_in_state(CHIPSET_STATE_ANY_OFF) &&
charge_get_percent() < LOW_BATTERY_PERCENTAGE)
led_set_color_battery(
(battery_ticks % LED_TOTAL_4SECS_TICKS <
LED_ON_1SEC_TICKS) ? LED_AMBER : LED_OFF);
else {
if (chipset_in_state(CHIPSET_STATE_SUSPEND
| CHIPSET_STATE_STANDBY)) {
if (!previous_state_suspend)
suspend_ticks = 0;
/* Blink once every four seconds. */
led_set_color_battery(
(suspend_ticks % LED_TOTAL_4SECS_TICKS)
< LED_ON_1SEC_TICKS ?
LED_AMBER : LED_OFF);
previous_state_suspend = 1;
return;
}
if (chipset_in_state(CHIPSET_STATE_ON))
led_set_color_battery(LED_BLUE);
else
led_set_color_battery(LED_OFF);
}
break;
case PWR_STATE_ERROR:
led_set_color_battery(
(battery_ticks % LED_TOTAL_2SECS_TICKS <
LED_ON_1SEC_TICKS) ? LED_AMBER : LED_OFF);
break;
case PWR_STATE_CHARGE_NEAR_FULL:
led_set_color_battery(LED_BLUE);
break;
case PWR_STATE_IDLE: /* External power connected in IDLE */
if (chflags & CHARGE_FLAG_FORCE_IDLE)
led_set_color_battery(
(battery_ticks % LED_TOTAL_4SECS_TICKS <
LED_ON_2SECS_TICKS) ? LED_AMBER : LED_BLUE);
else
led_set_color_battery(LED_BLUE);
break;
default:
/* Other states don't alter LED behavior */
break;
}
previous_state_suspend = 0;
}
/* Called by hook task every 1 sec */
static void led_second(void)
{
/*
* Reference board only has one LED, so overload it to act as both
* power LED and battery LED.
*/
if (led_auto_control_is_enabled(EC_LED_ID_BATTERY_LED))
led_set_battery();
}
DECLARE_HOOK(HOOK_SECOND, led_second, HOOK_PRIO_DEFAULT);

374
board/pyro/usb_pd_policy.c Normal file
View File

@@ -0,0 +1,374 @@
/* 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/charger/bd9995x.h"
#include "driver/tcpm/anx74xx.h"
#include "driver/tcpm/ps8751.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"
#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: 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_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 */
}
int pd_set_power_supply_ready(int port)
{
/* Ensure we're not charging from this port */
if (charge_manager_get_active_charge_port() == port)
bd9995x_select_input_port(BD9995X_CHARGE_PORT_NONE);
/* Provide VBUS */
gpio_set_level(port ? GPIO_USB_C1_5V_EN :
GPIO_USB_C0_5V_EN, 1);
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)
{
enum gpio_signal gpio;
int prev_en;
gpio = port ? GPIO_USB_C1_5V_EN : GPIO_USB_C0_5V_EN;
prev_en = gpio_get_level(gpio);
/* Disable VBUS */
gpio_set_level(gpio, 0);
/* Enable discharge if we were previously sourcing 5V */
if (prev_en)
pd_set_vbus_discharge(port, 1);
/* notify host of power info change */
pd_send_host_event(PD_EVENT_POWER_CHANGE);
}
void pd_set_input_current_limit(int port, uint32_t max_ma,
uint32_t supply_voltage)
{
#ifdef CONFIG_CHARGE_MANAGER
struct charge_port_info charge;
charge.current = max_ma;
charge.voltage = supply_voltage;
charge_manager_update_charge(CHARGE_SUPPLIER_PD, port, &charge);
#endif
}
void typec_set_input_current_limit(int port, uint32_t max_ma,
uint32_t supply_voltage)
{
#ifdef CONFIG_CHARGE_MANAGER
struct charge_port_info charge;
charge.current = max_ma;
charge.voltage = supply_voltage;
charge_manager_update_charge(CHARGE_SUPPLIER_TYPEC, port, &charge);
#endif
}
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 */
return (data_role == PD_ROLE_UFP) ? 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_EN_PP5000);
}
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)
pd_request_data_swap(port);
}
/* ----------------- Vendor Defined Messages ------------------ */
const struct svdm_response svdm_rsp = {
.identity = NULL,
.svids = NULL,
.modes = NULL,
};
int pd_custom_vdm(int port, int cnt, uint32_t *payload,
uint32_t **rpayload)
{
int cmd = PD_VDO_CMD(payload[0]);
uint16_t dev_id = 0;
int is_rw;
/* make sure we have some payload */
if (cnt == 0)
return 0;
switch (cmd) {
case VDO_CMD_VERSION:
/* guarantee last byte of payload is null character */
*(payload + cnt - 1) = 0;
CPRINTF("version: %s\n", (char *)(payload+1));
break;
case VDO_CMD_READ_INFO:
case VDO_CMD_SEND_INFO:
/* copy hash */
if (cnt == 7) {
dev_id = VDO_INFO_HW_DEV_ID(payload[6]);
is_rw = VDO_INFO_IS_RW(payload[6]);
CPRINTF("DevId:%d.%d SW:%d RW:%d\n",
HW_DEV_ID_MAJ(dev_id),
HW_DEV_ID_MIN(dev_id),
VDO_INFO_SW_DBG_VER(payload[6]),
is_rw);
} else if (cnt == 6) {
/* really old devices don't have last byte */
pd_dev_store_rw_hash(port, dev_id, payload + 1,
SYSTEM_IMAGE_UNKNOWN);
}
break;
case VDO_CMD_CURRENT:
CPRINTF("Current: %dmA\n", payload[1]);
break;
case VDO_CMD_FLIP:
usb_mux_flip(port);
break;
#ifdef CONFIG_USB_PD_LOGGING
case VDO_CMD_GET_LOG:
pd_log_recv_vdm(port, cnt, payload);
break;
#endif /* CONFIG_USB_PD_LOGGING */
}
return 0;
}
#ifdef CONFIG_USB_PD_ALT_MODE_DFP
static int dp_flags[CONFIG_USB_PD_PORT_COUNT];
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);
usb_mux_set(port, 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(MODE_DP_PIN_E, /* 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 */

View File

@@ -104,6 +104,7 @@ BOARDS_NPCX_SPI=(
amenia
gru
kevin
pyro
reef
wheatley
)
@@ -121,12 +122,14 @@ BOARDS_MEC1322=(
BOARDS_SPI_1800MV=(
gru
kevin
pyro
reef
)
BOARDS_RAIDEN=(
gru
kevin
pyro
reef
)