Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: ISC
0002 /*
0003  * Copyright (C) 2018 Lorenzo Bianconi <lorenzo.bianconi83@gmail.com>
0004  */
0005 
0006 #include <linux/kernel.h>
0007 #include <linux/module.h>
0008 
0009 #include "../mt76x02_usb.h"
0010 #include "mt76x2u.h"
0011 
0012 static const struct usb_device_id mt76x2u_device_table[] = {
0013     { USB_DEVICE(0x0b05, 0x1833) }, /* Asus USB-AC54 */
0014     { USB_DEVICE(0x0b05, 0x17eb) }, /* Asus USB-AC55 */
0015     { USB_DEVICE(0x0b05, 0x180b) }, /* Asus USB-N53 B1 */
0016     { USB_DEVICE(0x0e8d, 0x7612) }, /* Aukey USBAC1200 - Alfa AWUS036ACM */
0017     { USB_DEVICE(0x057c, 0x8503) }, /* Avm FRITZ!WLAN AC860 */
0018     { USB_DEVICE(0x7392, 0xb711) }, /* Edimax EW 7722 UAC */
0019     { USB_DEVICE(0x0e8d, 0x7632) }, /* HC-M7662BU1 */
0020     { USB_DEVICE(0x2c4e, 0x0103) }, /* Mercury UD13 */
0021     { USB_DEVICE(0x0846, 0x9053) }, /* Netgear A6210 */
0022     { USB_DEVICE(0x045e, 0x02e6) }, /* XBox One Wireless Adapter */
0023     { USB_DEVICE(0x045e, 0x02fe) }, /* XBox One Wireless Adapter */
0024     { },
0025 };
0026 
0027 static int mt76x2u_probe(struct usb_interface *intf,
0028              const struct usb_device_id *id)
0029 {
0030     static const struct mt76_driver_ops drv_ops = {
0031         .drv_flags = MT_DRV_SW_RX_AIRTIME,
0032         .survey_flags = SURVEY_INFO_TIME_TX,
0033         .update_survey = mt76x02_update_channel,
0034         .tx_prepare_skb = mt76x02u_tx_prepare_skb,
0035         .tx_complete_skb = mt76x02u_tx_complete_skb,
0036         .tx_status_data = mt76x02_tx_status_data,
0037         .rx_skb = mt76x02_queue_rx_skb,
0038         .sta_ps = mt76x02_sta_ps,
0039         .sta_add = mt76x02_sta_add,
0040         .sta_remove = mt76x02_sta_remove,
0041     };
0042     struct usb_device *udev = interface_to_usbdev(intf);
0043     struct mt76x02_dev *dev;
0044     struct mt76_dev *mdev;
0045     int err;
0046 
0047     mdev = mt76_alloc_device(&intf->dev, sizeof(*dev), &mt76x2u_ops,
0048                  &drv_ops);
0049     if (!mdev)
0050         return -ENOMEM;
0051 
0052     dev = container_of(mdev, struct mt76x02_dev, mt76);
0053 
0054     udev = usb_get_dev(udev);
0055     usb_reset_device(udev);
0056 
0057     usb_set_intfdata(intf, dev);
0058 
0059     mt76x02u_init_mcu(mdev);
0060     err = mt76u_init(mdev, intf);
0061     if (err < 0)
0062         goto err;
0063 
0064     mdev->rev = mt76_rr(dev, MT_ASIC_VERSION);
0065     dev_info(mdev->dev, "ASIC revision: %08x\n", mdev->rev);
0066     if (!is_mt76x2(dev)) {
0067         err = -ENODEV;
0068         goto err;
0069     }
0070 
0071     err = mt76x2u_register_device(dev);
0072     if (err < 0)
0073         goto err;
0074 
0075     return 0;
0076 
0077 err:
0078     mt76u_queues_deinit(&dev->mt76);
0079     mt76_free_device(&dev->mt76);
0080     usb_set_intfdata(intf, NULL);
0081     usb_put_dev(udev);
0082 
0083     return err;
0084 }
0085 
0086 static void mt76x2u_disconnect(struct usb_interface *intf)
0087 {
0088     struct usb_device *udev = interface_to_usbdev(intf);
0089     struct mt76x02_dev *dev = usb_get_intfdata(intf);
0090     struct ieee80211_hw *hw = mt76_hw(dev);
0091 
0092     set_bit(MT76_REMOVED, &dev->mphy.state);
0093     ieee80211_unregister_hw(hw);
0094     mt76x2u_cleanup(dev);
0095     mt76_free_device(&dev->mt76);
0096     usb_set_intfdata(intf, NULL);
0097     usb_put_dev(udev);
0098 }
0099 
0100 static int __maybe_unused mt76x2u_suspend(struct usb_interface *intf,
0101                       pm_message_t state)
0102 {
0103     struct mt76x02_dev *dev = usb_get_intfdata(intf);
0104 
0105     mt76u_stop_rx(&dev->mt76);
0106 
0107     return 0;
0108 }
0109 
0110 static int __maybe_unused mt76x2u_resume(struct usb_interface *intf)
0111 {
0112     struct mt76x02_dev *dev = usb_get_intfdata(intf);
0113     int err;
0114 
0115     err = mt76u_resume_rx(&dev->mt76);
0116     if (err < 0)
0117         goto err;
0118 
0119     err = mt76x2u_init_hardware(dev);
0120     if (err < 0)
0121         goto err;
0122 
0123     return 0;
0124 
0125 err:
0126     mt76x2u_cleanup(dev);
0127     return err;
0128 }
0129 
0130 MODULE_DEVICE_TABLE(usb, mt76x2u_device_table);
0131 MODULE_FIRMWARE(MT7662_FIRMWARE);
0132 MODULE_FIRMWARE(MT7662_ROM_PATCH);
0133 
0134 static struct usb_driver mt76x2u_driver = {
0135     .name       = KBUILD_MODNAME,
0136     .id_table   = mt76x2u_device_table,
0137     .probe      = mt76x2u_probe,
0138     .disconnect = mt76x2u_disconnect,
0139 #ifdef CONFIG_PM
0140     .suspend    = mt76x2u_suspend,
0141     .resume     = mt76x2u_resume,
0142     .reset_resume   = mt76x2u_resume,
0143 #endif /* CONFIG_PM */
0144     .soft_unbind    = 1,
0145     .disable_hub_initiated_lpm = 1,
0146 };
0147 module_usb_driver(mt76x2u_driver);
0148 
0149 MODULE_AUTHOR("Lorenzo Bianconi <lorenzo.bianconi83@gmail.com>");
0150 MODULE_LICENSE("Dual BSD/GPL");