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> |
| 23 | #ifdef __PRE_RAM__ |
| 24 | #include <arch/romcc_io.h> |
| 25 | #else |
| 26 | #include <device/device.h> |
| 27 | #include <device/pci.h> |
| 28 | #endif |
| 29 | #include <southbridge/intel/lynxpoint/pch.h> |
| 30 | |
| 31 | #ifndef __PRE_RAM__ |
| 32 | #include <boot/coreboot_tables.h> |
| 33 | #include <arch/coreboot_tables.h> |
| 34 | |
| 35 | #define GPIO_COUNT 6 |
| 36 | #define ACTIVE_LOW 0 |
| 37 | #define ACTIVE_HIGH 1 |
| 38 | |
| 39 | void fill_lb_gpios(struct lb_gpios *gpios) |
| 40 | { |
| 41 | device_t dev = dev_find_slot(0, PCI_DEVFN(0x1f,0)); |
| 42 | u16 gpio_base = pci_read_config32(dev, GPIOBASE) & 0xfffe; |
| 43 | |
| 44 | if (!gpio_base) |
| 45 | return; |
| 46 | |
| 47 | u32 gp_lvl = inl(gpio_base + 0x0c); |
| 48 | u32 gp_lvl2 = inl(gpio_base + 0x38); |
| 49 | /* u32 gp_lvl3 = inl(gpio_base + 0x48); */ |
| 50 | |
| 51 | gpios->size = sizeof(*gpios) + (GPIO_COUNT * sizeof(struct lb_gpio)); |
| 52 | gpios->count = GPIO_COUNT; |
| 53 | |
| 54 | /* Write Protect: GPIO48 */ |
| 55 | gpios->gpios[0].port = 48; |
| 56 | gpios->gpios[0].polarity = ACTIVE_LOW; |
| 57 | gpios->gpios[0].value = (gp_lvl2 >> (48-32)) & 1; |
| 58 | strncpy((char *)gpios->gpios[0].name,"write protect", |
| 59 | GPIO_MAX_NAME_LENGTH); |
| 60 | |
| 61 | /* Recovery: GPIO22 */ |
| 62 | gpios->gpios[1].port = 22; |
| 63 | gpios->gpios[1].polarity = ACTIVE_LOW; |
| 64 | gpios->gpios[1].value = (gp_lvl >> 22) & 1; |
| 65 | strncpy((char *)gpios->gpios[1].name,"recovery", GPIO_MAX_NAME_LENGTH); |
| 66 | |
| 67 | /* Developer: GPIO57 */ |
| 68 | gpios->gpios[2].port = 57; |
| 69 | gpios->gpios[2].polarity = ACTIVE_LOW; |
| 70 | gpios->gpios[2].value = (gp_lvl2 >> (57-32)) & 1; |
| 71 | strncpy((char *)gpios->gpios[2].name,"developer", GPIO_MAX_NAME_LENGTH); |
| 72 | |
| 73 | /* Hard code the lid switch GPIO to open. */ |
| 74 | gpios->gpios[3].port = -1; |
| 75 | gpios->gpios[3].polarity = ACTIVE_HIGH; |
| 76 | gpios->gpios[3].value = 1; |
| 77 | strncpy((char *)gpios->gpios[3].name,"lid", GPIO_MAX_NAME_LENGTH); |
| 78 | |
| 79 | /* Power Button */ |
| 80 | gpios->gpios[4].port = -1; |
| 81 | gpios->gpios[4].polarity = ACTIVE_HIGH; |
| 82 | gpios->gpios[4].value = 0; |
| 83 | strncpy((char *)gpios->gpios[4].name,"power", GPIO_MAX_NAME_LENGTH); |
| 84 | |
| 85 | /* Did we load the VGA option ROM? */ |
| 86 | gpios->gpios[5].port = -1; |
| 87 | gpios->gpios[5].polarity = ACTIVE_HIGH; |
| 88 | gpios->gpios[5].value = oprom_is_loaded; |
| 89 | strncpy((char *)gpios->gpios[5].name,"oprom", GPIO_MAX_NAME_LENGTH); |
| 90 | } |
| 91 | #endif |
| 92 | |
| 93 | int get_developer_mode_switch(void) |
| 94 | { |
| 95 | device_t dev; |
| 96 | #ifdef __PRE_RAM__ |
| 97 | dev = PCI_DEV(0, 0x1f, 0); |
| 98 | #else |
| 99 | dev = dev_find_slot(0, PCI_DEVFN(0x1f,0)); |
| 100 | #endif |
| 101 | u16 gpio_base = pci_read_config32(dev, GPIOBASE) & 0xfffe; |
| 102 | u32 gp_lvl2 = inl(gpio_base + 0x38); |
| 103 | |
| 104 | /* Developer: GPIO17, active high */ |
| 105 | return (gp_lvl2 >> (57-32)) & 1; |
| 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; |
| 117 | u32 gp_lvl = inl(gpio_base + 0x0c); |
| 118 | |
| 119 | /* Recovery: GPIO22, active low */ |
| 120 | return !((gp_lvl >> 22) & 1); |
| 121 | } |
| 122 | |