2 * This file is part of the coreboot project.
4 * Copyright (C) 2015 Google Inc.
5 * Copyright (C) 2015 Intel Corporation
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.
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.
18 #include <console/console.h>
19 #include <device/device.h>
20 #include <device/pci.h>
25 #include <ec/google/chromeec/ec.h>
26 #include <vendorcode/google/chromeos/chromeos.h>
32 #include <boot/coreboot_tables.h>
34 void fill_lb_gpios(struct lb_gpios
*gpios
)
36 struct lb_gpio
*start_gpio
= gpios
->gpios
;
37 struct lb_gpio
*gpio
= start_gpio
;
39 fill_lb_gpio(gpio
++, -1, ACTIVE_HIGH
, "write protect",
40 get_write_protect_state());
41 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",
47 fill_lb_gpio(gpio
++, -1, ACTIVE_HIGH
, "power", 0);
48 fill_lb_gpio(gpio
++, -1, ACTIVE_HIGH
, "oprom", gfx_get_init_done());
49 fill_lb_gpio(gpio
++, GPIO_EC_IN_RW
, ACTIVE_HIGH
, "EC in RW",
50 gpio_get(GPIO_EC_IN_RW
));
52 gpios
->count
= gpio
- start_gpio
;
53 gpios
->size
= sizeof(*gpios
) + (gpios
->count
* sizeof(*gpio
));
55 #endif /* ENV_RAMSTAGE */
57 int get_lid_switch(void)
59 /* Read lid switch state from the EC. */
60 return !!(google_chromeec_get_switches() & EC_SWITCH_LID_OPEN
);
63 int get_developer_mode_switch(void)
65 /* No physical developer mode switch. */
69 int get_recovery_mode_switch(void)
71 /* Check for dedicated recovery switch first. */
72 if (google_chromeec_get_switches() & EC_SWITCH_DEDICATED_RECOVERY
)
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
));
80 int clear_recovery_mode_switch(void)
82 /* Clear keyboard recovery event. */
83 return google_chromeec_clear_events_b(
84 EC_HOST_EVENT_MASK(EC_HOST_EVENT_KEYBOARD_RECOVERY
));
87 int get_write_protect_state(void)
89 /* Read PCH_WP GPIO. */
90 return gpio_get(GPIO_PCH_WP
);