0001
0002
0003
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) },
0014 { USB_DEVICE(0x0b05, 0x17eb) },
0015 { USB_DEVICE(0x0b05, 0x180b) },
0016 { USB_DEVICE(0x0e8d, 0x7612) },
0017 { USB_DEVICE(0x057c, 0x8503) },
0018 { USB_DEVICE(0x7392, 0xb711) },
0019 { USB_DEVICE(0x0e8d, 0x7632) },
0020 { USB_DEVICE(0x2c4e, 0x0103) },
0021 { USB_DEVICE(0x0846, 0x9053) },
0022 { USB_DEVICE(0x045e, 0x02e6) },
0023 { USB_DEVICE(0x045e, 0x02fe) },
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
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");