huang lin | a6dbfb5 | 2016-03-02 18:38:40 +0800 | [diff] [blame] | 1 | /* |
| 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 Shaikh | cd2afc0 | 2016-11-15 20:33:29 -0800 | [diff] [blame] | 17 | #include <bootmode.h> |
huang lin | a6dbfb5 | 2016-03-02 18:38:40 +0800 | [diff] [blame] | 18 | #include <boot/coreboot_tables.h> |
Vadim Bendebury | 9ed93cb | 2016-05-22 16:09:54 -0700 | [diff] [blame] | 19 | #include <gpio.h> |
Philipp Deppenwiese | d88fb36 | 2017-10-18 20:26:18 +0200 | [diff] [blame] | 20 | #include <security/tpm/tis.h> |
huang lin | a6dbfb5 | 2016-03-02 18:38:40 +0800 | [diff] [blame] | 21 | |
Vadim Bendebury | 9ed93cb | 2016-05-22 16:09:54 -0700 | [diff] [blame] | 22 | #include "board.h" |
| 23 | |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame^] | 24 | static const uint32_t wp_polarity = CONFIG(GRU_BASEBOARD_SCARLET) ? |
Julius Werner | 9ec6928 | 2018-02-14 18:01:27 -0800 | [diff] [blame] | 25 | ACTIVE_LOW : ACTIVE_HIGH; |
| 26 | |
Douglas Anderson | 4884c5d | 2016-08-04 09:27:40 -0700 | [diff] [blame] | 27 | int get_write_protect_state(void) |
| 28 | { |
Julius Werner | 9ec6928 | 2018-02-14 18:01:27 -0800 | [diff] [blame] | 29 | int raw = gpio_get(GPIO_WP); |
| 30 | return wp_polarity == ACTIVE_HIGH ? raw : !raw; |
Douglas Anderson | 4884c5d | 2016-08-04 09:27:40 -0700 | [diff] [blame] | 31 | } |
| 32 | |
huang lin | a6dbfb5 | 2016-03-02 18:38:40 +0800 | [diff] [blame] | 33 | void fill_lb_gpios(struct lb_gpios *gpios) |
| 34 | { |
Vadim Bendebury | 9ed93cb | 2016-05-22 16:09:54 -0700 | [diff] [blame] | 35 | struct lb_gpio chromeos_gpios[] = { |
Julius Werner | 9ec6928 | 2018-02-14 18:01:27 -0800 | [diff] [blame] | 36 | {GPIO_WP.raw, wp_polarity, gpio_get(GPIO_WP), |
Douglas Anderson | 4884c5d | 2016-08-04 09:27:40 -0700 | [diff] [blame] | 37 | "write protect"}, |
Shelley Chen | 1592bfb | 2016-06-30 12:51:57 -0700 | [diff] [blame] | 38 | {-1, ACTIVE_HIGH, get_recovery_mode_switch(), "recovery"}, |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame^] | 39 | #if CONFIG(GRU_BASEBOARD_SCARLET) |
Vadim Bendebury | 9ed93cb | 2016-05-22 16:09:54 -0700 | [diff] [blame] | 40 | {GPIO_BACKLIGHT.raw, ACTIVE_HIGH, -1, "backlight"}, |
Lin Huang | 18617bf | 2017-11-20 14:57:22 +0800 | [diff] [blame] | 41 | #endif |
Vadim Bendebury | 9ed93cb | 2016-05-22 16:09:54 -0700 | [diff] [blame] | 42 | {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 Werner | 1ab8c01 | 2017-11-03 15:23:09 -0700 | [diff] [blame] | 45 | {GPIO_SPK_PA_EN.raw, ACTIVE_HIGH, -1, "speaker enable"}, |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame^] | 46 | #if CONFIG(GRU_HAS_TPM2) |
Jeffy Chen | 3d96625 | 2017-03-03 18:24:02 +0800 | [diff] [blame] | 47 | {GPIO_TPM_IRQ.raw, ACTIVE_HIGH, -1, "TPM interrupt"}, |
| 48 | #endif |
Vadim Bendebury | 9ed93cb | 2016-05-22 16:09:54 -0700 | [diff] [blame] | 49 | }; |
huang lin | a6dbfb5 | 2016-03-02 18:38:40 +0800 | [diff] [blame] | 50 | |
Vadim Bendebury | 9ed93cb | 2016-05-22 16:09:54 -0700 | [diff] [blame] | 51 | lb_add_gpios(gpios, chromeos_gpios, ARRAY_SIZE(chromeos_gpios)); |
huang lin | a6dbfb5 | 2016-03-02 18:38:40 +0800 | [diff] [blame] | 52 | } |
| 53 | |
Vadim Bendebury | 9ed93cb | 2016-05-22 16:09:54 -0700 | [diff] [blame] | 54 | void setup_chromeos_gpios(void) |
| 55 | { |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame^] | 56 | if (CONFIG(GRU_BASEBOARD_SCARLET)) |
Julius Werner | 9ec6928 | 2018-02-14 18:01:27 -0800 | [diff] [blame] | 57 | gpio_input(GPIO_WP); |
| 58 | else |
| 59 | gpio_input_pullup(GPIO_WP); |
Vadim Bendebury | 9ed93cb | 2016-05-22 16:09:54 -0700 | [diff] [blame] | 60 | gpio_input_pullup(GPIO_EC_IN_RW); |
| 61 | gpio_input_pullup(GPIO_EC_IRQ); |
huang lin | a6dbfb5 | 2016-03-02 18:38:40 +0800 | [diff] [blame] | 62 | } |
Jeffy Chen | 3d96625 | 2017-03-03 18:24:02 +0800 | [diff] [blame] | 63 | |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame^] | 64 | #if CONFIG(GRU_HAS_TPM2) |
Jeffy Chen | 3d96625 | 2017-03-03 18:24:02 +0800 | [diff] [blame] | 65 | int tis_plat_irq_status(void) |
| 66 | { |
| 67 | return gpio_irq_status(GPIO_TPM_IRQ); |
| 68 | } |
| 69 | #endif |