blob: 356e97b7b5e4b0ff312470b73ef66c2e6f4f92e8 [file] [log] [blame]
Angel Pons54c54722020-04-05 13:20:54 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Stefan Reinauerd7bd4eb2013-02-11 11:11:36 -08002
3#include <console/console.h>
Kyösti Mälkkiab728092014-05-03 16:47:52 +03004#include <bootmode.h>
Kyösti Mälkki17887d02019-07-23 19:08:01 +03005#include <boot/coreboot_tables.h>
Stefan Reinauerd7bd4eb2013-02-11 11:11:36 -08006#include <device/device.h>
Stefan Reinauerd7bd4eb2013-02-11 11:11:36 -08007
8#include <southbridge/intel/bd82x6x/pch.h>
Patrick Rudolphe8e66f42016-02-06 17:42:42 +01009#include <southbridge/intel/common/gpio.h>
Stefan Reinauerd7bd4eb2013-02-11 11:11:36 -080010#include <ec/quanta/ene_kb3940q/ec.h>
Aaron Durbinb0f81512016-07-25 21:31:41 -050011#include <vendorcode/google/chromeos/chromeos.h>
Stefan Reinauerd7bd4eb2013-02-11 11:11:36 -080012#include "ec.h"
13
Stefan Reinauerd7bd4eb2013-02-11 11:11:36 -080014#define WP_GPIO 6
15#define DEVMODE_GPIO 54
16#define FORCE_RECOVERY_MODE 0
Stefan Reinauerd7bd4eb2013-02-11 11:11:36 -080017
Stefan Reinauerd7bd4eb2013-02-11 11:11:36 -080018void fill_lb_gpios(struct lb_gpios *gpios)
19{
Joel Kitching2e1f6552019-03-23 12:41:04 +080020 struct lb_gpio chromeos_gpios[] = {
Joel Kitching2e1f6552019-03-23 12:41:04 +080021 /* lid switch value from EC */
22 {-1, ACTIVE_HIGH, get_lid_switch(), "lid"},
Stefan Reinauerd7bd4eb2013-02-11 11:11:36 -080023
Joel Kitching2e1f6552019-03-23 12:41:04 +080024 /* Power Button - Hardcode Low as power button may still be
25 * pressed when read here.*/
26 {-1, ACTIVE_HIGH, 0, "power"},
Stefan Reinauerd7bd4eb2013-02-11 11:11:36 -080027
Joel Kitching2e1f6552019-03-23 12:41:04 +080028 /* Was VGA Option ROM loaded? */
29 /* -1 indicates that this is a pseudo GPIO */
30 {-1, ACTIVE_HIGH, gfx_get_init_done(), "oprom"},
31 };
32 lb_add_gpios(gpios, chromeos_gpios, ARRAY_SIZE(chromeos_gpios));
Stefan Reinauerd7bd4eb2013-02-11 11:11:36 -080033}
Stefan Reinauerd7bd4eb2013-02-11 11:11:36 -080034
Patrick Georgi5e0a2e22015-07-27 23:18:15 +020035int get_write_protect_state(void)
36{
Patrick Rudolphe8e66f42016-02-06 17:42:42 +010037 return !get_gpio(WP_GPIO);
Patrick Georgi5e0a2e22015-07-27 23:18:15 +020038}
39
40int get_lid_switch(void)
41{
42 return (ec_mem_read(EC_HW_GPI_STATUS) >> EC_GPI_LID_STAT_BIT) & 1;
43}
44
Stefan Reinauerd7bd4eb2013-02-11 11:11:36 -080045int get_recovery_mode_switch(void)
46{
47 int ec_rec_mode = 0;
48
Kyösti Mälkki8d75f6c2019-08-17 05:28:38 +030049 if (FORCE_RECOVERY_MODE) {
50 printk(BIOS_DEBUG, "FORCING RECOVERY MODE.\n");
51 return 1;
Stefan Reinauerd7bd4eb2013-02-11 11:11:36 -080052 }
Kyösti Mälkki8d75f6c2019-08-17 05:28:38 +030053
54 if (ENV_RAMSTAGE) {
55 if (ec_mem_read(EC_CODE_STATE) == EC_COS_EC_RO)
56 ec_rec_mode = 1;
57
58 printk(BIOS_DEBUG, "RECOVERY MODE FROM EC: %x\n", ec_rec_mode);
59 }
Stefan Reinauerd7bd4eb2013-02-11 11:11:36 -080060
61 return ec_rec_mode;
62}
Aaron Durbinb0f81512016-07-25 21:31:41 -050063
64static const struct cros_gpio cros_gpios[] = {
65 CROS_GPIO_REC_AH(CROS_GPIO_VIRTUAL, CROS_GPIO_DEVICE_NAME),
Aaron Durbinb0f81512016-07-25 21:31:41 -050066 CROS_GPIO_WP_AL(WP_GPIO, CROS_GPIO_DEVICE_NAME),
67};
68
69void mainboard_chromeos_acpi_generate(void)
70{
Kyösti Mälkkibc441c72021-02-18 06:26:52 +020071 // TODO: MLR
72 // The firmware read/write status is a "virtual" switch and
73 // will be handled elsewhere. Until then hard-code to
74 // read/write instead of read-only for developer mode.
75 if (CONFIG(CHROMEOS_NVS))
76 chromeos_set_ecfw_rw();
77
Aaron Durbinb0f81512016-07-25 21:31:41 -050078 chromeos_acpi_gpio_generate(cros_gpios, ARRAY_SIZE(cros_gpios));
79}