blob: 8abdb67cbffe407387fa185df5149878c9ee0e31 [file] [log] [blame]
Angel Pons2e8a4b02020-04-05 13:22:54 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Stefan Reinauerb7ecf6d2013-03-13 17:13:32 -07002
Kyösti Mälkkiab728092014-05-03 16:47:52 +03003#include <bootmode.h>
Kyösti Mälkki17887d02019-07-23 19:08:01 +03004#include <boot/coreboot_tables.h>
Kyösti Mälkkif1b58b72019-03-01 13:43:02 +02005#include <device/pci_ops.h>
Stefan Reinauerb7ecf6d2013-03-13 17:13:32 -07006#include <console/console.h>
Stefan Reinauerb7ecf6d2013-03-13 17:13:32 -07007#include <device/device.h>
Stefan Reinauerb7ecf6d2013-03-13 17:13:32 -07008
9#include <southbridge/intel/bd82x6x/pch.h>
Patrick Rudolphe8e66f42016-02-06 17:42:42 +010010#include <southbridge/intel/common/gpio.h>
Kyösti Mälkki9a3bde02021-11-06 16:13:15 +020011#include <types.h>
Aaron Durbinb0f81512016-07-25 21:31:41 -050012#include <vendorcode/google/chromeos/chromeos.h>
Stefan Reinauerb7ecf6d2013-03-13 17:13:32 -070013#include "ec.h"
14#include <ec/quanta/it8518/ec.h>
Kyösti Mälkki4bcc2752021-11-05 22:02:26 +020015#include "onboard.h"
Stefan Reinauerb7ecf6d2013-03-13 17:13:32 -070016
Stefan Reinauerb7ecf6d2013-03-13 17:13:32 -070017void fill_lb_gpios(struct lb_gpios *gpios)
18{
Joel Kitching2e1f6552019-03-23 12:41:04 +080019 struct lb_gpio chromeos_gpios[] = {
Joel Kitching2e1f6552019-03-23 12:41:04 +080020 /* Lid Switch: Virtual switch */
21 {-1, ACTIVE_HIGH, get_lid_switch(), "lid"},
Stefan Reinauerb7ecf6d2013-03-13 17:13:32 -070022
Joel Kitching2e1f6552019-03-23 12:41:04 +080023 /* Power Button: Virtual switch */
24 /* Hard-code value to de-asserted */
25 {-1, ACTIVE_HIGH, 0, "power"},
Stefan Reinauerb7ecf6d2013-03-13 17:13:32 -070026
Joel Kitching2e1f6552019-03-23 12:41:04 +080027 /* Was VGA Option ROM loaded? */
28 /* -1 indicates that this is a pseudo GPIO */
29 {-1, ACTIVE_HIGH, gfx_get_init_done(), "oprom"},
Stefan Reinauerb7ecf6d2013-03-13 17:13:32 -070030
Joel Kitching2e1f6552019-03-23 12:41:04 +080031 /* EC is in RW mode when it isn't in recovery mode. */
32 {-1, ACTIVE_HIGH, !get_recovery_mode_switch(), "ec_in_rw"}
33 };
34 lb_add_gpios(gpios, chromeos_gpios, ARRAY_SIZE(chromeos_gpios));
Stefan Reinauerb7ecf6d2013-03-13 17:13:32 -070035}
Stefan Reinauerb7ecf6d2013-03-13 17:13:32 -070036
Patrick Georgi556538a2015-07-27 23:18:15 +020037int get_write_protect_state(void)
38{
Kyösti Mälkki4bcc2752021-11-05 22:02:26 +020039 return !get_gpio(GPIO_SPI_WP);
Patrick Georgi556538a2015-07-27 23:18:15 +020040}
41
42int get_lid_switch(void)
43{
44 /* hard-code to open */
45 return 1;
46}
47
Stefan Reinauerb7ecf6d2013-03-13 17:13:32 -070048/*
49 * The recovery-switch is virtual on Stout and is handled via the EC.
50 * Stout recovery mode is only valid if RTC_PWR_STS is set and the EC
51 * indicated the recovery keys were pressed. We use a global flag for
Kyösti Mälkkie50bb8f2021-11-02 18:16:32 +020052 * rec_mode to be used after RTC_POWER_STS has been cleared.
Stefan Reinauerb7ecf6d2013-03-13 17:13:32 -070053 * Note, rec_mode is the only time the EC is in RO mode, otherwise, RW.
54 */
55int get_recovery_mode_switch(void)
56{
Kyösti Mälkkifcbbb912020-04-20 10:21:39 +030057 static int ec_in_rec_mode;
58 static int ec_rec_flag_good;
Kyösti Mälkki216f7172019-08-17 05:27:45 +030059
60 if (ec_rec_flag_good)
61 return ec_in_rec_mode;
62
Elyes HAOUASa4faec32020-04-22 16:49:28 +020063 const pci_devfn_t dev = PCI_DEV(0, 0x1f, 0);
Kyösti Mälkki17887d02019-07-23 19:08:01 +030064 u8 reg8 = pci_s_read_config8(dev, GEN_PMCON_3);
Stefan Reinauerb7ecf6d2013-03-13 17:13:32 -070065
66 u8 ec_status = ec_read(EC_STATUS_REG);
Stefan Reinauerb7ecf6d2013-03-13 17:13:32 -070067
68 printk(BIOS_SPEW,"%s: EC status:%#x RTC_BAT: %x\n",
69 __func__, ec_status, reg8 & RTC_BATTERY_DEAD);
70
Kyösti Mälkki216f7172019-08-17 05:27:45 +030071 ec_in_rec_mode = (((reg8 & RTC_BATTERY_DEAD) != 0) &&
72 ((ec_status & 0x3) == EC_IN_RECOVERY_MODE));
73 ec_rec_flag_good = 1;
Stefan Reinauerb7ecf6d2013-03-13 17:13:32 -070074 return ec_in_rec_mode;
Stefan Reinauerb7ecf6d2013-03-13 17:13:32 -070075}
Aaron Durbinb0f81512016-07-25 21:31:41 -050076
77static const struct cros_gpio cros_gpios[] = {
78 CROS_GPIO_REC_AH(CROS_GPIO_VIRTUAL, CROS_GPIO_DEVICE_NAME),
Kyösti Mälkki4bcc2752021-11-05 22:02:26 +020079 CROS_GPIO_WP_AL(GPIO_SPI_WP, CROS_GPIO_DEVICE_NAME),
Aaron Durbinb0f81512016-07-25 21:31:41 -050080};
81
Kyösti Mälkki4ff218a2021-11-02 13:03:06 +020082DECLARE_CROS_GPIOS(cros_gpios);