blob: f6f13edc24bad98f5dacf213caa2af2d88b8e6a3 [file] [log] [blame]
Aaron Durbinc625d092013-10-04 16:00:07 -05001/*
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
20#include <string.h>
21#include <vendorcode/google/chromeos/chromeos.h>
22#include <arch/io.h>
23#include <device/device.h>
24#include <device/pci.h>
Aaron Durbin063c8732013-10-28 11:24:53 -050025#include <baytrail/gpio.h>
Aaron Durbinc625d092013-10-04 16:00:07 -050026
Aaron Durbin063c8732013-10-28 11:24:53 -050027#if CONFIG_EC_GOOGLE_CHROMEEC
28#include "ec.h"
29#include <ec/google/chromeec/ec.h>
30#endif
31
32/* The WP status pin lives on GPIO_SSUS_6 which is pad 36 in the SUS well. */
33#define WP_STATUS_PAD 36
Aaron Durbinc625d092013-10-04 16:00:07 -050034
35#ifndef __PRE_RAM__
36#include <boot/coreboot_tables.h>
37
38#define GPIO_COUNT 6
39#define ACTIVE_LOW 0
40#define ACTIVE_HIGH 1
41
Aaron Durbin063c8732013-10-28 11:24:53 -050042static int get_lid_switch(void)
43{
44#if CONFIG_EC_GOOGLE_CHROMEEC
45 u8 ec_switches = inb(EC_LPC_ADDR_MEMMAP + EC_MEMMAP_SWITCHES);
46
47 return !!(ec_switches & EC_SWITCH_LID_OPEN);
48#else
49 /* Default to force open. */
50 return 1;
51#endif
52}
53
54static void fill_lb_gpio(struct lb_gpio *gpio, int port, int polarity,
Aaron Durbinc625d092013-10-04 16:00:07 -050055 const char *name, int force)
56{
57 memset(gpio, 0, sizeof(*gpio));
Aaron Durbin063c8732013-10-28 11:24:53 -050058 gpio->port = port;
Aaron Durbinc625d092013-10-04 16:00:07 -050059 gpio->polarity = polarity;
60 if (force >= 0)
61 gpio->value = force;
62 strncpy((char *)gpio->name, name, GPIO_MAX_NAME_LENGTH);
63}
64
65void fill_lb_gpios(struct lb_gpios *gpios)
66{
67 struct lb_gpio *gpio;
68
69 gpios->size = sizeof(*gpios) + (GPIO_COUNT * sizeof(struct lb_gpio));
70 gpios->count = GPIO_COUNT;
71
72 gpio = gpios->gpios;
Aaron Durbin063c8732013-10-28 11:24:53 -050073 fill_lb_gpio(gpio++, -1, ACTIVE_HIGH, "write protect",
74 get_write_protect_state());
75 fill_lb_gpio(gpio++, -1, ACTIVE_HIGH, "recovery",
76 get_recovery_mode_switch());
77 fill_lb_gpio(gpio++, -1, ACTIVE_HIGH, "developer",
78 get_developer_mode_switch());
79 fill_lb_gpio(gpio++, -1, ACTIVE_HIGH, "lid", get_lid_switch());
80 fill_lb_gpio(gpio++, -1, ACTIVE_HIGH, "power", 0);
81 fill_lb_gpio(gpio++, -1, ACTIVE_HIGH, "oprom", oprom_is_loaded);
Aaron Durbinc625d092013-10-04 16:00:07 -050082}
83#endif
84
85int get_developer_mode_switch(void)
86{
Aaron Durbin063c8732013-10-28 11:24:53 -050087 return 0;
Aaron Durbinc625d092013-10-04 16:00:07 -050088}
89
90int get_recovery_mode_switch(void)
91{
Aaron Durbin063c8732013-10-28 11:24:53 -050092#if CONFIG_EC_GOOGLE_CHROMEEC
93 u8 ec_switches = inb(EC_LPC_ADDR_MEMMAP + EC_MEMMAP_SWITCHES);
94 u32 ec_events;
95
96 /* If a switch is set, we don't need to look at events. */
97 if (ec_switches & (EC_SWITCH_DEDICATED_RECOVERY))
98 return 1;
99
100 /* Else check if the EC has posted the keyboard recovery event. */
101 ec_events = google_chromeec_get_events_b();
102
103 return !!(ec_events &
104 EC_HOST_EVENT_MASK(EC_HOST_EVENT_KEYBOARD_RECOVERY));
105#else
106 return 0;
107#endif
Aaron Durbinc625d092013-10-04 16:00:07 -0500108}
109
110int get_write_protect_state(void)
111{
Aaron Durbin063c8732013-10-28 11:24:53 -0500112 /* WP is enabled when the pin is reading high. */
113 return ssus_get_gpio(WP_STATUS_PAD);
Aaron Durbinc625d092013-10-04 16:00:07 -0500114}
115