blob: d1d5684a19606e7748ec3d10a3fe47795385cdff [file] [log] [blame]
Vladimir Serbinenko41f55b72014-10-31 09:10:16 +01001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2014 Vladimir Serbinenko
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.
Vladimir Serbinenko41f55b72014-10-31 09:10:16 +010015 */
16
Stefan Reinauer6a001132017-07-13 02:20:27 +020017#include <compiler.h>
Duncan Laurie5c026442016-05-11 14:05:07 -070018#include <arch/acpi_device.h>
19#include <arch/acpigen.h>
Vladimir Serbinenko41f55b72014-10-31 09:10:16 +010020#include <console/console.h>
21#include <device/device.h>
22#include <device/pci.h>
23#include <device/pci_ids.h>
Naresh G Solanki3c6377f2017-07-03 21:57:11 +053024#include <elog.h>
Robbie Zhang3dea69a2016-12-23 12:20:47 -080025#include <sar.h>
Vladimir Serbinenko41f55b72014-10-31 09:10:16 +010026#include <smbios.h>
27#include <string.h>
Duncan Laurie5c026442016-05-11 14:05:07 -070028#include <wrdd.h>
29#include "chip.h"
Vladimir Serbinenko41f55b72014-10-31 09:10:16 +010030
Naresh G Solanki3c6377f2017-07-03 21:57:11 +053031#define PMCS_DR 0xcc
32#define PME_STS (1 << 15)
33
Kyösti Mälkki828e73e2016-07-28 17:26:39 +030034#if IS_ENABLED(CONFIG_GENERATE_SMBIOS_TABLES)
Vladimir Serbinenko41f55b72014-10-31 09:10:16 +010035static int smbios_write_wifi(struct device *dev, int *handle,
36 unsigned long *current)
37{
38 struct smbios_type_intel_wifi {
39 u8 type;
40 u8 length;
41 u16 handle;
42 u8 str;
43 char eos[2];
Stefan Reinauer6a001132017-07-13 02:20:27 +020044 } __packed;
Vladimir Serbinenko41f55b72014-10-31 09:10:16 +010045
Duncan Laurie5c026442016-05-11 14:05:07 -070046 struct smbios_type_intel_wifi *t =
47 (struct smbios_type_intel_wifi *)*current;
Vladimir Serbinenko41f55b72014-10-31 09:10:16 +010048 int len = sizeof(struct smbios_type_intel_wifi);
49
50 memset(t, 0, sizeof(struct smbios_type_intel_wifi));
51 t->type = 0x85;
52 t->length = len - 2;
53 t->handle = *handle;
Duncan Laurie5c026442016-05-11 14:05:07 -070054 /*
55 * Intel wifi driver expects this string to be in the table 0x85
56 * with PCI IDs enumerated below.
Vladimir Serbinenko41f55b72014-10-31 09:10:16 +010057 */
58 t->str = smbios_add_string(t->eos, "KHOIHGIUCCHHII");
59
60 len = t->length + smbios_string_table_len(t->eos);
61 *current += len;
62 *handle += 1;
63 return len;
64}
Kyösti Mälkki828e73e2016-07-28 17:26:39 +030065#endif
Vladimir Serbinenko41f55b72014-10-31 09:10:16 +010066
Aaron Durbin2abbbf12017-05-04 22:26:44 -050067__attribute__((weak))
68int get_wifi_sar_limits(struct wifi_sar_limits *sar_limits)
69{
70 return -1;
71}
72
Duncan Laurie5c026442016-05-11 14:05:07 -070073#if IS_ENABLED(CONFIG_HAVE_ACPI_TABLES)
Robbie Zhang3dea69a2016-12-23 12:20:47 -080074static void emit_sar_acpi_structures(void)
75{
76 int i, j, package_size;
77 struct wifi_sar_limits sar_limits;
78
79 /* Retrieve the sar limits data */
80 if (get_wifi_sar_limits(&sar_limits) < 0) {
81 printk(BIOS_ERR, "Error: failed from getting SAR limits!\n");
82 return;
83 }
84
85 /*
86 * Name ("WRDS", Package () {
87 * Revision,
88 * Package () {
89 * Domain Type, // 0x7:WiFi
90 * WiFi SAR BIOS, // BIOS SAR Enable/disable
91 * SAR Table Set // Set#1 of SAR Table (10 bytes)
92 * }
93 * })
94 */
95 acpigen_write_name("WRDS");
96 acpigen_write_package(2);
97 acpigen_write_dword(WRDS_REVISION);
98 /* Emit 'Domain Type' + 'WiFi SAR BIOS' + 10 bytes for Set#1 */
99 package_size = 1 + 1 + BYTES_PER_SAR_LIMIT;
100 acpigen_write_package(package_size);
101 acpigen_write_dword(WRDS_DOMAIN_TYPE_WIFI);
102 acpigen_write_dword(CONFIG_SAR_ENABLE);
103 for (i = 0; i < BYTES_PER_SAR_LIMIT; i++)
104 acpigen_write_byte(sar_limits.sar_limit[0][i]);
105 acpigen_pop_len();
106 acpigen_pop_len();
107
108 /*
109 * Name ("EWRD", Package () {
110 * Revision,
111 * Package () {
112 * Domain Type, // 0x7:WiFi
113 * Dynamic SAR Enable, // Dynamic SAR Enable/disable
114 * Extended SAR sets, // Number of optional SAR table sets
115 * SAR Table Set, // Set#2 of SAR Table (10 bytes)
116 * SAR Table Set, // Set#3 of SAR Table (10 bytes)
117 * SAR Table Set // Set#4 of SAR Table (10 bytes)
118 * }
119 * })
120 */
121 acpigen_write_name("EWRD");
122 acpigen_write_package(2);
123 acpigen_write_dword(EWRD_REVISION);
124 /*
125 * Emit 'Domain Type' + "Dynamic SAR Enable' + 'Extended SAR sets'
126 * + number of bytes for Set#2 & 3 & 4
127 */
128 package_size = 1 + 1 + 1 + (NUM_SAR_LIMITS - 1) * BYTES_PER_SAR_LIMIT;
129 acpigen_write_package(package_size);
130 acpigen_write_dword(EWRD_DOMAIN_TYPE_WIFI);
131 acpigen_write_dword(CONFIG_DSAR_ENABLE);
132 acpigen_write_dword(CONFIG_DSAR_SET_NUM);
133 for (i = 1; i < NUM_SAR_LIMITS; i++)
134 for (j = 0; j < BYTES_PER_SAR_LIMIT; j++)
135 acpigen_write_byte(sar_limits.sar_limit[i][j]);
136 acpigen_pop_len();
137 acpigen_pop_len();
138}
139
Duncan Laurie5c026442016-05-11 14:05:07 -0700140static void intel_wifi_fill_ssdt(struct device *dev)
141{
142 struct drivers_intel_wifi_config *config = dev->chip_info;
143 const char *path = acpi_device_path(dev->bus->dev);
144 u32 address;
145
146 if (!path)
147 return;
148
149 /* Device */
150 acpigen_write_scope(path);
151 acpigen_write_device(acpi_device_name(dev));
152 acpigen_write_name_integer("_UID", 0);
Patrick Rudolph6086b4e2017-06-07 09:39:28 +0200153 if (dev->chip_ops)
154 acpigen_write_name_string("_DDN", dev->chip_ops->name);
Duncan Laurie5c026442016-05-11 14:05:07 -0700155
156 /* Address */
157 address = PCI_SLOT(dev->path.pci.devfn) & 0xffff;
158 address <<= 16;
159 address |= PCI_FUNC(dev->path.pci.devfn) & 0xffff;
160 acpigen_write_name_dword("_ADR", address);
161
162 /* Wake capabilities */
163 if (config && config->wake)
164 acpigen_write_PRW(config->wake, 3);
165
166 /* Fill regulatory domain structure */
167 if (IS_ENABLED(CONFIG_HAVE_REGULATORY_DOMAIN)) {
168 /*
169 * Name ("WRDD", Package () {
170 * WRDD_REVISION, // Revision
171 * Package () {
172 * WRDD_DOMAIN_TYPE_WIFI, // Domain Type, 7:WiFi
173 * wifi_regulatory_domain() // Country Identifier
174 * }
175 * })
176 */
177 acpigen_write_name("WRDD");
178 acpigen_write_package(2);
179 acpigen_write_integer(WRDD_REVISION);
180 acpigen_write_package(2);
181 acpigen_write_dword(WRDD_DOMAIN_TYPE_WIFI);
182 acpigen_write_dword(wifi_regulatory_domain());
183 acpigen_pop_len();
184 acpigen_pop_len();
185 }
186
Robbie Zhang3dea69a2016-12-23 12:20:47 -0800187 /* Fill Wifi sar related ACPI structures */
188 if (IS_ENABLED(CONFIG_USE_SAR))
189 emit_sar_acpi_structures();
190
Duncan Laurie5c026442016-05-11 14:05:07 -0700191 acpigen_pop_len(); /* Device */
192 acpigen_pop_len(); /* Scope */
193
194 printk(BIOS_INFO, "%s.%s: %s %s\n", path, acpi_device_name(dev),
Patrick Rudolph6086b4e2017-06-07 09:39:28 +0200195 dev->chip_ops ? dev->chip_ops->name : "", dev_path(dev));
Duncan Laurie5c026442016-05-11 14:05:07 -0700196}
197
198static const char *intel_wifi_acpi_name(struct device *dev)
199{
200 return "WIFI";
201}
202#endif
203
Naresh G Solanki3c6377f2017-07-03 21:57:11 +0530204static void wifi_pci_dev_init(struct device *dev)
205{
206 pci_dev_init(dev);
207
208 if (IS_ENABLED(CONFIG_ELOG)) {
209 uint32_t val;
210 val = pci_read_config16(dev, PMCS_DR);
211 if (val & PME_STS)
212 elog_add_event_wake(ELOG_WAKE_SOURCE_PME_WIFI, 0);
213 }
214}
215
Vladimir Serbinenko41f55b72014-10-31 09:10:16 +0100216static struct pci_operations pci_ops = {
217 .set_subsystem = pci_dev_set_subsystem,
218};
219
220struct device_operations device_ops = {
Duncan Laurie5c026442016-05-11 14:05:07 -0700221 .read_resources = pci_dev_read_resources,
222 .set_resources = pci_dev_set_resources,
223 .enable_resources = pci_dev_enable_resources,
Naresh G Solanki3c6377f2017-07-03 21:57:11 +0530224 .init = wifi_pci_dev_init,
Kyösti Mälkki828e73e2016-07-28 17:26:39 +0300225#if IS_ENABLED(CONFIG_GENERATE_SMBIOS_TABLES)
Duncan Laurie5c026442016-05-11 14:05:07 -0700226 .get_smbios_data = smbios_write_wifi,
Kyösti Mälkki828e73e2016-07-28 17:26:39 +0300227#endif
Duncan Laurie5c026442016-05-11 14:05:07 -0700228 .ops_pci = &pci_ops,
229#if IS_ENABLED(CONFIG_HAVE_ACPI_TABLES)
230 .acpi_name = &intel_wifi_acpi_name,
231 .acpi_fill_ssdt_generator = &intel_wifi_fill_ssdt,
232#endif
Vladimir Serbinenko41f55b72014-10-31 09:10:16 +0100233};
234
Vladimir Serbinenko41f55b72014-10-31 09:10:16 +0100235static const unsigned short pci_device_ids[] = {
236 0x0084, 0x0085, 0x0089, 0x008b, 0x008e, 0x0090,
237 0x0886, 0x0888, 0x0891, 0x0893, 0x0895, 0x088f,
238 0x4236, 0x4237, 0x4238, 0x4239, 0x423b, 0x423d,
Duncan Laurie5c026442016-05-11 14:05:07 -0700239 0x08b1, 0x08b2, /* Wilkins Peak 2 */
240 0x095a, 0x095b, /* Stone Peak 2 */
241 0
242};
Vladimir Serbinenko41f55b72014-10-31 09:10:16 +0100243
244static const struct pci_driver pch_intel_wifi __pci_driver = {
245 .ops = &device_ops,
246 .vendor = PCI_VENDOR_ID_INTEL,
247 .devices = pci_device_ids,
248};
Duncan Laurie5c026442016-05-11 14:05:07 -0700249
250static void intel_wifi_enable(struct device *dev)
251{
252 dev->ops = &device_ops;
253}
254
255struct chip_operations drivers_intel_wifi_ops = {
256 CHIP_NAME("Intel WiFi")
257 .enable_dev = &intel_wifi_enable
258};