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