blob: 0c47458902f38444a8fa753286e6f798aa7879a2 [file] [log] [blame]
Ronald G. Minnich3faa2c72013-02-20 15:46:46 -08001/*
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 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>
Ronald G. Minnich3faa2c72013-02-20 15:46:46 -080024#include <string.h>
25#include <vendorcode/google/chromeos/chromeos.h>
Ronald G. Minnich3faa2c72013-02-20 15:46:46 -080026
David Hendricksd9b16f32013-03-06 19:16:10 -080027#include <cpu/samsung/exynos5250/cpu.h>
28#include <cpu/samsung/exynos5250/gpio.h>
29#include <cpu/samsung/exynos5-common/gpio.h>
30
Gabe Blacka5d914e42013-04-15 18:22:11 -070031enum {
32 ACTIVE_LOW = 0,
33 ACTIVE_HIGH = 1
34};
Ronald G. Minnich3faa2c72013-02-20 15:46:46 -080035
Gabe Blacka5d914e42013-04-15 18:22:11 -070036enum {
37 WP_GPIO = 6,
38 RECMODE_GPIO = 0,
Gabe Black5cda3082013-04-15 19:59:10 -070039 LID_GPIO = 5,
40 POWER_GPIO = 3
Gabe Blacka5d914e42013-04-15 18:22:11 -070041};
Ronald G. Minnich3faa2c72013-02-20 15:46:46 -080042
Gabe Black7fa726a2013-04-15 18:09:15 -070043static struct exynos5_gpio_part1 *gpio_pt1 =
44 (struct exynos5_gpio_part1 *)EXYNOS5_GPIO_PART1_BASE;
45static struct exynos5_gpio_part2 *gpio_pt2 =
46 (struct exynos5_gpio_part2 *)EXYNOS5_GPIO_PART2_BASE;
47
Ronald G. Minnich3faa2c72013-02-20 15:46:46 -080048void fill_lb_gpios(struct lb_gpios *gpios)
49{
Gabe Blacka5d914e42013-04-15 18:22:11 -070050 int count = 0;
Ronald G. Minnich3faa2c72013-02-20 15:46:46 -080051
Gabe Blacka554e232013-04-15 16:25:02 -070052 /* Write Protect: active low */
Gabe Blacka5d914e42013-04-15 18:22:11 -070053 gpios->gpios[count].port = EXYNOS5_GPD1;
54 gpios->gpios[count].polarity = ACTIVE_LOW;
55 gpios->gpios[count].value = s5p_gpio_get_value(&gpio_pt1->d1, WP_GPIO);
56 strncpy((char *)gpios->gpios[count].name, "write protect",
57 GPIO_MAX_NAME_LENGTH);
58 count++;
Ronald G. Minnich3faa2c72013-02-20 15:46:46 -080059
Gabe Blackfe3b0242013-04-10 14:39:09 -070060 /* Recovery: active low */
Gabe Blacka5d914e42013-04-15 18:22:11 -070061 gpios->gpios[count].port = -1;
62 gpios->gpios[count].polarity = ACTIVE_HIGH;
63 gpios->gpios[count].value = get_recovery_mode_switch();
64 strncpy((char *)gpios->gpios[count].name, "recovery",
65 GPIO_MAX_NAME_LENGTH);
66 count++;
Ronald G. Minnich3faa2c72013-02-20 15:46:46 -080067
Gabe Blacka554e232013-04-15 16:25:02 -070068 /* Lid: active high */
Gabe Blacka5d914e42013-04-15 18:22:11 -070069 gpios->gpios[count].port = EXYNOS5_GPX3;
70 gpios->gpios[count].polarity = ACTIVE_HIGH;
71 gpios->gpios[count].value = s5p_gpio_get_value(&gpio_pt2->x3, LID_GPIO);
72 strncpy((char *)gpios->gpios[count].name, "lid", GPIO_MAX_NAME_LENGTH);
73 count++;
Ronald G. Minnicheeb36322013-02-27 10:12:03 -080074
David Hendricksd9b16f32013-03-06 19:16:10 -080075 /* Power: virtual GPIO active low */
Gabe Black5cda3082013-04-15 19:59:10 -070076 gpios->gpios[count].port = EXYNOS5_GPX1;
Gabe Blacka5d914e42013-04-15 18:22:11 -070077 gpios->gpios[count].polarity = ACTIVE_LOW;
Gabe Black5cda3082013-04-15 19:59:10 -070078 gpios->gpios[count].value =
79 s5p_gpio_get_value(&gpio_pt2->x1, POWER_GPIO);
Gabe Blacka5d914e42013-04-15 18:22:11 -070080 strncpy((char *)gpios->gpios[count].name, "power",
81 GPIO_MAX_NAME_LENGTH);
82 count++;
Ronald G. Minnicheeb36322013-02-27 10:12:03 -080083
84 /* Developer: virtual GPIO active high */
Gabe Blacka5d914e42013-04-15 18:22:11 -070085 gpios->gpios[count].port = -1;
86 gpios->gpios[count].polarity = ACTIVE_HIGH;
87 gpios->gpios[count].value = get_developer_mode_switch();
88 strncpy((char *)gpios->gpios[count].name, "developer",
89 GPIO_MAX_NAME_LENGTH);
90 count++;
Ronald G. Minnich3faa2c72013-02-20 15:46:46 -080091
Gabe Blacka5d914e42013-04-15 18:22:11 -070092 gpios->size = sizeof(*gpios) + (count * sizeof(struct lb_gpio));
93 gpios->count = count;
94
95 printk(BIOS_ERR, "Added %d GPIOS size %d\n", count, gpios->size);
Ronald G. Minnich3faa2c72013-02-20 15:46:46 -080096
97}
98
99int get_developer_mode_switch(void)
100{
Gabe Blacka5d914e42013-04-15 18:22:11 -0700101 return 0;
Ronald G. Minnich3faa2c72013-02-20 15:46:46 -0800102}
103
104int get_recovery_mode_switch(void)
105{
Gabe Black7fa726a2013-04-15 18:09:15 -0700106 uint32_t ec_events;
Ronald G. Minnich3faa2c72013-02-20 15:46:46 -0800107
Gabe Black7fa726a2013-04-15 18:09:15 -0700108 /* The GPIO is active low. */
109 if (!s5p_gpio_get_value(&gpio_pt1->y1, RECMODE_GPIO))
110 return 1;
111
112 ec_events = google_chromeec_get_events_b();
113 return !!(ec_events &
114 EC_HOST_EVENT_MASK(EC_HOST_EVENT_KEYBOARD_RECOVERY));
Ronald G. Minnich3faa2c72013-02-20 15:46:46 -0800115}
116
117int get_recovery_mode_from_vbnv(void)
118{
119 return 1;
120}