diff options
author | Nicolas Boichat <drinkcat@chromium.org> | 2017-09-18 17:02:09 +0800 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2017-12-20 05:49:34 -0800 |
commit | 9a284576a822c10683ed03daa86266a94a462de9 (patch) | |
tree | 6e1cf46abfd28ad815ccf0ebafbf69229acf5b87 /board | |
parent | 764c42ca94d61fc93ca438c5cca0eac917d21457 (diff) | |
download | chrome-ec-9a284576a822c10683ed03daa86266a94a462de9.tar.gz |
wand: Add wand board
hammer derivative, with a battery.
BRANCH=none
BUG=b:66575472
TEST=make BOARD=wand -j, flash to reworked hammer board,
battery charging works.
Change-Id: I42366f4738b35c352b9be0c44a17ebeb323adfd1
Signed-off-by: Nicolas Boichat <drinkcat@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/678756
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
Diffstat (limited to 'board')
-rw-r--r-- | board/hammer/battery.c | 52 | ||||
-rw-r--r-- | board/hammer/board.c | 60 | ||||
-rw-r--r-- | board/hammer/board.h | 51 | ||||
-rw-r--r-- | board/hammer/build.mk | 1 | ||||
-rw-r--r-- | board/hammer/ec.tasklist | 11 | ||||
-rw-r--r-- | board/hammer/gpio.inc | 30 | ||||
l--------- | board/wand | 1 |
7 files changed, 194 insertions, 12 deletions
diff --git a/board/hammer/battery.c b/board/hammer/battery.c new file mode 100644 index 0000000000..4025a08b14 --- /dev/null +++ b/board/hammer/battery.c @@ -0,0 +1,52 @@ +/* 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. + */ + +#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" + +/* 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 = 8800, + .voltage_normal = 7700, + .voltage_min = 6000, + /* Pre-charge values. */ + .precharge_current = 256, /* mA */ + + .start_charging_min_c = 0, + .start_charging_max_c = 45, + .charging_min_c = 0, + .charging_max_c = 60, + .discharging_min_c = -20, + .discharging_max_c = 60, +}; + +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); +} + +/* TODO(b:66575472): Do we need to define functions like battery_is_present? */ diff --git a/board/hammer/board.c b/board/hammer/board.c index acb5ccb29d..cb6d7d836b 100644 --- a/board/hammer/board.c +++ b/board/hammer/board.c @@ -6,7 +6,7 @@ #include "common.h" #include "ec_version.h" -#include "touchpad.h" +#include "ec_ec_comm_slave.h" #include "gpio.h" #include "hooks.h" #include "hwtimer.h" @@ -16,10 +16,13 @@ #include "printf.h" #include "pwm.h" #include "pwm_chip.h" +#include "queue.h" +#include "queue_policies.h" #include "registers.h" #include "rollback.h" #include "system.h" #include "task.h" +#include "touchpad.h" #include "timer.h" #include "update_fw.h" #include "usart-stm32f0.h" @@ -60,10 +63,15 @@ BUILD_ASSERT(ARRAY_SIZE(usb_strings) == USB_STR_COUNT); */ #ifdef SECTION_IS_RW + /* I2C ports */ const struct i2c_port_t i2c_ports[] = { - {"master", I2C_PORT_MASTER, 400, - GPIO_MASTER_I2C_SCL, GPIO_MASTER_I2C_SDA}, + {"touchpad", I2C_PORT_TOUCHPAD, 400, + GPIO_TOUCHPAD_I2C_SCL, GPIO_TOUCHPAD_I2C_SDA}, +#ifdef BOARD_WAND + {"charger", I2C_PORT_CHARGER, 100, + GPIO_CHARGER_I2C_SCL, GPIO_CHARGER_I2C_SDA}, +#endif }; const unsigned int i2c_ports_used = ARRAY_SIZE(i2c_ports); @@ -101,6 +109,32 @@ struct keyboard_scan_config keyscan_config = { #endif #endif +#if defined(BOARD_WAND) && defined(SECTION_IS_RW) +struct consumer const ec_ec_usart_consumer; +static struct usart_config const ec_ec_usart; + +struct queue const ec_ec_comm_slave_input = QUEUE_DIRECT(64, uint8_t, + ec_ec_usart.producer, ec_ec_usart_consumer); +struct queue const ec_ec_comm_slave_output = QUEUE_DIRECT(64, uint8_t, + null_producer, ec_ec_usart.consumer); + +struct consumer const ec_ec_usart_consumer = { + .queue = &ec_ec_comm_slave_input, + .ops = &((struct consumer_ops const) { + .written = ec_ec_comm_slave_written, + }), +}; + +static struct usart_config const ec_ec_usart = + USART_CONFIG(EC_EC_UART, + usart_rx_interrupt, + usart_tx_interrupt, + 115200, + USART_CONFIG_FLAG_HDSEL, + ec_ec_comm_slave_input, + ec_ec_comm_slave_output); +#endif /* BOARD_WAND && SECTION_IS_RW */ + /****************************************************************************** * Initialize board. */ @@ -127,6 +161,15 @@ static void board_init(void) GPIO_PULL_DOWN | GPIO_INPUT); } #endif /* BOARD_STAFF */ + +#if defined(BOARD_WAND) && defined(SECTION_IS_RW) + /* USB to serial queues */ + queue_init(&ec_ec_comm_slave_input); + queue_init(&ec_ec_comm_slave_output); + + /* UART init */ + usart_init(&ec_ec_usart); +#endif } /* This needs to happen before PWM is initialized. */ DECLARE_HOOK(HOOK_INIT, board_init, HOOK_PRIO_INIT_PWM - 1); @@ -156,6 +199,9 @@ int board_has_keyboard_backlight(void) */ void board_usb_wake(void) { +#ifdef BOARD_WAND + /* FIXME: Implement side-band wake for wand. */ +#else /* * Poke detection pin for about 500us, we disable interrupts * to make sure that we do not get preempted (setting GPIO high @@ -168,6 +214,7 @@ void board_usb_wake(void) udelay(500); gpio_set_flags(GPIO_BASE_DET, GPIO_INPUT); interrupt_enable(); +#endif } /* @@ -224,3 +271,10 @@ int board_write_serial(const char *serialno) return 0; } +#ifdef BOARD_WAND +/* TODO(b:66575472): This assumes external power is always present. */ +int extpower_is_present(void) +{ + return 1; +} +#endif diff --git a/board/hammer/board.h b/board/hammer/board.h index 7febe92ddb..4c9675f312 100644 --- a/board/hammer/board.h +++ b/board/hammer/board.h @@ -72,11 +72,16 @@ #define CONFIG_UART_CONSOLE 1 /* Optional features */ +/* + * TODO(b:65697962): Reenable low-power-idle on wand without breaking EC-EC + * communication + */ +#ifndef BOARD_WAND #define CONFIG_LOW_POWER_IDLE +#endif #define CONFIG_LTO #define CONFIG_FORCE_CONSOLE_RESUME #define CONFIG_STM_HWTIMER32 -#define CONFIG_HW_CRC /* USB Configuration */ #define CONFIG_USB @@ -84,6 +89,8 @@ #define CONFIG_USB_PID 0x5022 #elif defined(BOARD_STAFF) #define CONFIG_USB_PID 0x502b +#elif defined(BOARD_WAND) +#define CONFIG_USB_PID 0x502d #elif defined(BOARD_WHISKERS) #define CONFIG_USB_PID 0x5030 #else @@ -160,7 +167,7 @@ #define CONFIG_TOUCHPAD_HASH_FW /* Touchpad firmware size and dimension difference */ -#ifdef BOARD_HAMMER +#if defined(BOARD_HAMMER) || defined(BOARD_WAND) #define CONFIG_USB_HID_TOUCHPAD_LOGICAL_MAX_X 3207 #define CONFIG_USB_HID_TOUCHPAD_LOGICAL_MAX_Y 1783 #define CONFIG_USB_HID_TOUCHPAD_PHYSICAL_MAX_X 1018 /* tenth of mm */ @@ -197,7 +204,8 @@ #define CONFIG_USB_I2C #define CONFIG_I2C #define CONFIG_I2C_MASTER -#define I2C_PORT_MASTER 0 +#define I2C_PORT_TOUCHPAD 0 +#define I2C_PORT_CHARGER 1 /* Enable PWM */ #define CONFIG_PWM @@ -205,13 +213,37 @@ /* Enable Elan touchpad driver */ #define CONFIG_TOUCHPAD #define CONFIG_TOUCHPAD_ELAN -#define CONFIG_TOUCHPAD_I2C_PORT 0 +#define CONFIG_TOUCHPAD_I2C_PORT I2C_PORT_TOUCHPAD #define CONFIG_TOUCHPAD_I2C_ADDR (0x15 << 1) #define CONFIG_CURVE25519 #define CONFIG_USB_PAIRING +#ifdef BOARD_WAND +/* Battery and charger options. */ +#define CONFIG_CHARGER +#define CONFIG_CHARGER_V2 +#define CONFIG_CHARGER_INPUT_CURRENT 128 +#define CONFIG_CHARGER_ISL9238 +#define CONFIG_CHARGER_SENSE_RESISTOR 10 +#define CONFIG_CHARGER_SENSE_RESISTOR_AC 20 +#define CONFIG_CHARGER_DISCHARGE_ON_AC + +#define CONFIG_BATTERY_CUT_OFF +#define CONFIG_BATTERY_SMART + +#define I2C_PORT_BATTERY I2C_PORT_CHARGER + +#define EC_EC_UART usart2_hw +#define CONFIG_STREAM_USART2 +#define CONFIG_STREAM_USART + +#define CONFIG_EC_EC_COMM_SLAVE +#define CONFIG_EC_EC_COMM_BATTERY +#define CONFIG_CRC8 +#endif /* BOARD_WAND */ + #else /* SECTION_IS_RO */ /* Sign and switch to RW partition on boot. */ #define CONFIG_RWSIG @@ -238,6 +270,12 @@ #undef CONFIG_ROLLBACK_UPDATE #endif +/* Maximum current to draw. */ +#define MAX_CURRENT_MA 2000 +/* Maximum current/voltage to provide over OTG. */ +#define MAX_OTG_CURRENT_MA 2000 +#define MAX_OTG_VOLTAGE_MV 20000 + #ifndef __ASSEMBLER__ /* Timer selection */ @@ -270,6 +308,11 @@ enum pwm_channel { /* Number of PWM channels */ PWM_CH_COUNT }; + +enum adc_channel { + /* Number of ADC channels */ + ADC_CH_COUNT +}; #endif #endif /* !__ASSEMBLER__ */ diff --git a/board/hammer/build.mk b/board/hammer/build.mk index 0e069a31ad..28652fee93 100644 --- a/board/hammer/build.mk +++ b/board/hammer/build.mk @@ -11,3 +11,4 @@ CHIP_FAMILY:=stm32f0 CHIP_VARIANT:=stm32f07x board-y=board.o +board-$(CONFIG_BATTERY_SMART)+=battery.o diff --git a/board/hammer/ec.tasklist b/board/hammer/ec.tasklist index b1675e37e2..cfa7ddfcf2 100644 --- a/board/hammer/ec.tasklist +++ b/board/hammer/ec.tasklist @@ -16,9 +16,20 @@ * 'd' in an opaque parameter passed to the routine at startup * 's' is the stack size in bytes; must be a multiple of 8 */ +#ifdef BOARD_WAND #define CONFIG_TASK_LIST \ TASK_ALWAYS_RO(RWSIG, rwsig_task, NULL, 1280) \ TASK_ALWAYS (HOOKS, hook_task, NULL, 2048) \ TASK_ALWAYS_RW(TOUCHPAD, touchpad_task, NULL, LARGER_TASK_STACK_SIZE) \ + TASK_ALWAYS_RW(CHARGER, charger_task, NULL, LARGER_TASK_STACK_SIZE) \ TASK_ALWAYS (CONSOLE, console_task, NULL, 1024) \ + TASK_ALWAYS_RW(ECCOMM, ec_ec_comm_slave_task, NULL, TASK_STACK_SIZE) \ TASK_NOTEST_RW(KEYSCAN, keyboard_scan_task, NULL, TASK_STACK_SIZE) +#else +#define CONFIG_TASK_LIST \ + TASK_ALWAYS_RO(RWSIG, rwsig_task, NULL, 1280) \ + TASK_ALWAYS (HOOKS, hook_task, NULL, 2048) \ + TASK_ALWAYS_RW(TOUCHPAD, touchpad_task, NULL, LARGER_TASK_STACK_SIZE) \ + TASK_ALWAYS (CONSOLE, console_task, NULL, 1024) \ + TASK_NOTEST_RW(KEYSCAN, keyboard_scan_task, NULL, TASK_STACK_SIZE) +#endif diff --git a/board/hammer/gpio.inc b/board/hammer/gpio.inc index 3b16f643ef..1b60a32100 100644 --- a/board/hammer/gpio.inc +++ b/board/hammer/gpio.inc @@ -36,8 +36,13 @@ GPIO_INT(KB_IN07, PIN(B, 15), GPIO_KB_INPUT, keyboard_raw_gpio_interrupt) /* Do not forget to update KB_OUT_PORT_LIST to match this. */ GPIO(KB_OUT00, PIN(B, 1), GPIO_KB_OUTPUT) GPIO(KB_OUT01, PIN(A, 5), GPIO_KB_OUTPUT) +#ifdef BOARD_WAND +GPIO(KB_OUT02, PIN(A, 8), GPIO_KB_OUTPUT) +GPIO(KB_OUT03, PIN(B, 4), GPIO_KB_OUTPUT) +#else GPIO(KB_OUT02, PIN(A, 3), GPIO_KB_OUTPUT) GPIO(KB_OUT03, PIN(A, 2), GPIO_KB_OUTPUT) +#endif GPIO(KB_OUT04, PIN(A, 6), GPIO_KB_OUTPUT) GPIO(KB_OUT05, PIN(A, 0), GPIO_KB_OUTPUT) GPIO(KB_OUT06, PIN(A, 1), GPIO_KB_OUTPUT) @@ -50,8 +55,8 @@ GPIO(KB_OUT12, PIN(C, 13), GPIO_KB_OUTPUT) /* I2C pins should be configured as inputs until I2C module is */ /* initialized. This will avoid driving the lines unintentionally.*/ -GPIO(MASTER_I2C_SCL, PIN(B, 6), GPIO_INPUT) -GPIO(MASTER_I2C_SDA, PIN(B, 7), GPIO_INPUT) +GPIO(TOUCHPAD_I2C_SCL, PIN(B, 6), GPIO_INPUT) +GPIO(TOUCHPAD_I2C_SDA, PIN(B, 7), GPIO_INPUT) /* TODO(crosbug.com/p/59083): Disable trackpad when appropriate */ #ifdef BOARD_WHISKERS GPIO(EN_PP3300_TP, PIN(A, 14), GPIO_OUT_HIGH) @@ -67,19 +72,34 @@ GPIO(KEYBOARD_BACKLIGHT, PIN(B, 9), GPIO_INPUT) GPIO(WP_L, PIN(A, 13), GPIO_INPUT | GPIO_PULL_UP) -GPIO(BASE_DET, PIN(A, 15), GPIO_INPUT) - #ifdef BOARD_WHISKERS GPIO(TP_BOOT0, PIN(B, 4), GPIO_INPUT) GPIO(TP_RESET, PIN(B, 5), GPIO_INPUT) #endif +#ifdef BOARD_WAND +GPIO(BASE_UART_TX_RX, PIN(A, 2), GPIO_ODR_HIGH | GPIO_PULL_UP) + +GPIO(CHARGER_I2C_SCL, PIN(B, 10), GPIO_INPUT) +GPIO(CHARGER_I2C_SDA, PIN(B, 11), GPIO_INPUT) + +GPIO(SWITCH_STATUS, PIN(A, 15), GPIO_INPUT) +GPIO(EN_OTG, PIN(B, 5), GPIO_INPUT) +#else +GPIO(BASE_DET, PIN(A, 15), GPIO_INPUT) +#endif + /* Unimplemented signals since we are not an EC */ UNIMPLEMENTED(ENTERING_RW) ALTERNATE(PIN_MASK(A, 0x0600), 1, MODULE_UART, GPIO_PULL_UP) /* USART1: PA09/PA10 - Servo stm32 console UART */ -ALTERNATE(PIN_MASK(B, 0x00c0), 1, MODULE_I2C, 0) /* I2C MASTER:PB6/7 GPIO_ODR_HIGH */ +#ifdef BOARD_WAND +ALTERNATE(PIN_MASK(A, 0x0004), 1, MODULE_UART, GPIO_ODR_HIGH) /* USART2: PA2 - EC-EC UART */ +ALTERNATE(PIN_MASK(B, 0x0c00), 1, MODULE_I2C, 0) /* I2C CHARGER: PB10/11 GPIO_ODR_HIGH */ +#endif + +ALTERNATE(PIN_MASK(B, 0x00c0), 1, MODULE_I2C, 0) /* I2C TOUCHPAD: PB6/7 GPIO_ODR_HIGH */ #ifdef BOARD_WHISKERS ALTERNATE(PIN_MASK(B, 0x0100), 2, MODULE_PWM, GPIO_PULL_DOWN) /* PWM: PB8 */ diff --git a/board/wand b/board/wand new file mode 120000 index 0000000000..7f4a914148 --- /dev/null +++ b/board/wand @@ -0,0 +1 @@ +hammer
\ No newline at end of file |