blob: 2f393e017271b8f46bb939de78a9081095ca8bdc [file] [log] [blame]
Duncan Laurie3ece50d2013-06-24 14:57:40 -07001/*
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 Laurie3ece50d2013-06-24 14:57:40 -070014 */
15
16#include <string.h>
Kyösti Mälkki16455892014-04-28 23:41:06 +030017#include <bootmode.h>
Duncan Laurie3ece50d2013-06-24 14:57:40 -070018#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 Laurie3ece50d2013-06-24 14:57:40 -070035
Duncan Laurie3ece50d2013-06-24 14:57:40 -070036void 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älkkiab56b3b2013-11-28 16:44:51 +020052 fill_lb_gpio(gpio++, -1, ACTIVE_HIGH, "oprom", gfx_get_init_done());
Duncan Laurie3ece50d2013-06-24 14:57:40 -070053}
54#endif
55
Patrick Georgi08b87852015-05-28 11:59:33 +020056int 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 Laurie3ece50d2013-06-24 14:57:40 -070067/* The dev-switch is virtual */
68int 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. */
75int 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
95int get_write_protect_state(void)
96{
97 return get_gpio(CROS_WP_GPIO);
98}