Patrick Georgi | 406313d | 2015-07-20 22:01:32 +0200 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright (C) 2015 Google Inc. |
| 5 | * Copyright (C) 2015 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. |
Patrick Georgi | 406313d | 2015-07-20 22:01:32 +0200 | [diff] [blame] | 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> |
Duncan Laurie | c328191 | 2015-08-13 12:54:27 -0700 | [diff] [blame] | 22 | #include <gpio.h> |
Patrick Georgi | 406313d | 2015-07-20 22:01:32 +0200 | [diff] [blame] | 23 | #include <soc/gpio.h> |
| 24 | #include <string.h> |
Duncan Laurie | c328191 | 2015-08-13 12:54:27 -0700 | [diff] [blame] | 25 | #include <ec/google/chromeec/ec.h> |
Patrick Georgi | 406313d | 2015-07-20 22:01:32 +0200 | [diff] [blame] | 26 | #include <vendorcode/google/chromeos/chromeos.h> |
| 27 | |
Duncan Laurie | 241f8fc | 2015-09-03 16:10:48 -0700 | [diff] [blame] | 28 | #include "gpio.h" |
Duncan Laurie | c328191 | 2015-08-13 12:54:27 -0700 | [diff] [blame] | 29 | #include "ec.h" |
| 30 | |
Patrick Georgi | 406313d | 2015-07-20 22:01:32 +0200 | [diff] [blame] | 31 | #if ENV_RAMSTAGE |
| 32 | #include <boot/coreboot_tables.h> |
| 33 | |
Patrick Georgi | 406313d | 2015-07-20 22:01:32 +0200 | [diff] [blame] | 34 | void fill_lb_gpios(struct lb_gpios *gpios) |
| 35 | { |
Duncan Laurie | a58cf01 | 2015-08-20 09:54:18 -0700 | [diff] [blame] | 36 | struct lb_gpio *start_gpio = gpios->gpios; |
| 37 | struct lb_gpio *gpio = start_gpio; |
Patrick Georgi | 406313d | 2015-07-20 22:01:32 +0200 | [diff] [blame] | 38 | |
Duncan Laurie | caa5149 | 2015-07-20 15:50:42 -0700 | [diff] [blame] | 39 | fill_lb_gpio(gpio++, -1, ACTIVE_HIGH, "write protect", |
| 40 | get_write_protect_state()); |
Patrick Georgi | 406313d | 2015-07-20 22:01:32 +0200 | [diff] [blame] | 41 | fill_lb_gpio(gpio++, -1, ACTIVE_HIGH, "recovery", |
| 42 | get_recovery_mode_switch()); |
| 43 | fill_lb_gpio(gpio++, -1, ACTIVE_HIGH, "developer", |
| 44 | get_developer_mode_switch()); |
| 45 | fill_lb_gpio(gpio++, -1, ACTIVE_HIGH, "lid", |
| 46 | get_lid_switch()); |
| 47 | fill_lb_gpio(gpio++, -1, ACTIVE_HIGH, "power", 0); |
| 48 | fill_lb_gpio(gpio++, -1, ACTIVE_HIGH, "oprom", gfx_get_init_done()); |
Duncan Laurie | a58cf01 | 2015-08-20 09:54:18 -0700 | [diff] [blame] | 49 | fill_lb_gpio(gpio++, GPIO_EC_IN_RW, ACTIVE_HIGH, "EC in RW", |
| 50 | gpio_get(GPIO_EC_IN_RW)); |
| 51 | |
| 52 | gpios->count = gpio - start_gpio; |
| 53 | gpios->size = sizeof(*gpios) + (gpios->count * sizeof(*gpio)); |
Patrick Georgi | 406313d | 2015-07-20 22:01:32 +0200 | [diff] [blame] | 54 | } |
| 55 | #endif /* ENV_RAMSTAGE */ |
| 56 | |
| 57 | int get_lid_switch(void) |
| 58 | { |
Duncan Laurie | c328191 | 2015-08-13 12:54:27 -0700 | [diff] [blame] | 59 | /* Read lid switch state from the EC. */ |
| 60 | return !!(google_chromeec_get_switches() & EC_SWITCH_LID_OPEN); |
Patrick Georgi | 406313d | 2015-07-20 22:01:32 +0200 | [diff] [blame] | 61 | } |
Duncan Laurie | c328191 | 2015-08-13 12:54:27 -0700 | [diff] [blame] | 62 | |
Patrick Georgi | 406313d | 2015-07-20 22:01:32 +0200 | [diff] [blame] | 63 | int get_developer_mode_switch(void) |
| 64 | { |
Duncan Laurie | c328191 | 2015-08-13 12:54:27 -0700 | [diff] [blame] | 65 | /* No physical developer mode switch. */ |
Patrick Georgi | 406313d | 2015-07-20 22:01:32 +0200 | [diff] [blame] | 66 | return 0; |
| 67 | } |
| 68 | |
| 69 | int get_recovery_mode_switch(void) |
| 70 | { |
Duncan Laurie | c328191 | 2015-08-13 12:54:27 -0700 | [diff] [blame] | 71 | /* Check for dedicated recovery switch first. */ |
| 72 | if (google_chromeec_get_switches() & EC_SWITCH_DEDICATED_RECOVERY) |
| 73 | return 1; |
| 74 | |
| 75 | /* Otherwise check if the EC has posted the keyboard recovery event. */ |
| 76 | return !!(google_chromeec_get_events_b() & |
| 77 | EC_HOST_EVENT_MASK(EC_HOST_EVENT_KEYBOARD_RECOVERY)); |
| 78 | } |
| 79 | |
| 80 | int clear_recovery_mode_switch(void) |
| 81 | { |
| 82 | /* Clear keyboard recovery event. */ |
| 83 | return google_chromeec_clear_events_b( |
| 84 | EC_HOST_EVENT_MASK(EC_HOST_EVENT_KEYBOARD_RECOVERY)); |
Patrick Georgi | 406313d | 2015-07-20 22:01:32 +0200 | [diff] [blame] | 85 | } |
| 86 | |
| 87 | int get_write_protect_state(void) |
| 88 | { |
Duncan Laurie | c328191 | 2015-08-13 12:54:27 -0700 | [diff] [blame] | 89 | /* Read PCH_WP GPIO. */ |
Duncan Laurie | 5626085 | 2015-08-17 09:53:22 -0700 | [diff] [blame] | 90 | return gpio_get(GPIO_PCH_WP); |
Patrick Georgi | 406313d | 2015-07-20 22:01:32 +0200 | [diff] [blame] | 91 | } |