Path: blob/main/sys/contrib/dev/mediatek/mt76/mt76x2/usb.c
48526 views
// SPDX-License-Identifier: ISC1/*2* Copyright (C) 2018 Lorenzo Bianconi <[email protected]>3*/45#include <linux/kernel.h>6#include <linux/module.h>78#include "../mt76x02_usb.h"9#include "mt76x2u.h"1011static const struct usb_device_id mt76x2u_device_table[] = {12{ USB_DEVICE(0x0b05, 0x1833) }, /* Asus USB-AC54 */13{ USB_DEVICE(0x0b05, 0x17eb) }, /* Asus USB-AC55 */14{ USB_DEVICE(0x0b05, 0x180b) }, /* Asus USB-N53 B1 */15{ USB_DEVICE(0x0e8d, 0x7612) }, /* Aukey USBAC1200 - Alfa AWUS036ACM */16{ USB_DEVICE(0x057c, 0x8503) }, /* Avm FRITZ!WLAN AC860 */17{ USB_DEVICE(0x7392, 0xb711) }, /* Edimax EW 7722 UAC */18{ USB_DEVICE(0x0e8d, 0x7632) }, /* HC-M7662BU1 */19{ USB_DEVICE(0x0471, 0x2126) }, /* LiteOn WN4516R module, nonstandard USB connector */20{ USB_DEVICE(0x0471, 0x7600) }, /* LiteOn WN4519R module, nonstandard USB connector */21{ USB_DEVICE(0x2c4e, 0x0103) }, /* Mercury UD13 */22{ USB_DEVICE(0x0846, 0x9014) }, /* Netgear WNDA3100v3 */23{ USB_DEVICE(0x0846, 0x9053) }, /* Netgear A6210 */24{ USB_DEVICE(0x045e, 0x02e6) }, /* XBox One Wireless Adapter */25{ USB_DEVICE(0x045e, 0x02fe) }, /* XBox One Wireless Adapter */26{ USB_DEVICE(0x2357, 0x0137) }, /* TP-Link TL-WDN6200 */27{ },28};2930static int mt76x2u_probe(struct usb_interface *intf,31const struct usb_device_id *id)32{33static const struct mt76_driver_ops drv_ops = {34.drv_flags = MT_DRV_SW_RX_AIRTIME |35MT_DRV_IGNORE_TXS_FAILED,36.survey_flags = SURVEY_INFO_TIME_TX,37.update_survey = mt76x02_update_channel,38.set_channel = mt76x2u_set_channel,39.tx_prepare_skb = mt76x02u_tx_prepare_skb,40.tx_complete_skb = mt76x02u_tx_complete_skb,41.tx_status_data = mt76x02_tx_status_data,42.rx_skb = mt76x02_queue_rx_skb,43.sta_ps = mt76x02_sta_ps,44.sta_add = mt76x02_sta_add,45.sta_remove = mt76x02_sta_remove,46};47struct usb_device *udev = interface_to_usbdev(intf);48struct mt76x02_dev *dev;49struct mt76_dev *mdev;50int err;5152mdev = mt76_alloc_device(&intf->dev, sizeof(*dev), &mt76x2u_ops,53&drv_ops);54if (!mdev)55return -ENOMEM;5657dev = container_of(mdev, struct mt76x02_dev, mt76);5859udev = usb_get_dev(udev);60usb_reset_device(udev);6162usb_set_intfdata(intf, dev);6364mt76x02u_init_mcu(mdev);65err = mt76u_init(mdev, intf);66if (err < 0)67goto err;6869mdev->rev = mt76_rr(dev, MT_ASIC_VERSION);70dev_info(mdev->dev, "ASIC revision: %08x\n", mdev->rev);71if (!is_mt76x2(dev)) {72err = -ENODEV;73goto err;74}7576err = mt76x2u_register_device(dev);77if (err < 0)78goto err;7980return 0;8182err:83mt76u_queues_deinit(&dev->mt76);84mt76_free_device(&dev->mt76);85usb_set_intfdata(intf, NULL);86usb_put_dev(udev);8788return err;89}9091static void mt76x2u_disconnect(struct usb_interface *intf)92{93struct usb_device *udev = interface_to_usbdev(intf);94struct mt76x02_dev *dev = usb_get_intfdata(intf);95struct ieee80211_hw *hw = mt76_hw(dev);9697set_bit(MT76_REMOVED, &dev->mphy.state);98ieee80211_unregister_hw(hw);99mt76x2u_cleanup(dev);100mt76_free_device(&dev->mt76);101usb_set_intfdata(intf, NULL);102usb_put_dev(udev);103}104105static int __maybe_unused mt76x2u_suspend(struct usb_interface *intf,106pm_message_t state)107{108struct mt76x02_dev *dev = usb_get_intfdata(intf);109110mt76u_stop_rx(&dev->mt76);111112return 0;113}114115static int __maybe_unused mt76x2u_resume(struct usb_interface *intf)116{117struct mt76x02_dev *dev = usb_get_intfdata(intf);118int err;119120err = mt76u_resume_rx(&dev->mt76);121if (err < 0)122goto err;123124err = mt76x2u_init_hardware(dev);125if (err < 0)126goto err;127128return 0;129130err:131mt76x2u_cleanup(dev);132return err;133}134135MODULE_DEVICE_TABLE(usb, mt76x2u_device_table);136MODULE_FIRMWARE(MT7662_FIRMWARE);137MODULE_FIRMWARE(MT7662_ROM_PATCH);138139static struct usb_driver mt76x2u_driver = {140.name = KBUILD_MODNAME,141.id_table = mt76x2u_device_table,142.probe = mt76x2u_probe,143.disconnect = mt76x2u_disconnect,144#ifdef CONFIG_PM145.suspend = mt76x2u_suspend,146.resume = mt76x2u_resume,147.reset_resume = mt76x2u_resume,148#endif /* CONFIG_PM */149.soft_unbind = 1,150.disable_hub_initiated_lpm = 1,151};152module_usb_driver(mt76x2u_driver);153154MODULE_AUTHOR("Lorenzo Bianconi <[email protected]>");155MODULE_DESCRIPTION("MediaTek MT76x2U (USB) wireless driver");156MODULE_LICENSE("Dual BSD/GPL");157158159