Furquan Shaikh | 2736c82 | 2020-10-27 19:46:11 -0700 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
| 2 | |
| 3 | #include <acpi/acpi_device.h> |
| 4 | #include <acpi/acpigen.h> |
Tim Wawrzynczak | d40a4c2 | 2021-02-25 13:14:49 -0700 | [diff] [blame] | 5 | #include <acpi/acpigen_pci.h> |
Furquan Shaikh | 2736c82 | 2020-10-27 19:46:11 -0700 | [diff] [blame] | 6 | #include <console/console.h> |
| 7 | #include <device/pci_ids.h> |
| 8 | #include <sar.h> |
| 9 | #include <wrdd.h> |
| 10 | |
| 11 | #include "chip.h" |
| 12 | #include "wifi_private.h" |
| 13 | |
| 14 | /* WRDS Spec Revision */ |
| 15 | #define WRDS_REVISION 0x0 |
| 16 | |
| 17 | /* EWRD Spec Revision */ |
| 18 | #define EWRD_REVISION 0x0 |
| 19 | |
| 20 | /* WRDS Domain type */ |
| 21 | #define WRDS_DOMAIN_TYPE_WIFI 0x7 |
| 22 | |
| 23 | /* EWRD Domain type */ |
| 24 | #define EWRD_DOMAIN_TYPE_WIFI 0x7 |
| 25 | |
| 26 | /* WGDS Domain type */ |
| 27 | #define WGDS_DOMAIN_TYPE_WIFI 0x7 |
| 28 | |
| 29 | /* |
| 30 | * WIFI ACPI NAME = "WF" + hex value of last 8 bits of dev_path_encode + '\0' |
| 31 | * The above representation returns unique and consistent name every time |
| 32 | * generate_wifi_acpi_name is invoked. The last 8 bits of dev_path_encode is |
| 33 | * chosen since it contains the bus address of the device. |
| 34 | */ |
| 35 | #define WIFI_ACPI_NAME_MAX_LEN 5 |
| 36 | |
| 37 | __weak int get_wifi_sar_limits(struct wifi_sar_limits *sar_limits) |
| 38 | { |
| 39 | return -1; |
| 40 | } |
| 41 | |
| 42 | static void emit_sar_acpi_structures(const struct device *dev) |
| 43 | { |
| 44 | int i, j, package_size; |
| 45 | struct wifi_sar_limits sar_limits; |
| 46 | struct wifi_sar_delta_table *wgds; |
| 47 | |
Furquan Shaikh | 43cc3c0 | 2020-11-09 08:07:10 -0800 | [diff] [blame] | 48 | /* |
| 49 | * If device type is PCI, ensure that the device has Intel vendor ID. CBFS SAR and SAR |
| 50 | * ACPI tables are currently used only by Intel WiFi devices. |
| 51 | */ |
| 52 | if (dev->path.type == DEVICE_PATH_PCI && dev->vendor != PCI_VENDOR_ID_INTEL) |
Furquan Shaikh | 2736c82 | 2020-10-27 19:46:11 -0700 | [diff] [blame] | 53 | return; |
| 54 | |
| 55 | /* Retrieve the sar limits data */ |
| 56 | if (get_wifi_sar_limits(&sar_limits) < 0) { |
Maulik V Vaghela | 0fd62f5 | 2020-11-11 12:44:28 +0530 | [diff] [blame] | 57 | printk(BIOS_DEBUG, "failed from getting SAR limits!\n"); |
Furquan Shaikh | 2736c82 | 2020-10-27 19:46:11 -0700 | [diff] [blame] | 58 | return; |
| 59 | } |
| 60 | |
| 61 | /* |
| 62 | * Name ("WRDS", Package () { |
| 63 | * Revision, |
| 64 | * Package () { |
| 65 | * Domain Type, // 0x7:WiFi |
| 66 | * WiFi SAR BIOS, // BIOS SAR Enable/disable |
| 67 | * SAR Table Set // Set#1 of SAR Table (10 bytes) |
| 68 | * } |
| 69 | * }) |
| 70 | */ |
| 71 | acpigen_write_name("WRDS"); |
| 72 | acpigen_write_package(2); |
| 73 | acpigen_write_dword(WRDS_REVISION); |
| 74 | /* Emit 'Domain Type' + 'WiFi SAR BIOS' + 10 bytes for Set#1 */ |
| 75 | package_size = 1 + 1 + BYTES_PER_SAR_LIMIT; |
| 76 | acpigen_write_package(package_size); |
| 77 | acpigen_write_dword(WRDS_DOMAIN_TYPE_WIFI); |
| 78 | acpigen_write_dword(CONFIG(SAR_ENABLE)); |
| 79 | for (i = 0; i < BYTES_PER_SAR_LIMIT; i++) |
| 80 | acpigen_write_byte(sar_limits.sar_limit[0][i]); |
| 81 | acpigen_pop_len(); |
| 82 | acpigen_pop_len(); |
| 83 | |
| 84 | /* |
| 85 | * Name ("EWRD", Package () { |
| 86 | * Revision, |
| 87 | * Package () { |
| 88 | * Domain Type, // 0x7:WiFi |
| 89 | * Dynamic SAR Enable, // Dynamic SAR Enable/disable |
| 90 | * Extended SAR sets, // Number of optional SAR table sets |
| 91 | * SAR Table Set, // Set#2 of SAR Table (10 bytes) |
| 92 | * SAR Table Set, // Set#3 of SAR Table (10 bytes) |
| 93 | * SAR Table Set // Set#4 of SAR Table (10 bytes) |
| 94 | * } |
| 95 | * }) |
| 96 | */ |
| 97 | acpigen_write_name("EWRD"); |
| 98 | acpigen_write_package(2); |
| 99 | acpigen_write_dword(EWRD_REVISION); |
| 100 | /* |
| 101 | * Emit 'Domain Type' + "Dynamic SAR Enable' + 'Extended SAR sets' |
| 102 | * + number of bytes for Set#2 & 3 & 4 |
| 103 | */ |
| 104 | package_size = 1 + 1 + 1 + (NUM_SAR_LIMITS - 1) * BYTES_PER_SAR_LIMIT; |
| 105 | acpigen_write_package(package_size); |
| 106 | acpigen_write_dword(EWRD_DOMAIN_TYPE_WIFI); |
| 107 | acpigen_write_dword(CONFIG(DSAR_ENABLE)); |
| 108 | acpigen_write_dword(CONFIG_DSAR_SET_NUM); |
| 109 | for (i = 1; i < NUM_SAR_LIMITS; i++) |
| 110 | for (j = 0; j < BYTES_PER_SAR_LIMIT; j++) |
| 111 | acpigen_write_byte(sar_limits.sar_limit[i][j]); |
| 112 | acpigen_pop_len(); |
| 113 | acpigen_pop_len(); |
| 114 | |
| 115 | if (!CONFIG(GEO_SAR_ENABLE)) |
| 116 | return; |
| 117 | |
| 118 | /* |
| 119 | * Name ("WGDS", Package() { |
| 120 | * Revision, |
| 121 | * Package() { |
| 122 | * DomainType, // 0x7:WiFi |
| 123 | * WgdsWiFiSarDeltaGroup1PowerMax1, // Group 1 FCC 2400 Max |
| 124 | * WgdsWiFiSarDeltaGroup1PowerChainA1, // Group 1 FCC 2400 A Offset |
| 125 | * WgdsWiFiSarDeltaGroup1PowerChainB1, // Group 1 FCC 2400 B Offset |
| 126 | * WgdsWiFiSarDeltaGroup1PowerMax2, // Group 1 FCC 5200 Max |
| 127 | * WgdsWiFiSarDeltaGroup1PowerChainA2, // Group 1 FCC 5200 A Offset |
| 128 | * WgdsWiFiSarDeltaGroup1PowerChainB2, // Group 1 FCC 5200 B Offset |
| 129 | * WgdsWiFiSarDeltaGroup2PowerMax1, // Group 2 EC Jap 2400 Max |
| 130 | * WgdsWiFiSarDeltaGroup2PowerChainA1, // Group 2 EC Jap 2400 A Offset |
| 131 | * WgdsWiFiSarDeltaGroup2PowerChainB1, // Group 2 EC Jap 2400 B Offset |
| 132 | * WgdsWiFiSarDeltaGroup2PowerMax2, // Group 2 EC Jap 5200 Max |
| 133 | * WgdsWiFiSarDeltaGroup2PowerChainA2, // Group 2 EC Jap 5200 A Offset |
| 134 | * WgdsWiFiSarDeltaGroup2PowerChainB2, // Group 2 EC Jap 5200 B Offset |
| 135 | * WgdsWiFiSarDeltaGroup3PowerMax1, // Group 3 ROW 2400 Max |
| 136 | * WgdsWiFiSarDeltaGroup3PowerChainA1, // Group 3 ROW 2400 A Offset |
| 137 | * WgdsWiFiSarDeltaGroup3PowerChainB1, // Group 3 ROW 2400 B Offset |
| 138 | * WgdsWiFiSarDeltaGroup3PowerMax2, // Group 3 ROW 5200 Max |
| 139 | * WgdsWiFiSarDeltaGroup3PowerChainA2, // Group 3 ROW 5200 A Offset |
| 140 | * WgdsWiFiSarDeltaGroup3PowerChainB2, // Group 3 ROW 5200 B Offset |
| 141 | * } |
| 142 | * }) |
| 143 | */ |
| 144 | |
| 145 | wgds = &sar_limits.wgds; |
| 146 | acpigen_write_name("WGDS"); |
| 147 | acpigen_write_package(2); |
| 148 | acpigen_write_dword(wgds->version); |
| 149 | /* Emit 'Domain Type' + |
| 150 | * Group specific delta of power (6 bytes * NUM_WGDS_SAR_GROUPS) |
| 151 | */ |
| 152 | package_size = sizeof(sar_limits.wgds.group) + 1; |
| 153 | acpigen_write_package(package_size); |
| 154 | acpigen_write_dword(WGDS_DOMAIN_TYPE_WIFI); |
| 155 | for (i = 0; i < SAR_NUM_WGDS_GROUPS; i++) { |
| 156 | acpigen_write_byte(wgds->group[i].power_max_2400mhz); |
| 157 | acpigen_write_byte(wgds->group[i].power_chain_a_2400mhz); |
| 158 | acpigen_write_byte(wgds->group[i].power_chain_b_2400mhz); |
| 159 | acpigen_write_byte(wgds->group[i].power_max_5200mhz); |
| 160 | acpigen_write_byte(wgds->group[i].power_chain_a_5200mhz); |
| 161 | acpigen_write_byte(wgds->group[i].power_chain_b_5200mhz); |
| 162 | } |
| 163 | |
| 164 | acpigen_pop_len(); |
| 165 | acpigen_pop_len(); |
| 166 | } |
| 167 | |
Furquan Shaikh | 6017abb | 2020-10-27 17:41:09 -0700 | [diff] [blame] | 168 | static void wifi_ssdt_write_device(const struct device *dev, const char *path) |
Furquan Shaikh | 2736c82 | 2020-10-27 19:46:11 -0700 | [diff] [blame] | 169 | { |
Furquan Shaikh | 2736c82 | 2020-10-27 19:46:11 -0700 | [diff] [blame] | 170 | /* Device */ |
Furquan Shaikh | 6017abb | 2020-10-27 17:41:09 -0700 | [diff] [blame] | 171 | acpigen_write_device(path); |
Furquan Shaikh | 2736c82 | 2020-10-27 19:46:11 -0700 | [diff] [blame] | 172 | acpi_device_write_uid(dev); |
| 173 | |
| 174 | if (dev->chip_ops) |
| 175 | acpigen_write_name_string("_DDN", dev->chip_ops->name); |
| 176 | |
| 177 | /* Address */ |
| 178 | acpigen_write_ADR_pci_device(dev); |
| 179 | |
Furquan Shaikh | 6017abb | 2020-10-27 17:41:09 -0700 | [diff] [blame] | 180 | acpigen_pop_len(); /* Device */ |
| 181 | } |
| 182 | |
| 183 | static void wifi_ssdt_write_properties(const struct device *dev, const char *scope) |
| 184 | { |
| 185 | const struct drivers_wifi_generic_config *config = dev->chip_info; |
| 186 | |
| 187 | /* Scope */ |
| 188 | acpigen_write_scope(scope); |
| 189 | |
Furquan Shaikh | 2736c82 | 2020-10-27 19:46:11 -0700 | [diff] [blame] | 190 | /* Wake capabilities */ |
| 191 | if (config) |
| 192 | acpigen_write_PRW(config->wake, ACPI_S3); |
| 193 | |
| 194 | /* Fill regulatory domain structure */ |
| 195 | if (CONFIG(HAVE_REGULATORY_DOMAIN)) { |
| 196 | /* |
| 197 | * Name ("WRDD", Package () { |
| 198 | * WRDD_REVISION, // Revision |
| 199 | * Package () { |
| 200 | * WRDD_DOMAIN_TYPE_WIFI, // Domain Type, 7:WiFi |
| 201 | * wifi_regulatory_domain() // Country Identifier |
| 202 | * } |
| 203 | * }) |
| 204 | */ |
| 205 | acpigen_write_name("WRDD"); |
| 206 | acpigen_write_package(2); |
| 207 | acpigen_write_integer(WRDD_REVISION); |
| 208 | acpigen_write_package(2); |
| 209 | acpigen_write_dword(WRDD_DOMAIN_TYPE_WIFI); |
| 210 | acpigen_write_dword(wifi_regulatory_domain()); |
| 211 | acpigen_pop_len(); |
| 212 | acpigen_pop_len(); |
| 213 | } |
| 214 | |
| 215 | /* Fill Wifi sar related ACPI structures */ |
| 216 | if (CONFIG(USE_SAR)) |
| 217 | emit_sar_acpi_structures(dev); |
| 218 | |
Furquan Shaikh | 2736c82 | 2020-10-27 19:46:11 -0700 | [diff] [blame] | 219 | acpigen_pop_len(); /* Scope */ |
| 220 | |
Furquan Shaikh | 6017abb | 2020-10-27 17:41:09 -0700 | [diff] [blame] | 221 | printk(BIOS_INFO, "%s: %s %s\n", scope, dev->chip_ops ? dev->chip_ops->name : "", |
| 222 | dev_path(dev)); |
| 223 | } |
| 224 | |
Furquan Shaikh | d436750 | 2020-10-27 18:00:46 -0700 | [diff] [blame] | 225 | void wifi_pcie_fill_ssdt(const struct device *dev) |
Furquan Shaikh | 6017abb | 2020-10-27 17:41:09 -0700 | [diff] [blame] | 226 | { |
| 227 | const char *path; |
| 228 | |
Furquan Shaikh | 6017abb | 2020-10-27 17:41:09 -0700 | [diff] [blame] | 229 | path = acpi_device_path(dev); |
| 230 | if (!path) |
| 231 | return; |
| 232 | |
| 233 | wifi_ssdt_write_device(dev, path); |
| 234 | wifi_ssdt_write_properties(dev, path); |
Furquan Shaikh | 2736c82 | 2020-10-27 19:46:11 -0700 | [diff] [blame] | 235 | } |
| 236 | |
Furquan Shaikh | d436750 | 2020-10-27 18:00:46 -0700 | [diff] [blame] | 237 | const char *wifi_pcie_acpi_name(const struct device *dev) |
Furquan Shaikh | 2736c82 | 2020-10-27 19:46:11 -0700 | [diff] [blame] | 238 | { |
| 239 | static char wifi_acpi_name[WIFI_ACPI_NAME_MAX_LEN]; |
| 240 | |
| 241 | /* ACPI 6.3, ASL 20.2.2: (Name Objects Encoding). */ |
| 242 | snprintf(wifi_acpi_name, sizeof(wifi_acpi_name), "WF%02X", |
| 243 | (dev_path_encode(dev) & 0xff)); |
| 244 | return wifi_acpi_name; |
| 245 | } |
Furquan Shaikh | d436750 | 2020-10-27 18:00:46 -0700 | [diff] [blame] | 246 | |
| 247 | void wifi_cnvi_fill_ssdt(const struct device *dev) |
| 248 | { |
| 249 | const char *path; |
| 250 | |
Furquan Shaikh | d436750 | 2020-10-27 18:00:46 -0700 | [diff] [blame] | 251 | path = acpi_device_path(dev->bus->dev); |
| 252 | if (!path) |
| 253 | return; |
| 254 | |
| 255 | wifi_ssdt_write_properties(dev, path); |
| 256 | } |