blob: 4304179d4b8ea8cb099b85286d656433656d9157 [file] [log] [blame]
Aaron Durbinc625d092013-10-04 16:00:07 -05001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2013 Google Inc.
5 *
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.
9 *
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.
Aaron Durbinc625d092013-10-04 16:00:07 -050014 */
15
16#include <string.h>
Aaron Durbinc625d092013-10-04 16:00:07 -050017#include <arch/io.h>
Furquan Shaikh0325dc62016-07-25 13:02:36 -070018#include <bootmode.h>
Aaron Durbinc625d092013-10-04 16:00:07 -050019#include <device/device.h>
20#include <device/pci.h>
Julius Werner18ea2d32014-10-07 16:42:17 -070021#include <soc/gpio.h>
Furquan Shaikh0325dc62016-07-25 13:02:36 -070022#include <vboot/vboot_common.h>
Aaron Durbinb0f81512016-07-25 21:31:41 -050023#include <vendorcode/google/chromeos/chromeos.h>
Aaron Durbinc625d092013-10-04 16:00:07 -050024
Aaron Durbin063c8732013-10-28 11:24:53 -050025#if CONFIG_EC_GOOGLE_CHROMEEC
26#include "ec.h"
27#include <ec/google/chromeec/ec.h>
28#endif
29
30/* The WP status pin lives on GPIO_SSUS_6 which is pad 36 in the SUS well. */
31#define WP_STATUS_PAD 36
Aaron Durbinc625d092013-10-04 16:00:07 -050032
33#ifndef __PRE_RAM__
34#include <boot/coreboot_tables.h>
35
Aaron Durbinc625d092013-10-04 16:00:07 -050036void fill_lb_gpios(struct lb_gpios *gpios)
37{
Julius Wernerc445b4f2016-03-31 17:27:05 -070038 struct lb_gpio chromeos_gpios[] = {
39 {-1, ACTIVE_HIGH, get_write_protect_state(), "write protect"},
Furquan Shaikh0325dc62016-07-25 13:02:36 -070040 {-1, ACTIVE_HIGH, vboot_recovery_mode_enabled(), "recovery"},
Julius Wernerc445b4f2016-03-31 17:27:05 -070041 {-1, ACTIVE_HIGH, get_developer_mode_switch(), "developer"},
42 {-1, ACTIVE_HIGH, get_lid_switch(), "lid"},
43 {-1, ACTIVE_HIGH, 0, "power"},
44 {-1, ACTIVE_HIGH, gfx_get_init_done(), "oprom"},
45 };
46 lb_add_gpios(gpios, chromeos_gpios, ARRAY_SIZE(chromeos_gpios));
Aaron Durbinc625d092013-10-04 16:00:07 -050047}
48#endif
49
Patrick Georgi08b87852015-05-28 11:59:33 +020050int get_lid_switch(void)
51{
52#if CONFIG_EC_GOOGLE_CHROMEEC
53 u8 ec_switches = inb(EC_LPC_ADDR_MEMMAP + EC_MEMMAP_SWITCHES);
54
55 return !!(ec_switches & EC_SWITCH_LID_OPEN);
56#else
57 /* Default to force open. */
58 return 1;
59#endif
60}
61
Aaron Durbinc625d092013-10-04 16:00:07 -050062int get_developer_mode_switch(void)
63{
Aaron Durbin063c8732013-10-28 11:24:53 -050064 return 0;
Aaron Durbinc625d092013-10-04 16:00:07 -050065}
66
67int get_recovery_mode_switch(void)
68{
Aaron Durbin063c8732013-10-28 11:24:53 -050069#if CONFIG_EC_GOOGLE_CHROMEEC
70 u8 ec_switches = inb(EC_LPC_ADDR_MEMMAP + EC_MEMMAP_SWITCHES);
71 u32 ec_events;
72
73 /* If a switch is set, we don't need to look at events. */
74 if (ec_switches & (EC_SWITCH_DEDICATED_RECOVERY))
75 return 1;
76
77 /* Else check if the EC has posted the keyboard recovery event. */
78 ec_events = google_chromeec_get_events_b();
79
80 return !!(ec_events &
81 EC_HOST_EVENT_MASK(EC_HOST_EVENT_KEYBOARD_RECOVERY));
82#else
83 return 0;
84#endif
Aaron Durbinc625d092013-10-04 16:00:07 -050085}
86
Sheng-Liang Song8c7e6222014-04-30 15:56:13 -070087int clear_recovery_mode_switch(void)
88{
89#if CONFIG_EC_GOOGLE_CHROMEEC
90 const uint32_t kb_rec_mask =
91 EC_HOST_EVENT_MASK(EC_HOST_EVENT_KEYBOARD_RECOVERY);
92 /* Unconditionally clear the EC recovery request. */
93 return google_chromeec_clear_events_b(kb_rec_mask);
94#else
95 return 0;
96#endif
97}
98
Aaron Durbinc625d092013-10-04 16:00:07 -050099int get_write_protect_state(void)
100{
Aaron Durbin4177db52014-02-05 14:55:26 -0600101 /*
102 * The vboot loader queries this function in romstage. The GPIOs have
103 * not been set up yet as that configuration is done in ramstage. The
104 * hardware defaults to an input but there is a 20K pulldown. Externally
105 * there is a 10K pullup. Disable the internal pull in romstage so that
106 * there isn't any ambiguity in the reading.
107 */
108#if defined(__PRE_RAM__)
109 ssus_disable_internal_pull(WP_STATUS_PAD);
110#endif
111
Aaron Durbin063c8732013-10-28 11:24:53 -0500112 /* WP is enabled when the pin is reading high. */
113 return ssus_get_gpio(WP_STATUS_PAD);
Aaron Durbinc625d092013-10-04 16:00:07 -0500114}
Aaron Durbinb0f81512016-07-25 21:31:41 -0500115
116static const struct cros_gpio cros_gpios[] = {
117 CROS_GPIO_REC_AL(CROS_GPIO_VIRTUAL, CROS_GPIO_DEVICE_NAME),
118 CROS_GPIO_WP_AH(0x2006, CROS_GPIO_DEVICE_NAME),
119};
120
121void mainboard_chromeos_acpi_generate(void)
122{
123 chromeos_acpi_gpio_generate(cros_gpios, ARRAY_SIZE(cros_gpios));
124}