blob: 6a1bc26150ee8645432f5e2c0f28ddfa84d195c7 [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>
23#ifdef __PRE_RAM__
24#include <arch/romcc_io.h>
25#else
26#include <device/device.h>
27#include <device/pci.h>
28#endif
29#include <southbridge/intel/lynxpoint/pch.h>
Aaron Durbin0160d762012-12-13 16:51:41 -060030#include <southbridge/intel/lynxpoint/gpio.h>
Aaron Durbinf6933a62012-10-30 09:09:39 -050031
32#ifndef __PRE_RAM__
33#include <boot/coreboot_tables.h>
34#include <arch/coreboot_tables.h>
35
36#define GPIO_COUNT 6
37#define ACTIVE_LOW 0
38#define ACTIVE_HIGH 1
39
40void fill_lb_gpios(struct lb_gpios *gpios)
41{
42 device_t dev = dev_find_slot(0, PCI_DEVFN(0x1f,0));
43 u16 gpio_base = pci_read_config32(dev, GPIOBASE) & 0xfffe;
44
45 if (!gpio_base)
46 return;
47
Aaron Durbin0160d762012-12-13 16:51:41 -060048 u32 gp_lvl = inl(gpio_base + GP_LVL);
49 u32 gp_lvl2 = inl(gpio_base + GP_LVL2);
50 u32 gp_lvl3 = inl(gpio_base + GP_LVL3);
Aaron Durbinf6933a62012-10-30 09:09:39 -050051
52 gpios->size = sizeof(*gpios) + (GPIO_COUNT * sizeof(struct lb_gpio));
53 gpios->count = GPIO_COUNT;
54
Aaron Durbin0160d762012-12-13 16:51:41 -060055 /* Write Protect: GPIO22 */
56 gpios->gpios[0].port = 0;
Aaron Durbinf6933a62012-10-30 09:09:39 -050057 gpios->gpios[0].polarity = ACTIVE_LOW;
Aaron Durbin0160d762012-12-13 16:51:41 -060058 gpios->gpios[0].value = (gp_lvl >> 22) & 1;
Aaron Durbinf6933a62012-10-30 09:09:39 -050059 strncpy((char *)gpios->gpios[0].name,"write protect",
60 GPIO_MAX_NAME_LENGTH);
61
Aaron Durbin0160d762012-12-13 16:51:41 -060062 /* Recovery: GPIO69 - SV_DETECT - J8E3 (silkscreen: J8E2) */
63 gpios->gpios[1].port = 69;
64 gpios->gpios[1].polarity = ACTIVE_HIGH;
65 gpios->gpios[1].value = (gp_lvl3 >> (69-64)) & 1;
Aaron Durbinf6933a62012-10-30 09:09:39 -050066 strncpy((char *)gpios->gpios[1].name,"recovery", GPIO_MAX_NAME_LENGTH);
67
Aaron Durbin0160d762012-12-13 16:51:41 -060068 /* Developer: GPIO48 - BIOS_RESP - J8E4 (silkscreen: J8E3) */
69 gpios->gpios[2].port = 48;
Aaron Durbinf6933a62012-10-30 09:09:39 -050070 gpios->gpios[2].polarity = ACTIVE_LOW;
Aaron Durbin0160d762012-12-13 16:51:41 -060071 gpios->gpios[2].value = (gp_lvl2 >> (48-32)) & 1;
Aaron Durbinf6933a62012-10-30 09:09:39 -050072 strncpy((char *)gpios->gpios[2].name,"developer", GPIO_MAX_NAME_LENGTH);
73
74 /* Hard code the lid switch GPIO to open. */
75 gpios->gpios[3].port = -1;
76 gpios->gpios[3].polarity = ACTIVE_HIGH;
77 gpios->gpios[3].value = 1;
78 strncpy((char *)gpios->gpios[3].name,"lid", GPIO_MAX_NAME_LENGTH);
79
80 /* Power Button */
81 gpios->gpios[4].port = -1;
82 gpios->gpios[4].polarity = ACTIVE_HIGH;
83 gpios->gpios[4].value = 0;
84 strncpy((char *)gpios->gpios[4].name,"power", GPIO_MAX_NAME_LENGTH);
85
86 /* Did we load the VGA option ROM? */
87 gpios->gpios[5].port = -1;
88 gpios->gpios[5].polarity = ACTIVE_HIGH;
89 gpios->gpios[5].value = oprom_is_loaded;
90 strncpy((char *)gpios->gpios[5].name,"oprom", GPIO_MAX_NAME_LENGTH);
91}
92#endif
93
94int get_developer_mode_switch(void)
95{
96 device_t dev;
97#ifdef __PRE_RAM__
98 dev = PCI_DEV(0, 0x1f, 0);
99#else
100 dev = dev_find_slot(0, PCI_DEVFN(0x1f,0));
101#endif
102 u16 gpio_base = pci_read_config32(dev, GPIOBASE) & 0xfffe;
Aaron Durbin0160d762012-12-13 16:51:41 -0600103 u32 gp_lvl2 = inl(gpio_base + GP_LVL2);
Aaron Durbinf6933a62012-10-30 09:09:39 -0500104
Aaron Durbin0160d762012-12-13 16:51:41 -0600105 /*
106 * Developer: GPIO48, Connected to J8E4, however the silkscreen says
107 * J8E3. The jumper is active low.
108 */
109 return !((gp_lvl2 >> (48-32)) & 1);
Aaron Durbinf6933a62012-10-30 09:09:39 -0500110}
111
112int get_recovery_mode_switch(void)
113{
114 device_t dev;
115#ifdef __PRE_RAM__
116 dev = PCI_DEV(0, 0x1f, 0);
117#else
118 dev = dev_find_slot(0, PCI_DEVFN(0x1f,0));
119#endif
120 u16 gpio_base = pci_read_config32(dev, GPIOBASE) & 0xfffe;
Aaron Durbin0160d762012-12-13 16:51:41 -0600121 u32 gp_lvl3 = inl(gpio_base + GP_LVL3);
Aaron Durbinf6933a62012-10-30 09:09:39 -0500122
Aaron Durbin0160d762012-12-13 16:51:41 -0600123 /*
124 * Recovery: GPIO69, Connected to J8E3, however the silkscreen says
125 * J8E2. The jump is active high.
126 */
127 return (gp_lvl3 >> (69-64)) & 1;
Aaron Durbinf6933a62012-10-30 09:09:39 -0500128}
129