blob: 789d0d5431b9d3d33ed8eaf227396c9dfbf5f5e2 [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
Duncan Laurie5c026442016-05-11 14:05:07 -070017#include <arch/acpi_device.h>
18#include <arch/acpigen.h>
Vladimir Serbinenko41f55b72014-10-31 09:10:16 +010019#include <console/console.h>
20#include <device/device.h>
21#include <device/pci.h>
22#include <device/pci_ids.h>
23#include <smbios.h>
24#include <string.h>
Duncan Laurie5c026442016-05-11 14:05:07 -070025#include <wrdd.h>
26#include "chip.h"
Vladimir Serbinenko41f55b72014-10-31 09:10:16 +010027
Kyösti Mälkki828e73e2016-07-28 17:26:39 +030028#if IS_ENABLED(CONFIG_GENERATE_SMBIOS_TABLES)
Vladimir Serbinenko41f55b72014-10-31 09:10:16 +010029static int smbios_write_wifi(struct device *dev, int *handle,
30 unsigned long *current)
31{
32 struct smbios_type_intel_wifi {
33 u8 type;
34 u8 length;
35 u16 handle;
36 u8 str;
37 char eos[2];
38 } __attribute__((packed));
39
Duncan Laurie5c026442016-05-11 14:05:07 -070040 struct smbios_type_intel_wifi *t =
41 (struct smbios_type_intel_wifi *)*current;
Vladimir Serbinenko41f55b72014-10-31 09:10:16 +010042 int len = sizeof(struct smbios_type_intel_wifi);
43
44 memset(t, 0, sizeof(struct smbios_type_intel_wifi));
45 t->type = 0x85;
46 t->length = len - 2;
47 t->handle = *handle;
Duncan Laurie5c026442016-05-11 14:05:07 -070048 /*
49 * Intel wifi driver expects this string to be in the table 0x85
50 * with PCI IDs enumerated below.
Vladimir Serbinenko41f55b72014-10-31 09:10:16 +010051 */
52 t->str = smbios_add_string(t->eos, "KHOIHGIUCCHHII");
53
54 len = t->length + smbios_string_table_len(t->eos);
55 *current += len;
56 *handle += 1;
57 return len;
58}
Kyösti Mälkki828e73e2016-07-28 17:26:39 +030059#endif
Vladimir Serbinenko41f55b72014-10-31 09:10:16 +010060
Duncan Laurie5c026442016-05-11 14:05:07 -070061#if IS_ENABLED(CONFIG_HAVE_ACPI_TABLES)
62static void intel_wifi_fill_ssdt(struct device *dev)
63{
64 struct drivers_intel_wifi_config *config = dev->chip_info;
65 const char *path = acpi_device_path(dev->bus->dev);
66 u32 address;
67
68 if (!path)
69 return;
70
71 /* Device */
72 acpigen_write_scope(path);
73 acpigen_write_device(acpi_device_name(dev));
74 acpigen_write_name_integer("_UID", 0);
75 acpigen_write_name_string("_DDN", dev->chip_ops->name);
76
77 /* Address */
78 address = PCI_SLOT(dev->path.pci.devfn) & 0xffff;
79 address <<= 16;
80 address |= PCI_FUNC(dev->path.pci.devfn) & 0xffff;
81 acpigen_write_name_dword("_ADR", address);
82
83 /* Wake capabilities */
84 if (config && config->wake)
85 acpigen_write_PRW(config->wake, 3);
86
87 /* Fill regulatory domain structure */
88 if (IS_ENABLED(CONFIG_HAVE_REGULATORY_DOMAIN)) {
89 /*
90 * Name ("WRDD", Package () {
91 * WRDD_REVISION, // Revision
92 * Package () {
93 * WRDD_DOMAIN_TYPE_WIFI, // Domain Type, 7:WiFi
94 * wifi_regulatory_domain() // Country Identifier
95 * }
96 * })
97 */
98 acpigen_write_name("WRDD");
99 acpigen_write_package(2);
100 acpigen_write_integer(WRDD_REVISION);
101 acpigen_write_package(2);
102 acpigen_write_dword(WRDD_DOMAIN_TYPE_WIFI);
103 acpigen_write_dword(wifi_regulatory_domain());
104 acpigen_pop_len();
105 acpigen_pop_len();
106 }
107
108 acpigen_pop_len(); /* Device */
109 acpigen_pop_len(); /* Scope */
110
111 printk(BIOS_INFO, "%s.%s: %s %s\n", path, acpi_device_name(dev),
112 dev->chip_ops->name, dev_path(dev));
113}
114
115static const char *intel_wifi_acpi_name(struct device *dev)
116{
117 return "WIFI";
118}
119#endif
120
Vladimir Serbinenko41f55b72014-10-31 09:10:16 +0100121static struct pci_operations pci_ops = {
122 .set_subsystem = pci_dev_set_subsystem,
123};
124
125struct device_operations device_ops = {
Duncan Laurie5c026442016-05-11 14:05:07 -0700126 .read_resources = pci_dev_read_resources,
127 .set_resources = pci_dev_set_resources,
128 .enable_resources = pci_dev_enable_resources,
129 .init = pci_dev_init,
Kyösti Mälkki828e73e2016-07-28 17:26:39 +0300130#if IS_ENABLED(CONFIG_GENERATE_SMBIOS_TABLES)
Duncan Laurie5c026442016-05-11 14:05:07 -0700131 .get_smbios_data = smbios_write_wifi,
Kyösti Mälkki828e73e2016-07-28 17:26:39 +0300132#endif
Duncan Laurie5c026442016-05-11 14:05:07 -0700133 .ops_pci = &pci_ops,
134#if IS_ENABLED(CONFIG_HAVE_ACPI_TABLES)
135 .acpi_name = &intel_wifi_acpi_name,
136 .acpi_fill_ssdt_generator = &intel_wifi_fill_ssdt,
137#endif
Vladimir Serbinenko41f55b72014-10-31 09:10:16 +0100138};
139
Vladimir Serbinenko41f55b72014-10-31 09:10:16 +0100140static const unsigned short pci_device_ids[] = {
141 0x0084, 0x0085, 0x0089, 0x008b, 0x008e, 0x0090,
142 0x0886, 0x0888, 0x0891, 0x0893, 0x0895, 0x088f,
143 0x4236, 0x4237, 0x4238, 0x4239, 0x423b, 0x423d,
Duncan Laurie5c026442016-05-11 14:05:07 -0700144 0x08b1, 0x08b2, /* Wilkins Peak 2 */
145 0x095a, 0x095b, /* Stone Peak 2 */
146 0
147};
Vladimir Serbinenko41f55b72014-10-31 09:10:16 +0100148
149static const struct pci_driver pch_intel_wifi __pci_driver = {
150 .ops = &device_ops,
151 .vendor = PCI_VENDOR_ID_INTEL,
152 .devices = pci_device_ids,
153};
Duncan Laurie5c026442016-05-11 14:05:07 -0700154
155static void intel_wifi_enable(struct device *dev)
156{
157 dev->ops = &device_ops;
158}
159
160struct chip_operations drivers_intel_wifi_ops = {
161 CHIP_NAME("Intel WiFi")
162 .enable_dev = &intel_wifi_enable
163};