Martin Roth | 0cd338e | 2016-07-29 14:07:30 -0600 | [diff] [blame] | 1 | /* |
jinkun.hong | 692a2c0 | 2015-01-07 08:57:48 +0800 | [diff] [blame] | 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright 2014 Rockchip Inc. |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; version 2 of the License. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
jinkun.hong | 692a2c0 | 2015-01-07 08:57:48 +0800 | [diff] [blame] | 14 | */ |
| 15 | |
| 16 | #include <boot/coreboot_tables.h> |
| 17 | #include <console/console.h> |
| 18 | #include <gpio.h> |
| 19 | #include <string.h> |
| 20 | #include <vendorcode/google/chromeos/chromeos.h> |
| 21 | |
| 22 | #include "board.h" |
| 23 | |
| 24 | #define GPIO_WP GPIO(7, A, 6) |
| 25 | #define GPIO_POWER GPIO(0, A, 5) |
Hung-Te Lin | 7049a8f | 2015-01-30 11:55:39 +0800 | [diff] [blame] | 26 | #define GPIO_RECOVERY_SERVO GPIO(0, B, 1) |
| 27 | #define GPIO_RECOVERY_PUSHKEY GPIO(7, B, 1) |
Jonathan Dixon | 2580508 | 2015-04-01 14:02:34 -0700 | [diff] [blame] | 28 | |
jinkun.hong | 692a2c0 | 2015-01-07 08:57:48 +0800 | [diff] [blame] | 29 | |
| 30 | void setup_chromeos_gpios(void) |
| 31 | { |
| 32 | gpio_input(GPIO_WP); |
| 33 | gpio_input(GPIO_POWER); |
Hung-Te Lin | 7049a8f | 2015-01-30 11:55:39 +0800 | [diff] [blame] | 34 | gpio_input_pullup(GPIO_RECOVERY_SERVO); |
| 35 | gpio_input_pullup(GPIO_RECOVERY_PUSHKEY); |
jinkun.hong | 692a2c0 | 2015-01-07 08:57:48 +0800 | [diff] [blame] | 36 | } |
| 37 | |
| 38 | void fill_lb_gpios(struct lb_gpios *gpios) |
| 39 | { |
Julius Werner | c445b4f | 2016-03-31 17:27:05 -0700 | [diff] [blame] | 40 | struct lb_gpio chromeos_gpios[] = { |
| 41 | {GPIO_WP.raw, ACTIVE_LOW, gpio_get(GPIO_WP), "write protect"}, |
| 42 | /* Note for early development, we want to support both servo |
| 43 | * and pushkey recovery buttons in firmware boot stages. */ |
| 44 | {GPIO_RECOVERY_PUSHKEY.raw, ACTIVE_LOW, |
| 45 | !get_recovery_mode_switch(), "recovery"}, |
| 46 | {GPIO_POWER.raw, ACTIVE_LOW, -1, "power"}, |
| 47 | {-1, ACTIVE_HIGH, get_developer_mode_switch(), "developer"}, |
| 48 | {GPIO_RESET.raw, ACTIVE_HIGH, -1, "reset"}, |
| 49 | }; |
| 50 | lb_add_gpios(gpios, chromeos_gpios, ARRAY_SIZE(chromeos_gpios)); |
jinkun.hong | 692a2c0 | 2015-01-07 08:57:48 +0800 | [diff] [blame] | 51 | } |
| 52 | |
| 53 | int get_developer_mode_switch(void) |
| 54 | { |
Alexandru M Stan | 70cada2 | 2016-02-03 17:28:38 -0800 | [diff] [blame] | 55 | return 0; |
jinkun.hong | 692a2c0 | 2015-01-07 08:57:48 +0800 | [diff] [blame] | 56 | } |
| 57 | |
| 58 | int get_recovery_mode_switch(void) |
| 59 | { |
Hung-Te Lin | 7049a8f | 2015-01-30 11:55:39 +0800 | [diff] [blame] | 60 | // Both RECOVERY_SERVO and RECOVERY_PUSHKEY are low active. |
| 61 | return !(gpio_get(GPIO_RECOVERY_SERVO) && |
| 62 | gpio_get(GPIO_RECOVERY_PUSHKEY)); |
jinkun.hong | 692a2c0 | 2015-01-07 08:57:48 +0800 | [diff] [blame] | 63 | } |
| 64 | |
| 65 | int get_write_protect_state(void) |
| 66 | { |
| 67 | return !gpio_get(GPIO_WP); |
| 68 | } |