Angel Pons | 2e8a4b0 | 2020-04-05 13:22:54 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Stefan Reinauer | b7ecf6d | 2013-03-13 17:13:32 -0700 | [diff] [blame] | 2 | |
Kyösti Mälkki | ab72809 | 2014-05-03 16:47:52 +0300 | [diff] [blame] | 3 | #include <bootmode.h> |
Kyösti Mälkki | 17887d0 | 2019-07-23 19:08:01 +0300 | [diff] [blame] | 4 | #include <boot/coreboot_tables.h> |
Kyösti Mälkki | f1b58b7 | 2019-03-01 13:43:02 +0200 | [diff] [blame] | 5 | #include <device/pci_ops.h> |
Stefan Reinauer | b7ecf6d | 2013-03-13 17:13:32 -0700 | [diff] [blame] | 6 | #include <console/console.h> |
Stefan Reinauer | b7ecf6d | 2013-03-13 17:13:32 -0700 | [diff] [blame] | 7 | #include <device/device.h> |
Stefan Reinauer | b7ecf6d | 2013-03-13 17:13:32 -0700 | [diff] [blame] | 8 | |
| 9 | #include <southbridge/intel/bd82x6x/pch.h> |
Patrick Rudolph | e8e66f4 | 2016-02-06 17:42:42 +0100 | [diff] [blame] | 10 | #include <southbridge/intel/common/gpio.h> |
Kyösti Mälkki | 9a3bde0 | 2021-11-06 16:13:15 +0200 | [diff] [blame] | 11 | #include <types.h> |
Aaron Durbin | b0f8151 | 2016-07-25 21:31:41 -0500 | [diff] [blame] | 12 | #include <vendorcode/google/chromeos/chromeos.h> |
Stefan Reinauer | b7ecf6d | 2013-03-13 17:13:32 -0700 | [diff] [blame] | 13 | #include "ec.h" |
| 14 | #include <ec/quanta/it8518/ec.h> |
Kyösti Mälkki | 4bcc275 | 2021-11-05 22:02:26 +0200 | [diff] [blame] | 15 | #include "onboard.h" |
Stefan Reinauer | b7ecf6d | 2013-03-13 17:13:32 -0700 | [diff] [blame] | 16 | |
Stefan Reinauer | b7ecf6d | 2013-03-13 17:13:32 -0700 | [diff] [blame] | 17 | void fill_lb_gpios(struct lb_gpios *gpios) |
| 18 | { |
Joel Kitching | 2e1f655 | 2019-03-23 12:41:04 +0800 | [diff] [blame] | 19 | struct lb_gpio chromeos_gpios[] = { |
Joel Kitching | 2e1f655 | 2019-03-23 12:41:04 +0800 | [diff] [blame] | 20 | /* Lid Switch: Virtual switch */ |
| 21 | {-1, ACTIVE_HIGH, get_lid_switch(), "lid"}, |
Stefan Reinauer | b7ecf6d | 2013-03-13 17:13:32 -0700 | [diff] [blame] | 22 | |
Joel Kitching | 2e1f655 | 2019-03-23 12:41:04 +0800 | [diff] [blame] | 23 | /* Power Button: Virtual switch */ |
| 24 | /* Hard-code value to de-asserted */ |
| 25 | {-1, ACTIVE_HIGH, 0, "power"}, |
Stefan Reinauer | b7ecf6d | 2013-03-13 17:13:32 -0700 | [diff] [blame] | 26 | |
Joel Kitching | 2e1f655 | 2019-03-23 12:41:04 +0800 | [diff] [blame] | 27 | /* Was VGA Option ROM loaded? */ |
| 28 | /* -1 indicates that this is a pseudo GPIO */ |
| 29 | {-1, ACTIVE_HIGH, gfx_get_init_done(), "oprom"}, |
Stefan Reinauer | b7ecf6d | 2013-03-13 17:13:32 -0700 | [diff] [blame] | 30 | |
Joel Kitching | 2e1f655 | 2019-03-23 12:41:04 +0800 | [diff] [blame] | 31 | /* 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 Reinauer | b7ecf6d | 2013-03-13 17:13:32 -0700 | [diff] [blame] | 35 | } |
Stefan Reinauer | b7ecf6d | 2013-03-13 17:13:32 -0700 | [diff] [blame] | 36 | |
Patrick Georgi | 556538a | 2015-07-27 23:18:15 +0200 | [diff] [blame] | 37 | int get_write_protect_state(void) |
| 38 | { |
Kyösti Mälkki | 4bcc275 | 2021-11-05 22:02:26 +0200 | [diff] [blame] | 39 | return !get_gpio(GPIO_SPI_WP); |
Patrick Georgi | 556538a | 2015-07-27 23:18:15 +0200 | [diff] [blame] | 40 | } |
| 41 | |
| 42 | int get_lid_switch(void) |
| 43 | { |
| 44 | /* hard-code to open */ |
| 45 | return 1; |
| 46 | } |
| 47 | |
Stefan Reinauer | b7ecf6d | 2013-03-13 17:13:32 -0700 | [diff] [blame] | 48 | /* |
| 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älkki | e50bb8f | 2021-11-02 18:16:32 +0200 | [diff] [blame] | 52 | * rec_mode to be used after RTC_POWER_STS has been cleared. |
Stefan Reinauer | b7ecf6d | 2013-03-13 17:13:32 -0700 | [diff] [blame] | 53 | * Note, rec_mode is the only time the EC is in RO mode, otherwise, RW. |
| 54 | */ |
| 55 | int get_recovery_mode_switch(void) |
| 56 | { |
Kyösti Mälkki | fcbbb91 | 2020-04-20 10:21:39 +0300 | [diff] [blame] | 57 | static int ec_in_rec_mode; |
| 58 | static int ec_rec_flag_good; |
Kyösti Mälkki | 216f717 | 2019-08-17 05:27:45 +0300 | [diff] [blame] | 59 | |
| 60 | if (ec_rec_flag_good) |
| 61 | return ec_in_rec_mode; |
| 62 | |
Elyes HAOUAS | a4faec3 | 2020-04-22 16:49:28 +0200 | [diff] [blame] | 63 | const pci_devfn_t dev = PCI_DEV(0, 0x1f, 0); |
Kyösti Mälkki | 17887d0 | 2019-07-23 19:08:01 +0300 | [diff] [blame] | 64 | u8 reg8 = pci_s_read_config8(dev, GEN_PMCON_3); |
Stefan Reinauer | b7ecf6d | 2013-03-13 17:13:32 -0700 | [diff] [blame] | 65 | |
| 66 | u8 ec_status = ec_read(EC_STATUS_REG); |
Stefan Reinauer | b7ecf6d | 2013-03-13 17:13:32 -0700 | [diff] [blame] | 67 | |
| 68 | printk(BIOS_SPEW,"%s: EC status:%#x RTC_BAT: %x\n", |
| 69 | __func__, ec_status, reg8 & RTC_BATTERY_DEAD); |
| 70 | |
Kyösti Mälkki | 216f717 | 2019-08-17 05:27:45 +0300 | [diff] [blame] | 71 | ec_in_rec_mode = (((reg8 & RTC_BATTERY_DEAD) != 0) && |
| 72 | ((ec_status & 0x3) == EC_IN_RECOVERY_MODE)); |
| 73 | ec_rec_flag_good = 1; |
Stefan Reinauer | b7ecf6d | 2013-03-13 17:13:32 -0700 | [diff] [blame] | 74 | return ec_in_rec_mode; |
Stefan Reinauer | b7ecf6d | 2013-03-13 17:13:32 -0700 | [diff] [blame] | 75 | } |
Aaron Durbin | b0f8151 | 2016-07-25 21:31:41 -0500 | [diff] [blame] | 76 | |
| 77 | static const struct cros_gpio cros_gpios[] = { |
| 78 | CROS_GPIO_REC_AH(CROS_GPIO_VIRTUAL, CROS_GPIO_DEVICE_NAME), |
Kyösti Mälkki | 4bcc275 | 2021-11-05 22:02:26 +0200 | [diff] [blame] | 79 | CROS_GPIO_WP_AL(GPIO_SPI_WP, CROS_GPIO_DEVICE_NAME), |
Aaron Durbin | b0f8151 | 2016-07-25 21:31:41 -0500 | [diff] [blame] | 80 | }; |
| 81 | |
Kyösti Mälkki | 4ff218a | 2021-11-02 13:03:06 +0200 | [diff] [blame] | 82 | DECLARE_CROS_GPIOS(cros_gpios); |