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