10e3d6777SRyder Lee // SPDX-License-Identifier: ISC 21613c621SLorenzo Bianconi /* 31613c621SLorenzo Bianconi * Copyright (C) 2016 Felix Fietkau <nbd@nbd.name> 41613c621SLorenzo Bianconi */ 51613c621SLorenzo Bianconi 61613c621SLorenzo Bianconi #include <linux/kernel.h> 71613c621SLorenzo Bianconi #include <linux/module.h> 81613c621SLorenzo Bianconi #include <linux/pci.h> 91613c621SLorenzo Bianconi 101613c621SLorenzo Bianconi #include "mt76x2.h" 111613c621SLorenzo Bianconi 121613c621SLorenzo Bianconi static const struct pci_device_id mt76pci_device_table[] = { 131613c621SLorenzo Bianconi { PCI_DEVICE(0x14c3, 0x7662) }, 141613c621SLorenzo Bianconi { PCI_DEVICE(0x14c3, 0x7612) }, 151613c621SLorenzo Bianconi { PCI_DEVICE(0x14c3, 0x7602) }, 161613c621SLorenzo Bianconi { }, 171613c621SLorenzo Bianconi }; 181613c621SLorenzo Bianconi 191613c621SLorenzo Bianconi static int 201613c621SLorenzo Bianconi mt76pci_probe(struct pci_dev *pdev, const struct pci_device_id *id) 211613c621SLorenzo Bianconi { 22ecd25b54SLorenzo Bianconi static const struct mt76_driver_ops drv_ops = { 23ecd25b54SLorenzo Bianconi .txwi_size = sizeof(struct mt76x02_txwi), 245ce09c1aSFelix Fietkau .drv_flags = MT_DRV_TX_ALIGNED4_SKBS | 255ce09c1aSFelix Fietkau MT_DRV_SW_RX_AIRTIME, 26*355f8d00SFelix Fietkau .survey_flags = SURVEY_INFO_TIME_TX, 27ecd25b54SLorenzo Bianconi .update_survey = mt76x02_update_channel, 28ecd25b54SLorenzo Bianconi .tx_prepare_skb = mt76x02_tx_prepare_skb, 29ecd25b54SLorenzo Bianconi .tx_complete_skb = mt76x02_tx_complete_skb, 30ecd25b54SLorenzo Bianconi .rx_skb = mt76x02_queue_rx_skb, 31ecd25b54SLorenzo Bianconi .rx_poll_complete = mt76x02_rx_poll_complete, 32ecd25b54SLorenzo Bianconi .sta_ps = mt76x02_sta_ps, 33ecd25b54SLorenzo Bianconi .sta_add = mt76x02_sta_add, 34ecd25b54SLorenzo Bianconi .sta_remove = mt76x02_sta_remove, 35ecd25b54SLorenzo Bianconi }; 36e40803f2SLorenzo Bianconi struct mt76x02_dev *dev; 37ecd25b54SLorenzo Bianconi struct mt76_dev *mdev; 381613c621SLorenzo Bianconi int ret; 391613c621SLorenzo Bianconi 401613c621SLorenzo Bianconi ret = pcim_enable_device(pdev); 411613c621SLorenzo Bianconi if (ret) 421613c621SLorenzo Bianconi return ret; 431613c621SLorenzo Bianconi 441613c621SLorenzo Bianconi ret = pcim_iomap_regions(pdev, BIT(0), pci_name(pdev)); 451613c621SLorenzo Bianconi if (ret) 461613c621SLorenzo Bianconi return ret; 471613c621SLorenzo Bianconi 481613c621SLorenzo Bianconi pci_set_master(pdev); 491613c621SLorenzo Bianconi 501613c621SLorenzo Bianconi ret = pci_set_dma_mask(pdev, DMA_BIT_MASK(32)); 511613c621SLorenzo Bianconi if (ret) 521613c621SLorenzo Bianconi return ret; 531613c621SLorenzo Bianconi 54ecd25b54SLorenzo Bianconi mdev = mt76_alloc_device(&pdev->dev, sizeof(*dev), &mt76x2_ops, 55ecd25b54SLorenzo Bianconi &drv_ops); 56ecd25b54SLorenzo Bianconi if (!mdev) 571613c621SLorenzo Bianconi return -ENOMEM; 581613c621SLorenzo Bianconi 59ecd25b54SLorenzo Bianconi dev = container_of(mdev, struct mt76x02_dev, mt76); 60ecd25b54SLorenzo Bianconi mt76_mmio_init(mdev, pcim_iomap_table(pdev)[0]); 611613c621SLorenzo Bianconi mt76x2_reset_wlan(dev, false); 621613c621SLorenzo Bianconi 63ecd25b54SLorenzo Bianconi mdev->rev = mt76_rr(dev, MT_ASIC_VERSION); 64ecd25b54SLorenzo Bianconi dev_info(mdev->dev, "ASIC revision: %08x\n", mdev->rev); 651613c621SLorenzo Bianconi 66ecd25b54SLorenzo Bianconi ret = devm_request_irq(mdev->dev, pdev->irq, mt76x02_irq_handler, 671613c621SLorenzo Bianconi IRQF_SHARED, KBUILD_MODNAME, dev); 681613c621SLorenzo Bianconi if (ret) 691613c621SLorenzo Bianconi goto error; 701613c621SLorenzo Bianconi 711613c621SLorenzo Bianconi ret = mt76x2_register_device(dev); 721613c621SLorenzo Bianconi if (ret) 731613c621SLorenzo Bianconi goto error; 741613c621SLorenzo Bianconi 751613c621SLorenzo Bianconi /* Fix up ASPM configuration */ 761613c621SLorenzo Bianconi 771613c621SLorenzo Bianconi /* RG_SSUSB_G1_CDR_BIR_LTR = 0x9 */ 781613c621SLorenzo Bianconi mt76_rmw_field(dev, 0x15a10, 0x1f << 16, 0x9); 791613c621SLorenzo Bianconi 801613c621SLorenzo Bianconi /* RG_SSUSB_G1_CDR_BIC_LTR = 0xf */ 811613c621SLorenzo Bianconi mt76_rmw_field(dev, 0x15a0c, 0xf << 28, 0xf); 821613c621SLorenzo Bianconi 831613c621SLorenzo Bianconi /* RG_SSUSB_CDR_BR_PE1D = 0x3 */ 841613c621SLorenzo Bianconi mt76_rmw_field(dev, 0x15c58, 0x3 << 6, 0x3); 851613c621SLorenzo Bianconi 86f37f0550SLorenzo Bianconi mt76_pci_disable_aspm(pdev); 87f37f0550SLorenzo Bianconi 881613c621SLorenzo Bianconi return 0; 891613c621SLorenzo Bianconi 901613c621SLorenzo Bianconi error: 911613c621SLorenzo Bianconi ieee80211_free_hw(mt76_hw(dev)); 921613c621SLorenzo Bianconi return ret; 931613c621SLorenzo Bianconi } 941613c621SLorenzo Bianconi 951613c621SLorenzo Bianconi static void 961613c621SLorenzo Bianconi mt76pci_remove(struct pci_dev *pdev) 971613c621SLorenzo Bianconi { 981613c621SLorenzo Bianconi struct mt76_dev *mdev = pci_get_drvdata(pdev); 99e40803f2SLorenzo Bianconi struct mt76x02_dev *dev = container_of(mdev, struct mt76x02_dev, mt76); 1001613c621SLorenzo Bianconi 1011613c621SLorenzo Bianconi mt76_unregister_device(mdev); 1021613c621SLorenzo Bianconi mt76x2_cleanup(dev); 103def34a2fSLorenzo Bianconi mt76_free_device(mdev); 1041613c621SLorenzo Bianconi } 1051613c621SLorenzo Bianconi 1061613c621SLorenzo Bianconi MODULE_DEVICE_TABLE(pci, mt76pci_device_table); 1071613c621SLorenzo Bianconi MODULE_FIRMWARE(MT7662_FIRMWARE); 1081613c621SLorenzo Bianconi MODULE_FIRMWARE(MT7662_ROM_PATCH); 1091613c621SLorenzo Bianconi MODULE_LICENSE("Dual BSD/GPL"); 1101613c621SLorenzo Bianconi 1111613c621SLorenzo Bianconi static struct pci_driver mt76pci_driver = { 1121613c621SLorenzo Bianconi .name = KBUILD_MODNAME, 1131613c621SLorenzo Bianconi .id_table = mt76pci_device_table, 1141613c621SLorenzo Bianconi .probe = mt76pci_probe, 1151613c621SLorenzo Bianconi .remove = mt76pci_remove, 1161613c621SLorenzo Bianconi }; 1171613c621SLorenzo Bianconi 1181613c621SLorenzo Bianconi module_pci_driver(mt76pci_driver); 119