Angel Pons | 54c5472 | 2020-04-05 13:20:54 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Stefan Reinauer | d7bd4eb | 2013-02-11 11:11:36 -0800 | [diff] [blame] | 2 | |
| 3 | #include <console/console.h> |
Kyösti Mälkki | ab72809 | 2014-05-03 16:47:52 +0300 | [diff] [blame] | 4 | #include <bootmode.h> |
Kyösti Mälkki | 17887d0 | 2019-07-23 19:08:01 +0300 | [diff] [blame] | 5 | #include <boot/coreboot_tables.h> |
Stefan Reinauer | d7bd4eb | 2013-02-11 11:11:36 -0800 | [diff] [blame] | 6 | #include <device/device.h> |
Stefan Reinauer | d7bd4eb | 2013-02-11 11:11:36 -0800 | [diff] [blame] | 7 | |
| 8 | #include <southbridge/intel/bd82x6x/pch.h> |
Patrick Rudolph | e8e66f4 | 2016-02-06 17:42:42 +0100 | [diff] [blame] | 9 | #include <southbridge/intel/common/gpio.h> |
Stefan Reinauer | d7bd4eb | 2013-02-11 11:11:36 -0800 | [diff] [blame] | 10 | #include <ec/quanta/ene_kb3940q/ec.h> |
Aaron Durbin | b0f8151 | 2016-07-25 21:31:41 -0500 | [diff] [blame] | 11 | #include <vendorcode/google/chromeos/chromeos.h> |
Stefan Reinauer | d7bd4eb | 2013-02-11 11:11:36 -0800 | [diff] [blame] | 12 | #include "ec.h" |
| 13 | |
Stefan Reinauer | d7bd4eb | 2013-02-11 11:11:36 -0800 | [diff] [blame] | 14 | #define WP_GPIO 6 |
| 15 | #define DEVMODE_GPIO 54 |
| 16 | #define FORCE_RECOVERY_MODE 0 |
Stefan Reinauer | d7bd4eb | 2013-02-11 11:11:36 -0800 | [diff] [blame] | 17 | |
Stefan Reinauer | d7bd4eb | 2013-02-11 11:11:36 -0800 | [diff] [blame] | 18 | void fill_lb_gpios(struct lb_gpios *gpios) |
| 19 | { |
Joel Kitching | 2e1f655 | 2019-03-23 12:41:04 +0800 | [diff] [blame] | 20 | struct lb_gpio chromeos_gpios[] = { |
Joel Kitching | 2e1f655 | 2019-03-23 12:41:04 +0800 | [diff] [blame] | 21 | /* lid switch value from EC */ |
| 22 | {-1, ACTIVE_HIGH, get_lid_switch(), "lid"}, |
Stefan Reinauer | d7bd4eb | 2013-02-11 11:11:36 -0800 | [diff] [blame] | 23 | |
Joel Kitching | 2e1f655 | 2019-03-23 12:41:04 +0800 | [diff] [blame] | 24 | /* Power Button - Hardcode Low as power button may still be |
| 25 | * pressed when read here.*/ |
| 26 | {-1, ACTIVE_HIGH, 0, "power"}, |
Stefan Reinauer | d7bd4eb | 2013-02-11 11:11:36 -0800 | [diff] [blame] | 27 | |
Joel Kitching | 2e1f655 | 2019-03-23 12:41:04 +0800 | [diff] [blame] | 28 | /* 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 Reinauer | d7bd4eb | 2013-02-11 11:11:36 -0800 | [diff] [blame] | 33 | } |
Stefan Reinauer | d7bd4eb | 2013-02-11 11:11:36 -0800 | [diff] [blame] | 34 | |
Patrick Georgi | 5e0a2e2 | 2015-07-27 23:18:15 +0200 | [diff] [blame] | 35 | int get_write_protect_state(void) |
| 36 | { |
Patrick Rudolph | e8e66f4 | 2016-02-06 17:42:42 +0100 | [diff] [blame] | 37 | return !get_gpio(WP_GPIO); |
Patrick Georgi | 5e0a2e2 | 2015-07-27 23:18:15 +0200 | [diff] [blame] | 38 | } |
| 39 | |
| 40 | int get_lid_switch(void) |
| 41 | { |
| 42 | return (ec_mem_read(EC_HW_GPI_STATUS) >> EC_GPI_LID_STAT_BIT) & 1; |
| 43 | } |
| 44 | |
Stefan Reinauer | d7bd4eb | 2013-02-11 11:11:36 -0800 | [diff] [blame] | 45 | int get_recovery_mode_switch(void) |
| 46 | { |
| 47 | int ec_rec_mode = 0; |
| 48 | |
Kyösti Mälkki | 8d75f6c | 2019-08-17 05:28:38 +0300 | [diff] [blame] | 49 | if (FORCE_RECOVERY_MODE) { |
| 50 | printk(BIOS_DEBUG, "FORCING RECOVERY MODE.\n"); |
| 51 | return 1; |
Stefan Reinauer | d7bd4eb | 2013-02-11 11:11:36 -0800 | [diff] [blame] | 52 | } |
Kyösti Mälkki | 8d75f6c | 2019-08-17 05:28:38 +0300 | [diff] [blame] | 53 | |
| 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 Reinauer | d7bd4eb | 2013-02-11 11:11:36 -0800 | [diff] [blame] | 60 | |
| 61 | return ec_rec_mode; |
| 62 | } |
Aaron Durbin | b0f8151 | 2016-07-25 21:31:41 -0500 | [diff] [blame] | 63 | |
| 64 | static const struct cros_gpio cros_gpios[] = { |
| 65 | CROS_GPIO_REC_AH(CROS_GPIO_VIRTUAL, CROS_GPIO_DEVICE_NAME), |
Aaron Durbin | b0f8151 | 2016-07-25 21:31:41 -0500 | [diff] [blame] | 66 | CROS_GPIO_WP_AL(WP_GPIO, CROS_GPIO_DEVICE_NAME), |
| 67 | }; |
| 68 | |
| 69 | void mainboard_chromeos_acpi_generate(void) |
| 70 | { |
Kyösti Mälkki | bc441c7 | 2021-02-18 06:26:52 +0200 | [diff] [blame] | 71 | // 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 Durbin | b0f8151 | 2016-07-25 21:31:41 -0500 | [diff] [blame] | 78 | chromeos_acpi_gpio_generate(cros_gpios, ARRAY_SIZE(cros_gpios)); |
| 79 | } |