Lee Leahy | 5cb9dda | 2015-05-01 10:34:54 -0700 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright (C) 2013 Google Inc. |
| 5 | * Copyright (C) 2015 Intel Corp. |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License as published by |
| 9 | * the Free Software Foundation; version 2 of the License. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
Lee Leahy | 5cb9dda | 2015-05-01 10:34:54 -0700 | [diff] [blame] | 15 | */ |
| 16 | |
Lee Leahy | 5cb9dda | 2015-05-01 10:34:54 -0700 | [diff] [blame] | 17 | #include <rules.h> |
Hannah Williams | 9657f3b | 2016-01-22 23:04:05 -0800 | [diff] [blame] | 18 | #include <gpio.h> |
Lee Leahy | 5cb9dda | 2015-05-01 10:34:54 -0700 | [diff] [blame] | 19 | #include <string.h> |
| 20 | #include <vendorcode/google/chromeos/chromeos.h> |
| 21 | |
Hannah Williams | 9657f3b | 2016-01-22 23:04:05 -0800 | [diff] [blame] | 22 | #define WP_GPIO GP_E_22 |
Lee Leahy | 5cb9dda | 2015-05-01 10:34:54 -0700 | [diff] [blame] | 23 | |
| 24 | #if ENV_RAMSTAGE |
| 25 | #include <boot/coreboot_tables.h> |
| 26 | |
Lee Leahy | 5cb9dda | 2015-05-01 10:34:54 -0700 | [diff] [blame] | 27 | #define ACTIVE_LOW 0 |
| 28 | #define ACTIVE_HIGH 1 |
| 29 | |
| 30 | void fill_lb_gpios(struct lb_gpios *gpios) |
| 31 | { |
Julius Werner | c445b4f | 2016-03-31 17:27:05 -0700 | [diff] [blame] | 32 | struct lb_gpio chromeos_gpios[] = { |
| 33 | {-1, ACTIVE_HIGH, get_write_protect_state(), "write protect"}, |
Furquan Shaikh | 0325dc6 | 2016-07-25 13:02:36 -0700 | [diff] [blame] | 34 | {-1, ACTIVE_HIGH, vboot_recovery_mode_enabled(), "recovery"}, |
Julius Werner | c445b4f | 2016-03-31 17:27:05 -0700 | [diff] [blame] | 35 | {-1, ACTIVE_HIGH, get_developer_mode_switch(), "developer"}, |
| 36 | {-1, ACTIVE_HIGH, get_lid_switch(), "lid"}, |
| 37 | {-1, ACTIVE_HIGH, 0, "power"}, |
| 38 | {-1, ACTIVE_HIGH, gfx_get_init_done(), "oprom"}, |
| 39 | }; |
| 40 | lb_add_gpios(gpios, chromeos_gpios, ARRAY_SIZE(chromeos_gpios)); |
Lee Leahy | 5cb9dda | 2015-05-01 10:34:54 -0700 | [diff] [blame] | 41 | } |
| 42 | #endif /* ENV_RAMSTAGE */ |
| 43 | |
Lee Leahy | 5cb9dda | 2015-05-01 10:34:54 -0700 | [diff] [blame] | 44 | int get_write_protect_state(void) |
| 45 | { |
| 46 | /* |
| 47 | * The vboot loader queries this function in romstage. The GPIOs have |
Hannah Williams | 9657f3b | 2016-01-22 23:04:05 -0800 | [diff] [blame] | 48 | * not been set up yet as that configuration is done in ramstage. |
| 49 | * Configuring this GPIO as input so that there isn't any ambiguity |
| 50 | * in the reading. |
Lee Leahy | 5cb9dda | 2015-05-01 10:34:54 -0700 | [diff] [blame] | 51 | */ |
| 52 | #if ENV_ROMSTAGE |
Hannah Williams | 9657f3b | 2016-01-22 23:04:05 -0800 | [diff] [blame] | 53 | gpio_input_pullup(WP_GPIO); |
Lee Leahy | 5cb9dda | 2015-05-01 10:34:54 -0700 | [diff] [blame] | 54 | #endif |
| 55 | |
| 56 | /* WP is enabled when the pin is reading high. */ |
Hannah Williams | 9657f3b | 2016-01-22 23:04:05 -0800 | [diff] [blame] | 57 | return !!gpio_get(WP_GPIO); |
Lee Leahy | 5cb9dda | 2015-05-01 10:34:54 -0700 | [diff] [blame] | 58 | } |
Aaron Durbin | b0f8151 | 2016-07-25 21:31:41 -0500 | [diff] [blame] | 59 | |
| 60 | static const struct cros_gpio cros_gpios[] = { |
| 61 | CROS_GPIO_REC_AL(CROS_GPIO_VIRTUAL, CROS_GPIO_DEVICE_NAME), |
| 62 | CROS_GPIO_WP_AH(0x10013, CROS_GPIO_DEVICE_NAME), |
| 63 | }; |
| 64 | |
| 65 | void mainboard_chromeos_acpi_generate(void) |
| 66 | { |
| 67 | chromeos_acpi_gpio_generate(cros_gpios, ARRAY_SIZE(cros_gpios)); |
| 68 | } |