Add initial support for jerry

BUG=chrome-os-partner:33269
TEST=make BOARD=jerry; ./util/flash_ec BOARD=jerry
(on a pinky rev2 as a sanity)

Change-Id: I2c54e4044a65a0014adb32dd46f74bf5ed11b02d
Signed-off-by: Katie Roberts-Hoffman <katierh@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/225300
Reviewed-by: Alexandru Stan <amstan@chromium.org>
This commit is contained in:
Katie Roberts-Hoffman
2014-10-23 17:29:31 -07:00
committed by chrome-internal-fetch
parent cadce20c1a
commit 908b3f559b
9 changed files with 449 additions and 0 deletions

1
board/jerry/Makefile Symbolic link
View File

@@ -0,0 +1 @@
../../Makefile

54
board/jerry/battery.c Normal file
View File

@@ -0,0 +1,54 @@
/* 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.
*
* Battery pack vendor provided charging profile
*/
#include "battery.h"
#include "battery_smart.h"
#include "console.h"
#include "gpio.h"
#include "host_command.h"
#include "util.h"
/* Shutdown mode parameter to write to manufacturer access register */
#define SB_SHUTDOWN_DATA 0x0010
static const struct battery_info info = {
.voltage_max = 8400, /* mV */
.voltage_normal = 7400,
.voltage_min = 6000,
.precharge_current = 256, /* mA */
.start_charging_min_c = 0,
.start_charging_max_c = 45,
.charging_min_c = 0,
.charging_max_c = 45,
.discharging_min_c = 0,
.discharging_max_c = 60,
};
const struct battery_info *battery_get_info(void)
{
return &info;
}
static int cutoff(void)
{
int rv;
/* Ship mode command must be sent twice to take effect */
rv = sb_write(SB_MANUFACTURER_ACCESS, SB_SHUTDOWN_DATA);
if (rv != EC_SUCCESS)
return rv;
return sb_write(SB_MANUFACTURER_ACCESS, SB_SHUTDOWN_DATA);
}
int board_cut_off_battery(void)
{
return cutoff();
}

75
board/jerry/board.c Normal file
View File

@@ -0,0 +1,75 @@
/* Copyright (c) 2014 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.
*/
/* Veyron board-specific configuration */
#include "battery.h"
#include "chipset.h"
#include "common.h"
#include "extpower.h"
#include "gpio.h"
#include "i2c.h"
#include "keyboard_raw.h"
#include "lid_switch.h"
#include "power.h"
#include "power_button.h"
#include "power.h"
#include "pwm.h"
#include "pwm_chip.h"
#include "registers.h"
#include "spi.h"
#include "task.h"
#include "util.h"
#include "timer.h"
#include "charger.h"
#define GPIO_KB_INPUT (GPIO_INPUT | GPIO_PULL_UP | GPIO_INT_BOTH)
#define GPIO_KB_OUTPUT GPIO_ODR_HIGH
#include "gpio_list.h"
/* power signal list. Must match order of enum power_signal. */
const struct power_signal_info power_signal_list[] = {
{GPIO_SOC_POWER_GOOD, 1, "POWER_GOOD"},
{GPIO_SUSPEND_L, 1, "SUSPEND#_ASSERTED"},
};
BUILD_ASSERT(ARRAY_SIZE(power_signal_list) == POWER_SIGNAL_COUNT);
/* I2C ports */
const struct i2c_port_t i2c_ports[] = {
{"master", I2C_PORT_MASTER, 100},
};
const unsigned int i2c_ports_used = ARRAY_SIZE(i2c_ports);
/* PWM channels. Must be in the exactly same order as in enum pwm_channel. */
const struct pwm_t pwm_channels[] = {
{STM32_TIM(2), STM32_TIM_CH(3),
PWM_CONFIG_ACTIVE_LOW},
};
BUILD_ASSERT(ARRAY_SIZE(pwm_channels) == PWM_CH_COUNT);
/**
* Discharge battery when on AC power for factory test.
*/
int board_discharge_on_ac(int enable)
{
return charger_discharge_on_ac(enable);
}
void board_config_pre_init(void)
{
/* enable SYSCFG clock */
STM32_RCC_APB2ENR |= 1 << 0;
/* Remap USART DMA to match the USART driver */
/*
* the DMA mapping is :
* Chan 2 : TIM1_CH1
* Chan 3 : SPI1_TX
* Chan 4 : USART1_TX
* Chan 5 : USART1_RX
*/
STM32_SYSCFG_CFGR1 |= (1 << 9) | (1 << 10); /* Remap USART1 RX/TX DMA */
}

85
board/jerry/board.h Normal file
View File

@@ -0,0 +1,85 @@
/* Copyright (c) 2014 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.
*/
/* Veyron board configuration */
#ifndef __BOARD_H
#define __BOARD_H
/* Optional features */
#define CONFIG_AP_HANG_DETECT
#define CONFIG_BATTERY_CUT_OFF
#define CONFIG_BATTERY_SMART
#define CONFIG_BOARD_PRE_INIT
#define CONFIG_CHARGER
#define CONFIG_CHARGER_BQ24715
#define CONFIG_CHARGER_DISCHARGE_ON_AC
#define CONFIG_CHARGER_V2
#define CONFIG_CHIPSET_ROCKCHIP
#define CONFIG_EXTPOWER_GPIO
#define CONFIG_FORCE_CONSOLE_RESUME
#define CONFIG_HOST_COMMAND_STATUS
#define CONFIG_I2C
#define CONFIG_KEYBOARD_COL2_INVERTED
#define CONFIG_KEYBOARD_PROTOCOL_MKBP
#define CONFIG_LED_COMMON
#define CONFIG_LOW_POWER_IDLE
#define CONFIG_LOW_POWER_S0
#define CONFIG_POWER_BUTTON
#define CONFIG_POWER_COMMON
#define CONFIG_PWM
#define CONFIG_SPI
#define CONFIG_STM_HWTIMER32
#define CONFIG_VBOOT_HASH
#undef CONFIG_WATCHDOG_HELP
#ifndef __ASSEMBLER__
/* 48 MHz SYSCLK clock frequency */
#define CPU_CLOCK 48000000
/* Keyboard output port list */
#define KB_OUT_PORT_LIST GPIO_A, GPIO_B, GPIO_C
/* Single I2C port, where the EC is the master. */
#define I2C_PORT_MASTER 0
#define I2C_PORT_BATTERY I2C_PORT_MASTER
#define I2C_PORT_CHARGER I2C_PORT_MASTER
/* Timer selection */
#define TIM_CLOCK32 2
#define TIM_WATCHDOG 4
#include "gpio_signal.h"
enum power_signal {
RK_POWER_GOOD = 0,
RK_SUSPEND_ASSERTED,
/* Number of power signals */
POWER_SIGNAL_COUNT
};
enum pwm_channel {
PWM_CH_POWER_LED = 0,
/* Number of PWM channels */
PWM_CH_COUNT
};
/* Charger module */
#define CONFIG_CHARGER_SENSE_RESISTOR 10 /* Charge sense resistor, mOhm */
#define CONFIG_CHARGER_SENSE_RESISTOR_AC 20 /* Input sensor resistor, mOhm */
/* Input current limit for 45W AC adapter:
* 45W/19V*85%=2013mA, choose the closest charger setting = 2048mA
*/
#define CONFIG_CHARGER_INPUT_CURRENT 2048 /* mA, based on Link HW design */
#define CONFIG_CHARGER_CURRENT_LIMIT 3000 /* PL102 inductor 3.0A(3.8A) */
/* Discharge battery when on AC power for factory test. */
int board_discharge_on_ac(int enable);
#endif /* !__ASSEMBLER__ */
#endif /* __BOARD_H */

13
board/jerry/build.mk Normal file
View File

@@ -0,0 +1,13 @@
# -*- makefile -*-
# Copyright (c) 2014 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 STM32F071RB
CHIP:=stm32
CHIP_FAMILY:=stm32f0
CHIP_VARIANT:=stm32f07x
board-y=board.o battery.o led.o

23
board/jerry/ec.tasklist Normal file
View File

@@ -0,0 +1,23 @@
/* Copyright (c) 2014 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_ALWAYS(HOOKS, hook_task, NULL, LARGER_TASK_STACK_SIZE) \
TASK_ALWAYS(CHARGER, charger_task, NULL, LARGER_TASK_STACK_SIZE) \
TASK_NOTEST(CHIPSET, chipset_task, NULL, LARGER_TASK_STACK_SIZE) \
TASK_ALWAYS(HOSTCMD, host_command_task, NULL, TASK_STACK_SIZE) \
TASK_ALWAYS(CONSOLE, console_task, NULL, TASK_STACK_SIZE) \
TASK_NOTEST(KEYSCAN, keyboard_scan_task, NULL, TASK_STACK_SIZE)

58
board/jerry/gpio.inc Normal file
View File

@@ -0,0 +1,58 @@
/* -*- mode:c -*-
*
* Copyright (c) 2014 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.
*/
/* Inputs with interrupt handlers are first for efficiency */
GPIO(POWER_BUTTON_L, B, 5, GPIO_INT_BOTH, power_button_interrupt)
GPIO(SOC_POWER_GOOD, A, 3, GPIO_INT_BOTH, power_signal_interrupt)
GPIO(LID_OPEN, C, 13, GPIO_INT_BOTH, lid_interrupt)
GPIO(SUSPEND_L, C, 7, GPIO_INT_BOTH, power_signal_interrupt)
GPIO(SPI1_NSS, A, 4, GPIO_INT_BOTH, spi_event)
GPIO(AC_PRESENT, A, 0, GPIO_INT_BOTH | GPIO_PULL_UP, extpower_interrupt)
/* Keyboard inputs */
GPIO(KB_IN00, C, 8, GPIO_KB_INPUT, keyboard_raw_gpio_interrupt)
GPIO(KB_IN01, C, 9, GPIO_KB_INPUT, keyboard_raw_gpio_interrupt)
GPIO(KB_IN02, C, 10, GPIO_KB_INPUT, keyboard_raw_gpio_interrupt)
GPIO(KB_IN03, C, 11, GPIO_KB_INPUT, keyboard_raw_gpio_interrupt)
GPIO(KB_IN04, C, 12, GPIO_KB_INPUT, keyboard_raw_gpio_interrupt)
GPIO(KB_IN05, C, 14, GPIO_KB_INPUT, keyboard_raw_gpio_interrupt)
GPIO(KB_IN06, C, 15, GPIO_KB_INPUT, keyboard_raw_gpio_interrupt)
GPIO(KB_IN07, D, 2, GPIO_KB_INPUT, keyboard_raw_gpio_interrupt)
/* Other inputs */
GPIO(WP_L, B, 4, GPIO_INPUT, NULL)
/* Outputs */
GPIO(5V_DRV, A, 8, GPIO_OUT_LOW, NULL)
GPIO(BAT_LED0, B, 11, GPIO_OUT_LOW, NULL)
GPIO(BAT_LED1, A, 11, GPIO_OUT_LOW, NULL)
GPIO(EC_BL_OVERRIDE, F, 1, GPIO_OUT_LOW, NULL)
GPIO(EC_INT, B, 9, GPIO_OUT_LOW, NULL)
GPIO(ENTERING_RW, F, 0, GPIO_OUT_LOW, NULL)
GPIO(I2C1_SCL, B, 6, GPIO_ODR_HIGH, NULL)
GPIO(I2C1_SDA, B, 7, GPIO_ODR_HIGH, NULL)
GPIO(KB_OUT00, B, 0, GPIO_KB_OUTPUT, NULL)
GPIO(KB_OUT01, B, 8, GPIO_KB_OUTPUT, NULL)
GPIO(KB_OUT02, B, 12, GPIO_OUT_LOW, NULL) /* Inverted from silegro */
GPIO(KB_OUT03, B, 13, GPIO_KB_OUTPUT, NULL)
GPIO(KB_OUT04, B, 14, GPIO_KB_OUTPUT, NULL)
GPIO(KB_OUT05, B, 15, GPIO_KB_OUTPUT, NULL)
GPIO(KB_OUT06, C, 0, GPIO_KB_OUTPUT, NULL)
GPIO(KB_OUT07, C, 1, GPIO_KB_OUTPUT, NULL)
GPIO(KB_OUT08, C, 2, GPIO_KB_OUTPUT, NULL)
GPIO(KB_OUT09, B, 1, GPIO_KB_OUTPUT, NULL)
GPIO(KB_OUT10, C, 5, GPIO_KB_OUTPUT, NULL)
GPIO(KB_OUT11, C, 4, GPIO_KB_OUTPUT, NULL)
GPIO(KB_OUT12, A, 13, GPIO_KB_OUTPUT, NULL)
GPIO(PMIC_PWRON, A, 12, GPIO_OUT_LOW, NULL)
GPIO(PMIC_RESET, B, 3, GPIO_OUT_LOW, NULL)
GPIO(PMIC_SOURCE_PWREN, B, 10, GPIO_OUT_LOW, NULL)
GPIO(PMIC_WARM_RESET_L, C, 3, GPIO_ODR_HIGH, NULL)
ALTERNATE(A, 0x00f0, 0, MODULE_SPI, 0)
ALTERNATE(A, 0x0600, 1, MODULE_UART, 0)
ALTERNATE(B, 0x00c0, 1, MODULE_I2C, 0)

139
board/jerry/led.c Normal file
View File

@@ -0,0 +1,139 @@
/* Copyright (c) 2014 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 LED and Power LED control for jerry
*/
#include "gpio.h"
#include "hooks.h"
#include "battery.h"
#include "charge_state.h"
#include "chipset.h"
#include "led_common.h"
#include "util.h"
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_GREEN = 0,
LED_ORANGE,
LED_COLOR_COUNT /* Number of colors, not a color itself */
};
static int bat_led_set(enum led_color color, int on)
{
switch (color) {
case LED_GREEN:
gpio_set_level(GPIO_BAT_LED1, on ? 0 : 1);
break;
case LED_ORANGE:
gpio_set_level(GPIO_BAT_LED0, on ? 0 : 1);
break;
default:
return EC_ERROR_UNKNOWN;
}
return EC_SUCCESS;
}
void led_get_brightness_range(enum ec_led_id led_id, uint8_t *brightness_range)
{
/* Ignoring led_id as both leds support the same colors */
brightness_range[EC_LED_COLOR_GREEN] = 1;
brightness_range[EC_LED_COLOR_YELLOW] = 1;
}
int led_set_brightness(enum ec_led_id led_id, const uint8_t *brightness)
{
if (EC_LED_ID_BATTERY_LED == led_id) {
if (brightness[EC_LED_COLOR_GREEN] != 0) {
bat_led_set(LED_GREEN, 1);
bat_led_set(LED_ORANGE, 0);
} else if (brightness[EC_LED_COLOR_YELLOW] != 0) {
bat_led_set(LED_GREEN, 1);
bat_led_set(LED_ORANGE, 1);
} else {
bat_led_set(LED_GREEN, 0);
bat_led_set(LED_ORANGE, 0);
}
return EC_SUCCESS;
} else {
return EC_ERROR_UNKNOWN;
}
}
static void jerry_led_set_power(void)
{
static int power_second;
power_second++;
/* PWR LED behavior:
* Power on: Green
* Suspend: Green in breeze mode ( 1 sec on/ 3 sec off)
* Power off: OFF
*/
if (chipset_in_state(CHIPSET_STATE_ANY_OFF))
bat_led_set(LED_GREEN, 0);
else if (chipset_in_state(CHIPSET_STATE_ON))
bat_led_set(LED_GREEN, 1);
else if (chipset_in_state(CHIPSET_STATE_SUSPEND))
bat_led_set(LED_GREEN, (power_second & 3) ? 0 : 1);
}
static void jerry_led_set_battery(void)
{
static int battery_second;
battery_second++;
/* BAT LED behavior:
* Fully charged / idle: Off
* Under charging: Orange
* Battery low (10%): Orange in breeze mode (1 sec on, 3 sec off)
* Battery critical low (less than 3%) or abnormal battery
* situation: Orange in blinking mode (1 sec on, 1 sec off)
* Using battery or not connected to AC power: OFF
*/
switch (charge_get_state()) {
case PWR_STATE_CHARGE:
bat_led_set(LED_ORANGE, 1);
break;
case PWR_STATE_CHARGE_NEAR_FULL:
bat_led_set(LED_ORANGE, 1);
break;
case PWR_STATE_DISCHARGE:
if (charge_get_percent() < 3)
bat_led_set(LED_ORANGE, (battery_second & 1) ? 0 : 1);
else if (charge_get_percent() < 10)
bat_led_set(LED_ORANGE, (battery_second & 3) ? 0 : 1);
else
bat_led_set(LED_ORANGE, 0);
break;
case PWR_STATE_ERROR:
bat_led_set(LED_ORANGE, (battery_second & 1) ? 0 : 1);
break;
case PWR_STATE_IDLE: /* External power connected in IDLE. */
bat_led_set(LED_ORANGE, 0);
break;
default:
/* Other states don't alter LED behavior */
break;
}
}
/** * Called by hook task every 1 sec */
static void led_second(void)
{
if (led_auto_control_is_enabled(EC_LED_ID_POWER_LED))
jerry_led_set_power();
if (led_auto_control_is_enabled(EC_LED_ID_BATTERY_LED))
jerry_led_set_battery();
}
DECLARE_HOOK(HOOK_SECOND, led_second, HOOK_PRIO_DEFAULT);

View File

@@ -64,6 +64,7 @@ BOARDS_STM32=(
discovery
firefly
fruitpie
jerry
kitty
minimuffin
nyan