2 * Copyright (C) 2016 Felix Fietkau <nbd@nbd.name>
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/kernel.h>
18 #include <linux/module.h>
19 #include <linux/pci.h>
24 static int mt76x0e_start(struct ieee80211_hw *hw)
26 struct mt76x02_dev *dev = hw->priv;
28 mutex_lock(&dev->mt76.mutex);
30 mt76x02_mac_start(dev);
31 ieee80211_queue_delayed_work(dev->mt76.hw, &dev->mac_work,
32 MT_CALIBRATE_INTERVAL);
33 ieee80211_queue_delayed_work(dev->mt76.hw, &dev->cal_work,
34 MT_CALIBRATE_INTERVAL);
35 set_bit(MT76_STATE_RUNNING, &dev->mt76.state);
37 mutex_unlock(&dev->mt76.mutex);
42 static void mt76x0e_stop_hw(struct mt76x02_dev *dev)
44 cancel_delayed_work_sync(&dev->cal_work);
45 cancel_delayed_work_sync(&dev->mac_work);
47 if (!mt76_poll(dev, MT_WPDMA_GLO_CFG, MT_WPDMA_GLO_CFG_TX_DMA_BUSY,
49 dev_warn(dev->mt76.dev, "TX DMA did not stop\n");
50 mt76_clear(dev, MT_WPDMA_GLO_CFG, MT_WPDMA_GLO_CFG_TX_DMA_EN);
54 if (!mt76_poll(dev, MT_WPDMA_GLO_CFG, MT_WPDMA_GLO_CFG_RX_DMA_BUSY,
56 dev_warn(dev->mt76.dev, "TX DMA did not stop\n");
57 mt76_clear(dev, MT_WPDMA_GLO_CFG, MT_WPDMA_GLO_CFG_RX_DMA_EN);
60 static void mt76x0e_stop(struct ieee80211_hw *hw)
62 struct mt76x02_dev *dev = hw->priv;
64 mutex_lock(&dev->mt76.mutex);
65 clear_bit(MT76_STATE_RUNNING, &dev->mt76.state);
67 mutex_unlock(&dev->mt76.mutex);
70 static const struct ieee80211_ops mt76x0e_ops = {
72 .start = mt76x0e_start,
74 .config = mt76x0_config,
75 .add_interface = mt76x02_add_interface,
76 .remove_interface = mt76x02_remove_interface,
77 .configure_filter = mt76x02_configure_filter,
80 static int mt76x0e_register_device(struct mt76x02_dev *dev)
84 mt76x0_chip_onoff(dev, true, false);
85 if (!mt76x02_wait_for_mac(&dev->mt76))
88 mt76x02_dma_disable(dev);
89 err = mt76x0e_mcu_init(dev);
93 err = mt76x02_dma_init(dev);
97 err = mt76x0_init_hardware(dev);
101 if (mt76_chip(&dev->mt76) == 0x7610) {
104 mt76_clear(dev, MT_COEXCFG0, BIT(0));
105 val = mt76x02_eeprom_get(&dev->mt76, MT_EE_NIC_CONF_0);
106 if (val & MT_EE_NIC_CONF_0_PA_IO_CURRENT) {
109 /* set external external PA I/O
112 data = mt76_rr(dev, 0x11c);
114 mt76_wr(dev, 0x11c, val);
118 mt76_clear(dev, 0x110, BIT(9));
119 mt76_set(dev, MT_MAX_LEN_CFG, BIT(13));
125 mt76x0e_probe(struct pci_dev *pdev, const struct pci_device_id *id)
127 struct mt76x02_dev *dev;
130 ret = pcim_enable_device(pdev);
134 ret = pcim_iomap_regions(pdev, BIT(0), pci_name(pdev));
138 pci_set_master(pdev);
140 ret = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
144 dev = mt76x0_alloc_device(&pdev->dev, NULL, &mt76x0e_ops);
148 mt76_mmio_init(&dev->mt76, pcim_iomap_table(pdev)[0]);
150 dev->mt76.rev = mt76_rr(dev, MT_ASIC_VERSION);
151 dev_info(dev->mt76.dev, "ASIC revision: %08x\n", dev->mt76.rev);
153 ret = mt76x0e_register_device(dev);
160 ieee80211_free_hw(mt76_hw(dev));
164 static void mt76x0e_cleanup(struct mt76x02_dev *dev)
166 clear_bit(MT76_STATE_INITIALIZED, &dev->mt76.state);
167 mt76x0_chip_onoff(dev, false, false);
168 mt76x0e_stop_hw(dev);
169 mt76_dma_cleanup(&dev->mt76);
170 mt76x02_mcu_cleanup(&dev->mt76);
174 mt76x0e_remove(struct pci_dev *pdev)
176 struct mt76_dev *mdev = pci_get_drvdata(pdev);
177 struct mt76x02_dev *dev = container_of(mdev, struct mt76x02_dev, mt76);
179 mt76_unregister_device(mdev);
180 mt76x0e_cleanup(dev);
181 ieee80211_free_hw(mdev->hw);
184 static const struct pci_device_id mt76x0e_device_table[] = {
185 { PCI_DEVICE(0x14c3, 0x7630) },
186 { PCI_DEVICE(0x14c3, 0x7650) },
190 MODULE_DEVICE_TABLE(pci, mt76x0e_device_table);
191 MODULE_LICENSE("Dual BSD/GPL");
193 static struct pci_driver mt76x0e_driver = {
194 .name = KBUILD_MODNAME,
195 .id_table = mt76x0e_device_table,
196 .probe = mt76x0e_probe,
197 .remove = mt76x0e_remove,
200 module_pci_driver(mt76x0e_driver);