Aaron Durbin | c625d09 | 2013-10-04 16:00:07 -0500 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright (C) 2013 Google 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. |
Aaron Durbin | c625d09 | 2013-10-04 16:00:07 -0500 | [diff] [blame] | 14 | */ |
| 15 | |
| 16 | #include <string.h> |
Aaron Durbin | c625d09 | 2013-10-04 16:00:07 -0500 | [diff] [blame] | 17 | #include <arch/io.h> |
Furquan Shaikh | 0325dc6 | 2016-07-25 13:02:36 -0700 | [diff] [blame^] | 18 | #include <bootmode.h> |
Aaron Durbin | c625d09 | 2013-10-04 16:00:07 -0500 | [diff] [blame] | 19 | #include <device/device.h> |
| 20 | #include <device/pci.h> |
Julius Werner | 18ea2d3 | 2014-10-07 16:42:17 -0700 | [diff] [blame] | 21 | #include <soc/gpio.h> |
Furquan Shaikh | 0325dc6 | 2016-07-25 13:02:36 -0700 | [diff] [blame^] | 22 | #include <vboot/vboot_common.h> |
Aaron Durbin | c625d09 | 2013-10-04 16:00:07 -0500 | [diff] [blame] | 23 | |
Aaron Durbin | 063c873 | 2013-10-28 11:24:53 -0500 | [diff] [blame] | 24 | #if CONFIG_EC_GOOGLE_CHROMEEC |
| 25 | #include "ec.h" |
| 26 | #include <ec/google/chromeec/ec.h> |
| 27 | #endif |
| 28 | |
| 29 | /* The WP status pin lives on GPIO_SSUS_6 which is pad 36 in the SUS well. */ |
| 30 | #define WP_STATUS_PAD 36 |
Aaron Durbin | c625d09 | 2013-10-04 16:00:07 -0500 | [diff] [blame] | 31 | |
| 32 | #ifndef __PRE_RAM__ |
| 33 | #include <boot/coreboot_tables.h> |
| 34 | |
Aaron Durbin | c625d09 | 2013-10-04 16:00:07 -0500 | [diff] [blame] | 35 | void fill_lb_gpios(struct lb_gpios *gpios) |
| 36 | { |
Julius Werner | c445b4f | 2016-03-31 17:27:05 -0700 | [diff] [blame] | 37 | struct lb_gpio chromeos_gpios[] = { |
| 38 | {-1, ACTIVE_HIGH, get_write_protect_state(), "write protect"}, |
Furquan Shaikh | 0325dc6 | 2016-07-25 13:02:36 -0700 | [diff] [blame^] | 39 | {-1, ACTIVE_HIGH, vboot_recovery_mode_enabled(), "recovery"}, |
Julius Werner | c445b4f | 2016-03-31 17:27:05 -0700 | [diff] [blame] | 40 | {-1, ACTIVE_HIGH, get_developer_mode_switch(), "developer"}, |
| 41 | {-1, ACTIVE_HIGH, get_lid_switch(), "lid"}, |
| 42 | {-1, ACTIVE_HIGH, 0, "power"}, |
| 43 | {-1, ACTIVE_HIGH, gfx_get_init_done(), "oprom"}, |
| 44 | }; |
| 45 | lb_add_gpios(gpios, chromeos_gpios, ARRAY_SIZE(chromeos_gpios)); |
Aaron Durbin | c625d09 | 2013-10-04 16:00:07 -0500 | [diff] [blame] | 46 | } |
| 47 | #endif |
| 48 | |
Patrick Georgi | 08b8785 | 2015-05-28 11:59:33 +0200 | [diff] [blame] | 49 | int get_lid_switch(void) |
| 50 | { |
| 51 | #if CONFIG_EC_GOOGLE_CHROMEEC |
| 52 | u8 ec_switches = inb(EC_LPC_ADDR_MEMMAP + EC_MEMMAP_SWITCHES); |
| 53 | |
| 54 | return !!(ec_switches & EC_SWITCH_LID_OPEN); |
| 55 | #else |
| 56 | /* Default to force open. */ |
| 57 | return 1; |
| 58 | #endif |
| 59 | } |
| 60 | |
Aaron Durbin | c625d09 | 2013-10-04 16:00:07 -0500 | [diff] [blame] | 61 | int get_developer_mode_switch(void) |
| 62 | { |
Aaron Durbin | 063c873 | 2013-10-28 11:24:53 -0500 | [diff] [blame] | 63 | return 0; |
Aaron Durbin | c625d09 | 2013-10-04 16:00:07 -0500 | [diff] [blame] | 64 | } |
| 65 | |
| 66 | int get_recovery_mode_switch(void) |
| 67 | { |
Aaron Durbin | 063c873 | 2013-10-28 11:24:53 -0500 | [diff] [blame] | 68 | #if CONFIG_EC_GOOGLE_CHROMEEC |
| 69 | u8 ec_switches = inb(EC_LPC_ADDR_MEMMAP + EC_MEMMAP_SWITCHES); |
| 70 | u32 ec_events; |
| 71 | |
| 72 | /* If a switch is set, we don't need to look at events. */ |
| 73 | if (ec_switches & (EC_SWITCH_DEDICATED_RECOVERY)) |
| 74 | return 1; |
| 75 | |
| 76 | /* Else check if the EC has posted the keyboard recovery event. */ |
| 77 | ec_events = google_chromeec_get_events_b(); |
| 78 | |
| 79 | return !!(ec_events & |
| 80 | EC_HOST_EVENT_MASK(EC_HOST_EVENT_KEYBOARD_RECOVERY)); |
| 81 | #else |
| 82 | return 0; |
| 83 | #endif |
Aaron Durbin | c625d09 | 2013-10-04 16:00:07 -0500 | [diff] [blame] | 84 | } |
| 85 | |
Sheng-Liang Song | 8c7e622 | 2014-04-30 15:56:13 -0700 | [diff] [blame] | 86 | int clear_recovery_mode_switch(void) |
| 87 | { |
| 88 | #if CONFIG_EC_GOOGLE_CHROMEEC |
| 89 | const uint32_t kb_rec_mask = |
| 90 | EC_HOST_EVENT_MASK(EC_HOST_EVENT_KEYBOARD_RECOVERY); |
| 91 | /* Unconditionally clear the EC recovery request. */ |
| 92 | return google_chromeec_clear_events_b(kb_rec_mask); |
| 93 | #else |
| 94 | return 0; |
| 95 | #endif |
| 96 | } |
| 97 | |
Aaron Durbin | c625d09 | 2013-10-04 16:00:07 -0500 | [diff] [blame] | 98 | int get_write_protect_state(void) |
| 99 | { |
Aaron Durbin | 4177db5 | 2014-02-05 14:55:26 -0600 | [diff] [blame] | 100 | /* |
| 101 | * The vboot loader queries this function in romstage. The GPIOs have |
| 102 | * not been set up yet as that configuration is done in ramstage. The |
| 103 | * hardware defaults to an input but there is a 20K pulldown. Externally |
| 104 | * there is a 10K pullup. Disable the internal pull in romstage so that |
| 105 | * there isn't any ambiguity in the reading. |
| 106 | */ |
| 107 | #if defined(__PRE_RAM__) |
| 108 | ssus_disable_internal_pull(WP_STATUS_PAD); |
| 109 | #endif |
| 110 | |
Aaron Durbin | 063c873 | 2013-10-28 11:24:53 -0500 | [diff] [blame] | 111 | /* WP is enabled when the pin is reading high. */ |
| 112 | return ssus_get_gpio(WP_STATUS_PAD); |
Aaron Durbin | c625d09 | 2013-10-04 16:00:07 -0500 | [diff] [blame] | 113 | } |