Angel Pons | 2de6bdf | 2020-04-05 13:21:00 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Lee Leahy | 89b5fbd | 2015-05-11 17:24:31 -0700 | [diff] [blame] | 2 | |
Kyösti Mälkki | be7692a | 2021-11-03 17:54:14 +0200 | [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 | 13f6650 | 2019-03-03 08:01:05 +0200 | [diff] [blame] | 5 | #include <device/mmio.h> |
Matt DeVillier | 4f20a4a | 2017-08-20 17:56:48 -0500 | [diff] [blame] | 6 | #include <gpio.h> |
Lee Leahy | 89b5fbd | 2015-05-11 17:24:31 -0700 | [diff] [blame] | 7 | #include <soc/gpio.h> |
Lee Leahy | 89b5fbd | 2015-05-11 17:24:31 -0700 | [diff] [blame] | 8 | #include <vendorcode/google/chromeos/chromeos.h> |
| 9 | |
| 10 | /* The WP status pin lives on MF_ISH_GPIO_4 */ |
| 11 | #define WP_STATUS_PAD_CFG0 0x4838 |
| 12 | #define WP_STATUS_PAD_CFG1 0x483C |
| 13 | |
Matt DeVillier | 4f20a4a | 2017-08-20 17:56:48 -0500 | [diff] [blame] | 14 | #define WP_GPIO GP_E_22 |
| 15 | |
Lee Leahy | 89b5fbd | 2015-05-11 17:24:31 -0700 | [diff] [blame] | 16 | #define ACTIVE_LOW 0 |
| 17 | #define ACTIVE_HIGH 1 |
| 18 | |
| 19 | void fill_lb_gpios(struct lb_gpios *gpios) |
| 20 | { |
Julius Werner | c445b4f | 2016-03-31 17:27:05 -0700 | [diff] [blame] | 21 | struct lb_gpio chromeos_gpios[] = { |
Julius Werner | c445b4f | 2016-03-31 17:27:05 -0700 | [diff] [blame] | 22 | {-1, ACTIVE_HIGH, get_lid_switch(), "lid"}, |
| 23 | {-1, ACTIVE_HIGH, 0, "power"}, |
| 24 | {-1, ACTIVE_HIGH, gfx_get_init_done(), "oprom"}, |
| 25 | }; |
| 26 | lb_add_gpios(gpios, chromeos_gpios, ARRAY_SIZE(chromeos_gpios)); |
Lee Leahy | 89b5fbd | 2015-05-11 17:24:31 -0700 | [diff] [blame] | 27 | } |
Lee Leahy | 89b5fbd | 2015-05-11 17:24:31 -0700 | [diff] [blame] | 28 | |
Lee Leahy | 89b5fbd | 2015-05-11 17:24:31 -0700 | [diff] [blame] | 29 | int get_write_protect_state(void) |
| 30 | { |
| 31 | /* |
| 32 | * The vboot loader queries this function in romstage. The GPIOs have |
| 33 | * not been set up yet as that configuration is done in ramstage. |
| 34 | * Configuring this GPIO as input so that there isn't any ambiguity |
| 35 | * in the reading. |
| 36 | */ |
| 37 | #if ENV_ROMSTAGE |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 38 | if (CONFIG(BOARD_GOOGLE_CYAN)) { |
Matt DeVillier | 4f20a4a | 2017-08-20 17:56:48 -0500 | [diff] [blame] | 39 | write32((void *)(COMMUNITY_GPEAST_BASE + WP_STATUS_PAD_CFG0), |
| 40 | (PAD_PULL_UP_20K | PAD_GPIO_ENABLE | PAD_CONFIG0_GPI_DEFAULT)); |
| 41 | write32((void *)(COMMUNITY_GPEAST_BASE + WP_STATUS_PAD_CFG1), |
| 42 | PAD_CONFIG1_DEFAULT0); |
| 43 | } else { |
| 44 | gpio_input_pullup(WP_GPIO); |
| 45 | } |
Lee Leahy | 89b5fbd | 2015-05-11 17:24:31 -0700 | [diff] [blame] | 46 | #endif |
| 47 | |
| 48 | /* WP is enabled when the pin is reading high. */ |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 49 | if (CONFIG(BOARD_GOOGLE_CYAN)) { |
Matt DeVillier | 4f20a4a | 2017-08-20 17:56:48 -0500 | [diff] [blame] | 50 | return (read32((void *)(COMMUNITY_GPEAST_BASE + WP_STATUS_PAD_CFG0)) |
| 51 | & PAD_VAL_HIGH); |
| 52 | } else { |
| 53 | return !!gpio_get(WP_GPIO); |
| 54 | } |
Lee Leahy | 89b5fbd | 2015-05-11 17:24:31 -0700 | [diff] [blame] | 55 | } |
Aaron Durbin | b0f8151 | 2016-07-25 21:31:41 -0500 | [diff] [blame] | 56 | |
| 57 | static const struct cros_gpio cros_gpios[] = { |
| 58 | CROS_GPIO_REC_AL(CROS_GPIO_VIRTUAL, CROS_GPIO_DEVICE_NAME), |
| 59 | CROS_GPIO_WP_AH(0x10013, CROS_GPIO_DEVICE_NAME), |
| 60 | }; |
| 61 | |
| 62 | void mainboard_chromeos_acpi_generate(void) |
| 63 | { |
| 64 | chromeos_acpi_gpio_generate(cros_gpios, ARRAY_SIZE(cros_gpios)); |
| 65 | } |