blob: 4a93ae2c73d3bcb11d869f103bbb5f41cecb0865 [file] [log] [blame]
Yidi Lin97b9d9e2021-04-12 12:01:48 +08001/* SPDX-License-Identifier: GPL-2.0-only */
2
3#include <bootmode.h>
4#include <boot/coreboot_tables.h>
Grzegorz Bernacki7758b472023-06-14 12:01:32 +00005#include <drivers/tpm/cr50.h>
Yu-Ping Wua21797a2021-04-01 16:11:25 +08006#include <gpio.h>
7
8#include "gpio.h"
9
10void setup_chromeos_gpios(void)
11{
12 gpio_input(GPIO_WP);
13 gpio_input_pullup(GPIO_EC_AP_INT);
14 gpio_input_pullup(GPIO_SD_CD);
15 gpio_input_pullup(GPIO_EC_IN_RW);
16 gpio_input_pullup(GPIO_GSC_AP_INT);
17 gpio_output(GPIO_EN_SPK, 0);
18 gpio_output(GPIO_RESET, 0);
Yu-Ping Wu1ce64532021-07-15 11:34:43 +080019 gpio_output(GPIO_XHCI_DONE, 0);
Trevor Wu1d194322021-08-17 15:58:11 +080020 if (CONFIG(CHERRY_USE_RT1019))
21 gpio_output(GPIO_BEEP_ON, 0);
22 else if (CONFIG(CHERRY_USE_RT1011))
23 gpio_output(GPIO_RST_RT1011, 0);
24
Yu-Ping Wua21797a2021-04-01 16:11:25 +080025}
Yidi Lin97b9d9e2021-04-12 12:01:48 +080026
27void fill_lb_gpios(struct lb_gpios *gpios)
28{
Yu-Ping Wua21797a2021-04-01 16:11:25 +080029 struct lb_gpio chromeos_gpios[] = {
30 {GPIO_EC_AP_INT.id, ACTIVE_LOW, -1, "EC interrupt"},
31 {GPIO_SD_CD.id, ACTIVE_LOW, -1, "SD card detect"},
32 {GPIO_EC_IN_RW.id, ACTIVE_LOW, -1, "EC in RW"},
Rex-BC Chenbcf42fb2021-06-15 20:19:01 +080033 /*
34 * The GPIO_GSC_AP_INT itself is active low, but the payloads will
35 * create the IRQ using its eint driver, which is active high.
36 */
37 {GPIO_GSC_AP_INT.id, ACTIVE_HIGH, -1, "TPM interrupt"},
Trevor Wu1d194322021-08-17 15:58:11 +080038 };
39
40 struct lb_gpio rt1019_gpios[] = {
41 {GPIO_BEEP_ON.id, ACTIVE_HIGH, -1, "beep enable"},
Yu-Ping Wua21797a2021-04-01 16:11:25 +080042 {GPIO_EN_SPK.id, ACTIVE_HIGH, -1, "speaker enable"},
43 };
Trevor Wu1d194322021-08-17 15:58:11 +080044
45 struct lb_gpio rt1011_gpios[] = {
46 {GPIO_RST_RT1011.id, ACTIVE_HIGH, -1, "rt1011 reset"},
47 {GPIO_EN_SPK.id, ACTIVE_HIGH, -1, "speaker enable"},
48 };
49
Trevor Wu812df722022-03-22 13:09:13 +080050 struct lb_gpio spk_gpios[] = {
51 {GPIO_EN_SPK.id, ACTIVE_HIGH, -1, "speaker enable"},
52 };
53
Yu-Ping Wua21797a2021-04-01 16:11:25 +080054 lb_add_gpios(gpios, chromeos_gpios, ARRAY_SIZE(chromeos_gpios));
Trevor Wu1d194322021-08-17 15:58:11 +080055
56 if (CONFIG(CHERRY_USE_RT1019))
57 lb_add_gpios(gpios, rt1019_gpios, ARRAY_SIZE(rt1019_gpios));
58 else if (CONFIG(CHERRY_USE_RT1011))
59 lb_add_gpios(gpios, rt1011_gpios, ARRAY_SIZE(rt1011_gpios));
Trevor Wu812df722022-03-22 13:09:13 +080060 else if (CONFIG(CHERRY_USE_MAX98390))
61 lb_add_gpios(gpios, spk_gpios, ARRAY_SIZE(spk_gpios));
Yidi Lin97b9d9e2021-04-12 12:01:48 +080062}
Yidi Lin4b97a132021-04-06 14:10:53 +080063
Grzegorz Bernacki7758b472023-06-14 12:01:32 +000064int cr50_plat_irq_status(void)
Yidi Lin4b97a132021-04-06 14:10:53 +080065{
66 return gpio_eint_poll(GPIO_GSC_AP_INT);
67}
Hsuan-ting Chen642508a2021-10-27 10:59:41 +000068
69int get_ec_is_trusted(void)
70{
71 /* EC is trusted if not in RW. This is active low. */
72 return !!gpio_get(GPIO_EC_IN_RW);
73}