blob: d48c9c238be1ee784635cb9aabb41f252b6837da [file] [log] [blame]
Naresh G Solankiab5d6902016-10-15 18:13:55 +05301/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2013 Google Inc.
5 * Copyright (C) 2016 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.
15 */
16
Naresh G Solankiab5d6902016-10-15 18:13:55 +053017#include <device/device.h>
18#include <device/pci.h>
Naresh G Solankiab5d6902016-10-15 18:13:55 +053019#include <gpio.h>
20#include <soc/gpio.h>
21#include <string.h>
22#include <ec/google/chromeec/ec.h>
23#include <vendorcode/google/chromeos/chromeos.h>
24
25#include "gpio.h"
26#include "ec.h"
27
28#if ENV_RAMSTAGE
29#include <boot/coreboot_tables.h>
30
31void fill_lb_gpios(struct lb_gpios *gpios)
32{
33 struct lb_gpio chromeos_gpios[] = {
34 {-1, ACTIVE_HIGH, get_write_protect_state(), "write protect"},
35 {-1, ACTIVE_HIGH, get_recovery_mode_switch(), "recovery"},
Naresh G Solankiab5d6902016-10-15 18:13:55 +053036 {-1, ACTIVE_HIGH, get_lid_switch(), "lid"},
37 {-1, ACTIVE_HIGH, 0, "power"},
38 {-1, ACTIVE_HIGH, gfx_get_init_done(), "oprom"},
Naresh G Solankiab5d6902016-10-15 18:13:55 +053039 };
40 lb_add_gpios(gpios, chromeos_gpios, ARRAY_SIZE(chromeos_gpios));
41}
42#endif /* ENV_RAMSTAGE */
43
44int get_lid_switch(void)
45{
Naresh G Solankidd397f02016-11-06 14:05:35 +053046 if (IS_ENABLED(CONFIG_EC_GOOGLE_CHROMEEC))
47 /* Read lid switch state from the EC. */
48 return !!(google_chromeec_get_switches() & EC_SWITCH_LID_OPEN);
49
50 /* Lid always open */
51 return 1;
Naresh G Solankiab5d6902016-10-15 18:13:55 +053052}
53
Naresh G Solankiab5d6902016-10-15 18:13:55 +053054int get_recovery_mode_switch(void)
55{
Naresh G Solankidd397f02016-11-06 14:05:35 +053056 if (IS_ENABLED(CONFIG_EC_GOOGLE_CHROMEEC)) {
57 /* Check for dedicated recovery switch first. */
58 if (google_chromeec_get_switches() &
59 EC_SWITCH_DEDICATED_RECOVERY)
Naresh G Solankiab5d6902016-10-15 18:13:55 +053060 return 1;
61
Naresh G Solankidd397f02016-11-06 14:05:35 +053062 /* Otherwise check if the EC has posted the keyboard recovery
63 * event. */
64 return !!(google_chromeec_get_events_b() &
65 EC_HOST_EVENT_MASK(EC_HOST_EVENT_KEYBOARD_RECOVERY));
66 }
67
68 return 0;
Naresh G Solankiab5d6902016-10-15 18:13:55 +053069}
70
71int clear_recovery_mode_switch(void)
72{
Naresh G Solankidd397f02016-11-06 14:05:35 +053073 if (IS_ENABLED(CONFIG_EC_GOOGLE_CHROMEEC))
74 /* Clear keyboard recovery event. */
75 return google_chromeec_clear_events_b(
76 EC_HOST_EVENT_MASK(EC_HOST_EVENT_KEYBOARD_RECOVERY));
77
78 return 0;
Naresh G Solankiab5d6902016-10-15 18:13:55 +053079}
80
81int get_write_protect_state(void)
82{
Naresh G Solankidd397f02016-11-06 14:05:35 +053083 /* No write protect */
84 return 0;
Naresh G Solankiab5d6902016-10-15 18:13:55 +053085}
86
87static const struct cros_gpio cros_gpios[] = {
88 CROS_GPIO_REC_AL(CROS_GPIO_VIRTUAL, CROS_GPIO_DEVICE_NAME),
Naresh G Solankidd397f02016-11-06 14:05:35 +053089 CROS_GPIO_WP_AH(CROS_GPIO_VIRTUAL, CROS_GPIO_DEVICE_NAME),
Naresh G Solankiab5d6902016-10-15 18:13:55 +053090};
91
92void mainboard_chromeos_acpi_generate(void)
93{
94 chromeos_acpi_gpio_generate(cros_gpios, ARRAY_SIZE(cros_gpios));
95}