2 * Copyright (c) 2012-2014 Qualcomm Atheros, Inc.
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.
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.
17 #include <linux/module.h>
18 #include <linux/pci.h>
19 #include <linux/moduleparam.h>
20 #include <linux/interrupt.h>
24 static int use_msi = 1;
25 module_param(use_msi, int, S_IRUGO);
26 MODULE_PARM_DESC(use_msi,
27 " Use MSI interrupt: "
28 "0 - don't, 1 - (default) - single, or 3");
30 static bool debug_fw; /* = false; */
31 module_param(debug_fw, bool, S_IRUGO);
32 MODULE_PARM_DESC(debug_fw, " load driver if FW not ready. For FW debug");
35 void wil_set_capabilities(struct wil6210_priv *wil)
37 u32 rev_id = ioread32(wil->csr + HOSTADDR(RGF_USER_JTAG_DEV_ID));
39 bitmap_zero(wil->hw_capabilities, hw_capability_last);
42 case JTAG_DEV_ID_SPARROW_B0:
43 wil->hw_name = "Sparrow B0";
44 wil->hw_version = HW_VER_SPARROW_B0;
47 wil_err(wil, "Unknown board hardware 0x%08x\n", rev_id);
48 wil->hw_name = "Unknown";
49 wil->hw_version = HW_VER_UNKNOWN;
52 wil_info(wil, "Board hardware is %s\n", wil->hw_name);
55 void wil_disable_irq(struct wil6210_priv *wil)
57 int irq = wil->pdev->irq;
60 if (wil->n_msi == 3) {
66 void wil_enable_irq(struct wil6210_priv *wil)
68 int irq = wil->pdev->irq;
71 if (wil->n_msi == 3) {
78 static int wil_if_pcie_enable(struct wil6210_priv *wil)
80 struct pci_dev *pdev = wil->pdev;
82 /* on platforms with buggy ACPI, pdev->msi_enabled may be set to
83 * allow pci_enable_device to work. This indicates INTx was not routed
84 * and only MSI should be used
86 int msi_only = pdev->msi_enabled;
88 wil_dbg_misc(wil, "%s()\n", __func__);
90 pdev->msi_enabled = 0;
95 * how many MSI interrupts to request?
100 wil_dbg_misc(wil, "Setup %d MSI interrupts\n", use_msi);
103 wil_dbg_misc(wil, "MSI interrupts disabled, use INTx\n");
106 wil_err(wil, "Invalid use_msi=%d, default to 1\n", use_msi);
110 if (use_msi == 3 && pci_enable_msi_range(pdev, 3, 3) < 0) {
111 wil_err(wil, "3 MSI mode failed, try 1 MSI\n");
115 if (use_msi == 1 && pci_enable_msi(pdev)) {
116 wil_err(wil, "pci_enable_msi failed, use INTx\n");
120 wil->n_msi = use_msi;
122 if ((wil->n_msi == 0) && msi_only) {
123 wil_err(wil, "Interrupt pin not routed, unable to use INTx\n");
128 rc = wil6210_init_irq(wil, pdev->irq);
132 /* need reset here to obtain MAC */
133 mutex_lock(&wil->mutex);
134 rc = wil_reset(wil, false);
135 mutex_unlock(&wil->mutex);
144 wil6210_fini_irq(wil, pdev->irq);
145 /* safe to call if no MSI */
146 pci_disable_msi(pdev);
148 pci_clear_master(pdev);
152 static int wil_if_pcie_disable(struct wil6210_priv *wil)
154 struct pci_dev *pdev = wil->pdev;
156 wil_dbg_misc(wil, "%s()\n", __func__);
158 pci_clear_master(pdev);
159 /* disable and release IRQ */
160 wil6210_fini_irq(wil, pdev->irq);
161 /* safe to call if no MSI */
162 pci_disable_msi(pdev);
163 /* TODO: disable HW */
168 static int wil_pcie_probe(struct pci_dev *pdev, const struct pci_device_id *id)
170 struct wil6210_priv *wil;
171 struct device *dev = &pdev->dev;
176 dev_info(&pdev->dev, WIL_NAME
177 " device found [%04x:%04x] (rev %x)\n",
178 (int)pdev->vendor, (int)pdev->device, (int)pdev->revision);
180 if (pci_resource_len(pdev, 0) != WIL6210_MEM_SIZE) {
181 dev_err(&pdev->dev, "Not " WIL_NAME "? "
182 "BAR0 size is %lu while expecting %lu\n",
183 (ulong)pci_resource_len(pdev, 0), WIL6210_MEM_SIZE);
187 rc = pci_enable_device(pdev);
190 "pci_enable_device failed, retry with MSI only\n");
191 /* Work around for platforms that can't allocate IRQ:
192 * retry with MSI only
194 pdev->msi_enabled = 1;
195 rc = pci_enable_device(pdev);
199 /* rollback to err_disable_pdev */
201 rc = pci_request_region(pdev, 0, WIL_NAME);
203 dev_err(&pdev->dev, "pci_request_region failed\n");
204 goto err_disable_pdev;
206 /* rollback to err_release_reg */
208 csr = pci_ioremap_bar(pdev, 0);
210 dev_err(&pdev->dev, "pci_ioremap_bar failed\n");
212 goto err_release_reg;
214 /* rollback to err_iounmap */
215 dev_info(&pdev->dev, "CSR at %pR -> 0x%p\n", &pdev->resource[0], csr);
217 wil = wil_if_alloc(dev, csr);
219 rc = (int)PTR_ERR(wil);
220 dev_err(dev, "wil_if_alloc failed: %d\n", rc);
223 /* rollback to if_free */
225 pci_set_drvdata(pdev, wil);
227 wil_set_capabilities(wil);
228 wil6210_clear_irq(wil);
230 wil->platform_handle =
231 wil_platform_init(&pdev->dev, &wil->platform_ops);
233 /* FW should raise IRQ when ready */
234 rc = wil_if_pcie_enable(wil);
236 wil_err(wil, "Enable device failed\n");
239 /* rollback to bus_disable */
241 rc = wil_if_add(wil);
243 wil_err(wil, "wil_if_add failed: %d\n", rc);
247 wil6210_debugfs_init(wil);
253 wil_if_pcie_disable(wil);
255 if (wil->platform_ops.uninit)
256 wil->platform_ops.uninit(wil->platform_handle);
259 pci_iounmap(pdev, csr);
261 pci_release_region(pdev, 0);
263 pci_disable_device(pdev);
268 static void wil_pcie_remove(struct pci_dev *pdev)
270 struct wil6210_priv *wil = pci_get_drvdata(pdev);
271 void __iomem *csr = wil->csr;
273 wil_dbg_misc(wil, "%s()\n", __func__);
275 wil6210_debugfs_remove(wil);
277 wil_if_pcie_disable(wil);
278 if (wil->platform_ops.uninit)
279 wil->platform_ops.uninit(wil->platform_handle);
281 pci_iounmap(pdev, csr);
282 pci_release_region(pdev, 0);
283 pci_disable_device(pdev);
286 static const struct pci_device_id wil6210_pcie_ids[] = {
287 { PCI_DEVICE(0x1ae9, 0x0310) },
288 { PCI_DEVICE(0x1ae9, 0x0302) }, /* same as above, firmware broken */
289 { /* end: all zeroes */ },
291 MODULE_DEVICE_TABLE(pci, wil6210_pcie_ids);
293 static struct pci_driver wil6210_driver = {
294 .probe = wil_pcie_probe,
295 .remove = wil_pcie_remove,
296 .id_table = wil6210_pcie_ids,
300 module_pci_driver(wil6210_driver);
302 MODULE_LICENSE("Dual BSD/GPL");
303 MODULE_AUTHOR("Qualcomm Atheros <wil6210@qca.qualcomm.com>");
304 MODULE_DESCRIPTION("Driver for 60g WiFi WIL6210 card");