Katie Roberts-Hoffman | b262c72 | 2014-10-23 19:14:30 -0700 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright 2014 Rockchip 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. |
Katie Roberts-Hoffman | b262c72 | 2014-10-23 19:14:30 -0700 | [diff] [blame] | 14 | */ |
| 15 | |
| 16 | #include <boot/coreboot_tables.h> |
| 17 | #include <console/console.h> |
| 18 | #include <ec/google/chromeec/ec.h> |
| 19 | #include <ec/google/chromeec/ec_commands.h> |
| 20 | #include <gpio.h> |
| 21 | #include <string.h> |
| 22 | #include <vendorcode/google/chromeos/chromeos.h> |
| 23 | |
Julius Werner | 36fd82d | 2014-11-20 17:02:17 -0800 | [diff] [blame] | 24 | #include "board.h" |
| 25 | |
Katie Roberts-Hoffman | b262c72 | 2014-10-23 19:14:30 -0700 | [diff] [blame] | 26 | #define GPIO_WP GPIO(7, A, 6) |
Julius Werner | 0353c9f | 2014-11-06 12:51:24 -0800 | [diff] [blame] | 27 | #define GPIO_LID GPIO(0, A, 6) |
Katie Roberts-Hoffman | b262c72 | 2014-10-23 19:14:30 -0700 | [diff] [blame] | 28 | #define GPIO_POWER GPIO(0, A, 5) |
| 29 | #define GPIO_RECOVERY GPIO(0, B, 1) |
Julius Werner | 36fd82d | 2014-11-20 17:02:17 -0800 | [diff] [blame] | 30 | #define GPIO_ECINRW GPIO(0, A, 7) |
Julius Werner | 9ac9ac63 | 2015-04-24 17:30:36 -0700 | [diff] [blame] | 31 | #define GPIO_ECIRQ GPIO(7, A, 7) |
Katie Roberts-Hoffman | b262c72 | 2014-10-23 19:14:30 -0700 | [diff] [blame] | 32 | |
| 33 | void setup_chromeos_gpios(void) |
| 34 | { |
| 35 | gpio_input(GPIO_WP); |
| 36 | gpio_input_pullup(GPIO_LID); |
| 37 | gpio_input(GPIO_POWER); |
| 38 | gpio_input_pullup(GPIO_RECOVERY); |
Julius Werner | 9ac9ac63 | 2015-04-24 17:30:36 -0700 | [diff] [blame] | 39 | gpio_input(GPIO_ECIRQ); |
Katie Roberts-Hoffman | b262c72 | 2014-10-23 19:14:30 -0700 | [diff] [blame] | 40 | } |
| 41 | |
| 42 | void fill_lb_gpios(struct lb_gpios *gpios) |
| 43 | { |
| 44 | int count = 0; |
| 45 | |
| 46 | /* Write Protect: active low */ |
| 47 | gpios->gpios[count].port = GPIO_WP.raw; |
| 48 | gpios->gpios[count].polarity = ACTIVE_LOW; |
| 49 | gpios->gpios[count].value = gpio_get(GPIO_WP); |
| 50 | strncpy((char *)gpios->gpios[count].name, "write protect", |
| 51 | GPIO_MAX_NAME_LENGTH); |
| 52 | count++; |
| 53 | |
| 54 | /* Recovery: active low */ |
| 55 | gpios->gpios[count].port = GPIO_RECOVERY.raw; |
| 56 | gpios->gpios[count].polarity = ACTIVE_HIGH; |
| 57 | gpios->gpios[count].value = get_recovery_mode_switch(); |
| 58 | strncpy((char *)gpios->gpios[count].name, "recovery", |
| 59 | GPIO_MAX_NAME_LENGTH); |
| 60 | count++; |
| 61 | |
| 62 | /* Lid: active high */ |
| 63 | gpios->gpios[count].port = GPIO_LID.raw; |
| 64 | gpios->gpios[count].polarity = ACTIVE_HIGH; |
Julius Werner | 36fd82d | 2014-11-20 17:02:17 -0800 | [diff] [blame] | 65 | gpios->gpios[count].value = -1; |
Katie Roberts-Hoffman | b262c72 | 2014-10-23 19:14:30 -0700 | [diff] [blame] | 66 | strncpy((char *)gpios->gpios[count].name, "lid", GPIO_MAX_NAME_LENGTH); |
| 67 | count++; |
| 68 | |
| 69 | /* Power:GPIO active high */ |
| 70 | gpios->gpios[count].port = GPIO_POWER.raw; |
Julius Werner | 5016820 | 2014-11-10 21:37:12 -0800 | [diff] [blame] | 71 | gpios->gpios[count].polarity = ACTIVE_LOW; |
Julius Werner | 36fd82d | 2014-11-20 17:02:17 -0800 | [diff] [blame] | 72 | gpios->gpios[count].value = -1; |
Katie Roberts-Hoffman | b262c72 | 2014-10-23 19:14:30 -0700 | [diff] [blame] | 73 | strncpy((char *)gpios->gpios[count].name, "power", |
| 74 | GPIO_MAX_NAME_LENGTH); |
| 75 | count++; |
| 76 | |
| 77 | /* Developer: GPIO active high */ |
| 78 | gpios->gpios[count].port = -1; |
| 79 | gpios->gpios[count].polarity = ACTIVE_HIGH; |
| 80 | gpios->gpios[count].value = get_developer_mode_switch(); |
| 81 | strncpy((char *)gpios->gpios[count].name, "developer", |
| 82 | GPIO_MAX_NAME_LENGTH); |
| 83 | count++; |
| 84 | |
Julius Werner | 36fd82d | 2014-11-20 17:02:17 -0800 | [diff] [blame] | 85 | /* EC in RW: GPIO active high */ |
| 86 | gpios->gpios[count].port = GPIO_ECINRW.raw; |
| 87 | gpios->gpios[count].polarity = ACTIVE_HIGH; |
| 88 | gpios->gpios[count].value = -1; |
| 89 | strncpy((char *)gpios->gpios[count].name, "EC in RW", |
| 90 | GPIO_MAX_NAME_LENGTH); |
| 91 | count++; |
| 92 | |
Julius Werner | 9ac9ac63 | 2015-04-24 17:30:36 -0700 | [diff] [blame] | 93 | /* EC interrupt: GPIO active high */ |
| 94 | gpios->gpios[count].port = GPIO_ECIRQ.raw; |
| 95 | gpios->gpios[count].polarity = ACTIVE_LOW; |
| 96 | gpios->gpios[count].value = -1; |
| 97 | strncpy((char *)gpios->gpios[count].name, "EC interrupt", |
| 98 | GPIO_MAX_NAME_LENGTH); |
| 99 | count++; |
| 100 | |
Julius Werner | 36fd82d | 2014-11-20 17:02:17 -0800 | [diff] [blame] | 101 | /* Reset: GPIO active high (output) */ |
| 102 | gpios->gpios[count].port = GPIO_RESET.raw; |
| 103 | gpios->gpios[count].polarity = ACTIVE_HIGH; |
| 104 | gpios->gpios[count].value = -1; |
| 105 | strncpy((char *)gpios->gpios[count].name, "reset", |
| 106 | GPIO_MAX_NAME_LENGTH); |
| 107 | count++; |
| 108 | |
Julius Werner | 1f0569f | 2015-01-21 15:28:07 -0800 | [diff] [blame] | 109 | /* Backlight: GPIO active high (output) */ |
| 110 | gpios->gpios[count].port = GPIO_BACKLIGHT.raw; |
| 111 | gpios->gpios[count].polarity = ACTIVE_HIGH; |
| 112 | gpios->gpios[count].value = -1; |
| 113 | strncpy((char *)gpios->gpios[count].name, "backlight", |
| 114 | GPIO_MAX_NAME_LENGTH); |
| 115 | count++; |
| 116 | |
Katie Roberts-Hoffman | b262c72 | 2014-10-23 19:14:30 -0700 | [diff] [blame] | 117 | gpios->size = sizeof(*gpios) + (count * sizeof(struct lb_gpio)); |
| 118 | gpios->count = count; |
| 119 | |
| 120 | printk(BIOS_ERR, "Added %d GPIOS size %d\n", count, gpios->size); |
| 121 | } |
| 122 | |
| 123 | int get_developer_mode_switch(void) |
| 124 | { |
| 125 | return 0; |
| 126 | } |
| 127 | |
| 128 | int get_recovery_mode_switch(void) |
| 129 | { |
| 130 | uint32_t ec_events; |
| 131 | |
| 132 | /* The GPIO is active low. */ |
| 133 | if (!gpio_get(GPIO_RECOVERY)) |
| 134 | return 1; |
| 135 | |
| 136 | ec_events = google_chromeec_get_events_b(); |
| 137 | return !!(ec_events & |
| 138 | EC_HOST_EVENT_MASK(EC_HOST_EVENT_KEYBOARD_RECOVERY)); |
| 139 | } |
| 140 | |
| 141 | int get_write_protect_state(void) |
| 142 | { |
| 143 | return !gpio_get(GPIO_WP); |
| 144 | } |