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