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