blob: a7d96a856210ee6d00ac4aa818e29affebc85bf9 [file] [log] [blame]
Duncan Lauriecf72d912013-04-29 15:10:31 -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 Lauriecf72d912013-04-29 15:10:31 -070014 */
15
16#include <string.h>
Kyösti Mälkki16455892014-04-28 23:41:06 +030017#include <bootmode.h>
Duncan Lauriecf72d912013-04-29 15:10:31 -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#ifndef __PRE_RAM__
29#include <boot/coreboot_tables.h>
30
31#define GPIO_COUNT 6
Duncan Lauriecf72d912013-04-29 15:10:31 -070032
Duncan Lauriecf72d912013-04-29 15:10:31 -070033void 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älkkiab56b3b2013-11-28 16:44:51 +020049 fill_lb_gpio(gpio++, -1, ACTIVE_HIGH, "oprom", gfx_get_init_done());
Duncan Lauriecf72d912013-04-29 15:10:31 -070050}
51#endif
52
Patrick Georgi08b87852015-05-28 11:59:33 +020053int 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 Lauriecf72d912013-04-29 15:10:31 -070064/* The dev-switch is virtual */
65int get_developer_mode_switch(void)
66{
Duncan Laurie6a805902013-06-03 10:45:08 -070067 return 0;
Duncan Lauriecf72d912013-04-29 15:10:31 -070068}
69
70/* There are actually two recovery switches. One is the magic keyboard chord,
71 * the other is driven by Servo. */
72int 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
92int get_write_protect_state(void)
93{
94 return get_gpio(58);
95}