Zheng Bao | eff2ffd | 2010-03-16 01:38:54 +0000 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright (C) 2010 Advanced Micro Devices, Inc. |
| 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 |
Paul Menzel | a46a712 | 2013-02-23 18:37:27 +0100 | [diff] [blame] | 17 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
Zheng Bao | eff2ffd | 2010-03-16 01:38:54 +0000 | [diff] [blame] | 18 | */ |
| 19 | |
| 20 | #include <console/console.h> |
| 21 | #include <device/device.h> |
| 22 | #include <device/pci.h> |
| 23 | #include <device/pnp.h> |
| 24 | #include <device/pci_ids.h> |
| 25 | #include <device/pci_ops.h> |
| 26 | #include <pc80/mc146818rtc.h> |
Vladimir Serbinenko | 6985d4e | 2014-09-21 14:31:19 +0200 | [diff] [blame] | 27 | #include <arch/acpi.h> |
| 28 | #include <arch/acpigen.h> |
Zheng Bao | eff2ffd | 2010-03-16 01:38:54 +0000 | [diff] [blame] | 29 | #include <pc80/isa-dma.h> |
Zheng Bao | eff2ffd | 2010-03-16 01:38:54 +0000 | [diff] [blame] | 30 | #include <arch/io.h> |
Uwe Hermann | 74d1a6e | 2010-10-12 17:34:08 +0000 | [diff] [blame] | 31 | #include <arch/ioapic.h> |
Vladimir Serbinenko | 6985d4e | 2014-09-21 14:31:19 +0200 | [diff] [blame] | 32 | #include <arch/acpi.h> |
Rudolf Marek | c436953 | 2010-12-13 19:59:13 +0000 | [diff] [blame] | 33 | #include <cbmem.h> |
Vladimir Serbinenko | 4743254 | 2014-10-05 14:54:26 +0200 | [diff] [blame] | 34 | #include <cpu/amd/powernow.h> |
Zheng Bao | eff2ffd | 2010-03-16 01:38:54 +0000 | [diff] [blame] | 35 | #include "sb700.h" |
| 36 | |
Vladimir Serbinenko | 6985d4e | 2014-09-21 14:31:19 +0200 | [diff] [blame] | 37 | unsigned long acpi_fill_mcfg(unsigned long current) |
| 38 | { |
| 39 | /* Just a dummy */ |
| 40 | return current; |
| 41 | } |
| 42 | |
Zheng Bao | eff2ffd | 2010-03-16 01:38:54 +0000 | [diff] [blame] | 43 | static void lpc_init(device_t dev) |
| 44 | { |
| 45 | u8 byte; |
| 46 | u32 dword; |
| 47 | device_t sm_dev; |
| 48 | |
| 49 | /* Enable the LPC Controller */ |
| 50 | sm_dev = dev_find_slot(0, PCI_DEVFN(0x14, 0)); |
| 51 | dword = pci_read_config32(sm_dev, 0x64); |
| 52 | dword |= 1 << 20; |
| 53 | pci_write_config32(sm_dev, 0x64, dword); |
| 54 | |
| 55 | /* Initialize isa dma */ |
Juhana Helovuo | 50b78b6 | 2010-09-13 14:43:02 +0000 | [diff] [blame] | 56 | #if CONFIG_SOUTHBRIDGE_AMD_SB700_SKIP_ISA_DMA_INIT |
| 57 | printk(BIOS_DEBUG, "Skipping isa_dma_init() to avoid getting stuck.\n"); |
| 58 | #else |
Zheng Bao | eff2ffd | 2010-03-16 01:38:54 +0000 | [diff] [blame] | 59 | isa_dma_init(); |
Juhana Helovuo | 50b78b6 | 2010-09-13 14:43:02 +0000 | [diff] [blame] | 60 | #endif |
Zheng Bao | eff2ffd | 2010-03-16 01:38:54 +0000 | [diff] [blame] | 61 | |
| 62 | /* Enable DMA transaction on the LPC bus */ |
| 63 | byte = pci_read_config8(dev, 0x40); |
| 64 | byte |= (1 << 2); |
| 65 | pci_write_config8(dev, 0x40, byte); |
| 66 | |
| 67 | /* Disable the timeout mechanism on LPC */ |
| 68 | byte = pci_read_config8(dev, 0x48); |
| 69 | byte &= ~(1 << 7); |
| 70 | pci_write_config8(dev, 0x48, byte); |
| 71 | |
| 72 | /* Disable LPC MSI Capability */ |
| 73 | byte = pci_read_config8(dev, 0x78); |
| 74 | byte &= ~(1 << 1); |
Kyösti Mälkki | 399fcdd | 2012-02-23 18:42:55 +0200 | [diff] [blame] | 75 | #if CONFIG_SOUTHBRIDGE_AMD_SUBTYPE_SP5100 |
Zheng Bao | c342223 | 2011-03-28 03:33:10 +0000 | [diff] [blame] | 76 | /* Disable FlowContrl, Always service the request from Host |
| 77 | * whenever there is a request from Host pending |
| 78 | */ |
| 79 | byte &= ~(1 << 0); |
| 80 | #endif |
Zheng Bao | eff2ffd | 2010-03-16 01:38:54 +0000 | [diff] [blame] | 81 | pci_write_config8(dev, 0x78, byte); |
Rudolf Marek | c436953 | 2010-12-13 19:59:13 +0000 | [diff] [blame] | 82 | |
| 83 | /* hack, but the whole sb700 startup lacks any device which |
| 84 | is doing the acpi init */ |
Patrick Georgi | e166782 | 2012-05-05 15:29:32 +0200 | [diff] [blame] | 85 | #if CONFIG_HAVE_ACPI_RESUME |
Rudolf Marek | c436953 | 2010-12-13 19:59:13 +0000 | [diff] [blame] | 86 | { |
Rudolf Marek | c436953 | 2010-12-13 19:59:13 +0000 | [diff] [blame] | 87 | u16 tmp = inw(ACPI_PM1_CNT_BLK); |
| 88 | acpi_slp_type = ((tmp & (7 << 10)) >> 10); |
| 89 | printk(BIOS_DEBUG, "SLP_TYP type was %x\n", acpi_slp_type); |
| 90 | } |
| 91 | #endif |
zbao | 366f0fc | 2012-08-03 16:58:53 +0800 | [diff] [blame] | 92 | |
Gabe Black | 03abaee21 | 2014-04-30 21:31:44 -0700 | [diff] [blame^] | 93 | cmos_check_update_date(); |
Rudolf Marek | c436953 | 2010-12-13 19:59:13 +0000 | [diff] [blame] | 94 | } |
| 95 | |
Kyösti Mälkki | bc90e15 | 2013-09-04 13:26:11 +0300 | [diff] [blame] | 96 | void backup_top_of_ram(uint64_t ramtop) |
Zheng Bao | a5c949e | 2011-01-27 03:31:50 +0000 | [diff] [blame] | 97 | { |
Kyösti Mälkki | bc90e15 | 2013-09-04 13:26:11 +0300 | [diff] [blame] | 98 | u32 dword = (u32) ramtop; |
Rudolf Marek | c436953 | 2010-12-13 19:59:13 +0000 | [diff] [blame] | 99 | int nvram_pos = 0xfc, i; |
| 100 | for (i = 0; i<4; i++) { |
| 101 | outb(nvram_pos, BIOSRAM_INDEX); |
| 102 | outb((dword >>(8 * i)) & 0xff , BIOSRAM_DATA); |
| 103 | nvram_pos++; |
| 104 | } |
Zheng Bao | eff2ffd | 2010-03-16 01:38:54 +0000 | [diff] [blame] | 105 | } |
| 106 | |
| 107 | static void sb700_lpc_read_resources(device_t dev) |
| 108 | { |
| 109 | struct resource *res; |
| 110 | |
| 111 | /* Get the normal pci resources of this device */ |
| 112 | pci_dev_read_resources(dev); /* We got one for APIC, or one more for TRAP */ |
| 113 | |
| 114 | pci_get_resource(dev, 0xA0); /* SPI ROM base address */ |
| 115 | |
| 116 | /* Add an extra subtractive resource for both memory and I/O. */ |
| 117 | res = new_resource(dev, IOINDEX_SUBTRACTIVE(0, 0)); |
| 118 | res->base = 0; |
| 119 | res->size = 0x1000; |
| 120 | res->flags = IORESOURCE_IO | IORESOURCE_SUBTRACTIVE | |
| 121 | IORESOURCE_ASSIGNED | IORESOURCE_FIXED; |
| 122 | |
| 123 | res = new_resource(dev, IOINDEX_SUBTRACTIVE(1, 0)); |
| 124 | res->base = 0xff800000; |
| 125 | res->size = 0x00800000; /* 8 MB for flash */ |
| 126 | res->flags = IORESOURCE_MEM | IORESOURCE_SUBTRACTIVE | |
| 127 | IORESOURCE_ASSIGNED | IORESOURCE_FIXED; |
| 128 | |
| 129 | res = new_resource(dev, 3); /* IOAPIC */ |
Uwe Hermann | 74d1a6e | 2010-10-12 17:34:08 +0000 | [diff] [blame] | 130 | res->base = IO_APIC_ADDR; |
Zheng Bao | eff2ffd | 2010-03-16 01:38:54 +0000 | [diff] [blame] | 131 | res->size = 0x00001000; |
| 132 | res->flags = IORESOURCE_MEM | IORESOURCE_ASSIGNED | IORESOURCE_FIXED; |
| 133 | |
| 134 | compact_resources(dev); |
| 135 | } |
| 136 | |
| 137 | static void sb700_lpc_set_resources(struct device *dev) |
| 138 | { |
| 139 | struct resource *res; |
Zheng Bao | eff2ffd | 2010-03-16 01:38:54 +0000 | [diff] [blame] | 140 | |
| 141 | pci_dev_set_resources(dev); |
| 142 | |
Martin Roth | dcf253c | 2014-12-16 20:51:31 -0700 | [diff] [blame] | 143 | /* Special case. SPI Base Address. The SpiRomEnable should be set. */ |
Zheng Bao | eff2ffd | 2010-03-16 01:38:54 +0000 | [diff] [blame] | 144 | res = find_resource(dev, 0xA0); |
| 145 | pci_write_config32(dev, 0xA0, res->base | 1 << 1); |
Zheng Bao | eff2ffd | 2010-03-16 01:38:54 +0000 | [diff] [blame] | 146 | } |
| 147 | |
| 148 | /** |
| 149 | * @brief Enable resources for children devices |
| 150 | * |
Zheng Bao | 2a5101a | 2010-10-10 15:18:53 +0000 | [diff] [blame] | 151 | * @param dev the device whose children's resources are to be enabled |
Zheng Bao | eff2ffd | 2010-03-16 01:38:54 +0000 | [diff] [blame] | 152 | * |
Zheng Bao | eff2ffd | 2010-03-16 01:38:54 +0000 | [diff] [blame] | 153 | */ |
| 154 | static void sb700_lpc_enable_childrens_resources(device_t dev) |
| 155 | { |
Myles Watson | 894a347 | 2010-06-09 22:41:35 +0000 | [diff] [blame] | 156 | struct bus *link; |
Zheng Bao | eff2ffd | 2010-03-16 01:38:54 +0000 | [diff] [blame] | 157 | u32 reg, reg_x; |
Zheng Bao | eff2ffd | 2010-03-16 01:38:54 +0000 | [diff] [blame] | 158 | int var_num = 0; |
Rudolf Marek | 86bd99a | 2011-01-28 20:57:48 +0000 | [diff] [blame] | 159 | u16 reg_var[3] = {0x0, 0x0, 0x0}; |
| 160 | u8 wiosize = pci_read_config8(dev, 0x74); |
Zheng Bao | eff2ffd | 2010-03-16 01:38:54 +0000 | [diff] [blame] | 161 | |
| 162 | reg = pci_read_config32(dev, 0x44); |
| 163 | reg_x = pci_read_config32(dev, 0x48); |
| 164 | |
Myles Watson | 894a347 | 2010-06-09 22:41:35 +0000 | [diff] [blame] | 165 | for (link = dev->link_list; link; link = link->next) { |
Zheng Bao | eff2ffd | 2010-03-16 01:38:54 +0000 | [diff] [blame] | 166 | device_t child; |
Myles Watson | 894a347 | 2010-06-09 22:41:35 +0000 | [diff] [blame] | 167 | for (child = link->children; child; |
Zheng Bao | eff2ffd | 2010-03-16 01:38:54 +0000 | [diff] [blame] | 168 | child = child->sibling) { |
Zheng Bao | eff2ffd | 2010-03-16 01:38:54 +0000 | [diff] [blame] | 169 | if (child->enabled |
| 170 | && (child->path.type == DEVICE_PATH_PNP)) { |
Myles Watson | c25cc11 | 2010-05-21 14:33:48 +0000 | [diff] [blame] | 171 | struct resource *res; |
| 172 | for (res = child->resource_list; res; res = res->next) { |
Zheng Bao | eff2ffd | 2010-03-16 01:38:54 +0000 | [diff] [blame] | 173 | u32 base, end; /* don't need long long */ |
Zheng Bao | eff2ffd | 2010-03-16 01:38:54 +0000 | [diff] [blame] | 174 | if (!(res->flags & IORESOURCE_IO)) |
| 175 | continue; |
| 176 | base = res->base; |
| 177 | end = resource_end(res); |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 178 | printk(BIOS_DEBUG, "sb700 lpc decode:%s, base=0x%08x, end=0x%08x\n", |
Zheng Bao | eff2ffd | 2010-03-16 01:38:54 +0000 | [diff] [blame] | 179 | dev_path(child), base, end); |
| 180 | switch (base) { |
| 181 | case 0x60: /* KB */ |
| 182 | case 0x64: /* MS */ |
| 183 | reg |= (1 << 29); |
| 184 | break; |
| 185 | case 0x3f8: /* COM1 */ |
| 186 | reg |= (1 << 6); |
| 187 | break; |
| 188 | case 0x2f8: /* COM2 */ |
| 189 | reg |= (1 << 7); |
| 190 | break; |
Rudolf Marek | 86bd99a | 2011-01-28 20:57:48 +0000 | [diff] [blame] | 191 | case 0x378: /* Parallel 1 */ |
Zheng Bao | eff2ffd | 2010-03-16 01:38:54 +0000 | [diff] [blame] | 192 | reg |= (1 << 0); |
Rudolf Marek | 86bd99a | 2011-01-28 20:57:48 +0000 | [diff] [blame] | 193 | reg |= (1 << 1); /* + 0x778 for ECP */ |
Zheng Bao | eff2ffd | 2010-03-16 01:38:54 +0000 | [diff] [blame] | 194 | break; |
| 195 | case 0x3f0: /* FD0 */ |
| 196 | reg |= (1 << 26); |
| 197 | break; |
Rudolf Marek | 86bd99a | 2011-01-28 20:57:48 +0000 | [diff] [blame] | 198 | case 0x220: /* Audio 0 */ |
Zheng Bao | eff2ffd | 2010-03-16 01:38:54 +0000 | [diff] [blame] | 199 | reg |= (1 << 8); |
| 200 | break; |
| 201 | case 0x300: /* Midi 0 */ |
| 202 | reg |= (1 << 18); |
| 203 | break; |
| 204 | case 0x400: |
| 205 | reg_x |= (1 << 16); |
| 206 | break; |
| 207 | case 0x480: |
| 208 | reg_x |= (1 << 17); |
| 209 | break; |
| 210 | case 0x500: |
| 211 | reg_x |= (1 << 18); |
| 212 | break; |
| 213 | case 0x580: |
| 214 | reg_x |= (1 << 19); |
| 215 | break; |
| 216 | case 0x4700: |
| 217 | reg_x |= (1 << 22); |
| 218 | break; |
| 219 | case 0xfd60: |
| 220 | reg_x |= (1 << 23); |
| 221 | break; |
| 222 | default: |
| 223 | if (var_num >= 3) |
| 224 | continue; /* only 3 var ; compact them ? */ |
| 225 | switch (var_num) { |
| 226 | case 0: |
| 227 | reg_x |= (1 << 2); |
Rudolf Marek | 86bd99a | 2011-01-28 20:57:48 +0000 | [diff] [blame] | 228 | if ((end - base) < 16) |
| 229 | wiosize |= (1 << 0); |
Zheng Bao | eff2ffd | 2010-03-16 01:38:54 +0000 | [diff] [blame] | 230 | break; |
| 231 | case 1: |
| 232 | reg_x |= (1 << 24); |
Rudolf Marek | 86bd99a | 2011-01-28 20:57:48 +0000 | [diff] [blame] | 233 | if ((end - base) < 16) |
| 234 | wiosize |= (1 << 2); |
Zheng Bao | eff2ffd | 2010-03-16 01:38:54 +0000 | [diff] [blame] | 235 | break; |
| 236 | case 2: |
| 237 | reg_x |= (1 << 25); |
Rudolf Marek | 86bd99a | 2011-01-28 20:57:48 +0000 | [diff] [blame] | 238 | reg_x |= (1 << 24); |
| 239 | if ((end - base) < 16) |
| 240 | wiosize |= (1 << 3); |
Zheng Bao | eff2ffd | 2010-03-16 01:38:54 +0000 | [diff] [blame] | 241 | break; |
| 242 | } |
| 243 | reg_var[var_num++] = |
| 244 | base & 0xffff; |
| 245 | } |
| 246 | } |
| 247 | } |
| 248 | } |
| 249 | } |
| 250 | pci_write_config32(dev, 0x44, reg); |
| 251 | pci_write_config32(dev, 0x48, reg_x); |
| 252 | /* Set WideIO for as many IOs found (fall through is on purpose) */ |
| 253 | switch (var_num) { |
| 254 | case 2: |
| 255 | pci_write_config16(dev, 0x90, reg_var[2]); |
| 256 | case 1: |
| 257 | pci_write_config16(dev, 0x66, reg_var[1]); |
| 258 | case 0: |
| 259 | pci_write_config16(dev, 0x64, reg_var[0]); |
| 260 | break; |
| 261 | } |
Rudolf Marek | 86bd99a | 2011-01-28 20:57:48 +0000 | [diff] [blame] | 262 | pci_write_config8(dev, 0x74, wiosize); |
Zheng Bao | eff2ffd | 2010-03-16 01:38:54 +0000 | [diff] [blame] | 263 | } |
| 264 | |
| 265 | static void sb700_lpc_enable_resources(device_t dev) |
| 266 | { |
| 267 | pci_dev_enable_resources(dev); |
| 268 | sb700_lpc_enable_childrens_resources(dev); |
| 269 | } |
| 270 | |
Vladimir Serbinenko | f21271e | 2014-10-16 18:00:27 +0200 | [diff] [blame] | 271 | #if IS_ENABLED(CONFIG_HAVE_ACPI_TABLES) && IS_ENABLED(CONFIG_PER_DEVICE_ACPI_TABLES) |
Vladimir Serbinenko | 6985d4e | 2014-09-21 14:31:19 +0200 | [diff] [blame] | 272 | |
| 273 | static void southbridge_acpi_fill_ssdt_generator(void) { |
Vladimir Serbinenko | 4743254 | 2014-10-05 14:54:26 +0200 | [diff] [blame] | 274 | amd_generate_powernow(ACPI_CPU_CONTROL, 6, 1); |
Vladimir Serbinenko | 6985d4e | 2014-09-21 14:31:19 +0200 | [diff] [blame] | 275 | } |
| 276 | |
| 277 | #endif |
| 278 | |
| 279 | |
Zheng Bao | eff2ffd | 2010-03-16 01:38:54 +0000 | [diff] [blame] | 280 | static struct pci_operations lops_pci = { |
| 281 | .set_subsystem = pci_dev_set_subsystem, |
| 282 | }; |
| 283 | |
| 284 | static struct device_operations lpc_ops = { |
| 285 | .read_resources = sb700_lpc_read_resources, |
| 286 | .set_resources = sb700_lpc_set_resources, |
| 287 | .enable_resources = sb700_lpc_enable_resources, |
Vladimir Serbinenko | f21271e | 2014-10-16 18:00:27 +0200 | [diff] [blame] | 288 | #if IS_ENABLED(CONFIG_HAVE_ACPI_TABLES) && IS_ENABLED(CONFIG_PER_DEVICE_ACPI_TABLES) |
Vladimir Serbinenko | 6985d4e | 2014-09-21 14:31:19 +0200 | [diff] [blame] | 289 | .write_acpi_tables = acpi_write_hpet, |
| 290 | .acpi_fill_ssdt_generator = southbridge_acpi_fill_ssdt_generator, |
| 291 | #endif |
Zheng Bao | eff2ffd | 2010-03-16 01:38:54 +0000 | [diff] [blame] | 292 | .init = lpc_init, |
| 293 | .scan_bus = scan_static_bus, |
| 294 | .ops_pci = &lops_pci, |
| 295 | }; |
Stefan Reinauer | 8e96ba2 | 2010-03-16 23:33:29 +0000 | [diff] [blame] | 296 | static const struct pci_driver lpc_driver __pci_driver = { |
Zheng Bao | eff2ffd | 2010-03-16 01:38:54 +0000 | [diff] [blame] | 297 | .ops = &lpc_ops, |
| 298 | .vendor = PCI_VENDOR_ID_ATI, |
| 299 | .device = PCI_DEVICE_ID_ATI_SB700_LPC, |
| 300 | }; |