Duncan Laurie | 3ece50d | 2013-06-24 14:57:40 -0700 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright (C) 2012 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. |
Duncan Laurie | 3ece50d | 2013-06-24 14:57:40 -0700 | [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> |
Duncan Laurie | 3ece50d | 2013-06-24 14:57:40 -0700 | [diff] [blame] | 18 | #include <arch/io.h> |
| 19 | #include <device/device.h> |
| 20 | #include <device/pci.h> |
| 21 | #include <southbridge/intel/lynxpoint/pch.h> |
| 22 | |
| 23 | #if CONFIG_EC_GOOGLE_CHROMEEC |
| 24 | #include "ec.h" |
| 25 | #include <ec/google/chromeec/ec.h> |
| 26 | #endif |
| 27 | |
| 28 | /* SPI Write protect is GPIO 16 */ |
| 29 | #define CROS_WP_GPIO 16 |
| 30 | |
| 31 | #ifndef __PRE_RAM__ |
| 32 | #include <boot/coreboot_tables.h> |
| 33 | |
| 34 | #define GPIO_COUNT 6 |
Duncan Laurie | 3ece50d | 2013-06-24 14:57:40 -0700 | [diff] [blame] | 35 | |
Duncan Laurie | 3ece50d | 2013-06-24 14:57:40 -0700 | [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; |
| 44 | fill_lb_gpio(gpio++, CROS_WP_GPIO, ACTIVE_HIGH, "write protect", 0); |
| 45 | fill_lb_gpio(gpio++, -1, ACTIVE_HIGH, "recovery", |
| 46 | get_recovery_mode_switch()); |
| 47 | fill_lb_gpio(gpio++, -1, ACTIVE_HIGH, "developer", |
| 48 | get_developer_mode_switch()); |
| 49 | fill_lb_gpio(gpio++, -1, ACTIVE_HIGH, "lid", |
| 50 | 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()); |
Duncan Laurie | 3ece50d | 2013-06-24 14:57:40 -0700 | [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 | return 0; |
| 64 | #endif |
| 65 | } |
| 66 | |
Duncan Laurie | 3ece50d | 2013-06-24 14:57:40 -0700 | [diff] [blame] | 67 | /* The dev-switch is virtual */ |
| 68 | int get_developer_mode_switch(void) |
| 69 | { |
| 70 | return 0; |
| 71 | } |
| 72 | |
| 73 | /* There are actually two recovery switches. One is the magic keyboard chord, |
| 74 | * the other is driven by Servo. */ |
| 75 | int get_recovery_mode_switch(void) |
| 76 | { |
| 77 | #if CONFIG_EC_GOOGLE_CHROMEEC |
| 78 | u8 ec_switches = inb(EC_LPC_ADDR_MEMMAP + EC_MEMMAP_SWITCHES); |
| 79 | u32 ec_events; |
| 80 | |
| 81 | /* If a switch is set, we don't need to look at events. */ |
| 82 | if (ec_switches & (EC_SWITCH_DEDICATED_RECOVERY)) |
| 83 | return 1; |
| 84 | |
| 85 | /* Else check if the EC has posted the keyboard recovery event. */ |
| 86 | ec_events = google_chromeec_get_events_b(); |
| 87 | |
| 88 | return !!(ec_events & |
| 89 | EC_HOST_EVENT_MASK(EC_HOST_EVENT_KEYBOARD_RECOVERY)); |
| 90 | #else |
| 91 | return 0; |
| 92 | #endif |
| 93 | } |
| 94 | |
| 95 | int get_write_protect_state(void) |
| 96 | { |
| 97 | return get_gpio(CROS_WP_GPIO); |
| 98 | } |