blob: b593ffe8bcbe899234249316751c8a1ac4c20888 [file] [log] [blame]
Karthikeyan Ramasubramanianfd5d7882019-05-29 15:09:42 -06001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright 2019 Google LLC
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 or (at your option)
9 * any later version of the License.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 */
16
17#include <arch/acpi_device.h>
18#include <arch/acpigen.h>
19#include <console/console.h>
20#include <device/device.h>
21#include <device/pci_def.h>
22#include <sar.h>
23#include <string.h>
24#include <wrdd.h>
25#include "generic_wifi.h"
26
27/* WRDS Spec Revision */
28#define WRDS_REVISION 0x0
29
30/* EWRD Spec Revision */
31#define EWRD_REVISION 0x0
32
33/* WRDS Domain type */
34#define WRDS_DOMAIN_TYPE_WIFI 0x7
35
36/* EWRD Domain type */
37#define EWRD_DOMAIN_TYPE_WIFI 0x7
38
39/* WGDS Domain type */
40#define WGDS_DOMAIN_TYPE_WIFI 0x7
41
42/*
43 * WIFI ACPI NAME = "WF" + hex value of last 8 bits of dev_path_encode + '\0'
44 * The above representation returns unique and consistent name every time
45 * generate_wifi_acpi_name is invoked. The last 8 bits of dev_path_encode is
46 * chosen since it contains the bus address of the device.
47 */
48#define WIFI_ACPI_NAME_MAX_LEN 5
49
50__weak
51int get_wifi_sar_limits(struct wifi_sar_limits *sar_limits)
52{
53 return -1;
54}
55
56static void emit_sar_acpi_structures(void)
57{
58 int i, j, package_size;
59 struct wifi_sar_limits sar_limits;
60 struct wifi_sar_delta_table *wgds;
61
62 /* Retrieve the sar limits data */
63 if (get_wifi_sar_limits(&sar_limits) < 0) {
64 printk(BIOS_ERR, "Error: failed from getting SAR limits!\n");
65 return;
66 }
67
68 /*
69 * Name ("WRDS", Package () {
70 * Revision,
71 * Package () {
72 * Domain Type, // 0x7:WiFi
73 * WiFi SAR BIOS, // BIOS SAR Enable/disable
74 * SAR Table Set // Set#1 of SAR Table (10 bytes)
75 * }
76 * })
77 */
78 acpigen_write_name("WRDS");
79 acpigen_write_package(2);
80 acpigen_write_dword(WRDS_REVISION);
81 /* Emit 'Domain Type' + 'WiFi SAR BIOS' + 10 bytes for Set#1 */
82 package_size = 1 + 1 + BYTES_PER_SAR_LIMIT;
83 acpigen_write_package(package_size);
84 acpigen_write_dword(WRDS_DOMAIN_TYPE_WIFI);
85 acpigen_write_dword(CONFIG(SAR_ENABLE));
86 for (i = 0; i < BYTES_PER_SAR_LIMIT; i++)
87 acpigen_write_byte(sar_limits.sar_limit[0][i]);
88 acpigen_pop_len();
89 acpigen_pop_len();
90
91 /*
92 * Name ("EWRD", Package () {
93 * Revision,
94 * Package () {
95 * Domain Type, // 0x7:WiFi
96 * Dynamic SAR Enable, // Dynamic SAR Enable/disable
97 * Extended SAR sets, // Number of optional SAR table sets
98 * SAR Table Set, // Set#2 of SAR Table (10 bytes)
99 * SAR Table Set, // Set#3 of SAR Table (10 bytes)
100 * SAR Table Set // Set#4 of SAR Table (10 bytes)
101 * }
102 * })
103 */
104 acpigen_write_name("EWRD");
105 acpigen_write_package(2);
106 acpigen_write_dword(EWRD_REVISION);
107 /*
108 * Emit 'Domain Type' + "Dynamic SAR Enable' + 'Extended SAR sets'
109 * + number of bytes for Set#2 & 3 & 4
110 */
111 package_size = 1 + 1 + 1 + (NUM_SAR_LIMITS - 1) * BYTES_PER_SAR_LIMIT;
112 acpigen_write_package(package_size);
113 acpigen_write_dword(EWRD_DOMAIN_TYPE_WIFI);
114 acpigen_write_dword(CONFIG(DSAR_ENABLE));
115 acpigen_write_dword(CONFIG_DSAR_SET_NUM);
116 for (i = 1; i < NUM_SAR_LIMITS; i++)
117 for (j = 0; j < BYTES_PER_SAR_LIMIT; j++)
118 acpigen_write_byte(sar_limits.sar_limit[i][j]);
119 acpigen_pop_len();
120 acpigen_pop_len();
121
122
123 if (!CONFIG(GEO_SAR_ENABLE))
124 return;
125
126 /*
127 * Name ("WGDS", Package() {
128 * Revision,
129 * Package() {
130 * DomainType, // 0x7:WiFi
131 * WgdsWiFiSarDeltaGroup1PowerMax1, // Group 1 FCC 2400 Max
132 * WgdsWiFiSarDeltaGroup1PowerChainA1, // Group 1 FCC 2400 A Offset
133 * WgdsWiFiSarDeltaGroup1PowerChainB1, // Group 1 FCC 2400 B Offset
134 * WgdsWiFiSarDeltaGroup1PowerMax2, // Group 1 FCC 5200 Max
135 * WgdsWiFiSarDeltaGroup1PowerChainA2, // Group 1 FCC 5200 A Offset
136 * WgdsWiFiSarDeltaGroup1PowerChainB2, // Group 1 FCC 5200 B Offset
137 * WgdsWiFiSarDeltaGroup2PowerMax1, // Group 2 EC Jap 2400 Max
138 * WgdsWiFiSarDeltaGroup2PowerChainA1, // Group 2 EC Jap 2400 A Offset
139 * WgdsWiFiSarDeltaGroup2PowerChainB1, // Group 2 EC Jap 2400 B Offset
140 * WgdsWiFiSarDeltaGroup2PowerMax2, // Group 2 EC Jap 5200 Max
141 * WgdsWiFiSarDeltaGroup2PowerChainA2, // Group 2 EC Jap 5200 A Offset
142 * WgdsWiFiSarDeltaGroup2PowerChainB2, // Group 2 EC Jap 5200 B Offset
143 * WgdsWiFiSarDeltaGroup3PowerMax1, // Group 3 ROW 2400 Max
144 * WgdsWiFiSarDeltaGroup3PowerChainA1, // Group 3 ROW 2400 A Offset
145 * WgdsWiFiSarDeltaGroup3PowerChainB1, // Group 3 ROW 2400 B Offset
146 * WgdsWiFiSarDeltaGroup3PowerMax2, // Group 3 ROW 5200 Max
147 * WgdsWiFiSarDeltaGroup3PowerChainA2, // Group 3 ROW 5200 A Offset
148 * WgdsWiFiSarDeltaGroup3PowerChainB2, // Group 3 ROW 5200 B Offset
149 * }
150 * })
151 */
152
153 wgds = &sar_limits.wgds;
154 acpigen_write_name("WGDS");
155 acpigen_write_package(2);
156 acpigen_write_dword(wgds->version);
157 /* Emit 'Domain Type' +
158 * Group specific delta of power (6 bytes * NUM_WGDS_SAR_GROUPS)
159 */
160 package_size = sizeof(sar_limits.wgds.group) + 1;
161 acpigen_write_package(package_size);
162 acpigen_write_dword(WGDS_DOMAIN_TYPE_WIFI);
163 for (i = 0; i < SAR_NUM_WGDS_GROUPS; i++) {
164 acpigen_write_byte(wgds->group[i].power_max_2400mhz);
165 acpigen_write_byte(wgds->group[i].power_chain_a_2400mhz);
166 acpigen_write_byte(wgds->group[i].power_chain_b_2400mhz);
167 acpigen_write_byte(wgds->group[i].power_max_5200mhz);
168 acpigen_write_byte(wgds->group[i].power_chain_a_5200mhz);
169 acpigen_write_byte(wgds->group[i].power_chain_b_5200mhz);
170 }
171
172 acpigen_pop_len();
173 acpigen_pop_len();
174}
175
176void generic_wifi_fill_ssdt(struct device *dev,
177 const struct generic_wifi_config *config)
178{
179 const char *path;
180 u32 address;
181
182 if (!dev->enabled)
183 return;
184
185 path = acpi_device_path(dev->bus->dev);
186 if (!path)
187 return;
188
189 /* Device */
190 acpigen_write_scope(path);
191 acpigen_write_device(acpi_device_name(dev));
192 acpigen_write_name_integer("_UID", 0);
193 if (dev->chip_ops)
194 acpigen_write_name_string("_DDN", dev->chip_ops->name);
195
196 /* Address */
197 address = PCI_SLOT(dev->path.pci.devfn) & 0xffff;
198 address <<= 16;
199 address |= PCI_FUNC(dev->path.pci.devfn) & 0xffff;
200 acpigen_write_name_dword("_ADR", address);
201
202 /* Wake capabilities */
203 if (config)
204 acpigen_write_PRW(config->wake, config->maxsleep);
205
206 /* Fill regulatory domain structure */
207 if (CONFIG(HAVE_REGULATORY_DOMAIN)) {
208 /*
209 * Name ("WRDD", Package () {
210 * WRDD_REVISION, // Revision
211 * Package () {
212 * WRDD_DOMAIN_TYPE_WIFI, // Domain Type, 7:WiFi
213 * wifi_regulatory_domain() // Country Identifier
214 * }
215 * })
216 */
217 acpigen_write_name("WRDD");
218 acpigen_write_package(2);
219 acpigen_write_integer(WRDD_REVISION);
220 acpigen_write_package(2);
221 acpigen_write_dword(WRDD_DOMAIN_TYPE_WIFI);
222 acpigen_write_dword(wifi_regulatory_domain());
223 acpigen_pop_len();
224 acpigen_pop_len();
225 }
226
227 /* Fill Wifi sar related ACPI structures */
228 if (CONFIG(USE_SAR))
229 emit_sar_acpi_structures();
230
231 acpigen_pop_len(); /* Device */
232 acpigen_pop_len(); /* Scope */
233
234 printk(BIOS_INFO, "%s.%s: %s %s\n", path, acpi_device_name(dev),
235 dev->chip_ops ? dev->chip_ops->name : "", dev_path(dev));
236}
237
238const char *generic_wifi_acpi_name(const struct device *dev)
239{
240 static char wifi_acpi_name[WIFI_ACPI_NAME_MAX_LEN];
241
242 snprintf(wifi_acpi_name, sizeof(wifi_acpi_name), "WF%02x",
243 (dev_path_encode(dev) & 0xff));
244 return wifi_acpi_name;
245}