Aaron Durbin | 2b0b764 | 2014-08-05 14:03:17 -0500 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright 2014 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. |
Aaron Durbin | 2b0b764 | 2014-08-05 14:03:17 -0500 | [diff] [blame] | 14 | */ |
| 15 | |
Furquan Shaikh | ad73c45 | 2014-11-10 23:22:01 -0800 | [diff] [blame] | 16 | #include <boardid.h> |
Aaron Durbin | 2b0b764 | 2014-08-05 14:03:17 -0500 | [diff] [blame] | 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> |
Julius Werner | 96195ee | 2014-10-20 13:25:21 -0700 | [diff] [blame] | 23 | |
Aaron Durbin | 45a1c94 | 2014-08-29 10:48:27 -0500 | [diff] [blame] | 24 | #include "gpio.h" |
Aaron Durbin | 2b0b764 | 2014-08-05 14:03:17 -0500 | [diff] [blame] | 25 | |
Furquan Shaikh | ad73c45 | 2014-11-10 23:22:01 -0800 | [diff] [blame] | 26 | static inline uint32_t get_pwr_btn_polarity(void) |
| 27 | { |
| 28 | if (board_id() < BOARD_ID_PROTO_3) |
| 29 | return ACTIVE_HIGH; |
| 30 | |
| 31 | return ACTIVE_LOW; |
| 32 | } |
| 33 | |
Aaron Durbin | 2b0b764 | 2014-08-05 14:03:17 -0500 | [diff] [blame] | 34 | void fill_lb_gpios(struct lb_gpios *gpios) |
| 35 | { |
| 36 | int count = 0; |
| 37 | |
| 38 | /* Write Protect: active low */ |
Julius Werner | 36fd82d | 2014-11-20 17:02:17 -0800 | [diff] [blame] | 39 | gpios->gpios[count].port = WRITE_PROTECT_L; |
Aaron Durbin | 2b0b764 | 2014-08-05 14:03:17 -0500 | [diff] [blame] | 40 | gpios->gpios[count].polarity = ACTIVE_LOW; |
Julius Werner | eaa9c45 | 2014-09-24 15:40:49 -0700 | [diff] [blame] | 41 | gpios->gpios[count].value = gpio_get(WRITE_PROTECT_L); |
Aaron Durbin | 2b0b764 | 2014-08-05 14:03:17 -0500 | [diff] [blame] | 42 | strncpy((char *)gpios->gpios[count].name, "write protect", |
| 43 | GPIO_MAX_NAME_LENGTH); |
| 44 | count++; |
| 45 | |
| 46 | /* Recovery: active high */ |
| 47 | gpios->gpios[count].port = -1; |
| 48 | gpios->gpios[count].polarity = ACTIVE_HIGH; |
| 49 | gpios->gpios[count].value = get_recovery_mode_switch(); |
| 50 | strncpy((char *)gpios->gpios[count].name, "recovery", |
| 51 | GPIO_MAX_NAME_LENGTH); |
| 52 | count++; |
| 53 | |
| 54 | /* TODO(adurbin): add lid switch */ |
| 55 | |
Furquan Shaikh | ad73c45 | 2014-11-10 23:22:01 -0800 | [diff] [blame] | 56 | /* Power: active low / high depending on board id */ |
Julius Werner | 36fd82d | 2014-11-20 17:02:17 -0800 | [diff] [blame] | 57 | gpios->gpios[count].port = POWER_BUTTON; |
Furquan Shaikh | ad73c45 | 2014-11-10 23:22:01 -0800 | [diff] [blame] | 58 | gpios->gpios[count].polarity = get_pwr_btn_polarity(); |
Julius Werner | 36fd82d | 2014-11-20 17:02:17 -0800 | [diff] [blame] | 59 | gpios->gpios[count].value = -1; |
Aaron Durbin | 2b0b764 | 2014-08-05 14:03:17 -0500 | [diff] [blame] | 60 | strncpy((char *)gpios->gpios[count].name, "power", |
| 61 | GPIO_MAX_NAME_LENGTH); |
| 62 | count++; |
| 63 | |
| 64 | /* Developer: virtual GPIO active high */ |
| 65 | gpios->gpios[count].port = -1; |
| 66 | gpios->gpios[count].polarity = ACTIVE_HIGH; |
| 67 | gpios->gpios[count].value = get_developer_mode_switch(); |
| 68 | strncpy((char *)gpios->gpios[count].name, "developer", |
| 69 | GPIO_MAX_NAME_LENGTH); |
| 70 | count++; |
| 71 | |
Julius Werner | 36fd82d | 2014-11-20 17:02:17 -0800 | [diff] [blame] | 72 | /* EC in RW: active high */ |
| 73 | gpios->gpios[count].port = EC_IN_RW; |
| 74 | gpios->gpios[count].polarity = ACTIVE_HIGH; |
| 75 | gpios->gpios[count].value = -1; |
| 76 | strncpy((char *)gpios->gpios[count].name, "EC in RW", |
| 77 | GPIO_MAX_NAME_LENGTH); |
| 78 | count++; |
| 79 | |
| 80 | /* Reset: active low (output) */ |
| 81 | gpios->gpios[count].port = AP_SYS_RESET_L; |
| 82 | gpios->gpios[count].polarity = ACTIVE_LOW; |
| 83 | gpios->gpios[count].value = -1; |
| 84 | strncpy((char *)gpios->gpios[count].name, "reset", |
| 85 | GPIO_MAX_NAME_LENGTH); |
| 86 | count++; |
| 87 | |
Aaron Durbin | 2b0b764 | 2014-08-05 14:03:17 -0500 | [diff] [blame] | 88 | gpios->size = sizeof(*gpios) + (count * sizeof(struct lb_gpio)); |
| 89 | gpios->count = count; |
| 90 | |
| 91 | printk(BIOS_ERR, "Added %d GPIOS size %d\n", count, gpios->size); |
| 92 | } |
| 93 | |
| 94 | int get_developer_mode_switch(void) |
| 95 | { |
| 96 | return 0; |
| 97 | } |
| 98 | |
| 99 | int get_recovery_mode_switch(void) |
| 100 | { |
| 101 | uint32_t ec_events; |
| 102 | |
| 103 | ec_events = google_chromeec_get_events_b(); |
| 104 | return !!(ec_events & |
| 105 | EC_HOST_EVENT_MASK(EC_HOST_EVENT_KEYBOARD_RECOVERY)); |
| 106 | } |
| 107 | |
| 108 | int get_write_protect_state(void) |
| 109 | { |
Julius Werner | eaa9c45 | 2014-09-24 15:40:49 -0700 | [diff] [blame] | 110 | return !gpio_get(WRITE_PROTECT_L); |
Aaron Durbin | 2b0b764 | 2014-08-05 14:03:17 -0500 | [diff] [blame] | 111 | } |