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. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program; if not, write to the Free Software |
| 17 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 18 | */ |
| 19 | |
| 20 | #include <string.h> |
| 21 | #include <vendorcode/google/chromeos/chromeos.h> |
| 22 | #include <arch/io.h> |
| 23 | #include <device/device.h> |
| 24 | #include <device/pci.h> |
Aaron Durbin | 063c873 | 2013-10-28 11:24:53 -0500 | [diff] [blame^] | 25 | #include <baytrail/gpio.h> |
Aaron Durbin | c625d09 | 2013-10-04 16:00:07 -0500 | [diff] [blame] | 26 | |
Aaron Durbin | 063c873 | 2013-10-28 11:24:53 -0500 | [diff] [blame^] | 27 | #if CONFIG_EC_GOOGLE_CHROMEEC |
| 28 | #include "ec.h" |
| 29 | #include <ec/google/chromeec/ec.h> |
| 30 | #endif |
| 31 | |
| 32 | /* The WP status pin lives on GPIO_SSUS_6 which is pad 36 in the SUS well. */ |
| 33 | #define WP_STATUS_PAD 36 |
Aaron Durbin | c625d09 | 2013-10-04 16:00:07 -0500 | [diff] [blame] | 34 | |
| 35 | #ifndef __PRE_RAM__ |
| 36 | #include <boot/coreboot_tables.h> |
| 37 | |
| 38 | #define GPIO_COUNT 6 |
| 39 | #define ACTIVE_LOW 0 |
| 40 | #define ACTIVE_HIGH 1 |
| 41 | |
Aaron Durbin | 063c873 | 2013-10-28 11:24:53 -0500 | [diff] [blame^] | 42 | static int get_lid_switch(void) |
| 43 | { |
| 44 | #if CONFIG_EC_GOOGLE_CHROMEEC |
| 45 | u8 ec_switches = inb(EC_LPC_ADDR_MEMMAP + EC_MEMMAP_SWITCHES); |
| 46 | |
| 47 | return !!(ec_switches & EC_SWITCH_LID_OPEN); |
| 48 | #else |
| 49 | /* Default to force open. */ |
| 50 | return 1; |
| 51 | #endif |
| 52 | } |
| 53 | |
| 54 | static void fill_lb_gpio(struct lb_gpio *gpio, int port, int polarity, |
Aaron Durbin | c625d09 | 2013-10-04 16:00:07 -0500 | [diff] [blame] | 55 | const char *name, int force) |
| 56 | { |
| 57 | memset(gpio, 0, sizeof(*gpio)); |
Aaron Durbin | 063c873 | 2013-10-28 11:24:53 -0500 | [diff] [blame^] | 58 | gpio->port = port; |
Aaron Durbin | c625d09 | 2013-10-04 16:00:07 -0500 | [diff] [blame] | 59 | gpio->polarity = polarity; |
| 60 | if (force >= 0) |
| 61 | gpio->value = force; |
| 62 | strncpy((char *)gpio->name, name, GPIO_MAX_NAME_LENGTH); |
| 63 | } |
| 64 | |
| 65 | void fill_lb_gpios(struct lb_gpios *gpios) |
| 66 | { |
| 67 | struct lb_gpio *gpio; |
| 68 | |
| 69 | gpios->size = sizeof(*gpios) + (GPIO_COUNT * sizeof(struct lb_gpio)); |
| 70 | gpios->count = GPIO_COUNT; |
| 71 | |
| 72 | gpio = gpios->gpios; |
Aaron Durbin | 063c873 | 2013-10-28 11:24:53 -0500 | [diff] [blame^] | 73 | fill_lb_gpio(gpio++, -1, ACTIVE_HIGH, "write protect", |
| 74 | get_write_protect_state()); |
| 75 | fill_lb_gpio(gpio++, -1, ACTIVE_HIGH, "recovery", |
| 76 | get_recovery_mode_switch()); |
| 77 | fill_lb_gpio(gpio++, -1, ACTIVE_HIGH, "developer", |
| 78 | get_developer_mode_switch()); |
| 79 | fill_lb_gpio(gpio++, -1, ACTIVE_HIGH, "lid", get_lid_switch()); |
| 80 | fill_lb_gpio(gpio++, -1, ACTIVE_HIGH, "power", 0); |
| 81 | fill_lb_gpio(gpio++, -1, ACTIVE_HIGH, "oprom", oprom_is_loaded); |
Aaron Durbin | c625d09 | 2013-10-04 16:00:07 -0500 | [diff] [blame] | 82 | } |
| 83 | #endif |
| 84 | |
| 85 | int get_developer_mode_switch(void) |
| 86 | { |
Aaron Durbin | 063c873 | 2013-10-28 11:24:53 -0500 | [diff] [blame^] | 87 | return 0; |
Aaron Durbin | c625d09 | 2013-10-04 16:00:07 -0500 | [diff] [blame] | 88 | } |
| 89 | |
| 90 | int get_recovery_mode_switch(void) |
| 91 | { |
Aaron Durbin | 063c873 | 2013-10-28 11:24:53 -0500 | [diff] [blame^] | 92 | #if CONFIG_EC_GOOGLE_CHROMEEC |
| 93 | u8 ec_switches = inb(EC_LPC_ADDR_MEMMAP + EC_MEMMAP_SWITCHES); |
| 94 | u32 ec_events; |
| 95 | |
| 96 | /* If a switch is set, we don't need to look at events. */ |
| 97 | if (ec_switches & (EC_SWITCH_DEDICATED_RECOVERY)) |
| 98 | return 1; |
| 99 | |
| 100 | /* Else check if the EC has posted the keyboard recovery event. */ |
| 101 | ec_events = google_chromeec_get_events_b(); |
| 102 | |
| 103 | return !!(ec_events & |
| 104 | EC_HOST_EVENT_MASK(EC_HOST_EVENT_KEYBOARD_RECOVERY)); |
| 105 | #else |
| 106 | return 0; |
| 107 | #endif |
Aaron Durbin | c625d09 | 2013-10-04 16:00:07 -0500 | [diff] [blame] | 108 | } |
| 109 | |
| 110 | int get_write_protect_state(void) |
| 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 | } |
| 115 | |