Naresh G Solanki | ab5d690 | 2016-10-15 18:13:55 +0530 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright (C) 2013 Google Inc. |
| 5 | * Copyright (C) 2016 Intel Corporation. |
| 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. |
| 15 | */ |
| 16 | |
Naresh G Solanki | ab5d690 | 2016-10-15 18:13:55 +0530 | [diff] [blame] | 17 | #include <device/device.h> |
| 18 | #include <device/pci.h> |
Naresh G Solanki | ab5d690 | 2016-10-15 18:13:55 +0530 | [diff] [blame] | 19 | #include <gpio.h> |
| 20 | #include <soc/gpio.h> |
| 21 | #include <string.h> |
| 22 | #include <ec/google/chromeec/ec.h> |
| 23 | #include <vendorcode/google/chromeos/chromeos.h> |
| 24 | |
| 25 | #include "gpio.h" |
| 26 | #include "ec.h" |
| 27 | |
| 28 | #if ENV_RAMSTAGE |
| 29 | #include <boot/coreboot_tables.h> |
| 30 | |
| 31 | void fill_lb_gpios(struct lb_gpios *gpios) |
| 32 | { |
| 33 | struct lb_gpio chromeos_gpios[] = { |
| 34 | {-1, ACTIVE_HIGH, get_write_protect_state(), "write protect"}, |
| 35 | {-1, ACTIVE_HIGH, get_recovery_mode_switch(), "recovery"}, |
Naresh G Solanki | ab5d690 | 2016-10-15 18:13:55 +0530 | [diff] [blame] | 36 | {-1, ACTIVE_HIGH, get_lid_switch(), "lid"}, |
| 37 | {-1, ACTIVE_HIGH, 0, "power"}, |
| 38 | {-1, ACTIVE_HIGH, gfx_get_init_done(), "oprom"}, |
Naresh G Solanki | ab5d690 | 2016-10-15 18:13:55 +0530 | [diff] [blame] | 39 | }; |
| 40 | lb_add_gpios(gpios, chromeos_gpios, ARRAY_SIZE(chromeos_gpios)); |
| 41 | } |
| 42 | #endif /* ENV_RAMSTAGE */ |
| 43 | |
| 44 | int get_lid_switch(void) |
| 45 | { |
Naresh G Solanki | dd397f0 | 2016-11-06 14:05:35 +0530 | [diff] [blame] | 46 | if (IS_ENABLED(CONFIG_EC_GOOGLE_CHROMEEC)) |
| 47 | /* Read lid switch state from the EC. */ |
| 48 | return !!(google_chromeec_get_switches() & EC_SWITCH_LID_OPEN); |
| 49 | |
| 50 | /* Lid always open */ |
| 51 | return 1; |
Naresh G Solanki | ab5d690 | 2016-10-15 18:13:55 +0530 | [diff] [blame] | 52 | } |
| 53 | |
Naresh G Solanki | ab5d690 | 2016-10-15 18:13:55 +0530 | [diff] [blame] | 54 | int get_recovery_mode_switch(void) |
| 55 | { |
Naresh G Solanki | dd397f0 | 2016-11-06 14:05:35 +0530 | [diff] [blame] | 56 | if (IS_ENABLED(CONFIG_EC_GOOGLE_CHROMEEC)) { |
| 57 | /* Check for dedicated recovery switch first. */ |
| 58 | if (google_chromeec_get_switches() & |
| 59 | EC_SWITCH_DEDICATED_RECOVERY) |
Naresh G Solanki | ab5d690 | 2016-10-15 18:13:55 +0530 | [diff] [blame] | 60 | return 1; |
| 61 | |
Naresh G Solanki | dd397f0 | 2016-11-06 14:05:35 +0530 | [diff] [blame] | 62 | /* Otherwise check if the EC has posted the keyboard recovery |
| 63 | * event. */ |
| 64 | return !!(google_chromeec_get_events_b() & |
| 65 | EC_HOST_EVENT_MASK(EC_HOST_EVENT_KEYBOARD_RECOVERY)); |
| 66 | } |
| 67 | |
| 68 | return 0; |
Naresh G Solanki | ab5d690 | 2016-10-15 18:13:55 +0530 | [diff] [blame] | 69 | } |
| 70 | |
| 71 | int clear_recovery_mode_switch(void) |
| 72 | { |
Naresh G Solanki | dd397f0 | 2016-11-06 14:05:35 +0530 | [diff] [blame] | 73 | if (IS_ENABLED(CONFIG_EC_GOOGLE_CHROMEEC)) |
| 74 | /* Clear keyboard recovery event. */ |
| 75 | return google_chromeec_clear_events_b( |
| 76 | EC_HOST_EVENT_MASK(EC_HOST_EVENT_KEYBOARD_RECOVERY)); |
| 77 | |
| 78 | return 0; |
Naresh G Solanki | ab5d690 | 2016-10-15 18:13:55 +0530 | [diff] [blame] | 79 | } |
| 80 | |
| 81 | int get_write_protect_state(void) |
| 82 | { |
Naresh G Solanki | dd397f0 | 2016-11-06 14:05:35 +0530 | [diff] [blame] | 83 | /* No write protect */ |
| 84 | return 0; |
Naresh G Solanki | ab5d690 | 2016-10-15 18:13:55 +0530 | [diff] [blame] | 85 | } |
| 86 | |
| 87 | static const struct cros_gpio cros_gpios[] = { |
| 88 | CROS_GPIO_REC_AL(CROS_GPIO_VIRTUAL, CROS_GPIO_DEVICE_NAME), |
Naresh G Solanki | dd397f0 | 2016-11-06 14:05:35 +0530 | [diff] [blame] | 89 | CROS_GPIO_WP_AH(CROS_GPIO_VIRTUAL, CROS_GPIO_DEVICE_NAME), |
Naresh G Solanki | ab5d690 | 2016-10-15 18:13:55 +0530 | [diff] [blame] | 90 | }; |
| 91 | |
| 92 | void mainboard_chromeos_acpi_generate(void) |
| 93 | { |
| 94 | chromeos_acpi_gpio_generate(cros_gpios, ARRAY_SIZE(cros_gpios)); |
| 95 | } |