diff options
author | Linus Torvalds <torvalds@ppc970.osdl.org> | 2005-06-27 18:13:26 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@ppc970.osdl.org> | 2005-06-27 18:13:26 -0400 |
commit | d3b8a1a8496c83bc4a3cc76505c29255af15572c (patch) | |
tree | b56eb3ef27117bad5c516d6b647bdcd465d7659a /drivers/usb/atm/speedtch.c | |
parent | 60564a313a5738960064d6c555ec066d9332f278 (diff) | |
parent | 0ed0c0c48c508578c30aa58f755ca0d692636906 (diff) |
Merge master.kernel.org:/pub/scm/linux/kernel/git/gregkh/usb-2.6
Diffstat (limited to 'drivers/usb/atm/speedtch.c')
-rw-r--r-- | drivers/usb/atm/speedtch.c | 1085 |
1 files changed, 532 insertions, 553 deletions
diff --git a/drivers/usb/atm/speedtch.c b/drivers/usb/atm/speedtch.c index 2a1697bfd695..6a6eaa2a3b1c 100644 --- a/drivers/usb/atm/speedtch.c +++ b/drivers/usb/atm/speedtch.c | |||
@@ -5,6 +5,8 @@ | |||
5 | * Copyright (C) 2003, Duncan Sands | 5 | * Copyright (C) 2003, Duncan Sands |
6 | * Copyright (C) 2004, David Woodhouse | 6 | * Copyright (C) 2004, David Woodhouse |
7 | * | 7 | * |
8 | * Based on "modem_run.c", copyright (C) 2001, Benoit Papillault | ||
9 | * | ||
8 | * This program is free software; you can redistribute it and/or modify it | 10 | * This program is free software; you can redistribute it and/or modify it |
9 | * under the terms of the GNU General Public License as published by the Free | 11 | * under the terms of the GNU General Public License as published by the Free |
10 | * Software Foundation; either version 2 of the License, or (at your option) | 12 | * Software Foundation; either version 2 of the License, or (at your option) |
@@ -21,821 +23,798 @@ | |||
21 | * | 23 | * |
22 | ******************************************************************************/ | 24 | ******************************************************************************/ |
23 | 25 | ||
24 | #include <linux/module.h> | 26 | #include <asm/page.h> |
25 | #include <linux/moduleparam.h> | 27 | #include <linux/device.h> |
28 | #include <linux/errno.h> | ||
29 | #include <linux/firmware.h> | ||
26 | #include <linux/gfp.h> | 30 | #include <linux/gfp.h> |
31 | #include <linux/init.h> | ||
27 | #include <linux/kernel.h> | 32 | #include <linux/kernel.h> |
28 | #include <linux/sched.h> | 33 | #include <linux/module.h> |
29 | #include <linux/timer.h> | 34 | #include <linux/moduleparam.h> |
30 | #include <linux/errno.h> | ||
31 | #include <linux/proc_fs.h> | ||
32 | #include <linux/slab.h> | 35 | #include <linux/slab.h> |
33 | #include <linux/wait.h> | 36 | #include <linux/stat.h> |
34 | #include <linux/list.h> | 37 | #include <linux/timer.h> |
35 | #include <asm/processor.h> | 38 | #include <linux/workqueue.h> |
36 | #include <asm/uaccess.h> | ||
37 | #include <linux/smp_lock.h> | ||
38 | #include <linux/interrupt.h> | ||
39 | #include <linux/atm.h> | ||
40 | #include <linux/atmdev.h> | ||
41 | #include <linux/crc32.h> | ||
42 | #include <linux/init.h> | ||
43 | #include <linux/firmware.h> | ||
44 | |||
45 | #include "usb_atm.h" | ||
46 | 39 | ||
47 | #if defined(CONFIG_FW_LOADER) || defined(CONFIG_FW_LOADER_MODULE) | 40 | #include "usbatm.h" |
48 | # define USE_FW_LOADER | ||
49 | #endif | ||
50 | 41 | ||
51 | #define DRIVER_AUTHOR "Johan Verrept, Duncan Sands <duncan.sands@free.fr>" | 42 | #define DRIVER_AUTHOR "Johan Verrept, Duncan Sands <duncan.sands@free.fr>" |
52 | #define DRIVER_VERSION "1.8" | 43 | #define DRIVER_VERSION "1.9" |
53 | #define DRIVER_DESC "Alcatel SpeedTouch USB driver version " DRIVER_VERSION | 44 | #define DRIVER_DESC "Alcatel SpeedTouch USB driver version " DRIVER_VERSION |
54 | 45 | ||
55 | static const char speedtch_driver_name[] = "speedtch"; | 46 | static const char speedtch_driver_name[] = "speedtch"; |
56 | 47 | ||
57 | #define SPEEDTOUCH_VENDORID 0x06b9 | 48 | #define CTRL_TIMEOUT 2000 /* milliseconds */ |
58 | #define SPEEDTOUCH_PRODUCTID 0x4061 | 49 | #define DATA_TIMEOUT 2000 /* milliseconds */ |
59 | 50 | ||
60 | /* Timeout in jiffies */ | 51 | #define OFFSET_7 0 /* size 1 */ |
61 | #define CTRL_TIMEOUT 2000 | 52 | #define OFFSET_b 1 /* size 8 */ |
62 | #define DATA_TIMEOUT 2000 | 53 | #define OFFSET_d 9 /* size 4 */ |
54 | #define OFFSET_e 13 /* size 1 */ | ||
55 | #define OFFSET_f 14 /* size 1 */ | ||
56 | #define TOTAL 15 | ||
63 | 57 | ||
64 | #define OFFSET_7 0 /* size 1 */ | 58 | #define SIZE_7 1 |
65 | #define OFFSET_b 1 /* size 8 */ | 59 | #define SIZE_b 8 |
66 | #define OFFSET_d 9 /* size 4 */ | 60 | #define SIZE_d 4 |
67 | #define OFFSET_e 13 /* size 1 */ | 61 | #define SIZE_e 1 |
68 | #define OFFSET_f 14 /* size 1 */ | 62 | #define SIZE_f 1 |
69 | #define TOTAL 15 | ||
70 | 63 | ||
71 | #define SIZE_7 1 | 64 | #define MIN_POLL_DELAY 5000 /* milliseconds */ |
72 | #define SIZE_b 8 | 65 | #define MAX_POLL_DELAY 60000 /* milliseconds */ |
73 | #define SIZE_d 4 | ||
74 | #define SIZE_e 1 | ||
75 | #define SIZE_f 1 | ||
76 | 66 | ||
77 | static int dl_512_first = 0; | 67 | #define RESUBMIT_DELAY 1000 /* milliseconds */ |
78 | static int sw_buffering = 0; | ||
79 | 68 | ||
80 | module_param(dl_512_first, bool, 0444); | 69 | #define DEFAULT_ALTSETTING 1 |
81 | MODULE_PARM_DESC(dl_512_first, "Read 512 bytes before sending firmware"); | 70 | #define DEFAULT_DL_512_FIRST 0 |
71 | #define DEFAULT_SW_BUFFERING 0 | ||
82 | 72 | ||
83 | module_param(sw_buffering, uint, 0444); | 73 | static int altsetting = DEFAULT_ALTSETTING; |
84 | MODULE_PARM_DESC(sw_buffering, "Enable software buffering"); | 74 | static int dl_512_first = DEFAULT_DL_512_FIRST; |
75 | static int sw_buffering = DEFAULT_SW_BUFFERING; | ||
85 | 76 | ||
86 | #define UDSL_IOCTL_LINE_UP 1 | 77 | module_param(altsetting, int, S_IRUGO | S_IWUSR); |
87 | #define UDSL_IOCTL_LINE_DOWN 2 | 78 | MODULE_PARM_DESC(altsetting, |
79 | "Alternative setting for data interface (default: " | ||
80 | __MODULE_STRING(DEFAULT_ALTSETTING) ")"); | ||
88 | 81 | ||
89 | #define SPEEDTCH_ENDPOINT_INT 0x81 | 82 | module_param(dl_512_first, bool, S_IRUGO | S_IWUSR); |
90 | #define SPEEDTCH_ENDPOINT_DATA 0x07 | 83 | MODULE_PARM_DESC(dl_512_first, |
91 | #define SPEEDTCH_ENDPOINT_FIRMWARE 0x05 | 84 | "Read 512 bytes before sending firmware (default: " |
85 | __MODULE_STRING(DEFAULT_DL_512_FIRST) ")"); | ||
92 | 86 | ||
93 | #define hex2int(c) ( (c >= '0') && (c <= '9') ? (c - '0') : ((c & 0xf) + 9) ) | 87 | module_param(sw_buffering, bool, S_IRUGO | S_IWUSR); |
88 | MODULE_PARM_DESC(sw_buffering, | ||
89 | "Enable software buffering (default: " | ||
90 | __MODULE_STRING(DEFAULT_SW_BUFFERING) ")"); | ||
94 | 91 | ||
95 | static struct usb_device_id speedtch_usb_ids[] = { | 92 | #define ENDPOINT_INT 0x81 |
96 | {USB_DEVICE(SPEEDTOUCH_VENDORID, SPEEDTOUCH_PRODUCTID)}, | 93 | #define ENDPOINT_DATA 0x07 |
97 | {} | 94 | #define ENDPOINT_FIRMWARE 0x05 |
98 | }; | ||
99 | 95 | ||
100 | MODULE_DEVICE_TABLE(usb, speedtch_usb_ids); | 96 | #define hex2int(c) ( (c >= '0') && (c <= '9') ? (c - '0') : ((c & 0xf) + 9) ) |
101 | 97 | ||
102 | struct speedtch_instance_data { | 98 | struct speedtch_instance_data { |
103 | struct udsl_instance_data u; | 99 | struct usbatm_data *usbatm; |
100 | |||
101 | struct work_struct status_checker; | ||
104 | 102 | ||
105 | /* Status */ | 103 | int poll_delay; /* milliseconds */ |
104 | |||
105 | struct timer_list resubmit_timer; | ||
106 | struct urb *int_urb; | 106 | struct urb *int_urb; |
107 | unsigned char int_data[16]; | 107 | unsigned char int_data[16]; |
108 | struct work_struct poll_work; | ||
109 | struct timer_list poll_timer; | ||
110 | }; | ||
111 | /* USB */ | ||
112 | |||
113 | static int speedtch_usb_probe(struct usb_interface *intf, | ||
114 | const struct usb_device_id *id); | ||
115 | static void speedtch_usb_disconnect(struct usb_interface *intf); | ||
116 | static int speedtch_usb_ioctl(struct usb_interface *intf, unsigned int code, | ||
117 | void *user_data); | ||
118 | static void speedtch_handle_int(struct urb *urb, struct pt_regs *regs); | ||
119 | static void speedtch_poll_status(struct speedtch_instance_data *instance); | ||
120 | 108 | ||
121 | static struct usb_driver speedtch_usb_driver = { | 109 | unsigned char scratch_buffer[TOTAL]; |
122 | .owner = THIS_MODULE, | ||
123 | .name = speedtch_driver_name, | ||
124 | .probe = speedtch_usb_probe, | ||
125 | .disconnect = speedtch_usb_disconnect, | ||
126 | .ioctl = speedtch_usb_ioctl, | ||
127 | .id_table = speedtch_usb_ids, | ||
128 | }; | 110 | }; |
129 | 111 | ||
130 | /*************** | 112 | /*************** |
131 | ** firmware ** | 113 | ** firmware ** |
132 | ***************/ | 114 | ***************/ |
133 | 115 | ||
134 | static void speedtch_got_firmware(struct speedtch_instance_data *instance, | 116 | static void speedtch_set_swbuff(struct speedtch_instance_data *instance, int state) |
135 | int got_it) | ||
136 | { | 117 | { |
137 | int err; | 118 | struct usbatm_data *usbatm = instance->usbatm; |
138 | struct usb_interface *intf; | 119 | struct usb_device *usb_dev = usbatm->usb_dev; |
139 | |||
140 | down(&instance->u.serialize); /* vs self, speedtch_firmware_start */ | ||
141 | if (instance->u.status == UDSL_LOADED_FIRMWARE) | ||
142 | goto out; | ||
143 | if (!got_it) { | ||
144 | instance->u.status = UDSL_NO_FIRMWARE; | ||
145 | goto out; | ||
146 | } | ||
147 | if ((err = usb_set_interface(instance->u.usb_dev, 1, 1)) < 0) { | ||
148 | dbg("speedtch_got_firmware: usb_set_interface returned %d!", err); | ||
149 | instance->u.status = UDSL_NO_FIRMWARE; | ||
150 | goto out; | ||
151 | } | ||
152 | |||
153 | /* Set up interrupt endpoint */ | ||
154 | intf = usb_ifnum_to_if(instance->u.usb_dev, 0); | ||
155 | if (intf && !usb_driver_claim_interface(&speedtch_usb_driver, intf, NULL)) { | ||
156 | |||
157 | instance->int_urb = usb_alloc_urb(0, GFP_KERNEL); | ||
158 | if (instance->int_urb) { | ||
159 | |||
160 | usb_fill_int_urb(instance->int_urb, instance->u.usb_dev, | ||
161 | usb_rcvintpipe(instance->u.usb_dev, SPEEDTCH_ENDPOINT_INT), | ||
162 | instance->int_data, | ||
163 | sizeof(instance->int_data), | ||
164 | speedtch_handle_int, instance, 50); | ||
165 | err = usb_submit_urb(instance->int_urb, GFP_KERNEL); | ||
166 | if (err) { | ||
167 | /* Doesn't matter; we'll poll anyway */ | ||
168 | dbg("speedtch_got_firmware: Submission of interrupt URB failed %d", err); | ||
169 | usb_free_urb(instance->int_urb); | ||
170 | instance->int_urb = NULL; | ||
171 | usb_driver_release_interface(&speedtch_usb_driver, intf); | ||
172 | } | ||
173 | } | ||
174 | } | ||
175 | /* Start status polling */ | ||
176 | mod_timer(&instance->poll_timer, jiffies + (1 * HZ)); | ||
177 | |||
178 | instance->u.status = UDSL_LOADED_FIRMWARE; | ||
179 | tasklet_schedule(&instance->u.receive_tasklet); | ||
180 | out: | ||
181 | up(&instance->u.serialize); | ||
182 | wake_up_interruptible(&instance->u.firmware_waiters); | ||
183 | } | ||
184 | |||
185 | static int speedtch_set_swbuff(struct speedtch_instance_data *instance, | ||
186 | int state) | ||
187 | { | ||
188 | struct usb_device *dev = instance->u.usb_dev; | ||
189 | int ret; | 120 | int ret; |
190 | 121 | ||
191 | ret = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), | 122 | ret = usb_control_msg(usb_dev, usb_sndctrlpipe(usb_dev, 0), |
192 | 0x32, 0x40, state ? 0x01 : 0x00, | 123 | 0x32, 0x40, state ? 0x01 : 0x00, 0x00, NULL, 0, CTRL_TIMEOUT); |
193 | 0x00, NULL, 0, 100); | 124 | if (ret < 0) |
194 | if (ret < 0) { | 125 | usb_warn(usbatm, |
195 | printk("Warning: %sabling SW buffering: usb_control_msg returned %d\n", | 126 | "%sabling SW buffering: usb_control_msg returned %d\n", |
196 | state ? "En" : "Dis", ret); | 127 | state ? "En" : "Dis", ret); |
197 | return ret; | 128 | else |
198 | } | 129 | dbg("speedtch_set_swbuff: %sbled SW buffering", state ? "En" : "Dis"); |
199 | |||
200 | dbg("speedtch_set_swbuff: %sbled SW buffering", state ? "En" : "Dis"); | ||
201 | return 0; | ||
202 | } | 130 | } |
203 | 131 | ||
204 | static void speedtch_test_sequence(struct speedtch_instance_data *instance) | 132 | static void speedtch_test_sequence(struct speedtch_instance_data *instance) |
205 | { | 133 | { |
206 | struct usb_device *dev = instance->u.usb_dev; | 134 | struct usbatm_data *usbatm = instance->usbatm; |
207 | unsigned char buf[10]; | 135 | struct usb_device *usb_dev = usbatm->usb_dev; |
136 | unsigned char *buf = instance->scratch_buffer; | ||
208 | int ret; | 137 | int ret; |
209 | 138 | ||
210 | /* URB 147 */ | 139 | /* URB 147 */ |
211 | buf[0] = 0x1c; | 140 | buf[0] = 0x1c; |
212 | buf[1] = 0x50; | 141 | buf[1] = 0x50; |
213 | ret = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), | 142 | ret = usb_control_msg(usb_dev, usb_sndctrlpipe(usb_dev, 0), |
214 | 0x01, 0x40, 0x0b, 0x00, buf, 2, 100); | 143 | 0x01, 0x40, 0x0b, 0x00, buf, 2, CTRL_TIMEOUT); |
215 | if (ret < 0) | 144 | if (ret < 0) |
216 | printk(KERN_WARNING "%s failed on URB147: %d\n", __func__, ret); | 145 | usb_warn(usbatm, "%s failed on URB147: %d\n", __func__, ret); |
217 | 146 | ||
218 | /* URB 148 */ | 147 | /* URB 148 */ |
219 | buf[0] = 0x32; | 148 | buf[0] = 0x32; |
220 | buf[1] = 0x00; | 149 | buf[1] = 0x00; |
221 | ret = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), | 150 | ret = usb_control_msg(usb_dev, usb_sndctrlpipe(usb_dev, 0), |
222 | 0x01, 0x40, 0x02, 0x00, buf, 2, 100); | 151 | 0x01, 0x40, 0x02, 0x00, buf, 2, CTRL_TIMEOUT); |
223 | if (ret < 0) | 152 | if (ret < 0) |
224 | printk(KERN_WARNING "%s failed on URB148: %d\n", __func__, ret); | 153 | usb_warn(usbatm, "%s failed on URB148: %d\n", __func__, ret); |
225 | 154 | ||
226 | /* URB 149 */ | 155 | /* URB 149 */ |
227 | buf[0] = 0x01; | 156 | buf[0] = 0x01; |
228 | buf[1] = 0x00; | 157 | buf[1] = 0x00; |
229 | buf[2] = 0x01; | 158 | buf[2] = 0x01; |
230 | ret = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), | 159 | ret = usb_control_msg(usb_dev, usb_sndctrlpipe(usb_dev, 0), |
231 | 0x01, 0x40, 0x03, 0x00, buf, 3, 100); | 160 | 0x01, 0x40, 0x03, 0x00, buf, 3, CTRL_TIMEOUT); |
232 | if (ret < 0) | 161 | if (ret < 0) |
233 | printk(KERN_WARNING "%s failed on URB149: %d\n", __func__, ret); | 162 | usb_warn(usbatm, "%s failed on URB149: %d\n", __func__, ret); |
234 | 163 | ||
235 | /* URB 150 */ | 164 | /* URB 150 */ |
236 | buf[0] = 0x01; | 165 | buf[0] = 0x01; |
237 | buf[1] = 0x00; | 166 | buf[1] = 0x00; |
238 | buf[2] = 0x01; | 167 | buf[2] = 0x01; |
239 | ret = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), | 168 | ret = usb_control_msg(usb_dev, usb_sndctrlpipe(usb_dev, 0), |
240 | 0x01, 0x40, 0x04, 0x00, buf, 3, 100); | 169 | 0x01, 0x40, 0x04, 0x00, buf, 3, CTRL_TIMEOUT); |
241 | if (ret < 0) | 170 | if (ret < 0) |
242 | printk(KERN_WARNING "%s failed on URB150: %d\n", __func__, ret); | 171 | usb_warn(usbatm, "%s failed on URB150: %d\n", __func__, ret); |
243 | } | 172 | } |
244 | 173 | ||
245 | static int speedtch_start_synchro(struct speedtch_instance_data *instance) | 174 | static int speedtch_upload_firmware(struct speedtch_instance_data *instance, |
175 | const struct firmware *fw1, | ||
176 | const struct firmware *fw2) | ||
246 | { | 177 | { |
247 | struct usb_device *dev = instance->u.usb_dev; | 178 | unsigned char *buffer; |
248 | unsigned char buf[2]; | 179 | struct usbatm_data *usbatm = instance->usbatm; |
249 | int ret; | 180 | struct usb_interface *intf; |
181 | struct usb_device *usb_dev = usbatm->usb_dev; | ||
182 | int actual_length; | ||
183 | int ret = 0; | ||
184 | int offset; | ||
185 | |||
186 | usb_dbg(usbatm, "%s entered\n", __func__); | ||
187 | |||
188 | if (!(buffer = (unsigned char *)__get_free_page(GFP_KERNEL))) { | ||
189 | ret = -ENOMEM; | ||
190 | usb_dbg(usbatm, "%s: no memory for buffer!\n", __func__); | ||
191 | goto out; | ||
192 | } | ||
193 | |||
194 | if (!(intf = usb_ifnum_to_if(usb_dev, 2))) { | ||
195 | ret = -ENODEV; | ||
196 | usb_dbg(usbatm, "%s: interface not found!\n", __func__); | ||
197 | goto out_free; | ||
198 | } | ||
199 | |||
200 | /* URB 7 */ | ||
201 | if (dl_512_first) { /* some modems need a read before writing the firmware */ | ||
202 | ret = usb_bulk_msg(usb_dev, usb_rcvbulkpipe(usb_dev, ENDPOINT_FIRMWARE), | ||
203 | buffer, 0x200, &actual_length, 2000); | ||
204 | |||
205 | if (ret < 0 && ret != -ETIMEDOUT) | ||
206 | usb_dbg(usbatm, "%s: read BLOCK0 from modem failed (%d)!\n", __func__, ret); | ||
207 | else | ||
208 | usb_dbg(usbatm, "%s: BLOCK0 downloaded (%d bytes)\n", __func__, ret); | ||
209 | } | ||
210 | |||
211 | /* URB 8 : both leds are static green */ | ||
212 | for (offset = 0; offset < fw1->size; offset += PAGE_SIZE) { | ||
213 | int thislen = min_t(int, PAGE_SIZE, fw1->size - offset); | ||
214 | memcpy(buffer, fw1->data + offset, thislen); | ||
215 | |||
216 | ret = usb_bulk_msg(usb_dev, usb_sndbulkpipe(usb_dev, ENDPOINT_FIRMWARE), | ||
217 | buffer, thislen, &actual_length, DATA_TIMEOUT); | ||
218 | |||
219 | if (ret < 0) { | ||
220 | usb_dbg(usbatm, "%s: write BLOCK1 to modem failed (%d)!\n", __func__, ret); | ||
221 | goto out_free; | ||
222 | } | ||
223 | usb_dbg(usbatm, "%s: BLOCK1 uploaded (%zu bytes)\n", __func__, fw1->size); | ||
224 | } | ||
225 | |||
226 | /* USB led blinking green, ADSL led off */ | ||
227 | |||
228 | /* URB 11 */ | ||
229 | ret = usb_bulk_msg(usb_dev, usb_rcvbulkpipe(usb_dev, ENDPOINT_FIRMWARE), | ||
230 | buffer, 0x200, &actual_length, DATA_TIMEOUT); | ||
250 | 231 | ||
251 | ret = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0), | ||
252 | 0x12, 0xc0, 0x04, 0x00, | ||
253 | buf, sizeof(buf), CTRL_TIMEOUT); | ||
254 | if (ret < 0) { | 232 | if (ret < 0) { |
255 | printk(KERN_WARNING "SpeedTouch: Failed to start ADSL synchronisation: %d\n", ret); | 233 | usb_dbg(usbatm, "%s: read BLOCK2 from modem failed (%d)!\n", __func__, ret); |
256 | return ret; | 234 | goto out_free; |
257 | } | 235 | } |
236 | usb_dbg(usbatm, "%s: BLOCK2 downloaded (%d bytes)\n", __func__, actual_length); | ||
258 | 237 | ||
259 | dbg("speedtch_start_synchro: modem prodded. %d Bytes returned: %02x %02x", ret, buf[0], buf[1]); | 238 | /* URBs 12 to 139 - USB led blinking green, ADSL led off */ |
260 | return 0; | 239 | for (offset = 0; offset < fw2->size; offset += PAGE_SIZE) { |
240 | int thislen = min_t(int, PAGE_SIZE, fw2->size - offset); | ||
241 | memcpy(buffer, fw2->data + offset, thislen); | ||
242 | |||
243 | ret = usb_bulk_msg(usb_dev, usb_sndbulkpipe(usb_dev, ENDPOINT_FIRMWARE), | ||
244 | buffer, thislen, &actual_length, DATA_TIMEOUT); | ||
245 | |||
246 | if (ret < 0) { | ||
247 | usb_dbg(usbatm, "%s: write BLOCK3 to modem failed (%d)!\n", __func__, ret); | ||
248 | goto out_free; | ||
249 | } | ||
250 | } | ||
251 | usb_dbg(usbatm, "%s: BLOCK3 uploaded (%zu bytes)\n", __func__, fw2->size); | ||
252 | |||
253 | /* USB led static green, ADSL led static red */ | ||
254 | |||
255 | /* URB 142 */ | ||
256 | ret = usb_bulk_msg(usb_dev, usb_rcvbulkpipe(usb_dev, ENDPOINT_FIRMWARE), | ||
257 | buffer, 0x200, &actual_length, DATA_TIMEOUT); | ||
258 | |||
259 | if (ret < 0) { | ||
260 | usb_dbg(usbatm, "%s: read BLOCK4 from modem failed (%d)!\n", __func__, ret); | ||
261 | goto out_free; | ||
262 | } | ||
263 | |||
264 | /* success */ | ||
265 | usb_dbg(usbatm, "%s: BLOCK4 downloaded (%d bytes)\n", __func__, actual_length); | ||
266 | |||
267 | /* Delay to allow firmware to start up. We can do this here | ||
268 | because we're in our own kernel thread anyway. */ | ||
269 | msleep_interruptible(1000); | ||
270 | |||
271 | /* Enable software buffering, if requested */ | ||
272 | if (sw_buffering) | ||
273 | speedtch_set_swbuff(instance, 1); | ||
274 | |||
275 | /* Magic spell; don't ask us what this does */ | ||
276 | speedtch_test_sequence(instance); | ||
277 | |||
278 | ret = 0; | ||
279 | |||
280 | out_free: | ||
281 | free_page((unsigned long)buffer); | ||
282 | out: | ||
283 | return ret; | ||
261 | } | 284 | } |
262 | 285 | ||
263 | static void speedtch_handle_int(struct urb *urb, struct pt_regs *regs) | 286 | static int speedtch_find_firmware(struct usb_interface *intf, int phase, |
287 | const struct firmware **fw_p) | ||
264 | { | 288 | { |
265 | struct speedtch_instance_data *instance = urb->context; | 289 | struct device *dev = &intf->dev; |
266 | unsigned int count = urb->actual_length; | 290 | const u16 bcdDevice = le16_to_cpu(interface_to_usbdev(intf)->descriptor.bcdDevice); |
267 | int ret; | 291 | const u8 major_revision = bcdDevice >> 8; |
292 | const u8 minor_revision = bcdDevice & 0xff; | ||
293 | char buf[24]; | ||
268 | 294 | ||
269 | /* The magic interrupt for "up state" */ | 295 | sprintf(buf, "speedtch-%d.bin.%x.%02x", phase, major_revision, minor_revision); |
270 | const static unsigned char up_int[6] = { 0xa1, 0x00, 0x01, 0x00, 0x00, 0x00 }; | 296 | dev_dbg(dev, "%s: looking for %s\n", __func__, buf); |
271 | /* The magic interrupt for "down state" */ | ||
272 | const static unsigned char down_int[6] = { 0xa1, 0x00, 0x00, 0x00, 0x00, 0x00 }; | ||
273 | 297 | ||
274 | switch (urb->status) { | 298 | if (request_firmware(fw_p, buf, dev)) { |
275 | case 0: | 299 | sprintf(buf, "speedtch-%d.bin.%x", phase, major_revision); |
276 | /* success */ | 300 | dev_dbg(dev, "%s: looking for %s\n", __func__, buf); |
277 | break; | ||
278 | case -ECONNRESET: | ||
279 | case -ENOENT: | ||
280 | case -ESHUTDOWN: | ||
281 | /* this urb is terminated; clean up */ | ||
282 | dbg("%s - urb shutting down with status: %d", __func__, urb->status); | ||
283 | return; | ||
284 | default: | ||
285 | dbg("%s - nonzero urb status received: %d", __func__, urb->status); | ||
286 | goto exit; | ||
287 | } | ||
288 | 301 | ||
289 | if (count < 6) { | 302 | if (request_firmware(fw_p, buf, dev)) { |
290 | dbg("%s - int packet too short", __func__); | 303 | sprintf(buf, "speedtch-%d.bin", phase); |
291 | goto exit; | 304 | dev_dbg(dev, "%s: looking for %s\n", __func__, buf); |
305 | |||
306 | if (request_firmware(fw_p, buf, dev)) { | ||
307 | dev_warn(dev, "no stage %d firmware found!\n", phase); | ||
308 | return -ENOENT; | ||
309 | } | ||
310 | } | ||
292 | } | 311 | } |
293 | 312 | ||
294 | if (!memcmp(up_int, instance->int_data, 6)) { | 313 | dev_info(dev, "found stage %d firmware %s\n", phase, buf); |
295 | del_timer(&instance->poll_timer); | ||
296 | printk(KERN_NOTICE "DSL line goes up\n"); | ||
297 | } else if (!memcmp(down_int, instance->int_data, 6)) { | ||
298 | printk(KERN_NOTICE "DSL line goes down\n"); | ||
299 | } else { | ||
300 | int i; | ||
301 | 314 | ||
302 | printk(KERN_DEBUG "Unknown interrupt packet of %d bytes:", count); | 315 | return 0; |
303 | for (i = 0; i < count; i++) | 316 | } |
304 | printk(" %02x", instance->int_data[i]); | 317 | |
305 | printk("\n"); | 318 | static int speedtch_heavy_init(struct usbatm_data *usbatm, struct usb_interface *intf) |
319 | { | ||
320 | const struct firmware *fw1, *fw2; | ||
321 | struct speedtch_instance_data *instance = usbatm->driver_data; | ||
322 | int ret; | ||
323 | |||
324 | if ((ret = speedtch_find_firmware(intf, 1, &fw1)) < 0) | ||
325 | return ret; | ||
326 | |||
327 | if ((ret = speedtch_find_firmware(intf, 2, &fw2)) < 0) { | ||
328 | release_firmware(fw1); | ||
329 | return ret; | ||
306 | } | 330 | } |
307 | schedule_work(&instance->poll_work); | ||
308 | 331 | ||
309 | exit: | 332 | ret = speedtch_upload_firmware(instance, fw1, fw2); |
310 | rmb(); | 333 | |
311 | if (!instance->int_urb) | 334 | release_firmware(fw2); |
312 | return; | 335 | release_firmware(fw1); |
313 | 336 | ||
314 | ret = usb_submit_urb(urb, GFP_ATOMIC); | 337 | return ret; |
315 | if (ret) | ||
316 | err("%s - usb_submit_urb failed with result %d", __func__, ret); | ||
317 | } | 338 | } |
318 | 339 | ||
319 | static int speedtch_get_status(struct speedtch_instance_data *instance, | 340 | |
320 | unsigned char *buf) | 341 | /********** |
342 | ** ATM ** | ||
343 | **********/ | ||
344 | |||
345 | static int speedtch_read_status(struct speedtch_instance_data *instance) | ||
321 | { | 346 | { |
322 | struct usb_device *dev = instance->u.usb_dev; | 347 | struct usbatm_data *usbatm = instance->usbatm; |
348 | struct usb_device *usb_dev = usbatm->usb_dev; | ||
349 | unsigned char *buf = instance->scratch_buffer; | ||
323 | int ret; | 350 | int ret; |
324 | 351 | ||
325 | memset(buf, 0, TOTAL); | 352 | memset(buf, 0, TOTAL); |
326 | 353 | ||
327 | ret = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0), | 354 | ret = usb_control_msg(usb_dev, usb_rcvctrlpipe(usb_dev, 0), |
328 | 0x12, 0xc0, 0x07, 0x00, buf + OFFSET_7, SIZE_7, | 355 | 0x12, 0xc0, 0x07, 0x00, buf + OFFSET_7, SIZE_7, |
329 | CTRL_TIMEOUT); | 356 | CTRL_TIMEOUT); |
330 | if (ret < 0) { | 357 | if (ret < 0) { |
331 | dbg("MSG 7 failed"); | 358 | atm_dbg(usbatm, "%s: MSG 7 failed\n", __func__); |
332 | return ret; | 359 | return ret; |
333 | } | 360 | } |
334 | 361 | ||
335 | ret = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0), | 362 | ret = usb_control_msg(usb_dev, usb_rcvctrlpipe(usb_dev, 0), |
336 | 0x12, 0xc0, 0x0b, 0x00, buf + OFFSET_b, SIZE_b, | 363 | 0x12, 0xc0, 0x0b, 0x00, buf + OFFSET_b, SIZE_b, |
337 | CTRL_TIMEOUT); | 364 | CTRL_TIMEOUT); |
338 | if (ret < 0) { | 365 | if (ret < 0) { |
339 | dbg("MSG B failed"); | 366 | atm_dbg(usbatm, "%s: MSG B failed\n", __func__); |
340 | return ret; | 367 | return ret; |
341 | } | 368 | } |
342 | 369 | ||
343 | ret = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0), | 370 | ret = usb_control_msg(usb_dev, usb_rcvctrlpipe(usb_dev, 0), |
344 | 0x12, 0xc0, 0x0d, 0x00, buf + OFFSET_d, SIZE_d, | 371 | 0x12, 0xc0, 0x0d, 0x00, buf + OFFSET_d, SIZE_d, |
345 | CTRL_TIMEOUT); | 372 | CTRL_TIMEOUT); |
346 | if (ret < 0) { | 373 | if (ret < 0) { |
347 | dbg("MSG D failed"); | 374 | atm_dbg(usbatm, "%s: MSG D failed\n", __func__); |
348 | return ret; | 375 | return ret; |
349 | } | 376 | } |
350 | 377 | ||
351 | ret = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0), | 378 | ret = usb_control_msg(usb_dev, usb_rcvctrlpipe(usb_dev, 0), |
352 | 0x01, 0xc0, 0x0e, 0x00, buf + OFFSET_e, SIZE_e, | 379 | 0x01, 0xc0, 0x0e, 0x00, buf + OFFSET_e, SIZE_e, |
353 | CTRL_TIMEOUT); | 380 | CTRL_TIMEOUT); |
354 | if (ret < 0) { | 381 | if (ret < 0) { |
355 | dbg("MSG E failed"); | 382 | atm_dbg(usbatm, "%s: MSG E failed\n", __func__); |
356 | return ret; | 383 | return ret; |
357 | } | 384 | } |
358 | 385 | ||
359 | ret = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0), | 386 | ret = usb_control_msg(usb_dev, usb_rcvctrlpipe(usb_dev, 0), |
360 | 0x01, 0xc0, 0x0f, 0x00, buf + OFFSET_f, SIZE_f, | 387 | 0x01, 0xc0, 0x0f, 0x00, buf + OFFSET_f, SIZE_f, |
361 | CTRL_TIMEOUT); | 388 | CTRL_TIMEOUT); |
362 | if (ret < 0) { | 389 | if (ret < 0) { |
363 | dbg("MSG F failed"); | 390 | atm_dbg(usbatm, "%s: MSG F failed\n", __func__); |
364 | return ret; | 391 | return ret; |
365 | } | 392 | } |
366 | 393 | ||
367 | return 0; | 394 | return 0; |
368 | } | 395 | } |
369 | 396 | ||
370 | static void speedtch_poll_status(struct speedtch_instance_data *instance) | 397 | static int speedtch_start_synchro(struct speedtch_instance_data *instance) |
371 | { | 398 | { |
372 | unsigned char buf[TOTAL]; | 399 | struct usbatm_data *usbatm = instance->usbatm; |
400 | struct usb_device *usb_dev = usbatm->usb_dev; | ||
401 | unsigned char *buf = instance->scratch_buffer; | ||
373 | int ret; | 402 | int ret; |
374 | 403 | ||
375 | ret = speedtch_get_status(instance, buf); | 404 | atm_dbg(usbatm, "%s entered\n", __func__); |
376 | if (ret) { | 405 | |
377 | printk(KERN_WARNING | 406 | memset(buf, 0, 2); |
378 | "SpeedTouch: Error %d fetching device status\n", ret); | 407 | |
408 | ret = usb_control_msg(usb_dev, usb_rcvctrlpipe(usb_dev, 0), | ||
409 | 0x12, 0xc0, 0x04, 0x00, | ||
410 | buf, 2, CTRL_TIMEOUT); | ||
411 | |||
412 | if (ret < 0) | ||
413 | atm_warn(usbatm, "failed to start ADSL synchronisation: %d\n", ret); | ||
414 | else | ||
415 | atm_dbg(usbatm, "%s: modem prodded. %d bytes returned: %02x %02x\n", | ||
416 | __func__, ret, buf[0], buf[1]); | ||
417 | |||
418 | return ret; | ||
419 | } | ||
420 | |||
421 | static void speedtch_check_status(struct speedtch_instance_data *instance) | ||
422 | { | ||
423 | struct usbatm_data *usbatm = instance->usbatm; | ||
424 | struct atm_dev *atm_dev = usbatm->atm_dev; | ||
425 | unsigned char *buf = instance->scratch_buffer; | ||
426 | int ret; | ||
427 | |||
428 | atm_dbg(usbatm, "%s entered\n", __func__); | ||
429 | |||
430 | ret = speedtch_read_status(instance); | ||
431 | if (ret < 0) { | ||
432 | atm_warn(usbatm, "error %d fetching device status\n", ret); | ||
433 | if (instance->poll_delay < MAX_POLL_DELAY) | ||
434 | instance->poll_delay *= 2; | ||
379 | return; | 435 | return; |
380 | } | 436 | } |
381 | 437 | ||
382 | dbg("Line state %02x", buf[OFFSET_7]); | 438 | if (instance->poll_delay > MIN_POLL_DELAY) |
439 | instance->poll_delay /= 2; | ||
440 | |||
441 | atm_dbg(usbatm, "%s: line state %02x\n", __func__, buf[OFFSET_7]); | ||
383 | 442 | ||
384 | switch (buf[OFFSET_7]) { | 443 | switch (buf[OFFSET_7]) { |
385 | case 0: | 444 | case 0: |
386 | if (instance->u.atm_dev->signal != ATM_PHY_SIG_LOST) { | 445 | if (atm_dev->signal != ATM_PHY_SIG_LOST) { |
387 | instance->u.atm_dev->signal = ATM_PHY_SIG_LOST; | 446 | atm_dev->signal = ATM_PHY_SIG_LOST; |
388 | printk(KERN_NOTICE "ADSL line is down\n"); | 447 | atm_info(usbatm, "ADSL line is down\n"); |
389 | /* It'll never resync again unless we ask it to... */ | 448 | /* It'll never resync again unless we ask it to... */ |
390 | speedtch_start_synchro(instance); | 449 | ret = speedtch_start_synchro(instance); |
391 | } | 450 | } |
392 | break; | 451 | break; |
393 | 452 | ||
394 | case 0x08: | 453 | case 0x08: |
395 | if (instance->u.atm_dev->signal != ATM_PHY_SIG_UNKNOWN) { | 454 | if (atm_dev->signal != ATM_PHY_SIG_UNKNOWN) { |
396 | instance->u.atm_dev->signal = ATM_PHY_SIG_UNKNOWN; | 455 | atm_dev->signal = ATM_PHY_SIG_UNKNOWN; |
397 | printk(KERN_NOTICE "ADSL line is blocked?\n"); | 456 | atm_info(usbatm, "ADSL line is blocked?\n"); |
398 | } | 457 | } |
399 | break; | 458 | break; |
400 | 459 | ||
401 | case 0x10: | 460 | case 0x10: |
402 | if (instance->u.atm_dev->signal != ATM_PHY_SIG_LOST) { | 461 | if (atm_dev->signal != ATM_PHY_SIG_LOST) { |
403 | instance->u.atm_dev->signal = ATM_PHY_SIG_LOST; | 462 | atm_dev->signal = ATM_PHY_SIG_LOST; |
404 | printk(KERN_NOTICE "ADSL line is synchronising\n"); | 463 | atm_info(usbatm, "ADSL line is synchronising\n"); |
405 | } | 464 | } |
406 | break; | 465 | break; |
407 | 466 | ||
408 | case 0x20: | 467 | case 0x20: |
409 | if (instance->u.atm_dev->signal != ATM_PHY_SIG_FOUND) { | 468 | if (atm_dev->signal != ATM_PHY_SIG_FOUND) { |
410 | int down_speed = buf[OFFSET_b] | (buf[OFFSET_b + 1] << 8) | 469 | int down_speed = buf[OFFSET_b] | (buf[OFFSET_b + 1] << 8) |
411 | | (buf[OFFSET_b + 2] << 16) | (buf[OFFSET_b + 3] << 24); | 470 | | (buf[OFFSET_b + 2] << 16) | (buf[OFFSET_b + 3] << 24); |
412 | int up_speed = buf[OFFSET_b + 4] | (buf[OFFSET_b + 5] << 8) | 471 | int up_speed = buf[OFFSET_b + 4] | (buf[OFFSET_b + 5] << 8) |
413 | | (buf[OFFSET_b + 6] << 16) | (buf[OFFSET_b + 7] << 24); | 472 | | (buf[OFFSET_b + 6] << 16) | (buf[OFFSET_b + 7] << 24); |
414 | 473 | ||
415 | if (!(down_speed & 0x0000ffff) && | 474 | if (!(down_speed & 0x0000ffff) && !(up_speed & 0x0000ffff)) { |
416 | !(up_speed & 0x0000ffff)) { | ||
417 | down_speed >>= 16; | 475 | down_speed >>= 16; |
418 | up_speed >>= 16; | 476 | up_speed >>= 16; |
419 | } | 477 | } |
420 | instance->u.atm_dev->link_rate = down_speed * 1000 / 424; | ||
421 | instance->u.atm_dev->signal = ATM_PHY_SIG_FOUND; | ||
422 | 478 | ||
423 | printk(KERN_NOTICE | 479 | atm_dev->link_rate = down_speed * 1000 / 424; |
424 | "ADSL line is up (%d Kib/s down | %d Kib/s up)\n", | 480 | atm_dev->signal = ATM_PHY_SIG_FOUND; |
425 | down_speed, up_speed); | 481 | |
482 | atm_info(usbatm, | ||
483 | "ADSL line is up (%d Kib/s down | %d Kib/s up)\n", | ||
484 | down_speed, up_speed); | ||
426 | } | 485 | } |
427 | break; | 486 | break; |
428 | 487 | ||
429 | default: | 488 | default: |
430 | if (instance->u.atm_dev->signal != ATM_PHY_SIG_UNKNOWN) { | 489 | if (atm_dev->signal != ATM_PHY_SIG_UNKNOWN) { |
431 | instance->u.atm_dev->signal = ATM_PHY_SIG_UNKNOWN; | 490 | atm_dev->signal = ATM_PHY_SIG_UNKNOWN; |
432 | printk(KERN_NOTICE "Unknown line state %02x\n", buf[OFFSET_7]); | 491 | atm_info(usbatm, "Unknown line state %02x\n", buf[OFFSET_7]); |
433 | } | 492 | } |
434 | break; | 493 | break; |
435 | } | 494 | } |
436 | } | 495 | } |
437 | 496 | ||
438 | static void speedtch_timer_poll(unsigned long data) | 497 | static void speedtch_status_poll(unsigned long data) |
439 | { | 498 | { |
440 | struct speedtch_instance_data *instance = (void *)data; | 499 | struct speedtch_instance_data *instance = (void *)data; |
441 | 500 | ||
442 | schedule_work(&instance->poll_work); | 501 | schedule_work(&instance->status_checker); |
443 | mod_timer(&instance->poll_timer, jiffies + (5 * HZ)); | 502 | |
503 | /* The following check is racy, but the race is harmless */ | ||
504 | if (instance->poll_delay < MAX_POLL_DELAY) | ||
505 | mod_timer(&instance->status_checker.timer, jiffies + msecs_to_jiffies(instance->poll_delay)); | ||
506 | else | ||
507 | atm_warn(instance->usbatm, "Too many failures - disabling line status polling\n"); | ||
444 | } | 508 | } |
445 | 509 | ||
446 | #ifdef USE_FW_LOADER | 510 | static void speedtch_resubmit_int(unsigned long data) |
447 | static void speedtch_upload_firmware(struct speedtch_instance_data *instance, | ||
448 | const struct firmware *fw1, | ||
449 | const struct firmware *fw2) | ||
450 | { | 511 | { |
451 | unsigned char *buffer; | 512 | struct speedtch_instance_data *instance = (void *)data; |
452 | struct usb_device *usb_dev = instance->u.usb_dev; | 513 | struct urb *int_urb = instance->int_urb; |
453 | struct usb_interface *intf; | 514 | int ret; |
454 | int actual_length, ret; | ||
455 | int offset; | ||
456 | |||
457 | dbg("speedtch_upload_firmware"); | ||
458 | |||
459 | if (!(intf = usb_ifnum_to_if(usb_dev, 2))) { | ||
460 | dbg("speedtch_upload_firmware: interface not found!"); | ||
461 | goto fail; | ||
462 | } | ||
463 | |||
464 | if (!(buffer = (unsigned char *)__get_free_page(GFP_KERNEL))) { | ||
465 | dbg("speedtch_upload_firmware: no memory for buffer!"); | ||
466 | goto fail; | ||
467 | } | ||
468 | |||
469 | /* A user-space firmware loader may already have claimed interface #2 */ | ||
470 | if ((ret = | ||
471 | usb_driver_claim_interface(&speedtch_usb_driver, intf, NULL)) < 0) { | ||
472 | dbg("speedtch_upload_firmware: interface in use (%d)!", ret); | ||
473 | goto fail_free; | ||
474 | } | ||
475 | |||
476 | /* URB 7 */ | ||
477 | if (dl_512_first) { /* some modems need a read before writing the firmware */ | ||
478 | ret = usb_bulk_msg(usb_dev, usb_rcvbulkpipe(usb_dev, SPEEDTCH_ENDPOINT_FIRMWARE), | ||
479 | buffer, 0x200, &actual_length, 2000); | ||
480 | |||
481 | if (ret < 0 && ret != -ETIMEDOUT) | ||
482 | dbg("speedtch_upload_firmware: read BLOCK0 from modem failed (%d)!", ret); | ||
483 | else | ||
484 | dbg("speedtch_upload_firmware: BLOCK0 downloaded (%d bytes)", ret); | ||
485 | } | ||
486 | |||
487 | /* URB 8 : both leds are static green */ | ||
488 | for (offset = 0; offset < fw1->size; offset += PAGE_SIZE) { | ||
489 | int thislen = min_t(int, PAGE_SIZE, fw1->size - offset); | ||
490 | memcpy(buffer, fw1->data + offset, thislen); | ||
491 | 515 | ||
492 | ret = usb_bulk_msg(usb_dev, usb_sndbulkpipe(usb_dev, SPEEDTCH_ENDPOINT_FIRMWARE), | 516 | atm_dbg(instance->usbatm, "%s entered\n", __func__); |
493 | buffer, thislen, &actual_length, DATA_TIMEOUT); | ||
494 | 517 | ||
495 | if (ret < 0) { | 518 | if (int_urb) { |
496 | dbg("speedtch_upload_firmware: write BLOCK1 to modem failed (%d)!", ret); | 519 | ret = usb_submit_urb(int_urb, GFP_ATOMIC); |
497 | goto fail_release; | 520 | if (!ret) |
521 | schedule_work(&instance->status_checker); | ||
522 | else { | ||
523 | atm_dbg(instance->usbatm, "%s: usb_submit_urb failed with result %d\n", __func__, ret); | ||
524 | mod_timer(&instance->resubmit_timer, jiffies + msecs_to_jiffies(RESUBMIT_DELAY)); | ||
498 | } | 525 | } |
499 | dbg("speedtch_upload_firmware: BLOCK1 uploaded (%zu bytes)", fw1->size); | ||
500 | } | 526 | } |
527 | } | ||
501 | 528 | ||
502 | /* USB led blinking green, ADSL led off */ | 529 | static void speedtch_handle_int(struct urb *int_urb, struct pt_regs *regs) |
530 | { | ||
531 | struct speedtch_instance_data *instance = int_urb->context; | ||
532 | struct usbatm_data *usbatm = instance->usbatm; | ||
533 | unsigned int count = int_urb->actual_length; | ||
534 | int ret = int_urb->status; | ||
503 | 535 | ||
504 | /* URB 11 */ | 536 | /* The magic interrupt for "up state" */ |
505 | ret = usb_bulk_msg(usb_dev, usb_rcvbulkpipe(usb_dev, SPEEDTCH_ENDPOINT_FIRMWARE), | 537 | const static unsigned char up_int[6] = { 0xa1, 0x00, 0x01, 0x00, 0x00, 0x00 }; |
506 | buffer, 0x200, &actual_length, DATA_TIMEOUT); | 538 | /* The magic interrupt for "down state" */ |
539 | const static unsigned char down_int[6] = { 0xa1, 0x00, 0x00, 0x00, 0x00, 0x00 }; | ||
540 | |||
541 | atm_dbg(usbatm, "%s entered\n", __func__); | ||
507 | 542 | ||
508 | if (ret < 0) { | 543 | if (ret < 0) { |
509 | dbg("speedtch_upload_firmware: read BLOCK2 from modem failed (%d)!", ret); | 544 | atm_dbg(usbatm, "%s: nonzero urb status %d!\n", __func__, ret); |
510 | goto fail_release; | 545 | goto fail; |
511 | } | 546 | } |
512 | dbg("speedtch_upload_firmware: BLOCK2 downloaded (%d bytes)", actual_length); | ||
513 | 547 | ||
514 | /* URBs 12 to 139 - USB led blinking green, ADSL led off */ | 548 | if ((count == 6) && !memcmp(up_int, instance->int_data, 6)) { |
515 | for (offset = 0; offset < fw2->size; offset += PAGE_SIZE) { | 549 | del_timer(&instance->status_checker.timer); |
516 | int thislen = min_t(int, PAGE_SIZE, fw2->size - offset); | 550 | atm_info(usbatm, "DSL line goes up\n"); |
517 | memcpy(buffer, fw2->data + offset, thislen); | 551 | } else if ((count == 6) && !memcmp(down_int, instance->int_data, 6)) { |
552 | atm_info(usbatm, "DSL line goes down\n"); | ||
553 | } else { | ||
554 | int i; | ||
518 | 555 | ||
519 | ret = usb_bulk_msg(usb_dev, usb_sndbulkpipe(usb_dev, SPEEDTCH_ENDPOINT_FIRMWARE), | 556 | atm_dbg(usbatm, "%s: unknown interrupt packet of length %d:", __func__, count); |
520 | buffer, thislen, &actual_length, DATA_TIMEOUT); | 557 | for (i = 0; i < count; i++) |
558 | printk(" %02x", instance->int_data[i]); | ||
559 | printk("\n"); | ||
560 | goto fail; | ||
561 | } | ||
521 | 562 | ||
563 | if ((int_urb = instance->int_urb)) { | ||
564 | ret = usb_submit_urb(int_urb, GFP_ATOMIC); | ||
565 | schedule_work(&instance->status_checker); | ||
522 | if (ret < 0) { | 566 | if (ret < 0) { |
523 | dbg("speedtch_upload_firmware: write BLOCK3 to modem failed (%d)!", ret); | 567 | atm_dbg(usbatm, "%s: usb_submit_urb failed with result %d\n", __func__, ret); |
524 | goto fail_release; | 568 | goto fail; |
525 | } | 569 | } |
526 | } | 570 | } |
527 | dbg("speedtch_upload_firmware: BLOCK3 uploaded (%zu bytes)", fw2->size); | ||
528 | |||
529 | /* USB led static green, ADSL led static red */ | ||
530 | |||
531 | /* URB 142 */ | ||
532 | ret = usb_bulk_msg(usb_dev, usb_rcvbulkpipe(usb_dev, SPEEDTCH_ENDPOINT_FIRMWARE), | ||
533 | buffer, 0x200, &actual_length, DATA_TIMEOUT); | ||
534 | |||
535 | if (ret < 0) { | ||
536 | dbg("speedtch_upload_firmware: read BLOCK4 from modem failed (%d)!", ret); | ||
537 | goto fail_release; | ||
538 | } | ||
539 | |||
540 | /* success */ | ||
541 | dbg("speedtch_upload_firmware: BLOCK4 downloaded (%d bytes)", actual_length); | ||
542 | |||
543 | /* Delay to allow firmware to start up. We can do this here | ||
544 | because we're in our own kernel thread anyway. */ | ||
545 | msleep(1000); | ||
546 | |||
547 | /* Enable software buffering, if requested */ | ||
548 | if (sw_buffering) | ||
549 | speedtch_set_swbuff(instance, 1); | ||
550 | |||
551 | /* Magic spell; don't ask us what this does */ | ||
552 | speedtch_test_sequence(instance); | ||
553 | |||
554 | /* Start modem synchronisation */ | ||
555 | if (speedtch_start_synchro(instance)) | ||
556 | dbg("speedtch_start_synchro: failed"); | ||
557 | |||
558 | speedtch_got_firmware(instance, 1); | ||
559 | 571 | ||
560 | free_page((unsigned long)buffer); | ||
561 | return; | 572 | return; |
562 | 573 | ||
563 | fail_release: | 574 | fail: |
564 | /* Only release interface #2 if uploading failed; we don't release it | 575 | if ((int_urb = instance->int_urb)) |
565 | we succeeded. This prevents the userspace tools from trying to load | 576 | mod_timer(&instance->resubmit_timer, jiffies + msecs_to_jiffies(RESUBMIT_DELAY)); |
566 | the firmware themselves */ | ||
567 | usb_driver_release_interface(&speedtch_usb_driver, intf); | ||
568 | fail_free: | ||
569 | free_page((unsigned long)buffer); | ||
570 | fail: | ||
571 | speedtch_got_firmware(instance, 0); | ||
572 | } | 577 | } |
573 | 578 | ||
574 | static int speedtch_find_firmware(struct speedtch_instance_data | 579 | static int speedtch_atm_start(struct usbatm_data *usbatm, struct atm_dev *atm_dev) |
575 | *instance, int phase, | ||
576 | const struct firmware **fw_p) | ||
577 | { | 580 | { |
578 | char buf[24]; | 581 | struct usb_device *usb_dev = usbatm->usb_dev; |
579 | const u16 bcdDevice = le16_to_cpu(instance->u.usb_dev->descriptor.bcdDevice); | 582 | struct speedtch_instance_data *instance = usbatm->driver_data; |
580 | const u8 major_revision = bcdDevice >> 8; | 583 | int i, ret; |
581 | const u8 minor_revision = bcdDevice & 0xff; | 584 | unsigned char mac_str[13]; |
582 | |||
583 | sprintf(buf, "speedtch-%d.bin.%x.%02x", phase, major_revision, minor_revision); | ||
584 | dbg("speedtch_find_firmware: looking for %s", buf); | ||
585 | |||
586 | if (request_firmware(fw_p, buf, &instance->u.usb_dev->dev)) { | ||
587 | sprintf(buf, "speedtch-%d.bin.%x", phase, major_revision); | ||
588 | dbg("speedtch_find_firmware: looking for %s", buf); | ||
589 | 585 | ||
590 | if (request_firmware(fw_p, buf, &instance->u.usb_dev->dev)) { | 586 | atm_dbg(usbatm, "%s entered\n", __func__); |
591 | sprintf(buf, "speedtch-%d.bin", phase); | ||
592 | dbg("speedtch_find_firmware: looking for %s", buf); | ||
593 | 587 | ||
594 | if (request_firmware(fw_p, buf, &instance->u.usb_dev->dev)) { | 588 | if ((ret = usb_set_interface(usb_dev, 1, altsetting)) < 0) { |
595 | dev_warn(&instance->u.usb_dev->dev, "no stage %d firmware found!", phase); | 589 | atm_dbg(usbatm, "%s: usb_set_interface returned %d!\n", __func__, ret); |
596 | return -ENOENT; | 590 | return ret; |
597 | } | ||
598 | } | ||
599 | } | 591 | } |
600 | 592 | ||
601 | dev_info(&instance->u.usb_dev->dev, "found stage %d firmware %s\n", phase, buf); | 593 | /* Set MAC address, it is stored in the serial number */ |
602 | 594 | memset(atm_dev->esi, 0, sizeof(atm_dev->esi)); | |
603 | return 0; | 595 | if (usb_string(usb_dev, usb_dev->descriptor.iSerialNumber, mac_str, sizeof(mac_str)) == 12) { |
604 | } | 596 | for (i = 0; i < 6; i++) |
605 | 597 | atm_dev->esi[i] = (hex2int(mac_str[i * 2]) * 16) + (hex2int(mac_str[i * 2 + 1])); | |
606 | static int speedtch_load_firmware(void *arg) | 598 | } |
607 | { | ||
608 | const struct firmware *fw1, *fw2; | ||
609 | struct speedtch_instance_data *instance = arg; | ||
610 | |||
611 | BUG_ON(!instance); | ||
612 | 599 | ||
613 | daemonize("firmware/speedtch"); | 600 | /* Start modem synchronisation */ |
601 | ret = speedtch_start_synchro(instance); | ||
614 | 602 | ||
615 | if (!speedtch_find_firmware(instance, 1, &fw1)) { | 603 | /* Set up interrupt endpoint */ |
616 | if (!speedtch_find_firmware(instance, 2, &fw2)) { | 604 | if (instance->int_urb) { |
617 | speedtch_upload_firmware(instance, fw1, fw2); | 605 | ret = usb_submit_urb(instance->int_urb, GFP_KERNEL); |
618 | release_firmware(fw2); | 606 | if (ret < 0) { |
607 | /* Doesn't matter; we'll poll anyway */ | ||
608 | atm_dbg(usbatm, "%s: submission of interrupt URB failed (%d)!\n", __func__, ret); | ||
609 | usb_free_urb(instance->int_urb); | ||
610 | instance->int_urb = NULL; | ||
619 | } | 611 | } |
620 | release_firmware(fw1); | ||
621 | } | 612 | } |
622 | 613 | ||
623 | /* In case we failed, set state back to NO_FIRMWARE so that | 614 | /* Start status polling */ |
624 | another later attempt may work. Otherwise, we never actually | 615 | mod_timer(&instance->status_checker.timer, jiffies + msecs_to_jiffies(1000)); |
625 | manage to recover if, for example, the firmware is on /usr and | ||
626 | we look for it too early. */ | ||
627 | speedtch_got_firmware(instance, 0); | ||
628 | 616 | ||
629 | module_put(THIS_MODULE); | ||
630 | udsl_put_instance(&instance->u); | ||
631 | return 0; | 617 | return 0; |
632 | } | 618 | } |
633 | #endif /* USE_FW_LOADER */ | ||
634 | 619 | ||
635 | static void speedtch_firmware_start(struct speedtch_instance_data *instance) | 620 | static void speedtch_atm_stop(struct usbatm_data *usbatm, struct atm_dev *atm_dev) |
636 | { | 621 | { |
637 | #ifdef USE_FW_LOADER | 622 | struct speedtch_instance_data *instance = usbatm->driver_data; |
638 | int ret; | 623 | struct urb *int_urb = instance->int_urb; |
639 | #endif | 624 | |
640 | 625 | atm_dbg(usbatm, "%s entered\n", __func__); | |
641 | dbg("speedtch_firmware_start"); | 626 | |
642 | 627 | del_timer_sync(&instance->status_checker.timer); | |
643 | down(&instance->u.serialize); /* vs self, speedtch_got_firmware */ | 628 | |
644 | 629 | /* | |
645 | if (instance->u.status >= UDSL_LOADING_FIRMWARE) { | 630 | * Since resubmit_timer and int_urb can schedule themselves and |
646 | up(&instance->u.serialize); | 631 | * each other, shutting them down correctly takes some care |
647 | return; | 632 | */ |
648 | } | 633 | instance->int_urb = NULL; /* signal shutdown */ |
634 | mb(); | ||
635 | usb_kill_urb(int_urb); | ||
636 | del_timer_sync(&instance->resubmit_timer); | ||
637 | /* | ||
638 | * At this point, speedtch_handle_int and speedtch_resubmit_int | ||
639 | * can run or be running, but instance->int_urb == NULL means that | ||
640 | * they will not reschedule | ||
641 | */ | ||
642 | usb_kill_urb(int_urb); | ||
643 | del_timer_sync(&instance->resubmit_timer); | ||
644 | usb_free_urb(int_urb); | ||
649 | 645 | ||
650 | instance->u.status = UDSL_LOADING_FIRMWARE; | 646 | flush_scheduled_work(); |
651 | up(&instance->u.serialize); | 647 | } |
652 | 648 | ||
653 | #ifdef USE_FW_LOADER | ||
654 | udsl_get_instance(&instance->u); | ||
655 | try_module_get(THIS_MODULE); | ||
656 | 649 | ||
657 | ret = kernel_thread(speedtch_load_firmware, instance, | 650 | /********** |
658 | CLONE_FS | CLONE_FILES); | 651 | ** USB ** |
652 | **********/ | ||
659 | 653 | ||
660 | if (ret >= 0) | 654 | static struct usb_device_id speedtch_usb_ids[] = { |
661 | return; /* OK */ | 655 | {USB_DEVICE(0x06b9, 0x4061)}, |
656 | {} | ||
657 | }; | ||
662 | 658 | ||
663 | dbg("speedtch_firmware_start: kernel_thread failed (%d)!", ret); | 659 | MODULE_DEVICE_TABLE(usb, speedtch_usb_ids); |
664 | 660 | ||
665 | module_put(THIS_MODULE); | 661 | static int speedtch_usb_probe(struct usb_interface *, const struct usb_device_id *); |
666 | udsl_put_instance(&instance->u); | ||
667 | /* Just pretend it never happened... hope modem_run happens */ | ||
668 | #endif /* USE_FW_LOADER */ | ||
669 | 662 | ||
670 | speedtch_got_firmware(instance, 0); | 663 | static struct usb_driver speedtch_usb_driver = { |
671 | } | 664 | .owner = THIS_MODULE, |
672 | 665 | .name = speedtch_driver_name, | |
673 | static int speedtch_firmware_wait(struct udsl_instance_data *instance) | 666 | .probe = speedtch_usb_probe, |
674 | { | 667 | .disconnect = usbatm_usb_disconnect, |
675 | speedtch_firmware_start((void *)instance); | 668 | .id_table = speedtch_usb_ids |
669 | }; | ||
676 | 670 | ||
677 | if (wait_event_interruptible(instance->firmware_waiters, instance->status != UDSL_LOADING_FIRMWARE) < 0) | 671 | static void speedtch_release_interfaces(struct usb_device *usb_dev, int num_interfaces) { |
678 | return -ERESTARTSYS; | 672 | struct usb_interface *cur_intf; |
673 | int i; | ||
679 | 674 | ||
680 | return (instance->status == UDSL_LOADED_FIRMWARE) ? 0 : -EAGAIN; | 675 | for(i = 0; i < num_interfaces; i++) |
676 | if ((cur_intf = usb_ifnum_to_if(usb_dev, i))) { | ||
677 | usb_set_intfdata(cur_intf, NULL); | ||
678 | usb_driver_release_interface(&speedtch_usb_driver, cur_intf); | ||
679 | } | ||
681 | } | 680 | } |
682 | 681 | ||
683 | /********** | 682 | static int speedtch_bind(struct usbatm_data *usbatm, |
684 | ** USB ** | 683 | struct usb_interface *intf, |
685 | **********/ | 684 | const struct usb_device_id *id, |
686 | 685 | int *need_heavy_init) | |
687 | static int speedtch_usb_ioctl(struct usb_interface *intf, unsigned int code, | ||
688 | void *user_data) | ||
689 | { | 686 | { |
690 | struct speedtch_instance_data *instance = usb_get_intfdata(intf); | 687 | struct usb_device *usb_dev = interface_to_usbdev(intf); |
688 | struct usb_interface *cur_intf; | ||
689 | struct speedtch_instance_data *instance; | ||
690 | int ifnum = intf->altsetting->desc.bInterfaceNumber; | ||
691 | int num_interfaces = usb_dev->actconfig->desc.bNumInterfaces; | ||
692 | int i, ret; | ||
691 | 693 | ||
692 | dbg("speedtch_usb_ioctl entered"); | 694 | usb_dbg(usbatm, "%s entered\n", __func__); |
693 | 695 | ||
694 | if (!instance) { | 696 | if (usb_dev->descriptor.bDeviceClass != USB_CLASS_VENDOR_SPEC) { |
695 | dbg("speedtch_usb_ioctl: NULL instance!"); | 697 | usb_dbg(usbatm, "%s: wrong device class %d\n", __func__, usb_dev->descriptor.bDeviceClass); |
696 | return -ENODEV; | 698 | return -ENODEV; |
697 | } | 699 | } |
698 | 700 | ||
699 | switch (code) { | 701 | /* claim all interfaces */ |
700 | case UDSL_IOCTL_LINE_UP: | ||
701 | instance->u.atm_dev->signal = ATM_PHY_SIG_FOUND; | ||
702 | speedtch_got_firmware(instance, 1); | ||
703 | return (instance->u.status == UDSL_LOADED_FIRMWARE) ? 0 : -EIO; | ||
704 | case UDSL_IOCTL_LINE_DOWN: | ||
705 | instance->u.atm_dev->signal = ATM_PHY_SIG_LOST; | ||
706 | return 0; | ||
707 | default: | ||
708 | return -ENOTTY; | ||
709 | } | ||
710 | } | ||
711 | 702 | ||
712 | static int speedtch_usb_probe(struct usb_interface *intf, | 703 | for (i=0; i < num_interfaces; i++) { |
713 | const struct usb_device_id *id) | 704 | cur_intf = usb_ifnum_to_if(usb_dev, i); |
714 | { | ||
715 | struct usb_device *dev = interface_to_usbdev(intf); | ||
716 | int ifnum = intf->altsetting->desc.bInterfaceNumber; | ||
717 | struct speedtch_instance_data *instance; | ||
718 | unsigned char mac_str[13]; | ||
719 | int ret, i; | ||
720 | char buf7[SIZE_7]; | ||
721 | 705 | ||
722 | dbg("speedtch_usb_probe: trying device with vendor=0x%x, product=0x%x, ifnum %d", | 706 | if ((i != ifnum) && cur_intf) { |
723 | le16_to_cpu(dev->descriptor.idVendor), | 707 | ret = usb_driver_claim_interface(&speedtch_usb_driver, cur_intf, usbatm); |
724 | le16_to_cpu(dev->descriptor.idProduct), ifnum); | ||
725 | 708 | ||
726 | if ((dev->descriptor.bDeviceClass != USB_CLASS_VENDOR_SPEC) || | 709 | if (ret < 0) { |
727 | (ifnum != 1)) | 710 | usb_dbg(usbatm, "%s: failed to claim interface %d (%d)\n", __func__, i, ret); |
728 | return -ENODEV; | 711 | speedtch_release_interfaces(usb_dev, i); |
729 | 712 | return ret; | |
730 | dbg("speedtch_usb_probe: device accepted"); | 713 | } |
714 | } | ||
715 | } | ||
731 | 716 | ||
732 | /* instance init */ | ||
733 | instance = kmalloc(sizeof(*instance), GFP_KERNEL); | 717 | instance = kmalloc(sizeof(*instance), GFP_KERNEL); |
718 | |||
734 | if (!instance) { | 719 | if (!instance) { |
735 | dbg("speedtch_usb_probe: no memory for instance data!"); | 720 | usb_dbg(usbatm, "%s: no memory for instance data!\n", __func__); |
736 | return -ENOMEM; | 721 | ret = -ENOMEM; |
722 | goto fail_release; | ||
737 | } | 723 | } |
738 | 724 | ||
739 | memset(instance, 0, sizeof(struct speedtch_instance_data)); | 725 | memset(instance, 0, sizeof(struct speedtch_instance_data)); |
740 | 726 | ||
741 | if ((ret = usb_set_interface(dev, 0, 0)) < 0) | 727 | instance->usbatm = usbatm; |
742 | goto fail; | ||
743 | 728 | ||
744 | if ((ret = usb_set_interface(dev, 2, 0)) < 0) | 729 | INIT_WORK(&instance->status_checker, (void *)speedtch_check_status, instance); |
745 | goto fail; | ||
746 | 730 | ||
747 | instance->u.data_endpoint = SPEEDTCH_ENDPOINT_DATA; | 731 | instance->status_checker.timer.function = speedtch_status_poll; |
748 | instance->u.firmware_wait = speedtch_firmware_wait; | 732 | instance->status_checker.timer.data = (unsigned long)instance; |
749 | instance->u.driver_name = speedtch_driver_name; | 733 | instance->poll_delay = MIN_POLL_DELAY; |
750 | 734 | ||
751 | ret = udsl_instance_setup(dev, &instance->u); | 735 | init_timer(&instance->resubmit_timer); |
752 | if (ret) | 736 | instance->resubmit_timer.function = speedtch_resubmit_int; |
753 | goto fail; | 737 | instance->resubmit_timer.data = (unsigned long)instance; |
754 | 738 | ||
755 | init_timer(&instance->poll_timer); | 739 | instance->int_urb = usb_alloc_urb(0, GFP_KERNEL); |
756 | instance->poll_timer.function = speedtch_timer_poll; | ||
757 | instance->poll_timer.data = (unsigned long)instance; | ||
758 | 740 | ||
759 | INIT_WORK(&instance->poll_work, (void *)speedtch_poll_status, instance); | 741 | if (instance->int_urb) |
742 | usb_fill_int_urb(instance->int_urb, usb_dev, | ||
743 | usb_rcvintpipe(usb_dev, ENDPOINT_INT), | ||
744 | instance->int_data, sizeof(instance->int_data), | ||
745 | speedtch_handle_int, instance, 50); | ||
746 | else | ||
747 | usb_dbg(usbatm, "%s: no memory for interrupt urb!\n", __func__); | ||
760 | 748 | ||
761 | /* set MAC address, it is stored in the serial number */ | 749 | /* check whether the modem already seems to be alive */ |
762 | memset(instance->u.atm_dev->esi, 0, sizeof(instance->u.atm_dev->esi)); | 750 | ret = usb_control_msg(usb_dev, usb_rcvctrlpipe(usb_dev, 0), |
763 | if (usb_string(dev, dev->descriptor.iSerialNumber, mac_str, sizeof(mac_str)) == 12) { | 751 | 0x12, 0xc0, 0x07, 0x00, |
764 | for (i = 0; i < 6; i++) | 752 | instance->scratch_buffer + OFFSET_7, SIZE_7, 500); |
765 | instance->u.atm_dev->esi[i] = | ||
766 | (hex2int(mac_str[i * 2]) * 16) + (hex2int(mac_str[i * 2 + 1])); | ||
767 | } | ||
768 | 753 | ||
769 | /* First check whether the modem already seems to be alive */ | 754 | *need_heavy_init = (ret != SIZE_7); |
770 | ret = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0), | ||
771 | 0x12, 0xc0, 0x07, 0x00, buf7, SIZE_7, 500); | ||
772 | 755 | ||
773 | if (ret == SIZE_7) { | 756 | usb_dbg(usbatm, "%s: firmware %s loaded\n", __func__, need_heavy_init ? "not" : "already"); |
774 | dbg("firmware appears to be already loaded"); | 757 | |
775 | speedtch_got_firmware(instance, 1); | 758 | if (*need_heavy_init) |
776 | speedtch_poll_status(instance); | 759 | if ((ret = usb_reset_device(usb_dev)) < 0) |
777 | } else { | 760 | goto fail_free; |
778 | speedtch_firmware_start(instance); | ||
779 | } | ||
780 | 761 | ||
781 | usb_set_intfdata(intf, instance); | 762 | usbatm->driver_data = instance; |
782 | 763 | ||
783 | return 0; | 764 | return 0; |
784 | 765 | ||
785 | fail: | 766 | fail_free: |
767 | usb_free_urb(instance->int_urb); | ||
786 | kfree(instance); | 768 | kfree(instance); |
787 | 769 | fail_release: | |
788 | return -ENOMEM; | 770 | speedtch_release_interfaces(usb_dev, num_interfaces); |
771 | return ret; | ||
789 | } | 772 | } |
790 | 773 | ||
791 | static void speedtch_usb_disconnect(struct usb_interface *intf) | 774 | static void speedtch_unbind(struct usbatm_data *usbatm, struct usb_interface *intf) |
792 | { | 775 | { |
793 | struct speedtch_instance_data *instance = usb_get_intfdata(intf); | 776 | struct usb_device *usb_dev = interface_to_usbdev(intf); |
794 | 777 | struct speedtch_instance_data *instance = usbatm->driver_data; | |
795 | dbg("speedtch_usb_disconnect entered"); | ||
796 | |||
797 | if (!instance) { | ||
798 | dbg("speedtch_usb_disconnect: NULL instance!"); | ||
799 | return; | ||
800 | } | ||
801 | 778 | ||
802 | /*QQ need to handle disconnects on interface #2 while uploading firmware */ | 779 | usb_dbg(usbatm, "%s entered\n", __func__); |
803 | /*QQ and what about interface #1? */ | ||
804 | |||
805 | if (instance->int_urb) { | ||
806 | struct urb *int_urb = instance->int_urb; | ||
807 | instance->int_urb = NULL; | ||
808 | wmb(); | ||
809 | usb_unlink_urb(int_urb); | ||
810 | usb_free_urb(int_urb); | ||
811 | } | ||
812 | 780 | ||
813 | instance->int_data[0] = 1; | 781 | speedtch_release_interfaces(usb_dev, usb_dev->actconfig->desc.bNumInterfaces); |
814 | del_timer_sync(&instance->poll_timer); | 782 | usb_free_urb(instance->int_urb); |
815 | wmb(); | 783 | kfree(instance); |
816 | flush_scheduled_work(); | ||
817 | |||
818 | udsl_instance_disconnect(&instance->u); | ||
819 | |||
820 | /* clean up */ | ||
821 | usb_set_intfdata(intf, NULL); | ||
822 | udsl_put_instance(&instance->u); | ||
823 | } | 784 | } |
824 | 785 | ||
786 | |||
825 | /*********** | 787 | /*********** |
826 | ** init ** | 788 | ** init ** |
827 | ***********/ | 789 | ***********/ |
828 | 790 | ||
791 | static struct usbatm_driver speedtch_usbatm_driver = { | ||
792 | .owner = THIS_MODULE, | ||
793 | .driver_name = speedtch_driver_name, | ||
794 | .bind = speedtch_bind, | ||
795 | .heavy_init = speedtch_heavy_init, | ||
796 | .unbind = speedtch_unbind, | ||
797 | .atm_start = speedtch_atm_start, | ||
798 | .atm_stop = speedtch_atm_stop, | ||
799 | .in = ENDPOINT_DATA, | ||
800 | .out = ENDPOINT_DATA | ||
801 | }; | ||
802 | |||
803 | static int speedtch_usb_probe(struct usb_interface *intf, const struct usb_device_id *id) | ||
804 | { | ||
805 | return usbatm_usb_probe(intf, id, &speedtch_usbatm_driver); | ||
806 | } | ||
807 | |||
829 | static int __init speedtch_usb_init(void) | 808 | static int __init speedtch_usb_init(void) |
830 | { | 809 | { |
831 | dbg("speedtch_usb_init: driver version " DRIVER_VERSION); | 810 | dbg("%s: driver version %s", __func__, DRIVER_VERSION); |
832 | 811 | ||
833 | return usb_register(&speedtch_usb_driver); | 812 | return usb_register(&speedtch_usb_driver); |
834 | } | 813 | } |
835 | 814 | ||
836 | static void __exit speedtch_usb_cleanup(void) | 815 | static void __exit speedtch_usb_cleanup(void) |
837 | { | 816 | { |
838 | dbg("speedtch_usb_cleanup entered"); | 817 | dbg("%s", __func__); |
839 | 818 | ||
840 | usb_deregister(&speedtch_usb_driver); | 819 | usb_deregister(&speedtch_usb_driver); |
841 | } | 820 | } |