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