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