Stefan Reinauer | e1ae4b2 | 2012-04-27 23:20:58 +0200 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright (C) 2011 The ChromiumOS 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 | e1ae4b2 | 2012-04-27 23:20:58 +0200 | [diff] [blame] | 14 | */ |
| 15 | |
| 16 | #include <string.h> |
Kyösti Mälkki | e3ddee0 | 2014-05-03 10:45:28 +0300 | [diff] [blame] | 17 | #include <bootmode.h> |
Stefan Reinauer | e1ae4b2 | 2012-04-27 23:20:58 +0200 | [diff] [blame] | 18 | #include <arch/io.h> |
Stefan Reinauer | e1ae4b2 | 2012-04-27 23:20:58 +0200 | [diff] [blame] | 19 | #include <device/device.h> |
| 20 | #include <device/pci.h> |
Stefan Reinauer | e1ae4b2 | 2012-04-27 23:20:58 +0200 | [diff] [blame] | 21 | #include <southbridge/intel/bd82x6x/pch.h> |
| 22 | |
| 23 | #define GPIO_SPI_WP 68 |
| 24 | #define GPIO_REC_MODE 42 |
| 25 | #define GPIO_DEV_MODE 17 |
| 26 | |
| 27 | #define FLAG_SPI_WP 0 |
| 28 | #define FLAG_REC_MODE 1 |
| 29 | #define FLAG_DEV_MODE 2 |
| 30 | |
| 31 | #ifndef __PRE_RAM__ |
Stefan Reinauer | 3e4e303 | 2013-03-20 14:08:04 -0700 | [diff] [blame] | 32 | #include <boot/coreboot_tables.h> |
Stefan Reinauer | e1ae4b2 | 2012-04-27 23:20:58 +0200 | [diff] [blame] | 33 | |
Vadim Bendebury | 6b3d09e | 2012-08-28 14:37:57 -0700 | [diff] [blame] | 34 | #define GPIO_COUNT 6 |
Stefan Reinauer | e1ae4b2 | 2012-04-27 23:20:58 +0200 | [diff] [blame] | 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 gen_pmcon_1 = pci_read_config32(dev, GEN_PMCON_1); |
| 40 | |
| 41 | gpios->size = sizeof(*gpios) + (GPIO_COUNT * sizeof(struct lb_gpio)); |
| 42 | gpios->count = GPIO_COUNT; |
| 43 | |
| 44 | /* Write Protect: GPIO68 = CHP3_SPI_WP */ |
| 45 | gpios->gpios[0].port = GPIO_SPI_WP; |
| 46 | gpios->gpios[0].polarity = ACTIVE_HIGH; |
Patrick Georgi | 94b8ad4 | 2015-06-30 12:49:50 +0200 | [diff] [blame] | 47 | gpios->gpios[0].value = get_write_protect_state(); |
Stefan Reinauer | e1ae4b2 | 2012-04-27 23:20:58 +0200 | [diff] [blame] | 48 | strncpy((char *)gpios->gpios[0].name,"write protect", |
| 49 | GPIO_MAX_NAME_LENGTH); |
| 50 | |
| 51 | /* Recovery: GPIO42 = CHP3_REC_MODE# */ |
| 52 | gpios->gpios[1].port = GPIO_REC_MODE; |
| 53 | gpios->gpios[1].polarity = ACTIVE_LOW; |
| 54 | gpios->gpios[1].value = !get_recovery_mode_switch(); |
| 55 | strncpy((char *)gpios->gpios[1].name,"recovery", GPIO_MAX_NAME_LENGTH); |
| 56 | |
| 57 | /* Developer: GPIO17 = KBC3_DVP_MODE */ |
| 58 | gpios->gpios[2].port = GPIO_DEV_MODE; |
| 59 | gpios->gpios[2].polarity = ACTIVE_HIGH; |
| 60 | gpios->gpios[2].value = get_developer_mode_switch(); |
| 61 | strncpy((char *)gpios->gpios[2].name,"developer", GPIO_MAX_NAME_LENGTH); |
| 62 | |
| 63 | /* Hard code the lid switch GPIO to open. */ |
| 64 | gpios->gpios[3].port = 100; |
| 65 | gpios->gpios[3].polarity = ACTIVE_HIGH; |
| 66 | gpios->gpios[3].value = 1; |
| 67 | strncpy((char *)gpios->gpios[3].name,"lid", GPIO_MAX_NAME_LENGTH); |
| 68 | |
| 69 | /* Power Button */ |
| 70 | gpios->gpios[4].port = 101; |
| 71 | gpios->gpios[4].polarity = ACTIVE_LOW; |
| 72 | gpios->gpios[4].value = (gen_pmcon_1 >> 9) & 1; |
| 73 | strncpy((char *)gpios->gpios[4].name,"power", GPIO_MAX_NAME_LENGTH); |
Vadim Bendebury | 6b3d09e | 2012-08-28 14:37:57 -0700 | [diff] [blame] | 74 | |
| 75 | /* Did we load the VGA Option ROM? */ |
| 76 | gpios->gpios[5].port = -1; /* Indicate that this is a pseudo GPIO */ |
| 77 | gpios->gpios[5].polarity = ACTIVE_HIGH; |
Kyösti Mälkki | ab56b3b | 2013-11-28 16:44:51 +0200 | [diff] [blame] | 78 | gpios->gpios[5].value = gfx_get_init_done(); |
Vadim Bendebury | 6b3d09e | 2012-08-28 14:37:57 -0700 | [diff] [blame] | 79 | strncpy((char *)gpios->gpios[5].name,"oprom", GPIO_MAX_NAME_LENGTH); |
Stefan Reinauer | e1ae4b2 | 2012-04-27 23:20:58 +0200 | [diff] [blame] | 80 | } |
| 81 | #endif |
| 82 | |
Patrick Georgi | 94b8ad4 | 2015-06-30 12:49:50 +0200 | [diff] [blame] | 83 | int get_write_protect_state(void) |
| 84 | { |
| 85 | device_t dev; |
| 86 | #ifdef __PRE_RAM__ |
| 87 | dev = PCI_DEV(0, 0x1f, 2); |
| 88 | #else |
| 89 | dev = dev_find_slot(0, PCI_DEVFN(0x1f, 2)); |
| 90 | #endif |
| 91 | return (pci_read_config32(dev, SATA_SP) >> FLAG_SPI_WP) & 1; |
| 92 | } |
| 93 | |
Stefan Reinauer | e1ae4b2 | 2012-04-27 23:20:58 +0200 | [diff] [blame] | 94 | int get_developer_mode_switch(void) |
| 95 | { |
| 96 | device_t dev; |
| 97 | #ifdef __PRE_RAM__ |
| 98 | dev = PCI_DEV(0, 0x1f, 2); |
| 99 | #else |
| 100 | dev = dev_find_slot(0, PCI_DEVFN(0x1f, 2)); |
| 101 | #endif |
| 102 | return (pci_read_config32(dev, SATA_SP) >> FLAG_DEV_MODE) & 1; |
| 103 | } |
| 104 | |
| 105 | int get_recovery_mode_switch(void) |
| 106 | { |
| 107 | device_t dev; |
| 108 | #ifdef __PRE_RAM__ |
| 109 | dev = PCI_DEV(0, 0x1f, 2); |
| 110 | #else |
| 111 | dev = dev_find_slot(0, PCI_DEVFN(0x1f, 2)); |
| 112 | #endif |
| 113 | return (pci_read_config32(dev, SATA_SP) >> FLAG_REC_MODE) & 1; |
| 114 | } |
| 115 | |
Kyösti Mälkki | e3ddee0 | 2014-05-03 10:45:28 +0300 | [diff] [blame] | 116 | void init_bootmode_straps(void) |
Stefan Reinauer | e1ae4b2 | 2012-04-27 23:20:58 +0200 | [diff] [blame] | 117 | { |
Kyösti Mälkki | e3ddee0 | 2014-05-03 10:45:28 +0300 | [diff] [blame] | 118 | #ifdef __PRE_RAM__ |
Stefan Reinauer | e1ae4b2 | 2012-04-27 23:20:58 +0200 | [diff] [blame] | 119 | u16 gpio_base = pci_read_config32(PCH_LPC_DEV, GPIO_BASE) & 0xfffe; |
| 120 | u32 gp_lvl3 = inl(gpio_base + GP_LVL3); |
| 121 | u32 gp_lvl2 = inl(gpio_base + GP_LVL2); |
| 122 | u32 gp_lvl = inl(gpio_base + GP_LVL); |
| 123 | u32 flags = 0; |
| 124 | |
| 125 | /* Write Protect: GPIO68 = CHP3_SPI_WP, active high */ |
| 126 | if (gp_lvl3 & (1 << (GPIO_SPI_WP-64))) |
| 127 | flags |= (1 << FLAG_SPI_WP); |
| 128 | /* Recovery: GPIO42 = CHP3_REC_MODE#, active low */ |
| 129 | if (!(gp_lvl2 & (1 << (GPIO_REC_MODE-32)))) |
| 130 | flags |= (1 << FLAG_REC_MODE); |
| 131 | /* Developer: GPIO17 = KBC3_DVP_MODE, active high */ |
| 132 | if (gp_lvl & (1 << GPIO_DEV_MODE)) |
| 133 | flags |= (1 << FLAG_DEV_MODE); |
| 134 | |
| 135 | pci_write_config32(PCI_DEV(0, 0x1f, 2), SATA_SP, flags); |
Stefan Reinauer | e1ae4b2 | 2012-04-27 23:20:58 +0200 | [diff] [blame] | 136 | #endif |
Kyösti Mälkki | e3ddee0 | 2014-05-03 10:45:28 +0300 | [diff] [blame] | 137 | } |