blob: 7dcf7dc778d5b4b2c74b8d16b275a3b4f3684096 [file] [log] [blame]
Angel Pons2e530382020-04-05 13:23:08 +02001/* SPDX-License-Identifier: GPL-2.0-only */
jinkun.hong692a2c02015-01-07 08:57:48 +08002
Kyösti Mälkkif1226962021-11-03 17:19:31 +02003#include <bootmode.h>
jinkun.hong692a2c02015-01-07 08:57:48 +08004#include <boot/coreboot_tables.h>
jinkun.hong692a2c02015-01-07 08:57:48 +08005#include <gpio.h>
jinkun.hong692a2c02015-01-07 08:57:48 +08006
7#include "board.h"
8
9#define GPIO_WP GPIO(7, A, 6)
10#define GPIO_POWER GPIO(0, A, 5)
Hung-Te Lin7049a8f2015-01-30 11:55:39 +080011#define GPIO_RECOVERY_SERVO GPIO(0, B, 1)
12#define GPIO_RECOVERY_PUSHKEY GPIO(7, B, 1)
Jonathan Dixon25805082015-04-01 14:02:34 -070013
jinkun.hong692a2c02015-01-07 08:57:48 +080014void setup_chromeos_gpios(void)
15{
16 gpio_input(GPIO_WP);
17 gpio_input(GPIO_POWER);
Hung-Te Lin7049a8f2015-01-30 11:55:39 +080018 gpio_input_pullup(GPIO_RECOVERY_SERVO);
19 gpio_input_pullup(GPIO_RECOVERY_PUSHKEY);
jinkun.hong692a2c02015-01-07 08:57:48 +080020}
21
22void fill_lb_gpios(struct lb_gpios *gpios)
23{
Julius Wernerc445b4f2016-03-31 17:27:05 -070024 struct lb_gpio chromeos_gpios[] = {
Julius Wernerc445b4f2016-03-31 17:27:05 -070025 /* Note for early development, we want to support both servo
26 * and pushkey recovery buttons in firmware boot stages. */
27 {GPIO_RECOVERY_PUSHKEY.raw, ACTIVE_LOW,
Matt Delco2cb39962019-04-30 14:59:43 -070028 !get_recovery_mode_switch(), "presence"},
Julius Wernerc445b4f2016-03-31 17:27:05 -070029 {GPIO_POWER.raw, ACTIVE_LOW, -1, "power"},
Julius Wernerc445b4f2016-03-31 17:27:05 -070030 {GPIO_RESET.raw, ACTIVE_HIGH, -1, "reset"},
31 };
32 lb_add_gpios(gpios, chromeos_gpios, ARRAY_SIZE(chromeos_gpios));
jinkun.hong692a2c02015-01-07 08:57:48 +080033}
34
jinkun.hong692a2c02015-01-07 08:57:48 +080035int get_recovery_mode_switch(void)
36{
Hung-Te Lin7049a8f2015-01-30 11:55:39 +080037 // Both RECOVERY_SERVO and RECOVERY_PUSHKEY are low active.
38 return !(gpio_get(GPIO_RECOVERY_SERVO) &&
39 gpio_get(GPIO_RECOVERY_PUSHKEY));
jinkun.hong692a2c02015-01-07 08:57:48 +080040}
41
42int get_write_protect_state(void)
43{
44 return !gpio_get(GPIO_WP);
45}