blob: fc1bcd2b9ddc7e7be0d7649458e6ac6749e9745b [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
17#include <arch/io.h>
18#include <console/console.h>
19#include <device/device.h>
20#include <device/pci.h>
21#include <rules.h>
22#include <gpio.h>
23#include <soc/gpio.h>
24#include <string.h>
25#include <ec/google/chromeec/ec.h>
26#include <vendorcode/google/chromeos/chromeos.h>
27
28#include "gpio.h"
29#include "ec.h"
30
31#if ENV_RAMSTAGE
32#include <boot/coreboot_tables.h>
33
34void fill_lb_gpios(struct lb_gpios *gpios)
35{
36 struct lb_gpio chromeos_gpios[] = {
37 {-1, ACTIVE_HIGH, get_write_protect_state(), "write protect"},
38 {-1, ACTIVE_HIGH, get_recovery_mode_switch(), "recovery"},
39 {-1, ACTIVE_HIGH, get_developer_mode_switch(), "developer"},
40 {-1, ACTIVE_HIGH, get_lid_switch(), "lid"},
41 {-1, ACTIVE_HIGH, 0, "power"},
42 {-1, ACTIVE_HIGH, gfx_get_init_done(), "oprom"},
Naresh G Solankiab5d6902016-10-15 18:13:55 +053043 };
44 lb_add_gpios(gpios, chromeos_gpios, ARRAY_SIZE(chromeos_gpios));
45}
46#endif /* ENV_RAMSTAGE */
47
48int get_lid_switch(void)
49{
Naresh G Solankidd397f02016-11-06 14:05:35 +053050 if (IS_ENABLED(CONFIG_EC_GOOGLE_CHROMEEC))
51 /* Read lid switch state from the EC. */
52 return !!(google_chromeec_get_switches() & EC_SWITCH_LID_OPEN);
53
54 /* Lid always open */
55 return 1;
Naresh G Solankiab5d6902016-10-15 18:13:55 +053056}
57
58int get_developer_mode_switch(void)
59{
60 /* No physical developer mode switch. */
61 return 0;
62}
63
64int get_recovery_mode_switch(void)
65{
Naresh G Solankidd397f02016-11-06 14:05:35 +053066 if (IS_ENABLED(CONFIG_EC_GOOGLE_CHROMEEC)) {
67 /* Check for dedicated recovery switch first. */
68 if (google_chromeec_get_switches() &
69 EC_SWITCH_DEDICATED_RECOVERY)
Naresh G Solankiab5d6902016-10-15 18:13:55 +053070 return 1;
71
Naresh G Solankidd397f02016-11-06 14:05:35 +053072 /* Otherwise check if the EC has posted the keyboard recovery
73 * event. */
74 return !!(google_chromeec_get_events_b() &
75 EC_HOST_EVENT_MASK(EC_HOST_EVENT_KEYBOARD_RECOVERY));
76 }
77
78 return 0;
Naresh G Solankiab5d6902016-10-15 18:13:55 +053079}
80
81int clear_recovery_mode_switch(void)
82{
Naresh G Solankidd397f02016-11-06 14:05:35 +053083 if (IS_ENABLED(CONFIG_EC_GOOGLE_CHROMEEC))
84 /* Clear keyboard recovery event. */
85 return google_chromeec_clear_events_b(
86 EC_HOST_EVENT_MASK(EC_HOST_EVENT_KEYBOARD_RECOVERY));
87
88 return 0;
Naresh G Solankiab5d6902016-10-15 18:13:55 +053089}
90
91int get_write_protect_state(void)
92{
Naresh G Solankidd397f02016-11-06 14:05:35 +053093 /* No write protect */
94 return 0;
Naresh G Solankiab5d6902016-10-15 18:13:55 +053095}
96
97static const struct cros_gpio cros_gpios[] = {
98 CROS_GPIO_REC_AL(CROS_GPIO_VIRTUAL, CROS_GPIO_DEVICE_NAME),
Naresh G Solankidd397f02016-11-06 14:05:35 +053099 CROS_GPIO_WP_AH(CROS_GPIO_VIRTUAL, CROS_GPIO_DEVICE_NAME),
Naresh G Solankiab5d6902016-10-15 18:13:55 +0530100};
101
102void mainboard_chromeos_acpi_generate(void)
103{
104 chromeos_acpi_gpio_generate(cros_gpios, ARRAY_SIZE(cros_gpios));
105}