From 0e693fc437f61bba43b89475b39df351701969f1 Mon Sep 17 00:00:00 2001 From: Vincent Palatin Date: Tue, 18 Sep 2012 14:47:37 -0700 Subject: Add Spring board configuration Assign GPIOs and board specific peripheral/pin mux configurations. Signed-off-by: Vincent Palatin BUG=chrome-os-partner:14313 TEST=make BOARD=spring run spring binary on snow for basic sanity checking. BRANCH=none Change-Id: I6384024a0f27af67744e98a55b66d08f587bffa0 Reviewed-on: https://gerrit.chromium.org/gerrit/33631 Reviewed-by: David Hendricks Tested-by: Vincent Palatin Reviewed-by: Vic Yang Commit-Ready: Vincent Palatin --- board/spring/board.c | 257 +++++++++++++++++++++++++++++++++++++++++++++ board/spring/board.h | 128 ++++++++++++++++++++++ board/spring/build.mk | 11 ++ board/spring/ec.tasklist | 25 +++++ chip/stm32/keyboard_scan.c | 2 +- util/flash_ec | 2 +- 6 files changed, 423 insertions(+), 2 deletions(-) create mode 100644 board/spring/board.c create mode 100644 board/spring/board.h create mode 100644 board/spring/build.mk create mode 100644 board/spring/ec.tasklist diff --git a/board/spring/board.c b/board/spring/board.c new file mode 100644 index 0000000000..3a2cb34966 --- /dev/null +++ b/board/spring/board.c @@ -0,0 +1,257 @@ +/* Copyright (c) 2012 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. + */ +/* Spring board-specific configuration */ + +#include "board.h" +#include "chipset.h" +#include "common.h" +#include "console.h" +#include "dma.h" +#include "gpio.h" +#include "hooks.h" +#include "i2c.h" +#include "pmu_tpschrome.h" +#include "registers.h" +#include "timer.h" +#include "util.h" + +#define GPIO_KB_INPUT (GPIO_INPUT | GPIO_PULL_UP | GPIO_INT_BOTH) +#define GPIO_KB_OUTPUT (GPIO_OUTPUT | GPIO_OPEN_DRAIN) + +#define INT_BOTH_FLOATING (GPIO_INPUT | GPIO_INT_BOTH) +#define INT_BOTH_PULL_UP (GPIO_INPUT | GPIO_PULL_UP | GPIO_INT_BOTH) + +#define HARD_RESET_TIMEOUT_MS 5 + +/* GPIO interrupt handlers prototypes */ +#ifndef CONFIG_TASK_GAIAPOWER +#define gaia_power_event NULL +#define gaia_suspend_event NULL +#define gaia_lid_event NULL +#else +void gaia_power_event(enum gpio_signal signal); +void gaia_suspend_event(enum gpio_signal signal); +void gaia_lid_event(enum gpio_signal signal); +#endif +#ifndef CONFIG_TASK_KEYSCAN +#define matrix_interrupt NULL +#endif + +/* GPIO signal list. Must match order from enum gpio_signal. */ +const struct gpio_info gpio_list[GPIO_COUNT] = { + /* Inputs with interrupt handlers are first for efficiency */ + {"KB_PWR_ON_L", GPIO_B, (1<<5), GPIO_INT_BOTH, gaia_power_event}, + {"PP1800_LDO2", GPIO_A, (1<<1), GPIO_INT_BOTH, gaia_power_event}, + {"XPSHOLD", GPIO_A, (1<<3), GPIO_INT_BOTH, gaia_power_event}, + {"CHARGER_INT", GPIO_C, (1<<4), GPIO_INT_FALLING, pmu_irq_handler}, + {"LID_OPEN", GPIO_C, (1<<13), GPIO_INT_RISING, gaia_lid_event}, + {"SUSPEND_L", GPIO_A, (1<<7), INT_BOTH_FLOATING, gaia_suspend_event}, + {"WP_L", GPIO_A, (1<<13), GPIO_INPUT, NULL}, + {"KB_IN00", GPIO_C, (1<<8), GPIO_KB_INPUT, matrix_interrupt}, + {"KB_IN01", GPIO_C, (1<<9), GPIO_KB_INPUT, matrix_interrupt}, + {"KB_IN02", GPIO_C, (1<<10), GPIO_KB_INPUT, matrix_interrupt}, + {"KB_IN03", GPIO_C, (1<<11), GPIO_KB_INPUT, matrix_interrupt}, + {"KB_IN04", GPIO_C, (1<<12), GPIO_KB_INPUT, matrix_interrupt}, + {"KB_IN05", GPIO_C, (1<<14), GPIO_KB_INPUT, matrix_interrupt}, + {"KB_IN06", GPIO_C, (1<<15), GPIO_KB_INPUT, matrix_interrupt}, + {"KB_IN07", GPIO_D, (1<<2), GPIO_KB_INPUT, matrix_interrupt}, + {"USB_CHG_INT", GPIO_A, (1<<6), GPIO_INT_FALLING, NULL}, + /* Other inputs */ + {"BCHGR_VACG", GPIO_A, (1<<0), GPIO_INT_BOTH, NULL}, + /* + * I2C pins should be configured as inputs until I2C module is + * initialized. This will avoid driving the lines unintentionally. + */ + {"I2C1_SCL", GPIO_B, (1<<6), GPIO_INPUT, NULL}, + {"I2C1_SDA", GPIO_B, (1<<7), GPIO_INPUT, NULL}, + {"I2C2_SCL", GPIO_B, (1<<10), GPIO_INPUT, NULL}, + {"I2C2_SDA", GPIO_B, (1<<11), GPIO_INPUT, NULL}, + /* Outputs */ + {"EN_PP1350", GPIO_A, (1<<14), GPIO_OUT_LOW, NULL}, + {"EN_PP5000", GPIO_A, (1<<11), GPIO_OUT_LOW, NULL}, + {"EN_PP3300", GPIO_A, (1<<8), GPIO_OUT_LOW, NULL}, + {"PMIC_PWRON_L",GPIO_A, (1<<12), GPIO_OUT_HIGH, NULL}, + {"PMIC_RESET", GPIO_A, (1<<15), GPIO_OUT_LOW, NULL}, + {"ENTERING_RW", GPIO_D, (1<<0), GPIO_OUT_LOW, NULL}, + {"CHARGER_EN", GPIO_B, (1<<2), GPIO_OUT_LOW, NULL}, + {"EC_INT", GPIO_B, (1<<9), GPIO_HI_Z, NULL}, + {"CODEC_INT", GPIO_D, (1<<1), GPIO_HI_Z, NULL}, + {"KB_OUT00", GPIO_B, (1<<0), GPIO_KB_OUTPUT, NULL}, + {"KB_OUT01", GPIO_B, (1<<8), GPIO_KB_OUTPUT, NULL}, + {"KB_OUT02", GPIO_B, (1<<12), GPIO_KB_OUTPUT, NULL}, + {"KB_OUT03", GPIO_B, (1<<13), GPIO_KB_OUTPUT, NULL}, + {"KB_OUT04", GPIO_B, (1<<14), GPIO_KB_OUTPUT, NULL}, + {"KB_OUT05", GPIO_B, (1<<15), GPIO_KB_OUTPUT, NULL}, + {"KB_OUT06", GPIO_C, (1<<0), GPIO_KB_OUTPUT, NULL}, + {"KB_OUT07", GPIO_C, (1<<1), GPIO_KB_OUTPUT, NULL}, + {"KB_OUT08", GPIO_C, (1<<2), GPIO_KB_OUTPUT, NULL}, + {"KB_OUT09", GPIO_B, (1<<1), GPIO_KB_OUTPUT, NULL}, + {"KB_OUT10", GPIO_C, (1<<5), GPIO_KB_OUTPUT, NULL}, + {"KB_OUT11", GPIO_C, (1<<6), GPIO_KB_OUTPUT, NULL}, + {"KB_OUT12", GPIO_C, (1<<7), GPIO_KB_OUTPUT, NULL}, + {"ILIM_1500", GPIO_B, (1<<3), GPIO_OUT_LOW, NULL}, + {"ILIM_500", GPIO_B, (1<<4), GPIO_OUT_LOW, NULL}, +}; + +void configure_board(void) +{ + uint32_t val; + + dma_init(); + + /* Enable all GPIOs clocks + * TODO: more fine-grained enabling for power saving + */ + STM32_RCC_APB2ENR |= 0x1fd; + + /* remap OSC_IN/OSC_OUT to PD0/PD1 */ + STM32_GPIO_AFIO_MAPR |= 1 << 15; + + /* + * use PA13, PA14, PA15, PB3, PB4 as a GPIO, + * so disable JTAG and SWD + */ + STM32_GPIO_AFIO_MAPR = (STM32_GPIO_AFIO_MAPR & ~(0x7 << 24)) + | (4 << 24); + + /* + * Set alternate function for USART1. For alt. function input + * the port is configured in either floating or pull-up/down + * input mode (ref. section 7.1.4 in datasheet RM0041): + * PA9: Tx, alt. function output + * PA10: Rx, input with pull-down + * + * note: see crosbug.com/p/12223 for more info + */ + val = STM32_GPIO_CRH_OFF(GPIO_A) & ~0x00000ff0; + val |= 0x00000890; + STM32_GPIO_CRH_OFF(GPIO_A) = val; + + /* EC_INT is output, open-drain */ + val = STM32_GPIO_CRH_OFF(GPIO_B) & ~0xf0; + val |= 0x50; + STM32_GPIO_CRH_OFF(GPIO_B) = val; + /* put GPIO in Hi-Z state */ + gpio_set_level(GPIO_EC_INT, 1); +} + +/* GPIO configuration to be done after I2C module init */ +void board_i2c_post_init(int port) +{ + uint32_t val; + + /* enable alt. function (open-drain) */ + if (port == STM32_I2C1_PORT) { + /* I2C1 is on PB6-7 */ + val = STM32_GPIO_CRL_OFF(GPIO_B) & ~0xff000000; + val |= 0xdd000000; + STM32_GPIO_CRL_OFF(GPIO_B) = val; + } else if (port == STM32_I2C2_PORT) { + /* I2C2 is on PB10-11 */ + val = STM32_GPIO_CRH_OFF(GPIO_B) & ~0x0000ff00; + val |= 0x0000dd00; + STM32_GPIO_CRH_OFF(GPIO_B) = val; + } +} + +void board_interrupt_host(int active) +{ + /* interrupt host by using active low EC_INT signal */ + gpio_set_level(GPIO_EC_INT, !active); +} + +void board_keyboard_suppress_noise(void) +{ + /* notify audio codec of keypress for noise suppression */ + gpio_set_level(GPIO_CODEC_INT, 0); + gpio_set_level(GPIO_CODEC_INT, 1); +} + +static int board_startup_hook(void) +{ + gpio_set_flags(GPIO_SUSPEND_L, INT_BOTH_PULL_UP); + return 0; +} +DECLARE_HOOK(HOOK_CHIPSET_STARTUP, board_startup_hook, HOOK_PRIO_DEFAULT); + +static int board_shutdown_hook(void) +{ + /* Disable pull-up on SUSPEND_L during shutdown to prevent leakage */ + gpio_set_flags(GPIO_SUSPEND_L, INT_BOTH_FLOATING); + + return 0; +} +DECLARE_HOOK(HOOK_CHIPSET_SHUTDOWN, board_shutdown_hook, HOOK_PRIO_DEFAULT); + +/* + * Force the pmic to reset completely. This forces an entire system reset, + * and therefore should never return + */ +void board_hard_reset(void) +{ + /* Force a hard reset of tps Chrome */ + gpio_set_level(GPIO_PMIC_RESET, 1); + + /* Delay while the power is cut */ + udelay(HARD_RESET_TIMEOUT_MS * 1000); + + /* Shouldn't get here unless the board doesn't have this capability */ + panic_puts("Hard reset failed! (this board may not be capable)\n"); +} + +#ifdef CONFIG_PMU_BOARD_INIT + +/** + * Initialize PMU register settings + * + * PMU init settings depend on board configuration. This function should be + * called inside PMU init function. + */ +int board_pmu_init(void) +{ + int ver, failure = 0; + + /* Set fast charging timeout to 6 hours*/ + if (!failure) + failure = pmu_set_fastcharge(TIMEOUT_6HRS); + /* Enable external gpio CHARGER_EN control */ + if (!failure) + failure = pmu_enable_ext_control(1); + /* Disable force charging */ + if (!failure) + failure = pmu_enable_charger(0); + + /* Set NOITERM bit */ + if (!failure) + failure = pmu_low_current_charging(1); + + /* + * High temperature charging + * termination voltage: 2.1V + * termination current: 100% + */ + if (!failure) + failure = pmu_set_term_voltage(RANGE_T34, TERM_V2100); + if (!failure) + failure = pmu_set_term_current(RANGE_T34, TERM_I1000); + /* + * Standard temperature charging + * termination voltage: 2.1V + * termination current: 100% + */ + if (!failure) + failure = pmu_set_term_voltage(RANGE_T23, TERM_V2100); + if (!failure) + failure = pmu_set_term_current(RANGE_T23, TERM_I1000); + + return failure ? EC_ERROR_UNKNOWN : EC_SUCCESS; +} +#endif /* CONFIG_BOARD_PMU_INIT */ + +int board_get_ac(void) +{ + /* use TPSChrome VACG signal to detect AC state */ + return gpio_get_level(GPIO_BCHGR_VACG); +} diff --git a/board/spring/board.h b/board/spring/board.h new file mode 100644 index 0000000000..8acd4fc187 --- /dev/null +++ b/board/spring/board.h @@ -0,0 +1,128 @@ +/* Copyright (c) 2012 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. + */ + +/* Spring board configuration */ + +#ifndef __BOARD_H +#define __BOARD_H + +/* 16 MHz SYSCLK clock frequency */ +#define CPU_CLOCK 16000000 + +/* Use USART1 as console serial port */ +#define CONFIG_CONSOLE_UART 1 + +/* use I2C for host communication */ +#define CONFIG_I2C + +#define CONFIG_HOST_COMMAND_STATUS + +/* Debug features */ +#define CONFIG_PANIC_HELP +#define CONFIG_ASSERT_HELP +#define CONFIG_CONSOLE_CMDHELP + +#undef CONFIG_TASK_PROFILING +#define CONFIG_WATCHDOG_HELP + +/* compute RW firmware hash at startup */ +#define CONFIG_VBOOT + +/* DE-ACTIVATED: use STOP mode when we have nothing to do */ +#undef CONFIG_LOW_POWER_IDLE + +#ifndef __ASSEMBLER__ + +/* By default, enable all console messages except keyboard */ +#define CC_DEFAULT (CC_ALL & ~CC_MASK(CC_KEYSCAN)) + +/* EC drives 13 outputs to keyboard matrix */ +#define KB_OUTPUTS 13 + +/* Charging */ +#define CONFIG_SMART_BATTERY +#define CONFIG_PMU_TPS65090 +#define CONFIG_PMU_BOARD_INIT +#define I2C_PORT_HOST 0 +#define I2C_PORT_BATTERY I2C_PORT_HOST +#define I2C_PORT_CHARGER I2C_PORT_HOST +#define I2C_PORT_SLAVE 1 + +#define CONFIG_CMD_PMU + +/* Battery */ +#define CONFIG_BATTERY_BQ20Z453 + +/* GPIO signal list */ +enum gpio_signal { + /* Inputs with interrupt handlers are first for efficiency */ + GPIO_KB_PWR_ON_L = 0, /* Keyboard power button */ + GPIO_PP1800_LDO2, /* LDO2 is ON (end of PMIC sequence) */ + GPIO_SOC1V8_XPSHOLD, /* App Processor ON */ + GPIO_CHARGER_INT, + GPIO_LID_OPEN, /* LID switch detection */ + GPIO_SUSPEND_L, /* AP suspend/resume state */ + GPIO_WRITE_PROTECTn, /* Write protection pin (low active) */ + /* Keyboard inputs */ + GPIO_KB_IN00, + GPIO_KB_IN01, + GPIO_KB_IN02, + GPIO_KB_IN03, + GPIO_KB_IN04, + GPIO_KB_IN05, + GPIO_KB_IN06, + GPIO_KB_IN07, + GPIO_USB_CHG_INT, + /* Other inputs */ + GPIO_BCHGR_VACG, /* AC good on TPSChrome */ + GPIO_I2C1_SCL, + GPIO_I2C1_SDA, + GPIO_I2C2_SCL, + GPIO_I2C2_SDA, + /* Outputs */ + GPIO_EN_PP1350, /* DDR 1.35v rail enable */ + GPIO_EN_PP5000, /* 5.0v rail enable */ + GPIO_EN_PP3300, /* 3.3v rail enable */ + GPIO_PMIC_PWRON_L, /* 5v rail ready */ + GPIO_PMIC_RESET, /* Force hard reset of the pmic */ + GPIO_ENTERING_RW, /* EC is R/W mode for the kbc mux */ + GPIO_CHARGER_EN, + GPIO_EC_INT, + GPIO_CODEC_INT, /* To audio codec (KB noise cancellation) */ + GPIO_KB_OUT00, + GPIO_KB_OUT01, + GPIO_KB_OUT02, + GPIO_KB_OUT03, + GPIO_KB_OUT04, + GPIO_KB_OUT05, + GPIO_KB_OUT06, + GPIO_KB_OUT07, + GPIO_KB_OUT08, + GPIO_KB_OUT09, + GPIO_KB_OUT10, + GPIO_KB_OUT11, + GPIO_KB_OUT12, + GPIO_ILIM_1500, /* max charging current : 1500 mA */ + GPIO_ILIM_500, /* max charging current : 500 mA */ + /* Number of GPIOs; not an actual GPIO */ + GPIO_COUNT +}; + +void configure_board(void); + +void matrix_interrupt(enum gpio_signal signal); + +/* Signal to AP that data is waiting */ +void board_interrupt_host(int active); + +/* Initialize PMU registers using board settings */ +int board_pmu_init(void); + +/* Force the pmu to reset everything on the board */ +void board_hard_reset(void); + +#endif /* !__ASSEMBLER__ */ + +#endif /* __BOARD_H */ diff --git a/board/spring/build.mk b/board/spring/build.mk new file mode 100644 index 0000000000..ae15fbe081 --- /dev/null +++ b/board/spring/build.mk @@ -0,0 +1,11 @@ +# Copyright (c) 2012 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 + +# the IC is STmicro STM32F100RB +CHIP:=stm32 +CHIP_VARIANT:=stm32f100 + +board-y=board.o diff --git a/board/spring/ec.tasklist b/board/spring/ec.tasklist new file mode 100644 index 0000000000..7c99047a1f --- /dev/null +++ b/board/spring/ec.tasklist @@ -0,0 +1,25 @@ +/* Copyright (c) 2012 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(n, r, d, s) 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 + */ +#define CONFIG_TASK_LIST \ + TASK(WATCHDOG, watchdog_task, NULL, 256) \ + TASK(VBOOTHASH, vboot_hash_task, NULL, TASK_STACK_SIZE) \ + TASK(POWERLED, power_led_task, NULL, 256) \ + TASK(PMU_TPS65090_CHARGER, pmu_charger_task, NULL, TASK_STACK_SIZE) \ + TASK(KEYSCAN, keyboard_scan_task, NULL, 256) \ + TASK(GAIAPOWER, gaia_power_task, NULL, TASK_STACK_SIZE) \ + TASK(CONSOLE, console_task, NULL, TASK_STACK_SIZE) \ + TASK(HOSTCMD, host_command_task, NULL, TASK_STACK_SIZE) diff --git a/chip/stm32/keyboard_scan.c b/chip/stm32/keyboard_scan.c index de537cc931..153c976c10 100644 --- a/chip/stm32/keyboard_scan.c +++ b/chip/stm32/keyboard_scan.c @@ -80,7 +80,7 @@ struct kbc_gpio { int pin; }; -#if defined(BOARD_daisy) || defined(BOARD_snow) +#if defined(BOARD_daisy) || defined(BOARD_snow) || defined(BOARD_spring) static const uint32_t ports[] = { GPIO_B, GPIO_C, GPIO_D }; #else #error "Need to specify GPIO ports used by keyboard" diff --git a/util/flash_ec b/util/flash_ec index 6449c68ff6..417a823fd5 100755 --- a/util/flash_ec +++ b/util/flash_ec @@ -124,7 +124,7 @@ info "EC UART pty : ${EC_UART}" save="$(servo_save)" case "${BOARD}" in - daisy | snow ) flash_daisy ;; + daisy | snow | spring ) flash_daisy ;; link ) flash_link ;; *) die "board ${BOARD} not supported" ;; esac -- cgit v1.2.1