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