blob: 3cc1c63aa9e86853a4a134bec6383165616f6e72 [file] [log] [blame]
Furquan Shaikh2736c822020-10-27 19:46:11 -07001/* SPDX-License-Identifier: GPL-2.0-only */
2
3#include <acpi/acpi_device.h>
4#include <acpi/acpigen.h>
Tim Wawrzynczakd40a4c22021-02-25 13:14:49 -07005#include <acpi/acpigen_pci.h>
Furquan Shaikh2736c822020-10-27 19:46:11 -07006#include <console/console.h>
7#include <device/pci_ids.h>
8#include <sar.h>
Sugnan Prabhu Sfcb4f2d2021-07-30 20:12:22 +05309#include <stdlib.h>
Furquan Shaikh2736c822020-10-27 19:46:11 -070010#include <wrdd.h>
11
12#include "chip.h"
13#include "wifi_private.h"
14
Sugnan Prabhu Sfcb4f2d2021-07-30 20:12:22 +053015/* WIFI Domain type */
16#define DOMAIN_TYPE_WIFI 0x7
Furquan Shaikh2736c822020-10-27 19:46:11 -070017
18/*
19 * WIFI ACPI NAME = "WF" + hex value of last 8 bits of dev_path_encode + '\0'
20 * The above representation returns unique and consistent name every time
21 * generate_wifi_acpi_name is invoked. The last 8 bits of dev_path_encode is
22 * chosen since it contains the bus address of the device.
23 */
24#define WIFI_ACPI_NAME_MAX_LEN 5
25
Sugnan Prabhu Sd70f4812021-08-25 17:36:44 +053026/* Unique ID for the WIFI _DSM */
27#define ACPI_DSM_OEM_WIFI_UUID "F21202BF-8F78-4DC6-A5B3-1F738E285ADE"
28
Sugnan Prabhu Sfcb4f2d2021-07-30 20:12:22 +053029__weak int get_wifi_sar_limits(union wifi_sar_limits *sar_limits)
Furquan Shaikh2736c822020-10-27 19:46:11 -070030{
31 return -1;
32}
33
Sugnan Prabhu Sd70f4812021-08-25 17:36:44 +053034/*
35 * Generate ACPI AML code for _DSM method.
36 * This function takes as input uuid for the device, set of callbacks and
37 * argument to pass into the callbacks. Callbacks should ensure that Local0 and
38 * Local1 are left untouched. Use of Local2-Local7 is permitted in callbacks.
39 */
40void wifi_emit_dsm(struct dsm_profile *dsm);
41
42/*
43 * Function 1: Allow PC OEMs to set ETSI 5.8GHz SRD in Passive/Disabled ESTI SRD
44 * Channels: 149, 153, 157, 161, 165
45 * 0 - ETSI 5.8GHz SRD active scan
46 * 1 - ETSI 5.8GHz SRD passive scan
47 * 2 - ETSI 5.8GHz SRD disabled
48 */
49static void wifi_dsm_srd_active_channels(void *args)
50{
51 struct dsm_profile *dsm_config = (struct dsm_profile *)args;
52
53 acpigen_write_return_integer(dsm_config->disable_active_sdr_channels);
54}
55
56/*
57 * Function 2 : Supported Indonesia 5.15-5.35 GHz Band
58 * 0 - Set 5.115-5.35GHz to Disable in Indonesia
59 * 1 - Set 5.115-5.35GHz to Enable (Passive) in Indonesia
60 * 2 - Reserved
61 */
62static void wifi_dsm_indonasia_5Ghz_band_enable(void *args)
63{
64 struct dsm_profile *dsm_config = (struct dsm_profile *)args;
65
66 acpigen_write_return_integer(dsm_config->support_indonesia_5g_band);
67}
68
69/*
70 * Function 3: Support Wi-Fi 6 11ax Rev 2 new channels on 6-7 GHz.
71 * Bit 0:
72 * 0 - No override; use device settings 0
73 * 1 - Force disable all countries that are not defined in the following bits
74 *
75 * Bit 1:
76 * 0 No override; USA 6GHz disable 0
77 * 1 6GHz allowed in the USA (enabled only if the device is certified to the USA)
78 */
79static void wifi_dsm_supported_ultra_high_band(void *args)
80{
81 struct dsm_profile *dsm_config = (struct dsm_profile *)args;
82
83 acpigen_write_return_integer(dsm_config->support_ultra_high_band);
84}
85
86/*
87 * Function 4: Regulatory Special Configurations Enablements
88 */
89static void wifi_dsm_regulatory_configurations(void *args)
90{
91 struct dsm_profile *dsm_config = (struct dsm_profile *)args;
92
93 acpigen_write_return_integer(dsm_config->regulatory_configurations);
94}
95
96/*
97 * Function 5: M.2 UART Interface Configuration
98 */
99static void wifi_dsm_uart_configurations(void *args)
100{
101 struct dsm_profile *dsm_config = (struct dsm_profile *)args;
102
103 acpigen_write_return_integer(dsm_config->uart_configurations);
104}
105
106/*
107 * Function 6: Control Enablement 11ax on certificated modules
108 * Bit 0 - Apply changes to country Ukraine. 11Ax Setting within module certification
109 * 0 - None. Work with Wi-Fi FW/OTP definitions [Default]
110 * 1 - Apply changes.
111 *
112 * Bit 1 - 11Ax Mode. Effective only if Bit 0 set to 1
113 * 0 - Disable 11Ax on country Ukraine [Default]
114 * 1 - Enable 11Ax on country Ukraine
115 *
116 * Bit 2 - Apply changes to country Russia. 11Ax Setting within module certification
117 * 0 - None. Work with Wi-Fi FW/OTP definitions [Default]
118 * 1 - Apply changes.
119 *
120 * Bit 3 - 11Ax Mode. Effective only if Bit 2 set to 1
121 * 0 - Disable 11Ax on country Russia [Default]
122 * 1 - Enable 11Ax on country Russia
123 *
124 * Bit 31:04 - Reserved
125 *
126 * Note: Assumed Russia Work with Wi-Fi FW/OTP definitions
127 */
128static void wifi_dsm_ukrane_russia_11ax_enable(void *args)
129{
130 struct dsm_profile *dsm_config = (struct dsm_profile *)args;
131
132 acpigen_write_return_integer(dsm_config->enablement_11ax);
133}
134
135/*
136 * Function 7: Control Enablement UNII-4 over certificate modules
137 */
138static void wifi_dsm_unii4_control_enable(void *args)
139{
140 struct dsm_profile *dsm_config = (struct dsm_profile *)args;
141
142 acpigen_write_return_integer(dsm_config->unii_4);
143}
144
145static void (*wifi_dsm_callbacks[])(void *) = {
146 NULL, /* Function 0 */
147 wifi_dsm_srd_active_channels, /* Function 1 */
148 wifi_dsm_indonasia_5Ghz_band_enable, /* Function 2 */
149 wifi_dsm_supported_ultra_high_band, /* Function 3 */
150 wifi_dsm_regulatory_configurations, /* Function 4 */
151 wifi_dsm_uart_configurations, /* Function 5 */
152 wifi_dsm_ukrane_russia_11ax_enable, /* Function 6 */
153 wifi_dsm_unii4_control_enable, /* Function 7 */
154};
155
156void wifi_emit_dsm(struct dsm_profile *dsm)
157{
158 int i;
159 size_t count = ARRAY_SIZE(wifi_dsm_callbacks);
160
161 if (dsm == NULL)
162 return;
163
164 for (i = 1; i < count; i++)
165 if (!(dsm->supported_functions & (1 << i)))
166 wifi_dsm_callbacks[i] = NULL;
167
168 acpigen_write_dsm(ACPI_DSM_OEM_WIFI_UUID, wifi_dsm_callbacks, count, dsm);
169}
170
Sugnan Prabhu Sfcb4f2d2021-07-30 20:12:22 +0530171static const uint8_t *sar_fetch_set(const struct sar_profile *sar, size_t set_num)
Furquan Shaikh2736c822020-10-27 19:46:11 -0700172{
Sugnan Prabhu Sfcb4f2d2021-07-30 20:12:22 +0530173 const uint8_t *sar_table = &sar->sar_table[0];
Furquan Shaikh2736c822020-10-27 19:46:11 -0700174
Sugnan Prabhu Sfcb4f2d2021-07-30 20:12:22 +0530175 return sar_table + (sar->chains_count * sar->subbands_count * set_num);
176}
Furquan Shaikh2736c822020-10-27 19:46:11 -0700177
Sugnan Prabhu Sfcb4f2d2021-07-30 20:12:22 +0530178static const uint8_t *wgds_fetch_set(struct geo_profile *wgds, size_t set_num)
179{
180 const uint8_t *wgds_table = &wgds->wgds_table[0];
181
182 return wgds_table + (wgds->bands_count * set_num);
183}
184
Sugnan Prabhu Sd1fc8322021-08-31 07:11:35 +0530185static const uint8_t *ppag_fetch_set(struct gain_profile *ppag, size_t set_num)
186{
187 const uint8_t *ppag_table = &ppag->ppag_table[0];
188
189 return ppag_table + (ppag->bands_count * set_num);
190}
191
Sugnan Prabhu Sfcb4f2d2021-07-30 20:12:22 +0530192static void sar_emit_wrds(const struct sar_profile *sar)
193{
194 int i;
195 size_t package_size, table_size;
196 const uint8_t *set;
197
198 if (sar == NULL)
Furquan Shaikh2736c822020-10-27 19:46:11 -0700199 return;
Furquan Shaikh2736c822020-10-27 19:46:11 -0700200
201 /*
202 * Name ("WRDS", Package () {
203 * Revision,
204 * Package () {
205 * Domain Type, // 0x7:WiFi
206 * WiFi SAR BIOS, // BIOS SAR Enable/disable
Sugnan Prabhu Sfcb4f2d2021-07-30 20:12:22 +0530207 * SAR Table Set // Set#1 of SAR Table
Furquan Shaikh2736c822020-10-27 19:46:11 -0700208 * }
209 * })
210 */
Sugnan Prabhu Sfcb4f2d2021-07-30 20:12:22 +0530211 if (sar->revision > MAX_SAR_REVISION) {
212 printk(BIOS_ERR, "ERROR: Invalid SAR table revision: %d\n", sar->revision);
213 return;
214 }
215
Furquan Shaikh2736c822020-10-27 19:46:11 -0700216 acpigen_write_name("WRDS");
217 acpigen_write_package(2);
Sugnan Prabhu Sfcb4f2d2021-07-30 20:12:22 +0530218 acpigen_write_dword(sar->revision);
219
220 table_size = sar->chains_count * sar->subbands_count;
221 /* Emit 'Domain Type' + 'WiFi SAR Enable' + Set#1 */
222 package_size = 1 + 1 + table_size;
Furquan Shaikh2736c822020-10-27 19:46:11 -0700223 acpigen_write_package(package_size);
Sugnan Prabhu Sfcb4f2d2021-07-30 20:12:22 +0530224 acpigen_write_dword(DOMAIN_TYPE_WIFI);
225 acpigen_write_dword(1);
226
227 set = sar_fetch_set(sar, 0);
228 for (i = 0; i < table_size; i++)
229 acpigen_write_byte(set[i]);
230
231 acpigen_write_package_end();
232 acpigen_write_package_end();
233}
234
235static void sar_emit_ewrd(const struct sar_profile *sar)
236{
237 int i;
238 size_t package_size, set_num, table_size;
239 const uint8_t *set;
240
241 if (sar == NULL)
242 return;
Furquan Shaikh2736c822020-10-27 19:46:11 -0700243
244 /*
245 * Name ("EWRD", Package () {
246 * Revision,
247 * Package () {
248 * Domain Type, // 0x7:WiFi
249 * Dynamic SAR Enable, // Dynamic SAR Enable/disable
250 * Extended SAR sets, // Number of optional SAR table sets
Sugnan Prabhu Sfcb4f2d2021-07-30 20:12:22 +0530251 * SAR Table Set, // Set#2 of SAR Table
252 * SAR Table Set, // Set#3 of SAR Table
253 * SAR Table Set // Set#4 of SAR Table
Furquan Shaikh2736c822020-10-27 19:46:11 -0700254 * }
255 * })
256 */
Sugnan Prabhu Sfcb4f2d2021-07-30 20:12:22 +0530257 if (sar->revision > MAX_SAR_REVISION) {
258 printk(BIOS_ERR, "ERROR: Invalid SAR table revision: %d\n", sar->revision);
259 return;
260 }
261
262 if (sar->dsar_set_count == 0) {
263 printk(BIOS_WARNING, "WARNING: DSAR set count is 0\n");
264 return;
265 }
266
Furquan Shaikh2736c822020-10-27 19:46:11 -0700267 acpigen_write_name("EWRD");
268 acpigen_write_package(2);
Sugnan Prabhu Sfcb4f2d2021-07-30 20:12:22 +0530269 acpigen_write_dword(sar->revision);
270
271 table_size = sar->chains_count * sar->subbands_count;
Furquan Shaikh2736c822020-10-27 19:46:11 -0700272 /*
Sugnan Prabhu Sfcb4f2d2021-07-30 20:12:22 +0530273 * Emit 'Domain Type' + 'Dynamic SAR Enable' + 'Extended SAR sets count'
Furquan Shaikh2736c822020-10-27 19:46:11 -0700274 * + number of bytes for Set#2 & 3 & 4
275 */
Matt Chen07e6b5f2021-11-04 18:13:25 +0800276 package_size = 1 + 1 + 1 + table_size * MAX_DSAR_SET_COUNT;
Furquan Shaikh2736c822020-10-27 19:46:11 -0700277 acpigen_write_package(package_size);
Sugnan Prabhu Sfcb4f2d2021-07-30 20:12:22 +0530278 acpigen_write_dword(DOMAIN_TYPE_WIFI);
279 acpigen_write_dword(1);
280 acpigen_write_dword(sar->dsar_set_count);
Furquan Shaikh2736c822020-10-27 19:46:11 -0700281
Sugnan Prabhu Sfcb4f2d2021-07-30 20:12:22 +0530282 for (set_num = 1; set_num <= sar->dsar_set_count; set_num++) {
283 set = sar_fetch_set(sar, set_num);
284 for (i = 0; i < table_size; i++)
285 acpigen_write_byte(set[i]);
286 }
287
288 /* wifi driver always expects 3 DSAR sets */
289 for (i = 0; i < (table_size * (MAX_DSAR_SET_COUNT - sar->dsar_set_count)); i++)
290 acpigen_write_byte(0);
291
292 acpigen_write_package_end();
293 acpigen_write_package_end();
294}
295
296static void sar_emit_wgds(struct geo_profile *wgds)
297{
298 int i;
299 size_t package_size, set_num;
300 const uint8_t *set;
301
302 if (wgds == NULL)
Furquan Shaikh2736c822020-10-27 19:46:11 -0700303 return;
304
305 /*
306 * Name ("WGDS", Package() {
307 * Revision,
308 * Package() {
309 * DomainType, // 0x7:WiFi
310 * WgdsWiFiSarDeltaGroup1PowerMax1, // Group 1 FCC 2400 Max
311 * WgdsWiFiSarDeltaGroup1PowerChainA1, // Group 1 FCC 2400 A Offset
312 * WgdsWiFiSarDeltaGroup1PowerChainB1, // Group 1 FCC 2400 B Offset
313 * WgdsWiFiSarDeltaGroup1PowerMax2, // Group 1 FCC 5200 Max
314 * WgdsWiFiSarDeltaGroup1PowerChainA2, // Group 1 FCC 5200 A Offset
315 * WgdsWiFiSarDeltaGroup1PowerChainB2, // Group 1 FCC 5200 B Offset
Sugnan Prabhu Sfcb4f2d2021-07-30 20:12:22 +0530316 * WgdsWiFiSarDeltaGroup1PowerMax3, // Group 1 FCC 6000-7000 Max
317 * WgdsWiFiSarDeltaGroup1PowerChainA3, // Group 1 FCC 6000-7000 A Offset
318 * WgdsWiFiSarDeltaGroup1PowerChainB3, // Group 1 FCC 6000-7000 B Offset
Furquan Shaikh2736c822020-10-27 19:46:11 -0700319 * WgdsWiFiSarDeltaGroup2PowerMax1, // Group 2 EC Jap 2400 Max
320 * WgdsWiFiSarDeltaGroup2PowerChainA1, // Group 2 EC Jap 2400 A Offset
321 * WgdsWiFiSarDeltaGroup2PowerChainB1, // Group 2 EC Jap 2400 B Offset
322 * WgdsWiFiSarDeltaGroup2PowerMax2, // Group 2 EC Jap 5200 Max
323 * WgdsWiFiSarDeltaGroup2PowerChainA2, // Group 2 EC Jap 5200 A Offset
324 * WgdsWiFiSarDeltaGroup2PowerChainB2, // Group 2 EC Jap 5200 B Offset
Sugnan Prabhu Sfcb4f2d2021-07-30 20:12:22 +0530325 * WgdsWiFiSarDeltaGroup2PowerMax3, // Group 2 EC Jap 6000-7000 Max
326 * WgdsWiFiSarDeltaGroup2PowerChainA3, // Group 2 EC Jap 6000-7000 A Offset
327 * WgdsWiFiSarDeltaGroup2PowerChainB3, // Group 2 EC Jap 6000-7000 B Offset
Furquan Shaikh2736c822020-10-27 19:46:11 -0700328 * WgdsWiFiSarDeltaGroup3PowerMax1, // Group 3 ROW 2400 Max
329 * WgdsWiFiSarDeltaGroup3PowerChainA1, // Group 3 ROW 2400 A Offset
330 * WgdsWiFiSarDeltaGroup3PowerChainB1, // Group 3 ROW 2400 B Offset
331 * WgdsWiFiSarDeltaGroup3PowerMax2, // Group 3 ROW 5200 Max
332 * WgdsWiFiSarDeltaGroup3PowerChainA2, // Group 3 ROW 5200 A Offset
333 * WgdsWiFiSarDeltaGroup3PowerChainB2, // Group 3 ROW 5200 B Offset
Sugnan Prabhu Sfcb4f2d2021-07-30 20:12:22 +0530334 * WgdsWiFiSarDeltaGroup3PowerMax3, // Group 3 ROW 6000-7000 Max
335 * WgdsWiFiSarDeltaGroup3PowerChainA3, // Group 3 ROW 6000-7000 A Offset
336 * WgdsWiFiSarDeltaGroup3PowerChainB3, // Group 3 ROW 6000-7000 B Offset
Furquan Shaikh2736c822020-10-27 19:46:11 -0700337 * }
338 * })
339 */
Sugnan Prabhu Sfcb4f2d2021-07-30 20:12:22 +0530340 if (wgds->revision > MAX_GEO_OFFSET_REVISION) {
341 printk(BIOS_ERR, "ERROR: Invalid WGDS revision: %d\n", wgds->revision);
342 return;
343 }
Furquan Shaikh2736c822020-10-27 19:46:11 -0700344
Sugnan Prabhu Sfcb4f2d2021-07-30 20:12:22 +0530345 package_size = 1 + wgds->chains_count * wgds->bands_count;
346
Furquan Shaikh2736c822020-10-27 19:46:11 -0700347 acpigen_write_name("WGDS");
348 acpigen_write_package(2);
Sugnan Prabhu Sfcb4f2d2021-07-30 20:12:22 +0530349 acpigen_write_dword(wgds->revision);
Furquan Shaikh2736c822020-10-27 19:46:11 -0700350 /* Emit 'Domain Type' +
351 * Group specific delta of power (6 bytes * NUM_WGDS_SAR_GROUPS)
352 */
Furquan Shaikh2736c822020-10-27 19:46:11 -0700353 acpigen_write_package(package_size);
Sugnan Prabhu Sfcb4f2d2021-07-30 20:12:22 +0530354 acpigen_write_dword(DOMAIN_TYPE_WIFI);
355
356 for (set_num = 0; set_num < wgds->chains_count; set_num++) {
357 set = wgds_fetch_set(wgds, set_num);
358 for (i = 0; i < wgds->bands_count; i++)
359 acpigen_write_byte(set[i]);
Furquan Shaikh2736c822020-10-27 19:46:11 -0700360 }
361
Sugnan Prabhu Sfcb4f2d2021-07-30 20:12:22 +0530362 acpigen_write_package_end();
363 acpigen_write_package_end();
364}
365
Sugnan Prabhu Sd1fc8322021-08-31 07:11:35 +0530366static void sar_emit_ppag(struct gain_profile *ppag)
367{
368 int i;
369 size_t package_size, set_num;
370 const uint8_t *set;
371
372 if (ppag == NULL)
373 return;
374
375 /*
376 * Name ("PPAG", Package () {
377 * Revision,
378 * Package () {
379 * Domain Type, // 0x7:WiFi
380 * PPAG Mode, // Defines the mode of ANT_gain control to be used
381 * ANT_gain Table Chain A // Defines the ANT_gain in dBi for chain A
382 * ANT_gain Table Chain B // Defines the ANT_gain in dBi for chain B
383 * }
384 * })
385 */
386 if (ppag->revision > MAX_ANT_GAINS_REVISION) {
387 printk(BIOS_ERR, "Invalid PPAG revision: %d\n", ppag->revision);
388 return;
389 }
390
391 package_size = 1 + 1 + ppag->chains_count * ppag->bands_count;
392
393 acpigen_write_name("PPAG");
394 acpigen_write_package(2);
395 acpigen_write_dword(ppag->revision);
396 acpigen_write_package(package_size);
397 acpigen_write_dword(DOMAIN_TYPE_WIFI);
398 acpigen_write_dword(ppag->mode);
399
400 for (set_num = 0; set_num < ppag->chains_count; set_num++) {
401 set = ppag_fetch_set(ppag, set_num);
402 for (i = 0; i < ppag->bands_count; i++)
403 acpigen_write_byte(set[i]);
404 }
405
406 acpigen_write_package_end();
407 acpigen_write_package_end();
408}
409
Sugnan Prabhu Scc507702021-08-31 07:19:30 +0530410static void sar_emit_wtas(struct avg_profile *wtas)
411{
412 int i;
413 size_t package_size;
414
415 if (wtas == NULL)
416 return;
417
418 /*
419 * Name (WTAS, Package() {
420 * {
421 * Revision,
422 * Package()
423 * {
424 * DomainType, // 0x7:WiFi
425 * WifiTASSelection, // Enable/Disable the TAS feature
426 * WifiTASListEntries, // No. of blocked countries not approved by OEM to
427 * BlockedListEntry1, support this feature
428 * BlockedListEntry2,
429 * BlockedListEntry3,
430 * BlockedListEntry4,
431 * BlockedListEntry5,
432 * BlockedListEntry6,
433 * BlockedListEntry7,
434 * BlockedListEntry8,
435 * BlockedListEntry9,
436 * BlockedListEntry10,
437 * BlockedListEntry11,
438 * BlockedListEntry12,
439 * BlockedListEntry13,
440 * BlockedListEntry14,
441 * BlockedListEntry15,
442 * BlockedListEntry16,
443 * }
444 * })
445 */
446 package_size = 1 + 1 + 1 + MAX_DENYLIST_ENTRY;
447
448 acpigen_write_name("WTAS");
449 acpigen_write_package(2);
450 acpigen_write_dword(wtas->revision);
451 acpigen_write_package(package_size);
452 acpigen_write_dword(DOMAIN_TYPE_WIFI);
Sugnan Prabhu S627c8442021-09-06 15:05:56 +0530453 acpigen_write_byte(wtas->tas_selection);
454 acpigen_write_byte(wtas->tas_list_size);
Sugnan Prabhu Scc507702021-08-31 07:19:30 +0530455 for (i = 0; i < MAX_DENYLIST_ENTRY; i++)
Sugnan Prabhu S627c8442021-09-06 15:05:56 +0530456 acpigen_write_word(wtas->deny_list_entry[i]);
Sugnan Prabhu Scc507702021-08-31 07:19:30 +0530457
458 acpigen_write_package_end();
459 acpigen_write_package_end();
460}
461
Sugnan Prabhu Sfcb4f2d2021-07-30 20:12:22 +0530462static void emit_sar_acpi_structures(const struct device *dev)
463{
464 union wifi_sar_limits sar_limits;
465
466 /*
467 * If device type is PCI, ensure that the device has Intel vendor ID. CBFS SAR and SAR
468 * ACPI tables are currently used only by Intel WiFi devices.
469 */
470 if (dev->path.type == DEVICE_PATH_PCI && dev->vendor != PCI_VENDOR_ID_INTEL)
471 return;
472
473 /* Retrieve the sar limits data */
474 if (get_wifi_sar_limits(&sar_limits) < 0) {
475 printk(BIOS_ERR, "ERROR: failed getting SAR limits!\n");
476 return;
477 }
478
479 sar_emit_wrds(sar_limits.sar);
480 sar_emit_ewrd(sar_limits.sar);
481 sar_emit_wgds(sar_limits.wgds);
Sugnan Prabhu Sd1fc8322021-08-31 07:11:35 +0530482 sar_emit_ppag(sar_limits.ppag);
Sugnan Prabhu Scc507702021-08-31 07:19:30 +0530483 sar_emit_wtas(sar_limits.wtas);
Sugnan Prabhu Sd70f4812021-08-25 17:36:44 +0530484 wifi_emit_dsm(sar_limits.dsm);
Sugnan Prabhu Sfcb4f2d2021-07-30 20:12:22 +0530485
486 free(sar_limits.sar);
Furquan Shaikh2736c822020-10-27 19:46:11 -0700487}
488
Furquan Shaikh6017abb2020-10-27 17:41:09 -0700489static void wifi_ssdt_write_device(const struct device *dev, const char *path)
Furquan Shaikh2736c822020-10-27 19:46:11 -0700490{
Furquan Shaikh2736c822020-10-27 19:46:11 -0700491 /* Device */
Furquan Shaikh6017abb2020-10-27 17:41:09 -0700492 acpigen_write_device(path);
Furquan Shaikh2736c822020-10-27 19:46:11 -0700493 acpi_device_write_uid(dev);
494
495 if (dev->chip_ops)
496 acpigen_write_name_string("_DDN", dev->chip_ops->name);
497
498 /* Address */
499 acpigen_write_ADR_pci_device(dev);
500
Furquan Shaikh6017abb2020-10-27 17:41:09 -0700501 acpigen_pop_len(); /* Device */
502}
503
504static void wifi_ssdt_write_properties(const struct device *dev, const char *scope)
505{
506 const struct drivers_wifi_generic_config *config = dev->chip_info;
507
508 /* Scope */
509 acpigen_write_scope(scope);
510
Furquan Shaikh2736c822020-10-27 19:46:11 -0700511 /* Wake capabilities */
512 if (config)
513 acpigen_write_PRW(config->wake, ACPI_S3);
514
515 /* Fill regulatory domain structure */
516 if (CONFIG(HAVE_REGULATORY_DOMAIN)) {
517 /*
518 * Name ("WRDD", Package () {
519 * WRDD_REVISION, // Revision
520 * Package () {
Sugnan Prabhu Sfcb4f2d2021-07-30 20:12:22 +0530521 * DOMAIN_TYPE_WIFI, // Domain Type, 7:WiFi
Furquan Shaikh2736c822020-10-27 19:46:11 -0700522 * wifi_regulatory_domain() // Country Identifier
523 * }
524 * })
525 */
526 acpigen_write_name("WRDD");
527 acpigen_write_package(2);
528 acpigen_write_integer(WRDD_REVISION);
529 acpigen_write_package(2);
Sugnan Prabhu Sfcb4f2d2021-07-30 20:12:22 +0530530 acpigen_write_dword(DOMAIN_TYPE_WIFI);
Furquan Shaikh2736c822020-10-27 19:46:11 -0700531 acpigen_write_dword(wifi_regulatory_domain());
532 acpigen_pop_len();
533 acpigen_pop_len();
534 }
535
536 /* Fill Wifi sar related ACPI structures */
537 if (CONFIG(USE_SAR))
538 emit_sar_acpi_structures(dev);
539
Furquan Shaikh2736c822020-10-27 19:46:11 -0700540 acpigen_pop_len(); /* Scope */
541
Furquan Shaikh6017abb2020-10-27 17:41:09 -0700542 printk(BIOS_INFO, "%s: %s %s\n", scope, dev->chip_ops ? dev->chip_ops->name : "",
543 dev_path(dev));
544}
545
Furquan Shaikhd4367502020-10-27 18:00:46 -0700546void wifi_pcie_fill_ssdt(const struct device *dev)
Furquan Shaikh6017abb2020-10-27 17:41:09 -0700547{
548 const char *path;
549
Furquan Shaikh6017abb2020-10-27 17:41:09 -0700550 path = acpi_device_path(dev);
551 if (!path)
552 return;
553
554 wifi_ssdt_write_device(dev, path);
555 wifi_ssdt_write_properties(dev, path);
Furquan Shaikh2736c822020-10-27 19:46:11 -0700556}
557
Furquan Shaikhd4367502020-10-27 18:00:46 -0700558const char *wifi_pcie_acpi_name(const struct device *dev)
Furquan Shaikh2736c822020-10-27 19:46:11 -0700559{
560 static char wifi_acpi_name[WIFI_ACPI_NAME_MAX_LEN];
561
562 /* ACPI 6.3, ASL 20.2.2: (Name Objects Encoding). */
563 snprintf(wifi_acpi_name, sizeof(wifi_acpi_name), "WF%02X",
564 (dev_path_encode(dev) & 0xff));
565 return wifi_acpi_name;
566}
Furquan Shaikhd4367502020-10-27 18:00:46 -0700567
568void wifi_cnvi_fill_ssdt(const struct device *dev)
569{
570 const char *path;
571
Furquan Shaikhd4367502020-10-27 18:00:46 -0700572 path = acpi_device_path(dev->bus->dev);
573 if (!path)
574 return;
575
576 wifi_ssdt_write_properties(dev, path);
577}