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