usb.c 4.1 KB

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