blob: 9e67a4c1270ca09c9edfb99e083f798118d07039 [file] [log] [blame]
Ronald G. Minnich3faa2c72013-02-20 15:46:46 -08001/*
2 * This file is part of the coreboot project.
3 *
Stefan Reinauer08dc3572013-05-14 16:57:50 -07004 * Copyright 2013 Google Inc.
Ronald G. Minnich3faa2c72013-02-20 15:46:46 -08005 *
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 Blacka5d914e42013-04-15 18:22:11 -070020#include <boot/coreboot_tables.h>
Ronald G. Minnich3faa2c72013-02-20 15:46:46 -080021#include <console/console.h>
Gabe Black7fa726a2013-04-15 18:09:15 -070022#include <ec/google/chromeec/ec.h>
23#include <ec/google/chromeec/ec_commands.h>
Julius Werner1ed0c8c2014-10-20 13:16:29 -070024#include <soc/cpu.h>
25#include <soc/gpio.h>
Ronald G. Minnich3faa2c72013-02-20 15:46:46 -080026#include <string.h>
27#include <vendorcode/google/chromeos/chromeos.h>
Kyösti Mälkkiab728092014-05-03 16:47:52 +030028#include <bootmode.h>
David Hendricksd9b16f32013-03-06 19:16:10 -080029
Ronald G. Minnich3faa2c72013-02-20 15:46:46 -080030void fill_lb_gpios(struct lb_gpios *gpios)
31{
Gabe Blacka5d914e42013-04-15 18:22:11 -070032 int count = 0;
Ronald G. Minnich3faa2c72013-02-20 15:46:46 -080033
Gabe Blacka554e232013-04-15 16:25:02 -070034 /* Write Protect: active low */
Gabe Blacka5d914e42013-04-15 18:22:11 -070035 gpios->gpios[count].port = EXYNOS5_GPD1;
36 gpios->gpios[count].polarity = ACTIVE_LOW;
Stefan Reinauerdc006c12013-05-15 14:54:07 -070037 gpios->gpios[count].value = gpio_get_value(GPIO_D16); // WP_GPIO
Gabe Blacka5d914e42013-04-15 18:22:11 -070038 strncpy((char *)gpios->gpios[count].name, "write protect",
39 GPIO_MAX_NAME_LENGTH);
40 count++;
Ronald G. Minnich3faa2c72013-02-20 15:46:46 -080041
Gabe Blackfe3b0242013-04-10 14:39:09 -070042 /* Recovery: active low */
Gabe Blacka5d914e42013-04-15 18:22:11 -070043 gpios->gpios[count].port = -1;
44 gpios->gpios[count].polarity = ACTIVE_HIGH;
45 gpios->gpios[count].value = get_recovery_mode_switch();
46 strncpy((char *)gpios->gpios[count].name, "recovery",
47 GPIO_MAX_NAME_LENGTH);
48 count++;
Ronald G. Minnich3faa2c72013-02-20 15:46:46 -080049
Gabe Blacka554e232013-04-15 16:25:02 -070050 /* Lid: active high */
Gabe Blacka5d914e42013-04-15 18:22:11 -070051 gpios->gpios[count].port = EXYNOS5_GPX3;
52 gpios->gpios[count].polarity = ACTIVE_HIGH;
Stefan Reinauerdc006c12013-05-15 14:54:07 -070053 gpios->gpios[count].value = gpio_get_value(GPIO_X35); // LID_GPIO
Gabe Blacka5d914e42013-04-15 18:22:11 -070054 strncpy((char *)gpios->gpios[count].name, "lid", GPIO_MAX_NAME_LENGTH);
55 count++;
Ronald G. Minnicheeb36322013-02-27 10:12:03 -080056
David Hendricksd9b16f32013-03-06 19:16:10 -080057 /* Power: virtual GPIO active low */
Gabe Black5cda3082013-04-15 19:59:10 -070058 gpios->gpios[count].port = EXYNOS5_GPX1;
Gabe Blacka5d914e42013-04-15 18:22:11 -070059 gpios->gpios[count].polarity = ACTIVE_LOW;
Gabe Black5cda3082013-04-15 19:59:10 -070060 gpios->gpios[count].value =
Stefan Reinauerdc006c12013-05-15 14:54:07 -070061 gpio_get_value(GPIO_X13); // POWER_GPIO
Gabe Blacka5d914e42013-04-15 18:22:11 -070062 strncpy((char *)gpios->gpios[count].name, "power",
63 GPIO_MAX_NAME_LENGTH);
64 count++;
Ronald G. Minnicheeb36322013-02-27 10:12:03 -080065
66 /* Developer: virtual GPIO active high */
Gabe Blacka5d914e42013-04-15 18:22:11 -070067 gpios->gpios[count].port = -1;
68 gpios->gpios[count].polarity = ACTIVE_HIGH;
69 gpios->gpios[count].value = get_developer_mode_switch();
70 strncpy((char *)gpios->gpios[count].name, "developer",
71 GPIO_MAX_NAME_LENGTH);
72 count++;
Ronald G. Minnich3faa2c72013-02-20 15:46:46 -080073
Gabe Blacka5d914e42013-04-15 18:22:11 -070074 gpios->size = sizeof(*gpios) + (count * sizeof(struct lb_gpio));
75 gpios->count = count;
76
77 printk(BIOS_ERR, "Added %d GPIOS size %d\n", count, gpios->size);
Ronald G. Minnich3faa2c72013-02-20 15:46:46 -080078}
79
80int get_developer_mode_switch(void)
81{
Gabe Blacka5d914e42013-04-15 18:22:11 -070082 return 0;
Ronald G. Minnich3faa2c72013-02-20 15:46:46 -080083}
84
85int get_recovery_mode_switch(void)
86{
Gabe Black7fa726a2013-04-15 18:09:15 -070087 uint32_t ec_events;
Ronald G. Minnich3faa2c72013-02-20 15:46:46 -080088
Gabe Black7fa726a2013-04-15 18:09:15 -070089 /* The GPIO is active low. */
Stefan Reinauerdc006c12013-05-15 14:54:07 -070090 if (!gpio_get_value(GPIO_Y10)) // RECMODE_GPIO
Gabe Black7fa726a2013-04-15 18:09:15 -070091 return 1;
92
93 ec_events = google_chromeec_get_events_b();
94 return !!(ec_events &
95 EC_HOST_EVENT_MASK(EC_HOST_EVENT_KEYBOARD_RECOVERY));
Ronald G. Minnich3faa2c72013-02-20 15:46:46 -080096}
97
Gabe Blackd29bf202013-09-12 06:23:51 -070098int get_write_protect_state(void)
Ronald G. Minnich3faa2c72013-02-20 15:46:46 -080099{
Gabe Blackd29bf202013-09-12 06:23:51 -0700100 return !gpio_get_value(GPIO_D16);
Ronald G. Minnich3faa2c72013-02-20 15:46:46 -0800101}