blob: 98749e0c6e94e6c62fedecd4d5c156b841e25ade [file] [log] [blame]
Stefan Reinauer6651da32012-04-27 23:16:30 +02001/*
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.
Stefan Reinauer6651da32012-04-27 23:16:30 +020014 */
15
16#include <string.h>
Kyösti Mälkkiab728092014-05-03 16:47:52 +030017#include <bootmode.h>
Stefan Reinauer6651da32012-04-27 23:16:30 +020018#include <arch/io.h>
Stefan Reinauer6651da32012-04-27 23:16:30 +020019#include <device/device.h>
20#include <device/pci.h>
Stefan Reinauer6651da32012-04-27 23:16:30 +020021#include <southbridge/intel/bd82x6x/pch.h>
22
23#ifndef __PRE_RAM__
Stefan Reinauer3e4e3032013-03-20 14:08:04 -070024#include <boot/coreboot_tables.h>
Stefan Reinauer6651da32012-04-27 23:16:30 +020025
Duncan Lauriec64947b2012-10-01 13:31:25 -070026#define GPIO_COUNT 6
Stefan Reinauer6651da32012-04-27 23:16:30 +020027
28void fill_lb_gpios(struct lb_gpios *gpios)
29{
30 device_t dev = dev_find_slot(0, PCI_DEVFN(0x1f,0));
31 u16 gpio_base = pci_read_config32(dev, GPIOBASE) & 0xfffe;
Stefan Reinauer6651da32012-04-27 23:16:30 +020032
33 if (!gpio_base)
34 return;
35
Stefan Reinauer6651da32012-04-27 23:16:30 +020036 u32 gp_lvl = inl(gpio_base + 0x0c);
Stefan Reinauer6651da32012-04-27 23:16:30 +020037 u32 gp_lvl2 = inl(gpio_base + 0x38);
Gabe Blackf40a2592012-03-29 18:04:56 -070038 /* u32 gp_lvl3 = inl(gpio_base + 0x48); */
Stefan Reinauer6651da32012-04-27 23:16:30 +020039
40 gpios->size = sizeof(*gpios) + (GPIO_COUNT * sizeof(struct lb_gpio));
41 gpios->count = GPIO_COUNT;
42
Gabe Blackf40a2592012-03-29 18:04:56 -070043 /* Write Protect: GPIO48 */
44 gpios->gpios[0].port = 48;
45 gpios->gpios[0].polarity = ACTIVE_LOW;
46 gpios->gpios[0].value = (gp_lvl2 >> (48-32)) & 1;
Stefan Reinauer6651da32012-04-27 23:16:30 +020047 strncpy((char *)gpios->gpios[0].name,"write protect",
48 GPIO_MAX_NAME_LENGTH);
49
Gabe Blackf40a2592012-03-29 18:04:56 -070050 /* Recovery: GPIO22 */
51 gpios->gpios[1].port = 22;
Stefan Reinauer6651da32012-04-27 23:16:30 +020052 gpios->gpios[1].polarity = ACTIVE_LOW;
Gabe Blackf40a2592012-03-29 18:04:56 -070053 gpios->gpios[1].value = (gp_lvl >> 22) & 1;
Stefan Reinauer6651da32012-04-27 23:16:30 +020054 strncpy((char *)gpios->gpios[1].name,"recovery", GPIO_MAX_NAME_LENGTH);
55
Gabe Blackf40a2592012-03-29 18:04:56 -070056 /* Developer: GPIO57 */
57 gpios->gpios[2].port = 57;
Duncan Lauriec64947b2012-10-01 13:31:25 -070058 gpios->gpios[2].polarity = ACTIVE_LOW;
Gabe Blackf40a2592012-03-29 18:04:56 -070059 gpios->gpios[2].value = (gp_lvl2 >> (57-32)) & 1;
Stefan Reinauer6651da32012-04-27 23:16:30 +020060 strncpy((char *)gpios->gpios[2].name,"developer", GPIO_MAX_NAME_LENGTH);
61
62 /* Hard code the lid switch GPIO to open. */
Duncan Lauriec64947b2012-10-01 13:31:25 -070063 gpios->gpios[3].port = -1;
Stefan Reinauer6651da32012-04-27 23:16:30 +020064 gpios->gpios[3].polarity = ACTIVE_HIGH;
65 gpios->gpios[3].value = 1;
66 strncpy((char *)gpios->gpios[3].name,"lid", GPIO_MAX_NAME_LENGTH);
67
68 /* Power Button */
Duncan Lauriec64947b2012-10-01 13:31:25 -070069 gpios->gpios[4].port = -1;
70 gpios->gpios[4].polarity = ACTIVE_HIGH;
71 gpios->gpios[4].value = 0;
Stefan Reinauer6651da32012-04-27 23:16:30 +020072 strncpy((char *)gpios->gpios[4].name,"power", GPIO_MAX_NAME_LENGTH);
Duncan Lauriec64947b2012-10-01 13:31:25 -070073
74 /* Did we load the VGA option ROM? */
75 gpios->gpios[5].port = -1;
76 gpios->gpios[5].polarity = ACTIVE_HIGH;
Kyösti Mälkkiab56b3b2013-11-28 16:44:51 +020077 gpios->gpios[5].value = gfx_get_init_done();
Duncan Lauriec64947b2012-10-01 13:31:25 -070078 strncpy((char *)gpios->gpios[5].name,"oprom", GPIO_MAX_NAME_LENGTH);
Stefan Reinauer6651da32012-04-27 23:16:30 +020079}
80#endif
81
82int get_developer_mode_switch(void)
83{
Stefan Reinauer6651da32012-04-27 23:16:30 +020084 device_t dev;
85#ifdef __PRE_RAM__
86 dev = PCI_DEV(0, 0x1f, 0);
87#else
88 dev = dev_find_slot(0, PCI_DEVFN(0x1f,0));
89#endif
90 u16 gpio_base = pci_read_config32(dev, GPIOBASE) & 0xfffe;
Gabe Blackf40a2592012-03-29 18:04:56 -070091 u32 gp_lvl2 = inl(gpio_base + 0x38);
Stefan Reinauer6651da32012-04-27 23:16:30 +020092
Gabe Blackf40a2592012-03-29 18:04:56 -070093 /* Developer: GPIO17, active high */
94 return (gp_lvl2 >> (57-32)) & 1;
Stefan Reinauer6651da32012-04-27 23:16:30 +020095}
96
97int get_recovery_mode_switch(void)
98{
99 device_t dev;
100#ifdef __PRE_RAM__
101 dev = PCI_DEV(0, 0x1f, 0);
102#else
103 dev = dev_find_slot(0, PCI_DEVFN(0x1f,0));
104#endif
105 u16 gpio_base = pci_read_config32(dev, GPIOBASE) & 0xfffe;
Gabe Blackf40a2592012-03-29 18:04:56 -0700106 u32 gp_lvl = inl(gpio_base + 0x0c);
Stefan Reinauer6651da32012-04-27 23:16:30 +0200107
Gabe Blackf40a2592012-03-29 18:04:56 -0700108 /* Recovery: GPIO22, active low */
109 return !((gp_lvl >> 22) & 1);
Stefan Reinauer6651da32012-04-27 23:16:30 +0200110}