Aaron Durbin | f6933a6 | 2012-10-30 09:09:39 -0500 | [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 | 1645589 | 2014-04-28 23:41:06 +0300 | [diff] [blame^] | 21 | #include <bootmode.h> |
Aaron Durbin | f6933a6 | 2012-10-30 09:09:39 -0500 | [diff] [blame] | 22 | #include <arch/io.h> |
Aaron Durbin | f6933a6 | 2012-10-30 09:09:39 -0500 | [diff] [blame] | 23 | #include <device/device.h> |
| 24 | #include <device/pci.h> |
Aaron Durbin | f6933a6 | 2012-10-30 09:09:39 -0500 | [diff] [blame] | 25 | #include <southbridge/intel/lynxpoint/pch.h> |
Aaron Durbin | 0160d76 | 2012-12-13 16:51:41 -0600 | [diff] [blame] | 26 | #include <southbridge/intel/lynxpoint/gpio.h> |
Aaron Durbin | f6933a6 | 2012-10-30 09:09:39 -0500 | [diff] [blame] | 27 | |
| 28 | #ifndef __PRE_RAM__ |
| 29 | #include <boot/coreboot_tables.h> |
Aaron Durbin | f6933a6 | 2012-10-30 09:09:39 -0500 | [diff] [blame] | 30 | |
| 31 | #define GPIO_COUNT 6 |
Aaron Durbin | f6933a6 | 2012-10-30 09:09:39 -0500 | [diff] [blame] | 32 | |
| 33 | void fill_lb_gpios(struct lb_gpios *gpios) |
| 34 | { |
| 35 | device_t dev = dev_find_slot(0, PCI_DEVFN(0x1f,0)); |
| 36 | u16 gpio_base = pci_read_config32(dev, GPIOBASE) & 0xfffe; |
| 37 | |
| 38 | if (!gpio_base) |
| 39 | return; |
| 40 | |
Aaron Durbin | 0160d76 | 2012-12-13 16:51:41 -0600 | [diff] [blame] | 41 | u32 gp_lvl = inl(gpio_base + GP_LVL); |
| 42 | u32 gp_lvl2 = inl(gpio_base + GP_LVL2); |
| 43 | u32 gp_lvl3 = inl(gpio_base + GP_LVL3); |
Aaron Durbin | f6933a6 | 2012-10-30 09:09:39 -0500 | [diff] [blame] | 44 | |
| 45 | gpios->size = sizeof(*gpios) + (GPIO_COUNT * sizeof(struct lb_gpio)); |
| 46 | gpios->count = GPIO_COUNT; |
| 47 | |
Aaron Durbin | 0160d76 | 2012-12-13 16:51:41 -0600 | [diff] [blame] | 48 | /* Write Protect: GPIO22 */ |
| 49 | gpios->gpios[0].port = 0; |
Aaron Durbin | f6933a6 | 2012-10-30 09:09:39 -0500 | [diff] [blame] | 50 | gpios->gpios[0].polarity = ACTIVE_LOW; |
Aaron Durbin | 0160d76 | 2012-12-13 16:51:41 -0600 | [diff] [blame] | 51 | gpios->gpios[0].value = (gp_lvl >> 22) & 1; |
Aaron Durbin | f6933a6 | 2012-10-30 09:09:39 -0500 | [diff] [blame] | 52 | strncpy((char *)gpios->gpios[0].name,"write protect", |
| 53 | GPIO_MAX_NAME_LENGTH); |
| 54 | |
Aaron Durbin | 0160d76 | 2012-12-13 16:51:41 -0600 | [diff] [blame] | 55 | /* Recovery: GPIO69 - SV_DETECT - J8E3 (silkscreen: J8E2) */ |
| 56 | gpios->gpios[1].port = 69; |
| 57 | gpios->gpios[1].polarity = ACTIVE_HIGH; |
| 58 | gpios->gpios[1].value = (gp_lvl3 >> (69-64)) & 1; |
Aaron Durbin | f6933a6 | 2012-10-30 09:09:39 -0500 | [diff] [blame] | 59 | strncpy((char *)gpios->gpios[1].name,"recovery", GPIO_MAX_NAME_LENGTH); |
| 60 | |
Aaron Durbin | 0160d76 | 2012-12-13 16:51:41 -0600 | [diff] [blame] | 61 | /* Developer: GPIO48 - BIOS_RESP - J8E4 (silkscreen: J8E3) */ |
| 62 | gpios->gpios[2].port = 48; |
Aaron Durbin | f6933a6 | 2012-10-30 09:09:39 -0500 | [diff] [blame] | 63 | gpios->gpios[2].polarity = ACTIVE_LOW; |
Aaron Durbin | 0160d76 | 2012-12-13 16:51:41 -0600 | [diff] [blame] | 64 | gpios->gpios[2].value = (gp_lvl2 >> (48-32)) & 1; |
Aaron Durbin | f6933a6 | 2012-10-30 09:09:39 -0500 | [diff] [blame] | 65 | strncpy((char *)gpios->gpios[2].name,"developer", GPIO_MAX_NAME_LENGTH); |
| 66 | |
| 67 | /* Hard code the lid switch GPIO to open. */ |
| 68 | gpios->gpios[3].port = -1; |
| 69 | gpios->gpios[3].polarity = ACTIVE_HIGH; |
| 70 | gpios->gpios[3].value = 1; |
| 71 | strncpy((char *)gpios->gpios[3].name,"lid", GPIO_MAX_NAME_LENGTH); |
| 72 | |
| 73 | /* Power Button */ |
| 74 | gpios->gpios[4].port = -1; |
| 75 | gpios->gpios[4].polarity = ACTIVE_HIGH; |
| 76 | gpios->gpios[4].value = 0; |
| 77 | strncpy((char *)gpios->gpios[4].name,"power", GPIO_MAX_NAME_LENGTH); |
| 78 | |
| 79 | /* Did we load the VGA option ROM? */ |
| 80 | gpios->gpios[5].port = -1; |
| 81 | gpios->gpios[5].polarity = ACTIVE_HIGH; |
Kyösti Mälkki | ab56b3b | 2013-11-28 16:44:51 +0200 | [diff] [blame] | 82 | gpios->gpios[5].value = gfx_get_init_done(); |
Aaron Durbin | f6933a6 | 2012-10-30 09:09:39 -0500 | [diff] [blame] | 83 | strncpy((char *)gpios->gpios[5].name,"oprom", GPIO_MAX_NAME_LENGTH); |
| 84 | } |
| 85 | #endif |
| 86 | |
| 87 | int get_developer_mode_switch(void) |
| 88 | { |
| 89 | device_t dev; |
| 90 | #ifdef __PRE_RAM__ |
| 91 | dev = PCI_DEV(0, 0x1f, 0); |
| 92 | #else |
| 93 | dev = dev_find_slot(0, PCI_DEVFN(0x1f,0)); |
| 94 | #endif |
| 95 | u16 gpio_base = pci_read_config32(dev, GPIOBASE) & 0xfffe; |
Aaron Durbin | 0160d76 | 2012-12-13 16:51:41 -0600 | [diff] [blame] | 96 | u32 gp_lvl2 = inl(gpio_base + GP_LVL2); |
Aaron Durbin | f6933a6 | 2012-10-30 09:09:39 -0500 | [diff] [blame] | 97 | |
Aaron Durbin | 0160d76 | 2012-12-13 16:51:41 -0600 | [diff] [blame] | 98 | /* |
| 99 | * Developer: GPIO48, Connected to J8E4, however the silkscreen says |
| 100 | * J8E3. The jumper is active low. |
| 101 | */ |
| 102 | return !((gp_lvl2 >> (48-32)) & 1); |
Aaron Durbin | f6933a6 | 2012-10-30 09:09:39 -0500 | [diff] [blame] | 103 | } |
| 104 | |
| 105 | int get_recovery_mode_switch(void) |
| 106 | { |
| 107 | device_t dev; |
| 108 | #ifdef __PRE_RAM__ |
| 109 | dev = PCI_DEV(0, 0x1f, 0); |
| 110 | #else |
| 111 | dev = dev_find_slot(0, PCI_DEVFN(0x1f,0)); |
| 112 | #endif |
| 113 | u16 gpio_base = pci_read_config32(dev, GPIOBASE) & 0xfffe; |
Aaron Durbin | 0160d76 | 2012-12-13 16:51:41 -0600 | [diff] [blame] | 114 | u32 gp_lvl3 = inl(gpio_base + GP_LVL3); |
Aaron Durbin | f6933a6 | 2012-10-30 09:09:39 -0500 | [diff] [blame] | 115 | |
Aaron Durbin | 0160d76 | 2012-12-13 16:51:41 -0600 | [diff] [blame] | 116 | /* |
| 117 | * Recovery: GPIO69, Connected to J8E3, however the silkscreen says |
| 118 | * J8E2. The jump is active high. |
| 119 | */ |
| 120 | return (gp_lvl3 >> (69-64)) & 1; |
Aaron Durbin | f6933a6 | 2012-10-30 09:09:39 -0500 | [diff] [blame] | 121 | } |
| 122 | |
Aaron Durbin | 0df4de9 | 2013-03-01 17:38:59 -0600 | [diff] [blame] | 123 | int get_write_protect_state(void) |
| 124 | { |
| 125 | return 0; |
| 126 | } |
| 127 | |