blob: 896f8767f81844b2f471d514880249c9bbee957e [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>
Aaron Durbinb0f81512016-07-25 21:31:41 -050023#include <vendorcode/google/chromeos/chromeos.h>
Stefan Reinauer6651da32012-04-27 23:16:30 +020024
25#ifndef __PRE_RAM__
Stefan Reinauer3e4e3032013-03-20 14:08:04 -070026#include <boot/coreboot_tables.h>
Stefan Reinauer6651da32012-04-27 23:16:30 +020027
Duncan Lauriec64947b2012-10-01 13:31:25 -070028#define GPIO_COUNT 6
Stefan Reinauer6651da32012-04-27 23:16:30 +020029
30void fill_lb_gpios(struct lb_gpios *gpios)
31{
32 device_t dev = dev_find_slot(0, PCI_DEVFN(0x1f,0));
33 u16 gpio_base = pci_read_config32(dev, GPIOBASE) & 0xfffe;
Stefan Reinauer6651da32012-04-27 23:16:30 +020034
35 if (!gpio_base)
36 return;
37
Stefan Reinauer6651da32012-04-27 23:16:30 +020038 u32 gp_lvl = inl(gpio_base + 0x0c);
Stefan Reinauer6651da32012-04-27 23:16:30 +020039 u32 gp_lvl2 = inl(gpio_base + 0x38);
Gabe Blackf40a2592012-03-29 18:04:56 -070040 /* u32 gp_lvl3 = inl(gpio_base + 0x48); */
Stefan Reinauer6651da32012-04-27 23:16:30 +020041
42 gpios->size = sizeof(*gpios) + (GPIO_COUNT * sizeof(struct lb_gpio));
43 gpios->count = GPIO_COUNT;
44
Gabe Blackf40a2592012-03-29 18:04:56 -070045 /* Write Protect: GPIO48 */
46 gpios->gpios[0].port = 48;
47 gpios->gpios[0].polarity = ACTIVE_LOW;
48 gpios->gpios[0].value = (gp_lvl2 >> (48-32)) & 1;
Stefan Reinauer6651da32012-04-27 23:16:30 +020049 strncpy((char *)gpios->gpios[0].name,"write protect",
50 GPIO_MAX_NAME_LENGTH);
51
Gabe Blackf40a2592012-03-29 18:04:56 -070052 /* Recovery: GPIO22 */
53 gpios->gpios[1].port = 22;
Stefan Reinauer6651da32012-04-27 23:16:30 +020054 gpios->gpios[1].polarity = ACTIVE_LOW;
Gabe Blackf40a2592012-03-29 18:04:56 -070055 gpios->gpios[1].value = (gp_lvl >> 22) & 1;
Stefan Reinauer6651da32012-04-27 23:16:30 +020056 strncpy((char *)gpios->gpios[1].name,"recovery", GPIO_MAX_NAME_LENGTH);
57
Gabe Blackf40a2592012-03-29 18:04:56 -070058 /* Developer: GPIO57 */
59 gpios->gpios[2].port = 57;
Duncan Lauriec64947b2012-10-01 13:31:25 -070060 gpios->gpios[2].polarity = ACTIVE_LOW;
Gabe Blackf40a2592012-03-29 18:04:56 -070061 gpios->gpios[2].value = (gp_lvl2 >> (57-32)) & 1;
Stefan Reinauer6651da32012-04-27 23:16:30 +020062 strncpy((char *)gpios->gpios[2].name,"developer", GPIO_MAX_NAME_LENGTH);
63
64 /* Hard code the lid switch GPIO to open. */
Duncan Lauriec64947b2012-10-01 13:31:25 -070065 gpios->gpios[3].port = -1;
Stefan Reinauer6651da32012-04-27 23:16:30 +020066 gpios->gpios[3].polarity = ACTIVE_HIGH;
67 gpios->gpios[3].value = 1;
68 strncpy((char *)gpios->gpios[3].name,"lid", GPIO_MAX_NAME_LENGTH);
69
70 /* Power Button */
Duncan Lauriec64947b2012-10-01 13:31:25 -070071 gpios->gpios[4].port = -1;
72 gpios->gpios[4].polarity = ACTIVE_HIGH;
73 gpios->gpios[4].value = 0;
Stefan Reinauer6651da32012-04-27 23:16:30 +020074 strncpy((char *)gpios->gpios[4].name,"power", GPIO_MAX_NAME_LENGTH);
Duncan Lauriec64947b2012-10-01 13:31:25 -070075
76 /* Did we load the VGA option ROM? */
77 gpios->gpios[5].port = -1;
78 gpios->gpios[5].polarity = ACTIVE_HIGH;
Kyösti Mälkkiab56b3b2013-11-28 16:44:51 +020079 gpios->gpios[5].value = gfx_get_init_done();
Duncan Lauriec64947b2012-10-01 13:31:25 -070080 strncpy((char *)gpios->gpios[5].name,"oprom", GPIO_MAX_NAME_LENGTH);
Stefan Reinauer6651da32012-04-27 23:16:30 +020081}
82#endif
83
84int get_developer_mode_switch(void)
85{
Patrick Rudolphe8e66f42016-02-06 17:42:42 +010086 /* Developer: GPIO57, active high */
87 return get_gpio(57);
Stefan Reinauer6651da32012-04-27 23:16:30 +020088}
89
90int get_recovery_mode_switch(void)
91{
Gabe Blackf40a2592012-03-29 18:04:56 -070092 /* Recovery: GPIO22, active low */
Patrick Rudolphe8e66f42016-02-06 17:42:42 +010093 return !get_gpio(22);
Stefan Reinauer6651da32012-04-27 23:16:30 +020094}
Aaron Durbinb0f81512016-07-25 21:31:41 -050095
96static const struct cros_gpio cros_gpios[] = {
97 CROS_GPIO_REC_AL(22, CROS_GPIO_DEVICE_NAME),
98 CROS_GPIO_DEV_AH(57, CROS_GPIO_DEVICE_NAME),
99 CROS_GPIO_WP_AL(48, CROS_GPIO_DEVICE_NAME),
100};
101
102void mainboard_chromeos_acpi_generate(void)
103{
104 chromeos_acpi_gpio_generate(cros_gpios, ARRAY_SIZE(cros_gpios));
105}