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