blob: e639fd3cbd5b23be9684450cf23e4761d4f16853 [file] [log] [blame]
Stefan Reinauere1ae4b22012-04-27 23:20:58 +02001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2011 The ChromiumOS 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 Reinauere1ae4b22012-04-27 23:20:58 +020023#include <device/device.h>
24#include <device/pci.h>
Stefan Reinauere1ae4b22012-04-27 23:20:58 +020025#include <southbridge/intel/bd82x6x/pch.h>
26
27#define GPIO_SPI_WP 68
28#define GPIO_REC_MODE 42
29#define GPIO_DEV_MODE 17
30
31#define FLAG_SPI_WP 0
32#define FLAG_REC_MODE 1
33#define FLAG_DEV_MODE 2
34
35#ifndef __PRE_RAM__
Stefan Reinauer3e4e3032013-03-20 14:08:04 -070036#include <boot/coreboot_tables.h>
Stefan Reinauere1ae4b22012-04-27 23:20:58 +020037
Vadim Bendebury6b3d09e2012-08-28 14:37:57 -070038#define GPIO_COUNT 6
Stefan Reinauere1ae4b22012-04-27 23:20:58 +020039#define ACTIVE_LOW 0
40#define ACTIVE_HIGH 1
41
42void fill_lb_gpios(struct lb_gpios *gpios)
43{
44 device_t dev = dev_find_slot(0, PCI_DEVFN(0x1f,0));
45 u16 gen_pmcon_1 = pci_read_config32(dev, GEN_PMCON_1);
46
47 gpios->size = sizeof(*gpios) + (GPIO_COUNT * sizeof(struct lb_gpio));
48 gpios->count = GPIO_COUNT;
49
50 /* Write Protect: GPIO68 = CHP3_SPI_WP */
51 gpios->gpios[0].port = GPIO_SPI_WP;
52 gpios->gpios[0].polarity = ACTIVE_HIGH;
53 gpios->gpios[0].value =
54 (pci_read_config32(dev_find_slot(0, PCI_DEVFN(0x1f, 2)),
55 SATA_SP) >> FLAG_SPI_WP) & 1;
56 strncpy((char *)gpios->gpios[0].name,"write protect",
57 GPIO_MAX_NAME_LENGTH);
58
59 /* Recovery: GPIO42 = CHP3_REC_MODE# */
60 gpios->gpios[1].port = GPIO_REC_MODE;
61 gpios->gpios[1].polarity = ACTIVE_LOW;
62 gpios->gpios[1].value = !get_recovery_mode_switch();
63 strncpy((char *)gpios->gpios[1].name,"recovery", GPIO_MAX_NAME_LENGTH);
64
65 /* Developer: GPIO17 = KBC3_DVP_MODE */
66 gpios->gpios[2].port = GPIO_DEV_MODE;
67 gpios->gpios[2].polarity = ACTIVE_HIGH;
68 gpios->gpios[2].value = get_developer_mode_switch();
69 strncpy((char *)gpios->gpios[2].name,"developer", GPIO_MAX_NAME_LENGTH);
70
71 /* Hard code the lid switch GPIO to open. */
72 gpios->gpios[3].port = 100;
73 gpios->gpios[3].polarity = ACTIVE_HIGH;
74 gpios->gpios[3].value = 1;
75 strncpy((char *)gpios->gpios[3].name,"lid", GPIO_MAX_NAME_LENGTH);
76
77 /* Power Button */
78 gpios->gpios[4].port = 101;
79 gpios->gpios[4].polarity = ACTIVE_LOW;
80 gpios->gpios[4].value = (gen_pmcon_1 >> 9) & 1;
81 strncpy((char *)gpios->gpios[4].name,"power", GPIO_MAX_NAME_LENGTH);
Vadim Bendebury6b3d09e2012-08-28 14:37:57 -070082
83 /* Did we load the VGA Option ROM? */
84 gpios->gpios[5].port = -1; /* Indicate that this is a pseudo GPIO */
85 gpios->gpios[5].polarity = ACTIVE_HIGH;
86 gpios->gpios[5].value = oprom_is_loaded;
87 strncpy((char *)gpios->gpios[5].name,"oprom", GPIO_MAX_NAME_LENGTH);
Stefan Reinauere1ae4b22012-04-27 23:20:58 +020088}
89#endif
90
91int get_developer_mode_switch(void)
92{
93 device_t dev;
94#ifdef __PRE_RAM__
95 dev = PCI_DEV(0, 0x1f, 2);
96#else
97 dev = dev_find_slot(0, PCI_DEVFN(0x1f, 2));
98#endif
99 return (pci_read_config32(dev, SATA_SP) >> FLAG_DEV_MODE) & 1;
100}
101
102int get_recovery_mode_switch(void)
103{
104 device_t dev;
105#ifdef __PRE_RAM__
106 dev = PCI_DEV(0, 0x1f, 2);
107#else
108 dev = dev_find_slot(0, PCI_DEVFN(0x1f, 2));
109#endif
110 return (pci_read_config32(dev, SATA_SP) >> FLAG_REC_MODE) & 1;
111}
112
113#ifdef __PRE_RAM__
114void save_chromeos_gpios(void)
115{
116 u16 gpio_base = pci_read_config32(PCH_LPC_DEV, GPIO_BASE) & 0xfffe;
117 u32 gp_lvl3 = inl(gpio_base + GP_LVL3);
118 u32 gp_lvl2 = inl(gpio_base + GP_LVL2);
119 u32 gp_lvl = inl(gpio_base + GP_LVL);
120 u32 flags = 0;
121
122 /* Write Protect: GPIO68 = CHP3_SPI_WP, active high */
123 if (gp_lvl3 & (1 << (GPIO_SPI_WP-64)))
124 flags |= (1 << FLAG_SPI_WP);
125 /* Recovery: GPIO42 = CHP3_REC_MODE#, active low */
126 if (!(gp_lvl2 & (1 << (GPIO_REC_MODE-32))))
127 flags |= (1 << FLAG_REC_MODE);
128 /* Developer: GPIO17 = KBC3_DVP_MODE, active high */
129 if (gp_lvl & (1 << GPIO_DEV_MODE))
130 flags |= (1 << FLAG_DEV_MODE);
131
132 pci_write_config32(PCI_DEV(0, 0x1f, 2), SATA_SP, flags);
133}
134#endif