blob: a856e450897fd6083c9fabc774d50532817cfc67 [file] [log] [blame]
huang lina6dbfb52016-03-02 18:38:40 +08001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright 2016 Rockchip Inc.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 */
16
Furquan Shaikhcd2afc02016-11-15 20:33:29 -080017#include <bootmode.h>
huang lina6dbfb52016-03-02 18:38:40 +080018#include <boot/coreboot_tables.h>
Vadim Bendebury9ed93cb2016-05-22 16:09:54 -070019#include <gpio.h>
Philipp Deppenwiesed88fb362017-10-18 20:26:18 +020020#include <security/tpm/tis.h>
huang lina6dbfb52016-03-02 18:38:40 +080021
Vadim Bendebury9ed93cb2016-05-22 16:09:54 -070022#include "board.h"
23
Julius Wernercd49cce2019-03-05 16:53:33 -080024static const uint32_t wp_polarity = CONFIG(GRU_BASEBOARD_SCARLET) ?
Julius Werner9ec69282018-02-14 18:01:27 -080025 ACTIVE_LOW : ACTIVE_HIGH;
26
Douglas Anderson4884c5d2016-08-04 09:27:40 -070027int get_write_protect_state(void)
28{
Julius Werner9ec69282018-02-14 18:01:27 -080029 int raw = gpio_get(GPIO_WP);
30 return wp_polarity == ACTIVE_HIGH ? raw : !raw;
Douglas Anderson4884c5d2016-08-04 09:27:40 -070031}
32
huang lina6dbfb52016-03-02 18:38:40 +080033void fill_lb_gpios(struct lb_gpios *gpios)
34{
Vadim Bendebury9ed93cb2016-05-22 16:09:54 -070035 struct lb_gpio chromeos_gpios[] = {
Julius Werner9ec69282018-02-14 18:01:27 -080036 {GPIO_WP.raw, wp_polarity, gpio_get(GPIO_WP),
Douglas Anderson4884c5d2016-08-04 09:27:40 -070037 "write protect"},
Shelley Chen1592bfb2016-06-30 12:51:57 -070038 {-1, ACTIVE_HIGH, get_recovery_mode_switch(), "recovery"},
Julius Wernercd49cce2019-03-05 16:53:33 -080039#if CONFIG(GRU_BASEBOARD_SCARLET)
Vadim Bendebury9ed93cb2016-05-22 16:09:54 -070040 {GPIO_BACKLIGHT.raw, ACTIVE_HIGH, -1, "backlight"},
Lin Huang18617bf2017-11-20 14:57:22 +080041#endif
Vadim Bendebury9ed93cb2016-05-22 16:09:54 -070042 {GPIO_EC_IN_RW.raw, ACTIVE_HIGH, -1, "EC in RW"},
43 {GPIO_EC_IRQ.raw, ACTIVE_LOW, -1, "EC interrupt"},
44 {GPIO_RESET.raw, ACTIVE_HIGH, -1, "reset"},
Julius Werner1ab8c012017-11-03 15:23:09 -070045 {GPIO_SPK_PA_EN.raw, ACTIVE_HIGH, -1, "speaker enable"},
Julius Wernercd49cce2019-03-05 16:53:33 -080046#if CONFIG(GRU_HAS_TPM2)
Jeffy Chen3d966252017-03-03 18:24:02 +080047 {GPIO_TPM_IRQ.raw, ACTIVE_HIGH, -1, "TPM interrupt"},
48#endif
Vadim Bendebury9ed93cb2016-05-22 16:09:54 -070049 };
huang lina6dbfb52016-03-02 18:38:40 +080050
Vadim Bendebury9ed93cb2016-05-22 16:09:54 -070051 lb_add_gpios(gpios, chromeos_gpios, ARRAY_SIZE(chromeos_gpios));
huang lina6dbfb52016-03-02 18:38:40 +080052}
53
Vadim Bendebury9ed93cb2016-05-22 16:09:54 -070054void setup_chromeos_gpios(void)
55{
Julius Wernercd49cce2019-03-05 16:53:33 -080056 if (CONFIG(GRU_BASEBOARD_SCARLET))
Julius Werner9ec69282018-02-14 18:01:27 -080057 gpio_input(GPIO_WP);
58 else
59 gpio_input_pullup(GPIO_WP);
Vadim Bendebury9ed93cb2016-05-22 16:09:54 -070060 gpio_input_pullup(GPIO_EC_IN_RW);
61 gpio_input_pullup(GPIO_EC_IRQ);
huang lina6dbfb52016-03-02 18:38:40 +080062}
Jeffy Chen3d966252017-03-03 18:24:02 +080063
Julius Wernercd49cce2019-03-05 16:53:33 -080064#if CONFIG(GRU_HAS_TPM2)
Jeffy Chen3d966252017-03-03 18:24:02 +080065int tis_plat_irq_status(void)
66{
67 return gpio_irq_status(GPIO_TPM_IRQ);
68}
69#endif