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