blob: 0c3fe2a6251044b0721c864d833de0c28f2c1d1f [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.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19
20#include <string.h>
Kyösti Mälkki16455892014-04-28 23:41:06 +030021#include <bootmode.h>
Aaron Durbinc625d092013-10-04 16:00:07 -050022#include <arch/io.h>
23#include <device/device.h>
24#include <device/pci.h>
Aaron Durbin063c8732013-10-28 11:24:53 -050025#include <baytrail/gpio.h>
Aaron Durbinc625d092013-10-04 16:00:07 -050026
Aaron Durbin063c8732013-10-28 11:24:53 -050027#if CONFIG_EC_GOOGLE_CHROMEEC
28#include "ec.h"
29#include <ec/google/chromeec/ec.h>
30#endif
31
32/* The WP status pin lives on GPIO_SSUS_6 which is pad 36 in the SUS well. */
33#define WP_STATUS_PAD 36
Aaron Durbinc625d092013-10-04 16:00:07 -050034
35#ifndef __PRE_RAM__
36#include <boot/coreboot_tables.h>
37
38#define GPIO_COUNT 6
Aaron Durbinc625d092013-10-04 16:00:07 -050039
Aaron Durbin063c8732013-10-28 11:24:53 -050040static int get_lid_switch(void)
41{
42#if CONFIG_EC_GOOGLE_CHROMEEC
43 u8 ec_switches = inb(EC_LPC_ADDR_MEMMAP + EC_MEMMAP_SWITCHES);
44
45 return !!(ec_switches & EC_SWITCH_LID_OPEN);
46#else
47 /* Default to force open. */
48 return 1;
49#endif
50}
51
Aaron Durbinc625d092013-10-04 16:00:07 -050052void fill_lb_gpios(struct lb_gpios *gpios)
53{
54 struct lb_gpio *gpio;
55
56 gpios->size = sizeof(*gpios) + (GPIO_COUNT * sizeof(struct lb_gpio));
57 gpios->count = GPIO_COUNT;
58
59 gpio = gpios->gpios;
Aaron Durbin063c8732013-10-28 11:24:53 -050060 fill_lb_gpio(gpio++, -1, ACTIVE_HIGH, "write protect",
61 get_write_protect_state());
62 fill_lb_gpio(gpio++, -1, ACTIVE_HIGH, "recovery",
63 get_recovery_mode_switch());
64 fill_lb_gpio(gpio++, -1, ACTIVE_HIGH, "developer",
65 get_developer_mode_switch());
66 fill_lb_gpio(gpio++, -1, ACTIVE_HIGH, "lid", get_lid_switch());
67 fill_lb_gpio(gpio++, -1, ACTIVE_HIGH, "power", 0);
Kyösti Mälkkiab56b3b2013-11-28 16:44:51 +020068 fill_lb_gpio(gpio++, -1, ACTIVE_HIGH, "oprom", gfx_get_init_done());
Aaron Durbinc625d092013-10-04 16:00:07 -050069}
70#endif
71
72int get_developer_mode_switch(void)
73{
Aaron Durbin063c8732013-10-28 11:24:53 -050074 return 0;
Aaron Durbinc625d092013-10-04 16:00:07 -050075}
76
77int get_recovery_mode_switch(void)
78{
Aaron Durbin063c8732013-10-28 11:24:53 -050079#if CONFIG_EC_GOOGLE_CHROMEEC
80 u8 ec_switches = inb(EC_LPC_ADDR_MEMMAP + EC_MEMMAP_SWITCHES);
81 u32 ec_events;
82
83 /* If a switch is set, we don't need to look at events. */
84 if (ec_switches & (EC_SWITCH_DEDICATED_RECOVERY))
85 return 1;
86
87 /* Else check if the EC has posted the keyboard recovery event. */
88 ec_events = google_chromeec_get_events_b();
89
90 return !!(ec_events &
91 EC_HOST_EVENT_MASK(EC_HOST_EVENT_KEYBOARD_RECOVERY));
92#else
93 return 0;
94#endif
Aaron Durbinc625d092013-10-04 16:00:07 -050095}
96
97int 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}