blob: ac1afd991105918bba1cbdf41cc89e0b1bf66ce1 [file] [log] [blame]
Martin Roth0cd338e2016-07-29 14:07:30 -06001/*
jinkun.hong692a2c02015-01-07 08:57:48 +08002 * This file is part of the coreboot project.
3 *
4 * Copyright 2014 Rockchip 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.
jinkun.hong692a2c02015-01-07 08:57:48 +080014 */
15
16#include <boot/coreboot_tables.h>
17#include <console/console.h>
18#include <gpio.h>
19#include <string.h>
20#include <vendorcode/google/chromeos/chromeos.h>
21
22#include "board.h"
23
24#define GPIO_WP GPIO(7, A, 6)
25#define GPIO_POWER GPIO(0, A, 5)
Hung-Te Lin7049a8f2015-01-30 11:55:39 +080026#define GPIO_RECOVERY_SERVO GPIO(0, B, 1)
27#define GPIO_RECOVERY_PUSHKEY GPIO(7, B, 1)
Jonathan Dixon25805082015-04-01 14:02:34 -070028
jinkun.hong692a2c02015-01-07 08:57:48 +080029
30void setup_chromeos_gpios(void)
31{
32 gpio_input(GPIO_WP);
33 gpio_input(GPIO_POWER);
Hung-Te Lin7049a8f2015-01-30 11:55:39 +080034 gpio_input_pullup(GPIO_RECOVERY_SERVO);
35 gpio_input_pullup(GPIO_RECOVERY_PUSHKEY);
jinkun.hong692a2c02015-01-07 08:57:48 +080036}
37
38void fill_lb_gpios(struct lb_gpios *gpios)
39{
Julius Wernerc445b4f2016-03-31 17:27:05 -070040 struct lb_gpio chromeos_gpios[] = {
41 {GPIO_WP.raw, ACTIVE_LOW, gpio_get(GPIO_WP), "write protect"},
42 /* Note for early development, we want to support both servo
43 * and pushkey recovery buttons in firmware boot stages. */
44 {GPIO_RECOVERY_PUSHKEY.raw, ACTIVE_LOW,
45 !get_recovery_mode_switch(), "recovery"},
46 {GPIO_POWER.raw, ACTIVE_LOW, -1, "power"},
47 {-1, ACTIVE_HIGH, get_developer_mode_switch(), "developer"},
48 {GPIO_RESET.raw, ACTIVE_HIGH, -1, "reset"},
49 };
50 lb_add_gpios(gpios, chromeos_gpios, ARRAY_SIZE(chromeos_gpios));
jinkun.hong692a2c02015-01-07 08:57:48 +080051}
52
53int get_developer_mode_switch(void)
54{
Alexandru M Stan70cada22016-02-03 17:28:38 -080055 return 0;
jinkun.hong692a2c02015-01-07 08:57:48 +080056}
57
58int get_recovery_mode_switch(void)
59{
Hung-Te Lin7049a8f2015-01-30 11:55:39 +080060 // Both RECOVERY_SERVO and RECOVERY_PUSHKEY are low active.
61 return !(gpio_get(GPIO_RECOVERY_SERVO) &&
62 gpio_get(GPIO_RECOVERY_PUSHKEY));
jinkun.hong692a2c02015-01-07 08:57:48 +080063}
64
65int get_write_protect_state(void)
66{
67 return !gpio_get(GPIO_WP);
68}