blob: 510d737d13d201a52ab3204a40078af2a8dd1fdc [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__
40#include <boot/coreboot_tables.h>
41#include <arch/coreboot_tables.h>
42
43#define GPIO_COUNT 5
44#define ACTIVE_LOW 0
45#define ACTIVE_HIGH 1
46
47void fill_lb_gpios(struct lb_gpios *gpios)
48{
49 device_t dev = dev_find_slot(0, PCI_DEVFN(0x1f,0));
50 u16 gen_pmcon_1 = pci_read_config32(dev, GEN_PMCON_1);
51
52 gpios->size = sizeof(*gpios) + (GPIO_COUNT * sizeof(struct lb_gpio));
53 gpios->count = GPIO_COUNT;
54
55 /* Write Protect: GPIO68 = CHP3_SPI_WP */
56 gpios->gpios[0].port = GPIO_SPI_WP;
57 gpios->gpios[0].polarity = ACTIVE_HIGH;
58 gpios->gpios[0].value =
59 (pci_read_config32(dev_find_slot(0, PCI_DEVFN(0x1f, 2)),
60 SATA_SP) >> FLAG_SPI_WP) & 1;
61 strncpy((char *)gpios->gpios[0].name,"write protect",
62 GPIO_MAX_NAME_LENGTH);
63
64 /* Recovery: GPIO42 = CHP3_REC_MODE# */
65 gpios->gpios[1].port = GPIO_REC_MODE;
66 gpios->gpios[1].polarity = ACTIVE_LOW;
67 gpios->gpios[1].value = !get_recovery_mode_switch();
68 strncpy((char *)gpios->gpios[1].name,"recovery", GPIO_MAX_NAME_LENGTH);
69
70 /* Developer: GPIO17 = KBC3_DVP_MODE */
71 gpios->gpios[2].port = GPIO_DEV_MODE;
72 gpios->gpios[2].polarity = ACTIVE_HIGH;
73 gpios->gpios[2].value = get_developer_mode_switch();
74 strncpy((char *)gpios->gpios[2].name,"developer", GPIO_MAX_NAME_LENGTH);
75
76 /* Hard code the lid switch GPIO to open. */
77 gpios->gpios[3].port = 100;
78 gpios->gpios[3].polarity = ACTIVE_HIGH;
79 gpios->gpios[3].value = 1;
80 strncpy((char *)gpios->gpios[3].name,"lid", GPIO_MAX_NAME_LENGTH);
81
82 /* Power Button */
83 gpios->gpios[4].port = 101;
84 gpios->gpios[4].polarity = ACTIVE_LOW;
85 gpios->gpios[4].value = (gen_pmcon_1 >> 9) & 1;
86 strncpy((char *)gpios->gpios[4].name,"power", GPIO_MAX_NAME_LENGTH);
87}
88#endif
89
90int get_developer_mode_switch(void)
91{
92 device_t dev;
93#ifdef __PRE_RAM__
94 dev = PCI_DEV(0, 0x1f, 2);
95#else
96 dev = dev_find_slot(0, PCI_DEVFN(0x1f, 2));
97#endif
98 return (pci_read_config32(dev, SATA_SP) >> FLAG_DEV_MODE) & 1;
99}
100
101int get_recovery_mode_switch(void)
102{
103 device_t dev;
104#ifdef __PRE_RAM__
105 dev = PCI_DEV(0, 0x1f, 2);
106#else
107 dev = dev_find_slot(0, PCI_DEVFN(0x1f, 2));
108#endif
109 return (pci_read_config32(dev, SATA_SP) >> FLAG_REC_MODE) & 1;
110}
111
112#ifdef __PRE_RAM__
113void save_chromeos_gpios(void)
114{
115 u16 gpio_base = pci_read_config32(PCH_LPC_DEV, GPIO_BASE) & 0xfffe;
116 u32 gp_lvl3 = inl(gpio_base + GP_LVL3);
117 u32 gp_lvl2 = inl(gpio_base + GP_LVL2);
118 u32 gp_lvl = inl(gpio_base + GP_LVL);
119 u32 flags = 0;
120
121 /* Write Protect: GPIO68 = CHP3_SPI_WP, active high */
122 if (gp_lvl3 & (1 << (GPIO_SPI_WP-64)))
123 flags |= (1 << FLAG_SPI_WP);
124 /* Recovery: GPIO42 = CHP3_REC_MODE#, active low */
125 if (!(gp_lvl2 & (1 << (GPIO_REC_MODE-32))))
126 flags |= (1 << FLAG_REC_MODE);
127 /* Developer: GPIO17 = KBC3_DVP_MODE, active high */
128 if (gp_lvl & (1 << GPIO_DEV_MODE))
129 flags |= (1 << FLAG_DEV_MODE);
130
131 pci_write_config32(PCI_DEV(0, 0x1f, 2), SATA_SP, flags);
132}
133#endif