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