blob: 739b5775df2a1aef0e23142a329d4da90b8c4fc1 [file] [log] [blame]
Angel Ponsd32b6de2020-04-03 01:23:13 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Stefan Reinauere1ae4b22012-04-27 23:20: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 Reinauere1ae4b22012-04-27 23:20:58 +02006#include <device/device.h>
Stefan Reinauere1ae4b22012-04-27 23:20:58 +02007#include <southbridge/intel/bd82x6x/pch.h>
Patrick Rudolphe8e66f42016-02-06 17:42:42 +01008#include <southbridge/intel/common/gpio.h>
Kyösti Mälkki9a3bde02021-11-06 16:13:15 +02009#include <types.h>
Aaron Durbinb0f81512016-07-25 21:31:41 -050010#include <vendorcode/google/chromeos/chromeos.h>
Kyösti Mälkki0cb11662021-11-06 20:51:58 +020011#include "onboard.h"
Stefan Reinauere1ae4b22012-04-27 23:20:58 +020012
Stefan Reinauere1ae4b22012-04-27 23:20:58 +020013void fill_lb_gpios(struct lb_gpios *gpios)
14{
Joel Kitching2e1f6552019-03-23 12:41:04 +080015 struct lb_gpio chromeos_gpios[] = {
Joel Kitching2e1f6552019-03-23 12:41:04 +080016 /* Recovery: GPIO42 = CHP3_REC_MODE# */
17 {GPIO_REC_MODE, ACTIVE_LOW, !get_recovery_mode_switch(),
Matt Delco2cb39962019-04-30 14:59:43 -070018 "presence"},
Stefan Reinauere1ae4b22012-04-27 23:20:58 +020019
Joel Kitching2e1f6552019-03-23 12:41:04 +080020 /* Hard code the lid switch GPIO to open. */
21 {100, ACTIVE_HIGH, 1, "lid"},
Stefan Reinauere1ae4b22012-04-27 23:20:58 +020022
Joel Kitching2e1f6552019-03-23 12:41:04 +080023 /* Power Button */
Kyösti Mälkki4b6ad4e2021-11-07 00:12:25 +020024 {101, ACTIVE_LOW, get_power_switch(), "power"},
Stefan Reinauere1ae4b22012-04-27 23:20:58 +020025
Joel Kitching2e1f6552019-03-23 12:41:04 +080026 /* Did we load the VGA Option ROM? */
27 /* -1 indicates that this is a pseudo GPIO */
28 {-1, ACTIVE_HIGH, gfx_get_init_done(), "oprom"},
29 };
30 lb_add_gpios(gpios, chromeos_gpios, ARRAY_SIZE(chromeos_gpios));
Stefan Reinauere1ae4b22012-04-27 23:20:58 +020031}
Stefan Reinauere1ae4b22012-04-27 23:20:58 +020032
Kyösti Mälkki7a874332021-11-07 10:23:36 +020033int get_write_protect_state(void)
Kyösti Mälkki0cb11662021-11-06 20:51:58 +020034{
35 return get_gpio(GPIO_SPI_WP);
36}
37
Kyösti Mälkki7a874332021-11-07 10:23:36 +020038int get_recovery_mode_switch(void)
Kyösti Mälkki0cb11662021-11-06 20:51:58 +020039{
40 return !get_gpio(GPIO_REC_MODE);
41}
42
Kyösti Mälkki4b6ad4e2021-11-07 00:12:25 +020043int get_power_switch(void)
44{
45 const pci_devfn_t dev = PCI_DEV(0, 0x1f, 0);
46 u16 gen_pmcon_1 = pci_s_read_config32(dev, GEN_PMCON_1);
47 return (gen_pmcon_1 >> 9) & 1;
48}
49
Aaron Durbinb0f81512016-07-25 21:31:41 -050050static const struct cros_gpio cros_gpios[] = {
51 CROS_GPIO_REC_AL(GPIO_REC_MODE, CROS_GPIO_DEVICE_NAME),
Aaron Durbinb0f81512016-07-25 21:31:41 -050052 CROS_GPIO_WP_AH(GPIO_SPI_WP, CROS_GPIO_DEVICE_NAME),
53};
54
Kyösti Mälkki4ff218a2021-11-02 13:03:06 +020055DECLARE_CROS_GPIOS(cros_gpios);