blob: f2a2ab7abb824c8081fe40561904ef3810e6c51f [file] [log] [blame]
Aaron Durbinc625d092013-10-04 16:00:07 -05001/*
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.
Aaron Durbinc625d092013-10-04 16:00:07 -050014 */
15
16#include <string.h>
Kyösti Mälkki16455892014-04-28 23:41:06 +030017#include <bootmode.h>
Aaron Durbinc625d092013-10-04 16:00:07 -050018#include <arch/io.h>
19#include <device/device.h>
20#include <device/pci.h>
Julius Werner18ea2d32014-10-07 16:42:17 -070021#include <soc/gpio.h>
Aaron Durbinc625d092013-10-04 16:00:07 -050022
Aaron Durbin063c8732013-10-28 11:24:53 -050023#if CONFIG_EC_GOOGLE_CHROMEEC
24#include "ec.h"
25#include <ec/google/chromeec/ec.h>
26#endif
27
28/* The WP status pin lives on GPIO_SSUS_6 which is pad 36 in the SUS well. */
29#define WP_STATUS_PAD 36
Aaron Durbinc625d092013-10-04 16:00:07 -050030
31#ifndef __PRE_RAM__
32#include <boot/coreboot_tables.h>
33
Aaron Durbinc625d092013-10-04 16:00:07 -050034void fill_lb_gpios(struct lb_gpios *gpios)
35{
Julius Wernerc445b4f2016-03-31 17:27:05 -070036 struct lb_gpio chromeos_gpios[] = {
37 {-1, ACTIVE_HIGH, get_write_protect_state(), "write protect"},
38 {-1, ACTIVE_HIGH, recovery_mode_enabled(), "recovery"},
39 {-1, ACTIVE_HIGH, get_developer_mode_switch(), "developer"},
40 {-1, ACTIVE_HIGH, get_lid_switch(), "lid"},
41 {-1, ACTIVE_HIGH, 0, "power"},
42 {-1, ACTIVE_HIGH, gfx_get_init_done(), "oprom"},
43 };
44 lb_add_gpios(gpios, chromeos_gpios, ARRAY_SIZE(chromeos_gpios));
Aaron Durbinc625d092013-10-04 16:00:07 -050045}
46#endif
47
Patrick Georgi08b87852015-05-28 11:59:33 +020048int get_lid_switch(void)
49{
50#if CONFIG_EC_GOOGLE_CHROMEEC
51 u8 ec_switches = inb(EC_LPC_ADDR_MEMMAP + EC_MEMMAP_SWITCHES);
52
53 return !!(ec_switches & EC_SWITCH_LID_OPEN);
54#else
55 /* Default to force open. */
56 return 1;
57#endif
58}
59
Aaron Durbinc625d092013-10-04 16:00:07 -050060int get_developer_mode_switch(void)
61{
Aaron Durbin063c8732013-10-28 11:24:53 -050062 return 0;
Aaron Durbinc625d092013-10-04 16:00:07 -050063}
64
65int get_recovery_mode_switch(void)
66{
Aaron Durbin063c8732013-10-28 11:24:53 -050067#if CONFIG_EC_GOOGLE_CHROMEEC
68 u8 ec_switches = inb(EC_LPC_ADDR_MEMMAP + EC_MEMMAP_SWITCHES);
69 u32 ec_events;
70
71 /* If a switch is set, we don't need to look at events. */
72 if (ec_switches & (EC_SWITCH_DEDICATED_RECOVERY))
73 return 1;
74
75 /* Else check if the EC has posted the keyboard recovery event. */
76 ec_events = google_chromeec_get_events_b();
77
78 return !!(ec_events &
79 EC_HOST_EVENT_MASK(EC_HOST_EVENT_KEYBOARD_RECOVERY));
80#else
81 return 0;
82#endif
Aaron Durbinc625d092013-10-04 16:00:07 -050083}
84
Sheng-Liang Song8c7e6222014-04-30 15:56:13 -070085int clear_recovery_mode_switch(void)
86{
87#if CONFIG_EC_GOOGLE_CHROMEEC
88 const uint32_t kb_rec_mask =
89 EC_HOST_EVENT_MASK(EC_HOST_EVENT_KEYBOARD_RECOVERY);
90 /* Unconditionally clear the EC recovery request. */
91 return google_chromeec_clear_events_b(kb_rec_mask);
92#else
93 return 0;
94#endif
95}
96
Aaron Durbinc625d092013-10-04 16:00:07 -050097int get_write_protect_state(void)
98{
Aaron Durbin4177db52014-02-05 14:55:26 -060099 /*
100 * The vboot loader queries this function in romstage. The GPIOs have
101 * not been set up yet as that configuration is done in ramstage. The
102 * hardware defaults to an input but there is a 20K pulldown. Externally
103 * there is a 10K pullup. Disable the internal pull in romstage so that
104 * there isn't any ambiguity in the reading.
105 */
106#if defined(__PRE_RAM__)
107 ssus_disable_internal_pull(WP_STATUS_PAD);
108#endif
109
Aaron Durbin063c8732013-10-28 11:24:53 -0500110 /* WP is enabled when the pin is reading high. */
111 return ssus_get_gpio(WP_STATUS_PAD);
Aaron Durbinc625d092013-10-04 16:00:07 -0500112}