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 | 2abbbf1 | 2017-05-04 22:26:44 -0500 | [diff] [blame] | 67 | __attribute__((weak)) |
| 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 | |
| 198 | static const char *intel_wifi_acpi_name(struct device *dev) |
| 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[] = { |
| 236 | 0x0084, 0x0085, 0x0089, 0x008b, 0x008e, 0x0090, |
| 237 | 0x0886, 0x0888, 0x0891, 0x0893, 0x0895, 0x088f, |
| 238 | 0x4236, 0x4237, 0x4238, 0x4239, 0x423b, 0x423d, |
Duncan Laurie | 5c02644 | 2016-05-11 14:05:07 -0700 | [diff] [blame] | 239 | 0x08b1, 0x08b2, /* Wilkins Peak 2 */ |
| 240 | 0x095a, 0x095b, /* Stone Peak 2 */ |
| 241 | 0 |
| 242 | }; |
Vladimir Serbinenko | 41f55b7 | 2014-10-31 09:10:16 +0100 | [diff] [blame] | 243 | |
| 244 | static const struct pci_driver pch_intel_wifi __pci_driver = { |
| 245 | .ops = &device_ops, |
| 246 | .vendor = PCI_VENDOR_ID_INTEL, |
| 247 | .devices = pci_device_ids, |
| 248 | }; |
Duncan Laurie | 5c02644 | 2016-05-11 14:05:07 -0700 | [diff] [blame] | 249 | |
| 250 | static void intel_wifi_enable(struct device *dev) |
| 251 | { |
| 252 | dev->ops = &device_ops; |
| 253 | } |
| 254 | |
| 255 | struct chip_operations drivers_intel_wifi_ops = { |
| 256 | CHIP_NAME("Intel WiFi") |
| 257 | .enable_dev = &intel_wifi_enable |
| 258 | }; |