blob: 7b64f1060410793aa24dd1dc36b2a812af764f31 [file] [log] [blame]
Aaron Durbinf6933a62012-10-30 09:09:39 -05001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2012 The Chromium OS Authors. All rights reserved.
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>
Aaron Durbinf6933a62012-10-30 09:09:39 -050023#include <device/device.h>
24#include <device/pci.h>
Aaron Durbinf6933a62012-10-30 09:09:39 -050025#include <southbridge/intel/lynxpoint/pch.h>
Aaron Durbin0160d762012-12-13 16:51:41 -060026#include <southbridge/intel/lynxpoint/gpio.h>
Aaron Durbinf6933a62012-10-30 09:09:39 -050027
28#ifndef __PRE_RAM__
29#include <boot/coreboot_tables.h>
Aaron Durbinf6933a62012-10-30 09:09:39 -050030
31#define GPIO_COUNT 6
32#define ACTIVE_LOW 0
33#define ACTIVE_HIGH 1
34
35void fill_lb_gpios(struct lb_gpios *gpios)
36{
37 device_t dev = dev_find_slot(0, PCI_DEVFN(0x1f,0));
38 u16 gpio_base = pci_read_config32(dev, GPIOBASE) & 0xfffe;
39
40 if (!gpio_base)
41 return;
42
Aaron Durbin0160d762012-12-13 16:51:41 -060043 u32 gp_lvl = inl(gpio_base + GP_LVL);
44 u32 gp_lvl2 = inl(gpio_base + GP_LVL2);
45 u32 gp_lvl3 = inl(gpio_base + GP_LVL3);
Aaron Durbinf6933a62012-10-30 09:09:39 -050046
47 gpios->size = sizeof(*gpios) + (GPIO_COUNT * sizeof(struct lb_gpio));
48 gpios->count = GPIO_COUNT;
49
Aaron Durbin0160d762012-12-13 16:51:41 -060050 /* Write Protect: GPIO22 */
51 gpios->gpios[0].port = 0;
Aaron Durbinf6933a62012-10-30 09:09:39 -050052 gpios->gpios[0].polarity = ACTIVE_LOW;
Aaron Durbin0160d762012-12-13 16:51:41 -060053 gpios->gpios[0].value = (gp_lvl >> 22) & 1;
Aaron Durbinf6933a62012-10-30 09:09:39 -050054 strncpy((char *)gpios->gpios[0].name,"write protect",
55 GPIO_MAX_NAME_LENGTH);
56
Aaron Durbin0160d762012-12-13 16:51:41 -060057 /* Recovery: GPIO69 - SV_DETECT - J8E3 (silkscreen: J8E2) */
58 gpios->gpios[1].port = 69;
59 gpios->gpios[1].polarity = ACTIVE_HIGH;
60 gpios->gpios[1].value = (gp_lvl3 >> (69-64)) & 1;
Aaron Durbinf6933a62012-10-30 09:09:39 -050061 strncpy((char *)gpios->gpios[1].name,"recovery", GPIO_MAX_NAME_LENGTH);
62
Aaron Durbin0160d762012-12-13 16:51:41 -060063 /* Developer: GPIO48 - BIOS_RESP - J8E4 (silkscreen: J8E3) */
64 gpios->gpios[2].port = 48;
Aaron Durbinf6933a62012-10-30 09:09:39 -050065 gpios->gpios[2].polarity = ACTIVE_LOW;
Aaron Durbin0160d762012-12-13 16:51:41 -060066 gpios->gpios[2].value = (gp_lvl2 >> (48-32)) & 1;
Aaron Durbinf6933a62012-10-30 09:09:39 -050067 strncpy((char *)gpios->gpios[2].name,"developer", GPIO_MAX_NAME_LENGTH);
68
69 /* Hard code the lid switch GPIO to open. */
70 gpios->gpios[3].port = -1;
71 gpios->gpios[3].polarity = ACTIVE_HIGH;
72 gpios->gpios[3].value = 1;
73 strncpy((char *)gpios->gpios[3].name,"lid", GPIO_MAX_NAME_LENGTH);
74
75 /* Power Button */
76 gpios->gpios[4].port = -1;
77 gpios->gpios[4].polarity = ACTIVE_HIGH;
78 gpios->gpios[4].value = 0;
79 strncpy((char *)gpios->gpios[4].name,"power", GPIO_MAX_NAME_LENGTH);
80
81 /* Did we load the VGA option ROM? */
82 gpios->gpios[5].port = -1;
83 gpios->gpios[5].polarity = ACTIVE_HIGH;
Kyösti Mälkkiab56b3b2013-11-28 16:44:51 +020084 gpios->gpios[5].value = gfx_get_init_done();
Aaron Durbinf6933a62012-10-30 09:09:39 -050085 strncpy((char *)gpios->gpios[5].name,"oprom", GPIO_MAX_NAME_LENGTH);
86}
87#endif
88
89int get_developer_mode_switch(void)
90{
91 device_t dev;
92#ifdef __PRE_RAM__
93 dev = PCI_DEV(0, 0x1f, 0);
94#else
95 dev = dev_find_slot(0, PCI_DEVFN(0x1f,0));
96#endif
97 u16 gpio_base = pci_read_config32(dev, GPIOBASE) & 0xfffe;
Aaron Durbin0160d762012-12-13 16:51:41 -060098 u32 gp_lvl2 = inl(gpio_base + GP_LVL2);
Aaron Durbinf6933a62012-10-30 09:09:39 -050099
Aaron Durbin0160d762012-12-13 16:51:41 -0600100 /*
101 * Developer: GPIO48, Connected to J8E4, however the silkscreen says
102 * J8E3. The jumper is active low.
103 */
104 return !((gp_lvl2 >> (48-32)) & 1);
Aaron Durbinf6933a62012-10-30 09:09:39 -0500105}
106
107int get_recovery_mode_switch(void)
108{
109 device_t dev;
110#ifdef __PRE_RAM__
111 dev = PCI_DEV(0, 0x1f, 0);
112#else
113 dev = dev_find_slot(0, PCI_DEVFN(0x1f,0));
114#endif
115 u16 gpio_base = pci_read_config32(dev, GPIOBASE) & 0xfffe;
Aaron Durbin0160d762012-12-13 16:51:41 -0600116 u32 gp_lvl3 = inl(gpio_base + GP_LVL3);
Aaron Durbinf6933a62012-10-30 09:09:39 -0500117
Aaron Durbin0160d762012-12-13 16:51:41 -0600118 /*
119 * Recovery: GPIO69, Connected to J8E3, however the silkscreen says
120 * J8E2. The jump is active high.
121 */
122 return (gp_lvl3 >> (69-64)) & 1;
Aaron Durbinf6933a62012-10-30 09:09:39 -0500123}
124
Aaron Durbin0df4de92013-03-01 17:38:59 -0600125int get_write_protect_state(void)
126{
127 return 0;
128}
129