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");
34 void wil_disable_irq(struct wil6210_priv *wil)
36 int irq = wil->pdev->irq;
39 if (wil->n_msi == 3) {
45 void wil_enable_irq(struct wil6210_priv *wil)
47 int irq = wil->pdev->irq;
50 if (wil->n_msi == 3) {
57 static int wil_if_pcie_enable(struct wil6210_priv *wil)
59 struct pci_dev *pdev = wil->pdev;
61 /* on platforms with buggy ACPI, pdev->msi_enabled may be set to
62 * allow pci_enable_device to work. This indicates INTx was not routed
63 * and only MSI should be used
65 int msi_only = pdev->msi_enabled;
67 wil_dbg_misc(wil, "%s()\n", __func__);
69 pdev->msi_enabled = 0;
74 * how many MSI interrupts to request?
79 wil_dbg_misc(wil, "Setup %d MSI interrupts\n", use_msi);
82 wil_dbg_misc(wil, "MSI interrupts disabled, use INTx\n");
85 wil_err(wil, "Invalid use_msi=%d, default to 1\n", use_msi);
89 if (use_msi == 3 && pci_enable_msi_range(pdev, 3, 3) < 0) {
90 wil_err(wil, "3 MSI mode failed, try 1 MSI\n");
94 if (use_msi == 1 && pci_enable_msi(pdev)) {
95 wil_err(wil, "pci_enable_msi failed, use INTx\n");
101 if ((wil->n_msi == 0) && msi_only) {
102 wil_err(wil, "Interrupt pin not routed, unable to use INTx\n");
107 rc = wil6210_init_irq(wil, pdev->irq);
111 /* need reset here to obtain MAC */
112 mutex_lock(&wil->mutex);
114 mutex_unlock(&wil->mutex);
123 wil6210_fini_irq(wil, pdev->irq);
124 /* safe to call if no MSI */
125 pci_disable_msi(pdev);
127 pci_clear_master(pdev);
131 static int wil_if_pcie_disable(struct wil6210_priv *wil)
133 struct pci_dev *pdev = wil->pdev;
135 wil_dbg_misc(wil, "%s()\n", __func__);
137 pci_clear_master(pdev);
138 /* disable and release IRQ */
139 wil6210_fini_irq(wil, pdev->irq);
140 /* safe to call if no MSI */
141 pci_disable_msi(pdev);
142 /* TODO: disable HW */
147 static int wil_pcie_probe(struct pci_dev *pdev, const struct pci_device_id *id)
149 struct wil6210_priv *wil;
150 struct device *dev = &pdev->dev;
152 struct wil_board *board = (struct wil_board *)id->driver_data;
156 dev_info(&pdev->dev, WIL_NAME
157 " \"%s\" device found [%04x:%04x] (rev %x)\n", board->name,
158 (int)pdev->vendor, (int)pdev->device, (int)pdev->revision);
160 if (pci_resource_len(pdev, 0) != WIL6210_MEM_SIZE) {
161 dev_err(&pdev->dev, "Not " WIL_NAME "? "
162 "BAR0 size is %lu while expecting %lu\n",
163 (ulong)pci_resource_len(pdev, 0), WIL6210_MEM_SIZE);
167 rc = pci_enable_device(pdev);
170 "pci_enable_device failed, retry with MSI only\n");
171 /* Work around for platforms that can't allocate IRQ:
172 * retry with MSI only
174 pdev->msi_enabled = 1;
175 rc = pci_enable_device(pdev);
179 /* rollback to err_disable_pdev */
181 rc = pci_request_region(pdev, 0, WIL_NAME);
183 dev_err(&pdev->dev, "pci_request_region failed\n");
184 goto err_disable_pdev;
186 /* rollback to err_release_reg */
188 csr = pci_ioremap_bar(pdev, 0);
190 dev_err(&pdev->dev, "pci_ioremap_bar failed\n");
192 goto err_release_reg;
194 /* rollback to err_iounmap */
195 dev_info(&pdev->dev, "CSR at %pR -> 0x%p\n", &pdev->resource[0], csr);
197 wil = wil_if_alloc(dev, csr);
199 rc = (int)PTR_ERR(wil);
200 dev_err(dev, "wil_if_alloc failed: %d\n", rc);
203 /* rollback to if_free */
205 pci_set_drvdata(pdev, wil);
209 wil6210_clear_irq(wil);
211 wil->platform_handle =
212 wil_platform_init(&pdev->dev, &wil->platform_ops);
214 /* FW should raise IRQ when ready */
215 rc = wil_if_pcie_enable(wil);
217 wil_err(wil, "Enable device failed\n");
220 /* rollback to bus_disable */
222 rc = wil_if_add(wil);
224 wil_err(wil, "wil_if_add failed: %d\n", rc);
228 wil6210_debugfs_init(wil);
230 /* check FW is alive */
236 wil_if_pcie_disable(wil);
238 if (wil->platform_ops.uninit)
239 wil->platform_ops.uninit(wil->platform_handle);
242 pci_iounmap(pdev, csr);
244 pci_release_region(pdev, 0);
246 pci_disable_device(pdev);
251 static void wil_pcie_remove(struct pci_dev *pdev)
253 struct wil6210_priv *wil = pci_get_drvdata(pdev);
254 void __iomem *csr = wil->csr;
256 wil_dbg_misc(wil, "%s()\n", __func__);
258 wil6210_debugfs_remove(wil);
260 wil_if_pcie_disable(wil);
261 if (wil->platform_ops.uninit)
262 wil->platform_ops.uninit(wil->platform_handle);
264 pci_iounmap(pdev, csr);
265 pci_release_region(pdev, 0);
266 pci_disable_device(pdev);
269 static const struct wil_board wil_board_marlon = {
270 .board = WIL_BOARD_MARLON,
274 static const struct wil_board wil_board_sparrow = {
275 .board = WIL_BOARD_SPARROW,
279 static const struct pci_device_id wil6210_pcie_ids[] = {
280 { PCI_DEVICE(0x1ae9, 0x0301),
281 .driver_data = (kernel_ulong_t)&wil_board_marlon },
282 { PCI_DEVICE(0x1ae9, 0x0310),
283 .driver_data = (kernel_ulong_t)&wil_board_sparrow },
284 { PCI_DEVICE(0x1ae9, 0x0302), /* same as above, firmware broken */
285 .driver_data = (kernel_ulong_t)&wil_board_sparrow },
286 { /* end: all zeroes */ },
288 MODULE_DEVICE_TABLE(pci, wil6210_pcie_ids);
290 static struct pci_driver wil6210_driver = {
291 .probe = wil_pcie_probe,
292 .remove = wil_pcie_remove,
293 .id_table = wil6210_pcie_ids,
297 module_pci_driver(wil6210_driver);
299 MODULE_LICENSE("Dual BSD/GPL");
300 MODULE_AUTHOR("Qualcomm Atheros <wil6210@qca.qualcomm.com>");
301 MODULE_DESCRIPTION("Driver for 60g WiFi WIL6210 card");