blob: 853fc7f40034b51d57ec86fde37486f58af5be27 [file] [log] [blame]
Patrick Georgi406313d2015-07-20 22:01:32 +02001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2015 Google Inc.
5 * Copyright (C) 2015 Intel Corporation
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; version 2 of the License.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
Patrick Georgi406313d2015-07-20 22:01:32 +020015 */
16
17#include <arch/io.h>
18#include <console/console.h>
19#include <device/device.h>
20#include <device/pci.h>
21#include <rules.h>
Duncan Lauriec3281912015-08-13 12:54:27 -070022#include <gpio.h>
Patrick Georgi406313d2015-07-20 22:01:32 +020023#include <soc/gpio.h>
24#include <string.h>
Duncan Lauriec3281912015-08-13 12:54:27 -070025#include <ec/google/chromeec/ec.h>
Patrick Georgi406313d2015-07-20 22:01:32 +020026#include <vendorcode/google/chromeos/chromeos.h>
27
Duncan Laurie241f8fc2015-09-03 16:10:48 -070028#include "gpio.h"
Duncan Lauriec3281912015-08-13 12:54:27 -070029#include "ec.h"
30
Patrick Georgi406313d2015-07-20 22:01:32 +020031#if ENV_RAMSTAGE
32#include <boot/coreboot_tables.h>
33
Patrick Georgi406313d2015-07-20 22:01:32 +020034void fill_lb_gpios(struct lb_gpios *gpios)
35{
Duncan Lauriea58cf012015-08-20 09:54:18 -070036 struct lb_gpio *start_gpio = gpios->gpios;
37 struct lb_gpio *gpio = start_gpio;
Patrick Georgi406313d2015-07-20 22:01:32 +020038
Duncan Lauriecaa51492015-07-20 15:50:42 -070039 fill_lb_gpio(gpio++, -1, ACTIVE_HIGH, "write protect",
40 get_write_protect_state());
Patrick Georgi406313d2015-07-20 22:01:32 +020041 fill_lb_gpio(gpio++, -1, ACTIVE_HIGH, "recovery",
42 get_recovery_mode_switch());
43 fill_lb_gpio(gpio++, -1, ACTIVE_HIGH, "developer",
44 get_developer_mode_switch());
45 fill_lb_gpio(gpio++, -1, ACTIVE_HIGH, "lid",
46 get_lid_switch());
47 fill_lb_gpio(gpio++, -1, ACTIVE_HIGH, "power", 0);
48 fill_lb_gpio(gpio++, -1, ACTIVE_HIGH, "oprom", gfx_get_init_done());
Duncan Lauriea58cf012015-08-20 09:54:18 -070049 fill_lb_gpio(gpio++, GPIO_EC_IN_RW, ACTIVE_HIGH, "EC in RW",
50 gpio_get(GPIO_EC_IN_RW));
51
52 gpios->count = gpio - start_gpio;
53 gpios->size = sizeof(*gpios) + (gpios->count * sizeof(*gpio));
Patrick Georgi406313d2015-07-20 22:01:32 +020054}
55#endif /* ENV_RAMSTAGE */
56
57int get_lid_switch(void)
58{
Duncan Lauriec3281912015-08-13 12:54:27 -070059 /* Read lid switch state from the EC. */
60 return !!(google_chromeec_get_switches() & EC_SWITCH_LID_OPEN);
Patrick Georgi406313d2015-07-20 22:01:32 +020061}
Duncan Lauriec3281912015-08-13 12:54:27 -070062
Patrick Georgi406313d2015-07-20 22:01:32 +020063int get_developer_mode_switch(void)
64{
Duncan Lauriec3281912015-08-13 12:54:27 -070065 /* No physical developer mode switch. */
Patrick Georgi406313d2015-07-20 22:01:32 +020066 return 0;
67}
68
69int get_recovery_mode_switch(void)
70{
Duncan Lauriec3281912015-08-13 12:54:27 -070071 /* Check for dedicated recovery switch first. */
72 if (google_chromeec_get_switches() & EC_SWITCH_DEDICATED_RECOVERY)
73 return 1;
74
75 /* Otherwise check if the EC has posted the keyboard recovery event. */
76 return !!(google_chromeec_get_events_b() &
77 EC_HOST_EVENT_MASK(EC_HOST_EVENT_KEYBOARD_RECOVERY));
78}
79
80int clear_recovery_mode_switch(void)
81{
82 /* Clear keyboard recovery event. */
83 return google_chromeec_clear_events_b(
84 EC_HOST_EVENT_MASK(EC_HOST_EVENT_KEYBOARD_RECOVERY));
Patrick Georgi406313d2015-07-20 22:01:32 +020085}
86
87int get_write_protect_state(void)
88{
Duncan Lauriec3281912015-08-13 12:54:27 -070089 /* Read PCH_WP GPIO. */
Duncan Laurie56260852015-08-17 09:53:22 -070090 return gpio_get(GPIO_PCH_WP);
Patrick Georgi406313d2015-07-20 22:01:32 +020091}