diff options
author | james_chao <james_chao@asus.com> | 2015-10-27 14:50:10 +0800 |
---|---|---|
committer | ChromeOS bot <3su6n15k.default@developer.gserviceaccount.com> | 2015-10-30 03:11:43 +0000 |
commit | 48e051cfcabd328fa40d9bb4e644ccc01632db85 (patch) | |
tree | 33c7e0920a82bfcd2fc2c99bee024cc86bffc6e8 | |
parent | 8f4864632ca425b69cd0eeb4d9fcd8181e6f67a5 (diff) | |
download | chrome-ec-48e051cfcabd328fa40d9bb4e644ccc01632db85.tar.gz |
Terra: Initial Version of Terra Board added.
Copy from Strago, remove modules are listed below:
- ALS
- Accelerometer
- Gyroscope
- Buttons (Volume up, Volume down)
- PD and MUX
- USB Charge
BUG=None
BRANCH=None
TEST=make
Change-Id: I232553eeaef0113308be1f4913185b5d8a7440ea
Signed-off-by: james_chao <james_chao@asus.com>
Reviewed-on: https://chromium-review.googlesource.com/309410
Reviewed-by: Shawn N <shawnn@chromium.org>
l--------- | board/terra/Makefile | 1 | ||||
-rw-r--r-- | board/terra/battery.c | 43 | ||||
-rw-r--r-- | board/terra/board.c | 100 | ||||
-rw-r--r-- | board/terra/board.h | 122 | ||||
-rw-r--r-- | board/terra/build.mk | 14 | ||||
-rw-r--r-- | board/terra/ec.tasklist | 28 | ||||
-rw-r--r-- | board/terra/gpio.inc | 126 | ||||
-rw-r--r-- | board/terra/led.c | 211 | ||||
-rw-r--r-- | board/terra/lfw/gpio.inc | 16 |
9 files changed, 661 insertions, 0 deletions
diff --git a/board/terra/Makefile b/board/terra/Makefile new file mode 120000 index 0000000000..94aaae2c4d --- /dev/null +++ b/board/terra/Makefile @@ -0,0 +1 @@ +../../Makefile
\ No newline at end of file diff --git a/board/terra/battery.c b/board/terra/battery.c new file mode 100644 index 0000000000..43fa956ced --- /dev/null +++ b/board/terra/battery.c @@ -0,0 +1,43 @@ +/* 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" + +/* Shutdown mode parameter to write to manufacturer access register */ +#define SB_SHUTDOWN_DATA 0x0010 + +static const struct battery_info info = { + .voltage_max = 8700,/* mV */ + .voltage_normal = 7600, + .voltage_min = 6000, + .precharge_current = 150,/* mA */ + .start_charging_min_c = 0, + .start_charging_max_c = 45, + .charging_min_c = 0, + .charging_max_c = 45, + .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_MANUFACTURER_ACCESS, SB_SHUTDOWN_DATA); + + if (rv != EC_SUCCESS) + return rv; + + return sb_write(SB_MANUFACTURER_ACCESS, SB_SHUTDOWN_DATA); +} diff --git a/board/terra/board.c b/board/terra/board.c new file mode 100644 index 0000000000..d45488e4c3 --- /dev/null +++ b/board/terra/board.c @@ -0,0 +1,100 @@ +/* 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. + */ +/* Terra board-specific configuration */ + +#include "adc.h" +#include "als.h" +#include "button.h" +#include "charger.h" +#include "charge_state.h" +#include "driver/accel_kxcj9.h" +#include "driver/als_isl29035.h" +#include "driver/gyro_l3gd20h.h" +#include "driver/temp_sensor/tmp432.h" +#include "extpower.h" +#include "gpio.h" +#include "hooks.h" +#include "host_command.h" +#include "i2c.h" +#include "lid_switch.h" +#include "math_util.h" +#include "motion_lid.h" +#include "motion_sense.h" +#include "power.h" +#include "power_button.h" +#include "pwm.h" +#include "pwm_chip.h" +#include "registers.h" +#include "temp_sensor.h" +#include "temp_sensor_chip.h" +#include "thermal.h" +#include "uart.h" +#include "util.h" + +#define GPIO_KB_INPUT (GPIO_INPUT | GPIO_PULL_UP) +#define GPIO_KB_OUTPUT (GPIO_ODR_HIGH) +#define GPIO_KB_OUTPUT_COL2 (GPIO_OUT_LOW) + +#include "gpio_list.h" + +/* PWM channels. Must be in the exactly same order as in enum pwm_channel. */ +const struct pwm_t pwm_channels[] = { + {0, PWM_CONFIG_ACTIVE_LOW}, + {1, PWM_CONFIG_ACTIVE_LOW}, + {3, PWM_CONFIG_ACTIVE_LOW}, +}; + +BUILD_ASSERT(ARRAY_SIZE(pwm_channels) == PWM_CH_COUNT); + +/* power signal list. Must match order of enum power_signal. */ +const struct power_signal_info power_signal_list[] = { + {GPIO_ALL_SYS_PGOOD, 1, "ALL_SYS_PWRGD"}, + {GPIO_RSMRST_L_PGOOD, 1, "RSMRST_N_PWRGD"}, + {GPIO_PCH_SLP_S3_L, 1, "SLP_S3#_DEASSERTED"}, + {GPIO_PCH_SLP_S4_L, 1, "SLP_S4#_DEASSERTED"}, +}; +BUILD_ASSERT(ARRAY_SIZE(power_signal_list) == POWER_SIGNAL_COUNT); + +const struct i2c_port_t i2c_ports[] = { + {"batt_chg", MEC1322_I2C0_0, 100, + GPIO_I2C_PORT0_0_SCL, GPIO_I2C_PORT0_0_SDA}, + {"thermal", MEC1322_I2C3, 100, + GPIO_I2C_PORT3_SCL, GPIO_I2C_PORT3_SDA} +}; +const unsigned int i2c_ports_used = ARRAY_SIZE(i2c_ports); + +const enum gpio_signal hibernate_wake_pins[] = { + GPIO_POWER_BUTTON_L, +}; + +const int hibernate_wake_pins_used = ARRAY_SIZE(hibernate_wake_pins); + +/* + * Temperature sensors data; must be in same order as enum temp_sensor_id. + * Sensor index and name must match those present in coreboot: + * src/mainboard/google/${board}/acpi/dptf.asl + */ +const struct temp_sensor_t temp_sensors[] = { + {"TMP432_Internal", TEMP_SENSOR_TYPE_BOARD, tmp432_get_val, + TMP432_IDX_LOCAL, 4}, + {"TMP432_Sensor_1", TEMP_SENSOR_TYPE_BOARD, tmp432_get_val, + TMP432_IDX_REMOTE1, 4}, + {"TMP432_Sensor_2", TEMP_SENSOR_TYPE_BOARD, tmp432_get_val, + TMP432_IDX_REMOTE2, 4}, + {"Battery", TEMP_SENSOR_TYPE_BATTERY, charge_temp_sensor_get_val, + 0, 4}, +}; +BUILD_ASSERT(ARRAY_SIZE(temp_sensors) == TEMP_SENSOR_COUNT); + +/* Thermal limits for each temp sensor. All temps are in degrees K. Must be in + * same order as enum temp_sensor_id. To always ignore any temp, use 0. + */ +struct ec_thermal_config thermal_params[] = { + {{0, 0, 0}, 0, 0}, /* TMP432_Internal */ + {{0, 0, 0}, 0, 0}, /* TMP432_Sensor_1 */ + {{0, 0, 0}, 0, 0}, /* TMP432_Sensor_2 */ + {{0, 0, 0}, 0, 0}, /* Battery Sensor */ +}; +BUILD_ASSERT(ARRAY_SIZE(thermal_params) == TEMP_SENSOR_COUNT); diff --git a/board/terra/board.h b/board/terra/board.h new file mode 100644 index 0000000000..2a7f7cb23e --- /dev/null +++ b/board/terra/board.h @@ -0,0 +1,122 @@ +/* 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. + */ + +/* Terra board configuration */ + +#ifndef __CROS_EC_BOARD_H +#define __CROS_EC_BOARD_H + +/* Optional features */ +#define CONFIG_WATCHDOG_HELP +#define CONFIG_CLOCK_CRYSTAL +#define CONFIG_CHIPSET_BRASWELL +#define CONFIG_SCI_GPIO GPIO_PCH_SCI_L + +#define CONFIG_BOARD_VERSION + +#define CONFIG_KEYBOARD_COL2_INVERTED +#define CONFIG_KEYBOARD_IRQ_GPIO GPIO_KBD_IRQ_L +#undef CONFIG_KEYBOARD_KSO_BASE +#define CONFIG_KEYBOARD_KSO_BASE 4 /* KSO starts from KSO04 */ +#define CONFIG_KEYBOARD_PROTOCOL_8042 +#define CONFIG_POWER_BUTTON +#define CONFIG_POWER_BUTTON_X86 +#define CONFIG_LID_SWITCH +#define CONFIG_LOW_POWER_IDLE +#define CONFIG_LOW_POWER_PSEUDO_G3 +#define CONFIG_POWER_COMMON +#define CONFIG_POWER_SHUTDOWN_PAUSE_IN_S5 +#define CONFIG_EXTPOWER_GPIO +#define CONFIG_VBOOT_HASH +#define CONFIG_PORT80_TASK_EN +#define CONFIG_WIRELESS + +#define CONFIG_SPI_PORT 1 +#define CONFIG_SPI_CS_GPIO GPIO_PVT_CS0 +#define CONFIG_SPI_FLASH +#define CONFIG_SPI_FLASH_SIZE 524288 +#define CONFIG_SPI_FLASH_W25Q64 + +#define CONFIG_TEMP_SENSOR +#define CONFIG_TEMP_SENSOR_TMP432 + +#define CONFIG_PMIC + +#define CONFIG_BATTERY_CUT_OFF +#define CONFIG_BATTERY_SMART +#define CONFIG_CHARGER +#define CONFIG_CHARGER_V2 +#define CONFIG_CHARGER_BQ24770 +#define CONFIG_CHARGER_ILIM_PIN_DISABLED +#define CONFIG_CHARGER_SENSE_RESISTOR 10 +#define CONFIG_CHARGER_SENSE_RESISTOR_AC 10 +#define CONFIG_CHARGER_INPUT_CURRENT 2240 +#define CONFIG_CHARGER_DISCHARGE_ON_AC + +#define CONFIG_PWM +#define CONFIG_LED_COMMON + +#define CONFIG_I2C + +/* Wireless signals */ +#define WIRELESS_GPIO_WLAN GPIO_WLAN_OFF_L + +/* Modules we want to exclude */ +#undef CONFIG_EEPROM +#undef CONFIG_EOPTION +#undef CONFIG_PSTORE +#undef CONFIG_PECI +#undef CONFIG_FANS +#undef CONFIG_ADC +#ifndef __ASSEMBLER__ + +#include "gpio_signal.h" +#include "registers.h" + +/* I2C ports */ +#define I2C_PORT_BATTERY MEC1322_I2C0_0 +#define I2C_PORT_CHARGER MEC1322_I2C0_0 +#define I2C_PORT_THERMAL MEC1322_I2C3 + +/* ADC signal */ +enum adc_channel { + /* Number of ADC channels */ + ADC_CH_COUNT +}; + +/* power signal definitions */ +enum power_signal { + X86_ALL_SYS_PWRGD = 0, + X86_RSMRST_L_PWRGD, + X86_SLP_S3_DEASSERTED, + X86_SLP_S4_DEASSERTED, + + /* Number of X86 signals */ + POWER_SIGNAL_COUNT +}; + +enum pwm_channel { + PWM_CH_LED_RED, + PWM_CH_LED_BLUE, + PWM_CH_LED_GREEN, + /* Number of PWM channels */ + PWM_CH_COUNT +}; + +enum temp_sensor_id { + /* TMP432 local and remote sensors */ + TEMP_SENSOR_I2C_TMP432_LOCAL, + TEMP_SENSOR_I2C_TMP432_REMOTE1, + TEMP_SENSOR_I2C_TMP432_REMOTE2, + + /* Battery temperature sensor */ + TEMP_SENSOR_BATTERY, + + TEMP_SENSOR_COUNT +}; + +#endif /* !__ASSEMBLER__ */ + +#endif /* __CROS_EC_BOARD_H */ diff --git a/board/terra/build.mk b/board/terra/build.mk new file mode 100644 index 0000000000..894de2b191 --- /dev/null +++ b/board/terra/build.mk @@ -0,0 +1,14 @@ +# -*- 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 SMSC MEC1322 / external SPI is 4MB / external clock is crystal +CHIP:=mec1322 +CHIP_SPI_SIZE_KB:=512 + +board-y=board.o led.o +board-$(CONFIG_BATTERY_SMART)+=battery.o diff --git a/board/terra/ec.tasklist b/board/terra/ec.tasklist new file mode 100644 index 0000000000..40f7091744 --- /dev/null +++ b/board/terra/ec.tasklist @@ -0,0 +1,28 @@ +/* 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_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 + */ +#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_NOTEST(KEYPROTO, keyboard_protocol_task, NULL, TASK_STACK_SIZE) \ + TASK_ALWAYS(HOSTCMD, host_command_task, NULL, LARGER_TASK_STACK_SIZE) \ + TASK_ALWAYS(CONSOLE, console_task, NULL, LARGER_TASK_STACK_SIZE) \ + TASK_NOTEST(PORT80, port80_task, NULL, TASK_STACK_SIZE) \ + TASK_ALWAYS(POWERBTN, power_button_task, NULL, TASK_STACK_SIZE) \ + TASK_NOTEST(KEYSCAN, keyboard_scan_task, NULL, TASK_STACK_SIZE) diff --git a/board/terra/gpio.inc b/board/terra/gpio.inc new file mode 100644 index 0000000000..fa7286470f --- /dev/null +++ b/board/terra/gpio.inc @@ -0,0 +1,126 @@ +/* -*- 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. + */ + +GPIO_INT(LID_OPEN, PIN(27), GPIO_INT_BOTH | GPIO_PULL_UP, lid_interrupt) /* Lid switch */ +GPIO_INT(AC_PRESENT, PIN(30), GPIO_INT_BOTH | GPIO_PULL_UP | GPIO_PULL_DOWN, extpower_interrupt) /* BC_ACOK / EC_ACIN - to know if battery or AC connected */ +GPIO_INT(POWER_BUTTON_L, PIN(35), GPIO_INT_BOTH, power_button_interrupt) /* Power button */ +GPIO_INT(RSMRST_L_PGOOD, PIN(63), GPIO_INT_BOTH, power_signal_interrupt) /* RSMRST_N_PWRGD from power logic */ +GPIO_INT(ALL_SYS_PGOOD, PIN(130), GPIO_INT_BOTH, power_signal_interrupt) /* ALL_SYS_PWRGD from power logic */ +#ifdef CONFIG_LOW_POWER_IDLE +GPIO_INT(UART0_RX, PIN(162), GPIO_INT_BOTH_DSLEEP | GPIO_PULL_UP, uart_deepsleep_interrupt) /* UART0 RX input */ +#else +GPIO_INT(UART0_RX, PIN(162), GPIO_INPUT | GPIO_PULL_UP, NULL) /* UART0 RX input */ +#endif +GPIO_INT(PCH_SLP_S4_L, PIN(200), GPIO_INT_BOTH, power_signal_interrupt) /* SLP_S4# signal from PCH */ +GPIO_INT(PCH_SLP_S3_L, PIN(206), GPIO_INT_BOTH, power_signal_interrupt) /* SLP_S3# signal from PCH */ + +GPIO(BOARD_VERSION2, PIN(0), GPIO_INPUT) /* BOARD_ID1 */ +GPIO(KBD_KSO2, PIN(1), GPIO_KB_OUTPUT_COL2) /* Negative edge triggered irq. */ + +GPIO(NC_USBPD_BOOT0, PIN(12), GPIO_INPUT | GPIO_PULL_DOWN) /* NC */ +GPIO(USB_ILIM_SEL, PIN(13), GPIO_OUT_HIGH) /* USB current control */ +GPIO(I2C_PORT0_0_SCL, PIN(15), GPIO_INPUT) +GPIO(I2C_PORT0_0_SDA, PIN(16), GPIO_INPUT) +GPIO(I2C_PORT0_1_SCL, PIN(134), GPIO_INPUT) +GPIO(I2C_PORT0_1_SDA, PIN(17), GPIO_INPUT) +GPIO(I2C_PORT1_SCL, PIN(22), GPIO_INPUT) +GPIO(I2C_PORT1_SDA, PIN(23), GPIO_INPUT) +GPIO(I2C_PORT2_SCL, PIN(20), GPIO_INPUT) +GPIO(I2C_PORT2_SDA, PIN(21), GPIO_INPUT) +GPIO(I2C_PORT3_SCL, PIN(24), GPIO_INPUT) +GPIO(I2C_PORT3_SDA, PIN(25), GPIO_INPUT) +GPIO(PCH_SCI_L, PIN(26), GPIO_ODR_HIGH) /* SCI output */ + +GPIO(WP_L, PIN(33), GPIO_INPUT) /* EC_SPI_WP_ME_L */ +GPIO(USB2_ENABLE, PIN(36), GPIO_OUT_LOW) /* Enable power for USB2 Port */ + +GPIO(ENTERING_RW, PIN(41), GPIO_OUT_LOW) /* Indicate when EC is entering RW code */ +GPIO(PCH_SMI_L, PIN(44), GPIO_ODR_HIGH) /* SMI output */ +GPIO(USB_OC1_L, PIN(45), GPIO_INT_FALLING) /* DB2 BC1.2 over current signal to EC */ + +GPIO(PCH_SUS_STAT_L, PIN(51), GPIO_INT_FALLING) /* Signal to inform EC that SOC is entering low power state */ +GPIO(TRACKPAD_PWREN, PIN(53), GPIO_OUT_HIGH) /* Enable power for Track Pad */ +GPIO(USB_OC0_L, PIN(55), GPIO_INT_FALLING) /* Over current signal of the BC1.2 charger to EC */ +GPIO(EC_ADC1, PIN(57), GPIO_INPUT) /* EC_ADC1, TEMP_SENSOR_2 no_stuff */ + +GPIO(EC_ADC0, PIN(61), GPIO_INPUT) /* EC_ADC0 */ +GPIO(EC_HIB_L, PIN(64), GPIO_OUT_LOW) /* Set to high before Pseduo G3 */ +GPIO(PCH_SYS_PWROK, PIN(65), GPIO_OUT_LOW) /* EC thinks everything is up and ready (DELAY_ALL_SYS_PWRGD) */ +GPIO(PCH_WAKE_L, PIN(66), GPIO_ODR_HIGH) /* PCH wake pin */ +GPIO(USB1_ENABLE, PIN(67), GPIO_OUT_LOW) /* Enable power for USB3 Port */ + +GPIO(NC_GPIO100, PIN(100), GPIO_INPUT | GPIO_PULL_UP) /* NC */ +GPIO(NC_GPIO101, PIN(101), GPIO_INPUT | GPIO_PULL_UP) /* NC */ +GPIO(BOARD_VERSION3, PIN(102), GPIO_INPUT) /* BOARD_ID2 */ +GPIO(USB_CTL1, PIN(105), GPIO_OUT_HIGH) /* USB charging mode control */ + +GPIO(PCH_RCIN_L, PIN(110), GPIO_ODR_HIGH) /* Reset line to PCH (for 8042 emulation) */ +GPIO(NC_115, PIN(115), GPIO_INPUT | GPIO_PULL_UP) /* NC */ +GPIO(EC_VNN_VCLK, PIN(122), GPIO_INPUT | GPIO_PULL_UP) /* Interrupt from USB PD Controller to EC */ +GPIO(STRAP_L, PIN(123), GPIO_OUT_LOW) +GPIO(EC_VNN_ALERT_L, PIN(124), GPIO_INPUT | GPIO_PULL_UP) + +GPIO(PCH_RSMRST_L, PIN(143), GPIO_OUT_LOW) /* RSMRST_N to PCH */ +GPIO(EC_KBD_ALERT, PIN(145), GPIO_OUT_LOW) /* EC_KBD_ALERT */ +GPIO(PVT_CS0, PIN(146), GPIO_ODR_HIGH) /* SPI PVT Chip select */ + +GPIO(WLAN_OFF_L, PIN(150), GPIO_ODR_HIGH) /* Wireless LAN */ +GPIO(CPU_PROCHOT, PIN(151), GPIO_OUT_LOW) +GPIO(KBD_IRQ_L, PIN(152), GPIO_ODR_HIGH) /* Negative edge triggered irq. */ +GPIO(BOARD_VERSION1, PIN(154), GPIO_INPUT) /* BOARD_ID0 */ +GPIO(PCH_SUSPWRDNACK, PIN(157), GPIO_INT_FALLING) /* PMC SUSPWRDNACK signal from SOC to EC */ + +GPIO(PCH_PWRBTN_L, PIN(160), GPIO_OUT_HIGH) /* Power button output to PCH */ + +GPIO(STARTUP_LATCH_SET, PIN(201), GPIO_INPUT) /* Not used in BCRD2. Programmed as Input to fix EC power leakage in S3*/ +GPIO(EC_BL_DISABLE_L, PIN(202), GPIO_OUT_HIGH) /* EDP backligh disable signal from EC */ +GPIO(SMC_SHUTDOWN, PIN(203), GPIO_OUT_LOW) /* Shutdown signal from EC to power sequencing PLD */ + +GPIO(SUSPWRDNACK_SOC_EC,PIN(210), GPIO_OUT_LOW) /* SUSPWRDNACK signal from MOIC device to EC */ +GPIO(GPIO_3_EC, PIN(211), GPIO_OUT_LOW) /* Sleep SOIX signal from SOC to EC */ + +/* Alternate functions GPIO definition */ +ALTERNATE(PIN_MASK(16, 0x24), 1, MODULE_UART, 0) /* UART0 */ + +ALTERNATE(PIN_MASK(1, 0x60), 2, MODULE_I2C, GPIO_OPEN_DRAIN) /* I2C0: Battery Charger */ +ALTERNATE(PIN_MASK(2, 0x3f), 2, MODULE_I2C, GPIO_OPEN_DRAIN) /* I2C1: Temp Sensor / I2C2: SOC / I2C3: VNN */ + +ALTERNATE(PIN_MASK(0, 0xfc), 3, MODULE_KEYBOARD_SCAN, GPIO_KB_OUTPUT) +ALTERNATE(PIN_MASK(1, 0x03), 3, MODULE_KEYBOARD_SCAN, GPIO_KB_OUTPUT) +ALTERNATE(PIN_MASK(10, 0xd8), 3, MODULE_KEYBOARD_SCAN, GPIO_KB_OUTPUT) +ALTERNATE(PIN_MASK(3, 0x04), 3, MODULE_KEYBOARD_SCAN, GPIO_KB_INPUT) +ALTERNATE(PIN_MASK(4, 0x0d), 3, MODULE_KEYBOARD_SCAN, GPIO_KB_INPUT) +ALTERNATE(PIN_MASK(12, 0x60), 2, MODULE_KEYBOARD_SCAN, GPIO_KB_INPUT) +ALTERNATE(PIN_MASK(14, 0x14), 3, MODULE_KEYBOARD_SCAN, GPIO_KB_INPUT) + +ALTERNATE(PIN_MASK(1, 0x10), 0, MODULE_LPC, GPIO_OUT_HIGH) /* 14: LPC CLKRUN - Program as GPIO for power saving */ +ALTERNATE(PIN_MASK(11, 0x9e), 1, MODULE_LPC, 0) /* 111~114:LAD[0:3], 117:PCI_CLK */ +ALTERNATE(PIN_MASK(11, 0x40), 1, MODULE_LPC, GPIO_INT_BOTH) /* 116: LRESET# */ +ALTERNATE(PIN_MASK(12, 0x01), 1, MODULE_LPC, 0) /* 120: LFRAME# */ + +ALTERNATE(PIN_MASK(5, 0x10), 1, MODULE_SPI, 0) +ALTERNATE(PIN_MASK(16, 0x10), 1, MODULE_SPI, 0) +ALTERNATE(PIN_MASK(15, 0x08), 1, MODULE_SPI, 0) /* 153: CLK */ + +ALTERNATE(PIN_MASK(13, 0x48), 1, MODULE_PWM_LED, GPIO_OUTPUT) /* 133: PWM0, 136: PWM1 */ +ALTERNATE(PIN_MASK(14, 0x02), 1, MODULE_PWM_LED, GPIO_OUTPUT) /* 141: PWM3 */ +ALTERNATE(PIN_MASK(5, 0x40), 1, MODULE_ADC, 0) /* 56: temperature sensor 1 */ +ALTERNATE(PIN_MASK(6, 0x05), 1, MODULE_ADC, 0) /* 60: PC_MON, 62: temperature sensor 3 */ + +/* Re-Config LPC Pins to GPIO Open Drain for SOC G3 (EC - POWER_G3) state */ +ALTERNATE(PIN_MASK(1, 0x10), 0, MODULE_GPIO, GPIO_ODR_HIGH) /* 14: LPC CLKRUN */ +ALTERNATE(PIN_MASK(11, 0x9e), 0, MODULE_GPIO, GPIO_ODR_HIGH) /* 111~114:LAD[0:3], 117:PCI_CLK */ +ALTERNATE(PIN_MASK(11, 0x40), 0, MODULE_GPIO, GPIO_ODR_HIGH) /* 116: LRESET# */ +ALTERNATE(PIN_MASK(12, 0x01), 0, MODULE_GPIO, GPIO_ODR_HIGH) /* 120: LFRAME# */ + +/* I2C pins */ +/* I2C0_0 CLK - GPIO015, I2C0_0 DAT - GPIO016, I2C0_1 DAT - GPIO017 */ +ALTERNATE(PIN_MASK(1, 0xe0), 2, MODULE_I2C, GPIO_ODR_HIGH) +/* I2C0_1 CLK - GPIO134 */ +ALTERNATE(PIN_MASK(13, 0x10), 2, MODULE_I2C, GPIO_ODR_HIGH) +/* I2C{1,2,3} CLK / DAT - GPIO022-GPIO025*/ +ALTERNATE(PIN_MASK(2, 0x3f), 2, MODULE_I2C, GPIO_ODR_HIGH) diff --git a/board/terra/led.c b/board/terra/led.c new file mode 100644 index 0000000000..a8330fc755 --- /dev/null +++ b/board/terra/led.c @@ -0,0 +1,211 @@ +/* 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. + * + * Power/Battery LED control for Terra + */ + +#include "charge_state.h" +#include "chipset.h" +#include "console.h" +#include "extpower.h" +#include "gpio.h" +#include "hooks.h" +#include "led_common.h" +#include "pwm.h" +#include "registers.h" +#include "util.h" + +#define CPRINTF(format, args...) cprintf(CC_PWM, format, ## args) +#define CPRINTS(format, args...) cprints(CC_PWM, format, ## args) + +#define LED_TOTAL_TICKS 16 +#define LED_ON_TICKS 4 + +static int led_debug; + +const enum ec_led_id supported_led_ids[] = { + EC_LED_ID_POWER_LED, EC_LED_ID_BATTERY_LED}; +const int supported_led_ids_count = ARRAY_SIZE(supported_led_ids); + +enum led_color { + LED_OFF = 0, + LED_RED, + LED_AMBER, + LED_GREEN, + + /* Number of colors, not a color itself */ + LED_COLOR_COUNT +}; + +/* Brightness vs. color, in the order of off, red, amber, and green */ +static const uint8_t color_brightness[LED_COLOR_COUNT][3] = { + /* {Red, Blue, Green}, */ + [LED_OFF] = { 0, 0, 0}, + [LED_RED] = {100, 0, 0}, + [LED_AMBER] = { 75, 0, 10}, + [LED_GREEN] = { 0, 0, 100}, +}; + +/** + * Set LED color + * + * @param color Enumerated color value + */ +static void set_color(enum led_color color) +{ + pwm_set_duty(PWM_CH_LED_RED, color_brightness[color][0]); + pwm_set_duty(PWM_CH_LED_BLUE, color_brightness[color][1]); + pwm_set_duty(PWM_CH_LED_GREEN, color_brightness[color][2]); +} + +void led_get_brightness_range(enum ec_led_id led_id, uint8_t *brightness_range) +{ + brightness_range[EC_LED_COLOR_RED] = 100; + brightness_range[EC_LED_COLOR_BLUE] = 100; + brightness_range[EC_LED_COLOR_GREEN] = 100; +} + +int led_set_brightness(enum ec_led_id led_id, const uint8_t *brightness) +{ + pwm_set_duty(PWM_CH_LED_RED, brightness[EC_LED_COLOR_RED]); + pwm_set_duty(PWM_CH_LED_BLUE, brightness[EC_LED_COLOR_BLUE]); + pwm_set_duty(PWM_CH_LED_GREEN, brightness[EC_LED_COLOR_GREEN]); + return EC_SUCCESS; +} + +static void terra_led_set_power(void) +{ + static int power_ticks; + static int previous_state_suspend; + + power_ticks++; + + if (chipset_in_state(CHIPSET_STATE_SUSPEND)) { + /* Reset ticks if entering suspend so LED turns amber + * as soon as possible. */ + if (!previous_state_suspend) + power_ticks = 0; + + /* Blink once every four seconds. */ + set_color( + (power_ticks % LED_TOTAL_TICKS) < LED_ON_TICKS ? + LED_AMBER : LED_OFF); + + previous_state_suspend = 1; + return; + } + + previous_state_suspend = 0; + + if (chipset_in_state(CHIPSET_STATE_ANY_OFF)) + set_color(LED_OFF); + else if (chipset_in_state(CHIPSET_STATE_ON)) + set_color(LED_GREEN); +} + +static void terra_led_set_battery(void) +{ + static int battery_ticks; + + battery_ticks++; + + switch (charge_get_state()) { + case PWR_STATE_CHARGE: + set_color(LED_AMBER); + break; + case PWR_STATE_ERROR: + set_color(LED_RED); + break; + case PWR_STATE_CHARGE_NEAR_FULL: + case PWR_STATE_IDLE: /* External power connected in IDLE. */ + set_color(LED_GREEN); + break; + default: + /* Other states don't alter LED behavior */ + break; + } +} + +static void led_init(void) +{ + /* Configure GPIOs */ + gpio_config_module(MODULE_PWM_LED, 1); + + /* + * Enable PWMs and set to 0% duty cycle. If they're disabled, + * seems to ground the pins instead of letting them float. + */ + pwm_enable(PWM_CH_LED_RED, 1); + pwm_enable(PWM_CH_LED_GREEN, 1); + pwm_enable(PWM_CH_LED_BLUE, 1); + + set_color(LED_OFF); +} +DECLARE_HOOK(HOOK_INIT, led_init, HOOK_PRIO_DEFAULT); + +/** + * Called by hook task every 250 ms + */ +static void led_tick(void) +{ + if (led_debug) + return; + + if (extpower_is_present()) { + if (led_auto_control_is_enabled(EC_LED_ID_BATTERY_LED)) { + terra_led_set_battery(); + return; + } + } else if (led_auto_control_is_enabled(EC_LED_ID_POWER_LED)) { + terra_led_set_power(); + return; + } + + set_color(LED_OFF); +} +DECLARE_HOOK(HOOK_TICK, led_tick, HOOK_PRIO_DEFAULT); + +static void dump_pwm_channels(void) +{ + int ch; + + for (ch = 0; ch < 4; ch++) { + CPRINTF("channel = %d\n", ch); + CPRINTF("0x%04X 0x%04X 0x%04X\n", + MEC1322_PWM_CFG(ch), + MEC1322_PWM_ON(ch), + MEC1322_PWM_OFF(ch)); + } +} +/******************************************************************/ +/* Console commands */ +static int command_led_color(int argc, char **argv) +{ + if (argc > 1) { + if (!strcasecmp(argv[1], "debug")) { + led_debug ^= 1; + CPRINTF("led_debug = %d\n", led_debug); + } else if (!strcasecmp(argv[1], "off")) { + set_color(LED_OFF); + } else if (!strcasecmp(argv[1], "red")) { + set_color(LED_RED); + } else if (!strcasecmp(argv[1], "green")) { + set_color(LED_GREEN); + } else if (!strcasecmp(argv[1], "amber")) { + set_color(LED_AMBER); + } else { + /* maybe handle charger_discharge_on_ac() too? */ + return EC_ERROR_PARAM1; + } + } + + if (led_debug == 1) + dump_pwm_channels(); + return EC_SUCCESS; +} +DECLARE_CONSOLE_COMMAND(ledcolor, command_led_color, + "[debug|red|green|amber|off]", + "Change LED color", + NULL); + diff --git a/board/terra/lfw/gpio.inc b/board/terra/lfw/gpio.inc new file mode 100644 index 0000000000..122aff0cdf --- /dev/null +++ b/board/terra/lfw/gpio.inc @@ -0,0 +1,16 @@ +/* -*- 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. + * + * Minimal set of GPIOs needed for LFW loader + */ + +GPIO(PVT_CS0, PIN(146), GPIO_ODR_HIGH) /* SPI PVT Chip select */ + +/* Alternate functions GPIO definition */ +ALTERNATE(PIN_MASK(16, 0x24), 1, MODULE_UART, 0) /* UART0 */ +ALTERNATE(PIN_MASK(5, 0x10), 1, MODULE_SPI, 0) +ALTERNATE(PIN_MASK(16, 0x10), 1, MODULE_SPI, 0) +ALTERNATE(PIN_MASK(15, 0x08), 1, MODULE_SPI, 0) /* 153: CLK */ |