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