Rex-BC Chen | 74a0629 | 2021-09-09 18:43:22 +0800 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
| 2 | |
| 3 | #include <bootmode.h> |
| 4 | #include <boot/coreboot_tables.h> |
Grzegorz Bernacki | 7758b47 | 2023-06-14 12:01:32 +0000 | [diff] [blame] | 5 | #include <drivers/tpm/cr50.h> |
Yu-Ping Wu | c7730dd | 2022-06-28 17:29:20 +0800 | [diff] [blame] | 6 | #include <ec/google/chromeec/ec.h> |
Rex-BC Chen | 580150d | 2021-11-17 15:50:38 +0800 | [diff] [blame] | 7 | #include <gpio.h> |
Yu-Ping Wu | c7730dd | 2022-06-28 17:29:20 +0800 | [diff] [blame] | 8 | #include <stdbool.h> |
Rex-BC Chen | 580150d | 2021-11-17 15:50:38 +0800 | [diff] [blame] | 9 | |
| 10 | #include "gpio.h" |
| 11 | |
| 12 | void setup_chromeos_gpios(void) |
| 13 | { |
Rex-BC Chen | ee56998 | 2021-12-09 11:35:02 +0800 | [diff] [blame] | 14 | /* Set up open-drain pins */ |
| 15 | gpio_input(GPIO_SAR_INT_ODL); |
| 16 | gpio_input(GPIO_BT_WAKE_AP_ODL); |
| 17 | gpio_input(GPIO_WIFI_INT_ODL); |
| 18 | gpio_input(GPIO_DPBRDG_INT_ODL); |
| 19 | gpio_input(GPIO_EDPBRDG_INT_ODL); |
| 20 | gpio_input(GPIO_EC_AP_HPD_OD); |
| 21 | gpio_input(GPIO_TCHPAD_INT_ODL); |
| 22 | gpio_input(GPIO_TCHSCR_INT_1V8_ODL); |
| 23 | gpio_input(GPIO_EC_AP_INT_ODL); |
| 24 | gpio_input(GPIO_EC_IN_RW_ODL); |
| 25 | gpio_input(GPIO_GSC_AP_INT_ODL); |
| 26 | gpio_input(GPIO_AP_WP_ODL); |
| 27 | gpio_input(GPIO_HP_INT_ODL); |
| 28 | gpio_input(GPIO_PEN_EJECT_OD); |
| 29 | gpio_input(GPIO_UCAM_DET_ODL); |
| 30 | |
| 31 | /* Set up GPIOs */ |
Rex-BC Chen | 580150d | 2021-11-17 15:50:38 +0800 | [diff] [blame] | 32 | gpio_output(GPIO_RESET, 0); |
Rex-BC Chen | ee56998 | 2021-12-09 11:35:02 +0800 | [diff] [blame] | 33 | gpio_output(GPIO_XHCI_DONE, 0); |
| 34 | gpio_output(GPIO_EN_SPK, 0); |
Rex-BC Chen | 580150d | 2021-11-17 15:50:38 +0800 | [diff] [blame] | 35 | } |
Rex-BC Chen | 74a0629 | 2021-09-09 18:43:22 +0800 | [diff] [blame] | 36 | |
| 37 | void fill_lb_gpios(struct lb_gpios *gpios) |
| 38 | { |
Rex-BC Chen | 580150d | 2021-11-17 15:50:38 +0800 | [diff] [blame] | 39 | struct lb_gpio chromeos_gpios[] = { |
Rex-BC Chen | ee56998 | 2021-12-09 11:35:02 +0800 | [diff] [blame] | 40 | {GPIO_EC_AP_INT_ODL.id, ACTIVE_LOW, -1, "EC interrupt"}, |
| 41 | {GPIO_EC_IN_RW_ODL.id, ACTIVE_LOW, -1, "EC in RW"}, |
| 42 | {GPIO_GSC_AP_INT_ODL.id, ACTIVE_HIGH, -1, "TPM interrupt"}, |
Rex-BC Chen | 580150d | 2021-11-17 15:50:38 +0800 | [diff] [blame] | 43 | {GPIO_EN_SPK.id, ACTIVE_HIGH, -1, "speaker enable"}, |
| 44 | }; |
| 45 | lb_add_gpios(gpios, chromeos_gpios, ARRAY_SIZE(chromeos_gpios)); |
Rex-BC Chen | 74a0629 | 2021-09-09 18:43:22 +0800 | [diff] [blame] | 46 | } |
Rex-BC Chen | e96861f | 2021-11-18 15:02:35 +0800 | [diff] [blame] | 47 | |
| 48 | int get_ec_is_trusted(void) |
| 49 | { |
Yu-Ping Wu | c7730dd | 2022-06-28 17:29:20 +0800 | [diff] [blame] | 50 | uint32_t rev; |
| 51 | bool has_cr50 = false; |
| 52 | |
| 53 | /* |
| 54 | * Kingler and Krabby's rev 0 boards both use Cr50 instead of Ti50. In order to share |
| 55 | * the same firmware with newer rev, get the board rev from CBI, and ignore |
| 56 | * TPM_GOOGLE_TI50 when rev is 0. |
| 57 | */ |
| 58 | if (CONFIG(BOARD_GOOGLE_KINGLER) || CONFIG(BOARD_GOOGLE_KRABBY)) { |
| 59 | if (google_chromeec_cbi_get_board_version(&rev) == 0 && rev == 0) |
| 60 | has_cr50 = true; |
| 61 | } |
| 62 | |
Yu-Ping Wu | 7f339c6 | 2022-06-07 16:10:04 +0800 | [diff] [blame] | 63 | /* With Ti50, VB2_CONTEXT_EC_TRUSTED should be set according to the boot mode. */ |
Yu-Ping Wu | c7730dd | 2022-06-28 17:29:20 +0800 | [diff] [blame] | 64 | if (CONFIG(TPM_GOOGLE_TI50) && !has_cr50) |
Yu-Ping Wu | 7f339c6 | 2022-06-07 16:10:04 +0800 | [diff] [blame] | 65 | return 0; |
| 66 | |
Rex-BC Chen | e96861f | 2021-11-18 15:02:35 +0800 | [diff] [blame] | 67 | /* EC is trusted if not in RW. This is active low. */ |
Rex-BC Chen | ee56998 | 2021-12-09 11:35:02 +0800 | [diff] [blame] | 68 | return !!gpio_get(GPIO_EC_IN_RW_ODL); |
Rex-BC Chen | e96861f | 2021-11-18 15:02:35 +0800 | [diff] [blame] | 69 | } |
Rex-BC Chen | 858481e | 2021-11-18 15:43:40 +0800 | [diff] [blame] | 70 | |
Grzegorz Bernacki | 7758b47 | 2023-06-14 12:01:32 +0000 | [diff] [blame] | 71 | int cr50_plat_irq_status(void) |
Rex-BC Chen | 858481e | 2021-11-18 15:43:40 +0800 | [diff] [blame] | 72 | { |
Rex-BC Chen | ee56998 | 2021-12-09 11:35:02 +0800 | [diff] [blame] | 73 | return gpio_eint_poll(GPIO_GSC_AP_INT_ODL); |
Rex-BC Chen | 858481e | 2021-11-18 15:43:40 +0800 | [diff] [blame] | 74 | } |