Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 1 | /* |
Maya Erez | e34dc64 | 2016-05-16 22:23:34 +0300 | [diff] [blame] | 2 | * Copyright (c) 2012-2016 Qualcomm Atheros, Inc. |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 3 | * |
| 4 | * Permission to use, copy, modify, and/or distribute this software for any |
| 5 | * purpose with or without fee is hereby granted, provided that the above |
| 6 | * copyright notice and this permission notice appear in all copies. |
| 7 | * |
| 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
| 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
| 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
| 11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
| 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
| 13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
| 14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
| 15 | */ |
| 16 | |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 17 | #include <linux/module.h> |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 18 | #include <linux/pci.h> |
| 19 | #include <linux/moduleparam.h> |
Vladimir Kondratiev | 73d839a | 2014-09-10 16:34:50 +0300 | [diff] [blame] | 20 | #include <linux/interrupt.h> |
Maya Erez | e34dc64 | 2016-05-16 22:23:34 +0300 | [diff] [blame] | 21 | #include <linux/suspend.h> |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 22 | #include "wil6210.h" |
| 23 | |
Vladimir Kondratiev | bd2d18b | 2015-07-30 13:52:02 +0300 | [diff] [blame] | 24 | static bool use_msi = true; |
| 25 | module_param(use_msi, bool, S_IRUGO); |
| 26 | MODULE_PARM_DESC(use_msi, " Use MSI interrupt, default - true"); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 27 | |
Maya Erez | e34dc64 | 2016-05-16 22:23:34 +0300 | [diff] [blame] | 28 | #ifdef CONFIG_PM |
| 29 | #ifdef CONFIG_PM_SLEEP |
| 30 | static int wil6210_pm_notify(struct notifier_block *notify_block, |
| 31 | unsigned long mode, void *unused); |
| 32 | #endif /* CONFIG_PM_SLEEP */ |
| 33 | #endif /* CONFIG_PM */ |
| 34 | |
Vladimir Kondratiev | d8cfb80 | 2014-12-23 09:47:17 +0200 | [diff] [blame] | 35 | static |
| 36 | void wil_set_capabilities(struct wil6210_priv *wil) |
| 37 | { |
Vladimir Kondratiev | b9eeb51 | 2015-07-30 13:52:03 +0300 | [diff] [blame] | 38 | u32 rev_id = wil_r(wil, RGF_USER_JTAG_DEV_ID); |
Vladimir Kondratiev | d8cfb80 | 2014-12-23 09:47:17 +0200 | [diff] [blame] | 39 | |
| 40 | bitmap_zero(wil->hw_capabilities, hw_capability_last); |
| 41 | |
| 42 | switch (rev_id) { |
Vladimir Kondratiev | d8cfb80 | 2014-12-23 09:47:17 +0200 | [diff] [blame] | 43 | case JTAG_DEV_ID_SPARROW_B0: |
Vladimir Kondratiev | 1aeda13 | 2014-12-23 09:47:18 +0200 | [diff] [blame] | 44 | wil->hw_name = "Sparrow B0"; |
Vladimir Kondratiev | d8cfb80 | 2014-12-23 09:47:17 +0200 | [diff] [blame] | 45 | wil->hw_version = HW_VER_SPARROW_B0; |
| 46 | break; |
| 47 | default: |
| 48 | wil_err(wil, "Unknown board hardware 0x%08x\n", rev_id); |
Vladimir Kondratiev | 1aeda13 | 2014-12-23 09:47:18 +0200 | [diff] [blame] | 49 | wil->hw_name = "Unknown"; |
Vladimir Kondratiev | d8cfb80 | 2014-12-23 09:47:17 +0200 | [diff] [blame] | 50 | wil->hw_version = HW_VER_UNKNOWN; |
| 51 | } |
Vladimir Kondratiev | 1aeda13 | 2014-12-23 09:47:18 +0200 | [diff] [blame] | 52 | |
| 53 | wil_info(wil, "Board hardware is %s\n", wil->hw_name); |
Vladimir Kondratiev | d8cfb80 | 2014-12-23 09:47:17 +0200 | [diff] [blame] | 54 | } |
| 55 | |
Vladimir Kondratiev | 73d839a | 2014-09-10 16:34:50 +0300 | [diff] [blame] | 56 | void wil_disable_irq(struct wil6210_priv *wil) |
| 57 | { |
Vladimir Kondratiev | bd2d18b | 2015-07-30 13:52:02 +0300 | [diff] [blame] | 58 | disable_irq(wil->pdev->irq); |
Vladimir Kondratiev | 73d839a | 2014-09-10 16:34:50 +0300 | [diff] [blame] | 59 | } |
| 60 | |
| 61 | void wil_enable_irq(struct wil6210_priv *wil) |
| 62 | { |
Vladimir Kondratiev | bd2d18b | 2015-07-30 13:52:02 +0300 | [diff] [blame] | 63 | enable_irq(wil->pdev->irq); |
Vladimir Kondratiev | 73d839a | 2014-09-10 16:34:50 +0300 | [diff] [blame] | 64 | } |
| 65 | |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 66 | /* Bus ops */ |
| 67 | static int wil_if_pcie_enable(struct wil6210_priv *wil) |
| 68 | { |
| 69 | struct pci_dev *pdev = wil->pdev; |
| 70 | int rc; |
Vladimir Kondratiev | 2bdc070 | 2014-06-16 19:37:20 +0300 | [diff] [blame] | 71 | /* on platforms with buggy ACPI, pdev->msi_enabled may be set to |
| 72 | * allow pci_enable_device to work. This indicates INTx was not routed |
| 73 | * and only MSI should be used |
| 74 | */ |
| 75 | int msi_only = pdev->msi_enabled; |
Vladimir Kondratiev | bd2d18b | 2015-07-30 13:52:02 +0300 | [diff] [blame] | 76 | bool _use_msi = use_msi; |
Vladimir Kondratiev | 2bdc070 | 2014-06-16 19:37:20 +0300 | [diff] [blame] | 77 | |
Vladimir Kondratiev | 9cf10d6 | 2014-09-10 16:34:36 +0300 | [diff] [blame] | 78 | wil_dbg_misc(wil, "%s()\n", __func__); |
| 79 | |
Vladimir Kondratiev | 2bdc070 | 2014-06-16 19:37:20 +0300 | [diff] [blame] | 80 | pdev->msi_enabled = 0; |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 81 | |
| 82 | pci_set_master(pdev); |
| 83 | |
Vladimir Kondratiev | bd2d18b | 2015-07-30 13:52:02 +0300 | [diff] [blame] | 84 | wil_dbg_misc(wil, "Setup %s interrupt\n", use_msi ? "MSI" : "INTx"); |
Alexander Gordeev | b4b3906 | 2014-02-18 11:12:04 +0100 | [diff] [blame] | 85 | |
Vladimir Kondratiev | bd2d18b | 2015-07-30 13:52:02 +0300 | [diff] [blame] | 86 | if (use_msi && pci_enable_msi(pdev)) { |
Alexander Gordeev | b4b3906 | 2014-02-18 11:12:04 +0100 | [diff] [blame] | 87 | wil_err(wil, "pci_enable_msi failed, use INTx\n"); |
Vladimir Kondratiev | bd2d18b | 2015-07-30 13:52:02 +0300 | [diff] [blame] | 88 | _use_msi = false; |
Alexander Gordeev | b4b3906 | 2014-02-18 11:12:04 +0100 | [diff] [blame] | 89 | } |
| 90 | |
Vladimir Kondratiev | bd2d18b | 2015-07-30 13:52:02 +0300 | [diff] [blame] | 91 | if (!_use_msi && msi_only) { |
Vladimir Kondratiev | 2bdc070 | 2014-06-16 19:37:20 +0300 | [diff] [blame] | 92 | wil_err(wil, "Interrupt pin not routed, unable to use INTx\n"); |
| 93 | rc = -ENODEV; |
| 94 | goto stop_master; |
| 95 | } |
| 96 | |
Vladimir Kondratiev | bd2d18b | 2015-07-30 13:52:02 +0300 | [diff] [blame] | 97 | rc = wil6210_init_irq(wil, pdev->irq, _use_msi); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 98 | if (rc) |
| 99 | goto stop_master; |
| 100 | |
| 101 | /* need reset here to obtain MAC */ |
Vladimir Kondratiev | 097638a | 2014-03-17 15:34:25 +0200 | [diff] [blame] | 102 | mutex_lock(&wil->mutex); |
Vladimir Kondratiev | 2cd0f02 | 2015-02-15 14:02:30 +0200 | [diff] [blame] | 103 | rc = wil_reset(wil, false); |
Vladimir Kondratiev | 097638a | 2014-03-17 15:34:25 +0200 | [diff] [blame] | 104 | mutex_unlock(&wil->mutex); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 105 | if (rc) |
| 106 | goto release_irq; |
| 107 | |
| 108 | return 0; |
| 109 | |
| 110 | release_irq: |
| 111 | wil6210_fini_irq(wil, pdev->irq); |
| 112 | /* safe to call if no MSI */ |
| 113 | pci_disable_msi(pdev); |
| 114 | stop_master: |
| 115 | pci_clear_master(pdev); |
| 116 | return rc; |
| 117 | } |
| 118 | |
| 119 | static int wil_if_pcie_disable(struct wil6210_priv *wil) |
| 120 | { |
| 121 | struct pci_dev *pdev = wil->pdev; |
| 122 | |
Vladimir Kondratiev | 9cf10d6 | 2014-09-10 16:34:36 +0300 | [diff] [blame] | 123 | wil_dbg_misc(wil, "%s()\n", __func__); |
| 124 | |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 125 | pci_clear_master(pdev); |
| 126 | /* disable and release IRQ */ |
| 127 | wil6210_fini_irq(wil, pdev->irq); |
| 128 | /* safe to call if no MSI */ |
| 129 | pci_disable_msi(pdev); |
| 130 | /* TODO: disable HW */ |
| 131 | |
| 132 | return 0; |
| 133 | } |
| 134 | |
Lior David | ea3ade7 | 2015-12-16 17:51:46 +0200 | [diff] [blame] | 135 | static int wil_platform_rop_ramdump(void *wil_handle, void *buf, uint32_t size) |
| 136 | { |
| 137 | struct wil6210_priv *wil = wil_handle; |
| 138 | |
| 139 | if (!wil) |
| 140 | return -EINVAL; |
| 141 | |
| 142 | return wil_fw_copy_crash_dump(wil, buf, size); |
| 143 | } |
| 144 | |
| 145 | static int wil_platform_rop_fw_recovery(void *wil_handle) |
| 146 | { |
| 147 | struct wil6210_priv *wil = wil_handle; |
| 148 | |
| 149 | if (!wil) |
| 150 | return -EINVAL; |
| 151 | |
| 152 | wil_fw_error_recovery(wil); |
| 153 | |
| 154 | return 0; |
| 155 | } |
| 156 | |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 157 | static int wil_pcie_probe(struct pci_dev *pdev, const struct pci_device_id *id) |
| 158 | { |
| 159 | struct wil6210_priv *wil; |
| 160 | struct device *dev = &pdev->dev; |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 161 | int rc; |
Lior David | ea3ade7 | 2015-12-16 17:51:46 +0200 | [diff] [blame] | 162 | const struct wil_platform_rops rops = { |
| 163 | .ramdump = wil_platform_rop_ramdump, |
| 164 | .fw_recovery = wil_platform_rop_fw_recovery, |
| 165 | }; |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 166 | |
| 167 | /* check HW */ |
Vladimir Kondratiev | 6508281 | 2014-07-14 09:49:37 +0300 | [diff] [blame] | 168 | dev_info(&pdev->dev, WIL_NAME |
Vladimir Kondratiev | 1aeda13 | 2014-12-23 09:47:18 +0200 | [diff] [blame] | 169 | " device found [%04x:%04x] (rev %x)\n", |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 170 | (int)pdev->vendor, (int)pdev->device, (int)pdev->revision); |
| 171 | |
| 172 | if (pci_resource_len(pdev, 0) != WIL6210_MEM_SIZE) { |
| 173 | dev_err(&pdev->dev, "Not " WIL_NAME "? " |
| 174 | "BAR0 size is %lu while expecting %lu\n", |
| 175 | (ulong)pci_resource_len(pdev, 0), WIL6210_MEM_SIZE); |
| 176 | return -ENODEV; |
| 177 | } |
| 178 | |
Vladimir Kondratiev | 3e2d8e1 | 2015-06-09 14:11:19 +0300 | [diff] [blame] | 179 | wil = wil_if_alloc(dev); |
| 180 | if (IS_ERR(wil)) { |
| 181 | rc = (int)PTR_ERR(wil); |
| 182 | dev_err(dev, "wil_if_alloc failed: %d\n", rc); |
| 183 | return rc; |
| 184 | } |
| 185 | wil->pdev = pdev; |
| 186 | pci_set_drvdata(pdev, wil); |
| 187 | /* rollback to if_free */ |
| 188 | |
| 189 | wil->platform_handle = |
Lior David | ea3ade7 | 2015-12-16 17:51:46 +0200 | [diff] [blame] | 190 | wil_platform_init(&pdev->dev, &wil->platform_ops, &rops, wil); |
Vladimir Kondratiev | 3e2d8e1 | 2015-06-09 14:11:19 +0300 | [diff] [blame] | 191 | if (!wil->platform_handle) { |
| 192 | rc = -ENODEV; |
| 193 | wil_err(wil, "wil_platform_init failed\n"); |
| 194 | goto if_free; |
| 195 | } |
| 196 | /* rollback to err_plat */ |
| 197 | |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 198 | rc = pci_enable_device(pdev); |
| 199 | if (rc) { |
Vladimir Kondratiev | 3e2d8e1 | 2015-06-09 14:11:19 +0300 | [diff] [blame] | 200 | wil_err(wil, |
Vladimir Kondratiev | 2bdc070 | 2014-06-16 19:37:20 +0300 | [diff] [blame] | 201 | "pci_enable_device failed, retry with MSI only\n"); |
| 202 | /* Work around for platforms that can't allocate IRQ: |
| 203 | * retry with MSI only |
| 204 | */ |
| 205 | pdev->msi_enabled = 1; |
| 206 | rc = pci_enable_device(pdev); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 207 | } |
Vladimir Kondratiev | 3e2d8e1 | 2015-06-09 14:11:19 +0300 | [diff] [blame] | 208 | if (rc) { |
| 209 | wil_err(wil, |
| 210 | "pci_enable_device failed, even with MSI only\n"); |
| 211 | goto err_plat; |
| 212 | } |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 213 | /* rollback to err_disable_pdev */ |
| 214 | |
| 215 | rc = pci_request_region(pdev, 0, WIL_NAME); |
| 216 | if (rc) { |
Vladimir Kondratiev | 3e2d8e1 | 2015-06-09 14:11:19 +0300 | [diff] [blame] | 217 | wil_err(wil, "pci_request_region failed\n"); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 218 | goto err_disable_pdev; |
| 219 | } |
| 220 | /* rollback to err_release_reg */ |
| 221 | |
Vladimir Kondratiev | 3e2d8e1 | 2015-06-09 14:11:19 +0300 | [diff] [blame] | 222 | wil->csr = pci_ioremap_bar(pdev, 0); |
| 223 | if (!wil->csr) { |
| 224 | wil_err(wil, "pci_ioremap_bar failed\n"); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 225 | rc = -ENODEV; |
| 226 | goto err_release_reg; |
| 227 | } |
| 228 | /* rollback to err_iounmap */ |
Vladimir Kondratiev | 3e2d8e1 | 2015-06-09 14:11:19 +0300 | [diff] [blame] | 229 | wil_info(wil, "CSR at %pR -> 0x%p\n", &pdev->resource[0], wil->csr); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 230 | |
Vladimir Kondratiev | d8cfb80 | 2014-12-23 09:47:17 +0200 | [diff] [blame] | 231 | wil_set_capabilities(wil); |
Vladimir Kondratiev | f4b5a80 | 2014-03-17 15:34:13 +0200 | [diff] [blame] | 232 | wil6210_clear_irq(wil); |
Vladimir Kondratiev | f772ebf | 2014-09-10 16:34:35 +0300 | [diff] [blame] | 233 | |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 234 | /* FW should raise IRQ when ready */ |
| 235 | rc = wil_if_pcie_enable(wil); |
| 236 | if (rc) { |
| 237 | wil_err(wil, "Enable device failed\n"); |
Vladimir Kondratiev | 3e2d8e1 | 2015-06-09 14:11:19 +0300 | [diff] [blame] | 238 | goto err_iounmap; |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 239 | } |
| 240 | /* rollback to bus_disable */ |
| 241 | |
| 242 | rc = wil_if_add(wil); |
| 243 | if (rc) { |
| 244 | wil_err(wil, "wil_if_add failed: %d\n", rc); |
| 245 | goto bus_disable; |
| 246 | } |
| 247 | |
Maya Erez | e34dc64 | 2016-05-16 22:23:34 +0300 | [diff] [blame] | 248 | #ifdef CONFIG_PM |
| 249 | #ifdef CONFIG_PM_SLEEP |
| 250 | wil->pm_notify.notifier_call = wil6210_pm_notify; |
| 251 | rc = register_pm_notifier(&wil->pm_notify); |
| 252 | if (rc) |
| 253 | /* Do not fail the driver initialization, as suspend can |
| 254 | * be prevented in a later phase if needed |
| 255 | */ |
| 256 | wil_err(wil, "register_pm_notifier failed: %d\n", rc); |
| 257 | #endif /* CONFIG_PM_SLEEP */ |
| 258 | #endif /* CONFIG_PM */ |
| 259 | |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 260 | wil6210_debugfs_init(wil); |
| 261 | |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 262 | |
| 263 | return 0; |
| 264 | |
Vladimir Kondratiev | 3e2d8e1 | 2015-06-09 14:11:19 +0300 | [diff] [blame] | 265 | bus_disable: |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 266 | wil_if_pcie_disable(wil); |
Vladimir Kondratiev | 3e2d8e1 | 2015-06-09 14:11:19 +0300 | [diff] [blame] | 267 | err_iounmap: |
| 268 | pci_iounmap(pdev, wil->csr); |
| 269 | err_release_reg: |
| 270 | pci_release_region(pdev, 0); |
| 271 | err_disable_pdev: |
| 272 | pci_disable_device(pdev); |
| 273 | err_plat: |
Vladimir Kondratiev | f772ebf | 2014-09-10 16:34:35 +0300 | [diff] [blame] | 274 | if (wil->platform_ops.uninit) |
| 275 | wil->platform_ops.uninit(wil->platform_handle); |
Vladimir Kondratiev | 3e2d8e1 | 2015-06-09 14:11:19 +0300 | [diff] [blame] | 276 | if_free: |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 277 | wil_if_free(wil); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 278 | |
| 279 | return rc; |
| 280 | } |
| 281 | |
| 282 | static void wil_pcie_remove(struct pci_dev *pdev) |
| 283 | { |
| 284 | struct wil6210_priv *wil = pci_get_drvdata(pdev); |
Vladimir Kondratiev | 560ce30 | 2014-08-06 10:32:01 +0300 | [diff] [blame] | 285 | void __iomem *csr = wil->csr; |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 286 | |
Vladimir Kondratiev | 9cf10d6 | 2014-09-10 16:34:36 +0300 | [diff] [blame] | 287 | wil_dbg_misc(wil, "%s()\n", __func__); |
| 288 | |
Maya Erez | e34dc64 | 2016-05-16 22:23:34 +0300 | [diff] [blame] | 289 | #ifdef CONFIG_PM |
| 290 | #ifdef CONFIG_PM_SLEEP |
| 291 | unregister_pm_notifier(&wil->pm_notify); |
| 292 | #endif /* CONFIG_PM_SLEEP */ |
| 293 | #endif /* CONFIG_PM */ |
| 294 | |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 295 | wil6210_debugfs_remove(wil); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 296 | wil_if_remove(wil); |
Dedy Lansky | f172b56 | 2014-09-10 16:34:38 +0300 | [diff] [blame] | 297 | wil_if_pcie_disable(wil); |
Vladimir Kondratiev | 560ce30 | 2014-08-06 10:32:01 +0300 | [diff] [blame] | 298 | pci_iounmap(pdev, csr); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 299 | pci_release_region(pdev, 0); |
| 300 | pci_disable_device(pdev); |
Vladimir Kondratiev | 3e2d8e1 | 2015-06-09 14:11:19 +0300 | [diff] [blame] | 301 | if (wil->platform_ops.uninit) |
| 302 | wil->platform_ops.uninit(wil->platform_handle); |
Lior David | 4332cac | 2016-03-01 19:18:13 +0200 | [diff] [blame] | 303 | wil_p2p_wdev_free(wil); |
Vladimir Kondratiev | 3e2d8e1 | 2015-06-09 14:11:19 +0300 | [diff] [blame] | 304 | wil_if_free(wil); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 305 | } |
| 306 | |
Vladimir Kondratiev | 6508281 | 2014-07-14 09:49:37 +0300 | [diff] [blame] | 307 | static const struct pci_device_id wil6210_pcie_ids[] = { |
Vladimir Kondratiev | 1aeda13 | 2014-12-23 09:47:18 +0200 | [diff] [blame] | 308 | { PCI_DEVICE(0x1ae9, 0x0310) }, |
| 309 | { PCI_DEVICE(0x1ae9, 0x0302) }, /* same as above, firmware broken */ |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 310 | { /* end: all zeroes */ }, |
| 311 | }; |
| 312 | MODULE_DEVICE_TABLE(pci, wil6210_pcie_ids); |
| 313 | |
Vladimir Kondratiev | 93cb679 | 2015-07-30 13:52:05 +0300 | [diff] [blame] | 314 | #ifdef CONFIG_PM |
Vladimir Kondratiev | 5a813da | 2015-10-04 10:23:18 +0300 | [diff] [blame] | 315 | #ifdef CONFIG_PM_SLEEP |
Vladimir Kondratiev | 93cb679 | 2015-07-30 13:52:05 +0300 | [diff] [blame] | 316 | |
| 317 | static int wil6210_suspend(struct device *dev, bool is_runtime) |
| 318 | { |
| 319 | int rc = 0; |
| 320 | struct pci_dev *pdev = to_pci_dev(dev); |
| 321 | struct wil6210_priv *wil = pci_get_drvdata(pdev); |
| 322 | |
| 323 | wil_dbg_pm(wil, "%s(%s)\n", __func__, |
| 324 | is_runtime ? "runtime" : "system"); |
| 325 | |
| 326 | rc = wil_can_suspend(wil, is_runtime); |
| 327 | if (rc) |
| 328 | goto out; |
| 329 | |
| 330 | rc = wil_suspend(wil, is_runtime); |
| 331 | if (rc) |
| 332 | goto out; |
| 333 | |
| 334 | /* TODO: how do I bring card in low power state? */ |
| 335 | |
| 336 | /* disable bus mastering */ |
| 337 | pci_clear_master(pdev); |
| 338 | /* PCI will call pci_save_state(pdev) and pci_prepare_to_sleep(pdev) */ |
| 339 | |
| 340 | out: |
| 341 | return rc; |
| 342 | } |
| 343 | |
| 344 | static int wil6210_resume(struct device *dev, bool is_runtime) |
| 345 | { |
| 346 | int rc = 0; |
| 347 | struct pci_dev *pdev = to_pci_dev(dev); |
| 348 | struct wil6210_priv *wil = pci_get_drvdata(pdev); |
| 349 | |
| 350 | wil_dbg_pm(wil, "%s(%s)\n", __func__, |
| 351 | is_runtime ? "runtime" : "system"); |
| 352 | |
| 353 | /* allow master */ |
| 354 | pci_set_master(pdev); |
| 355 | |
| 356 | rc = wil_resume(wil, is_runtime); |
| 357 | if (rc) |
| 358 | pci_clear_master(pdev); |
| 359 | |
| 360 | return rc; |
| 361 | } |
| 362 | |
Maya Erez | e34dc64 | 2016-05-16 22:23:34 +0300 | [diff] [blame] | 363 | static int wil6210_pm_notify(struct notifier_block *notify_block, |
| 364 | unsigned long mode, void *unused) |
| 365 | { |
| 366 | struct wil6210_priv *wil = container_of( |
| 367 | notify_block, struct wil6210_priv, pm_notify); |
| 368 | int rc = 0; |
| 369 | enum wil_platform_event evt; |
| 370 | |
| 371 | wil_dbg_pm(wil, "%s: mode (%ld)\n", __func__, mode); |
| 372 | |
| 373 | switch (mode) { |
| 374 | case PM_HIBERNATION_PREPARE: |
| 375 | case PM_SUSPEND_PREPARE: |
| 376 | case PM_RESTORE_PREPARE: |
| 377 | rc = wil_can_suspend(wil, false); |
| 378 | if (rc) |
| 379 | break; |
| 380 | evt = WIL_PLATFORM_EVT_PRE_SUSPEND; |
| 381 | if (wil->platform_ops.notify) |
| 382 | rc = wil->platform_ops.notify(wil->platform_handle, |
| 383 | evt); |
| 384 | break; |
| 385 | case PM_POST_SUSPEND: |
| 386 | case PM_POST_HIBERNATION: |
| 387 | case PM_POST_RESTORE: |
| 388 | evt = WIL_PLATFORM_EVT_POST_SUSPEND; |
| 389 | if (wil->platform_ops.notify) |
| 390 | rc = wil->platform_ops.notify(wil->platform_handle, |
| 391 | evt); |
| 392 | break; |
| 393 | default: |
| 394 | wil_dbg_pm(wil, "unhandled notify mode %ld\n", mode); |
| 395 | break; |
| 396 | } |
| 397 | |
| 398 | wil_dbg_pm(wil, "notification mode %ld: rc (%d)\n", mode, rc); |
| 399 | return rc; |
| 400 | } |
| 401 | |
Vladimir Kondratiev | 93cb679 | 2015-07-30 13:52:05 +0300 | [diff] [blame] | 402 | static int wil6210_pm_suspend(struct device *dev) |
| 403 | { |
| 404 | return wil6210_suspend(dev, false); |
| 405 | } |
| 406 | |
| 407 | static int wil6210_pm_resume(struct device *dev) |
| 408 | { |
| 409 | return wil6210_resume(dev, false); |
| 410 | } |
| 411 | #endif /* CONFIG_PM_SLEEP */ |
| 412 | |
| 413 | #endif /* CONFIG_PM */ |
| 414 | |
| 415 | static const struct dev_pm_ops wil6210_pm_ops = { |
| 416 | SET_SYSTEM_SLEEP_PM_OPS(wil6210_pm_suspend, wil6210_pm_resume) |
| 417 | }; |
| 418 | |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 419 | static struct pci_driver wil6210_driver = { |
| 420 | .probe = wil_pcie_probe, |
| 421 | .remove = wil_pcie_remove, |
| 422 | .id_table = wil6210_pcie_ids, |
| 423 | .name = WIL_NAME, |
Vladimir Kondratiev | 93cb679 | 2015-07-30 13:52:05 +0300 | [diff] [blame] | 424 | .driver = { |
| 425 | .pm = &wil6210_pm_ops, |
| 426 | }, |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 427 | }; |
| 428 | |
Vladimir Kondratiev | b39d693 | 2015-06-09 14:11:19 +0300 | [diff] [blame] | 429 | static int __init wil6210_driver_init(void) |
| 430 | { |
| 431 | int rc; |
| 432 | |
| 433 | rc = wil_platform_modinit(); |
| 434 | if (rc) |
| 435 | return rc; |
| 436 | |
| 437 | rc = pci_register_driver(&wil6210_driver); |
| 438 | if (rc) |
| 439 | wil_platform_modexit(); |
| 440 | return rc; |
| 441 | } |
| 442 | module_init(wil6210_driver_init); |
| 443 | |
| 444 | static void __exit wil6210_driver_exit(void) |
| 445 | { |
| 446 | pci_unregister_driver(&wil6210_driver); |
| 447 | wil_platform_modexit(); |
| 448 | } |
| 449 | module_exit(wil6210_driver_exit); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 450 | |
| 451 | MODULE_LICENSE("Dual BSD/GPL"); |
| 452 | MODULE_AUTHOR("Qualcomm Atheros <wil6210@qca.qualcomm.com>"); |
| 453 | MODULE_DESCRIPTION("Driver for 60g WiFi WIL6210 card"); |