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