This source file includes following definitions.
- mt76x2u_probe
- mt76x2u_disconnect
- mt76x2u_suspend
- mt76x2u_resume
1
2
3
4
5
6 #include <linux/kernel.h>
7 #include <linux/module.h>
8
9 #include "../mt76x02_usb.h"
10 #include "mt76x2u.h"
11
12 static const struct usb_device_id mt76x2u_device_table[] = {
13 { USB_DEVICE(0x0b05, 0x1833) },
14 { USB_DEVICE(0x0b05, 0x17eb) },
15 { USB_DEVICE(0x0b05, 0x180b) },
16 { USB_DEVICE(0x0e8d, 0x7612) },
17 { USB_DEVICE(0x057c, 0x8503) },
18 { USB_DEVICE(0x7392, 0xb711) },
19 { USB_DEVICE(0x0846, 0x9053) },
20 { USB_DEVICE(0x045e, 0x02e6) },
21 { USB_DEVICE(0x045e, 0x02fe) },
22 { },
23 };
24
25 static int mt76x2u_probe(struct usb_interface *intf,
26 const struct usb_device_id *id)
27 {
28 static const struct mt76_driver_ops drv_ops = {
29 .update_survey = mt76x02_update_channel,
30 .tx_prepare_skb = mt76x02u_tx_prepare_skb,
31 .tx_complete_skb = mt76x02u_tx_complete_skb,
32 .tx_status_data = mt76x02_tx_status_data,
33 .rx_skb = mt76x02_queue_rx_skb,
34 .sta_ps = mt76x02_sta_ps,
35 .sta_add = mt76x02_sta_add,
36 .sta_remove = mt76x02_sta_remove,
37 };
38 struct usb_device *udev = interface_to_usbdev(intf);
39 struct mt76x02_dev *dev;
40 struct mt76_dev *mdev;
41 int err;
42
43 mdev = mt76_alloc_device(&intf->dev, sizeof(*dev), &mt76x2u_ops,
44 &drv_ops);
45 if (!mdev)
46 return -ENOMEM;
47
48 dev = container_of(mdev, struct mt76x02_dev, mt76);
49
50 udev = usb_get_dev(udev);
51 usb_reset_device(udev);
52
53 usb_set_intfdata(intf, dev);
54
55 mt76x02u_init_mcu(mdev);
56 err = mt76u_init(mdev, intf);
57 if (err < 0)
58 goto err;
59
60 mdev->rev = mt76_rr(dev, MT_ASIC_VERSION);
61 dev_info(mdev->dev, "ASIC revision: %08x\n", mdev->rev);
62 if (!is_mt76x2(dev)) {
63 err = -ENODEV;
64 goto err;
65 }
66
67 err = mt76x2u_register_device(dev);
68 if (err < 0)
69 goto err;
70
71 return 0;
72
73 err:
74 ieee80211_free_hw(mt76_hw(dev));
75 usb_set_intfdata(intf, NULL);
76 usb_put_dev(udev);
77
78 return err;
79 }
80
81 static void mt76x2u_disconnect(struct usb_interface *intf)
82 {
83 struct usb_device *udev = interface_to_usbdev(intf);
84 struct mt76x02_dev *dev = usb_get_intfdata(intf);
85 struct ieee80211_hw *hw = mt76_hw(dev);
86
87 set_bit(MT76_REMOVED, &dev->mt76.state);
88 ieee80211_unregister_hw(hw);
89 mt76x2u_cleanup(dev);
90
91 ieee80211_free_hw(hw);
92 usb_set_intfdata(intf, NULL);
93 usb_put_dev(udev);
94 }
95
96 static int __maybe_unused mt76x2u_suspend(struct usb_interface *intf,
97 pm_message_t state)
98 {
99 struct mt76x02_dev *dev = usb_get_intfdata(intf);
100
101 mt76u_stop_rx(&dev->mt76);
102
103 return 0;
104 }
105
106 static int __maybe_unused mt76x2u_resume(struct usb_interface *intf)
107 {
108 struct mt76x02_dev *dev = usb_get_intfdata(intf);
109 int err;
110
111 err = mt76u_resume_rx(&dev->mt76);
112 if (err < 0)
113 goto err;
114
115 err = mt76x2u_init_hardware(dev);
116 if (err < 0)
117 goto err;
118
119 return 0;
120
121 err:
122 mt76x2u_cleanup(dev);
123 return err;
124 }
125
126 MODULE_DEVICE_TABLE(usb, mt76x2u_device_table);
127 MODULE_FIRMWARE(MT7662_FIRMWARE);
128 MODULE_FIRMWARE(MT7662_ROM_PATCH);
129
130 static struct usb_driver mt76x2u_driver = {
131 .name = KBUILD_MODNAME,
132 .id_table = mt76x2u_device_table,
133 .probe = mt76x2u_probe,
134 .disconnect = mt76x2u_disconnect,
135 #ifdef CONFIG_PM
136 .suspend = mt76x2u_suspend,
137 .resume = mt76x2u_resume,
138 .reset_resume = mt76x2u_resume,
139 #endif
140 .soft_unbind = 1,
141 .disable_hub_initiated_lpm = 1,
142 };
143 module_usb_driver(mt76x2u_driver);
144
145 MODULE_AUTHOR("Lorenzo Bianconi <lorenzo.bianconi83@gmail.com>");
146 MODULE_LICENSE("Dual BSD/GPL");