tree: drop last paragraph of GPL copyright header
[coreboot.git] / src / mainboard / google / samus / chromeos.c
blob327690c5b7d0605a1b47f6aff34618166a4b49a8
1 /*
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.
16 #include <string.h>
17 #include <bootmode.h>
18 #include <arch/io.h>
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>
25 #include <soc/gpio.h>
28 /* SPI Write protect is GPIO 16 */
29 #define CROS_WP_GPIO 16
31 #ifndef __PRE_RAM__
32 #include <boot/coreboot_tables.h>
34 #define GPIO_COUNT 6
36 void fill_lb_gpios(struct lb_gpios *gpios)
38 struct lb_gpio *gpio;
40 gpios->size = sizeof(*gpios) + (GPIO_COUNT * sizeof(struct lb_gpio));
41 gpios->count = GPIO_COUNT;
43 gpio = gpios->gpios;
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",
50 get_lid_switch());
51 fill_lb_gpio(gpio++, -1, ACTIVE_HIGH, "power", 0);
52 fill_lb_gpio(gpio++, -1, ACTIVE_HIGH, "oprom", gfx_get_init_done());
54 #endif
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)
66 return 0;
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);
75 u32 ec_events;
77 /* If a switch is set, we don't need to look at events. */
78 if (ec_switches & (EC_SWITCH_DEDICATED_RECOVERY))
79 return 1;
81 /* Else check if the EC has posted the keyboard recovery event. */
82 ec_events = google_chromeec_get_events_b();
84 return !!(ec_events &
85 EC_HOST_EVENT_MASK(EC_HOST_EVENT_KEYBOARD_RECOVERY));
86 #else
87 return 0;
88 #endif
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);