]> asedeno.scripts.mit.edu Git - linux.git/blob - drivers/net/wireless/mediatek/mt76/mt76x0/pci.c
99d142319d1cb93af4fb698b34594bc473c15c9a
[linux.git] / drivers / net / wireless / mediatek / mt76 / mt76x0 / pci.c
1 /*
2  * Copyright (C) 2016 Felix Fietkau <nbd@nbd.name>
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
17 #include <linux/kernel.h>
18 #include <linux/module.h>
19 #include <linux/pci.h>
20
21 #include "mt76x0.h"
22 #include "mcu.h"
23
24 static int
25 mt76x0e_probe(struct pci_dev *pdev, const struct pci_device_id *id)
26 {
27         struct mt76x0_dev *dev;
28         int ret = -ENODEV;
29
30         ret = pcim_enable_device(pdev);
31         if (ret)
32                 return ret;
33
34         ret = pcim_iomap_regions(pdev, BIT(0), pci_name(pdev));
35         if (ret)
36                 return ret;
37
38         pci_set_master(pdev);
39
40         ret = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
41         if (ret)
42                 return ret;
43
44         dev = mt76x0_alloc_device(&pdev->dev, NULL);
45         if (!dev)
46                 return -ENOMEM;
47
48         mt76_mmio_init(&dev->mt76, pcim_iomap_table(pdev)[0]);
49
50         dev->mt76.rev = mt76_rr(dev, MT_ASIC_VERSION);
51         dev_info(dev->mt76.dev, "ASIC revision: %08x\n", dev->mt76.rev);
52
53         ret = mt76x0e_mcu_init(dev);
54         if (ret < 0)
55                 goto error;
56
57         return 0;
58
59 error:
60         ieee80211_free_hw(mt76_hw(dev));
61         return ret;
62 }
63
64 static void
65 mt76x0e_remove(struct pci_dev *pdev)
66 {
67         struct mt76_dev *mdev = pci_get_drvdata(pdev);
68
69         mt76_unregister_device(mdev);
70         ieee80211_free_hw(mdev->hw);
71 }
72
73 static const struct pci_device_id mt76x0e_device_table[] = {
74         { PCI_DEVICE(0x14c3, 0x7630) },
75         { PCI_DEVICE(0x14c3, 0x7650) },
76         { },
77 };
78
79 MODULE_DEVICE_TABLE(pci, mt76x0e_device_table);
80 MODULE_LICENSE("Dual BSD/GPL");
81
82 static struct pci_driver mt76x0e_driver = {
83         .name           = KBUILD_MODNAME,
84         .id_table       = mt76x0e_device_table,
85         .probe          = mt76x0e_probe,
86         .remove         = mt76x0e_remove,
87 };
88
89 module_pci_driver(mt76x0e_driver);