blob: 1006484e668383f09d02a2b5b8705bf1e2ce1b0a [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>
Aaron Durbinc625d092013-10-04 16:00:07 -050017#include <arch/io.h>
Furquan Shaikh0325dc62016-07-25 13:02:36 -070018#include <bootmode.h>
Aaron Durbinc625d092013-10-04 16:00:07 -050019#include <device/device.h>
20#include <device/pci.h>
Julius Werner18ea2d32014-10-07 16:42:17 -070021#include <soc/gpio.h>
Furquan Shaikh0325dc62016-07-25 13:02:36 -070022#include <vboot/vboot_common.h>
Aaron Durbinc625d092013-10-04 16:00:07 -050023
Aaron Durbin063c8732013-10-28 11:24:53 -050024#if CONFIG_EC_GOOGLE_CHROMEEC
25#include "ec.h"
26#include <ec/google/chromeec/ec.h>
27#endif
28
29/* The WP status pin lives on GPIO_SSUS_6 which is pad 36 in the SUS well. */
30#define WP_STATUS_PAD 36
Aaron Durbinc625d092013-10-04 16:00:07 -050031
32#ifndef __PRE_RAM__
33#include <boot/coreboot_tables.h>
34
Aaron Durbinc625d092013-10-04 16:00:07 -050035void fill_lb_gpios(struct lb_gpios *gpios)
36{
Julius Wernerc445b4f2016-03-31 17:27:05 -070037 struct lb_gpio chromeos_gpios[] = {
38 {-1, ACTIVE_HIGH, get_write_protect_state(), "write protect"},
Furquan Shaikh0325dc62016-07-25 13:02:36 -070039 {-1, ACTIVE_HIGH, vboot_recovery_mode_enabled(), "recovery"},
Julius Wernerc445b4f2016-03-31 17:27:05 -070040 {-1, ACTIVE_HIGH, get_developer_mode_switch(), "developer"},
41 {-1, ACTIVE_HIGH, get_lid_switch(), "lid"},
42 {-1, ACTIVE_HIGH, 0, "power"},
43 {-1, ACTIVE_HIGH, gfx_get_init_done(), "oprom"},
44 };
45 lb_add_gpios(gpios, chromeos_gpios, ARRAY_SIZE(chromeos_gpios));
Aaron Durbinc625d092013-10-04 16:00:07 -050046}
47#endif
48
Patrick Georgi08b87852015-05-28 11:59:33 +020049int get_lid_switch(void)
50{
51#if CONFIG_EC_GOOGLE_CHROMEEC
52 u8 ec_switches = inb(EC_LPC_ADDR_MEMMAP + EC_MEMMAP_SWITCHES);
53
54 return !!(ec_switches & EC_SWITCH_LID_OPEN);
55#else
56 /* Default to force open. */
57 return 1;
58#endif
59}
60
Aaron Durbinc625d092013-10-04 16:00:07 -050061int get_developer_mode_switch(void)
62{
Aaron Durbin063c8732013-10-28 11:24:53 -050063 return 0;
Aaron Durbinc625d092013-10-04 16:00:07 -050064}
65
66int get_recovery_mode_switch(void)
67{
Aaron Durbin063c8732013-10-28 11:24:53 -050068#if CONFIG_EC_GOOGLE_CHROMEEC
69 u8 ec_switches = inb(EC_LPC_ADDR_MEMMAP + EC_MEMMAP_SWITCHES);
70 u32 ec_events;
71
72 /* If a switch is set, we don't need to look at events. */
73 if (ec_switches & (EC_SWITCH_DEDICATED_RECOVERY))
74 return 1;
75
76 /* Else check if the EC has posted the keyboard recovery event. */
77 ec_events = google_chromeec_get_events_b();
78
79 return !!(ec_events &
80 EC_HOST_EVENT_MASK(EC_HOST_EVENT_KEYBOARD_RECOVERY));
81#else
82 return 0;
83#endif
Aaron Durbinc625d092013-10-04 16:00:07 -050084}
85
Sheng-Liang Song8c7e6222014-04-30 15:56:13 -070086int clear_recovery_mode_switch(void)
87{
88#if CONFIG_EC_GOOGLE_CHROMEEC
89 const uint32_t kb_rec_mask =
90 EC_HOST_EVENT_MASK(EC_HOST_EVENT_KEYBOARD_RECOVERY);
91 /* Unconditionally clear the EC recovery request. */
92 return google_chromeec_clear_events_b(kb_rec_mask);
93#else
94 return 0;
95#endif
96}
97
Aaron Durbinc625d092013-10-04 16:00:07 -050098int get_write_protect_state(void)
99{
Aaron Durbin4177db52014-02-05 14:55:26 -0600100 /*
101 * The vboot loader queries this function in romstage. The GPIOs have
102 * not been set up yet as that configuration is done in ramstage. The
103 * hardware defaults to an input but there is a 20K pulldown. Externally
104 * there is a 10K pullup. Disable the internal pull in romstage so that
105 * there isn't any ambiguity in the reading.
106 */
107#if defined(__PRE_RAM__)
108 ssus_disable_internal_pull(WP_STATUS_PAD);
109#endif
110
Aaron Durbin063c8732013-10-28 11:24:53 -0500111 /* WP is enabled when the pin is reading high. */
112 return ssus_get_gpio(WP_STATUS_PAD);
Aaron Durbinc625d092013-10-04 16:00:07 -0500113}