1 /******************************************************************************
2 * speedtch.c - Alcatel SpeedTouch USB xDSL modem driver
4 * Copyright (C) 2001, Alcatel
5 * Copyright (C) 2003, Duncan Sands
6 * Copyright (C) 2004, David Woodhouse
8 * Based on "modem_run.c", copyright (C) 2001, Benoit Papillault
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)
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
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.
24 ******************************************************************************/
27 #include <linux/device.h>
28 #include <linux/errno.h>
29 #include <linux/firmware.h>
30 #include <linux/gfp.h>
31 #include <linux/init.h>
32 #include <linux/kernel.h>
33 #include <linux/module.h>
34 #include <linux/moduleparam.h>
35 #include <linux/slab.h>
36 #include <linux/stat.h>
37 #include <linux/timer.h>
38 #include <linux/types.h>
39 #include <linux/usb_ch9.h>
40 #include <linux/workqueue.h>
44 #define DRIVER_AUTHOR "Johan Verrept, Duncan Sands <duncan.sands@free.fr>"
45 #define DRIVER_VERSION "1.10"
46 #define DRIVER_DESC "Alcatel SpeedTouch USB driver version " DRIVER_VERSION
48 static const char speedtch_driver_name[] = "speedtch";
50 #define CTRL_TIMEOUT 2000 /* milliseconds */
51 #define DATA_TIMEOUT 2000 /* milliseconds */
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 */
66 #define MIN_POLL_DELAY 5000 /* milliseconds */
67 #define MAX_POLL_DELAY 60000 /* milliseconds */
69 #define RESUBMIT_DELAY 1000 /* milliseconds */
71 #define DEFAULT_BULK_ALTSETTING 1
72 #define DEFAULT_ISOC_ALTSETTING 2
73 #define DEFAULT_DL_512_FIRST 0
74 #define DEFAULT_ENABLE_ISOC 0
75 #define DEFAULT_SW_BUFFERING 0
77 static unsigned int altsetting = 0; /* zero means: use the default */
78 static int dl_512_first = DEFAULT_DL_512_FIRST;
79 static int enable_isoc = DEFAULT_ENABLE_ISOC;
80 static int sw_buffering = DEFAULT_SW_BUFFERING;
82 module_param(altsetting, uint, S_IRUGO | S_IWUSR);
83 MODULE_PARM_DESC(altsetting,
84 "Alternative setting for data interface (bulk_default: "
85 __MODULE_STRING(DEFAULT_BULK_ALTSETTING) "; isoc_default: "
86 __MODULE_STRING(DEFAULT_ISOC_ALTSETTING) ")");
88 module_param(dl_512_first, bool, S_IRUGO | S_IWUSR);
89 MODULE_PARM_DESC(dl_512_first,
90 "Read 512 bytes before sending firmware (default: "
91 __MODULE_STRING(DEFAULT_DL_512_FIRST) ")");
93 module_param(enable_isoc, bool, S_IRUGO | S_IWUSR);
94 MODULE_PARM_DESC(enable_isoc,
95 "Use isochronous transfers if available (default: "
96 __MODULE_STRING(DEFAULT_ENABLE_ISOC) ")");
98 module_param(sw_buffering, bool, S_IRUGO | S_IWUSR);
99 MODULE_PARM_DESC(sw_buffering,
100 "Enable software buffering (default: "
101 __MODULE_STRING(DEFAULT_SW_BUFFERING) ")");
103 #define INTERFACE_DATA 1
104 #define ENDPOINT_INT 0x81
105 #define ENDPOINT_BULK_DATA 0x07
106 #define ENDPOINT_ISOC_DATA 0x07
107 #define ENDPOINT_FIRMWARE 0x05
109 #define hex2int(c) ( (c >= '0') && (c <= '9') ? (c - '0') : ((c & 0xf) + 9) )
111 struct speedtch_instance_data {
112 struct usbatm_data *usbatm;
114 unsigned int altsetting;
116 struct work_struct status_checker;
118 unsigned char last_status;
120 int poll_delay; /* milliseconds */
122 struct timer_list resubmit_timer;
124 unsigned char int_data[16];
126 unsigned char scratch_buffer[TOTAL];
133 static void speedtch_set_swbuff(struct speedtch_instance_data *instance, int state)
135 struct usbatm_data *usbatm = instance->usbatm;
136 struct usb_device *usb_dev = usbatm->usb_dev;
139 ret = usb_control_msg(usb_dev, usb_sndctrlpipe(usb_dev, 0),
140 0x32, 0x40, state ? 0x01 : 0x00, 0x00, NULL, 0, CTRL_TIMEOUT);
143 "%sabling SW buffering: usb_control_msg returned %d\n",
144 state ? "En" : "Dis", ret);
146 dbg("speedtch_set_swbuff: %sbled SW buffering", state ? "En" : "Dis");
149 static void speedtch_test_sequence(struct speedtch_instance_data *instance)
151 struct usbatm_data *usbatm = instance->usbatm;
152 struct usb_device *usb_dev = usbatm->usb_dev;
153 unsigned char *buf = instance->scratch_buffer;
159 ret = usb_control_msg(usb_dev, usb_sndctrlpipe(usb_dev, 0),
160 0x01, 0x40, 0x0b, 0x00, buf, 2, CTRL_TIMEOUT);
162 usb_warn(usbatm, "%s failed on URB147: %d\n", __func__, ret);
167 ret = usb_control_msg(usb_dev, usb_sndctrlpipe(usb_dev, 0),
168 0x01, 0x40, 0x02, 0x00, buf, 2, CTRL_TIMEOUT);
170 usb_warn(usbatm, "%s failed on URB148: %d\n", __func__, ret);
176 ret = usb_control_msg(usb_dev, usb_sndctrlpipe(usb_dev, 0),
177 0x01, 0x40, 0x03, 0x00, buf, 3, CTRL_TIMEOUT);
179 usb_warn(usbatm, "%s failed on URB149: %d\n", __func__, ret);
185 ret = usb_control_msg(usb_dev, usb_sndctrlpipe(usb_dev, 0),
186 0x01, 0x40, 0x04, 0x00, buf, 3, CTRL_TIMEOUT);
188 usb_warn(usbatm, "%s failed on URB150: %d\n", __func__, ret);
191 static int speedtch_upload_firmware(struct speedtch_instance_data *instance,
192 const struct firmware *fw1,
193 const struct firmware *fw2)
195 unsigned char *buffer;
196 struct usbatm_data *usbatm = instance->usbatm;
197 struct usb_interface *intf;
198 struct usb_device *usb_dev = usbatm->usb_dev;
203 usb_dbg(usbatm, "%s entered\n", __func__);
205 if (!(buffer = (unsigned char *)__get_free_page(GFP_KERNEL))) {
207 usb_dbg(usbatm, "%s: no memory for buffer!\n", __func__);
211 if (!(intf = usb_ifnum_to_if(usb_dev, 2))) {
213 usb_dbg(usbatm, "%s: interface not found!\n", __func__);
218 if (dl_512_first) { /* some modems need a read before writing the firmware */
219 ret = usb_bulk_msg(usb_dev, usb_rcvbulkpipe(usb_dev, ENDPOINT_FIRMWARE),
220 buffer, 0x200, &actual_length, 2000);
222 if (ret < 0 && ret != -ETIMEDOUT)
223 usb_warn(usbatm, "%s: read BLOCK0 from modem failed (%d)!\n", __func__, ret);
225 usb_dbg(usbatm, "%s: BLOCK0 downloaded (%d bytes)\n", __func__, ret);
228 /* URB 8 : both leds are static green */
229 for (offset = 0; offset < fw1->size; offset += PAGE_SIZE) {
230 int thislen = min_t(int, PAGE_SIZE, fw1->size - offset);
231 memcpy(buffer, fw1->data + offset, thislen);
233 ret = usb_bulk_msg(usb_dev, usb_sndbulkpipe(usb_dev, ENDPOINT_FIRMWARE),
234 buffer, thislen, &actual_length, DATA_TIMEOUT);
237 usb_err(usbatm, "%s: write BLOCK1 to modem failed (%d)!\n", __func__, ret);
240 usb_dbg(usbatm, "%s: BLOCK1 uploaded (%zu bytes)\n", __func__, fw1->size);
243 /* USB led blinking green, ADSL led off */
246 ret = usb_bulk_msg(usb_dev, usb_rcvbulkpipe(usb_dev, ENDPOINT_FIRMWARE),
247 buffer, 0x200, &actual_length, DATA_TIMEOUT);
250 usb_err(usbatm, "%s: read BLOCK2 from modem failed (%d)!\n", __func__, ret);
253 usb_dbg(usbatm, "%s: BLOCK2 downloaded (%d bytes)\n", __func__, actual_length);
255 /* URBs 12 to 139 - USB led blinking green, ADSL led off */
256 for (offset = 0; offset < fw2->size; offset += PAGE_SIZE) {
257 int thislen = min_t(int, PAGE_SIZE, fw2->size - offset);
258 memcpy(buffer, fw2->data + offset, thislen);
260 ret = usb_bulk_msg(usb_dev, usb_sndbulkpipe(usb_dev, ENDPOINT_FIRMWARE),
261 buffer, thislen, &actual_length, DATA_TIMEOUT);
264 usb_err(usbatm, "%s: write BLOCK3 to modem failed (%d)!\n", __func__, ret);
268 usb_dbg(usbatm, "%s: BLOCK3 uploaded (%zu bytes)\n", __func__, fw2->size);
270 /* USB led static green, ADSL led static red */
273 ret = usb_bulk_msg(usb_dev, usb_rcvbulkpipe(usb_dev, ENDPOINT_FIRMWARE),
274 buffer, 0x200, &actual_length, DATA_TIMEOUT);
277 usb_err(usbatm, "%s: read BLOCK4 from modem failed (%d)!\n", __func__, ret);
282 usb_dbg(usbatm, "%s: BLOCK4 downloaded (%d bytes)\n", __func__, actual_length);
284 /* Delay to allow firmware to start up. We can do this here
285 because we're in our own kernel thread anyway. */
286 msleep_interruptible(1000);
288 if ((ret = usb_set_interface(usb_dev, INTERFACE_DATA, instance->altsetting)) < 0) {
289 usb_err(usbatm, "%s: setting interface to %d failed (%d)!\n", __func__, instance->altsetting, ret);
293 /* Enable software buffering, if requested */
295 speedtch_set_swbuff(instance, 1);
297 /* Magic spell; don't ask us what this does */
298 speedtch_test_sequence(instance);
303 free_page((unsigned long)buffer);
308 static int speedtch_find_firmware(struct usbatm_data *usbatm, struct usb_interface *intf,
309 int phase, const struct firmware **fw_p)
311 struct device *dev = &intf->dev;
312 const u16 bcdDevice = le16_to_cpu(interface_to_usbdev(intf)->descriptor.bcdDevice);
313 const u8 major_revision = bcdDevice >> 8;
314 const u8 minor_revision = bcdDevice & 0xff;
317 sprintf(buf, "speedtch-%d.bin.%x.%02x", phase, major_revision, minor_revision);
318 usb_dbg(usbatm, "%s: looking for %s\n", __func__, buf);
320 if (request_firmware(fw_p, buf, dev)) {
321 sprintf(buf, "speedtch-%d.bin.%x", phase, major_revision);
322 usb_dbg(usbatm, "%s: looking for %s\n", __func__, buf);
324 if (request_firmware(fw_p, buf, dev)) {
325 sprintf(buf, "speedtch-%d.bin", phase);
326 usb_dbg(usbatm, "%s: looking for %s\n", __func__, buf);
328 if (request_firmware(fw_p, buf, dev)) {
329 usb_err(usbatm, "%s: no stage %d firmware found!\n", __func__, phase);
335 usb_info(usbatm, "found stage %d firmware %s\n", phase, buf);
340 static int speedtch_heavy_init(struct usbatm_data *usbatm, struct usb_interface *intf)
342 const struct firmware *fw1, *fw2;
343 struct speedtch_instance_data *instance = usbatm->driver_data;
346 if ((ret = speedtch_find_firmware(usbatm, intf, 1, &fw1)) < 0)
349 if ((ret = speedtch_find_firmware(usbatm, intf, 2, &fw2)) < 0) {
350 release_firmware(fw1);
354 if ((ret = speedtch_upload_firmware(instance, fw1, fw2)) < 0)
355 usb_err(usbatm, "%s: firmware upload failed (%d)!\n", __func__, ret);
357 release_firmware(fw2);
358 release_firmware(fw1);
368 static int speedtch_read_status(struct speedtch_instance_data *instance)
370 struct usbatm_data *usbatm = instance->usbatm;
371 struct usb_device *usb_dev = usbatm->usb_dev;
372 unsigned char *buf = instance->scratch_buffer;
375 memset(buf, 0, TOTAL);
377 ret = usb_control_msg(usb_dev, usb_rcvctrlpipe(usb_dev, 0),
378 0x12, 0xc0, 0x07, 0x00, buf + OFFSET_7, SIZE_7,
381 atm_dbg(usbatm, "%s: MSG 7 failed\n", __func__);
385 ret = usb_control_msg(usb_dev, usb_rcvctrlpipe(usb_dev, 0),
386 0x12, 0xc0, 0x0b, 0x00, buf + OFFSET_b, SIZE_b,
389 atm_dbg(usbatm, "%s: MSG B failed\n", __func__);
393 ret = usb_control_msg(usb_dev, usb_rcvctrlpipe(usb_dev, 0),
394 0x12, 0xc0, 0x0d, 0x00, buf + OFFSET_d, SIZE_d,
397 atm_dbg(usbatm, "%s: MSG D failed\n", __func__);
401 ret = usb_control_msg(usb_dev, usb_rcvctrlpipe(usb_dev, 0),
402 0x01, 0xc0, 0x0e, 0x00, buf + OFFSET_e, SIZE_e,
405 atm_dbg(usbatm, "%s: MSG E failed\n", __func__);
409 ret = usb_control_msg(usb_dev, usb_rcvctrlpipe(usb_dev, 0),
410 0x01, 0xc0, 0x0f, 0x00, buf + OFFSET_f, SIZE_f,
413 atm_dbg(usbatm, "%s: MSG F failed\n", __func__);
420 static int speedtch_start_synchro(struct speedtch_instance_data *instance)
422 struct usbatm_data *usbatm = instance->usbatm;
423 struct usb_device *usb_dev = usbatm->usb_dev;
424 unsigned char *buf = instance->scratch_buffer;
427 atm_dbg(usbatm, "%s entered\n", __func__);
431 ret = usb_control_msg(usb_dev, usb_rcvctrlpipe(usb_dev, 0),
432 0x12, 0xc0, 0x04, 0x00,
433 buf, 2, CTRL_TIMEOUT);
436 atm_warn(usbatm, "failed to start ADSL synchronisation: %d\n", ret);
438 atm_dbg(usbatm, "%s: modem prodded. %d bytes returned: %02x %02x\n",
439 __func__, ret, buf[0], buf[1]);
444 static void speedtch_check_status(struct speedtch_instance_data *instance)
446 struct usbatm_data *usbatm = instance->usbatm;
447 struct atm_dev *atm_dev = usbatm->atm_dev;
448 unsigned char *buf = instance->scratch_buffer;
449 int down_speed, up_speed, ret;
450 unsigned char status;
453 atm_dbg(usbatm, "%s entered\n", __func__);
456 ret = speedtch_read_status(instance);
458 atm_warn(usbatm, "error %d fetching device status\n", ret);
459 instance->poll_delay = min(2 * instance->poll_delay, MAX_POLL_DELAY);
463 instance->poll_delay = max(instance->poll_delay / 2, MIN_POLL_DELAY);
465 status = buf[OFFSET_7];
467 if ((status != instance->last_status) || !status) {
468 atm_dbg(usbatm, "%s: line state 0x%02x\n", __func__, status);
472 atm_dev->signal = ATM_PHY_SIG_LOST;
473 if (instance->last_status)
474 atm_info(usbatm, "ADSL line is down\n");
475 /* It may never resync again unless we ask it to... */
476 ret = speedtch_start_synchro(instance);
480 atm_dev->signal = ATM_PHY_SIG_UNKNOWN;
481 atm_info(usbatm, "ADSL line is blocked?\n");
485 atm_dev->signal = ATM_PHY_SIG_LOST;
486 atm_info(usbatm, "ADSL line is synchronising\n");
490 down_speed = buf[OFFSET_b] | (buf[OFFSET_b + 1] << 8)
491 | (buf[OFFSET_b + 2] << 16) | (buf[OFFSET_b + 3] << 24);
492 up_speed = buf[OFFSET_b + 4] | (buf[OFFSET_b + 5] << 8)
493 | (buf[OFFSET_b + 6] << 16) | (buf[OFFSET_b + 7] << 24);
495 if (!(down_speed & 0x0000ffff) && !(up_speed & 0x0000ffff)) {
500 atm_dev->link_rate = down_speed * 1000 / 424;
501 atm_dev->signal = ATM_PHY_SIG_FOUND;
504 "ADSL line is up (%d kb/s down | %d kb/s up)\n",
505 down_speed, up_speed);
509 atm_dev->signal = ATM_PHY_SIG_UNKNOWN;
510 atm_info(usbatm, "unknown line state %02x\n", status);
514 instance->last_status = status;
518 static void speedtch_status_poll(unsigned long data)
520 struct speedtch_instance_data *instance = (void *)data;
522 schedule_work(&instance->status_checker);
524 /* The following check is racy, but the race is harmless */
525 if (instance->poll_delay < MAX_POLL_DELAY)
526 mod_timer(&instance->status_checker.timer, jiffies + msecs_to_jiffies(instance->poll_delay));
528 atm_warn(instance->usbatm, "Too many failures - disabling line status polling\n");
531 static void speedtch_resubmit_int(unsigned long data)
533 struct speedtch_instance_data *instance = (void *)data;
534 struct urb *int_urb = instance->int_urb;
537 atm_dbg(instance->usbatm, "%s entered\n", __func__);
540 ret = usb_submit_urb(int_urb, GFP_ATOMIC);
542 schedule_work(&instance->status_checker);
544 atm_dbg(instance->usbatm, "%s: usb_submit_urb failed with result %d\n", __func__, ret);
545 mod_timer(&instance->resubmit_timer, jiffies + msecs_to_jiffies(RESUBMIT_DELAY));
550 static void speedtch_handle_int(struct urb *int_urb, struct pt_regs *regs)
552 struct speedtch_instance_data *instance = int_urb->context;
553 struct usbatm_data *usbatm = instance->usbatm;
554 unsigned int count = int_urb->actual_length;
555 int ret = int_urb->status;
557 /* The magic interrupt for "up state" */
558 static const unsigned char up_int[6] = { 0xa1, 0x00, 0x01, 0x00, 0x00, 0x00 };
559 /* The magic interrupt for "down state" */
560 static const unsigned char down_int[6] = { 0xa1, 0x00, 0x00, 0x00, 0x00, 0x00 };
562 atm_dbg(usbatm, "%s entered\n", __func__);
565 atm_dbg(usbatm, "%s: nonzero urb status %d!\n", __func__, ret);
569 if ((count == 6) && !memcmp(up_int, instance->int_data, 6)) {
570 del_timer(&instance->status_checker.timer);
571 atm_info(usbatm, "DSL line goes up\n");
572 } else if ((count == 6) && !memcmp(down_int, instance->int_data, 6)) {
573 atm_info(usbatm, "DSL line goes down\n");
577 atm_dbg(usbatm, "%s: unknown interrupt packet of length %d:", __func__, count);
578 for (i = 0; i < count; i++)
579 printk(" %02x", instance->int_data[i]);
584 if ((int_urb = instance->int_urb)) {
585 ret = usb_submit_urb(int_urb, GFP_ATOMIC);
586 schedule_work(&instance->status_checker);
588 atm_dbg(usbatm, "%s: usb_submit_urb failed with result %d\n", __func__, ret);
596 if ((int_urb = instance->int_urb))
597 mod_timer(&instance->resubmit_timer, jiffies + msecs_to_jiffies(RESUBMIT_DELAY));
600 static int speedtch_atm_start(struct usbatm_data *usbatm, struct atm_dev *atm_dev)
602 struct usb_device *usb_dev = usbatm->usb_dev;
603 struct speedtch_instance_data *instance = usbatm->driver_data;
605 unsigned char mac_str[13];
607 atm_dbg(usbatm, "%s entered\n", __func__);
609 /* Set MAC address, it is stored in the serial number */
610 memset(atm_dev->esi, 0, sizeof(atm_dev->esi));
611 if (usb_string(usb_dev, usb_dev->descriptor.iSerialNumber, mac_str, sizeof(mac_str)) == 12) {
612 for (i = 0; i < 6; i++)
613 atm_dev->esi[i] = (hex2int(mac_str[i * 2]) * 16) + (hex2int(mac_str[i * 2 + 1]));
616 /* Start modem synchronisation */
617 ret = speedtch_start_synchro(instance);
619 /* Set up interrupt endpoint */
620 if (instance->int_urb) {
621 ret = usb_submit_urb(instance->int_urb, GFP_KERNEL);
623 /* Doesn't matter; we'll poll anyway */
624 atm_dbg(usbatm, "%s: submission of interrupt URB failed (%d)!\n", __func__, ret);
625 usb_free_urb(instance->int_urb);
626 instance->int_urb = NULL;
630 /* Start status polling */
631 mod_timer(&instance->status_checker.timer, jiffies + msecs_to_jiffies(1000));
636 static void speedtch_atm_stop(struct usbatm_data *usbatm, struct atm_dev *atm_dev)
638 struct speedtch_instance_data *instance = usbatm->driver_data;
639 struct urb *int_urb = instance->int_urb;
641 atm_dbg(usbatm, "%s entered\n", __func__);
643 del_timer_sync(&instance->status_checker.timer);
646 * Since resubmit_timer and int_urb can schedule themselves and
647 * each other, shutting them down correctly takes some care
649 instance->int_urb = NULL; /* signal shutdown */
651 usb_kill_urb(int_urb);
652 del_timer_sync(&instance->resubmit_timer);
654 * At this point, speedtch_handle_int and speedtch_resubmit_int
655 * can run or be running, but instance->int_urb == NULL means that
656 * they will not reschedule
658 usb_kill_urb(int_urb);
659 del_timer_sync(&instance->resubmit_timer);
660 usb_free_urb(int_urb);
662 flush_scheduled_work();
670 static struct usb_device_id speedtch_usb_ids[] = {
671 {USB_DEVICE(0x06b9, 0x4061)},
675 MODULE_DEVICE_TABLE(usb, speedtch_usb_ids);
677 static int speedtch_usb_probe(struct usb_interface *, const struct usb_device_id *);
679 static struct usb_driver speedtch_usb_driver = {
680 .name = speedtch_driver_name,
681 .probe = speedtch_usb_probe,
682 .disconnect = usbatm_usb_disconnect,
683 .id_table = speedtch_usb_ids
686 static void speedtch_release_interfaces(struct usb_device *usb_dev, int num_interfaces) {
687 struct usb_interface *cur_intf;
690 for(i = 0; i < num_interfaces; i++)
691 if ((cur_intf = usb_ifnum_to_if(usb_dev, i))) {
692 usb_set_intfdata(cur_intf, NULL);
693 usb_driver_release_interface(&speedtch_usb_driver, cur_intf);
697 static int speedtch_bind(struct usbatm_data *usbatm,
698 struct usb_interface *intf,
699 const struct usb_device_id *id)
701 struct usb_device *usb_dev = interface_to_usbdev(intf);
702 struct usb_interface *cur_intf, *data_intf;
703 struct speedtch_instance_data *instance;
704 int ifnum = intf->altsetting->desc.bInterfaceNumber;
705 int num_interfaces = usb_dev->actconfig->desc.bNumInterfaces;
709 usb_dbg(usbatm, "%s entered\n", __func__);
713 if (usb_dev->descriptor.bDeviceClass != USB_CLASS_VENDOR_SPEC) {
714 usb_err(usbatm, "%s: wrong device class %d\n", __func__, usb_dev->descriptor.bDeviceClass);
718 if (!(data_intf = usb_ifnum_to_if(usb_dev, INTERFACE_DATA))) {
719 usb_err(usbatm, "%s: data interface not found!\n", __func__);
723 /* claim all interfaces */
725 for (i=0; i < num_interfaces; i++) {
726 cur_intf = usb_ifnum_to_if(usb_dev, i);
728 if ((i != ifnum) && cur_intf) {
729 ret = usb_driver_claim_interface(&speedtch_usb_driver, cur_intf, usbatm);
732 usb_err(usbatm, "%s: failed to claim interface %2d (%d)!\n", __func__, i, ret);
733 speedtch_release_interfaces(usb_dev, i);
739 instance = kzalloc(sizeof(*instance), GFP_KERNEL);
742 usb_err(usbatm, "%s: no memory for instance data!\n", __func__);
747 instance->usbatm = usbatm;
749 /* altsetting and enable_isoc may change at any moment, so take a snapshot */
750 instance->altsetting = altsetting;
751 use_isoc = enable_isoc;
753 if (instance->altsetting)
754 if ((ret = usb_set_interface(usb_dev, INTERFACE_DATA, instance->altsetting)) < 0) {
755 usb_err(usbatm, "%s: setting interface to %2d failed (%d)!\n", __func__, instance->altsetting, ret);
756 instance->altsetting = 0; /* fall back to default */
759 if (!instance->altsetting && use_isoc)
760 if ((ret = usb_set_interface(usb_dev, INTERFACE_DATA, DEFAULT_ISOC_ALTSETTING)) < 0) {
761 usb_dbg(usbatm, "%s: setting interface to %2d failed (%d)!\n", __func__, DEFAULT_ISOC_ALTSETTING, ret);
762 use_isoc = 0; /* fall back to bulk */
766 const struct usb_host_interface *desc = data_intf->cur_altsetting;
767 const __u8 target_address = USB_DIR_IN | usbatm->driver->isoc_in;
770 use_isoc = 0; /* fall back to bulk if endpoint not found */
772 for (i=0; i<desc->desc.bNumEndpoints; i++) {
773 const struct usb_endpoint_descriptor *endpoint_desc = &desc->endpoint[i].desc;
775 if ((endpoint_desc->bEndpointAddress == target_address)) {
776 use_isoc = (endpoint_desc->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) ==
777 USB_ENDPOINT_XFER_ISOC;
783 usb_info(usbatm, "isochronous transfer not supported - using bulk\n");
786 if (!use_isoc && !instance->altsetting)
787 if ((ret = usb_set_interface(usb_dev, INTERFACE_DATA, DEFAULT_BULK_ALTSETTING)) < 0) {
788 usb_err(usbatm, "%s: setting interface to %2d failed (%d)!\n", __func__, DEFAULT_BULK_ALTSETTING, ret);
792 if (!instance->altsetting)
793 instance->altsetting = use_isoc ? DEFAULT_ISOC_ALTSETTING : DEFAULT_BULK_ALTSETTING;
795 usbatm->flags |= (use_isoc ? UDSL_USE_ISOC : 0);
797 INIT_WORK(&instance->status_checker, (void *)speedtch_check_status, instance);
799 instance->status_checker.timer.function = speedtch_status_poll;
800 instance->status_checker.timer.data = (unsigned long)instance;
801 instance->last_status = 0xff;
802 instance->poll_delay = MIN_POLL_DELAY;
804 init_timer(&instance->resubmit_timer);
805 instance->resubmit_timer.function = speedtch_resubmit_int;
806 instance->resubmit_timer.data = (unsigned long)instance;
808 instance->int_urb = usb_alloc_urb(0, GFP_KERNEL);
810 if (instance->int_urb)
811 usb_fill_int_urb(instance->int_urb, usb_dev,
812 usb_rcvintpipe(usb_dev, ENDPOINT_INT),
813 instance->int_data, sizeof(instance->int_data),
814 speedtch_handle_int, instance, 50);
816 usb_dbg(usbatm, "%s: no memory for interrupt urb!\n", __func__);
818 /* check whether the modem already seems to be alive */
819 ret = usb_control_msg(usb_dev, usb_rcvctrlpipe(usb_dev, 0),
820 0x12, 0xc0, 0x07, 0x00,
821 instance->scratch_buffer + OFFSET_7, SIZE_7, 500);
823 usbatm->flags |= (ret == SIZE_7 ? UDSL_SKIP_HEAVY_INIT : 0);
825 usb_dbg(usbatm, "%s: firmware %s loaded\n", __func__, usbatm->flags & UDSL_SKIP_HEAVY_INIT ? "already" : "not");
827 if (!(usbatm->flags & UDSL_SKIP_HEAVY_INIT))
828 if ((ret = usb_reset_device(usb_dev)) < 0) {
829 usb_err(usbatm, "%s: device reset failed (%d)!\n", __func__, ret);
833 usbatm->driver_data = instance;
838 usb_free_urb(instance->int_urb);
841 speedtch_release_interfaces(usb_dev, num_interfaces);
845 static void speedtch_unbind(struct usbatm_data *usbatm, struct usb_interface *intf)
847 struct usb_device *usb_dev = interface_to_usbdev(intf);
848 struct speedtch_instance_data *instance = usbatm->driver_data;
850 usb_dbg(usbatm, "%s entered\n", __func__);
852 speedtch_release_interfaces(usb_dev, usb_dev->actconfig->desc.bNumInterfaces);
853 usb_free_urb(instance->int_urb);
862 static struct usbatm_driver speedtch_usbatm_driver = {
863 .driver_name = speedtch_driver_name,
864 .bind = speedtch_bind,
865 .heavy_init = speedtch_heavy_init,
866 .unbind = speedtch_unbind,
867 .atm_start = speedtch_atm_start,
868 .atm_stop = speedtch_atm_stop,
869 .bulk_in = ENDPOINT_BULK_DATA,
870 .bulk_out = ENDPOINT_BULK_DATA,
871 .isoc_in = ENDPOINT_ISOC_DATA
874 static int speedtch_usb_probe(struct usb_interface *intf, const struct usb_device_id *id)
876 return usbatm_usb_probe(intf, id, &speedtch_usbatm_driver);
879 static int __init speedtch_usb_init(void)
881 dbg("%s: driver version %s", __func__, DRIVER_VERSION);
883 return usb_register(&speedtch_usb_driver);
886 static void __exit speedtch_usb_cleanup(void)
890 usb_deregister(&speedtch_usb_driver);
893 module_init(speedtch_usb_init);
894 module_exit(speedtch_usb_cleanup);
896 MODULE_AUTHOR(DRIVER_AUTHOR);
897 MODULE_DESCRIPTION(DRIVER_DESC);
898 MODULE_LICENSE("GPL");
899 MODULE_VERSION(DRIVER_VERSION);