Frank Vibrans | 63e62b0 | 2011-02-14 18:38:14 +0000 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright (C) 2011 Advanced Micro Devices, Inc. |
Dave Frodin | ac1b875 | 2014-06-05 14:30:22 -0600 | [diff] [blame] | 5 | * Copyright (C) 2014 Sage Electronic Engineering, LLC |
Frank Vibrans | 63e62b0 | 2011-02-14 18:38:14 +0000 | [diff] [blame] | 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License as published by |
| 9 | * the Free Software Foundation; version 2 of the License. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with this program; if not, write to the Free Software |
Paul Menzel | a46a712 | 2013-02-23 18:37:27 +0100 | [diff] [blame] | 18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
Frank Vibrans | 63e62b0 | 2011-02-14 18:38:14 +0000 | [diff] [blame] | 19 | */ |
| 20 | |
Kerry She | feed329 | 2011-08-18 18:03:44 +0800 | [diff] [blame] | 21 | #include <console/console.h> |
Frank Vibrans | 63e62b0 | 2011-02-14 18:38:14 +0000 | [diff] [blame] | 22 | #include <device/pci.h> |
Martin Roth | 3aef7b4 | 2012-12-05 15:50:32 -0700 | [diff] [blame] | 23 | #include <device/pci_def.h> |
Patrick Georgi | 2c2e78d | 2012-02-16 18:54:37 +0100 | [diff] [blame] | 24 | #include <arch/ioapic.h> |
Frank Vibrans | 63e62b0 | 2011-02-14 18:38:14 +0000 | [diff] [blame] | 25 | #include "lpc.h" |
zbao | 9bcdbf8 | 2012-04-05 13:18:49 +0800 | [diff] [blame] | 26 | #include <arch/io.h> |
| 27 | #include <cbmem.h> |
Frank Vibrans | 63e62b0 | 2011-02-14 18:38:14 +0000 | [diff] [blame] | 28 | |
| 29 | void lpc_read_resources(device_t dev) |
| 30 | { |
| 31 | struct resource *res; |
| 32 | |
Kerry She | feed329 | 2011-08-18 18:03:44 +0800 | [diff] [blame] | 33 | printk(BIOS_DEBUG, "SB800 - Lpc.c - lpc_read_resources - Start.\n"); |
Frank Vibrans | 63e62b0 | 2011-02-14 18:38:14 +0000 | [diff] [blame] | 34 | /* Get the normal pci resources of this device */ |
| 35 | pci_dev_read_resources(dev); /* We got one for APIC, or one more for TRAP */ |
| 36 | |
Frank Vibrans | 63e62b0 | 2011-02-14 18:38:14 +0000 | [diff] [blame] | 37 | /* Add an extra subtractive resource for both memory and I/O. */ |
| 38 | res = new_resource(dev, IOINDEX_SUBTRACTIVE(0, 0)); |
| 39 | res->base = 0; |
| 40 | res->size = 0x1000; |
| 41 | res->flags = IORESOURCE_IO | IORESOURCE_SUBTRACTIVE | |
| 42 | IORESOURCE_ASSIGNED | IORESOURCE_FIXED; |
| 43 | |
| 44 | res = new_resource(dev, IOINDEX_SUBTRACTIVE(1, 0)); |
| 45 | res->base = 0xff800000; |
| 46 | res->size = 0x00800000; /* 8 MB for flash */ |
| 47 | res->flags = IORESOURCE_MEM | IORESOURCE_SUBTRACTIVE | |
| 48 | IORESOURCE_ASSIGNED | IORESOURCE_FIXED; |
| 49 | |
Dave Frodin | ac1b875 | 2014-06-05 14:30:22 -0600 | [diff] [blame] | 50 | /* Add a memory resource for the SPI BAR. */ |
| 51 | fixed_mem_resource(dev, 2, SPI_BASE_ADDRESS / 1024, 1, IORESOURCE_SUBTRACTIVE); |
| 52 | |
Patrick Georgi | 2c2e78d | 2012-02-16 18:54:37 +0100 | [diff] [blame] | 53 | res = new_resource(dev, 3); |
| 54 | res->base = IO_APIC_ADDR; |
Frank Vibrans | 63e62b0 | 2011-02-14 18:38:14 +0000 | [diff] [blame] | 55 | res->size = 0x00001000; |
| 56 | res->flags = IORESOURCE_MEM | IORESOURCE_ASSIGNED | IORESOURCE_FIXED; |
| 57 | |
| 58 | compact_resources(dev); |
Kerry She | feed329 | 2011-08-18 18:03:44 +0800 | [diff] [blame] | 59 | printk(BIOS_DEBUG, "SB800 - Lpc.c - lpc_read_resources - End.\n"); |
Frank Vibrans | 63e62b0 | 2011-02-14 18:38:14 +0000 | [diff] [blame] | 60 | } |
| 61 | |
| 62 | void lpc_set_resources(struct device *dev) |
| 63 | { |
| 64 | struct resource *res; |
| 65 | |
Kerry She | feed329 | 2011-08-18 18:03:44 +0800 | [diff] [blame] | 66 | printk(BIOS_DEBUG, "SB800 - Lpc.c - lpc_set_resources - Start.\n"); |
Martin Roth | 3aef7b4 | 2012-12-05 15:50:32 -0700 | [diff] [blame] | 67 | |
| 68 | /* Special case. SPI Base Address. The SpiRomEnable should STAY set. */ |
Dave Frodin | ac1b875 | 2014-06-05 14:30:22 -0600 | [diff] [blame] | 69 | res = find_resource(dev, 2); |
| 70 | pci_write_config32(dev, SPIROM_BASE_ADDRESS_REGISTER, res->base | SPI_ROM_ENABLE); |
Martin Roth | 3aef7b4 | 2012-12-05 15:50:32 -0700 | [diff] [blame] | 71 | |
Frank Vibrans | 63e62b0 | 2011-02-14 18:38:14 +0000 | [diff] [blame] | 72 | pci_dev_set_resources(dev); |
| 73 | |
Kerry She | feed329 | 2011-08-18 18:03:44 +0800 | [diff] [blame] | 74 | printk(BIOS_DEBUG, "SB800 - Lpc.c - lpc_set_resources - End.\n"); |
Frank Vibrans | 63e62b0 | 2011-02-14 18:38:14 +0000 | [diff] [blame] | 75 | } |
| 76 | |
| 77 | /** |
| 78 | * @brief Enable resources for children devices |
| 79 | * |
Martin Roth | 3c3a50c | 2014-12-16 20:50:26 -0700 | [diff] [blame^] | 80 | * @param dev the device whose children's resources are to be enabled |
Frank Vibrans | 63e62b0 | 2011-02-14 18:38:14 +0000 | [diff] [blame] | 81 | * |
| 82 | */ |
| 83 | void lpc_enable_childrens_resources(device_t dev) |
| 84 | { |
| 85 | struct bus *link; |
| 86 | u32 reg, reg_x; |
| 87 | int var_num = 0; |
| 88 | u16 reg_var[3]; |
| 89 | |
Kerry She | feed329 | 2011-08-18 18:03:44 +0800 | [diff] [blame] | 90 | printk(BIOS_DEBUG, "SB800 - Lpc.c - lpc_enable_childrens_resources - Start.\n"); |
Frank Vibrans | 63e62b0 | 2011-02-14 18:38:14 +0000 | [diff] [blame] | 91 | reg = pci_read_config32(dev, 0x44); |
| 92 | reg_x = pci_read_config32(dev, 0x48); |
| 93 | |
| 94 | for (link = dev->link_list; link; link = link->next) { |
| 95 | device_t child; |
| 96 | for (child = link->children; child; |
| 97 | child = child->sibling) { |
| 98 | if (child->enabled |
| 99 | && (child->path.type == DEVICE_PATH_PNP)) { |
| 100 | struct resource *res; |
| 101 | for (res = child->resource_list; res; res = res->next) { |
| 102 | u32 base, end; /* don't need long long */ |
| 103 | if (!(res->flags & IORESOURCE_IO)) |
| 104 | continue; |
| 105 | base = res->base; |
| 106 | end = resource_end(res); |
| 107 | /* |
| 108 | printk(BIOS_DEBUG, "sb800 lpc decode:%s, base=0x%08x, end=0x%08x\n", |
| 109 | dev_path(child), base, end); |
| 110 | */ |
| 111 | switch (base) { |
| 112 | case 0x60: /* KB */ |
| 113 | case 0x64: /* MS */ |
| 114 | reg |= (1 << 29); |
| 115 | break; |
| 116 | case 0x3f8: /* COM1 */ |
| 117 | reg |= (1 << 6); |
| 118 | break; |
| 119 | case 0x2f8: /* COM2 */ |
| 120 | reg |= (1 << 7); |
| 121 | break; |
Martin Roth | 3c3a50c | 2014-12-16 20:50:26 -0700 | [diff] [blame^] | 122 | case 0x378: /* Parallel 1 */ |
Frank Vibrans | 63e62b0 | 2011-02-14 18:38:14 +0000 | [diff] [blame] | 123 | reg |= (1 << 0); |
| 124 | break; |
| 125 | case 0x3f0: /* FD0 */ |
| 126 | reg |= (1 << 26); |
| 127 | break; |
Martin Roth | 3c3a50c | 2014-12-16 20:50:26 -0700 | [diff] [blame^] | 128 | case 0x220: /* Audio 0 */ |
Frank Vibrans | 63e62b0 | 2011-02-14 18:38:14 +0000 | [diff] [blame] | 129 | reg |= (1 << 8); |
| 130 | break; |
| 131 | case 0x300: /* Midi 0 */ |
| 132 | reg |= (1 << 18); |
| 133 | break; |
| 134 | case 0x400: |
| 135 | reg_x |= (1 << 16); |
| 136 | break; |
| 137 | case 0x480: |
| 138 | reg_x |= (1 << 17); |
| 139 | break; |
| 140 | case 0x500: |
| 141 | reg_x |= (1 << 18); |
| 142 | break; |
| 143 | case 0x580: |
| 144 | reg_x |= (1 << 19); |
| 145 | break; |
| 146 | case 0x4700: |
| 147 | reg_x |= (1 << 22); |
| 148 | break; |
| 149 | case 0xfd60: |
| 150 | reg_x |= (1 << 23); |
| 151 | break; |
| 152 | default: |
| 153 | if (var_num >= 3) |
| 154 | continue; /* only 3 var ; compact them ? */ |
| 155 | switch (var_num) { |
| 156 | case 0: |
| 157 | reg_x |= (1 << 2); |
| 158 | break; |
| 159 | case 1: |
| 160 | reg_x |= (1 << 24); |
| 161 | break; |
| 162 | case 2: |
| 163 | reg_x |= (1 << 25); |
| 164 | break; |
| 165 | } |
| 166 | reg_var[var_num++] = |
| 167 | base & 0xffff; |
| 168 | } |
| 169 | } |
| 170 | } |
| 171 | } |
| 172 | } |
| 173 | pci_write_config32(dev, 0x44, reg); |
| 174 | pci_write_config32(dev, 0x48, reg_x); |
| 175 | /* Set WideIO for as many IOs found (fall through is on purpose) */ |
| 176 | switch (var_num) { |
| 177 | case 2: |
| 178 | pci_write_config16(dev, 0x90, reg_var[2]); |
| 179 | case 1: |
| 180 | pci_write_config16(dev, 0x66, reg_var[1]); |
| 181 | case 0: |
| 182 | //pci_write_config16(dev, 0x64, reg_var[0]); //cause filo can not find sata |
| 183 | break; |
| 184 | } |
Kerry She | feed329 | 2011-08-18 18:03:44 +0800 | [diff] [blame] | 185 | printk(BIOS_DEBUG, "SB800 - Lpc.c - lpc_enable_childrens_resources - End.\n"); |
Frank Vibrans | 63e62b0 | 2011-02-14 18:38:14 +0000 | [diff] [blame] | 186 | } |