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