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