blob: 3f2e9c0a0debfe58c6a4afb7bfc973e5cc16c95e [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
34#define GPIO_COUNT 6
Aaron Durbinc625d092013-10-04 16:00:07 -050035
Aaron Durbinc625d092013-10-04 16:00:07 -050036void 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;
Aaron Durbin063c8732013-10-28 11:24:53 -050044 fill_lb_gpio(gpio++, -1, ACTIVE_HIGH, "write protect",
45 get_write_protect_state());
46 fill_lb_gpio(gpio++, -1, ACTIVE_HIGH, "recovery",
Sheng-Liang Song8c7e6222014-04-30 15:56:13 -070047 recovery_mode_enabled());
Aaron Durbin063c8732013-10-28 11:24:53 -050048 fill_lb_gpio(gpio++, -1, ACTIVE_HIGH, "developer",
49 get_developer_mode_switch());
50 fill_lb_gpio(gpio++, -1, ACTIVE_HIGH, "lid", 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());
Aaron Durbinc625d092013-10-04 16:00:07 -050053}
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 /* Default to force open. */
64 return 1;
65#endif
66}
67
Aaron Durbinc625d092013-10-04 16:00:07 -050068int get_developer_mode_switch(void)
69{
Aaron Durbin063c8732013-10-28 11:24:53 -050070 return 0;
Aaron Durbinc625d092013-10-04 16:00:07 -050071}
72
73int get_recovery_mode_switch(void)
74{
Aaron Durbin063c8732013-10-28 11:24:53 -050075#if CONFIG_EC_GOOGLE_CHROMEEC
76 u8 ec_switches = inb(EC_LPC_ADDR_MEMMAP + EC_MEMMAP_SWITCHES);
77 u32 ec_events;
78
79 /* If a switch is set, we don't need to look at events. */
80 if (ec_switches & (EC_SWITCH_DEDICATED_RECOVERY))
81 return 1;
82
83 /* Else check if the EC has posted the keyboard recovery event. */
84 ec_events = google_chromeec_get_events_b();
85
86 return !!(ec_events &
87 EC_HOST_EVENT_MASK(EC_HOST_EVENT_KEYBOARD_RECOVERY));
88#else
89 return 0;
90#endif
Aaron Durbinc625d092013-10-04 16:00:07 -050091}
92
Sheng-Liang Song8c7e6222014-04-30 15:56:13 -070093int clear_recovery_mode_switch(void)
94{
95#if CONFIG_EC_GOOGLE_CHROMEEC
96 const uint32_t kb_rec_mask =
97 EC_HOST_EVENT_MASK(EC_HOST_EVENT_KEYBOARD_RECOVERY);
98 /* Unconditionally clear the EC recovery request. */
99 return google_chromeec_clear_events_b(kb_rec_mask);
100#else
101 return 0;
102#endif
103}
104
Aaron Durbinc625d092013-10-04 16:00:07 -0500105int get_write_protect_state(void)
106{
Aaron Durbin4177db52014-02-05 14:55:26 -0600107 /*
108 * The vboot loader queries this function in romstage. The GPIOs have
109 * not been set up yet as that configuration is done in ramstage. The
110 * hardware defaults to an input but there is a 20K pulldown. Externally
111 * there is a 10K pullup. Disable the internal pull in romstage so that
112 * there isn't any ambiguity in the reading.
113 */
114#if defined(__PRE_RAM__)
115 ssus_disable_internal_pull(WP_STATUS_PAD);
116#endif
117
Aaron Durbin063c8732013-10-28 11:24:53 -0500118 /* WP is enabled when the pin is reading high. */
119 return ssus_get_gpio(WP_STATUS_PAD);
Aaron Durbinc625d092013-10-04 16:00:07 -0500120}