2 * This file is part of the coreboot project.
4 * Copyright (C) 2013 Google Inc.
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.
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.
19 #include <device/device.h>
20 #include <device/pci.h>
21 #include <console/console.h>
22 #include <vendorcode/google/chromeos/chromeos.h>
23 #include <ec/google/chromeec/ec.h>
24 #include <ec/google/chromeec/ec_commands.h>
28 /* SPI Write protect is GPIO 16 */
29 #define CROS_WP_GPIO 16
32 #include <boot/coreboot_tables.h>
36 void fill_lb_gpios(struct lb_gpios
*gpios
)
40 gpios
->size
= sizeof(*gpios
) + (GPIO_COUNT
* sizeof(struct lb_gpio
));
41 gpios
->count
= GPIO_COUNT
;
44 fill_lb_gpio(gpio
++, CROS_WP_GPIO
, ACTIVE_HIGH
, "write protect", 0);
45 fill_lb_gpio(gpio
++, -1, ACTIVE_HIGH
, "recovery",
46 get_recovery_mode_switch());
47 fill_lb_gpio(gpio
++, -1, ACTIVE_HIGH
, "developer",
48 get_developer_mode_switch());
49 fill_lb_gpio(gpio
++, -1, ACTIVE_HIGH
, "lid",
51 fill_lb_gpio(gpio
++, -1, ACTIVE_HIGH
, "power", 0);
52 fill_lb_gpio(gpio
++, -1, ACTIVE_HIGH
, "oprom", gfx_get_init_done());
56 int get_lid_switch(void)
58 u8 ec_switches
= inb(EC_LPC_ADDR_MEMMAP
+ EC_MEMMAP_SWITCHES
);
60 return !!(ec_switches
& EC_SWITCH_LID_OPEN
);
63 /* The dev-switch is virtual */
64 int get_developer_mode_switch(void)
69 /* There are actually two recovery switches. One is the magic keyboard chord,
70 * the other is driven by Servo. */
71 int get_recovery_mode_switch(void)
73 #if CONFIG_EC_GOOGLE_CHROMEEC
74 u8 ec_switches
= inb(EC_LPC_ADDR_MEMMAP
+ EC_MEMMAP_SWITCHES
);
77 /* If a switch is set, we don't need to look at events. */
78 if (ec_switches
& (EC_SWITCH_DEDICATED_RECOVERY
))
81 /* Else check if the EC has posted the keyboard recovery event. */
82 ec_events
= google_chromeec_get_events_b();
85 EC_HOST_EVENT_MASK(EC_HOST_EVENT_KEYBOARD_RECOVERY
));
91 int clear_recovery_mode_switch(void)
93 const uint32_t kb_rec_mask
=
94 EC_HOST_EVENT_MASK(EC_HOST_EVENT_KEYBOARD_RECOVERY
);
96 /* Unconditionally clear the EC recovery request. */
97 return google_chromeec_clear_events_b(kb_rec_mask
);
100 int get_write_protect_state(void)
102 return get_gpio(CROS_WP_GPIO
);