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"}, |
| 43 | {GPIO_EC_IN_RW, ACTIVE_HIGH, |
| 44 | gpio_get(GPIO_EC_IN_RW), "EC in RW"}, |
| 45 | }; |
| 46 | lb_add_gpios(gpios, chromeos_gpios, ARRAY_SIZE(chromeos_gpios)); |
| 47 | } |
| 48 | #endif /* ENV_RAMSTAGE */ |
| 49 | |
| 50 | int get_lid_switch(void) |
| 51 | { |
| 52 | /* Read lid switch state from the EC. */ |
| 53 | return !!(google_chromeec_get_switches() & EC_SWITCH_LID_OPEN); |
| 54 | } |
| 55 | |
| 56 | int get_developer_mode_switch(void) |
| 57 | { |
| 58 | /* No physical developer mode switch. */ |
| 59 | return 0; |
| 60 | } |
| 61 | |
| 62 | int get_recovery_mode_switch(void) |
| 63 | { |
| 64 | /* Check for dedicated recovery switch first. */ |
| 65 | if (google_chromeec_get_switches() & EC_SWITCH_DEDICATED_RECOVERY) |
| 66 | return 1; |
| 67 | |
| 68 | /* Otherwise check if the EC has posted the keyboard recovery event. */ |
| 69 | return !!(google_chromeec_get_events_b() & |
| 70 | EC_HOST_EVENT_MASK(EC_HOST_EVENT_KEYBOARD_RECOVERY)); |
| 71 | } |
| 72 | |
| 73 | int clear_recovery_mode_switch(void) |
| 74 | { |
| 75 | /* Clear keyboard recovery event. */ |
| 76 | return google_chromeec_clear_events_b( |
| 77 | EC_HOST_EVENT_MASK(EC_HOST_EVENT_KEYBOARD_RECOVERY)); |
| 78 | } |
| 79 | |
| 80 | int get_write_protect_state(void) |
| 81 | { |
| 82 | /* Read PCH_WP GPIO. */ |
| 83 | return gpio_get(GPIO_PCH_WP); |
| 84 | } |
| 85 | |
| 86 | static const struct cros_gpio cros_gpios[] = { |
| 87 | CROS_GPIO_REC_AL(CROS_GPIO_VIRTUAL, CROS_GPIO_DEVICE_NAME), |
| 88 | CROS_GPIO_WP_AH(GPIO_PCH_WP, CROS_GPIO_DEVICE_NAME), |
| 89 | }; |
| 90 | |
| 91 | void mainboard_chromeos_acpi_generate(void) |
| 92 | { |
| 93 | chromeos_acpi_gpio_generate(cros_gpios, ARRAY_SIZE(cros_gpios)); |
| 94 | } |