Ronald G. Minnich | 3faa2c7 | 2013-02-20 15:46:46 -0800 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
Stefan Reinauer | 08dc357 | 2013-05-14 16:57:50 -0700 | [diff] [blame] | 4 | * Copyright 2013 Google Inc. |
Ronald G. Minnich | 3faa2c7 | 2013-02-20 15:46:46 -0800 | [diff] [blame] | 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. |
Ronald G. Minnich | 3faa2c7 | 2013-02-20 15:46:46 -0800 | [diff] [blame] | 14 | */ |
| 15 | |
Gabe Black | a5d914e4 | 2013-04-15 18:22:11 -0700 | [diff] [blame] | 16 | #include <boot/coreboot_tables.h> |
Ronald G. Minnich | 3faa2c7 | 2013-02-20 15:46:46 -0800 | [diff] [blame] | 17 | #include <console/console.h> |
Gabe Black | 7fa726a | 2013-04-15 18:09:15 -0700 | [diff] [blame] | 18 | #include <ec/google/chromeec/ec.h> |
| 19 | #include <ec/google/chromeec/ec_commands.h> |
Julius Werner | 1ed0c8c | 2014-10-20 13:16:29 -0700 | [diff] [blame] | 20 | #include <soc/cpu.h> |
| 21 | #include <soc/gpio.h> |
Ronald G. Minnich | 3faa2c7 | 2013-02-20 15:46:46 -0800 | [diff] [blame] | 22 | #include <string.h> |
| 23 | #include <vendorcode/google/chromeos/chromeos.h> |
Kyösti Mälkki | ab72809 | 2014-05-03 16:47:52 +0300 | [diff] [blame] | 24 | #include <bootmode.h> |
David Hendricks | d9b16f3 | 2013-03-06 19:16:10 -0800 | [diff] [blame] | 25 | |
Ronald G. Minnich | 3faa2c7 | 2013-02-20 15:46:46 -0800 | [diff] [blame] | 26 | void fill_lb_gpios(struct lb_gpios *gpios) |
| 27 | { |
Gabe Black | a5d914e4 | 2013-04-15 18:22:11 -0700 | [diff] [blame] | 28 | int count = 0; |
Ronald G. Minnich | 3faa2c7 | 2013-02-20 15:46:46 -0800 | [diff] [blame] | 29 | |
Gabe Black | a554e23 | 2013-04-15 16:25:02 -0700 | [diff] [blame] | 30 | /* Write Protect: active low */ |
Gabe Black | a5d914e4 | 2013-04-15 18:22:11 -0700 | [diff] [blame] | 31 | gpios->gpios[count].port = EXYNOS5_GPD1; |
| 32 | gpios->gpios[count].polarity = ACTIVE_LOW; |
Stefan Reinauer | dc006c1 | 2013-05-15 14:54:07 -0700 | [diff] [blame] | 33 | gpios->gpios[count].value = gpio_get_value(GPIO_D16); // WP_GPIO |
Gabe Black | a5d914e4 | 2013-04-15 18:22:11 -0700 | [diff] [blame] | 34 | strncpy((char *)gpios->gpios[count].name, "write protect", |
| 35 | GPIO_MAX_NAME_LENGTH); |
| 36 | count++; |
Ronald G. Minnich | 3faa2c7 | 2013-02-20 15:46:46 -0800 | [diff] [blame] | 37 | |
Gabe Black | fe3b024 | 2013-04-10 14:39:09 -0700 | [diff] [blame] | 38 | /* Recovery: active low */ |
Gabe Black | a5d914e4 | 2013-04-15 18:22:11 -0700 | [diff] [blame] | 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++; |
Ronald G. Minnich | 3faa2c7 | 2013-02-20 15:46:46 -0800 | [diff] [blame] | 45 | |
Gabe Black | a554e23 | 2013-04-15 16:25:02 -0700 | [diff] [blame] | 46 | /* Lid: active high */ |
Gabe Black | a5d914e4 | 2013-04-15 18:22:11 -0700 | [diff] [blame] | 47 | gpios->gpios[count].port = EXYNOS5_GPX3; |
| 48 | gpios->gpios[count].polarity = ACTIVE_HIGH; |
Stefan Reinauer | dc006c1 | 2013-05-15 14:54:07 -0700 | [diff] [blame] | 49 | gpios->gpios[count].value = gpio_get_value(GPIO_X35); // LID_GPIO |
Gabe Black | a5d914e4 | 2013-04-15 18:22:11 -0700 | [diff] [blame] | 50 | strncpy((char *)gpios->gpios[count].name, "lid", GPIO_MAX_NAME_LENGTH); |
| 51 | count++; |
Ronald G. Minnich | eeb3632 | 2013-02-27 10:12:03 -0800 | [diff] [blame] | 52 | |
David Hendricks | d9b16f3 | 2013-03-06 19:16:10 -0800 | [diff] [blame] | 53 | /* Power: virtual GPIO active low */ |
Gabe Black | 5cda308 | 2013-04-15 19:59:10 -0700 | [diff] [blame] | 54 | gpios->gpios[count].port = EXYNOS5_GPX1; |
Gabe Black | a5d914e4 | 2013-04-15 18:22:11 -0700 | [diff] [blame] | 55 | gpios->gpios[count].polarity = ACTIVE_LOW; |
Gabe Black | 5cda308 | 2013-04-15 19:59:10 -0700 | [diff] [blame] | 56 | gpios->gpios[count].value = |
Stefan Reinauer | dc006c1 | 2013-05-15 14:54:07 -0700 | [diff] [blame] | 57 | gpio_get_value(GPIO_X13); // POWER_GPIO |
Gabe Black | a5d914e4 | 2013-04-15 18:22:11 -0700 | [diff] [blame] | 58 | strncpy((char *)gpios->gpios[count].name, "power", |
| 59 | GPIO_MAX_NAME_LENGTH); |
| 60 | count++; |
Ronald G. Minnich | eeb3632 | 2013-02-27 10:12:03 -0800 | [diff] [blame] | 61 | |
| 62 | /* Developer: virtual GPIO active high */ |
Gabe Black | a5d914e4 | 2013-04-15 18:22:11 -0700 | [diff] [blame] | 63 | gpios->gpios[count].port = -1; |
| 64 | gpios->gpios[count].polarity = ACTIVE_HIGH; |
| 65 | gpios->gpios[count].value = get_developer_mode_switch(); |
| 66 | strncpy((char *)gpios->gpios[count].name, "developer", |
| 67 | GPIO_MAX_NAME_LENGTH); |
| 68 | count++; |
Ronald G. Minnich | 3faa2c7 | 2013-02-20 15:46:46 -0800 | [diff] [blame] | 69 | |
Gabe Black | a5d914e4 | 2013-04-15 18:22:11 -0700 | [diff] [blame] | 70 | gpios->size = sizeof(*gpios) + (count * sizeof(struct lb_gpio)); |
| 71 | gpios->count = count; |
| 72 | |
| 73 | 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] | 74 | } |
| 75 | |
| 76 | int get_developer_mode_switch(void) |
| 77 | { |
Gabe Black | a5d914e4 | 2013-04-15 18:22:11 -0700 | [diff] [blame] | 78 | return 0; |
Ronald G. Minnich | 3faa2c7 | 2013-02-20 15:46:46 -0800 | [diff] [blame] | 79 | } |
| 80 | |
| 81 | int get_recovery_mode_switch(void) |
| 82 | { |
Gabe Black | 7fa726a | 2013-04-15 18:09:15 -0700 | [diff] [blame] | 83 | uint32_t ec_events; |
Ronald G. Minnich | 3faa2c7 | 2013-02-20 15:46:46 -0800 | [diff] [blame] | 84 | |
Gabe Black | 7fa726a | 2013-04-15 18:09:15 -0700 | [diff] [blame] | 85 | /* The GPIO is active low. */ |
Stefan Reinauer | dc006c1 | 2013-05-15 14:54:07 -0700 | [diff] [blame] | 86 | if (!gpio_get_value(GPIO_Y10)) // RECMODE_GPIO |
Gabe Black | 7fa726a | 2013-04-15 18:09:15 -0700 | [diff] [blame] | 87 | return 1; |
| 88 | |
| 89 | ec_events = google_chromeec_get_events_b(); |
| 90 | return !!(ec_events & |
| 91 | EC_HOST_EVENT_MASK(EC_HOST_EVENT_KEYBOARD_RECOVERY)); |
Ronald G. Minnich | 3faa2c7 | 2013-02-20 15:46:46 -0800 | [diff] [blame] | 92 | } |
| 93 | |
Gabe Black | d29bf20 | 2013-09-12 06:23:51 -0700 | [diff] [blame] | 94 | int get_write_protect_state(void) |
Ronald G. Minnich | 3faa2c7 | 2013-02-20 15:46:46 -0800 | [diff] [blame] | 95 | { |
Gabe Black | d29bf20 | 2013-09-12 06:23:51 -0700 | [diff] [blame] | 96 | return !gpio_get_value(GPIO_D16); |
Ronald G. Minnich | 3faa2c7 | 2013-02-20 15:46:46 -0800 | [diff] [blame] | 97 | } |