blob: 14efdc3e4fb2427dfdefce615621f8e78bb8c00c [file] [log] [blame]
Angel Pons2de6bdf2020-04-05 13:21:00 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Lee Leahy89b5fbd2015-05-11 17:24:31 -07002
Kyösti Mälkkibe7692a2021-11-03 17:54:14 +02003#include <bootmode.h>
Kyösti Mälkki17887d02019-07-23 19:08:01 +03004#include <boot/coreboot_tables.h>
Kyösti Mälkki13f66502019-03-03 08:01:05 +02005#include <device/mmio.h>
Matt DeVillier4f20a4a2017-08-20 17:56:48 -05006#include <gpio.h>
Lee Leahy89b5fbd2015-05-11 17:24:31 -07007#include <soc/gpio.h>
Lee Leahy89b5fbd2015-05-11 17:24:31 -07008#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 DeVillier4f20a4a2017-08-20 17:56:48 -050014#define WP_GPIO GP_E_22
15
Lee Leahy89b5fbd2015-05-11 17:24:31 -070016#define ACTIVE_LOW 0
17#define ACTIVE_HIGH 1
18
19void fill_lb_gpios(struct lb_gpios *gpios)
20{
Julius Wernerc445b4f2016-03-31 17:27:05 -070021 struct lb_gpio chromeos_gpios[] = {
Julius Wernerc445b4f2016-03-31 17:27:05 -070022 {-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 Leahy89b5fbd2015-05-11 17:24:31 -070027}
Lee Leahy89b5fbd2015-05-11 17:24:31 -070028
Lee Leahy89b5fbd2015-05-11 17:24:31 -070029int 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 Wernercd49cce2019-03-05 16:53:33 -080038 if (CONFIG(BOARD_GOOGLE_CYAN)) {
Matt DeVillier4f20a4a2017-08-20 17:56:48 -050039 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 Leahy89b5fbd2015-05-11 17:24:31 -070046#endif
47
48 /* WP is enabled when the pin is reading high. */
Julius Wernercd49cce2019-03-05 16:53:33 -080049 if (CONFIG(BOARD_GOOGLE_CYAN)) {
Matt DeVillier4f20a4a2017-08-20 17:56:48 -050050 return (read32((void *)(COMMUNITY_GPEAST_BASE + WP_STATUS_PAD_CFG0))
51 & PAD_VAL_HIGH);
52 } else {
53 return !!gpio_get(WP_GPIO);
54 }
Lee Leahy89b5fbd2015-05-11 17:24:31 -070055}
Aaron Durbinb0f81512016-07-25 21:31:41 -050056
57static 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
62void mainboard_chromeos_acpi_generate(void)
63{
64 chromeos_acpi_gpio_generate(cros_gpios, ARRAY_SIZE(cros_gpios));
65}