Duncan Laurie | cf72d91 | 2013-04-29 15:10:31 -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 | cf72d91 | 2013-04-29 15:10:31 -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 | cf72d91 | 2013-04-29 15:10:31 -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 | #ifndef __PRE_RAM__ |
| 29 | #include <boot/coreboot_tables.h> |
| 30 | |
| 31 | #define GPIO_COUNT 6 |
Duncan Laurie | cf72d91 | 2013-04-29 15:10:31 -0700 | [diff] [blame] | 32 | |
Duncan Laurie | cf72d91 | 2013-04-29 15:10:31 -0700 | [diff] [blame] | 33 | void fill_lb_gpios(struct lb_gpios *gpios) |
| 34 | { |
| 35 | struct lb_gpio *gpio; |
| 36 | |
| 37 | gpios->size = sizeof(*gpios) + (GPIO_COUNT * sizeof(struct lb_gpio)); |
| 38 | gpios->count = GPIO_COUNT; |
| 39 | |
| 40 | gpio = gpios->gpios; |
| 41 | fill_lb_gpio(gpio++, 58, ACTIVE_HIGH, "write protect", 0); |
| 42 | fill_lb_gpio(gpio++, -1, ACTIVE_HIGH, "recovery", |
| 43 | get_recovery_mode_switch()); |
| 44 | fill_lb_gpio(gpio++, -1, ACTIVE_HIGH, "developer", |
| 45 | get_developer_mode_switch()); |
| 46 | fill_lb_gpio(gpio++, -1, ACTIVE_HIGH, "lid", |
| 47 | get_lid_switch()); |
| 48 | fill_lb_gpio(gpio++, -1, ACTIVE_HIGH, "power", 0); |
Kyösti Mälkki | ab56b3b | 2013-11-28 16:44:51 +0200 | [diff] [blame] | 49 | fill_lb_gpio(gpio++, -1, ACTIVE_HIGH, "oprom", gfx_get_init_done()); |
Duncan Laurie | cf72d91 | 2013-04-29 15:10:31 -0700 | [diff] [blame] | 50 | } |
| 51 | #endif |
| 52 | |
Patrick Georgi | 08b8785 | 2015-05-28 11:59:33 +0200 | [diff] [blame] | 53 | int get_lid_switch(void) |
| 54 | { |
| 55 | #if CONFIG_EC_GOOGLE_CHROMEEC |
| 56 | u8 ec_switches = inb(EC_LPC_ADDR_MEMMAP + EC_MEMMAP_SWITCHES); |
| 57 | |
| 58 | return !!(ec_switches & EC_SWITCH_LID_OPEN); |
| 59 | #else |
| 60 | return 0; |
| 61 | #endif |
| 62 | } |
| 63 | |
Duncan Laurie | cf72d91 | 2013-04-29 15:10:31 -0700 | [diff] [blame] | 64 | /* The dev-switch is virtual */ |
| 65 | int get_developer_mode_switch(void) |
| 66 | { |
Duncan Laurie | 6a80590 | 2013-06-03 10:45:08 -0700 | [diff] [blame] | 67 | return 0; |
Duncan Laurie | cf72d91 | 2013-04-29 15:10:31 -0700 | [diff] [blame] | 68 | } |
| 69 | |
| 70 | /* There are actually two recovery switches. One is the magic keyboard chord, |
| 71 | * the other is driven by Servo. */ |
| 72 | int get_recovery_mode_switch(void) |
| 73 | { |
| 74 | #if CONFIG_EC_GOOGLE_CHROMEEC |
| 75 | u8 ec_switches = inb(EC_LPC_ADDR_MEMMAP + EC_MEMMAP_SWITCHES); |
| 76 | u32 ec_events; |
| 77 | |
| 78 | /* If a switch is set, we don't need to look at events. */ |
| 79 | if (ec_switches & (EC_SWITCH_DEDICATED_RECOVERY)) |
| 80 | return 1; |
| 81 | |
| 82 | /* Else check if the EC has posted the keyboard recovery event. */ |
| 83 | ec_events = google_chromeec_get_events_b(); |
| 84 | |
| 85 | return !!(ec_events & |
| 86 | EC_HOST_EVENT_MASK(EC_HOST_EVENT_KEYBOARD_RECOVERY)); |
| 87 | #else |
| 88 | return 0; |
| 89 | #endif |
| 90 | } |
| 91 | |
| 92 | int get_write_protect_state(void) |
| 93 | { |
| 94 | return get_gpio(58); |
| 95 | } |