summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKatie Roberts-Hoffman <katierh@google.com>2014-10-23 17:29:31 -0700
committerchrome-internal-fetch <chrome-internal-fetch@google.com>2014-10-25 08:14:16 +0000
commit908b3f559b2959173f55a2f3e32ea10047f00c0d (patch)
tree5e1c60caf98ad7aa8e69424fb1845c163ad5e061
parentcadce20c1ac866833d15ad7d8360cda17ea344e2 (diff)
downloadchrome-ec-908b3f559b2959173f55a2f3e32ea10047f00c0d.tar.gz
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>
l---------board/jerry/Makefile1
-rw-r--r--board/jerry/battery.c54
-rw-r--r--board/jerry/board.c75
-rw-r--r--board/jerry/board.h85
-rw-r--r--board/jerry/build.mk13
-rw-r--r--board/jerry/ec.tasklist23
-rw-r--r--board/jerry/gpio.inc58
-rw-r--r--board/jerry/led.c139
-rwxr-xr-xutil/flash_ec1
9 files changed, 449 insertions, 0 deletions
diff --git a/board/jerry/Makefile b/board/jerry/Makefile
new file mode 120000
index 0000000000..94aaae2c4d
--- /dev/null
+++ b/board/jerry/Makefile
@@ -0,0 +1 @@
+../../Makefile \ No newline at end of file
diff --git a/board/jerry/battery.c b/board/jerry/battery.c
new file mode 100644
index 0000000000..02b491443f
--- /dev/null
+++ b/board/jerry/battery.c
@@ -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();
+}
+
diff --git a/board/jerry/board.c b/board/jerry/board.c
new file mode 100644
index 0000000000..a91a25c6a4
--- /dev/null
+++ b/board/jerry/board.c
@@ -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 */
+}
diff --git a/board/jerry/board.h b/board/jerry/board.h
new file mode 100644
index 0000000000..398a56b62a
--- /dev/null
+++ b/board/jerry/board.h
@@ -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 */
diff --git a/board/jerry/build.mk b/board/jerry/build.mk
new file mode 100644
index 0000000000..a0f9570511
--- /dev/null
+++ b/board/jerry/build.mk
@@ -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
diff --git a/board/jerry/ec.tasklist b/board/jerry/ec.tasklist
new file mode 100644
index 0000000000..318cfe2553
--- /dev/null
+++ b/board/jerry/ec.tasklist
@@ -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)
diff --git a/board/jerry/gpio.inc b/board/jerry/gpio.inc
new file mode 100644
index 0000000000..a0909168c2
--- /dev/null
+++ b/board/jerry/gpio.inc
@@ -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)
diff --git a/board/jerry/led.c b/board/jerry/led.c
new file mode 100644
index 0000000000..005f314c7e
--- /dev/null
+++ b/board/jerry/led.c
@@ -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);
+
diff --git a/util/flash_ec b/util/flash_ec
index 3cedb33465..10d924f0be 100755
--- a/util/flash_ec
+++ b/util/flash_ec
@@ -64,6 +64,7 @@ BOARDS_STM32=(
discovery
firefly
fruitpie
+ jerry
kitty
minimuffin
nyan