blob: 213fd858f13f179dc81d03caf453b0cace4df001 [file] [log] [blame]
Aaron Durbin2b0b7642014-08-05 14:03:17 -05001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright 2014 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.
Aaron Durbin2b0b7642014-08-05 14:03:17 -050014 */
15
Furquan Shaikhad73c452014-11-10 23:22:01 -080016#include <boardid.h>
Aaron Durbin2b0b7642014-08-05 14:03:17 -050017#include <boot/coreboot_tables.h>
18#include <console/console.h>
19#include <ec/google/chromeec/ec.h>
20#include <ec/google/chromeec/ec_commands.h>
21#include <string.h>
22#include <vendorcode/google/chromeos/chromeos.h>
Julius Werner96195ee2014-10-20 13:25:21 -070023
Aaron Durbin45a1c942014-08-29 10:48:27 -050024#include "gpio.h"
Aaron Durbin2b0b7642014-08-05 14:03:17 -050025
Furquan Shaikhad73c452014-11-10 23:22:01 -080026static inline uint32_t get_pwr_btn_polarity(void)
27{
28 if (board_id() < BOARD_ID_PROTO_3)
29 return ACTIVE_HIGH;
30
31 return ACTIVE_LOW;
32}
33
Aaron Durbin2b0b7642014-08-05 14:03:17 -050034void fill_lb_gpios(struct lb_gpios *gpios)
35{
36 int count = 0;
37
38 /* Write Protect: active low */
Julius Werner36fd82d2014-11-20 17:02:17 -080039 gpios->gpios[count].port = WRITE_PROTECT_L;
Aaron Durbin2b0b7642014-08-05 14:03:17 -050040 gpios->gpios[count].polarity = ACTIVE_LOW;
Julius Wernereaa9c452014-09-24 15:40:49 -070041 gpios->gpios[count].value = gpio_get(WRITE_PROTECT_L);
Aaron Durbin2b0b7642014-08-05 14:03:17 -050042 strncpy((char *)gpios->gpios[count].name, "write protect",
43 GPIO_MAX_NAME_LENGTH);
44 count++;
45
46 /* Recovery: active high */
47 gpios->gpios[count].port = -1;
48 gpios->gpios[count].polarity = ACTIVE_HIGH;
49 gpios->gpios[count].value = get_recovery_mode_switch();
50 strncpy((char *)gpios->gpios[count].name, "recovery",
51 GPIO_MAX_NAME_LENGTH);
52 count++;
53
54 /* TODO(adurbin): add lid switch */
55
Furquan Shaikhad73c452014-11-10 23:22:01 -080056 /* Power: active low / high depending on board id */
Julius Werner36fd82d2014-11-20 17:02:17 -080057 gpios->gpios[count].port = POWER_BUTTON;
Furquan Shaikhad73c452014-11-10 23:22:01 -080058 gpios->gpios[count].polarity = get_pwr_btn_polarity();
Julius Werner36fd82d2014-11-20 17:02:17 -080059 gpios->gpios[count].value = -1;
Aaron Durbin2b0b7642014-08-05 14:03:17 -050060 strncpy((char *)gpios->gpios[count].name, "power",
61 GPIO_MAX_NAME_LENGTH);
62 count++;
63
64 /* Developer: virtual GPIO active high */
65 gpios->gpios[count].port = -1;
66 gpios->gpios[count].polarity = ACTIVE_HIGH;
67 gpios->gpios[count].value = get_developer_mode_switch();
68 strncpy((char *)gpios->gpios[count].name, "developer",
69 GPIO_MAX_NAME_LENGTH);
70 count++;
71
Julius Werner36fd82d2014-11-20 17:02:17 -080072 /* EC in RW: active high */
73 gpios->gpios[count].port = EC_IN_RW;
74 gpios->gpios[count].polarity = ACTIVE_HIGH;
75 gpios->gpios[count].value = -1;
76 strncpy((char *)gpios->gpios[count].name, "EC in RW",
77 GPIO_MAX_NAME_LENGTH);
78 count++;
79
80 /* Reset: active low (output) */
81 gpios->gpios[count].port = AP_SYS_RESET_L;
82 gpios->gpios[count].polarity = ACTIVE_LOW;
83 gpios->gpios[count].value = -1;
84 strncpy((char *)gpios->gpios[count].name, "reset",
85 GPIO_MAX_NAME_LENGTH);
86 count++;
87
Aaron Durbin2b0b7642014-08-05 14:03:17 -050088 gpios->size = sizeof(*gpios) + (count * sizeof(struct lb_gpio));
89 gpios->count = count;
90
91 printk(BIOS_ERR, "Added %d GPIOS size %d\n", count, gpios->size);
92}
93
94int get_developer_mode_switch(void)
95{
96 return 0;
97}
98
99int get_recovery_mode_switch(void)
100{
101 uint32_t ec_events;
102
103 ec_events = google_chromeec_get_events_b();
104 return !!(ec_events &
105 EC_HOST_EVENT_MASK(EC_HOST_EVENT_KEYBOARD_RECOVERY));
106}
107
108int get_write_protect_state(void)
109{
Julius Wernereaa9c452014-09-24 15:40:49 -0700110 return !gpio_get(WRITE_PROTECT_L);
Aaron Durbin2b0b7642014-08-05 14:03:17 -0500111}