blob: bb4ebe9f54c1dd8dd20b516ba3e792f02a9bcb96 [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>
Patrick Rudolphe8e66f42016-02-06 17:42:42 +010022#include <southbridge/intel/common/gpio.h>
Stefan Reinauer6651da32012-04-27 23:16:30 +020023
24#ifndef __PRE_RAM__
Stefan Reinauer3e4e3032013-03-20 14:08:04 -070025#include <boot/coreboot_tables.h>
Stefan Reinauer6651da32012-04-27 23:16:30 +020026
Duncan Lauriec64947b2012-10-01 13:31:25 -070027#define GPIO_COUNT 6
Stefan Reinauer6651da32012-04-27 23:16:30 +020028
29void fill_lb_gpios(struct lb_gpios *gpios)
30{
31 device_t dev = dev_find_slot(0, PCI_DEVFN(0x1f,0));
32 u16 gpio_base = pci_read_config32(dev, GPIOBASE) & 0xfffe;
Stefan Reinauer6651da32012-04-27 23:16:30 +020033
34 if (!gpio_base)
35 return;
36
Stefan Reinauer6651da32012-04-27 23:16:30 +020037 u32 gp_lvl = inl(gpio_base + 0x0c);
Stefan Reinauer6651da32012-04-27 23:16:30 +020038 u32 gp_lvl2 = inl(gpio_base + 0x38);
Gabe Blackf40a2592012-03-29 18:04:56 -070039 /* u32 gp_lvl3 = inl(gpio_base + 0x48); */
Stefan Reinauer6651da32012-04-27 23:16:30 +020040
41 gpios->size = sizeof(*gpios) + (GPIO_COUNT * sizeof(struct lb_gpio));
42 gpios->count = GPIO_COUNT;
43
Gabe Blackf40a2592012-03-29 18:04:56 -070044 /* Write Protect: GPIO48 */
45 gpios->gpios[0].port = 48;
46 gpios->gpios[0].polarity = ACTIVE_LOW;
47 gpios->gpios[0].value = (gp_lvl2 >> (48-32)) & 1;
Stefan Reinauer6651da32012-04-27 23:16:30 +020048 strncpy((char *)gpios->gpios[0].name,"write protect",
49 GPIO_MAX_NAME_LENGTH);
50
Gabe Blackf40a2592012-03-29 18:04:56 -070051 /* Recovery: GPIO22 */
52 gpios->gpios[1].port = 22;
Stefan Reinauer6651da32012-04-27 23:16:30 +020053 gpios->gpios[1].polarity = ACTIVE_LOW;
Gabe Blackf40a2592012-03-29 18:04:56 -070054 gpios->gpios[1].value = (gp_lvl >> 22) & 1;
Stefan Reinauer6651da32012-04-27 23:16:30 +020055 strncpy((char *)gpios->gpios[1].name,"recovery", GPIO_MAX_NAME_LENGTH);
56
Gabe Blackf40a2592012-03-29 18:04:56 -070057 /* Developer: GPIO57 */
58 gpios->gpios[2].port = 57;
Duncan Lauriec64947b2012-10-01 13:31:25 -070059 gpios->gpios[2].polarity = ACTIVE_LOW;
Gabe Blackf40a2592012-03-29 18:04:56 -070060 gpios->gpios[2].value = (gp_lvl2 >> (57-32)) & 1;
Stefan Reinauer6651da32012-04-27 23:16:30 +020061 strncpy((char *)gpios->gpios[2].name,"developer", GPIO_MAX_NAME_LENGTH);
62
63 /* Hard code the lid switch GPIO to open. */
Duncan Lauriec64947b2012-10-01 13:31:25 -070064 gpios->gpios[3].port = -1;
Stefan Reinauer6651da32012-04-27 23:16:30 +020065 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 */
Duncan Lauriec64947b2012-10-01 13:31:25 -070070 gpios->gpios[4].port = -1;
71 gpios->gpios[4].polarity = ACTIVE_HIGH;
72 gpios->gpios[4].value = 0;
Stefan Reinauer6651da32012-04-27 23:16:30 +020073 strncpy((char *)gpios->gpios[4].name,"power", GPIO_MAX_NAME_LENGTH);
Duncan Lauriec64947b2012-10-01 13:31:25 -070074
75 /* Did we load the VGA option ROM? */
76 gpios->gpios[5].port = -1;
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();
Duncan Lauriec64947b2012-10-01 13:31:25 -070079 strncpy((char *)gpios->gpios[5].name,"oprom", GPIO_MAX_NAME_LENGTH);
Stefan Reinauer6651da32012-04-27 23:16:30 +020080}
81#endif
82
83int get_developer_mode_switch(void)
84{
Patrick Rudolphe8e66f42016-02-06 17:42:42 +010085 /* Developer: GPIO57, active high */
86 return get_gpio(57);
Stefan Reinauer6651da32012-04-27 23:16:30 +020087}
88
89int get_recovery_mode_switch(void)
90{
Gabe Blackf40a2592012-03-29 18:04:56 -070091 /* Recovery: GPIO22, active low */
Patrick Rudolphe8e66f42016-02-06 17:42:42 +010092 return !get_gpio(22);
Stefan Reinauer6651da32012-04-27 23:16:30 +020093}