Angel Pons | ae59387 | 2020-04-04 18:50:57 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 2 | |
Kyösti Mälkki | 0c1dd9c | 2020-06-17 23:37:49 +0300 | [diff] [blame] | 3 | #include <acpi/acpi_gnvs.h> |
Marc Jones | 257db58 | 2017-06-18 17:33:30 -0600 | [diff] [blame] | 4 | #include <cbmem.h> |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 5 | #include <console/console.h> |
| 6 | #include <device/device.h> |
| 7 | #include <device/pci.h> |
| 8 | #include <device/pnp.h> |
| 9 | #include <device/pci_ids.h> |
| 10 | #include <device/pci_ops.h> |
| 11 | #include <device/pci_def.h> |
| 12 | #include <pc80/mc146818rtc.h> |
| 13 | #include <pc80/isa-dma.h> |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 14 | #include <arch/ioapic.h> |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 15 | #include <pc80/i8254.h> |
| 16 | #include <pc80/i8259.h> |
Marshall Dawson | 69486ca | 2019-05-02 12:03:45 -0600 | [diff] [blame] | 17 | #include <amdblocks/acpimmio.h> |
Furquan Shaikh | 511aa44 | 2020-05-04 23:42:46 -0700 | [diff] [blame] | 18 | #include <amdblocks/espi.h> |
Marshall Dawson | 6ab5ed3 | 2019-05-29 09:24:18 -0600 | [diff] [blame] | 19 | #include <amdblocks/lpc.h> |
Marc Jones | 257db58 | 2017-06-18 17:33:30 -0600 | [diff] [blame] | 20 | #include <soc/acpi.h> |
Marc Jones | dfeb1c4 | 2017-08-07 19:08:24 -0600 | [diff] [blame] | 21 | #include <soc/southbridge.h> |
Marc Jones | 257db58 | 2017-06-18 17:33:30 -0600 | [diff] [blame] | 22 | #include <soc/nvs.h> |
Marshall Dawson | 6ab5ed3 | 2019-05-29 09:24:18 -0600 | [diff] [blame] | 23 | #include <soc/iomap.h> |
| 24 | |
| 25 | /* Most systems should have already enabled the bridge */ |
| 26 | void __weak soc_late_lpc_bridge_enable(void) { } |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 27 | |
Elyes HAOUAS | 777ccd4 | 2018-05-22 10:52:05 +0200 | [diff] [blame] | 28 | static void lpc_init(struct device *dev) |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 29 | { |
| 30 | u8 byte; |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 31 | |
Marshall Dawson | 6ab5ed3 | 2019-05-29 09:24:18 -0600 | [diff] [blame] | 32 | soc_late_lpc_bridge_enable(); |
| 33 | |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 34 | /* Initialize isa dma */ |
| 35 | isa_dma_init(); |
| 36 | |
| 37 | /* Enable DMA transaction on the LPC bus */ |
Marshall Dawson | 1bc04e3 | 2019-05-02 18:56:54 -0600 | [diff] [blame] | 38 | byte = pci_read_config8(dev, LPC_PCI_CONTROL); |
Richard Spiegel | c5ecd3e | 2017-09-29 10:05:35 -0700 | [diff] [blame] | 39 | byte |= LEGACY_DMA_EN; |
Marshall Dawson | 1bc04e3 | 2019-05-02 18:56:54 -0600 | [diff] [blame] | 40 | pci_write_config8(dev, LPC_PCI_CONTROL, byte); |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 41 | |
| 42 | /* Disable the timeout mechanism on LPC */ |
Marshall Dawson | 1bc04e3 | 2019-05-02 18:56:54 -0600 | [diff] [blame] | 43 | byte = pci_read_config8(dev, LPC_IO_OR_MEM_DECODE_ENABLE); |
Richard Spiegel | c5ecd3e | 2017-09-29 10:05:35 -0700 | [diff] [blame] | 44 | byte &= ~LPC_SYNC_TIMEOUT_COUNT_ENABLE; |
Marshall Dawson | 1bc04e3 | 2019-05-02 18:56:54 -0600 | [diff] [blame] | 45 | pci_write_config8(dev, LPC_IO_OR_MEM_DECODE_ENABLE, byte); |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 46 | |
| 47 | /* Disable LPC MSI Capability */ |
Marshall Dawson | 1bc04e3 | 2019-05-02 18:56:54 -0600 | [diff] [blame] | 48 | byte = pci_read_config8(dev, LPC_MISC_CONTROL_BITS); |
Richard Spiegel | c5ecd3e | 2017-09-29 10:05:35 -0700 | [diff] [blame] | 49 | /* BIT 1 is not defined in public datasheet. */ |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 50 | byte &= ~(1 << 1); |
Richard Spiegel | c5ecd3e | 2017-09-29 10:05:35 -0700 | [diff] [blame] | 51 | |
| 52 | /* |
| 53 | * Keep the old way. i.e., when bus master/DMA cycle is going |
Marshall Dawson | 4e101ad | 2017-06-15 12:17:38 -0600 | [diff] [blame] | 54 | * on on LPC, it holds PCI grant, so no LPC slave cycle can |
| 55 | * interrupt and visit LPC. |
| 56 | */ |
Richard Spiegel | c5ecd3e | 2017-09-29 10:05:35 -0700 | [diff] [blame] | 57 | byte &= ~LPC_NOHOG; |
Marshall Dawson | 1bc04e3 | 2019-05-02 18:56:54 -0600 | [diff] [blame] | 58 | pci_write_config8(dev, LPC_MISC_CONTROL_BITS, byte); |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 59 | |
Richard Spiegel | c5ecd3e | 2017-09-29 10:05:35 -0700 | [diff] [blame] | 60 | /* |
Marshall Dawson | 6ab5ed3 | 2019-05-29 09:24:18 -0600 | [diff] [blame] | 61 | * Enable hand-instance of the pulse generator and SPI prefetch from |
| 62 | * host (earlier is recommended for boot speed). |
Marshall Dawson | 4e101ad | 2017-06-15 12:17:38 -0600 | [diff] [blame] | 63 | */ |
Marshall Dawson | 1bc04e3 | 2019-05-02 18:56:54 -0600 | [diff] [blame] | 64 | byte = pci_read_config8(dev, LPC_HOST_CONTROL); |
Richard Spiegel | ee09878 | 2018-07-30 12:05:22 -0700 | [diff] [blame] | 65 | byte |= PREFETCH_EN_SPI_FROM_HOST | T_START_ENH; |
Marshall Dawson | 1bc04e3 | 2019-05-02 18:56:54 -0600 | [diff] [blame] | 66 | pci_write_config8(dev, LPC_HOST_CONTROL, byte); |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 67 | |
| 68 | cmos_check_update_date(); |
| 69 | |
Richard Spiegel | c5ecd3e | 2017-09-29 10:05:35 -0700 | [diff] [blame] | 70 | /* |
| 71 | * Initialize the real time clock. |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 72 | * The 0 argument tells cmos_init not to |
| 73 | * update CMOS unless it is invalid. |
| 74 | * 1 tells cmos_init to always initialize the CMOS. |
| 75 | */ |
Aaron Durbin | 9fde0d7 | 2017-09-15 11:01:17 -0600 | [diff] [blame] | 76 | cmos_init(0); |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 77 | |
| 78 | /* Initialize i8259 pic */ |
Marshall Dawson | 4e101ad | 2017-06-15 12:17:38 -0600 | [diff] [blame] | 79 | setup_i8259(); |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 80 | |
| 81 | /* Initialize i8254 timers */ |
Marshall Dawson | 4e101ad | 2017-06-15 12:17:38 -0600 | [diff] [blame] | 82 | setup_i8254(); |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 83 | |
| 84 | /* Set up SERIRQ, enable continuous mode */ |
Richard Spiegel | c5ecd3e | 2017-09-29 10:05:35 -0700 | [diff] [blame] | 85 | byte = (PM_SERIRQ_NUM_BITS_21 | PM_SERIRQ_ENABLE); |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 86 | if (!CONFIG(SERIRQ_CONTINUOUS_MODE)) |
Richard Spiegel | c5ecd3e | 2017-09-29 10:05:35 -0700 | [diff] [blame] | 87 | byte |= PM_SERIRQ_MODE; |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 88 | |
| 89 | pm_write8(PM_SERIRQ_CONF, byte); |
| 90 | } |
| 91 | |
Elyes HAOUAS | 777ccd4 | 2018-05-22 10:52:05 +0200 | [diff] [blame] | 92 | static void lpc_read_resources(struct device *dev) |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 93 | { |
| 94 | struct resource *res; |
Kyösti Mälkki | 0c1dd9c | 2020-06-17 23:37:49 +0300 | [diff] [blame] | 95 | struct global_nvs *gnvs; |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 96 | |
| 97 | /* Get the normal pci resources of this device */ |
Marshall Dawson | 4e101ad | 2017-06-15 12:17:38 -0600 | [diff] [blame] | 98 | pci_dev_read_resources(dev); |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 99 | |
| 100 | /* Add an extra subtractive resource for both memory and I/O. */ |
| 101 | res = new_resource(dev, IOINDEX_SUBTRACTIVE(0, 0)); |
| 102 | res->base = 0; |
| 103 | res->size = 0x1000; |
| 104 | res->flags = IORESOURCE_IO | IORESOURCE_SUBTRACTIVE | |
| 105 | IORESOURCE_ASSIGNED | IORESOURCE_FIXED; |
| 106 | |
| 107 | res = new_resource(dev, IOINDEX_SUBTRACTIVE(1, 0)); |
Richard Spiegel | c5ecd3e | 2017-09-29 10:05:35 -0700 | [diff] [blame] | 108 | res->base = FLASH_BASE_ADDR; |
| 109 | res->size = CONFIG_ROM_SIZE; |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 110 | res->flags = IORESOURCE_MEM | IORESOURCE_SUBTRACTIVE | |
| 111 | IORESOURCE_ASSIGNED | IORESOURCE_FIXED; |
| 112 | |
| 113 | /* Add a memory resource for the SPI BAR. */ |
Marshall Dawson | 4e101ad | 2017-06-15 12:17:38 -0600 | [diff] [blame] | 114 | fixed_mem_resource(dev, 2, SPI_BASE_ADDRESS / 1024, 1, |
| 115 | IORESOURCE_SUBTRACTIVE); |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 116 | |
| 117 | res = new_resource(dev, 3); /* IOAPIC */ |
| 118 | res->base = IO_APIC_ADDR; |
| 119 | res->size = 0x00001000; |
| 120 | res->flags = IORESOURCE_MEM | IORESOURCE_ASSIGNED | IORESOURCE_FIXED; |
| 121 | |
Martin Roth | 7e78e56 | 2019-11-03 23:29:02 -0700 | [diff] [blame] | 122 | /* I2C devices */ |
Chris Ching | 6fc39d4 | 2017-12-20 16:06:03 -0700 | [diff] [blame] | 123 | res = new_resource(dev, 4); |
| 124 | res->base = I2C_BASE_ADDRESS; |
| 125 | res->size = I2C_DEVICE_SIZE * I2C_DEVICE_COUNT; |
| 126 | res->flags = IORESOURCE_MEM | IORESOURCE_ASSIGNED | IORESOURCE_FIXED; |
| 127 | |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 128 | compact_resources(dev); |
Marc Jones | 257db58 | 2017-06-18 17:33:30 -0600 | [diff] [blame] | 129 | |
| 130 | /* Allocate ACPI NVS in CBMEM */ |
Kyösti Mälkki | 0c1dd9c | 2020-06-17 23:37:49 +0300 | [diff] [blame] | 131 | gnvs = cbmem_add(CBMEM_ID_ACPI_GNVS, sizeof(struct global_nvs)); |
Richard Spiegel | 6a9e6cd | 2018-11-30 10:53:40 -0700 | [diff] [blame] | 132 | printk(BIOS_DEBUG, "ACPI GNVS at %p\n", gnvs); |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 133 | } |
| 134 | |
Marc Jones | dfeb1c4 | 2017-08-07 19:08:24 -0600 | [diff] [blame] | 135 | static void lpc_set_resources(struct device *dev) |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 136 | { |
| 137 | struct resource *res; |
| 138 | u32 spi_enable_bits; |
| 139 | |
| 140 | /* Special case. The SpiRomEnable and other enables should STAY set. */ |
| 141 | res = find_resource(dev, 2); |
| 142 | spi_enable_bits = pci_read_config32(dev, SPIROM_BASE_ADDRESS_REGISTER); |
Marshall Dawson | eceaa97 | 2019-05-05 18:35:12 -0600 | [diff] [blame] | 143 | spi_enable_bits &= SPI_BASE_ALIGNMENT - 1; |
Marshall Dawson | 4e101ad | 2017-06-15 12:17:38 -0600 | [diff] [blame] | 144 | pci_write_config32(dev, SPIROM_BASE_ADDRESS_REGISTER, |
| 145 | res->base | spi_enable_bits); |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 146 | |
| 147 | pci_dev_set_resources(dev); |
| 148 | } |
| 149 | |
Furquan Shaikh | 1e279a5 | 2020-05-04 21:22:22 -0700 | [diff] [blame] | 150 | static void configure_child_lpc_windows(struct device *dev, struct device *child) |
Richard Spiegel | aa18385 | 2017-10-05 18:53:31 -0700 | [diff] [blame] | 151 | { |
| 152 | struct resource *res; |
| 153 | u32 base, end; |
| 154 | u32 rsize = 0, set = 0, set_x = 0; |
Richard Spiegel | b5f9645 | 2017-11-22 15:28:25 -0700 | [diff] [blame] | 155 | int wideio_index; |
Furquan Shaikh | 1e279a5 | 2020-05-04 21:22:22 -0700 | [diff] [blame] | 156 | u32 reg, reg_x; |
| 157 | |
| 158 | reg = pci_read_config32(dev, LPC_IO_PORT_DECODE_ENABLE); |
| 159 | reg_x = pci_read_config32(dev, LPC_IO_OR_MEM_DECODE_ENABLE); |
| 160 | |
Richard Spiegel | aa18385 | 2017-10-05 18:53:31 -0700 | [diff] [blame] | 161 | |
Richard Spiegel | 7a39e02 | 2017-11-09 10:54:04 -0700 | [diff] [blame] | 162 | /* |
| 163 | * Be a bit relaxed, tolerate that LPC region might be bigger than |
| 164 | * resource we try to fit, do it like this for all regions < 16 bytes. |
| 165 | * If there is a resource > 16 bytes it must be 512 bytes to be able |
| 166 | * to allocate the fresh LPC window. |
| 167 | * |
| 168 | * AGESA and early initialization can set a wide IO port. This code |
| 169 | * will verify if required region was previously set and will avoid |
| 170 | * setting a new wide IO resource if one is already set. |
| 171 | */ |
| 172 | |
Richard Spiegel | aa18385 | 2017-10-05 18:53:31 -0700 | [diff] [blame] | 173 | for (res = child->resource_list; res; res = res->next) { |
| 174 | if (!(res->flags & IORESOURCE_IO)) |
| 175 | continue; |
| 176 | base = res->base; |
| 177 | end = resource_end(res); |
Richard Spiegel | aa18385 | 2017-10-05 18:53:31 -0700 | [diff] [blame] | 178 | printk(BIOS_DEBUG, |
Richard Spiegel | c5ecd3e | 2017-09-29 10:05:35 -0700 | [diff] [blame] | 179 | "Southbridge LPC decode:%s, base=0x%08x, end=0x%08x\n", |
| 180 | dev_path(child), base, end); |
| 181 | /* find a resource size */ |
Richard Spiegel | aa18385 | 2017-10-05 18:53:31 -0700 | [diff] [blame] | 182 | switch (base) { |
| 183 | case 0x60: /* KB */ |
| 184 | case 0x64: /* MS */ |
Richard Spiegel | c5ecd3e | 2017-09-29 10:05:35 -0700 | [diff] [blame] | 185 | set |= DECODE_ENABLE_KBC_PORT; |
Richard Spiegel | aa18385 | 2017-10-05 18:53:31 -0700 | [diff] [blame] | 186 | rsize = 1; |
| 187 | break; |
| 188 | case 0x3f8: /* COM1 */ |
Richard Spiegel | c5ecd3e | 2017-09-29 10:05:35 -0700 | [diff] [blame] | 189 | set |= DECODE_ENABLE_SERIAL_PORT0; |
Richard Spiegel | aa18385 | 2017-10-05 18:53:31 -0700 | [diff] [blame] | 190 | rsize = 8; |
| 191 | break; |
| 192 | case 0x2f8: /* COM2 */ |
Richard Spiegel | c5ecd3e | 2017-09-29 10:05:35 -0700 | [diff] [blame] | 193 | set |= DECODE_ENABLE_SERIAL_PORT1; |
Richard Spiegel | aa18385 | 2017-10-05 18:53:31 -0700 | [diff] [blame] | 194 | rsize = 8; |
| 195 | break; |
| 196 | case 0x378: /* Parallel 1 */ |
Richard Spiegel | c5ecd3e | 2017-09-29 10:05:35 -0700 | [diff] [blame] | 197 | set |= DECODE_ENABLE_PARALLEL_PORT0; |
| 198 | /* enable 0x778 for ECP mode */ |
| 199 | set |= DECODE_ENABLE_PARALLEL_PORT1; |
Richard Spiegel | aa18385 | 2017-10-05 18:53:31 -0700 | [diff] [blame] | 200 | rsize = 8; |
| 201 | break; |
| 202 | case 0x3f0: /* FD0 */ |
Richard Spiegel | c5ecd3e | 2017-09-29 10:05:35 -0700 | [diff] [blame] | 203 | set |= DECODE_ENABLE_FDC_PORT0; |
Richard Spiegel | aa18385 | 2017-10-05 18:53:31 -0700 | [diff] [blame] | 204 | rsize = 8; |
| 205 | break; |
| 206 | case 0x220: /* 0x220 - 0x227 */ |
Richard Spiegel | c5ecd3e | 2017-09-29 10:05:35 -0700 | [diff] [blame] | 207 | set |= DECODE_ENABLE_SERIAL_PORT2; |
Richard Spiegel | aa18385 | 2017-10-05 18:53:31 -0700 | [diff] [blame] | 208 | rsize = 8; |
| 209 | break; |
| 210 | case 0x228: /* 0x228 - 0x22f */ |
Richard Spiegel | c5ecd3e | 2017-09-29 10:05:35 -0700 | [diff] [blame] | 211 | set |= DECODE_ENABLE_SERIAL_PORT3; |
Richard Spiegel | aa18385 | 2017-10-05 18:53:31 -0700 | [diff] [blame] | 212 | rsize = 8; |
| 213 | break; |
| 214 | case 0x238: /* 0x238 - 0x23f */ |
Richard Spiegel | c5ecd3e | 2017-09-29 10:05:35 -0700 | [diff] [blame] | 215 | set |= DECODE_ENABLE_SERIAL_PORT4; |
Richard Spiegel | aa18385 | 2017-10-05 18:53:31 -0700 | [diff] [blame] | 216 | rsize = 8; |
| 217 | break; |
| 218 | case 0x300: /* 0x300 - 0x301 */ |
Richard Spiegel | c5ecd3e | 2017-09-29 10:05:35 -0700 | [diff] [blame] | 219 | set |= DECODE_ENABLE_MIDI_PORT0; |
Richard Spiegel | aa18385 | 2017-10-05 18:53:31 -0700 | [diff] [blame] | 220 | rsize = 2; |
| 221 | break; |
| 222 | case 0x400: |
Richard Spiegel | c5ecd3e | 2017-09-29 10:05:35 -0700 | [diff] [blame] | 223 | set_x |= DECODE_IO_PORT_ENABLE0; |
Richard Spiegel | aa18385 | 2017-10-05 18:53:31 -0700 | [diff] [blame] | 224 | rsize = 0x40; |
| 225 | break; |
| 226 | case 0x480: |
Richard Spiegel | c5ecd3e | 2017-09-29 10:05:35 -0700 | [diff] [blame] | 227 | set_x |= DECODE_IO_PORT_ENABLE1; |
Richard Spiegel | aa18385 | 2017-10-05 18:53:31 -0700 | [diff] [blame] | 228 | rsize = 0x40; |
| 229 | break; |
| 230 | case 0x500: |
Richard Spiegel | c5ecd3e | 2017-09-29 10:05:35 -0700 | [diff] [blame] | 231 | set_x |= DECODE_IO_PORT_ENABLE2; |
Richard Spiegel | aa18385 | 2017-10-05 18:53:31 -0700 | [diff] [blame] | 232 | rsize = 0x40; |
| 233 | break; |
| 234 | case 0x580: |
Richard Spiegel | c5ecd3e | 2017-09-29 10:05:35 -0700 | [diff] [blame] | 235 | set_x |= DECODE_IO_PORT_ENABLE3; |
Richard Spiegel | aa18385 | 2017-10-05 18:53:31 -0700 | [diff] [blame] | 236 | rsize = 0x40; |
| 237 | break; |
| 238 | case 0x4700: |
Richard Spiegel | c5ecd3e | 2017-09-29 10:05:35 -0700 | [diff] [blame] | 239 | set_x |= DECODE_IO_PORT_ENABLE5; |
Richard Spiegel | aa18385 | 2017-10-05 18:53:31 -0700 | [diff] [blame] | 240 | rsize = 0xc; |
| 241 | break; |
| 242 | case 0xfd60: |
Richard Spiegel | c5ecd3e | 2017-09-29 10:05:35 -0700 | [diff] [blame] | 243 | set_x |= DECODE_IO_PORT_ENABLE6; |
Richard Spiegel | aa18385 | 2017-10-05 18:53:31 -0700 | [diff] [blame] | 244 | rsize = 16; |
| 245 | break; |
| 246 | default: |
| 247 | rsize = 0; |
Marshall Dawson | 6ab5ed3 | 2019-05-29 09:24:18 -0600 | [diff] [blame] | 248 | wideio_index = lpc_find_wideio_range(base, res->size); |
Richard Spiegel | b5f9645 | 2017-11-22 15:28:25 -0700 | [diff] [blame] | 249 | if (wideio_index != WIDEIO_RANGE_ERROR) { |
Marshall Dawson | 6ab5ed3 | 2019-05-29 09:24:18 -0600 | [diff] [blame] | 250 | rsize = lpc_wideio_size(wideio_index); |
Richard Spiegel | b5f9645 | 2017-11-22 15:28:25 -0700 | [diff] [blame] | 251 | printk(BIOS_DEBUG, "Covered by wideIO"); |
| 252 | printk(BIOS_DEBUG, " %d\n", wideio_index); |
Richard Spiegel | 7a39e02 | 2017-11-09 10:54:04 -0700 | [diff] [blame] | 253 | } |
Richard Spiegel | aa18385 | 2017-10-05 18:53:31 -0700 | [diff] [blame] | 254 | } |
| 255 | /* check if region found and matches the enable */ |
| 256 | if (res->size <= rsize) { |
Furquan Shaikh | 1e279a5 | 2020-05-04 21:22:22 -0700 | [diff] [blame] | 257 | reg |= set; |
| 258 | reg_x |= set_x; |
Richard Spiegel | aa18385 | 2017-10-05 18:53:31 -0700 | [diff] [blame] | 259 | /* check if we can fit resource in variable range */ |
Richard Spiegel | aa18385 | 2017-10-05 18:53:31 -0700 | [diff] [blame] | 260 | } else { |
Marshall Dawson | 6ab5ed3 | 2019-05-29 09:24:18 -0600 | [diff] [blame] | 261 | wideio_index = lpc_set_wideio_range(base, res->size); |
Richard Spiegel | b5f9645 | 2017-11-22 15:28:25 -0700 | [diff] [blame] | 262 | if (wideio_index != WIDEIO_RANGE_ERROR) { |
| 263 | /* preserve wide IO related bits. */ |
Furquan Shaikh | 1e279a5 | 2020-05-04 21:22:22 -0700 | [diff] [blame] | 264 | reg_x = pci_read_config32(dev, |
Richard Spiegel | b5f9645 | 2017-11-22 15:28:25 -0700 | [diff] [blame] | 265 | LPC_IO_OR_MEM_DECODE_ENABLE); |
Richard Spiegel | b5f9645 | 2017-11-22 15:28:25 -0700 | [diff] [blame] | 266 | printk(BIOS_DEBUG, |
| 267 | "Range assigned to wide IO %d\n", |
| 268 | wideio_index); |
| 269 | } else { |
| 270 | printk(BIOS_ERR, |
| 271 | "cannot fit LPC decode region:"); |
| 272 | printk(BIOS_ERR, |
| 273 | "%s, base = 0x%08x, end = 0x%08x\n", |
| 274 | dev_path(child), base, end); |
| 275 | } |
Richard Spiegel | aa18385 | 2017-10-05 18:53:31 -0700 | [diff] [blame] | 276 | } |
| 277 | } |
Richard Spiegel | aa18385 | 2017-10-05 18:53:31 -0700 | [diff] [blame] | 278 | |
Richard Spiegel | c5ecd3e | 2017-09-29 10:05:35 -0700 | [diff] [blame] | 279 | pci_write_config32(dev, LPC_IO_PORT_DECODE_ENABLE, reg); |
| 280 | pci_write_config32(dev, LPC_IO_OR_MEM_DECODE_ENABLE, reg_x); |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 281 | } |
| 282 | |
Furquan Shaikh | 511aa44 | 2020-05-04 23:42:46 -0700 | [diff] [blame] | 283 | static void configure_child_espi_windows(struct device *child) |
| 284 | { |
| 285 | struct resource *res; |
| 286 | |
| 287 | for (res = child->resource_list; res; res = res->next) { |
| 288 | if (res->flags & IORESOURCE_IO) |
| 289 | espi_open_io_window(res->base, res->size); |
| 290 | else if (res->flags & IORESOURCE_MEM) |
| 291 | espi_open_mmio_window(res->base, res->size); |
| 292 | } |
| 293 | } |
| 294 | |
Furquan Shaikh | 1e279a5 | 2020-05-04 21:22:22 -0700 | [diff] [blame] | 295 | static void lpc_enable_children_resources(struct device *dev) |
| 296 | { |
| 297 | struct bus *link; |
| 298 | struct device *child; |
| 299 | |
| 300 | for (link = dev->link_list; link; link = link->next) { |
| 301 | for (child = link->children; child; child = child->sibling) { |
| 302 | if (!child->enabled) |
| 303 | continue; |
| 304 | if (child->path.type != DEVICE_PATH_PNP) |
| 305 | continue; |
Furquan Shaikh | 511aa44 | 2020-05-04 23:42:46 -0700 | [diff] [blame] | 306 | if (CONFIG(SOC_AMD_COMMON_BLOCK_USE_ESPI)) |
| 307 | configure_child_espi_windows(child); |
| 308 | else |
| 309 | configure_child_lpc_windows(dev, child); |
Furquan Shaikh | 1e279a5 | 2020-05-04 21:22:22 -0700 | [diff] [blame] | 310 | } |
| 311 | } |
| 312 | } |
| 313 | |
Elyes HAOUAS | 777ccd4 | 2018-05-22 10:52:05 +0200 | [diff] [blame] | 314 | static void lpc_enable_resources(struct device *dev) |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 315 | { |
| 316 | pci_dev_enable_resources(dev); |
Furquan Shaikh | 1e279a5 | 2020-05-04 21:22:22 -0700 | [diff] [blame] | 317 | lpc_enable_children_resources(dev); |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 318 | } |
| 319 | |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 320 | static struct device_operations lpc_ops = { |
Marc Jones | dfeb1c4 | 2017-08-07 19:08:24 -0600 | [diff] [blame] | 321 | .read_resources = lpc_read_resources, |
| 322 | .set_resources = lpc_set_resources, |
| 323 | .enable_resources = lpc_enable_resources, |
Nico Huber | 68680dd | 2020-03-31 17:34:52 +0200 | [diff] [blame] | 324 | .acpi_inject_dsdt = southbridge_inject_dsdt, |
Marc Jones | 257db58 | 2017-06-18 17:33:30 -0600 | [diff] [blame] | 325 | .write_acpi_tables = southbridge_write_acpi_tables, |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 326 | .init = lpc_init, |
Nico Huber | 51b75ae | 2019-03-14 16:02:05 +0100 | [diff] [blame] | 327 | .scan_bus = scan_static_bus, |
Furquan Shaikh | 40454b7 | 2020-05-04 20:52:08 -0700 | [diff] [blame] | 328 | .ops_pci = &pci_dev_ops_pci, |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 329 | }; |
| 330 | |
| 331 | static const unsigned short pci_device_ids[] = { |
| 332 | PCI_DEVICE_ID_AMD_SB900_LPC, |
| 333 | PCI_DEVICE_ID_AMD_CZ_LPC, |
Furquan Shaikh | a1cd7eb | 2020-04-15 23:58:22 -0700 | [diff] [blame] | 334 | PCI_DEVICE_ID_AMD_FAM17H_LPC, |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 335 | 0 |
| 336 | }; |
| 337 | static const struct pci_driver lpc_driver __pci_driver = { |
| 338 | .ops = &lpc_ops, |
| 339 | .vendor = PCI_VENDOR_ID_AMD, |
| 340 | .devices = pci_device_ids, |
| 341 | }; |