blob: 8b4282853318349fcc8cc5657eef56119195954a [file] [log] [blame]
Stefan Reinauer49428d82013-02-21 15:48:37 -08001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2011 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.
Stefan Reinauer49428d82013-02-21 15:48:37 -080014 */
15
16#include <string.h>
Kyösti Mälkkiab728092014-05-03 16:47:52 +030017#include <bootmode.h>
Stefan Reinauer49428d82013-02-21 15:48:37 -080018#include <arch/io.h>
Stefan Reinauer49428d82013-02-21 15:48:37 -080019#include <device/device.h>
20#include <device/pci.h>
Stefan Reinauer49428d82013-02-21 15:48:37 -080021#include <southbridge/intel/bd82x6x/pch.h>
22#include "ec.h"
23#include <ec/google/chromeec/ec.h>
24
25#ifndef __PRE_RAM__
26#include <boot/coreboot_tables.h>
Stefan Reinauer49428d82013-02-21 15:48:37 -080027
28#define GPIO_COUNT 6
Stefan Reinauer49428d82013-02-21 15:48:37 -080029
Stefan Reinauer49428d82013-02-21 15:48:37 -080030void fill_lb_gpios(struct lb_gpios *gpios)
31{
Stefan Reinauer49428d82013-02-21 15:48:37 -080032 gpios->size = sizeof(*gpios) + (GPIO_COUNT * sizeof(struct lb_gpio));
33 gpios->count = GPIO_COUNT;
34
35 /* Write Protect: GPIO57 = PCH_SPI_WP_D */
36 gpios->gpios[0].port = 57;
37 gpios->gpios[0].polarity = ACTIVE_HIGH;
Patrick Georgi2f31ef12015-06-30 12:49:50 +020038 gpios->gpios[0].value = get_write_protect_state();
Stefan Reinauer49428d82013-02-21 15:48:37 -080039 strncpy((char *)gpios->gpios[0].name,"write protect",
40 GPIO_MAX_NAME_LENGTH);
41 /* Recovery: the "switch" comes from the EC */
42 gpios->gpios[1].port = -1; /* Indicate that this is a pseudo GPIO */
43 gpios->gpios[1].polarity = ACTIVE_HIGH;
44 gpios->gpios[1].value = get_recovery_mode_switch();
45 strncpy((char *)gpios->gpios[1].name,"recovery", GPIO_MAX_NAME_LENGTH);
46
47 /* Lid: the "switch" comes from the EC */
48 gpios->gpios[2].port = -1;
49 gpios->gpios[2].polarity = ACTIVE_HIGH;
50 gpios->gpios[2].value = get_lid_switch();
51 strncpy((char *)gpios->gpios[2].name,"lid", GPIO_MAX_NAME_LENGTH);
52
53 /* Power Button: hard-coded as not pressed; we'll detect later presses
54 * via SMI. */
55 gpios->gpios[3].port = -1;
56 gpios->gpios[3].polarity = ACTIVE_HIGH;
57 gpios->gpios[3].value = 0;
58 strncpy((char *)gpios->gpios[3].name,"power", GPIO_MAX_NAME_LENGTH);
59
60 /* Developer: a tricky case on Link, there is no switch */
61 gpios->gpios[4].port = -1; /* Indicate that this is a pseudo GPIO */
62 gpios->gpios[4].polarity = ACTIVE_HIGH;
63 gpios->gpios[4].value = get_developer_mode_switch();
64 strncpy((char *)gpios->gpios[4].name,"developer", GPIO_MAX_NAME_LENGTH);
65
66 /* Did we load the VGA Option ROM? */
67 gpios->gpios[5].port = -1; /* Indicate that this is a pseudo GPIO */
68 gpios->gpios[5].polarity = ACTIVE_HIGH;
Kyösti Mälkkiab56b3b2013-11-28 16:44:51 +020069 gpios->gpios[5].value = gfx_get_init_done();
Stefan Reinauer49428d82013-02-21 15:48:37 -080070 strncpy((char *)gpios->gpios[5].name,"oprom", GPIO_MAX_NAME_LENGTH);
71}
72#endif
73
Patrick Georgi2f31ef12015-06-30 12:49:50 +020074int get_write_protect_state(void)
75{
76 device_t dev;
77#ifdef __PRE_RAM__
78 dev = PCI_DEV(0, 0x1f, 0);
79#else
80 dev = dev_find_slot(0, PCI_DEVFN(0x1f, 0));
81#endif
82 u16 gpio_base = pci_read_config32(dev, GPIOBASE) & 0xfffe;
83 //u16 gen_pmcon_1 = pci_read_config32(dev, GEN_PMCON_1);
84
85 if (!gpio_base)
86 return -1;
87
88 u32 gp_lvl2 = inl(gpio_base + 0x38);
89
90 return (gp_lvl2 >> (57 - 32)) & 1;
91}
92
Patrick Georgi08b87852015-05-28 11:59:33 +020093int get_lid_switch(void)
94{
95 u8 ec_switches = inb(EC_LPC_ADDR_MEMMAP + EC_MEMMAP_SWITCHES);
96
97 return !!(ec_switches & EC_SWITCH_LID_OPEN);
98}
99
Stefan Reinauer49428d82013-02-21 15:48:37 -0800100/* The dev-switch is virtual on Link (and so handled elsewhere). */
101int get_developer_mode_switch(void)
102{
103 return 0;
104}
105
106/* There are actually two recovery switches. One is the magic keyboard chord,
107 * the other is driven by Servo. */
108int get_recovery_mode_switch(void)
109{
110 u8 ec_switches = inb(EC_LPC_ADDR_MEMMAP + EC_MEMMAP_SWITCHES);
111 u32 ec_events;
112
113 /* If a switch is set, we don't need to look at events. */
Duncan Laurie433432b2013-06-03 10:38:22 -0700114 if (ec_switches & (EC_SWITCH_DEDICATED_RECOVERY))
Stefan Reinauer49428d82013-02-21 15:48:37 -0800115 return 1;
116
117 /* Else check if the EC has posted the keyboard recovery event. */
118 ec_events = google_chromeec_get_events_b();
119
120 return !!(ec_events &
121 EC_HOST_EVENT_MASK(EC_HOST_EVENT_KEYBOARD_RECOVERY));
122}