Yidi Lin | 3d7b606 | 2015-07-31 17:10:40 +0800 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright 2015 MediaTek Inc. |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; version 2 of the License. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program; if not, write to the Free Software |
| 17 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 18 | */ |
| 19 | |
| 20 | #include <boot/coreboot_tables.h> |
Yidi Lin | 65873ca | 2015-07-31 17:10:57 +0800 | [diff] [blame] | 21 | #include <console/console.h> |
| 22 | #include <ec/google/chromeec/ec.h> |
| 23 | #include <ec/google/chromeec/ec_commands.h> |
| 24 | #include <gpio.h> |
| 25 | #include <string.h> |
Yidi Lin | 3d7b606 | 2015-07-31 17:10:40 +0800 | [diff] [blame] | 26 | #include <vendorcode/google/chromeos/chromeos.h> |
| 27 | |
Yidi Lin | 65873ca | 2015-07-31 17:10:57 +0800 | [diff] [blame] | 28 | #include "gpio.h" |
| 29 | |
| 30 | void setup_chromeos_gpios(void) |
| 31 | { |
| 32 | gpio_input(WRITE_PROTECT); |
| 33 | gpio_input_pullup(EC_IN_RW); |
| 34 | gpio_input_pullup(EC_IRQ); |
| 35 | gpio_input_pullup(LID); |
| 36 | gpio_input_pullup(POWER_BUTTON); |
| 37 | gpio_output(EC_SUSPEND_L, 1); |
| 38 | } |
| 39 | |
Yidi Lin | 3d7b606 | 2015-07-31 17:10:40 +0800 | [diff] [blame] | 40 | void fill_lb_gpios(struct lb_gpios *gpios) |
| 41 | { |
Yidi Lin | 65873ca | 2015-07-31 17:10:57 +0800 | [diff] [blame] | 42 | int count = 0; |
| 43 | |
| 44 | /* Write protect : active low */ |
| 45 | gpios->gpios[count].port = WRITE_PROTECT; |
| 46 | gpios->gpios[count].polarity = ACTIVE_LOW; |
| 47 | gpios->gpios[count].value = gpio_get(WRITE_PROTECT); |
| 48 | strncpy((char *)gpios->gpios[count].name, "write protect", |
| 49 | GPIO_MAX_NAME_LENGTH); |
| 50 | count++; |
| 51 | |
| 52 | /* Recovery: active high */ |
| 53 | gpios->gpios[count].port = -1; |
| 54 | gpios->gpios[count].polarity = ACTIVE_HIGH; |
| 55 | gpios->gpios[count].value = get_recovery_mode_switch(); |
| 56 | strncpy((char *)gpios->gpios[count].name, "recovery", |
| 57 | GPIO_MAX_NAME_LENGTH); |
| 58 | count++; |
| 59 | |
| 60 | /* Lid: active high */ |
| 61 | gpios->gpios[count].port = LID; |
| 62 | gpios->gpios[count].polarity = ACTIVE_HIGH; |
| 63 | gpios->gpios[count].value = -1; |
| 64 | strncpy((char *)gpios->gpios[count].name, "lid", GPIO_MAX_NAME_LENGTH); |
| 65 | count++; |
| 66 | |
| 67 | /* Power: active high */ |
| 68 | gpios->gpios[count].port = POWER_BUTTON; |
| 69 | gpios->gpios[count].polarity = ACTIVE_HIGH; |
| 70 | gpios->gpios[count].value = -1; |
| 71 | strncpy((char *)gpios->gpios[count].name, "power", |
| 72 | GPIO_MAX_NAME_LENGTH); |
| 73 | count++; |
| 74 | |
| 75 | /* Developer: virtual GPIO active high */ |
| 76 | gpios->gpios[count].port = -1; |
| 77 | gpios->gpios[count].polarity = ACTIVE_HIGH; |
| 78 | gpios->gpios[count].value = get_developer_mode_switch(); |
| 79 | strncpy((char *)gpios->gpios[count].name, "developer", |
| 80 | GPIO_MAX_NAME_LENGTH); |
| 81 | count++; |
| 82 | |
| 83 | /* EC in RW: active high */ |
| 84 | gpios->gpios[count].port = EC_IN_RW; |
| 85 | gpios->gpios[count].polarity = ACTIVE_HIGH; |
| 86 | gpios->gpios[count].value = -1; |
| 87 | strncpy((char *)gpios->gpios[count].name, "EC in RW", |
| 88 | GPIO_MAX_NAME_LENGTH); |
| 89 | count++; |
| 90 | |
| 91 | /* EC interrupt: GPIO active low */ |
| 92 | gpios->gpios[count].port = EC_IRQ; |
| 93 | gpios->gpios[count].polarity = ACTIVE_LOW; |
| 94 | gpios->gpios[count].value = -1; |
| 95 | strncpy((char *)gpios->gpios[count].name, "EC interrupt", |
| 96 | GPIO_MAX_NAME_LENGTH); |
| 97 | count++; |
| 98 | |
| 99 | gpios->size = sizeof(*gpios) + (count * sizeof(struct lb_gpio)); |
| 100 | gpios->count = count; |
| 101 | |
| 102 | printk(BIOS_ERR, "Added %d GPIOS size %d\n", count, gpios->size); |
Yidi Lin | 3d7b606 | 2015-07-31 17:10:40 +0800 | [diff] [blame] | 103 | } |
| 104 | |
| 105 | int get_developer_mode_switch(void) |
| 106 | { |
| 107 | return 0; |
| 108 | } |
| 109 | |
| 110 | int get_recovery_mode_switch(void) |
| 111 | { |
Yidi Lin | 65873ca | 2015-07-31 17:10:57 +0800 | [diff] [blame] | 112 | uint32_t ec_events; |
| 113 | |
| 114 | ec_events = google_chromeec_get_events_b(); |
| 115 | return !!(ec_events & |
| 116 | EC_HOST_EVENT_MASK(EC_HOST_EVENT_KEYBOARD_RECOVERY)); |
Yidi Lin | 3d7b606 | 2015-07-31 17:10:40 +0800 | [diff] [blame] | 117 | } |
| 118 | |
| 119 | int get_write_protect_state(void) |
| 120 | { |
Yidi Lin | 65873ca | 2015-07-31 17:10:57 +0800 | [diff] [blame] | 121 | return !gpio_get(WRITE_PROTECT); |
Yidi Lin | 3d7b606 | 2015-07-31 17:10:40 +0800 | [diff] [blame] | 122 | } |