Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
Richard Spiegel | 7a39e02 | 2017-11-09 10:54:04 -0700 | [diff] [blame] | 4 | * Copyright (C) 2010-2017 Advanced Micro Devices, Inc. |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 5 | * Copyright (C) 2014 Sage Electronic Engineering, LLC |
| 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. |
| 15 | */ |
| 16 | |
Marc Jones | 257db58 | 2017-06-18 17:33:30 -0600 | [diff] [blame] | 17 | #include <cbmem.h> |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 18 | #include <console/console.h> |
| 19 | #include <device/device.h> |
| 20 | #include <device/pci.h> |
| 21 | #include <device/pnp.h> |
| 22 | #include <device/pci_ids.h> |
| 23 | #include <device/pci_ops.h> |
| 24 | #include <device/pci_def.h> |
| 25 | #include <pc80/mc146818rtc.h> |
| 26 | #include <pc80/isa-dma.h> |
| 27 | #include <arch/io.h> |
| 28 | #include <arch/ioapic.h> |
| 29 | #include <arch/acpi.h> |
| 30 | #include <pc80/i8254.h> |
| 31 | #include <pc80/i8259.h> |
Marc Jones | 257db58 | 2017-06-18 17:33:30 -0600 | [diff] [blame] | 32 | #include <soc/acpi.h> |
Marshall Dawson | 4e101ad | 2017-06-15 12:17:38 -0600 | [diff] [blame] | 33 | #include <soc/pci_devs.h> |
Marc Jones | dfeb1c4 | 2017-08-07 19:08:24 -0600 | [diff] [blame] | 34 | #include <soc/southbridge.h> |
Marc Jones | 257db58 | 2017-06-18 17:33:30 -0600 | [diff] [blame] | 35 | #include <soc/nvs.h> |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 36 | |
Elyes HAOUAS | 777ccd4 | 2018-05-22 10:52:05 +0200 | [diff] [blame^] | 37 | static void lpc_init(struct device *dev) |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 38 | { |
| 39 | u8 byte; |
| 40 | u32 dword; |
Elyes HAOUAS | 777ccd4 | 2018-05-22 10:52:05 +0200 | [diff] [blame^] | 41 | struct device *sm_dev; |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 42 | |
Richard Spiegel | c5ecd3e | 2017-09-29 10:05:35 -0700 | [diff] [blame] | 43 | /* |
| 44 | * Enable the LPC Controller |
| 45 | * SMBus register 0x64 is not defined in public datasheet. |
| 46 | */ |
Chris Ching | 6a35fab | 2017-10-19 11:45:30 -0600 | [diff] [blame] | 47 | sm_dev = dev_find_slot(0, SMBUS_DEVFN); |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 48 | dword = pci_read_config32(sm_dev, 0x64); |
| 49 | dword |= 1 << 20; |
| 50 | pci_write_config32(sm_dev, 0x64, dword); |
| 51 | |
| 52 | /* Initialize isa dma */ |
| 53 | isa_dma_init(); |
| 54 | |
| 55 | /* Enable DMA transaction on the LPC bus */ |
Richard Spiegel | c5ecd3e | 2017-09-29 10:05:35 -0700 | [diff] [blame] | 56 | byte = pci_read_config8(dev, LPC_PCI_CONTROL); |
| 57 | byte |= LEGACY_DMA_EN; |
| 58 | pci_write_config8(dev, LPC_PCI_CONTROL, byte); |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 59 | |
| 60 | /* Disable the timeout mechanism on LPC */ |
Richard Spiegel | c5ecd3e | 2017-09-29 10:05:35 -0700 | [diff] [blame] | 61 | byte = pci_read_config8(dev, LPC_IO_OR_MEM_DECODE_ENABLE); |
| 62 | byte &= ~LPC_SYNC_TIMEOUT_COUNT_ENABLE; |
| 63 | pci_write_config8(dev, LPC_IO_OR_MEM_DECODE_ENABLE, byte); |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 64 | |
| 65 | /* Disable LPC MSI Capability */ |
Richard Spiegel | c5ecd3e | 2017-09-29 10:05:35 -0700 | [diff] [blame] | 66 | byte = pci_read_config8(dev, LPC_MISC_CONTROL_BITS); |
| 67 | /* BIT 1 is not defined in public datasheet. */ |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 68 | byte &= ~(1 << 1); |
Richard Spiegel | c5ecd3e | 2017-09-29 10:05:35 -0700 | [diff] [blame] | 69 | |
| 70 | /* |
| 71 | * 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] | 72 | * on on LPC, it holds PCI grant, so no LPC slave cycle can |
| 73 | * interrupt and visit LPC. |
| 74 | */ |
Richard Spiegel | c5ecd3e | 2017-09-29 10:05:35 -0700 | [diff] [blame] | 75 | byte &= ~LPC_NOHOG; |
| 76 | pci_write_config8(dev, LPC_MISC_CONTROL_BITS, byte); |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 77 | |
Richard Spiegel | c5ecd3e | 2017-09-29 10:05:35 -0700 | [diff] [blame] | 78 | /* |
Richard Spiegel | bbcfa8a | 2018-04-12 10:22:31 -0700 | [diff] [blame] | 79 | * IMC is not used, but some of its registers and ports need to be |
| 80 | * programmed/accessed. So enable CPU access to them. This fixes |
| 81 | * SPI_CS# timing issue when running at 66MHz. |
Marshall Dawson | 4e101ad | 2017-06-15 12:17:38 -0600 | [diff] [blame] | 82 | */ |
Richard Spiegel | c5ecd3e | 2017-09-29 10:05:35 -0700 | [diff] [blame] | 83 | byte = pci_read_config8(dev, LPC_HOST_CONTROL); |
Richard Spiegel | bbcfa8a | 2018-04-12 10:22:31 -0700 | [diff] [blame] | 84 | byte |= IMC_PAGE_FROM_HOST_EN | IMC_PORT_FROM_HOST_EN; |
Richard Spiegel | c5ecd3e | 2017-09-29 10:05:35 -0700 | [diff] [blame] | 85 | pci_write_config8(dev, LPC_HOST_CONTROL, byte); |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 86 | |
| 87 | cmos_check_update_date(); |
| 88 | |
Richard Spiegel | c5ecd3e | 2017-09-29 10:05:35 -0700 | [diff] [blame] | 89 | /* |
| 90 | * Initialize the real time clock. |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 91 | * The 0 argument tells cmos_init not to |
| 92 | * update CMOS unless it is invalid. |
| 93 | * 1 tells cmos_init to always initialize the CMOS. |
| 94 | */ |
Aaron Durbin | 9fde0d7 | 2017-09-15 11:01:17 -0600 | [diff] [blame] | 95 | cmos_init(0); |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 96 | |
| 97 | /* Initialize i8259 pic */ |
Marshall Dawson | 4e101ad | 2017-06-15 12:17:38 -0600 | [diff] [blame] | 98 | setup_i8259(); |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 99 | |
| 100 | /* Initialize i8254 timers */ |
Marshall Dawson | 4e101ad | 2017-06-15 12:17:38 -0600 | [diff] [blame] | 101 | setup_i8254(); |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 102 | |
| 103 | /* Set up SERIRQ, enable continuous mode */ |
Richard Spiegel | c5ecd3e | 2017-09-29 10:05:35 -0700 | [diff] [blame] | 104 | byte = (PM_SERIRQ_NUM_BITS_21 | PM_SERIRQ_ENABLE); |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 105 | if (!IS_ENABLED(CONFIG_SERIRQ_CONTINUOUS_MODE)) |
Richard Spiegel | c5ecd3e | 2017-09-29 10:05:35 -0700 | [diff] [blame] | 106 | byte |= PM_SERIRQ_MODE; |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 107 | |
| 108 | pm_write8(PM_SERIRQ_CONF, byte); |
| 109 | } |
| 110 | |
Elyes HAOUAS | 777ccd4 | 2018-05-22 10:52:05 +0200 | [diff] [blame^] | 111 | static void lpc_read_resources(struct device *dev) |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 112 | { |
| 113 | struct resource *res; |
Marc Jones | 257db58 | 2017-06-18 17:33:30 -0600 | [diff] [blame] | 114 | global_nvs_t *gnvs; |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 115 | |
| 116 | /* Get the normal pci resources of this device */ |
Marshall Dawson | 4e101ad | 2017-06-15 12:17:38 -0600 | [diff] [blame] | 117 | pci_dev_read_resources(dev); |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 118 | |
| 119 | /* Add an extra subtractive resource for both memory and I/O. */ |
| 120 | res = new_resource(dev, IOINDEX_SUBTRACTIVE(0, 0)); |
| 121 | res->base = 0; |
| 122 | res->size = 0x1000; |
| 123 | res->flags = IORESOURCE_IO | IORESOURCE_SUBTRACTIVE | |
| 124 | IORESOURCE_ASSIGNED | IORESOURCE_FIXED; |
| 125 | |
| 126 | res = new_resource(dev, IOINDEX_SUBTRACTIVE(1, 0)); |
Richard Spiegel | c5ecd3e | 2017-09-29 10:05:35 -0700 | [diff] [blame] | 127 | res->base = FLASH_BASE_ADDR; |
| 128 | res->size = CONFIG_ROM_SIZE; |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 129 | res->flags = IORESOURCE_MEM | IORESOURCE_SUBTRACTIVE | |
| 130 | IORESOURCE_ASSIGNED | IORESOURCE_FIXED; |
| 131 | |
| 132 | /* Add a memory resource for the SPI BAR. */ |
Marshall Dawson | 4e101ad | 2017-06-15 12:17:38 -0600 | [diff] [blame] | 133 | fixed_mem_resource(dev, 2, SPI_BASE_ADDRESS / 1024, 1, |
| 134 | IORESOURCE_SUBTRACTIVE); |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 135 | |
| 136 | res = new_resource(dev, 3); /* IOAPIC */ |
| 137 | res->base = IO_APIC_ADDR; |
| 138 | res->size = 0x00001000; |
| 139 | res->flags = IORESOURCE_MEM | IORESOURCE_ASSIGNED | IORESOURCE_FIXED; |
| 140 | |
Chris Ching | 6fc39d4 | 2017-12-20 16:06:03 -0700 | [diff] [blame] | 141 | /* I2C devices (all 4 devices) */ |
| 142 | res = new_resource(dev, 4); |
| 143 | res->base = I2C_BASE_ADDRESS; |
| 144 | res->size = I2C_DEVICE_SIZE * I2C_DEVICE_COUNT; |
| 145 | res->flags = IORESOURCE_MEM | IORESOURCE_ASSIGNED | IORESOURCE_FIXED; |
| 146 | |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 147 | compact_resources(dev); |
Marc Jones | 257db58 | 2017-06-18 17:33:30 -0600 | [diff] [blame] | 148 | |
| 149 | /* Allocate ACPI NVS in CBMEM */ |
| 150 | gnvs = cbmem_add(CBMEM_ID_ACPI_GNVS, sizeof(global_nvs_t)); |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 151 | } |
| 152 | |
Marc Jones | dfeb1c4 | 2017-08-07 19:08:24 -0600 | [diff] [blame] | 153 | static void lpc_set_resources(struct device *dev) |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 154 | { |
| 155 | struct resource *res; |
| 156 | u32 spi_enable_bits; |
| 157 | |
| 158 | /* Special case. The SpiRomEnable and other enables should STAY set. */ |
| 159 | res = find_resource(dev, 2); |
| 160 | spi_enable_bits = pci_read_config32(dev, SPIROM_BASE_ADDRESS_REGISTER); |
Richard Spiegel | c5ecd3e | 2017-09-29 10:05:35 -0700 | [diff] [blame] | 161 | spi_enable_bits &= SPI_PRESERVE_BITS; |
Marshall Dawson | 4e101ad | 2017-06-15 12:17:38 -0600 | [diff] [blame] | 162 | pci_write_config32(dev, SPIROM_BASE_ADDRESS_REGISTER, |
| 163 | res->base | spi_enable_bits); |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 164 | |
| 165 | pci_dev_set_resources(dev); |
| 166 | } |
| 167 | |
Elyes HAOUAS | 777ccd4 | 2018-05-22 10:52:05 +0200 | [diff] [blame^] | 168 | static void set_child_resource(struct device *child, |
Richard Spiegel | aa18385 | 2017-10-05 18:53:31 -0700 | [diff] [blame] | 169 | u32 *reg, |
Richard Spiegel | b5f9645 | 2017-11-22 15:28:25 -0700 | [diff] [blame] | 170 | u32 *reg_x) |
Richard Spiegel | aa18385 | 2017-10-05 18:53:31 -0700 | [diff] [blame] | 171 | { |
| 172 | struct resource *res; |
| 173 | u32 base, end; |
| 174 | u32 rsize = 0, set = 0, set_x = 0; |
Richard Spiegel | b5f9645 | 2017-11-22 15:28:25 -0700 | [diff] [blame] | 175 | int wideio_index; |
Richard Spiegel | aa18385 | 2017-10-05 18:53:31 -0700 | [diff] [blame] | 176 | |
Richard Spiegel | 7a39e02 | 2017-11-09 10:54:04 -0700 | [diff] [blame] | 177 | /* |
| 178 | * Be a bit relaxed, tolerate that LPC region might be bigger than |
| 179 | * resource we try to fit, do it like this for all regions < 16 bytes. |
| 180 | * If there is a resource > 16 bytes it must be 512 bytes to be able |
| 181 | * to allocate the fresh LPC window. |
| 182 | * |
| 183 | * AGESA and early initialization can set a wide IO port. This code |
| 184 | * will verify if required region was previously set and will avoid |
| 185 | * setting a new wide IO resource if one is already set. |
| 186 | */ |
| 187 | |
Richard Spiegel | aa18385 | 2017-10-05 18:53:31 -0700 | [diff] [blame] | 188 | for (res = child->resource_list; res; res = res->next) { |
| 189 | if (!(res->flags & IORESOURCE_IO)) |
| 190 | continue; |
| 191 | base = res->base; |
| 192 | end = resource_end(res); |
Richard Spiegel | aa18385 | 2017-10-05 18:53:31 -0700 | [diff] [blame] | 193 | printk(BIOS_DEBUG, |
Richard Spiegel | c5ecd3e | 2017-09-29 10:05:35 -0700 | [diff] [blame] | 194 | "Southbridge LPC decode:%s, base=0x%08x, end=0x%08x\n", |
| 195 | dev_path(child), base, end); |
| 196 | /* find a resource size */ |
Richard Spiegel | aa18385 | 2017-10-05 18:53:31 -0700 | [diff] [blame] | 197 | switch (base) { |
| 198 | case 0x60: /* KB */ |
| 199 | case 0x64: /* MS */ |
Richard Spiegel | c5ecd3e | 2017-09-29 10:05:35 -0700 | [diff] [blame] | 200 | set |= DECODE_ENABLE_KBC_PORT; |
Richard Spiegel | aa18385 | 2017-10-05 18:53:31 -0700 | [diff] [blame] | 201 | rsize = 1; |
| 202 | break; |
| 203 | case 0x3f8: /* COM1 */ |
Richard Spiegel | c5ecd3e | 2017-09-29 10:05:35 -0700 | [diff] [blame] | 204 | set |= DECODE_ENABLE_SERIAL_PORT0; |
Richard Spiegel | aa18385 | 2017-10-05 18:53:31 -0700 | [diff] [blame] | 205 | rsize = 8; |
| 206 | break; |
| 207 | case 0x2f8: /* COM2 */ |
Richard Spiegel | c5ecd3e | 2017-09-29 10:05:35 -0700 | [diff] [blame] | 208 | set |= DECODE_ENABLE_SERIAL_PORT1; |
Richard Spiegel | aa18385 | 2017-10-05 18:53:31 -0700 | [diff] [blame] | 209 | rsize = 8; |
| 210 | break; |
| 211 | case 0x378: /* Parallel 1 */ |
Richard Spiegel | c5ecd3e | 2017-09-29 10:05:35 -0700 | [diff] [blame] | 212 | set |= DECODE_ENABLE_PARALLEL_PORT0; |
| 213 | /* enable 0x778 for ECP mode */ |
| 214 | set |= DECODE_ENABLE_PARALLEL_PORT1; |
Richard Spiegel | aa18385 | 2017-10-05 18:53:31 -0700 | [diff] [blame] | 215 | rsize = 8; |
| 216 | break; |
| 217 | case 0x3f0: /* FD0 */ |
Richard Spiegel | c5ecd3e | 2017-09-29 10:05:35 -0700 | [diff] [blame] | 218 | set |= DECODE_ENABLE_FDC_PORT0; |
Richard Spiegel | aa18385 | 2017-10-05 18:53:31 -0700 | [diff] [blame] | 219 | rsize = 8; |
| 220 | break; |
| 221 | case 0x220: /* 0x220 - 0x227 */ |
Richard Spiegel | c5ecd3e | 2017-09-29 10:05:35 -0700 | [diff] [blame] | 222 | set |= DECODE_ENABLE_SERIAL_PORT2; |
Richard Spiegel | aa18385 | 2017-10-05 18:53:31 -0700 | [diff] [blame] | 223 | rsize = 8; |
| 224 | break; |
| 225 | case 0x228: /* 0x228 - 0x22f */ |
Richard Spiegel | c5ecd3e | 2017-09-29 10:05:35 -0700 | [diff] [blame] | 226 | set |= DECODE_ENABLE_SERIAL_PORT3; |
Richard Spiegel | aa18385 | 2017-10-05 18:53:31 -0700 | [diff] [blame] | 227 | rsize = 8; |
| 228 | break; |
| 229 | case 0x238: /* 0x238 - 0x23f */ |
Richard Spiegel | c5ecd3e | 2017-09-29 10:05:35 -0700 | [diff] [blame] | 230 | set |= DECODE_ENABLE_SERIAL_PORT4; |
Richard Spiegel | aa18385 | 2017-10-05 18:53:31 -0700 | [diff] [blame] | 231 | rsize = 8; |
| 232 | break; |
| 233 | case 0x300: /* 0x300 - 0x301 */ |
Richard Spiegel | c5ecd3e | 2017-09-29 10:05:35 -0700 | [diff] [blame] | 234 | set |= DECODE_ENABLE_MIDI_PORT0; |
Richard Spiegel | aa18385 | 2017-10-05 18:53:31 -0700 | [diff] [blame] | 235 | rsize = 2; |
| 236 | break; |
| 237 | case 0x400: |
Richard Spiegel | c5ecd3e | 2017-09-29 10:05:35 -0700 | [diff] [blame] | 238 | set_x |= DECODE_IO_PORT_ENABLE0; |
Richard Spiegel | aa18385 | 2017-10-05 18:53:31 -0700 | [diff] [blame] | 239 | rsize = 0x40; |
| 240 | break; |
| 241 | case 0x480: |
Richard Spiegel | c5ecd3e | 2017-09-29 10:05:35 -0700 | [diff] [blame] | 242 | set_x |= DECODE_IO_PORT_ENABLE1; |
Richard Spiegel | aa18385 | 2017-10-05 18:53:31 -0700 | [diff] [blame] | 243 | rsize = 0x40; |
| 244 | break; |
| 245 | case 0x500: |
Richard Spiegel | c5ecd3e | 2017-09-29 10:05:35 -0700 | [diff] [blame] | 246 | set_x |= DECODE_IO_PORT_ENABLE2; |
Richard Spiegel | aa18385 | 2017-10-05 18:53:31 -0700 | [diff] [blame] | 247 | rsize = 0x40; |
| 248 | break; |
| 249 | case 0x580: |
Richard Spiegel | c5ecd3e | 2017-09-29 10:05:35 -0700 | [diff] [blame] | 250 | set_x |= DECODE_IO_PORT_ENABLE3; |
Richard Spiegel | aa18385 | 2017-10-05 18:53:31 -0700 | [diff] [blame] | 251 | rsize = 0x40; |
| 252 | break; |
| 253 | case 0x4700: |
Richard Spiegel | c5ecd3e | 2017-09-29 10:05:35 -0700 | [diff] [blame] | 254 | set_x |= DECODE_IO_PORT_ENABLE5; |
Richard Spiegel | aa18385 | 2017-10-05 18:53:31 -0700 | [diff] [blame] | 255 | rsize = 0xc; |
| 256 | break; |
| 257 | case 0xfd60: |
Richard Spiegel | c5ecd3e | 2017-09-29 10:05:35 -0700 | [diff] [blame] | 258 | set_x |= DECODE_IO_PORT_ENABLE6; |
Richard Spiegel | aa18385 | 2017-10-05 18:53:31 -0700 | [diff] [blame] | 259 | rsize = 16; |
| 260 | break; |
| 261 | default: |
| 262 | rsize = 0; |
Richard Spiegel | b5f9645 | 2017-11-22 15:28:25 -0700 | [diff] [blame] | 263 | wideio_index = sb_find_wideio_range(base, res->size); |
| 264 | if (wideio_index != WIDEIO_RANGE_ERROR) { |
| 265 | rsize = sb_wideio_size(wideio_index); |
| 266 | printk(BIOS_DEBUG, "Covered by wideIO"); |
| 267 | printk(BIOS_DEBUG, " %d\n", wideio_index); |
Richard Spiegel | 7a39e02 | 2017-11-09 10:54:04 -0700 | [diff] [blame] | 268 | } |
Richard Spiegel | aa18385 | 2017-10-05 18:53:31 -0700 | [diff] [blame] | 269 | } |
| 270 | /* check if region found and matches the enable */ |
| 271 | if (res->size <= rsize) { |
| 272 | *reg |= set; |
| 273 | *reg_x |= set_x; |
| 274 | /* check if we can fit resource in variable range */ |
Richard Spiegel | aa18385 | 2017-10-05 18:53:31 -0700 | [diff] [blame] | 275 | } else { |
Richard Spiegel | b5f9645 | 2017-11-22 15:28:25 -0700 | [diff] [blame] | 276 | wideio_index = sb_set_wideio_range(base, res->size); |
| 277 | if (wideio_index != WIDEIO_RANGE_ERROR) { |
| 278 | /* preserve wide IO related bits. */ |
| 279 | *reg_x = pci_read_config32(SOC_LPC_DEV, |
| 280 | LPC_IO_OR_MEM_DECODE_ENABLE); |
| 281 | |
| 282 | printk(BIOS_DEBUG, |
| 283 | "Range assigned to wide IO %d\n", |
| 284 | wideio_index); |
| 285 | } else { |
| 286 | printk(BIOS_ERR, |
| 287 | "cannot fit LPC decode region:"); |
| 288 | printk(BIOS_ERR, |
| 289 | "%s, base = 0x%08x, end = 0x%08x\n", |
| 290 | dev_path(child), base, end); |
| 291 | } |
Richard Spiegel | aa18385 | 2017-10-05 18:53:31 -0700 | [diff] [blame] | 292 | } |
| 293 | } |
Richard Spiegel | aa18385 | 2017-10-05 18:53:31 -0700 | [diff] [blame] | 294 | } |
| 295 | |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 296 | /** |
| 297 | * @brief Enable resources for children devices |
| 298 | * |
| 299 | * @param dev the device whose children's resources are to be enabled |
| 300 | * |
| 301 | */ |
Elyes HAOUAS | 777ccd4 | 2018-05-22 10:52:05 +0200 | [diff] [blame^] | 302 | static void lpc_enable_childrens_resources(struct device *dev) |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 303 | { |
| 304 | struct bus *link; |
| 305 | u32 reg, reg_x; |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 306 | |
Richard Spiegel | c5ecd3e | 2017-09-29 10:05:35 -0700 | [diff] [blame] | 307 | reg = pci_read_config32(dev, LPC_IO_PORT_DECODE_ENABLE); |
| 308 | reg_x = pci_read_config32(dev, LPC_IO_OR_MEM_DECODE_ENABLE); |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 309 | |
Richard Spiegel | aa18385 | 2017-10-05 18:53:31 -0700 | [diff] [blame] | 310 | for (link = dev->link_list; link; link = link->next) { |
Elyes HAOUAS | 777ccd4 | 2018-05-22 10:52:05 +0200 | [diff] [blame^] | 311 | struct device *child; |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 312 | for (child = link->children; child; |
| 313 | child = child->sibling) { |
| 314 | if (child->enabled |
| 315 | && (child->path.type == DEVICE_PATH_PNP)) { |
Richard Spiegel | 7a39e02 | 2017-11-09 10:54:04 -0700 | [diff] [blame] | 316 | set_child_resource(child, |
Richard Spiegel | aa18385 | 2017-10-05 18:53:31 -0700 | [diff] [blame] | 317 | ®, |
Richard Spiegel | b5f9645 | 2017-11-22 15:28:25 -0700 | [diff] [blame] | 318 | ®_x); |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 319 | } |
| 320 | } |
| 321 | } |
Richard Spiegel | c5ecd3e | 2017-09-29 10:05:35 -0700 | [diff] [blame] | 322 | pci_write_config32(dev, LPC_IO_PORT_DECODE_ENABLE, reg); |
| 323 | pci_write_config32(dev, LPC_IO_OR_MEM_DECODE_ENABLE, reg_x); |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 324 | } |
| 325 | |
Elyes HAOUAS | 777ccd4 | 2018-05-22 10:52:05 +0200 | [diff] [blame^] | 326 | static void lpc_enable_resources(struct device *dev) |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 327 | { |
| 328 | pci_dev_enable_resources(dev); |
Marc Jones | dfeb1c4 | 2017-08-07 19:08:24 -0600 | [diff] [blame] | 329 | lpc_enable_childrens_resources(dev); |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 330 | } |
| 331 | |
| 332 | unsigned long acpi_fill_mcfg(unsigned long current) |
| 333 | { |
| 334 | /* Just a dummy */ |
| 335 | return current; |
| 336 | } |
| 337 | |
| 338 | static struct pci_operations lops_pci = { |
| 339 | .set_subsystem = pci_dev_set_subsystem, |
| 340 | }; |
| 341 | |
| 342 | static struct device_operations lpc_ops = { |
Marc Jones | dfeb1c4 | 2017-08-07 19:08:24 -0600 | [diff] [blame] | 343 | .read_resources = lpc_read_resources, |
| 344 | .set_resources = lpc_set_resources, |
| 345 | .enable_resources = lpc_enable_resources, |
Marc Jones | 257db58 | 2017-06-18 17:33:30 -0600 | [diff] [blame] | 346 | .acpi_inject_dsdt_generator = southbridge_inject_dsdt, |
| 347 | .write_acpi_tables = southbridge_write_acpi_tables, |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 348 | .init = lpc_init, |
| 349 | .scan_bus = scan_lpc_bus, |
| 350 | .ops_pci = &lops_pci, |
| 351 | }; |
| 352 | |
| 353 | static const unsigned short pci_device_ids[] = { |
| 354 | PCI_DEVICE_ID_AMD_SB900_LPC, |
| 355 | PCI_DEVICE_ID_AMD_CZ_LPC, |
| 356 | 0 |
| 357 | }; |
| 358 | static const struct pci_driver lpc_driver __pci_driver = { |
| 359 | .ops = &lpc_ops, |
| 360 | .vendor = PCI_VENDOR_ID_AMD, |
| 361 | .devices = pci_device_ids, |
| 362 | }; |