Angel Pons | 0612b27 | 2020-04-05 15:46:56 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Furquan Shaikh | a8198eb | 2017-08-04 16:12:19 -0700 | [diff] [blame] | 2 | |
Furquan Shaikh | 76cedd2 | 2020-05-02 10:24:23 -0700 | [diff] [blame] | 3 | #include <acpi/acpi.h> |
Patrick Rudolph | 49ae596 | 2020-04-15 11:19:31 +0200 | [diff] [blame] | 4 | #include <acpi/acpigen.h> |
Kyösti Mälkki | 5daa1d3 | 2020-06-14 12:01:58 +0300 | [diff] [blame] | 5 | #include <acpi/acpi_gnvs.h> |
Subrata Banik | afa07f7 | 2018-05-24 12:21:06 +0530 | [diff] [blame] | 6 | #include <console/uart.h> |
Aamir Bohra | 83f7bae | 2017-04-26 19:30:41 +0530 | [diff] [blame] | 7 | #include <device/device.h> |
| 8 | #include <device/pci.h> |
Aamir Bohra | 83f7bae | 2017-04-26 19:30:41 +0530 | [diff] [blame] | 9 | #include <device/pci_ids.h> |
Furquan Shaikh | a8198eb | 2017-08-04 16:12:19 -0700 | [diff] [blame] | 10 | #include <device/pci_ops.h> |
Tim Wawrzynczak | f9bb1b4 | 2021-06-25 13:02:16 -0600 | [diff] [blame] | 11 | #include <intelblocks/irq.h> |
Aamir Bohra | 01d75f4 | 2017-03-30 20:12:21 +0530 | [diff] [blame] | 12 | #include <intelblocks/lpss.h> |
| 13 | #include <intelblocks/uart.h> |
Subrata Banik | afa07f7 | 2018-05-24 12:21:06 +0530 | [diff] [blame] | 14 | #include <soc/pci_devs.h> |
| 15 | #include <soc/iomap.h> |
| 16 | #include <soc/nvs.h> |
Patrick Rudolph | 49ae596 | 2020-04-15 11:19:31 +0200 | [diff] [blame] | 17 | #include "chip.h" |
Aamir Bohra | 01d75f4 | 2017-03-30 20:12:21 +0530 | [diff] [blame] | 18 | |
Furquan Shaikh | a8198eb | 2017-08-04 16:12:19 -0700 | [diff] [blame] | 19 | #define UART_PCI_ENABLE (PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER) |
Subrata Banik | afa07f7 | 2018-05-24 12:21:06 +0530 | [diff] [blame] | 20 | |
Michael Niewöhner | 405f229 | 2020-12-21 03:46:58 +0100 | [diff] [blame] | 21 | extern const unsigned int uart_devices[]; |
| 22 | extern const int uart_devices_size; |
Furquan Shaikh | a8198eb | 2017-08-04 16:12:19 -0700 | [diff] [blame] | 23 | |
Furquan Shaikh | 582a0e2 | 2021-01-07 00:16:35 -0800 | [diff] [blame] | 24 | static void uart_lpss_init(pci_devfn_t dev, uintptr_t baseaddr) |
Furquan Shaikh | 3406dd6 | 2017-08-04 15:58:26 -0700 | [diff] [blame] | 25 | { |
Usha P | 5e59a82 | 2019-08-09 18:42:00 +0530 | [diff] [blame] | 26 | /* Ensure controller is in D0 state */ |
Furquan Shaikh | 582a0e2 | 2021-01-07 00:16:35 -0800 | [diff] [blame] | 27 | lpss_set_power_state(dev, STATE_D0); |
Usha P | 5e59a82 | 2019-08-09 18:42:00 +0530 | [diff] [blame] | 28 | |
Furquan Shaikh | 3406dd6 | 2017-08-04 15:58:26 -0700 | [diff] [blame] | 29 | /* Take UART out of reset */ |
| 30 | lpss_reset_release(baseaddr); |
| 31 | |
| 32 | /* Set M and N divisor inputs and enable clock */ |
| 33 | lpss_clk_update(baseaddr, CONFIG_SOC_INTEL_COMMON_LPSS_UART_CLK_M_VAL, |
| 34 | CONFIG_SOC_INTEL_COMMON_LPSS_UART_CLK_N_VAL); |
| 35 | } |
| 36 | |
Nico Huber | 62ddc49 | 2019-05-29 18:39:31 +0200 | [diff] [blame] | 37 | #if CONFIG(INTEL_LPSS_UART_FOR_CONSOLE) |
Felix Held | e3a1247 | 2020-09-11 15:47:09 +0200 | [diff] [blame] | 38 | uintptr_t uart_platform_base(unsigned int idx) |
Aamir Bohra | 01d75f4 | 2017-03-30 20:12:21 +0530 | [diff] [blame] | 39 | { |
Nico Huber | ce8eebd | 2019-05-29 18:33:35 +0200 | [diff] [blame] | 40 | if (idx == CONFIG_UART_FOR_CONSOLE) |
Nico Huber | 9995418 | 2019-05-29 23:33:06 +0200 | [diff] [blame] | 41 | return CONFIG_CONSOLE_UART_BASE_ADDRESS; |
Nico Huber | ce8eebd | 2019-05-29 18:33:35 +0200 | [diff] [blame] | 42 | return 0; |
Subrata Banik | afa07f7 | 2018-05-24 12:21:06 +0530 | [diff] [blame] | 43 | } |
| 44 | #endif |
| 45 | |
Furquan Shaikh | 582a0e2 | 2021-01-07 00:16:35 -0800 | [diff] [blame] | 46 | static pci_devfn_t uart_console_get_pci_bdf(void) |
Subrata Banik | afa07f7 | 2018-05-24 12:21:06 +0530 | [diff] [blame] | 47 | { |
Furquan Shaikh | 582a0e2 | 2021-01-07 00:16:35 -0800 | [diff] [blame] | 48 | int devfn; |
Subrata Banik | afa07f7 | 2018-05-24 12:21:06 +0530 | [diff] [blame] | 49 | |
Furquan Shaikh | a8198eb | 2017-08-04 16:12:19 -0700 | [diff] [blame] | 50 | /* |
Nico Huber | a96e66a | 2018-11-11 02:51:14 +0100 | [diff] [blame] | 51 | * This function will get called even if INTEL_LPSS_UART_FOR_CONSOLE |
| 52 | * config option is not selected. |
| 53 | * By default return NULL in this case to avoid compilation errors. |
Furquan Shaikh | a8198eb | 2017-08-04 16:12:19 -0700 | [diff] [blame] | 54 | */ |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 55 | if (!CONFIG(INTEL_LPSS_UART_FOR_CONSOLE)) |
Furquan Shaikh | 582a0e2 | 2021-01-07 00:16:35 -0800 | [diff] [blame] | 56 | return PCI_DEV_INVALID; |
| 57 | |
Michael Niewöhner | 405f229 | 2020-12-21 03:46:58 +0100 | [diff] [blame] | 58 | if (CONFIG_UART_FOR_CONSOLE > uart_devices_size) |
Furquan Shaikh | 582a0e2 | 2021-01-07 00:16:35 -0800 | [diff] [blame] | 59 | return PCI_DEV_INVALID; |
| 60 | |
Michael Niewöhner | 405f229 | 2020-12-21 03:46:58 +0100 | [diff] [blame] | 61 | devfn = uart_devices[CONFIG_UART_FOR_CONSOLE]; |
| 62 | if (devfn == PCI_DEVFN_INVALID) |
| 63 | return PCI_DEV_INVALID; |
| 64 | |
Furquan Shaikh | 582a0e2 | 2021-01-07 00:16:35 -0800 | [diff] [blame] | 65 | return PCI_DEV(0, PCI_SLOT(devfn), PCI_FUNC(devfn)); |
| 66 | } |
| 67 | |
| 68 | const struct device *uart_get_device(void) |
| 69 | { |
| 70 | pci_devfn_t dev = uart_console_get_pci_bdf(); |
| 71 | if (dev == PCI_DEV_INVALID) |
Subrata Banik | afa07f7 | 2018-05-24 12:21:06 +0530 | [diff] [blame] | 72 | return NULL; |
| 73 | |
Furquan Shaikh | 582a0e2 | 2021-01-07 00:16:35 -0800 | [diff] [blame] | 74 | return pcidev_path_on_root(PCI_DEV2DEVFN(dev)); |
Furquan Shaikh | a8198eb | 2017-08-04 16:12:19 -0700 | [diff] [blame] | 75 | } |
| 76 | |
Subrata Banik | afa07f7 | 2018-05-24 12:21:06 +0530 | [diff] [blame] | 77 | bool uart_is_controller_initialized(void) |
Furquan Shaikh | a8198eb | 2017-08-04 16:12:19 -0700 | [diff] [blame] | 78 | { |
Furquan Shaikh | a8198eb | 2017-08-04 16:12:19 -0700 | [diff] [blame] | 79 | uintptr_t base; |
Furquan Shaikh | 582a0e2 | 2021-01-07 00:16:35 -0800 | [diff] [blame] | 80 | pci_devfn_t dev = uart_console_get_pci_bdf(); |
Aamir Bohra | 17cfba6 | 2019-07-25 20:56:54 +0530 | [diff] [blame] | 81 | |
Furquan Shaikh | 582a0e2 | 2021-01-07 00:16:35 -0800 | [diff] [blame] | 82 | if (dev == PCI_DEV_INVALID) |
Aamir Bohra | 17cfba6 | 2019-07-25 20:56:54 +0530 | [diff] [blame] | 83 | return false; |
Furquan Shaikh | a8198eb | 2017-08-04 16:12:19 -0700 | [diff] [blame] | 84 | |
Furquan Shaikh | 582a0e2 | 2021-01-07 00:16:35 -0800 | [diff] [blame] | 85 | base = pci_s_read_config32(dev, PCI_BASE_ADDRESS_0) & ~0xFFF; |
Furquan Shaikh | a8198eb | 2017-08-04 16:12:19 -0700 | [diff] [blame] | 86 | if (!base) |
| 87 | return false; |
| 88 | |
Furquan Shaikh | 582a0e2 | 2021-01-07 00:16:35 -0800 | [diff] [blame] | 89 | if ((pci_s_read_config16(dev, PCI_COMMAND) & UART_PCI_ENABLE) |
Furquan Shaikh | a8198eb | 2017-08-04 16:12:19 -0700 | [diff] [blame] | 90 | != UART_PCI_ENABLE) |
| 91 | return false; |
| 92 | |
| 93 | return !lpss_is_controller_in_reset(base); |
Aamir Bohra | 01d75f4 | 2017-03-30 20:12:21 +0530 | [diff] [blame] | 94 | } |
Aamir Bohra | 83f7bae | 2017-04-26 19:30:41 +0530 | [diff] [blame] | 95 | |
Subrata Banik | afa07f7 | 2018-05-24 12:21:06 +0530 | [diff] [blame] | 96 | void uart_bootblock_init(void) |
Furquan Shaikh | a8198eb | 2017-08-04 16:12:19 -0700 | [diff] [blame] | 97 | { |
Furquan Shaikh | 582a0e2 | 2021-01-07 00:16:35 -0800 | [diff] [blame] | 98 | const uint32_t baseaddr = CONFIG_CONSOLE_UART_BASE_ADDRESS; |
| 99 | pci_devfn_t dev = uart_console_get_pci_bdf(); |
Aamir Bohra | 17cfba6 | 2019-07-25 20:56:54 +0530 | [diff] [blame] | 100 | |
Furquan Shaikh | 582a0e2 | 2021-01-07 00:16:35 -0800 | [diff] [blame] | 101 | if (dev == PCI_DEV_INVALID) |
Aamir Bohra | 17cfba6 | 2019-07-25 20:56:54 +0530 | [diff] [blame] | 102 | return; |
| 103 | |
Furquan Shaikh | 582a0e2 | 2021-01-07 00:16:35 -0800 | [diff] [blame] | 104 | /* Set UART base address */ |
| 105 | pci_s_write_config32(dev, PCI_BASE_ADDRESS_0, baseaddr); |
| 106 | |
| 107 | /* Enable memory access and bus master */ |
| 108 | pci_s_write_config16(dev, PCI_COMMAND, UART_PCI_ENABLE); |
| 109 | |
| 110 | uart_lpss_init(dev, baseaddr); |
Subrata Banik | afa07f7 | 2018-05-24 12:21:06 +0530 | [diff] [blame] | 111 | } |
| 112 | |
| 113 | #if ENV_RAMSTAGE |
| 114 | |
| 115 | static void uart_read_resources(struct device *dev) |
| 116 | { |
| 117 | pci_dev_read_resources(dev); |
| 118 | |
| 119 | /* Set the configured UART base address for the debug port */ |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 120 | if (CONFIG(INTEL_LPSS_UART_FOR_CONSOLE) && |
Nico Huber | a96e66a | 2018-11-11 02:51:14 +0100 | [diff] [blame] | 121 | uart_is_debug_controller(dev)) { |
Subrata Banik | afa07f7 | 2018-05-24 12:21:06 +0530 | [diff] [blame] | 122 | struct resource *res = find_resource(dev, PCI_BASE_ADDRESS_0); |
| 123 | /* Need to set the base and size for the resource allocator. */ |
Nico Huber | 9995418 | 2019-05-29 23:33:06 +0200 | [diff] [blame] | 124 | res->base = CONFIG_CONSOLE_UART_BASE_ADDRESS; |
| 125 | res->size = 0x1000; |
Subrata Banik | afa07f7 | 2018-05-24 12:21:06 +0530 | [diff] [blame] | 126 | res->flags = IORESOURCE_MEM | IORESOURCE_ASSIGNED | |
| 127 | IORESOURCE_FIXED; |
| 128 | } |
Patrick Rudolph | e42ce6b | 2021-06-07 16:46:40 +0200 | [diff] [blame] | 129 | /* In ACPI mode mark the decoded region as reserved */ |
| 130 | if (dev->hidden) { |
| 131 | struct resource *res = find_resource(dev, PCI_BASE_ADDRESS_0); |
| 132 | res->flags |= IORESOURCE_RESERVE; |
| 133 | } |
Subrata Banik | afa07f7 | 2018-05-24 12:21:06 +0530 | [diff] [blame] | 134 | } |
| 135 | |
| 136 | /* |
| 137 | * Check if UART debug port controller needs to be initialized on resume. |
| 138 | * |
| 139 | * Returns: |
| 140 | * true = when SoC wants debug port initialization on resume |
| 141 | * false = otherwise |
| 142 | */ |
| 143 | static bool pch_uart_init_debug_controller_on_resume(void) |
| 144 | { |
Kyösti Mälkki | 0c1dd9c | 2020-06-17 23:37:49 +0300 | [diff] [blame] | 145 | struct global_nvs *gnvs = acpi_get_gnvs(); |
Subrata Banik | afa07f7 | 2018-05-24 12:21:06 +0530 | [diff] [blame] | 146 | |
| 147 | if (gnvs) |
| 148 | return !!gnvs->uior; |
| 149 | |
Furquan Shaikh | a8198eb | 2017-08-04 16:12:19 -0700 | [diff] [blame] | 150 | return false; |
| 151 | } |
| 152 | |
| 153 | bool uart_is_debug_controller(struct device *dev) |
| 154 | { |
Subrata Banik | afa07f7 | 2018-05-24 12:21:06 +0530 | [diff] [blame] | 155 | return dev == uart_get_device(); |
Furquan Shaikh | a8198eb | 2017-08-04 16:12:19 -0700 | [diff] [blame] | 156 | } |
| 157 | |
| 158 | /* |
| 159 | * This is a workaround to enable UART controller for the debug port if: |
| 160 | * 1. CONSOLE_SERIAL is not enabled in coreboot, and |
| 161 | * 2. This boot is S3 resume, and |
| 162 | * 3. SoC wants to initialize debug UART controller. |
| 163 | * |
| 164 | * This workaround is required because Linux kernel hangs on resume if console |
| 165 | * is not enabled in coreboot, but it is enabled in kernel and not suspended. |
| 166 | */ |
| 167 | static bool uart_controller_needs_init(struct device *dev) |
| 168 | { |
| 169 | /* |
Jonathan Neuschäfer | 5268b76 | 2018-02-12 12:24:25 +0100 | [diff] [blame] | 170 | * If coreboot has CONSOLE_SERIAL enabled, the skip re-initializing |
Furquan Shaikh | a8198eb | 2017-08-04 16:12:19 -0700 | [diff] [blame] | 171 | * controller here. |
| 172 | */ |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 173 | if (CONFIG(CONSOLE_SERIAL)) |
Furquan Shaikh | a8198eb | 2017-08-04 16:12:19 -0700 | [diff] [blame] | 174 | return false; |
| 175 | |
| 176 | /* If this device does not correspond to debug port, then skip. */ |
| 177 | if (!uart_is_debug_controller(dev)) |
| 178 | return false; |
| 179 | |
| 180 | /* Initialize UART controller only on S3 resume. */ |
| 181 | if (!acpi_is_wakeup_s3()) |
| 182 | return false; |
| 183 | |
| 184 | /* |
Subrata Banik | afa07f7 | 2018-05-24 12:21:06 +0530 | [diff] [blame] | 185 | * check if SOC wants to initialize UART on resume |
Furquan Shaikh | a8198eb | 2017-08-04 16:12:19 -0700 | [diff] [blame] | 186 | */ |
| 187 | return pch_uart_init_debug_controller_on_resume(); |
| 188 | } |
| 189 | |
| 190 | static void uart_common_enable_resources(struct device *dev) |
| 191 | { |
| 192 | pci_dev_enable_resources(dev); |
| 193 | |
| 194 | if (uart_controller_needs_init(dev)) { |
| 195 | uintptr_t base; |
| 196 | |
| 197 | base = pci_read_config32(dev, PCI_BASE_ADDRESS_0) & ~0xFFF; |
| 198 | if (base) |
Furquan Shaikh | 582a0e2 | 2021-01-07 00:16:35 -0800 | [diff] [blame] | 199 | uart_lpss_init(PCI_BDF(dev), base); |
Furquan Shaikh | a8198eb | 2017-08-04 16:12:19 -0700 | [diff] [blame] | 200 | } |
| 201 | } |
| 202 | |
Patrick Rudolph | 49ae596 | 2020-04-15 11:19:31 +0200 | [diff] [blame] | 203 | static void uart_acpi_write_irq(const struct device *dev) |
| 204 | { |
Tim Wawrzynczak | f9bb1b4 | 2021-06-25 13:02:16 -0600 | [diff] [blame] | 205 | if (CONFIG(SOC_INTEL_COMMON_BLOCK_IRQ)) { |
| 206 | const int irq = get_pci_devfn_irq(dev->path.pci.devfn); |
| 207 | if (irq != INVALID_IRQ) { |
| 208 | struct acpi_irq airq = (struct acpi_irq)ACPI_IRQ_LEVEL_LOW(irq); |
| 209 | acpi_device_write_interrupt(&airq); |
| 210 | } |
Patrick Rudolph | 49ae596 | 2020-04-15 11:19:31 +0200 | [diff] [blame] | 211 | } |
Patrick Rudolph | 49ae596 | 2020-04-15 11:19:31 +0200 | [diff] [blame] | 212 | } |
| 213 | |
| 214 | /* |
| 215 | * Generate an ACPI entry if the device is enabled in devicetree for the ACPI |
| 216 | * LPSS driver. In this mode the device and vendor ID reads as 0xffff, but the |
| 217 | * PCI device is still there. |
| 218 | */ |
| 219 | static void uart_fill_ssdt(const struct device *dev) |
| 220 | { |
| 221 | const char *scope = acpi_device_scope(dev); |
| 222 | const char *hid = acpi_device_hid(dev); |
| 223 | struct resource *res; |
| 224 | |
| 225 | /* In ACPI mode the device is "invisible" */ |
| 226 | if (!dev->hidden) |
| 227 | return; |
| 228 | |
| 229 | if (!scope || !hid) |
| 230 | return; |
| 231 | |
| 232 | res = probe_resource(dev, PCI_BASE_ADDRESS_0); |
| 233 | if (!res) |
| 234 | return; |
| 235 | |
| 236 | /* Scope */ |
| 237 | acpigen_write_scope(scope); |
| 238 | |
| 239 | /* Device */ |
| 240 | acpigen_write_device(acpi_device_name(dev)); |
| 241 | acpigen_write_name_string("_HID", hid); |
| 242 | /* |
| 243 | * Advertise compatibility to Sunrise Point, as the Linux kernel doesn't support |
| 244 | * CannonPoint yet... |
| 245 | */ |
| 246 | if (strcmp(hid, "INT34B8") == 0) |
| 247 | acpigen_write_name_string("_CID", "INT3448"); |
| 248 | else if (strcmp(hid, "INT34B9") == 0) |
| 249 | acpigen_write_name_string("_CID", "INT3449"); |
| 250 | else if (strcmp(hid, "INT34BA") == 0) |
| 251 | acpigen_write_name_string("_CID", "INT344A"); |
| 252 | |
| 253 | acpi_device_write_uid(dev); |
| 254 | acpigen_write_name_string("_DDN", "LPSS ACPI UART"); |
Angel Pons | 69a8a53 | 2022-11-30 11:23:31 +0100 | [diff] [blame] | 255 | |
| 256 | /* Do not hide the UART device from the OS */ |
| 257 | acpigen_write_STA(ACPI_STATUS_DEVICE_ALL_ON); |
Patrick Rudolph | 49ae596 | 2020-04-15 11:19:31 +0200 | [diff] [blame] | 258 | |
| 259 | /* Resources */ |
| 260 | acpigen_write_name("_CRS"); |
| 261 | acpigen_write_resourcetemplate_header(); |
| 262 | |
| 263 | uart_acpi_write_irq(dev); |
| 264 | acpigen_write_mem32fixed(1, res->base, res->size); |
| 265 | |
| 266 | acpigen_write_resourcetemplate_footer(); |
| 267 | |
| 268 | acpigen_pop_len(); /* Device */ |
| 269 | acpigen_pop_len(); /* Scope */ |
| 270 | } |
| 271 | |
| 272 | static const char *uart_acpi_hid(const struct device *dev) |
| 273 | { |
| 274 | switch (dev->device) { |
Felix Singer | 43b7f41 | 2022-03-07 04:34:52 +0100 | [diff] [blame] | 275 | case PCI_DID_INTEL_APL_UART0: |
Patrick Rudolph | 49ae596 | 2020-04-15 11:19:31 +0200 | [diff] [blame] | 276 | return "80865abc"; |
Felix Singer | 43b7f41 | 2022-03-07 04:34:52 +0100 | [diff] [blame] | 277 | case PCI_DID_INTEL_APL_UART1: |
Patrick Rudolph | 49ae596 | 2020-04-15 11:19:31 +0200 | [diff] [blame] | 278 | return "80865abe"; |
Felix Singer | 43b7f41 | 2022-03-07 04:34:52 +0100 | [diff] [blame] | 279 | case PCI_DID_INTEL_APL_UART2: |
Patrick Rudolph | 49ae596 | 2020-04-15 11:19:31 +0200 | [diff] [blame] | 280 | return "80865ac0"; |
Felix Singer | 43b7f41 | 2022-03-07 04:34:52 +0100 | [diff] [blame] | 281 | case PCI_DID_INTEL_GLK_UART0: |
Patrick Rudolph | 49ae596 | 2020-04-15 11:19:31 +0200 | [diff] [blame] | 282 | return "808631bc"; |
Felix Singer | 43b7f41 | 2022-03-07 04:34:52 +0100 | [diff] [blame] | 283 | case PCI_DID_INTEL_GLK_UART1: |
Patrick Rudolph | 49ae596 | 2020-04-15 11:19:31 +0200 | [diff] [blame] | 284 | return "808631be"; |
Felix Singer | 43b7f41 | 2022-03-07 04:34:52 +0100 | [diff] [blame] | 285 | case PCI_DID_INTEL_GLK_UART2: |
Patrick Rudolph | 49ae596 | 2020-04-15 11:19:31 +0200 | [diff] [blame] | 286 | return "808631c0"; |
Felix Singer | 43b7f41 | 2022-03-07 04:34:52 +0100 | [diff] [blame] | 287 | case PCI_DID_INTEL_GLK_UART3: |
Patrick Rudolph | 49ae596 | 2020-04-15 11:19:31 +0200 | [diff] [blame] | 288 | return "808631ee"; |
Felix Singer | 43b7f41 | 2022-03-07 04:34:52 +0100 | [diff] [blame] | 289 | case PCI_DID_INTEL_SPT_UART0: |
| 290 | case PCI_DID_INTEL_SPT_H_UART0: |
Patrick Rudolph | 49ae596 | 2020-04-15 11:19:31 +0200 | [diff] [blame] | 291 | return "INT3448"; |
Felix Singer | 43b7f41 | 2022-03-07 04:34:52 +0100 | [diff] [blame] | 292 | case PCI_DID_INTEL_SPT_UART1: |
| 293 | case PCI_DID_INTEL_SPT_H_UART1: |
Patrick Rudolph | 49ae596 | 2020-04-15 11:19:31 +0200 | [diff] [blame] | 294 | return "INT3449"; |
Felix Singer | 43b7f41 | 2022-03-07 04:34:52 +0100 | [diff] [blame] | 295 | case PCI_DID_INTEL_SPT_UART2: |
| 296 | case PCI_DID_INTEL_SPT_H_UART2: |
Patrick Rudolph | 49ae596 | 2020-04-15 11:19:31 +0200 | [diff] [blame] | 297 | return "INT344A"; |
Felix Singer | 43b7f41 | 2022-03-07 04:34:52 +0100 | [diff] [blame] | 298 | case PCI_DID_INTEL_CNP_H_UART0: |
Patrick Rudolph | 49ae596 | 2020-04-15 11:19:31 +0200 | [diff] [blame] | 299 | return "INT34B8"; |
Felix Singer | 43b7f41 | 2022-03-07 04:34:52 +0100 | [diff] [blame] | 300 | case PCI_DID_INTEL_CNP_H_UART1: |
Patrick Rudolph | 49ae596 | 2020-04-15 11:19:31 +0200 | [diff] [blame] | 301 | return "INT34B9"; |
Felix Singer | 43b7f41 | 2022-03-07 04:34:52 +0100 | [diff] [blame] | 302 | case PCI_DID_INTEL_CNP_H_UART2: |
Patrick Rudolph | 49ae596 | 2020-04-15 11:19:31 +0200 | [diff] [blame] | 303 | return "INT34BA"; |
| 304 | default: |
| 305 | return NULL; |
| 306 | } |
| 307 | } |
| 308 | |
| 309 | static const char *uart_acpi_name(const struct device *dev) |
| 310 | { |
| 311 | switch (dev->device) { |
Tarun Tuli | d8d5228 | 2022-05-03 20:34:32 +0000 | [diff] [blame] | 312 | case PCI_DID_INTEL_ADP_P_UART0: |
Felix Singer | 43b7f41 | 2022-03-07 04:34:52 +0100 | [diff] [blame] | 313 | case PCI_DID_INTEL_APL_UART0: |
| 314 | case PCI_DID_INTEL_GLK_UART0: |
| 315 | case PCI_DID_INTEL_SPT_UART0: |
| 316 | case PCI_DID_INTEL_SPT_H_UART0: |
| 317 | case PCI_DID_INTEL_CNP_H_UART0: |
Patrick Rudolph | 49ae596 | 2020-04-15 11:19:31 +0200 | [diff] [blame] | 318 | return "UAR0"; |
Tarun Tuli | d8d5228 | 2022-05-03 20:34:32 +0000 | [diff] [blame] | 319 | case PCI_DID_INTEL_ADP_P_UART1: |
Felix Singer | 43b7f41 | 2022-03-07 04:34:52 +0100 | [diff] [blame] | 320 | case PCI_DID_INTEL_APL_UART1: |
| 321 | case PCI_DID_INTEL_GLK_UART1: |
| 322 | case PCI_DID_INTEL_SPT_UART1: |
| 323 | case PCI_DID_INTEL_SPT_H_UART1: |
| 324 | case PCI_DID_INTEL_CNP_H_UART1: |
Patrick Rudolph | 49ae596 | 2020-04-15 11:19:31 +0200 | [diff] [blame] | 325 | return "UAR1"; |
Tarun Tuli | d8d5228 | 2022-05-03 20:34:32 +0000 | [diff] [blame] | 326 | case PCI_DID_INTEL_ADP_P_UART2: |
Felix Singer | 43b7f41 | 2022-03-07 04:34:52 +0100 | [diff] [blame] | 327 | case PCI_DID_INTEL_APL_UART2: |
| 328 | case PCI_DID_INTEL_GLK_UART2: |
| 329 | case PCI_DID_INTEL_SPT_UART2: |
| 330 | case PCI_DID_INTEL_SPT_H_UART2: |
| 331 | case PCI_DID_INTEL_CNP_H_UART2: |
Patrick Rudolph | 49ae596 | 2020-04-15 11:19:31 +0200 | [diff] [blame] | 332 | return "UAR2"; |
Tarun Tuli | d8d5228 | 2022-05-03 20:34:32 +0000 | [diff] [blame] | 333 | case PCI_DID_INTEL_ADP_P_UART3: |
Felix Singer | 43b7f41 | 2022-03-07 04:34:52 +0100 | [diff] [blame] | 334 | case PCI_DID_INTEL_GLK_UART3: |
Patrick Rudolph | 49ae596 | 2020-04-15 11:19:31 +0200 | [diff] [blame] | 335 | return "UAR3"; |
| 336 | default: |
| 337 | return NULL; |
| 338 | } |
| 339 | } |
| 340 | |
Nico Huber | 5768619 | 2022-08-06 19:11:55 +0200 | [diff] [blame] | 341 | struct device_operations uart_ops = { |
Elyes HAOUAS | 1d19127 | 2018-11-27 12:23:48 +0100 | [diff] [blame] | 342 | .read_resources = uart_read_resources, |
| 343 | .set_resources = pci_dev_set_resources, |
| 344 | .enable_resources = uart_common_enable_resources, |
Subrata Banik | 6bbc91a | 2017-12-07 14:55:51 +0530 | [diff] [blame] | 345 | .ops_pci = &pci_dev_ops_pci, |
Patrick Rudolph | 49ae596 | 2020-04-15 11:19:31 +0200 | [diff] [blame] | 346 | .acpi_fill_ssdt = uart_fill_ssdt, |
| 347 | .acpi_hid = uart_acpi_hid, |
| 348 | .acpi_name = uart_acpi_name, |
Aamir Bohra | 83f7bae | 2017-04-26 19:30:41 +0530 | [diff] [blame] | 349 | }; |
| 350 | |
| 351 | static const unsigned short pci_device_ids[] = { |
Wonkyu Kim | 9f40107 | 2020-11-13 15:16:32 -0800 | [diff] [blame] | 352 | PCI_DID_INTEL_MTL_UART0, |
| 353 | PCI_DID_INTEL_MTL_UART1, |
| 354 | PCI_DID_INTEL_MTL_UART2, |
Felix Singer | 43b7f41 | 2022-03-07 04:34:52 +0100 | [diff] [blame] | 355 | PCI_DID_INTEL_APL_UART0, |
| 356 | PCI_DID_INTEL_APL_UART1, |
| 357 | PCI_DID_INTEL_APL_UART2, |
| 358 | PCI_DID_INTEL_APL_UART3, |
| 359 | PCI_DID_INTEL_CNL_UART0, |
| 360 | PCI_DID_INTEL_CNL_UART1, |
| 361 | PCI_DID_INTEL_CNL_UART2, |
| 362 | PCI_DID_INTEL_GLK_UART0, |
| 363 | PCI_DID_INTEL_GLK_UART1, |
| 364 | PCI_DID_INTEL_GLK_UART2, |
| 365 | PCI_DID_INTEL_GLK_UART3, |
| 366 | PCI_DID_INTEL_CNP_H_UART0, |
| 367 | PCI_DID_INTEL_CNP_H_UART1, |
| 368 | PCI_DID_INTEL_CNP_H_UART2, |
| 369 | PCI_DID_INTEL_ICP_UART0, |
| 370 | PCI_DID_INTEL_ICP_UART1, |
| 371 | PCI_DID_INTEL_ICP_UART2, |
| 372 | PCI_DID_INTEL_CMP_UART0, |
| 373 | PCI_DID_INTEL_CMP_UART1, |
| 374 | PCI_DID_INTEL_CMP_UART2, |
| 375 | PCI_DID_INTEL_CMP_H_UART0, |
| 376 | PCI_DID_INTEL_CMP_H_UART1, |
| 377 | PCI_DID_INTEL_CMP_H_UART2, |
| 378 | PCI_DID_INTEL_TGP_UART0, |
| 379 | PCI_DID_INTEL_TGP_UART1, |
| 380 | PCI_DID_INTEL_TGP_UART2, |
| 381 | PCI_DID_INTEL_TGP_H_UART0, |
| 382 | PCI_DID_INTEL_TGP_H_UART1, |
| 383 | PCI_DID_INTEL_TGP_H_UART2, |
| 384 | PCI_DID_INTEL_TGP_H_UART3, |
| 385 | PCI_DID_INTEL_MCC_UART0, |
| 386 | PCI_DID_INTEL_MCC_UART1, |
| 387 | PCI_DID_INTEL_MCC_UART2, |
| 388 | PCI_DID_INTEL_JSP_UART0, |
| 389 | PCI_DID_INTEL_JSP_UART1, |
| 390 | PCI_DID_INTEL_JSP_UART2, |
| 391 | PCI_DID_INTEL_ADP_S_UART0, |
| 392 | PCI_DID_INTEL_ADP_S_UART1, |
| 393 | PCI_DID_INTEL_ADP_S_UART2, |
| 394 | PCI_DID_INTEL_ADP_S_UART3, |
| 395 | PCI_DID_INTEL_ADP_S_UART4, |
| 396 | PCI_DID_INTEL_ADP_S_UART5, |
| 397 | PCI_DID_INTEL_ADP_S_UART6, |
| 398 | PCI_DID_INTEL_ADP_P_UART0, |
| 399 | PCI_DID_INTEL_ADP_P_UART1, |
| 400 | PCI_DID_INTEL_ADP_P_UART2, |
| 401 | PCI_DID_INTEL_ADP_P_UART3, |
| 402 | PCI_DID_INTEL_ADP_P_UART4, |
| 403 | PCI_DID_INTEL_ADP_P_UART5, |
| 404 | PCI_DID_INTEL_ADP_P_UART6, |
| 405 | PCI_DID_INTEL_ADP_M_N_UART0, |
| 406 | PCI_DID_INTEL_ADP_M_N_UART1, |
| 407 | PCI_DID_INTEL_ADP_M_N_UART2, |
| 408 | PCI_DID_INTEL_ADP_M_N_UART3, |
Jeremy Soller | 14d69d0 | 2023-05-17 14:52:03 -0600 | [diff] [blame^] | 409 | PCI_DID_INTEL_RPP_S_UART0, |
| 410 | PCI_DID_INTEL_RPP_S_UART1, |
| 411 | PCI_DID_INTEL_RPP_S_UART2, |
| 412 | PCI_DID_INTEL_RPP_S_UART3, |
Hannah Williams | f714965 | 2017-05-13 16:18:02 -0700 | [diff] [blame] | 413 | 0, |
Aamir Bohra | 83f7bae | 2017-04-26 19:30:41 +0530 | [diff] [blame] | 414 | }; |
| 415 | |
| 416 | static const struct pci_driver pch_uart __pci_driver = { |
Nico Huber | 5768619 | 2022-08-06 19:11:55 +0200 | [diff] [blame] | 417 | .ops = &uart_ops, |
Felix Singer | 43b7f41 | 2022-03-07 04:34:52 +0100 | [diff] [blame] | 418 | .vendor = PCI_VID_INTEL, |
Aamir Bohra | 83f7bae | 2017-04-26 19:30:41 +0530 | [diff] [blame] | 419 | .devices = pci_device_ids, |
| 420 | }; |
Patrick Rudolph | 49ae596 | 2020-04-15 11:19:31 +0200 | [diff] [blame] | 421 | |
| 422 | static void uart_enable(struct device *dev) |
| 423 | { |
| 424 | struct soc_intel_common_block_uart_config *conf = dev->chip_info; |
Nico Huber | 5768619 | 2022-08-06 19:11:55 +0200 | [diff] [blame] | 425 | dev->ops = &uart_ops; |
Patrick Rudolph | 49ae596 | 2020-04-15 11:19:31 +0200 | [diff] [blame] | 426 | dev->device = conf ? conf->devid : 0; |
| 427 | } |
| 428 | |
| 429 | struct chip_operations soc_intel_common_block_uart_ops = { |
| 430 | CHIP_NAME("LPSS UART in ACPI mode") |
| 431 | .enable_dev = uart_enable |
| 432 | }; |
| 433 | |
Aamir Bohra | 83f7bae | 2017-04-26 19:30:41 +0530 | [diff] [blame] | 434 | #endif /* ENV_RAMSTAGE */ |