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