Ronald G. Minnich | 3faa2c7 | 2013-02-20 15:46:46 -0800 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright (C) 2013 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. |
| 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 | |
Gabe Black | a5d914e4 | 2013-04-15 18:22:11 -0700 | [diff] [blame^] | 20 | #include <boot/coreboot_tables.h> |
Ronald G. Minnich | 3faa2c7 | 2013-02-20 15:46:46 -0800 | [diff] [blame] | 21 | #include <console/console.h> |
Gabe Black | 7fa726a | 2013-04-15 18:09:15 -0700 | [diff] [blame] | 22 | #include <ec/google/chromeec/ec.h> |
| 23 | #include <ec/google/chromeec/ec_commands.h> |
Ronald G. Minnich | 3faa2c7 | 2013-02-20 15:46:46 -0800 | [diff] [blame] | 24 | #include <string.h> |
| 25 | #include <vendorcode/google/chromeos/chromeos.h> |
Ronald G. Minnich | 3faa2c7 | 2013-02-20 15:46:46 -0800 | [diff] [blame] | 26 | |
David Hendricks | d9b16f3 | 2013-03-06 19:16:10 -0800 | [diff] [blame] | 27 | #include <cpu/samsung/exynos5250/cpu.h> |
| 28 | #include <cpu/samsung/exynos5250/gpio.h> |
| 29 | #include <cpu/samsung/exynos5-common/gpio.h> |
| 30 | |
Gabe Black | a5d914e4 | 2013-04-15 18:22:11 -0700 | [diff] [blame^] | 31 | enum { |
| 32 | ACTIVE_LOW = 0, |
| 33 | ACTIVE_HIGH = 1 |
| 34 | }; |
Ronald G. Minnich | 3faa2c7 | 2013-02-20 15:46:46 -0800 | [diff] [blame] | 35 | |
Gabe Black | a5d914e4 | 2013-04-15 18:22:11 -0700 | [diff] [blame^] | 36 | enum { |
| 37 | WP_GPIO = 6, |
| 38 | RECMODE_GPIO = 0, |
| 39 | LID_GPIO = 5 |
| 40 | }; |
Ronald G. Minnich | 3faa2c7 | 2013-02-20 15:46:46 -0800 | [diff] [blame] | 41 | |
Gabe Black | 7fa726a | 2013-04-15 18:09:15 -0700 | [diff] [blame] | 42 | static struct exynos5_gpio_part1 *gpio_pt1 = |
| 43 | (struct exynos5_gpio_part1 *)EXYNOS5_GPIO_PART1_BASE; |
| 44 | static struct exynos5_gpio_part2 *gpio_pt2 = |
| 45 | (struct exynos5_gpio_part2 *)EXYNOS5_GPIO_PART2_BASE; |
| 46 | |
Ronald G. Minnich | 3faa2c7 | 2013-02-20 15:46:46 -0800 | [diff] [blame] | 47 | void fill_lb_gpios(struct lb_gpios *gpios) |
| 48 | { |
Gabe Black | a5d914e4 | 2013-04-15 18:22:11 -0700 | [diff] [blame^] | 49 | int count = 0; |
Ronald G. Minnich | 3faa2c7 | 2013-02-20 15:46:46 -0800 | [diff] [blame] | 50 | |
Gabe Black | a554e23 | 2013-04-15 16:25:02 -0700 | [diff] [blame] | 51 | /* Write Protect: active low */ |
Gabe Black | a5d914e4 | 2013-04-15 18:22:11 -0700 | [diff] [blame^] | 52 | gpios->gpios[count].port = EXYNOS5_GPD1; |
| 53 | gpios->gpios[count].polarity = ACTIVE_LOW; |
| 54 | gpios->gpios[count].value = s5p_gpio_get_value(&gpio_pt1->d1, WP_GPIO); |
| 55 | strncpy((char *)gpios->gpios[count].name, "write protect", |
| 56 | GPIO_MAX_NAME_LENGTH); |
| 57 | count++; |
Ronald G. Minnich | 3faa2c7 | 2013-02-20 15:46:46 -0800 | [diff] [blame] | 58 | |
Gabe Black | fe3b024 | 2013-04-10 14:39:09 -0700 | [diff] [blame] | 59 | /* Recovery: active low */ |
Gabe Black | a5d914e4 | 2013-04-15 18:22:11 -0700 | [diff] [blame^] | 60 | gpios->gpios[count].port = -1; |
| 61 | gpios->gpios[count].polarity = ACTIVE_HIGH; |
| 62 | gpios->gpios[count].value = get_recovery_mode_switch(); |
| 63 | strncpy((char *)gpios->gpios[count].name, "recovery", |
| 64 | GPIO_MAX_NAME_LENGTH); |
| 65 | count++; |
Ronald G. Minnich | 3faa2c7 | 2013-02-20 15:46:46 -0800 | [diff] [blame] | 66 | |
Gabe Black | a554e23 | 2013-04-15 16:25:02 -0700 | [diff] [blame] | 67 | /* Lid: active high */ |
Gabe Black | a5d914e4 | 2013-04-15 18:22:11 -0700 | [diff] [blame^] | 68 | gpios->gpios[count].port = EXYNOS5_GPX3; |
| 69 | gpios->gpios[count].polarity = ACTIVE_HIGH; |
| 70 | gpios->gpios[count].value = s5p_gpio_get_value(&gpio_pt2->x3, LID_GPIO); |
| 71 | strncpy((char *)gpios->gpios[count].name, "lid", GPIO_MAX_NAME_LENGTH); |
| 72 | count++; |
Ronald G. Minnich | eeb3632 | 2013-02-27 10:12:03 -0800 | [diff] [blame] | 73 | |
David Hendricks | d9b16f3 | 2013-03-06 19:16:10 -0800 | [diff] [blame] | 74 | /* Power: virtual GPIO active low */ |
Gabe Black | a5d914e4 | 2013-04-15 18:22:11 -0700 | [diff] [blame^] | 75 | gpios->gpios[count].port = -1; |
| 76 | gpios->gpios[count].polarity = ACTIVE_LOW; |
| 77 | gpios->gpios[count].value = 1; |
| 78 | strncpy((char *)gpios->gpios[count].name, "power", |
| 79 | GPIO_MAX_NAME_LENGTH); |
| 80 | count++; |
Ronald G. Minnich | eeb3632 | 2013-02-27 10:12:03 -0800 | [diff] [blame] | 81 | |
| 82 | /* Developer: virtual GPIO active high */ |
Gabe Black | a5d914e4 | 2013-04-15 18:22:11 -0700 | [diff] [blame^] | 83 | gpios->gpios[count].port = -1; |
| 84 | gpios->gpios[count].polarity = ACTIVE_HIGH; |
| 85 | gpios->gpios[count].value = get_developer_mode_switch(); |
| 86 | strncpy((char *)gpios->gpios[count].name, "developer", |
| 87 | GPIO_MAX_NAME_LENGTH); |
| 88 | count++; |
Ronald G. Minnich | 3faa2c7 | 2013-02-20 15:46:46 -0800 | [diff] [blame] | 89 | |
| 90 | /* Was VGA Option ROM loaded? */ |
Gabe Black | a5d914e4 | 2013-04-15 18:22:11 -0700 | [diff] [blame^] | 91 | gpios->gpios[count].port = -1; /* This is a pseudo GPIO */ |
| 92 | gpios->gpios[count].polarity = ACTIVE_HIGH; |
| 93 | gpios->gpios[count].value = 0; |
| 94 | strncpy((char *)gpios->gpios[count].name, "oprom", |
| 95 | GPIO_MAX_NAME_LENGTH); |
| 96 | count++; |
Ronald G. Minnich | 3faa2c7 | 2013-02-20 15:46:46 -0800 | [diff] [blame] | 97 | |
Gabe Black | a5d914e4 | 2013-04-15 18:22:11 -0700 | [diff] [blame^] | 98 | gpios->size = sizeof(*gpios) + (count * sizeof(struct lb_gpio)); |
| 99 | gpios->count = count; |
| 100 | |
| 101 | printk(BIOS_ERR, "Added %d GPIOS size %d\n", count, gpios->size); |
Ronald G. Minnich | 3faa2c7 | 2013-02-20 15:46:46 -0800 | [diff] [blame] | 102 | |
| 103 | } |
| 104 | |
| 105 | int get_developer_mode_switch(void) |
| 106 | { |
Gabe Black | a5d914e4 | 2013-04-15 18:22:11 -0700 | [diff] [blame^] | 107 | return 0; |
Ronald G. Minnich | 3faa2c7 | 2013-02-20 15:46:46 -0800 | [diff] [blame] | 108 | } |
| 109 | |
| 110 | int get_recovery_mode_switch(void) |
| 111 | { |
Gabe Black | 7fa726a | 2013-04-15 18:09:15 -0700 | [diff] [blame] | 112 | uint32_t ec_events; |
Ronald G. Minnich | 3faa2c7 | 2013-02-20 15:46:46 -0800 | [diff] [blame] | 113 | |
Gabe Black | 7fa726a | 2013-04-15 18:09:15 -0700 | [diff] [blame] | 114 | /* The GPIO is active low. */ |
| 115 | if (!s5p_gpio_get_value(&gpio_pt1->y1, RECMODE_GPIO)) |
| 116 | return 1; |
| 117 | |
| 118 | ec_events = google_chromeec_get_events_b(); |
| 119 | return !!(ec_events & |
| 120 | EC_HOST_EVENT_MASK(EC_HOST_EVENT_KEYBOARD_RECOVERY)); |
Ronald G. Minnich | 3faa2c7 | 2013-02-20 15:46:46 -0800 | [diff] [blame] | 121 | } |
| 122 | |
| 123 | int get_recovery_mode_from_vbnv(void) |
| 124 | { |
| 125 | return 1; |
| 126 | } |