| 1 |
// SPDX-License-Identifier: BSD-3-Clause-Clear |
| 2 |
/* |
| 3 |
* Copyright (C) 2018 Lorenzo Bianconi <[email protected]> |
| 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(0x0e8d, 0x7632) }, /* HC-M7662BU1 */ |
| 20 |
{ USB_DEVICE(0x0471, 0x2126) }, /* LiteOn WN4516R module, nonstandard USB connector */ |
| 21 |
{ USB_DEVICE(0x0471, 0x7600) }, /* LiteOn WN4519R module, nonstandard USB connector */ |
| 22 |
{ USB_DEVICE(0x2c4e, 0x0103) }, /* Mercury UD13 */ |
| 23 |
{ USB_DEVICE(0x0846, 0x9014) }, /* Netgear WNDA3100v3 */ |
| 24 |
{ USB_DEVICE(0x0846, 0x9053) }, /* Netgear A6210 */ |
| 25 |
{ USB_DEVICE(0x045e, 0x02e6) }, /* XBox One Wireless Adapter */ |
| 26 |
{ USB_DEVICE(0x045e, 0x02fe) }, /* XBox One Wireless Adapter */ |
| 27 |
{ USB_DEVICE(0x2357, 0x0137) }, /* TP-Link TL-WDN6200 */ |
| 28 |
{ }, |
| 29 |
}; |
| 30 |
|
| 31 |
static int mt76x2u_probe(struct usb_interface *intf, |
| 32 |
const struct usb_device_id *id) |
| 33 |
{ |
| 34 |
static const struct mt76_driver_ops drv_ops = { |
| 35 |
.drv_flags = MT_DRV_SW_RX_AIRTIME | |
| 36 |
MT_DRV_IGNORE_TXS_FAILED, |
| 37 |
.survey_flags = SURVEY_INFO_TIME_TX, |
| 38 |
.update_survey = mt76x02_update_channel, |
| 39 |
.set_channel = mt76x2u_set_channel, |
| 40 |
.tx_prepare_skb = mt76x02u_tx_prepare_skb, |
| 41 |
.tx_complete_skb = mt76x02u_tx_complete_skb, |
| 42 |
.tx_status_data = mt76x02_tx_status_data, |
| 43 |
.rx_skb = mt76x02_queue_rx_skb, |
| 44 |
.sta_ps = mt76x02_sta_ps, |
| 45 |
.sta_add = mt76x02_sta_add, |
| 46 |
.sta_remove = mt76x02_sta_remove, |
| 47 |
}; |
| 48 |
struct usb_device *udev = interface_to_usbdev(intf); |
| 49 |
struct mt76x02_dev *dev; |
| 50 |
struct mt76_dev *mdev; |
| 51 |
int err; |
| 52 |
|
| 53 |
mdev = mt76_alloc_device(&intf->dev, sizeof(*dev), &mt76x2u_ops, |
| 54 |
&drv_ops); |
| 55 |
if (!mdev) |
| 56 |
return -ENOMEM; |
| 57 |
|
| 58 |
dev = container_of(mdev, struct mt76x02_dev, mt76); |
| 59 |
|
| 60 |
udev = usb_get_dev(udev); |
| 61 |
usb_reset_device(udev); |
| 62 |
|
| 63 |
usb_set_intfdata(intf, dev); |
| 64 |
|
| 65 |
mt76x02u_init_mcu(mdev); |
| 66 |
err = mt76u_init(mdev, intf); |
| 67 |
if (err < 0) |
| 68 |
goto err; |
| 69 |
|
| 70 |
mdev->rev = mt76_rr(dev, MT_ASIC_VERSION); |
| 71 |
dev_info(mdev->dev, "ASIC revision: %08x\n", mdev->rev); |
| 72 |
if (!is_mt76x2(dev)) { |
| 73 |
err = -ENODEV; |
| 74 |
goto err; |
| 75 |
} |
| 76 |
|
| 77 |
err = mt76x2u_register_device(dev); |
| 78 |
if (err < 0) |
| 79 |
goto err; |
| 80 |
|
| 81 |
return 0; |
| 82 |
|
| 83 |
err: |
| 84 |
mt76u_queues_deinit(&dev->mt76); |
| 85 |
mt76_free_device(&dev->mt76); |
| 86 |
usb_set_intfdata(intf, NULL); |
| 87 |
usb_put_dev(udev); |
| 88 |
|
| 89 |
return err; |
| 90 |
} |
| 91 |
|
| 92 |
static void mt76x2u_disconnect(struct usb_interface *intf) |
| 93 |
{ |
| 94 |
struct usb_device *udev = interface_to_usbdev(intf); |
| 95 |
struct mt76x02_dev *dev = usb_get_intfdata(intf); |
| 96 |
struct ieee80211_hw *hw = mt76_hw(dev); |
| 97 |
|
| 98 |
set_bit(MT76_REMOVED, &dev->mphy.state); |
| 99 |
ieee80211_unregister_hw(hw); |
| 100 |
mt76x2u_cleanup(dev); |
| 101 |
mt76_free_device(&dev->mt76); |
| 102 |
usb_set_intfdata(intf, NULL); |
| 103 |
usb_put_dev(udev); |
| 104 |
} |
| 105 |
|
| 106 |
static int __maybe_unused mt76x2u_suspend(struct usb_interface *intf, |
| 107 |
pm_message_t state) |
| 108 |
{ |
| 109 |
struct mt76x02_dev *dev = usb_get_intfdata(intf); |
| 110 |
|
| 111 |
mt76u_stop_rx(&dev->mt76); |
| 112 |
|
| 113 |
return 0; |
| 114 |
} |
| 115 |
|
| 116 |
static int __maybe_unused mt76x2u_resume(struct usb_interface *intf) |
| 117 |
{ |
| 118 |
struct mt76x02_dev *dev = usb_get_intfdata(intf); |
| 119 |
int err; |
| 120 |
|
| 121 |
err = mt76u_resume_rx(&dev->mt76); |
| 122 |
if (err < 0) |
| 123 |
goto err; |
| 124 |
|
| 125 |
err = mt76x2u_init_hardware(dev); |
| 126 |
if (err < 0) |
| 127 |
goto err; |
| 128 |
|
| 129 |
return 0; |
| 130 |
|
| 131 |
err: |
| 132 |
mt76x2u_cleanup(dev); |
| 133 |
return err; |
| 134 |
} |
| 135 |
|
| 136 |
MODULE_DEVICE_TABLE(usb, mt76x2u_device_table); |
| 137 |
MODULE_FIRMWARE(MT7662_FIRMWARE); |
| 138 |
MODULE_FIRMWARE(MT7662_ROM_PATCH); |
| 139 |
|
| 140 |
static struct usb_driver mt76x2u_driver = { |
| 141 |
.name = KBUILD_MODNAME, |
| 142 |
.id_table = mt76x2u_device_table, |
| 143 |
.probe = mt76x2u_probe, |
| 144 |
.disconnect = mt76x2u_disconnect, |
| 145 |
#ifdef CONFIG_PM |
| 146 |
.suspend = mt76x2u_suspend, |
| 147 |
.resume = mt76x2u_resume, |
| 148 |
.reset_resume = mt76x2u_resume, |
| 149 |
#endif /* CONFIG_PM */ |
| 150 |
.soft_unbind = 1, |
| 151 |
.disable_hub_initiated_lpm = 1, |
| 152 |
}; |
| 153 |
module_usb_driver(mt76x2u_driver); |
| 154 |
|
| 155 |
MODULE_AUTHOR("Lorenzo Bianconi <[email protected]>"); |
| 156 |
MODULE_DESCRIPTION("MediaTek MT76x2U (USB) wireless driver"); |
| 157 |
MODULE_LICENSE("Dual BSD/GPL"); |