diff options
author | Dmitry Torokhov <dtor@insightbb.com> | 2007-05-01 00:24:54 -0400 |
---|---|---|
committer | Dmitry Torokhov <dtor@insightbb.com> | 2007-05-01 00:24:54 -0400 |
commit | bc95f3669f5e6f63cf0b84fe4922c3c6dd4aa775 (patch) | |
tree | 427fcf2a7287c16d4b5aa6cbf494d59579a6a8b1 /drivers/usb | |
parent | 3d29cdff999c37b3876082278a8134a0642a02cd (diff) | |
parent | dc87c3985e9b442c60994308a96f887579addc39 (diff) |
Merge master.kernel.org:/pub/scm/linux/kernel/git/torvalds/linux-2.6
Conflicts:
drivers/usb/input/Makefile
drivers/usb/input/gtco.c
Diffstat (limited to 'drivers/usb')
127 files changed, 8142 insertions, 11382 deletions
diff --git a/drivers/usb/Makefile b/drivers/usb/Makefile index 825bf884537a..f5de58a63f2b 100644 --- a/drivers/usb/Makefile +++ b/drivers/usb/Makefile | |||
@@ -15,7 +15,6 @@ obj-$(CONFIG_USB_OHCI_HCD) += host/ | |||
15 | obj-$(CONFIG_USB_UHCI_HCD) += host/ | 15 | obj-$(CONFIG_USB_UHCI_HCD) += host/ |
16 | obj-$(CONFIG_USB_SL811_HCD) += host/ | 16 | obj-$(CONFIG_USB_SL811_HCD) += host/ |
17 | obj-$(CONFIG_USB_U132_HCD) += host/ | 17 | obj-$(CONFIG_USB_U132_HCD) += host/ |
18 | obj-$(CONFIG_ETRAX_USB_HOST) += host/ | ||
19 | obj-$(CONFIG_USB_OHCI_AT91) += host/ | 18 | obj-$(CONFIG_USB_OHCI_AT91) += host/ |
20 | 19 | ||
21 | obj-$(CONFIG_USB_ACM) += class/ | 20 | obj-$(CONFIG_USB_ACM) += class/ |
@@ -27,10 +26,7 @@ obj-$(CONFIG_USB) += storage/ | |||
27 | obj-$(CONFIG_USB_ACECAD) += input/ | 26 | obj-$(CONFIG_USB_ACECAD) += input/ |
28 | obj-$(CONFIG_USB_AIPTEK) += input/ | 27 | obj-$(CONFIG_USB_AIPTEK) += input/ |
29 | obj-$(CONFIG_USB_ATI_REMOTE) += input/ | 28 | obj-$(CONFIG_USB_ATI_REMOTE) += input/ |
30 | obj-$(CONFIG_USB_HID) += input/ | ||
31 | obj-$(CONFIG_USB_KBD) += input/ | ||
32 | obj-$(CONFIG_USB_KBTAB) += input/ | 29 | obj-$(CONFIG_USB_KBTAB) += input/ |
33 | obj-$(CONFIG_USB_MOUSE) += input/ | ||
34 | obj-$(CONFIG_USB_MTOUCH) += input/ | 30 | obj-$(CONFIG_USB_MTOUCH) += input/ |
35 | obj-$(CONFIG_USB_POWERMATE) += input/ | 31 | obj-$(CONFIG_USB_POWERMATE) += input/ |
36 | obj-$(CONFIG_USB_WACOM) += input/ | 32 | obj-$(CONFIG_USB_WACOM) += input/ |
@@ -51,6 +47,7 @@ obj-$(CONFIG_USB_SERIAL) += serial/ | |||
51 | obj-$(CONFIG_USB_ADUTUX) += misc/ | 47 | obj-$(CONFIG_USB_ADUTUX) += misc/ |
52 | obj-$(CONFIG_USB_APPLEDISPLAY) += misc/ | 48 | obj-$(CONFIG_USB_APPLEDISPLAY) += misc/ |
53 | obj-$(CONFIG_USB_AUERSWALD) += misc/ | 49 | obj-$(CONFIG_USB_AUERSWALD) += misc/ |
50 | obj-$(CONFIG_USB_BERRY_CHARGE) += misc/ | ||
54 | obj-$(CONFIG_USB_CYPRESS_CY7C63)+= misc/ | 51 | obj-$(CONFIG_USB_CYPRESS_CY7C63)+= misc/ |
55 | obj-$(CONFIG_USB_CYTHERM) += misc/ | 52 | obj-$(CONFIG_USB_CYTHERM) += misc/ |
56 | obj-$(CONFIG_USB_EMI26) += misc/ | 53 | obj-$(CONFIG_USB_EMI26) += misc/ |
diff --git a/drivers/usb/atm/cxacru.c b/drivers/usb/atm/cxacru.c index 3dfa3e40e148..30b7bfbc985a 100644 --- a/drivers/usb/atm/cxacru.c +++ b/drivers/usb/atm/cxacru.c | |||
@@ -4,6 +4,7 @@ | |||
4 | * | 4 | * |
5 | * Copyright (C) 2004 David Woodhouse, Duncan Sands, Roman Kagan | 5 | * Copyright (C) 2004 David Woodhouse, Duncan Sands, Roman Kagan |
6 | * Copyright (C) 2005 Duncan Sands, Roman Kagan (rkagan % mail ! ru) | 6 | * Copyright (C) 2005 Duncan Sands, Roman Kagan (rkagan % mail ! ru) |
7 | * Copyright (C) 2007 Simon Arlott | ||
7 | * | 8 | * |
8 | * This program is free software; you can redistribute it and/or modify it | 9 | * 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 | 10 | * under the terms of the GNU General Public License as published by the Free |
@@ -34,14 +35,14 @@ | |||
34 | #include <linux/errno.h> | 35 | #include <linux/errno.h> |
35 | #include <linux/slab.h> | 36 | #include <linux/slab.h> |
36 | #include <linux/init.h> | 37 | #include <linux/init.h> |
37 | #include <linux/device.h> /* FIXME: linux/firmware.h should include it itself */ | 38 | #include <linux/device.h> |
38 | #include <linux/firmware.h> | 39 | #include <linux/firmware.h> |
39 | #include <linux/mutex.h> | 40 | #include <linux/mutex.h> |
40 | 41 | ||
41 | #include "usbatm.h" | 42 | #include "usbatm.h" |
42 | 43 | ||
43 | #define DRIVER_AUTHOR "Roman Kagan, David Woodhouse, Duncan Sands" | 44 | #define DRIVER_AUTHOR "Roman Kagan, David Woodhouse, Duncan Sands, Simon Arlott" |
44 | #define DRIVER_VERSION "0.2" | 45 | #define DRIVER_VERSION "0.3" |
45 | #define DRIVER_DESC "Conexant AccessRunner ADSL USB modem driver" | 46 | #define DRIVER_DESC "Conexant AccessRunner ADSL USB modem driver" |
46 | 47 | ||
47 | static const char cxacru_driver_name[] = "cxacru"; | 48 | static const char cxacru_driver_name[] = "cxacru"; |
@@ -64,7 +65,7 @@ static const char cxacru_driver_name[] = "cxacru"; | |||
64 | #define SDRAM_ENA 0x1 | 65 | #define SDRAM_ENA 0x1 |
65 | 66 | ||
66 | #define CMD_TIMEOUT 2000 /* msecs */ | 67 | #define CMD_TIMEOUT 2000 /* msecs */ |
67 | #define POLL_INTERVAL 5000 /* msecs */ | 68 | #define POLL_INTERVAL 1 /* secs */ |
68 | 69 | ||
69 | /* commands for interaction with the modem through the control channel before | 70 | /* commands for interaction with the modem through the control channel before |
70 | * firmware is loaded */ | 71 | * firmware is loaded */ |
@@ -146,6 +147,13 @@ enum cxacru_info_idx { | |||
146 | CXINF_MAX = 0x1c, | 147 | CXINF_MAX = 0x1c, |
147 | }; | 148 | }; |
148 | 149 | ||
150 | enum cxacru_poll_state { | ||
151 | CXPOLL_STOPPING, | ||
152 | CXPOLL_STOPPED, | ||
153 | CXPOLL_POLLING, | ||
154 | CXPOLL_SHUTDOWN | ||
155 | }; | ||
156 | |||
149 | struct cxacru_modem_type { | 157 | struct cxacru_modem_type { |
150 | u32 pll_f_clk; | 158 | u32 pll_f_clk; |
151 | u32 pll_b_clk; | 159 | u32 pll_b_clk; |
@@ -158,7 +166,12 @@ struct cxacru_data { | |||
158 | const struct cxacru_modem_type *modem_type; | 166 | const struct cxacru_modem_type *modem_type; |
159 | 167 | ||
160 | int line_status; | 168 | int line_status; |
169 | struct mutex adsl_state_serialize; | ||
170 | int adsl_status; | ||
161 | struct delayed_work poll_work; | 171 | struct delayed_work poll_work; |
172 | u32 card_info[CXINF_MAX]; | ||
173 | struct mutex poll_state_serialize; | ||
174 | int poll_state; | ||
162 | 175 | ||
163 | /* contol handles */ | 176 | /* contol handles */ |
164 | struct mutex cm_serialize; | 177 | struct mutex cm_serialize; |
@@ -170,6 +183,275 @@ struct cxacru_data { | |||
170 | struct completion snd_done; | 183 | struct completion snd_done; |
171 | }; | 184 | }; |
172 | 185 | ||
186 | static int cxacru_cm(struct cxacru_data *instance, enum cxacru_cm_request cm, | ||
187 | u8 *wdata, int wsize, u8 *rdata, int rsize); | ||
188 | static void cxacru_poll_status(struct work_struct *work); | ||
189 | |||
190 | /* Card info exported through sysfs */ | ||
191 | #define CXACRU__ATTR_INIT(_name) \ | ||
192 | static DEVICE_ATTR(_name, S_IRUGO, cxacru_sysfs_show_##_name, NULL) | ||
193 | |||
194 | #define CXACRU_CMD_INIT(_name) \ | ||
195 | static DEVICE_ATTR(_name, S_IWUSR | S_IRUGO, \ | ||
196 | cxacru_sysfs_show_##_name, cxacru_sysfs_store_##_name) | ||
197 | |||
198 | #define CXACRU_ATTR_INIT(_value, _type, _name) \ | ||
199 | static ssize_t cxacru_sysfs_show_##_name(struct device *dev, \ | ||
200 | struct device_attribute *attr, char *buf) \ | ||
201 | { \ | ||
202 | struct usb_interface *intf = to_usb_interface(dev); \ | ||
203 | struct usbatm_data *usbatm_instance = usb_get_intfdata(intf); \ | ||
204 | struct cxacru_data *instance = usbatm_instance->driver_data; \ | ||
205 | return cxacru_sysfs_showattr_##_type(instance->card_info[_value], buf); \ | ||
206 | } \ | ||
207 | CXACRU__ATTR_INIT(_name) | ||
208 | |||
209 | #define CXACRU_ATTR_CREATE(_v, _t, _name) CXACRU_DEVICE_CREATE_FILE(_name) | ||
210 | #define CXACRU_CMD_CREATE(_name) CXACRU_DEVICE_CREATE_FILE(_name) | ||
211 | #define CXACRU__ATTR_CREATE(_name) CXACRU_DEVICE_CREATE_FILE(_name) | ||
212 | |||
213 | #define CXACRU_ATTR_REMOVE(_v, _t, _name) CXACRU_DEVICE_REMOVE_FILE(_name) | ||
214 | #define CXACRU_CMD_REMOVE(_name) CXACRU_DEVICE_REMOVE_FILE(_name) | ||
215 | #define CXACRU__ATTR_REMOVE(_name) CXACRU_DEVICE_REMOVE_FILE(_name) | ||
216 | |||
217 | static ssize_t cxacru_sysfs_showattr_u32(u32 value, char *buf) | ||
218 | { | ||
219 | return snprintf(buf, PAGE_SIZE, "%u\n", value); | ||
220 | } | ||
221 | |||
222 | static ssize_t cxacru_sysfs_showattr_s8(s8 value, char *buf) | ||
223 | { | ||
224 | return snprintf(buf, PAGE_SIZE, "%d\n", value); | ||
225 | } | ||
226 | |||
227 | static ssize_t cxacru_sysfs_showattr_dB(s16 value, char *buf) | ||
228 | { | ||
229 | if (unlikely(value < 0)) { | ||
230 | return snprintf(buf, PAGE_SIZE, "%d.%02u\n", | ||
231 | value / 100, -value % 100); | ||
232 | } else { | ||
233 | return snprintf(buf, PAGE_SIZE, "%d.%02u\n", | ||
234 | value / 100, value % 100); | ||
235 | } | ||
236 | } | ||
237 | |||
238 | static ssize_t cxacru_sysfs_showattr_bool(u32 value, char *buf) | ||
239 | { | ||
240 | switch (value) { | ||
241 | case 0: return snprintf(buf, PAGE_SIZE, "no\n"); | ||
242 | case 1: return snprintf(buf, PAGE_SIZE, "yes\n"); | ||
243 | default: return 0; | ||
244 | } | ||
245 | } | ||
246 | |||
247 | static ssize_t cxacru_sysfs_showattr_LINK(u32 value, char *buf) | ||
248 | { | ||
249 | switch (value) { | ||
250 | case 1: return snprintf(buf, PAGE_SIZE, "not connected\n"); | ||
251 | case 2: return snprintf(buf, PAGE_SIZE, "connected\n"); | ||
252 | case 3: return snprintf(buf, PAGE_SIZE, "lost\n"); | ||
253 | default: return snprintf(buf, PAGE_SIZE, "unknown (%u)\n", value); | ||
254 | } | ||
255 | } | ||
256 | |||
257 | static ssize_t cxacru_sysfs_showattr_LINE(u32 value, char *buf) | ||
258 | { | ||
259 | switch (value) { | ||
260 | case 0: return snprintf(buf, PAGE_SIZE, "down\n"); | ||
261 | case 1: return snprintf(buf, PAGE_SIZE, "attempting to activate\n"); | ||
262 | case 2: return snprintf(buf, PAGE_SIZE, "training\n"); | ||
263 | case 3: return snprintf(buf, PAGE_SIZE, "channel analysis\n"); | ||
264 | case 4: return snprintf(buf, PAGE_SIZE, "exchange\n"); | ||
265 | case 5: return snprintf(buf, PAGE_SIZE, "up\n"); | ||
266 | case 6: return snprintf(buf, PAGE_SIZE, "waiting\n"); | ||
267 | case 7: return snprintf(buf, PAGE_SIZE, "initialising\n"); | ||
268 | default: return snprintf(buf, PAGE_SIZE, "unknown (%u)\n", value); | ||
269 | } | ||
270 | } | ||
271 | |||
272 | static ssize_t cxacru_sysfs_showattr_MODU(u32 value, char *buf) | ||
273 | { | ||
274 | switch (value) { | ||
275 | case 0: return 0; | ||
276 | case 1: return snprintf(buf, PAGE_SIZE, "ANSI T1.413\n"); | ||
277 | case 2: return snprintf(buf, PAGE_SIZE, "ITU-T G.992.1 (G.DMT)\n"); | ||
278 | case 3: return snprintf(buf, PAGE_SIZE, "ITU-T G.992.2 (G.LITE)\n"); | ||
279 | default: return snprintf(buf, PAGE_SIZE, "unknown (%u)\n", value); | ||
280 | } | ||
281 | } | ||
282 | |||
283 | /* | ||
284 | * This could use MAC_ADDRESS_HIGH and MAC_ADDRESS_LOW, but since | ||
285 | * this data is already in atm_dev there's no point. | ||
286 | * | ||
287 | * MAC_ADDRESS_HIGH = 0x????5544 | ||
288 | * MAC_ADDRESS_LOW = 0x33221100 | ||
289 | * Where 00-55 are bytes 0-5 of the MAC. | ||
290 | */ | ||
291 | static ssize_t cxacru_sysfs_show_mac_address(struct device *dev, | ||
292 | struct device_attribute *attr, char *buf) | ||
293 | { | ||
294 | struct usb_interface *intf = to_usb_interface(dev); | ||
295 | struct usbatm_data *usbatm_instance = usb_get_intfdata(intf); | ||
296 | struct atm_dev *atm_dev = usbatm_instance->atm_dev; | ||
297 | |||
298 | return snprintf(buf, PAGE_SIZE, "%02x:%02x:%02x:%02x:%02x:%02x\n", | ||
299 | atm_dev->esi[0], atm_dev->esi[1], atm_dev->esi[2], | ||
300 | atm_dev->esi[3], atm_dev->esi[4], atm_dev->esi[5]); | ||
301 | } | ||
302 | |||
303 | static ssize_t cxacru_sysfs_show_adsl_state(struct device *dev, | ||
304 | struct device_attribute *attr, char *buf) | ||
305 | { | ||
306 | struct usb_interface *intf = to_usb_interface(dev); | ||
307 | struct usbatm_data *usbatm_instance = usb_get_intfdata(intf); | ||
308 | struct cxacru_data *instance = usbatm_instance->driver_data; | ||
309 | u32 value = instance->card_info[CXINF_LINE_STARTABLE]; | ||
310 | |||
311 | switch (value) { | ||
312 | case 0: return snprintf(buf, PAGE_SIZE, "running\n"); | ||
313 | case 1: return snprintf(buf, PAGE_SIZE, "stopped\n"); | ||
314 | default: return snprintf(buf, PAGE_SIZE, "unknown (%u)\n", value); | ||
315 | } | ||
316 | } | ||
317 | |||
318 | static ssize_t cxacru_sysfs_store_adsl_state(struct device *dev, | ||
319 | struct device_attribute *attr, const char *buf, size_t count) | ||
320 | { | ||
321 | struct usb_interface *intf = to_usb_interface(dev); | ||
322 | struct usbatm_data *usbatm_instance = usb_get_intfdata(intf); | ||
323 | struct cxacru_data *instance = usbatm_instance->driver_data; | ||
324 | int ret; | ||
325 | int poll = -1; | ||
326 | char str_cmd[8]; | ||
327 | int len = strlen(buf); | ||
328 | |||
329 | if (!capable(CAP_NET_ADMIN)) | ||
330 | return -EACCES; | ||
331 | |||
332 | ret = sscanf(buf, "%7s", str_cmd); | ||
333 | if (ret != 1) | ||
334 | return -EINVAL; | ||
335 | ret = 0; | ||
336 | |||
337 | if (mutex_lock_interruptible(&instance->adsl_state_serialize)) | ||
338 | return -ERESTARTSYS; | ||
339 | |||
340 | if (!strcmp(str_cmd, "stop") || !strcmp(str_cmd, "restart")) { | ||
341 | ret = cxacru_cm(instance, CM_REQUEST_CHIP_ADSL_LINE_STOP, NULL, 0, NULL, 0); | ||
342 | if (ret < 0) { | ||
343 | atm_err(usbatm_instance, "change adsl state:" | ||
344 | " CHIP_ADSL_LINE_STOP returned %d\n", ret); | ||
345 | |||
346 | ret = -EIO; | ||
347 | } else { | ||
348 | ret = len; | ||
349 | poll = CXPOLL_STOPPED; | ||
350 | } | ||
351 | } | ||
352 | |||
353 | /* Line status is only updated every second | ||
354 | * and the device appears to only react to | ||
355 | * START/STOP every second too. Wait 1.5s to | ||
356 | * be sure that restart will have an effect. */ | ||
357 | if (!strcmp(str_cmd, "restart")) | ||
358 | msleep(1500); | ||
359 | |||
360 | if (!strcmp(str_cmd, "start") || !strcmp(str_cmd, "restart")) { | ||
361 | ret = cxacru_cm(instance, CM_REQUEST_CHIP_ADSL_LINE_START, NULL, 0, NULL, 0); | ||
362 | if (ret < 0) { | ||
363 | atm_err(usbatm_instance, "change adsl state:" | ||
364 | " CHIP_ADSL_LINE_START returned %d\n", ret); | ||
365 | |||
366 | ret = -EIO; | ||
367 | } else { | ||
368 | ret = len; | ||
369 | poll = CXPOLL_POLLING; | ||
370 | } | ||
371 | } | ||
372 | |||
373 | if (!strcmp(str_cmd, "poll")) { | ||
374 | ret = len; | ||
375 | poll = CXPOLL_POLLING; | ||
376 | } | ||
377 | |||
378 | if (ret == 0) { | ||
379 | ret = -EINVAL; | ||
380 | poll = -1; | ||
381 | } | ||
382 | |||
383 | if (poll == CXPOLL_POLLING) { | ||
384 | mutex_lock(&instance->poll_state_serialize); | ||
385 | switch (instance->poll_state) { | ||
386 | case CXPOLL_STOPPED: | ||
387 | /* start polling */ | ||
388 | instance->poll_state = CXPOLL_POLLING; | ||
389 | break; | ||
390 | |||
391 | case CXPOLL_STOPPING: | ||
392 | /* abort stop request */ | ||
393 | instance->poll_state = CXPOLL_POLLING; | ||
394 | case CXPOLL_POLLING: | ||
395 | case CXPOLL_SHUTDOWN: | ||
396 | /* don't start polling */ | ||
397 | poll = -1; | ||
398 | } | ||
399 | mutex_unlock(&instance->poll_state_serialize); | ||
400 | } else if (poll == CXPOLL_STOPPED) { | ||
401 | mutex_lock(&instance->poll_state_serialize); | ||
402 | /* request stop */ | ||
403 | if (instance->poll_state == CXPOLL_POLLING) | ||
404 | instance->poll_state = CXPOLL_STOPPING; | ||
405 | mutex_unlock(&instance->poll_state_serialize); | ||
406 | } | ||
407 | |||
408 | mutex_unlock(&instance->adsl_state_serialize); | ||
409 | |||
410 | if (poll == CXPOLL_POLLING) | ||
411 | cxacru_poll_status(&instance->poll_work.work); | ||
412 | |||
413 | return ret; | ||
414 | } | ||
415 | |||
416 | /* | ||
417 | * All device attributes are included in CXACRU_ALL_FILES | ||
418 | * so that the same list can be used multiple times: | ||
419 | * INIT (define the device attributes) | ||
420 | * CREATE (create all the device files) | ||
421 | * REMOVE (remove all the device files) | ||
422 | * | ||
423 | * With the last two being defined as needed in the functions | ||
424 | * they are used in before calling CXACRU_ALL_FILES() | ||
425 | */ | ||
426 | #define CXACRU_ALL_FILES(_action) \ | ||
427 | CXACRU_ATTR_##_action(CXINF_DOWNSTREAM_RATE, u32, downstream_rate); \ | ||
428 | CXACRU_ATTR_##_action(CXINF_UPSTREAM_RATE, u32, upstream_rate); \ | ||
429 | CXACRU_ATTR_##_action(CXINF_LINK_STATUS, LINK, link_status); \ | ||
430 | CXACRU_ATTR_##_action(CXINF_LINE_STATUS, LINE, line_status); \ | ||
431 | CXACRU__ATTR_##_action( mac_address); \ | ||
432 | CXACRU_ATTR_##_action(CXINF_UPSTREAM_SNR_MARGIN, dB, upstream_snr_margin); \ | ||
433 | CXACRU_ATTR_##_action(CXINF_DOWNSTREAM_SNR_MARGIN, dB, downstream_snr_margin); \ | ||
434 | CXACRU_ATTR_##_action(CXINF_UPSTREAM_ATTENUATION, dB, upstream_attenuation); \ | ||
435 | CXACRU_ATTR_##_action(CXINF_DOWNSTREAM_ATTENUATION, dB, downstream_attenuation); \ | ||
436 | CXACRU_ATTR_##_action(CXINF_TRANSMITTER_POWER, s8, transmitter_power); \ | ||
437 | CXACRU_ATTR_##_action(CXINF_UPSTREAM_BITS_PER_FRAME, u32, upstream_bits_per_frame); \ | ||
438 | CXACRU_ATTR_##_action(CXINF_DOWNSTREAM_BITS_PER_FRAME, u32, downstream_bits_per_frame); \ | ||
439 | CXACRU_ATTR_##_action(CXINF_STARTUP_ATTEMPTS, u32, startup_attempts); \ | ||
440 | CXACRU_ATTR_##_action(CXINF_UPSTREAM_CRC_ERRORS, u32, upstream_crc_errors); \ | ||
441 | CXACRU_ATTR_##_action(CXINF_DOWNSTREAM_CRC_ERRORS, u32, downstream_crc_errors); \ | ||
442 | CXACRU_ATTR_##_action(CXINF_UPSTREAM_FEC_ERRORS, u32, upstream_fec_errors); \ | ||
443 | CXACRU_ATTR_##_action(CXINF_DOWNSTREAM_FEC_ERRORS, u32, downstream_fec_errors); \ | ||
444 | CXACRU_ATTR_##_action(CXINF_UPSTREAM_HEC_ERRORS, u32, upstream_hec_errors); \ | ||
445 | CXACRU_ATTR_##_action(CXINF_DOWNSTREAM_HEC_ERRORS, u32, downstream_hec_errors); \ | ||
446 | CXACRU_ATTR_##_action(CXINF_LINE_STARTABLE, bool, line_startable); \ | ||
447 | CXACRU_ATTR_##_action(CXINF_MODULATION, MODU, modulation); \ | ||
448 | CXACRU_ATTR_##_action(CXINF_ADSL_HEADEND, u32, adsl_headend); \ | ||
449 | CXACRU_ATTR_##_action(CXINF_ADSL_HEADEND_ENVIRONMENT, u32, adsl_headend_environment); \ | ||
450 | CXACRU_ATTR_##_action(CXINF_CONTROLLER_VERSION, u32, adsl_controller_version); \ | ||
451 | CXACRU_CMD_##_action( adsl_state); | ||
452 | |||
453 | CXACRU_ALL_FILES(INIT); | ||
454 | |||
173 | /* the following three functions are stolen from drivers/usb/core/message.c */ | 455 | /* the following three functions are stolen from drivers/usb/core/message.c */ |
174 | static void cxacru_blocking_completion(struct urb *urb) | 456 | static void cxacru_blocking_completion(struct urb *urb) |
175 | { | 457 | { |
@@ -347,8 +629,6 @@ static int cxacru_card_status(struct cxacru_data *instance) | |||
347 | return 0; | 629 | return 0; |
348 | } | 630 | } |
349 | 631 | ||
350 | static void cxacru_poll_status(struct work_struct *work); | ||
351 | |||
352 | static int cxacru_atm_start(struct usbatm_data *usbatm_instance, | 632 | static int cxacru_atm_start(struct usbatm_data *usbatm_instance, |
353 | struct atm_dev *atm_dev) | 633 | struct atm_dev *atm_dev) |
354 | { | 634 | { |
@@ -357,6 +637,7 @@ static int cxacru_atm_start(struct usbatm_data *usbatm_instance, | |||
357 | struct atm_dev *atm_dev = usbatm_instance->atm_dev; | 637 | struct atm_dev *atm_dev = usbatm_instance->atm_dev; |
358 | */ | 638 | */ |
359 | int ret; | 639 | int ret; |
640 | int start_polling = 1; | ||
360 | 641 | ||
361 | dbg("cxacru_atm_start"); | 642 | dbg("cxacru_atm_start"); |
362 | 643 | ||
@@ -369,14 +650,35 @@ static int cxacru_atm_start(struct usbatm_data *usbatm_instance, | |||
369 | } | 650 | } |
370 | 651 | ||
371 | /* start ADSL */ | 652 | /* start ADSL */ |
653 | mutex_lock(&instance->adsl_state_serialize); | ||
372 | ret = cxacru_cm(instance, CM_REQUEST_CHIP_ADSL_LINE_START, NULL, 0, NULL, 0); | 654 | ret = cxacru_cm(instance, CM_REQUEST_CHIP_ADSL_LINE_START, NULL, 0, NULL, 0); |
373 | if (ret < 0) { | 655 | if (ret < 0) { |
374 | atm_err(usbatm_instance, "cxacru_atm_start: CHIP_ADSL_LINE_START returned %d\n", ret); | 656 | atm_err(usbatm_instance, "cxacru_atm_start: CHIP_ADSL_LINE_START returned %d\n", ret); |
657 | mutex_unlock(&instance->adsl_state_serialize); | ||
375 | return ret; | 658 | return ret; |
376 | } | 659 | } |
377 | 660 | ||
378 | /* Start status polling */ | 661 | /* Start status polling */ |
379 | cxacru_poll_status(&instance->poll_work.work); | 662 | mutex_lock(&instance->poll_state_serialize); |
663 | switch (instance->poll_state) { | ||
664 | case CXPOLL_STOPPED: | ||
665 | /* start polling */ | ||
666 | instance->poll_state = CXPOLL_POLLING; | ||
667 | break; | ||
668 | |||
669 | case CXPOLL_STOPPING: | ||
670 | /* abort stop request */ | ||
671 | instance->poll_state = CXPOLL_POLLING; | ||
672 | case CXPOLL_POLLING: | ||
673 | case CXPOLL_SHUTDOWN: | ||
674 | /* don't start polling */ | ||
675 | start_polling = 0; | ||
676 | } | ||
677 | mutex_unlock(&instance->poll_state_serialize); | ||
678 | mutex_unlock(&instance->adsl_state_serialize); | ||
679 | |||
680 | if (start_polling) | ||
681 | cxacru_poll_status(&instance->poll_work.work); | ||
380 | return 0; | 682 | return 0; |
381 | } | 683 | } |
382 | 684 | ||
@@ -387,14 +689,46 @@ static void cxacru_poll_status(struct work_struct *work) | |||
387 | u32 buf[CXINF_MAX] = {}; | 689 | u32 buf[CXINF_MAX] = {}; |
388 | struct usbatm_data *usbatm = instance->usbatm; | 690 | struct usbatm_data *usbatm = instance->usbatm; |
389 | struct atm_dev *atm_dev = usbatm->atm_dev; | 691 | struct atm_dev *atm_dev = usbatm->atm_dev; |
692 | int keep_polling = 1; | ||
390 | int ret; | 693 | int ret; |
391 | 694 | ||
392 | ret = cxacru_cm_get_array(instance, CM_REQUEST_CARD_INFO_GET, buf, CXINF_MAX); | 695 | ret = cxacru_cm_get_array(instance, CM_REQUEST_CARD_INFO_GET, buf, CXINF_MAX); |
393 | if (ret < 0) { | 696 | if (ret < 0) { |
394 | atm_warn(usbatm, "poll status: error %d\n", ret); | 697 | if (ret != -ESHUTDOWN) |
698 | atm_warn(usbatm, "poll status: error %d\n", ret); | ||
699 | |||
700 | mutex_lock(&instance->poll_state_serialize); | ||
701 | if (instance->poll_state != CXPOLL_SHUTDOWN) { | ||
702 | instance->poll_state = CXPOLL_STOPPED; | ||
703 | |||
704 | if (ret != -ESHUTDOWN) | ||
705 | atm_warn(usbatm, "polling disabled, set adsl_state" | ||
706 | " to 'start' or 'poll' to resume\n"); | ||
707 | } | ||
708 | mutex_unlock(&instance->poll_state_serialize); | ||
395 | goto reschedule; | 709 | goto reschedule; |
396 | } | 710 | } |
397 | 711 | ||
712 | memcpy(instance->card_info, buf, sizeof(instance->card_info)); | ||
713 | |||
714 | if (instance->adsl_status != buf[CXINF_LINE_STARTABLE]) { | ||
715 | instance->adsl_status = buf[CXINF_LINE_STARTABLE]; | ||
716 | |||
717 | switch (instance->adsl_status) { | ||
718 | case 0: | ||
719 | atm_printk(KERN_INFO, usbatm, "ADSL state: running\n"); | ||
720 | break; | ||
721 | |||
722 | case 1: | ||
723 | atm_printk(KERN_INFO, usbatm, "ADSL state: stopped\n"); | ||
724 | break; | ||
725 | |||
726 | default: | ||
727 | atm_printk(KERN_INFO, usbatm, "Unknown adsl status %02x\n", instance->adsl_status); | ||
728 | break; | ||
729 | } | ||
730 | } | ||
731 | |||
398 | if (instance->line_status == buf[CXINF_LINE_STATUS]) | 732 | if (instance->line_status == buf[CXINF_LINE_STATUS]) |
399 | goto reschedule; | 733 | goto reschedule; |
400 | 734 | ||
@@ -449,7 +783,20 @@ static void cxacru_poll_status(struct work_struct *work) | |||
449 | break; | 783 | break; |
450 | } | 784 | } |
451 | reschedule: | 785 | reschedule: |
452 | schedule_delayed_work(&instance->poll_work, msecs_to_jiffies(POLL_INTERVAL)); | 786 | |
787 | mutex_lock(&instance->poll_state_serialize); | ||
788 | if (instance->poll_state == CXPOLL_STOPPING && | ||
789 | instance->adsl_status == 1 && /* stopped */ | ||
790 | instance->line_status == 0) /* down */ | ||
791 | instance->poll_state = CXPOLL_STOPPED; | ||
792 | |||
793 | if (instance->poll_state == CXPOLL_STOPPED) | ||
794 | keep_polling = 0; | ||
795 | mutex_unlock(&instance->poll_state_serialize); | ||
796 | |||
797 | if (keep_polling) | ||
798 | schedule_delayed_work(&instance->poll_work, | ||
799 | round_jiffies_relative(POLL_INTERVAL*HZ)); | ||
453 | } | 800 | } |
454 | 801 | ||
455 | static int cxacru_fw(struct usb_device *usb_dev, enum cxacru_fw_request fw, | 802 | static int cxacru_fw(struct usb_device *usb_dev, enum cxacru_fw_request fw, |
@@ -684,6 +1031,14 @@ static int cxacru_bind(struct usbatm_data *usbatm_instance, | |||
684 | 1031 | ||
685 | instance->usbatm = usbatm_instance; | 1032 | instance->usbatm = usbatm_instance; |
686 | instance->modem_type = (struct cxacru_modem_type *) id->driver_info; | 1033 | instance->modem_type = (struct cxacru_modem_type *) id->driver_info; |
1034 | memset(instance->card_info, 0, sizeof(instance->card_info)); | ||
1035 | |||
1036 | mutex_init(&instance->poll_state_serialize); | ||
1037 | instance->poll_state = CXPOLL_STOPPED; | ||
1038 | instance->line_status = -1; | ||
1039 | instance->adsl_status = -1; | ||
1040 | |||
1041 | mutex_init(&instance->adsl_state_serialize); | ||
687 | 1042 | ||
688 | instance->rcv_buf = (u8 *) __get_free_page(GFP_KERNEL); | 1043 | instance->rcv_buf = (u8 *) __get_free_page(GFP_KERNEL); |
689 | if (!instance->rcv_buf) { | 1044 | if (!instance->rcv_buf) { |
@@ -710,6 +1065,13 @@ static int cxacru_bind(struct usbatm_data *usbatm_instance, | |||
710 | goto fail; | 1065 | goto fail; |
711 | } | 1066 | } |
712 | 1067 | ||
1068 | #define CXACRU_DEVICE_CREATE_FILE(_name) \ | ||
1069 | ret = device_create_file(&intf->dev, &dev_attr_##_name); \ | ||
1070 | if (unlikely(ret)) \ | ||
1071 | goto fail_sysfs; | ||
1072 | CXACRU_ALL_FILES(CREATE); | ||
1073 | #undef CXACRU_DEVICE_CREATE_FILE | ||
1074 | |||
713 | usb_fill_int_urb(instance->rcv_urb, | 1075 | usb_fill_int_urb(instance->rcv_urb, |
714 | usb_dev, usb_rcvintpipe(usb_dev, CXACRU_EP_CMD), | 1076 | usb_dev, usb_rcvintpipe(usb_dev, CXACRU_EP_CMD), |
715 | instance->rcv_buf, PAGE_SIZE, | 1077 | instance->rcv_buf, PAGE_SIZE, |
@@ -730,6 +1092,14 @@ static int cxacru_bind(struct usbatm_data *usbatm_instance, | |||
730 | 1092 | ||
731 | return 0; | 1093 | return 0; |
732 | 1094 | ||
1095 | fail_sysfs: | ||
1096 | dbg("cxacru_bind: device_create_file failed (%d)\n", ret); | ||
1097 | |||
1098 | #define CXACRU_DEVICE_REMOVE_FILE(_name) \ | ||
1099 | device_remove_file(&intf->dev, &dev_attr_##_name); | ||
1100 | CXACRU_ALL_FILES(REMOVE); | ||
1101 | #undef CXACRU_DEVICE_REVOVE_FILE | ||
1102 | |||
733 | fail: | 1103 | fail: |
734 | free_page((unsigned long) instance->snd_buf); | 1104 | free_page((unsigned long) instance->snd_buf); |
735 | free_page((unsigned long) instance->rcv_buf); | 1105 | free_page((unsigned long) instance->rcv_buf); |
@@ -744,6 +1114,7 @@ static void cxacru_unbind(struct usbatm_data *usbatm_instance, | |||
744 | struct usb_interface *intf) | 1114 | struct usb_interface *intf) |
745 | { | 1115 | { |
746 | struct cxacru_data *instance = usbatm_instance->driver_data; | 1116 | struct cxacru_data *instance = usbatm_instance->driver_data; |
1117 | int is_polling = 1; | ||
747 | 1118 | ||
748 | dbg("cxacru_unbind entered"); | 1119 | dbg("cxacru_unbind entered"); |
749 | 1120 | ||
@@ -752,8 +1123,20 @@ static void cxacru_unbind(struct usbatm_data *usbatm_instance, | |||
752 | return; | 1123 | return; |
753 | } | 1124 | } |
754 | 1125 | ||
755 | while (!cancel_delayed_work(&instance->poll_work)) | 1126 | mutex_lock(&instance->poll_state_serialize); |
756 | flush_scheduled_work(); | 1127 | BUG_ON(instance->poll_state == CXPOLL_SHUTDOWN); |
1128 | |||
1129 | /* ensure that status polling continues unless | ||
1130 | * it has already stopped */ | ||
1131 | if (instance->poll_state == CXPOLL_STOPPED) | ||
1132 | is_polling = 0; | ||
1133 | |||
1134 | /* stop polling from being stopped or started */ | ||
1135 | instance->poll_state = CXPOLL_SHUTDOWN; | ||
1136 | mutex_unlock(&instance->poll_state_serialize); | ||
1137 | |||
1138 | if (is_polling) | ||
1139 | cancel_rearming_delayed_work(&instance->poll_work); | ||
757 | 1140 | ||
758 | usb_kill_urb(instance->snd_urb); | 1141 | usb_kill_urb(instance->snd_urb); |
759 | usb_kill_urb(instance->rcv_urb); | 1142 | usb_kill_urb(instance->rcv_urb); |
@@ -762,6 +1145,12 @@ static void cxacru_unbind(struct usbatm_data *usbatm_instance, | |||
762 | 1145 | ||
763 | free_page((unsigned long) instance->snd_buf); | 1146 | free_page((unsigned long) instance->snd_buf); |
764 | free_page((unsigned long) instance->rcv_buf); | 1147 | free_page((unsigned long) instance->rcv_buf); |
1148 | |||
1149 | #define CXACRU_DEVICE_REMOVE_FILE(_name) \ | ||
1150 | device_remove_file(&intf->dev, &dev_attr_##_name); | ||
1151 | CXACRU_ALL_FILES(REMOVE); | ||
1152 | #undef CXACRU_DEVICE_REVOVE_FILE | ||
1153 | |||
765 | kfree(instance); | 1154 | kfree(instance); |
766 | 1155 | ||
767 | usbatm_instance->driver_data = NULL; | 1156 | usbatm_instance->driver_data = NULL; |
diff --git a/drivers/usb/atm/ueagle-atm.c b/drivers/usb/atm/ueagle-atm.c index dae4ef1e8fe5..4973e147bc79 100644 --- a/drivers/usb/atm/ueagle-atm.c +++ b/drivers/usb/atm/ueagle-atm.c | |||
@@ -61,6 +61,7 @@ | |||
61 | #include <linux/usb.h> | 61 | #include <linux/usb.h> |
62 | #include <linux/firmware.h> | 62 | #include <linux/firmware.h> |
63 | #include <linux/ctype.h> | 63 | #include <linux/ctype.h> |
64 | #include <linux/sched.h> | ||
64 | #include <linux/kthread.h> | 65 | #include <linux/kthread.h> |
65 | #include <linux/version.h> | 66 | #include <linux/version.h> |
66 | #include <linux/mutex.h> | 67 | #include <linux/mutex.h> |
diff --git a/drivers/usb/atm/usbatm.c b/drivers/usb/atm/usbatm.c index ec63b0ee0743..b3f779f5933a 100644 --- a/drivers/usb/atm/usbatm.c +++ b/drivers/usb/atm/usbatm.c | |||
@@ -274,6 +274,9 @@ static void usbatm_complete(struct urb *urb) | |||
274 | (!(channel->usbatm->flags & UDSL_IGNORE_EILSEQ) || | 274 | (!(channel->usbatm->flags & UDSL_IGNORE_EILSEQ) || |
275 | urb->status != -EILSEQ )) | 275 | urb->status != -EILSEQ )) |
276 | { | 276 | { |
277 | if (urb->status == -ESHUTDOWN) | ||
278 | return; | ||
279 | |||
277 | if (printk_ratelimit()) | 280 | if (printk_ratelimit()) |
278 | atm_warn(channel->usbatm, "%s: urb 0x%p failed (%d)!\n", | 281 | atm_warn(channel->usbatm, "%s: urb 0x%p failed (%d)!\n", |
279 | __func__, urb, urb->status); | 282 | __func__, urb, urb->status); |
@@ -343,7 +346,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char | |||
343 | UDSL_ASSERT(sarb->tail + ATM_CELL_PAYLOAD <= sarb->end); | 346 | UDSL_ASSERT(sarb->tail + ATM_CELL_PAYLOAD <= sarb->end); |
344 | } | 347 | } |
345 | 348 | ||
346 | memcpy(sarb->tail, source + ATM_CELL_HEADER, ATM_CELL_PAYLOAD); | 349 | memcpy(skb_tail_pointer(sarb), source + ATM_CELL_HEADER, ATM_CELL_PAYLOAD); |
347 | __skb_put(sarb, ATM_CELL_PAYLOAD); | 350 | __skb_put(sarb, ATM_CELL_PAYLOAD); |
348 | 351 | ||
349 | if (pti & 1) { | 352 | if (pti & 1) { |
@@ -370,7 +373,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char | |||
370 | goto out; | 373 | goto out; |
371 | } | 374 | } |
372 | 375 | ||
373 | if (crc32_be(~0, sarb->tail - pdu_length, pdu_length) != 0xc704dd7b) { | 376 | if (crc32_be(~0, skb_tail_pointer(sarb) - pdu_length, pdu_length) != 0xc704dd7b) { |
374 | atm_rldbg(instance, "%s: packet failed crc check (vcc: 0x%p)!\n", | 377 | atm_rldbg(instance, "%s: packet failed crc check (vcc: 0x%p)!\n", |
375 | __func__, vcc); | 378 | __func__, vcc); |
376 | atomic_inc(&vcc->stats->rx_err); | 379 | atomic_inc(&vcc->stats->rx_err); |
@@ -396,7 +399,9 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char | |||
396 | goto out; /* atm_charge increments rx_drop */ | 399 | goto out; /* atm_charge increments rx_drop */ |
397 | } | 400 | } |
398 | 401 | ||
399 | memcpy(skb->data, sarb->tail - pdu_length, length); | 402 | skb_copy_to_linear_data(skb, |
403 | skb_tail_pointer(sarb) - pdu_length, | ||
404 | length); | ||
400 | __skb_put(skb, length); | 405 | __skb_put(skb, length); |
401 | 406 | ||
402 | vdbg("%s: sending skb 0x%p, skb->len %u, skb->truesize %u", | 407 | vdbg("%s: sending skb 0x%p, skb->len %u, skb->truesize %u", |
@@ -484,7 +489,7 @@ static unsigned int usbatm_write_cells(struct usbatm_data *instance, | |||
484 | ptr[4] = 0xec; | 489 | ptr[4] = 0xec; |
485 | ptr += ATM_CELL_HEADER; | 490 | ptr += ATM_CELL_HEADER; |
486 | 491 | ||
487 | memcpy(ptr, skb->data, data_len); | 492 | skb_copy_from_linear_data(skb, ptr, data_len); |
488 | ptr += data_len; | 493 | ptr += data_len; |
489 | __skb_pull(skb, data_len); | 494 | __skb_pull(skb, data_len); |
490 | 495 | ||
@@ -966,6 +971,14 @@ static int usbatm_atm_init(struct usbatm_data *instance) | |||
966 | /* temp init ATM device, set to 128kbit */ | 971 | /* temp init ATM device, set to 128kbit */ |
967 | atm_dev->link_rate = 128 * 1000 / 424; | 972 | atm_dev->link_rate = 128 * 1000 / 424; |
968 | 973 | ||
974 | ret = sysfs_create_link(&atm_dev->class_dev.kobj, | ||
975 | &instance->usb_intf->dev.kobj, "device"); | ||
976 | if (ret) { | ||
977 | atm_err(instance, "%s: sysfs_create_link failed: %d\n", | ||
978 | __func__, ret); | ||
979 | goto fail_sysfs; | ||
980 | } | ||
981 | |||
969 | if (instance->driver->atm_start && ((ret = instance->driver->atm_start(instance, atm_dev)) < 0)) { | 982 | if (instance->driver->atm_start && ((ret = instance->driver->atm_start(instance, atm_dev)) < 0)) { |
970 | atm_err(instance, "%s: atm_start failed: %d!\n", __func__, ret); | 983 | atm_err(instance, "%s: atm_start failed: %d!\n", __func__, ret); |
971 | goto fail; | 984 | goto fail; |
@@ -984,6 +997,8 @@ static int usbatm_atm_init(struct usbatm_data *instance) | |||
984 | return 0; | 997 | return 0; |
985 | 998 | ||
986 | fail: | 999 | fail: |
1000 | sysfs_remove_link(&atm_dev->class_dev.kobj, "device"); | ||
1001 | fail_sysfs: | ||
987 | instance->atm_dev = NULL; | 1002 | instance->atm_dev = NULL; |
988 | atm_dev_deregister(atm_dev); /* usbatm_atm_dev_close will eventually be called */ | 1003 | atm_dev_deregister(atm_dev); /* usbatm_atm_dev_close will eventually be called */ |
989 | return ret; | 1004 | return ret; |
@@ -1316,8 +1331,10 @@ void usbatm_usb_disconnect(struct usb_interface *intf) | |||
1316 | kfree(instance->cell_buf); | 1331 | kfree(instance->cell_buf); |
1317 | 1332 | ||
1318 | /* ATM finalize */ | 1333 | /* ATM finalize */ |
1319 | if (instance->atm_dev) | 1334 | if (instance->atm_dev) { |
1335 | sysfs_remove_link(&instance->atm_dev->class_dev.kobj, "device"); | ||
1320 | atm_dev_deregister(instance->atm_dev); | 1336 | atm_dev_deregister(instance->atm_dev); |
1337 | } | ||
1321 | 1338 | ||
1322 | usbatm_put_instance(instance); /* taken in usbatm_usb_probe */ | 1339 | usbatm_put_instance(instance); /* taken in usbatm_usb_probe */ |
1323 | } | 1340 | } |
diff --git a/drivers/usb/class/cdc-acm.c b/drivers/usb/class/cdc-acm.c index 98199628e394..14de3b1b6a20 100644 --- a/drivers/usb/class/cdc-acm.c +++ b/drivers/usb/class/cdc-acm.c | |||
@@ -212,7 +212,41 @@ static int acm_write_start(struct acm *acm) | |||
212 | } | 212 | } |
213 | return rc; | 213 | return rc; |
214 | } | 214 | } |
215 | /* | ||
216 | * attributes exported through sysfs | ||
217 | */ | ||
218 | static ssize_t show_caps | ||
219 | (struct device *dev, struct device_attribute *attr, char *buf) | ||
220 | { | ||
221 | struct usb_interface *intf = to_usb_interface(dev); | ||
222 | struct acm *acm = usb_get_intfdata(intf); | ||
223 | |||
224 | return sprintf(buf, "%d", acm->ctrl_caps); | ||
225 | } | ||
226 | static DEVICE_ATTR(bmCapabilities, S_IRUGO, show_caps, NULL); | ||
227 | |||
228 | static ssize_t show_country_codes | ||
229 | (struct device *dev, struct device_attribute *attr, char *buf) | ||
230 | { | ||
231 | struct usb_interface *intf = to_usb_interface(dev); | ||
232 | struct acm *acm = usb_get_intfdata(intf); | ||
233 | |||
234 | memcpy(buf, acm->country_codes, acm->country_code_size); | ||
235 | return acm->country_code_size; | ||
236 | } | ||
215 | 237 | ||
238 | static DEVICE_ATTR(wCountryCodes, S_IRUGO, show_country_codes, NULL); | ||
239 | |||
240 | static ssize_t show_country_rel_date | ||
241 | (struct device *dev, struct device_attribute *attr, char *buf) | ||
242 | { | ||
243 | struct usb_interface *intf = to_usb_interface(dev); | ||
244 | struct acm *acm = usb_get_intfdata(intf); | ||
245 | |||
246 | return sprintf(buf, "%d", acm->country_rel_date); | ||
247 | } | ||
248 | |||
249 | static DEVICE_ATTR(iCountryCodeRelDate, S_IRUGO, show_country_rel_date, NULL); | ||
216 | /* | 250 | /* |
217 | * Interrupt handlers for various ACM device responses | 251 | * Interrupt handlers for various ACM device responses |
218 | */ | 252 | */ |
@@ -326,10 +360,16 @@ static void acm_rx_tasklet(unsigned long _acm) | |||
326 | struct tty_struct *tty = acm->tty; | 360 | struct tty_struct *tty = acm->tty; |
327 | struct acm_ru *rcv; | 361 | struct acm_ru *rcv; |
328 | unsigned long flags; | 362 | unsigned long flags; |
329 | int i = 0; | 363 | unsigned char throttled; |
330 | dbg("Entering acm_rx_tasklet"); | 364 | dbg("Entering acm_rx_tasklet"); |
331 | 365 | ||
332 | if (!ACM_READY(acm) || acm->throttle) | 366 | if (!ACM_READY(acm)) |
367 | return; | ||
368 | |||
369 | spin_lock_irqsave(&acm->throttle_lock, flags); | ||
370 | throttled = acm->throttle; | ||
371 | spin_unlock_irqrestore(&acm->throttle_lock, flags); | ||
372 | if (throttled) | ||
333 | return; | 373 | return; |
334 | 374 | ||
335 | next_buffer: | 375 | next_buffer: |
@@ -346,22 +386,20 @@ next_buffer: | |||
346 | dbg("acm_rx_tasklet: procesing buf 0x%p, size = %d", buf, buf->size); | 386 | dbg("acm_rx_tasklet: procesing buf 0x%p, size = %d", buf, buf->size); |
347 | 387 | ||
348 | tty_buffer_request_room(tty, buf->size); | 388 | tty_buffer_request_room(tty, buf->size); |
349 | if (!acm->throttle) | 389 | spin_lock_irqsave(&acm->throttle_lock, flags); |
390 | throttled = acm->throttle; | ||
391 | spin_unlock_irqrestore(&acm->throttle_lock, flags); | ||
392 | if (!throttled) | ||
350 | tty_insert_flip_string(tty, buf->base, buf->size); | 393 | tty_insert_flip_string(tty, buf->base, buf->size); |
351 | tty_flip_buffer_push(tty); | 394 | tty_flip_buffer_push(tty); |
352 | 395 | ||
353 | spin_lock(&acm->throttle_lock); | 396 | if (throttled) { |
354 | if (acm->throttle) { | 397 | dbg("Throttling noticed"); |
355 | dbg("Throtteling noticed"); | ||
356 | memmove(buf->base, buf->base + i, buf->size - i); | ||
357 | buf->size -= i; | ||
358 | spin_unlock(&acm->throttle_lock); | ||
359 | spin_lock_irqsave(&acm->read_lock, flags); | 398 | spin_lock_irqsave(&acm->read_lock, flags); |
360 | list_add(&buf->list, &acm->filled_read_bufs); | 399 | list_add(&buf->list, &acm->filled_read_bufs); |
361 | spin_unlock_irqrestore(&acm->read_lock, flags); | 400 | spin_unlock_irqrestore(&acm->read_lock, flags); |
362 | return; | 401 | return; |
363 | } | 402 | } |
364 | spin_unlock(&acm->throttle_lock); | ||
365 | 403 | ||
366 | spin_lock_irqsave(&acm->read_lock, flags); | 404 | spin_lock_irqsave(&acm->read_lock, flags); |
367 | list_add(&buf->list, &acm->spare_read_bufs); | 405 | list_add(&buf->list, &acm->spare_read_bufs); |
@@ -467,7 +505,8 @@ static int acm_tty_open(struct tty_struct *tty, struct file *filp) | |||
467 | goto bail_out; | 505 | goto bail_out; |
468 | } | 506 | } |
469 | 507 | ||
470 | if (0 > acm_set_control(acm, acm->ctrlout = ACM_CTRL_DTR | ACM_CTRL_RTS)) | 508 | if (0 > acm_set_control(acm, acm->ctrlout = ACM_CTRL_DTR | ACM_CTRL_RTS) && |
509 | (acm->ctrl_caps & USB_CDC_CAP_LINE)) | ||
471 | goto full_bailout; | 510 | goto full_bailout; |
472 | 511 | ||
473 | INIT_LIST_HEAD(&acm->spare_read_urbs); | 512 | INIT_LIST_HEAD(&acm->spare_read_urbs); |
@@ -480,6 +519,8 @@ static int acm_tty_open(struct tty_struct *tty, struct file *filp) | |||
480 | list_add(&(acm->rb[i].list), &acm->spare_read_bufs); | 519 | list_add(&(acm->rb[i].list), &acm->spare_read_bufs); |
481 | } | 520 | } |
482 | 521 | ||
522 | acm->throttle = 0; | ||
523 | |||
483 | tasklet_schedule(&acm->urb_task); | 524 | tasklet_schedule(&acm->urb_task); |
484 | 525 | ||
485 | done: | 526 | done: |
@@ -507,6 +548,7 @@ static void acm_tty_unregister(struct acm *acm) | |||
507 | usb_free_urb(acm->writeurb); | 548 | usb_free_urb(acm->writeurb); |
508 | for (i = 0; i < nr; i++) | 549 | for (i = 0; i < nr; i++) |
509 | usb_free_urb(acm->ru[i].urb); | 550 | usb_free_urb(acm->ru[i].urb); |
551 | kfree(acm->country_codes); | ||
510 | kfree(acm); | 552 | kfree(acm); |
511 | } | 553 | } |
512 | 554 | ||
@@ -754,6 +796,7 @@ static int acm_probe (struct usb_interface *intf, | |||
754 | const struct usb_device_id *id) | 796 | const struct usb_device_id *id) |
755 | { | 797 | { |
756 | struct usb_cdc_union_desc *union_header = NULL; | 798 | struct usb_cdc_union_desc *union_header = NULL; |
799 | struct usb_cdc_country_functional_desc *cfd = NULL; | ||
757 | char *buffer = intf->altsetting->extra; | 800 | char *buffer = intf->altsetting->extra; |
758 | int buflen = intf->altsetting->extralen; | 801 | int buflen = intf->altsetting->extralen; |
759 | struct usb_interface *control_interface; | 802 | struct usb_interface *control_interface; |
@@ -817,8 +860,9 @@ static int acm_probe (struct usb_interface *intf, | |||
817 | union_header = (struct usb_cdc_union_desc *) | 860 | union_header = (struct usb_cdc_union_desc *) |
818 | buffer; | 861 | buffer; |
819 | break; | 862 | break; |
820 | case USB_CDC_COUNTRY_TYPE: /* maybe somehow export */ | 863 | case USB_CDC_COUNTRY_TYPE: /* export through sysfs*/ |
821 | break; /* for now we ignore it */ | 864 | cfd = (struct usb_cdc_country_functional_desc *)buffer; |
865 | break; | ||
822 | case USB_CDC_HEADER_TYPE: /* maybe check version */ | 866 | case USB_CDC_HEADER_TYPE: /* maybe check version */ |
823 | break; /* for now we ignore it */ | 867 | break; /* for now we ignore it */ |
824 | case USB_CDC_ACM_TYPE: | 868 | case USB_CDC_ACM_TYPE: |
@@ -976,6 +1020,34 @@ skip_normal_probe: | |||
976 | goto alloc_fail7; | 1020 | goto alloc_fail7; |
977 | } | 1021 | } |
978 | 1022 | ||
1023 | usb_set_intfdata (intf, acm); | ||
1024 | |||
1025 | i = device_create_file(&intf->dev, &dev_attr_bmCapabilities); | ||
1026 | if (i < 0) | ||
1027 | goto alloc_fail8; | ||
1028 | |||
1029 | if (cfd) { /* export the country data */ | ||
1030 | acm->country_codes = kmalloc(cfd->bLength - 4, GFP_KERNEL); | ||
1031 | if (!acm->country_codes) | ||
1032 | goto skip_countries; | ||
1033 | acm->country_code_size = cfd->bLength - 4; | ||
1034 | memcpy(acm->country_codes, (u8 *)&cfd->wCountyCode0, cfd->bLength - 4); | ||
1035 | acm->country_rel_date = cfd->iCountryCodeRelDate; | ||
1036 | |||
1037 | i = device_create_file(&intf->dev, &dev_attr_wCountryCodes); | ||
1038 | if (i < 0) { | ||
1039 | kfree(acm->country_codes); | ||
1040 | goto skip_countries; | ||
1041 | } | ||
1042 | |||
1043 | i = device_create_file(&intf->dev, &dev_attr_iCountryCodeRelDate); | ||
1044 | if (i < 0) { | ||
1045 | kfree(acm->country_codes); | ||
1046 | goto skip_countries; | ||
1047 | } | ||
1048 | } | ||
1049 | |||
1050 | skip_countries: | ||
979 | usb_fill_int_urb(acm->ctrlurb, usb_dev, usb_rcvintpipe(usb_dev, epctrl->bEndpointAddress), | 1051 | usb_fill_int_urb(acm->ctrlurb, usb_dev, usb_rcvintpipe(usb_dev, epctrl->bEndpointAddress), |
980 | acm->ctrl_buffer, ctrlsize, acm_ctrl_irq, acm, epctrl->bInterval); | 1052 | acm->ctrl_buffer, ctrlsize, acm_ctrl_irq, acm, epctrl->bInterval); |
981 | acm->ctrlurb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; | 1053 | acm->ctrlurb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; |
@@ -999,9 +1071,10 @@ skip_normal_probe: | |||
999 | tty_register_device(acm_tty_driver, minor, &control_interface->dev); | 1071 | tty_register_device(acm_tty_driver, minor, &control_interface->dev); |
1000 | 1072 | ||
1001 | acm_table[minor] = acm; | 1073 | acm_table[minor] = acm; |
1002 | usb_set_intfdata (intf, acm); | ||
1003 | return 0; | ||
1004 | 1074 | ||
1075 | return 0; | ||
1076 | alloc_fail8: | ||
1077 | usb_free_urb(acm->writeurb); | ||
1005 | alloc_fail7: | 1078 | alloc_fail7: |
1006 | for (i = 0; i < num_rx_buf; i++) | 1079 | for (i = 0; i < num_rx_buf; i++) |
1007 | usb_buffer_free(usb_dev, acm->readsize, acm->rb[i].base, acm->rb[i].dma); | 1080 | usb_buffer_free(usb_dev, acm->readsize, acm->rb[i].base, acm->rb[i].dma); |
@@ -1020,7 +1093,7 @@ alloc_fail: | |||
1020 | 1093 | ||
1021 | static void acm_disconnect(struct usb_interface *intf) | 1094 | static void acm_disconnect(struct usb_interface *intf) |
1022 | { | 1095 | { |
1023 | struct acm *acm = usb_get_intfdata (intf); | 1096 | struct acm *acm = usb_get_intfdata(intf); |
1024 | struct usb_device *usb_dev = interface_to_usbdev(intf); | 1097 | struct usb_device *usb_dev = interface_to_usbdev(intf); |
1025 | int i; | 1098 | int i; |
1026 | 1099 | ||
@@ -1034,6 +1107,11 @@ static void acm_disconnect(struct usb_interface *intf) | |||
1034 | mutex_unlock(&open_mutex); | 1107 | mutex_unlock(&open_mutex); |
1035 | return; | 1108 | return; |
1036 | } | 1109 | } |
1110 | if (acm->country_codes){ | ||
1111 | device_remove_file(&intf->dev, &dev_attr_wCountryCodes); | ||
1112 | device_remove_file(&intf->dev, &dev_attr_iCountryCodeRelDate); | ||
1113 | } | ||
1114 | device_remove_file(&intf->dev, &dev_attr_bmCapabilities); | ||
1037 | acm->dev = NULL; | 1115 | acm->dev = NULL; |
1038 | usb_set_intfdata(acm->control, NULL); | 1116 | usb_set_intfdata(acm->control, NULL); |
1039 | usb_set_intfdata(acm->data, NULL); | 1117 | usb_set_intfdata(acm->data, NULL); |
@@ -1092,6 +1170,10 @@ static struct usb_device_id acm_ids[] = { | |||
1092 | { USB_DEVICE(0x0ace, 0x1611), /* ZyDAS 56K USB MODEM - new version */ | 1170 | { USB_DEVICE(0x0ace, 0x1611), /* ZyDAS 56K USB MODEM - new version */ |
1093 | .driver_info = SINGLE_RX_URB, /* firmware bug */ | 1171 | .driver_info = SINGLE_RX_URB, /* firmware bug */ |
1094 | }, | 1172 | }, |
1173 | { USB_DEVICE(0x22b8, 0x7000), /* Motorola Q Phone */ | ||
1174 | .driver_info = NO_UNION_NORMAL, /* has no union descriptor */ | ||
1175 | }, | ||
1176 | |||
1095 | /* control interfaces with various AT-command sets */ | 1177 | /* control interfaces with various AT-command sets */ |
1096 | { USB_INTERFACE_INFO(USB_CLASS_COMM, USB_CDC_SUBCLASS_ACM, | 1178 | { USB_INTERFACE_INFO(USB_CLASS_COMM, USB_CDC_SUBCLASS_ACM, |
1097 | USB_CDC_ACM_PROTO_AT_V25TER) }, | 1179 | USB_CDC_ACM_PROTO_AT_V25TER) }, |
diff --git a/drivers/usb/class/cdc-acm.h b/drivers/usb/class/cdc-acm.h index 1bcaea32cfc1..09f7765dbf8d 100644 --- a/drivers/usb/class/cdc-acm.h +++ b/drivers/usb/class/cdc-acm.h | |||
@@ -91,6 +91,9 @@ struct acm { | |||
91 | struct urb *ctrlurb, *writeurb; /* urbs */ | 91 | struct urb *ctrlurb, *writeurb; /* urbs */ |
92 | u8 *ctrl_buffer; /* buffers of urbs */ | 92 | u8 *ctrl_buffer; /* buffers of urbs */ |
93 | dma_addr_t ctrl_dma; /* dma handles of buffers */ | 93 | dma_addr_t ctrl_dma; /* dma handles of buffers */ |
94 | u8 *country_codes; /* country codes from device */ | ||
95 | unsigned int country_code_size; /* size of this buffer */ | ||
96 | unsigned int country_rel_date; /* release date of version */ | ||
94 | struct acm_wb wb[ACM_NW]; | 97 | struct acm_wb wb[ACM_NW]; |
95 | struct acm_ru ru[ACM_NR]; | 98 | struct acm_ru ru[ACM_NR]; |
96 | struct acm_rb rb[ACM_NR]; | 99 | struct acm_rb rb[ACM_NR]; |
diff --git a/drivers/usb/class/usblp.c b/drivers/usb/class/usblp.c index 63e50a1f1396..6584cf00f7f3 100644 --- a/drivers/usb/class/usblp.c +++ b/drivers/usb/class/usblp.c | |||
@@ -202,6 +202,7 @@ struct quirk_printer_struct { | |||
202 | 202 | ||
203 | #define USBLP_QUIRK_BIDIR 0x1 /* reports bidir but requires unidirectional mode (no INs/reads) */ | 203 | #define USBLP_QUIRK_BIDIR 0x1 /* reports bidir but requires unidirectional mode (no INs/reads) */ |
204 | #define USBLP_QUIRK_USB_INIT 0x2 /* needs vendor USB init string */ | 204 | #define USBLP_QUIRK_USB_INIT 0x2 /* needs vendor USB init string */ |
205 | #define USBLP_QUIRK_BAD_CLASS 0x4 /* descriptor uses vendor-specific Class or SubClass */ | ||
205 | 206 | ||
206 | static const struct quirk_printer_struct quirk_printers[] = { | 207 | static const struct quirk_printer_struct quirk_printers[] = { |
207 | { 0x03f0, 0x0004, USBLP_QUIRK_BIDIR }, /* HP DeskJet 895C */ | 208 | { 0x03f0, 0x0004, USBLP_QUIRK_BIDIR }, /* HP DeskJet 895C */ |
@@ -218,6 +219,7 @@ static const struct quirk_printer_struct quirk_printers[] = { | |||
218 | { 0x0409, 0xf0be, USBLP_QUIRK_BIDIR }, /* NEC Picty920 (HP OEM) */ | 219 | { 0x0409, 0xf0be, USBLP_QUIRK_BIDIR }, /* NEC Picty920 (HP OEM) */ |
219 | { 0x0409, 0xf1be, USBLP_QUIRK_BIDIR }, /* NEC Picty800 (HP OEM) */ | 220 | { 0x0409, 0xf1be, USBLP_QUIRK_BIDIR }, /* NEC Picty800 (HP OEM) */ |
220 | { 0x0482, 0x0010, USBLP_QUIRK_BIDIR }, /* Kyocera Mita FS 820, by zut <kernel@zut.de> */ | 221 | { 0x0482, 0x0010, USBLP_QUIRK_BIDIR }, /* Kyocera Mita FS 820, by zut <kernel@zut.de> */ |
222 | { 0x04b8, 0x0202, USBLP_QUIRK_BAD_CLASS }, /* Seiko Epson Receipt Printer M129C */ | ||
221 | { 0, 0 } | 223 | { 0, 0 } |
222 | }; | 224 | }; |
223 | 225 | ||
@@ -1048,7 +1050,8 @@ static int usblp_select_alts(struct usblp *usblp) | |||
1048 | ifd = &if_alt->altsetting[i]; | 1050 | ifd = &if_alt->altsetting[i]; |
1049 | 1051 | ||
1050 | if (ifd->desc.bInterfaceClass != 7 || ifd->desc.bInterfaceSubClass != 1) | 1052 | if (ifd->desc.bInterfaceClass != 7 || ifd->desc.bInterfaceSubClass != 1) |
1051 | continue; | 1053 | if (!(usblp->quirks & USBLP_QUIRK_BAD_CLASS)) |
1054 | continue; | ||
1052 | 1055 | ||
1053 | if (ifd->desc.bInterfaceProtocol < USBLP_FIRST_PROTOCOL || | 1056 | if (ifd->desc.bInterfaceProtocol < USBLP_FIRST_PROTOCOL || |
1054 | ifd->desc.bInterfaceProtocol > USBLP_LAST_PROTOCOL) | 1057 | ifd->desc.bInterfaceProtocol > USBLP_LAST_PROTOCOL) |
@@ -1232,6 +1235,7 @@ static struct usb_device_id usblp_ids [] = { | |||
1232 | { USB_INTERFACE_INFO(7, 1, 1) }, | 1235 | { USB_INTERFACE_INFO(7, 1, 1) }, |
1233 | { USB_INTERFACE_INFO(7, 1, 2) }, | 1236 | { USB_INTERFACE_INFO(7, 1, 2) }, |
1234 | { USB_INTERFACE_INFO(7, 1, 3) }, | 1237 | { USB_INTERFACE_INFO(7, 1, 3) }, |
1238 | { USB_DEVICE(0x04b8, 0x0202) }, /* Seiko Epson Receipt Printer M129C */ | ||
1235 | { } /* Terminating entry */ | 1239 | { } /* Terminating entry */ |
1236 | }; | 1240 | }; |
1237 | 1241 | ||
diff --git a/drivers/usb/core/Kconfig b/drivers/usb/core/Kconfig index 2fc0f88a3d86..f493fb1eaa27 100644 --- a/drivers/usb/core/Kconfig +++ b/drivers/usb/core/Kconfig | |||
@@ -31,7 +31,30 @@ config USB_DEVICEFS | |||
31 | For the format of the various /proc/bus/usb/ files, please read | 31 | For the format of the various /proc/bus/usb/ files, please read |
32 | <file:Documentation/usb/proc_usb_info.txt>. | 32 | <file:Documentation/usb/proc_usb_info.txt>. |
33 | 33 | ||
34 | Most users want to say Y here. | 34 | Usbfs files can't handle Access Control Lists (ACL), which are the |
35 | default way to grant access to USB devices for untrusted users of a | ||
36 | desktop system. The usbfs functionality is replaced by real | ||
37 | device-nodes managed by udev. These nodes live in /dev/bus/usb and | ||
38 | are used by libusb. | ||
39 | |||
40 | config USB_DEVICE_CLASS | ||
41 | bool "USB device class-devices (DEPRECATED)" | ||
42 | depends on USB | ||
43 | default n | ||
44 | ---help--- | ||
45 | Userspace access to USB devices is granted by device-nodes exported | ||
46 | directly from the usbdev in sysfs. Old versions of the driver | ||
47 | core and udev needed additional class devices to export device nodes. | ||
48 | |||
49 | These additional devices are difficult to handle in userspace, if | ||
50 | information about USB interfaces must be available. One device contains | ||
51 | the device node, the other device contains the interface data. Both | ||
52 | devices are at the same level in sysfs (siblings) and one can't access | ||
53 | the other. The device node created directly by the usbdev is the parent | ||
54 | device of the interface and therefore easily accessible from the interface | ||
55 | event. | ||
56 | |||
57 | This option provides backward compatibility if needed. | ||
35 | 58 | ||
36 | config USB_DYNAMIC_MINORS | 59 | config USB_DYNAMIC_MINORS |
37 | bool "Dynamic USB minor allocation (EXPERIMENTAL)" | 60 | bool "Dynamic USB minor allocation (EXPERIMENTAL)" |
diff --git a/drivers/usb/core/Makefile b/drivers/usb/core/Makefile index 34e9bac319b4..b6078706fb93 100644 --- a/drivers/usb/core/Makefile +++ b/drivers/usb/core/Makefile | |||
@@ -4,7 +4,7 @@ | |||
4 | 4 | ||
5 | usbcore-objs := usb.o hub.o hcd.o urb.o message.o driver.o \ | 5 | usbcore-objs := usb.o hub.o hcd.o urb.o message.o driver.o \ |
6 | config.o file.o buffer.o sysfs.o endpoint.o \ | 6 | config.o file.o buffer.o sysfs.o endpoint.o \ |
7 | devio.o notify.o generic.o | 7 | devio.o notify.o generic.o quirks.o |
8 | 8 | ||
9 | ifeq ($(CONFIG_PCI),y) | 9 | ifeq ($(CONFIG_PCI),y) |
10 | usbcore-objs += hcd-pci.o | 10 | usbcore-objs += hcd-pci.o |
diff --git a/drivers/usb/core/devices.c b/drivers/usb/core/devices.c index a47c30b2d764..6753ca059ee4 100644 --- a/drivers/usb/core/devices.c +++ b/drivers/usb/core/devices.c | |||
@@ -246,7 +246,6 @@ static char *usb_dump_interface_descriptor(char *start, char *end, | |||
246 | 246 | ||
247 | if (start > end) | 247 | if (start > end) |
248 | return start; | 248 | return start; |
249 | down_read(&usb_bus_type.subsys.rwsem); | ||
250 | if (iface) { | 249 | if (iface) { |
251 | driver_name = (iface->dev.driver | 250 | driver_name = (iface->dev.driver |
252 | ? iface->dev.driver->name | 251 | ? iface->dev.driver->name |
@@ -263,7 +262,6 @@ static char *usb_dump_interface_descriptor(char *start, char *end, | |||
263 | desc->bInterfaceSubClass, | 262 | desc->bInterfaceSubClass, |
264 | desc->bInterfaceProtocol, | 263 | desc->bInterfaceProtocol, |
265 | driver_name); | 264 | driver_name); |
266 | up_read(&usb_bus_type.subsys.rwsem); | ||
267 | return start; | 265 | return start; |
268 | } | 266 | } |
269 | 267 | ||
@@ -604,10 +602,6 @@ static unsigned int usb_device_poll(struct file *file, struct poll_table_struct | |||
604 | lock_kernel(); | 602 | lock_kernel(); |
605 | if (!st) { | 603 | if (!st) { |
606 | st = kmalloc(sizeof(struct usb_device_status), GFP_KERNEL); | 604 | st = kmalloc(sizeof(struct usb_device_status), GFP_KERNEL); |
607 | if (!st) { | ||
608 | unlock_kernel(); | ||
609 | return POLLIN; | ||
610 | } | ||
611 | 605 | ||
612 | /* we may have dropped BKL - need to check for having lost the race */ | 606 | /* we may have dropped BKL - need to check for having lost the race */ |
613 | if (file->private_data) { | 607 | if (file->private_data) { |
@@ -615,6 +609,11 @@ static unsigned int usb_device_poll(struct file *file, struct poll_table_struct | |||
615 | st = file->private_data; | 609 | st = file->private_data; |
616 | goto lost_race; | 610 | goto lost_race; |
617 | } | 611 | } |
612 | /* we haven't lost - check for allocation failure now */ | ||
613 | if (!st) { | ||
614 | unlock_kernel(); | ||
615 | return POLLIN; | ||
616 | } | ||
618 | 617 | ||
619 | /* | 618 | /* |
620 | * need to prevent the module from being unloaded, since | 619 | * need to prevent the module from being unloaded, since |
diff --git a/drivers/usb/core/devio.c b/drivers/usb/core/devio.c index 2087766f9e88..927a181120a9 100644 --- a/drivers/usb/core/devio.c +++ b/drivers/usb/core/devio.c | |||
@@ -57,7 +57,6 @@ | |||
57 | 57 | ||
58 | #define USB_MAXBUS 64 | 58 | #define USB_MAXBUS 64 |
59 | #define USB_DEVICE_MAX USB_MAXBUS * 128 | 59 | #define USB_DEVICE_MAX USB_MAXBUS * 128 |
60 | static struct class *usb_device_class; | ||
61 | 60 | ||
62 | /* Mutual exclusion for removal, open, and release */ | 61 | /* Mutual exclusion for removal, open, and release */ |
63 | DEFINE_MUTEX(usbfs_mutex); | 62 | DEFINE_MUTEX(usbfs_mutex); |
@@ -421,14 +420,11 @@ static int claimintf(struct dev_state *ps, unsigned int ifnum) | |||
421 | if (test_bit(ifnum, &ps->ifclaimed)) | 420 | if (test_bit(ifnum, &ps->ifclaimed)) |
422 | return 0; | 421 | return 0; |
423 | 422 | ||
424 | /* lock against other changes to driver bindings */ | ||
425 | down_write(&usb_bus_type.subsys.rwsem); | ||
426 | intf = usb_ifnum_to_if(dev, ifnum); | 423 | intf = usb_ifnum_to_if(dev, ifnum); |
427 | if (!intf) | 424 | if (!intf) |
428 | err = -ENOENT; | 425 | err = -ENOENT; |
429 | else | 426 | else |
430 | err = usb_driver_claim_interface(&usbfs_driver, intf, ps); | 427 | err = usb_driver_claim_interface(&usbfs_driver, intf, ps); |
431 | up_write(&usb_bus_type.subsys.rwsem); | ||
432 | if (err == 0) | 428 | if (err == 0) |
433 | set_bit(ifnum, &ps->ifclaimed); | 429 | set_bit(ifnum, &ps->ifclaimed); |
434 | return err; | 430 | return err; |
@@ -444,8 +440,6 @@ static int releaseintf(struct dev_state *ps, unsigned int ifnum) | |||
444 | if (ifnum >= 8*sizeof(ps->ifclaimed)) | 440 | if (ifnum >= 8*sizeof(ps->ifclaimed)) |
445 | return err; | 441 | return err; |
446 | dev = ps->dev; | 442 | dev = ps->dev; |
447 | /* lock against other changes to driver bindings */ | ||
448 | down_write(&usb_bus_type.subsys.rwsem); | ||
449 | intf = usb_ifnum_to_if(dev, ifnum); | 443 | intf = usb_ifnum_to_if(dev, ifnum); |
450 | if (!intf) | 444 | if (!intf) |
451 | err = -ENOENT; | 445 | err = -ENOENT; |
@@ -453,7 +447,6 @@ static int releaseintf(struct dev_state *ps, unsigned int ifnum) | |||
453 | usb_driver_release_interface(&usbfs_driver, intf); | 447 | usb_driver_release_interface(&usbfs_driver, intf); |
454 | err = 0; | 448 | err = 0; |
455 | } | 449 | } |
456 | up_write(&usb_bus_type.subsys.rwsem); | ||
457 | return err; | 450 | return err; |
458 | } | 451 | } |
459 | 452 | ||
@@ -520,22 +513,25 @@ static int check_ctrlrecip(struct dev_state *ps, unsigned int requesttype, unsig | |||
520 | return ret; | 513 | return ret; |
521 | } | 514 | } |
522 | 515 | ||
523 | static struct usb_device *usbdev_lookup_minor(int minor) | 516 | static int __match_minor(struct device *dev, void *data) |
524 | { | 517 | { |
525 | struct device *device; | 518 | int minor = *((int *)data); |
526 | struct usb_device *udev = NULL; | ||
527 | 519 | ||
528 | down(&usb_device_class->sem); | 520 | if (dev->devt == MKDEV(USB_DEVICE_MAJOR, minor)) |
529 | list_for_each_entry(device, &usb_device_class->devices, node) { | 521 | return 1; |
530 | if (device->devt == MKDEV(USB_DEVICE_MAJOR, minor)) { | 522 | return 0; |
531 | udev = device->platform_data; | 523 | } |
532 | break; | ||
533 | } | ||
534 | } | ||
535 | up(&usb_device_class->sem); | ||
536 | 524 | ||
537 | return udev; | 525 | static struct usb_device *usbdev_lookup_by_minor(int minor) |
538 | }; | 526 | { |
527 | struct device *dev; | ||
528 | |||
529 | dev = bus_find_device(&usb_bus_type, NULL, &minor, __match_minor); | ||
530 | if (!dev) | ||
531 | return NULL; | ||
532 | put_device(dev); | ||
533 | return container_of(dev, struct usb_device, dev); | ||
534 | } | ||
539 | 535 | ||
540 | /* | 536 | /* |
541 | * file operations | 537 | * file operations |
@@ -554,11 +550,14 @@ static int usbdev_open(struct inode *inode, struct file *file) | |||
554 | goto out; | 550 | goto out; |
555 | 551 | ||
556 | ret = -ENOENT; | 552 | ret = -ENOENT; |
557 | /* check if we are called from a real node or usbfs */ | 553 | /* usbdev device-node */ |
558 | if (imajor(inode) == USB_DEVICE_MAJOR) | 554 | if (imajor(inode) == USB_DEVICE_MAJOR) |
559 | dev = usbdev_lookup_minor(iminor(inode)); | 555 | dev = usbdev_lookup_by_minor(iminor(inode)); |
556 | #ifdef CONFIG_USB_DEVICEFS | ||
557 | /* procfs file */ | ||
560 | if (!dev) | 558 | if (!dev) |
561 | dev = inode->i_private; | 559 | dev = inode->i_private; |
560 | #endif | ||
562 | if (!dev) | 561 | if (!dev) |
563 | goto out; | 562 | goto out; |
564 | ret = usb_autoresume_device(dev); | 563 | ret = usb_autoresume_device(dev); |
@@ -581,7 +580,7 @@ static int usbdev_open(struct inode *inode, struct file *file) | |||
581 | ps->disccontext = NULL; | 580 | ps->disccontext = NULL; |
582 | ps->ifclaimed = 0; | 581 | ps->ifclaimed = 0; |
583 | security_task_getsecid(current, &ps->secid); | 582 | security_task_getsecid(current, &ps->secid); |
584 | wmb(); | 583 | smp_wmb(); |
585 | list_add_tail(&ps->list, &dev->filelist); | 584 | list_add_tail(&ps->list, &dev->filelist); |
586 | file->private_data = ps; | 585 | file->private_data = ps; |
587 | out: | 586 | out: |
@@ -813,7 +812,6 @@ static int proc_getdriver(struct dev_state *ps, void __user *arg) | |||
813 | 812 | ||
814 | if (copy_from_user(&gd, arg, sizeof(gd))) | 813 | if (copy_from_user(&gd, arg, sizeof(gd))) |
815 | return -EFAULT; | 814 | return -EFAULT; |
816 | down_read(&usb_bus_type.subsys.rwsem); | ||
817 | intf = usb_ifnum_to_if(ps->dev, gd.interface); | 815 | intf = usb_ifnum_to_if(ps->dev, gd.interface); |
818 | if (!intf || !intf->dev.driver) | 816 | if (!intf || !intf->dev.driver) |
819 | ret = -ENODATA; | 817 | ret = -ENODATA; |
@@ -822,7 +820,6 @@ static int proc_getdriver(struct dev_state *ps, void __user *arg) | |||
822 | sizeof(gd.driver)); | 820 | sizeof(gd.driver)); |
823 | ret = (copy_to_user(arg, &gd, sizeof(gd)) ? -EFAULT : 0); | 821 | ret = (copy_to_user(arg, &gd, sizeof(gd)) ? -EFAULT : 0); |
824 | } | 822 | } |
825 | up_read(&usb_bus_type.subsys.rwsem); | ||
826 | return ret; | 823 | return ret; |
827 | } | 824 | } |
828 | 825 | ||
@@ -857,11 +854,11 @@ static int proc_setintf(struct dev_state *ps, void __user *arg) | |||
857 | 854 | ||
858 | static int proc_setconfig(struct dev_state *ps, void __user *arg) | 855 | static int proc_setconfig(struct dev_state *ps, void __user *arg) |
859 | { | 856 | { |
860 | unsigned int u; | 857 | int u; |
861 | int status = 0; | 858 | int status = 0; |
862 | struct usb_host_config *actconfig; | 859 | struct usb_host_config *actconfig; |
863 | 860 | ||
864 | if (get_user(u, (unsigned int __user *)arg)) | 861 | if (get_user(u, (int __user *)arg)) |
865 | return -EFAULT; | 862 | return -EFAULT; |
866 | 863 | ||
867 | actconfig = ps->dev->actconfig; | 864 | actconfig = ps->dev->actconfig; |
@@ -912,7 +909,7 @@ static int proc_do_submiturb(struct dev_state *ps, struct usbdevfs_urb *uurb, | |||
912 | struct async *as; | 909 | struct async *as; |
913 | struct usb_ctrlrequest *dr = NULL; | 910 | struct usb_ctrlrequest *dr = NULL; |
914 | unsigned int u, totlen, isofrmlen; | 911 | unsigned int u, totlen, isofrmlen; |
915 | int ret, interval = 0, ifnum = -1; | 912 | int ret, ifnum = -1; |
916 | 913 | ||
917 | if (uurb->flags & ~(USBDEVFS_URB_ISO_ASAP|USBDEVFS_URB_SHORT_NOT_OK| | 914 | if (uurb->flags & ~(USBDEVFS_URB_ISO_ASAP|USBDEVFS_URB_SHORT_NOT_OK| |
918 | URB_NO_FSBR|URB_ZERO_PACKET)) | 915 | URB_NO_FSBR|URB_ZERO_PACKET)) |
@@ -992,7 +989,6 @@ static int proc_do_submiturb(struct dev_state *ps, struct usbdevfs_urb *uurb, | |||
992 | if ((ep->desc.bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) | 989 | if ((ep->desc.bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) |
993 | != USB_ENDPOINT_XFER_ISOC) | 990 | != USB_ENDPOINT_XFER_ISOC) |
994 | return -EINVAL; | 991 | return -EINVAL; |
995 | interval = 1 << min (15, ep->desc.bInterval - 1); | ||
996 | isofrmlen = sizeof(struct usbdevfs_iso_packet_desc) * uurb->number_of_packets; | 992 | isofrmlen = sizeof(struct usbdevfs_iso_packet_desc) * uurb->number_of_packets; |
997 | if (!(isopkt = kmalloc(isofrmlen, GFP_KERNEL))) | 993 | if (!(isopkt = kmalloc(isofrmlen, GFP_KERNEL))) |
998 | return -ENOMEM; | 994 | return -ENOMEM; |
@@ -1021,10 +1017,6 @@ static int proc_do_submiturb(struct dev_state *ps, struct usbdevfs_urb *uurb, | |||
1021 | if ((ep->desc.bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) | 1017 | if ((ep->desc.bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) |
1022 | != USB_ENDPOINT_XFER_INT) | 1018 | != USB_ENDPOINT_XFER_INT) |
1023 | return -EINVAL; | 1019 | return -EINVAL; |
1024 | if (ps->dev->speed == USB_SPEED_HIGH) | ||
1025 | interval = 1 << min (15, ep->desc.bInterval - 1); | ||
1026 | else | ||
1027 | interval = ep->desc.bInterval; | ||
1028 | if (uurb->buffer_length > MAX_USBFS_BUFFER_SIZE) | 1020 | if (uurb->buffer_length > MAX_USBFS_BUFFER_SIZE) |
1029 | return -EINVAL; | 1021 | return -EINVAL; |
1030 | if (!access_ok((uurb->endpoint & USB_DIR_IN) ? VERIFY_WRITE : VERIFY_READ, uurb->buffer, uurb->buffer_length)) | 1022 | if (!access_ok((uurb->endpoint & USB_DIR_IN) ? VERIFY_WRITE : VERIFY_READ, uurb->buffer, uurb->buffer_length)) |
@@ -1053,7 +1045,11 @@ static int proc_do_submiturb(struct dev_state *ps, struct usbdevfs_urb *uurb, | |||
1053 | as->urb->setup_packet = (unsigned char*)dr; | 1045 | as->urb->setup_packet = (unsigned char*)dr; |
1054 | as->urb->start_frame = uurb->start_frame; | 1046 | as->urb->start_frame = uurb->start_frame; |
1055 | as->urb->number_of_packets = uurb->number_of_packets; | 1047 | as->urb->number_of_packets = uurb->number_of_packets; |
1056 | as->urb->interval = interval; | 1048 | if (uurb->type == USBDEVFS_URB_TYPE_ISO || |
1049 | ps->dev->speed == USB_SPEED_HIGH) | ||
1050 | as->urb->interval = 1 << min(15, ep->desc.bInterval - 1); | ||
1051 | else | ||
1052 | as->urb->interval = ep->desc.bInterval; | ||
1057 | as->urb->context = as; | 1053 | as->urb->context = as; |
1058 | as->urb->complete = async_completed; | 1054 | as->urb->complete = async_completed; |
1059 | for (totlen = u = 0; u < uurb->number_of_packets; u++) { | 1055 | for (totlen = u = 0; u < uurb->number_of_packets; u++) { |
@@ -1352,15 +1348,12 @@ static int proc_ioctl(struct dev_state *ps, struct usbdevfs_ioctl *ctl) | |||
1352 | 1348 | ||
1353 | /* disconnect kernel driver from interface */ | 1349 | /* disconnect kernel driver from interface */ |
1354 | case USBDEVFS_DISCONNECT: | 1350 | case USBDEVFS_DISCONNECT: |
1355 | |||
1356 | down_write(&usb_bus_type.subsys.rwsem); | ||
1357 | if (intf->dev.driver) { | 1351 | if (intf->dev.driver) { |
1358 | driver = to_usb_driver(intf->dev.driver); | 1352 | driver = to_usb_driver(intf->dev.driver); |
1359 | dev_dbg (&intf->dev, "disconnect by usbfs\n"); | 1353 | dev_dbg (&intf->dev, "disconnect by usbfs\n"); |
1360 | usb_driver_release_interface(driver, intf); | 1354 | usb_driver_release_interface(driver, intf); |
1361 | } else | 1355 | } else |
1362 | retval = -ENODATA; | 1356 | retval = -ENODATA; |
1363 | up_write(&usb_bus_type.subsys.rwsem); | ||
1364 | break; | 1357 | break; |
1365 | 1358 | ||
1366 | /* let kernel drivers try to (re)bind to the interface */ | 1359 | /* let kernel drivers try to (re)bind to the interface */ |
@@ -1372,7 +1365,6 @@ static int proc_ioctl(struct dev_state *ps, struct usbdevfs_ioctl *ctl) | |||
1372 | 1365 | ||
1373 | /* talk directly to the interface's driver */ | 1366 | /* talk directly to the interface's driver */ |
1374 | default: | 1367 | default: |
1375 | down_read(&usb_bus_type.subsys.rwsem); | ||
1376 | if (intf->dev.driver) | 1368 | if (intf->dev.driver) |
1377 | driver = to_usb_driver(intf->dev.driver); | 1369 | driver = to_usb_driver(intf->dev.driver); |
1378 | if (driver == NULL || driver->ioctl == NULL) { | 1370 | if (driver == NULL || driver->ioctl == NULL) { |
@@ -1382,7 +1374,6 @@ static int proc_ioctl(struct dev_state *ps, struct usbdevfs_ioctl *ctl) | |||
1382 | if (retval == -ENOIOCTLCMD) | 1374 | if (retval == -ENOIOCTLCMD) |
1383 | retval = -ENOTTY; | 1375 | retval = -ENOTTY; |
1384 | } | 1376 | } |
1385 | up_read(&usb_bus_type.subsys.rwsem); | ||
1386 | } | 1377 | } |
1387 | 1378 | ||
1388 | /* cleanup and return */ | 1379 | /* cleanup and return */ |
@@ -1584,7 +1575,7 @@ static unsigned int usbdev_poll(struct file *file, struct poll_table_struct *wai | |||
1584 | return mask; | 1575 | return mask; |
1585 | } | 1576 | } |
1586 | 1577 | ||
1587 | const struct file_operations usbfs_device_file_operations = { | 1578 | const struct file_operations usbdev_file_operations = { |
1588 | .llseek = usbdev_lseek, | 1579 | .llseek = usbdev_lseek, |
1589 | .read = usbdev_read, | 1580 | .read = usbdev_read, |
1590 | .poll = usbdev_poll, | 1581 | .poll = usbdev_poll, |
@@ -1593,50 +1584,53 @@ const struct file_operations usbfs_device_file_operations = { | |||
1593 | .release = usbdev_release, | 1584 | .release = usbdev_release, |
1594 | }; | 1585 | }; |
1595 | 1586 | ||
1596 | static int usbdev_add(struct usb_device *dev) | 1587 | #ifdef CONFIG_USB_DEVICE_CLASS |
1588 | static struct class *usb_classdev_class; | ||
1589 | |||
1590 | static int usb_classdev_add(struct usb_device *dev) | ||
1597 | { | 1591 | { |
1598 | int minor = ((dev->bus->busnum-1) * 128) + (dev->devnum-1); | 1592 | int minor = ((dev->bus->busnum-1) * 128) + (dev->devnum-1); |
1599 | 1593 | ||
1600 | dev->usbfs_dev = device_create(usb_device_class, &dev->dev, | 1594 | dev->usb_classdev = device_create(usb_classdev_class, &dev->dev, |
1601 | MKDEV(USB_DEVICE_MAJOR, minor), | 1595 | MKDEV(USB_DEVICE_MAJOR, minor), |
1602 | "usbdev%d.%d", dev->bus->busnum, dev->devnum); | 1596 | "usbdev%d.%d", dev->bus->busnum, dev->devnum); |
1603 | if (IS_ERR(dev->usbfs_dev)) | 1597 | if (IS_ERR(dev->usb_classdev)) |
1604 | return PTR_ERR(dev->usbfs_dev); | 1598 | return PTR_ERR(dev->usb_classdev); |
1605 | 1599 | ||
1606 | dev->usbfs_dev->platform_data = dev; | ||
1607 | return 0; | 1600 | return 0; |
1608 | } | 1601 | } |
1609 | 1602 | ||
1610 | static void usbdev_remove(struct usb_device *dev) | 1603 | static void usb_classdev_remove(struct usb_device *dev) |
1611 | { | 1604 | { |
1612 | device_unregister(dev->usbfs_dev); | 1605 | device_unregister(dev->usb_classdev); |
1613 | } | 1606 | } |
1614 | 1607 | ||
1615 | static int usbdev_notify(struct notifier_block *self, unsigned long action, | 1608 | static int usb_classdev_notify(struct notifier_block *self, |
1616 | void *dev) | 1609 | unsigned long action, void *dev) |
1617 | { | 1610 | { |
1618 | switch (action) { | 1611 | switch (action) { |
1619 | case USB_DEVICE_ADD: | 1612 | case USB_DEVICE_ADD: |
1620 | if (usbdev_add(dev)) | 1613 | if (usb_classdev_add(dev)) |
1621 | return NOTIFY_BAD; | 1614 | return NOTIFY_BAD; |
1622 | break; | 1615 | break; |
1623 | case USB_DEVICE_REMOVE: | 1616 | case USB_DEVICE_REMOVE: |
1624 | usbdev_remove(dev); | 1617 | usb_classdev_remove(dev); |
1625 | break; | 1618 | break; |
1626 | } | 1619 | } |
1627 | return NOTIFY_OK; | 1620 | return NOTIFY_OK; |
1628 | } | 1621 | } |
1629 | 1622 | ||
1630 | static struct notifier_block usbdev_nb = { | 1623 | static struct notifier_block usbdev_nb = { |
1631 | .notifier_call = usbdev_notify, | 1624 | .notifier_call = usb_classdev_notify, |
1632 | }; | 1625 | }; |
1626 | #endif | ||
1633 | 1627 | ||
1634 | static struct cdev usb_device_cdev = { | 1628 | static struct cdev usb_device_cdev = { |
1635 | .kobj = {.name = "usb_device", }, | 1629 | .kobj = {.name = "usb_device", }, |
1636 | .owner = THIS_MODULE, | 1630 | .owner = THIS_MODULE, |
1637 | }; | 1631 | }; |
1638 | 1632 | ||
1639 | int __init usbdev_init(void) | 1633 | int __init usb_devio_init(void) |
1640 | { | 1634 | { |
1641 | int retval; | 1635 | int retval; |
1642 | 1636 | ||
@@ -1646,38 +1640,38 @@ int __init usbdev_init(void) | |||
1646 | err("unable to register minors for usb_device"); | 1640 | err("unable to register minors for usb_device"); |
1647 | goto out; | 1641 | goto out; |
1648 | } | 1642 | } |
1649 | cdev_init(&usb_device_cdev, &usbfs_device_file_operations); | 1643 | cdev_init(&usb_device_cdev, &usbdev_file_operations); |
1650 | retval = cdev_add(&usb_device_cdev, USB_DEVICE_DEV, USB_DEVICE_MAX); | 1644 | retval = cdev_add(&usb_device_cdev, USB_DEVICE_DEV, USB_DEVICE_MAX); |
1651 | if (retval) { | 1645 | if (retval) { |
1652 | err("unable to get usb_device major %d", USB_DEVICE_MAJOR); | 1646 | err("unable to get usb_device major %d", USB_DEVICE_MAJOR); |
1653 | goto error_cdev; | 1647 | goto error_cdev; |
1654 | } | 1648 | } |
1655 | usb_device_class = class_create(THIS_MODULE, "usb_device"); | 1649 | #ifdef CONFIG_USB_DEVICE_CLASS |
1656 | if (IS_ERR(usb_device_class)) { | 1650 | usb_classdev_class = class_create(THIS_MODULE, "usb_device"); |
1651 | if (IS_ERR(usb_classdev_class)) { | ||
1657 | err("unable to register usb_device class"); | 1652 | err("unable to register usb_device class"); |
1658 | retval = PTR_ERR(usb_device_class); | 1653 | retval = PTR_ERR(usb_classdev_class); |
1659 | goto error_class; | 1654 | cdev_del(&usb_device_cdev); |
1655 | usb_classdev_class = NULL; | ||
1656 | goto out; | ||
1660 | } | 1657 | } |
1661 | 1658 | ||
1662 | usb_register_notify(&usbdev_nb); | 1659 | usb_register_notify(&usbdev_nb); |
1663 | 1660 | #endif | |
1664 | out: | 1661 | out: |
1665 | return retval; | 1662 | return retval; |
1666 | 1663 | ||
1667 | error_class: | ||
1668 | usb_device_class = NULL; | ||
1669 | cdev_del(&usb_device_cdev); | ||
1670 | |||
1671 | error_cdev: | 1664 | error_cdev: |
1672 | unregister_chrdev_region(USB_DEVICE_DEV, USB_DEVICE_MAX); | 1665 | unregister_chrdev_region(USB_DEVICE_DEV, USB_DEVICE_MAX); |
1673 | goto out; | 1666 | goto out; |
1674 | } | 1667 | } |
1675 | 1668 | ||
1676 | void usbdev_cleanup(void) | 1669 | void usb_devio_cleanup(void) |
1677 | { | 1670 | { |
1671 | #ifdef CONFIG_USB_DEVICE_CLASS | ||
1678 | usb_unregister_notify(&usbdev_nb); | 1672 | usb_unregister_notify(&usbdev_nb); |
1679 | class_destroy(usb_device_class); | 1673 | class_destroy(usb_classdev_class); |
1674 | #endif | ||
1680 | cdev_del(&usb_device_cdev); | 1675 | cdev_del(&usb_device_cdev); |
1681 | unregister_chrdev_region(USB_DEVICE_DEV, USB_DEVICE_MAX); | 1676 | unregister_chrdev_region(USB_DEVICE_DEV, USB_DEVICE_MAX); |
1682 | } | 1677 | } |
1683 | |||
diff --git a/drivers/usb/core/driver.c b/drivers/usb/core/driver.c index 600d1bc8272a..b9f7f90aef82 100644 --- a/drivers/usb/core/driver.c +++ b/drivers/usb/core/driver.c | |||
@@ -287,9 +287,9 @@ static int usb_unbind_interface(struct device *dev) | |||
287 | * way to bind to an interface is to return the private data from | 287 | * way to bind to an interface is to return the private data from |
288 | * the driver's probe() method. | 288 | * the driver's probe() method. |
289 | * | 289 | * |
290 | * Callers must own the device lock and the driver model's usb_bus_type.subsys | 290 | * Callers must own the device lock, so driver probe() entries don't need |
291 | * writelock. So driver probe() entries don't need extra locking, | 291 | * extra locking, but other call contexts may need to explicitly claim that |
292 | * but other call contexts may need to explicitly claim those locks. | 292 | * lock. |
293 | */ | 293 | */ |
294 | int usb_driver_claim_interface(struct usb_driver *driver, | 294 | int usb_driver_claim_interface(struct usb_driver *driver, |
295 | struct usb_interface *iface, void* priv) | 295 | struct usb_interface *iface, void* priv) |
@@ -330,9 +330,9 @@ EXPORT_SYMBOL(usb_driver_claim_interface); | |||
330 | * also causes the driver disconnect() method to be called. | 330 | * also causes the driver disconnect() method to be called. |
331 | * | 331 | * |
332 | * This call is synchronous, and may not be used in an interrupt context. | 332 | * This call is synchronous, and may not be used in an interrupt context. |
333 | * Callers must own the device lock and the driver model's usb_bus_type.subsys | 333 | * Callers must own the device lock, so driver disconnect() entries don't |
334 | * writelock. So driver disconnect() entries don't need extra locking, | 334 | * need extra locking, but other call contexts may need to explicitly claim |
335 | * but other call contexts may need to explicitly claim those locks. | 335 | * that lock. |
336 | */ | 336 | */ |
337 | void usb_driver_release_interface(struct usb_driver *driver, | 337 | void usb_driver_release_interface(struct usb_driver *driver, |
338 | struct usb_interface *iface) | 338 | struct usb_interface *iface) |
@@ -366,19 +366,8 @@ void usb_driver_release_interface(struct usb_driver *driver, | |||
366 | EXPORT_SYMBOL(usb_driver_release_interface); | 366 | EXPORT_SYMBOL(usb_driver_release_interface); |
367 | 367 | ||
368 | /* returns 0 if no match, 1 if match */ | 368 | /* returns 0 if no match, 1 if match */ |
369 | int usb_match_one_id(struct usb_interface *interface, | 369 | int usb_match_device(struct usb_device *dev, const struct usb_device_id *id) |
370 | const struct usb_device_id *id) | ||
371 | { | 370 | { |
372 | struct usb_host_interface *intf; | ||
373 | struct usb_device *dev; | ||
374 | |||
375 | /* proc_connectinfo in devio.c may call us with id == NULL. */ | ||
376 | if (id == NULL) | ||
377 | return 0; | ||
378 | |||
379 | intf = interface->cur_altsetting; | ||
380 | dev = interface_to_usbdev(interface); | ||
381 | |||
382 | if ((id->match_flags & USB_DEVICE_ID_MATCH_VENDOR) && | 371 | if ((id->match_flags & USB_DEVICE_ID_MATCH_VENDOR) && |
383 | id->idVendor != le16_to_cpu(dev->descriptor.idVendor)) | 372 | id->idVendor != le16_to_cpu(dev->descriptor.idVendor)) |
384 | return 0; | 373 | return 0; |
@@ -409,6 +398,26 @@ int usb_match_one_id(struct usb_interface *interface, | |||
409 | (id->bDeviceProtocol != dev->descriptor.bDeviceProtocol)) | 398 | (id->bDeviceProtocol != dev->descriptor.bDeviceProtocol)) |
410 | return 0; | 399 | return 0; |
411 | 400 | ||
401 | return 1; | ||
402 | } | ||
403 | |||
404 | /* returns 0 if no match, 1 if match */ | ||
405 | int usb_match_one_id(struct usb_interface *interface, | ||
406 | const struct usb_device_id *id) | ||
407 | { | ||
408 | struct usb_host_interface *intf; | ||
409 | struct usb_device *dev; | ||
410 | |||
411 | /* proc_connectinfo in devio.c may call us with id == NULL. */ | ||
412 | if (id == NULL) | ||
413 | return 0; | ||
414 | |||
415 | intf = interface->cur_altsetting; | ||
416 | dev = interface_to_usbdev(interface); | ||
417 | |||
418 | if (!usb_match_device(dev, id)) | ||
419 | return 0; | ||
420 | |||
412 | /* The interface class, subclass, and protocol should never be | 421 | /* The interface class, subclass, and protocol should never be |
413 | * checked for a match if the device class is Vendor Specific, | 422 | * checked for a match if the device class is Vendor Specific, |
414 | * unless the match record specifies the Vendor ID. */ | 423 | * unless the match record specifies the Vendor ID. */ |
@@ -565,23 +574,10 @@ static int usb_device_match(struct device *dev, struct device_driver *drv) | |||
565 | } | 574 | } |
566 | 575 | ||
567 | #ifdef CONFIG_HOTPLUG | 576 | #ifdef CONFIG_HOTPLUG |
568 | |||
569 | /* | ||
570 | * This sends an uevent to userspace, typically helping to load driver | ||
571 | * or other modules, configure the device, and more. Drivers can provide | ||
572 | * a MODULE_DEVICE_TABLE to help with module loading subtasks. | ||
573 | * | ||
574 | * We're called either from khubd (the typical case) or from root hub | ||
575 | * (init, kapmd, modprobe, rmmod, etc), but the agents need to handle | ||
576 | * delays in event delivery. Use sysfs (and DEVPATH) to make sure the | ||
577 | * device (and this configuration!) are still present. | ||
578 | */ | ||
579 | static int usb_uevent(struct device *dev, char **envp, int num_envp, | 577 | static int usb_uevent(struct device *dev, char **envp, int num_envp, |
580 | char *buffer, int buffer_size) | 578 | char *buffer, int buffer_size) |
581 | { | 579 | { |
582 | struct usb_interface *intf; | ||
583 | struct usb_device *usb_dev; | 580 | struct usb_device *usb_dev; |
584 | struct usb_host_interface *alt; | ||
585 | int i = 0; | 581 | int i = 0; |
586 | int length = 0; | 582 | int length = 0; |
587 | 583 | ||
@@ -591,13 +587,11 @@ static int usb_uevent(struct device *dev, char **envp, int num_envp, | |||
591 | /* driver is often null here; dev_dbg() would oops */ | 587 | /* driver is often null here; dev_dbg() would oops */ |
592 | pr_debug ("usb %s: uevent\n", dev->bus_id); | 588 | pr_debug ("usb %s: uevent\n", dev->bus_id); |
593 | 589 | ||
594 | if (is_usb_device(dev)) { | 590 | if (is_usb_device(dev)) |
595 | usb_dev = to_usb_device(dev); | 591 | usb_dev = to_usb_device(dev); |
596 | alt = NULL; | 592 | else { |
597 | } else { | 593 | struct usb_interface *intf = to_usb_interface(dev); |
598 | intf = to_usb_interface(dev); | ||
599 | usb_dev = interface_to_usbdev(intf); | 594 | usb_dev = interface_to_usbdev(intf); |
600 | alt = intf->cur_altsetting; | ||
601 | } | 595 | } |
602 | 596 | ||
603 | if (usb_dev->devnum < 0) { | 597 | if (usb_dev->devnum < 0) { |
@@ -612,9 +606,7 @@ static int usb_uevent(struct device *dev, char **envp, int num_envp, | |||
612 | #ifdef CONFIG_USB_DEVICEFS | 606 | #ifdef CONFIG_USB_DEVICEFS |
613 | /* If this is available, userspace programs can directly read | 607 | /* If this is available, userspace programs can directly read |
614 | * all the device descriptors we don't tell them about. Or | 608 | * all the device descriptors we don't tell them about. Or |
615 | * even act as usermode drivers. | 609 | * act as usermode drivers. |
616 | * | ||
617 | * FIXME reduce hardwired intelligence here | ||
618 | */ | 610 | */ |
619 | if (add_uevent_var(envp, num_envp, &i, | 611 | if (add_uevent_var(envp, num_envp, &i, |
620 | buffer, buffer_size, &length, | 612 | buffer, buffer_size, &length, |
@@ -641,44 +633,29 @@ static int usb_uevent(struct device *dev, char **envp, int num_envp, | |||
641 | usb_dev->descriptor.bDeviceProtocol)) | 633 | usb_dev->descriptor.bDeviceProtocol)) |
642 | return -ENOMEM; | 634 | return -ENOMEM; |
643 | 635 | ||
644 | if (!is_usb_device(dev)) { | 636 | if (add_uevent_var(envp, num_envp, &i, |
645 | |||
646 | if (add_uevent_var(envp, num_envp, &i, | ||
647 | buffer, buffer_size, &length, | 637 | buffer, buffer_size, &length, |
648 | "INTERFACE=%d/%d/%d", | 638 | "BUSNUM=%03d", |
649 | alt->desc.bInterfaceClass, | 639 | usb_dev->bus->busnum)) |
650 | alt->desc.bInterfaceSubClass, | 640 | return -ENOMEM; |
651 | alt->desc.bInterfaceProtocol)) | ||
652 | return -ENOMEM; | ||
653 | 641 | ||
654 | if (add_uevent_var(envp, num_envp, &i, | 642 | if (add_uevent_var(envp, num_envp, &i, |
655 | buffer, buffer_size, &length, | 643 | buffer, buffer_size, &length, |
656 | "MODALIAS=usb:v%04Xp%04Xd%04Xdc%02Xdsc%02Xdp%02Xic%02Xisc%02Xip%02X", | 644 | "DEVNUM=%03d", |
657 | le16_to_cpu(usb_dev->descriptor.idVendor), | 645 | usb_dev->devnum)) |
658 | le16_to_cpu(usb_dev->descriptor.idProduct), | 646 | return -ENOMEM; |
659 | le16_to_cpu(usb_dev->descriptor.bcdDevice), | ||
660 | usb_dev->descriptor.bDeviceClass, | ||
661 | usb_dev->descriptor.bDeviceSubClass, | ||
662 | usb_dev->descriptor.bDeviceProtocol, | ||
663 | alt->desc.bInterfaceClass, | ||
664 | alt->desc.bInterfaceSubClass, | ||
665 | alt->desc.bInterfaceProtocol)) | ||
666 | return -ENOMEM; | ||
667 | } | ||
668 | 647 | ||
669 | envp[i] = NULL; | 648 | envp[i] = NULL; |
670 | |||
671 | return 0; | 649 | return 0; |
672 | } | 650 | } |
673 | 651 | ||
674 | #else | 652 | #else |
675 | 653 | ||
676 | static int usb_uevent(struct device *dev, char **envp, | 654 | static int usb_uevent(struct device *dev, char **envp, |
677 | int num_envp, char *buffer, int buffer_size) | 655 | int num_envp, char *buffer, int buffer_size) |
678 | { | 656 | { |
679 | return -ENODEV; | 657 | return -ENODEV; |
680 | } | 658 | } |
681 | |||
682 | #endif /* CONFIG_HOTPLUG */ | 659 | #endif /* CONFIG_HOTPLUG */ |
683 | 660 | ||
684 | /** | 661 | /** |
@@ -743,6 +720,7 @@ EXPORT_SYMBOL_GPL(usb_deregister_device_driver); | |||
743 | * usb_register_driver - register a USB interface driver | 720 | * usb_register_driver - register a USB interface driver |
744 | * @new_driver: USB operations for the interface driver | 721 | * @new_driver: USB operations for the interface driver |
745 | * @owner: module owner of this driver. | 722 | * @owner: module owner of this driver. |
723 | * @mod_name: module name string | ||
746 | * | 724 | * |
747 | * Registers a USB interface driver with the USB core. The list of | 725 | * Registers a USB interface driver with the USB core. The list of |
748 | * unattached interfaces will be rescanned whenever a new driver is | 726 | * unattached interfaces will be rescanned whenever a new driver is |
@@ -862,8 +840,10 @@ static int usb_resume_device(struct usb_device *udev) | |||
862 | 840 | ||
863 | done: | 841 | done: |
864 | // dev_dbg(&udev->dev, "%s: status %d\n", __FUNCTION__, status); | 842 | // dev_dbg(&udev->dev, "%s: status %d\n", __FUNCTION__, status); |
865 | if (status == 0) | 843 | if (status == 0) { |
844 | udev->autoresume_disabled = 0; | ||
866 | udev->dev.power.power_state.event = PM_EVENT_ON; | 845 | udev->dev.power.power_state.event = PM_EVENT_ON; |
846 | } | ||
867 | return status; | 847 | return status; |
868 | } | 848 | } |
869 | 849 | ||
@@ -952,13 +932,19 @@ static int autosuspend_check(struct usb_device *udev) | |||
952 | { | 932 | { |
953 | int i; | 933 | int i; |
954 | struct usb_interface *intf; | 934 | struct usb_interface *intf; |
935 | unsigned long suspend_time; | ||
955 | 936 | ||
956 | /* For autosuspend, fail fast if anything is in use. | 937 | /* For autosuspend, fail fast if anything is in use or autosuspend |
957 | * Also fail if any interfaces require remote wakeup but it | 938 | * is disabled. Also fail if any interfaces require remote wakeup |
958 | * isn't available. */ | 939 | * but it isn't available. |
940 | */ | ||
959 | udev->do_remote_wakeup = device_may_wakeup(&udev->dev); | 941 | udev->do_remote_wakeup = device_may_wakeup(&udev->dev); |
960 | if (udev->pm_usage_cnt > 0) | 942 | if (udev->pm_usage_cnt > 0) |
961 | return -EBUSY; | 943 | return -EBUSY; |
944 | if (udev->autosuspend_delay < 0 || udev->autosuspend_disabled) | ||
945 | return -EPERM; | ||
946 | |||
947 | suspend_time = udev->last_busy + udev->autosuspend_delay; | ||
962 | if (udev->actconfig) { | 948 | if (udev->actconfig) { |
963 | for (i = 0; i < udev->actconfig->desc.bNumInterfaces; i++) { | 949 | for (i = 0; i < udev->actconfig->desc.bNumInterfaces; i++) { |
964 | intf = udev->actconfig->interface[i]; | 950 | intf = udev->actconfig->interface[i]; |
@@ -974,6 +960,24 @@ static int autosuspend_check(struct usb_device *udev) | |||
974 | } | 960 | } |
975 | } | 961 | } |
976 | } | 962 | } |
963 | |||
964 | /* If everything is okay but the device hasn't been idle for long | ||
965 | * enough, queue a delayed autosuspend request. | ||
966 | */ | ||
967 | if (time_after(suspend_time, jiffies)) { | ||
968 | if (!timer_pending(&udev->autosuspend.timer)) { | ||
969 | |||
970 | /* The value of jiffies may change between the | ||
971 | * time_after() comparison above and the subtraction | ||
972 | * below. That's okay; the system behaves sanely | ||
973 | * when a timer is registered for the present moment | ||
974 | * or for the past. | ||
975 | */ | ||
976 | queue_delayed_work(ksuspend_usb_wq, &udev->autosuspend, | ||
977 | suspend_time - jiffies); | ||
978 | } | ||
979 | return -EAGAIN; | ||
980 | } | ||
977 | return 0; | 981 | return 0; |
978 | } | 982 | } |
979 | 983 | ||
@@ -981,7 +985,7 @@ static int autosuspend_check(struct usb_device *udev) | |||
981 | 985 | ||
982 | #define autosuspend_check(udev) 0 | 986 | #define autosuspend_check(udev) 0 |
983 | 987 | ||
984 | #endif | 988 | #endif /* CONFIG_USB_SUSPEND */ |
985 | 989 | ||
986 | /** | 990 | /** |
987 | * usb_suspend_both - suspend a USB device and its interfaces | 991 | * usb_suspend_both - suspend a USB device and its interfaces |
@@ -1019,26 +1023,25 @@ static int autosuspend_check(struct usb_device *udev) | |||
1019 | * | 1023 | * |
1020 | * This routine can run only in process context. | 1024 | * This routine can run only in process context. |
1021 | */ | 1025 | */ |
1022 | int usb_suspend_both(struct usb_device *udev, pm_message_t msg) | 1026 | static int usb_suspend_both(struct usb_device *udev, pm_message_t msg) |
1023 | { | 1027 | { |
1024 | int status = 0; | 1028 | int status = 0; |
1025 | int i = 0; | 1029 | int i = 0; |
1026 | struct usb_interface *intf; | 1030 | struct usb_interface *intf; |
1027 | struct usb_device *parent = udev->parent; | 1031 | struct usb_device *parent = udev->parent; |
1028 | 1032 | ||
1029 | cancel_delayed_work(&udev->autosuspend); | 1033 | if (udev->state == USB_STATE_NOTATTACHED || |
1030 | if (udev->state == USB_STATE_NOTATTACHED) | 1034 | udev->state == USB_STATE_SUSPENDED) |
1031 | return 0; | 1035 | goto done; |
1032 | if (udev->state == USB_STATE_SUSPENDED) | ||
1033 | return 0; | ||
1034 | 1036 | ||
1035 | udev->do_remote_wakeup = device_may_wakeup(&udev->dev); | 1037 | udev->do_remote_wakeup = device_may_wakeup(&udev->dev); |
1036 | 1038 | ||
1037 | if (udev->auto_pm) { | 1039 | if (udev->auto_pm) { |
1038 | status = autosuspend_check(udev); | 1040 | status = autosuspend_check(udev); |
1039 | if (status < 0) | 1041 | if (status < 0) |
1040 | return status; | 1042 | goto done; |
1041 | } | 1043 | } |
1044 | cancel_delayed_work(&udev->autosuspend); | ||
1042 | 1045 | ||
1043 | /* Suspend all the interfaces and then udev itself */ | 1046 | /* Suspend all the interfaces and then udev itself */ |
1044 | if (udev->actconfig) { | 1047 | if (udev->actconfig) { |
@@ -1063,6 +1066,7 @@ int usb_suspend_both(struct usb_device *udev, pm_message_t msg) | |||
1063 | } else if (parent) | 1066 | } else if (parent) |
1064 | usb_autosuspend_device(parent); | 1067 | usb_autosuspend_device(parent); |
1065 | 1068 | ||
1069 | done: | ||
1066 | // dev_dbg(&udev->dev, "%s: status %d\n", __FUNCTION__, status); | 1070 | // dev_dbg(&udev->dev, "%s: status %d\n", __FUNCTION__, status); |
1067 | return status; | 1071 | return status; |
1068 | } | 1072 | } |
@@ -1095,7 +1099,7 @@ int usb_suspend_both(struct usb_device *udev, pm_message_t msg) | |||
1095 | * | 1099 | * |
1096 | * This routine can run only in process context. | 1100 | * This routine can run only in process context. |
1097 | */ | 1101 | */ |
1098 | int usb_resume_both(struct usb_device *udev) | 1102 | static int usb_resume_both(struct usb_device *udev) |
1099 | { | 1103 | { |
1100 | int status = 0; | 1104 | int status = 0; |
1101 | int i; | 1105 | int i; |
@@ -1103,11 +1107,17 @@ int usb_resume_both(struct usb_device *udev) | |||
1103 | struct usb_device *parent = udev->parent; | 1107 | struct usb_device *parent = udev->parent; |
1104 | 1108 | ||
1105 | cancel_delayed_work(&udev->autosuspend); | 1109 | cancel_delayed_work(&udev->autosuspend); |
1106 | if (udev->state == USB_STATE_NOTATTACHED) | 1110 | if (udev->state == USB_STATE_NOTATTACHED) { |
1107 | return -ENODEV; | 1111 | status = -ENODEV; |
1112 | goto done; | ||
1113 | } | ||
1108 | 1114 | ||
1109 | /* Propagate the resume up the tree, if necessary */ | 1115 | /* Propagate the resume up the tree, if necessary */ |
1110 | if (udev->state == USB_STATE_SUSPENDED) { | 1116 | if (udev->state == USB_STATE_SUSPENDED) { |
1117 | if (udev->auto_pm && udev->autoresume_disabled) { | ||
1118 | status = -EPERM; | ||
1119 | goto done; | ||
1120 | } | ||
1111 | if (parent) { | 1121 | if (parent) { |
1112 | status = usb_autoresume_device(parent); | 1122 | status = usb_autoresume_device(parent); |
1113 | if (status == 0) { | 1123 | if (status == 0) { |
@@ -1153,6 +1163,7 @@ int usb_resume_both(struct usb_device *udev) | |||
1153 | } | 1163 | } |
1154 | } | 1164 | } |
1155 | 1165 | ||
1166 | done: | ||
1156 | // dev_dbg(&udev->dev, "%s: status %d\n", __FUNCTION__, status); | 1167 | // dev_dbg(&udev->dev, "%s: status %d\n", __FUNCTION__, status); |
1157 | return status; | 1168 | return status; |
1158 | } | 1169 | } |
@@ -1167,20 +1178,34 @@ static int usb_autopm_do_device(struct usb_device *udev, int inc_usage_cnt) | |||
1167 | int status = 0; | 1178 | int status = 0; |
1168 | 1179 | ||
1169 | usb_pm_lock(udev); | 1180 | usb_pm_lock(udev); |
1181 | udev->auto_pm = 1; | ||
1170 | udev->pm_usage_cnt += inc_usage_cnt; | 1182 | udev->pm_usage_cnt += inc_usage_cnt; |
1171 | WARN_ON(udev->pm_usage_cnt < 0); | 1183 | WARN_ON(udev->pm_usage_cnt < 0); |
1172 | if (inc_usage_cnt >= 0 && udev->pm_usage_cnt > 0) { | 1184 | if (inc_usage_cnt >= 0 && udev->pm_usage_cnt > 0) { |
1173 | udev->auto_pm = 1; | 1185 | if (udev->state == USB_STATE_SUSPENDED) |
1174 | status = usb_resume_both(udev); | 1186 | status = usb_resume_both(udev); |
1175 | if (status != 0) | 1187 | if (status != 0) |
1176 | udev->pm_usage_cnt -= inc_usage_cnt; | 1188 | udev->pm_usage_cnt -= inc_usage_cnt; |
1177 | } else if (inc_usage_cnt <= 0 && autosuspend_check(udev) == 0) | 1189 | else if (inc_usage_cnt) |
1178 | queue_delayed_work(ksuspend_usb_wq, &udev->autosuspend, | 1190 | udev->last_busy = jiffies; |
1179 | USB_AUTOSUSPEND_DELAY); | 1191 | } else if (inc_usage_cnt <= 0 && udev->pm_usage_cnt <= 0) { |
1192 | if (inc_usage_cnt) | ||
1193 | udev->last_busy = jiffies; | ||
1194 | status = usb_suspend_both(udev, PMSG_SUSPEND); | ||
1195 | } | ||
1180 | usb_pm_unlock(udev); | 1196 | usb_pm_unlock(udev); |
1181 | return status; | 1197 | return status; |
1182 | } | 1198 | } |
1183 | 1199 | ||
1200 | /* usb_autosuspend_work - callback routine to autosuspend a USB device */ | ||
1201 | void usb_autosuspend_work(struct work_struct *work) | ||
1202 | { | ||
1203 | struct usb_device *udev = | ||
1204 | container_of(work, struct usb_device, autosuspend.work); | ||
1205 | |||
1206 | usb_autopm_do_device(udev, 0); | ||
1207 | } | ||
1208 | |||
1184 | /** | 1209 | /** |
1185 | * usb_autosuspend_device - delayed autosuspend of a USB device and its interfaces | 1210 | * usb_autosuspend_device - delayed autosuspend of a USB device and its interfaces |
1186 | * @udev: the usb_device to autosuspend | 1211 | * @udev: the usb_device to autosuspend |
@@ -1211,6 +1236,26 @@ void usb_autosuspend_device(struct usb_device *udev) | |||
1211 | } | 1236 | } |
1212 | 1237 | ||
1213 | /** | 1238 | /** |
1239 | * usb_try_autosuspend_device - attempt an autosuspend of a USB device and its interfaces | ||
1240 | * @udev: the usb_device to autosuspend | ||
1241 | * | ||
1242 | * This routine should be called when a core subsystem thinks @udev may | ||
1243 | * be ready to autosuspend. | ||
1244 | * | ||
1245 | * @udev's usage counter left unchanged. If it or any of the usage counters | ||
1246 | * for an active interface is greater than 0, or autosuspend is not allowed | ||
1247 | * for any other reason, no autosuspend request will be queued. | ||
1248 | * | ||
1249 | * This routine can run only in process context. | ||
1250 | */ | ||
1251 | void usb_try_autosuspend_device(struct usb_device *udev) | ||
1252 | { | ||
1253 | usb_autopm_do_device(udev, 0); | ||
1254 | // dev_dbg(&udev->dev, "%s: cnt %d\n", | ||
1255 | // __FUNCTION__, udev->pm_usage_cnt); | ||
1256 | } | ||
1257 | |||
1258 | /** | ||
1214 | * usb_autoresume_device - immediately autoresume a USB device and its interfaces | 1259 | * usb_autoresume_device - immediately autoresume a USB device and its interfaces |
1215 | * @udev: the usb_device to autoresume | 1260 | * @udev: the usb_device to autoresume |
1216 | * | 1261 | * |
@@ -1252,15 +1297,20 @@ static int usb_autopm_do_interface(struct usb_interface *intf, | |||
1252 | if (intf->condition == USB_INTERFACE_UNBOUND) | 1297 | if (intf->condition == USB_INTERFACE_UNBOUND) |
1253 | status = -ENODEV; | 1298 | status = -ENODEV; |
1254 | else { | 1299 | else { |
1300 | udev->auto_pm = 1; | ||
1255 | intf->pm_usage_cnt += inc_usage_cnt; | 1301 | intf->pm_usage_cnt += inc_usage_cnt; |
1256 | if (inc_usage_cnt >= 0 && intf->pm_usage_cnt > 0) { | 1302 | if (inc_usage_cnt >= 0 && intf->pm_usage_cnt > 0) { |
1257 | udev->auto_pm = 1; | 1303 | if (udev->state == USB_STATE_SUSPENDED) |
1258 | status = usb_resume_both(udev); | 1304 | status = usb_resume_both(udev); |
1259 | if (status != 0) | 1305 | if (status != 0) |
1260 | intf->pm_usage_cnt -= inc_usage_cnt; | 1306 | intf->pm_usage_cnt -= inc_usage_cnt; |
1261 | } else if (inc_usage_cnt <= 0 && autosuspend_check(udev) == 0) | 1307 | else if (inc_usage_cnt) |
1262 | queue_delayed_work(ksuspend_usb_wq, &udev->autosuspend, | 1308 | udev->last_busy = jiffies; |
1263 | USB_AUTOSUSPEND_DELAY); | 1309 | } else if (inc_usage_cnt <= 0 && intf->pm_usage_cnt <= 0) { |
1310 | if (inc_usage_cnt) | ||
1311 | udev->last_busy = jiffies; | ||
1312 | status = usb_suspend_both(udev, PMSG_SUSPEND); | ||
1313 | } | ||
1264 | } | 1314 | } |
1265 | usb_pm_unlock(udev); | 1315 | usb_pm_unlock(udev); |
1266 | return status; | 1316 | return status; |
@@ -1319,11 +1369,14 @@ EXPORT_SYMBOL_GPL(usb_autopm_put_interface); | |||
1319 | * or @intf is unbound. A typical example would be a character-device | 1369 | * or @intf is unbound. A typical example would be a character-device |
1320 | * driver when its device file is opened. | 1370 | * driver when its device file is opened. |
1321 | * | 1371 | * |
1322 | * The routine increments @intf's usage counter. So long as the counter | 1372 | * |
1323 | * is greater than 0, autosuspend will not be allowed for @intf or its | 1373 | * The routine increments @intf's usage counter. (However if the |
1324 | * usb_device. When the driver is finished using @intf it should call | 1374 | * autoresume fails then the counter is re-decremented.) So long as the |
1325 | * usb_autopm_put_interface() to decrement the usage counter and queue | 1375 | * counter is greater than 0, autosuspend will not be allowed for @intf |
1326 | * a delayed autosuspend request (if the counter is <= 0). | 1376 | * or its usb_device. When the driver is finished using @intf it should |
1377 | * call usb_autopm_put_interface() to decrement the usage counter and | ||
1378 | * queue a delayed autosuspend request (if the counter is <= 0). | ||
1379 | * | ||
1327 | * | 1380 | * |
1328 | * Note that @intf->pm_usage_cnt is owned by the interface driver. The | 1381 | * Note that @intf->pm_usage_cnt is owned by the interface driver. The |
1329 | * core will not change its value other than the increment and decrement | 1382 | * core will not change its value other than the increment and decrement |
@@ -1371,50 +1424,96 @@ int usb_autopm_set_interface(struct usb_interface *intf) | |||
1371 | } | 1424 | } |
1372 | EXPORT_SYMBOL_GPL(usb_autopm_set_interface); | 1425 | EXPORT_SYMBOL_GPL(usb_autopm_set_interface); |
1373 | 1426 | ||
1427 | #else | ||
1428 | |||
1429 | void usb_autosuspend_work(struct work_struct *work) | ||
1430 | {} | ||
1431 | |||
1374 | #endif /* CONFIG_USB_SUSPEND */ | 1432 | #endif /* CONFIG_USB_SUSPEND */ |
1375 | 1433 | ||
1376 | static int usb_suspend(struct device *dev, pm_message_t message) | 1434 | /** |
1435 | * usb_external_suspend_device - external suspend of a USB device and its interfaces | ||
1436 | * @udev: the usb_device to suspend | ||
1437 | * @msg: Power Management message describing this state transition | ||
1438 | * | ||
1439 | * This routine handles external suspend requests: ones not generated | ||
1440 | * internally by a USB driver (autosuspend) but rather coming from the user | ||
1441 | * (via sysfs) or the PM core (system sleep). The suspend will be carried | ||
1442 | * out regardless of @udev's usage counter or those of its interfaces, | ||
1443 | * and regardless of whether or not remote wakeup is enabled. Of course, | ||
1444 | * interface drivers still have the option of failing the suspend (if | ||
1445 | * there are unsuspended children, for example). | ||
1446 | * | ||
1447 | * The caller must hold @udev's device lock. | ||
1448 | */ | ||
1449 | int usb_external_suspend_device(struct usb_device *udev, pm_message_t msg) | ||
1377 | { | 1450 | { |
1378 | int status; | 1451 | int status; |
1379 | 1452 | ||
1380 | if (is_usb_device(dev)) { | 1453 | usb_pm_lock(udev); |
1381 | struct usb_device *udev = to_usb_device(dev); | 1454 | udev->auto_pm = 0; |
1382 | 1455 | status = usb_suspend_both(udev, msg); | |
1383 | usb_pm_lock(udev); | 1456 | usb_pm_unlock(udev); |
1384 | udev->auto_pm = 0; | ||
1385 | status = usb_suspend_both(udev, message); | ||
1386 | usb_pm_unlock(udev); | ||
1387 | } else | ||
1388 | status = 0; | ||
1389 | return status; | 1457 | return status; |
1390 | } | 1458 | } |
1391 | 1459 | ||
1392 | static int usb_resume(struct device *dev) | 1460 | /** |
1461 | * usb_external_resume_device - external resume of a USB device and its interfaces | ||
1462 | * @udev: the usb_device to resume | ||
1463 | * | ||
1464 | * This routine handles external resume requests: ones not generated | ||
1465 | * internally by a USB driver (autoresume) but rather coming from the user | ||
1466 | * (via sysfs), the PM core (system resume), or the device itself (remote | ||
1467 | * wakeup). @udev's usage counter is unaffected. | ||
1468 | * | ||
1469 | * The caller must hold @udev's device lock. | ||
1470 | */ | ||
1471 | int usb_external_resume_device(struct usb_device *udev) | ||
1393 | { | 1472 | { |
1394 | int status; | 1473 | int status; |
1395 | 1474 | ||
1396 | if (is_usb_device(dev)) { | 1475 | usb_pm_lock(udev); |
1397 | struct usb_device *udev = to_usb_device(dev); | 1476 | udev->auto_pm = 0; |
1398 | 1477 | status = usb_resume_both(udev); | |
1399 | usb_pm_lock(udev); | 1478 | usb_pm_unlock(udev); |
1400 | udev->auto_pm = 0; | ||
1401 | status = usb_resume_both(udev); | ||
1402 | usb_pm_unlock(udev); | ||
1403 | 1479 | ||
1404 | /* Rebind drivers that had no suspend method? */ | 1480 | /* Now that the device is awake, we can start trying to autosuspend |
1405 | } else | 1481 | * it again. */ |
1406 | status = 0; | 1482 | if (status == 0) |
1483 | usb_try_autosuspend_device(udev); | ||
1407 | return status; | 1484 | return status; |
1408 | } | 1485 | } |
1409 | 1486 | ||
1487 | static int usb_suspend(struct device *dev, pm_message_t message) | ||
1488 | { | ||
1489 | if (!is_usb_device(dev)) /* Ignore PM for interfaces */ | ||
1490 | return 0; | ||
1491 | return usb_external_suspend_device(to_usb_device(dev), message); | ||
1492 | } | ||
1493 | |||
1494 | static int usb_resume(struct device *dev) | ||
1495 | { | ||
1496 | struct usb_device *udev; | ||
1497 | |||
1498 | if (!is_usb_device(dev)) /* Ignore PM for interfaces */ | ||
1499 | return 0; | ||
1500 | udev = to_usb_device(dev); | ||
1501 | if (udev->autoresume_disabled) | ||
1502 | return -EPERM; | ||
1503 | return usb_external_resume_device(udev); | ||
1504 | } | ||
1505 | |||
1506 | #else | ||
1507 | |||
1508 | #define usb_suspend NULL | ||
1509 | #define usb_resume NULL | ||
1510 | |||
1410 | #endif /* CONFIG_PM */ | 1511 | #endif /* CONFIG_PM */ |
1411 | 1512 | ||
1412 | struct bus_type usb_bus_type = { | 1513 | struct bus_type usb_bus_type = { |
1413 | .name = "usb", | 1514 | .name = "usb", |
1414 | .match = usb_device_match, | 1515 | .match = usb_device_match, |
1415 | .uevent = usb_uevent, | 1516 | .uevent = usb_uevent, |
1416 | #ifdef CONFIG_PM | ||
1417 | .suspend = usb_suspend, | 1517 | .suspend = usb_suspend, |
1418 | .resume = usb_resume, | 1518 | .resume = usb_resume, |
1419 | #endif | ||
1420 | }; | 1519 | }; |
diff --git a/drivers/usb/core/endpoint.c b/drivers/usb/core/endpoint.c index 5e628ae3aec7..e0ec7045e865 100644 --- a/drivers/usb/core/endpoint.c +++ b/drivers/usb/core/endpoint.c | |||
@@ -229,7 +229,7 @@ static int init_endpoint_class(void) | |||
229 | kref_init(&ep_class->kref); | 229 | kref_init(&ep_class->kref); |
230 | ep_class->class = class_create(THIS_MODULE, "usb_endpoint"); | 230 | ep_class->class = class_create(THIS_MODULE, "usb_endpoint"); |
231 | if (IS_ERR(ep_class->class)) { | 231 | if (IS_ERR(ep_class->class)) { |
232 | result = IS_ERR(ep_class->class); | 232 | result = PTR_ERR(ep_class->class); |
233 | goto class_create_error; | 233 | goto class_create_error; |
234 | } | 234 | } |
235 | 235 | ||
diff --git a/drivers/usb/core/generic.c b/drivers/usb/core/generic.c index b531a4fd30c2..9bbcb20e2d94 100644 --- a/drivers/usb/core/generic.c +++ b/drivers/usb/core/generic.c | |||
@@ -184,7 +184,7 @@ static void generic_disconnect(struct usb_device *udev) | |||
184 | /* if this is only an unbind, not a physical disconnect, then | 184 | /* if this is only an unbind, not a physical disconnect, then |
185 | * unconfigure the device */ | 185 | * unconfigure the device */ |
186 | if (udev->actconfig) | 186 | if (udev->actconfig) |
187 | usb_set_configuration(udev, 0); | 187 | usb_set_configuration(udev, -1); |
188 | 188 | ||
189 | usb_remove_sysfs_dev_files(udev); | 189 | usb_remove_sysfs_dev_files(udev); |
190 | } | 190 | } |
diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c index b26c19e8d19f..40cf882293e6 100644 --- a/drivers/usb/core/hcd.c +++ b/drivers/usb/core/hcd.c | |||
@@ -37,6 +37,7 @@ | |||
37 | #include <asm/irq.h> | 37 | #include <asm/irq.h> |
38 | #include <asm/byteorder.h> | 38 | #include <asm/byteorder.h> |
39 | #include <linux/platform_device.h> | 39 | #include <linux/platform_device.h> |
40 | #include <linux/workqueue.h> | ||
40 | 41 | ||
41 | #include <linux/usb.h> | 42 | #include <linux/usb.h> |
42 | 43 | ||
@@ -544,6 +545,8 @@ void usb_hcd_poll_rh_status(struct usb_hcd *hcd) | |||
544 | unsigned long flags; | 545 | unsigned long flags; |
545 | char buffer[4]; /* Any root hubs with > 31 ports? */ | 546 | char buffer[4]; /* Any root hubs with > 31 ports? */ |
546 | 547 | ||
548 | if (unlikely(!hcd->rh_registered)) | ||
549 | return; | ||
547 | if (!hcd->uses_new_polling && !hcd->status_urb) | 550 | if (!hcd->uses_new_polling && !hcd->status_urb) |
548 | return; | 551 | return; |
549 | 552 | ||
@@ -1296,14 +1299,26 @@ int hcd_bus_resume (struct usb_bus *bus) | |||
1296 | return status; | 1299 | return status; |
1297 | } | 1300 | } |
1298 | 1301 | ||
1302 | /* Workqueue routine for root-hub remote wakeup */ | ||
1303 | static void hcd_resume_work(struct work_struct *work) | ||
1304 | { | ||
1305 | struct usb_hcd *hcd = container_of(work, struct usb_hcd, wakeup_work); | ||
1306 | struct usb_device *udev = hcd->self.root_hub; | ||
1307 | |||
1308 | usb_lock_device(udev); | ||
1309 | usb_mark_last_busy(udev); | ||
1310 | usb_external_resume_device(udev); | ||
1311 | usb_unlock_device(udev); | ||
1312 | } | ||
1313 | |||
1299 | /** | 1314 | /** |
1300 | * usb_hcd_resume_root_hub - called by HCD to resume its root hub | 1315 | * usb_hcd_resume_root_hub - called by HCD to resume its root hub |
1301 | * @hcd: host controller for this root hub | 1316 | * @hcd: host controller for this root hub |
1302 | * | 1317 | * |
1303 | * The USB host controller calls this function when its root hub is | 1318 | * The USB host controller calls this function when its root hub is |
1304 | * suspended (with the remote wakeup feature enabled) and a remote | 1319 | * suspended (with the remote wakeup feature enabled) and a remote |
1305 | * wakeup request is received. It queues a request for khubd to | 1320 | * wakeup request is received. The routine submits a workqueue request |
1306 | * resume the root hub (that is, manage its downstream ports again). | 1321 | * to resume the root hub (that is, manage its downstream ports again). |
1307 | */ | 1322 | */ |
1308 | void usb_hcd_resume_root_hub (struct usb_hcd *hcd) | 1323 | void usb_hcd_resume_root_hub (struct usb_hcd *hcd) |
1309 | { | 1324 | { |
@@ -1311,7 +1326,7 @@ void usb_hcd_resume_root_hub (struct usb_hcd *hcd) | |||
1311 | 1326 | ||
1312 | spin_lock_irqsave (&hcd_root_hub_lock, flags); | 1327 | spin_lock_irqsave (&hcd_root_hub_lock, flags); |
1313 | if (hcd->rh_registered) | 1328 | if (hcd->rh_registered) |
1314 | usb_resume_root_hub (hcd->self.root_hub); | 1329 | queue_work(ksuspend_usb_wq, &hcd->wakeup_work); |
1315 | spin_unlock_irqrestore (&hcd_root_hub_lock, flags); | 1330 | spin_unlock_irqrestore (&hcd_root_hub_lock, flags); |
1316 | } | 1331 | } |
1317 | EXPORT_SYMBOL_GPL(usb_hcd_resume_root_hub); | 1332 | EXPORT_SYMBOL_GPL(usb_hcd_resume_root_hub); |
@@ -1500,6 +1515,9 @@ struct usb_hcd *usb_create_hcd (const struct hc_driver *driver, | |||
1500 | init_timer(&hcd->rh_timer); | 1515 | init_timer(&hcd->rh_timer); |
1501 | hcd->rh_timer.function = rh_timer_func; | 1516 | hcd->rh_timer.function = rh_timer_func; |
1502 | hcd->rh_timer.data = (unsigned long) hcd; | 1517 | hcd->rh_timer.data = (unsigned long) hcd; |
1518 | #ifdef CONFIG_PM | ||
1519 | INIT_WORK(&hcd->wakeup_work, hcd_resume_work); | ||
1520 | #endif | ||
1503 | 1521 | ||
1504 | hcd->driver = driver; | 1522 | hcd->driver = driver; |
1505 | hcd->product_desc = (driver->product_desc) ? driver->product_desc : | 1523 | hcd->product_desc = (driver->product_desc) ? driver->product_desc : |
@@ -1666,16 +1684,20 @@ void usb_remove_hcd(struct usb_hcd *hcd) | |||
1666 | hcd->rh_registered = 0; | 1684 | hcd->rh_registered = 0; |
1667 | spin_unlock_irq (&hcd_root_hub_lock); | 1685 | spin_unlock_irq (&hcd_root_hub_lock); |
1668 | 1686 | ||
1687 | #ifdef CONFIG_PM | ||
1688 | flush_workqueue(ksuspend_usb_wq); | ||
1689 | #endif | ||
1690 | |||
1669 | mutex_lock(&usb_bus_list_lock); | 1691 | mutex_lock(&usb_bus_list_lock); |
1670 | usb_disconnect(&hcd->self.root_hub); | 1692 | usb_disconnect(&hcd->self.root_hub); |
1671 | mutex_unlock(&usb_bus_list_lock); | 1693 | mutex_unlock(&usb_bus_list_lock); |
1672 | 1694 | ||
1673 | hcd->poll_rh = 0; | ||
1674 | del_timer_sync(&hcd->rh_timer); | ||
1675 | |||
1676 | hcd->driver->stop(hcd); | 1695 | hcd->driver->stop(hcd); |
1677 | hcd->state = HC_STATE_HALT; | 1696 | hcd->state = HC_STATE_HALT; |
1678 | 1697 | ||
1698 | hcd->poll_rh = 0; | ||
1699 | del_timer_sync(&hcd->rh_timer); | ||
1700 | |||
1679 | if (hcd->irq >= 0) | 1701 | if (hcd->irq >= 0) |
1680 | free_irq(hcd->irq, hcd); | 1702 | free_irq(hcd->irq, hcd); |
1681 | usb_deregister_bus(&hcd->self); | 1703 | usb_deregister_bus(&hcd->self); |
diff --git a/drivers/usb/core/hcd.h b/drivers/usb/core/hcd.h index 2a269ca20517..ef50fa494e47 100644 --- a/drivers/usb/core/hcd.h +++ b/drivers/usb/core/hcd.h | |||
@@ -68,6 +68,9 @@ struct usb_hcd { | |||
68 | 68 | ||
69 | struct timer_list rh_timer; /* drives root-hub polling */ | 69 | struct timer_list rh_timer; /* drives root-hub polling */ |
70 | struct urb *status_urb; /* the current status urb */ | 70 | struct urb *status_urb; /* the current status urb */ |
71 | #ifdef CONFIG_PM | ||
72 | struct work_struct wakeup_work; /* for remote wakeup */ | ||
73 | #endif | ||
71 | 74 | ||
72 | /* | 75 | /* |
73 | * hardware info/state | 76 | * hardware info/state |
diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c index 590ec82d0515..bde29ab2b504 100644 --- a/drivers/usb/core/hub.c +++ b/drivers/usb/core/hub.c | |||
@@ -44,6 +44,7 @@ struct usb_hub { | |||
44 | struct usb_hub_status hub; | 44 | struct usb_hub_status hub; |
45 | struct usb_port_status port; | 45 | struct usb_port_status port; |
46 | } *status; /* buffer for status reports */ | 46 | } *status; /* buffer for status reports */ |
47 | struct mutex status_mutex; /* for the status buffer */ | ||
47 | 48 | ||
48 | int error; /* last reported error */ | 49 | int error; /* last reported error */ |
49 | int nerrors; /* track consecutive errors */ | 50 | int nerrors; /* track consecutive errors */ |
@@ -118,8 +119,7 @@ MODULE_PARM_DESC(use_both_schemes, | |||
118 | "first one fails"); | 119 | "first one fails"); |
119 | 120 | ||
120 | 121 | ||
121 | #ifdef DEBUG | 122 | static inline char *portspeed(int portstatus) |
122 | static inline char *portspeed (int portstatus) | ||
123 | { | 123 | { |
124 | if (portstatus & (1 << USB_PORT_FEAT_HIGHSPEED)) | 124 | if (portstatus & (1 << USB_PORT_FEAT_HIGHSPEED)) |
125 | return "480 Mb/s"; | 125 | return "480 Mb/s"; |
@@ -128,7 +128,6 @@ static inline char *portspeed (int portstatus) | |||
128 | else | 128 | else |
129 | return "12 Mb/s"; | 129 | return "12 Mb/s"; |
130 | } | 130 | } |
131 | #endif | ||
132 | 131 | ||
133 | /* Note that hdev or one of its children must be locked! */ | 132 | /* Note that hdev or one of its children must be locked! */ |
134 | static inline struct usb_hub *hdev_to_hub(struct usb_device *hdev) | 133 | static inline struct usb_hub *hdev_to_hub(struct usb_device *hdev) |
@@ -535,6 +534,7 @@ static int hub_hub_status(struct usb_hub *hub, | |||
535 | { | 534 | { |
536 | int ret; | 535 | int ret; |
537 | 536 | ||
537 | mutex_lock(&hub->status_mutex); | ||
538 | ret = get_hub_status(hub->hdev, &hub->status->hub); | 538 | ret = get_hub_status(hub->hdev, &hub->status->hub); |
539 | if (ret < 0) | 539 | if (ret < 0) |
540 | dev_err (hub->intfdev, | 540 | dev_err (hub->intfdev, |
@@ -544,6 +544,7 @@ static int hub_hub_status(struct usb_hub *hub, | |||
544 | *change = le16_to_cpu(hub->status->hub.wHubChange); | 544 | *change = le16_to_cpu(hub->status->hub.wHubChange); |
545 | ret = 0; | 545 | ret = 0; |
546 | } | 546 | } |
547 | mutex_unlock(&hub->status_mutex); | ||
547 | return ret; | 548 | return ret; |
548 | } | 549 | } |
549 | 550 | ||
@@ -617,6 +618,7 @@ static int hub_configure(struct usb_hub *hub, | |||
617 | ret = -ENOMEM; | 618 | ret = -ENOMEM; |
618 | goto fail; | 619 | goto fail; |
619 | } | 620 | } |
621 | mutex_init(&hub->status_mutex); | ||
620 | 622 | ||
621 | hub->descriptor = kmalloc(sizeof(*hub->descriptor), GFP_KERNEL); | 623 | hub->descriptor = kmalloc(sizeof(*hub->descriptor), GFP_KERNEL); |
622 | if (!hub->descriptor) { | 624 | if (!hub->descriptor) { |
@@ -1277,11 +1279,8 @@ int usb_new_device(struct usb_device *udev) | |||
1277 | { | 1279 | { |
1278 | int err; | 1280 | int err; |
1279 | 1281 | ||
1280 | /* Lock ourself into memory in order to keep a probe sequence | 1282 | /* Determine quirks */ |
1281 | * sleeping in a new thread from allowing us to be unloaded. | 1283 | usb_detect_quirks(udev); |
1282 | */ | ||
1283 | if (!try_module_get(THIS_MODULE)) | ||
1284 | return -EINVAL; | ||
1285 | 1284 | ||
1286 | err = usb_get_configuration(udev); | 1285 | err = usb_get_configuration(udev); |
1287 | if (err < 0) { | 1286 | if (err < 0) { |
@@ -1368,11 +1367,15 @@ int usb_new_device(struct usb_device *udev) | |||
1368 | } | 1367 | } |
1369 | #endif | 1368 | #endif |
1370 | 1369 | ||
1370 | /* export the usbdev device-node for libusb */ | ||
1371 | udev->dev.devt = MKDEV(USB_DEVICE_MAJOR, | ||
1372 | (((udev->bus->busnum-1) * 128) + (udev->devnum-1))); | ||
1373 | |||
1371 | /* Register the device. The device driver is responsible | 1374 | /* Register the device. The device driver is responsible |
1372 | * for adding the device files to usbfs and sysfs and for | 1375 | * for adding the device files to sysfs and for configuring |
1373 | * configuring the device. | 1376 | * the device. |
1374 | */ | 1377 | */ |
1375 | err = device_add (&udev->dev); | 1378 | err = device_add(&udev->dev); |
1376 | if (err) { | 1379 | if (err) { |
1377 | dev_err(&udev->dev, "can't device_add, error %d\n", err); | 1380 | dev_err(&udev->dev, "can't device_add, error %d\n", err); |
1378 | goto fail; | 1381 | goto fail; |
@@ -1383,7 +1386,6 @@ int usb_new_device(struct usb_device *udev) | |||
1383 | usb_autoresume_device(udev->parent); | 1386 | usb_autoresume_device(udev->parent); |
1384 | 1387 | ||
1385 | exit: | 1388 | exit: |
1386 | module_put(THIS_MODULE); | ||
1387 | return err; | 1389 | return err; |
1388 | 1390 | ||
1389 | fail: | 1391 | fail: |
@@ -1396,6 +1398,7 @@ static int hub_port_status(struct usb_hub *hub, int port1, | |||
1396 | { | 1398 | { |
1397 | int ret; | 1399 | int ret; |
1398 | 1400 | ||
1401 | mutex_lock(&hub->status_mutex); | ||
1399 | ret = get_port_status(hub->hdev, port1, &hub->status->port); | 1402 | ret = get_port_status(hub->hdev, port1, &hub->status->port); |
1400 | if (ret < 4) { | 1403 | if (ret < 4) { |
1401 | dev_err (hub->intfdev, | 1404 | dev_err (hub->intfdev, |
@@ -1407,6 +1410,7 @@ static int hub_port_status(struct usb_hub *hub, int port1, | |||
1407 | *change = le16_to_cpu(hub->status->port.wPortChange); | 1410 | *change = le16_to_cpu(hub->status->port.wPortChange); |
1408 | ret = 0; | 1411 | ret = 0; |
1409 | } | 1412 | } |
1413 | mutex_unlock(&hub->status_mutex); | ||
1410 | return ret; | 1414 | return ret; |
1411 | } | 1415 | } |
1412 | 1416 | ||
@@ -1855,12 +1859,8 @@ static int remote_wakeup(struct usb_device *udev) | |||
1855 | usb_lock_device(udev); | 1859 | usb_lock_device(udev); |
1856 | if (udev->state == USB_STATE_SUSPENDED) { | 1860 | if (udev->state == USB_STATE_SUSPENDED) { |
1857 | dev_dbg(&udev->dev, "usb %sresume\n", "wakeup-"); | 1861 | dev_dbg(&udev->dev, "usb %sresume\n", "wakeup-"); |
1858 | status = usb_autoresume_device(udev); | 1862 | usb_mark_last_busy(udev); |
1859 | 1863 | status = usb_external_resume_device(udev); | |
1860 | /* Give the interface drivers a chance to do something, | ||
1861 | * then autosuspend the device again. */ | ||
1862 | if (status == 0) | ||
1863 | usb_autosuspend_device(udev); | ||
1864 | } | 1864 | } |
1865 | usb_unlock_device(udev); | 1865 | usb_unlock_device(udev); |
1866 | return status; | 1866 | return status; |
@@ -1904,6 +1904,7 @@ static int hub_suspend(struct usb_interface *intf, pm_message_t msg) | |||
1904 | struct usb_hub *hub = usb_get_intfdata (intf); | 1904 | struct usb_hub *hub = usb_get_intfdata (intf); |
1905 | struct usb_device *hdev = hub->hdev; | 1905 | struct usb_device *hdev = hub->hdev; |
1906 | unsigned port1; | 1906 | unsigned port1; |
1907 | int status = 0; | ||
1907 | 1908 | ||
1908 | /* fail if children aren't already suspended */ | 1909 | /* fail if children aren't already suspended */ |
1909 | for (port1 = 1; port1 <= hdev->maxchild; port1++) { | 1910 | for (port1 = 1; port1 <= hdev->maxchild; port1++) { |
@@ -1927,24 +1928,18 @@ static int hub_suspend(struct usb_interface *intf, pm_message_t msg) | |||
1927 | 1928 | ||
1928 | dev_dbg(&intf->dev, "%s\n", __FUNCTION__); | 1929 | dev_dbg(&intf->dev, "%s\n", __FUNCTION__); |
1929 | 1930 | ||
1931 | /* stop khubd and related activity */ | ||
1932 | hub_quiesce(hub); | ||
1933 | |||
1930 | /* "global suspend" of the downstream HC-to-USB interface */ | 1934 | /* "global suspend" of the downstream HC-to-USB interface */ |
1931 | if (!hdev->parent) { | 1935 | if (!hdev->parent) { |
1932 | struct usb_bus *bus = hdev->bus; | 1936 | status = hcd_bus_suspend(hdev->bus); |
1933 | if (bus) { | 1937 | if (status != 0) { |
1934 | int status = hcd_bus_suspend (bus); | 1938 | dev_dbg(&hdev->dev, "'global' suspend %d\n", status); |
1935 | 1939 | hub_activate(hub); | |
1936 | if (status != 0) { | 1940 | } |
1937 | dev_dbg(&hdev->dev, "'global' suspend %d\n", | ||
1938 | status); | ||
1939 | return status; | ||
1940 | } | ||
1941 | } else | ||
1942 | return -EOPNOTSUPP; | ||
1943 | } | 1941 | } |
1944 | 1942 | return status; | |
1945 | /* stop khubd and related activity */ | ||
1946 | hub_quiesce(hub); | ||
1947 | return 0; | ||
1948 | } | 1943 | } |
1949 | 1944 | ||
1950 | static int hub_resume(struct usb_interface *intf) | 1945 | static int hub_resume(struct usb_interface *intf) |
@@ -1989,13 +1984,6 @@ static inline int remote_wakeup(struct usb_device *udev) | |||
1989 | #define hub_resume NULL | 1984 | #define hub_resume NULL |
1990 | #endif | 1985 | #endif |
1991 | 1986 | ||
1992 | void usb_resume_root_hub(struct usb_device *hdev) | ||
1993 | { | ||
1994 | struct usb_hub *hub = hdev_to_hub(hdev); | ||
1995 | |||
1996 | kick_khubd(hub); | ||
1997 | } | ||
1998 | |||
1999 | 1987 | ||
2000 | /* USB 2.0 spec, 7.1.7.3 / fig 7-29: | 1988 | /* USB 2.0 spec, 7.1.7.3 / fig 7-29: |
2001 | * | 1989 | * |
@@ -2439,7 +2427,7 @@ static void hub_port_connect_change(struct usb_hub *hub, int port1, | |||
2439 | 2427 | ||
2440 | if (portchange & USB_PORT_STAT_C_CONNECTION) { | 2428 | if (portchange & USB_PORT_STAT_C_CONNECTION) { |
2441 | status = hub_port_debounce(hub, port1); | 2429 | status = hub_port_debounce(hub, port1); |
2442 | if (status < 0) { | 2430 | if (status < 0 && printk_ratelimit()) { |
2443 | dev_err (hub_dev, | 2431 | dev_err (hub_dev, |
2444 | "connect-debounce failed, port %d disabled\n", | 2432 | "connect-debounce failed, port %d disabled\n", |
2445 | port1); | 2433 | port1); |
diff --git a/drivers/usb/core/inode.c b/drivers/usb/core/inode.c index 11dad22da41c..cddfc62c4611 100644 --- a/drivers/usb/core/inode.c +++ b/drivers/usb/core/inode.c | |||
@@ -662,7 +662,7 @@ static void usbfs_add_device(struct usb_device *dev) | |||
662 | sprintf (name, "%03d", dev->devnum); | 662 | sprintf (name, "%03d", dev->devnum); |
663 | dev->usbfs_dentry = fs_create_file (name, devmode | S_IFREG, | 663 | dev->usbfs_dentry = fs_create_file (name, devmode | S_IFREG, |
664 | dev->bus->usbfs_dentry, dev, | 664 | dev->bus->usbfs_dentry, dev, |
665 | &usbfs_device_file_operations, | 665 | &usbdev_file_operations, |
666 | devuid, devgid); | 666 | devuid, devgid); |
667 | if (dev->usbfs_dentry == NULL) { | 667 | if (dev->usbfs_dentry == NULL) { |
668 | err ("error creating usbfs device entry"); | 668 | err ("error creating usbfs device entry"); |
diff --git a/drivers/usb/core/message.c b/drivers/usb/core/message.c index 8aca3574c2b5..b7434787db5f 100644 --- a/drivers/usb/core/message.c +++ b/drivers/usb/core/message.c | |||
@@ -11,6 +11,7 @@ | |||
11 | #include <linux/timer.h> | 11 | #include <linux/timer.h> |
12 | #include <linux/ctype.h> | 12 | #include <linux/ctype.h> |
13 | #include <linux/device.h> | 13 | #include <linux/device.h> |
14 | #include <linux/usb/quirks.h> | ||
14 | #include <asm/byteorder.h> | 15 | #include <asm/byteorder.h> |
15 | #include <asm/scatterlist.h> | 16 | #include <asm/scatterlist.h> |
16 | 17 | ||
@@ -220,10 +221,15 @@ int usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe, | |||
220 | 221 | ||
221 | if ((ep->desc.bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) == | 222 | if ((ep->desc.bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) == |
222 | USB_ENDPOINT_XFER_INT) { | 223 | USB_ENDPOINT_XFER_INT) { |
224 | int interval; | ||
225 | |||
226 | if (usb_dev->speed == USB_SPEED_HIGH) | ||
227 | interval = 1 << min(15, ep->desc.bInterval - 1); | ||
228 | else | ||
229 | interval = ep->desc.bInterval; | ||
223 | pipe = (pipe & ~(3 << 30)) | (PIPE_INTERRUPT << 30); | 230 | pipe = (pipe & ~(3 << 30)) | (PIPE_INTERRUPT << 30); |
224 | usb_fill_int_urb(urb, usb_dev, pipe, data, len, | 231 | usb_fill_int_urb(urb, usb_dev, pipe, data, len, |
225 | usb_api_blocking_completion, NULL, | 232 | usb_api_blocking_completion, NULL, interval); |
226 | ep->desc.bInterval); | ||
227 | } else | 233 | } else |
228 | usb_fill_bulk_urb(urb, usb_dev, pipe, data, len, | 234 | usb_fill_bulk_urb(urb, usb_dev, pipe, data, len, |
229 | usb_api_blocking_completion, NULL); | 235 | usb_api_blocking_completion, NULL); |
@@ -406,10 +412,24 @@ int usb_sg_init ( | |||
406 | io->urbs [i]->status = -EINPROGRESS; | 412 | io->urbs [i]->status = -EINPROGRESS; |
407 | io->urbs [i]->actual_length = 0; | 413 | io->urbs [i]->actual_length = 0; |
408 | 414 | ||
415 | /* | ||
416 | * Some systems need to revert to PIO when DMA is temporarily | ||
417 | * unavailable. For their sakes, both transfer_buffer and | ||
418 | * transfer_dma are set when possible. However this can only | ||
419 | * work on systems without HIGHMEM, since DMA buffers located | ||
420 | * in high memory are not directly addressable by the CPU for | ||
421 | * PIO ... so when HIGHMEM is in use, transfer_buffer is NULL | ||
422 | * to prevent stale pointers and to help spot bugs. | ||
423 | */ | ||
409 | if (dma) { | 424 | if (dma) { |
410 | /* hc may use _only_ transfer_dma */ | ||
411 | io->urbs [i]->transfer_dma = sg_dma_address (sg + i); | 425 | io->urbs [i]->transfer_dma = sg_dma_address (sg + i); |
412 | len = sg_dma_len (sg + i); | 426 | len = sg_dma_len (sg + i); |
427 | #ifdef CONFIG_HIGHMEM | ||
428 | io->urbs[i]->transfer_buffer = NULL; | ||
429 | #else | ||
430 | io->urbs[i]->transfer_buffer = | ||
431 | page_address(sg[i].page) + sg[i].offset; | ||
432 | #endif | ||
413 | } else { | 433 | } else { |
414 | /* hc may use _only_ transfer_buffer */ | 434 | /* hc may use _only_ transfer_buffer */ |
415 | io->urbs [i]->transfer_buffer = | 435 | io->urbs [i]->transfer_buffer = |
@@ -685,7 +705,10 @@ static int usb_string_sub(struct usb_device *dev, unsigned int langid, | |||
685 | 705 | ||
686 | /* Try to read the string descriptor by asking for the maximum | 706 | /* Try to read the string descriptor by asking for the maximum |
687 | * possible number of bytes */ | 707 | * possible number of bytes */ |
688 | rc = usb_get_string(dev, langid, index, buf, 255); | 708 | if (dev->quirks & USB_QUIRK_STRING_FETCH_255) |
709 | rc = -EIO; | ||
710 | else | ||
711 | rc = usb_get_string(dev, langid, index, buf, 255); | ||
689 | 712 | ||
690 | /* If that failed try to read the descriptor length, then | 713 | /* If that failed try to read the descriptor length, then |
691 | * ask for just that many bytes */ | 714 | * ask for just that many bytes */ |
@@ -1296,7 +1319,7 @@ int usb_reset_configuration(struct usb_device *dev) | |||
1296 | return 0; | 1319 | return 0; |
1297 | } | 1320 | } |
1298 | 1321 | ||
1299 | static void release_interface(struct device *dev) | 1322 | void usb_release_interface(struct device *dev) |
1300 | { | 1323 | { |
1301 | struct usb_interface *intf = to_usb_interface(dev); | 1324 | struct usb_interface *intf = to_usb_interface(dev); |
1302 | struct usb_interface_cache *intfc = | 1325 | struct usb_interface_cache *intfc = |
@@ -1306,6 +1329,67 @@ static void release_interface(struct device *dev) | |||
1306 | kfree(intf); | 1329 | kfree(intf); |
1307 | } | 1330 | } |
1308 | 1331 | ||
1332 | #ifdef CONFIG_HOTPLUG | ||
1333 | static int usb_if_uevent(struct device *dev, char **envp, int num_envp, | ||
1334 | char *buffer, int buffer_size) | ||
1335 | { | ||
1336 | struct usb_device *usb_dev; | ||
1337 | struct usb_interface *intf; | ||
1338 | struct usb_host_interface *alt; | ||
1339 | int i = 0; | ||
1340 | int length = 0; | ||
1341 | |||
1342 | if (!dev) | ||
1343 | return -ENODEV; | ||
1344 | |||
1345 | /* driver is often null here; dev_dbg() would oops */ | ||
1346 | pr_debug ("usb %s: uevent\n", dev->bus_id); | ||
1347 | |||
1348 | intf = to_usb_interface(dev); | ||
1349 | usb_dev = interface_to_usbdev(intf); | ||
1350 | alt = intf->cur_altsetting; | ||
1351 | |||
1352 | if (add_uevent_var(envp, num_envp, &i, | ||
1353 | buffer, buffer_size, &length, | ||
1354 | "INTERFACE=%d/%d/%d", | ||
1355 | alt->desc.bInterfaceClass, | ||
1356 | alt->desc.bInterfaceSubClass, | ||
1357 | alt->desc.bInterfaceProtocol)) | ||
1358 | return -ENOMEM; | ||
1359 | |||
1360 | if (add_uevent_var(envp, num_envp, &i, | ||
1361 | buffer, buffer_size, &length, | ||
1362 | "MODALIAS=usb:v%04Xp%04Xd%04Xdc%02Xdsc%02Xdp%02Xic%02Xisc%02Xip%02X", | ||
1363 | le16_to_cpu(usb_dev->descriptor.idVendor), | ||
1364 | le16_to_cpu(usb_dev->descriptor.idProduct), | ||
1365 | le16_to_cpu(usb_dev->descriptor.bcdDevice), | ||
1366 | usb_dev->descriptor.bDeviceClass, | ||
1367 | usb_dev->descriptor.bDeviceSubClass, | ||
1368 | usb_dev->descriptor.bDeviceProtocol, | ||
1369 | alt->desc.bInterfaceClass, | ||
1370 | alt->desc.bInterfaceSubClass, | ||
1371 | alt->desc.bInterfaceProtocol)) | ||
1372 | return -ENOMEM; | ||
1373 | |||
1374 | envp[i] = NULL; | ||
1375 | return 0; | ||
1376 | } | ||
1377 | |||
1378 | #else | ||
1379 | |||
1380 | static int usb_if_uevent(struct device *dev, char **envp, | ||
1381 | int num_envp, char *buffer, int buffer_size) | ||
1382 | { | ||
1383 | return -ENODEV; | ||
1384 | } | ||
1385 | #endif /* CONFIG_HOTPLUG */ | ||
1386 | |||
1387 | struct device_type usb_if_device_type = { | ||
1388 | .name = "usb_interface", | ||
1389 | .release = usb_release_interface, | ||
1390 | .uevent = usb_if_uevent, | ||
1391 | }; | ||
1392 | |||
1309 | /* | 1393 | /* |
1310 | * usb_set_configuration - Makes a particular device setting be current | 1394 | * usb_set_configuration - Makes a particular device setting be current |
1311 | * @dev: the device whose configuration is being updated | 1395 | * @dev: the device whose configuration is being updated |
@@ -1316,6 +1400,14 @@ static void release_interface(struct device *dev) | |||
1316 | * use this kind of configurability; many devices only have one | 1400 | * use this kind of configurability; many devices only have one |
1317 | * configuration. | 1401 | * configuration. |
1318 | * | 1402 | * |
1403 | * @configuration is the value of the configuration to be installed. | ||
1404 | * According to the USB spec (e.g. section 9.1.1.5), configuration values | ||
1405 | * must be non-zero; a value of zero indicates that the device in | ||
1406 | * unconfigured. However some devices erroneously use 0 as one of their | ||
1407 | * configuration values. To help manage such devices, this routine will | ||
1408 | * accept @configuration = -1 as indicating the device should be put in | ||
1409 | * an unconfigured state. | ||
1410 | * | ||
1319 | * USB device configurations may affect Linux interoperability, | 1411 | * USB device configurations may affect Linux interoperability, |
1320 | * power consumption and the functionality available. For example, | 1412 | * power consumption and the functionality available. For example, |
1321 | * the default configuration is limited to using 100mA of bus power, | 1413 | * the default configuration is limited to using 100mA of bus power, |
@@ -1332,7 +1424,7 @@ static void release_interface(struct device *dev) | |||
1332 | * | 1424 | * |
1333 | * This call is synchronous. The calling context must be able to sleep, | 1425 | * This call is synchronous. The calling context must be able to sleep, |
1334 | * must own the device lock, and must not hold the driver model's USB | 1426 | * must own the device lock, and must not hold the driver model's USB |
1335 | * bus rwsem; usb device driver probe() methods cannot use this routine. | 1427 | * bus mutex; usb device driver probe() methods cannot use this routine. |
1336 | * | 1428 | * |
1337 | * Returns zero on success, or else the status code returned by the | 1429 | * Returns zero on success, or else the status code returned by the |
1338 | * underlying call that failed. On successful completion, each interface | 1430 | * underlying call that failed. On successful completion, each interface |
@@ -1347,10 +1439,15 @@ int usb_set_configuration(struct usb_device *dev, int configuration) | |||
1347 | struct usb_interface **new_interfaces = NULL; | 1439 | struct usb_interface **new_interfaces = NULL; |
1348 | int n, nintf; | 1440 | int n, nintf; |
1349 | 1441 | ||
1350 | for (i = 0; i < dev->descriptor.bNumConfigurations; i++) { | 1442 | if (configuration == -1) |
1351 | if (dev->config[i].desc.bConfigurationValue == configuration) { | 1443 | configuration = 0; |
1352 | cp = &dev->config[i]; | 1444 | else { |
1353 | break; | 1445 | for (i = 0; i < dev->descriptor.bNumConfigurations; i++) { |
1446 | if (dev->config[i].desc.bConfigurationValue == | ||
1447 | configuration) { | ||
1448 | cp = &dev->config[i]; | ||
1449 | break; | ||
1450 | } | ||
1354 | } | 1451 | } |
1355 | } | 1452 | } |
1356 | if ((!cp && configuration != 0)) | 1453 | if ((!cp && configuration != 0)) |
@@ -1359,6 +1456,7 @@ int usb_set_configuration(struct usb_device *dev, int configuration) | |||
1359 | /* The USB spec says configuration 0 means unconfigured. | 1456 | /* The USB spec says configuration 0 means unconfigured. |
1360 | * But if a device includes a configuration numbered 0, | 1457 | * But if a device includes a configuration numbered 0, |
1361 | * we will accept it as a correctly configured state. | 1458 | * we will accept it as a correctly configured state. |
1459 | * Use -1 if you really want to unconfigure the device. | ||
1362 | */ | 1460 | */ |
1363 | if (cp && configuration == 0) | 1461 | if (cp && configuration == 0) |
1364 | dev_warn(&dev->dev, "config 0 descriptor??\n"); | 1462 | dev_warn(&dev->dev, "config 0 descriptor??\n"); |
@@ -1455,8 +1553,8 @@ free_interfaces: | |||
1455 | intf->dev.parent = &dev->dev; | 1553 | intf->dev.parent = &dev->dev; |
1456 | intf->dev.driver = NULL; | 1554 | intf->dev.driver = NULL; |
1457 | intf->dev.bus = &usb_bus_type; | 1555 | intf->dev.bus = &usb_bus_type; |
1556 | intf->dev.type = &usb_if_device_type; | ||
1458 | intf->dev.dma_mask = dev->dev.dma_mask; | 1557 | intf->dev.dma_mask = dev->dev.dma_mask; |
1459 | intf->dev.release = release_interface; | ||
1460 | device_initialize (&intf->dev); | 1558 | device_initialize (&intf->dev); |
1461 | mark_quiesced(intf); | 1559 | mark_quiesced(intf); |
1462 | sprintf (&intf->dev.bus_id[0], "%d-%s:%d.%d", | 1560 | sprintf (&intf->dev.bus_id[0], "%d-%s:%d.%d", |
diff --git a/drivers/usb/core/otg_whitelist.h b/drivers/usb/core/otg_whitelist.h index 627a5a2fc9cf..7f31a495a25d 100644 --- a/drivers/usb/core/otg_whitelist.h +++ b/drivers/usb/core/otg_whitelist.h | |||
@@ -31,7 +31,7 @@ static struct usb_device_id whitelist_table [] = { | |||
31 | { USB_DEVICE_INFO(7, 1, 3) }, | 31 | { USB_DEVICE_INFO(7, 1, 3) }, |
32 | #endif | 32 | #endif |
33 | 33 | ||
34 | #ifdef CONFIG_USB_CDCETHER | 34 | #ifdef CONFIG_USB_NET_CDCETHER |
35 | /* Linux-USB CDC Ethernet gadget */ | 35 | /* Linux-USB CDC Ethernet gadget */ |
36 | { USB_DEVICE(0x0525, 0xa4a1), }, | 36 | { USB_DEVICE(0x0525, 0xa4a1), }, |
37 | /* Linux-USB CDC Ethernet + RNDIS gadget */ | 37 | /* Linux-USB CDC Ethernet + RNDIS gadget */ |
diff --git a/drivers/usb/core/quirks.c b/drivers/usb/core/quirks.c new file mode 100644 index 000000000000..739f520908aa --- /dev/null +++ b/drivers/usb/core/quirks.c | |||
@@ -0,0 +1,78 @@ | |||
1 | /* | ||
2 | * USB device quirk handling logic and table | ||
3 | * | ||
4 | * Copyright (c) 2007 Oliver Neukum | ||
5 | * Copyright (c) 2007 Greg Kroah-Hartman <gregkh@suse.de> | ||
6 | * | ||
7 | * This program is free software; you can redistribute it and/or modify it | ||
8 | * under the terms of the GNU General Public License as published by the Free | ||
9 | * Software Foundation, version 2. | ||
10 | * | ||
11 | * | ||
12 | */ | ||
13 | |||
14 | #include <linux/usb.h> | ||
15 | #include <linux/usb/quirks.h> | ||
16 | #include "usb.h" | ||
17 | |||
18 | /* List of quirky USB devices. Please keep this list ordered by: | ||
19 | * 1) Vendor ID | ||
20 | * 2) Product ID | ||
21 | * 3) Class ID | ||
22 | * | ||
23 | * as we want specific devices to be overridden first, and only after that, any | ||
24 | * class specific quirks. | ||
25 | * | ||
26 | * Right now the logic aborts if it finds a valid device in the table, we might | ||
27 | * want to change that in the future if it turns out that a whole class of | ||
28 | * devices is broken... | ||
29 | */ | ||
30 | static const struct usb_device_id usb_quirk_list[] = { | ||
31 | /* HP 5300/5370C scanner */ | ||
32 | { USB_DEVICE(0x03f0, 0x0701), .driver_info = USB_QUIRK_STRING_FETCH_255 }, | ||
33 | /* Seiko Epson Corp - Perfection 1670 */ | ||
34 | { USB_DEVICE(0x04b8, 0x011f), .driver_info = USB_QUIRK_NO_AUTOSUSPEND }, | ||
35 | /* Elsa MicroLink 56k (V.250) */ | ||
36 | { USB_DEVICE(0x05cc, 0x2267), .driver_info = USB_QUIRK_NO_AUTOSUSPEND }, | ||
37 | |||
38 | { } /* terminating entry must be last */ | ||
39 | }; | ||
40 | |||
41 | static void usb_autosuspend_quirk(struct usb_device *udev) | ||
42 | { | ||
43 | #ifdef CONFIG_USB_SUSPEND | ||
44 | /* disable autosuspend, but allow the user to re-enable it via sysfs */ | ||
45 | udev->autosuspend_disabled = 1; | ||
46 | #endif | ||
47 | } | ||
48 | |||
49 | static const struct usb_device_id *find_id(struct usb_device *udev) | ||
50 | { | ||
51 | const struct usb_device_id *id = usb_quirk_list; | ||
52 | |||
53 | for (; id->idVendor || id->bDeviceClass || id->bInterfaceClass || | ||
54 | id->driver_info; id++) { | ||
55 | if (usb_match_device(udev, id)) | ||
56 | return id; | ||
57 | } | ||
58 | return NULL; | ||
59 | } | ||
60 | |||
61 | /* | ||
62 | * Detect any quirks the device has, and do any housekeeping for it if needed. | ||
63 | */ | ||
64 | void usb_detect_quirks(struct usb_device *udev) | ||
65 | { | ||
66 | const struct usb_device_id *id = usb_quirk_list; | ||
67 | |||
68 | id = find_id(udev); | ||
69 | if (id) | ||
70 | udev->quirks = (u32)(id->driver_info); | ||
71 | if (udev->quirks) | ||
72 | dev_dbg(&udev->dev, "USB quirks for this device: %x\n", | ||
73 | udev->quirks); | ||
74 | |||
75 | /* do any special quirk handling here if needed */ | ||
76 | if (udev->quirks & USB_QUIRK_NO_AUTOSUSPEND) | ||
77 | usb_autosuspend_quirk(udev); | ||
78 | } | ||
diff --git a/drivers/usb/core/sysfs.c b/drivers/usb/core/sysfs.c index 4eaa0ee8e72f..e7c982377488 100644 --- a/drivers/usb/core/sysfs.c +++ b/drivers/usb/core/sysfs.c | |||
@@ -11,6 +11,7 @@ | |||
11 | 11 | ||
12 | 12 | ||
13 | #include <linux/kernel.h> | 13 | #include <linux/kernel.h> |
14 | #include <linux/string.h> | ||
14 | #include <linux/usb.h> | 15 | #include <linux/usb.h> |
15 | #include "usb.h" | 16 | #include "usb.h" |
16 | 17 | ||
@@ -63,7 +64,7 @@ set_bConfigurationValue(struct device *dev, struct device_attribute *attr, | |||
63 | struct usb_device *udev = to_usb_device(dev); | 64 | struct usb_device *udev = to_usb_device(dev); |
64 | int config, value; | 65 | int config, value; |
65 | 66 | ||
66 | if (sscanf(buf, "%u", &config) != 1 || config > 255) | 67 | if (sscanf(buf, "%d", &config) != 1 || config < -1 || config > 255) |
67 | return -EINVAL; | 68 | return -EINVAL; |
68 | usb_lock_device(udev); | 69 | usb_lock_device(udev); |
69 | value = usb_set_configuration(udev, config); | 70 | value = usb_set_configuration(udev, config); |
@@ -117,6 +118,16 @@ show_speed(struct device *dev, struct device_attribute *attr, char *buf) | |||
117 | static DEVICE_ATTR(speed, S_IRUGO, show_speed, NULL); | 118 | static DEVICE_ATTR(speed, S_IRUGO, show_speed, NULL); |
118 | 119 | ||
119 | static ssize_t | 120 | static ssize_t |
121 | show_busnum(struct device *dev, struct device_attribute *attr, char *buf) | ||
122 | { | ||
123 | struct usb_device *udev; | ||
124 | |||
125 | udev = to_usb_device(dev); | ||
126 | return sprintf(buf, "%d\n", udev->bus->busnum); | ||
127 | } | ||
128 | static DEVICE_ATTR(busnum, S_IRUGO, show_busnum, NULL); | ||
129 | |||
130 | static ssize_t | ||
120 | show_devnum(struct device *dev, struct device_attribute *attr, char *buf) | 131 | show_devnum(struct device *dev, struct device_attribute *attr, char *buf) |
121 | { | 132 | { |
122 | struct usb_device *udev; | 133 | struct usb_device *udev; |
@@ -148,6 +159,151 @@ show_maxchild(struct device *dev, struct device_attribute *attr, char *buf) | |||
148 | } | 159 | } |
149 | static DEVICE_ATTR(maxchild, S_IRUGO, show_maxchild, NULL); | 160 | static DEVICE_ATTR(maxchild, S_IRUGO, show_maxchild, NULL); |
150 | 161 | ||
162 | static ssize_t | ||
163 | show_quirks(struct device *dev, struct device_attribute *attr, char *buf) | ||
164 | { | ||
165 | struct usb_device *udev; | ||
166 | |||
167 | udev = to_usb_device(dev); | ||
168 | return sprintf(buf, "0x%x\n", udev->quirks); | ||
169 | } | ||
170 | static DEVICE_ATTR(quirks, S_IRUGO, show_quirks, NULL); | ||
171 | |||
172 | #ifdef CONFIG_USB_SUSPEND | ||
173 | |||
174 | static ssize_t | ||
175 | show_autosuspend(struct device *dev, struct device_attribute *attr, char *buf) | ||
176 | { | ||
177 | struct usb_device *udev = to_usb_device(dev); | ||
178 | |||
179 | return sprintf(buf, "%d\n", udev->autosuspend_delay / HZ); | ||
180 | } | ||
181 | |||
182 | static ssize_t | ||
183 | set_autosuspend(struct device *dev, struct device_attribute *attr, | ||
184 | const char *buf, size_t count) | ||
185 | { | ||
186 | struct usb_device *udev = to_usb_device(dev); | ||
187 | int value; | ||
188 | |||
189 | if (sscanf(buf, "%d", &value) != 1 || value >= INT_MAX/HZ || | ||
190 | value <= - INT_MAX/HZ) | ||
191 | return -EINVAL; | ||
192 | value *= HZ; | ||
193 | |||
194 | udev->autosuspend_delay = value; | ||
195 | if (value >= 0) | ||
196 | usb_try_autosuspend_device(udev); | ||
197 | else { | ||
198 | if (usb_autoresume_device(udev) == 0) | ||
199 | usb_autosuspend_device(udev); | ||
200 | } | ||
201 | return count; | ||
202 | } | ||
203 | |||
204 | static DEVICE_ATTR(autosuspend, S_IRUGO | S_IWUSR, | ||
205 | show_autosuspend, set_autosuspend); | ||
206 | |||
207 | static const char on_string[] = "on"; | ||
208 | static const char auto_string[] = "auto"; | ||
209 | static const char suspend_string[] = "suspend"; | ||
210 | |||
211 | static ssize_t | ||
212 | show_level(struct device *dev, struct device_attribute *attr, char *buf) | ||
213 | { | ||
214 | struct usb_device *udev = to_usb_device(dev); | ||
215 | const char *p = auto_string; | ||
216 | |||
217 | if (udev->state == USB_STATE_SUSPENDED) { | ||
218 | if (udev->autoresume_disabled) | ||
219 | p = suspend_string; | ||
220 | } else { | ||
221 | if (udev->autosuspend_disabled) | ||
222 | p = on_string; | ||
223 | } | ||
224 | return sprintf(buf, "%s\n", p); | ||
225 | } | ||
226 | |||
227 | static ssize_t | ||
228 | set_level(struct device *dev, struct device_attribute *attr, | ||
229 | const char *buf, size_t count) | ||
230 | { | ||
231 | struct usb_device *udev = to_usb_device(dev); | ||
232 | int len = count; | ||
233 | char *cp; | ||
234 | int rc = 0; | ||
235 | |||
236 | cp = memchr(buf, '\n', count); | ||
237 | if (cp) | ||
238 | len = cp - buf; | ||
239 | |||
240 | usb_lock_device(udev); | ||
241 | |||
242 | /* Setting the flags without calling usb_pm_lock is a subject to | ||
243 | * races, but who cares... | ||
244 | */ | ||
245 | if (len == sizeof on_string - 1 && | ||
246 | strncmp(buf, on_string, len) == 0) { | ||
247 | udev->autosuspend_disabled = 1; | ||
248 | udev->autoresume_disabled = 0; | ||
249 | rc = usb_external_resume_device(udev); | ||
250 | |||
251 | } else if (len == sizeof auto_string - 1 && | ||
252 | strncmp(buf, auto_string, len) == 0) { | ||
253 | udev->autosuspend_disabled = 0; | ||
254 | udev->autoresume_disabled = 0; | ||
255 | rc = usb_external_resume_device(udev); | ||
256 | |||
257 | } else if (len == sizeof suspend_string - 1 && | ||
258 | strncmp(buf, suspend_string, len) == 0) { | ||
259 | udev->autosuspend_disabled = 0; | ||
260 | udev->autoresume_disabled = 1; | ||
261 | rc = usb_external_suspend_device(udev, PMSG_SUSPEND); | ||
262 | |||
263 | } else | ||
264 | rc = -EINVAL; | ||
265 | |||
266 | usb_unlock_device(udev); | ||
267 | return (rc < 0 ? rc : count); | ||
268 | } | ||
269 | |||
270 | static DEVICE_ATTR(level, S_IRUGO | S_IWUSR, show_level, set_level); | ||
271 | |||
272 | static char power_group[] = "power"; | ||
273 | |||
274 | static int add_power_attributes(struct device *dev) | ||
275 | { | ||
276 | int rc = 0; | ||
277 | |||
278 | if (is_usb_device(dev)) { | ||
279 | rc = sysfs_add_file_to_group(&dev->kobj, | ||
280 | &dev_attr_autosuspend.attr, | ||
281 | power_group); | ||
282 | if (rc == 0) | ||
283 | rc = sysfs_add_file_to_group(&dev->kobj, | ||
284 | &dev_attr_level.attr, | ||
285 | power_group); | ||
286 | } | ||
287 | return rc; | ||
288 | } | ||
289 | |||
290 | static void remove_power_attributes(struct device *dev) | ||
291 | { | ||
292 | sysfs_remove_file_from_group(&dev->kobj, | ||
293 | &dev_attr_level.attr, | ||
294 | power_group); | ||
295 | sysfs_remove_file_from_group(&dev->kobj, | ||
296 | &dev_attr_autosuspend.attr, | ||
297 | power_group); | ||
298 | } | ||
299 | |||
300 | #else | ||
301 | |||
302 | #define add_power_attributes(dev) 0 | ||
303 | #define remove_power_attributes(dev) do {} while (0) | ||
304 | |||
305 | #endif /* CONFIG_USB_SUSPEND */ | ||
306 | |||
151 | /* Descriptor fields */ | 307 | /* Descriptor fields */ |
152 | #define usb_descriptor_attr_le16(field, format_string) \ | 308 | #define usb_descriptor_attr_le16(field, format_string) \ |
153 | static ssize_t \ | 309 | static ssize_t \ |
@@ -201,9 +357,11 @@ static struct attribute *dev_attrs[] = { | |||
201 | &dev_attr_bNumConfigurations.attr, | 357 | &dev_attr_bNumConfigurations.attr, |
202 | &dev_attr_bMaxPacketSize0.attr, | 358 | &dev_attr_bMaxPacketSize0.attr, |
203 | &dev_attr_speed.attr, | 359 | &dev_attr_speed.attr, |
360 | &dev_attr_busnum.attr, | ||
204 | &dev_attr_devnum.attr, | 361 | &dev_attr_devnum.attr, |
205 | &dev_attr_version.attr, | 362 | &dev_attr_version.attr, |
206 | &dev_attr_maxchild.attr, | 363 | &dev_attr_maxchild.attr, |
364 | &dev_attr_quirks.attr, | ||
207 | NULL, | 365 | NULL, |
208 | }; | 366 | }; |
209 | static struct attribute_group dev_attr_grp = { | 367 | static struct attribute_group dev_attr_grp = { |
@@ -219,6 +377,10 @@ int usb_create_sysfs_dev_files(struct usb_device *udev) | |||
219 | if (retval) | 377 | if (retval) |
220 | return retval; | 378 | return retval; |
221 | 379 | ||
380 | retval = add_power_attributes(dev); | ||
381 | if (retval) | ||
382 | goto error; | ||
383 | |||
222 | if (udev->manufacturer) { | 384 | if (udev->manufacturer) { |
223 | retval = device_create_file(dev, &dev_attr_manufacturer); | 385 | retval = device_create_file(dev, &dev_attr_manufacturer); |
224 | if (retval) | 386 | if (retval) |
@@ -239,10 +401,7 @@ int usb_create_sysfs_dev_files(struct usb_device *udev) | |||
239 | goto error; | 401 | goto error; |
240 | return 0; | 402 | return 0; |
241 | error: | 403 | error: |
242 | usb_remove_ep_files(&udev->ep0); | 404 | usb_remove_sysfs_dev_files(udev); |
243 | device_remove_file(dev, &dev_attr_manufacturer); | ||
244 | device_remove_file(dev, &dev_attr_product); | ||
245 | device_remove_file(dev, &dev_attr_serial); | ||
246 | return retval; | 405 | return retval; |
247 | } | 406 | } |
248 | 407 | ||
@@ -251,14 +410,11 @@ void usb_remove_sysfs_dev_files(struct usb_device *udev) | |||
251 | struct device *dev = &udev->dev; | 410 | struct device *dev = &udev->dev; |
252 | 411 | ||
253 | usb_remove_ep_files(&udev->ep0); | 412 | usb_remove_ep_files(&udev->ep0); |
413 | device_remove_file(dev, &dev_attr_manufacturer); | ||
414 | device_remove_file(dev, &dev_attr_product); | ||
415 | device_remove_file(dev, &dev_attr_serial); | ||
416 | remove_power_attributes(dev); | ||
254 | sysfs_remove_group(&dev->kobj, &dev_attr_grp); | 417 | sysfs_remove_group(&dev->kobj, &dev_attr_grp); |
255 | |||
256 | if (udev->manufacturer) | ||
257 | device_remove_file(dev, &dev_attr_manufacturer); | ||
258 | if (udev->product) | ||
259 | device_remove_file(dev, &dev_attr_product); | ||
260 | if (udev->serial) | ||
261 | device_remove_file(dev, &dev_attr_serial); | ||
262 | } | 418 | } |
263 | 419 | ||
264 | /* Interface fields */ | 420 | /* Interface fields */ |
@@ -362,33 +518,28 @@ static inline void usb_remove_intf_ep_files(struct usb_interface *intf) | |||
362 | 518 | ||
363 | int usb_create_sysfs_intf_files(struct usb_interface *intf) | 519 | int usb_create_sysfs_intf_files(struct usb_interface *intf) |
364 | { | 520 | { |
521 | struct device *dev = &intf->dev; | ||
365 | struct usb_device *udev = interface_to_usbdev(intf); | 522 | struct usb_device *udev = interface_to_usbdev(intf); |
366 | struct usb_host_interface *alt = intf->cur_altsetting; | 523 | struct usb_host_interface *alt = intf->cur_altsetting; |
367 | int retval; | 524 | int retval; |
368 | 525 | ||
369 | retval = sysfs_create_group(&intf->dev.kobj, &intf_attr_grp); | 526 | retval = sysfs_create_group(&dev->kobj, &intf_attr_grp); |
370 | if (retval) | 527 | if (retval) |
371 | goto error; | 528 | return retval; |
372 | 529 | ||
373 | if (alt->string == NULL) | 530 | if (alt->string == NULL) |
374 | alt->string = usb_cache_string(udev, alt->desc.iInterface); | 531 | alt->string = usb_cache_string(udev, alt->desc.iInterface); |
375 | if (alt->string) | 532 | if (alt->string) |
376 | retval = device_create_file(&intf->dev, &dev_attr_interface); | 533 | retval = device_create_file(dev, &dev_attr_interface); |
377 | usb_create_intf_ep_files(intf, udev); | 534 | usb_create_intf_ep_files(intf, udev); |
378 | return 0; | 535 | return 0; |
379 | error: | ||
380 | if (alt->string) | ||
381 | device_remove_file(&intf->dev, &dev_attr_interface); | ||
382 | sysfs_remove_group(&intf->dev.kobj, &intf_attr_grp); | ||
383 | usb_remove_intf_ep_files(intf); | ||
384 | return retval; | ||
385 | } | 536 | } |
386 | 537 | ||
387 | void usb_remove_sysfs_intf_files(struct usb_interface *intf) | 538 | void usb_remove_sysfs_intf_files(struct usb_interface *intf) |
388 | { | 539 | { |
389 | usb_remove_intf_ep_files(intf); | 540 | struct device *dev = &intf->dev; |
390 | sysfs_remove_group(&intf->dev.kobj, &intf_attr_grp); | ||
391 | 541 | ||
392 | if (intf->cur_altsetting->string) | 542 | usb_remove_intf_ep_files(intf); |
393 | device_remove_file(&intf->dev, &dev_attr_interface); | 543 | device_remove_file(dev, &dev_attr_interface); |
544 | sysfs_remove_group(&dev->kobj, &intf_attr_grp); | ||
394 | } | 545 | } |
diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c index 3db721cd557a..dfd1b5c87ca3 100644 --- a/drivers/usb/core/usb.c +++ b/drivers/usb/core/usb.c | |||
@@ -22,6 +22,7 @@ | |||
22 | */ | 22 | */ |
23 | 23 | ||
24 | #include <linux/module.h> | 24 | #include <linux/module.h> |
25 | #include <linux/moduleparam.h> | ||
25 | #include <linux/string.h> | 26 | #include <linux/string.h> |
26 | #include <linux/bitops.h> | 27 | #include <linux/bitops.h> |
27 | #include <linux/slab.h> | 28 | #include <linux/slab.h> |
@@ -48,7 +49,18 @@ const char *usbcore_name = "usbcore"; | |||
48 | 49 | ||
49 | static int nousb; /* Disable USB when built into kernel image */ | 50 | static int nousb; /* Disable USB when built into kernel image */ |
50 | 51 | ||
51 | struct workqueue_struct *ksuspend_usb_wq; /* For autosuspend */ | 52 | /* Workqueue for autosuspend and for remote wakeup of root hubs */ |
53 | struct workqueue_struct *ksuspend_usb_wq; | ||
54 | |||
55 | #ifdef CONFIG_USB_SUSPEND | ||
56 | static int usb_autosuspend_delay = 2; /* Default delay value, | ||
57 | * in seconds */ | ||
58 | module_param_named(autosuspend, usb_autosuspend_delay, int, 0644); | ||
59 | MODULE_PARM_DESC(autosuspend, "default autosuspend delay"); | ||
60 | |||
61 | #else | ||
62 | #define usb_autosuspend_delay 0 | ||
63 | #endif | ||
52 | 64 | ||
53 | 65 | ||
54 | /** | 66 | /** |
@@ -185,6 +197,11 @@ static void usb_release_dev(struct device *dev) | |||
185 | kfree(udev); | 197 | kfree(udev); |
186 | } | 198 | } |
187 | 199 | ||
200 | struct device_type usb_device_type = { | ||
201 | .name = "usb_device", | ||
202 | .release = usb_release_dev, | ||
203 | }; | ||
204 | |||
188 | #ifdef CONFIG_PM | 205 | #ifdef CONFIG_PM |
189 | 206 | ||
190 | static int ksuspend_usb_init(void) | 207 | static int ksuspend_usb_init(void) |
@@ -200,27 +217,6 @@ static void ksuspend_usb_cleanup(void) | |||
200 | destroy_workqueue(ksuspend_usb_wq); | 217 | destroy_workqueue(ksuspend_usb_wq); |
201 | } | 218 | } |
202 | 219 | ||
203 | #ifdef CONFIG_USB_SUSPEND | ||
204 | |||
205 | /* usb_autosuspend_work - callback routine to autosuspend a USB device */ | ||
206 | static void usb_autosuspend_work(struct work_struct *work) | ||
207 | { | ||
208 | struct usb_device *udev = | ||
209 | container_of(work, struct usb_device, autosuspend.work); | ||
210 | |||
211 | usb_pm_lock(udev); | ||
212 | udev->auto_pm = 1; | ||
213 | usb_suspend_both(udev, PMSG_SUSPEND); | ||
214 | usb_pm_unlock(udev); | ||
215 | } | ||
216 | |||
217 | #else | ||
218 | |||
219 | static void usb_autosuspend_work(struct work_struct *work) | ||
220 | {} | ||
221 | |||
222 | #endif /* CONFIG_USB_SUSPEND */ | ||
223 | |||
224 | #else | 220 | #else |
225 | 221 | ||
226 | #define ksuspend_usb_init() 0 | 222 | #define ksuspend_usb_init() 0 |
@@ -256,13 +252,10 @@ usb_alloc_dev(struct usb_device *parent, struct usb_bus *bus, unsigned port1) | |||
256 | 252 | ||
257 | device_initialize(&dev->dev); | 253 | device_initialize(&dev->dev); |
258 | dev->dev.bus = &usb_bus_type; | 254 | dev->dev.bus = &usb_bus_type; |
255 | dev->dev.type = &usb_device_type; | ||
259 | dev->dev.dma_mask = bus->controller->dma_mask; | 256 | dev->dev.dma_mask = bus->controller->dma_mask; |
260 | dev->dev.release = usb_release_dev; | ||
261 | dev->state = USB_STATE_ATTACHED; | 257 | dev->state = USB_STATE_ATTACHED; |
262 | 258 | ||
263 | /* This magic assignment distinguishes devices from interfaces */ | ||
264 | dev->dev.platform_data = &usb_generic_driver; | ||
265 | |||
266 | INIT_LIST_HEAD(&dev->ep0.urb_list); | 259 | INIT_LIST_HEAD(&dev->ep0.urb_list); |
267 | dev->ep0.desc.bLength = USB_DT_ENDPOINT_SIZE; | 260 | dev->ep0.desc.bLength = USB_DT_ENDPOINT_SIZE; |
268 | dev->ep0.desc.bDescriptorType = USB_DT_ENDPOINT; | 261 | dev->ep0.desc.bDescriptorType = USB_DT_ENDPOINT; |
@@ -306,6 +299,7 @@ usb_alloc_dev(struct usb_device *parent, struct usb_bus *bus, unsigned port1) | |||
306 | #ifdef CONFIG_PM | 299 | #ifdef CONFIG_PM |
307 | mutex_init(&dev->pm_mutex); | 300 | mutex_init(&dev->pm_mutex); |
308 | INIT_DELAYED_WORK(&dev->autosuspend, usb_autosuspend_work); | 301 | INIT_DELAYED_WORK(&dev->autosuspend, usb_autosuspend_work); |
302 | dev->autosuspend_delay = usb_autosuspend_delay * HZ; | ||
309 | #endif | 303 | #endif |
310 | return dev; | 304 | return dev; |
311 | } | 305 | } |
@@ -890,9 +884,9 @@ static int __init usb_init(void) | |||
890 | retval = usb_register(&usbfs_driver); | 884 | retval = usb_register(&usbfs_driver); |
891 | if (retval) | 885 | if (retval) |
892 | goto driver_register_failed; | 886 | goto driver_register_failed; |
893 | retval = usbdev_init(); | 887 | retval = usb_devio_init(); |
894 | if (retval) | 888 | if (retval) |
895 | goto usbdevice_init_failed; | 889 | goto usb_devio_init_failed; |
896 | retval = usbfs_init(); | 890 | retval = usbfs_init(); |
897 | if (retval) | 891 | if (retval) |
898 | goto fs_init_failed; | 892 | goto fs_init_failed; |
@@ -907,8 +901,8 @@ static int __init usb_init(void) | |||
907 | hub_init_failed: | 901 | hub_init_failed: |
908 | usbfs_cleanup(); | 902 | usbfs_cleanup(); |
909 | fs_init_failed: | 903 | fs_init_failed: |
910 | usbdev_cleanup(); | 904 | usb_devio_cleanup(); |
911 | usbdevice_init_failed: | 905 | usb_devio_init_failed: |
912 | usb_deregister(&usbfs_driver); | 906 | usb_deregister(&usbfs_driver); |
913 | driver_register_failed: | 907 | driver_register_failed: |
914 | usb_major_cleanup(); | 908 | usb_major_cleanup(); |
@@ -935,7 +929,7 @@ static void __exit usb_exit(void) | |||
935 | usb_major_cleanup(); | 929 | usb_major_cleanup(); |
936 | usbfs_cleanup(); | 930 | usbfs_cleanup(); |
937 | usb_deregister(&usbfs_driver); | 931 | usb_deregister(&usbfs_driver); |
938 | usbdev_cleanup(); | 932 | usb_devio_cleanup(); |
939 | usb_hub_cleanup(); | 933 | usb_hub_cleanup(); |
940 | usb_host_cleanup(); | 934 | usb_host_cleanup(); |
941 | bus_unregister(&usb_bus_type); | 935 | bus_unregister(&usb_bus_type); |
diff --git a/drivers/usb/core/usb.h b/drivers/usb/core/usb.h index 17830a81be14..bf2eb0dae2ec 100644 --- a/drivers/usb/core/usb.h +++ b/drivers/usb/core/usb.h | |||
@@ -13,6 +13,7 @@ extern void usb_disable_interface (struct usb_device *dev, | |||
13 | struct usb_interface *intf); | 13 | struct usb_interface *intf); |
14 | extern void usb_release_interface_cache(struct kref *ref); | 14 | extern void usb_release_interface_cache(struct kref *ref); |
15 | extern void usb_disable_device (struct usb_device *dev, int skip_ep0); | 15 | extern void usb_disable_device (struct usb_device *dev, int skip_ep0); |
16 | extern void usb_detect_quirks(struct usb_device *udev); | ||
16 | 17 | ||
17 | extern int usb_get_device_descriptor(struct usb_device *dev, | 18 | extern int usb_get_device_descriptor(struct usb_device *dev, |
18 | unsigned int size); | 19 | unsigned int size); |
@@ -20,7 +21,8 @@ extern char *usb_cache_string(struct usb_device *udev, int index); | |||
20 | extern int usb_set_configuration(struct usb_device *dev, int configuration); | 21 | extern int usb_set_configuration(struct usb_device *dev, int configuration); |
21 | 22 | ||
22 | extern void usb_kick_khubd(struct usb_device *dev); | 23 | extern void usb_kick_khubd(struct usb_device *dev); |
23 | extern void usb_resume_root_hub(struct usb_device *dev); | 24 | extern int usb_match_device(struct usb_device *dev, |
25 | const struct usb_device_id *id); | ||
24 | 26 | ||
25 | extern int usb_hub_init(void); | 27 | extern int usb_hub_init(void); |
26 | extern void usb_hub_cleanup(void); | 28 | extern void usb_hub_cleanup(void); |
@@ -31,10 +33,12 @@ extern void usb_host_cleanup(void); | |||
31 | 33 | ||
32 | #ifdef CONFIG_PM | 34 | #ifdef CONFIG_PM |
33 | 35 | ||
34 | extern int usb_suspend_both(struct usb_device *udev, pm_message_t msg); | 36 | extern void usb_autosuspend_work(struct work_struct *work); |
35 | extern int usb_resume_both(struct usb_device *udev); | ||
36 | extern int usb_port_suspend(struct usb_device *dev); | 37 | extern int usb_port_suspend(struct usb_device *dev); |
37 | extern int usb_port_resume(struct usb_device *dev); | 38 | extern int usb_port_resume(struct usb_device *dev); |
39 | extern int usb_external_suspend_device(struct usb_device *udev, | ||
40 | pm_message_t msg); | ||
41 | extern int usb_external_resume_device(struct usb_device *udev); | ||
38 | 42 | ||
39 | static inline void usb_pm_lock(struct usb_device *udev) | 43 | static inline void usb_pm_lock(struct usb_device *udev) |
40 | { | 44 | { |
@@ -48,11 +52,6 @@ static inline void usb_pm_unlock(struct usb_device *udev) | |||
48 | 52 | ||
49 | #else | 53 | #else |
50 | 54 | ||
51 | #define usb_suspend_both(udev, msg) 0 | ||
52 | static inline int usb_resume_both(struct usb_device *udev) | ||
53 | { | ||
54 | return 0; | ||
55 | } | ||
56 | #define usb_port_suspend(dev) 0 | 55 | #define usb_port_suspend(dev) 0 |
57 | #define usb_port_resume(dev) 0 | 56 | #define usb_port_resume(dev) 0 |
58 | static inline void usb_pm_lock(struct usb_device *udev) {} | 57 | static inline void usb_pm_lock(struct usb_device *udev) {} |
@@ -62,14 +61,14 @@ static inline void usb_pm_unlock(struct usb_device *udev) {} | |||
62 | 61 | ||
63 | #ifdef CONFIG_USB_SUSPEND | 62 | #ifdef CONFIG_USB_SUSPEND |
64 | 63 | ||
65 | #define USB_AUTOSUSPEND_DELAY (HZ*2) | ||
66 | |||
67 | extern void usb_autosuspend_device(struct usb_device *udev); | 64 | extern void usb_autosuspend_device(struct usb_device *udev); |
65 | extern void usb_try_autosuspend_device(struct usb_device *udev); | ||
68 | extern int usb_autoresume_device(struct usb_device *udev); | 66 | extern int usb_autoresume_device(struct usb_device *udev); |
69 | 67 | ||
70 | #else | 68 | #else |
71 | 69 | ||
72 | #define usb_autosuspend_device(udev) do {} while (0) | 70 | #define usb_autosuspend_device(udev) do {} while (0) |
71 | #define usb_try_autosuspend_device(udev) do {} while (0) | ||
73 | static inline int usb_autoresume_device(struct usb_device *udev) | 72 | static inline int usb_autoresume_device(struct usb_device *udev) |
74 | { | 73 | { |
75 | return 0; | 74 | return 0; |
@@ -79,15 +78,13 @@ static inline int usb_autoresume_device(struct usb_device *udev) | |||
79 | 78 | ||
80 | extern struct workqueue_struct *ksuspend_usb_wq; | 79 | extern struct workqueue_struct *ksuspend_usb_wq; |
81 | extern struct bus_type usb_bus_type; | 80 | extern struct bus_type usb_bus_type; |
81 | extern struct device_type usb_device_type; | ||
82 | extern struct device_type usb_if_device_type; | ||
82 | extern struct usb_device_driver usb_generic_driver; | 83 | extern struct usb_device_driver usb_generic_driver; |
83 | 84 | ||
84 | /* Here's how we tell apart devices and interfaces. Luckily there's | ||
85 | * no such thing as a platform USB device, so we can steal the use | ||
86 | * of the platform_data field. */ | ||
87 | |||
88 | static inline int is_usb_device(const struct device *dev) | 85 | static inline int is_usb_device(const struct device *dev) |
89 | { | 86 | { |
90 | return dev->platform_data == &usb_generic_driver; | 87 | return dev->type == &usb_device_type; |
91 | } | 88 | } |
92 | 89 | ||
93 | /* Do the same for device drivers and interface drivers. */ | 90 | /* Do the same for device drivers and interface drivers. */ |
@@ -123,11 +120,11 @@ extern const char *usbcore_name; | |||
123 | extern struct mutex usbfs_mutex; | 120 | extern struct mutex usbfs_mutex; |
124 | extern struct usb_driver usbfs_driver; | 121 | extern struct usb_driver usbfs_driver; |
125 | extern const struct file_operations usbfs_devices_fops; | 122 | extern const struct file_operations usbfs_devices_fops; |
126 | extern const struct file_operations usbfs_device_file_operations; | 123 | extern const struct file_operations usbdev_file_operations; |
127 | extern void usbfs_conn_disc_event(void); | 124 | extern void usbfs_conn_disc_event(void); |
128 | 125 | ||
129 | extern int usbdev_init(void); | 126 | extern int usb_devio_init(void); |
130 | extern void usbdev_cleanup(void); | 127 | extern void usb_devio_cleanup(void); |
131 | 128 | ||
132 | struct dev_state { | 129 | struct dev_state { |
133 | struct list_head list; /* state list */ | 130 | struct list_head list; /* state list */ |
diff --git a/drivers/usb/gadget/Kconfig b/drivers/usb/gadget/Kconfig index 4097a86c4b5e..8065f2b53701 100644 --- a/drivers/usb/gadget/Kconfig +++ b/drivers/usb/gadget/Kconfig | |||
@@ -68,6 +68,27 @@ choice | |||
68 | Many controller drivers are platform-specific; these | 68 | Many controller drivers are platform-specific; these |
69 | often need board-specific hooks. | 69 | often need board-specific hooks. |
70 | 70 | ||
71 | config USB_GADGET_FSL_USB2 | ||
72 | boolean "Freescale Highspeed USB DR Peripheral Controller" | ||
73 | depends on MPC834x || PPC_MPC831x | ||
74 | select USB_GADGET_DUALSPEED | ||
75 | help | ||
76 | Some of Freescale PowerPC processors have a High Speed | ||
77 | Dual-Role(DR) USB controller, which supports device mode. | ||
78 | |||
79 | The number of programmable endpoints is different through | ||
80 | SOC revisions. | ||
81 | |||
82 | Say "y" to link the driver statically, or "m" to build a | ||
83 | dynamically linked module called "fsl_usb2_udc" and force | ||
84 | all gadget drivers to also be dynamically linked. | ||
85 | |||
86 | config USB_FSL_USB2 | ||
87 | tristate | ||
88 | depends on USB_GADGET_FSL_USB2 | ||
89 | default USB_GADGET | ||
90 | select USB_GADGET_SELECTED | ||
91 | |||
71 | config USB_GADGET_NET2280 | 92 | config USB_GADGET_NET2280 |
72 | boolean "NetChip 228x" | 93 | boolean "NetChip 228x" |
73 | depends on PCI | 94 | depends on PCI |
@@ -370,6 +391,7 @@ config USB_GADGETFS | |||
370 | 391 | ||
371 | config USB_FILE_STORAGE | 392 | config USB_FILE_STORAGE |
372 | tristate "File-backed Storage Gadget" | 393 | tristate "File-backed Storage Gadget" |
394 | depends on BLOCK | ||
373 | help | 395 | help |
374 | The File-backed Storage Gadget acts as a USB Mass Storage | 396 | The File-backed Storage Gadget acts as a USB Mass Storage |
375 | disk drive. As its storage repository it can use a regular | 397 | disk drive. As its storage repository it can use a regular |
diff --git a/drivers/usb/gadget/Makefile b/drivers/usb/gadget/Makefile index e71e086a1cfa..5db19396631c 100644 --- a/drivers/usb/gadget/Makefile +++ b/drivers/usb/gadget/Makefile | |||
@@ -8,6 +8,7 @@ obj-$(CONFIG_USB_GOKU) += goku_udc.o | |||
8 | obj-$(CONFIG_USB_OMAP) += omap_udc.o | 8 | obj-$(CONFIG_USB_OMAP) += omap_udc.o |
9 | obj-$(CONFIG_USB_LH7A40X) += lh7a40x_udc.o | 9 | obj-$(CONFIG_USB_LH7A40X) += lh7a40x_udc.o |
10 | obj-$(CONFIG_USB_AT91) += at91_udc.o | 10 | obj-$(CONFIG_USB_AT91) += at91_udc.o |
11 | obj-$(CONFIG_USB_FSL_USB2) += fsl_usb2_udc.o | ||
11 | 12 | ||
12 | # | 13 | # |
13 | # USB gadget drivers | 14 | # USB gadget drivers |
diff --git a/drivers/usb/gadget/at91_udc.c b/drivers/usb/gadget/at91_udc.c index 36b36e0175fc..2a6e3163d944 100644 --- a/drivers/usb/gadget/at91_udc.c +++ b/drivers/usb/gadget/at91_udc.c | |||
@@ -784,7 +784,7 @@ static int at91_ep_set_halt(struct usb_ep *_ep, int value) | |||
784 | return status; | 784 | return status; |
785 | } | 785 | } |
786 | 786 | ||
787 | static struct usb_ep_ops at91_ep_ops = { | 787 | static const struct usb_ep_ops at91_ep_ops = { |
788 | .enable = at91_ep_enable, | 788 | .enable = at91_ep_enable, |
789 | .disable = at91_ep_disable, | 789 | .disable = at91_ep_disable, |
790 | .alloc_request = at91_ep_alloc_request, | 790 | .alloc_request = at91_ep_alloc_request, |
@@ -912,7 +912,7 @@ static void pullup(struct at91_udc *udc, int is_on) | |||
912 | at91_udp_write(udc, AT91_UDP_TXVC, 0); | 912 | at91_udp_write(udc, AT91_UDP_TXVC, 0); |
913 | if (cpu_is_at91rm9200()) | 913 | if (cpu_is_at91rm9200()) |
914 | at91_set_gpio_value(udc->board.pullup_pin, 1); | 914 | at91_set_gpio_value(udc->board.pullup_pin, 1); |
915 | else if (cpu_is_at91sam9260()) { | 915 | else if (cpu_is_at91sam9260() || cpu_is_at91sam9263()) { |
916 | u32 txvc = at91_udp_read(udc, AT91_UDP_TXVC); | 916 | u32 txvc = at91_udp_read(udc, AT91_UDP_TXVC); |
917 | 917 | ||
918 | txvc |= AT91_UDP_TXVC_PUON; | 918 | txvc |= AT91_UDP_TXVC_PUON; |
@@ -929,7 +929,7 @@ static void pullup(struct at91_udc *udc, int is_on) | |||
929 | at91_udp_write(udc, AT91_UDP_TXVC, AT91_UDP_TXVC_TXVDIS); | 929 | at91_udp_write(udc, AT91_UDP_TXVC, AT91_UDP_TXVC_TXVDIS); |
930 | if (cpu_is_at91rm9200()) | 930 | if (cpu_is_at91rm9200()) |
931 | at91_set_gpio_value(udc->board.pullup_pin, 0); | 931 | at91_set_gpio_value(udc->board.pullup_pin, 0); |
932 | else if (cpu_is_at91sam9260()) { | 932 | else if (cpu_is_at91sam9260() || cpu_is_at91sam9263()) { |
933 | u32 txvc = at91_udp_read(udc, AT91_UDP_TXVC); | 933 | u32 txvc = at91_udp_read(udc, AT91_UDP_TXVC); |
934 | 934 | ||
935 | txvc &= ~AT91_UDP_TXVC_PUON; | 935 | txvc &= ~AT91_UDP_TXVC_PUON; |
@@ -1651,7 +1651,7 @@ static void at91udc_shutdown(struct platform_device *dev) | |||
1651 | pullup(platform_get_drvdata(dev), 0); | 1651 | pullup(platform_get_drvdata(dev), 0); |
1652 | } | 1652 | } |
1653 | 1653 | ||
1654 | static int __devinit at91udc_probe(struct platform_device *pdev) | 1654 | static int __init at91udc_probe(struct platform_device *pdev) |
1655 | { | 1655 | { |
1656 | struct device *dev = &pdev->dev; | 1656 | struct device *dev = &pdev->dev; |
1657 | struct at91_udc *udc; | 1657 | struct at91_udc *udc; |
@@ -1762,7 +1762,7 @@ fail0: | |||
1762 | return retval; | 1762 | return retval; |
1763 | } | 1763 | } |
1764 | 1764 | ||
1765 | static int __devexit at91udc_remove(struct platform_device *pdev) | 1765 | static int __exit at91udc_remove(struct platform_device *pdev) |
1766 | { | 1766 | { |
1767 | struct at91_udc *udc = platform_get_drvdata(pdev); | 1767 | struct at91_udc *udc = platform_get_drvdata(pdev); |
1768 | struct resource *res; | 1768 | struct resource *res; |
@@ -1835,9 +1835,8 @@ static int at91udc_resume(struct platform_device *pdev) | |||
1835 | #define at91udc_resume NULL | 1835 | #define at91udc_resume NULL |
1836 | #endif | 1836 | #endif |
1837 | 1837 | ||
1838 | static struct platform_driver at91_udc = { | 1838 | static struct platform_driver at91_udc_driver = { |
1839 | .probe = at91udc_probe, | 1839 | .remove = __exit_p(at91udc_remove), |
1840 | .remove = __devexit_p(at91udc_remove), | ||
1841 | .shutdown = at91udc_shutdown, | 1840 | .shutdown = at91udc_shutdown, |
1842 | .suspend = at91udc_suspend, | 1841 | .suspend = at91udc_suspend, |
1843 | .resume = at91udc_resume, | 1842 | .resume = at91udc_resume, |
@@ -1847,15 +1846,15 @@ static struct platform_driver at91_udc = { | |||
1847 | }, | 1846 | }, |
1848 | }; | 1847 | }; |
1849 | 1848 | ||
1850 | static int __devinit udc_init_module(void) | 1849 | static int __init udc_init_module(void) |
1851 | { | 1850 | { |
1852 | return platform_driver_register(&at91_udc); | 1851 | return platform_driver_probe(&at91_udc_driver, at91udc_probe); |
1853 | } | 1852 | } |
1854 | module_init(udc_init_module); | 1853 | module_init(udc_init_module); |
1855 | 1854 | ||
1856 | static void __devexit udc_exit_module(void) | 1855 | static void __exit udc_exit_module(void) |
1857 | { | 1856 | { |
1858 | platform_driver_unregister(&at91_udc); | 1857 | platform_driver_unregister(&at91_udc_driver); |
1859 | } | 1858 | } |
1860 | module_exit(udc_exit_module); | 1859 | module_exit(udc_exit_module); |
1861 | 1860 | ||
diff --git a/drivers/usb/gadget/ether.c b/drivers/usb/gadget/ether.c index 04e6b8508fb6..1dd8b57f4420 100644 --- a/drivers/usb/gadget/ether.c +++ b/drivers/usb/gadget/ether.c | |||
@@ -282,6 +282,9 @@ MODULE_PARM_DESC(host_addr, "Host Ethernet Address"); | |||
282 | #define DEV_CONFIG_CDC | 282 | #define DEV_CONFIG_CDC |
283 | #endif | 283 | #endif |
284 | 284 | ||
285 | #ifdef CONFIG_USB_GADGET_FSL_USB2 | ||
286 | #define DEV_CONFIG_CDC | ||
287 | #endif | ||
285 | 288 | ||
286 | /* For CDC-incapable hardware, choose the simple cdc subset. | 289 | /* For CDC-incapable hardware, choose the simple cdc subset. |
287 | * Anything that talks bulk (without notable bugs) can do this. | 290 | * Anything that talks bulk (without notable bugs) can do this. |
@@ -1735,7 +1738,8 @@ enomem: | |||
1735 | defer_kevent (dev, WORK_RX_MEMORY); | 1738 | defer_kevent (dev, WORK_RX_MEMORY); |
1736 | if (retval) { | 1739 | if (retval) { |
1737 | DEBUG (dev, "rx submit --> %d\n", retval); | 1740 | DEBUG (dev, "rx submit --> %d\n", retval); |
1738 | dev_kfree_skb_any (skb); | 1741 | if (skb) |
1742 | dev_kfree_skb_any(skb); | ||
1739 | spin_lock(&dev->req_lock); | 1743 | spin_lock(&dev->req_lock); |
1740 | list_add (&req->list, &dev->rx_reqs); | 1744 | list_add (&req->list, &dev->rx_reqs); |
1741 | spin_unlock(&dev->req_lock); | 1745 | spin_unlock(&dev->req_lock); |
@@ -1766,7 +1770,6 @@ static void rx_complete (struct usb_ep *ep, struct usb_request *req) | |||
1766 | break; | 1770 | break; |
1767 | } | 1771 | } |
1768 | 1772 | ||
1769 | skb->dev = dev->net; | ||
1770 | skb->protocol = eth_type_trans (skb, dev->net); | 1773 | skb->protocol = eth_type_trans (skb, dev->net); |
1771 | dev->stats.rx_packets++; | 1774 | dev->stats.rx_packets++; |
1772 | dev->stats.rx_bytes += skb->len; | 1775 | dev->stats.rx_bytes += skb->len; |
diff --git a/drivers/usb/gadget/fsl_usb2_udc.c b/drivers/usb/gadget/fsl_usb2_udc.c new file mode 100644 index 000000000000..157054ea3978 --- /dev/null +++ b/drivers/usb/gadget/fsl_usb2_udc.c | |||
@@ -0,0 +1,2500 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2004-2007 Freescale Semicondutor, Inc. All rights reserved. | ||
3 | * | ||
4 | * Author: Li Yang <leoli@freescale.com> | ||
5 | * Jiang Bo <tanya.jiang@freescale.com> | ||
6 | * | ||
7 | * Description: | ||
8 | * Freescale high-speed USB SOC DR module device controller driver. | ||
9 | * This can be found on MPC8349E/MPC8313E cpus. | ||
10 | * The driver is previously named as mpc_udc. Based on bare board | ||
11 | * code from Dave Liu and Shlomi Gridish. | ||
12 | * | ||
13 | * This program is free software; you can redistribute it and/or modify it | ||
14 | * under the terms of the GNU General Public License as published by the | ||
15 | * Free Software Foundation; either version 2 of the License, or (at your | ||
16 | * option) any later version. | ||
17 | */ | ||
18 | |||
19 | #undef VERBOSE | ||
20 | |||
21 | #include <linux/module.h> | ||
22 | #include <linux/kernel.h> | ||
23 | #include <linux/ioport.h> | ||
24 | #include <linux/types.h> | ||
25 | #include <linux/errno.h> | ||
26 | #include <linux/delay.h> | ||
27 | #include <linux/sched.h> | ||
28 | #include <linux/slab.h> | ||
29 | #include <linux/init.h> | ||
30 | #include <linux/timer.h> | ||
31 | #include <linux/list.h> | ||
32 | #include <linux/interrupt.h> | ||
33 | #include <linux/proc_fs.h> | ||
34 | #include <linux/mm.h> | ||
35 | #include <linux/moduleparam.h> | ||
36 | #include <linux/device.h> | ||
37 | #include <linux/usb/ch9.h> | ||
38 | #include <linux/usb_gadget.h> | ||
39 | #include <linux/usb/otg.h> | ||
40 | #include <linux/dma-mapping.h> | ||
41 | #include <linux/platform_device.h> | ||
42 | #include <linux/fsl_devices.h> | ||
43 | #include <linux/dmapool.h> | ||
44 | |||
45 | #include <asm/byteorder.h> | ||
46 | #include <asm/io.h> | ||
47 | #include <asm/irq.h> | ||
48 | #include <asm/system.h> | ||
49 | #include <asm/unaligned.h> | ||
50 | #include <asm/dma.h> | ||
51 | #include <asm/cacheflush.h> | ||
52 | |||
53 | #include "fsl_usb2_udc.h" | ||
54 | |||
55 | #define DRIVER_DESC "Freescale High-Speed USB SOC Device Controller driver" | ||
56 | #define DRIVER_AUTHOR "Li Yang/Jiang Bo" | ||
57 | #define DRIVER_VERSION "Apr 20, 2007" | ||
58 | |||
59 | #define DMA_ADDR_INVALID (~(dma_addr_t)0) | ||
60 | |||
61 | static const char driver_name[] = "fsl-usb2-udc"; | ||
62 | static const char driver_desc[] = DRIVER_DESC; | ||
63 | |||
64 | volatile static struct usb_dr_device *dr_regs = NULL; | ||
65 | volatile static struct usb_sys_interface *usb_sys_regs = NULL; | ||
66 | |||
67 | /* it is initialized in probe() */ | ||
68 | static struct fsl_udc *udc_controller = NULL; | ||
69 | |||
70 | static const struct usb_endpoint_descriptor | ||
71 | fsl_ep0_desc = { | ||
72 | .bLength = USB_DT_ENDPOINT_SIZE, | ||
73 | .bDescriptorType = USB_DT_ENDPOINT, | ||
74 | .bEndpointAddress = 0, | ||
75 | .bmAttributes = USB_ENDPOINT_XFER_CONTROL, | ||
76 | .wMaxPacketSize = USB_MAX_CTRL_PAYLOAD, | ||
77 | }; | ||
78 | |||
79 | static int fsl_udc_suspend(struct platform_device *pdev, pm_message_t state); | ||
80 | static int fsl_udc_resume(struct platform_device *pdev); | ||
81 | static void fsl_ep_fifo_flush(struct usb_ep *_ep); | ||
82 | |||
83 | #ifdef CONFIG_PPC32 | ||
84 | #define fsl_readl(addr) in_le32(addr) | ||
85 | #define fsl_writel(addr, val32) out_le32(val32, addr) | ||
86 | #else | ||
87 | #define fsl_readl(addr) readl(addr) | ||
88 | #define fsl_writel(addr, val32) writel(addr, val32) | ||
89 | #endif | ||
90 | |||
91 | /******************************************************************** | ||
92 | * Internal Used Function | ||
93 | ********************************************************************/ | ||
94 | /*----------------------------------------------------------------- | ||
95 | * done() - retire a request; caller blocked irqs | ||
96 | * @status : request status to be set, only works when | ||
97 | * request is still in progress. | ||
98 | *--------------------------------------------------------------*/ | ||
99 | static void done(struct fsl_ep *ep, struct fsl_req *req, int status) | ||
100 | { | ||
101 | struct fsl_udc *udc = NULL; | ||
102 | unsigned char stopped = ep->stopped; | ||
103 | struct ep_td_struct *curr_td, *next_td; | ||
104 | int j; | ||
105 | |||
106 | udc = (struct fsl_udc *)ep->udc; | ||
107 | /* Removed the req from fsl_ep->queue */ | ||
108 | list_del_init(&req->queue); | ||
109 | |||
110 | /* req.status should be set as -EINPROGRESS in ep_queue() */ | ||
111 | if (req->req.status == -EINPROGRESS) | ||
112 | req->req.status = status; | ||
113 | else | ||
114 | status = req->req.status; | ||
115 | |||
116 | /* Free dtd for the request */ | ||
117 | next_td = req->head; | ||
118 | for (j = 0; j < req->dtd_count; j++) { | ||
119 | curr_td = next_td; | ||
120 | if (j != req->dtd_count - 1) { | ||
121 | next_td = curr_td->next_td_virt; | ||
122 | } | ||
123 | dma_pool_free(udc->td_pool, curr_td, curr_td->td_dma); | ||
124 | } | ||
125 | |||
126 | if (req->mapped) { | ||
127 | dma_unmap_single(ep->udc->gadget.dev.parent, | ||
128 | req->req.dma, req->req.length, | ||
129 | ep_is_in(ep) | ||
130 | ? DMA_TO_DEVICE | ||
131 | : DMA_FROM_DEVICE); | ||
132 | req->req.dma = DMA_ADDR_INVALID; | ||
133 | req->mapped = 0; | ||
134 | } else | ||
135 | dma_sync_single_for_cpu(ep->udc->gadget.dev.parent, | ||
136 | req->req.dma, req->req.length, | ||
137 | ep_is_in(ep) | ||
138 | ? DMA_TO_DEVICE | ||
139 | : DMA_FROM_DEVICE); | ||
140 | |||
141 | if (status && (status != -ESHUTDOWN)) | ||
142 | VDBG("complete %s req %p stat %d len %u/%u", | ||
143 | ep->ep.name, &req->req, status, | ||
144 | req->req.actual, req->req.length); | ||
145 | |||
146 | ep->stopped = 1; | ||
147 | |||
148 | spin_unlock(&ep->udc->lock); | ||
149 | /* complete() is from gadget layer, | ||
150 | * eg fsg->bulk_in_complete() */ | ||
151 | if (req->req.complete) | ||
152 | req->req.complete(&ep->ep, &req->req); | ||
153 | |||
154 | spin_lock(&ep->udc->lock); | ||
155 | ep->stopped = stopped; | ||
156 | } | ||
157 | |||
158 | /*----------------------------------------------------------------- | ||
159 | * nuke(): delete all requests related to this ep | ||
160 | * called with spinlock held | ||
161 | *--------------------------------------------------------------*/ | ||
162 | static void nuke(struct fsl_ep *ep, int status) | ||
163 | { | ||
164 | ep->stopped = 1; | ||
165 | |||
166 | /* Flush fifo */ | ||
167 | fsl_ep_fifo_flush(&ep->ep); | ||
168 | |||
169 | /* Whether this eq has request linked */ | ||
170 | while (!list_empty(&ep->queue)) { | ||
171 | struct fsl_req *req = NULL; | ||
172 | |||
173 | req = list_entry(ep->queue.next, struct fsl_req, queue); | ||
174 | done(ep, req, status); | ||
175 | } | ||
176 | } | ||
177 | |||
178 | /*------------------------------------------------------------------ | ||
179 | Internal Hardware related function | ||
180 | ------------------------------------------------------------------*/ | ||
181 | |||
182 | static int dr_controller_setup(struct fsl_udc *udc) | ||
183 | { | ||
184 | unsigned int tmp = 0, portctrl = 0, ctrl = 0; | ||
185 | unsigned long timeout; | ||
186 | #define FSL_UDC_RESET_TIMEOUT 1000 | ||
187 | |||
188 | /* before here, make sure dr_regs has been initialized */ | ||
189 | if (!udc) | ||
190 | return -EINVAL; | ||
191 | |||
192 | /* Stop and reset the usb controller */ | ||
193 | tmp = fsl_readl(&dr_regs->usbcmd); | ||
194 | tmp &= ~USB_CMD_RUN_STOP; | ||
195 | fsl_writel(tmp, &dr_regs->usbcmd); | ||
196 | |||
197 | tmp = fsl_readl(&dr_regs->usbcmd); | ||
198 | tmp |= USB_CMD_CTRL_RESET; | ||
199 | fsl_writel(tmp, &dr_regs->usbcmd); | ||
200 | |||
201 | /* Wait for reset to complete */ | ||
202 | timeout = jiffies + FSL_UDC_RESET_TIMEOUT; | ||
203 | while (fsl_readl(&dr_regs->usbcmd) & USB_CMD_CTRL_RESET) { | ||
204 | if (time_after(jiffies, timeout)) { | ||
205 | ERR("udc reset timeout! \n"); | ||
206 | return -ETIMEDOUT; | ||
207 | } | ||
208 | cpu_relax(); | ||
209 | } | ||
210 | |||
211 | /* Set the controller as device mode */ | ||
212 | tmp = fsl_readl(&dr_regs->usbmode); | ||
213 | tmp |= USB_MODE_CTRL_MODE_DEVICE; | ||
214 | /* Disable Setup Lockout */ | ||
215 | tmp |= USB_MODE_SETUP_LOCK_OFF; | ||
216 | fsl_writel(tmp, &dr_regs->usbmode); | ||
217 | |||
218 | /* Clear the setup status */ | ||
219 | fsl_writel(0, &dr_regs->usbsts); | ||
220 | |||
221 | tmp = udc->ep_qh_dma; | ||
222 | tmp &= USB_EP_LIST_ADDRESS_MASK; | ||
223 | fsl_writel(tmp, &dr_regs->endpointlistaddr); | ||
224 | |||
225 | VDBG("vir[qh_base] is %p phy[qh_base] is 0x%8x reg is 0x%8x", | ||
226 | (int)udc->ep_qh, (int)tmp, | ||
227 | fsl_readl(&dr_regs->endpointlistaddr)); | ||
228 | |||
229 | /* Config PHY interface */ | ||
230 | portctrl = fsl_readl(&dr_regs->portsc1); | ||
231 | portctrl &= ~PORTSCX_PHY_TYPE_SEL; | ||
232 | switch (udc->phy_mode) { | ||
233 | case FSL_USB2_PHY_ULPI: | ||
234 | portctrl |= PORTSCX_PTS_ULPI; | ||
235 | break; | ||
236 | case FSL_USB2_PHY_UTMI: | ||
237 | case FSL_USB2_PHY_UTMI_WIDE: | ||
238 | portctrl |= PORTSCX_PTS_UTMI; | ||
239 | break; | ||
240 | case FSL_USB2_PHY_SERIAL: | ||
241 | portctrl |= PORTSCX_PTS_FSLS; | ||
242 | break; | ||
243 | default: | ||
244 | return -EINVAL; | ||
245 | } | ||
246 | fsl_writel(portctrl, &dr_regs->portsc1); | ||
247 | |||
248 | /* Config control enable i/o output, cpu endian register */ | ||
249 | ctrl = __raw_readl(&usb_sys_regs->control); | ||
250 | ctrl |= USB_CTRL_IOENB; | ||
251 | __raw_writel(ctrl, &usb_sys_regs->control); | ||
252 | |||
253 | #if defined(CONFIG_PPC32) && !defined(CONFIG_NOT_COHERENT_CACHE) | ||
254 | /* Turn on cache snooping hardware, since some PowerPC platforms | ||
255 | * wholly rely on hardware to deal with cache coherent. */ | ||
256 | |||
257 | /* Setup Snooping for all the 4GB space */ | ||
258 | tmp = SNOOP_SIZE_2GB; /* starts from 0x0, size 2G */ | ||
259 | __raw_writel(tmp, &usb_sys_regs->snoop1); | ||
260 | tmp |= 0x80000000; /* starts from 0x8000000, size 2G */ | ||
261 | __raw_writel(tmp, &usb_sys_regs->snoop2); | ||
262 | #endif | ||
263 | |||
264 | return 0; | ||
265 | } | ||
266 | |||
267 | /* Enable DR irq and set controller to run state */ | ||
268 | static void dr_controller_run(struct fsl_udc *udc) | ||
269 | { | ||
270 | u32 temp; | ||
271 | |||
272 | /* Enable DR irq reg */ | ||
273 | temp = USB_INTR_INT_EN | USB_INTR_ERR_INT_EN | ||
274 | | USB_INTR_PTC_DETECT_EN | USB_INTR_RESET_EN | ||
275 | | USB_INTR_DEVICE_SUSPEND | USB_INTR_SYS_ERR_EN; | ||
276 | |||
277 | fsl_writel(temp, &dr_regs->usbintr); | ||
278 | |||
279 | /* Clear stopped bit */ | ||
280 | udc->stopped = 0; | ||
281 | |||
282 | /* Set the controller as device mode */ | ||
283 | temp = fsl_readl(&dr_regs->usbmode); | ||
284 | temp |= USB_MODE_CTRL_MODE_DEVICE; | ||
285 | fsl_writel(temp, &dr_regs->usbmode); | ||
286 | |||
287 | /* Set controller to Run */ | ||
288 | temp = fsl_readl(&dr_regs->usbcmd); | ||
289 | temp |= USB_CMD_RUN_STOP; | ||
290 | fsl_writel(temp, &dr_regs->usbcmd); | ||
291 | |||
292 | return; | ||
293 | } | ||
294 | |||
295 | static void dr_controller_stop(struct fsl_udc *udc) | ||
296 | { | ||
297 | unsigned int tmp; | ||
298 | |||
299 | /* disable all INTR */ | ||
300 | fsl_writel(0, &dr_regs->usbintr); | ||
301 | |||
302 | /* Set stopped bit for isr */ | ||
303 | udc->stopped = 1; | ||
304 | |||
305 | /* disable IO output */ | ||
306 | /* usb_sys_regs->control = 0; */ | ||
307 | |||
308 | /* set controller to Stop */ | ||
309 | tmp = fsl_readl(&dr_regs->usbcmd); | ||
310 | tmp &= ~USB_CMD_RUN_STOP; | ||
311 | fsl_writel(tmp, &dr_regs->usbcmd); | ||
312 | |||
313 | return; | ||
314 | } | ||
315 | |||
316 | void dr_ep_setup(unsigned char ep_num, unsigned char dir, unsigned char ep_type) | ||
317 | { | ||
318 | unsigned int tmp_epctrl = 0; | ||
319 | |||
320 | tmp_epctrl = fsl_readl(&dr_regs->endptctrl[ep_num]); | ||
321 | if (dir) { | ||
322 | if (ep_num) | ||
323 | tmp_epctrl |= EPCTRL_TX_DATA_TOGGLE_RST; | ||
324 | tmp_epctrl |= EPCTRL_TX_ENABLE; | ||
325 | tmp_epctrl |= ((unsigned int)(ep_type) | ||
326 | << EPCTRL_TX_EP_TYPE_SHIFT); | ||
327 | } else { | ||
328 | if (ep_num) | ||
329 | tmp_epctrl |= EPCTRL_RX_DATA_TOGGLE_RST; | ||
330 | tmp_epctrl |= EPCTRL_RX_ENABLE; | ||
331 | tmp_epctrl |= ((unsigned int)(ep_type) | ||
332 | << EPCTRL_RX_EP_TYPE_SHIFT); | ||
333 | } | ||
334 | |||
335 | fsl_writel(tmp_epctrl, &dr_regs->endptctrl[ep_num]); | ||
336 | } | ||
337 | |||
338 | static void | ||
339 | dr_ep_change_stall(unsigned char ep_num, unsigned char dir, int value) | ||
340 | { | ||
341 | u32 tmp_epctrl = 0; | ||
342 | |||
343 | tmp_epctrl = fsl_readl(&dr_regs->endptctrl[ep_num]); | ||
344 | |||
345 | if (value) { | ||
346 | /* set the stall bit */ | ||
347 | if (dir) | ||
348 | tmp_epctrl |= EPCTRL_TX_EP_STALL; | ||
349 | else | ||
350 | tmp_epctrl |= EPCTRL_RX_EP_STALL; | ||
351 | } else { | ||
352 | /* clear the stall bit and reset data toggle */ | ||
353 | if (dir) { | ||
354 | tmp_epctrl &= ~EPCTRL_TX_EP_STALL; | ||
355 | tmp_epctrl |= EPCTRL_TX_DATA_TOGGLE_RST; | ||
356 | } else { | ||
357 | tmp_epctrl &= ~EPCTRL_RX_EP_STALL; | ||
358 | tmp_epctrl |= EPCTRL_RX_DATA_TOGGLE_RST; | ||
359 | } | ||
360 | } | ||
361 | fsl_writel(tmp_epctrl, &dr_regs->endptctrl[ep_num]); | ||
362 | } | ||
363 | |||
364 | /* Get stall status of a specific ep | ||
365 | Return: 0: not stalled; 1:stalled */ | ||
366 | static int dr_ep_get_stall(unsigned char ep_num, unsigned char dir) | ||
367 | { | ||
368 | u32 epctrl; | ||
369 | |||
370 | epctrl = fsl_readl(&dr_regs->endptctrl[ep_num]); | ||
371 | if (dir) | ||
372 | return (epctrl & EPCTRL_TX_EP_STALL) ? 1 : 0; | ||
373 | else | ||
374 | return (epctrl & EPCTRL_RX_EP_STALL) ? 1 : 0; | ||
375 | } | ||
376 | |||
377 | /******************************************************************** | ||
378 | Internal Structure Build up functions | ||
379 | ********************************************************************/ | ||
380 | |||
381 | /*------------------------------------------------------------------ | ||
382 | * struct_ep_qh_setup(): set the Endpoint Capabilites field of QH | ||
383 | * @zlt: Zero Length Termination Select (1: disable; 0: enable) | ||
384 | * @mult: Mult field | ||
385 | ------------------------------------------------------------------*/ | ||
386 | static void struct_ep_qh_setup(struct fsl_udc *udc, unsigned char ep_num, | ||
387 | unsigned char dir, unsigned char ep_type, | ||
388 | unsigned int max_pkt_len, | ||
389 | unsigned int zlt, unsigned char mult) | ||
390 | { | ||
391 | struct ep_queue_head *p_QH = &udc->ep_qh[2 * ep_num + dir]; | ||
392 | unsigned int tmp = 0; | ||
393 | |||
394 | /* set the Endpoint Capabilites in QH */ | ||
395 | switch (ep_type) { | ||
396 | case USB_ENDPOINT_XFER_CONTROL: | ||
397 | /* Interrupt On Setup (IOS). for control ep */ | ||
398 | tmp = (max_pkt_len << EP_QUEUE_HEAD_MAX_PKT_LEN_POS) | ||
399 | | EP_QUEUE_HEAD_IOS; | ||
400 | break; | ||
401 | case USB_ENDPOINT_XFER_ISOC: | ||
402 | tmp = (max_pkt_len << EP_QUEUE_HEAD_MAX_PKT_LEN_POS) | ||
403 | | (mult << EP_QUEUE_HEAD_MULT_POS); | ||
404 | break; | ||
405 | case USB_ENDPOINT_XFER_BULK: | ||
406 | case USB_ENDPOINT_XFER_INT: | ||
407 | tmp = max_pkt_len << EP_QUEUE_HEAD_MAX_PKT_LEN_POS; | ||
408 | break; | ||
409 | default: | ||
410 | VDBG("error ep type is %d", ep_type); | ||
411 | return; | ||
412 | } | ||
413 | if (zlt) | ||
414 | tmp |= EP_QUEUE_HEAD_ZLT_SEL; | ||
415 | p_QH->max_pkt_length = cpu_to_le32(tmp); | ||
416 | |||
417 | return; | ||
418 | } | ||
419 | |||
420 | /* Setup qh structure and ep register for ep0. */ | ||
421 | static void ep0_setup(struct fsl_udc *udc) | ||
422 | { | ||
423 | /* the intialization of an ep includes: fields in QH, Regs, | ||
424 | * fsl_ep struct */ | ||
425 | struct_ep_qh_setup(udc, 0, USB_RECV, USB_ENDPOINT_XFER_CONTROL, | ||
426 | USB_MAX_CTRL_PAYLOAD, 0, 0); | ||
427 | struct_ep_qh_setup(udc, 0, USB_SEND, USB_ENDPOINT_XFER_CONTROL, | ||
428 | USB_MAX_CTRL_PAYLOAD, 0, 0); | ||
429 | dr_ep_setup(0, USB_RECV, USB_ENDPOINT_XFER_CONTROL); | ||
430 | dr_ep_setup(0, USB_SEND, USB_ENDPOINT_XFER_CONTROL); | ||
431 | |||
432 | return; | ||
433 | |||
434 | } | ||
435 | |||
436 | /*********************************************************************** | ||
437 | Endpoint Management Functions | ||
438 | ***********************************************************************/ | ||
439 | |||
440 | /*------------------------------------------------------------------------- | ||
441 | * when configurations are set, or when interface settings change | ||
442 | * for example the do_set_interface() in gadget layer, | ||
443 | * the driver will enable or disable the relevant endpoints | ||
444 | * ep0 doesn't use this routine. It is always enabled. | ||
445 | -------------------------------------------------------------------------*/ | ||
446 | static int fsl_ep_enable(struct usb_ep *_ep, | ||
447 | const struct usb_endpoint_descriptor *desc) | ||
448 | { | ||
449 | struct fsl_udc *udc = NULL; | ||
450 | struct fsl_ep *ep = NULL; | ||
451 | unsigned short max = 0; | ||
452 | unsigned char mult = 0, zlt; | ||
453 | int retval = -EINVAL; | ||
454 | unsigned long flags = 0; | ||
455 | |||
456 | ep = container_of(_ep, struct fsl_ep, ep); | ||
457 | |||
458 | /* catch various bogus parameters */ | ||
459 | if (!_ep || !desc || ep->desc | ||
460 | || (desc->bDescriptorType != USB_DT_ENDPOINT)) | ||
461 | return -EINVAL; | ||
462 | |||
463 | udc = ep->udc; | ||
464 | |||
465 | if (!udc->driver || (udc->gadget.speed == USB_SPEED_UNKNOWN)) | ||
466 | return -ESHUTDOWN; | ||
467 | |||
468 | max = le16_to_cpu(desc->wMaxPacketSize); | ||
469 | |||
470 | /* Disable automatic zlp generation. Driver is reponsible to indicate | ||
471 | * explicitly through req->req.zero. This is needed to enable multi-td | ||
472 | * request. */ | ||
473 | zlt = 1; | ||
474 | |||
475 | /* Assume the max packet size from gadget is always correct */ | ||
476 | switch (desc->bmAttributes & 0x03) { | ||
477 | case USB_ENDPOINT_XFER_CONTROL: | ||
478 | case USB_ENDPOINT_XFER_BULK: | ||
479 | case USB_ENDPOINT_XFER_INT: | ||
480 | /* mult = 0. Execute N Transactions as demonstrated by | ||
481 | * the USB variable length packet protocol where N is | ||
482 | * computed using the Maximum Packet Length (dQH) and | ||
483 | * the Total Bytes field (dTD) */ | ||
484 | mult = 0; | ||
485 | break; | ||
486 | case USB_ENDPOINT_XFER_ISOC: | ||
487 | /* Calculate transactions needed for high bandwidth iso */ | ||
488 | mult = (unsigned char)(1 + ((max >> 11) & 0x03)); | ||
489 | max = max & 0x8ff; /* bit 0~10 */ | ||
490 | /* 3 transactions at most */ | ||
491 | if (mult > 3) | ||
492 | goto en_done; | ||
493 | break; | ||
494 | default: | ||
495 | goto en_done; | ||
496 | } | ||
497 | |||
498 | spin_lock_irqsave(&udc->lock, flags); | ||
499 | ep->ep.maxpacket = max; | ||
500 | ep->desc = desc; | ||
501 | ep->stopped = 0; | ||
502 | |||
503 | /* Controller related setup */ | ||
504 | /* Init EPx Queue Head (Ep Capabilites field in QH | ||
505 | * according to max, zlt, mult) */ | ||
506 | struct_ep_qh_setup(udc, (unsigned char) ep_index(ep), | ||
507 | (unsigned char) ((desc->bEndpointAddress & USB_DIR_IN) | ||
508 | ? USB_SEND : USB_RECV), | ||
509 | (unsigned char) (desc->bmAttributes | ||
510 | & USB_ENDPOINT_XFERTYPE_MASK), | ||
511 | max, zlt, mult); | ||
512 | |||
513 | /* Init endpoint ctrl register */ | ||
514 | dr_ep_setup((unsigned char) ep_index(ep), | ||
515 | (unsigned char) ((desc->bEndpointAddress & USB_DIR_IN) | ||
516 | ? USB_SEND : USB_RECV), | ||
517 | (unsigned char) (desc->bmAttributes | ||
518 | & USB_ENDPOINT_XFERTYPE_MASK)); | ||
519 | |||
520 | spin_unlock_irqrestore(&udc->lock, flags); | ||
521 | retval = 0; | ||
522 | |||
523 | VDBG("enabled %s (ep%d%s) maxpacket %d",ep->ep.name, | ||
524 | ep->desc->bEndpointAddress & 0x0f, | ||
525 | (desc->bEndpointAddress & USB_DIR_IN) | ||
526 | ? "in" : "out", max); | ||
527 | en_done: | ||
528 | return retval; | ||
529 | } | ||
530 | |||
531 | /*--------------------------------------------------------------------- | ||
532 | * @ep : the ep being unconfigured. May not be ep0 | ||
533 | * Any pending and uncomplete req will complete with status (-ESHUTDOWN) | ||
534 | *---------------------------------------------------------------------*/ | ||
535 | static int fsl_ep_disable(struct usb_ep *_ep) | ||
536 | { | ||
537 | struct fsl_udc *udc = NULL; | ||
538 | struct fsl_ep *ep = NULL; | ||
539 | unsigned long flags = 0; | ||
540 | u32 epctrl; | ||
541 | int ep_num; | ||
542 | |||
543 | ep = container_of(_ep, struct fsl_ep, ep); | ||
544 | if (!_ep || !ep->desc) { | ||
545 | VDBG("%s not enabled", _ep ? ep->ep.name : NULL); | ||
546 | return -EINVAL; | ||
547 | } | ||
548 | |||
549 | /* disable ep on controller */ | ||
550 | ep_num = ep_index(ep); | ||
551 | epctrl = fsl_readl(&dr_regs->endptctrl[ep_num]); | ||
552 | if (ep_is_in(ep)) | ||
553 | epctrl &= ~EPCTRL_TX_ENABLE; | ||
554 | else | ||
555 | epctrl &= ~EPCTRL_RX_ENABLE; | ||
556 | fsl_writel(epctrl, &dr_regs->endptctrl[ep_num]); | ||
557 | |||
558 | udc = (struct fsl_udc *)ep->udc; | ||
559 | spin_lock_irqsave(&udc->lock, flags); | ||
560 | |||
561 | /* nuke all pending requests (does flush) */ | ||
562 | nuke(ep, -ESHUTDOWN); | ||
563 | |||
564 | ep->desc = 0; | ||
565 | ep->stopped = 1; | ||
566 | spin_unlock_irqrestore(&udc->lock, flags); | ||
567 | |||
568 | VDBG("disabled %s OK", _ep->name); | ||
569 | return 0; | ||
570 | } | ||
571 | |||
572 | /*--------------------------------------------------------------------- | ||
573 | * allocate a request object used by this endpoint | ||
574 | * the main operation is to insert the req->queue to the eq->queue | ||
575 | * Returns the request, or null if one could not be allocated | ||
576 | *---------------------------------------------------------------------*/ | ||
577 | static struct usb_request * | ||
578 | fsl_alloc_request(struct usb_ep *_ep, gfp_t gfp_flags) | ||
579 | { | ||
580 | struct fsl_req *req = NULL; | ||
581 | |||
582 | req = kzalloc(sizeof *req, gfp_flags); | ||
583 | if (!req) | ||
584 | return NULL; | ||
585 | |||
586 | req->req.dma = DMA_ADDR_INVALID; | ||
587 | INIT_LIST_HEAD(&req->queue); | ||
588 | |||
589 | return &req->req; | ||
590 | } | ||
591 | |||
592 | static void fsl_free_request(struct usb_ep *_ep, struct usb_request *_req) | ||
593 | { | ||
594 | struct fsl_req *req = NULL; | ||
595 | |||
596 | req = container_of(_req, struct fsl_req, req); | ||
597 | |||
598 | if (_req) | ||
599 | kfree(req); | ||
600 | } | ||
601 | |||
602 | /*------------------------------------------------------------------ | ||
603 | * Allocate an I/O buffer | ||
604 | *---------------------------------------------------------------------*/ | ||
605 | static void *fsl_alloc_buffer(struct usb_ep *_ep, unsigned bytes, | ||
606 | dma_addr_t *dma, gfp_t gfp_flags) | ||
607 | { | ||
608 | struct fsl_ep *ep; | ||
609 | |||
610 | if (!_ep) | ||
611 | return NULL; | ||
612 | |||
613 | ep = container_of(_ep, struct fsl_ep, ep); | ||
614 | |||
615 | return dma_alloc_coherent(ep->udc->gadget.dev.parent, | ||
616 | bytes, dma, gfp_flags); | ||
617 | } | ||
618 | |||
619 | /*------------------------------------------------------------------ | ||
620 | * frees an i/o buffer | ||
621 | *---------------------------------------------------------------------*/ | ||
622 | static void fsl_free_buffer(struct usb_ep *_ep, void *buf, | ||
623 | dma_addr_t dma, unsigned bytes) | ||
624 | { | ||
625 | struct fsl_ep *ep; | ||
626 | |||
627 | if (!_ep) | ||
628 | return NULL; | ||
629 | |||
630 | ep = container_of(_ep, struct fsl_ep, ep); | ||
631 | |||
632 | dma_free_coherent(ep->udc->gadget.dev.parent, bytes, buf, dma); | ||
633 | } | ||
634 | |||
635 | /*-------------------------------------------------------------------------*/ | ||
636 | static int fsl_queue_td(struct fsl_ep *ep, struct fsl_req *req) | ||
637 | { | ||
638 | int i = ep_index(ep) * 2 + ep_is_in(ep); | ||
639 | u32 temp, bitmask, tmp_stat; | ||
640 | struct ep_queue_head *dQH = &ep->udc->ep_qh[i]; | ||
641 | |||
642 | /* VDBG("QH addr Register 0x%8x", dr_regs->endpointlistaddr); | ||
643 | VDBG("ep_qh[%d] addr is 0x%8x", i, (u32)&(ep->udc->ep_qh[i])); */ | ||
644 | |||
645 | bitmask = ep_is_in(ep) | ||
646 | ? (1 << (ep_index(ep) + 16)) | ||
647 | : (1 << (ep_index(ep))); | ||
648 | |||
649 | /* check if the pipe is empty */ | ||
650 | if (!(list_empty(&ep->queue))) { | ||
651 | /* Add td to the end */ | ||
652 | struct fsl_req *lastreq; | ||
653 | lastreq = list_entry(ep->queue.prev, struct fsl_req, queue); | ||
654 | lastreq->tail->next_td_ptr = | ||
655 | cpu_to_le32(req->head->td_dma & DTD_ADDR_MASK); | ||
656 | /* Read prime bit, if 1 goto done */ | ||
657 | if (fsl_readl(&dr_regs->endpointprime) & bitmask) | ||
658 | goto out; | ||
659 | |||
660 | do { | ||
661 | /* Set ATDTW bit in USBCMD */ | ||
662 | temp = fsl_readl(&dr_regs->usbcmd); | ||
663 | fsl_writel(temp | USB_CMD_ATDTW, &dr_regs->usbcmd); | ||
664 | |||
665 | /* Read correct status bit */ | ||
666 | tmp_stat = fsl_readl(&dr_regs->endptstatus) & bitmask; | ||
667 | |||
668 | } while (!(fsl_readl(&dr_regs->usbcmd) & USB_CMD_ATDTW)); | ||
669 | |||
670 | /* Write ATDTW bit to 0 */ | ||
671 | temp = fsl_readl(&dr_regs->usbcmd); | ||
672 | fsl_writel(temp & ~USB_CMD_ATDTW, &dr_regs->usbcmd); | ||
673 | |||
674 | if (tmp_stat) | ||
675 | goto out; | ||
676 | } | ||
677 | |||
678 | /* Write dQH next pointer and terminate bit to 0 */ | ||
679 | temp = req->head->td_dma & EP_QUEUE_HEAD_NEXT_POINTER_MASK; | ||
680 | dQH->next_dtd_ptr = cpu_to_le32(temp); | ||
681 | |||
682 | /* Clear active and halt bit */ | ||
683 | temp = cpu_to_le32(~(EP_QUEUE_HEAD_STATUS_ACTIVE | ||
684 | | EP_QUEUE_HEAD_STATUS_HALT)); | ||
685 | dQH->size_ioc_int_sts &= temp; | ||
686 | |||
687 | /* Prime endpoint by writing 1 to ENDPTPRIME */ | ||
688 | temp = ep_is_in(ep) | ||
689 | ? (1 << (ep_index(ep) + 16)) | ||
690 | : (1 << (ep_index(ep))); | ||
691 | fsl_writel(temp, &dr_regs->endpointprime); | ||
692 | out: | ||
693 | return 0; | ||
694 | } | ||
695 | |||
696 | /* Fill in the dTD structure | ||
697 | * @req: request that the transfer belongs to | ||
698 | * @length: return actually data length of the dTD | ||
699 | * @dma: return dma address of the dTD | ||
700 | * @is_last: return flag if it is the last dTD of the request | ||
701 | * return: pointer to the built dTD */ | ||
702 | static struct ep_td_struct *fsl_build_dtd(struct fsl_req *req, unsigned *length, | ||
703 | dma_addr_t *dma, int *is_last) | ||
704 | { | ||
705 | u32 swap_temp; | ||
706 | struct ep_td_struct *dtd; | ||
707 | |||
708 | /* how big will this transfer be? */ | ||
709 | *length = min(req->req.length - req->req.actual, | ||
710 | (unsigned)EP_MAX_LENGTH_TRANSFER); | ||
711 | |||
712 | dtd = dma_pool_alloc(udc_controller->td_pool, GFP_KERNEL, dma); | ||
713 | if (dtd == NULL) | ||
714 | return dtd; | ||
715 | |||
716 | dtd->td_dma = *dma; | ||
717 | /* Clear reserved field */ | ||
718 | swap_temp = cpu_to_le32(dtd->size_ioc_sts); | ||
719 | swap_temp &= ~DTD_RESERVED_FIELDS; | ||
720 | dtd->size_ioc_sts = cpu_to_le32(swap_temp); | ||
721 | |||
722 | /* Init all of buffer page pointers */ | ||
723 | swap_temp = (u32) (req->req.dma + req->req.actual); | ||
724 | dtd->buff_ptr0 = cpu_to_le32(swap_temp); | ||
725 | dtd->buff_ptr1 = cpu_to_le32(swap_temp + 0x1000); | ||
726 | dtd->buff_ptr2 = cpu_to_le32(swap_temp + 0x2000); | ||
727 | dtd->buff_ptr3 = cpu_to_le32(swap_temp + 0x3000); | ||
728 | dtd->buff_ptr4 = cpu_to_le32(swap_temp + 0x4000); | ||
729 | |||
730 | req->req.actual += *length; | ||
731 | |||
732 | /* zlp is needed if req->req.zero is set */ | ||
733 | if (req->req.zero) { | ||
734 | if (*length == 0 || (*length % req->ep->ep.maxpacket) != 0) | ||
735 | *is_last = 1; | ||
736 | else | ||
737 | *is_last = 0; | ||
738 | } else if (req->req.length == req->req.actual) | ||
739 | *is_last = 1; | ||
740 | else | ||
741 | *is_last = 0; | ||
742 | |||
743 | if ((*is_last) == 0) | ||
744 | VDBG("multi-dtd request!\n"); | ||
745 | /* Fill in the transfer size; set active bit */ | ||
746 | swap_temp = ((*length << DTD_LENGTH_BIT_POS) | DTD_STATUS_ACTIVE); | ||
747 | |||
748 | /* Enable interrupt for the last dtd of a request */ | ||
749 | if (*is_last && !req->req.no_interrupt) | ||
750 | swap_temp |= DTD_IOC; | ||
751 | |||
752 | dtd->size_ioc_sts = cpu_to_le32(swap_temp); | ||
753 | |||
754 | mb(); | ||
755 | |||
756 | VDBG("length = %d address= 0x%x", *length, (int)*dma); | ||
757 | |||
758 | return dtd; | ||
759 | } | ||
760 | |||
761 | /* Generate dtd chain for a request */ | ||
762 | static int fsl_req_to_dtd(struct fsl_req *req) | ||
763 | { | ||
764 | unsigned count; | ||
765 | int is_last; | ||
766 | int is_first =1; | ||
767 | struct ep_td_struct *last_dtd = NULL, *dtd; | ||
768 | dma_addr_t dma; | ||
769 | |||
770 | do { | ||
771 | dtd = fsl_build_dtd(req, &count, &dma, &is_last); | ||
772 | if (dtd == NULL) | ||
773 | return -ENOMEM; | ||
774 | |||
775 | if (is_first) { | ||
776 | is_first = 0; | ||
777 | req->head = dtd; | ||
778 | } else { | ||
779 | last_dtd->next_td_ptr = cpu_to_le32(dma); | ||
780 | last_dtd->next_td_virt = dtd; | ||
781 | } | ||
782 | last_dtd = dtd; | ||
783 | |||
784 | req->dtd_count++; | ||
785 | } while (!is_last); | ||
786 | |||
787 | dtd->next_td_ptr = cpu_to_le32(DTD_NEXT_TERMINATE); | ||
788 | |||
789 | req->tail = dtd; | ||
790 | |||
791 | return 0; | ||
792 | } | ||
793 | |||
794 | /* queues (submits) an I/O request to an endpoint */ | ||
795 | static int | ||
796 | fsl_ep_queue(struct usb_ep *_ep, struct usb_request *_req, gfp_t gfp_flags) | ||
797 | { | ||
798 | struct fsl_ep *ep = container_of(_ep, struct fsl_ep, ep); | ||
799 | struct fsl_req *req = container_of(_req, struct fsl_req, req); | ||
800 | struct fsl_udc *udc; | ||
801 | unsigned long flags; | ||
802 | int is_iso = 0; | ||
803 | |||
804 | /* catch various bogus parameters */ | ||
805 | if (!_req || !req->req.complete || !req->req.buf | ||
806 | || !list_empty(&req->queue)) { | ||
807 | VDBG("%s, bad params\n", __FUNCTION__); | ||
808 | return -EINVAL; | ||
809 | } | ||
810 | if (!_ep || (!ep->desc && ep_index(ep))) { | ||
811 | VDBG("%s, bad ep\n", __FUNCTION__); | ||
812 | return -EINVAL; | ||
813 | } | ||
814 | if (ep->desc->bmAttributes == USB_ENDPOINT_XFER_ISOC) { | ||
815 | if (req->req.length > ep->ep.maxpacket) | ||
816 | return -EMSGSIZE; | ||
817 | is_iso = 1; | ||
818 | } | ||
819 | |||
820 | udc = ep->udc; | ||
821 | if (!udc->driver || udc->gadget.speed == USB_SPEED_UNKNOWN) | ||
822 | return -ESHUTDOWN; | ||
823 | |||
824 | req->ep = ep; | ||
825 | |||
826 | /* map virtual address to hardware */ | ||
827 | if (req->req.dma == DMA_ADDR_INVALID) { | ||
828 | req->req.dma = dma_map_single(ep->udc->gadget.dev.parent, | ||
829 | req->req.buf, | ||
830 | req->req.length, ep_is_in(ep) | ||
831 | ? DMA_TO_DEVICE | ||
832 | : DMA_FROM_DEVICE); | ||
833 | req->mapped = 1; | ||
834 | } else { | ||
835 | dma_sync_single_for_device(ep->udc->gadget.dev.parent, | ||
836 | req->req.dma, req->req.length, | ||
837 | ep_is_in(ep) | ||
838 | ? DMA_TO_DEVICE | ||
839 | : DMA_FROM_DEVICE); | ||
840 | req->mapped = 0; | ||
841 | } | ||
842 | |||
843 | req->req.status = -EINPROGRESS; | ||
844 | req->req.actual = 0; | ||
845 | req->dtd_count = 0; | ||
846 | |||
847 | spin_lock_irqsave(&udc->lock, flags); | ||
848 | |||
849 | /* build dtds and push them to device queue */ | ||
850 | if (!fsl_req_to_dtd(req)) { | ||
851 | fsl_queue_td(ep, req); | ||
852 | } else { | ||
853 | spin_unlock_irqrestore(&udc->lock, flags); | ||
854 | return -ENOMEM; | ||
855 | } | ||
856 | |||
857 | /* Update ep0 state */ | ||
858 | if ((ep_index(ep) == 0)) | ||
859 | udc->ep0_state = DATA_STATE_XMIT; | ||
860 | |||
861 | /* irq handler advances the queue */ | ||
862 | if (req != NULL) | ||
863 | list_add_tail(&req->queue, &ep->queue); | ||
864 | spin_unlock_irqrestore(&udc->lock, flags); | ||
865 | |||
866 | return 0; | ||
867 | } | ||
868 | |||
869 | /* dequeues (cancels, unlinks) an I/O request from an endpoint */ | ||
870 | static int fsl_ep_dequeue(struct usb_ep *_ep, struct usb_request *_req) | ||
871 | { | ||
872 | struct fsl_ep *ep = container_of(_ep, struct fsl_ep, ep); | ||
873 | struct fsl_req *req; | ||
874 | unsigned long flags; | ||
875 | int ep_num, stopped, ret = 0; | ||
876 | u32 epctrl; | ||
877 | |||
878 | if (!_ep || !_req) | ||
879 | return -EINVAL; | ||
880 | |||
881 | spin_lock_irqsave(&ep->udc->lock, flags); | ||
882 | stopped = ep->stopped; | ||
883 | |||
884 | /* Stop the ep before we deal with the queue */ | ||
885 | ep->stopped = 1; | ||
886 | ep_num = ep_index(ep); | ||
887 | epctrl = fsl_readl(&dr_regs->endptctrl[ep_num]); | ||
888 | if (ep_is_in(ep)) | ||
889 | epctrl &= ~EPCTRL_TX_ENABLE; | ||
890 | else | ||
891 | epctrl &= ~EPCTRL_RX_ENABLE; | ||
892 | fsl_writel(epctrl, &dr_regs->endptctrl[ep_num]); | ||
893 | |||
894 | /* make sure it's actually queued on this endpoint */ | ||
895 | list_for_each_entry(req, &ep->queue, queue) { | ||
896 | if (&req->req == _req) | ||
897 | break; | ||
898 | } | ||
899 | if (&req->req != _req) { | ||
900 | ret = -EINVAL; | ||
901 | goto out; | ||
902 | } | ||
903 | |||
904 | /* The request is in progress, or completed but not dequeued */ | ||
905 | if (ep->queue.next == &req->queue) { | ||
906 | _req->status = -ECONNRESET; | ||
907 | fsl_ep_fifo_flush(_ep); /* flush current transfer */ | ||
908 | |||
909 | /* The request isn't the last request in this ep queue */ | ||
910 | if (req->queue.next != &ep->queue) { | ||
911 | struct ep_queue_head *qh; | ||
912 | struct fsl_req *next_req; | ||
913 | |||
914 | qh = ep->qh; | ||
915 | next_req = list_entry(req->queue.next, struct fsl_req, | ||
916 | queue); | ||
917 | |||
918 | /* Point the QH to the first TD of next request */ | ||
919 | fsl_writel((u32) next_req->head, &qh->curr_dtd_ptr); | ||
920 | } | ||
921 | |||
922 | /* The request hasn't been processed, patch up the TD chain */ | ||
923 | } else { | ||
924 | struct fsl_req *prev_req; | ||
925 | |||
926 | prev_req = list_entry(req->queue.prev, struct fsl_req, queue); | ||
927 | fsl_writel(fsl_readl(&req->tail->next_td_ptr), | ||
928 | &prev_req->tail->next_td_ptr); | ||
929 | |||
930 | } | ||
931 | |||
932 | done(ep, req, -ECONNRESET); | ||
933 | |||
934 | /* Enable EP */ | ||
935 | out: epctrl = fsl_readl(&dr_regs->endptctrl[ep_num]); | ||
936 | if (ep_is_in(ep)) | ||
937 | epctrl |= EPCTRL_TX_ENABLE; | ||
938 | else | ||
939 | epctrl |= EPCTRL_RX_ENABLE; | ||
940 | fsl_writel(epctrl, &dr_regs->endptctrl[ep_num]); | ||
941 | ep->stopped = stopped; | ||
942 | |||
943 | spin_unlock_irqrestore(&ep->udc->lock, flags); | ||
944 | return ret; | ||
945 | } | ||
946 | |||
947 | /*-------------------------------------------------------------------------*/ | ||
948 | |||
949 | /*----------------------------------------------------------------- | ||
950 | * modify the endpoint halt feature | ||
951 | * @ep: the non-isochronous endpoint being stalled | ||
952 | * @value: 1--set halt 0--clear halt | ||
953 | * Returns zero, or a negative error code. | ||
954 | *----------------------------------------------------------------*/ | ||
955 | static int fsl_ep_set_halt(struct usb_ep *_ep, int value) | ||
956 | { | ||
957 | struct fsl_ep *ep = NULL; | ||
958 | unsigned long flags = 0; | ||
959 | int status = -EOPNOTSUPP; /* operation not supported */ | ||
960 | unsigned char ep_dir = 0, ep_num = 0; | ||
961 | struct fsl_udc *udc = NULL; | ||
962 | |||
963 | ep = container_of(_ep, struct fsl_ep, ep); | ||
964 | udc = ep->udc; | ||
965 | if (!_ep || !ep->desc) { | ||
966 | status = -EINVAL; | ||
967 | goto out; | ||
968 | } | ||
969 | |||
970 | if (ep->desc->bmAttributes == USB_ENDPOINT_XFER_ISOC) { | ||
971 | status = -EOPNOTSUPP; | ||
972 | goto out; | ||
973 | } | ||
974 | |||
975 | /* Attempt to halt IN ep will fail if any transfer requests | ||
976 | * are still queue */ | ||
977 | if (value && ep_is_in(ep) && !list_empty(&ep->queue)) { | ||
978 | status = -EAGAIN; | ||
979 | goto out; | ||
980 | } | ||
981 | |||
982 | status = 0; | ||
983 | ep_dir = ep_is_in(ep) ? USB_SEND : USB_RECV; | ||
984 | ep_num = (unsigned char)(ep_index(ep)); | ||
985 | spin_lock_irqsave(&ep->udc->lock, flags); | ||
986 | dr_ep_change_stall(ep_num, ep_dir, value); | ||
987 | spin_unlock_irqrestore(&ep->udc->lock, flags); | ||
988 | |||
989 | if (ep_index(ep) == 0) { | ||
990 | udc->ep0_state = WAIT_FOR_SETUP; | ||
991 | udc->ep0_dir = 0; | ||
992 | } | ||
993 | out: | ||
994 | VDBG(" %s %s halt stat %d", ep->ep.name, | ||
995 | value ? "set" : "clear", status); | ||
996 | |||
997 | return status; | ||
998 | } | ||
999 | |||
1000 | static void fsl_ep_fifo_flush(struct usb_ep *_ep) | ||
1001 | { | ||
1002 | struct fsl_ep *ep; | ||
1003 | int ep_num, ep_dir; | ||
1004 | u32 bits; | ||
1005 | unsigned long timeout; | ||
1006 | #define FSL_UDC_FLUSH_TIMEOUT 1000 | ||
1007 | |||
1008 | if (!_ep) { | ||
1009 | return; | ||
1010 | } else { | ||
1011 | ep = container_of(_ep, struct fsl_ep, ep); | ||
1012 | if (!ep->desc) | ||
1013 | return; | ||
1014 | } | ||
1015 | ep_num = ep_index(ep); | ||
1016 | ep_dir = ep_is_in(ep) ? USB_SEND : USB_RECV; | ||
1017 | |||
1018 | if (ep_num == 0) | ||
1019 | bits = (1 << 16) | 1; | ||
1020 | else if (ep_dir == USB_SEND) | ||
1021 | bits = 1 << (16 + ep_num); | ||
1022 | else | ||
1023 | bits = 1 << ep_num; | ||
1024 | |||
1025 | timeout = jiffies + FSL_UDC_FLUSH_TIMEOUT; | ||
1026 | do { | ||
1027 | fsl_writel(bits, &dr_regs->endptflush); | ||
1028 | |||
1029 | /* Wait until flush complete */ | ||
1030 | while (fsl_readl(&dr_regs->endptflush)) { | ||
1031 | if (time_after(jiffies, timeout)) { | ||
1032 | ERR("ep flush timeout\n"); | ||
1033 | return; | ||
1034 | } | ||
1035 | cpu_relax(); | ||
1036 | } | ||
1037 | /* See if we need to flush again */ | ||
1038 | } while (fsl_readl(&dr_regs->endptstatus) & bits); | ||
1039 | } | ||
1040 | |||
1041 | static struct usb_ep_ops fsl_ep_ops = { | ||
1042 | .enable = fsl_ep_enable, | ||
1043 | .disable = fsl_ep_disable, | ||
1044 | |||
1045 | .alloc_request = fsl_alloc_request, | ||
1046 | .free_request = fsl_free_request, | ||
1047 | |||
1048 | .alloc_buffer = fsl_alloc_buffer, | ||
1049 | .free_buffer = fsl_free_buffer, | ||
1050 | |||
1051 | .queue = fsl_ep_queue, | ||
1052 | .dequeue = fsl_ep_dequeue, | ||
1053 | |||
1054 | .set_halt = fsl_ep_set_halt, | ||
1055 | .fifo_flush = fsl_ep_fifo_flush, /* flush fifo */ | ||
1056 | }; | ||
1057 | |||
1058 | /*------------------------------------------------------------------------- | ||
1059 | Gadget Driver Layer Operations | ||
1060 | -------------------------------------------------------------------------*/ | ||
1061 | |||
1062 | /*---------------------------------------------------------------------- | ||
1063 | * Get the current frame number (from DR frame_index Reg ) | ||
1064 | *----------------------------------------------------------------------*/ | ||
1065 | static int fsl_get_frame(struct usb_gadget *gadget) | ||
1066 | { | ||
1067 | return (int)(fsl_readl(&dr_regs->frindex) & USB_FRINDEX_MASKS); | ||
1068 | } | ||
1069 | |||
1070 | /*----------------------------------------------------------------------- | ||
1071 | * Tries to wake up the host connected to this gadget | ||
1072 | -----------------------------------------------------------------------*/ | ||
1073 | static int fsl_wakeup(struct usb_gadget *gadget) | ||
1074 | { | ||
1075 | struct fsl_udc *udc = container_of(gadget, struct fsl_udc, gadget); | ||
1076 | u32 portsc; | ||
1077 | |||
1078 | /* Remote wakeup feature not enabled by host */ | ||
1079 | if (!udc->remote_wakeup) | ||
1080 | return -ENOTSUPP; | ||
1081 | |||
1082 | portsc = fsl_readl(&dr_regs->portsc1); | ||
1083 | /* not suspended? */ | ||
1084 | if (!(portsc & PORTSCX_PORT_SUSPEND)) | ||
1085 | return 0; | ||
1086 | /* trigger force resume */ | ||
1087 | portsc |= PORTSCX_PORT_FORCE_RESUME; | ||
1088 | fsl_writel(portsc, &dr_regs->portsc1); | ||
1089 | return 0; | ||
1090 | } | ||
1091 | |||
1092 | static int can_pullup(struct fsl_udc *udc) | ||
1093 | { | ||
1094 | return udc->driver && udc->softconnect && udc->vbus_active; | ||
1095 | } | ||
1096 | |||
1097 | /* Notify controller that VBUS is powered, Called by whatever | ||
1098 | detects VBUS sessions */ | ||
1099 | static int fsl_vbus_session(struct usb_gadget *gadget, int is_active) | ||
1100 | { | ||
1101 | struct fsl_udc *udc; | ||
1102 | unsigned long flags; | ||
1103 | |||
1104 | udc = container_of(gadget, struct fsl_udc, gadget); | ||
1105 | spin_lock_irqsave(&udc->lock, flags); | ||
1106 | VDBG("VBUS %s\n", is_active ? "on" : "off"); | ||
1107 | udc->vbus_active = (is_active != 0); | ||
1108 | if (can_pullup(udc)) | ||
1109 | fsl_writel((fsl_readl(&dr_regs->usbcmd) | USB_CMD_RUN_STOP), | ||
1110 | &dr_regs->usbcmd); | ||
1111 | else | ||
1112 | fsl_writel((fsl_readl(&dr_regs->usbcmd) & ~USB_CMD_RUN_STOP), | ||
1113 | &dr_regs->usbcmd); | ||
1114 | spin_unlock_irqrestore(&udc->lock, flags); | ||
1115 | return 0; | ||
1116 | } | ||
1117 | |||
1118 | /* constrain controller's VBUS power usage | ||
1119 | * This call is used by gadget drivers during SET_CONFIGURATION calls, | ||
1120 | * reporting how much power the device may consume. For example, this | ||
1121 | * could affect how quickly batteries are recharged. | ||
1122 | * | ||
1123 | * Returns zero on success, else negative errno. | ||
1124 | */ | ||
1125 | static int fsl_vbus_draw(struct usb_gadget *gadget, unsigned mA) | ||
1126 | { | ||
1127 | #ifdef CONFIG_USB_OTG | ||
1128 | struct fsl_udc *udc; | ||
1129 | |||
1130 | udc = container_of(gadget, struct fsl_udc, gadget); | ||
1131 | |||
1132 | if (udc->transceiver) | ||
1133 | return otg_set_power(udc->transceiver, mA); | ||
1134 | #endif | ||
1135 | return -ENOTSUPP; | ||
1136 | } | ||
1137 | |||
1138 | /* Change Data+ pullup status | ||
1139 | * this func is used by usb_gadget_connect/disconnet | ||
1140 | */ | ||
1141 | static int fsl_pullup(struct usb_gadget *gadget, int is_on) | ||
1142 | { | ||
1143 | struct fsl_udc *udc; | ||
1144 | |||
1145 | udc = container_of(gadget, struct fsl_udc, gadget); | ||
1146 | udc->softconnect = (is_on != 0); | ||
1147 | if (can_pullup(udc)) | ||
1148 | fsl_writel((fsl_readl(&dr_regs->usbcmd) | USB_CMD_RUN_STOP), | ||
1149 | &dr_regs->usbcmd); | ||
1150 | else | ||
1151 | fsl_writel((fsl_readl(&dr_regs->usbcmd) & ~USB_CMD_RUN_STOP), | ||
1152 | &dr_regs->usbcmd); | ||
1153 | |||
1154 | return 0; | ||
1155 | } | ||
1156 | |||
1157 | /* defined in usb_gadget.h */ | ||
1158 | static struct usb_gadget_ops fsl_gadget_ops = { | ||
1159 | .get_frame = fsl_get_frame, | ||
1160 | .wakeup = fsl_wakeup, | ||
1161 | /* .set_selfpowered = fsl_set_selfpowered, */ /* Always selfpowered */ | ||
1162 | .vbus_session = fsl_vbus_session, | ||
1163 | .vbus_draw = fsl_vbus_draw, | ||
1164 | .pullup = fsl_pullup, | ||
1165 | }; | ||
1166 | |||
1167 | /* Set protocol stall on ep0, protocol stall will automatically be cleared | ||
1168 | on new transaction */ | ||
1169 | static void ep0stall(struct fsl_udc *udc) | ||
1170 | { | ||
1171 | u32 tmp; | ||
1172 | |||
1173 | /* must set tx and rx to stall at the same time */ | ||
1174 | tmp = fsl_readl(&dr_regs->endptctrl[0]); | ||
1175 | tmp |= EPCTRL_TX_EP_STALL | EPCTRL_RX_EP_STALL; | ||
1176 | fsl_writel(tmp, &dr_regs->endptctrl[0]); | ||
1177 | udc->ep0_state = WAIT_FOR_SETUP; | ||
1178 | udc->ep0_dir = 0; | ||
1179 | } | ||
1180 | |||
1181 | /* Prime a status phase for ep0 */ | ||
1182 | static int ep0_prime_status(struct fsl_udc *udc, int direction) | ||
1183 | { | ||
1184 | struct fsl_req *req = udc->status_req; | ||
1185 | struct fsl_ep *ep; | ||
1186 | int status = 0; | ||
1187 | |||
1188 | if (direction == EP_DIR_IN) | ||
1189 | udc->ep0_dir = USB_DIR_IN; | ||
1190 | else | ||
1191 | udc->ep0_dir = USB_DIR_OUT; | ||
1192 | |||
1193 | ep = &udc->eps[0]; | ||
1194 | udc->ep0_state = WAIT_FOR_OUT_STATUS; | ||
1195 | |||
1196 | req->ep = ep; | ||
1197 | req->req.length = 0; | ||
1198 | req->req.status = -EINPROGRESS; | ||
1199 | req->req.actual = 0; | ||
1200 | req->req.complete = NULL; | ||
1201 | req->dtd_count = 0; | ||
1202 | |||
1203 | if (fsl_req_to_dtd(req) == 0) | ||
1204 | status = fsl_queue_td(ep, req); | ||
1205 | else | ||
1206 | return -ENOMEM; | ||
1207 | |||
1208 | if (status) | ||
1209 | ERR("Can't queue ep0 status request \n"); | ||
1210 | list_add_tail(&req->queue, &ep->queue); | ||
1211 | |||
1212 | return status; | ||
1213 | } | ||
1214 | |||
1215 | static inline int udc_reset_ep_queue(struct fsl_udc *udc, u8 pipe) | ||
1216 | { | ||
1217 | struct fsl_ep *ep = get_ep_by_pipe(udc, pipe); | ||
1218 | |||
1219 | if (!ep->name) | ||
1220 | return 0; | ||
1221 | |||
1222 | nuke(ep, -ESHUTDOWN); | ||
1223 | |||
1224 | return 0; | ||
1225 | } | ||
1226 | |||
1227 | /* | ||
1228 | * ch9 Set address | ||
1229 | */ | ||
1230 | static void ch9setaddress(struct fsl_udc *udc, u16 value, u16 index, u16 length) | ||
1231 | { | ||
1232 | /* Save the new address to device struct */ | ||
1233 | udc->device_address = (u8) value; | ||
1234 | /* Update usb state */ | ||
1235 | udc->usb_state = USB_STATE_ADDRESS; | ||
1236 | /* Status phase */ | ||
1237 | if (ep0_prime_status(udc, EP_DIR_IN)) | ||
1238 | ep0stall(udc); | ||
1239 | } | ||
1240 | |||
1241 | /* | ||
1242 | * ch9 Get status | ||
1243 | */ | ||
1244 | static void ch9getstatus(struct fsl_udc *udc, u8 request_type, u16 value, | ||
1245 | u16 index, u16 length) | ||
1246 | { | ||
1247 | u16 tmp = 0; /* Status, cpu endian */ | ||
1248 | |||
1249 | struct fsl_req *req; | ||
1250 | struct fsl_ep *ep; | ||
1251 | int status = 0; | ||
1252 | |||
1253 | ep = &udc->eps[0]; | ||
1254 | |||
1255 | if ((request_type & USB_RECIP_MASK) == USB_RECIP_DEVICE) { | ||
1256 | /* Get device status */ | ||
1257 | tmp = 1 << USB_DEVICE_SELF_POWERED; | ||
1258 | tmp |= udc->remote_wakeup << USB_DEVICE_REMOTE_WAKEUP; | ||
1259 | } else if ((request_type & USB_RECIP_MASK) == USB_RECIP_INTERFACE) { | ||
1260 | /* Get interface status */ | ||
1261 | /* We don't have interface information in udc driver */ | ||
1262 | tmp = 0; | ||
1263 | } else if ((request_type & USB_RECIP_MASK) == USB_RECIP_ENDPOINT) { | ||
1264 | /* Get endpoint status */ | ||
1265 | struct fsl_ep *target_ep; | ||
1266 | |||
1267 | target_ep = get_ep_by_pipe(udc, get_pipe_by_windex(index)); | ||
1268 | |||
1269 | /* stall if endpoint doesn't exist */ | ||
1270 | if (!target_ep->desc) | ||
1271 | goto stall; | ||
1272 | tmp = dr_ep_get_stall(ep_index(target_ep), ep_is_in(target_ep)) | ||
1273 | << USB_ENDPOINT_HALT; | ||
1274 | } | ||
1275 | |||
1276 | udc->ep0_dir = USB_DIR_IN; | ||
1277 | /* Borrow the per device status_req */ | ||
1278 | req = udc->status_req; | ||
1279 | /* Fill in the reqest structure */ | ||
1280 | *((u16 *) req->req.buf) = cpu_to_le16(tmp); | ||
1281 | req->ep = ep; | ||
1282 | req->req.length = 2; | ||
1283 | req->req.status = -EINPROGRESS; | ||
1284 | req->req.actual = 0; | ||
1285 | req->req.complete = NULL; | ||
1286 | req->dtd_count = 0; | ||
1287 | |||
1288 | /* prime the data phase */ | ||
1289 | if ((fsl_req_to_dtd(req) == 0)) | ||
1290 | status = fsl_queue_td(ep, req); | ||
1291 | else /* no mem */ | ||
1292 | goto stall; | ||
1293 | |||
1294 | if (status) { | ||
1295 | ERR("Can't respond to getstatus request \n"); | ||
1296 | goto stall; | ||
1297 | } | ||
1298 | list_add_tail(&req->queue, &ep->queue); | ||
1299 | udc->ep0_state = DATA_STATE_XMIT; | ||
1300 | return; | ||
1301 | stall: | ||
1302 | ep0stall(udc); | ||
1303 | } | ||
1304 | |||
1305 | static void setup_received_irq(struct fsl_udc *udc, | ||
1306 | struct usb_ctrlrequest *setup) | ||
1307 | { | ||
1308 | u16 wValue = le16_to_cpu(setup->wValue); | ||
1309 | u16 wIndex = le16_to_cpu(setup->wIndex); | ||
1310 | u16 wLength = le16_to_cpu(setup->wLength); | ||
1311 | |||
1312 | udc_reset_ep_queue(udc, 0); | ||
1313 | |||
1314 | switch (setup->bRequest) { | ||
1315 | /* Request that need Data+Status phase from udc */ | ||
1316 | case USB_REQ_GET_STATUS: | ||
1317 | if ((setup->bRequestType & (USB_DIR_IN | USB_TYPE_STANDARD)) | ||
1318 | != (USB_DIR_IN | USB_TYPE_STANDARD)) | ||
1319 | break; | ||
1320 | ch9getstatus(udc, setup->bRequestType, wValue, wIndex, wLength); | ||
1321 | break; | ||
1322 | |||
1323 | /* Requests that need Status phase from udc */ | ||
1324 | case USB_REQ_SET_ADDRESS: | ||
1325 | if (setup->bRequestType != (USB_DIR_OUT | USB_TYPE_STANDARD | ||
1326 | | USB_RECIP_DEVICE)) | ||
1327 | break; | ||
1328 | ch9setaddress(udc, wValue, wIndex, wLength); | ||
1329 | break; | ||
1330 | |||
1331 | /* Handled by udc, no data, status by udc */ | ||
1332 | case USB_REQ_CLEAR_FEATURE: | ||
1333 | case USB_REQ_SET_FEATURE: | ||
1334 | { /* status transaction */ | ||
1335 | int rc = -EOPNOTSUPP; | ||
1336 | |||
1337 | if ((setup->bRequestType & USB_RECIP_MASK) | ||
1338 | == USB_RECIP_ENDPOINT) { | ||
1339 | int pipe = get_pipe_by_windex(wIndex); | ||
1340 | struct fsl_ep *ep; | ||
1341 | |||
1342 | if (wValue != 0 || wLength != 0 || pipe > udc->max_ep) | ||
1343 | break; | ||
1344 | ep = get_ep_by_pipe(udc, pipe); | ||
1345 | |||
1346 | spin_unlock(&udc->lock); | ||
1347 | rc = fsl_ep_set_halt(&ep->ep, | ||
1348 | (setup->bRequest == USB_REQ_SET_FEATURE) | ||
1349 | ? 1 : 0); | ||
1350 | spin_lock(&udc->lock); | ||
1351 | |||
1352 | } else if ((setup->bRequestType & USB_RECIP_MASK) | ||
1353 | == USB_RECIP_DEVICE) { | ||
1354 | /* Note: The driver has not include OTG support yet. | ||
1355 | * This will be set when OTG support is added */ | ||
1356 | if (!udc->gadget.is_otg) | ||
1357 | break; | ||
1358 | else if (setup->bRequest == USB_DEVICE_B_HNP_ENABLE) | ||
1359 | udc->gadget.b_hnp_enable = 1; | ||
1360 | else if (setup->bRequest == USB_DEVICE_A_HNP_SUPPORT) | ||
1361 | udc->gadget.a_hnp_support = 1; | ||
1362 | else if (setup->bRequest == | ||
1363 | USB_DEVICE_A_ALT_HNP_SUPPORT) | ||
1364 | udc->gadget.a_alt_hnp_support = 1; | ||
1365 | rc = 0; | ||
1366 | } | ||
1367 | if (rc == 0) { | ||
1368 | if (ep0_prime_status(udc, EP_DIR_IN)) | ||
1369 | ep0stall(udc); | ||
1370 | } | ||
1371 | break; | ||
1372 | } | ||
1373 | /* Requests handled by gadget */ | ||
1374 | default: | ||
1375 | if (wLength) { | ||
1376 | /* Data phase from gadget, status phase from udc */ | ||
1377 | udc->ep0_dir = (setup->bRequestType & USB_DIR_IN) | ||
1378 | ? USB_DIR_IN : USB_DIR_OUT; | ||
1379 | spin_unlock(&udc->lock); | ||
1380 | if (udc->driver->setup(&udc->gadget, | ||
1381 | &udc->local_setup_buff) < 0) | ||
1382 | ep0stall(udc); | ||
1383 | spin_lock(&udc->lock); | ||
1384 | udc->ep0_state = (setup->bRequestType & USB_DIR_IN) | ||
1385 | ? DATA_STATE_XMIT : DATA_STATE_RECV; | ||
1386 | |||
1387 | } else { | ||
1388 | /* No data phase, IN status from gadget */ | ||
1389 | udc->ep0_dir = USB_DIR_IN; | ||
1390 | spin_unlock(&udc->lock); | ||
1391 | if (udc->driver->setup(&udc->gadget, | ||
1392 | &udc->local_setup_buff) < 0) | ||
1393 | ep0stall(udc); | ||
1394 | spin_lock(&udc->lock); | ||
1395 | udc->ep0_state = WAIT_FOR_OUT_STATUS; | ||
1396 | } | ||
1397 | break; | ||
1398 | } | ||
1399 | } | ||
1400 | |||
1401 | /* Process request for Data or Status phase of ep0 | ||
1402 | * prime status phase if needed */ | ||
1403 | static void ep0_req_complete(struct fsl_udc *udc, struct fsl_ep *ep0, | ||
1404 | struct fsl_req *req) | ||
1405 | { | ||
1406 | if (udc->usb_state == USB_STATE_ADDRESS) { | ||
1407 | /* Set the new address */ | ||
1408 | u32 new_address = (u32) udc->device_address; | ||
1409 | fsl_writel(new_address << USB_DEVICE_ADDRESS_BIT_POS, | ||
1410 | &dr_regs->deviceaddr); | ||
1411 | } | ||
1412 | |||
1413 | done(ep0, req, 0); | ||
1414 | |||
1415 | switch (udc->ep0_state) { | ||
1416 | case DATA_STATE_XMIT: | ||
1417 | /* receive status phase */ | ||
1418 | if (ep0_prime_status(udc, EP_DIR_OUT)) | ||
1419 | ep0stall(udc); | ||
1420 | break; | ||
1421 | case DATA_STATE_RECV: | ||
1422 | /* send status phase */ | ||
1423 | if (ep0_prime_status(udc, EP_DIR_IN)) | ||
1424 | ep0stall(udc); | ||
1425 | break; | ||
1426 | case WAIT_FOR_OUT_STATUS: | ||
1427 | udc->ep0_state = WAIT_FOR_SETUP; | ||
1428 | break; | ||
1429 | case WAIT_FOR_SETUP: | ||
1430 | ERR("Unexpect ep0 packets \n"); | ||
1431 | break; | ||
1432 | default: | ||
1433 | ep0stall(udc); | ||
1434 | break; | ||
1435 | } | ||
1436 | } | ||
1437 | |||
1438 | /* Tripwire mechanism to ensure a setup packet payload is extracted without | ||
1439 | * being corrupted by another incoming setup packet */ | ||
1440 | static void tripwire_handler(struct fsl_udc *udc, u8 ep_num, u8 *buffer_ptr) | ||
1441 | { | ||
1442 | u32 temp; | ||
1443 | struct ep_queue_head *qh; | ||
1444 | |||
1445 | qh = &udc->ep_qh[ep_num * 2 + EP_DIR_OUT]; | ||
1446 | |||
1447 | /* Clear bit in ENDPTSETUPSTAT */ | ||
1448 | temp = fsl_readl(&dr_regs->endptsetupstat); | ||
1449 | fsl_writel(temp | (1 << ep_num), &dr_regs->endptsetupstat); | ||
1450 | |||
1451 | /* while a hazard exists when setup package arrives */ | ||
1452 | do { | ||
1453 | /* Set Setup Tripwire */ | ||
1454 | temp = fsl_readl(&dr_regs->usbcmd); | ||
1455 | fsl_writel(temp | USB_CMD_SUTW, &dr_regs->usbcmd); | ||
1456 | |||
1457 | /* Copy the setup packet to local buffer */ | ||
1458 | memcpy(buffer_ptr, (u8 *) qh->setup_buffer, 8); | ||
1459 | } while (!(fsl_readl(&dr_regs->usbcmd) & USB_CMD_SUTW)); | ||
1460 | |||
1461 | /* Clear Setup Tripwire */ | ||
1462 | temp = fsl_readl(&dr_regs->usbcmd); | ||
1463 | fsl_writel(temp & ~USB_CMD_SUTW, &dr_regs->usbcmd); | ||
1464 | } | ||
1465 | |||
1466 | /* process-ep_req(): free the completed Tds for this req */ | ||
1467 | static int process_ep_req(struct fsl_udc *udc, int pipe, | ||
1468 | struct fsl_req *curr_req) | ||
1469 | { | ||
1470 | struct ep_td_struct *curr_td; | ||
1471 | int td_complete, actual, remaining_length, j, tmp; | ||
1472 | int status = 0; | ||
1473 | int errors = 0; | ||
1474 | struct ep_queue_head *curr_qh = &udc->ep_qh[pipe]; | ||
1475 | int direction = pipe % 2; | ||
1476 | |||
1477 | curr_td = curr_req->head; | ||
1478 | td_complete = 0; | ||
1479 | actual = curr_req->req.length; | ||
1480 | |||
1481 | for (j = 0; j < curr_req->dtd_count; j++) { | ||
1482 | remaining_length = (le32_to_cpu(curr_td->size_ioc_sts) | ||
1483 | & DTD_PACKET_SIZE) | ||
1484 | >> DTD_LENGTH_BIT_POS; | ||
1485 | actual -= remaining_length; | ||
1486 | |||
1487 | if ((errors = le32_to_cpu(curr_td->size_ioc_sts) & | ||
1488 | DTD_ERROR_MASK)) { | ||
1489 | if (errors & DTD_STATUS_HALTED) { | ||
1490 | ERR("dTD error %08x QH=%d\n", errors, pipe); | ||
1491 | /* Clear the errors and Halt condition */ | ||
1492 | tmp = le32_to_cpu(curr_qh->size_ioc_int_sts); | ||
1493 | tmp &= ~errors; | ||
1494 | curr_qh->size_ioc_int_sts = cpu_to_le32(tmp); | ||
1495 | status = -EPIPE; | ||
1496 | /* FIXME: continue with next queued TD? */ | ||
1497 | |||
1498 | break; | ||
1499 | } | ||
1500 | if (errors & DTD_STATUS_DATA_BUFF_ERR) { | ||
1501 | VDBG("Transfer overflow"); | ||
1502 | status = -EPROTO; | ||
1503 | break; | ||
1504 | } else if (errors & DTD_STATUS_TRANSACTION_ERR) { | ||
1505 | VDBG("ISO error"); | ||
1506 | status = -EILSEQ; | ||
1507 | break; | ||
1508 | } else | ||
1509 | ERR("Unknown error has occured (0x%x)!\r\n", | ||
1510 | errors); | ||
1511 | |||
1512 | } else if (le32_to_cpu(curr_td->size_ioc_sts) | ||
1513 | & DTD_STATUS_ACTIVE) { | ||
1514 | VDBG("Request not complete"); | ||
1515 | status = REQ_UNCOMPLETE; | ||
1516 | return status; | ||
1517 | } else if (remaining_length) { | ||
1518 | if (direction) { | ||
1519 | VDBG("Transmit dTD remaining length not zero"); | ||
1520 | status = -EPROTO; | ||
1521 | break; | ||
1522 | } else { | ||
1523 | td_complete++; | ||
1524 | break; | ||
1525 | } | ||
1526 | } else { | ||
1527 | td_complete++; | ||
1528 | VDBG("dTD transmitted successful "); | ||
1529 | } | ||
1530 | |||
1531 | if (j != curr_req->dtd_count - 1) | ||
1532 | curr_td = (struct ep_td_struct *)curr_td->next_td_virt; | ||
1533 | } | ||
1534 | |||
1535 | if (status) | ||
1536 | return status; | ||
1537 | |||
1538 | curr_req->req.actual = actual; | ||
1539 | |||
1540 | return 0; | ||
1541 | } | ||
1542 | |||
1543 | /* Process a DTD completion interrupt */ | ||
1544 | static void dtd_complete_irq(struct fsl_udc *udc) | ||
1545 | { | ||
1546 | u32 bit_pos; | ||
1547 | int i, ep_num, direction, bit_mask, status; | ||
1548 | struct fsl_ep *curr_ep; | ||
1549 | struct fsl_req *curr_req, *temp_req; | ||
1550 | |||
1551 | /* Clear the bits in the register */ | ||
1552 | bit_pos = fsl_readl(&dr_regs->endptcomplete); | ||
1553 | fsl_writel(bit_pos, &dr_regs->endptcomplete); | ||
1554 | |||
1555 | if (!bit_pos) | ||
1556 | return; | ||
1557 | |||
1558 | for (i = 0; i < udc->max_ep * 2; i++) { | ||
1559 | ep_num = i >> 1; | ||
1560 | direction = i % 2; | ||
1561 | |||
1562 | bit_mask = 1 << (ep_num + 16 * direction); | ||
1563 | |||
1564 | if (!(bit_pos & bit_mask)) | ||
1565 | continue; | ||
1566 | |||
1567 | curr_ep = get_ep_by_pipe(udc, i); | ||
1568 | |||
1569 | /* If the ep is configured */ | ||
1570 | if (curr_ep->name == NULL) { | ||
1571 | WARN("Invalid EP?"); | ||
1572 | continue; | ||
1573 | } | ||
1574 | |||
1575 | /* process the req queue until an uncomplete request */ | ||
1576 | list_for_each_entry_safe(curr_req, temp_req, &curr_ep->queue, | ||
1577 | queue) { | ||
1578 | status = process_ep_req(udc, i, curr_req); | ||
1579 | |||
1580 | VDBG("status of process_ep_req= %d, ep = %d", | ||
1581 | status, ep_num); | ||
1582 | if (status == REQ_UNCOMPLETE) | ||
1583 | break; | ||
1584 | /* write back status to req */ | ||
1585 | curr_req->req.status = status; | ||
1586 | |||
1587 | if (ep_num == 0) { | ||
1588 | ep0_req_complete(udc, curr_ep, curr_req); | ||
1589 | break; | ||
1590 | } else | ||
1591 | done(curr_ep, curr_req, status); | ||
1592 | } | ||
1593 | } | ||
1594 | } | ||
1595 | |||
1596 | /* Process a port change interrupt */ | ||
1597 | static void port_change_irq(struct fsl_udc *udc) | ||
1598 | { | ||
1599 | u32 speed; | ||
1600 | |||
1601 | if (udc->bus_reset) | ||
1602 | udc->bus_reset = 0; | ||
1603 | |||
1604 | /* Bus resetting is finished */ | ||
1605 | if (!(fsl_readl(&dr_regs->portsc1) & PORTSCX_PORT_RESET)) { | ||
1606 | /* Get the speed */ | ||
1607 | speed = (fsl_readl(&dr_regs->portsc1) | ||
1608 | & PORTSCX_PORT_SPEED_MASK); | ||
1609 | switch (speed) { | ||
1610 | case PORTSCX_PORT_SPEED_HIGH: | ||
1611 | udc->gadget.speed = USB_SPEED_HIGH; | ||
1612 | break; | ||
1613 | case PORTSCX_PORT_SPEED_FULL: | ||
1614 | udc->gadget.speed = USB_SPEED_FULL; | ||
1615 | break; | ||
1616 | case PORTSCX_PORT_SPEED_LOW: | ||
1617 | udc->gadget.speed = USB_SPEED_LOW; | ||
1618 | break; | ||
1619 | default: | ||
1620 | udc->gadget.speed = USB_SPEED_UNKNOWN; | ||
1621 | break; | ||
1622 | } | ||
1623 | } | ||
1624 | |||
1625 | /* Update USB state */ | ||
1626 | if (!udc->resume_state) | ||
1627 | udc->usb_state = USB_STATE_DEFAULT; | ||
1628 | } | ||
1629 | |||
1630 | /* Process suspend interrupt */ | ||
1631 | static void suspend_irq(struct fsl_udc *udc) | ||
1632 | { | ||
1633 | udc->resume_state = udc->usb_state; | ||
1634 | udc->usb_state = USB_STATE_SUSPENDED; | ||
1635 | |||
1636 | /* report suspend to the driver, serial.c does not support this */ | ||
1637 | if (udc->driver->suspend) | ||
1638 | udc->driver->suspend(&udc->gadget); | ||
1639 | } | ||
1640 | |||
1641 | static void bus_resume(struct fsl_udc *udc) | ||
1642 | { | ||
1643 | udc->usb_state = udc->resume_state; | ||
1644 | udc->resume_state = 0; | ||
1645 | |||
1646 | /* report resume to the driver, serial.c does not support this */ | ||
1647 | if (udc->driver->resume) | ||
1648 | udc->driver->resume(&udc->gadget); | ||
1649 | } | ||
1650 | |||
1651 | /* Clear up all ep queues */ | ||
1652 | static int reset_queues(struct fsl_udc *udc) | ||
1653 | { | ||
1654 | u8 pipe; | ||
1655 | |||
1656 | for (pipe = 0; pipe < udc->max_pipes; pipe++) | ||
1657 | udc_reset_ep_queue(udc, pipe); | ||
1658 | |||
1659 | /* report disconnect; the driver is already quiesced */ | ||
1660 | udc->driver->disconnect(&udc->gadget); | ||
1661 | |||
1662 | return 0; | ||
1663 | } | ||
1664 | |||
1665 | /* Process reset interrupt */ | ||
1666 | static void reset_irq(struct fsl_udc *udc) | ||
1667 | { | ||
1668 | u32 temp; | ||
1669 | unsigned long timeout; | ||
1670 | |||
1671 | /* Clear the device address */ | ||
1672 | temp = fsl_readl(&dr_regs->deviceaddr); | ||
1673 | fsl_writel(temp & ~USB_DEVICE_ADDRESS_MASK, &dr_regs->deviceaddr); | ||
1674 | |||
1675 | udc->device_address = 0; | ||
1676 | |||
1677 | /* Clear usb state */ | ||
1678 | udc->resume_state = 0; | ||
1679 | udc->ep0_dir = 0; | ||
1680 | udc->ep0_state = WAIT_FOR_SETUP; | ||
1681 | udc->remote_wakeup = 0; /* default to 0 on reset */ | ||
1682 | udc->gadget.b_hnp_enable = 0; | ||
1683 | udc->gadget.a_hnp_support = 0; | ||
1684 | udc->gadget.a_alt_hnp_support = 0; | ||
1685 | |||
1686 | /* Clear all the setup token semaphores */ | ||
1687 | temp = fsl_readl(&dr_regs->endptsetupstat); | ||
1688 | fsl_writel(temp, &dr_regs->endptsetupstat); | ||
1689 | |||
1690 | /* Clear all the endpoint complete status bits */ | ||
1691 | temp = fsl_readl(&dr_regs->endptcomplete); | ||
1692 | fsl_writel(temp, &dr_regs->endptcomplete); | ||
1693 | |||
1694 | timeout = jiffies + 100; | ||
1695 | while (fsl_readl(&dr_regs->endpointprime)) { | ||
1696 | /* Wait until all endptprime bits cleared */ | ||
1697 | if (time_after(jiffies, timeout)) { | ||
1698 | ERR("Timeout for reset\n"); | ||
1699 | break; | ||
1700 | } | ||
1701 | cpu_relax(); | ||
1702 | } | ||
1703 | |||
1704 | /* Write 1s to the flush register */ | ||
1705 | fsl_writel(0xffffffff, &dr_regs->endptflush); | ||
1706 | |||
1707 | if (fsl_readl(&dr_regs->portsc1) & PORTSCX_PORT_RESET) { | ||
1708 | VDBG("Bus reset"); | ||
1709 | /* Bus is reseting */ | ||
1710 | udc->bus_reset = 1; | ||
1711 | /* Reset all the queues, include XD, dTD, EP queue | ||
1712 | * head and TR Queue */ | ||
1713 | reset_queues(udc); | ||
1714 | udc->usb_state = USB_STATE_DEFAULT; | ||
1715 | } else { | ||
1716 | VDBG("Controller reset"); | ||
1717 | /* initialize usb hw reg except for regs for EP, not | ||
1718 | * touch usbintr reg */ | ||
1719 | dr_controller_setup(udc); | ||
1720 | |||
1721 | /* Reset all internal used Queues */ | ||
1722 | reset_queues(udc); | ||
1723 | |||
1724 | ep0_setup(udc); | ||
1725 | |||
1726 | /* Enable DR IRQ reg, Set Run bit, change udc state */ | ||
1727 | dr_controller_run(udc); | ||
1728 | udc->usb_state = USB_STATE_ATTACHED; | ||
1729 | } | ||
1730 | } | ||
1731 | |||
1732 | /* | ||
1733 | * USB device controller interrupt handler | ||
1734 | */ | ||
1735 | static irqreturn_t fsl_udc_irq(int irq, void *_udc) | ||
1736 | { | ||
1737 | struct fsl_udc *udc = _udc; | ||
1738 | u32 irq_src; | ||
1739 | irqreturn_t status = IRQ_NONE; | ||
1740 | unsigned long flags; | ||
1741 | |||
1742 | /* Disable ISR for OTG host mode */ | ||
1743 | if (udc->stopped) | ||
1744 | return IRQ_NONE; | ||
1745 | spin_lock_irqsave(&udc->lock, flags); | ||
1746 | irq_src = fsl_readl(&dr_regs->usbsts) & fsl_readl(&dr_regs->usbintr); | ||
1747 | /* Clear notification bits */ | ||
1748 | fsl_writel(irq_src, &dr_regs->usbsts); | ||
1749 | |||
1750 | /* VDBG("irq_src [0x%8x]", irq_src); */ | ||
1751 | |||
1752 | /* Need to resume? */ | ||
1753 | if (udc->usb_state == USB_STATE_SUSPENDED) | ||
1754 | if ((fsl_readl(&dr_regs->portsc1) & PORTSCX_PORT_SUSPEND) == 0) | ||
1755 | bus_resume(udc); | ||
1756 | |||
1757 | /* USB Interrupt */ | ||
1758 | if (irq_src & USB_STS_INT) { | ||
1759 | VDBG("Packet int"); | ||
1760 | /* Setup package, we only support ep0 as control ep */ | ||
1761 | if (fsl_readl(&dr_regs->endptsetupstat) & EP_SETUP_STATUS_EP0) { | ||
1762 | tripwire_handler(udc, 0, | ||
1763 | (u8 *) (&udc->local_setup_buff)); | ||
1764 | setup_received_irq(udc, &udc->local_setup_buff); | ||
1765 | status = IRQ_HANDLED; | ||
1766 | } | ||
1767 | |||
1768 | /* completion of dtd */ | ||
1769 | if (fsl_readl(&dr_regs->endptcomplete)) { | ||
1770 | dtd_complete_irq(udc); | ||
1771 | status = IRQ_HANDLED; | ||
1772 | } | ||
1773 | } | ||
1774 | |||
1775 | /* SOF (for ISO transfer) */ | ||
1776 | if (irq_src & USB_STS_SOF) { | ||
1777 | status = IRQ_HANDLED; | ||
1778 | } | ||
1779 | |||
1780 | /* Port Change */ | ||
1781 | if (irq_src & USB_STS_PORT_CHANGE) { | ||
1782 | port_change_irq(udc); | ||
1783 | status = IRQ_HANDLED; | ||
1784 | } | ||
1785 | |||
1786 | /* Reset Received */ | ||
1787 | if (irq_src & USB_STS_RESET) { | ||
1788 | reset_irq(udc); | ||
1789 | status = IRQ_HANDLED; | ||
1790 | } | ||
1791 | |||
1792 | /* Sleep Enable (Suspend) */ | ||
1793 | if (irq_src & USB_STS_SUSPEND) { | ||
1794 | suspend_irq(udc); | ||
1795 | status = IRQ_HANDLED; | ||
1796 | } | ||
1797 | |||
1798 | if (irq_src & (USB_STS_ERR | USB_STS_SYS_ERR)) { | ||
1799 | VDBG("Error IRQ %x ", irq_src); | ||
1800 | } | ||
1801 | |||
1802 | spin_unlock_irqrestore(&udc->lock, flags); | ||
1803 | return status; | ||
1804 | } | ||
1805 | |||
1806 | /*----------------------------------------------------------------* | ||
1807 | * Hook to gadget drivers | ||
1808 | * Called by initialization code of gadget drivers | ||
1809 | *----------------------------------------------------------------*/ | ||
1810 | int usb_gadget_register_driver(struct usb_gadget_driver *driver) | ||
1811 | { | ||
1812 | int retval = -ENODEV; | ||
1813 | unsigned long flags = 0; | ||
1814 | |||
1815 | if (!udc_controller) | ||
1816 | return -ENODEV; | ||
1817 | |||
1818 | if (!driver || (driver->speed != USB_SPEED_FULL | ||
1819 | && driver->speed != USB_SPEED_HIGH) | ||
1820 | || !driver->bind || !driver->disconnect | ||
1821 | || !driver->setup) | ||
1822 | return -EINVAL; | ||
1823 | |||
1824 | if (udc_controller->driver) | ||
1825 | return -EBUSY; | ||
1826 | |||
1827 | /* lock is needed but whether should use this lock or another */ | ||
1828 | spin_lock_irqsave(&udc_controller->lock, flags); | ||
1829 | |||
1830 | driver->driver.bus = 0; | ||
1831 | /* hook up the driver */ | ||
1832 | udc_controller->driver = driver; | ||
1833 | udc_controller->gadget.dev.driver = &driver->driver; | ||
1834 | spin_unlock_irqrestore(&udc_controller->lock, flags); | ||
1835 | |||
1836 | /* bind udc driver to gadget driver */ | ||
1837 | retval = driver->bind(&udc_controller->gadget); | ||
1838 | if (retval) { | ||
1839 | VDBG("bind to %s --> %d", driver->driver.name, retval); | ||
1840 | udc_controller->gadget.dev.driver = 0; | ||
1841 | udc_controller->driver = 0; | ||
1842 | goto out; | ||
1843 | } | ||
1844 | |||
1845 | /* Enable DR IRQ reg and Set usbcmd reg Run bit */ | ||
1846 | dr_controller_run(udc_controller); | ||
1847 | udc_controller->usb_state = USB_STATE_ATTACHED; | ||
1848 | udc_controller->ep0_state = WAIT_FOR_SETUP; | ||
1849 | udc_controller->ep0_dir = 0; | ||
1850 | printk(KERN_INFO "%s: bind to driver %s \n", | ||
1851 | udc_controller->gadget.name, driver->driver.name); | ||
1852 | |||
1853 | out: | ||
1854 | if (retval) | ||
1855 | printk("retval %d \n", retval); | ||
1856 | return retval; | ||
1857 | } | ||
1858 | EXPORT_SYMBOL(usb_gadget_register_driver); | ||
1859 | |||
1860 | /* Disconnect from gadget driver */ | ||
1861 | int usb_gadget_unregister_driver(struct usb_gadget_driver *driver) | ||
1862 | { | ||
1863 | struct fsl_ep *loop_ep; | ||
1864 | unsigned long flags; | ||
1865 | |||
1866 | if (!udc_controller) | ||
1867 | return -ENODEV; | ||
1868 | |||
1869 | if (!driver || driver != udc_controller->driver || !driver->unbind) | ||
1870 | return -EINVAL; | ||
1871 | |||
1872 | #ifdef CONFIG_USB_OTG | ||
1873 | if (udc_controller->transceiver) | ||
1874 | (void)otg_set_peripheral(udc_controller->transceiver, 0); | ||
1875 | #endif | ||
1876 | |||
1877 | /* stop DR, disable intr */ | ||
1878 | dr_controller_stop(udc_controller); | ||
1879 | |||
1880 | /* in fact, no needed */ | ||
1881 | udc_controller->usb_state = USB_STATE_ATTACHED; | ||
1882 | udc_controller->ep0_state = WAIT_FOR_SETUP; | ||
1883 | udc_controller->ep0_dir = 0; | ||
1884 | |||
1885 | /* stand operation */ | ||
1886 | spin_lock_irqsave(&udc_controller->lock, flags); | ||
1887 | udc_controller->gadget.speed = USB_SPEED_UNKNOWN; | ||
1888 | nuke(&udc_controller->eps[0], -ESHUTDOWN); | ||
1889 | list_for_each_entry(loop_ep, &udc_controller->gadget.ep_list, | ||
1890 | ep.ep_list) | ||
1891 | nuke(loop_ep, -ESHUTDOWN); | ||
1892 | spin_unlock_irqrestore(&udc_controller->lock, flags); | ||
1893 | |||
1894 | /* unbind gadget and unhook driver. */ | ||
1895 | driver->unbind(&udc_controller->gadget); | ||
1896 | udc_controller->gadget.dev.driver = 0; | ||
1897 | udc_controller->driver = 0; | ||
1898 | |||
1899 | printk("unregistered gadget driver '%s'\r\n", driver->driver.name); | ||
1900 | return 0; | ||
1901 | } | ||
1902 | EXPORT_SYMBOL(usb_gadget_unregister_driver); | ||
1903 | |||
1904 | /*------------------------------------------------------------------------- | ||
1905 | PROC File System Support | ||
1906 | -------------------------------------------------------------------------*/ | ||
1907 | #ifdef CONFIG_USB_GADGET_DEBUG_FILES | ||
1908 | |||
1909 | #include <linux/seq_file.h> | ||
1910 | |||
1911 | static const char proc_filename[] = "driver/fsl_usb2_udc"; | ||
1912 | |||
1913 | static int fsl_proc_read(char *page, char **start, off_t off, int count, | ||
1914 | int *eof, void *_dev) | ||
1915 | { | ||
1916 | char *buf = page; | ||
1917 | char *next = buf; | ||
1918 | unsigned size = count; | ||
1919 | unsigned long flags; | ||
1920 | int t, i; | ||
1921 | u32 tmp_reg; | ||
1922 | struct fsl_ep *ep = NULL; | ||
1923 | struct fsl_req *req; | ||
1924 | |||
1925 | struct fsl_udc *udc = udc_controller; | ||
1926 | if (off != 0) | ||
1927 | return 0; | ||
1928 | |||
1929 | spin_lock_irqsave(&udc->lock, flags); | ||
1930 | |||
1931 | /* ------basic driver infomation ---- */ | ||
1932 | t = scnprintf(next, size, | ||
1933 | DRIVER_DESC "\n" | ||
1934 | "%s version: %s\n" | ||
1935 | "Gadget driver: %s\n\n", | ||
1936 | driver_name, DRIVER_VERSION, | ||
1937 | udc->driver ? udc->driver->driver.name : "(none)"); | ||
1938 | size -= t; | ||
1939 | next += t; | ||
1940 | |||
1941 | /* ------ DR Registers ----- */ | ||
1942 | tmp_reg = fsl_readl(&dr_regs->usbcmd); | ||
1943 | t = scnprintf(next, size, | ||
1944 | "USBCMD reg:\n" | ||
1945 | "SetupTW: %d\n" | ||
1946 | "Run/Stop: %s\n\n", | ||
1947 | (tmp_reg & USB_CMD_SUTW) ? 1 : 0, | ||
1948 | (tmp_reg & USB_CMD_RUN_STOP) ? "Run" : "Stop"); | ||
1949 | size -= t; | ||
1950 | next += t; | ||
1951 | |||
1952 | tmp_reg = fsl_readl(&dr_regs->usbsts); | ||
1953 | t = scnprintf(next, size, | ||
1954 | "USB Status Reg:\n" | ||
1955 | "Dr Suspend: %d" "Reset Received: %d" "System Error: %s" | ||
1956 | "USB Error Interrupt: %s\n\n", | ||
1957 | (tmp_reg & USB_STS_SUSPEND) ? 1 : 0, | ||
1958 | (tmp_reg & USB_STS_RESET) ? 1 : 0, | ||
1959 | (tmp_reg & USB_STS_SYS_ERR) ? "Err" : "Normal", | ||
1960 | (tmp_reg & USB_STS_ERR) ? "Err detected" : "No err"); | ||
1961 | size -= t; | ||
1962 | next += t; | ||
1963 | |||
1964 | tmp_reg = fsl_readl(&dr_regs->usbintr); | ||
1965 | t = scnprintf(next, size, | ||
1966 | "USB Intrrupt Enable Reg:\n" | ||
1967 | "Sleep Enable: %d" "SOF Received Enable: %d" | ||
1968 | "Reset Enable: %d\n" | ||
1969 | "System Error Enable: %d" | ||
1970 | "Port Change Dectected Enable: %d\n" | ||
1971 | "USB Error Intr Enable: %d" "USB Intr Enable: %d\n\n", | ||
1972 | (tmp_reg & USB_INTR_DEVICE_SUSPEND) ? 1 : 0, | ||
1973 | (tmp_reg & USB_INTR_SOF_EN) ? 1 : 0, | ||
1974 | (tmp_reg & USB_INTR_RESET_EN) ? 1 : 0, | ||
1975 | (tmp_reg & USB_INTR_SYS_ERR_EN) ? 1 : 0, | ||
1976 | (tmp_reg & USB_INTR_PTC_DETECT_EN) ? 1 : 0, | ||
1977 | (tmp_reg & USB_INTR_ERR_INT_EN) ? 1 : 0, | ||
1978 | (tmp_reg & USB_INTR_INT_EN) ? 1 : 0); | ||
1979 | size -= t; | ||
1980 | next += t; | ||
1981 | |||
1982 | tmp_reg = fsl_readl(&dr_regs->frindex); | ||
1983 | t = scnprintf(next, size, | ||
1984 | "USB Frame Index Reg:" "Frame Number is 0x%x\n\n", | ||
1985 | (tmp_reg & USB_FRINDEX_MASKS)); | ||
1986 | size -= t; | ||
1987 | next += t; | ||
1988 | |||
1989 | tmp_reg = fsl_readl(&dr_regs->deviceaddr); | ||
1990 | t = scnprintf(next, size, | ||
1991 | "USB Device Address Reg:" "Device Addr is 0x%x\n\n", | ||
1992 | (tmp_reg & USB_DEVICE_ADDRESS_MASK)); | ||
1993 | size -= t; | ||
1994 | next += t; | ||
1995 | |||
1996 | tmp_reg = fsl_readl(&dr_regs->endpointlistaddr); | ||
1997 | t = scnprintf(next, size, | ||
1998 | "USB Endpoint List Address Reg:" | ||
1999 | "Device Addr is 0x%x\n\n", | ||
2000 | (tmp_reg & USB_EP_LIST_ADDRESS_MASK)); | ||
2001 | size -= t; | ||
2002 | next += t; | ||
2003 | |||
2004 | tmp_reg = fsl_readl(&dr_regs->portsc1); | ||
2005 | t = scnprintf(next, size, | ||
2006 | "USB Port Status&Control Reg:\n" | ||
2007 | "Port Transceiver Type : %s" "Port Speed: %s \n" | ||
2008 | "PHY Low Power Suspend: %s" "Port Reset: %s" | ||
2009 | "Port Suspend Mode: %s \n" "Over-current Change: %s" | ||
2010 | "Port Enable/Disable Change: %s\n" | ||
2011 | "Port Enabled/Disabled: %s" | ||
2012 | "Current Connect Status: %s\n\n", ( { | ||
2013 | char *s; | ||
2014 | switch (tmp_reg & PORTSCX_PTS_FSLS) { | ||
2015 | case PORTSCX_PTS_UTMI: | ||
2016 | s = "UTMI"; break; | ||
2017 | case PORTSCX_PTS_ULPI: | ||
2018 | s = "ULPI "; break; | ||
2019 | case PORTSCX_PTS_FSLS: | ||
2020 | s = "FS/LS Serial"; break; | ||
2021 | default: | ||
2022 | s = "None"; break; | ||
2023 | } | ||
2024 | s;} ), ( { | ||
2025 | char *s; | ||
2026 | switch (tmp_reg & PORTSCX_PORT_SPEED_UNDEF) { | ||
2027 | case PORTSCX_PORT_SPEED_FULL: | ||
2028 | s = "Full Speed"; break; | ||
2029 | case PORTSCX_PORT_SPEED_LOW: | ||
2030 | s = "Low Speed"; break; | ||
2031 | case PORTSCX_PORT_SPEED_HIGH: | ||
2032 | s = "High Speed"; break; | ||
2033 | default: | ||
2034 | s = "Undefined"; break; | ||
2035 | } | ||
2036 | s; | ||
2037 | } ), | ||
2038 | (tmp_reg & PORTSCX_PHY_LOW_POWER_SPD) ? | ||
2039 | "Normal PHY mode" : "Low power mode", | ||
2040 | (tmp_reg & PORTSCX_PORT_RESET) ? "In Reset" : | ||
2041 | "Not in Reset", | ||
2042 | (tmp_reg & PORTSCX_PORT_SUSPEND) ? "In " : "Not in", | ||
2043 | (tmp_reg & PORTSCX_OVER_CURRENT_CHG) ? "Dected" : | ||
2044 | "No", | ||
2045 | (tmp_reg & PORTSCX_PORT_EN_DIS_CHANGE) ? "Disable" : | ||
2046 | "Not change", | ||
2047 | (tmp_reg & PORTSCX_PORT_ENABLE) ? "Enable" : | ||
2048 | "Not correct", | ||
2049 | (tmp_reg & PORTSCX_CURRENT_CONNECT_STATUS) ? | ||
2050 | "Attached" : "Not-Att"); | ||
2051 | size -= t; | ||
2052 | next += t; | ||
2053 | |||
2054 | tmp_reg = fsl_readl(&dr_regs->usbmode); | ||
2055 | t = scnprintf(next, size, | ||
2056 | "USB Mode Reg:" "Controller Mode is : %s\n\n", ( { | ||
2057 | char *s; | ||
2058 | switch (tmp_reg & USB_MODE_CTRL_MODE_HOST) { | ||
2059 | case USB_MODE_CTRL_MODE_IDLE: | ||
2060 | s = "Idle"; break; | ||
2061 | case USB_MODE_CTRL_MODE_DEVICE: | ||
2062 | s = "Device Controller"; break; | ||
2063 | case USB_MODE_CTRL_MODE_HOST: | ||
2064 | s = "Host Controller"; break; | ||
2065 | default: | ||
2066 | s = "None"; break; | ||
2067 | } | ||
2068 | s; | ||
2069 | } )); | ||
2070 | size -= t; | ||
2071 | next += t; | ||
2072 | |||
2073 | tmp_reg = fsl_readl(&dr_regs->endptsetupstat); | ||
2074 | t = scnprintf(next, size, | ||
2075 | "Endpoint Setup Status Reg:" "SETUP on ep 0x%x\n\n", | ||
2076 | (tmp_reg & EP_SETUP_STATUS_MASK)); | ||
2077 | size -= t; | ||
2078 | next += t; | ||
2079 | |||
2080 | for (i = 0; i < udc->max_ep / 2; i++) { | ||
2081 | tmp_reg = fsl_readl(&dr_regs->endptctrl[i]); | ||
2082 | t = scnprintf(next, size, "EP Ctrl Reg [0x%x]: = [0x%x]\n", | ||
2083 | i, tmp_reg); | ||
2084 | size -= t; | ||
2085 | next += t; | ||
2086 | } | ||
2087 | tmp_reg = fsl_readl(&dr_regs->endpointprime); | ||
2088 | t = scnprintf(next, size, "EP Prime Reg = [0x%x]\n", tmp_reg); | ||
2089 | size -= t; | ||
2090 | next += t; | ||
2091 | |||
2092 | tmp_reg = usb_sys_regs->snoop1; | ||
2093 | t = scnprintf(next, size, "\nSnoop1 Reg : = [0x%x]\n\n", tmp_reg); | ||
2094 | size -= t; | ||
2095 | next += t; | ||
2096 | |||
2097 | tmp_reg = usb_sys_regs->control; | ||
2098 | t = scnprintf(next, size, "General Control Reg : = [0x%x]\n\n", | ||
2099 | tmp_reg); | ||
2100 | size -= t; | ||
2101 | next += t; | ||
2102 | |||
2103 | /* ------fsl_udc, fsl_ep, fsl_request structure information ----- */ | ||
2104 | ep = &udc->eps[0]; | ||
2105 | t = scnprintf(next, size, "For %s Maxpkt is 0x%x index is 0x%x\n", | ||
2106 | ep->ep.name, ep_maxpacket(ep), ep_index(ep)); | ||
2107 | size -= t; | ||
2108 | next += t; | ||
2109 | |||
2110 | if (list_empty(&ep->queue)) { | ||
2111 | t = scnprintf(next, size, "its req queue is empty\n\n"); | ||
2112 | size -= t; | ||
2113 | next += t; | ||
2114 | } else { | ||
2115 | list_for_each_entry(req, &ep->queue, queue) { | ||
2116 | t = scnprintf(next, size, | ||
2117 | "req %p actual 0x%x length 0x%x buf %p\n", | ||
2118 | &req->req, req->req.actual, | ||
2119 | req->req.length, req->req.buf); | ||
2120 | size -= t; | ||
2121 | next += t; | ||
2122 | } | ||
2123 | } | ||
2124 | /* other gadget->eplist ep */ | ||
2125 | list_for_each_entry(ep, &udc->gadget.ep_list, ep.ep_list) { | ||
2126 | if (ep->desc) { | ||
2127 | t = scnprintf(next, size, | ||
2128 | "\nFor %s Maxpkt is 0x%x " | ||
2129 | "index is 0x%x\n", | ||
2130 | ep->ep.name, ep_maxpacket(ep), | ||
2131 | ep_index(ep)); | ||
2132 | size -= t; | ||
2133 | next += t; | ||
2134 | |||
2135 | if (list_empty(&ep->queue)) { | ||
2136 | t = scnprintf(next, size, | ||
2137 | "its req queue is empty\n\n"); | ||
2138 | size -= t; | ||
2139 | next += t; | ||
2140 | } else { | ||
2141 | list_for_each_entry(req, &ep->queue, queue) { | ||
2142 | t = scnprintf(next, size, | ||
2143 | "req %p actual 0x%x length" | ||
2144 | "0x%x buf %p\n", | ||
2145 | &req->req, req->req.actual, | ||
2146 | req->req.length, req->req.buf); | ||
2147 | size -= t; | ||
2148 | next += t; | ||
2149 | } /* end for each_entry of ep req */ | ||
2150 | } /* end for else */ | ||
2151 | } /* end for if(ep->queue) */ | ||
2152 | } /* end (ep->desc) */ | ||
2153 | |||
2154 | spin_unlock_irqrestore(&udc->lock, flags); | ||
2155 | |||
2156 | *eof = 1; | ||
2157 | return count - size; | ||
2158 | } | ||
2159 | |||
2160 | #define create_proc_file() create_proc_read_entry(proc_filename, \ | ||
2161 | 0, NULL, fsl_proc_read, NULL) | ||
2162 | |||
2163 | #define remove_proc_file() remove_proc_entry(proc_filename, NULL) | ||
2164 | |||
2165 | #else /* !CONFIG_USB_GADGET_DEBUG_FILES */ | ||
2166 | |||
2167 | #define create_proc_file() do {} while (0) | ||
2168 | #define remove_proc_file() do {} while (0) | ||
2169 | |||
2170 | #endif /* CONFIG_USB_GADGET_DEBUG_FILES */ | ||
2171 | |||
2172 | /*-------------------------------------------------------------------------*/ | ||
2173 | |||
2174 | /* Release udc structures */ | ||
2175 | static void fsl_udc_release(struct device *dev) | ||
2176 | { | ||
2177 | complete(udc_controller->done); | ||
2178 | dma_free_coherent(dev, udc_controller->ep_qh_size, | ||
2179 | udc_controller->ep_qh, udc_controller->ep_qh_dma); | ||
2180 | kfree(udc_controller); | ||
2181 | } | ||
2182 | |||
2183 | /****************************************************************** | ||
2184 | Internal structure setup functions | ||
2185 | *******************************************************************/ | ||
2186 | /*------------------------------------------------------------------ | ||
2187 | * init resource for globle controller | ||
2188 | * Return the udc handle on success or NULL on failure | ||
2189 | ------------------------------------------------------------------*/ | ||
2190 | static struct fsl_udc *__init struct_udc_setup(struct platform_device *pdev) | ||
2191 | { | ||
2192 | struct fsl_udc *udc; | ||
2193 | struct fsl_usb2_platform_data *pdata; | ||
2194 | size_t size; | ||
2195 | |||
2196 | udc = kzalloc(sizeof(struct fsl_udc), GFP_KERNEL); | ||
2197 | if (udc == NULL) { | ||
2198 | ERR("malloc udc failed\n"); | ||
2199 | return NULL; | ||
2200 | } | ||
2201 | |||
2202 | pdata = pdev->dev.platform_data; | ||
2203 | udc->phy_mode = pdata->phy_mode; | ||
2204 | /* max_ep_nr is bidirectional ep number, max_ep doubles the number */ | ||
2205 | udc->max_ep = pdata->max_ep_nr * 2; | ||
2206 | |||
2207 | udc->eps = kzalloc(sizeof(struct fsl_ep) * udc->max_ep, GFP_KERNEL); | ||
2208 | if (!udc->eps) { | ||
2209 | ERR("malloc fsl_ep failed\n"); | ||
2210 | goto cleanup; | ||
2211 | } | ||
2212 | |||
2213 | /* initialized QHs, take care of alignment */ | ||
2214 | size = udc->max_ep * sizeof(struct ep_queue_head); | ||
2215 | if (size < QH_ALIGNMENT) | ||
2216 | size = QH_ALIGNMENT; | ||
2217 | else if ((size % QH_ALIGNMENT) != 0) { | ||
2218 | size += QH_ALIGNMENT + 1; | ||
2219 | size &= ~(QH_ALIGNMENT - 1); | ||
2220 | } | ||
2221 | udc->ep_qh = dma_alloc_coherent(&pdev->dev, size, | ||
2222 | &udc->ep_qh_dma, GFP_KERNEL); | ||
2223 | if (!udc->ep_qh) { | ||
2224 | ERR("malloc QHs for udc failed\n"); | ||
2225 | kfree(udc->eps); | ||
2226 | goto cleanup; | ||
2227 | } | ||
2228 | |||
2229 | udc->ep_qh_size = size; | ||
2230 | |||
2231 | /* Initialize ep0 status request structure */ | ||
2232 | /* FIXME: fsl_alloc_request() ignores ep argument */ | ||
2233 | udc->status_req = container_of(fsl_alloc_request(NULL, GFP_KERNEL), | ||
2234 | struct fsl_req, req); | ||
2235 | /* allocate a small amount of memory to get valid address */ | ||
2236 | udc->status_req->req.buf = kmalloc(8, GFP_KERNEL); | ||
2237 | udc->status_req->req.dma = virt_to_phys(udc->status_req->req.buf); | ||
2238 | |||
2239 | udc->resume_state = USB_STATE_NOTATTACHED; | ||
2240 | udc->usb_state = USB_STATE_POWERED; | ||
2241 | udc->ep0_dir = 0; | ||
2242 | udc->remote_wakeup = 0; /* default to 0 on reset */ | ||
2243 | spin_lock_init(&udc->lock); | ||
2244 | |||
2245 | return udc; | ||
2246 | |||
2247 | cleanup: | ||
2248 | kfree(udc); | ||
2249 | return NULL; | ||
2250 | } | ||
2251 | |||
2252 | /*---------------------------------------------------------------- | ||
2253 | * Setup the fsl_ep struct for eps | ||
2254 | * Link fsl_ep->ep to gadget->ep_list | ||
2255 | * ep0out is not used so do nothing here | ||
2256 | * ep0in should be taken care | ||
2257 | *--------------------------------------------------------------*/ | ||
2258 | static int __init struct_ep_setup(struct fsl_udc *udc, unsigned char index, | ||
2259 | char *name, int link) | ||
2260 | { | ||
2261 | struct fsl_ep *ep = &udc->eps[index]; | ||
2262 | |||
2263 | ep->udc = udc; | ||
2264 | strcpy(ep->name, name); | ||
2265 | ep->ep.name = ep->name; | ||
2266 | |||
2267 | ep->ep.ops = &fsl_ep_ops; | ||
2268 | ep->stopped = 0; | ||
2269 | |||
2270 | /* for ep0: maxP defined in desc | ||
2271 | * for other eps, maxP is set by epautoconfig() called by gadget layer | ||
2272 | */ | ||
2273 | ep->ep.maxpacket = (unsigned short) ~0; | ||
2274 | |||
2275 | /* the queue lists any req for this ep */ | ||
2276 | INIT_LIST_HEAD(&ep->queue); | ||
2277 | |||
2278 | /* gagdet.ep_list used for ep_autoconfig so no ep0 */ | ||
2279 | if (link) | ||
2280 | list_add_tail(&ep->ep.ep_list, &udc->gadget.ep_list); | ||
2281 | ep->gadget = &udc->gadget; | ||
2282 | ep->qh = &udc->ep_qh[index]; | ||
2283 | |||
2284 | return 0; | ||
2285 | } | ||
2286 | |||
2287 | /* Driver probe function | ||
2288 | * all intialize operations implemented here except enabling usb_intr reg | ||
2289 | */ | ||
2290 | static int __init fsl_udc_probe(struct platform_device *pdev) | ||
2291 | { | ||
2292 | struct resource *res; | ||
2293 | int ret = -ENODEV; | ||
2294 | unsigned int i; | ||
2295 | |||
2296 | if (strcmp(pdev->name, driver_name)) { | ||
2297 | VDBG("Wrong device\n"); | ||
2298 | return -ENODEV; | ||
2299 | } | ||
2300 | |||
2301 | /* board setup should have been done in the platform code */ | ||
2302 | |||
2303 | /* Initialize the udc structure including QH member and other member */ | ||
2304 | udc_controller = struct_udc_setup(pdev); | ||
2305 | if (!udc_controller) { | ||
2306 | VDBG("udc_controller is NULL \n"); | ||
2307 | return -ENOMEM; | ||
2308 | } | ||
2309 | |||
2310 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); | ||
2311 | if (!res) | ||
2312 | return -ENXIO; | ||
2313 | |||
2314 | if (!request_mem_region(res->start, res->end - res->start + 1, | ||
2315 | driver_name)) { | ||
2316 | ERR("request mem region for %s failed \n", pdev->name); | ||
2317 | return -EBUSY; | ||
2318 | } | ||
2319 | |||
2320 | dr_regs = ioremap(res->start, res->end - res->start + 1); | ||
2321 | if (!dr_regs) { | ||
2322 | ret = -ENOMEM; | ||
2323 | goto err1; | ||
2324 | } | ||
2325 | |||
2326 | usb_sys_regs = (struct usb_sys_interface *) | ||
2327 | ((u32)dr_regs + USB_DR_SYS_OFFSET); | ||
2328 | |||
2329 | udc_controller->irq = platform_get_irq(pdev, 0); | ||
2330 | if (!udc_controller->irq) { | ||
2331 | ret = -ENODEV; | ||
2332 | goto err2; | ||
2333 | } | ||
2334 | |||
2335 | ret = request_irq(udc_controller->irq, fsl_udc_irq, SA_SHIRQ, | ||
2336 | driver_name, udc_controller); | ||
2337 | if (ret != 0) { | ||
2338 | ERR("cannot request irq %d err %d \n", | ||
2339 | udc_controller->irq, ret); | ||
2340 | goto err2; | ||
2341 | } | ||
2342 | |||
2343 | /* initialize usb hw reg except for regs for EP, | ||
2344 | * leave usbintr reg untouched */ | ||
2345 | dr_controller_setup(udc_controller); | ||
2346 | |||
2347 | /* Setup gadget structure */ | ||
2348 | udc_controller->gadget.ops = &fsl_gadget_ops; | ||
2349 | udc_controller->gadget.is_dualspeed = 1; | ||
2350 | udc_controller->gadget.ep0 = &udc_controller->eps[0].ep; | ||
2351 | INIT_LIST_HEAD(&udc_controller->gadget.ep_list); | ||
2352 | udc_controller->gadget.speed = USB_SPEED_UNKNOWN; | ||
2353 | udc_controller->gadget.name = driver_name; | ||
2354 | |||
2355 | /* Setup gadget.dev and register with kernel */ | ||
2356 | strcpy(udc_controller->gadget.dev.bus_id, "gadget"); | ||
2357 | udc_controller->gadget.dev.release = fsl_udc_release; | ||
2358 | udc_controller->gadget.dev.parent = &pdev->dev; | ||
2359 | ret = device_register(&udc_controller->gadget.dev); | ||
2360 | if (ret < 0) | ||
2361 | goto err3; | ||
2362 | |||
2363 | /* setup QH and epctrl for ep0 */ | ||
2364 | ep0_setup(udc_controller); | ||
2365 | |||
2366 | /* setup udc->eps[] for ep0 */ | ||
2367 | struct_ep_setup(udc_controller, 0, "ep0", 0); | ||
2368 | /* for ep0: the desc defined here; | ||
2369 | * for other eps, gadget layer called ep_enable with defined desc | ||
2370 | */ | ||
2371 | udc_controller->eps[0].desc = &fsl_ep0_desc; | ||
2372 | udc_controller->eps[0].ep.maxpacket = USB_MAX_CTRL_PAYLOAD; | ||
2373 | |||
2374 | /* setup the udc->eps[] for non-control endpoints and link | ||
2375 | * to gadget.ep_list */ | ||
2376 | for (i = 1; i < (int)(udc_controller->max_ep / 2); i++) { | ||
2377 | char name[14]; | ||
2378 | |||
2379 | sprintf(name, "ep%dout", i); | ||
2380 | struct_ep_setup(udc_controller, i * 2, name, 1); | ||
2381 | sprintf(name, "ep%din", i); | ||
2382 | struct_ep_setup(udc_controller, i * 2 + 1, name, 1); | ||
2383 | } | ||
2384 | |||
2385 | /* use dma_pool for TD management */ | ||
2386 | udc_controller->td_pool = dma_pool_create("udc_td", &pdev->dev, | ||
2387 | sizeof(struct ep_td_struct), | ||
2388 | DTD_ALIGNMENT, UDC_DMA_BOUNDARY); | ||
2389 | if (udc_controller->td_pool == NULL) { | ||
2390 | ret = -ENOMEM; | ||
2391 | goto err4; | ||
2392 | } | ||
2393 | create_proc_file(); | ||
2394 | return 0; | ||
2395 | |||
2396 | err4: | ||
2397 | device_unregister(&udc_controller->gadget.dev); | ||
2398 | err3: | ||
2399 | free_irq(udc_controller->irq, udc_controller); | ||
2400 | err2: | ||
2401 | iounmap(dr_regs); | ||
2402 | err1: | ||
2403 | release_mem_region(res->start, res->end - res->start + 1); | ||
2404 | return ret; | ||
2405 | } | ||
2406 | |||
2407 | /* Driver removal function | ||
2408 | * Free resources and finish pending transactions | ||
2409 | */ | ||
2410 | static int __exit fsl_udc_remove(struct platform_device *pdev) | ||
2411 | { | ||
2412 | struct resource *res = platform_get_resource(pdev, IORESOURCE_MEM, 0); | ||
2413 | |||
2414 | DECLARE_COMPLETION(done); | ||
2415 | |||
2416 | if (!udc_controller) | ||
2417 | return -ENODEV; | ||
2418 | udc_controller->done = &done; | ||
2419 | |||
2420 | /* DR has been stopped in usb_gadget_unregister_driver() */ | ||
2421 | remove_proc_file(); | ||
2422 | |||
2423 | /* Free allocated memory */ | ||
2424 | kfree(udc_controller->status_req->req.buf); | ||
2425 | kfree(udc_controller->status_req); | ||
2426 | kfree(udc_controller->eps); | ||
2427 | |||
2428 | dma_pool_destroy(udc_controller->td_pool); | ||
2429 | free_irq(udc_controller->irq, udc_controller); | ||
2430 | iounmap(dr_regs); | ||
2431 | release_mem_region(res->start, res->end - res->start + 1); | ||
2432 | |||
2433 | device_unregister(&udc_controller->gadget.dev); | ||
2434 | /* free udc --wait for the release() finished */ | ||
2435 | wait_for_completion(&done); | ||
2436 | |||
2437 | return 0; | ||
2438 | } | ||
2439 | |||
2440 | /*----------------------------------------------------------------- | ||
2441 | * Modify Power management attributes | ||
2442 | * Used by OTG statemachine to disable gadget temporarily | ||
2443 | -----------------------------------------------------------------*/ | ||
2444 | static int fsl_udc_suspend(struct platform_device *pdev, pm_message_t state) | ||
2445 | { | ||
2446 | dr_controller_stop(udc_controller); | ||
2447 | return 0; | ||
2448 | } | ||
2449 | |||
2450 | /*----------------------------------------------------------------- | ||
2451 | * Invoked on USB resume. May be called in_interrupt. | ||
2452 | * Here we start the DR controller and enable the irq | ||
2453 | *-----------------------------------------------------------------*/ | ||
2454 | static int fsl_udc_resume(struct platform_device *pdev) | ||
2455 | { | ||
2456 | /* Enable DR irq reg and set controller Run */ | ||
2457 | if (udc_controller->stopped) { | ||
2458 | dr_controller_setup(udc_controller); | ||
2459 | dr_controller_run(udc_controller); | ||
2460 | } | ||
2461 | udc_controller->usb_state = USB_STATE_ATTACHED; | ||
2462 | udc_controller->ep0_state = WAIT_FOR_SETUP; | ||
2463 | udc_controller->ep0_dir = 0; | ||
2464 | return 0; | ||
2465 | } | ||
2466 | |||
2467 | /*------------------------------------------------------------------------- | ||
2468 | Register entry point for the peripheral controller driver | ||
2469 | --------------------------------------------------------------------------*/ | ||
2470 | |||
2471 | static struct platform_driver udc_driver = { | ||
2472 | .remove = __exit_p(fsl_udc_remove), | ||
2473 | /* these suspend and resume are not usb suspend and resume */ | ||
2474 | .suspend = fsl_udc_suspend, | ||
2475 | .resume = fsl_udc_resume, | ||
2476 | .driver = { | ||
2477 | .name = (char *)driver_name, | ||
2478 | .owner = THIS_MODULE, | ||
2479 | }, | ||
2480 | }; | ||
2481 | |||
2482 | static int __init udc_init(void) | ||
2483 | { | ||
2484 | printk(KERN_INFO "%s (%s)\n", driver_desc, DRIVER_VERSION); | ||
2485 | return platform_driver_probe(&udc_driver, fsl_udc_probe); | ||
2486 | } | ||
2487 | |||
2488 | module_init(udc_init); | ||
2489 | |||
2490 | static void __exit udc_exit(void) | ||
2491 | { | ||
2492 | platform_driver_unregister(&udc_driver); | ||
2493 | printk("%s unregistered \n", driver_desc); | ||
2494 | } | ||
2495 | |||
2496 | module_exit(udc_exit); | ||
2497 | |||
2498 | MODULE_DESCRIPTION(DRIVER_DESC); | ||
2499 | MODULE_AUTHOR(DRIVER_AUTHOR); | ||
2500 | MODULE_LICENSE("GPL"); | ||
diff --git a/drivers/usb/gadget/fsl_usb2_udc.h b/drivers/usb/gadget/fsl_usb2_udc.h new file mode 100644 index 000000000000..c6291e046507 --- /dev/null +++ b/drivers/usb/gadget/fsl_usb2_udc.h | |||
@@ -0,0 +1,579 @@ | |||
1 | /* | ||
2 | * Freescale USB device/endpoint management registers | ||
3 | */ | ||
4 | #ifndef __FSL_USB2_UDC_H | ||
5 | #define __FSL_USB2_UDC_H | ||
6 | |||
7 | /* ### define USB registers here | ||
8 | */ | ||
9 | #define USB_MAX_CTRL_PAYLOAD 64 | ||
10 | #define USB_DR_SYS_OFFSET 0x400 | ||
11 | |||
12 | /* USB DR device mode registers (Little Endian) */ | ||
13 | struct usb_dr_device { | ||
14 | /* Capability register */ | ||
15 | u8 res1[256]; | ||
16 | u16 caplength; /* Capability Register Length */ | ||
17 | u16 hciversion; /* Host Controller Interface Version */ | ||
18 | u32 hcsparams; /* Host Controller Structual Parameters */ | ||
19 | u32 hccparams; /* Host Controller Capability Parameters */ | ||
20 | u8 res2[20]; | ||
21 | u32 dciversion; /* Device Controller Interface Version */ | ||
22 | u32 dccparams; /* Device Controller Capability Parameters */ | ||
23 | u8 res3[24]; | ||
24 | /* Operation register */ | ||
25 | u32 usbcmd; /* USB Command Register */ | ||
26 | u32 usbsts; /* USB Status Register */ | ||
27 | u32 usbintr; /* USB Interrupt Enable Register */ | ||
28 | u32 frindex; /* Frame Index Register */ | ||
29 | u8 res4[4]; | ||
30 | u32 deviceaddr; /* Device Address */ | ||
31 | u32 endpointlistaddr; /* Endpoint List Address Register */ | ||
32 | u8 res5[4]; | ||
33 | u32 burstsize; /* Master Interface Data Burst Size Register */ | ||
34 | u32 txttfilltuning; /* Transmit FIFO Tuning Controls Register */ | ||
35 | u8 res6[24]; | ||
36 | u32 configflag; /* Configure Flag Register */ | ||
37 | u32 portsc1; /* Port 1 Status and Control Register */ | ||
38 | u8 res7[28]; | ||
39 | u32 otgsc; /* On-The-Go Status and Control */ | ||
40 | u32 usbmode; /* USB Mode Register */ | ||
41 | u32 endptsetupstat; /* Endpoint Setup Status Register */ | ||
42 | u32 endpointprime; /* Endpoint Initialization Register */ | ||
43 | u32 endptflush; /* Endpoint Flush Register */ | ||
44 | u32 endptstatus; /* Endpoint Status Register */ | ||
45 | u32 endptcomplete; /* Endpoint Complete Register */ | ||
46 | u32 endptctrl[6]; /* Endpoint Control Registers */ | ||
47 | }; | ||
48 | |||
49 | /* USB DR host mode registers (Little Endian) */ | ||
50 | struct usb_dr_host { | ||
51 | /* Capability register */ | ||
52 | u8 res1[256]; | ||
53 | u16 caplength; /* Capability Register Length */ | ||
54 | u16 hciversion; /* Host Controller Interface Version */ | ||
55 | u32 hcsparams; /* Host Controller Structual Parameters */ | ||
56 | u32 hccparams; /* Host Controller Capability Parameters */ | ||
57 | u8 res2[20]; | ||
58 | u32 dciversion; /* Device Controller Interface Version */ | ||
59 | u32 dccparams; /* Device Controller Capability Parameters */ | ||
60 | u8 res3[24]; | ||
61 | /* Operation register */ | ||
62 | u32 usbcmd; /* USB Command Register */ | ||
63 | u32 usbsts; /* USB Status Register */ | ||
64 | u32 usbintr; /* USB Interrupt Enable Register */ | ||
65 | u32 frindex; /* Frame Index Register */ | ||
66 | u8 res4[4]; | ||
67 | u32 periodiclistbase; /* Periodic Frame List Base Address Register */ | ||
68 | u32 asynclistaddr; /* Current Asynchronous List Address Register */ | ||
69 | u8 res5[4]; | ||
70 | u32 burstsize; /* Master Interface Data Burst Size Register */ | ||
71 | u32 txttfilltuning; /* Transmit FIFO Tuning Controls Register */ | ||
72 | u8 res6[24]; | ||
73 | u32 configflag; /* Configure Flag Register */ | ||
74 | u32 portsc1; /* Port 1 Status and Control Register */ | ||
75 | u8 res7[28]; | ||
76 | u32 otgsc; /* On-The-Go Status and Control */ | ||
77 | u32 usbmode; /* USB Mode Register */ | ||
78 | u32 endptsetupstat; /* Endpoint Setup Status Register */ | ||
79 | u32 endpointprime; /* Endpoint Initialization Register */ | ||
80 | u32 endptflush; /* Endpoint Flush Register */ | ||
81 | u32 endptstatus; /* Endpoint Status Register */ | ||
82 | u32 endptcomplete; /* Endpoint Complete Register */ | ||
83 | u32 endptctrl[6]; /* Endpoint Control Registers */ | ||
84 | }; | ||
85 | |||
86 | /* non-EHCI USB system interface registers (Big Endian) */ | ||
87 | struct usb_sys_interface { | ||
88 | u32 snoop1; | ||
89 | u32 snoop2; | ||
90 | u32 age_cnt_thresh; /* Age Count Threshold Register */ | ||
91 | u32 pri_ctrl; /* Priority Control Register */ | ||
92 | u32 si_ctrl; /* System Interface Control Register */ | ||
93 | u8 res[236]; | ||
94 | u32 control; /* General Purpose Control Register */ | ||
95 | }; | ||
96 | |||
97 | /* ep0 transfer state */ | ||
98 | #define WAIT_FOR_SETUP 0 | ||
99 | #define DATA_STATE_XMIT 1 | ||
100 | #define DATA_STATE_NEED_ZLP 2 | ||
101 | #define WAIT_FOR_OUT_STATUS 3 | ||
102 | #define DATA_STATE_RECV 4 | ||
103 | |||
104 | /* Frame Index Register Bit Masks */ | ||
105 | #define USB_FRINDEX_MASKS 0x3fff | ||
106 | /* USB CMD Register Bit Masks */ | ||
107 | #define USB_CMD_RUN_STOP 0x00000001 | ||
108 | #define USB_CMD_CTRL_RESET 0x00000002 | ||
109 | #define USB_CMD_PERIODIC_SCHEDULE_EN 0x00000010 | ||
110 | #define USB_CMD_ASYNC_SCHEDULE_EN 0x00000020 | ||
111 | #define USB_CMD_INT_AA_DOORBELL 0x00000040 | ||
112 | #define USB_CMD_ASP 0x00000300 | ||
113 | #define USB_CMD_ASYNC_SCH_PARK_EN 0x00000800 | ||
114 | #define USB_CMD_SUTW 0x00002000 | ||
115 | #define USB_CMD_ATDTW 0x00004000 | ||
116 | #define USB_CMD_ITC 0x00FF0000 | ||
117 | |||
118 | /* bit 15,3,2 are frame list size */ | ||
119 | #define USB_CMD_FRAME_SIZE_1024 0x00000000 | ||
120 | #define USB_CMD_FRAME_SIZE_512 0x00000004 | ||
121 | #define USB_CMD_FRAME_SIZE_256 0x00000008 | ||
122 | #define USB_CMD_FRAME_SIZE_128 0x0000000C | ||
123 | #define USB_CMD_FRAME_SIZE_64 0x00008000 | ||
124 | #define USB_CMD_FRAME_SIZE_32 0x00008004 | ||
125 | #define USB_CMD_FRAME_SIZE_16 0x00008008 | ||
126 | #define USB_CMD_FRAME_SIZE_8 0x0000800C | ||
127 | |||
128 | /* bit 9-8 are async schedule park mode count */ | ||
129 | #define USB_CMD_ASP_00 0x00000000 | ||
130 | #define USB_CMD_ASP_01 0x00000100 | ||
131 | #define USB_CMD_ASP_10 0x00000200 | ||
132 | #define USB_CMD_ASP_11 0x00000300 | ||
133 | #define USB_CMD_ASP_BIT_POS 8 | ||
134 | |||
135 | /* bit 23-16 are interrupt threshold control */ | ||
136 | #define USB_CMD_ITC_NO_THRESHOLD 0x00000000 | ||
137 | #define USB_CMD_ITC_1_MICRO_FRM 0x00010000 | ||
138 | #define USB_CMD_ITC_2_MICRO_FRM 0x00020000 | ||
139 | #define USB_CMD_ITC_4_MICRO_FRM 0x00040000 | ||
140 | #define USB_CMD_ITC_8_MICRO_FRM 0x00080000 | ||
141 | #define USB_CMD_ITC_16_MICRO_FRM 0x00100000 | ||
142 | #define USB_CMD_ITC_32_MICRO_FRM 0x00200000 | ||
143 | #define USB_CMD_ITC_64_MICRO_FRM 0x00400000 | ||
144 | #define USB_CMD_ITC_BIT_POS 16 | ||
145 | |||
146 | /* USB STS Register Bit Masks */ | ||
147 | #define USB_STS_INT 0x00000001 | ||
148 | #define USB_STS_ERR 0x00000002 | ||
149 | #define USB_STS_PORT_CHANGE 0x00000004 | ||
150 | #define USB_STS_FRM_LST_ROLL 0x00000008 | ||
151 | #define USB_STS_SYS_ERR 0x00000010 | ||
152 | #define USB_STS_IAA 0x00000020 | ||
153 | #define USB_STS_RESET 0x00000040 | ||
154 | #define USB_STS_SOF 0x00000080 | ||
155 | #define USB_STS_SUSPEND 0x00000100 | ||
156 | #define USB_STS_HC_HALTED 0x00001000 | ||
157 | #define USB_STS_RCL 0x00002000 | ||
158 | #define USB_STS_PERIODIC_SCHEDULE 0x00004000 | ||
159 | #define USB_STS_ASYNC_SCHEDULE 0x00008000 | ||
160 | |||
161 | /* USB INTR Register Bit Masks */ | ||
162 | #define USB_INTR_INT_EN 0x00000001 | ||
163 | #define USB_INTR_ERR_INT_EN 0x00000002 | ||
164 | #define USB_INTR_PTC_DETECT_EN 0x00000004 | ||
165 | #define USB_INTR_FRM_LST_ROLL_EN 0x00000008 | ||
166 | #define USB_INTR_SYS_ERR_EN 0x00000010 | ||
167 | #define USB_INTR_ASYN_ADV_EN 0x00000020 | ||
168 | #define USB_INTR_RESET_EN 0x00000040 | ||
169 | #define USB_INTR_SOF_EN 0x00000080 | ||
170 | #define USB_INTR_DEVICE_SUSPEND 0x00000100 | ||
171 | |||
172 | /* Device Address bit masks */ | ||
173 | #define USB_DEVICE_ADDRESS_MASK 0xFE000000 | ||
174 | #define USB_DEVICE_ADDRESS_BIT_POS 25 | ||
175 | |||
176 | /* endpoint list address bit masks */ | ||
177 | #define USB_EP_LIST_ADDRESS_MASK 0xfffff800 | ||
178 | |||
179 | /* PORTSCX Register Bit Masks */ | ||
180 | #define PORTSCX_CURRENT_CONNECT_STATUS 0x00000001 | ||
181 | #define PORTSCX_CONNECT_STATUS_CHANGE 0x00000002 | ||
182 | #define PORTSCX_PORT_ENABLE 0x00000004 | ||
183 | #define PORTSCX_PORT_EN_DIS_CHANGE 0x00000008 | ||
184 | #define PORTSCX_OVER_CURRENT_ACT 0x00000010 | ||
185 | #define PORTSCX_OVER_CURRENT_CHG 0x00000020 | ||
186 | #define PORTSCX_PORT_FORCE_RESUME 0x00000040 | ||
187 | #define PORTSCX_PORT_SUSPEND 0x00000080 | ||
188 | #define PORTSCX_PORT_RESET 0x00000100 | ||
189 | #define PORTSCX_LINE_STATUS_BITS 0x00000C00 | ||
190 | #define PORTSCX_PORT_POWER 0x00001000 | ||
191 | #define PORTSCX_PORT_INDICTOR_CTRL 0x0000C000 | ||
192 | #define PORTSCX_PORT_TEST_CTRL 0x000F0000 | ||
193 | #define PORTSCX_WAKE_ON_CONNECT_EN 0x00100000 | ||
194 | #define PORTSCX_WAKE_ON_CONNECT_DIS 0x00200000 | ||
195 | #define PORTSCX_WAKE_ON_OVER_CURRENT 0x00400000 | ||
196 | #define PORTSCX_PHY_LOW_POWER_SPD 0x00800000 | ||
197 | #define PORTSCX_PORT_FORCE_FULL_SPEED 0x01000000 | ||
198 | #define PORTSCX_PORT_SPEED_MASK 0x0C000000 | ||
199 | #define PORTSCX_PORT_WIDTH 0x10000000 | ||
200 | #define PORTSCX_PHY_TYPE_SEL 0xC0000000 | ||
201 | |||
202 | /* bit 11-10 are line status */ | ||
203 | #define PORTSCX_LINE_STATUS_SE0 0x00000000 | ||
204 | #define PORTSCX_LINE_STATUS_JSTATE 0x00000400 | ||
205 | #define PORTSCX_LINE_STATUS_KSTATE 0x00000800 | ||
206 | #define PORTSCX_LINE_STATUS_UNDEF 0x00000C00 | ||
207 | #define PORTSCX_LINE_STATUS_BIT_POS 10 | ||
208 | |||
209 | /* bit 15-14 are port indicator control */ | ||
210 | #define PORTSCX_PIC_OFF 0x00000000 | ||
211 | #define PORTSCX_PIC_AMBER 0x00004000 | ||
212 | #define PORTSCX_PIC_GREEN 0x00008000 | ||
213 | #define PORTSCX_PIC_UNDEF 0x0000C000 | ||
214 | #define PORTSCX_PIC_BIT_POS 14 | ||
215 | |||
216 | /* bit 19-16 are port test control */ | ||
217 | #define PORTSCX_PTC_DISABLE 0x00000000 | ||
218 | #define PORTSCX_PTC_JSTATE 0x00010000 | ||
219 | #define PORTSCX_PTC_KSTATE 0x00020000 | ||
220 | #define PORTSCX_PTC_SEQNAK 0x00030000 | ||
221 | #define PORTSCX_PTC_PACKET 0x00040000 | ||
222 | #define PORTSCX_PTC_FORCE_EN 0x00050000 | ||
223 | #define PORTSCX_PTC_BIT_POS 16 | ||
224 | |||
225 | /* bit 27-26 are port speed */ | ||
226 | #define PORTSCX_PORT_SPEED_FULL 0x00000000 | ||
227 | #define PORTSCX_PORT_SPEED_LOW 0x04000000 | ||
228 | #define PORTSCX_PORT_SPEED_HIGH 0x08000000 | ||
229 | #define PORTSCX_PORT_SPEED_UNDEF 0x0C000000 | ||
230 | #define PORTSCX_SPEED_BIT_POS 26 | ||
231 | |||
232 | /* bit 28 is parallel transceiver width for UTMI interface */ | ||
233 | #define PORTSCX_PTW 0x10000000 | ||
234 | #define PORTSCX_PTW_8BIT 0x00000000 | ||
235 | #define PORTSCX_PTW_16BIT 0x10000000 | ||
236 | |||
237 | /* bit 31-30 are port transceiver select */ | ||
238 | #define PORTSCX_PTS_UTMI 0x00000000 | ||
239 | #define PORTSCX_PTS_ULPI 0x80000000 | ||
240 | #define PORTSCX_PTS_FSLS 0xC0000000 | ||
241 | #define PORTSCX_PTS_BIT_POS 30 | ||
242 | |||
243 | /* otgsc Register Bit Masks */ | ||
244 | #define OTGSC_CTRL_VUSB_DISCHARGE 0x00000001 | ||
245 | #define OTGSC_CTRL_VUSB_CHARGE 0x00000002 | ||
246 | #define OTGSC_CTRL_OTG_TERM 0x00000008 | ||
247 | #define OTGSC_CTRL_DATA_PULSING 0x00000010 | ||
248 | #define OTGSC_STS_USB_ID 0x00000100 | ||
249 | #define OTGSC_STS_A_VBUS_VALID 0x00000200 | ||
250 | #define OTGSC_STS_A_SESSION_VALID 0x00000400 | ||
251 | #define OTGSC_STS_B_SESSION_VALID 0x00000800 | ||
252 | #define OTGSC_STS_B_SESSION_END 0x00001000 | ||
253 | #define OTGSC_STS_1MS_TOGGLE 0x00002000 | ||
254 | #define OTGSC_STS_DATA_PULSING 0x00004000 | ||
255 | #define OTGSC_INTSTS_USB_ID 0x00010000 | ||
256 | #define OTGSC_INTSTS_A_VBUS_VALID 0x00020000 | ||
257 | #define OTGSC_INTSTS_A_SESSION_VALID 0x00040000 | ||
258 | #define OTGSC_INTSTS_B_SESSION_VALID 0x00080000 | ||
259 | #define OTGSC_INTSTS_B_SESSION_END 0x00100000 | ||
260 | #define OTGSC_INTSTS_1MS 0x00200000 | ||
261 | #define OTGSC_INTSTS_DATA_PULSING 0x00400000 | ||
262 | #define OTGSC_INTR_USB_ID 0x01000000 | ||
263 | #define OTGSC_INTR_A_VBUS_VALID 0x02000000 | ||
264 | #define OTGSC_INTR_A_SESSION_VALID 0x04000000 | ||
265 | #define OTGSC_INTR_B_SESSION_VALID 0x08000000 | ||
266 | #define OTGSC_INTR_B_SESSION_END 0x10000000 | ||
267 | #define OTGSC_INTR_1MS_TIMER 0x20000000 | ||
268 | #define OTGSC_INTR_DATA_PULSING 0x40000000 | ||
269 | |||
270 | /* USB MODE Register Bit Masks */ | ||
271 | #define USB_MODE_CTRL_MODE_IDLE 0x00000000 | ||
272 | #define USB_MODE_CTRL_MODE_DEVICE 0x00000002 | ||
273 | #define USB_MODE_CTRL_MODE_HOST 0x00000003 | ||
274 | #define USB_MODE_CTRL_MODE_RSV 0x00000001 | ||
275 | #define USB_MODE_SETUP_LOCK_OFF 0x00000008 | ||
276 | #define USB_MODE_STREAM_DISABLE 0x00000010 | ||
277 | /* Endpoint Flush Register */ | ||
278 | #define EPFLUSH_TX_OFFSET 0x00010000 | ||
279 | #define EPFLUSH_RX_OFFSET 0x00000000 | ||
280 | |||
281 | /* Endpoint Setup Status bit masks */ | ||
282 | #define EP_SETUP_STATUS_MASK 0x0000003F | ||
283 | #define EP_SETUP_STATUS_EP0 0x00000001 | ||
284 | |||
285 | /* ENDPOINTCTRLx Register Bit Masks */ | ||
286 | #define EPCTRL_TX_ENABLE 0x00800000 | ||
287 | #define EPCTRL_TX_DATA_TOGGLE_RST 0x00400000 /* Not EP0 */ | ||
288 | #define EPCTRL_TX_DATA_TOGGLE_INH 0x00200000 /* Not EP0 */ | ||
289 | #define EPCTRL_TX_TYPE 0x000C0000 | ||
290 | #define EPCTRL_TX_DATA_SOURCE 0x00020000 /* Not EP0 */ | ||
291 | #define EPCTRL_TX_EP_STALL 0x00010000 | ||
292 | #define EPCTRL_RX_ENABLE 0x00000080 | ||
293 | #define EPCTRL_RX_DATA_TOGGLE_RST 0x00000040 /* Not EP0 */ | ||
294 | #define EPCTRL_RX_DATA_TOGGLE_INH 0x00000020 /* Not EP0 */ | ||
295 | #define EPCTRL_RX_TYPE 0x0000000C | ||
296 | #define EPCTRL_RX_DATA_SINK 0x00000002 /* Not EP0 */ | ||
297 | #define EPCTRL_RX_EP_STALL 0x00000001 | ||
298 | |||
299 | /* bit 19-18 and 3-2 are endpoint type */ | ||
300 | #define EPCTRL_EP_TYPE_CONTROL 0 | ||
301 | #define EPCTRL_EP_TYPE_ISO 1 | ||
302 | #define EPCTRL_EP_TYPE_BULK 2 | ||
303 | #define EPCTRL_EP_TYPE_INTERRUPT 3 | ||
304 | #define EPCTRL_TX_EP_TYPE_SHIFT 18 | ||
305 | #define EPCTRL_RX_EP_TYPE_SHIFT 2 | ||
306 | |||
307 | /* SNOOPn Register Bit Masks */ | ||
308 | #define SNOOP_ADDRESS_MASK 0xFFFFF000 | ||
309 | #define SNOOP_SIZE_ZERO 0x00 /* snooping disable */ | ||
310 | #define SNOOP_SIZE_4KB 0x0B /* 4KB snoop size */ | ||
311 | #define SNOOP_SIZE_8KB 0x0C | ||
312 | #define SNOOP_SIZE_16KB 0x0D | ||
313 | #define SNOOP_SIZE_32KB 0x0E | ||
314 | #define SNOOP_SIZE_64KB 0x0F | ||
315 | #define SNOOP_SIZE_128KB 0x10 | ||
316 | #define SNOOP_SIZE_256KB 0x11 | ||
317 | #define SNOOP_SIZE_512KB 0x12 | ||
318 | #define SNOOP_SIZE_1MB 0x13 | ||
319 | #define SNOOP_SIZE_2MB 0x14 | ||
320 | #define SNOOP_SIZE_4MB 0x15 | ||
321 | #define SNOOP_SIZE_8MB 0x16 | ||
322 | #define SNOOP_SIZE_16MB 0x17 | ||
323 | #define SNOOP_SIZE_32MB 0x18 | ||
324 | #define SNOOP_SIZE_64MB 0x19 | ||
325 | #define SNOOP_SIZE_128MB 0x1A | ||
326 | #define SNOOP_SIZE_256MB 0x1B | ||
327 | #define SNOOP_SIZE_512MB 0x1C | ||
328 | #define SNOOP_SIZE_1GB 0x1D | ||
329 | #define SNOOP_SIZE_2GB 0x1E /* 2GB snoop size */ | ||
330 | |||
331 | /* pri_ctrl Register Bit Masks */ | ||
332 | #define PRI_CTRL_PRI_LVL1 0x0000000C | ||
333 | #define PRI_CTRL_PRI_LVL0 0x00000003 | ||
334 | |||
335 | /* si_ctrl Register Bit Masks */ | ||
336 | #define SI_CTRL_ERR_DISABLE 0x00000010 | ||
337 | #define SI_CTRL_IDRC_DISABLE 0x00000008 | ||
338 | #define SI_CTRL_RD_SAFE_EN 0x00000004 | ||
339 | #define SI_CTRL_RD_PREFETCH_DISABLE 0x00000002 | ||
340 | #define SI_CTRL_RD_PREFEFETCH_VAL 0x00000001 | ||
341 | |||
342 | /* control Register Bit Masks */ | ||
343 | #define USB_CTRL_IOENB 0x00000004 | ||
344 | #define USB_CTRL_ULPI_INT0EN 0x00000001 | ||
345 | |||
346 | /* Endpoint Queue Head data struct | ||
347 | * Rem: all the variables of qh are LittleEndian Mode | ||
348 | * and NEXT_POINTER_MASK should operate on a LittleEndian, Phy Addr | ||
349 | */ | ||
350 | struct ep_queue_head { | ||
351 | u32 max_pkt_length; /* Mult(31-30) , Zlt(29) , Max Pkt len | ||
352 | and IOS(15) */ | ||
353 | u32 curr_dtd_ptr; /* Current dTD Pointer(31-5) */ | ||
354 | u32 next_dtd_ptr; /* Next dTD Pointer(31-5), T(0) */ | ||
355 | u32 size_ioc_int_sts; /* Total bytes (30-16), IOC (15), | ||
356 | MultO(11-10), STS (7-0) */ | ||
357 | u32 buff_ptr0; /* Buffer pointer Page 0 (31-12) */ | ||
358 | u32 buff_ptr1; /* Buffer pointer Page 1 (31-12) */ | ||
359 | u32 buff_ptr2; /* Buffer pointer Page 2 (31-12) */ | ||
360 | u32 buff_ptr3; /* Buffer pointer Page 3 (31-12) */ | ||
361 | u32 buff_ptr4; /* Buffer pointer Page 4 (31-12) */ | ||
362 | u32 res1; | ||
363 | u8 setup_buffer[8]; /* Setup data 8 bytes */ | ||
364 | u32 res2[4]; | ||
365 | }; | ||
366 | |||
367 | /* Endpoint Queue Head Bit Masks */ | ||
368 | #define EP_QUEUE_HEAD_MULT_POS 30 | ||
369 | #define EP_QUEUE_HEAD_ZLT_SEL 0x20000000 | ||
370 | #define EP_QUEUE_HEAD_MAX_PKT_LEN_POS 16 | ||
371 | #define EP_QUEUE_HEAD_MAX_PKT_LEN(ep_info) (((ep_info)>>16)&0x07ff) | ||
372 | #define EP_QUEUE_HEAD_IOS 0x00008000 | ||
373 | #define EP_QUEUE_HEAD_NEXT_TERMINATE 0x00000001 | ||
374 | #define EP_QUEUE_HEAD_IOC 0x00008000 | ||
375 | #define EP_QUEUE_HEAD_MULTO 0x00000C00 | ||
376 | #define EP_QUEUE_HEAD_STATUS_HALT 0x00000040 | ||
377 | #define EP_QUEUE_HEAD_STATUS_ACTIVE 0x00000080 | ||
378 | #define EP_QUEUE_CURRENT_OFFSET_MASK 0x00000FFF | ||
379 | #define EP_QUEUE_HEAD_NEXT_POINTER_MASK 0xFFFFFFE0 | ||
380 | #define EP_QUEUE_FRINDEX_MASK 0x000007FF | ||
381 | #define EP_MAX_LENGTH_TRANSFER 0x4000 | ||
382 | |||
383 | /* Endpoint Transfer Descriptor data struct */ | ||
384 | /* Rem: all the variables of td are LittleEndian Mode */ | ||
385 | struct ep_td_struct { | ||
386 | u32 next_td_ptr; /* Next TD pointer(31-5), T(0) set | ||
387 | indicate invalid */ | ||
388 | u32 size_ioc_sts; /* Total bytes (30-16), IOC (15), | ||
389 | MultO(11-10), STS (7-0) */ | ||
390 | u32 buff_ptr0; /* Buffer pointer Page 0 */ | ||
391 | u32 buff_ptr1; /* Buffer pointer Page 1 */ | ||
392 | u32 buff_ptr2; /* Buffer pointer Page 2 */ | ||
393 | u32 buff_ptr3; /* Buffer pointer Page 3 */ | ||
394 | u32 buff_ptr4; /* Buffer pointer Page 4 */ | ||
395 | u32 res; | ||
396 | /* 32 bytes */ | ||
397 | dma_addr_t td_dma; /* dma address for this td */ | ||
398 | /* virtual address of next td specified in next_td_ptr */ | ||
399 | struct ep_td_struct *next_td_virt; | ||
400 | }; | ||
401 | |||
402 | /* Endpoint Transfer Descriptor bit Masks */ | ||
403 | #define DTD_NEXT_TERMINATE 0x00000001 | ||
404 | #define DTD_IOC 0x00008000 | ||
405 | #define DTD_STATUS_ACTIVE 0x00000080 | ||
406 | #define DTD_STATUS_HALTED 0x00000040 | ||
407 | #define DTD_STATUS_DATA_BUFF_ERR 0x00000020 | ||
408 | #define DTD_STATUS_TRANSACTION_ERR 0x00000008 | ||
409 | #define DTD_RESERVED_FIELDS 0x80007300 | ||
410 | #define DTD_ADDR_MASK 0xFFFFFFE0 | ||
411 | #define DTD_PACKET_SIZE 0x7FFF0000 | ||
412 | #define DTD_LENGTH_BIT_POS 16 | ||
413 | #define DTD_ERROR_MASK (DTD_STATUS_HALTED | \ | ||
414 | DTD_STATUS_DATA_BUFF_ERR | \ | ||
415 | DTD_STATUS_TRANSACTION_ERR) | ||
416 | /* Alignment requirements; must be a power of two */ | ||
417 | #define DTD_ALIGNMENT 0x20 | ||
418 | #define QH_ALIGNMENT 2048 | ||
419 | |||
420 | /* Controller dma boundary */ | ||
421 | #define UDC_DMA_BOUNDARY 0x1000 | ||
422 | |||
423 | /* -----------------------------------------------------------------------*/ | ||
424 | /* ##### enum data | ||
425 | */ | ||
426 | typedef enum { | ||
427 | e_ULPI, | ||
428 | e_UTMI_8BIT, | ||
429 | e_UTMI_16BIT, | ||
430 | e_SERIAL | ||
431 | } e_PhyInterface; | ||
432 | |||
433 | /*-------------------------------------------------------------------------*/ | ||
434 | |||
435 | /* ### driver private data | ||
436 | */ | ||
437 | struct fsl_req { | ||
438 | struct usb_request req; | ||
439 | struct list_head queue; | ||
440 | /* ep_queue() func will add | ||
441 | a request->queue into a udc_ep->queue 'd tail */ | ||
442 | struct fsl_ep *ep; | ||
443 | unsigned mapped:1; | ||
444 | |||
445 | struct ep_td_struct *head, *tail; /* For dTD List | ||
446 | cpu endian Virtual addr */ | ||
447 | unsigned int dtd_count; | ||
448 | }; | ||
449 | |||
450 | #define REQ_UNCOMPLETE 1 | ||
451 | |||
452 | struct fsl_ep { | ||
453 | struct usb_ep ep; | ||
454 | struct list_head queue; | ||
455 | struct fsl_udc *udc; | ||
456 | struct ep_queue_head *qh; | ||
457 | const struct usb_endpoint_descriptor *desc; | ||
458 | struct usb_gadget *gadget; | ||
459 | |||
460 | char name[14]; | ||
461 | unsigned stopped:1; | ||
462 | }; | ||
463 | |||
464 | #define EP_DIR_IN 1 | ||
465 | #define EP_DIR_OUT 0 | ||
466 | |||
467 | struct fsl_udc { | ||
468 | |||
469 | struct usb_gadget gadget; | ||
470 | struct usb_gadget_driver *driver; | ||
471 | struct fsl_ep *eps; | ||
472 | unsigned int max_ep; | ||
473 | unsigned int irq; | ||
474 | |||
475 | struct usb_ctrlrequest local_setup_buff; | ||
476 | spinlock_t lock; | ||
477 | struct otg_transceiver *transceiver; | ||
478 | unsigned softconnect:1; | ||
479 | unsigned vbus_active:1; | ||
480 | unsigned stopped:1; | ||
481 | unsigned remote_wakeup:1; | ||
482 | |||
483 | struct ep_queue_head *ep_qh; /* Endpoints Queue-Head */ | ||
484 | struct fsl_req *status_req; /* ep0 status request */ | ||
485 | struct dma_pool *td_pool; /* dma pool for DTD */ | ||
486 | enum fsl_usb2_phy_modes phy_mode; | ||
487 | |||
488 | size_t ep_qh_size; /* size after alignment adjustment*/ | ||
489 | dma_addr_t ep_qh_dma; /* dma address of QH */ | ||
490 | |||
491 | u32 max_pipes; /* Device max pipes */ | ||
492 | u32 max_use_endpts; /* Max endpointes to be used */ | ||
493 | u32 bus_reset; /* Device is bus reseting */ | ||
494 | u32 resume_state; /* USB state to resume */ | ||
495 | u32 usb_state; /* USB current state */ | ||
496 | u32 usb_next_state; /* USB next state */ | ||
497 | u32 ep0_state; /* Endpoint zero state */ | ||
498 | u32 ep0_dir; /* Endpoint zero direction: can be | ||
499 | USB_DIR_IN or USB_DIR_OUT */ | ||
500 | u32 usb_sof_count; /* SOF count */ | ||
501 | u32 errors; /* USB ERRORs count */ | ||
502 | u8 device_address; /* Device USB address */ | ||
503 | |||
504 | struct completion *done; /* to make sure release() is done */ | ||
505 | }; | ||
506 | |||
507 | /*-------------------------------------------------------------------------*/ | ||
508 | |||
509 | #ifdef DEBUG | ||
510 | #define DBG(fmt, args...) printk(KERN_DEBUG "[%s] " fmt "\n", \ | ||
511 | __FUNCTION__, ## args) | ||
512 | #else | ||
513 | #define DBG(fmt, args...) do{}while(0) | ||
514 | #endif | ||
515 | |||
516 | #if 0 | ||
517 | static void dump_msg(const char *label, const u8 * buf, unsigned int length) | ||
518 | { | ||
519 | unsigned int start, num, i; | ||
520 | char line[52], *p; | ||
521 | |||
522 | if (length >= 512) | ||
523 | return; | ||
524 | DBG("%s, length %u:\n", label, length); | ||
525 | start = 0; | ||
526 | while (length > 0) { | ||
527 | num = min(length, 16u); | ||
528 | p = line; | ||
529 | for (i = 0; i < num; ++i) { | ||
530 | if (i == 8) | ||
531 | *p++ = ' '; | ||
532 | sprintf(p, " %02x", buf[i]); | ||
533 | p += 3; | ||
534 | } | ||
535 | *p = 0; | ||
536 | printk(KERN_DEBUG "%6x: %s\n", start, line); | ||
537 | buf += num; | ||
538 | start += num; | ||
539 | length -= num; | ||
540 | } | ||
541 | } | ||
542 | #endif | ||
543 | |||
544 | #ifdef VERBOSE | ||
545 | #define VDBG DBG | ||
546 | #else | ||
547 | #define VDBG(stuff...) do{}while(0) | ||
548 | #endif | ||
549 | |||
550 | #define ERR(stuff...) printk(KERN_ERR "udc: " stuff) | ||
551 | #define WARN(stuff...) printk(KERN_WARNING "udc: " stuff) | ||
552 | #define INFO(stuff...) printk(KERN_INFO "udc: " stuff) | ||
553 | |||
554 | /*-------------------------------------------------------------------------*/ | ||
555 | |||
556 | /* ### Add board specific defines here | ||
557 | */ | ||
558 | |||
559 | /* | ||
560 | * ### pipe direction macro from device view | ||
561 | */ | ||
562 | #define USB_RECV 0 /* OUT EP */ | ||
563 | #define USB_SEND 1 /* IN EP */ | ||
564 | |||
565 | /* | ||
566 | * ### internal used help routines. | ||
567 | */ | ||
568 | #define ep_index(EP) ((EP)->desc->bEndpointAddress&0xF) | ||
569 | #define ep_maxpacket(EP) ((EP)->ep.maxpacket) | ||
570 | #define ep_is_in(EP) ( (ep_index(EP) == 0) ? (EP->udc->ep0_dir == \ | ||
571 | USB_DIR_IN ):((EP)->desc->bEndpointAddress \ | ||
572 | & USB_DIR_IN)==USB_DIR_IN) | ||
573 | #define get_ep_by_pipe(udc, pipe) ((pipe == 1)? &udc->eps[0]: \ | ||
574 | &udc->eps[pipe]) | ||
575 | #define get_pipe_by_windex(windex) ((windex & USB_ENDPOINT_NUMBER_MASK) \ | ||
576 | * 2 + ((windex & USB_DIR_IN) ? 1 : 0)) | ||
577 | #define get_pipe_by_ep(EP) (ep_index(EP) * 2 + ep_is_in(EP)) | ||
578 | |||
579 | #endif | ||
diff --git a/drivers/usb/gadget/gadget_chips.h b/drivers/usb/gadget/gadget_chips.h index 2e3d6620d216..d041b919e7b8 100644 --- a/drivers/usb/gadget/gadget_chips.h +++ b/drivers/usb/gadget/gadget_chips.h | |||
@@ -99,6 +99,12 @@ | |||
99 | #define gadget_is_imx(g) 0 | 99 | #define gadget_is_imx(g) 0 |
100 | #endif | 100 | #endif |
101 | 101 | ||
102 | #ifdef CONFIG_USB_GADGET_FSL_USB2 | ||
103 | #define gadget_is_fsl_usb2(g) !strcmp("fsl-usb2-udc", (g)->name) | ||
104 | #else | ||
105 | #define gadget_is_fsl_usb2(g) 0 | ||
106 | #endif | ||
107 | |||
102 | /* Mentor high speed function controller */ | 108 | /* Mentor high speed function controller */ |
103 | #ifdef CONFIG_USB_GADGET_MUSBHSFC | 109 | #ifdef CONFIG_USB_GADGET_MUSBHSFC |
104 | #define gadget_is_musbhsfc(g) !strcmp("musbhsfc_udc", (g)->name) | 110 | #define gadget_is_musbhsfc(g) !strcmp("musbhsfc_udc", (g)->name) |
@@ -177,5 +183,7 @@ static inline int usb_gadget_controller_number(struct usb_gadget *gadget) | |||
177 | return 0x17; | 183 | return 0x17; |
178 | else if (gadget_is_husb2dev(gadget)) | 184 | else if (gadget_is_husb2dev(gadget)) |
179 | return 0x18; | 185 | return 0x18; |
186 | else if (gadget_is_fsl_usb2(gadget)) | ||
187 | return 0x19; | ||
180 | return -ENOENT; | 188 | return -ENOENT; |
181 | } | 189 | } |
diff --git a/drivers/usb/gadget/goku_udc.c b/drivers/usb/gadget/goku_udc.c index 7b3a326b57ab..65c91d3735de 100644 --- a/drivers/usb/gadget/goku_udc.c +++ b/drivers/usb/gadget/goku_udc.c | |||
@@ -297,27 +297,6 @@ goku_free_request(struct usb_ep *_ep, struct usb_request *_req) | |||
297 | 297 | ||
298 | /*-------------------------------------------------------------------------*/ | 298 | /*-------------------------------------------------------------------------*/ |
299 | 299 | ||
300 | #undef USE_KMALLOC | ||
301 | |||
302 | /* many common platforms have dma-coherent caches, which means that it's | ||
303 | * safe to use kmalloc() memory for all i/o buffers without using any | ||
304 | * cache flushing calls. (unless you're trying to share cache lines | ||
305 | * between dma and non-dma activities, which is a slow idea in any case.) | ||
306 | * | ||
307 | * other platforms need more care, with 2.6 having a moderately general | ||
308 | * solution except for the common "buffer is smaller than a page" case. | ||
309 | */ | ||
310 | #if defined(CONFIG_X86) | ||
311 | #define USE_KMALLOC | ||
312 | |||
313 | #elif defined(CONFIG_MIPS) && !defined(CONFIG_DMA_NONCOHERENT) | ||
314 | #define USE_KMALLOC | ||
315 | |||
316 | #elif defined(CONFIG_PPC) && !defined(CONFIG_NOT_COHERENT_CACHE) | ||
317 | #define USE_KMALLOC | ||
318 | |||
319 | #endif | ||
320 | |||
321 | /* allocating buffers this way eliminates dma mapping overhead, which | 300 | /* allocating buffers this way eliminates dma mapping overhead, which |
322 | * on some platforms will mean eliminating a per-io buffer copy. with | 301 | * on some platforms will mean eliminating a per-io buffer copy. with |
323 | * some kinds of system caches, further tweaks may still be needed. | 302 | * some kinds of system caches, further tweaks may still be needed. |
@@ -334,11 +313,6 @@ goku_alloc_buffer(struct usb_ep *_ep, unsigned bytes, | |||
334 | return NULL; | 313 | return NULL; |
335 | *dma = DMA_ADDR_INVALID; | 314 | *dma = DMA_ADDR_INVALID; |
336 | 315 | ||
337 | #if defined(USE_KMALLOC) | ||
338 | retval = kmalloc(bytes, gfp_flags); | ||
339 | if (retval) | ||
340 | *dma = virt_to_phys(retval); | ||
341 | #else | ||
342 | if (ep->dma) { | 316 | if (ep->dma) { |
343 | /* the main problem with this call is that it wastes memory | 317 | /* the main problem with this call is that it wastes memory |
344 | * on typical 1/N page allocations: it allocates 1-N pages. | 318 | * on typical 1/N page allocations: it allocates 1-N pages. |
@@ -348,7 +322,6 @@ goku_alloc_buffer(struct usb_ep *_ep, unsigned bytes, | |||
348 | bytes, dma, gfp_flags); | 322 | bytes, dma, gfp_flags); |
349 | } else | 323 | } else |
350 | retval = kmalloc(bytes, gfp_flags); | 324 | retval = kmalloc(bytes, gfp_flags); |
351 | #endif | ||
352 | return retval; | 325 | return retval; |
353 | } | 326 | } |
354 | 327 | ||
@@ -356,7 +329,6 @@ static void | |||
356 | goku_free_buffer(struct usb_ep *_ep, void *buf, dma_addr_t dma, unsigned bytes) | 329 | goku_free_buffer(struct usb_ep *_ep, void *buf, dma_addr_t dma, unsigned bytes) |
357 | { | 330 | { |
358 | /* free memory into the right allocator */ | 331 | /* free memory into the right allocator */ |
359 | #ifndef USE_KMALLOC | ||
360 | if (dma != DMA_ADDR_INVALID) { | 332 | if (dma != DMA_ADDR_INVALID) { |
361 | struct goku_ep *ep; | 333 | struct goku_ep *ep; |
362 | 334 | ||
@@ -365,7 +337,6 @@ goku_free_buffer(struct usb_ep *_ep, void *buf, dma_addr_t dma, unsigned bytes) | |||
365 | return; | 337 | return; |
366 | dma_free_coherent(&ep->dev->pdev->dev, bytes, buf, dma); | 338 | dma_free_coherent(&ep->dev->pdev->dev, bytes, buf, dma); |
367 | } else | 339 | } else |
368 | #endif | ||
369 | kfree (buf); | 340 | kfree (buf); |
370 | } | 341 | } |
371 | 342 | ||
diff --git a/drivers/usb/gadget/inode.c b/drivers/usb/gadget/inode.c index 34296e79edcf..188c74a95216 100644 --- a/drivers/usb/gadget/inode.c +++ b/drivers/usb/gadget/inode.c | |||
@@ -553,6 +553,7 @@ static ssize_t ep_aio_read_retry(struct kiocb *iocb) | |||
553 | { | 553 | { |
554 | struct kiocb_priv *priv = iocb->private; | 554 | struct kiocb_priv *priv = iocb->private; |
555 | ssize_t len, total; | 555 | ssize_t len, total; |
556 | void *to_copy; | ||
556 | int i; | 557 | int i; |
557 | 558 | ||
558 | /* we "retry" to get the right mm context for this: */ | 559 | /* we "retry" to get the right mm context for this: */ |
@@ -560,10 +561,11 @@ static ssize_t ep_aio_read_retry(struct kiocb *iocb) | |||
560 | /* copy stuff into user buffers */ | 561 | /* copy stuff into user buffers */ |
561 | total = priv->actual; | 562 | total = priv->actual; |
562 | len = 0; | 563 | len = 0; |
564 | to_copy = priv->buf; | ||
563 | for (i=0; i < priv->nr_segs; i++) { | 565 | for (i=0; i < priv->nr_segs; i++) { |
564 | ssize_t this = min((ssize_t)(priv->iv[i].iov_len), total); | 566 | ssize_t this = min((ssize_t)(priv->iv[i].iov_len), total); |
565 | 567 | ||
566 | if (copy_to_user(priv->iv[i].iov_base, priv->buf, this)) { | 568 | if (copy_to_user(priv->iv[i].iov_base, to_copy, this)) { |
567 | if (len == 0) | 569 | if (len == 0) |
568 | len = -EFAULT; | 570 | len = -EFAULT; |
569 | break; | 571 | break; |
@@ -571,6 +573,7 @@ static ssize_t ep_aio_read_retry(struct kiocb *iocb) | |||
571 | 573 | ||
572 | total -= this; | 574 | total -= this; |
573 | len += this; | 575 | len += this; |
576 | to_copy += this; | ||
574 | if (total == 0) | 577 | if (total == 0) |
575 | break; | 578 | break; |
576 | } | 579 | } |
diff --git a/drivers/usb/gadget/omap_udc.c b/drivers/usb/gadget/omap_udc.c index 8f9a2b615422..b394e63894d2 100644 --- a/drivers/usb/gadget/omap_udc.c +++ b/drivers/usb/gadget/omap_udc.c | |||
@@ -296,6 +296,15 @@ omap_free_request(struct usb_ep *ep, struct usb_request *_req) | |||
296 | 296 | ||
297 | /*-------------------------------------------------------------------------*/ | 297 | /*-------------------------------------------------------------------------*/ |
298 | 298 | ||
299 | /* | ||
300 | * dma-coherent memory allocation (for dma-capable endpoints) | ||
301 | * | ||
302 | * NOTE: the dma_*_coherent() API calls suck. Most implementations are | ||
303 | * (a) page-oriented, so small buffers lose big; and (b) asymmetric with | ||
304 | * respect to calls with irqs disabled: alloc is safe, free is not. | ||
305 | * We currently work around (b), but not (a). | ||
306 | */ | ||
307 | |||
299 | static void * | 308 | static void * |
300 | omap_alloc_buffer( | 309 | omap_alloc_buffer( |
301 | struct usb_ep *_ep, | 310 | struct usb_ep *_ep, |
@@ -307,6 +316,9 @@ omap_alloc_buffer( | |||
307 | void *retval; | 316 | void *retval; |
308 | struct omap_ep *ep; | 317 | struct omap_ep *ep; |
309 | 318 | ||
319 | if (!_ep) | ||
320 | return NULL; | ||
321 | |||
310 | ep = container_of(_ep, struct omap_ep, ep); | 322 | ep = container_of(_ep, struct omap_ep, ep); |
311 | if (use_dma && ep->has_dma) { | 323 | if (use_dma && ep->has_dma) { |
312 | static int warned; | 324 | static int warned; |
@@ -326,6 +338,35 @@ omap_alloc_buffer( | |||
326 | return retval; | 338 | return retval; |
327 | } | 339 | } |
328 | 340 | ||
341 | static DEFINE_SPINLOCK(buflock); | ||
342 | static LIST_HEAD(buffers); | ||
343 | |||
344 | struct free_record { | ||
345 | struct list_head list; | ||
346 | struct device *dev; | ||
347 | unsigned bytes; | ||
348 | dma_addr_t dma; | ||
349 | }; | ||
350 | |||
351 | static void do_free(unsigned long ignored) | ||
352 | { | ||
353 | spin_lock_irq(&buflock); | ||
354 | while (!list_empty(&buffers)) { | ||
355 | struct free_record *buf; | ||
356 | |||
357 | buf = list_entry(buffers.next, struct free_record, list); | ||
358 | list_del(&buf->list); | ||
359 | spin_unlock_irq(&buflock); | ||
360 | |||
361 | dma_free_coherent(buf->dev, buf->bytes, buf, buf->dma); | ||
362 | |||
363 | spin_lock_irq(&buflock); | ||
364 | } | ||
365 | spin_unlock_irq(&buflock); | ||
366 | } | ||
367 | |||
368 | static DECLARE_TASKLET(deferred_free, do_free, 0); | ||
369 | |||
329 | static void omap_free_buffer( | 370 | static void omap_free_buffer( |
330 | struct usb_ep *_ep, | 371 | struct usb_ep *_ep, |
331 | void *buf, | 372 | void *buf, |
@@ -333,13 +374,29 @@ static void omap_free_buffer( | |||
333 | unsigned bytes | 374 | unsigned bytes |
334 | ) | 375 | ) |
335 | { | 376 | { |
336 | struct omap_ep *ep; | 377 | if (!_ep) { |
378 | WARN_ON(1); | ||
379 | return; | ||
380 | } | ||
337 | 381 | ||
338 | ep = container_of(_ep, struct omap_ep, ep); | 382 | /* free memory into the right allocator */ |
339 | if (use_dma && _ep && ep->has_dma) | 383 | if (dma != DMA_ADDR_INVALID) { |
340 | dma_free_coherent(ep->udc->gadget.dev.parent, bytes, buf, dma); | 384 | struct omap_ep *ep; |
341 | else | 385 | struct free_record *rec = buf; |
342 | kfree (buf); | 386 | unsigned long flags; |
387 | |||
388 | ep = container_of(_ep, struct omap_ep, ep); | ||
389 | |||
390 | rec->dev = ep->udc->gadget.dev.parent; | ||
391 | rec->bytes = bytes; | ||
392 | rec->dma = dma; | ||
393 | |||
394 | spin_lock_irqsave(&buflock, flags); | ||
395 | list_add_tail(&rec->list, &buffers); | ||
396 | tasklet_schedule(&deferred_free); | ||
397 | spin_unlock_irqrestore(&buflock, flags); | ||
398 | } else | ||
399 | kfree(buf); | ||
343 | } | 400 | } |
344 | 401 | ||
345 | /*-------------------------------------------------------------------------*/ | 402 | /*-------------------------------------------------------------------------*/ |
@@ -1691,12 +1748,38 @@ ep0out_status_stage: | |||
1691 | udc->ep0_pending = 0; | 1748 | udc->ep0_pending = 0; |
1692 | break; | 1749 | break; |
1693 | case USB_REQ_GET_STATUS: | 1750 | case USB_REQ_GET_STATUS: |
1751 | /* USB_ENDPOINT_HALT status? */ | ||
1752 | if (u.r.bRequestType != (USB_DIR_IN|USB_RECIP_ENDPOINT)) | ||
1753 | goto intf_status; | ||
1754 | |||
1755 | /* ep0 never stalls */ | ||
1756 | if (!(w_index & 0xf)) | ||
1757 | goto zero_status; | ||
1758 | |||
1759 | /* only active endpoints count */ | ||
1760 | ep = &udc->ep[w_index & 0xf]; | ||
1761 | if (w_index & USB_DIR_IN) | ||
1762 | ep += 16; | ||
1763 | if (!ep->desc) | ||
1764 | goto do_stall; | ||
1765 | |||
1766 | /* iso never stalls */ | ||
1767 | if (ep->bmAttributes == USB_ENDPOINT_XFER_ISOC) | ||
1768 | goto zero_status; | ||
1769 | |||
1770 | /* FIXME don't assume non-halted endpoints!! */ | ||
1771 | ERR("%s status, can't report\n", ep->ep.name); | ||
1772 | goto do_stall; | ||
1773 | |||
1774 | intf_status: | ||
1694 | /* return interface status. if we were pedantic, | 1775 | /* return interface status. if we were pedantic, |
1695 | * we'd detect non-existent interfaces, and stall. | 1776 | * we'd detect non-existent interfaces, and stall. |
1696 | */ | 1777 | */ |
1697 | if (u.r.bRequestType | 1778 | if (u.r.bRequestType |
1698 | != (USB_DIR_IN|USB_RECIP_INTERFACE)) | 1779 | != (USB_DIR_IN|USB_RECIP_INTERFACE)) |
1699 | goto delegate; | 1780 | goto delegate; |
1781 | |||
1782 | zero_status: | ||
1700 | /* return two zero bytes */ | 1783 | /* return two zero bytes */ |
1701 | UDC_EP_NUM_REG = UDC_EP_SEL|UDC_EP_DIR; | 1784 | UDC_EP_NUM_REG = UDC_EP_SEL|UDC_EP_DIR; |
1702 | UDC_DATA_REG = 0; | 1785 | UDC_DATA_REG = 0; |
@@ -2068,7 +2151,7 @@ static irqreturn_t omap_udc_iso_irq(int irq, void *_dev) | |||
2068 | 2151 | ||
2069 | /*-------------------------------------------------------------------------*/ | 2152 | /*-------------------------------------------------------------------------*/ |
2070 | 2153 | ||
2071 | static inline int machine_needs_vbus_session(void) | 2154 | static inline int machine_without_vbus_sense(void) |
2072 | { | 2155 | { |
2073 | return (machine_is_omap_innovator() | 2156 | return (machine_is_omap_innovator() |
2074 | || machine_is_omap_osk() | 2157 | || machine_is_omap_osk() |
@@ -2156,7 +2239,7 @@ int usb_gadget_register_driver (struct usb_gadget_driver *driver) | |||
2156 | /* boards that don't have VBUS sensing can't autogate 48MHz; | 2239 | /* boards that don't have VBUS sensing can't autogate 48MHz; |
2157 | * can't enter deep sleep while a gadget driver is active. | 2240 | * can't enter deep sleep while a gadget driver is active. |
2158 | */ | 2241 | */ |
2159 | if (machine_needs_vbus_session()) | 2242 | if (machine_without_vbus_sense()) |
2160 | omap_vbus_session(&udc->gadget, 1); | 2243 | omap_vbus_session(&udc->gadget, 1); |
2161 | 2244 | ||
2162 | done: | 2245 | done: |
@@ -2179,7 +2262,7 @@ int usb_gadget_unregister_driver (struct usb_gadget_driver *driver) | |||
2179 | if (udc->dc_clk != NULL) | 2262 | if (udc->dc_clk != NULL) |
2180 | omap_udc_enable_clock(1); | 2263 | omap_udc_enable_clock(1); |
2181 | 2264 | ||
2182 | if (machine_needs_vbus_session()) | 2265 | if (machine_without_vbus_sense()) |
2183 | omap_vbus_session(&udc->gadget, 0); | 2266 | omap_vbus_session(&udc->gadget, 0); |
2184 | 2267 | ||
2185 | if (udc->transceiver) | 2268 | if (udc->transceiver) |
@@ -2822,7 +2905,7 @@ static int __init omap_udc_probe(struct platform_device *pdev) | |||
2822 | hmc = HMC_1510; | 2905 | hmc = HMC_1510; |
2823 | type = "(unknown)"; | 2906 | type = "(unknown)"; |
2824 | 2907 | ||
2825 | if (machine_is_omap_innovator() || machine_is_sx1()) { | 2908 | if (machine_without_vbus_sense()) { |
2826 | /* just set up software VBUS detect, and then | 2909 | /* just set up software VBUS detect, and then |
2827 | * later rig it so we always report VBUS. | 2910 | * later rig it so we always report VBUS. |
2828 | * FIXME without really sensing VBUS, we can't | 2911 | * FIXME without really sensing VBUS, we can't |
diff --git a/drivers/usb/gadget/pxa2xx_udc.c b/drivers/usb/gadget/pxa2xx_udc.c index 27904a56494b..2c043a1ea156 100644 --- a/drivers/usb/gadget/pxa2xx_udc.c +++ b/drivers/usb/gadget/pxa2xx_udc.c | |||
@@ -71,7 +71,7 @@ | |||
71 | * by the host to interact with this device, and allocates endpoints to | 71 | * by the host to interact with this device, and allocates endpoints to |
72 | * the different protocol interfaces. The controller driver virtualizes | 72 | * the different protocol interfaces. The controller driver virtualizes |
73 | * usb hardware so that the gadget drivers will be more portable. | 73 | * usb hardware so that the gadget drivers will be more portable. |
74 | * | 74 | * |
75 | * This UDC hardware wants to implement a bit too much USB protocol, so | 75 | * This UDC hardware wants to implement a bit too much USB protocol, so |
76 | * it constrains the sorts of USB configuration change events that work. | 76 | * it constrains the sorts of USB configuration change events that work. |
77 | * The errata for these chips are misleading; some "fixed" bugs from | 77 | * The errata for these chips are misleading; some "fixed" bugs from |
@@ -141,7 +141,7 @@ MODULE_PARM_DESC (fifo_mode, "pxa2xx udc fifo mode"); | |||
141 | #endif | 141 | #endif |
142 | 142 | ||
143 | /* --------------------------------------------------------------------------- | 143 | /* --------------------------------------------------------------------------- |
144 | * endpoint related parts of the api to the usb controller hardware, | 144 | * endpoint related parts of the api to the usb controller hardware, |
145 | * used by gadget driver; and the inner talker-to-hardware core. | 145 | * used by gadget driver; and the inner talker-to-hardware core. |
146 | * --------------------------------------------------------------------------- | 146 | * --------------------------------------------------------------------------- |
147 | */ | 147 | */ |
@@ -155,7 +155,7 @@ static int is_vbus_present(void) | |||
155 | struct pxa2xx_udc_mach_info *mach = the_controller->mach; | 155 | struct pxa2xx_udc_mach_info *mach = the_controller->mach; |
156 | 156 | ||
157 | if (mach->gpio_vbus) | 157 | if (mach->gpio_vbus) |
158 | return pxa_gpio_get(mach->gpio_vbus); | 158 | return udc_gpio_get(mach->gpio_vbus); |
159 | if (mach->udc_is_connected) | 159 | if (mach->udc_is_connected) |
160 | return mach->udc_is_connected(); | 160 | return mach->udc_is_connected(); |
161 | return 1; | 161 | return 1; |
@@ -167,7 +167,7 @@ static void pullup_off(void) | |||
167 | struct pxa2xx_udc_mach_info *mach = the_controller->mach; | 167 | struct pxa2xx_udc_mach_info *mach = the_controller->mach; |
168 | 168 | ||
169 | if (mach->gpio_pullup) | 169 | if (mach->gpio_pullup) |
170 | pxa_gpio_set(mach->gpio_pullup, 0); | 170 | udc_gpio_set(mach->gpio_pullup, 0); |
171 | else if (mach->udc_command) | 171 | else if (mach->udc_command) |
172 | mach->udc_command(PXA2XX_UDC_CMD_DISCONNECT); | 172 | mach->udc_command(PXA2XX_UDC_CMD_DISCONNECT); |
173 | } | 173 | } |
@@ -177,7 +177,7 @@ static void pullup_on(void) | |||
177 | struct pxa2xx_udc_mach_info *mach = the_controller->mach; | 177 | struct pxa2xx_udc_mach_info *mach = the_controller->mach; |
178 | 178 | ||
179 | if (mach->gpio_pullup) | 179 | if (mach->gpio_pullup) |
180 | pxa_gpio_set(mach->gpio_pullup, 1); | 180 | udc_gpio_set(mach->gpio_pullup, 1); |
181 | else if (mach->udc_command) | 181 | else if (mach->udc_command) |
182 | mach->udc_command(PXA2XX_UDC_CMD_CONNECT); | 182 | mach->udc_command(PXA2XX_UDC_CMD_CONNECT); |
183 | } | 183 | } |
@@ -293,7 +293,7 @@ static int pxa2xx_ep_enable (struct usb_ep *_ep, | |||
293 | 293 | ||
294 | #ifdef USE_DMA | 294 | #ifdef USE_DMA |
295 | /* for (some) bulk and ISO endpoints, try to get a DMA channel and | 295 | /* for (some) bulk and ISO endpoints, try to get a DMA channel and |
296 | * bind it to the endpoint. otherwise use PIO. | 296 | * bind it to the endpoint. otherwise use PIO. |
297 | */ | 297 | */ |
298 | switch (ep->bmAttributes) { | 298 | switch (ep->bmAttributes) { |
299 | case USB_ENDPOINT_XFER_ISOC: | 299 | case USB_ENDPOINT_XFER_ISOC: |
@@ -304,7 +304,7 @@ static int pxa2xx_ep_enable (struct usb_ep *_ep, | |||
304 | if (!use_dma || !ep->reg_drcmr) | 304 | if (!use_dma || !ep->reg_drcmr) |
305 | break; | 305 | break; |
306 | ep->dma = pxa_request_dma ((char *)_ep->name, | 306 | ep->dma = pxa_request_dma ((char *)_ep->name, |
307 | (le16_to_cpu (desc->wMaxPacketSize) > 64) | 307 | (le16_to_cpu (desc->wMaxPacketSize) > 64) |
308 | ? DMA_PRIO_MEDIUM /* some iso */ | 308 | ? DMA_PRIO_MEDIUM /* some iso */ |
309 | : DMA_PRIO_LOW, | 309 | : DMA_PRIO_LOW, |
310 | dma_nodesc_handler, ep); | 310 | dma_nodesc_handler, ep); |
@@ -361,7 +361,7 @@ static int pxa2xx_ep_disable (struct usb_ep *_ep) | |||
361 | */ | 361 | */ |
362 | 362 | ||
363 | /* | 363 | /* |
364 | * pxa2xx_ep_alloc_request - allocate a request data structure | 364 | * pxa2xx_ep_alloc_request - allocate a request data structure |
365 | */ | 365 | */ |
366 | static struct usb_request * | 366 | static struct usb_request * |
367 | pxa2xx_ep_alloc_request (struct usb_ep *_ep, gfp_t gfp_flags) | 367 | pxa2xx_ep_alloc_request (struct usb_ep *_ep, gfp_t gfp_flags) |
@@ -378,7 +378,7 @@ pxa2xx_ep_alloc_request (struct usb_ep *_ep, gfp_t gfp_flags) | |||
378 | 378 | ||
379 | 379 | ||
380 | /* | 380 | /* |
381 | * pxa2xx_ep_free_request - deallocate a request data structure | 381 | * pxa2xx_ep_free_request - deallocate a request data structure |
382 | */ | 382 | */ |
383 | static void | 383 | static void |
384 | pxa2xx_ep_free_request (struct usb_ep *_ep, struct usb_request *_req) | 384 | pxa2xx_ep_free_request (struct usb_ep *_ep, struct usb_request *_req) |
@@ -1031,7 +1031,7 @@ pxa2xx_ep_queue(struct usb_ep *_ep, struct usb_request *_req, gfp_t gfp_flags) | |||
1031 | 1031 | ||
1032 | 1032 | ||
1033 | /* | 1033 | /* |
1034 | * nuke - dequeue ALL requests | 1034 | * nuke - dequeue ALL requests |
1035 | */ | 1035 | */ |
1036 | static void nuke(struct pxa2xx_ep *ep, int status) | 1036 | static void nuke(struct pxa2xx_ep *ep, int status) |
1037 | { | 1037 | { |
@@ -1136,16 +1136,16 @@ static int pxa2xx_ep_set_halt(struct usb_ep *_ep, int value) | |||
1136 | ep->dev->req_pending = 0; | 1136 | ep->dev->req_pending = 0; |
1137 | ep->dev->ep0state = EP0_STALL; | 1137 | ep->dev->ep0state = EP0_STALL; |
1138 | 1138 | ||
1139 | /* and bulk/intr endpoints like dropping stalls too */ | 1139 | /* and bulk/intr endpoints like dropping stalls too */ |
1140 | } else { | 1140 | } else { |
1141 | unsigned i; | 1141 | unsigned i; |
1142 | for (i = 0; i < 1000; i += 20) { | 1142 | for (i = 0; i < 1000; i += 20) { |
1143 | if (*ep->reg_udccs & UDCCS_BI_SST) | 1143 | if (*ep->reg_udccs & UDCCS_BI_SST) |
1144 | break; | 1144 | break; |
1145 | udelay(20); | 1145 | udelay(20); |
1146 | } | 1146 | } |
1147 | } | 1147 | } |
1148 | local_irq_restore(flags); | 1148 | local_irq_restore(flags); |
1149 | 1149 | ||
1150 | DBG(DBG_VERBOSE, "%s halt\n", _ep->name); | 1150 | DBG(DBG_VERBOSE, "%s halt\n", _ep->name); |
1151 | return 0; | 1151 | return 0; |
@@ -1216,7 +1216,7 @@ static struct usb_ep_ops pxa2xx_ep_ops = { | |||
1216 | 1216 | ||
1217 | 1217 | ||
1218 | /* --------------------------------------------------------------------------- | 1218 | /* --------------------------------------------------------------------------- |
1219 | * device-scoped parts of the api to the usb controller hardware | 1219 | * device-scoped parts of the api to the usb controller hardware |
1220 | * --------------------------------------------------------------------------- | 1220 | * --------------------------------------------------------------------------- |
1221 | */ | 1221 | */ |
1222 | 1222 | ||
@@ -1239,7 +1239,7 @@ static void udc_enable (struct pxa2xx_udc *); | |||
1239 | static void udc_disable(struct pxa2xx_udc *); | 1239 | static void udc_disable(struct pxa2xx_udc *); |
1240 | 1240 | ||
1241 | /* We disable the UDC -- and its 48 MHz clock -- whenever it's not | 1241 | /* We disable the UDC -- and its 48 MHz clock -- whenever it's not |
1242 | * in active use. | 1242 | * in active use. |
1243 | */ | 1243 | */ |
1244 | static int pullup(struct pxa2xx_udc *udc, int is_active) | 1244 | static int pullup(struct pxa2xx_udc *udc, int is_active) |
1245 | { | 1245 | { |
@@ -1464,24 +1464,10 @@ done: | |||
1464 | 1464 | ||
1465 | #endif /* CONFIG_USB_GADGET_DEBUG_FILES */ | 1465 | #endif /* CONFIG_USB_GADGET_DEBUG_FILES */ |
1466 | 1466 | ||
1467 | /* "function" sysfs attribute */ | ||
1468 | static ssize_t | ||
1469 | show_function (struct device *_dev, struct device_attribute *attr, char *buf) | ||
1470 | { | ||
1471 | struct pxa2xx_udc *dev = dev_get_drvdata (_dev); | ||
1472 | |||
1473 | if (!dev->driver | ||
1474 | || !dev->driver->function | ||
1475 | || strlen (dev->driver->function) > PAGE_SIZE) | ||
1476 | return 0; | ||
1477 | return scnprintf (buf, PAGE_SIZE, "%s\n", dev->driver->function); | ||
1478 | } | ||
1479 | static DEVICE_ATTR (function, S_IRUGO, show_function, NULL); | ||
1480 | |||
1481 | /*-------------------------------------------------------------------------*/ | 1467 | /*-------------------------------------------------------------------------*/ |
1482 | 1468 | ||
1483 | /* | 1469 | /* |
1484 | * udc_disable - disable USB device controller | 1470 | * udc_disable - disable USB device controller |
1485 | */ | 1471 | */ |
1486 | static void udc_disable(struct pxa2xx_udc *dev) | 1472 | static void udc_disable(struct pxa2xx_udc *dev) |
1487 | { | 1473 | { |
@@ -1507,7 +1493,7 @@ static void udc_disable(struct pxa2xx_udc *dev) | |||
1507 | 1493 | ||
1508 | 1494 | ||
1509 | /* | 1495 | /* |
1510 | * udc_reinit - initialize software state | 1496 | * udc_reinit - initialize software state |
1511 | */ | 1497 | */ |
1512 | static void udc_reinit(struct pxa2xx_udc *dev) | 1498 | static void udc_reinit(struct pxa2xx_udc *dev) |
1513 | { | 1499 | { |
@@ -1635,18 +1621,20 @@ int usb_gadget_register_driver(struct usb_gadget_driver *driver) | |||
1635 | dev->gadget.dev.driver = &driver->driver; | 1621 | dev->gadget.dev.driver = &driver->driver; |
1636 | dev->pullup = 1; | 1622 | dev->pullup = 1; |
1637 | 1623 | ||
1638 | device_add (&dev->gadget.dev); | 1624 | retval = device_add (&dev->gadget.dev); |
1625 | if (retval) { | ||
1626 | fail: | ||
1627 | dev->driver = NULL; | ||
1628 | dev->gadget.dev.driver = NULL; | ||
1629 | return retval; | ||
1630 | } | ||
1639 | retval = driver->bind(&dev->gadget); | 1631 | retval = driver->bind(&dev->gadget); |
1640 | if (retval) { | 1632 | if (retval) { |
1641 | DMSG("bind to driver %s --> error %d\n", | 1633 | DMSG("bind to driver %s --> error %d\n", |
1642 | driver->driver.name, retval); | 1634 | driver->driver.name, retval); |
1643 | device_del (&dev->gadget.dev); | 1635 | device_del (&dev->gadget.dev); |
1644 | 1636 | goto fail; | |
1645 | dev->driver = NULL; | ||
1646 | dev->gadget.dev.driver = NULL; | ||
1647 | return retval; | ||
1648 | } | 1637 | } |
1649 | device_create_file(dev->dev, &dev_attr_function); | ||
1650 | 1638 | ||
1651 | /* ... then enable host detection and ep0; and we're ready | 1639 | /* ... then enable host detection and ep0; and we're ready |
1652 | * for set_configuration as well as eventual disconnect. | 1640 | * for set_configuration as well as eventual disconnect. |
@@ -1704,7 +1692,6 @@ int usb_gadget_unregister_driver(struct usb_gadget_driver *driver) | |||
1704 | dev->driver = NULL; | 1692 | dev->driver = NULL; |
1705 | 1693 | ||
1706 | device_del (&dev->gadget.dev); | 1694 | device_del (&dev->gadget.dev); |
1707 | device_remove_file(dev->dev, &dev_attr_function); | ||
1708 | 1695 | ||
1709 | DMSG("unregistered gadget driver '%s'\n", driver->driver.name); | 1696 | DMSG("unregistered gadget driver '%s'\n", driver->driver.name); |
1710 | dump_state(dev); | 1697 | dump_state(dev); |
@@ -1755,7 +1742,7 @@ lubbock_vbus_irq(int irq, void *_dev) | |||
1755 | static irqreturn_t udc_vbus_irq(int irq, void *_dev) | 1742 | static irqreturn_t udc_vbus_irq(int irq, void *_dev) |
1756 | { | 1743 | { |
1757 | struct pxa2xx_udc *dev = _dev; | 1744 | struct pxa2xx_udc *dev = _dev; |
1758 | int vbus = pxa_gpio_get(dev->mach->gpio_vbus); | 1745 | int vbus = udc_gpio_get(dev->mach->gpio_vbus); |
1759 | 1746 | ||
1760 | pxa2xx_udc_vbus_session(&dev->gadget, vbus); | 1747 | pxa2xx_udc_vbus_session(&dev->gadget, vbus); |
1761 | return IRQ_HANDLED; | 1748 | return IRQ_HANDLED; |
@@ -2474,12 +2461,12 @@ static struct pxa2xx_udc memory = { | |||
2474 | #define IXP465_AD 0x00000200 | 2461 | #define IXP465_AD 0x00000200 |
2475 | 2462 | ||
2476 | /* | 2463 | /* |
2477 | * probe - binds to the platform device | 2464 | * probe - binds to the platform device |
2478 | */ | 2465 | */ |
2479 | static int __init pxa2xx_udc_probe(struct platform_device *pdev) | 2466 | static int __init pxa2xx_udc_probe(struct platform_device *pdev) |
2480 | { | 2467 | { |
2481 | struct pxa2xx_udc *dev = &memory; | 2468 | struct pxa2xx_udc *dev = &memory; |
2482 | int retval, out_dma = 1, vbus_irq; | 2469 | int retval, out_dma = 1, vbus_irq, irq; |
2483 | u32 chiprev; | 2470 | u32 chiprev; |
2484 | 2471 | ||
2485 | /* insist on Intel/ARM/XScale */ | 2472 | /* insist on Intel/ARM/XScale */ |
@@ -2522,7 +2509,11 @@ static int __init pxa2xx_udc_probe(struct platform_device *pdev) | |||
2522 | return -ENODEV; | 2509 | return -ENODEV; |
2523 | } | 2510 | } |
2524 | 2511 | ||
2525 | pr_debug("%s: IRQ %d%s%s%s\n", driver_name, IRQ_USB, | 2512 | irq = platform_get_irq(pdev, 0); |
2513 | if (irq < 0) | ||
2514 | return -ENODEV; | ||
2515 | |||
2516 | pr_debug("%s: IRQ %d%s%s%s\n", driver_name, irq, | ||
2526 | dev->has_cfr ? "" : " (!cfr)", | 2517 | dev->has_cfr ? "" : " (!cfr)", |
2527 | out_dma ? "" : " (broken dma-out)", | 2518 | out_dma ? "" : " (broken dma-out)", |
2528 | SIZE_STR DMASTR | 2519 | SIZE_STR DMASTR |
@@ -2545,15 +2536,13 @@ static int __init pxa2xx_udc_probe(struct platform_device *pdev) | |||
2545 | dev->dev = &pdev->dev; | 2536 | dev->dev = &pdev->dev; |
2546 | dev->mach = pdev->dev.platform_data; | 2537 | dev->mach = pdev->dev.platform_data; |
2547 | if (dev->mach->gpio_vbus) { | 2538 | if (dev->mach->gpio_vbus) { |
2548 | vbus_irq = IRQ_GPIO(dev->mach->gpio_vbus & GPIO_MD_MASK_NR); | 2539 | udc_gpio_init_vbus(dev->mach->gpio_vbus); |
2549 | pxa_gpio_mode((dev->mach->gpio_vbus & GPIO_MD_MASK_NR) | 2540 | vbus_irq = udc_gpio_to_irq(dev->mach->gpio_vbus); |
2550 | | GPIO_IN); | ||
2551 | set_irq_type(vbus_irq, IRQT_BOTHEDGE); | 2541 | set_irq_type(vbus_irq, IRQT_BOTHEDGE); |
2552 | } else | 2542 | } else |
2553 | vbus_irq = 0; | 2543 | vbus_irq = 0; |
2554 | if (dev->mach->gpio_pullup) | 2544 | if (dev->mach->gpio_pullup) |
2555 | pxa_gpio_mode((dev->mach->gpio_pullup & GPIO_MD_MASK_NR) | 2545 | udc_gpio_init_pullup(dev->mach->gpio_pullup); |
2556 | | GPIO_OUT | GPIO_DFLT_LOW); | ||
2557 | 2546 | ||
2558 | init_timer(&dev->timer); | 2547 | init_timer(&dev->timer); |
2559 | dev->timer.function = udc_watchdog; | 2548 | dev->timer.function = udc_watchdog; |
@@ -2572,11 +2561,11 @@ static int __init pxa2xx_udc_probe(struct platform_device *pdev) | |||
2572 | dev->vbus = is_vbus_present(); | 2561 | dev->vbus = is_vbus_present(); |
2573 | 2562 | ||
2574 | /* irq setup after old hardware state is cleaned up */ | 2563 | /* irq setup after old hardware state is cleaned up */ |
2575 | retval = request_irq(IRQ_USB, pxa2xx_udc_irq, | 2564 | retval = request_irq(irq, pxa2xx_udc_irq, |
2576 | IRQF_DISABLED, driver_name, dev); | 2565 | IRQF_DISABLED, driver_name, dev); |
2577 | if (retval != 0) { | 2566 | if (retval != 0) { |
2578 | printk(KERN_ERR "%s: can't get irq %i, err %d\n", | 2567 | printk(KERN_ERR "%s: can't get irq %d, err %d\n", |
2579 | driver_name, IRQ_USB, retval); | 2568 | driver_name, irq, retval); |
2580 | return -EBUSY; | 2569 | return -EBUSY; |
2581 | } | 2570 | } |
2582 | dev->got_irq = 1; | 2571 | dev->got_irq = 1; |
@@ -2591,7 +2580,7 @@ static int __init pxa2xx_udc_probe(struct platform_device *pdev) | |||
2591 | printk(KERN_ERR "%s: can't get irq %i, err %d\n", | 2580 | printk(KERN_ERR "%s: can't get irq %i, err %d\n", |
2592 | driver_name, LUBBOCK_USB_DISC_IRQ, retval); | 2581 | driver_name, LUBBOCK_USB_DISC_IRQ, retval); |
2593 | lubbock_fail0: | 2582 | lubbock_fail0: |
2594 | free_irq(IRQ_USB, dev); | 2583 | free_irq(irq, dev); |
2595 | return -EBUSY; | 2584 | return -EBUSY; |
2596 | } | 2585 | } |
2597 | retval = request_irq(LUBBOCK_USB_IRQ, | 2586 | retval = request_irq(LUBBOCK_USB_IRQ, |
@@ -2618,7 +2607,7 @@ lubbock_fail0: | |||
2618 | if (retval != 0) { | 2607 | if (retval != 0) { |
2619 | printk(KERN_ERR "%s: can't get irq %i, err %d\n", | 2608 | printk(KERN_ERR "%s: can't get irq %i, err %d\n", |
2620 | driver_name, vbus_irq, retval); | 2609 | driver_name, vbus_irq, retval); |
2621 | free_irq(IRQ_USB, dev); | 2610 | free_irq(irq, dev); |
2622 | return -EBUSY; | 2611 | return -EBUSY; |
2623 | } | 2612 | } |
2624 | } | 2613 | } |
@@ -2643,7 +2632,7 @@ static int __exit pxa2xx_udc_remove(struct platform_device *pdev) | |||
2643 | remove_proc_files(); | 2632 | remove_proc_files(); |
2644 | 2633 | ||
2645 | if (dev->got_irq) { | 2634 | if (dev->got_irq) { |
2646 | free_irq(IRQ_USB, dev); | 2635 | free_irq(platform_get_irq(pdev, 0), dev); |
2647 | dev->got_irq = 0; | 2636 | dev->got_irq = 0; |
2648 | } | 2637 | } |
2649 | #ifdef CONFIG_ARCH_LUBBOCK | 2638 | #ifdef CONFIG_ARCH_LUBBOCK |
@@ -2670,7 +2659,7 @@ static int __exit pxa2xx_udc_remove(struct platform_device *pdev) | |||
2670 | * | 2659 | * |
2671 | * For now, we punt and forcibly disconnect from the USB host when PXA | 2660 | * For now, we punt and forcibly disconnect from the USB host when PXA |
2672 | * enters any suspend state. While we're disconnected, we always disable | 2661 | * enters any suspend state. While we're disconnected, we always disable |
2673 | * the 48MHz USB clock ... allowing PXA sleep and/or 33 MHz idle states. | 2662 | * the 48MHz USB clock ... allowing PXA sleep and/or 33 MHz idle states. |
2674 | * Boards without software pullup control shouldn't use those states. | 2663 | * Boards without software pullup control shouldn't use those states. |
2675 | * VBUS IRQs should probably be ignored so that the PXA device just acts | 2664 | * VBUS IRQs should probably be ignored so that the PXA device just acts |
2676 | * "dead" to USB hosts until system resume. | 2665 | * "dead" to USB hosts until system resume. |
@@ -2703,7 +2692,6 @@ static int pxa2xx_udc_resume(struct platform_device *dev) | |||
2703 | /*-------------------------------------------------------------------------*/ | 2692 | /*-------------------------------------------------------------------------*/ |
2704 | 2693 | ||
2705 | static struct platform_driver udc_driver = { | 2694 | static struct platform_driver udc_driver = { |
2706 | .probe = pxa2xx_udc_probe, | ||
2707 | .shutdown = pxa2xx_udc_shutdown, | 2695 | .shutdown = pxa2xx_udc_shutdown, |
2708 | .remove = __exit_p(pxa2xx_udc_remove), | 2696 | .remove = __exit_p(pxa2xx_udc_remove), |
2709 | .suspend = pxa2xx_udc_suspend, | 2697 | .suspend = pxa2xx_udc_suspend, |
@@ -2717,7 +2705,7 @@ static struct platform_driver udc_driver = { | |||
2717 | static int __init udc_init(void) | 2705 | static int __init udc_init(void) |
2718 | { | 2706 | { |
2719 | printk(KERN_INFO "%s: version %s\n", driver_name, DRIVER_VERSION); | 2707 | printk(KERN_INFO "%s: version %s\n", driver_name, DRIVER_VERSION); |
2720 | return platform_driver_register(&udc_driver); | 2708 | return platform_driver_probe(&udc_driver, pxa2xx_udc_probe); |
2721 | } | 2709 | } |
2722 | module_init(udc_init); | 2710 | module_init(udc_init); |
2723 | 2711 | ||
diff --git a/drivers/usb/gadget/pxa2xx_udc.h b/drivers/usb/gadget/pxa2xx_udc.h index 8e598c8bf4e3..773e549aff3f 100644 --- a/drivers/usb/gadget/pxa2xx_udc.h +++ b/drivers/usb/gadget/pxa2xx_udc.h | |||
@@ -177,21 +177,6 @@ struct pxa2xx_udc { | |||
177 | 177 | ||
178 | static struct pxa2xx_udc *the_controller; | 178 | static struct pxa2xx_udc *the_controller; |
179 | 179 | ||
180 | static inline int pxa_gpio_get(unsigned gpio) | ||
181 | { | ||
182 | return (GPLR(gpio) & GPIO_bit(gpio)) != 0; | ||
183 | } | ||
184 | |||
185 | static inline void pxa_gpio_set(unsigned gpio, int is_on) | ||
186 | { | ||
187 | int mask = GPIO_bit(gpio); | ||
188 | |||
189 | if (is_on) | ||
190 | GPSR(gpio) = mask; | ||
191 | else | ||
192 | GPCR(gpio) = mask; | ||
193 | } | ||
194 | |||
195 | /*-------------------------------------------------------------------------*/ | 180 | /*-------------------------------------------------------------------------*/ |
196 | 181 | ||
197 | /* | 182 | /* |
diff --git a/drivers/usb/gadget/rndis.h b/drivers/usb/gadget/rndis.h index 4c3c7259f019..397b149f3ca7 100644 --- a/drivers/usb/gadget/rndis.h +++ b/drivers/usb/gadget/rndis.h | |||
@@ -195,7 +195,7 @@ struct rndis_packet_msg_type | |||
195 | __le32 PerPacketInfoLength; | 195 | __le32 PerPacketInfoLength; |
196 | __le32 VcHandle; | 196 | __le32 VcHandle; |
197 | __le32 Reserved; | 197 | __le32 Reserved; |
198 | }; | 198 | } __attribute__ ((packed)); |
199 | 199 | ||
200 | struct rndis_config_parameter | 200 | struct rndis_config_parameter |
201 | { | 201 | { |
diff --git a/drivers/usb/gadget/serial.c b/drivers/usb/gadget/serial.c index e6c19aa4bef3..e552668d36b3 100644 --- a/drivers/usb/gadget/serial.c +++ b/drivers/usb/gadget/serial.c | |||
@@ -1699,6 +1699,7 @@ static int gs_setup_class(struct usb_gadget *gadget, | |||
1699 | memcpy(&port->port_line_coding, req->buf, ret); | 1699 | memcpy(&port->port_line_coding, req->buf, ret); |
1700 | spin_unlock(&port->port_lock); | 1700 | spin_unlock(&port->port_lock); |
1701 | } | 1701 | } |
1702 | ret = 0; | ||
1702 | break; | 1703 | break; |
1703 | 1704 | ||
1704 | case USB_CDC_REQ_GET_LINE_CODING: | 1705 | case USB_CDC_REQ_GET_LINE_CODING: |
diff --git a/drivers/usb/host/Makefile b/drivers/usb/host/Makefile index a2e58c86849f..2ff396bd180f 100644 --- a/drivers/usb/host/Makefile +++ b/drivers/usb/host/Makefile | |||
@@ -15,4 +15,3 @@ obj-$(CONFIG_USB_UHCI_HCD) += uhci-hcd.o | |||
15 | obj-$(CONFIG_USB_SL811_HCD) += sl811-hcd.o | 15 | obj-$(CONFIG_USB_SL811_HCD) += sl811-hcd.o |
16 | obj-$(CONFIG_USB_SL811_CS) += sl811_cs.o | 16 | obj-$(CONFIG_USB_SL811_CS) += sl811_cs.o |
17 | obj-$(CONFIG_USB_U132_HCD) += u132-hcd.o | 17 | obj-$(CONFIG_USB_U132_HCD) += u132-hcd.o |
18 | obj-$(CONFIG_ETRAX_ARCH_V10) += hc_crisv10.o | ||
diff --git a/drivers/usb/host/ehci-dbg.c b/drivers/usb/host/ehci-dbg.c index 246afea9e83b..43eddaecc3dd 100644 --- a/drivers/usb/host/ehci-dbg.c +++ b/drivers/usb/host/ehci-dbg.c | |||
@@ -322,7 +322,7 @@ static inline void remove_debug_files (struct ehci_hcd *bus) { } | |||
322 | 322 | ||
323 | #else | 323 | #else |
324 | 324 | ||
325 | /* troubleshooting help: expose state in driverfs */ | 325 | /* troubleshooting help: expose state in sysfs */ |
326 | 326 | ||
327 | #define speed_char(info1) ({ char tmp; \ | 327 | #define speed_char(info1) ({ char tmp; \ |
328 | switch (info1 & (3 << 12)) { \ | 328 | switch (info1 & (3 << 12)) { \ |
diff --git a/drivers/usb/host/ehci-fsl.h b/drivers/usb/host/ehci-fsl.h index caac0d1967d0..f28736a917e4 100644 --- a/drivers/usb/host/ehci-fsl.h +++ b/drivers/usb/host/ehci-fsl.h | |||
@@ -31,7 +31,7 @@ | |||
31 | #define FSL_SOC_USB_SNOOP1 0x400 /* NOTE: big-endian */ | 31 | #define FSL_SOC_USB_SNOOP1 0x400 /* NOTE: big-endian */ |
32 | #define FSL_SOC_USB_SNOOP2 0x404 /* NOTE: big-endian */ | 32 | #define FSL_SOC_USB_SNOOP2 0x404 /* NOTE: big-endian */ |
33 | #define FSL_SOC_USB_AGECNTTHRSH 0x408 /* NOTE: big-endian */ | 33 | #define FSL_SOC_USB_AGECNTTHRSH 0x408 /* NOTE: big-endian */ |
34 | #define FSL_SOC_USB_SICTRL 0x40c /* NOTE: big-endian */ | 34 | #define FSL_SOC_USB_PRICTRL 0x40c /* NOTE: big-endian */ |
35 | #define FSL_SOC_USB_PRICTRL 0x410 /* NOTE: big-endian */ | 35 | #define FSL_SOC_USB_SICTRL 0x410 /* NOTE: big-endian */ |
36 | #define FSL_SOC_USB_CTRL 0x500 /* NOTE: big-endian */ | 36 | #define FSL_SOC_USB_CTRL 0x500 /* NOTE: big-endian */ |
37 | #endif /* _EHCI_FSL_H */ | 37 | #endif /* _EHCI_FSL_H */ |
diff --git a/drivers/usb/host/ehci-hcd.c b/drivers/usb/host/ehci-hcd.c index 185721dba42b..c7458f7e56cc 100644 --- a/drivers/usb/host/ehci-hcd.c +++ b/drivers/usb/host/ehci-hcd.c | |||
@@ -42,6 +42,9 @@ | |||
42 | #include <asm/irq.h> | 42 | #include <asm/irq.h> |
43 | #include <asm/system.h> | 43 | #include <asm/system.h> |
44 | #include <asm/unaligned.h> | 44 | #include <asm/unaligned.h> |
45 | #ifdef CONFIG_PPC_PS3 | ||
46 | #include <asm/firmware.h> | ||
47 | #endif | ||
45 | 48 | ||
46 | 49 | ||
47 | /*-------------------------------------------------------------------------*/ | 50 | /*-------------------------------------------------------------------------*/ |
@@ -299,6 +302,19 @@ static void ehci_watchdog (unsigned long param) | |||
299 | spin_unlock_irqrestore (&ehci->lock, flags); | 302 | spin_unlock_irqrestore (&ehci->lock, flags); |
300 | } | 303 | } |
301 | 304 | ||
305 | /* On some systems, leaving remote wakeup enabled prevents system shutdown. | ||
306 | * The firmware seems to think that powering off is a wakeup event! | ||
307 | * This routine turns off remote wakeup and everything else, on all ports. | ||
308 | */ | ||
309 | static void ehci_turn_off_all_ports(struct ehci_hcd *ehci) | ||
310 | { | ||
311 | int port = HCS_N_PORTS(ehci->hcs_params); | ||
312 | |||
313 | while (port--) | ||
314 | ehci_writel(ehci, PORT_RWC_BITS, | ||
315 | &ehci->regs->port_status[port]); | ||
316 | } | ||
317 | |||
302 | /* ehci_shutdown kick in for silicon on any bus (not just pci, etc). | 318 | /* ehci_shutdown kick in for silicon on any bus (not just pci, etc). |
303 | * This forcibly disables dma and IRQs, helping kexec and other cases | 319 | * This forcibly disables dma and IRQs, helping kexec and other cases |
304 | * where the next system software may expect clean state. | 320 | * where the next system software may expect clean state. |
@@ -310,9 +326,13 @@ ehci_shutdown (struct usb_hcd *hcd) | |||
310 | 326 | ||
311 | ehci = hcd_to_ehci (hcd); | 327 | ehci = hcd_to_ehci (hcd); |
312 | (void) ehci_halt (ehci); | 328 | (void) ehci_halt (ehci); |
329 | ehci_turn_off_all_ports(ehci); | ||
313 | 330 | ||
314 | /* make BIOS/etc use companion controller during reboot */ | 331 | /* make BIOS/etc use companion controller during reboot */ |
315 | ehci_writel(ehci, 0, &ehci->regs->configured_flag); | 332 | ehci_writel(ehci, 0, &ehci->regs->configured_flag); |
333 | |||
334 | /* unblock posted writes */ | ||
335 | ehci_readl(ehci, &ehci->regs->configured_flag); | ||
316 | } | 336 | } |
317 | 337 | ||
318 | static void ehci_port_power (struct ehci_hcd *ehci, int is_on) | 338 | static void ehci_port_power (struct ehci_hcd *ehci, int is_on) |
@@ -649,6 +669,7 @@ static irqreturn_t ehci_irq (struct usb_hcd *hcd) | |||
649 | */ | 669 | */ |
650 | ehci->reset_done [i] = jiffies + msecs_to_jiffies (20); | 670 | ehci->reset_done [i] = jiffies + msecs_to_jiffies (20); |
651 | ehci_dbg (ehci, "port %d remote wakeup\n", i + 1); | 671 | ehci_dbg (ehci, "port %d remote wakeup\n", i + 1); |
672 | mod_timer(&hcd->rh_timer, ehci->reset_done[i]); | ||
652 | } | 673 | } |
653 | } | 674 | } |
654 | 675 | ||
@@ -951,15 +972,18 @@ static int __init ehci_hcd_init(void) | |||
951 | #endif | 972 | #endif |
952 | 973 | ||
953 | #ifdef PS3_SYSTEM_BUS_DRIVER | 974 | #ifdef PS3_SYSTEM_BUS_DRIVER |
954 | retval = ps3_system_bus_driver_register(&PS3_SYSTEM_BUS_DRIVER); | 975 | if (firmware_has_feature(FW_FEATURE_PS3_LV1)) { |
955 | if (retval < 0) { | 976 | retval = ps3_system_bus_driver_register( |
977 | &PS3_SYSTEM_BUS_DRIVER); | ||
978 | if (retval < 0) { | ||
956 | #ifdef PLATFORM_DRIVER | 979 | #ifdef PLATFORM_DRIVER |
957 | platform_driver_unregister(&PLATFORM_DRIVER); | 980 | platform_driver_unregister(&PLATFORM_DRIVER); |
958 | #endif | 981 | #endif |
959 | #ifdef PCI_DRIVER | 982 | #ifdef PCI_DRIVER |
960 | pci_unregister_driver(&PCI_DRIVER); | 983 | pci_unregister_driver(&PCI_DRIVER); |
961 | #endif | 984 | #endif |
962 | return retval; | 985 | return retval; |
986 | } | ||
963 | } | 987 | } |
964 | #endif | 988 | #endif |
965 | 989 | ||
@@ -976,7 +1000,8 @@ static void __exit ehci_hcd_cleanup(void) | |||
976 | pci_unregister_driver(&PCI_DRIVER); | 1000 | pci_unregister_driver(&PCI_DRIVER); |
977 | #endif | 1001 | #endif |
978 | #ifdef PS3_SYSTEM_BUS_DRIVER | 1002 | #ifdef PS3_SYSTEM_BUS_DRIVER |
979 | ps3_system_bus_driver_unregister(&PS3_SYSTEM_BUS_DRIVER); | 1003 | if (firmware_has_feature(FW_FEATURE_PS3_LV1)) |
1004 | ps3_system_bus_driver_unregister(&PS3_SYSTEM_BUS_DRIVER); | ||
980 | #endif | 1005 | #endif |
981 | } | 1006 | } |
982 | module_exit(ehci_hcd_cleanup); | 1007 | module_exit(ehci_hcd_cleanup); |
diff --git a/drivers/usb/host/ehci-hub.c b/drivers/usb/host/ehci-hub.c index 0d83c6df1a3b..f4d301bc83b9 100644 --- a/drivers/usb/host/ehci-hub.c +++ b/drivers/usb/host/ehci-hub.c | |||
@@ -36,6 +36,8 @@ static int ehci_bus_suspend (struct usb_hcd *hcd) | |||
36 | int port; | 36 | int port; |
37 | int mask; | 37 | int mask; |
38 | 38 | ||
39 | ehci_dbg(ehci, "suspend root hub\n"); | ||
40 | |||
39 | if (time_before (jiffies, ehci->next_statechange)) | 41 | if (time_before (jiffies, ehci->next_statechange)) |
40 | msleep(5); | 42 | msleep(5); |
41 | 43 | ||
@@ -134,6 +136,10 @@ static int ehci_bus_resume (struct usb_hcd *hcd) | |||
134 | /* restore CMD_RUN, framelist size, and irq threshold */ | 136 | /* restore CMD_RUN, framelist size, and irq threshold */ |
135 | ehci_writel(ehci, ehci->command, &ehci->regs->command); | 137 | ehci_writel(ehci, ehci->command, &ehci->regs->command); |
136 | 138 | ||
139 | /* Some controller/firmware combinations need a delay during which | ||
140 | * they set up the port statuses. See Bugzilla #8190. */ | ||
141 | mdelay(8); | ||
142 | |||
137 | /* manually resume the ports we suspended during bus_suspend() */ | 143 | /* manually resume the ports we suspended during bus_suspend() */ |
138 | i = HCS_N_PORTS (ehci->hcs_params); | 144 | i = HCS_N_PORTS (ehci->hcs_params); |
139 | while (i--) { | 145 | while (i--) { |
@@ -651,8 +657,7 @@ static int ehci_hub_control ( | |||
651 | if (status & ~0xffff) /* only if wPortChange is interesting */ | 657 | if (status & ~0xffff) /* only if wPortChange is interesting */ |
652 | #endif | 658 | #endif |
653 | dbg_port (ehci, "GetStatus", wIndex + 1, temp); | 659 | dbg_port (ehci, "GetStatus", wIndex + 1, temp); |
654 | // we "know" this alignment is good, caller used kmalloc()... | 660 | put_unaligned(cpu_to_le32 (status), (__le32 *) buf); |
655 | *((__le32 *) buf) = cpu_to_le32 (status); | ||
656 | break; | 661 | break; |
657 | case SetHubFeature: | 662 | case SetHubFeature: |
658 | switch (wValue) { | 663 | switch (wValue) { |
diff --git a/drivers/usb/host/hc_crisv10.c b/drivers/usb/host/hc_crisv10.c deleted file mode 100644 index 32f7caf24747..000000000000 --- a/drivers/usb/host/hc_crisv10.c +++ /dev/null | |||
@@ -1,4550 +0,0 @@ | |||
1 | /* | ||
2 | * usb-host.c: ETRAX 100LX USB Host Controller Driver (HCD) | ||
3 | * | ||
4 | * Copyright (c) 2002, 2003 Axis Communications AB. | ||
5 | */ | ||
6 | |||
7 | #include <linux/kernel.h> | ||
8 | #include <linux/delay.h> | ||
9 | #include <linux/ioport.h> | ||
10 | #include <linux/slab.h> | ||
11 | #include <linux/errno.h> | ||
12 | #include <linux/unistd.h> | ||
13 | #include <linux/interrupt.h> | ||
14 | #include <linux/init.h> | ||
15 | #include <linux/list.h> | ||
16 | #include <linux/spinlock.h> | ||
17 | |||
18 | #include <asm/uaccess.h> | ||
19 | #include <asm/io.h> | ||
20 | #include <asm/irq.h> | ||
21 | #include <asm/dma.h> | ||
22 | #include <asm/system.h> | ||
23 | #include <asm/arch/svinto.h> | ||
24 | |||
25 | #include <linux/usb.h> | ||
26 | /* Ugly include because we don't live with the other host drivers. */ | ||
27 | #include <../drivers/usb/core/hcd.h> | ||
28 | #include <../drivers/usb/core/usb.h> | ||
29 | |||
30 | #include "hc_crisv10.h" | ||
31 | |||
32 | #define ETRAX_USB_HC_IRQ USB_HC_IRQ_NBR | ||
33 | #define ETRAX_USB_RX_IRQ USB_DMA_RX_IRQ_NBR | ||
34 | #define ETRAX_USB_TX_IRQ USB_DMA_TX_IRQ_NBR | ||
35 | |||
36 | static const char *usb_hcd_version = "$Revision: 1.2 $"; | ||
37 | |||
38 | #undef KERN_DEBUG | ||
39 | #define KERN_DEBUG "" | ||
40 | |||
41 | |||
42 | #undef USB_DEBUG_RH | ||
43 | #undef USB_DEBUG_EPID | ||
44 | #undef USB_DEBUG_SB | ||
45 | #undef USB_DEBUG_DESC | ||
46 | #undef USB_DEBUG_URB | ||
47 | #undef USB_DEBUG_TRACE | ||
48 | #undef USB_DEBUG_BULK | ||
49 | #undef USB_DEBUG_CTRL | ||
50 | #undef USB_DEBUG_INTR | ||
51 | #undef USB_DEBUG_ISOC | ||
52 | |||
53 | #ifdef USB_DEBUG_RH | ||
54 | #define dbg_rh(format, arg...) printk(KERN_DEBUG __FILE__ ": (RH) " format "\n" , ## arg) | ||
55 | #else | ||
56 | #define dbg_rh(format, arg...) do {} while (0) | ||
57 | #endif | ||
58 | |||
59 | #ifdef USB_DEBUG_EPID | ||
60 | #define dbg_epid(format, arg...) printk(KERN_DEBUG __FILE__ ": (EPID) " format "\n" , ## arg) | ||
61 | #else | ||
62 | #define dbg_epid(format, arg...) do {} while (0) | ||
63 | #endif | ||
64 | |||
65 | #ifdef USB_DEBUG_SB | ||
66 | #define dbg_sb(format, arg...) printk(KERN_DEBUG __FILE__ ": (SB) " format "\n" , ## arg) | ||
67 | #else | ||
68 | #define dbg_sb(format, arg...) do {} while (0) | ||
69 | #endif | ||
70 | |||
71 | #ifdef USB_DEBUG_CTRL | ||
72 | #define dbg_ctrl(format, arg...) printk(KERN_DEBUG __FILE__ ": (CTRL) " format "\n" , ## arg) | ||
73 | #else | ||
74 | #define dbg_ctrl(format, arg...) do {} while (0) | ||
75 | #endif | ||
76 | |||
77 | #ifdef USB_DEBUG_BULK | ||
78 | #define dbg_bulk(format, arg...) printk(KERN_DEBUG __FILE__ ": (BULK) " format "\n" , ## arg) | ||
79 | #else | ||
80 | #define dbg_bulk(format, arg...) do {} while (0) | ||
81 | #endif | ||
82 | |||
83 | #ifdef USB_DEBUG_INTR | ||
84 | #define dbg_intr(format, arg...) printk(KERN_DEBUG __FILE__ ": (INTR) " format "\n" , ## arg) | ||
85 | #else | ||
86 | #define dbg_intr(format, arg...) do {} while (0) | ||
87 | #endif | ||
88 | |||
89 | #ifdef USB_DEBUG_ISOC | ||
90 | #define dbg_isoc(format, arg...) printk(KERN_DEBUG __FILE__ ": (ISOC) " format "\n" , ## arg) | ||
91 | #else | ||
92 | #define dbg_isoc(format, arg...) do {} while (0) | ||
93 | #endif | ||
94 | |||
95 | #ifdef USB_DEBUG_TRACE | ||
96 | #define DBFENTER (printk(": Entering: %s\n", __FUNCTION__)) | ||
97 | #define DBFEXIT (printk(": Exiting: %s\n", __FUNCTION__)) | ||
98 | #else | ||
99 | #define DBFENTER do {} while (0) | ||
100 | #define DBFEXIT do {} while (0) | ||
101 | #endif | ||
102 | |||
103 | #define usb_pipeslow(pipe) (((pipe) >> 26) & 1) | ||
104 | |||
105 | /*------------------------------------------------------------------- | ||
106 | Virtual Root Hub | ||
107 | -------------------------------------------------------------------*/ | ||
108 | |||
109 | static __u8 root_hub_dev_des[] = | ||
110 | { | ||
111 | 0x12, /* __u8 bLength; */ | ||
112 | 0x01, /* __u8 bDescriptorType; Device */ | ||
113 | 0x00, /* __le16 bcdUSB; v1.0 */ | ||
114 | 0x01, | ||
115 | 0x09, /* __u8 bDeviceClass; HUB_CLASSCODE */ | ||
116 | 0x00, /* __u8 bDeviceSubClass; */ | ||
117 | 0x00, /* __u8 bDeviceProtocol; */ | ||
118 | 0x08, /* __u8 bMaxPacketSize0; 8 Bytes */ | ||
119 | 0x00, /* __le16 idVendor; */ | ||
120 | 0x00, | ||
121 | 0x00, /* __le16 idProduct; */ | ||
122 | 0x00, | ||
123 | 0x00, /* __le16 bcdDevice; */ | ||
124 | 0x00, | ||
125 | 0x00, /* __u8 iManufacturer; */ | ||
126 | 0x02, /* __u8 iProduct; */ | ||
127 | 0x01, /* __u8 iSerialNumber; */ | ||
128 | 0x01 /* __u8 bNumConfigurations; */ | ||
129 | }; | ||
130 | |||
131 | /* Configuration descriptor */ | ||
132 | static __u8 root_hub_config_des[] = | ||
133 | { | ||
134 | 0x09, /* __u8 bLength; */ | ||
135 | 0x02, /* __u8 bDescriptorType; Configuration */ | ||
136 | 0x19, /* __le16 wTotalLength; */ | ||
137 | 0x00, | ||
138 | 0x01, /* __u8 bNumInterfaces; */ | ||
139 | 0x01, /* __u8 bConfigurationValue; */ | ||
140 | 0x00, /* __u8 iConfiguration; */ | ||
141 | 0x40, /* __u8 bmAttributes; Bit 7: Bus-powered */ | ||
142 | 0x00, /* __u8 MaxPower; */ | ||
143 | |||
144 | /* interface */ | ||
145 | 0x09, /* __u8 if_bLength; */ | ||
146 | 0x04, /* __u8 if_bDescriptorType; Interface */ | ||
147 | 0x00, /* __u8 if_bInterfaceNumber; */ | ||
148 | 0x00, /* __u8 if_bAlternateSetting; */ | ||
149 | 0x01, /* __u8 if_bNumEndpoints; */ | ||
150 | 0x09, /* __u8 if_bInterfaceClass; HUB_CLASSCODE */ | ||
151 | 0x00, /* __u8 if_bInterfaceSubClass; */ | ||
152 | 0x00, /* __u8 if_bInterfaceProtocol; */ | ||
153 | 0x00, /* __u8 if_iInterface; */ | ||
154 | |||
155 | /* endpoint */ | ||
156 | 0x07, /* __u8 ep_bLength; */ | ||
157 | 0x05, /* __u8 ep_bDescriptorType; Endpoint */ | ||
158 | 0x81, /* __u8 ep_bEndpointAddress; IN Endpoint 1 */ | ||
159 | 0x03, /* __u8 ep_bmAttributes; Interrupt */ | ||
160 | 0x08, /* __le16 ep_wMaxPacketSize; 8 Bytes */ | ||
161 | 0x00, | ||
162 | 0xff /* __u8 ep_bInterval; 255 ms */ | ||
163 | }; | ||
164 | |||
165 | static __u8 root_hub_hub_des[] = | ||
166 | { | ||
167 | 0x09, /* __u8 bLength; */ | ||
168 | 0x29, /* __u8 bDescriptorType; Hub-descriptor */ | ||
169 | 0x02, /* __u8 bNbrPorts; */ | ||
170 | 0x00, /* __u16 wHubCharacteristics; */ | ||
171 | 0x00, | ||
172 | 0x01, /* __u8 bPwrOn2pwrGood; 2ms */ | ||
173 | 0x00, /* __u8 bHubContrCurrent; 0 mA */ | ||
174 | 0x00, /* __u8 DeviceRemovable; *** 7 Ports max *** */ | ||
175 | 0xff /* __u8 PortPwrCtrlMask; *** 7 ports max *** */ | ||
176 | }; | ||
177 | |||
178 | static DEFINE_TIMER(bulk_start_timer, NULL, 0, 0); | ||
179 | static DEFINE_TIMER(bulk_eot_timer, NULL, 0, 0); | ||
180 | |||
181 | /* We want the start timer to expire before the eot timer, because the former might start | ||
182 | traffic, thus making it unnecessary for the latter to time out. */ | ||
183 | #define BULK_START_TIMER_INTERVAL (HZ/10) /* 100 ms */ | ||
184 | #define BULK_EOT_TIMER_INTERVAL (HZ/10+2) /* 120 ms */ | ||
185 | |||
186 | #define OK(x) len = (x); dbg_rh("OK(%d): line: %d", x, __LINE__); break | ||
187 | #define CHECK_ALIGN(x) if (((__u32)(x)) & 0x00000003) \ | ||
188 | {panic("Alignment check (DWORD) failed at %s:%s:%d\n", __FILE__, __FUNCTION__, __LINE__);} | ||
189 | |||
190 | #define SLAB_FLAG (in_interrupt() ? GFP_ATOMIC : GFP_KERNEL) | ||
191 | #define KMALLOC_FLAG (in_interrupt() ? GFP_ATOMIC : GFP_KERNEL) | ||
192 | |||
193 | /* Most helpful debugging aid */ | ||
194 | #define assert(expr) ((void) ((expr) ? 0 : (err("assert failed at line %d",__LINE__)))) | ||
195 | |||
196 | /* Alternative assert define which stops after a failed assert. */ | ||
197 | /* | ||
198 | #define assert(expr) \ | ||
199 | { \ | ||
200 | if (!(expr)) { \ | ||
201 | err("assert failed at line %d",__LINE__); \ | ||
202 | while (1); \ | ||
203 | } \ | ||
204 | } | ||
205 | */ | ||
206 | |||
207 | |||
208 | /* FIXME: Should RX_BUF_SIZE be a config option, or maybe we should adjust it dynamically? | ||
209 | To adjust it dynamically we would have to get an interrupt when we reach the end | ||
210 | of the rx descriptor list, or when we get close to the end, and then allocate more | ||
211 | descriptors. */ | ||
212 | |||
213 | #define NBR_OF_RX_DESC 512 | ||
214 | #define RX_DESC_BUF_SIZE 1024 | ||
215 | #define RX_BUF_SIZE (NBR_OF_RX_DESC * RX_DESC_BUF_SIZE) | ||
216 | |||
217 | /* The number of epids is, among other things, used for pre-allocating | ||
218 | ctrl, bulk and isoc EP descriptors (one for each epid). | ||
219 | Assumed to be > 1 when initiating the DMA lists. */ | ||
220 | #define NBR_OF_EPIDS 32 | ||
221 | |||
222 | /* Support interrupt traffic intervals up to 128 ms. */ | ||
223 | #define MAX_INTR_INTERVAL 128 | ||
224 | |||
225 | /* If periodic traffic (intr or isoc) is to be used, then one entry in the EP table | ||
226 | must be "invalid". By this we mean that we shouldn't care about epid attentions | ||
227 | for this epid, or at least handle them differently from epid attentions for "valid" | ||
228 | epids. This define determines which one to use (don't change it). */ | ||
229 | #define INVALID_EPID 31 | ||
230 | /* A special epid for the bulk dummys. */ | ||
231 | #define DUMMY_EPID 30 | ||
232 | |||
233 | /* This is just a software cache for the valid entries in R_USB_EPT_DATA. */ | ||
234 | static __u32 epid_usage_bitmask; | ||
235 | |||
236 | /* A bitfield to keep information on in/out traffic is needed to uniquely identify | ||
237 | an endpoint on a device, since the most significant bit which indicates traffic | ||
238 | direction is lacking in the ep_id field (ETRAX epids can handle both in and | ||
239 | out traffic on endpoints that are otherwise identical). The USB framework, however, | ||
240 | relies on them to be handled separately. For example, bulk IN and OUT urbs cannot | ||
241 | be queued in the same list, since they would block each other. */ | ||
242 | static __u32 epid_out_traffic; | ||
243 | |||
244 | /* DMA IN cache bug. Align the DMA IN buffers to 32 bytes, i.e. a cache line. | ||
245 | Since RX_DESC_BUF_SIZE is 1024 is a multiple of 32, all rx buffers will be cache aligned. */ | ||
246 | static volatile unsigned char RxBuf[RX_BUF_SIZE] __attribute__ ((aligned (32))); | ||
247 | static volatile USB_IN_Desc_t RxDescList[NBR_OF_RX_DESC] __attribute__ ((aligned (4))); | ||
248 | |||
249 | /* Pointers into RxDescList. */ | ||
250 | static volatile USB_IN_Desc_t *myNextRxDesc; | ||
251 | static volatile USB_IN_Desc_t *myLastRxDesc; | ||
252 | static volatile USB_IN_Desc_t *myPrevRxDesc; | ||
253 | |||
254 | /* EP descriptors must be 32-bit aligned. */ | ||
255 | static volatile USB_EP_Desc_t TxCtrlEPList[NBR_OF_EPIDS] __attribute__ ((aligned (4))); | ||
256 | static volatile USB_EP_Desc_t TxBulkEPList[NBR_OF_EPIDS] __attribute__ ((aligned (4))); | ||
257 | /* After each enabled bulk EP (IN or OUT) we put two disabled EP descriptors with the eol flag set, | ||
258 | causing the DMA to stop the DMA channel. The first of these two has the intr flag set, which | ||
259 | gives us a dma8_sub0_descr interrupt. When we receive this, we advance the DMA one step in the | ||
260 | EP list and then restart the bulk channel, thus forcing a switch between bulk EP descriptors | ||
261 | in each frame. */ | ||
262 | static volatile USB_EP_Desc_t TxBulkDummyEPList[NBR_OF_EPIDS][2] __attribute__ ((aligned (4))); | ||
263 | |||
264 | static volatile USB_EP_Desc_t TxIsocEPList[NBR_OF_EPIDS] __attribute__ ((aligned (4))); | ||
265 | static volatile USB_SB_Desc_t TxIsocSB_zout __attribute__ ((aligned (4))); | ||
266 | |||
267 | static volatile USB_EP_Desc_t TxIntrEPList[MAX_INTR_INTERVAL] __attribute__ ((aligned (4))); | ||
268 | static volatile USB_SB_Desc_t TxIntrSB_zout __attribute__ ((aligned (4))); | ||
269 | |||
270 | /* A zout transfer makes a memory access at the address of its buf pointer, which means that setting | ||
271 | this buf pointer to 0 will cause an access to the flash. In addition to this, setting sw_len to 0 | ||
272 | results in a 16/32 bytes (depending on DMA burst size) transfer. Instead, we set it to 1, and point | ||
273 | it to this buffer. */ | ||
274 | static int zout_buffer[4] __attribute__ ((aligned (4))); | ||
275 | |||
276 | /* Cache for allocating new EP and SB descriptors. */ | ||
277 | static struct kmem_cache *usb_desc_cache; | ||
278 | |||
279 | /* Cache for the registers allocated in the top half. */ | ||
280 | static struct kmem_cache *top_half_reg_cache; | ||
281 | |||
282 | /* Cache for the data allocated in the isoc descr top half. */ | ||
283 | static struct kmem_cache *isoc_compl_cache; | ||
284 | |||
285 | static struct usb_bus *etrax_usb_bus; | ||
286 | |||
287 | /* This is a circular (double-linked) list of the active urbs for each epid. | ||
288 | The head is never removed, and new urbs are linked onto the list as | ||
289 | urb_entry_t elements. Don't reference urb_list directly; use the wrapper | ||
290 | functions instead. Note that working with these lists might require spinlock | ||
291 | protection. */ | ||
292 | static struct list_head urb_list[NBR_OF_EPIDS]; | ||
293 | |||
294 | /* Read about the need and usage of this lock in submit_ctrl_urb. */ | ||
295 | static spinlock_t urb_list_lock; | ||
296 | |||
297 | /* Used when unlinking asynchronously. */ | ||
298 | static struct list_head urb_unlink_list; | ||
299 | |||
300 | /* for returning string descriptors in UTF-16LE */ | ||
301 | static int ascii2utf (char *ascii, __u8 *utf, int utfmax) | ||
302 | { | ||
303 | int retval; | ||
304 | |||
305 | for (retval = 0; *ascii && utfmax > 1; utfmax -= 2, retval += 2) { | ||
306 | *utf++ = *ascii++ & 0x7f; | ||
307 | *utf++ = 0; | ||
308 | } | ||
309 | return retval; | ||
310 | } | ||
311 | |||
312 | static int usb_root_hub_string (int id, int serial, char *type, __u8 *data, int len) | ||
313 | { | ||
314 | char buf [30]; | ||
315 | |||
316 | // assert (len > (2 * (sizeof (buf) + 1))); | ||
317 | // assert (strlen (type) <= 8); | ||
318 | |||
319 | // language ids | ||
320 | if (id == 0) { | ||
321 | *data++ = 4; *data++ = 3; /* 4 bytes data */ | ||
322 | *data++ = 0; *data++ = 0; /* some language id */ | ||
323 | return 4; | ||
324 | |||
325 | // serial number | ||
326 | } else if (id == 1) { | ||
327 | sprintf (buf, "%x", serial); | ||
328 | |||
329 | // product description | ||
330 | } else if (id == 2) { | ||
331 | sprintf (buf, "USB %s Root Hub", type); | ||
332 | |||
333 | // id 3 == vendor description | ||
334 | |||
335 | // unsupported IDs --> "stall" | ||
336 | } else | ||
337 | return 0; | ||
338 | |||
339 | data [0] = 2 + ascii2utf (buf, data + 2, len - 2); | ||
340 | data [1] = 3; | ||
341 | return data [0]; | ||
342 | } | ||
343 | |||
344 | /* Wrappers around the list functions (include/linux/list.h). */ | ||
345 | |||
346 | static inline int urb_list_empty(int epid) | ||
347 | { | ||
348 | return list_empty(&urb_list[epid]); | ||
349 | } | ||
350 | |||
351 | /* Returns first urb for this epid, or NULL if list is empty. */ | ||
352 | static inline struct urb *urb_list_first(int epid) | ||
353 | { | ||
354 | struct urb *first_urb = 0; | ||
355 | |||
356 | if (!urb_list_empty(epid)) { | ||
357 | /* Get the first urb (i.e. head->next). */ | ||
358 | urb_entry_t *urb_entry = list_entry((&urb_list[epid])->next, urb_entry_t, list); | ||
359 | first_urb = urb_entry->urb; | ||
360 | } | ||
361 | return first_urb; | ||
362 | } | ||
363 | |||
364 | /* Adds an urb_entry last in the list for this epid. */ | ||
365 | static inline void urb_list_add(struct urb *urb, int epid) | ||
366 | { | ||
367 | urb_entry_t *urb_entry = kmalloc(sizeof(urb_entry_t), KMALLOC_FLAG); | ||
368 | assert(urb_entry); | ||
369 | |||
370 | urb_entry->urb = urb; | ||
371 | list_add_tail(&urb_entry->list, &urb_list[epid]); | ||
372 | } | ||
373 | |||
374 | /* Search through the list for an element that contains this urb. (The list | ||
375 | is expected to be short and the one we are about to delete will often be | ||
376 | the first in the list.) */ | ||
377 | static inline urb_entry_t *__urb_list_entry(struct urb *urb, int epid) | ||
378 | { | ||
379 | struct list_head *entry; | ||
380 | struct list_head *tmp; | ||
381 | urb_entry_t *urb_entry; | ||
382 | |||
383 | list_for_each_safe(entry, tmp, &urb_list[epid]) { | ||
384 | urb_entry = list_entry(entry, urb_entry_t, list); | ||
385 | assert(urb_entry); | ||
386 | assert(urb_entry->urb); | ||
387 | |||
388 | if (urb_entry->urb == urb) { | ||
389 | return urb_entry; | ||
390 | } | ||
391 | } | ||
392 | return 0; | ||
393 | } | ||
394 | |||
395 | /* Delete an urb from the list. */ | ||
396 | static inline void urb_list_del(struct urb *urb, int epid) | ||
397 | { | ||
398 | urb_entry_t *urb_entry = __urb_list_entry(urb, epid); | ||
399 | assert(urb_entry); | ||
400 | |||
401 | /* Delete entry and free. */ | ||
402 | list_del(&urb_entry->list); | ||
403 | kfree(urb_entry); | ||
404 | } | ||
405 | |||
406 | /* Move an urb to the end of the list. */ | ||
407 | static inline void urb_list_move_last(struct urb *urb, int epid) | ||
408 | { | ||
409 | urb_entry_t *urb_entry = __urb_list_entry(urb, epid); | ||
410 | assert(urb_entry); | ||
411 | |||
412 | list_move_tail(&urb_entry->list, &urb_list[epid]); | ||
413 | } | ||
414 | |||
415 | /* Get the next urb in the list. */ | ||
416 | static inline struct urb *urb_list_next(struct urb *urb, int epid) | ||
417 | { | ||
418 | urb_entry_t *urb_entry = __urb_list_entry(urb, epid); | ||
419 | |||
420 | assert(urb_entry); | ||
421 | |||
422 | if (urb_entry->list.next != &urb_list[epid]) { | ||
423 | struct list_head *elem = urb_entry->list.next; | ||
424 | urb_entry = list_entry(elem, urb_entry_t, list); | ||
425 | return urb_entry->urb; | ||
426 | } else { | ||
427 | return NULL; | ||
428 | } | ||
429 | } | ||
430 | |||
431 | |||
432 | |||
433 | /* For debug purposes only. */ | ||
434 | static inline void urb_list_dump(int epid) | ||
435 | { | ||
436 | struct list_head *entry; | ||
437 | struct list_head *tmp; | ||
438 | urb_entry_t *urb_entry; | ||
439 | int i = 0; | ||
440 | |||
441 | info("Dumping urb list for epid %d", epid); | ||
442 | |||
443 | list_for_each_safe(entry, tmp, &urb_list[epid]) { | ||
444 | urb_entry = list_entry(entry, urb_entry_t, list); | ||
445 | info(" entry %d, urb = 0x%lx", i, (unsigned long)urb_entry->urb); | ||
446 | } | ||
447 | } | ||
448 | |||
449 | static void init_rx_buffers(void); | ||
450 | static int etrax_rh_unlink_urb(struct urb *urb); | ||
451 | static void etrax_rh_send_irq(struct urb *urb); | ||
452 | static void etrax_rh_init_int_timer(struct urb *urb); | ||
453 | static void etrax_rh_int_timer_do(unsigned long ptr); | ||
454 | |||
455 | static int etrax_usb_setup_epid(struct urb *urb); | ||
456 | static int etrax_usb_lookup_epid(struct urb *urb); | ||
457 | static int etrax_usb_allocate_epid(void); | ||
458 | static void etrax_usb_free_epid(int epid); | ||
459 | |||
460 | static int etrax_remove_from_sb_list(struct urb *urb); | ||
461 | |||
462 | static void* etrax_usb_buffer_alloc(struct usb_bus* bus, size_t size, | ||
463 | unsigned mem_flags, dma_addr_t *dma); | ||
464 | static void etrax_usb_buffer_free(struct usb_bus *bus, size_t size, void *addr, dma_addr_t dma); | ||
465 | |||
466 | static void etrax_usb_add_to_bulk_sb_list(struct urb *urb, int epid); | ||
467 | static void etrax_usb_add_to_ctrl_sb_list(struct urb *urb, int epid); | ||
468 | static void etrax_usb_add_to_intr_sb_list(struct urb *urb, int epid); | ||
469 | static void etrax_usb_add_to_isoc_sb_list(struct urb *urb, int epid); | ||
470 | |||
471 | static int etrax_usb_submit_bulk_urb(struct urb *urb); | ||
472 | static int etrax_usb_submit_ctrl_urb(struct urb *urb); | ||
473 | static int etrax_usb_submit_intr_urb(struct urb *urb); | ||
474 | static int etrax_usb_submit_isoc_urb(struct urb *urb); | ||
475 | |||
476 | static int etrax_usb_submit_urb(struct urb *urb, unsigned mem_flags); | ||
477 | static int etrax_usb_unlink_urb(struct urb *urb, int status); | ||
478 | static int etrax_usb_get_frame_number(struct usb_device *usb_dev); | ||
479 | |||
480 | static irqreturn_t etrax_usb_tx_interrupt(int irq, void *vhc); | ||
481 | static irqreturn_t etrax_usb_rx_interrupt(int irq, void *vhc); | ||
482 | static irqreturn_t etrax_usb_hc_interrupt_top_half(int irq, void *vhc); | ||
483 | static void etrax_usb_hc_interrupt_bottom_half(void *data); | ||
484 | |||
485 | static void etrax_usb_isoc_descr_interrupt_bottom_half(void *data); | ||
486 | |||
487 | |||
488 | /* The following is a list of interrupt handlers for the host controller interrupts we use. | ||
489 | They are called from etrax_usb_hc_interrupt_bottom_half. */ | ||
490 | static void etrax_usb_hc_isoc_eof_interrupt(void); | ||
491 | static void etrax_usb_hc_bulk_eot_interrupt(int timer_induced); | ||
492 | static void etrax_usb_hc_epid_attn_interrupt(usb_interrupt_registers_t *reg); | ||
493 | static void etrax_usb_hc_port_status_interrupt(usb_interrupt_registers_t *reg); | ||
494 | static void etrax_usb_hc_ctl_status_interrupt(usb_interrupt_registers_t *reg); | ||
495 | |||
496 | static int etrax_rh_submit_urb (struct urb *urb); | ||
497 | |||
498 | /* Forward declaration needed because they are used in the rx interrupt routine. */ | ||
499 | static void etrax_usb_complete_urb(struct urb *urb, int status); | ||
500 | static void etrax_usb_complete_bulk_urb(struct urb *urb, int status); | ||
501 | static void etrax_usb_complete_ctrl_urb(struct urb *urb, int status); | ||
502 | static void etrax_usb_complete_intr_urb(struct urb *urb, int status); | ||
503 | static void etrax_usb_complete_isoc_urb(struct urb *urb, int status); | ||
504 | |||
505 | static int etrax_usb_hc_init(void); | ||
506 | static void etrax_usb_hc_cleanup(void); | ||
507 | |||
508 | static struct usb_operations etrax_usb_device_operations = | ||
509 | { | ||
510 | .get_frame_number = etrax_usb_get_frame_number, | ||
511 | .submit_urb = etrax_usb_submit_urb, | ||
512 | .unlink_urb = etrax_usb_unlink_urb, | ||
513 | .buffer_alloc = etrax_usb_buffer_alloc, | ||
514 | .buffer_free = etrax_usb_buffer_free | ||
515 | }; | ||
516 | |||
517 | /* Note that these functions are always available in their "__" variants, for use in | ||
518 | error situations. The "__" missing variants are controlled by the USB_DEBUG_DESC/ | ||
519 | USB_DEBUG_URB macros. */ | ||
520 | static void __dump_urb(struct urb* purb) | ||
521 | { | ||
522 | printk("\nurb :0x%08lx\n", (unsigned long)purb); | ||
523 | printk("dev :0x%08lx\n", (unsigned long)purb->dev); | ||
524 | printk("pipe :0x%08x\n", purb->pipe); | ||
525 | printk("status :%d\n", purb->status); | ||
526 | printk("transfer_flags :0x%08x\n", purb->transfer_flags); | ||
527 | printk("transfer_buffer :0x%08lx\n", (unsigned long)purb->transfer_buffer); | ||
528 | printk("transfer_buffer_length:%d\n", purb->transfer_buffer_length); | ||
529 | printk("actual_length :%d\n", purb->actual_length); | ||
530 | printk("setup_packet :0x%08lx\n", (unsigned long)purb->setup_packet); | ||
531 | printk("start_frame :%d\n", purb->start_frame); | ||
532 | printk("number_of_packets :%d\n", purb->number_of_packets); | ||
533 | printk("interval :%d\n", purb->interval); | ||
534 | printk("error_count :%d\n", purb->error_count); | ||
535 | printk("context :0x%08lx\n", (unsigned long)purb->context); | ||
536 | printk("complete :0x%08lx\n\n", (unsigned long)purb->complete); | ||
537 | } | ||
538 | |||
539 | static void __dump_in_desc(volatile USB_IN_Desc_t *in) | ||
540 | { | ||
541 | printk("\nUSB_IN_Desc at 0x%08lx\n", (unsigned long)in); | ||
542 | printk(" sw_len : 0x%04x (%d)\n", in->sw_len, in->sw_len); | ||
543 | printk(" command : 0x%04x\n", in->command); | ||
544 | printk(" next : 0x%08lx\n", in->next); | ||
545 | printk(" buf : 0x%08lx\n", in->buf); | ||
546 | printk(" hw_len : 0x%04x (%d)\n", in->hw_len, in->hw_len); | ||
547 | printk(" status : 0x%04x\n\n", in->status); | ||
548 | } | ||
549 | |||
550 | static void __dump_sb_desc(volatile USB_SB_Desc_t *sb) | ||
551 | { | ||
552 | char tt = (sb->command & 0x30) >> 4; | ||
553 | char *tt_string; | ||
554 | |||
555 | switch (tt) { | ||
556 | case 0: | ||
557 | tt_string = "zout"; | ||
558 | break; | ||
559 | case 1: | ||
560 | tt_string = "in"; | ||
561 | break; | ||
562 | case 2: | ||
563 | tt_string = "out"; | ||
564 | break; | ||
565 | case 3: | ||
566 | tt_string = "setup"; | ||
567 | break; | ||
568 | default: | ||
569 | tt_string = "unknown (weird)"; | ||
570 | } | ||
571 | |||
572 | printk("\n USB_SB_Desc at 0x%08lx\n", (unsigned long)sb); | ||
573 | printk(" command : 0x%04x\n", sb->command); | ||
574 | printk(" rem : %d\n", (sb->command & 0x3f00) >> 8); | ||
575 | printk(" full : %d\n", (sb->command & 0x40) >> 6); | ||
576 | printk(" tt : %d (%s)\n", tt, tt_string); | ||
577 | printk(" intr : %d\n", (sb->command & 0x8) >> 3); | ||
578 | printk(" eot : %d\n", (sb->command & 0x2) >> 1); | ||
579 | printk(" eol : %d\n", sb->command & 0x1); | ||
580 | printk(" sw_len : 0x%04x (%d)\n", sb->sw_len, sb->sw_len); | ||
581 | printk(" next : 0x%08lx\n", sb->next); | ||
582 | printk(" buf : 0x%08lx\n\n", sb->buf); | ||
583 | } | ||
584 | |||
585 | |||
586 | static void __dump_ep_desc(volatile USB_EP_Desc_t *ep) | ||
587 | { | ||
588 | printk("\nUSB_EP_Desc at 0x%08lx\n", (unsigned long)ep); | ||
589 | printk(" command : 0x%04x\n", ep->command); | ||
590 | printk(" ep_id : %d\n", (ep->command & 0x1f00) >> 8); | ||
591 | printk(" enable : %d\n", (ep->command & 0x10) >> 4); | ||
592 | printk(" intr : %d\n", (ep->command & 0x8) >> 3); | ||
593 | printk(" eof : %d\n", (ep->command & 0x2) >> 1); | ||
594 | printk(" eol : %d\n", ep->command & 0x1); | ||
595 | printk(" hw_len : 0x%04x (%d)\n", ep->hw_len, ep->hw_len); | ||
596 | printk(" next : 0x%08lx\n", ep->next); | ||
597 | printk(" sub : 0x%08lx\n\n", ep->sub); | ||
598 | } | ||
599 | |||
600 | static inline void __dump_ep_list(int pipe_type) | ||
601 | { | ||
602 | volatile USB_EP_Desc_t *ep; | ||
603 | volatile USB_EP_Desc_t *first_ep; | ||
604 | volatile USB_SB_Desc_t *sb; | ||
605 | |||
606 | switch (pipe_type) | ||
607 | { | ||
608 | case PIPE_BULK: | ||
609 | first_ep = &TxBulkEPList[0]; | ||
610 | break; | ||
611 | case PIPE_CONTROL: | ||
612 | first_ep = &TxCtrlEPList[0]; | ||
613 | break; | ||
614 | case PIPE_INTERRUPT: | ||
615 | first_ep = &TxIntrEPList[0]; | ||
616 | break; | ||
617 | case PIPE_ISOCHRONOUS: | ||
618 | first_ep = &TxIsocEPList[0]; | ||
619 | break; | ||
620 | default: | ||
621 | warn("Cannot dump unknown traffic type"); | ||
622 | return; | ||
623 | } | ||
624 | ep = first_ep; | ||
625 | |||
626 | printk("\n\nDumping EP list...\n\n"); | ||
627 | |||
628 | do { | ||
629 | __dump_ep_desc(ep); | ||
630 | /* Cannot phys_to_virt on 0 as it turns into 80000000, which is != 0. */ | ||
631 | sb = ep->sub ? phys_to_virt(ep->sub) : 0; | ||
632 | while (sb) { | ||
633 | __dump_sb_desc(sb); | ||
634 | sb = sb->next ? phys_to_virt(sb->next) : 0; | ||
635 | } | ||
636 | ep = (volatile USB_EP_Desc_t *)(phys_to_virt(ep->next)); | ||
637 | |||
638 | } while (ep != first_ep); | ||
639 | } | ||
640 | |||
641 | static inline void __dump_ept_data(int epid) | ||
642 | { | ||
643 | unsigned long flags; | ||
644 | __u32 r_usb_ept_data; | ||
645 | |||
646 | if (epid < 0 || epid > 31) { | ||
647 | printk("Cannot dump ept data for invalid epid %d\n", epid); | ||
648 | return; | ||
649 | } | ||
650 | |||
651 | save_flags(flags); | ||
652 | cli(); | ||
653 | *R_USB_EPT_INDEX = IO_FIELD(R_USB_EPT_INDEX, value, epid); | ||
654 | nop(); | ||
655 | r_usb_ept_data = *R_USB_EPT_DATA; | ||
656 | restore_flags(flags); | ||
657 | |||
658 | printk("\nR_USB_EPT_DATA = 0x%x for epid %d :\n", r_usb_ept_data, epid); | ||
659 | if (r_usb_ept_data == 0) { | ||
660 | /* No need for more detailed printing. */ | ||
661 | return; | ||
662 | } | ||
663 | printk(" valid : %d\n", (r_usb_ept_data & 0x80000000) >> 31); | ||
664 | printk(" hold : %d\n", (r_usb_ept_data & 0x40000000) >> 30); | ||
665 | printk(" error_count_in : %d\n", (r_usb_ept_data & 0x30000000) >> 28); | ||
666 | printk(" t_in : %d\n", (r_usb_ept_data & 0x08000000) >> 27); | ||
667 | printk(" low_speed : %d\n", (r_usb_ept_data & 0x04000000) >> 26); | ||
668 | printk(" port : %d\n", (r_usb_ept_data & 0x03000000) >> 24); | ||
669 | printk(" error_code : %d\n", (r_usb_ept_data & 0x00c00000) >> 22); | ||
670 | printk(" t_out : %d\n", (r_usb_ept_data & 0x00200000) >> 21); | ||
671 | printk(" error_count_out : %d\n", (r_usb_ept_data & 0x00180000) >> 19); | ||
672 | printk(" max_len : %d\n", (r_usb_ept_data & 0x0003f800) >> 11); | ||
673 | printk(" ep : %d\n", (r_usb_ept_data & 0x00000780) >> 7); | ||
674 | printk(" dev : %d\n", (r_usb_ept_data & 0x0000003f)); | ||
675 | } | ||
676 | |||
677 | static inline void __dump_ept_data_list(void) | ||
678 | { | ||
679 | int i; | ||
680 | |||
681 | printk("Dumping the whole R_USB_EPT_DATA list\n"); | ||
682 | |||
683 | for (i = 0; i < 32; i++) { | ||
684 | __dump_ept_data(i); | ||
685 | } | ||
686 | } | ||
687 | #ifdef USB_DEBUG_DESC | ||
688 | #define dump_in_desc(...) __dump_in_desc(...) | ||
689 | #define dump_sb_desc(...) __dump_sb_desc(...) | ||
690 | #define dump_ep_desc(...) __dump_ep_desc(...) | ||
691 | #else | ||
692 | #define dump_in_desc(...) do {} while (0) | ||
693 | #define dump_sb_desc(...) do {} while (0) | ||
694 | #define dump_ep_desc(...) do {} while (0) | ||
695 | #endif | ||
696 | |||
697 | #ifdef USB_DEBUG_URB | ||
698 | #define dump_urb(x) __dump_urb(x) | ||
699 | #else | ||
700 | #define dump_urb(x) do {} while (0) | ||
701 | #endif | ||
702 | |||
703 | static void init_rx_buffers(void) | ||
704 | { | ||
705 | int i; | ||
706 | |||
707 | DBFENTER; | ||
708 | |||
709 | for (i = 0; i < (NBR_OF_RX_DESC - 1); i++) { | ||
710 | RxDescList[i].sw_len = RX_DESC_BUF_SIZE; | ||
711 | RxDescList[i].command = 0; | ||
712 | RxDescList[i].next = virt_to_phys(&RxDescList[i + 1]); | ||
713 | RxDescList[i].buf = virt_to_phys(RxBuf + (i * RX_DESC_BUF_SIZE)); | ||
714 | RxDescList[i].hw_len = 0; | ||
715 | RxDescList[i].status = 0; | ||
716 | |||
717 | /* DMA IN cache bug. (struct etrax_dma_descr has the same layout as USB_IN_Desc | ||
718 | for the relevant fields.) */ | ||
719 | prepare_rx_descriptor((struct etrax_dma_descr*)&RxDescList[i]); | ||
720 | |||
721 | } | ||
722 | |||
723 | RxDescList[i].sw_len = RX_DESC_BUF_SIZE; | ||
724 | RxDescList[i].command = IO_STATE(USB_IN_command, eol, yes); | ||
725 | RxDescList[i].next = virt_to_phys(&RxDescList[0]); | ||
726 | RxDescList[i].buf = virt_to_phys(RxBuf + (i * RX_DESC_BUF_SIZE)); | ||
727 | RxDescList[i].hw_len = 0; | ||
728 | RxDescList[i].status = 0; | ||
729 | |||
730 | myNextRxDesc = &RxDescList[0]; | ||
731 | myLastRxDesc = &RxDescList[NBR_OF_RX_DESC - 1]; | ||
732 | myPrevRxDesc = &RxDescList[NBR_OF_RX_DESC - 1]; | ||
733 | |||
734 | *R_DMA_CH9_FIRST = virt_to_phys(myNextRxDesc); | ||
735 | *R_DMA_CH9_CMD = IO_STATE(R_DMA_CH9_CMD, cmd, start); | ||
736 | |||
737 | DBFEXIT; | ||
738 | } | ||
739 | |||
740 | static void init_tx_bulk_ep(void) | ||
741 | { | ||
742 | int i; | ||
743 | |||
744 | DBFENTER; | ||
745 | |||
746 | for (i = 0; i < (NBR_OF_EPIDS - 1); i++) { | ||
747 | CHECK_ALIGN(&TxBulkEPList[i]); | ||
748 | TxBulkEPList[i].hw_len = 0; | ||
749 | TxBulkEPList[i].command = IO_FIELD(USB_EP_command, epid, i); | ||
750 | TxBulkEPList[i].sub = 0; | ||
751 | TxBulkEPList[i].next = virt_to_phys(&TxBulkEPList[i + 1]); | ||
752 | |||
753 | /* Initiate two EPs, disabled and with the eol flag set. No need for any | ||
754 | preserved epid. */ | ||
755 | |||
756 | /* The first one has the intr flag set so we get an interrupt when the DMA | ||
757 | channel is about to become disabled. */ | ||
758 | CHECK_ALIGN(&TxBulkDummyEPList[i][0]); | ||
759 | TxBulkDummyEPList[i][0].hw_len = 0; | ||
760 | TxBulkDummyEPList[i][0].command = (IO_FIELD(USB_EP_command, epid, DUMMY_EPID) | | ||
761 | IO_STATE(USB_EP_command, eol, yes) | | ||
762 | IO_STATE(USB_EP_command, intr, yes)); | ||
763 | TxBulkDummyEPList[i][0].sub = 0; | ||
764 | TxBulkDummyEPList[i][0].next = virt_to_phys(&TxBulkDummyEPList[i][1]); | ||
765 | |||
766 | /* The second one. */ | ||
767 | CHECK_ALIGN(&TxBulkDummyEPList[i][1]); | ||
768 | TxBulkDummyEPList[i][1].hw_len = 0; | ||
769 | TxBulkDummyEPList[i][1].command = (IO_FIELD(USB_EP_command, epid, DUMMY_EPID) | | ||
770 | IO_STATE(USB_EP_command, eol, yes)); | ||
771 | TxBulkDummyEPList[i][1].sub = 0; | ||
772 | /* The last dummy's next pointer is the same as the current EP's next pointer. */ | ||
773 | TxBulkDummyEPList[i][1].next = virt_to_phys(&TxBulkEPList[i + 1]); | ||
774 | } | ||
775 | |||
776 | /* Configure the last one. */ | ||
777 | CHECK_ALIGN(&TxBulkEPList[i]); | ||
778 | TxBulkEPList[i].hw_len = 0; | ||
779 | TxBulkEPList[i].command = (IO_STATE(USB_EP_command, eol, yes) | | ||
780 | IO_FIELD(USB_EP_command, epid, i)); | ||
781 | TxBulkEPList[i].sub = 0; | ||
782 | TxBulkEPList[i].next = virt_to_phys(&TxBulkEPList[0]); | ||
783 | |||
784 | /* No need configuring dummy EPs for the last one as it will never be used for | ||
785 | bulk traffic (i == INVALD_EPID at this point). */ | ||
786 | |||
787 | /* Set up to start on the last EP so we will enable it when inserting traffic | ||
788 | for the first time (imitating the situation where the DMA has stopped | ||
789 | because there was no more traffic). */ | ||
790 | *R_DMA_CH8_SUB0_EP = virt_to_phys(&TxBulkEPList[i]); | ||
791 | /* No point in starting the bulk channel yet. | ||
792 | *R_DMA_CH8_SUB0_CMD = IO_STATE(R_DMA_CH8_SUB0_CMD, cmd, start); */ | ||
793 | DBFEXIT; | ||
794 | } | ||
795 | |||
796 | static void init_tx_ctrl_ep(void) | ||
797 | { | ||
798 | int i; | ||
799 | |||
800 | DBFENTER; | ||
801 | |||
802 | for (i = 0; i < (NBR_OF_EPIDS - 1); i++) { | ||
803 | CHECK_ALIGN(&TxCtrlEPList[i]); | ||
804 | TxCtrlEPList[i].hw_len = 0; | ||
805 | TxCtrlEPList[i].command = IO_FIELD(USB_EP_command, epid, i); | ||
806 | TxCtrlEPList[i].sub = 0; | ||
807 | TxCtrlEPList[i].next = virt_to_phys(&TxCtrlEPList[i + 1]); | ||
808 | } | ||
809 | |||
810 | CHECK_ALIGN(&TxCtrlEPList[i]); | ||
811 | TxCtrlEPList[i].hw_len = 0; | ||
812 | TxCtrlEPList[i].command = (IO_STATE(USB_EP_command, eol, yes) | | ||
813 | IO_FIELD(USB_EP_command, epid, i)); | ||
814 | |||
815 | TxCtrlEPList[i].sub = 0; | ||
816 | TxCtrlEPList[i].next = virt_to_phys(&TxCtrlEPList[0]); | ||
817 | |||
818 | *R_DMA_CH8_SUB1_EP = virt_to_phys(&TxCtrlEPList[0]); | ||
819 | *R_DMA_CH8_SUB1_CMD = IO_STATE(R_DMA_CH8_SUB1_CMD, cmd, start); | ||
820 | |||
821 | DBFEXIT; | ||
822 | } | ||
823 | |||
824 | |||
825 | static void init_tx_intr_ep(void) | ||
826 | { | ||
827 | int i; | ||
828 | |||
829 | DBFENTER; | ||
830 | |||
831 | /* Read comment at zout_buffer declaration for an explanation to this. */ | ||
832 | TxIntrSB_zout.sw_len = 1; | ||
833 | TxIntrSB_zout.next = 0; | ||
834 | TxIntrSB_zout.buf = virt_to_phys(&zout_buffer[0]); | ||
835 | TxIntrSB_zout.command = (IO_FIELD(USB_SB_command, rem, 0) | | ||
836 | IO_STATE(USB_SB_command, tt, zout) | | ||
837 | IO_STATE(USB_SB_command, full, yes) | | ||
838 | IO_STATE(USB_SB_command, eot, yes) | | ||
839 | IO_STATE(USB_SB_command, eol, yes)); | ||
840 | |||
841 | for (i = 0; i < (MAX_INTR_INTERVAL - 1); i++) { | ||
842 | CHECK_ALIGN(&TxIntrEPList[i]); | ||
843 | TxIntrEPList[i].hw_len = 0; | ||
844 | TxIntrEPList[i].command = | ||
845 | (IO_STATE(USB_EP_command, eof, yes) | | ||
846 | IO_STATE(USB_EP_command, enable, yes) | | ||
847 | IO_FIELD(USB_EP_command, epid, INVALID_EPID)); | ||
848 | TxIntrEPList[i].sub = virt_to_phys(&TxIntrSB_zout); | ||
849 | TxIntrEPList[i].next = virt_to_phys(&TxIntrEPList[i + 1]); | ||
850 | } | ||
851 | |||
852 | CHECK_ALIGN(&TxIntrEPList[i]); | ||
853 | TxIntrEPList[i].hw_len = 0; | ||
854 | TxIntrEPList[i].command = | ||
855 | (IO_STATE(USB_EP_command, eof, yes) | | ||
856 | IO_STATE(USB_EP_command, eol, yes) | | ||
857 | IO_STATE(USB_EP_command, enable, yes) | | ||
858 | IO_FIELD(USB_EP_command, epid, INVALID_EPID)); | ||
859 | TxIntrEPList[i].sub = virt_to_phys(&TxIntrSB_zout); | ||
860 | TxIntrEPList[i].next = virt_to_phys(&TxIntrEPList[0]); | ||
861 | |||
862 | *R_DMA_CH8_SUB2_EP = virt_to_phys(&TxIntrEPList[0]); | ||
863 | *R_DMA_CH8_SUB2_CMD = IO_STATE(R_DMA_CH8_SUB2_CMD, cmd, start); | ||
864 | DBFEXIT; | ||
865 | } | ||
866 | |||
867 | static void init_tx_isoc_ep(void) | ||
868 | { | ||
869 | int i; | ||
870 | |||
871 | DBFENTER; | ||
872 | |||
873 | /* Read comment at zout_buffer declaration for an explanation to this. */ | ||
874 | TxIsocSB_zout.sw_len = 1; | ||
875 | TxIsocSB_zout.next = 0; | ||
876 | TxIsocSB_zout.buf = virt_to_phys(&zout_buffer[0]); | ||
877 | TxIsocSB_zout.command = (IO_FIELD(USB_SB_command, rem, 0) | | ||
878 | IO_STATE(USB_SB_command, tt, zout) | | ||
879 | IO_STATE(USB_SB_command, full, yes) | | ||
880 | IO_STATE(USB_SB_command, eot, yes) | | ||
881 | IO_STATE(USB_SB_command, eol, yes)); | ||
882 | |||
883 | /* The last isochronous EP descriptor is a dummy. */ | ||
884 | |||
885 | for (i = 0; i < (NBR_OF_EPIDS - 1); i++) { | ||
886 | CHECK_ALIGN(&TxIsocEPList[i]); | ||
887 | TxIsocEPList[i].hw_len = 0; | ||
888 | TxIsocEPList[i].command = IO_FIELD(USB_EP_command, epid, i); | ||
889 | TxIsocEPList[i].sub = 0; | ||
890 | TxIsocEPList[i].next = virt_to_phys(&TxIsocEPList[i + 1]); | ||
891 | } | ||
892 | |||
893 | CHECK_ALIGN(&TxIsocEPList[i]); | ||
894 | TxIsocEPList[i].hw_len = 0; | ||
895 | |||
896 | /* Must enable the last EP descr to get eof interrupt. */ | ||
897 | TxIsocEPList[i].command = (IO_STATE(USB_EP_command, enable, yes) | | ||
898 | IO_STATE(USB_EP_command, eof, yes) | | ||
899 | IO_STATE(USB_EP_command, eol, yes) | | ||
900 | IO_FIELD(USB_EP_command, epid, INVALID_EPID)); | ||
901 | TxIsocEPList[i].sub = virt_to_phys(&TxIsocSB_zout); | ||
902 | TxIsocEPList[i].next = virt_to_phys(&TxIsocEPList[0]); | ||
903 | |||
904 | *R_DMA_CH8_SUB3_EP = virt_to_phys(&TxIsocEPList[0]); | ||
905 | *R_DMA_CH8_SUB3_CMD = IO_STATE(R_DMA_CH8_SUB3_CMD, cmd, start); | ||
906 | |||
907 | DBFEXIT; | ||
908 | } | ||
909 | |||
910 | static void etrax_usb_unlink_intr_urb(struct urb *urb) | ||
911 | { | ||
912 | volatile USB_EP_Desc_t *first_ep; /* First EP in the list. */ | ||
913 | volatile USB_EP_Desc_t *curr_ep; /* Current EP, the iterator. */ | ||
914 | volatile USB_EP_Desc_t *next_ep; /* The EP after current. */ | ||
915 | volatile USB_EP_Desc_t *unlink_ep; /* The one we should remove from the list. */ | ||
916 | |||
917 | int epid; | ||
918 | |||
919 | /* Read 8.8.4 in Designer's Reference, "Removing an EP Descriptor from the List". */ | ||
920 | |||
921 | DBFENTER; | ||
922 | |||
923 | epid = ((etrax_urb_priv_t *)urb->hcpriv)->epid; | ||
924 | |||
925 | first_ep = &TxIntrEPList[0]; | ||
926 | curr_ep = first_ep; | ||
927 | |||
928 | |||
929 | /* Note that this loop removes all EP descriptors with this epid. This assumes | ||
930 | that all EP descriptors belong to the one and only urb for this epid. */ | ||
931 | |||
932 | do { | ||
933 | next_ep = (USB_EP_Desc_t *)phys_to_virt(curr_ep->next); | ||
934 | |||
935 | if (IO_EXTRACT(USB_EP_command, epid, next_ep->command) == epid) { | ||
936 | |||
937 | dbg_intr("Found EP to unlink for epid %d", epid); | ||
938 | |||
939 | /* This is the one we should unlink. */ | ||
940 | unlink_ep = next_ep; | ||
941 | |||
942 | /* Actually unlink the EP from the DMA list. */ | ||
943 | curr_ep->next = unlink_ep->next; | ||
944 | |||
945 | /* Wait until the DMA is no longer at this descriptor. */ | ||
946 | while (*R_DMA_CH8_SUB2_EP == virt_to_phys(unlink_ep)); | ||
947 | |||
948 | /* Now we are free to remove it and its SB descriptor. | ||
949 | Note that it is assumed here that there is only one sb in the | ||
950 | sb list for this ep. */ | ||
951 | kmem_cache_free(usb_desc_cache, phys_to_virt(unlink_ep->sub)); | ||
952 | kmem_cache_free(usb_desc_cache, (USB_EP_Desc_t *)unlink_ep); | ||
953 | } | ||
954 | |||
955 | curr_ep = phys_to_virt(curr_ep->next); | ||
956 | |||
957 | } while (curr_ep != first_ep); | ||
958 | urb->hcpriv = NULL; | ||
959 | } | ||
960 | |||
961 | void etrax_usb_do_intr_recover(int epid) | ||
962 | { | ||
963 | USB_EP_Desc_t *first_ep, *tmp_ep; | ||
964 | |||
965 | DBFENTER; | ||
966 | |||
967 | first_ep = (USB_EP_Desc_t *)phys_to_virt(*R_DMA_CH8_SUB2_EP); | ||
968 | tmp_ep = first_ep; | ||
969 | |||
970 | /* What this does is simply to walk the list of interrupt | ||
971 | ep descriptors and enable those that are disabled. */ | ||
972 | |||
973 | do { | ||
974 | if (IO_EXTRACT(USB_EP_command, epid, tmp_ep->command) == epid && | ||
975 | !(tmp_ep->command & IO_MASK(USB_EP_command, enable))) { | ||
976 | tmp_ep->command |= IO_STATE(USB_EP_command, enable, yes); | ||
977 | } | ||
978 | |||
979 | tmp_ep = (USB_EP_Desc_t *)phys_to_virt(tmp_ep->next); | ||
980 | |||
981 | } while (tmp_ep != first_ep); | ||
982 | |||
983 | |||
984 | DBFEXIT; | ||
985 | } | ||
986 | |||
987 | static int etrax_rh_unlink_urb (struct urb *urb) | ||
988 | { | ||
989 | etrax_hc_t *hc; | ||
990 | |||
991 | DBFENTER; | ||
992 | |||
993 | hc = urb->dev->bus->hcpriv; | ||
994 | |||
995 | if (hc->rh.urb == urb) { | ||
996 | hc->rh.send = 0; | ||
997 | del_timer(&hc->rh.rh_int_timer); | ||
998 | } | ||
999 | |||
1000 | DBFEXIT; | ||
1001 | return 0; | ||
1002 | } | ||
1003 | |||
1004 | static void etrax_rh_send_irq(struct urb *urb) | ||
1005 | { | ||
1006 | __u16 data = 0; | ||
1007 | etrax_hc_t *hc = urb->dev->bus->hcpriv; | ||
1008 | DBFENTER; | ||
1009 | |||
1010 | /* | ||
1011 | dbg_rh("R_USB_FM_NUMBER : 0x%08X", *R_USB_FM_NUMBER); | ||
1012 | dbg_rh("R_USB_FM_REMAINING: 0x%08X", *R_USB_FM_REMAINING); | ||
1013 | */ | ||
1014 | |||
1015 | data |= (hc->rh.wPortChange_1) ? (1 << 1) : 0; | ||
1016 | data |= (hc->rh.wPortChange_2) ? (1 << 2) : 0; | ||
1017 | |||
1018 | *((__u16 *)urb->transfer_buffer) = cpu_to_le16(data); | ||
1019 | /* FIXME: Why is actual_length set to 1 when data is 2 bytes? | ||
1020 | Since only 1 byte is used, why not declare data as __u8? */ | ||
1021 | urb->actual_length = 1; | ||
1022 | urb->status = 0; | ||
1023 | |||
1024 | if (hc->rh.send && urb->complete) { | ||
1025 | dbg_rh("wPortChange_1: 0x%04X", hc->rh.wPortChange_1); | ||
1026 | dbg_rh("wPortChange_2: 0x%04X", hc->rh.wPortChange_2); | ||
1027 | |||
1028 | urb->complete(urb, NULL); | ||
1029 | } | ||
1030 | |||
1031 | DBFEXIT; | ||
1032 | } | ||
1033 | |||
1034 | static void etrax_rh_init_int_timer(struct urb *urb) | ||
1035 | { | ||
1036 | etrax_hc_t *hc; | ||
1037 | |||
1038 | DBFENTER; | ||
1039 | |||
1040 | hc = urb->dev->bus->hcpriv; | ||
1041 | hc->rh.interval = urb->interval; | ||
1042 | init_timer(&hc->rh.rh_int_timer); | ||
1043 | hc->rh.rh_int_timer.function = etrax_rh_int_timer_do; | ||
1044 | hc->rh.rh_int_timer.data = (unsigned long)urb; | ||
1045 | /* FIXME: Is the jiffies resolution enough? All intervals < 10 ms will be mapped | ||
1046 | to 0, and the rest to the nearest lower 10 ms. */ | ||
1047 | hc->rh.rh_int_timer.expires = jiffies + ((HZ * hc->rh.interval) / 1000); | ||
1048 | add_timer(&hc->rh.rh_int_timer); | ||
1049 | |||
1050 | DBFEXIT; | ||
1051 | } | ||
1052 | |||
1053 | static void etrax_rh_int_timer_do(unsigned long ptr) | ||
1054 | { | ||
1055 | struct urb *urb; | ||
1056 | etrax_hc_t *hc; | ||
1057 | |||
1058 | DBFENTER; | ||
1059 | |||
1060 | urb = (struct urb*)ptr; | ||
1061 | hc = urb->dev->bus->hcpriv; | ||
1062 | |||
1063 | if (hc->rh.send) { | ||
1064 | etrax_rh_send_irq(urb); | ||
1065 | } | ||
1066 | |||
1067 | DBFEXIT; | ||
1068 | } | ||
1069 | |||
1070 | static int etrax_usb_setup_epid(struct urb *urb) | ||
1071 | { | ||
1072 | int epid; | ||
1073 | char devnum, endpoint, out_traffic, slow; | ||
1074 | int maxlen; | ||
1075 | unsigned long flags; | ||
1076 | |||
1077 | DBFENTER; | ||
1078 | |||
1079 | epid = etrax_usb_lookup_epid(urb); | ||
1080 | if ((epid != -1)){ | ||
1081 | /* An epid that fits this urb has been found. */ | ||
1082 | DBFEXIT; | ||
1083 | return epid; | ||
1084 | } | ||
1085 | |||
1086 | /* We must find and initiate a new epid for this urb. */ | ||
1087 | epid = etrax_usb_allocate_epid(); | ||
1088 | |||
1089 | if (epid == -1) { | ||
1090 | /* Failed to allocate a new epid. */ | ||
1091 | DBFEXIT; | ||
1092 | return epid; | ||
1093 | } | ||
1094 | |||
1095 | /* We now have a new epid to use. Initiate it. */ | ||
1096 | set_bit(epid, (void *)&epid_usage_bitmask); | ||
1097 | |||
1098 | devnum = usb_pipedevice(urb->pipe); | ||
1099 | endpoint = usb_pipeendpoint(urb->pipe); | ||
1100 | slow = usb_pipeslow(urb->pipe); | ||
1101 | maxlen = usb_maxpacket(urb->dev, urb->pipe, usb_pipeout(urb->pipe)); | ||
1102 | if (usb_pipetype(urb->pipe) == PIPE_CONTROL) { | ||
1103 | /* We want both IN and OUT control traffic to be put on the same EP/SB list. */ | ||
1104 | out_traffic = 1; | ||
1105 | } else { | ||
1106 | out_traffic = usb_pipeout(urb->pipe); | ||
1107 | } | ||
1108 | |||
1109 | save_flags(flags); | ||
1110 | cli(); | ||
1111 | |||
1112 | *R_USB_EPT_INDEX = IO_FIELD(R_USB_EPT_INDEX, value, epid); | ||
1113 | nop(); | ||
1114 | |||
1115 | if (usb_pipetype(urb->pipe) == PIPE_ISOCHRONOUS) { | ||
1116 | *R_USB_EPT_DATA_ISO = IO_STATE(R_USB_EPT_DATA_ISO, valid, yes) | | ||
1117 | /* FIXME: Change any to the actual port? */ | ||
1118 | IO_STATE(R_USB_EPT_DATA_ISO, port, any) | | ||
1119 | IO_FIELD(R_USB_EPT_DATA_ISO, max_len, maxlen) | | ||
1120 | IO_FIELD(R_USB_EPT_DATA_ISO, ep, endpoint) | | ||
1121 | IO_FIELD(R_USB_EPT_DATA_ISO, dev, devnum); | ||
1122 | } else { | ||
1123 | *R_USB_EPT_DATA = IO_STATE(R_USB_EPT_DATA, valid, yes) | | ||
1124 | IO_FIELD(R_USB_EPT_DATA, low_speed, slow) | | ||
1125 | /* FIXME: Change any to the actual port? */ | ||
1126 | IO_STATE(R_USB_EPT_DATA, port, any) | | ||
1127 | IO_FIELD(R_USB_EPT_DATA, max_len, maxlen) | | ||
1128 | IO_FIELD(R_USB_EPT_DATA, ep, endpoint) | | ||
1129 | IO_FIELD(R_USB_EPT_DATA, dev, devnum); | ||
1130 | } | ||
1131 | |||
1132 | restore_flags(flags); | ||
1133 | |||
1134 | if (out_traffic) { | ||
1135 | set_bit(epid, (void *)&epid_out_traffic); | ||
1136 | } else { | ||
1137 | clear_bit(epid, (void *)&epid_out_traffic); | ||
1138 | } | ||
1139 | |||
1140 | dbg_epid("Setting up epid %d with devnum %d, endpoint %d and max_len %d (%s)", | ||
1141 | epid, devnum, endpoint, maxlen, out_traffic ? "OUT" : "IN"); | ||
1142 | |||
1143 | DBFEXIT; | ||
1144 | return epid; | ||
1145 | } | ||
1146 | |||
1147 | static void etrax_usb_free_epid(int epid) | ||
1148 | { | ||
1149 | unsigned long flags; | ||
1150 | |||
1151 | DBFENTER; | ||
1152 | |||
1153 | if (!test_bit(epid, (void *)&epid_usage_bitmask)) { | ||
1154 | warn("Trying to free unused epid %d", epid); | ||
1155 | DBFEXIT; | ||
1156 | return; | ||
1157 | } | ||
1158 | |||
1159 | save_flags(flags); | ||
1160 | cli(); | ||
1161 | |||
1162 | *R_USB_EPT_INDEX = IO_FIELD(R_USB_EPT_INDEX, value, epid); | ||
1163 | nop(); | ||
1164 | while (*R_USB_EPT_DATA & IO_MASK(R_USB_EPT_DATA, hold)); | ||
1165 | /* This will, among other things, set the valid field to 0. */ | ||
1166 | *R_USB_EPT_DATA = 0; | ||
1167 | restore_flags(flags); | ||
1168 | |||
1169 | clear_bit(epid, (void *)&epid_usage_bitmask); | ||
1170 | |||
1171 | |||
1172 | dbg_epid("Freed epid %d", epid); | ||
1173 | |||
1174 | DBFEXIT; | ||
1175 | } | ||
1176 | |||
1177 | static int etrax_usb_lookup_epid(struct urb *urb) | ||
1178 | { | ||
1179 | int i; | ||
1180 | __u32 data; | ||
1181 | char devnum, endpoint, slow, out_traffic; | ||
1182 | int maxlen; | ||
1183 | unsigned long flags; | ||
1184 | |||
1185 | DBFENTER; | ||
1186 | |||
1187 | devnum = usb_pipedevice(urb->pipe); | ||
1188 | endpoint = usb_pipeendpoint(urb->pipe); | ||
1189 | slow = usb_pipeslow(urb->pipe); | ||
1190 | maxlen = usb_maxpacket(urb->dev, urb->pipe, usb_pipeout(urb->pipe)); | ||
1191 | if (usb_pipetype(urb->pipe) == PIPE_CONTROL) { | ||
1192 | /* We want both IN and OUT control traffic to be put on the same EP/SB list. */ | ||
1193 | out_traffic = 1; | ||
1194 | } else { | ||
1195 | out_traffic = usb_pipeout(urb->pipe); | ||
1196 | } | ||
1197 | |||
1198 | /* Step through att epids. */ | ||
1199 | for (i = 0; i < NBR_OF_EPIDS; i++) { | ||
1200 | if (test_bit(i, (void *)&epid_usage_bitmask) && | ||
1201 | test_bit(i, (void *)&epid_out_traffic) == out_traffic) { | ||
1202 | |||
1203 | save_flags(flags); | ||
1204 | cli(); | ||
1205 | *R_USB_EPT_INDEX = IO_FIELD(R_USB_EPT_INDEX, value, i); | ||
1206 | nop(); | ||
1207 | |||
1208 | if (usb_pipetype(urb->pipe) == PIPE_ISOCHRONOUS) { | ||
1209 | data = *R_USB_EPT_DATA_ISO; | ||
1210 | restore_flags(flags); | ||
1211 | |||
1212 | if ((IO_MASK(R_USB_EPT_DATA_ISO, valid) & data) && | ||
1213 | (IO_EXTRACT(R_USB_EPT_DATA_ISO, dev, data) == devnum) && | ||
1214 | (IO_EXTRACT(R_USB_EPT_DATA_ISO, ep, data) == endpoint) && | ||
1215 | (IO_EXTRACT(R_USB_EPT_DATA_ISO, max_len, data) == maxlen)) { | ||
1216 | dbg_epid("Found epid %d for devnum %d, endpoint %d (%s)", | ||
1217 | i, devnum, endpoint, out_traffic ? "OUT" : "IN"); | ||
1218 | DBFEXIT; | ||
1219 | return i; | ||
1220 | } | ||
1221 | } else { | ||
1222 | data = *R_USB_EPT_DATA; | ||
1223 | restore_flags(flags); | ||
1224 | |||
1225 | if ((IO_MASK(R_USB_EPT_DATA, valid) & data) && | ||
1226 | (IO_EXTRACT(R_USB_EPT_DATA, dev, data) == devnum) && | ||
1227 | (IO_EXTRACT(R_USB_EPT_DATA, ep, data) == endpoint) && | ||
1228 | (IO_EXTRACT(R_USB_EPT_DATA, low_speed, data) == slow) && | ||
1229 | (IO_EXTRACT(R_USB_EPT_DATA, max_len, data) == maxlen)) { | ||
1230 | dbg_epid("Found epid %d for devnum %d, endpoint %d (%s)", | ||
1231 | i, devnum, endpoint, out_traffic ? "OUT" : "IN"); | ||
1232 | DBFEXIT; | ||
1233 | return i; | ||
1234 | } | ||
1235 | } | ||
1236 | } | ||
1237 | } | ||
1238 | |||
1239 | DBFEXIT; | ||
1240 | return -1; | ||
1241 | } | ||
1242 | |||
1243 | static int etrax_usb_allocate_epid(void) | ||
1244 | { | ||
1245 | int i; | ||
1246 | |||
1247 | DBFENTER; | ||
1248 | |||
1249 | for (i = 0; i < NBR_OF_EPIDS; i++) { | ||
1250 | if (!test_bit(i, (void *)&epid_usage_bitmask)) { | ||
1251 | dbg_epid("Found free epid %d", i); | ||
1252 | DBFEXIT; | ||
1253 | return i; | ||
1254 | } | ||
1255 | } | ||
1256 | |||
1257 | dbg_epid("Found no free epids"); | ||
1258 | DBFEXIT; | ||
1259 | return -1; | ||
1260 | } | ||
1261 | |||
1262 | static int etrax_usb_submit_urb(struct urb *urb, unsigned mem_flags) | ||
1263 | { | ||
1264 | etrax_hc_t *hc; | ||
1265 | int ret = -EINVAL; | ||
1266 | |||
1267 | DBFENTER; | ||
1268 | |||
1269 | if (!urb->dev || !urb->dev->bus) { | ||
1270 | return -ENODEV; | ||
1271 | } | ||
1272 | if (usb_maxpacket(urb->dev, urb->pipe, usb_pipeout(urb->pipe)) <= 0) { | ||
1273 | info("Submit urb to pipe with maxpacketlen 0, pipe 0x%X\n", urb->pipe); | ||
1274 | return -EMSGSIZE; | ||
1275 | } | ||
1276 | |||
1277 | if (urb->timeout) { | ||
1278 | /* FIXME. */ | ||
1279 | warn("urb->timeout specified, ignoring."); | ||
1280 | } | ||
1281 | |||
1282 | hc = (etrax_hc_t*)urb->dev->bus->hcpriv; | ||
1283 | |||
1284 | if (usb_pipedevice(urb->pipe) == hc->rh.devnum) { | ||
1285 | /* This request is for the Virtual Root Hub. */ | ||
1286 | ret = etrax_rh_submit_urb(urb); | ||
1287 | |||
1288 | } else if (usb_pipetype(urb->pipe) == PIPE_BULK) { | ||
1289 | |||
1290 | ret = etrax_usb_submit_bulk_urb(urb); | ||
1291 | |||
1292 | } else if (usb_pipetype(urb->pipe) == PIPE_CONTROL) { | ||
1293 | |||
1294 | ret = etrax_usb_submit_ctrl_urb(urb); | ||
1295 | |||
1296 | } else if (usb_pipetype(urb->pipe) == PIPE_INTERRUPT) { | ||
1297 | int bustime; | ||
1298 | |||
1299 | if (urb->bandwidth == 0) { | ||
1300 | bustime = usb_check_bandwidth(urb->dev, urb); | ||
1301 | if (bustime < 0) { | ||
1302 | ret = bustime; | ||
1303 | } else { | ||
1304 | ret = etrax_usb_submit_intr_urb(urb); | ||
1305 | if (ret == 0) | ||
1306 | usb_claim_bandwidth(urb->dev, urb, bustime, 0); | ||
1307 | } | ||
1308 | } else { | ||
1309 | /* Bandwidth already set. */ | ||
1310 | ret = etrax_usb_submit_intr_urb(urb); | ||
1311 | } | ||
1312 | |||
1313 | } else if (usb_pipetype(urb->pipe) == PIPE_ISOCHRONOUS) { | ||
1314 | int bustime; | ||
1315 | |||
1316 | if (urb->bandwidth == 0) { | ||
1317 | bustime = usb_check_bandwidth(urb->dev, urb); | ||
1318 | if (bustime < 0) { | ||
1319 | ret = bustime; | ||
1320 | } else { | ||
1321 | ret = etrax_usb_submit_isoc_urb(urb); | ||
1322 | if (ret == 0) | ||
1323 | usb_claim_bandwidth(urb->dev, urb, bustime, 0); | ||
1324 | } | ||
1325 | } else { | ||
1326 | /* Bandwidth already set. */ | ||
1327 | ret = etrax_usb_submit_isoc_urb(urb); | ||
1328 | } | ||
1329 | } | ||
1330 | |||
1331 | DBFEXIT; | ||
1332 | |||
1333 | if (ret != 0) | ||
1334 | printk("Submit URB error %d\n", ret); | ||
1335 | |||
1336 | return ret; | ||
1337 | } | ||
1338 | |||
1339 | static int etrax_usb_unlink_urb(struct urb *urb, int status) | ||
1340 | { | ||
1341 | etrax_hc_t *hc; | ||
1342 | etrax_urb_priv_t *urb_priv; | ||
1343 | int epid; | ||
1344 | unsigned int flags; | ||
1345 | |||
1346 | DBFENTER; | ||
1347 | |||
1348 | if (!urb) { | ||
1349 | return -EINVAL; | ||
1350 | } | ||
1351 | |||
1352 | /* Disable interrupts here since a descriptor interrupt for the isoc epid | ||
1353 | will modify the sb list. This could possibly be done more granular, but | ||
1354 | unlink_urb should not be used frequently anyway. | ||
1355 | */ | ||
1356 | |||
1357 | save_flags(flags); | ||
1358 | cli(); | ||
1359 | |||
1360 | if (!urb->dev || !urb->dev->bus) { | ||
1361 | restore_flags(flags); | ||
1362 | return -ENODEV; | ||
1363 | } | ||
1364 | if (!urb->hcpriv) { | ||
1365 | /* This happens if a device driver calls unlink on an urb that | ||
1366 | was never submitted (lazy driver) or if the urb was completed | ||
1367 | while unlink was being called. */ | ||
1368 | restore_flags(flags); | ||
1369 | return 0; | ||
1370 | } | ||
1371 | if (urb->transfer_flags & URB_ASYNC_UNLINK) { | ||
1372 | /* FIXME. */ | ||
1373 | /* If URB_ASYNC_UNLINK is set: | ||
1374 | unlink | ||
1375 | move to a separate urb list | ||
1376 | call complete at next sof with ECONNRESET | ||
1377 | |||
1378 | If not: | ||
1379 | wait 1 ms | ||
1380 | unlink | ||
1381 | call complete with ENOENT | ||
1382 | */ | ||
1383 | warn("URB_ASYNC_UNLINK set, ignoring."); | ||
1384 | } | ||
1385 | |||
1386 | /* One might think that urb->status = -EINPROGRESS would be a requirement for unlinking, | ||
1387 | but that doesn't work for interrupt and isochronous traffic since they are completed | ||
1388 | repeatedly, and urb->status is set then. That may in itself be a bug though. */ | ||
1389 | |||
1390 | hc = urb->dev->bus->hcpriv; | ||
1391 | urb_priv = (etrax_urb_priv_t *)urb->hcpriv; | ||
1392 | epid = urb_priv->epid; | ||
1393 | |||
1394 | /* Set the urb status (synchronous unlink). */ | ||
1395 | urb->status = -ENOENT; | ||
1396 | urb_priv->urb_state = UNLINK; | ||
1397 | |||
1398 | if (usb_pipedevice(urb->pipe) == hc->rh.devnum) { | ||
1399 | int ret; | ||
1400 | ret = etrax_rh_unlink_urb(urb); | ||
1401 | DBFEXIT; | ||
1402 | restore_flags(flags); | ||
1403 | return ret; | ||
1404 | |||
1405 | } else if (usb_pipetype(urb->pipe) == PIPE_BULK) { | ||
1406 | |||
1407 | dbg_bulk("Unlink of bulk urb (0x%lx)", (unsigned long)urb); | ||
1408 | |||
1409 | if (TxBulkEPList[epid].command & IO_MASK(USB_EP_command, enable)) { | ||
1410 | /* The EP was enabled, disable it and wait. */ | ||
1411 | TxBulkEPList[epid].command &= ~IO_MASK(USB_EP_command, enable); | ||
1412 | |||
1413 | /* Ah, the luxury of busy-wait. */ | ||
1414 | while (*R_DMA_CH8_SUB0_EP == virt_to_phys(&TxBulkEPList[epid])); | ||
1415 | } | ||
1416 | /* Kicking dummy list out of the party. */ | ||
1417 | TxBulkEPList[epid].next = virt_to_phys(&TxBulkEPList[(epid + 1) % NBR_OF_EPIDS]); | ||
1418 | |||
1419 | } else if (usb_pipetype(urb->pipe) == PIPE_CONTROL) { | ||
1420 | |||
1421 | dbg_ctrl("Unlink of ctrl urb (0x%lx)", (unsigned long)urb); | ||
1422 | |||
1423 | if (TxCtrlEPList[epid].command & IO_MASK(USB_EP_command, enable)) { | ||
1424 | /* The EP was enabled, disable it and wait. */ | ||
1425 | TxCtrlEPList[epid].command &= ~IO_MASK(USB_EP_command, enable); | ||
1426 | |||
1427 | /* Ah, the luxury of busy-wait. */ | ||
1428 | while (*R_DMA_CH8_SUB1_EP == virt_to_phys(&TxCtrlEPList[epid])); | ||
1429 | } | ||
1430 | |||
1431 | } else if (usb_pipetype(urb->pipe) == PIPE_INTERRUPT) { | ||
1432 | |||
1433 | dbg_intr("Unlink of intr urb (0x%lx)", (unsigned long)urb); | ||
1434 | |||
1435 | /* Separate function because it's a tad more complicated. */ | ||
1436 | etrax_usb_unlink_intr_urb(urb); | ||
1437 | |||
1438 | } else if (usb_pipetype(urb->pipe) == PIPE_ISOCHRONOUS) { | ||
1439 | |||
1440 | dbg_isoc("Unlink of isoc urb (0x%lx)", (unsigned long)urb); | ||
1441 | |||
1442 | if (TxIsocEPList[epid].command & IO_MASK(USB_EP_command, enable)) { | ||
1443 | /* The EP was enabled, disable it and wait. */ | ||
1444 | TxIsocEPList[epid].command &= ~IO_MASK(USB_EP_command, enable); | ||
1445 | |||
1446 | /* Ah, the luxury of busy-wait. */ | ||
1447 | while (*R_DMA_CH8_SUB3_EP == virt_to_phys(&TxIsocEPList[epid])); | ||
1448 | } | ||
1449 | } | ||
1450 | |||
1451 | /* Note that we need to remove the urb from the urb list *before* removing its SB | ||
1452 | descriptors. (This means that the isoc eof handler might get a null urb when we | ||
1453 | are unlinking the last urb.) */ | ||
1454 | |||
1455 | if (usb_pipetype(urb->pipe) == PIPE_BULK) { | ||
1456 | |||
1457 | urb_list_del(urb, epid); | ||
1458 | TxBulkEPList[epid].sub = 0; | ||
1459 | etrax_remove_from_sb_list(urb); | ||
1460 | |||
1461 | } else if (usb_pipetype(urb->pipe) == PIPE_CONTROL) { | ||
1462 | |||
1463 | urb_list_del(urb, epid); | ||
1464 | TxCtrlEPList[epid].sub = 0; | ||
1465 | etrax_remove_from_sb_list(urb); | ||
1466 | |||
1467 | } else if (usb_pipetype(urb->pipe) == PIPE_INTERRUPT) { | ||
1468 | |||
1469 | urb_list_del(urb, epid); | ||
1470 | /* Sanity check (should never happen). */ | ||
1471 | assert(urb_list_empty(epid)); | ||
1472 | |||
1473 | /* Release allocated bandwidth. */ | ||
1474 | usb_release_bandwidth(urb->dev, urb, 0); | ||
1475 | |||
1476 | } else if (usb_pipetype(urb->pipe) == PIPE_ISOCHRONOUS) { | ||
1477 | |||
1478 | if (usb_pipeout(urb->pipe)) { | ||
1479 | |||
1480 | USB_SB_Desc_t *iter_sb, *prev_sb, *next_sb; | ||
1481 | |||
1482 | if (__urb_list_entry(urb, epid)) { | ||
1483 | |||
1484 | urb_list_del(urb, epid); | ||
1485 | iter_sb = TxIsocEPList[epid].sub ? phys_to_virt(TxIsocEPList[epid].sub) : 0; | ||
1486 | prev_sb = 0; | ||
1487 | while (iter_sb && (iter_sb != urb_priv->first_sb)) { | ||
1488 | prev_sb = iter_sb; | ||
1489 | iter_sb = iter_sb->next ? phys_to_virt(iter_sb->next) : 0; | ||
1490 | } | ||
1491 | |||
1492 | if (iter_sb == 0) { | ||
1493 | /* Unlink of the URB currently being transmitted. */ | ||
1494 | prev_sb = 0; | ||
1495 | iter_sb = TxIsocEPList[epid].sub ? phys_to_virt(TxIsocEPList[epid].sub) : 0; | ||
1496 | } | ||
1497 | |||
1498 | while (iter_sb && (iter_sb != urb_priv->last_sb)) { | ||
1499 | iter_sb = iter_sb->next ? phys_to_virt(iter_sb->next) : 0; | ||
1500 | } | ||
1501 | if (iter_sb) { | ||
1502 | next_sb = iter_sb->next ? phys_to_virt(iter_sb->next) : 0; | ||
1503 | } else { | ||
1504 | /* This should only happen if the DMA has completed | ||
1505 | processing the SB list for this EP while interrupts | ||
1506 | are disabled. */ | ||
1507 | dbg_isoc("Isoc urb not found, already sent?"); | ||
1508 | next_sb = 0; | ||
1509 | } | ||
1510 | if (prev_sb) { | ||
1511 | prev_sb->next = next_sb ? virt_to_phys(next_sb) : 0; | ||
1512 | } else { | ||
1513 | TxIsocEPList[epid].sub = next_sb ? virt_to_phys(next_sb) : 0; | ||
1514 | } | ||
1515 | |||
1516 | etrax_remove_from_sb_list(urb); | ||
1517 | if (urb_list_empty(epid)) { | ||
1518 | TxIsocEPList[epid].sub = 0; | ||
1519 | dbg_isoc("Last isoc out urb epid %d", epid); | ||
1520 | } else if (next_sb || prev_sb) { | ||
1521 | dbg_isoc("Re-enable isoc out epid %d", epid); | ||
1522 | |||
1523 | TxIsocEPList[epid].hw_len = 0; | ||
1524 | TxIsocEPList[epid].command |= IO_STATE(USB_EP_command, enable, yes); | ||
1525 | } else { | ||
1526 | TxIsocEPList[epid].sub = 0; | ||
1527 | dbg_isoc("URB list non-empty and no SB list, EP disabled"); | ||
1528 | } | ||
1529 | } else { | ||
1530 | dbg_isoc("Urb 0x%p not found, completed already?", urb); | ||
1531 | } | ||
1532 | } else { | ||
1533 | |||
1534 | urb_list_del(urb, epid); | ||
1535 | |||
1536 | /* For in traffic there is only one SB descriptor for each EP even | ||
1537 | though there may be several urbs (all urbs point at the same SB). */ | ||
1538 | if (urb_list_empty(epid)) { | ||
1539 | /* No more urbs, remove the SB. */ | ||
1540 | TxIsocEPList[epid].sub = 0; | ||
1541 | etrax_remove_from_sb_list(urb); | ||
1542 | } else { | ||
1543 | TxIsocEPList[epid].hw_len = 0; | ||
1544 | TxIsocEPList[epid].command |= IO_STATE(USB_EP_command, enable, yes); | ||
1545 | } | ||
1546 | } | ||
1547 | /* Release allocated bandwidth. */ | ||
1548 | usb_release_bandwidth(urb->dev, urb, 1); | ||
1549 | } | ||
1550 | /* Free the epid if urb list is empty. */ | ||
1551 | if (urb_list_empty(epid)) { | ||
1552 | etrax_usb_free_epid(epid); | ||
1553 | } | ||
1554 | restore_flags(flags); | ||
1555 | |||
1556 | /* Must be done before calling completion handler. */ | ||
1557 | kfree(urb_priv); | ||
1558 | urb->hcpriv = 0; | ||
1559 | |||
1560 | if (urb->complete) { | ||
1561 | urb->complete(urb, NULL); | ||
1562 | } | ||
1563 | |||
1564 | DBFEXIT; | ||
1565 | return 0; | ||
1566 | } | ||
1567 | |||
1568 | static int etrax_usb_get_frame_number(struct usb_device *usb_dev) | ||
1569 | { | ||
1570 | DBFENTER; | ||
1571 | DBFEXIT; | ||
1572 | return (*R_USB_FM_NUMBER & 0x7ff); | ||
1573 | } | ||
1574 | |||
1575 | static irqreturn_t etrax_usb_tx_interrupt(int irq, void *vhc) | ||
1576 | { | ||
1577 | DBFENTER; | ||
1578 | |||
1579 | /* This interrupt handler could be used when unlinking EP descriptors. */ | ||
1580 | |||
1581 | if (*R_IRQ_READ2 & IO_MASK(R_IRQ_READ2, dma8_sub0_descr)) { | ||
1582 | USB_EP_Desc_t *ep; | ||
1583 | |||
1584 | //dbg_bulk("dma8_sub0_descr (BULK) intr."); | ||
1585 | |||
1586 | /* It should be safe clearing the interrupt here, since we don't expect to get a new | ||
1587 | one until we restart the bulk channel. */ | ||
1588 | *R_DMA_CH8_SUB0_CLR_INTR = IO_STATE(R_DMA_CH8_SUB0_CLR_INTR, clr_descr, do); | ||
1589 | |||
1590 | /* Wait while the DMA is running (though we don't expect it to be). */ | ||
1591 | while (*R_DMA_CH8_SUB0_CMD & IO_MASK(R_DMA_CH8_SUB0_CMD, cmd)); | ||
1592 | |||
1593 | /* Advance the DMA to the next EP descriptor. */ | ||
1594 | ep = (USB_EP_Desc_t *)phys_to_virt(*R_DMA_CH8_SUB0_EP); | ||
1595 | |||
1596 | //dbg_bulk("descr intr: DMA is at 0x%lx", (unsigned long)ep); | ||
1597 | |||
1598 | /* ep->next is already a physical address; no need for a virt_to_phys. */ | ||
1599 | *R_DMA_CH8_SUB0_EP = ep->next; | ||
1600 | |||
1601 | /* Start the DMA bulk channel again. */ | ||
1602 | *R_DMA_CH8_SUB0_CMD = IO_STATE(R_DMA_CH8_SUB0_CMD, cmd, start); | ||
1603 | } | ||
1604 | if (*R_IRQ_READ2 & IO_MASK(R_IRQ_READ2, dma8_sub1_descr)) { | ||
1605 | struct urb *urb; | ||
1606 | int epid; | ||
1607 | etrax_urb_priv_t *urb_priv; | ||
1608 | unsigned long int flags; | ||
1609 | |||
1610 | dbg_ctrl("dma8_sub1_descr (CTRL) intr."); | ||
1611 | *R_DMA_CH8_SUB1_CLR_INTR = IO_STATE(R_DMA_CH8_SUB1_CLR_INTR, clr_descr, do); | ||
1612 | |||
1613 | /* The complete callback gets called so we cli. */ | ||
1614 | save_flags(flags); | ||
1615 | cli(); | ||
1616 | |||
1617 | for (epid = 0; epid < NBR_OF_EPIDS - 1; epid++) { | ||
1618 | if ((TxCtrlEPList[epid].sub == 0) || | ||
1619 | (epid == DUMMY_EPID) || | ||
1620 | (epid == INVALID_EPID)) { | ||
1621 | /* Nothing here to see. */ | ||
1622 | continue; | ||
1623 | } | ||
1624 | |||
1625 | /* Get the first urb (if any). */ | ||
1626 | urb = urb_list_first(epid); | ||
1627 | |||
1628 | if (urb) { | ||
1629 | |||
1630 | /* Sanity check. */ | ||
1631 | assert(usb_pipetype(urb->pipe) == PIPE_CONTROL); | ||
1632 | |||
1633 | urb_priv = (etrax_urb_priv_t *)urb->hcpriv; | ||
1634 | assert(urb_priv); | ||
1635 | |||
1636 | if (urb_priv->urb_state == WAITING_FOR_DESCR_INTR) { | ||
1637 | assert(!(TxCtrlEPList[urb_priv->epid].command & IO_MASK(USB_EP_command, enable))); | ||
1638 | |||
1639 | etrax_usb_complete_urb(urb, 0); | ||
1640 | } | ||
1641 | } | ||
1642 | } | ||
1643 | restore_flags(flags); | ||
1644 | } | ||
1645 | if (*R_IRQ_READ2 & IO_MASK(R_IRQ_READ2, dma8_sub2_descr)) { | ||
1646 | dbg_intr("dma8_sub2_descr (INTR) intr."); | ||
1647 | *R_DMA_CH8_SUB2_CLR_INTR = IO_STATE(R_DMA_CH8_SUB2_CLR_INTR, clr_descr, do); | ||
1648 | } | ||
1649 | if (*R_IRQ_READ2 & IO_MASK(R_IRQ_READ2, dma8_sub3_descr)) { | ||
1650 | struct urb *urb; | ||
1651 | int epid; | ||
1652 | int epid_done; | ||
1653 | etrax_urb_priv_t *urb_priv; | ||
1654 | USB_SB_Desc_t *sb_desc; | ||
1655 | |||
1656 | usb_isoc_complete_data_t *comp_data = NULL; | ||
1657 | |||
1658 | /* One or more isoc out transfers are done. */ | ||
1659 | dbg_isoc("dma8_sub3_descr (ISOC) intr."); | ||
1660 | |||
1661 | /* For each isoc out EP search for the first sb_desc with the intr flag | ||
1662 | set. This descriptor must be the last packet from an URB. Then | ||
1663 | traverse the URB list for the EP until the URB with urb_priv->last_sb | ||
1664 | matching the intr-marked sb_desc is found. All URBs before this have | ||
1665 | been sent. | ||
1666 | */ | ||
1667 | |||
1668 | for (epid = 0; epid < NBR_OF_EPIDS - 1; epid++) { | ||
1669 | /* Skip past epids with no SB lists, epids used for in traffic, | ||
1670 | and special (dummy, invalid) epids. */ | ||
1671 | if ((TxIsocEPList[epid].sub == 0) || | ||
1672 | (test_bit(epid, (void *)&epid_out_traffic) == 0) || | ||
1673 | (epid == DUMMY_EPID) || | ||
1674 | (epid == INVALID_EPID)) { | ||
1675 | /* Nothing here to see. */ | ||
1676 | continue; | ||
1677 | } | ||
1678 | sb_desc = phys_to_virt(TxIsocEPList[epid].sub); | ||
1679 | |||
1680 | /* Find the last descriptor of the currently active URB for this ep. | ||
1681 | This is the first descriptor in the sub list marked for a descriptor | ||
1682 | interrupt. */ | ||
1683 | while (sb_desc && !IO_EXTRACT(USB_SB_command, intr, sb_desc->command)) { | ||
1684 | sb_desc = sb_desc->next ? phys_to_virt(sb_desc->next) : 0; | ||
1685 | } | ||
1686 | assert(sb_desc); | ||
1687 | |||
1688 | dbg_isoc("Check epid %d, sub 0x%p, SB 0x%p", | ||
1689 | epid, | ||
1690 | phys_to_virt(TxIsocEPList[epid].sub), | ||
1691 | sb_desc); | ||
1692 | |||
1693 | epid_done = 0; | ||
1694 | |||
1695 | /* Get the first urb (if any). */ | ||
1696 | urb = urb_list_first(epid); | ||
1697 | assert(urb); | ||
1698 | |||
1699 | while (urb && !epid_done) { | ||
1700 | |||
1701 | /* Sanity check. */ | ||
1702 | assert(usb_pipetype(urb->pipe) == PIPE_ISOCHRONOUS); | ||
1703 | |||
1704 | if (!usb_pipeout(urb->pipe)) { | ||
1705 | /* descr interrupts are generated only for out pipes. */ | ||
1706 | epid_done = 1; | ||
1707 | continue; | ||
1708 | } | ||
1709 | |||
1710 | urb_priv = (etrax_urb_priv_t *)urb->hcpriv; | ||
1711 | assert(urb_priv); | ||
1712 | |||
1713 | if (sb_desc != urb_priv->last_sb) { | ||
1714 | |||
1715 | /* This urb has been sent. */ | ||
1716 | dbg_isoc("out URB 0x%p sent", urb); | ||
1717 | |||
1718 | urb_priv->urb_state = TRANSFER_DONE; | ||
1719 | |||
1720 | } else if ((sb_desc == urb_priv->last_sb) && | ||
1721 | !(TxIsocEPList[epid].command & IO_MASK(USB_EP_command, enable))) { | ||
1722 | |||
1723 | assert((sb_desc->command & IO_MASK(USB_SB_command, eol)) == IO_STATE(USB_SB_command, eol, yes)); | ||
1724 | assert(sb_desc->next == 0); | ||
1725 | |||
1726 | dbg_isoc("out URB 0x%p last in list, epid disabled", urb); | ||
1727 | TxIsocEPList[epid].sub = 0; | ||
1728 | TxIsocEPList[epid].hw_len = 0; | ||
1729 | urb_priv->urb_state = TRANSFER_DONE; | ||
1730 | |||
1731 | epid_done = 1; | ||
1732 | |||
1733 | } else { | ||
1734 | epid_done = 1; | ||
1735 | } | ||
1736 | if (!epid_done) { | ||
1737 | urb = urb_list_next(urb, epid); | ||
1738 | } | ||
1739 | } | ||
1740 | |||
1741 | } | ||
1742 | |||
1743 | *R_DMA_CH8_SUB3_CLR_INTR = IO_STATE(R_DMA_CH8_SUB3_CLR_INTR, clr_descr, do); | ||
1744 | |||
1745 | comp_data = (usb_isoc_complete_data_t*)kmem_cache_alloc(isoc_compl_cache, GFP_ATOMIC); | ||
1746 | assert(comp_data != NULL); | ||
1747 | |||
1748 | INIT_WORK(&comp_data->usb_bh, etrax_usb_isoc_descr_interrupt_bottom_half, comp_data); | ||
1749 | schedule_work(&comp_data->usb_bh); | ||
1750 | } | ||
1751 | |||
1752 | DBFEXIT; | ||
1753 | return IRQ_HANDLED; | ||
1754 | } | ||
1755 | |||
1756 | static void etrax_usb_isoc_descr_interrupt_bottom_half(void *data) | ||
1757 | { | ||
1758 | usb_isoc_complete_data_t *comp_data = (usb_isoc_complete_data_t*)data; | ||
1759 | |||
1760 | struct urb *urb; | ||
1761 | int epid; | ||
1762 | int epid_done; | ||
1763 | etrax_urb_priv_t *urb_priv; | ||
1764 | |||
1765 | DBFENTER; | ||
1766 | |||
1767 | dbg_isoc("dma8_sub3_descr (ISOC) bottom half."); | ||
1768 | |||
1769 | for (epid = 0; epid < NBR_OF_EPIDS - 1; epid++) { | ||
1770 | unsigned long flags; | ||
1771 | |||
1772 | save_flags(flags); | ||
1773 | cli(); | ||
1774 | |||
1775 | epid_done = 0; | ||
1776 | |||
1777 | /* The descriptor interrupt handler has marked all transmitted isoch. out | ||
1778 | URBs with TRANSFER_DONE. Now we traverse all epids and for all that | ||
1779 | have isoch. out traffic traverse its URB list and complete the | ||
1780 | transmitted URB. | ||
1781 | */ | ||
1782 | |||
1783 | while (!epid_done) { | ||
1784 | |||
1785 | /* Get the first urb (if any). */ | ||
1786 | urb = urb_list_first(epid); | ||
1787 | if (urb == 0) { | ||
1788 | epid_done = 1; | ||
1789 | continue; | ||
1790 | } | ||
1791 | |||
1792 | if (usb_pipetype(urb->pipe) != PIPE_ISOCHRONOUS) { | ||
1793 | epid_done = 1; | ||
1794 | continue; | ||
1795 | } | ||
1796 | |||
1797 | if (!usb_pipeout(urb->pipe)) { | ||
1798 | /* descr interrupts are generated only for out pipes. */ | ||
1799 | epid_done = 1; | ||
1800 | continue; | ||
1801 | } | ||
1802 | |||
1803 | dbg_isoc("Check epid %d, SB 0x%p", epid, (char*)TxIsocEPList[epid].sub); | ||
1804 | |||
1805 | urb_priv = (etrax_urb_priv_t *)urb->hcpriv; | ||
1806 | assert(urb_priv); | ||
1807 | |||
1808 | if (urb_priv->urb_state == TRANSFER_DONE) { | ||
1809 | int i; | ||
1810 | struct usb_iso_packet_descriptor *packet; | ||
1811 | |||
1812 | /* This urb has been sent. */ | ||
1813 | dbg_isoc("Completing isoc out URB 0x%p", urb); | ||
1814 | |||
1815 | for (i = 0; i < urb->number_of_packets; i++) { | ||
1816 | packet = &urb->iso_frame_desc[i]; | ||
1817 | packet->status = 0; | ||
1818 | packet->actual_length = packet->length; | ||
1819 | } | ||
1820 | |||
1821 | etrax_usb_complete_isoc_urb(urb, 0); | ||
1822 | |||
1823 | if (urb_list_empty(epid)) { | ||
1824 | etrax_usb_free_epid(epid); | ||
1825 | epid_done = 1; | ||
1826 | } | ||
1827 | } else { | ||
1828 | epid_done = 1; | ||
1829 | } | ||
1830 | } | ||
1831 | restore_flags(flags); | ||
1832 | |||
1833 | } | ||
1834 | kmem_cache_free(isoc_compl_cache, comp_data); | ||
1835 | |||
1836 | DBFEXIT; | ||
1837 | } | ||
1838 | |||
1839 | |||
1840 | |||
1841 | static irqreturn_t etrax_usb_rx_interrupt(int irq, void *vhc) | ||
1842 | { | ||
1843 | struct urb *urb; | ||
1844 | etrax_urb_priv_t *urb_priv; | ||
1845 | int epid = 0; | ||
1846 | unsigned long flags; | ||
1847 | |||
1848 | /* Isoc diagnostics. */ | ||
1849 | static int curr_fm = 0; | ||
1850 | static int prev_fm = 0; | ||
1851 | |||
1852 | DBFENTER; | ||
1853 | |||
1854 | /* Clear this interrupt. */ | ||
1855 | *R_DMA_CH9_CLR_INTR = IO_STATE(R_DMA_CH9_CLR_INTR, clr_eop, do); | ||
1856 | |||
1857 | /* Note that this while loop assumes that all packets span only | ||
1858 | one rx descriptor. */ | ||
1859 | |||
1860 | /* The reason we cli here is that we call the driver's callback functions. */ | ||
1861 | save_flags(flags); | ||
1862 | cli(); | ||
1863 | |||
1864 | while (myNextRxDesc->status & IO_MASK(USB_IN_status, eop)) { | ||
1865 | |||
1866 | epid = IO_EXTRACT(USB_IN_status, epid, myNextRxDesc->status); | ||
1867 | urb = urb_list_first(epid); | ||
1868 | |||
1869 | //printk("eop for epid %d, first urb 0x%lx\n", epid, (unsigned long)urb); | ||
1870 | |||
1871 | if (!urb) { | ||
1872 | err("No urb for epid %d in rx interrupt", epid); | ||
1873 | __dump_ept_data(epid); | ||
1874 | goto skip_out; | ||
1875 | } | ||
1876 | |||
1877 | /* Note that we cannot indescriminately assert(usb_pipein(urb->pipe)) since | ||
1878 | ctrl pipes are not. */ | ||
1879 | |||
1880 | if (myNextRxDesc->status & IO_MASK(USB_IN_status, error)) { | ||
1881 | __u32 r_usb_ept_data; | ||
1882 | int no_error = 0; | ||
1883 | |||
1884 | assert(test_bit(epid, (void *)&epid_usage_bitmask)); | ||
1885 | |||
1886 | *R_USB_EPT_INDEX = IO_FIELD(R_USB_EPT_INDEX, value, epid); | ||
1887 | nop(); | ||
1888 | if (usb_pipetype(urb->pipe) == PIPE_ISOCHRONOUS) { | ||
1889 | r_usb_ept_data = *R_USB_EPT_DATA_ISO; | ||
1890 | |||
1891 | if ((r_usb_ept_data & IO_MASK(R_USB_EPT_DATA_ISO, valid)) && | ||
1892 | (IO_EXTRACT(R_USB_EPT_DATA_ISO, error_code, r_usb_ept_data) == 0) && | ||
1893 | (myNextRxDesc->status & IO_MASK(USB_IN_status, nodata))) { | ||
1894 | /* Not an error, just a failure to receive an expected iso | ||
1895 | in packet in this frame. This is not documented | ||
1896 | in the designers reference. | ||
1897 | */ | ||
1898 | no_error++; | ||
1899 | } else { | ||
1900 | warn("R_USB_EPT_DATA_ISO for epid %d = 0x%x", epid, r_usb_ept_data); | ||
1901 | } | ||
1902 | } else { | ||
1903 | r_usb_ept_data = *R_USB_EPT_DATA; | ||
1904 | warn("R_USB_EPT_DATA for epid %d = 0x%x", epid, r_usb_ept_data); | ||
1905 | } | ||
1906 | |||
1907 | if (!no_error){ | ||
1908 | warn("error in rx desc->status, epid %d, first urb = 0x%lx", | ||
1909 | epid, (unsigned long)urb); | ||
1910 | __dump_in_desc(myNextRxDesc); | ||
1911 | |||
1912 | warn("R_USB_STATUS = 0x%x", *R_USB_STATUS); | ||
1913 | |||
1914 | /* Check that ept was disabled when error occurred. */ | ||
1915 | switch (usb_pipetype(urb->pipe)) { | ||
1916 | case PIPE_BULK: | ||
1917 | assert(!(TxBulkEPList[epid].command & IO_MASK(USB_EP_command, enable))); | ||
1918 | break; | ||
1919 | case PIPE_CONTROL: | ||
1920 | assert(!(TxCtrlEPList[epid].command & IO_MASK(USB_EP_command, enable))); | ||
1921 | break; | ||
1922 | case PIPE_INTERRUPT: | ||
1923 | assert(!(TxIntrEPList[epid].command & IO_MASK(USB_EP_command, enable))); | ||
1924 | break; | ||
1925 | case PIPE_ISOCHRONOUS: | ||
1926 | assert(!(TxIsocEPList[epid].command & IO_MASK(USB_EP_command, enable))); | ||
1927 | break; | ||
1928 | default: | ||
1929 | warn("etrax_usb_rx_interrupt: bad pipetype %d in urb 0x%p", | ||
1930 | usb_pipetype(urb->pipe), | ||
1931 | urb); | ||
1932 | } | ||
1933 | etrax_usb_complete_urb(urb, -EPROTO); | ||
1934 | goto skip_out; | ||
1935 | } | ||
1936 | } | ||
1937 | |||
1938 | urb_priv = (etrax_urb_priv_t *)urb->hcpriv; | ||
1939 | assert(urb_priv); | ||
1940 | |||
1941 | if ((usb_pipetype(urb->pipe) == PIPE_BULK) || | ||
1942 | (usb_pipetype(urb->pipe) == PIPE_CONTROL) || | ||
1943 | (usb_pipetype(urb->pipe) == PIPE_INTERRUPT)) { | ||
1944 | |||
1945 | if (myNextRxDesc->status & IO_MASK(USB_IN_status, nodata)) { | ||
1946 | /* We get nodata for empty data transactions, and the rx descriptor's | ||
1947 | hw_len field is not valid in that case. No data to copy in other | ||
1948 | words. */ | ||
1949 | } else { | ||
1950 | /* Make sure the data fits in the buffer. */ | ||
1951 | assert(urb_priv->rx_offset + myNextRxDesc->hw_len | ||
1952 | <= urb->transfer_buffer_length); | ||
1953 | |||
1954 | memcpy(urb->transfer_buffer + urb_priv->rx_offset, | ||
1955 | phys_to_virt(myNextRxDesc->buf), myNextRxDesc->hw_len); | ||
1956 | urb_priv->rx_offset += myNextRxDesc->hw_len; | ||
1957 | } | ||
1958 | |||
1959 | if (myNextRxDesc->status & IO_MASK(USB_IN_status, eot)) { | ||
1960 | if ((usb_pipetype(urb->pipe) == PIPE_CONTROL) && | ||
1961 | ((TxCtrlEPList[urb_priv->epid].command & IO_MASK(USB_EP_command, enable)) == | ||
1962 | IO_STATE(USB_EP_command, enable, yes))) { | ||
1963 | /* The EP is still enabled, so the OUT packet used to ack | ||
1964 | the in data is probably not processed yet. If the EP | ||
1965 | sub pointer has not moved beyond urb_priv->last_sb mark | ||
1966 | it for a descriptor interrupt and complete the urb in | ||
1967 | the descriptor interrupt handler. | ||
1968 | */ | ||
1969 | USB_SB_Desc_t *sub = TxCtrlEPList[urb_priv->epid].sub ? phys_to_virt(TxCtrlEPList[urb_priv->epid].sub) : 0; | ||
1970 | |||
1971 | while ((sub != NULL) && (sub != urb_priv->last_sb)) { | ||
1972 | sub = sub->next ? phys_to_virt(sub->next) : 0; | ||
1973 | } | ||
1974 | if (sub != NULL) { | ||
1975 | /* The urb has not been fully processed. */ | ||
1976 | urb_priv->urb_state = WAITING_FOR_DESCR_INTR; | ||
1977 | } else { | ||
1978 | warn("(CTRL) epid enabled and urb (0x%p) processed, ep->sub=0x%p", urb, (char*)TxCtrlEPList[urb_priv->epid].sub); | ||
1979 | etrax_usb_complete_urb(urb, 0); | ||
1980 | } | ||
1981 | } else { | ||
1982 | etrax_usb_complete_urb(urb, 0); | ||
1983 | } | ||
1984 | } | ||
1985 | |||
1986 | } else if (usb_pipetype(urb->pipe) == PIPE_ISOCHRONOUS) { | ||
1987 | |||
1988 | struct usb_iso_packet_descriptor *packet; | ||
1989 | |||
1990 | if (urb_priv->urb_state == UNLINK) { | ||
1991 | info("Ignoring rx data for urb being unlinked."); | ||
1992 | goto skip_out; | ||
1993 | } else if (urb_priv->urb_state == NOT_STARTED) { | ||
1994 | info("What? Got rx data for urb that isn't started?"); | ||
1995 | goto skip_out; | ||
1996 | } | ||
1997 | |||
1998 | packet = &urb->iso_frame_desc[urb_priv->isoc_packet_counter]; | ||
1999 | packet->status = 0; | ||
2000 | |||
2001 | if (myNextRxDesc->status & IO_MASK(USB_IN_status, nodata)) { | ||
2002 | /* We get nodata for empty data transactions, and the rx descriptor's | ||
2003 | hw_len field is not valid in that case. We copy 0 bytes however to | ||
2004 | stay in synch. */ | ||
2005 | packet->actual_length = 0; | ||
2006 | } else { | ||
2007 | packet->actual_length = myNextRxDesc->hw_len; | ||
2008 | /* Make sure the data fits in the buffer. */ | ||
2009 | assert(packet->actual_length <= packet->length); | ||
2010 | memcpy(urb->transfer_buffer + packet->offset, | ||
2011 | phys_to_virt(myNextRxDesc->buf), packet->actual_length); | ||
2012 | } | ||
2013 | |||
2014 | /* Increment the packet counter. */ | ||
2015 | urb_priv->isoc_packet_counter++; | ||
2016 | |||
2017 | /* Note that we don't care about the eot field in the rx descriptor's status. | ||
2018 | It will always be set for isoc traffic. */ | ||
2019 | if (urb->number_of_packets == urb_priv->isoc_packet_counter) { | ||
2020 | |||
2021 | /* Out-of-synch diagnostics. */ | ||
2022 | curr_fm = (*R_USB_FM_NUMBER & 0x7ff); | ||
2023 | if (((prev_fm + urb_priv->isoc_packet_counter) % (0x7ff + 1)) != curr_fm) { | ||
2024 | /* This test is wrong, if there is more than one isoc | ||
2025 | in endpoint active it will always calculate wrong | ||
2026 | since prev_fm is shared by all endpoints. | ||
2027 | |||
2028 | FIXME Make this check per URB using urb->start_frame. | ||
2029 | */ | ||
2030 | dbg_isoc("Out of synch? Previous frame = %d, current frame = %d", | ||
2031 | prev_fm, curr_fm); | ||
2032 | |||
2033 | } | ||
2034 | prev_fm = curr_fm; | ||
2035 | |||
2036 | /* Complete the urb with status OK. */ | ||
2037 | etrax_usb_complete_isoc_urb(urb, 0); | ||
2038 | } | ||
2039 | } | ||
2040 | |||
2041 | skip_out: | ||
2042 | |||
2043 | /* DMA IN cache bug. Flush the DMA IN buffer from the cache. (struct etrax_dma_descr | ||
2044 | has the same layout as USB_IN_Desc for the relevant fields.) */ | ||
2045 | prepare_rx_descriptor((struct etrax_dma_descr*)myNextRxDesc); | ||
2046 | |||
2047 | myPrevRxDesc = myNextRxDesc; | ||
2048 | myPrevRxDesc->command |= IO_MASK(USB_IN_command, eol); | ||
2049 | myLastRxDesc->command &= ~IO_MASK(USB_IN_command, eol); | ||
2050 | myLastRxDesc = myPrevRxDesc; | ||
2051 | |||
2052 | myNextRxDesc->status = 0; | ||
2053 | myNextRxDesc = phys_to_virt(myNextRxDesc->next); | ||
2054 | } | ||
2055 | |||
2056 | restore_flags(flags); | ||
2057 | |||
2058 | DBFEXIT; | ||
2059 | |||
2060 | return IRQ_HANDLED; | ||
2061 | } | ||
2062 | |||
2063 | |||
2064 | /* This function will unlink the SB descriptors associated with this urb. */ | ||
2065 | static int etrax_remove_from_sb_list(struct urb *urb) | ||
2066 | { | ||
2067 | USB_SB_Desc_t *next_sb, *first_sb, *last_sb; | ||
2068 | etrax_urb_priv_t *urb_priv; | ||
2069 | int i = 0; | ||
2070 | |||
2071 | DBFENTER; | ||
2072 | |||
2073 | urb_priv = (etrax_urb_priv_t *)urb->hcpriv; | ||
2074 | assert(urb_priv); | ||
2075 | |||
2076 | /* Just a sanity check. Since we don't fiddle with the DMA list the EP descriptor | ||
2077 | doesn't really need to be disabled, it's just that we expect it to be. */ | ||
2078 | if (usb_pipetype(urb->pipe) == PIPE_BULK) { | ||
2079 | assert(!(TxBulkEPList[urb_priv->epid].command & IO_MASK(USB_EP_command, enable))); | ||
2080 | } else if (usb_pipetype(urb->pipe) == PIPE_CONTROL) { | ||
2081 | assert(!(TxCtrlEPList[urb_priv->epid].command & IO_MASK(USB_EP_command, enable))); | ||
2082 | } | ||
2083 | |||
2084 | first_sb = urb_priv->first_sb; | ||
2085 | last_sb = urb_priv->last_sb; | ||
2086 | |||
2087 | assert(first_sb); | ||
2088 | assert(last_sb); | ||
2089 | |||
2090 | while (first_sb != last_sb) { | ||
2091 | next_sb = (USB_SB_Desc_t *)phys_to_virt(first_sb->next); | ||
2092 | kmem_cache_free(usb_desc_cache, first_sb); | ||
2093 | first_sb = next_sb; | ||
2094 | i++; | ||
2095 | } | ||
2096 | kmem_cache_free(usb_desc_cache, last_sb); | ||
2097 | i++; | ||
2098 | dbg_sb("%d SB descriptors freed", i); | ||
2099 | /* Compare i with urb->number_of_packets for Isoc traffic. | ||
2100 | Should be same when calling unlink_urb */ | ||
2101 | |||
2102 | DBFEXIT; | ||
2103 | |||
2104 | return i; | ||
2105 | } | ||
2106 | |||
2107 | static int etrax_usb_submit_bulk_urb(struct urb *urb) | ||
2108 | { | ||
2109 | int epid; | ||
2110 | int empty; | ||
2111 | unsigned long flags; | ||
2112 | etrax_urb_priv_t *urb_priv; | ||
2113 | |||
2114 | DBFENTER; | ||
2115 | |||
2116 | /* Epid allocation, empty check and list add must be protected. | ||
2117 | Read about this in etrax_usb_submit_ctrl_urb. */ | ||
2118 | |||
2119 | spin_lock_irqsave(&urb_list_lock, flags); | ||
2120 | epid = etrax_usb_setup_epid(urb); | ||
2121 | if (epid == -1) { | ||
2122 | DBFEXIT; | ||
2123 | spin_unlock_irqrestore(&urb_list_lock, flags); | ||
2124 | return -ENOMEM; | ||
2125 | } | ||
2126 | empty = urb_list_empty(epid); | ||
2127 | urb_list_add(urb, epid); | ||
2128 | spin_unlock_irqrestore(&urb_list_lock, flags); | ||
2129 | |||
2130 | dbg_bulk("Adding bulk %s urb 0x%lx to %s list, epid %d", | ||
2131 | usb_pipein(urb->pipe) ? "IN" : "OUT", (unsigned long)urb, empty ? "empty" : "", epid); | ||
2132 | |||
2133 | /* Mark the urb as being in progress. */ | ||
2134 | urb->status = -EINPROGRESS; | ||
2135 | |||
2136 | /* Setup the hcpriv data. */ | ||
2137 | urb_priv = kzalloc(sizeof(etrax_urb_priv_t), KMALLOC_FLAG); | ||
2138 | assert(urb_priv != NULL); | ||
2139 | /* This sets rx_offset to 0. */ | ||
2140 | urb_priv->urb_state = NOT_STARTED; | ||
2141 | urb->hcpriv = urb_priv; | ||
2142 | |||
2143 | if (empty) { | ||
2144 | etrax_usb_add_to_bulk_sb_list(urb, epid); | ||
2145 | } | ||
2146 | |||
2147 | DBFEXIT; | ||
2148 | |||
2149 | return 0; | ||
2150 | } | ||
2151 | |||
2152 | static void etrax_usb_add_to_bulk_sb_list(struct urb *urb, int epid) | ||
2153 | { | ||
2154 | USB_SB_Desc_t *sb_desc; | ||
2155 | etrax_urb_priv_t *urb_priv = (etrax_urb_priv_t *)urb->hcpriv; | ||
2156 | unsigned long flags; | ||
2157 | char maxlen; | ||
2158 | |||
2159 | DBFENTER; | ||
2160 | |||
2161 | dbg_bulk("etrax_usb_add_to_bulk_sb_list, urb 0x%lx", (unsigned long)urb); | ||
2162 | |||
2163 | maxlen = usb_maxpacket(urb->dev, urb->pipe, usb_pipeout(urb->pipe)); | ||
2164 | |||
2165 | sb_desc = kmem_cache_zalloc(usb_desc_cache, SLAB_FLAG); | ||
2166 | assert(sb_desc != NULL); | ||
2167 | |||
2168 | |||
2169 | if (usb_pipeout(urb->pipe)) { | ||
2170 | |||
2171 | dbg_bulk("Grabbing bulk OUT, urb 0x%lx, epid %d", (unsigned long)urb, epid); | ||
2172 | |||
2173 | /* This is probably a sanity check of the bulk transaction length | ||
2174 | not being larger than 64 kB. */ | ||
2175 | if (urb->transfer_buffer_length > 0xffff) { | ||
2176 | panic("urb->transfer_buffer_length > 0xffff"); | ||
2177 | } | ||
2178 | |||
2179 | sb_desc->sw_len = urb->transfer_buffer_length; | ||
2180 | |||
2181 | /* The rem field is don't care if it's not a full-length transfer, so setting | ||
2182 | it shouldn't hurt. Also, rem isn't used for OUT traffic. */ | ||
2183 | sb_desc->command = (IO_FIELD(USB_SB_command, rem, 0) | | ||
2184 | IO_STATE(USB_SB_command, tt, out) | | ||
2185 | IO_STATE(USB_SB_command, eot, yes) | | ||
2186 | IO_STATE(USB_SB_command, eol, yes)); | ||
2187 | |||
2188 | /* The full field is set to yes, even if we don't actually check that this is | ||
2189 | a full-length transfer (i.e., that transfer_buffer_length % maxlen = 0). | ||
2190 | Setting full prevents the USB controller from sending an empty packet in | ||
2191 | that case. However, if URB_ZERO_PACKET was set we want that. */ | ||
2192 | if (!(urb->transfer_flags & URB_ZERO_PACKET)) { | ||
2193 | sb_desc->command |= IO_STATE(USB_SB_command, full, yes); | ||
2194 | } | ||
2195 | |||
2196 | sb_desc->buf = virt_to_phys(urb->transfer_buffer); | ||
2197 | sb_desc->next = 0; | ||
2198 | |||
2199 | } else if (usb_pipein(urb->pipe)) { | ||
2200 | |||
2201 | dbg_bulk("Grabbing bulk IN, urb 0x%lx, epid %d", (unsigned long)urb, epid); | ||
2202 | |||
2203 | sb_desc->sw_len = urb->transfer_buffer_length ? | ||
2204 | (urb->transfer_buffer_length - 1) / maxlen + 1 : 0; | ||
2205 | |||
2206 | /* The rem field is don't care if it's not a full-length transfer, so setting | ||
2207 | it shouldn't hurt. */ | ||
2208 | sb_desc->command = | ||
2209 | (IO_FIELD(USB_SB_command, rem, | ||
2210 | urb->transfer_buffer_length % maxlen) | | ||
2211 | IO_STATE(USB_SB_command, tt, in) | | ||
2212 | IO_STATE(USB_SB_command, eot, yes) | | ||
2213 | IO_STATE(USB_SB_command, eol, yes)); | ||
2214 | |||
2215 | sb_desc->buf = 0; | ||
2216 | sb_desc->next = 0; | ||
2217 | } | ||
2218 | |||
2219 | urb_priv->first_sb = sb_desc; | ||
2220 | urb_priv->last_sb = sb_desc; | ||
2221 | urb_priv->epid = epid; | ||
2222 | |||
2223 | urb->hcpriv = urb_priv; | ||
2224 | |||
2225 | /* Reset toggle bits and reset error count. */ | ||
2226 | save_flags(flags); | ||
2227 | cli(); | ||
2228 | |||
2229 | *R_USB_EPT_INDEX = IO_FIELD(R_USB_EPT_INDEX, value, epid); | ||
2230 | nop(); | ||
2231 | |||
2232 | /* FIXME: Is this a special case since the hold field is checked, | ||
2233 | or should we check hold in a lot of other cases as well? */ | ||
2234 | if (*R_USB_EPT_DATA & IO_MASK(R_USB_EPT_DATA, hold)) { | ||
2235 | panic("Hold was set in %s", __FUNCTION__); | ||
2236 | } | ||
2237 | |||
2238 | /* Reset error counters (regardless of which direction this traffic is). */ | ||
2239 | *R_USB_EPT_DATA &= | ||
2240 | ~(IO_MASK(R_USB_EPT_DATA, error_count_in) | | ||
2241 | IO_MASK(R_USB_EPT_DATA, error_count_out)); | ||
2242 | |||
2243 | /* Software must preset the toggle bits. */ | ||
2244 | if (usb_pipeout(urb->pipe)) { | ||
2245 | char toggle = | ||
2246 | usb_gettoggle(urb->dev, usb_pipeendpoint(urb->pipe), usb_pipeout(urb->pipe)); | ||
2247 | *R_USB_EPT_DATA &= ~IO_MASK(R_USB_EPT_DATA, t_out); | ||
2248 | *R_USB_EPT_DATA |= IO_FIELD(R_USB_EPT_DATA, t_out, toggle); | ||
2249 | } else { | ||
2250 | char toggle = | ||
2251 | usb_gettoggle(urb->dev, usb_pipeendpoint(urb->pipe), usb_pipeout(urb->pipe)); | ||
2252 | *R_USB_EPT_DATA &= ~IO_MASK(R_USB_EPT_DATA, t_in); | ||
2253 | *R_USB_EPT_DATA |= IO_FIELD(R_USB_EPT_DATA, t_in, toggle); | ||
2254 | } | ||
2255 | |||
2256 | /* Assert that the EP descriptor is disabled. */ | ||
2257 | assert(!(TxBulkEPList[epid].command & IO_MASK(USB_EP_command, enable))); | ||
2258 | |||
2259 | /* The reason we set the EP's sub pointer directly instead of | ||
2260 | walking the SB list and linking it last in the list is that we only | ||
2261 | have one active urb at a time (the rest are queued). */ | ||
2262 | |||
2263 | /* Note that we cannot have interrupts running when we have set the SB descriptor | ||
2264 | but the EP is not yet enabled. If a bulk eot happens for another EP, we will | ||
2265 | find this EP disabled and with a SB != 0, which will make us think that it's done. */ | ||
2266 | TxBulkEPList[epid].sub = virt_to_phys(sb_desc); | ||
2267 | TxBulkEPList[epid].hw_len = 0; | ||
2268 | /* Note that we don't have to fill in the ep_id field since this | ||
2269 | was done when we allocated the EP descriptors in init_tx_bulk_ep. */ | ||
2270 | |||
2271 | /* Check if the dummy list is already with us (if several urbs were queued). */ | ||
2272 | if (TxBulkEPList[epid].next != virt_to_phys(&TxBulkDummyEPList[epid][0])) { | ||
2273 | |||
2274 | dbg_bulk("Inviting dummy list to the party for urb 0x%lx, epid %d", | ||
2275 | (unsigned long)urb, epid); | ||
2276 | |||
2277 | /* The last EP in the dummy list already has its next pointer set to | ||
2278 | TxBulkEPList[epid].next. */ | ||
2279 | |||
2280 | /* We don't need to check if the DMA is at this EP or not before changing the | ||
2281 | next pointer, since we will do it in one 32-bit write (EP descriptors are | ||
2282 | 32-bit aligned). */ | ||
2283 | TxBulkEPList[epid].next = virt_to_phys(&TxBulkDummyEPList[epid][0]); | ||
2284 | } | ||
2285 | /* Enable the EP descr. */ | ||
2286 | dbg_bulk("Enabling bulk EP for urb 0x%lx, epid %d", (unsigned long)urb, epid); | ||
2287 | TxBulkEPList[epid].command |= IO_STATE(USB_EP_command, enable, yes); | ||
2288 | |||
2289 | /* Everything is set up, safe to enable interrupts again. */ | ||
2290 | restore_flags(flags); | ||
2291 | |||
2292 | /* If the DMA bulk channel isn't running, we need to restart it if it | ||
2293 | has stopped at the last EP descriptor (DMA stopped because there was | ||
2294 | no more traffic) or if it has stopped at a dummy EP with the intr flag | ||
2295 | set (DMA stopped because we were too slow in inserting new traffic). */ | ||
2296 | if (!(*R_DMA_CH8_SUB0_CMD & IO_MASK(R_DMA_CH8_SUB0_CMD, cmd))) { | ||
2297 | |||
2298 | USB_EP_Desc_t *ep; | ||
2299 | ep = (USB_EP_Desc_t *)phys_to_virt(*R_DMA_CH8_SUB0_EP); | ||
2300 | dbg_bulk("DMA channel not running in add"); | ||
2301 | dbg_bulk("DMA is at 0x%lx", (unsigned long)ep); | ||
2302 | |||
2303 | if (*R_DMA_CH8_SUB0_EP == virt_to_phys(&TxBulkEPList[NBR_OF_EPIDS - 1]) || | ||
2304 | (ep->command & 0x8) >> 3) { | ||
2305 | *R_DMA_CH8_SUB0_CMD = IO_STATE(R_DMA_CH8_SUB0_CMD, cmd, start); | ||
2306 | /* Update/restart the bulk start timer since we just started the channel. */ | ||
2307 | mod_timer(&bulk_start_timer, jiffies + BULK_START_TIMER_INTERVAL); | ||
2308 | /* Update/restart the bulk eot timer since we just inserted traffic. */ | ||
2309 | mod_timer(&bulk_eot_timer, jiffies + BULK_EOT_TIMER_INTERVAL); | ||
2310 | } | ||
2311 | } | ||
2312 | |||
2313 | DBFEXIT; | ||
2314 | } | ||
2315 | |||
2316 | static void etrax_usb_complete_bulk_urb(struct urb *urb, int status) | ||
2317 | { | ||
2318 | etrax_urb_priv_t *urb_priv = (etrax_urb_priv_t *)urb->hcpriv; | ||
2319 | int epid = urb_priv->epid; | ||
2320 | unsigned long flags; | ||
2321 | |||
2322 | DBFENTER; | ||
2323 | |||
2324 | if (status) | ||
2325 | warn("Completing bulk urb with status %d.", status); | ||
2326 | |||
2327 | dbg_bulk("Completing bulk urb 0x%lx for epid %d", (unsigned long)urb, epid); | ||
2328 | |||
2329 | /* Update the urb list. */ | ||
2330 | urb_list_del(urb, epid); | ||
2331 | |||
2332 | /* For an IN pipe, we always set the actual length, regardless of whether there was | ||
2333 | an error or not (which means the device driver can use the data if it wants to). */ | ||
2334 | if (usb_pipein(urb->pipe)) { | ||
2335 | urb->actual_length = urb_priv->rx_offset; | ||
2336 | } else { | ||
2337 | /* Set actual_length for OUT urbs also; the USB mass storage driver seems | ||
2338 | to want that. We wouldn't know of any partial writes if there was an error. */ | ||
2339 | if (status == 0) { | ||
2340 | urb->actual_length = urb->transfer_buffer_length; | ||
2341 | } else { | ||
2342 | urb->actual_length = 0; | ||
2343 | } | ||
2344 | } | ||
2345 | |||
2346 | /* FIXME: Is there something of the things below we shouldn't do if there was an error? | ||
2347 | Like, maybe we shouldn't toggle the toggle bits, or maybe we shouldn't insert more traffic. */ | ||
2348 | |||
2349 | save_flags(flags); | ||
2350 | cli(); | ||
2351 | |||
2352 | *R_USB_EPT_INDEX = IO_FIELD(R_USB_EPT_INDEX, value, epid); | ||
2353 | nop(); | ||
2354 | |||
2355 | /* We need to fiddle with the toggle bits because the hardware doesn't do it for us. */ | ||
2356 | if (usb_pipeout(urb->pipe)) { | ||
2357 | char toggle = | ||
2358 | IO_EXTRACT(R_USB_EPT_DATA, t_out, *R_USB_EPT_DATA); | ||
2359 | usb_settoggle(urb->dev, usb_pipeendpoint(urb->pipe), | ||
2360 | usb_pipeout(urb->pipe), toggle); | ||
2361 | } else { | ||
2362 | char toggle = | ||
2363 | IO_EXTRACT(R_USB_EPT_DATA, t_in, *R_USB_EPT_DATA); | ||
2364 | usb_settoggle(urb->dev, usb_pipeendpoint(urb->pipe), | ||
2365 | usb_pipeout(urb->pipe), toggle); | ||
2366 | } | ||
2367 | restore_flags(flags); | ||
2368 | |||
2369 | /* Remember to free the SBs. */ | ||
2370 | etrax_remove_from_sb_list(urb); | ||
2371 | kfree(urb_priv); | ||
2372 | urb->hcpriv = 0; | ||
2373 | |||
2374 | /* If there are any more urb's in the list we'd better start sending */ | ||
2375 | if (!urb_list_empty(epid)) { | ||
2376 | |||
2377 | struct urb *new_urb; | ||
2378 | |||
2379 | /* Get the first urb. */ | ||
2380 | new_urb = urb_list_first(epid); | ||
2381 | assert(new_urb); | ||
2382 | |||
2383 | dbg_bulk("More bulk for epid %d", epid); | ||
2384 | |||
2385 | etrax_usb_add_to_bulk_sb_list(new_urb, epid); | ||
2386 | } | ||
2387 | |||
2388 | urb->status = status; | ||
2389 | |||
2390 | /* We let any non-zero status from the layer above have precedence. */ | ||
2391 | if (status == 0) { | ||
2392 | /* URB_SHORT_NOT_OK means that short reads (shorter than the endpoint's max length) | ||
2393 | is to be treated as an error. */ | ||
2394 | if (urb->transfer_flags & URB_SHORT_NOT_OK) { | ||
2395 | if (usb_pipein(urb->pipe) && | ||
2396 | (urb->actual_length != | ||
2397 | usb_maxpacket(urb->dev, urb->pipe, usb_pipeout(urb->pipe)))) { | ||
2398 | urb->status = -EREMOTEIO; | ||
2399 | } | ||
2400 | } | ||
2401 | } | ||
2402 | |||
2403 | if (urb->complete) { | ||
2404 | urb->complete(urb, NULL); | ||
2405 | } | ||
2406 | |||
2407 | if (urb_list_empty(epid)) { | ||
2408 | /* This means that this EP is now free, deconfigure it. */ | ||
2409 | etrax_usb_free_epid(epid); | ||
2410 | |||
2411 | /* No more traffic; time to clean up. | ||
2412 | Must set sub pointer to 0, since we look at the sub pointer when handling | ||
2413 | the bulk eot interrupt. */ | ||
2414 | |||
2415 | dbg_bulk("No bulk for epid %d", epid); | ||
2416 | |||
2417 | TxBulkEPList[epid].sub = 0; | ||
2418 | |||
2419 | /* Unlink the dummy list. */ | ||
2420 | |||
2421 | dbg_bulk("Kicking dummy list out of party for urb 0x%lx, epid %d", | ||
2422 | (unsigned long)urb, epid); | ||
2423 | |||
2424 | /* No need to wait for the DMA before changing the next pointer. | ||
2425 | The modulo NBR_OF_EPIDS isn't actually necessary, since we will never use | ||
2426 | the last one (INVALID_EPID) for actual traffic. */ | ||
2427 | TxBulkEPList[epid].next = | ||
2428 | virt_to_phys(&TxBulkEPList[(epid + 1) % NBR_OF_EPIDS]); | ||
2429 | } | ||
2430 | |||
2431 | DBFEXIT; | ||
2432 | } | ||
2433 | |||
2434 | static int etrax_usb_submit_ctrl_urb(struct urb *urb) | ||
2435 | { | ||
2436 | int epid; | ||
2437 | int empty; | ||
2438 | unsigned long flags; | ||
2439 | etrax_urb_priv_t *urb_priv; | ||
2440 | |||
2441 | DBFENTER; | ||
2442 | |||
2443 | /* FIXME: Return -ENXIO if there is already a queued urb for this endpoint? */ | ||
2444 | |||
2445 | /* Epid allocation, empty check and list add must be protected. | ||
2446 | |||
2447 | Epid allocation because if we find an existing epid for this endpoint an urb might be | ||
2448 | completed (emptying the list) before we add the new urb to the list, causing the epid | ||
2449 | to be de-allocated. We would then start the transfer with an invalid epid -> epid attn. | ||
2450 | |||
2451 | Empty check and add because otherwise we might conclude that the list is not empty, | ||
2452 | after which it becomes empty before we add the new urb to the list, causing us not to | ||
2453 | insert the new traffic into the SB list. */ | ||
2454 | |||
2455 | spin_lock_irqsave(&urb_list_lock, flags); | ||
2456 | epid = etrax_usb_setup_epid(urb); | ||
2457 | if (epid == -1) { | ||
2458 | spin_unlock_irqrestore(&urb_list_lock, flags); | ||
2459 | DBFEXIT; | ||
2460 | return -ENOMEM; | ||
2461 | } | ||
2462 | empty = urb_list_empty(epid); | ||
2463 | urb_list_add(urb, epid); | ||
2464 | spin_unlock_irqrestore(&urb_list_lock, flags); | ||
2465 | |||
2466 | dbg_ctrl("Adding ctrl urb 0x%lx to %s list, epid %d", | ||
2467 | (unsigned long)urb, empty ? "empty" : "", epid); | ||
2468 | |||
2469 | /* Mark the urb as being in progress. */ | ||
2470 | urb->status = -EINPROGRESS; | ||
2471 | |||
2472 | /* Setup the hcpriv data. */ | ||
2473 | urb_priv = kzalloc(sizeof(etrax_urb_priv_t), KMALLOC_FLAG); | ||
2474 | assert(urb_priv != NULL); | ||
2475 | /* This sets rx_offset to 0. */ | ||
2476 | urb_priv->urb_state = NOT_STARTED; | ||
2477 | urb->hcpriv = urb_priv; | ||
2478 | |||
2479 | if (empty) { | ||
2480 | etrax_usb_add_to_ctrl_sb_list(urb, epid); | ||
2481 | } | ||
2482 | |||
2483 | DBFEXIT; | ||
2484 | |||
2485 | return 0; | ||
2486 | } | ||
2487 | |||
2488 | static void etrax_usb_add_to_ctrl_sb_list(struct urb *urb, int epid) | ||
2489 | { | ||
2490 | USB_SB_Desc_t *sb_desc_setup; | ||
2491 | USB_SB_Desc_t *sb_desc_data; | ||
2492 | USB_SB_Desc_t *sb_desc_status; | ||
2493 | |||
2494 | etrax_urb_priv_t *urb_priv = (etrax_urb_priv_t *)urb->hcpriv; | ||
2495 | |||
2496 | unsigned long flags; | ||
2497 | char maxlen; | ||
2498 | |||
2499 | DBFENTER; | ||
2500 | |||
2501 | maxlen = usb_maxpacket(urb->dev, urb->pipe, usb_pipeout(urb->pipe)); | ||
2502 | |||
2503 | sb_desc_setup = (USB_SB_Desc_t*)kmem_cache_alloc(usb_desc_cache, SLAB_FLAG); | ||
2504 | assert(sb_desc_setup != NULL); | ||
2505 | sb_desc_status = (USB_SB_Desc_t*)kmem_cache_alloc(usb_desc_cache, SLAB_FLAG); | ||
2506 | assert(sb_desc_status != NULL); | ||
2507 | |||
2508 | /* Initialize the mandatory setup SB descriptor (used only in control transfers) */ | ||
2509 | sb_desc_setup->sw_len = 8; | ||
2510 | sb_desc_setup->command = (IO_FIELD(USB_SB_command, rem, 0) | | ||
2511 | IO_STATE(USB_SB_command, tt, setup) | | ||
2512 | IO_STATE(USB_SB_command, full, yes) | | ||
2513 | IO_STATE(USB_SB_command, eot, yes)); | ||
2514 | |||
2515 | sb_desc_setup->buf = virt_to_phys(urb->setup_packet); | ||
2516 | |||
2517 | if (usb_pipeout(urb->pipe)) { | ||
2518 | dbg_ctrl("Transfer for epid %d is OUT", epid); | ||
2519 | |||
2520 | /* If this Control OUT transfer has an optional data stage we add an OUT token | ||
2521 | before the mandatory IN (status) token, hence the reordered SB list */ | ||
2522 | |||
2523 | sb_desc_setup->next = virt_to_phys(sb_desc_status); | ||
2524 | if (urb->transfer_buffer) { | ||
2525 | |||
2526 | dbg_ctrl("This OUT transfer has an extra data stage"); | ||
2527 | |||
2528 | sb_desc_data = (USB_SB_Desc_t*)kmem_cache_alloc(usb_desc_cache, SLAB_FLAG); | ||
2529 | assert(sb_desc_data != NULL); | ||
2530 | |||
2531 | sb_desc_setup->next = virt_to_phys(sb_desc_data); | ||
2532 | |||
2533 | sb_desc_data->sw_len = urb->transfer_buffer_length; | ||
2534 | sb_desc_data->command = (IO_STATE(USB_SB_command, tt, out) | | ||
2535 | IO_STATE(USB_SB_command, full, yes) | | ||
2536 | IO_STATE(USB_SB_command, eot, yes)); | ||
2537 | sb_desc_data->buf = virt_to_phys(urb->transfer_buffer); | ||
2538 | sb_desc_data->next = virt_to_phys(sb_desc_status); | ||
2539 | } | ||
2540 | |||
2541 | sb_desc_status->sw_len = 1; | ||
2542 | sb_desc_status->command = (IO_FIELD(USB_SB_command, rem, 0) | | ||
2543 | IO_STATE(USB_SB_command, tt, in) | | ||
2544 | IO_STATE(USB_SB_command, eot, yes) | | ||
2545 | IO_STATE(USB_SB_command, intr, yes) | | ||
2546 | IO_STATE(USB_SB_command, eol, yes)); | ||
2547 | |||
2548 | sb_desc_status->buf = 0; | ||
2549 | sb_desc_status->next = 0; | ||
2550 | |||
2551 | } else if (usb_pipein(urb->pipe)) { | ||
2552 | |||
2553 | dbg_ctrl("Transfer for epid %d is IN", epid); | ||
2554 | dbg_ctrl("transfer_buffer_length = %d", urb->transfer_buffer_length); | ||
2555 | dbg_ctrl("rem is calculated to %d", urb->transfer_buffer_length % maxlen); | ||
2556 | |||
2557 | sb_desc_data = (USB_SB_Desc_t*)kmem_cache_alloc(usb_desc_cache, SLAB_FLAG); | ||
2558 | assert(sb_desc_data != NULL); | ||
2559 | |||
2560 | sb_desc_setup->next = virt_to_phys(sb_desc_data); | ||
2561 | |||
2562 | sb_desc_data->sw_len = urb->transfer_buffer_length ? | ||
2563 | (urb->transfer_buffer_length - 1) / maxlen + 1 : 0; | ||
2564 | dbg_ctrl("sw_len got %d", sb_desc_data->sw_len); | ||
2565 | |||
2566 | sb_desc_data->command = | ||
2567 | (IO_FIELD(USB_SB_command, rem, | ||
2568 | urb->transfer_buffer_length % maxlen) | | ||
2569 | IO_STATE(USB_SB_command, tt, in) | | ||
2570 | IO_STATE(USB_SB_command, eot, yes)); | ||
2571 | |||
2572 | sb_desc_data->buf = 0; | ||
2573 | sb_desc_data->next = virt_to_phys(sb_desc_status); | ||
2574 | |||
2575 | /* Read comment at zout_buffer declaration for an explanation to this. */ | ||
2576 | sb_desc_status->sw_len = 1; | ||
2577 | sb_desc_status->command = (IO_FIELD(USB_SB_command, rem, 0) | | ||
2578 | IO_STATE(USB_SB_command, tt, zout) | | ||
2579 | IO_STATE(USB_SB_command, full, yes) | | ||
2580 | IO_STATE(USB_SB_command, eot, yes) | | ||
2581 | IO_STATE(USB_SB_command, intr, yes) | | ||
2582 | IO_STATE(USB_SB_command, eol, yes)); | ||
2583 | |||
2584 | sb_desc_status->buf = virt_to_phys(&zout_buffer[0]); | ||
2585 | sb_desc_status->next = 0; | ||
2586 | } | ||
2587 | |||
2588 | urb_priv->first_sb = sb_desc_setup; | ||
2589 | urb_priv->last_sb = sb_desc_status; | ||
2590 | urb_priv->epid = epid; | ||
2591 | |||
2592 | urb_priv->urb_state = STARTED; | ||
2593 | |||
2594 | /* Reset toggle bits and reset error count, remember to di and ei */ | ||
2595 | /* Warning: it is possible that this locking doesn't work with bottom-halves */ | ||
2596 | |||
2597 | save_flags(flags); | ||
2598 | cli(); | ||
2599 | |||
2600 | *R_USB_EPT_INDEX = IO_FIELD(R_USB_EPT_INDEX, value, epid); | ||
2601 | nop(); | ||
2602 | if (*R_USB_EPT_DATA & IO_MASK(R_USB_EPT_DATA, hold)) { | ||
2603 | panic("Hold was set in %s", __FUNCTION__); | ||
2604 | } | ||
2605 | |||
2606 | |||
2607 | /* FIXME: Compare with etrax_usb_add_to_bulk_sb_list where the toggle bits | ||
2608 | are set to a specific value. Why the difference? Read "Transfer and Toggle Bits | ||
2609 | in Designer's Reference, p. 8 - 11. */ | ||
2610 | *R_USB_EPT_DATA &= | ||
2611 | ~(IO_MASK(R_USB_EPT_DATA, error_count_in) | | ||
2612 | IO_MASK(R_USB_EPT_DATA, error_count_out) | | ||
2613 | IO_MASK(R_USB_EPT_DATA, t_in) | | ||
2614 | IO_MASK(R_USB_EPT_DATA, t_out)); | ||
2615 | |||
2616 | /* Since we use the rx interrupt to complete ctrl urbs, we can enable interrupts now | ||
2617 | (i.e. we don't check the sub pointer on an eot interrupt like we do for bulk traffic). */ | ||
2618 | restore_flags(flags); | ||
2619 | |||
2620 | /* Assert that the EP descriptor is disabled. */ | ||
2621 | assert(!(TxCtrlEPList[epid].command & IO_MASK(USB_EP_command, enable))); | ||
2622 | |||
2623 | /* Set up and enable the EP descriptor. */ | ||
2624 | TxCtrlEPList[epid].sub = virt_to_phys(sb_desc_setup); | ||
2625 | TxCtrlEPList[epid].hw_len = 0; | ||
2626 | TxCtrlEPList[epid].command |= IO_STATE(USB_EP_command, enable, yes); | ||
2627 | |||
2628 | /* We start the DMA sub channel without checking if it's running or not, because: | ||
2629 | 1) If it's already running, issuing the start command is a nop. | ||
2630 | 2) We avoid a test-and-set race condition. */ | ||
2631 | *R_DMA_CH8_SUB1_CMD = IO_STATE(R_DMA_CH8_SUB1_CMD, cmd, start); | ||
2632 | |||
2633 | DBFEXIT; | ||
2634 | } | ||
2635 | |||
2636 | static void etrax_usb_complete_ctrl_urb(struct urb *urb, int status) | ||
2637 | { | ||
2638 | etrax_urb_priv_t *urb_priv = (etrax_urb_priv_t *)urb->hcpriv; | ||
2639 | int epid = urb_priv->epid; | ||
2640 | |||
2641 | DBFENTER; | ||
2642 | |||
2643 | if (status) | ||
2644 | warn("Completing ctrl urb with status %d.", status); | ||
2645 | |||
2646 | dbg_ctrl("Completing ctrl epid %d, urb 0x%lx", epid, (unsigned long)urb); | ||
2647 | |||
2648 | /* Remove this urb from the list. */ | ||
2649 | urb_list_del(urb, epid); | ||
2650 | |||
2651 | /* For an IN pipe, we always set the actual length, regardless of whether there was | ||
2652 | an error or not (which means the device driver can use the data if it wants to). */ | ||
2653 | if (usb_pipein(urb->pipe)) { | ||
2654 | urb->actual_length = urb_priv->rx_offset; | ||
2655 | } | ||
2656 | |||
2657 | /* FIXME: Is there something of the things below we shouldn't do if there was an error? | ||
2658 | Like, maybe we shouldn't insert more traffic. */ | ||
2659 | |||
2660 | /* Remember to free the SBs. */ | ||
2661 | etrax_remove_from_sb_list(urb); | ||
2662 | kfree(urb_priv); | ||
2663 | urb->hcpriv = 0; | ||
2664 | |||
2665 | /* If there are any more urbs in the list we'd better start sending. */ | ||
2666 | if (!urb_list_empty(epid)) { | ||
2667 | struct urb *new_urb; | ||
2668 | |||
2669 | /* Get the first urb. */ | ||
2670 | new_urb = urb_list_first(epid); | ||
2671 | assert(new_urb); | ||
2672 | |||
2673 | dbg_ctrl("More ctrl for epid %d, first urb = 0x%lx", epid, (unsigned long)new_urb); | ||
2674 | |||
2675 | etrax_usb_add_to_ctrl_sb_list(new_urb, epid); | ||
2676 | } | ||
2677 | |||
2678 | urb->status = status; | ||
2679 | |||
2680 | /* We let any non-zero status from the layer above have precedence. */ | ||
2681 | if (status == 0) { | ||
2682 | /* URB_SHORT_NOT_OK means that short reads (shorter than the endpoint's max length) | ||
2683 | is to be treated as an error. */ | ||
2684 | if (urb->transfer_flags & URB_SHORT_NOT_OK) { | ||
2685 | if (usb_pipein(urb->pipe) && | ||
2686 | (urb->actual_length != | ||
2687 | usb_maxpacket(urb->dev, urb->pipe, usb_pipeout(urb->pipe)))) { | ||
2688 | urb->status = -EREMOTEIO; | ||
2689 | } | ||
2690 | } | ||
2691 | } | ||
2692 | |||
2693 | if (urb->complete) { | ||
2694 | urb->complete(urb, NULL); | ||
2695 | } | ||
2696 | |||
2697 | if (urb_list_empty(epid)) { | ||
2698 | /* No more traffic. Time to clean up. */ | ||
2699 | etrax_usb_free_epid(epid); | ||
2700 | /* Must set sub pointer to 0. */ | ||
2701 | dbg_ctrl("No ctrl for epid %d", epid); | ||
2702 | TxCtrlEPList[epid].sub = 0; | ||
2703 | } | ||
2704 | |||
2705 | DBFEXIT; | ||
2706 | } | ||
2707 | |||
2708 | static int etrax_usb_submit_intr_urb(struct urb *urb) | ||
2709 | { | ||
2710 | |||
2711 | int epid; | ||
2712 | |||
2713 | DBFENTER; | ||
2714 | |||
2715 | if (usb_pipeout(urb->pipe)) { | ||
2716 | /* Unsupported transfer type. | ||
2717 | We don't support interrupt out traffic. (If we do, we can't support | ||
2718 | intervals for neither in or out traffic, but are forced to schedule all | ||
2719 | interrupt traffic in one frame.) */ | ||
2720 | return -EINVAL; | ||
2721 | } | ||
2722 | |||
2723 | epid = etrax_usb_setup_epid(urb); | ||
2724 | if (epid == -1) { | ||
2725 | DBFEXIT; | ||
2726 | return -ENOMEM; | ||
2727 | } | ||
2728 | |||
2729 | if (!urb_list_empty(epid)) { | ||
2730 | /* There is already a queued urb for this endpoint. */ | ||
2731 | etrax_usb_free_epid(epid); | ||
2732 | return -ENXIO; | ||
2733 | } | ||
2734 | |||
2735 | urb->status = -EINPROGRESS; | ||
2736 | |||
2737 | dbg_intr("Add intr urb 0x%lx, to list, epid %d", (unsigned long)urb, epid); | ||
2738 | |||
2739 | urb_list_add(urb, epid); | ||
2740 | etrax_usb_add_to_intr_sb_list(urb, epid); | ||
2741 | |||
2742 | return 0; | ||
2743 | |||
2744 | DBFEXIT; | ||
2745 | } | ||
2746 | |||
2747 | static void etrax_usb_add_to_intr_sb_list(struct urb *urb, int epid) | ||
2748 | { | ||
2749 | |||
2750 | volatile USB_EP_Desc_t *tmp_ep; | ||
2751 | volatile USB_EP_Desc_t *first_ep; | ||
2752 | |||
2753 | char maxlen; | ||
2754 | int interval; | ||
2755 | int i; | ||
2756 | |||
2757 | etrax_urb_priv_t *urb_priv; | ||
2758 | |||
2759 | DBFENTER; | ||
2760 | |||
2761 | maxlen = usb_maxpacket(urb->dev, urb->pipe, usb_pipeout(urb->pipe)); | ||
2762 | interval = urb->interval; | ||
2763 | |||
2764 | urb_priv = kzalloc(sizeof(etrax_urb_priv_t), KMALLOC_FLAG); | ||
2765 | assert(urb_priv != NULL); | ||
2766 | urb->hcpriv = urb_priv; | ||
2767 | |||
2768 | first_ep = &TxIntrEPList[0]; | ||
2769 | |||
2770 | /* Round of the interval to 2^n, it is obvious that this code favours | ||
2771 | smaller numbers, but that is actually a good thing */ | ||
2772 | /* FIXME: The "rounding error" for larger intervals will be quite | ||
2773 | large. For in traffic this shouldn't be a problem since it will only | ||
2774 | mean that we "poll" more often. */ | ||
2775 | for (i = 0; interval; i++) { | ||
2776 | interval = interval >> 1; | ||
2777 | } | ||
2778 | interval = 1 << (i - 1); | ||
2779 | |||
2780 | dbg_intr("Interval rounded to %d", interval); | ||
2781 | |||
2782 | tmp_ep = first_ep; | ||
2783 | i = 0; | ||
2784 | do { | ||
2785 | if (tmp_ep->command & IO_MASK(USB_EP_command, eof)) { | ||
2786 | if ((i % interval) == 0) { | ||
2787 | /* Insert the traffic ep after tmp_ep */ | ||
2788 | USB_EP_Desc_t *ep_desc; | ||
2789 | USB_SB_Desc_t *sb_desc; | ||
2790 | |||
2791 | dbg_intr("Inserting EP for epid %d", epid); | ||
2792 | |||
2793 | ep_desc = (USB_EP_Desc_t *) | ||
2794 | kmem_cache_alloc(usb_desc_cache, SLAB_FLAG); | ||
2795 | sb_desc = (USB_SB_Desc_t *) | ||
2796 | kmem_cache_alloc(usb_desc_cache, SLAB_FLAG); | ||
2797 | assert(ep_desc != NULL); | ||
2798 | CHECK_ALIGN(ep_desc); | ||
2799 | assert(sb_desc != NULL); | ||
2800 | |||
2801 | ep_desc->sub = virt_to_phys(sb_desc); | ||
2802 | ep_desc->hw_len = 0; | ||
2803 | ep_desc->command = (IO_FIELD(USB_EP_command, epid, epid) | | ||
2804 | IO_STATE(USB_EP_command, enable, yes)); | ||
2805 | |||
2806 | |||
2807 | /* Round upwards the number of packets of size maxlen | ||
2808 | that this SB descriptor should receive. */ | ||
2809 | sb_desc->sw_len = urb->transfer_buffer_length ? | ||
2810 | (urb->transfer_buffer_length - 1) / maxlen + 1 : 0; | ||
2811 | sb_desc->next = 0; | ||
2812 | sb_desc->buf = 0; | ||
2813 | sb_desc->command = | ||
2814 | (IO_FIELD(USB_SB_command, rem, urb->transfer_buffer_length % maxlen) | | ||
2815 | IO_STATE(USB_SB_command, tt, in) | | ||
2816 | IO_STATE(USB_SB_command, eot, yes) | | ||
2817 | IO_STATE(USB_SB_command, eol, yes)); | ||
2818 | |||
2819 | ep_desc->next = tmp_ep->next; | ||
2820 | tmp_ep->next = virt_to_phys(ep_desc); | ||
2821 | } | ||
2822 | i++; | ||
2823 | } | ||
2824 | tmp_ep = (USB_EP_Desc_t *)phys_to_virt(tmp_ep->next); | ||
2825 | } while (tmp_ep != first_ep); | ||
2826 | |||
2827 | |||
2828 | /* Note that first_sb/last_sb doesn't apply to interrupt traffic. */ | ||
2829 | urb_priv->epid = epid; | ||
2830 | |||
2831 | /* We start the DMA sub channel without checking if it's running or not, because: | ||
2832 | 1) If it's already running, issuing the start command is a nop. | ||
2833 | 2) We avoid a test-and-set race condition. */ | ||
2834 | *R_DMA_CH8_SUB2_CMD = IO_STATE(R_DMA_CH8_SUB2_CMD, cmd, start); | ||
2835 | |||
2836 | DBFEXIT; | ||
2837 | } | ||
2838 | |||
2839 | |||
2840 | |||
2841 | static void etrax_usb_complete_intr_urb(struct urb *urb, int status) | ||
2842 | { | ||
2843 | etrax_urb_priv_t *urb_priv = (etrax_urb_priv_t *)urb->hcpriv; | ||
2844 | int epid = urb_priv->epid; | ||
2845 | |||
2846 | DBFENTER; | ||
2847 | |||
2848 | if (status) | ||
2849 | warn("Completing intr urb with status %d.", status); | ||
2850 | |||
2851 | dbg_intr("Completing intr epid %d, urb 0x%lx", epid, (unsigned long)urb); | ||
2852 | |||
2853 | urb->status = status; | ||
2854 | urb->actual_length = urb_priv->rx_offset; | ||
2855 | |||
2856 | dbg_intr("interrupt urb->actual_length = %d", urb->actual_length); | ||
2857 | |||
2858 | /* We let any non-zero status from the layer above have precedence. */ | ||
2859 | if (status == 0) { | ||
2860 | /* URB_SHORT_NOT_OK means that short reads (shorter than the endpoint's max length) | ||
2861 | is to be treated as an error. */ | ||
2862 | if (urb->transfer_flags & URB_SHORT_NOT_OK) { | ||
2863 | if (urb->actual_length != | ||
2864 | usb_maxpacket(urb->dev, urb->pipe, usb_pipeout(urb->pipe))) { | ||
2865 | urb->status = -EREMOTEIO; | ||
2866 | } | ||
2867 | } | ||
2868 | } | ||
2869 | |||
2870 | /* The driver will resubmit the URB so we need to remove it first */ | ||
2871 | etrax_usb_unlink_urb(urb, 0); | ||
2872 | if (urb->complete) { | ||
2873 | urb->complete(urb, NULL); | ||
2874 | } | ||
2875 | |||
2876 | DBFEXIT; | ||
2877 | } | ||
2878 | |||
2879 | |||
2880 | static int etrax_usb_submit_isoc_urb(struct urb *urb) | ||
2881 | { | ||
2882 | int epid; | ||
2883 | unsigned long flags; | ||
2884 | |||
2885 | DBFENTER; | ||
2886 | |||
2887 | dbg_isoc("Submitting isoc urb = 0x%lx", (unsigned long)urb); | ||
2888 | |||
2889 | /* Epid allocation, empty check and list add must be protected. | ||
2890 | Read about this in etrax_usb_submit_ctrl_urb. */ | ||
2891 | |||
2892 | spin_lock_irqsave(&urb_list_lock, flags); | ||
2893 | /* Is there an active epid for this urb ? */ | ||
2894 | epid = etrax_usb_setup_epid(urb); | ||
2895 | if (epid == -1) { | ||
2896 | DBFEXIT; | ||
2897 | spin_unlock_irqrestore(&urb_list_lock, flags); | ||
2898 | return -ENOMEM; | ||
2899 | } | ||
2900 | |||
2901 | /* Ok, now we got valid endpoint, lets insert some traffic */ | ||
2902 | |||
2903 | urb->status = -EINPROGRESS; | ||
2904 | |||
2905 | /* Find the last urb in the URB_List and add this urb after that one. | ||
2906 | Also add the traffic, that is do an etrax_usb_add_to_isoc_sb_list. This | ||
2907 | is important to make this in "real time" since isochronous traffic is | ||
2908 | time sensitive. */ | ||
2909 | |||
2910 | dbg_isoc("Adding isoc urb to (possibly empty) list"); | ||
2911 | urb_list_add(urb, epid); | ||
2912 | etrax_usb_add_to_isoc_sb_list(urb, epid); | ||
2913 | spin_unlock_irqrestore(&urb_list_lock, flags); | ||
2914 | |||
2915 | DBFEXIT; | ||
2916 | |||
2917 | return 0; | ||
2918 | } | ||
2919 | |||
2920 | static void etrax_usb_check_error_isoc_ep(const int epid) | ||
2921 | { | ||
2922 | unsigned long int flags; | ||
2923 | int error_code; | ||
2924 | __u32 r_usb_ept_data; | ||
2925 | |||
2926 | /* We can't read R_USB_EPID_ATTN here since it would clear the iso_eof, | ||
2927 | bulk_eot and epid_attn interrupts. So we just check the status of | ||
2928 | the epid without testing if for it in R_USB_EPID_ATTN. */ | ||
2929 | |||
2930 | |||
2931 | save_flags(flags); | ||
2932 | cli(); | ||
2933 | *R_USB_EPT_INDEX = IO_FIELD(R_USB_EPT_INDEX, value, epid); | ||
2934 | nop(); | ||
2935 | /* Note that although there are separate R_USB_EPT_DATA and R_USB_EPT_DATA_ISO | ||
2936 | registers, they are located at the same address and are of the same size. | ||
2937 | In other words, this read should be ok for isoc also. */ | ||
2938 | r_usb_ept_data = *R_USB_EPT_DATA; | ||
2939 | restore_flags(flags); | ||
2940 | |||
2941 | error_code = IO_EXTRACT(R_USB_EPT_DATA_ISO, error_code, r_usb_ept_data); | ||
2942 | |||
2943 | if (r_usb_ept_data & IO_MASK(R_USB_EPT_DATA, hold)) { | ||
2944 | warn("Hold was set for epid %d.", epid); | ||
2945 | return; | ||
2946 | } | ||
2947 | |||
2948 | if (error_code == IO_STATE_VALUE(R_USB_EPT_DATA_ISO, error_code, no_error)) { | ||
2949 | |||
2950 | /* This indicates that the SB list of the ept was completed before | ||
2951 | new data was appended to it. This is not an error, but indicates | ||
2952 | large system or USB load and could possibly cause trouble for | ||
2953 | very timing sensitive USB device drivers so we log it. | ||
2954 | */ | ||
2955 | info("Isoc. epid %d disabled with no error", epid); | ||
2956 | return; | ||
2957 | |||
2958 | } else if (error_code == IO_STATE_VALUE(R_USB_EPT_DATA_ISO, error_code, stall)) { | ||
2959 | /* Not really a protocol error, just says that the endpoint gave | ||
2960 | a stall response. Note that error_code cannot be stall for isoc. */ | ||
2961 | panic("Isoc traffic cannot stall"); | ||
2962 | |||
2963 | } else if (error_code == IO_STATE_VALUE(R_USB_EPT_DATA_ISO, error_code, bus_error)) { | ||
2964 | /* Two devices responded to a transaction request. Must be resolved | ||
2965 | by software. FIXME: Reset ports? */ | ||
2966 | panic("Bus error for epid %d." | ||
2967 | " Two devices responded to transaction request", | ||
2968 | epid); | ||
2969 | |||
2970 | } else if (error_code == IO_STATE_VALUE(R_USB_EPT_DATA, error_code, buffer_error)) { | ||
2971 | /* DMA overrun or underrun. */ | ||
2972 | warn("Buffer overrun/underrun for epid %d. DMA too busy?", epid); | ||
2973 | |||
2974 | /* It seems that error_code = buffer_error in | ||
2975 | R_USB_EPT_DATA/R_USB_EPT_DATA_ISO and ourun = yes in R_USB_STATUS | ||
2976 | are the same error. */ | ||
2977 | } | ||
2978 | } | ||
2979 | |||
2980 | |||
2981 | static void etrax_usb_add_to_isoc_sb_list(struct urb *urb, int epid) | ||
2982 | { | ||
2983 | |||
2984 | int i = 0; | ||
2985 | |||
2986 | etrax_urb_priv_t *urb_priv; | ||
2987 | USB_SB_Desc_t *prev_sb_desc, *next_sb_desc, *temp_sb_desc; | ||
2988 | |||
2989 | DBFENTER; | ||
2990 | |||
2991 | prev_sb_desc = next_sb_desc = temp_sb_desc = NULL; | ||
2992 | |||
2993 | urb_priv = kzalloc(sizeof(etrax_urb_priv_t), GFP_ATOMIC); | ||
2994 | assert(urb_priv != NULL); | ||
2995 | |||
2996 | urb->hcpriv = urb_priv; | ||
2997 | urb_priv->epid = epid; | ||
2998 | |||
2999 | if (usb_pipeout(urb->pipe)) { | ||
3000 | |||
3001 | if (urb->number_of_packets == 0) panic("etrax_usb_add_to_isoc_sb_list 0 packets\n"); | ||
3002 | |||
3003 | dbg_isoc("Transfer for epid %d is OUT", epid); | ||
3004 | dbg_isoc("%d packets in URB", urb->number_of_packets); | ||
3005 | |||
3006 | /* Create one SB descriptor for each packet and link them together. */ | ||
3007 | for (i = 0; i < urb->number_of_packets; i++) { | ||
3008 | if (!urb->iso_frame_desc[i].length) | ||
3009 | continue; | ||
3010 | |||
3011 | next_sb_desc = (USB_SB_Desc_t*)kmem_cache_alloc(usb_desc_cache, GFP_ATOMIC); | ||
3012 | assert(next_sb_desc != NULL); | ||
3013 | |||
3014 | if (urb->iso_frame_desc[i].length > 0) { | ||
3015 | |||
3016 | next_sb_desc->command = (IO_STATE(USB_SB_command, tt, out) | | ||
3017 | IO_STATE(USB_SB_command, eot, yes)); | ||
3018 | |||
3019 | next_sb_desc->sw_len = urb->iso_frame_desc[i].length; | ||
3020 | next_sb_desc->buf = virt_to_phys((char*)urb->transfer_buffer + urb->iso_frame_desc[i].offset); | ||
3021 | |||
3022 | /* Check if full length transfer. */ | ||
3023 | if (urb->iso_frame_desc[i].length == | ||
3024 | usb_maxpacket(urb->dev, urb->pipe, usb_pipeout(urb->pipe))) { | ||
3025 | next_sb_desc->command |= IO_STATE(USB_SB_command, full, yes); | ||
3026 | } | ||
3027 | } else { | ||
3028 | dbg_isoc("zero len packet"); | ||
3029 | next_sb_desc->command = (IO_FIELD(USB_SB_command, rem, 0) | | ||
3030 | IO_STATE(USB_SB_command, tt, zout) | | ||
3031 | IO_STATE(USB_SB_command, eot, yes) | | ||
3032 | IO_STATE(USB_SB_command, full, yes)); | ||
3033 | |||
3034 | next_sb_desc->sw_len = 1; | ||
3035 | next_sb_desc->buf = virt_to_phys(&zout_buffer[0]); | ||
3036 | } | ||
3037 | |||
3038 | /* First SB descriptor that belongs to this urb */ | ||
3039 | if (i == 0) | ||
3040 | urb_priv->first_sb = next_sb_desc; | ||
3041 | else | ||
3042 | prev_sb_desc->next = virt_to_phys(next_sb_desc); | ||
3043 | |||
3044 | prev_sb_desc = next_sb_desc; | ||
3045 | } | ||
3046 | |||
3047 | next_sb_desc->command |= (IO_STATE(USB_SB_command, intr, yes) | | ||
3048 | IO_STATE(USB_SB_command, eol, yes)); | ||
3049 | next_sb_desc->next = 0; | ||
3050 | urb_priv->last_sb = next_sb_desc; | ||
3051 | |||
3052 | } else if (usb_pipein(urb->pipe)) { | ||
3053 | |||
3054 | dbg_isoc("Transfer for epid %d is IN", epid); | ||
3055 | dbg_isoc("transfer_buffer_length = %d", urb->transfer_buffer_length); | ||
3056 | dbg_isoc("rem is calculated to %d", urb->iso_frame_desc[urb->number_of_packets - 1].length); | ||
3057 | |||
3058 | /* Note that in descriptors for periodic traffic are not consumed. This means that | ||
3059 | the USB controller never propagates in the SB list. In other words, if there already | ||
3060 | is an SB descriptor in the list for this EP we don't have to do anything. */ | ||
3061 | if (TxIsocEPList[epid].sub == 0) { | ||
3062 | dbg_isoc("Isoc traffic not already running, allocating SB"); | ||
3063 | |||
3064 | next_sb_desc = (USB_SB_Desc_t*)kmem_cache_alloc(usb_desc_cache, GFP_ATOMIC); | ||
3065 | assert(next_sb_desc != NULL); | ||
3066 | |||
3067 | next_sb_desc->command = (IO_STATE(USB_SB_command, tt, in) | | ||
3068 | IO_STATE(USB_SB_command, eot, yes) | | ||
3069 | IO_STATE(USB_SB_command, eol, yes)); | ||
3070 | |||
3071 | next_sb_desc->next = 0; | ||
3072 | next_sb_desc->sw_len = 1; /* Actual number of packets is not relevant | ||
3073 | for periodic in traffic as long as it is more | ||
3074 | than zero. Set to 1 always. */ | ||
3075 | next_sb_desc->buf = 0; | ||
3076 | |||
3077 | /* The rem field is don't care for isoc traffic, so we don't set it. */ | ||
3078 | |||
3079 | /* Only one SB descriptor that belongs to this urb. */ | ||
3080 | urb_priv->first_sb = next_sb_desc; | ||
3081 | urb_priv->last_sb = next_sb_desc; | ||
3082 | |||
3083 | } else { | ||
3084 | |||
3085 | dbg_isoc("Isoc traffic already running, just setting first/last_sb"); | ||
3086 | |||
3087 | /* Each EP for isoc in will have only one SB descriptor, setup when submitting the | ||
3088 | already active urb. Note that even though we may have several first_sb/last_sb | ||
3089 | pointing at the same SB descriptor, they are freed only once (when the list has | ||
3090 | become empty). */ | ||
3091 | urb_priv->first_sb = phys_to_virt(TxIsocEPList[epid].sub); | ||
3092 | urb_priv->last_sb = phys_to_virt(TxIsocEPList[epid].sub); | ||
3093 | return; | ||
3094 | } | ||
3095 | |||
3096 | } | ||
3097 | |||
3098 | /* Find the spot to insert this urb and add it. */ | ||
3099 | if (TxIsocEPList[epid].sub == 0) { | ||
3100 | /* First SB descriptor inserted in this list (in or out). */ | ||
3101 | dbg_isoc("Inserting SB desc first in list"); | ||
3102 | TxIsocEPList[epid].hw_len = 0; | ||
3103 | TxIsocEPList[epid].sub = virt_to_phys(urb_priv->first_sb); | ||
3104 | |||
3105 | } else { | ||
3106 | /* Isochronous traffic is already running, insert new traffic last (only out). */ | ||
3107 | dbg_isoc("Inserting SB desc last in list"); | ||
3108 | temp_sb_desc = phys_to_virt(TxIsocEPList[epid].sub); | ||
3109 | while ((temp_sb_desc->command & IO_MASK(USB_SB_command, eol)) != | ||
3110 | IO_STATE(USB_SB_command, eol, yes)) { | ||
3111 | assert(temp_sb_desc->next); | ||
3112 | temp_sb_desc = phys_to_virt(temp_sb_desc->next); | ||
3113 | } | ||
3114 | dbg_isoc("Appending list on desc 0x%p", temp_sb_desc); | ||
3115 | |||
3116 | /* Next pointer must be set before eol is removed. */ | ||
3117 | temp_sb_desc->next = virt_to_phys(urb_priv->first_sb); | ||
3118 | /* Clear the previous end of list flag since there is a new in the | ||
3119 | added SB descriptor list. */ | ||
3120 | temp_sb_desc->command &= ~IO_MASK(USB_SB_command, eol); | ||
3121 | |||
3122 | if (!(TxIsocEPList[epid].command & IO_MASK(USB_EP_command, enable))) { | ||
3123 | /* 8.8.5 in Designer's Reference says we should check for and correct | ||
3124 | any errors in the EP here. That should not be necessary if epid_attn | ||
3125 | is handled correctly, so we assume all is ok. */ | ||
3126 | dbg_isoc("EP disabled"); | ||
3127 | etrax_usb_check_error_isoc_ep(epid); | ||
3128 | |||
3129 | /* The SB list was exhausted. */ | ||
3130 | if (virt_to_phys(urb_priv->last_sb) != TxIsocEPList[epid].sub) { | ||
3131 | /* The new sublist did not get processed before the EP was | ||
3132 | disabled. Setup the EP again. */ | ||
3133 | dbg_isoc("Set EP sub to new list"); | ||
3134 | TxIsocEPList[epid].hw_len = 0; | ||
3135 | TxIsocEPList[epid].sub = virt_to_phys(urb_priv->first_sb); | ||
3136 | } | ||
3137 | } | ||
3138 | } | ||
3139 | |||
3140 | if (urb->transfer_flags & URB_ISO_ASAP) { | ||
3141 | /* The isoc transfer should be started as soon as possible. The start_frame | ||
3142 | field is a return value if URB_ISO_ASAP was set. Comparing R_USB_FM_NUMBER | ||
3143 | with a USB Chief trace shows that the first isoc IN token is sent 2 frames | ||
3144 | later. I'm not sure how this affects usage of the start_frame field by the | ||
3145 | device driver, or how it affects things when USB_ISO_ASAP is not set, so | ||
3146 | therefore there's no compensation for the 2 frame "lag" here. */ | ||
3147 | urb->start_frame = (*R_USB_FM_NUMBER & 0x7ff); | ||
3148 | TxIsocEPList[epid].command |= IO_STATE(USB_EP_command, enable, yes); | ||
3149 | urb_priv->urb_state = STARTED; | ||
3150 | dbg_isoc("URB_ISO_ASAP set, urb->start_frame set to %d", urb->start_frame); | ||
3151 | } else { | ||
3152 | /* Not started yet. */ | ||
3153 | urb_priv->urb_state = NOT_STARTED; | ||
3154 | dbg_isoc("urb_priv->urb_state set to NOT_STARTED"); | ||
3155 | } | ||
3156 | |||
3157 | /* We start the DMA sub channel without checking if it's running or not, because: | ||
3158 | 1) If it's already running, issuing the start command is a nop. | ||
3159 | 2) We avoid a test-and-set race condition. */ | ||
3160 | *R_DMA_CH8_SUB3_CMD = IO_STATE(R_DMA_CH8_SUB3_CMD, cmd, start); | ||
3161 | |||
3162 | DBFEXIT; | ||
3163 | } | ||
3164 | |||
3165 | static void etrax_usb_complete_isoc_urb(struct urb *urb, int status) | ||
3166 | { | ||
3167 | etrax_urb_priv_t *urb_priv = (etrax_urb_priv_t *)urb->hcpriv; | ||
3168 | int epid = urb_priv->epid; | ||
3169 | int auto_resubmit = 0; | ||
3170 | |||
3171 | DBFENTER; | ||
3172 | dbg_isoc("complete urb 0x%p, status %d", urb, status); | ||
3173 | |||
3174 | if (status) | ||
3175 | warn("Completing isoc urb with status %d.", status); | ||
3176 | |||
3177 | if (usb_pipein(urb->pipe)) { | ||
3178 | int i; | ||
3179 | |||
3180 | /* Make that all isoc packets have status and length set before | ||
3181 | completing the urb. */ | ||
3182 | for (i = urb_priv->isoc_packet_counter; i < urb->number_of_packets; i++) { | ||
3183 | urb->iso_frame_desc[i].actual_length = 0; | ||
3184 | urb->iso_frame_desc[i].status = -EPROTO; | ||
3185 | } | ||
3186 | |||
3187 | urb_list_del(urb, epid); | ||
3188 | |||
3189 | if (!list_empty(&urb_list[epid])) { | ||
3190 | ((etrax_urb_priv_t *)(urb_list_first(epid)->hcpriv))->urb_state = STARTED; | ||
3191 | } else { | ||
3192 | unsigned long int flags; | ||
3193 | if (TxIsocEPList[epid].command & IO_MASK(USB_EP_command, enable)) { | ||
3194 | /* The EP was enabled, disable it and wait. */ | ||
3195 | TxIsocEPList[epid].command &= ~IO_MASK(USB_EP_command, enable); | ||
3196 | |||
3197 | /* Ah, the luxury of busy-wait. */ | ||
3198 | while (*R_DMA_CH8_SUB3_EP == virt_to_phys(&TxIsocEPList[epid])); | ||
3199 | } | ||
3200 | |||
3201 | etrax_remove_from_sb_list(urb); | ||
3202 | TxIsocEPList[epid].sub = 0; | ||
3203 | TxIsocEPList[epid].hw_len = 0; | ||
3204 | |||
3205 | save_flags(flags); | ||
3206 | cli(); | ||
3207 | etrax_usb_free_epid(epid); | ||
3208 | restore_flags(flags); | ||
3209 | } | ||
3210 | |||
3211 | urb->hcpriv = 0; | ||
3212 | kfree(urb_priv); | ||
3213 | |||
3214 | /* Release allocated bandwidth. */ | ||
3215 | usb_release_bandwidth(urb->dev, urb, 0); | ||
3216 | } else if (usb_pipeout(urb->pipe)) { | ||
3217 | int freed_descr; | ||
3218 | |||
3219 | dbg_isoc("Isoc out urb complete 0x%p", urb); | ||
3220 | |||
3221 | /* Update the urb list. */ | ||
3222 | urb_list_del(urb, epid); | ||
3223 | |||
3224 | freed_descr = etrax_remove_from_sb_list(urb); | ||
3225 | dbg_isoc("freed %d descriptors of %d packets", freed_descr, urb->number_of_packets); | ||
3226 | assert(freed_descr == urb->number_of_packets); | ||
3227 | urb->hcpriv = 0; | ||
3228 | kfree(urb_priv); | ||
3229 | |||
3230 | /* Release allocated bandwidth. */ | ||
3231 | usb_release_bandwidth(urb->dev, urb, 0); | ||
3232 | } | ||
3233 | |||
3234 | urb->status = status; | ||
3235 | if (urb->complete) { | ||
3236 | urb->complete(urb, NULL); | ||
3237 | } | ||
3238 | |||
3239 | if (auto_resubmit) { | ||
3240 | /* Check that urb was not unlinked by the complete callback. */ | ||
3241 | if (__urb_list_entry(urb, epid)) { | ||
3242 | /* Move this one down the list. */ | ||
3243 | urb_list_move_last(urb, epid); | ||
3244 | |||
3245 | /* Mark the now first urb as started (may already be). */ | ||
3246 | ((etrax_urb_priv_t *)(urb_list_first(epid)->hcpriv))->urb_state = STARTED; | ||
3247 | |||
3248 | /* Must set this to 0 since this urb is still active after | ||
3249 | completion. */ | ||
3250 | urb_priv->isoc_packet_counter = 0; | ||
3251 | } else { | ||
3252 | warn("(ISOC) automatic resubmit urb 0x%p removed by complete.", urb); | ||
3253 | } | ||
3254 | } | ||
3255 | |||
3256 | DBFEXIT; | ||
3257 | } | ||
3258 | |||
3259 | static void etrax_usb_complete_urb(struct urb *urb, int status) | ||
3260 | { | ||
3261 | switch (usb_pipetype(urb->pipe)) { | ||
3262 | case PIPE_BULK: | ||
3263 | etrax_usb_complete_bulk_urb(urb, status); | ||
3264 | break; | ||
3265 | case PIPE_CONTROL: | ||
3266 | etrax_usb_complete_ctrl_urb(urb, status); | ||
3267 | break; | ||
3268 | case PIPE_INTERRUPT: | ||
3269 | etrax_usb_complete_intr_urb(urb, status); | ||
3270 | break; | ||
3271 | case PIPE_ISOCHRONOUS: | ||
3272 | etrax_usb_complete_isoc_urb(urb, status); | ||
3273 | break; | ||
3274 | default: | ||
3275 | err("Unknown pipetype"); | ||
3276 | } | ||
3277 | } | ||
3278 | |||
3279 | |||
3280 | |||
3281 | static irqreturn_t etrax_usb_hc_interrupt_top_half(int irq, void *vhc) | ||
3282 | { | ||
3283 | usb_interrupt_registers_t *reg; | ||
3284 | unsigned long flags; | ||
3285 | __u32 irq_mask; | ||
3286 | __u8 status; | ||
3287 | __u32 epid_attn; | ||
3288 | __u16 port_status_1; | ||
3289 | __u16 port_status_2; | ||
3290 | __u32 fm_number; | ||
3291 | |||
3292 | DBFENTER; | ||
3293 | |||
3294 | /* Read critical registers into local variables, do kmalloc afterwards. */ | ||
3295 | save_flags(flags); | ||
3296 | cli(); | ||
3297 | |||
3298 | irq_mask = *R_USB_IRQ_MASK_READ; | ||
3299 | /* Reading R_USB_STATUS clears the ctl_status interrupt. Note that R_USB_STATUS | ||
3300 | must be read before R_USB_EPID_ATTN since reading the latter clears the | ||
3301 | ourun and perror fields of R_USB_STATUS. */ | ||
3302 | status = *R_USB_STATUS; | ||
3303 | |||
3304 | /* Reading R_USB_EPID_ATTN clears the iso_eof, bulk_eot and epid_attn interrupts. */ | ||
3305 | epid_attn = *R_USB_EPID_ATTN; | ||
3306 | |||
3307 | /* Reading R_USB_RH_PORT_STATUS_1 and R_USB_RH_PORT_STATUS_2 clears the | ||
3308 | port_status interrupt. */ | ||
3309 | port_status_1 = *R_USB_RH_PORT_STATUS_1; | ||
3310 | port_status_2 = *R_USB_RH_PORT_STATUS_2; | ||
3311 | |||
3312 | /* Reading R_USB_FM_NUMBER clears the sof interrupt. */ | ||
3313 | /* Note: the lower 11 bits contain the actual frame number, sent with each sof. */ | ||
3314 | fm_number = *R_USB_FM_NUMBER; | ||
3315 | |||
3316 | restore_flags(flags); | ||
3317 | |||
3318 | reg = (usb_interrupt_registers_t *)kmem_cache_alloc(top_half_reg_cache, GFP_ATOMIC); | ||
3319 | |||
3320 | assert(reg != NULL); | ||
3321 | |||
3322 | reg->hc = (etrax_hc_t *)vhc; | ||
3323 | |||
3324 | /* Now put register values into kmalloc'd area. */ | ||
3325 | reg->r_usb_irq_mask_read = irq_mask; | ||
3326 | reg->r_usb_status = status; | ||
3327 | reg->r_usb_epid_attn = epid_attn; | ||
3328 | reg->r_usb_rh_port_status_1 = port_status_1; | ||
3329 | reg->r_usb_rh_port_status_2 = port_status_2; | ||
3330 | reg->r_usb_fm_number = fm_number; | ||
3331 | |||
3332 | INIT_WORK(®->usb_bh, etrax_usb_hc_interrupt_bottom_half, reg); | ||
3333 | schedule_work(®->usb_bh); | ||
3334 | |||
3335 | DBFEXIT; | ||
3336 | |||
3337 | return IRQ_HANDLED; | ||
3338 | } | ||
3339 | |||
3340 | static void etrax_usb_hc_interrupt_bottom_half(void *data) | ||
3341 | { | ||
3342 | usb_interrupt_registers_t *reg = (usb_interrupt_registers_t *)data; | ||
3343 | __u32 irq_mask = reg->r_usb_irq_mask_read; | ||
3344 | |||
3345 | DBFENTER; | ||
3346 | |||
3347 | /* Interrupts are handled in order of priority. */ | ||
3348 | if (irq_mask & IO_MASK(R_USB_IRQ_MASK_READ, epid_attn)) { | ||
3349 | etrax_usb_hc_epid_attn_interrupt(reg); | ||
3350 | } | ||
3351 | if (irq_mask & IO_MASK(R_USB_IRQ_MASK_READ, port_status)) { | ||
3352 | etrax_usb_hc_port_status_interrupt(reg); | ||
3353 | } | ||
3354 | if (irq_mask & IO_MASK(R_USB_IRQ_MASK_READ, ctl_status)) { | ||
3355 | etrax_usb_hc_ctl_status_interrupt(reg); | ||
3356 | } | ||
3357 | if (irq_mask & IO_MASK(R_USB_IRQ_MASK_READ, iso_eof)) { | ||
3358 | etrax_usb_hc_isoc_eof_interrupt(); | ||
3359 | } | ||
3360 | if (irq_mask & IO_MASK(R_USB_IRQ_MASK_READ, bulk_eot)) { | ||
3361 | /* Update/restart the bulk start timer since obviously the channel is running. */ | ||
3362 | mod_timer(&bulk_start_timer, jiffies + BULK_START_TIMER_INTERVAL); | ||
3363 | /* Update/restart the bulk eot timer since we just received an bulk eot interrupt. */ | ||
3364 | mod_timer(&bulk_eot_timer, jiffies + BULK_EOT_TIMER_INTERVAL); | ||
3365 | |||
3366 | etrax_usb_hc_bulk_eot_interrupt(0); | ||
3367 | } | ||
3368 | |||
3369 | kmem_cache_free(top_half_reg_cache, reg); | ||
3370 | |||
3371 | DBFEXIT; | ||
3372 | } | ||
3373 | |||
3374 | |||
3375 | void etrax_usb_hc_isoc_eof_interrupt(void) | ||
3376 | { | ||
3377 | struct urb *urb; | ||
3378 | etrax_urb_priv_t *urb_priv; | ||
3379 | int epid; | ||
3380 | unsigned long flags; | ||
3381 | |||
3382 | DBFENTER; | ||
3383 | |||
3384 | /* Do not check the invalid epid (it has a valid sub pointer). */ | ||
3385 | for (epid = 0; epid < NBR_OF_EPIDS - 1; epid++) { | ||
3386 | |||
3387 | /* Do not check the invalid epid (it has a valid sub pointer). */ | ||
3388 | if ((epid == DUMMY_EPID) || (epid == INVALID_EPID)) | ||
3389 | continue; | ||
3390 | |||
3391 | /* Disable interrupts to block the isoc out descriptor interrupt handler | ||
3392 | from being called while the isoc EPID list is being checked. | ||
3393 | */ | ||
3394 | save_flags(flags); | ||
3395 | cli(); | ||
3396 | |||
3397 | if (TxIsocEPList[epid].sub == 0) { | ||
3398 | /* Nothing here to see. */ | ||
3399 | restore_flags(flags); | ||
3400 | continue; | ||
3401 | } | ||
3402 | |||
3403 | /* Get the first urb (if any). */ | ||
3404 | urb = urb_list_first(epid); | ||
3405 | if (urb == 0) { | ||
3406 | warn("Ignoring NULL urb"); | ||
3407 | restore_flags(flags); | ||
3408 | continue; | ||
3409 | } | ||
3410 | if (usb_pipein(urb->pipe)) { | ||
3411 | |||
3412 | /* Sanity check. */ | ||
3413 | assert(usb_pipetype(urb->pipe) == PIPE_ISOCHRONOUS); | ||
3414 | |||
3415 | urb_priv = (etrax_urb_priv_t *)urb->hcpriv; | ||
3416 | assert(urb_priv); | ||
3417 | |||
3418 | if (urb_priv->urb_state == NOT_STARTED) { | ||
3419 | |||
3420 | /* If ASAP is not set and urb->start_frame is the current frame, | ||
3421 | start the transfer. */ | ||
3422 | if (!(urb->transfer_flags & URB_ISO_ASAP) && | ||
3423 | (urb->start_frame == (*R_USB_FM_NUMBER & 0x7ff))) { | ||
3424 | |||
3425 | dbg_isoc("Enabling isoc IN EP descr for epid %d", epid); | ||
3426 | TxIsocEPList[epid].command |= IO_STATE(USB_EP_command, enable, yes); | ||
3427 | |||
3428 | /* This urb is now active. */ | ||
3429 | urb_priv->urb_state = STARTED; | ||
3430 | continue; | ||
3431 | } | ||
3432 | } | ||
3433 | } | ||
3434 | restore_flags(flags); | ||
3435 | } | ||
3436 | |||
3437 | DBFEXIT; | ||
3438 | |||
3439 | } | ||
3440 | |||
3441 | void etrax_usb_hc_bulk_eot_interrupt(int timer_induced) | ||
3442 | { | ||
3443 | int epid; | ||
3444 | |||
3445 | /* The technique is to run one urb at a time, wait for the eot interrupt at which | ||
3446 | point the EP descriptor has been disabled. */ | ||
3447 | |||
3448 | DBFENTER; | ||
3449 | dbg_bulk("bulk eot%s", timer_induced ? ", called by timer" : ""); | ||
3450 | |||
3451 | for (epid = 0; epid < NBR_OF_EPIDS; epid++) { | ||
3452 | |||
3453 | if (!(TxBulkEPList[epid].command & IO_MASK(USB_EP_command, enable)) && | ||
3454 | (TxBulkEPList[epid].sub != 0)) { | ||
3455 | |||
3456 | struct urb *urb; | ||
3457 | etrax_urb_priv_t *urb_priv; | ||
3458 | unsigned long flags; | ||
3459 | __u32 r_usb_ept_data; | ||
3460 | |||
3461 | /* Found a disabled EP descriptor which has a non-null sub pointer. | ||
3462 | Verify that this ctrl EP descriptor got disabled no errors. | ||
3463 | FIXME: Necessary to check error_code? */ | ||
3464 | dbg_bulk("for epid %d?", epid); | ||
3465 | |||
3466 | /* Get the first urb. */ | ||
3467 | urb = urb_list_first(epid); | ||
3468 | |||
3469 | /* FIXME: Could this happen for valid reasons? Why did it disappear? Because of | ||
3470 | wrong unlinking? */ | ||
3471 | if (!urb) { | ||
3472 | warn("NULL urb for epid %d", epid); | ||
3473 | continue; | ||
3474 | } | ||
3475 | |||
3476 | assert(urb); | ||
3477 | urb_priv = (etrax_urb_priv_t *)urb->hcpriv; | ||
3478 | assert(urb_priv); | ||
3479 | |||
3480 | /* Sanity checks. */ | ||
3481 | assert(usb_pipetype(urb->pipe) == PIPE_BULK); | ||
3482 | if (phys_to_virt(TxBulkEPList[epid].sub) != urb_priv->last_sb) { | ||
3483 | err("bulk endpoint got disabled before reaching last sb"); | ||
3484 | } | ||
3485 | |||
3486 | /* For bulk IN traffic, there seems to be a race condition between | ||
3487 | between the bulk eot and eop interrupts, or rather an uncertainty regarding | ||
3488 | the order in which they happen. Normally we expect the eop interrupt from | ||
3489 | DMA channel 9 to happen before the eot interrupt. | ||
3490 | |||
3491 | Therefore, we complete the bulk IN urb in the rx interrupt handler instead. */ | ||
3492 | |||
3493 | if (usb_pipein(urb->pipe)) { | ||
3494 | dbg_bulk("in urb, continuing"); | ||
3495 | continue; | ||
3496 | } | ||
3497 | |||
3498 | save_flags(flags); | ||
3499 | cli(); | ||
3500 | *R_USB_EPT_INDEX = IO_FIELD(R_USB_EPT_INDEX, value, epid); | ||
3501 | nop(); | ||
3502 | r_usb_ept_data = *R_USB_EPT_DATA; | ||
3503 | restore_flags(flags); | ||
3504 | |||
3505 | if (IO_EXTRACT(R_USB_EPT_DATA, error_code, r_usb_ept_data) == | ||
3506 | IO_STATE_VALUE(R_USB_EPT_DATA, error_code, no_error)) { | ||
3507 | /* This means that the endpoint has no error, is disabled | ||
3508 | and had inserted traffic, i.e. transfer successfully completed. */ | ||
3509 | etrax_usb_complete_bulk_urb(urb, 0); | ||
3510 | } else { | ||
3511 | /* Shouldn't happen. We expect errors to be caught by epid attention. */ | ||
3512 | err("Found disabled bulk EP desc, error_code != no_error"); | ||
3513 | } | ||
3514 | } | ||
3515 | } | ||
3516 | |||
3517 | /* Normally, we should find (at least) one disabled EP descriptor with a valid sub pointer. | ||
3518 | However, because of the uncertainty in the deliverance of the eop/eot interrupts, we may | ||
3519 | not. Also, we might find two disabled EPs when handling an eot interrupt, and then find | ||
3520 | none the next time. */ | ||
3521 | |||
3522 | DBFEXIT; | ||
3523 | |||
3524 | } | ||
3525 | |||
3526 | void etrax_usb_hc_epid_attn_interrupt(usb_interrupt_registers_t *reg) | ||
3527 | { | ||
3528 | /* This function handles the epid attention interrupt. There are a variety of reasons | ||
3529 | for this interrupt to happen (Designer's Reference, p. 8 - 22 for the details): | ||
3530 | |||
3531 | invalid ep_id - Invalid epid in an EP (EP disabled). | ||
3532 | stall - Not strictly an error condition (EP disabled). | ||
3533 | 3rd error - Three successive transaction errors (EP disabled). | ||
3534 | buffer ourun - Buffer overrun or underrun (EP disabled). | ||
3535 | past eof1 - Intr or isoc transaction proceeds past EOF1. | ||
3536 | near eof - Intr or isoc transaction would not fit inside the frame. | ||
3537 | zout transfer - If zout transfer for a bulk endpoint (EP disabled). | ||
3538 | setup transfer - If setup transfer for a non-ctrl endpoint (EP disabled). */ | ||
3539 | |||
3540 | int epid; | ||
3541 | |||
3542 | |||
3543 | DBFENTER; | ||
3544 | |||
3545 | assert(reg != NULL); | ||
3546 | |||
3547 | /* Note that we loop through all epids. We still want to catch errors for | ||
3548 | the invalid one, even though we might handle them differently. */ | ||
3549 | for (epid = 0; epid < NBR_OF_EPIDS; epid++) { | ||
3550 | |||
3551 | if (test_bit(epid, (void *)®->r_usb_epid_attn)) { | ||
3552 | |||
3553 | struct urb *urb; | ||
3554 | __u32 r_usb_ept_data; | ||
3555 | unsigned long flags; | ||
3556 | int error_code; | ||
3557 | |||
3558 | save_flags(flags); | ||
3559 | cli(); | ||
3560 | *R_USB_EPT_INDEX = IO_FIELD(R_USB_EPT_INDEX, value, epid); | ||
3561 | nop(); | ||
3562 | /* Note that although there are separate R_USB_EPT_DATA and R_USB_EPT_DATA_ISO | ||
3563 | registers, they are located at the same address and are of the same size. | ||
3564 | In other words, this read should be ok for isoc also. */ | ||
3565 | r_usb_ept_data = *R_USB_EPT_DATA; | ||
3566 | restore_flags(flags); | ||
3567 | |||
3568 | /* First some sanity checks. */ | ||
3569 | if (epid == INVALID_EPID) { | ||
3570 | /* FIXME: What if it became disabled? Could seriously hurt interrupt | ||
3571 | traffic. (Use do_intr_recover.) */ | ||
3572 | warn("Got epid_attn for INVALID_EPID (%d).", epid); | ||
3573 | err("R_USB_EPT_DATA = 0x%x", r_usb_ept_data); | ||
3574 | err("R_USB_STATUS = 0x%x", reg->r_usb_status); | ||
3575 | continue; | ||
3576 | } else if (epid == DUMMY_EPID) { | ||
3577 | /* We definitely don't care about these ones. Besides, they are | ||
3578 | always disabled, so any possible disabling caused by the | ||
3579 | epid attention interrupt is irrelevant. */ | ||
3580 | warn("Got epid_attn for DUMMY_EPID (%d).", epid); | ||
3581 | continue; | ||
3582 | } | ||
3583 | |||
3584 | /* Get the first urb in the urb list for this epid. We blatantly assume | ||
3585 | that only the first urb could have caused the epid attention. | ||
3586 | (For bulk and ctrl, only one urb is active at any one time. For intr | ||
3587 | and isoc we remove them once they are completed.) */ | ||
3588 | urb = urb_list_first(epid); | ||
3589 | |||
3590 | if (urb == NULL) { | ||
3591 | err("Got epid_attn for epid %i with no urb.", epid); | ||
3592 | err("R_USB_EPT_DATA = 0x%x", r_usb_ept_data); | ||
3593 | err("R_USB_STATUS = 0x%x", reg->r_usb_status); | ||
3594 | continue; | ||
3595 | } | ||
3596 | |||
3597 | switch (usb_pipetype(urb->pipe)) { | ||
3598 | case PIPE_BULK: | ||
3599 | warn("Got epid attn for bulk endpoint, epid %d", epid); | ||
3600 | break; | ||
3601 | case PIPE_CONTROL: | ||
3602 | warn("Got epid attn for control endpoint, epid %d", epid); | ||
3603 | break; | ||
3604 | case PIPE_INTERRUPT: | ||
3605 | warn("Got epid attn for interrupt endpoint, epid %d", epid); | ||
3606 | break; | ||
3607 | case PIPE_ISOCHRONOUS: | ||
3608 | warn("Got epid attn for isochronous endpoint, epid %d", epid); | ||
3609 | break; | ||
3610 | } | ||
3611 | |||
3612 | if (usb_pipetype(urb->pipe) != PIPE_ISOCHRONOUS) { | ||
3613 | if (r_usb_ept_data & IO_MASK(R_USB_EPT_DATA, hold)) { | ||
3614 | warn("Hold was set for epid %d.", epid); | ||
3615 | continue; | ||
3616 | } | ||
3617 | } | ||
3618 | |||
3619 | /* Even though error_code occupies bits 22 - 23 in both R_USB_EPT_DATA and | ||
3620 | R_USB_EPT_DATA_ISOC, we separate them here so we don't forget in other places. */ | ||
3621 | if (usb_pipetype(urb->pipe) == PIPE_ISOCHRONOUS) { | ||
3622 | error_code = IO_EXTRACT(R_USB_EPT_DATA_ISO, error_code, r_usb_ept_data); | ||
3623 | } else { | ||
3624 | error_code = IO_EXTRACT(R_USB_EPT_DATA, error_code, r_usb_ept_data); | ||
3625 | } | ||
3626 | |||
3627 | /* Using IO_STATE_VALUE on R_USB_EPT_DATA should be ok for isoc also. */ | ||
3628 | if (error_code == IO_STATE_VALUE(R_USB_EPT_DATA, error_code, no_error)) { | ||
3629 | |||
3630 | /* Isoc traffic doesn't have error_count_in/error_count_out. */ | ||
3631 | if ((usb_pipetype(urb->pipe) != PIPE_ISOCHRONOUS) && | ||
3632 | (IO_EXTRACT(R_USB_EPT_DATA, error_count_in, r_usb_ept_data) == 3 || | ||
3633 | IO_EXTRACT(R_USB_EPT_DATA, error_count_out, r_usb_ept_data) == 3)) { | ||
3634 | /* 3rd error. */ | ||
3635 | warn("3rd error for epid %i", epid); | ||
3636 | etrax_usb_complete_urb(urb, -EPROTO); | ||
3637 | |||
3638 | } else if (reg->r_usb_status & IO_MASK(R_USB_STATUS, perror)) { | ||
3639 | |||
3640 | warn("Perror for epid %d", epid); | ||
3641 | |||
3642 | if (!(r_usb_ept_data & IO_MASK(R_USB_EPT_DATA, valid))) { | ||
3643 | /* invalid ep_id */ | ||
3644 | panic("Perror because of invalid epid." | ||
3645 | " Deconfigured too early?"); | ||
3646 | } else { | ||
3647 | /* past eof1, near eof, zout transfer, setup transfer */ | ||
3648 | |||
3649 | /* Dump the urb and the relevant EP descriptor list. */ | ||
3650 | |||
3651 | __dump_urb(urb); | ||
3652 | __dump_ept_data(epid); | ||
3653 | __dump_ep_list(usb_pipetype(urb->pipe)); | ||
3654 | |||
3655 | panic("Something wrong with DMA descriptor contents." | ||
3656 | " Too much traffic inserted?"); | ||
3657 | } | ||
3658 | } else if (reg->r_usb_status & IO_MASK(R_USB_STATUS, ourun)) { | ||
3659 | /* buffer ourun */ | ||
3660 | panic("Buffer overrun/underrun for epid %d. DMA too busy?", epid); | ||
3661 | } | ||
3662 | |||
3663 | } else if (error_code == IO_STATE_VALUE(R_USB_EPT_DATA, error_code, stall)) { | ||
3664 | /* Not really a protocol error, just says that the endpoint gave | ||
3665 | a stall response. Note that error_code cannot be stall for isoc. */ | ||
3666 | if (usb_pipetype(urb->pipe) == PIPE_ISOCHRONOUS) { | ||
3667 | panic("Isoc traffic cannot stall"); | ||
3668 | } | ||
3669 | |||
3670 | warn("Stall for epid %d", epid); | ||
3671 | etrax_usb_complete_urb(urb, -EPIPE); | ||
3672 | |||
3673 | } else if (error_code == IO_STATE_VALUE(R_USB_EPT_DATA, error_code, bus_error)) { | ||
3674 | /* Two devices responded to a transaction request. Must be resolved | ||
3675 | by software. FIXME: Reset ports? */ | ||
3676 | panic("Bus error for epid %d." | ||
3677 | " Two devices responded to transaction request", | ||
3678 | epid); | ||
3679 | |||
3680 | } else if (error_code == IO_STATE_VALUE(R_USB_EPT_DATA, error_code, buffer_error)) { | ||
3681 | /* DMA overrun or underrun. */ | ||
3682 | warn("Buffer overrun/underrun for epid %d. DMA too busy?", epid); | ||
3683 | |||
3684 | /* It seems that error_code = buffer_error in | ||
3685 | R_USB_EPT_DATA/R_USB_EPT_DATA_ISO and ourun = yes in R_USB_STATUS | ||
3686 | are the same error. */ | ||
3687 | etrax_usb_complete_urb(urb, -EPROTO); | ||
3688 | } | ||
3689 | } | ||
3690 | } | ||
3691 | |||
3692 | DBFEXIT; | ||
3693 | |||
3694 | } | ||
3695 | |||
3696 | void etrax_usb_bulk_start_timer_func(unsigned long dummy) | ||
3697 | { | ||
3698 | |||
3699 | /* We might enable an EP descriptor behind the current DMA position when it's about | ||
3700 | to decide that there are no more bulk traffic and it should stop the bulk channel. | ||
3701 | Therefore we periodically check if the bulk channel is stopped and there is an | ||
3702 | enabled bulk EP descriptor, in which case we start the bulk channel. */ | ||
3703 | dbg_bulk("bulk_start_timer timed out."); | ||
3704 | |||
3705 | if (!(*R_DMA_CH8_SUB0_CMD & IO_MASK(R_DMA_CH8_SUB0_CMD, cmd))) { | ||
3706 | int epid; | ||
3707 | |||
3708 | dbg_bulk("Bulk DMA channel not running."); | ||
3709 | |||
3710 | for (epid = 0; epid < NBR_OF_EPIDS; epid++) { | ||
3711 | if (TxBulkEPList[epid].command & IO_MASK(USB_EP_command, enable)) { | ||
3712 | dbg_bulk("Found enabled EP for epid %d, starting bulk channel.\n", | ||
3713 | epid); | ||
3714 | *R_DMA_CH8_SUB0_CMD = IO_STATE(R_DMA_CH8_SUB0_CMD, cmd, start); | ||
3715 | |||
3716 | /* Restart the bulk eot timer since we just started the bulk channel. */ | ||
3717 | mod_timer(&bulk_eot_timer, jiffies + BULK_EOT_TIMER_INTERVAL); | ||
3718 | |||
3719 | /* No need to search any further. */ | ||
3720 | break; | ||
3721 | } | ||
3722 | } | ||
3723 | } else { | ||
3724 | dbg_bulk("Bulk DMA channel running."); | ||
3725 | } | ||
3726 | } | ||
3727 | |||
3728 | void etrax_usb_hc_port_status_interrupt(usb_interrupt_registers_t *reg) | ||
3729 | { | ||
3730 | etrax_hc_t *hc = reg->hc; | ||
3731 | __u16 r_usb_rh_port_status_1 = reg->r_usb_rh_port_status_1; | ||
3732 | __u16 r_usb_rh_port_status_2 = reg->r_usb_rh_port_status_2; | ||
3733 | |||
3734 | DBFENTER; | ||
3735 | |||
3736 | /* The Etrax RH does not include a wPortChange register, so this has to be handled in software | ||
3737 | (by saving the old port status value for comparison when the port status interrupt happens). | ||
3738 | See section 11.16.2.6.2 in the USB 1.1 spec for details. */ | ||
3739 | |||
3740 | dbg_rh("hc->rh.prev_wPortStatus_1 = 0x%x", hc->rh.prev_wPortStatus_1); | ||
3741 | dbg_rh("hc->rh.prev_wPortStatus_2 = 0x%x", hc->rh.prev_wPortStatus_2); | ||
3742 | dbg_rh("r_usb_rh_port_status_1 = 0x%x", r_usb_rh_port_status_1); | ||
3743 | dbg_rh("r_usb_rh_port_status_2 = 0x%x", r_usb_rh_port_status_2); | ||
3744 | |||
3745 | /* C_PORT_CONNECTION is set on any transition. */ | ||
3746 | hc->rh.wPortChange_1 |= | ||
3747 | ((r_usb_rh_port_status_1 & (1 << RH_PORT_CONNECTION)) != | ||
3748 | (hc->rh.prev_wPortStatus_1 & (1 << RH_PORT_CONNECTION))) ? | ||
3749 | (1 << RH_PORT_CONNECTION) : 0; | ||
3750 | |||
3751 | hc->rh.wPortChange_2 |= | ||
3752 | ((r_usb_rh_port_status_2 & (1 << RH_PORT_CONNECTION)) != | ||
3753 | (hc->rh.prev_wPortStatus_2 & (1 << RH_PORT_CONNECTION))) ? | ||
3754 | (1 << RH_PORT_CONNECTION) : 0; | ||
3755 | |||
3756 | /* C_PORT_ENABLE is _only_ set on a one to zero transition, i.e. when | ||
3757 | the port is disabled, not when it's enabled. */ | ||
3758 | hc->rh.wPortChange_1 |= | ||
3759 | ((hc->rh.prev_wPortStatus_1 & (1 << RH_PORT_ENABLE)) | ||
3760 | && !(r_usb_rh_port_status_1 & (1 << RH_PORT_ENABLE))) ? | ||
3761 | (1 << RH_PORT_ENABLE) : 0; | ||
3762 | |||
3763 | hc->rh.wPortChange_2 |= | ||
3764 | ((hc->rh.prev_wPortStatus_2 & (1 << RH_PORT_ENABLE)) | ||
3765 | && !(r_usb_rh_port_status_2 & (1 << RH_PORT_ENABLE))) ? | ||
3766 | (1 << RH_PORT_ENABLE) : 0; | ||
3767 | |||
3768 | /* C_PORT_SUSPEND is set to one when the device has transitioned out | ||
3769 | of the suspended state, i.e. when suspend goes from one to zero. */ | ||
3770 | hc->rh.wPortChange_1 |= | ||
3771 | ((hc->rh.prev_wPortStatus_1 & (1 << RH_PORT_SUSPEND)) | ||
3772 | && !(r_usb_rh_port_status_1 & (1 << RH_PORT_SUSPEND))) ? | ||
3773 | (1 << RH_PORT_SUSPEND) : 0; | ||
3774 | |||
3775 | hc->rh.wPortChange_2 |= | ||
3776 | ((hc->rh.prev_wPortStatus_2 & (1 << RH_PORT_SUSPEND)) | ||
3777 | && !(r_usb_rh_port_status_2 & (1 << RH_PORT_SUSPEND))) ? | ||
3778 | (1 << RH_PORT_SUSPEND) : 0; | ||
3779 | |||
3780 | |||
3781 | /* C_PORT_RESET is set when reset processing on this port is complete. */ | ||
3782 | hc->rh.wPortChange_1 |= | ||
3783 | ((hc->rh.prev_wPortStatus_1 & (1 << RH_PORT_RESET)) | ||
3784 | && !(r_usb_rh_port_status_1 & (1 << RH_PORT_RESET))) ? | ||
3785 | (1 << RH_PORT_RESET) : 0; | ||
3786 | |||
3787 | hc->rh.wPortChange_2 |= | ||
3788 | ((hc->rh.prev_wPortStatus_2 & (1 << RH_PORT_RESET)) | ||
3789 | && !(r_usb_rh_port_status_2 & (1 << RH_PORT_RESET))) ? | ||
3790 | (1 << RH_PORT_RESET) : 0; | ||
3791 | |||
3792 | /* Save the new values for next port status change. */ | ||
3793 | hc->rh.prev_wPortStatus_1 = r_usb_rh_port_status_1; | ||
3794 | hc->rh.prev_wPortStatus_2 = r_usb_rh_port_status_2; | ||
3795 | |||
3796 | dbg_rh("hc->rh.wPortChange_1 set to 0x%x", hc->rh.wPortChange_1); | ||
3797 | dbg_rh("hc->rh.wPortChange_2 set to 0x%x", hc->rh.wPortChange_2); | ||
3798 | |||
3799 | DBFEXIT; | ||
3800 | |||
3801 | } | ||
3802 | |||
3803 | void etrax_usb_hc_ctl_status_interrupt(usb_interrupt_registers_t *reg) | ||
3804 | { | ||
3805 | DBFENTER; | ||
3806 | |||
3807 | /* FIXME: What should we do if we get ourun or perror? Dump the EP and SB | ||
3808 | list for the corresponding epid? */ | ||
3809 | if (reg->r_usb_status & IO_MASK(R_USB_STATUS, ourun)) { | ||
3810 | panic("USB controller got ourun."); | ||
3811 | } | ||
3812 | if (reg->r_usb_status & IO_MASK(R_USB_STATUS, perror)) { | ||
3813 | |||
3814 | /* Before, etrax_usb_do_intr_recover was called on this epid if it was | ||
3815 | an interrupt pipe. I don't see how re-enabling all EP descriptors | ||
3816 | will help if there was a programming error. */ | ||
3817 | panic("USB controller got perror."); | ||
3818 | } | ||
3819 | |||
3820 | if (reg->r_usb_status & IO_MASK(R_USB_STATUS, device_mode)) { | ||
3821 | /* We should never operate in device mode. */ | ||
3822 | panic("USB controller in device mode."); | ||
3823 | } | ||
3824 | |||
3825 | /* These if-statements could probably be nested. */ | ||
3826 | if (reg->r_usb_status & IO_MASK(R_USB_STATUS, host_mode)) { | ||
3827 | info("USB controller in host mode."); | ||
3828 | } | ||
3829 | if (reg->r_usb_status & IO_MASK(R_USB_STATUS, started)) { | ||
3830 | info("USB controller started."); | ||
3831 | } | ||
3832 | if (reg->r_usb_status & IO_MASK(R_USB_STATUS, running)) { | ||
3833 | info("USB controller running."); | ||
3834 | } | ||
3835 | |||
3836 | DBFEXIT; | ||
3837 | |||
3838 | } | ||
3839 | |||
3840 | |||
3841 | static int etrax_rh_submit_urb(struct urb *urb) | ||
3842 | { | ||
3843 | struct usb_device *usb_dev = urb->dev; | ||
3844 | etrax_hc_t *hc = usb_dev->bus->hcpriv; | ||
3845 | unsigned int pipe = urb->pipe; | ||
3846 | struct usb_ctrlrequest *cmd = (struct usb_ctrlrequest *) urb->setup_packet; | ||
3847 | void *data = urb->transfer_buffer; | ||
3848 | int leni = urb->transfer_buffer_length; | ||
3849 | int len = 0; | ||
3850 | int stat = 0; | ||
3851 | |||
3852 | __u16 bmRType_bReq; | ||
3853 | __u16 wValue; | ||
3854 | __u16 wIndex; | ||
3855 | __u16 wLength; | ||
3856 | |||
3857 | DBFENTER; | ||
3858 | |||
3859 | /* FIXME: What is this interrupt urb that is sent to the root hub? */ | ||
3860 | if (usb_pipetype (pipe) == PIPE_INTERRUPT) { | ||
3861 | dbg_rh("Root-Hub submit IRQ: every %d ms", urb->interval); | ||
3862 | hc->rh.urb = urb; | ||
3863 | hc->rh.send = 1; | ||
3864 | /* FIXME: We could probably remove this line since it's done | ||
3865 | in etrax_rh_init_int_timer. (Don't remove it from | ||
3866 | etrax_rh_init_int_timer though.) */ | ||
3867 | hc->rh.interval = urb->interval; | ||
3868 | etrax_rh_init_int_timer(urb); | ||
3869 | DBFEXIT; | ||
3870 | |||
3871 | return 0; | ||
3872 | } | ||
3873 | |||
3874 | bmRType_bReq = cmd->bRequestType | (cmd->bRequest << 8); | ||
3875 | wValue = le16_to_cpu(cmd->wValue); | ||
3876 | wIndex = le16_to_cpu(cmd->wIndex); | ||
3877 | wLength = le16_to_cpu(cmd->wLength); | ||
3878 | |||
3879 | dbg_rh("bmRType_bReq : 0x%04x (%d)", bmRType_bReq, bmRType_bReq); | ||
3880 | dbg_rh("wValue : 0x%04x (%d)", wValue, wValue); | ||
3881 | dbg_rh("wIndex : 0x%04x (%d)", wIndex, wIndex); | ||
3882 | dbg_rh("wLength : 0x%04x (%d)", wLength, wLength); | ||
3883 | |||
3884 | switch (bmRType_bReq) { | ||
3885 | |||
3886 | /* Request Destination: | ||
3887 | without flags: Device, | ||
3888 | RH_INTERFACE: interface, | ||
3889 | RH_ENDPOINT: endpoint, | ||
3890 | RH_CLASS means HUB here, | ||
3891 | RH_OTHER | RH_CLASS almost ever means HUB_PORT here | ||
3892 | */ | ||
3893 | |||
3894 | case RH_GET_STATUS: | ||
3895 | *(__u16 *) data = cpu_to_le16 (1); | ||
3896 | OK (2); | ||
3897 | |||
3898 | case RH_GET_STATUS | RH_INTERFACE: | ||
3899 | *(__u16 *) data = cpu_to_le16 (0); | ||
3900 | OK (2); | ||
3901 | |||
3902 | case RH_GET_STATUS | RH_ENDPOINT: | ||
3903 | *(__u16 *) data = cpu_to_le16 (0); | ||
3904 | OK (2); | ||
3905 | |||
3906 | case RH_GET_STATUS | RH_CLASS: | ||
3907 | *(__u32 *) data = cpu_to_le32 (0); | ||
3908 | OK (4); /* hub power ** */ | ||
3909 | |||
3910 | case RH_GET_STATUS | RH_OTHER | RH_CLASS: | ||
3911 | if (wIndex == 1) { | ||
3912 | *((__u16*)data) = cpu_to_le16(hc->rh.prev_wPortStatus_1); | ||
3913 | *((__u16*)data + 1) = cpu_to_le16(hc->rh.wPortChange_1); | ||
3914 | } else if (wIndex == 2) { | ||
3915 | *((__u16*)data) = cpu_to_le16(hc->rh.prev_wPortStatus_2); | ||
3916 | *((__u16*)data + 1) = cpu_to_le16(hc->rh.wPortChange_2); | ||
3917 | } else { | ||
3918 | dbg_rh("RH_GET_STATUS whith invalid wIndex!"); | ||
3919 | OK(0); | ||
3920 | } | ||
3921 | |||
3922 | OK(4); | ||
3923 | |||
3924 | case RH_CLEAR_FEATURE | RH_ENDPOINT: | ||
3925 | switch (wValue) { | ||
3926 | case (RH_ENDPOINT_STALL): | ||
3927 | OK (0); | ||
3928 | } | ||
3929 | break; | ||
3930 | |||
3931 | case RH_CLEAR_FEATURE | RH_CLASS: | ||
3932 | switch (wValue) { | ||
3933 | case (RH_C_HUB_OVER_CURRENT): | ||
3934 | OK (0); /* hub power over current ** */ | ||
3935 | } | ||
3936 | break; | ||
3937 | |||
3938 | case RH_CLEAR_FEATURE | RH_OTHER | RH_CLASS: | ||
3939 | switch (wValue) { | ||
3940 | case (RH_PORT_ENABLE): | ||
3941 | if (wIndex == 1) { | ||
3942 | |||
3943 | dbg_rh("trying to do disable port 1"); | ||
3944 | |||
3945 | *R_USB_PORT1_DISABLE = IO_STATE(R_USB_PORT1_DISABLE, disable, yes); | ||
3946 | |||
3947 | while (hc->rh.prev_wPortStatus_1 & | ||
3948 | IO_STATE(R_USB_RH_PORT_STATUS_1, enabled, yes)); | ||
3949 | *R_USB_PORT1_DISABLE = IO_STATE(R_USB_PORT1_DISABLE, disable, no); | ||
3950 | dbg_rh("Port 1 is disabled"); | ||
3951 | |||
3952 | } else if (wIndex == 2) { | ||
3953 | |||
3954 | dbg_rh("trying to do disable port 2"); | ||
3955 | |||
3956 | *R_USB_PORT2_DISABLE = IO_STATE(R_USB_PORT2_DISABLE, disable, yes); | ||
3957 | |||
3958 | while (hc->rh.prev_wPortStatus_2 & | ||
3959 | IO_STATE(R_USB_RH_PORT_STATUS_2, enabled, yes)); | ||
3960 | *R_USB_PORT2_DISABLE = IO_STATE(R_USB_PORT2_DISABLE, disable, no); | ||
3961 | dbg_rh("Port 2 is disabled"); | ||
3962 | |||
3963 | } else { | ||
3964 | dbg_rh("RH_CLEAR_FEATURE->RH_PORT_ENABLE " | ||
3965 | "with invalid wIndex == %d!", wIndex); | ||
3966 | } | ||
3967 | |||
3968 | OK (0); | ||
3969 | case (RH_PORT_SUSPEND): | ||
3970 | /* Opposite to suspend should be resume, so we'll do a resume. */ | ||
3971 | /* FIXME: USB 1.1, 11.16.2.2 says: | ||
3972 | "Clearing the PORT_SUSPEND feature causes a host-initiated resume | ||
3973 | on the specified port. If the port is not in the Suspended state, | ||
3974 | the hub should treat this request as a functional no-operation." | ||
3975 | Shouldn't we check if the port is in a suspended state before | ||
3976 | resuming? */ | ||
3977 | |||
3978 | /* Make sure the controller isn't busy. */ | ||
3979 | while (*R_USB_COMMAND & IO_MASK(R_USB_COMMAND, busy)); | ||
3980 | |||
3981 | if (wIndex == 1) { | ||
3982 | *R_USB_COMMAND = | ||
3983 | IO_STATE(R_USB_COMMAND, port_sel, port1) | | ||
3984 | IO_STATE(R_USB_COMMAND, port_cmd, resume) | | ||
3985 | IO_STATE(R_USB_COMMAND, ctrl_cmd, nop); | ||
3986 | } else if (wIndex == 2) { | ||
3987 | *R_USB_COMMAND = | ||
3988 | IO_STATE(R_USB_COMMAND, port_sel, port2) | | ||
3989 | IO_STATE(R_USB_COMMAND, port_cmd, resume) | | ||
3990 | IO_STATE(R_USB_COMMAND, ctrl_cmd, nop); | ||
3991 | } else { | ||
3992 | dbg_rh("RH_CLEAR_FEATURE->RH_PORT_SUSPEND " | ||
3993 | "with invalid wIndex == %d!", wIndex); | ||
3994 | } | ||
3995 | |||
3996 | OK (0); | ||
3997 | case (RH_PORT_POWER): | ||
3998 | OK (0); /* port power ** */ | ||
3999 | case (RH_C_PORT_CONNECTION): | ||
4000 | if (wIndex == 1) { | ||
4001 | hc->rh.wPortChange_1 &= ~(1 << RH_PORT_CONNECTION); | ||
4002 | } else if (wIndex == 2) { | ||
4003 | hc->rh.wPortChange_2 &= ~(1 << RH_PORT_CONNECTION); | ||
4004 | } else { | ||
4005 | dbg_rh("RH_CLEAR_FEATURE->RH_C_PORT_CONNECTION " | ||
4006 | "with invalid wIndex == %d!", wIndex); | ||
4007 | } | ||
4008 | |||
4009 | OK (0); | ||
4010 | case (RH_C_PORT_ENABLE): | ||
4011 | if (wIndex == 1) { | ||
4012 | hc->rh.wPortChange_1 &= ~(1 << RH_PORT_ENABLE); | ||
4013 | } else if (wIndex == 2) { | ||
4014 | hc->rh.wPortChange_2 &= ~(1 << RH_PORT_ENABLE); | ||
4015 | } else { | ||
4016 | dbg_rh("RH_CLEAR_FEATURE->RH_C_PORT_ENABLE " | ||
4017 | "with invalid wIndex == %d!", wIndex); | ||
4018 | } | ||
4019 | OK (0); | ||
4020 | case (RH_C_PORT_SUSPEND): | ||
4021 | /*** WR_RH_PORTSTAT(RH_PS_PSSC); */ | ||
4022 | OK (0); | ||
4023 | case (RH_C_PORT_OVER_CURRENT): | ||
4024 | OK (0); /* port power over current ** */ | ||
4025 | case (RH_C_PORT_RESET): | ||
4026 | if (wIndex == 1) { | ||
4027 | hc->rh.wPortChange_1 &= ~(1 << RH_PORT_RESET); | ||
4028 | } else if (wIndex == 2) { | ||
4029 | hc->rh.wPortChange_2 &= ~(1 << RH_PORT_RESET); | ||
4030 | } else { | ||
4031 | dbg_rh("RH_CLEAR_FEATURE->RH_C_PORT_RESET " | ||
4032 | "with invalid index == %d!", wIndex); | ||
4033 | } | ||
4034 | |||
4035 | OK (0); | ||
4036 | |||
4037 | } | ||
4038 | break; | ||
4039 | |||
4040 | case RH_SET_FEATURE | RH_OTHER | RH_CLASS: | ||
4041 | switch (wValue) { | ||
4042 | case (RH_PORT_SUSPEND): | ||
4043 | |||
4044 | /* Make sure the controller isn't busy. */ | ||
4045 | while (*R_USB_COMMAND & IO_MASK(R_USB_COMMAND, busy)); | ||
4046 | |||
4047 | if (wIndex == 1) { | ||
4048 | *R_USB_COMMAND = | ||
4049 | IO_STATE(R_USB_COMMAND, port_sel, port1) | | ||
4050 | IO_STATE(R_USB_COMMAND, port_cmd, suspend) | | ||
4051 | IO_STATE(R_USB_COMMAND, ctrl_cmd, nop); | ||
4052 | } else if (wIndex == 2) { | ||
4053 | *R_USB_COMMAND = | ||
4054 | IO_STATE(R_USB_COMMAND, port_sel, port2) | | ||
4055 | IO_STATE(R_USB_COMMAND, port_cmd, suspend) | | ||
4056 | IO_STATE(R_USB_COMMAND, ctrl_cmd, nop); | ||
4057 | } else { | ||
4058 | dbg_rh("RH_SET_FEATURE->RH_PORT_SUSPEND " | ||
4059 | "with invalid wIndex == %d!", wIndex); | ||
4060 | } | ||
4061 | |||
4062 | OK (0); | ||
4063 | case (RH_PORT_RESET): | ||
4064 | if (wIndex == 1) { | ||
4065 | |||
4066 | port_1_reset: | ||
4067 | dbg_rh("Doing reset of port 1"); | ||
4068 | |||
4069 | /* Make sure the controller isn't busy. */ | ||
4070 | while (*R_USB_COMMAND & IO_MASK(R_USB_COMMAND, busy)); | ||
4071 | |||
4072 | *R_USB_COMMAND = | ||
4073 | IO_STATE(R_USB_COMMAND, port_sel, port1) | | ||
4074 | IO_STATE(R_USB_COMMAND, port_cmd, reset) | | ||
4075 | IO_STATE(R_USB_COMMAND, ctrl_cmd, nop); | ||
4076 | |||
4077 | /* We must wait at least 10 ms for the device to recover. | ||
4078 | 15 ms should be enough. */ | ||
4079 | udelay(15000); | ||
4080 | |||
4081 | /* Wait for reset bit to go low (should be done by now). */ | ||
4082 | while (hc->rh.prev_wPortStatus_1 & | ||
4083 | IO_STATE(R_USB_RH_PORT_STATUS_1, reset, yes)); | ||
4084 | |||
4085 | /* If the port status is | ||
4086 | 1) connected and enabled then there is a device and everything is fine | ||
4087 | 2) neither connected nor enabled then there is no device, also fine | ||
4088 | 3) connected and not enabled then we try again | ||
4089 | (Yes, there are other port status combinations besides these.) */ | ||
4090 | |||
4091 | if ((hc->rh.prev_wPortStatus_1 & | ||
4092 | IO_STATE(R_USB_RH_PORT_STATUS_1, connected, yes)) && | ||
4093 | (hc->rh.prev_wPortStatus_1 & | ||
4094 | IO_STATE(R_USB_RH_PORT_STATUS_1, enabled, no))) { | ||
4095 | dbg_rh("Connected device on port 1, but port not enabled?" | ||
4096 | " Trying reset again."); | ||
4097 | goto port_2_reset; | ||
4098 | } | ||
4099 | |||
4100 | /* Diagnostic printouts. */ | ||
4101 | if ((hc->rh.prev_wPortStatus_1 & | ||
4102 | IO_STATE(R_USB_RH_PORT_STATUS_1, connected, no)) && | ||
4103 | (hc->rh.prev_wPortStatus_1 & | ||
4104 | IO_STATE(R_USB_RH_PORT_STATUS_1, enabled, no))) { | ||
4105 | dbg_rh("No connected device on port 1"); | ||
4106 | } else if ((hc->rh.prev_wPortStatus_1 & | ||
4107 | IO_STATE(R_USB_RH_PORT_STATUS_1, connected, yes)) && | ||
4108 | (hc->rh.prev_wPortStatus_1 & | ||
4109 | IO_STATE(R_USB_RH_PORT_STATUS_1, enabled, yes))) { | ||
4110 | dbg_rh("Connected device on port 1, port 1 enabled"); | ||
4111 | } | ||
4112 | |||
4113 | } else if (wIndex == 2) { | ||
4114 | |||
4115 | port_2_reset: | ||
4116 | dbg_rh("Doing reset of port 2"); | ||
4117 | |||
4118 | /* Make sure the controller isn't busy. */ | ||
4119 | while (*R_USB_COMMAND & IO_MASK(R_USB_COMMAND, busy)); | ||
4120 | |||
4121 | /* Issue the reset command. */ | ||
4122 | *R_USB_COMMAND = | ||
4123 | IO_STATE(R_USB_COMMAND, port_sel, port2) | | ||
4124 | IO_STATE(R_USB_COMMAND, port_cmd, reset) | | ||
4125 | IO_STATE(R_USB_COMMAND, ctrl_cmd, nop); | ||
4126 | |||
4127 | /* We must wait at least 10 ms for the device to recover. | ||
4128 | 15 ms should be enough. */ | ||
4129 | udelay(15000); | ||
4130 | |||
4131 | /* Wait for reset bit to go low (should be done by now). */ | ||
4132 | while (hc->rh.prev_wPortStatus_2 & | ||
4133 | IO_STATE(R_USB_RH_PORT_STATUS_2, reset, yes)); | ||
4134 | |||
4135 | /* If the port status is | ||
4136 | 1) connected and enabled then there is a device and everything is fine | ||
4137 | 2) neither connected nor enabled then there is no device, also fine | ||
4138 | 3) connected and not enabled then we try again | ||
4139 | (Yes, there are other port status combinations besides these.) */ | ||
4140 | |||
4141 | if ((hc->rh.prev_wPortStatus_2 & | ||
4142 | IO_STATE(R_USB_RH_PORT_STATUS_2, connected, yes)) && | ||
4143 | (hc->rh.prev_wPortStatus_2 & | ||
4144 | IO_STATE(R_USB_RH_PORT_STATUS_2, enabled, no))) { | ||
4145 | dbg_rh("Connected device on port 2, but port not enabled?" | ||
4146 | " Trying reset again."); | ||
4147 | goto port_2_reset; | ||
4148 | } | ||
4149 | |||
4150 | /* Diagnostic printouts. */ | ||
4151 | if ((hc->rh.prev_wPortStatus_2 & | ||
4152 | IO_STATE(R_USB_RH_PORT_STATUS_2, connected, no)) && | ||
4153 | (hc->rh.prev_wPortStatus_2 & | ||
4154 | IO_STATE(R_USB_RH_PORT_STATUS_2, enabled, no))) { | ||
4155 | dbg_rh("No connected device on port 2"); | ||
4156 | } else if ((hc->rh.prev_wPortStatus_2 & | ||
4157 | IO_STATE(R_USB_RH_PORT_STATUS_2, connected, yes)) && | ||
4158 | (hc->rh.prev_wPortStatus_2 & | ||
4159 | IO_STATE(R_USB_RH_PORT_STATUS_2, enabled, yes))) { | ||
4160 | dbg_rh("Connected device on port 2, port 2 enabled"); | ||
4161 | } | ||
4162 | |||
4163 | } else { | ||
4164 | dbg_rh("RH_SET_FEATURE->RH_PORT_RESET with invalid wIndex = %d", wIndex); | ||
4165 | } | ||
4166 | |||
4167 | /* Make sure the controller isn't busy. */ | ||
4168 | while (*R_USB_COMMAND & IO_MASK(R_USB_COMMAND, busy)); | ||
4169 | |||
4170 | /* If all enabled ports were disabled the host controller goes down into | ||
4171 | started mode, so we need to bring it back into the running state. | ||
4172 | (This is safe even if it's already in the running state.) */ | ||
4173 | *R_USB_COMMAND = | ||
4174 | IO_STATE(R_USB_COMMAND, port_sel, nop) | | ||
4175 | IO_STATE(R_USB_COMMAND, port_cmd, reset) | | ||
4176 | IO_STATE(R_USB_COMMAND, ctrl_cmd, host_run); | ||
4177 | |||
4178 | dbg_rh("...Done"); | ||
4179 | OK(0); | ||
4180 | |||
4181 | case (RH_PORT_POWER): | ||
4182 | OK (0); /* port power ** */ | ||
4183 | case (RH_PORT_ENABLE): | ||
4184 | /* There is no port enable command in the host controller, so if the | ||
4185 | port is already enabled, we do nothing. If not, we reset the port | ||
4186 | (with an ugly goto). */ | ||
4187 | |||
4188 | if (wIndex == 1) { | ||
4189 | if (hc->rh.prev_wPortStatus_1 & | ||
4190 | IO_STATE(R_USB_RH_PORT_STATUS_1, enabled, no)) { | ||
4191 | goto port_1_reset; | ||
4192 | } | ||
4193 | } else if (wIndex == 2) { | ||
4194 | if (hc->rh.prev_wPortStatus_2 & | ||
4195 | IO_STATE(R_USB_RH_PORT_STATUS_2, enabled, no)) { | ||
4196 | goto port_2_reset; | ||
4197 | } | ||
4198 | } else { | ||
4199 | dbg_rh("RH_SET_FEATURE->RH_GET_STATUS with invalid wIndex = %d", wIndex); | ||
4200 | } | ||
4201 | OK (0); | ||
4202 | } | ||
4203 | break; | ||
4204 | |||
4205 | case RH_SET_ADDRESS: | ||
4206 | hc->rh.devnum = wValue; | ||
4207 | dbg_rh("RH address set to: %d", hc->rh.devnum); | ||
4208 | OK (0); | ||
4209 | |||
4210 | case RH_GET_DESCRIPTOR: | ||
4211 | switch ((wValue & 0xff00) >> 8) { | ||
4212 | case (0x01): /* device descriptor */ | ||
4213 | len = min_t(unsigned int, leni, min_t(unsigned int, sizeof (root_hub_dev_des), wLength)); | ||
4214 | memcpy (data, root_hub_dev_des, len); | ||
4215 | OK (len); | ||
4216 | case (0x02): /* configuration descriptor */ | ||
4217 | len = min_t(unsigned int, leni, min_t(unsigned int, sizeof (root_hub_config_des), wLength)); | ||
4218 | memcpy (data, root_hub_config_des, len); | ||
4219 | OK (len); | ||
4220 | case (0x03): /* string descriptors */ | ||
4221 | len = usb_root_hub_string (wValue & 0xff, | ||
4222 | 0xff, "ETRAX 100LX", | ||
4223 | data, wLength); | ||
4224 | if (len > 0) { | ||
4225 | OK(min(leni, len)); | ||
4226 | } else { | ||
4227 | stat = -EPIPE; | ||
4228 | } | ||
4229 | |||
4230 | } | ||
4231 | break; | ||
4232 | |||
4233 | case RH_GET_DESCRIPTOR | RH_CLASS: | ||
4234 | root_hub_hub_des[2] = hc->rh.numports; | ||
4235 | len = min_t(unsigned int, leni, min_t(unsigned int, sizeof (root_hub_hub_des), wLength)); | ||
4236 | memcpy (data, root_hub_hub_des, len); | ||
4237 | OK (len); | ||
4238 | |||
4239 | case RH_GET_CONFIGURATION: | ||
4240 | *(__u8 *) data = 0x01; | ||
4241 | OK (1); | ||
4242 | |||
4243 | case RH_SET_CONFIGURATION: | ||
4244 | OK (0); | ||
4245 | |||
4246 | default: | ||
4247 | stat = -EPIPE; | ||
4248 | } | ||
4249 | |||
4250 | urb->actual_length = len; | ||
4251 | urb->status = stat; | ||
4252 | urb->dev = NULL; | ||
4253 | if (urb->complete) { | ||
4254 | urb->complete(urb, NULL); | ||
4255 | } | ||
4256 | DBFEXIT; | ||
4257 | |||
4258 | return 0; | ||
4259 | } | ||
4260 | |||
4261 | static void | ||
4262 | etrax_usb_bulk_eot_timer_func(unsigned long dummy) | ||
4263 | { | ||
4264 | /* Because of a race condition in the top half, we might miss a bulk eot. | ||
4265 | This timer "simulates" a bulk eot if we don't get one for a while, hopefully | ||
4266 | correcting the situation. */ | ||
4267 | dbg_bulk("bulk_eot_timer timed out."); | ||
4268 | etrax_usb_hc_bulk_eot_interrupt(1); | ||
4269 | } | ||
4270 | |||
4271 | static void* | ||
4272 | etrax_usb_buffer_alloc(struct usb_bus* bus, size_t size, | ||
4273 | unsigned mem_flags, dma_addr_t *dma) | ||
4274 | { | ||
4275 | return kmalloc(size, mem_flags); | ||
4276 | } | ||
4277 | |||
4278 | static void | ||
4279 | etrax_usb_buffer_free(struct usb_bus *bus, size_t size, void *addr, dma_addr_t dma) | ||
4280 | { | ||
4281 | kfree(addr); | ||
4282 | } | ||
4283 | |||
4284 | |||
4285 | static struct device fake_device; | ||
4286 | |||
4287 | static int __init etrax_usb_hc_init(void) | ||
4288 | { | ||
4289 | static etrax_hc_t *hc; | ||
4290 | struct usb_bus *bus; | ||
4291 | struct usb_device *usb_rh; | ||
4292 | int i; | ||
4293 | |||
4294 | DBFENTER; | ||
4295 | |||
4296 | info("ETRAX 100LX USB-HCD %s (c) 2001-2003 Axis Communications AB\n", usb_hcd_version); | ||
4297 | |||
4298 | hc = kmalloc(sizeof(etrax_hc_t), GFP_KERNEL); | ||
4299 | assert(hc != NULL); | ||
4300 | |||
4301 | /* We use kmem_cache_* to make sure that all DMA desc. are dword aligned */ | ||
4302 | /* Note that we specify sizeof(USB_EP_Desc_t) as the size, but also allocate | ||
4303 | SB descriptors from this cache. This is ok since sizeof(USB_EP_Desc_t) == | ||
4304 | sizeof(USB_SB_Desc_t). */ | ||
4305 | |||
4306 | usb_desc_cache = kmem_cache_create("usb_desc_cache", sizeof(USB_EP_Desc_t), 0, | ||
4307 | SLAB_HWCACHE_ALIGN, 0, 0); | ||
4308 | assert(usb_desc_cache != NULL); | ||
4309 | |||
4310 | top_half_reg_cache = kmem_cache_create("top_half_reg_cache", | ||
4311 | sizeof(usb_interrupt_registers_t), | ||
4312 | 0, SLAB_HWCACHE_ALIGN, 0, 0); | ||
4313 | assert(top_half_reg_cache != NULL); | ||
4314 | |||
4315 | isoc_compl_cache = kmem_cache_create("isoc_compl_cache", | ||
4316 | sizeof(usb_isoc_complete_data_t), | ||
4317 | 0, SLAB_HWCACHE_ALIGN, 0, 0); | ||
4318 | assert(isoc_compl_cache != NULL); | ||
4319 | |||
4320 | etrax_usb_bus = bus = usb_alloc_bus(&etrax_usb_device_operations); | ||
4321 | hc->bus = bus; | ||
4322 | bus->bus_name="ETRAX 100LX"; | ||
4323 | bus->hcpriv = hc; | ||
4324 | |||
4325 | /* Initialize RH to the default address. | ||
4326 | And make sure that we have no status change indication */ | ||
4327 | hc->rh.numports = 2; /* The RH has two ports */ | ||
4328 | hc->rh.devnum = 1; | ||
4329 | hc->rh.wPortChange_1 = 0; | ||
4330 | hc->rh.wPortChange_2 = 0; | ||
4331 | |||
4332 | /* Also initate the previous values to zero */ | ||
4333 | hc->rh.prev_wPortStatus_1 = 0; | ||
4334 | hc->rh.prev_wPortStatus_2 = 0; | ||
4335 | |||
4336 | /* Initialize the intr-traffic flags */ | ||
4337 | /* FIXME: This isn't used. (Besides, the error field isn't initialized.) */ | ||
4338 | hc->intr.sleeping = 0; | ||
4339 | hc->intr.wq = NULL; | ||
4340 | |||
4341 | epid_usage_bitmask = 0; | ||
4342 | epid_out_traffic = 0; | ||
4343 | |||
4344 | /* Mark the invalid epid as being used. */ | ||
4345 | set_bit(INVALID_EPID, (void *)&epid_usage_bitmask); | ||
4346 | *R_USB_EPT_INDEX = IO_FIELD(R_USB_EPT_INDEX, value, INVALID_EPID); | ||
4347 | nop(); | ||
4348 | /* The valid bit should still be set ('invalid' is in our world; not the hardware's). */ | ||
4349 | *R_USB_EPT_DATA = (IO_STATE(R_USB_EPT_DATA, valid, yes) | | ||
4350 | IO_FIELD(R_USB_EPT_DATA, max_len, 1)); | ||
4351 | |||
4352 | /* Mark the dummy epid as being used. */ | ||
4353 | set_bit(DUMMY_EPID, (void *)&epid_usage_bitmask); | ||
4354 | *R_USB_EPT_INDEX = IO_FIELD(R_USB_EPT_INDEX, value, DUMMY_EPID); | ||
4355 | nop(); | ||
4356 | *R_USB_EPT_DATA = (IO_STATE(R_USB_EPT_DATA, valid, no) | | ||
4357 | IO_FIELD(R_USB_EPT_DATA, max_len, 1)); | ||
4358 | |||
4359 | /* Initialize the urb list by initiating a head for each list. */ | ||
4360 | for (i = 0; i < NBR_OF_EPIDS; i++) { | ||
4361 | INIT_LIST_HEAD(&urb_list[i]); | ||
4362 | } | ||
4363 | spin_lock_init(&urb_list_lock); | ||
4364 | |||
4365 | INIT_LIST_HEAD(&urb_unlink_list); | ||
4366 | |||
4367 | |||
4368 | /* Initiate the bulk start timer. */ | ||
4369 | init_timer(&bulk_start_timer); | ||
4370 | bulk_start_timer.expires = jiffies + BULK_START_TIMER_INTERVAL; | ||
4371 | bulk_start_timer.function = etrax_usb_bulk_start_timer_func; | ||
4372 | add_timer(&bulk_start_timer); | ||
4373 | |||
4374 | |||
4375 | /* Initiate the bulk eot timer. */ | ||
4376 | init_timer(&bulk_eot_timer); | ||
4377 | bulk_eot_timer.expires = jiffies + BULK_EOT_TIMER_INTERVAL; | ||
4378 | bulk_eot_timer.function = etrax_usb_bulk_eot_timer_func; | ||
4379 | add_timer(&bulk_eot_timer); | ||
4380 | |||
4381 | /* Set up the data structures for USB traffic. Note that this must be done before | ||
4382 | any interrupt that relies on sane DMA list occurrs. */ | ||
4383 | init_rx_buffers(); | ||
4384 | init_tx_bulk_ep(); | ||
4385 | init_tx_ctrl_ep(); | ||
4386 | init_tx_intr_ep(); | ||
4387 | init_tx_isoc_ep(); | ||
4388 | |||
4389 | device_initialize(&fake_device); | ||
4390 | kobject_set_name(&fake_device.kobj, "etrax_usb"); | ||
4391 | kobject_add(&fake_device.kobj); | ||
4392 | kobject_uevent(&fake_device.kobj, KOBJ_ADD); | ||
4393 | hc->bus->controller = &fake_device; | ||
4394 | usb_register_bus(hc->bus); | ||
4395 | |||
4396 | *R_IRQ_MASK2_SET = | ||
4397 | /* Note that these interrupts are not used. */ | ||
4398 | IO_STATE(R_IRQ_MASK2_SET, dma8_sub0_descr, set) | | ||
4399 | /* Sub channel 1 (ctrl) descr. interrupts are used. */ | ||
4400 | IO_STATE(R_IRQ_MASK2_SET, dma8_sub1_descr, set) | | ||
4401 | IO_STATE(R_IRQ_MASK2_SET, dma8_sub2_descr, set) | | ||
4402 | /* Sub channel 3 (isoc) descr. interrupts are used. */ | ||
4403 | IO_STATE(R_IRQ_MASK2_SET, dma8_sub3_descr, set); | ||
4404 | |||
4405 | /* Note that the dma9_descr interrupt is not used. */ | ||
4406 | *R_IRQ_MASK2_SET = | ||
4407 | IO_STATE(R_IRQ_MASK2_SET, dma9_eop, set) | | ||
4408 | IO_STATE(R_IRQ_MASK2_SET, dma9_descr, set); | ||
4409 | |||
4410 | /* FIXME: Enable iso_eof only when isoc traffic is running. */ | ||
4411 | *R_USB_IRQ_MASK_SET = | ||
4412 | IO_STATE(R_USB_IRQ_MASK_SET, iso_eof, set) | | ||
4413 | IO_STATE(R_USB_IRQ_MASK_SET, bulk_eot, set) | | ||
4414 | IO_STATE(R_USB_IRQ_MASK_SET, epid_attn, set) | | ||
4415 | IO_STATE(R_USB_IRQ_MASK_SET, port_status, set) | | ||
4416 | IO_STATE(R_USB_IRQ_MASK_SET, ctl_status, set); | ||
4417 | |||
4418 | |||
4419 | if (request_irq(ETRAX_USB_HC_IRQ, etrax_usb_hc_interrupt_top_half, 0, | ||
4420 | "ETRAX 100LX built-in USB (HC)", hc)) { | ||
4421 | err("Could not allocate IRQ %d for USB", ETRAX_USB_HC_IRQ); | ||
4422 | etrax_usb_hc_cleanup(); | ||
4423 | DBFEXIT; | ||
4424 | return -1; | ||
4425 | } | ||
4426 | |||
4427 | if (request_irq(ETRAX_USB_RX_IRQ, etrax_usb_rx_interrupt, 0, | ||
4428 | "ETRAX 100LX built-in USB (Rx)", hc)) { | ||
4429 | err("Could not allocate IRQ %d for USB", ETRAX_USB_RX_IRQ); | ||
4430 | etrax_usb_hc_cleanup(); | ||
4431 | DBFEXIT; | ||
4432 | return -1; | ||
4433 | } | ||
4434 | |||
4435 | if (request_irq(ETRAX_USB_TX_IRQ, etrax_usb_tx_interrupt, 0, | ||
4436 | "ETRAX 100LX built-in USB (Tx)", hc)) { | ||
4437 | err("Could not allocate IRQ %d for USB", ETRAX_USB_TX_IRQ); | ||
4438 | etrax_usb_hc_cleanup(); | ||
4439 | DBFEXIT; | ||
4440 | return -1; | ||
4441 | } | ||
4442 | |||
4443 | /* R_USB_COMMAND: | ||
4444 | USB commands in host mode. The fields in this register should all be | ||
4445 | written to in one write. Do not read-modify-write one field at a time. A | ||
4446 | write to this register will trigger events in the USB controller and an | ||
4447 | incomplete command may lead to unpredictable results, and in worst case | ||
4448 | even to a deadlock in the controller. | ||
4449 | (Note however that the busy field is read-only, so no need to write to it.) */ | ||
4450 | |||
4451 | /* Check the busy bit before writing to R_USB_COMMAND. */ | ||
4452 | |||
4453 | while (*R_USB_COMMAND & IO_MASK(R_USB_COMMAND, busy)); | ||
4454 | |||
4455 | /* Reset the USB interface. */ | ||
4456 | *R_USB_COMMAND = | ||
4457 | IO_STATE(R_USB_COMMAND, port_sel, nop) | | ||
4458 | IO_STATE(R_USB_COMMAND, port_cmd, reset) | | ||
4459 | IO_STATE(R_USB_COMMAND, ctrl_cmd, reset); | ||
4460 | |||
4461 | /* Designer's Reference, p. 8 - 10 says we should Initate R_USB_FM_PSTART to 0x2A30 (10800), | ||
4462 | to guarantee that control traffic gets 10% of the bandwidth, and periodic transfer may | ||
4463 | allocate the rest (90%). This doesn't work though. Read on for a lenghty explanation. | ||
4464 | |||
4465 | While there is a difference between rev. 2 and rev. 3 of the ETRAX 100LX regarding the NAK | ||
4466 | behaviour, it doesn't solve this problem. What happens is that a control transfer will not | ||
4467 | be interrupted in its data stage when PSTART happens (the point at which periodic traffic | ||
4468 | is started). Thus, if PSTART is set to 10800 and its IN or OUT token is NAKed until just before | ||
4469 | PSTART happens, it will continue the IN/OUT transfer as long as it's ACKed. After it's done, | ||
4470 | there may be too little time left for an isochronous transfer, causing an epid attention | ||
4471 | interrupt due to perror. The work-around for this is to let the control transfers run at the | ||
4472 | end of the frame instead of at the beginning, and will be interrupted just fine if it doesn't | ||
4473 | fit into the frame. However, since there will *always* be a control transfer at the beginning | ||
4474 | of the frame, regardless of what we set PSTART to, that transfer might be a 64-byte transfer | ||
4475 | which consumes up to 15% of the frame, leaving only 85% for periodic traffic. The solution to | ||
4476 | this would be to 'dummy allocate' 5% of the frame with the usb_claim_bandwidth function to make | ||
4477 | sure that the periodic transfers that are inserted will always fit in the frame. | ||
4478 | |||
4479 | The idea was suggested that a control transfer could be split up into several 8 byte transfers, | ||
4480 | so that it would be interrupted by PSTART, but since this can't be done for an IN transfer this | ||
4481 | hasn't been implemented. | ||
4482 | |||
4483 | The value 11960 is chosen to be just after the SOF token, with a couple of bit times extra | ||
4484 | for possible bit stuffing. */ | ||
4485 | |||
4486 | *R_USB_FM_PSTART = IO_FIELD(R_USB_FM_PSTART, value, 11960); | ||
4487 | |||
4488 | #ifdef CONFIG_ETRAX_USB_HOST_PORT1 | ||
4489 | *R_USB_PORT1_DISABLE = IO_STATE(R_USB_PORT1_DISABLE, disable, no); | ||
4490 | #endif | ||
4491 | |||
4492 | #ifdef CONFIG_ETRAX_USB_HOST_PORT2 | ||
4493 | *R_USB_PORT2_DISABLE = IO_STATE(R_USB_PORT2_DISABLE, disable, no); | ||
4494 | #endif | ||
4495 | |||
4496 | while (*R_USB_COMMAND & IO_MASK(R_USB_COMMAND, busy)); | ||
4497 | |||
4498 | /* Configure the USB interface as a host controller. */ | ||
4499 | *R_USB_COMMAND = | ||
4500 | IO_STATE(R_USB_COMMAND, port_sel, nop) | | ||
4501 | IO_STATE(R_USB_COMMAND, port_cmd, reset) | | ||
4502 | IO_STATE(R_USB_COMMAND, ctrl_cmd, host_config); | ||
4503 | |||
4504 | /* Note: Do not reset any ports here. Await the port status interrupts, to have a controlled | ||
4505 | sequence of resetting the ports. If we reset both ports now, and there are devices | ||
4506 | on both ports, we will get a bus error because both devices will answer the set address | ||
4507 | request. */ | ||
4508 | |||
4509 | while (*R_USB_COMMAND & IO_MASK(R_USB_COMMAND, busy)); | ||
4510 | |||
4511 | /* Start processing of USB traffic. */ | ||
4512 | *R_USB_COMMAND = | ||
4513 | IO_STATE(R_USB_COMMAND, port_sel, nop) | | ||
4514 | IO_STATE(R_USB_COMMAND, port_cmd, reset) | | ||
4515 | IO_STATE(R_USB_COMMAND, ctrl_cmd, host_run); | ||
4516 | |||
4517 | while (*R_USB_COMMAND & IO_MASK(R_USB_COMMAND, busy)); | ||
4518 | |||
4519 | usb_rh = usb_alloc_dev(NULL, hc->bus, 0); | ||
4520 | hc->bus->root_hub = usb_rh; | ||
4521 | usb_rh->state = USB_STATE_ADDRESS; | ||
4522 | usb_rh->speed = USB_SPEED_FULL; | ||
4523 | usb_rh->devnum = 1; | ||
4524 | hc->bus->devnum_next = 2; | ||
4525 | usb_rh->ep0.desc.wMaxPacketSize = __const_cpu_to_le16(64); | ||
4526 | usb_get_device_descriptor(usb_rh, USB_DT_DEVICE_SIZE); | ||
4527 | usb_new_device(usb_rh); | ||
4528 | |||
4529 | DBFEXIT; | ||
4530 | |||
4531 | return 0; | ||
4532 | } | ||
4533 | |||
4534 | static void etrax_usb_hc_cleanup(void) | ||
4535 | { | ||
4536 | DBFENTER; | ||
4537 | |||
4538 | free_irq(ETRAX_USB_HC_IRQ, NULL); | ||
4539 | free_irq(ETRAX_USB_RX_IRQ, NULL); | ||
4540 | free_irq(ETRAX_USB_TX_IRQ, NULL); | ||
4541 | |||
4542 | usb_deregister_bus(etrax_usb_bus); | ||
4543 | |||
4544 | /* FIXME: call kmem_cache_destroy here? */ | ||
4545 | |||
4546 | DBFEXIT; | ||
4547 | } | ||
4548 | |||
4549 | module_init(etrax_usb_hc_init); | ||
4550 | module_exit(etrax_usb_hc_cleanup); | ||
diff --git a/drivers/usb/host/hc_crisv10.h b/drivers/usb/host/hc_crisv10.h deleted file mode 100644 index 62f77111d418..000000000000 --- a/drivers/usb/host/hc_crisv10.h +++ /dev/null | |||
@@ -1,289 +0,0 @@ | |||
1 | #ifndef __LINUX_ETRAX_USB_H | ||
2 | #define __LINUX_ETRAX_USB_H | ||
3 | |||
4 | #include <linux/types.h> | ||
5 | #include <linux/list.h> | ||
6 | |||
7 | typedef struct USB_IN_Desc { | ||
8 | volatile __u16 sw_len; | ||
9 | volatile __u16 command; | ||
10 | volatile unsigned long next; | ||
11 | volatile unsigned long buf; | ||
12 | volatile __u16 hw_len; | ||
13 | volatile __u16 status; | ||
14 | } USB_IN_Desc_t; | ||
15 | |||
16 | typedef struct USB_SB_Desc { | ||
17 | volatile __u16 sw_len; | ||
18 | volatile __u16 command; | ||
19 | volatile unsigned long next; | ||
20 | volatile unsigned long buf; | ||
21 | __u32 dummy; | ||
22 | } USB_SB_Desc_t; | ||
23 | |||
24 | typedef struct USB_EP_Desc { | ||
25 | volatile __u16 hw_len; | ||
26 | volatile __u16 command; | ||
27 | volatile unsigned long sub; | ||
28 | volatile unsigned long next; | ||
29 | __u32 dummy; | ||
30 | } USB_EP_Desc_t; | ||
31 | |||
32 | struct virt_root_hub { | ||
33 | int devnum; | ||
34 | void *urb; | ||
35 | void *int_addr; | ||
36 | int send; | ||
37 | int interval; | ||
38 | int numports; | ||
39 | struct timer_list rh_int_timer; | ||
40 | volatile __u16 wPortChange_1; | ||
41 | volatile __u16 wPortChange_2; | ||
42 | volatile __u16 prev_wPortStatus_1; | ||
43 | volatile __u16 prev_wPortStatus_2; | ||
44 | }; | ||
45 | |||
46 | struct etrax_usb_intr_traffic { | ||
47 | int sleeping; | ||
48 | int error; | ||
49 | struct wait_queue *wq; | ||
50 | }; | ||
51 | |||
52 | typedef struct etrax_usb_hc { | ||
53 | struct usb_bus *bus; | ||
54 | struct virt_root_hub rh; | ||
55 | struct etrax_usb_intr_traffic intr; | ||
56 | } etrax_hc_t; | ||
57 | |||
58 | typedef enum { | ||
59 | STARTED, | ||
60 | NOT_STARTED, | ||
61 | UNLINK, | ||
62 | TRANSFER_DONE, | ||
63 | WAITING_FOR_DESCR_INTR | ||
64 | } etrax_usb_urb_state_t; | ||
65 | |||
66 | |||
67 | |||
68 | typedef struct etrax_usb_urb_priv { | ||
69 | /* The first_sb field is used for freeing all SB descriptors belonging | ||
70 | to an urb. The corresponding ep descriptor's sub pointer cannot be | ||
71 | used for this since the DMA advances the sub pointer as it processes | ||
72 | the sb list. */ | ||
73 | USB_SB_Desc_t *first_sb; | ||
74 | /* The last_sb field referes to the last SB descriptor that belongs to | ||
75 | this urb. This is important to know so we can free the SB descriptors | ||
76 | that ranges between first_sb and last_sb. */ | ||
77 | USB_SB_Desc_t *last_sb; | ||
78 | |||
79 | /* The rx_offset field is used in ctrl and bulk traffic to keep track | ||
80 | of the offset in the urb's transfer_buffer where incoming data should be | ||
81 | copied to. */ | ||
82 | __u32 rx_offset; | ||
83 | |||
84 | /* Counter used in isochronous transfers to keep track of the | ||
85 | number of packets received/transmitted. */ | ||
86 | __u32 isoc_packet_counter; | ||
87 | |||
88 | /* This field is used to pass information about the urb's current state between | ||
89 | the various interrupt handlers (thus marked volatile). */ | ||
90 | volatile etrax_usb_urb_state_t urb_state; | ||
91 | |||
92 | /* Connection between the submitted urb and ETRAX epid number */ | ||
93 | __u8 epid; | ||
94 | |||
95 | /* The rx_data_list field is used for periodic traffic, to hold | ||
96 | received data for later processing in the the complete_urb functions, | ||
97 | where the data us copied to the urb's transfer_buffer. Basically, we | ||
98 | use this intermediate storage because we don't know when it's safe to | ||
99 | reuse the transfer_buffer (FIXME?). */ | ||
100 | struct list_head rx_data_list; | ||
101 | } etrax_urb_priv_t; | ||
102 | |||
103 | /* This struct is for passing data from the top half to the bottom half. */ | ||
104 | typedef struct usb_interrupt_registers | ||
105 | { | ||
106 | etrax_hc_t *hc; | ||
107 | __u32 r_usb_epid_attn; | ||
108 | __u8 r_usb_status; | ||
109 | __u16 r_usb_rh_port_status_1; | ||
110 | __u16 r_usb_rh_port_status_2; | ||
111 | __u32 r_usb_irq_mask_read; | ||
112 | __u32 r_usb_fm_number; | ||
113 | struct work_struct usb_bh; | ||
114 | } usb_interrupt_registers_t; | ||
115 | |||
116 | /* This struct is for passing data from the isoc top half to the isoc bottom half. */ | ||
117 | typedef struct usb_isoc_complete_data | ||
118 | { | ||
119 | struct urb *urb; | ||
120 | struct work_struct usb_bh; | ||
121 | } usb_isoc_complete_data_t; | ||
122 | |||
123 | /* This struct holds data we get from the rx descriptors for DMA channel 9 | ||
124 | for periodic traffic (intr and isoc). */ | ||
125 | typedef struct rx_data | ||
126 | { | ||
127 | void *data; | ||
128 | int length; | ||
129 | struct list_head list; | ||
130 | } rx_data_t; | ||
131 | |||
132 | typedef struct urb_entry | ||
133 | { | ||
134 | struct urb *urb; | ||
135 | struct list_head list; | ||
136 | } urb_entry_t; | ||
137 | |||
138 | /* --------------------------------------------------------------------------- | ||
139 | Virtual Root HUB | ||
140 | ------------------------------------------------------------------------- */ | ||
141 | /* destination of request */ | ||
142 | #define RH_INTERFACE 0x01 | ||
143 | #define RH_ENDPOINT 0x02 | ||
144 | #define RH_OTHER 0x03 | ||
145 | |||
146 | #define RH_CLASS 0x20 | ||
147 | #define RH_VENDOR 0x40 | ||
148 | |||
149 | /* Requests: bRequest << 8 | bmRequestType */ | ||
150 | #define RH_GET_STATUS 0x0080 | ||
151 | #define RH_CLEAR_FEATURE 0x0100 | ||
152 | #define RH_SET_FEATURE 0x0300 | ||
153 | #define RH_SET_ADDRESS 0x0500 | ||
154 | #define RH_GET_DESCRIPTOR 0x0680 | ||
155 | #define RH_SET_DESCRIPTOR 0x0700 | ||
156 | #define RH_GET_CONFIGURATION 0x0880 | ||
157 | #define RH_SET_CONFIGURATION 0x0900 | ||
158 | #define RH_GET_STATE 0x0280 | ||
159 | #define RH_GET_INTERFACE 0x0A80 | ||
160 | #define RH_SET_INTERFACE 0x0B00 | ||
161 | #define RH_SYNC_FRAME 0x0C80 | ||
162 | /* Our Vendor Specific Request */ | ||
163 | #define RH_SET_EP 0x2000 | ||
164 | |||
165 | |||
166 | /* Hub port features */ | ||
167 | #define RH_PORT_CONNECTION 0x00 | ||
168 | #define RH_PORT_ENABLE 0x01 | ||
169 | #define RH_PORT_SUSPEND 0x02 | ||
170 | #define RH_PORT_OVER_CURRENT 0x03 | ||
171 | #define RH_PORT_RESET 0x04 | ||
172 | #define RH_PORT_POWER 0x08 | ||
173 | #define RH_PORT_LOW_SPEED 0x09 | ||
174 | #define RH_C_PORT_CONNECTION 0x10 | ||
175 | #define RH_C_PORT_ENABLE 0x11 | ||
176 | #define RH_C_PORT_SUSPEND 0x12 | ||
177 | #define RH_C_PORT_OVER_CURRENT 0x13 | ||
178 | #define RH_C_PORT_RESET 0x14 | ||
179 | |||
180 | /* Hub features */ | ||
181 | #define RH_C_HUB_LOCAL_POWER 0x00 | ||
182 | #define RH_C_HUB_OVER_CURRENT 0x01 | ||
183 | |||
184 | #define RH_DEVICE_REMOTE_WAKEUP 0x00 | ||
185 | #define RH_ENDPOINT_STALL 0x01 | ||
186 | |||
187 | /* Our Vendor Specific feature */ | ||
188 | #define RH_REMOVE_EP 0x00 | ||
189 | |||
190 | |||
191 | #define RH_ACK 0x01 | ||
192 | #define RH_REQ_ERR -1 | ||
193 | #define RH_NACK 0x00 | ||
194 | |||
195 | /* Field definitions for */ | ||
196 | |||
197 | #define USB_IN_command__eol__BITNR 0 /* command macros */ | ||
198 | #define USB_IN_command__eol__WIDTH 1 | ||
199 | #define USB_IN_command__eol__no 0 | ||
200 | #define USB_IN_command__eol__yes 1 | ||
201 | |||
202 | #define USB_IN_command__intr__BITNR 3 | ||
203 | #define USB_IN_command__intr__WIDTH 1 | ||
204 | #define USB_IN_command__intr__no 0 | ||
205 | #define USB_IN_command__intr__yes 1 | ||
206 | |||
207 | #define USB_IN_status__eop__BITNR 1 /* status macros. */ | ||
208 | #define USB_IN_status__eop__WIDTH 1 | ||
209 | #define USB_IN_status__eop__no 0 | ||
210 | #define USB_IN_status__eop__yes 1 | ||
211 | |||
212 | #define USB_IN_status__eot__BITNR 5 | ||
213 | #define USB_IN_status__eot__WIDTH 1 | ||
214 | #define USB_IN_status__eot__no 0 | ||
215 | #define USB_IN_status__eot__yes 1 | ||
216 | |||
217 | #define USB_IN_status__error__BITNR 6 | ||
218 | #define USB_IN_status__error__WIDTH 1 | ||
219 | #define USB_IN_status__error__no 0 | ||
220 | #define USB_IN_status__error__yes 1 | ||
221 | |||
222 | #define USB_IN_status__nodata__BITNR 7 | ||
223 | #define USB_IN_status__nodata__WIDTH 1 | ||
224 | #define USB_IN_status__nodata__no 0 | ||
225 | #define USB_IN_status__nodata__yes 1 | ||
226 | |||
227 | #define USB_IN_status__epid__BITNR 8 | ||
228 | #define USB_IN_status__epid__WIDTH 5 | ||
229 | |||
230 | #define USB_EP_command__eol__BITNR 0 | ||
231 | #define USB_EP_command__eol__WIDTH 1 | ||
232 | #define USB_EP_command__eol__no 0 | ||
233 | #define USB_EP_command__eol__yes 1 | ||
234 | |||
235 | #define USB_EP_command__eof__BITNR 1 | ||
236 | #define USB_EP_command__eof__WIDTH 1 | ||
237 | #define USB_EP_command__eof__no 0 | ||
238 | #define USB_EP_command__eof__yes 1 | ||
239 | |||
240 | #define USB_EP_command__intr__BITNR 3 | ||
241 | #define USB_EP_command__intr__WIDTH 1 | ||
242 | #define USB_EP_command__intr__no 0 | ||
243 | #define USB_EP_command__intr__yes 1 | ||
244 | |||
245 | #define USB_EP_command__enable__BITNR 4 | ||
246 | #define USB_EP_command__enable__WIDTH 1 | ||
247 | #define USB_EP_command__enable__no 0 | ||
248 | #define USB_EP_command__enable__yes 1 | ||
249 | |||
250 | #define USB_EP_command__hw_valid__BITNR 5 | ||
251 | #define USB_EP_command__hw_valid__WIDTH 1 | ||
252 | #define USB_EP_command__hw_valid__no 0 | ||
253 | #define USB_EP_command__hw_valid__yes 1 | ||
254 | |||
255 | #define USB_EP_command__epid__BITNR 8 | ||
256 | #define USB_EP_command__epid__WIDTH 5 | ||
257 | |||
258 | #define USB_SB_command__eol__BITNR 0 /* command macros. */ | ||
259 | #define USB_SB_command__eol__WIDTH 1 | ||
260 | #define USB_SB_command__eol__no 0 | ||
261 | #define USB_SB_command__eol__yes 1 | ||
262 | |||
263 | #define USB_SB_command__eot__BITNR 1 | ||
264 | #define USB_SB_command__eot__WIDTH 1 | ||
265 | #define USB_SB_command__eot__no 0 | ||
266 | #define USB_SB_command__eot__yes 1 | ||
267 | |||
268 | #define USB_SB_command__intr__BITNR 3 | ||
269 | #define USB_SB_command__intr__WIDTH 1 | ||
270 | #define USB_SB_command__intr__no 0 | ||
271 | #define USB_SB_command__intr__yes 1 | ||
272 | |||
273 | #define USB_SB_command__tt__BITNR 4 | ||
274 | #define USB_SB_command__tt__WIDTH 2 | ||
275 | #define USB_SB_command__tt__zout 0 | ||
276 | #define USB_SB_command__tt__in 1 | ||
277 | #define USB_SB_command__tt__out 2 | ||
278 | #define USB_SB_command__tt__setup 3 | ||
279 | |||
280 | |||
281 | #define USB_SB_command__rem__BITNR 8 | ||
282 | #define USB_SB_command__rem__WIDTH 6 | ||
283 | |||
284 | #define USB_SB_command__full__BITNR 6 | ||
285 | #define USB_SB_command__full__WIDTH 1 | ||
286 | #define USB_SB_command__full__no 0 | ||
287 | #define USB_SB_command__full__yes 1 | ||
288 | |||
289 | #endif | ||
diff --git a/drivers/usb/host/isp116x-hcd.c b/drivers/usb/host/isp116x-hcd.c index 2718b5dc4ec1..46873f2534b5 100644 --- a/drivers/usb/host/isp116x-hcd.c +++ b/drivers/usb/host/isp116x-hcd.c | |||
@@ -1577,7 +1577,7 @@ static int isp116x_remove(struct platform_device *pdev) | |||
1577 | 1577 | ||
1578 | #define resource_len(r) (((r)->end - (r)->start) + 1) | 1578 | #define resource_len(r) (((r)->end - (r)->start) + 1) |
1579 | 1579 | ||
1580 | static int __init isp116x_probe(struct platform_device *pdev) | 1580 | static int __devinit isp116x_probe(struct platform_device *pdev) |
1581 | { | 1581 | { |
1582 | struct usb_hcd *hcd; | 1582 | struct usb_hcd *hcd; |
1583 | struct isp116x *isp116x; | 1583 | struct isp116x *isp116x; |
diff --git a/drivers/usb/host/ohci-at91.c b/drivers/usb/host/ohci-at91.c index 930346487278..d849c809acbd 100644 --- a/drivers/usb/host/ohci-at91.c +++ b/drivers/usb/host/ohci-at91.c | |||
@@ -18,19 +18,38 @@ | |||
18 | #include <asm/mach-types.h> | 18 | #include <asm/mach-types.h> |
19 | #include <asm/hardware.h> | 19 | #include <asm/hardware.h> |
20 | #include <asm/arch/board.h> | 20 | #include <asm/arch/board.h> |
21 | #include <asm/arch/cpu.h> | ||
21 | 22 | ||
22 | #ifndef CONFIG_ARCH_AT91 | 23 | #ifndef CONFIG_ARCH_AT91 |
23 | #error "CONFIG_ARCH_AT91 must be defined." | 24 | #error "CONFIG_ARCH_AT91 must be defined." |
24 | #endif | 25 | #endif |
25 | 26 | ||
26 | /* interface and function clocks */ | 27 | /* interface and function clocks; sometimes also an AHB clock */ |
27 | static struct clk *iclk, *fclk; | 28 | static struct clk *iclk, *fclk, *hclk; |
28 | static int clocked; | 29 | static int clocked; |
29 | 30 | ||
30 | extern int usb_disabled(void); | 31 | extern int usb_disabled(void); |
31 | 32 | ||
32 | /*-------------------------------------------------------------------------*/ | 33 | /*-------------------------------------------------------------------------*/ |
33 | 34 | ||
35 | static void at91_start_clock(void) | ||
36 | { | ||
37 | if (cpu_is_at91sam9261()) | ||
38 | clk_enable(hclk); | ||
39 | clk_enable(iclk); | ||
40 | clk_enable(fclk); | ||
41 | clocked = 1; | ||
42 | } | ||
43 | |||
44 | static void at91_stop_clock(void) | ||
45 | { | ||
46 | clk_disable(fclk); | ||
47 | clk_disable(iclk); | ||
48 | if (cpu_is_at91sam9261()) | ||
49 | clk_disable(hclk); | ||
50 | clocked = 0; | ||
51 | } | ||
52 | |||
34 | static void at91_start_hc(struct platform_device *pdev) | 53 | static void at91_start_hc(struct platform_device *pdev) |
35 | { | 54 | { |
36 | struct usb_hcd *hcd = platform_get_drvdata(pdev); | 55 | struct usb_hcd *hcd = platform_get_drvdata(pdev); |
@@ -41,9 +60,7 @@ static void at91_start_hc(struct platform_device *pdev) | |||
41 | /* | 60 | /* |
42 | * Start the USB clocks. | 61 | * Start the USB clocks. |
43 | */ | 62 | */ |
44 | clk_enable(iclk); | 63 | at91_start_clock(); |
45 | clk_enable(fclk); | ||
46 | clocked = 1; | ||
47 | 64 | ||
48 | /* | 65 | /* |
49 | * The USB host controller must remain in reset. | 66 | * The USB host controller must remain in reset. |
@@ -66,9 +83,7 @@ static void at91_stop_hc(struct platform_device *pdev) | |||
66 | /* | 83 | /* |
67 | * Stop the USB clocks. | 84 | * Stop the USB clocks. |
68 | */ | 85 | */ |
69 | clk_disable(fclk); | 86 | at91_stop_clock(); |
70 | clk_disable(iclk); | ||
71 | clocked = 0; | ||
72 | } | 87 | } |
73 | 88 | ||
74 | 89 | ||
@@ -126,6 +141,8 @@ static int usb_hcd_at91_probe(const struct hc_driver *driver, | |||
126 | 141 | ||
127 | iclk = clk_get(&pdev->dev, "ohci_clk"); | 142 | iclk = clk_get(&pdev->dev, "ohci_clk"); |
128 | fclk = clk_get(&pdev->dev, "uhpck"); | 143 | fclk = clk_get(&pdev->dev, "uhpck"); |
144 | if (cpu_is_at91sam9261()) | ||
145 | hclk = clk_get(&pdev->dev, "hck0"); | ||
129 | 146 | ||
130 | at91_start_hc(pdev); | 147 | at91_start_hc(pdev); |
131 | ohci_hcd_init(hcd_to_ohci(hcd)); | 148 | ohci_hcd_init(hcd_to_ohci(hcd)); |
@@ -137,6 +154,8 @@ static int usb_hcd_at91_probe(const struct hc_driver *driver, | |||
137 | /* Error handling */ | 154 | /* Error handling */ |
138 | at91_stop_hc(pdev); | 155 | at91_stop_hc(pdev); |
139 | 156 | ||
157 | if (cpu_is_at91sam9261()) | ||
158 | clk_put(hclk); | ||
140 | clk_put(fclk); | 159 | clk_put(fclk); |
141 | clk_put(iclk); | 160 | clk_put(iclk); |
142 | 161 | ||
@@ -171,9 +190,11 @@ static int usb_hcd_at91_remove(struct usb_hcd *hcd, | |||
171 | iounmap(hcd->regs); | 190 | iounmap(hcd->regs); |
172 | release_mem_region(hcd->rsrc_start, hcd->rsrc_len); | 191 | release_mem_region(hcd->rsrc_start, hcd->rsrc_len); |
173 | 192 | ||
193 | if (cpu_is_at91sam9261()) | ||
194 | clk_put(hclk); | ||
174 | clk_put(fclk); | 195 | clk_put(fclk); |
175 | clk_put(iclk); | 196 | clk_put(iclk); |
176 | fclk = iclk = NULL; | 197 | fclk = iclk = hclk = NULL; |
177 | 198 | ||
178 | dev_set_drvdata(&pdev->dev, NULL); | 199 | dev_set_drvdata(&pdev->dev, NULL); |
179 | return 0; | 200 | return 0; |
@@ -280,9 +301,7 @@ ohci_hcd_at91_drv_suspend(struct platform_device *pdev, pm_message_t mesg) | |||
280 | */ | 301 | */ |
281 | if (at91_suspend_entering_slow_clock()) { | 302 | if (at91_suspend_entering_slow_clock()) { |
282 | ohci_usb_reset (ohci); | 303 | ohci_usb_reset (ohci); |
283 | clk_disable(fclk); | 304 | at91_stop_clock(); |
284 | clk_disable(iclk); | ||
285 | clocked = 0; | ||
286 | } | 305 | } |
287 | 306 | ||
288 | return 0; | 307 | return 0; |
@@ -295,11 +314,8 @@ static int ohci_hcd_at91_drv_resume(struct platform_device *pdev) | |||
295 | if (device_may_wakeup(&pdev->dev)) | 314 | if (device_may_wakeup(&pdev->dev)) |
296 | disable_irq_wake(hcd->irq); | 315 | disable_irq_wake(hcd->irq); |
297 | 316 | ||
298 | if (!clocked) { | 317 | if (!clocked) |
299 | clk_enable(iclk); | 318 | at91_start_clock(); |
300 | clk_enable(fclk); | ||
301 | clocked = 1; | ||
302 | } | ||
303 | 319 | ||
304 | return 0; | 320 | return 0; |
305 | } | 321 | } |
diff --git a/drivers/usb/host/ohci-hcd.c b/drivers/usb/host/ohci-hcd.c index fa6a7ceaa0db..e8bbe8bc2598 100644 --- a/drivers/usb/host/ohci-hcd.c +++ b/drivers/usb/host/ohci-hcd.c | |||
@@ -42,6 +42,9 @@ | |||
42 | #include <asm/system.h> | 42 | #include <asm/system.h> |
43 | #include <asm/unaligned.h> | 43 | #include <asm/unaligned.h> |
44 | #include <asm/byteorder.h> | 44 | #include <asm/byteorder.h> |
45 | #ifdef CONFIG_PPC_PS3 | ||
46 | #include <asm/firmware.h> | ||
47 | #endif | ||
45 | 48 | ||
46 | #include "../core/hcd.h" | 49 | #include "../core/hcd.h" |
47 | 50 | ||
@@ -483,9 +486,6 @@ static int ohci_run (struct ohci_hcd *ohci) | |||
483 | * or if bus glue did the same (e.g. for PCI add-in cards with | 486 | * or if bus glue did the same (e.g. for PCI add-in cards with |
484 | * PCI PM support). | 487 | * PCI PM support). |
485 | */ | 488 | */ |
486 | ohci_dbg (ohci, "resetting from state '%s', control = 0x%x\n", | ||
487 | hcfs2string (ohci->hc_control & OHCI_CTRL_HCFS), | ||
488 | ohci_readl (ohci, &ohci->regs->control)); | ||
489 | if ((ohci->hc_control & OHCI_CTRL_RWC) != 0 | 489 | if ((ohci->hc_control & OHCI_CTRL_RWC) != 0 |
490 | && !device_may_wakeup(hcd->self.controller)) | 490 | && !device_may_wakeup(hcd->self.controller)) |
491 | device_init_wakeup(hcd->self.controller, 1); | 491 | device_init_wakeup(hcd->self.controller, 1); |
@@ -741,9 +741,6 @@ static void ohci_stop (struct usb_hcd *hcd) | |||
741 | { | 741 | { |
742 | struct ohci_hcd *ohci = hcd_to_ohci (hcd); | 742 | struct ohci_hcd *ohci = hcd_to_ohci (hcd); |
743 | 743 | ||
744 | ohci_dbg (ohci, "stop %s controller (state 0x%02x)\n", | ||
745 | hcfs2string (ohci->hc_control & OHCI_CTRL_HCFS), | ||
746 | hcd->state); | ||
747 | ohci_dump (ohci, 1); | 744 | ohci_dump (ohci, 1); |
748 | 745 | ||
749 | flush_scheduled_work(); | 746 | flush_scheduled_work(); |
@@ -944,9 +941,12 @@ static int __init ohci_hcd_mod_init(void) | |||
944 | sizeof (struct ed), sizeof (struct td)); | 941 | sizeof (struct ed), sizeof (struct td)); |
945 | 942 | ||
946 | #ifdef PS3_SYSTEM_BUS_DRIVER | 943 | #ifdef PS3_SYSTEM_BUS_DRIVER |
947 | retval = ps3_system_bus_driver_register(&PS3_SYSTEM_BUS_DRIVER); | 944 | if (firmware_has_feature(FW_FEATURE_PS3_LV1)) { |
948 | if (retval < 0) | 945 | retval = ps3_system_bus_driver_register( |
949 | goto error_ps3; | 946 | &PS3_SYSTEM_BUS_DRIVER); |
947 | if (retval < 0) | ||
948 | goto error_ps3; | ||
949 | } | ||
950 | #endif | 950 | #endif |
951 | 951 | ||
952 | #ifdef PLATFORM_DRIVER | 952 | #ifdef PLATFORM_DRIVER |
@@ -992,7 +992,8 @@ static int __init ohci_hcd_mod_init(void) | |||
992 | error_platform: | 992 | error_platform: |
993 | #endif | 993 | #endif |
994 | #ifdef PS3_SYSTEM_BUS_DRIVER | 994 | #ifdef PS3_SYSTEM_BUS_DRIVER |
995 | ps3_system_bus_driver_unregister(&PS3_SYSTEM_BUS_DRIVER); | 995 | if (firmware_has_feature(FW_FEATURE_PS3_LV1)) |
996 | ps3_system_bus_driver_unregister(&PS3_SYSTEM_BUS_DRIVER); | ||
996 | error_ps3: | 997 | error_ps3: |
997 | #endif | 998 | #endif |
998 | return retval; | 999 | return retval; |
@@ -1014,7 +1015,8 @@ static void __exit ohci_hcd_mod_exit(void) | |||
1014 | platform_driver_unregister(&PLATFORM_DRIVER); | 1015 | platform_driver_unregister(&PLATFORM_DRIVER); |
1015 | #endif | 1016 | #endif |
1016 | #ifdef PS3_SYSTEM_BUS_DRIVER | 1017 | #ifdef PS3_SYSTEM_BUS_DRIVER |
1017 | ps3_system_bus_driver_unregister(&PS3_SYSTEM_BUS_DRIVER); | 1018 | if (firmware_has_feature(FW_FEATURE_PS3_LV1)) |
1019 | ps3_system_bus_driver_unregister(&PS3_SYSTEM_BUS_DRIVER); | ||
1018 | #endif | 1020 | #endif |
1019 | } | 1021 | } |
1020 | module_exit(ohci_hcd_mod_exit); | 1022 | module_exit(ohci_hcd_mod_exit); |
diff --git a/drivers/usb/host/ohci-pci.c b/drivers/usb/host/ohci-pci.c index b331ac4d0d62..79705609fd0c 100644 --- a/drivers/usb/host/ohci-pci.c +++ b/drivers/usb/host/ohci-pci.c | |||
@@ -20,10 +20,16 @@ | |||
20 | 20 | ||
21 | /*-------------------------------------------------------------------------*/ | 21 | /*-------------------------------------------------------------------------*/ |
22 | 22 | ||
23 | static int broken_suspend(struct usb_hcd *hcd) | ||
24 | { | ||
25 | device_init_wakeup(&hcd->self.root_hub->dev, 0); | ||
26 | return 0; | ||
27 | } | ||
28 | |||
23 | /* AMD 756, for most chips (early revs), corrupts register | 29 | /* AMD 756, for most chips (early revs), corrupts register |
24 | * values on read ... so enable the vendor workaround. | 30 | * values on read ... so enable the vendor workaround. |
25 | */ | 31 | */ |
26 | static int __devinit ohci_quirk_amd756(struct usb_hcd *hcd) | 32 | static int ohci_quirk_amd756(struct usb_hcd *hcd) |
27 | { | 33 | { |
28 | struct ohci_hcd *ohci = hcd_to_ohci (hcd); | 34 | struct ohci_hcd *ohci = hcd_to_ohci (hcd); |
29 | 35 | ||
@@ -31,16 +37,14 @@ static int __devinit ohci_quirk_amd756(struct usb_hcd *hcd) | |||
31 | ohci_dbg (ohci, "AMD756 erratum 4 workaround\n"); | 37 | ohci_dbg (ohci, "AMD756 erratum 4 workaround\n"); |
32 | 38 | ||
33 | /* also erratum 10 (suspend/resume issues) */ | 39 | /* also erratum 10 (suspend/resume issues) */ |
34 | device_init_wakeup(&hcd->self.root_hub->dev, 0); | 40 | return broken_suspend(hcd); |
35 | |||
36 | return 0; | ||
37 | } | 41 | } |
38 | 42 | ||
39 | /* Apple's OHCI driver has a lot of bizarre workarounds | 43 | /* Apple's OHCI driver has a lot of bizarre workarounds |
40 | * for this chip. Evidently control and bulk lists | 44 | * for this chip. Evidently control and bulk lists |
41 | * can get confused. (B&W G3 models, and ...) | 45 | * can get confused. (B&W G3 models, and ...) |
42 | */ | 46 | */ |
43 | static int __devinit ohci_quirk_opti(struct usb_hcd *hcd) | 47 | static int ohci_quirk_opti(struct usb_hcd *hcd) |
44 | { | 48 | { |
45 | struct ohci_hcd *ohci = hcd_to_ohci (hcd); | 49 | struct ohci_hcd *ohci = hcd_to_ohci (hcd); |
46 | 50 | ||
@@ -53,7 +57,7 @@ static int __devinit ohci_quirk_opti(struct usb_hcd *hcd) | |||
53 | * identify the USB (fn2). This quirk might apply to more or | 57 | * identify the USB (fn2). This quirk might apply to more or |
54 | * even all NSC stuff. | 58 | * even all NSC stuff. |
55 | */ | 59 | */ |
56 | static int __devinit ohci_quirk_ns(struct usb_hcd *hcd) | 60 | static int ohci_quirk_ns(struct usb_hcd *hcd) |
57 | { | 61 | { |
58 | struct pci_dev *pdev = to_pci_dev(hcd->self.controller); | 62 | struct pci_dev *pdev = to_pci_dev(hcd->self.controller); |
59 | struct pci_dev *b; | 63 | struct pci_dev *b; |
@@ -75,7 +79,7 @@ static int __devinit ohci_quirk_ns(struct usb_hcd *hcd) | |||
75 | * delays before control or bulk queues get re-activated | 79 | * delays before control or bulk queues get re-activated |
76 | * in finish_unlinks() | 80 | * in finish_unlinks() |
77 | */ | 81 | */ |
78 | static int __devinit ohci_quirk_zfmicro(struct usb_hcd *hcd) | 82 | static int ohci_quirk_zfmicro(struct usb_hcd *hcd) |
79 | { | 83 | { |
80 | struct ohci_hcd *ohci = hcd_to_ohci (hcd); | 84 | struct ohci_hcd *ohci = hcd_to_ohci (hcd); |
81 | 85 | ||
@@ -88,7 +92,7 @@ static int __devinit ohci_quirk_zfmicro(struct usb_hcd *hcd) | |||
88 | /* Check for Toshiba SCC OHCI which has big endian registers | 92 | /* Check for Toshiba SCC OHCI which has big endian registers |
89 | * and little endian in memory data structures | 93 | * and little endian in memory data structures |
90 | */ | 94 | */ |
91 | static int __devinit ohci_quirk_toshiba_scc(struct usb_hcd *hcd) | 95 | static int ohci_quirk_toshiba_scc(struct usb_hcd *hcd) |
92 | { | 96 | { |
93 | struct ohci_hcd *ohci = hcd_to_ohci (hcd); | 97 | struct ohci_hcd *ohci = hcd_to_ohci (hcd); |
94 | 98 | ||
@@ -129,6 +133,18 @@ static const struct pci_device_id ohci_pci_quirks[] = { | |||
129 | PCI_DEVICE(PCI_VENDOR_ID_TOSHIBA_2, 0x01b6), | 133 | PCI_DEVICE(PCI_VENDOR_ID_TOSHIBA_2, 0x01b6), |
130 | .driver_data = (unsigned long)ohci_quirk_toshiba_scc, | 134 | .driver_data = (unsigned long)ohci_quirk_toshiba_scc, |
131 | }, | 135 | }, |
136 | { | ||
137 | /* Toshiba portege 4000 */ | ||
138 | .vendor = PCI_VENDOR_ID_AL, | ||
139 | .device = 0x5237, | ||
140 | .subvendor = PCI_VENDOR_ID_TOSHIBA_2, | ||
141 | .subdevice = 0x0004, | ||
142 | .driver_data = (unsigned long) broken_suspend, | ||
143 | }, | ||
144 | { | ||
145 | PCI_DEVICE(PCI_VENDOR_ID_ITE, 0x8152), | ||
146 | .driver_data = (unsigned long) broken_suspend, | ||
147 | }, | ||
132 | /* FIXME for some of the early AMD 760 southbridges, OHCI | 148 | /* FIXME for some of the early AMD 760 southbridges, OHCI |
133 | * won't work at all. blacklist them. | 149 | * won't work at all. blacklist them. |
134 | */ | 150 | */ |
diff --git a/drivers/usb/host/uhci-debug.c b/drivers/usb/host/uhci-debug.c index 5d6c06bc4524..1497371583b9 100644 --- a/drivers/usb/host/uhci-debug.c +++ b/drivers/usb/host/uhci-debug.c | |||
@@ -145,7 +145,8 @@ static int uhci_show_urbp(struct urb_priv *urbp, char *buf, int len, int space) | |||
145 | return out - buf; | 145 | return out - buf; |
146 | } | 146 | } |
147 | 147 | ||
148 | static int uhci_show_qh(struct uhci_qh *qh, char *buf, int len, int space) | 148 | static int uhci_show_qh(struct uhci_hcd *uhci, |
149 | struct uhci_qh *qh, char *buf, int len, int space) | ||
149 | { | 150 | { |
150 | char *out = buf; | 151 | char *out = buf; |
151 | int i, nurbs; | 152 | int i, nurbs; |
@@ -190,13 +191,16 @@ static int uhci_show_qh(struct uhci_qh *qh, char *buf, int len, int space) | |||
190 | 191 | ||
191 | if (list_empty(&qh->queue)) { | 192 | if (list_empty(&qh->queue)) { |
192 | out += sprintf(out, "%*s queue is empty\n", space, ""); | 193 | out += sprintf(out, "%*s queue is empty\n", space, ""); |
194 | if (qh == uhci->skel_async_qh) | ||
195 | out += uhci_show_td(uhci->term_td, out, | ||
196 | len - (out - buf), 0); | ||
193 | } else { | 197 | } else { |
194 | struct urb_priv *urbp = list_entry(qh->queue.next, | 198 | struct urb_priv *urbp = list_entry(qh->queue.next, |
195 | struct urb_priv, node); | 199 | struct urb_priv, node); |
196 | struct uhci_td *td = list_entry(urbp->td_list.next, | 200 | struct uhci_td *td = list_entry(urbp->td_list.next, |
197 | struct uhci_td, list); | 201 | struct uhci_td, list); |
198 | 202 | ||
199 | if (cpu_to_le32(td->dma_handle) != (element & ~UHCI_PTR_BITS)) | 203 | if (element != LINK_TO_TD(td)) |
200 | out += sprintf(out, "%*s Element != First TD\n", | 204 | out += sprintf(out, "%*s Element != First TD\n", |
201 | space, ""); | 205 | space, ""); |
202 | i = nurbs = 0; | 206 | i = nurbs = 0; |
@@ -220,16 +224,6 @@ static int uhci_show_qh(struct uhci_qh *qh, char *buf, int len, int space) | |||
220 | return out - buf; | 224 | return out - buf; |
221 | } | 225 | } |
222 | 226 | ||
223 | static const char * const qh_names[] = { | ||
224 | "skel_unlink_qh", "skel_iso_qh", | ||
225 | "skel_int128_qh", "skel_int64_qh", | ||
226 | "skel_int32_qh", "skel_int16_qh", | ||
227 | "skel_int8_qh", "skel_int4_qh", | ||
228 | "skel_int2_qh", "skel_int1_qh", | ||
229 | "skel_ls_control_qh", "skel_fs_control_qh", | ||
230 | "skel_bulk_qh", "skel_term_qh" | ||
231 | }; | ||
232 | |||
233 | static int uhci_show_sc(int port, unsigned short status, char *buf, int len) | 227 | static int uhci_show_sc(int port, unsigned short status, char *buf, int len) |
234 | { | 228 | { |
235 | char *out = buf; | 229 | char *out = buf; |
@@ -352,6 +346,13 @@ static int uhci_sprint_schedule(struct uhci_hcd *uhci, char *buf, int len) | |||
352 | struct uhci_td *td; | 346 | struct uhci_td *td; |
353 | struct list_head *tmp, *head; | 347 | struct list_head *tmp, *head; |
354 | int nframes, nerrs; | 348 | int nframes, nerrs; |
349 | __le32 link; | ||
350 | __le32 fsbr_link; | ||
351 | |||
352 | static const char * const qh_names[] = { | ||
353 | "unlink", "iso", "int128", "int64", "int32", "int16", | ||
354 | "int8", "int4", "int2", "async", "term" | ||
355 | }; | ||
355 | 356 | ||
356 | out += uhci_show_root_hub_state(uhci, out, len - (out - buf)); | 357 | out += uhci_show_root_hub_state(uhci, out, len - (out - buf)); |
357 | out += sprintf(out, "HC status\n"); | 358 | out += sprintf(out, "HC status\n"); |
@@ -374,7 +375,7 @@ static int uhci_sprint_schedule(struct uhci_hcd *uhci, char *buf, int len) | |||
374 | nframes = 10; | 375 | nframes = 10; |
375 | nerrs = 0; | 376 | nerrs = 0; |
376 | for (i = 0; i < UHCI_NUMFRAMES; ++i) { | 377 | for (i = 0; i < UHCI_NUMFRAMES; ++i) { |
377 | __le32 link, qh_dma; | 378 | __le32 qh_dma; |
378 | 379 | ||
379 | j = 0; | 380 | j = 0; |
380 | td = uhci->frame_cpu[i]; | 381 | td = uhci->frame_cpu[i]; |
@@ -393,7 +394,7 @@ static int uhci_sprint_schedule(struct uhci_hcd *uhci, char *buf, int len) | |||
393 | do { | 394 | do { |
394 | td = list_entry(tmp, struct uhci_td, fl_list); | 395 | td = list_entry(tmp, struct uhci_td, fl_list); |
395 | tmp = tmp->next; | 396 | tmp = tmp->next; |
396 | if (cpu_to_le32(td->dma_handle) != link) { | 397 | if (link != LINK_TO_TD(td)) { |
397 | if (nframes > 0) | 398 | if (nframes > 0) |
398 | out += sprintf(out, " link does " | 399 | out += sprintf(out, " link does " |
399 | "not match list entry!\n"); | 400 | "not match list entry!\n"); |
@@ -428,25 +429,24 @@ check_link: | |||
428 | 429 | ||
429 | out += sprintf(out, "Skeleton QHs\n"); | 430 | out += sprintf(out, "Skeleton QHs\n"); |
430 | 431 | ||
432 | fsbr_link = 0; | ||
431 | for (i = 0; i < UHCI_NUM_SKELQH; ++i) { | 433 | for (i = 0; i < UHCI_NUM_SKELQH; ++i) { |
432 | int cnt = 0; | 434 | int cnt = 0; |
433 | 435 | ||
434 | qh = uhci->skelqh[i]; | 436 | qh = uhci->skelqh[i]; |
435 | out += sprintf(out, "- %s\n", qh_names[i]); \ | 437 | out += sprintf(out, "- skel_%s_qh\n", qh_names[i]); \ |
436 | out += uhci_show_qh(qh, out, len - (out - buf), 4); | 438 | out += uhci_show_qh(uhci, qh, out, len - (out - buf), 4); |
437 | 439 | ||
438 | /* Last QH is the Terminating QH, it's different */ | 440 | /* Last QH is the Terminating QH, it's different */ |
439 | if (i == UHCI_NUM_SKELQH - 1) { | 441 | if (i == SKEL_TERM) { |
440 | if (qh->link != UHCI_PTR_TERM) | 442 | if (qh_element(qh) != LINK_TO_TD(uhci->term_td)) |
441 | out += sprintf(out, " bandwidth reclamation on!\n"); | ||
442 | |||
443 | if (qh_element(qh) != cpu_to_le32(uhci->term_td->dma_handle)) | ||
444 | out += sprintf(out, " skel_term_qh element is not set to term_td!\n"); | 443 | out += sprintf(out, " skel_term_qh element is not set to term_td!\n"); |
445 | 444 | link = fsbr_link; | |
446 | continue; | 445 | if (!link) |
446 | link = LINK_TO_QH(uhci->skel_term_qh); | ||
447 | goto check_qh_link; | ||
447 | } | 448 | } |
448 | 449 | ||
449 | j = (i < 9) ? 9 : i+1; /* Next skeleton */ | ||
450 | head = &qh->node; | 450 | head = &qh->node; |
451 | tmp = head->next; | 451 | tmp = head->next; |
452 | 452 | ||
@@ -454,17 +454,26 @@ check_link: | |||
454 | qh = list_entry(tmp, struct uhci_qh, node); | 454 | qh = list_entry(tmp, struct uhci_qh, node); |
455 | tmp = tmp->next; | 455 | tmp = tmp->next; |
456 | if (++cnt <= 10) | 456 | if (++cnt <= 10) |
457 | out += uhci_show_qh(qh, out, | 457 | out += uhci_show_qh(uhci, qh, out, |
458 | len - (out - buf), 4); | 458 | len - (out - buf), 4); |
459 | if (!fsbr_link && qh->skel >= SKEL_FSBR) | ||
460 | fsbr_link = LINK_TO_QH(qh); | ||
459 | } | 461 | } |
460 | if ((cnt -= 10) > 0) | 462 | if ((cnt -= 10) > 0) |
461 | out += sprintf(out, " Skipped %d QHs\n", cnt); | 463 | out += sprintf(out, " Skipped %d QHs\n", cnt); |
462 | 464 | ||
463 | if (i > 1 && i < UHCI_NUM_SKELQH - 1) { | 465 | link = UHCI_PTR_TERM; |
464 | if (qh->link != | 466 | if (i <= SKEL_ISO) |
465 | (cpu_to_le32(uhci->skelqh[j]->dma_handle) | UHCI_PTR_QH)) | 467 | ; |
466 | out += sprintf(out, " last QH not linked to next skeleton!\n"); | 468 | else if (i < SKEL_ASYNC) |
467 | } | 469 | link = LINK_TO_QH(uhci->skel_async_qh); |
470 | else if (!uhci->fsbr_is_on) | ||
471 | ; | ||
472 | else | ||
473 | link = LINK_TO_QH(uhci->skel_term_qh); | ||
474 | check_qh_link: | ||
475 | if (qh->link != link) | ||
476 | out += sprintf(out, " last QH not linked to next skeleton!\n"); | ||
468 | } | 477 | } |
469 | 478 | ||
470 | return out - buf; | 479 | return out - buf; |
@@ -568,8 +577,8 @@ static const struct file_operations uhci_debug_operations = { | |||
568 | static inline void lprintk(char *buf) | 577 | static inline void lprintk(char *buf) |
569 | {} | 578 | {} |
570 | 579 | ||
571 | static inline int uhci_show_qh(struct uhci_qh *qh, char *buf, | 580 | static inline int uhci_show_qh(struct uhci_hcd *uhci, |
572 | int len, int space) | 581 | struct uhci_qh *qh, char *buf, int len, int space) |
573 | { | 582 | { |
574 | return 0; | 583 | return 0; |
575 | } | 584 | } |
diff --git a/drivers/usb/host/uhci-hcd.c b/drivers/usb/host/uhci-hcd.c index ded4df30a631..d22da26ff167 100644 --- a/drivers/usb/host/uhci-hcd.c +++ b/drivers/usb/host/uhci-hcd.c | |||
@@ -13,7 +13,7 @@ | |||
13 | * (C) Copyright 2000 Yggdrasil Computing, Inc. (port of new PCI interface | 13 | * (C) Copyright 2000 Yggdrasil Computing, Inc. (port of new PCI interface |
14 | * support from usb-ohci.c by Adam Richter, adam@yggdrasil.com). | 14 | * support from usb-ohci.c by Adam Richter, adam@yggdrasil.com). |
15 | * (C) Copyright 1999 Gregory P. Smith (from usb-ohci.c) | 15 | * (C) Copyright 1999 Gregory P. Smith (from usb-ohci.c) |
16 | * (C) Copyright 2004-2006 Alan Stern, stern@rowland.harvard.edu | 16 | * (C) Copyright 2004-2007 Alan Stern, stern@rowland.harvard.edu |
17 | * | 17 | * |
18 | * Intel documents this fairly well, and as far as I know there | 18 | * Intel documents this fairly well, and as far as I know there |
19 | * are no royalties or anything like that, but even so there are | 19 | * are no royalties or anything like that, but even so there are |
@@ -107,16 +107,16 @@ static __le32 uhci_frame_skel_link(struct uhci_hcd *uhci, int frame) | |||
107 | * interrupt QHs, which will help spread out bandwidth utilization. | 107 | * interrupt QHs, which will help spread out bandwidth utilization. |
108 | * | 108 | * |
109 | * ffs (Find First bit Set) does exactly what we need: | 109 | * ffs (Find First bit Set) does exactly what we need: |
110 | * 1,3,5,... => ffs = 0 => use skel_int2_qh = skelqh[8], | 110 | * 1,3,5,... => ffs = 0 => use period-2 QH = skelqh[8], |
111 | * 2,6,10,... => ffs = 1 => use skel_int4_qh = skelqh[7], etc. | 111 | * 2,6,10,... => ffs = 1 => use period-4 QH = skelqh[7], etc. |
112 | * ffs >= 7 => not on any high-period queue, so use | 112 | * ffs >= 7 => not on any high-period queue, so use |
113 | * skel_int1_qh = skelqh[9]. | 113 | * period-1 QH = skelqh[9]. |
114 | * Add in UHCI_NUMFRAMES to insure at least one bit is set. | 114 | * Add in UHCI_NUMFRAMES to insure at least one bit is set. |
115 | */ | 115 | */ |
116 | skelnum = 8 - (int) __ffs(frame | UHCI_NUMFRAMES); | 116 | skelnum = 8 - (int) __ffs(frame | UHCI_NUMFRAMES); |
117 | if (skelnum <= 1) | 117 | if (skelnum <= 1) |
118 | skelnum = 9; | 118 | skelnum = 9; |
119 | return UHCI_PTR_QH | cpu_to_le32(uhci->skelqh[skelnum]->dma_handle); | 119 | return LINK_TO_QH(uhci->skelqh[skelnum]); |
120 | } | 120 | } |
121 | 121 | ||
122 | #include "uhci-debug.c" | 122 | #include "uhci-debug.c" |
@@ -540,16 +540,18 @@ static void uhci_shutdown(struct pci_dev *pdev) | |||
540 | * | 540 | * |
541 | * The hardware doesn't really know any difference | 541 | * The hardware doesn't really know any difference |
542 | * in the queues, but the order does matter for the | 542 | * in the queues, but the order does matter for the |
543 | * protocols higher up. The order is: | 543 | * protocols higher up. The order in which the queues |
544 | * are encountered by the hardware is: | ||
544 | * | 545 | * |
545 | * - any isochronous events handled before any | 546 | * - All isochronous events are handled before any |
546 | * of the queues. We don't do that here, because | 547 | * of the queues. We don't do that here, because |
547 | * we'll create the actual TD entries on demand. | 548 | * we'll create the actual TD entries on demand. |
548 | * - The first queue is the interrupt queue. | 549 | * - The first queue is the high-period interrupt queue. |
549 | * - The second queue is the control queue, split into low- and full-speed | 550 | * - The second queue is the period-1 interrupt and async |
550 | * - The third queue is bulk queue. | 551 | * (low-speed control, full-speed control, then bulk) queue. |
551 | * - The fourth queue is the bandwidth reclamation queue, which loops back | 552 | * - The third queue is the terminating bandwidth reclamation queue, |
552 | * to the full-speed control queue. | 553 | * which contains no members, loops back to itself, and is present |
554 | * only when FSBR is on and there are no full-speed control or bulk QHs. | ||
553 | */ | 555 | */ |
554 | static int uhci_start(struct usb_hcd *hcd) | 556 | static int uhci_start(struct usb_hcd *hcd) |
555 | { | 557 | { |
@@ -626,34 +628,19 @@ static int uhci_start(struct usb_hcd *hcd) | |||
626 | } | 628 | } |
627 | 629 | ||
628 | /* | 630 | /* |
629 | * 8 Interrupt queues; link all higher int queues to int1, | 631 | * 8 Interrupt queues; link all higher int queues to int1 = async |
630 | * then link int1 to control and control to bulk | ||
631 | */ | 632 | */ |
632 | uhci->skel_int128_qh->link = | 633 | for (i = SKEL_ISO + 1; i < SKEL_ASYNC; ++i) |
633 | uhci->skel_int64_qh->link = | 634 | uhci->skelqh[i]->link = LINK_TO_QH(uhci->skel_async_qh); |
634 | uhci->skel_int32_qh->link = | 635 | uhci->skel_async_qh->link = UHCI_PTR_TERM; |
635 | uhci->skel_int16_qh->link = | 636 | uhci->skel_term_qh->link = LINK_TO_QH(uhci->skel_term_qh); |
636 | uhci->skel_int8_qh->link = | ||
637 | uhci->skel_int4_qh->link = | ||
638 | uhci->skel_int2_qh->link = UHCI_PTR_QH | | ||
639 | cpu_to_le32(uhci->skel_int1_qh->dma_handle); | ||
640 | |||
641 | uhci->skel_int1_qh->link = UHCI_PTR_QH | | ||
642 | cpu_to_le32(uhci->skel_ls_control_qh->dma_handle); | ||
643 | uhci->skel_ls_control_qh->link = UHCI_PTR_QH | | ||
644 | cpu_to_le32(uhci->skel_fs_control_qh->dma_handle); | ||
645 | uhci->skel_fs_control_qh->link = UHCI_PTR_QH | | ||
646 | cpu_to_le32(uhci->skel_bulk_qh->dma_handle); | ||
647 | uhci->skel_bulk_qh->link = UHCI_PTR_QH | | ||
648 | cpu_to_le32(uhci->skel_term_qh->dma_handle); | ||
649 | 637 | ||
650 | /* This dummy TD is to work around a bug in Intel PIIX controllers */ | 638 | /* This dummy TD is to work around a bug in Intel PIIX controllers */ |
651 | uhci_fill_td(uhci->term_td, 0, uhci_explen(0) | | 639 | uhci_fill_td(uhci->term_td, 0, uhci_explen(0) | |
652 | (0x7f << TD_TOKEN_DEVADDR_SHIFT) | USB_PID_IN, 0); | 640 | (0x7f << TD_TOKEN_DEVADDR_SHIFT) | USB_PID_IN, 0); |
653 | uhci->term_td->link = cpu_to_le32(uhci->term_td->dma_handle); | 641 | uhci->term_td->link = UHCI_PTR_TERM; |
654 | 642 | uhci->skel_async_qh->element = uhci->skel_term_qh->element = | |
655 | uhci->skel_term_qh->link = UHCI_PTR_TERM; | 643 | LINK_TO_TD(uhci->term_td); |
656 | uhci->skel_term_qh->element = cpu_to_le32(uhci->term_td->dma_handle); | ||
657 | 644 | ||
658 | /* | 645 | /* |
659 | * Fill the frame list: make all entries point to the proper | 646 | * Fill the frame list: make all entries point to the proper |
diff --git a/drivers/usb/host/uhci-hcd.h b/drivers/usb/host/uhci-hcd.h index 74469b5bcb61..1b3d23406ac4 100644 --- a/drivers/usb/host/uhci-hcd.h +++ b/drivers/usb/host/uhci-hcd.h | |||
@@ -129,11 +129,12 @@ struct uhci_qh { | |||
129 | __le32 element; /* Queue element (TD) pointer */ | 129 | __le32 element; /* Queue element (TD) pointer */ |
130 | 130 | ||
131 | /* Software fields */ | 131 | /* Software fields */ |
132 | dma_addr_t dma_handle; | ||
133 | |||
132 | struct list_head node; /* Node in the list of QHs */ | 134 | struct list_head node; /* Node in the list of QHs */ |
133 | struct usb_host_endpoint *hep; /* Endpoint information */ | 135 | struct usb_host_endpoint *hep; /* Endpoint information */ |
134 | struct usb_device *udev; | 136 | struct usb_device *udev; |
135 | struct list_head queue; /* Queue of urbps for this QH */ | 137 | struct list_head queue; /* Queue of urbps for this QH */ |
136 | struct uhci_qh *skel; /* Skeleton for this QH */ | ||
137 | struct uhci_td *dummy_td; /* Dummy TD to end the queue */ | 138 | struct uhci_td *dummy_td; /* Dummy TD to end the queue */ |
138 | struct uhci_td *post_td; /* Last TD completed */ | 139 | struct uhci_td *post_td; /* Last TD completed */ |
139 | 140 | ||
@@ -149,8 +150,7 @@ struct uhci_qh { | |||
149 | 150 | ||
150 | int state; /* QH_STATE_xxx; see above */ | 151 | int state; /* QH_STATE_xxx; see above */ |
151 | int type; /* Queue type (control, bulk, etc) */ | 152 | int type; /* Queue type (control, bulk, etc) */ |
152 | 153 | int skel; /* Skeleton queue number */ | |
153 | dma_addr_t dma_handle; | ||
154 | 154 | ||
155 | unsigned int initial_toggle:1; /* Endpoint's current toggle value */ | 155 | unsigned int initial_toggle:1; /* Endpoint's current toggle value */ |
156 | unsigned int needs_fixup:1; /* Must fix the TD toggle values */ | 156 | unsigned int needs_fixup:1; /* Must fix the TD toggle values */ |
@@ -171,6 +171,8 @@ static inline __le32 qh_element(struct uhci_qh *qh) { | |||
171 | return element; | 171 | return element; |
172 | } | 172 | } |
173 | 173 | ||
174 | #define LINK_TO_QH(qh) (UHCI_PTR_QH | cpu_to_le32((qh)->dma_handle)) | ||
175 | |||
174 | 176 | ||
175 | /* | 177 | /* |
176 | * Transfer Descriptors | 178 | * Transfer Descriptors |
@@ -264,6 +266,8 @@ static inline u32 td_status(struct uhci_td *td) { | |||
264 | return le32_to_cpu(status); | 266 | return le32_to_cpu(status); |
265 | } | 267 | } |
266 | 268 | ||
269 | #define LINK_TO_TD(td) (cpu_to_le32((td)->dma_handle)) | ||
270 | |||
267 | 271 | ||
268 | /* | 272 | /* |
269 | * Skeleton Queue Headers | 273 | * Skeleton Queue Headers |
@@ -272,12 +276,13 @@ static inline u32 td_status(struct uhci_td *td) { | |||
272 | /* | 276 | /* |
273 | * The UHCI driver uses QHs with Interrupt, Control and Bulk URBs for | 277 | * The UHCI driver uses QHs with Interrupt, Control and Bulk URBs for |
274 | * automatic queuing. To make it easy to insert entries into the schedule, | 278 | * automatic queuing. To make it easy to insert entries into the schedule, |
275 | * we have a skeleton of QHs for each predefined Interrupt latency, | 279 | * we have a skeleton of QHs for each predefined Interrupt latency. |
276 | * low-speed control, full-speed control, bulk, and terminating QH | 280 | * Asynchronous QHs (low-speed control, full-speed control, and bulk) |
277 | * (see explanation for the terminating QH below). | 281 | * go onto the period-1 interrupt list, since they all get accessed on |
282 | * every frame. | ||
278 | * | 283 | * |
279 | * When we want to add a new QH, we add it to the end of the list for the | 284 | * When we want to add a new QH, we add it to the list starting from the |
280 | * skeleton QH. For instance, the schedule list can look like this: | 285 | * appropriate skeleton QH. For instance, the schedule can look like this: |
281 | * | 286 | * |
282 | * skel int128 QH | 287 | * skel int128 QH |
283 | * dev 1 interrupt QH | 288 | * dev 1 interrupt QH |
@@ -285,50 +290,47 @@ static inline u32 td_status(struct uhci_td *td) { | |||
285 | * skel int64 QH | 290 | * skel int64 QH |
286 | * skel int32 QH | 291 | * skel int32 QH |
287 | * ... | 292 | * ... |
288 | * skel int1 QH | 293 | * skel int1 + async QH |
289 | * skel low-speed control QH | 294 | * dev 5 low-speed control QH |
290 | * dev 5 control QH | ||
291 | * skel full-speed control QH | ||
292 | * skel bulk QH | ||
293 | * dev 1 bulk QH | 295 | * dev 1 bulk QH |
294 | * dev 2 bulk QH | 296 | * dev 2 bulk QH |
295 | * skel terminating QH | ||
296 | * | 297 | * |
297 | * The terminating QH is used for 2 reasons: | 298 | * There is a special terminating QH used to keep full-speed bandwidth |
298 | * - To place a terminating TD which is used to workaround a PIIX bug | 299 | * reclamation active when no full-speed control or bulk QHs are linked |
299 | * (see Intel errata for explanation), and | 300 | * into the schedule. It has an inactive TD (to work around a PIIX bug, |
300 | * - To loop back to the full-speed control queue for full-speed bandwidth | 301 | * see the Intel errata) and it points back to itself. |
301 | * reclamation. | ||
302 | * | 302 | * |
303 | * There's a special skeleton QH for Isochronous QHs. It never appears | 303 | * There's a special skeleton QH for Isochronous QHs which never appears |
304 | * on the schedule, and Isochronous TDs go on the schedule before the | 304 | * on the schedule. Isochronous TDs go on the schedule before the |
305 | * the skeleton QHs. The hardware accesses them directly rather than | 305 | * the skeleton QHs. The hardware accesses them directly rather than |
306 | * through their QH, which is used only for bookkeeping purposes. | 306 | * through their QH, which is used only for bookkeeping purposes. |
307 | * While the UHCI spec doesn't forbid the use of QHs for Isochronous, | 307 | * While the UHCI spec doesn't forbid the use of QHs for Isochronous, |
308 | * it doesn't use them either. And the spec says that queues never | 308 | * it doesn't use them either. And the spec says that queues never |
309 | * advance on an error completion status, which makes them totally | 309 | * advance on an error completion status, which makes them totally |
310 | * unsuitable for Isochronous transfers. | 310 | * unsuitable for Isochronous transfers. |
311 | * | ||
312 | * There's also a special skeleton QH used for QHs which are in the process | ||
313 | * of unlinking and so may still be in use by the hardware. It too never | ||
314 | * appears on the schedule. | ||
311 | */ | 315 | */ |
312 | 316 | ||
313 | #define UHCI_NUM_SKELQH 14 | 317 | #define UHCI_NUM_SKELQH 11 |
314 | #define skel_unlink_qh skelqh[0] | 318 | #define SKEL_UNLINK 0 |
315 | #define skel_iso_qh skelqh[1] | 319 | #define skel_unlink_qh skelqh[SKEL_UNLINK] |
316 | #define skel_int128_qh skelqh[2] | 320 | #define SKEL_ISO 1 |
317 | #define skel_int64_qh skelqh[3] | 321 | #define skel_iso_qh skelqh[SKEL_ISO] |
318 | #define skel_int32_qh skelqh[4] | 322 | /* int128, int64, ..., int1 = 2, 3, ..., 9 */ |
319 | #define skel_int16_qh skelqh[5] | 323 | #define SKEL_INDEX(exponent) (9 - exponent) |
320 | #define skel_int8_qh skelqh[6] | 324 | #define SKEL_ASYNC 9 |
321 | #define skel_int4_qh skelqh[7] | 325 | #define skel_async_qh skelqh[SKEL_ASYNC] |
322 | #define skel_int2_qh skelqh[8] | 326 | #define SKEL_TERM 10 |
323 | #define skel_int1_qh skelqh[9] | 327 | #define skel_term_qh skelqh[SKEL_TERM] |
324 | #define skel_ls_control_qh skelqh[10] | 328 | |
325 | #define skel_fs_control_qh skelqh[11] | 329 | /* The following entries refer to sublists of skel_async_qh */ |
326 | #define skel_bulk_qh skelqh[12] | 330 | #define SKEL_LS_CONTROL 20 |
327 | #define skel_term_qh skelqh[13] | 331 | #define SKEL_FS_CONTROL 21 |
328 | 332 | #define SKEL_FSBR SKEL_FS_CONTROL | |
329 | /* Find the skelqh entry corresponding to an interval exponent */ | 333 | #define SKEL_BULK 22 |
330 | #define UHCI_SKEL_INDEX(exponent) (9 - exponent) | ||
331 | |||
332 | 334 | ||
333 | /* | 335 | /* |
334 | * The UHCI controller and root hub | 336 | * The UHCI controller and root hub |
diff --git a/drivers/usb/host/uhci-hub.c b/drivers/usb/host/uhci-hub.c index bacc25c53ba3..8e4427aebb14 100644 --- a/drivers/usb/host/uhci-hub.c +++ b/drivers/usb/host/uhci-hub.c | |||
@@ -33,6 +33,9 @@ static __u8 root_hub_hub_des[] = | |||
33 | /* status change bits: nonzero writes will clear */ | 33 | /* status change bits: nonzero writes will clear */ |
34 | #define RWC_BITS (USBPORTSC_OCC | USBPORTSC_PEC | USBPORTSC_CSC) | 34 | #define RWC_BITS (USBPORTSC_OCC | USBPORTSC_PEC | USBPORTSC_CSC) |
35 | 35 | ||
36 | /* suspend/resume bits: port suspended or port resuming */ | ||
37 | #define SUSPEND_BITS (USBPORTSC_SUSP | USBPORTSC_RD) | ||
38 | |||
36 | /* A port that either is connected or has a changed-bit set will prevent | 39 | /* A port that either is connected or has a changed-bit set will prevent |
37 | * us from AUTO_STOPPING. | 40 | * us from AUTO_STOPPING. |
38 | */ | 41 | */ |
@@ -96,8 +99,8 @@ static void uhci_finish_suspend(struct uhci_hcd *uhci, int port, | |||
96 | int status; | 99 | int status; |
97 | int i; | 100 | int i; |
98 | 101 | ||
99 | if (inw(port_addr) & (USBPORTSC_SUSP | USBPORTSC_RD)) { | 102 | if (inw(port_addr) & SUSPEND_BITS) { |
100 | CLR_RH_PORTSTAT(USBPORTSC_SUSP | USBPORTSC_RD); | 103 | CLR_RH_PORTSTAT(SUSPEND_BITS); |
101 | if (test_bit(port, &uhci->resuming_ports)) | 104 | if (test_bit(port, &uhci->resuming_ports)) |
102 | set_bit(port, &uhci->port_c_suspend); | 105 | set_bit(port, &uhci->port_c_suspend); |
103 | 106 | ||
@@ -107,7 +110,7 @@ static void uhci_finish_suspend(struct uhci_hcd *uhci, int port, | |||
107 | * Experiments show that some controllers take longer, so | 110 | * Experiments show that some controllers take longer, so |
108 | * we'll poll for completion. */ | 111 | * we'll poll for completion. */ |
109 | for (i = 0; i < 10; ++i) { | 112 | for (i = 0; i < 10; ++i) { |
110 | if (!(inw(port_addr) & USBPORTSC_RD)) | 113 | if (!(inw(port_addr) & SUSPEND_BITS)) |
111 | break; | 114 | break; |
112 | udelay(1); | 115 | udelay(1); |
113 | } | 116 | } |
@@ -289,7 +292,7 @@ static int uhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue, | |||
289 | wPortStatus |= USB_PORT_STAT_CONNECTION; | 292 | wPortStatus |= USB_PORT_STAT_CONNECTION; |
290 | if (status & USBPORTSC_PE) { | 293 | if (status & USBPORTSC_PE) { |
291 | wPortStatus |= USB_PORT_STAT_ENABLE; | 294 | wPortStatus |= USB_PORT_STAT_ENABLE; |
292 | if (status & (USBPORTSC_SUSP | USBPORTSC_RD)) | 295 | if (status & SUSPEND_BITS) |
293 | wPortStatus |= USB_PORT_STAT_SUSPEND; | 296 | wPortStatus |= USB_PORT_STAT_SUSPEND; |
294 | } | 297 | } |
295 | if (status & USBPORTSC_OC) | 298 | if (status & USBPORTSC_OC) |
diff --git a/drivers/usb/host/uhci-q.c b/drivers/usb/host/uhci-q.c index 68e66b33e726..4aed305982ec 100644 --- a/drivers/usb/host/uhci-q.c +++ b/drivers/usb/host/uhci-q.c | |||
@@ -13,7 +13,7 @@ | |||
13 | * (C) Copyright 2000 Yggdrasil Computing, Inc. (port of new PCI interface | 13 | * (C) Copyright 2000 Yggdrasil Computing, Inc. (port of new PCI interface |
14 | * support from usb-ohci.c by Adam Richter, adam@yggdrasil.com). | 14 | * support from usb-ohci.c by Adam Richter, adam@yggdrasil.com). |
15 | * (C) Copyright 1999 Gregory P. Smith (from usb-ohci.c) | 15 | * (C) Copyright 1999 Gregory P. Smith (from usb-ohci.c) |
16 | * (C) Copyright 2004-2006 Alan Stern, stern@rowland.harvard.edu | 16 | * (C) Copyright 2004-2007 Alan Stern, stern@rowland.harvard.edu |
17 | */ | 17 | */ |
18 | 18 | ||
19 | 19 | ||
@@ -45,15 +45,27 @@ static inline void uhci_clear_next_interrupt(struct uhci_hcd *uhci) | |||
45 | */ | 45 | */ |
46 | static void uhci_fsbr_on(struct uhci_hcd *uhci) | 46 | static void uhci_fsbr_on(struct uhci_hcd *uhci) |
47 | { | 47 | { |
48 | struct uhci_qh *lqh; | ||
49 | |||
50 | /* The terminating skeleton QH always points back to the first | ||
51 | * FSBR QH. Make the last async QH point to the terminating | ||
52 | * skeleton QH. */ | ||
48 | uhci->fsbr_is_on = 1; | 53 | uhci->fsbr_is_on = 1; |
49 | uhci->skel_term_qh->link = cpu_to_le32( | 54 | lqh = list_entry(uhci->skel_async_qh->node.prev, |
50 | uhci->skel_fs_control_qh->dma_handle) | UHCI_PTR_QH; | 55 | struct uhci_qh, node); |
56 | lqh->link = LINK_TO_QH(uhci->skel_term_qh); | ||
51 | } | 57 | } |
52 | 58 | ||
53 | static void uhci_fsbr_off(struct uhci_hcd *uhci) | 59 | static void uhci_fsbr_off(struct uhci_hcd *uhci) |
54 | { | 60 | { |
61 | struct uhci_qh *lqh; | ||
62 | |||
63 | /* Remove the link from the last async QH to the terminating | ||
64 | * skeleton QH. */ | ||
55 | uhci->fsbr_is_on = 0; | 65 | uhci->fsbr_is_on = 0; |
56 | uhci->skel_term_qh->link = UHCI_PTR_TERM; | 66 | lqh = list_entry(uhci->skel_async_qh->node.prev, |
67 | struct uhci_qh, node); | ||
68 | lqh->link = UHCI_PTR_TERM; | ||
57 | } | 69 | } |
58 | 70 | ||
59 | static void uhci_add_fsbr(struct uhci_hcd *uhci, struct urb *urb) | 71 | static void uhci_add_fsbr(struct uhci_hcd *uhci, struct urb *urb) |
@@ -111,10 +123,14 @@ static struct uhci_td *uhci_alloc_td(struct uhci_hcd *uhci) | |||
111 | 123 | ||
112 | static void uhci_free_td(struct uhci_hcd *uhci, struct uhci_td *td) | 124 | static void uhci_free_td(struct uhci_hcd *uhci, struct uhci_td *td) |
113 | { | 125 | { |
114 | if (!list_empty(&td->list)) | 126 | if (!list_empty(&td->list)) { |
115 | dev_warn(uhci_dev(uhci), "td %p still in list!\n", td); | 127 | dev_warn(uhci_dev(uhci), "td %p still in list!\n", td); |
116 | if (!list_empty(&td->fl_list)) | 128 | WARN_ON(1); |
129 | } | ||
130 | if (!list_empty(&td->fl_list)) { | ||
117 | dev_warn(uhci_dev(uhci), "td %p still in fl_list!\n", td); | 131 | dev_warn(uhci_dev(uhci), "td %p still in fl_list!\n", td); |
132 | WARN_ON(1); | ||
133 | } | ||
118 | 134 | ||
119 | dma_pool_free(uhci->td_pool, td, td->dma_handle); | 135 | dma_pool_free(uhci->td_pool, td, td->dma_handle); |
120 | } | 136 | } |
@@ -158,11 +174,11 @@ static inline void uhci_insert_td_in_frame_list(struct uhci_hcd *uhci, | |||
158 | 174 | ||
159 | td->link = ltd->link; | 175 | td->link = ltd->link; |
160 | wmb(); | 176 | wmb(); |
161 | ltd->link = cpu_to_le32(td->dma_handle); | 177 | ltd->link = LINK_TO_TD(td); |
162 | } else { | 178 | } else { |
163 | td->link = uhci->frame[framenum]; | 179 | td->link = uhci->frame[framenum]; |
164 | wmb(); | 180 | wmb(); |
165 | uhci->frame[framenum] = cpu_to_le32(td->dma_handle); | 181 | uhci->frame[framenum] = LINK_TO_TD(td); |
166 | uhci->frame_cpu[framenum] = td; | 182 | uhci->frame_cpu[framenum] = td; |
167 | } | 183 | } |
168 | } | 184 | } |
@@ -184,7 +200,7 @@ static inline void uhci_remove_td_from_frame_list(struct uhci_hcd *uhci, | |||
184 | struct uhci_td *ntd; | 200 | struct uhci_td *ntd; |
185 | 201 | ||
186 | ntd = list_entry(td->fl_list.next, struct uhci_td, fl_list); | 202 | ntd = list_entry(td->fl_list.next, struct uhci_td, fl_list); |
187 | uhci->frame[td->frame] = cpu_to_le32(ntd->dma_handle); | 203 | uhci->frame[td->frame] = LINK_TO_TD(ntd); |
188 | uhci->frame_cpu[td->frame] = ntd; | 204 | uhci->frame_cpu[td->frame] = ntd; |
189 | } | 205 | } |
190 | } else { | 206 | } else { |
@@ -279,8 +295,10 @@ static struct uhci_qh *uhci_alloc_qh(struct uhci_hcd *uhci, | |||
279 | static void uhci_free_qh(struct uhci_hcd *uhci, struct uhci_qh *qh) | 295 | static void uhci_free_qh(struct uhci_hcd *uhci, struct uhci_qh *qh) |
280 | { | 296 | { |
281 | WARN_ON(qh->state != QH_STATE_IDLE && qh->udev); | 297 | WARN_ON(qh->state != QH_STATE_IDLE && qh->udev); |
282 | if (!list_empty(&qh->queue)) | 298 | if (!list_empty(&qh->queue)) { |
283 | dev_warn(uhci_dev(uhci), "qh %p list not empty!\n", qh); | 299 | dev_warn(uhci_dev(uhci), "qh %p list not empty!\n", qh); |
300 | WARN_ON(1); | ||
301 | } | ||
284 | 302 | ||
285 | list_del(&qh->node); | 303 | list_del(&qh->node); |
286 | if (qh->udev) { | 304 | if (qh->udev) { |
@@ -405,12 +423,66 @@ static void uhci_fixup_toggles(struct uhci_qh *qh, int skip_first) | |||
405 | } | 423 | } |
406 | 424 | ||
407 | /* | 425 | /* |
408 | * Put a QH on the schedule in both hardware and software | 426 | * Link an Isochronous QH into its skeleton's list |
409 | */ | 427 | */ |
410 | static void uhci_activate_qh(struct uhci_hcd *uhci, struct uhci_qh *qh) | 428 | static inline void link_iso(struct uhci_hcd *uhci, struct uhci_qh *qh) |
429 | { | ||
430 | list_add_tail(&qh->node, &uhci->skel_iso_qh->node); | ||
431 | |||
432 | /* Isochronous QHs aren't linked by the hardware */ | ||
433 | } | ||
434 | |||
435 | /* | ||
436 | * Link a high-period interrupt QH into the schedule at the end of its | ||
437 | * skeleton's list | ||
438 | */ | ||
439 | static void link_interrupt(struct uhci_hcd *uhci, struct uhci_qh *qh) | ||
411 | { | 440 | { |
412 | struct uhci_qh *pqh; | 441 | struct uhci_qh *pqh; |
413 | 442 | ||
443 | list_add_tail(&qh->node, &uhci->skelqh[qh->skel]->node); | ||
444 | |||
445 | pqh = list_entry(qh->node.prev, struct uhci_qh, node); | ||
446 | qh->link = pqh->link; | ||
447 | wmb(); | ||
448 | pqh->link = LINK_TO_QH(qh); | ||
449 | } | ||
450 | |||
451 | /* | ||
452 | * Link a period-1 interrupt or async QH into the schedule at the | ||
453 | * correct spot in the async skeleton's list, and update the FSBR link | ||
454 | */ | ||
455 | static void link_async(struct uhci_hcd *uhci, struct uhci_qh *qh) | ||
456 | { | ||
457 | struct uhci_qh *pqh; | ||
458 | __le32 link_to_new_qh; | ||
459 | |||
460 | /* Find the predecessor QH for our new one and insert it in the list. | ||
461 | * The list of QHs is expected to be short, so linear search won't | ||
462 | * take too long. */ | ||
463 | list_for_each_entry_reverse(pqh, &uhci->skel_async_qh->node, node) { | ||
464 | if (pqh->skel <= qh->skel) | ||
465 | break; | ||
466 | } | ||
467 | list_add(&qh->node, &pqh->node); | ||
468 | |||
469 | /* Link it into the schedule */ | ||
470 | qh->link = pqh->link; | ||
471 | wmb(); | ||
472 | link_to_new_qh = LINK_TO_QH(qh); | ||
473 | pqh->link = link_to_new_qh; | ||
474 | |||
475 | /* If this is now the first FSBR QH, link the terminating skeleton | ||
476 | * QH to it. */ | ||
477 | if (pqh->skel < SKEL_FSBR && qh->skel >= SKEL_FSBR) | ||
478 | uhci->skel_term_qh->link = link_to_new_qh; | ||
479 | } | ||
480 | |||
481 | /* | ||
482 | * Put a QH on the schedule in both hardware and software | ||
483 | */ | ||
484 | static void uhci_activate_qh(struct uhci_hcd *uhci, struct uhci_qh *qh) | ||
485 | { | ||
414 | WARN_ON(list_empty(&qh->queue)); | 486 | WARN_ON(list_empty(&qh->queue)); |
415 | 487 | ||
416 | /* Set the element pointer if it isn't set already. | 488 | /* Set the element pointer if it isn't set already. |
@@ -421,7 +493,7 @@ static void uhci_activate_qh(struct uhci_hcd *uhci, struct uhci_qh *qh) | |||
421 | struct uhci_td *td = list_entry(urbp->td_list.next, | 493 | struct uhci_td *td = list_entry(urbp->td_list.next, |
422 | struct uhci_td, list); | 494 | struct uhci_td, list); |
423 | 495 | ||
424 | qh->element = cpu_to_le32(td->dma_handle); | 496 | qh->element = LINK_TO_TD(td); |
425 | } | 497 | } |
426 | 498 | ||
427 | /* Treat the queue as if it has just advanced */ | 499 | /* Treat the queue as if it has just advanced */ |
@@ -432,36 +504,68 @@ static void uhci_activate_qh(struct uhci_hcd *uhci, struct uhci_qh *qh) | |||
432 | return; | 504 | return; |
433 | qh->state = QH_STATE_ACTIVE; | 505 | qh->state = QH_STATE_ACTIVE; |
434 | 506 | ||
435 | /* Move the QH from its old list to the end of the appropriate | 507 | /* Move the QH from its old list to the correct spot in the appropriate |
436 | * skeleton's list */ | 508 | * skeleton's list */ |
437 | if (qh == uhci->next_qh) | 509 | if (qh == uhci->next_qh) |
438 | uhci->next_qh = list_entry(qh->node.next, struct uhci_qh, | 510 | uhci->next_qh = list_entry(qh->node.next, struct uhci_qh, |
439 | node); | 511 | node); |
440 | list_move_tail(&qh->node, &qh->skel->node); | 512 | list_del(&qh->node); |
513 | |||
514 | if (qh->skel == SKEL_ISO) | ||
515 | link_iso(uhci, qh); | ||
516 | else if (qh->skel < SKEL_ASYNC) | ||
517 | link_interrupt(uhci, qh); | ||
518 | else | ||
519 | link_async(uhci, qh); | ||
520 | } | ||
521 | |||
522 | /* | ||
523 | * Unlink a high-period interrupt QH from the schedule | ||
524 | */ | ||
525 | static void unlink_interrupt(struct uhci_hcd *uhci, struct uhci_qh *qh) | ||
526 | { | ||
527 | struct uhci_qh *pqh; | ||
441 | 528 | ||
442 | /* Link it into the schedule */ | ||
443 | pqh = list_entry(qh->node.prev, struct uhci_qh, node); | 529 | pqh = list_entry(qh->node.prev, struct uhci_qh, node); |
444 | qh->link = pqh->link; | 530 | pqh->link = qh->link; |
445 | wmb(); | 531 | mb(); |
446 | pqh->link = UHCI_PTR_QH | cpu_to_le32(qh->dma_handle); | ||
447 | } | 532 | } |
448 | 533 | ||
449 | /* | 534 | /* |
450 | * Take a QH off the hardware schedule | 535 | * Unlink a period-1 interrupt or async QH from the schedule |
451 | */ | 536 | */ |
452 | static void uhci_unlink_qh(struct uhci_hcd *uhci, struct uhci_qh *qh) | 537 | static void unlink_async(struct uhci_hcd *uhci, struct uhci_qh *qh) |
453 | { | 538 | { |
454 | struct uhci_qh *pqh; | 539 | struct uhci_qh *pqh; |
540 | __le32 link_to_next_qh = qh->link; | ||
455 | 541 | ||
542 | pqh = list_entry(qh->node.prev, struct uhci_qh, node); | ||
543 | pqh->link = link_to_next_qh; | ||
544 | |||
545 | /* If this was the old first FSBR QH, link the terminating skeleton | ||
546 | * QH to the next (new first FSBR) QH. */ | ||
547 | if (pqh->skel < SKEL_FSBR && qh->skel >= SKEL_FSBR) | ||
548 | uhci->skel_term_qh->link = link_to_next_qh; | ||
549 | mb(); | ||
550 | } | ||
551 | |||
552 | /* | ||
553 | * Take a QH off the hardware schedule | ||
554 | */ | ||
555 | static void uhci_unlink_qh(struct uhci_hcd *uhci, struct uhci_qh *qh) | ||
556 | { | ||
456 | if (qh->state == QH_STATE_UNLINKING) | 557 | if (qh->state == QH_STATE_UNLINKING) |
457 | return; | 558 | return; |
458 | WARN_ON(qh->state != QH_STATE_ACTIVE || !qh->udev); | 559 | WARN_ON(qh->state != QH_STATE_ACTIVE || !qh->udev); |
459 | qh->state = QH_STATE_UNLINKING; | 560 | qh->state = QH_STATE_UNLINKING; |
460 | 561 | ||
461 | /* Unlink the QH from the schedule and record when we did it */ | 562 | /* Unlink the QH from the schedule and record when we did it */ |
462 | pqh = list_entry(qh->node.prev, struct uhci_qh, node); | 563 | if (qh->skel == SKEL_ISO) |
463 | pqh->link = qh->link; | 564 | ; |
464 | mb(); | 565 | else if (qh->skel < SKEL_ASYNC) |
566 | unlink_interrupt(uhci, qh); | ||
567 | else | ||
568 | unlink_async(uhci, qh); | ||
465 | 569 | ||
466 | uhci_get_current_frame_number(uhci); | 570 | uhci_get_current_frame_number(uhci); |
467 | qh->unlink_frame = uhci->frame_number; | 571 | qh->unlink_frame = uhci->frame_number; |
@@ -642,9 +746,11 @@ static void uhci_free_urb_priv(struct uhci_hcd *uhci, | |||
642 | { | 746 | { |
643 | struct uhci_td *td, *tmp; | 747 | struct uhci_td *td, *tmp; |
644 | 748 | ||
645 | if (!list_empty(&urbp->node)) | 749 | if (!list_empty(&urbp->node)) { |
646 | dev_warn(uhci_dev(uhci), "urb %p still on QH's list!\n", | 750 | dev_warn(uhci_dev(uhci), "urb %p still on QH's list!\n", |
647 | urbp->urb); | 751 | urbp->urb); |
752 | WARN_ON(1); | ||
753 | } | ||
648 | 754 | ||
649 | list_for_each_entry_safe(td, tmp, &urbp->td_list, list) { | 755 | list_for_each_entry_safe(td, tmp, &urbp->td_list, list) { |
650 | uhci_remove_td_from_urbp(td); | 756 | uhci_remove_td_from_urbp(td); |
@@ -697,6 +803,7 @@ static int uhci_submit_control(struct uhci_hcd *uhci, struct urb *urb, | |||
697 | dma_addr_t data = urb->transfer_dma; | 803 | dma_addr_t data = urb->transfer_dma; |
698 | __le32 *plink; | 804 | __le32 *plink; |
699 | struct urb_priv *urbp = urb->hcpriv; | 805 | struct urb_priv *urbp = urb->hcpriv; |
806 | int skel; | ||
700 | 807 | ||
701 | /* The "pipe" thing contains the destination in bits 8--18 */ | 808 | /* The "pipe" thing contains the destination in bits 8--18 */ |
702 | destination = (urb->pipe & PIPE_DEVEP_MASK) | USB_PID_SETUP; | 809 | destination = (urb->pipe & PIPE_DEVEP_MASK) | USB_PID_SETUP; |
@@ -737,7 +844,7 @@ static int uhci_submit_control(struct uhci_hcd *uhci, struct urb *urb, | |||
737 | td = uhci_alloc_td(uhci); | 844 | td = uhci_alloc_td(uhci); |
738 | if (!td) | 845 | if (!td) |
739 | goto nomem; | 846 | goto nomem; |
740 | *plink = cpu_to_le32(td->dma_handle); | 847 | *plink = LINK_TO_TD(td); |
741 | 848 | ||
742 | /* Alternate Data0/1 (start with Data1) */ | 849 | /* Alternate Data0/1 (start with Data1) */ |
743 | destination ^= TD_TOKEN_TOGGLE; | 850 | destination ^= TD_TOKEN_TOGGLE; |
@@ -757,7 +864,7 @@ static int uhci_submit_control(struct uhci_hcd *uhci, struct urb *urb, | |||
757 | td = uhci_alloc_td(uhci); | 864 | td = uhci_alloc_td(uhci); |
758 | if (!td) | 865 | if (!td) |
759 | goto nomem; | 866 | goto nomem; |
760 | *plink = cpu_to_le32(td->dma_handle); | 867 | *plink = LINK_TO_TD(td); |
761 | 868 | ||
762 | /* | 869 | /* |
763 | * It's IN if the pipe is an output pipe or we're not expecting | 870 | * It's IN if the pipe is an output pipe or we're not expecting |
@@ -784,7 +891,7 @@ static int uhci_submit_control(struct uhci_hcd *uhci, struct urb *urb, | |||
784 | td = uhci_alloc_td(uhci); | 891 | td = uhci_alloc_td(uhci); |
785 | if (!td) | 892 | if (!td) |
786 | goto nomem; | 893 | goto nomem; |
787 | *plink = cpu_to_le32(td->dma_handle); | 894 | *plink = LINK_TO_TD(td); |
788 | 895 | ||
789 | uhci_fill_td(td, 0, USB_PID_OUT | uhci_explen(0), 0); | 896 | uhci_fill_td(td, 0, USB_PID_OUT | uhci_explen(0), 0); |
790 | wmb(); | 897 | wmb(); |
@@ -797,11 +904,13 @@ static int uhci_submit_control(struct uhci_hcd *uhci, struct urb *urb, | |||
797 | * isn't in the CONFIGURED state. */ | 904 | * isn't in the CONFIGURED state. */ |
798 | if (urb->dev->speed == USB_SPEED_LOW || | 905 | if (urb->dev->speed == USB_SPEED_LOW || |
799 | urb->dev->state != USB_STATE_CONFIGURED) | 906 | urb->dev->state != USB_STATE_CONFIGURED) |
800 | qh->skel = uhci->skel_ls_control_qh; | 907 | skel = SKEL_LS_CONTROL; |
801 | else { | 908 | else { |
802 | qh->skel = uhci->skel_fs_control_qh; | 909 | skel = SKEL_FS_CONTROL; |
803 | uhci_add_fsbr(uhci, urb); | 910 | uhci_add_fsbr(uhci, urb); |
804 | } | 911 | } |
912 | if (qh->state != QH_STATE_ACTIVE) | ||
913 | qh->skel = skel; | ||
805 | 914 | ||
806 | urb->actual_length = -8; /* Account for the SETUP packet */ | 915 | urb->actual_length = -8; /* Account for the SETUP packet */ |
807 | return 0; | 916 | return 0; |
@@ -860,7 +969,7 @@ static int uhci_submit_common(struct uhci_hcd *uhci, struct urb *urb, | |||
860 | td = uhci_alloc_td(uhci); | 969 | td = uhci_alloc_td(uhci); |
861 | if (!td) | 970 | if (!td) |
862 | goto nomem; | 971 | goto nomem; |
863 | *plink = cpu_to_le32(td->dma_handle); | 972 | *plink = LINK_TO_TD(td); |
864 | } | 973 | } |
865 | uhci_add_td_to_urbp(td, urbp); | 974 | uhci_add_td_to_urbp(td, urbp); |
866 | uhci_fill_td(td, status, | 975 | uhci_fill_td(td, status, |
@@ -888,7 +997,7 @@ static int uhci_submit_common(struct uhci_hcd *uhci, struct urb *urb, | |||
888 | td = uhci_alloc_td(uhci); | 997 | td = uhci_alloc_td(uhci); |
889 | if (!td) | 998 | if (!td) |
890 | goto nomem; | 999 | goto nomem; |
891 | *plink = cpu_to_le32(td->dma_handle); | 1000 | *plink = LINK_TO_TD(td); |
892 | 1001 | ||
893 | uhci_add_td_to_urbp(td, urbp); | 1002 | uhci_add_td_to_urbp(td, urbp); |
894 | uhci_fill_td(td, status, | 1003 | uhci_fill_td(td, status, |
@@ -914,7 +1023,7 @@ static int uhci_submit_common(struct uhci_hcd *uhci, struct urb *urb, | |||
914 | td = uhci_alloc_td(uhci); | 1023 | td = uhci_alloc_td(uhci); |
915 | if (!td) | 1024 | if (!td) |
916 | goto nomem; | 1025 | goto nomem; |
917 | *plink = cpu_to_le32(td->dma_handle); | 1026 | *plink = LINK_TO_TD(td); |
918 | 1027 | ||
919 | uhci_fill_td(td, 0, USB_PID_OUT | uhci_explen(0), 0); | 1028 | uhci_fill_td(td, 0, USB_PID_OUT | uhci_explen(0), 0); |
920 | wmb(); | 1029 | wmb(); |
@@ -931,7 +1040,7 @@ nomem: | |||
931 | return -ENOMEM; | 1040 | return -ENOMEM; |
932 | } | 1041 | } |
933 | 1042 | ||
934 | static inline int uhci_submit_bulk(struct uhci_hcd *uhci, struct urb *urb, | 1043 | static int uhci_submit_bulk(struct uhci_hcd *uhci, struct urb *urb, |
935 | struct uhci_qh *qh) | 1044 | struct uhci_qh *qh) |
936 | { | 1045 | { |
937 | int ret; | 1046 | int ret; |
@@ -940,7 +1049,8 @@ static inline int uhci_submit_bulk(struct uhci_hcd *uhci, struct urb *urb, | |||
940 | if (urb->dev->speed == USB_SPEED_LOW) | 1049 | if (urb->dev->speed == USB_SPEED_LOW) |
941 | return -EINVAL; | 1050 | return -EINVAL; |
942 | 1051 | ||
943 | qh->skel = uhci->skel_bulk_qh; | 1052 | if (qh->state != QH_STATE_ACTIVE) |
1053 | qh->skel = SKEL_BULK; | ||
944 | ret = uhci_submit_common(uhci, urb, qh); | 1054 | ret = uhci_submit_common(uhci, urb, qh); |
945 | if (ret == 0) | 1055 | if (ret == 0) |
946 | uhci_add_fsbr(uhci, urb); | 1056 | uhci_add_fsbr(uhci, urb); |
@@ -968,7 +1078,7 @@ static int uhci_submit_interrupt(struct uhci_hcd *uhci, struct urb *urb, | |||
968 | if (exponent < 0) | 1078 | if (exponent < 0) |
969 | return -EINVAL; | 1079 | return -EINVAL; |
970 | qh->period = 1 << exponent; | 1080 | qh->period = 1 << exponent; |
971 | qh->skel = uhci->skelqh[UHCI_SKEL_INDEX(exponent)]; | 1081 | qh->skel = SKEL_INDEX(exponent); |
972 | 1082 | ||
973 | /* For now, interrupt phase is fixed by the layout | 1083 | /* For now, interrupt phase is fixed by the layout |
974 | * of the QH lists. */ | 1084 | * of the QH lists. */ |
@@ -1005,7 +1115,7 @@ static int uhci_fixup_short_transfer(struct uhci_hcd *uhci, | |||
1005 | * the queue at the status stage transaction, which is | 1115 | * the queue at the status stage transaction, which is |
1006 | * the last TD. */ | 1116 | * the last TD. */ |
1007 | WARN_ON(list_empty(&urbp->td_list)); | 1117 | WARN_ON(list_empty(&urbp->td_list)); |
1008 | qh->element = cpu_to_le32(td->dma_handle); | 1118 | qh->element = LINK_TO_TD(td); |
1009 | tmp = td->list.prev; | 1119 | tmp = td->list.prev; |
1010 | ret = -EINPROGRESS; | 1120 | ret = -EINPROGRESS; |
1011 | 1121 | ||
@@ -1069,7 +1179,7 @@ static int uhci_result_common(struct uhci_hcd *uhci, struct urb *urb) | |||
1069 | 1179 | ||
1070 | if (debug > 1 && errbuf) { | 1180 | if (debug > 1 && errbuf) { |
1071 | /* Print the chain for debugging */ | 1181 | /* Print the chain for debugging */ |
1072 | uhci_show_qh(urbp->qh, errbuf, | 1182 | uhci_show_qh(uhci, urbp->qh, errbuf, |
1073 | ERRBUF_LEN, 0); | 1183 | ERRBUF_LEN, 0); |
1074 | lprintk(errbuf); | 1184 | lprintk(errbuf); |
1075 | } | 1185 | } |
@@ -1216,7 +1326,7 @@ static int uhci_submit_isochronous(struct uhci_hcd *uhci, struct urb *urb, | |||
1216 | qh->iso_status = 0; | 1326 | qh->iso_status = 0; |
1217 | } | 1327 | } |
1218 | 1328 | ||
1219 | qh->skel = uhci->skel_iso_qh; | 1329 | qh->skel = SKEL_ISO; |
1220 | if (!qh->bandwidth_reserved) | 1330 | if (!qh->bandwidth_reserved) |
1221 | uhci_reserve_bandwidth(uhci, qh); | 1331 | uhci_reserve_bandwidth(uhci, qh); |
1222 | return 0; | 1332 | return 0; |
@@ -1566,8 +1676,7 @@ static int uhci_advance_check(struct uhci_hcd *uhci, struct uhci_qh *qh) | |||
1566 | if (time_after(jiffies, qh->advance_jiffies + QH_WAIT_TIMEOUT)) { | 1676 | if (time_after(jiffies, qh->advance_jiffies + QH_WAIT_TIMEOUT)) { |
1567 | 1677 | ||
1568 | /* Detect the Intel bug and work around it */ | 1678 | /* Detect the Intel bug and work around it */ |
1569 | if (qh->post_td && qh_element(qh) == | 1679 | if (qh->post_td && qh_element(qh) == LINK_TO_TD(qh->post_td)) { |
1570 | cpu_to_le32(qh->post_td->dma_handle)) { | ||
1571 | qh->element = qh->post_td->link; | 1680 | qh->element = qh->post_td->link; |
1572 | qh->advance_jiffies = jiffies; | 1681 | qh->advance_jiffies = jiffies; |
1573 | ret = 1; | 1682 | ret = 1; |
diff --git a/drivers/usb/input/Kconfig b/drivers/usb/input/Kconfig index 69a9f3b6d0a9..a792e42f58af 100644 --- a/drivers/usb/input/Kconfig +++ b/drivers/usb/input/Kconfig | |||
@@ -4,151 +4,6 @@ | |||
4 | comment "USB Input Devices" | 4 | comment "USB Input Devices" |
5 | depends on USB | 5 | depends on USB |
6 | 6 | ||
7 | config USB_HID | ||
8 | tristate "USB Human Interface Device (full HID) support" | ||
9 | default y | ||
10 | depends on USB && INPUT | ||
11 | select HID | ||
12 | ---help--- | ||
13 | Say Y here if you want full HID support to connect USB keyboards, | ||
14 | mice, joysticks, graphic tablets, or any other HID based devices | ||
15 | to your computer via USB, as well as Uninterruptible Power Supply | ||
16 | (UPS) and monitor control devices. | ||
17 | |||
18 | You can't use this driver and the HIDBP (Boot Protocol) keyboard | ||
19 | and mouse drivers at the same time. More information is available: | ||
20 | <file:Documentation/input/input.txt>. | ||
21 | |||
22 | If unsure, say Y. | ||
23 | |||
24 | To compile this driver as a module, choose M here: the | ||
25 | module will be called usbhid. | ||
26 | |||
27 | comment "Input core support is needed for USB HID input layer or HIDBP support" | ||
28 | depends on USB_HID && INPUT=n | ||
29 | |||
30 | config USB_HIDINPUT_POWERBOOK | ||
31 | bool "Enable support for iBook/PowerBook special keys" | ||
32 | default n | ||
33 | depends on USB_HID | ||
34 | help | ||
35 | Say Y here if you want support for the special keys (Fn, Numlock) on | ||
36 | Apple iBooks and PowerBooks. | ||
37 | |||
38 | If unsure, say N. | ||
39 | |||
40 | config HID_FF | ||
41 | bool "Force feedback support (EXPERIMENTAL)" | ||
42 | depends on USB_HID && EXPERIMENTAL | ||
43 | help | ||
44 | Say Y here is you want force feedback support for a few HID devices. | ||
45 | See below for a list of supported devices. | ||
46 | |||
47 | See <file:Documentation/input/ff.txt> for a description of the force | ||
48 | feedback API. | ||
49 | |||
50 | If unsure, say N. | ||
51 | |||
52 | config HID_PID | ||
53 | bool "PID device support" | ||
54 | depends on HID_FF | ||
55 | help | ||
56 | Say Y here if you have a PID-compliant device and wish to enable force | ||
57 | feedback for it. Microsoft Sidewinder Force Feedback 2 is one of such | ||
58 | devices. | ||
59 | |||
60 | config LOGITECH_FF | ||
61 | bool "Logitech devices support" | ||
62 | depends on HID_FF | ||
63 | select INPUT_FF_MEMLESS if USB_HID | ||
64 | help | ||
65 | Say Y here if you have one of these devices: | ||
66 | - Logitech WingMan Cordless RumblePad | ||
67 | - Logitech WingMan Cordless RumblePad 2 | ||
68 | - Logitech WingMan Force 3D | ||
69 | - Logitech Formula Force EX | ||
70 | - Logitech MOMO Force wheel | ||
71 | |||
72 | and if you want to enable force feedback for them. | ||
73 | Note: if you say N here, this device will still be supported, but without | ||
74 | force feedback. | ||
75 | |||
76 | config PANTHERLORD_FF | ||
77 | bool "PantherLord USB/PS2 2in1 Adapter support" | ||
78 | depends on HID_FF | ||
79 | select INPUT_FF_MEMLESS if USB_HID | ||
80 | help | ||
81 | Say Y here if you have a PantherLord USB/PS2 2in1 Adapter and want | ||
82 | to enable force feedback support for it. | ||
83 | |||
84 | config THRUSTMASTER_FF | ||
85 | bool "ThrustMaster FireStorm Dual Power 2 support (EXPERIMENTAL)" | ||
86 | depends on HID_FF && EXPERIMENTAL | ||
87 | select INPUT_FF_MEMLESS if USB_HID | ||
88 | help | ||
89 | Say Y here if you have a THRUSTMASTER FireStore Dual Power 2, | ||
90 | and want to enable force feedback support for it. | ||
91 | Note: if you say N here, this device will still be supported, but without | ||
92 | force feedback. | ||
93 | |||
94 | config ZEROPLUS_FF | ||
95 | bool "Zeroplus based game controller support" | ||
96 | depends on HID_FF | ||
97 | select INPUT_FF_MEMLESS if USB_HID | ||
98 | help | ||
99 | Say Y here if you have a Zeroplus based game controller and want to | ||
100 | enable force feedback for it. | ||
101 | |||
102 | config USB_HIDDEV | ||
103 | bool "/dev/hiddev raw HID device support" | ||
104 | depends on USB_HID | ||
105 | help | ||
106 | Say Y here if you want to support HID devices (from the USB | ||
107 | specification standpoint) that aren't strictly user interface | ||
108 | devices, like monitor controls and Uninterruptable Power Supplies. | ||
109 | |||
110 | This module supports these devices separately using a separate | ||
111 | event interface on /dev/usb/hiddevX (char 180:96 to 180:111). | ||
112 | |||
113 | If unsure, say Y. | ||
114 | |||
115 | menu "USB HID Boot Protocol drivers" | ||
116 | depends on USB!=n && USB_HID!=y | ||
117 | |||
118 | config USB_KBD | ||
119 | tristate "USB HIDBP Keyboard (simple Boot) support" | ||
120 | depends on USB && INPUT | ||
121 | ---help--- | ||
122 | Say Y here only if you are absolutely sure that you don't want | ||
123 | to use the generic HID driver for your USB keyboard and prefer | ||
124 | to use the keyboard in its limited Boot Protocol mode instead. | ||
125 | |||
126 | This is almost certainly not what you want. This is mostly | ||
127 | useful for embedded applications or simple keyboards. | ||
128 | |||
129 | To compile this driver as a module, choose M here: the | ||
130 | module will be called usbkbd. | ||
131 | |||
132 | If even remotely unsure, say N. | ||
133 | |||
134 | config USB_MOUSE | ||
135 | tristate "USB HIDBP Mouse (simple Boot) support" | ||
136 | depends on USB && INPUT | ||
137 | ---help--- | ||
138 | Say Y here only if you are absolutely sure that you don't want | ||
139 | to use the generic HID driver for your USB mouse and prefer | ||
140 | to use the mouse in its limited Boot Protocol mode instead. | ||
141 | |||
142 | This is almost certainly not what you want. This is mostly | ||
143 | useful for embedded applications or simple mice. | ||
144 | |||
145 | To compile this driver as a module, choose M here: the | ||
146 | module will be called usbmouse. | ||
147 | |||
148 | If even remotely unsure, say N. | ||
149 | |||
150 | endmenu | ||
151 | |||
152 | config USB_AIPTEK | 7 | config USB_AIPTEK |
153 | tristate "Aiptek 6000U/8000U tablet support" | 8 | tristate "Aiptek 6000U/8000U tablet support" |
154 | depends on USB && INPUT | 9 | depends on USB && INPUT |
diff --git a/drivers/usb/input/Makefile b/drivers/usb/input/Makefile index f8c35b66c466..284a0734e0cd 100644 --- a/drivers/usb/input/Makefile +++ b/drivers/usb/input/Makefile | |||
@@ -4,40 +4,12 @@ | |||
4 | 4 | ||
5 | # Multipart objects. | 5 | # Multipart objects. |
6 | wacom-objs := wacom_wac.o wacom_sys.o | 6 | wacom-objs := wacom_wac.o wacom_sys.o |
7 | usbhid-objs := hid-core.o | ||
8 | |||
9 | # Optional parts of multipart objects. | ||
10 | |||
11 | ifeq ($(CONFIG_USB_HIDDEV),y) | ||
12 | usbhid-objs += hiddev.o | ||
13 | endif | ||
14 | ifeq ($(CONFIG_HID_PID),y) | ||
15 | usbhid-objs += hid-pidff.o | ||
16 | endif | ||
17 | ifeq ($(CONFIG_LOGITECH_FF),y) | ||
18 | usbhid-objs += hid-lgff.o | ||
19 | endif | ||
20 | ifeq ($(CONFIG_PANTHERLORD_FF),y) | ||
21 | usbhid-objs += hid-plff.o | ||
22 | endif | ||
23 | ifeq ($(CONFIG_THRUSTMASTER_FF),y) | ||
24 | usbhid-objs += hid-tmff.o | ||
25 | endif | ||
26 | ifeq ($(CONFIG_ZEROPLUS_FF),y) | ||
27 | usbhid-objs += hid-zpff.o | ||
28 | endif | ||
29 | ifeq ($(CONFIG_HID_FF),y) | ||
30 | usbhid-objs += hid-ff.o | ||
31 | endif | ||
32 | 7 | ||
33 | obj-$(CONFIG_USB_AIPTEK) += aiptek.o | 8 | obj-$(CONFIG_USB_AIPTEK) += aiptek.o |
34 | obj-$(CONFIG_USB_ATI_REMOTE) += ati_remote.o | 9 | obj-$(CONFIG_USB_ATI_REMOTE) += ati_remote.o |
35 | obj-$(CONFIG_USB_ATI_REMOTE2) += ati_remote2.o | 10 | obj-$(CONFIG_USB_ATI_REMOTE2) += ati_remote2.o |
36 | obj-$(CONFIG_USB_HID) += usbhid.o | ||
37 | obj-$(CONFIG_USB_KBD) += usbkbd.o | ||
38 | obj-$(CONFIG_USB_KBTAB) += kbtab.o | 11 | obj-$(CONFIG_USB_KBTAB) += kbtab.o |
39 | obj-$(CONFIG_USB_KEYSPAN_REMOTE) += keyspan_remote.o | 12 | obj-$(CONFIG_USB_KEYSPAN_REMOTE) += keyspan_remote.o |
40 | obj-$(CONFIG_USB_MOUSE) += usbmouse.o | ||
41 | obj-$(CONFIG_USB_TOUCHSCREEN) += usbtouchscreen.o | 13 | obj-$(CONFIG_USB_TOUCHSCREEN) += usbtouchscreen.o |
42 | obj-$(CONFIG_USB_POWERMATE) += powermate.o | 14 | obj-$(CONFIG_USB_POWERMATE) += powermate.o |
43 | obj-$(CONFIG_USB_WACOM) += wacom.o | 15 | obj-$(CONFIG_USB_WACOM) += wacom.o |
@@ -45,7 +17,7 @@ obj-$(CONFIG_USB_ACECAD) += acecad.o | |||
45 | obj-$(CONFIG_USB_YEALINK) += yealink.o | 17 | obj-$(CONFIG_USB_YEALINK) += yealink.o |
46 | obj-$(CONFIG_USB_XPAD) += xpad.o | 18 | obj-$(CONFIG_USB_XPAD) += xpad.o |
47 | obj-$(CONFIG_USB_APPLETOUCH) += appletouch.o | 19 | obj-$(CONFIG_USB_APPLETOUCH) += appletouch.o |
48 | obj-$(CONFIG_USB_GTCO) += gtco.o | 20 | obj-$(CONFIG_USB_GTCO) += gtco.o |
49 | 21 | ||
50 | ifeq ($(CONFIG_USB_DEBUG),y) | 22 | ifeq ($(CONFIG_USB_DEBUG),y) |
51 | EXTRA_CFLAGS += -DDEBUG | 23 | EXTRA_CFLAGS += -DDEBUG |
diff --git a/drivers/usb/input/gtco.c b/drivers/usb/input/gtco.c index dbd207efb8f5..b2ca10f2fe0e 100644 --- a/drivers/usb/input/gtco.c +++ b/drivers/usb/input/gtco.c | |||
@@ -223,7 +223,7 @@ static void parse_hid_report_descriptor(struct gtco *device, char * report, | |||
223 | __u32 oldval[TAG_GLOB_MAX]; | 223 | __u32 oldval[TAG_GLOB_MAX]; |
224 | 224 | ||
225 | /* Debug stuff */ | 225 | /* Debug stuff */ |
226 | char maintype='x'; | 226 | char maintype = 'x'; |
227 | char globtype[12]; | 227 | char globtype[12]; |
228 | int indent = 0; | 228 | int indent = 0; |
229 | char indentstr[10] = ""; | 229 | char indentstr[10] = ""; |
diff --git a/drivers/usb/input/hid-core.c b/drivers/usb/input/hid-core.c deleted file mode 100644 index 4d8ed3d71a15..000000000000 --- a/drivers/usb/input/hid-core.c +++ /dev/null | |||
@@ -1,1459 +0,0 @@ | |||
1 | /* | ||
2 | * USB HID support for Linux | ||
3 | * | ||
4 | * Copyright (c) 1999 Andreas Gal | ||
5 | * Copyright (c) 2000-2005 Vojtech Pavlik <vojtech@suse.cz> | ||
6 | * Copyright (c) 2005 Michael Haboustak <mike-@cinci.rr.com> for Concept2, Inc | ||
7 | * Copyright (c) 2006 Jiri Kosina | ||
8 | */ | ||
9 | |||
10 | /* | ||
11 | * This program is free software; you can redistribute it and/or modify it | ||
12 | * under the terms of the GNU General Public License as published by the Free | ||
13 | * Software Foundation; either version 2 of the License, or (at your option) | ||
14 | * any later version. | ||
15 | */ | ||
16 | |||
17 | #include <linux/module.h> | ||
18 | #include <linux/slab.h> | ||
19 | #include <linux/init.h> | ||
20 | #include <linux/kernel.h> | ||
21 | #include <linux/list.h> | ||
22 | #include <linux/mm.h> | ||
23 | #include <linux/smp_lock.h> | ||
24 | #include <linux/spinlock.h> | ||
25 | #include <asm/unaligned.h> | ||
26 | #include <asm/byteorder.h> | ||
27 | #include <linux/input.h> | ||
28 | #include <linux/wait.h> | ||
29 | |||
30 | #undef DEBUG | ||
31 | #undef DEBUG_DATA | ||
32 | |||
33 | #include <linux/usb.h> | ||
34 | |||
35 | #include <linux/hid.h> | ||
36 | #include <linux/hiddev.h> | ||
37 | #include <linux/hid-debug.h> | ||
38 | #include "usbhid.h" | ||
39 | |||
40 | /* | ||
41 | * Version Information | ||
42 | */ | ||
43 | |||
44 | #define DRIVER_VERSION "v2.6" | ||
45 | #define DRIVER_AUTHOR "Andreas Gal, Vojtech Pavlik" | ||
46 | #define DRIVER_DESC "USB HID core driver" | ||
47 | #define DRIVER_LICENSE "GPL" | ||
48 | |||
49 | static char *hid_types[] = {"Device", "Pointer", "Mouse", "Device", "Joystick", | ||
50 | "Gamepad", "Keyboard", "Keypad", "Multi-Axis Controller"}; | ||
51 | /* | ||
52 | * Module parameters. | ||
53 | */ | ||
54 | |||
55 | static unsigned int hid_mousepoll_interval; | ||
56 | module_param_named(mousepoll, hid_mousepoll_interval, uint, 0644); | ||
57 | MODULE_PARM_DESC(mousepoll, "Polling interval of mice"); | ||
58 | |||
59 | /* | ||
60 | * Input submission and I/O error handler. | ||
61 | */ | ||
62 | |||
63 | static void hid_io_error(struct hid_device *hid); | ||
64 | |||
65 | /* Start up the input URB */ | ||
66 | static int hid_start_in(struct hid_device *hid) | ||
67 | { | ||
68 | unsigned long flags; | ||
69 | int rc = 0; | ||
70 | struct usbhid_device *usbhid = hid->driver_data; | ||
71 | |||
72 | spin_lock_irqsave(&usbhid->inlock, flags); | ||
73 | if (hid->open > 0 && !test_bit(HID_SUSPENDED, &usbhid->iofl) && | ||
74 | !test_and_set_bit(HID_IN_RUNNING, &usbhid->iofl)) { | ||
75 | rc = usb_submit_urb(usbhid->urbin, GFP_ATOMIC); | ||
76 | if (rc != 0) | ||
77 | clear_bit(HID_IN_RUNNING, &usbhid->iofl); | ||
78 | } | ||
79 | spin_unlock_irqrestore(&usbhid->inlock, flags); | ||
80 | return rc; | ||
81 | } | ||
82 | |||
83 | /* I/O retry timer routine */ | ||
84 | static void hid_retry_timeout(unsigned long _hid) | ||
85 | { | ||
86 | struct hid_device *hid = (struct hid_device *) _hid; | ||
87 | struct usbhid_device *usbhid = hid->driver_data; | ||
88 | |||
89 | dev_dbg(&usbhid->intf->dev, "retrying intr urb\n"); | ||
90 | if (hid_start_in(hid)) | ||
91 | hid_io_error(hid); | ||
92 | } | ||
93 | |||
94 | /* Workqueue routine to reset the device or clear a halt */ | ||
95 | static void hid_reset(struct work_struct *work) | ||
96 | { | ||
97 | struct usbhid_device *usbhid = | ||
98 | container_of(work, struct usbhid_device, reset_work); | ||
99 | struct hid_device *hid = usbhid->hid; | ||
100 | int rc_lock, rc = 0; | ||
101 | |||
102 | if (test_bit(HID_CLEAR_HALT, &usbhid->iofl)) { | ||
103 | dev_dbg(&usbhid->intf->dev, "clear halt\n"); | ||
104 | rc = usb_clear_halt(hid_to_usb_dev(hid), usbhid->urbin->pipe); | ||
105 | clear_bit(HID_CLEAR_HALT, &usbhid->iofl); | ||
106 | hid_start_in(hid); | ||
107 | } | ||
108 | |||
109 | else if (test_bit(HID_RESET_PENDING, &usbhid->iofl)) { | ||
110 | dev_dbg(&usbhid->intf->dev, "resetting device\n"); | ||
111 | rc = rc_lock = usb_lock_device_for_reset(hid_to_usb_dev(hid), usbhid->intf); | ||
112 | if (rc_lock >= 0) { | ||
113 | rc = usb_reset_composite_device(hid_to_usb_dev(hid), usbhid->intf); | ||
114 | if (rc_lock) | ||
115 | usb_unlock_device(hid_to_usb_dev(hid)); | ||
116 | } | ||
117 | clear_bit(HID_RESET_PENDING, &usbhid->iofl); | ||
118 | } | ||
119 | |||
120 | switch (rc) { | ||
121 | case 0: | ||
122 | if (!test_bit(HID_IN_RUNNING, &usbhid->iofl)) | ||
123 | hid_io_error(hid); | ||
124 | break; | ||
125 | default: | ||
126 | err("can't reset device, %s-%s/input%d, status %d", | ||
127 | hid_to_usb_dev(hid)->bus->bus_name, | ||
128 | hid_to_usb_dev(hid)->devpath, | ||
129 | usbhid->ifnum, rc); | ||
130 | /* FALLTHROUGH */ | ||
131 | case -EHOSTUNREACH: | ||
132 | case -ENODEV: | ||
133 | case -EINTR: | ||
134 | break; | ||
135 | } | ||
136 | } | ||
137 | |||
138 | /* Main I/O error handler */ | ||
139 | static void hid_io_error(struct hid_device *hid) | ||
140 | { | ||
141 | unsigned long flags; | ||
142 | struct usbhid_device *usbhid = hid->driver_data; | ||
143 | |||
144 | spin_lock_irqsave(&usbhid->inlock, flags); | ||
145 | |||
146 | /* Stop when disconnected */ | ||
147 | if (usb_get_intfdata(usbhid->intf) == NULL) | ||
148 | goto done; | ||
149 | |||
150 | /* When an error occurs, retry at increasing intervals */ | ||
151 | if (usbhid->retry_delay == 0) { | ||
152 | usbhid->retry_delay = 13; /* Then 26, 52, 104, 104, ... */ | ||
153 | usbhid->stop_retry = jiffies + msecs_to_jiffies(1000); | ||
154 | } else if (usbhid->retry_delay < 100) | ||
155 | usbhid->retry_delay *= 2; | ||
156 | |||
157 | if (time_after(jiffies, usbhid->stop_retry)) { | ||
158 | |||
159 | /* Retries failed, so do a port reset */ | ||
160 | if (!test_and_set_bit(HID_RESET_PENDING, &usbhid->iofl)) { | ||
161 | schedule_work(&usbhid->reset_work); | ||
162 | goto done; | ||
163 | } | ||
164 | } | ||
165 | |||
166 | mod_timer(&usbhid->io_retry, | ||
167 | jiffies + msecs_to_jiffies(usbhid->retry_delay)); | ||
168 | done: | ||
169 | spin_unlock_irqrestore(&usbhid->inlock, flags); | ||
170 | } | ||
171 | |||
172 | /* | ||
173 | * Input interrupt completion handler. | ||
174 | */ | ||
175 | |||
176 | static void hid_irq_in(struct urb *urb) | ||
177 | { | ||
178 | struct hid_device *hid = urb->context; | ||
179 | struct usbhid_device *usbhid = hid->driver_data; | ||
180 | int status; | ||
181 | |||
182 | switch (urb->status) { | ||
183 | case 0: /* success */ | ||
184 | usbhid->retry_delay = 0; | ||
185 | hid_input_report(urb->context, HID_INPUT_REPORT, | ||
186 | urb->transfer_buffer, | ||
187 | urb->actual_length, 1); | ||
188 | break; | ||
189 | case -EPIPE: /* stall */ | ||
190 | clear_bit(HID_IN_RUNNING, &usbhid->iofl); | ||
191 | set_bit(HID_CLEAR_HALT, &usbhid->iofl); | ||
192 | schedule_work(&usbhid->reset_work); | ||
193 | return; | ||
194 | case -ECONNRESET: /* unlink */ | ||
195 | case -ENOENT: | ||
196 | case -ESHUTDOWN: /* unplug */ | ||
197 | clear_bit(HID_IN_RUNNING, &usbhid->iofl); | ||
198 | return; | ||
199 | case -EILSEQ: /* protocol error or unplug */ | ||
200 | case -EPROTO: /* protocol error or unplug */ | ||
201 | case -ETIME: /* protocol error or unplug */ | ||
202 | case -ETIMEDOUT: /* Should never happen, but... */ | ||
203 | clear_bit(HID_IN_RUNNING, &usbhid->iofl); | ||
204 | hid_io_error(hid); | ||
205 | return; | ||
206 | default: /* error */ | ||
207 | warn("input irq status %d received", urb->status); | ||
208 | } | ||
209 | |||
210 | status = usb_submit_urb(urb, GFP_ATOMIC); | ||
211 | if (status) { | ||
212 | clear_bit(HID_IN_RUNNING, &usbhid->iofl); | ||
213 | if (status != -EPERM) { | ||
214 | err("can't resubmit intr, %s-%s/input%d, status %d", | ||
215 | hid_to_usb_dev(hid)->bus->bus_name, | ||
216 | hid_to_usb_dev(hid)->devpath, | ||
217 | usbhid->ifnum, status); | ||
218 | hid_io_error(hid); | ||
219 | } | ||
220 | } | ||
221 | } | ||
222 | |||
223 | static int hid_submit_out(struct hid_device *hid) | ||
224 | { | ||
225 | struct hid_report *report; | ||
226 | struct usbhid_device *usbhid = hid->driver_data; | ||
227 | |||
228 | report = usbhid->out[usbhid->outtail]; | ||
229 | |||
230 | hid_output_report(report, usbhid->outbuf); | ||
231 | usbhid->urbout->transfer_buffer_length = ((report->size - 1) >> 3) + 1 + (report->id > 0); | ||
232 | usbhid->urbout->dev = hid_to_usb_dev(hid); | ||
233 | |||
234 | dbg("submitting out urb"); | ||
235 | |||
236 | if (usb_submit_urb(usbhid->urbout, GFP_ATOMIC)) { | ||
237 | err("usb_submit_urb(out) failed"); | ||
238 | return -1; | ||
239 | } | ||
240 | |||
241 | return 0; | ||
242 | } | ||
243 | |||
244 | static int hid_submit_ctrl(struct hid_device *hid) | ||
245 | { | ||
246 | struct hid_report *report; | ||
247 | unsigned char dir; | ||
248 | int len; | ||
249 | struct usbhid_device *usbhid = hid->driver_data; | ||
250 | |||
251 | report = usbhid->ctrl[usbhid->ctrltail].report; | ||
252 | dir = usbhid->ctrl[usbhid->ctrltail].dir; | ||
253 | |||
254 | len = ((report->size - 1) >> 3) + 1 + (report->id > 0); | ||
255 | if (dir == USB_DIR_OUT) { | ||
256 | hid_output_report(report, usbhid->ctrlbuf); | ||
257 | usbhid->urbctrl->pipe = usb_sndctrlpipe(hid_to_usb_dev(hid), 0); | ||
258 | usbhid->urbctrl->transfer_buffer_length = len; | ||
259 | } else { | ||
260 | int maxpacket, padlen; | ||
261 | |||
262 | usbhid->urbctrl->pipe = usb_rcvctrlpipe(hid_to_usb_dev(hid), 0); | ||
263 | maxpacket = usb_maxpacket(hid_to_usb_dev(hid), usbhid->urbctrl->pipe, 0); | ||
264 | if (maxpacket > 0) { | ||
265 | padlen = (len + maxpacket - 1) / maxpacket; | ||
266 | padlen *= maxpacket; | ||
267 | if (padlen > usbhid->bufsize) | ||
268 | padlen = usbhid->bufsize; | ||
269 | } else | ||
270 | padlen = 0; | ||
271 | usbhid->urbctrl->transfer_buffer_length = padlen; | ||
272 | } | ||
273 | usbhid->urbctrl->dev = hid_to_usb_dev(hid); | ||
274 | |||
275 | usbhid->cr->bRequestType = USB_TYPE_CLASS | USB_RECIP_INTERFACE | dir; | ||
276 | usbhid->cr->bRequest = (dir == USB_DIR_OUT) ? HID_REQ_SET_REPORT : HID_REQ_GET_REPORT; | ||
277 | usbhid->cr->wValue = cpu_to_le16(((report->type + 1) << 8) | report->id); | ||
278 | usbhid->cr->wIndex = cpu_to_le16(usbhid->ifnum); | ||
279 | usbhid->cr->wLength = cpu_to_le16(len); | ||
280 | |||
281 | dbg("submitting ctrl urb: %s wValue=0x%04x wIndex=0x%04x wLength=%u", | ||
282 | usbhid->cr->bRequest == HID_REQ_SET_REPORT ? "Set_Report" : "Get_Report", | ||
283 | usbhid->cr->wValue, usbhid->cr->wIndex, usbhid->cr->wLength); | ||
284 | |||
285 | if (usb_submit_urb(usbhid->urbctrl, GFP_ATOMIC)) { | ||
286 | err("usb_submit_urb(ctrl) failed"); | ||
287 | return -1; | ||
288 | } | ||
289 | |||
290 | return 0; | ||
291 | } | ||
292 | |||
293 | /* | ||
294 | * Output interrupt completion handler. | ||
295 | */ | ||
296 | |||
297 | static void hid_irq_out(struct urb *urb) | ||
298 | { | ||
299 | struct hid_device *hid = urb->context; | ||
300 | struct usbhid_device *usbhid = hid->driver_data; | ||
301 | unsigned long flags; | ||
302 | int unplug = 0; | ||
303 | |||
304 | switch (urb->status) { | ||
305 | case 0: /* success */ | ||
306 | break; | ||
307 | case -ESHUTDOWN: /* unplug */ | ||
308 | unplug = 1; | ||
309 | case -EILSEQ: /* protocol error or unplug */ | ||
310 | case -EPROTO: /* protocol error or unplug */ | ||
311 | case -ECONNRESET: /* unlink */ | ||
312 | case -ENOENT: | ||
313 | break; | ||
314 | default: /* error */ | ||
315 | warn("output irq status %d received", urb->status); | ||
316 | } | ||
317 | |||
318 | spin_lock_irqsave(&usbhid->outlock, flags); | ||
319 | |||
320 | if (unplug) | ||
321 | usbhid->outtail = usbhid->outhead; | ||
322 | else | ||
323 | usbhid->outtail = (usbhid->outtail + 1) & (HID_OUTPUT_FIFO_SIZE - 1); | ||
324 | |||
325 | if (usbhid->outhead != usbhid->outtail) { | ||
326 | if (hid_submit_out(hid)) { | ||
327 | clear_bit(HID_OUT_RUNNING, &usbhid->iofl); | ||
328 | wake_up(&hid->wait); | ||
329 | } | ||
330 | spin_unlock_irqrestore(&usbhid->outlock, flags); | ||
331 | return; | ||
332 | } | ||
333 | |||
334 | clear_bit(HID_OUT_RUNNING, &usbhid->iofl); | ||
335 | spin_unlock_irqrestore(&usbhid->outlock, flags); | ||
336 | wake_up(&hid->wait); | ||
337 | } | ||
338 | |||
339 | /* | ||
340 | * Control pipe completion handler. | ||
341 | */ | ||
342 | |||
343 | static void hid_ctrl(struct urb *urb) | ||
344 | { | ||
345 | struct hid_device *hid = urb->context; | ||
346 | struct usbhid_device *usbhid = hid->driver_data; | ||
347 | unsigned long flags; | ||
348 | int unplug = 0; | ||
349 | |||
350 | spin_lock_irqsave(&usbhid->ctrllock, flags); | ||
351 | |||
352 | switch (urb->status) { | ||
353 | case 0: /* success */ | ||
354 | if (usbhid->ctrl[usbhid->ctrltail].dir == USB_DIR_IN) | ||
355 | hid_input_report(urb->context, usbhid->ctrl[usbhid->ctrltail].report->type, | ||
356 | urb->transfer_buffer, urb->actual_length, 0); | ||
357 | break; | ||
358 | case -ESHUTDOWN: /* unplug */ | ||
359 | unplug = 1; | ||
360 | case -EILSEQ: /* protocol error or unplug */ | ||
361 | case -EPROTO: /* protocol error or unplug */ | ||
362 | case -ECONNRESET: /* unlink */ | ||
363 | case -ENOENT: | ||
364 | case -EPIPE: /* report not available */ | ||
365 | break; | ||
366 | default: /* error */ | ||
367 | warn("ctrl urb status %d received", urb->status); | ||
368 | } | ||
369 | |||
370 | if (unplug) | ||
371 | usbhid->ctrltail = usbhid->ctrlhead; | ||
372 | else | ||
373 | usbhid->ctrltail = (usbhid->ctrltail + 1) & (HID_CONTROL_FIFO_SIZE - 1); | ||
374 | |||
375 | if (usbhid->ctrlhead != usbhid->ctrltail) { | ||
376 | if (hid_submit_ctrl(hid)) { | ||
377 | clear_bit(HID_CTRL_RUNNING, &usbhid->iofl); | ||
378 | wake_up(&hid->wait); | ||
379 | } | ||
380 | spin_unlock_irqrestore(&usbhid->ctrllock, flags); | ||
381 | return; | ||
382 | } | ||
383 | |||
384 | clear_bit(HID_CTRL_RUNNING, &usbhid->iofl); | ||
385 | spin_unlock_irqrestore(&usbhid->ctrllock, flags); | ||
386 | wake_up(&hid->wait); | ||
387 | } | ||
388 | |||
389 | void usbhid_submit_report(struct hid_device *hid, struct hid_report *report, unsigned char dir) | ||
390 | { | ||
391 | int head; | ||
392 | unsigned long flags; | ||
393 | struct usbhid_device *usbhid = hid->driver_data; | ||
394 | |||
395 | if ((hid->quirks & HID_QUIRK_NOGET) && dir == USB_DIR_IN) | ||
396 | return; | ||
397 | |||
398 | if (usbhid->urbout && dir == USB_DIR_OUT && report->type == HID_OUTPUT_REPORT) { | ||
399 | |||
400 | spin_lock_irqsave(&usbhid->outlock, flags); | ||
401 | |||
402 | if ((head = (usbhid->outhead + 1) & (HID_OUTPUT_FIFO_SIZE - 1)) == usbhid->outtail) { | ||
403 | spin_unlock_irqrestore(&usbhid->outlock, flags); | ||
404 | warn("output queue full"); | ||
405 | return; | ||
406 | } | ||
407 | |||
408 | usbhid->out[usbhid->outhead] = report; | ||
409 | usbhid->outhead = head; | ||
410 | |||
411 | if (!test_and_set_bit(HID_OUT_RUNNING, &usbhid->iofl)) | ||
412 | if (hid_submit_out(hid)) | ||
413 | clear_bit(HID_OUT_RUNNING, &usbhid->iofl); | ||
414 | |||
415 | spin_unlock_irqrestore(&usbhid->outlock, flags); | ||
416 | return; | ||
417 | } | ||
418 | |||
419 | spin_lock_irqsave(&usbhid->ctrllock, flags); | ||
420 | |||
421 | if ((head = (usbhid->ctrlhead + 1) & (HID_CONTROL_FIFO_SIZE - 1)) == usbhid->ctrltail) { | ||
422 | spin_unlock_irqrestore(&usbhid->ctrllock, flags); | ||
423 | warn("control queue full"); | ||
424 | return; | ||
425 | } | ||
426 | |||
427 | usbhid->ctrl[usbhid->ctrlhead].report = report; | ||
428 | usbhid->ctrl[usbhid->ctrlhead].dir = dir; | ||
429 | usbhid->ctrlhead = head; | ||
430 | |||
431 | if (!test_and_set_bit(HID_CTRL_RUNNING, &usbhid->iofl)) | ||
432 | if (hid_submit_ctrl(hid)) | ||
433 | clear_bit(HID_CTRL_RUNNING, &usbhid->iofl); | ||
434 | |||
435 | spin_unlock_irqrestore(&usbhid->ctrllock, flags); | ||
436 | } | ||
437 | |||
438 | static int usb_hidinput_input_event(struct input_dev *dev, unsigned int type, unsigned int code, int value) | ||
439 | { | ||
440 | struct hid_device *hid = dev->private; | ||
441 | struct hid_field *field; | ||
442 | int offset; | ||
443 | |||
444 | if (type == EV_FF) | ||
445 | return input_ff_event(dev, type, code, value); | ||
446 | |||
447 | if (type != EV_LED) | ||
448 | return -1; | ||
449 | |||
450 | if ((offset = hidinput_find_field(hid, type, code, &field)) == -1) { | ||
451 | warn("event field not found"); | ||
452 | return -1; | ||
453 | } | ||
454 | |||
455 | hid_set_field(field, offset, value); | ||
456 | usbhid_submit_report(hid, field->report, USB_DIR_OUT); | ||
457 | |||
458 | return 0; | ||
459 | } | ||
460 | |||
461 | int usbhid_wait_io(struct hid_device *hid) | ||
462 | { | ||
463 | struct usbhid_device *usbhid = hid->driver_data; | ||
464 | |||
465 | if (!wait_event_timeout(hid->wait, (!test_bit(HID_CTRL_RUNNING, &usbhid->iofl) && | ||
466 | !test_bit(HID_OUT_RUNNING, &usbhid->iofl)), | ||
467 | 10*HZ)) { | ||
468 | dbg("timeout waiting for ctrl or out queue to clear"); | ||
469 | return -1; | ||
470 | } | ||
471 | |||
472 | return 0; | ||
473 | } | ||
474 | |||
475 | static int hid_set_idle(struct usb_device *dev, int ifnum, int report, int idle) | ||
476 | { | ||
477 | return usb_control_msg(dev, usb_sndctrlpipe(dev, 0), | ||
478 | HID_REQ_SET_IDLE, USB_TYPE_CLASS | USB_RECIP_INTERFACE, (idle << 8) | report, | ||
479 | ifnum, NULL, 0, USB_CTRL_SET_TIMEOUT); | ||
480 | } | ||
481 | |||
482 | static int hid_get_class_descriptor(struct usb_device *dev, int ifnum, | ||
483 | unsigned char type, void *buf, int size) | ||
484 | { | ||
485 | int result, retries = 4; | ||
486 | |||
487 | memset(buf, 0, size); | ||
488 | |||
489 | do { | ||
490 | result = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0), | ||
491 | USB_REQ_GET_DESCRIPTOR, USB_RECIP_INTERFACE | USB_DIR_IN, | ||
492 | (type << 8), ifnum, buf, size, USB_CTRL_GET_TIMEOUT); | ||
493 | retries--; | ||
494 | } while (result < size && retries); | ||
495 | return result; | ||
496 | } | ||
497 | |||
498 | int usbhid_open(struct hid_device *hid) | ||
499 | { | ||
500 | ++hid->open; | ||
501 | if (hid_start_in(hid)) | ||
502 | hid_io_error(hid); | ||
503 | return 0; | ||
504 | } | ||
505 | |||
506 | void usbhid_close(struct hid_device *hid) | ||
507 | { | ||
508 | struct usbhid_device *usbhid = hid->driver_data; | ||
509 | |||
510 | if (!--hid->open) | ||
511 | usb_kill_urb(usbhid->urbin); | ||
512 | } | ||
513 | |||
514 | #define USB_VENDOR_ID_PANJIT 0x134c | ||
515 | |||
516 | #define USB_VENDOR_ID_TURBOX 0x062a | ||
517 | #define USB_DEVICE_ID_TURBOX_KEYBOARD 0x0201 | ||
518 | |||
519 | /* | ||
520 | * Initialize all reports | ||
521 | */ | ||
522 | |||
523 | void usbhid_init_reports(struct hid_device *hid) | ||
524 | { | ||
525 | struct hid_report *report; | ||
526 | struct usbhid_device *usbhid = hid->driver_data; | ||
527 | int err, ret; | ||
528 | |||
529 | list_for_each_entry(report, &hid->report_enum[HID_INPUT_REPORT].report_list, list) | ||
530 | usbhid_submit_report(hid, report, USB_DIR_IN); | ||
531 | |||
532 | list_for_each_entry(report, &hid->report_enum[HID_FEATURE_REPORT].report_list, list) | ||
533 | usbhid_submit_report(hid, report, USB_DIR_IN); | ||
534 | |||
535 | err = 0; | ||
536 | ret = usbhid_wait_io(hid); | ||
537 | while (ret) { | ||
538 | err |= ret; | ||
539 | if (test_bit(HID_CTRL_RUNNING, &usbhid->iofl)) | ||
540 | usb_kill_urb(usbhid->urbctrl); | ||
541 | if (test_bit(HID_OUT_RUNNING, &usbhid->iofl)) | ||
542 | usb_kill_urb(usbhid->urbout); | ||
543 | ret = usbhid_wait_io(hid); | ||
544 | } | ||
545 | |||
546 | if (err) | ||
547 | warn("timeout initializing reports"); | ||
548 | } | ||
549 | |||
550 | #define USB_VENDOR_ID_GTCO 0x078c | ||
551 | #define USB_VENDOR_ID_GTCO_IPANEL_2 0x5543 | ||
552 | #define USB_DEVICE_ID_GTCO_90 0x0090 | ||
553 | #define USB_DEVICE_ID_GTCO_100 0x0100 | ||
554 | #define USB_DEVICE_ID_GTCO_101 0x0101 | ||
555 | #define USB_DEVICE_ID_GTCO_103 0x0103 | ||
556 | #define USB_DEVICE_ID_GTCO_104 0x0104 | ||
557 | #define USB_DEVICE_ID_GTCO_105 0x0105 | ||
558 | #define USB_DEVICE_ID_GTCO_106 0x0106 | ||
559 | #define USB_DEVICE_ID_GTCO_107 0x0107 | ||
560 | #define USB_DEVICE_ID_GTCO_108 0x0108 | ||
561 | #define USB_DEVICE_ID_GTCO_200 0x0200 | ||
562 | #define USB_DEVICE_ID_GTCO_201 0x0201 | ||
563 | #define USB_DEVICE_ID_GTCO_202 0x0202 | ||
564 | #define USB_DEVICE_ID_GTCO_203 0x0203 | ||
565 | #define USB_DEVICE_ID_GTCO_204 0x0204 | ||
566 | #define USB_DEVICE_ID_GTCO_205 0x0205 | ||
567 | #define USB_DEVICE_ID_GTCO_206 0x0206 | ||
568 | #define USB_DEVICE_ID_GTCO_207 0x0207 | ||
569 | #define USB_DEVICE_ID_GTCO_300 0x0300 | ||
570 | #define USB_DEVICE_ID_GTCO_301 0x0301 | ||
571 | #define USB_DEVICE_ID_GTCO_302 0x0302 | ||
572 | #define USB_DEVICE_ID_GTCO_303 0x0303 | ||
573 | #define USB_DEVICE_ID_GTCO_304 0x0304 | ||
574 | #define USB_DEVICE_ID_GTCO_305 0x0305 | ||
575 | #define USB_DEVICE_ID_GTCO_306 0x0306 | ||
576 | #define USB_DEVICE_ID_GTCO_307 0x0307 | ||
577 | #define USB_DEVICE_ID_GTCO_308 0x0308 | ||
578 | #define USB_DEVICE_ID_GTCO_309 0x0309 | ||
579 | #define USB_DEVICE_ID_GTCO_400 0x0400 | ||
580 | #define USB_DEVICE_ID_GTCO_401 0x0401 | ||
581 | #define USB_DEVICE_ID_GTCO_402 0x0402 | ||
582 | #define USB_DEVICE_ID_GTCO_403 0x0403 | ||
583 | #define USB_DEVICE_ID_GTCO_404 0x0404 | ||
584 | #define USB_DEVICE_ID_GTCO_405 0x0405 | ||
585 | #define USB_DEVICE_ID_GTCO_500 0x0500 | ||
586 | #define USB_DEVICE_ID_GTCO_501 0x0501 | ||
587 | #define USB_DEVICE_ID_GTCO_502 0x0502 | ||
588 | #define USB_DEVICE_ID_GTCO_503 0x0503 | ||
589 | #define USB_DEVICE_ID_GTCO_504 0x0504 | ||
590 | #define USB_DEVICE_ID_GTCO_1000 0x1000 | ||
591 | #define USB_DEVICE_ID_GTCO_1001 0x1001 | ||
592 | #define USB_DEVICE_ID_GTCO_1002 0x1002 | ||
593 | #define USB_DEVICE_ID_GTCO_1003 0x1003 | ||
594 | #define USB_DEVICE_ID_GTCO_1004 0x1004 | ||
595 | #define USB_DEVICE_ID_GTCO_1005 0x1005 | ||
596 | #define USB_DEVICE_ID_GTCO_1006 0x1006 | ||
597 | #define USB_DEVICE_ID_GTCO_8 0x0008 | ||
598 | #define USB_DEVICE_ID_GTCO_d 0x000d | ||
599 | |||
600 | #define USB_VENDOR_ID_WACOM 0x056a | ||
601 | |||
602 | #define USB_VENDOR_ID_ACECAD 0x0460 | ||
603 | #define USB_DEVICE_ID_ACECAD_FLAIR 0x0004 | ||
604 | #define USB_DEVICE_ID_ACECAD_302 0x0008 | ||
605 | |||
606 | #define USB_VENDOR_ID_KBGEAR 0x084e | ||
607 | #define USB_DEVICE_ID_KBGEAR_JAMSTUDIO 0x1001 | ||
608 | |||
609 | #define USB_VENDOR_ID_AIPTEK 0x08ca | ||
610 | #define USB_DEVICE_ID_AIPTEK_01 0x0001 | ||
611 | #define USB_DEVICE_ID_AIPTEK_10 0x0010 | ||
612 | #define USB_DEVICE_ID_AIPTEK_20 0x0020 | ||
613 | #define USB_DEVICE_ID_AIPTEK_21 0x0021 | ||
614 | #define USB_DEVICE_ID_AIPTEK_22 0x0022 | ||
615 | #define USB_DEVICE_ID_AIPTEK_23 0x0023 | ||
616 | #define USB_DEVICE_ID_AIPTEK_24 0x0024 | ||
617 | |||
618 | #define USB_VENDOR_ID_GRIFFIN 0x077d | ||
619 | #define USB_DEVICE_ID_POWERMATE 0x0410 | ||
620 | #define USB_DEVICE_ID_SOUNDKNOB 0x04AA | ||
621 | |||
622 | #define USB_VENDOR_ID_ATEN 0x0557 | ||
623 | #define USB_DEVICE_ID_ATEN_UC100KM 0x2004 | ||
624 | #define USB_DEVICE_ID_ATEN_CS124U 0x2202 | ||
625 | #define USB_DEVICE_ID_ATEN_2PORTKVM 0x2204 | ||
626 | #define USB_DEVICE_ID_ATEN_4PORTKVM 0x2205 | ||
627 | #define USB_DEVICE_ID_ATEN_4PORTKVMC 0x2208 | ||
628 | |||
629 | #define USB_VENDOR_ID_TOPMAX 0x0663 | ||
630 | #define USB_DEVICE_ID_TOPMAX_COBRAPAD 0x0103 | ||
631 | |||
632 | #define USB_VENDOR_ID_HAPP 0x078b | ||
633 | #define USB_DEVICE_ID_UGCI_DRIVING 0x0010 | ||
634 | #define USB_DEVICE_ID_UGCI_FLYING 0x0020 | ||
635 | #define USB_DEVICE_ID_UGCI_FIGHTING 0x0030 | ||
636 | |||
637 | #define USB_VENDOR_ID_MGE 0x0463 | ||
638 | #define USB_DEVICE_ID_MGE_UPS 0xffff | ||
639 | #define USB_DEVICE_ID_MGE_UPS1 0x0001 | ||
640 | |||
641 | #define USB_VENDOR_ID_ONTRAK 0x0a07 | ||
642 | #define USB_DEVICE_ID_ONTRAK_ADU100 0x0064 | ||
643 | |||
644 | #define USB_VENDOR_ID_ESSENTIAL_REALITY 0x0d7f | ||
645 | #define USB_DEVICE_ID_ESSENTIAL_REALITY_P5 0x0100 | ||
646 | |||
647 | #define USB_VENDOR_ID_A4TECH 0x09da | ||
648 | #define USB_DEVICE_ID_A4TECH_WCP32PU 0x0006 | ||
649 | |||
650 | #define USB_VENDOR_ID_AASHIMA 0x06d6 | ||
651 | #define USB_DEVICE_ID_AASHIMA_GAMEPAD 0x0025 | ||
652 | #define USB_DEVICE_ID_AASHIMA_PREDATOR 0x0026 | ||
653 | |||
654 | #define USB_VENDOR_ID_CYPRESS 0x04b4 | ||
655 | #define USB_DEVICE_ID_CYPRESS_MOUSE 0x0001 | ||
656 | #define USB_DEVICE_ID_CYPRESS_HIDCOM 0x5500 | ||
657 | #define USB_DEVICE_ID_CYPRESS_ULTRAMOUSE 0x7417 | ||
658 | |||
659 | #define USB_VENDOR_ID_BERKSHIRE 0x0c98 | ||
660 | #define USB_DEVICE_ID_BERKSHIRE_PCWD 0x1140 | ||
661 | |||
662 | #define USB_VENDOR_ID_ALPS 0x0433 | ||
663 | #define USB_DEVICE_ID_IBM_GAMEPAD 0x1101 | ||
664 | |||
665 | #define USB_VENDOR_ID_SAITEK 0x06a3 | ||
666 | #define USB_DEVICE_ID_SAITEK_RUMBLEPAD 0xff17 | ||
667 | |||
668 | #define USB_VENDOR_ID_NEC 0x073e | ||
669 | #define USB_DEVICE_ID_NEC_USB_GAME_PAD 0x0301 | ||
670 | |||
671 | #define USB_VENDOR_ID_CHIC 0x05fe | ||
672 | #define USB_DEVICE_ID_CHIC_GAMEPAD 0x0014 | ||
673 | |||
674 | #define USB_VENDOR_ID_GLAB 0x06c2 | ||
675 | #define USB_DEVICE_ID_4_PHIDGETSERVO_30 0x0038 | ||
676 | #define USB_DEVICE_ID_1_PHIDGETSERVO_30 0x0039 | ||
677 | #define USB_DEVICE_ID_0_0_4_IF_KIT 0x0040 | ||
678 | #define USB_DEVICE_ID_0_16_16_IF_KIT 0x0044 | ||
679 | #define USB_DEVICE_ID_8_8_8_IF_KIT 0x0045 | ||
680 | #define USB_DEVICE_ID_0_8_7_IF_KIT 0x0051 | ||
681 | #define USB_DEVICE_ID_0_8_8_IF_KIT 0x0053 | ||
682 | #define USB_DEVICE_ID_PHIDGET_MOTORCONTROL 0x0058 | ||
683 | |||
684 | #define USB_VENDOR_ID_WISEGROUP 0x0925 | ||
685 | #define USB_DEVICE_ID_1_PHIDGETSERVO_20 0x8101 | ||
686 | #define USB_DEVICE_ID_4_PHIDGETSERVO_20 0x8104 | ||
687 | #define USB_DEVICE_ID_8_8_4_IF_KIT 0x8201 | ||
688 | #define USB_DEVICE_ID_DUAL_USB_JOYPAD 0x8866 | ||
689 | |||
690 | #define USB_VENDOR_ID_WISEGROUP_LTD 0x6677 | ||
691 | #define USB_DEVICE_ID_SMARTJOY_DUAL_PLUS 0x8802 | ||
692 | |||
693 | #define USB_VENDOR_ID_CODEMERCS 0x07c0 | ||
694 | #define USB_DEVICE_ID_CODEMERCS_IOW40 0x1500 | ||
695 | #define USB_DEVICE_ID_CODEMERCS_IOW24 0x1501 | ||
696 | #define USB_DEVICE_ID_CODEMERCS_IOW48 0x1502 | ||
697 | #define USB_DEVICE_ID_CODEMERCS_IOW28 0x1503 | ||
698 | |||
699 | #define USB_VENDOR_ID_DELORME 0x1163 | ||
700 | #define USB_DEVICE_ID_DELORME_EARTHMATE 0x0100 | ||
701 | #define USB_DEVICE_ID_DELORME_EM_LT20 0x0200 | ||
702 | |||
703 | #define USB_VENDOR_ID_MCC 0x09db | ||
704 | #define USB_DEVICE_ID_MCC_PMD1024LS 0x0076 | ||
705 | #define USB_DEVICE_ID_MCC_PMD1208LS 0x007a | ||
706 | |||
707 | #define USB_VENDOR_ID_VERNIER 0x08f7 | ||
708 | #define USB_DEVICE_ID_VERNIER_LABPRO 0x0001 | ||
709 | #define USB_DEVICE_ID_VERNIER_GOTEMP 0x0002 | ||
710 | #define USB_DEVICE_ID_VERNIER_SKIP 0x0003 | ||
711 | #define USB_DEVICE_ID_VERNIER_CYCLOPS 0x0004 | ||
712 | |||
713 | #define USB_VENDOR_ID_LD 0x0f11 | ||
714 | #define USB_DEVICE_ID_LD_CASSY 0x1000 | ||
715 | #define USB_DEVICE_ID_LD_POCKETCASSY 0x1010 | ||
716 | #define USB_DEVICE_ID_LD_MOBILECASSY 0x1020 | ||
717 | #define USB_DEVICE_ID_LD_JWM 0x1080 | ||
718 | #define USB_DEVICE_ID_LD_DMMP 0x1081 | ||
719 | #define USB_DEVICE_ID_LD_UMIP 0x1090 | ||
720 | #define USB_DEVICE_ID_LD_XRAY1 0x1100 | ||
721 | #define USB_DEVICE_ID_LD_XRAY2 0x1101 | ||
722 | #define USB_DEVICE_ID_LD_VIDEOCOM 0x1200 | ||
723 | #define USB_DEVICE_ID_LD_COM3LAB 0x2000 | ||
724 | #define USB_DEVICE_ID_LD_TELEPORT 0x2010 | ||
725 | #define USB_DEVICE_ID_LD_NETWORKANALYSER 0x2020 | ||
726 | #define USB_DEVICE_ID_LD_POWERCONTROL 0x2030 | ||
727 | #define USB_DEVICE_ID_LD_MACHINETEST 0x2040 | ||
728 | |||
729 | #define USB_VENDOR_ID_APPLE 0x05ac | ||
730 | #define USB_DEVICE_ID_APPLE_MIGHTYMOUSE 0x0304 | ||
731 | #define USB_DEVICE_ID_APPLE_FOUNTAIN_ANSI 0x020e | ||
732 | #define USB_DEVICE_ID_APPLE_FOUNTAIN_ISO 0x020f | ||
733 | #define USB_DEVICE_ID_APPLE_GEYSER_ANSI 0x0214 | ||
734 | #define USB_DEVICE_ID_APPLE_GEYSER_ISO 0x0215 | ||
735 | #define USB_DEVICE_ID_APPLE_GEYSER_JIS 0x0216 | ||
736 | #define USB_DEVICE_ID_APPLE_GEYSER3_ANSI 0x0217 | ||
737 | #define USB_DEVICE_ID_APPLE_GEYSER3_ISO 0x0218 | ||
738 | #define USB_DEVICE_ID_APPLE_GEYSER3_JIS 0x0219 | ||
739 | #define USB_DEVICE_ID_APPLE_GEYSER4_ANSI 0x021a | ||
740 | #define USB_DEVICE_ID_APPLE_GEYSER4_ISO 0x021b | ||
741 | #define USB_DEVICE_ID_APPLE_GEYSER4_JIS 0x021c | ||
742 | #define USB_DEVICE_ID_APPLE_FOUNTAIN_TP_ONLY 0x030a | ||
743 | #define USB_DEVICE_ID_APPLE_GEYSER1_TP_ONLY 0x030b | ||
744 | #define USB_DEVICE_ID_APPLE_IR 0x8240 | ||
745 | |||
746 | #define USB_VENDOR_ID_CHERRY 0x046a | ||
747 | #define USB_DEVICE_ID_CHERRY_CYMOTION 0x0023 | ||
748 | |||
749 | #define USB_VENDOR_ID_YEALINK 0x6993 | ||
750 | #define USB_DEVICE_ID_YEALINK_P1K_P4K_B2K 0xb001 | ||
751 | |||
752 | #define USB_VENDOR_ID_ALCOR 0x058f | ||
753 | #define USB_DEVICE_ID_ALCOR_USBRS232 0x9720 | ||
754 | |||
755 | #define USB_VENDOR_ID_SUN 0x0430 | ||
756 | #define USB_DEVICE_ID_RARITAN_KVM_DONGLE 0xcdab | ||
757 | |||
758 | #define USB_VENDOR_ID_AIRCABLE 0x16CA | ||
759 | #define USB_DEVICE_ID_AIRCABLE1 0x1502 | ||
760 | |||
761 | #define USB_VENDOR_ID_LOGITECH 0x046d | ||
762 | #define USB_DEVICE_ID_LOGITECH_USB_RECEIVER 0xc101 | ||
763 | |||
764 | #define USB_VENDOR_ID_IMATION 0x0718 | ||
765 | #define USB_DEVICE_ID_DISC_STAKKA 0xd000 | ||
766 | |||
767 | #define USB_VENDOR_ID_PANTHERLORD 0x0810 | ||
768 | #define USB_DEVICE_ID_PANTHERLORD_TWIN_USB_JOYSTICK 0x0001 | ||
769 | |||
770 | #define USB_VENDOR_ID_SONY 0x054c | ||
771 | #define USB_DEVICE_ID_SONY_PS3_CONTROLLER 0x0268 | ||
772 | |||
773 | /* | ||
774 | * Alphabetically sorted blacklist by quirk type. | ||
775 | */ | ||
776 | |||
777 | static const struct hid_blacklist { | ||
778 | __u16 idVendor; | ||
779 | __u16 idProduct; | ||
780 | unsigned quirks; | ||
781 | } hid_blacklist[] = { | ||
782 | |||
783 | { USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_01, HID_QUIRK_IGNORE }, | ||
784 | { USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_10, HID_QUIRK_IGNORE }, | ||
785 | { USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_20, HID_QUIRK_IGNORE }, | ||
786 | { USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_21, HID_QUIRK_IGNORE }, | ||
787 | { USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_22, HID_QUIRK_IGNORE }, | ||
788 | { USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_23, HID_QUIRK_IGNORE }, | ||
789 | { USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_24, HID_QUIRK_IGNORE }, | ||
790 | { USB_VENDOR_ID_AIRCABLE, USB_DEVICE_ID_AIRCABLE1, HID_QUIRK_IGNORE }, | ||
791 | { USB_VENDOR_ID_ALCOR, USB_DEVICE_ID_ALCOR_USBRS232, HID_QUIRK_IGNORE }, | ||
792 | { USB_VENDOR_ID_BERKSHIRE, USB_DEVICE_ID_BERKSHIRE_PCWD, HID_QUIRK_IGNORE }, | ||
793 | { USB_VENDOR_ID_CODEMERCS, USB_DEVICE_ID_CODEMERCS_IOW40, HID_QUIRK_IGNORE }, | ||
794 | { USB_VENDOR_ID_CODEMERCS, USB_DEVICE_ID_CODEMERCS_IOW24, HID_QUIRK_IGNORE }, | ||
795 | { USB_VENDOR_ID_CODEMERCS, USB_DEVICE_ID_CODEMERCS_IOW48, HID_QUIRK_IGNORE }, | ||
796 | { USB_VENDOR_ID_CODEMERCS, USB_DEVICE_ID_CODEMERCS_IOW28, HID_QUIRK_IGNORE }, | ||
797 | { USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_HIDCOM, HID_QUIRK_IGNORE }, | ||
798 | { USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_ULTRAMOUSE, HID_QUIRK_IGNORE }, | ||
799 | { USB_VENDOR_ID_DELORME, USB_DEVICE_ID_DELORME_EARTHMATE, HID_QUIRK_IGNORE }, | ||
800 | { USB_VENDOR_ID_DELORME, USB_DEVICE_ID_DELORME_EM_LT20, HID_QUIRK_IGNORE }, | ||
801 | { USB_VENDOR_ID_ESSENTIAL_REALITY, USB_DEVICE_ID_ESSENTIAL_REALITY_P5, HID_QUIRK_IGNORE }, | ||
802 | { USB_VENDOR_ID_GLAB, USB_DEVICE_ID_4_PHIDGETSERVO_30, HID_QUIRK_IGNORE }, | ||
803 | { USB_VENDOR_ID_GLAB, USB_DEVICE_ID_1_PHIDGETSERVO_30, HID_QUIRK_IGNORE }, | ||
804 | { USB_VENDOR_ID_GLAB, USB_DEVICE_ID_0_0_4_IF_KIT, HID_QUIRK_IGNORE }, | ||
805 | { USB_VENDOR_ID_GLAB, USB_DEVICE_ID_0_16_16_IF_KIT, HID_QUIRK_IGNORE }, | ||
806 | { USB_VENDOR_ID_GLAB, USB_DEVICE_ID_8_8_8_IF_KIT, HID_QUIRK_IGNORE }, | ||
807 | { USB_VENDOR_ID_GLAB, USB_DEVICE_ID_0_8_7_IF_KIT, HID_QUIRK_IGNORE }, | ||
808 | { USB_VENDOR_ID_GLAB, USB_DEVICE_ID_0_8_8_IF_KIT, HID_QUIRK_IGNORE }, | ||
809 | { USB_VENDOR_ID_GLAB, USB_DEVICE_ID_PHIDGET_MOTORCONTROL, HID_QUIRK_IGNORE }, | ||
810 | { USB_VENDOR_ID_GRIFFIN, USB_DEVICE_ID_POWERMATE, HID_QUIRK_IGNORE }, | ||
811 | { USB_VENDOR_ID_GRIFFIN, USB_DEVICE_ID_SOUNDKNOB, HID_QUIRK_IGNORE }, | ||
812 | { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_90, HID_QUIRK_IGNORE }, | ||
813 | { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_100, HID_QUIRK_IGNORE }, | ||
814 | { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_101, HID_QUIRK_IGNORE }, | ||
815 | { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_103, HID_QUIRK_IGNORE }, | ||
816 | { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_104, HID_QUIRK_IGNORE }, | ||
817 | { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_105, HID_QUIRK_IGNORE }, | ||
818 | { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_106, HID_QUIRK_IGNORE }, | ||
819 | { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_107, HID_QUIRK_IGNORE }, | ||
820 | { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_108, HID_QUIRK_IGNORE }, | ||
821 | { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_200, HID_QUIRK_IGNORE }, | ||
822 | { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_201, HID_QUIRK_IGNORE }, | ||
823 | { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_202, HID_QUIRK_IGNORE }, | ||
824 | { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_203, HID_QUIRK_IGNORE }, | ||
825 | { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_204, HID_QUIRK_IGNORE }, | ||
826 | { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_205, HID_QUIRK_IGNORE }, | ||
827 | { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_206, HID_QUIRK_IGNORE }, | ||
828 | { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_207, HID_QUIRK_IGNORE }, | ||
829 | { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_300, HID_QUIRK_IGNORE }, | ||
830 | { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_301, HID_QUIRK_IGNORE }, | ||
831 | { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_302, HID_QUIRK_IGNORE }, | ||
832 | { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_303, HID_QUIRK_IGNORE }, | ||
833 | { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_304, HID_QUIRK_IGNORE }, | ||
834 | { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_305, HID_QUIRK_IGNORE }, | ||
835 | { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_306, HID_QUIRK_IGNORE }, | ||
836 | { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_307, HID_QUIRK_IGNORE }, | ||
837 | { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_308, HID_QUIRK_IGNORE }, | ||
838 | { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_309, HID_QUIRK_IGNORE }, | ||
839 | { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_400, HID_QUIRK_IGNORE }, | ||
840 | { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_401, HID_QUIRK_IGNORE }, | ||
841 | { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_402, HID_QUIRK_IGNORE }, | ||
842 | { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_403, HID_QUIRK_IGNORE }, | ||
843 | { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_404, HID_QUIRK_IGNORE }, | ||
844 | { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_405, HID_QUIRK_IGNORE }, | ||
845 | { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_500, HID_QUIRK_IGNORE }, | ||
846 | { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_501, HID_QUIRK_IGNORE }, | ||
847 | { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_502, HID_QUIRK_IGNORE }, | ||
848 | { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_503, HID_QUIRK_IGNORE }, | ||
849 | { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_504, HID_QUIRK_IGNORE }, | ||
850 | { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1000, HID_QUIRK_IGNORE }, | ||
851 | { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1001, HID_QUIRK_IGNORE }, | ||
852 | { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1002, HID_QUIRK_IGNORE }, | ||
853 | { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1003, HID_QUIRK_IGNORE }, | ||
854 | { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1004, HID_QUIRK_IGNORE }, | ||
855 | { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1005, HID_QUIRK_IGNORE }, | ||
856 | { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1006, HID_QUIRK_IGNORE }, | ||
857 | { USB_VENDOR_ID_GTCO_IPANEL_2, USB_DEVICE_ID_GTCO_8, HID_QUIRK_IGNORE }, | ||
858 | { USB_VENDOR_ID_GTCO_IPANEL_2, USB_DEVICE_ID_GTCO_d, HID_QUIRK_IGNORE }, | ||
859 | { USB_VENDOR_ID_IMATION, USB_DEVICE_ID_DISC_STAKKA, HID_QUIRK_IGNORE }, | ||
860 | { USB_VENDOR_ID_KBGEAR, USB_DEVICE_ID_KBGEAR_JAMSTUDIO, HID_QUIRK_IGNORE }, | ||
861 | { USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_CASSY, HID_QUIRK_IGNORE }, | ||
862 | { USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_POCKETCASSY, HID_QUIRK_IGNORE }, | ||
863 | { USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MOBILECASSY, HID_QUIRK_IGNORE }, | ||
864 | { USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_JWM, HID_QUIRK_IGNORE }, | ||
865 | { USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_DMMP, HID_QUIRK_IGNORE }, | ||
866 | { USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_UMIP, HID_QUIRK_IGNORE }, | ||
867 | { USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_XRAY1, HID_QUIRK_IGNORE }, | ||
868 | { USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_XRAY2, HID_QUIRK_IGNORE }, | ||
869 | { USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_VIDEOCOM, HID_QUIRK_IGNORE }, | ||
870 | { USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_COM3LAB, HID_QUIRK_IGNORE }, | ||
871 | { USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_TELEPORT, HID_QUIRK_IGNORE }, | ||
872 | { USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_NETWORKANALYSER, HID_QUIRK_IGNORE }, | ||
873 | { USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_POWERCONTROL, HID_QUIRK_IGNORE }, | ||
874 | { USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MACHINETEST, HID_QUIRK_IGNORE }, | ||
875 | { USB_VENDOR_ID_MCC, USB_DEVICE_ID_MCC_PMD1024LS, HID_QUIRK_IGNORE }, | ||
876 | { USB_VENDOR_ID_MCC, USB_DEVICE_ID_MCC_PMD1208LS, HID_QUIRK_IGNORE }, | ||
877 | { USB_VENDOR_ID_MGE, USB_DEVICE_ID_MGE_UPS, HID_QUIRK_IGNORE }, | ||
878 | { USB_VENDOR_ID_MGE, USB_DEVICE_ID_MGE_UPS1, HID_QUIRK_IGNORE }, | ||
879 | { USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100, HID_QUIRK_IGNORE }, | ||
880 | { USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 20, HID_QUIRK_IGNORE }, | ||
881 | { USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 30, HID_QUIRK_IGNORE }, | ||
882 | { USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 100, HID_QUIRK_IGNORE }, | ||
883 | { USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 108, HID_QUIRK_IGNORE }, | ||
884 | { USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 118, HID_QUIRK_IGNORE }, | ||
885 | { USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 200, HID_QUIRK_IGNORE }, | ||
886 | { USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 300, HID_QUIRK_IGNORE }, | ||
887 | { USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 400, HID_QUIRK_IGNORE }, | ||
888 | { USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 500, HID_QUIRK_IGNORE }, | ||
889 | { USB_VENDOR_ID_VERNIER, USB_DEVICE_ID_VERNIER_LABPRO, HID_QUIRK_IGNORE }, | ||
890 | { USB_VENDOR_ID_VERNIER, USB_DEVICE_ID_VERNIER_GOTEMP, HID_QUIRK_IGNORE }, | ||
891 | { USB_VENDOR_ID_VERNIER, USB_DEVICE_ID_VERNIER_SKIP, HID_QUIRK_IGNORE }, | ||
892 | { USB_VENDOR_ID_VERNIER, USB_DEVICE_ID_VERNIER_CYCLOPS, HID_QUIRK_IGNORE }, | ||
893 | { USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_4_PHIDGETSERVO_20, HID_QUIRK_IGNORE }, | ||
894 | { USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_1_PHIDGETSERVO_20, HID_QUIRK_IGNORE }, | ||
895 | { USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_8_8_4_IF_KIT, HID_QUIRK_IGNORE }, | ||
896 | { USB_VENDOR_ID_YEALINK, USB_DEVICE_ID_YEALINK_P1K_P4K_B2K, HID_QUIRK_IGNORE }, | ||
897 | |||
898 | { USB_VENDOR_ID_ACECAD, USB_DEVICE_ID_ACECAD_FLAIR, HID_QUIRK_IGNORE }, | ||
899 | { USB_VENDOR_ID_ACECAD, USB_DEVICE_ID_ACECAD_302, HID_QUIRK_IGNORE }, | ||
900 | |||
901 | { USB_VENDOR_ID_ATEN, USB_DEVICE_ID_ATEN_UC100KM, HID_QUIRK_NOGET }, | ||
902 | { USB_VENDOR_ID_ATEN, USB_DEVICE_ID_ATEN_CS124U, HID_QUIRK_NOGET }, | ||
903 | { USB_VENDOR_ID_ATEN, USB_DEVICE_ID_ATEN_2PORTKVM, HID_QUIRK_NOGET }, | ||
904 | { USB_VENDOR_ID_ATEN, USB_DEVICE_ID_ATEN_4PORTKVM, HID_QUIRK_NOGET }, | ||
905 | { USB_VENDOR_ID_ATEN, USB_DEVICE_ID_ATEN_4PORTKVMC, HID_QUIRK_NOGET }, | ||
906 | { USB_VENDOR_ID_SUN, USB_DEVICE_ID_RARITAN_KVM_DONGLE, HID_QUIRK_NOGET }, | ||
907 | { USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_DUAL_USB_JOYPAD, HID_QUIRK_NOGET | HID_QUIRK_MULTI_INPUT }, | ||
908 | { USB_VENDOR_ID_WISEGROUP_LTD, USB_DEVICE_ID_SMARTJOY_DUAL_PLUS, HID_QUIRK_NOGET | HID_QUIRK_MULTI_INPUT }, | ||
909 | |||
910 | { USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_MIGHTYMOUSE, HID_QUIRK_MIGHTYMOUSE | HID_QUIRK_INVERT_HWHEEL }, | ||
911 | { USB_VENDOR_ID_A4TECH, USB_DEVICE_ID_A4TECH_WCP32PU, HID_QUIRK_2WHEEL_MOUSE_HACK_7 }, | ||
912 | { USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_MOUSE, HID_QUIRK_2WHEEL_MOUSE_HACK_5 }, | ||
913 | |||
914 | { USB_VENDOR_ID_AASHIMA, USB_DEVICE_ID_AASHIMA_GAMEPAD, HID_QUIRK_BADPAD }, | ||
915 | { USB_VENDOR_ID_AASHIMA, USB_DEVICE_ID_AASHIMA_PREDATOR, HID_QUIRK_BADPAD }, | ||
916 | { USB_VENDOR_ID_ALPS, USB_DEVICE_ID_IBM_GAMEPAD, HID_QUIRK_BADPAD }, | ||
917 | { USB_VENDOR_ID_CHIC, USB_DEVICE_ID_CHIC_GAMEPAD, HID_QUIRK_BADPAD }, | ||
918 | { USB_VENDOR_ID_HAPP, USB_DEVICE_ID_UGCI_DRIVING, HID_QUIRK_BADPAD | HID_QUIRK_MULTI_INPUT }, | ||
919 | { USB_VENDOR_ID_HAPP, USB_DEVICE_ID_UGCI_FLYING, HID_QUIRK_BADPAD | HID_QUIRK_MULTI_INPUT }, | ||
920 | { USB_VENDOR_ID_HAPP, USB_DEVICE_ID_UGCI_FIGHTING, HID_QUIRK_BADPAD | HID_QUIRK_MULTI_INPUT }, | ||
921 | { USB_VENDOR_ID_NEC, USB_DEVICE_ID_NEC_USB_GAME_PAD, HID_QUIRK_BADPAD }, | ||
922 | { USB_VENDOR_ID_SAITEK, USB_DEVICE_ID_SAITEK_RUMBLEPAD, HID_QUIRK_BADPAD }, | ||
923 | { USB_VENDOR_ID_TOPMAX, USB_DEVICE_ID_TOPMAX_COBRAPAD, HID_QUIRK_BADPAD }, | ||
924 | |||
925 | { USB_VENDOR_ID_CHERRY, USB_DEVICE_ID_CHERRY_CYMOTION, HID_QUIRK_CYMOTION }, | ||
926 | |||
927 | { USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_ANSI, HID_QUIRK_POWERBOOK_HAS_FN | HID_QUIRK_IGNORE_MOUSE }, | ||
928 | { USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_ISO, HID_QUIRK_POWERBOOK_HAS_FN | HID_QUIRK_IGNORE_MOUSE }, | ||
929 | { USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER_ANSI, HID_QUIRK_POWERBOOK_HAS_FN | HID_QUIRK_IGNORE_MOUSE }, | ||
930 | { USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER_ISO, HID_QUIRK_POWERBOOK_HAS_FN | HID_QUIRK_IGNORE_MOUSE | HID_QUIRK_POWERBOOK_ISO_KEYBOARD}, | ||
931 | { USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER_JIS, HID_QUIRK_POWERBOOK_HAS_FN | HID_QUIRK_IGNORE_MOUSE }, | ||
932 | { USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER3_ANSI, HID_QUIRK_POWERBOOK_HAS_FN | HID_QUIRK_IGNORE_MOUSE }, | ||
933 | { USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER3_ISO, HID_QUIRK_POWERBOOK_HAS_FN | HID_QUIRK_IGNORE_MOUSE | HID_QUIRK_POWERBOOK_ISO_KEYBOARD}, | ||
934 | { USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER3_JIS, HID_QUIRK_POWERBOOK_HAS_FN | HID_QUIRK_IGNORE_MOUSE }, | ||
935 | { USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_ANSI, HID_QUIRK_POWERBOOK_HAS_FN | HID_QUIRK_IGNORE_MOUSE }, | ||
936 | { USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_ISO, HID_QUIRK_POWERBOOK_HAS_FN | HID_QUIRK_IGNORE_MOUSE | HID_QUIRK_POWERBOOK_ISO_KEYBOARD}, | ||
937 | { USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_JIS, HID_QUIRK_POWERBOOK_HAS_FN | HID_QUIRK_IGNORE_MOUSE }, | ||
938 | { USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_TP_ONLY, HID_QUIRK_POWERBOOK_HAS_FN | HID_QUIRK_IGNORE_MOUSE }, | ||
939 | { USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER1_TP_ONLY, HID_QUIRK_POWERBOOK_HAS_FN | HID_QUIRK_IGNORE_MOUSE }, | ||
940 | |||
941 | { USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_IR, HID_QUIRK_IGNORE }, | ||
942 | |||
943 | { USB_VENDOR_ID_PANJIT, 0x0001, HID_QUIRK_IGNORE }, | ||
944 | { USB_VENDOR_ID_PANJIT, 0x0002, HID_QUIRK_IGNORE }, | ||
945 | { USB_VENDOR_ID_PANJIT, 0x0003, HID_QUIRK_IGNORE }, | ||
946 | { USB_VENDOR_ID_PANJIT, 0x0004, HID_QUIRK_IGNORE }, | ||
947 | |||
948 | { USB_VENDOR_ID_TURBOX, USB_DEVICE_ID_TURBOX_KEYBOARD, HID_QUIRK_NOGET }, | ||
949 | |||
950 | { USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_USB_RECEIVER, HID_QUIRK_BAD_RELATIVE_KEYS }, | ||
951 | |||
952 | { USB_VENDOR_ID_PANTHERLORD, USB_DEVICE_ID_PANTHERLORD_TWIN_USB_JOYSTICK, HID_QUIRK_MULTI_INPUT | HID_QUIRK_SKIP_OUTPUT_REPORTS }, | ||
953 | |||
954 | { USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_PS3_CONTROLLER, HID_QUIRK_SONY_PS3_CONTROLLER }, | ||
955 | |||
956 | { 0, 0 } | ||
957 | }; | ||
958 | |||
959 | /* | ||
960 | * Traverse the supplied list of reports and find the longest | ||
961 | */ | ||
962 | static void hid_find_max_report(struct hid_device *hid, unsigned int type, int *max) | ||
963 | { | ||
964 | struct hid_report *report; | ||
965 | int size; | ||
966 | |||
967 | list_for_each_entry(report, &hid->report_enum[type].report_list, list) { | ||
968 | size = ((report->size - 1) >> 3) + 1; | ||
969 | if (type == HID_INPUT_REPORT && hid->report_enum[type].numbered) | ||
970 | size++; | ||
971 | if (*max < size) | ||
972 | *max = size; | ||
973 | } | ||
974 | } | ||
975 | |||
976 | static int hid_alloc_buffers(struct usb_device *dev, struct hid_device *hid) | ||
977 | { | ||
978 | struct usbhid_device *usbhid = hid->driver_data; | ||
979 | |||
980 | if (!(usbhid->inbuf = usb_buffer_alloc(dev, usbhid->bufsize, GFP_ATOMIC, &usbhid->inbuf_dma))) | ||
981 | return -1; | ||
982 | if (!(usbhid->outbuf = usb_buffer_alloc(dev, usbhid->bufsize, GFP_ATOMIC, &usbhid->outbuf_dma))) | ||
983 | return -1; | ||
984 | if (!(usbhid->cr = usb_buffer_alloc(dev, sizeof(*(usbhid->cr)), GFP_ATOMIC, &usbhid->cr_dma))) | ||
985 | return -1; | ||
986 | if (!(usbhid->ctrlbuf = usb_buffer_alloc(dev, usbhid->bufsize, GFP_ATOMIC, &usbhid->ctrlbuf_dma))) | ||
987 | return -1; | ||
988 | |||
989 | return 0; | ||
990 | } | ||
991 | |||
992 | static void hid_free_buffers(struct usb_device *dev, struct hid_device *hid) | ||
993 | { | ||
994 | struct usbhid_device *usbhid = hid->driver_data; | ||
995 | |||
996 | if (usbhid->inbuf) | ||
997 | usb_buffer_free(dev, usbhid->bufsize, usbhid->inbuf, usbhid->inbuf_dma); | ||
998 | if (usbhid->outbuf) | ||
999 | usb_buffer_free(dev, usbhid->bufsize, usbhid->outbuf, usbhid->outbuf_dma); | ||
1000 | if (usbhid->cr) | ||
1001 | usb_buffer_free(dev, sizeof(*(usbhid->cr)), usbhid->cr, usbhid->cr_dma); | ||
1002 | if (usbhid->ctrlbuf) | ||
1003 | usb_buffer_free(dev, usbhid->bufsize, usbhid->ctrlbuf, usbhid->ctrlbuf_dma); | ||
1004 | } | ||
1005 | |||
1006 | /* | ||
1007 | * Cherry Cymotion keyboard have an invalid HID report descriptor, | ||
1008 | * that needs fixing before we can parse it. | ||
1009 | */ | ||
1010 | |||
1011 | static void hid_fixup_cymotion_descriptor(char *rdesc, int rsize) | ||
1012 | { | ||
1013 | if (rsize >= 17 && rdesc[11] == 0x3c && rdesc[12] == 0x02) { | ||
1014 | info("Fixing up Cherry Cymotion report descriptor"); | ||
1015 | rdesc[11] = rdesc[16] = 0xff; | ||
1016 | rdesc[12] = rdesc[17] = 0x03; | ||
1017 | } | ||
1018 | } | ||
1019 | |||
1020 | /* | ||
1021 | * Sending HID_REQ_GET_REPORT changes the operation mode of the ps3 controller | ||
1022 | * to "operational". Without this, the ps3 controller will not report any | ||
1023 | * events. | ||
1024 | */ | ||
1025 | static void hid_fixup_sony_ps3_controller(struct usb_device *dev, int ifnum) | ||
1026 | { | ||
1027 | int result; | ||
1028 | char *buf = kmalloc(18, GFP_KERNEL); | ||
1029 | |||
1030 | if (!buf) | ||
1031 | return; | ||
1032 | |||
1033 | result = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0), | ||
1034 | HID_REQ_GET_REPORT, | ||
1035 | USB_DIR_IN | USB_TYPE_CLASS | | ||
1036 | USB_RECIP_INTERFACE, | ||
1037 | (3 << 8) | 0xf2, ifnum, buf, 17, | ||
1038 | USB_CTRL_GET_TIMEOUT); | ||
1039 | |||
1040 | if (result < 0) | ||
1041 | err("%s failed: %d\n", __func__, result); | ||
1042 | |||
1043 | kfree(buf); | ||
1044 | } | ||
1045 | |||
1046 | static struct hid_device *usb_hid_configure(struct usb_interface *intf) | ||
1047 | { | ||
1048 | struct usb_host_interface *interface = intf->cur_altsetting; | ||
1049 | struct usb_device *dev = interface_to_usbdev (intf); | ||
1050 | struct hid_descriptor *hdesc; | ||
1051 | struct hid_device *hid; | ||
1052 | unsigned quirks = 0, rsize = 0; | ||
1053 | char *rdesc; | ||
1054 | int n, len, insize = 0; | ||
1055 | struct usbhid_device *usbhid; | ||
1056 | |||
1057 | /* Ignore all Wacom devices */ | ||
1058 | if (le16_to_cpu(dev->descriptor.idVendor) == USB_VENDOR_ID_WACOM) | ||
1059 | return NULL; | ||
1060 | |||
1061 | for (n = 0; hid_blacklist[n].idVendor; n++) | ||
1062 | if ((hid_blacklist[n].idVendor == le16_to_cpu(dev->descriptor.idVendor)) && | ||
1063 | (hid_blacklist[n].idProduct == le16_to_cpu(dev->descriptor.idProduct))) | ||
1064 | quirks = hid_blacklist[n].quirks; | ||
1065 | |||
1066 | /* Many keyboards and mice don't like to be polled for reports, | ||
1067 | * so we will always set the HID_QUIRK_NOGET flag for them. */ | ||
1068 | if (interface->desc.bInterfaceSubClass == USB_INTERFACE_SUBCLASS_BOOT) { | ||
1069 | if (interface->desc.bInterfaceProtocol == USB_INTERFACE_PROTOCOL_KEYBOARD || | ||
1070 | interface->desc.bInterfaceProtocol == USB_INTERFACE_PROTOCOL_MOUSE) | ||
1071 | quirks |= HID_QUIRK_NOGET; | ||
1072 | } | ||
1073 | |||
1074 | if (quirks & HID_QUIRK_IGNORE) | ||
1075 | return NULL; | ||
1076 | |||
1077 | if ((quirks & HID_QUIRK_IGNORE_MOUSE) && | ||
1078 | (interface->desc.bInterfaceProtocol == USB_INTERFACE_PROTOCOL_MOUSE)) | ||
1079 | return NULL; | ||
1080 | |||
1081 | |||
1082 | if (usb_get_extra_descriptor(interface, HID_DT_HID, &hdesc) && | ||
1083 | (!interface->desc.bNumEndpoints || | ||
1084 | usb_get_extra_descriptor(&interface->endpoint[0], HID_DT_HID, &hdesc))) { | ||
1085 | dbg("class descriptor not present\n"); | ||
1086 | return NULL; | ||
1087 | } | ||
1088 | |||
1089 | for (n = 0; n < hdesc->bNumDescriptors; n++) | ||
1090 | if (hdesc->desc[n].bDescriptorType == HID_DT_REPORT) | ||
1091 | rsize = le16_to_cpu(hdesc->desc[n].wDescriptorLength); | ||
1092 | |||
1093 | if (!rsize || rsize > HID_MAX_DESCRIPTOR_SIZE) { | ||
1094 | dbg("weird size of report descriptor (%u)", rsize); | ||
1095 | return NULL; | ||
1096 | } | ||
1097 | |||
1098 | if (!(rdesc = kmalloc(rsize, GFP_KERNEL))) { | ||
1099 | dbg("couldn't allocate rdesc memory"); | ||
1100 | return NULL; | ||
1101 | } | ||
1102 | |||
1103 | hid_set_idle(dev, interface->desc.bInterfaceNumber, 0, 0); | ||
1104 | |||
1105 | if ((n = hid_get_class_descriptor(dev, interface->desc.bInterfaceNumber, HID_DT_REPORT, rdesc, rsize)) < 0) { | ||
1106 | dbg("reading report descriptor failed"); | ||
1107 | kfree(rdesc); | ||
1108 | return NULL; | ||
1109 | } | ||
1110 | |||
1111 | if ((quirks & HID_QUIRK_CYMOTION)) | ||
1112 | hid_fixup_cymotion_descriptor(rdesc, rsize); | ||
1113 | |||
1114 | #ifdef DEBUG_DATA | ||
1115 | printk(KERN_DEBUG __FILE__ ": report descriptor (size %u, read %d) = ", rsize, n); | ||
1116 | for (n = 0; n < rsize; n++) | ||
1117 | printk(" %02x", (unsigned char) rdesc[n]); | ||
1118 | printk("\n"); | ||
1119 | #endif | ||
1120 | |||
1121 | if (!(hid = hid_parse_report(rdesc, n))) { | ||
1122 | dbg("parsing report descriptor failed"); | ||
1123 | kfree(rdesc); | ||
1124 | return NULL; | ||
1125 | } | ||
1126 | |||
1127 | kfree(rdesc); | ||
1128 | hid->quirks = quirks; | ||
1129 | |||
1130 | if (!(usbhid = kzalloc(sizeof(struct usbhid_device), GFP_KERNEL))) | ||
1131 | goto fail; | ||
1132 | |||
1133 | hid->driver_data = usbhid; | ||
1134 | usbhid->hid = hid; | ||
1135 | |||
1136 | usbhid->bufsize = HID_MIN_BUFFER_SIZE; | ||
1137 | hid_find_max_report(hid, HID_INPUT_REPORT, &usbhid->bufsize); | ||
1138 | hid_find_max_report(hid, HID_OUTPUT_REPORT, &usbhid->bufsize); | ||
1139 | hid_find_max_report(hid, HID_FEATURE_REPORT, &usbhid->bufsize); | ||
1140 | |||
1141 | if (usbhid->bufsize > HID_MAX_BUFFER_SIZE) | ||
1142 | usbhid->bufsize = HID_MAX_BUFFER_SIZE; | ||
1143 | |||
1144 | hid_find_max_report(hid, HID_INPUT_REPORT, &insize); | ||
1145 | |||
1146 | if (insize > HID_MAX_BUFFER_SIZE) | ||
1147 | insize = HID_MAX_BUFFER_SIZE; | ||
1148 | |||
1149 | if (hid_alloc_buffers(dev, hid)) { | ||
1150 | hid_free_buffers(dev, hid); | ||
1151 | goto fail; | ||
1152 | } | ||
1153 | |||
1154 | for (n = 0; n < interface->desc.bNumEndpoints; n++) { | ||
1155 | |||
1156 | struct usb_endpoint_descriptor *endpoint; | ||
1157 | int pipe; | ||
1158 | int interval; | ||
1159 | |||
1160 | endpoint = &interface->endpoint[n].desc; | ||
1161 | if ((endpoint->bmAttributes & 3) != 3) /* Not an interrupt endpoint */ | ||
1162 | continue; | ||
1163 | |||
1164 | interval = endpoint->bInterval; | ||
1165 | |||
1166 | /* Change the polling interval of mice. */ | ||
1167 | if (hid->collection->usage == HID_GD_MOUSE && hid_mousepoll_interval > 0) | ||
1168 | interval = hid_mousepoll_interval; | ||
1169 | |||
1170 | if (usb_endpoint_dir_in(endpoint)) { | ||
1171 | if (usbhid->urbin) | ||
1172 | continue; | ||
1173 | if (!(usbhid->urbin = usb_alloc_urb(0, GFP_KERNEL))) | ||
1174 | goto fail; | ||
1175 | pipe = usb_rcvintpipe(dev, endpoint->bEndpointAddress); | ||
1176 | usb_fill_int_urb(usbhid->urbin, dev, pipe, usbhid->inbuf, insize, | ||
1177 | hid_irq_in, hid, interval); | ||
1178 | usbhid->urbin->transfer_dma = usbhid->inbuf_dma; | ||
1179 | usbhid->urbin->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; | ||
1180 | } else { | ||
1181 | if (usbhid->urbout) | ||
1182 | continue; | ||
1183 | if (!(usbhid->urbout = usb_alloc_urb(0, GFP_KERNEL))) | ||
1184 | goto fail; | ||
1185 | pipe = usb_sndintpipe(dev, endpoint->bEndpointAddress); | ||
1186 | usb_fill_int_urb(usbhid->urbout, dev, pipe, usbhid->outbuf, 0, | ||
1187 | hid_irq_out, hid, interval); | ||
1188 | usbhid->urbout->transfer_dma = usbhid->outbuf_dma; | ||
1189 | usbhid->urbout->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; | ||
1190 | } | ||
1191 | } | ||
1192 | |||
1193 | if (!usbhid->urbin) { | ||
1194 | err("couldn't find an input interrupt endpoint"); | ||
1195 | goto fail; | ||
1196 | } | ||
1197 | |||
1198 | init_waitqueue_head(&hid->wait); | ||
1199 | |||
1200 | INIT_WORK(&usbhid->reset_work, hid_reset); | ||
1201 | setup_timer(&usbhid->io_retry, hid_retry_timeout, (unsigned long) hid); | ||
1202 | |||
1203 | spin_lock_init(&usbhid->inlock); | ||
1204 | spin_lock_init(&usbhid->outlock); | ||
1205 | spin_lock_init(&usbhid->ctrllock); | ||
1206 | |||
1207 | hid->version = le16_to_cpu(hdesc->bcdHID); | ||
1208 | hid->country = hdesc->bCountryCode; | ||
1209 | hid->dev = &intf->dev; | ||
1210 | usbhid->intf = intf; | ||
1211 | usbhid->ifnum = interface->desc.bInterfaceNumber; | ||
1212 | |||
1213 | hid->name[0] = 0; | ||
1214 | |||
1215 | if (dev->manufacturer) | ||
1216 | strlcpy(hid->name, dev->manufacturer, sizeof(hid->name)); | ||
1217 | |||
1218 | if (dev->product) { | ||
1219 | if (dev->manufacturer) | ||
1220 | strlcat(hid->name, " ", sizeof(hid->name)); | ||
1221 | strlcat(hid->name, dev->product, sizeof(hid->name)); | ||
1222 | } | ||
1223 | |||
1224 | if (!strlen(hid->name)) | ||
1225 | snprintf(hid->name, sizeof(hid->name), "HID %04x:%04x", | ||
1226 | le16_to_cpu(dev->descriptor.idVendor), | ||
1227 | le16_to_cpu(dev->descriptor.idProduct)); | ||
1228 | |||
1229 | hid->bus = BUS_USB; | ||
1230 | hid->vendor = dev->descriptor.idVendor; | ||
1231 | hid->product = dev->descriptor.idProduct; | ||
1232 | |||
1233 | usb_make_path(dev, hid->phys, sizeof(hid->phys)); | ||
1234 | strlcat(hid->phys, "/input", sizeof(hid->phys)); | ||
1235 | len = strlen(hid->phys); | ||
1236 | if (len < sizeof(hid->phys) - 1) | ||
1237 | snprintf(hid->phys + len, sizeof(hid->phys) - len, | ||
1238 | "%d", intf->altsetting[0].desc.bInterfaceNumber); | ||
1239 | |||
1240 | if (usb_string(dev, dev->descriptor.iSerialNumber, hid->uniq, 64) <= 0) | ||
1241 | hid->uniq[0] = 0; | ||
1242 | |||
1243 | usbhid->urbctrl = usb_alloc_urb(0, GFP_KERNEL); | ||
1244 | if (!usbhid->urbctrl) | ||
1245 | goto fail; | ||
1246 | |||
1247 | usb_fill_control_urb(usbhid->urbctrl, dev, 0, (void *) usbhid->cr, | ||
1248 | usbhid->ctrlbuf, 1, hid_ctrl, hid); | ||
1249 | usbhid->urbctrl->setup_dma = usbhid->cr_dma; | ||
1250 | usbhid->urbctrl->transfer_dma = usbhid->ctrlbuf_dma; | ||
1251 | usbhid->urbctrl->transfer_flags |= (URB_NO_TRANSFER_DMA_MAP | URB_NO_SETUP_DMA_MAP); | ||
1252 | hid->hidinput_input_event = usb_hidinput_input_event; | ||
1253 | hid->hid_open = usbhid_open; | ||
1254 | hid->hid_close = usbhid_close; | ||
1255 | #ifdef CONFIG_USB_HIDDEV | ||
1256 | hid->hiddev_hid_event = hiddev_hid_event; | ||
1257 | hid->hiddev_report_event = hiddev_report_event; | ||
1258 | #endif | ||
1259 | return hid; | ||
1260 | |||
1261 | fail: | ||
1262 | usb_free_urb(usbhid->urbin); | ||
1263 | usb_free_urb(usbhid->urbout); | ||
1264 | usb_free_urb(usbhid->urbctrl); | ||
1265 | hid_free_buffers(dev, hid); | ||
1266 | hid_free_device(hid); | ||
1267 | |||
1268 | return NULL; | ||
1269 | } | ||
1270 | |||
1271 | static void hid_disconnect(struct usb_interface *intf) | ||
1272 | { | ||
1273 | struct hid_device *hid = usb_get_intfdata (intf); | ||
1274 | struct usbhid_device *usbhid; | ||
1275 | |||
1276 | if (!hid) | ||
1277 | return; | ||
1278 | |||
1279 | usbhid = hid->driver_data; | ||
1280 | |||
1281 | spin_lock_irq(&usbhid->inlock); /* Sync with error handler */ | ||
1282 | usb_set_intfdata(intf, NULL); | ||
1283 | spin_unlock_irq(&usbhid->inlock); | ||
1284 | usb_kill_urb(usbhid->urbin); | ||
1285 | usb_kill_urb(usbhid->urbout); | ||
1286 | usb_kill_urb(usbhid->urbctrl); | ||
1287 | |||
1288 | del_timer_sync(&usbhid->io_retry); | ||
1289 | flush_scheduled_work(); | ||
1290 | |||
1291 | if (hid->claimed & HID_CLAIMED_INPUT) | ||
1292 | hidinput_disconnect(hid); | ||
1293 | if (hid->claimed & HID_CLAIMED_HIDDEV) | ||
1294 | hiddev_disconnect(hid); | ||
1295 | |||
1296 | usb_free_urb(usbhid->urbin); | ||
1297 | usb_free_urb(usbhid->urbctrl); | ||
1298 | usb_free_urb(usbhid->urbout); | ||
1299 | |||
1300 | hid_free_buffers(hid_to_usb_dev(hid), hid); | ||
1301 | hid_free_device(hid); | ||
1302 | } | ||
1303 | |||
1304 | static int hid_probe(struct usb_interface *intf, const struct usb_device_id *id) | ||
1305 | { | ||
1306 | struct hid_device *hid; | ||
1307 | char path[64]; | ||
1308 | int i; | ||
1309 | char *c; | ||
1310 | |||
1311 | dbg("HID probe called for ifnum %d", | ||
1312 | intf->altsetting->desc.bInterfaceNumber); | ||
1313 | |||
1314 | if (!(hid = usb_hid_configure(intf))) | ||
1315 | return -ENODEV; | ||
1316 | |||
1317 | usbhid_init_reports(hid); | ||
1318 | hid_dump_device(hid); | ||
1319 | |||
1320 | if (!hidinput_connect(hid)) | ||
1321 | hid->claimed |= HID_CLAIMED_INPUT; | ||
1322 | if (!hiddev_connect(hid)) | ||
1323 | hid->claimed |= HID_CLAIMED_HIDDEV; | ||
1324 | |||
1325 | usb_set_intfdata(intf, hid); | ||
1326 | |||
1327 | if (!hid->claimed) { | ||
1328 | printk ("HID device not claimed by input or hiddev\n"); | ||
1329 | hid_disconnect(intf); | ||
1330 | return -ENODEV; | ||
1331 | } | ||
1332 | |||
1333 | if ((hid->claimed & HID_CLAIMED_INPUT)) | ||
1334 | hid_ff_init(hid); | ||
1335 | |||
1336 | if (hid->quirks & HID_QUIRK_SONY_PS3_CONTROLLER) | ||
1337 | hid_fixup_sony_ps3_controller(interface_to_usbdev(intf), | ||
1338 | intf->cur_altsetting->desc.bInterfaceNumber); | ||
1339 | |||
1340 | printk(KERN_INFO); | ||
1341 | |||
1342 | if (hid->claimed & HID_CLAIMED_INPUT) | ||
1343 | printk("input"); | ||
1344 | if (hid->claimed == (HID_CLAIMED_INPUT | HID_CLAIMED_HIDDEV)) | ||
1345 | printk(","); | ||
1346 | if (hid->claimed & HID_CLAIMED_HIDDEV) | ||
1347 | printk("hiddev%d", hid->minor); | ||
1348 | |||
1349 | c = "Device"; | ||
1350 | for (i = 0; i < hid->maxcollection; i++) { | ||
1351 | if (hid->collection[i].type == HID_COLLECTION_APPLICATION && | ||
1352 | (hid->collection[i].usage & HID_USAGE_PAGE) == HID_UP_GENDESK && | ||
1353 | (hid->collection[i].usage & 0xffff) < ARRAY_SIZE(hid_types)) { | ||
1354 | c = hid_types[hid->collection[i].usage & 0xffff]; | ||
1355 | break; | ||
1356 | } | ||
1357 | } | ||
1358 | |||
1359 | usb_make_path(interface_to_usbdev(intf), path, 63); | ||
1360 | |||
1361 | printk(": USB HID v%x.%02x %s [%s] on %s\n", | ||
1362 | hid->version >> 8, hid->version & 0xff, c, hid->name, path); | ||
1363 | |||
1364 | return 0; | ||
1365 | } | ||
1366 | |||
1367 | static int hid_suspend(struct usb_interface *intf, pm_message_t message) | ||
1368 | { | ||
1369 | struct hid_device *hid = usb_get_intfdata (intf); | ||
1370 | struct usbhid_device *usbhid = hid->driver_data; | ||
1371 | |||
1372 | spin_lock_irq(&usbhid->inlock); /* Sync with error handler */ | ||
1373 | set_bit(HID_SUSPENDED, &usbhid->iofl); | ||
1374 | spin_unlock_irq(&usbhid->inlock); | ||
1375 | del_timer(&usbhid->io_retry); | ||
1376 | usb_kill_urb(usbhid->urbin); | ||
1377 | dev_dbg(&intf->dev, "suspend\n"); | ||
1378 | return 0; | ||
1379 | } | ||
1380 | |||
1381 | static int hid_resume(struct usb_interface *intf) | ||
1382 | { | ||
1383 | struct hid_device *hid = usb_get_intfdata (intf); | ||
1384 | struct usbhid_device *usbhid = hid->driver_data; | ||
1385 | int status; | ||
1386 | |||
1387 | clear_bit(HID_SUSPENDED, &usbhid->iofl); | ||
1388 | usbhid->retry_delay = 0; | ||
1389 | status = hid_start_in(hid); | ||
1390 | dev_dbg(&intf->dev, "resume status %d\n", status); | ||
1391 | return status; | ||
1392 | } | ||
1393 | |||
1394 | /* Treat USB reset pretty much the same as suspend/resume */ | ||
1395 | static void hid_pre_reset(struct usb_interface *intf) | ||
1396 | { | ||
1397 | /* FIXME: What if the interface is already suspended? */ | ||
1398 | hid_suspend(intf, PMSG_ON); | ||
1399 | } | ||
1400 | |||
1401 | static void hid_post_reset(struct usb_interface *intf) | ||
1402 | { | ||
1403 | struct usb_device *dev = interface_to_usbdev (intf); | ||
1404 | |||
1405 | hid_set_idle(dev, intf->cur_altsetting->desc.bInterfaceNumber, 0, 0); | ||
1406 | /* FIXME: Any more reinitialization needed? */ | ||
1407 | |||
1408 | hid_resume(intf); | ||
1409 | } | ||
1410 | |||
1411 | static struct usb_device_id hid_usb_ids [] = { | ||
1412 | { .match_flags = USB_DEVICE_ID_MATCH_INT_CLASS, | ||
1413 | .bInterfaceClass = USB_INTERFACE_CLASS_HID }, | ||
1414 | { } /* Terminating entry */ | ||
1415 | }; | ||
1416 | |||
1417 | MODULE_DEVICE_TABLE (usb, hid_usb_ids); | ||
1418 | |||
1419 | static struct usb_driver hid_driver = { | ||
1420 | .name = "usbhid", | ||
1421 | .probe = hid_probe, | ||
1422 | .disconnect = hid_disconnect, | ||
1423 | .suspend = hid_suspend, | ||
1424 | .resume = hid_resume, | ||
1425 | .pre_reset = hid_pre_reset, | ||
1426 | .post_reset = hid_post_reset, | ||
1427 | .id_table = hid_usb_ids, | ||
1428 | }; | ||
1429 | |||
1430 | static int __init hid_init(void) | ||
1431 | { | ||
1432 | int retval; | ||
1433 | retval = hiddev_init(); | ||
1434 | if (retval) | ||
1435 | goto hiddev_init_fail; | ||
1436 | retval = usb_register(&hid_driver); | ||
1437 | if (retval) | ||
1438 | goto usb_register_fail; | ||
1439 | info(DRIVER_VERSION ":" DRIVER_DESC); | ||
1440 | |||
1441 | return 0; | ||
1442 | usb_register_fail: | ||
1443 | hiddev_exit(); | ||
1444 | hiddev_init_fail: | ||
1445 | return retval; | ||
1446 | } | ||
1447 | |||
1448 | static void __exit hid_exit(void) | ||
1449 | { | ||
1450 | usb_deregister(&hid_driver); | ||
1451 | hiddev_exit(); | ||
1452 | } | ||
1453 | |||
1454 | module_init(hid_init); | ||
1455 | module_exit(hid_exit); | ||
1456 | |||
1457 | MODULE_AUTHOR(DRIVER_AUTHOR); | ||
1458 | MODULE_DESCRIPTION(DRIVER_DESC); | ||
1459 | MODULE_LICENSE(DRIVER_LICENSE); | ||
diff --git a/drivers/usb/input/hid-ff.c b/drivers/usb/input/hid-ff.c deleted file mode 100644 index e431faaa6abc..000000000000 --- a/drivers/usb/input/hid-ff.c +++ /dev/null | |||
@@ -1,89 +0,0 @@ | |||
1 | /* | ||
2 | * $Id: hid-ff.c,v 1.2 2002/04/18 22:02:47 jdeneux Exp $ | ||
3 | * | ||
4 | * Force feedback support for hid devices. | ||
5 | * Not all hid devices use the same protocol. For example, some use PID, | ||
6 | * other use their own proprietary procotol. | ||
7 | * | ||
8 | * Copyright (c) 2002-2004 Johann Deneux | ||
9 | */ | ||
10 | |||
11 | /* | ||
12 | * This program is free software; you can redistribute it and/or modify | ||
13 | * it under the terms of the GNU General Public License as published by | ||
14 | * the Free Software Foundation; either version 2 of the License, or | ||
15 | * (at your option) any later version. | ||
16 | * | ||
17 | * This program is distributed in the hope that it will be useful, | ||
18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
20 | * GNU General Public License for more details. | ||
21 | * | ||
22 | * You should have received a copy of the GNU General Public License | ||
23 | * along with this program; if not, write to the Free Software | ||
24 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
25 | * | ||
26 | * Should you need to contact me, the author, you can do so by | ||
27 | * e-mail - mail your message to <johann.deneux@it.uu.se> | ||
28 | */ | ||
29 | |||
30 | #include <linux/input.h> | ||
31 | |||
32 | #undef DEBUG | ||
33 | #include <linux/usb.h> | ||
34 | |||
35 | #include <linux/hid.h> | ||
36 | #include "usbhid.h" | ||
37 | |||
38 | /* | ||
39 | * This table contains pointers to initializers. To add support for new | ||
40 | * devices, you need to add the USB vendor and product ids here. | ||
41 | */ | ||
42 | struct hid_ff_initializer { | ||
43 | u16 idVendor; | ||
44 | u16 idProduct; | ||
45 | int (*init)(struct hid_device*); | ||
46 | }; | ||
47 | |||
48 | /* | ||
49 | * We try pidff when no other driver is found because PID is the | ||
50 | * standards compliant way of implementing force feedback in HID. | ||
51 | * pidff_init() will quickly abort if the device doesn't appear to | ||
52 | * be a PID device | ||
53 | */ | ||
54 | static struct hid_ff_initializer inits[] = { | ||
55 | #ifdef CONFIG_LOGITECH_FF | ||
56 | { 0x46d, 0xc211, hid_lgff_init }, /* Logitech Cordless rumble pad */ | ||
57 | { 0x46d, 0xc219, hid_lgff_init }, /* Logitech Cordless rumble pad 2 */ | ||
58 | { 0x46d, 0xc283, hid_lgff_init }, /* Logitech Wingman Force 3d */ | ||
59 | { 0x46d, 0xc294, hid_lgff_init }, /* Logitech Formula Force EX */ | ||
60 | { 0x46d, 0xc295, hid_lgff_init }, /* Logitech MOMO force wheel */ | ||
61 | { 0x46d, 0xca03, hid_lgff_init }, /* Logitech MOMO force wheel */ | ||
62 | #endif | ||
63 | #ifdef CONFIG_PANTHERLORD_FF | ||
64 | { 0x810, 0x0001, hid_plff_init }, | ||
65 | #endif | ||
66 | #ifdef CONFIG_THRUSTMASTER_FF | ||
67 | { 0x44f, 0xb304, hid_tmff_init }, | ||
68 | #endif | ||
69 | #ifdef CONFIG_ZEROPLUS_FF | ||
70 | { 0xc12, 0x0005, hid_zpff_init }, | ||
71 | { 0xc12, 0x0030, hid_zpff_init }, | ||
72 | #endif | ||
73 | { 0, 0, hid_pidff_init} /* Matches anything */ | ||
74 | }; | ||
75 | |||
76 | int hid_ff_init(struct hid_device* hid) | ||
77 | { | ||
78 | struct hid_ff_initializer *init; | ||
79 | int vendor = le16_to_cpu(hid_to_usb_dev(hid)->descriptor.idVendor); | ||
80 | int product = le16_to_cpu(hid_to_usb_dev(hid)->descriptor.idProduct); | ||
81 | |||
82 | for (init = inits; init->idVendor; init++) | ||
83 | if (init->idVendor == vendor && init->idProduct == product) | ||
84 | break; | ||
85 | |||
86 | return init->init(hid); | ||
87 | } | ||
88 | EXPORT_SYMBOL_GPL(hid_ff_init); | ||
89 | |||
diff --git a/drivers/usb/input/hid-lgff.c b/drivers/usb/input/hid-lgff.c deleted file mode 100644 index e6f3af3e66d1..000000000000 --- a/drivers/usb/input/hid-lgff.c +++ /dev/null | |||
@@ -1,150 +0,0 @@ | |||
1 | /* | ||
2 | * Force feedback support for hid-compliant for some of the devices from | ||
3 | * Logitech, namely: | ||
4 | * - WingMan Cordless RumblePad | ||
5 | * - WingMan Force 3D | ||
6 | * | ||
7 | * Copyright (c) 2002-2004 Johann Deneux | ||
8 | * Copyright (c) 2006 Anssi Hannula <anssi.hannula@gmail.com> | ||
9 | */ | ||
10 | |||
11 | /* | ||
12 | * This program is free software; you can redistribute it and/or modify | ||
13 | * it under the terms of the GNU General Public License as published by | ||
14 | * the Free Software Foundation; either version 2 of the License, or | ||
15 | * (at your option) any later version. | ||
16 | * | ||
17 | * This program is distributed in the hope that it will be useful, | ||
18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
20 | * GNU General Public License for more details. | ||
21 | * | ||
22 | * You should have received a copy of the GNU General Public License | ||
23 | * along with this program; if not, write to the Free Software | ||
24 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
25 | * | ||
26 | * Should you need to contact me, the author, you can do so by | ||
27 | * e-mail - mail your message to <johann.deneux@it.uu.se> | ||
28 | */ | ||
29 | |||
30 | #include <linux/input.h> | ||
31 | #include <linux/usb.h> | ||
32 | #include <linux/hid.h> | ||
33 | #include "usbhid.h" | ||
34 | |||
35 | struct dev_type { | ||
36 | u16 idVendor; | ||
37 | u16 idProduct; | ||
38 | const signed short *ff; | ||
39 | }; | ||
40 | |||
41 | static const signed short ff_rumble[] = { | ||
42 | FF_RUMBLE, | ||
43 | -1 | ||
44 | }; | ||
45 | |||
46 | static const signed short ff_joystick[] = { | ||
47 | FF_CONSTANT, | ||
48 | -1 | ||
49 | }; | ||
50 | |||
51 | static const struct dev_type devices[] = { | ||
52 | { 0x046d, 0xc211, ff_rumble }, | ||
53 | { 0x046d, 0xc219, ff_rumble }, | ||
54 | { 0x046d, 0xc283, ff_joystick }, | ||
55 | { 0x046d, 0xc294, ff_joystick }, | ||
56 | { 0x046d, 0xc295, ff_joystick }, | ||
57 | { 0x046d, 0xca03, ff_joystick }, | ||
58 | }; | ||
59 | |||
60 | static int hid_lgff_play(struct input_dev *dev, void *data, struct ff_effect *effect) | ||
61 | { | ||
62 | struct hid_device *hid = dev->private; | ||
63 | struct list_head *report_list = &hid->report_enum[HID_OUTPUT_REPORT].report_list; | ||
64 | struct hid_report *report = list_entry(report_list->next, struct hid_report, list); | ||
65 | int x, y; | ||
66 | unsigned int left, right; | ||
67 | |||
68 | #define CLAMP(x) if (x < 0) x = 0; if (x > 0xff) x = 0xff | ||
69 | |||
70 | switch (effect->type) { | ||
71 | case FF_CONSTANT: | ||
72 | x = effect->u.ramp.start_level + 0x7f; /* 0x7f is center */ | ||
73 | y = effect->u.ramp.end_level + 0x7f; | ||
74 | CLAMP(x); | ||
75 | CLAMP(y); | ||
76 | report->field[0]->value[0] = 0x51; | ||
77 | report->field[0]->value[1] = 0x08; | ||
78 | report->field[0]->value[2] = x; | ||
79 | report->field[0]->value[3] = y; | ||
80 | dbg("(x, y)=(%04x, %04x)", x, y); | ||
81 | usbhid_submit_report(hid, report, USB_DIR_OUT); | ||
82 | break; | ||
83 | |||
84 | case FF_RUMBLE: | ||
85 | right = effect->u.rumble.strong_magnitude; | ||
86 | left = effect->u.rumble.weak_magnitude; | ||
87 | right = right * 0xff / 0xffff; | ||
88 | left = left * 0xff / 0xffff; | ||
89 | CLAMP(left); | ||
90 | CLAMP(right); | ||
91 | report->field[0]->value[0] = 0x42; | ||
92 | report->field[0]->value[1] = 0x00; | ||
93 | report->field[0]->value[2] = left; | ||
94 | report->field[0]->value[3] = right; | ||
95 | dbg("(left, right)=(%04x, %04x)", left, right); | ||
96 | usbhid_submit_report(hid, report, USB_DIR_OUT); | ||
97 | break; | ||
98 | } | ||
99 | return 0; | ||
100 | } | ||
101 | |||
102 | int hid_lgff_init(struct hid_device* hid) | ||
103 | { | ||
104 | struct hid_input *hidinput = list_entry(hid->inputs.next, struct hid_input, list); | ||
105 | struct list_head *report_list = &hid->report_enum[HID_OUTPUT_REPORT].report_list; | ||
106 | struct input_dev *dev = hidinput->input; | ||
107 | struct hid_report *report; | ||
108 | struct hid_field *field; | ||
109 | const signed short *ff_bits = ff_joystick; | ||
110 | int error; | ||
111 | int i; | ||
112 | |||
113 | /* Find the report to use */ | ||
114 | if (list_empty(report_list)) { | ||
115 | err("No output report found"); | ||
116 | return -1; | ||
117 | } | ||
118 | |||
119 | /* Check that the report looks ok */ | ||
120 | report = list_entry(report_list->next, struct hid_report, list); | ||
121 | if (!report) { | ||
122 | err("NULL output report"); | ||
123 | return -1; | ||
124 | } | ||
125 | |||
126 | field = report->field[0]; | ||
127 | if (!field) { | ||
128 | err("NULL field"); | ||
129 | return -1; | ||
130 | } | ||
131 | |||
132 | for (i = 0; i < ARRAY_SIZE(devices); i++) { | ||
133 | if (dev->id.vendor == devices[i].idVendor && | ||
134 | dev->id.product == devices[i].idProduct) { | ||
135 | ff_bits = devices[i].ff; | ||
136 | break; | ||
137 | } | ||
138 | } | ||
139 | |||
140 | for (i = 0; ff_bits[i] >= 0; i++) | ||
141 | set_bit(ff_bits[i], dev->ffbit); | ||
142 | |||
143 | error = input_ff_create_memless(dev, NULL, hid_lgff_play); | ||
144 | if (error) | ||
145 | return error; | ||
146 | |||
147 | printk(KERN_INFO "Force feedback for Logitech force feedback devices by Johann Deneux <johann.deneux@it.uu.se>\n"); | ||
148 | |||
149 | return 0; | ||
150 | } | ||
diff --git a/drivers/usb/input/hid-pidff.c b/drivers/usb/input/hid-pidff.c deleted file mode 100644 index f5a90e950e6b..000000000000 --- a/drivers/usb/input/hid-pidff.c +++ /dev/null | |||
@@ -1,1331 +0,0 @@ | |||
1 | /* | ||
2 | * Force feedback driver for USB HID PID compliant devices | ||
3 | * | ||
4 | * Copyright (c) 2005, 2006 Anssi Hannula <anssi.hannula@gmail.com> | ||
5 | */ | ||
6 | |||
7 | /* | ||
8 | * This program is free software; you can redistribute it and/or modify | ||
9 | * it under the terms of the GNU General Public License as published by | ||
10 | * the Free Software Foundation; either version 2 of the License, or | ||
11 | * (at your option) any later version. | ||
12 | * | ||
13 | * This program is distributed in the hope that it will be useful, | ||
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
16 | * GNU General Public License for more details. | ||
17 | * | ||
18 | * You should have received a copy of the GNU General Public License | ||
19 | * along with this program; if not, write to the Free Software | ||
20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
21 | */ | ||
22 | |||
23 | /* #define DEBUG */ | ||
24 | |||
25 | #define debug(format, arg...) pr_debug("hid-pidff: " format "\n" , ## arg) | ||
26 | |||
27 | #include <linux/input.h> | ||
28 | #include <linux/usb.h> | ||
29 | |||
30 | #include <linux/hid.h> | ||
31 | |||
32 | #include "usbhid.h" | ||
33 | |||
34 | #define PID_EFFECTS_MAX 64 | ||
35 | |||
36 | /* Report usage table used to put reports into an array */ | ||
37 | |||
38 | #define PID_SET_EFFECT 0 | ||
39 | #define PID_EFFECT_OPERATION 1 | ||
40 | #define PID_DEVICE_GAIN 2 | ||
41 | #define PID_POOL 3 | ||
42 | #define PID_BLOCK_LOAD 4 | ||
43 | #define PID_BLOCK_FREE 5 | ||
44 | #define PID_DEVICE_CONTROL 6 | ||
45 | #define PID_CREATE_NEW_EFFECT 7 | ||
46 | |||
47 | #define PID_REQUIRED_REPORTS 7 | ||
48 | |||
49 | #define PID_SET_ENVELOPE 8 | ||
50 | #define PID_SET_CONDITION 9 | ||
51 | #define PID_SET_PERIODIC 10 | ||
52 | #define PID_SET_CONSTANT 11 | ||
53 | #define PID_SET_RAMP 12 | ||
54 | static const u8 pidff_reports[] = { | ||
55 | 0x21, 0x77, 0x7d, 0x7f, 0x89, 0x90, 0x96, 0xab, | ||
56 | 0x5a, 0x5f, 0x6e, 0x73, 0x74 | ||
57 | }; | ||
58 | |||
59 | /* device_control is really 0x95, but 0x96 specified as it is the usage of | ||
60 | the only field in that report */ | ||
61 | |||
62 | /* Value usage tables used to put fields and values into arrays */ | ||
63 | |||
64 | #define PID_EFFECT_BLOCK_INDEX 0 | ||
65 | |||
66 | #define PID_DURATION 1 | ||
67 | #define PID_GAIN 2 | ||
68 | #define PID_TRIGGER_BUTTON 3 | ||
69 | #define PID_TRIGGER_REPEAT_INT 4 | ||
70 | #define PID_DIRECTION_ENABLE 5 | ||
71 | #define PID_START_DELAY 6 | ||
72 | static const u8 pidff_set_effect[] = { | ||
73 | 0x22, 0x50, 0x52, 0x53, 0x54, 0x56, 0xa7 | ||
74 | }; | ||
75 | |||
76 | #define PID_ATTACK_LEVEL 1 | ||
77 | #define PID_ATTACK_TIME 2 | ||
78 | #define PID_FADE_LEVEL 3 | ||
79 | #define PID_FADE_TIME 4 | ||
80 | static const u8 pidff_set_envelope[] = { 0x22, 0x5b, 0x5c, 0x5d, 0x5e }; | ||
81 | |||
82 | #define PID_PARAM_BLOCK_OFFSET 1 | ||
83 | #define PID_CP_OFFSET 2 | ||
84 | #define PID_POS_COEFFICIENT 3 | ||
85 | #define PID_NEG_COEFFICIENT 4 | ||
86 | #define PID_POS_SATURATION 5 | ||
87 | #define PID_NEG_SATURATION 6 | ||
88 | #define PID_DEAD_BAND 7 | ||
89 | static const u8 pidff_set_condition[] = { | ||
90 | 0x22, 0x23, 0x60, 0x61, 0x62, 0x63, 0x64, 0x65 | ||
91 | }; | ||
92 | |||
93 | #define PID_MAGNITUDE 1 | ||
94 | #define PID_OFFSET 2 | ||
95 | #define PID_PHASE 3 | ||
96 | #define PID_PERIOD 4 | ||
97 | static const u8 pidff_set_periodic[] = { 0x22, 0x70, 0x6f, 0x71, 0x72 }; | ||
98 | static const u8 pidff_set_constant[] = { 0x22, 0x70 }; | ||
99 | |||
100 | #define PID_RAMP_START 1 | ||
101 | #define PID_RAMP_END 2 | ||
102 | static const u8 pidff_set_ramp[] = { 0x22, 0x75, 0x76 }; | ||
103 | |||
104 | #define PID_RAM_POOL_AVAILABLE 1 | ||
105 | static const u8 pidff_block_load[] = { 0x22, 0xac }; | ||
106 | |||
107 | #define PID_LOOP_COUNT 1 | ||
108 | static const u8 pidff_effect_operation[] = { 0x22, 0x7c }; | ||
109 | |||
110 | static const u8 pidff_block_free[] = { 0x22 }; | ||
111 | |||
112 | #define PID_DEVICE_GAIN_FIELD 0 | ||
113 | static const u8 pidff_device_gain[] = { 0x7e }; | ||
114 | |||
115 | #define PID_RAM_POOL_SIZE 0 | ||
116 | #define PID_SIMULTANEOUS_MAX 1 | ||
117 | #define PID_DEVICE_MANAGED_POOL 2 | ||
118 | static const u8 pidff_pool[] = { 0x80, 0x83, 0xa9 }; | ||
119 | |||
120 | /* Special field key tables used to put special field keys into arrays */ | ||
121 | |||
122 | #define PID_ENABLE_ACTUATORS 0 | ||
123 | #define PID_RESET 1 | ||
124 | static const u8 pidff_device_control[] = { 0x97, 0x9a }; | ||
125 | |||
126 | #define PID_CONSTANT 0 | ||
127 | #define PID_RAMP 1 | ||
128 | #define PID_SQUARE 2 | ||
129 | #define PID_SINE 3 | ||
130 | #define PID_TRIANGLE 4 | ||
131 | #define PID_SAW_UP 5 | ||
132 | #define PID_SAW_DOWN 6 | ||
133 | #define PID_SPRING 7 | ||
134 | #define PID_DAMPER 8 | ||
135 | #define PID_INERTIA 9 | ||
136 | #define PID_FRICTION 10 | ||
137 | static const u8 pidff_effect_types[] = { | ||
138 | 0x26, 0x27, 0x30, 0x31, 0x32, 0x33, 0x34, | ||
139 | 0x40, 0x41, 0x42, 0x43 | ||
140 | }; | ||
141 | |||
142 | #define PID_BLOCK_LOAD_SUCCESS 0 | ||
143 | #define PID_BLOCK_LOAD_FULL 1 | ||
144 | static const u8 pidff_block_load_status[] = { 0x8c, 0x8d }; | ||
145 | |||
146 | #define PID_EFFECT_START 0 | ||
147 | #define PID_EFFECT_STOP 1 | ||
148 | static const u8 pidff_effect_operation_status[] = { 0x79, 0x7b }; | ||
149 | |||
150 | struct pidff_usage { | ||
151 | struct hid_field *field; | ||
152 | s32 *value; | ||
153 | }; | ||
154 | |||
155 | struct pidff_device { | ||
156 | struct hid_device *hid; | ||
157 | |||
158 | struct hid_report *reports[sizeof(pidff_reports)]; | ||
159 | |||
160 | struct pidff_usage set_effect[sizeof(pidff_set_effect)]; | ||
161 | struct pidff_usage set_envelope[sizeof(pidff_set_envelope)]; | ||
162 | struct pidff_usage set_condition[sizeof(pidff_set_condition)]; | ||
163 | struct pidff_usage set_periodic[sizeof(pidff_set_periodic)]; | ||
164 | struct pidff_usage set_constant[sizeof(pidff_set_constant)]; | ||
165 | struct pidff_usage set_ramp[sizeof(pidff_set_ramp)]; | ||
166 | |||
167 | struct pidff_usage device_gain[sizeof(pidff_device_gain)]; | ||
168 | struct pidff_usage block_load[sizeof(pidff_block_load)]; | ||
169 | struct pidff_usage pool[sizeof(pidff_pool)]; | ||
170 | struct pidff_usage effect_operation[sizeof(pidff_effect_operation)]; | ||
171 | struct pidff_usage block_free[sizeof(pidff_block_free)]; | ||
172 | |||
173 | /* Special field is a field that is not composed of | ||
174 | usage<->value pairs that pidff_usage values are */ | ||
175 | |||
176 | /* Special field in create_new_effect */ | ||
177 | struct hid_field *create_new_effect_type; | ||
178 | |||
179 | /* Special fields in set_effect */ | ||
180 | struct hid_field *set_effect_type; | ||
181 | struct hid_field *effect_direction; | ||
182 | |||
183 | /* Special field in device_control */ | ||
184 | struct hid_field *device_control; | ||
185 | |||
186 | /* Special field in block_load */ | ||
187 | struct hid_field *block_load_status; | ||
188 | |||
189 | /* Special field in effect_operation */ | ||
190 | struct hid_field *effect_operation_status; | ||
191 | |||
192 | int control_id[sizeof(pidff_device_control)]; | ||
193 | int type_id[sizeof(pidff_effect_types)]; | ||
194 | int status_id[sizeof(pidff_block_load_status)]; | ||
195 | int operation_id[sizeof(pidff_effect_operation_status)]; | ||
196 | |||
197 | int pid_id[PID_EFFECTS_MAX]; | ||
198 | }; | ||
199 | |||
200 | /* | ||
201 | * Scale an unsigned value with range 0..max for the given field | ||
202 | */ | ||
203 | static int pidff_rescale(int i, int max, struct hid_field *field) | ||
204 | { | ||
205 | return i * (field->logical_maximum - field->logical_minimum) / max + | ||
206 | field->logical_minimum; | ||
207 | } | ||
208 | |||
209 | /* | ||
210 | * Scale a signed value in range -0x8000..0x7fff for the given field | ||
211 | */ | ||
212 | static int pidff_rescale_signed(int i, struct hid_field *field) | ||
213 | { | ||
214 | return i == 0 ? 0 : i > | ||
215 | 0 ? i * field->logical_maximum / 0x7fff : i * | ||
216 | field->logical_minimum / -0x8000; | ||
217 | } | ||
218 | |||
219 | static void pidff_set(struct pidff_usage *usage, u16 value) | ||
220 | { | ||
221 | usage->value[0] = pidff_rescale(value, 0xffff, usage->field); | ||
222 | debug("calculated from %d to %d", value, usage->value[0]); | ||
223 | } | ||
224 | |||
225 | static void pidff_set_signed(struct pidff_usage *usage, s16 value) | ||
226 | { | ||
227 | if (usage->field->logical_minimum < 0) | ||
228 | usage->value[0] = pidff_rescale_signed(value, usage->field); | ||
229 | else { | ||
230 | if (value < 0) | ||
231 | usage->value[0] = | ||
232 | pidff_rescale(-value, 0x8000, usage->field); | ||
233 | else | ||
234 | usage->value[0] = | ||
235 | pidff_rescale(value, 0x7fff, usage->field); | ||
236 | } | ||
237 | debug("calculated from %d to %d", value, usage->value[0]); | ||
238 | } | ||
239 | |||
240 | /* | ||
241 | * Send envelope report to the device | ||
242 | */ | ||
243 | static void pidff_set_envelope_report(struct pidff_device *pidff, | ||
244 | struct ff_envelope *envelope) | ||
245 | { | ||
246 | pidff->set_envelope[PID_EFFECT_BLOCK_INDEX].value[0] = | ||
247 | pidff->block_load[PID_EFFECT_BLOCK_INDEX].value[0]; | ||
248 | |||
249 | pidff->set_envelope[PID_ATTACK_LEVEL].value[0] = | ||
250 | pidff_rescale(envelope->attack_level > | ||
251 | 0x7fff ? 0x7fff : envelope->attack_level, 0x7fff, | ||
252 | pidff->set_envelope[PID_ATTACK_LEVEL].field); | ||
253 | pidff->set_envelope[PID_FADE_LEVEL].value[0] = | ||
254 | pidff_rescale(envelope->fade_level > | ||
255 | 0x7fff ? 0x7fff : envelope->fade_level, 0x7fff, | ||
256 | pidff->set_envelope[PID_FADE_LEVEL].field); | ||
257 | |||
258 | pidff->set_envelope[PID_ATTACK_TIME].value[0] = envelope->attack_length; | ||
259 | pidff->set_envelope[PID_FADE_TIME].value[0] = envelope->fade_length; | ||
260 | |||
261 | debug("attack %u => %d", envelope->attack_level, | ||
262 | pidff->set_envelope[PID_ATTACK_LEVEL].value[0]); | ||
263 | |||
264 | usbhid_submit_report(pidff->hid, pidff->reports[PID_SET_ENVELOPE], | ||
265 | USB_DIR_OUT); | ||
266 | } | ||
267 | |||
268 | /* | ||
269 | * Test if the new envelope differs from old one | ||
270 | */ | ||
271 | static int pidff_needs_set_envelope(struct ff_envelope *envelope, | ||
272 | struct ff_envelope *old) | ||
273 | { | ||
274 | return envelope->attack_level != old->attack_level || | ||
275 | envelope->fade_level != old->fade_level || | ||
276 | envelope->attack_length != old->attack_length || | ||
277 | envelope->fade_length != old->fade_length; | ||
278 | } | ||
279 | |||
280 | /* | ||
281 | * Send constant force report to the device | ||
282 | */ | ||
283 | static void pidff_set_constant_force_report(struct pidff_device *pidff, | ||
284 | struct ff_effect *effect) | ||
285 | { | ||
286 | pidff->set_constant[PID_EFFECT_BLOCK_INDEX].value[0] = | ||
287 | pidff->block_load[PID_EFFECT_BLOCK_INDEX].value[0]; | ||
288 | pidff_set_signed(&pidff->set_constant[PID_MAGNITUDE], | ||
289 | effect->u.constant.level); | ||
290 | |||
291 | usbhid_submit_report(pidff->hid, pidff->reports[PID_SET_CONSTANT], | ||
292 | USB_DIR_OUT); | ||
293 | } | ||
294 | |||
295 | /* | ||
296 | * Test if the constant parameters have changed between effects | ||
297 | */ | ||
298 | static int pidff_needs_set_constant(struct ff_effect *effect, | ||
299 | struct ff_effect *old) | ||
300 | { | ||
301 | return effect->u.constant.level != old->u.constant.level; | ||
302 | } | ||
303 | |||
304 | /* | ||
305 | * Send set effect report to the device | ||
306 | */ | ||
307 | static void pidff_set_effect_report(struct pidff_device *pidff, | ||
308 | struct ff_effect *effect) | ||
309 | { | ||
310 | pidff->set_effect[PID_EFFECT_BLOCK_INDEX].value[0] = | ||
311 | pidff->block_load[PID_EFFECT_BLOCK_INDEX].value[0]; | ||
312 | pidff->set_effect_type->value[0] = | ||
313 | pidff->create_new_effect_type->value[0]; | ||
314 | pidff->set_effect[PID_DURATION].value[0] = effect->replay.length; | ||
315 | pidff->set_effect[PID_TRIGGER_BUTTON].value[0] = effect->trigger.button; | ||
316 | pidff->set_effect[PID_TRIGGER_REPEAT_INT].value[0] = | ||
317 | effect->trigger.interval; | ||
318 | pidff->set_effect[PID_GAIN].value[0] = | ||
319 | pidff->set_effect[PID_GAIN].field->logical_maximum; | ||
320 | pidff->set_effect[PID_DIRECTION_ENABLE].value[0] = 1; | ||
321 | pidff->effect_direction->value[0] = | ||
322 | pidff_rescale(effect->direction, 0xffff, | ||
323 | pidff->effect_direction); | ||
324 | pidff->set_effect[PID_START_DELAY].value[0] = effect->replay.delay; | ||
325 | |||
326 | usbhid_submit_report(pidff->hid, pidff->reports[PID_SET_EFFECT], | ||
327 | USB_DIR_OUT); | ||
328 | } | ||
329 | |||
330 | /* | ||
331 | * Test if the values used in set_effect have changed | ||
332 | */ | ||
333 | static int pidff_needs_set_effect(struct ff_effect *effect, | ||
334 | struct ff_effect *old) | ||
335 | { | ||
336 | return effect->replay.length != old->replay.length || | ||
337 | effect->trigger.interval != old->trigger.interval || | ||
338 | effect->trigger.button != old->trigger.button || | ||
339 | effect->direction != old->direction || | ||
340 | effect->replay.delay != old->replay.delay; | ||
341 | } | ||
342 | |||
343 | /* | ||
344 | * Send periodic effect report to the device | ||
345 | */ | ||
346 | static void pidff_set_periodic_report(struct pidff_device *pidff, | ||
347 | struct ff_effect *effect) | ||
348 | { | ||
349 | pidff->set_periodic[PID_EFFECT_BLOCK_INDEX].value[0] = | ||
350 | pidff->block_load[PID_EFFECT_BLOCK_INDEX].value[0]; | ||
351 | pidff_set_signed(&pidff->set_periodic[PID_MAGNITUDE], | ||
352 | effect->u.periodic.magnitude); | ||
353 | pidff_set_signed(&pidff->set_periodic[PID_OFFSET], | ||
354 | effect->u.periodic.offset); | ||
355 | pidff_set(&pidff->set_periodic[PID_PHASE], effect->u.periodic.phase); | ||
356 | pidff->set_periodic[PID_PERIOD].value[0] = effect->u.periodic.period; | ||
357 | |||
358 | usbhid_submit_report(pidff->hid, pidff->reports[PID_SET_PERIODIC], | ||
359 | USB_DIR_OUT); | ||
360 | |||
361 | } | ||
362 | |||
363 | /* | ||
364 | * Test if periodic effect parameters have changed | ||
365 | */ | ||
366 | static int pidff_needs_set_periodic(struct ff_effect *effect, | ||
367 | struct ff_effect *old) | ||
368 | { | ||
369 | return effect->u.periodic.magnitude != old->u.periodic.magnitude || | ||
370 | effect->u.periodic.offset != old->u.periodic.offset || | ||
371 | effect->u.periodic.phase != old->u.periodic.phase || | ||
372 | effect->u.periodic.period != old->u.periodic.period; | ||
373 | } | ||
374 | |||
375 | /* | ||
376 | * Send condition effect reports to the device | ||
377 | */ | ||
378 | static void pidff_set_condition_report(struct pidff_device *pidff, | ||
379 | struct ff_effect *effect) | ||
380 | { | ||
381 | int i; | ||
382 | |||
383 | pidff->set_condition[PID_EFFECT_BLOCK_INDEX].value[0] = | ||
384 | pidff->block_load[PID_EFFECT_BLOCK_INDEX].value[0]; | ||
385 | |||
386 | for (i = 0; i < 2; i++) { | ||
387 | pidff->set_condition[PID_PARAM_BLOCK_OFFSET].value[0] = i; | ||
388 | pidff_set_signed(&pidff->set_condition[PID_CP_OFFSET], | ||
389 | effect->u.condition[i].center); | ||
390 | pidff_set_signed(&pidff->set_condition[PID_POS_COEFFICIENT], | ||
391 | effect->u.condition[i].right_coeff); | ||
392 | pidff_set_signed(&pidff->set_condition[PID_NEG_COEFFICIENT], | ||
393 | effect->u.condition[i].left_coeff); | ||
394 | pidff_set(&pidff->set_condition[PID_POS_SATURATION], | ||
395 | effect->u.condition[i].right_saturation); | ||
396 | pidff_set(&pidff->set_condition[PID_NEG_SATURATION], | ||
397 | effect->u.condition[i].left_saturation); | ||
398 | pidff_set(&pidff->set_condition[PID_DEAD_BAND], | ||
399 | effect->u.condition[i].deadband); | ||
400 | usbhid_wait_io(pidff->hid); | ||
401 | usbhid_submit_report(pidff->hid, pidff->reports[PID_SET_CONDITION], | ||
402 | USB_DIR_OUT); | ||
403 | } | ||
404 | } | ||
405 | |||
406 | /* | ||
407 | * Test if condition effect parameters have changed | ||
408 | */ | ||
409 | static int pidff_needs_set_condition(struct ff_effect *effect, | ||
410 | struct ff_effect *old) | ||
411 | { | ||
412 | int i; | ||
413 | int ret = 0; | ||
414 | |||
415 | for (i = 0; i < 2; i++) { | ||
416 | struct ff_condition_effect *cond = &effect->u.condition[i]; | ||
417 | struct ff_condition_effect *old_cond = &old->u.condition[i]; | ||
418 | |||
419 | ret |= cond->center != old_cond->center || | ||
420 | cond->right_coeff != old_cond->right_coeff || | ||
421 | cond->left_coeff != old_cond->left_coeff || | ||
422 | cond->right_saturation != old_cond->right_saturation || | ||
423 | cond->left_saturation != old_cond->left_saturation || | ||
424 | cond->deadband != old_cond->deadband; | ||
425 | } | ||
426 | |||
427 | return ret; | ||
428 | } | ||
429 | |||
430 | /* | ||
431 | * Send ramp force report to the device | ||
432 | */ | ||
433 | static void pidff_set_ramp_force_report(struct pidff_device *pidff, | ||
434 | struct ff_effect *effect) | ||
435 | { | ||
436 | pidff->set_ramp[PID_EFFECT_BLOCK_INDEX].value[0] = | ||
437 | pidff->block_load[PID_EFFECT_BLOCK_INDEX].value[0]; | ||
438 | pidff_set_signed(&pidff->set_ramp[PID_RAMP_START], | ||
439 | effect->u.ramp.start_level); | ||
440 | pidff_set_signed(&pidff->set_ramp[PID_RAMP_END], | ||
441 | effect->u.ramp.end_level); | ||
442 | usbhid_submit_report(pidff->hid, pidff->reports[PID_SET_RAMP], | ||
443 | USB_DIR_OUT); | ||
444 | } | ||
445 | |||
446 | /* | ||
447 | * Test if ramp force parameters have changed | ||
448 | */ | ||
449 | static int pidff_needs_set_ramp(struct ff_effect *effect, struct ff_effect *old) | ||
450 | { | ||
451 | return effect->u.ramp.start_level != old->u.ramp.start_level || | ||
452 | effect->u.ramp.end_level != old->u.ramp.end_level; | ||
453 | } | ||
454 | |||
455 | /* | ||
456 | * Send a request for effect upload to the device | ||
457 | * | ||
458 | * Returns 0 if device reported success, -ENOSPC if the device reported memory | ||
459 | * is full. Upon unknown response the function will retry for 60 times, if | ||
460 | * still unsuccessful -EIO is returned. | ||
461 | */ | ||
462 | static int pidff_request_effect_upload(struct pidff_device *pidff, int efnum) | ||
463 | { | ||
464 | int j; | ||
465 | |||
466 | pidff->create_new_effect_type->value[0] = efnum; | ||
467 | usbhid_submit_report(pidff->hid, pidff->reports[PID_CREATE_NEW_EFFECT], | ||
468 | USB_DIR_OUT); | ||
469 | debug("create_new_effect sent, type: %d", efnum); | ||
470 | |||
471 | pidff->block_load[PID_EFFECT_BLOCK_INDEX].value[0] = 0; | ||
472 | pidff->block_load_status->value[0] = 0; | ||
473 | usbhid_wait_io(pidff->hid); | ||
474 | |||
475 | for (j = 0; j < 60; j++) { | ||
476 | debug("pid_block_load requested"); | ||
477 | usbhid_submit_report(pidff->hid, pidff->reports[PID_BLOCK_LOAD], | ||
478 | USB_DIR_IN); | ||
479 | usbhid_wait_io(pidff->hid); | ||
480 | if (pidff->block_load_status->value[0] == | ||
481 | pidff->status_id[PID_BLOCK_LOAD_SUCCESS]) { | ||
482 | debug("device reported free memory: %d bytes", | ||
483 | pidff->block_load[PID_RAM_POOL_AVAILABLE].value ? | ||
484 | pidff->block_load[PID_RAM_POOL_AVAILABLE].value[0] : -1); | ||
485 | return 0; | ||
486 | } | ||
487 | if (pidff->block_load_status->value[0] == | ||
488 | pidff->status_id[PID_BLOCK_LOAD_FULL]) { | ||
489 | debug("not enough memory free: %d bytes", | ||
490 | pidff->block_load[PID_RAM_POOL_AVAILABLE].value ? | ||
491 | pidff->block_load[PID_RAM_POOL_AVAILABLE].value[0] : -1); | ||
492 | return -ENOSPC; | ||
493 | } | ||
494 | } | ||
495 | printk(KERN_ERR "hid-pidff: pid_block_load failed 60 times\n"); | ||
496 | return -EIO; | ||
497 | } | ||
498 | |||
499 | /* | ||
500 | * Play the effect with PID id n times | ||
501 | */ | ||
502 | static void pidff_playback_pid(struct pidff_device *pidff, int pid_id, int n) | ||
503 | { | ||
504 | pidff->effect_operation[PID_EFFECT_BLOCK_INDEX].value[0] = pid_id; | ||
505 | |||
506 | if (n == 0) { | ||
507 | pidff->effect_operation_status->value[0] = | ||
508 | pidff->operation_id[PID_EFFECT_STOP]; | ||
509 | } else { | ||
510 | pidff->effect_operation_status->value[0] = | ||
511 | pidff->operation_id[PID_EFFECT_START]; | ||
512 | pidff->effect_operation[PID_LOOP_COUNT].value[0] = n; | ||
513 | } | ||
514 | |||
515 | usbhid_wait_io(pidff->hid); | ||
516 | usbhid_submit_report(pidff->hid, pidff->reports[PID_EFFECT_OPERATION], | ||
517 | USB_DIR_OUT); | ||
518 | } | ||
519 | |||
520 | /** | ||
521 | * Play the effect with effect id @effect_id for @value times | ||
522 | */ | ||
523 | static int pidff_playback(struct input_dev *dev, int effect_id, int value) | ||
524 | { | ||
525 | struct pidff_device *pidff = dev->ff->private; | ||
526 | |||
527 | pidff_playback_pid(pidff, pidff->pid_id[effect_id], value); | ||
528 | |||
529 | return 0; | ||
530 | } | ||
531 | |||
532 | /* | ||
533 | * Erase effect with PID id | ||
534 | */ | ||
535 | static void pidff_erase_pid(struct pidff_device *pidff, int pid_id) | ||
536 | { | ||
537 | pidff->block_free[PID_EFFECT_BLOCK_INDEX].value[0] = pid_id; | ||
538 | usbhid_submit_report(pidff->hid, pidff->reports[PID_BLOCK_FREE], | ||
539 | USB_DIR_OUT); | ||
540 | } | ||
541 | |||
542 | /* | ||
543 | * Stop and erase effect with effect_id | ||
544 | */ | ||
545 | static int pidff_erase_effect(struct input_dev *dev, int effect_id) | ||
546 | { | ||
547 | struct pidff_device *pidff = dev->ff->private; | ||
548 | int pid_id = pidff->pid_id[effect_id]; | ||
549 | |||
550 | debug("starting to erase %d/%d", effect_id, pidff->pid_id[effect_id]); | ||
551 | pidff_playback_pid(pidff, pid_id, 0); | ||
552 | pidff_erase_pid(pidff, pid_id); | ||
553 | |||
554 | return 0; | ||
555 | } | ||
556 | |||
557 | /* | ||
558 | * Effect upload handler | ||
559 | */ | ||
560 | static int pidff_upload_effect(struct input_dev *dev, struct ff_effect *effect, | ||
561 | struct ff_effect *old) | ||
562 | { | ||
563 | struct pidff_device *pidff = dev->ff->private; | ||
564 | int type_id; | ||
565 | int error; | ||
566 | |||
567 | switch (effect->type) { | ||
568 | case FF_CONSTANT: | ||
569 | if (!old) { | ||
570 | error = pidff_request_effect_upload(pidff, | ||
571 | pidff->type_id[PID_CONSTANT]); | ||
572 | if (error) | ||
573 | return error; | ||
574 | } | ||
575 | if (!old || pidff_needs_set_effect(effect, old)) | ||
576 | pidff_set_effect_report(pidff, effect); | ||
577 | if (!old || pidff_needs_set_constant(effect, old)) | ||
578 | pidff_set_constant_force_report(pidff, effect); | ||
579 | if (!old || | ||
580 | pidff_needs_set_envelope(&effect->u.constant.envelope, | ||
581 | &old->u.constant.envelope)) | ||
582 | pidff_set_envelope_report(pidff, | ||
583 | &effect->u.constant.envelope); | ||
584 | break; | ||
585 | |||
586 | case FF_PERIODIC: | ||
587 | if (!old) { | ||
588 | switch (effect->u.periodic.waveform) { | ||
589 | case FF_SQUARE: | ||
590 | type_id = PID_SQUARE; | ||
591 | break; | ||
592 | case FF_TRIANGLE: | ||
593 | type_id = PID_TRIANGLE; | ||
594 | break; | ||
595 | case FF_SINE: | ||
596 | type_id = PID_SINE; | ||
597 | break; | ||
598 | case FF_SAW_UP: | ||
599 | type_id = PID_SAW_UP; | ||
600 | break; | ||
601 | case FF_SAW_DOWN: | ||
602 | type_id = PID_SAW_DOWN; | ||
603 | break; | ||
604 | default: | ||
605 | printk(KERN_ERR | ||
606 | "hid-pidff: invalid waveform\n"); | ||
607 | return -EINVAL; | ||
608 | } | ||
609 | |||
610 | error = pidff_request_effect_upload(pidff, | ||
611 | pidff->type_id[type_id]); | ||
612 | if (error) | ||
613 | return error; | ||
614 | } | ||
615 | if (!old || pidff_needs_set_effect(effect, old)) | ||
616 | pidff_set_effect_report(pidff, effect); | ||
617 | if (!old || pidff_needs_set_periodic(effect, old)) | ||
618 | pidff_set_periodic_report(pidff, effect); | ||
619 | if (!old || | ||
620 | pidff_needs_set_envelope(&effect->u.periodic.envelope, | ||
621 | &old->u.periodic.envelope)) | ||
622 | pidff_set_envelope_report(pidff, | ||
623 | &effect->u.periodic.envelope); | ||
624 | break; | ||
625 | |||
626 | case FF_RAMP: | ||
627 | if (!old) { | ||
628 | error = pidff_request_effect_upload(pidff, | ||
629 | pidff->type_id[PID_RAMP]); | ||
630 | if (error) | ||
631 | return error; | ||
632 | } | ||
633 | if (!old || pidff_needs_set_effect(effect, old)) | ||
634 | pidff_set_effect_report(pidff, effect); | ||
635 | if (!old || pidff_needs_set_ramp(effect, old)) | ||
636 | pidff_set_ramp_force_report(pidff, effect); | ||
637 | if (!old || | ||
638 | pidff_needs_set_envelope(&effect->u.ramp.envelope, | ||
639 | &old->u.ramp.envelope)) | ||
640 | pidff_set_envelope_report(pidff, | ||
641 | &effect->u.ramp.envelope); | ||
642 | break; | ||
643 | |||
644 | case FF_SPRING: | ||
645 | if (!old) { | ||
646 | error = pidff_request_effect_upload(pidff, | ||
647 | pidff->type_id[PID_SPRING]); | ||
648 | if (error) | ||
649 | return error; | ||
650 | } | ||
651 | if (!old || pidff_needs_set_effect(effect, old)) | ||
652 | pidff_set_effect_report(pidff, effect); | ||
653 | if (!old || pidff_needs_set_condition(effect, old)) | ||
654 | pidff_set_condition_report(pidff, effect); | ||
655 | break; | ||
656 | |||
657 | case FF_FRICTION: | ||
658 | if (!old) { | ||
659 | error = pidff_request_effect_upload(pidff, | ||
660 | pidff->type_id[PID_FRICTION]); | ||
661 | if (error) | ||
662 | return error; | ||
663 | } | ||
664 | if (!old || pidff_needs_set_effect(effect, old)) | ||
665 | pidff_set_effect_report(pidff, effect); | ||
666 | if (!old || pidff_needs_set_condition(effect, old)) | ||
667 | pidff_set_condition_report(pidff, effect); | ||
668 | break; | ||
669 | |||
670 | case FF_DAMPER: | ||
671 | if (!old) { | ||
672 | error = pidff_request_effect_upload(pidff, | ||
673 | pidff->type_id[PID_DAMPER]); | ||
674 | if (error) | ||
675 | return error; | ||
676 | } | ||
677 | if (!old || pidff_needs_set_effect(effect, old)) | ||
678 | pidff_set_effect_report(pidff, effect); | ||
679 | if (!old || pidff_needs_set_condition(effect, old)) | ||
680 | pidff_set_condition_report(pidff, effect); | ||
681 | break; | ||
682 | |||
683 | case FF_INERTIA: | ||
684 | if (!old) { | ||
685 | error = pidff_request_effect_upload(pidff, | ||
686 | pidff->type_id[PID_INERTIA]); | ||
687 | if (error) | ||
688 | return error; | ||
689 | } | ||
690 | if (!old || pidff_needs_set_effect(effect, old)) | ||
691 | pidff_set_effect_report(pidff, effect); | ||
692 | if (!old || pidff_needs_set_condition(effect, old)) | ||
693 | pidff_set_condition_report(pidff, effect); | ||
694 | break; | ||
695 | |||
696 | default: | ||
697 | printk(KERN_ERR "hid-pidff: invalid type\n"); | ||
698 | return -EINVAL; | ||
699 | } | ||
700 | |||
701 | if (!old) | ||
702 | pidff->pid_id[effect->id] = | ||
703 | pidff->block_load[PID_EFFECT_BLOCK_INDEX].value[0]; | ||
704 | |||
705 | debug("uploaded"); | ||
706 | |||
707 | return 0; | ||
708 | } | ||
709 | |||
710 | /* | ||
711 | * set_gain() handler | ||
712 | */ | ||
713 | static void pidff_set_gain(struct input_dev *dev, u16 gain) | ||
714 | { | ||
715 | struct pidff_device *pidff = dev->ff->private; | ||
716 | |||
717 | pidff_set(&pidff->device_gain[PID_DEVICE_GAIN_FIELD], gain); | ||
718 | usbhid_submit_report(pidff->hid, pidff->reports[PID_DEVICE_GAIN], | ||
719 | USB_DIR_OUT); | ||
720 | } | ||
721 | |||
722 | static void pidff_autocenter(struct pidff_device *pidff, u16 magnitude) | ||
723 | { | ||
724 | struct hid_field *field = | ||
725 | pidff->block_load[PID_EFFECT_BLOCK_INDEX].field; | ||
726 | |||
727 | if (!magnitude) { | ||
728 | pidff_playback_pid(pidff, field->logical_minimum, 0); | ||
729 | return; | ||
730 | } | ||
731 | |||
732 | pidff_playback_pid(pidff, field->logical_minimum, 1); | ||
733 | |||
734 | pidff->set_effect[PID_EFFECT_BLOCK_INDEX].value[0] = | ||
735 | pidff->block_load[PID_EFFECT_BLOCK_INDEX].field->logical_minimum; | ||
736 | pidff->set_effect_type->value[0] = pidff->type_id[PID_SPRING]; | ||
737 | pidff->set_effect[PID_DURATION].value[0] = 0; | ||
738 | pidff->set_effect[PID_TRIGGER_BUTTON].value[0] = 0; | ||
739 | pidff->set_effect[PID_TRIGGER_REPEAT_INT].value[0] = 0; | ||
740 | pidff_set(&pidff->set_effect[PID_GAIN], magnitude); | ||
741 | pidff->set_effect[PID_START_DELAY].value[0] = 0; | ||
742 | |||
743 | usbhid_submit_report(pidff->hid, pidff->reports[PID_SET_EFFECT], | ||
744 | USB_DIR_OUT); | ||
745 | } | ||
746 | |||
747 | /* | ||
748 | * pidff_set_autocenter() handler | ||
749 | */ | ||
750 | static void pidff_set_autocenter(struct input_dev *dev, u16 magnitude) | ||
751 | { | ||
752 | struct pidff_device *pidff = dev->ff->private; | ||
753 | |||
754 | pidff_autocenter(pidff, magnitude); | ||
755 | } | ||
756 | |||
757 | /* | ||
758 | * Find fields from a report and fill a pidff_usage | ||
759 | */ | ||
760 | static int pidff_find_fields(struct pidff_usage *usage, const u8 *table, | ||
761 | struct hid_report *report, int count, int strict) | ||
762 | { | ||
763 | int i, j, k, found; | ||
764 | |||
765 | for (k = 0; k < count; k++) { | ||
766 | found = 0; | ||
767 | for (i = 0; i < report->maxfield; i++) { | ||
768 | if (report->field[i]->maxusage != | ||
769 | report->field[i]->report_count) { | ||
770 | debug("maxusage and report_count do not match, " | ||
771 | "skipping"); | ||
772 | continue; | ||
773 | } | ||
774 | for (j = 0; j < report->field[i]->maxusage; j++) { | ||
775 | if (report->field[i]->usage[j].hid == | ||
776 | (HID_UP_PID | table[k])) { | ||
777 | debug("found %d at %d->%d", k, i, j); | ||
778 | usage[k].field = report->field[i]; | ||
779 | usage[k].value = | ||
780 | &report->field[i]->value[j]; | ||
781 | found = 1; | ||
782 | break; | ||
783 | } | ||
784 | } | ||
785 | if (found) | ||
786 | break; | ||
787 | } | ||
788 | if (!found && strict) { | ||
789 | debug("failed to locate %d", k); | ||
790 | return -1; | ||
791 | } | ||
792 | } | ||
793 | return 0; | ||
794 | } | ||
795 | |||
796 | /* | ||
797 | * Return index into pidff_reports for the given usage | ||
798 | */ | ||
799 | static int pidff_check_usage(int usage) | ||
800 | { | ||
801 | int i; | ||
802 | |||
803 | for (i = 0; i < sizeof(pidff_reports); i++) | ||
804 | if (usage == (HID_UP_PID | pidff_reports[i])) | ||
805 | return i; | ||
806 | |||
807 | return -1; | ||
808 | } | ||
809 | |||
810 | /* | ||
811 | * Find the reports and fill pidff->reports[] | ||
812 | * report_type specifies either OUTPUT or FEATURE reports | ||
813 | */ | ||
814 | static void pidff_find_reports(struct hid_device *hid, int report_type, | ||
815 | struct pidff_device *pidff) | ||
816 | { | ||
817 | struct hid_report *report; | ||
818 | int i, ret; | ||
819 | |||
820 | list_for_each_entry(report, | ||
821 | &hid->report_enum[report_type].report_list, list) { | ||
822 | if (report->maxfield < 1) | ||
823 | continue; | ||
824 | ret = pidff_check_usage(report->field[0]->logical); | ||
825 | if (ret != -1) { | ||
826 | debug("found usage 0x%02x from field->logical", | ||
827 | pidff_reports[ret]); | ||
828 | pidff->reports[ret] = report; | ||
829 | continue; | ||
830 | } | ||
831 | |||
832 | /* | ||
833 | * Sometimes logical collections are stacked to indicate | ||
834 | * different usages for the report and the field, in which | ||
835 | * case we want the usage of the parent. However, Linux HID | ||
836 | * implementation hides this fact, so we have to dig it up | ||
837 | * ourselves | ||
838 | */ | ||
839 | i = report->field[0]->usage[0].collection_index; | ||
840 | if (i <= 0 || | ||
841 | hid->collection[i - 1].type != HID_COLLECTION_LOGICAL) | ||
842 | continue; | ||
843 | ret = pidff_check_usage(hid->collection[i - 1].usage); | ||
844 | if (ret != -1 && !pidff->reports[ret]) { | ||
845 | debug("found usage 0x%02x from collection array", | ||
846 | pidff_reports[ret]); | ||
847 | pidff->reports[ret] = report; | ||
848 | } | ||
849 | } | ||
850 | } | ||
851 | |||
852 | /* | ||
853 | * Test if the required reports have been found | ||
854 | */ | ||
855 | static int pidff_reports_ok(struct pidff_device *pidff) | ||
856 | { | ||
857 | int i; | ||
858 | |||
859 | for (i = 0; i <= PID_REQUIRED_REPORTS; i++) { | ||
860 | if (!pidff->reports[i]) { | ||
861 | debug("%d missing", i); | ||
862 | return 0; | ||
863 | } | ||
864 | } | ||
865 | |||
866 | return 1; | ||
867 | } | ||
868 | |||
869 | /* | ||
870 | * Find a field with a specific usage within a report | ||
871 | */ | ||
872 | static struct hid_field *pidff_find_special_field(struct hid_report *report, | ||
873 | int usage, int enforce_min) | ||
874 | { | ||
875 | int i; | ||
876 | |||
877 | for (i = 0; i < report->maxfield; i++) { | ||
878 | if (report->field[i]->logical == (HID_UP_PID | usage) && | ||
879 | report->field[i]->report_count > 0) { | ||
880 | if (!enforce_min || | ||
881 | report->field[i]->logical_minimum == 1) | ||
882 | return report->field[i]; | ||
883 | else { | ||
884 | printk(KERN_ERR "hid-pidff: logical_minimum " | ||
885 | "is not 1 as it should be\n"); | ||
886 | return NULL; | ||
887 | } | ||
888 | } | ||
889 | } | ||
890 | return NULL; | ||
891 | } | ||
892 | |||
893 | /* | ||
894 | * Fill a pidff->*_id struct table | ||
895 | */ | ||
896 | static int pidff_find_special_keys(int *keys, struct hid_field *fld, | ||
897 | const u8 *usagetable, int count) | ||
898 | { | ||
899 | |||
900 | int i, j; | ||
901 | int found = 0; | ||
902 | |||
903 | for (i = 0; i < count; i++) { | ||
904 | for (j = 0; j < fld->maxusage; j++) { | ||
905 | if (fld->usage[j].hid == (HID_UP_PID | usagetable[i])) { | ||
906 | keys[i] = j + 1; | ||
907 | found++; | ||
908 | break; | ||
909 | } | ||
910 | } | ||
911 | } | ||
912 | return found; | ||
913 | } | ||
914 | |||
915 | #define PIDFF_FIND_SPECIAL_KEYS(keys, field, name) \ | ||
916 | pidff_find_special_keys(pidff->keys, pidff->field, pidff_ ## name, \ | ||
917 | sizeof(pidff_ ## name)) | ||
918 | |||
919 | /* | ||
920 | * Find and check the special fields | ||
921 | */ | ||
922 | static int pidff_find_special_fields(struct pidff_device *pidff) | ||
923 | { | ||
924 | debug("finding special fields"); | ||
925 | |||
926 | pidff->create_new_effect_type = | ||
927 | pidff_find_special_field(pidff->reports[PID_CREATE_NEW_EFFECT], | ||
928 | 0x25, 1); | ||
929 | pidff->set_effect_type = | ||
930 | pidff_find_special_field(pidff->reports[PID_SET_EFFECT], | ||
931 | 0x25, 1); | ||
932 | pidff->effect_direction = | ||
933 | pidff_find_special_field(pidff->reports[PID_SET_EFFECT], | ||
934 | 0x57, 0); | ||
935 | pidff->device_control = | ||
936 | pidff_find_special_field(pidff->reports[PID_DEVICE_CONTROL], | ||
937 | 0x96, 1); | ||
938 | pidff->block_load_status = | ||
939 | pidff_find_special_field(pidff->reports[PID_BLOCK_LOAD], | ||
940 | 0x8b, 1); | ||
941 | pidff->effect_operation_status = | ||
942 | pidff_find_special_field(pidff->reports[PID_EFFECT_OPERATION], | ||
943 | 0x78, 1); | ||
944 | |||
945 | debug("search done"); | ||
946 | |||
947 | if (!pidff->create_new_effect_type || !pidff->set_effect_type) { | ||
948 | printk(KERN_ERR "hid-pidff: effect lists not found\n"); | ||
949 | return -1; | ||
950 | } | ||
951 | |||
952 | if (!pidff->effect_direction) { | ||
953 | printk(KERN_ERR "hid-pidff: direction field not found\n"); | ||
954 | return -1; | ||
955 | } | ||
956 | |||
957 | if (!pidff->device_control) { | ||
958 | printk(KERN_ERR "hid-pidff: device control field not found\n"); | ||
959 | return -1; | ||
960 | } | ||
961 | |||
962 | if (!pidff->block_load_status) { | ||
963 | printk(KERN_ERR | ||
964 | "hid-pidff: block load status field not found\n"); | ||
965 | return -1; | ||
966 | } | ||
967 | |||
968 | if (!pidff->effect_operation_status) { | ||
969 | printk(KERN_ERR | ||
970 | "hid-pidff: effect operation field not found\n"); | ||
971 | return -1; | ||
972 | } | ||
973 | |||
974 | pidff_find_special_keys(pidff->control_id, pidff->device_control, | ||
975 | pidff_device_control, | ||
976 | sizeof(pidff_device_control)); | ||
977 | |||
978 | PIDFF_FIND_SPECIAL_KEYS(control_id, device_control, device_control); | ||
979 | |||
980 | if (!PIDFF_FIND_SPECIAL_KEYS(type_id, create_new_effect_type, | ||
981 | effect_types)) { | ||
982 | printk(KERN_ERR "hid-pidff: no effect types found\n"); | ||
983 | return -1; | ||
984 | } | ||
985 | |||
986 | if (PIDFF_FIND_SPECIAL_KEYS(status_id, block_load_status, | ||
987 | block_load_status) != | ||
988 | sizeof(pidff_block_load_status)) { | ||
989 | printk(KERN_ERR | ||
990 | "hidpidff: block load status identifiers not found\n"); | ||
991 | return -1; | ||
992 | } | ||
993 | |||
994 | if (PIDFF_FIND_SPECIAL_KEYS(operation_id, effect_operation_status, | ||
995 | effect_operation_status) != | ||
996 | sizeof(pidff_effect_operation_status)) { | ||
997 | printk(KERN_ERR | ||
998 | "hidpidff: effect operation identifiers not found\n"); | ||
999 | return -1; | ||
1000 | } | ||
1001 | |||
1002 | return 0; | ||
1003 | } | ||
1004 | |||
1005 | /** | ||
1006 | * Find the implemented effect types | ||
1007 | */ | ||
1008 | static int pidff_find_effects(struct pidff_device *pidff, | ||
1009 | struct input_dev *dev) | ||
1010 | { | ||
1011 | int i; | ||
1012 | |||
1013 | for (i = 0; i < sizeof(pidff_effect_types); i++) { | ||
1014 | int pidff_type = pidff->type_id[i]; | ||
1015 | if (pidff->set_effect_type->usage[pidff_type].hid != | ||
1016 | pidff->create_new_effect_type->usage[pidff_type].hid) { | ||
1017 | printk(KERN_ERR "hid-pidff: " | ||
1018 | "effect type number %d is invalid\n", i); | ||
1019 | return -1; | ||
1020 | } | ||
1021 | } | ||
1022 | |||
1023 | if (pidff->type_id[PID_CONSTANT]) | ||
1024 | set_bit(FF_CONSTANT, dev->ffbit); | ||
1025 | if (pidff->type_id[PID_RAMP]) | ||
1026 | set_bit(FF_RAMP, dev->ffbit); | ||
1027 | if (pidff->type_id[PID_SQUARE]) { | ||
1028 | set_bit(FF_SQUARE, dev->ffbit); | ||
1029 | set_bit(FF_PERIODIC, dev->ffbit); | ||
1030 | } | ||
1031 | if (pidff->type_id[PID_SINE]) { | ||
1032 | set_bit(FF_SINE, dev->ffbit); | ||
1033 | set_bit(FF_PERIODIC, dev->ffbit); | ||
1034 | } | ||
1035 | if (pidff->type_id[PID_TRIANGLE]) { | ||
1036 | set_bit(FF_TRIANGLE, dev->ffbit); | ||
1037 | set_bit(FF_PERIODIC, dev->ffbit); | ||
1038 | } | ||
1039 | if (pidff->type_id[PID_SAW_UP]) { | ||
1040 | set_bit(FF_SAW_UP, dev->ffbit); | ||
1041 | set_bit(FF_PERIODIC, dev->ffbit); | ||
1042 | } | ||
1043 | if (pidff->type_id[PID_SAW_DOWN]) { | ||
1044 | set_bit(FF_SAW_DOWN, dev->ffbit); | ||
1045 | set_bit(FF_PERIODIC, dev->ffbit); | ||
1046 | } | ||
1047 | if (pidff->type_id[PID_SPRING]) | ||
1048 | set_bit(FF_SPRING, dev->ffbit); | ||
1049 | if (pidff->type_id[PID_DAMPER]) | ||
1050 | set_bit(FF_DAMPER, dev->ffbit); | ||
1051 | if (pidff->type_id[PID_INERTIA]) | ||
1052 | set_bit(FF_INERTIA, dev->ffbit); | ||
1053 | if (pidff->type_id[PID_FRICTION]) | ||
1054 | set_bit(FF_FRICTION, dev->ffbit); | ||
1055 | |||
1056 | return 0; | ||
1057 | |||
1058 | } | ||
1059 | |||
1060 | #define PIDFF_FIND_FIELDS(name, report, strict) \ | ||
1061 | pidff_find_fields(pidff->name, pidff_ ## name, \ | ||
1062 | pidff->reports[report], \ | ||
1063 | sizeof(pidff_ ## name), strict) | ||
1064 | |||
1065 | /* | ||
1066 | * Fill and check the pidff_usages | ||
1067 | */ | ||
1068 | static int pidff_init_fields(struct pidff_device *pidff, struct input_dev *dev) | ||
1069 | { | ||
1070 | int envelope_ok = 0; | ||
1071 | |||
1072 | if (PIDFF_FIND_FIELDS(set_effect, PID_SET_EFFECT, 1)) { | ||
1073 | printk(KERN_ERR | ||
1074 | "hid-pidff: unknown set_effect report layout\n"); | ||
1075 | return -ENODEV; | ||
1076 | } | ||
1077 | |||
1078 | PIDFF_FIND_FIELDS(block_load, PID_BLOCK_LOAD, 0); | ||
1079 | if (!pidff->block_load[PID_EFFECT_BLOCK_INDEX].value) { | ||
1080 | printk(KERN_ERR | ||
1081 | "hid-pidff: unknown pid_block_load report layout\n"); | ||
1082 | return -ENODEV; | ||
1083 | } | ||
1084 | |||
1085 | if (PIDFF_FIND_FIELDS(effect_operation, PID_EFFECT_OPERATION, 1)) { | ||
1086 | printk(KERN_ERR | ||
1087 | "hid-pidff: unknown effect_operation report layout\n"); | ||
1088 | return -ENODEV; | ||
1089 | } | ||
1090 | |||
1091 | if (PIDFF_FIND_FIELDS(block_free, PID_BLOCK_FREE, 1)) { | ||
1092 | printk(KERN_ERR | ||
1093 | "hid-pidff: unknown pid_block_free report layout\n"); | ||
1094 | return -ENODEV; | ||
1095 | } | ||
1096 | |||
1097 | if (!PIDFF_FIND_FIELDS(set_envelope, PID_SET_ENVELOPE, 1)) | ||
1098 | envelope_ok = 1; | ||
1099 | |||
1100 | if (pidff_find_special_fields(pidff) || pidff_find_effects(pidff, dev)) | ||
1101 | return -ENODEV; | ||
1102 | |||
1103 | if (!envelope_ok) { | ||
1104 | if (test_and_clear_bit(FF_CONSTANT, dev->ffbit)) | ||
1105 | printk(KERN_WARNING "hid-pidff: " | ||
1106 | "has constant effect but no envelope\n"); | ||
1107 | if (test_and_clear_bit(FF_RAMP, dev->ffbit)) | ||
1108 | printk(KERN_WARNING "hid-pidff: " | ||
1109 | "has ramp effect but no envelope\n"); | ||
1110 | |||
1111 | if (test_and_clear_bit(FF_PERIODIC, dev->ffbit)) | ||
1112 | printk(KERN_WARNING "hid-pidff: " | ||
1113 | "has periodic effect but no envelope\n"); | ||
1114 | } | ||
1115 | |||
1116 | if (test_bit(FF_CONSTANT, dev->ffbit) && | ||
1117 | PIDFF_FIND_FIELDS(set_constant, PID_SET_CONSTANT, 1)) { | ||
1118 | printk(KERN_WARNING | ||
1119 | "hid-pidff: unknown constant effect layout\n"); | ||
1120 | clear_bit(FF_CONSTANT, dev->ffbit); | ||
1121 | } | ||
1122 | |||
1123 | if (test_bit(FF_RAMP, dev->ffbit) && | ||
1124 | PIDFF_FIND_FIELDS(set_ramp, PID_SET_RAMP, 1)) { | ||
1125 | printk(KERN_WARNING "hid-pidff: unknown ramp effect layout\n"); | ||
1126 | clear_bit(FF_RAMP, dev->ffbit); | ||
1127 | } | ||
1128 | |||
1129 | if ((test_bit(FF_SPRING, dev->ffbit) || | ||
1130 | test_bit(FF_DAMPER, dev->ffbit) || | ||
1131 | test_bit(FF_FRICTION, dev->ffbit) || | ||
1132 | test_bit(FF_INERTIA, dev->ffbit)) && | ||
1133 | PIDFF_FIND_FIELDS(set_condition, PID_SET_CONDITION, 1)) { | ||
1134 | printk(KERN_WARNING | ||
1135 | "hid-pidff: unknown condition effect layout\n"); | ||
1136 | clear_bit(FF_SPRING, dev->ffbit); | ||
1137 | clear_bit(FF_DAMPER, dev->ffbit); | ||
1138 | clear_bit(FF_FRICTION, dev->ffbit); | ||
1139 | clear_bit(FF_INERTIA, dev->ffbit); | ||
1140 | } | ||
1141 | |||
1142 | if (test_bit(FF_PERIODIC, dev->ffbit) && | ||
1143 | PIDFF_FIND_FIELDS(set_periodic, PID_SET_PERIODIC, 1)) { | ||
1144 | printk(KERN_WARNING | ||
1145 | "hid-pidff: unknown periodic effect layout\n"); | ||
1146 | clear_bit(FF_PERIODIC, dev->ffbit); | ||
1147 | } | ||
1148 | |||
1149 | PIDFF_FIND_FIELDS(pool, PID_POOL, 0); | ||
1150 | |||
1151 | if (!PIDFF_FIND_FIELDS(device_gain, PID_DEVICE_GAIN, 1)) | ||
1152 | set_bit(FF_GAIN, dev->ffbit); | ||
1153 | |||
1154 | return 0; | ||
1155 | } | ||
1156 | |||
1157 | /* | ||
1158 | * Reset the device | ||
1159 | */ | ||
1160 | static void pidff_reset(struct pidff_device *pidff) | ||
1161 | { | ||
1162 | struct hid_device *hid = pidff->hid; | ||
1163 | int i = 0; | ||
1164 | |||
1165 | pidff->device_control->value[0] = pidff->control_id[PID_RESET]; | ||
1166 | /* We reset twice as sometimes hid_wait_io isn't waiting long enough */ | ||
1167 | usbhid_submit_report(hid, pidff->reports[PID_DEVICE_CONTROL], USB_DIR_OUT); | ||
1168 | usbhid_wait_io(hid); | ||
1169 | usbhid_submit_report(hid, pidff->reports[PID_DEVICE_CONTROL], USB_DIR_OUT); | ||
1170 | usbhid_wait_io(hid); | ||
1171 | |||
1172 | pidff->device_control->value[0] = | ||
1173 | pidff->control_id[PID_ENABLE_ACTUATORS]; | ||
1174 | usbhid_submit_report(hid, pidff->reports[PID_DEVICE_CONTROL], USB_DIR_OUT); | ||
1175 | usbhid_wait_io(hid); | ||
1176 | |||
1177 | /* pool report is sometimes messed up, refetch it */ | ||
1178 | usbhid_submit_report(hid, pidff->reports[PID_POOL], USB_DIR_IN); | ||
1179 | usbhid_wait_io(hid); | ||
1180 | |||
1181 | if (pidff->pool[PID_SIMULTANEOUS_MAX].value) { | ||
1182 | int sim_effects = pidff->pool[PID_SIMULTANEOUS_MAX].value[0]; | ||
1183 | while (sim_effects < 2) { | ||
1184 | if (i++ > 20) { | ||
1185 | printk(KERN_WARNING "hid-pidff: device reports " | ||
1186 | "%d simultaneous effects\n", | ||
1187 | sim_effects); | ||
1188 | break; | ||
1189 | } | ||
1190 | debug("pid_pool requested again"); | ||
1191 | usbhid_submit_report(hid, pidff->reports[PID_POOL], | ||
1192 | USB_DIR_IN); | ||
1193 | usbhid_wait_io(hid); | ||
1194 | } | ||
1195 | } | ||
1196 | } | ||
1197 | |||
1198 | /* | ||
1199 | * Test if autocenter modification is using the supported method | ||
1200 | */ | ||
1201 | static int pidff_check_autocenter(struct pidff_device *pidff, | ||
1202 | struct input_dev *dev) | ||
1203 | { | ||
1204 | int error; | ||
1205 | |||
1206 | /* | ||
1207 | * Let's find out if autocenter modification is supported | ||
1208 | * Specification doesn't specify anything, so we request an | ||
1209 | * effect upload and cancel it immediately. If the approved | ||
1210 | * effect id was one above the minimum, then we assume the first | ||
1211 | * effect id is a built-in spring type effect used for autocenter | ||
1212 | */ | ||
1213 | |||
1214 | error = pidff_request_effect_upload(pidff, 1); | ||
1215 | if (error) { | ||
1216 | printk(KERN_ERR "hid-pidff: upload request failed\n"); | ||
1217 | return error; | ||
1218 | } | ||
1219 | |||
1220 | if (pidff->block_load[PID_EFFECT_BLOCK_INDEX].value[0] == | ||
1221 | pidff->block_load[PID_EFFECT_BLOCK_INDEX].field->logical_minimum + 1) { | ||
1222 | pidff_autocenter(pidff, 0xffff); | ||
1223 | set_bit(FF_AUTOCENTER, dev->ffbit); | ||
1224 | } else { | ||
1225 | printk(KERN_NOTICE "hid-pidff: " | ||
1226 | "device has unknown autocenter control method\n"); | ||
1227 | } | ||
1228 | |||
1229 | pidff_erase_pid(pidff, | ||
1230 | pidff->block_load[PID_EFFECT_BLOCK_INDEX].value[0]); | ||
1231 | |||
1232 | return 0; | ||
1233 | |||
1234 | } | ||
1235 | |||
1236 | /* | ||
1237 | * Check if the device is PID and initialize it | ||
1238 | */ | ||
1239 | int hid_pidff_init(struct hid_device *hid) | ||
1240 | { | ||
1241 | struct pidff_device *pidff; | ||
1242 | struct hid_input *hidinput = list_entry(hid->inputs.next, | ||
1243 | struct hid_input, list); | ||
1244 | struct input_dev *dev = hidinput->input; | ||
1245 | struct ff_device *ff; | ||
1246 | int max_effects; | ||
1247 | int error; | ||
1248 | |||
1249 | debug("starting pid init"); | ||
1250 | |||
1251 | if (list_empty(&hid->report_enum[HID_OUTPUT_REPORT].report_list)) { | ||
1252 | debug("not a PID device, no output report"); | ||
1253 | return -ENODEV; | ||
1254 | } | ||
1255 | |||
1256 | pidff = kzalloc(sizeof(*pidff), GFP_KERNEL); | ||
1257 | if (!pidff) | ||
1258 | return -ENOMEM; | ||
1259 | |||
1260 | pidff->hid = hid; | ||
1261 | |||
1262 | pidff_find_reports(hid, HID_OUTPUT_REPORT, pidff); | ||
1263 | pidff_find_reports(hid, HID_FEATURE_REPORT, pidff); | ||
1264 | |||
1265 | if (!pidff_reports_ok(pidff)) { | ||
1266 | debug("reports not ok, aborting"); | ||
1267 | error = -ENODEV; | ||
1268 | goto fail; | ||
1269 | } | ||
1270 | |||
1271 | error = pidff_init_fields(pidff, dev); | ||
1272 | if (error) | ||
1273 | goto fail; | ||
1274 | |||
1275 | pidff_reset(pidff); | ||
1276 | |||
1277 | if (test_bit(FF_GAIN, dev->ffbit)) { | ||
1278 | pidff_set(&pidff->device_gain[PID_DEVICE_GAIN_FIELD], 0xffff); | ||
1279 | usbhid_submit_report(pidff->hid, pidff->reports[PID_DEVICE_GAIN], | ||
1280 | USB_DIR_OUT); | ||
1281 | } | ||
1282 | |||
1283 | error = pidff_check_autocenter(pidff, dev); | ||
1284 | if (error) | ||
1285 | goto fail; | ||
1286 | |||
1287 | max_effects = | ||
1288 | pidff->block_load[PID_EFFECT_BLOCK_INDEX].field->logical_maximum - | ||
1289 | pidff->block_load[PID_EFFECT_BLOCK_INDEX].field->logical_minimum + | ||
1290 | 1; | ||
1291 | debug("max effects is %d", max_effects); | ||
1292 | |||
1293 | if (max_effects > PID_EFFECTS_MAX) | ||
1294 | max_effects = PID_EFFECTS_MAX; | ||
1295 | |||
1296 | if (pidff->pool[PID_SIMULTANEOUS_MAX].value) | ||
1297 | debug("max simultaneous effects is %d", | ||
1298 | pidff->pool[PID_SIMULTANEOUS_MAX].value[0]); | ||
1299 | |||
1300 | if (pidff->pool[PID_RAM_POOL_SIZE].value) | ||
1301 | debug("device memory size is %d bytes", | ||
1302 | pidff->pool[PID_RAM_POOL_SIZE].value[0]); | ||
1303 | |||
1304 | if (pidff->pool[PID_DEVICE_MANAGED_POOL].value && | ||
1305 | pidff->pool[PID_DEVICE_MANAGED_POOL].value[0] == 0) { | ||
1306 | printk(KERN_NOTICE "hid-pidff: " | ||
1307 | "device does not support device managed pool\n"); | ||
1308 | goto fail; | ||
1309 | } | ||
1310 | |||
1311 | error = input_ff_create(dev, max_effects); | ||
1312 | if (error) | ||
1313 | goto fail; | ||
1314 | |||
1315 | ff = dev->ff; | ||
1316 | ff->private = pidff; | ||
1317 | ff->upload = pidff_upload_effect; | ||
1318 | ff->erase = pidff_erase_effect; | ||
1319 | ff->set_gain = pidff_set_gain; | ||
1320 | ff->set_autocenter = pidff_set_autocenter; | ||
1321 | ff->playback = pidff_playback; | ||
1322 | |||
1323 | printk(KERN_INFO "Force feedback for USB HID PID devices by " | ||
1324 | "Anssi Hannula <anssi.hannula@gmail.com>\n"); | ||
1325 | |||
1326 | return 0; | ||
1327 | |||
1328 | fail: | ||
1329 | kfree(pidff); | ||
1330 | return error; | ||
1331 | } | ||
diff --git a/drivers/usb/input/hid-plff.c b/drivers/usb/input/hid-plff.c deleted file mode 100644 index 76d2e6e14db4..000000000000 --- a/drivers/usb/input/hid-plff.c +++ /dev/null | |||
@@ -1,129 +0,0 @@ | |||
1 | /* | ||
2 | * Force feedback support for PantherLord USB/PS2 2in1 Adapter devices | ||
3 | * | ||
4 | * Copyright (c) 2007 Anssi Hannula <anssi.hannula@gmail.com> | ||
5 | */ | ||
6 | |||
7 | /* | ||
8 | * This program is free software; you can redistribute it and/or modify | ||
9 | * it under the terms of the GNU General Public License as published by | ||
10 | * the Free Software Foundation; either version 2 of the License, or | ||
11 | * (at your option) any later version. | ||
12 | * | ||
13 | * This program is distributed in the hope that it will be useful, | ||
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
16 | * GNU General Public License for more details. | ||
17 | * | ||
18 | * You should have received a copy of the GNU General Public License | ||
19 | * along with this program; if not, write to the Free Software | ||
20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
21 | */ | ||
22 | |||
23 | |||
24 | /* #define DEBUG */ | ||
25 | |||
26 | #define debug(format, arg...) pr_debug("hid-plff: " format "\n" , ## arg) | ||
27 | |||
28 | #include <linux/input.h> | ||
29 | #include <linux/usb.h> | ||
30 | #include <linux/hid.h> | ||
31 | #include "usbhid.h" | ||
32 | |||
33 | struct plff_device { | ||
34 | struct hid_report *report; | ||
35 | }; | ||
36 | |||
37 | static int hid_plff_play(struct input_dev *dev, void *data, | ||
38 | struct ff_effect *effect) | ||
39 | { | ||
40 | struct hid_device *hid = dev->private; | ||
41 | struct plff_device *plff = data; | ||
42 | int left, right; | ||
43 | |||
44 | left = effect->u.rumble.strong_magnitude; | ||
45 | right = effect->u.rumble.weak_magnitude; | ||
46 | debug("called with 0x%04x 0x%04x", left, right); | ||
47 | |||
48 | left = left * 0x7f / 0xffff; | ||
49 | right = right * 0x7f / 0xffff; | ||
50 | |||
51 | plff->report->field[0]->value[2] = left; | ||
52 | plff->report->field[0]->value[3] = right; | ||
53 | debug("running with 0x%02x 0x%02x", left, right); | ||
54 | usbhid_submit_report(hid, plff->report, USB_DIR_OUT); | ||
55 | |||
56 | return 0; | ||
57 | } | ||
58 | |||
59 | int hid_plff_init(struct hid_device *hid) | ||
60 | { | ||
61 | struct plff_device *plff; | ||
62 | struct hid_report *report; | ||
63 | struct hid_input *hidinput; | ||
64 | struct list_head *report_list = | ||
65 | &hid->report_enum[HID_OUTPUT_REPORT].report_list; | ||
66 | struct list_head *report_ptr = report_list; | ||
67 | struct input_dev *dev; | ||
68 | int error; | ||
69 | |||
70 | /* The device contains 2 output reports (one for each | ||
71 | HID_QUIRK_MULTI_INPUT device), both containing 1 field, which | ||
72 | contains 4 ff00.0002 usages and 4 16bit absolute values. | ||
73 | |||
74 | The 2 input reports also contain a field which contains | ||
75 | 8 ff00.0001 usages and 8 boolean values. Their meaning is | ||
76 | currently unknown. */ | ||
77 | |||
78 | if (list_empty(report_list)) { | ||
79 | printk(KERN_ERR "hid-plff: no output reports found\n"); | ||
80 | return -ENODEV; | ||
81 | } | ||
82 | |||
83 | list_for_each_entry(hidinput, &hid->inputs, list) { | ||
84 | |||
85 | report_ptr = report_ptr->next; | ||
86 | |||
87 | if (report_ptr == report_list) { | ||
88 | printk(KERN_ERR "hid-plff: required output report is missing\n"); | ||
89 | return -ENODEV; | ||
90 | } | ||
91 | |||
92 | report = list_entry(report_ptr, struct hid_report, list); | ||
93 | if (report->maxfield < 1) { | ||
94 | printk(KERN_ERR "hid-plff: no fields in the report\n"); | ||
95 | return -ENODEV; | ||
96 | } | ||
97 | |||
98 | if (report->field[0]->report_count < 4) { | ||
99 | printk(KERN_ERR "hid-plff: not enough values in the field\n"); | ||
100 | return -ENODEV; | ||
101 | } | ||
102 | |||
103 | plff = kzalloc(sizeof(struct plff_device), GFP_KERNEL); | ||
104 | if (!plff) | ||
105 | return -ENOMEM; | ||
106 | |||
107 | dev = hidinput->input; | ||
108 | |||
109 | set_bit(FF_RUMBLE, dev->ffbit); | ||
110 | |||
111 | error = input_ff_create_memless(dev, plff, hid_plff_play); | ||
112 | if (error) { | ||
113 | kfree(plff); | ||
114 | return error; | ||
115 | } | ||
116 | |||
117 | plff->report = report; | ||
118 | plff->report->field[0]->value[0] = 0x00; | ||
119 | plff->report->field[0]->value[1] = 0x00; | ||
120 | plff->report->field[0]->value[2] = 0x00; | ||
121 | plff->report->field[0]->value[3] = 0x00; | ||
122 | usbhid_submit_report(hid, plff->report, USB_DIR_OUT); | ||
123 | } | ||
124 | |||
125 | printk(KERN_INFO "hid-plff: Force feedback for PantherLord USB/PS2 " | ||
126 | "2in1 Adapters by Anssi Hannula <anssi.hannula@gmail.com>\n"); | ||
127 | |||
128 | return 0; | ||
129 | } | ||
diff --git a/drivers/usb/input/hid-tmff.c b/drivers/usb/input/hid-tmff.c deleted file mode 100644 index ab67331620d0..000000000000 --- a/drivers/usb/input/hid-tmff.c +++ /dev/null | |||
@@ -1,147 +0,0 @@ | |||
1 | /* | ||
2 | * Force feedback support for various HID compliant devices by ThrustMaster: | ||
3 | * ThrustMaster FireStorm Dual Power 2 | ||
4 | * and possibly others whose device ids haven't been added. | ||
5 | * | ||
6 | * Modified to support ThrustMaster devices by Zinx Verituse | ||
7 | * on 2003-01-25 from the Logitech force feedback driver, | ||
8 | * which is by Johann Deneux. | ||
9 | * | ||
10 | * Copyright (c) 2003 Zinx Verituse <zinx@epicsol.org> | ||
11 | * Copyright (c) 2002 Johann Deneux | ||
12 | */ | ||
13 | |||
14 | /* | ||
15 | * This program is free software; you can redistribute it and/or modify | ||
16 | * it under the terms of the GNU General Public License as published by | ||
17 | * the Free Software Foundation; either version 2 of the License, or | ||
18 | * (at your option) any later version. | ||
19 | * | ||
20 | * This program is distributed in the hope that it will be useful, | ||
21 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
22 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
23 | * GNU General Public License for more details. | ||
24 | * | ||
25 | * You should have received a copy of the GNU General Public License | ||
26 | * along with this program; if not, write to the Free Software | ||
27 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
28 | */ | ||
29 | |||
30 | #include <linux/input.h> | ||
31 | |||
32 | #undef DEBUG | ||
33 | #include <linux/usb.h> | ||
34 | |||
35 | #include <linux/hid.h> | ||
36 | #include "usbhid.h" | ||
37 | |||
38 | /* Usages for thrustmaster devices I know about */ | ||
39 | #define THRUSTMASTER_USAGE_RUMBLE_LR (HID_UP_GENDESK | 0xbb) | ||
40 | |||
41 | |||
42 | struct tmff_device { | ||
43 | struct hid_report *report; | ||
44 | struct hid_field *rumble; | ||
45 | }; | ||
46 | |||
47 | /* Changes values from 0 to 0xffff into values from minimum to maximum */ | ||
48 | static inline int hid_tmff_scale(unsigned int in, int minimum, int maximum) | ||
49 | { | ||
50 | int ret; | ||
51 | |||
52 | ret = (in * (maximum - minimum) / 0xffff) + minimum; | ||
53 | if (ret < minimum) | ||
54 | return minimum; | ||
55 | if (ret > maximum) | ||
56 | return maximum; | ||
57 | return ret; | ||
58 | } | ||
59 | |||
60 | static int hid_tmff_play(struct input_dev *dev, void *data, struct ff_effect *effect) | ||
61 | { | ||
62 | struct hid_device *hid = dev->private; | ||
63 | struct tmff_device *tmff = data; | ||
64 | int left, right; /* Rumbling */ | ||
65 | |||
66 | left = hid_tmff_scale(effect->u.rumble.weak_magnitude, | ||
67 | tmff->rumble->logical_minimum, tmff->rumble->logical_maximum); | ||
68 | right = hid_tmff_scale(effect->u.rumble.strong_magnitude, | ||
69 | tmff->rumble->logical_minimum, tmff->rumble->logical_maximum); | ||
70 | |||
71 | tmff->rumble->value[0] = left; | ||
72 | tmff->rumble->value[1] = right; | ||
73 | dbg("(left,right)=(%08x, %08x)", left, right); | ||
74 | usbhid_submit_report(hid, tmff->report, USB_DIR_OUT); | ||
75 | |||
76 | return 0; | ||
77 | } | ||
78 | |||
79 | int hid_tmff_init(struct hid_device *hid) | ||
80 | { | ||
81 | struct tmff_device *tmff; | ||
82 | struct list_head *pos; | ||
83 | struct hid_input *hidinput = list_entry(hid->inputs.next, struct hid_input, list); | ||
84 | struct input_dev *input_dev = hidinput->input; | ||
85 | int error; | ||
86 | |||
87 | tmff = kzalloc(sizeof(struct tmff_device), GFP_KERNEL); | ||
88 | if (!tmff) | ||
89 | return -ENOMEM; | ||
90 | |||
91 | /* Find the report to use */ | ||
92 | __list_for_each(pos, &hid->report_enum[HID_OUTPUT_REPORT].report_list) { | ||
93 | struct hid_report *report = (struct hid_report *)pos; | ||
94 | int fieldnum; | ||
95 | |||
96 | for (fieldnum = 0; fieldnum < report->maxfield; ++fieldnum) { | ||
97 | struct hid_field *field = report->field[fieldnum]; | ||
98 | |||
99 | if (field->maxusage <= 0) | ||
100 | continue; | ||
101 | |||
102 | switch (field->usage[0].hid) { | ||
103 | case THRUSTMASTER_USAGE_RUMBLE_LR: | ||
104 | if (field->report_count < 2) { | ||
105 | warn("ignoring THRUSTMASTER_USAGE_RUMBLE_LR with report_count < 2"); | ||
106 | continue; | ||
107 | } | ||
108 | |||
109 | if (field->logical_maximum == field->logical_minimum) { | ||
110 | warn("ignoring THRUSTMASTER_USAGE_RUMBLE_LR with logical_maximum == logical_minimum"); | ||
111 | continue; | ||
112 | } | ||
113 | |||
114 | if (tmff->report && tmff->report != report) { | ||
115 | warn("ignoring THRUSTMASTER_USAGE_RUMBLE_LR in other report"); | ||
116 | continue; | ||
117 | } | ||
118 | |||
119 | if (tmff->rumble && tmff->rumble != field) { | ||
120 | warn("ignoring duplicate THRUSTMASTER_USAGE_RUMBLE_LR"); | ||
121 | continue; | ||
122 | } | ||
123 | |||
124 | tmff->report = report; | ||
125 | tmff->rumble = field; | ||
126 | |||
127 | set_bit(FF_RUMBLE, input_dev->ffbit); | ||
128 | break; | ||
129 | |||
130 | default: | ||
131 | warn("ignoring unknown output usage %08x", field->usage[0].hid); | ||
132 | continue; | ||
133 | } | ||
134 | } | ||
135 | } | ||
136 | |||
137 | error = input_ff_create_memless(input_dev, tmff, hid_tmff_play); | ||
138 | if (error) { | ||
139 | kfree(tmff); | ||
140 | return error; | ||
141 | } | ||
142 | |||
143 | info("Force feedback for ThrustMaster rumble pad devices by Zinx Verituse <zinx@epicsol.org>"); | ||
144 | |||
145 | return 0; | ||
146 | } | ||
147 | |||
diff --git a/drivers/usb/input/hid-zpff.c b/drivers/usb/input/hid-zpff.c deleted file mode 100644 index 7bd8238ca212..000000000000 --- a/drivers/usb/input/hid-zpff.c +++ /dev/null | |||
@@ -1,111 +0,0 @@ | |||
1 | /* | ||
2 | * Force feedback support for Zeroplus based devices | ||
3 | * | ||
4 | * Copyright (c) 2005, 2006 Anssi Hannula <anssi.hannula@gmail.com> | ||
5 | */ | ||
6 | |||
7 | /* | ||
8 | * This program is free software; you can redistribute it and/or modify | ||
9 | * it under the terms of the GNU General Public License as published by | ||
10 | * the Free Software Foundation; either version 2 of the License, or | ||
11 | * (at your option) any later version. | ||
12 | * | ||
13 | * This program is distributed in the hope that it will be useful, | ||
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
16 | * GNU General Public License for more details. | ||
17 | * | ||
18 | * You should have received a copy of the GNU General Public License | ||
19 | * along with this program; if not, write to the Free Software | ||
20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
21 | */ | ||
22 | |||
23 | |||
24 | /* #define DEBUG */ | ||
25 | |||
26 | #define debug(format, arg...) pr_debug("hid-zpff: " format "\n" , ## arg) | ||
27 | |||
28 | #include <linux/input.h> | ||
29 | #include <linux/usb.h> | ||
30 | #include <linux/hid.h> | ||
31 | #include "usbhid.h" | ||
32 | |||
33 | struct zpff_device { | ||
34 | struct hid_report *report; | ||
35 | }; | ||
36 | |||
37 | static int hid_zpff_play(struct input_dev *dev, void *data, | ||
38 | struct ff_effect *effect) | ||
39 | { | ||
40 | struct hid_device *hid = dev->private; | ||
41 | struct zpff_device *zpff = data; | ||
42 | int left, right; | ||
43 | |||
44 | /* | ||
45 | * The following is specified the other way around in the Zeroplus | ||
46 | * datasheet but the order below is correct for the XFX Executioner; | ||
47 | * however it is possible that the XFX Executioner is an exception | ||
48 | */ | ||
49 | |||
50 | left = effect->u.rumble.strong_magnitude; | ||
51 | right = effect->u.rumble.weak_magnitude; | ||
52 | debug("called with 0x%04x 0x%04x", left, right); | ||
53 | |||
54 | left = left * 0x7f / 0xffff; | ||
55 | right = right * 0x7f / 0xffff; | ||
56 | |||
57 | zpff->report->field[2]->value[0] = left; | ||
58 | zpff->report->field[3]->value[0] = right; | ||
59 | debug("running with 0x%02x 0x%02x", left, right); | ||
60 | usbhid_submit_report(hid, zpff->report, USB_DIR_OUT); | ||
61 | |||
62 | return 0; | ||
63 | } | ||
64 | |||
65 | int hid_zpff_init(struct hid_device *hid) | ||
66 | { | ||
67 | struct zpff_device *zpff; | ||
68 | struct hid_report *report; | ||
69 | struct hid_input *hidinput = list_entry(hid->inputs.next, | ||
70 | struct hid_input, list); | ||
71 | struct list_head *report_list = | ||
72 | &hid->report_enum[HID_OUTPUT_REPORT].report_list; | ||
73 | struct input_dev *dev = hidinput->input; | ||
74 | int error; | ||
75 | |||
76 | if (list_empty(report_list)) { | ||
77 | printk(KERN_ERR "hid-zpff: no output report found\n"); | ||
78 | return -ENODEV; | ||
79 | } | ||
80 | |||
81 | report = list_entry(report_list->next, struct hid_report, list); | ||
82 | |||
83 | if (report->maxfield < 4) { | ||
84 | printk(KERN_ERR "hid-zpff: not enough fields in report\n"); | ||
85 | return -ENODEV; | ||
86 | } | ||
87 | |||
88 | zpff = kzalloc(sizeof(struct zpff_device), GFP_KERNEL); | ||
89 | if (!zpff) | ||
90 | return -ENOMEM; | ||
91 | |||
92 | set_bit(FF_RUMBLE, dev->ffbit); | ||
93 | |||
94 | error = input_ff_create_memless(dev, zpff, hid_zpff_play); | ||
95 | if (error) { | ||
96 | kfree(zpff); | ||
97 | return error; | ||
98 | } | ||
99 | |||
100 | zpff->report = report; | ||
101 | zpff->report->field[0]->value[0] = 0x00; | ||
102 | zpff->report->field[1]->value[0] = 0x02; | ||
103 | zpff->report->field[2]->value[0] = 0x00; | ||
104 | zpff->report->field[3]->value[0] = 0x00; | ||
105 | usbhid_submit_report(hid, zpff->report, USB_DIR_OUT); | ||
106 | |||
107 | printk(KERN_INFO "Force feedback for Zeroplus based devices by " | ||
108 | "Anssi Hannula <anssi.hannula@gmail.com>\n"); | ||
109 | |||
110 | return 0; | ||
111 | } | ||
diff --git a/drivers/usb/input/hiddev.c b/drivers/usb/input/hiddev.c deleted file mode 100644 index a8b3d66cd498..000000000000 --- a/drivers/usb/input/hiddev.c +++ /dev/null | |||
@@ -1,847 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (c) 2001 Paul Stewart | ||
3 | * Copyright (c) 2001 Vojtech Pavlik | ||
4 | * | ||
5 | * HID char devices, giving access to raw HID device events. | ||
6 | * | ||
7 | */ | ||
8 | |||
9 | /* | ||
10 | * This program is free software; you can redistribute it and/or modify | ||
11 | * it under the terms of the GNU General Public License as published by | ||
12 | * the Free Software Foundation; either version 2 of the License, or | ||
13 | * (at your option) any later version. | ||
14 | * | ||
15 | * This program is distributed in the hope that it will be useful, | ||
16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
18 | * GNU General Public License for more details. | ||
19 | * | ||
20 | * You should have received a copy of the GNU General Public License | ||
21 | * along with this program; if not, write to the Free Software | ||
22 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
23 | * | ||
24 | * Should you need to contact me, the author, you can do so either by | ||
25 | * e-mail - mail your message to Paul Stewart <stewart@wetlogic.net> | ||
26 | */ | ||
27 | |||
28 | #include <linux/poll.h> | ||
29 | #include <linux/slab.h> | ||
30 | #include <linux/module.h> | ||
31 | #include <linux/init.h> | ||
32 | #include <linux/smp_lock.h> | ||
33 | #include <linux/input.h> | ||
34 | #include <linux/usb.h> | ||
35 | #include <linux/hid.h> | ||
36 | #include <linux/hiddev.h> | ||
37 | #include "usbhid.h" | ||
38 | |||
39 | #ifdef CONFIG_USB_DYNAMIC_MINORS | ||
40 | #define HIDDEV_MINOR_BASE 0 | ||
41 | #define HIDDEV_MINORS 256 | ||
42 | #else | ||
43 | #define HIDDEV_MINOR_BASE 96 | ||
44 | #define HIDDEV_MINORS 16 | ||
45 | #endif | ||
46 | #define HIDDEV_BUFFER_SIZE 64 | ||
47 | |||
48 | struct hiddev { | ||
49 | int exist; | ||
50 | int open; | ||
51 | wait_queue_head_t wait; | ||
52 | struct hid_device *hid; | ||
53 | struct list_head list; | ||
54 | }; | ||
55 | |||
56 | struct hiddev_list { | ||
57 | struct hiddev_usage_ref buffer[HIDDEV_BUFFER_SIZE]; | ||
58 | int head; | ||
59 | int tail; | ||
60 | unsigned flags; | ||
61 | struct fasync_struct *fasync; | ||
62 | struct hiddev *hiddev; | ||
63 | struct list_head node; | ||
64 | }; | ||
65 | |||
66 | static struct hiddev *hiddev_table[HIDDEV_MINORS]; | ||
67 | |||
68 | /* | ||
69 | * Find a report, given the report's type and ID. The ID can be specified | ||
70 | * indirectly by REPORT_ID_FIRST (which returns the first report of the given | ||
71 | * type) or by (REPORT_ID_NEXT | old_id), which returns the next report of the | ||
72 | * given type which follows old_id. | ||
73 | */ | ||
74 | static struct hid_report * | ||
75 | hiddev_lookup_report(struct hid_device *hid, struct hiddev_report_info *rinfo) | ||
76 | { | ||
77 | unsigned int flags = rinfo->report_id & ~HID_REPORT_ID_MASK; | ||
78 | unsigned int rid = rinfo->report_id & HID_REPORT_ID_MASK; | ||
79 | struct hid_report_enum *report_enum; | ||
80 | struct hid_report *report; | ||
81 | struct list_head *list; | ||
82 | |||
83 | if (rinfo->report_type < HID_REPORT_TYPE_MIN || | ||
84 | rinfo->report_type > HID_REPORT_TYPE_MAX) | ||
85 | return NULL; | ||
86 | |||
87 | report_enum = hid->report_enum + | ||
88 | (rinfo->report_type - HID_REPORT_TYPE_MIN); | ||
89 | |||
90 | switch (flags) { | ||
91 | case 0: /* Nothing to do -- report_id is already set correctly */ | ||
92 | break; | ||
93 | |||
94 | case HID_REPORT_ID_FIRST: | ||
95 | if (list_empty(&report_enum->report_list)) | ||
96 | return NULL; | ||
97 | |||
98 | list = report_enum->report_list.next; | ||
99 | report = list_entry(list, struct hid_report, list); | ||
100 | rinfo->report_id = report->id; | ||
101 | break; | ||
102 | |||
103 | case HID_REPORT_ID_NEXT: | ||
104 | report = report_enum->report_id_hash[rid]; | ||
105 | if (!report) | ||
106 | return NULL; | ||
107 | |||
108 | list = report->list.next; | ||
109 | if (list == &report_enum->report_list) | ||
110 | return NULL; | ||
111 | |||
112 | report = list_entry(list, struct hid_report, list); | ||
113 | rinfo->report_id = report->id; | ||
114 | break; | ||
115 | |||
116 | default: | ||
117 | return NULL; | ||
118 | } | ||
119 | |||
120 | return report_enum->report_id_hash[rinfo->report_id]; | ||
121 | } | ||
122 | |||
123 | /* | ||
124 | * Perform an exhaustive search of the report table for a usage, given its | ||
125 | * type and usage id. | ||
126 | */ | ||
127 | static struct hid_field * | ||
128 | hiddev_lookup_usage(struct hid_device *hid, struct hiddev_usage_ref *uref) | ||
129 | { | ||
130 | int i, j; | ||
131 | struct hid_report *report; | ||
132 | struct hid_report_enum *report_enum; | ||
133 | struct hid_field *field; | ||
134 | |||
135 | if (uref->report_type < HID_REPORT_TYPE_MIN || | ||
136 | uref->report_type > HID_REPORT_TYPE_MAX) | ||
137 | return NULL; | ||
138 | |||
139 | report_enum = hid->report_enum + | ||
140 | (uref->report_type - HID_REPORT_TYPE_MIN); | ||
141 | |||
142 | list_for_each_entry(report, &report_enum->report_list, list) { | ||
143 | for (i = 0; i < report->maxfield; i++) { | ||
144 | field = report->field[i]; | ||
145 | for (j = 0; j < field->maxusage; j++) { | ||
146 | if (field->usage[j].hid == uref->usage_code) { | ||
147 | uref->report_id = report->id; | ||
148 | uref->field_index = i; | ||
149 | uref->usage_index = j; | ||
150 | return field; | ||
151 | } | ||
152 | } | ||
153 | } | ||
154 | } | ||
155 | |||
156 | return NULL; | ||
157 | } | ||
158 | |||
159 | static void hiddev_send_event(struct hid_device *hid, | ||
160 | struct hiddev_usage_ref *uref) | ||
161 | { | ||
162 | struct hiddev *hiddev = hid->hiddev; | ||
163 | struct hiddev_list *list; | ||
164 | |||
165 | list_for_each_entry(list, &hiddev->list, node) { | ||
166 | if (uref->field_index != HID_FIELD_INDEX_NONE || | ||
167 | (list->flags & HIDDEV_FLAG_REPORT) != 0) { | ||
168 | list->buffer[list->head] = *uref; | ||
169 | list->head = (list->head + 1) & | ||
170 | (HIDDEV_BUFFER_SIZE - 1); | ||
171 | kill_fasync(&list->fasync, SIGIO, POLL_IN); | ||
172 | } | ||
173 | } | ||
174 | |||
175 | wake_up_interruptible(&hiddev->wait); | ||
176 | } | ||
177 | |||
178 | /* | ||
179 | * This is where hid.c calls into hiddev to pass an event that occurred over | ||
180 | * the interrupt pipe | ||
181 | */ | ||
182 | void hiddev_hid_event(struct hid_device *hid, struct hid_field *field, | ||
183 | struct hid_usage *usage, __s32 value) | ||
184 | { | ||
185 | unsigned type = field->report_type; | ||
186 | struct hiddev_usage_ref uref; | ||
187 | |||
188 | uref.report_type = | ||
189 | (type == HID_INPUT_REPORT) ? HID_REPORT_TYPE_INPUT : | ||
190 | ((type == HID_OUTPUT_REPORT) ? HID_REPORT_TYPE_OUTPUT : | ||
191 | ((type == HID_FEATURE_REPORT) ? HID_REPORT_TYPE_FEATURE : 0)); | ||
192 | uref.report_id = field->report->id; | ||
193 | uref.field_index = field->index; | ||
194 | uref.usage_index = (usage - field->usage); | ||
195 | uref.usage_code = usage->hid; | ||
196 | uref.value = value; | ||
197 | |||
198 | hiddev_send_event(hid, &uref); | ||
199 | } | ||
200 | EXPORT_SYMBOL_GPL(hiddev_hid_event); | ||
201 | |||
202 | void hiddev_report_event(struct hid_device *hid, struct hid_report *report) | ||
203 | { | ||
204 | unsigned type = report->type; | ||
205 | struct hiddev_usage_ref uref; | ||
206 | |||
207 | memset(&uref, 0, sizeof(uref)); | ||
208 | uref.report_type = | ||
209 | (type == HID_INPUT_REPORT) ? HID_REPORT_TYPE_INPUT : | ||
210 | ((type == HID_OUTPUT_REPORT) ? HID_REPORT_TYPE_OUTPUT : | ||
211 | ((type == HID_FEATURE_REPORT) ? HID_REPORT_TYPE_FEATURE : 0)); | ||
212 | uref.report_id = report->id; | ||
213 | uref.field_index = HID_FIELD_INDEX_NONE; | ||
214 | |||
215 | hiddev_send_event(hid, &uref); | ||
216 | } | ||
217 | |||
218 | /* | ||
219 | * fasync file op | ||
220 | */ | ||
221 | static int hiddev_fasync(int fd, struct file *file, int on) | ||
222 | { | ||
223 | int retval; | ||
224 | struct hiddev_list *list = file->private_data; | ||
225 | |||
226 | retval = fasync_helper(fd, file, on, &list->fasync); | ||
227 | |||
228 | return retval < 0 ? retval : 0; | ||
229 | } | ||
230 | |||
231 | |||
232 | /* | ||
233 | * release file op | ||
234 | */ | ||
235 | static int hiddev_release(struct inode * inode, struct file * file) | ||
236 | { | ||
237 | struct hiddev_list *list = file->private_data; | ||
238 | |||
239 | hiddev_fasync(-1, file, 0); | ||
240 | list_del(&list->node); | ||
241 | |||
242 | if (!--list->hiddev->open) { | ||
243 | if (list->hiddev->exist) | ||
244 | usbhid_close(list->hiddev->hid); | ||
245 | else | ||
246 | kfree(list->hiddev); | ||
247 | } | ||
248 | |||
249 | kfree(list); | ||
250 | |||
251 | return 0; | ||
252 | } | ||
253 | |||
254 | /* | ||
255 | * open file op | ||
256 | */ | ||
257 | static int hiddev_open(struct inode *inode, struct file *file) | ||
258 | { | ||
259 | struct hiddev_list *list; | ||
260 | |||
261 | int i = iminor(inode) - HIDDEV_MINOR_BASE; | ||
262 | |||
263 | if (i >= HIDDEV_MINORS || !hiddev_table[i]) | ||
264 | return -ENODEV; | ||
265 | |||
266 | if (!(list = kzalloc(sizeof(struct hiddev_list), GFP_KERNEL))) | ||
267 | return -ENOMEM; | ||
268 | |||
269 | list->hiddev = hiddev_table[i]; | ||
270 | list_add_tail(&list->node, &hiddev_table[i]->list); | ||
271 | file->private_data = list; | ||
272 | |||
273 | if (!list->hiddev->open++) | ||
274 | if (list->hiddev->exist) | ||
275 | usbhid_open(hiddev_table[i]->hid); | ||
276 | |||
277 | return 0; | ||
278 | } | ||
279 | |||
280 | /* | ||
281 | * "write" file op | ||
282 | */ | ||
283 | static ssize_t hiddev_write(struct file * file, const char __user * buffer, size_t count, loff_t *ppos) | ||
284 | { | ||
285 | return -EINVAL; | ||
286 | } | ||
287 | |||
288 | /* | ||
289 | * "read" file op | ||
290 | */ | ||
291 | static ssize_t hiddev_read(struct file * file, char __user * buffer, size_t count, loff_t *ppos) | ||
292 | { | ||
293 | DECLARE_WAITQUEUE(wait, current); | ||
294 | struct hiddev_list *list = file->private_data; | ||
295 | int event_size; | ||
296 | int retval = 0; | ||
297 | |||
298 | event_size = ((list->flags & HIDDEV_FLAG_UREF) != 0) ? | ||
299 | sizeof(struct hiddev_usage_ref) : sizeof(struct hiddev_event); | ||
300 | |||
301 | if (count < event_size) | ||
302 | return 0; | ||
303 | |||
304 | while (retval == 0) { | ||
305 | if (list->head == list->tail) { | ||
306 | add_wait_queue(&list->hiddev->wait, &wait); | ||
307 | set_current_state(TASK_INTERRUPTIBLE); | ||
308 | |||
309 | while (list->head == list->tail) { | ||
310 | if (file->f_flags & O_NONBLOCK) { | ||
311 | retval = -EAGAIN; | ||
312 | break; | ||
313 | } | ||
314 | if (signal_pending(current)) { | ||
315 | retval = -ERESTARTSYS; | ||
316 | break; | ||
317 | } | ||
318 | if (!list->hiddev->exist) { | ||
319 | retval = -EIO; | ||
320 | break; | ||
321 | } | ||
322 | |||
323 | schedule(); | ||
324 | set_current_state(TASK_INTERRUPTIBLE); | ||
325 | } | ||
326 | |||
327 | set_current_state(TASK_RUNNING); | ||
328 | remove_wait_queue(&list->hiddev->wait, &wait); | ||
329 | } | ||
330 | |||
331 | if (retval) | ||
332 | return retval; | ||
333 | |||
334 | |||
335 | while (list->head != list->tail && | ||
336 | retval + event_size <= count) { | ||
337 | if ((list->flags & HIDDEV_FLAG_UREF) == 0) { | ||
338 | if (list->buffer[list->tail].field_index != | ||
339 | HID_FIELD_INDEX_NONE) { | ||
340 | struct hiddev_event event; | ||
341 | event.hid = list->buffer[list->tail].usage_code; | ||
342 | event.value = list->buffer[list->tail].value; | ||
343 | if (copy_to_user(buffer + retval, &event, sizeof(struct hiddev_event))) | ||
344 | return -EFAULT; | ||
345 | retval += sizeof(struct hiddev_event); | ||
346 | } | ||
347 | } else { | ||
348 | if (list->buffer[list->tail].field_index != HID_FIELD_INDEX_NONE || | ||
349 | (list->flags & HIDDEV_FLAG_REPORT) != 0) { | ||
350 | if (copy_to_user(buffer + retval, list->buffer + list->tail, sizeof(struct hiddev_usage_ref))) | ||
351 | return -EFAULT; | ||
352 | retval += sizeof(struct hiddev_usage_ref); | ||
353 | } | ||
354 | } | ||
355 | list->tail = (list->tail + 1) & (HIDDEV_BUFFER_SIZE - 1); | ||
356 | } | ||
357 | |||
358 | } | ||
359 | |||
360 | return retval; | ||
361 | } | ||
362 | |||
363 | /* | ||
364 | * "poll" file op | ||
365 | * No kernel lock - fine | ||
366 | */ | ||
367 | static unsigned int hiddev_poll(struct file *file, poll_table *wait) | ||
368 | { | ||
369 | struct hiddev_list *list = file->private_data; | ||
370 | |||
371 | poll_wait(file, &list->hiddev->wait, wait); | ||
372 | if (list->head != list->tail) | ||
373 | return POLLIN | POLLRDNORM; | ||
374 | if (!list->hiddev->exist) | ||
375 | return POLLERR | POLLHUP; | ||
376 | return 0; | ||
377 | } | ||
378 | |||
379 | /* | ||
380 | * "ioctl" file op | ||
381 | */ | ||
382 | static int hiddev_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg) | ||
383 | { | ||
384 | struct hiddev_list *list = file->private_data; | ||
385 | struct hiddev *hiddev = list->hiddev; | ||
386 | struct hid_device *hid = hiddev->hid; | ||
387 | struct usb_device *dev = hid_to_usb_dev(hid); | ||
388 | struct hiddev_collection_info cinfo; | ||
389 | struct hiddev_report_info rinfo; | ||
390 | struct hiddev_field_info finfo; | ||
391 | struct hiddev_usage_ref_multi *uref_multi = NULL; | ||
392 | struct hiddev_usage_ref *uref; | ||
393 | struct hiddev_devinfo dinfo; | ||
394 | struct hid_report *report; | ||
395 | struct hid_field *field; | ||
396 | struct usbhid_device *usbhid = hid->driver_data; | ||
397 | void __user *user_arg = (void __user *)arg; | ||
398 | int i; | ||
399 | |||
400 | if (!hiddev->exist) | ||
401 | return -EIO; | ||
402 | |||
403 | switch (cmd) { | ||
404 | |||
405 | case HIDIOCGVERSION: | ||
406 | return put_user(HID_VERSION, (int __user *)arg); | ||
407 | |||
408 | case HIDIOCAPPLICATION: | ||
409 | if (arg < 0 || arg >= hid->maxapplication) | ||
410 | return -EINVAL; | ||
411 | |||
412 | for (i = 0; i < hid->maxcollection; i++) | ||
413 | if (hid->collection[i].type == | ||
414 | HID_COLLECTION_APPLICATION && arg-- == 0) | ||
415 | break; | ||
416 | |||
417 | if (i == hid->maxcollection) | ||
418 | return -EINVAL; | ||
419 | |||
420 | return hid->collection[i].usage; | ||
421 | |||
422 | case HIDIOCGDEVINFO: | ||
423 | dinfo.bustype = BUS_USB; | ||
424 | dinfo.busnum = dev->bus->busnum; | ||
425 | dinfo.devnum = dev->devnum; | ||
426 | dinfo.ifnum = usbhid->ifnum; | ||
427 | dinfo.vendor = le16_to_cpu(dev->descriptor.idVendor); | ||
428 | dinfo.product = le16_to_cpu(dev->descriptor.idProduct); | ||
429 | dinfo.version = le16_to_cpu(dev->descriptor.bcdDevice); | ||
430 | dinfo.num_applications = hid->maxapplication; | ||
431 | if (copy_to_user(user_arg, &dinfo, sizeof(dinfo))) | ||
432 | return -EFAULT; | ||
433 | |||
434 | return 0; | ||
435 | |||
436 | case HIDIOCGFLAG: | ||
437 | if (put_user(list->flags, (int __user *)arg)) | ||
438 | return -EFAULT; | ||
439 | |||
440 | return 0; | ||
441 | |||
442 | case HIDIOCSFLAG: | ||
443 | { | ||
444 | int newflags; | ||
445 | if (get_user(newflags, (int __user *)arg)) | ||
446 | return -EFAULT; | ||
447 | |||
448 | if ((newflags & ~HIDDEV_FLAGS) != 0 || | ||
449 | ((newflags & HIDDEV_FLAG_REPORT) != 0 && | ||
450 | (newflags & HIDDEV_FLAG_UREF) == 0)) | ||
451 | return -EINVAL; | ||
452 | |||
453 | list->flags = newflags; | ||
454 | |||
455 | return 0; | ||
456 | } | ||
457 | |||
458 | case HIDIOCGSTRING: | ||
459 | { | ||
460 | int idx, len; | ||
461 | char *buf; | ||
462 | |||
463 | if (get_user(idx, (int __user *)arg)) | ||
464 | return -EFAULT; | ||
465 | |||
466 | if ((buf = kmalloc(HID_STRING_SIZE, GFP_KERNEL)) == NULL) | ||
467 | return -ENOMEM; | ||
468 | |||
469 | if ((len = usb_string(dev, idx, buf, HID_STRING_SIZE-1)) < 0) { | ||
470 | kfree(buf); | ||
471 | return -EINVAL; | ||
472 | } | ||
473 | |||
474 | if (copy_to_user(user_arg+sizeof(int), buf, len+1)) { | ||
475 | kfree(buf); | ||
476 | return -EFAULT; | ||
477 | } | ||
478 | |||
479 | kfree(buf); | ||
480 | |||
481 | return len; | ||
482 | } | ||
483 | |||
484 | case HIDIOCINITREPORT: | ||
485 | usbhid_init_reports(hid); | ||
486 | |||
487 | return 0; | ||
488 | |||
489 | case HIDIOCGREPORT: | ||
490 | if (copy_from_user(&rinfo, user_arg, sizeof(rinfo))) | ||
491 | return -EFAULT; | ||
492 | |||
493 | if (rinfo.report_type == HID_REPORT_TYPE_OUTPUT) | ||
494 | return -EINVAL; | ||
495 | |||
496 | if ((report = hiddev_lookup_report(hid, &rinfo)) == NULL) | ||
497 | return -EINVAL; | ||
498 | |||
499 | usbhid_submit_report(hid, report, USB_DIR_IN); | ||
500 | usbhid_wait_io(hid); | ||
501 | |||
502 | return 0; | ||
503 | |||
504 | case HIDIOCSREPORT: | ||
505 | if (copy_from_user(&rinfo, user_arg, sizeof(rinfo))) | ||
506 | return -EFAULT; | ||
507 | |||
508 | if (rinfo.report_type == HID_REPORT_TYPE_INPUT) | ||
509 | return -EINVAL; | ||
510 | |||
511 | if ((report = hiddev_lookup_report(hid, &rinfo)) == NULL) | ||
512 | return -EINVAL; | ||
513 | |||
514 | usbhid_submit_report(hid, report, USB_DIR_OUT); | ||
515 | usbhid_wait_io(hid); | ||
516 | |||
517 | return 0; | ||
518 | |||
519 | case HIDIOCGREPORTINFO: | ||
520 | if (copy_from_user(&rinfo, user_arg, sizeof(rinfo))) | ||
521 | return -EFAULT; | ||
522 | |||
523 | if ((report = hiddev_lookup_report(hid, &rinfo)) == NULL) | ||
524 | return -EINVAL; | ||
525 | |||
526 | rinfo.num_fields = report->maxfield; | ||
527 | |||
528 | if (copy_to_user(user_arg, &rinfo, sizeof(rinfo))) | ||
529 | return -EFAULT; | ||
530 | |||
531 | return 0; | ||
532 | |||
533 | case HIDIOCGFIELDINFO: | ||
534 | if (copy_from_user(&finfo, user_arg, sizeof(finfo))) | ||
535 | return -EFAULT; | ||
536 | rinfo.report_type = finfo.report_type; | ||
537 | rinfo.report_id = finfo.report_id; | ||
538 | if ((report = hiddev_lookup_report(hid, &rinfo)) == NULL) | ||
539 | return -EINVAL; | ||
540 | |||
541 | if (finfo.field_index >= report->maxfield) | ||
542 | return -EINVAL; | ||
543 | |||
544 | field = report->field[finfo.field_index]; | ||
545 | memset(&finfo, 0, sizeof(finfo)); | ||
546 | finfo.report_type = rinfo.report_type; | ||
547 | finfo.report_id = rinfo.report_id; | ||
548 | finfo.field_index = field->report_count - 1; | ||
549 | finfo.maxusage = field->maxusage; | ||
550 | finfo.flags = field->flags; | ||
551 | finfo.physical = field->physical; | ||
552 | finfo.logical = field->logical; | ||
553 | finfo.application = field->application; | ||
554 | finfo.logical_minimum = field->logical_minimum; | ||
555 | finfo.logical_maximum = field->logical_maximum; | ||
556 | finfo.physical_minimum = field->physical_minimum; | ||
557 | finfo.physical_maximum = field->physical_maximum; | ||
558 | finfo.unit_exponent = field->unit_exponent; | ||
559 | finfo.unit = field->unit; | ||
560 | |||
561 | if (copy_to_user(user_arg, &finfo, sizeof(finfo))) | ||
562 | return -EFAULT; | ||
563 | |||
564 | return 0; | ||
565 | |||
566 | case HIDIOCGUCODE: | ||
567 | uref_multi = kmalloc(sizeof(struct hiddev_usage_ref_multi), GFP_KERNEL); | ||
568 | if (!uref_multi) | ||
569 | return -ENOMEM; | ||
570 | uref = &uref_multi->uref; | ||
571 | if (copy_from_user(uref, user_arg, sizeof(*uref))) | ||
572 | goto fault; | ||
573 | |||
574 | rinfo.report_type = uref->report_type; | ||
575 | rinfo.report_id = uref->report_id; | ||
576 | if ((report = hiddev_lookup_report(hid, &rinfo)) == NULL) | ||
577 | goto inval; | ||
578 | |||
579 | if (uref->field_index >= report->maxfield) | ||
580 | goto inval; | ||
581 | |||
582 | field = report->field[uref->field_index]; | ||
583 | if (uref->usage_index >= field->maxusage) | ||
584 | goto inval; | ||
585 | |||
586 | uref->usage_code = field->usage[uref->usage_index].hid; | ||
587 | |||
588 | if (copy_to_user(user_arg, uref, sizeof(*uref))) | ||
589 | goto fault; | ||
590 | |||
591 | kfree(uref_multi); | ||
592 | return 0; | ||
593 | |||
594 | case HIDIOCGUSAGE: | ||
595 | case HIDIOCSUSAGE: | ||
596 | case HIDIOCGUSAGES: | ||
597 | case HIDIOCSUSAGES: | ||
598 | case HIDIOCGCOLLECTIONINDEX: | ||
599 | uref_multi = kmalloc(sizeof(struct hiddev_usage_ref_multi), GFP_KERNEL); | ||
600 | if (!uref_multi) | ||
601 | return -ENOMEM; | ||
602 | uref = &uref_multi->uref; | ||
603 | if (cmd == HIDIOCGUSAGES || cmd == HIDIOCSUSAGES) { | ||
604 | if (copy_from_user(uref_multi, user_arg, | ||
605 | sizeof(*uref_multi))) | ||
606 | goto fault; | ||
607 | } else { | ||
608 | if (copy_from_user(uref, user_arg, sizeof(*uref))) | ||
609 | goto fault; | ||
610 | } | ||
611 | |||
612 | if (cmd != HIDIOCGUSAGE && | ||
613 | cmd != HIDIOCGUSAGES && | ||
614 | uref->report_type == HID_REPORT_TYPE_INPUT) | ||
615 | goto inval; | ||
616 | |||
617 | if (uref->report_id == HID_REPORT_ID_UNKNOWN) { | ||
618 | field = hiddev_lookup_usage(hid, uref); | ||
619 | if (field == NULL) | ||
620 | goto inval; | ||
621 | } else { | ||
622 | rinfo.report_type = uref->report_type; | ||
623 | rinfo.report_id = uref->report_id; | ||
624 | if ((report = hiddev_lookup_report(hid, &rinfo)) == NULL) | ||
625 | goto inval; | ||
626 | |||
627 | if (uref->field_index >= report->maxfield) | ||
628 | goto inval; | ||
629 | |||
630 | field = report->field[uref->field_index]; | ||
631 | |||
632 | if (cmd == HIDIOCGCOLLECTIONINDEX) { | ||
633 | if (uref->usage_index >= field->maxusage) | ||
634 | goto inval; | ||
635 | } else if (uref->usage_index >= field->report_count) | ||
636 | goto inval; | ||
637 | |||
638 | else if ((cmd == HIDIOCGUSAGES || cmd == HIDIOCSUSAGES) && | ||
639 | (uref_multi->num_values > HID_MAX_MULTI_USAGES || | ||
640 | uref->usage_index + uref_multi->num_values > field->report_count)) | ||
641 | goto inval; | ||
642 | } | ||
643 | |||
644 | switch (cmd) { | ||
645 | case HIDIOCGUSAGE: | ||
646 | uref->value = field->value[uref->usage_index]; | ||
647 | if (copy_to_user(user_arg, uref, sizeof(*uref))) | ||
648 | goto fault; | ||
649 | goto goodreturn; | ||
650 | |||
651 | case HIDIOCSUSAGE: | ||
652 | field->value[uref->usage_index] = uref->value; | ||
653 | goto goodreturn; | ||
654 | |||
655 | case HIDIOCGCOLLECTIONINDEX: | ||
656 | kfree(uref_multi); | ||
657 | return field->usage[uref->usage_index].collection_index; | ||
658 | case HIDIOCGUSAGES: | ||
659 | for (i = 0; i < uref_multi->num_values; i++) | ||
660 | uref_multi->values[i] = | ||
661 | field->value[uref->usage_index + i]; | ||
662 | if (copy_to_user(user_arg, uref_multi, | ||
663 | sizeof(*uref_multi))) | ||
664 | goto fault; | ||
665 | goto goodreturn; | ||
666 | case HIDIOCSUSAGES: | ||
667 | for (i = 0; i < uref_multi->num_values; i++) | ||
668 | field->value[uref->usage_index + i] = | ||
669 | uref_multi->values[i]; | ||
670 | goto goodreturn; | ||
671 | } | ||
672 | |||
673 | goodreturn: | ||
674 | kfree(uref_multi); | ||
675 | return 0; | ||
676 | fault: | ||
677 | kfree(uref_multi); | ||
678 | return -EFAULT; | ||
679 | inval: | ||
680 | kfree(uref_multi); | ||
681 | return -EINVAL; | ||
682 | |||
683 | case HIDIOCGCOLLECTIONINFO: | ||
684 | if (copy_from_user(&cinfo, user_arg, sizeof(cinfo))) | ||
685 | return -EFAULT; | ||
686 | |||
687 | if (cinfo.index >= hid->maxcollection) | ||
688 | return -EINVAL; | ||
689 | |||
690 | cinfo.type = hid->collection[cinfo.index].type; | ||
691 | cinfo.usage = hid->collection[cinfo.index].usage; | ||
692 | cinfo.level = hid->collection[cinfo.index].level; | ||
693 | |||
694 | if (copy_to_user(user_arg, &cinfo, sizeof(cinfo))) | ||
695 | return -EFAULT; | ||
696 | return 0; | ||
697 | |||
698 | default: | ||
699 | |||
700 | if (_IOC_TYPE(cmd) != 'H' || _IOC_DIR(cmd) != _IOC_READ) | ||
701 | return -EINVAL; | ||
702 | |||
703 | if (_IOC_NR(cmd) == _IOC_NR(HIDIOCGNAME(0))) { | ||
704 | int len; | ||
705 | if (!hid->name) | ||
706 | return 0; | ||
707 | len = strlen(hid->name) + 1; | ||
708 | if (len > _IOC_SIZE(cmd)) | ||
709 | len = _IOC_SIZE(cmd); | ||
710 | return copy_to_user(user_arg, hid->name, len) ? | ||
711 | -EFAULT : len; | ||
712 | } | ||
713 | |||
714 | if (_IOC_NR(cmd) == _IOC_NR(HIDIOCGPHYS(0))) { | ||
715 | int len; | ||
716 | if (!hid->phys) | ||
717 | return 0; | ||
718 | len = strlen(hid->phys) + 1; | ||
719 | if (len > _IOC_SIZE(cmd)) | ||
720 | len = _IOC_SIZE(cmd); | ||
721 | return copy_to_user(user_arg, hid->phys, len) ? | ||
722 | -EFAULT : len; | ||
723 | } | ||
724 | } | ||
725 | return -EINVAL; | ||
726 | } | ||
727 | |||
728 | static const struct file_operations hiddev_fops = { | ||
729 | .owner = THIS_MODULE, | ||
730 | .read = hiddev_read, | ||
731 | .write = hiddev_write, | ||
732 | .poll = hiddev_poll, | ||
733 | .open = hiddev_open, | ||
734 | .release = hiddev_release, | ||
735 | .ioctl = hiddev_ioctl, | ||
736 | .fasync = hiddev_fasync, | ||
737 | }; | ||
738 | |||
739 | static struct usb_class_driver hiddev_class = { | ||
740 | .name = "hiddev%d", | ||
741 | .fops = &hiddev_fops, | ||
742 | .minor_base = HIDDEV_MINOR_BASE, | ||
743 | }; | ||
744 | |||
745 | /* | ||
746 | * This is where hid.c calls us to connect a hid device to the hiddev driver | ||
747 | */ | ||
748 | int hiddev_connect(struct hid_device *hid) | ||
749 | { | ||
750 | struct hiddev *hiddev; | ||
751 | struct usbhid_device *usbhid = hid->driver_data; | ||
752 | int i; | ||
753 | int retval; | ||
754 | |||
755 | for (i = 0; i < hid->maxcollection; i++) | ||
756 | if (hid->collection[i].type == | ||
757 | HID_COLLECTION_APPLICATION && | ||
758 | !IS_INPUT_APPLICATION(hid->collection[i].usage)) | ||
759 | break; | ||
760 | |||
761 | if (i == hid->maxcollection && (hid->quirks & HID_QUIRK_HIDDEV) == 0) | ||
762 | return -1; | ||
763 | |||
764 | if (!(hiddev = kzalloc(sizeof(struct hiddev), GFP_KERNEL))) | ||
765 | return -1; | ||
766 | |||
767 | retval = usb_register_dev(usbhid->intf, &hiddev_class); | ||
768 | if (retval) { | ||
769 | err("Not able to get a minor for this device."); | ||
770 | kfree(hiddev); | ||
771 | return -1; | ||
772 | } | ||
773 | |||
774 | init_waitqueue_head(&hiddev->wait); | ||
775 | INIT_LIST_HEAD(&hiddev->list); | ||
776 | hiddev->hid = hid; | ||
777 | hiddev->exist = 1; | ||
778 | |||
779 | hid->minor = usbhid->intf->minor; | ||
780 | hid->hiddev = hiddev; | ||
781 | |||
782 | hiddev_table[usbhid->intf->minor - HIDDEV_MINOR_BASE] = hiddev; | ||
783 | |||
784 | return 0; | ||
785 | } | ||
786 | |||
787 | /* | ||
788 | * This is where hid.c calls us to disconnect a hiddev device from the | ||
789 | * corresponding hid device (usually because the usb device has disconnected) | ||
790 | */ | ||
791 | static struct usb_class_driver hiddev_class; | ||
792 | void hiddev_disconnect(struct hid_device *hid) | ||
793 | { | ||
794 | struct hiddev *hiddev = hid->hiddev; | ||
795 | struct usbhid_device *usbhid = hid->driver_data; | ||
796 | |||
797 | hiddev->exist = 0; | ||
798 | |||
799 | hiddev_table[hiddev->hid->minor - HIDDEV_MINOR_BASE] = NULL; | ||
800 | usb_deregister_dev(usbhid->intf, &hiddev_class); | ||
801 | |||
802 | if (hiddev->open) { | ||
803 | usbhid_close(hiddev->hid); | ||
804 | wake_up_interruptible(&hiddev->wait); | ||
805 | } else { | ||
806 | kfree(hiddev); | ||
807 | } | ||
808 | } | ||
809 | |||
810 | /* Currently this driver is a USB driver. It's not a conventional one in | ||
811 | * the sense that it doesn't probe at the USB level. Instead it waits to | ||
812 | * be connected by HID through the hiddev_connect / hiddev_disconnect | ||
813 | * routines. The reason to register as a USB device is to gain part of the | ||
814 | * minor number space from the USB major. | ||
815 | * | ||
816 | * In theory, should the HID code be generalized to more than one physical | ||
817 | * medium (say, IEEE 1384), this driver will probably need to register its | ||
818 | * own major number, and in doing so, no longer need to register with USB. | ||
819 | * At that point the probe routine and hiddev_driver struct below will no | ||
820 | * longer be useful. | ||
821 | */ | ||
822 | |||
823 | |||
824 | /* We never attach in this manner, and rely on HID to connect us. This | ||
825 | * is why there is no disconnect routine defined in the usb_driver either. | ||
826 | */ | ||
827 | static int hiddev_usbd_probe(struct usb_interface *intf, | ||
828 | const struct usb_device_id *hiddev_info) | ||
829 | { | ||
830 | return -ENODEV; | ||
831 | } | ||
832 | |||
833 | |||
834 | static /* const */ struct usb_driver hiddev_driver = { | ||
835 | .name = "hiddev", | ||
836 | .probe = hiddev_usbd_probe, | ||
837 | }; | ||
838 | |||
839 | int __init hiddev_init(void) | ||
840 | { | ||
841 | return usb_register(&hiddev_driver); | ||
842 | } | ||
843 | |||
844 | void hiddev_exit(void) | ||
845 | { | ||
846 | usb_deregister(&hiddev_driver); | ||
847 | } | ||
diff --git a/drivers/usb/input/usbhid.h b/drivers/usb/input/usbhid.h deleted file mode 100644 index 0023f96d4294..000000000000 --- a/drivers/usb/input/usbhid.h +++ /dev/null | |||
@@ -1,87 +0,0 @@ | |||
1 | #ifndef __USBHID_H | ||
2 | #define __USBHID_H | ||
3 | |||
4 | /* | ||
5 | * Copyright (c) 1999 Andreas Gal | ||
6 | * Copyright (c) 2000-2001 Vojtech Pavlik | ||
7 | * Copyright (c) 2006 Jiri Kosina | ||
8 | */ | ||
9 | |||
10 | /* | ||
11 | * This program is free software; you can redistribute it and/or modify | ||
12 | * it under the terms of the GNU General Public License as published by | ||
13 | * the Free Software Foundation; either version 2 of the License, or | ||
14 | * (at your option) any later version. | ||
15 | * | ||
16 | * This program is distributed in the hope that it will be useful, | ||
17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
19 | * GNU General Public License for more details. | ||
20 | * | ||
21 | * You should have received a copy of the GNU General Public License | ||
22 | * along with this program; if not, write to the Free Software | ||
23 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
24 | * | ||
25 | */ | ||
26 | |||
27 | #include <linux/types.h> | ||
28 | #include <linux/slab.h> | ||
29 | #include <linux/list.h> | ||
30 | #include <linux/timer.h> | ||
31 | #include <linux/workqueue.h> | ||
32 | #include <linux/input.h> | ||
33 | |||
34 | /* API provided by hid-core.c for USB HID drivers */ | ||
35 | int usbhid_wait_io(struct hid_device* hid); | ||
36 | void usbhid_close(struct hid_device *hid); | ||
37 | int usbhid_open(struct hid_device *hid); | ||
38 | void usbhid_init_reports(struct hid_device *hid); | ||
39 | void usbhid_submit_report(struct hid_device *hid, struct hid_report *report, unsigned char dir); | ||
40 | |||
41 | /* | ||
42 | * USB-specific HID struct, to be pointed to | ||
43 | * from struct hid_device->driver_data | ||
44 | */ | ||
45 | |||
46 | struct usbhid_device { | ||
47 | struct hid_device *hid; /* pointer to corresponding HID dev */ | ||
48 | |||
49 | struct usb_interface *intf; /* USB interface */ | ||
50 | int ifnum; /* USB interface number */ | ||
51 | |||
52 | unsigned int bufsize; /* URB buffer size */ | ||
53 | |||
54 | struct urb *urbin; /* Input URB */ | ||
55 | char *inbuf; /* Input buffer */ | ||
56 | dma_addr_t inbuf_dma; /* Input buffer dma */ | ||
57 | spinlock_t inlock; /* Input fifo spinlock */ | ||
58 | |||
59 | struct urb *urbctrl; /* Control URB */ | ||
60 | struct usb_ctrlrequest *cr; /* Control request struct */ | ||
61 | dma_addr_t cr_dma; /* Control request struct dma */ | ||
62 | struct hid_control_fifo ctrl[HID_CONTROL_FIFO_SIZE]; /* Control fifo */ | ||
63 | unsigned char ctrlhead, ctrltail; /* Control fifo head & tail */ | ||
64 | char *ctrlbuf; /* Control buffer */ | ||
65 | dma_addr_t ctrlbuf_dma; /* Control buffer dma */ | ||
66 | spinlock_t ctrllock; /* Control fifo spinlock */ | ||
67 | |||
68 | struct urb *urbout; /* Output URB */ | ||
69 | struct hid_report *out[HID_CONTROL_FIFO_SIZE]; /* Output pipe fifo */ | ||
70 | unsigned char outhead, outtail; /* Output pipe fifo head & tail */ | ||
71 | char *outbuf; /* Output buffer */ | ||
72 | dma_addr_t outbuf_dma; /* Output buffer dma */ | ||
73 | spinlock_t outlock; /* Output fifo spinlock */ | ||
74 | |||
75 | unsigned long iofl; /* I/O flags (CTRL_RUNNING, OUT_RUNNING) */ | ||
76 | struct timer_list io_retry; /* Retry timer */ | ||
77 | unsigned long stop_retry; /* Time to give up, in jiffies */ | ||
78 | unsigned int retry_delay; /* Delay length in ms */ | ||
79 | struct work_struct reset_work; /* Task context for resets */ | ||
80 | |||
81 | }; | ||
82 | |||
83 | #define hid_to_usb_dev(hid_dev) \ | ||
84 | container_of(hid_dev->dev->parent, struct usb_device, dev) | ||
85 | |||
86 | #endif | ||
87 | |||
diff --git a/drivers/usb/input/usbkbd.c b/drivers/usb/input/usbkbd.c deleted file mode 100644 index 8505824848f6..000000000000 --- a/drivers/usb/input/usbkbd.c +++ /dev/null | |||
@@ -1,360 +0,0 @@ | |||
1 | /* | ||
2 | * $Id: usbkbd.c,v 1.27 2001/12/27 10:37:41 vojtech Exp $ | ||
3 | * | ||
4 | * Copyright (c) 1999-2001 Vojtech Pavlik | ||
5 | * | ||
6 | * USB HIDBP Keyboard support | ||
7 | */ | ||
8 | |||
9 | /* | ||
10 | * This program is free software; you can redistribute it and/or modify | ||
11 | * it under the terms of the GNU General Public License as published by | ||
12 | * the Free Software Foundation; either version 2 of the License, or | ||
13 | * (at your option) any later version. | ||
14 | * | ||
15 | * This program is distributed in the hope that it will be useful, | ||
16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
18 | * GNU General Public License for more details. | ||
19 | * | ||
20 | * You should have received a copy of the GNU General Public License | ||
21 | * along with this program; if not, write to the Free Software | ||
22 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
23 | * | ||
24 | * Should you need to contact me, the author, you can do so either by | ||
25 | * e-mail - mail your message to <vojtech@ucw.cz>, or by paper mail: | ||
26 | * Vojtech Pavlik, Simunkova 1594, Prague 8, 182 00 Czech Republic | ||
27 | */ | ||
28 | |||
29 | #include <linux/kernel.h> | ||
30 | #include <linux/slab.h> | ||
31 | #include <linux/module.h> | ||
32 | #include <linux/init.h> | ||
33 | #include <linux/usb/input.h> | ||
34 | |||
35 | /* | ||
36 | * Version Information | ||
37 | */ | ||
38 | #define DRIVER_VERSION "" | ||
39 | #define DRIVER_AUTHOR "Vojtech Pavlik <vojtech@ucw.cz>" | ||
40 | #define DRIVER_DESC "USB HID Boot Protocol keyboard driver" | ||
41 | #define DRIVER_LICENSE "GPL" | ||
42 | |||
43 | MODULE_AUTHOR(DRIVER_AUTHOR); | ||
44 | MODULE_DESCRIPTION(DRIVER_DESC); | ||
45 | MODULE_LICENSE(DRIVER_LICENSE); | ||
46 | |||
47 | static unsigned char usb_kbd_keycode[256] = { | ||
48 | 0, 0, 0, 0, 30, 48, 46, 32, 18, 33, 34, 35, 23, 36, 37, 38, | ||
49 | 50, 49, 24, 25, 16, 19, 31, 20, 22, 47, 17, 45, 21, 44, 2, 3, | ||
50 | 4, 5, 6, 7, 8, 9, 10, 11, 28, 1, 14, 15, 57, 12, 13, 26, | ||
51 | 27, 43, 43, 39, 40, 41, 51, 52, 53, 58, 59, 60, 61, 62, 63, 64, | ||
52 | 65, 66, 67, 68, 87, 88, 99, 70,119,110,102,104,111,107,109,106, | ||
53 | 105,108,103, 69, 98, 55, 74, 78, 96, 79, 80, 81, 75, 76, 77, 71, | ||
54 | 72, 73, 82, 83, 86,127,116,117,183,184,185,186,187,188,189,190, | ||
55 | 191,192,193,194,134,138,130,132,128,129,131,137,133,135,136,113, | ||
56 | 115,114, 0, 0, 0,121, 0, 89, 93,124, 92, 94, 95, 0, 0, 0, | ||
57 | 122,123, 90, 91, 85, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
58 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
59 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
60 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
61 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
62 | 29, 42, 56,125, 97, 54,100,126,164,166,165,163,161,115,114,113, | ||
63 | 150,158,159,128,136,177,178,176,142,152,173,140 | ||
64 | }; | ||
65 | |||
66 | struct usb_kbd { | ||
67 | struct input_dev *dev; | ||
68 | struct usb_device *usbdev; | ||
69 | unsigned char old[8]; | ||
70 | struct urb *irq, *led; | ||
71 | unsigned char newleds; | ||
72 | char name[128]; | ||
73 | char phys[64]; | ||
74 | |||
75 | unsigned char *new; | ||
76 | struct usb_ctrlrequest *cr; | ||
77 | unsigned char *leds; | ||
78 | dma_addr_t cr_dma; | ||
79 | dma_addr_t new_dma; | ||
80 | dma_addr_t leds_dma; | ||
81 | }; | ||
82 | |||
83 | static void usb_kbd_irq(struct urb *urb) | ||
84 | { | ||
85 | struct usb_kbd *kbd = urb->context; | ||
86 | int i; | ||
87 | |||
88 | switch (urb->status) { | ||
89 | case 0: /* success */ | ||
90 | break; | ||
91 | case -ECONNRESET: /* unlink */ | ||
92 | case -ENOENT: | ||
93 | case -ESHUTDOWN: | ||
94 | return; | ||
95 | /* -EPIPE: should clear the halt */ | ||
96 | default: /* error */ | ||
97 | goto resubmit; | ||
98 | } | ||
99 | |||
100 | for (i = 0; i < 8; i++) | ||
101 | input_report_key(kbd->dev, usb_kbd_keycode[i + 224], (kbd->new[0] >> i) & 1); | ||
102 | |||
103 | for (i = 2; i < 8; i++) { | ||
104 | |||
105 | if (kbd->old[i] > 3 && memscan(kbd->new + 2, kbd->old[i], 6) == kbd->new + 8) { | ||
106 | if (usb_kbd_keycode[kbd->old[i]]) | ||
107 | input_report_key(kbd->dev, usb_kbd_keycode[kbd->old[i]], 0); | ||
108 | else | ||
109 | info("Unknown key (scancode %#x) released.", kbd->old[i]); | ||
110 | } | ||
111 | |||
112 | if (kbd->new[i] > 3 && memscan(kbd->old + 2, kbd->new[i], 6) == kbd->old + 8) { | ||
113 | if (usb_kbd_keycode[kbd->new[i]]) | ||
114 | input_report_key(kbd->dev, usb_kbd_keycode[kbd->new[i]], 1); | ||
115 | else | ||
116 | info("Unknown key (scancode %#x) pressed.", kbd->new[i]); | ||
117 | } | ||
118 | } | ||
119 | |||
120 | input_sync(kbd->dev); | ||
121 | |||
122 | memcpy(kbd->old, kbd->new, 8); | ||
123 | |||
124 | resubmit: | ||
125 | i = usb_submit_urb (urb, GFP_ATOMIC); | ||
126 | if (i) | ||
127 | err ("can't resubmit intr, %s-%s/input0, status %d", | ||
128 | kbd->usbdev->bus->bus_name, | ||
129 | kbd->usbdev->devpath, i); | ||
130 | } | ||
131 | |||
132 | static int usb_kbd_event(struct input_dev *dev, unsigned int type, | ||
133 | unsigned int code, int value) | ||
134 | { | ||
135 | struct usb_kbd *kbd = dev->private; | ||
136 | |||
137 | if (type != EV_LED) | ||
138 | return -1; | ||
139 | |||
140 | |||
141 | kbd->newleds = (!!test_bit(LED_KANA, dev->led) << 3) | (!!test_bit(LED_COMPOSE, dev->led) << 3) | | ||
142 | (!!test_bit(LED_SCROLLL, dev->led) << 2) | (!!test_bit(LED_CAPSL, dev->led) << 1) | | ||
143 | (!!test_bit(LED_NUML, dev->led)); | ||
144 | |||
145 | if (kbd->led->status == -EINPROGRESS) | ||
146 | return 0; | ||
147 | |||
148 | if (*(kbd->leds) == kbd->newleds) | ||
149 | return 0; | ||
150 | |||
151 | *(kbd->leds) = kbd->newleds; | ||
152 | kbd->led->dev = kbd->usbdev; | ||
153 | if (usb_submit_urb(kbd->led, GFP_ATOMIC)) | ||
154 | err("usb_submit_urb(leds) failed"); | ||
155 | |||
156 | return 0; | ||
157 | } | ||
158 | |||
159 | static void usb_kbd_led(struct urb *urb) | ||
160 | { | ||
161 | struct usb_kbd *kbd = urb->context; | ||
162 | |||
163 | if (urb->status) | ||
164 | warn("led urb status %d received", urb->status); | ||
165 | |||
166 | if (*(kbd->leds) == kbd->newleds) | ||
167 | return; | ||
168 | |||
169 | *(kbd->leds) = kbd->newleds; | ||
170 | kbd->led->dev = kbd->usbdev; | ||
171 | if (usb_submit_urb(kbd->led, GFP_ATOMIC)) | ||
172 | err("usb_submit_urb(leds) failed"); | ||
173 | } | ||
174 | |||
175 | static int usb_kbd_open(struct input_dev *dev) | ||
176 | { | ||
177 | struct usb_kbd *kbd = dev->private; | ||
178 | |||
179 | kbd->irq->dev = kbd->usbdev; | ||
180 | if (usb_submit_urb(kbd->irq, GFP_KERNEL)) | ||
181 | return -EIO; | ||
182 | |||
183 | return 0; | ||
184 | } | ||
185 | |||
186 | static void usb_kbd_close(struct input_dev *dev) | ||
187 | { | ||
188 | struct usb_kbd *kbd = dev->private; | ||
189 | |||
190 | usb_kill_urb(kbd->irq); | ||
191 | } | ||
192 | |||
193 | static int usb_kbd_alloc_mem(struct usb_device *dev, struct usb_kbd *kbd) | ||
194 | { | ||
195 | if (!(kbd->irq = usb_alloc_urb(0, GFP_KERNEL))) | ||
196 | return -1; | ||
197 | if (!(kbd->led = usb_alloc_urb(0, GFP_KERNEL))) | ||
198 | return -1; | ||
199 | if (!(kbd->new = usb_buffer_alloc(dev, 8, GFP_ATOMIC, &kbd->new_dma))) | ||
200 | return -1; | ||
201 | if (!(kbd->cr = usb_buffer_alloc(dev, sizeof(struct usb_ctrlrequest), GFP_ATOMIC, &kbd->cr_dma))) | ||
202 | return -1; | ||
203 | if (!(kbd->leds = usb_buffer_alloc(dev, 1, GFP_ATOMIC, &kbd->leds_dma))) | ||
204 | return -1; | ||
205 | |||
206 | return 0; | ||
207 | } | ||
208 | |||
209 | static void usb_kbd_free_mem(struct usb_device *dev, struct usb_kbd *kbd) | ||
210 | { | ||
211 | usb_free_urb(kbd->irq); | ||
212 | usb_free_urb(kbd->led); | ||
213 | if (kbd->new) | ||
214 | usb_buffer_free(dev, 8, kbd->new, kbd->new_dma); | ||
215 | if (kbd->cr) | ||
216 | usb_buffer_free(dev, sizeof(struct usb_ctrlrequest), kbd->cr, kbd->cr_dma); | ||
217 | if (kbd->leds) | ||
218 | usb_buffer_free(dev, 1, kbd->leds, kbd->leds_dma); | ||
219 | } | ||
220 | |||
221 | static int usb_kbd_probe(struct usb_interface *iface, | ||
222 | const struct usb_device_id *id) | ||
223 | { | ||
224 | struct usb_device *dev = interface_to_usbdev(iface); | ||
225 | struct usb_host_interface *interface; | ||
226 | struct usb_endpoint_descriptor *endpoint; | ||
227 | struct usb_kbd *kbd; | ||
228 | struct input_dev *input_dev; | ||
229 | int i, pipe, maxp; | ||
230 | |||
231 | interface = iface->cur_altsetting; | ||
232 | |||
233 | if (interface->desc.bNumEndpoints != 1) | ||
234 | return -ENODEV; | ||
235 | |||
236 | endpoint = &interface->endpoint[0].desc; | ||
237 | if (!usb_endpoint_is_int_in(endpoint)) | ||
238 | return -ENODEV; | ||
239 | |||
240 | pipe = usb_rcvintpipe(dev, endpoint->bEndpointAddress); | ||
241 | maxp = usb_maxpacket(dev, pipe, usb_pipeout(pipe)); | ||
242 | |||
243 | kbd = kzalloc(sizeof(struct usb_kbd), GFP_KERNEL); | ||
244 | input_dev = input_allocate_device(); | ||
245 | if (!kbd || !input_dev) | ||
246 | goto fail1; | ||
247 | |||
248 | if (usb_kbd_alloc_mem(dev, kbd)) | ||
249 | goto fail2; | ||
250 | |||
251 | kbd->usbdev = dev; | ||
252 | kbd->dev = input_dev; | ||
253 | |||
254 | if (dev->manufacturer) | ||
255 | strlcpy(kbd->name, dev->manufacturer, sizeof(kbd->name)); | ||
256 | |||
257 | if (dev->product) { | ||
258 | if (dev->manufacturer) | ||
259 | strlcat(kbd->name, " ", sizeof(kbd->name)); | ||
260 | strlcat(kbd->name, dev->product, sizeof(kbd->name)); | ||
261 | } | ||
262 | |||
263 | if (!strlen(kbd->name)) | ||
264 | snprintf(kbd->name, sizeof(kbd->name), | ||
265 | "USB HIDBP Keyboard %04x:%04x", | ||
266 | le16_to_cpu(dev->descriptor.idVendor), | ||
267 | le16_to_cpu(dev->descriptor.idProduct)); | ||
268 | |||
269 | usb_make_path(dev, kbd->phys, sizeof(kbd->phys)); | ||
270 | strlcpy(kbd->phys, "/input0", sizeof(kbd->phys)); | ||
271 | |||
272 | input_dev->name = kbd->name; | ||
273 | input_dev->phys = kbd->phys; | ||
274 | usb_to_input_id(dev, &input_dev->id); | ||
275 | input_dev->cdev.dev = &iface->dev; | ||
276 | input_dev->private = kbd; | ||
277 | |||
278 | input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_LED) | BIT(EV_REP); | ||
279 | input_dev->ledbit[0] = BIT(LED_NUML) | BIT(LED_CAPSL) | BIT(LED_SCROLLL) | BIT(LED_COMPOSE) | BIT(LED_KANA); | ||
280 | |||
281 | for (i = 0; i < 255; i++) | ||
282 | set_bit(usb_kbd_keycode[i], input_dev->keybit); | ||
283 | clear_bit(0, input_dev->keybit); | ||
284 | |||
285 | input_dev->event = usb_kbd_event; | ||
286 | input_dev->open = usb_kbd_open; | ||
287 | input_dev->close = usb_kbd_close; | ||
288 | |||
289 | usb_fill_int_urb(kbd->irq, dev, pipe, | ||
290 | kbd->new, (maxp > 8 ? 8 : maxp), | ||
291 | usb_kbd_irq, kbd, endpoint->bInterval); | ||
292 | kbd->irq->transfer_dma = kbd->new_dma; | ||
293 | kbd->irq->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; | ||
294 | |||
295 | kbd->cr->bRequestType = USB_TYPE_CLASS | USB_RECIP_INTERFACE; | ||
296 | kbd->cr->bRequest = 0x09; | ||
297 | kbd->cr->wValue = cpu_to_le16(0x200); | ||
298 | kbd->cr->wIndex = cpu_to_le16(interface->desc.bInterfaceNumber); | ||
299 | kbd->cr->wLength = cpu_to_le16(1); | ||
300 | |||
301 | usb_fill_control_urb(kbd->led, dev, usb_sndctrlpipe(dev, 0), | ||
302 | (void *) kbd->cr, kbd->leds, 1, | ||
303 | usb_kbd_led, kbd); | ||
304 | kbd->led->setup_dma = kbd->cr_dma; | ||
305 | kbd->led->transfer_dma = kbd->leds_dma; | ||
306 | kbd->led->transfer_flags |= (URB_NO_TRANSFER_DMA_MAP | URB_NO_SETUP_DMA_MAP); | ||
307 | |||
308 | input_register_device(kbd->dev); | ||
309 | |||
310 | usb_set_intfdata(iface, kbd); | ||
311 | return 0; | ||
312 | |||
313 | fail2: usb_kbd_free_mem(dev, kbd); | ||
314 | fail1: input_free_device(input_dev); | ||
315 | kfree(kbd); | ||
316 | return -ENOMEM; | ||
317 | } | ||
318 | |||
319 | static void usb_kbd_disconnect(struct usb_interface *intf) | ||
320 | { | ||
321 | struct usb_kbd *kbd = usb_get_intfdata (intf); | ||
322 | |||
323 | usb_set_intfdata(intf, NULL); | ||
324 | if (kbd) { | ||
325 | usb_kill_urb(kbd->irq); | ||
326 | input_unregister_device(kbd->dev); | ||
327 | usb_kbd_free_mem(interface_to_usbdev(intf), kbd); | ||
328 | kfree(kbd); | ||
329 | } | ||
330 | } | ||
331 | |||
332 | static struct usb_device_id usb_kbd_id_table [] = { | ||
333 | { USB_INTERFACE_INFO(3, 1, 1) }, | ||
334 | { } /* Terminating entry */ | ||
335 | }; | ||
336 | |||
337 | MODULE_DEVICE_TABLE (usb, usb_kbd_id_table); | ||
338 | |||
339 | static struct usb_driver usb_kbd_driver = { | ||
340 | .name = "usbkbd", | ||
341 | .probe = usb_kbd_probe, | ||
342 | .disconnect = usb_kbd_disconnect, | ||
343 | .id_table = usb_kbd_id_table, | ||
344 | }; | ||
345 | |||
346 | static int __init usb_kbd_init(void) | ||
347 | { | ||
348 | int result = usb_register(&usb_kbd_driver); | ||
349 | if (result == 0) | ||
350 | info(DRIVER_VERSION ":" DRIVER_DESC); | ||
351 | return result; | ||
352 | } | ||
353 | |||
354 | static void __exit usb_kbd_exit(void) | ||
355 | { | ||
356 | usb_deregister(&usb_kbd_driver); | ||
357 | } | ||
358 | |||
359 | module_init(usb_kbd_init); | ||
360 | module_exit(usb_kbd_exit); | ||
diff --git a/drivers/usb/input/usbmouse.c b/drivers/usb/input/usbmouse.c deleted file mode 100644 index 64a33e420cfb..000000000000 --- a/drivers/usb/input/usbmouse.c +++ /dev/null | |||
@@ -1,243 +0,0 @@ | |||
1 | /* | ||
2 | * $Id: usbmouse.c,v 1.15 2001/12/27 10:37:41 vojtech Exp $ | ||
3 | * | ||
4 | * Copyright (c) 1999-2001 Vojtech Pavlik | ||
5 | * | ||
6 | * USB HIDBP Mouse support | ||
7 | */ | ||
8 | |||
9 | /* | ||
10 | * This program is free software; you can redistribute it and/or modify | ||
11 | * it under the terms of the GNU General Public License as published by | ||
12 | * the Free Software Foundation; either version 2 of the License, or | ||
13 | * (at your option) any later version. | ||
14 | * | ||
15 | * This program is distributed in the hope that it will be useful, | ||
16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
18 | * GNU General Public License for more details. | ||
19 | * | ||
20 | * You should have received a copy of the GNU General Public License | ||
21 | * along with this program; if not, write to the Free Software | ||
22 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
23 | * | ||
24 | * Should you need to contact me, the author, you can do so either by | ||
25 | * e-mail - mail your message to <vojtech@ucw.cz>, or by paper mail: | ||
26 | * Vojtech Pavlik, Simunkova 1594, Prague 8, 182 00 Czech Republic | ||
27 | */ | ||
28 | |||
29 | #include <linux/kernel.h> | ||
30 | #include <linux/slab.h> | ||
31 | #include <linux/module.h> | ||
32 | #include <linux/init.h> | ||
33 | #include <linux/usb/input.h> | ||
34 | |||
35 | /* | ||
36 | * Version Information | ||
37 | */ | ||
38 | #define DRIVER_VERSION "v1.6" | ||
39 | #define DRIVER_AUTHOR "Vojtech Pavlik <vojtech@ucw.cz>" | ||
40 | #define DRIVER_DESC "USB HID Boot Protocol mouse driver" | ||
41 | #define DRIVER_LICENSE "GPL" | ||
42 | |||
43 | MODULE_AUTHOR(DRIVER_AUTHOR); | ||
44 | MODULE_DESCRIPTION(DRIVER_DESC); | ||
45 | MODULE_LICENSE(DRIVER_LICENSE); | ||
46 | |||
47 | struct usb_mouse { | ||
48 | char name[128]; | ||
49 | char phys[64]; | ||
50 | struct usb_device *usbdev; | ||
51 | struct input_dev *dev; | ||
52 | struct urb *irq; | ||
53 | |||
54 | signed char *data; | ||
55 | dma_addr_t data_dma; | ||
56 | }; | ||
57 | |||
58 | static void usb_mouse_irq(struct urb *urb) | ||
59 | { | ||
60 | struct usb_mouse *mouse = urb->context; | ||
61 | signed char *data = mouse->data; | ||
62 | struct input_dev *dev = mouse->dev; | ||
63 | int status; | ||
64 | |||
65 | switch (urb->status) { | ||
66 | case 0: /* success */ | ||
67 | break; | ||
68 | case -ECONNRESET: /* unlink */ | ||
69 | case -ENOENT: | ||
70 | case -ESHUTDOWN: | ||
71 | return; | ||
72 | /* -EPIPE: should clear the halt */ | ||
73 | default: /* error */ | ||
74 | goto resubmit; | ||
75 | } | ||
76 | |||
77 | input_report_key(dev, BTN_LEFT, data[0] & 0x01); | ||
78 | input_report_key(dev, BTN_RIGHT, data[0] & 0x02); | ||
79 | input_report_key(dev, BTN_MIDDLE, data[0] & 0x04); | ||
80 | input_report_key(dev, BTN_SIDE, data[0] & 0x08); | ||
81 | input_report_key(dev, BTN_EXTRA, data[0] & 0x10); | ||
82 | |||
83 | input_report_rel(dev, REL_X, data[1]); | ||
84 | input_report_rel(dev, REL_Y, data[2]); | ||
85 | input_report_rel(dev, REL_WHEEL, data[3]); | ||
86 | |||
87 | input_sync(dev); | ||
88 | resubmit: | ||
89 | status = usb_submit_urb (urb, GFP_ATOMIC); | ||
90 | if (status) | ||
91 | err ("can't resubmit intr, %s-%s/input0, status %d", | ||
92 | mouse->usbdev->bus->bus_name, | ||
93 | mouse->usbdev->devpath, status); | ||
94 | } | ||
95 | |||
96 | static int usb_mouse_open(struct input_dev *dev) | ||
97 | { | ||
98 | struct usb_mouse *mouse = dev->private; | ||
99 | |||
100 | mouse->irq->dev = mouse->usbdev; | ||
101 | if (usb_submit_urb(mouse->irq, GFP_KERNEL)) | ||
102 | return -EIO; | ||
103 | |||
104 | return 0; | ||
105 | } | ||
106 | |||
107 | static void usb_mouse_close(struct input_dev *dev) | ||
108 | { | ||
109 | struct usb_mouse *mouse = dev->private; | ||
110 | |||
111 | usb_kill_urb(mouse->irq); | ||
112 | } | ||
113 | |||
114 | static int usb_mouse_probe(struct usb_interface *intf, const struct usb_device_id *id) | ||
115 | { | ||
116 | struct usb_device *dev = interface_to_usbdev(intf); | ||
117 | struct usb_host_interface *interface; | ||
118 | struct usb_endpoint_descriptor *endpoint; | ||
119 | struct usb_mouse *mouse; | ||
120 | struct input_dev *input_dev; | ||
121 | int pipe, maxp; | ||
122 | |||
123 | interface = intf->cur_altsetting; | ||
124 | |||
125 | if (interface->desc.bNumEndpoints != 1) | ||
126 | return -ENODEV; | ||
127 | |||
128 | endpoint = &interface->endpoint[0].desc; | ||
129 | if (!usb_endpoint_is_int_in(endpoint)) | ||
130 | return -ENODEV; | ||
131 | |||
132 | pipe = usb_rcvintpipe(dev, endpoint->bEndpointAddress); | ||
133 | maxp = usb_maxpacket(dev, pipe, usb_pipeout(pipe)); | ||
134 | |||
135 | mouse = kzalloc(sizeof(struct usb_mouse), GFP_KERNEL); | ||
136 | input_dev = input_allocate_device(); | ||
137 | if (!mouse || !input_dev) | ||
138 | goto fail1; | ||
139 | |||
140 | mouse->data = usb_buffer_alloc(dev, 8, GFP_ATOMIC, &mouse->data_dma); | ||
141 | if (!mouse->data) | ||
142 | goto fail1; | ||
143 | |||
144 | mouse->irq = usb_alloc_urb(0, GFP_KERNEL); | ||
145 | if (!mouse->irq) | ||
146 | goto fail2; | ||
147 | |||
148 | mouse->usbdev = dev; | ||
149 | mouse->dev = input_dev; | ||
150 | |||
151 | if (dev->manufacturer) | ||
152 | strlcpy(mouse->name, dev->manufacturer, sizeof(mouse->name)); | ||
153 | |||
154 | if (dev->product) { | ||
155 | if (dev->manufacturer) | ||
156 | strlcat(mouse->name, " ", sizeof(mouse->name)); | ||
157 | strlcat(mouse->name, dev->product, sizeof(mouse->name)); | ||
158 | } | ||
159 | |||
160 | if (!strlen(mouse->name)) | ||
161 | snprintf(mouse->name, sizeof(mouse->name), | ||
162 | "USB HIDBP Mouse %04x:%04x", | ||
163 | le16_to_cpu(dev->descriptor.idVendor), | ||
164 | le16_to_cpu(dev->descriptor.idProduct)); | ||
165 | |||
166 | usb_make_path(dev, mouse->phys, sizeof(mouse->phys)); | ||
167 | strlcat(mouse->phys, "/input0", sizeof(mouse->phys)); | ||
168 | |||
169 | input_dev->name = mouse->name; | ||
170 | input_dev->phys = mouse->phys; | ||
171 | usb_to_input_id(dev, &input_dev->id); | ||
172 | input_dev->cdev.dev = &intf->dev; | ||
173 | |||
174 | input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_REL); | ||
175 | input_dev->keybit[LONG(BTN_MOUSE)] = BIT(BTN_LEFT) | BIT(BTN_RIGHT) | BIT(BTN_MIDDLE); | ||
176 | input_dev->relbit[0] = BIT(REL_X) | BIT(REL_Y); | ||
177 | input_dev->keybit[LONG(BTN_MOUSE)] |= BIT(BTN_SIDE) | BIT(BTN_EXTRA); | ||
178 | input_dev->relbit[0] |= BIT(REL_WHEEL); | ||
179 | |||
180 | input_dev->private = mouse; | ||
181 | input_dev->open = usb_mouse_open; | ||
182 | input_dev->close = usb_mouse_close; | ||
183 | |||
184 | usb_fill_int_urb(mouse->irq, dev, pipe, mouse->data, | ||
185 | (maxp > 8 ? 8 : maxp), | ||
186 | usb_mouse_irq, mouse, endpoint->bInterval); | ||
187 | mouse->irq->transfer_dma = mouse->data_dma; | ||
188 | mouse->irq->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; | ||
189 | |||
190 | input_register_device(mouse->dev); | ||
191 | |||
192 | usb_set_intfdata(intf, mouse); | ||
193 | return 0; | ||
194 | |||
195 | fail2: usb_buffer_free(dev, 8, mouse->data, mouse->data_dma); | ||
196 | fail1: input_free_device(input_dev); | ||
197 | kfree(mouse); | ||
198 | return -ENOMEM; | ||
199 | } | ||
200 | |||
201 | static void usb_mouse_disconnect(struct usb_interface *intf) | ||
202 | { | ||
203 | struct usb_mouse *mouse = usb_get_intfdata (intf); | ||
204 | |||
205 | usb_set_intfdata(intf, NULL); | ||
206 | if (mouse) { | ||
207 | usb_kill_urb(mouse->irq); | ||
208 | input_unregister_device(mouse->dev); | ||
209 | usb_free_urb(mouse->irq); | ||
210 | usb_buffer_free(interface_to_usbdev(intf), 8, mouse->data, mouse->data_dma); | ||
211 | kfree(mouse); | ||
212 | } | ||
213 | } | ||
214 | |||
215 | static struct usb_device_id usb_mouse_id_table [] = { | ||
216 | { USB_INTERFACE_INFO(3, 1, 2) }, | ||
217 | { } /* Terminating entry */ | ||
218 | }; | ||
219 | |||
220 | MODULE_DEVICE_TABLE (usb, usb_mouse_id_table); | ||
221 | |||
222 | static struct usb_driver usb_mouse_driver = { | ||
223 | .name = "usbmouse", | ||
224 | .probe = usb_mouse_probe, | ||
225 | .disconnect = usb_mouse_disconnect, | ||
226 | .id_table = usb_mouse_id_table, | ||
227 | }; | ||
228 | |||
229 | static int __init usb_mouse_init(void) | ||
230 | { | ||
231 | int retval = usb_register(&usb_mouse_driver); | ||
232 | if (retval == 0) | ||
233 | info(DRIVER_VERSION ":" DRIVER_DESC); | ||
234 | return retval; | ||
235 | } | ||
236 | |||
237 | static void __exit usb_mouse_exit(void) | ||
238 | { | ||
239 | usb_deregister(&usb_mouse_driver); | ||
240 | } | ||
241 | |||
242 | module_init(usb_mouse_init); | ||
243 | module_exit(usb_mouse_exit); | ||
diff --git a/drivers/usb/input/wacom_wac.c b/drivers/usb/input/wacom_wac.c index 4142e36730fc..4f3e9bc7177d 100644 --- a/drivers/usb/input/wacom_wac.c +++ b/drivers/usb/input/wacom_wac.c | |||
@@ -163,7 +163,7 @@ static int wacom_graphire_irq(struct wacom_wac *wacom, void *wcombo) | |||
163 | } | 163 | } |
164 | 164 | ||
165 | id = STYLUS_DEVICE_ID; | 165 | id = STYLUS_DEVICE_ID; |
166 | if (data[1] & 0x10) { /* in prox */ | 166 | if (data[1] & 0x80) { /* in prox */ |
167 | 167 | ||
168 | switch ((data[1] >> 5) & 3) { | 168 | switch ((data[1] >> 5) & 3) { |
169 | 169 | ||
@@ -196,9 +196,6 @@ static int wacom_graphire_irq(struct wacom_wac *wacom, void *wcombo) | |||
196 | wacom_report_abs(wcombo, ABS_DISTANCE, data[7] & 0x3f); | 196 | wacom_report_abs(wcombo, ABS_DISTANCE, data[7] & 0x3f); |
197 | break; | 197 | break; |
198 | } | 198 | } |
199 | } | ||
200 | |||
201 | if (data[1] & 0x90) { | ||
202 | x = wacom_le16_to_cpu(&data[2]); | 199 | x = wacom_le16_to_cpu(&data[2]); |
203 | y = wacom_le16_to_cpu(&data[4]); | 200 | y = wacom_le16_to_cpu(&data[4]); |
204 | wacom_report_abs(wcombo, ABS_X, x); | 201 | wacom_report_abs(wcombo, ABS_X, x); |
@@ -210,19 +207,28 @@ static int wacom_graphire_irq(struct wacom_wac *wacom, void *wcombo) | |||
210 | wacom_report_key(wcombo, BTN_STYLUS2, data[1] & 0x04); | 207 | wacom_report_key(wcombo, BTN_STYLUS2, data[1] & 0x04); |
211 | } | 208 | } |
212 | wacom_report_abs(wcombo, ABS_MISC, id); /* report tool id */ | 209 | wacom_report_abs(wcombo, ABS_MISC, id); /* report tool id */ |
213 | } | ||
214 | else | ||
215 | wacom_report_abs(wcombo, ABS_MISC, 0); /* reset tool id */ | ||
216 | |||
217 | if (data[1] & 0x10) /* only report prox-in when in area */ | ||
218 | wacom_report_key(wcombo, wacom->tool[0], 1); | 210 | wacom_report_key(wcombo, wacom->tool[0], 1); |
219 | if (!(data[1] & 0x90)) /* report prox-out when physically out */ | 211 | } else if (!(data[1] & 0x90)) { |
212 | wacom_report_abs(wcombo, ABS_X, 0); | ||
213 | wacom_report_abs(wcombo, ABS_Y, 0); | ||
214 | if (wacom->tool[0] == BTN_TOOL_MOUSE) { | ||
215 | wacom_report_key(wcombo, BTN_LEFT, 0); | ||
216 | wacom_report_key(wcombo, BTN_RIGHT, 0); | ||
217 | wacom_report_abs(wcombo, ABS_DISTANCE, 0); | ||
218 | } else { | ||
219 | wacom_report_abs(wcombo, ABS_PRESSURE, 0); | ||
220 | wacom_report_key(wcombo, BTN_TOUCH, 0); | ||
221 | wacom_report_key(wcombo, BTN_STYLUS, 0); | ||
222 | wacom_report_key(wcombo, BTN_STYLUS2, 0); | ||
223 | } | ||
224 | wacom_report_abs(wcombo, ABS_MISC, 0); /* reset tool id */ | ||
220 | wacom_report_key(wcombo, wacom->tool[0], 0); | 225 | wacom_report_key(wcombo, wacom->tool[0], 0); |
221 | wacom_input_sync(wcombo); | 226 | } |
222 | 227 | ||
223 | /* send pad data */ | 228 | /* send pad data */ |
224 | if (wacom->features->type == WACOM_G4) { | 229 | if (wacom->features->type == WACOM_G4) { |
225 | if ( (wacom->serial[1] & 0xc0) != (data[7] & 0xf8) ) { | 230 | if (data[7] & 0xf8) { |
231 | wacom_input_sync(wcombo); /* sync last event */ | ||
226 | wacom->id[1] = 1; | 232 | wacom->id[1] = 1; |
227 | wacom->serial[1] = (data[7] & 0xf8); | 233 | wacom->serial[1] = (data[7] & 0xf8); |
228 | wacom_report_key(wcombo, BTN_0, (data[7] & 0x40)); | 234 | wacom_report_key(wcombo, BTN_0, (data[7] & 0x40)); |
@@ -230,10 +236,15 @@ static int wacom_graphire_irq(struct wacom_wac *wacom, void *wcombo) | |||
230 | rw = ((data[7] & 0x18) >> 3) - ((data[7] & 0x20) >> 3); | 236 | rw = ((data[7] & 0x18) >> 3) - ((data[7] & 0x20) >> 3); |
231 | wacom_report_rel(wcombo, REL_WHEEL, rw); | 237 | wacom_report_rel(wcombo, REL_WHEEL, rw); |
232 | wacom_report_key(wcombo, BTN_TOOL_FINGER, 0xf0); | 238 | wacom_report_key(wcombo, BTN_TOOL_FINGER, 0xf0); |
239 | wacom_report_abs(wcombo, ABS_MISC, PAD_DEVICE_ID); | ||
233 | wacom_input_event(wcombo, EV_MSC, MSC_SERIAL, 0xf0); | 240 | wacom_input_event(wcombo, EV_MSC, MSC_SERIAL, 0xf0); |
234 | } else if (wacom->id[1]) { | 241 | } else if (wacom->id[1]) { |
242 | wacom_input_sync(wcombo); /* sync last event */ | ||
235 | wacom->id[1] = 0; | 243 | wacom->id[1] = 0; |
244 | wacom_report_key(wcombo, BTN_0, (data[7] & 0x40)); | ||
245 | wacom_report_key(wcombo, BTN_4, (data[7] & 0x80)); | ||
236 | wacom_report_key(wcombo, BTN_TOOL_FINGER, 0); | 246 | wacom_report_key(wcombo, BTN_TOOL_FINGER, 0); |
247 | wacom_report_abs(wcombo, ABS_MISC, 0); | ||
237 | wacom_input_event(wcombo, EV_MSC, MSC_SERIAL, 0xf0); | 248 | wacom_input_event(wcombo, EV_MSC, MSC_SERIAL, 0xf0); |
238 | } | 249 | } |
239 | } | 250 | } |
@@ -304,28 +315,35 @@ static int wacom_intuos_inout(struct wacom_wac *wacom, void *wcombo) | |||
304 | default: /* Unknown tool */ | 315 | default: /* Unknown tool */ |
305 | wacom->tool[idx] = BTN_TOOL_PEN; | 316 | wacom->tool[idx] = BTN_TOOL_PEN; |
306 | } | 317 | } |
307 | /* only large I3 support Lens Cursor */ | ||
308 | if(!((wacom->tool[idx] == BTN_TOOL_LENS) | ||
309 | && ((wacom->features->type == INTUOS3) | ||
310 | || (wacom->features->type == INTUOS3S)))) { | ||
311 | wacom_report_abs(wcombo, ABS_MISC, wacom->id[idx]); /* report tool id */ | ||
312 | wacom_report_key(wcombo, wacom->tool[idx], 1); | ||
313 | wacom_input_event(wcombo, EV_MSC, MSC_SERIAL, wacom->serial[idx]); | ||
314 | return 2; | ||
315 | } | ||
316 | return 1; | 318 | return 1; |
317 | } | 319 | } |
318 | 320 | ||
319 | /* Exit report */ | 321 | /* Exit report */ |
320 | if ((data[1] & 0xfe) == 0x80) { | 322 | if ((data[1] & 0xfe) == 0x80) { |
321 | if(!((wacom->tool[idx] == BTN_TOOL_LENS) | 323 | wacom_report_abs(wcombo, ABS_X, 0); |
322 | && ((wacom->features->type == INTUOS3) | 324 | wacom_report_abs(wcombo, ABS_Y, 0); |
323 | || (wacom->features->type == INTUOS3S)))) { | 325 | wacom_report_abs(wcombo, ABS_DISTANCE, 0); |
324 | wacom_report_key(wcombo, wacom->tool[idx], 0); | 326 | if (wacom->tool[idx] >= BTN_TOOL_MOUSE) { |
325 | wacom_report_abs(wcombo, ABS_MISC, 0); /* reset tool id */ | 327 | wacom_report_key(wcombo, BTN_LEFT, 0); |
326 | wacom_input_event(wcombo, EV_MSC, MSC_SERIAL, wacom->serial[idx]); | 328 | wacom_report_key(wcombo, BTN_MIDDLE, 0); |
327 | return 2; | 329 | wacom_report_key(wcombo, BTN_RIGHT, 0); |
330 | wacom_report_key(wcombo, BTN_SIDE, 0); | ||
331 | wacom_report_key(wcombo, BTN_EXTRA, 0); | ||
332 | wacom_report_abs(wcombo, ABS_THROTTLE, 0); | ||
333 | wacom_report_abs(wcombo, ABS_RZ, 0); | ||
334 | } else { | ||
335 | wacom_report_abs(wcombo, ABS_PRESSURE, 0); | ||
336 | wacom_report_abs(wcombo, ABS_TILT_X, 0); | ||
337 | wacom_report_abs(wcombo, ABS_TILT_Y, 0); | ||
338 | wacom_report_key(wcombo, BTN_STYLUS, 0); | ||
339 | wacom_report_key(wcombo, BTN_STYLUS2, 0); | ||
340 | wacom_report_key(wcombo, BTN_TOUCH, 0); | ||
341 | wacom_report_abs(wcombo, ABS_WHEEL, 0); | ||
328 | } | 342 | } |
343 | wacom_report_key(wcombo, wacom->tool[idx], 0); | ||
344 | wacom_report_abs(wcombo, ABS_MISC, 0); /* reset tool id */ | ||
345 | wacom_input_event(wcombo, EV_MSC, MSC_SERIAL, wacom->serial[idx]); | ||
346 | return 2; | ||
329 | } | 347 | } |
330 | return 0; | 348 | return 0; |
331 | } | 349 | } |
@@ -394,6 +412,7 @@ static int wacom_intuos_irq(struct wacom_wac *wacom, void *wcombo) | |||
394 | wacom_report_key(wcombo, wacom->tool[1], 1); | 412 | wacom_report_key(wcombo, wacom->tool[1], 1); |
395 | else | 413 | else |
396 | wacom_report_key(wcombo, wacom->tool[1], 0); | 414 | wacom_report_key(wcombo, wacom->tool[1], 0); |
415 | wacom_report_abs(wcombo, ABS_MISC, PAD_DEVICE_ID); | ||
397 | wacom_input_event(wcombo, EV_MSC, MSC_SERIAL, 0xffffffff); | 416 | wacom_input_event(wcombo, EV_MSC, MSC_SERIAL, 0xffffffff); |
398 | return 1; | 417 | return 1; |
399 | } | 418 | } |
@@ -403,6 +422,12 @@ static int wacom_intuos_irq(struct wacom_wac *wacom, void *wcombo) | |||
403 | if (result) | 422 | if (result) |
404 | return result-1; | 423 | return result-1; |
405 | 424 | ||
425 | /* Only large I3 and I1 & I2 support Lense Cursor */ | ||
426 | if((wacom->tool[idx] == BTN_TOOL_LENS) | ||
427 | && ((wacom->features->type == INTUOS3) | ||
428 | || (wacom->features->type == INTUOS3S))) | ||
429 | return 0; | ||
430 | |||
406 | /* Cintiq doesn't send data when RDY bit isn't set */ | 431 | /* Cintiq doesn't send data when RDY bit isn't set */ |
407 | if ((wacom->features->type == CINTIQ) && !(data[1] & 0x40)) | 432 | if ((wacom->features->type == CINTIQ) && !(data[1] & 0x40)) |
408 | return 0; | 433 | return 0; |
@@ -554,11 +579,11 @@ static struct wacom_features wacom_features[] = { | |||
554 | { "Wacom Volito2 4x5", 8, 5104, 3712, 511, 63, GRAPHIRE }, | 579 | { "Wacom Volito2 4x5", 8, 5104, 3712, 511, 63, GRAPHIRE }, |
555 | { "Wacom Volito2 2x3", 8, 3248, 2320, 511, 63, GRAPHIRE }, | 580 | { "Wacom Volito2 2x3", 8, 3248, 2320, 511, 63, GRAPHIRE }, |
556 | { "Wacom PenPartner2", 8, 3250, 2320, 255, 63, GRAPHIRE }, | 581 | { "Wacom PenPartner2", 8, 3250, 2320, 255, 63, GRAPHIRE }, |
557 | { "Wacom Intuos 4x5", 10, 12700, 10600, 1023, 63, INTUOS }, | 582 | { "Wacom Intuos 4x5", 10, 12700, 10600, 1023, 31, INTUOS }, |
558 | { "Wacom Intuos 6x8", 10, 20320, 16240, 1023, 63, INTUOS }, | 583 | { "Wacom Intuos 6x8", 10, 20320, 16240, 1023, 31, INTUOS }, |
559 | { "Wacom Intuos 9x12", 10, 30480, 24060, 1023, 63, INTUOS }, | 584 | { "Wacom Intuos 9x12", 10, 30480, 24060, 1023, 31, INTUOS }, |
560 | { "Wacom Intuos 12x12", 10, 30480, 31680, 1023, 63, INTUOS }, | 585 | { "Wacom Intuos 12x12", 10, 30480, 31680, 1023, 31, INTUOS }, |
561 | { "Wacom Intuos 12x18", 10, 45720, 31680, 1023, 63, INTUOS }, | 586 | { "Wacom Intuos 12x18", 10, 45720, 31680, 1023, 31, INTUOS }, |
562 | { "Wacom PL400", 8, 5408, 4056, 255, 0, PL }, | 587 | { "Wacom PL400", 8, 5408, 4056, 255, 0, PL }, |
563 | { "Wacom PL500", 8, 6144, 4608, 255, 0, PL }, | 588 | { "Wacom PL500", 8, 6144, 4608, 255, 0, PL }, |
564 | { "Wacom PL600", 8, 6126, 4604, 255, 0, PL }, | 589 | { "Wacom PL600", 8, 6126, 4604, 255, 0, PL }, |
@@ -571,11 +596,11 @@ static struct wacom_features wacom_features[] = { | |||
571 | { "Wacom DTF521", 8, 6282, 4762, 511, 0, PL }, | 596 | { "Wacom DTF521", 8, 6282, 4762, 511, 0, PL }, |
572 | { "Wacom DTF720", 8, 6858, 5506, 511, 0, PL }, | 597 | { "Wacom DTF720", 8, 6858, 5506, 511, 0, PL }, |
573 | { "Wacom Cintiq Partner",8, 20480, 15360, 511, 0, PTU }, | 598 | { "Wacom Cintiq Partner",8, 20480, 15360, 511, 0, PTU }, |
574 | { "Wacom Intuos2 4x5", 10, 12700, 10600, 1023, 63, INTUOS }, | 599 | { "Wacom Intuos2 4x5", 10, 12700, 10600, 1023, 31, INTUOS }, |
575 | { "Wacom Intuos2 6x8", 10, 20320, 16240, 1023, 63, INTUOS }, | 600 | { "Wacom Intuos2 6x8", 10, 20320, 16240, 1023, 31, INTUOS }, |
576 | { "Wacom Intuos2 9x12", 10, 30480, 24060, 1023, 63, INTUOS }, | 601 | { "Wacom Intuos2 9x12", 10, 30480, 24060, 1023, 31, INTUOS }, |
577 | { "Wacom Intuos2 12x12", 10, 30480, 31680, 1023, 63, INTUOS }, | 602 | { "Wacom Intuos2 12x12", 10, 30480, 31680, 1023, 31, INTUOS }, |
578 | { "Wacom Intuos2 12x18", 10, 45720, 31680, 1023, 63, INTUOS }, | 603 | { "Wacom Intuos2 12x18", 10, 45720, 31680, 1023, 31, INTUOS }, |
579 | { "Wacom Intuos3 4x5", 10, 25400, 20320, 1023, 63, INTUOS3S }, | 604 | { "Wacom Intuos3 4x5", 10, 25400, 20320, 1023, 63, INTUOS3S }, |
580 | { "Wacom Intuos3 6x8", 10, 40640, 30480, 1023, 63, INTUOS3 }, | 605 | { "Wacom Intuos3 6x8", 10, 40640, 30480, 1023, 63, INTUOS3 }, |
581 | { "Wacom Intuos3 9x12", 10, 60960, 45720, 1023, 63, INTUOS3 }, | 606 | { "Wacom Intuos3 9x12", 10, 60960, 45720, 1023, 63, INTUOS3 }, |
@@ -584,7 +609,7 @@ static struct wacom_features wacom_features[] = { | |||
584 | { "Wacom Intuos3 6x11", 10, 54204, 31750, 1023, 63, INTUOS3 }, | 609 | { "Wacom Intuos3 6x11", 10, 54204, 31750, 1023, 63, INTUOS3 }, |
585 | { "Wacom Intuos3 4x6", 10, 31496, 19685, 1023, 63, INTUOS3S }, | 610 | { "Wacom Intuos3 4x6", 10, 31496, 19685, 1023, 63, INTUOS3S }, |
586 | { "Wacom Cintiq 21UX", 10, 87200, 65600, 1023, 63, CINTIQ }, | 611 | { "Wacom Cintiq 21UX", 10, 87200, 65600, 1023, 63, CINTIQ }, |
587 | { "Wacom Intuos2 6x8", 10, 20320, 16240, 1023, 63, INTUOS }, | 612 | { "Wacom Intuos2 6x8", 10, 20320, 16240, 1023, 31, INTUOS }, |
588 | { } | 613 | { } |
589 | }; | 614 | }; |
590 | 615 | ||
diff --git a/drivers/usb/input/wacom_wac.h b/drivers/usb/input/wacom_wac.h index a1d9ce007970..a23022287248 100644 --- a/drivers/usb/input/wacom_wac.h +++ b/drivers/usb/input/wacom_wac.h | |||
@@ -12,6 +12,7 @@ | |||
12 | #define STYLUS_DEVICE_ID 0x02 | 12 | #define STYLUS_DEVICE_ID 0x02 |
13 | #define CURSOR_DEVICE_ID 0x06 | 13 | #define CURSOR_DEVICE_ID 0x06 |
14 | #define ERASER_DEVICE_ID 0x0A | 14 | #define ERASER_DEVICE_ID 0x0A |
15 | #define PAD_DEVICE_ID 0x0F | ||
15 | 16 | ||
16 | enum { | 17 | enum { |
17 | PENPARTNER = 0, | 18 | PENPARTNER = 0, |
diff --git a/drivers/usb/misc/Kconfig b/drivers/usb/misc/Kconfig index a74bf8617e7f..9c7eb6144d02 100644 --- a/drivers/usb/misc/Kconfig +++ b/drivers/usb/misc/Kconfig | |||
@@ -88,6 +88,17 @@ config USB_LCD | |||
88 | To compile this driver as a module, choose M here: the | 88 | To compile this driver as a module, choose M here: the |
89 | module will be called usblcd. | 89 | module will be called usblcd. |
90 | 90 | ||
91 | config USB_BERRY_CHARGE | ||
92 | tristate "USB BlackBerry recharge support" | ||
93 | depends on USB | ||
94 | help | ||
95 | Say Y here if you want to connect a BlackBerry device to your | ||
96 | computer's USB port and have it automatically switch to "recharge" | ||
97 | mode. | ||
98 | |||
99 | To compile this driver as a module, choose M here: the | ||
100 | module will be called berry_charge. | ||
101 | |||
91 | config USB_LED | 102 | config USB_LED |
92 | tristate "USB LED driver support" | 103 | tristate "USB LED driver support" |
93 | depends on USB | 104 | depends on USB |
@@ -233,6 +244,20 @@ config USB_TRANCEVIBRATOR | |||
233 | To compile this driver as a module, choose M here: the | 244 | To compile this driver as a module, choose M here: the |
234 | module will be called trancevibrator. | 245 | module will be called trancevibrator. |
235 | 246 | ||
247 | config USB_IOWARRIOR | ||
248 | tristate "IO Warrior driver support" | ||
249 | depends on USB | ||
250 | help | ||
251 | Say Y here if you want to support the IO Warrior devices from Code | ||
252 | Mercenaries. This includes support for the following devices: | ||
253 | IO Warrior 40 | ||
254 | IO Warrior 24 | ||
255 | IO Warrior 56 | ||
256 | IO Warrior 24 Power Vampire | ||
257 | |||
258 | To compile this driver as a module, choose M here: the | ||
259 | module will be called iowarrior. | ||
260 | |||
236 | config USB_TEST | 261 | config USB_TEST |
237 | tristate "USB testing driver (DEVELOPMENT)" | 262 | tristate "USB testing driver (DEVELOPMENT)" |
238 | depends on USB && USB_DEVICEFS && EXPERIMENTAL | 263 | depends on USB && USB_DEVICEFS && EXPERIMENTAL |
diff --git a/drivers/usb/misc/Makefile b/drivers/usb/misc/Makefile index 2cba07d31971..b68e6b774f1a 100644 --- a/drivers/usb/misc/Makefile +++ b/drivers/usb/misc/Makefile | |||
@@ -6,12 +6,14 @@ | |||
6 | obj-$(CONFIG_USB_ADUTUX) += adutux.o | 6 | obj-$(CONFIG_USB_ADUTUX) += adutux.o |
7 | obj-$(CONFIG_USB_APPLEDISPLAY) += appledisplay.o | 7 | obj-$(CONFIG_USB_APPLEDISPLAY) += appledisplay.o |
8 | obj-$(CONFIG_USB_AUERSWALD) += auerswald.o | 8 | obj-$(CONFIG_USB_AUERSWALD) += auerswald.o |
9 | obj-$(CONFIG_USB_BERRY_CHARGE) += berry_charge.o | ||
9 | obj-$(CONFIG_USB_CYPRESS_CY7C63)+= cypress_cy7c63.o | 10 | obj-$(CONFIG_USB_CYPRESS_CY7C63)+= cypress_cy7c63.o |
10 | obj-$(CONFIG_USB_CYTHERM) += cytherm.o | 11 | obj-$(CONFIG_USB_CYTHERM) += cytherm.o |
11 | obj-$(CONFIG_USB_EMI26) += emi26.o | 12 | obj-$(CONFIG_USB_EMI26) += emi26.o |
12 | obj-$(CONFIG_USB_EMI62) += emi62.o | 13 | obj-$(CONFIG_USB_EMI62) += emi62.o |
13 | obj-$(CONFIG_USB_FTDI_ELAN) += ftdi-elan.o | 14 | obj-$(CONFIG_USB_FTDI_ELAN) += ftdi-elan.o |
14 | obj-$(CONFIG_USB_IDMOUSE) += idmouse.o | 15 | obj-$(CONFIG_USB_IDMOUSE) += idmouse.o |
16 | obj-$(CONFIG_USB_IOWARRIOR) += iowarrior.o | ||
15 | obj-$(CONFIG_USB_LCD) += usblcd.o | 17 | obj-$(CONFIG_USB_LCD) += usblcd.o |
16 | obj-$(CONFIG_USB_LD) += ldusb.o | 18 | obj-$(CONFIG_USB_LD) += ldusb.o |
17 | obj-$(CONFIG_USB_LED) += usbled.o | 19 | obj-$(CONFIG_USB_LED) += usbled.o |
diff --git a/drivers/usb/misc/adutux.c b/drivers/usb/misc/adutux.c index 75bfab95ab3c..77145f9db043 100644 --- a/drivers/usb/misc/adutux.c +++ b/drivers/usb/misc/adutux.c | |||
@@ -285,23 +285,24 @@ static int adu_open(struct inode *inode, struct file *file) | |||
285 | /* save device in the file's private structure */ | 285 | /* save device in the file's private structure */ |
286 | file->private_data = dev; | 286 | file->private_data = dev; |
287 | 287 | ||
288 | /* initialize in direction */ | 288 | if (dev->open_count == 1) { |
289 | dev->read_buffer_length = 0; | 289 | /* initialize in direction */ |
290 | 290 | dev->read_buffer_length = 0; | |
291 | /* fixup first read by having urb waiting for it */ | ||
292 | usb_fill_int_urb(dev->interrupt_in_urb,dev->udev, | ||
293 | usb_rcvintpipe(dev->udev, | ||
294 | dev->interrupt_in_endpoint->bEndpointAddress), | ||
295 | dev->interrupt_in_buffer, | ||
296 | le16_to_cpu(dev->interrupt_in_endpoint->wMaxPacketSize), | ||
297 | adu_interrupt_in_callback, dev, | ||
298 | dev->interrupt_in_endpoint->bInterval); | ||
299 | /* dev->interrupt_in_urb->transfer_flags |= URB_ASYNC_UNLINK; */ | ||
300 | dev->read_urb_finished = 0; | ||
301 | usb_submit_urb(dev->interrupt_in_urb, GFP_KERNEL); | ||
302 | /* we ignore failure */ | ||
303 | /* end of fixup for first read */ | ||
304 | 291 | ||
292 | /* fixup first read by having urb waiting for it */ | ||
293 | usb_fill_int_urb(dev->interrupt_in_urb,dev->udev, | ||
294 | usb_rcvintpipe(dev->udev, | ||
295 | dev->interrupt_in_endpoint->bEndpointAddress), | ||
296 | dev->interrupt_in_buffer, | ||
297 | le16_to_cpu(dev->interrupt_in_endpoint->wMaxPacketSize), | ||
298 | adu_interrupt_in_callback, dev, | ||
299 | dev->interrupt_in_endpoint->bInterval); | ||
300 | /* dev->interrupt_in_urb->transfer_flags |= URB_ASYNC_UNLINK; */ | ||
301 | dev->read_urb_finished = 0; | ||
302 | retval = usb_submit_urb(dev->interrupt_in_urb, GFP_KERNEL); | ||
303 | if (retval) | ||
304 | --dev->open_count; | ||
305 | } | ||
305 | up(&dev->sem); | 306 | up(&dev->sem); |
306 | 307 | ||
307 | exit_no_device: | 308 | exit_no_device: |
@@ -469,7 +470,7 @@ static ssize_t adu_read(struct file *file, __user char *buffer, size_t count, | |||
469 | adu_interrupt_in_callback, | 470 | adu_interrupt_in_callback, |
470 | dev, | 471 | dev, |
471 | dev->interrupt_in_endpoint->bInterval); | 472 | dev->interrupt_in_endpoint->bInterval); |
472 | retval = usb_submit_urb(dev->interrupt_in_urb, GFP_KERNEL); | 473 | retval = usb_submit_urb(dev->interrupt_in_urb, GFP_ATOMIC); |
473 | if (!retval) { | 474 | if (!retval) { |
474 | spin_unlock_irqrestore(&dev->buflock, flags); | 475 | spin_unlock_irqrestore(&dev->buflock, flags); |
475 | dbg(2," %s : submitted OK", __FUNCTION__); | 476 | dbg(2," %s : submitted OK", __FUNCTION__); |
@@ -539,7 +540,7 @@ static ssize_t adu_write(struct file *file, const __user char *buffer, | |||
539 | size_t bytes_written = 0; | 540 | size_t bytes_written = 0; |
540 | size_t bytes_to_write; | 541 | size_t bytes_to_write; |
541 | size_t buffer_size; | 542 | size_t buffer_size; |
542 | int retval = 0; | 543 | int retval; |
543 | int timeout = 0; | 544 | int timeout = 0; |
544 | 545 | ||
545 | dbg(2," %s : enter, count = %Zd", __FUNCTION__, count); | 546 | dbg(2," %s : enter, count = %Zd", __FUNCTION__, count); |
@@ -547,7 +548,9 @@ static ssize_t adu_write(struct file *file, const __user char *buffer, | |||
547 | dev = file->private_data; | 548 | dev = file->private_data; |
548 | 549 | ||
549 | /* lock this object */ | 550 | /* lock this object */ |
550 | down_interruptible(&dev->sem); | 551 | retval = down_interruptible(&dev->sem); |
552 | if (retval) | ||
553 | goto exit_nolock; | ||
551 | 554 | ||
552 | /* verify that the device wasn't unplugged */ | 555 | /* verify that the device wasn't unplugged */ |
553 | if (dev->udev == NULL || dev->minor == 0) { | 556 | if (dev->udev == NULL || dev->minor == 0) { |
@@ -575,7 +578,11 @@ static ssize_t adu_write(struct file *file, const __user char *buffer, | |||
575 | } | 578 | } |
576 | up(&dev->sem); | 579 | up(&dev->sem); |
577 | timeout = interruptible_sleep_on_timeout(&dev->write_wait, timeout); | 580 | timeout = interruptible_sleep_on_timeout(&dev->write_wait, timeout); |
578 | down_interruptible(&dev->sem); | 581 | retval = down_interruptible(&dev->sem); |
582 | if (retval) { | ||
583 | retval = bytes_written ? bytes_written : retval; | ||
584 | goto exit_nolock; | ||
585 | } | ||
579 | if (timeout > 0) { | 586 | if (timeout > 0) { |
580 | break; | 587 | break; |
581 | } | 588 | } |
@@ -637,6 +644,7 @@ static ssize_t adu_write(struct file *file, const __user char *buffer, | |||
637 | exit: | 644 | exit: |
638 | /* unlock the device */ | 645 | /* unlock the device */ |
639 | up(&dev->sem); | 646 | up(&dev->sem); |
647 | exit_nolock: | ||
640 | 648 | ||
641 | dbg(2," %s : leave, return value %d", __FUNCTION__, retval); | 649 | dbg(2," %s : leave, return value %d", __FUNCTION__, retval); |
642 | 650 | ||
diff --git a/drivers/usb/misc/appledisplay.c b/drivers/usb/misc/appledisplay.c index 32f0e3a5b022..cf70c16f0e3f 100644 --- a/drivers/usb/misc/appledisplay.c +++ b/drivers/usb/misc/appledisplay.c | |||
@@ -141,7 +141,7 @@ static int appledisplay_bl_update_status(struct backlight_device *bd) | |||
141 | int retval; | 141 | int retval; |
142 | 142 | ||
143 | pdata->msgdata[0] = 0x10; | 143 | pdata->msgdata[0] = 0x10; |
144 | pdata->msgdata[1] = bd->props->brightness; | 144 | pdata->msgdata[1] = bd->props.brightness; |
145 | 145 | ||
146 | retval = usb_control_msg( | 146 | retval = usb_control_msg( |
147 | pdata->udev, | 147 | pdata->udev, |
@@ -177,11 +177,9 @@ static int appledisplay_bl_get_brightness(struct backlight_device *bd) | |||
177 | return pdata->msgdata[1]; | 177 | return pdata->msgdata[1]; |
178 | } | 178 | } |
179 | 179 | ||
180 | static struct backlight_properties appledisplay_bl_data = { | 180 | static struct backlight_ops appledisplay_bl_data = { |
181 | .owner = THIS_MODULE, | ||
182 | .get_brightness = appledisplay_bl_get_brightness, | 181 | .get_brightness = appledisplay_bl_get_brightness, |
183 | .update_status = appledisplay_bl_update_status, | 182 | .update_status = appledisplay_bl_update_status, |
184 | .max_brightness = 0xFF | ||
185 | }; | 183 | }; |
186 | 184 | ||
187 | static void appledisplay_work(struct work_struct *work) | 185 | static void appledisplay_work(struct work_struct *work) |
@@ -190,11 +188,9 @@ static void appledisplay_work(struct work_struct *work) | |||
190 | container_of(work, struct appledisplay, work.work); | 188 | container_of(work, struct appledisplay, work.work); |
191 | int retval; | 189 | int retval; |
192 | 190 | ||
193 | up(&pdata->bd->sem); | ||
194 | retval = appledisplay_bl_get_brightness(pdata->bd); | 191 | retval = appledisplay_bl_get_brightness(pdata->bd); |
195 | if (retval >= 0) | 192 | if (retval >= 0) |
196 | pdata->bd->props->brightness = retval; | 193 | pdata->bd->props.brightness = retval; |
197 | down(&pdata->bd->sem); | ||
198 | 194 | ||
199 | /* Poll again in about 125ms if there's still a button pressed */ | 195 | /* Poll again in about 125ms if there's still a button pressed */ |
200 | if (pdata->button_pressed) | 196 | if (pdata->button_pressed) |
@@ -281,17 +277,17 @@ static int appledisplay_probe(struct usb_interface *iface, | |||
281 | /* Register backlight device */ | 277 | /* Register backlight device */ |
282 | snprintf(bl_name, sizeof(bl_name), "appledisplay%d", | 278 | snprintf(bl_name, sizeof(bl_name), "appledisplay%d", |
283 | atomic_inc_return(&count_displays) - 1); | 279 | atomic_inc_return(&count_displays) - 1); |
284 | pdata->bd = backlight_device_register(bl_name, NULL, | 280 | pdata->bd = backlight_device_register(bl_name, NULL, pdata, |
285 | pdata, &appledisplay_bl_data); | 281 | &appledisplay_bl_data); |
286 | if (IS_ERR(pdata->bd)) { | 282 | if (IS_ERR(pdata->bd)) { |
287 | err("appledisplay: Backlight registration failed"); | 283 | err("appledisplay: Backlight registration failed"); |
288 | goto error; | 284 | goto error; |
289 | } | 285 | } |
290 | 286 | ||
287 | pdata->bd->props.max_brightness = 0xff; | ||
288 | |||
291 | /* Try to get brightness */ | 289 | /* Try to get brightness */ |
292 | up(&pdata->bd->sem); | ||
293 | brightness = appledisplay_bl_get_brightness(pdata->bd); | 290 | brightness = appledisplay_bl_get_brightness(pdata->bd); |
294 | down(&pdata->bd->sem); | ||
295 | 291 | ||
296 | if (brightness < 0) { | 292 | if (brightness < 0) { |
297 | retval = brightness; | 293 | retval = brightness; |
@@ -300,9 +296,7 @@ static int appledisplay_probe(struct usb_interface *iface, | |||
300 | } | 296 | } |
301 | 297 | ||
302 | /* Set brightness in backlight device */ | 298 | /* Set brightness in backlight device */ |
303 | up(&pdata->bd->sem); | 299 | pdata->bd->props.brightness = brightness; |
304 | pdata->bd->props->brightness = brightness; | ||
305 | down(&pdata->bd->sem); | ||
306 | 300 | ||
307 | /* save our data pointer in the interface device */ | 301 | /* save our data pointer in the interface device */ |
308 | usb_set_intfdata(iface, pdata); | 302 | usb_set_intfdata(iface, pdata); |
diff --git a/drivers/usb/misc/berry_charge.c b/drivers/usb/misc/berry_charge.c new file mode 100644 index 000000000000..b15f2fd8dab4 --- /dev/null +++ b/drivers/usb/misc/berry_charge.c | |||
@@ -0,0 +1,140 @@ | |||
1 | /* | ||
2 | * USB BlackBerry charging module | ||
3 | * | ||
4 | * Copyright (C) 2007 Greg Kroah-Hartman <gregkh@suse.de> | ||
5 | * | ||
6 | * This program is free software; you can redistribute it and/or | ||
7 | * modify it under the terms of the GNU General Public License as | ||
8 | * published by the Free Software Foundation, version 2. | ||
9 | * | ||
10 | * Information on how to switch configs was taken by the bcharge.cc file | ||
11 | * created by the barry.sf.net project. | ||
12 | * | ||
13 | * bcharge.cc has the following copyright: | ||
14 | * Copyright (C) 2006, Net Direct Inc. (http://www.netdirect.ca/) | ||
15 | * and is released under the GPLv2. | ||
16 | * | ||
17 | * | ||
18 | */ | ||
19 | |||
20 | #include <linux/kernel.h> | ||
21 | #include <linux/errno.h> | ||
22 | #include <linux/init.h> | ||
23 | #include <linux/slab.h> | ||
24 | #include <linux/module.h> | ||
25 | #include <linux/usb.h> | ||
26 | |||
27 | #define RIM_VENDOR 0x0fca | ||
28 | #define BLACKBERRY 0x0001 | ||
29 | |||
30 | static int debug; | ||
31 | |||
32 | #ifdef dbg | ||
33 | #undef dbg | ||
34 | #endif | ||
35 | #define dbg(dev, format, arg...) \ | ||
36 | if (debug) \ | ||
37 | dev_printk(KERN_DEBUG , dev , format , ## arg) | ||
38 | |||
39 | static struct usb_device_id id_table [] = { | ||
40 | { USB_DEVICE(RIM_VENDOR, BLACKBERRY) }, | ||
41 | { }, /* Terminating entry */ | ||
42 | }; | ||
43 | MODULE_DEVICE_TABLE(usb, id_table); | ||
44 | |||
45 | static int magic_charge(struct usb_device *udev) | ||
46 | { | ||
47 | char *dummy_buffer = kzalloc(2, GFP_KERNEL); | ||
48 | int retval; | ||
49 | |||
50 | if (!dummy_buffer) | ||
51 | return -ENOMEM; | ||
52 | |||
53 | /* send two magic commands and then set the configuration. The device | ||
54 | * will then reset itself with the new power usage and should start | ||
55 | * charging. */ | ||
56 | |||
57 | /* Note, with testing, it only seems that the first message is really | ||
58 | * needed (at least for the 8700c), but to be safe, we emulate what | ||
59 | * other operating systems seem to be sending to their device. We | ||
60 | * really need to get some specs for this device to be sure about what | ||
61 | * is going on here. | ||
62 | */ | ||
63 | dbg(&udev->dev, "Sending first magic command\n"); | ||
64 | retval = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0), | ||
65 | 0xa5, 0xc0, 0, 1, dummy_buffer, 2, 100); | ||
66 | if (retval != 2) { | ||
67 | dev_err(&udev->dev, "First magic command failed: %d.\n", | ||
68 | retval); | ||
69 | return retval; | ||
70 | } | ||
71 | |||
72 | dbg(&udev->dev, "Sending second magic command\n"); | ||
73 | retval = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0), | ||
74 | 0xa2, 0x40, 0, 1, dummy_buffer, 0, 100); | ||
75 | if (retval != 0) { | ||
76 | dev_err(&udev->dev, "Second magic command failed: %d.\n", | ||
77 | retval); | ||
78 | return retval; | ||
79 | } | ||
80 | |||
81 | dbg(&udev->dev, "Calling set_configuration\n"); | ||
82 | retval = usb_driver_set_configuration(udev, 1); | ||
83 | if (retval) | ||
84 | dev_err(&udev->dev, "Set Configuration failed :%d.\n", retval); | ||
85 | |||
86 | return retval; | ||
87 | } | ||
88 | |||
89 | static int berry_probe(struct usb_interface *intf, | ||
90 | const struct usb_device_id *id) | ||
91 | { | ||
92 | struct usb_device *udev = interface_to_usbdev(intf); | ||
93 | |||
94 | dbg(&udev->dev, "Power is set to %dmA\n", | ||
95 | udev->actconfig->desc.bMaxPower * 2); | ||
96 | |||
97 | /* check the power usage so we don't try to enable something that is | ||
98 | * already enabled */ | ||
99 | if ((udev->actconfig->desc.bMaxPower * 2) == 500) { | ||
100 | dbg(&udev->dev, "device is already charging, power is " | ||
101 | "set to %dmA\n", udev->actconfig->desc.bMaxPower * 2); | ||
102 | return -ENODEV; | ||
103 | } | ||
104 | |||
105 | /* turn the power on */ | ||
106 | magic_charge(udev); | ||
107 | |||
108 | /* we don't really want to bind to the device, userspace programs can | ||
109 | * handle the syncing just fine, so get outta here. */ | ||
110 | return -ENODEV; | ||
111 | } | ||
112 | |||
113 | static void berry_disconnect(struct usb_interface *intf) | ||
114 | { | ||
115 | } | ||
116 | |||
117 | static struct usb_driver berry_driver = { | ||
118 | .name = "berry_charge", | ||
119 | .probe = berry_probe, | ||
120 | .disconnect = berry_disconnect, | ||
121 | .id_table = id_table, | ||
122 | }; | ||
123 | |||
124 | static int __init berry_init(void) | ||
125 | { | ||
126 | return usb_register(&berry_driver); | ||
127 | } | ||
128 | |||
129 | static void __exit berry_exit(void) | ||
130 | { | ||
131 | usb_deregister(&berry_driver); | ||
132 | } | ||
133 | |||
134 | module_init(berry_init); | ||
135 | module_exit(berry_exit); | ||
136 | |||
137 | MODULE_LICENSE("GPL"); | ||
138 | MODULE_AUTHOR("Greg Kroah-Hartman <gregkh@suse.de>"); | ||
139 | module_param(debug, bool, S_IRUGO | S_IWUSR); | ||
140 | MODULE_PARM_DESC(debug, "Debug enabled or not"); | ||
diff --git a/drivers/usb/misc/cypress_cy7c63.c b/drivers/usb/misc/cypress_cy7c63.c index b63b5f34b2aa..d721380b242d 100644 --- a/drivers/usb/misc/cypress_cy7c63.c +++ b/drivers/usb/misc/cypress_cy7c63.c | |||
@@ -246,11 +246,13 @@ static void cypress_disconnect(struct usb_interface *interface) | |||
246 | struct cypress *dev; | 246 | struct cypress *dev; |
247 | 247 | ||
248 | dev = usb_get_intfdata(interface); | 248 | dev = usb_get_intfdata(interface); |
249 | usb_set_intfdata(interface, NULL); | ||
250 | 249 | ||
251 | /* remove device attribute files */ | 250 | /* remove device attribute files */ |
252 | device_remove_file(&interface->dev, &dev_attr_port0); | 251 | device_remove_file(&interface->dev, &dev_attr_port0); |
253 | device_remove_file(&interface->dev, &dev_attr_port1); | 252 | device_remove_file(&interface->dev, &dev_attr_port1); |
253 | /* the intfdata can be set to NULL only after the | ||
254 | * device files have been removed */ | ||
255 | usb_set_intfdata(interface, NULL); | ||
254 | 256 | ||
255 | usb_put_dev(dev->udev); | 257 | usb_put_dev(dev->udev); |
256 | 258 | ||
diff --git a/drivers/usb/misc/ftdi-elan.c b/drivers/usb/misc/ftdi-elan.c index 0c1d66ddb812..e2172e5cf152 100644 --- a/drivers/usb/misc/ftdi-elan.c +++ b/drivers/usb/misc/ftdi-elan.c | |||
@@ -2304,7 +2304,6 @@ static int ftdi_elan_checkingPCI(struct usb_ftdi *ftdi) | |||
2304 | #define OHCI_QUIRK_SUPERIO 0x02 | 2304 | #define OHCI_QUIRK_SUPERIO 0x02 |
2305 | #define OHCI_QUIRK_INITRESET 0x04 | 2305 | #define OHCI_QUIRK_INITRESET 0x04 |
2306 | #define OHCI_BIG_ENDIAN 0x08 | 2306 | #define OHCI_BIG_ENDIAN 0x08 |
2307 | #define OHCI_QUIRK_ZFMICRO 0x10 | ||
2308 | #define OHCI_CONTROL_INIT OHCI_CTRL_CBSR | 2307 | #define OHCI_CONTROL_INIT OHCI_CTRL_CBSR |
2309 | #define OHCI_INTR_INIT (OHCI_INTR_MIE | OHCI_INTR_UE | OHCI_INTR_RD | \ | 2308 | #define OHCI_INTR_INIT (OHCI_INTR_MIE | OHCI_INTR_UE | OHCI_INTR_RD | \ |
2310 | OHCI_INTR_WDH) | 2309 | OHCI_INTR_WDH) |
@@ -2905,17 +2904,35 @@ static int __init ftdi_elan_init(void) | |||
2905 | { | 2904 | { |
2906 | int result; | 2905 | int result; |
2907 | printk(KERN_INFO "driver %s built at %s on %s\n", ftdi_elan_driver.name, | 2906 | printk(KERN_INFO "driver %s built at %s on %s\n", ftdi_elan_driver.name, |
2908 | __TIME__, __DATE__); | 2907 | __TIME__, __DATE__); |
2909 | init_MUTEX(&ftdi_module_lock); | 2908 | init_MUTEX(&ftdi_module_lock); |
2910 | INIT_LIST_HEAD(&ftdi_static_list); | 2909 | INIT_LIST_HEAD(&ftdi_static_list); |
2911 | status_queue = create_singlethread_workqueue("ftdi-status-control"); | 2910 | status_queue = create_singlethread_workqueue("ftdi-status-control"); |
2911 | if (!status_queue) | ||
2912 | goto err_status_queue; | ||
2912 | command_queue = create_singlethread_workqueue("ftdi-command-engine"); | 2913 | command_queue = create_singlethread_workqueue("ftdi-command-engine"); |
2914 | if (!command_queue) | ||
2915 | goto err_command_queue; | ||
2913 | respond_queue = create_singlethread_workqueue("ftdi-respond-engine"); | 2916 | respond_queue = create_singlethread_workqueue("ftdi-respond-engine"); |
2917 | if (!respond_queue) | ||
2918 | goto err_respond_queue; | ||
2914 | result = usb_register(&ftdi_elan_driver); | 2919 | result = usb_register(&ftdi_elan_driver); |
2915 | if (result) | 2920 | if (result) { |
2921 | destroy_workqueue(status_queue); | ||
2922 | destroy_workqueue(command_queue); | ||
2923 | destroy_workqueue(respond_queue); | ||
2916 | printk(KERN_ERR "usb_register failed. Error number %d\n", | 2924 | printk(KERN_ERR "usb_register failed. Error number %d\n", |
2917 | result); | 2925 | result); |
2926 | } | ||
2918 | return result; | 2927 | return result; |
2928 | |||
2929 | err_respond_queue: | ||
2930 | destroy_workqueue(command_queue); | ||
2931 | err_command_queue: | ||
2932 | destroy_workqueue(status_queue); | ||
2933 | err_status_queue: | ||
2934 | printk(KERN_ERR "%s couldn't create workqueue\n", ftdi_elan_driver.name); | ||
2935 | return -ENOMEM; | ||
2919 | } | 2936 | } |
2920 | 2937 | ||
2921 | static void __exit ftdi_elan_exit(void) | 2938 | static void __exit ftdi_elan_exit(void) |
diff --git a/drivers/usb/misc/iowarrior.c b/drivers/usb/misc/iowarrior.c new file mode 100644 index 000000000000..fc51207b71b8 --- /dev/null +++ b/drivers/usb/misc/iowarrior.c | |||
@@ -0,0 +1,925 @@ | |||
1 | /* | ||
2 | * Native support for the I/O-Warrior USB devices | ||
3 | * | ||
4 | * Copyright (c) 2003-2005 Code Mercenaries GmbH | ||
5 | * written by Christian Lucht <lucht@codemercs.com> | ||
6 | * | ||
7 | * based on | ||
8 | |||
9 | * usb-skeleton.c by Greg Kroah-Hartman <greg@kroah.com> | ||
10 | * brlvger.c by Stephane Dalton <sdalton@videotron.ca> | ||
11 | * and St�hane Doyon <s.doyon@videotron.ca> | ||
12 | * | ||
13 | * Released under the GPLv2. | ||
14 | */ | ||
15 | |||
16 | #include <linux/module.h> | ||
17 | #include <linux/usb.h> | ||
18 | #include <linux/init.h> | ||
19 | #include <linux/slab.h> | ||
20 | #include <linux/sched.h> | ||
21 | #include <linux/poll.h> | ||
22 | #include <linux/version.h> | ||
23 | #include <linux/usb/iowarrior.h> | ||
24 | |||
25 | /* Version Information */ | ||
26 | #define DRIVER_VERSION "v0.4.0" | ||
27 | #define DRIVER_AUTHOR "Christian Lucht <lucht@codemercs.com>" | ||
28 | #define DRIVER_DESC "USB IO-Warrior driver (Linux 2.6.x)" | ||
29 | |||
30 | #define USB_VENDOR_ID_CODEMERCS 1984 | ||
31 | /* low speed iowarrior */ | ||
32 | #define USB_DEVICE_ID_CODEMERCS_IOW40 0x1500 | ||
33 | #define USB_DEVICE_ID_CODEMERCS_IOW24 0x1501 | ||
34 | #define USB_DEVICE_ID_CODEMERCS_IOWPV1 0x1511 | ||
35 | #define USB_DEVICE_ID_CODEMERCS_IOWPV2 0x1512 | ||
36 | /* full speed iowarrior */ | ||
37 | #define USB_DEVICE_ID_CODEMERCS_IOW56 0x1503 | ||
38 | |||
39 | /* Get a minor range for your devices from the usb maintainer */ | ||
40 | #ifdef CONFIG_USB_DYNAMIC_MINORS | ||
41 | #define IOWARRIOR_MINOR_BASE 0 | ||
42 | #else | ||
43 | #define IOWARRIOR_MINOR_BASE 208 // SKELETON_MINOR_BASE 192 + 16, not offical yet | ||
44 | #endif | ||
45 | |||
46 | /* interrupt input queue size */ | ||
47 | #define MAX_INTERRUPT_BUFFER 16 | ||
48 | /* | ||
49 | maximum number of urbs that are submitted for writes at the same time, | ||
50 | this applies to the IOWarrior56 only! | ||
51 | IOWarrior24 and IOWarrior40 use synchronous usb_control_msg calls. | ||
52 | */ | ||
53 | #define MAX_WRITES_IN_FLIGHT 4 | ||
54 | |||
55 | /* Use our own dbg macro */ | ||
56 | #undef dbg | ||
57 | #define dbg( format, arg... ) do { if( debug ) printk( KERN_DEBUG __FILE__ ": " format "\n" , ## arg ); } while ( 0 ) | ||
58 | |||
59 | MODULE_AUTHOR(DRIVER_AUTHOR); | ||
60 | MODULE_DESCRIPTION(DRIVER_DESC); | ||
61 | MODULE_LICENSE("GPL"); | ||
62 | |||
63 | /* Module parameters */ | ||
64 | static int debug = 0; | ||
65 | module_param(debug, bool, 0644); | ||
66 | MODULE_PARM_DESC(debug, "debug=1 enables debugging messages"); | ||
67 | |||
68 | static struct usb_driver iowarrior_driver; | ||
69 | |||
70 | /*--------------*/ | ||
71 | /* data */ | ||
72 | /*--------------*/ | ||
73 | |||
74 | /* Structure to hold all of our device specific stuff */ | ||
75 | struct iowarrior { | ||
76 | struct mutex mutex; /* locks this structure */ | ||
77 | struct usb_device *udev; /* save off the usb device pointer */ | ||
78 | struct usb_interface *interface; /* the interface for this device */ | ||
79 | unsigned char minor; /* the starting minor number for this device */ | ||
80 | struct usb_endpoint_descriptor *int_out_endpoint; /* endpoint for reading (needed for IOW56 only) */ | ||
81 | struct usb_endpoint_descriptor *int_in_endpoint; /* endpoint for reading */ | ||
82 | struct urb *int_in_urb; /* the urb for reading data */ | ||
83 | unsigned char *int_in_buffer; /* buffer for data to be read */ | ||
84 | unsigned char serial_number; /* to detect lost packages */ | ||
85 | unsigned char *read_queue; /* size is MAX_INTERRUPT_BUFFER * packet size */ | ||
86 | wait_queue_head_t read_wait; | ||
87 | wait_queue_head_t write_wait; /* wait-queue for writing to the device */ | ||
88 | atomic_t write_busy; /* number of write-urbs submitted */ | ||
89 | atomic_t read_idx; | ||
90 | atomic_t intr_idx; | ||
91 | spinlock_t intr_idx_lock; /* protects intr_idx */ | ||
92 | atomic_t overflow_flag; /* signals an index 'rollover' */ | ||
93 | int present; /* this is 1 as long as the device is connected */ | ||
94 | int opened; /* this is 1 if the device is currently open */ | ||
95 | char chip_serial[9]; /* the serial number string of the chip connected */ | ||
96 | int report_size; /* number of bytes in a report */ | ||
97 | u16 product_id; | ||
98 | }; | ||
99 | |||
100 | /*--------------*/ | ||
101 | /* globals */ | ||
102 | /*--------------*/ | ||
103 | /* prevent races between open() and disconnect() */ | ||
104 | static DECLARE_MUTEX(disconnect_sem); | ||
105 | |||
106 | /* | ||
107 | * USB spec identifies 5 second timeouts. | ||
108 | */ | ||
109 | #define GET_TIMEOUT 5 | ||
110 | #define USB_REQ_GET_REPORT 0x01 | ||
111 | //#if 0 | ||
112 | static int usb_get_report(struct usb_device *dev, | ||
113 | struct usb_host_interface *inter, unsigned char type, | ||
114 | unsigned char id, void *buf, int size) | ||
115 | { | ||
116 | return usb_control_msg(dev, usb_rcvctrlpipe(dev, 0), | ||
117 | USB_REQ_GET_REPORT, | ||
118 | USB_DIR_IN | USB_TYPE_CLASS | | ||
119 | USB_RECIP_INTERFACE, (type << 8) + id, | ||
120 | inter->desc.bInterfaceNumber, buf, size, | ||
121 | GET_TIMEOUT*HZ); | ||
122 | } | ||
123 | //#endif | ||
124 | |||
125 | #define USB_REQ_SET_REPORT 0x09 | ||
126 | |||
127 | static int usb_set_report(struct usb_interface *intf, unsigned char type, | ||
128 | unsigned char id, void *buf, int size) | ||
129 | { | ||
130 | return usb_control_msg(interface_to_usbdev(intf), | ||
131 | usb_sndctrlpipe(interface_to_usbdev(intf), 0), | ||
132 | USB_REQ_SET_REPORT, | ||
133 | USB_TYPE_CLASS | USB_RECIP_INTERFACE, | ||
134 | (type << 8) + id, | ||
135 | intf->cur_altsetting->desc.bInterfaceNumber, buf, | ||
136 | size, HZ); | ||
137 | } | ||
138 | |||
139 | /*---------------------*/ | ||
140 | /* driver registration */ | ||
141 | /*---------------------*/ | ||
142 | /* table of devices that work with this driver */ | ||
143 | static struct usb_device_id iowarrior_ids[] = { | ||
144 | {USB_DEVICE(USB_VENDOR_ID_CODEMERCS, USB_DEVICE_ID_CODEMERCS_IOW40)}, | ||
145 | {USB_DEVICE(USB_VENDOR_ID_CODEMERCS, USB_DEVICE_ID_CODEMERCS_IOW24)}, | ||
146 | {USB_DEVICE(USB_VENDOR_ID_CODEMERCS, USB_DEVICE_ID_CODEMERCS_IOWPV1)}, | ||
147 | {USB_DEVICE(USB_VENDOR_ID_CODEMERCS, USB_DEVICE_ID_CODEMERCS_IOWPV2)}, | ||
148 | {USB_DEVICE(USB_VENDOR_ID_CODEMERCS, USB_DEVICE_ID_CODEMERCS_IOW56)}, | ||
149 | {} /* Terminating entry */ | ||
150 | }; | ||
151 | MODULE_DEVICE_TABLE(usb, iowarrior_ids); | ||
152 | |||
153 | /* | ||
154 | * USB callback handler for reading data | ||
155 | */ | ||
156 | static void iowarrior_callback(struct urb *urb) | ||
157 | { | ||
158 | struct iowarrior *dev = (struct iowarrior *)urb->context; | ||
159 | int intr_idx; | ||
160 | int read_idx; | ||
161 | int aux_idx; | ||
162 | int offset; | ||
163 | int status; | ||
164 | |||
165 | switch (urb->status) { | ||
166 | case 0: | ||
167 | /* success */ | ||
168 | break; | ||
169 | case -ECONNRESET: | ||
170 | case -ENOENT: | ||
171 | case -ESHUTDOWN: | ||
172 | return; | ||
173 | default: | ||
174 | goto exit; | ||
175 | } | ||
176 | |||
177 | spin_lock(&dev->intr_idx_lock); | ||
178 | intr_idx = atomic_read(&dev->intr_idx); | ||
179 | /* aux_idx become previous intr_idx */ | ||
180 | aux_idx = (intr_idx == 0) ? (MAX_INTERRUPT_BUFFER - 1) : (intr_idx - 1); | ||
181 | read_idx = atomic_read(&dev->read_idx); | ||
182 | |||
183 | /* queue is not empty and it's interface 0 */ | ||
184 | if ((intr_idx != read_idx) | ||
185 | && (dev->interface->cur_altsetting->desc.bInterfaceNumber == 0)) { | ||
186 | /* + 1 for serial number */ | ||
187 | offset = aux_idx * (dev->report_size + 1); | ||
188 | if (!memcmp | ||
189 | (dev->read_queue + offset, urb->transfer_buffer, | ||
190 | dev->report_size)) { | ||
191 | /* equal values on interface 0 will be ignored */ | ||
192 | spin_unlock(&dev->intr_idx_lock); | ||
193 | goto exit; | ||
194 | } | ||
195 | } | ||
196 | |||
197 | /* aux_idx become next intr_idx */ | ||
198 | aux_idx = (intr_idx == (MAX_INTERRUPT_BUFFER - 1)) ? 0 : (intr_idx + 1); | ||
199 | if (read_idx == aux_idx) { | ||
200 | /* queue full, dropping oldest input */ | ||
201 | read_idx = (++read_idx == MAX_INTERRUPT_BUFFER) ? 0 : read_idx; | ||
202 | atomic_set(&dev->read_idx, read_idx); | ||
203 | atomic_set(&dev->overflow_flag, 1); | ||
204 | } | ||
205 | |||
206 | /* +1 for serial number */ | ||
207 | offset = intr_idx * (dev->report_size + 1); | ||
208 | memcpy(dev->read_queue + offset, urb->transfer_buffer, | ||
209 | dev->report_size); | ||
210 | *(dev->read_queue + offset + (dev->report_size)) = dev->serial_number++; | ||
211 | |||
212 | atomic_set(&dev->intr_idx, aux_idx); | ||
213 | spin_unlock(&dev->intr_idx_lock); | ||
214 | /* tell the blocking read about the new data */ | ||
215 | wake_up_interruptible(&dev->read_wait); | ||
216 | |||
217 | exit: | ||
218 | status = usb_submit_urb(urb, GFP_ATOMIC); | ||
219 | if (status) | ||
220 | dev_err(&dev->interface->dev, "%s - usb_submit_urb failed with result %d", | ||
221 | __FUNCTION__, status); | ||
222 | |||
223 | } | ||
224 | |||
225 | /* | ||
226 | * USB Callback handler for write-ops | ||
227 | */ | ||
228 | static void iowarrior_write_callback(struct urb *urb) | ||
229 | { | ||
230 | struct iowarrior *dev; | ||
231 | dev = (struct iowarrior *)urb->context; | ||
232 | /* sync/async unlink faults aren't errors */ | ||
233 | if (urb->status && | ||
234 | !(urb->status == -ENOENT || | ||
235 | urb->status == -ECONNRESET || urb->status == -ESHUTDOWN)) { | ||
236 | dbg("%s - nonzero write bulk status received: %d", | ||
237 | __func__, urb->status); | ||
238 | } | ||
239 | /* free up our allocated buffer */ | ||
240 | usb_buffer_free(urb->dev, urb->transfer_buffer_length, | ||
241 | urb->transfer_buffer, urb->transfer_dma); | ||
242 | /* tell a waiting writer the interrupt-out-pipe is available again */ | ||
243 | atomic_dec(&dev->write_busy); | ||
244 | wake_up_interruptible(&dev->write_wait); | ||
245 | } | ||
246 | |||
247 | /** | ||
248 | * iowarrior_delete | ||
249 | */ | ||
250 | static inline void iowarrior_delete(struct iowarrior *dev) | ||
251 | { | ||
252 | dbg("%s - minor %d", __func__, dev->minor); | ||
253 | kfree(dev->int_in_buffer); | ||
254 | usb_free_urb(dev->int_in_urb); | ||
255 | kfree(dev->read_queue); | ||
256 | kfree(dev); | ||
257 | } | ||
258 | |||
259 | /*---------------------*/ | ||
260 | /* fops implementation */ | ||
261 | /*---------------------*/ | ||
262 | |||
263 | static int read_index(struct iowarrior *dev) | ||
264 | { | ||
265 | int intr_idx, read_idx; | ||
266 | |||
267 | read_idx = atomic_read(&dev->read_idx); | ||
268 | intr_idx = atomic_read(&dev->intr_idx); | ||
269 | |||
270 | return (read_idx == intr_idx ? -1 : read_idx); | ||
271 | } | ||
272 | |||
273 | /** | ||
274 | * iowarrior_read | ||
275 | */ | ||
276 | static ssize_t iowarrior_read(struct file *file, char __user *buffer, | ||
277 | size_t count, loff_t *ppos) | ||
278 | { | ||
279 | struct iowarrior *dev; | ||
280 | int read_idx; | ||
281 | int offset; | ||
282 | |||
283 | dev = (struct iowarrior *)file->private_data; | ||
284 | |||
285 | /* verify that the device wasn't unplugged */ | ||
286 | if (dev == NULL || !dev->present) | ||
287 | return -ENODEV; | ||
288 | |||
289 | dbg("%s - minor %d, count = %zd", __func__, dev->minor, count); | ||
290 | |||
291 | /* read count must be packet size (+ time stamp) */ | ||
292 | if ((count != dev->report_size) | ||
293 | && (count != (dev->report_size + 1))) | ||
294 | return -EINVAL; | ||
295 | |||
296 | /* repeat until no buffer overrun in callback handler occur */ | ||
297 | do { | ||
298 | atomic_set(&dev->overflow_flag, 0); | ||
299 | if ((read_idx = read_index(dev)) == -1) { | ||
300 | /* queue emty */ | ||
301 | if (file->f_flags & O_NONBLOCK) | ||
302 | return -EAGAIN; | ||
303 | else { | ||
304 | //next line will return when there is either new data, or the device is unplugged | ||
305 | int r = wait_event_interruptible(dev->read_wait, | ||
306 | (!dev->present | ||
307 | || (read_idx = | ||
308 | read_index | ||
309 | (dev)) != | ||
310 | -1)); | ||
311 | if (r) { | ||
312 | //we were interrupted by a signal | ||
313 | return -ERESTART; | ||
314 | } | ||
315 | if (!dev->present) { | ||
316 | //The device was unplugged | ||
317 | return -ENODEV; | ||
318 | } | ||
319 | if (read_idx == -1) { | ||
320 | // Can this happen ??? | ||
321 | return 0; | ||
322 | } | ||
323 | } | ||
324 | } | ||
325 | |||
326 | offset = read_idx * (dev->report_size + 1); | ||
327 | if (copy_to_user(buffer, dev->read_queue + offset, count)) { | ||
328 | return -EFAULT; | ||
329 | } | ||
330 | } while (atomic_read(&dev->overflow_flag)); | ||
331 | |||
332 | read_idx = ++read_idx == MAX_INTERRUPT_BUFFER ? 0 : read_idx; | ||
333 | atomic_set(&dev->read_idx, read_idx); | ||
334 | return count; | ||
335 | } | ||
336 | |||
337 | /* | ||
338 | * iowarrior_write | ||
339 | */ | ||
340 | static ssize_t iowarrior_write(struct file *file, | ||
341 | const char __user *user_buffer, | ||
342 | size_t count, loff_t *ppos) | ||
343 | { | ||
344 | struct iowarrior *dev; | ||
345 | int retval = 0; | ||
346 | char *buf = NULL; /* for IOW24 and IOW56 we need a buffer */ | ||
347 | struct urb *int_out_urb = NULL; | ||
348 | |||
349 | dev = (struct iowarrior *)file->private_data; | ||
350 | |||
351 | mutex_lock(&dev->mutex); | ||
352 | /* verify that the device wasn't unplugged */ | ||
353 | if (dev == NULL || !dev->present) { | ||
354 | retval = -ENODEV; | ||
355 | goto exit; | ||
356 | } | ||
357 | dbg("%s - minor %d, count = %zd", __func__, dev->minor, count); | ||
358 | /* if count is 0 we're already done */ | ||
359 | if (count == 0) { | ||
360 | retval = 0; | ||
361 | goto exit; | ||
362 | } | ||
363 | /* We only accept full reports */ | ||
364 | if (count != dev->report_size) { | ||
365 | retval = -EINVAL; | ||
366 | goto exit; | ||
367 | } | ||
368 | switch (dev->product_id) { | ||
369 | case USB_DEVICE_ID_CODEMERCS_IOW24: | ||
370 | case USB_DEVICE_ID_CODEMERCS_IOWPV1: | ||
371 | case USB_DEVICE_ID_CODEMERCS_IOWPV2: | ||
372 | case USB_DEVICE_ID_CODEMERCS_IOW40: | ||
373 | /* IOW24 and IOW40 use a synchronous call */ | ||
374 | buf = kmalloc(8, GFP_KERNEL); /* 8 bytes are enough for both products */ | ||
375 | if (!buf) { | ||
376 | retval = -ENOMEM; | ||
377 | goto exit; | ||
378 | } | ||
379 | if (copy_from_user(buf, user_buffer, count)) { | ||
380 | retval = -EFAULT; | ||
381 | kfree(buf); | ||
382 | goto exit; | ||
383 | } | ||
384 | retval = usb_set_report(dev->interface, 2, 0, buf, count); | ||
385 | kfree(buf); | ||
386 | goto exit; | ||
387 | break; | ||
388 | case USB_DEVICE_ID_CODEMERCS_IOW56: | ||
389 | /* The IOW56 uses asynchronous IO and more urbs */ | ||
390 | if (atomic_read(&dev->write_busy) == MAX_WRITES_IN_FLIGHT) { | ||
391 | /* Wait until we are below the limit for submitted urbs */ | ||
392 | if (file->f_flags & O_NONBLOCK) { | ||
393 | retval = -EAGAIN; | ||
394 | goto exit; | ||
395 | } else { | ||
396 | retval = wait_event_interruptible(dev->write_wait, | ||
397 | (!dev->present || (atomic_read (&dev-> write_busy) < MAX_WRITES_IN_FLIGHT))); | ||
398 | if (retval) { | ||
399 | /* we were interrupted by a signal */ | ||
400 | retval = -ERESTART; | ||
401 | goto exit; | ||
402 | } | ||
403 | if (!dev->present) { | ||
404 | /* The device was unplugged */ | ||
405 | retval = -ENODEV; | ||
406 | goto exit; | ||
407 | } | ||
408 | if (!dev->opened) { | ||
409 | /* We were closed while waiting for an URB */ | ||
410 | retval = -ENODEV; | ||
411 | goto exit; | ||
412 | } | ||
413 | } | ||
414 | } | ||
415 | atomic_inc(&dev->write_busy); | ||
416 | int_out_urb = usb_alloc_urb(0, GFP_KERNEL); | ||
417 | if (!int_out_urb) { | ||
418 | retval = -ENOMEM; | ||
419 | dbg("%s Unable to allocate urb ", __func__); | ||
420 | goto error_no_urb; | ||
421 | } | ||
422 | buf = usb_buffer_alloc(dev->udev, dev->report_size, | ||
423 | GFP_KERNEL, &int_out_urb->transfer_dma); | ||
424 | if (!buf) { | ||
425 | retval = -ENOMEM; | ||
426 | dbg("%s Unable to allocate buffer ", __func__); | ||
427 | goto error_no_buffer; | ||
428 | } | ||
429 | usb_fill_int_urb(int_out_urb, dev->udev, | ||
430 | usb_sndintpipe(dev->udev, | ||
431 | dev->int_out_endpoint->bEndpointAddress), | ||
432 | buf, dev->report_size, | ||
433 | iowarrior_write_callback, dev, | ||
434 | dev->int_out_endpoint->bInterval); | ||
435 | int_out_urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; | ||
436 | if (copy_from_user(buf, user_buffer, count)) { | ||
437 | retval = -EFAULT; | ||
438 | goto error; | ||
439 | } | ||
440 | retval = usb_submit_urb(int_out_urb, GFP_KERNEL); | ||
441 | if (retval) { | ||
442 | dbg("%s submit error %d for urb nr.%d", __func__, | ||
443 | retval, atomic_read(&dev->write_busy)); | ||
444 | goto error; | ||
445 | } | ||
446 | /* submit was ok */ | ||
447 | retval = count; | ||
448 | usb_free_urb(int_out_urb); | ||
449 | goto exit; | ||
450 | break; | ||
451 | default: | ||
452 | /* what do we have here ? An unsupported Product-ID ? */ | ||
453 | dev_err(&dev->interface->dev, "%s - not supported for product=0x%x", | ||
454 | __FUNCTION__, dev->product_id); | ||
455 | retval = -EFAULT; | ||
456 | goto exit; | ||
457 | break; | ||
458 | } | ||
459 | error: | ||
460 | usb_buffer_free(dev->udev, dev->report_size, buf, | ||
461 | int_out_urb->transfer_dma); | ||
462 | error_no_buffer: | ||
463 | usb_free_urb(int_out_urb); | ||
464 | error_no_urb: | ||
465 | atomic_dec(&dev->write_busy); | ||
466 | wake_up_interruptible(&dev->write_wait); | ||
467 | exit: | ||
468 | mutex_unlock(&dev->mutex); | ||
469 | return retval; | ||
470 | } | ||
471 | |||
472 | /** | ||
473 | * iowarrior_ioctl | ||
474 | */ | ||
475 | static int iowarrior_ioctl(struct inode *inode, struct file *file, | ||
476 | unsigned int cmd, unsigned long arg) | ||
477 | { | ||
478 | struct iowarrior *dev = NULL; | ||
479 | __u8 *buffer; | ||
480 | __u8 __user *user_buffer; | ||
481 | int retval; | ||
482 | int io_res; /* checks for bytes read/written and copy_to/from_user results */ | ||
483 | |||
484 | dev = (struct iowarrior *)file->private_data; | ||
485 | if (dev == NULL) { | ||
486 | return -ENODEV; | ||
487 | } | ||
488 | |||
489 | buffer = kzalloc(dev->report_size, GFP_KERNEL); | ||
490 | if (!buffer) | ||
491 | return -ENOMEM; | ||
492 | |||
493 | /* lock this object */ | ||
494 | mutex_lock(&dev->mutex); | ||
495 | |||
496 | /* verify that the device wasn't unplugged */ | ||
497 | if (!dev->present) { | ||
498 | mutex_unlock(&dev->mutex); | ||
499 | return -ENODEV; | ||
500 | } | ||
501 | |||
502 | dbg("%s - minor %d, cmd 0x%.4x, arg %ld", __func__, dev->minor, cmd, | ||
503 | arg); | ||
504 | |||
505 | retval = 0; | ||
506 | io_res = 0; | ||
507 | switch (cmd) { | ||
508 | case IOW_WRITE: | ||
509 | if (dev->product_id == USB_DEVICE_ID_CODEMERCS_IOW24 || | ||
510 | dev->product_id == USB_DEVICE_ID_CODEMERCS_IOWPV1 || | ||
511 | dev->product_id == USB_DEVICE_ID_CODEMERCS_IOWPV2 || | ||
512 | dev->product_id == USB_DEVICE_ID_CODEMERCS_IOW40) { | ||
513 | user_buffer = (__u8 __user *)arg; | ||
514 | io_res = copy_from_user(buffer, user_buffer, | ||
515 | dev->report_size); | ||
516 | if (io_res) { | ||
517 | retval = -EFAULT; | ||
518 | } else { | ||
519 | io_res = usb_set_report(dev->interface, 2, 0, | ||
520 | buffer, | ||
521 | dev->report_size); | ||
522 | if (io_res < 0) | ||
523 | retval = io_res; | ||
524 | } | ||
525 | } else { | ||
526 | retval = -EINVAL; | ||
527 | dev_err(&dev->interface->dev, | ||
528 | "ioctl 'IOW_WRITE' is not supported for product=0x%x.", | ||
529 | dev->product_id); | ||
530 | } | ||
531 | break; | ||
532 | case IOW_READ: | ||
533 | user_buffer = (__u8 __user *)arg; | ||
534 | io_res = usb_get_report(dev->udev, | ||
535 | dev->interface->cur_altsetting, 1, 0, | ||
536 | buffer, dev->report_size); | ||
537 | if (io_res < 0) | ||
538 | retval = io_res; | ||
539 | else { | ||
540 | io_res = copy_to_user(user_buffer, buffer, dev->report_size); | ||
541 | if (io_res < 0) | ||
542 | retval = -EFAULT; | ||
543 | } | ||
544 | break; | ||
545 | case IOW_GETINFO: | ||
546 | { | ||
547 | /* Report available information for the device */ | ||
548 | struct iowarrior_info info; | ||
549 | /* needed for power consumption */ | ||
550 | struct usb_config_descriptor *cfg_descriptor = &dev->udev->actconfig->desc; | ||
551 | |||
552 | /* directly from the descriptor */ | ||
553 | info.vendor = le16_to_cpu(dev->udev->descriptor.idVendor); | ||
554 | info.product = dev->product_id; | ||
555 | info.revision = le16_to_cpu(dev->udev->descriptor.bcdDevice); | ||
556 | |||
557 | /* 0==UNKNOWN, 1==LOW(usb1.1) ,2=FULL(usb1.1), 3=HIGH(usb2.0) */ | ||
558 | info.speed = le16_to_cpu(dev->udev->speed); | ||
559 | info.if_num = dev->interface->cur_altsetting->desc.bInterfaceNumber; | ||
560 | info.report_size = dev->report_size; | ||
561 | |||
562 | /* serial number string has been read earlier 8 chars or empty string */ | ||
563 | memcpy(info.serial, dev->chip_serial, | ||
564 | sizeof(dev->chip_serial)); | ||
565 | if (cfg_descriptor == NULL) { | ||
566 | info.power = -1; /* no information available */ | ||
567 | } else { | ||
568 | /* the MaxPower is stored in units of 2mA to make it fit into a byte-value */ | ||
569 | info.power = cfg_descriptor->bMaxPower * 2; | ||
570 | } | ||
571 | io_res = copy_to_user((struct iowarrior_info __user *)arg, &info, | ||
572 | sizeof(struct iowarrior_info)); | ||
573 | if (io_res < 0) | ||
574 | retval = -EFAULT; | ||
575 | break; | ||
576 | } | ||
577 | default: | ||
578 | /* return that we did not understand this ioctl call */ | ||
579 | retval = -ENOTTY; | ||
580 | break; | ||
581 | } | ||
582 | |||
583 | /* unlock the device */ | ||
584 | mutex_unlock(&dev->mutex); | ||
585 | return retval; | ||
586 | } | ||
587 | |||
588 | /** | ||
589 | * iowarrior_open | ||
590 | */ | ||
591 | static int iowarrior_open(struct inode *inode, struct file *file) | ||
592 | { | ||
593 | struct iowarrior *dev = NULL; | ||
594 | struct usb_interface *interface; | ||
595 | int subminor; | ||
596 | int retval = 0; | ||
597 | |||
598 | dbg("%s", __func__); | ||
599 | |||
600 | subminor = iminor(inode); | ||
601 | |||
602 | /* prevent disconnects */ | ||
603 | down(&disconnect_sem); | ||
604 | |||
605 | interface = usb_find_interface(&iowarrior_driver, subminor); | ||
606 | if (!interface) { | ||
607 | err("%s - error, can't find device for minor %d", __FUNCTION__, | ||
608 | subminor); | ||
609 | retval = -ENODEV; | ||
610 | goto out; | ||
611 | } | ||
612 | |||
613 | dev = usb_get_intfdata(interface); | ||
614 | if (!dev) { | ||
615 | retval = -ENODEV; | ||
616 | goto out; | ||
617 | } | ||
618 | |||
619 | /* Only one process can open each device, no sharing. */ | ||
620 | if (dev->opened) { | ||
621 | retval = -EBUSY; | ||
622 | goto out; | ||
623 | } | ||
624 | |||
625 | /* setup interrupt handler for receiving values */ | ||
626 | if ((retval = usb_submit_urb(dev->int_in_urb, GFP_KERNEL)) < 0) { | ||
627 | dev_err(&interface->dev, "Error %d while submitting URB\n", retval); | ||
628 | retval = -EFAULT; | ||
629 | goto out; | ||
630 | } | ||
631 | /* increment our usage count for the driver */ | ||
632 | ++dev->opened; | ||
633 | /* save our object in the file's private structure */ | ||
634 | file->private_data = dev; | ||
635 | retval = 0; | ||
636 | |||
637 | out: | ||
638 | up(&disconnect_sem); | ||
639 | return retval; | ||
640 | } | ||
641 | |||
642 | /** | ||
643 | * iowarrior_release | ||
644 | */ | ||
645 | static int iowarrior_release(struct inode *inode, struct file *file) | ||
646 | { | ||
647 | struct iowarrior *dev; | ||
648 | int retval = 0; | ||
649 | |||
650 | dev = (struct iowarrior *)file->private_data; | ||
651 | if (dev == NULL) { | ||
652 | return -ENODEV; | ||
653 | } | ||
654 | |||
655 | dbg("%s - minor %d", __func__, dev->minor); | ||
656 | |||
657 | /* lock our device */ | ||
658 | mutex_lock(&dev->mutex); | ||
659 | |||
660 | if (dev->opened <= 0) { | ||
661 | retval = -ENODEV; /* close called more than once */ | ||
662 | mutex_unlock(&dev->mutex); | ||
663 | } else { | ||
664 | dev->opened = 0; /* we're closeing now */ | ||
665 | retval = 0; | ||
666 | if (dev->present) { | ||
667 | /* | ||
668 | The device is still connected so we only shutdown | ||
669 | pending read-/write-ops. | ||
670 | */ | ||
671 | usb_kill_urb(dev->int_in_urb); | ||
672 | wake_up_interruptible(&dev->read_wait); | ||
673 | wake_up_interruptible(&dev->write_wait); | ||
674 | mutex_unlock(&dev->mutex); | ||
675 | } else { | ||
676 | /* The device was unplugged, cleanup resources */ | ||
677 | mutex_unlock(&dev->mutex); | ||
678 | iowarrior_delete(dev); | ||
679 | } | ||
680 | } | ||
681 | return retval; | ||
682 | } | ||
683 | |||
684 | static unsigned iowarrior_poll(struct file *file, poll_table * wait) | ||
685 | { | ||
686 | struct iowarrior *dev = file->private_data; | ||
687 | unsigned int mask = 0; | ||
688 | |||
689 | if (!dev->present) | ||
690 | return POLLERR | POLLHUP; | ||
691 | |||
692 | poll_wait(file, &dev->read_wait, wait); | ||
693 | poll_wait(file, &dev->write_wait, wait); | ||
694 | |||
695 | if (!dev->present) | ||
696 | return POLLERR | POLLHUP; | ||
697 | |||
698 | if (read_index(dev) != -1) | ||
699 | mask |= POLLIN | POLLRDNORM; | ||
700 | |||
701 | if (atomic_read(&dev->write_busy) < MAX_WRITES_IN_FLIGHT) | ||
702 | mask |= POLLOUT | POLLWRNORM; | ||
703 | return mask; | ||
704 | } | ||
705 | |||
706 | /* | ||
707 | * File operations needed when we register this driver. | ||
708 | * This assumes that this driver NEEDS file operations, | ||
709 | * of course, which means that the driver is expected | ||
710 | * to have a node in the /dev directory. If the USB | ||
711 | * device were for a network interface then the driver | ||
712 | * would use "struct net_driver" instead, and a serial | ||
713 | * device would use "struct tty_driver". | ||
714 | */ | ||
715 | static struct file_operations iowarrior_fops = { | ||
716 | .owner = THIS_MODULE, | ||
717 | .write = iowarrior_write, | ||
718 | .read = iowarrior_read, | ||
719 | .ioctl = iowarrior_ioctl, | ||
720 | .open = iowarrior_open, | ||
721 | .release = iowarrior_release, | ||
722 | .poll = iowarrior_poll, | ||
723 | }; | ||
724 | |||
725 | /* | ||
726 | * usb class driver info in order to get a minor number from the usb core, | ||
727 | * and to have the device registered with devfs and the driver core | ||
728 | */ | ||
729 | static struct usb_class_driver iowarrior_class = { | ||
730 | .name = "iowarrior%d", | ||
731 | .fops = &iowarrior_fops, | ||
732 | .minor_base = IOWARRIOR_MINOR_BASE, | ||
733 | }; | ||
734 | |||
735 | /*---------------------------------*/ | ||
736 | /* probe and disconnect functions */ | ||
737 | /*---------------------------------*/ | ||
738 | /** | ||
739 | * iowarrior_probe | ||
740 | * | ||
741 | * Called by the usb core when a new device is connected that it thinks | ||
742 | * this driver might be interested in. | ||
743 | */ | ||
744 | static int iowarrior_probe(struct usb_interface *interface, | ||
745 | const struct usb_device_id *id) | ||
746 | { | ||
747 | struct usb_device *udev = interface_to_usbdev(interface); | ||
748 | struct iowarrior *dev = NULL; | ||
749 | struct usb_host_interface *iface_desc; | ||
750 | struct usb_endpoint_descriptor *endpoint; | ||
751 | int i; | ||
752 | int retval = -ENOMEM; | ||
753 | |||
754 | /* allocate memory for our device state and intialize it */ | ||
755 | dev = kzalloc(sizeof(struct iowarrior), GFP_KERNEL); | ||
756 | if (dev == NULL) { | ||
757 | dev_err(&interface->dev, "Out of memory"); | ||
758 | return retval; | ||
759 | } | ||
760 | |||
761 | mutex_init(&dev->mutex); | ||
762 | |||
763 | atomic_set(&dev->intr_idx, 0); | ||
764 | atomic_set(&dev->read_idx, 0); | ||
765 | spin_lock_init(&dev->intr_idx_lock); | ||
766 | atomic_set(&dev->overflow_flag, 0); | ||
767 | init_waitqueue_head(&dev->read_wait); | ||
768 | atomic_set(&dev->write_busy, 0); | ||
769 | init_waitqueue_head(&dev->write_wait); | ||
770 | |||
771 | dev->udev = udev; | ||
772 | dev->interface = interface; | ||
773 | |||
774 | iface_desc = interface->cur_altsetting; | ||
775 | dev->product_id = le16_to_cpu(udev->descriptor.idProduct); | ||
776 | |||
777 | /* set up the endpoint information */ | ||
778 | for (i = 0; i < iface_desc->desc.bNumEndpoints; ++i) { | ||
779 | endpoint = &iface_desc->endpoint[i].desc; | ||
780 | |||
781 | if (usb_endpoint_is_int_in(endpoint)) | ||
782 | dev->int_in_endpoint = endpoint; | ||
783 | if (usb_endpoint_is_int_out(endpoint)) | ||
784 | /* this one will match for the IOWarrior56 only */ | ||
785 | dev->int_out_endpoint = endpoint; | ||
786 | } | ||
787 | /* we have to check the report_size often, so remember it in the endianess suitable for our machine */ | ||
788 | dev->report_size = le16_to_cpu(dev->int_in_endpoint->wMaxPacketSize); | ||
789 | if ((dev->interface->cur_altsetting->desc.bInterfaceNumber == 0) && | ||
790 | (dev->product_id == USB_DEVICE_ID_CODEMERCS_IOW56)) | ||
791 | /* IOWarrior56 has wMaxPacketSize different from report size */ | ||
792 | dev->report_size = 7; | ||
793 | |||
794 | /* create the urb and buffer for reading */ | ||
795 | dev->int_in_urb = usb_alloc_urb(0, GFP_KERNEL); | ||
796 | if (!dev->int_in_urb) { | ||
797 | dev_err(&interface->dev, "Couldn't allocate interrupt_in_urb\n"); | ||
798 | goto error; | ||
799 | } | ||
800 | dev->int_in_buffer = kmalloc(dev->report_size, GFP_KERNEL); | ||
801 | if (!dev->int_in_buffer) { | ||
802 | dev_err(&interface->dev, "Couldn't allocate int_in_buffer\n"); | ||
803 | goto error; | ||
804 | } | ||
805 | usb_fill_int_urb(dev->int_in_urb, dev->udev, | ||
806 | usb_rcvintpipe(dev->udev, | ||
807 | dev->int_in_endpoint->bEndpointAddress), | ||
808 | dev->int_in_buffer, dev->report_size, | ||
809 | iowarrior_callback, dev, | ||
810 | dev->int_in_endpoint->bInterval); | ||
811 | /* create an internal buffer for interrupt data from the device */ | ||
812 | dev->read_queue = | ||
813 | kmalloc(((dev->report_size + 1) * MAX_INTERRUPT_BUFFER), | ||
814 | GFP_KERNEL); | ||
815 | if (!dev->read_queue) { | ||
816 | dev_err(&interface->dev, "Couldn't allocate read_queue\n"); | ||
817 | goto error; | ||
818 | } | ||
819 | /* Get the serial-number of the chip */ | ||
820 | memset(dev->chip_serial, 0x00, sizeof(dev->chip_serial)); | ||
821 | usb_string(udev, udev->descriptor.iSerialNumber, dev->chip_serial, | ||
822 | sizeof(dev->chip_serial)); | ||
823 | if (strlen(dev->chip_serial) != 8) | ||
824 | memset(dev->chip_serial, 0x00, sizeof(dev->chip_serial)); | ||
825 | |||
826 | /* Set the idle timeout to 0, if this is interface 0 */ | ||
827 | if (dev->interface->cur_altsetting->desc.bInterfaceNumber == 0) { | ||
828 | usb_control_msg(udev, usb_sndctrlpipe(udev, 0), | ||
829 | 0x0A, | ||
830 | USB_TYPE_CLASS | USB_RECIP_INTERFACE, 0, | ||
831 | 0, NULL, 0, USB_CTRL_SET_TIMEOUT); | ||
832 | } | ||
833 | /* allow device read and ioctl */ | ||
834 | dev->present = 1; | ||
835 | |||
836 | /* we can register the device now, as it is ready */ | ||
837 | usb_set_intfdata(interface, dev); | ||
838 | |||
839 | retval = usb_register_dev(interface, &iowarrior_class); | ||
840 | if (retval) { | ||
841 | /* something prevented us from registering this driver */ | ||
842 | dev_err(&interface->dev, "Not able to get a minor for this device.\n"); | ||
843 | usb_set_intfdata(interface, NULL); | ||
844 | goto error; | ||
845 | } | ||
846 | |||
847 | dev->minor = interface->minor; | ||
848 | |||
849 | /* let the user know what node this device is now attached to */ | ||
850 | dev_info(&interface->dev, "IOWarrior product=0x%x, serial=%s interface=%d " | ||
851 | "now attached to iowarrior%d\n", dev->product_id, dev->chip_serial, | ||
852 | iface_desc->desc.bInterfaceNumber, dev->minor - IOWARRIOR_MINOR_BASE); | ||
853 | return retval; | ||
854 | |||
855 | error: | ||
856 | iowarrior_delete(dev); | ||
857 | return retval; | ||
858 | } | ||
859 | |||
860 | /** | ||
861 | * iowarrior_disconnect | ||
862 | * | ||
863 | * Called by the usb core when the device is removed from the system. | ||
864 | */ | ||
865 | static void iowarrior_disconnect(struct usb_interface *interface) | ||
866 | { | ||
867 | struct iowarrior *dev; | ||
868 | int minor; | ||
869 | |||
870 | /* prevent races with open() */ | ||
871 | down(&disconnect_sem); | ||
872 | |||
873 | dev = usb_get_intfdata(interface); | ||
874 | usb_set_intfdata(interface, NULL); | ||
875 | |||
876 | mutex_lock(&dev->mutex); | ||
877 | |||
878 | minor = dev->minor; | ||
879 | |||
880 | /* give back our minor */ | ||
881 | usb_deregister_dev(interface, &iowarrior_class); | ||
882 | |||
883 | /* prevent device read, write and ioctl */ | ||
884 | dev->present = 0; | ||
885 | |||
886 | mutex_unlock(&dev->mutex); | ||
887 | |||
888 | if (dev->opened) { | ||
889 | /* There is a process that holds a filedescriptor to the device , | ||
890 | so we only shutdown read-/write-ops going on. | ||
891 | Deleting the device is postponed until close() was called. | ||
892 | */ | ||
893 | usb_kill_urb(dev->int_in_urb); | ||
894 | wake_up_interruptible(&dev->read_wait); | ||
895 | wake_up_interruptible(&dev->write_wait); | ||
896 | } else { | ||
897 | /* no process is using the device, cleanup now */ | ||
898 | iowarrior_delete(dev); | ||
899 | } | ||
900 | up(&disconnect_sem); | ||
901 | |||
902 | dev_info(&interface->dev, "I/O-Warror #%d now disconnected\n", | ||
903 | minor - IOWARRIOR_MINOR_BASE); | ||
904 | } | ||
905 | |||
906 | /* usb specific object needed to register this driver with the usb subsystem */ | ||
907 | static struct usb_driver iowarrior_driver = { | ||
908 | .name = "iowarrior", | ||
909 | .probe = iowarrior_probe, | ||
910 | .disconnect = iowarrior_disconnect, | ||
911 | .id_table = iowarrior_ids, | ||
912 | }; | ||
913 | |||
914 | static int __init iowarrior_init(void) | ||
915 | { | ||
916 | return usb_register(&iowarrior_driver); | ||
917 | } | ||
918 | |||
919 | static void __exit iowarrior_exit(void) | ||
920 | { | ||
921 | usb_deregister(&iowarrior_driver); | ||
922 | } | ||
923 | |||
924 | module_init(iowarrior_init); | ||
925 | module_exit(iowarrior_exit); | ||
diff --git a/drivers/usb/misc/ldusb.c b/drivers/usb/misc/ldusb.c index 788a11e6772f..11555bde655b 100644 --- a/drivers/usb/misc/ldusb.c +++ b/drivers/usb/misc/ldusb.c | |||
@@ -62,6 +62,8 @@ | |||
62 | #define USB_DEVICE_ID_VERNIER_SKIP 0x0003 | 62 | #define USB_DEVICE_ID_VERNIER_SKIP 0x0003 |
63 | #define USB_DEVICE_ID_VERNIER_CYCLOPS 0x0004 | 63 | #define USB_DEVICE_ID_VERNIER_CYCLOPS 0x0004 |
64 | 64 | ||
65 | #define USB_VENDOR_ID_MICROCHIP 0x04d8 | ||
66 | #define USB_DEVICE_ID_PICDEM 0x000c | ||
65 | 67 | ||
66 | #ifdef CONFIG_USB_DYNAMIC_MINORS | 68 | #ifdef CONFIG_USB_DYNAMIC_MINORS |
67 | #define USB_LD_MINOR_BASE 0 | 69 | #define USB_LD_MINOR_BASE 0 |
@@ -89,6 +91,7 @@ static struct usb_device_id ld_usb_table [] = { | |||
89 | { USB_DEVICE(USB_VENDOR_ID_VERNIER, USB_DEVICE_ID_VERNIER_GOTEMP) }, | 91 | { USB_DEVICE(USB_VENDOR_ID_VERNIER, USB_DEVICE_ID_VERNIER_GOTEMP) }, |
90 | { USB_DEVICE(USB_VENDOR_ID_VERNIER, USB_DEVICE_ID_VERNIER_SKIP) }, | 92 | { USB_DEVICE(USB_VENDOR_ID_VERNIER, USB_DEVICE_ID_VERNIER_SKIP) }, |
91 | { USB_DEVICE(USB_VENDOR_ID_VERNIER, USB_DEVICE_ID_VERNIER_CYCLOPS) }, | 93 | { USB_DEVICE(USB_VENDOR_ID_VERNIER, USB_DEVICE_ID_VERNIER_CYCLOPS) }, |
94 | { USB_DEVICE(USB_VENDOR_ID_MICROCHIP, USB_DEVICE_ID_PICDEM) }, | ||
92 | { } /* Terminating entry */ | 95 | { } /* Terminating entry */ |
93 | }; | 96 | }; |
94 | MODULE_DEVICE_TABLE(usb, ld_usb_table); | 97 | MODULE_DEVICE_TABLE(usb, ld_usb_table); |
diff --git a/drivers/usb/misc/usblcd.c b/drivers/usb/misc/usblcd.c index ada2ebc464ae..887ef953f3d8 100644 --- a/drivers/usb/misc/usblcd.c +++ b/drivers/usb/misc/usblcd.c | |||
@@ -47,6 +47,7 @@ struct usb_lcd { | |||
47 | #define to_lcd_dev(d) container_of(d, struct usb_lcd, kref) | 47 | #define to_lcd_dev(d) container_of(d, struct usb_lcd, kref) |
48 | 48 | ||
49 | static struct usb_driver lcd_driver; | 49 | static struct usb_driver lcd_driver; |
50 | static DEFINE_MUTEX(usb_lcd_open_mutex); | ||
50 | 51 | ||
51 | 52 | ||
52 | static void lcd_delete(struct kref *kref) | 53 | static void lcd_delete(struct kref *kref) |
@@ -68,6 +69,7 @@ static int lcd_open(struct inode *inode, struct file *file) | |||
68 | 69 | ||
69 | subminor = iminor(inode); | 70 | subminor = iminor(inode); |
70 | 71 | ||
72 | mutex_lock(&usb_lcd_open_mutex); | ||
71 | interface = usb_find_interface(&lcd_driver, subminor); | 73 | interface = usb_find_interface(&lcd_driver, subminor); |
72 | if (!interface) { | 74 | if (!interface) { |
73 | err ("USBLCD: %s - error, can't find device for minor %d", | 75 | err ("USBLCD: %s - error, can't find device for minor %d", |
@@ -89,6 +91,7 @@ static int lcd_open(struct inode *inode, struct file *file) | |||
89 | file->private_data = dev; | 91 | file->private_data = dev; |
90 | 92 | ||
91 | exit: | 93 | exit: |
94 | mutex_unlock(&usb_lcd_open_mutex); | ||
92 | return retval; | 95 | return retval; |
93 | } | 96 | } |
94 | 97 | ||
@@ -347,7 +350,7 @@ static void lcd_disconnect(struct usb_interface *interface) | |||
347 | int minor = interface->minor; | 350 | int minor = interface->minor; |
348 | 351 | ||
349 | /* prevent skel_open() from racing skel_disconnect() */ | 352 | /* prevent skel_open() from racing skel_disconnect() */ |
350 | lock_kernel(); | 353 | mutex_lock(&usb_lcd_open_mutex); |
351 | 354 | ||
352 | dev = usb_get_intfdata(interface); | 355 | dev = usb_get_intfdata(interface); |
353 | usb_set_intfdata(interface, NULL); | 356 | usb_set_intfdata(interface, NULL); |
@@ -355,7 +358,7 @@ static void lcd_disconnect(struct usb_interface *interface) | |||
355 | /* give back our minor */ | 358 | /* give back our minor */ |
356 | usb_deregister_dev(interface, &lcd_class); | 359 | usb_deregister_dev(interface, &lcd_class); |
357 | 360 | ||
358 | unlock_kernel(); | 361 | mutex_unlock(&usb_lcd_open_mutex); |
359 | 362 | ||
360 | /* decrement our usage count */ | 363 | /* decrement our usage count */ |
361 | kref_put(&dev->kref, lcd_delete); | 364 | kref_put(&dev->kref, lcd_delete); |
diff --git a/drivers/usb/mon/mon_bin.c b/drivers/usb/mon/mon_bin.c index c01dfe603672..0af11a66207c 100644 --- a/drivers/usb/mon/mon_bin.c +++ b/drivers/usb/mon/mon_bin.c | |||
@@ -356,8 +356,10 @@ static inline char mon_bin_get_setup(unsigned char *setupb, | |||
356 | if (!usb_pipecontrol(urb->pipe) || ev_type != 'S') | 356 | if (!usb_pipecontrol(urb->pipe) || ev_type != 'S') |
357 | return '-'; | 357 | return '-'; |
358 | 358 | ||
359 | if (urb->transfer_flags & URB_NO_SETUP_DMA_MAP) | 359 | if (urb->dev->bus->uses_dma && |
360 | (urb->transfer_flags & URB_NO_SETUP_DMA_MAP)) { | ||
360 | return mon_dmapeek(setupb, urb->setup_dma, SETUP_LEN); | 361 | return mon_dmapeek(setupb, urb->setup_dma, SETUP_LEN); |
362 | } | ||
361 | if (urb->setup_packet == NULL) | 363 | if (urb->setup_packet == NULL) |
362 | return 'Z'; | 364 | return 'Z'; |
363 | 365 | ||
@@ -369,7 +371,8 @@ static char mon_bin_get_data(const struct mon_reader_bin *rp, | |||
369 | unsigned int offset, struct urb *urb, unsigned int length) | 371 | unsigned int offset, struct urb *urb, unsigned int length) |
370 | { | 372 | { |
371 | 373 | ||
372 | if (urb->transfer_flags & URB_NO_TRANSFER_DMA_MAP) { | 374 | if (urb->dev->bus->uses_dma && |
375 | (urb->transfer_flags & URB_NO_TRANSFER_DMA_MAP)) { | ||
373 | mon_dmapeek_vec(rp, offset, urb->transfer_dma, length); | 376 | mon_dmapeek_vec(rp, offset, urb->transfer_dma, length); |
374 | return 0; | 377 | return 0; |
375 | } | 378 | } |
@@ -440,7 +443,7 @@ static void mon_bin_event(struct mon_reader_bin *rp, struct urb *urb, | |||
440 | /* We use the fact that usb_pipein() returns 0x80 */ | 443 | /* We use the fact that usb_pipein() returns 0x80 */ |
441 | ep->epnum = usb_pipeendpoint(urb->pipe) | usb_pipein(urb->pipe); | 444 | ep->epnum = usb_pipeendpoint(urb->pipe) | usb_pipein(urb->pipe); |
442 | ep->devnum = usb_pipedevice(urb->pipe); | 445 | ep->devnum = usb_pipedevice(urb->pipe); |
443 | ep->busnum = rp->r.m_bus->u_bus->busnum; | 446 | ep->busnum = urb->dev->bus->busnum; |
444 | ep->id = (unsigned long) urb; | 447 | ep->id = (unsigned long) urb; |
445 | ep->ts_sec = ts.tv_sec; | 448 | ep->ts_sec = ts.tv_sec; |
446 | ep->ts_usec = ts.tv_usec; | 449 | ep->ts_usec = ts.tv_usec; |
@@ -500,7 +503,7 @@ static void mon_bin_error(void *data, struct urb *urb, int error) | |||
500 | /* We use the fact that usb_pipein() returns 0x80 */ | 503 | /* We use the fact that usb_pipein() returns 0x80 */ |
501 | ep->epnum = usb_pipeendpoint(urb->pipe) | usb_pipein(urb->pipe); | 504 | ep->epnum = usb_pipeendpoint(urb->pipe) | usb_pipein(urb->pipe); |
502 | ep->devnum = usb_pipedevice(urb->pipe); | 505 | ep->devnum = usb_pipedevice(urb->pipe); |
503 | ep->busnum = rp->r.m_bus->u_bus->busnum; | 506 | ep->busnum = urb->dev->bus->busnum; |
504 | ep->id = (unsigned long) urb; | 507 | ep->id = (unsigned long) urb; |
505 | ep->status = error; | 508 | ep->status = error; |
506 | 509 | ||
@@ -515,7 +518,6 @@ static void mon_bin_error(void *data, struct urb *urb, int error) | |||
515 | static int mon_bin_open(struct inode *inode, struct file *file) | 518 | static int mon_bin_open(struct inode *inode, struct file *file) |
516 | { | 519 | { |
517 | struct mon_bus *mbus; | 520 | struct mon_bus *mbus; |
518 | struct usb_bus *ubus; | ||
519 | struct mon_reader_bin *rp; | 521 | struct mon_reader_bin *rp; |
520 | size_t size; | 522 | size_t size; |
521 | int rc; | 523 | int rc; |
@@ -525,7 +527,7 @@ static int mon_bin_open(struct inode *inode, struct file *file) | |||
525 | mutex_unlock(&mon_lock); | 527 | mutex_unlock(&mon_lock); |
526 | return -ENODEV; | 528 | return -ENODEV; |
527 | } | 529 | } |
528 | if ((ubus = mbus->u_bus) == NULL) { | 530 | if (mbus != &mon_bus0 && mbus->u_bus == NULL) { |
529 | printk(KERN_ERR TAG ": consistency error on open\n"); | 531 | printk(KERN_ERR TAG ": consistency error on open\n"); |
530 | mutex_unlock(&mon_lock); | 532 | mutex_unlock(&mon_lock); |
531 | return -ENODEV; | 533 | return -ENODEV; |
@@ -1165,7 +1167,7 @@ err_dev: | |||
1165 | return rc; | 1167 | return rc; |
1166 | } | 1168 | } |
1167 | 1169 | ||
1168 | void __exit mon_bin_exit(void) | 1170 | void mon_bin_exit(void) |
1169 | { | 1171 | { |
1170 | cdev_del(&mon_bin_cdev); | 1172 | cdev_del(&mon_bin_cdev); |
1171 | unregister_chrdev_region(mon_bin_dev0, MON_BIN_MAX_MINOR); | 1173 | unregister_chrdev_region(mon_bin_dev0, MON_BIN_MAX_MINOR); |
diff --git a/drivers/usb/mon/mon_main.c b/drivers/usb/mon/mon_main.c index c9739e7b35e5..8a1df2c9c73e 100644 --- a/drivers/usb/mon/mon_main.c +++ b/drivers/usb/mon/mon_main.c | |||
@@ -16,8 +16,6 @@ | |||
16 | #include "usb_mon.h" | 16 | #include "usb_mon.h" |
17 | #include "../core/hcd.h" | 17 | #include "../core/hcd.h" |
18 | 18 | ||
19 | static void mon_submit(struct usb_bus *ubus, struct urb *urb); | ||
20 | static void mon_complete(struct usb_bus *ubus, struct urb *urb); | ||
21 | static void mon_stop(struct mon_bus *mbus); | 19 | static void mon_stop(struct mon_bus *mbus); |
22 | static void mon_dissolve(struct mon_bus *mbus, struct usb_bus *ubus); | 20 | static void mon_dissolve(struct mon_bus *mbus, struct usb_bus *ubus); |
23 | static void mon_bus_drop(struct kref *r); | 21 | static void mon_bus_drop(struct kref *r); |
@@ -25,6 +23,7 @@ static void mon_bus_init(struct usb_bus *ubus); | |||
25 | 23 | ||
26 | DEFINE_MUTEX(mon_lock); | 24 | DEFINE_MUTEX(mon_lock); |
27 | 25 | ||
26 | struct mon_bus mon_bus0; /* Pseudo bus meaning "all buses" */ | ||
28 | static LIST_HEAD(mon_buses); /* All buses we know: struct mon_bus */ | 27 | static LIST_HEAD(mon_buses); /* All buses we know: struct mon_bus */ |
29 | 28 | ||
30 | /* | 29 | /* |
@@ -35,22 +34,19 @@ static LIST_HEAD(mon_buses); /* All buses we know: struct mon_bus */ | |||
35 | void mon_reader_add(struct mon_bus *mbus, struct mon_reader *r) | 34 | void mon_reader_add(struct mon_bus *mbus, struct mon_reader *r) |
36 | { | 35 | { |
37 | unsigned long flags; | 36 | unsigned long flags; |
38 | struct usb_bus *ubus; | 37 | struct list_head *p; |
39 | 38 | ||
40 | spin_lock_irqsave(&mbus->lock, flags); | 39 | spin_lock_irqsave(&mbus->lock, flags); |
41 | if (mbus->nreaders == 0) { | 40 | if (mbus->nreaders == 0) { |
42 | ubus = mbus->u_bus; | 41 | if (mbus == &mon_bus0) { |
43 | if (ubus->monitored) { | 42 | list_for_each (p, &mon_buses) { |
44 | /* | 43 | struct mon_bus *m1; |
45 | * Something is really broken, refuse to go on and | 44 | m1 = list_entry(p, struct mon_bus, bus_link); |
46 | * possibly corrupt ops pointers or worse. | 45 | m1->u_bus->monitored = 1; |
47 | */ | 46 | } |
48 | printk(KERN_ERR TAG ": bus %d is already monitored\n", | 47 | } else { |
49 | ubus->busnum); | 48 | mbus->u_bus->monitored = 1; |
50 | spin_unlock_irqrestore(&mbus->lock, flags); | ||
51 | return; | ||
52 | } | 49 | } |
53 | ubus->monitored = 1; | ||
54 | } | 50 | } |
55 | mbus->nreaders++; | 51 | mbus->nreaders++; |
56 | list_add_tail(&r->r_link, &mbus->r_list); | 52 | list_add_tail(&r->r_link, &mbus->r_list); |
@@ -80,77 +76,79 @@ void mon_reader_del(struct mon_bus *mbus, struct mon_reader *r) | |||
80 | 76 | ||
81 | /* | 77 | /* |
82 | */ | 78 | */ |
83 | static void mon_submit(struct usb_bus *ubus, struct urb *urb) | 79 | static void mon_bus_submit(struct mon_bus *mbus, struct urb *urb) |
84 | { | 80 | { |
85 | struct mon_bus *mbus; | ||
86 | unsigned long flags; | 81 | unsigned long flags; |
87 | struct list_head *pos; | 82 | struct list_head *pos; |
88 | struct mon_reader *r; | 83 | struct mon_reader *r; |
89 | 84 | ||
90 | mbus = ubus->mon_bus; | ||
91 | if (mbus == NULL) | ||
92 | goto out_unlocked; | ||
93 | |||
94 | spin_lock_irqsave(&mbus->lock, flags); | 85 | spin_lock_irqsave(&mbus->lock, flags); |
95 | if (mbus->nreaders == 0) | ||
96 | goto out_locked; | ||
97 | |||
98 | mbus->cnt_events++; | 86 | mbus->cnt_events++; |
99 | list_for_each (pos, &mbus->r_list) { | 87 | list_for_each (pos, &mbus->r_list) { |
100 | r = list_entry(pos, struct mon_reader, r_link); | 88 | r = list_entry(pos, struct mon_reader, r_link); |
101 | r->rnf_submit(r->r_data, urb); | 89 | r->rnf_submit(r->r_data, urb); |
102 | } | 90 | } |
103 | |||
104 | spin_unlock_irqrestore(&mbus->lock, flags); | 91 | spin_unlock_irqrestore(&mbus->lock, flags); |
105 | return; | 92 | return; |
93 | } | ||
106 | 94 | ||
107 | out_locked: | 95 | static void mon_submit(struct usb_bus *ubus, struct urb *urb) |
108 | spin_unlock_irqrestore(&mbus->lock, flags); | 96 | { |
109 | out_unlocked: | 97 | struct mon_bus *mbus; |
110 | return; | 98 | |
99 | if ((mbus = ubus->mon_bus) != NULL) | ||
100 | mon_bus_submit(mbus, urb); | ||
101 | mon_bus_submit(&mon_bus0, urb); | ||
111 | } | 102 | } |
112 | 103 | ||
113 | /* | 104 | /* |
114 | */ | 105 | */ |
115 | static void mon_submit_error(struct usb_bus *ubus, struct urb *urb, int error) | 106 | static void mon_bus_submit_error(struct mon_bus *mbus, struct urb *urb, int error) |
116 | { | 107 | { |
117 | struct mon_bus *mbus; | ||
118 | unsigned long flags; | 108 | unsigned long flags; |
119 | struct list_head *pos; | 109 | struct list_head *pos; |
120 | struct mon_reader *r; | 110 | struct mon_reader *r; |
121 | 111 | ||
122 | mbus = ubus->mon_bus; | ||
123 | if (mbus == NULL) | ||
124 | goto out_unlocked; | ||
125 | |||
126 | spin_lock_irqsave(&mbus->lock, flags); | 112 | spin_lock_irqsave(&mbus->lock, flags); |
127 | if (mbus->nreaders == 0) | ||
128 | goto out_locked; | ||
129 | |||
130 | mbus->cnt_events++; | 113 | mbus->cnt_events++; |
131 | list_for_each (pos, &mbus->r_list) { | 114 | list_for_each (pos, &mbus->r_list) { |
132 | r = list_entry(pos, struct mon_reader, r_link); | 115 | r = list_entry(pos, struct mon_reader, r_link); |
133 | r->rnf_error(r->r_data, urb, error); | 116 | r->rnf_error(r->r_data, urb, error); |
134 | } | 117 | } |
135 | |||
136 | spin_unlock_irqrestore(&mbus->lock, flags); | 118 | spin_unlock_irqrestore(&mbus->lock, flags); |
137 | return; | 119 | return; |
120 | } | ||
138 | 121 | ||
139 | out_locked: | 122 | static void mon_submit_error(struct usb_bus *ubus, struct urb *urb, int error) |
140 | spin_unlock_irqrestore(&mbus->lock, flags); | 123 | { |
141 | out_unlocked: | 124 | struct mon_bus *mbus; |
142 | return; | 125 | |
126 | if ((mbus = ubus->mon_bus) != NULL) | ||
127 | mon_bus_submit_error(mbus, urb, error); | ||
128 | mon_bus_submit_error(&mon_bus0, urb, error); | ||
143 | } | 129 | } |
144 | 130 | ||
145 | /* | 131 | /* |
146 | */ | 132 | */ |
147 | static void mon_complete(struct usb_bus *ubus, struct urb *urb) | 133 | static void mon_bus_complete(struct mon_bus *mbus, struct urb *urb) |
148 | { | 134 | { |
149 | struct mon_bus *mbus; | ||
150 | unsigned long flags; | 135 | unsigned long flags; |
151 | struct list_head *pos; | 136 | struct list_head *pos; |
152 | struct mon_reader *r; | 137 | struct mon_reader *r; |
153 | 138 | ||
139 | spin_lock_irqsave(&mbus->lock, flags); | ||
140 | mbus->cnt_events++; | ||
141 | list_for_each (pos, &mbus->r_list) { | ||
142 | r = list_entry(pos, struct mon_reader, r_link); | ||
143 | r->rnf_complete(r->r_data, urb); | ||
144 | } | ||
145 | spin_unlock_irqrestore(&mbus->lock, flags); | ||
146 | } | ||
147 | |||
148 | static void mon_complete(struct usb_bus *ubus, struct urb *urb) | ||
149 | { | ||
150 | struct mon_bus *mbus; | ||
151 | |||
154 | mbus = ubus->mon_bus; | 152 | mbus = ubus->mon_bus; |
155 | if (mbus == NULL) { | 153 | if (mbus == NULL) { |
156 | /* | 154 | /* |
@@ -162,13 +160,8 @@ static void mon_complete(struct usb_bus *ubus, struct urb *urb) | |||
162 | return; | 160 | return; |
163 | } | 161 | } |
164 | 162 | ||
165 | spin_lock_irqsave(&mbus->lock, flags); | 163 | mon_bus_complete(mbus, urb); |
166 | mbus->cnt_events++; | 164 | mon_bus_complete(&mon_bus0, urb); |
167 | list_for_each (pos, &mbus->r_list) { | ||
168 | r = list_entry(pos, struct mon_reader, r_link); | ||
169 | r->rnf_complete(r->r_data, urb); | ||
170 | } | ||
171 | spin_unlock_irqrestore(&mbus->lock, flags); | ||
172 | } | 165 | } |
173 | 166 | ||
174 | /* int (*unlink_urb) (struct urb *urb, int status); */ | 167 | /* int (*unlink_urb) (struct urb *urb, int status); */ |
@@ -179,14 +172,26 @@ static void mon_complete(struct usb_bus *ubus, struct urb *urb) | |||
179 | static void mon_stop(struct mon_bus *mbus) | 172 | static void mon_stop(struct mon_bus *mbus) |
180 | { | 173 | { |
181 | struct usb_bus *ubus = mbus->u_bus; | 174 | struct usb_bus *ubus = mbus->u_bus; |
175 | struct list_head *p; | ||
182 | 176 | ||
183 | /* | 177 | if (mbus == &mon_bus0) { |
184 | * A stop can be called for a dissolved mon_bus in case of | 178 | list_for_each (p, &mon_buses) { |
185 | * a reader staying across an rmmod foo_hcd. | 179 | mbus = list_entry(p, struct mon_bus, bus_link); |
186 | */ | 180 | /* |
187 | if (ubus != NULL) { | 181 | * We do not change nreaders here, so rely on mon_lock. |
188 | ubus->monitored = 0; | 182 | */ |
189 | mb(); | 183 | if (mbus->nreaders == 0 && (ubus = mbus->u_bus) != NULL) |
184 | ubus->monitored = 0; | ||
185 | } | ||
186 | } else { | ||
187 | /* | ||
188 | * A stop can be called for a dissolved mon_bus in case of | ||
189 | * a reader staying across an rmmod foo_hcd, so test ->u_bus. | ||
190 | */ | ||
191 | if (mon_bus0.nreaders == 0 && (ubus = mbus->u_bus) != NULL) { | ||
192 | ubus->monitored = 0; | ||
193 | mb(); | ||
194 | } | ||
190 | } | 195 | } |
191 | } | 196 | } |
192 | 197 | ||
@@ -199,6 +204,10 @@ static void mon_stop(struct mon_bus *mbus) | |||
199 | static void mon_bus_add(struct usb_bus *ubus) | 204 | static void mon_bus_add(struct usb_bus *ubus) |
200 | { | 205 | { |
201 | mon_bus_init(ubus); | 206 | mon_bus_init(ubus); |
207 | mutex_lock(&mon_lock); | ||
208 | if (mon_bus0.nreaders != 0) | ||
209 | ubus->monitored = 1; | ||
210 | mutex_unlock(&mon_lock); | ||
202 | } | 211 | } |
203 | 212 | ||
204 | /* | 213 | /* |
@@ -250,12 +259,7 @@ static struct usb_mon_operations mon_ops_0 = { | |||
250 | static void mon_dissolve(struct mon_bus *mbus, struct usb_bus *ubus) | 259 | static void mon_dissolve(struct mon_bus *mbus, struct usb_bus *ubus) |
251 | { | 260 | { |
252 | 261 | ||
253 | /* | ||
254 | * Never happens, but... | ||
255 | */ | ||
256 | if (ubus->monitored) { | 262 | if (ubus->monitored) { |
257 | printk(KERN_ERR TAG ": bus %d is dissolved while monitored\n", | ||
258 | ubus->busnum); | ||
259 | ubus->monitored = 0; | 263 | ubus->monitored = 0; |
260 | mb(); | 264 | mb(); |
261 | } | 265 | } |
@@ -263,6 +267,8 @@ static void mon_dissolve(struct mon_bus *mbus, struct usb_bus *ubus) | |||
263 | ubus->mon_bus = NULL; | 267 | ubus->mon_bus = NULL; |
264 | mbus->u_bus = NULL; | 268 | mbus->u_bus = NULL; |
265 | mb(); | 269 | mb(); |
270 | |||
271 | /* We want synchronize_irq() here, but that needs an argument. */ | ||
266 | } | 272 | } |
267 | 273 | ||
268 | /* | 274 | /* |
@@ -295,9 +301,8 @@ static void mon_bus_init(struct usb_bus *ubus) | |||
295 | */ | 301 | */ |
296 | mbus->u_bus = ubus; | 302 | mbus->u_bus = ubus; |
297 | ubus->mon_bus = mbus; | 303 | ubus->mon_bus = mbus; |
298 | mbus->uses_dma = ubus->uses_dma; | ||
299 | 304 | ||
300 | mbus->text_inited = mon_text_add(mbus, ubus); | 305 | mbus->text_inited = mon_text_add(mbus, ubus->busnum); |
301 | // mon_bin_add(...) | 306 | // mon_bin_add(...) |
302 | 307 | ||
303 | mutex_lock(&mon_lock); | 308 | mutex_lock(&mon_lock); |
@@ -309,6 +314,18 @@ err_alloc: | |||
309 | return; | 314 | return; |
310 | } | 315 | } |
311 | 316 | ||
317 | static void mon_bus0_init(void) | ||
318 | { | ||
319 | struct mon_bus *mbus = &mon_bus0; | ||
320 | |||
321 | kref_init(&mbus->ref); | ||
322 | spin_lock_init(&mbus->lock); | ||
323 | INIT_LIST_HEAD(&mbus->r_list); | ||
324 | |||
325 | mbus->text_inited = mon_text_add(mbus, 0); | ||
326 | // mbus->bin_inited = mon_bin_add(mbus, 0); | ||
327 | } | ||
328 | |||
312 | /* | 329 | /* |
313 | * Search a USB bus by number. Notice that USB bus numbers start from one, | 330 | * Search a USB bus by number. Notice that USB bus numbers start from one, |
314 | * which we may later use to identify "all" with zero. | 331 | * which we may later use to identify "all" with zero. |
@@ -322,6 +339,9 @@ struct mon_bus *mon_bus_lookup(unsigned int num) | |||
322 | struct list_head *p; | 339 | struct list_head *p; |
323 | struct mon_bus *mbus; | 340 | struct mon_bus *mbus; |
324 | 341 | ||
342 | if (num == 0) { | ||
343 | return &mon_bus0; | ||
344 | } | ||
325 | list_for_each (p, &mon_buses) { | 345 | list_for_each (p, &mon_buses) { |
326 | mbus = list_entry(p, struct mon_bus, bus_link); | 346 | mbus = list_entry(p, struct mon_bus, bus_link); |
327 | if (mbus->u_bus->busnum == num) { | 347 | if (mbus->u_bus->busnum == num) { |
@@ -341,6 +361,8 @@ static int __init mon_init(void) | |||
341 | if ((rc = mon_bin_init()) != 0) | 361 | if ((rc = mon_bin_init()) != 0) |
342 | goto err_bin; | 362 | goto err_bin; |
343 | 363 | ||
364 | mon_bus0_init(); | ||
365 | |||
344 | if (usb_mon_register(&mon_ops_0) != 0) { | 366 | if (usb_mon_register(&mon_ops_0) != 0) { |
345 | printk(KERN_NOTICE TAG ": unable to register with the core\n"); | 367 | printk(KERN_NOTICE TAG ": unable to register with the core\n"); |
346 | rc = -ENODEV; | 368 | rc = -ENODEV; |
@@ -374,6 +396,7 @@ static void __exit mon_exit(void) | |||
374 | usb_mon_deregister(); | 396 | usb_mon_deregister(); |
375 | 397 | ||
376 | mutex_lock(&mon_lock); | 398 | mutex_lock(&mon_lock); |
399 | |||
377 | while (!list_empty(&mon_buses)) { | 400 | while (!list_empty(&mon_buses)) { |
378 | p = mon_buses.next; | 401 | p = mon_buses.next; |
379 | mbus = list_entry(p, struct mon_bus, bus_link); | 402 | mbus = list_entry(p, struct mon_bus, bus_link); |
@@ -397,6 +420,11 @@ static void __exit mon_exit(void) | |||
397 | mon_dissolve(mbus, mbus->u_bus); | 420 | mon_dissolve(mbus, mbus->u_bus); |
398 | kref_put(&mbus->ref, mon_bus_drop); | 421 | kref_put(&mbus->ref, mon_bus_drop); |
399 | } | 422 | } |
423 | |||
424 | mbus = &mon_bus0; | ||
425 | if (mbus->text_inited) | ||
426 | mon_text_del(mbus); | ||
427 | |||
400 | mutex_unlock(&mon_lock); | 428 | mutex_unlock(&mon_lock); |
401 | 429 | ||
402 | mon_text_exit(); | 430 | mon_text_exit(); |
diff --git a/drivers/usb/mon/mon_text.c b/drivers/usb/mon/mon_text.c index d38a1279d9d9..ec0cc51e39ac 100644 --- a/drivers/usb/mon/mon_text.c +++ b/drivers/usb/mon/mon_text.c | |||
@@ -31,9 +31,21 @@ | |||
31 | * to a local DoS. But we have to keep to root in order to prevent | 31 | * to a local DoS. But we have to keep to root in order to prevent |
32 | * password sniffing from HID devices. | 32 | * password sniffing from HID devices. |
33 | */ | 33 | */ |
34 | #define EVENT_MAX (2*PAGE_SIZE / sizeof(struct mon_event_text)) | 34 | #define EVENT_MAX (4*PAGE_SIZE / sizeof(struct mon_event_text)) |
35 | 35 | ||
36 | #define PRINTF_DFL 160 | 36 | /* |
37 | * Potentially unlimited number; we limit it for similar allocations. | ||
38 | * The usbfs limits this to 128, but we're not quite as generous. | ||
39 | */ | ||
40 | #define ISODESC_MAX 5 | ||
41 | |||
42 | #define PRINTF_DFL 250 /* with 5 ISOs segs */ | ||
43 | |||
44 | struct mon_iso_desc { | ||
45 | int status; | ||
46 | unsigned int offset; | ||
47 | unsigned int length; /* Unsigned here, signed in URB. Historic. */ | ||
48 | }; | ||
37 | 49 | ||
38 | struct mon_event_text { | 50 | struct mon_event_text { |
39 | struct list_head e_link; | 51 | struct list_head e_link; |
@@ -41,10 +53,16 @@ struct mon_event_text { | |||
41 | unsigned int pipe; /* Pipe */ | 53 | unsigned int pipe; /* Pipe */ |
42 | unsigned long id; /* From pointer, most of the time */ | 54 | unsigned long id; /* From pointer, most of the time */ |
43 | unsigned int tstamp; | 55 | unsigned int tstamp; |
56 | int busnum; | ||
44 | int length; /* Depends on type: xfer length or act length */ | 57 | int length; /* Depends on type: xfer length or act length */ |
45 | int status; | 58 | int status; |
59 | int interval; | ||
60 | int start_frame; | ||
61 | int error_count; | ||
46 | char setup_flag; | 62 | char setup_flag; |
47 | char data_flag; | 63 | char data_flag; |
64 | int numdesc; /* Full number */ | ||
65 | struct mon_iso_desc isodesc[ISODESC_MAX]; | ||
48 | unsigned char setup[SETUP_MAX]; | 66 | unsigned char setup[SETUP_MAX]; |
49 | unsigned char data[DATA_MAX]; | 67 | unsigned char data[DATA_MAX]; |
50 | }; | 68 | }; |
@@ -68,6 +86,28 @@ static struct dentry *mon_dir; /* Usually /sys/kernel/debug/usbmon */ | |||
68 | 86 | ||
69 | static void mon_text_ctor(void *, struct kmem_cache *, unsigned long); | 87 | static void mon_text_ctor(void *, struct kmem_cache *, unsigned long); |
70 | 88 | ||
89 | struct mon_text_ptr { | ||
90 | int cnt, limit; | ||
91 | char *pbuf; | ||
92 | }; | ||
93 | |||
94 | static struct mon_event_text * | ||
95 | mon_text_read_wait(struct mon_reader_text *rp, struct file *file); | ||
96 | static void mon_text_read_head_t(struct mon_reader_text *rp, | ||
97 | struct mon_text_ptr *p, const struct mon_event_text *ep); | ||
98 | static void mon_text_read_head_u(struct mon_reader_text *rp, | ||
99 | struct mon_text_ptr *p, const struct mon_event_text *ep); | ||
100 | static void mon_text_read_statset(struct mon_reader_text *rp, | ||
101 | struct mon_text_ptr *p, const struct mon_event_text *ep); | ||
102 | static void mon_text_read_intstat(struct mon_reader_text *rp, | ||
103 | struct mon_text_ptr *p, const struct mon_event_text *ep); | ||
104 | static void mon_text_read_isostat(struct mon_reader_text *rp, | ||
105 | struct mon_text_ptr *p, const struct mon_event_text *ep); | ||
106 | static void mon_text_read_isodesc(struct mon_reader_text *rp, | ||
107 | struct mon_text_ptr *p, const struct mon_event_text *ep); | ||
108 | static void mon_text_read_data(struct mon_reader_text *rp, | ||
109 | struct mon_text_ptr *p, const struct mon_event_text *ep); | ||
110 | |||
71 | /* | 111 | /* |
72 | * mon_text_submit | 112 | * mon_text_submit |
73 | * mon_text_complete | 113 | * mon_text_complete |
@@ -84,8 +124,10 @@ static inline char mon_text_get_setup(struct mon_event_text *ep, | |||
84 | if (!usb_pipecontrol(urb->pipe) || ev_type != 'S') | 124 | if (!usb_pipecontrol(urb->pipe) || ev_type != 'S') |
85 | return '-'; | 125 | return '-'; |
86 | 126 | ||
87 | if (mbus->uses_dma && (urb->transfer_flags & URB_NO_SETUP_DMA_MAP)) | 127 | if (urb->dev->bus->uses_dma && |
128 | (urb->transfer_flags & URB_NO_SETUP_DMA_MAP)) { | ||
88 | return mon_dmapeek(ep->setup, urb->setup_dma, SETUP_MAX); | 129 | return mon_dmapeek(ep->setup, urb->setup_dma, SETUP_MAX); |
130 | } | ||
89 | if (urb->setup_packet == NULL) | 131 | if (urb->setup_packet == NULL) |
90 | return 'Z'; /* '0' would be not as pretty. */ | 132 | return 'Z'; /* '0' would be not as pretty. */ |
91 | 133 | ||
@@ -104,10 +146,10 @@ static inline char mon_text_get_data(struct mon_event_text *ep, struct urb *urb, | |||
104 | len = DATA_MAX; | 146 | len = DATA_MAX; |
105 | 147 | ||
106 | if (usb_pipein(pipe)) { | 148 | if (usb_pipein(pipe)) { |
107 | if (ev_type == 'S') | 149 | if (ev_type != 'C') |
108 | return '<'; | 150 | return '<'; |
109 | } else { | 151 | } else { |
110 | if (ev_type == 'C') | 152 | if (ev_type != 'S') |
111 | return '>'; | 153 | return '>'; |
112 | } | 154 | } |
113 | 155 | ||
@@ -120,8 +162,10 @@ static inline char mon_text_get_data(struct mon_event_text *ep, struct urb *urb, | |||
120 | * contain non-NULL garbage in case the upper level promised to | 162 | * contain non-NULL garbage in case the upper level promised to |
121 | * set DMA for the HCD. | 163 | * set DMA for the HCD. |
122 | */ | 164 | */ |
123 | if (mbus->uses_dma && (urb->transfer_flags & URB_NO_TRANSFER_DMA_MAP)) | 165 | if (urb->dev->bus->uses_dma && |
166 | (urb->transfer_flags & URB_NO_TRANSFER_DMA_MAP)) { | ||
124 | return mon_dmapeek(ep->data, urb->transfer_dma, len); | 167 | return mon_dmapeek(ep->data, urb->transfer_dma, len); |
168 | } | ||
125 | 169 | ||
126 | if (urb->transfer_buffer == NULL) | 170 | if (urb->transfer_buffer == NULL) |
127 | return 'Z'; /* '0' would be not as pretty. */ | 171 | return 'Z'; /* '0' would be not as pretty. */ |
@@ -146,6 +190,9 @@ static void mon_text_event(struct mon_reader_text *rp, struct urb *urb, | |||
146 | { | 190 | { |
147 | struct mon_event_text *ep; | 191 | struct mon_event_text *ep; |
148 | unsigned int stamp; | 192 | unsigned int stamp; |
193 | struct usb_iso_packet_descriptor *fp; | ||
194 | struct mon_iso_desc *dp; | ||
195 | int i, ndesc; | ||
149 | 196 | ||
150 | stamp = mon_get_timestamp(); | 197 | stamp = mon_get_timestamp(); |
151 | 198 | ||
@@ -158,12 +205,36 @@ static void mon_text_event(struct mon_reader_text *rp, struct urb *urb, | |||
158 | ep->type = ev_type; | 205 | ep->type = ev_type; |
159 | ep->pipe = urb->pipe; | 206 | ep->pipe = urb->pipe; |
160 | ep->id = (unsigned long) urb; | 207 | ep->id = (unsigned long) urb; |
208 | ep->busnum = urb->dev->bus->busnum; | ||
161 | ep->tstamp = stamp; | 209 | ep->tstamp = stamp; |
162 | ep->length = (ev_type == 'S') ? | 210 | ep->length = (ev_type == 'S') ? |
163 | urb->transfer_buffer_length : urb->actual_length; | 211 | urb->transfer_buffer_length : urb->actual_length; |
164 | /* Collecting status makes debugging sense for submits, too */ | 212 | /* Collecting status makes debugging sense for submits, too */ |
165 | ep->status = urb->status; | 213 | ep->status = urb->status; |
166 | 214 | ||
215 | if (usb_pipeint(urb->pipe)) { | ||
216 | ep->interval = urb->interval; | ||
217 | } else if (usb_pipeisoc(urb->pipe)) { | ||
218 | ep->interval = urb->interval; | ||
219 | ep->start_frame = urb->start_frame; | ||
220 | ep->error_count = urb->error_count; | ||
221 | } | ||
222 | ep->numdesc = urb->number_of_packets; | ||
223 | if (usb_pipeisoc(urb->pipe) && urb->number_of_packets > 0) { | ||
224 | if ((ndesc = urb->number_of_packets) > ISODESC_MAX) | ||
225 | ndesc = ISODESC_MAX; | ||
226 | fp = urb->iso_frame_desc; | ||
227 | dp = ep->isodesc; | ||
228 | for (i = 0; i < ndesc; i++) { | ||
229 | dp->status = fp->status; | ||
230 | dp->offset = fp->offset; | ||
231 | dp->length = (ev_type == 'S') ? | ||
232 | fp->length : fp->actual_length; | ||
233 | fp++; | ||
234 | dp++; | ||
235 | } | ||
236 | } | ||
237 | |||
167 | ep->setup_flag = mon_text_get_setup(ep, urb, ev_type, rp->r.m_bus); | 238 | ep->setup_flag = mon_text_get_setup(ep, urb, ev_type, rp->r.m_bus); |
168 | ep->data_flag = mon_text_get_data(ep, urb, ep->length, ev_type, | 239 | ep->data_flag = mon_text_get_data(ep, urb, ep->length, ev_type, |
169 | rp->r.m_bus); | 240 | rp->r.m_bus); |
@@ -199,6 +270,7 @@ static void mon_text_error(void *data, struct urb *urb, int error) | |||
199 | ep->type = 'E'; | 270 | ep->type = 'E'; |
200 | ep->pipe = urb->pipe; | 271 | ep->pipe = urb->pipe; |
201 | ep->id = (unsigned long) urb; | 272 | ep->id = (unsigned long) urb; |
273 | ep->busnum = 0; | ||
202 | ep->tstamp = 0; | 274 | ep->tstamp = 0; |
203 | ep->length = 0; | 275 | ep->length = 0; |
204 | ep->status = error; | 276 | ep->status = error; |
@@ -237,13 +309,11 @@ static struct mon_event_text *mon_text_fetch(struct mon_reader_text *rp, | |||
237 | static int mon_text_open(struct inode *inode, struct file *file) | 309 | static int mon_text_open(struct inode *inode, struct file *file) |
238 | { | 310 | { |
239 | struct mon_bus *mbus; | 311 | struct mon_bus *mbus; |
240 | struct usb_bus *ubus; | ||
241 | struct mon_reader_text *rp; | 312 | struct mon_reader_text *rp; |
242 | int rc; | 313 | int rc; |
243 | 314 | ||
244 | mutex_lock(&mon_lock); | 315 | mutex_lock(&mon_lock); |
245 | mbus = inode->i_private; | 316 | mbus = inode->i_private; |
246 | ubus = mbus->u_bus; | ||
247 | 317 | ||
248 | rp = kzalloc(sizeof(struct mon_reader_text), GFP_KERNEL); | 318 | rp = kzalloc(sizeof(struct mon_reader_text), GFP_KERNEL); |
249 | if (rp == NULL) { | 319 | if (rp == NULL) { |
@@ -267,8 +337,7 @@ static int mon_text_open(struct inode *inode, struct file *file) | |||
267 | rp->r.rnf_error = mon_text_error; | 337 | rp->r.rnf_error = mon_text_error; |
268 | rp->r.rnf_complete = mon_text_complete; | 338 | rp->r.rnf_complete = mon_text_complete; |
269 | 339 | ||
270 | snprintf(rp->slab_name, SLAB_NAME_SZ, "mon%dt_%lx", ubus->busnum, | 340 | snprintf(rp->slab_name, SLAB_NAME_SZ, "mon_text_%p", rp); |
271 | (long)rp); | ||
272 | rp->e_slab = kmem_cache_create(rp->slab_name, | 341 | rp->e_slab = kmem_cache_create(rp->slab_name, |
273 | sizeof(struct mon_event_text), sizeof(long), 0, | 342 | sizeof(struct mon_event_text), sizeof(long), 0, |
274 | mon_text_ctor, NULL); | 343 | mon_text_ctor, NULL); |
@@ -300,17 +369,75 @@ err_alloc: | |||
300 | * dd if=/dbg/usbmon/0t bs=10 | 369 | * dd if=/dbg/usbmon/0t bs=10 |
301 | * Also, we do not allow seeks and do not bother advancing the offset. | 370 | * Also, we do not allow seeks and do not bother advancing the offset. |
302 | */ | 371 | */ |
303 | static ssize_t mon_text_read(struct file *file, char __user *buf, | 372 | static ssize_t mon_text_read_t(struct file *file, char __user *buf, |
304 | size_t nbytes, loff_t *ppos) | 373 | size_t nbytes, loff_t *ppos) |
305 | { | 374 | { |
306 | struct mon_reader_text *rp = file->private_data; | 375 | struct mon_reader_text *rp = file->private_data; |
376 | struct mon_event_text *ep; | ||
377 | struct mon_text_ptr ptr; | ||
378 | |||
379 | if (IS_ERR(ep = mon_text_read_wait(rp, file))) | ||
380 | return PTR_ERR(ep); | ||
381 | mutex_lock(&rp->printf_lock); | ||
382 | ptr.cnt = 0; | ||
383 | ptr.pbuf = rp->printf_buf; | ||
384 | ptr.limit = rp->printf_size; | ||
385 | |||
386 | mon_text_read_head_t(rp, &ptr, ep); | ||
387 | mon_text_read_statset(rp, &ptr, ep); | ||
388 | ptr.cnt += snprintf(ptr.pbuf + ptr.cnt, ptr.limit - ptr.cnt, | ||
389 | " %d", ep->length); | ||
390 | mon_text_read_data(rp, &ptr, ep); | ||
391 | |||
392 | if (copy_to_user(buf, rp->printf_buf, ptr.cnt)) | ||
393 | ptr.cnt = -EFAULT; | ||
394 | mutex_unlock(&rp->printf_lock); | ||
395 | kmem_cache_free(rp->e_slab, ep); | ||
396 | return ptr.cnt; | ||
397 | } | ||
398 | |||
399 | static ssize_t mon_text_read_u(struct file *file, char __user *buf, | ||
400 | size_t nbytes, loff_t *ppos) | ||
401 | { | ||
402 | struct mon_reader_text *rp = file->private_data; | ||
403 | struct mon_event_text *ep; | ||
404 | struct mon_text_ptr ptr; | ||
405 | |||
406 | if (IS_ERR(ep = mon_text_read_wait(rp, file))) | ||
407 | return PTR_ERR(ep); | ||
408 | mutex_lock(&rp->printf_lock); | ||
409 | ptr.cnt = 0; | ||
410 | ptr.pbuf = rp->printf_buf; | ||
411 | ptr.limit = rp->printf_size; | ||
412 | |||
413 | mon_text_read_head_u(rp, &ptr, ep); | ||
414 | if (ep->type == 'E') { | ||
415 | mon_text_read_statset(rp, &ptr, ep); | ||
416 | } else if (usb_pipeisoc(ep->pipe)) { | ||
417 | mon_text_read_isostat(rp, &ptr, ep); | ||
418 | mon_text_read_isodesc(rp, &ptr, ep); | ||
419 | } else if (usb_pipeint(ep->pipe)) { | ||
420 | mon_text_read_intstat(rp, &ptr, ep); | ||
421 | } else { | ||
422 | mon_text_read_statset(rp, &ptr, ep); | ||
423 | } | ||
424 | ptr.cnt += snprintf(ptr.pbuf + ptr.cnt, ptr.limit - ptr.cnt, | ||
425 | " %d", ep->length); | ||
426 | mon_text_read_data(rp, &ptr, ep); | ||
427 | |||
428 | if (copy_to_user(buf, rp->printf_buf, ptr.cnt)) | ||
429 | ptr.cnt = -EFAULT; | ||
430 | mutex_unlock(&rp->printf_lock); | ||
431 | kmem_cache_free(rp->e_slab, ep); | ||
432 | return ptr.cnt; | ||
433 | } | ||
434 | |||
435 | static struct mon_event_text *mon_text_read_wait(struct mon_reader_text *rp, | ||
436 | struct file *file) | ||
437 | { | ||
307 | struct mon_bus *mbus = rp->r.m_bus; | 438 | struct mon_bus *mbus = rp->r.m_bus; |
308 | DECLARE_WAITQUEUE(waita, current); | 439 | DECLARE_WAITQUEUE(waita, current); |
309 | struct mon_event_text *ep; | 440 | struct mon_event_text *ep; |
310 | int cnt, limit; | ||
311 | char *pbuf; | ||
312 | char udir, utype; | ||
313 | int data_len, i; | ||
314 | 441 | ||
315 | add_wait_queue(&rp->wait, &waita); | 442 | add_wait_queue(&rp->wait, &waita); |
316 | set_current_state(TASK_INTERRUPTIBLE); | 443 | set_current_state(TASK_INTERRUPTIBLE); |
@@ -318,7 +445,7 @@ static ssize_t mon_text_read(struct file *file, char __user *buf, | |||
318 | if (file->f_flags & O_NONBLOCK) { | 445 | if (file->f_flags & O_NONBLOCK) { |
319 | set_current_state(TASK_RUNNING); | 446 | set_current_state(TASK_RUNNING); |
320 | remove_wait_queue(&rp->wait, &waita); | 447 | remove_wait_queue(&rp->wait, &waita); |
321 | return -EWOULDBLOCK; /* Same as EAGAIN in Linux */ | 448 | return ERR_PTR(-EWOULDBLOCK); |
322 | } | 449 | } |
323 | /* | 450 | /* |
324 | * We do not count nwaiters, because ->release is supposed | 451 | * We do not count nwaiters, because ->release is supposed |
@@ -327,17 +454,19 @@ static ssize_t mon_text_read(struct file *file, char __user *buf, | |||
327 | schedule(); | 454 | schedule(); |
328 | if (signal_pending(current)) { | 455 | if (signal_pending(current)) { |
329 | remove_wait_queue(&rp->wait, &waita); | 456 | remove_wait_queue(&rp->wait, &waita); |
330 | return -EINTR; | 457 | return ERR_PTR(-EINTR); |
331 | } | 458 | } |
332 | set_current_state(TASK_INTERRUPTIBLE); | 459 | set_current_state(TASK_INTERRUPTIBLE); |
333 | } | 460 | } |
334 | set_current_state(TASK_RUNNING); | 461 | set_current_state(TASK_RUNNING); |
335 | remove_wait_queue(&rp->wait, &waita); | 462 | remove_wait_queue(&rp->wait, &waita); |
463 | return ep; | ||
464 | } | ||
336 | 465 | ||
337 | mutex_lock(&rp->printf_lock); | 466 | static void mon_text_read_head_t(struct mon_reader_text *rp, |
338 | cnt = 0; | 467 | struct mon_text_ptr *p, const struct mon_event_text *ep) |
339 | pbuf = rp->printf_buf; | 468 | { |
340 | limit = rp->printf_size; | 469 | char udir, utype; |
341 | 470 | ||
342 | udir = usb_pipein(ep->pipe) ? 'i' : 'o'; | 471 | udir = usb_pipein(ep->pipe) ? 'i' : 'o'; |
343 | switch (usb_pipetype(ep->pipe)) { | 472 | switch (usb_pipetype(ep->pipe)) { |
@@ -346,13 +475,38 @@ static ssize_t mon_text_read(struct file *file, char __user *buf, | |||
346 | case PIPE_CONTROL: utype = 'C'; break; | 475 | case PIPE_CONTROL: utype = 'C'; break; |
347 | default: /* PIPE_BULK */ utype = 'B'; | 476 | default: /* PIPE_BULK */ utype = 'B'; |
348 | } | 477 | } |
349 | cnt += snprintf(pbuf + cnt, limit - cnt, | 478 | p->cnt += snprintf(p->pbuf + p->cnt, p->limit - p->cnt, |
350 | "%lx %u %c %c%c:%03u:%02u", | 479 | "%lx %u %c %c%c:%03u:%02u", |
351 | ep->id, ep->tstamp, ep->type, | 480 | ep->id, ep->tstamp, ep->type, |
352 | utype, udir, usb_pipedevice(ep->pipe), usb_pipeendpoint(ep->pipe)); | 481 | utype, udir, |
482 | usb_pipedevice(ep->pipe), usb_pipeendpoint(ep->pipe)); | ||
483 | } | ||
484 | |||
485 | static void mon_text_read_head_u(struct mon_reader_text *rp, | ||
486 | struct mon_text_ptr *p, const struct mon_event_text *ep) | ||
487 | { | ||
488 | char udir, utype; | ||
489 | |||
490 | udir = usb_pipein(ep->pipe) ? 'i' : 'o'; | ||
491 | switch (usb_pipetype(ep->pipe)) { | ||
492 | case PIPE_ISOCHRONOUS: utype = 'Z'; break; | ||
493 | case PIPE_INTERRUPT: utype = 'I'; break; | ||
494 | case PIPE_CONTROL: utype = 'C'; break; | ||
495 | default: /* PIPE_BULK */ utype = 'B'; | ||
496 | } | ||
497 | p->cnt += snprintf(p->pbuf + p->cnt, p->limit - p->cnt, | ||
498 | "%lx %u %c %c%c:%d:%03u:%u", | ||
499 | ep->id, ep->tstamp, ep->type, | ||
500 | utype, udir, | ||
501 | ep->busnum, usb_pipedevice(ep->pipe), usb_pipeendpoint(ep->pipe)); | ||
502 | } | ||
503 | |||
504 | static void mon_text_read_statset(struct mon_reader_text *rp, | ||
505 | struct mon_text_ptr *p, const struct mon_event_text *ep) | ||
506 | { | ||
353 | 507 | ||
354 | if (ep->setup_flag == 0) { /* Setup packet is present and captured */ | 508 | if (ep->setup_flag == 0) { /* Setup packet is present and captured */ |
355 | cnt += snprintf(pbuf + cnt, limit - cnt, | 509 | p->cnt += snprintf(p->pbuf + p->cnt, p->limit - p->cnt, |
356 | " s %02x %02x %04x %04x %04x", | 510 | " s %02x %02x %04x %04x %04x", |
357 | ep->setup[0], | 511 | ep->setup[0], |
358 | ep->setup[1], | 512 | ep->setup[1], |
@@ -360,40 +514,86 @@ static ssize_t mon_text_read(struct file *file, char __user *buf, | |||
360 | (ep->setup[5] << 8) | ep->setup[4], | 514 | (ep->setup[5] << 8) | ep->setup[4], |
361 | (ep->setup[7] << 8) | ep->setup[6]); | 515 | (ep->setup[7] << 8) | ep->setup[6]); |
362 | } else if (ep->setup_flag != '-') { /* Unable to capture setup packet */ | 516 | } else if (ep->setup_flag != '-') { /* Unable to capture setup packet */ |
363 | cnt += snprintf(pbuf + cnt, limit - cnt, | 517 | p->cnt += snprintf(p->pbuf + p->cnt, p->limit - p->cnt, |
364 | " %c __ __ ____ ____ ____", ep->setup_flag); | 518 | " %c __ __ ____ ____ ____", ep->setup_flag); |
365 | } else { /* No setup for this kind of URB */ | 519 | } else { /* No setup for this kind of URB */ |
366 | cnt += snprintf(pbuf + cnt, limit - cnt, " %d", ep->status); | 520 | p->cnt += snprintf(p->pbuf + p->cnt, p->limit - p->cnt, |
521 | " %d", ep->status); | ||
367 | } | 522 | } |
368 | cnt += snprintf(pbuf + cnt, limit - cnt, " %d", ep->length); | 523 | } |
524 | |||
525 | static void mon_text_read_intstat(struct mon_reader_text *rp, | ||
526 | struct mon_text_ptr *p, const struct mon_event_text *ep) | ||
527 | { | ||
528 | p->cnt += snprintf(p->pbuf + p->cnt, p->limit - p->cnt, | ||
529 | " %d:%d", ep->status, ep->interval); | ||
530 | } | ||
531 | |||
532 | static void mon_text_read_isostat(struct mon_reader_text *rp, | ||
533 | struct mon_text_ptr *p, const struct mon_event_text *ep) | ||
534 | { | ||
535 | if (ep->type == 'S') { | ||
536 | p->cnt += snprintf(p->pbuf + p->cnt, p->limit - p->cnt, | ||
537 | " %d:%d:%d", ep->status, ep->interval, ep->start_frame); | ||
538 | } else { | ||
539 | p->cnt += snprintf(p->pbuf + p->cnt, p->limit - p->cnt, | ||
540 | " %d:%d:%d:%d", | ||
541 | ep->status, ep->interval, ep->start_frame, ep->error_count); | ||
542 | } | ||
543 | } | ||
544 | |||
545 | static void mon_text_read_isodesc(struct mon_reader_text *rp, | ||
546 | struct mon_text_ptr *p, const struct mon_event_text *ep) | ||
547 | { | ||
548 | int ndesc; /* Display this many */ | ||
549 | int i; | ||
550 | const struct mon_iso_desc *dp; | ||
551 | |||
552 | p->cnt += snprintf(p->pbuf + p->cnt, p->limit - p->cnt, | ||
553 | " %d", ep->numdesc); | ||
554 | ndesc = ep->numdesc; | ||
555 | if (ndesc > ISODESC_MAX) | ||
556 | ndesc = ISODESC_MAX; | ||
557 | if (ndesc < 0) | ||
558 | ndesc = 0; | ||
559 | dp = ep->isodesc; | ||
560 | for (i = 0; i < ndesc; i++) { | ||
561 | p->cnt += snprintf(p->pbuf + p->cnt, p->limit - p->cnt, | ||
562 | " %d:%u:%u", dp->status, dp->offset, dp->length); | ||
563 | dp++; | ||
564 | } | ||
565 | } | ||
566 | |||
567 | static void mon_text_read_data(struct mon_reader_text *rp, | ||
568 | struct mon_text_ptr *p, const struct mon_event_text *ep) | ||
569 | { | ||
570 | int data_len, i; | ||
369 | 571 | ||
370 | if ((data_len = ep->length) > 0) { | 572 | if ((data_len = ep->length) > 0) { |
371 | if (ep->data_flag == 0) { | 573 | if (ep->data_flag == 0) { |
372 | cnt += snprintf(pbuf + cnt, limit - cnt, " ="); | 574 | p->cnt += snprintf(p->pbuf + p->cnt, p->limit - p->cnt, |
575 | " ="); | ||
373 | if (data_len >= DATA_MAX) | 576 | if (data_len >= DATA_MAX) |
374 | data_len = DATA_MAX; | 577 | data_len = DATA_MAX; |
375 | for (i = 0; i < data_len; i++) { | 578 | for (i = 0; i < data_len; i++) { |
376 | if (i % 4 == 0) { | 579 | if (i % 4 == 0) { |
377 | cnt += snprintf(pbuf + cnt, limit - cnt, | 580 | p->cnt += snprintf(p->pbuf + p->cnt, |
581 | p->limit - p->cnt, | ||
378 | " "); | 582 | " "); |
379 | } | 583 | } |
380 | cnt += snprintf(pbuf + cnt, limit - cnt, | 584 | p->cnt += snprintf(p->pbuf + p->cnt, |
585 | p->limit - p->cnt, | ||
381 | "%02x", ep->data[i]); | 586 | "%02x", ep->data[i]); |
382 | } | 587 | } |
383 | cnt += snprintf(pbuf + cnt, limit - cnt, "\n"); | 588 | p->cnt += snprintf(p->pbuf + p->cnt, p->limit - p->cnt, |
589 | "\n"); | ||
384 | } else { | 590 | } else { |
385 | cnt += snprintf(pbuf + cnt, limit - cnt, | 591 | p->cnt += snprintf(p->pbuf + p->cnt, p->limit - p->cnt, |
386 | " %c\n", ep->data_flag); | 592 | " %c\n", ep->data_flag); |
387 | } | 593 | } |
388 | } else { | 594 | } else { |
389 | cnt += snprintf(pbuf + cnt, limit - cnt, "\n"); | 595 | p->cnt += snprintf(p->pbuf + p->cnt, p->limit - p->cnt, "\n"); |
390 | } | 596 | } |
391 | |||
392 | if (copy_to_user(buf, rp->printf_buf, cnt)) | ||
393 | cnt = -EFAULT; | ||
394 | mutex_unlock(&rp->printf_lock); | ||
395 | kmem_cache_free(rp->e_slab, ep); | ||
396 | return cnt; | ||
397 | } | 597 | } |
398 | 598 | ||
399 | static int mon_text_release(struct inode *inode, struct file *file) | 599 | static int mon_text_release(struct inode *inode, struct file *file) |
@@ -439,34 +639,46 @@ static int mon_text_release(struct inode *inode, struct file *file) | |||
439 | return 0; | 639 | return 0; |
440 | } | 640 | } |
441 | 641 | ||
442 | static const struct file_operations mon_fops_text = { | 642 | static const struct file_operations mon_fops_text_t = { |
443 | .owner = THIS_MODULE, | 643 | .owner = THIS_MODULE, |
444 | .open = mon_text_open, | 644 | .open = mon_text_open, |
445 | .llseek = no_llseek, | 645 | .llseek = no_llseek, |
446 | .read = mon_text_read, | 646 | .read = mon_text_read_t, |
447 | /* .write = mon_text_write, */ | ||
448 | /* .poll = mon_text_poll, */ | ||
449 | /* .ioctl = mon_text_ioctl, */ | ||
450 | .release = mon_text_release, | 647 | .release = mon_text_release, |
451 | }; | 648 | }; |
452 | 649 | ||
453 | int mon_text_add(struct mon_bus *mbus, const struct usb_bus *ubus) | 650 | static const struct file_operations mon_fops_text_u = { |
651 | .owner = THIS_MODULE, | ||
652 | .open = mon_text_open, | ||
653 | .llseek = no_llseek, | ||
654 | .read = mon_text_read_u, | ||
655 | .release = mon_text_release, | ||
656 | }; | ||
657 | |||
658 | int mon_text_add(struct mon_bus *mbus, int busnum) | ||
454 | { | 659 | { |
455 | struct dentry *d; | 660 | struct dentry *d; |
456 | enum { NAMESZ = 10 }; | 661 | enum { NAMESZ = 10 }; |
457 | char name[NAMESZ]; | 662 | char name[NAMESZ]; |
458 | int rc; | 663 | int rc; |
459 | 664 | ||
460 | rc = snprintf(name, NAMESZ, "%dt", ubus->busnum); | 665 | rc = snprintf(name, NAMESZ, "%dt", busnum); |
461 | if (rc <= 0 || rc >= NAMESZ) | 666 | if (rc <= 0 || rc >= NAMESZ) |
462 | goto err_print_t; | 667 | goto err_print_t; |
463 | d = debugfs_create_file(name, 0600, mon_dir, mbus, &mon_fops_text); | 668 | d = debugfs_create_file(name, 0600, mon_dir, mbus, &mon_fops_text_t); |
464 | if (d == NULL) | 669 | if (d == NULL) |
465 | goto err_create_t; | 670 | goto err_create_t; |
466 | mbus->dent_t = d; | 671 | mbus->dent_t = d; |
467 | 672 | ||
468 | /* XXX The stats do not belong to here (text API), but oh well... */ | 673 | rc = snprintf(name, NAMESZ, "%du", busnum); |
469 | rc = snprintf(name, NAMESZ, "%ds", ubus->busnum); | 674 | if (rc <= 0 || rc >= NAMESZ) |
675 | goto err_print_u; | ||
676 | d = debugfs_create_file(name, 0600, mon_dir, mbus, &mon_fops_text_u); | ||
677 | if (d == NULL) | ||
678 | goto err_create_u; | ||
679 | mbus->dent_u = d; | ||
680 | |||
681 | rc = snprintf(name, NAMESZ, "%ds", busnum); | ||
470 | if (rc <= 0 || rc >= NAMESZ) | 682 | if (rc <= 0 || rc >= NAMESZ) |
471 | goto err_print_s; | 683 | goto err_print_s; |
472 | d = debugfs_create_file(name, 0600, mon_dir, mbus, &mon_fops_stat); | 684 | d = debugfs_create_file(name, 0600, mon_dir, mbus, &mon_fops_stat); |
@@ -478,6 +690,10 @@ int mon_text_add(struct mon_bus *mbus, const struct usb_bus *ubus) | |||
478 | 690 | ||
479 | err_create_s: | 691 | err_create_s: |
480 | err_print_s: | 692 | err_print_s: |
693 | debugfs_remove(mbus->dent_u); | ||
694 | mbus->dent_u = NULL; | ||
695 | err_create_u: | ||
696 | err_print_u: | ||
481 | debugfs_remove(mbus->dent_t); | 697 | debugfs_remove(mbus->dent_t); |
482 | mbus->dent_t = NULL; | 698 | mbus->dent_t = NULL; |
483 | err_create_t: | 699 | err_create_t: |
@@ -487,6 +703,7 @@ err_print_t: | |||
487 | 703 | ||
488 | void mon_text_del(struct mon_bus *mbus) | 704 | void mon_text_del(struct mon_bus *mbus) |
489 | { | 705 | { |
706 | debugfs_remove(mbus->dent_u); | ||
490 | debugfs_remove(mbus->dent_t); | 707 | debugfs_remove(mbus->dent_t); |
491 | debugfs_remove(mbus->dent_s); | 708 | debugfs_remove(mbus->dent_s); |
492 | } | 709 | } |
@@ -520,7 +737,7 @@ int __init mon_text_init(void) | |||
520 | return 0; | 737 | return 0; |
521 | } | 738 | } |
522 | 739 | ||
523 | void __exit mon_text_exit(void) | 740 | void mon_text_exit(void) |
524 | { | 741 | { |
525 | debugfs_remove(mon_dir); | 742 | debugfs_remove(mon_dir); |
526 | } | 743 | } |
diff --git a/drivers/usb/mon/usb_mon.h b/drivers/usb/mon/usb_mon.h index 4f949ce8a7f3..13d63255283e 100644 --- a/drivers/usb/mon/usb_mon.h +++ b/drivers/usb/mon/usb_mon.h | |||
@@ -22,7 +22,7 @@ struct mon_bus { | |||
22 | int text_inited; | 22 | int text_inited; |
23 | struct dentry *dent_s; /* Debugging file */ | 23 | struct dentry *dent_s; /* Debugging file */ |
24 | struct dentry *dent_t; /* Text interface file */ | 24 | struct dentry *dent_t; /* Text interface file */ |
25 | int uses_dma; | 25 | struct dentry *dent_u; /* Second text interface file */ |
26 | 26 | ||
27 | /* Ref */ | 27 | /* Ref */ |
28 | int nreaders; /* Under mon_lock AND mbus->lock */ | 28 | int nreaders; /* Under mon_lock AND mbus->lock */ |
@@ -52,14 +52,14 @@ void mon_reader_del(struct mon_bus *mbus, struct mon_reader *r); | |||
52 | 52 | ||
53 | struct mon_bus *mon_bus_lookup(unsigned int num); | 53 | struct mon_bus *mon_bus_lookup(unsigned int num); |
54 | 54 | ||
55 | int /*bool*/ mon_text_add(struct mon_bus *mbus, const struct usb_bus *ubus); | 55 | int /*bool*/ mon_text_add(struct mon_bus *mbus, int busnum); |
56 | void mon_text_del(struct mon_bus *mbus); | 56 | void mon_text_del(struct mon_bus *mbus); |
57 | // void mon_bin_add(struct mon_bus *); | 57 | // void mon_bin_add(struct mon_bus *); |
58 | 58 | ||
59 | int __init mon_text_init(void); | 59 | int __init mon_text_init(void); |
60 | void __exit mon_text_exit(void); | 60 | void mon_text_exit(void); |
61 | int __init mon_bin_init(void); | 61 | int __init mon_bin_init(void); |
62 | void __exit mon_bin_exit(void); | 62 | void mon_bin_exit(void); |
63 | 63 | ||
64 | /* | 64 | /* |
65 | * DMA interface. | 65 | * DMA interface. |
@@ -81,4 +81,6 @@ extern struct mutex mon_lock; | |||
81 | 81 | ||
82 | extern const struct file_operations mon_fops_stat; | 82 | extern const struct file_operations mon_fops_stat; |
83 | 83 | ||
84 | extern struct mon_bus mon_bus0; /* Only for redundant checks */ | ||
85 | |||
84 | #endif /* __USB_MON_H */ | 86 | #endif /* __USB_MON_H */ |
diff --git a/drivers/usb/net/Kconfig b/drivers/usb/net/Kconfig index a2b94ef512bc..3de564b23147 100644 --- a/drivers/usb/net/Kconfig +++ b/drivers/usb/net/Kconfig | |||
@@ -84,6 +84,7 @@ config USB_PEGASUS | |||
84 | config USB_RTL8150 | 84 | config USB_RTL8150 |
85 | tristate "USB RTL8150 based ethernet device support (EXPERIMENTAL)" | 85 | tristate "USB RTL8150 based ethernet device support (EXPERIMENTAL)" |
86 | depends on EXPERIMENTAL | 86 | depends on EXPERIMENTAL |
87 | select MII | ||
87 | help | 88 | help |
88 | Say Y here if you have RTL8150 based usb-ethernet adapter. | 89 | Say Y here if you have RTL8150 based usb-ethernet adapter. |
89 | Send me <petkan@users.sourceforge.net> any comments you may have. | 90 | Send me <petkan@users.sourceforge.net> any comments you may have. |
@@ -98,7 +99,7 @@ config USB_USBNET_MII | |||
98 | 99 | ||
99 | config USB_USBNET | 100 | config USB_USBNET |
100 | tristate "Multi-purpose USB Networking Framework" | 101 | tristate "Multi-purpose USB Networking Framework" |
101 | select MII if USBNET_MII != n | 102 | select MII if USB_USBNET_MII != n |
102 | ---help--- | 103 | ---help--- |
103 | This driver supports several kinds of network links over USB, | 104 | This driver supports several kinds of network links over USB, |
104 | with "minidrivers" built around a common network driver core | 105 | with "minidrivers" built around a common network driver core |
@@ -185,6 +186,15 @@ config USB_NET_CDCETHER | |||
185 | IEEE 802 "local assignment" bit is set in the address, a "usbX" | 186 | IEEE 802 "local assignment" bit is set in the address, a "usbX" |
186 | name is used instead. | 187 | name is used instead. |
187 | 188 | ||
189 | config USB_NET_DM9601 | ||
190 | tristate "Davicom DM9601 based USB 1.1 10/100 ethernet devices" | ||
191 | depends on USB_USBNET | ||
192 | select CRC32 | ||
193 | select USB_USBNET_MII | ||
194 | help | ||
195 | This option adds support for Davicom DM9601 based USB 1.1 | ||
196 | 10/100 Ethernet adapters. | ||
197 | |||
188 | config USB_NET_GL620A | 198 | config USB_NET_GL620A |
189 | tristate "GeneSys GL620USB-A based cables" | 199 | tristate "GeneSys GL620USB-A based cables" |
190 | depends on USB_USBNET | 200 | depends on USB_USBNET |
@@ -239,6 +249,7 @@ config USB_NET_RNDIS_HOST | |||
239 | config USB_NET_CDC_SUBSET | 249 | config USB_NET_CDC_SUBSET |
240 | tristate "Simple USB Network Links (CDC Ethernet subset)" | 250 | tristate "Simple USB Network Links (CDC Ethernet subset)" |
241 | depends on USB_USBNET | 251 | depends on USB_USBNET |
252 | default y | ||
242 | help | 253 | help |
243 | This driver module supports USB network devices that can work | 254 | This driver module supports USB network devices that can work |
244 | without any device-specific information. Select it if you have | 255 | without any device-specific information. Select it if you have |
@@ -298,6 +309,13 @@ config USB_EPSON2888 | |||
298 | Choose this option to support the usb networking links used | 309 | Choose this option to support the usb networking links used |
299 | by some sample firmware from Epson. | 310 | by some sample firmware from Epson. |
300 | 311 | ||
312 | config USB_KC2190 | ||
313 | boolean "KT Technology KC2190 based cables (InstaNet)" | ||
314 | depends on USB_NET_CDC_SUBSET && EXPERIMENTAL | ||
315 | help | ||
316 | Choose this option if you're using a host-to-host cable | ||
317 | with one of these chips. | ||
318 | |||
301 | config USB_NET_ZAURUS | 319 | config USB_NET_ZAURUS |
302 | tristate "Sharp Zaurus (stock ROMs) and compatible" | 320 | tristate "Sharp Zaurus (stock ROMs) and compatible" |
303 | depends on USB_USBNET | 321 | depends on USB_USBNET |
diff --git a/drivers/usb/net/Makefile b/drivers/usb/net/Makefile index 7b51964de171..595a539f8384 100644 --- a/drivers/usb/net/Makefile +++ b/drivers/usb/net/Makefile | |||
@@ -8,6 +8,7 @@ obj-$(CONFIG_USB_PEGASUS) += pegasus.o | |||
8 | obj-$(CONFIG_USB_RTL8150) += rtl8150.o | 8 | obj-$(CONFIG_USB_RTL8150) += rtl8150.o |
9 | obj-$(CONFIG_USB_NET_AX8817X) += asix.o | 9 | obj-$(CONFIG_USB_NET_AX8817X) += asix.o |
10 | obj-$(CONFIG_USB_NET_CDCETHER) += cdc_ether.o | 10 | obj-$(CONFIG_USB_NET_CDCETHER) += cdc_ether.o |
11 | obj-$(CONFIG_USB_NET_DM9601) += dm9601.o | ||
11 | obj-$(CONFIG_USB_NET_GL620A) += gl620a.o | 12 | obj-$(CONFIG_USB_NET_GL620A) += gl620a.o |
12 | obj-$(CONFIG_USB_NET_NET1080) += net1080.o | 13 | obj-$(CONFIG_USB_NET_NET1080) += net1080.o |
13 | obj-$(CONFIG_USB_NET_PLUSB) += plusb.o | 14 | obj-$(CONFIG_USB_NET_PLUSB) += plusb.o |
diff --git a/drivers/usb/net/asix.c b/drivers/usb/net/asix.c index bd357e178e55..d5ef97bc4d01 100644 --- a/drivers/usb/net/asix.c +++ b/drivers/usb/net/asix.c | |||
@@ -298,7 +298,7 @@ static int asix_rx_fixup(struct usbnet *dev, struct sk_buff *skb) | |||
298 | if (ax_skb) { | 298 | if (ax_skb) { |
299 | ax_skb->len = size; | 299 | ax_skb->len = size; |
300 | ax_skb->data = packet; | 300 | ax_skb->data = packet; |
301 | ax_skb->tail = packet + size; | 301 | skb_set_tail_pointer(ax_skb, size); |
302 | usbnet_skb_return(dev, ax_skb); | 302 | usbnet_skb_return(dev, ax_skb); |
303 | } else { | 303 | } else { |
304 | return 0; | 304 | return 0; |
@@ -338,7 +338,7 @@ static struct sk_buff *asix_tx_fixup(struct usbnet *dev, struct sk_buff *skb, | |||
338 | && ((headroom + tailroom) >= (4 + padlen))) { | 338 | && ((headroom + tailroom) >= (4 + padlen))) { |
339 | if ((headroom < 4) || (tailroom < padlen)) { | 339 | if ((headroom < 4) || (tailroom < padlen)) { |
340 | skb->data = memmove(skb->head + 4, skb->data, skb->len); | 340 | skb->data = memmove(skb->head + 4, skb->data, skb->len); |
341 | skb->tail = skb->data + skb->len; | 341 | skb_set_tail_pointer(skb, skb->len); |
342 | } | 342 | } |
343 | } else { | 343 | } else { |
344 | struct sk_buff *skb2; | 344 | struct sk_buff *skb2; |
@@ -351,10 +351,12 @@ static struct sk_buff *asix_tx_fixup(struct usbnet *dev, struct sk_buff *skb, | |||
351 | 351 | ||
352 | skb_push(skb, 4); | 352 | skb_push(skb, 4); |
353 | packet_len = (((skb->len - 4) ^ 0x0000ffff) << 16) + (skb->len - 4); | 353 | packet_len = (((skb->len - 4) ^ 0x0000ffff) << 16) + (skb->len - 4); |
354 | memcpy(skb->data, &packet_len, sizeof(packet_len)); | 354 | cpu_to_le32s(&packet_len); |
355 | skb_copy_to_linear_data(skb, &packet_len, sizeof(packet_len)); | ||
355 | 356 | ||
356 | if ((skb->len % 512) == 0) { | 357 | if ((skb->len % 512) == 0) { |
357 | memcpy( skb->tail, &padbytes, sizeof(padbytes)); | 358 | cpu_to_le32s(&padbytes); |
359 | memcpy(skb_tail_pointer(skb), &padbytes, sizeof(padbytes)); | ||
358 | skb_put(skb, sizeof(padbytes)); | 360 | skb_put(skb, sizeof(padbytes)); |
359 | } | 361 | } |
360 | return skb; | 362 | return skb; |
@@ -1393,9 +1395,9 @@ static const struct usb_device_id products [] = { | |||
1393 | USB_DEVICE (0x07b8, 0x420a), | 1395 | USB_DEVICE (0x07b8, 0x420a), |
1394 | .driver_info = (unsigned long) &hawking_uf200_info, | 1396 | .driver_info = (unsigned long) &hawking_uf200_info, |
1395 | }, { | 1397 | }, { |
1396 | // Billionton Systems, USB2AR | 1398 | // Billionton Systems, USB2AR |
1397 | USB_DEVICE (0x08dd, 0x90ff), | 1399 | USB_DEVICE (0x08dd, 0x90ff), |
1398 | .driver_info = (unsigned long) &ax8817x_info, | 1400 | .driver_info = (unsigned long) &ax8817x_info, |
1399 | }, { | 1401 | }, { |
1400 | // ATEN UC210T | 1402 | // ATEN UC210T |
1401 | USB_DEVICE (0x0557, 0x2009), | 1403 | USB_DEVICE (0x0557, 0x2009), |
@@ -1421,9 +1423,13 @@ static const struct usb_device_id products [] = { | |||
1421 | USB_DEVICE (0x1631, 0x6200), | 1423 | USB_DEVICE (0x1631, 0x6200), |
1422 | .driver_info = (unsigned long) &ax8817x_info, | 1424 | .driver_info = (unsigned long) &ax8817x_info, |
1423 | }, { | 1425 | }, { |
1426 | // JVC MP-PRX1 Port Replicator | ||
1427 | USB_DEVICE (0x04f1, 0x3008), | ||
1428 | .driver_info = (unsigned long) &ax8817x_info, | ||
1429 | }, { | ||
1424 | // ASIX AX88772 10/100 | 1430 | // ASIX AX88772 10/100 |
1425 | USB_DEVICE (0x0b95, 0x7720), | 1431 | USB_DEVICE (0x0b95, 0x7720), |
1426 | .driver_info = (unsigned long) &ax88772_info, | 1432 | .driver_info = (unsigned long) &ax88772_info, |
1427 | }, { | 1433 | }, { |
1428 | // ASIX AX88178 10/100/1000 | 1434 | // ASIX AX88178 10/100/1000 |
1429 | USB_DEVICE (0x0b95, 0x1780), | 1435 | USB_DEVICE (0x0b95, 0x1780), |
diff --git a/drivers/usb/net/catc.c b/drivers/usb/net/catc.c index 4852012735f6..86e90c59d551 100644 --- a/drivers/usb/net/catc.c +++ b/drivers/usb/net/catc.c | |||
@@ -255,7 +255,6 @@ static void catc_rx_done(struct urb *urb) | |||
255 | if (!(skb = dev_alloc_skb(pkt_len))) | 255 | if (!(skb = dev_alloc_skb(pkt_len))) |
256 | return; | 256 | return; |
257 | 257 | ||
258 | skb->dev = catc->netdev; | ||
259 | eth_copy_and_sum(skb, pkt_start + pkt_offset, pkt_len, 0); | 258 | eth_copy_and_sum(skb, pkt_start + pkt_offset, pkt_len, 0); |
260 | skb_put(skb, pkt_len); | 259 | skb_put(skb, pkt_len); |
261 | 260 | ||
@@ -356,7 +355,7 @@ resubmit: | |||
356 | * Transmit routines. | 355 | * Transmit routines. |
357 | */ | 356 | */ |
358 | 357 | ||
359 | static void catc_tx_run(struct catc *catc) | 358 | static int catc_tx_run(struct catc *catc) |
360 | { | 359 | { |
361 | int status; | 360 | int status; |
362 | 361 | ||
@@ -374,12 +373,14 @@ static void catc_tx_run(struct catc *catc) | |||
374 | catc->tx_ptr = 0; | 373 | catc->tx_ptr = 0; |
375 | 374 | ||
376 | catc->netdev->trans_start = jiffies; | 375 | catc->netdev->trans_start = jiffies; |
376 | return status; | ||
377 | } | 377 | } |
378 | 378 | ||
379 | static void catc_tx_done(struct urb *urb) | 379 | static void catc_tx_done(struct urb *urb) |
380 | { | 380 | { |
381 | struct catc *catc = urb->context; | 381 | struct catc *catc = urb->context; |
382 | unsigned long flags; | 382 | unsigned long flags; |
383 | int r; | ||
383 | 384 | ||
384 | if (urb->status == -ECONNRESET) { | 385 | if (urb->status == -ECONNRESET) { |
385 | dbg("Tx Reset."); | 386 | dbg("Tx Reset."); |
@@ -398,10 +399,13 @@ static void catc_tx_done(struct urb *urb) | |||
398 | 399 | ||
399 | spin_lock_irqsave(&catc->tx_lock, flags); | 400 | spin_lock_irqsave(&catc->tx_lock, flags); |
400 | 401 | ||
401 | if (catc->tx_ptr) | 402 | if (catc->tx_ptr) { |
402 | catc_tx_run(catc); | 403 | r = catc_tx_run(catc); |
403 | else | 404 | if (unlikely(r < 0)) |
405 | clear_bit(TX_RUNNING, &catc->flags); | ||
406 | } else { | ||
404 | clear_bit(TX_RUNNING, &catc->flags); | 407 | clear_bit(TX_RUNNING, &catc->flags); |
408 | } | ||
405 | 409 | ||
406 | netif_wake_queue(catc->netdev); | 410 | netif_wake_queue(catc->netdev); |
407 | 411 | ||
@@ -412,6 +416,7 @@ static int catc_hard_start_xmit(struct sk_buff *skb, struct net_device *netdev) | |||
412 | { | 416 | { |
413 | struct catc *catc = netdev_priv(netdev); | 417 | struct catc *catc = netdev_priv(netdev); |
414 | unsigned long flags; | 418 | unsigned long flags; |
419 | int r = 0; | ||
415 | char *tx_buf; | 420 | char *tx_buf; |
416 | 421 | ||
417 | spin_lock_irqsave(&catc->tx_lock, flags); | 422 | spin_lock_irqsave(&catc->tx_lock, flags); |
@@ -419,11 +424,14 @@ static int catc_hard_start_xmit(struct sk_buff *skb, struct net_device *netdev) | |||
419 | catc->tx_ptr = (((catc->tx_ptr - 1) >> 6) + 1) << 6; | 424 | catc->tx_ptr = (((catc->tx_ptr - 1) >> 6) + 1) << 6; |
420 | tx_buf = catc->tx_buf[catc->tx_idx] + catc->tx_ptr; | 425 | tx_buf = catc->tx_buf[catc->tx_idx] + catc->tx_ptr; |
421 | *((u16*)tx_buf) = (catc->is_f5u011) ? cpu_to_be16((u16)skb->len) : cpu_to_le16((u16)skb->len); | 426 | *((u16*)tx_buf) = (catc->is_f5u011) ? cpu_to_be16((u16)skb->len) : cpu_to_le16((u16)skb->len); |
422 | memcpy(tx_buf + 2, skb->data, skb->len); | 427 | skb_copy_from_linear_data(skb, tx_buf + 2, skb->len); |
423 | catc->tx_ptr += skb->len + 2; | 428 | catc->tx_ptr += skb->len + 2; |
424 | 429 | ||
425 | if (!test_and_set_bit(TX_RUNNING, &catc->flags)) | 430 | if (!test_and_set_bit(TX_RUNNING, &catc->flags)) { |
426 | catc_tx_run(catc); | 431 | r = catc_tx_run(catc); |
432 | if (r < 0) | ||
433 | clear_bit(TX_RUNNING, &catc->flags); | ||
434 | } | ||
427 | 435 | ||
428 | if ((catc->is_f5u011 && catc->tx_ptr) | 436 | if ((catc->is_f5u011 && catc->tx_ptr) |
429 | || (catc->tx_ptr >= ((TX_MAX_BURST - 1) * (PKT_SZ + 2)))) | 437 | || (catc->tx_ptr >= ((TX_MAX_BURST - 1) * (PKT_SZ + 2)))) |
@@ -431,8 +439,10 @@ static int catc_hard_start_xmit(struct sk_buff *skb, struct net_device *netdev) | |||
431 | 439 | ||
432 | spin_unlock_irqrestore(&catc->tx_lock, flags); | 440 | spin_unlock_irqrestore(&catc->tx_lock, flags); |
433 | 441 | ||
434 | catc->stats.tx_bytes += skb->len; | 442 | if (r >= 0) { |
435 | catc->stats.tx_packets++; | 443 | catc->stats.tx_bytes += skb->len; |
444 | catc->stats.tx_packets++; | ||
445 | } | ||
436 | 446 | ||
437 | dev_kfree_skb(skb); | 447 | dev_kfree_skb(skb); |
438 | 448 | ||
diff --git a/drivers/usb/net/cdc_subset.c b/drivers/usb/net/cdc_subset.c index ae8fb06cf38e..bc62b012602b 100644 --- a/drivers/usb/net/cdc_subset.c +++ b/drivers/usb/net/cdc_subset.c | |||
@@ -79,13 +79,19 @@ static int always_connected (struct usbnet *dev) | |||
79 | * | 79 | * |
80 | * ALi M5632 driver ... does high speed | 80 | * ALi M5632 driver ... does high speed |
81 | * | 81 | * |
82 | * NOTE that the MS-Windows drivers for this chip use some funky and | ||
83 | * (naturally) undocumented 7-byte prefix to each packet, so this is a | ||
84 | * case where we don't currently interoperate. Also, once you unplug | ||
85 | * one end of the cable, you need to replug the other end too ... since | ||
86 | * chip docs are unavailable, there's no way to reset the relevant state | ||
87 | * short of a power cycle. | ||
88 | * | ||
82 | *-------------------------------------------------------------------------*/ | 89 | *-------------------------------------------------------------------------*/ |
83 | 90 | ||
84 | static const struct driver_info ali_m5632_info = { | 91 | static const struct driver_info ali_m5632_info = { |
85 | .description = "ALi M5632", | 92 | .description = "ALi M5632", |
86 | }; | 93 | }; |
87 | 94 | ||
88 | |||
89 | #endif | 95 | #endif |
90 | 96 | ||
91 | 97 | ||
@@ -159,6 +165,11 @@ static const struct driver_info epson2888_info = { | |||
159 | #endif /* CONFIG_USB_EPSON2888 */ | 165 | #endif /* CONFIG_USB_EPSON2888 */ |
160 | 166 | ||
161 | 167 | ||
168 | /*------------------------------------------------------------------------- | ||
169 | * | ||
170 | * info from Jonathan McDowell <noodles@earth.li> | ||
171 | * | ||
172 | *-------------------------------------------------------------------------*/ | ||
162 | #ifdef CONFIG_USB_KC2190 | 173 | #ifdef CONFIG_USB_KC2190 |
163 | #define HAVE_HARDWARE | 174 | #define HAVE_HARDWARE |
164 | static const struct driver_info kc2190_info = { | 175 | static const struct driver_info kc2190_info = { |
@@ -223,6 +234,10 @@ static const struct usb_device_id products [] = { | |||
223 | USB_DEVICE (0x0402, 0x5632), // ALi defaults | 234 | USB_DEVICE (0x0402, 0x5632), // ALi defaults |
224 | .driver_info = (unsigned long) &ali_m5632_info, | 235 | .driver_info = (unsigned long) &ali_m5632_info, |
225 | }, | 236 | }, |
237 | { | ||
238 | USB_DEVICE (0x182d,0x207c), // SiteCom CN-124 | ||
239 | .driver_info = (unsigned long) &ali_m5632_info, | ||
240 | }, | ||
226 | #endif | 241 | #endif |
227 | 242 | ||
228 | #ifdef CONFIG_USB_AN2720 | 243 | #ifdef CONFIG_USB_AN2720 |
@@ -314,13 +329,13 @@ static struct usb_driver cdc_subset_driver = { | |||
314 | 329 | ||
315 | static int __init cdc_subset_init(void) | 330 | static int __init cdc_subset_init(void) |
316 | { | 331 | { |
317 | return usb_register(&cdc_subset_driver); | 332 | return usb_register(&cdc_subset_driver); |
318 | } | 333 | } |
319 | module_init(cdc_subset_init); | 334 | module_init(cdc_subset_init); |
320 | 335 | ||
321 | static void __exit cdc_subset_exit(void) | 336 | static void __exit cdc_subset_exit(void) |
322 | { | 337 | { |
323 | usb_deregister(&cdc_subset_driver); | 338 | usb_deregister(&cdc_subset_driver); |
324 | } | 339 | } |
325 | module_exit(cdc_subset_exit); | 340 | module_exit(cdc_subset_exit); |
326 | 341 | ||
diff --git a/drivers/usb/net/dm9601.c b/drivers/usb/net/dm9601.c new file mode 100644 index 000000000000..a67638601477 --- /dev/null +++ b/drivers/usb/net/dm9601.c | |||
@@ -0,0 +1,619 @@ | |||
1 | /* | ||
2 | * Davicom DM9601 USB 1.1 10/100Mbps ethernet devices | ||
3 | * | ||
4 | * Peter Korsgaard <jacmet@sunsite.dk> | ||
5 | * | ||
6 | * This file is licensed under the terms of the GNU General Public License | ||
7 | * version 2. This program is licensed "as is" without any warranty of any | ||
8 | * kind, whether express or implied. | ||
9 | */ | ||
10 | |||
11 | //#define DEBUG | ||
12 | |||
13 | #include <linux/module.h> | ||
14 | #include <linux/sched.h> | ||
15 | #include <linux/stddef.h> | ||
16 | #include <linux/init.h> | ||
17 | #include <linux/netdevice.h> | ||
18 | #include <linux/etherdevice.h> | ||
19 | #include <linux/ethtool.h> | ||
20 | #include <linux/mii.h> | ||
21 | #include <linux/usb.h> | ||
22 | #include <linux/crc32.h> | ||
23 | |||
24 | #include "usbnet.h" | ||
25 | |||
26 | /* datasheet: | ||
27 | http://www.davicom.com.tw/big5/download/Data%20Sheet/DM9601-DS-P01-930914.pdf | ||
28 | */ | ||
29 | |||
30 | /* control requests */ | ||
31 | #define DM_READ_REGS 0x00 | ||
32 | #define DM_WRITE_REGS 0x01 | ||
33 | #define DM_READ_MEMS 0x02 | ||
34 | #define DM_WRITE_REG 0x03 | ||
35 | #define DM_WRITE_MEMS 0x05 | ||
36 | #define DM_WRITE_MEM 0x07 | ||
37 | |||
38 | /* registers */ | ||
39 | #define DM_NET_CTRL 0x00 | ||
40 | #define DM_RX_CTRL 0x05 | ||
41 | #define DM_SHARED_CTRL 0x0b | ||
42 | #define DM_SHARED_ADDR 0x0c | ||
43 | #define DM_SHARED_DATA 0x0d /* low + high */ | ||
44 | #define DM_PHY_ADDR 0x10 /* 6 bytes */ | ||
45 | #define DM_MCAST_ADDR 0x16 /* 8 bytes */ | ||
46 | #define DM_GPR_CTRL 0x1e | ||
47 | #define DM_GPR_DATA 0x1f | ||
48 | |||
49 | #define DM_MAX_MCAST 64 | ||
50 | #define DM_MCAST_SIZE 8 | ||
51 | #define DM_EEPROM_LEN 256 | ||
52 | #define DM_TX_OVERHEAD 2 /* 2 byte header */ | ||
53 | #define DM_RX_OVERHEAD 7 /* 3 byte header + 4 byte crc tail */ | ||
54 | #define DM_TIMEOUT 1000 | ||
55 | |||
56 | |||
57 | static int dm_read(struct usbnet *dev, u8 reg, u16 length, void *data) | ||
58 | { | ||
59 | devdbg(dev, "dm_read() reg=0x%02x length=%d", reg, length); | ||
60 | return usb_control_msg(dev->udev, | ||
61 | usb_rcvctrlpipe(dev->udev, 0), | ||
62 | DM_READ_REGS, | ||
63 | USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE, | ||
64 | 0, reg, data, length, USB_CTRL_SET_TIMEOUT); | ||
65 | } | ||
66 | |||
67 | static int dm_read_reg(struct usbnet *dev, u8 reg, u8 *value) | ||
68 | { | ||
69 | return dm_read(dev, reg, 1, value); | ||
70 | } | ||
71 | |||
72 | static int dm_write(struct usbnet *dev, u8 reg, u16 length, void *data) | ||
73 | { | ||
74 | devdbg(dev, "dm_write() reg=0x%02x, length=%d", reg, length); | ||
75 | return usb_control_msg(dev->udev, | ||
76 | usb_sndctrlpipe(dev->udev, 0), | ||
77 | DM_WRITE_REGS, | ||
78 | USB_DIR_OUT | USB_TYPE_VENDOR |USB_RECIP_DEVICE, | ||
79 | 0, reg, data, length, USB_CTRL_SET_TIMEOUT); | ||
80 | } | ||
81 | |||
82 | static int dm_write_reg(struct usbnet *dev, u8 reg, u8 value) | ||
83 | { | ||
84 | devdbg(dev, "dm_write_reg() reg=0x%02x, value=0x%02x", reg, value); | ||
85 | return usb_control_msg(dev->udev, | ||
86 | usb_sndctrlpipe(dev->udev, 0), | ||
87 | DM_WRITE_REG, | ||
88 | USB_DIR_OUT | USB_TYPE_VENDOR |USB_RECIP_DEVICE, | ||
89 | value, reg, NULL, 0, USB_CTRL_SET_TIMEOUT); | ||
90 | } | ||
91 | |||
92 | static void dm_write_async_callback(struct urb *urb) | ||
93 | { | ||
94 | struct usb_ctrlrequest *req = (struct usb_ctrlrequest *)urb->context; | ||
95 | |||
96 | if (urb->status < 0) | ||
97 | printk(KERN_DEBUG "dm_write_async_callback() failed with %d", | ||
98 | urb->status); | ||
99 | |||
100 | kfree(req); | ||
101 | usb_free_urb(urb); | ||
102 | } | ||
103 | |||
104 | static void dm_write_async(struct usbnet *dev, u8 reg, u16 length, void *data) | ||
105 | { | ||
106 | struct usb_ctrlrequest *req; | ||
107 | struct urb *urb; | ||
108 | int status; | ||
109 | |||
110 | devdbg(dev, "dm_write_async() reg=0x%02x length=%d", reg, length); | ||
111 | |||
112 | urb = usb_alloc_urb(0, GFP_ATOMIC); | ||
113 | if (!urb) { | ||
114 | deverr(dev, "Error allocating URB in dm_write_async!"); | ||
115 | return; | ||
116 | } | ||
117 | |||
118 | req = kmalloc(sizeof(struct usb_ctrlrequest), GFP_ATOMIC); | ||
119 | if (!req) { | ||
120 | deverr(dev, "Failed to allocate memory for control request"); | ||
121 | usb_free_urb(urb); | ||
122 | return; | ||
123 | } | ||
124 | |||
125 | req->bRequestType = USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE; | ||
126 | req->bRequest = DM_WRITE_REGS; | ||
127 | req->wValue = 0; | ||
128 | req->wIndex = cpu_to_le16(reg); | ||
129 | req->wLength = cpu_to_le16(length); | ||
130 | |||
131 | usb_fill_control_urb(urb, dev->udev, | ||
132 | usb_sndctrlpipe(dev->udev, 0), | ||
133 | (void *)req, data, length, | ||
134 | dm_write_async_callback, req); | ||
135 | |||
136 | status = usb_submit_urb(urb, GFP_ATOMIC); | ||
137 | if (status < 0) { | ||
138 | deverr(dev, "Error submitting the control message: status=%d", | ||
139 | status); | ||
140 | kfree(req); | ||
141 | usb_free_urb(urb); | ||
142 | } | ||
143 | } | ||
144 | |||
145 | static void dm_write_reg_async(struct usbnet *dev, u8 reg, u8 value) | ||
146 | { | ||
147 | struct usb_ctrlrequest *req; | ||
148 | struct urb *urb; | ||
149 | int status; | ||
150 | |||
151 | devdbg(dev, "dm_write_reg_async() reg=0x%02x value=0x%02x", | ||
152 | reg, value); | ||
153 | |||
154 | urb = usb_alloc_urb(0, GFP_ATOMIC); | ||
155 | if (!urb) { | ||
156 | deverr(dev, "Error allocating URB in dm_write_async!"); | ||
157 | return; | ||
158 | } | ||
159 | |||
160 | req = kmalloc(sizeof(struct usb_ctrlrequest), GFP_ATOMIC); | ||
161 | if (!req) { | ||
162 | deverr(dev, "Failed to allocate memory for control request"); | ||
163 | usb_free_urb(urb); | ||
164 | return; | ||
165 | } | ||
166 | |||
167 | req->bRequestType = USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE; | ||
168 | req->bRequest = DM_WRITE_REG; | ||
169 | req->wValue = cpu_to_le16(value); | ||
170 | req->wIndex = cpu_to_le16(reg); | ||
171 | req->wLength = 0; | ||
172 | |||
173 | usb_fill_control_urb(urb, dev->udev, | ||
174 | usb_sndctrlpipe(dev->udev, 0), | ||
175 | (void *)req, NULL, 0, dm_write_async_callback, req); | ||
176 | |||
177 | status = usb_submit_urb(urb, GFP_ATOMIC); | ||
178 | if (status < 0) { | ||
179 | deverr(dev, "Error submitting the control message: status=%d", | ||
180 | status); | ||
181 | kfree(req); | ||
182 | usb_free_urb(urb); | ||
183 | } | ||
184 | } | ||
185 | |||
186 | static int dm_read_shared_word(struct usbnet *dev, int phy, u8 reg, u16 *value) | ||
187 | { | ||
188 | int ret, i; | ||
189 | |||
190 | mutex_lock(&dev->phy_mutex); | ||
191 | |||
192 | dm_write_reg(dev, DM_SHARED_ADDR, phy ? (reg | 0x40) : reg); | ||
193 | dm_write_reg(dev, DM_SHARED_CTRL, phy ? 0xc : 0x4); | ||
194 | |||
195 | for (i = 0; i < DM_TIMEOUT; i++) { | ||
196 | u8 tmp; | ||
197 | |||
198 | udelay(1); | ||
199 | ret = dm_read_reg(dev, DM_SHARED_CTRL, &tmp); | ||
200 | if (ret < 0) | ||
201 | goto out; | ||
202 | |||
203 | /* ready */ | ||
204 | if ((tmp & 1) == 0) | ||
205 | break; | ||
206 | } | ||
207 | |||
208 | if (i == DM_TIMEOUT) { | ||
209 | deverr(dev, "%s read timed out!", phy ? "phy" : "eeprom"); | ||
210 | ret = -EIO; | ||
211 | goto out; | ||
212 | } | ||
213 | |||
214 | dm_write_reg(dev, DM_SHARED_CTRL, 0x0); | ||
215 | ret = dm_read(dev, DM_SHARED_DATA, 2, value); | ||
216 | |||
217 | devdbg(dev, "read shared %d 0x%02x returned 0x%04x, %d", | ||
218 | phy, reg, *value, ret); | ||
219 | |||
220 | out: | ||
221 | mutex_unlock(&dev->phy_mutex); | ||
222 | return ret; | ||
223 | } | ||
224 | |||
225 | static int dm_write_shared_word(struct usbnet *dev, int phy, u8 reg, u16 value) | ||
226 | { | ||
227 | int ret, i; | ||
228 | |||
229 | mutex_lock(&dev->phy_mutex); | ||
230 | |||
231 | ret = dm_write(dev, DM_SHARED_DATA, 2, &value); | ||
232 | if (ret < 0) | ||
233 | goto out; | ||
234 | |||
235 | dm_write_reg(dev, DM_SHARED_ADDR, phy ? (reg | 0x40) : reg); | ||
236 | dm_write_reg(dev, DM_SHARED_CTRL, phy ? 0x1c : 0x14); | ||
237 | |||
238 | for (i = 0; i < DM_TIMEOUT; i++) { | ||
239 | u8 tmp; | ||
240 | |||
241 | udelay(1); | ||
242 | ret = dm_read_reg(dev, DM_SHARED_CTRL, &tmp); | ||
243 | if (ret < 0) | ||
244 | goto out; | ||
245 | |||
246 | /* ready */ | ||
247 | if ((tmp & 1) == 0) | ||
248 | break; | ||
249 | } | ||
250 | |||
251 | if (i == DM_TIMEOUT) { | ||
252 | deverr(dev, "%s write timed out!", phy ? "phy" : "eeprom"); | ||
253 | ret = -EIO; | ||
254 | goto out; | ||
255 | } | ||
256 | |||
257 | dm_write_reg(dev, DM_SHARED_CTRL, 0x0); | ||
258 | |||
259 | out: | ||
260 | mutex_unlock(&dev->phy_mutex); | ||
261 | return ret; | ||
262 | } | ||
263 | |||
264 | static int dm_read_eeprom_word(struct usbnet *dev, u8 offset, void *value) | ||
265 | { | ||
266 | return dm_read_shared_word(dev, 0, offset, value); | ||
267 | } | ||
268 | |||
269 | |||
270 | |||
271 | static int dm9601_get_eeprom_len(struct net_device *dev) | ||
272 | { | ||
273 | return DM_EEPROM_LEN; | ||
274 | } | ||
275 | |||
276 | static int dm9601_get_eeprom(struct net_device *net, | ||
277 | struct ethtool_eeprom *eeprom, u8 * data) | ||
278 | { | ||
279 | struct usbnet *dev = netdev_priv(net); | ||
280 | u16 *ebuf = (u16 *) data; | ||
281 | int i; | ||
282 | |||
283 | /* access is 16bit */ | ||
284 | if ((eeprom->offset % 2) || (eeprom->len % 2)) | ||
285 | return -EINVAL; | ||
286 | |||
287 | for (i = 0; i < eeprom->len / 2; i++) { | ||
288 | if (dm_read_eeprom_word(dev, eeprom->offset / 2 + i, | ||
289 | &ebuf[i]) < 0) | ||
290 | return -EINVAL; | ||
291 | } | ||
292 | return 0; | ||
293 | } | ||
294 | |||
295 | static int dm9601_mdio_read(struct net_device *netdev, int phy_id, int loc) | ||
296 | { | ||
297 | struct usbnet *dev = netdev_priv(netdev); | ||
298 | |||
299 | u16 res; | ||
300 | |||
301 | if (phy_id) { | ||
302 | devdbg(dev, "Only internal phy supported"); | ||
303 | return 0; | ||
304 | } | ||
305 | |||
306 | dm_read_shared_word(dev, 1, loc, &res); | ||
307 | |||
308 | devdbg(dev, | ||
309 | "dm9601_mdio_read() phy_id=0x%02x, loc=0x%02x, returns=0x%04x", | ||
310 | phy_id, loc, le16_to_cpu(res)); | ||
311 | |||
312 | return le16_to_cpu(res); | ||
313 | } | ||
314 | |||
315 | static void dm9601_mdio_write(struct net_device *netdev, int phy_id, int loc, | ||
316 | int val) | ||
317 | { | ||
318 | struct usbnet *dev = netdev_priv(netdev); | ||
319 | u16 res = cpu_to_le16(val); | ||
320 | |||
321 | if (phy_id) { | ||
322 | devdbg(dev, "Only internal phy supported"); | ||
323 | return; | ||
324 | } | ||
325 | |||
326 | devdbg(dev,"dm9601_mdio_write() phy_id=0x%02x, loc=0x%02x, val=0x%04x", | ||
327 | phy_id, loc, val); | ||
328 | |||
329 | dm_write_shared_word(dev, 1, loc, res); | ||
330 | } | ||
331 | |||
332 | static void dm9601_get_drvinfo(struct net_device *net, | ||
333 | struct ethtool_drvinfo *info) | ||
334 | { | ||
335 | /* Inherit standard device info */ | ||
336 | usbnet_get_drvinfo(net, info); | ||
337 | info->eedump_len = DM_EEPROM_LEN; | ||
338 | } | ||
339 | |||
340 | static u32 dm9601_get_link(struct net_device *net) | ||
341 | { | ||
342 | struct usbnet *dev = netdev_priv(net); | ||
343 | |||
344 | return mii_link_ok(&dev->mii); | ||
345 | } | ||
346 | |||
347 | static int dm9601_ioctl(struct net_device *net, struct ifreq *rq, int cmd) | ||
348 | { | ||
349 | struct usbnet *dev = netdev_priv(net); | ||
350 | |||
351 | return generic_mii_ioctl(&dev->mii, if_mii(rq), cmd, NULL); | ||
352 | } | ||
353 | |||
354 | static struct ethtool_ops dm9601_ethtool_ops = { | ||
355 | .get_drvinfo = dm9601_get_drvinfo, | ||
356 | .get_link = dm9601_get_link, | ||
357 | .get_msglevel = usbnet_get_msglevel, | ||
358 | .set_msglevel = usbnet_set_msglevel, | ||
359 | .get_eeprom_len = dm9601_get_eeprom_len, | ||
360 | .get_eeprom = dm9601_get_eeprom, | ||
361 | .get_settings = usbnet_get_settings, | ||
362 | .set_settings = usbnet_set_settings, | ||
363 | .nway_reset = usbnet_nway_reset, | ||
364 | }; | ||
365 | |||
366 | static void dm9601_set_multicast(struct net_device *net) | ||
367 | { | ||
368 | struct usbnet *dev = netdev_priv(net); | ||
369 | /* We use the 20 byte dev->data for our 8 byte filter buffer | ||
370 | * to avoid allocating memory that is tricky to free later */ | ||
371 | u8 *hashes = (u8 *) & dev->data; | ||
372 | u8 rx_ctl = 0x01; | ||
373 | |||
374 | memset(hashes, 0x00, DM_MCAST_SIZE); | ||
375 | hashes[DM_MCAST_SIZE - 1] |= 0x80; /* broadcast address */ | ||
376 | |||
377 | if (net->flags & IFF_PROMISC) { | ||
378 | rx_ctl |= 0x02; | ||
379 | } else if (net->flags & IFF_ALLMULTI || net->mc_count > DM_MAX_MCAST) { | ||
380 | rx_ctl |= 0x04; | ||
381 | } else if (net->mc_count) { | ||
382 | struct dev_mc_list *mc_list = net->mc_list; | ||
383 | int i; | ||
384 | |||
385 | for (i = 0; i < net->mc_count; i++) { | ||
386 | u32 crc = ether_crc(ETH_ALEN, mc_list->dmi_addr) >> 26; | ||
387 | hashes[crc >> 3] |= 1 << (crc & 0x7); | ||
388 | } | ||
389 | } | ||
390 | |||
391 | dm_write_async(dev, DM_MCAST_ADDR, DM_MCAST_SIZE, hashes); | ||
392 | dm_write_reg_async(dev, DM_RX_CTRL, rx_ctl); | ||
393 | } | ||
394 | |||
395 | static int dm9601_bind(struct usbnet *dev, struct usb_interface *intf) | ||
396 | { | ||
397 | int ret; | ||
398 | |||
399 | ret = usbnet_get_endpoints(dev, intf); | ||
400 | if (ret) | ||
401 | goto out; | ||
402 | |||
403 | dev->net->do_ioctl = dm9601_ioctl; | ||
404 | dev->net->set_multicast_list = dm9601_set_multicast; | ||
405 | dev->net->ethtool_ops = &dm9601_ethtool_ops; | ||
406 | dev->net->hard_header_len += DM_TX_OVERHEAD; | ||
407 | dev->hard_mtu = dev->net->mtu + dev->net->hard_header_len; | ||
408 | dev->rx_urb_size = dev->net->mtu + DM_RX_OVERHEAD; | ||
409 | |||
410 | dev->mii.dev = dev->net; | ||
411 | dev->mii.mdio_read = dm9601_mdio_read; | ||
412 | dev->mii.mdio_write = dm9601_mdio_write; | ||
413 | dev->mii.phy_id_mask = 0x1f; | ||
414 | dev->mii.reg_num_mask = 0x1f; | ||
415 | |||
416 | /* reset */ | ||
417 | ret = dm_write_reg(dev, DM_NET_CTRL, 1); | ||
418 | udelay(20); | ||
419 | |||
420 | /* read MAC */ | ||
421 | ret = dm_read(dev, DM_PHY_ADDR, ETH_ALEN, dev->net->dev_addr); | ||
422 | if (ret < 0) { | ||
423 | printk(KERN_ERR "Error reading MAC address\n"); | ||
424 | ret = -ENODEV; | ||
425 | goto out; | ||
426 | } | ||
427 | |||
428 | |||
429 | /* power up phy */ | ||
430 | dm_write_reg(dev, DM_GPR_CTRL, 1); | ||
431 | dm_write_reg(dev, DM_GPR_DATA, 0); | ||
432 | |||
433 | /* receive broadcast packets */ | ||
434 | dm9601_set_multicast(dev->net); | ||
435 | |||
436 | dm9601_mdio_write(dev->net, dev->mii.phy_id, MII_BMCR, BMCR_RESET); | ||
437 | dm9601_mdio_write(dev->net, dev->mii.phy_id, MII_ADVERTISE, | ||
438 | ADVERTISE_ALL | ADVERTISE_CSMA | ADVERTISE_PAUSE_CAP); | ||
439 | mii_nway_restart(&dev->mii); | ||
440 | |||
441 | out: | ||
442 | return ret; | ||
443 | } | ||
444 | |||
445 | static int dm9601_rx_fixup(struct usbnet *dev, struct sk_buff *skb) | ||
446 | { | ||
447 | u8 status; | ||
448 | int len; | ||
449 | |||
450 | /* format: | ||
451 | b0: rx status | ||
452 | b1: packet length (incl crc) low | ||
453 | b2: packet length (incl crc) high | ||
454 | b3..n-4: packet data | ||
455 | bn-3..bn: ethernet crc | ||
456 | */ | ||
457 | |||
458 | if (unlikely(skb->len < DM_RX_OVERHEAD)) { | ||
459 | dev_err(&dev->udev->dev, "unexpected tiny rx frame\n"); | ||
460 | return 0; | ||
461 | } | ||
462 | |||
463 | status = skb->data[0]; | ||
464 | len = (skb->data[1] | (skb->data[2] << 8)) - 4; | ||
465 | |||
466 | if (unlikely(status & 0xbf)) { | ||
467 | if (status & 0x01) dev->stats.rx_fifo_errors++; | ||
468 | if (status & 0x02) dev->stats.rx_crc_errors++; | ||
469 | if (status & 0x04) dev->stats.rx_frame_errors++; | ||
470 | if (status & 0x20) dev->stats.rx_missed_errors++; | ||
471 | if (status & 0x90) dev->stats.rx_length_errors++; | ||
472 | return 0; | ||
473 | } | ||
474 | |||
475 | skb_pull(skb, 3); | ||
476 | skb_trim(skb, len); | ||
477 | |||
478 | return 1; | ||
479 | } | ||
480 | |||
481 | static struct sk_buff *dm9601_tx_fixup(struct usbnet *dev, struct sk_buff *skb, | ||
482 | gfp_t flags) | ||
483 | { | ||
484 | int len; | ||
485 | |||
486 | /* format: | ||
487 | b0: packet length low | ||
488 | b1: packet length high | ||
489 | b3..n: packet data | ||
490 | */ | ||
491 | |||
492 | if (skb_headroom(skb) < DM_TX_OVERHEAD) { | ||
493 | struct sk_buff *skb2; | ||
494 | |||
495 | skb2 = skb_copy_expand(skb, DM_TX_OVERHEAD, 0, flags); | ||
496 | dev_kfree_skb_any(skb); | ||
497 | skb = skb2; | ||
498 | if (!skb) | ||
499 | return NULL; | ||
500 | } | ||
501 | |||
502 | __skb_push(skb, DM_TX_OVERHEAD); | ||
503 | |||
504 | len = skb->len; | ||
505 | /* usbnet adds padding if length is a multiple of packet size | ||
506 | if so, adjust length value in header */ | ||
507 | if ((len % dev->maxpacket) == 0) | ||
508 | len++; | ||
509 | |||
510 | skb->data[0] = len; | ||
511 | skb->data[1] = len >> 8; | ||
512 | |||
513 | return skb; | ||
514 | } | ||
515 | |||
516 | static void dm9601_status(struct usbnet *dev, struct urb *urb) | ||
517 | { | ||
518 | int link; | ||
519 | u8 *buf; | ||
520 | |||
521 | /* format: | ||
522 | b0: net status | ||
523 | b1: tx status 1 | ||
524 | b2: tx status 2 | ||
525 | b3: rx status | ||
526 | b4: rx overflow | ||
527 | b5: rx count | ||
528 | b6: tx count | ||
529 | b7: gpr | ||
530 | */ | ||
531 | |||
532 | if (urb->actual_length < 8) | ||
533 | return; | ||
534 | |||
535 | buf = urb->transfer_buffer; | ||
536 | |||
537 | link = !!(buf[0] & 0x40); | ||
538 | if (netif_carrier_ok(dev->net) != link) { | ||
539 | if (link) { | ||
540 | netif_carrier_on(dev->net); | ||
541 | usbnet_defer_kevent (dev, EVENT_LINK_RESET); | ||
542 | } | ||
543 | else | ||
544 | netif_carrier_off(dev->net); | ||
545 | devdbg(dev, "Link Status is: %d", link); | ||
546 | } | ||
547 | } | ||
548 | |||
549 | static int dm9601_link_reset(struct usbnet *dev) | ||
550 | { | ||
551 | struct ethtool_cmd ecmd; | ||
552 | |||
553 | mii_check_media(&dev->mii, 1, 1); | ||
554 | mii_ethtool_gset(&dev->mii, &ecmd); | ||
555 | |||
556 | devdbg(dev, "link_reset() speed: %d duplex: %d", | ||
557 | ecmd.speed, ecmd.duplex); | ||
558 | |||
559 | return 0; | ||
560 | } | ||
561 | |||
562 | static const struct driver_info dm9601_info = { | ||
563 | .description = "Davicom DM9601 USB Ethernet", | ||
564 | .flags = FLAG_ETHER, | ||
565 | .bind = dm9601_bind, | ||
566 | .rx_fixup = dm9601_rx_fixup, | ||
567 | .tx_fixup = dm9601_tx_fixup, | ||
568 | .status = dm9601_status, | ||
569 | .link_reset = dm9601_link_reset, | ||
570 | .reset = dm9601_link_reset, | ||
571 | }; | ||
572 | |||
573 | static const struct usb_device_id products[] = { | ||
574 | { | ||
575 | USB_DEVICE(0x07aa, 0x9601), /* Corega FEther USB-TXC */ | ||
576 | .driver_info = (unsigned long)&dm9601_info, | ||
577 | }, | ||
578 | { | ||
579 | USB_DEVICE(0x0a46, 0x9601), /* Davicom USB-100 */ | ||
580 | .driver_info = (unsigned long)&dm9601_info, | ||
581 | }, | ||
582 | { | ||
583 | USB_DEVICE(0x0a46, 0x6688), /* ZT6688 USB NIC */ | ||
584 | .driver_info = (unsigned long)&dm9601_info, | ||
585 | }, | ||
586 | { | ||
587 | USB_DEVICE(0x0a46, 0x0268), /* ShanTou ST268 USB NIC */ | ||
588 | .driver_info = (unsigned long)&dm9601_info, | ||
589 | }, | ||
590 | {}, // END | ||
591 | }; | ||
592 | |||
593 | MODULE_DEVICE_TABLE(usb, products); | ||
594 | |||
595 | static struct usb_driver dm9601_driver = { | ||
596 | .name = "dm9601", | ||
597 | .id_table = products, | ||
598 | .probe = usbnet_probe, | ||
599 | .disconnect = usbnet_disconnect, | ||
600 | .suspend = usbnet_suspend, | ||
601 | .resume = usbnet_resume, | ||
602 | }; | ||
603 | |||
604 | static int __init dm9601_init(void) | ||
605 | { | ||
606 | return usb_register(&dm9601_driver); | ||
607 | } | ||
608 | |||
609 | static void __exit dm9601_exit(void) | ||
610 | { | ||
611 | usb_deregister(&dm9601_driver); | ||
612 | } | ||
613 | |||
614 | module_init(dm9601_init); | ||
615 | module_exit(dm9601_exit); | ||
616 | |||
617 | MODULE_AUTHOR("Peter Korsgaard <jacmet@sunsite.dk>"); | ||
618 | MODULE_DESCRIPTION("Davicom DM9601 USB 1.1 ethernet devices"); | ||
619 | MODULE_LICENSE("GPL"); | ||
diff --git a/drivers/usb/net/gl620a.c b/drivers/usb/net/gl620a.c index d257a8e026d6..031cf5ca4dbb 100644 --- a/drivers/usb/net/gl620a.c +++ b/drivers/usb/net/gl620a.c | |||
@@ -157,7 +157,7 @@ genelink_tx_fixup(struct usbnet *dev, struct sk_buff *skb, gfp_t flags) | |||
157 | if ((headroom < (4 + 4*1)) || (tailroom < padlen)) { | 157 | if ((headroom < (4 + 4*1)) || (tailroom < padlen)) { |
158 | skb->data = memmove(skb->head + (4 + 4*1), | 158 | skb->data = memmove(skb->head + (4 + 4*1), |
159 | skb->data, skb->len); | 159 | skb->data, skb->len); |
160 | skb->tail = skb->data + skb->len; | 160 | skb_set_tail_pointer(skb, skb->len); |
161 | } | 161 | } |
162 | } else { | 162 | } else { |
163 | struct sk_buff *skb2; | 163 | struct sk_buff *skb2; |
diff --git a/drivers/usb/net/kaweth.c b/drivers/usb/net/kaweth.c index de95268ae4b8..a0cc05d21a6a 100644 --- a/drivers/usb/net/kaweth.c +++ b/drivers/usb/net/kaweth.c | |||
@@ -636,8 +636,6 @@ static void kaweth_usb_receive(struct urb *urb) | |||
636 | 636 | ||
637 | skb_reserve(skb, 2); /* Align IP on 16 byte boundaries */ | 637 | skb_reserve(skb, 2); /* Align IP on 16 byte boundaries */ |
638 | 638 | ||
639 | skb->dev = net; | ||
640 | |||
641 | eth_copy_and_sum(skb, kaweth->rx_buf + 2, pkt_len, 0); | 639 | eth_copy_and_sum(skb, kaweth->rx_buf + 2, pkt_len, 0); |
642 | 640 | ||
643 | skb_put(skb, pkt_len); | 641 | skb_put(skb, pkt_len); |
diff --git a/drivers/usb/net/net1080.c b/drivers/usb/net/net1080.c index ccebfdef4751..19bf8dae70c9 100644 --- a/drivers/usb/net/net1080.c +++ b/drivers/usb/net/net1080.c | |||
@@ -520,7 +520,7 @@ net1080_tx_fixup(struct usbnet *dev, struct sk_buff *skb, gfp_t flags) | |||
520 | skb->data = memmove(skb->head | 520 | skb->data = memmove(skb->head |
521 | + sizeof (struct nc_header), | 521 | + sizeof (struct nc_header), |
522 | skb->data, skb->len); | 522 | skb->data, skb->len); |
523 | skb->tail = skb->data + len; | 523 | skb_set_tail_pointer(skb, len); |
524 | goto encapsulate; | 524 | goto encapsulate; |
525 | } | 525 | } |
526 | } | 526 | } |
diff --git a/drivers/usb/net/pegasus.c b/drivers/usb/net/pegasus.c index d48c024cff59..a05fd97e5bc2 100644 --- a/drivers/usb/net/pegasus.c +++ b/drivers/usb/net/pegasus.c | |||
@@ -316,6 +316,7 @@ static int update_eth_regs_async(pegasus_t * pegasus) | |||
316 | return ret; | 316 | return ret; |
317 | } | 317 | } |
318 | 318 | ||
319 | /* Returns 0 on success, error on failure */ | ||
319 | static int read_mii_word(pegasus_t * pegasus, __u8 phy, __u8 indx, __u16 * regd) | 320 | static int read_mii_word(pegasus_t * pegasus, __u8 phy, __u8 indx, __u16 * regd) |
320 | { | 321 | { |
321 | int i; | 322 | int i; |
@@ -574,7 +575,6 @@ static void fill_skb_pool(pegasus_t * pegasus) | |||
574 | */ | 575 | */ |
575 | if (pegasus->rx_pool[i] == NULL) | 576 | if (pegasus->rx_pool[i] == NULL) |
576 | return; | 577 | return; |
577 | pegasus->rx_pool[i]->dev = pegasus->net; | ||
578 | skb_reserve(pegasus->rx_pool[i], 2); | 578 | skb_reserve(pegasus->rx_pool[i], 2); |
579 | } | 579 | } |
580 | } | 580 | } |
@@ -847,10 +847,6 @@ static void intr_callback(struct urb *urb) | |||
847 | * d[0].NO_CARRIER kicks in only with failed TX. | 847 | * d[0].NO_CARRIER kicks in only with failed TX. |
848 | * ... so monitoring with MII may be safest. | 848 | * ... so monitoring with MII may be safest. |
849 | */ | 849 | */ |
850 | if (d[0] & NO_CARRIER) | ||
851 | netif_carrier_off(net); | ||
852 | else | ||
853 | netif_carrier_on(net); | ||
854 | 850 | ||
855 | /* bytes 3-4 == rx_lostpkt, reg 2E/2F */ | 851 | /* bytes 3-4 == rx_lostpkt, reg 2E/2F */ |
856 | pegasus->stats.rx_missed_errors += ((d[3] & 0x7f) << 8) | d[4]; | 852 | pegasus->stats.rx_missed_errors += ((d[3] & 0x7f) << 8) | d[4]; |
@@ -883,7 +879,7 @@ static int pegasus_start_xmit(struct sk_buff *skb, struct net_device *net) | |||
883 | netif_stop_queue(net); | 879 | netif_stop_queue(net); |
884 | 880 | ||
885 | ((__le16 *) pegasus->tx_buff)[0] = cpu_to_le16(l16); | 881 | ((__le16 *) pegasus->tx_buff)[0] = cpu_to_le16(l16); |
886 | memcpy(pegasus->tx_buff + 2, skb->data, skb->len); | 882 | skb_copy_from_linear_data(skb, pegasus->tx_buff + 2, skb->len); |
887 | usb_fill_bulk_urb(pegasus->tx_urb, pegasus->usb, | 883 | usb_fill_bulk_urb(pegasus->tx_urb, pegasus->usb, |
888 | usb_sndbulkpipe(pegasus->usb, 2), | 884 | usb_sndbulkpipe(pegasus->usb, 2), |
889 | pegasus->tx_buff, count, | 885 | pegasus->tx_buff, count, |
@@ -950,7 +946,7 @@ static void set_carrier(struct net_device *net) | |||
950 | pegasus_t *pegasus = netdev_priv(net); | 946 | pegasus_t *pegasus = netdev_priv(net); |
951 | u16 tmp; | 947 | u16 tmp; |
952 | 948 | ||
953 | if (!read_mii_word(pegasus, pegasus->phy, MII_BMSR, &tmp)) | 949 | if (read_mii_word(pegasus, pegasus->phy, MII_BMSR, &tmp)) |
954 | return; | 950 | return; |
955 | 951 | ||
956 | if (tmp & BMSR_LSTATUS) | 952 | if (tmp & BMSR_LSTATUS) |
@@ -1408,8 +1404,10 @@ static void pegasus_disconnect(struct usb_interface *intf) | |||
1408 | unlink_all_urbs(pegasus); | 1404 | unlink_all_urbs(pegasus); |
1409 | free_all_urbs(pegasus); | 1405 | free_all_urbs(pegasus); |
1410 | free_skb_pool(pegasus); | 1406 | free_skb_pool(pegasus); |
1411 | if (pegasus->rx_skb) | 1407 | if (pegasus->rx_skb != NULL) { |
1412 | dev_kfree_skb(pegasus->rx_skb); | 1408 | dev_kfree_skb(pegasus->rx_skb); |
1409 | pegasus->rx_skb = NULL; | ||
1410 | } | ||
1413 | free_netdev(pegasus->net); | 1411 | free_netdev(pegasus->net); |
1414 | } | 1412 | } |
1415 | 1413 | ||
diff --git a/drivers/usb/net/rndis_host.c b/drivers/usb/net/rndis_host.c index 39a21c74fdf4..980e4aaa97aa 100644 --- a/drivers/usb/net/rndis_host.c +++ b/drivers/usb/net/rndis_host.c | |||
@@ -253,6 +253,7 @@ struct rndis_keepalive_c { /* IN (optionally OUT) */ | |||
253 | * of that mess as possible. | 253 | * of that mess as possible. |
254 | */ | 254 | */ |
255 | #define OID_802_3_PERMANENT_ADDRESS ccpu2(0x01010101) | 255 | #define OID_802_3_PERMANENT_ADDRESS ccpu2(0x01010101) |
256 | #define OID_GEN_MAXIMUM_FRAME_SIZE ccpu2(0x00010106) | ||
256 | #define OID_GEN_CURRENT_PACKET_FILTER ccpu2(0x0001010e) | 257 | #define OID_GEN_CURRENT_PACKET_FILTER ccpu2(0x0001010e) |
257 | 258 | ||
258 | /* | 259 | /* |
@@ -349,7 +350,7 @@ static int rndis_command(struct usbnet *dev, struct rndis_msg_hdr *buf) | |||
349 | case RNDIS_MSG_INDICATE: { /* fault */ | 350 | case RNDIS_MSG_INDICATE: { /* fault */ |
350 | // struct rndis_indicate *msg = (void *)buf; | 351 | // struct rndis_indicate *msg = (void *)buf; |
351 | dev_info(&info->control->dev, | 352 | dev_info(&info->control->dev, |
352 | "rndis fault indication\n"); | 353 | "rndis fault indication\n"); |
353 | } | 354 | } |
354 | break; | 355 | break; |
355 | case RNDIS_MSG_KEEPALIVE: { /* ping */ | 356 | case RNDIS_MSG_KEEPALIVE: { /* ping */ |
@@ -387,6 +388,71 @@ static int rndis_command(struct usbnet *dev, struct rndis_msg_hdr *buf) | |||
387 | return -ETIMEDOUT; | 388 | return -ETIMEDOUT; |
388 | } | 389 | } |
389 | 390 | ||
391 | /* | ||
392 | * rndis_query: | ||
393 | * | ||
394 | * Performs a query for @oid along with 0 or more bytes of payload as | ||
395 | * specified by @in_len. If @reply_len is not set to -1 then the reply | ||
396 | * length is checked against this value, resulting in an error if it | ||
397 | * doesn't match. | ||
398 | * | ||
399 | * NOTE: Adding a payload exactly or greater than the size of the expected | ||
400 | * response payload is an evident requirement MSFT added for ActiveSync. | ||
401 | * | ||
402 | * The only exception is for OIDs that return a variably sized response, | ||
403 | * in which case no payload should be added. This undocumented (and | ||
404 | * nonsensical!) issue was found by sniffing protocol requests from the | ||
405 | * ActiveSync 4.1 Windows driver. | ||
406 | */ | ||
407 | static int rndis_query(struct usbnet *dev, struct usb_interface *intf, | ||
408 | void *buf, u32 oid, u32 in_len, | ||
409 | void **reply, int *reply_len) | ||
410 | { | ||
411 | int retval; | ||
412 | union { | ||
413 | void *buf; | ||
414 | struct rndis_msg_hdr *header; | ||
415 | struct rndis_query *get; | ||
416 | struct rndis_query_c *get_c; | ||
417 | } u; | ||
418 | u32 off, len; | ||
419 | |||
420 | u.buf = buf; | ||
421 | |||
422 | memset(u.get, 0, sizeof *u.get + in_len); | ||
423 | u.get->msg_type = RNDIS_MSG_QUERY; | ||
424 | u.get->msg_len = cpu_to_le32(sizeof *u.get + in_len); | ||
425 | u.get->oid = oid; | ||
426 | u.get->len = cpu_to_le32(in_len); | ||
427 | u.get->offset = ccpu2(20); | ||
428 | |||
429 | retval = rndis_command(dev, u.header); | ||
430 | if (unlikely(retval < 0)) { | ||
431 | dev_err(&intf->dev, "RNDIS_MSG_QUERY(0x%08x) failed, %d\n", | ||
432 | oid, retval); | ||
433 | return retval; | ||
434 | } | ||
435 | |||
436 | off = le32_to_cpu(u.get_c->offset); | ||
437 | len = le32_to_cpu(u.get_c->len); | ||
438 | if (unlikely((8 + off + len) > CONTROL_BUFFER_SIZE)) | ||
439 | goto response_error; | ||
440 | |||
441 | if (*reply_len != -1 && len != *reply_len) | ||
442 | goto response_error; | ||
443 | |||
444 | *reply = (unsigned char *) &u.get_c->request_id + off; | ||
445 | *reply_len = len; | ||
446 | |||
447 | return retval; | ||
448 | |||
449 | response_error: | ||
450 | dev_err(&intf->dev, "RNDIS_MSG_QUERY(0x%08x) " | ||
451 | "invalid response - off %d len %d\n", | ||
452 | oid, off, len); | ||
453 | return -EDOM; | ||
454 | } | ||
455 | |||
390 | static int rndis_bind(struct usbnet *dev, struct usb_interface *intf) | 456 | static int rndis_bind(struct usbnet *dev, struct usb_interface *intf) |
391 | { | 457 | { |
392 | int retval; | 458 | int retval; |
@@ -403,6 +469,8 @@ static int rndis_bind(struct usbnet *dev, struct usb_interface *intf) | |||
403 | struct rndis_set_c *set_c; | 469 | struct rndis_set_c *set_c; |
404 | } u; | 470 | } u; |
405 | u32 tmp; | 471 | u32 tmp; |
472 | int reply_len; | ||
473 | unsigned char *bp; | ||
406 | 474 | ||
407 | /* we can't rely on i/o from stack working, or stack allocation */ | 475 | /* we can't rely on i/o from stack working, or stack allocation */ |
408 | u.buf = kmalloc(CONTROL_BUFFER_SIZE, GFP_KERNEL); | 476 | u.buf = kmalloc(CONTROL_BUFFER_SIZE, GFP_KERNEL); |
@@ -421,6 +489,12 @@ static int rndis_bind(struct usbnet *dev, struct usb_interface *intf) | |||
421 | * TX we'll stick to one Ethernet packet plus RNDIS framing. | 489 | * TX we'll stick to one Ethernet packet plus RNDIS framing. |
422 | * For RX we handle drivers that zero-pad to end-of-packet. | 490 | * For RX we handle drivers that zero-pad to end-of-packet. |
423 | * Don't let userspace change these settings. | 491 | * Don't let userspace change these settings. |
492 | * | ||
493 | * NOTE: there still seems to be wierdness here, as if we need | ||
494 | * to do some more things to make sure WinCE targets accept this. | ||
495 | * They default to jumbograms of 8KB or 16KB, which is absurd | ||
496 | * for such low data rates and which is also more than Linux | ||
497 | * can usually expect to allocate for SKB data... | ||
424 | */ | 498 | */ |
425 | net->hard_header_len += sizeof (struct rndis_data_hdr); | 499 | net->hard_header_len += sizeof (struct rndis_data_hdr); |
426 | dev->hard_mtu = net->mtu + net->hard_header_len; | 500 | dev->hard_mtu = net->mtu + net->hard_header_len; |
@@ -434,7 +508,7 @@ static int rndis_bind(struct usbnet *dev, struct usb_interface *intf) | |||
434 | if (unlikely(retval < 0)) { | 508 | if (unlikely(retval < 0)) { |
435 | /* it might not even be an RNDIS device!! */ | 509 | /* it might not even be an RNDIS device!! */ |
436 | dev_err(&intf->dev, "RNDIS init failed, %d\n", retval); | 510 | dev_err(&intf->dev, "RNDIS init failed, %d\n", retval); |
437 | goto fail_and_release; | 511 | goto fail_and_release; |
438 | } | 512 | } |
439 | tmp = le32_to_cpu(u.init_c->max_transfer_size); | 513 | tmp = le32_to_cpu(u.init_c->max_transfer_size); |
440 | if (tmp < dev->hard_mtu) { | 514 | if (tmp < dev->hard_mtu) { |
@@ -450,34 +524,15 @@ static int rndis_bind(struct usbnet *dev, struct usb_interface *intf) | |||
450 | dev->hard_mtu, tmp, dev->rx_urb_size, | 524 | dev->hard_mtu, tmp, dev->rx_urb_size, |
451 | 1 << le32_to_cpu(u.init_c->packet_alignment)); | 525 | 1 << le32_to_cpu(u.init_c->packet_alignment)); |
452 | 526 | ||
453 | /* Get designated host ethernet address. | 527 | /* Get designated host ethernet address */ |
454 | * | 528 | reply_len = ETH_ALEN; |
455 | * Adding a payload exactly the same size as the expected response | 529 | retval = rndis_query(dev, intf, u.buf, OID_802_3_PERMANENT_ADDRESS, |
456 | * payload is an evident requirement MSFT added for ActiveSync. | 530 | 48, (void **) &bp, &reply_len); |
457 | * This undocumented (and nonsensical) issue was found by sniffing | 531 | if (unlikely(retval< 0)) { |
458 | * protocol requests from the ActiveSync 4.1 Windows driver. | ||
459 | */ | ||
460 | memset(u.get, 0, sizeof *u.get + 48); | ||
461 | u.get->msg_type = RNDIS_MSG_QUERY; | ||
462 | u.get->msg_len = ccpu2(sizeof *u.get + 48); | ||
463 | u.get->oid = OID_802_3_PERMANENT_ADDRESS; | ||
464 | u.get->len = ccpu2(48); | ||
465 | u.get->offset = ccpu2(20); | ||
466 | |||
467 | retval = rndis_command(dev, u.header); | ||
468 | if (unlikely(retval < 0)) { | ||
469 | dev_err(&intf->dev, "rndis get ethaddr, %d\n", retval); | 532 | dev_err(&intf->dev, "rndis get ethaddr, %d\n", retval); |
470 | goto fail_and_release; | 533 | goto fail_and_release; |
471 | } | 534 | } |
472 | tmp = le32_to_cpu(u.get_c->offset); | 535 | memcpy(net->dev_addr, bp, ETH_ALEN); |
473 | if (unlikely((tmp + 8) > (CONTROL_BUFFER_SIZE - ETH_ALEN) | ||
474 | || u.get_c->len != ccpu2(ETH_ALEN))) { | ||
475 | dev_err(&intf->dev, "rndis ethaddr off %d len %d ?\n", | ||
476 | tmp, le32_to_cpu(u.get_c->len)); | ||
477 | retval = -EDOM; | ||
478 | goto fail_and_release; | ||
479 | } | ||
480 | memcpy(net->dev_addr, tmp + (char *)&u.get_c->request_id, ETH_ALEN); | ||
481 | 536 | ||
482 | /* set a nonzero filter to enable data transfers */ | 537 | /* set a nonzero filter to enable data transfers */ |
483 | memset(u.set, 0, sizeof *u.set); | 538 | memset(u.set, 0, sizeof *u.set); |
@@ -502,6 +557,7 @@ static int rndis_bind(struct usbnet *dev, struct usb_interface *intf) | |||
502 | fail_and_release: | 557 | fail_and_release: |
503 | usb_set_intfdata(info->data, NULL); | 558 | usb_set_intfdata(info->data, NULL); |
504 | usb_driver_release_interface(driver_of(intf), info->data); | 559 | usb_driver_release_interface(driver_of(intf), info->data); |
560 | info->data = NULL; | ||
505 | fail: | 561 | fail: |
506 | kfree(u.buf); | 562 | kfree(u.buf); |
507 | return retval; | 563 | return retval; |
@@ -588,7 +644,7 @@ rndis_tx_fixup(struct usbnet *dev, struct sk_buff *skb, gfp_t flags) | |||
588 | if (likely((sizeof *hdr) <= room)) { | 644 | if (likely((sizeof *hdr) <= room)) { |
589 | skb->data = memmove(skb->head + sizeof *hdr, | 645 | skb->data = memmove(skb->head + sizeof *hdr, |
590 | skb->data, len); | 646 | skb->data, len); |
591 | skb->tail = skb->data + len; | 647 | skb_set_tail_pointer(skb, len); |
592 | goto fill; | 648 | goto fill; |
593 | } | 649 | } |
594 | } | 650 | } |
@@ -618,7 +674,7 @@ fill: | |||
618 | 674 | ||
619 | static const struct driver_info rndis_info = { | 675 | static const struct driver_info rndis_info = { |
620 | .description = "RNDIS device", | 676 | .description = "RNDIS device", |
621 | .flags = FLAG_ETHER | FLAG_FRAMING_RN, | 677 | .flags = FLAG_ETHER | FLAG_FRAMING_RN | FLAG_NO_SETINT, |
622 | .bind = rndis_bind, | 678 | .bind = rndis_bind, |
623 | .unbind = rndis_unbind, | 679 | .unbind = rndis_unbind, |
624 | .status = rndis_status, | 680 | .status = rndis_status, |
diff --git a/drivers/usb/net/rtl8150.c b/drivers/usb/net/rtl8150.c index ea153dc9b0ac..fa598f0340cf 100644 --- a/drivers/usb/net/rtl8150.c +++ b/drivers/usb/net/rtl8150.c | |||
@@ -646,7 +646,6 @@ static void fill_skb_pool(rtl8150_t *dev) | |||
646 | if (!skb) { | 646 | if (!skb) { |
647 | return; | 647 | return; |
648 | } | 648 | } |
649 | skb->dev = dev->netdev; | ||
650 | skb_reserve(skb, 2); | 649 | skb_reserve(skb, 2); |
651 | dev->rx_skb_pool[i] = skb; | 650 | dev->rx_skb_pool[i] = skb; |
652 | } | 651 | } |
diff --git a/drivers/usb/net/usbnet.c b/drivers/usb/net/usbnet.c index 43ba61abfcc5..f9cd42d058b0 100644 --- a/drivers/usb/net/usbnet.c +++ b/drivers/usb/net/usbnet.c | |||
@@ -147,7 +147,7 @@ int usbnet_get_endpoints(struct usbnet *dev, struct usb_interface *intf) | |||
147 | if (tmp < 0) | 147 | if (tmp < 0) |
148 | return tmp; | 148 | return tmp; |
149 | } | 149 | } |
150 | 150 | ||
151 | dev->in = usb_rcvbulkpipe (dev->udev, | 151 | dev->in = usb_rcvbulkpipe (dev->udev, |
152 | in->desc.bEndpointAddress & USB_ENDPOINT_NUMBER_MASK); | 152 | in->desc.bEndpointAddress & USB_ENDPOINT_NUMBER_MASK); |
153 | dev->out = usb_sndbulkpipe (dev->udev, | 153 | dev->out = usb_sndbulkpipe (dev->udev, |
@@ -203,7 +203,6 @@ void usbnet_skb_return (struct usbnet *dev, struct sk_buff *skb) | |||
203 | { | 203 | { |
204 | int status; | 204 | int status; |
205 | 205 | ||
206 | skb->dev = dev->net; | ||
207 | skb->protocol = eth_type_trans (skb, dev->net); | 206 | skb->protocol = eth_type_trans (skb, dev->net); |
208 | dev->stats.rx_packets++; | 207 | dev->stats.rx_packets++; |
209 | dev->stats.rx_bytes += skb->len; | 208 | dev->stats.rx_bytes += skb->len; |
@@ -327,7 +326,7 @@ static void rx_submit (struct usbnet *dev, struct urb *urb, gfp_t flags) | |||
327 | if (netif_running (dev->net) | 326 | if (netif_running (dev->net) |
328 | && netif_device_present (dev->net) | 327 | && netif_device_present (dev->net) |
329 | && !test_bit (EVENT_RX_HALT, &dev->flags)) { | 328 | && !test_bit (EVENT_RX_HALT, &dev->flags)) { |
330 | switch (retval = usb_submit_urb (urb, GFP_ATOMIC)){ | 329 | switch (retval = usb_submit_urb (urb, GFP_ATOMIC)){ |
331 | case -EPIPE: | 330 | case -EPIPE: |
332 | usbnet_defer_kevent (dev, EVENT_RX_HALT); | 331 | usbnet_defer_kevent (dev, EVENT_RX_HALT); |
333 | break; | 332 | break; |
@@ -443,7 +442,7 @@ block: | |||
443 | case -EOVERFLOW: | 442 | case -EOVERFLOW: |
444 | dev->stats.rx_over_errors++; | 443 | dev->stats.rx_over_errors++; |
445 | // FALLTHROUGH | 444 | // FALLTHROUGH |
446 | 445 | ||
447 | default: | 446 | default: |
448 | entry->state = rx_cleanup; | 447 | entry->state = rx_cleanup; |
449 | dev->stats.rx_errors++; | 448 | dev->stats.rx_errors++; |
@@ -560,7 +559,7 @@ static int usbnet_stop (struct net_device *net) | |||
560 | 559 | ||
561 | if (netif_msg_ifdown (dev)) | 560 | if (netif_msg_ifdown (dev)) |
562 | devinfo (dev, "stop stats: rx/tx %ld/%ld, errs %ld/%ld", | 561 | devinfo (dev, "stop stats: rx/tx %ld/%ld, errs %ld/%ld", |
563 | dev->stats.rx_packets, dev->stats.tx_packets, | 562 | dev->stats.rx_packets, dev->stats.tx_packets, |
564 | dev->stats.rx_errors, dev->stats.tx_errors | 563 | dev->stats.rx_errors, dev->stats.tx_errors |
565 | ); | 564 | ); |
566 | 565 | ||
@@ -578,7 +577,7 @@ static int usbnet_stop (struct net_device *net) | |||
578 | devdbg (dev, "waited for %d urb completions", temp); | 577 | devdbg (dev, "waited for %d urb completions", temp); |
579 | } | 578 | } |
580 | dev->wait = NULL; | 579 | dev->wait = NULL; |
581 | remove_wait_queue (&unlink_wakeup, &wait); | 580 | remove_wait_queue (&unlink_wakeup, &wait); |
582 | 581 | ||
583 | usb_kill_urb(dev->interrupt); | 582 | usb_kill_urb(dev->interrupt); |
584 | 583 | ||
@@ -735,8 +734,7 @@ void usbnet_get_drvinfo (struct net_device *net, struct ethtool_drvinfo *info) | |||
735 | { | 734 | { |
736 | struct usbnet *dev = netdev_priv(net); | 735 | struct usbnet *dev = netdev_priv(net); |
737 | 736 | ||
738 | /* REVISIT don't always return "usbnet" */ | 737 | strncpy (info->driver, dev->driver_name, sizeof info->driver); |
739 | strncpy (info->driver, driver_name, sizeof info->driver); | ||
740 | strncpy (info->version, DRIVER_VERSION, sizeof info->version); | 738 | strncpy (info->version, DRIVER_VERSION, sizeof info->version); |
741 | strncpy (info->fw_version, dev->driver_info->description, | 739 | strncpy (info->fw_version, dev->driver_info->description, |
742 | sizeof info->fw_version); | 740 | sizeof info->fw_version); |
@@ -834,7 +832,7 @@ kevent (struct work_struct *work) | |||
834 | } | 832 | } |
835 | 833 | ||
836 | if (test_bit (EVENT_LINK_RESET, &dev->flags)) { | 834 | if (test_bit (EVENT_LINK_RESET, &dev->flags)) { |
837 | struct driver_info *info = dev->driver_info; | 835 | struct driver_info *info = dev->driver_info; |
838 | int retval = 0; | 836 | int retval = 0; |
839 | 837 | ||
840 | clear_bit (EVENT_LINK_RESET, &dev->flags); | 838 | clear_bit (EVENT_LINK_RESET, &dev->flags); |
@@ -1066,7 +1064,7 @@ static void usbnet_bh (unsigned long param) | |||
1066 | * USB Device Driver support | 1064 | * USB Device Driver support |
1067 | * | 1065 | * |
1068 | *-------------------------------------------------------------------------*/ | 1066 | *-------------------------------------------------------------------------*/ |
1069 | 1067 | ||
1070 | // precondition: never called in_interrupt | 1068 | // precondition: never called in_interrupt |
1071 | 1069 | ||
1072 | void usbnet_disconnect (struct usb_interface *intf) | 1070 | void usbnet_disconnect (struct usb_interface *intf) |
@@ -1087,7 +1085,7 @@ void usbnet_disconnect (struct usb_interface *intf) | |||
1087 | intf->dev.driver->name, | 1085 | intf->dev.driver->name, |
1088 | xdev->bus->bus_name, xdev->devpath, | 1086 | xdev->bus->bus_name, xdev->devpath, |
1089 | dev->driver_info->description); | 1087 | dev->driver_info->description); |
1090 | 1088 | ||
1091 | net = dev->net; | 1089 | net = dev->net; |
1092 | unregister_netdev (net); | 1090 | unregister_netdev (net); |
1093 | 1091 | ||
@@ -1111,15 +1109,17 @@ int | |||
1111 | usbnet_probe (struct usb_interface *udev, const struct usb_device_id *prod) | 1109 | usbnet_probe (struct usb_interface *udev, const struct usb_device_id *prod) |
1112 | { | 1110 | { |
1113 | struct usbnet *dev; | 1111 | struct usbnet *dev; |
1114 | struct net_device *net; | 1112 | struct net_device *net; |
1115 | struct usb_host_interface *interface; | 1113 | struct usb_host_interface *interface; |
1116 | struct driver_info *info; | 1114 | struct driver_info *info; |
1117 | struct usb_device *xdev; | 1115 | struct usb_device *xdev; |
1118 | int status; | 1116 | int status; |
1117 | const char *name; | ||
1119 | 1118 | ||
1119 | name = udev->dev.driver->name; | ||
1120 | info = (struct driver_info *) prod->driver_info; | 1120 | info = (struct driver_info *) prod->driver_info; |
1121 | if (!info) { | 1121 | if (!info) { |
1122 | dev_dbg (&udev->dev, "blacklisted by %s\n", driver_name); | 1122 | dev_dbg (&udev->dev, "blacklisted by %s\n", name); |
1123 | return -ENODEV; | 1123 | return -ENODEV; |
1124 | } | 1124 | } |
1125 | xdev = interface_to_usbdev (udev); | 1125 | xdev = interface_to_usbdev (udev); |
@@ -1139,6 +1139,7 @@ usbnet_probe (struct usb_interface *udev, const struct usb_device_id *prod) | |||
1139 | dev = netdev_priv(net); | 1139 | dev = netdev_priv(net); |
1140 | dev->udev = xdev; | 1140 | dev->udev = xdev; |
1141 | dev->driver_info = info; | 1141 | dev->driver_info = info; |
1142 | dev->driver_name = name; | ||
1142 | dev->msg_enable = netif_msg_init (msg_level, NETIF_MSG_DRV | 1143 | dev->msg_enable = netif_msg_init (msg_level, NETIF_MSG_DRV |
1143 | | NETIF_MSG_PROBE | NETIF_MSG_LINK); | 1144 | | NETIF_MSG_PROBE | NETIF_MSG_LINK); |
1144 | skb_queue_head_init (&dev->rxq); | 1145 | skb_queue_head_init (&dev->rxq); |
@@ -1181,6 +1182,9 @@ usbnet_probe (struct usb_interface *udev, const struct usb_device_id *prod) | |||
1181 | // NOTE net->name still not usable ... | 1182 | // NOTE net->name still not usable ... |
1182 | if (info->bind) { | 1183 | if (info->bind) { |
1183 | status = info->bind (dev, udev); | 1184 | status = info->bind (dev, udev); |
1185 | if (status < 0) | ||
1186 | goto out1; | ||
1187 | |||
1184 | // heuristic: "usb%d" for links we know are two-host, | 1188 | // heuristic: "usb%d" for links we know are two-host, |
1185 | // else "eth%d" when there's reasonable doubt. userspace | 1189 | // else "eth%d" when there's reasonable doubt. userspace |
1186 | // can rename the link if it knows better. | 1190 | // can rename the link if it knows better. |
@@ -1207,12 +1211,12 @@ usbnet_probe (struct usb_interface *udev, const struct usb_device_id *prod) | |||
1207 | if (status == 0 && dev->status) | 1211 | if (status == 0 && dev->status) |
1208 | status = init_status (dev, udev); | 1212 | status = init_status (dev, udev); |
1209 | if (status < 0) | 1213 | if (status < 0) |
1210 | goto out1; | 1214 | goto out3; |
1211 | 1215 | ||
1212 | if (!dev->rx_urb_size) | 1216 | if (!dev->rx_urb_size) |
1213 | dev->rx_urb_size = dev->hard_mtu; | 1217 | dev->rx_urb_size = dev->hard_mtu; |
1214 | dev->maxpacket = usb_maxpacket (dev->udev, dev->out, 1); | 1218 | dev->maxpacket = usb_maxpacket (dev->udev, dev->out, 1); |
1215 | 1219 | ||
1216 | SET_NETDEV_DEV(net, &udev->dev); | 1220 | SET_NETDEV_DEV(net, &udev->dev); |
1217 | status = register_netdev (net); | 1221 | status = register_netdev (net); |
1218 | if (status) | 1222 | if (status) |
@@ -1255,7 +1259,7 @@ EXPORT_SYMBOL_GPL(usbnet_probe); | |||
1255 | int usbnet_suspend (struct usb_interface *intf, pm_message_t message) | 1259 | int usbnet_suspend (struct usb_interface *intf, pm_message_t message) |
1256 | { | 1260 | { |
1257 | struct usbnet *dev = usb_get_intfdata(intf); | 1261 | struct usbnet *dev = usb_get_intfdata(intf); |
1258 | 1262 | ||
1259 | /* accelerate emptying of the rx and queues, to avoid | 1263 | /* accelerate emptying of the rx and queues, to avoid |
1260 | * having everything error out. | 1264 | * having everything error out. |
1261 | */ | 1265 | */ |
@@ -1286,7 +1290,7 @@ static int __init usbnet_init(void) | |||
1286 | < sizeof (struct skb_data)); | 1290 | < sizeof (struct skb_data)); |
1287 | 1291 | ||
1288 | random_ether_addr(node_id); | 1292 | random_ether_addr(node_id); |
1289 | return 0; | 1293 | return 0; |
1290 | } | 1294 | } |
1291 | module_init(usbnet_init); | 1295 | module_init(usbnet_init); |
1292 | 1296 | ||
diff --git a/drivers/usb/net/usbnet.h b/drivers/usb/net/usbnet.h index 07c70abbe0ec..cbb53e065d6c 100644 --- a/drivers/usb/net/usbnet.h +++ b/drivers/usb/net/usbnet.h | |||
@@ -29,6 +29,7 @@ struct usbnet { | |||
29 | /* housekeeping */ | 29 | /* housekeeping */ |
30 | struct usb_device *udev; | 30 | struct usb_device *udev; |
31 | struct driver_info *driver_info; | 31 | struct driver_info *driver_info; |
32 | const char *driver_name; | ||
32 | wait_queue_head_t *wait; | 33 | wait_queue_head_t *wait; |
33 | struct mutex phy_mutex; | 34 | struct mutex phy_mutex; |
34 | 35 | ||
diff --git a/drivers/usb/serial/Kconfig b/drivers/usb/serial/Kconfig index 2f4d303ee36f..ba5d1dc03036 100644 --- a/drivers/usb/serial/Kconfig +++ b/drivers/usb/serial/Kconfig | |||
@@ -423,11 +423,11 @@ config USB_SERIAL_MCT_U232 | |||
423 | module will be called mct_u232. | 423 | module will be called mct_u232. |
424 | 424 | ||
425 | config USB_SERIAL_MOS7720 | 425 | config USB_SERIAL_MOS7720 |
426 | tristate "USB Moschip 7720 Single Port Serial Driver" | 426 | tristate "USB Moschip 7720 Serial Driver" |
427 | depends on USB_SERIAL | 427 | depends on USB_SERIAL |
428 | ---help--- | 428 | ---help--- |
429 | Say Y here if you want to use a USB Serial single port adapter from | 429 | Say Y here if you want to use USB Serial single and double |
430 | Moschip Semiconductor Tech. | 430 | port adapters from Moschip Semiconductor Tech. |
431 | 431 | ||
432 | To compile this driver as a module, choose M here: the | 432 | To compile this driver as a module, choose M here: the |
433 | module will be called mos7720. | 433 | module will be called mos7720. |
diff --git a/drivers/usb/serial/aircable.c b/drivers/usb/serial/aircable.c index 11dad42c3c60..b675735bfbee 100644 --- a/drivers/usb/serial/aircable.c +++ b/drivers/usb/serial/aircable.c | |||
@@ -209,6 +209,7 @@ static void aircable_send(struct usb_serial_port *port) | |||
209 | int count, result; | 209 | int count, result; |
210 | struct aircable_private *priv = usb_get_serial_port_data(port); | 210 | struct aircable_private *priv = usb_get_serial_port_data(port); |
211 | unsigned char* buf; | 211 | unsigned char* buf; |
212 | u16 *dbuf; | ||
212 | dbg("%s - port %d", __FUNCTION__, port->number); | 213 | dbg("%s - port %d", __FUNCTION__, port->number); |
213 | if (port->write_urb_busy) | 214 | if (port->write_urb_busy) |
214 | return; | 215 | return; |
@@ -226,8 +227,8 @@ static void aircable_send(struct usb_serial_port *port) | |||
226 | 227 | ||
227 | buf[0] = TX_HEADER_0; | 228 | buf[0] = TX_HEADER_0; |
228 | buf[1] = TX_HEADER_1; | 229 | buf[1] = TX_HEADER_1; |
229 | buf[2] = (unsigned char)count; | 230 | dbuf = (u16 *)&buf[2]; |
230 | buf[3] = (unsigned char)(count >> 8); | 231 | *dbuf = cpu_to_le16((u16)count); |
231 | serial_buf_get(priv->tx_buf,buf + HCI_HEADER_LENGTH, MAX_HCI_FRAMESIZE); | 232 | serial_buf_get(priv->tx_buf,buf + HCI_HEADER_LENGTH, MAX_HCI_FRAMESIZE); |
232 | 233 | ||
233 | memcpy(port->write_urb->transfer_buffer, buf, | 234 | memcpy(port->write_urb->transfer_buffer, buf, |
@@ -434,7 +435,7 @@ static void aircable_write_bulk_callback(struct urb *urb) | |||
434 | __FUNCTION__, urb->status); | 435 | __FUNCTION__, urb->status); |
435 | port->write_urb->transfer_buffer_length = 1; | 436 | port->write_urb->transfer_buffer_length = 1; |
436 | port->write_urb->dev = port->serial->dev; | 437 | port->write_urb->dev = port->serial->dev; |
437 | result = usb_submit_urb(port->write_urb, GFP_KERNEL); | 438 | result = usb_submit_urb(port->write_urb, GFP_ATOMIC); |
438 | if (result) | 439 | if (result) |
439 | dev_err(&urb->dev->dev, | 440 | dev_err(&urb->dev->dev, |
440 | "%s - failed resubmitting write urb, error %d\n", | 441 | "%s - failed resubmitting write urb, error %d\n", |
diff --git a/drivers/usb/serial/airprime.c b/drivers/usb/serial/airprime.c index 0af42e32fa0a..39a498362594 100644 --- a/drivers/usb/serial/airprime.c +++ b/drivers/usb/serial/airprime.c | |||
@@ -18,11 +18,6 @@ | |||
18 | 18 | ||
19 | static struct usb_device_id id_table [] = { | 19 | static struct usb_device_id id_table [] = { |
20 | { USB_DEVICE(0x0c88, 0x17da) }, /* Kyocera Wireless KPC650/Passport */ | 20 | { USB_DEVICE(0x0c88, 0x17da) }, /* Kyocera Wireless KPC650/Passport */ |
21 | { USB_DEVICE(0x1410, 0x1110) }, /* Novatel Wireless Merlin CDMA */ | ||
22 | { USB_DEVICE(0x1410, 0x1130) }, /* Novatel Wireless S720 CDMA/EV-DO */ | ||
23 | { USB_DEVICE(0x1410, 0x2110) }, /* Novatel Wireless U720 CDMA/EV-DO */ | ||
24 | { USB_DEVICE(0x1410, 0x1430) }, /* Novatel Merlin XU870 HSDPA/3G */ | ||
25 | { USB_DEVICE(0x1410, 0x1100) }, /* ExpressCard34 Qualcomm 3G CDMA */ | ||
26 | { USB_DEVICE(0x413c, 0x8115) }, /* Dell Wireless HSDPA 5500 */ | 21 | { USB_DEVICE(0x413c, 0x8115) }, /* Dell Wireless HSDPA 5500 */ |
27 | { }, | 22 | { }, |
28 | }; | 23 | }; |
@@ -44,8 +39,43 @@ struct airprime_private { | |||
44 | int outstanding_urbs; | 39 | int outstanding_urbs; |
45 | int throttled; | 40 | int throttled; |
46 | struct urb *read_urbp[NUM_READ_URBS]; | 41 | struct urb *read_urbp[NUM_READ_URBS]; |
42 | |||
43 | /* Settings for the port */ | ||
44 | int rts_state; /* Handshaking pins (outputs) */ | ||
45 | int dtr_state; | ||
46 | int cts_state; /* Handshaking pins (inputs) */ | ||
47 | int dsr_state; | ||
48 | int dcd_state; | ||
49 | int ri_state; | ||
47 | }; | 50 | }; |
48 | 51 | ||
52 | static int airprime_send_setup(struct usb_serial_port *port) | ||
53 | { | ||
54 | struct usb_serial *serial = port->serial; | ||
55 | struct airprime_private *priv; | ||
56 | |||
57 | dbg("%s", __FUNCTION__); | ||
58 | |||
59 | if (port->number != 0) | ||
60 | return 0; | ||
61 | |||
62 | priv = usb_get_serial_port_data(port); | ||
63 | |||
64 | if (port->tty) { | ||
65 | int val = 0; | ||
66 | if (priv->dtr_state) | ||
67 | val |= 0x01; | ||
68 | if (priv->rts_state) | ||
69 | val |= 0x02; | ||
70 | |||
71 | return usb_control_msg(serial->dev, | ||
72 | usb_rcvctrlpipe(serial->dev, 0), | ||
73 | 0x22,0x21,val,0,NULL,0,USB_CTRL_SET_TIMEOUT); | ||
74 | } | ||
75 | |||
76 | return 0; | ||
77 | } | ||
78 | |||
49 | static void airprime_read_bulk_callback(struct urb *urb) | 79 | static void airprime_read_bulk_callback(struct urb *urb) |
50 | { | 80 | { |
51 | struct usb_serial_port *port = urb->context; | 81 | struct usb_serial_port *port = urb->context; |
@@ -58,11 +88,6 @@ static void airprime_read_bulk_callback(struct urb *urb) | |||
58 | if (urb->status) { | 88 | if (urb->status) { |
59 | dbg("%s - nonzero read bulk status received: %d", | 89 | dbg("%s - nonzero read bulk status received: %d", |
60 | __FUNCTION__, urb->status); | 90 | __FUNCTION__, urb->status); |
61 | /* something happened, so free up the memory for this urb */ | ||
62 | if (urb->transfer_buffer) { | ||
63 | kfree (urb->transfer_buffer); | ||
64 | urb->transfer_buffer = NULL; | ||
65 | } | ||
66 | return; | 91 | return; |
67 | } | 92 | } |
68 | usb_serial_debug_data(debug, &port->dev, __FUNCTION__, urb->actual_length, data); | 93 | usb_serial_debug_data(debug, &port->dev, __FUNCTION__, urb->actual_length, data); |
@@ -123,6 +148,10 @@ static int airprime_open(struct usb_serial_port *port, struct file *filp) | |||
123 | usb_set_serial_port_data(port, priv); | 148 | usb_set_serial_port_data(port, priv); |
124 | } | 149 | } |
125 | 150 | ||
151 | /* Set some sane defaults */ | ||
152 | priv->rts_state = 1; | ||
153 | priv->dtr_state = 1; | ||
154 | |||
126 | for (i = 0; i < NUM_READ_URBS; ++i) { | 155 | for (i = 0; i < NUM_READ_URBS; ++i) { |
127 | buffer = kmalloc(buffer_size, GFP_KERNEL); | 156 | buffer = kmalloc(buffer_size, GFP_KERNEL); |
128 | if (!buffer) { | 157 | if (!buffer) { |
@@ -146,6 +175,8 @@ static int airprime_open(struct usb_serial_port *port, struct file *filp) | |||
146 | airprime_read_bulk_callback, port); | 175 | airprime_read_bulk_callback, port); |
147 | result = usb_submit_urb(urb, GFP_KERNEL); | 176 | result = usb_submit_urb(urb, GFP_KERNEL); |
148 | if (result) { | 177 | if (result) { |
178 | usb_free_urb(urb); | ||
179 | kfree(buffer); | ||
149 | dev_err(&port->dev, | 180 | dev_err(&port->dev, |
150 | "%s - failed submitting read urb %d for port %d, error %d\n", | 181 | "%s - failed submitting read urb %d for port %d, error %d\n", |
151 | __FUNCTION__, i, port->number, result); | 182 | __FUNCTION__, i, port->number, result); |
@@ -154,33 +185,21 @@ static int airprime_open(struct usb_serial_port *port, struct file *filp) | |||
154 | /* remember this urb so we can kill it when the port is closed */ | 185 | /* remember this urb so we can kill it when the port is closed */ |
155 | priv->read_urbp[i] = urb; | 186 | priv->read_urbp[i] = urb; |
156 | } | 187 | } |
188 | |||
189 | airprime_send_setup(port); | ||
190 | |||
157 | goto out; | 191 | goto out; |
158 | 192 | ||
159 | errout: | 193 | errout: |
160 | /* some error happened, cancel any submitted urbs and clean up anything that | 194 | /* some error happened, cancel any submitted urbs and clean up anything that |
161 | got allocated successfully */ | 195 | got allocated successfully */ |
162 | 196 | ||
163 | for ( ; i >= 0; --i) { | 197 | while (i-- != 0) { |
164 | urb = priv->read_urbp[i]; | 198 | urb = priv->read_urbp[i]; |
165 | if (urb) { | 199 | buffer = urb->transfer_buffer; |
166 | /* This urb was submitted successfully. So we have to | 200 | usb_kill_urb (urb); |
167 | cancel it. | 201 | usb_free_urb (urb); |
168 | Unlinking the urb will invoke read_bulk_callback() | 202 | kfree (buffer); |
169 | with an error status, so its transfer buffer will | ||
170 | be freed there */ | ||
171 | if (usb_unlink_urb (urb) != -EINPROGRESS) { | ||
172 | /* comments in drivers/usb/core/urb.c say this | ||
173 | can only happen if the urb was never submitted, | ||
174 | or has completed already. | ||
175 | Either way we may have to free the transfer | ||
176 | buffer here. */ | ||
177 | if (urb->transfer_buffer) { | ||
178 | kfree (urb->transfer_buffer); | ||
179 | urb->transfer_buffer = NULL; | ||
180 | } | ||
181 | } | ||
182 | usb_free_urb (urb); | ||
183 | } | ||
184 | } | 203 | } |
185 | 204 | ||
186 | out: | 205 | out: |
@@ -194,10 +213,14 @@ static void airprime_close(struct usb_serial_port *port, struct file * filp) | |||
194 | 213 | ||
195 | dbg("%s - port %d", __FUNCTION__, port->number); | 214 | dbg("%s - port %d", __FUNCTION__, port->number); |
196 | 215 | ||
197 | /* killing the urb will invoke read_bulk_callback() with an error status, | 216 | priv->rts_state = 0; |
198 | so the transfer buffer will be freed there */ | 217 | priv->dtr_state = 0; |
218 | |||
219 | airprime_send_setup(port); | ||
220 | |||
199 | for (i = 0; i < NUM_READ_URBS; ++i) { | 221 | for (i = 0; i < NUM_READ_URBS; ++i) { |
200 | usb_kill_urb (priv->read_urbp[i]); | 222 | usb_kill_urb (priv->read_urbp[i]); |
223 | kfree (priv->read_urbp[i]->transfer_buffer); | ||
201 | usb_free_urb (priv->read_urbp[i]); | 224 | usb_free_urb (priv->read_urbp[i]); |
202 | } | 225 | } |
203 | 226 | ||
diff --git a/drivers/usb/serial/ark3116.c b/drivers/usb/serial/ark3116.c index edd685791a6b..ea2175bb2274 100644 --- a/drivers/usb/serial/ark3116.c +++ b/drivers/usb/serial/ark3116.c | |||
@@ -341,7 +341,7 @@ static int ark3116_open(struct usb_serial_port *port, struct file *filp) | |||
341 | 341 | ||
342 | result = usb_serial_generic_open(port, filp); | 342 | result = usb_serial_generic_open(port, filp); |
343 | if (result) | 343 | if (result) |
344 | return result; | 344 | goto err_out; |
345 | 345 | ||
346 | /* open */ | 346 | /* open */ |
347 | ARK3116_RCV(serial, 111, 0xFE, 0xC0, 0x0000, 0x0003, 0x02, buf); | 347 | ARK3116_RCV(serial, 111, 0xFE, 0xC0, 0x0000, 0x0003, 0x02, buf); |
@@ -372,6 +372,7 @@ static int ark3116_open(struct usb_serial_port *port, struct file *filp) | |||
372 | if (port->tty) | 372 | if (port->tty) |
373 | ark3116_set_termios(port, &tmp_termios); | 373 | ark3116_set_termios(port, &tmp_termios); |
374 | 374 | ||
375 | err_out: | ||
375 | kfree(buf); | 376 | kfree(buf); |
376 | 377 | ||
377 | return result; | 378 | return result; |
diff --git a/drivers/usb/serial/cp2101.c b/drivers/usb/serial/cp2101.c index 3ec24870bca9..e831cb7f64fd 100644 --- a/drivers/usb/serial/cp2101.c +++ b/drivers/usb/serial/cp2101.c | |||
@@ -58,17 +58,22 @@ static struct usb_device_id id_table [] = { | |||
58 | { USB_DEVICE(0x10AB, 0x10C5) }, /* Siemens MC60 Cable */ | 58 | { USB_DEVICE(0x10AB, 0x10C5) }, /* Siemens MC60 Cable */ |
59 | { USB_DEVICE(0x10B5, 0xAC70) }, /* Nokia CA-42 USB */ | 59 | { USB_DEVICE(0x10B5, 0xAC70) }, /* Nokia CA-42 USB */ |
60 | { USB_DEVICE(0x10C4, 0x803B) }, /* Pololu USB-serial converter */ | 60 | { USB_DEVICE(0x10C4, 0x803B) }, /* Pololu USB-serial converter */ |
61 | { USB_DEVICE(0x10C4, 0x8053) }, /* Enfora EDG1228 */ | ||
61 | { USB_DEVICE(0x10C4, 0x8066) }, /* Argussoft In-System Programmer */ | 62 | { USB_DEVICE(0x10C4, 0x8066) }, /* Argussoft In-System Programmer */ |
62 | { USB_DEVICE(0x10C4, 0x807A) }, /* Crumb128 board */ | 63 | { USB_DEVICE(0x10C4, 0x807A) }, /* Crumb128 board */ |
63 | { USB_DEVICE(0x10C4, 0x80CA) }, /* Degree Controls Inc */ | 64 | { USB_DEVICE(0x10C4, 0x80CA) }, /* Degree Controls Inc */ |
65 | { USB_DEVICE(0x10C4, 0x80DD) }, /* Tracient RFID */ | ||
64 | { USB_DEVICE(0x10C4, 0x80F6) }, /* Suunto sports instrument */ | 66 | { USB_DEVICE(0x10C4, 0x80F6) }, /* Suunto sports instrument */ |
65 | { USB_DEVICE(0x10C4, 0x813D) }, /* Burnside Telecom Deskmobile */ | 67 | { USB_DEVICE(0x10C4, 0x813D) }, /* Burnside Telecom Deskmobile */ |
68 | { USB_DEVICE(0x10C4, 0x814A) }, /* West Mountain Radio RIGblaster P&P */ | ||
69 | { USB_DEVICE(0x10C4, 0x814B) }, /* West Mountain Radio RIGtalk */ | ||
66 | { USB_DEVICE(0x10C4, 0x815E) }, /* Helicomm IP-Link 1220-DVM */ | 70 | { USB_DEVICE(0x10C4, 0x815E) }, /* Helicomm IP-Link 1220-DVM */ |
67 | { USB_DEVICE(0x10C4, 0x81C8) }, /* Lipowsky Industrie Elektronik GmbH, Baby-JTAG */ | 71 | { USB_DEVICE(0x10C4, 0x81C8) }, /* Lipowsky Industrie Elektronik GmbH, Baby-JTAG */ |
68 | { USB_DEVICE(0x10C4, 0x81E2) }, /* Lipowsky Industrie Elektronik GmbH, Baby-LIN */ | 72 | { USB_DEVICE(0x10C4, 0x81E2) }, /* Lipowsky Industrie Elektronik GmbH, Baby-LIN */ |
69 | { USB_DEVICE(0x10C4, 0x8218) }, /* Lipowsky Industrie Elektronik GmbH, HARP-1 */ | 73 | { USB_DEVICE(0x10C4, 0x8218) }, /* Lipowsky Industrie Elektronik GmbH, HARP-1 */ |
70 | { USB_DEVICE(0x10C4, 0xEA60) }, /* Silicon Labs factory default */ | 74 | { USB_DEVICE(0x10C4, 0xEA60) }, /* Silicon Labs factory default */ |
71 | { USB_DEVICE(0x10C4, 0xEA61) }, /* Silicon Labs factory default */ | 75 | { USB_DEVICE(0x10C4, 0xEA61) }, /* Silicon Labs factory default */ |
76 | { USB_DEVICE(0x10C5, 0xEA61) }, /* Silicon Labs MobiData GPRS USB Modem */ | ||
72 | { USB_DEVICE(0x13AD, 0x9999) }, /* Baltech card reader */ | 77 | { USB_DEVICE(0x13AD, 0x9999) }, /* Baltech card reader */ |
73 | { USB_DEVICE(0x16D6, 0x0001) }, /* Jablotron serial interface */ | 78 | { USB_DEVICE(0x16D6, 0x0001) }, /* Jablotron serial interface */ |
74 | { } /* Terminating Entry */ | 79 | { } /* Terminating Entry */ |
diff --git a/drivers/usb/serial/ftdi_sio.c b/drivers/usb/serial/ftdi_sio.c index 4695952b6470..95a1805b064f 100644 --- a/drivers/usb/serial/ftdi_sio.c +++ b/drivers/usb/serial/ftdi_sio.c | |||
@@ -315,6 +315,7 @@ static struct usb_device_id id_table_combined [] = { | |||
315 | { USB_DEVICE(FTDI_VID, FTDI_SIO_PID) }, | 315 | { USB_DEVICE(FTDI_VID, FTDI_SIO_PID) }, |
316 | { USB_DEVICE(FTDI_VID, FTDI_8U232AM_PID) }, | 316 | { USB_DEVICE(FTDI_VID, FTDI_8U232AM_PID) }, |
317 | { USB_DEVICE(FTDI_VID, FTDI_8U232AM_ALT_PID) }, | 317 | { USB_DEVICE(FTDI_VID, FTDI_8U232AM_ALT_PID) }, |
318 | { USB_DEVICE(FTDI_VID, FTDI_232RL_PID) }, | ||
318 | { USB_DEVICE(FTDI_VID, FTDI_8U2232C_PID) }, | 319 | { USB_DEVICE(FTDI_VID, FTDI_8U2232C_PID) }, |
319 | { USB_DEVICE(FTDI_VID, FTDI_MICRO_CHAMELEON_PID) }, | 320 | { USB_DEVICE(FTDI_VID, FTDI_MICRO_CHAMELEON_PID) }, |
320 | { USB_DEVICE(FTDI_VID, FTDI_RELAIS_PID) }, | 321 | { USB_DEVICE(FTDI_VID, FTDI_RELAIS_PID) }, |
@@ -341,6 +342,7 @@ static struct usb_device_id id_table_combined [] = { | |||
341 | { USB_DEVICE(FTDI_VID, FTDI_PERLE_ULTRAPORT_PID) }, | 342 | { USB_DEVICE(FTDI_VID, FTDI_PERLE_ULTRAPORT_PID) }, |
342 | { USB_DEVICE(FTDI_VID, FTDI_PIEGROUP_PID) }, | 343 | { USB_DEVICE(FTDI_VID, FTDI_PIEGROUP_PID) }, |
343 | { USB_DEVICE(FTDI_VID, FTDI_TNC_X_PID) }, | 344 | { USB_DEVICE(FTDI_VID, FTDI_TNC_X_PID) }, |
345 | { USB_DEVICE(FTDI_VID, FTDI_USBX_707_PID) }, | ||
344 | { USB_DEVICE(SEALEVEL_VID, SEALEVEL_2101_PID) }, | 346 | { USB_DEVICE(SEALEVEL_VID, SEALEVEL_2101_PID) }, |
345 | { USB_DEVICE(SEALEVEL_VID, SEALEVEL_2102_PID) }, | 347 | { USB_DEVICE(SEALEVEL_VID, SEALEVEL_2102_PID) }, |
346 | { USB_DEVICE(SEALEVEL_VID, SEALEVEL_2103_PID) }, | 348 | { USB_DEVICE(SEALEVEL_VID, SEALEVEL_2103_PID) }, |
@@ -420,6 +422,14 @@ static struct usb_device_id id_table_combined [] = { | |||
420 | { USB_DEVICE(FTDI_VID, FTDI_ELV_ALC8500_PID) }, | 422 | { USB_DEVICE(FTDI_VID, FTDI_ELV_ALC8500_PID) }, |
421 | { USB_DEVICE(FTDI_VID, FTDI_PYRAMID_PID) }, | 423 | { USB_DEVICE(FTDI_VID, FTDI_PYRAMID_PID) }, |
422 | { USB_DEVICE(FTDI_VID, FTDI_ELV_FHZ1000PC_PID) }, | 424 | { USB_DEVICE(FTDI_VID, FTDI_ELV_FHZ1000PC_PID) }, |
425 | { USB_DEVICE(FTDI_VID, FTDI_IBS_US485_PID) }, | ||
426 | { USB_DEVICE(FTDI_VID, FTDI_IBS_PICPRO_PID) }, | ||
427 | { USB_DEVICE(FTDI_VID, FTDI_IBS_PCMCIA_PID) }, | ||
428 | { USB_DEVICE(FTDI_VID, FTDI_IBS_PK1_PID) }, | ||
429 | { USB_DEVICE(FTDI_VID, FTDI_IBS_RS232MON_PID) }, | ||
430 | { USB_DEVICE(FTDI_VID, FTDI_IBS_APP70_PID) }, | ||
431 | { USB_DEVICE(FTDI_VID, FTDI_IBS_PEDO_PID) }, | ||
432 | { USB_DEVICE(FTDI_VID, FTDI_IBS_PROD_PID) }, | ||
423 | /* | 433 | /* |
424 | * These will probably use user-space drivers. Uncomment them if | 434 | * These will probably use user-space drivers. Uncomment them if |
425 | * you need them or use the user-specified vendor/product module | 435 | * you need them or use the user-specified vendor/product module |
@@ -459,6 +469,7 @@ static struct usb_device_id id_table_combined [] = { | |||
459 | { USB_DEVICE(FALCOM_VID, FALCOM_TWIST_PID) }, | 469 | { USB_DEVICE(FALCOM_VID, FALCOM_TWIST_PID) }, |
460 | { USB_DEVICE(FALCOM_VID, FALCOM_SAMBA_PID) }, | 470 | { USB_DEVICE(FALCOM_VID, FALCOM_SAMBA_PID) }, |
461 | { USB_DEVICE(FTDI_VID, FTDI_SUUNTO_SPORTS_PID) }, | 471 | { USB_DEVICE(FTDI_VID, FTDI_SUUNTO_SPORTS_PID) }, |
472 | { USB_DEVICE(TTI_VID, TTI_QL355P_PID) }, | ||
462 | { USB_DEVICE(FTDI_VID, FTDI_RM_CANVIEW_PID) }, | 473 | { USB_DEVICE(FTDI_VID, FTDI_RM_CANVIEW_PID) }, |
463 | { USB_DEVICE(BANDB_VID, BANDB_USOTL4_PID) }, | 474 | { USB_DEVICE(BANDB_VID, BANDB_USOTL4_PID) }, |
464 | { USB_DEVICE(BANDB_VID, BANDB_USTL4_PID) }, | 475 | { USB_DEVICE(BANDB_VID, BANDB_USTL4_PID) }, |
@@ -513,6 +524,7 @@ static struct usb_device_id id_table_combined [] = { | |||
513 | { USB_DEVICE(FTDI_VID, FTDI_TACTRIX_OPENPORT_13S_PID) }, | 524 | { USB_DEVICE(FTDI_VID, FTDI_TACTRIX_OPENPORT_13S_PID) }, |
514 | { USB_DEVICE(FTDI_VID, FTDI_TACTRIX_OPENPORT_13U_PID) }, | 525 | { USB_DEVICE(FTDI_VID, FTDI_TACTRIX_OPENPORT_13U_PID) }, |
515 | { USB_DEVICE(ELEKTOR_VID, ELEKTOR_FT323R_PID) }, | 526 | { USB_DEVICE(ELEKTOR_VID, ELEKTOR_FT323R_PID) }, |
527 | { USB_DEVICE(TELLDUS_VID, TELLDUS_TELLSTICK_PID) }, | ||
516 | { }, /* Optional parameter entry */ | 528 | { }, /* Optional parameter entry */ |
517 | { } /* Terminating entry */ | 529 | { } /* Terminating entry */ |
518 | }; | 530 | }; |
@@ -532,6 +544,7 @@ static const char *ftdi_chip_name[] = { | |||
532 | [FT8U232AM] = "FT8U232AM", | 544 | [FT8U232AM] = "FT8U232AM", |
533 | [FT232BM] = "FT232BM", | 545 | [FT232BM] = "FT232BM", |
534 | [FT2232C] = "FT2232C", | 546 | [FT2232C] = "FT2232C", |
547 | [FT232RL] = "FT232RL", | ||
535 | }; | 548 | }; |
536 | 549 | ||
537 | 550 | ||
@@ -587,6 +600,8 @@ struct ftdi_private { | |||
587 | static int ftdi_sio_probe (struct usb_serial *serial, const struct usb_device_id *id); | 600 | static int ftdi_sio_probe (struct usb_serial *serial, const struct usb_device_id *id); |
588 | static int ftdi_sio_attach (struct usb_serial *serial); | 601 | static int ftdi_sio_attach (struct usb_serial *serial); |
589 | static void ftdi_shutdown (struct usb_serial *serial); | 602 | static void ftdi_shutdown (struct usb_serial *serial); |
603 | static int ftdi_sio_port_probe (struct usb_serial_port *port); | ||
604 | static int ftdi_sio_port_remove (struct usb_serial_port *port); | ||
590 | static int ftdi_open (struct usb_serial_port *port, struct file *filp); | 605 | static int ftdi_open (struct usb_serial_port *port, struct file *filp); |
591 | static void ftdi_close (struct usb_serial_port *port, struct file *filp); | 606 | static void ftdi_close (struct usb_serial_port *port, struct file *filp); |
592 | static int ftdi_write (struct usb_serial_port *port, const unsigned char *buf, int count); | 607 | static int ftdi_write (struct usb_serial_port *port, const unsigned char *buf, int count); |
@@ -621,6 +636,8 @@ static struct usb_serial_driver ftdi_sio_device = { | |||
621 | .num_bulk_out = 1, | 636 | .num_bulk_out = 1, |
622 | .num_ports = 1, | 637 | .num_ports = 1, |
623 | .probe = ftdi_sio_probe, | 638 | .probe = ftdi_sio_probe, |
639 | .port_probe = ftdi_sio_port_probe, | ||
640 | .port_remove = ftdi_sio_port_remove, | ||
624 | .open = ftdi_open, | 641 | .open = ftdi_open, |
625 | .close = ftdi_close, | 642 | .close = ftdi_close, |
626 | .throttle = ftdi_throttle, | 643 | .throttle = ftdi_throttle, |
@@ -863,6 +880,7 @@ static __u32 get_ftdi_divisor(struct usb_serial_port * port) | |||
863 | break; | 880 | break; |
864 | case FT232BM: /* FT232BM chip */ | 881 | case FT232BM: /* FT232BM chip */ |
865 | case FT2232C: /* FT2232C chip */ | 882 | case FT2232C: /* FT2232C chip */ |
883 | case FT232RL: | ||
866 | if (baud <= 3000000) { | 884 | if (baud <= 3000000) { |
867 | div_value = ftdi_232bm_baud_to_divisor(baud); | 885 | div_value = ftdi_232bm_baud_to_divisor(baud); |
868 | } else { | 886 | } else { |
@@ -1005,9 +1023,12 @@ static void ftdi_determine_type(struct usb_serial_port *port) | |||
1005 | /* (It might be a BM because of the iSerialNumber bug, | 1023 | /* (It might be a BM because of the iSerialNumber bug, |
1006 | * but it will still work as an AM device.) */ | 1024 | * but it will still work as an AM device.) */ |
1007 | priv->chip_type = FT8U232AM; | 1025 | priv->chip_type = FT8U232AM; |
1008 | } else { | 1026 | } else if (version < 0x600) { |
1009 | /* Assume its an FT232BM (or FT245BM) */ | 1027 | /* Assume its an FT232BM (or FT245BM) */ |
1010 | priv->chip_type = FT232BM; | 1028 | priv->chip_type = FT232BM; |
1029 | } else { | ||
1030 | /* Assume its an FT232R */ | ||
1031 | priv->chip_type = FT232RL; | ||
1011 | } | 1032 | } |
1012 | info("Detected %s", ftdi_chip_name[priv->chip_type]); | 1033 | info("Detected %s", ftdi_chip_name[priv->chip_type]); |
1013 | } | 1034 | } |
@@ -1023,11 +1044,10 @@ static ssize_t show_latency_timer(struct device *dev, struct device_attribute *a | |||
1023 | { | 1044 | { |
1024 | struct usb_serial_port *port = to_usb_serial_port(dev); | 1045 | struct usb_serial_port *port = to_usb_serial_port(dev); |
1025 | struct ftdi_private *priv = usb_get_serial_port_data(port); | 1046 | struct ftdi_private *priv = usb_get_serial_port_data(port); |
1026 | struct usb_device *udev; | 1047 | struct usb_device *udev = port->serial->dev; |
1027 | unsigned short latency = 0; | 1048 | unsigned short latency = 0; |
1028 | int rv = 0; | 1049 | int rv = 0; |
1029 | 1050 | ||
1030 | udev = to_usb_device(dev); | ||
1031 | 1051 | ||
1032 | dbg("%s",__FUNCTION__); | 1052 | dbg("%s",__FUNCTION__); |
1033 | 1053 | ||
@@ -1051,13 +1071,11 @@ static ssize_t store_latency_timer(struct device *dev, struct device_attribute * | |||
1051 | { | 1071 | { |
1052 | struct usb_serial_port *port = to_usb_serial_port(dev); | 1072 | struct usb_serial_port *port = to_usb_serial_port(dev); |
1053 | struct ftdi_private *priv = usb_get_serial_port_data(port); | 1073 | struct ftdi_private *priv = usb_get_serial_port_data(port); |
1054 | struct usb_device *udev; | 1074 | struct usb_device *udev = port->serial->dev; |
1055 | char buf[1]; | 1075 | char buf[1]; |
1056 | int v = simple_strtoul(valbuf, NULL, 10); | 1076 | int v = simple_strtoul(valbuf, NULL, 10); |
1057 | int rv = 0; | 1077 | int rv = 0; |
1058 | 1078 | ||
1059 | udev = to_usb_device(dev); | ||
1060 | |||
1061 | dbg("%s: setting latency timer = %i", __FUNCTION__, v); | 1079 | dbg("%s: setting latency timer = %i", __FUNCTION__, v); |
1062 | 1080 | ||
1063 | rv = usb_control_msg(udev, | 1081 | rv = usb_control_msg(udev, |
@@ -1082,13 +1100,11 @@ static ssize_t store_event_char(struct device *dev, struct device_attribute *att | |||
1082 | { | 1100 | { |
1083 | struct usb_serial_port *port = to_usb_serial_port(dev); | 1101 | struct usb_serial_port *port = to_usb_serial_port(dev); |
1084 | struct ftdi_private *priv = usb_get_serial_port_data(port); | 1102 | struct ftdi_private *priv = usb_get_serial_port_data(port); |
1085 | struct usb_device *udev; | 1103 | struct usb_device *udev = port->serial->dev; |
1086 | char buf[1]; | 1104 | char buf[1]; |
1087 | int v = simple_strtoul(valbuf, NULL, 10); | 1105 | int v = simple_strtoul(valbuf, NULL, 10); |
1088 | int rv = 0; | 1106 | int rv = 0; |
1089 | 1107 | ||
1090 | udev = to_usb_device(dev); | ||
1091 | |||
1092 | dbg("%s: setting event char = %i", __FUNCTION__, v); | 1108 | dbg("%s: setting event char = %i", __FUNCTION__, v); |
1093 | 1109 | ||
1094 | rv = usb_control_msg(udev, | 1110 | rv = usb_control_msg(udev, |
@@ -1109,46 +1125,38 @@ static ssize_t store_event_char(struct device *dev, struct device_attribute *att | |||
1109 | static DEVICE_ATTR(latency_timer, S_IWUSR | S_IRUGO, show_latency_timer, store_latency_timer); | 1125 | static DEVICE_ATTR(latency_timer, S_IWUSR | S_IRUGO, show_latency_timer, store_latency_timer); |
1110 | static DEVICE_ATTR(event_char, S_IWUSR, NULL, store_event_char); | 1126 | static DEVICE_ATTR(event_char, S_IWUSR, NULL, store_event_char); |
1111 | 1127 | ||
1112 | static int create_sysfs_attrs(struct usb_serial *serial) | 1128 | static int create_sysfs_attrs(struct usb_serial_port *port) |
1113 | { | 1129 | { |
1114 | struct ftdi_private *priv; | 1130 | struct ftdi_private *priv = usb_get_serial_port_data(port); |
1115 | struct usb_device *udev; | ||
1116 | int retval = 0; | 1131 | int retval = 0; |
1117 | 1132 | ||
1118 | dbg("%s",__FUNCTION__); | 1133 | dbg("%s",__FUNCTION__); |
1119 | 1134 | ||
1120 | priv = usb_get_serial_port_data(serial->port[0]); | ||
1121 | udev = serial->dev; | ||
1122 | |||
1123 | /* XXX I've no idea if the original SIO supports the event_char | 1135 | /* XXX I've no idea if the original SIO supports the event_char |
1124 | * sysfs parameter, so I'm playing it safe. */ | 1136 | * sysfs parameter, so I'm playing it safe. */ |
1125 | if (priv->chip_type != SIO) { | 1137 | if (priv->chip_type != SIO) { |
1126 | dbg("sysfs attributes for %s", ftdi_chip_name[priv->chip_type]); | 1138 | dbg("sysfs attributes for %s", ftdi_chip_name[priv->chip_type]); |
1127 | retval = device_create_file(&udev->dev, &dev_attr_event_char); | 1139 | retval = device_create_file(&port->dev, &dev_attr_event_char); |
1128 | if ((!retval) && | 1140 | if ((!retval) && |
1129 | (priv->chip_type == FT232BM || priv->chip_type == FT2232C)) { | 1141 | (priv->chip_type == FT232BM || priv->chip_type == FT2232C)) { |
1130 | retval = device_create_file(&udev->dev, | 1142 | retval = device_create_file(&port->dev, |
1131 | &dev_attr_latency_timer); | 1143 | &dev_attr_latency_timer); |
1132 | } | 1144 | } |
1133 | } | 1145 | } |
1134 | return retval; | 1146 | return retval; |
1135 | } | 1147 | } |
1136 | 1148 | ||
1137 | static void remove_sysfs_attrs(struct usb_serial *serial) | 1149 | static void remove_sysfs_attrs(struct usb_serial_port *port) |
1138 | { | 1150 | { |
1139 | struct ftdi_private *priv; | 1151 | struct ftdi_private *priv = usb_get_serial_port_data(port); |
1140 | struct usb_device *udev; | ||
1141 | 1152 | ||
1142 | dbg("%s",__FUNCTION__); | 1153 | dbg("%s",__FUNCTION__); |
1143 | 1154 | ||
1144 | priv = usb_get_serial_port_data(serial->port[0]); | ||
1145 | udev = serial->dev; | ||
1146 | |||
1147 | /* XXX see create_sysfs_attrs */ | 1155 | /* XXX see create_sysfs_attrs */ |
1148 | if (priv->chip_type != SIO) { | 1156 | if (priv->chip_type != SIO) { |
1149 | device_remove_file(&udev->dev, &dev_attr_event_char); | 1157 | device_remove_file(&port->dev, &dev_attr_event_char); |
1150 | if (priv->chip_type == FT232BM || priv->chip_type == FT2232C) { | 1158 | if (priv->chip_type == FT232BM || priv->chip_type == FT2232C) { |
1151 | device_remove_file(&udev->dev, &dev_attr_latency_timer); | 1159 | device_remove_file(&port->dev, &dev_attr_latency_timer); |
1152 | } | 1160 | } |
1153 | } | 1161 | } |
1154 | 1162 | ||
@@ -1168,13 +1176,9 @@ static int ftdi_sio_probe (struct usb_serial *serial, const struct usb_device_id | |||
1168 | return (0); | 1176 | return (0); |
1169 | } | 1177 | } |
1170 | 1178 | ||
1171 | /* attach subroutine */ | 1179 | static int ftdi_sio_port_probe(struct usb_serial_port *port) |
1172 | static int ftdi_sio_attach (struct usb_serial *serial) | ||
1173 | { | 1180 | { |
1174 | struct usb_serial_port *port = serial->port[0]; | ||
1175 | struct ftdi_private *priv; | 1181 | struct ftdi_private *priv; |
1176 | struct ftdi_sio_quirk *quirk; | ||
1177 | int retval; | ||
1178 | 1182 | ||
1179 | dbg("%s",__FUNCTION__); | 1183 | dbg("%s",__FUNCTION__); |
1180 | 1184 | ||
@@ -1214,19 +1218,21 @@ static int ftdi_sio_attach (struct usb_serial *serial) | |||
1214 | kfree(port->bulk_out_buffer); | 1218 | kfree(port->bulk_out_buffer); |
1215 | port->bulk_out_buffer = NULL; | 1219 | port->bulk_out_buffer = NULL; |
1216 | 1220 | ||
1217 | usb_set_serial_port_data(serial->port[0], priv); | 1221 | usb_set_serial_port_data(port, priv); |
1218 | 1222 | ||
1219 | ftdi_determine_type (serial->port[0]); | 1223 | ftdi_determine_type (port); |
1220 | retval = create_sysfs_attrs(serial); | 1224 | create_sysfs_attrs(port); |
1221 | if (retval) | 1225 | return 0; |
1222 | dev_err(&serial->dev->dev, "Error creating sysfs files, " | 1226 | } |
1223 | "continuing\n"); | ||
1224 | 1227 | ||
1228 | /* attach subroutine */ | ||
1229 | static int ftdi_sio_attach (struct usb_serial *serial) | ||
1230 | { | ||
1225 | /* Check for device requiring special set up. */ | 1231 | /* Check for device requiring special set up. */ |
1226 | quirk = (struct ftdi_sio_quirk *)usb_get_serial_data(serial); | 1232 | struct ftdi_sio_quirk *quirk = usb_get_serial_data(serial); |
1227 | if (quirk && quirk->setup) { | 1233 | |
1234 | if (quirk && quirk->setup) | ||
1228 | quirk->setup(serial); | 1235 | quirk->setup(serial); |
1229 | } | ||
1230 | 1236 | ||
1231 | return 0; | 1237 | return 0; |
1232 | } /* ftdi_sio_attach */ | 1238 | } /* ftdi_sio_attach */ |
@@ -1270,17 +1276,18 @@ static void ftdi_HE_TIRA1_setup (struct usb_serial *serial) | |||
1270 | * calls __serial_close for each open of the port | 1276 | * calls __serial_close for each open of the port |
1271 | * shutdown is called then (ie ftdi_shutdown) | 1277 | * shutdown is called then (ie ftdi_shutdown) |
1272 | */ | 1278 | */ |
1273 | |||
1274 | |||
1275 | static void ftdi_shutdown (struct usb_serial *serial) | 1279 | static void ftdi_shutdown (struct usb_serial *serial) |
1276 | { /* ftdi_shutdown */ | 1280 | { |
1281 | dbg("%s", __FUNCTION__); | ||
1282 | } | ||
1277 | 1283 | ||
1278 | struct usb_serial_port *port = serial->port[0]; | 1284 | static int ftdi_sio_port_remove(struct usb_serial_port *port) |
1285 | { | ||
1279 | struct ftdi_private *priv = usb_get_serial_port_data(port); | 1286 | struct ftdi_private *priv = usb_get_serial_port_data(port); |
1280 | 1287 | ||
1281 | dbg("%s", __FUNCTION__); | 1288 | dbg("%s", __FUNCTION__); |
1282 | 1289 | ||
1283 | remove_sysfs_attrs(serial); | 1290 | remove_sysfs_attrs(port); |
1284 | 1291 | ||
1285 | /* all open ports are closed at this point | 1292 | /* all open ports are closed at this point |
1286 | * (by usbserial.c:__serial_close, which calls ftdi_close) | 1293 | * (by usbserial.c:__serial_close, which calls ftdi_close) |
@@ -1290,8 +1297,9 @@ static void ftdi_shutdown (struct usb_serial *serial) | |||
1290 | usb_set_serial_port_data(port, NULL); | 1297 | usb_set_serial_port_data(port, NULL); |
1291 | kfree(priv); | 1298 | kfree(priv); |
1292 | } | 1299 | } |
1293 | } /* ftdi_shutdown */ | ||
1294 | 1300 | ||
1301 | return 0; | ||
1302 | } | ||
1295 | 1303 | ||
1296 | static int ftdi_open (struct usb_serial_port *port, struct file *filp) | 1304 | static int ftdi_open (struct usb_serial_port *port, struct file *filp) |
1297 | { /* ftdi_open */ | 1305 | { /* ftdi_open */ |
@@ -1426,6 +1434,7 @@ static int ftdi_write (struct usb_serial_port *port, | |||
1426 | dbg("%s - write limit hit\n", __FUNCTION__); | 1434 | dbg("%s - write limit hit\n", __FUNCTION__); |
1427 | return 0; | 1435 | return 0; |
1428 | } | 1436 | } |
1437 | priv->tx_outstanding_urbs++; | ||
1429 | spin_unlock_irqrestore(&priv->tx_lock, flags); | 1438 | spin_unlock_irqrestore(&priv->tx_lock, flags); |
1430 | 1439 | ||
1431 | data_offset = priv->write_offset; | 1440 | data_offset = priv->write_offset; |
@@ -1443,14 +1452,15 @@ static int ftdi_write (struct usb_serial_port *port, | |||
1443 | buffer = kmalloc (transfer_size, GFP_ATOMIC); | 1452 | buffer = kmalloc (transfer_size, GFP_ATOMIC); |
1444 | if (!buffer) { | 1453 | if (!buffer) { |
1445 | err("%s ran out of kernel memory for urb ...", __FUNCTION__); | 1454 | err("%s ran out of kernel memory for urb ...", __FUNCTION__); |
1446 | return -ENOMEM; | 1455 | count = -ENOMEM; |
1456 | goto error_no_buffer; | ||
1447 | } | 1457 | } |
1448 | 1458 | ||
1449 | urb = usb_alloc_urb(0, GFP_ATOMIC); | 1459 | urb = usb_alloc_urb(0, GFP_ATOMIC); |
1450 | if (!urb) { | 1460 | if (!urb) { |
1451 | err("%s - no more free urbs", __FUNCTION__); | 1461 | err("%s - no more free urbs", __FUNCTION__); |
1452 | kfree (buffer); | 1462 | count = -ENOMEM; |
1453 | return -ENOMEM; | 1463 | goto error_no_urb; |
1454 | } | 1464 | } |
1455 | 1465 | ||
1456 | /* Copy data */ | 1466 | /* Copy data */ |
@@ -1492,10 +1502,9 @@ static int ftdi_write (struct usb_serial_port *port, | |||
1492 | if (status) { | 1502 | if (status) { |
1493 | err("%s - failed submitting write urb, error %d", __FUNCTION__, status); | 1503 | err("%s - failed submitting write urb, error %d", __FUNCTION__, status); |
1494 | count = status; | 1504 | count = status; |
1495 | kfree (buffer); | 1505 | goto error; |
1496 | } else { | 1506 | } else { |
1497 | spin_lock_irqsave(&priv->tx_lock, flags); | 1507 | spin_lock_irqsave(&priv->tx_lock, flags); |
1498 | ++priv->tx_outstanding_urbs; | ||
1499 | priv->tx_outstanding_bytes += count; | 1508 | priv->tx_outstanding_bytes += count; |
1500 | priv->tx_bytes += count; | 1509 | priv->tx_bytes += count; |
1501 | spin_unlock_irqrestore(&priv->tx_lock, flags); | 1510 | spin_unlock_irqrestore(&priv->tx_lock, flags); |
@@ -1503,10 +1512,19 @@ static int ftdi_write (struct usb_serial_port *port, | |||
1503 | 1512 | ||
1504 | /* we are done with this urb, so let the host driver | 1513 | /* we are done with this urb, so let the host driver |
1505 | * really free it when it is finished with it */ | 1514 | * really free it when it is finished with it */ |
1506 | usb_free_urb (urb); | 1515 | usb_free_urb(urb); |
1507 | 1516 | ||
1508 | dbg("%s write returning: %d", __FUNCTION__, count); | 1517 | dbg("%s write returning: %d", __FUNCTION__, count); |
1509 | return count; | 1518 | return count; |
1519 | error: | ||
1520 | usb_free_urb(urb); | ||
1521 | error_no_urb: | ||
1522 | kfree (buffer); | ||
1523 | error_no_buffer: | ||
1524 | spin_lock_irqsave(&priv->tx_lock, flags); | ||
1525 | priv->tx_outstanding_urbs--; | ||
1526 | spin_unlock_irqrestore(&priv->tx_lock, flags); | ||
1527 | return count; | ||
1510 | } /* ftdi_write */ | 1528 | } /* ftdi_write */ |
1511 | 1529 | ||
1512 | 1530 | ||
diff --git a/drivers/usb/serial/ftdi_sio.h b/drivers/usb/serial/ftdi_sio.h index 7eff1c03ba80..77ad0a09b384 100644 --- a/drivers/usb/serial/ftdi_sio.h +++ b/drivers/usb/serial/ftdi_sio.h | |||
@@ -27,9 +27,11 @@ | |||
27 | #define FTDI_8U232AM_PID 0x6001 /* Similar device to SIO above */ | 27 | #define FTDI_8U232AM_PID 0x6001 /* Similar device to SIO above */ |
28 | #define FTDI_8U232AM_ALT_PID 0x6006 /* FTDI's alternate PID for above */ | 28 | #define FTDI_8U232AM_ALT_PID 0x6006 /* FTDI's alternate PID for above */ |
29 | #define FTDI_8U2232C_PID 0x6010 /* Dual channel device */ | 29 | #define FTDI_8U2232C_PID 0x6010 /* Dual channel device */ |
30 | #define FTDI_232RL_PID 0xFBFA /* Product ID for FT232RL */ | ||
30 | #define FTDI_RELAIS_PID 0xFA10 /* Relais device from Rudolf Gugler */ | 31 | #define FTDI_RELAIS_PID 0xFA10 /* Relais device from Rudolf Gugler */ |
31 | #define FTDI_NF_RIC_VID 0x0DCD /* Vendor Id */ | 32 | #define FTDI_NF_RIC_VID 0x0DCD /* Vendor Id */ |
32 | #define FTDI_NF_RIC_PID 0x0001 /* Product Id */ | 33 | #define FTDI_NF_RIC_PID 0x0001 /* Product Id */ |
34 | #define FTDI_USBX_707_PID 0xF857 /* ADSTech IR Blaster USBX-707 */ | ||
33 | 35 | ||
34 | 36 | ||
35 | /* www.canusb.com Lawicel CANUSB device */ | 37 | /* www.canusb.com Lawicel CANUSB device */ |
@@ -339,6 +341,12 @@ | |||
339 | #define FTDI_SUUNTO_SPORTS_PID 0xF680 /* Suunto Sports instrument */ | 341 | #define FTDI_SUUNTO_SPORTS_PID 0xF680 /* Suunto Sports instrument */ |
340 | 342 | ||
341 | /* | 343 | /* |
344 | * TTi (Thurlby Thandar Instruments) | ||
345 | */ | ||
346 | #define TTI_VID 0x103E /* Vendor Id */ | ||
347 | #define TTI_QL355P_PID 0x03E8 /* TTi QL355P power supply */ | ||
348 | |||
349 | /* | ||
342 | * Definitions for B&B Electronics products. | 350 | * Definitions for B&B Electronics products. |
343 | */ | 351 | */ |
344 | #define BANDB_VID 0x0856 /* B&B Electronics Vendor ID */ | 352 | #define BANDB_VID 0x0856 /* B&B Electronics Vendor ID */ |
@@ -491,6 +499,25 @@ | |||
491 | #define FTDI_TACTRIX_OPENPORT_13S_PID 0xCC49 /* OpenPort 1.3 Subaru */ | 499 | #define FTDI_TACTRIX_OPENPORT_13S_PID 0xCC49 /* OpenPort 1.3 Subaru */ |
492 | #define FTDI_TACTRIX_OPENPORT_13U_PID 0xCC4A /* OpenPort 1.3 Universal */ | 500 | #define FTDI_TACTRIX_OPENPORT_13U_PID 0xCC4A /* OpenPort 1.3 Universal */ |
493 | 501 | ||
502 | /* | ||
503 | * Telldus Technologies | ||
504 | */ | ||
505 | #define TELLDUS_VID 0x1781 /* Vendor ID */ | ||
506 | #define TELLDUS_TELLSTICK_PID 0x0C30 /* RF control dongle 433 MHz using FT232RL */ | ||
507 | |||
508 | /* | ||
509 | * IBS elektronik product ids | ||
510 | * Submitted by Thomas Schleusener | ||
511 | */ | ||
512 | #define FTDI_IBS_US485_PID 0xff38 /* IBS US485 (USB<-->RS422/485 interface) */ | ||
513 | #define FTDI_IBS_PICPRO_PID 0xff39 /* IBS PIC-Programmer */ | ||
514 | #define FTDI_IBS_PCMCIA_PID 0xff3a /* IBS Card reader for PCMCIA SRAM-cards */ | ||
515 | #define FTDI_IBS_PK1_PID 0xff3b /* IBS PK1 - Particel counter */ | ||
516 | #define FTDI_IBS_RS232MON_PID 0xff3c /* IBS RS232 - Monitor */ | ||
517 | #define FTDI_IBS_APP70_PID 0xff3d /* APP 70 (dust monitoring system) */ | ||
518 | #define FTDI_IBS_PEDO_PID 0xff3e /* IBS PEDO-Modem (RF modem 868.35 MHz) */ | ||
519 | #define FTDI_IBS_PROD_PID 0xff3f /* future device */ | ||
520 | |||
494 | /* Commands */ | 521 | /* Commands */ |
495 | #define FTDI_SIO_RESET 0 /* Reset the port */ | 522 | #define FTDI_SIO_RESET 0 /* Reset the port */ |
496 | #define FTDI_SIO_MODEM_CTRL 1 /* Set the modem control register */ | 523 | #define FTDI_SIO_MODEM_CTRL 1 /* Set the modem control register */ |
@@ -614,6 +641,7 @@ typedef enum { | |||
614 | FT8U232AM = 2, | 641 | FT8U232AM = 2, |
615 | FT232BM = 3, | 642 | FT232BM = 3, |
616 | FT2232C = 4, | 643 | FT2232C = 4, |
644 | FT232RL = 5, | ||
617 | } ftdi_chip_type_t; | 645 | } ftdi_chip_type_t; |
618 | 646 | ||
619 | typedef enum { | 647 | typedef enum { |
diff --git a/drivers/usb/serial/generic.c b/drivers/usb/serial/generic.c index 601e0648dec6..4f8282ad7720 100644 --- a/drivers/usb/serial/generic.c +++ b/drivers/usb/serial/generic.c | |||
@@ -20,13 +20,14 @@ | |||
20 | #include <linux/usb/serial.h> | 20 | #include <linux/usb/serial.h> |
21 | #include <asm/uaccess.h> | 21 | #include <asm/uaccess.h> |
22 | 22 | ||
23 | static int generic_probe(struct usb_interface *interface, | ||
24 | const struct usb_device_id *id); | ||
25 | |||
26 | 23 | ||
27 | static int debug; | 24 | static int debug; |
28 | 25 | ||
29 | #ifdef CONFIG_USB_SERIAL_GENERIC | 26 | #ifdef CONFIG_USB_SERIAL_GENERIC |
27 | |||
28 | static int generic_probe(struct usb_interface *interface, | ||
29 | const struct usb_device_id *id); | ||
30 | |||
30 | static __u16 vendor = 0x05f9; | 31 | static __u16 vendor = 0x05f9; |
31 | static __u16 product = 0xffff; | 32 | static __u16 product = 0xffff; |
32 | 33 | ||
@@ -66,6 +67,8 @@ struct usb_serial_driver usb_serial_generic_device = { | |||
66 | .num_bulk_out = NUM_DONT_CARE, | 67 | .num_bulk_out = NUM_DONT_CARE, |
67 | .num_ports = 1, | 68 | .num_ports = 1, |
68 | .shutdown = usb_serial_generic_shutdown, | 69 | .shutdown = usb_serial_generic_shutdown, |
70 | .throttle = usb_serial_generic_throttle, | ||
71 | .unthrottle = usb_serial_generic_unthrottle, | ||
69 | }; | 72 | }; |
70 | 73 | ||
71 | static int generic_probe(struct usb_interface *interface, | 74 | static int generic_probe(struct usb_interface *interface, |
@@ -115,6 +118,7 @@ int usb_serial_generic_open (struct usb_serial_port *port, struct file *filp) | |||
115 | { | 118 | { |
116 | struct usb_serial *serial = port->serial; | 119 | struct usb_serial *serial = port->serial; |
117 | int result = 0; | 120 | int result = 0; |
121 | unsigned long flags; | ||
118 | 122 | ||
119 | dbg("%s - port %d", __FUNCTION__, port->number); | 123 | dbg("%s - port %d", __FUNCTION__, port->number); |
120 | 124 | ||
@@ -124,7 +128,13 @@ int usb_serial_generic_open (struct usb_serial_port *port, struct file *filp) | |||
124 | if (port->tty) | 128 | if (port->tty) |
125 | port->tty->low_latency = 1; | 129 | port->tty->low_latency = 1; |
126 | 130 | ||
127 | /* if we have a bulk interrupt, start reading from it */ | 131 | /* clear the throttle flags */ |
132 | spin_lock_irqsave(&port->lock, flags); | ||
133 | port->throttled = 0; | ||
134 | port->throttle_req = 0; | ||
135 | spin_unlock_irqrestore(&port->lock, flags); | ||
136 | |||
137 | /* if we have a bulk endpoint, start reading from it */ | ||
128 | if (serial->num_bulk_in) { | 138 | if (serial->num_bulk_in) { |
129 | /* Start reading from the device */ | 139 | /* Start reading from the device */ |
130 | usb_fill_bulk_urb (port->read_urb, serial->dev, | 140 | usb_fill_bulk_urb (port->read_urb, serial->dev, |
@@ -253,31 +263,22 @@ int usb_serial_generic_chars_in_buffer (struct usb_serial_port *port) | |||
253 | return (chars); | 263 | return (chars); |
254 | } | 264 | } |
255 | 265 | ||
256 | void usb_serial_generic_read_bulk_callback (struct urb *urb) | 266 | /* Push data to tty layer and resubmit the bulk read URB */ |
267 | static void flush_and_resubmit_read_urb (struct usb_serial_port *port) | ||
257 | { | 268 | { |
258 | struct usb_serial_port *port = (struct usb_serial_port *)urb->context; | ||
259 | struct usb_serial *serial = port->serial; | 269 | struct usb_serial *serial = port->serial; |
260 | struct tty_struct *tty; | 270 | struct urb *urb = port->read_urb; |
261 | unsigned char *data = urb->transfer_buffer; | 271 | struct tty_struct *tty = port->tty; |
262 | int result; | 272 | int result; |
263 | 273 | ||
264 | dbg("%s - port %d", __FUNCTION__, port->number); | 274 | /* Push data to tty */ |
265 | |||
266 | if (urb->status) { | ||
267 | dbg("%s - nonzero read bulk status received: %d", __FUNCTION__, urb->status); | ||
268 | return; | ||
269 | } | ||
270 | |||
271 | usb_serial_debug_data(debug, &port->dev, __FUNCTION__, urb->actual_length, data); | ||
272 | |||
273 | tty = port->tty; | ||
274 | if (tty && urb->actual_length) { | 275 | if (tty && urb->actual_length) { |
275 | tty_buffer_request_room(tty, urb->actual_length); | 276 | tty_buffer_request_room(tty, urb->actual_length); |
276 | tty_insert_flip_string(tty, data, urb->actual_length); | 277 | tty_insert_flip_string(tty, urb->transfer_buffer, urb->actual_length); |
277 | tty_flip_buffer_push(tty); | 278 | tty_flip_buffer_push(tty); /* is this allowed from an URB callback ? */ |
278 | } | 279 | } |
279 | 280 | ||
280 | /* Continue trying to always read */ | 281 | /* Continue reading from device */ |
281 | usb_fill_bulk_urb (port->read_urb, serial->dev, | 282 | usb_fill_bulk_urb (port->read_urb, serial->dev, |
282 | usb_rcvbulkpipe (serial->dev, | 283 | usb_rcvbulkpipe (serial->dev, |
283 | port->bulk_in_endpointAddress), | 284 | port->bulk_in_endpointAddress), |
@@ -290,6 +291,40 @@ void usb_serial_generic_read_bulk_callback (struct urb *urb) | |||
290 | if (result) | 291 | if (result) |
291 | dev_err(&port->dev, "%s - failed resubmitting read urb, error %d\n", __FUNCTION__, result); | 292 | dev_err(&port->dev, "%s - failed resubmitting read urb, error %d\n", __FUNCTION__, result); |
292 | } | 293 | } |
294 | |||
295 | void usb_serial_generic_read_bulk_callback (struct urb *urb) | ||
296 | { | ||
297 | struct usb_serial_port *port = (struct usb_serial_port *)urb->context; | ||
298 | unsigned char *data = urb->transfer_buffer; | ||
299 | int is_throttled; | ||
300 | unsigned long flags; | ||
301 | |||
302 | dbg("%s - port %d", __FUNCTION__, port->number); | ||
303 | |||
304 | if (urb->status) { | ||
305 | dbg("%s - nonzero read bulk status received: %d", __FUNCTION__, urb->status); | ||
306 | return; | ||
307 | } | ||
308 | |||
309 | usb_serial_debug_data(debug, &port->dev, __FUNCTION__, urb->actual_length, data); | ||
310 | |||
311 | /* Throttle the device if requested by tty */ | ||
312 | if (urb->actual_length) { | ||
313 | spin_lock_irqsave(&port->lock, flags); | ||
314 | is_throttled = port->throttled = port->throttle_req; | ||
315 | spin_unlock_irqrestore(&port->lock, flags); | ||
316 | if (is_throttled) { | ||
317 | /* Let the received data linger in the read URB; | ||
318 | * usb_serial_generic_unthrottle() will pick it | ||
319 | * up later. */ | ||
320 | dbg("%s - throttling device", __FUNCTION__); | ||
321 | return; | ||
322 | } | ||
323 | } | ||
324 | |||
325 | /* Handle data and continue reading from device */ | ||
326 | flush_and_resubmit_read_urb(port); | ||
327 | } | ||
293 | EXPORT_SYMBOL_GPL(usb_serial_generic_read_bulk_callback); | 328 | EXPORT_SYMBOL_GPL(usb_serial_generic_read_bulk_callback); |
294 | 329 | ||
295 | void usb_serial_generic_write_bulk_callback (struct urb *urb) | 330 | void usb_serial_generic_write_bulk_callback (struct urb *urb) |
@@ -308,6 +343,38 @@ void usb_serial_generic_write_bulk_callback (struct urb *urb) | |||
308 | } | 343 | } |
309 | EXPORT_SYMBOL_GPL(usb_serial_generic_write_bulk_callback); | 344 | EXPORT_SYMBOL_GPL(usb_serial_generic_write_bulk_callback); |
310 | 345 | ||
346 | void usb_serial_generic_throttle (struct usb_serial_port *port) | ||
347 | { | ||
348 | unsigned long flags; | ||
349 | |||
350 | dbg("%s - port %d", __FUNCTION__, port->number); | ||
351 | |||
352 | /* Set the throttle request flag. It will be picked up | ||
353 | * by usb_serial_generic_read_bulk_callback(). */ | ||
354 | spin_lock_irqsave(&port->lock, flags); | ||
355 | port->throttle_req = 1; | ||
356 | spin_unlock_irqrestore(&port->lock, flags); | ||
357 | } | ||
358 | |||
359 | void usb_serial_generic_unthrottle (struct usb_serial_port *port) | ||
360 | { | ||
361 | int was_throttled; | ||
362 | unsigned long flags; | ||
363 | |||
364 | dbg("%s - port %d", __FUNCTION__, port->number); | ||
365 | |||
366 | /* Clear the throttle flags */ | ||
367 | spin_lock_irqsave(&port->lock, flags); | ||
368 | was_throttled = port->throttled; | ||
369 | port->throttled = port->throttle_req = 0; | ||
370 | spin_unlock_irqrestore(&port->lock, flags); | ||
371 | |||
372 | if (was_throttled) { | ||
373 | /* Handle pending data and resume reading from device */ | ||
374 | flush_and_resubmit_read_urb(port); | ||
375 | } | ||
376 | } | ||
377 | |||
311 | void usb_serial_generic_shutdown (struct usb_serial *serial) | 378 | void usb_serial_generic_shutdown (struct usb_serial *serial) |
312 | { | 379 | { |
313 | int i; | 380 | int i; |
diff --git a/drivers/usb/serial/io_edgeport.c b/drivers/usb/serial/io_edgeport.c index 6a26a2e683a6..18f74ac76565 100644 --- a/drivers/usb/serial/io_edgeport.c +++ b/drivers/usb/serial/io_edgeport.c | |||
@@ -111,7 +111,7 @@ struct edgeport_port { | |||
111 | 111 | ||
112 | struct TxFifo txfifo; /* transmit fifo -- size will be maxTxCredits */ | 112 | struct TxFifo txfifo; /* transmit fifo -- size will be maxTxCredits */ |
113 | struct urb *write_urb; /* write URB for this port */ | 113 | struct urb *write_urb; /* write URB for this port */ |
114 | char write_in_progress; /* TRUE while a write URB is outstanding */ | 114 | bool write_in_progress; /* 'true' while a write URB is outstanding */ |
115 | spinlock_t ep_lock; | 115 | spinlock_t ep_lock; |
116 | 116 | ||
117 | __u8 shadowLCR; /* last LCR value received */ | 117 | __u8 shadowLCR; /* last LCR value received */ |
@@ -123,11 +123,11 @@ struct edgeport_port { | |||
123 | __u8 validDataMask; | 123 | __u8 validDataMask; |
124 | __u32 baudRate; | 124 | __u32 baudRate; |
125 | 125 | ||
126 | char open; | 126 | bool open; |
127 | char openPending; | 127 | bool openPending; |
128 | char commandPending; | 128 | bool commandPending; |
129 | char closePending; | 129 | bool closePending; |
130 | char chaseResponsePending; | 130 | bool chaseResponsePending; |
131 | 131 | ||
132 | wait_queue_head_t wait_chase; /* for handling sleeping while waiting for chase to finish */ | 132 | wait_queue_head_t wait_chase; /* for handling sleeping while waiting for chase to finish */ |
133 | wait_queue_head_t wait_open; /* for handling sleeping while waiting for open to finish */ | 133 | wait_queue_head_t wait_open; /* for handling sleeping while waiting for open to finish */ |
@@ -156,7 +156,7 @@ struct edgeport_serial { | |||
156 | __u8 bulk_in_endpoint; /* the bulk in endpoint handle */ | 156 | __u8 bulk_in_endpoint; /* the bulk in endpoint handle */ |
157 | unsigned char * bulk_in_buffer; /* the buffer we use for the bulk in endpoint */ | 157 | unsigned char * bulk_in_buffer; /* the buffer we use for the bulk in endpoint */ |
158 | struct urb * read_urb; /* our bulk read urb */ | 158 | struct urb * read_urb; /* our bulk read urb */ |
159 | int read_in_progress; | 159 | bool read_in_progress; |
160 | spinlock_t es_lock; | 160 | spinlock_t es_lock; |
161 | 161 | ||
162 | __u8 bulk_out_endpoint; /* the bulk out endpoint handle */ | 162 | __u8 bulk_out_endpoint; /* the bulk out endpoint handle */ |
@@ -212,7 +212,7 @@ static int debug; | |||
212 | 212 | ||
213 | static int low_latency = 1; /* tty low latency flag, on by default */ | 213 | static int low_latency = 1; /* tty low latency flag, on by default */ |
214 | 214 | ||
215 | static int CmdUrbs = 0; /* Number of outstanding Command Write Urbs */ | 215 | static atomic_t CmdUrbs; /* Number of outstanding Command Write Urbs */ |
216 | 216 | ||
217 | 217 | ||
218 | /* local function prototypes */ | 218 | /* local function prototypes */ |
@@ -631,14 +631,14 @@ static void edge_interrupt_callback (struct urb *urb) | |||
631 | if (edge_serial->rxBytesAvail > 0 && | 631 | if (edge_serial->rxBytesAvail > 0 && |
632 | !edge_serial->read_in_progress) { | 632 | !edge_serial->read_in_progress) { |
633 | dbg("%s - posting a read", __FUNCTION__); | 633 | dbg("%s - posting a read", __FUNCTION__); |
634 | edge_serial->read_in_progress = TRUE; | 634 | edge_serial->read_in_progress = true; |
635 | 635 | ||
636 | /* we have pending bytes on the bulk in pipe, send a request */ | 636 | /* we have pending bytes on the bulk in pipe, send a request */ |
637 | edge_serial->read_urb->dev = edge_serial->serial->dev; | 637 | edge_serial->read_urb->dev = edge_serial->serial->dev; |
638 | result = usb_submit_urb(edge_serial->read_urb, GFP_ATOMIC); | 638 | result = usb_submit_urb(edge_serial->read_urb, GFP_ATOMIC); |
639 | if (result) { | 639 | if (result) { |
640 | dev_err(&edge_serial->serial->dev->dev, "%s - usb_submit_urb(read bulk) failed with result = %d\n", __FUNCTION__, result); | 640 | dev_err(&edge_serial->serial->dev->dev, "%s - usb_submit_urb(read bulk) failed with result = %d\n", __FUNCTION__, result); |
641 | edge_serial->read_in_progress = FALSE; | 641 | edge_serial->read_in_progress = false; |
642 | } | 642 | } |
643 | } | 643 | } |
644 | spin_unlock(&edge_serial->es_lock); | 644 | spin_unlock(&edge_serial->es_lock); |
@@ -695,13 +695,13 @@ static void edge_bulk_in_callback (struct urb *urb) | |||
695 | 695 | ||
696 | if (urb->status) { | 696 | if (urb->status) { |
697 | dbg("%s - nonzero read bulk status received: %d", __FUNCTION__, urb->status); | 697 | dbg("%s - nonzero read bulk status received: %d", __FUNCTION__, urb->status); |
698 | edge_serial->read_in_progress = FALSE; | 698 | edge_serial->read_in_progress = false; |
699 | return; | 699 | return; |
700 | } | 700 | } |
701 | 701 | ||
702 | if (urb->actual_length == 0) { | 702 | if (urb->actual_length == 0) { |
703 | dbg("%s - read bulk callback with no data", __FUNCTION__); | 703 | dbg("%s - read bulk callback with no data", __FUNCTION__); |
704 | edge_serial->read_in_progress = FALSE; | 704 | edge_serial->read_in_progress = false; |
705 | return; | 705 | return; |
706 | } | 706 | } |
707 | 707 | ||
@@ -725,10 +725,10 @@ static void edge_bulk_in_callback (struct urb *urb) | |||
725 | status = usb_submit_urb(edge_serial->read_urb, GFP_ATOMIC); | 725 | status = usb_submit_urb(edge_serial->read_urb, GFP_ATOMIC); |
726 | if (status) { | 726 | if (status) { |
727 | dev_err(&urb->dev->dev, "%s - usb_submit_urb(read bulk) failed, status = %d\n", __FUNCTION__, status); | 727 | dev_err(&urb->dev->dev, "%s - usb_submit_urb(read bulk) failed, status = %d\n", __FUNCTION__, status); |
728 | edge_serial->read_in_progress = FALSE; | 728 | edge_serial->read_in_progress = false; |
729 | } | 729 | } |
730 | } else { | 730 | } else { |
731 | edge_serial->read_in_progress = FALSE; | 731 | edge_serial->read_in_progress = false; |
732 | } | 732 | } |
733 | 733 | ||
734 | spin_unlock(&edge_serial->es_lock); | 734 | spin_unlock(&edge_serial->es_lock); |
@@ -759,7 +759,7 @@ static void edge_bulk_out_data_callback (struct urb *urb) | |||
759 | } | 759 | } |
760 | 760 | ||
761 | // Release the Write URB | 761 | // Release the Write URB |
762 | edge_port->write_in_progress = FALSE; | 762 | edge_port->write_in_progress = false; |
763 | 763 | ||
764 | // Check if more data needs to be sent | 764 | // Check if more data needs to be sent |
765 | send_more_port_data((struct edgeport_serial *)(usb_get_serial_data(edge_port->port->serial)), edge_port); | 765 | send_more_port_data((struct edgeport_serial *)(usb_get_serial_data(edge_port->port->serial)), edge_port); |
@@ -779,8 +779,8 @@ static void edge_bulk_out_cmd_callback (struct urb *urb) | |||
779 | 779 | ||
780 | dbg("%s", __FUNCTION__); | 780 | dbg("%s", __FUNCTION__); |
781 | 781 | ||
782 | CmdUrbs--; | 782 | atomic_dec(&CmdUrbs); |
783 | dbg("%s - FREE URB %p (outstanding %d)", __FUNCTION__, urb, CmdUrbs); | 783 | dbg("%s - FREE URB %p (outstanding %d)", __FUNCTION__, urb, atomic_read(&CmdUrbs)); |
784 | 784 | ||
785 | 785 | ||
786 | /* clean up the transfer buffer */ | 786 | /* clean up the transfer buffer */ |
@@ -802,7 +802,7 @@ static void edge_bulk_out_cmd_callback (struct urb *urb) | |||
802 | tty_wakeup(tty); | 802 | tty_wakeup(tty); |
803 | 803 | ||
804 | /* we have completed the command */ | 804 | /* we have completed the command */ |
805 | edge_port->commandPending = FALSE; | 805 | edge_port->commandPending = false; |
806 | wake_up(&edge_port->wait_command); | 806 | wake_up(&edge_port->wait_command); |
807 | } | 807 | } |
808 | 808 | ||
@@ -868,7 +868,7 @@ static int edge_open (struct usb_serial_port *port, struct file * filp) | |||
868 | port0->bulk_in_buffer, | 868 | port0->bulk_in_buffer, |
869 | edge_serial->read_urb->transfer_buffer_length, | 869 | edge_serial->read_urb->transfer_buffer_length, |
870 | edge_bulk_in_callback, edge_serial); | 870 | edge_bulk_in_callback, edge_serial); |
871 | edge_serial->read_in_progress = FALSE; | 871 | edge_serial->read_in_progress = false; |
872 | 872 | ||
873 | /* start interrupt read for this edgeport | 873 | /* start interrupt read for this edgeport |
874 | * this interrupt will continue as long as the edgeport is connected */ | 874 | * this interrupt will continue as long as the edgeport is connected */ |
@@ -890,26 +890,26 @@ static int edge_open (struct usb_serial_port *port, struct file * filp) | |||
890 | /* initialize our port settings */ | 890 | /* initialize our port settings */ |
891 | edge_port->txCredits = 0; /* Can't send any data yet */ | 891 | edge_port->txCredits = 0; /* Can't send any data yet */ |
892 | edge_port->shadowMCR = MCR_MASTER_IE; /* Must always set this bit to enable ints! */ | 892 | edge_port->shadowMCR = MCR_MASTER_IE; /* Must always set this bit to enable ints! */ |
893 | edge_port->chaseResponsePending = FALSE; | 893 | edge_port->chaseResponsePending = false; |
894 | 894 | ||
895 | /* send a open port command */ | 895 | /* send a open port command */ |
896 | edge_port->openPending = TRUE; | 896 | edge_port->openPending = true; |
897 | edge_port->open = FALSE; | 897 | edge_port->open = false; |
898 | response = send_iosp_ext_cmd (edge_port, IOSP_CMD_OPEN_PORT, 0); | 898 | response = send_iosp_ext_cmd (edge_port, IOSP_CMD_OPEN_PORT, 0); |
899 | 899 | ||
900 | if (response < 0) { | 900 | if (response < 0) { |
901 | dev_err(&port->dev, "%s - error sending open port command\n", __FUNCTION__); | 901 | dev_err(&port->dev, "%s - error sending open port command\n", __FUNCTION__); |
902 | edge_port->openPending = FALSE; | 902 | edge_port->openPending = false; |
903 | return -ENODEV; | 903 | return -ENODEV; |
904 | } | 904 | } |
905 | 905 | ||
906 | /* now wait for the port to be completely opened */ | 906 | /* now wait for the port to be completely opened */ |
907 | wait_event_timeout(edge_port->wait_open, (edge_port->openPending != TRUE), OPEN_TIMEOUT); | 907 | wait_event_timeout(edge_port->wait_open, !edge_port->openPending, OPEN_TIMEOUT); |
908 | 908 | ||
909 | if (edge_port->open == FALSE) { | 909 | if (!edge_port->open) { |
910 | /* open timed out */ | 910 | /* open timed out */ |
911 | dbg("%s - open timedout", __FUNCTION__); | 911 | dbg("%s - open timedout", __FUNCTION__); |
912 | edge_port->openPending = FALSE; | 912 | edge_port->openPending = false; |
913 | return -ENODEV; | 913 | return -ENODEV; |
914 | } | 914 | } |
915 | 915 | ||
@@ -928,7 +928,7 @@ static int edge_open (struct usb_serial_port *port, struct file * filp) | |||
928 | 928 | ||
929 | /* Allocate a URB for the write */ | 929 | /* Allocate a URB for the write */ |
930 | edge_port->write_urb = usb_alloc_urb (0, GFP_KERNEL); | 930 | edge_port->write_urb = usb_alloc_urb (0, GFP_KERNEL); |
931 | edge_port->write_in_progress = FALSE; | 931 | edge_port->write_in_progress = false; |
932 | 932 | ||
933 | if (!edge_port->write_urb) { | 933 | if (!edge_port->write_urb) { |
934 | dbg("%s - no memory", __FUNCTION__); | 934 | dbg("%s - no memory", __FUNCTION__); |
@@ -966,7 +966,7 @@ static void block_until_chase_response(struct edgeport_port *edge_port) | |||
966 | lastCredits = edge_port->txCredits; | 966 | lastCredits = edge_port->txCredits; |
967 | 967 | ||
968 | // Did we get our Chase response | 968 | // Did we get our Chase response |
969 | if (edge_port->chaseResponsePending == FALSE) { | 969 | if (!edge_port->chaseResponsePending) { |
970 | dbg("%s - Got Chase Response", __FUNCTION__); | 970 | dbg("%s - Got Chase Response", __FUNCTION__); |
971 | 971 | ||
972 | // did we get all of our credit back? | 972 | // did we get all of our credit back? |
@@ -985,7 +985,7 @@ static void block_until_chase_response(struct edgeport_port *edge_port) | |||
985 | // No activity.. count down. | 985 | // No activity.. count down. |
986 | loop--; | 986 | loop--; |
987 | if (loop == 0) { | 987 | if (loop == 0) { |
988 | edge_port->chaseResponsePending = FALSE; | 988 | edge_port->chaseResponsePending = false; |
989 | dbg("%s - Chase TIMEOUT", __FUNCTION__); | 989 | dbg("%s - Chase TIMEOUT", __FUNCTION__); |
990 | return; | 990 | return; |
991 | } | 991 | } |
@@ -1068,13 +1068,13 @@ static void edge_close (struct usb_serial_port *port, struct file * filp) | |||
1068 | // block until tx is empty | 1068 | // block until tx is empty |
1069 | block_until_tx_empty(edge_port); | 1069 | block_until_tx_empty(edge_port); |
1070 | 1070 | ||
1071 | edge_port->closePending = TRUE; | 1071 | edge_port->closePending = true; |
1072 | 1072 | ||
1073 | if ((!edge_serial->is_epic) || | 1073 | if ((!edge_serial->is_epic) || |
1074 | ((edge_serial->is_epic) && | 1074 | ((edge_serial->is_epic) && |
1075 | (edge_serial->epic_descriptor.Supports.IOSPChase))) { | 1075 | (edge_serial->epic_descriptor.Supports.IOSPChase))) { |
1076 | /* flush and chase */ | 1076 | /* flush and chase */ |
1077 | edge_port->chaseResponsePending = TRUE; | 1077 | edge_port->chaseResponsePending = true; |
1078 | 1078 | ||
1079 | dbg("%s - Sending IOSP_CMD_CHASE_PORT", __FUNCTION__); | 1079 | dbg("%s - Sending IOSP_CMD_CHASE_PORT", __FUNCTION__); |
1080 | status = send_iosp_ext_cmd (edge_port, IOSP_CMD_CHASE_PORT, 0); | 1080 | status = send_iosp_ext_cmd (edge_port, IOSP_CMD_CHASE_PORT, 0); |
@@ -1082,7 +1082,7 @@ static void edge_close (struct usb_serial_port *port, struct file * filp) | |||
1082 | // block until chase finished | 1082 | // block until chase finished |
1083 | block_until_chase_response(edge_port); | 1083 | block_until_chase_response(edge_port); |
1084 | } else { | 1084 | } else { |
1085 | edge_port->chaseResponsePending = FALSE; | 1085 | edge_port->chaseResponsePending = false; |
1086 | } | 1086 | } |
1087 | } | 1087 | } |
1088 | 1088 | ||
@@ -1094,10 +1094,10 @@ static void edge_close (struct usb_serial_port *port, struct file * filp) | |||
1094 | send_iosp_ext_cmd (edge_port, IOSP_CMD_CLOSE_PORT, 0); | 1094 | send_iosp_ext_cmd (edge_port, IOSP_CMD_CLOSE_PORT, 0); |
1095 | } | 1095 | } |
1096 | 1096 | ||
1097 | //port->close = TRUE; | 1097 | //port->close = true; |
1098 | edge_port->closePending = FALSE; | 1098 | edge_port->closePending = false; |
1099 | edge_port->open = FALSE; | 1099 | edge_port->open = false; |
1100 | edge_port->openPending = FALSE; | 1100 | edge_port->openPending = false; |
1101 | 1101 | ||
1102 | usb_kill_urb(edge_port->write_urb); | 1102 | usb_kill_urb(edge_port->write_urb); |
1103 | 1103 | ||
@@ -1247,7 +1247,7 @@ static void send_more_port_data(struct edgeport_serial *edge_serial, struct edge | |||
1247 | } | 1247 | } |
1248 | 1248 | ||
1249 | // lock this write | 1249 | // lock this write |
1250 | edge_port->write_in_progress = TRUE; | 1250 | edge_port->write_in_progress = true; |
1251 | 1251 | ||
1252 | // get a pointer to the write_urb | 1252 | // get a pointer to the write_urb |
1253 | urb = edge_port->write_urb; | 1253 | urb = edge_port->write_urb; |
@@ -1261,7 +1261,7 @@ static void send_more_port_data(struct edgeport_serial *edge_serial, struct edge | |||
1261 | buffer = kmalloc (count+2, GFP_ATOMIC); | 1261 | buffer = kmalloc (count+2, GFP_ATOMIC); |
1262 | if (buffer == NULL) { | 1262 | if (buffer == NULL) { |
1263 | dev_err(&edge_port->port->dev, "%s - no more kernel memory...\n", __FUNCTION__); | 1263 | dev_err(&edge_port->port->dev, "%s - no more kernel memory...\n", __FUNCTION__); |
1264 | edge_port->write_in_progress = FALSE; | 1264 | edge_port->write_in_progress = false; |
1265 | goto exit_send; | 1265 | goto exit_send; |
1266 | } | 1266 | } |
1267 | buffer[0] = IOSP_BUILD_DATA_HDR1 (edge_port->port->number - edge_port->port->serial->minor, count); | 1267 | buffer[0] = IOSP_BUILD_DATA_HDR1 (edge_port->port->number - edge_port->port->serial->minor, count); |
@@ -1301,7 +1301,7 @@ static void send_more_port_data(struct edgeport_serial *edge_serial, struct edge | |||
1301 | if (status) { | 1301 | if (status) { |
1302 | /* something went wrong */ | 1302 | /* something went wrong */ |
1303 | dev_err(&edge_port->port->dev, "%s - usb_submit_urb(write bulk) failed, status = %d, data lost\n", __FUNCTION__, status); | 1303 | dev_err(&edge_port->port->dev, "%s - usb_submit_urb(write bulk) failed, status = %d, data lost\n", __FUNCTION__, status); |
1304 | edge_port->write_in_progress = FALSE; | 1304 | edge_port->write_in_progress = false; |
1305 | 1305 | ||
1306 | /* revert the credits as something bad happened. */ | 1306 | /* revert the credits as something bad happened. */ |
1307 | edge_port->txCredits += count; | 1307 | edge_port->txCredits += count; |
@@ -1332,7 +1332,7 @@ static int edge_write_room (struct usb_serial_port *port) | |||
1332 | 1332 | ||
1333 | if (edge_port == NULL) | 1333 | if (edge_port == NULL) |
1334 | return -ENODEV; | 1334 | return -ENODEV; |
1335 | if (edge_port->closePending == TRUE) | 1335 | if (edge_port->closePending) |
1336 | return -ENODEV; | 1336 | return -ENODEV; |
1337 | 1337 | ||
1338 | dbg("%s - port %d", __FUNCTION__, port->number); | 1338 | dbg("%s - port %d", __FUNCTION__, port->number); |
@@ -1371,7 +1371,7 @@ static int edge_chars_in_buffer (struct usb_serial_port *port) | |||
1371 | 1371 | ||
1372 | if (edge_port == NULL) | 1372 | if (edge_port == NULL) |
1373 | return -ENODEV; | 1373 | return -ENODEV; |
1374 | if (edge_port->closePending == TRUE) | 1374 | if (edge_port->closePending) |
1375 | return -ENODEV; | 1375 | return -ENODEV; |
1376 | 1376 | ||
1377 | if (!edge_port->open) { | 1377 | if (!edge_port->open) { |
@@ -1762,7 +1762,7 @@ static void edge_break (struct usb_serial_port *port, int break_state) | |||
1762 | ((edge_serial->is_epic) && | 1762 | ((edge_serial->is_epic) && |
1763 | (edge_serial->epic_descriptor.Supports.IOSPChase))) { | 1763 | (edge_serial->epic_descriptor.Supports.IOSPChase))) { |
1764 | /* flush and chase */ | 1764 | /* flush and chase */ |
1765 | edge_port->chaseResponsePending = TRUE; | 1765 | edge_port->chaseResponsePending = true; |
1766 | 1766 | ||
1767 | dbg("%s - Sending IOSP_CMD_CHASE_PORT", __FUNCTION__); | 1767 | dbg("%s - Sending IOSP_CMD_CHASE_PORT", __FUNCTION__); |
1768 | status = send_iosp_ext_cmd (edge_port, IOSP_CMD_CHASE_PORT, 0); | 1768 | status = send_iosp_ext_cmd (edge_port, IOSP_CMD_CHASE_PORT, 0); |
@@ -1770,7 +1770,7 @@ static void edge_break (struct usb_serial_port *port, int break_state) | |||
1770 | // block until chase finished | 1770 | // block until chase finished |
1771 | block_until_chase_response(edge_port); | 1771 | block_until_chase_response(edge_port); |
1772 | } else { | 1772 | } else { |
1773 | edge_port->chaseResponsePending = FALSE; | 1773 | edge_port->chaseResponsePending = false; |
1774 | } | 1774 | } |
1775 | } | 1775 | } |
1776 | 1776 | ||
@@ -1952,13 +1952,13 @@ static void process_rcvd_status (struct edgeport_serial *edge_serial, __u8 byte2 | |||
1952 | // Also, we currently clear flag and close the port regardless of content of above's Byte3. | 1952 | // Also, we currently clear flag and close the port regardless of content of above's Byte3. |
1953 | // We could choose to do something else when Byte3 says Timeout on Chase from Edgeport, | 1953 | // We could choose to do something else when Byte3 says Timeout on Chase from Edgeport, |
1954 | // like wait longer in block_until_chase_response, but for now we don't. | 1954 | // like wait longer in block_until_chase_response, but for now we don't. |
1955 | edge_port->chaseResponsePending = FALSE; | 1955 | edge_port->chaseResponsePending = false; |
1956 | wake_up (&edge_port->wait_chase); | 1956 | wake_up (&edge_port->wait_chase); |
1957 | return; | 1957 | return; |
1958 | 1958 | ||
1959 | case IOSP_EXT_STATUS_RX_CHECK_RSP: | 1959 | case IOSP_EXT_STATUS_RX_CHECK_RSP: |
1960 | dbg("%s ========== Port %u CHECK_RSP Sequence = %02x =============\n", __FUNCTION__, edge_serial->rxPort, byte3 ); | 1960 | dbg("%s ========== Port %u CHECK_RSP Sequence = %02x =============\n", __FUNCTION__, edge_serial->rxPort, byte3 ); |
1961 | //Port->RxCheckRsp = TRUE; | 1961 | //Port->RxCheckRsp = true; |
1962 | return; | 1962 | return; |
1963 | } | 1963 | } |
1964 | } | 1964 | } |
@@ -1974,8 +1974,8 @@ static void process_rcvd_status (struct edgeport_serial *edge_serial, __u8 byte2 | |||
1974 | change_port_settings (edge_port, edge_port->port->tty->termios); | 1974 | change_port_settings (edge_port, edge_port->port->tty->termios); |
1975 | 1975 | ||
1976 | /* we have completed the open */ | 1976 | /* we have completed the open */ |
1977 | edge_port->openPending = FALSE; | 1977 | edge_port->openPending = false; |
1978 | edge_port->open = TRUE; | 1978 | edge_port->open = true; |
1979 | wake_up(&edge_port->wait_open); | 1979 | wake_up(&edge_port->wait_open); |
1980 | return; | 1980 | return; |
1981 | } | 1981 | } |
@@ -1983,7 +1983,7 @@ static void process_rcvd_status (struct edgeport_serial *edge_serial, __u8 byte2 | |||
1983 | // If port is closed, silently discard all rcvd status. We can | 1983 | // If port is closed, silently discard all rcvd status. We can |
1984 | // have cases where buffered status is received AFTER the close | 1984 | // have cases where buffered status is received AFTER the close |
1985 | // port command is sent to the Edgeport. | 1985 | // port command is sent to the Edgeport. |
1986 | if ((!edge_port->open ) || (edge_port->closePending)) { | 1986 | if (!edge_port->open || edge_port->closePending) { |
1987 | return; | 1987 | return; |
1988 | } | 1988 | } |
1989 | 1989 | ||
@@ -1991,14 +1991,14 @@ static void process_rcvd_status (struct edgeport_serial *edge_serial, __u8 byte2 | |||
1991 | // Not currently sent by Edgeport | 1991 | // Not currently sent by Edgeport |
1992 | case IOSP_STATUS_LSR: | 1992 | case IOSP_STATUS_LSR: |
1993 | dbg("%s - Port %u LSR Status = %02x", __FUNCTION__, edge_serial->rxPort, byte2); | 1993 | dbg("%s - Port %u LSR Status = %02x", __FUNCTION__, edge_serial->rxPort, byte2); |
1994 | handle_new_lsr (edge_port, FALSE, byte2, 0); | 1994 | handle_new_lsr(edge_port, false, byte2, 0); |
1995 | break; | 1995 | break; |
1996 | 1996 | ||
1997 | case IOSP_STATUS_LSR_DATA: | 1997 | case IOSP_STATUS_LSR_DATA: |
1998 | dbg("%s - Port %u LSR Status = %02x, Data = %02x", __FUNCTION__, edge_serial->rxPort, byte2, byte3); | 1998 | dbg("%s - Port %u LSR Status = %02x, Data = %02x", __FUNCTION__, edge_serial->rxPort, byte2, byte3); |
1999 | // byte2 is LSR Register | 1999 | // byte2 is LSR Register |
2000 | // byte3 is broken data byte | 2000 | // byte3 is broken data byte |
2001 | handle_new_lsr (edge_port, TRUE, byte2, byte3); | 2001 | handle_new_lsr(edge_port, true, byte2, byte3); |
2002 | break; | 2002 | break; |
2003 | // | 2003 | // |
2004 | // case IOSP_EXT_4_STATUS: | 2004 | // case IOSP_EXT_4_STATUS: |
@@ -2317,14 +2317,14 @@ static int write_cmd_usb (struct edgeport_port *edge_port, unsigned char *buffer | |||
2317 | if (!urb) | 2317 | if (!urb) |
2318 | return -ENOMEM; | 2318 | return -ENOMEM; |
2319 | 2319 | ||
2320 | CmdUrbs++; | 2320 | atomic_inc(&CmdUrbs); |
2321 | dbg("%s - ALLOCATE URB %p (outstanding %d)", __FUNCTION__, urb, CmdUrbs); | 2321 | dbg("%s - ALLOCATE URB %p (outstanding %d)", __FUNCTION__, urb, atomic_read(&CmdUrbs)); |
2322 | 2322 | ||
2323 | usb_fill_bulk_urb (urb, edge_serial->serial->dev, | 2323 | usb_fill_bulk_urb (urb, edge_serial->serial->dev, |
2324 | usb_sndbulkpipe(edge_serial->serial->dev, edge_serial->bulk_out_endpoint), | 2324 | usb_sndbulkpipe(edge_serial->serial->dev, edge_serial->bulk_out_endpoint), |
2325 | buffer, length, edge_bulk_out_cmd_callback, edge_port); | 2325 | buffer, length, edge_bulk_out_cmd_callback, edge_port); |
2326 | 2326 | ||
2327 | edge_port->commandPending = TRUE; | 2327 | edge_port->commandPending = true; |
2328 | status = usb_submit_urb(urb, GFP_ATOMIC); | 2328 | status = usb_submit_urb(urb, GFP_ATOMIC); |
2329 | 2329 | ||
2330 | if (status) { | 2330 | if (status) { |
@@ -2332,16 +2332,16 @@ static int write_cmd_usb (struct edgeport_port *edge_port, unsigned char *buffer | |||
2332 | dev_err(&edge_port->port->dev, "%s - usb_submit_urb(write command) failed, status = %d\n", __FUNCTION__, status); | 2332 | dev_err(&edge_port->port->dev, "%s - usb_submit_urb(write command) failed, status = %d\n", __FUNCTION__, status); |
2333 | usb_kill_urb(urb); | 2333 | usb_kill_urb(urb); |
2334 | usb_free_urb(urb); | 2334 | usb_free_urb(urb); |
2335 | CmdUrbs--; | 2335 | atomic_dec(&CmdUrbs); |
2336 | return status; | 2336 | return status; |
2337 | } | 2337 | } |
2338 | 2338 | ||
2339 | // wait for command to finish | 2339 | // wait for command to finish |
2340 | timeout = COMMAND_TIMEOUT; | 2340 | timeout = COMMAND_TIMEOUT; |
2341 | #if 0 | 2341 | #if 0 |
2342 | wait_event (&edge_port->wait_command, (edge_port->commandPending == FALSE)); | 2342 | wait_event (&edge_port->wait_command, !edge_port->commandPending); |
2343 | 2343 | ||
2344 | if (edge_port->commandPending == TRUE) { | 2344 | if (edge_port->commandPending) { |
2345 | /* command timed out */ | 2345 | /* command timed out */ |
2346 | dbg("%s - command timed out", __FUNCTION__); | 2346 | dbg("%s - command timed out", __FUNCTION__); |
2347 | status = -EINVAL; | 2347 | status = -EINVAL; |
@@ -2524,8 +2524,8 @@ static void change_port_settings (struct edgeport_port *edge_port, struct ktermi | |||
2524 | 2524 | ||
2525 | dbg("%s - port %d", __FUNCTION__, edge_port->port->number); | 2525 | dbg("%s - port %d", __FUNCTION__, edge_port->port->number); |
2526 | 2526 | ||
2527 | if ((!edge_port->open) && | 2527 | if (!edge_port->open && |
2528 | (!edge_port->openPending)) { | 2528 | !edge_port->openPending) { |
2529 | dbg("%s - port not opened", __FUNCTION__); | 2529 | dbg("%s - port not opened", __FUNCTION__); |
2530 | return; | 2530 | return; |
2531 | } | 2531 | } |
@@ -2836,9 +2836,9 @@ static int edge_startup (struct usb_serial *serial) | |||
2836 | struct usb_device *dev; | 2836 | struct usb_device *dev; |
2837 | int i, j; | 2837 | int i, j; |
2838 | int response; | 2838 | int response; |
2839 | int interrupt_in_found; | 2839 | bool interrupt_in_found; |
2840 | int bulk_in_found; | 2840 | bool bulk_in_found; |
2841 | int bulk_out_found; | 2841 | bool bulk_out_found; |
2842 | static __u32 descriptor[3] = { EDGE_COMPATIBILITY_MASK0, | 2842 | static __u32 descriptor[3] = { EDGE_COMPATIBILITY_MASK0, |
2843 | EDGE_COMPATIBILITY_MASK1, | 2843 | EDGE_COMPATIBILITY_MASK1, |
2844 | EDGE_COMPATIBILITY_MASK2 }; | 2844 | EDGE_COMPATIBILITY_MASK2 }; |
@@ -2936,14 +2936,14 @@ static int edge_startup (struct usb_serial *serial) | |||
2936 | if (edge_serial->is_epic) { | 2936 | if (edge_serial->is_epic) { |
2937 | /* EPIC thing, set up our interrupt polling now and our read urb, so | 2937 | /* EPIC thing, set up our interrupt polling now and our read urb, so |
2938 | * that the device knows it really is connected. */ | 2938 | * that the device knows it really is connected. */ |
2939 | interrupt_in_found = bulk_in_found = bulk_out_found = FALSE; | 2939 | interrupt_in_found = bulk_in_found = bulk_out_found = false; |
2940 | for (i = 0; i < serial->interface->altsetting[0].desc.bNumEndpoints; ++i) { | 2940 | for (i = 0; i < serial->interface->altsetting[0].desc.bNumEndpoints; ++i) { |
2941 | struct usb_endpoint_descriptor *endpoint; | 2941 | struct usb_endpoint_descriptor *endpoint; |
2942 | int buffer_size; | 2942 | int buffer_size; |
2943 | 2943 | ||
2944 | endpoint = &serial->interface->altsetting[0].endpoint[i].desc; | 2944 | endpoint = &serial->interface->altsetting[0].endpoint[i].desc; |
2945 | buffer_size = le16_to_cpu(endpoint->wMaxPacketSize); | 2945 | buffer_size = le16_to_cpu(endpoint->wMaxPacketSize); |
2946 | if ((!interrupt_in_found) && | 2946 | if (!interrupt_in_found && |
2947 | (usb_endpoint_is_int_in(endpoint))) { | 2947 | (usb_endpoint_is_int_in(endpoint))) { |
2948 | /* we found a interrupt in endpoint */ | 2948 | /* we found a interrupt in endpoint */ |
2949 | dbg("found interrupt in"); | 2949 | dbg("found interrupt in"); |
@@ -2972,10 +2972,10 @@ static int edge_startup (struct usb_serial *serial) | |||
2972 | edge_serial, | 2972 | edge_serial, |
2973 | endpoint->bInterval); | 2973 | endpoint->bInterval); |
2974 | 2974 | ||
2975 | interrupt_in_found = TRUE; | 2975 | interrupt_in_found = true; |
2976 | } | 2976 | } |
2977 | 2977 | ||
2978 | if ((!bulk_in_found) && | 2978 | if (!bulk_in_found && |
2979 | (usb_endpoint_is_bulk_in(endpoint))) { | 2979 | (usb_endpoint_is_bulk_in(endpoint))) { |
2980 | /* we found a bulk in endpoint */ | 2980 | /* we found a bulk in endpoint */ |
2981 | dbg("found bulk in"); | 2981 | dbg("found bulk in"); |
@@ -3001,19 +3001,19 @@ static int edge_startup (struct usb_serial *serial) | |||
3001 | endpoint->wMaxPacketSize, | 3001 | endpoint->wMaxPacketSize, |
3002 | edge_bulk_in_callback, | 3002 | edge_bulk_in_callback, |
3003 | edge_serial); | 3003 | edge_serial); |
3004 | bulk_in_found = TRUE; | 3004 | bulk_in_found = true; |
3005 | } | 3005 | } |
3006 | 3006 | ||
3007 | if ((!bulk_out_found) && | 3007 | if (!bulk_out_found && |
3008 | (usb_endpoint_is_bulk_out(endpoint))) { | 3008 | (usb_endpoint_is_bulk_out(endpoint))) { |
3009 | /* we found a bulk out endpoint */ | 3009 | /* we found a bulk out endpoint */ |
3010 | dbg("found bulk out"); | 3010 | dbg("found bulk out"); |
3011 | edge_serial->bulk_out_endpoint = endpoint->bEndpointAddress; | 3011 | edge_serial->bulk_out_endpoint = endpoint->bEndpointAddress; |
3012 | bulk_out_found = TRUE; | 3012 | bulk_out_found = true; |
3013 | } | 3013 | } |
3014 | } | 3014 | } |
3015 | 3015 | ||
3016 | if ((!interrupt_in_found) || (!bulk_in_found) || (!bulk_out_found)) { | 3016 | if (!interrupt_in_found || !bulk_in_found || !bulk_out_found) { |
3017 | err ("Error - the proper endpoints were not found!"); | 3017 | err ("Error - the proper endpoints were not found!"); |
3018 | return -ENODEV; | 3018 | return -ENODEV; |
3019 | } | 3019 | } |
@@ -3083,6 +3083,7 @@ static int __init edgeport_init(void) | |||
3083 | retval = usb_register(&io_driver); | 3083 | retval = usb_register(&io_driver); |
3084 | if (retval) | 3084 | if (retval) |
3085 | goto failed_usb_register; | 3085 | goto failed_usb_register; |
3086 | atomic_set(&CmdUrbs, 0); | ||
3086 | info(DRIVER_DESC " " DRIVER_VERSION); | 3087 | info(DRIVER_DESC " " DRIVER_VERSION); |
3087 | return 0; | 3088 | return 0; |
3088 | 3089 | ||
diff --git a/drivers/usb/serial/io_edgeport.h b/drivers/usb/serial/io_edgeport.h index 29a913a6daca..cb201c1f67f9 100644 --- a/drivers/usb/serial/io_edgeport.h +++ b/drivers/usb/serial/io_edgeport.h | |||
@@ -19,12 +19,6 @@ | |||
19 | #define MAX_RS232_PORTS 8 /* Max # of RS-232 ports per device */ | 19 | #define MAX_RS232_PORTS 8 /* Max # of RS-232 ports per device */ |
20 | 20 | ||
21 | /* typedefs that the insideout headers need */ | 21 | /* typedefs that the insideout headers need */ |
22 | #ifndef TRUE | ||
23 | #define TRUE (1) | ||
24 | #endif | ||
25 | #ifndef FALSE | ||
26 | #define FALSE (0) | ||
27 | #endif | ||
28 | #ifndef LOW8 | 22 | #ifndef LOW8 |
29 | #define LOW8(a) ((unsigned char)(a & 0xff)) | 23 | #define LOW8(a) ((unsigned char)(a & 0xff)) |
30 | #endif | 24 | #endif |
diff --git a/drivers/usb/serial/ipaq.c b/drivers/usb/serial/ipaq.c index a408184334ea..4df0ec74e0b1 100644 --- a/drivers/usb/serial/ipaq.c +++ b/drivers/usb/serial/ipaq.c | |||
@@ -247,12 +247,15 @@ static struct usb_device_id ipaq_id_table [] = { | |||
247 | { USB_DEVICE(0x04AD, 0x0301) }, /* USB Sync 0301 */ | 247 | { USB_DEVICE(0x04AD, 0x0301) }, /* USB Sync 0301 */ |
248 | { USB_DEVICE(0x04AD, 0x0302) }, /* USB Sync 0302 */ | 248 | { USB_DEVICE(0x04AD, 0x0302) }, /* USB Sync 0302 */ |
249 | { USB_DEVICE(0x04AD, 0x0303) }, /* USB Sync 0303 */ | 249 | { USB_DEVICE(0x04AD, 0x0303) }, /* USB Sync 0303 */ |
250 | { USB_DEVICE(0x04AD, 0x0306) }, /* GPS Pocket PC USB Sync */ | ||
251 | { USB_DEVICE(0x04B7, 0x0531) }, /* MyGuide 7000 XL USB Sync */ | ||
250 | { USB_DEVICE(0x04C5, 0x1058) }, /* FUJITSU USB Sync */ | 252 | { USB_DEVICE(0x04C5, 0x1058) }, /* FUJITSU USB Sync */ |
251 | { USB_DEVICE(0x04C5, 0x1079) }, /* FUJITSU USB Sync */ | 253 | { USB_DEVICE(0x04C5, 0x1079) }, /* FUJITSU USB Sync */ |
252 | { USB_DEVICE(0x04DA, 0x2500) }, /* Panasonic USB Sync */ | 254 | { USB_DEVICE(0x04DA, 0x2500) }, /* Panasonic USB Sync */ |
253 | { USB_DEVICE(0x04DD, 0x9102) }, /* SHARP WS003SH USB Modem */ | 255 | { USB_DEVICE(0x04DD, 0x9102) }, /* SHARP WS003SH USB Modem */ |
254 | { USB_DEVICE(0x04DD, 0x9121) }, /* SHARP WS004SH USB Modem */ | 256 | { USB_DEVICE(0x04DD, 0x9121) }, /* SHARP WS004SH USB Modem */ |
255 | { USB_DEVICE(0x04DD, 0x9123) }, /* SHARP WS007SH USB Modem */ | 257 | { USB_DEVICE(0x04DD, 0x9123) }, /* SHARP WS007SH USB Modem */ |
258 | { USB_DEVICE(0x04DD, 0x9151) }, /* SHARP S01SH USB Modem */ | ||
256 | { USB_DEVICE(0x04E8, 0x5F00) }, /* Samsung NEXiO USB Sync */ | 259 | { USB_DEVICE(0x04E8, 0x5F00) }, /* Samsung NEXiO USB Sync */ |
257 | { USB_DEVICE(0x04E8, 0x5F01) }, /* Samsung NEXiO USB Sync */ | 260 | { USB_DEVICE(0x04E8, 0x5F01) }, /* Samsung NEXiO USB Sync */ |
258 | { USB_DEVICE(0x04E8, 0x5F02) }, /* Samsung NEXiO USB Sync */ | 261 | { USB_DEVICE(0x04E8, 0x5F02) }, /* Samsung NEXiO USB Sync */ |
diff --git a/drivers/usb/serial/kl5kusb105.c b/drivers/usb/serial/kl5kusb105.c index b2097c45a235..7b085f334ceb 100644 --- a/drivers/usb/serial/kl5kusb105.c +++ b/drivers/usb/serial/kl5kusb105.c | |||
@@ -238,7 +238,7 @@ static int klsi_105_get_line_state(struct usb_serial_port *port, | |||
238 | if (rc < 0) | 238 | if (rc < 0) |
239 | err("Reading line status failed (error = %d)", rc); | 239 | err("Reading line status failed (error = %d)", rc); |
240 | else { | 240 | else { |
241 | status = status_buf[0] + (status_buf[1]<<8); | 241 | status = le16_to_cpu(*(u16 *)status_buf); |
242 | 242 | ||
243 | info("%s - read status %x %x", __FUNCTION__, | 243 | info("%s - read status %x %x", __FUNCTION__, |
244 | status_buf[0], status_buf[1]); | 244 | status_buf[0], status_buf[1]); |
@@ -257,7 +257,7 @@ static int klsi_105_get_line_state(struct usb_serial_port *port, | |||
257 | static int klsi_105_startup (struct usb_serial *serial) | 257 | static int klsi_105_startup (struct usb_serial *serial) |
258 | { | 258 | { |
259 | struct klsi_105_private *priv; | 259 | struct klsi_105_private *priv; |
260 | int i; | 260 | int i, j; |
261 | 261 | ||
262 | /* check if we support the product id (see keyspan.c) | 262 | /* check if we support the product id (see keyspan.c) |
263 | * FIXME | 263 | * FIXME |
@@ -265,12 +265,12 @@ static int klsi_105_startup (struct usb_serial *serial) | |||
265 | 265 | ||
266 | /* allocate the private data structure */ | 266 | /* allocate the private data structure */ |
267 | for (i=0; i<serial->num_ports; i++) { | 267 | for (i=0; i<serial->num_ports; i++) { |
268 | int j; | ||
269 | priv = kmalloc(sizeof(struct klsi_105_private), | 268 | priv = kmalloc(sizeof(struct klsi_105_private), |
270 | GFP_KERNEL); | 269 | GFP_KERNEL); |
271 | if (!priv) { | 270 | if (!priv) { |
272 | dbg("%skmalloc for klsi_105_private failed.", __FUNCTION__); | 271 | dbg("%skmalloc for klsi_105_private failed.", __FUNCTION__); |
273 | return -ENOMEM; | 272 | i--; |
273 | goto err_cleanup; | ||
274 | } | 274 | } |
275 | /* set initial values for control structures */ | 275 | /* set initial values for control structures */ |
276 | priv->cfg.pktlen = 5; | 276 | priv->cfg.pktlen = 5; |
@@ -292,15 +292,14 @@ static int klsi_105_startup (struct usb_serial *serial) | |||
292 | priv->write_urb_pool[j] = urb; | 292 | priv->write_urb_pool[j] = urb; |
293 | if (urb == NULL) { | 293 | if (urb == NULL) { |
294 | err("No more urbs???"); | 294 | err("No more urbs???"); |
295 | continue; | 295 | goto err_cleanup; |
296 | } | 296 | } |
297 | 297 | ||
298 | urb->transfer_buffer = NULL; | ||
299 | urb->transfer_buffer = kmalloc (URB_TRANSFER_BUFFER_SIZE, | 298 | urb->transfer_buffer = kmalloc (URB_TRANSFER_BUFFER_SIZE, |
300 | GFP_KERNEL); | 299 | GFP_KERNEL); |
301 | if (!urb->transfer_buffer) { | 300 | if (!urb->transfer_buffer) { |
302 | err("%s - out of memory for urb buffers.", __FUNCTION__); | 301 | err("%s - out of memory for urb buffers.", __FUNCTION__); |
303 | continue; | 302 | goto err_cleanup; |
304 | } | 303 | } |
305 | } | 304 | } |
306 | 305 | ||
@@ -308,7 +307,20 @@ static int klsi_105_startup (struct usb_serial *serial) | |||
308 | init_waitqueue_head(&serial->port[i]->write_wait); | 307 | init_waitqueue_head(&serial->port[i]->write_wait); |
309 | } | 308 | } |
310 | 309 | ||
311 | return (0); | 310 | return 0; |
311 | |||
312 | err_cleanup: | ||
313 | for (; i >= 0; i--) { | ||
314 | priv = usb_get_serial_port_data(serial->port[i]); | ||
315 | for (j=0; j < NUM_URBS; j++) { | ||
316 | if (priv->write_urb_pool[j]) { | ||
317 | kfree(priv->write_urb_pool[j]->transfer_buffer); | ||
318 | usb_free_urb(priv->write_urb_pool[j]); | ||
319 | } | ||
320 | } | ||
321 | usb_set_serial_port_data(serial->port[i], NULL); | ||
322 | } | ||
323 | return -ENOMEM; | ||
312 | } /* klsi_105_startup */ | 324 | } /* klsi_105_startup */ |
313 | 325 | ||
314 | 326 | ||
diff --git a/drivers/usb/serial/mct_u232.c b/drivers/usb/serial/mct_u232.c index 4cd839b1407f..3db1adc25f84 100644 --- a/drivers/usb/serial/mct_u232.c +++ b/drivers/usb/serial/mct_u232.c | |||
@@ -438,17 +438,21 @@ static int mct_u232_open (struct usb_serial_port *port, struct file *filp) | |||
438 | if (retval) { | 438 | if (retval) { |
439 | err("usb_submit_urb(read bulk) failed pipe 0x%x err %d", | 439 | err("usb_submit_urb(read bulk) failed pipe 0x%x err %d", |
440 | port->read_urb->pipe, retval); | 440 | port->read_urb->pipe, retval); |
441 | goto exit; | 441 | goto error; |
442 | } | 442 | } |
443 | 443 | ||
444 | port->interrupt_in_urb->dev = port->serial->dev; | 444 | port->interrupt_in_urb->dev = port->serial->dev; |
445 | retval = usb_submit_urb(port->interrupt_in_urb, GFP_KERNEL); | 445 | retval = usb_submit_urb(port->interrupt_in_urb, GFP_KERNEL); |
446 | if (retval) | 446 | if (retval) { |
447 | usb_kill_urb(port->read_urb); | ||
447 | err(" usb_submit_urb(read int) failed pipe 0x%x err %d", | 448 | err(" usb_submit_urb(read int) failed pipe 0x%x err %d", |
448 | port->interrupt_in_urb->pipe, retval); | 449 | port->interrupt_in_urb->pipe, retval); |
449 | 450 | goto error; | |
450 | exit: | 451 | } |
451 | return 0; | 452 | return 0; |
453 | |||
454 | error: | ||
455 | return retval; | ||
452 | } /* mct_u232_open */ | 456 | } /* mct_u232_open */ |
453 | 457 | ||
454 | 458 | ||
diff --git a/drivers/usb/serial/mos7720.c b/drivers/usb/serial/mos7720.c index 2d588fb82573..b563e2ad8728 100644 --- a/drivers/usb/serial/mos7720.c +++ b/drivers/usb/serial/mos7720.c | |||
@@ -103,11 +103,9 @@ static void mos7720_interrupt_callback(struct urb *urb) | |||
103 | { | 103 | { |
104 | int result; | 104 | int result; |
105 | int length; | 105 | int length; |
106 | __u32 *data; | 106 | __u8 *data; |
107 | unsigned int status; | ||
108 | __u8 sp1; | 107 | __u8 sp1; |
109 | __u8 sp2; | 108 | __u8 sp2; |
110 | __u8 st; | ||
111 | 109 | ||
112 | dbg("%s"," : Entering\n"); | 110 | dbg("%s"," : Entering\n"); |
113 | 111 | ||
@@ -141,18 +139,19 @@ static void mos7720_interrupt_callback(struct urb *urb) | |||
141 | * Byte 2 IIR Port 2 (port.number is 1) | 139 | * Byte 2 IIR Port 2 (port.number is 1) |
142 | * Byte 3 -------------- | 140 | * Byte 3 -------------- |
143 | * Byte 4 FIFO status for both */ | 141 | * Byte 4 FIFO status for both */ |
144 | if (length && length > 4) { | 142 | |
143 | /* the above description is inverted | ||
144 | * oneukum 2007-03-14 */ | ||
145 | |||
146 | if (unlikely(length != 4)) { | ||
145 | dbg("Wrong data !!!"); | 147 | dbg("Wrong data !!!"); |
146 | return; | 148 | return; |
147 | } | 149 | } |
148 | 150 | ||
149 | status = *data; | 151 | sp1 = data[3]; |
150 | 152 | sp2 = data[2]; | |
151 | sp1 = (status & 0xff000000)>>24; | ||
152 | sp2 = (status & 0x00ff0000)>>16; | ||
153 | st = status & 0x000000ff; | ||
154 | 153 | ||
155 | if ((sp1 & 0x01) || (sp2 & 0x01)) { | 154 | if ((sp1 | sp2) & 0x01) { |
156 | /* No Interrupt Pending in both the ports */ | 155 | /* No Interrupt Pending in both the ports */ |
157 | dbg("No Interrupt !!!"); | 156 | dbg("No Interrupt !!!"); |
158 | } else { | 157 | } else { |
@@ -333,6 +332,7 @@ static int mos7720_open(struct usb_serial_port *port, struct file * filp) | |||
333 | int response; | 332 | int response; |
334 | int port_number; | 333 | int port_number; |
335 | char data; | 334 | char data; |
335 | int allocated_urbs = 0; | ||
336 | int j; | 336 | int j; |
337 | 337 | ||
338 | serial = port->serial; | 338 | serial = port->serial; |
@@ -353,7 +353,7 @@ static int mos7720_open(struct usb_serial_port *port, struct file * filp) | |||
353 | 353 | ||
354 | /* Initialising the write urb pool */ | 354 | /* Initialising the write urb pool */ |
355 | for (j = 0; j < NUM_URBS; ++j) { | 355 | for (j = 0; j < NUM_URBS; ++j) { |
356 | urb = usb_alloc_urb(0,GFP_ATOMIC); | 356 | urb = usb_alloc_urb(0,GFP_KERNEL); |
357 | mos7720_port->write_urb_pool[j] = urb; | 357 | mos7720_port->write_urb_pool[j] = urb; |
358 | 358 | ||
359 | if (urb == NULL) { | 359 | if (urb == NULL) { |
@@ -365,10 +365,16 @@ static int mos7720_open(struct usb_serial_port *port, struct file * filp) | |||
365 | GFP_KERNEL); | 365 | GFP_KERNEL); |
366 | if (!urb->transfer_buffer) { | 366 | if (!urb->transfer_buffer) { |
367 | err("%s-out of memory for urb buffers.", __FUNCTION__); | 367 | err("%s-out of memory for urb buffers.", __FUNCTION__); |
368 | usb_free_urb(mos7720_port->write_urb_pool[j]); | ||
369 | mos7720_port->write_urb_pool[j] = NULL; | ||
368 | continue; | 370 | continue; |
369 | } | 371 | } |
372 | allocated_urbs++; | ||
370 | } | 373 | } |
371 | 374 | ||
375 | if (!allocated_urbs) | ||
376 | return -ENOMEM; | ||
377 | |||
372 | /* Initialize MCS7720 -- Write Init values to corresponding Registers | 378 | /* Initialize MCS7720 -- Write Init values to corresponding Registers |
373 | * | 379 | * |
374 | * Register Index | 380 | * Register Index |
@@ -526,7 +532,7 @@ static int mos7720_chars_in_buffer(struct usb_serial_port *port) | |||
526 | } | 532 | } |
527 | 533 | ||
528 | for (i = 0; i < NUM_URBS; ++i) { | 534 | for (i = 0; i < NUM_URBS; ++i) { |
529 | if (mos7720_port->write_urb_pool[i]->status == -EINPROGRESS) | 535 | if (mos7720_port->write_urb_pool[i] && mos7720_port->write_urb_pool[i]->status == -EINPROGRESS) |
530 | chars += URB_TRANSFER_BUFFER_SIZE; | 536 | chars += URB_TRANSFER_BUFFER_SIZE; |
531 | } | 537 | } |
532 | dbg("%s - returns %d", __FUNCTION__, chars); | 538 | dbg("%s - returns %d", __FUNCTION__, chars); |
@@ -629,7 +635,7 @@ static int mos7720_write_room(struct usb_serial_port *port) | |||
629 | } | 635 | } |
630 | 636 | ||
631 | for (i = 0; i < NUM_URBS; ++i) { | 637 | for (i = 0; i < NUM_URBS; ++i) { |
632 | if (mos7720_port->write_urb_pool[i]->status != -EINPROGRESS) | 638 | if (mos7720_port->write_urb_pool[i] && mos7720_port->write_urb_pool[i]->status != -EINPROGRESS) |
633 | room += URB_TRANSFER_BUFFER_SIZE; | 639 | room += URB_TRANSFER_BUFFER_SIZE; |
634 | } | 640 | } |
635 | 641 | ||
@@ -664,7 +670,7 @@ static int mos7720_write(struct usb_serial_port *port, | |||
664 | urb = NULL; | 670 | urb = NULL; |
665 | 671 | ||
666 | for (i = 0; i < NUM_URBS; ++i) { | 672 | for (i = 0; i < NUM_URBS; ++i) { |
667 | if (mos7720_port->write_urb_pool[i]->status != -EINPROGRESS) { | 673 | if (mos7720_port->write_urb_pool[i] && mos7720_port->write_urb_pool[i]->status != -EINPROGRESS) { |
668 | urb = mos7720_port->write_urb_pool[i]; | 674 | urb = mos7720_port->write_urb_pool[i]; |
669 | dbg("URB:%d",i); | 675 | dbg("URB:%d",i); |
670 | break; | 676 | break; |
@@ -1628,6 +1634,7 @@ static struct usb_serial_driver moschip7720_2port_driver = { | |||
1628 | .chars_in_buffer = mos7720_chars_in_buffer, | 1634 | .chars_in_buffer = mos7720_chars_in_buffer, |
1629 | .break_ctl = mos7720_break, | 1635 | .break_ctl = mos7720_break, |
1630 | .read_bulk_callback = mos7720_bulk_in_callback, | 1636 | .read_bulk_callback = mos7720_bulk_in_callback, |
1637 | .read_int_callback = mos7720_interrupt_callback, | ||
1631 | }; | 1638 | }; |
1632 | 1639 | ||
1633 | static int __init moschip7720_init(void) | 1640 | static int __init moschip7720_init(void) |
diff --git a/drivers/usb/serial/mos7840.c b/drivers/usb/serial/mos7840.c index c6cca859af45..2366e7b63ece 100644 --- a/drivers/usb/serial/mos7840.c +++ b/drivers/usb/serial/mos7840.c | |||
@@ -176,9 +176,12 @@ struct moschip_port { | |||
176 | int port_num; /*Actual port number in the device(1,2,etc) */ | 176 | int port_num; /*Actual port number in the device(1,2,etc) */ |
177 | struct urb *write_urb; /* write URB for this port */ | 177 | struct urb *write_urb; /* write URB for this port */ |
178 | struct urb *read_urb; /* read URB for this port */ | 178 | struct urb *read_urb; /* read URB for this port */ |
179 | struct urb *int_urb; | ||
179 | __u8 shadowLCR; /* last LCR value received */ | 180 | __u8 shadowLCR; /* last LCR value received */ |
180 | __u8 shadowMCR; /* last MCR value received */ | 181 | __u8 shadowMCR; /* last MCR value received */ |
181 | char open; | 182 | char open; |
183 | char open_ports; | ||
184 | char zombie; | ||
182 | wait_queue_head_t wait_chase; /* for handling sleeping while waiting for chase to finish */ | 185 | wait_queue_head_t wait_chase; /* for handling sleeping while waiting for chase to finish */ |
183 | wait_queue_head_t delta_msr_wait; /* for handling sleeping while waiting for msr change to happen */ | 186 | wait_queue_head_t delta_msr_wait; /* for handling sleeping while waiting for msr change to happen */ |
184 | int delta_msr_cond; | 187 | int delta_msr_cond; |
@@ -191,17 +194,17 @@ struct moschip_port { | |||
191 | __u8 DcrRegOffset; | 194 | __u8 DcrRegOffset; |
192 | //for processing control URBS in interrupt context | 195 | //for processing control URBS in interrupt context |
193 | struct urb *control_urb; | 196 | struct urb *control_urb; |
197 | struct usb_ctrlrequest *dr; | ||
194 | char *ctrl_buf; | 198 | char *ctrl_buf; |
195 | int MsrLsr; | 199 | int MsrLsr; |
196 | 200 | ||
201 | spinlock_t pool_lock; | ||
197 | struct urb *write_urb_pool[NUM_URBS]; | 202 | struct urb *write_urb_pool[NUM_URBS]; |
203 | char busy[NUM_URBS]; | ||
198 | }; | 204 | }; |
199 | 205 | ||
200 | 206 | ||
201 | static int debug; | 207 | static int debug; |
202 | static int mos7840_num_ports; //this says the number of ports in the device | ||
203 | static int mos7840_num_open_ports; | ||
204 | |||
205 | 208 | ||
206 | /* | 209 | /* |
207 | * mos7840_set_reg_sync | 210 | * mos7840_set_reg_sync |
@@ -254,7 +257,7 @@ static int mos7840_set_uart_reg(struct usb_serial_port *port, __u16 reg, | |||
254 | struct usb_device *dev = port->serial->dev; | 257 | struct usb_device *dev = port->serial->dev; |
255 | val = val & 0x00ff; | 258 | val = val & 0x00ff; |
256 | // For the UART control registers, the application number need to be Or'ed | 259 | // For the UART control registers, the application number need to be Or'ed |
257 | if (mos7840_num_ports == 4) { | 260 | if (port->serial->num_ports == 4) { |
258 | val |= | 261 | val |= |
259 | (((__u16) port->number - (__u16) (port->serial->minor)) + | 262 | (((__u16) port->number - (__u16) (port->serial->minor)) + |
260 | 1) << 8; | 263 | 1) << 8; |
@@ -294,7 +297,7 @@ static int mos7840_get_uart_reg(struct usb_serial_port *port, __u16 reg, | |||
294 | 297 | ||
295 | //dbg("application number is %4x \n",(((__u16)port->number - (__u16)(port->serial->minor))+1)<<8); | 298 | //dbg("application number is %4x \n",(((__u16)port->number - (__u16)(port->serial->minor))+1)<<8); |
296 | /*Wval is same as application number */ | 299 | /*Wval is same as application number */ |
297 | if (mos7840_num_ports == 4) { | 300 | if (port->serial->num_ports == 4) { |
298 | Wval = | 301 | Wval = |
299 | (((__u16) port->number - (__u16) (port->serial->minor)) + | 302 | (((__u16) port->number - (__u16) (port->serial->minor)) + |
300 | 1) << 8; | 303 | 1) << 8; |
@@ -352,7 +355,7 @@ static inline struct moschip_port *mos7840_get_port_private(struct | |||
352 | return (struct moschip_port *)usb_get_serial_port_data(port); | 355 | return (struct moschip_port *)usb_get_serial_port_data(port); |
353 | } | 356 | } |
354 | 357 | ||
355 | static int mos7840_handle_new_msr(struct moschip_port *port, __u8 new_msr) | 358 | static void mos7840_handle_new_msr(struct moschip_port *port, __u8 new_msr) |
356 | { | 359 | { |
357 | struct moschip_port *mos7840_port; | 360 | struct moschip_port *mos7840_port; |
358 | struct async_icount *icount; | 361 | struct async_icount *icount; |
@@ -366,22 +369,24 @@ static int mos7840_handle_new_msr(struct moschip_port *port, __u8 new_msr) | |||
366 | /* update input line counters */ | 369 | /* update input line counters */ |
367 | if (new_msr & MOS_MSR_DELTA_CTS) { | 370 | if (new_msr & MOS_MSR_DELTA_CTS) { |
368 | icount->cts++; | 371 | icount->cts++; |
372 | smp_wmb(); | ||
369 | } | 373 | } |
370 | if (new_msr & MOS_MSR_DELTA_DSR) { | 374 | if (new_msr & MOS_MSR_DELTA_DSR) { |
371 | icount->dsr++; | 375 | icount->dsr++; |
376 | smp_wmb(); | ||
372 | } | 377 | } |
373 | if (new_msr & MOS_MSR_DELTA_CD) { | 378 | if (new_msr & MOS_MSR_DELTA_CD) { |
374 | icount->dcd++; | 379 | icount->dcd++; |
380 | smp_wmb(); | ||
375 | } | 381 | } |
376 | if (new_msr & MOS_MSR_DELTA_RI) { | 382 | if (new_msr & MOS_MSR_DELTA_RI) { |
377 | icount->rng++; | 383 | icount->rng++; |
384 | smp_wmb(); | ||
378 | } | 385 | } |
379 | } | 386 | } |
380 | |||
381 | return 0; | ||
382 | } | 387 | } |
383 | 388 | ||
384 | static int mos7840_handle_new_lsr(struct moschip_port *port, __u8 new_lsr) | 389 | static void mos7840_handle_new_lsr(struct moschip_port *port, __u8 new_lsr) |
385 | { | 390 | { |
386 | struct async_icount *icount; | 391 | struct async_icount *icount; |
387 | 392 | ||
@@ -400,18 +405,20 @@ static int mos7840_handle_new_lsr(struct moschip_port *port, __u8 new_lsr) | |||
400 | icount = &port->icount; | 405 | icount = &port->icount; |
401 | if (new_lsr & SERIAL_LSR_BI) { | 406 | if (new_lsr & SERIAL_LSR_BI) { |
402 | icount->brk++; | 407 | icount->brk++; |
408 | smp_wmb(); | ||
403 | } | 409 | } |
404 | if (new_lsr & SERIAL_LSR_OE) { | 410 | if (new_lsr & SERIAL_LSR_OE) { |
405 | icount->overrun++; | 411 | icount->overrun++; |
412 | smp_wmb(); | ||
406 | } | 413 | } |
407 | if (new_lsr & SERIAL_LSR_PE) { | 414 | if (new_lsr & SERIAL_LSR_PE) { |
408 | icount->parity++; | 415 | icount->parity++; |
416 | smp_wmb(); | ||
409 | } | 417 | } |
410 | if (new_lsr & SERIAL_LSR_FE) { | 418 | if (new_lsr & SERIAL_LSR_FE) { |
411 | icount->frame++; | 419 | icount->frame++; |
420 | smp_wmb(); | ||
412 | } | 421 | } |
413 | |||
414 | return 0; | ||
415 | } | 422 | } |
416 | 423 | ||
417 | /************************************************************************/ | 424 | /************************************************************************/ |
@@ -426,12 +433,15 @@ static void mos7840_control_callback(struct urb *urb) | |||
426 | unsigned char *data; | 433 | unsigned char *data; |
427 | struct moschip_port *mos7840_port; | 434 | struct moschip_port *mos7840_port; |
428 | __u8 regval = 0x0; | 435 | __u8 regval = 0x0; |
436 | int result = 0; | ||
429 | 437 | ||
430 | if (!urb) { | 438 | if (!urb) { |
431 | dbg("%s", "Invalid Pointer !!!!:\n"); | 439 | dbg("%s", "Invalid Pointer !!!!:\n"); |
432 | return; | 440 | return; |
433 | } | 441 | } |
434 | 442 | ||
443 | mos7840_port = (struct moschip_port *)urb->context; | ||
444 | |||
435 | switch (urb->status) { | 445 | switch (urb->status) { |
436 | case 0: | 446 | case 0: |
437 | /* success */ | 447 | /* success */ |
@@ -449,8 +459,6 @@ static void mos7840_control_callback(struct urb *urb) | |||
449 | goto exit; | 459 | goto exit; |
450 | } | 460 | } |
451 | 461 | ||
452 | mos7840_port = (struct moschip_port *)urb->context; | ||
453 | |||
454 | dbg("%s urb buffer size is %d\n", __FUNCTION__, urb->actual_length); | 462 | dbg("%s urb buffer size is %d\n", __FUNCTION__, urb->actual_length); |
455 | dbg("%s mos7840_port->MsrLsr is %d port %d\n", __FUNCTION__, | 463 | dbg("%s mos7840_port->MsrLsr is %d port %d\n", __FUNCTION__, |
456 | mos7840_port->MsrLsr, mos7840_port->port_num); | 464 | mos7840_port->MsrLsr, mos7840_port->port_num); |
@@ -462,21 +470,26 @@ static void mos7840_control_callback(struct urb *urb) | |||
462 | else if (mos7840_port->MsrLsr == 1) | 470 | else if (mos7840_port->MsrLsr == 1) |
463 | mos7840_handle_new_lsr(mos7840_port, regval); | 471 | mos7840_handle_new_lsr(mos7840_port, regval); |
464 | 472 | ||
465 | exit: | 473 | exit: |
466 | return; | 474 | spin_lock(&mos7840_port->pool_lock); |
475 | if (!mos7840_port->zombie) | ||
476 | result = usb_submit_urb(mos7840_port->int_urb, GFP_ATOMIC); | ||
477 | spin_unlock(&mos7840_port->pool_lock); | ||
478 | if (result) { | ||
479 | dev_err(&urb->dev->dev, | ||
480 | "%s - Error %d submitting interrupt urb\n", | ||
481 | __FUNCTION__, result); | ||
482 | } | ||
467 | } | 483 | } |
468 | 484 | ||
469 | static int mos7840_get_reg(struct moschip_port *mcs, __u16 Wval, __u16 reg, | 485 | static int mos7840_get_reg(struct moschip_port *mcs, __u16 Wval, __u16 reg, |
470 | __u16 * val) | 486 | __u16 * val) |
471 | { | 487 | { |
472 | struct usb_device *dev = mcs->port->serial->dev; | 488 | struct usb_device *dev = mcs->port->serial->dev; |
473 | struct usb_ctrlrequest *dr = NULL; | 489 | struct usb_ctrlrequest *dr = mcs->dr; |
474 | unsigned char *buffer = NULL; | 490 | unsigned char *buffer = mcs->ctrl_buf; |
475 | int ret = 0; | 491 | int ret; |
476 | buffer = (__u8 *) mcs->ctrl_buf; | ||
477 | 492 | ||
478 | // dr=(struct usb_ctrlrequest *)(buffer); | ||
479 | dr = (void *)(buffer + 2); | ||
480 | dr->bRequestType = MCS_RD_RTYPE; | 493 | dr->bRequestType = MCS_RD_RTYPE; |
481 | dr->bRequest = MCS_RDREQ; | 494 | dr->bRequest = MCS_RDREQ; |
482 | dr->wValue = cpu_to_le16(Wval); //0; | 495 | dr->wValue = cpu_to_le16(Wval); //0; |
@@ -506,8 +519,8 @@ static void mos7840_interrupt_callback(struct urb *urb) | |||
506 | __u16 Data; | 519 | __u16 Data; |
507 | unsigned char *data; | 520 | unsigned char *data; |
508 | __u8 sp[5], st; | 521 | __u8 sp[5], st; |
509 | int i; | 522 | int i, rv = 0; |
510 | __u16 wval; | 523 | __u16 wval, wreg = 0; |
511 | 524 | ||
512 | dbg("%s", " : Entering\n"); | 525 | dbg("%s", " : Entering\n"); |
513 | if (!urb) { | 526 | if (!urb) { |
@@ -569,31 +582,34 @@ static void mos7840_interrupt_callback(struct urb *urb) | |||
569 | dbg("Serial Port %d: Receiver status error or ", i); | 582 | dbg("Serial Port %d: Receiver status error or ", i); |
570 | dbg("address bit detected in 9-bit mode\n"); | 583 | dbg("address bit detected in 9-bit mode\n"); |
571 | mos7840_port->MsrLsr = 1; | 584 | mos7840_port->MsrLsr = 1; |
572 | mos7840_get_reg(mos7840_port, wval, | 585 | wreg = LINE_STATUS_REGISTER; |
573 | LINE_STATUS_REGISTER, | ||
574 | &Data); | ||
575 | break; | 586 | break; |
576 | case SERIAL_IIR_MS: | 587 | case SERIAL_IIR_MS: |
577 | dbg("Serial Port %d: Modem status change\n", i); | 588 | dbg("Serial Port %d: Modem status change\n", i); |
578 | mos7840_port->MsrLsr = 0; | 589 | mos7840_port->MsrLsr = 0; |
579 | mos7840_get_reg(mos7840_port, wval, | 590 | wreg = MODEM_STATUS_REGISTER; |
580 | MODEM_STATUS_REGISTER, | ||
581 | &Data); | ||
582 | break; | 591 | break; |
583 | } | 592 | } |
593 | spin_lock(&mos7840_port->pool_lock); | ||
594 | if (!mos7840_port->zombie) { | ||
595 | rv = mos7840_get_reg(mos7840_port, wval, wreg, &Data); | ||
596 | } else { | ||
597 | spin_unlock(&mos7840_port->pool_lock); | ||
598 | return; | ||
599 | } | ||
600 | spin_unlock(&mos7840_port->pool_lock); | ||
584 | } | 601 | } |
585 | } | 602 | } |
586 | } | 603 | } |
587 | exit: | 604 | if (!(rv < 0)) /* the completion handler for the control urb will resubmit */ |
605 | return; | ||
606 | exit: | ||
588 | result = usb_submit_urb(urb, GFP_ATOMIC); | 607 | result = usb_submit_urb(urb, GFP_ATOMIC); |
589 | if (result) { | 608 | if (result) { |
590 | dev_err(&urb->dev->dev, | 609 | dev_err(&urb->dev->dev, |
591 | "%s - Error %d submitting interrupt urb\n", | 610 | "%s - Error %d submitting interrupt urb\n", |
592 | __FUNCTION__, result); | 611 | __FUNCTION__, result); |
593 | } | 612 | } |
594 | |||
595 | return; | ||
596 | |||
597 | } | 613 | } |
598 | 614 | ||
599 | static int mos7840_port_paranoia_check(struct usb_serial_port *port, | 615 | static int mos7840_port_paranoia_check(struct usb_serial_port *port, |
@@ -634,7 +650,8 @@ static struct usb_serial *mos7840_get_usb_serial(struct usb_serial_port *port, | |||
634 | if (!port || | 650 | if (!port || |
635 | mos7840_port_paranoia_check(port, function) || | 651 | mos7840_port_paranoia_check(port, function) || |
636 | mos7840_serial_paranoia_check(port->serial, function)) { | 652 | mos7840_serial_paranoia_check(port->serial, function)) { |
637 | /* then say that we don't have a valid usb_serial thing, which will * end up genrating -ENODEV return values */ | 653 | /* then say that we don't have a valid usb_serial thing, which will |
654 | * end up genrating -ENODEV return values */ | ||
638 | return NULL; | 655 | return NULL; |
639 | } | 656 | } |
640 | 657 | ||
@@ -699,6 +716,7 @@ static void mos7840_bulk_in_callback(struct urb *urb) | |||
699 | tty_flip_buffer_push(tty); | 716 | tty_flip_buffer_push(tty); |
700 | } | 717 | } |
701 | mos7840_port->icount.rx += urb->actual_length; | 718 | mos7840_port->icount.rx += urb->actual_length; |
719 | smp_wmb(); | ||
702 | dbg("mos7840_port->icount.rx is %d:\n", | 720 | dbg("mos7840_port->icount.rx is %d:\n", |
703 | mos7840_port->icount.rx); | 721 | mos7840_port->icount.rx); |
704 | } | 722 | } |
@@ -708,15 +726,14 @@ static void mos7840_bulk_in_callback(struct urb *urb) | |||
708 | return; | 726 | return; |
709 | } | 727 | } |
710 | 728 | ||
711 | if (mos7840_port->read_urb->status != -EINPROGRESS) { | ||
712 | mos7840_port->read_urb->dev = serial->dev; | ||
713 | 729 | ||
714 | status = usb_submit_urb(mos7840_port->read_urb, GFP_ATOMIC); | 730 | mos7840_port->read_urb->dev = serial->dev; |
715 | 731 | ||
716 | if (status) { | 732 | status = usb_submit_urb(mos7840_port->read_urb, GFP_ATOMIC); |
717 | dbg(" usb_submit_urb(read bulk) failed, status = %d", | 733 | |
718 | status); | 734 | if (status) { |
719 | } | 735 | dbg(" usb_submit_urb(read bulk) failed, status = %d", |
736 | status); | ||
720 | } | 737 | } |
721 | } | 738 | } |
722 | 739 | ||
@@ -730,17 +747,28 @@ static void mos7840_bulk_out_data_callback(struct urb *urb) | |||
730 | { | 747 | { |
731 | struct moschip_port *mos7840_port; | 748 | struct moschip_port *mos7840_port; |
732 | struct tty_struct *tty; | 749 | struct tty_struct *tty; |
750 | int i; | ||
751 | |||
733 | if (!urb) { | 752 | if (!urb) { |
734 | dbg("%s", "Invalid Pointer !!!!:\n"); | 753 | dbg("%s", "Invalid Pointer !!!!:\n"); |
735 | return; | 754 | return; |
736 | } | 755 | } |
737 | 756 | ||
757 | mos7840_port = (struct moschip_port *)urb->context; | ||
758 | spin_lock(&mos7840_port->pool_lock); | ||
759 | for (i = 0; i < NUM_URBS; i++) { | ||
760 | if (urb == mos7840_port->write_urb_pool[i]) { | ||
761 | mos7840_port->busy[i] = 0; | ||
762 | break; | ||
763 | } | ||
764 | } | ||
765 | spin_unlock(&mos7840_port->pool_lock); | ||
766 | |||
738 | if (urb->status) { | 767 | if (urb->status) { |
739 | dbg("nonzero write bulk status received:%d\n", urb->status); | 768 | dbg("nonzero write bulk status received:%d\n", urb->status); |
740 | return; | 769 | return; |
741 | } | 770 | } |
742 | 771 | ||
743 | mos7840_port = (struct moschip_port *)urb->context; | ||
744 | if (!mos7840_port) { | 772 | if (!mos7840_port) { |
745 | dbg("%s", "NULL mos7840_port pointer \n"); | 773 | dbg("%s", "NULL mos7840_port pointer \n"); |
746 | return; | 774 | return; |
@@ -792,13 +820,13 @@ static int mos7840_open(struct usb_serial_port *port, struct file *filp) | |||
792 | __u16 Data; | 820 | __u16 Data; |
793 | int status; | 821 | int status; |
794 | struct moschip_port *mos7840_port; | 822 | struct moschip_port *mos7840_port; |
823 | struct moschip_port *port0; | ||
795 | 824 | ||
796 | if (mos7840_port_paranoia_check(port, __FUNCTION__)) { | 825 | if (mos7840_port_paranoia_check(port, __FUNCTION__)) { |
797 | dbg("%s", "Port Paranoia failed \n"); | 826 | dbg("%s", "Port Paranoia failed \n"); |
798 | return -ENODEV; | 827 | return -ENODEV; |
799 | } | 828 | } |
800 | 829 | ||
801 | mos7840_num_open_ports++; | ||
802 | serial = port->serial; | 830 | serial = port->serial; |
803 | 831 | ||
804 | if (mos7840_serial_paranoia_check(serial, __FUNCTION__)) { | 832 | if (mos7840_serial_paranoia_check(serial, __FUNCTION__)) { |
@@ -807,16 +835,18 @@ static int mos7840_open(struct usb_serial_port *port, struct file *filp) | |||
807 | } | 835 | } |
808 | 836 | ||
809 | mos7840_port = mos7840_get_port_private(port); | 837 | mos7840_port = mos7840_get_port_private(port); |
838 | port0 = mos7840_get_port_private(serial->port[0]); | ||
810 | 839 | ||
811 | if (mos7840_port == NULL) | 840 | if (mos7840_port == NULL || port0 == NULL) |
812 | return -ENODEV; | 841 | return -ENODEV; |
813 | 842 | ||
814 | usb_clear_halt(serial->dev, port->write_urb->pipe); | 843 | usb_clear_halt(serial->dev, port->write_urb->pipe); |
815 | usb_clear_halt(serial->dev, port->read_urb->pipe); | 844 | usb_clear_halt(serial->dev, port->read_urb->pipe); |
845 | port0->open_ports++; | ||
816 | 846 | ||
817 | /* Initialising the write urb pool */ | 847 | /* Initialising the write urb pool */ |
818 | for (j = 0; j < NUM_URBS; ++j) { | 848 | for (j = 0; j < NUM_URBS; ++j) { |
819 | urb = usb_alloc_urb(0, GFP_ATOMIC); | 849 | urb = usb_alloc_urb(0, GFP_KERNEL); |
820 | mos7840_port->write_urb_pool[j] = urb; | 850 | mos7840_port->write_urb_pool[j] = urb; |
821 | 851 | ||
822 | if (urb == NULL) { | 852 | if (urb == NULL) { |
@@ -824,10 +854,10 @@ static int mos7840_open(struct usb_serial_port *port, struct file *filp) | |||
824 | continue; | 854 | continue; |
825 | } | 855 | } |
826 | 856 | ||
827 | urb->transfer_buffer = NULL; | 857 | urb->transfer_buffer = kmalloc(URB_TRANSFER_BUFFER_SIZE, GFP_KERNEL); |
828 | urb->transfer_buffer = | ||
829 | kmalloc(URB_TRANSFER_BUFFER_SIZE, GFP_KERNEL); | ||
830 | if (!urb->transfer_buffer) { | 858 | if (!urb->transfer_buffer) { |
859 | usb_free_urb(urb); | ||
860 | mos7840_port->write_urb_pool[j] = NULL; | ||
831 | err("%s-out of memory for urb buffers.", __FUNCTION__); | 861 | err("%s-out of memory for urb buffers.", __FUNCTION__); |
832 | continue; | 862 | continue; |
833 | } | 863 | } |
@@ -879,9 +909,7 @@ static int mos7840_open(struct usb_serial_port *port, struct file *filp) | |||
879 | } | 909 | } |
880 | Data |= 0x08; //Driver done bit | 910 | Data |= 0x08; //Driver done bit |
881 | Data |= 0x20; //rx_disable | 911 | Data |= 0x20; //rx_disable |
882 | status = 0; | 912 | status = mos7840_set_reg_sync(port, mos7840_port->ControlRegOffset, Data); |
883 | status = | ||
884 | mos7840_set_reg_sync(port, mos7840_port->ControlRegOffset, Data); | ||
885 | if (status < 0) { | 913 | if (status < 0) { |
886 | dbg("writing Controlreg failed\n"); | 914 | dbg("writing Controlreg failed\n"); |
887 | return -1; | 915 | return -1; |
@@ -893,7 +921,6 @@ static int mos7840_open(struct usb_serial_port *port, struct file *filp) | |||
893 | //////////////////////////////////// | 921 | //////////////////////////////////// |
894 | 922 | ||
895 | Data = 0x00; | 923 | Data = 0x00; |
896 | status = 0; | ||
897 | status = mos7840_set_uart_reg(port, INTERRUPT_ENABLE_REGISTER, Data); | 924 | status = mos7840_set_uart_reg(port, INTERRUPT_ENABLE_REGISTER, Data); |
898 | if (status < 0) { | 925 | if (status < 0) { |
899 | dbg("disableing interrupts failed\n"); | 926 | dbg("disableing interrupts failed\n"); |
@@ -901,7 +928,6 @@ static int mos7840_open(struct usb_serial_port *port, struct file *filp) | |||
901 | } | 928 | } |
902 | // Set FIFO_CONTROL_REGISTER to the default value | 929 | // Set FIFO_CONTROL_REGISTER to the default value |
903 | Data = 0x00; | 930 | Data = 0x00; |
904 | status = 0; | ||
905 | status = mos7840_set_uart_reg(port, FIFO_CONTROL_REGISTER, Data); | 931 | status = mos7840_set_uart_reg(port, FIFO_CONTROL_REGISTER, Data); |
906 | if (status < 0) { | 932 | if (status < 0) { |
907 | dbg("Writing FIFO_CONTROL_REGISTER failed\n"); | 933 | dbg("Writing FIFO_CONTROL_REGISTER failed\n"); |
@@ -909,7 +935,6 @@ static int mos7840_open(struct usb_serial_port *port, struct file *filp) | |||
909 | } | 935 | } |
910 | 936 | ||
911 | Data = 0xcf; | 937 | Data = 0xcf; |
912 | status = 0; | ||
913 | status = mos7840_set_uart_reg(port, FIFO_CONTROL_REGISTER, Data); | 938 | status = mos7840_set_uart_reg(port, FIFO_CONTROL_REGISTER, Data); |
914 | if (status < 0) { | 939 | if (status < 0) { |
915 | dbg("Writing FIFO_CONTROL_REGISTER failed\n"); | 940 | dbg("Writing FIFO_CONTROL_REGISTER failed\n"); |
@@ -917,22 +942,18 @@ static int mos7840_open(struct usb_serial_port *port, struct file *filp) | |||
917 | } | 942 | } |
918 | 943 | ||
919 | Data = 0x03; | 944 | Data = 0x03; |
920 | status = 0; | ||
921 | status = mos7840_set_uart_reg(port, LINE_CONTROL_REGISTER, Data); | 945 | status = mos7840_set_uart_reg(port, LINE_CONTROL_REGISTER, Data); |
922 | mos7840_port->shadowLCR = Data; | 946 | mos7840_port->shadowLCR = Data; |
923 | 947 | ||
924 | Data = 0x0b; | 948 | Data = 0x0b; |
925 | status = 0; | ||
926 | status = mos7840_set_uart_reg(port, MODEM_CONTROL_REGISTER, Data); | 949 | status = mos7840_set_uart_reg(port, MODEM_CONTROL_REGISTER, Data); |
927 | mos7840_port->shadowMCR = Data; | 950 | mos7840_port->shadowMCR = Data; |
928 | 951 | ||
929 | Data = 0x00; | 952 | Data = 0x00; |
930 | status = 0; | ||
931 | status = mos7840_get_uart_reg(port, LINE_CONTROL_REGISTER, &Data); | 953 | status = mos7840_get_uart_reg(port, LINE_CONTROL_REGISTER, &Data); |
932 | mos7840_port->shadowLCR = Data; | 954 | mos7840_port->shadowLCR = Data; |
933 | 955 | ||
934 | Data |= SERIAL_LCR_DLAB; //data latch enable in LCR 0x80 | 956 | Data |= SERIAL_LCR_DLAB; //data latch enable in LCR 0x80 |
935 | status = 0; | ||
936 | status = mos7840_set_uart_reg(port, LINE_CONTROL_REGISTER, Data); | 957 | status = mos7840_set_uart_reg(port, LINE_CONTROL_REGISTER, Data); |
937 | 958 | ||
938 | Data = 0x0c; | 959 | Data = 0x0c; |
@@ -999,7 +1020,7 @@ static int mos7840_open(struct usb_serial_port *port, struct file *filp) | |||
999 | /* Check to see if we've set up our endpoint info yet * | 1020 | /* Check to see if we've set up our endpoint info yet * |
1000 | * (can't set it up in mos7840_startup as the structures * | 1021 | * (can't set it up in mos7840_startup as the structures * |
1001 | * were not set up at that time.) */ | 1022 | * were not set up at that time.) */ |
1002 | if (mos7840_num_open_ports == 1) { | 1023 | if (port0->open_ports == 1) { |
1003 | if (serial->port[0]->interrupt_in_buffer == NULL) { | 1024 | if (serial->port[0]->interrupt_in_buffer == NULL) { |
1004 | 1025 | ||
1005 | /* set up interrupt urb */ | 1026 | /* set up interrupt urb */ |
@@ -1097,6 +1118,7 @@ static int mos7840_chars_in_buffer(struct usb_serial_port *port) | |||
1097 | { | 1118 | { |
1098 | int i; | 1119 | int i; |
1099 | int chars = 0; | 1120 | int chars = 0; |
1121 | unsigned long flags; | ||
1100 | struct moschip_port *mos7840_port; | 1122 | struct moschip_port *mos7840_port; |
1101 | 1123 | ||
1102 | dbg("%s \n", " mos7840_chars_in_buffer:entering ..........."); | 1124 | dbg("%s \n", " mos7840_chars_in_buffer:entering ..........."); |
@@ -1112,13 +1134,15 @@ static int mos7840_chars_in_buffer(struct usb_serial_port *port) | |||
1112 | return -1; | 1134 | return -1; |
1113 | } | 1135 | } |
1114 | 1136 | ||
1137 | spin_lock_irqsave(&mos7840_port->pool_lock,flags); | ||
1115 | for (i = 0; i < NUM_URBS; ++i) { | 1138 | for (i = 0; i < NUM_URBS; ++i) { |
1116 | if (mos7840_port->write_urb_pool[i]->status == -EINPROGRESS) { | 1139 | if (mos7840_port->busy[i]) { |
1117 | chars += URB_TRANSFER_BUFFER_SIZE; | 1140 | chars += URB_TRANSFER_BUFFER_SIZE; |
1118 | } | 1141 | } |
1119 | } | 1142 | } |
1143 | spin_unlock_irqrestore(&mos7840_port->pool_lock,flags); | ||
1120 | dbg("%s - returns %d", __FUNCTION__, chars); | 1144 | dbg("%s - returns %d", __FUNCTION__, chars); |
1121 | return (chars); | 1145 | return chars; |
1122 | 1146 | ||
1123 | } | 1147 | } |
1124 | 1148 | ||
@@ -1172,6 +1196,7 @@ static void mos7840_close(struct usb_serial_port *port, struct file *filp) | |||
1172 | { | 1196 | { |
1173 | struct usb_serial *serial; | 1197 | struct usb_serial *serial; |
1174 | struct moschip_port *mos7840_port; | 1198 | struct moschip_port *mos7840_port; |
1199 | struct moschip_port *port0; | ||
1175 | int j; | 1200 | int j; |
1176 | __u16 Data; | 1201 | __u16 Data; |
1177 | 1202 | ||
@@ -1189,10 +1214,10 @@ static void mos7840_close(struct usb_serial_port *port, struct file *filp) | |||
1189 | } | 1214 | } |
1190 | 1215 | ||
1191 | mos7840_port = mos7840_get_port_private(port); | 1216 | mos7840_port = mos7840_get_port_private(port); |
1217 | port0 = mos7840_get_port_private(serial->port[0]); | ||
1192 | 1218 | ||
1193 | if (mos7840_port == NULL) { | 1219 | if (mos7840_port == NULL || port0 == NULL) |
1194 | return; | 1220 | return; |
1195 | } | ||
1196 | 1221 | ||
1197 | for (j = 0; j < NUM_URBS; ++j) | 1222 | for (j = 0; j < NUM_URBS; ++j) |
1198 | usb_kill_urb(mos7840_port->write_urb_pool[j]); | 1223 | usb_kill_urb(mos7840_port->write_urb_pool[j]); |
@@ -1234,12 +1259,13 @@ static void mos7840_close(struct usb_serial_port *port, struct file *filp) | |||
1234 | } | 1259 | } |
1235 | // if(mos7840_port->ctrl_buf != NULL) | 1260 | // if(mos7840_port->ctrl_buf != NULL) |
1236 | // kfree(mos7840_port->ctrl_buf); | 1261 | // kfree(mos7840_port->ctrl_buf); |
1237 | mos7840_num_open_ports--; | 1262 | port0->open_ports--; |
1238 | dbg("mos7840_num_open_ports in close%d:in port%d\n", | 1263 | dbg("mos7840_num_open_ports in close%d:in port%d\n", |
1239 | mos7840_num_open_ports, port->number); | 1264 | port0->open_ports, port->number); |
1240 | if (mos7840_num_open_ports == 0) { | 1265 | if (port0->open_ports == 0) { |
1241 | if (serial->port[0]->interrupt_in_urb) { | 1266 | if (serial->port[0]->interrupt_in_urb) { |
1242 | dbg("%s", "Shutdown interrupt_in_urb\n"); | 1267 | dbg("%s", "Shutdown interrupt_in_urb\n"); |
1268 | usb_kill_urb(serial->port[0]->interrupt_in_urb); | ||
1243 | } | 1269 | } |
1244 | } | 1270 | } |
1245 | 1271 | ||
@@ -1368,6 +1394,7 @@ static int mos7840_write_room(struct usb_serial_port *port) | |||
1368 | { | 1394 | { |
1369 | int i; | 1395 | int i; |
1370 | int room = 0; | 1396 | int room = 0; |
1397 | unsigned long flags; | ||
1371 | struct moschip_port *mos7840_port; | 1398 | struct moschip_port *mos7840_port; |
1372 | 1399 | ||
1373 | dbg("%s \n", " mos7840_write_room:entering ..........."); | 1400 | dbg("%s \n", " mos7840_write_room:entering ..........."); |
@@ -1384,14 +1411,17 @@ static int mos7840_write_room(struct usb_serial_port *port) | |||
1384 | return -1; | 1411 | return -1; |
1385 | } | 1412 | } |
1386 | 1413 | ||
1414 | spin_lock_irqsave(&mos7840_port->pool_lock, flags); | ||
1387 | for (i = 0; i < NUM_URBS; ++i) { | 1415 | for (i = 0; i < NUM_URBS; ++i) { |
1388 | if (mos7840_port->write_urb_pool[i]->status != -EINPROGRESS) { | 1416 | if (!mos7840_port->busy[i]) { |
1389 | room += URB_TRANSFER_BUFFER_SIZE; | 1417 | room += URB_TRANSFER_BUFFER_SIZE; |
1390 | } | 1418 | } |
1391 | } | 1419 | } |
1420 | spin_unlock_irqrestore(&mos7840_port->pool_lock, flags); | ||
1392 | 1421 | ||
1422 | room = (room == 0) ? 0 : room - URB_TRANSFER_BUFFER_SIZE + 1; | ||
1393 | dbg("%s - returns %d", __FUNCTION__, room); | 1423 | dbg("%s - returns %d", __FUNCTION__, room); |
1394 | return (room); | 1424 | return room; |
1395 | 1425 | ||
1396 | } | 1426 | } |
1397 | 1427 | ||
@@ -1410,6 +1440,7 @@ static int mos7840_write(struct usb_serial_port *port, | |||
1410 | int i; | 1440 | int i; |
1411 | int bytes_sent = 0; | 1441 | int bytes_sent = 0; |
1412 | int transfer_size; | 1442 | int transfer_size; |
1443 | unsigned long flags; | ||
1413 | 1444 | ||
1414 | struct moschip_port *mos7840_port; | 1445 | struct moschip_port *mos7840_port; |
1415 | struct usb_serial *serial; | 1446 | struct usb_serial *serial; |
@@ -1476,13 +1507,16 @@ static int mos7840_write(struct usb_serial_port *port, | |||
1476 | /* try to find a free urb in the list */ | 1507 | /* try to find a free urb in the list */ |
1477 | urb = NULL; | 1508 | urb = NULL; |
1478 | 1509 | ||
1510 | spin_lock_irqsave(&mos7840_port->pool_lock, flags); | ||
1479 | for (i = 0; i < NUM_URBS; ++i) { | 1511 | for (i = 0; i < NUM_URBS; ++i) { |
1480 | if (mos7840_port->write_urb_pool[i]->status != -EINPROGRESS) { | 1512 | if (!mos7840_port->busy[i]) { |
1513 | mos7840_port->busy[i] = 1; | ||
1481 | urb = mos7840_port->write_urb_pool[i]; | 1514 | urb = mos7840_port->write_urb_pool[i]; |
1482 | dbg("\nURB:%d", i); | 1515 | dbg("\nURB:%d", i); |
1483 | break; | 1516 | break; |
1484 | } | 1517 | } |
1485 | } | 1518 | } |
1519 | spin_unlock_irqrestore(&mos7840_port->pool_lock, flags); | ||
1486 | 1520 | ||
1487 | if (urb == NULL) { | 1521 | if (urb == NULL) { |
1488 | dbg("%s - no more free urbs", __FUNCTION__); | 1522 | dbg("%s - no more free urbs", __FUNCTION__); |
@@ -1518,6 +1552,7 @@ static int mos7840_write(struct usb_serial_port *port, | |||
1518 | status = usb_submit_urb(urb, GFP_ATOMIC); | 1552 | status = usb_submit_urb(urb, GFP_ATOMIC); |
1519 | 1553 | ||
1520 | if (status) { | 1554 | if (status) { |
1555 | mos7840_port->busy[i] = 0; | ||
1521 | err("%s - usb_submit_urb(write bulk) failed with status = %d", | 1556 | err("%s - usb_submit_urb(write bulk) failed with status = %d", |
1522 | __FUNCTION__, status); | 1557 | __FUNCTION__, status); |
1523 | bytes_sent = status; | 1558 | bytes_sent = status; |
@@ -1525,6 +1560,7 @@ static int mos7840_write(struct usb_serial_port *port, | |||
1525 | } | 1560 | } |
1526 | bytes_sent = transfer_size; | 1561 | bytes_sent = transfer_size; |
1527 | mos7840_port->icount.tx += transfer_size; | 1562 | mos7840_port->icount.tx += transfer_size; |
1563 | smp_wmb(); | ||
1528 | dbg("mos7840_port->icount.tx is %d:\n", mos7840_port->icount.tx); | 1564 | dbg("mos7840_port->icount.tx is %d:\n", mos7840_port->icount.tx); |
1529 | exit: | 1565 | exit: |
1530 | 1566 | ||
@@ -2490,6 +2526,7 @@ static int mos7840_ioctl(struct usb_serial_port *port, struct file *file, | |||
2490 | if (signal_pending(current)) | 2526 | if (signal_pending(current)) |
2491 | return -ERESTARTSYS; | 2527 | return -ERESTARTSYS; |
2492 | cnow = mos7840_port->icount; | 2528 | cnow = mos7840_port->icount; |
2529 | smp_rmb(); | ||
2493 | if (cnow.rng == cprev.rng && cnow.dsr == cprev.dsr && | 2530 | if (cnow.rng == cprev.rng && cnow.dsr == cprev.dsr && |
2494 | cnow.dcd == cprev.dcd && cnow.cts == cprev.cts) | 2531 | cnow.dcd == cprev.dcd && cnow.cts == cprev.cts) |
2495 | return -EIO; /* no change => error */ | 2532 | return -EIO; /* no change => error */ |
@@ -2506,6 +2543,7 @@ static int mos7840_ioctl(struct usb_serial_port *port, struct file *file, | |||
2506 | 2543 | ||
2507 | case TIOCGICOUNT: | 2544 | case TIOCGICOUNT: |
2508 | cnow = mos7840_port->icount; | 2545 | cnow = mos7840_port->icount; |
2546 | smp_rmb(); | ||
2509 | icount.cts = cnow.cts; | 2547 | icount.cts = cnow.cts; |
2510 | icount.dsr = cnow.dsr; | 2548 | icount.dsr = cnow.dsr; |
2511 | icount.rng = cnow.rng; | 2549 | icount.rng = cnow.rng; |
@@ -2535,19 +2573,18 @@ static int mos7840_ioctl(struct usb_serial_port *port, struct file *file, | |||
2535 | 2573 | ||
2536 | static int mos7840_calc_num_ports(struct usb_serial *serial) | 2574 | static int mos7840_calc_num_ports(struct usb_serial *serial) |
2537 | { | 2575 | { |
2576 | int mos7840_num_ports = 0; | ||
2538 | 2577 | ||
2539 | dbg("numberofendpoints: %d \n", | 2578 | dbg("numberofendpoints: %d \n", |
2540 | (int)serial->interface->cur_altsetting->desc.bNumEndpoints); | 2579 | (int)serial->interface->cur_altsetting->desc.bNumEndpoints); |
2541 | dbg("numberofendpoints: %d \n", | 2580 | dbg("numberofendpoints: %d \n", |
2542 | (int)serial->interface->altsetting->desc.bNumEndpoints); | 2581 | (int)serial->interface->altsetting->desc.bNumEndpoints); |
2543 | if (serial->interface->cur_altsetting->desc.bNumEndpoints == 5) { | 2582 | if (serial->interface->cur_altsetting->desc.bNumEndpoints == 5) { |
2544 | mos7840_num_ports = 2; | 2583 | mos7840_num_ports = serial->num_ports = 2; |
2545 | serial->type->num_ports = 2; | ||
2546 | } else if (serial->interface->cur_altsetting->desc.bNumEndpoints == 9) { | 2584 | } else if (serial->interface->cur_altsetting->desc.bNumEndpoints == 9) { |
2547 | mos7840_num_ports = 4; | 2585 | serial->num_bulk_in = 4; |
2548 | serial->type->num_bulk_in = 4; | 2586 | serial->num_bulk_out = 4; |
2549 | serial->type->num_bulk_out = 4; | 2587 | mos7840_num_ports = serial->num_ports = 4; |
2550 | serial->type->num_ports = 4; | ||
2551 | } | 2588 | } |
2552 | 2589 | ||
2553 | return mos7840_num_ports; | 2590 | return mos7840_num_ports; |
@@ -2583,7 +2620,9 @@ static int mos7840_startup(struct usb_serial *serial) | |||
2583 | mos7840_port = kzalloc(sizeof(struct moschip_port), GFP_KERNEL); | 2620 | mos7840_port = kzalloc(sizeof(struct moschip_port), GFP_KERNEL); |
2584 | if (mos7840_port == NULL) { | 2621 | if (mos7840_port == NULL) { |
2585 | err("%s - Out of memory", __FUNCTION__); | 2622 | err("%s - Out of memory", __FUNCTION__); |
2586 | return -ENOMEM; | 2623 | status = -ENOMEM; |
2624 | i--; /* don't follow NULL pointer cleaning up */ | ||
2625 | goto error; | ||
2587 | } | 2626 | } |
2588 | 2627 | ||
2589 | /* Initialize all port interrupt end point to port 0 int endpoint * | 2628 | /* Initialize all port interrupt end point to port 0 int endpoint * |
@@ -2591,6 +2630,7 @@ static int mos7840_startup(struct usb_serial *serial) | |||
2591 | 2630 | ||
2592 | mos7840_port->port = serial->port[i]; | 2631 | mos7840_port->port = serial->port[i]; |
2593 | mos7840_set_port_private(serial->port[i], mos7840_port); | 2632 | mos7840_set_port_private(serial->port[i], mos7840_port); |
2633 | spin_lock_init(&mos7840_port->pool_lock); | ||
2594 | 2634 | ||
2595 | mos7840_port->port_num = ((serial->port[i]->number - | 2635 | mos7840_port->port_num = ((serial->port[i]->number - |
2596 | (serial->port[i]->serial->minor)) + | 2636 | (serial->port[i]->serial->minor)) + |
@@ -2601,22 +2641,22 @@ static int mos7840_startup(struct usb_serial *serial) | |||
2601 | mos7840_port->ControlRegOffset = 0x1; | 2641 | mos7840_port->ControlRegOffset = 0x1; |
2602 | mos7840_port->DcrRegOffset = 0x4; | 2642 | mos7840_port->DcrRegOffset = 0x4; |
2603 | } else if ((mos7840_port->port_num == 2) | 2643 | } else if ((mos7840_port->port_num == 2) |
2604 | && (mos7840_num_ports == 4)) { | 2644 | && (serial->num_ports == 4)) { |
2605 | mos7840_port->SpRegOffset = 0x8; | 2645 | mos7840_port->SpRegOffset = 0x8; |
2606 | mos7840_port->ControlRegOffset = 0x9; | 2646 | mos7840_port->ControlRegOffset = 0x9; |
2607 | mos7840_port->DcrRegOffset = 0x16; | 2647 | mos7840_port->DcrRegOffset = 0x16; |
2608 | } else if ((mos7840_port->port_num == 2) | 2648 | } else if ((mos7840_port->port_num == 2) |
2609 | && (mos7840_num_ports == 2)) { | 2649 | && (serial->num_ports == 2)) { |
2610 | mos7840_port->SpRegOffset = 0xa; | 2650 | mos7840_port->SpRegOffset = 0xa; |
2611 | mos7840_port->ControlRegOffset = 0xb; | 2651 | mos7840_port->ControlRegOffset = 0xb; |
2612 | mos7840_port->DcrRegOffset = 0x19; | 2652 | mos7840_port->DcrRegOffset = 0x19; |
2613 | } else if ((mos7840_port->port_num == 3) | 2653 | } else if ((mos7840_port->port_num == 3) |
2614 | && (mos7840_num_ports == 4)) { | 2654 | && (serial->num_ports == 4)) { |
2615 | mos7840_port->SpRegOffset = 0xa; | 2655 | mos7840_port->SpRegOffset = 0xa; |
2616 | mos7840_port->ControlRegOffset = 0xb; | 2656 | mos7840_port->ControlRegOffset = 0xb; |
2617 | mos7840_port->DcrRegOffset = 0x19; | 2657 | mos7840_port->DcrRegOffset = 0x19; |
2618 | } else if ((mos7840_port->port_num == 4) | 2658 | } else if ((mos7840_port->port_num == 4) |
2619 | && (mos7840_num_ports == 4)) { | 2659 | && (serial->num_ports == 4)) { |
2620 | mos7840_port->SpRegOffset = 0xc; | 2660 | mos7840_port->SpRegOffset = 0xc; |
2621 | mos7840_port->ControlRegOffset = 0xd; | 2661 | mos7840_port->ControlRegOffset = 0xd; |
2622 | mos7840_port->DcrRegOffset = 0x1c; | 2662 | mos7840_port->DcrRegOffset = 0x1c; |
@@ -2701,21 +2741,19 @@ static int mos7840_startup(struct usb_serial *serial) | |||
2701 | dbg("CLK_START_VALUE_REGISTER Writing success status%d\n", status); | 2741 | dbg("CLK_START_VALUE_REGISTER Writing success status%d\n", status); |
2702 | 2742 | ||
2703 | Data = 0x20; | 2743 | Data = 0x20; |
2704 | status = 0; | ||
2705 | status = | 2744 | status = |
2706 | mos7840_set_reg_sync(serial->port[i], CLK_MULTI_REGISTER, | 2745 | mos7840_set_reg_sync(serial->port[i], CLK_MULTI_REGISTER, |
2707 | Data); | 2746 | Data); |
2708 | if (status < 0) { | 2747 | if (status < 0) { |
2709 | dbg("Writing CLK_MULTI_REGISTER failed status-0x%x\n", | 2748 | dbg("Writing CLK_MULTI_REGISTER failed status-0x%x\n", |
2710 | status); | 2749 | status); |
2711 | break; | 2750 | goto error; |
2712 | } else | 2751 | } else |
2713 | dbg("CLK_MULTI_REGISTER Writing success status%d\n", | 2752 | dbg("CLK_MULTI_REGISTER Writing success status%d\n", |
2714 | status); | 2753 | status); |
2715 | 2754 | ||
2716 | //write value 0x0 to scratchpad register | 2755 | //write value 0x0 to scratchpad register |
2717 | Data = 0x00; | 2756 | Data = 0x00; |
2718 | status = 0; | ||
2719 | status = | 2757 | status = |
2720 | mos7840_set_uart_reg(serial->port[i], SCRATCH_PAD_REGISTER, | 2758 | mos7840_set_uart_reg(serial->port[i], SCRATCH_PAD_REGISTER, |
2721 | Data); | 2759 | Data); |
@@ -2729,7 +2767,7 @@ static int mos7840_startup(struct usb_serial *serial) | |||
2729 | 2767 | ||
2730 | //Zero Length flag register | 2768 | //Zero Length flag register |
2731 | if ((mos7840_port->port_num != 1) | 2769 | if ((mos7840_port->port_num != 1) |
2732 | && (mos7840_num_ports == 2)) { | 2770 | && (serial->num_ports == 2)) { |
2733 | 2771 | ||
2734 | Data = 0xff; | 2772 | Data = 0xff; |
2735 | status = 0; | 2773 | status = 0; |
@@ -2770,14 +2808,17 @@ static int mos7840_startup(struct usb_serial *serial) | |||
2770 | i + 1, status); | 2808 | i + 1, status); |
2771 | 2809 | ||
2772 | } | 2810 | } |
2773 | mos7840_port->control_urb = usb_alloc_urb(0, GFP_ATOMIC); | 2811 | mos7840_port->control_urb = usb_alloc_urb(0, GFP_KERNEL); |
2774 | mos7840_port->ctrl_buf = kmalloc(16, GFP_KERNEL); | 2812 | mos7840_port->ctrl_buf = kmalloc(16, GFP_KERNEL); |
2775 | 2813 | mos7840_port->dr = kmalloc(sizeof(struct usb_ctrlrequest), GFP_KERNEL); | |
2814 | if (!mos7840_port->control_urb || !mos7840_port->ctrl_buf || !mos7840_port->dr) { | ||
2815 | status = -ENOMEM; | ||
2816 | goto error; | ||
2817 | } | ||
2776 | } | 2818 | } |
2777 | 2819 | ||
2778 | //Zero Length flag enable | 2820 | //Zero Length flag enable |
2779 | Data = 0x0f; | 2821 | Data = 0x0f; |
2780 | status = 0; | ||
2781 | status = mos7840_set_reg_sync(serial->port[0], ZLP_REG5, Data); | 2822 | status = mos7840_set_reg_sync(serial->port[0], ZLP_REG5, Data); |
2782 | if (status < 0) { | 2823 | if (status < 0) { |
2783 | dbg("Writing ZLP_REG5 failed status-0x%x\n", status); | 2824 | dbg("Writing ZLP_REG5 failed status-0x%x\n", status); |
@@ -2789,6 +2830,17 @@ static int mos7840_startup(struct usb_serial *serial) | |||
2789 | usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0), | 2830 | usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0), |
2790 | (__u8) 0x03, 0x00, 0x01, 0x00, NULL, 0x00, 5 * HZ); | 2831 | (__u8) 0x03, 0x00, 0x01, 0x00, NULL, 0x00, 5 * HZ); |
2791 | return 0; | 2832 | return 0; |
2833 | error: | ||
2834 | for (/* nothing */; i >= 0; i--) { | ||
2835 | mos7840_port = mos7840_get_port_private(serial->port[i]); | ||
2836 | |||
2837 | kfree(mos7840_port->dr); | ||
2838 | kfree(mos7840_port->ctrl_buf); | ||
2839 | usb_free_urb(mos7840_port->control_urb); | ||
2840 | kfree(mos7840_port); | ||
2841 | serial->port[i] = NULL; | ||
2842 | } | ||
2843 | return status; | ||
2792 | } | 2844 | } |
2793 | 2845 | ||
2794 | /**************************************************************************** | 2846 | /**************************************************************************** |
@@ -2799,6 +2851,7 @@ static int mos7840_startup(struct usb_serial *serial) | |||
2799 | static void mos7840_shutdown(struct usb_serial *serial) | 2851 | static void mos7840_shutdown(struct usb_serial *serial) |
2800 | { | 2852 | { |
2801 | int i; | 2853 | int i; |
2854 | unsigned long flags; | ||
2802 | struct moschip_port *mos7840_port; | 2855 | struct moschip_port *mos7840_port; |
2803 | dbg("%s \n", " shutdown :entering.........."); | 2856 | dbg("%s \n", " shutdown :entering.........."); |
2804 | 2857 | ||
@@ -2814,8 +2867,12 @@ static void mos7840_shutdown(struct usb_serial *serial) | |||
2814 | 2867 | ||
2815 | for (i = 0; i < serial->num_ports; ++i) { | 2868 | for (i = 0; i < serial->num_ports; ++i) { |
2816 | mos7840_port = mos7840_get_port_private(serial->port[i]); | 2869 | mos7840_port = mos7840_get_port_private(serial->port[i]); |
2817 | kfree(mos7840_port->ctrl_buf); | 2870 | spin_lock_irqsave(&mos7840_port->pool_lock, flags); |
2871 | mos7840_port->zombie = 1; | ||
2872 | spin_unlock_irqrestore(&mos7840_port->pool_lock, flags); | ||
2818 | usb_kill_urb(mos7840_port->control_urb); | 2873 | usb_kill_urb(mos7840_port->control_urb); |
2874 | kfree(mos7840_port->ctrl_buf); | ||
2875 | kfree(mos7840_port->dr); | ||
2819 | kfree(mos7840_port); | 2876 | kfree(mos7840_port); |
2820 | mos7840_set_port_private(serial->port[i], NULL); | 2877 | mos7840_set_port_private(serial->port[i], NULL); |
2821 | } | 2878 | } |
diff --git a/drivers/usb/serial/omninet.c b/drivers/usb/serial/omninet.c index 0216ac12a27d..4adfab988e86 100644 --- a/drivers/usb/serial/omninet.c +++ b/drivers/usb/serial/omninet.c | |||
@@ -69,6 +69,7 @@ static void omninet_write_bulk_callback (struct urb *urb); | |||
69 | static int omninet_write (struct usb_serial_port *port, const unsigned char *buf, int count); | 69 | static int omninet_write (struct usb_serial_port *port, const unsigned char *buf, int count); |
70 | static int omninet_write_room (struct usb_serial_port *port); | 70 | static int omninet_write_room (struct usb_serial_port *port); |
71 | static void omninet_shutdown (struct usb_serial *serial); | 71 | static void omninet_shutdown (struct usb_serial *serial); |
72 | static int omninet_attach (struct usb_serial *serial); | ||
72 | 73 | ||
73 | static struct usb_device_id id_table [] = { | 74 | static struct usb_device_id id_table [] = { |
74 | { USB_DEVICE(ZYXEL_VENDOR_ID, ZYXEL_OMNINET_ID) }, | 75 | { USB_DEVICE(ZYXEL_VENDOR_ID, ZYXEL_OMNINET_ID) }, |
@@ -99,6 +100,7 @@ static struct usb_serial_driver zyxel_omninet_device = { | |||
99 | .num_bulk_in = 1, | 100 | .num_bulk_in = 1, |
100 | .num_bulk_out = 2, | 101 | .num_bulk_out = 2, |
101 | .num_ports = 1, | 102 | .num_ports = 1, |
103 | .attach = omninet_attach, | ||
102 | .open = omninet_open, | 104 | .open = omninet_open, |
103 | .close = omninet_close, | 105 | .close = omninet_close, |
104 | .write = omninet_write, | 106 | .write = omninet_write, |
@@ -145,22 +147,30 @@ struct omninet_data | |||
145 | __u8 od_outseq; // Sequence number for bulk_out URBs | 147 | __u8 od_outseq; // Sequence number for bulk_out URBs |
146 | }; | 148 | }; |
147 | 149 | ||
150 | static int omninet_attach (struct usb_serial *serial) | ||
151 | { | ||
152 | struct omninet_data *od; | ||
153 | struct usb_serial_port *port = serial->port[0]; | ||
154 | |||
155 | od = kmalloc( sizeof(struct omninet_data), GFP_KERNEL ); | ||
156 | if( !od ) { | ||
157 | err("%s- kmalloc(%Zd) failed.", __FUNCTION__, sizeof(struct omninet_data)); | ||
158 | return -ENOMEM; | ||
159 | } | ||
160 | usb_set_serial_port_data(port, od); | ||
161 | return 0; | ||
162 | } | ||
163 | |||
148 | static int omninet_open (struct usb_serial_port *port, struct file *filp) | 164 | static int omninet_open (struct usb_serial_port *port, struct file *filp) |
149 | { | 165 | { |
150 | struct usb_serial *serial = port->serial; | 166 | struct usb_serial *serial = port->serial; |
151 | struct usb_serial_port *wport; | 167 | struct usb_serial_port *wport; |
152 | struct omninet_data *od; | 168 | struct omninet_data *od = usb_get_serial_port_data(port); |
153 | int result = 0; | 169 | int result = 0; |
154 | 170 | ||
155 | dbg("%s - port %d", __FUNCTION__, port->number); | 171 | dbg("%s - port %d", __FUNCTION__, port->number); |
156 | 172 | ||
157 | od = kmalloc( sizeof(struct omninet_data), GFP_KERNEL ); | 173 | od = kmalloc( sizeof(struct omninet_data), GFP_KERNEL ); |
158 | if( !od ) { | ||
159 | err("%s- kmalloc(%Zd) failed.", __FUNCTION__, sizeof(struct omninet_data)); | ||
160 | return -ENOMEM; | ||
161 | } | ||
162 | |||
163 | usb_set_serial_port_data(port, od); | ||
164 | wport = serial->port[1]; | 174 | wport = serial->port[1]; |
165 | wport->tty = port->tty; | 175 | wport->tty = port->tty; |
166 | 176 | ||
@@ -170,24 +180,17 @@ static int omninet_open (struct usb_serial_port *port, struct file *filp) | |||
170 | port->read_urb->transfer_buffer, port->read_urb->transfer_buffer_length, | 180 | port->read_urb->transfer_buffer, port->read_urb->transfer_buffer_length, |
171 | omninet_read_bulk_callback, port); | 181 | omninet_read_bulk_callback, port); |
172 | result = usb_submit_urb(port->read_urb, GFP_KERNEL); | 182 | result = usb_submit_urb(port->read_urb, GFP_KERNEL); |
173 | if (result) | 183 | if (result) { |
174 | err("%s - failed submitting read urb, error %d", __FUNCTION__, result); | 184 | err("%s - failed submitting read urb, error %d", __FUNCTION__, result); |
185 | } | ||
175 | 186 | ||
176 | return result; | 187 | return result; |
177 | } | 188 | } |
178 | 189 | ||
179 | static void omninet_close (struct usb_serial_port *port, struct file * filp) | 190 | static void omninet_close (struct usb_serial_port *port, struct file * filp) |
180 | { | 191 | { |
181 | struct usb_serial *serial = port->serial; | ||
182 | struct usb_serial_port *wport; | ||
183 | |||
184 | dbg("%s - port %d", __FUNCTION__, port->number); | 192 | dbg("%s - port %d", __FUNCTION__, port->number); |
185 | |||
186 | wport = serial->port[1]; | ||
187 | usb_kill_urb(wport->write_urb); | ||
188 | usb_kill_urb(port->read_urb); | 193 | usb_kill_urb(port->read_urb); |
189 | |||
190 | kfree(usb_get_serial_port_data(port)); | ||
191 | } | 194 | } |
192 | 195 | ||
193 | 196 | ||
@@ -326,7 +329,12 @@ static void omninet_write_bulk_callback (struct urb *urb) | |||
326 | 329 | ||
327 | static void omninet_shutdown (struct usb_serial *serial) | 330 | static void omninet_shutdown (struct usb_serial *serial) |
328 | { | 331 | { |
332 | struct usb_serial_port *wport = serial->port[1]; | ||
333 | struct usb_serial_port *port = serial->port[0]; | ||
329 | dbg ("%s", __FUNCTION__); | 334 | dbg ("%s", __FUNCTION__); |
335 | |||
336 | usb_kill_urb(wport->write_urb); | ||
337 | kfree(usb_get_serial_port_data(port)); | ||
330 | } | 338 | } |
331 | 339 | ||
332 | 340 | ||
diff --git a/drivers/usb/serial/option.c b/drivers/usb/serial/option.c index ced9f32b29d9..8c3f55b080b4 100644 --- a/drivers/usb/serial/option.c +++ b/drivers/usb/serial/option.c | |||
@@ -67,54 +67,115 @@ static int option_tiocmset(struct usb_serial_port *port, struct file *file, | |||
67 | static int option_send_setup(struct usb_serial_port *port); | 67 | static int option_send_setup(struct usb_serial_port *port); |
68 | 68 | ||
69 | /* Vendor and product IDs */ | 69 | /* Vendor and product IDs */ |
70 | #define OPTION_VENDOR_ID 0x0AF0 | 70 | #define OPTION_VENDOR_ID 0x0AF0 |
71 | #define HUAWEI_VENDOR_ID 0x12D1 | 71 | #define OPTION_PRODUCT_COLT 0x5000 |
72 | #define AUDIOVOX_VENDOR_ID 0x0F3D | 72 | #define OPTION_PRODUCT_RICOLA 0x6000 |
73 | #define NOVATELWIRELESS_VENDOR_ID 0x1410 | 73 | #define OPTION_PRODUCT_RICOLA_LIGHT 0x6100 |
74 | #define ANYDATA_VENDOR_ID 0x16d5 | 74 | #define OPTION_PRODUCT_RICOLA_QUAD 0x6200 |
75 | 75 | #define OPTION_PRODUCT_RICOLA_QUAD_LIGHT 0x6300 | |
76 | #define OPTION_PRODUCT_OLD 0x5000 | 76 | #define OPTION_PRODUCT_RICOLA_NDIS 0x6050 |
77 | #define OPTION_PRODUCT_FUSION 0x6000 | 77 | #define OPTION_PRODUCT_RICOLA_NDIS_LIGHT 0x6150 |
78 | #define OPTION_PRODUCT_FUSION2 0x6300 | 78 | #define OPTION_PRODUCT_RICOLA_NDIS_QUAD 0x6250 |
79 | #define OPTION_PRODUCT_COBRA 0x6500 | 79 | #define OPTION_PRODUCT_RICOLA_NDIS_QUAD_LIGHT 0x6350 |
80 | #define OPTION_PRODUCT_COBRA2 0x6600 | 80 | #define OPTION_PRODUCT_COBRA 0x6500 |
81 | #define OPTION_PRODUCT_GTMAX36 0x6701 | 81 | #define OPTION_PRODUCT_COBRA_BUS 0x6501 |
82 | #define HUAWEI_PRODUCT_E600 0x1001 | 82 | #define OPTION_PRODUCT_VIPER 0x6600 |
83 | #define HUAWEI_PRODUCT_E220 0x1003 | 83 | #define OPTION_PRODUCT_VIPER_BUS 0x6601 |
84 | #define AUDIOVOX_PRODUCT_AIRCARD 0x0112 | 84 | #define OPTION_PRODUCT_GT_MAX_READY 0x6701 |
85 | #define NOVATELWIRELESS_PRODUCT_U740 0x1400 | 85 | #define OPTION_PRODUCT_GT_MAX 0x6711 |
86 | #define ANYDATA_PRODUCT_ID 0x6501 | 86 | #define OPTION_PRODUCT_FUJI_MODEM_LIGHT 0x6721 |
87 | #define OPTION_PRODUCT_FUJI_MODEM_GT 0x6741 | ||
88 | #define OPTION_PRODUCT_FUJI_MODEM_EX 0x6761 | ||
89 | #define OPTION_PRODUCT_FUJI_NETWORK_LIGHT 0x6731 | ||
90 | #define OPTION_PRODUCT_FUJI_NETWORK_GT 0x6751 | ||
91 | #define OPTION_PRODUCT_FUJI_NETWORK_EX 0x6771 | ||
92 | #define OPTION_PRODUCT_KOI_MODEM 0x6800 | ||
93 | #define OPTION_PRODUCT_KOI_NETWORK 0x6811 | ||
94 | #define OPTION_PRODUCT_SCORPION_MODEM 0x6901 | ||
95 | #define OPTION_PRODUCT_SCORPION_NETWORK 0x6911 | ||
96 | #define OPTION_PRODUCT_ETNA_MODEM 0x7001 | ||
97 | #define OPTION_PRODUCT_ETNA_NETWORK 0x7011 | ||
98 | #define OPTION_PRODUCT_ETNA_MODEM_LITE 0x7021 | ||
99 | #define OPTION_PRODUCT_ETNA_MODEM_GT 0x7041 | ||
100 | #define OPTION_PRODUCT_ETNA_MODEM_EX 0x7061 | ||
101 | #define OPTION_PRODUCT_ETNA_NETWORK_LITE 0x7031 | ||
102 | #define OPTION_PRODUCT_ETNA_NETWORK_GT 0x7051 | ||
103 | #define OPTION_PRODUCT_ETNA_NETWORK_EX 0x7071 | ||
104 | #define OPTION_PRODUCT_ETNA_KOI_MODEM 0x7100 | ||
105 | #define OPTION_PRODUCT_ETNA_KOI_NETWORK 0x7111 | ||
106 | |||
107 | #define HUAWEI_VENDOR_ID 0x12D1 | ||
108 | #define HUAWEI_PRODUCT_E600 0x1001 | ||
109 | #define HUAWEI_PRODUCT_E220 0x1003 | ||
110 | |||
111 | #define NOVATELWIRELESS_VENDOR_ID 0x1410 | ||
112 | |||
113 | #define ANYDATA_VENDOR_ID 0x16d5 | ||
114 | #define ANYDATA_PRODUCT_ID 0x6501 | ||
115 | |||
116 | #define BANDRICH_VENDOR_ID 0x1A8D | ||
117 | #define BANDRICH_PRODUCT_C100_1 0x1002 | ||
118 | #define BANDRICH_PRODUCT_C100_2 0x1003 | ||
119 | |||
120 | #define DELL_VENDOR_ID 0x413C | ||
87 | 121 | ||
88 | static struct usb_device_id option_ids[] = { | 122 | static struct usb_device_id option_ids[] = { |
89 | { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_OLD) }, | 123 | { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_COLT) }, |
90 | { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_FUSION) }, | 124 | { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_RICOLA) }, |
91 | { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_FUSION2) }, | 125 | { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_RICOLA_LIGHT) }, |
126 | { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_RICOLA_QUAD) }, | ||
127 | { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_RICOLA_QUAD_LIGHT) }, | ||
128 | { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_RICOLA_NDIS) }, | ||
129 | { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_RICOLA_NDIS_LIGHT) }, | ||
130 | { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_RICOLA_NDIS_QUAD) }, | ||
131 | { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_RICOLA_NDIS_QUAD_LIGHT) }, | ||
92 | { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_COBRA) }, | 132 | { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_COBRA) }, |
93 | { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_COBRA2) }, | 133 | { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_COBRA_BUS) }, |
94 | { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_GTMAX36) }, | 134 | { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_VIPER) }, |
135 | { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_VIPER_BUS) }, | ||
136 | { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_GT_MAX_READY) }, | ||
137 | { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_GT_MAX) }, | ||
138 | { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_FUJI_MODEM_LIGHT) }, | ||
139 | { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_FUJI_MODEM_GT) }, | ||
140 | { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_FUJI_MODEM_EX) }, | ||
141 | { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_FUJI_NETWORK_LIGHT) }, | ||
142 | { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_FUJI_NETWORK_GT) }, | ||
143 | { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_FUJI_NETWORK_EX) }, | ||
144 | { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_KOI_MODEM) }, | ||
145 | { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_KOI_NETWORK) }, | ||
146 | { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_SCORPION_MODEM) }, | ||
147 | { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_SCORPION_NETWORK) }, | ||
148 | { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_ETNA_MODEM) }, | ||
149 | { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_ETNA_NETWORK) }, | ||
150 | { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_ETNA_MODEM_LITE) }, | ||
151 | { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_ETNA_MODEM_GT) }, | ||
152 | { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_ETNA_MODEM_EX) }, | ||
153 | { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_ETNA_NETWORK_LITE) }, | ||
154 | { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_ETNA_NETWORK_GT) }, | ||
155 | { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_ETNA_NETWORK_EX) }, | ||
156 | { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_ETNA_KOI_MODEM) }, | ||
157 | { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_ETNA_KOI_NETWORK) }, | ||
95 | { USB_DEVICE(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_E600) }, | 158 | { USB_DEVICE(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_E600) }, |
96 | { USB_DEVICE(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_E220) }, | 159 | { USB_DEVICE(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_E220) }, |
97 | { USB_DEVICE(AUDIOVOX_VENDOR_ID, AUDIOVOX_PRODUCT_AIRCARD) }, | 160 | { USB_DEVICE(NOVATELWIRELESS_VENDOR_ID, 0x1100) }, /* Novatel Merlin XS620/S640 */ |
98 | { USB_DEVICE(NOVATELWIRELESS_VENDOR_ID,NOVATELWIRELESS_PRODUCT_U740) }, | 161 | { USB_DEVICE(NOVATELWIRELESS_VENDOR_ID, 0x1110) }, /* Novatel Merlin S620 */ |
162 | { USB_DEVICE(NOVATELWIRELESS_VENDOR_ID, 0x1120) }, /* Novatel Merlin EX720 */ | ||
163 | { USB_DEVICE(NOVATELWIRELESS_VENDOR_ID, 0x1130) }, /* Novatel Merlin S720 */ | ||
164 | { USB_DEVICE(NOVATELWIRELESS_VENDOR_ID, 0x1400) }, /* Novatel U730 */ | ||
165 | { USB_DEVICE(NOVATELWIRELESS_VENDOR_ID, 0x1410) }, /* Novatel U740 */ | ||
166 | { USB_DEVICE(NOVATELWIRELESS_VENDOR_ID, 0x1420) }, /* Novatel EU870 */ | ||
167 | { USB_DEVICE(NOVATELWIRELESS_VENDOR_ID, 0x1430) }, /* Novatel Merlin XU870 HSDPA/3G */ | ||
168 | { USB_DEVICE(NOVATELWIRELESS_VENDOR_ID, 0x1430) }, /* Novatel XU870 */ | ||
169 | { USB_DEVICE(NOVATELWIRELESS_VENDOR_ID, 0x2100) }, /* Novatel EV620 CDMA/EV-DO */ | ||
170 | { USB_DEVICE(NOVATELWIRELESS_VENDOR_ID, 0x2110) }, /* Novatel Merlin ES620 / Merlin ES720 / Ovation U720 */ | ||
171 | { USB_DEVICE(NOVATELWIRELESS_VENDOR_ID, 0x2130) }, /* Novatel Merlin ES620 SM Bus */ | ||
172 | { USB_DEVICE(NOVATELWIRELESS_VENDOR_ID, 0x2410) }, /* Novatel EU740 */ | ||
99 | { USB_DEVICE(ANYDATA_VENDOR_ID, ANYDATA_PRODUCT_ID) }, | 173 | { USB_DEVICE(ANYDATA_VENDOR_ID, ANYDATA_PRODUCT_ID) }, |
174 | { USB_DEVICE(BANDRICH_VENDOR_ID, BANDRICH_PRODUCT_C100_1) }, | ||
175 | { USB_DEVICE(BANDRICH_VENDOR_ID, BANDRICH_PRODUCT_C100_2) }, | ||
176 | { USB_DEVICE(DELL_VENDOR_ID, 0x8118) }, /* Dell Wireless 5510 Mobile Broadband HSDPA ExpressCard */ | ||
100 | { } /* Terminating entry */ | 177 | { } /* Terminating entry */ |
101 | }; | 178 | }; |
102 | |||
103 | static struct usb_device_id option_ids1[] = { | ||
104 | { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_OLD) }, | ||
105 | { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_FUSION) }, | ||
106 | { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_FUSION2) }, | ||
107 | { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_COBRA) }, | ||
108 | { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_COBRA2) }, | ||
109 | { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_GTMAX36) }, | ||
110 | { USB_DEVICE(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_E600) }, | ||
111 | { USB_DEVICE(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_E220) }, | ||
112 | { USB_DEVICE(AUDIOVOX_VENDOR_ID, AUDIOVOX_PRODUCT_AIRCARD) }, | ||
113 | { USB_DEVICE(NOVATELWIRELESS_VENDOR_ID,NOVATELWIRELESS_PRODUCT_U740) }, | ||
114 | { USB_DEVICE(ANYDATA_VENDOR_ID, ANYDATA_PRODUCT_ID) }, | ||
115 | { } /* Terminating entry */ | ||
116 | }; | ||
117 | |||
118 | MODULE_DEVICE_TABLE(usb, option_ids); | 179 | MODULE_DEVICE_TABLE(usb, option_ids); |
119 | 180 | ||
120 | static struct usb_driver option_driver = { | 181 | static struct usb_driver option_driver = { |
@@ -136,7 +197,7 @@ static struct usb_serial_driver option_1port_device = { | |||
136 | }, | 197 | }, |
137 | .description = "GSM modem (1-port)", | 198 | .description = "GSM modem (1-port)", |
138 | .usb_driver = &option_driver, | 199 | .usb_driver = &option_driver, |
139 | .id_table = option_ids1, | 200 | .id_table = option_ids, |
140 | .num_interrupt_in = NUM_DONT_CARE, | 201 | .num_interrupt_in = NUM_DONT_CARE, |
141 | .num_bulk_in = NUM_DONT_CARE, | 202 | .num_bulk_in = NUM_DONT_CARE, |
142 | .num_bulk_out = NUM_DONT_CARE, | 203 | .num_bulk_out = NUM_DONT_CARE, |
@@ -539,12 +600,6 @@ static int option_open(struct usb_serial_port *port, struct file *filp) | |||
539 | return (0); | 600 | return (0); |
540 | } | 601 | } |
541 | 602 | ||
542 | static inline void stop_urb(struct urb *urb) | ||
543 | { | ||
544 | if (urb && urb->status == -EINPROGRESS) | ||
545 | usb_kill_urb(urb); | ||
546 | } | ||
547 | |||
548 | static void option_close(struct usb_serial_port *port, struct file *filp) | 603 | static void option_close(struct usb_serial_port *port, struct file *filp) |
549 | { | 604 | { |
550 | int i; | 605 | int i; |
@@ -562,9 +617,9 @@ static void option_close(struct usb_serial_port *port, struct file *filp) | |||
562 | 617 | ||
563 | /* Stop reading/writing urbs */ | 618 | /* Stop reading/writing urbs */ |
564 | for (i = 0; i < N_IN_URB; i++) | 619 | for (i = 0; i < N_IN_URB; i++) |
565 | stop_urb(portdata->in_urbs[i]); | 620 | usb_kill_urb(portdata->in_urbs[i]); |
566 | for (i = 0; i < N_OUT_URB; i++) | 621 | for (i = 0; i < N_OUT_URB; i++) |
567 | stop_urb(portdata->out_urbs[i]); | 622 | usb_kill_urb(portdata->out_urbs[i]); |
568 | } | 623 | } |
569 | port->tty = NULL; | 624 | port->tty = NULL; |
570 | } | 625 | } |
@@ -695,9 +750,9 @@ static void option_shutdown(struct usb_serial *serial) | |||
695 | port = serial->port[i]; | 750 | port = serial->port[i]; |
696 | portdata = usb_get_serial_port_data(port); | 751 | portdata = usb_get_serial_port_data(port); |
697 | for (j = 0; j < N_IN_URB; j++) | 752 | for (j = 0; j < N_IN_URB; j++) |
698 | stop_urb(portdata->in_urbs[j]); | 753 | usb_kill_urb(portdata->in_urbs[j]); |
699 | for (j = 0; j < N_OUT_URB; j++) | 754 | for (j = 0; j < N_OUT_URB; j++) |
700 | stop_urb(portdata->out_urbs[j]); | 755 | usb_kill_urb(portdata->out_urbs[j]); |
701 | } | 756 | } |
702 | 757 | ||
703 | /* Now free them */ | 758 | /* Now free them */ |
diff --git a/drivers/usb/serial/pl2303.c b/drivers/usb/serial/pl2303.c index 6c083d4e2c9b..83dfae93a45d 100644 --- a/drivers/usb/serial/pl2303.c +++ b/drivers/usb/serial/pl2303.c | |||
@@ -83,6 +83,7 @@ static struct usb_device_id id_table [] = { | |||
83 | { USB_DEVICE(BELKIN_VENDOR_ID, BELKIN_PRODUCT_ID) }, | 83 | { USB_DEVICE(BELKIN_VENDOR_ID, BELKIN_PRODUCT_ID) }, |
84 | { USB_DEVICE(ALCOR_VENDOR_ID, ALCOR_PRODUCT_ID) }, | 84 | { USB_DEVICE(ALCOR_VENDOR_ID, ALCOR_PRODUCT_ID) }, |
85 | { USB_DEVICE(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_ID) }, | 85 | { USB_DEVICE(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_ID) }, |
86 | { USB_DEVICE(WS002IN_VENDOR_ID, WS002IN_PRODUCT_ID) }, | ||
86 | { } /* Terminating entry */ | 87 | { } /* Terminating entry */ |
87 | }; | 88 | }; |
88 | 89 | ||
diff --git a/drivers/usb/serial/pl2303.h b/drivers/usb/serial/pl2303.h index 65a5039665e7..f9a71d0c102e 100644 --- a/drivers/usb/serial/pl2303.h +++ b/drivers/usb/serial/pl2303.h | |||
@@ -97,3 +97,8 @@ | |||
97 | /* Huawei E620 UMTS/HSDPA card (ID: 12d1:1001) */ | 97 | /* Huawei E620 UMTS/HSDPA card (ID: 12d1:1001) */ |
98 | #define HUAWEI_VENDOR_ID 0x12d1 | 98 | #define HUAWEI_VENDOR_ID 0x12d1 |
99 | #define HUAWEI_PRODUCT_ID 0x1001 | 99 | #define HUAWEI_PRODUCT_ID 0x1001 |
100 | |||
101 | /* Willcom WS002IN Data Driver (by NetIndex Inc.) */ | ||
102 | #define WS002IN_VENDOR_ID 0x11f6 | ||
103 | #define WS002IN_PRODUCT_ID 0x2001 | ||
104 | |||
diff --git a/drivers/usb/serial/sierra.c b/drivers/usb/serial/sierra.c index ecedd833818d..644607de4c11 100644 --- a/drivers/usb/serial/sierra.c +++ b/drivers/usb/serial/sierra.c | |||
@@ -456,12 +456,6 @@ static int sierra_open(struct usb_serial_port *port, struct file *filp) | |||
456 | return (0); | 456 | return (0); |
457 | } | 457 | } |
458 | 458 | ||
459 | static inline void stop_urb(struct urb *urb) | ||
460 | { | ||
461 | if (urb && urb->status == -EINPROGRESS) | ||
462 | usb_kill_urb(urb); | ||
463 | } | ||
464 | |||
465 | static void sierra_close(struct usb_serial_port *port, struct file *filp) | 459 | static void sierra_close(struct usb_serial_port *port, struct file *filp) |
466 | { | 460 | { |
467 | int i; | 461 | int i; |
@@ -479,9 +473,9 @@ static void sierra_close(struct usb_serial_port *port, struct file *filp) | |||
479 | 473 | ||
480 | /* Stop reading/writing urbs */ | 474 | /* Stop reading/writing urbs */ |
481 | for (i = 0; i < N_IN_URB; i++) | 475 | for (i = 0; i < N_IN_URB; i++) |
482 | stop_urb(portdata->in_urbs[i]); | 476 | usb_unlink_urb(portdata->in_urbs[i]); |
483 | for (i = 0; i < N_OUT_URB; i++) | 477 | for (i = 0; i < N_OUT_URB; i++) |
484 | stop_urb(portdata->out_urbs[i]); | 478 | usb_unlink_urb(portdata->out_urbs[i]); |
485 | } | 479 | } |
486 | port->tty = NULL; | 480 | port->tty = NULL; |
487 | } | 481 | } |
@@ -583,17 +577,26 @@ static void sierra_shutdown(struct usb_serial *serial) | |||
583 | /* Stop reading/writing urbs */ | 577 | /* Stop reading/writing urbs */ |
584 | for (i = 0; i < serial->num_ports; ++i) { | 578 | for (i = 0; i < serial->num_ports; ++i) { |
585 | port = serial->port[i]; | 579 | port = serial->port[i]; |
580 | if (!port) | ||
581 | continue; | ||
586 | portdata = usb_get_serial_port_data(port); | 582 | portdata = usb_get_serial_port_data(port); |
583 | if (!portdata) | ||
584 | continue; | ||
585 | |||
587 | for (j = 0; j < N_IN_URB; j++) | 586 | for (j = 0; j < N_IN_URB; j++) |
588 | stop_urb(portdata->in_urbs[j]); | 587 | usb_unlink_urb(portdata->in_urbs[j]); |
589 | for (j = 0; j < N_OUT_URB; j++) | 588 | for (j = 0; j < N_OUT_URB; j++) |
590 | stop_urb(portdata->out_urbs[j]); | 589 | usb_unlink_urb(portdata->out_urbs[j]); |
591 | } | 590 | } |
592 | 591 | ||
593 | /* Now free them */ | 592 | /* Now free them */ |
594 | for (i = 0; i < serial->num_ports; ++i) { | 593 | for (i = 0; i < serial->num_ports; ++i) { |
595 | port = serial->port[i]; | 594 | port = serial->port[i]; |
595 | if (!port) | ||
596 | continue; | ||
596 | portdata = usb_get_serial_port_data(port); | 597 | portdata = usb_get_serial_port_data(port); |
598 | if (!portdata) | ||
599 | continue; | ||
597 | 600 | ||
598 | for (j = 0; j < N_IN_URB; j++) { | 601 | for (j = 0; j < N_IN_URB; j++) { |
599 | if (portdata->in_urbs[j]) { | 602 | if (portdata->in_urbs[j]) { |
@@ -612,6 +615,8 @@ static void sierra_shutdown(struct usb_serial *serial) | |||
612 | /* Now free per port private data */ | 615 | /* Now free per port private data */ |
613 | for (i = 0; i < serial->num_ports; i++) { | 616 | for (i = 0; i < serial->num_ports; i++) { |
614 | port = serial->port[i]; | 617 | port = serial->port[i]; |
618 | if (!port) | ||
619 | continue; | ||
615 | kfree(usb_get_serial_port_data(port)); | 620 | kfree(usb_get_serial_port_data(port)); |
616 | } | 621 | } |
617 | } | 622 | } |
diff --git a/drivers/usb/serial/usb-serial.c b/drivers/usb/serial/usb-serial.c index 6bf22a28adb8..7639022cdf84 100644 --- a/drivers/usb/serial/usb-serial.c +++ b/drivers/usb/serial/usb-serial.c | |||
@@ -99,9 +99,12 @@ static struct usb_serial *get_free_serial (struct usb_serial *serial, int num_po | |||
99 | continue; | 99 | continue; |
100 | 100 | ||
101 | *minor = i; | 101 | *minor = i; |
102 | j = 0; | ||
102 | dbg("%s - minor base = %d", __FUNCTION__, *minor); | 103 | dbg("%s - minor base = %d", __FUNCTION__, *minor); |
103 | for (i = *minor; (i < (*minor + num_ports)) && (i < SERIAL_TTY_MINORS); ++i) | 104 | for (i = *minor; (i < (*minor + num_ports)) && (i < SERIAL_TTY_MINORS); ++i) { |
104 | serial_table[i] = serial; | 105 | serial_table[i] = serial; |
106 | serial->port[j++]->number = i; | ||
107 | } | ||
105 | spin_unlock(&table_lock); | 108 | spin_unlock(&table_lock); |
106 | return serial; | 109 | return serial; |
107 | } | 110 | } |
@@ -826,7 +829,6 @@ int usb_serial_probe(struct usb_interface *interface, | |||
826 | num_ports = type->num_ports; | 829 | num_ports = type->num_ports; |
827 | } | 830 | } |
828 | 831 | ||
829 | serial->minor = minor; | ||
830 | serial->num_ports = num_ports; | 832 | serial->num_ports = num_ports; |
831 | serial->num_bulk_in = num_bulk_in; | 833 | serial->num_bulk_in = num_bulk_in; |
832 | serial->num_bulk_out = num_bulk_out; | 834 | serial->num_bulk_out = num_bulk_out; |
@@ -847,7 +849,6 @@ int usb_serial_probe(struct usb_interface *interface, | |||
847 | port = kzalloc(sizeof(struct usb_serial_port), GFP_KERNEL); | 849 | port = kzalloc(sizeof(struct usb_serial_port), GFP_KERNEL); |
848 | if (!port) | 850 | if (!port) |
849 | goto probe_error; | 851 | goto probe_error; |
850 | port->number = i + serial->minor; | ||
851 | port->serial = serial; | 852 | port->serial = serial; |
852 | spin_lock_init(&port->lock); | 853 | spin_lock_init(&port->lock); |
853 | mutex_init(&port->mutex); | 854 | mutex_init(&port->mutex); |
@@ -980,6 +981,7 @@ int usb_serial_probe(struct usb_interface *interface, | |||
980 | dev_err(&interface->dev, "No more free serial devices\n"); | 981 | dev_err(&interface->dev, "No more free serial devices\n"); |
981 | goto probe_error; | 982 | goto probe_error; |
982 | } | 983 | } |
984 | serial->minor = minor; | ||
983 | 985 | ||
984 | /* register all of the individual ports with the driver core */ | 986 | /* register all of the individual ports with the driver core */ |
985 | for (i = 0; i < num_ports; ++i) { | 987 | for (i = 0; i < num_ports; ++i) { |
@@ -1034,9 +1036,6 @@ probe_error: | |||
1034 | kfree(port->interrupt_out_buffer); | 1036 | kfree(port->interrupt_out_buffer); |
1035 | } | 1037 | } |
1036 | 1038 | ||
1037 | /* return the minor range that this device had */ | ||
1038 | return_serial (serial); | ||
1039 | |||
1040 | /* free up any memory that we allocated */ | 1039 | /* free up any memory that we allocated */ |
1041 | for (i = 0; i < serial->num_port_pointers; ++i) | 1040 | for (i = 0; i < serial->num_port_pointers; ++i) |
1042 | kfree(serial->port[i]); | 1041 | kfree(serial->port[i]); |
diff --git a/drivers/usb/serial/visor.c b/drivers/usb/serial/visor.c index 2f59ff226e2c..ffbe601cde2a 100644 --- a/drivers/usb/serial/visor.c +++ b/drivers/usb/serial/visor.c | |||
@@ -384,19 +384,21 @@ static int visor_write (struct usb_serial_port *port, const unsigned char *buf, | |||
384 | dbg("%s - write limit hit\n", __FUNCTION__); | 384 | dbg("%s - write limit hit\n", __FUNCTION__); |
385 | return 0; | 385 | return 0; |
386 | } | 386 | } |
387 | priv->outstanding_urbs++; | ||
387 | spin_unlock_irqrestore(&priv->lock, flags); | 388 | spin_unlock_irqrestore(&priv->lock, flags); |
388 | 389 | ||
389 | buffer = kmalloc (count, GFP_ATOMIC); | 390 | buffer = kmalloc (count, GFP_ATOMIC); |
390 | if (!buffer) { | 391 | if (!buffer) { |
391 | dev_err(&port->dev, "out of memory\n"); | 392 | dev_err(&port->dev, "out of memory\n"); |
392 | return -ENOMEM; | 393 | count = -ENOMEM; |
394 | goto error_no_buffer; | ||
393 | } | 395 | } |
394 | 396 | ||
395 | urb = usb_alloc_urb(0, GFP_ATOMIC); | 397 | urb = usb_alloc_urb(0, GFP_ATOMIC); |
396 | if (!urb) { | 398 | if (!urb) { |
397 | dev_err(&port->dev, "no more free urbs\n"); | 399 | dev_err(&port->dev, "no more free urbs\n"); |
398 | kfree (buffer); | 400 | count = -ENOMEM; |
399 | return -ENOMEM; | 401 | goto error_no_urb; |
400 | } | 402 | } |
401 | 403 | ||
402 | memcpy (buffer, buf, count); | 404 | memcpy (buffer, buf, count); |
@@ -415,19 +417,27 @@ static int visor_write (struct usb_serial_port *port, const unsigned char *buf, | |||
415 | dev_err(&port->dev, "%s - usb_submit_urb(write bulk) failed with status = %d\n", | 417 | dev_err(&port->dev, "%s - usb_submit_urb(write bulk) failed with status = %d\n", |
416 | __FUNCTION__, status); | 418 | __FUNCTION__, status); |
417 | count = status; | 419 | count = status; |
418 | kfree (buffer); | 420 | goto error; |
419 | } else { | 421 | } else { |
420 | spin_lock_irqsave(&priv->lock, flags); | 422 | spin_lock_irqsave(&priv->lock, flags); |
421 | ++priv->outstanding_urbs; | ||
422 | priv->bytes_out += count; | 423 | priv->bytes_out += count; |
423 | spin_unlock_irqrestore(&priv->lock, flags); | 424 | spin_unlock_irqrestore(&priv->lock, flags); |
424 | } | 425 | } |
425 | 426 | ||
426 | /* we are done with this urb, so let the host driver | 427 | /* we are done with this urb, so let the host driver |
427 | * really free it when it is finished with it */ | 428 | * really free it when it is finished with it */ |
428 | usb_free_urb (urb); | 429 | usb_free_urb(urb); |
429 | 430 | ||
430 | return count; | 431 | return count; |
432 | error: | ||
433 | usb_free_urb(urb); | ||
434 | error_no_urb: | ||
435 | kfree(buffer); | ||
436 | error_no_buffer: | ||
437 | spin_lock_irqsave(&priv->lock, flags); | ||
438 | --priv->outstanding_urbs; | ||
439 | spin_unlock_irqrestore(&priv->lock, flags); | ||
440 | return count; | ||
431 | } | 441 | } |
432 | 442 | ||
433 | 443 | ||
diff --git a/drivers/usb/serial/whiteheat.c b/drivers/usb/serial/whiteheat.c index bf16e9e1d84e..27c5f8f9a2d5 100644 --- a/drivers/usb/serial/whiteheat.c +++ b/drivers/usb/serial/whiteheat.c | |||
@@ -1109,7 +1109,7 @@ static int firm_send_command (struct usb_serial_port *port, __u8 command, __u8 * | |||
1109 | command_port = port->serial->port[COMMAND_PORT]; | 1109 | command_port = port->serial->port[COMMAND_PORT]; |
1110 | command_info = usb_get_serial_port_data(command_port); | 1110 | command_info = usb_get_serial_port_data(command_port); |
1111 | spin_lock_irqsave(&command_info->lock, flags); | 1111 | spin_lock_irqsave(&command_info->lock, flags); |
1112 | command_info->command_finished = FALSE; | 1112 | command_info->command_finished = false; |
1113 | 1113 | ||
1114 | transfer_buffer = (__u8 *)command_port->write_urb->transfer_buffer; | 1114 | transfer_buffer = (__u8 *)command_port->write_urb->transfer_buffer; |
1115 | transfer_buffer[0] = command; | 1115 | transfer_buffer[0] = command; |
@@ -1124,12 +1124,12 @@ static int firm_send_command (struct usb_serial_port *port, __u8 command, __u8 * | |||
1124 | spin_unlock_irqrestore(&command_info->lock, flags); | 1124 | spin_unlock_irqrestore(&command_info->lock, flags); |
1125 | 1125 | ||
1126 | /* wait for the command to complete */ | 1126 | /* wait for the command to complete */ |
1127 | wait_event_interruptible_timeout(command_info->wait_command, | 1127 | wait_event_interruptible_timeout(command_info->wait_command, |
1128 | (command_info->command_finished != FALSE), COMMAND_TIMEOUT); | 1128 | (bool)command_info->command_finished, COMMAND_TIMEOUT); |
1129 | 1129 | ||
1130 | spin_lock_irqsave(&command_info->lock, flags); | 1130 | spin_lock_irqsave(&command_info->lock, flags); |
1131 | 1131 | ||
1132 | if (command_info->command_finished == FALSE) { | 1132 | if (command_info->command_finished == false) { |
1133 | dbg("%s - command timed out.", __FUNCTION__); | 1133 | dbg("%s - command timed out.", __FUNCTION__); |
1134 | retval = -ETIMEDOUT; | 1134 | retval = -ETIMEDOUT; |
1135 | goto exit; | 1135 | goto exit; |
diff --git a/drivers/usb/serial/whiteheat.h b/drivers/usb/serial/whiteheat.h index d714eff58dc0..f16079705664 100644 --- a/drivers/usb/serial/whiteheat.h +++ b/drivers/usb/serial/whiteheat.h | |||
@@ -20,10 +20,6 @@ | |||
20 | #define __LINUX_USB_SERIAL_WHITEHEAT_H | 20 | #define __LINUX_USB_SERIAL_WHITEHEAT_H |
21 | 21 | ||
22 | 22 | ||
23 | #define FALSE 0 | ||
24 | #define TRUE 1 | ||
25 | |||
26 | |||
27 | /* WhiteHEAT commands */ | 23 | /* WhiteHEAT commands */ |
28 | #define WHITEHEAT_OPEN 1 /* open the port */ | 24 | #define WHITEHEAT_OPEN 1 /* open the port */ |
29 | #define WHITEHEAT_CLOSE 2 /* close the port */ | 25 | #define WHITEHEAT_CLOSE 2 /* close the port */ |
diff --git a/drivers/usb/storage/libusual.c b/drivers/usb/storage/libusual.c index 599ad10a761b..06d1107dbd47 100644 --- a/drivers/usb/storage/libusual.c +++ b/drivers/usb/storage/libusual.c | |||
@@ -117,6 +117,7 @@ EXPORT_SYMBOL_GPL(usb_usual_check_type); | |||
117 | static int usu_probe(struct usb_interface *intf, | 117 | static int usu_probe(struct usb_interface *intf, |
118 | const struct usb_device_id *id) | 118 | const struct usb_device_id *id) |
119 | { | 119 | { |
120 | int rc; | ||
120 | unsigned long type; | 121 | unsigned long type; |
121 | struct task_struct* task; | 122 | struct task_struct* task; |
122 | unsigned long flags; | 123 | unsigned long flags; |
@@ -135,7 +136,7 @@ static int usu_probe(struct usb_interface *intf, | |||
135 | 136 | ||
136 | task = kthread_run(usu_probe_thread, (void*)type, "libusual_%d", type); | 137 | task = kthread_run(usu_probe_thread, (void*)type, "libusual_%d", type); |
137 | if (IS_ERR(task)) { | 138 | if (IS_ERR(task)) { |
138 | int rc = PTR_ERR(task); | 139 | rc = PTR_ERR(task); |
139 | printk(KERN_WARNING "libusual: " | 140 | printk(KERN_WARNING "libusual: " |
140 | "Unable to start the thread for %s: %d\n", | 141 | "Unable to start the thread for %s: %d\n", |
141 | bias_names[type], rc); | 142 | bias_names[type], rc); |
diff --git a/drivers/usb/storage/scsiglue.c b/drivers/usb/storage/scsiglue.c index 70234f5dbeeb..e227f64d5641 100644 --- a/drivers/usb/storage/scsiglue.c +++ b/drivers/usb/storage/scsiglue.c | |||
@@ -153,6 +153,12 @@ static int slave_configure(struct scsi_device *sdev) | |||
153 | if (us->flags & US_FL_FIX_CAPACITY) | 153 | if (us->flags & US_FL_FIX_CAPACITY) |
154 | sdev->fix_capacity = 1; | 154 | sdev->fix_capacity = 1; |
155 | 155 | ||
156 | /* A few disks have two indistinguishable version, one of | ||
157 | * which reports the correct capacity and the other does not. | ||
158 | * The sd driver has to guess which is the case. */ | ||
159 | if (us->flags & US_FL_CAPACITY_HEURISTICS) | ||
160 | sdev->guess_capacity = 1; | ||
161 | |||
156 | /* Some devices report a SCSI revision level above 2 but are | 162 | /* Some devices report a SCSI revision level above 2 but are |
157 | * unable to handle the REPORT LUNS command (for which | 163 | * unable to handle the REPORT LUNS command (for which |
158 | * support is mandatory at level 3). Since we already have | 164 | * support is mandatory at level 3). Since we already have |
diff --git a/drivers/usb/storage/unusual_devs.h b/drivers/usb/storage/unusual_devs.h index f49a62fc32d2..8b3145ab7757 100644 --- a/drivers/usb/storage/unusual_devs.h +++ b/drivers/usb/storage/unusual_devs.h | |||
@@ -146,6 +146,13 @@ UNUSUAL_DEV( 0x0420, 0x0001, 0x0100, 0x0100, | |||
146 | US_SC_DEVICE, US_PR_DEVICE, NULL, | 146 | US_SC_DEVICE, US_PR_DEVICE, NULL, |
147 | US_FL_IGNORE_RESIDUE ), | 147 | US_FL_IGNORE_RESIDUE ), |
148 | 148 | ||
149 | /* Reported by Andrew Nayenko <relan@bk.ru> */ | ||
150 | UNUSUAL_DEV( 0x0421, 0x0019, 0x0592, 0x0592, | ||
151 | "Nokia", | ||
152 | "Nokia 6288", | ||
153 | US_SC_DEVICE, US_PR_DEVICE, NULL, | ||
154 | US_FL_MAX_SECTORS_64 ), | ||
155 | |||
149 | /* Reported by Mario Rettig <mariorettig@web.de> */ | 156 | /* Reported by Mario Rettig <mariorettig@web.de> */ |
150 | UNUSUAL_DEV( 0x0421, 0x042e, 0x0100, 0x0100, | 157 | UNUSUAL_DEV( 0x0421, 0x042e, 0x0100, 0x0100, |
151 | "Nokia", | 158 | "Nokia", |
@@ -320,6 +327,13 @@ UNUSUAL_DEV( 0x04b0, 0x040d, 0x0100, 0x0100, | |||
320 | US_SC_DEVICE, US_PR_DEVICE, NULL, | 327 | US_SC_DEVICE, US_PR_DEVICE, NULL, |
321 | US_FL_FIX_CAPACITY), | 328 | US_FL_FIX_CAPACITY), |
322 | 329 | ||
330 | /* Reported by Emil Larsson <emil@swip.net> */ | ||
331 | UNUSUAL_DEV( 0x04b0, 0x0411, 0x0100, 0x0100, | ||
332 | "NIKON", | ||
333 | "NIKON DSC D80", | ||
334 | US_SC_DEVICE, US_PR_DEVICE, NULL, | ||
335 | US_FL_FIX_CAPACITY), | ||
336 | |||
323 | /* BENQ DC5330 | 337 | /* BENQ DC5330 |
324 | * Reported by Manuel Fombuena <mfombuena@ya.com> and | 338 | * Reported by Manuel Fombuena <mfombuena@ya.com> and |
325 | * Frank Copeland <fjc@thingy.apana.org.au> */ | 339 | * Frank Copeland <fjc@thingy.apana.org.au> */ |
@@ -1101,6 +1115,15 @@ UNUSUAL_DEV( 0x08bd, 0x1100, 0x0000, 0x0000, | |||
1101 | US_SC_DEVICE, US_PR_DEVICE, NULL, | 1115 | US_SC_DEVICE, US_PR_DEVICE, NULL, |
1102 | US_FL_SINGLE_LUN), | 1116 | US_FL_SINGLE_LUN), |
1103 | 1117 | ||
1118 | /* Submitted by Dylan Taft <d13f00l@gmail.com> | ||
1119 | * US_FL_IGNORE_RESIDUE Needed | ||
1120 | */ | ||
1121 | UNUSUAL_DEV( 0x08ca, 0x3103, 0x0100, 0x0100, | ||
1122 | "AIPTEK", | ||
1123 | "Aiptek USB Keychain MP3 Player", | ||
1124 | US_SC_DEVICE, US_PR_DEVICE, NULL, | ||
1125 | US_FL_IGNORE_RESIDUE), | ||
1126 | |||
1104 | /* Entry needed for flags. Moreover, all devices with this ID use | 1127 | /* Entry needed for flags. Moreover, all devices with this ID use |
1105 | * bulk-only transport, but _some_ falsely report Control/Bulk instead. | 1128 | * bulk-only transport, but _some_ falsely report Control/Bulk instead. |
1106 | * One example is "Trumpion Digital Research MYMP3". | 1129 | * One example is "Trumpion Digital Research MYMP3". |
@@ -1311,12 +1334,13 @@ UNUSUAL_DEV( 0x0fce, 0xd008, 0x0000, 0x0000, | |||
1311 | US_SC_DEVICE, US_PR_DEVICE, NULL, | 1334 | US_SC_DEVICE, US_PR_DEVICE, NULL, |
1312 | US_FL_NO_WP_DETECT ), | 1335 | US_FL_NO_WP_DETECT ), |
1313 | 1336 | ||
1314 | /* Reported by Jan Mate <mate@fiit.stuba.sk> */ | 1337 | /* Reported by Jan Mate <mate@fiit.stuba.sk> |
1338 | * and by Soeren Sonnenburg <kernel@nn7.de> */ | ||
1315 | UNUSUAL_DEV( 0x0fce, 0xe030, 0x0000, 0x0000, | 1339 | UNUSUAL_DEV( 0x0fce, 0xe030, 0x0000, 0x0000, |
1316 | "Sony Ericsson", | 1340 | "Sony Ericsson", |
1317 | "P990i", | 1341 | "P990i", |
1318 | US_SC_DEVICE, US_PR_DEVICE, NULL, | 1342 | US_SC_DEVICE, US_PR_DEVICE, NULL, |
1319 | US_FL_FIX_CAPACITY ), | 1343 | US_FL_FIX_CAPACITY | US_FL_IGNORE_RESIDUE ), |
1320 | 1344 | ||
1321 | /* Reported by Emmanuel Vasilakis <evas@forthnet.gr> */ | 1345 | /* Reported by Emmanuel Vasilakis <evas@forthnet.gr> */ |
1322 | UNUSUAL_DEV( 0x0fce, 0xe031, 0x0000, 0x0000, | 1346 | UNUSUAL_DEV( 0x0fce, 0xe031, 0x0000, 0x0000, |
@@ -1347,15 +1371,6 @@ UNUSUAL_DEV( 0x1210, 0x0003, 0x0100, 0x0100, | |||
1347 | US_SC_DEVICE, US_PR_DEVICE, NULL, | 1371 | US_SC_DEVICE, US_PR_DEVICE, NULL, |
1348 | US_FL_IGNORE_RESIDUE ), | 1372 | US_FL_IGNORE_RESIDUE ), |
1349 | 1373 | ||
1350 | /* This prevents the kernel from detecting the virtual cd-drive with the | ||
1351 | * Windows drivers. <johann.wilhelm@student.tugraz.at> | ||
1352 | */ | ||
1353 | UNUSUAL_DEV( 0x12d1, 0x1003, 0x0000, 0xffff, | ||
1354 | "HUAWEI", | ||
1355 | "E220 USB-UMTS Install", | ||
1356 | US_SC_DEVICE, US_PR_DEVICE, NULL, | ||
1357 | US_FL_IGNORE_DEVICE), | ||
1358 | |||
1359 | /* Reported by Vilius Bilinkevicius <vilisas AT xxx DOT lt) */ | 1374 | /* Reported by Vilius Bilinkevicius <vilisas AT xxx DOT lt) */ |
1360 | UNUSUAL_DEV( 0x132b, 0x000b, 0x0001, 0x0001, | 1375 | UNUSUAL_DEV( 0x132b, 0x000b, 0x0001, 0x0001, |
1361 | "Minolta", | 1376 | "Minolta", |
@@ -1394,6 +1409,16 @@ UNUSUAL_DEV( 0x22b8, 0x3010, 0x0001, 0x0001, | |||
1394 | US_SC_DEVICE, US_PR_DEVICE, NULL, | 1409 | US_SC_DEVICE, US_PR_DEVICE, NULL, |
1395 | US_FL_FIX_CAPACITY | US_FL_IGNORE_RESIDUE ), | 1410 | US_FL_FIX_CAPACITY | US_FL_IGNORE_RESIDUE ), |
1396 | 1411 | ||
1412 | /* | ||
1413 | * Patch by Pete Zaitcev <zaitcev@redhat.com> | ||
1414 | * Report by Mark Patton. Red Hat bz#208928. | ||
1415 | */ | ||
1416 | UNUSUAL_DEV( 0x22b8, 0x4810, 0x0001, 0x0001, | ||
1417 | "Motorola", | ||
1418 | "RAZR V3i", | ||
1419 | US_SC_DEVICE, US_PR_DEVICE, NULL, | ||
1420 | US_FL_FIX_CAPACITY), | ||
1421 | |||
1397 | /* Reported by Radovan Garabik <garabik@kassiopeia.juls.savba.sk> */ | 1422 | /* Reported by Radovan Garabik <garabik@kassiopeia.juls.savba.sk> */ |
1398 | UNUSUAL_DEV( 0x2735, 0x100b, 0x0000, 0x9999, | 1423 | UNUSUAL_DEV( 0x2735, 0x100b, 0x0000, 0x9999, |
1399 | "MPIO", | 1424 | "MPIO", |
@@ -1423,7 +1448,7 @@ UNUSUAL_DEV( 0xed06, 0x4500, 0x0001, 0x0001, | |||
1423 | "DataStor", | 1448 | "DataStor", |
1424 | "USB4500 FW1.04", | 1449 | "USB4500 FW1.04", |
1425 | US_SC_DEVICE, US_PR_DEVICE, NULL, | 1450 | US_SC_DEVICE, US_PR_DEVICE, NULL, |
1426 | US_FL_FIX_CAPACITY), | 1451 | US_FL_CAPACITY_HEURISTICS), |
1427 | 1452 | ||
1428 | /* Control/Bulk transport for all SubClass values */ | 1453 | /* Control/Bulk transport for all SubClass values */ |
1429 | USUAL_DEV(US_SC_RBC, US_PR_CB, USB_US_TYPE_STOR), | 1454 | USUAL_DEV(US_SC_RBC, US_PR_CB, USB_US_TYPE_STOR), |
diff --git a/drivers/usb/storage/usb.c b/drivers/usb/storage/usb.c index 7e7ec29782f1..8e898e3d861e 100644 --- a/drivers/usb/storage/usb.c +++ b/drivers/usb/storage/usb.c | |||
@@ -55,7 +55,7 @@ | |||
55 | #include <linux/slab.h> | 55 | #include <linux/slab.h> |
56 | #include <linux/kthread.h> | 56 | #include <linux/kthread.h> |
57 | #include <linux/mutex.h> | 57 | #include <linux/mutex.h> |
58 | #include <linux/utsrelease.h> | 58 | #include <linux/utsname.h> |
59 | 59 | ||
60 | #include <scsi/scsi.h> | 60 | #include <scsi/scsi.h> |
61 | #include <scsi/scsi_cmnd.h> | 61 | #include <scsi/scsi_cmnd.h> |
@@ -547,7 +547,7 @@ static int get_device_info(struct us_data *us, const struct usb_device_id *id) | |||
547 | idesc->bInterfaceSubClass, | 547 | idesc->bInterfaceSubClass, |
548 | idesc->bInterfaceProtocol, | 548 | idesc->bInterfaceProtocol, |
549 | msgs[msg], | 549 | msgs[msg], |
550 | UTS_RELEASE); | 550 | utsname()->release); |
551 | } | 551 | } |
552 | 552 | ||
553 | return 0; | 553 | return 0; |
diff --git a/drivers/usb/usb-skeleton.c b/drivers/usb/usb-skeleton.c index 296b091cf168..8432bf171d2e 100644 --- a/drivers/usb/usb-skeleton.c +++ b/drivers/usb/usb-skeleton.c | |||
@@ -34,18 +34,25 @@ static struct usb_device_id skel_table [] = { | |||
34 | }; | 34 | }; |
35 | MODULE_DEVICE_TABLE(usb, skel_table); | 35 | MODULE_DEVICE_TABLE(usb, skel_table); |
36 | 36 | ||
37 | /* to prevent a race between open and disconnect */ | ||
38 | static DEFINE_MUTEX(skel_open_lock); | ||
39 | |||
37 | 40 | ||
38 | /* Get a minor range for your devices from the usb maintainer */ | 41 | /* Get a minor range for your devices from the usb maintainer */ |
39 | #define USB_SKEL_MINOR_BASE 192 | 42 | #define USB_SKEL_MINOR_BASE 192 |
40 | 43 | ||
41 | /* our private defines. if this grows any larger, use your own .h file */ | 44 | /* our private defines. if this grows any larger, use your own .h file */ |
42 | #define MAX_TRANSFER (PAGE_SIZE - 512) | 45 | #define MAX_TRANSFER (PAGE_SIZE - 512) |
46 | /* MAX_TRANSFER is chosen so that the VM is not stressed by | ||
47 | allocations > PAGE_SIZE and the number of packets in a page | ||
48 | is an integer 512 is the largest possible packet on EHCI */ | ||
43 | #define WRITES_IN_FLIGHT 8 | 49 | #define WRITES_IN_FLIGHT 8 |
50 | /* arbitrarily chosen */ | ||
44 | 51 | ||
45 | /* Structure to hold all of our device specific stuff */ | 52 | /* Structure to hold all of our device specific stuff */ |
46 | struct usb_skel { | 53 | struct usb_skel { |
47 | struct usb_device *dev; /* the usb device for this device */ | 54 | struct usb_device *udev; /* the usb device for this device */ |
48 | struct usb_interface *interface; /* the interface for this device */ | 55 | struct usb_interface *interface; /* the interface for this device */ |
49 | struct semaphore limit_sem; /* limiting the number of writes in progress */ | 56 | struct semaphore limit_sem; /* limiting the number of writes in progress */ |
50 | unsigned char *bulk_in_buffer; /* the buffer to receive data */ | 57 | unsigned char *bulk_in_buffer; /* the buffer to receive data */ |
51 | size_t bulk_in_size; /* the size of the receive buffer */ | 58 | size_t bulk_in_size; /* the size of the receive buffer */ |
@@ -76,8 +83,10 @@ static int skel_open(struct inode *inode, struct file *file) | |||
76 | 83 | ||
77 | subminor = iminor(inode); | 84 | subminor = iminor(inode); |
78 | 85 | ||
86 | mutex_lock(&skel_open_lock); | ||
79 | interface = usb_find_interface(&skel_driver, subminor); | 87 | interface = usb_find_interface(&skel_driver, subminor); |
80 | if (!interface) { | 88 | if (!interface) { |
89 | mutex_unlock(&skel_open_lock); | ||
81 | err ("%s - error, can't find device for minor %d", | 90 | err ("%s - error, can't find device for minor %d", |
82 | __FUNCTION__, subminor); | 91 | __FUNCTION__, subminor); |
83 | retval = -ENODEV; | 92 | retval = -ENODEV; |
@@ -86,17 +95,22 @@ static int skel_open(struct inode *inode, struct file *file) | |||
86 | 95 | ||
87 | dev = usb_get_intfdata(interface); | 96 | dev = usb_get_intfdata(interface); |
88 | if (!dev) { | 97 | if (!dev) { |
98 | mutex_unlock(&skel_open_lock); | ||
89 | retval = -ENODEV; | 99 | retval = -ENODEV; |
90 | goto exit; | 100 | goto exit; |
91 | } | 101 | } |
92 | 102 | ||
103 | /* increment our usage count for the device */ | ||
104 | kref_get(&dev->kref); | ||
105 | /* now we can drop the lock */ | ||
106 | mutex_unlock(&skel_open_lock); | ||
107 | |||
93 | /* prevent the device from being autosuspended */ | 108 | /* prevent the device from being autosuspended */ |
94 | retval = usb_autopm_get_interface(interface); | 109 | retval = usb_autopm_get_interface(interface); |
95 | if (retval) | 110 | if (retval) { |
111 | kref_put(&dev->kref, skel_delete); | ||
96 | goto exit; | 112 | goto exit; |
97 | 113 | } | |
98 | /* increment our usage count for the device */ | ||
99 | kref_get(&dev->kref); | ||
100 | 114 | ||
101 | /* save our object in the file's private structure */ | 115 | /* save our object in the file's private structure */ |
102 | file->private_data = dev; | 116 | file->private_data = dev; |
@@ -199,12 +213,6 @@ static ssize_t skel_write(struct file *file, const char *user_buffer, size_t cou | |||
199 | goto exit; | 213 | goto exit; |
200 | } | 214 | } |
201 | 215 | ||
202 | mutex_lock(&dev->io_mutex); | ||
203 | if (!dev->interface) { /* disconnect() was called */ | ||
204 | retval = -ENODEV; | ||
205 | goto error; | ||
206 | } | ||
207 | |||
208 | /* create a urb, and a buffer for it, and copy the data to the urb */ | 216 | /* create a urb, and a buffer for it, and copy the data to the urb */ |
209 | urb = usb_alloc_urb(0, GFP_KERNEL); | 217 | urb = usb_alloc_urb(0, GFP_KERNEL); |
210 | if (!urb) { | 218 | if (!urb) { |
@@ -223,6 +231,14 @@ static ssize_t skel_write(struct file *file, const char *user_buffer, size_t cou | |||
223 | goto error; | 231 | goto error; |
224 | } | 232 | } |
225 | 233 | ||
234 | /* this lock makes sure we don't submit URBs to gone devices */ | ||
235 | mutex_lock(&dev->io_mutex); | ||
236 | if (!dev->interface) { /* disconnect() was called */ | ||
237 | mutex_unlock(&dev->io_mutex); | ||
238 | retval = -ENODEV; | ||
239 | goto error; | ||
240 | } | ||
241 | |||
226 | /* initialize the urb properly */ | 242 | /* initialize the urb properly */ |
227 | usb_fill_bulk_urb(urb, dev->udev, | 243 | usb_fill_bulk_urb(urb, dev->udev, |
228 | usb_sndbulkpipe(dev->udev, dev->bulk_out_endpointAddr), | 244 | usb_sndbulkpipe(dev->udev, dev->bulk_out_endpointAddr), |
@@ -231,6 +247,7 @@ static ssize_t skel_write(struct file *file, const char *user_buffer, size_t cou | |||
231 | 247 | ||
232 | /* send the data out the bulk port */ | 248 | /* send the data out the bulk port */ |
233 | retval = usb_submit_urb(urb, GFP_KERNEL); | 249 | retval = usb_submit_urb(urb, GFP_KERNEL); |
250 | mutex_unlock(&dev->io_mutex); | ||
234 | if (retval) { | 251 | if (retval) { |
235 | err("%s - failed submitting write urb, error %d", __FUNCTION__, retval); | 252 | err("%s - failed submitting write urb, error %d", __FUNCTION__, retval); |
236 | goto error; | 253 | goto error; |
@@ -239,7 +256,7 @@ static ssize_t skel_write(struct file *file, const char *user_buffer, size_t cou | |||
239 | /* release our reference to this urb, the USB core will eventually free it entirely */ | 256 | /* release our reference to this urb, the USB core will eventually free it entirely */ |
240 | usb_free_urb(urb); | 257 | usb_free_urb(urb); |
241 | 258 | ||
242 | mutex_unlock(&dev->io_mutex); | 259 | |
243 | return writesize; | 260 | return writesize; |
244 | 261 | ||
245 | error: | 262 | error: |
@@ -247,7 +264,6 @@ error: | |||
247 | usb_buffer_free(dev->udev, writesize, buf, urb->transfer_dma); | 264 | usb_buffer_free(dev->udev, writesize, buf, urb->transfer_dma); |
248 | usb_free_urb(urb); | 265 | usb_free_urb(urb); |
249 | } | 266 | } |
250 | mutex_unlock(&dev->io_mutex); | ||
251 | up(&dev->limit_sem); | 267 | up(&dev->limit_sem); |
252 | 268 | ||
253 | exit: | 269 | exit: |
@@ -342,6 +358,7 @@ static int skel_probe(struct usb_interface *interface, const struct usb_device_i | |||
342 | 358 | ||
343 | error: | 359 | error: |
344 | if (dev) | 360 | if (dev) |
361 | /* this frees allocated memory */ | ||
345 | kref_put(&dev->kref, skel_delete); | 362 | kref_put(&dev->kref, skel_delete); |
346 | return retval; | 363 | return retval; |
347 | } | 364 | } |
@@ -352,20 +369,21 @@ static void skel_disconnect(struct usb_interface *interface) | |||
352 | int minor = interface->minor; | 369 | int minor = interface->minor; |
353 | 370 | ||
354 | /* prevent skel_open() from racing skel_disconnect() */ | 371 | /* prevent skel_open() from racing skel_disconnect() */ |
355 | lock_kernel(); | 372 | mutex_lock(&skel_open_lock); |
356 | 373 | ||
357 | dev = usb_get_intfdata(interface); | 374 | dev = usb_get_intfdata(interface); |
358 | usb_set_intfdata(interface, NULL); | 375 | usb_set_intfdata(interface, NULL); |
359 | 376 | ||
360 | /* give back our minor */ | 377 | /* give back our minor */ |
361 | usb_deregister_dev(interface, &skel_class); | 378 | usb_deregister_dev(interface, &skel_class); |
379 | mutex_unlock(&skel_open_lock); | ||
362 | 380 | ||
363 | /* prevent more I/O from starting */ | 381 | /* prevent more I/O from starting */ |
364 | mutex_lock(&dev->io_mutex); | 382 | mutex_lock(&dev->io_mutex); |
365 | dev->interface = NULL; | 383 | dev->interface = NULL; |
366 | mutex_unlock(&dev->io_mutex); | 384 | mutex_unlock(&dev->io_mutex); |
367 | 385 | ||
368 | unlock_kernel(); | 386 | |
369 | 387 | ||
370 | /* decrement our usage count */ | 388 | /* decrement our usage count */ |
371 | kref_put(&dev->kref, skel_delete); | 389 | kref_put(&dev->kref, skel_delete); |
@@ -378,6 +396,7 @@ static struct usb_driver skel_driver = { | |||
378 | .probe = skel_probe, | 396 | .probe = skel_probe, |
379 | .disconnect = skel_disconnect, | 397 | .disconnect = skel_disconnect, |
380 | .id_table = skel_table, | 398 | .id_table = skel_table, |
399 | .supports_autosuspend = 1, | ||
381 | }; | 400 | }; |
382 | 401 | ||
383 | static int __init usb_skel_init(void) | 402 | static int __init usb_skel_init(void) |