Angel Pons | 2e53038 | 2020-04-05 13:23:08 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
jinkun.hong | 692a2c0 | 2015-01-07 08:57:48 +0800 | [diff] [blame] | 2 | |
Kyösti Mälkki | f122696 | 2021-11-03 17:19:31 +0200 | [diff] [blame^] | 3 | #include <bootmode.h> |
jinkun.hong | 692a2c0 | 2015-01-07 08:57:48 +0800 | [diff] [blame] | 4 | #include <boot/coreboot_tables.h> |
jinkun.hong | 692a2c0 | 2015-01-07 08:57:48 +0800 | [diff] [blame] | 5 | #include <gpio.h> |
jinkun.hong | 692a2c0 | 2015-01-07 08:57:48 +0800 | [diff] [blame] | 6 | |
| 7 | #include "board.h" |
| 8 | |
| 9 | #define GPIO_WP GPIO(7, A, 6) |
| 10 | #define GPIO_POWER GPIO(0, A, 5) |
Hung-Te Lin | 7049a8f | 2015-01-30 11:55:39 +0800 | [diff] [blame] | 11 | #define GPIO_RECOVERY_SERVO GPIO(0, B, 1) |
| 12 | #define GPIO_RECOVERY_PUSHKEY GPIO(7, B, 1) |
Jonathan Dixon | 2580508 | 2015-04-01 14:02:34 -0700 | [diff] [blame] | 13 | |
jinkun.hong | 692a2c0 | 2015-01-07 08:57:48 +0800 | [diff] [blame] | 14 | void setup_chromeos_gpios(void) |
| 15 | { |
| 16 | gpio_input(GPIO_WP); |
| 17 | gpio_input(GPIO_POWER); |
Hung-Te Lin | 7049a8f | 2015-01-30 11:55:39 +0800 | [diff] [blame] | 18 | gpio_input_pullup(GPIO_RECOVERY_SERVO); |
| 19 | gpio_input_pullup(GPIO_RECOVERY_PUSHKEY); |
jinkun.hong | 692a2c0 | 2015-01-07 08:57:48 +0800 | [diff] [blame] | 20 | } |
| 21 | |
| 22 | void fill_lb_gpios(struct lb_gpios *gpios) |
| 23 | { |
Julius Werner | c445b4f | 2016-03-31 17:27:05 -0700 | [diff] [blame] | 24 | struct lb_gpio chromeos_gpios[] = { |
Julius Werner | c445b4f | 2016-03-31 17:27:05 -0700 | [diff] [blame] | 25 | /* 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 Delco | 2cb3996 | 2019-04-30 14:59:43 -0700 | [diff] [blame] | 28 | !get_recovery_mode_switch(), "presence"}, |
Julius Werner | c445b4f | 2016-03-31 17:27:05 -0700 | [diff] [blame] | 29 | {GPIO_POWER.raw, ACTIVE_LOW, -1, "power"}, |
Julius Werner | c445b4f | 2016-03-31 17:27:05 -0700 | [diff] [blame] | 30 | {GPIO_RESET.raw, ACTIVE_HIGH, -1, "reset"}, |
| 31 | }; |
| 32 | lb_add_gpios(gpios, chromeos_gpios, ARRAY_SIZE(chromeos_gpios)); |
jinkun.hong | 692a2c0 | 2015-01-07 08:57:48 +0800 | [diff] [blame] | 33 | } |
| 34 | |
jinkun.hong | 692a2c0 | 2015-01-07 08:57:48 +0800 | [diff] [blame] | 35 | int get_recovery_mode_switch(void) |
| 36 | { |
Hung-Te Lin | 7049a8f | 2015-01-30 11:55:39 +0800 | [diff] [blame] | 37 | // Both RECOVERY_SERVO and RECOVERY_PUSHKEY are low active. |
| 38 | return !(gpio_get(GPIO_RECOVERY_SERVO) && |
| 39 | gpio_get(GPIO_RECOVERY_PUSHKEY)); |
jinkun.hong | 692a2c0 | 2015-01-07 08:57:48 +0800 | [diff] [blame] | 40 | } |
| 41 | |
| 42 | int get_write_protect_state(void) |
| 43 | { |
| 44 | return !gpio_get(GPIO_WP); |
| 45 | } |