blob: f83d04ccc18cb643c7d6741f054c722992b949a3 [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>
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
41static 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
164void wifi_generic_fill_ssdt(const struct device *dev)
165{
166 const char *path;
167 const struct drivers_wifi_generic_config *config = dev->chip_info;
168
169 if (!dev->enabled)
170 return;
171
172 path = acpi_device_path(dev->bus->dev);
173 if (!path)
174 return;
175
176 /* Device */
177 acpigen_write_scope(path);
178 acpigen_write_device(acpi_device_name(dev));
179 acpi_device_write_uid(dev);
180
181 if (dev->chip_ops)
182 acpigen_write_name_string("_DDN", dev->chip_ops->name);
183
184 /* Address */
185 acpigen_write_ADR_pci_device(dev);
186
187 /* Wake capabilities */
188 if (config)
189 acpigen_write_PRW(config->wake, ACPI_S3);
190
191 /* Fill regulatory domain structure */
192 if (CONFIG(HAVE_REGULATORY_DOMAIN)) {
193 /*
194 * Name ("WRDD", Package () {
195 * WRDD_REVISION, // Revision
196 * Package () {
197 * WRDD_DOMAIN_TYPE_WIFI, // Domain Type, 7:WiFi
198 * wifi_regulatory_domain() // Country Identifier
199 * }
200 * })
201 */
202 acpigen_write_name("WRDD");
203 acpigen_write_package(2);
204 acpigen_write_integer(WRDD_REVISION);
205 acpigen_write_package(2);
206 acpigen_write_dword(WRDD_DOMAIN_TYPE_WIFI);
207 acpigen_write_dword(wifi_regulatory_domain());
208 acpigen_pop_len();
209 acpigen_pop_len();
210 }
211
212 /* Fill Wifi sar related ACPI structures */
213 if (CONFIG(USE_SAR))
214 emit_sar_acpi_structures(dev);
215
216 acpigen_pop_len(); /* Device */
217 acpigen_pop_len(); /* Scope */
218
219 printk(BIOS_INFO, "%s.%s: %s %s\n", path, acpi_device_name(dev),
220 dev->chip_ops ? dev->chip_ops->name : "", dev_path(dev));
221}
222
223const char *wifi_generic_acpi_name(const struct device *dev)
224{
225 static char wifi_acpi_name[WIFI_ACPI_NAME_MAX_LEN];
226
227 /* ACPI 6.3, ASL 20.2.2: (Name Objects Encoding). */
228 snprintf(wifi_acpi_name, sizeof(wifi_acpi_name), "WF%02X",
229 (dev_path_encode(dev) & 0xff));
230 return wifi_acpi_name;
231}