mt76x2_usb.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. /*
  2. * Copyright (C) 2018 Lorenzo Bianconi <lorenzo.bianconi83@gmail.com>
  3. *
  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.
  7. *
  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.
  15. */
  16. #include <linux/kernel.h>
  17. #include <linux/module.h>
  18. #include "mt76x2u.h"
  19. static const struct usb_device_id mt76x2u_device_table[] = {
  20. { USB_DEVICE(0x0b05, 0x1833) }, /* Asus USB-AC54 */
  21. { USB_DEVICE(0x0b05, 0x17eb) }, /* Asus USB-AC55 */
  22. { USB_DEVICE(0x0b05, 0x180b) }, /* Asus USB-N53 B1 */
  23. { USB_DEVICE(0x0e8d, 0x7612) }, /* Aukey USB-AC1200 */
  24. { USB_DEVICE(0x057c, 0x8503) }, /* Avm FRITZ!WLAN AC860 */
  25. { USB_DEVICE(0x7392, 0xb711) }, /* Edimax EW 7722 UAC */
  26. { USB_DEVICE(0x0846, 0x9053) }, /* Netgear A6210 */
  27. { USB_DEVICE(0x045e, 0x02e6) }, /* XBox One Wireless Adapter */
  28. { },
  29. };
  30. static int mt76x2u_probe(struct usb_interface *intf,
  31. const struct usb_device_id *id)
  32. {
  33. struct usb_device *udev = interface_to_usbdev(intf);
  34. struct mt76x2_dev *dev;
  35. int err;
  36. dev = mt76x2u_alloc_device(&intf->dev);
  37. if (!dev)
  38. return -ENOMEM;
  39. udev = usb_get_dev(udev);
  40. usb_reset_device(udev);
  41. err = mt76u_init(&dev->mt76, intf);
  42. if (err < 0)
  43. goto err;
  44. dev->mt76.rev = mt76_rr(dev, MT_ASIC_VERSION);
  45. dev_info(dev->mt76.dev, "ASIC revision: %08x\n", dev->mt76.rev);
  46. err = mt76x2u_register_device(dev);
  47. if (err < 0)
  48. goto err;
  49. return 0;
  50. err:
  51. ieee80211_free_hw(mt76_hw(dev));
  52. usb_set_intfdata(intf, NULL);
  53. usb_put_dev(udev);
  54. return err;
  55. }
  56. static void mt76x2u_disconnect(struct usb_interface *intf)
  57. {
  58. struct usb_device *udev = interface_to_usbdev(intf);
  59. struct mt76x2_dev *dev = usb_get_intfdata(intf);
  60. struct ieee80211_hw *hw = mt76_hw(dev);
  61. set_bit(MT76_REMOVED, &dev->mt76.state);
  62. ieee80211_unregister_hw(hw);
  63. mt76x2u_cleanup(dev);
  64. ieee80211_free_hw(hw);
  65. usb_set_intfdata(intf, NULL);
  66. usb_put_dev(udev);
  67. }
  68. static int __maybe_unused mt76x2u_suspend(struct usb_interface *intf,
  69. pm_message_t state)
  70. {
  71. struct mt76x2_dev *dev = usb_get_intfdata(intf);
  72. struct mt76_usb *usb = &dev->mt76.usb;
  73. mt76u_stop_queues(&dev->mt76);
  74. mt76x2u_stop_hw(dev);
  75. usb_kill_urb(usb->mcu.res.urb);
  76. return 0;
  77. }
  78. static int __maybe_unused mt76x2u_resume(struct usb_interface *intf)
  79. {
  80. struct mt76x2_dev *dev = usb_get_intfdata(intf);
  81. struct mt76_usb *usb = &dev->mt76.usb;
  82. int err;
  83. reinit_completion(&usb->mcu.cmpl);
  84. err = mt76u_submit_buf(&dev->mt76, USB_DIR_IN,
  85. MT_EP_IN_CMD_RESP,
  86. &usb->mcu.res, GFP_KERNEL,
  87. mt76u_mcu_complete_urb,
  88. &usb->mcu.cmpl);
  89. if (err < 0)
  90. goto err;
  91. err = mt76u_submit_rx_buffers(&dev->mt76);
  92. if (err < 0)
  93. goto err;
  94. tasklet_enable(&usb->rx_tasklet);
  95. tasklet_enable(&usb->tx_tasklet);
  96. err = mt76x2u_init_hardware(dev);
  97. if (err < 0)
  98. goto err;
  99. return 0;
  100. err:
  101. mt76x2u_cleanup(dev);
  102. return err;
  103. }
  104. MODULE_DEVICE_TABLE(usb, mt76x2u_device_table);
  105. MODULE_FIRMWARE(MT7662U_FIRMWARE);
  106. MODULE_FIRMWARE(MT7662U_ROM_PATCH);
  107. static struct usb_driver mt76x2u_driver = {
  108. .name = KBUILD_MODNAME,
  109. .id_table = mt76x2u_device_table,
  110. .probe = mt76x2u_probe,
  111. .disconnect = mt76x2u_disconnect,
  112. #ifdef CONFIG_PM
  113. .suspend = mt76x2u_suspend,
  114. .resume = mt76x2u_resume,
  115. .reset_resume = mt76x2u_resume,
  116. #endif /* CONFIG_PM */
  117. .soft_unbind = 1,
  118. .disable_hub_initiated_lpm = 1,
  119. };
  120. module_usb_driver(mt76x2u_driver);
  121. MODULE_AUTHOR("Lorenzo Bianconi <lorenzo.bianconi83@gmail.com>");
  122. MODULE_LICENSE("Dual BSD/GPL");