blob: c9450ec805c9310294722eda79d5a91e7a01914a [file] [log] [blame]
Katie Roberts-Hoffmanb262c722014-10-23 19:14:30 -07001/*
2 * 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.
Katie Roberts-Hoffmanb262c722014-10-23 19:14:30 -070014 */
15
16#include <boot/coreboot_tables.h>
17#include <console/console.h>
18#include <ec/google/chromeec/ec.h>
19#include <ec/google/chromeec/ec_commands.h>
20#include <gpio.h>
21#include <string.h>
22#include <vendorcode/google/chromeos/chromeos.h>
23
Julius Werner36fd82d2014-11-20 17:02:17 -080024#include "board.h"
25
Katie Roberts-Hoffmanb262c722014-10-23 19:14:30 -070026#define GPIO_WP GPIO(7, A, 6)
Julius Werner0353c9f2014-11-06 12:51:24 -080027#define GPIO_LID GPIO(0, A, 6)
Katie Roberts-Hoffmanb262c722014-10-23 19:14:30 -070028#define GPIO_POWER GPIO(0, A, 5)
29#define GPIO_RECOVERY GPIO(0, B, 1)
Julius Werner36fd82d2014-11-20 17:02:17 -080030#define GPIO_ECINRW GPIO(0, A, 7)
Julius Werner9ac9ac632015-04-24 17:30:36 -070031#define GPIO_ECIRQ GPIO(7, A, 7)
Katie Roberts-Hoffmanb262c722014-10-23 19:14:30 -070032
33void setup_chromeos_gpios(void)
34{
35 gpio_input(GPIO_WP);
36 gpio_input_pullup(GPIO_LID);
37 gpio_input(GPIO_POWER);
38 gpio_input_pullup(GPIO_RECOVERY);
Julius Werner9ac9ac632015-04-24 17:30:36 -070039 gpio_input(GPIO_ECIRQ);
Katie Roberts-Hoffmanb262c722014-10-23 19:14:30 -070040}
41
42void fill_lb_gpios(struct lb_gpios *gpios)
43{
44 int count = 0;
45
46 /* Write Protect: active low */
47 gpios->gpios[count].port = GPIO_WP.raw;
48 gpios->gpios[count].polarity = ACTIVE_LOW;
49 gpios->gpios[count].value = gpio_get(GPIO_WP);
50 strncpy((char *)gpios->gpios[count].name, "write protect",
51 GPIO_MAX_NAME_LENGTH);
52 count++;
53
54 /* Recovery: active low */
55 gpios->gpios[count].port = GPIO_RECOVERY.raw;
56 gpios->gpios[count].polarity = ACTIVE_HIGH;
57 gpios->gpios[count].value = get_recovery_mode_switch();
58 strncpy((char *)gpios->gpios[count].name, "recovery",
59 GPIO_MAX_NAME_LENGTH);
60 count++;
61
62 /* Lid: active high */
63 gpios->gpios[count].port = GPIO_LID.raw;
64 gpios->gpios[count].polarity = ACTIVE_HIGH;
Julius Werner36fd82d2014-11-20 17:02:17 -080065 gpios->gpios[count].value = -1;
Katie Roberts-Hoffmanb262c722014-10-23 19:14:30 -070066 strncpy((char *)gpios->gpios[count].name, "lid", GPIO_MAX_NAME_LENGTH);
67 count++;
68
69 /* Power:GPIO active high */
70 gpios->gpios[count].port = GPIO_POWER.raw;
Julius Werner50168202014-11-10 21:37:12 -080071 gpios->gpios[count].polarity = ACTIVE_LOW;
Julius Werner36fd82d2014-11-20 17:02:17 -080072 gpios->gpios[count].value = -1;
Katie Roberts-Hoffmanb262c722014-10-23 19:14:30 -070073 strncpy((char *)gpios->gpios[count].name, "power",
74 GPIO_MAX_NAME_LENGTH);
75 count++;
76
77 /* Developer: GPIO active high */
78 gpios->gpios[count].port = -1;
79 gpios->gpios[count].polarity = ACTIVE_HIGH;
80 gpios->gpios[count].value = get_developer_mode_switch();
81 strncpy((char *)gpios->gpios[count].name, "developer",
82 GPIO_MAX_NAME_LENGTH);
83 count++;
84
Julius Werner36fd82d2014-11-20 17:02:17 -080085 /* EC in RW: GPIO active high */
86 gpios->gpios[count].port = GPIO_ECINRW.raw;
87 gpios->gpios[count].polarity = ACTIVE_HIGH;
88 gpios->gpios[count].value = -1;
89 strncpy((char *)gpios->gpios[count].name, "EC in RW",
90 GPIO_MAX_NAME_LENGTH);
91 count++;
92
Julius Werner9ac9ac632015-04-24 17:30:36 -070093 /* EC interrupt: GPIO active high */
94 gpios->gpios[count].port = GPIO_ECIRQ.raw;
95 gpios->gpios[count].polarity = ACTIVE_LOW;
96 gpios->gpios[count].value = -1;
97 strncpy((char *)gpios->gpios[count].name, "EC interrupt",
98 GPIO_MAX_NAME_LENGTH);
99 count++;
100
Julius Werner36fd82d2014-11-20 17:02:17 -0800101 /* Reset: GPIO active high (output) */
102 gpios->gpios[count].port = GPIO_RESET.raw;
103 gpios->gpios[count].polarity = ACTIVE_HIGH;
104 gpios->gpios[count].value = -1;
105 strncpy((char *)gpios->gpios[count].name, "reset",
106 GPIO_MAX_NAME_LENGTH);
107 count++;
108
Julius Werner1f0569f2015-01-21 15:28:07 -0800109 /* Backlight: GPIO active high (output) */
110 gpios->gpios[count].port = GPIO_BACKLIGHT.raw;
111 gpios->gpios[count].polarity = ACTIVE_HIGH;
112 gpios->gpios[count].value = -1;
113 strncpy((char *)gpios->gpios[count].name, "backlight",
114 GPIO_MAX_NAME_LENGTH);
115 count++;
116
Katie Roberts-Hoffmanb262c722014-10-23 19:14:30 -0700117 gpios->size = sizeof(*gpios) + (count * sizeof(struct lb_gpio));
118 gpios->count = count;
119
120 printk(BIOS_ERR, "Added %d GPIOS size %d\n", count, gpios->size);
121}
122
123int get_developer_mode_switch(void)
124{
125 return 0;
126}
127
128int get_recovery_mode_switch(void)
129{
130 uint32_t ec_events;
131
132 /* The GPIO is active low. */
133 if (!gpio_get(GPIO_RECOVERY))
134 return 1;
135
136 ec_events = google_chromeec_get_events_b();
137 return !!(ec_events &
138 EC_HOST_EVENT_MASK(EC_HOST_EVENT_KEYBOARD_RECOVERY));
139}
140
141int get_write_protect_state(void)
142{
143 return !gpio_get(GPIO_WP);
144}