blob: 2194973fb5f00a94a22b7a9360522c41d588b5c5 [file] [log] [blame]
Stefan Reinauer6651da32012-04-27 23:16:30 +02001/*
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>
Stefan Reinauer6651da32012-04-27 23:16:30 +020023#include <device/device.h>
24#include <device/pci.h>
Stefan Reinauer6651da32012-04-27 23:16:30 +020025#include <southbridge/intel/bd82x6x/pch.h>
26
27#ifndef __PRE_RAM__
Stefan Reinauer3e4e3032013-03-20 14:08:04 -070028#include <boot/coreboot_tables.h>
Stefan Reinauer6651da32012-04-27 23:16:30 +020029
Duncan Lauriec64947b2012-10-01 13:31:25 -070030#define GPIO_COUNT 6
Stefan Reinauer6651da32012-04-27 23:16:30 +020031#define ACTIVE_LOW 0
32#define ACTIVE_HIGH 1
33
34void fill_lb_gpios(struct lb_gpios *gpios)
35{
36 device_t dev = dev_find_slot(0, PCI_DEVFN(0x1f,0));
37 u16 gpio_base = pci_read_config32(dev, GPIOBASE) & 0xfffe;
Stefan Reinauer6651da32012-04-27 23:16:30 +020038
39 if (!gpio_base)
40 return;
41
Stefan Reinauer6651da32012-04-27 23:16:30 +020042 u32 gp_lvl = inl(gpio_base + 0x0c);
Stefan Reinauer6651da32012-04-27 23:16:30 +020043 u32 gp_lvl2 = inl(gpio_base + 0x38);
Gabe Blackf40a2592012-03-29 18:04:56 -070044 /* u32 gp_lvl3 = inl(gpio_base + 0x48); */
Stefan Reinauer6651da32012-04-27 23:16:30 +020045
46 gpios->size = sizeof(*gpios) + (GPIO_COUNT * sizeof(struct lb_gpio));
47 gpios->count = GPIO_COUNT;
48
Gabe Blackf40a2592012-03-29 18:04:56 -070049 /* Write Protect: GPIO48 */
50 gpios->gpios[0].port = 48;
51 gpios->gpios[0].polarity = ACTIVE_LOW;
52 gpios->gpios[0].value = (gp_lvl2 >> (48-32)) & 1;
Stefan Reinauer6651da32012-04-27 23:16:30 +020053 strncpy((char *)gpios->gpios[0].name,"write protect",
54 GPIO_MAX_NAME_LENGTH);
55
Gabe Blackf40a2592012-03-29 18:04:56 -070056 /* Recovery: GPIO22 */
57 gpios->gpios[1].port = 22;
Stefan Reinauer6651da32012-04-27 23:16:30 +020058 gpios->gpios[1].polarity = ACTIVE_LOW;
Gabe Blackf40a2592012-03-29 18:04:56 -070059 gpios->gpios[1].value = (gp_lvl >> 22) & 1;
Stefan Reinauer6651da32012-04-27 23:16:30 +020060 strncpy((char *)gpios->gpios[1].name,"recovery", GPIO_MAX_NAME_LENGTH);
61
Gabe Blackf40a2592012-03-29 18:04:56 -070062 /* Developer: GPIO57 */
63 gpios->gpios[2].port = 57;
Duncan Lauriec64947b2012-10-01 13:31:25 -070064 gpios->gpios[2].polarity = ACTIVE_LOW;
Gabe Blackf40a2592012-03-29 18:04:56 -070065 gpios->gpios[2].value = (gp_lvl2 >> (57-32)) & 1;
Stefan Reinauer6651da32012-04-27 23:16:30 +020066 strncpy((char *)gpios->gpios[2].name,"developer", GPIO_MAX_NAME_LENGTH);
67
68 /* Hard code the lid switch GPIO to open. */
Duncan Lauriec64947b2012-10-01 13:31:25 -070069 gpios->gpios[3].port = -1;
Stefan Reinauer6651da32012-04-27 23:16:30 +020070 gpios->gpios[3].polarity = ACTIVE_HIGH;
71 gpios->gpios[3].value = 1;
72 strncpy((char *)gpios->gpios[3].name,"lid", GPIO_MAX_NAME_LENGTH);
73
74 /* Power Button */
Duncan Lauriec64947b2012-10-01 13:31:25 -070075 gpios->gpios[4].port = -1;
76 gpios->gpios[4].polarity = ACTIVE_HIGH;
77 gpios->gpios[4].value = 0;
Stefan Reinauer6651da32012-04-27 23:16:30 +020078 strncpy((char *)gpios->gpios[4].name,"power", GPIO_MAX_NAME_LENGTH);
Duncan Lauriec64947b2012-10-01 13:31:25 -070079
80 /* Did we load the VGA option ROM? */
81 gpios->gpios[5].port = -1;
82 gpios->gpios[5].polarity = ACTIVE_HIGH;
Kyösti Mälkkiab56b3b2013-11-28 16:44:51 +020083 gpios->gpios[5].value = gfx_get_init_done();
Duncan Lauriec64947b2012-10-01 13:31:25 -070084 strncpy((char *)gpios->gpios[5].name,"oprom", GPIO_MAX_NAME_LENGTH);
Stefan Reinauer6651da32012-04-27 23:16:30 +020085}
86#endif
87
88int get_developer_mode_switch(void)
89{
Stefan Reinauer6651da32012-04-27 23:16:30 +020090 device_t dev;
91#ifdef __PRE_RAM__
92 dev = PCI_DEV(0, 0x1f, 0);
93#else
94 dev = dev_find_slot(0, PCI_DEVFN(0x1f,0));
95#endif
96 u16 gpio_base = pci_read_config32(dev, GPIOBASE) & 0xfffe;
Gabe Blackf40a2592012-03-29 18:04:56 -070097 u32 gp_lvl2 = inl(gpio_base + 0x38);
Stefan Reinauer6651da32012-04-27 23:16:30 +020098
Gabe Blackf40a2592012-03-29 18:04:56 -070099 /* Developer: GPIO17, active high */
100 return (gp_lvl2 >> (57-32)) & 1;
Stefan Reinauer6651da32012-04-27 23:16:30 +0200101}
102
103int get_recovery_mode_switch(void)
104{
105 device_t dev;
106#ifdef __PRE_RAM__
107 dev = PCI_DEV(0, 0x1f, 0);
108#else
109 dev = dev_find_slot(0, PCI_DEVFN(0x1f,0));
110#endif
111 u16 gpio_base = pci_read_config32(dev, GPIOBASE) & 0xfffe;
Gabe Blackf40a2592012-03-29 18:04:56 -0700112 u32 gp_lvl = inl(gpio_base + 0x0c);
Stefan Reinauer6651da32012-04-27 23:16:30 +0200113
Gabe Blackf40a2592012-03-29 18:04:56 -0700114 /* Recovery: GPIO22, active low */
115 return !((gp_lvl >> 22) & 1);
Stefan Reinauer6651da32012-04-27 23:16:30 +0200116}
117