blob: aa96153c29b64e4edef56f184cbafec7f2fa22e5 [file] [log] [blame]
Angel Ponsd32b6de2020-04-03 01:23:13 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Stefan Reinauer155e9b52012-04-27 23:19:58 +02002
Kyösti Mälkkie3ddee02014-05-03 10:45:28 +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 Reinauer155e9b52012-04-27 23:19:58 +02006#include <device/device.h>
Stefan Reinauer155e9b52012-04-27 23:19:58 +02007#include <northbridge/intel/sandybridge/sandybridge.h>
8#include <southbridge/intel/bd82x6x/pch.h>
Patrick Rudolphe8e66f42016-02-06 17:42:42 +01009#include <southbridge/intel/common/gpio.h>
Aaron Durbinb0f81512016-07-25 21:31:41 -050010#include <vendorcode/google/chromeos/chromeos.h>
Stefan Reinauer155e9b52012-04-27 23:19:58 +020011
12#define GPIO_SPI_WP 24
13#define GPIO_REC_MODE 42
Stefan Reinauer155e9b52012-04-27 23:19:58 +020014
15#define FLAG_SPI_WP 0
16#define FLAG_REC_MODE 1
Stefan Reinauer155e9b52012-04-27 23:19:58 +020017
Stefan Reinauer155e9b52012-04-27 23:19:58 +020018#include "ec.h"
19#include <ec/smsc/mec1308/ec.h>
20
Stefan Reinauer155e9b52012-04-27 23:19:58 +020021void fill_lb_gpios(struct lb_gpios *gpios)
22{
Elyes HAOUASa4faec32020-04-22 16:49:28 +020023 const pci_devfn_t dev = PCI_DEV(0, 0x1f, 0);
Kyösti Mälkki17887d02019-07-23 19:08:01 +030024 u16 gen_pmcon_1 = pci_s_read_config32(dev, GEN_PMCON_1);
Joel Kitching2e1f6552019-03-23 12:41:04 +080025 u8 lid = ec_read(0x83);
Stefan Reinauer155e9b52012-04-27 23:19:58 +020026
Joel Kitching2e1f6552019-03-23 12:41:04 +080027 struct lb_gpio chromeos_gpios[] = {
Joel Kitching2e1f6552019-03-23 12:41:04 +080028 /* Recovery: GPIO42 = CHP3_REC_MODE# */
29 {GPIO_REC_MODE, ACTIVE_LOW, !get_recovery_mode_switch(),
Matt Delco2cb39962019-04-30 14:59:43 -070030 "presence"},
Stefan Reinauer155e9b52012-04-27 23:19:58 +020031
Joel Kitching2e1f6552019-03-23 12:41:04 +080032 {100, ACTIVE_HIGH, lid & 1, "lid"},
Stefan Reinauer155e9b52012-04-27 23:19:58 +020033
Joel Kitching2e1f6552019-03-23 12:41:04 +080034 /* Power Button */
35 {101, ACTIVE_LOW, (gen_pmcon_1 >> 9) & 1, "power"},
Stefan Reinauer155e9b52012-04-27 23:19:58 +020036
Joel Kitching2e1f6552019-03-23 12:41:04 +080037 /* Did we load the VGA Option ROM? */
38 /* -1 indicates that this is a pseudo GPIO */
39 {-1, ACTIVE_HIGH, gfx_get_init_done(), "oprom"},
40 };
41 lb_add_gpios(gpios, chromeos_gpios, ARRAY_SIZE(chromeos_gpios));
Stefan Reinauer155e9b52012-04-27 23:19:58 +020042}
Stefan Reinauer155e9b52012-04-27 23:19:58 +020043
Patrick Georgi961e8a42015-06-30 12:49:50 +020044int get_write_protect_state(void)
45{
Elyes HAOUASa4faec32020-04-22 16:49:28 +020046 const pci_devfn_t dev = PCI_DEV(0, 0x1f, 2);
Kyösti Mälkki17887d02019-07-23 19:08:01 +030047 return (pci_s_read_config32(dev, SATA_SP) >> FLAG_SPI_WP) & 1;
Patrick Georgi961e8a42015-06-30 12:49:50 +020048}
49
Stefan Reinauer155e9b52012-04-27 23:19:58 +020050int get_recovery_mode_switch(void)
51{
Elyes HAOUASa4faec32020-04-22 16:49:28 +020052 const pci_devfn_t dev = PCI_DEV(0, 0x1f, 2);
Kyösti Mälkki17887d02019-07-23 19:08:01 +030053 return (pci_s_read_config32(dev, SATA_SP) >> FLAG_REC_MODE) & 1;
Stefan Reinauer155e9b52012-04-27 23:19:58 +020054}
55
Kyösti Mälkkie3ddee02014-05-03 10:45:28 +030056void init_bootmode_straps(void)
Stefan Reinauer155e9b52012-04-27 23:19:58 +020057{
Stefan Reinauer155e9b52012-04-27 23:19:58 +020058 u32 flags = 0;
Elyes HAOUASa4faec32020-04-22 16:49:28 +020059 const pci_devfn_t dev = PCI_DEV(0, 0x1f, 2);
Stefan Reinauer155e9b52012-04-27 23:19:58 +020060
61 /* Write Protect: GPIO24 = KBC3_SPI_WP#, active high */
Patrick Rudolphe8e66f42016-02-06 17:42:42 +010062 if (get_gpio(GPIO_SPI_WP))
Stefan Reinauer155e9b52012-04-27 23:19:58 +020063 flags |= (1 << FLAG_SPI_WP);
64 /* Recovery: GPIO42 = CHP3_REC_MODE#, active low */
Patrick Rudolphe8e66f42016-02-06 17:42:42 +010065 if (!get_gpio(GPIO_REC_MODE))
Stefan Reinauer155e9b52012-04-27 23:19:58 +020066 flags |= (1 << FLAG_REC_MODE);
Stefan Reinauer155e9b52012-04-27 23:19:58 +020067
Kyösti Mälkki17887d02019-07-23 19:08:01 +030068 pci_s_write_config32(dev, SATA_SP, flags);
Kyösti Mälkkie3ddee02014-05-03 10:45:28 +030069}
Aaron Durbinb0f81512016-07-25 21:31:41 -050070
71static const struct cros_gpio cros_gpios[] = {
72 CROS_GPIO_REC_AL(GPIO_REC_MODE, CROS_GPIO_DEVICE_NAME),
Aaron Durbinb0f81512016-07-25 21:31:41 -050073 CROS_GPIO_WP_AH(GPIO_SPI_WP, CROS_GPIO_DEVICE_NAME),
74};
75
76void mainboard_chromeos_acpi_generate(void)
77{
Kyösti Mälkkibc441c72021-02-18 06:26:52 +020078 if (CONFIG(CHROMEOS_NVS) && ec_read(0xcb))
79 chromeos_set_ecfw_rw();
80
Aaron Durbinb0f81512016-07-25 21:31:41 -050081 chromeos_acpi_gpio_generate(cros_gpios, ARRAY_SIZE(cros_gpios));
82}