blob: 8bd35bee954f4403d60d422d5a5c5110c30ec0b4 [file] [log] [blame]
Gabe Blackd3163ab2013-05-16 05:53:40 -07001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright 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.
Gabe Blackd3163ab2013-05-16 05:53:40 -070014 */
15
16#include <boot/coreboot_tables.h>
Julius Werner80af4422014-10-20 13:18:56 -070017#include <bootmode.h>
Gabe Blackd3163ab2013-05-16 05:53:40 -070018#include <ec/google/chromeec/ec.h>
19#include <ec/google/chromeec/ec_commands.h>
Julius Werner80af4422014-10-20 13:18:56 -070020#include <soc/cpu.h>
21#include <soc/gpio.h>
Gabe Blackd3163ab2013-05-16 05:53:40 -070022#include <string.h>
23#include <vendorcode/google/chromeos/chromeos.h>
Gabe Blackd3163ab2013-05-16 05:53:40 -070024
Gabe Blackd3163ab2013-05-16 05:53:40 -070025void fill_lb_gpios(struct lb_gpios *gpios)
26{
Joel Kitching2e1f6552019-03-23 12:41:04 +080027 struct lb_gpio chromeos_gpios[] = {
28 /* Write Protect: active low (WP_GPIO) */
Joel Kitchingae0fb762019-04-07 00:37:14 +080029 {EXYNOS5_GPX3, ACTIVE_LOW, !get_write_protect_state(),
Joel Kitching2e1f6552019-03-23 12:41:04 +080030 "write protect"},
Gabe Blackd3163ab2013-05-16 05:53:40 -070031
Joel Kitching2e1f6552019-03-23 12:41:04 +080032 /* Lid: active high (LID_GPIO) */
33 {EXYNOS5_GPX3, ACTIVE_HIGH, gpio_get_value(GPIO_X34), "lid"},
Gabe Blackd3163ab2013-05-16 05:53:40 -070034
Joel Kitching2e1f6552019-03-23 12:41:04 +080035 /* Power: virtual GPIO active low (POWER_GPIO) */
36 {EXYNOS5_GPX1, ACTIVE_LOW, gpio_get_value(GPIO_X12), "power"},
37 };
38 lb_add_gpios(gpios, chromeos_gpios, ARRAY_SIZE(chromeos_gpios));
Gabe Blackd3163ab2013-05-16 05:53:40 -070039}
40
Gabe Blackd3163ab2013-05-16 05:53:40 -070041int get_recovery_mode_switch(void)
42{
Furquan Shaikh8788fd62017-11-20 20:28:18 -080043 uint64_t ec_events;
Gabe Blackd3163ab2013-05-16 05:53:40 -070044
45 /* The GPIO is active low. */
Gabe Black63bb6102013-06-19 03:29:45 -070046 if (!gpio_get_value(GPIO_X07)) // RECMODE_GPIO
Gabe Blackd3163ab2013-05-16 05:53:40 -070047 return 1;
48
49 ec_events = google_chromeec_get_events_b();
50 return !!(ec_events &
51 EC_HOST_EVENT_MASK(EC_HOST_EVENT_KEYBOARD_RECOVERY));
52}
53
Stefan Reinaueraaaf6892013-08-29 15:57:11 -070054int get_write_protect_state(void)
Gabe Blackd3163ab2013-05-16 05:53:40 -070055{
Gabe Blackd29bf202013-09-12 06:23:51 -070056 return !gpio_get_value(GPIO_X30);
Gabe Blackd3163ab2013-05-16 05:53:40 -070057}