Vladimir Serbinenko | 41f55b7 | 2014-10-31 09:10:16 +0100 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright (C) 2014 Vladimir Serbinenko |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; version 2 or (at your option) |
| 9 | * any later version 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. |
Vladimir Serbinenko | 41f55b7 | 2014-10-31 09:10:16 +0100 | [diff] [blame] | 15 | */ |
| 16 | |
Stefan Reinauer | 6a00113 | 2017-07-13 02:20:27 +0200 | [diff] [blame] | 17 | #include <compiler.h> |
Duncan Laurie | 5c02644 | 2016-05-11 14:05:07 -0700 | [diff] [blame] | 18 | #include <arch/acpi_device.h> |
| 19 | #include <arch/acpigen.h> |
Vladimir Serbinenko | 41f55b7 | 2014-10-31 09:10:16 +0100 | [diff] [blame] | 20 | #include <console/console.h> |
| 21 | #include <device/device.h> |
| 22 | #include <device/pci.h> |
| 23 | #include <device/pci_ids.h> |
Naresh G Solanki | 3c6377f | 2017-07-03 21:57:11 +0530 | [diff] [blame] | 24 | #include <elog.h> |
Robbie Zhang | 3dea69a | 2016-12-23 12:20:47 -0800 | [diff] [blame] | 25 | #include <sar.h> |
Vladimir Serbinenko | 41f55b7 | 2014-10-31 09:10:16 +0100 | [diff] [blame] | 26 | #include <smbios.h> |
| 27 | #include <string.h> |
Duncan Laurie | 5c02644 | 2016-05-11 14:05:07 -0700 | [diff] [blame] | 28 | #include <wrdd.h> |
| 29 | #include "chip.h" |
Vladimir Serbinenko | 41f55b7 | 2014-10-31 09:10:16 +0100 | [diff] [blame] | 30 | |
Naresh G Solanki | 3c6377f | 2017-07-03 21:57:11 +0530 | [diff] [blame] | 31 | #define PMCS_DR 0xcc |
| 32 | #define PME_STS (1 << 15) |
| 33 | |
Kyösti Mälkki | 828e73e | 2016-07-28 17:26:39 +0300 | [diff] [blame] | 34 | #if IS_ENABLED(CONFIG_GENERATE_SMBIOS_TABLES) |
Vladimir Serbinenko | 41f55b7 | 2014-10-31 09:10:16 +0100 | [diff] [blame] | 35 | static int smbios_write_wifi(struct device *dev, int *handle, |
| 36 | unsigned long *current) |
| 37 | { |
| 38 | struct smbios_type_intel_wifi { |
| 39 | u8 type; |
| 40 | u8 length; |
| 41 | u16 handle; |
| 42 | u8 str; |
Konstantin Aladyshev | d0df1d7 | 2017-08-01 15:52:46 +0300 | [diff] [blame] | 43 | u8 eos[2]; |
Stefan Reinauer | 6a00113 | 2017-07-13 02:20:27 +0200 | [diff] [blame] | 44 | } __packed; |
Vladimir Serbinenko | 41f55b7 | 2014-10-31 09:10:16 +0100 | [diff] [blame] | 45 | |
Duncan Laurie | 5c02644 | 2016-05-11 14:05:07 -0700 | [diff] [blame] | 46 | struct smbios_type_intel_wifi *t = |
| 47 | (struct smbios_type_intel_wifi *)*current; |
Vladimir Serbinenko | 41f55b7 | 2014-10-31 09:10:16 +0100 | [diff] [blame] | 48 | int len = sizeof(struct smbios_type_intel_wifi); |
| 49 | |
| 50 | memset(t, 0, sizeof(struct smbios_type_intel_wifi)); |
| 51 | t->type = 0x85; |
| 52 | t->length = len - 2; |
| 53 | t->handle = *handle; |
Duncan Laurie | 5c02644 | 2016-05-11 14:05:07 -0700 | [diff] [blame] | 54 | /* |
| 55 | * Intel wifi driver expects this string to be in the table 0x85 |
| 56 | * with PCI IDs enumerated below. |
Vladimir Serbinenko | 41f55b7 | 2014-10-31 09:10:16 +0100 | [diff] [blame] | 57 | */ |
| 58 | t->str = smbios_add_string(t->eos, "KHOIHGIUCCHHII"); |
| 59 | |
| 60 | len = t->length + smbios_string_table_len(t->eos); |
| 61 | *current += len; |
| 62 | *handle += 1; |
| 63 | return len; |
| 64 | } |
Kyösti Mälkki | 828e73e | 2016-07-28 17:26:39 +0300 | [diff] [blame] | 65 | #endif |
Vladimir Serbinenko | 41f55b7 | 2014-10-31 09:10:16 +0100 | [diff] [blame] | 66 | |
Aaron Durbin | 6403167 | 2018-04-21 14:45:32 -0600 | [diff] [blame] | 67 | __weak |
Aaron Durbin | 2abbbf1 | 2017-05-04 22:26:44 -0500 | [diff] [blame] | 68 | int get_wifi_sar_limits(struct wifi_sar_limits *sar_limits) |
| 69 | { |
| 70 | return -1; |
| 71 | } |
| 72 | |
Duncan Laurie | 5c02644 | 2016-05-11 14:05:07 -0700 | [diff] [blame] | 73 | #if IS_ENABLED(CONFIG_HAVE_ACPI_TABLES) |
Robbie Zhang | 3dea69a | 2016-12-23 12:20:47 -0800 | [diff] [blame] | 74 | static void emit_sar_acpi_structures(void) |
| 75 | { |
| 76 | int i, j, package_size; |
| 77 | struct wifi_sar_limits sar_limits; |
| 78 | |
| 79 | /* Retrieve the sar limits data */ |
| 80 | if (get_wifi_sar_limits(&sar_limits) < 0) { |
| 81 | printk(BIOS_ERR, "Error: failed from getting SAR limits!\n"); |
| 82 | return; |
| 83 | } |
| 84 | |
| 85 | /* |
| 86 | * Name ("WRDS", Package () { |
| 87 | * Revision, |
| 88 | * Package () { |
| 89 | * Domain Type, // 0x7:WiFi |
| 90 | * WiFi SAR BIOS, // BIOS SAR Enable/disable |
| 91 | * SAR Table Set // Set#1 of SAR Table (10 bytes) |
| 92 | * } |
| 93 | * }) |
| 94 | */ |
| 95 | acpigen_write_name("WRDS"); |
| 96 | acpigen_write_package(2); |
| 97 | acpigen_write_dword(WRDS_REVISION); |
| 98 | /* Emit 'Domain Type' + 'WiFi SAR BIOS' + 10 bytes for Set#1 */ |
| 99 | package_size = 1 + 1 + BYTES_PER_SAR_LIMIT; |
| 100 | acpigen_write_package(package_size); |
| 101 | acpigen_write_dword(WRDS_DOMAIN_TYPE_WIFI); |
| 102 | acpigen_write_dword(CONFIG_SAR_ENABLE); |
| 103 | for (i = 0; i < BYTES_PER_SAR_LIMIT; i++) |
| 104 | acpigen_write_byte(sar_limits.sar_limit[0][i]); |
| 105 | acpigen_pop_len(); |
| 106 | acpigen_pop_len(); |
| 107 | |
| 108 | /* |
| 109 | * Name ("EWRD", Package () { |
| 110 | * Revision, |
| 111 | * Package () { |
| 112 | * Domain Type, // 0x7:WiFi |
| 113 | * Dynamic SAR Enable, // Dynamic SAR Enable/disable |
| 114 | * Extended SAR sets, // Number of optional SAR table sets |
| 115 | * SAR Table Set, // Set#2 of SAR Table (10 bytes) |
| 116 | * SAR Table Set, // Set#3 of SAR Table (10 bytes) |
| 117 | * SAR Table Set // Set#4 of SAR Table (10 bytes) |
| 118 | * } |
| 119 | * }) |
| 120 | */ |
| 121 | acpigen_write_name("EWRD"); |
| 122 | acpigen_write_package(2); |
| 123 | acpigen_write_dword(EWRD_REVISION); |
| 124 | /* |
| 125 | * Emit 'Domain Type' + "Dynamic SAR Enable' + 'Extended SAR sets' |
| 126 | * + number of bytes for Set#2 & 3 & 4 |
| 127 | */ |
| 128 | package_size = 1 + 1 + 1 + (NUM_SAR_LIMITS - 1) * BYTES_PER_SAR_LIMIT; |
| 129 | acpigen_write_package(package_size); |
| 130 | acpigen_write_dword(EWRD_DOMAIN_TYPE_WIFI); |
| 131 | acpigen_write_dword(CONFIG_DSAR_ENABLE); |
| 132 | acpigen_write_dword(CONFIG_DSAR_SET_NUM); |
| 133 | for (i = 1; i < NUM_SAR_LIMITS; i++) |
| 134 | for (j = 0; j < BYTES_PER_SAR_LIMIT; j++) |
| 135 | acpigen_write_byte(sar_limits.sar_limit[i][j]); |
| 136 | acpigen_pop_len(); |
| 137 | acpigen_pop_len(); |
| 138 | } |
| 139 | |
Duncan Laurie | 5c02644 | 2016-05-11 14:05:07 -0700 | [diff] [blame] | 140 | static void intel_wifi_fill_ssdt(struct device *dev) |
| 141 | { |
| 142 | struct drivers_intel_wifi_config *config = dev->chip_info; |
| 143 | const char *path = acpi_device_path(dev->bus->dev); |
| 144 | u32 address; |
| 145 | |
| 146 | if (!path) |
| 147 | return; |
| 148 | |
| 149 | /* Device */ |
| 150 | acpigen_write_scope(path); |
| 151 | acpigen_write_device(acpi_device_name(dev)); |
| 152 | acpigen_write_name_integer("_UID", 0); |
Patrick Rudolph | 6086b4e | 2017-06-07 09:39:28 +0200 | [diff] [blame] | 153 | if (dev->chip_ops) |
| 154 | acpigen_write_name_string("_DDN", dev->chip_ops->name); |
Duncan Laurie | 5c02644 | 2016-05-11 14:05:07 -0700 | [diff] [blame] | 155 | |
| 156 | /* Address */ |
| 157 | address = PCI_SLOT(dev->path.pci.devfn) & 0xffff; |
| 158 | address <<= 16; |
| 159 | address |= PCI_FUNC(dev->path.pci.devfn) & 0xffff; |
| 160 | acpigen_write_name_dword("_ADR", address); |
| 161 | |
| 162 | /* Wake capabilities */ |
| 163 | if (config && config->wake) |
| 164 | acpigen_write_PRW(config->wake, 3); |
| 165 | |
| 166 | /* Fill regulatory domain structure */ |
| 167 | if (IS_ENABLED(CONFIG_HAVE_REGULATORY_DOMAIN)) { |
| 168 | /* |
| 169 | * Name ("WRDD", Package () { |
| 170 | * WRDD_REVISION, // Revision |
| 171 | * Package () { |
| 172 | * WRDD_DOMAIN_TYPE_WIFI, // Domain Type, 7:WiFi |
| 173 | * wifi_regulatory_domain() // Country Identifier |
| 174 | * } |
| 175 | * }) |
| 176 | */ |
| 177 | acpigen_write_name("WRDD"); |
| 178 | acpigen_write_package(2); |
| 179 | acpigen_write_integer(WRDD_REVISION); |
| 180 | acpigen_write_package(2); |
| 181 | acpigen_write_dword(WRDD_DOMAIN_TYPE_WIFI); |
| 182 | acpigen_write_dword(wifi_regulatory_domain()); |
| 183 | acpigen_pop_len(); |
| 184 | acpigen_pop_len(); |
| 185 | } |
| 186 | |
Robbie Zhang | 3dea69a | 2016-12-23 12:20:47 -0800 | [diff] [blame] | 187 | /* Fill Wifi sar related ACPI structures */ |
| 188 | if (IS_ENABLED(CONFIG_USE_SAR)) |
| 189 | emit_sar_acpi_structures(); |
| 190 | |
Duncan Laurie | 5c02644 | 2016-05-11 14:05:07 -0700 | [diff] [blame] | 191 | acpigen_pop_len(); /* Device */ |
| 192 | acpigen_pop_len(); /* Scope */ |
| 193 | |
| 194 | printk(BIOS_INFO, "%s.%s: %s %s\n", path, acpi_device_name(dev), |
Patrick Rudolph | 6086b4e | 2017-06-07 09:39:28 +0200 | [diff] [blame] | 195 | dev->chip_ops ? dev->chip_ops->name : "", dev_path(dev)); |
Duncan Laurie | 5c02644 | 2016-05-11 14:05:07 -0700 | [diff] [blame] | 196 | } |
| 197 | |
Aaron Durbin | aa090cb | 2017-09-13 16:01:52 -0600 | [diff] [blame] | 198 | static const char *intel_wifi_acpi_name(const struct device *dev) |
Duncan Laurie | 5c02644 | 2016-05-11 14:05:07 -0700 | [diff] [blame] | 199 | { |
| 200 | return "WIFI"; |
| 201 | } |
| 202 | #endif |
| 203 | |
Naresh G Solanki | 3c6377f | 2017-07-03 21:57:11 +0530 | [diff] [blame] | 204 | static void wifi_pci_dev_init(struct device *dev) |
| 205 | { |
| 206 | pci_dev_init(dev); |
| 207 | |
| 208 | if (IS_ENABLED(CONFIG_ELOG)) { |
| 209 | uint32_t val; |
| 210 | val = pci_read_config16(dev, PMCS_DR); |
| 211 | if (val & PME_STS) |
| 212 | elog_add_event_wake(ELOG_WAKE_SOURCE_PME_WIFI, 0); |
| 213 | } |
| 214 | } |
| 215 | |
Vladimir Serbinenko | 41f55b7 | 2014-10-31 09:10:16 +0100 | [diff] [blame] | 216 | static struct pci_operations pci_ops = { |
| 217 | .set_subsystem = pci_dev_set_subsystem, |
| 218 | }; |
| 219 | |
| 220 | struct device_operations device_ops = { |
Duncan Laurie | 5c02644 | 2016-05-11 14:05:07 -0700 | [diff] [blame] | 221 | .read_resources = pci_dev_read_resources, |
| 222 | .set_resources = pci_dev_set_resources, |
| 223 | .enable_resources = pci_dev_enable_resources, |
Naresh G Solanki | 3c6377f | 2017-07-03 21:57:11 +0530 | [diff] [blame] | 224 | .init = wifi_pci_dev_init, |
Kyösti Mälkki | 828e73e | 2016-07-28 17:26:39 +0300 | [diff] [blame] | 225 | #if IS_ENABLED(CONFIG_GENERATE_SMBIOS_TABLES) |
Duncan Laurie | 5c02644 | 2016-05-11 14:05:07 -0700 | [diff] [blame] | 226 | .get_smbios_data = smbios_write_wifi, |
Kyösti Mälkki | 828e73e | 2016-07-28 17:26:39 +0300 | [diff] [blame] | 227 | #endif |
Duncan Laurie | 5c02644 | 2016-05-11 14:05:07 -0700 | [diff] [blame] | 228 | .ops_pci = &pci_ops, |
| 229 | #if IS_ENABLED(CONFIG_HAVE_ACPI_TABLES) |
| 230 | .acpi_name = &intel_wifi_acpi_name, |
| 231 | .acpi_fill_ssdt_generator = &intel_wifi_fill_ssdt, |
| 232 | #endif |
Vladimir Serbinenko | 41f55b7 | 2014-10-31 09:10:16 +0100 | [diff] [blame] | 233 | }; |
| 234 | |
Vladimir Serbinenko | 41f55b7 | 2014-10-31 09:10:16 +0100 | [diff] [blame] | 235 | static const unsigned short pci_device_ids[] = { |
Subrata Banik | f952983 | 2018-03-22 05:25:45 +0530 | [diff] [blame] | 236 | PCI_DEVICE_ID_1000_SERIES_WIFI, |
| 237 | PCI_DEVICE_ID_6005_SERIES_WIFI, |
| 238 | PCI_DEVICE_ID_6005_I_SERIES_WIFI, |
| 239 | PCI_DEVICE_ID_1030_SERIES_WIFI, |
| 240 | PCI_DEVICE_ID_6030_I_SERIES_WIFI, |
| 241 | PCI_DEVICE_ID_6030_SERIES_WIFI, |
| 242 | PCI_DEVICE_ID_6150_SERIES_WIFI, |
| 243 | PCI_DEVICE_ID_2030_SERIES_WIFI, |
| 244 | PCI_DEVICE_ID_2000_SERIES_WIFI, |
| 245 | PCI_DEVICE_ID_0135_SERIES_WIFI, |
| 246 | PCI_DEVICE_ID_0105_SERIES_WIFI, |
| 247 | PCI_DEVICE_ID_6035_SERIES_WIFI, |
| 248 | PCI_DEVICE_ID_5300_SERIES_WIFI, |
| 249 | PCI_DEVICE_ID_5100_SERIES_WIFI, |
| 250 | PCI_DEVICE_ID_6000_SERIES_WIFI, |
| 251 | PCI_DEVICE_ID_6000_I_SERIES_WIFI, |
| 252 | PCI_DEVICE_ID_5350_SERIES_WIFI, |
| 253 | PCI_DEVICE_ID_5150_SERIES_WIFI, |
| 254 | /* Wilkins Peak 2 */ |
| 255 | PCI_DEVICE_ID_WP_7260_SERIES_1_WIFI, |
| 256 | PCI_DEVICE_ID_WP_7260_SERIES_2_WIFI, |
| 257 | /* Stone Peak 2 */ |
| 258 | PCI_DEVICE_ID_SP_7265_SERIES_1_WIFI, |
| 259 | PCI_DEVICE_ID_SP_7265_SERIES_2_WIFI, |
| 260 | /* Jefferson Peak */ |
| 261 | PCI_DEVICE_ID_JP_9000_SERIES_1_WIFI, |
| 262 | PCI_DEVICE_ID_JP_9000_SERIES_2_WIFI, |
| 263 | PCI_DEVICE_ID_JP_9000_SERIES_3_WIFI, |
Furquan Shaikh | 39130a4 | 2018-05-30 19:57:14 -0700 | [diff] [blame^] | 264 | /* Thunder Peak 2 */ |
| 265 | PCI_DEVICE_ID_TP_9260_SERIES_WIFI, |
Subrata Banik | f952983 | 2018-03-22 05:25:45 +0530 | [diff] [blame] | 266 | /* Harrison Peak */ |
| 267 | PCI_DEVICE_ID_HrP_9560_SERIES_1_WIFI, |
| 268 | PCI_DEVICE_ID_HrP_9560_SERIES_2_WIFI, |
Duncan Laurie | 5c02644 | 2016-05-11 14:05:07 -0700 | [diff] [blame] | 269 | 0 |
| 270 | }; |
Vladimir Serbinenko | 41f55b7 | 2014-10-31 09:10:16 +0100 | [diff] [blame] | 271 | |
| 272 | static const struct pci_driver pch_intel_wifi __pci_driver = { |
| 273 | .ops = &device_ops, |
| 274 | .vendor = PCI_VENDOR_ID_INTEL, |
| 275 | .devices = pci_device_ids, |
| 276 | }; |
Duncan Laurie | 5c02644 | 2016-05-11 14:05:07 -0700 | [diff] [blame] | 277 | |
| 278 | static void intel_wifi_enable(struct device *dev) |
| 279 | { |
| 280 | dev->ops = &device_ops; |
| 281 | } |
| 282 | |
| 283 | struct chip_operations drivers_intel_wifi_ops = { |
| 284 | CHIP_NAME("Intel WiFi") |
| 285 | .enable_dev = &intel_wifi_enable |
| 286 | }; |