Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /****************************************************************************** |
2 | * speedtch.c - Alcatel SpeedTouch USB xDSL modem driver | |
3 | * | |
4 | * Copyright (C) 2001, Alcatel | |
5 | * Copyright (C) 2003, Duncan Sands | |
6 | * Copyright (C) 2004, David Woodhouse | |
7 | * | |
48da7267 DS |
8 | * Based on "modem_run.c", copyright (C) 2001, Benoit Papillault |
9 | * | |
1da177e4 LT |
10 | * This program is free software; you can redistribute it and/or modify it |
11 | * under the terms of the GNU General Public License as published by the Free | |
12 | * Software Foundation; either version 2 of the License, or (at your option) | |
13 | * any later version. | |
14 | * | |
15 | * This program is distributed in the hope that it will be useful, but WITHOUT | |
16 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
17 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | |
18 | * more details. | |
19 | * | |
20 | * You should have received a copy of the GNU General Public License along with | |
21 | * this program; if not, write to the Free Software Foundation, Inc., 59 | |
22 | * Temple Place - Suite 330, Boston, MA 02111-1307, USA. | |
23 | * | |
24 | ******************************************************************************/ | |
25 | ||
48da7267 DS |
26 | #include <asm/page.h> |
27 | #include <linux/device.h> | |
28 | #include <linux/errno.h> | |
29 | #include <linux/firmware.h> | |
1da177e4 | 30 | #include <linux/kernel.h> |
48da7267 DS |
31 | #include <linux/module.h> |
32 | #include <linux/moduleparam.h> | |
1da177e4 | 33 | #include <linux/slab.h> |
48da7267 DS |
34 | #include <linux/stat.h> |
35 | #include <linux/timer.h> | |
80aae7a1 | 36 | #include <linux/types.h> |
5f848137 | 37 | #include <linux/usb/ch9.h> |
48da7267 | 38 | #include <linux/workqueue.h> |
1da177e4 | 39 | |
48da7267 | 40 | #include "usbatm.h" |
1da177e4 LT |
41 | |
42 | #define DRIVER_AUTHOR "Johan Verrept, Duncan Sands <duncan.sands@free.fr>" | |
9b0e54ad | 43 | #define DRIVER_VERSION "1.10" |
1da177e4 LT |
44 | #define DRIVER_DESC "Alcatel SpeedTouch USB driver version " DRIVER_VERSION |
45 | ||
46 | static const char speedtch_driver_name[] = "speedtch"; | |
47 | ||
48da7267 DS |
48 | #define CTRL_TIMEOUT 2000 /* milliseconds */ |
49 | #define DATA_TIMEOUT 2000 /* milliseconds */ | |
1da177e4 | 50 | |
48da7267 DS |
51 | #define OFFSET_7 0 /* size 1 */ |
52 | #define OFFSET_b 1 /* size 8 */ | |
53 | #define OFFSET_d 9 /* size 4 */ | |
54 | #define OFFSET_e 13 /* size 1 */ | |
55 | #define OFFSET_f 14 /* size 1 */ | |
1da177e4 | 56 | |
48da7267 DS |
57 | #define SIZE_7 1 |
58 | #define SIZE_b 8 | |
59 | #define SIZE_d 4 | |
60 | #define SIZE_e 1 | |
61 | #define SIZE_f 1 | |
1da177e4 | 62 | |
48da7267 DS |
63 | #define MIN_POLL_DELAY 5000 /* milliseconds */ |
64 | #define MAX_POLL_DELAY 60000 /* milliseconds */ | |
1da177e4 | 65 | |
48da7267 | 66 | #define RESUBMIT_DELAY 1000 /* milliseconds */ |
1da177e4 | 67 | |
80aae7a1 | 68 | #define DEFAULT_BULK_ALTSETTING 1 |
67c752b4 | 69 | #define DEFAULT_ISOC_ALTSETTING 3 |
48da7267 | 70 | #define DEFAULT_DL_512_FIRST 0 |
80aae7a1 | 71 | #define DEFAULT_ENABLE_ISOC 0 |
48da7267 | 72 | #define DEFAULT_SW_BUFFERING 0 |
1da177e4 | 73 | |
80aae7a1 | 74 | static unsigned int altsetting = 0; /* zero means: use the default */ |
90ab5ee9 RR |
75 | static bool dl_512_first = DEFAULT_DL_512_FIRST; |
76 | static bool enable_isoc = DEFAULT_ENABLE_ISOC; | |
77 | static bool sw_buffering = DEFAULT_SW_BUFFERING; | |
1da177e4 | 78 | |
6a4f1b41 DS |
79 | #define DEFAULT_B_MAX_DSL 8128 |
80 | #define DEFAULT_MODEM_MODE 11 | |
81 | #define MODEM_OPTION_LENGTH 16 | |
82 | static const unsigned char DEFAULT_MODEM_OPTION[MODEM_OPTION_LENGTH] = { | |
83 | 0x10, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 | |
84 | }; | |
85 | ||
86 | static unsigned int BMaxDSL = DEFAULT_B_MAX_DSL; | |
87 | static unsigned char ModemMode = DEFAULT_MODEM_MODE; | |
88 | static unsigned char ModemOption[MODEM_OPTION_LENGTH]; | |
64a6f950 | 89 | static unsigned int num_ModemOption; |
6a4f1b41 | 90 | |
80aae7a1 | 91 | module_param(altsetting, uint, S_IRUGO | S_IWUSR); |
48da7267 | 92 | MODULE_PARM_DESC(altsetting, |
80aae7a1 DS |
93 | "Alternative setting for data interface (bulk_default: " |
94 | __MODULE_STRING(DEFAULT_BULK_ALTSETTING) "; isoc_default: " | |
95 | __MODULE_STRING(DEFAULT_ISOC_ALTSETTING) ")"); | |
1da177e4 | 96 | |
48da7267 DS |
97 | module_param(dl_512_first, bool, S_IRUGO | S_IWUSR); |
98 | MODULE_PARM_DESC(dl_512_first, | |
99 | "Read 512 bytes before sending firmware (default: " | |
100 | __MODULE_STRING(DEFAULT_DL_512_FIRST) ")"); | |
1da177e4 | 101 | |
80aae7a1 DS |
102 | module_param(enable_isoc, bool, S_IRUGO | S_IWUSR); |
103 | MODULE_PARM_DESC(enable_isoc, | |
104 | "Use isochronous transfers if available (default: " | |
105 | __MODULE_STRING(DEFAULT_ENABLE_ISOC) ")"); | |
106 | ||
48da7267 DS |
107 | module_param(sw_buffering, bool, S_IRUGO | S_IWUSR); |
108 | MODULE_PARM_DESC(sw_buffering, | |
109 | "Enable software buffering (default: " | |
110 | __MODULE_STRING(DEFAULT_SW_BUFFERING) ")"); | |
1da177e4 | 111 | |
6a4f1b41 DS |
112 | module_param(BMaxDSL, uint, S_IRUGO | S_IWUSR); |
113 | MODULE_PARM_DESC(BMaxDSL, | |
114 | "default: " __MODULE_STRING(DEFAULT_B_MAX_DSL)); | |
115 | ||
116 | module_param(ModemMode, byte, S_IRUGO | S_IWUSR); | |
117 | MODULE_PARM_DESC(ModemMode, | |
118 | "default: " __MODULE_STRING(DEFAULT_MODEM_MODE)); | |
119 | ||
120 | module_param_array(ModemOption, byte, &num_ModemOption, S_IRUGO); | |
121 | MODULE_PARM_DESC(ModemOption, "default: 0x10,0x00,0x00,0x00,0x20"); | |
122 | ||
6f749475 | 123 | #define INTERFACE_DATA 1 |
48da7267 | 124 | #define ENDPOINT_INT 0x81 |
80aae7a1 DS |
125 | #define ENDPOINT_BULK_DATA 0x07 |
126 | #define ENDPOINT_ISOC_DATA 0x07 | |
48da7267 | 127 | #define ENDPOINT_FIRMWARE 0x05 |
1da177e4 | 128 | |
6a4f1b41 DS |
129 | struct speedtch_params { |
130 | unsigned int altsetting; | |
131 | unsigned int BMaxDSL; | |
132 | unsigned char ModemMode; | |
133 | unsigned char ModemOption[MODEM_OPTION_LENGTH]; | |
134 | }; | |
135 | ||
1da177e4 | 136 | struct speedtch_instance_data { |
48da7267 DS |
137 | struct usbatm_data *usbatm; |
138 | ||
6a4f1b41 | 139 | struct speedtch_params params; /* set in probe, constant afterwards */ |
6f749475 | 140 | |
37c95bfe TH |
141 | struct timer_list status_check_timer; |
142 | struct work_struct status_check_work; | |
1da177e4 | 143 | |
1a7aad15 DS |
144 | unsigned char last_status; |
145 | ||
48da7267 DS |
146 | int poll_delay; /* milliseconds */ |
147 | ||
148 | struct timer_list resubmit_timer; | |
1da177e4 LT |
149 | struct urb *int_urb; |
150 | unsigned char int_data[16]; | |
1da177e4 | 151 | |
6a4f1b41 | 152 | unsigned char scratch_buffer[16]; |
1da177e4 LT |
153 | }; |
154 | ||
155 | /*************** | |
156 | ** firmware ** | |
157 | ***************/ | |
158 | ||
48da7267 | 159 | static void speedtch_set_swbuff(struct speedtch_instance_data *instance, int state) |
1da177e4 | 160 | { |
48da7267 DS |
161 | struct usbatm_data *usbatm = instance->usbatm; |
162 | struct usb_device *usb_dev = usbatm->usb_dev; | |
1da177e4 LT |
163 | int ret; |
164 | ||
48da7267 DS |
165 | ret = usb_control_msg(usb_dev, usb_sndctrlpipe(usb_dev, 0), |
166 | 0x32, 0x40, state ? 0x01 : 0x00, 0x00, NULL, 0, CTRL_TIMEOUT); | |
167 | if (ret < 0) | |
168 | usb_warn(usbatm, | |
169 | "%sabling SW buffering: usb_control_msg returned %d\n", | |
170 | state ? "En" : "Dis", ret); | |
171 | else | |
d8995425 | 172 | usb_dbg(usbatm, "speedtch_set_swbuff: %sbled SW buffering\n", state ? "En" : "Dis"); |
1da177e4 LT |
173 | } |
174 | ||
175 | static void speedtch_test_sequence(struct speedtch_instance_data *instance) | |
176 | { | |
48da7267 DS |
177 | struct usbatm_data *usbatm = instance->usbatm; |
178 | struct usb_device *usb_dev = usbatm->usb_dev; | |
179 | unsigned char *buf = instance->scratch_buffer; | |
1da177e4 LT |
180 | int ret; |
181 | ||
182 | /* URB 147 */ | |
183 | buf[0] = 0x1c; | |
184 | buf[1] = 0x50; | |
48da7267 DS |
185 | ret = usb_control_msg(usb_dev, usb_sndctrlpipe(usb_dev, 0), |
186 | 0x01, 0x40, 0x0b, 0x00, buf, 2, CTRL_TIMEOUT); | |
1da177e4 | 187 | if (ret < 0) |
48da7267 | 188 | usb_warn(usbatm, "%s failed on URB147: %d\n", __func__, ret); |
1da177e4 LT |
189 | |
190 | /* URB 148 */ | |
191 | buf[0] = 0x32; | |
192 | buf[1] = 0x00; | |
48da7267 DS |
193 | ret = usb_control_msg(usb_dev, usb_sndctrlpipe(usb_dev, 0), |
194 | 0x01, 0x40, 0x02, 0x00, buf, 2, CTRL_TIMEOUT); | |
1da177e4 | 195 | if (ret < 0) |
48da7267 | 196 | usb_warn(usbatm, "%s failed on URB148: %d\n", __func__, ret); |
1da177e4 LT |
197 | |
198 | /* URB 149 */ | |
199 | buf[0] = 0x01; | |
200 | buf[1] = 0x00; | |
201 | buf[2] = 0x01; | |
48da7267 DS |
202 | ret = usb_control_msg(usb_dev, usb_sndctrlpipe(usb_dev, 0), |
203 | 0x01, 0x40, 0x03, 0x00, buf, 3, CTRL_TIMEOUT); | |
1da177e4 | 204 | if (ret < 0) |
48da7267 | 205 | usb_warn(usbatm, "%s failed on URB149: %d\n", __func__, ret); |
1da177e4 LT |
206 | |
207 | /* URB 150 */ | |
208 | buf[0] = 0x01; | |
209 | buf[1] = 0x00; | |
210 | buf[2] = 0x01; | |
48da7267 DS |
211 | ret = usb_control_msg(usb_dev, usb_sndctrlpipe(usb_dev, 0), |
212 | 0x01, 0x40, 0x04, 0x00, buf, 3, CTRL_TIMEOUT); | |
1da177e4 | 213 | if (ret < 0) |
48da7267 | 214 | usb_warn(usbatm, "%s failed on URB150: %d\n", __func__, ret); |
6a4f1b41 DS |
215 | |
216 | /* Extra initialisation in recent drivers - gives higher speeds */ | |
217 | ||
218 | /* URBext1 */ | |
219 | buf[0] = instance->params.ModemMode; | |
220 | ret = usb_control_msg(usb_dev, usb_sndctrlpipe(usb_dev, 0), | |
221 | 0x01, 0x40, 0x11, 0x00, buf, 1, CTRL_TIMEOUT); | |
222 | if (ret < 0) | |
223 | usb_warn(usbatm, "%s failed on URBext1: %d\n", __func__, ret); | |
224 | ||
225 | /* URBext2 */ | |
226 | /* This seems to be the one which actually triggers the higher sync | |
227 | rate -- it does require the new firmware too, although it works OK | |
228 | with older firmware */ | |
229 | ret = usb_control_msg(usb_dev, usb_sndctrlpipe(usb_dev, 0), | |
230 | 0x01, 0x40, 0x14, 0x00, | |
231 | instance->params.ModemOption, | |
232 | MODEM_OPTION_LENGTH, CTRL_TIMEOUT); | |
233 | if (ret < 0) | |
234 | usb_warn(usbatm, "%s failed on URBext2: %d\n", __func__, ret); | |
235 | ||
236 | /* URBext3 */ | |
237 | buf[0] = instance->params.BMaxDSL & 0xff; | |
238 | buf[1] = instance->params.BMaxDSL >> 8; | |
239 | ret = usb_control_msg(usb_dev, usb_sndctrlpipe(usb_dev, 0), | |
240 | 0x01, 0x40, 0x12, 0x00, buf, 2, CTRL_TIMEOUT); | |
241 | if (ret < 0) | |
242 | usb_warn(usbatm, "%s failed on URBext3: %d\n", __func__, ret); | |
1da177e4 LT |
243 | } |
244 | ||
48da7267 DS |
245 | static int speedtch_upload_firmware(struct speedtch_instance_data *instance, |
246 | const struct firmware *fw1, | |
247 | const struct firmware *fw2) | |
1da177e4 | 248 | { |
48da7267 DS |
249 | unsigned char *buffer; |
250 | struct usbatm_data *usbatm = instance->usbatm; | |
48da7267 DS |
251 | struct usb_device *usb_dev = usbatm->usb_dev; |
252 | int actual_length; | |
253 | int ret = 0; | |
254 | int offset; | |
255 | ||
256 | usb_dbg(usbatm, "%s entered\n", __func__); | |
257 | ||
3383ee4c GKH |
258 | buffer = (unsigned char *)__get_free_page(GFP_KERNEL); |
259 | if (!buffer) { | |
48da7267 DS |
260 | ret = -ENOMEM; |
261 | usb_dbg(usbatm, "%s: no memory for buffer!\n", __func__); | |
262 | goto out; | |
263 | } | |
264 | ||
011db815 | 265 | if (!usb_ifnum_to_if(usb_dev, 2)) { |
48da7267 DS |
266 | ret = -ENODEV; |
267 | usb_dbg(usbatm, "%s: interface not found!\n", __func__); | |
268 | goto out_free; | |
269 | } | |
270 | ||
271 | /* URB 7 */ | |
272 | if (dl_512_first) { /* some modems need a read before writing the firmware */ | |
273 | ret = usb_bulk_msg(usb_dev, usb_rcvbulkpipe(usb_dev, ENDPOINT_FIRMWARE), | |
274 | buffer, 0x200, &actual_length, 2000); | |
275 | ||
276 | if (ret < 0 && ret != -ETIMEDOUT) | |
0ec3c7e8 | 277 | usb_warn(usbatm, "%s: read BLOCK0 from modem failed (%d)!\n", __func__, ret); |
48da7267 DS |
278 | else |
279 | usb_dbg(usbatm, "%s: BLOCK0 downloaded (%d bytes)\n", __func__, ret); | |
280 | } | |
281 | ||
282 | /* URB 8 : both leds are static green */ | |
283 | for (offset = 0; offset < fw1->size; offset += PAGE_SIZE) { | |
284 | int thislen = min_t(int, PAGE_SIZE, fw1->size - offset); | |
285 | memcpy(buffer, fw1->data + offset, thislen); | |
286 | ||
287 | ret = usb_bulk_msg(usb_dev, usb_sndbulkpipe(usb_dev, ENDPOINT_FIRMWARE), | |
288 | buffer, thislen, &actual_length, DATA_TIMEOUT); | |
289 | ||
290 | if (ret < 0) { | |
0ec3c7e8 | 291 | usb_err(usbatm, "%s: write BLOCK1 to modem failed (%d)!\n", __func__, ret); |
48da7267 DS |
292 | goto out_free; |
293 | } | |
294 | usb_dbg(usbatm, "%s: BLOCK1 uploaded (%zu bytes)\n", __func__, fw1->size); | |
295 | } | |
296 | ||
297 | /* USB led blinking green, ADSL led off */ | |
298 | ||
299 | /* URB 11 */ | |
300 | ret = usb_bulk_msg(usb_dev, usb_rcvbulkpipe(usb_dev, ENDPOINT_FIRMWARE), | |
301 | buffer, 0x200, &actual_length, DATA_TIMEOUT); | |
1da177e4 | 302 | |
1da177e4 | 303 | if (ret < 0) { |
0ec3c7e8 | 304 | usb_err(usbatm, "%s: read BLOCK2 from modem failed (%d)!\n", __func__, ret); |
48da7267 | 305 | goto out_free; |
1da177e4 | 306 | } |
48da7267 | 307 | usb_dbg(usbatm, "%s: BLOCK2 downloaded (%d bytes)\n", __func__, actual_length); |
1da177e4 | 308 | |
48da7267 DS |
309 | /* URBs 12 to 139 - USB led blinking green, ADSL led off */ |
310 | for (offset = 0; offset < fw2->size; offset += PAGE_SIZE) { | |
311 | int thislen = min_t(int, PAGE_SIZE, fw2->size - offset); | |
312 | memcpy(buffer, fw2->data + offset, thislen); | |
313 | ||
314 | ret = usb_bulk_msg(usb_dev, usb_sndbulkpipe(usb_dev, ENDPOINT_FIRMWARE), | |
315 | buffer, thislen, &actual_length, DATA_TIMEOUT); | |
316 | ||
317 | if (ret < 0) { | |
0ec3c7e8 | 318 | usb_err(usbatm, "%s: write BLOCK3 to modem failed (%d)!\n", __func__, ret); |
48da7267 DS |
319 | goto out_free; |
320 | } | |
321 | } | |
322 | usb_dbg(usbatm, "%s: BLOCK3 uploaded (%zu bytes)\n", __func__, fw2->size); | |
323 | ||
324 | /* USB led static green, ADSL led static red */ | |
325 | ||
326 | /* URB 142 */ | |
327 | ret = usb_bulk_msg(usb_dev, usb_rcvbulkpipe(usb_dev, ENDPOINT_FIRMWARE), | |
328 | buffer, 0x200, &actual_length, DATA_TIMEOUT); | |
329 | ||
330 | if (ret < 0) { | |
0ec3c7e8 | 331 | usb_err(usbatm, "%s: read BLOCK4 from modem failed (%d)!\n", __func__, ret); |
48da7267 DS |
332 | goto out_free; |
333 | } | |
334 | ||
335 | /* success */ | |
336 | usb_dbg(usbatm, "%s: BLOCK4 downloaded (%d bytes)\n", __func__, actual_length); | |
337 | ||
338 | /* Delay to allow firmware to start up. We can do this here | |
339 | because we're in our own kernel thread anyway. */ | |
340 | msleep_interruptible(1000); | |
341 | ||
6a4f1b41 DS |
342 | if ((ret = usb_set_interface(usb_dev, INTERFACE_DATA, instance->params.altsetting)) < 0) { |
343 | usb_err(usbatm, "%s: setting interface to %d failed (%d)!\n", __func__, instance->params.altsetting, ret); | |
6f749475 DS |
344 | goto out_free; |
345 | } | |
346 | ||
48da7267 DS |
347 | /* Enable software buffering, if requested */ |
348 | if (sw_buffering) | |
349 | speedtch_set_swbuff(instance, 1); | |
350 | ||
351 | /* Magic spell; don't ask us what this does */ | |
352 | speedtch_test_sequence(instance); | |
353 | ||
354 | ret = 0; | |
355 | ||
356 | out_free: | |
357 | free_page((unsigned long)buffer); | |
358 | out: | |
359 | return ret; | |
1da177e4 LT |
360 | } |
361 | ||
0ec3c7e8 DS |
362 | static int speedtch_find_firmware(struct usbatm_data *usbatm, struct usb_interface *intf, |
363 | int phase, const struct firmware **fw_p) | |
1da177e4 | 364 | { |
48da7267 DS |
365 | struct device *dev = &intf->dev; |
366 | const u16 bcdDevice = le16_to_cpu(interface_to_usbdev(intf)->descriptor.bcdDevice); | |
367 | const u8 major_revision = bcdDevice >> 8; | |
368 | const u8 minor_revision = bcdDevice & 0xff; | |
369 | char buf[24]; | |
1da177e4 | 370 | |
48da7267 | 371 | sprintf(buf, "speedtch-%d.bin.%x.%02x", phase, major_revision, minor_revision); |
0ec3c7e8 | 372 | usb_dbg(usbatm, "%s: looking for %s\n", __func__, buf); |
1da177e4 | 373 | |
48da7267 DS |
374 | if (request_firmware(fw_p, buf, dev)) { |
375 | sprintf(buf, "speedtch-%d.bin.%x", phase, major_revision); | |
0ec3c7e8 | 376 | usb_dbg(usbatm, "%s: looking for %s\n", __func__, buf); |
1da177e4 | 377 | |
48da7267 DS |
378 | if (request_firmware(fw_p, buf, dev)) { |
379 | sprintf(buf, "speedtch-%d.bin", phase); | |
0ec3c7e8 | 380 | usb_dbg(usbatm, "%s: looking for %s\n", __func__, buf); |
48da7267 DS |
381 | |
382 | if (request_firmware(fw_p, buf, dev)) { | |
0ec3c7e8 | 383 | usb_err(usbatm, "%s: no stage %d firmware found!\n", __func__, phase); |
48da7267 DS |
384 | return -ENOENT; |
385 | } | |
386 | } | |
1da177e4 LT |
387 | } |
388 | ||
0ec3c7e8 | 389 | usb_info(usbatm, "found stage %d firmware %s\n", phase, buf); |
1da177e4 | 390 | |
48da7267 DS |
391 | return 0; |
392 | } | |
393 | ||
394 | static int speedtch_heavy_init(struct usbatm_data *usbatm, struct usb_interface *intf) | |
395 | { | |
396 | const struct firmware *fw1, *fw2; | |
397 | struct speedtch_instance_data *instance = usbatm->driver_data; | |
398 | int ret; | |
399 | ||
0ec3c7e8 DS |
400 | if ((ret = speedtch_find_firmware(usbatm, intf, 1, &fw1)) < 0) |
401 | return ret; | |
48da7267 | 402 | |
0ec3c7e8 | 403 | if ((ret = speedtch_find_firmware(usbatm, intf, 2, &fw2)) < 0) { |
48da7267 DS |
404 | release_firmware(fw1); |
405 | return ret; | |
1da177e4 | 406 | } |
1da177e4 | 407 | |
0ec3c7e8 DS |
408 | if ((ret = speedtch_upload_firmware(instance, fw1, fw2)) < 0) |
409 | usb_err(usbatm, "%s: firmware upload failed (%d)!\n", __func__, ret); | |
48da7267 DS |
410 | |
411 | release_firmware(fw2); | |
412 | release_firmware(fw1); | |
1da177e4 | 413 | |
48da7267 | 414 | return ret; |
1da177e4 LT |
415 | } |
416 | ||
48da7267 DS |
417 | |
418 | /********** | |
419 | ** ATM ** | |
420 | **********/ | |
421 | ||
422 | static int speedtch_read_status(struct speedtch_instance_data *instance) | |
1da177e4 | 423 | { |
48da7267 DS |
424 | struct usbatm_data *usbatm = instance->usbatm; |
425 | struct usb_device *usb_dev = usbatm->usb_dev; | |
426 | unsigned char *buf = instance->scratch_buffer; | |
1da177e4 LT |
427 | int ret; |
428 | ||
6a4f1b41 | 429 | memset(buf, 0, 16); |
1da177e4 | 430 | |
48da7267 | 431 | ret = usb_control_msg(usb_dev, usb_rcvctrlpipe(usb_dev, 0), |
1da177e4 LT |
432 | 0x12, 0xc0, 0x07, 0x00, buf + OFFSET_7, SIZE_7, |
433 | CTRL_TIMEOUT); | |
434 | if (ret < 0) { | |
48da7267 | 435 | atm_dbg(usbatm, "%s: MSG 7 failed\n", __func__); |
1da177e4 LT |
436 | return ret; |
437 | } | |
438 | ||
48da7267 | 439 | ret = usb_control_msg(usb_dev, usb_rcvctrlpipe(usb_dev, 0), |
1da177e4 LT |
440 | 0x12, 0xc0, 0x0b, 0x00, buf + OFFSET_b, SIZE_b, |
441 | CTRL_TIMEOUT); | |
442 | if (ret < 0) { | |
48da7267 | 443 | atm_dbg(usbatm, "%s: MSG B failed\n", __func__); |
1da177e4 LT |
444 | return ret; |
445 | } | |
446 | ||
48da7267 | 447 | ret = usb_control_msg(usb_dev, usb_rcvctrlpipe(usb_dev, 0), |
1da177e4 LT |
448 | 0x12, 0xc0, 0x0d, 0x00, buf + OFFSET_d, SIZE_d, |
449 | CTRL_TIMEOUT); | |
450 | if (ret < 0) { | |
48da7267 | 451 | atm_dbg(usbatm, "%s: MSG D failed\n", __func__); |
1da177e4 LT |
452 | return ret; |
453 | } | |
454 | ||
48da7267 | 455 | ret = usb_control_msg(usb_dev, usb_rcvctrlpipe(usb_dev, 0), |
1da177e4 LT |
456 | 0x01, 0xc0, 0x0e, 0x00, buf + OFFSET_e, SIZE_e, |
457 | CTRL_TIMEOUT); | |
458 | if (ret < 0) { | |
48da7267 | 459 | atm_dbg(usbatm, "%s: MSG E failed\n", __func__); |
1da177e4 LT |
460 | return ret; |
461 | } | |
462 | ||
48da7267 | 463 | ret = usb_control_msg(usb_dev, usb_rcvctrlpipe(usb_dev, 0), |
1da177e4 LT |
464 | 0x01, 0xc0, 0x0f, 0x00, buf + OFFSET_f, SIZE_f, |
465 | CTRL_TIMEOUT); | |
466 | if (ret < 0) { | |
48da7267 | 467 | atm_dbg(usbatm, "%s: MSG F failed\n", __func__); |
1da177e4 LT |
468 | return ret; |
469 | } | |
470 | ||
471 | return 0; | |
472 | } | |
473 | ||
48da7267 | 474 | static int speedtch_start_synchro(struct speedtch_instance_data *instance) |
1da177e4 | 475 | { |
48da7267 DS |
476 | struct usbatm_data *usbatm = instance->usbatm; |
477 | struct usb_device *usb_dev = usbatm->usb_dev; | |
478 | unsigned char *buf = instance->scratch_buffer; | |
1da177e4 LT |
479 | int ret; |
480 | ||
48da7267 DS |
481 | atm_dbg(usbatm, "%s entered\n", __func__); |
482 | ||
483 | memset(buf, 0, 2); | |
484 | ||
485 | ret = usb_control_msg(usb_dev, usb_rcvctrlpipe(usb_dev, 0), | |
486 | 0x12, 0xc0, 0x04, 0x00, | |
487 | buf, 2, CTRL_TIMEOUT); | |
488 | ||
489 | if (ret < 0) | |
490 | atm_warn(usbatm, "failed to start ADSL synchronisation: %d\n", ret); | |
491 | else | |
492 | atm_dbg(usbatm, "%s: modem prodded. %d bytes returned: %02x %02x\n", | |
493 | __func__, ret, buf[0], buf[1]); | |
494 | ||
495 | return ret; | |
496 | } | |
497 | ||
c4028958 | 498 | static void speedtch_check_status(struct work_struct *work) |
48da7267 | 499 | { |
c4028958 DH |
500 | struct speedtch_instance_data *instance = |
501 | container_of(work, struct speedtch_instance_data, | |
37c95bfe | 502 | status_check_work); |
48da7267 DS |
503 | struct usbatm_data *usbatm = instance->usbatm; |
504 | struct atm_dev *atm_dev = usbatm->atm_dev; | |
505 | unsigned char *buf = instance->scratch_buffer; | |
1a7aad15 DS |
506 | int down_speed, up_speed, ret; |
507 | unsigned char status; | |
48da7267 | 508 | |
0ec3c7e8 | 509 | #ifdef VERBOSE_DEBUG |
48da7267 | 510 | atm_dbg(usbatm, "%s entered\n", __func__); |
0ec3c7e8 | 511 | #endif |
48da7267 DS |
512 | |
513 | ret = speedtch_read_status(instance); | |
514 | if (ret < 0) { | |
515 | atm_warn(usbatm, "error %d fetching device status\n", ret); | |
cd5c08fb | 516 | instance->poll_delay = min(2 * instance->poll_delay, MAX_POLL_DELAY); |
1da177e4 LT |
517 | return; |
518 | } | |
519 | ||
cd5c08fb | 520 | instance->poll_delay = max(instance->poll_delay / 2, MIN_POLL_DELAY); |
48da7267 | 521 | |
1a7aad15 | 522 | status = buf[OFFSET_7]; |
1da177e4 | 523 | |
1a7aad15 | 524 | if ((status != instance->last_status) || !status) { |
0ec3c7e8 DS |
525 | atm_dbg(usbatm, "%s: line state 0x%02x\n", __func__, status); |
526 | ||
1a7aad15 DS |
527 | switch (status) { |
528 | case 0: | |
23f89f04 | 529 | atm_dev_signal_change(atm_dev, ATM_PHY_SIG_LOST); |
1a7aad15 | 530 | if (instance->last_status) |
52fbae2a | 531 | atm_info(usbatm, "ADSL line is down\n"); |
1a7aad15 | 532 | /* It may never resync again unless we ask it to... */ |
48da7267 | 533 | ret = speedtch_start_synchro(instance); |
1a7aad15 | 534 | break; |
1da177e4 | 535 | |
1a7aad15 | 536 | case 0x08: |
23f89f04 | 537 | atm_dev_signal_change(atm_dev, ATM_PHY_SIG_UNKNOWN); |
52fbae2a | 538 | atm_info(usbatm, "ADSL line is blocked?\n"); |
1a7aad15 | 539 | break; |
1da177e4 | 540 | |
1a7aad15 | 541 | case 0x10: |
23f89f04 | 542 | atm_dev_signal_change(atm_dev, ATM_PHY_SIG_LOST); |
52fbae2a | 543 | atm_info(usbatm, "ADSL line is synchronising\n"); |
1a7aad15 | 544 | break; |
1da177e4 | 545 | |
1a7aad15 DS |
546 | case 0x20: |
547 | down_speed = buf[OFFSET_b] | (buf[OFFSET_b + 1] << 8) | |
1da177e4 | 548 | | (buf[OFFSET_b + 2] << 16) | (buf[OFFSET_b + 3] << 24); |
1a7aad15 | 549 | up_speed = buf[OFFSET_b + 4] | (buf[OFFSET_b + 5] << 8) |
1da177e4 LT |
550 | | (buf[OFFSET_b + 6] << 16) | (buf[OFFSET_b + 7] << 24); |
551 | ||
48da7267 | 552 | if (!(down_speed & 0x0000ffff) && !(up_speed & 0x0000ffff)) { |
1da177e4 LT |
553 | down_speed >>= 16; |
554 | up_speed >>= 16; | |
555 | } | |
1da177e4 | 556 | |
48da7267 | 557 | atm_dev->link_rate = down_speed * 1000 / 424; |
23f89f04 | 558 | atm_dev_signal_change(atm_dev, ATM_PHY_SIG_FOUND); |
48da7267 DS |
559 | |
560 | atm_info(usbatm, | |
322a95bc | 561 | "ADSL line is up (%d kb/s down | %d kb/s up)\n", |
48da7267 | 562 | down_speed, up_speed); |
1a7aad15 | 563 | break; |
1da177e4 | 564 | |
1a7aad15 | 565 | default: |
23f89f04 | 566 | atm_dev_signal_change(atm_dev, ATM_PHY_SIG_UNKNOWN); |
0ec3c7e8 | 567 | atm_info(usbatm, "unknown line state %02x\n", status); |
1a7aad15 | 568 | break; |
1da177e4 | 569 | } |
1a7aad15 DS |
570 | |
571 | instance->last_status = status; | |
1da177e4 LT |
572 | } |
573 | } | |
574 | ||
48da7267 | 575 | static void speedtch_status_poll(unsigned long data) |
1da177e4 LT |
576 | { |
577 | struct speedtch_instance_data *instance = (void *)data; | |
578 | ||
37c95bfe | 579 | schedule_work(&instance->status_check_work); |
48da7267 DS |
580 | |
581 | /* The following check is racy, but the race is harmless */ | |
582 | if (instance->poll_delay < MAX_POLL_DELAY) | |
37c95bfe | 583 | mod_timer(&instance->status_check_timer, jiffies + msecs_to_jiffies(instance->poll_delay)); |
48da7267 | 584 | else |
52fbae2a | 585 | atm_warn(instance->usbatm, "Too many failures - disabling line status polling\n"); |
1da177e4 LT |
586 | } |
587 | ||
48da7267 | 588 | static void speedtch_resubmit_int(unsigned long data) |
1da177e4 | 589 | { |
48da7267 DS |
590 | struct speedtch_instance_data *instance = (void *)data; |
591 | struct urb *int_urb = instance->int_urb; | |
592 | int ret; | |
1da177e4 | 593 | |
48da7267 | 594 | atm_dbg(instance->usbatm, "%s entered\n", __func__); |
1da177e4 | 595 | |
48da7267 DS |
596 | if (int_urb) { |
597 | ret = usb_submit_urb(int_urb, GFP_ATOMIC); | |
598 | if (!ret) | |
37c95bfe | 599 | schedule_work(&instance->status_check_work); |
48da7267 DS |
600 | else { |
601 | atm_dbg(instance->usbatm, "%s: usb_submit_urb failed with result %d\n", __func__, ret); | |
602 | mod_timer(&instance->resubmit_timer, jiffies + msecs_to_jiffies(RESUBMIT_DELAY)); | |
1da177e4 | 603 | } |
1da177e4 | 604 | } |
48da7267 | 605 | } |
1da177e4 | 606 | |
7d12e780 | 607 | static void speedtch_handle_int(struct urb *int_urb) |
48da7267 DS |
608 | { |
609 | struct speedtch_instance_data *instance = int_urb->context; | |
610 | struct usbatm_data *usbatm = instance->usbatm; | |
611 | unsigned int count = int_urb->actual_length; | |
9a5a3e95 GKH |
612 | int status = int_urb->status; |
613 | int ret; | |
1da177e4 | 614 | |
48da7267 | 615 | /* The magic interrupt for "up state" */ |
3c6bee1d | 616 | static const unsigned char up_int[6] = { 0xa1, 0x00, 0x01, 0x00, 0x00, 0x00 }; |
48da7267 | 617 | /* The magic interrupt for "down state" */ |
3c6bee1d | 618 | static const unsigned char down_int[6] = { 0xa1, 0x00, 0x00, 0x00, 0x00, 0x00 }; |
48da7267 DS |
619 | |
620 | atm_dbg(usbatm, "%s entered\n", __func__); | |
1da177e4 | 621 | |
9a5a3e95 GKH |
622 | if (status < 0) { |
623 | atm_dbg(usbatm, "%s: nonzero urb status %d!\n", __func__, status); | |
48da7267 | 624 | goto fail; |
1da177e4 | 625 | } |
1da177e4 | 626 | |
48da7267 | 627 | if ((count == 6) && !memcmp(up_int, instance->int_data, 6)) { |
37c95bfe | 628 | del_timer(&instance->status_check_timer); |
52fbae2a | 629 | atm_info(usbatm, "DSL line goes up\n"); |
48da7267 | 630 | } else if ((count == 6) && !memcmp(down_int, instance->int_data, 6)) { |
52fbae2a | 631 | atm_info(usbatm, "DSL line goes down\n"); |
48da7267 DS |
632 | } else { |
633 | int i; | |
1da177e4 | 634 | |
48da7267 DS |
635 | atm_dbg(usbatm, "%s: unknown interrupt packet of length %d:", __func__, count); |
636 | for (i = 0; i < count; i++) | |
637 | printk(" %02x", instance->int_data[i]); | |
638 | printk("\n"); | |
639 | goto fail; | |
640 | } | |
1da177e4 | 641 | |
3383ee4c GKH |
642 | int_urb = instance->int_urb; |
643 | if (int_urb) { | |
48da7267 | 644 | ret = usb_submit_urb(int_urb, GFP_ATOMIC); |
37c95bfe | 645 | schedule_work(&instance->status_check_work); |
1da177e4 | 646 | if (ret < 0) { |
48da7267 DS |
647 | atm_dbg(usbatm, "%s: usb_submit_urb failed with result %d\n", __func__, ret); |
648 | goto fail; | |
1da177e4 LT |
649 | } |
650 | } | |
1da177e4 | 651 | |
1da177e4 LT |
652 | return; |
653 | ||
48da7267 | 654 | fail: |
3383ee4c GKH |
655 | int_urb = instance->int_urb; |
656 | if (int_urb) | |
48da7267 | 657 | mod_timer(&instance->resubmit_timer, jiffies + msecs_to_jiffies(RESUBMIT_DELAY)); |
1da177e4 LT |
658 | } |
659 | ||
48da7267 | 660 | static int speedtch_atm_start(struct usbatm_data *usbatm, struct atm_dev *atm_dev) |
1da177e4 | 661 | { |
48da7267 DS |
662 | struct usb_device *usb_dev = usbatm->usb_dev; |
663 | struct speedtch_instance_data *instance = usbatm->driver_data; | |
664 | int i, ret; | |
665 | unsigned char mac_str[13]; | |
1da177e4 | 666 | |
48da7267 | 667 | atm_dbg(usbatm, "%s entered\n", __func__); |
1da177e4 | 668 | |
48da7267 DS |
669 | /* Set MAC address, it is stored in the serial number */ |
670 | memset(atm_dev->esi, 0, sizeof(atm_dev->esi)); | |
671 | if (usb_string(usb_dev, usb_dev->descriptor.iSerialNumber, mac_str, sizeof(mac_str)) == 12) { | |
672 | for (i = 0; i < 6; i++) | |
96b89f32 AS |
673 | atm_dev->esi[i] = (hex_to_bin(mac_str[i * 2]) << 4) + |
674 | hex_to_bin(mac_str[i * 2 + 1]); | |
48da7267 | 675 | } |
1da177e4 | 676 | |
48da7267 DS |
677 | /* Start modem synchronisation */ |
678 | ret = speedtch_start_synchro(instance); | |
1da177e4 | 679 | |
48da7267 DS |
680 | /* Set up interrupt endpoint */ |
681 | if (instance->int_urb) { | |
682 | ret = usb_submit_urb(instance->int_urb, GFP_KERNEL); | |
683 | if (ret < 0) { | |
684 | /* Doesn't matter; we'll poll anyway */ | |
685 | atm_dbg(usbatm, "%s: submission of interrupt URB failed (%d)!\n", __func__, ret); | |
686 | usb_free_urb(instance->int_urb); | |
687 | instance->int_urb = NULL; | |
1da177e4 | 688 | } |
1da177e4 LT |
689 | } |
690 | ||
48da7267 | 691 | /* Start status polling */ |
37c95bfe | 692 | mod_timer(&instance->status_check_timer, jiffies + msecs_to_jiffies(1000)); |
1da177e4 | 693 | |
1da177e4 LT |
694 | return 0; |
695 | } | |
1da177e4 | 696 | |
48da7267 | 697 | static void speedtch_atm_stop(struct usbatm_data *usbatm, struct atm_dev *atm_dev) |
1da177e4 | 698 | { |
48da7267 DS |
699 | struct speedtch_instance_data *instance = usbatm->driver_data; |
700 | struct urb *int_urb = instance->int_urb; | |
701 | ||
702 | atm_dbg(usbatm, "%s entered\n", __func__); | |
703 | ||
37c95bfe | 704 | del_timer_sync(&instance->status_check_timer); |
48da7267 DS |
705 | |
706 | /* | |
707 | * Since resubmit_timer and int_urb can schedule themselves and | |
708 | * each other, shutting them down correctly takes some care | |
709 | */ | |
710 | instance->int_urb = NULL; /* signal shutdown */ | |
711 | mb(); | |
712 | usb_kill_urb(int_urb); | |
713 | del_timer_sync(&instance->resubmit_timer); | |
714 | /* | |
715 | * At this point, speedtch_handle_int and speedtch_resubmit_int | |
716 | * can run or be running, but instance->int_urb == NULL means that | |
717 | * they will not reschedule | |
718 | */ | |
719 | usb_kill_urb(int_urb); | |
720 | del_timer_sync(&instance->resubmit_timer); | |
721 | usb_free_urb(int_urb); | |
1da177e4 | 722 | |
43829731 | 723 | flush_work(&instance->status_check_work); |
48da7267 | 724 | } |
1da177e4 | 725 | |
8fc7aeab AS |
726 | static int speedtch_pre_reset(struct usb_interface *intf) |
727 | { | |
728 | return 0; | |
729 | } | |
730 | ||
731 | static int speedtch_post_reset(struct usb_interface *intf) | |
732 | { | |
733 | return 0; | |
734 | } | |
735 | ||
1da177e4 | 736 | |
48da7267 DS |
737 | /********** |
738 | ** USB ** | |
739 | **********/ | |
1da177e4 | 740 | |
48da7267 DS |
741 | static struct usb_device_id speedtch_usb_ids[] = { |
742 | {USB_DEVICE(0x06b9, 0x4061)}, | |
743 | {} | |
744 | }; | |
1da177e4 | 745 | |
48da7267 | 746 | MODULE_DEVICE_TABLE(usb, speedtch_usb_ids); |
1da177e4 | 747 | |
48da7267 | 748 | static int speedtch_usb_probe(struct usb_interface *, const struct usb_device_id *); |
1da177e4 | 749 | |
48da7267 | 750 | static struct usb_driver speedtch_usb_driver = { |
48da7267 DS |
751 | .name = speedtch_driver_name, |
752 | .probe = speedtch_usb_probe, | |
753 | .disconnect = usbatm_usb_disconnect, | |
8fc7aeab AS |
754 | .pre_reset = speedtch_pre_reset, |
755 | .post_reset = speedtch_post_reset, | |
48da7267 DS |
756 | .id_table = speedtch_usb_ids |
757 | }; | |
1da177e4 | 758 | |
6c4b7f70 NK |
759 | static void speedtch_release_interfaces(struct usb_device *usb_dev, |
760 | int num_interfaces) | |
761 | { | |
48da7267 DS |
762 | struct usb_interface *cur_intf; |
763 | int i; | |
1da177e4 | 764 | |
3383ee4c GKH |
765 | for (i = 0; i < num_interfaces; i++) { |
766 | cur_intf = usb_ifnum_to_if(usb_dev, i); | |
767 | if (cur_intf) { | |
48da7267 DS |
768 | usb_set_intfdata(cur_intf, NULL); |
769 | usb_driver_release_interface(&speedtch_usb_driver, cur_intf); | |
770 | } | |
3383ee4c | 771 | } |
1da177e4 LT |
772 | } |
773 | ||
48da7267 DS |
774 | static int speedtch_bind(struct usbatm_data *usbatm, |
775 | struct usb_interface *intf, | |
35644b0c | 776 | const struct usb_device_id *id) |
1da177e4 | 777 | { |
48da7267 | 778 | struct usb_device *usb_dev = interface_to_usbdev(intf); |
80aae7a1 | 779 | struct usb_interface *cur_intf, *data_intf; |
48da7267 DS |
780 | struct speedtch_instance_data *instance; |
781 | int ifnum = intf->altsetting->desc.bInterfaceNumber; | |
782 | int num_interfaces = usb_dev->actconfig->desc.bNumInterfaces; | |
783 | int i, ret; | |
80aae7a1 | 784 | int use_isoc; |
1da177e4 | 785 | |
48da7267 | 786 | usb_dbg(usbatm, "%s entered\n", __func__); |
1da177e4 | 787 | |
0ec3c7e8 DS |
788 | /* sanity checks */ |
789 | ||
48da7267 | 790 | if (usb_dev->descriptor.bDeviceClass != USB_CLASS_VENDOR_SPEC) { |
0ec3c7e8 | 791 | usb_err(usbatm, "%s: wrong device class %d\n", __func__, usb_dev->descriptor.bDeviceClass); |
1da177e4 LT |
792 | return -ENODEV; |
793 | } | |
794 | ||
3383ee4c GKH |
795 | data_intf = usb_ifnum_to_if(usb_dev, INTERFACE_DATA); |
796 | if (!data_intf) { | |
80aae7a1 DS |
797 | usb_err(usbatm, "%s: data interface not found!\n", __func__); |
798 | return -ENODEV; | |
799 | } | |
800 | ||
48da7267 | 801 | /* claim all interfaces */ |
1da177e4 | 802 | |
9196cc7b | 803 | for (i = 0; i < num_interfaces; i++) { |
48da7267 | 804 | cur_intf = usb_ifnum_to_if(usb_dev, i); |
1da177e4 | 805 | |
48da7267 DS |
806 | if ((i != ifnum) && cur_intf) { |
807 | ret = usb_driver_claim_interface(&speedtch_usb_driver, cur_intf, usbatm); | |
1da177e4 | 808 | |
48da7267 | 809 | if (ret < 0) { |
0ec3c7e8 | 810 | usb_err(usbatm, "%s: failed to claim interface %2d (%d)!\n", __func__, i, ret); |
48da7267 DS |
811 | speedtch_release_interfaces(usb_dev, i); |
812 | return ret; | |
813 | } | |
814 | } | |
815 | } | |
1da177e4 | 816 | |
9a734efe | 817 | instance = kzalloc(sizeof(*instance), GFP_KERNEL); |
48da7267 | 818 | |
1da177e4 | 819 | if (!instance) { |
0ec3c7e8 | 820 | usb_err(usbatm, "%s: no memory for instance data!\n", __func__); |
48da7267 DS |
821 | ret = -ENOMEM; |
822 | goto fail_release; | |
1da177e4 LT |
823 | } |
824 | ||
48da7267 | 825 | instance->usbatm = usbatm; |
1da177e4 | 826 | |
6a4f1b41 DS |
827 | /* module parameters may change at any moment, so take a snapshot */ |
828 | instance->params.altsetting = altsetting; | |
829 | instance->params.BMaxDSL = BMaxDSL; | |
830 | instance->params.ModemMode = ModemMode; | |
831 | memcpy(instance->params.ModemOption, DEFAULT_MODEM_OPTION, MODEM_OPTION_LENGTH); | |
832 | memcpy(instance->params.ModemOption, ModemOption, num_ModemOption); | |
80aae7a1 | 833 | use_isoc = enable_isoc; |
6f749475 | 834 | |
6a4f1b41 DS |
835 | if (instance->params.altsetting) |
836 | if ((ret = usb_set_interface(usb_dev, INTERFACE_DATA, instance->params.altsetting)) < 0) { | |
837 | usb_err(usbatm, "%s: setting interface to %2d failed (%d)!\n", __func__, instance->params.altsetting, ret); | |
838 | instance->params.altsetting = 0; /* fall back to default */ | |
6f749475 DS |
839 | } |
840 | ||
6a4f1b41 | 841 | if (!instance->params.altsetting && use_isoc) |
80aae7a1 DS |
842 | if ((ret = usb_set_interface(usb_dev, INTERFACE_DATA, DEFAULT_ISOC_ALTSETTING)) < 0) { |
843 | usb_dbg(usbatm, "%s: setting interface to %2d failed (%d)!\n", __func__, DEFAULT_ISOC_ALTSETTING, ret); | |
844 | use_isoc = 0; /* fall back to bulk */ | |
6f749475 | 845 | } |
80aae7a1 DS |
846 | |
847 | if (use_isoc) { | |
848 | const struct usb_host_interface *desc = data_intf->cur_altsetting; | |
849 | const __u8 target_address = USB_DIR_IN | usbatm->driver->isoc_in; | |
80aae7a1 DS |
850 | |
851 | use_isoc = 0; /* fall back to bulk if endpoint not found */ | |
852 | ||
9196cc7b | 853 | for (i = 0; i < desc->desc.bNumEndpoints; i++) { |
80aae7a1 DS |
854 | const struct usb_endpoint_descriptor *endpoint_desc = &desc->endpoint[i].desc; |
855 | ||
856 | if ((endpoint_desc->bEndpointAddress == target_address)) { | |
c5dd1f94 LFC |
857 | use_isoc = |
858 | usb_endpoint_xfer_isoc(endpoint_desc); | |
80aae7a1 DS |
859 | break; |
860 | } | |
861 | } | |
862 | ||
863 | if (!use_isoc) | |
864 | usb_info(usbatm, "isochronous transfer not supported - using bulk\n"); | |
6f749475 DS |
865 | } |
866 | ||
6a4f1b41 | 867 | if (!use_isoc && !instance->params.altsetting) |
80aae7a1 DS |
868 | if ((ret = usb_set_interface(usb_dev, INTERFACE_DATA, DEFAULT_BULK_ALTSETTING)) < 0) { |
869 | usb_err(usbatm, "%s: setting interface to %2d failed (%d)!\n", __func__, DEFAULT_BULK_ALTSETTING, ret); | |
870 | goto fail_free; | |
871 | } | |
872 | ||
6a4f1b41 DS |
873 | if (!instance->params.altsetting) |
874 | instance->params.altsetting = use_isoc ? DEFAULT_ISOC_ALTSETTING : DEFAULT_BULK_ALTSETTING; | |
80aae7a1 DS |
875 | |
876 | usbatm->flags |= (use_isoc ? UDSL_USE_ISOC : 0); | |
877 | ||
37c95bfe TH |
878 | INIT_WORK(&instance->status_check_work, speedtch_check_status); |
879 | init_timer(&instance->status_check_timer); | |
1da177e4 | 880 | |
37c95bfe TH |
881 | instance->status_check_timer.function = speedtch_status_poll; |
882 | instance->status_check_timer.data = (unsigned long)instance; | |
1a7aad15 | 883 | instance->last_status = 0xff; |
48da7267 | 884 | instance->poll_delay = MIN_POLL_DELAY; |
1da177e4 | 885 | |
48da7267 DS |
886 | init_timer(&instance->resubmit_timer); |
887 | instance->resubmit_timer.function = speedtch_resubmit_int; | |
888 | instance->resubmit_timer.data = (unsigned long)instance; | |
1da177e4 | 889 | |
48da7267 | 890 | instance->int_urb = usb_alloc_urb(0, GFP_KERNEL); |
1da177e4 | 891 | |
48da7267 DS |
892 | if (instance->int_urb) |
893 | usb_fill_int_urb(instance->int_urb, usb_dev, | |
894 | usb_rcvintpipe(usb_dev, ENDPOINT_INT), | |
895 | instance->int_data, sizeof(instance->int_data), | |
afb8aae8 | 896 | speedtch_handle_int, instance, 16); |
48da7267 DS |
897 | else |
898 | usb_dbg(usbatm, "%s: no memory for interrupt urb!\n", __func__); | |
1da177e4 | 899 | |
48da7267 DS |
900 | /* check whether the modem already seems to be alive */ |
901 | ret = usb_control_msg(usb_dev, usb_rcvctrlpipe(usb_dev, 0), | |
902 | 0x12, 0xc0, 0x07, 0x00, | |
903 | instance->scratch_buffer + OFFSET_7, SIZE_7, 500); | |
1da177e4 | 904 | |
80aae7a1 | 905 | usbatm->flags |= (ret == SIZE_7 ? UDSL_SKIP_HEAVY_INIT : 0); |
1da177e4 | 906 | |
35644b0c | 907 | usb_dbg(usbatm, "%s: firmware %s loaded\n", __func__, usbatm->flags & UDSL_SKIP_HEAVY_INIT ? "already" : "not"); |
48da7267 | 908 | |
35644b0c | 909 | if (!(usbatm->flags & UDSL_SKIP_HEAVY_INIT)) |
0ec3c7e8 DS |
910 | if ((ret = usb_reset_device(usb_dev)) < 0) { |
911 | usb_err(usbatm, "%s: device reset failed (%d)!\n", __func__, ret); | |
48da7267 | 912 | goto fail_free; |
0ec3c7e8 | 913 | } |
1da177e4 | 914 | |
48da7267 | 915 | usbatm->driver_data = instance; |
1da177e4 LT |
916 | |
917 | return 0; | |
918 | ||
48da7267 DS |
919 | fail_free: |
920 | usb_free_urb(instance->int_urb); | |
1da177e4 | 921 | kfree(instance); |
48da7267 DS |
922 | fail_release: |
923 | speedtch_release_interfaces(usb_dev, num_interfaces); | |
924 | return ret; | |
1da177e4 LT |
925 | } |
926 | ||
48da7267 | 927 | static void speedtch_unbind(struct usbatm_data *usbatm, struct usb_interface *intf) |
1da177e4 | 928 | { |
48da7267 DS |
929 | struct usb_device *usb_dev = interface_to_usbdev(intf); |
930 | struct speedtch_instance_data *instance = usbatm->driver_data; | |
1da177e4 | 931 | |
48da7267 | 932 | usb_dbg(usbatm, "%s entered\n", __func__); |
1da177e4 | 933 | |
48da7267 DS |
934 | speedtch_release_interfaces(usb_dev, usb_dev->actconfig->desc.bNumInterfaces); |
935 | usb_free_urb(instance->int_urb); | |
936 | kfree(instance); | |
1da177e4 LT |
937 | } |
938 | ||
48da7267 | 939 | |
1da177e4 LT |
940 | /*********** |
941 | ** init ** | |
942 | ***********/ | |
943 | ||
48da7267 | 944 | static struct usbatm_driver speedtch_usbatm_driver = { |
48da7267 DS |
945 | .driver_name = speedtch_driver_name, |
946 | .bind = speedtch_bind, | |
947 | .heavy_init = speedtch_heavy_init, | |
948 | .unbind = speedtch_unbind, | |
949 | .atm_start = speedtch_atm_start, | |
950 | .atm_stop = speedtch_atm_stop, | |
80aae7a1 DS |
951 | .bulk_in = ENDPOINT_BULK_DATA, |
952 | .bulk_out = ENDPOINT_BULK_DATA, | |
953 | .isoc_in = ENDPOINT_ISOC_DATA | |
48da7267 DS |
954 | }; |
955 | ||
956 | static int speedtch_usb_probe(struct usb_interface *intf, const struct usb_device_id *id) | |
957 | { | |
958 | return usbatm_usb_probe(intf, id, &speedtch_usbatm_driver); | |
959 | } | |
960 | ||
65db4305 | 961 | module_usb_driver(speedtch_usb_driver); |
1da177e4 LT |
962 | |
963 | MODULE_AUTHOR(DRIVER_AUTHOR); | |
964 | MODULE_DESCRIPTION(DRIVER_DESC); | |
965 | MODULE_LICENSE("GPL"); | |
966 | MODULE_VERSION(DRIVER_VERSION); |