10e3d6777SRyder Lee // SPDX-License-Identifier: ISC 21613c621SLorenzo Bianconi /* 31613c621SLorenzo Bianconi * Copyright (C) 2018 Lorenzo Bianconi <lorenzo.bianconi83@gmail.com> 41613c621SLorenzo Bianconi */ 51613c621SLorenzo Bianconi 61613c621SLorenzo Bianconi #include <linux/kernel.h> 71613c621SLorenzo Bianconi #include <linux/module.h> 81613c621SLorenzo Bianconi 91613c621SLorenzo Bianconi #include "../mt76x02_usb.h" 101613c621SLorenzo Bianconi #include "mt76x2u.h" 111613c621SLorenzo Bianconi 121613c621SLorenzo Bianconi static const struct usb_device_id mt76x2u_device_table[] = { 131613c621SLorenzo Bianconi { USB_DEVICE(0x0b05, 0x1833) }, /* Asus USB-AC54 */ 141613c621SLorenzo Bianconi { USB_DEVICE(0x0b05, 0x17eb) }, /* Asus USB-AC55 */ 151613c621SLorenzo Bianconi { USB_DEVICE(0x0b05, 0x180b) }, /* Asus USB-N53 B1 */ 16411e05f4SLorenzo Bianconi { USB_DEVICE(0x0e8d, 0x7612) }, /* Aukey USBAC1200 - Alfa AWUS036ACM */ 171613c621SLorenzo Bianconi { USB_DEVICE(0x057c, 0x8503) }, /* Avm FRITZ!WLAN AC860 */ 181613c621SLorenzo Bianconi { USB_DEVICE(0x7392, 0xb711) }, /* Edimax EW 7722 UAC */ 1905b5a339SLorenzo Bianconi { USB_DEVICE(0x0e8d, 0x7632) }, /* HC-M7662BU1 */ 203efdfbe0SLorenzo Bianconi { USB_DEVICE(0x2c4e, 0x0103) }, /* Mercury UD13 */ 211613c621SLorenzo Bianconi { USB_DEVICE(0x0846, 0x9053) }, /* Netgear A6210 */ 221613c621SLorenzo Bianconi { USB_DEVICE(0x045e, 0x02e6) }, /* XBox One Wireless Adapter */ 23b2934279SMatthew Garrett { USB_DEVICE(0x045e, 0x02fe) }, /* XBox One Wireless Adapter */ 241613c621SLorenzo Bianconi { }, 251613c621SLorenzo Bianconi }; 261613c621SLorenzo Bianconi 271613c621SLorenzo Bianconi static int mt76x2u_probe(struct usb_interface *intf, 281613c621SLorenzo Bianconi const struct usb_device_id *id) 291613c621SLorenzo Bianconi { 303bfaa974SLorenzo Bianconi static const struct mt76_driver_ops drv_ops = { 315ce09c1aSFelix Fietkau .drv_flags = MT_DRV_SW_RX_AIRTIME, 32355f8d00SFelix Fietkau .survey_flags = SURVEY_INFO_TIME_TX, 33168aea24SLorenzo Bianconi .update_survey = mt76x02_update_channel, 343bfaa974SLorenzo Bianconi .tx_prepare_skb = mt76x02u_tx_prepare_skb, 353bfaa974SLorenzo Bianconi .tx_complete_skb = mt76x02u_tx_complete_skb, 363bfaa974SLorenzo Bianconi .tx_status_data = mt76x02_tx_status_data, 373bfaa974SLorenzo Bianconi .rx_skb = mt76x02_queue_rx_skb, 382baed5dbSStanislaw Gruszka .sta_ps = mt76x02_sta_ps, 393bfaa974SLorenzo Bianconi .sta_add = mt76x02_sta_add, 403bfaa974SLorenzo Bianconi .sta_remove = mt76x02_sta_remove, 413bfaa974SLorenzo Bianconi }; 421613c621SLorenzo Bianconi struct usb_device *udev = interface_to_usbdev(intf); 43e40803f2SLorenzo Bianconi struct mt76x02_dev *dev; 443bfaa974SLorenzo Bianconi struct mt76_dev *mdev; 451613c621SLorenzo Bianconi int err; 461613c621SLorenzo Bianconi 4780df01f4SLorenzo Bianconi mdev = mt76_alloc_device(&intf->dev, sizeof(*dev), &mt76x2u_ops, 483bfaa974SLorenzo Bianconi &drv_ops); 493bfaa974SLorenzo Bianconi if (!mdev) 501613c621SLorenzo Bianconi return -ENOMEM; 511613c621SLorenzo Bianconi 523bfaa974SLorenzo Bianconi dev = container_of(mdev, struct mt76x02_dev, mt76); 533bfaa974SLorenzo Bianconi 541613c621SLorenzo Bianconi udev = usb_get_dev(udev); 551613c621SLorenzo Bianconi usb_reset_device(udev); 561613c621SLorenzo Bianconi 57112f980aSStanislaw Gruszka usb_set_intfdata(intf, dev); 58112f980aSStanislaw Gruszka 593bfaa974SLorenzo Bianconi mt76x02u_init_mcu(mdev); 601e816c65SLorenzo Bianconi err = mt76u_init(mdev, intf, false); 611613c621SLorenzo Bianconi if (err < 0) 621613c621SLorenzo Bianconi goto err; 631613c621SLorenzo Bianconi 643bfaa974SLorenzo Bianconi mdev->rev = mt76_rr(dev, MT_ASIC_VERSION); 653bfaa974SLorenzo Bianconi dev_info(mdev->dev, "ASIC revision: %08x\n", mdev->rev); 6640b94161SStanislaw Gruszka if (!is_mt76x2(dev)) { 6740b94161SStanislaw Gruszka err = -ENODEV; 6840b94161SStanislaw Gruszka goto err; 6940b94161SStanislaw Gruszka } 701613c621SLorenzo Bianconi 711613c621SLorenzo Bianconi err = mt76x2u_register_device(dev); 721613c621SLorenzo Bianconi if (err < 0) 731613c621SLorenzo Bianconi goto err; 741613c621SLorenzo Bianconi 751613c621SLorenzo Bianconi return 0; 761613c621SLorenzo Bianconi 771613c621SLorenzo Bianconi err: 78*a86f1d01SLorenzo Bianconi mt76_free_device(&dev->mt76); 791613c621SLorenzo Bianconi usb_set_intfdata(intf, NULL); 801613c621SLorenzo Bianconi usb_put_dev(udev); 811613c621SLorenzo Bianconi 821613c621SLorenzo Bianconi return err; 831613c621SLorenzo Bianconi } 841613c621SLorenzo Bianconi 851613c621SLorenzo Bianconi static void mt76x2u_disconnect(struct usb_interface *intf) 861613c621SLorenzo Bianconi { 871613c621SLorenzo Bianconi struct usb_device *udev = interface_to_usbdev(intf); 88e40803f2SLorenzo Bianconi struct mt76x02_dev *dev = usb_get_intfdata(intf); 891613c621SLorenzo Bianconi struct ieee80211_hw *hw = mt76_hw(dev); 901613c621SLorenzo Bianconi 91011849e0SFelix Fietkau set_bit(MT76_REMOVED, &dev->mphy.state); 921613c621SLorenzo Bianconi ieee80211_unregister_hw(hw); 931613c621SLorenzo Bianconi mt76x2u_cleanup(dev); 94*a86f1d01SLorenzo Bianconi mt76_free_device(&dev->mt76); 951613c621SLorenzo Bianconi usb_set_intfdata(intf, NULL); 961613c621SLorenzo Bianconi usb_put_dev(udev); 971613c621SLorenzo Bianconi } 981613c621SLorenzo Bianconi 991613c621SLorenzo Bianconi static int __maybe_unused mt76x2u_suspend(struct usb_interface *intf, 1001613c621SLorenzo Bianconi pm_message_t state) 1011613c621SLorenzo Bianconi { 102e40803f2SLorenzo Bianconi struct mt76x02_dev *dev = usb_get_intfdata(intf); 1031613c621SLorenzo Bianconi 10439d501d9SStanislaw Gruszka mt76u_stop_rx(&dev->mt76); 1051613c621SLorenzo Bianconi 1061613c621SLorenzo Bianconi return 0; 1071613c621SLorenzo Bianconi } 1081613c621SLorenzo Bianconi 1091613c621SLorenzo Bianconi static int __maybe_unused mt76x2u_resume(struct usb_interface *intf) 1101613c621SLorenzo Bianconi { 111e40803f2SLorenzo Bianconi struct mt76x02_dev *dev = usb_get_intfdata(intf); 1121613c621SLorenzo Bianconi int err; 1131613c621SLorenzo Bianconi 11439d501d9SStanislaw Gruszka err = mt76u_resume_rx(&dev->mt76); 1151613c621SLorenzo Bianconi if (err < 0) 1161613c621SLorenzo Bianconi goto err; 1171613c621SLorenzo Bianconi 1181613c621SLorenzo Bianconi err = mt76x2u_init_hardware(dev); 1191613c621SLorenzo Bianconi if (err < 0) 1201613c621SLorenzo Bianconi goto err; 1211613c621SLorenzo Bianconi 1221613c621SLorenzo Bianconi return 0; 1231613c621SLorenzo Bianconi 1241613c621SLorenzo Bianconi err: 1251613c621SLorenzo Bianconi mt76x2u_cleanup(dev); 1261613c621SLorenzo Bianconi return err; 1271613c621SLorenzo Bianconi } 1281613c621SLorenzo Bianconi 1291613c621SLorenzo Bianconi MODULE_DEVICE_TABLE(usb, mt76x2u_device_table); 130cac97ed6SLorenzo Bianconi MODULE_FIRMWARE(MT7662_FIRMWARE); 131cac97ed6SLorenzo Bianconi MODULE_FIRMWARE(MT7662_ROM_PATCH); 1321613c621SLorenzo Bianconi 1331613c621SLorenzo Bianconi static struct usb_driver mt76x2u_driver = { 1341613c621SLorenzo Bianconi .name = KBUILD_MODNAME, 1351613c621SLorenzo Bianconi .id_table = mt76x2u_device_table, 1361613c621SLorenzo Bianconi .probe = mt76x2u_probe, 1371613c621SLorenzo Bianconi .disconnect = mt76x2u_disconnect, 1381613c621SLorenzo Bianconi #ifdef CONFIG_PM 1391613c621SLorenzo Bianconi .suspend = mt76x2u_suspend, 1401613c621SLorenzo Bianconi .resume = mt76x2u_resume, 1411613c621SLorenzo Bianconi .reset_resume = mt76x2u_resume, 1421613c621SLorenzo Bianconi #endif /* CONFIG_PM */ 1431613c621SLorenzo Bianconi .soft_unbind = 1, 1441613c621SLorenzo Bianconi .disable_hub_initiated_lpm = 1, 1451613c621SLorenzo Bianconi }; 1461613c621SLorenzo Bianconi module_usb_driver(mt76x2u_driver); 1471613c621SLorenzo Bianconi 1481613c621SLorenzo Bianconi MODULE_AUTHOR("Lorenzo Bianconi <lorenzo.bianconi83@gmail.com>"); 1491613c621SLorenzo Bianconi MODULE_LICENSE("Dual BSD/GPL"); 150