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 | |
| 47 | /* CBFS SAR and SAR ACPI tables are currently used only by Intel WiFi devices. */ |
| 48 | if (dev->vendor != PCI_VENDOR_ID_INTEL) |
| 49 | return; |
| 50 | |
| 51 | /* Retrieve the sar limits data */ |
| 52 | if (get_wifi_sar_limits(&sar_limits) < 0) { |
| 53 | printk(BIOS_ERR, "Error: failed from getting SAR limits!\n"); |
| 54 | return; |
| 55 | } |
| 56 | |
| 57 | /* |
| 58 | * Name ("WRDS", Package () { |
| 59 | * Revision, |
| 60 | * Package () { |
| 61 | * Domain Type, // 0x7:WiFi |
| 62 | * WiFi SAR BIOS, // BIOS SAR Enable/disable |
| 63 | * SAR Table Set // Set#1 of SAR Table (10 bytes) |
| 64 | * } |
| 65 | * }) |
| 66 | */ |
| 67 | acpigen_write_name("WRDS"); |
| 68 | acpigen_write_package(2); |
| 69 | acpigen_write_dword(WRDS_REVISION); |
| 70 | /* Emit 'Domain Type' + 'WiFi SAR BIOS' + 10 bytes for Set#1 */ |
| 71 | package_size = 1 + 1 + BYTES_PER_SAR_LIMIT; |
| 72 | acpigen_write_package(package_size); |
| 73 | acpigen_write_dword(WRDS_DOMAIN_TYPE_WIFI); |
| 74 | acpigen_write_dword(CONFIG(SAR_ENABLE)); |
| 75 | for (i = 0; i < BYTES_PER_SAR_LIMIT; i++) |
| 76 | acpigen_write_byte(sar_limits.sar_limit[0][i]); |
| 77 | acpigen_pop_len(); |
| 78 | acpigen_pop_len(); |
| 79 | |
| 80 | /* |
| 81 | * Name ("EWRD", Package () { |
| 82 | * Revision, |
| 83 | * Package () { |
| 84 | * Domain Type, // 0x7:WiFi |
| 85 | * Dynamic SAR Enable, // Dynamic SAR Enable/disable |
| 86 | * Extended SAR sets, // Number of optional SAR table sets |
| 87 | * SAR Table Set, // Set#2 of SAR Table (10 bytes) |
| 88 | * SAR Table Set, // Set#3 of SAR Table (10 bytes) |
| 89 | * SAR Table Set // Set#4 of SAR Table (10 bytes) |
| 90 | * } |
| 91 | * }) |
| 92 | */ |
| 93 | acpigen_write_name("EWRD"); |
| 94 | acpigen_write_package(2); |
| 95 | acpigen_write_dword(EWRD_REVISION); |
| 96 | /* |
| 97 | * Emit 'Domain Type' + "Dynamic SAR Enable' + 'Extended SAR sets' |
| 98 | * + number of bytes for Set#2 & 3 & 4 |
| 99 | */ |
| 100 | package_size = 1 + 1 + 1 + (NUM_SAR_LIMITS - 1) * BYTES_PER_SAR_LIMIT; |
| 101 | acpigen_write_package(package_size); |
| 102 | acpigen_write_dword(EWRD_DOMAIN_TYPE_WIFI); |
| 103 | acpigen_write_dword(CONFIG(DSAR_ENABLE)); |
| 104 | acpigen_write_dword(CONFIG_DSAR_SET_NUM); |
| 105 | for (i = 1; i < NUM_SAR_LIMITS; i++) |
| 106 | for (j = 0; j < BYTES_PER_SAR_LIMIT; j++) |
| 107 | acpigen_write_byte(sar_limits.sar_limit[i][j]); |
| 108 | acpigen_pop_len(); |
| 109 | acpigen_pop_len(); |
| 110 | |
| 111 | if (!CONFIG(GEO_SAR_ENABLE)) |
| 112 | return; |
| 113 | |
| 114 | /* |
| 115 | * Name ("WGDS", Package() { |
| 116 | * Revision, |
| 117 | * Package() { |
| 118 | * DomainType, // 0x7:WiFi |
| 119 | * WgdsWiFiSarDeltaGroup1PowerMax1, // Group 1 FCC 2400 Max |
| 120 | * WgdsWiFiSarDeltaGroup1PowerChainA1, // Group 1 FCC 2400 A Offset |
| 121 | * WgdsWiFiSarDeltaGroup1PowerChainB1, // Group 1 FCC 2400 B Offset |
| 122 | * WgdsWiFiSarDeltaGroup1PowerMax2, // Group 1 FCC 5200 Max |
| 123 | * WgdsWiFiSarDeltaGroup1PowerChainA2, // Group 1 FCC 5200 A Offset |
| 124 | * WgdsWiFiSarDeltaGroup1PowerChainB2, // Group 1 FCC 5200 B Offset |
| 125 | * WgdsWiFiSarDeltaGroup2PowerMax1, // Group 2 EC Jap 2400 Max |
| 126 | * WgdsWiFiSarDeltaGroup2PowerChainA1, // Group 2 EC Jap 2400 A Offset |
| 127 | * WgdsWiFiSarDeltaGroup2PowerChainB1, // Group 2 EC Jap 2400 B Offset |
| 128 | * WgdsWiFiSarDeltaGroup2PowerMax2, // Group 2 EC Jap 5200 Max |
| 129 | * WgdsWiFiSarDeltaGroup2PowerChainA2, // Group 2 EC Jap 5200 A Offset |
| 130 | * WgdsWiFiSarDeltaGroup2PowerChainB2, // Group 2 EC Jap 5200 B Offset |
| 131 | * WgdsWiFiSarDeltaGroup3PowerMax1, // Group 3 ROW 2400 Max |
| 132 | * WgdsWiFiSarDeltaGroup3PowerChainA1, // Group 3 ROW 2400 A Offset |
| 133 | * WgdsWiFiSarDeltaGroup3PowerChainB1, // Group 3 ROW 2400 B Offset |
| 134 | * WgdsWiFiSarDeltaGroup3PowerMax2, // Group 3 ROW 5200 Max |
| 135 | * WgdsWiFiSarDeltaGroup3PowerChainA2, // Group 3 ROW 5200 A Offset |
| 136 | * WgdsWiFiSarDeltaGroup3PowerChainB2, // Group 3 ROW 5200 B Offset |
| 137 | * } |
| 138 | * }) |
| 139 | */ |
| 140 | |
| 141 | wgds = &sar_limits.wgds; |
| 142 | acpigen_write_name("WGDS"); |
| 143 | acpigen_write_package(2); |
| 144 | acpigen_write_dword(wgds->version); |
| 145 | /* Emit 'Domain Type' + |
| 146 | * Group specific delta of power (6 bytes * NUM_WGDS_SAR_GROUPS) |
| 147 | */ |
| 148 | package_size = sizeof(sar_limits.wgds.group) + 1; |
| 149 | acpigen_write_package(package_size); |
| 150 | acpigen_write_dword(WGDS_DOMAIN_TYPE_WIFI); |
| 151 | for (i = 0; i < SAR_NUM_WGDS_GROUPS; i++) { |
| 152 | acpigen_write_byte(wgds->group[i].power_max_2400mhz); |
| 153 | acpigen_write_byte(wgds->group[i].power_chain_a_2400mhz); |
| 154 | acpigen_write_byte(wgds->group[i].power_chain_b_2400mhz); |
| 155 | acpigen_write_byte(wgds->group[i].power_max_5200mhz); |
| 156 | acpigen_write_byte(wgds->group[i].power_chain_a_5200mhz); |
| 157 | acpigen_write_byte(wgds->group[i].power_chain_b_5200mhz); |
| 158 | } |
| 159 | |
| 160 | acpigen_pop_len(); |
| 161 | acpigen_pop_len(); |
| 162 | } |
| 163 | |
Furquan Shaikh | 6017abb | 2020-10-27 17:41:09 -0700 | [diff] [blame^] | 164 | 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] | 165 | { |
Furquan Shaikh | 2736c82 | 2020-10-27 19:46:11 -0700 | [diff] [blame] | 166 | /* Device */ |
Furquan Shaikh | 6017abb | 2020-10-27 17:41:09 -0700 | [diff] [blame^] | 167 | acpigen_write_device(path); |
Furquan Shaikh | 2736c82 | 2020-10-27 19:46:11 -0700 | [diff] [blame] | 168 | acpi_device_write_uid(dev); |
| 169 | |
| 170 | if (dev->chip_ops) |
| 171 | acpigen_write_name_string("_DDN", dev->chip_ops->name); |
| 172 | |
| 173 | /* Address */ |
| 174 | acpigen_write_ADR_pci_device(dev); |
| 175 | |
Furquan Shaikh | 6017abb | 2020-10-27 17:41:09 -0700 | [diff] [blame^] | 176 | acpigen_pop_len(); /* Device */ |
| 177 | } |
| 178 | |
| 179 | static void wifi_ssdt_write_properties(const struct device *dev, const char *scope) |
| 180 | { |
| 181 | const struct drivers_wifi_generic_config *config = dev->chip_info; |
| 182 | |
| 183 | /* Scope */ |
| 184 | acpigen_write_scope(scope); |
| 185 | |
Furquan Shaikh | 2736c82 | 2020-10-27 19:46:11 -0700 | [diff] [blame] | 186 | /* Wake capabilities */ |
| 187 | if (config) |
| 188 | acpigen_write_PRW(config->wake, ACPI_S3); |
| 189 | |
| 190 | /* Fill regulatory domain structure */ |
| 191 | if (CONFIG(HAVE_REGULATORY_DOMAIN)) { |
| 192 | /* |
| 193 | * Name ("WRDD", Package () { |
| 194 | * WRDD_REVISION, // Revision |
| 195 | * Package () { |
| 196 | * WRDD_DOMAIN_TYPE_WIFI, // Domain Type, 7:WiFi |
| 197 | * wifi_regulatory_domain() // Country Identifier |
| 198 | * } |
| 199 | * }) |
| 200 | */ |
| 201 | acpigen_write_name("WRDD"); |
| 202 | acpigen_write_package(2); |
| 203 | acpigen_write_integer(WRDD_REVISION); |
| 204 | acpigen_write_package(2); |
| 205 | acpigen_write_dword(WRDD_DOMAIN_TYPE_WIFI); |
| 206 | acpigen_write_dword(wifi_regulatory_domain()); |
| 207 | acpigen_pop_len(); |
| 208 | acpigen_pop_len(); |
| 209 | } |
| 210 | |
| 211 | /* Fill Wifi sar related ACPI structures */ |
| 212 | if (CONFIG(USE_SAR)) |
| 213 | emit_sar_acpi_structures(dev); |
| 214 | |
Furquan Shaikh | 2736c82 | 2020-10-27 19:46:11 -0700 | [diff] [blame] | 215 | acpigen_pop_len(); /* Scope */ |
| 216 | |
Furquan Shaikh | 6017abb | 2020-10-27 17:41:09 -0700 | [diff] [blame^] | 217 | printk(BIOS_INFO, "%s: %s %s\n", scope, dev->chip_ops ? dev->chip_ops->name : "", |
| 218 | dev_path(dev)); |
| 219 | } |
| 220 | |
| 221 | void wifi_generic_fill_ssdt(const struct device *dev) |
| 222 | { |
| 223 | const char *path; |
| 224 | |
| 225 | if (!dev->enabled) |
| 226 | return; |
| 227 | |
| 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 | |
| 236 | const char *wifi_generic_acpi_name(const struct device *dev) |
| 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 | } |