1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17#include <linux/kernel.h>
18#include <linux/module.h>
19#include <linux/pci.h>
20
21#include "mt76x2.h"
22
23static const struct pci_device_id mt76pci_device_table[] = {
24 { PCI_DEVICE(0x14c3, 0x7662) },
25 { PCI_DEVICE(0x14c3, 0x7612) },
26 { PCI_DEVICE(0x14c3, 0x7602) },
27 { },
28};
29
30static int
31mt76pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)
32{
33 static const struct mt76_driver_ops drv_ops = {
34 .txwi_size = sizeof(struct mt76x02_txwi),
35 .tx_aligned4_skbs = true,
36 .update_survey = mt76x02_update_channel,
37 .tx_prepare_skb = mt76x02_tx_prepare_skb,
38 .tx_complete_skb = mt76x02_tx_complete_skb,
39 .rx_skb = mt76x02_queue_rx_skb,
40 .rx_poll_complete = mt76x02_rx_poll_complete,
41 .sta_ps = mt76x02_sta_ps,
42 .sta_add = mt76x02_sta_add,
43 .sta_remove = mt76x02_sta_remove,
44 };
45 struct mt76x02_dev *dev;
46 struct mt76_dev *mdev;
47 int ret;
48
49 ret = pcim_enable_device(pdev);
50 if (ret)
51 return ret;
52
53 ret = pcim_iomap_regions(pdev, BIT(0), pci_name(pdev));
54 if (ret)
55 return ret;
56
57 pci_set_master(pdev);
58
59 ret = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
60 if (ret)
61 return ret;
62
63 mdev = mt76_alloc_device(&pdev->dev, sizeof(*dev), &mt76x2_ops,
64 &drv_ops);
65 if (!mdev)
66 return -ENOMEM;
67
68 dev = container_of(mdev, struct mt76x02_dev, mt76);
69 mt76_mmio_init(mdev, pcim_iomap_table(pdev)[0]);
70 mt76x2_reset_wlan(dev, false);
71
72 mdev->rev = mt76_rr(dev, MT_ASIC_VERSION);
73 dev_info(mdev->dev, "ASIC revision: %08x\n", mdev->rev);
74
75 ret = devm_request_irq(mdev->dev, pdev->irq, mt76x02_irq_handler,
76 IRQF_SHARED, KBUILD_MODNAME, dev);
77 if (ret)
78 goto error;
79
80 ret = mt76x2_register_device(dev);
81 if (ret)
82 goto error;
83
84
85
86
87 mt76_rmw_field(dev, 0x15a10, 0x1f << 16, 0x9);
88
89
90 mt76_rmw_field(dev, 0x15a0c, 0xf << 28, 0xf);
91
92
93 mt76_rmw_field(dev, 0x15c58, 0x3 << 6, 0x3);
94
95 return 0;
96
97error:
98 ieee80211_free_hw(mt76_hw(dev));
99 return ret;
100}
101
102static void
103mt76pci_remove(struct pci_dev *pdev)
104{
105 struct mt76_dev *mdev = pci_get_drvdata(pdev);
106 struct mt76x02_dev *dev = container_of(mdev, struct mt76x02_dev, mt76);
107
108 mt76_unregister_device(mdev);
109 mt76x2_cleanup(dev);
110 mt76_free_device(mdev);
111}
112
113MODULE_DEVICE_TABLE(pci, mt76pci_device_table);
114MODULE_FIRMWARE(MT7662_FIRMWARE);
115MODULE_FIRMWARE(MT7662_ROM_PATCH);
116MODULE_LICENSE("Dual BSD/GPL");
117
118static struct pci_driver mt76pci_driver = {
119 .name = KBUILD_MODNAME,
120 .id_table = mt76pci_device_table,
121 .probe = mt76pci_probe,
122 .remove = mt76pci_remove,
123};
124
125module_pci_driver(mt76pci_driver);
126