blob: 8b6716a44175995aa6b6adece75dbb0b249ead82 [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.
Stefan Reinauere1ae4b22012-04-27 23:20:58 +020014 */
15
16#include <string.h>
Kyösti Mälkkie3ddee02014-05-03 10:45:28 +030017#include <bootmode.h>
Stefan Reinauere1ae4b22012-04-27 23:20:58 +020018#include <arch/io.h>
Stefan Reinauere1ae4b22012-04-27 23:20:58 +020019#include <device/device.h>
20#include <device/pci.h>
Stefan Reinauere1ae4b22012-04-27 23:20:58 +020021#include <southbridge/intel/bd82x6x/pch.h>
22
23#define GPIO_SPI_WP 68
24#define GPIO_REC_MODE 42
25#define GPIO_DEV_MODE 17
26
27#define FLAG_SPI_WP 0
28#define FLAG_REC_MODE 1
29#define FLAG_DEV_MODE 2
30
31#ifndef __PRE_RAM__
Stefan Reinauer3e4e3032013-03-20 14:08:04 -070032#include <boot/coreboot_tables.h>
Stefan Reinauere1ae4b22012-04-27 23:20:58 +020033
Vadim Bendebury6b3d09e2012-08-28 14:37:57 -070034#define GPIO_COUNT 6
Stefan Reinauere1ae4b22012-04-27 23:20:58 +020035
36void fill_lb_gpios(struct lb_gpios *gpios)
37{
38 device_t dev = dev_find_slot(0, PCI_DEVFN(0x1f,0));
39 u16 gen_pmcon_1 = pci_read_config32(dev, GEN_PMCON_1);
40
41 gpios->size = sizeof(*gpios) + (GPIO_COUNT * sizeof(struct lb_gpio));
42 gpios->count = GPIO_COUNT;
43
44 /* Write Protect: GPIO68 = CHP3_SPI_WP */
45 gpios->gpios[0].port = GPIO_SPI_WP;
46 gpios->gpios[0].polarity = ACTIVE_HIGH;
Patrick Georgi94b8ad42015-06-30 12:49:50 +020047 gpios->gpios[0].value = get_write_protect_state();
Stefan Reinauere1ae4b22012-04-27 23:20:58 +020048 strncpy((char *)gpios->gpios[0].name,"write protect",
49 GPIO_MAX_NAME_LENGTH);
50
51 /* Recovery: GPIO42 = CHP3_REC_MODE# */
52 gpios->gpios[1].port = GPIO_REC_MODE;
53 gpios->gpios[1].polarity = ACTIVE_LOW;
54 gpios->gpios[1].value = !get_recovery_mode_switch();
55 strncpy((char *)gpios->gpios[1].name,"recovery", GPIO_MAX_NAME_LENGTH);
56
57 /* Developer: GPIO17 = KBC3_DVP_MODE */
58 gpios->gpios[2].port = GPIO_DEV_MODE;
59 gpios->gpios[2].polarity = ACTIVE_HIGH;
60 gpios->gpios[2].value = get_developer_mode_switch();
61 strncpy((char *)gpios->gpios[2].name,"developer", GPIO_MAX_NAME_LENGTH);
62
63 /* Hard code the lid switch GPIO to open. */
64 gpios->gpios[3].port = 100;
65 gpios->gpios[3].polarity = ACTIVE_HIGH;
66 gpios->gpios[3].value = 1;
67 strncpy((char *)gpios->gpios[3].name,"lid", GPIO_MAX_NAME_LENGTH);
68
69 /* Power Button */
70 gpios->gpios[4].port = 101;
71 gpios->gpios[4].polarity = ACTIVE_LOW;
72 gpios->gpios[4].value = (gen_pmcon_1 >> 9) & 1;
73 strncpy((char *)gpios->gpios[4].name,"power", GPIO_MAX_NAME_LENGTH);
Vadim Bendebury6b3d09e2012-08-28 14:37:57 -070074
75 /* Did we load the VGA Option ROM? */
76 gpios->gpios[5].port = -1; /* Indicate that this is a pseudo GPIO */
77 gpios->gpios[5].polarity = ACTIVE_HIGH;
Kyösti Mälkkiab56b3b2013-11-28 16:44:51 +020078 gpios->gpios[5].value = gfx_get_init_done();
Vadim Bendebury6b3d09e2012-08-28 14:37:57 -070079 strncpy((char *)gpios->gpios[5].name,"oprom", GPIO_MAX_NAME_LENGTH);
Stefan Reinauere1ae4b22012-04-27 23:20:58 +020080}
81#endif
82
Patrick Georgi94b8ad42015-06-30 12:49:50 +020083int get_write_protect_state(void)
84{
85 device_t dev;
86#ifdef __PRE_RAM__
87 dev = PCI_DEV(0, 0x1f, 2);
88#else
89 dev = dev_find_slot(0, PCI_DEVFN(0x1f, 2));
90#endif
91 return (pci_read_config32(dev, SATA_SP) >> FLAG_SPI_WP) & 1;
92}
93
Stefan Reinauere1ae4b22012-04-27 23:20:58 +020094int get_developer_mode_switch(void)
95{
96 device_t dev;
97#ifdef __PRE_RAM__
98 dev = PCI_DEV(0, 0x1f, 2);
99#else
100 dev = dev_find_slot(0, PCI_DEVFN(0x1f, 2));
101#endif
102 return (pci_read_config32(dev, SATA_SP) >> FLAG_DEV_MODE) & 1;
103}
104
105int get_recovery_mode_switch(void)
106{
107 device_t dev;
108#ifdef __PRE_RAM__
109 dev = PCI_DEV(0, 0x1f, 2);
110#else
111 dev = dev_find_slot(0, PCI_DEVFN(0x1f, 2));
112#endif
113 return (pci_read_config32(dev, SATA_SP) >> FLAG_REC_MODE) & 1;
114}
115
Kyösti Mälkkie3ddee02014-05-03 10:45:28 +0300116void init_bootmode_straps(void)
Stefan Reinauere1ae4b22012-04-27 23:20:58 +0200117{
Kyösti Mälkkie3ddee02014-05-03 10:45:28 +0300118#ifdef __PRE_RAM__
Stefan Reinauere1ae4b22012-04-27 23:20:58 +0200119 u16 gpio_base = pci_read_config32(PCH_LPC_DEV, GPIO_BASE) & 0xfffe;
120 u32 gp_lvl3 = inl(gpio_base + GP_LVL3);
121 u32 gp_lvl2 = inl(gpio_base + GP_LVL2);
122 u32 gp_lvl = inl(gpio_base + GP_LVL);
123 u32 flags = 0;
124
125 /* Write Protect: GPIO68 = CHP3_SPI_WP, active high */
126 if (gp_lvl3 & (1 << (GPIO_SPI_WP-64)))
127 flags |= (1 << FLAG_SPI_WP);
128 /* Recovery: GPIO42 = CHP3_REC_MODE#, active low */
129 if (!(gp_lvl2 & (1 << (GPIO_REC_MODE-32))))
130 flags |= (1 << FLAG_REC_MODE);
131 /* Developer: GPIO17 = KBC3_DVP_MODE, active high */
132 if (gp_lvl & (1 << GPIO_DEV_MODE))
133 flags |= (1 << FLAG_DEV_MODE);
134
135 pci_write_config32(PCI_DEV(0, 0x1f, 2), SATA_SP, flags);
Stefan Reinauere1ae4b22012-04-27 23:20:58 +0200136#endif
Kyösti Mälkkie3ddee02014-05-03 10:45:28 +0300137}