blob: 6d00d72dee7c3f1ffeb144667a378fb0926d5c31 [file] [log] [blame]
Lee Leahy5cb9dda2015-05-01 10:34:54 -07001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2013 Google Inc.
5 * Copyright (C) 2015 Intel Corp.
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.
Lee Leahy5cb9dda2015-05-01 10:34:54 -070015 */
16
Lee Leahy5cb9dda2015-05-01 10:34:54 -070017#include <rules.h>
Hannah Williams9657f3b2016-01-22 23:04:05 -080018#include <gpio.h>
Lee Leahy5cb9dda2015-05-01 10:34:54 -070019#include <string.h>
20#include <vendorcode/google/chromeos/chromeos.h>
21
Hannah Williams9657f3b2016-01-22 23:04:05 -080022#define WP_GPIO GP_E_22
Lee Leahy5cb9dda2015-05-01 10:34:54 -070023
24#if ENV_RAMSTAGE
25#include <boot/coreboot_tables.h>
26
Lee Leahy5cb9dda2015-05-01 10:34:54 -070027#define ACTIVE_LOW 0
28#define ACTIVE_HIGH 1
29
30void fill_lb_gpios(struct lb_gpios *gpios)
31{
Julius Wernerc445b4f2016-03-31 17:27:05 -070032 struct lb_gpio chromeos_gpios[] = {
33 {-1, ACTIVE_HIGH, get_write_protect_state(), "write protect"},
Furquan Shaikh0325dc62016-07-25 13:02:36 -070034 {-1, ACTIVE_HIGH, vboot_recovery_mode_enabled(), "recovery"},
Julius Wernerc445b4f2016-03-31 17:27:05 -070035 {-1, ACTIVE_HIGH, get_developer_mode_switch(), "developer"},
36 {-1, ACTIVE_HIGH, get_lid_switch(), "lid"},
37 {-1, ACTIVE_HIGH, 0, "power"},
38 {-1, ACTIVE_HIGH, gfx_get_init_done(), "oprom"},
39 };
40 lb_add_gpios(gpios, chromeos_gpios, ARRAY_SIZE(chromeos_gpios));
Lee Leahy5cb9dda2015-05-01 10:34:54 -070041}
42#endif /* ENV_RAMSTAGE */
43
Lee Leahy5cb9dda2015-05-01 10:34:54 -070044int get_write_protect_state(void)
45{
46 /*
47 * The vboot loader queries this function in romstage. The GPIOs have
Hannah Williams9657f3b2016-01-22 23:04:05 -080048 * not been set up yet as that configuration is done in ramstage.
49 * Configuring this GPIO as input so that there isn't any ambiguity
50 * in the reading.
Lee Leahy5cb9dda2015-05-01 10:34:54 -070051 */
52#if ENV_ROMSTAGE
Hannah Williams9657f3b2016-01-22 23:04:05 -080053 gpio_input_pullup(WP_GPIO);
Lee Leahy5cb9dda2015-05-01 10:34:54 -070054#endif
55
56 /* WP is enabled when the pin is reading high. */
Hannah Williams9657f3b2016-01-22 23:04:05 -080057 return !!gpio_get(WP_GPIO);
Lee Leahy5cb9dda2015-05-01 10:34:54 -070058}
Aaron Durbinb0f81512016-07-25 21:31:41 -050059
60static const struct cros_gpio cros_gpios[] = {
61 CROS_GPIO_REC_AL(CROS_GPIO_VIRTUAL, CROS_GPIO_DEVICE_NAME),
62 CROS_GPIO_WP_AH(0x10013, CROS_GPIO_DEVICE_NAME),
63};
64
65void mainboard_chromeos_acpi_generate(void)
66{
67 chromeos_acpi_gpio_generate(cros_gpios, ARRAY_SIZE(cros_gpios));
68}