Patrick Georgi | 4d6ad83 | 2015-06-22 19:43:18 +0200 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright 2015 Google 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. |
Patrick Georgi | 4d6ad83 | 2015-06-22 19:43:18 +0200 | [diff] [blame] | 14 | */ |
| 15 | |
| 16 | #include <boardid.h> |
| 17 | #include <boot/coreboot_tables.h> |
| 18 | #include <console/console.h> |
| 19 | #include <ec/google/chromeec/ec.h> |
| 20 | #include <ec/google/chromeec/ec_commands.h> |
| 21 | #include <string.h> |
| 22 | #include <vendorcode/google/chromeos/chromeos.h> |
| 23 | |
| 24 | #include "gpio.h" |
| 25 | |
| 26 | void fill_lb_gpios(struct lb_gpios *gpios) |
| 27 | { |
| 28 | int count = 0; |
| 29 | |
| 30 | /* Write Protect: active low */ |
| 31 | gpios->gpios[count].port = WRITE_PROTECT_L; |
| 32 | gpios->gpios[count].polarity = ACTIVE_LOW; |
| 33 | gpios->gpios[count].value = gpio_get(WRITE_PROTECT_L); |
| 34 | strncpy((char *)gpios->gpios[count].name, "write protect", |
| 35 | GPIO_MAX_NAME_LENGTH); |
| 36 | count++; |
| 37 | |
| 38 | /* Recovery: active high */ |
| 39 | gpios->gpios[count].port = -1; |
| 40 | gpios->gpios[count].polarity = ACTIVE_HIGH; |
| 41 | gpios->gpios[count].value = get_recovery_mode_switch(); |
| 42 | strncpy((char *)gpios->gpios[count].name, "recovery", |
| 43 | GPIO_MAX_NAME_LENGTH); |
| 44 | count++; |
| 45 | |
| 46 | /* TODO(furquan): add lid switch */ |
| 47 | |
| 48 | /* Power: active low / high depending on board id */ |
| 49 | gpios->gpios[count].port = POWER_BUTTON; |
| 50 | gpios->gpios[count].polarity = ACTIVE_LOW; |
| 51 | gpios->gpios[count].value = -1; |
| 52 | strncpy((char *)gpios->gpios[count].name, "power", |
| 53 | GPIO_MAX_NAME_LENGTH); |
| 54 | count++; |
| 55 | |
| 56 | /* Developer: virtual GPIO active high */ |
| 57 | gpios->gpios[count].port = -1; |
| 58 | gpios->gpios[count].polarity = ACTIVE_HIGH; |
| 59 | gpios->gpios[count].value = get_developer_mode_switch(); |
| 60 | strncpy((char *)gpios->gpios[count].name, "developer", |
| 61 | GPIO_MAX_NAME_LENGTH); |
| 62 | count++; |
| 63 | |
| 64 | /* EC in RW: active high */ |
| 65 | gpios->gpios[count].port = EC_IN_RW; |
| 66 | gpios->gpios[count].polarity = ACTIVE_HIGH; |
| 67 | gpios->gpios[count].value = -1; |
| 68 | strncpy((char *)gpios->gpios[count].name, "EC in RW", |
| 69 | GPIO_MAX_NAME_LENGTH); |
| 70 | count++; |
| 71 | |
| 72 | /* Reset: active low (output) */ |
| 73 | gpios->gpios[count].port = AP_SYS_RESET_L; |
| 74 | gpios->gpios[count].polarity = ACTIVE_LOW; |
| 75 | gpios->gpios[count].value = -1; |
| 76 | strncpy((char *)gpios->gpios[count].name, "reset", |
| 77 | GPIO_MAX_NAME_LENGTH); |
| 78 | count++; |
| 79 | |
| 80 | gpios->size = sizeof(*gpios) + (count * sizeof(struct lb_gpio)); |
| 81 | gpios->count = count; |
| 82 | |
| 83 | printk(BIOS_ERR, "Added %d GPIOS size %d\n", count, gpios->size); |
| 84 | } |
| 85 | |
| 86 | int get_developer_mode_switch(void) |
| 87 | { |
| 88 | return 0; |
| 89 | } |
| 90 | |
| 91 | int get_recovery_mode_switch(void) |
| 92 | { |
| 93 | uint32_t ec_events; |
| 94 | |
| 95 | ec_events = google_chromeec_get_events_b(); |
| 96 | |
| 97 | /* Enter recovery mode either on keyboard recovery / fastboot event. */ |
| 98 | return !!((ec_events & |
| 99 | EC_HOST_EVENT_MASK(EC_HOST_EVENT_KEYBOARD_RECOVERY)) || |
| 100 | (ec_events & |
| 101 | EC_HOST_EVENT_MASK(EC_HOST_EVENT_KEYBOARD_FASTBOOT))); |
| 102 | } |
| 103 | |
| 104 | int get_write_protect_state(void) |
| 105 | { |
| 106 | return !gpio_get(WRITE_PROTECT_L); |
| 107 | } |