Patrick Georgi | ac95903 | 2020-05-05 22:49:26 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Vladimir Serbinenko | 41f55b7 | 2014-10-31 09:10:16 +0100 | [diff] [blame] | 2 | |
Vladimir Serbinenko | 41f55b7 | 2014-10-31 09:10:16 +0100 | [diff] [blame] | 3 | #include <device/device.h> |
| 4 | #include <device/pci.h> |
Kyösti Mälkki | f1b58b7 | 2019-03-01 13:43:02 +0200 | [diff] [blame] | 5 | #include <device/pci_ops.h> |
Vladimir Serbinenko | 41f55b7 | 2014-10-31 09:10:16 +0100 | [diff] [blame] | 6 | #include <device/pci_ids.h> |
Naresh G Solanki | 3c6377f | 2017-07-03 21:57:11 +0530 | [diff] [blame] | 7 | #include <elog.h> |
Vladimir Serbinenko | 41f55b7 | 2014-10-31 09:10:16 +0100 | [diff] [blame] | 8 | #include <smbios.h> |
| 9 | #include <string.h> |
Duncan Laurie | 5c02644 | 2016-05-11 14:05:07 -0700 | [diff] [blame] | 10 | #include "chip.h" |
Karthikeyan Ramasubramanian | fd5d788 | 2019-05-29 15:09:42 -0600 | [diff] [blame] | 11 | #include "drivers/wifi/generic_wifi.h" |
Vladimir Serbinenko | 41f55b7 | 2014-10-31 09:10:16 +0100 | [diff] [blame] | 12 | |
Naresh G Solanki | 3c6377f | 2017-07-03 21:57:11 +0530 | [diff] [blame] | 13 | #define PMCS_DR 0xcc |
| 14 | #define PME_STS (1 << 15) |
| 15 | |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 16 | #if CONFIG(GENERATE_SMBIOS_TABLES) |
Vladimir Serbinenko | 41f55b7 | 2014-10-31 09:10:16 +0100 | [diff] [blame] | 17 | static int smbios_write_wifi(struct device *dev, int *handle, |
| 18 | unsigned long *current) |
| 19 | { |
| 20 | struct smbios_type_intel_wifi { |
| 21 | u8 type; |
| 22 | u8 length; |
| 23 | u16 handle; |
| 24 | u8 str; |
Konstantin Aladyshev | d0df1d7 | 2017-08-01 15:52:46 +0300 | [diff] [blame] | 25 | u8 eos[2]; |
Stefan Reinauer | 6a00113 | 2017-07-13 02:20:27 +0200 | [diff] [blame] | 26 | } __packed; |
Vladimir Serbinenko | 41f55b7 | 2014-10-31 09:10:16 +0100 | [diff] [blame] | 27 | |
Duncan Laurie | 5c02644 | 2016-05-11 14:05:07 -0700 | [diff] [blame] | 28 | struct smbios_type_intel_wifi *t = |
| 29 | (struct smbios_type_intel_wifi *)*current; |
Vladimir Serbinenko | 41f55b7 | 2014-10-31 09:10:16 +0100 | [diff] [blame] | 30 | int len = sizeof(struct smbios_type_intel_wifi); |
| 31 | |
| 32 | memset(t, 0, sizeof(struct smbios_type_intel_wifi)); |
| 33 | t->type = 0x85; |
| 34 | t->length = len - 2; |
| 35 | t->handle = *handle; |
Duncan Laurie | 5c02644 | 2016-05-11 14:05:07 -0700 | [diff] [blame] | 36 | /* |
| 37 | * Intel wifi driver expects this string to be in the table 0x85 |
| 38 | * with PCI IDs enumerated below. |
Vladimir Serbinenko | 41f55b7 | 2014-10-31 09:10:16 +0100 | [diff] [blame] | 39 | */ |
| 40 | t->str = smbios_add_string(t->eos, "KHOIHGIUCCHHII"); |
| 41 | |
| 42 | len = t->length + smbios_string_table_len(t->eos); |
| 43 | *current += len; |
| 44 | *handle += 1; |
| 45 | return len; |
| 46 | } |
Kyösti Mälkki | 828e73e | 2016-07-28 17:26:39 +0300 | [diff] [blame] | 47 | #endif |
Vladimir Serbinenko | 41f55b7 | 2014-10-31 09:10:16 +0100 | [diff] [blame] | 48 | |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 49 | #if CONFIG(HAVE_ACPI_TABLES) |
Furquan Shaikh | 7536a39 | 2020-04-24 21:59:21 -0700 | [diff] [blame] | 50 | static void intel_wifi_fill_ssdt(const struct device *dev) |
Duncan Laurie | 5c02644 | 2016-05-11 14:05:07 -0700 | [diff] [blame] | 51 | { |
| 52 | struct drivers_intel_wifi_config *config = dev->chip_info; |
Karthikeyan Ramasubramanian | fd5d788 | 2019-05-29 15:09:42 -0600 | [diff] [blame] | 53 | struct generic_wifi_config generic_config; |
Duncan Laurie | 5c02644 | 2016-05-11 14:05:07 -0700 | [diff] [blame] | 54 | |
Karthikeyan Ramasubramanian | fd5d788 | 2019-05-29 15:09:42 -0600 | [diff] [blame] | 55 | if (config) { |
| 56 | generic_config.wake = config->wake; |
| 57 | /* By default, all intel wifi chips wake from S3 */ |
| 58 | generic_config.maxsleep = 3; |
Duncan Laurie | 5c02644 | 2016-05-11 14:05:07 -0700 | [diff] [blame] | 59 | } |
Karthikeyan Ramasubramanian | fd5d788 | 2019-05-29 15:09:42 -0600 | [diff] [blame] | 60 | generic_wifi_fill_ssdt(dev, config ? &generic_config : NULL); |
Duncan Laurie | 5c02644 | 2016-05-11 14:05:07 -0700 | [diff] [blame] | 61 | } |
| 62 | #endif |
| 63 | |
Naresh G Solanki | 3c6377f | 2017-07-03 21:57:11 +0530 | [diff] [blame] | 64 | static void wifi_pci_dev_init(struct device *dev) |
| 65 | { |
| 66 | pci_dev_init(dev); |
| 67 | |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 68 | if (CONFIG(ELOG)) { |
Naresh G Solanki | 3c6377f | 2017-07-03 21:57:11 +0530 | [diff] [blame] | 69 | uint32_t val; |
| 70 | val = pci_read_config16(dev, PMCS_DR); |
| 71 | if (val & PME_STS) |
| 72 | elog_add_event_wake(ELOG_WAKE_SOURCE_PME_WIFI, 0); |
Elyes HAOUAS | 88607a4 | 2018-10-05 10:36:45 +0200 | [diff] [blame] | 73 | } |
Naresh G Solanki | 3c6377f | 2017-07-03 21:57:11 +0530 | [diff] [blame] | 74 | } |
| 75 | |
Vladimir Serbinenko | 41f55b7 | 2014-10-31 09:10:16 +0100 | [diff] [blame] | 76 | struct device_operations device_ops = { |
Nico Huber | 68680dd | 2020-03-31 17:34:52 +0200 | [diff] [blame] | 77 | .read_resources = pci_dev_read_resources, |
| 78 | .set_resources = pci_dev_set_resources, |
| 79 | .enable_resources = pci_dev_enable_resources, |
| 80 | .init = wifi_pci_dev_init, |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 81 | #if CONFIG(GENERATE_SMBIOS_TABLES) |
Nico Huber | 68680dd | 2020-03-31 17:34:52 +0200 | [diff] [blame] | 82 | .get_smbios_data = smbios_write_wifi, |
Kyösti Mälkki | 828e73e | 2016-07-28 17:26:39 +0300 | [diff] [blame] | 83 | #endif |
Angel Pons | 1fc0edd | 2020-05-31 00:03:28 +0200 | [diff] [blame^] | 84 | .ops_pci = &pci_dev_ops_pci, |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 85 | #if CONFIG(HAVE_ACPI_TABLES) |
Nico Huber | 68680dd | 2020-03-31 17:34:52 +0200 | [diff] [blame] | 86 | .acpi_name = generic_wifi_acpi_name, |
| 87 | .acpi_fill_ssdt = intel_wifi_fill_ssdt, |
Duncan Laurie | 5c02644 | 2016-05-11 14:05:07 -0700 | [diff] [blame] | 88 | #endif |
Vladimir Serbinenko | 41f55b7 | 2014-10-31 09:10:16 +0100 | [diff] [blame] | 89 | }; |
| 90 | |
Vladimir Serbinenko | 41f55b7 | 2014-10-31 09:10:16 +0100 | [diff] [blame] | 91 | static const unsigned short pci_device_ids[] = { |
Subrata Banik | f952983 | 2018-03-22 05:25:45 +0530 | [diff] [blame] | 92 | PCI_DEVICE_ID_1000_SERIES_WIFI, |
| 93 | PCI_DEVICE_ID_6005_SERIES_WIFI, |
| 94 | PCI_DEVICE_ID_6005_I_SERIES_WIFI, |
| 95 | PCI_DEVICE_ID_1030_SERIES_WIFI, |
| 96 | PCI_DEVICE_ID_6030_I_SERIES_WIFI, |
| 97 | PCI_DEVICE_ID_6030_SERIES_WIFI, |
| 98 | PCI_DEVICE_ID_6150_SERIES_WIFI, |
| 99 | PCI_DEVICE_ID_2030_SERIES_WIFI, |
| 100 | PCI_DEVICE_ID_2000_SERIES_WIFI, |
| 101 | PCI_DEVICE_ID_0135_SERIES_WIFI, |
| 102 | PCI_DEVICE_ID_0105_SERIES_WIFI, |
| 103 | PCI_DEVICE_ID_6035_SERIES_WIFI, |
| 104 | PCI_DEVICE_ID_5300_SERIES_WIFI, |
| 105 | PCI_DEVICE_ID_5100_SERIES_WIFI, |
| 106 | PCI_DEVICE_ID_6000_SERIES_WIFI, |
| 107 | PCI_DEVICE_ID_6000_I_SERIES_WIFI, |
| 108 | PCI_DEVICE_ID_5350_SERIES_WIFI, |
| 109 | PCI_DEVICE_ID_5150_SERIES_WIFI, |
| 110 | /* Wilkins Peak 2 */ |
| 111 | PCI_DEVICE_ID_WP_7260_SERIES_1_WIFI, |
| 112 | PCI_DEVICE_ID_WP_7260_SERIES_2_WIFI, |
| 113 | /* Stone Peak 2 */ |
| 114 | PCI_DEVICE_ID_SP_7265_SERIES_1_WIFI, |
| 115 | PCI_DEVICE_ID_SP_7265_SERIES_2_WIFI, |
Subrata Banik | 4530af2 | 2018-09-28 22:43:10 +0530 | [diff] [blame] | 116 | /* Stone Field Peak */ |
| 117 | PCI_DEVICE_ID_SFP_8260_SERIES_1_WIFI, |
| 118 | PCI_DEVICE_ID_SFP_8260_SERIES_2_WIFI, |
| 119 | /* Windstorm Peak */ |
| 120 | PCI_DEVICE_ID_WSP_8275_SERIES_1_WIFI, |
Subrata Banik | f952983 | 2018-03-22 05:25:45 +0530 | [diff] [blame] | 121 | /* Jefferson Peak */ |
| 122 | PCI_DEVICE_ID_JP_9000_SERIES_1_WIFI, |
| 123 | PCI_DEVICE_ID_JP_9000_SERIES_2_WIFI, |
| 124 | PCI_DEVICE_ID_JP_9000_SERIES_3_WIFI, |
Furquan Shaikh | 39130a4 | 2018-05-30 19:57:14 -0700 | [diff] [blame] | 125 | /* Thunder Peak 2 */ |
| 126 | PCI_DEVICE_ID_TP_9260_SERIES_WIFI, |
Subrata Banik | f952983 | 2018-03-22 05:25:45 +0530 | [diff] [blame] | 127 | /* Harrison Peak */ |
| 128 | PCI_DEVICE_ID_HrP_9560_SERIES_1_WIFI, |
| 129 | PCI_DEVICE_ID_HrP_9560_SERIES_2_WIFI, |
Subrata Banik | 71da5fe | 2019-02-19 12:11:26 +0530 | [diff] [blame] | 130 | PCI_DEVICE_ID_HrP_9560_SERIES_3_WIFI, |
Subrata Banik | 13f5360 | 2019-03-28 10:35:30 +0530 | [diff] [blame] | 131 | PCI_DEVICE_ID_HrP_9560_SERIES_4_WIFI, |
Subrata Banik | b98c896 | 2020-04-06 12:08:01 +0530 | [diff] [blame] | 132 | PCI_DEVICE_ID_HrP_6SERIES_WIFI, |
| 133 | /* Cyclone Peak */ |
| 134 | PCI_DEVICE_ID_CyP_6SERIES_WIFI, |
| 135 | /* Typhoon Peak */ |
| 136 | PCI_DEVICE_ID_TyP_6SERIES_WIFI, |
| 137 | /* Garfiled Peak */ |
| 138 | PCI_DEVICE_ID_GrP_6SERIES_1_WIFI, |
| 139 | PCI_DEVICE_ID_GrP_6SERIES_2_WIFI, |
Duncan Laurie | 5c02644 | 2016-05-11 14:05:07 -0700 | [diff] [blame] | 140 | 0 |
| 141 | }; |
Vladimir Serbinenko | 41f55b7 | 2014-10-31 09:10:16 +0100 | [diff] [blame] | 142 | |
| 143 | static const struct pci_driver pch_intel_wifi __pci_driver = { |
| 144 | .ops = &device_ops, |
| 145 | .vendor = PCI_VENDOR_ID_INTEL, |
| 146 | .devices = pci_device_ids, |
| 147 | }; |
Duncan Laurie | 5c02644 | 2016-05-11 14:05:07 -0700 | [diff] [blame] | 148 | |
| 149 | static void intel_wifi_enable(struct device *dev) |
| 150 | { |
| 151 | dev->ops = &device_ops; |
| 152 | } |
| 153 | |
| 154 | struct chip_operations drivers_intel_wifi_ops = { |
| 155 | CHIP_NAME("Intel WiFi") |
Elyes HAOUAS | 2aa3b16 | 2018-11-27 17:02:10 +0100 | [diff] [blame] | 156 | .enable_dev = intel_wifi_enable |
Duncan Laurie | 5c02644 | 2016-05-11 14:05:07 -0700 | [diff] [blame] | 157 | }; |