1 // SPDX-License-Identifier: ISC 2 /* 3 * Copyright (C) 2018 Lorenzo Bianconi <lorenzo.bianconi83@gmail.com> 4 */ 5 6 #include <linux/kernel.h> 7 #include <linux/module.h> 8 9 #include "../mt76x02_usb.h" 10 #include "mt76x2u.h" 11 12 static const struct usb_device_id mt76x2u_device_table[] = { 13 { USB_DEVICE(0x0b05, 0x1833) }, /* Asus USB-AC54 */ 14 { USB_DEVICE(0x0b05, 0x17eb) }, /* Asus USB-AC55 */ 15 { USB_DEVICE(0x0b05, 0x180b) }, /* Asus USB-N53 B1 */ 16 { USB_DEVICE(0x0e8d, 0x7612) }, /* Aukey USBAC1200 - Alfa AWUS036ACM */ 17 { USB_DEVICE(0x057c, 0x8503) }, /* Avm FRITZ!WLAN AC860 */ 18 { USB_DEVICE(0x7392, 0xb711) }, /* Edimax EW 7722 UAC */ 19 { USB_DEVICE(0x0846, 0x9053) }, /* Netgear A6210 */ 20 { USB_DEVICE(0x045e, 0x02e6) }, /* XBox One Wireless Adapter */ 21 { }, 22 }; 23 24 static int mt76x2u_probe(struct usb_interface *intf, 25 const struct usb_device_id *id) 26 { 27 static const struct mt76_driver_ops drv_ops = { 28 .drv_flags = MT_DRV_SW_RX_AIRTIME, 29 .survey_flags = SURVEY_INFO_TIME_TX, 30 .update_survey = mt76x02_update_channel, 31 .tx_prepare_skb = mt76x02u_tx_prepare_skb, 32 .tx_complete_skb = mt76x02u_tx_complete_skb, 33 .tx_status_data = mt76x02_tx_status_data, 34 .rx_skb = mt76x02_queue_rx_skb, 35 .sta_ps = mt76x02_sta_ps, 36 .sta_add = mt76x02_sta_add, 37 .sta_remove = mt76x02_sta_remove, 38 }; 39 struct usb_device *udev = interface_to_usbdev(intf); 40 struct mt76x02_dev *dev; 41 struct mt76_dev *mdev; 42 int err; 43 44 mdev = mt76_alloc_device(&intf->dev, sizeof(*dev), &mt76x2u_ops, 45 &drv_ops); 46 if (!mdev) 47 return -ENOMEM; 48 49 dev = container_of(mdev, struct mt76x02_dev, mt76); 50 51 udev = usb_get_dev(udev); 52 usb_reset_device(udev); 53 54 usb_set_intfdata(intf, dev); 55 56 mt76x02u_init_mcu(mdev); 57 err = mt76u_init(mdev, intf); 58 if (err < 0) 59 goto err; 60 61 mdev->rev = mt76_rr(dev, MT_ASIC_VERSION); 62 dev_info(mdev->dev, "ASIC revision: %08x\n", mdev->rev); 63 if (!is_mt76x2(dev)) { 64 err = -ENODEV; 65 goto err; 66 } 67 68 err = mt76x2u_register_device(dev); 69 if (err < 0) 70 goto err; 71 72 return 0; 73 74 err: 75 ieee80211_free_hw(mt76_hw(dev)); 76 usb_set_intfdata(intf, NULL); 77 usb_put_dev(udev); 78 79 return err; 80 } 81 82 static void mt76x2u_disconnect(struct usb_interface *intf) 83 { 84 struct usb_device *udev = interface_to_usbdev(intf); 85 struct mt76x02_dev *dev = usb_get_intfdata(intf); 86 struct ieee80211_hw *hw = mt76_hw(dev); 87 88 set_bit(MT76_REMOVED, &dev->mt76.state); 89 ieee80211_unregister_hw(hw); 90 mt76x2u_cleanup(dev); 91 92 ieee80211_free_hw(hw); 93 usb_set_intfdata(intf, NULL); 94 usb_put_dev(udev); 95 } 96 97 static int __maybe_unused mt76x2u_suspend(struct usb_interface *intf, 98 pm_message_t state) 99 { 100 struct mt76x02_dev *dev = usb_get_intfdata(intf); 101 102 mt76u_stop_rx(&dev->mt76); 103 104 return 0; 105 } 106 107 static int __maybe_unused mt76x2u_resume(struct usb_interface *intf) 108 { 109 struct mt76x02_dev *dev = usb_get_intfdata(intf); 110 int err; 111 112 err = mt76u_resume_rx(&dev->mt76); 113 if (err < 0) 114 goto err; 115 116 err = mt76x2u_init_hardware(dev); 117 if (err < 0) 118 goto err; 119 120 return 0; 121 122 err: 123 mt76x2u_cleanup(dev); 124 return err; 125 } 126 127 MODULE_DEVICE_TABLE(usb, mt76x2u_device_table); 128 MODULE_FIRMWARE(MT7662_FIRMWARE); 129 MODULE_FIRMWARE(MT7662_ROM_PATCH); 130 131 static struct usb_driver mt76x2u_driver = { 132 .name = KBUILD_MODNAME, 133 .id_table = mt76x2u_device_table, 134 .probe = mt76x2u_probe, 135 .disconnect = mt76x2u_disconnect, 136 #ifdef CONFIG_PM 137 .suspend = mt76x2u_suspend, 138 .resume = mt76x2u_resume, 139 .reset_resume = mt76x2u_resume, 140 #endif /* CONFIG_PM */ 141 .soft_unbind = 1, 142 .disable_hub_initiated_lpm = 1, 143 }; 144 module_usb_driver(mt76x2u_driver); 145 146 MODULE_AUTHOR("Lorenzo Bianconi <lorenzo.bianconi83@gmail.com>"); 147 MODULE_LICENSE("Dual BSD/GPL"); 148