Stefan Reinauer | 6651da3 | 2012-04-27 23:16:30 +0200 | [diff] [blame] | 1 | /* |
| 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. |
| 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> |
Kyösti Mälkki | ab72809 | 2014-05-03 16:47:52 +0300 | [diff] [blame^] | 21 | #include <bootmode.h> |
Stefan Reinauer | 6651da3 | 2012-04-27 23:16:30 +0200 | [diff] [blame] | 22 | #include <arch/io.h> |
Stefan Reinauer | 6651da3 | 2012-04-27 23:16:30 +0200 | [diff] [blame] | 23 | #include <device/device.h> |
| 24 | #include <device/pci.h> |
Stefan Reinauer | 6651da3 | 2012-04-27 23:16:30 +0200 | [diff] [blame] | 25 | #include <southbridge/intel/bd82x6x/pch.h> |
| 26 | |
| 27 | #ifndef __PRE_RAM__ |
Stefan Reinauer | 3e4e303 | 2013-03-20 14:08:04 -0700 | [diff] [blame] | 28 | #include <boot/coreboot_tables.h> |
Stefan Reinauer | 6651da3 | 2012-04-27 23:16:30 +0200 | [diff] [blame] | 29 | |
Duncan Laurie | c64947b | 2012-10-01 13:31:25 -0700 | [diff] [blame] | 30 | #define GPIO_COUNT 6 |
Stefan Reinauer | 6651da3 | 2012-04-27 23:16:30 +0200 | [diff] [blame] | 31 | |
| 32 | void fill_lb_gpios(struct lb_gpios *gpios) |
| 33 | { |
| 34 | device_t dev = dev_find_slot(0, PCI_DEVFN(0x1f,0)); |
| 35 | u16 gpio_base = pci_read_config32(dev, GPIOBASE) & 0xfffe; |
Stefan Reinauer | 6651da3 | 2012-04-27 23:16:30 +0200 | [diff] [blame] | 36 | |
| 37 | if (!gpio_base) |
| 38 | return; |
| 39 | |
Stefan Reinauer | 6651da3 | 2012-04-27 23:16:30 +0200 | [diff] [blame] | 40 | u32 gp_lvl = inl(gpio_base + 0x0c); |
Stefan Reinauer | 6651da3 | 2012-04-27 23:16:30 +0200 | [diff] [blame] | 41 | u32 gp_lvl2 = inl(gpio_base + 0x38); |
Gabe Black | f40a259 | 2012-03-29 18:04:56 -0700 | [diff] [blame] | 42 | /* u32 gp_lvl3 = inl(gpio_base + 0x48); */ |
Stefan Reinauer | 6651da3 | 2012-04-27 23:16:30 +0200 | [diff] [blame] | 43 | |
| 44 | gpios->size = sizeof(*gpios) + (GPIO_COUNT * sizeof(struct lb_gpio)); |
| 45 | gpios->count = GPIO_COUNT; |
| 46 | |
Gabe Black | f40a259 | 2012-03-29 18:04:56 -0700 | [diff] [blame] | 47 | /* Write Protect: GPIO48 */ |
| 48 | gpios->gpios[0].port = 48; |
| 49 | gpios->gpios[0].polarity = ACTIVE_LOW; |
| 50 | gpios->gpios[0].value = (gp_lvl2 >> (48-32)) & 1; |
Stefan Reinauer | 6651da3 | 2012-04-27 23:16:30 +0200 | [diff] [blame] | 51 | strncpy((char *)gpios->gpios[0].name,"write protect", |
| 52 | GPIO_MAX_NAME_LENGTH); |
| 53 | |
Gabe Black | f40a259 | 2012-03-29 18:04:56 -0700 | [diff] [blame] | 54 | /* Recovery: GPIO22 */ |
| 55 | gpios->gpios[1].port = 22; |
Stefan Reinauer | 6651da3 | 2012-04-27 23:16:30 +0200 | [diff] [blame] | 56 | gpios->gpios[1].polarity = ACTIVE_LOW; |
Gabe Black | f40a259 | 2012-03-29 18:04:56 -0700 | [diff] [blame] | 57 | gpios->gpios[1].value = (gp_lvl >> 22) & 1; |
Stefan Reinauer | 6651da3 | 2012-04-27 23:16:30 +0200 | [diff] [blame] | 58 | strncpy((char *)gpios->gpios[1].name,"recovery", GPIO_MAX_NAME_LENGTH); |
| 59 | |
Gabe Black | f40a259 | 2012-03-29 18:04:56 -0700 | [diff] [blame] | 60 | /* Developer: GPIO57 */ |
| 61 | gpios->gpios[2].port = 57; |
Duncan Laurie | c64947b | 2012-10-01 13:31:25 -0700 | [diff] [blame] | 62 | gpios->gpios[2].polarity = ACTIVE_LOW; |
Gabe Black | f40a259 | 2012-03-29 18:04:56 -0700 | [diff] [blame] | 63 | gpios->gpios[2].value = (gp_lvl2 >> (57-32)) & 1; |
Stefan Reinauer | 6651da3 | 2012-04-27 23:16:30 +0200 | [diff] [blame] | 64 | strncpy((char *)gpios->gpios[2].name,"developer", GPIO_MAX_NAME_LENGTH); |
| 65 | |
| 66 | /* Hard code the lid switch GPIO to open. */ |
Duncan Laurie | c64947b | 2012-10-01 13:31:25 -0700 | [diff] [blame] | 67 | gpios->gpios[3].port = -1; |
Stefan Reinauer | 6651da3 | 2012-04-27 23:16:30 +0200 | [diff] [blame] | 68 | gpios->gpios[3].polarity = ACTIVE_HIGH; |
| 69 | gpios->gpios[3].value = 1; |
| 70 | strncpy((char *)gpios->gpios[3].name,"lid", GPIO_MAX_NAME_LENGTH); |
| 71 | |
| 72 | /* Power Button */ |
Duncan Laurie | c64947b | 2012-10-01 13:31:25 -0700 | [diff] [blame] | 73 | gpios->gpios[4].port = -1; |
| 74 | gpios->gpios[4].polarity = ACTIVE_HIGH; |
| 75 | gpios->gpios[4].value = 0; |
Stefan Reinauer | 6651da3 | 2012-04-27 23:16:30 +0200 | [diff] [blame] | 76 | strncpy((char *)gpios->gpios[4].name,"power", GPIO_MAX_NAME_LENGTH); |
Duncan Laurie | c64947b | 2012-10-01 13:31:25 -0700 | [diff] [blame] | 77 | |
| 78 | /* Did we load the VGA option ROM? */ |
| 79 | gpios->gpios[5].port = -1; |
| 80 | gpios->gpios[5].polarity = ACTIVE_HIGH; |
Kyösti Mälkki | ab56b3b | 2013-11-28 16:44:51 +0200 | [diff] [blame] | 81 | gpios->gpios[5].value = gfx_get_init_done(); |
Duncan Laurie | c64947b | 2012-10-01 13:31:25 -0700 | [diff] [blame] | 82 | strncpy((char *)gpios->gpios[5].name,"oprom", GPIO_MAX_NAME_LENGTH); |
Stefan Reinauer | 6651da3 | 2012-04-27 23:16:30 +0200 | [diff] [blame] | 83 | } |
| 84 | #endif |
| 85 | |
| 86 | int get_developer_mode_switch(void) |
| 87 | { |
Stefan Reinauer | 6651da3 | 2012-04-27 23:16:30 +0200 | [diff] [blame] | 88 | device_t dev; |
| 89 | #ifdef __PRE_RAM__ |
| 90 | dev = PCI_DEV(0, 0x1f, 0); |
| 91 | #else |
| 92 | dev = dev_find_slot(0, PCI_DEVFN(0x1f,0)); |
| 93 | #endif |
| 94 | u16 gpio_base = pci_read_config32(dev, GPIOBASE) & 0xfffe; |
Gabe Black | f40a259 | 2012-03-29 18:04:56 -0700 | [diff] [blame] | 95 | u32 gp_lvl2 = inl(gpio_base + 0x38); |
Stefan Reinauer | 6651da3 | 2012-04-27 23:16:30 +0200 | [diff] [blame] | 96 | |
Gabe Black | f40a259 | 2012-03-29 18:04:56 -0700 | [diff] [blame] | 97 | /* Developer: GPIO17, active high */ |
| 98 | return (gp_lvl2 >> (57-32)) & 1; |
Stefan Reinauer | 6651da3 | 2012-04-27 23:16:30 +0200 | [diff] [blame] | 99 | } |
| 100 | |
| 101 | int get_recovery_mode_switch(void) |
| 102 | { |
| 103 | device_t dev; |
| 104 | #ifdef __PRE_RAM__ |
| 105 | dev = PCI_DEV(0, 0x1f, 0); |
| 106 | #else |
| 107 | dev = dev_find_slot(0, PCI_DEVFN(0x1f,0)); |
| 108 | #endif |
| 109 | u16 gpio_base = pci_read_config32(dev, GPIOBASE) & 0xfffe; |
Gabe Black | f40a259 | 2012-03-29 18:04:56 -0700 | [diff] [blame] | 110 | u32 gp_lvl = inl(gpio_base + 0x0c); |
Stefan Reinauer | 6651da3 | 2012-04-27 23:16:30 +0200 | [diff] [blame] | 111 | |
Gabe Black | f40a259 | 2012-03-29 18:04:56 -0700 | [diff] [blame] | 112 | /* Recovery: GPIO22, active low */ |
| 113 | return !((gp_lvl >> 22) & 1); |
Stefan Reinauer | 6651da3 | 2012-04-27 23:16:30 +0200 | [diff] [blame] | 114 | } |
| 115 | |