blob: e782986cf408b1134579ccd73b1409ab11250ad2 [file] [log] [blame]
Gabe Blackd3163ab2013-05-16 05:53:40 -07001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright 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.
Gabe Blackd3163ab2013-05-16 05:53:40 -070014 */
15
16#include <boot/coreboot_tables.h>
Julius Werner80af4422014-10-20 13:18:56 -070017#include <bootmode.h>
Gabe Blackd3163ab2013-05-16 05:53:40 -070018#include <console/console.h>
19#include <ec/google/chromeec/ec.h>
20#include <ec/google/chromeec/ec_commands.h>
Julius Werner80af4422014-10-20 13:18:56 -070021#include <soc/cpu.h>
22#include <soc/gpio.h>
Gabe Blackd3163ab2013-05-16 05:53:40 -070023#include <string.h>
24#include <vendorcode/google/chromeos/chromeos.h>
Gabe Blackd3163ab2013-05-16 05:53:40 -070025
Gabe Blackd3163ab2013-05-16 05:53:40 -070026void fill_lb_gpios(struct lb_gpios *gpios)
27{
28 int count = 0;
29
30 /* Write Protect: active low */
Gabe Black63bb6102013-06-19 03:29:45 -070031 gpios->gpios[count].port = EXYNOS5_GPX3;
Gabe Blackd3163ab2013-05-16 05:53:40 -070032 gpios->gpios[count].polarity = ACTIVE_LOW;
Gabe Black63bb6102013-06-19 03:29:45 -070033 gpios->gpios[count].value = gpio_get_value(GPIO_X30); // WP_GPIO
Gabe Blackd3163ab2013-05-16 05:53:40 -070034 strncpy((char *)gpios->gpios[count].name, "write protect",
35 GPIO_MAX_NAME_LENGTH);
36 count++;
37
38 /* Recovery: active low */
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++;
45
46 /* Lid: active high */
47 gpios->gpios[count].port = EXYNOS5_GPX3;
48 gpios->gpios[count].polarity = ACTIVE_HIGH;
Gabe Black63bb6102013-06-19 03:29:45 -070049 gpios->gpios[count].value = gpio_get_value(GPIO_X34); // LID_GPIO
Gabe Blackd3163ab2013-05-16 05:53:40 -070050 strncpy((char *)gpios->gpios[count].name, "lid", GPIO_MAX_NAME_LENGTH);
51 count++;
52
53 /* Power: virtual GPIO active low */
54 gpios->gpios[count].port = EXYNOS5_GPX1;
55 gpios->gpios[count].polarity = ACTIVE_LOW;
56 gpios->gpios[count].value =
Gabe Black63bb6102013-06-19 03:29:45 -070057 gpio_get_value(GPIO_X12); // POWER_GPIO
Gabe Blackd3163ab2013-05-16 05:53:40 -070058 strncpy((char *)gpios->gpios[count].name, "power",
59 GPIO_MAX_NAME_LENGTH);
60 count++;
61
Gabe Blackd3163ab2013-05-16 05:53:40 -070062 gpios->size = sizeof(*gpios) + (count * sizeof(struct lb_gpio));
63 gpios->count = count;
64
65 printk(BIOS_ERR, "Added %d GPIOS size %d\n", count, gpios->size);
66}
67
Gabe Blackd3163ab2013-05-16 05:53:40 -070068int get_recovery_mode_switch(void)
69{
Furquan Shaikh8788fd62017-11-20 20:28:18 -080070 uint64_t ec_events;
Gabe Blackd3163ab2013-05-16 05:53:40 -070071
72 /* The GPIO is active low. */
Gabe Black63bb6102013-06-19 03:29:45 -070073 if (!gpio_get_value(GPIO_X07)) // RECMODE_GPIO
Gabe Blackd3163ab2013-05-16 05:53:40 -070074 return 1;
75
76 ec_events = google_chromeec_get_events_b();
77 return !!(ec_events &
78 EC_HOST_EVENT_MASK(EC_HOST_EVENT_KEYBOARD_RECOVERY));
79}
80
Stefan Reinaueraaaf6892013-08-29 15:57:11 -070081int get_write_protect_state(void)
Gabe Blackd3163ab2013-05-16 05:53:40 -070082{
Gabe Blackd29bf202013-09-12 06:23:51 -070083 return !gpio_get_value(GPIO_X30);
Gabe Blackd3163ab2013-05-16 05:53:40 -070084}