diff options
author | Russell King <rmk+kernel@arm.linux.org.uk> | 2009-09-24 16:22:33 -0400 |
---|---|---|
committer | Russell King <rmk+kernel@arm.linux.org.uk> | 2009-09-24 16:22:33 -0400 |
commit | baea7b946f00a291b166ccae7fcfed6c01530cc6 (patch) | |
tree | 4aa275fbdbec9c7b9b4629e8bee2bbecd3c6a6af /drivers/usb | |
parent | ae19ffbadc1b2100285a5b5b3d0a4e0a11390904 (diff) | |
parent | 94e0fb086fc5663c38bbc0fe86d698be8314f82f (diff) |
Merge branch 'origin' into for-linus
Conflicts:
MAINTAINERS
Diffstat (limited to 'drivers/usb')
161 files changed, 12009 insertions, 2545 deletions
diff --git a/drivers/usb/Kconfig b/drivers/usb/Kconfig index dcd49f1e96d0..240750881d28 100644 --- a/drivers/usb/Kconfig +++ b/drivers/usb/Kconfig | |||
@@ -22,7 +22,6 @@ config USB_ARCH_HAS_HCD | |||
22 | default y if PCMCIA && !M32R # sl811_cs | 22 | default y if PCMCIA && !M32R # sl811_cs |
23 | default y if ARM # SL-811 | 23 | default y if ARM # SL-811 |
24 | default y if SUPERH # r8a66597-hcd | 24 | default y if SUPERH # r8a66597-hcd |
25 | default y if MICROBLAZE | ||
26 | default PCI | 25 | default PCI |
27 | 26 | ||
28 | # many non-PCI SOC chips embed OHCI | 27 | # many non-PCI SOC chips embed OHCI |
@@ -39,6 +38,7 @@ config USB_ARCH_HAS_OHCI | |||
39 | default y if ARCH_AT91 | 38 | default y if ARCH_AT91 |
40 | default y if ARCH_PNX4008 && I2C | 39 | default y if ARCH_PNX4008 && I2C |
41 | default y if MFD_TC6393XB | 40 | default y if MFD_TC6393XB |
41 | default y if ARCH_W90X900 | ||
42 | # PPC: | 42 | # PPC: |
43 | default y if STB03xxx | 43 | default y if STB03xxx |
44 | default y if PPC_MPC52xx | 44 | default y if PPC_MPC52xx |
@@ -58,6 +58,8 @@ config USB_ARCH_HAS_EHCI | |||
58 | default y if PPC_83xx | 58 | default y if PPC_83xx |
59 | default y if SOC_AU1200 | 59 | default y if SOC_AU1200 |
60 | default y if ARCH_IXP4XX | 60 | default y if ARCH_IXP4XX |
61 | default y if ARCH_W90X900 | ||
62 | default y if ARCH_AT91SAM9G45 | ||
61 | default PCI | 63 | default PCI |
62 | 64 | ||
63 | # ARM SA1111 chips have a non-PCI based "OHCI-compatible" USB host interface. | 65 | # ARM SA1111 chips have a non-PCI based "OHCI-compatible" USB host interface. |
diff --git a/drivers/usb/Makefile b/drivers/usb/Makefile index 19cb7d5480d7..be3c9b80bc9f 100644 --- a/drivers/usb/Makefile +++ b/drivers/usb/Makefile | |||
@@ -16,6 +16,7 @@ obj-$(CONFIG_USB_UHCI_HCD) += host/ | |||
16 | obj-$(CONFIG_USB_FHCI_HCD) += host/ | 16 | obj-$(CONFIG_USB_FHCI_HCD) += host/ |
17 | obj-$(CONFIG_USB_XHCI_HCD) += host/ | 17 | obj-$(CONFIG_USB_XHCI_HCD) += host/ |
18 | obj-$(CONFIG_USB_SL811_HCD) += host/ | 18 | obj-$(CONFIG_USB_SL811_HCD) += host/ |
19 | obj-$(CONFIG_USB_ISP1362_HCD) += host/ | ||
19 | obj-$(CONFIG_USB_U132_HCD) += host/ | 20 | obj-$(CONFIG_USB_U132_HCD) += host/ |
20 | obj-$(CONFIG_USB_R8A66597_HCD) += host/ | 21 | obj-$(CONFIG_USB_R8A66597_HCD) += host/ |
21 | obj-$(CONFIG_USB_HWA_HCD) += host/ | 22 | obj-$(CONFIG_USB_HWA_HCD) += host/ |
@@ -39,6 +40,7 @@ obj-$(CONFIG_USB_MICROTEK) += image/ | |||
39 | obj-$(CONFIG_USB_SERIAL) += serial/ | 40 | obj-$(CONFIG_USB_SERIAL) += serial/ |
40 | 41 | ||
41 | obj-$(CONFIG_USB) += misc/ | 42 | obj-$(CONFIG_USB) += misc/ |
43 | obj-y += early/ | ||
42 | 44 | ||
43 | obj-$(CONFIG_USB_ATM) += atm/ | 45 | obj-$(CONFIG_USB_ATM) += atm/ |
44 | obj-$(CONFIG_USB_SPEEDTOUCH) += atm/ | 46 | obj-$(CONFIG_USB_SPEEDTOUCH) += atm/ |
diff --git a/drivers/usb/class/cdc-acm.c b/drivers/usb/class/cdc-acm.c index 2bfc41ece0e1..e3861b21e776 100644 --- a/drivers/usb/class/cdc-acm.c +++ b/drivers/usb/class/cdc-acm.c | |||
@@ -59,6 +59,7 @@ | |||
59 | #include <linux/init.h> | 59 | #include <linux/init.h> |
60 | #include <linux/slab.h> | 60 | #include <linux/slab.h> |
61 | #include <linux/tty.h> | 61 | #include <linux/tty.h> |
62 | #include <linux/serial.h> | ||
62 | #include <linux/tty_driver.h> | 63 | #include <linux/tty_driver.h> |
63 | #include <linux/tty_flip.h> | 64 | #include <linux/tty_flip.h> |
64 | #include <linux/module.h> | 65 | #include <linux/module.h> |
@@ -609,6 +610,7 @@ static int acm_tty_open(struct tty_struct *tty, struct file *filp) | |||
609 | acm->throttle = 0; | 610 | acm->throttle = 0; |
610 | 611 | ||
611 | tasklet_schedule(&acm->urb_task); | 612 | tasklet_schedule(&acm->urb_task); |
613 | set_bit(ASYNCB_INITIALIZED, &acm->port.flags); | ||
612 | rv = tty_port_block_til_ready(&acm->port, tty, filp); | 614 | rv = tty_port_block_til_ready(&acm->port, tty, filp); |
613 | done: | 615 | done: |
614 | mutex_unlock(&acm->mutex); | 616 | mutex_unlock(&acm->mutex); |
@@ -858,10 +860,7 @@ static void acm_tty_set_termios(struct tty_struct *tty, | |||
858 | if (!ACM_READY(acm)) | 860 | if (!ACM_READY(acm)) |
859 | return; | 861 | return; |
860 | 862 | ||
861 | /* FIXME: Needs to support the tty_baud interface */ | 863 | newline.dwDTERate = cpu_to_le32(tty_get_baud_rate(tty)); |
862 | /* FIXME: Broken on sparc */ | ||
863 | newline.dwDTERate = cpu_to_le32p(acm_tty_speed + | ||
864 | (termios->c_cflag & CBAUD & ~CBAUDEX) + (termios->c_cflag & CBAUDEX ? 15 : 0)); | ||
865 | newline.bCharFormat = termios->c_cflag & CSTOPB ? 2 : 0; | 864 | newline.bCharFormat = termios->c_cflag & CSTOPB ? 2 : 0; |
866 | newline.bParityType = termios->c_cflag & PARENB ? | 865 | newline.bParityType = termios->c_cflag & PARENB ? |
867 | (termios->c_cflag & PARODD ? 1 : 2) + | 866 | (termios->c_cflag & PARODD ? 1 : 2) + |
diff --git a/drivers/usb/class/cdc-wdm.c b/drivers/usb/class/cdc-wdm.c index ba589d4ca8bc..3e564bfe17d1 100644 --- a/drivers/usb/class/cdc-wdm.c +++ b/drivers/usb/class/cdc-wdm.c | |||
@@ -313,8 +313,13 @@ static ssize_t wdm_write | |||
313 | r = usb_autopm_get_interface(desc->intf); | 313 | r = usb_autopm_get_interface(desc->intf); |
314 | if (r < 0) | 314 | if (r < 0) |
315 | goto outnp; | 315 | goto outnp; |
316 | r = wait_event_interruptible(desc->wait, !test_bit(WDM_IN_USE, | 316 | |
317 | &desc->flags)); | 317 | if (!file->f_flags && O_NONBLOCK) |
318 | r = wait_event_interruptible(desc->wait, !test_bit(WDM_IN_USE, | ||
319 | &desc->flags)); | ||
320 | else | ||
321 | if (test_bit(WDM_IN_USE, &desc->flags)) | ||
322 | r = -EAGAIN; | ||
318 | if (r < 0) | 323 | if (r < 0) |
319 | goto out; | 324 | goto out; |
320 | 325 | ||
@@ -377,7 +382,7 @@ outnl: | |||
377 | static ssize_t wdm_read | 382 | static ssize_t wdm_read |
378 | (struct file *file, char __user *buffer, size_t count, loff_t *ppos) | 383 | (struct file *file, char __user *buffer, size_t count, loff_t *ppos) |
379 | { | 384 | { |
380 | int rv, cntr; | 385 | int rv, cntr = 0; |
381 | int i = 0; | 386 | int i = 0; |
382 | struct wdm_device *desc = file->private_data; | 387 | struct wdm_device *desc = file->private_data; |
383 | 388 | ||
@@ -389,10 +394,23 @@ static ssize_t wdm_read | |||
389 | if (desc->length == 0) { | 394 | if (desc->length == 0) { |
390 | desc->read = 0; | 395 | desc->read = 0; |
391 | retry: | 396 | retry: |
397 | if (test_bit(WDM_DISCONNECTING, &desc->flags)) { | ||
398 | rv = -ENODEV; | ||
399 | goto err; | ||
400 | } | ||
392 | i++; | 401 | i++; |
393 | rv = wait_event_interruptible(desc->wait, | 402 | if (file->f_flags & O_NONBLOCK) { |
394 | test_bit(WDM_READ, &desc->flags)); | 403 | if (!test_bit(WDM_READ, &desc->flags)) { |
404 | rv = cntr ? cntr : -EAGAIN; | ||
405 | goto err; | ||
406 | } | ||
407 | rv = 0; | ||
408 | } else { | ||
409 | rv = wait_event_interruptible(desc->wait, | ||
410 | test_bit(WDM_READ, &desc->flags)); | ||
411 | } | ||
395 | 412 | ||
413 | /* may have happened while we slept */ | ||
396 | if (test_bit(WDM_DISCONNECTING, &desc->flags)) { | 414 | if (test_bit(WDM_DISCONNECTING, &desc->flags)) { |
397 | rv = -ENODEV; | 415 | rv = -ENODEV; |
398 | goto err; | 416 | goto err; |
@@ -448,7 +466,7 @@ retry: | |||
448 | 466 | ||
449 | err: | 467 | err: |
450 | mutex_unlock(&desc->rlock); | 468 | mutex_unlock(&desc->rlock); |
451 | if (rv < 0) | 469 | if (rv < 0 && rv != -EAGAIN) |
452 | dev_err(&desc->intf->dev, "wdm_read: exit error\n"); | 470 | dev_err(&desc->intf->dev, "wdm_read: exit error\n"); |
453 | return rv; | 471 | return rv; |
454 | } | 472 | } |
@@ -506,8 +524,6 @@ static int wdm_open(struct inode *inode, struct file *file) | |||
506 | desc = usb_get_intfdata(intf); | 524 | desc = usb_get_intfdata(intf); |
507 | if (test_bit(WDM_DISCONNECTING, &desc->flags)) | 525 | if (test_bit(WDM_DISCONNECTING, &desc->flags)) |
508 | goto out; | 526 | goto out; |
509 | |||
510 | ; | ||
511 | file->private_data = desc; | 527 | file->private_data = desc; |
512 | 528 | ||
513 | rv = usb_autopm_get_interface(desc->intf); | 529 | rv = usb_autopm_get_interface(desc->intf); |
diff --git a/drivers/usb/class/usblp.c b/drivers/usb/class/usblp.c index 26c09f0257db..9bc112ee7803 100644 --- a/drivers/usb/class/usblp.c +++ b/drivers/usb/class/usblp.c | |||
@@ -1057,14 +1057,14 @@ static const struct file_operations usblp_fops = { | |||
1057 | .release = usblp_release, | 1057 | .release = usblp_release, |
1058 | }; | 1058 | }; |
1059 | 1059 | ||
1060 | static char *usblp_nodename(struct device *dev) | 1060 | static char *usblp_devnode(struct device *dev, mode_t *mode) |
1061 | { | 1061 | { |
1062 | return kasprintf(GFP_KERNEL, "usb/%s", dev_name(dev)); | 1062 | return kasprintf(GFP_KERNEL, "usb/%s", dev_name(dev)); |
1063 | } | 1063 | } |
1064 | 1064 | ||
1065 | static struct usb_class_driver usblp_class = { | 1065 | static struct usb_class_driver usblp_class = { |
1066 | .name = "lp%d", | 1066 | .name = "lp%d", |
1067 | .nodename = usblp_nodename, | 1067 | .devnode = usblp_devnode, |
1068 | .fops = &usblp_fops, | 1068 | .fops = &usblp_fops, |
1069 | .minor_base = USBLP_MINOR_BASE, | 1069 | .minor_base = USBLP_MINOR_BASE, |
1070 | }; | 1070 | }; |
diff --git a/drivers/usb/class/usbtmc.c b/drivers/usb/class/usbtmc.c index b09a527f7341..333ee02e7b2b 100644 --- a/drivers/usb/class/usbtmc.c +++ b/drivers/usb/class/usbtmc.c | |||
@@ -57,7 +57,9 @@ MODULE_DEVICE_TABLE(usb, usbtmc_devices); | |||
57 | 57 | ||
58 | /* | 58 | /* |
59 | * This structure is the capabilities for the device | 59 | * This structure is the capabilities for the device |
60 | * See section 4.2.1.8 of the USBTMC specification for details. | 60 | * See section 4.2.1.8 of the USBTMC specification, |
61 | * and section 4.2.2 of the USBTMC usb488 subclass | ||
62 | * specification for details. | ||
61 | */ | 63 | */ |
62 | struct usbtmc_dev_capabilities { | 64 | struct usbtmc_dev_capabilities { |
63 | __u8 interface_capabilities; | 65 | __u8 interface_capabilities; |
@@ -86,6 +88,8 @@ struct usbtmc_device_data { | |||
86 | bool TermCharEnabled; | 88 | bool TermCharEnabled; |
87 | bool auto_abort; | 89 | bool auto_abort; |
88 | 90 | ||
91 | bool zombie; /* fd of disconnected device */ | ||
92 | |||
89 | struct usbtmc_dev_capabilities capabilities; | 93 | struct usbtmc_dev_capabilities capabilities; |
90 | struct kref kref; | 94 | struct kref kref; |
91 | struct mutex io_mutex; /* only one i/o function running at a time */ | 95 | struct mutex io_mutex; /* only one i/o function running at a time */ |
@@ -367,13 +371,13 @@ static ssize_t usbtmc_read(struct file *filp, char __user *buf, | |||
367 | { | 371 | { |
368 | struct usbtmc_device_data *data; | 372 | struct usbtmc_device_data *data; |
369 | struct device *dev; | 373 | struct device *dev; |
370 | unsigned long int n_characters; | 374 | u32 n_characters; |
371 | u8 *buffer; | 375 | u8 *buffer; |
372 | int actual; | 376 | int actual; |
373 | int done; | 377 | size_t done; |
374 | int remaining; | 378 | size_t remaining; |
375 | int retval; | 379 | int retval; |
376 | int this_part; | 380 | size_t this_part; |
377 | 381 | ||
378 | /* Get pointer to private data structure */ | 382 | /* Get pointer to private data structure */ |
379 | data = filp->private_data; | 383 | data = filp->private_data; |
@@ -384,6 +388,10 @@ static ssize_t usbtmc_read(struct file *filp, char __user *buf, | |||
384 | return -ENOMEM; | 388 | return -ENOMEM; |
385 | 389 | ||
386 | mutex_lock(&data->io_mutex); | 390 | mutex_lock(&data->io_mutex); |
391 | if (data->zombie) { | ||
392 | retval = -ENODEV; | ||
393 | goto exit; | ||
394 | } | ||
387 | 395 | ||
388 | remaining = count; | 396 | remaining = count; |
389 | done = 0; | 397 | done = 0; |
@@ -401,10 +409,10 @@ static ssize_t usbtmc_read(struct file *filp, char __user *buf, | |||
401 | buffer[1] = data->bTag; | 409 | buffer[1] = data->bTag; |
402 | buffer[2] = ~(data->bTag); | 410 | buffer[2] = ~(data->bTag); |
403 | buffer[3] = 0; /* Reserved */ | 411 | buffer[3] = 0; /* Reserved */ |
404 | buffer[4] = (this_part - 12 - 3) & 255; | 412 | buffer[4] = (this_part) & 255; |
405 | buffer[5] = ((this_part - 12 - 3) >> 8) & 255; | 413 | buffer[5] = ((this_part) >> 8) & 255; |
406 | buffer[6] = ((this_part - 12 - 3) >> 16) & 255; | 414 | buffer[6] = ((this_part) >> 16) & 255; |
407 | buffer[7] = ((this_part - 12 - 3) >> 24) & 255; | 415 | buffer[7] = ((this_part) >> 24) & 255; |
408 | buffer[8] = data->TermCharEnabled * 2; | 416 | buffer[8] = data->TermCharEnabled * 2; |
409 | /* Use term character? */ | 417 | /* Use term character? */ |
410 | buffer[9] = data->TermChar; | 418 | buffer[9] = data->TermChar; |
@@ -455,6 +463,22 @@ static ssize_t usbtmc_read(struct file *filp, char __user *buf, | |||
455 | (buffer[6] << 16) + | 463 | (buffer[6] << 16) + |
456 | (buffer[7] << 24); | 464 | (buffer[7] << 24); |
457 | 465 | ||
466 | /* Ensure the instrument doesn't lie about it */ | ||
467 | if(n_characters > actual - 12) { | ||
468 | dev_err(dev, "Device lies about message size: %u > %d\n", n_characters, actual - 12); | ||
469 | n_characters = actual - 12; | ||
470 | } | ||
471 | |||
472 | /* Ensure the instrument doesn't send more back than requested */ | ||
473 | if(n_characters > this_part) { | ||
474 | dev_err(dev, "Device returns more than requested: %zu > %zu\n", done + n_characters, done + this_part); | ||
475 | n_characters = this_part; | ||
476 | } | ||
477 | |||
478 | /* Bound amount of data received by amount of data requested */ | ||
479 | if (n_characters > this_part) | ||
480 | n_characters = this_part; | ||
481 | |||
458 | /* Copy buffer to user space */ | 482 | /* Copy buffer to user space */ |
459 | if (copy_to_user(buf + done, &buffer[12], n_characters)) { | 483 | if (copy_to_user(buf + done, &buffer[12], n_characters)) { |
460 | /* There must have been an addressing problem */ | 484 | /* There must have been an addressing problem */ |
@@ -463,8 +487,11 @@ static ssize_t usbtmc_read(struct file *filp, char __user *buf, | |||
463 | } | 487 | } |
464 | 488 | ||
465 | done += n_characters; | 489 | done += n_characters; |
466 | if (n_characters < USBTMC_SIZE_IOBUFFER) | 490 | /* Terminate if end-of-message bit recieved from device */ |
491 | if ((buffer[8] & 0x01) && (actual >= n_characters + 12)) | ||
467 | remaining = 0; | 492 | remaining = 0; |
493 | else | ||
494 | remaining -= n_characters; | ||
468 | } | 495 | } |
469 | 496 | ||
470 | /* Update file position value */ | 497 | /* Update file position value */ |
@@ -496,6 +523,10 @@ static ssize_t usbtmc_write(struct file *filp, const char __user *buf, | |||
496 | return -ENOMEM; | 523 | return -ENOMEM; |
497 | 524 | ||
498 | mutex_lock(&data->io_mutex); | 525 | mutex_lock(&data->io_mutex); |
526 | if (data->zombie) { | ||
527 | retval = -ENODEV; | ||
528 | goto exit; | ||
529 | } | ||
499 | 530 | ||
500 | remaining = count; | 531 | remaining = count; |
501 | done = 0; | 532 | done = 0; |
@@ -767,20 +798,21 @@ static int get_capabilities(struct usbtmc_device_data *data) | |||
767 | } | 798 | } |
768 | 799 | ||
769 | dev_dbg(dev, "GET_CAPABILITIES returned %x\n", buffer[0]); | 800 | dev_dbg(dev, "GET_CAPABILITIES returned %x\n", buffer[0]); |
770 | dev_dbg(dev, "Interface capabilities are %x\n", buffer[4]); | ||
771 | dev_dbg(dev, "Device capabilities are %x\n", buffer[5]); | ||
772 | dev_dbg(dev, "USB488 interface capabilities are %x\n", buffer[14]); | ||
773 | dev_dbg(dev, "USB488 device capabilities are %x\n", buffer[15]); | ||
774 | if (buffer[0] != USBTMC_STATUS_SUCCESS) { | 801 | if (buffer[0] != USBTMC_STATUS_SUCCESS) { |
775 | dev_err(dev, "GET_CAPABILITIES returned %x\n", buffer[0]); | 802 | dev_err(dev, "GET_CAPABILITIES returned %x\n", buffer[0]); |
776 | rv = -EPERM; | 803 | rv = -EPERM; |
777 | goto err_out; | 804 | goto err_out; |
778 | } | 805 | } |
806 | dev_dbg(dev, "Interface capabilities are %x\n", buffer[4]); | ||
807 | dev_dbg(dev, "Device capabilities are %x\n", buffer[5]); | ||
808 | dev_dbg(dev, "USB488 interface capabilities are %x\n", buffer[14]); | ||
809 | dev_dbg(dev, "USB488 device capabilities are %x\n", buffer[15]); | ||
779 | 810 | ||
780 | data->capabilities.interface_capabilities = buffer[4]; | 811 | data->capabilities.interface_capabilities = buffer[4]; |
781 | data->capabilities.device_capabilities = buffer[5]; | 812 | data->capabilities.device_capabilities = buffer[5]; |
782 | data->capabilities.usb488_interface_capabilities = buffer[14]; | 813 | data->capabilities.usb488_interface_capabilities = buffer[14]; |
783 | data->capabilities.usb488_device_capabilities = buffer[15]; | 814 | data->capabilities.usb488_device_capabilities = buffer[15]; |
815 | rv = 0; | ||
784 | 816 | ||
785 | err_out: | 817 | err_out: |
786 | kfree(buffer); | 818 | kfree(buffer); |
@@ -925,6 +957,10 @@ static long usbtmc_ioctl(struct file *file, unsigned int cmd, unsigned long arg) | |||
925 | 957 | ||
926 | data = file->private_data; | 958 | data = file->private_data; |
927 | mutex_lock(&data->io_mutex); | 959 | mutex_lock(&data->io_mutex); |
960 | if (data->zombie) { | ||
961 | retval = -ENODEV; | ||
962 | goto skip_io_on_zombie; | ||
963 | } | ||
928 | 964 | ||
929 | switch (cmd) { | 965 | switch (cmd) { |
930 | case USBTMC_IOCTL_CLEAR_OUT_HALT: | 966 | case USBTMC_IOCTL_CLEAR_OUT_HALT: |
@@ -952,6 +988,7 @@ static long usbtmc_ioctl(struct file *file, unsigned int cmd, unsigned long arg) | |||
952 | break; | 988 | break; |
953 | } | 989 | } |
954 | 990 | ||
991 | skip_io_on_zombie: | ||
955 | mutex_unlock(&data->io_mutex); | 992 | mutex_unlock(&data->io_mutex); |
956 | return retval; | 993 | return retval; |
957 | } | 994 | } |
@@ -995,6 +1032,7 @@ static int usbtmc_probe(struct usb_interface *intf, | |||
995 | usb_set_intfdata(intf, data); | 1032 | usb_set_intfdata(intf, data); |
996 | kref_init(&data->kref); | 1033 | kref_init(&data->kref); |
997 | mutex_init(&data->io_mutex); | 1034 | mutex_init(&data->io_mutex); |
1035 | data->zombie = 0; | ||
998 | 1036 | ||
999 | /* Initialize USBTMC bTag and other fields */ | 1037 | /* Initialize USBTMC bTag and other fields */ |
1000 | data->bTag = 1; | 1038 | data->bTag = 1; |
@@ -1065,14 +1103,30 @@ static void usbtmc_disconnect(struct usb_interface *intf) | |||
1065 | usb_deregister_dev(intf, &usbtmc_class); | 1103 | usb_deregister_dev(intf, &usbtmc_class); |
1066 | sysfs_remove_group(&intf->dev.kobj, &capability_attr_grp); | 1104 | sysfs_remove_group(&intf->dev.kobj, &capability_attr_grp); |
1067 | sysfs_remove_group(&intf->dev.kobj, &data_attr_grp); | 1105 | sysfs_remove_group(&intf->dev.kobj, &data_attr_grp); |
1106 | mutex_lock(&data->io_mutex); | ||
1107 | data->zombie = 1; | ||
1108 | mutex_unlock(&data->io_mutex); | ||
1068 | kref_put(&data->kref, usbtmc_delete); | 1109 | kref_put(&data->kref, usbtmc_delete); |
1069 | } | 1110 | } |
1070 | 1111 | ||
1112 | static int usbtmc_suspend (struct usb_interface *intf, pm_message_t message) | ||
1113 | { | ||
1114 | /* this driver does not have pending URBs */ | ||
1115 | return 0; | ||
1116 | } | ||
1117 | |||
1118 | static int usbtmc_resume (struct usb_interface *intf) | ||
1119 | { | ||
1120 | return 0; | ||
1121 | } | ||
1122 | |||
1071 | static struct usb_driver usbtmc_driver = { | 1123 | static struct usb_driver usbtmc_driver = { |
1072 | .name = "usbtmc", | 1124 | .name = "usbtmc", |
1073 | .id_table = usbtmc_devices, | 1125 | .id_table = usbtmc_devices, |
1074 | .probe = usbtmc_probe, | 1126 | .probe = usbtmc_probe, |
1075 | .disconnect = usbtmc_disconnect | 1127 | .disconnect = usbtmc_disconnect, |
1128 | .suspend = usbtmc_suspend, | ||
1129 | .resume = usbtmc_resume, | ||
1076 | }; | 1130 | }; |
1077 | 1131 | ||
1078 | static int __init usbtmc_init(void) | 1132 | static int __init usbtmc_init(void) |
diff --git a/drivers/usb/core/config.c b/drivers/usb/core/config.c index a16c538d0132..0d3af6a6ee49 100644 --- a/drivers/usb/core/config.c +++ b/drivers/usb/core/config.c | |||
@@ -105,7 +105,7 @@ static int usb_parse_ss_endpoint_companion(struct device *ddev, int cfgno, | |||
105 | ep->ss_ep_comp->extralen = i; | 105 | ep->ss_ep_comp->extralen = i; |
106 | buffer += i; | 106 | buffer += i; |
107 | size -= i; | 107 | size -= i; |
108 | retval = buffer - buffer_start + i; | 108 | retval = buffer - buffer_start; |
109 | if (num_skipped > 0) | 109 | if (num_skipped > 0) |
110 | dev_dbg(ddev, "skipped %d descriptor%s after %s\n", | 110 | dev_dbg(ddev, "skipped %d descriptor%s after %s\n", |
111 | num_skipped, plural(num_skipped), | 111 | num_skipped, plural(num_skipped), |
diff --git a/drivers/usb/core/devio.c b/drivers/usb/core/devio.c index 4247eccf858c..181f78c84105 100644 --- a/drivers/usb/core/devio.c +++ b/drivers/usb/core/devio.c | |||
@@ -52,6 +52,7 @@ | |||
52 | 52 | ||
53 | #include "hcd.h" /* for usbcore internals */ | 53 | #include "hcd.h" /* for usbcore internals */ |
54 | #include "usb.h" | 54 | #include "usb.h" |
55 | #include "hub.h" | ||
55 | 56 | ||
56 | #define USB_MAXBUS 64 | 57 | #define USB_MAXBUS 64 |
57 | #define USB_DEVICE_MAX USB_MAXBUS * 128 | 58 | #define USB_DEVICE_MAX USB_MAXBUS * 128 |
@@ -73,6 +74,7 @@ struct dev_state { | |||
73 | void __user *disccontext; | 74 | void __user *disccontext; |
74 | unsigned long ifclaimed; | 75 | unsigned long ifclaimed; |
75 | u32 secid; | 76 | u32 secid; |
77 | u32 disabled_bulk_eps; | ||
76 | }; | 78 | }; |
77 | 79 | ||
78 | struct async { | 80 | struct async { |
@@ -87,6 +89,8 @@ struct async { | |||
87 | struct urb *urb; | 89 | struct urb *urb; |
88 | int status; | 90 | int status; |
89 | u32 secid; | 91 | u32 secid; |
92 | u8 bulk_addr; | ||
93 | u8 bulk_status; | ||
90 | }; | 94 | }; |
91 | 95 | ||
92 | static int usbfs_snoop; | 96 | static int usbfs_snoop; |
@@ -99,11 +103,15 @@ MODULE_PARM_DESC(usbfs_snoop, "true to log all usbfs traffic"); | |||
99 | dev_info(dev , format , ## arg); \ | 103 | dev_info(dev , format , ## arg); \ |
100 | } while (0) | 104 | } while (0) |
101 | 105 | ||
102 | #define USB_DEVICE_DEV MKDEV(USB_DEVICE_MAJOR, 0) | 106 | enum snoop_when { |
107 | SUBMIT, COMPLETE | ||
108 | }; | ||
103 | 109 | ||
110 | #define USB_DEVICE_DEV MKDEV(USB_DEVICE_MAJOR, 0) | ||
104 | 111 | ||
105 | #define MAX_USBFS_BUFFER_SIZE 16384 | 112 | #define MAX_USBFS_BUFFER_SIZE 16384 |
106 | 113 | ||
114 | |||
107 | static int connected(struct dev_state *ps) | 115 | static int connected(struct dev_state *ps) |
108 | { | 116 | { |
109 | return (!list_empty(&ps->list) && | 117 | return (!list_empty(&ps->list) && |
@@ -300,24 +308,79 @@ static struct async *async_getpending(struct dev_state *ps, | |||
300 | return NULL; | 308 | return NULL; |
301 | } | 309 | } |
302 | 310 | ||
303 | static void snoop_urb(struct urb *urb, void __user *userurb) | 311 | static void snoop_urb(struct usb_device *udev, |
312 | void __user *userurb, int pipe, unsigned length, | ||
313 | int timeout_or_status, enum snoop_when when) | ||
304 | { | 314 | { |
305 | unsigned j; | 315 | static const char *types[] = {"isoc", "int", "ctrl", "bulk"}; |
306 | unsigned char *data = urb->transfer_buffer; | 316 | static const char *dirs[] = {"out", "in"}; |
317 | int ep; | ||
318 | const char *t, *d; | ||
307 | 319 | ||
308 | if (!usbfs_snoop) | 320 | if (!usbfs_snoop) |
309 | return; | 321 | return; |
310 | 322 | ||
311 | dev_info(&urb->dev->dev, "direction=%s\n", | 323 | ep = usb_pipeendpoint(pipe); |
312 | usb_urb_dir_in(urb) ? "IN" : "OUT"); | 324 | t = types[usb_pipetype(pipe)]; |
313 | dev_info(&urb->dev->dev, "userurb=%p\n", userurb); | 325 | d = dirs[!!usb_pipein(pipe)]; |
314 | dev_info(&urb->dev->dev, "transfer_buffer_length=%u\n", | 326 | |
315 | urb->transfer_buffer_length); | 327 | if (userurb) { /* Async */ |
316 | dev_info(&urb->dev->dev, "actual_length=%u\n", urb->actual_length); | 328 | if (when == SUBMIT) |
317 | dev_info(&urb->dev->dev, "data: "); | 329 | dev_info(&udev->dev, "userurb %p, ep%d %s-%s, " |
318 | for (j = 0; j < urb->transfer_buffer_length; ++j) | 330 | "length %u\n", |
319 | printk("%02x ", data[j]); | 331 | userurb, ep, t, d, length); |
320 | printk("\n"); | 332 | else |
333 | dev_info(&udev->dev, "userurb %p, ep%d %s-%s, " | ||
334 | "actual_length %u status %d\n", | ||
335 | userurb, ep, t, d, length, | ||
336 | timeout_or_status); | ||
337 | } else { | ||
338 | if (when == SUBMIT) | ||
339 | dev_info(&udev->dev, "ep%d %s-%s, length %u, " | ||
340 | "timeout %d\n", | ||
341 | ep, t, d, length, timeout_or_status); | ||
342 | else | ||
343 | dev_info(&udev->dev, "ep%d %s-%s, actual_length %u, " | ||
344 | "status %d\n", | ||
345 | ep, t, d, length, timeout_or_status); | ||
346 | } | ||
347 | } | ||
348 | |||
349 | #define AS_CONTINUATION 1 | ||
350 | #define AS_UNLINK 2 | ||
351 | |||
352 | static void cancel_bulk_urbs(struct dev_state *ps, unsigned bulk_addr) | ||
353 | __releases(ps->lock) | ||
354 | __acquires(ps->lock) | ||
355 | { | ||
356 | struct async *as; | ||
357 | |||
358 | /* Mark all the pending URBs that match bulk_addr, up to but not | ||
359 | * including the first one without AS_CONTINUATION. If such an | ||
360 | * URB is encountered then a new transfer has already started so | ||
361 | * the endpoint doesn't need to be disabled; otherwise it does. | ||
362 | */ | ||
363 | list_for_each_entry(as, &ps->async_pending, asynclist) { | ||
364 | if (as->bulk_addr == bulk_addr) { | ||
365 | if (as->bulk_status != AS_CONTINUATION) | ||
366 | goto rescan; | ||
367 | as->bulk_status = AS_UNLINK; | ||
368 | as->bulk_addr = 0; | ||
369 | } | ||
370 | } | ||
371 | ps->disabled_bulk_eps |= (1 << bulk_addr); | ||
372 | |||
373 | /* Now carefully unlink all the marked pending URBs */ | ||
374 | rescan: | ||
375 | list_for_each_entry(as, &ps->async_pending, asynclist) { | ||
376 | if (as->bulk_status == AS_UNLINK) { | ||
377 | as->bulk_status = 0; /* Only once */ | ||
378 | spin_unlock(&ps->lock); /* Allow completions */ | ||
379 | usb_unlink_urb(as->urb); | ||
380 | spin_lock(&ps->lock); | ||
381 | goto rescan; | ||
382 | } | ||
383 | } | ||
321 | } | 384 | } |
322 | 385 | ||
323 | static void async_completed(struct urb *urb) | 386 | static void async_completed(struct urb *urb) |
@@ -346,7 +409,11 @@ static void async_completed(struct urb *urb) | |||
346 | secid = as->secid; | 409 | secid = as->secid; |
347 | } | 410 | } |
348 | snoop(&urb->dev->dev, "urb complete\n"); | 411 | snoop(&urb->dev->dev, "urb complete\n"); |
349 | snoop_urb(urb, as->userurb); | 412 | snoop_urb(urb->dev, as->userurb, urb->pipe, urb->actual_length, |
413 | as->status, COMPLETE); | ||
414 | if (as->status < 0 && as->bulk_addr && as->status != -ECONNRESET && | ||
415 | as->status != -ENOENT) | ||
416 | cancel_bulk_urbs(ps, as->bulk_addr); | ||
350 | spin_unlock(&ps->lock); | 417 | spin_unlock(&ps->lock); |
351 | 418 | ||
352 | if (signr) | 419 | if (signr) |
@@ -655,6 +722,7 @@ static int usbdev_release(struct inode *inode, struct file *file) | |||
655 | struct async *as; | 722 | struct async *as; |
656 | 723 | ||
657 | usb_lock_device(dev); | 724 | usb_lock_device(dev); |
725 | usb_hub_release_all_ports(dev, ps); | ||
658 | 726 | ||
659 | /* Protect against simultaneous open */ | 727 | /* Protect against simultaneous open */ |
660 | mutex_lock(&usbfs_mutex); | 728 | mutex_lock(&usbfs_mutex); |
@@ -688,7 +756,7 @@ static int proc_control(struct dev_state *ps, void __user *arg) | |||
688 | unsigned int tmo; | 756 | unsigned int tmo; |
689 | unsigned char *tbuf; | 757 | unsigned char *tbuf; |
690 | unsigned wLength; | 758 | unsigned wLength; |
691 | int i, j, ret; | 759 | int i, pipe, ret; |
692 | 760 | ||
693 | if (copy_from_user(&ctrl, arg, sizeof(ctrl))) | 761 | if (copy_from_user(&ctrl, arg, sizeof(ctrl))) |
694 | return -EFAULT; | 762 | return -EFAULT; |
@@ -708,24 +776,17 @@ static int proc_control(struct dev_state *ps, void __user *arg) | |||
708 | free_page((unsigned long)tbuf); | 776 | free_page((unsigned long)tbuf); |
709 | return -EINVAL; | 777 | return -EINVAL; |
710 | } | 778 | } |
711 | snoop(&dev->dev, "control read: bRequest=%02x " | 779 | pipe = usb_rcvctrlpipe(dev, 0); |
712 | "bRrequestType=%02x wValue=%04x " | 780 | snoop_urb(dev, NULL, pipe, ctrl.wLength, tmo, SUBMIT); |
713 | "wIndex=%04x wLength=%04x\n", | ||
714 | ctrl.bRequest, ctrl.bRequestType, ctrl.wValue, | ||
715 | ctrl.wIndex, ctrl.wLength); | ||
716 | 781 | ||
717 | usb_unlock_device(dev); | 782 | usb_unlock_device(dev); |
718 | i = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0), ctrl.bRequest, | 783 | i = usb_control_msg(dev, pipe, ctrl.bRequest, |
719 | ctrl.bRequestType, ctrl.wValue, ctrl.wIndex, | 784 | ctrl.bRequestType, ctrl.wValue, ctrl.wIndex, |
720 | tbuf, ctrl.wLength, tmo); | 785 | tbuf, ctrl.wLength, tmo); |
721 | usb_lock_device(dev); | 786 | usb_lock_device(dev); |
787 | snoop_urb(dev, NULL, pipe, max(i, 0), min(i, 0), COMPLETE); | ||
788 | |||
722 | if ((i > 0) && ctrl.wLength) { | 789 | if ((i > 0) && ctrl.wLength) { |
723 | if (usbfs_snoop) { | ||
724 | dev_info(&dev->dev, "control read: data "); | ||
725 | for (j = 0; j < i; ++j) | ||
726 | printk("%02x ", (u8)(tbuf)[j]); | ||
727 | printk("\n"); | ||
728 | } | ||
729 | if (copy_to_user(ctrl.data, tbuf, i)) { | 790 | if (copy_to_user(ctrl.data, tbuf, i)) { |
730 | free_page((unsigned long)tbuf); | 791 | free_page((unsigned long)tbuf); |
731 | return -EFAULT; | 792 | return -EFAULT; |
@@ -738,22 +799,15 @@ static int proc_control(struct dev_state *ps, void __user *arg) | |||
738 | return -EFAULT; | 799 | return -EFAULT; |
739 | } | 800 | } |
740 | } | 801 | } |
741 | snoop(&dev->dev, "control write: bRequest=%02x " | 802 | pipe = usb_sndctrlpipe(dev, 0); |
742 | "bRrequestType=%02x wValue=%04x " | 803 | snoop_urb(dev, NULL, pipe, ctrl.wLength, tmo, SUBMIT); |
743 | "wIndex=%04x wLength=%04x\n", | 804 | |
744 | ctrl.bRequest, ctrl.bRequestType, ctrl.wValue, | ||
745 | ctrl.wIndex, ctrl.wLength); | ||
746 | if (usbfs_snoop) { | ||
747 | dev_info(&dev->dev, "control write: data: "); | ||
748 | for (j = 0; j < ctrl.wLength; ++j) | ||
749 | printk("%02x ", (unsigned char)(tbuf)[j]); | ||
750 | printk("\n"); | ||
751 | } | ||
752 | usb_unlock_device(dev); | 805 | usb_unlock_device(dev); |
753 | i = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), ctrl.bRequest, | 806 | i = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), ctrl.bRequest, |
754 | ctrl.bRequestType, ctrl.wValue, ctrl.wIndex, | 807 | ctrl.bRequestType, ctrl.wValue, ctrl.wIndex, |
755 | tbuf, ctrl.wLength, tmo); | 808 | tbuf, ctrl.wLength, tmo); |
756 | usb_lock_device(dev); | 809 | usb_lock_device(dev); |
810 | snoop_urb(dev, NULL, pipe, max(i, 0), min(i, 0), COMPLETE); | ||
757 | } | 811 | } |
758 | free_page((unsigned long)tbuf); | 812 | free_page((unsigned long)tbuf); |
759 | if (i < 0 && i != -EPIPE) { | 813 | if (i < 0 && i != -EPIPE) { |
@@ -772,7 +826,7 @@ static int proc_bulk(struct dev_state *ps, void __user *arg) | |||
772 | unsigned int tmo, len1, pipe; | 826 | unsigned int tmo, len1, pipe; |
773 | int len2; | 827 | int len2; |
774 | unsigned char *tbuf; | 828 | unsigned char *tbuf; |
775 | int i, j, ret; | 829 | int i, ret; |
776 | 830 | ||
777 | if (copy_from_user(&bulk, arg, sizeof(bulk))) | 831 | if (copy_from_user(&bulk, arg, sizeof(bulk))) |
778 | return -EFAULT; | 832 | return -EFAULT; |
@@ -799,18 +853,14 @@ static int proc_bulk(struct dev_state *ps, void __user *arg) | |||
799 | kfree(tbuf); | 853 | kfree(tbuf); |
800 | return -EINVAL; | 854 | return -EINVAL; |
801 | } | 855 | } |
802 | snoop(&dev->dev, "bulk read: len=0x%02x timeout=%04d\n", | 856 | snoop_urb(dev, NULL, pipe, len1, tmo, SUBMIT); |
803 | bulk.len, bulk.timeout); | 857 | |
804 | usb_unlock_device(dev); | 858 | usb_unlock_device(dev); |
805 | i = usb_bulk_msg(dev, pipe, tbuf, len1, &len2, tmo); | 859 | i = usb_bulk_msg(dev, pipe, tbuf, len1, &len2, tmo); |
806 | usb_lock_device(dev); | 860 | usb_lock_device(dev); |
861 | snoop_urb(dev, NULL, pipe, len2, i, COMPLETE); | ||
862 | |||
807 | if (!i && len2) { | 863 | if (!i && len2) { |
808 | if (usbfs_snoop) { | ||
809 | dev_info(&dev->dev, "bulk read: data "); | ||
810 | for (j = 0; j < len2; ++j) | ||
811 | printk("%02x ", (u8)(tbuf)[j]); | ||
812 | printk("\n"); | ||
813 | } | ||
814 | if (copy_to_user(bulk.data, tbuf, len2)) { | 864 | if (copy_to_user(bulk.data, tbuf, len2)) { |
815 | kfree(tbuf); | 865 | kfree(tbuf); |
816 | return -EFAULT; | 866 | return -EFAULT; |
@@ -823,17 +873,12 @@ static int proc_bulk(struct dev_state *ps, void __user *arg) | |||
823 | return -EFAULT; | 873 | return -EFAULT; |
824 | } | 874 | } |
825 | } | 875 | } |
826 | snoop(&dev->dev, "bulk write: len=0x%02x timeout=%04d\n", | 876 | snoop_urb(dev, NULL, pipe, len1, tmo, SUBMIT); |
827 | bulk.len, bulk.timeout); | 877 | |
828 | if (usbfs_snoop) { | ||
829 | dev_info(&dev->dev, "bulk write: data: "); | ||
830 | for (j = 0; j < len1; ++j) | ||
831 | printk("%02x ", (unsigned char)(tbuf)[j]); | ||
832 | printk("\n"); | ||
833 | } | ||
834 | usb_unlock_device(dev); | 878 | usb_unlock_device(dev); |
835 | i = usb_bulk_msg(dev, pipe, tbuf, len1, &len2, tmo); | 879 | i = usb_bulk_msg(dev, pipe, tbuf, len1, &len2, tmo); |
836 | usb_lock_device(dev); | 880 | usb_lock_device(dev); |
881 | snoop_urb(dev, NULL, pipe, len2, i, COMPLETE); | ||
837 | } | 882 | } |
838 | kfree(tbuf); | 883 | kfree(tbuf); |
839 | if (i < 0) | 884 | if (i < 0) |
@@ -991,6 +1036,7 @@ static int proc_do_submiturb(struct dev_state *ps, struct usbdevfs_urb *uurb, | |||
991 | 1036 | ||
992 | if (uurb->flags & ~(USBDEVFS_URB_ISO_ASAP | | 1037 | if (uurb->flags & ~(USBDEVFS_URB_ISO_ASAP | |
993 | USBDEVFS_URB_SHORT_NOT_OK | | 1038 | USBDEVFS_URB_SHORT_NOT_OK | |
1039 | USBDEVFS_URB_BULK_CONTINUATION | | ||
994 | USBDEVFS_URB_NO_FSBR | | 1040 | USBDEVFS_URB_NO_FSBR | |
995 | USBDEVFS_URB_ZERO_PACKET | | 1041 | USBDEVFS_URB_ZERO_PACKET | |
996 | USBDEVFS_URB_NO_INTERRUPT)) | 1042 | USBDEVFS_URB_NO_INTERRUPT)) |
@@ -1051,13 +1097,6 @@ static int proc_do_submiturb(struct dev_state *ps, struct usbdevfs_urb *uurb, | |||
1051 | is_in = 0; | 1097 | is_in = 0; |
1052 | uurb->endpoint &= ~USB_DIR_IN; | 1098 | uurb->endpoint &= ~USB_DIR_IN; |
1053 | } | 1099 | } |
1054 | snoop(&ps->dev->dev, "control urb: bRequest=%02x " | ||
1055 | "bRrequestType=%02x wValue=%04x " | ||
1056 | "wIndex=%04x wLength=%04x\n", | ||
1057 | dr->bRequest, dr->bRequestType, | ||
1058 | __le16_to_cpup(&dr->wValue), | ||
1059 | __le16_to_cpup(&dr->wIndex), | ||
1060 | __le16_to_cpup(&dr->wLength)); | ||
1061 | break; | 1100 | break; |
1062 | 1101 | ||
1063 | case USBDEVFS_URB_TYPE_BULK: | 1102 | case USBDEVFS_URB_TYPE_BULK: |
@@ -1070,7 +1109,6 @@ static int proc_do_submiturb(struct dev_state *ps, struct usbdevfs_urb *uurb, | |||
1070 | uurb->number_of_packets = 0; | 1109 | uurb->number_of_packets = 0; |
1071 | if (uurb->buffer_length > MAX_USBFS_BUFFER_SIZE) | 1110 | if (uurb->buffer_length > MAX_USBFS_BUFFER_SIZE) |
1072 | return -EINVAL; | 1111 | return -EINVAL; |
1073 | snoop(&ps->dev->dev, "bulk urb\n"); | ||
1074 | break; | 1112 | break; |
1075 | 1113 | ||
1076 | case USBDEVFS_URB_TYPE_ISO: | 1114 | case USBDEVFS_URB_TYPE_ISO: |
@@ -1097,12 +1135,12 @@ static int proc_do_submiturb(struct dev_state *ps, struct usbdevfs_urb *uurb, | |||
1097 | } | 1135 | } |
1098 | totlen += isopkt[u].length; | 1136 | totlen += isopkt[u].length; |
1099 | } | 1137 | } |
1100 | if (totlen > 32768) { | 1138 | /* 3072 * 64 microframes */ |
1139 | if (totlen > 196608) { | ||
1101 | kfree(isopkt); | 1140 | kfree(isopkt); |
1102 | return -EINVAL; | 1141 | return -EINVAL; |
1103 | } | 1142 | } |
1104 | uurb->buffer_length = totlen; | 1143 | uurb->buffer_length = totlen; |
1105 | snoop(&ps->dev->dev, "iso urb\n"); | ||
1106 | break; | 1144 | break; |
1107 | 1145 | ||
1108 | case USBDEVFS_URB_TYPE_INTERRUPT: | 1146 | case USBDEVFS_URB_TYPE_INTERRUPT: |
@@ -1111,7 +1149,6 @@ static int proc_do_submiturb(struct dev_state *ps, struct usbdevfs_urb *uurb, | |||
1111 | return -EINVAL; | 1149 | return -EINVAL; |
1112 | if (uurb->buffer_length > MAX_USBFS_BUFFER_SIZE) | 1150 | if (uurb->buffer_length > MAX_USBFS_BUFFER_SIZE) |
1113 | return -EINVAL; | 1151 | return -EINVAL; |
1114 | snoop(&ps->dev->dev, "interrupt urb\n"); | ||
1115 | break; | 1152 | break; |
1116 | 1153 | ||
1117 | default: | 1154 | default: |
@@ -1198,11 +1235,46 @@ static int proc_do_submiturb(struct dev_state *ps, struct usbdevfs_urb *uurb, | |||
1198 | return -EFAULT; | 1235 | return -EFAULT; |
1199 | } | 1236 | } |
1200 | } | 1237 | } |
1201 | snoop_urb(as->urb, as->userurb); | 1238 | snoop_urb(ps->dev, as->userurb, as->urb->pipe, |
1239 | as->urb->transfer_buffer_length, 0, SUBMIT); | ||
1202 | async_newpending(as); | 1240 | async_newpending(as); |
1203 | if ((ret = usb_submit_urb(as->urb, GFP_KERNEL))) { | 1241 | |
1242 | if (usb_endpoint_xfer_bulk(&ep->desc)) { | ||
1243 | spin_lock_irq(&ps->lock); | ||
1244 | |||
1245 | /* Not exactly the endpoint address; the direction bit is | ||
1246 | * shifted to the 0x10 position so that the value will be | ||
1247 | * between 0 and 31. | ||
1248 | */ | ||
1249 | as->bulk_addr = usb_endpoint_num(&ep->desc) | | ||
1250 | ((ep->desc.bEndpointAddress & USB_ENDPOINT_DIR_MASK) | ||
1251 | >> 3); | ||
1252 | |||
1253 | /* If this bulk URB is the start of a new transfer, re-enable | ||
1254 | * the endpoint. Otherwise mark it as a continuation URB. | ||
1255 | */ | ||
1256 | if (uurb->flags & USBDEVFS_URB_BULK_CONTINUATION) | ||
1257 | as->bulk_status = AS_CONTINUATION; | ||
1258 | else | ||
1259 | ps->disabled_bulk_eps &= ~(1 << as->bulk_addr); | ||
1260 | |||
1261 | /* Don't accept continuation URBs if the endpoint is | ||
1262 | * disabled because of an earlier error. | ||
1263 | */ | ||
1264 | if (ps->disabled_bulk_eps & (1 << as->bulk_addr)) | ||
1265 | ret = -EREMOTEIO; | ||
1266 | else | ||
1267 | ret = usb_submit_urb(as->urb, GFP_ATOMIC); | ||
1268 | spin_unlock_irq(&ps->lock); | ||
1269 | } else { | ||
1270 | ret = usb_submit_urb(as->urb, GFP_KERNEL); | ||
1271 | } | ||
1272 | |||
1273 | if (ret) { | ||
1204 | dev_printk(KERN_DEBUG, &ps->dev->dev, | 1274 | dev_printk(KERN_DEBUG, &ps->dev->dev, |
1205 | "usbfs: usb_submit_urb returned %d\n", ret); | 1275 | "usbfs: usb_submit_urb returned %d\n", ret); |
1276 | snoop_urb(ps->dev, as->userurb, as->urb->pipe, | ||
1277 | 0, ret, COMPLETE); | ||
1206 | async_removepending(as); | 1278 | async_removepending(as); |
1207 | free_async(as); | 1279 | free_async(as); |
1208 | return ret; | 1280 | return ret; |
@@ -1548,6 +1620,29 @@ static int proc_ioctl_compat(struct dev_state *ps, compat_uptr_t arg) | |||
1548 | } | 1620 | } |
1549 | #endif | 1621 | #endif |
1550 | 1622 | ||
1623 | static int proc_claim_port(struct dev_state *ps, void __user *arg) | ||
1624 | { | ||
1625 | unsigned portnum; | ||
1626 | int rc; | ||
1627 | |||
1628 | if (get_user(portnum, (unsigned __user *) arg)) | ||
1629 | return -EFAULT; | ||
1630 | rc = usb_hub_claim_port(ps->dev, portnum, ps); | ||
1631 | if (rc == 0) | ||
1632 | snoop(&ps->dev->dev, "port %d claimed by process %d: %s\n", | ||
1633 | portnum, task_pid_nr(current), current->comm); | ||
1634 | return rc; | ||
1635 | } | ||
1636 | |||
1637 | static int proc_release_port(struct dev_state *ps, void __user *arg) | ||
1638 | { | ||
1639 | unsigned portnum; | ||
1640 | |||
1641 | if (get_user(portnum, (unsigned __user *) arg)) | ||
1642 | return -EFAULT; | ||
1643 | return usb_hub_release_port(ps->dev, portnum, ps); | ||
1644 | } | ||
1645 | |||
1551 | /* | 1646 | /* |
1552 | * NOTE: All requests here that have interface numbers as parameters | 1647 | * NOTE: All requests here that have interface numbers as parameters |
1553 | * are assuming that somehow the configuration has been prevented from | 1648 | * are assuming that somehow the configuration has been prevented from |
@@ -1645,7 +1740,7 @@ static int usbdev_ioctl(struct inode *inode, struct file *file, | |||
1645 | break; | 1740 | break; |
1646 | 1741 | ||
1647 | case USBDEVFS_REAPURBNDELAY32: | 1742 | case USBDEVFS_REAPURBNDELAY32: |
1648 | snoop(&dev->dev, "%s: REAPURBDELAY32\n", __func__); | 1743 | snoop(&dev->dev, "%s: REAPURBNDELAY32\n", __func__); |
1649 | ret = proc_reapurbnonblock_compat(ps, p); | 1744 | ret = proc_reapurbnonblock_compat(ps, p); |
1650 | break; | 1745 | break; |
1651 | 1746 | ||
@@ -1666,7 +1761,7 @@ static int usbdev_ioctl(struct inode *inode, struct file *file, | |||
1666 | break; | 1761 | break; |
1667 | 1762 | ||
1668 | case USBDEVFS_REAPURBNDELAY: | 1763 | case USBDEVFS_REAPURBNDELAY: |
1669 | snoop(&dev->dev, "%s: REAPURBDELAY\n", __func__); | 1764 | snoop(&dev->dev, "%s: REAPURBNDELAY\n", __func__); |
1670 | ret = proc_reapurbnonblock(ps, p); | 1765 | ret = proc_reapurbnonblock(ps, p); |
1671 | break; | 1766 | break; |
1672 | 1767 | ||
@@ -1689,6 +1784,16 @@ static int usbdev_ioctl(struct inode *inode, struct file *file, | |||
1689 | snoop(&dev->dev, "%s: IOCTL\n", __func__); | 1784 | snoop(&dev->dev, "%s: IOCTL\n", __func__); |
1690 | ret = proc_ioctl_default(ps, p); | 1785 | ret = proc_ioctl_default(ps, p); |
1691 | break; | 1786 | break; |
1787 | |||
1788 | case USBDEVFS_CLAIM_PORT: | ||
1789 | snoop(&dev->dev, "%s: CLAIM_PORT\n", __func__); | ||
1790 | ret = proc_claim_port(ps, p); | ||
1791 | break; | ||
1792 | |||
1793 | case USBDEVFS_RELEASE_PORT: | ||
1794 | snoop(&dev->dev, "%s: RELEASE_PORT\n", __func__); | ||
1795 | ret = proc_release_port(ps, p); | ||
1796 | break; | ||
1692 | } | 1797 | } |
1693 | usb_unlock_device(dev); | 1798 | usb_unlock_device(dev); |
1694 | if (ret >= 0) | 1799 | if (ret >= 0) |
diff --git a/drivers/usb/core/driver.c b/drivers/usb/core/driver.c index 69e5773abfce..4f864472c5c4 100644 --- a/drivers/usb/core/driver.c +++ b/drivers/usb/core/driver.c | |||
@@ -207,6 +207,9 @@ static int usb_probe_interface(struct device *dev) | |||
207 | 207 | ||
208 | intf->needs_binding = 0; | 208 | intf->needs_binding = 0; |
209 | 209 | ||
210 | if (usb_device_is_owned(udev)) | ||
211 | return -ENODEV; | ||
212 | |||
210 | if (udev->authorized == 0) { | 213 | if (udev->authorized == 0) { |
211 | dev_err(&intf->dev, "Device is not authorized for usage\n"); | 214 | dev_err(&intf->dev, "Device is not authorized for usage\n"); |
212 | return -ENODEV; | 215 | return -ENODEV; |
@@ -232,28 +235,35 @@ static int usb_probe_interface(struct device *dev) | |||
232 | /* The interface should always appear to be in use | 235 | /* The interface should always appear to be in use |
233 | * unless the driver suports autosuspend. | 236 | * unless the driver suports autosuspend. |
234 | */ | 237 | */ |
235 | intf->pm_usage_cnt = !(driver->supports_autosuspend); | 238 | atomic_set(&intf->pm_usage_cnt, !driver->supports_autosuspend); |
236 | 239 | ||
237 | /* Carry out a deferred switch to altsetting 0 */ | 240 | /* Carry out a deferred switch to altsetting 0 */ |
238 | if (intf->needs_altsetting0) { | 241 | if (intf->needs_altsetting0) { |
239 | usb_set_interface(udev, intf->altsetting[0]. | 242 | error = usb_set_interface(udev, intf->altsetting[0]. |
240 | desc.bInterfaceNumber, 0); | 243 | desc.bInterfaceNumber, 0); |
244 | if (error < 0) | ||
245 | goto err; | ||
246 | |||
241 | intf->needs_altsetting0 = 0; | 247 | intf->needs_altsetting0 = 0; |
242 | } | 248 | } |
243 | 249 | ||
244 | error = driver->probe(intf, id); | 250 | error = driver->probe(intf, id); |
245 | if (error) { | 251 | if (error) |
246 | mark_quiesced(intf); | 252 | goto err; |
247 | intf->needs_remote_wakeup = 0; | ||
248 | intf->condition = USB_INTERFACE_UNBOUND; | ||
249 | usb_cancel_queued_reset(intf); | ||
250 | } else | ||
251 | intf->condition = USB_INTERFACE_BOUND; | ||
252 | 253 | ||
254 | intf->condition = USB_INTERFACE_BOUND; | ||
253 | usb_autosuspend_device(udev); | 255 | usb_autosuspend_device(udev); |
254 | } | 256 | } |
255 | 257 | ||
256 | return error; | 258 | return error; |
259 | |||
260 | err: | ||
261 | mark_quiesced(intf); | ||
262 | intf->needs_remote_wakeup = 0; | ||
263 | intf->condition = USB_INTERFACE_UNBOUND; | ||
264 | usb_cancel_queued_reset(intf); | ||
265 | usb_autosuspend_device(udev); | ||
266 | return error; | ||
257 | } | 267 | } |
258 | 268 | ||
259 | /* called from driver core with dev locked */ | 269 | /* called from driver core with dev locked */ |
@@ -262,7 +272,7 @@ static int usb_unbind_interface(struct device *dev) | |||
262 | struct usb_driver *driver = to_usb_driver(dev->driver); | 272 | struct usb_driver *driver = to_usb_driver(dev->driver); |
263 | struct usb_interface *intf = to_usb_interface(dev); | 273 | struct usb_interface *intf = to_usb_interface(dev); |
264 | struct usb_device *udev; | 274 | struct usb_device *udev; |
265 | int error; | 275 | int error, r; |
266 | 276 | ||
267 | intf->condition = USB_INTERFACE_UNBINDING; | 277 | intf->condition = USB_INTERFACE_UNBINDING; |
268 | 278 | ||
@@ -290,11 +300,14 @@ static int usb_unbind_interface(struct device *dev) | |||
290 | * Just re-enable it without affecting the endpoint toggles. | 300 | * Just re-enable it without affecting the endpoint toggles. |
291 | */ | 301 | */ |
292 | usb_enable_interface(udev, intf, false); | 302 | usb_enable_interface(udev, intf, false); |
293 | } else if (!error && intf->dev.power.status == DPM_ON) | 303 | } else if (!error && intf->dev.power.status == DPM_ON) { |
294 | usb_set_interface(udev, intf->altsetting[0]. | 304 | r = usb_set_interface(udev, intf->altsetting[0]. |
295 | desc.bInterfaceNumber, 0); | 305 | desc.bInterfaceNumber, 0); |
296 | else | 306 | if (r < 0) |
307 | intf->needs_altsetting0 = 1; | ||
308 | } else { | ||
297 | intf->needs_altsetting0 = 1; | 309 | intf->needs_altsetting0 = 1; |
310 | } | ||
298 | usb_set_intfdata(intf, NULL); | 311 | usb_set_intfdata(intf, NULL); |
299 | 312 | ||
300 | intf->condition = USB_INTERFACE_UNBOUND; | 313 | intf->condition = USB_INTERFACE_UNBOUND; |
@@ -344,7 +357,7 @@ int usb_driver_claim_interface(struct usb_driver *driver, | |||
344 | usb_pm_lock(udev); | 357 | usb_pm_lock(udev); |
345 | iface->condition = USB_INTERFACE_BOUND; | 358 | iface->condition = USB_INTERFACE_BOUND; |
346 | mark_active(iface); | 359 | mark_active(iface); |
347 | iface->pm_usage_cnt = !(driver->supports_autosuspend); | 360 | atomic_set(&iface->pm_usage_cnt, !driver->supports_autosuspend); |
348 | usb_pm_unlock(udev); | 361 | usb_pm_unlock(udev); |
349 | 362 | ||
350 | /* if interface was already added, bind now; else let | 363 | /* if interface was already added, bind now; else let |
@@ -1065,7 +1078,7 @@ static int autosuspend_check(struct usb_device *udev, int reschedule) | |||
1065 | intf = udev->actconfig->interface[i]; | 1078 | intf = udev->actconfig->interface[i]; |
1066 | if (!is_active(intf)) | 1079 | if (!is_active(intf)) |
1067 | continue; | 1080 | continue; |
1068 | if (intf->pm_usage_cnt > 0) | 1081 | if (atomic_read(&intf->pm_usage_cnt) > 0) |
1069 | return -EBUSY; | 1082 | return -EBUSY; |
1070 | if (intf->needs_remote_wakeup && | 1083 | if (intf->needs_remote_wakeup && |
1071 | !udev->do_remote_wakeup) { | 1084 | !udev->do_remote_wakeup) { |
@@ -1461,17 +1474,19 @@ static int usb_autopm_do_interface(struct usb_interface *intf, | |||
1461 | status = -ENODEV; | 1474 | status = -ENODEV; |
1462 | else { | 1475 | else { |
1463 | udev->auto_pm = 1; | 1476 | udev->auto_pm = 1; |
1464 | intf->pm_usage_cnt += inc_usage_cnt; | 1477 | atomic_add(inc_usage_cnt, &intf->pm_usage_cnt); |
1465 | udev->last_busy = jiffies; | 1478 | udev->last_busy = jiffies; |
1466 | if (inc_usage_cnt >= 0 && intf->pm_usage_cnt > 0) { | 1479 | if (inc_usage_cnt >= 0 && |
1480 | atomic_read(&intf->pm_usage_cnt) > 0) { | ||
1467 | if (udev->state == USB_STATE_SUSPENDED) | 1481 | if (udev->state == USB_STATE_SUSPENDED) |
1468 | status = usb_resume_both(udev, | 1482 | status = usb_resume_both(udev, |
1469 | PMSG_AUTO_RESUME); | 1483 | PMSG_AUTO_RESUME); |
1470 | if (status != 0) | 1484 | if (status != 0) |
1471 | intf->pm_usage_cnt -= inc_usage_cnt; | 1485 | atomic_sub(inc_usage_cnt, &intf->pm_usage_cnt); |
1472 | else | 1486 | else |
1473 | udev->last_busy = jiffies; | 1487 | udev->last_busy = jiffies; |
1474 | } else if (inc_usage_cnt <= 0 && intf->pm_usage_cnt <= 0) { | 1488 | } else if (inc_usage_cnt <= 0 && |
1489 | atomic_read(&intf->pm_usage_cnt) <= 0) { | ||
1475 | status = usb_suspend_both(udev, PMSG_AUTO_SUSPEND); | 1490 | status = usb_suspend_both(udev, PMSG_AUTO_SUSPEND); |
1476 | } | 1491 | } |
1477 | } | 1492 | } |
@@ -1516,7 +1531,7 @@ void usb_autopm_put_interface(struct usb_interface *intf) | |||
1516 | 1531 | ||
1517 | status = usb_autopm_do_interface(intf, -1); | 1532 | status = usb_autopm_do_interface(intf, -1); |
1518 | dev_vdbg(&intf->dev, "%s: status %d cnt %d\n", | 1533 | dev_vdbg(&intf->dev, "%s: status %d cnt %d\n", |
1519 | __func__, status, intf->pm_usage_cnt); | 1534 | __func__, status, atomic_read(&intf->pm_usage_cnt)); |
1520 | } | 1535 | } |
1521 | EXPORT_SYMBOL_GPL(usb_autopm_put_interface); | 1536 | EXPORT_SYMBOL_GPL(usb_autopm_put_interface); |
1522 | 1537 | ||
@@ -1544,10 +1559,10 @@ void usb_autopm_put_interface_async(struct usb_interface *intf) | |||
1544 | status = -ENODEV; | 1559 | status = -ENODEV; |
1545 | } else { | 1560 | } else { |
1546 | udev->last_busy = jiffies; | 1561 | udev->last_busy = jiffies; |
1547 | --intf->pm_usage_cnt; | 1562 | atomic_dec(&intf->pm_usage_cnt); |
1548 | if (udev->autosuspend_disabled || udev->autosuspend_delay < 0) | 1563 | if (udev->autosuspend_disabled || udev->autosuspend_delay < 0) |
1549 | status = -EPERM; | 1564 | status = -EPERM; |
1550 | else if (intf->pm_usage_cnt <= 0 && | 1565 | else if (atomic_read(&intf->pm_usage_cnt) <= 0 && |
1551 | !timer_pending(&udev->autosuspend.timer)) { | 1566 | !timer_pending(&udev->autosuspend.timer)) { |
1552 | queue_delayed_work(ksuspend_usb_wq, &udev->autosuspend, | 1567 | queue_delayed_work(ksuspend_usb_wq, &udev->autosuspend, |
1553 | round_jiffies_up_relative( | 1568 | round_jiffies_up_relative( |
@@ -1555,7 +1570,7 @@ void usb_autopm_put_interface_async(struct usb_interface *intf) | |||
1555 | } | 1570 | } |
1556 | } | 1571 | } |
1557 | dev_vdbg(&intf->dev, "%s: status %d cnt %d\n", | 1572 | dev_vdbg(&intf->dev, "%s: status %d cnt %d\n", |
1558 | __func__, status, intf->pm_usage_cnt); | 1573 | __func__, status, atomic_read(&intf->pm_usage_cnt)); |
1559 | } | 1574 | } |
1560 | EXPORT_SYMBOL_GPL(usb_autopm_put_interface_async); | 1575 | EXPORT_SYMBOL_GPL(usb_autopm_put_interface_async); |
1561 | 1576 | ||
@@ -1599,7 +1614,7 @@ int usb_autopm_get_interface(struct usb_interface *intf) | |||
1599 | 1614 | ||
1600 | status = usb_autopm_do_interface(intf, 1); | 1615 | status = usb_autopm_do_interface(intf, 1); |
1601 | dev_vdbg(&intf->dev, "%s: status %d cnt %d\n", | 1616 | dev_vdbg(&intf->dev, "%s: status %d cnt %d\n", |
1602 | __func__, status, intf->pm_usage_cnt); | 1617 | __func__, status, atomic_read(&intf->pm_usage_cnt)); |
1603 | return status; | 1618 | return status; |
1604 | } | 1619 | } |
1605 | EXPORT_SYMBOL_GPL(usb_autopm_get_interface); | 1620 | EXPORT_SYMBOL_GPL(usb_autopm_get_interface); |
@@ -1627,10 +1642,14 @@ int usb_autopm_get_interface_async(struct usb_interface *intf) | |||
1627 | status = -ENODEV; | 1642 | status = -ENODEV; |
1628 | else if (udev->autoresume_disabled) | 1643 | else if (udev->autoresume_disabled) |
1629 | status = -EPERM; | 1644 | status = -EPERM; |
1630 | else if (++intf->pm_usage_cnt > 0 && udev->state == USB_STATE_SUSPENDED) | 1645 | else { |
1631 | queue_work(ksuspend_usb_wq, &udev->autoresume); | 1646 | atomic_inc(&intf->pm_usage_cnt); |
1647 | if (atomic_read(&intf->pm_usage_cnt) > 0 && | ||
1648 | udev->state == USB_STATE_SUSPENDED) | ||
1649 | queue_work(ksuspend_usb_wq, &udev->autoresume); | ||
1650 | } | ||
1632 | dev_vdbg(&intf->dev, "%s: status %d cnt %d\n", | 1651 | dev_vdbg(&intf->dev, "%s: status %d cnt %d\n", |
1633 | __func__, status, intf->pm_usage_cnt); | 1652 | __func__, status, atomic_read(&intf->pm_usage_cnt)); |
1634 | return status; | 1653 | return status; |
1635 | } | 1654 | } |
1636 | EXPORT_SYMBOL_GPL(usb_autopm_get_interface_async); | 1655 | EXPORT_SYMBOL_GPL(usb_autopm_get_interface_async); |
@@ -1652,7 +1671,7 @@ int usb_autopm_set_interface(struct usb_interface *intf) | |||
1652 | 1671 | ||
1653 | status = usb_autopm_do_interface(intf, 0); | 1672 | status = usb_autopm_do_interface(intf, 0); |
1654 | dev_vdbg(&intf->dev, "%s: status %d cnt %d\n", | 1673 | dev_vdbg(&intf->dev, "%s: status %d cnt %d\n", |
1655 | __func__, status, intf->pm_usage_cnt); | 1674 | __func__, status, atomic_read(&intf->pm_usage_cnt)); |
1656 | return status; | 1675 | return status; |
1657 | } | 1676 | } |
1658 | EXPORT_SYMBOL_GPL(usb_autopm_set_interface); | 1677 | EXPORT_SYMBOL_GPL(usb_autopm_set_interface); |
diff --git a/drivers/usb/core/file.c b/drivers/usb/core/file.c index 5cef88929b3e..222ee07ea680 100644 --- a/drivers/usb/core/file.c +++ b/drivers/usb/core/file.c | |||
@@ -67,14 +67,14 @@ static struct usb_class { | |||
67 | struct class *class; | 67 | struct class *class; |
68 | } *usb_class; | 68 | } *usb_class; |
69 | 69 | ||
70 | static char *usb_nodename(struct device *dev) | 70 | static char *usb_devnode(struct device *dev, mode_t *mode) |
71 | { | 71 | { |
72 | struct usb_class_driver *drv; | 72 | struct usb_class_driver *drv; |
73 | 73 | ||
74 | drv = dev_get_drvdata(dev); | 74 | drv = dev_get_drvdata(dev); |
75 | if (!drv || !drv->nodename) | 75 | if (!drv || !drv->devnode) |
76 | return NULL; | 76 | return NULL; |
77 | return drv->nodename(dev); | 77 | return drv->devnode(dev, mode); |
78 | } | 78 | } |
79 | 79 | ||
80 | static int init_usb_class(void) | 80 | static int init_usb_class(void) |
@@ -100,7 +100,7 @@ static int init_usb_class(void) | |||
100 | kfree(usb_class); | 100 | kfree(usb_class); |
101 | usb_class = NULL; | 101 | usb_class = NULL; |
102 | } | 102 | } |
103 | usb_class->class->nodename = usb_nodename; | 103 | usb_class->class->devnode = usb_devnode; |
104 | 104 | ||
105 | exit: | 105 | exit: |
106 | return result; | 106 | return result; |
diff --git a/drivers/usb/core/generic.c b/drivers/usb/core/generic.c index 30ecac3af15a..05e6d313961e 100644 --- a/drivers/usb/core/generic.c +++ b/drivers/usb/core/generic.c | |||
@@ -158,7 +158,9 @@ static int generic_probe(struct usb_device *udev) | |||
158 | /* Choose and set the configuration. This registers the interfaces | 158 | /* Choose and set the configuration. This registers the interfaces |
159 | * with the driver core and lets interface drivers bind to them. | 159 | * with the driver core and lets interface drivers bind to them. |
160 | */ | 160 | */ |
161 | if (udev->authorized == 0) | 161 | if (usb_device_is_owned(udev)) |
162 | ; /* Don't configure if the device is owned */ | ||
163 | else if (udev->authorized == 0) | ||
162 | dev_err(&udev->dev, "Device is not authorized for usage\n"); | 164 | dev_err(&udev->dev, "Device is not authorized for usage\n"); |
163 | else { | 165 | else { |
164 | c = usb_choose_configuration(udev); | 166 | c = usb_choose_configuration(udev); |
diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c index 95ccfa0b9fc5..34de475f016e 100644 --- a/drivers/usb/core/hcd.c +++ b/drivers/usb/core/hcd.c | |||
@@ -337,72 +337,89 @@ static const u8 ss_rh_config_descriptor[] = { | |||
337 | 337 | ||
338 | /*-------------------------------------------------------------------------*/ | 338 | /*-------------------------------------------------------------------------*/ |
339 | 339 | ||
340 | /* | 340 | /** |
341 | * helper routine for returning string descriptors in UTF-16LE | 341 | * ascii2desc() - Helper routine for producing UTF-16LE string descriptors |
342 | * input can actually be ISO-8859-1; ASCII is its 7-bit subset | 342 | * @s: Null-terminated ASCII (actually ISO-8859-1) string |
343 | * @buf: Buffer for USB string descriptor (header + UTF-16LE) | ||
344 | * @len: Length (in bytes; may be odd) of descriptor buffer. | ||
345 | * | ||
346 | * The return value is the number of bytes filled in: 2 + 2*strlen(s) or | ||
347 | * buflen, whichever is less. | ||
348 | * | ||
349 | * USB String descriptors can contain at most 126 characters; input | ||
350 | * strings longer than that are truncated. | ||
343 | */ | 351 | */ |
344 | static unsigned ascii2utf(char *s, u8 *utf, int utfmax) | 352 | static unsigned |
353 | ascii2desc(char const *s, u8 *buf, unsigned len) | ||
345 | { | 354 | { |
346 | unsigned retval; | 355 | unsigned n, t = 2 + 2*strlen(s); |
347 | 356 | ||
348 | for (retval = 0; *s && utfmax > 1; utfmax -= 2, retval += 2) { | 357 | if (t > 254) |
349 | *utf++ = *s++; | 358 | t = 254; /* Longest possible UTF string descriptor */ |
350 | *utf++ = 0; | 359 | if (len > t) |
351 | } | 360 | len = t; |
352 | if (utfmax > 0) { | 361 | |
353 | *utf = *s; | 362 | t += USB_DT_STRING << 8; /* Now t is first 16 bits to store */ |
354 | ++retval; | 363 | |
364 | n = len; | ||
365 | while (n--) { | ||
366 | *buf++ = t; | ||
367 | if (!n--) | ||
368 | break; | ||
369 | *buf++ = t >> 8; | ||
370 | t = (unsigned char)*s++; | ||
355 | } | 371 | } |
356 | return retval; | 372 | return len; |
357 | } | 373 | } |
358 | 374 | ||
359 | /* | 375 | /** |
360 | * rh_string - provides manufacturer, product and serial strings for root hub | 376 | * rh_string() - provides string descriptors for root hub |
361 | * @id: the string ID number (1: serial number, 2: product, 3: vendor) | 377 | * @id: the string ID number (0: langids, 1: serial #, 2: product, 3: vendor) |
362 | * @hcd: the host controller for this root hub | 378 | * @hcd: the host controller for this root hub |
363 | * @data: return packet in UTF-16 LE | 379 | * @data: buffer for output packet |
364 | * @len: length of the return packet | 380 | * @len: length of the provided buffer |
365 | * | 381 | * |
366 | * Produces either a manufacturer, product or serial number string for the | 382 | * Produces either a manufacturer, product or serial number string for the |
367 | * virtual root hub device. | 383 | * virtual root hub device. |
384 | * Returns the number of bytes filled in: the length of the descriptor or | ||
385 | * of the provided buffer, whichever is less. | ||
368 | */ | 386 | */ |
369 | static unsigned rh_string(int id, struct usb_hcd *hcd, u8 *data, unsigned len) | 387 | static unsigned |
388 | rh_string(int id, struct usb_hcd const *hcd, u8 *data, unsigned len) | ||
370 | { | 389 | { |
371 | char buf [100]; | 390 | char buf[100]; |
391 | char const *s; | ||
392 | static char const langids[4] = {4, USB_DT_STRING, 0x09, 0x04}; | ||
372 | 393 | ||
373 | // language ids | 394 | // language ids |
374 | if (id == 0) { | 395 | switch (id) { |
375 | buf[0] = 4; buf[1] = 3; /* 4 bytes string data */ | 396 | case 0: |
376 | buf[2] = 0x09; buf[3] = 0x04; /* MSFT-speak for "en-us" */ | 397 | /* Array of LANGID codes (0x0409 is MSFT-speak for "en-us") */ |
377 | len = min_t(unsigned, len, 4); | 398 | /* See http://www.usb.org/developers/docs/USB_LANGIDs.pdf */ |
378 | memcpy (data, buf, len); | 399 | if (len > 4) |
400 | len = 4; | ||
401 | memcpy(data, langids, len); | ||
379 | return len; | 402 | return len; |
380 | 403 | case 1: | |
381 | // serial number | 404 | /* Serial number */ |
382 | } else if (id == 1) { | 405 | s = hcd->self.bus_name; |
383 | strlcpy (buf, hcd->self.bus_name, sizeof buf); | 406 | break; |
384 | 407 | case 2: | |
385 | // product description | 408 | /* Product name */ |
386 | } else if (id == 2) { | 409 | s = hcd->product_desc; |
387 | strlcpy (buf, hcd->product_desc, sizeof buf); | 410 | break; |
388 | 411 | case 3: | |
389 | // id 3 == vendor description | 412 | /* Manufacturer */ |
390 | } else if (id == 3) { | ||
391 | snprintf (buf, sizeof buf, "%s %s %s", init_utsname()->sysname, | 413 | snprintf (buf, sizeof buf, "%s %s %s", init_utsname()->sysname, |
392 | init_utsname()->release, hcd->driver->description); | 414 | init_utsname()->release, hcd->driver->description); |
393 | } | 415 | s = buf; |
394 | 416 | break; | |
395 | switch (len) { /* All cases fall through */ | ||
396 | default: | 417 | default: |
397 | len = 2 + ascii2utf (buf, data + 2, len - 2); | 418 | /* Can't happen; caller guarantees it */ |
398 | case 2: | 419 | return 0; |
399 | data [1] = 3; /* type == string */ | ||
400 | case 1: | ||
401 | data [0] = 2 * (strlen (buf) + 1); | ||
402 | case 0: | ||
403 | ; /* Compiler wants a statement here */ | ||
404 | } | 420 | } |
405 | return len; | 421 | |
422 | return ascii2desc(s, data, len); | ||
406 | } | 423 | } |
407 | 424 | ||
408 | 425 | ||
diff --git a/drivers/usb/core/hcd.h b/drivers/usb/core/hcd.h index ec5c67ea07b7..79782a1c43f6 100644 --- a/drivers/usb/core/hcd.h +++ b/drivers/usb/core/hcd.h | |||
@@ -267,6 +267,11 @@ struct hc_driver { | |||
267 | void (*reset_bandwidth)(struct usb_hcd *, struct usb_device *); | 267 | void (*reset_bandwidth)(struct usb_hcd *, struct usb_device *); |
268 | /* Returns the hardware-chosen device address */ | 268 | /* Returns the hardware-chosen device address */ |
269 | int (*address_device)(struct usb_hcd *, struct usb_device *udev); | 269 | int (*address_device)(struct usb_hcd *, struct usb_device *udev); |
270 | /* Notifies the HCD after a hub descriptor is fetched. | ||
271 | * Will block. | ||
272 | */ | ||
273 | int (*update_hub_device)(struct usb_hcd *, struct usb_device *hdev, | ||
274 | struct usb_tt *tt, gfp_t mem_flags); | ||
270 | }; | 275 | }; |
271 | 276 | ||
272 | extern int usb_hcd_link_urb_to_ep(struct usb_hcd *hcd, struct urb *urb); | 277 | extern int usb_hcd_link_urb_to_ep(struct usb_hcd *hcd, struct urb *urb); |
diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c index 71f86c60d83c..5ce839137ad6 100644 --- a/drivers/usb/core/hub.c +++ b/drivers/usb/core/hub.c | |||
@@ -78,6 +78,7 @@ struct usb_hub { | |||
78 | u8 indicator[USB_MAXCHILDREN]; | 78 | u8 indicator[USB_MAXCHILDREN]; |
79 | struct delayed_work leds; | 79 | struct delayed_work leds; |
80 | struct delayed_work init_work; | 80 | struct delayed_work init_work; |
81 | void **port_owners; | ||
81 | }; | 82 | }; |
82 | 83 | ||
83 | 84 | ||
@@ -162,8 +163,10 @@ static inline char *portspeed(int portstatus) | |||
162 | } | 163 | } |
163 | 164 | ||
164 | /* Note that hdev or one of its children must be locked! */ | 165 | /* Note that hdev or one of its children must be locked! */ |
165 | static inline struct usb_hub *hdev_to_hub(struct usb_device *hdev) | 166 | static struct usb_hub *hdev_to_hub(struct usb_device *hdev) |
166 | { | 167 | { |
168 | if (!hdev || !hdev->actconfig) | ||
169 | return NULL; | ||
167 | return usb_get_intfdata(hdev->actconfig->interface[0]); | 170 | return usb_get_intfdata(hdev->actconfig->interface[0]); |
168 | } | 171 | } |
169 | 172 | ||
@@ -372,7 +375,7 @@ static void kick_khubd(struct usb_hub *hub) | |||
372 | unsigned long flags; | 375 | unsigned long flags; |
373 | 376 | ||
374 | /* Suppress autosuspend until khubd runs */ | 377 | /* Suppress autosuspend until khubd runs */ |
375 | to_usb_interface(hub->intfdev)->pm_usage_cnt = 1; | 378 | atomic_set(&to_usb_interface(hub->intfdev)->pm_usage_cnt, 1); |
376 | 379 | ||
377 | spin_lock_irqsave(&hub_event_lock, flags); | 380 | spin_lock_irqsave(&hub_event_lock, flags); |
378 | if (!hub->disconnected && list_empty(&hub->event_list)) { | 381 | if (!hub->disconnected && list_empty(&hub->event_list)) { |
@@ -384,8 +387,10 @@ static void kick_khubd(struct usb_hub *hub) | |||
384 | 387 | ||
385 | void usb_kick_khubd(struct usb_device *hdev) | 388 | void usb_kick_khubd(struct usb_device *hdev) |
386 | { | 389 | { |
387 | /* FIXME: What if hdev isn't bound to the hub driver? */ | 390 | struct usb_hub *hub = hdev_to_hub(hdev); |
388 | kick_khubd(hdev_to_hub(hdev)); | 391 | |
392 | if (hub) | ||
393 | kick_khubd(hub); | ||
389 | } | 394 | } |
390 | 395 | ||
391 | 396 | ||
@@ -677,7 +682,8 @@ static void hub_activate(struct usb_hub *hub, enum hub_activation_type type) | |||
677 | msecs_to_jiffies(delay)); | 682 | msecs_to_jiffies(delay)); |
678 | 683 | ||
679 | /* Suppress autosuspend until init is done */ | 684 | /* Suppress autosuspend until init is done */ |
680 | to_usb_interface(hub->intfdev)->pm_usage_cnt = 1; | 685 | atomic_set(&to_usb_interface(hub->intfdev)-> |
686 | pm_usage_cnt, 1); | ||
681 | return; /* Continues at init2: below */ | 687 | return; /* Continues at init2: below */ |
682 | } else { | 688 | } else { |
683 | hub_power_on(hub, true); | 689 | hub_power_on(hub, true); |
@@ -854,25 +860,24 @@ static int hub_post_reset(struct usb_interface *intf) | |||
854 | static int hub_configure(struct usb_hub *hub, | 860 | static int hub_configure(struct usb_hub *hub, |
855 | struct usb_endpoint_descriptor *endpoint) | 861 | struct usb_endpoint_descriptor *endpoint) |
856 | { | 862 | { |
863 | struct usb_hcd *hcd; | ||
857 | struct usb_device *hdev = hub->hdev; | 864 | struct usb_device *hdev = hub->hdev; |
858 | struct device *hub_dev = hub->intfdev; | 865 | struct device *hub_dev = hub->intfdev; |
859 | u16 hubstatus, hubchange; | 866 | u16 hubstatus, hubchange; |
860 | u16 wHubCharacteristics; | 867 | u16 wHubCharacteristics; |
861 | unsigned int pipe; | 868 | unsigned int pipe; |
862 | int maxp, ret; | 869 | int maxp, ret; |
863 | char *message; | 870 | char *message = "out of memory"; |
864 | 871 | ||
865 | hub->buffer = usb_buffer_alloc(hdev, sizeof(*hub->buffer), GFP_KERNEL, | 872 | hub->buffer = usb_buffer_alloc(hdev, sizeof(*hub->buffer), GFP_KERNEL, |
866 | &hub->buffer_dma); | 873 | &hub->buffer_dma); |
867 | if (!hub->buffer) { | 874 | if (!hub->buffer) { |
868 | message = "can't allocate hub irq buffer"; | ||
869 | ret = -ENOMEM; | 875 | ret = -ENOMEM; |
870 | goto fail; | 876 | goto fail; |
871 | } | 877 | } |
872 | 878 | ||
873 | hub->status = kmalloc(sizeof(*hub->status), GFP_KERNEL); | 879 | hub->status = kmalloc(sizeof(*hub->status), GFP_KERNEL); |
874 | if (!hub->status) { | 880 | if (!hub->status) { |
875 | message = "can't kmalloc hub status buffer"; | ||
876 | ret = -ENOMEM; | 881 | ret = -ENOMEM; |
877 | goto fail; | 882 | goto fail; |
878 | } | 883 | } |
@@ -880,7 +885,6 @@ static int hub_configure(struct usb_hub *hub, | |||
880 | 885 | ||
881 | hub->descriptor = kmalloc(sizeof(*hub->descriptor), GFP_KERNEL); | 886 | hub->descriptor = kmalloc(sizeof(*hub->descriptor), GFP_KERNEL); |
882 | if (!hub->descriptor) { | 887 | if (!hub->descriptor) { |
883 | message = "can't kmalloc hub descriptor"; | ||
884 | ret = -ENOMEM; | 888 | ret = -ENOMEM; |
885 | goto fail; | 889 | goto fail; |
886 | } | 890 | } |
@@ -904,6 +908,12 @@ static int hub_configure(struct usb_hub *hub, | |||
904 | dev_info (hub_dev, "%d port%s detected\n", hdev->maxchild, | 908 | dev_info (hub_dev, "%d port%s detected\n", hdev->maxchild, |
905 | (hdev->maxchild == 1) ? "" : "s"); | 909 | (hdev->maxchild == 1) ? "" : "s"); |
906 | 910 | ||
911 | hub->port_owners = kzalloc(hdev->maxchild * sizeof(void *), GFP_KERNEL); | ||
912 | if (!hub->port_owners) { | ||
913 | ret = -ENOMEM; | ||
914 | goto fail; | ||
915 | } | ||
916 | |||
907 | wHubCharacteristics = le16_to_cpu(hub->descriptor->wHubCharacteristics); | 917 | wHubCharacteristics = le16_to_cpu(hub->descriptor->wHubCharacteristics); |
908 | 918 | ||
909 | if (wHubCharacteristics & HUB_CHAR_COMPOUND) { | 919 | if (wHubCharacteristics & HUB_CHAR_COMPOUND) { |
@@ -1052,6 +1062,19 @@ static int hub_configure(struct usb_hub *hub, | |||
1052 | dev_dbg(hub_dev, "%umA bus power budget for each child\n", | 1062 | dev_dbg(hub_dev, "%umA bus power budget for each child\n", |
1053 | hub->mA_per_port); | 1063 | hub->mA_per_port); |
1054 | 1064 | ||
1065 | /* Update the HCD's internal representation of this hub before khubd | ||
1066 | * starts getting port status changes for devices under the hub. | ||
1067 | */ | ||
1068 | hcd = bus_to_hcd(hdev->bus); | ||
1069 | if (hcd->driver->update_hub_device) { | ||
1070 | ret = hcd->driver->update_hub_device(hcd, hdev, | ||
1071 | &hub->tt, GFP_KERNEL); | ||
1072 | if (ret < 0) { | ||
1073 | message = "can't update HCD hub info"; | ||
1074 | goto fail; | ||
1075 | } | ||
1076 | } | ||
1077 | |||
1055 | ret = hub_hub_status(hub, &hubstatus, &hubchange); | 1078 | ret = hub_hub_status(hub, &hubstatus, &hubchange); |
1056 | if (ret < 0) { | 1079 | if (ret < 0) { |
1057 | message = "can't get hub status"; | 1080 | message = "can't get hub status"; |
@@ -1082,7 +1105,6 @@ static int hub_configure(struct usb_hub *hub, | |||
1082 | 1105 | ||
1083 | hub->urb = usb_alloc_urb(0, GFP_KERNEL); | 1106 | hub->urb = usb_alloc_urb(0, GFP_KERNEL); |
1084 | if (!hub->urb) { | 1107 | if (!hub->urb) { |
1085 | message = "couldn't allocate interrupt urb"; | ||
1086 | ret = -ENOMEM; | 1108 | ret = -ENOMEM; |
1087 | goto fail; | 1109 | goto fail; |
1088 | } | 1110 | } |
@@ -1131,11 +1153,13 @@ static void hub_disconnect(struct usb_interface *intf) | |||
1131 | hub_quiesce(hub, HUB_DISCONNECT); | 1153 | hub_quiesce(hub, HUB_DISCONNECT); |
1132 | 1154 | ||
1133 | usb_set_intfdata (intf, NULL); | 1155 | usb_set_intfdata (intf, NULL); |
1156 | hub->hdev->maxchild = 0; | ||
1134 | 1157 | ||
1135 | if (hub->hdev->speed == USB_SPEED_HIGH) | 1158 | if (hub->hdev->speed == USB_SPEED_HIGH) |
1136 | highspeed_hubs--; | 1159 | highspeed_hubs--; |
1137 | 1160 | ||
1138 | usb_free_urb(hub->urb); | 1161 | usb_free_urb(hub->urb); |
1162 | kfree(hub->port_owners); | ||
1139 | kfree(hub->descriptor); | 1163 | kfree(hub->descriptor); |
1140 | kfree(hub->status); | 1164 | kfree(hub->status); |
1141 | usb_buffer_free(hub->hdev, sizeof(*hub->buffer), hub->buffer, | 1165 | usb_buffer_free(hub->hdev, sizeof(*hub->buffer), hub->buffer, |
@@ -1250,6 +1274,79 @@ hub_ioctl(struct usb_interface *intf, unsigned int code, void *user_data) | |||
1250 | } | 1274 | } |
1251 | } | 1275 | } |
1252 | 1276 | ||
1277 | /* | ||
1278 | * Allow user programs to claim ports on a hub. When a device is attached | ||
1279 | * to one of these "claimed" ports, the program will "own" the device. | ||
1280 | */ | ||
1281 | static int find_port_owner(struct usb_device *hdev, unsigned port1, | ||
1282 | void ***ppowner) | ||
1283 | { | ||
1284 | if (hdev->state == USB_STATE_NOTATTACHED) | ||
1285 | return -ENODEV; | ||
1286 | if (port1 == 0 || port1 > hdev->maxchild) | ||
1287 | return -EINVAL; | ||
1288 | |||
1289 | /* This assumes that devices not managed by the hub driver | ||
1290 | * will always have maxchild equal to 0. | ||
1291 | */ | ||
1292 | *ppowner = &(hdev_to_hub(hdev)->port_owners[port1 - 1]); | ||
1293 | return 0; | ||
1294 | } | ||
1295 | |||
1296 | /* In the following three functions, the caller must hold hdev's lock */ | ||
1297 | int usb_hub_claim_port(struct usb_device *hdev, unsigned port1, void *owner) | ||
1298 | { | ||
1299 | int rc; | ||
1300 | void **powner; | ||
1301 | |||
1302 | rc = find_port_owner(hdev, port1, &powner); | ||
1303 | if (rc) | ||
1304 | return rc; | ||
1305 | if (*powner) | ||
1306 | return -EBUSY; | ||
1307 | *powner = owner; | ||
1308 | return rc; | ||
1309 | } | ||
1310 | |||
1311 | int usb_hub_release_port(struct usb_device *hdev, unsigned port1, void *owner) | ||
1312 | { | ||
1313 | int rc; | ||
1314 | void **powner; | ||
1315 | |||
1316 | rc = find_port_owner(hdev, port1, &powner); | ||
1317 | if (rc) | ||
1318 | return rc; | ||
1319 | if (*powner != owner) | ||
1320 | return -ENOENT; | ||
1321 | *powner = NULL; | ||
1322 | return rc; | ||
1323 | } | ||
1324 | |||
1325 | void usb_hub_release_all_ports(struct usb_device *hdev, void *owner) | ||
1326 | { | ||
1327 | int n; | ||
1328 | void **powner; | ||
1329 | |||
1330 | n = find_port_owner(hdev, 1, &powner); | ||
1331 | if (n == 0) { | ||
1332 | for (; n < hdev->maxchild; (++n, ++powner)) { | ||
1333 | if (*powner == owner) | ||
1334 | *powner = NULL; | ||
1335 | } | ||
1336 | } | ||
1337 | } | ||
1338 | |||
1339 | /* The caller must hold udev's lock */ | ||
1340 | bool usb_device_is_owned(struct usb_device *udev) | ||
1341 | { | ||
1342 | struct usb_hub *hub; | ||
1343 | |||
1344 | if (udev->state == USB_STATE_NOTATTACHED || !udev->parent) | ||
1345 | return false; | ||
1346 | hub = hdev_to_hub(udev->parent); | ||
1347 | return !!hub->port_owners[udev->portnum - 1]; | ||
1348 | } | ||
1349 | |||
1253 | 1350 | ||
1254 | static void recursively_mark_NOTATTACHED(struct usb_device *udev) | 1351 | static void recursively_mark_NOTATTACHED(struct usb_device *udev) |
1255 | { | 1352 | { |
@@ -2849,14 +2946,7 @@ static void hub_port_connect_change(struct usb_hub *hub, int port1, | |||
2849 | /* For a suspended device, treat this as a | 2946 | /* For a suspended device, treat this as a |
2850 | * remote wakeup event. | 2947 | * remote wakeup event. |
2851 | */ | 2948 | */ |
2852 | if (udev->do_remote_wakeup) | 2949 | status = remote_wakeup(udev); |
2853 | status = remote_wakeup(udev); | ||
2854 | |||
2855 | /* Otherwise leave it be; devices can't tell the | ||
2856 | * difference between suspended and disabled. | ||
2857 | */ | ||
2858 | else | ||
2859 | status = 0; | ||
2860 | #endif | 2950 | #endif |
2861 | 2951 | ||
2862 | } else { | 2952 | } else { |
diff --git a/drivers/usb/core/inode.c b/drivers/usb/core/inode.c index ffe75e83787c..97b40ce133f0 100644 --- a/drivers/usb/core/inode.c +++ b/drivers/usb/core/inode.c | |||
@@ -48,7 +48,6 @@ | |||
48 | #define USBFS_DEFAULT_BUSMODE (S_IXUGO | S_IRUGO) | 48 | #define USBFS_DEFAULT_BUSMODE (S_IXUGO | S_IRUGO) |
49 | #define USBFS_DEFAULT_LISTMODE S_IRUGO | 49 | #define USBFS_DEFAULT_LISTMODE S_IRUGO |
50 | 50 | ||
51 | static struct super_operations usbfs_ops; | ||
52 | static const struct file_operations default_file_operations; | 51 | static const struct file_operations default_file_operations; |
53 | static struct vfsmount *usbfs_mount; | 52 | static struct vfsmount *usbfs_mount; |
54 | static int usbfs_mount_count; /* = 0 */ | 53 | static int usbfs_mount_count; /* = 0 */ |
@@ -449,7 +448,7 @@ static const struct file_operations default_file_operations = { | |||
449 | .llseek = default_file_lseek, | 448 | .llseek = default_file_lseek, |
450 | }; | 449 | }; |
451 | 450 | ||
452 | static struct super_operations usbfs_ops = { | 451 | static const struct super_operations usbfs_ops = { |
453 | .statfs = simple_statfs, | 452 | .statfs = simple_statfs, |
454 | .drop_inode = generic_delete_inode, | 453 | .drop_inode = generic_delete_inode, |
455 | .remount_fs = remount, | 454 | .remount_fs = remount, |
diff --git a/drivers/usb/core/message.c b/drivers/usb/core/message.c index 9720e699f472..da718e84d58d 100644 --- a/drivers/usb/core/message.c +++ b/drivers/usb/core/message.c | |||
@@ -459,35 +459,23 @@ int usb_sg_init(struct usb_sg_request *io, struct usb_device *dev, | |||
459 | io->urbs[i]->context = io; | 459 | io->urbs[i]->context = io; |
460 | 460 | ||
461 | /* | 461 | /* |
462 | * Some systems need to revert to PIO when DMA is | 462 | * Some systems need to revert to PIO when DMA is temporarily |
463 | * temporarily unavailable. For their sakes, both | 463 | * unavailable. For their sakes, both transfer_buffer and |
464 | * transfer_buffer and transfer_dma are set when | 464 | * transfer_dma are set when possible. |
465 | * possible. However this can only work on systems | ||
466 | * without: | ||
467 | * | 465 | * |
468 | * - HIGHMEM, since DMA buffers located in high memory | 466 | * Note that if IOMMU coalescing occurred, we cannot |
469 | * are not directly addressable by the CPU for PIO; | 467 | * trust sg_page anymore, so check if S/G list shrunk. |
470 | * | ||
471 | * - IOMMU, since dma_map_sg() is allowed to use an | ||
472 | * IOMMU to make virtually discontiguous buffers be | ||
473 | * "dma-contiguous" so that PIO and DMA need diferent | ||
474 | * numbers of URBs. | ||
475 | * | ||
476 | * So when HIGHMEM or IOMMU are in use, transfer_buffer | ||
477 | * is NULL to prevent stale pointers and to help spot | ||
478 | * bugs. | ||
479 | */ | 468 | */ |
469 | if (io->nents == io->entries && !PageHighMem(sg_page(sg))) | ||
470 | io->urbs[i]->transfer_buffer = sg_virt(sg); | ||
471 | else | ||
472 | io->urbs[i]->transfer_buffer = NULL; | ||
473 | |||
480 | if (dma) { | 474 | if (dma) { |
481 | io->urbs[i]->transfer_dma = sg_dma_address(sg); | 475 | io->urbs[i]->transfer_dma = sg_dma_address(sg); |
482 | len = sg_dma_len(sg); | 476 | len = sg_dma_len(sg); |
483 | #if defined(CONFIG_HIGHMEM) || defined(CONFIG_GART_IOMMU) | ||
484 | io->urbs[i]->transfer_buffer = NULL; | ||
485 | #else | ||
486 | io->urbs[i]->transfer_buffer = sg_virt(sg); | ||
487 | #endif | ||
488 | } else { | 477 | } else { |
489 | /* hc may use _only_ transfer_buffer */ | 478 | /* hc may use _only_ transfer_buffer */ |
490 | io->urbs[i]->transfer_buffer = sg_virt(sg); | ||
491 | len = sg->length; | 479 | len = sg->length; |
492 | } | 480 | } |
493 | 481 | ||
diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c index a26f73880c32..b1b85abb9a2d 100644 --- a/drivers/usb/core/usb.c +++ b/drivers/usb/core/usb.c | |||
@@ -311,7 +311,7 @@ static struct dev_pm_ops usb_device_pm_ops = { | |||
311 | #endif /* CONFIG_PM */ | 311 | #endif /* CONFIG_PM */ |
312 | 312 | ||
313 | 313 | ||
314 | static char *usb_nodename(struct device *dev) | 314 | static char *usb_devnode(struct device *dev, mode_t *mode) |
315 | { | 315 | { |
316 | struct usb_device *usb_dev; | 316 | struct usb_device *usb_dev; |
317 | 317 | ||
@@ -324,7 +324,7 @@ struct device_type usb_device_type = { | |||
324 | .name = "usb_device", | 324 | .name = "usb_device", |
325 | .release = usb_release_dev, | 325 | .release = usb_release_dev, |
326 | .uevent = usb_dev_uevent, | 326 | .uevent = usb_dev_uevent, |
327 | .nodename = usb_nodename, | 327 | .devnode = usb_devnode, |
328 | .pm = &usb_device_pm_ops, | 328 | .pm = &usb_device_pm_ops, |
329 | }; | 329 | }; |
330 | 330 | ||
@@ -413,8 +413,13 @@ struct usb_device *usb_alloc_dev(struct usb_device *parent, | |||
413 | } else { | 413 | } else { |
414 | snprintf(dev->devpath, sizeof dev->devpath, | 414 | snprintf(dev->devpath, sizeof dev->devpath, |
415 | "%s.%d", parent->devpath, port1); | 415 | "%s.%d", parent->devpath, port1); |
416 | dev->route = parent->route + | 416 | /* Route string assumes hubs have less than 16 ports */ |
417 | (port1 << ((parent->level - 1)*4)); | 417 | if (port1 < 15) |
418 | dev->route = parent->route + | ||
419 | (port1 << ((parent->level - 1)*4)); | ||
420 | else | ||
421 | dev->route = parent->route + | ||
422 | (15 << ((parent->level - 1)*4)); | ||
418 | } | 423 | } |
419 | 424 | ||
420 | dev->dev.parent = &parent->dev; | 425 | dev->dev.parent = &parent->dev; |
@@ -914,11 +919,11 @@ int usb_buffer_map_sg(const struct usb_device *dev, int is_in, | |||
914 | || !(bus = dev->bus) | 919 | || !(bus = dev->bus) |
915 | || !(controller = bus->controller) | 920 | || !(controller = bus->controller) |
916 | || !controller->dma_mask) | 921 | || !controller->dma_mask) |
917 | return -1; | 922 | return -EINVAL; |
918 | 923 | ||
919 | /* FIXME generic api broken like pci, can't report errors */ | 924 | /* FIXME generic api broken like pci, can't report errors */ |
920 | return dma_map_sg(controller, sg, nents, | 925 | return dma_map_sg(controller, sg, nents, |
921 | is_in ? DMA_FROM_DEVICE : DMA_TO_DEVICE); | 926 | is_in ? DMA_FROM_DEVICE : DMA_TO_DEVICE) ? : -ENOMEM; |
922 | } | 927 | } |
923 | EXPORT_SYMBOL_GPL(usb_buffer_map_sg); | 928 | EXPORT_SYMBOL_GPL(usb_buffer_map_sg); |
924 | 929 | ||
diff --git a/drivers/usb/core/usb.h b/drivers/usb/core/usb.h index c0e0ae2bb8e7..9a8b15e6377a 100644 --- a/drivers/usb/core/usb.h +++ b/drivers/usb/core/usb.h | |||
@@ -37,6 +37,13 @@ extern int usb_match_device(struct usb_device *dev, | |||
37 | extern void usb_forced_unbind_intf(struct usb_interface *intf); | 37 | extern void usb_forced_unbind_intf(struct usb_interface *intf); |
38 | extern void usb_rebind_intf(struct usb_interface *intf); | 38 | extern void usb_rebind_intf(struct usb_interface *intf); |
39 | 39 | ||
40 | extern int usb_hub_claim_port(struct usb_device *hdev, unsigned port, | ||
41 | void *owner); | ||
42 | extern int usb_hub_release_port(struct usb_device *hdev, unsigned port, | ||
43 | void *owner); | ||
44 | extern void usb_hub_release_all_ports(struct usb_device *hdev, void *owner); | ||
45 | extern bool usb_device_is_owned(struct usb_device *udev); | ||
46 | |||
40 | extern int usb_hub_init(void); | 47 | extern int usb_hub_init(void); |
41 | extern void usb_hub_cleanup(void); | 48 | extern void usb_hub_cleanup(void); |
42 | extern int usb_major_init(void); | 49 | extern int usb_major_init(void); |
diff --git a/drivers/usb/early/Makefile b/drivers/usb/early/Makefile new file mode 100644 index 000000000000..dfedee8c45b6 --- /dev/null +++ b/drivers/usb/early/Makefile | |||
@@ -0,0 +1,5 @@ | |||
1 | # | ||
2 | # Makefile for early USB devices | ||
3 | # | ||
4 | |||
5 | obj-$(CONFIG_EARLY_PRINTK_DBGP) += ehci-dbgp.o | ||
diff --git a/drivers/usb/early/ehci-dbgp.c b/drivers/usb/early/ehci-dbgp.c new file mode 100644 index 000000000000..1206a26ef893 --- /dev/null +++ b/drivers/usb/early/ehci-dbgp.c | |||
@@ -0,0 +1,996 @@ | |||
1 | /* | ||
2 | * Standalone EHCI usb debug driver | ||
3 | * | ||
4 | * Originally written by: | ||
5 | * Eric W. Biederman" <ebiederm@xmission.com> and | ||
6 | * Yinghai Lu <yhlu.kernel@gmail.com> | ||
7 | * | ||
8 | * Changes for early/late printk and HW errata: | ||
9 | * Jason Wessel <jason.wessel@windriver.com> | ||
10 | * Copyright (C) 2009 Wind River Systems, Inc. | ||
11 | * | ||
12 | */ | ||
13 | |||
14 | #include <linux/console.h> | ||
15 | #include <linux/errno.h> | ||
16 | #include <linux/module.h> | ||
17 | #include <linux/pci_regs.h> | ||
18 | #include <linux/pci_ids.h> | ||
19 | #include <linux/usb/ch9.h> | ||
20 | #include <linux/usb/ehci_def.h> | ||
21 | #include <linux/delay.h> | ||
22 | #include <asm/io.h> | ||
23 | #include <asm/pci-direct.h> | ||
24 | #include <asm/fixmap.h> | ||
25 | |||
26 | /* The code here is intended to talk directly to the EHCI debug port | ||
27 | * and does not require that you have any kind of USB host controller | ||
28 | * drivers or USB device drivers compiled into the kernel. | ||
29 | * | ||
30 | * If you make a change to anything in here, the following test cases | ||
31 | * need to pass where a USB debug device works in the following | ||
32 | * configurations. | ||
33 | * | ||
34 | * 1. boot args: earlyprintk=dbgp | ||
35 | * o kernel compiled with # CONFIG_USB_EHCI_HCD is not set | ||
36 | * o kernel compiled with CONFIG_USB_EHCI_HCD=y | ||
37 | * 2. boot args: earlyprintk=dbgp,keep | ||
38 | * o kernel compiled with # CONFIG_USB_EHCI_HCD is not set | ||
39 | * o kernel compiled with CONFIG_USB_EHCI_HCD=y | ||
40 | * 3. boot args: earlyprintk=dbgp console=ttyUSB0 | ||
41 | * o kernel has CONFIG_USB_EHCI_HCD=y and | ||
42 | * CONFIG_USB_SERIAL_DEBUG=y | ||
43 | * 4. boot args: earlyprintk=vga,dbgp | ||
44 | * o kernel compiled with # CONFIG_USB_EHCI_HCD is not set | ||
45 | * o kernel compiled with CONFIG_USB_EHCI_HCD=y | ||
46 | * | ||
47 | * For the 4th configuration you can turn on or off the DBGP_DEBUG | ||
48 | * such that you can debug the dbgp device's driver code. | ||
49 | */ | ||
50 | |||
51 | static int dbgp_phys_port = 1; | ||
52 | |||
53 | static struct ehci_caps __iomem *ehci_caps; | ||
54 | static struct ehci_regs __iomem *ehci_regs; | ||
55 | static struct ehci_dbg_port __iomem *ehci_debug; | ||
56 | static int dbgp_not_safe; /* Cannot use debug device during ehci reset */ | ||
57 | static unsigned int dbgp_endpoint_out; | ||
58 | |||
59 | struct ehci_dev { | ||
60 | u32 bus; | ||
61 | u32 slot; | ||
62 | u32 func; | ||
63 | }; | ||
64 | |||
65 | static struct ehci_dev ehci_dev; | ||
66 | |||
67 | #define USB_DEBUG_DEVNUM 127 | ||
68 | |||
69 | #define DBGP_DATA_TOGGLE 0x8800 | ||
70 | |||
71 | #ifdef DBGP_DEBUG | ||
72 | #define dbgp_printk printk | ||
73 | static void dbgp_ehci_status(char *str) | ||
74 | { | ||
75 | if (!ehci_debug) | ||
76 | return; | ||
77 | dbgp_printk("dbgp: %s\n", str); | ||
78 | dbgp_printk(" Debug control: %08x", readl(&ehci_debug->control)); | ||
79 | dbgp_printk(" ehci cmd : %08x", readl(&ehci_regs->command)); | ||
80 | dbgp_printk(" ehci conf flg: %08x\n", | ||
81 | readl(&ehci_regs->configured_flag)); | ||
82 | dbgp_printk(" ehci status : %08x", readl(&ehci_regs->status)); | ||
83 | dbgp_printk(" ehci portsc : %08x\n", | ||
84 | readl(&ehci_regs->port_status[dbgp_phys_port - 1])); | ||
85 | } | ||
86 | #else | ||
87 | static inline void dbgp_ehci_status(char *str) { } | ||
88 | static inline void dbgp_printk(const char *fmt, ...) { } | ||
89 | #endif | ||
90 | |||
91 | static inline u32 dbgp_pid_update(u32 x, u32 tok) | ||
92 | { | ||
93 | return ((x ^ DBGP_DATA_TOGGLE) & 0xffff00) | (tok & 0xff); | ||
94 | } | ||
95 | |||
96 | static inline u32 dbgp_len_update(u32 x, u32 len) | ||
97 | { | ||
98 | return (x & ~0x0f) | (len & 0x0f); | ||
99 | } | ||
100 | |||
101 | /* | ||
102 | * USB Packet IDs (PIDs) | ||
103 | */ | ||
104 | |||
105 | /* token */ | ||
106 | #define USB_PID_OUT 0xe1 | ||
107 | #define USB_PID_IN 0x69 | ||
108 | #define USB_PID_SOF 0xa5 | ||
109 | #define USB_PID_SETUP 0x2d | ||
110 | /* handshake */ | ||
111 | #define USB_PID_ACK 0xd2 | ||
112 | #define USB_PID_NAK 0x5a | ||
113 | #define USB_PID_STALL 0x1e | ||
114 | #define USB_PID_NYET 0x96 | ||
115 | /* data */ | ||
116 | #define USB_PID_DATA0 0xc3 | ||
117 | #define USB_PID_DATA1 0x4b | ||
118 | #define USB_PID_DATA2 0x87 | ||
119 | #define USB_PID_MDATA 0x0f | ||
120 | /* Special */ | ||
121 | #define USB_PID_PREAMBLE 0x3c | ||
122 | #define USB_PID_ERR 0x3c | ||
123 | #define USB_PID_SPLIT 0x78 | ||
124 | #define USB_PID_PING 0xb4 | ||
125 | #define USB_PID_UNDEF_0 0xf0 | ||
126 | |||
127 | #define USB_PID_DATA_TOGGLE 0x88 | ||
128 | #define DBGP_CLAIM (DBGP_OWNER | DBGP_ENABLED | DBGP_INUSE) | ||
129 | |||
130 | #define PCI_CAP_ID_EHCI_DEBUG 0xa | ||
131 | |||
132 | #define HUB_ROOT_RESET_TIME 50 /* times are in msec */ | ||
133 | #define HUB_SHORT_RESET_TIME 10 | ||
134 | #define HUB_LONG_RESET_TIME 200 | ||
135 | #define HUB_RESET_TIMEOUT 500 | ||
136 | |||
137 | #define DBGP_MAX_PACKET 8 | ||
138 | #define DBGP_TIMEOUT (250 * 1000) | ||
139 | |||
140 | static int dbgp_wait_until_complete(void) | ||
141 | { | ||
142 | u32 ctrl; | ||
143 | int loop = DBGP_TIMEOUT; | ||
144 | |||
145 | do { | ||
146 | ctrl = readl(&ehci_debug->control); | ||
147 | /* Stop when the transaction is finished */ | ||
148 | if (ctrl & DBGP_DONE) | ||
149 | break; | ||
150 | udelay(1); | ||
151 | } while (--loop > 0); | ||
152 | |||
153 | if (!loop) | ||
154 | return -DBGP_TIMEOUT; | ||
155 | |||
156 | /* | ||
157 | * Now that we have observed the completed transaction, | ||
158 | * clear the done bit. | ||
159 | */ | ||
160 | writel(ctrl | DBGP_DONE, &ehci_debug->control); | ||
161 | return (ctrl & DBGP_ERROR) ? -DBGP_ERRCODE(ctrl) : DBGP_LEN(ctrl); | ||
162 | } | ||
163 | |||
164 | static inline void dbgp_mdelay(int ms) | ||
165 | { | ||
166 | int i; | ||
167 | |||
168 | while (ms--) { | ||
169 | for (i = 0; i < 1000; i++) | ||
170 | outb(0x1, 0x80); | ||
171 | } | ||
172 | } | ||
173 | |||
174 | static void dbgp_breath(void) | ||
175 | { | ||
176 | /* Sleep to give the debug port a chance to breathe */ | ||
177 | } | ||
178 | |||
179 | static int dbgp_wait_until_done(unsigned ctrl) | ||
180 | { | ||
181 | u32 pids, lpid; | ||
182 | int ret; | ||
183 | int loop = 3; | ||
184 | |||
185 | retry: | ||
186 | writel(ctrl | DBGP_GO, &ehci_debug->control); | ||
187 | ret = dbgp_wait_until_complete(); | ||
188 | pids = readl(&ehci_debug->pids); | ||
189 | lpid = DBGP_PID_GET(pids); | ||
190 | |||
191 | if (ret < 0) { | ||
192 | /* A -DBGP_TIMEOUT failure here means the device has | ||
193 | * failed, perhaps because it was unplugged, in which | ||
194 | * case we do not want to hang the system so the dbgp | ||
195 | * will be marked as unsafe to use. EHCI reset is the | ||
196 | * only way to recover if you unplug the dbgp device. | ||
197 | */ | ||
198 | if (ret == -DBGP_TIMEOUT && !dbgp_not_safe) | ||
199 | dbgp_not_safe = 1; | ||
200 | return ret; | ||
201 | } | ||
202 | |||
203 | /* | ||
204 | * If the port is getting full or it has dropped data | ||
205 | * start pacing ourselves, not necessary but it's friendly. | ||
206 | */ | ||
207 | if ((lpid == USB_PID_NAK) || (lpid == USB_PID_NYET)) | ||
208 | dbgp_breath(); | ||
209 | |||
210 | /* If I get a NACK reissue the transmission */ | ||
211 | if (lpid == USB_PID_NAK) { | ||
212 | if (--loop > 0) | ||
213 | goto retry; | ||
214 | } | ||
215 | |||
216 | return ret; | ||
217 | } | ||
218 | |||
219 | static inline void dbgp_set_data(const void *buf, int size) | ||
220 | { | ||
221 | const unsigned char *bytes = buf; | ||
222 | u32 lo, hi; | ||
223 | int i; | ||
224 | |||
225 | lo = hi = 0; | ||
226 | for (i = 0; i < 4 && i < size; i++) | ||
227 | lo |= bytes[i] << (8*i); | ||
228 | for (; i < 8 && i < size; i++) | ||
229 | hi |= bytes[i] << (8*(i - 4)); | ||
230 | writel(lo, &ehci_debug->data03); | ||
231 | writel(hi, &ehci_debug->data47); | ||
232 | } | ||
233 | |||
234 | static inline void dbgp_get_data(void *buf, int size) | ||
235 | { | ||
236 | unsigned char *bytes = buf; | ||
237 | u32 lo, hi; | ||
238 | int i; | ||
239 | |||
240 | lo = readl(&ehci_debug->data03); | ||
241 | hi = readl(&ehci_debug->data47); | ||
242 | for (i = 0; i < 4 && i < size; i++) | ||
243 | bytes[i] = (lo >> (8*i)) & 0xff; | ||
244 | for (; i < 8 && i < size; i++) | ||
245 | bytes[i] = (hi >> (8*(i - 4))) & 0xff; | ||
246 | } | ||
247 | |||
248 | static int dbgp_out(u32 addr, const char *bytes, int size) | ||
249 | { | ||
250 | u32 pids, ctrl; | ||
251 | |||
252 | pids = readl(&ehci_debug->pids); | ||
253 | pids = dbgp_pid_update(pids, USB_PID_OUT); | ||
254 | |||
255 | ctrl = readl(&ehci_debug->control); | ||
256 | ctrl = dbgp_len_update(ctrl, size); | ||
257 | ctrl |= DBGP_OUT; | ||
258 | ctrl |= DBGP_GO; | ||
259 | |||
260 | dbgp_set_data(bytes, size); | ||
261 | writel(addr, &ehci_debug->address); | ||
262 | writel(pids, &ehci_debug->pids); | ||
263 | return dbgp_wait_until_done(ctrl); | ||
264 | } | ||
265 | |||
266 | static int dbgp_bulk_write(unsigned devnum, unsigned endpoint, | ||
267 | const char *bytes, int size) | ||
268 | { | ||
269 | int ret; | ||
270 | int loops = 5; | ||
271 | u32 addr; | ||
272 | if (size > DBGP_MAX_PACKET) | ||
273 | return -1; | ||
274 | |||
275 | addr = DBGP_EPADDR(devnum, endpoint); | ||
276 | try_again: | ||
277 | if (loops--) { | ||
278 | ret = dbgp_out(addr, bytes, size); | ||
279 | if (ret == -DBGP_ERR_BAD) { | ||
280 | int try_loops = 3; | ||
281 | do { | ||
282 | /* Emit a dummy packet to re-sync communication | ||
283 | * with the debug device */ | ||
284 | if (dbgp_out(addr, "12345678", 8) >= 0) { | ||
285 | udelay(2); | ||
286 | goto try_again; | ||
287 | } | ||
288 | } while (try_loops--); | ||
289 | } | ||
290 | } | ||
291 | |||
292 | return ret; | ||
293 | } | ||
294 | |||
295 | static int dbgp_bulk_read(unsigned devnum, unsigned endpoint, void *data, | ||
296 | int size) | ||
297 | { | ||
298 | u32 pids, addr, ctrl; | ||
299 | int ret; | ||
300 | |||
301 | if (size > DBGP_MAX_PACKET) | ||
302 | return -1; | ||
303 | |||
304 | addr = DBGP_EPADDR(devnum, endpoint); | ||
305 | |||
306 | pids = readl(&ehci_debug->pids); | ||
307 | pids = dbgp_pid_update(pids, USB_PID_IN); | ||
308 | |||
309 | ctrl = readl(&ehci_debug->control); | ||
310 | ctrl = dbgp_len_update(ctrl, size); | ||
311 | ctrl &= ~DBGP_OUT; | ||
312 | ctrl |= DBGP_GO; | ||
313 | |||
314 | writel(addr, &ehci_debug->address); | ||
315 | writel(pids, &ehci_debug->pids); | ||
316 | ret = dbgp_wait_until_done(ctrl); | ||
317 | if (ret < 0) | ||
318 | return ret; | ||
319 | |||
320 | if (size > ret) | ||
321 | size = ret; | ||
322 | dbgp_get_data(data, size); | ||
323 | return ret; | ||
324 | } | ||
325 | |||
326 | static int dbgp_control_msg(unsigned devnum, int requesttype, | ||
327 | int request, int value, int index, void *data, int size) | ||
328 | { | ||
329 | u32 pids, addr, ctrl; | ||
330 | struct usb_ctrlrequest req; | ||
331 | int read; | ||
332 | int ret; | ||
333 | |||
334 | read = (requesttype & USB_DIR_IN) != 0; | ||
335 | if (size > (read ? DBGP_MAX_PACKET:0)) | ||
336 | return -1; | ||
337 | |||
338 | /* Compute the control message */ | ||
339 | req.bRequestType = requesttype; | ||
340 | req.bRequest = request; | ||
341 | req.wValue = cpu_to_le16(value); | ||
342 | req.wIndex = cpu_to_le16(index); | ||
343 | req.wLength = cpu_to_le16(size); | ||
344 | |||
345 | pids = DBGP_PID_SET(USB_PID_DATA0, USB_PID_SETUP); | ||
346 | addr = DBGP_EPADDR(devnum, 0); | ||
347 | |||
348 | ctrl = readl(&ehci_debug->control); | ||
349 | ctrl = dbgp_len_update(ctrl, sizeof(req)); | ||
350 | ctrl |= DBGP_OUT; | ||
351 | ctrl |= DBGP_GO; | ||
352 | |||
353 | /* Send the setup message */ | ||
354 | dbgp_set_data(&req, sizeof(req)); | ||
355 | writel(addr, &ehci_debug->address); | ||
356 | writel(pids, &ehci_debug->pids); | ||
357 | ret = dbgp_wait_until_done(ctrl); | ||
358 | if (ret < 0) | ||
359 | return ret; | ||
360 | |||
361 | /* Read the result */ | ||
362 | return dbgp_bulk_read(devnum, 0, data, size); | ||
363 | } | ||
364 | |||
365 | |||
366 | /* Find a PCI capability */ | ||
367 | static u32 __init find_cap(u32 num, u32 slot, u32 func, int cap) | ||
368 | { | ||
369 | u8 pos; | ||
370 | int bytes; | ||
371 | |||
372 | if (!(read_pci_config_16(num, slot, func, PCI_STATUS) & | ||
373 | PCI_STATUS_CAP_LIST)) | ||
374 | return 0; | ||
375 | |||
376 | pos = read_pci_config_byte(num, slot, func, PCI_CAPABILITY_LIST); | ||
377 | for (bytes = 0; bytes < 48 && pos >= 0x40; bytes++) { | ||
378 | u8 id; | ||
379 | |||
380 | pos &= ~3; | ||
381 | id = read_pci_config_byte(num, slot, func, pos+PCI_CAP_LIST_ID); | ||
382 | if (id == 0xff) | ||
383 | break; | ||
384 | if (id == cap) | ||
385 | return pos; | ||
386 | |||
387 | pos = read_pci_config_byte(num, slot, func, | ||
388 | pos+PCI_CAP_LIST_NEXT); | ||
389 | } | ||
390 | return 0; | ||
391 | } | ||
392 | |||
393 | static u32 __init __find_dbgp(u32 bus, u32 slot, u32 func) | ||
394 | { | ||
395 | u32 class; | ||
396 | |||
397 | class = read_pci_config(bus, slot, func, PCI_CLASS_REVISION); | ||
398 | if ((class >> 8) != PCI_CLASS_SERIAL_USB_EHCI) | ||
399 | return 0; | ||
400 | |||
401 | return find_cap(bus, slot, func, PCI_CAP_ID_EHCI_DEBUG); | ||
402 | } | ||
403 | |||
404 | static u32 __init find_dbgp(int ehci_num, u32 *rbus, u32 *rslot, u32 *rfunc) | ||
405 | { | ||
406 | u32 bus, slot, func; | ||
407 | |||
408 | for (bus = 0; bus < 256; bus++) { | ||
409 | for (slot = 0; slot < 32; slot++) { | ||
410 | for (func = 0; func < 8; func++) { | ||
411 | unsigned cap; | ||
412 | |||
413 | cap = __find_dbgp(bus, slot, func); | ||
414 | |||
415 | if (!cap) | ||
416 | continue; | ||
417 | if (ehci_num-- != 0) | ||
418 | continue; | ||
419 | *rbus = bus; | ||
420 | *rslot = slot; | ||
421 | *rfunc = func; | ||
422 | return cap; | ||
423 | } | ||
424 | } | ||
425 | } | ||
426 | return 0; | ||
427 | } | ||
428 | |||
429 | static int dbgp_ehci_startup(void) | ||
430 | { | ||
431 | u32 ctrl, cmd, status; | ||
432 | int loop; | ||
433 | |||
434 | /* Claim ownership, but do not enable yet */ | ||
435 | ctrl = readl(&ehci_debug->control); | ||
436 | ctrl |= DBGP_OWNER; | ||
437 | ctrl &= ~(DBGP_ENABLED | DBGP_INUSE); | ||
438 | writel(ctrl, &ehci_debug->control); | ||
439 | udelay(1); | ||
440 | |||
441 | dbgp_ehci_status("EHCI startup"); | ||
442 | /* Start the ehci running */ | ||
443 | cmd = readl(&ehci_regs->command); | ||
444 | cmd &= ~(CMD_LRESET | CMD_IAAD | CMD_PSE | CMD_ASE | CMD_RESET); | ||
445 | cmd |= CMD_RUN; | ||
446 | writel(cmd, &ehci_regs->command); | ||
447 | |||
448 | /* Ensure everything is routed to the EHCI */ | ||
449 | writel(FLAG_CF, &ehci_regs->configured_flag); | ||
450 | |||
451 | /* Wait until the controller is no longer halted */ | ||
452 | loop = 10; | ||
453 | do { | ||
454 | status = readl(&ehci_regs->status); | ||
455 | if (!(status & STS_HALT)) | ||
456 | break; | ||
457 | udelay(1); | ||
458 | } while (--loop > 0); | ||
459 | |||
460 | if (!loop) { | ||
461 | dbgp_printk("ehci can not be started\n"); | ||
462 | return -ENODEV; | ||
463 | } | ||
464 | dbgp_printk("ehci started\n"); | ||
465 | return 0; | ||
466 | } | ||
467 | |||
468 | static int dbgp_ehci_controller_reset(void) | ||
469 | { | ||
470 | int loop = 250 * 1000; | ||
471 | u32 cmd; | ||
472 | |||
473 | /* Reset the EHCI controller */ | ||
474 | cmd = readl(&ehci_regs->command); | ||
475 | cmd |= CMD_RESET; | ||
476 | writel(cmd, &ehci_regs->command); | ||
477 | do { | ||
478 | cmd = readl(&ehci_regs->command); | ||
479 | } while ((cmd & CMD_RESET) && (--loop > 0)); | ||
480 | |||
481 | if (!loop) { | ||
482 | dbgp_printk("can not reset ehci\n"); | ||
483 | return -1; | ||
484 | } | ||
485 | dbgp_ehci_status("ehci reset done"); | ||
486 | return 0; | ||
487 | } | ||
488 | static int ehci_wait_for_port(int port); | ||
489 | /* Return 0 on success | ||
490 | * Return -ENODEV for any general failure | ||
491 | * Return -EIO if wait for port fails | ||
492 | */ | ||
493 | int dbgp_external_startup(void) | ||
494 | { | ||
495 | int devnum; | ||
496 | struct usb_debug_descriptor dbgp_desc; | ||
497 | int ret; | ||
498 | u32 ctrl, portsc, cmd; | ||
499 | int dbg_port = dbgp_phys_port; | ||
500 | int tries = 3; | ||
501 | int reset_port_tries = 1; | ||
502 | int try_hard_once = 1; | ||
503 | |||
504 | try_port_reset_again: | ||
505 | ret = dbgp_ehci_startup(); | ||
506 | if (ret) | ||
507 | return ret; | ||
508 | |||
509 | /* Wait for a device to show up in the debug port */ | ||
510 | ret = ehci_wait_for_port(dbg_port); | ||
511 | if (ret < 0) { | ||
512 | portsc = readl(&ehci_regs->port_status[dbg_port - 1]); | ||
513 | if (!(portsc & PORT_CONNECT) && try_hard_once) { | ||
514 | /* Last ditch effort to try to force enable | ||
515 | * the debug device by using the packet test | ||
516 | * ehci command to try and wake it up. */ | ||
517 | try_hard_once = 0; | ||
518 | cmd = readl(&ehci_regs->command); | ||
519 | cmd &= ~CMD_RUN; | ||
520 | writel(cmd, &ehci_regs->command); | ||
521 | portsc = readl(&ehci_regs->port_status[dbg_port - 1]); | ||
522 | portsc |= PORT_TEST_PKT; | ||
523 | writel(portsc, &ehci_regs->port_status[dbg_port - 1]); | ||
524 | dbgp_ehci_status("Trying to force debug port online"); | ||
525 | mdelay(50); | ||
526 | dbgp_ehci_controller_reset(); | ||
527 | goto try_port_reset_again; | ||
528 | } else if (reset_port_tries--) { | ||
529 | goto try_port_reset_again; | ||
530 | } | ||
531 | dbgp_printk("No device found in debug port\n"); | ||
532 | return -EIO; | ||
533 | } | ||
534 | dbgp_ehci_status("wait for port done"); | ||
535 | |||
536 | /* Enable the debug port */ | ||
537 | ctrl = readl(&ehci_debug->control); | ||
538 | ctrl |= DBGP_CLAIM; | ||
539 | writel(ctrl, &ehci_debug->control); | ||
540 | ctrl = readl(&ehci_debug->control); | ||
541 | if ((ctrl & DBGP_CLAIM) != DBGP_CLAIM) { | ||
542 | dbgp_printk("No device in debug port\n"); | ||
543 | writel(ctrl & ~DBGP_CLAIM, &ehci_debug->control); | ||
544 | return -ENODEV; | ||
545 | } | ||
546 | dbgp_ehci_status("debug ported enabled"); | ||
547 | |||
548 | /* Completely transfer the debug device to the debug controller */ | ||
549 | portsc = readl(&ehci_regs->port_status[dbg_port - 1]); | ||
550 | portsc &= ~PORT_PE; | ||
551 | writel(portsc, &ehci_regs->port_status[dbg_port - 1]); | ||
552 | |||
553 | dbgp_mdelay(100); | ||
554 | |||
555 | try_again: | ||
556 | /* Find the debug device and make it device number 127 */ | ||
557 | for (devnum = 0; devnum <= 127; devnum++) { | ||
558 | ret = dbgp_control_msg(devnum, | ||
559 | USB_DIR_IN | USB_TYPE_STANDARD | USB_RECIP_DEVICE, | ||
560 | USB_REQ_GET_DESCRIPTOR, (USB_DT_DEBUG << 8), 0, | ||
561 | &dbgp_desc, sizeof(dbgp_desc)); | ||
562 | if (ret > 0) | ||
563 | break; | ||
564 | } | ||
565 | if (devnum > 127) { | ||
566 | dbgp_printk("Could not find attached debug device\n"); | ||
567 | goto err; | ||
568 | } | ||
569 | if (ret < 0) { | ||
570 | dbgp_printk("Attached device is not a debug device\n"); | ||
571 | goto err; | ||
572 | } | ||
573 | dbgp_endpoint_out = dbgp_desc.bDebugOutEndpoint; | ||
574 | |||
575 | /* Move the device to 127 if it isn't already there */ | ||
576 | if (devnum != USB_DEBUG_DEVNUM) { | ||
577 | ret = dbgp_control_msg(devnum, | ||
578 | USB_DIR_OUT | USB_TYPE_STANDARD | USB_RECIP_DEVICE, | ||
579 | USB_REQ_SET_ADDRESS, USB_DEBUG_DEVNUM, 0, NULL, 0); | ||
580 | if (ret < 0) { | ||
581 | dbgp_printk("Could not move attached device to %d\n", | ||
582 | USB_DEBUG_DEVNUM); | ||
583 | goto err; | ||
584 | } | ||
585 | devnum = USB_DEBUG_DEVNUM; | ||
586 | dbgp_printk("debug device renamed to 127\n"); | ||
587 | } | ||
588 | |||
589 | /* Enable the debug interface */ | ||
590 | ret = dbgp_control_msg(USB_DEBUG_DEVNUM, | ||
591 | USB_DIR_OUT | USB_TYPE_STANDARD | USB_RECIP_DEVICE, | ||
592 | USB_REQ_SET_FEATURE, USB_DEVICE_DEBUG_MODE, 0, NULL, 0); | ||
593 | if (ret < 0) { | ||
594 | dbgp_printk(" Could not enable the debug device\n"); | ||
595 | goto err; | ||
596 | } | ||
597 | dbgp_printk("debug interface enabled\n"); | ||
598 | /* Perform a small write to get the even/odd data state in sync | ||
599 | */ | ||
600 | ret = dbgp_bulk_write(USB_DEBUG_DEVNUM, dbgp_endpoint_out, " ", 1); | ||
601 | if (ret < 0) { | ||
602 | dbgp_printk("dbgp_bulk_write failed: %d\n", ret); | ||
603 | goto err; | ||
604 | } | ||
605 | dbgp_printk("small write doned\n"); | ||
606 | dbgp_not_safe = 0; | ||
607 | |||
608 | return 0; | ||
609 | err: | ||
610 | if (tries--) | ||
611 | goto try_again; | ||
612 | return -ENODEV; | ||
613 | } | ||
614 | EXPORT_SYMBOL_GPL(dbgp_external_startup); | ||
615 | |||
616 | static int __init ehci_reset_port(int port) | ||
617 | { | ||
618 | u32 portsc; | ||
619 | u32 delay_time, delay; | ||
620 | int loop; | ||
621 | |||
622 | dbgp_ehci_status("reset port"); | ||
623 | /* Reset the usb debug port */ | ||
624 | portsc = readl(&ehci_regs->port_status[port - 1]); | ||
625 | portsc &= ~PORT_PE; | ||
626 | portsc |= PORT_RESET; | ||
627 | writel(portsc, &ehci_regs->port_status[port - 1]); | ||
628 | |||
629 | delay = HUB_ROOT_RESET_TIME; | ||
630 | for (delay_time = 0; delay_time < HUB_RESET_TIMEOUT; | ||
631 | delay_time += delay) { | ||
632 | dbgp_mdelay(delay); | ||
633 | portsc = readl(&ehci_regs->port_status[port - 1]); | ||
634 | if (!(portsc & PORT_RESET)) | ||
635 | break; | ||
636 | } | ||
637 | if (portsc & PORT_RESET) { | ||
638 | /* force reset to complete */ | ||
639 | loop = 100 * 1000; | ||
640 | writel(portsc & ~(PORT_RWC_BITS | PORT_RESET), | ||
641 | &ehci_regs->port_status[port - 1]); | ||
642 | do { | ||
643 | udelay(1); | ||
644 | portsc = readl(&ehci_regs->port_status[port-1]); | ||
645 | } while ((portsc & PORT_RESET) && (--loop > 0)); | ||
646 | } | ||
647 | |||
648 | /* Device went away? */ | ||
649 | if (!(portsc & PORT_CONNECT)) | ||
650 | return -ENOTCONN; | ||
651 | |||
652 | /* bomb out completely if something weird happend */ | ||
653 | if ((portsc & PORT_CSC)) | ||
654 | return -EINVAL; | ||
655 | |||
656 | /* If we've finished resetting, then break out of the loop */ | ||
657 | if (!(portsc & PORT_RESET) && (portsc & PORT_PE)) | ||
658 | return 0; | ||
659 | return -EBUSY; | ||
660 | } | ||
661 | |||
662 | static int ehci_wait_for_port(int port) | ||
663 | { | ||
664 | u32 status; | ||
665 | int ret, reps; | ||
666 | |||
667 | for (reps = 0; reps < 300; reps++) { | ||
668 | status = readl(&ehci_regs->status); | ||
669 | if (status & STS_PCD) | ||
670 | break; | ||
671 | dbgp_mdelay(1); | ||
672 | } | ||
673 | ret = ehci_reset_port(port); | ||
674 | if (ret == 0) | ||
675 | return 0; | ||
676 | return -ENOTCONN; | ||
677 | } | ||
678 | |||
679 | typedef void (*set_debug_port_t)(int port); | ||
680 | |||
681 | static void __init default_set_debug_port(int port) | ||
682 | { | ||
683 | } | ||
684 | |||
685 | static set_debug_port_t __initdata set_debug_port = default_set_debug_port; | ||
686 | |||
687 | static void __init nvidia_set_debug_port(int port) | ||
688 | { | ||
689 | u32 dword; | ||
690 | dword = read_pci_config(ehci_dev.bus, ehci_dev.slot, ehci_dev.func, | ||
691 | 0x74); | ||
692 | dword &= ~(0x0f<<12); | ||
693 | dword |= ((port & 0x0f)<<12); | ||
694 | write_pci_config(ehci_dev.bus, ehci_dev.slot, ehci_dev.func, 0x74, | ||
695 | dword); | ||
696 | dbgp_printk("set debug port to %d\n", port); | ||
697 | } | ||
698 | |||
699 | static void __init detect_set_debug_port(void) | ||
700 | { | ||
701 | u32 vendorid; | ||
702 | |||
703 | vendorid = read_pci_config(ehci_dev.bus, ehci_dev.slot, ehci_dev.func, | ||
704 | 0x00); | ||
705 | |||
706 | if ((vendorid & 0xffff) == 0x10de) { | ||
707 | dbgp_printk("using nvidia set_debug_port\n"); | ||
708 | set_debug_port = nvidia_set_debug_port; | ||
709 | } | ||
710 | } | ||
711 | |||
712 | /* The code in early_ehci_bios_handoff() is derived from the usb pci | ||
713 | * quirk initialization, but altered so as to use the early PCI | ||
714 | * routines. */ | ||
715 | #define EHCI_USBLEGSUP_BIOS (1 << 16) /* BIOS semaphore */ | ||
716 | #define EHCI_USBLEGCTLSTS 4 /* legacy control/status */ | ||
717 | static void __init early_ehci_bios_handoff(void) | ||
718 | { | ||
719 | u32 hcc_params = readl(&ehci_caps->hcc_params); | ||
720 | int offset = (hcc_params >> 8) & 0xff; | ||
721 | u32 cap; | ||
722 | int msec; | ||
723 | |||
724 | if (!offset) | ||
725 | return; | ||
726 | |||
727 | cap = read_pci_config(ehci_dev.bus, ehci_dev.slot, | ||
728 | ehci_dev.func, offset); | ||
729 | dbgp_printk("dbgp: ehci BIOS state %08x\n", cap); | ||
730 | |||
731 | if ((cap & 0xff) == 1 && (cap & EHCI_USBLEGSUP_BIOS)) { | ||
732 | dbgp_printk("dbgp: BIOS handoff\n"); | ||
733 | write_pci_config_byte(ehci_dev.bus, ehci_dev.slot, | ||
734 | ehci_dev.func, offset + 3, 1); | ||
735 | } | ||
736 | |||
737 | /* if boot firmware now owns EHCI, spin till it hands it over. */ | ||
738 | msec = 1000; | ||
739 | while ((cap & EHCI_USBLEGSUP_BIOS) && (msec > 0)) { | ||
740 | mdelay(10); | ||
741 | msec -= 10; | ||
742 | cap = read_pci_config(ehci_dev.bus, ehci_dev.slot, | ||
743 | ehci_dev.func, offset); | ||
744 | } | ||
745 | |||
746 | if (cap & EHCI_USBLEGSUP_BIOS) { | ||
747 | /* well, possibly buggy BIOS... try to shut it down, | ||
748 | * and hope nothing goes too wrong */ | ||
749 | dbgp_printk("dbgp: BIOS handoff failed: %08x\n", cap); | ||
750 | write_pci_config_byte(ehci_dev.bus, ehci_dev.slot, | ||
751 | ehci_dev.func, offset + 2, 0); | ||
752 | } | ||
753 | |||
754 | /* just in case, always disable EHCI SMIs */ | ||
755 | write_pci_config_byte(ehci_dev.bus, ehci_dev.slot, ehci_dev.func, | ||
756 | offset + EHCI_USBLEGCTLSTS, 0); | ||
757 | } | ||
758 | |||
759 | static int __init ehci_setup(void) | ||
760 | { | ||
761 | u32 ctrl, portsc, hcs_params; | ||
762 | u32 debug_port, new_debug_port = 0, n_ports; | ||
763 | int ret, i; | ||
764 | int port_map_tried; | ||
765 | int playtimes = 3; | ||
766 | |||
767 | early_ehci_bios_handoff(); | ||
768 | |||
769 | try_next_time: | ||
770 | port_map_tried = 0; | ||
771 | |||
772 | try_next_port: | ||
773 | |||
774 | hcs_params = readl(&ehci_caps->hcs_params); | ||
775 | debug_port = HCS_DEBUG_PORT(hcs_params); | ||
776 | dbgp_phys_port = debug_port; | ||
777 | n_ports = HCS_N_PORTS(hcs_params); | ||
778 | |||
779 | dbgp_printk("debug_port: %d\n", debug_port); | ||
780 | dbgp_printk("n_ports: %d\n", n_ports); | ||
781 | dbgp_ehci_status(""); | ||
782 | |||
783 | for (i = 1; i <= n_ports; i++) { | ||
784 | portsc = readl(&ehci_regs->port_status[i-1]); | ||
785 | dbgp_printk("portstatus%d: %08x\n", i, portsc); | ||
786 | } | ||
787 | |||
788 | if (port_map_tried && (new_debug_port != debug_port)) { | ||
789 | if (--playtimes) { | ||
790 | set_debug_port(new_debug_port); | ||
791 | goto try_next_time; | ||
792 | } | ||
793 | return -1; | ||
794 | } | ||
795 | |||
796 | /* Only reset the controller if it is not already in the | ||
797 | * configured state */ | ||
798 | if (!(readl(&ehci_regs->configured_flag) & FLAG_CF)) { | ||
799 | if (dbgp_ehci_controller_reset() != 0) | ||
800 | return -1; | ||
801 | } else { | ||
802 | dbgp_ehci_status("ehci skip - already configured"); | ||
803 | } | ||
804 | |||
805 | ret = dbgp_external_startup(); | ||
806 | if (ret == -EIO) | ||
807 | goto next_debug_port; | ||
808 | |||
809 | if (ret < 0) { | ||
810 | /* Things didn't work so remove my claim */ | ||
811 | ctrl = readl(&ehci_debug->control); | ||
812 | ctrl &= ~(DBGP_CLAIM | DBGP_OUT); | ||
813 | writel(ctrl, &ehci_debug->control); | ||
814 | return -1; | ||
815 | } | ||
816 | return 0; | ||
817 | |||
818 | next_debug_port: | ||
819 | port_map_tried |= (1<<(debug_port - 1)); | ||
820 | new_debug_port = ((debug_port-1+1)%n_ports) + 1; | ||
821 | if (port_map_tried != ((1<<n_ports) - 1)) { | ||
822 | set_debug_port(new_debug_port); | ||
823 | goto try_next_port; | ||
824 | } | ||
825 | if (--playtimes) { | ||
826 | set_debug_port(new_debug_port); | ||
827 | goto try_next_time; | ||
828 | } | ||
829 | |||
830 | return -1; | ||
831 | } | ||
832 | |||
833 | int __init early_dbgp_init(char *s) | ||
834 | { | ||
835 | u32 debug_port, bar, offset; | ||
836 | u32 bus, slot, func, cap; | ||
837 | void __iomem *ehci_bar; | ||
838 | u32 dbgp_num; | ||
839 | u32 bar_val; | ||
840 | char *e; | ||
841 | int ret; | ||
842 | u8 byte; | ||
843 | |||
844 | if (!early_pci_allowed()) | ||
845 | return -1; | ||
846 | |||
847 | dbgp_num = 0; | ||
848 | if (*s) | ||
849 | dbgp_num = simple_strtoul(s, &e, 10); | ||
850 | dbgp_printk("dbgp_num: %d\n", dbgp_num); | ||
851 | |||
852 | cap = find_dbgp(dbgp_num, &bus, &slot, &func); | ||
853 | if (!cap) | ||
854 | return -1; | ||
855 | |||
856 | dbgp_printk("Found EHCI debug port on %02x:%02x.%1x\n", bus, slot, | ||
857 | func); | ||
858 | |||
859 | debug_port = read_pci_config(bus, slot, func, cap); | ||
860 | bar = (debug_port >> 29) & 0x7; | ||
861 | bar = (bar * 4) + 0xc; | ||
862 | offset = (debug_port >> 16) & 0xfff; | ||
863 | dbgp_printk("bar: %02x offset: %03x\n", bar, offset); | ||
864 | if (bar != PCI_BASE_ADDRESS_0) { | ||
865 | dbgp_printk("only debug ports on bar 1 handled.\n"); | ||
866 | |||
867 | return -1; | ||
868 | } | ||
869 | |||
870 | bar_val = read_pci_config(bus, slot, func, PCI_BASE_ADDRESS_0); | ||
871 | dbgp_printk("bar_val: %02x offset: %03x\n", bar_val, offset); | ||
872 | if (bar_val & ~PCI_BASE_ADDRESS_MEM_MASK) { | ||
873 | dbgp_printk("only simple 32bit mmio bars supported\n"); | ||
874 | |||
875 | return -1; | ||
876 | } | ||
877 | |||
878 | /* double check if the mem space is enabled */ | ||
879 | byte = read_pci_config_byte(bus, slot, func, 0x04); | ||
880 | if (!(byte & 0x2)) { | ||
881 | byte |= 0x02; | ||
882 | write_pci_config_byte(bus, slot, func, 0x04, byte); | ||
883 | dbgp_printk("mmio for ehci enabled\n"); | ||
884 | } | ||
885 | |||
886 | /* | ||
887 | * FIXME I don't have the bar size so just guess PAGE_SIZE is more | ||
888 | * than enough. 1K is the biggest I have seen. | ||
889 | */ | ||
890 | set_fixmap_nocache(FIX_DBGP_BASE, bar_val & PAGE_MASK); | ||
891 | ehci_bar = (void __iomem *)__fix_to_virt(FIX_DBGP_BASE); | ||
892 | ehci_bar += bar_val & ~PAGE_MASK; | ||
893 | dbgp_printk("ehci_bar: %p\n", ehci_bar); | ||
894 | |||
895 | ehci_caps = ehci_bar; | ||
896 | ehci_regs = ehci_bar + HC_LENGTH(readl(&ehci_caps->hc_capbase)); | ||
897 | ehci_debug = ehci_bar + offset; | ||
898 | ehci_dev.bus = bus; | ||
899 | ehci_dev.slot = slot; | ||
900 | ehci_dev.func = func; | ||
901 | |||
902 | detect_set_debug_port(); | ||
903 | |||
904 | ret = ehci_setup(); | ||
905 | if (ret < 0) { | ||
906 | dbgp_printk("ehci_setup failed\n"); | ||
907 | ehci_debug = NULL; | ||
908 | |||
909 | return -1; | ||
910 | } | ||
911 | dbgp_ehci_status("early_init_complete"); | ||
912 | |||
913 | return 0; | ||
914 | } | ||
915 | |||
916 | static void early_dbgp_write(struct console *con, const char *str, u32 n) | ||
917 | { | ||
918 | int chunk, ret; | ||
919 | char buf[DBGP_MAX_PACKET]; | ||
920 | int use_cr = 0; | ||
921 | u32 cmd, ctrl; | ||
922 | int reset_run = 0; | ||
923 | |||
924 | if (!ehci_debug || dbgp_not_safe) | ||
925 | return; | ||
926 | |||
927 | cmd = readl(&ehci_regs->command); | ||
928 | if (unlikely(!(cmd & CMD_RUN))) { | ||
929 | /* If the ehci controller is not in the run state do extended | ||
930 | * checks to see if the acpi or some other initialization also | ||
931 | * reset the ehci debug port */ | ||
932 | ctrl = readl(&ehci_debug->control); | ||
933 | if (!(ctrl & DBGP_ENABLED)) { | ||
934 | dbgp_not_safe = 1; | ||
935 | dbgp_external_startup(); | ||
936 | } else { | ||
937 | cmd |= CMD_RUN; | ||
938 | writel(cmd, &ehci_regs->command); | ||
939 | reset_run = 1; | ||
940 | } | ||
941 | } | ||
942 | while (n > 0) { | ||
943 | for (chunk = 0; chunk < DBGP_MAX_PACKET && n > 0; | ||
944 | str++, chunk++, n--) { | ||
945 | if (!use_cr && *str == '\n') { | ||
946 | use_cr = 1; | ||
947 | buf[chunk] = '\r'; | ||
948 | str--; | ||
949 | n++; | ||
950 | continue; | ||
951 | } | ||
952 | if (use_cr) | ||
953 | use_cr = 0; | ||
954 | buf[chunk] = *str; | ||
955 | } | ||
956 | if (chunk > 0) { | ||
957 | ret = dbgp_bulk_write(USB_DEBUG_DEVNUM, | ||
958 | dbgp_endpoint_out, buf, chunk); | ||
959 | } | ||
960 | } | ||
961 | if (unlikely(reset_run)) { | ||
962 | cmd = readl(&ehci_regs->command); | ||
963 | cmd &= ~CMD_RUN; | ||
964 | writel(cmd, &ehci_regs->command); | ||
965 | } | ||
966 | } | ||
967 | |||
968 | struct console early_dbgp_console = { | ||
969 | .name = "earlydbg", | ||
970 | .write = early_dbgp_write, | ||
971 | .flags = CON_PRINTBUFFER, | ||
972 | .index = -1, | ||
973 | }; | ||
974 | |||
975 | int dbgp_reset_prep(void) | ||
976 | { | ||
977 | u32 ctrl; | ||
978 | |||
979 | dbgp_not_safe = 1; | ||
980 | if (!ehci_debug) | ||
981 | return 0; | ||
982 | |||
983 | if (early_dbgp_console.index != -1 && | ||
984 | !(early_dbgp_console.flags & CON_BOOT)) | ||
985 | return 1; | ||
986 | /* This means the console is not initialized, or should get | ||
987 | * shutdown so as to allow for reuse of the usb device, which | ||
988 | * means it is time to shutdown the usb debug port. */ | ||
989 | ctrl = readl(&ehci_debug->control); | ||
990 | if (ctrl & DBGP_ENABLED) { | ||
991 | ctrl &= ~(DBGP_CLAIM); | ||
992 | writel(ctrl, &ehci_debug->control); | ||
993 | } | ||
994 | return 0; | ||
995 | } | ||
996 | EXPORT_SYMBOL_GPL(dbgp_reset_prep); | ||
diff --git a/drivers/usb/gadget/Kconfig b/drivers/usb/gadget/Kconfig index 7f8e83a954ac..33351312327f 100644 --- a/drivers/usb/gadget/Kconfig +++ b/drivers/usb/gadget/Kconfig | |||
@@ -124,7 +124,7 @@ choice | |||
124 | 124 | ||
125 | config USB_GADGET_AT91 | 125 | config USB_GADGET_AT91 |
126 | boolean "Atmel AT91 USB Device Port" | 126 | boolean "Atmel AT91 USB Device Port" |
127 | depends on ARCH_AT91 && !ARCH_AT91SAM9RL && !ARCH_AT91CAP9 | 127 | depends on ARCH_AT91 && !ARCH_AT91SAM9RL && !ARCH_AT91CAP9 && !ARCH_AT91SAM9G45 |
128 | select USB_GADGET_SELECTED | 128 | select USB_GADGET_SELECTED |
129 | help | 129 | help |
130 | Many Atmel AT91 processors (such as the AT91RM2000) have a | 130 | Many Atmel AT91 processors (such as the AT91RM2000) have a |
@@ -143,7 +143,7 @@ config USB_AT91 | |||
143 | config USB_GADGET_ATMEL_USBA | 143 | config USB_GADGET_ATMEL_USBA |
144 | boolean "Atmel USBA" | 144 | boolean "Atmel USBA" |
145 | select USB_GADGET_DUALSPEED | 145 | select USB_GADGET_DUALSPEED |
146 | depends on AVR32 || ARCH_AT91CAP9 || ARCH_AT91SAM9RL | 146 | depends on AVR32 || ARCH_AT91CAP9 || ARCH_AT91SAM9RL || ARCH_AT91SAM9G45 |
147 | help | 147 | help |
148 | USBA is the integrated high-speed USB Device controller on | 148 | USBA is the integrated high-speed USB Device controller on |
149 | the AT32AP700x, some AT91SAM9 and AT91CAP9 processors from Atmel. | 149 | the AT32AP700x, some AT91SAM9 and AT91CAP9 processors from Atmel. |
@@ -251,6 +251,24 @@ config USB_PXA25X_SMALL | |||
251 | default y if USB_ETH | 251 | default y if USB_ETH |
252 | default y if USB_G_SERIAL | 252 | default y if USB_G_SERIAL |
253 | 253 | ||
254 | config USB_GADGET_R8A66597 | ||
255 | boolean "Renesas R8A66597 USB Peripheral Controller" | ||
256 | select USB_GADGET_DUALSPEED | ||
257 | help | ||
258 | R8A66597 is a discrete USB host and peripheral controller chip that | ||
259 | supports both full and high speed USB 2.0 data transfers. | ||
260 | It has nine configurable endpoints, and endpoint zero. | ||
261 | |||
262 | Say "y" to link the driver statically, or "m" to build a | ||
263 | dynamically linked module called "r8a66597_udc" and force all | ||
264 | gadget drivers to also be dynamically linked. | ||
265 | |||
266 | config USB_R8A66597 | ||
267 | tristate | ||
268 | depends on USB_GADGET_R8A66597 | ||
269 | default USB_GADGET | ||
270 | select USB_GADGET_SELECTED | ||
271 | |||
254 | config USB_GADGET_PXA27X | 272 | config USB_GADGET_PXA27X |
255 | boolean "PXA 27x" | 273 | boolean "PXA 27x" |
256 | depends on ARCH_PXA && (PXA27x || PXA3xx) | 274 | depends on ARCH_PXA && (PXA27x || PXA3xx) |
@@ -360,16 +378,6 @@ config USB_M66592 | |||
360 | default USB_GADGET | 378 | default USB_GADGET |
361 | select USB_GADGET_SELECTED | 379 | select USB_GADGET_SELECTED |
362 | 380 | ||
363 | config SUPERH_BUILT_IN_M66592 | ||
364 | boolean "Enable SuperH built-in USB like the M66592" | ||
365 | depends on USB_GADGET_M66592 && CPU_SUBTYPE_SH7722 | ||
366 | help | ||
367 | SH7722 has USB like the M66592. | ||
368 | |||
369 | The transfer rate is very slow when use "Ethernet Gadget". | ||
370 | However, this problem is improved if change a value of | ||
371 | NET_IP_ALIGN to 4. | ||
372 | |||
373 | # | 381 | # |
374 | # Controllers available only in discrete form (and all PCI controllers) | 382 | # Controllers available only in discrete form (and all PCI controllers) |
375 | # | 383 | # |
@@ -619,9 +627,10 @@ config USB_AUDIO | |||
619 | config USB_ETH | 627 | config USB_ETH |
620 | tristate "Ethernet Gadget (with CDC Ethernet support)" | 628 | tristate "Ethernet Gadget (with CDC Ethernet support)" |
621 | depends on NET | 629 | depends on NET |
630 | select CRC32 | ||
622 | help | 631 | help |
623 | This driver implements Ethernet style communication, in either | 632 | This driver implements Ethernet style communication, in one of |
624 | of two ways: | 633 | several ways: |
625 | 634 | ||
626 | - The "Communication Device Class" (CDC) Ethernet Control Model. | 635 | - The "Communication Device Class" (CDC) Ethernet Control Model. |
627 | That protocol is often avoided with pure Ethernet adapters, in | 636 | That protocol is often avoided with pure Ethernet adapters, in |
@@ -631,7 +640,11 @@ config USB_ETH | |||
631 | - On hardware can't implement that protocol, a simple CDC subset | 640 | - On hardware can't implement that protocol, a simple CDC subset |
632 | is used, placing fewer demands on USB. | 641 | is used, placing fewer demands on USB. |
633 | 642 | ||
634 | RNDIS support is a third option, more demanding than that subset. | 643 | - CDC Ethernet Emulation Model (EEM) is a newer standard that has |
644 | a simpler interface that can be used by more USB hardware. | ||
645 | |||
646 | RNDIS support is an additional option, more demanding than than | ||
647 | subset. | ||
635 | 648 | ||
636 | Within the USB device, this gadget driver exposes a network device | 649 | Within the USB device, this gadget driver exposes a network device |
637 | "usbX", where X depends on what other networking devices you have. | 650 | "usbX", where X depends on what other networking devices you have. |
@@ -664,6 +677,22 @@ config USB_ETH_RNDIS | |||
664 | XP, you'll need to download drivers from Microsoft's website; a URL | 677 | XP, you'll need to download drivers from Microsoft's website; a URL |
665 | is given in comments found in that info file. | 678 | is given in comments found in that info file. |
666 | 679 | ||
680 | config USB_ETH_EEM | ||
681 | bool "Ethernet Emulation Model (EEM) support" | ||
682 | depends on USB_ETH | ||
683 | default n | ||
684 | help | ||
685 | CDC EEM is a newer USB standard that is somewhat simpler than CDC ECM | ||
686 | and therefore can be supported by more hardware. Technically ECM and | ||
687 | EEM are designed for different applications. The ECM model extends | ||
688 | the network interface to the target (e.g. a USB cable modem), and the | ||
689 | EEM model is for mobile devices to communicate with hosts using | ||
690 | ethernet over USB. For Linux gadgets, however, the interface with | ||
691 | the host is the same (a usbX device), so the differences are minimal. | ||
692 | |||
693 | If you say "y" here, the Ethernet gadget driver will use the EEM | ||
694 | protocol rather than ECM. If unsure, say "n". | ||
695 | |||
667 | config USB_GADGETFS | 696 | config USB_GADGETFS |
668 | tristate "Gadget Filesystem (EXPERIMENTAL)" | 697 | tristate "Gadget Filesystem (EXPERIMENTAL)" |
669 | depends on EXPERIMENTAL | 698 | depends on EXPERIMENTAL |
diff --git a/drivers/usb/gadget/Makefile b/drivers/usb/gadget/Makefile index e6017e6bf6da..9d7b87c52e9f 100644 --- a/drivers/usb/gadget/Makefile +++ b/drivers/usb/gadget/Makefile | |||
@@ -23,6 +23,7 @@ ifeq ($(CONFIG_ARCH_MXC),y) | |||
23 | fsl_usb2_udc-objs += fsl_mx3_udc.o | 23 | fsl_usb2_udc-objs += fsl_mx3_udc.o |
24 | endif | 24 | endif |
25 | obj-$(CONFIG_USB_M66592) += m66592-udc.o | 25 | obj-$(CONFIG_USB_M66592) += m66592-udc.o |
26 | obj-$(CONFIG_USB_R8A66597) += r8a66597-udc.o | ||
26 | obj-$(CONFIG_USB_FSL_QE) += fsl_qe_udc.o | 27 | obj-$(CONFIG_USB_FSL_QE) += fsl_qe_udc.o |
27 | obj-$(CONFIG_USB_CI13XXX) += ci13xxx_udc.o | 28 | obj-$(CONFIG_USB_CI13XXX) += ci13xxx_udc.o |
28 | obj-$(CONFIG_USB_S3C_HSOTG) += s3c-hsotg.o | 29 | obj-$(CONFIG_USB_S3C_HSOTG) += s3c-hsotg.o |
diff --git a/drivers/usb/gadget/amd5536udc.c b/drivers/usb/gadget/amd5536udc.c index 77352ccc245e..d5b65962dd36 100644 --- a/drivers/usb/gadget/amd5536udc.c +++ b/drivers/usb/gadget/amd5536udc.c | |||
@@ -2378,40 +2378,34 @@ static irqreturn_t udc_data_in_isr(struct udc *dev, int ep_ix) | |||
2378 | if (!ep->cancel_transfer && !list_empty(&ep->queue)) { | 2378 | if (!ep->cancel_transfer && !list_empty(&ep->queue)) { |
2379 | req = list_entry(ep->queue.next, | 2379 | req = list_entry(ep->queue.next, |
2380 | struct udc_request, queue); | 2380 | struct udc_request, queue); |
2381 | if (req) { | 2381 | /* |
2382 | /* | 2382 | * length bytes transfered |
2383 | * length bytes transfered | 2383 | * check dma done of last desc. in PPBDU mode |
2384 | * check dma done of last desc. in PPBDU mode | 2384 | */ |
2385 | */ | 2385 | if (use_dma_ppb_du) { |
2386 | if (use_dma_ppb_du) { | 2386 | td = udc_get_last_dma_desc(req); |
2387 | td = udc_get_last_dma_desc(req); | 2387 | if (td) { |
2388 | if (td) { | 2388 | dma_done = |
2389 | dma_done = | 2389 | AMD_GETBITS(td->status, |
2390 | AMD_GETBITS(td->status, | 2390 | UDC_DMA_IN_STS_BS); |
2391 | UDC_DMA_IN_STS_BS); | 2391 | /* don't care DMA done */ |
2392 | /* don't care DMA done */ | ||
2393 | req->req.actual = | ||
2394 | req->req.length; | ||
2395 | } | ||
2396 | } else { | ||
2397 | /* assume all bytes transferred */ | ||
2398 | req->req.actual = req->req.length; | 2392 | req->req.actual = req->req.length; |
2399 | } | 2393 | } |
2394 | } else { | ||
2395 | /* assume all bytes transferred */ | ||
2396 | req->req.actual = req->req.length; | ||
2397 | } | ||
2400 | 2398 | ||
2401 | if (req->req.actual == req->req.length) { | 2399 | if (req->req.actual == req->req.length) { |
2402 | /* complete req */ | 2400 | /* complete req */ |
2403 | complete_req(ep, req, 0); | 2401 | complete_req(ep, req, 0); |
2404 | req->dma_going = 0; | 2402 | req->dma_going = 0; |
2405 | /* further request available ? */ | 2403 | /* further request available ? */ |
2406 | if (list_empty(&ep->queue)) { | 2404 | if (list_empty(&ep->queue)) { |
2407 | /* disable interrupt */ | 2405 | /* disable interrupt */ |
2408 | tmp = readl( | 2406 | tmp = readl(&dev->regs->ep_irqmsk); |
2409 | &dev->regs->ep_irqmsk); | 2407 | tmp |= AMD_BIT(ep->num); |
2410 | tmp |= AMD_BIT(ep->num); | 2408 | writel(tmp, &dev->regs->ep_irqmsk); |
2411 | writel(tmp, | ||
2412 | &dev->regs->ep_irqmsk); | ||
2413 | } | ||
2414 | |||
2415 | } | 2409 | } |
2416 | } | 2410 | } |
2417 | } | 2411 | } |
diff --git a/drivers/usb/gadget/at91_udc.c b/drivers/usb/gadget/at91_udc.c index 72bae8f39d81..66450a1abc22 100644 --- a/drivers/usb/gadget/at91_udc.c +++ b/drivers/usb/gadget/at91_udc.c | |||
@@ -1754,7 +1754,6 @@ static int __init at91udc_probe(struct platform_device *pdev) | |||
1754 | IRQF_DISABLED, driver_name, udc)) { | 1754 | IRQF_DISABLED, driver_name, udc)) { |
1755 | DBG("request vbus irq %d failed\n", | 1755 | DBG("request vbus irq %d failed\n", |
1756 | udc->board.vbus_pin); | 1756 | udc->board.vbus_pin); |
1757 | free_irq(udc->udp_irq, udc); | ||
1758 | retval = -EBUSY; | 1757 | retval = -EBUSY; |
1759 | goto fail3; | 1758 | goto fail3; |
1760 | } | 1759 | } |
diff --git a/drivers/usb/gadget/audio.c b/drivers/usb/gadget/audio.c index 9f80f4e970bd..a3a0f4a27ef0 100644 --- a/drivers/usb/gadget/audio.c +++ b/drivers/usb/gadget/audio.c | |||
@@ -106,20 +106,20 @@ static int audio_set_endpoint_req(struct usb_configuration *c, | |||
106 | ctrl->bRequest, w_value, len, ep); | 106 | ctrl->bRequest, w_value, len, ep); |
107 | 107 | ||
108 | switch (ctrl->bRequest) { | 108 | switch (ctrl->bRequest) { |
109 | case SET_CUR: | 109 | case UAC_SET_CUR: |
110 | value = 0; | 110 | value = 0; |
111 | break; | 111 | break; |
112 | 112 | ||
113 | case SET_MIN: | 113 | case UAC_SET_MIN: |
114 | break; | 114 | break; |
115 | 115 | ||
116 | case SET_MAX: | 116 | case UAC_SET_MAX: |
117 | break; | 117 | break; |
118 | 118 | ||
119 | case SET_RES: | 119 | case UAC_SET_RES: |
120 | break; | 120 | break; |
121 | 121 | ||
122 | case SET_MEM: | 122 | case UAC_SET_MEM: |
123 | break; | 123 | break; |
124 | 124 | ||
125 | default: | 125 | default: |
@@ -142,13 +142,13 @@ static int audio_get_endpoint_req(struct usb_configuration *c, | |||
142 | ctrl->bRequest, w_value, len, ep); | 142 | ctrl->bRequest, w_value, len, ep); |
143 | 143 | ||
144 | switch (ctrl->bRequest) { | 144 | switch (ctrl->bRequest) { |
145 | case GET_CUR: | 145 | case UAC_GET_CUR: |
146 | case GET_MIN: | 146 | case UAC_GET_MIN: |
147 | case GET_MAX: | 147 | case UAC_GET_MAX: |
148 | case GET_RES: | 148 | case UAC_GET_RES: |
149 | value = 3; | 149 | value = 3; |
150 | break; | 150 | break; |
151 | case GET_MEM: | 151 | case UAC_GET_MEM: |
152 | break; | 152 | break; |
153 | default: | 153 | default: |
154 | break; | 154 | break; |
@@ -171,11 +171,11 @@ audio_setup(struct usb_configuration *c, const struct usb_ctrlrequest *ctrl) | |||
171 | * Audio class messages; interface activation uses set_alt(). | 171 | * Audio class messages; interface activation uses set_alt(). |
172 | */ | 172 | */ |
173 | switch (ctrl->bRequestType) { | 173 | switch (ctrl->bRequestType) { |
174 | case USB_AUDIO_SET_ENDPOINT: | 174 | case USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_ENDPOINT: |
175 | value = audio_set_endpoint_req(c, ctrl); | 175 | value = audio_set_endpoint_req(c, ctrl); |
176 | break; | 176 | break; |
177 | 177 | ||
178 | case USB_AUDIO_GET_ENDPOINT: | 178 | case USB_DIR_IN | USB_TYPE_CLASS | USB_RECIP_ENDPOINT: |
179 | value = audio_get_endpoint_req(c, ctrl); | 179 | value = audio_get_endpoint_req(c, ctrl); |
180 | break; | 180 | break; |
181 | 181 | ||
diff --git a/drivers/usb/gadget/composite.c b/drivers/usb/gadget/composite.c index 59e85234fa0a..d05397ec8a18 100644 --- a/drivers/usb/gadget/composite.c +++ b/drivers/usb/gadget/composite.c | |||
@@ -602,7 +602,7 @@ static int get_string(struct usb_composite_dev *cdev, | |||
602 | } | 602 | } |
603 | } | 603 | } |
604 | 604 | ||
605 | for (len = 0; s->wData[len] && len <= 126; len++) | 605 | for (len = 0; len <= 126 && s->wData[len]; len++) |
606 | continue; | 606 | continue; |
607 | if (!len) | 607 | if (!len) |
608 | return -EINVAL; | 608 | return -EINVAL; |
diff --git a/drivers/usb/gadget/dummy_hcd.c b/drivers/usb/gadget/dummy_hcd.c index a56b24d305f8..5e0966485188 100644 --- a/drivers/usb/gadget/dummy_hcd.c +++ b/drivers/usb/gadget/dummy_hcd.c | |||
@@ -1306,11 +1306,6 @@ restart: | |||
1306 | setup = *(struct usb_ctrlrequest*) urb->setup_packet; | 1306 | setup = *(struct usb_ctrlrequest*) urb->setup_packet; |
1307 | w_index = le16_to_cpu(setup.wIndex); | 1307 | w_index = le16_to_cpu(setup.wIndex); |
1308 | w_value = le16_to_cpu(setup.wValue); | 1308 | w_value = le16_to_cpu(setup.wValue); |
1309 | if (le16_to_cpu(setup.wLength) != | ||
1310 | urb->transfer_buffer_length) { | ||
1311 | status = -EOVERFLOW; | ||
1312 | goto return_urb; | ||
1313 | } | ||
1314 | 1309 | ||
1315 | /* paranoia, in case of stale queued data */ | 1310 | /* paranoia, in case of stale queued data */ |
1316 | list_for_each_entry (req, &ep->queue, queue) { | 1311 | list_for_each_entry (req, &ep->queue, queue) { |
diff --git a/drivers/usb/gadget/ether.c b/drivers/usb/gadget/ether.c index bd102f5052ba..f37de283d0ab 100644 --- a/drivers/usb/gadget/ether.c +++ b/drivers/usb/gadget/ether.c | |||
@@ -61,6 +61,11 @@ | |||
61 | * simpler, Microsoft pushes their own approach: RNDIS. The published | 61 | * simpler, Microsoft pushes their own approach: RNDIS. The published |
62 | * RNDIS specs are ambiguous and appear to be incomplete, and are also | 62 | * RNDIS specs are ambiguous and appear to be incomplete, and are also |
63 | * needlessly complex. They borrow more from CDC ACM than CDC ECM. | 63 | * needlessly complex. They borrow more from CDC ACM than CDC ECM. |
64 | * | ||
65 | * While CDC ECM, CDC Subset, and RNDIS are designed to extend the ethernet | ||
66 | * interface to the target, CDC EEM was designed to use ethernet over the USB | ||
67 | * link between the host and target. CDC EEM is implemented as an alternative | ||
68 | * to those other protocols when that communication model is more appropriate | ||
64 | */ | 69 | */ |
65 | 70 | ||
66 | #define DRIVER_DESC "Ethernet Gadget" | 71 | #define DRIVER_DESC "Ethernet Gadget" |
@@ -114,6 +119,7 @@ static inline bool has_rndis(void) | |||
114 | #include "f_rndis.c" | 119 | #include "f_rndis.c" |
115 | #include "rndis.c" | 120 | #include "rndis.c" |
116 | #endif | 121 | #endif |
122 | #include "f_eem.c" | ||
117 | #include "u_ether.c" | 123 | #include "u_ether.c" |
118 | 124 | ||
119 | /*-------------------------------------------------------------------------*/ | 125 | /*-------------------------------------------------------------------------*/ |
@@ -150,6 +156,10 @@ static inline bool has_rndis(void) | |||
150 | #define RNDIS_VENDOR_NUM 0x0525 /* NetChip */ | 156 | #define RNDIS_VENDOR_NUM 0x0525 /* NetChip */ |
151 | #define RNDIS_PRODUCT_NUM 0xa4a2 /* Ethernet/RNDIS Gadget */ | 157 | #define RNDIS_PRODUCT_NUM 0xa4a2 /* Ethernet/RNDIS Gadget */ |
152 | 158 | ||
159 | /* For EEM gadgets */ | ||
160 | #define EEM_VENDOR_NUM 0x0525 /* INVALID - NEEDS TO BE ALLOCATED */ | ||
161 | #define EEM_PRODUCT_NUM 0xa4a1 /* INVALID - NEEDS TO BE ALLOCATED */ | ||
162 | |||
153 | /*-------------------------------------------------------------------------*/ | 163 | /*-------------------------------------------------------------------------*/ |
154 | 164 | ||
155 | static struct usb_device_descriptor device_desc = { | 165 | static struct usb_device_descriptor device_desc = { |
@@ -246,8 +256,16 @@ static struct usb_configuration rndis_config_driver = { | |||
246 | 256 | ||
247 | /*-------------------------------------------------------------------------*/ | 257 | /*-------------------------------------------------------------------------*/ |
248 | 258 | ||
259 | #ifdef CONFIG_USB_ETH_EEM | ||
260 | static int use_eem = 1; | ||
261 | #else | ||
262 | static int use_eem; | ||
263 | #endif | ||
264 | module_param(use_eem, bool, 0); | ||
265 | MODULE_PARM_DESC(use_eem, "use CDC EEM mode"); | ||
266 | |||
249 | /* | 267 | /* |
250 | * We _always_ have an ECM or CDC Subset configuration. | 268 | * We _always_ have an ECM, CDC Subset, or EEM configuration. |
251 | */ | 269 | */ |
252 | static int __init eth_do_config(struct usb_configuration *c) | 270 | static int __init eth_do_config(struct usb_configuration *c) |
253 | { | 271 | { |
@@ -258,7 +276,9 @@ static int __init eth_do_config(struct usb_configuration *c) | |||
258 | c->bmAttributes |= USB_CONFIG_ATT_WAKEUP; | 276 | c->bmAttributes |= USB_CONFIG_ATT_WAKEUP; |
259 | } | 277 | } |
260 | 278 | ||
261 | if (can_support_ecm(c->cdev->gadget)) | 279 | if (use_eem) |
280 | return eem_bind_config(c); | ||
281 | else if (can_support_ecm(c->cdev->gadget)) | ||
262 | return ecm_bind_config(c, hostaddr); | 282 | return ecm_bind_config(c, hostaddr); |
263 | else | 283 | else |
264 | return geth_bind_config(c, hostaddr); | 284 | return geth_bind_config(c, hostaddr); |
@@ -286,7 +306,12 @@ static int __init eth_bind(struct usb_composite_dev *cdev) | |||
286 | return status; | 306 | return status; |
287 | 307 | ||
288 | /* set up main config label and device descriptor */ | 308 | /* set up main config label and device descriptor */ |
289 | if (can_support_ecm(cdev->gadget)) { | 309 | if (use_eem) { |
310 | /* EEM */ | ||
311 | eth_config_driver.label = "CDC Ethernet (EEM)"; | ||
312 | device_desc.idVendor = cpu_to_le16(EEM_VENDOR_NUM); | ||
313 | device_desc.idProduct = cpu_to_le16(EEM_PRODUCT_NUM); | ||
314 | } else if (can_support_ecm(cdev->gadget)) { | ||
290 | /* ECM */ | 315 | /* ECM */ |
291 | eth_config_driver.label = "CDC Ethernet (ECM)"; | 316 | eth_config_driver.label = "CDC Ethernet (ECM)"; |
292 | } else { | 317 | } else { |
diff --git a/drivers/usb/gadget/f_audio.c b/drivers/usb/gadget/f_audio.c index 66527ba2d2ea..98e9bb977291 100644 --- a/drivers/usb/gadget/f_audio.c +++ b/drivers/usb/gadget/f_audio.c | |||
@@ -28,6 +28,9 @@ static int audio_buf_size = 48000; | |||
28 | module_param(audio_buf_size, int, S_IRUGO); | 28 | module_param(audio_buf_size, int, S_IRUGO); |
29 | MODULE_PARM_DESC(audio_buf_size, "Audio buffer size"); | 29 | MODULE_PARM_DESC(audio_buf_size, "Audio buffer size"); |
30 | 30 | ||
31 | static int generic_set_cmd(struct usb_audio_control *con, u8 cmd, int value); | ||
32 | static int generic_get_cmd(struct usb_audio_control *con, u8 cmd); | ||
33 | |||
31 | /* | 34 | /* |
32 | * DESCRIPTORS ... most are static, but strings and full | 35 | * DESCRIPTORS ... most are static, but strings and full |
33 | * configuration descriptors are built on demand. | 36 | * configuration descriptors are built on demand. |
@@ -50,16 +53,16 @@ static struct usb_interface_descriptor ac_interface_desc __initdata = { | |||
50 | .bInterfaceSubClass = USB_SUBCLASS_AUDIOCONTROL, | 53 | .bInterfaceSubClass = USB_SUBCLASS_AUDIOCONTROL, |
51 | }; | 54 | }; |
52 | 55 | ||
53 | DECLARE_USB_AC_HEADER_DESCRIPTOR(2); | 56 | DECLARE_UAC_AC_HEADER_DESCRIPTOR(2); |
54 | 57 | ||
55 | #define USB_DT_AC_HEADER_LENGH USB_DT_AC_HEADER_SIZE(F_AUDIO_NUM_INTERFACES) | 58 | #define UAC_DT_AC_HEADER_LENGTH UAC_DT_AC_HEADER_SIZE(F_AUDIO_NUM_INTERFACES) |
56 | /* B.3.2 Class-Specific AC Interface Descriptor */ | 59 | /* B.3.2 Class-Specific AC Interface Descriptor */ |
57 | static struct usb_ac_header_descriptor_2 ac_header_desc = { | 60 | static struct uac_ac_header_descriptor_2 ac_header_desc = { |
58 | .bLength = USB_DT_AC_HEADER_LENGH, | 61 | .bLength = UAC_DT_AC_HEADER_LENGTH, |
59 | .bDescriptorType = USB_DT_CS_INTERFACE, | 62 | .bDescriptorType = USB_DT_CS_INTERFACE, |
60 | .bDescriptorSubtype = HEADER, | 63 | .bDescriptorSubtype = UAC_HEADER, |
61 | .bcdADC = __constant_cpu_to_le16(0x0100), | 64 | .bcdADC = __constant_cpu_to_le16(0x0100), |
62 | .wTotalLength = __constant_cpu_to_le16(USB_DT_AC_HEADER_LENGH), | 65 | .wTotalLength = __constant_cpu_to_le16(UAC_DT_AC_HEADER_LENGTH), |
63 | .bInCollection = F_AUDIO_NUM_INTERFACES, | 66 | .bInCollection = F_AUDIO_NUM_INTERFACES, |
64 | .baInterfaceNr = { | 67 | .baInterfaceNr = { |
65 | [0] = F_AUDIO_AC_INTERFACE, | 68 | [0] = F_AUDIO_AC_INTERFACE, |
@@ -68,33 +71,33 @@ static struct usb_ac_header_descriptor_2 ac_header_desc = { | |||
68 | }; | 71 | }; |
69 | 72 | ||
70 | #define INPUT_TERMINAL_ID 1 | 73 | #define INPUT_TERMINAL_ID 1 |
71 | static struct usb_input_terminal_descriptor input_terminal_desc = { | 74 | static struct uac_input_terminal_descriptor input_terminal_desc = { |
72 | .bLength = USB_DT_AC_INPUT_TERMINAL_SIZE, | 75 | .bLength = UAC_DT_INPUT_TERMINAL_SIZE, |
73 | .bDescriptorType = USB_DT_CS_INTERFACE, | 76 | .bDescriptorType = USB_DT_CS_INTERFACE, |
74 | .bDescriptorSubtype = INPUT_TERMINAL, | 77 | .bDescriptorSubtype = UAC_INPUT_TERMINAL, |
75 | .bTerminalID = INPUT_TERMINAL_ID, | 78 | .bTerminalID = INPUT_TERMINAL_ID, |
76 | .wTerminalType = USB_AC_TERMINAL_STREAMING, | 79 | .wTerminalType = UAC_TERMINAL_STREAMING, |
77 | .bAssocTerminal = 0, | 80 | .bAssocTerminal = 0, |
78 | .wChannelConfig = 0x3, | 81 | .wChannelConfig = 0x3, |
79 | }; | 82 | }; |
80 | 83 | ||
81 | DECLARE_USB_AC_FEATURE_UNIT_DESCRIPTOR(0); | 84 | DECLARE_UAC_FEATURE_UNIT_DESCRIPTOR(0); |
82 | 85 | ||
83 | #define FEATURE_UNIT_ID 2 | 86 | #define FEATURE_UNIT_ID 2 |
84 | static struct usb_ac_feature_unit_descriptor_0 feature_unit_desc = { | 87 | static struct uac_feature_unit_descriptor_0 feature_unit_desc = { |
85 | .bLength = USB_DT_AC_FEATURE_UNIT_SIZE(0), | 88 | .bLength = UAC_DT_FEATURE_UNIT_SIZE(0), |
86 | .bDescriptorType = USB_DT_CS_INTERFACE, | 89 | .bDescriptorType = USB_DT_CS_INTERFACE, |
87 | .bDescriptorSubtype = FEATURE_UNIT, | 90 | .bDescriptorSubtype = UAC_FEATURE_UNIT, |
88 | .bUnitID = FEATURE_UNIT_ID, | 91 | .bUnitID = FEATURE_UNIT_ID, |
89 | .bSourceID = INPUT_TERMINAL_ID, | 92 | .bSourceID = INPUT_TERMINAL_ID, |
90 | .bControlSize = 2, | 93 | .bControlSize = 2, |
91 | .bmaControls[0] = (FU_MUTE | FU_VOLUME), | 94 | .bmaControls[0] = (UAC_FU_MUTE | UAC_FU_VOLUME), |
92 | }; | 95 | }; |
93 | 96 | ||
94 | static struct usb_audio_control mute_control = { | 97 | static struct usb_audio_control mute_control = { |
95 | .list = LIST_HEAD_INIT(mute_control.list), | 98 | .list = LIST_HEAD_INIT(mute_control.list), |
96 | .name = "Mute Control", | 99 | .name = "Mute Control", |
97 | .type = MUTE_CONTROL, | 100 | .type = UAC_MUTE_CONTROL, |
98 | /* Todo: add real Mute control code */ | 101 | /* Todo: add real Mute control code */ |
99 | .set = generic_set_cmd, | 102 | .set = generic_set_cmd, |
100 | .get = generic_get_cmd, | 103 | .get = generic_get_cmd, |
@@ -103,7 +106,7 @@ static struct usb_audio_control mute_control = { | |||
103 | static struct usb_audio_control volume_control = { | 106 | static struct usb_audio_control volume_control = { |
104 | .list = LIST_HEAD_INIT(volume_control.list), | 107 | .list = LIST_HEAD_INIT(volume_control.list), |
105 | .name = "Volume Control", | 108 | .name = "Volume Control", |
106 | .type = VOLUME_CONTROL, | 109 | .type = UAC_VOLUME_CONTROL, |
107 | /* Todo: add real Volume control code */ | 110 | /* Todo: add real Volume control code */ |
108 | .set = generic_set_cmd, | 111 | .set = generic_set_cmd, |
109 | .get = generic_get_cmd, | 112 | .get = generic_get_cmd, |
@@ -113,17 +116,17 @@ static struct usb_audio_control_selector feature_unit = { | |||
113 | .list = LIST_HEAD_INIT(feature_unit.list), | 116 | .list = LIST_HEAD_INIT(feature_unit.list), |
114 | .id = FEATURE_UNIT_ID, | 117 | .id = FEATURE_UNIT_ID, |
115 | .name = "Mute & Volume Control", | 118 | .name = "Mute & Volume Control", |
116 | .type = FEATURE_UNIT, | 119 | .type = UAC_FEATURE_UNIT, |
117 | .desc = (struct usb_descriptor_header *)&feature_unit_desc, | 120 | .desc = (struct usb_descriptor_header *)&feature_unit_desc, |
118 | }; | 121 | }; |
119 | 122 | ||
120 | #define OUTPUT_TERMINAL_ID 3 | 123 | #define OUTPUT_TERMINAL_ID 3 |
121 | static struct usb_output_terminal_descriptor output_terminal_desc = { | 124 | static struct uac_output_terminal_descriptor output_terminal_desc = { |
122 | .bLength = USB_DT_AC_OUTPUT_TERMINAL_SIZE, | 125 | .bLength = UAC_DT_OUTPUT_TERMINAL_SIZE, |
123 | .bDescriptorType = USB_DT_CS_INTERFACE, | 126 | .bDescriptorType = USB_DT_CS_INTERFACE, |
124 | .bDescriptorSubtype = OUTPUT_TERMINAL, | 127 | .bDescriptorSubtype = UAC_OUTPUT_TERMINAL, |
125 | .bTerminalID = OUTPUT_TERMINAL_ID, | 128 | .bTerminalID = OUTPUT_TERMINAL_ID, |
126 | .wTerminalType = USB_AC_OUTPUT_TERMINAL_SPEAKER, | 129 | .wTerminalType = UAC_OUTPUT_TERMINAL_SPEAKER, |
127 | .bAssocTerminal = FEATURE_UNIT_ID, | 130 | .bAssocTerminal = FEATURE_UNIT_ID, |
128 | .bSourceID = FEATURE_UNIT_ID, | 131 | .bSourceID = FEATURE_UNIT_ID, |
129 | }; | 132 | }; |
@@ -148,22 +151,22 @@ static struct usb_interface_descriptor as_interface_alt_1_desc = { | |||
148 | }; | 151 | }; |
149 | 152 | ||
150 | /* B.4.2 Class-Specific AS Interface Descriptor */ | 153 | /* B.4.2 Class-Specific AS Interface Descriptor */ |
151 | static struct usb_as_header_descriptor as_header_desc = { | 154 | static struct uac_as_header_descriptor as_header_desc = { |
152 | .bLength = USB_DT_AS_HEADER_SIZE, | 155 | .bLength = UAC_DT_AS_HEADER_SIZE, |
153 | .bDescriptorType = USB_DT_CS_INTERFACE, | 156 | .bDescriptorType = USB_DT_CS_INTERFACE, |
154 | .bDescriptorSubtype = AS_GENERAL, | 157 | .bDescriptorSubtype = UAC_AS_GENERAL, |
155 | .bTerminalLink = INPUT_TERMINAL_ID, | 158 | .bTerminalLink = INPUT_TERMINAL_ID, |
156 | .bDelay = 1, | 159 | .bDelay = 1, |
157 | .wFormatTag = USB_AS_AUDIO_FORMAT_TYPE_I_PCM, | 160 | .wFormatTag = UAC_FORMAT_TYPE_I_PCM, |
158 | }; | 161 | }; |
159 | 162 | ||
160 | DECLARE_USB_AS_FORMAT_TYPE_I_DISCRETE_DESC(1); | 163 | DECLARE_UAC_FORMAT_TYPE_I_DISCRETE_DESC(1); |
161 | 164 | ||
162 | static struct usb_as_formate_type_i_discrete_descriptor_1 as_type_i_desc = { | 165 | static struct uac_format_type_i_discrete_descriptor_1 as_type_i_desc = { |
163 | .bLength = USB_AS_FORMAT_TYPE_I_DISCRETE_DESC_SIZE(1), | 166 | .bLength = UAC_FORMAT_TYPE_I_DISCRETE_DESC_SIZE(1), |
164 | .bDescriptorType = USB_DT_CS_INTERFACE, | 167 | .bDescriptorType = USB_DT_CS_INTERFACE, |
165 | .bDescriptorSubtype = FORMAT_TYPE, | 168 | .bDescriptorSubtype = UAC_FORMAT_TYPE, |
166 | .bFormatType = USB_AS_FORMAT_TYPE_I, | 169 | .bFormatType = UAC_FORMAT_TYPE_I, |
167 | .bSubframeSize = 2, | 170 | .bSubframeSize = 2, |
168 | .bBitResolution = 16, | 171 | .bBitResolution = 16, |
169 | .bSamFreqType = 1, | 172 | .bSamFreqType = 1, |
@@ -174,17 +177,17 @@ static struct usb_endpoint_descriptor as_out_ep_desc __initdata = { | |||
174 | .bLength = USB_DT_ENDPOINT_AUDIO_SIZE, | 177 | .bLength = USB_DT_ENDPOINT_AUDIO_SIZE, |
175 | .bDescriptorType = USB_DT_ENDPOINT, | 178 | .bDescriptorType = USB_DT_ENDPOINT, |
176 | .bEndpointAddress = USB_DIR_OUT, | 179 | .bEndpointAddress = USB_DIR_OUT, |
177 | .bmAttributes = USB_AS_ENDPOINT_ADAPTIVE | 180 | .bmAttributes = USB_ENDPOINT_SYNC_ADAPTIVE |
178 | | USB_ENDPOINT_XFER_ISOC, | 181 | | USB_ENDPOINT_XFER_ISOC, |
179 | .wMaxPacketSize = __constant_cpu_to_le16(OUT_EP_MAX_PACKET_SIZE), | 182 | .wMaxPacketSize = __constant_cpu_to_le16(OUT_EP_MAX_PACKET_SIZE), |
180 | .bInterval = 4, | 183 | .bInterval = 4, |
181 | }; | 184 | }; |
182 | 185 | ||
183 | /* Class-specific AS ISO OUT Endpoint Descriptor */ | 186 | /* Class-specific AS ISO OUT Endpoint Descriptor */ |
184 | static struct usb_as_iso_endpoint_descriptor as_iso_out_desc __initdata = { | 187 | static struct uac_iso_endpoint_descriptor as_iso_out_desc __initdata = { |
185 | .bLength = USB_AS_ISO_ENDPOINT_DESC_SIZE, | 188 | .bLength = UAC_ISO_ENDPOINT_DESC_SIZE, |
186 | .bDescriptorType = USB_DT_CS_ENDPOINT, | 189 | .bDescriptorType = USB_DT_CS_ENDPOINT, |
187 | .bDescriptorSubtype = EP_GENERAL, | 190 | .bDescriptorSubtype = UAC_EP_GENERAL, |
188 | .bmAttributes = 1, | 191 | .bmAttributes = 1, |
189 | .bLockDelayUnits = 1, | 192 | .bLockDelayUnits = 1, |
190 | .wLockDelay = __constant_cpu_to_le16(1), | 193 | .wLockDelay = __constant_cpu_to_le16(1), |
@@ -456,11 +459,11 @@ f_audio_setup(struct usb_function *f, const struct usb_ctrlrequest *ctrl) | |||
456 | * Audio class messages; interface activation uses set_alt(). | 459 | * Audio class messages; interface activation uses set_alt(). |
457 | */ | 460 | */ |
458 | switch (ctrl->bRequestType) { | 461 | switch (ctrl->bRequestType) { |
459 | case USB_AUDIO_SET_INTF: | 462 | case USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE: |
460 | value = audio_set_intf_req(f, ctrl); | 463 | value = audio_set_intf_req(f, ctrl); |
461 | break; | 464 | break; |
462 | 465 | ||
463 | case USB_AUDIO_GET_INTF: | 466 | case USB_DIR_IN | USB_TYPE_CLASS | USB_RECIP_INTERFACE: |
464 | value = audio_get_intf_req(f, ctrl); | 467 | value = audio_get_intf_req(f, ctrl); |
465 | break; | 468 | break; |
466 | 469 | ||
@@ -632,6 +635,18 @@ f_audio_unbind(struct usb_configuration *c, struct usb_function *f) | |||
632 | 635 | ||
633 | /*-------------------------------------------------------------------------*/ | 636 | /*-------------------------------------------------------------------------*/ |
634 | 637 | ||
638 | static int generic_set_cmd(struct usb_audio_control *con, u8 cmd, int value) | ||
639 | { | ||
640 | con->data[cmd] = value; | ||
641 | |||
642 | return 0; | ||
643 | } | ||
644 | |||
645 | static int generic_get_cmd(struct usb_audio_control *con, u8 cmd) | ||
646 | { | ||
647 | return con->data[cmd]; | ||
648 | } | ||
649 | |||
635 | /* Todo: add more control selecotor dynamically */ | 650 | /* Todo: add more control selecotor dynamically */ |
636 | int __init control_selector_init(struct f_audio *audio) | 651 | int __init control_selector_init(struct f_audio *audio) |
637 | { | 652 | { |
@@ -642,10 +657,10 @@ int __init control_selector_init(struct f_audio *audio) | |||
642 | list_add(&mute_control.list, &feature_unit.control); | 657 | list_add(&mute_control.list, &feature_unit.control); |
643 | list_add(&volume_control.list, &feature_unit.control); | 658 | list_add(&volume_control.list, &feature_unit.control); |
644 | 659 | ||
645 | volume_control.data[_CUR] = 0xffc0; | 660 | volume_control.data[UAC__CUR] = 0xffc0; |
646 | volume_control.data[_MIN] = 0xe3a0; | 661 | volume_control.data[UAC__MIN] = 0xe3a0; |
647 | volume_control.data[_MAX] = 0xfff0; | 662 | volume_control.data[UAC__MAX] = 0xfff0; |
648 | volume_control.data[_RES] = 0x0030; | 663 | volume_control.data[UAC__RES] = 0x0030; |
649 | 664 | ||
650 | return 0; | 665 | return 0; |
651 | } | 666 | } |
diff --git a/drivers/usb/gadget/f_eem.c b/drivers/usb/gadget/f_eem.c new file mode 100644 index 000000000000..0a577d5694fd --- /dev/null +++ b/drivers/usb/gadget/f_eem.c | |||
@@ -0,0 +1,562 @@ | |||
1 | /* | ||
2 | * f_eem.c -- USB CDC Ethernet (EEM) link function driver | ||
3 | * | ||
4 | * Copyright (C) 2003-2005,2008 David Brownell | ||
5 | * Copyright (C) 2008 Nokia Corporation | ||
6 | * Copyright (C) 2009 EF Johnson Technologies | ||
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 | #include <linux/kernel.h> | ||
24 | #include <linux/device.h> | ||
25 | #include <linux/etherdevice.h> | ||
26 | #include <linux/crc32.h> | ||
27 | |||
28 | #include "u_ether.h" | ||
29 | |||
30 | #define EEM_HLEN 2 | ||
31 | |||
32 | /* | ||
33 | * This function is a "CDC Ethernet Emulation Model" (CDC EEM) | ||
34 | * Ethernet link. | ||
35 | */ | ||
36 | |||
37 | struct eem_ep_descs { | ||
38 | struct usb_endpoint_descriptor *in; | ||
39 | struct usb_endpoint_descriptor *out; | ||
40 | }; | ||
41 | |||
42 | struct f_eem { | ||
43 | struct gether port; | ||
44 | u8 ctrl_id; | ||
45 | |||
46 | struct eem_ep_descs fs; | ||
47 | struct eem_ep_descs hs; | ||
48 | }; | ||
49 | |||
50 | static inline struct f_eem *func_to_eem(struct usb_function *f) | ||
51 | { | ||
52 | return container_of(f, struct f_eem, port.func); | ||
53 | } | ||
54 | |||
55 | /*-------------------------------------------------------------------------*/ | ||
56 | |||
57 | /* interface descriptor: */ | ||
58 | |||
59 | static struct usb_interface_descriptor eem_intf __initdata = { | ||
60 | .bLength = sizeof eem_intf, | ||
61 | .bDescriptorType = USB_DT_INTERFACE, | ||
62 | |||
63 | /* .bInterfaceNumber = DYNAMIC */ | ||
64 | .bNumEndpoints = 2, | ||
65 | .bInterfaceClass = USB_CLASS_COMM, | ||
66 | .bInterfaceSubClass = USB_CDC_SUBCLASS_EEM, | ||
67 | .bInterfaceProtocol = USB_CDC_PROTO_EEM, | ||
68 | /* .iInterface = DYNAMIC */ | ||
69 | }; | ||
70 | |||
71 | /* full speed support: */ | ||
72 | |||
73 | static struct usb_endpoint_descriptor eem_fs_in_desc __initdata = { | ||
74 | .bLength = USB_DT_ENDPOINT_SIZE, | ||
75 | .bDescriptorType = USB_DT_ENDPOINT, | ||
76 | |||
77 | .bEndpointAddress = USB_DIR_IN, | ||
78 | .bmAttributes = USB_ENDPOINT_XFER_BULK, | ||
79 | }; | ||
80 | |||
81 | static struct usb_endpoint_descriptor eem_fs_out_desc __initdata = { | ||
82 | .bLength = USB_DT_ENDPOINT_SIZE, | ||
83 | .bDescriptorType = USB_DT_ENDPOINT, | ||
84 | |||
85 | .bEndpointAddress = USB_DIR_OUT, | ||
86 | .bmAttributes = USB_ENDPOINT_XFER_BULK, | ||
87 | }; | ||
88 | |||
89 | static struct usb_descriptor_header *eem_fs_function[] __initdata = { | ||
90 | /* CDC EEM control descriptors */ | ||
91 | (struct usb_descriptor_header *) &eem_intf, | ||
92 | (struct usb_descriptor_header *) &eem_fs_in_desc, | ||
93 | (struct usb_descriptor_header *) &eem_fs_out_desc, | ||
94 | NULL, | ||
95 | }; | ||
96 | |||
97 | /* high speed support: */ | ||
98 | |||
99 | static struct usb_endpoint_descriptor eem_hs_in_desc __initdata = { | ||
100 | .bLength = USB_DT_ENDPOINT_SIZE, | ||
101 | .bDescriptorType = USB_DT_ENDPOINT, | ||
102 | |||
103 | .bEndpointAddress = USB_DIR_IN, | ||
104 | .bmAttributes = USB_ENDPOINT_XFER_BULK, | ||
105 | .wMaxPacketSize = cpu_to_le16(512), | ||
106 | }; | ||
107 | |||
108 | static struct usb_endpoint_descriptor eem_hs_out_desc __initdata = { | ||
109 | .bLength = USB_DT_ENDPOINT_SIZE, | ||
110 | .bDescriptorType = USB_DT_ENDPOINT, | ||
111 | |||
112 | .bEndpointAddress = USB_DIR_OUT, | ||
113 | .bmAttributes = USB_ENDPOINT_XFER_BULK, | ||
114 | .wMaxPacketSize = cpu_to_le16(512), | ||
115 | }; | ||
116 | |||
117 | static struct usb_descriptor_header *eem_hs_function[] __initdata = { | ||
118 | /* CDC EEM control descriptors */ | ||
119 | (struct usb_descriptor_header *) &eem_intf, | ||
120 | (struct usb_descriptor_header *) &eem_hs_in_desc, | ||
121 | (struct usb_descriptor_header *) &eem_hs_out_desc, | ||
122 | NULL, | ||
123 | }; | ||
124 | |||
125 | /* string descriptors: */ | ||
126 | |||
127 | static struct usb_string eem_string_defs[] = { | ||
128 | [0].s = "CDC Ethernet Emulation Model (EEM)", | ||
129 | { } /* end of list */ | ||
130 | }; | ||
131 | |||
132 | static struct usb_gadget_strings eem_string_table = { | ||
133 | .language = 0x0409, /* en-us */ | ||
134 | .strings = eem_string_defs, | ||
135 | }; | ||
136 | |||
137 | static struct usb_gadget_strings *eem_strings[] = { | ||
138 | &eem_string_table, | ||
139 | NULL, | ||
140 | }; | ||
141 | |||
142 | /*-------------------------------------------------------------------------*/ | ||
143 | |||
144 | static int eem_setup(struct usb_function *f, const struct usb_ctrlrequest *ctrl) | ||
145 | { | ||
146 | struct usb_composite_dev *cdev = f->config->cdev; | ||
147 | int value = -EOPNOTSUPP; | ||
148 | u16 w_index = le16_to_cpu(ctrl->wIndex); | ||
149 | u16 w_value = le16_to_cpu(ctrl->wValue); | ||
150 | u16 w_length = le16_to_cpu(ctrl->wLength); | ||
151 | |||
152 | DBG(cdev, "invalid control req%02x.%02x v%04x i%04x l%d\n", | ||
153 | ctrl->bRequestType, ctrl->bRequest, | ||
154 | w_value, w_index, w_length); | ||
155 | |||
156 | /* device either stalls (value < 0) or reports success */ | ||
157 | return value; | ||
158 | } | ||
159 | |||
160 | |||
161 | static int eem_set_alt(struct usb_function *f, unsigned intf, unsigned alt) | ||
162 | { | ||
163 | struct f_eem *eem = func_to_eem(f); | ||
164 | struct usb_composite_dev *cdev = f->config->cdev; | ||
165 | struct net_device *net; | ||
166 | |||
167 | /* we know alt == 0, so this is an activation or a reset */ | ||
168 | if (alt != 0) | ||
169 | goto fail; | ||
170 | |||
171 | if (intf == eem->ctrl_id) { | ||
172 | |||
173 | if (eem->port.in_ep->driver_data) { | ||
174 | DBG(cdev, "reset eem\n"); | ||
175 | gether_disconnect(&eem->port); | ||
176 | } | ||
177 | |||
178 | if (!eem->port.in) { | ||
179 | DBG(cdev, "init eem\n"); | ||
180 | eem->port.in = ep_choose(cdev->gadget, | ||
181 | eem->hs.in, eem->fs.in); | ||
182 | eem->port.out = ep_choose(cdev->gadget, | ||
183 | eem->hs.out, eem->fs.out); | ||
184 | } | ||
185 | |||
186 | /* zlps should not occur because zero-length EEM packets | ||
187 | * will be inserted in those cases where they would occur | ||
188 | */ | ||
189 | eem->port.is_zlp_ok = 1; | ||
190 | eem->port.cdc_filter = DEFAULT_FILTER; | ||
191 | DBG(cdev, "activate eem\n"); | ||
192 | net = gether_connect(&eem->port); | ||
193 | if (IS_ERR(net)) | ||
194 | return PTR_ERR(net); | ||
195 | } else | ||
196 | goto fail; | ||
197 | |||
198 | return 0; | ||
199 | fail: | ||
200 | return -EINVAL; | ||
201 | } | ||
202 | |||
203 | static void eem_disable(struct usb_function *f) | ||
204 | { | ||
205 | struct f_eem *eem = func_to_eem(f); | ||
206 | struct usb_composite_dev *cdev = f->config->cdev; | ||
207 | |||
208 | DBG(cdev, "eem deactivated\n"); | ||
209 | |||
210 | if (eem->port.in_ep->driver_data) | ||
211 | gether_disconnect(&eem->port); | ||
212 | } | ||
213 | |||
214 | /*-------------------------------------------------------------------------*/ | ||
215 | |||
216 | /* EEM function driver setup/binding */ | ||
217 | |||
218 | static int __init | ||
219 | eem_bind(struct usb_configuration *c, struct usb_function *f) | ||
220 | { | ||
221 | struct usb_composite_dev *cdev = c->cdev; | ||
222 | struct f_eem *eem = func_to_eem(f); | ||
223 | int status; | ||
224 | struct usb_ep *ep; | ||
225 | |||
226 | /* allocate instance-specific interface IDs */ | ||
227 | status = usb_interface_id(c, f); | ||
228 | if (status < 0) | ||
229 | goto fail; | ||
230 | eem->ctrl_id = status; | ||
231 | eem_intf.bInterfaceNumber = status; | ||
232 | |||
233 | status = -ENODEV; | ||
234 | |||
235 | /* allocate instance-specific endpoints */ | ||
236 | ep = usb_ep_autoconfig(cdev->gadget, &eem_fs_in_desc); | ||
237 | if (!ep) | ||
238 | goto fail; | ||
239 | eem->port.in_ep = ep; | ||
240 | ep->driver_data = cdev; /* claim */ | ||
241 | |||
242 | ep = usb_ep_autoconfig(cdev->gadget, &eem_fs_out_desc); | ||
243 | if (!ep) | ||
244 | goto fail; | ||
245 | eem->port.out_ep = ep; | ||
246 | ep->driver_data = cdev; /* claim */ | ||
247 | |||
248 | status = -ENOMEM; | ||
249 | |||
250 | /* copy descriptors, and track endpoint copies */ | ||
251 | f->descriptors = usb_copy_descriptors(eem_fs_function); | ||
252 | if (!f->descriptors) | ||
253 | goto fail; | ||
254 | |||
255 | eem->fs.in = usb_find_endpoint(eem_fs_function, | ||
256 | f->descriptors, &eem_fs_in_desc); | ||
257 | eem->fs.out = usb_find_endpoint(eem_fs_function, | ||
258 | f->descriptors, &eem_fs_out_desc); | ||
259 | |||
260 | /* support all relevant hardware speeds... we expect that when | ||
261 | * hardware is dual speed, all bulk-capable endpoints work at | ||
262 | * both speeds | ||
263 | */ | ||
264 | if (gadget_is_dualspeed(c->cdev->gadget)) { | ||
265 | eem_hs_in_desc.bEndpointAddress = | ||
266 | eem_fs_in_desc.bEndpointAddress; | ||
267 | eem_hs_out_desc.bEndpointAddress = | ||
268 | eem_fs_out_desc.bEndpointAddress; | ||
269 | |||
270 | /* copy descriptors, and track endpoint copies */ | ||
271 | f->hs_descriptors = usb_copy_descriptors(eem_hs_function); | ||
272 | if (!f->hs_descriptors) | ||
273 | goto fail; | ||
274 | |||
275 | eem->hs.in = usb_find_endpoint(eem_hs_function, | ||
276 | f->hs_descriptors, &eem_hs_in_desc); | ||
277 | eem->hs.out = usb_find_endpoint(eem_hs_function, | ||
278 | f->hs_descriptors, &eem_hs_out_desc); | ||
279 | } | ||
280 | |||
281 | DBG(cdev, "CDC Ethernet (EEM): %s speed IN/%s OUT/%s\n", | ||
282 | gadget_is_dualspeed(c->cdev->gadget) ? "dual" : "full", | ||
283 | eem->port.in_ep->name, eem->port.out_ep->name); | ||
284 | return 0; | ||
285 | |||
286 | fail: | ||
287 | if (f->descriptors) | ||
288 | usb_free_descriptors(f->descriptors); | ||
289 | |||
290 | /* we might as well release our claims on endpoints */ | ||
291 | if (eem->port.out) | ||
292 | eem->port.out_ep->driver_data = NULL; | ||
293 | if (eem->port.in) | ||
294 | eem->port.in_ep->driver_data = NULL; | ||
295 | |||
296 | ERROR(cdev, "%s: can't bind, err %d\n", f->name, status); | ||
297 | |||
298 | return status; | ||
299 | } | ||
300 | |||
301 | static void | ||
302 | eem_unbind(struct usb_configuration *c, struct usb_function *f) | ||
303 | { | ||
304 | struct f_eem *eem = func_to_eem(f); | ||
305 | |||
306 | DBG(c->cdev, "eem unbind\n"); | ||
307 | |||
308 | if (gadget_is_dualspeed(c->cdev->gadget)) | ||
309 | usb_free_descriptors(f->hs_descriptors); | ||
310 | usb_free_descriptors(f->descriptors); | ||
311 | kfree(eem); | ||
312 | } | ||
313 | |||
314 | static void eem_cmd_complete(struct usb_ep *ep, struct usb_request *req) | ||
315 | { | ||
316 | } | ||
317 | |||
318 | /* | ||
319 | * Add the EEM header and ethernet checksum. | ||
320 | * We currently do not attempt to put multiple ethernet frames | ||
321 | * into a single USB transfer | ||
322 | */ | ||
323 | static struct sk_buff *eem_wrap(struct gether *port, struct sk_buff *skb) | ||
324 | { | ||
325 | struct sk_buff *skb2 = NULL; | ||
326 | struct usb_ep *in = port->in_ep; | ||
327 | int padlen = 0; | ||
328 | u16 len = skb->len; | ||
329 | |||
330 | if (!skb_cloned(skb)) { | ||
331 | int headroom = skb_headroom(skb); | ||
332 | int tailroom = skb_tailroom(skb); | ||
333 | |||
334 | /* When (len + EEM_HLEN + ETH_FCS_LEN) % in->maxpacket) is 0, | ||
335 | * stick two bytes of zero-length EEM packet on the end. | ||
336 | */ | ||
337 | if (((len + EEM_HLEN + ETH_FCS_LEN) % in->maxpacket) == 0) | ||
338 | padlen += 2; | ||
339 | |||
340 | if ((tailroom >= (ETH_FCS_LEN + padlen)) && | ||
341 | (headroom >= EEM_HLEN)) | ||
342 | goto done; | ||
343 | } | ||
344 | |||
345 | skb2 = skb_copy_expand(skb, EEM_HLEN, ETH_FCS_LEN + padlen, GFP_ATOMIC); | ||
346 | dev_kfree_skb_any(skb); | ||
347 | skb = skb2; | ||
348 | if (!skb) | ||
349 | return skb; | ||
350 | |||
351 | done: | ||
352 | /* use the "no CRC" option */ | ||
353 | put_unaligned_be32(0xdeadbeef, skb_put(skb, 4)); | ||
354 | |||
355 | /* EEM packet header format: | ||
356 | * b0..13: length of ethernet frame | ||
357 | * b14: bmCRC (0 == sentinel CRC) | ||
358 | * b15: bmType (0 == data) | ||
359 | */ | ||
360 | len = skb->len; | ||
361 | put_unaligned_le16((len & 0x3FFF) | BIT(14), skb_push(skb, 2)); | ||
362 | |||
363 | /* add a zero-length EEM packet, if needed */ | ||
364 | if (padlen) | ||
365 | put_unaligned_le16(0, skb_put(skb, 2)); | ||
366 | |||
367 | return skb; | ||
368 | } | ||
369 | |||
370 | /* | ||
371 | * Remove the EEM header. Note that there can be many EEM packets in a single | ||
372 | * USB transfer, so we need to break them out and handle them independently. | ||
373 | */ | ||
374 | static int eem_unwrap(struct gether *port, | ||
375 | struct sk_buff *skb, | ||
376 | struct sk_buff_head *list) | ||
377 | { | ||
378 | struct usb_composite_dev *cdev = port->func.config->cdev; | ||
379 | int status = 0; | ||
380 | |||
381 | do { | ||
382 | struct sk_buff *skb2; | ||
383 | u16 header; | ||
384 | u16 len = 0; | ||
385 | |||
386 | if (skb->len < EEM_HLEN) { | ||
387 | status = -EINVAL; | ||
388 | DBG(cdev, "invalid EEM header\n"); | ||
389 | goto error; | ||
390 | } | ||
391 | |||
392 | /* remove the EEM header */ | ||
393 | header = get_unaligned_le16(skb->data); | ||
394 | skb_pull(skb, EEM_HLEN); | ||
395 | |||
396 | /* EEM packet header format: | ||
397 | * b0..14: EEM type dependent (data or command) | ||
398 | * b15: bmType (0 == data, 1 == command) | ||
399 | */ | ||
400 | if (header & BIT(15)) { | ||
401 | struct usb_request *req = cdev->req; | ||
402 | u16 bmEEMCmd; | ||
403 | |||
404 | /* EEM command packet format: | ||
405 | * b0..10: bmEEMCmdParam | ||
406 | * b11..13: bmEEMCmd | ||
407 | * b14: reserved (must be zero) | ||
408 | * b15: bmType (1 == command) | ||
409 | */ | ||
410 | if (header & BIT(14)) | ||
411 | continue; | ||
412 | |||
413 | bmEEMCmd = (header >> 11) & 0x7; | ||
414 | switch (bmEEMCmd) { | ||
415 | case 0: /* echo */ | ||
416 | len = header & 0x7FF; | ||
417 | if (skb->len < len) { | ||
418 | status = -EOVERFLOW; | ||
419 | goto error; | ||
420 | } | ||
421 | |||
422 | skb2 = skb_clone(skb, GFP_ATOMIC); | ||
423 | if (unlikely(!skb2)) { | ||
424 | DBG(cdev, "EEM echo response error\n"); | ||
425 | goto next; | ||
426 | } | ||
427 | skb_trim(skb2, len); | ||
428 | put_unaligned_le16(BIT(15) | BIT(11) | len, | ||
429 | skb_push(skb2, 2)); | ||
430 | skb_copy_bits(skb, 0, req->buf, skb->len); | ||
431 | req->length = skb->len; | ||
432 | req->complete = eem_cmd_complete; | ||
433 | req->zero = 1; | ||
434 | if (usb_ep_queue(port->in_ep, req, GFP_ATOMIC)) | ||
435 | DBG(cdev, "echo response queue fail\n"); | ||
436 | break; | ||
437 | |||
438 | case 1: /* echo response */ | ||
439 | case 2: /* suspend hint */ | ||
440 | case 3: /* response hint */ | ||
441 | case 4: /* response complete hint */ | ||
442 | case 5: /* tickle */ | ||
443 | default: /* reserved */ | ||
444 | continue; | ||
445 | } | ||
446 | } else { | ||
447 | u32 crc, crc2; | ||
448 | struct sk_buff *skb3; | ||
449 | |||
450 | /* check for zero-length EEM packet */ | ||
451 | if (header == 0) | ||
452 | continue; | ||
453 | |||
454 | /* EEM data packet format: | ||
455 | * b0..13: length of ethernet frame | ||
456 | * b14: bmCRC (0 == sentinel, 1 == calculated) | ||
457 | * b15: bmType (0 == data) | ||
458 | */ | ||
459 | len = header & 0x3FFF; | ||
460 | if ((skb->len < len) | ||
461 | || (len < (ETH_HLEN + ETH_FCS_LEN))) { | ||
462 | status = -EINVAL; | ||
463 | goto error; | ||
464 | } | ||
465 | |||
466 | /* validate CRC */ | ||
467 | crc = get_unaligned_le32(skb->data + len - ETH_FCS_LEN); | ||
468 | if (header & BIT(14)) { | ||
469 | crc = get_unaligned_le32(skb->data + len | ||
470 | - ETH_FCS_LEN); | ||
471 | crc2 = ~crc32_le(~0, | ||
472 | skb->data, | ||
473 | skb->len - ETH_FCS_LEN); | ||
474 | } else { | ||
475 | crc = get_unaligned_be32(skb->data + len | ||
476 | - ETH_FCS_LEN); | ||
477 | crc2 = 0xdeadbeef; | ||
478 | } | ||
479 | if (crc != crc2) { | ||
480 | DBG(cdev, "invalid EEM CRC\n"); | ||
481 | goto next; | ||
482 | } | ||
483 | |||
484 | skb2 = skb_clone(skb, GFP_ATOMIC); | ||
485 | if (unlikely(!skb2)) { | ||
486 | DBG(cdev, "unable to unframe EEM packet\n"); | ||
487 | continue; | ||
488 | } | ||
489 | skb_trim(skb2, len - ETH_FCS_LEN); | ||
490 | |||
491 | skb3 = skb_copy_expand(skb2, | ||
492 | NET_IP_ALIGN, | ||
493 | 0, | ||
494 | GFP_ATOMIC); | ||
495 | if (unlikely(!skb3)) { | ||
496 | DBG(cdev, "unable to realign EEM packet\n"); | ||
497 | dev_kfree_skb_any(skb2); | ||
498 | continue; | ||
499 | } | ||
500 | dev_kfree_skb_any(skb2); | ||
501 | skb_queue_tail(list, skb3); | ||
502 | } | ||
503 | next: | ||
504 | skb_pull(skb, len); | ||
505 | } while (skb->len); | ||
506 | |||
507 | error: | ||
508 | dev_kfree_skb_any(skb); | ||
509 | return status; | ||
510 | } | ||
511 | |||
512 | /** | ||
513 | * eem_bind_config - add CDC Ethernet (EEM) network link to a configuration | ||
514 | * @c: the configuration to support the network link | ||
515 | * Context: single threaded during gadget setup | ||
516 | * | ||
517 | * Returns zero on success, else negative errno. | ||
518 | * | ||
519 | * Caller must have called @gether_setup(). Caller is also responsible | ||
520 | * for calling @gether_cleanup() before module unload. | ||
521 | */ | ||
522 | int __init eem_bind_config(struct usb_configuration *c) | ||
523 | { | ||
524 | struct f_eem *eem; | ||
525 | int status; | ||
526 | |||
527 | /* maybe allocate device-global string IDs */ | ||
528 | if (eem_string_defs[0].id == 0) { | ||
529 | |||
530 | /* control interface label */ | ||
531 | status = usb_string_id(c->cdev); | ||
532 | if (status < 0) | ||
533 | return status; | ||
534 | eem_string_defs[0].id = status; | ||
535 | eem_intf.iInterface = status; | ||
536 | } | ||
537 | |||
538 | /* allocate and initialize one new instance */ | ||
539 | eem = kzalloc(sizeof *eem, GFP_KERNEL); | ||
540 | if (!eem) | ||
541 | return -ENOMEM; | ||
542 | |||
543 | eem->port.cdc_filter = DEFAULT_FILTER; | ||
544 | |||
545 | eem->port.func.name = "cdc_eem"; | ||
546 | eem->port.func.strings = eem_strings; | ||
547 | /* descriptors are per-instance copies */ | ||
548 | eem->port.func.bind = eem_bind; | ||
549 | eem->port.func.unbind = eem_unbind; | ||
550 | eem->port.func.set_alt = eem_set_alt; | ||
551 | eem->port.func.setup = eem_setup; | ||
552 | eem->port.func.disable = eem_disable; | ||
553 | eem->port.wrap = eem_wrap; | ||
554 | eem->port.unwrap = eem_unwrap; | ||
555 | eem->port.header_len = EEM_HLEN; | ||
556 | |||
557 | status = usb_add_function(c, &eem->port.func); | ||
558 | if (status) | ||
559 | kfree(eem); | ||
560 | return status; | ||
561 | } | ||
562 | |||
diff --git a/drivers/usb/gadget/f_loopback.c b/drivers/usb/gadget/f_loopback.c index eb6ddfc20857..6cb29d3df575 100644 --- a/drivers/usb/gadget/f_loopback.c +++ b/drivers/usb/gadget/f_loopback.c | |||
@@ -22,7 +22,6 @@ | |||
22 | /* #define VERBOSE_DEBUG */ | 22 | /* #define VERBOSE_DEBUG */ |
23 | 23 | ||
24 | #include <linux/kernel.h> | 24 | #include <linux/kernel.h> |
25 | #include <linux/utsname.h> | ||
26 | #include <linux/device.h> | 25 | #include <linux/device.h> |
27 | 26 | ||
28 | #include "g_zero.h" | 27 | #include "g_zero.h" |
diff --git a/drivers/usb/gadget/f_obex.c b/drivers/usb/gadget/f_obex.c index 46d6266f30ec..b4a3ba654ea5 100644 --- a/drivers/usb/gadget/f_obex.c +++ b/drivers/usb/gadget/f_obex.c | |||
@@ -24,7 +24,6 @@ | |||
24 | /* #define VERBOSE_DEBUG */ | 24 | /* #define VERBOSE_DEBUG */ |
25 | 25 | ||
26 | #include <linux/kernel.h> | 26 | #include <linux/kernel.h> |
27 | #include <linux/utsname.h> | ||
28 | #include <linux/device.h> | 27 | #include <linux/device.h> |
29 | 28 | ||
30 | #include "u_serial.h" | 29 | #include "u_serial.h" |
diff --git a/drivers/usb/gadget/f_rndis.c b/drivers/usb/gadget/f_rndis.c index 424a37c5773f..c9966cc07d3a 100644 --- a/drivers/usb/gadget/f_rndis.c +++ b/drivers/usb/gadget/f_rndis.c | |||
@@ -286,12 +286,17 @@ static struct usb_gadget_strings *rndis_strings[] = { | |||
286 | 286 | ||
287 | /*-------------------------------------------------------------------------*/ | 287 | /*-------------------------------------------------------------------------*/ |
288 | 288 | ||
289 | static struct sk_buff *rndis_add_header(struct sk_buff *skb) | 289 | static struct sk_buff *rndis_add_header(struct gether *port, |
290 | struct sk_buff *skb) | ||
290 | { | 291 | { |
291 | skb = skb_realloc_headroom(skb, sizeof(struct rndis_packet_msg_type)); | 292 | struct sk_buff *skb2; |
292 | if (skb) | 293 | |
293 | rndis_add_hdr(skb); | 294 | skb2 = skb_realloc_headroom(skb, sizeof(struct rndis_packet_msg_type)); |
294 | return skb; | 295 | if (skb2) |
296 | rndis_add_hdr(skb2); | ||
297 | |||
298 | dev_kfree_skb_any(skb); | ||
299 | return skb2; | ||
295 | } | 300 | } |
296 | 301 | ||
297 | static void rndis_response_available(void *_rndis) | 302 | static void rndis_response_available(void *_rndis) |
diff --git a/drivers/usb/gadget/f_sourcesink.c b/drivers/usb/gadget/f_sourcesink.c index bffe91d525f9..09cba273d2db 100644 --- a/drivers/usb/gadget/f_sourcesink.c +++ b/drivers/usb/gadget/f_sourcesink.c | |||
@@ -22,7 +22,6 @@ | |||
22 | /* #define VERBOSE_DEBUG */ | 22 | /* #define VERBOSE_DEBUG */ |
23 | 23 | ||
24 | #include <linux/kernel.h> | 24 | #include <linux/kernel.h> |
25 | #include <linux/utsname.h> | ||
26 | #include <linux/device.h> | 25 | #include <linux/device.h> |
27 | 26 | ||
28 | #include "g_zero.h" | 27 | #include "g_zero.h" |
diff --git a/drivers/usb/gadget/fsl_qe_udc.c b/drivers/usb/gadget/fsl_qe_udc.c index d701bf4698d2..7881f12413c4 100644 --- a/drivers/usb/gadget/fsl_qe_udc.c +++ b/drivers/usb/gadget/fsl_qe_udc.c | |||
@@ -2751,6 +2751,10 @@ static int __devexit qe_udc_remove(struct of_device *ofdev) | |||
2751 | /*-------------------------------------------------------------------------*/ | 2751 | /*-------------------------------------------------------------------------*/ |
2752 | static struct of_device_id __devinitdata qe_udc_match[] = { | 2752 | static struct of_device_id __devinitdata qe_udc_match[] = { |
2753 | { | 2753 | { |
2754 | .compatible = "fsl,mpc8323-qe-usb", | ||
2755 | .data = (void *)PORT_QE, | ||
2756 | }, | ||
2757 | { | ||
2754 | .compatible = "fsl,mpc8360-qe-usb", | 2758 | .compatible = "fsl,mpc8360-qe-usb", |
2755 | .data = (void *)PORT_QE, | 2759 | .data = (void *)PORT_QE, |
2756 | }, | 2760 | }, |
diff --git a/drivers/usb/gadget/gadget_chips.h b/drivers/usb/gadget/gadget_chips.h index 8e0e9a0b7364..f2d270b202f2 100644 --- a/drivers/usb/gadget/gadget_chips.h +++ b/drivers/usb/gadget/gadget_chips.h | |||
@@ -173,6 +173,12 @@ | |||
173 | // CONFIG_USB_GADGET_AU1X00 | 173 | // CONFIG_USB_GADGET_AU1X00 |
174 | // ... | 174 | // ... |
175 | 175 | ||
176 | #ifdef CONFIG_USB_GADGET_R8A66597 | ||
177 | #define gadget_is_r8a66597(g) !strcmp("r8a66597_udc", (g)->name) | ||
178 | #else | ||
179 | #define gadget_is_r8a66597(g) 0 | ||
180 | #endif | ||
181 | |||
176 | 182 | ||
177 | /** | 183 | /** |
178 | * usb_gadget_controller_number - support bcdDevice id convention | 184 | * usb_gadget_controller_number - support bcdDevice id convention |
@@ -239,6 +245,8 @@ static inline int usb_gadget_controller_number(struct usb_gadget *gadget) | |||
239 | return 0x23; | 245 | return 0x23; |
240 | else if (gadget_is_langwell(gadget)) | 246 | else if (gadget_is_langwell(gadget)) |
241 | return 0x24; | 247 | return 0x24; |
248 | else if (gadget_is_r8a66597(gadget)) | ||
249 | return 0x25; | ||
242 | return -ENOENT; | 250 | return -ENOENT; |
243 | } | 251 | } |
244 | 252 | ||
diff --git a/drivers/usb/gadget/gmidi.c b/drivers/usb/gadget/gmidi.c index b9312dc6e041..d0b1e836f0e0 100644 --- a/drivers/usb/gadget/gmidi.c +++ b/drivers/usb/gadget/gmidi.c | |||
@@ -191,7 +191,7 @@ module_param(qlen, uint, S_IRUGO); | |||
191 | #define GMIDI_MS_INTERFACE 1 | 191 | #define GMIDI_MS_INTERFACE 1 |
192 | #define GMIDI_NUM_INTERFACES 2 | 192 | #define GMIDI_NUM_INTERFACES 2 |
193 | 193 | ||
194 | DECLARE_USB_AC_HEADER_DESCRIPTOR(1); | 194 | DECLARE_UAC_AC_HEADER_DESCRIPTOR(1); |
195 | DECLARE_USB_MIDI_OUT_JACK_DESCRIPTOR(1); | 195 | DECLARE_USB_MIDI_OUT_JACK_DESCRIPTOR(1); |
196 | DECLARE_USB_MS_ENDPOINT_DESCRIPTOR(1); | 196 | DECLARE_USB_MS_ENDPOINT_DESCRIPTOR(1); |
197 | 197 | ||
@@ -237,12 +237,12 @@ static const struct usb_interface_descriptor ac_interface_desc = { | |||
237 | }; | 237 | }; |
238 | 238 | ||
239 | /* B.3.2 Class-Specific AC Interface Descriptor */ | 239 | /* B.3.2 Class-Specific AC Interface Descriptor */ |
240 | static const struct usb_ac_header_descriptor_1 ac_header_desc = { | 240 | static const struct uac_ac_header_descriptor_1 ac_header_desc = { |
241 | .bLength = USB_DT_AC_HEADER_SIZE(1), | 241 | .bLength = UAC_DT_AC_HEADER_SIZE(1), |
242 | .bDescriptorType = USB_DT_CS_INTERFACE, | 242 | .bDescriptorType = USB_DT_CS_INTERFACE, |
243 | .bDescriptorSubtype = USB_MS_HEADER, | 243 | .bDescriptorSubtype = USB_MS_HEADER, |
244 | .bcdADC = cpu_to_le16(0x0100), | 244 | .bcdADC = cpu_to_le16(0x0100), |
245 | .wTotalLength = cpu_to_le16(USB_DT_AC_HEADER_SIZE(1)), | 245 | .wTotalLength = cpu_to_le16(UAC_DT_AC_HEADER_SIZE(1)), |
246 | .bInCollection = 1, | 246 | .bInCollection = 1, |
247 | .baInterfaceNr = { | 247 | .baInterfaceNr = { |
248 | [0] = GMIDI_MS_INTERFACE, | 248 | [0] = GMIDI_MS_INTERFACE, |
diff --git a/drivers/usb/gadget/inode.c b/drivers/usb/gadget/inode.c index 7d33f50b5874..c44367fea185 100644 --- a/drivers/usb/gadget/inode.c +++ b/drivers/usb/gadget/inode.c | |||
@@ -2033,7 +2033,7 @@ gadgetfs_create_file (struct super_block *sb, char const *name, | |||
2033 | return inode; | 2033 | return inode; |
2034 | } | 2034 | } |
2035 | 2035 | ||
2036 | static struct super_operations gadget_fs_operations = { | 2036 | static const struct super_operations gadget_fs_operations = { |
2037 | .statfs = simple_statfs, | 2037 | .statfs = simple_statfs, |
2038 | .drop_inode = generic_delete_inode, | 2038 | .drop_inode = generic_delete_inode, |
2039 | }; | 2039 | }; |
diff --git a/drivers/usb/gadget/m66592-udc.c b/drivers/usb/gadget/m66592-udc.c index 43dcf9e1af6b..a8c8543d1b08 100644 --- a/drivers/usb/gadget/m66592-udc.c +++ b/drivers/usb/gadget/m66592-udc.c | |||
@@ -25,44 +25,18 @@ | |||
25 | #include <linux/delay.h> | 25 | #include <linux/delay.h> |
26 | #include <linux/io.h> | 26 | #include <linux/io.h> |
27 | #include <linux/platform_device.h> | 27 | #include <linux/platform_device.h> |
28 | 28 | #include <linux/err.h> | |
29 | #include <linux/usb/ch9.h> | 29 | #include <linux/usb/ch9.h> |
30 | #include <linux/usb/gadget.h> | 30 | #include <linux/usb/gadget.h> |
31 | 31 | ||
32 | #include "m66592-udc.h" | 32 | #include "m66592-udc.h" |
33 | 33 | ||
34 | |||
35 | MODULE_DESCRIPTION("M66592 USB gadget driver"); | 34 | MODULE_DESCRIPTION("M66592 USB gadget driver"); |
36 | MODULE_LICENSE("GPL"); | 35 | MODULE_LICENSE("GPL"); |
37 | MODULE_AUTHOR("Yoshihiro Shimoda"); | 36 | MODULE_AUTHOR("Yoshihiro Shimoda"); |
38 | MODULE_ALIAS("platform:m66592_udc"); | 37 | MODULE_ALIAS("platform:m66592_udc"); |
39 | 38 | ||
40 | #define DRIVER_VERSION "18 Oct 2007" | 39 | #define DRIVER_VERSION "21 July 2009" |
41 | |||
42 | /* module parameters */ | ||
43 | #if defined(CONFIG_SUPERH_BUILT_IN_M66592) | ||
44 | static unsigned short endian = M66592_LITTLE; | ||
45 | module_param(endian, ushort, 0644); | ||
46 | MODULE_PARM_DESC(endian, "data endian: big=0, little=0 (default=0)"); | ||
47 | #else | ||
48 | static unsigned short clock = M66592_XTAL24; | ||
49 | module_param(clock, ushort, 0644); | ||
50 | MODULE_PARM_DESC(clock, "input clock: 48MHz=32768, 24MHz=16384, 12MHz=0 " | ||
51 | "(default=16384)"); | ||
52 | |||
53 | static unsigned short vif = M66592_LDRV; | ||
54 | module_param(vif, ushort, 0644); | ||
55 | MODULE_PARM_DESC(vif, "input VIF: 3.3V=32768, 1.5V=0 (default=32768)"); | ||
56 | |||
57 | static unsigned short endian; | ||
58 | module_param(endian, ushort, 0644); | ||
59 | MODULE_PARM_DESC(endian, "data endian: big=256, little=0 (default=0)"); | ||
60 | |||
61 | static unsigned short irq_sense = M66592_INTL; | ||
62 | module_param(irq_sense, ushort, 0644); | ||
63 | MODULE_PARM_DESC(irq_sense, "IRQ sense: low level=2, falling edge=0 " | ||
64 | "(default=2)"); | ||
65 | #endif | ||
66 | 40 | ||
67 | static const char udc_name[] = "m66592_udc"; | 41 | static const char udc_name[] = "m66592_udc"; |
68 | static const char *m66592_ep_name[] = { | 42 | static const char *m66592_ep_name[] = { |
@@ -244,6 +218,7 @@ static inline int get_buffer_size(struct m66592 *m66592, u16 pipenum) | |||
244 | static inline void pipe_change(struct m66592 *m66592, u16 pipenum) | 218 | static inline void pipe_change(struct m66592 *m66592, u16 pipenum) |
245 | { | 219 | { |
246 | struct m66592_ep *ep = m66592->pipenum2ep[pipenum]; | 220 | struct m66592_ep *ep = m66592->pipenum2ep[pipenum]; |
221 | unsigned short mbw; | ||
247 | 222 | ||
248 | if (ep->use_dma) | 223 | if (ep->use_dma) |
249 | return; | 224 | return; |
@@ -252,7 +227,12 @@ static inline void pipe_change(struct m66592 *m66592, u16 pipenum) | |||
252 | 227 | ||
253 | ndelay(450); | 228 | ndelay(450); |
254 | 229 | ||
255 | m66592_bset(m66592, M66592_MBW, ep->fifosel); | 230 | if (m66592->pdata->on_chip) |
231 | mbw = M66592_MBW_32; | ||
232 | else | ||
233 | mbw = M66592_MBW_16; | ||
234 | |||
235 | m66592_bset(m66592, mbw, ep->fifosel); | ||
256 | } | 236 | } |
257 | 237 | ||
258 | static int pipe_buffer_setting(struct m66592 *m66592, | 238 | static int pipe_buffer_setting(struct m66592 *m66592, |
@@ -276,24 +256,27 @@ static int pipe_buffer_setting(struct m66592 *m66592, | |||
276 | buf_bsize = 0; | 256 | buf_bsize = 0; |
277 | break; | 257 | break; |
278 | case M66592_BULK: | 258 | case M66592_BULK: |
279 | bufnum = m66592->bi_bufnum + | 259 | /* isochronous pipes may be used as bulk pipes */ |
280 | (info->pipe - M66592_BASE_PIPENUM_BULK) * 16; | 260 | if (info->pipe > M66592_BASE_PIPENUM_BULK) |
281 | m66592->bi_bufnum += 16; | 261 | bufnum = info->pipe - M66592_BASE_PIPENUM_BULK; |
262 | else | ||
263 | bufnum = info->pipe - M66592_BASE_PIPENUM_ISOC; | ||
264 | |||
265 | bufnum = M66592_BASE_BUFNUM + (bufnum * 16); | ||
282 | buf_bsize = 7; | 266 | buf_bsize = 7; |
283 | pipecfg |= M66592_DBLB; | 267 | pipecfg |= M66592_DBLB; |
284 | if (!info->dir_in) | 268 | if (!info->dir_in) |
285 | pipecfg |= M66592_SHTNAK; | 269 | pipecfg |= M66592_SHTNAK; |
286 | break; | 270 | break; |
287 | case M66592_ISO: | 271 | case M66592_ISO: |
288 | bufnum = m66592->bi_bufnum + | 272 | bufnum = M66592_BASE_BUFNUM + |
289 | (info->pipe - M66592_BASE_PIPENUM_ISOC) * 16; | 273 | (info->pipe - M66592_BASE_PIPENUM_ISOC) * 16; |
290 | m66592->bi_bufnum += 16; | ||
291 | buf_bsize = 7; | 274 | buf_bsize = 7; |
292 | break; | 275 | break; |
293 | } | 276 | } |
294 | if (m66592->bi_bufnum > M66592_MAX_BUFNUM) { | 277 | |
295 | pr_err("m66592 pipe memory is insufficient(%d)\n", | 278 | if (buf_bsize && ((bufnum + 16) >= M66592_MAX_BUFNUM)) { |
296 | m66592->bi_bufnum); | 279 | pr_err("m66592 pipe memory is insufficient\n"); |
297 | return -ENOMEM; | 280 | return -ENOMEM; |
298 | } | 281 | } |
299 | 282 | ||
@@ -313,17 +296,6 @@ static void pipe_buffer_release(struct m66592 *m66592, | |||
313 | if (info->pipe == 0) | 296 | if (info->pipe == 0) |
314 | return; | 297 | return; |
315 | 298 | ||
316 | switch (info->type) { | ||
317 | case M66592_BULK: | ||
318 | if (is_bulk_pipe(info->pipe)) | ||
319 | m66592->bi_bufnum -= 16; | ||
320 | break; | ||
321 | case M66592_ISO: | ||
322 | if (is_isoc_pipe(info->pipe)) | ||
323 | m66592->bi_bufnum -= 16; | ||
324 | break; | ||
325 | } | ||
326 | |||
327 | if (is_bulk_pipe(info->pipe)) { | 299 | if (is_bulk_pipe(info->pipe)) { |
328 | m66592->bulk--; | 300 | m66592->bulk--; |
329 | } else if (is_interrupt_pipe(info->pipe)) | 301 | } else if (is_interrupt_pipe(info->pipe)) |
@@ -340,6 +312,7 @@ static void pipe_buffer_release(struct m66592 *m66592, | |||
340 | static void pipe_initialize(struct m66592_ep *ep) | 312 | static void pipe_initialize(struct m66592_ep *ep) |
341 | { | 313 | { |
342 | struct m66592 *m66592 = ep->m66592; | 314 | struct m66592 *m66592 = ep->m66592; |
315 | unsigned short mbw; | ||
343 | 316 | ||
344 | m66592_mdfy(m66592, 0, M66592_CURPIPE, ep->fifosel); | 317 | m66592_mdfy(m66592, 0, M66592_CURPIPE, ep->fifosel); |
345 | 318 | ||
@@ -351,7 +324,12 @@ static void pipe_initialize(struct m66592_ep *ep) | |||
351 | 324 | ||
352 | ndelay(450); | 325 | ndelay(450); |
353 | 326 | ||
354 | m66592_bset(m66592, M66592_MBW, ep->fifosel); | 327 | if (m66592->pdata->on_chip) |
328 | mbw = M66592_MBW_32; | ||
329 | else | ||
330 | mbw = M66592_MBW_16; | ||
331 | |||
332 | m66592_bset(m66592, mbw, ep->fifosel); | ||
355 | } | 333 | } |
356 | } | 334 | } |
357 | 335 | ||
@@ -367,15 +345,13 @@ static void m66592_ep_setting(struct m66592 *m66592, struct m66592_ep *ep, | |||
367 | ep->fifosel = M66592_D0FIFOSEL; | 345 | ep->fifosel = M66592_D0FIFOSEL; |
368 | ep->fifoctr = M66592_D0FIFOCTR; | 346 | ep->fifoctr = M66592_D0FIFOCTR; |
369 | ep->fifotrn = M66592_D0FIFOTRN; | 347 | ep->fifotrn = M66592_D0FIFOTRN; |
370 | #if !defined(CONFIG_SUPERH_BUILT_IN_M66592) | 348 | } else if (!m66592->pdata->on_chip && m66592->num_dma == 1) { |
371 | } else if (m66592->num_dma == 1) { | ||
372 | m66592->num_dma++; | 349 | m66592->num_dma++; |
373 | ep->use_dma = 1; | 350 | ep->use_dma = 1; |
374 | ep->fifoaddr = M66592_D1FIFO; | 351 | ep->fifoaddr = M66592_D1FIFO; |
375 | ep->fifosel = M66592_D1FIFOSEL; | 352 | ep->fifosel = M66592_D1FIFOSEL; |
376 | ep->fifoctr = M66592_D1FIFOCTR; | 353 | ep->fifoctr = M66592_D1FIFOCTR; |
377 | ep->fifotrn = M66592_D1FIFOTRN; | 354 | ep->fifotrn = M66592_D1FIFOTRN; |
378 | #endif | ||
379 | } else { | 355 | } else { |
380 | ep->use_dma = 0; | 356 | ep->use_dma = 0; |
381 | ep->fifoaddr = M66592_CFIFO; | 357 | ep->fifoaddr = M66592_CFIFO; |
@@ -620,76 +596,120 @@ static void start_ep0(struct m66592_ep *ep, struct m66592_request *req) | |||
620 | } | 596 | } |
621 | } | 597 | } |
622 | 598 | ||
623 | #if defined(CONFIG_SUPERH_BUILT_IN_M66592) | ||
624 | static void init_controller(struct m66592 *m66592) | 599 | static void init_controller(struct m66592 *m66592) |
625 | { | 600 | { |
626 | m66592_bset(m66592, M66592_HSE, M66592_SYSCFG); /* High spd */ | 601 | unsigned int endian; |
627 | m66592_bclr(m66592, M66592_USBE, M66592_SYSCFG); | ||
628 | m66592_bclr(m66592, M66592_DPRPU, M66592_SYSCFG); | ||
629 | m66592_bset(m66592, M66592_USBE, M66592_SYSCFG); | ||
630 | 602 | ||
631 | /* This is a workaound for SH7722 2nd cut */ | 603 | if (m66592->pdata->on_chip) { |
632 | m66592_bset(m66592, 0x8000, M66592_DVSTCTR); | 604 | if (m66592->pdata->endian) |
633 | m66592_bset(m66592, 0x1000, M66592_TESTMODE); | 605 | endian = 0; /* big endian */ |
634 | m66592_bclr(m66592, 0x8000, M66592_DVSTCTR); | 606 | else |
607 | endian = M66592_LITTLE; /* little endian */ | ||
635 | 608 | ||
636 | m66592_bset(m66592, M66592_INTL, M66592_INTENB1); | 609 | m66592_bset(m66592, M66592_HSE, M66592_SYSCFG); /* High spd */ |
610 | m66592_bclr(m66592, M66592_USBE, M66592_SYSCFG); | ||
611 | m66592_bclr(m66592, M66592_DPRPU, M66592_SYSCFG); | ||
612 | m66592_bset(m66592, M66592_USBE, M66592_SYSCFG); | ||
637 | 613 | ||
638 | m66592_write(m66592, 0, M66592_CFBCFG); | 614 | /* This is a workaound for SH7722 2nd cut */ |
639 | m66592_write(m66592, 0, M66592_D0FBCFG); | 615 | m66592_bset(m66592, 0x8000, M66592_DVSTCTR); |
640 | m66592_bset(m66592, endian, M66592_CFBCFG); | 616 | m66592_bset(m66592, 0x1000, M66592_TESTMODE); |
641 | m66592_bset(m66592, endian, M66592_D0FBCFG); | 617 | m66592_bclr(m66592, 0x8000, M66592_DVSTCTR); |
642 | } | ||
643 | #else /* #if defined(CONFIG_SUPERH_BUILT_IN_M66592) */ | ||
644 | static void init_controller(struct m66592 *m66592) | ||
645 | { | ||
646 | m66592_bset(m66592, (vif & M66592_LDRV) | (endian & M66592_BIGEND), | ||
647 | M66592_PINCFG); | ||
648 | m66592_bset(m66592, M66592_HSE, M66592_SYSCFG); /* High spd */ | ||
649 | m66592_mdfy(m66592, clock & M66592_XTAL, M66592_XTAL, M66592_SYSCFG); | ||
650 | 618 | ||
651 | m66592_bclr(m66592, M66592_USBE, M66592_SYSCFG); | 619 | m66592_bset(m66592, M66592_INTL, M66592_INTENB1); |
652 | m66592_bclr(m66592, M66592_DPRPU, M66592_SYSCFG); | 620 | |
653 | m66592_bset(m66592, M66592_USBE, M66592_SYSCFG); | 621 | m66592_write(m66592, 0, M66592_CFBCFG); |
622 | m66592_write(m66592, 0, M66592_D0FBCFG); | ||
623 | m66592_bset(m66592, endian, M66592_CFBCFG); | ||
624 | m66592_bset(m66592, endian, M66592_D0FBCFG); | ||
625 | } else { | ||
626 | unsigned int clock, vif, irq_sense; | ||
627 | |||
628 | if (m66592->pdata->endian) | ||
629 | endian = M66592_BIGEND; /* big endian */ | ||
630 | else | ||
631 | endian = 0; /* little endian */ | ||
632 | |||
633 | if (m66592->pdata->vif) | ||
634 | vif = M66592_LDRV; /* 3.3v */ | ||
635 | else | ||
636 | vif = 0; /* 1.5v */ | ||
637 | |||
638 | switch (m66592->pdata->xtal) { | ||
639 | case M66592_PLATDATA_XTAL_12MHZ: | ||
640 | clock = M66592_XTAL12; | ||
641 | break; | ||
642 | case M66592_PLATDATA_XTAL_24MHZ: | ||
643 | clock = M66592_XTAL24; | ||
644 | break; | ||
645 | case M66592_PLATDATA_XTAL_48MHZ: | ||
646 | clock = M66592_XTAL48; | ||
647 | break; | ||
648 | default: | ||
649 | pr_warning("m66592-udc: xtal configuration error\n"); | ||
650 | clock = 0; | ||
651 | } | ||
652 | |||
653 | switch (m66592->irq_trigger) { | ||
654 | case IRQF_TRIGGER_LOW: | ||
655 | irq_sense = M66592_INTL; | ||
656 | break; | ||
657 | case IRQF_TRIGGER_FALLING: | ||
658 | irq_sense = 0; | ||
659 | break; | ||
660 | default: | ||
661 | pr_warning("m66592-udc: irq trigger config error\n"); | ||
662 | irq_sense = 0; | ||
663 | } | ||
654 | 664 | ||
655 | m66592_bset(m66592, M66592_XCKE, M66592_SYSCFG); | 665 | m66592_bset(m66592, |
666 | (vif & M66592_LDRV) | (endian & M66592_BIGEND), | ||
667 | M66592_PINCFG); | ||
668 | m66592_bset(m66592, M66592_HSE, M66592_SYSCFG); /* High spd */ | ||
669 | m66592_mdfy(m66592, clock & M66592_XTAL, M66592_XTAL, | ||
670 | M66592_SYSCFG); | ||
671 | m66592_bclr(m66592, M66592_USBE, M66592_SYSCFG); | ||
672 | m66592_bclr(m66592, M66592_DPRPU, M66592_SYSCFG); | ||
673 | m66592_bset(m66592, M66592_USBE, M66592_SYSCFG); | ||
674 | |||
675 | m66592_bset(m66592, M66592_XCKE, M66592_SYSCFG); | ||
656 | 676 | ||
657 | msleep(3); | 677 | msleep(3); |
658 | 678 | ||
659 | m66592_bset(m66592, M66592_RCKE | M66592_PLLC, M66592_SYSCFG); | 679 | m66592_bset(m66592, M66592_RCKE | M66592_PLLC, M66592_SYSCFG); |
660 | 680 | ||
661 | msleep(1); | 681 | msleep(1); |
662 | 682 | ||
663 | m66592_bset(m66592, M66592_SCKE, M66592_SYSCFG); | 683 | m66592_bset(m66592, M66592_SCKE, M66592_SYSCFG); |
664 | 684 | ||
665 | m66592_bset(m66592, irq_sense & M66592_INTL, M66592_INTENB1); | 685 | m66592_bset(m66592, irq_sense & M66592_INTL, M66592_INTENB1); |
666 | m66592_write(m66592, M66592_BURST | M66592_CPU_ADR_RD_WR, | 686 | m66592_write(m66592, M66592_BURST | M66592_CPU_ADR_RD_WR, |
667 | M66592_DMA0CFG); | 687 | M66592_DMA0CFG); |
688 | } | ||
668 | } | 689 | } |
669 | #endif /* #if defined(CONFIG_SUPERH_BUILT_IN_M66592) */ | ||
670 | 690 | ||
671 | static void disable_controller(struct m66592 *m66592) | 691 | static void disable_controller(struct m66592 *m66592) |
672 | { | 692 | { |
673 | #if !defined(CONFIG_SUPERH_BUILT_IN_M66592) | 693 | if (!m66592->pdata->on_chip) { |
674 | m66592_bclr(m66592, M66592_SCKE, M66592_SYSCFG); | 694 | m66592_bclr(m66592, M66592_SCKE, M66592_SYSCFG); |
675 | udelay(1); | 695 | udelay(1); |
676 | m66592_bclr(m66592, M66592_PLLC, M66592_SYSCFG); | 696 | m66592_bclr(m66592, M66592_PLLC, M66592_SYSCFG); |
677 | udelay(1); | 697 | udelay(1); |
678 | m66592_bclr(m66592, M66592_RCKE, M66592_SYSCFG); | 698 | m66592_bclr(m66592, M66592_RCKE, M66592_SYSCFG); |
679 | udelay(1); | 699 | udelay(1); |
680 | m66592_bclr(m66592, M66592_XCKE, M66592_SYSCFG); | 700 | m66592_bclr(m66592, M66592_XCKE, M66592_SYSCFG); |
681 | #endif | 701 | } |
682 | } | 702 | } |
683 | 703 | ||
684 | static void m66592_start_xclock(struct m66592 *m66592) | 704 | static void m66592_start_xclock(struct m66592 *m66592) |
685 | { | 705 | { |
686 | #if !defined(CONFIG_SUPERH_BUILT_IN_M66592) | ||
687 | u16 tmp; | 706 | u16 tmp; |
688 | 707 | ||
689 | tmp = m66592_read(m66592, M66592_SYSCFG); | 708 | if (!m66592->pdata->on_chip) { |
690 | if (!(tmp & M66592_XCKE)) | 709 | tmp = m66592_read(m66592, M66592_SYSCFG); |
691 | m66592_bset(m66592, M66592_XCKE, M66592_SYSCFG); | 710 | if (!(tmp & M66592_XCKE)) |
692 | #endif | 711 | m66592_bset(m66592, M66592_XCKE, M66592_SYSCFG); |
712 | } | ||
693 | } | 713 | } |
694 | 714 | ||
695 | /*-------------------------------------------------------------------------*/ | 715 | /*-------------------------------------------------------------------------*/ |
@@ -1177,8 +1197,7 @@ static irqreturn_t m66592_irq(int irq, void *_m66592) | |||
1177 | intsts0 = m66592_read(m66592, M66592_INTSTS0); | 1197 | intsts0 = m66592_read(m66592, M66592_INTSTS0); |
1178 | intenb0 = m66592_read(m66592, M66592_INTENB0); | 1198 | intenb0 = m66592_read(m66592, M66592_INTENB0); |
1179 | 1199 | ||
1180 | #if defined(CONFIG_SUPERH_BUILT_IN_M66592) | 1200 | if (m66592->pdata->on_chip && !intsts0 && !intenb0) { |
1181 | if (!intsts0 && !intenb0) { | ||
1182 | /* | 1201 | /* |
1183 | * When USB clock stops, it cannot read register. Even if a | 1202 | * When USB clock stops, it cannot read register. Even if a |
1184 | * clock stops, the interrupt occurs. So this driver turn on | 1203 | * clock stops, the interrupt occurs. So this driver turn on |
@@ -1188,7 +1207,6 @@ static irqreturn_t m66592_irq(int irq, void *_m66592) | |||
1188 | intsts0 = m66592_read(m66592, M66592_INTSTS0); | 1207 | intsts0 = m66592_read(m66592, M66592_INTSTS0); |
1189 | intenb0 = m66592_read(m66592, M66592_INTENB0); | 1208 | intenb0 = m66592_read(m66592, M66592_INTENB0); |
1190 | } | 1209 | } |
1191 | #endif | ||
1192 | 1210 | ||
1193 | savepipe = m66592_read(m66592, M66592_CFIFOSEL); | 1211 | savepipe = m66592_read(m66592, M66592_CFIFOSEL); |
1194 | 1212 | ||
@@ -1534,9 +1552,11 @@ static int __exit m66592_remove(struct platform_device *pdev) | |||
1534 | iounmap(m66592->reg); | 1552 | iounmap(m66592->reg); |
1535 | free_irq(platform_get_irq(pdev, 0), m66592); | 1553 | free_irq(platform_get_irq(pdev, 0), m66592); |
1536 | m66592_free_request(&m66592->ep[0].ep, m66592->ep0_req); | 1554 | m66592_free_request(&m66592->ep[0].ep, m66592->ep0_req); |
1537 | #if defined(CONFIG_SUPERH_BUILT_IN_M66592) && defined(CONFIG_HAVE_CLK) | 1555 | #ifdef CONFIG_HAVE_CLK |
1538 | clk_disable(m66592->clk); | 1556 | if (m66592->pdata->on_chip) { |
1539 | clk_put(m66592->clk); | 1557 | clk_disable(m66592->clk); |
1558 | clk_put(m66592->clk); | ||
1559 | } | ||
1540 | #endif | 1560 | #endif |
1541 | kfree(m66592); | 1561 | kfree(m66592); |
1542 | return 0; | 1562 | return 0; |
@@ -1548,11 +1568,10 @@ static void nop_completion(struct usb_ep *ep, struct usb_request *r) | |||
1548 | 1568 | ||
1549 | static int __init m66592_probe(struct platform_device *pdev) | 1569 | static int __init m66592_probe(struct platform_device *pdev) |
1550 | { | 1570 | { |
1551 | struct resource *res; | 1571 | struct resource *res, *ires; |
1552 | int irq; | ||
1553 | void __iomem *reg = NULL; | 1572 | void __iomem *reg = NULL; |
1554 | struct m66592 *m66592 = NULL; | 1573 | struct m66592 *m66592 = NULL; |
1555 | #if defined(CONFIG_SUPERH_BUILT_IN_M66592) && defined(CONFIG_HAVE_CLK) | 1574 | #ifdef CONFIG_HAVE_CLK |
1556 | char clk_name[8]; | 1575 | char clk_name[8]; |
1557 | #endif | 1576 | #endif |
1558 | int ret = 0; | 1577 | int ret = 0; |
@@ -1565,10 +1584,11 @@ static int __init m66592_probe(struct platform_device *pdev) | |||
1565 | goto clean_up; | 1584 | goto clean_up; |
1566 | } | 1585 | } |
1567 | 1586 | ||
1568 | irq = platform_get_irq(pdev, 0); | 1587 | ires = platform_get_resource(pdev, IORESOURCE_IRQ, 0); |
1569 | if (irq < 0) { | 1588 | if (!ires) { |
1570 | ret = -ENODEV; | 1589 | ret = -ENODEV; |
1571 | pr_err("platform_get_irq error.\n"); | 1590 | dev_err(&pdev->dev, |
1591 | "platform_get_resource IORESOURCE_IRQ error.\n"); | ||
1572 | goto clean_up; | 1592 | goto clean_up; |
1573 | } | 1593 | } |
1574 | 1594 | ||
@@ -1579,6 +1599,12 @@ static int __init m66592_probe(struct platform_device *pdev) | |||
1579 | goto clean_up; | 1599 | goto clean_up; |
1580 | } | 1600 | } |
1581 | 1601 | ||
1602 | if (pdev->dev.platform_data == NULL) { | ||
1603 | dev_err(&pdev->dev, "no platform data\n"); | ||
1604 | ret = -ENODEV; | ||
1605 | goto clean_up; | ||
1606 | } | ||
1607 | |||
1582 | /* initialize ucd */ | 1608 | /* initialize ucd */ |
1583 | m66592 = kzalloc(sizeof(struct m66592), GFP_KERNEL); | 1609 | m66592 = kzalloc(sizeof(struct m66592), GFP_KERNEL); |
1584 | if (m66592 == NULL) { | 1610 | if (m66592 == NULL) { |
@@ -1586,6 +1612,9 @@ static int __init m66592_probe(struct platform_device *pdev) | |||
1586 | goto clean_up; | 1612 | goto clean_up; |
1587 | } | 1613 | } |
1588 | 1614 | ||
1615 | m66592->pdata = pdev->dev.platform_data; | ||
1616 | m66592->irq_trigger = ires->flags & IRQF_TRIGGER_MASK; | ||
1617 | |||
1589 | spin_lock_init(&m66592->lock); | 1618 | spin_lock_init(&m66592->lock); |
1590 | dev_set_drvdata(&pdev->dev, m66592); | 1619 | dev_set_drvdata(&pdev->dev, m66592); |
1591 | 1620 | ||
@@ -1603,24 +1632,25 @@ static int __init m66592_probe(struct platform_device *pdev) | |||
1603 | m66592->timer.data = (unsigned long)m66592; | 1632 | m66592->timer.data = (unsigned long)m66592; |
1604 | m66592->reg = reg; | 1633 | m66592->reg = reg; |
1605 | 1634 | ||
1606 | m66592->bi_bufnum = M66592_BASE_BUFNUM; | 1635 | ret = request_irq(ires->start, m66592_irq, IRQF_DISABLED | IRQF_SHARED, |
1607 | |||
1608 | ret = request_irq(irq, m66592_irq, IRQF_DISABLED | IRQF_SHARED, | ||
1609 | udc_name, m66592); | 1636 | udc_name, m66592); |
1610 | if (ret < 0) { | 1637 | if (ret < 0) { |
1611 | pr_err("request_irq error (%d)\n", ret); | 1638 | pr_err("request_irq error (%d)\n", ret); |
1612 | goto clean_up; | 1639 | goto clean_up; |
1613 | } | 1640 | } |
1614 | 1641 | ||
1615 | #if defined(CONFIG_SUPERH_BUILT_IN_M66592) && defined(CONFIG_HAVE_CLK) | 1642 | #ifdef CONFIG_HAVE_CLK |
1616 | snprintf(clk_name, sizeof(clk_name), "usbf%d", pdev->id); | 1643 | if (m66592->pdata->on_chip) { |
1617 | m66592->clk = clk_get(&pdev->dev, clk_name); | 1644 | snprintf(clk_name, sizeof(clk_name), "usbf%d", pdev->id); |
1618 | if (IS_ERR(m66592->clk)) { | 1645 | m66592->clk = clk_get(&pdev->dev, clk_name); |
1619 | dev_err(&pdev->dev, "cannot get clock \"%s\"\n", clk_name); | 1646 | if (IS_ERR(m66592->clk)) { |
1620 | ret = PTR_ERR(m66592->clk); | 1647 | dev_err(&pdev->dev, "cannot get clock \"%s\"\n", |
1621 | goto clean_up2; | 1648 | clk_name); |
1649 | ret = PTR_ERR(m66592->clk); | ||
1650 | goto clean_up2; | ||
1651 | } | ||
1652 | clk_enable(m66592->clk); | ||
1622 | } | 1653 | } |
1623 | clk_enable(m66592->clk); | ||
1624 | #endif | 1654 | #endif |
1625 | INIT_LIST_HEAD(&m66592->gadget.ep_list); | 1655 | INIT_LIST_HEAD(&m66592->gadget.ep_list); |
1626 | m66592->gadget.ep0 = &m66592->ep[0].ep; | 1656 | m66592->gadget.ep0 = &m66592->ep[0].ep; |
@@ -1662,12 +1692,14 @@ static int __init m66592_probe(struct platform_device *pdev) | |||
1662 | return 0; | 1692 | return 0; |
1663 | 1693 | ||
1664 | clean_up3: | 1694 | clean_up3: |
1665 | #if defined(CONFIG_SUPERH_BUILT_IN_M66592) && defined(CONFIG_HAVE_CLK) | 1695 | #ifdef CONFIG_HAVE_CLK |
1666 | clk_disable(m66592->clk); | 1696 | if (m66592->pdata->on_chip) { |
1667 | clk_put(m66592->clk); | 1697 | clk_disable(m66592->clk); |
1698 | clk_put(m66592->clk); | ||
1699 | } | ||
1668 | clean_up2: | 1700 | clean_up2: |
1669 | #endif | 1701 | #endif |
1670 | free_irq(irq, m66592); | 1702 | free_irq(ires->start, m66592); |
1671 | clean_up: | 1703 | clean_up: |
1672 | if (m66592) { | 1704 | if (m66592) { |
1673 | if (m66592->ep0_req) | 1705 | if (m66592->ep0_req) |
diff --git a/drivers/usb/gadget/m66592-udc.h b/drivers/usb/gadget/m66592-udc.h index 286ce07e7960..8b960deed680 100644 --- a/drivers/usb/gadget/m66592-udc.h +++ b/drivers/usb/gadget/m66592-udc.h | |||
@@ -23,10 +23,12 @@ | |||
23 | #ifndef __M66592_UDC_H__ | 23 | #ifndef __M66592_UDC_H__ |
24 | #define __M66592_UDC_H__ | 24 | #define __M66592_UDC_H__ |
25 | 25 | ||
26 | #if defined(CONFIG_SUPERH_BUILT_IN_M66592) && defined(CONFIG_HAVE_CLK) | 26 | #ifdef CONFIG_HAVE_CLK |
27 | #include <linux/clk.h> | 27 | #include <linux/clk.h> |
28 | #endif | 28 | #endif |
29 | 29 | ||
30 | #include <linux/usb/m66592.h> | ||
31 | |||
30 | #define M66592_SYSCFG 0x00 | 32 | #define M66592_SYSCFG 0x00 |
31 | #define M66592_XTAL 0xC000 /* b15-14: Crystal selection */ | 33 | #define M66592_XTAL 0xC000 /* b15-14: Crystal selection */ |
32 | #define M66592_XTAL48 0x8000 /* 48MHz */ | 34 | #define M66592_XTAL48 0x8000 /* 48MHz */ |
@@ -76,11 +78,11 @@ | |||
76 | #define M66592_P_TST_J 0x0001 /* PERI TEST J */ | 78 | #define M66592_P_TST_J 0x0001 /* PERI TEST J */ |
77 | #define M66592_P_TST_NORMAL 0x0000 /* PERI Normal Mode */ | 79 | #define M66592_P_TST_NORMAL 0x0000 /* PERI Normal Mode */ |
78 | 80 | ||
79 | #if defined(CONFIG_SUPERH_BUILT_IN_M66592) | 81 | /* built-in registers */ |
80 | #define M66592_CFBCFG 0x0A | 82 | #define M66592_CFBCFG 0x0A |
81 | #define M66592_D0FBCFG 0x0C | 83 | #define M66592_D0FBCFG 0x0C |
82 | #define M66592_LITTLE 0x0100 /* b8: Little endian mode */ | 84 | #define M66592_LITTLE 0x0100 /* b8: Little endian mode */ |
83 | #else | 85 | /* external chip case */ |
84 | #define M66592_PINCFG 0x0A | 86 | #define M66592_PINCFG 0x0A |
85 | #define M66592_LDRV 0x8000 /* b15: Drive Current Adjust */ | 87 | #define M66592_LDRV 0x8000 /* b15: Drive Current Adjust */ |
86 | #define M66592_BIGEND 0x0100 /* b8: Big endian mode */ | 88 | #define M66592_BIGEND 0x0100 /* b8: Big endian mode */ |
@@ -100,8 +102,8 @@ | |||
100 | #define M66592_PKTM 0x0020 /* b5: Packet mode */ | 102 | #define M66592_PKTM 0x0020 /* b5: Packet mode */ |
101 | #define M66592_DENDE 0x0010 /* b4: Dend enable */ | 103 | #define M66592_DENDE 0x0010 /* b4: Dend enable */ |
102 | #define M66592_OBUS 0x0004 /* b2: OUTbus mode */ | 104 | #define M66592_OBUS 0x0004 /* b2: OUTbus mode */ |
103 | #endif /* #if defined(CONFIG_SUPERH_BUILT_IN_M66592) */ | ||
104 | 105 | ||
106 | /* common case */ | ||
105 | #define M66592_CFIFO 0x10 | 107 | #define M66592_CFIFO 0x10 |
106 | #define M66592_D0FIFO 0x14 | 108 | #define M66592_D0FIFO 0x14 |
107 | #define M66592_D1FIFO 0x18 | 109 | #define M66592_D1FIFO 0x18 |
@@ -113,13 +115,9 @@ | |||
113 | #define M66592_REW 0x4000 /* b14: Buffer rewind */ | 115 | #define M66592_REW 0x4000 /* b14: Buffer rewind */ |
114 | #define M66592_DCLRM 0x2000 /* b13: DMA buffer clear mode */ | 116 | #define M66592_DCLRM 0x2000 /* b13: DMA buffer clear mode */ |
115 | #define M66592_DREQE 0x1000 /* b12: DREQ output enable */ | 117 | #define M66592_DREQE 0x1000 /* b12: DREQ output enable */ |
116 | #if defined(CONFIG_SUPERH_BUILT_IN_M66592) | 118 | #define M66592_MBW_8 0x0000 /* 8bit */ |
117 | #define M66592_MBW 0x0800 /* b11: Maximum bit width for FIFO */ | 119 | #define M66592_MBW_16 0x0400 /* 16bit */ |
118 | #else | 120 | #define M66592_MBW_32 0x0800 /* 32bit */ |
119 | #define M66592_MBW 0x0400 /* b10: Maximum bit width for FIFO */ | ||
120 | #define M66592_MBW_8 0x0000 /* 8bit */ | ||
121 | #define M66592_MBW_16 0x0400 /* 16bit */ | ||
122 | #endif /* #if defined(CONFIG_SUPERH_BUILT_IN_M66592) */ | ||
123 | #define M66592_TRENB 0x0200 /* b9: Transaction counter enable */ | 121 | #define M66592_TRENB 0x0200 /* b9: Transaction counter enable */ |
124 | #define M66592_TRCLR 0x0100 /* b8: Transaction counter clear */ | 122 | #define M66592_TRCLR 0x0100 /* b8: Transaction counter clear */ |
125 | #define M66592_DEZPM 0x0080 /* b7: Zero-length packet mode */ | 123 | #define M66592_DEZPM 0x0080 /* b7: Zero-length packet mode */ |
@@ -480,9 +478,11 @@ struct m66592_ep { | |||
480 | struct m66592 { | 478 | struct m66592 { |
481 | spinlock_t lock; | 479 | spinlock_t lock; |
482 | void __iomem *reg; | 480 | void __iomem *reg; |
483 | #if defined(CONFIG_SUPERH_BUILT_IN_M66592) && defined(CONFIG_HAVE_CLK) | 481 | #ifdef CONFIG_HAVE_CLK |
484 | struct clk *clk; | 482 | struct clk *clk; |
485 | #endif | 483 | #endif |
484 | struct m66592_platdata *pdata; | ||
485 | unsigned long irq_trigger; | ||
486 | 486 | ||
487 | struct usb_gadget gadget; | 487 | struct usb_gadget gadget; |
488 | struct usb_gadget_driver *driver; | 488 | struct usb_gadget_driver *driver; |
@@ -506,7 +506,6 @@ struct m66592 { | |||
506 | int interrupt; | 506 | int interrupt; |
507 | int isochronous; | 507 | int isochronous; |
508 | int num_dma; | 508 | int num_dma; |
509 | int bi_bufnum; /* bulk and isochronous's bufnum */ | ||
510 | }; | 509 | }; |
511 | 510 | ||
512 | #define gadget_to_m66592(_gadget) container_of(_gadget, struct m66592, gadget) | 511 | #define gadget_to_m66592(_gadget) container_of(_gadget, struct m66592, gadget) |
@@ -547,13 +546,13 @@ static inline void m66592_read_fifo(struct m66592 *m66592, | |||
547 | { | 546 | { |
548 | unsigned long fifoaddr = (unsigned long)m66592->reg + offset; | 547 | unsigned long fifoaddr = (unsigned long)m66592->reg + offset; |
549 | 548 | ||
550 | #if defined(CONFIG_SUPERH_BUILT_IN_M66592) | 549 | if (m66592->pdata->on_chip) { |
551 | len = (len + 3) / 4; | 550 | len = (len + 3) / 4; |
552 | insl(fifoaddr, buf, len); | 551 | insl(fifoaddr, buf, len); |
553 | #else | 552 | } else { |
554 | len = (len + 1) / 2; | 553 | len = (len + 1) / 2; |
555 | insw(fifoaddr, buf, len); | 554 | insw(fifoaddr, buf, len); |
556 | #endif | 555 | } |
557 | } | 556 | } |
558 | 557 | ||
559 | static inline void m66592_write(struct m66592 *m66592, u16 val, | 558 | static inline void m66592_write(struct m66592 *m66592, u16 val, |
@@ -567,33 +566,34 @@ static inline void m66592_write_fifo(struct m66592 *m66592, | |||
567 | void *buf, unsigned long len) | 566 | void *buf, unsigned long len) |
568 | { | 567 | { |
569 | unsigned long fifoaddr = (unsigned long)m66592->reg + offset; | 568 | unsigned long fifoaddr = (unsigned long)m66592->reg + offset; |
570 | #if defined(CONFIG_SUPERH_BUILT_IN_M66592) | 569 | |
571 | unsigned long count; | 570 | if (m66592->pdata->on_chip) { |
572 | unsigned char *pb; | 571 | unsigned long count; |
573 | int i; | 572 | unsigned char *pb; |
574 | 573 | int i; | |
575 | count = len / 4; | 574 | |
576 | outsl(fifoaddr, buf, count); | 575 | count = len / 4; |
577 | 576 | outsl(fifoaddr, buf, count); | |
578 | if (len & 0x00000003) { | 577 | |
579 | pb = buf + count * 4; | 578 | if (len & 0x00000003) { |
580 | for (i = 0; i < (len & 0x00000003); i++) { | 579 | pb = buf + count * 4; |
581 | if (m66592_read(m66592, M66592_CFBCFG)) /* little */ | 580 | for (i = 0; i < (len & 0x00000003); i++) { |
582 | outb(pb[i], fifoaddr + (3 - i)); | 581 | if (m66592_read(m66592, M66592_CFBCFG)) /* le */ |
583 | else | 582 | outb(pb[i], fifoaddr + (3 - i)); |
584 | outb(pb[i], fifoaddr + i); | 583 | else |
584 | outb(pb[i], fifoaddr + i); | ||
585 | } | ||
586 | } | ||
587 | } else { | ||
588 | unsigned long odd = len & 0x0001; | ||
589 | |||
590 | len = len / 2; | ||
591 | outsw(fifoaddr, buf, len); | ||
592 | if (odd) { | ||
593 | unsigned char *p = buf + len*2; | ||
594 | outb(*p, fifoaddr); | ||
585 | } | 595 | } |
586 | } | 596 | } |
587 | #else | ||
588 | unsigned long odd = len & 0x0001; | ||
589 | |||
590 | len = len / 2; | ||
591 | outsw(fifoaddr, buf, len); | ||
592 | if (odd) { | ||
593 | unsigned char *p = buf + len*2; | ||
594 | outb(*p, fifoaddr); | ||
595 | } | ||
596 | #endif /* #if defined(CONFIG_SUPERH_BUILT_IN_M66592) */ | ||
597 | } | 597 | } |
598 | 598 | ||
599 | static inline void m66592_mdfy(struct m66592 *m66592, u16 val, u16 pat, | 599 | static inline void m66592_mdfy(struct m66592 *m66592, u16 val, u16 pat, |
diff --git a/drivers/usb/gadget/pxa25x_udc.c b/drivers/usb/gadget/pxa25x_udc.c index ed21e263f832..e6fedbd5a654 100644 --- a/drivers/usb/gadget/pxa25x_udc.c +++ b/drivers/usb/gadget/pxa25x_udc.c | |||
@@ -56,6 +56,7 @@ | |||
56 | 56 | ||
57 | #include <linux/usb/ch9.h> | 57 | #include <linux/usb/ch9.h> |
58 | #include <linux/usb/gadget.h> | 58 | #include <linux/usb/gadget.h> |
59 | #include <linux/usb/otg.h> | ||
59 | 60 | ||
60 | /* | 61 | /* |
61 | * This driver is PXA25x only. Grab the right register definitions. | 62 | * This driver is PXA25x only. Grab the right register definitions. |
@@ -1008,15 +1009,27 @@ static int pxa25x_udc_pullup(struct usb_gadget *_gadget, int is_active) | |||
1008 | return 0; | 1009 | return 0; |
1009 | } | 1010 | } |
1010 | 1011 | ||
1012 | /* boards may consume current from VBUS, up to 100-500mA based on config. | ||
1013 | * the 500uA suspend ceiling means that exclusively vbus-powered PXA designs | ||
1014 | * violate USB specs. | ||
1015 | */ | ||
1016 | static int pxa25x_udc_vbus_draw(struct usb_gadget *_gadget, unsigned mA) | ||
1017 | { | ||
1018 | struct pxa25x_udc *udc; | ||
1019 | |||
1020 | udc = container_of(_gadget, struct pxa25x_udc, gadget); | ||
1021 | |||
1022 | if (udc->transceiver) | ||
1023 | return otg_set_power(udc->transceiver, mA); | ||
1024 | return -EOPNOTSUPP; | ||
1025 | } | ||
1026 | |||
1011 | static const struct usb_gadget_ops pxa25x_udc_ops = { | 1027 | static const struct usb_gadget_ops pxa25x_udc_ops = { |
1012 | .get_frame = pxa25x_udc_get_frame, | 1028 | .get_frame = pxa25x_udc_get_frame, |
1013 | .wakeup = pxa25x_udc_wakeup, | 1029 | .wakeup = pxa25x_udc_wakeup, |
1014 | .vbus_session = pxa25x_udc_vbus_session, | 1030 | .vbus_session = pxa25x_udc_vbus_session, |
1015 | .pullup = pxa25x_udc_pullup, | 1031 | .pullup = pxa25x_udc_pullup, |
1016 | 1032 | .vbus_draw = pxa25x_udc_vbus_draw, | |
1017 | // .vbus_draw ... boards may consume current from VBUS, up to | ||
1018 | // 100-500mA based on config. the 500uA suspend ceiling means | ||
1019 | // that exclusively vbus-powered PXA designs violate USB specs. | ||
1020 | }; | 1033 | }; |
1021 | 1034 | ||
1022 | /*-------------------------------------------------------------------------*/ | 1035 | /*-------------------------------------------------------------------------*/ |
@@ -1303,9 +1316,23 @@ fail: | |||
1303 | * for set_configuration as well as eventual disconnect. | 1316 | * for set_configuration as well as eventual disconnect. |
1304 | */ | 1317 | */ |
1305 | DMSG("registered gadget driver '%s'\n", driver->driver.name); | 1318 | DMSG("registered gadget driver '%s'\n", driver->driver.name); |
1319 | |||
1320 | /* connect to bus through transceiver */ | ||
1321 | if (dev->transceiver) { | ||
1322 | retval = otg_set_peripheral(dev->transceiver, &dev->gadget); | ||
1323 | if (retval) { | ||
1324 | DMSG("can't bind to transceiver\n"); | ||
1325 | if (driver->unbind) | ||
1326 | driver->unbind(&dev->gadget); | ||
1327 | goto bind_fail; | ||
1328 | } | ||
1329 | } | ||
1330 | |||
1306 | pullup(dev); | 1331 | pullup(dev); |
1307 | dump_state(dev); | 1332 | dump_state(dev); |
1308 | return 0; | 1333 | return 0; |
1334 | bind_fail: | ||
1335 | return retval; | ||
1309 | } | 1336 | } |
1310 | EXPORT_SYMBOL(usb_gadget_register_driver); | 1337 | EXPORT_SYMBOL(usb_gadget_register_driver); |
1311 | 1338 | ||
@@ -1351,6 +1378,9 @@ int usb_gadget_unregister_driver(struct usb_gadget_driver *driver) | |||
1351 | stop_activity(dev, driver); | 1378 | stop_activity(dev, driver); |
1352 | local_irq_enable(); | 1379 | local_irq_enable(); |
1353 | 1380 | ||
1381 | if (dev->transceiver) | ||
1382 | (void) otg_set_peripheral(dev->transceiver, NULL); | ||
1383 | |||
1354 | driver->unbind(&dev->gadget); | 1384 | driver->unbind(&dev->gadget); |
1355 | dev->gadget.dev.driver = NULL; | 1385 | dev->gadget.dev.driver = NULL; |
1356 | dev->driver = NULL; | 1386 | dev->driver = NULL; |
@@ -2162,6 +2192,8 @@ static int __init pxa25x_udc_probe(struct platform_device *pdev) | |||
2162 | dev->dev = &pdev->dev; | 2192 | dev->dev = &pdev->dev; |
2163 | dev->mach = pdev->dev.platform_data; | 2193 | dev->mach = pdev->dev.platform_data; |
2164 | 2194 | ||
2195 | dev->transceiver = otg_get_transceiver(); | ||
2196 | |||
2165 | if (gpio_is_valid(dev->mach->gpio_vbus)) { | 2197 | if (gpio_is_valid(dev->mach->gpio_vbus)) { |
2166 | if ((retval = gpio_request(dev->mach->gpio_vbus, | 2198 | if ((retval = gpio_request(dev->mach->gpio_vbus, |
2167 | "pxa25x_udc GPIO VBUS"))) { | 2199 | "pxa25x_udc GPIO VBUS"))) { |
@@ -2264,6 +2296,10 @@ lubbock_fail0: | |||
2264 | if (gpio_is_valid(dev->mach->gpio_vbus)) | 2296 | if (gpio_is_valid(dev->mach->gpio_vbus)) |
2265 | gpio_free(dev->mach->gpio_vbus); | 2297 | gpio_free(dev->mach->gpio_vbus); |
2266 | err_gpio_vbus: | 2298 | err_gpio_vbus: |
2299 | if (dev->transceiver) { | ||
2300 | otg_put_transceiver(dev->transceiver); | ||
2301 | dev->transceiver = NULL; | ||
2302 | } | ||
2267 | clk_put(dev->clk); | 2303 | clk_put(dev->clk); |
2268 | err_clk: | 2304 | err_clk: |
2269 | return retval; | 2305 | return retval; |
@@ -2305,6 +2341,11 @@ static int __exit pxa25x_udc_remove(struct platform_device *pdev) | |||
2305 | 2341 | ||
2306 | clk_put(dev->clk); | 2342 | clk_put(dev->clk); |
2307 | 2343 | ||
2344 | if (dev->transceiver) { | ||
2345 | otg_put_transceiver(dev->transceiver); | ||
2346 | dev->transceiver = NULL; | ||
2347 | } | ||
2348 | |||
2308 | platform_set_drvdata(pdev, NULL); | 2349 | platform_set_drvdata(pdev, NULL); |
2309 | the_controller = NULL; | 2350 | the_controller = NULL; |
2310 | return 0; | 2351 | return 0; |
diff --git a/drivers/usb/gadget/pxa25x_udc.h b/drivers/usb/gadget/pxa25x_udc.h index 1d51aa21e6eb..f572c5617462 100644 --- a/drivers/usb/gadget/pxa25x_udc.h +++ b/drivers/usb/gadget/pxa25x_udc.h | |||
@@ -128,6 +128,7 @@ struct pxa25x_udc { | |||
128 | struct device *dev; | 128 | struct device *dev; |
129 | struct clk *clk; | 129 | struct clk *clk; |
130 | struct pxa2xx_udc_mach_info *mach; | 130 | struct pxa2xx_udc_mach_info *mach; |
131 | struct otg_transceiver *transceiver; | ||
131 | u64 dma_mask; | 132 | u64 dma_mask; |
132 | struct pxa25x_ep ep [PXA_UDC_NUM_ENDPOINTS]; | 133 | struct pxa25x_ep ep [PXA_UDC_NUM_ENDPOINTS]; |
133 | 134 | ||
diff --git a/drivers/usb/gadget/r8a66597-udc.c b/drivers/usb/gadget/r8a66597-udc.c new file mode 100644 index 000000000000..e220fb8091a3 --- /dev/null +++ b/drivers/usb/gadget/r8a66597-udc.c | |||
@@ -0,0 +1,1689 @@ | |||
1 | /* | ||
2 | * R8A66597 UDC (USB gadget) | ||
3 | * | ||
4 | * Copyright (C) 2006-2009 Renesas Solutions Corp. | ||
5 | * | ||
6 | * Author : Yoshihiro Shimoda <shimoda.yoshihiro@renesas.com> | ||
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; version 2 of the License. | ||
11 | * | ||
12 | * This program is distributed in the hope that it will be useful, | ||
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
15 | * GNU General Public License for more details. | ||
16 | * | ||
17 | * You should have received a copy of the GNU General Public License | ||
18 | * along with this program; if not, write to the Free Software | ||
19 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
20 | * | ||
21 | */ | ||
22 | |||
23 | #include <linux/module.h> | ||
24 | #include <linux/interrupt.h> | ||
25 | #include <linux/delay.h> | ||
26 | #include <linux/io.h> | ||
27 | #include <linux/platform_device.h> | ||
28 | #include <linux/clk.h> | ||
29 | |||
30 | #include <linux/usb/ch9.h> | ||
31 | #include <linux/usb/gadget.h> | ||
32 | |||
33 | #include "r8a66597-udc.h" | ||
34 | |||
35 | #define DRIVER_VERSION "2009-08-18" | ||
36 | |||
37 | static const char udc_name[] = "r8a66597_udc"; | ||
38 | static const char *r8a66597_ep_name[] = { | ||
39 | "ep0", "ep1", "ep2", "ep3", "ep4", "ep5", "ep6", "ep7", | ||
40 | "ep8", "ep9", | ||
41 | }; | ||
42 | |||
43 | static void disable_controller(struct r8a66597 *r8a66597); | ||
44 | static void irq_ep0_write(struct r8a66597_ep *ep, struct r8a66597_request *req); | ||
45 | static void irq_packet_write(struct r8a66597_ep *ep, | ||
46 | struct r8a66597_request *req); | ||
47 | static int r8a66597_queue(struct usb_ep *_ep, struct usb_request *_req, | ||
48 | gfp_t gfp_flags); | ||
49 | |||
50 | static void transfer_complete(struct r8a66597_ep *ep, | ||
51 | struct r8a66597_request *req, int status); | ||
52 | |||
53 | /*-------------------------------------------------------------------------*/ | ||
54 | static inline u16 get_usb_speed(struct r8a66597 *r8a66597) | ||
55 | { | ||
56 | return r8a66597_read(r8a66597, DVSTCTR0) & RHST; | ||
57 | } | ||
58 | |||
59 | static void enable_pipe_irq(struct r8a66597 *r8a66597, u16 pipenum, | ||
60 | unsigned long reg) | ||
61 | { | ||
62 | u16 tmp; | ||
63 | |||
64 | tmp = r8a66597_read(r8a66597, INTENB0); | ||
65 | r8a66597_bclr(r8a66597, BEMPE | NRDYE | BRDYE, | ||
66 | INTENB0); | ||
67 | r8a66597_bset(r8a66597, (1 << pipenum), reg); | ||
68 | r8a66597_write(r8a66597, tmp, INTENB0); | ||
69 | } | ||
70 | |||
71 | static void disable_pipe_irq(struct r8a66597 *r8a66597, u16 pipenum, | ||
72 | unsigned long reg) | ||
73 | { | ||
74 | u16 tmp; | ||
75 | |||
76 | tmp = r8a66597_read(r8a66597, INTENB0); | ||
77 | r8a66597_bclr(r8a66597, BEMPE | NRDYE | BRDYE, | ||
78 | INTENB0); | ||
79 | r8a66597_bclr(r8a66597, (1 << pipenum), reg); | ||
80 | r8a66597_write(r8a66597, tmp, INTENB0); | ||
81 | } | ||
82 | |||
83 | static void r8a66597_usb_connect(struct r8a66597 *r8a66597) | ||
84 | { | ||
85 | r8a66597_bset(r8a66597, CTRE, INTENB0); | ||
86 | r8a66597_bset(r8a66597, BEMPE | BRDYE, INTENB0); | ||
87 | |||
88 | r8a66597_bset(r8a66597, DPRPU, SYSCFG0); | ||
89 | } | ||
90 | |||
91 | static void r8a66597_usb_disconnect(struct r8a66597 *r8a66597) | ||
92 | __releases(r8a66597->lock) | ||
93 | __acquires(r8a66597->lock) | ||
94 | { | ||
95 | r8a66597_bclr(r8a66597, CTRE, INTENB0); | ||
96 | r8a66597_bclr(r8a66597, BEMPE | BRDYE, INTENB0); | ||
97 | r8a66597_bclr(r8a66597, DPRPU, SYSCFG0); | ||
98 | |||
99 | r8a66597->gadget.speed = USB_SPEED_UNKNOWN; | ||
100 | spin_unlock(&r8a66597->lock); | ||
101 | r8a66597->driver->disconnect(&r8a66597->gadget); | ||
102 | spin_lock(&r8a66597->lock); | ||
103 | |||
104 | disable_controller(r8a66597); | ||
105 | INIT_LIST_HEAD(&r8a66597->ep[0].queue); | ||
106 | } | ||
107 | |||
108 | static inline u16 control_reg_get_pid(struct r8a66597 *r8a66597, u16 pipenum) | ||
109 | { | ||
110 | u16 pid = 0; | ||
111 | unsigned long offset; | ||
112 | |||
113 | if (pipenum == 0) | ||
114 | pid = r8a66597_read(r8a66597, DCPCTR) & PID; | ||
115 | else if (pipenum < R8A66597_MAX_NUM_PIPE) { | ||
116 | offset = get_pipectr_addr(pipenum); | ||
117 | pid = r8a66597_read(r8a66597, offset) & PID; | ||
118 | } else | ||
119 | printk(KERN_ERR "unexpect pipe num (%d)\n", pipenum); | ||
120 | |||
121 | return pid; | ||
122 | } | ||
123 | |||
124 | static inline void control_reg_set_pid(struct r8a66597 *r8a66597, u16 pipenum, | ||
125 | u16 pid) | ||
126 | { | ||
127 | unsigned long offset; | ||
128 | |||
129 | if (pipenum == 0) | ||
130 | r8a66597_mdfy(r8a66597, pid, PID, DCPCTR); | ||
131 | else if (pipenum < R8A66597_MAX_NUM_PIPE) { | ||
132 | offset = get_pipectr_addr(pipenum); | ||
133 | r8a66597_mdfy(r8a66597, pid, PID, offset); | ||
134 | } else | ||
135 | printk(KERN_ERR "unexpect pipe num (%d)\n", pipenum); | ||
136 | } | ||
137 | |||
138 | static inline void pipe_start(struct r8a66597 *r8a66597, u16 pipenum) | ||
139 | { | ||
140 | control_reg_set_pid(r8a66597, pipenum, PID_BUF); | ||
141 | } | ||
142 | |||
143 | static inline void pipe_stop(struct r8a66597 *r8a66597, u16 pipenum) | ||
144 | { | ||
145 | control_reg_set_pid(r8a66597, pipenum, PID_NAK); | ||
146 | } | ||
147 | |||
148 | static inline void pipe_stall(struct r8a66597 *r8a66597, u16 pipenum) | ||
149 | { | ||
150 | control_reg_set_pid(r8a66597, pipenum, PID_STALL); | ||
151 | } | ||
152 | |||
153 | static inline u16 control_reg_get(struct r8a66597 *r8a66597, u16 pipenum) | ||
154 | { | ||
155 | u16 ret = 0; | ||
156 | unsigned long offset; | ||
157 | |||
158 | if (pipenum == 0) | ||
159 | ret = r8a66597_read(r8a66597, DCPCTR); | ||
160 | else if (pipenum < R8A66597_MAX_NUM_PIPE) { | ||
161 | offset = get_pipectr_addr(pipenum); | ||
162 | ret = r8a66597_read(r8a66597, offset); | ||
163 | } else | ||
164 | printk(KERN_ERR "unexpect pipe num (%d)\n", pipenum); | ||
165 | |||
166 | return ret; | ||
167 | } | ||
168 | |||
169 | static inline void control_reg_sqclr(struct r8a66597 *r8a66597, u16 pipenum) | ||
170 | { | ||
171 | unsigned long offset; | ||
172 | |||
173 | pipe_stop(r8a66597, pipenum); | ||
174 | |||
175 | if (pipenum == 0) | ||
176 | r8a66597_bset(r8a66597, SQCLR, DCPCTR); | ||
177 | else if (pipenum < R8A66597_MAX_NUM_PIPE) { | ||
178 | offset = get_pipectr_addr(pipenum); | ||
179 | r8a66597_bset(r8a66597, SQCLR, offset); | ||
180 | } else | ||
181 | printk(KERN_ERR "unexpect pipe num(%d)\n", pipenum); | ||
182 | } | ||
183 | |||
184 | static inline int get_buffer_size(struct r8a66597 *r8a66597, u16 pipenum) | ||
185 | { | ||
186 | u16 tmp; | ||
187 | int size; | ||
188 | |||
189 | if (pipenum == 0) { | ||
190 | tmp = r8a66597_read(r8a66597, DCPCFG); | ||
191 | if ((tmp & R8A66597_CNTMD) != 0) | ||
192 | size = 256; | ||
193 | else { | ||
194 | tmp = r8a66597_read(r8a66597, DCPMAXP); | ||
195 | size = tmp & MAXP; | ||
196 | } | ||
197 | } else { | ||
198 | r8a66597_write(r8a66597, pipenum, PIPESEL); | ||
199 | tmp = r8a66597_read(r8a66597, PIPECFG); | ||
200 | if ((tmp & R8A66597_CNTMD) != 0) { | ||
201 | tmp = r8a66597_read(r8a66597, PIPEBUF); | ||
202 | size = ((tmp >> 10) + 1) * 64; | ||
203 | } else { | ||
204 | tmp = r8a66597_read(r8a66597, PIPEMAXP); | ||
205 | size = tmp & MXPS; | ||
206 | } | ||
207 | } | ||
208 | |||
209 | return size; | ||
210 | } | ||
211 | |||
212 | static inline unsigned short mbw_value(struct r8a66597 *r8a66597) | ||
213 | { | ||
214 | if (r8a66597->pdata->on_chip) | ||
215 | return MBW_32; | ||
216 | else | ||
217 | return MBW_16; | ||
218 | } | ||
219 | |||
220 | static inline void pipe_change(struct r8a66597 *r8a66597, u16 pipenum) | ||
221 | { | ||
222 | struct r8a66597_ep *ep = r8a66597->pipenum2ep[pipenum]; | ||
223 | |||
224 | if (ep->use_dma) | ||
225 | return; | ||
226 | |||
227 | r8a66597_mdfy(r8a66597, pipenum, CURPIPE, ep->fifosel); | ||
228 | |||
229 | ndelay(450); | ||
230 | |||
231 | r8a66597_bset(r8a66597, mbw_value(r8a66597), ep->fifosel); | ||
232 | } | ||
233 | |||
234 | static int pipe_buffer_setting(struct r8a66597 *r8a66597, | ||
235 | struct r8a66597_pipe_info *info) | ||
236 | { | ||
237 | u16 bufnum = 0, buf_bsize = 0; | ||
238 | u16 pipecfg = 0; | ||
239 | |||
240 | if (info->pipe == 0) | ||
241 | return -EINVAL; | ||
242 | |||
243 | r8a66597_write(r8a66597, info->pipe, PIPESEL); | ||
244 | |||
245 | if (info->dir_in) | ||
246 | pipecfg |= R8A66597_DIR; | ||
247 | pipecfg |= info->type; | ||
248 | pipecfg |= info->epnum; | ||
249 | switch (info->type) { | ||
250 | case R8A66597_INT: | ||
251 | bufnum = 4 + (info->pipe - R8A66597_BASE_PIPENUM_INT); | ||
252 | buf_bsize = 0; | ||
253 | break; | ||
254 | case R8A66597_BULK: | ||
255 | /* isochronous pipes may be used as bulk pipes */ | ||
256 | if (info->pipe > R8A66597_BASE_PIPENUM_BULK) | ||
257 | bufnum = info->pipe - R8A66597_BASE_PIPENUM_BULK; | ||
258 | else | ||
259 | bufnum = info->pipe - R8A66597_BASE_PIPENUM_ISOC; | ||
260 | |||
261 | bufnum = R8A66597_BASE_BUFNUM + (bufnum * 16); | ||
262 | buf_bsize = 7; | ||
263 | pipecfg |= R8A66597_DBLB; | ||
264 | if (!info->dir_in) | ||
265 | pipecfg |= R8A66597_SHTNAK; | ||
266 | break; | ||
267 | case R8A66597_ISO: | ||
268 | bufnum = R8A66597_BASE_BUFNUM + | ||
269 | (info->pipe - R8A66597_BASE_PIPENUM_ISOC) * 16; | ||
270 | buf_bsize = 7; | ||
271 | break; | ||
272 | } | ||
273 | |||
274 | if (buf_bsize && ((bufnum + 16) >= R8A66597_MAX_BUFNUM)) { | ||
275 | pr_err(KERN_ERR "r8a66597 pipe memory is insufficient\n"); | ||
276 | return -ENOMEM; | ||
277 | } | ||
278 | |||
279 | r8a66597_write(r8a66597, pipecfg, PIPECFG); | ||
280 | r8a66597_write(r8a66597, (buf_bsize << 10) | (bufnum), PIPEBUF); | ||
281 | r8a66597_write(r8a66597, info->maxpacket, PIPEMAXP); | ||
282 | if (info->interval) | ||
283 | info->interval--; | ||
284 | r8a66597_write(r8a66597, info->interval, PIPEPERI); | ||
285 | |||
286 | return 0; | ||
287 | } | ||
288 | |||
289 | static void pipe_buffer_release(struct r8a66597 *r8a66597, | ||
290 | struct r8a66597_pipe_info *info) | ||
291 | { | ||
292 | if (info->pipe == 0) | ||
293 | return; | ||
294 | |||
295 | if (is_bulk_pipe(info->pipe)) | ||
296 | r8a66597->bulk--; | ||
297 | else if (is_interrupt_pipe(info->pipe)) | ||
298 | r8a66597->interrupt--; | ||
299 | else if (is_isoc_pipe(info->pipe)) { | ||
300 | r8a66597->isochronous--; | ||
301 | if (info->type == R8A66597_BULK) | ||
302 | r8a66597->bulk--; | ||
303 | } else | ||
304 | printk(KERN_ERR "ep_release: unexpect pipenum (%d)\n", | ||
305 | info->pipe); | ||
306 | } | ||
307 | |||
308 | static void pipe_initialize(struct r8a66597_ep *ep) | ||
309 | { | ||
310 | struct r8a66597 *r8a66597 = ep->r8a66597; | ||
311 | |||
312 | r8a66597_mdfy(r8a66597, 0, CURPIPE, ep->fifosel); | ||
313 | |||
314 | r8a66597_write(r8a66597, ACLRM, ep->pipectr); | ||
315 | r8a66597_write(r8a66597, 0, ep->pipectr); | ||
316 | r8a66597_write(r8a66597, SQCLR, ep->pipectr); | ||
317 | if (ep->use_dma) { | ||
318 | r8a66597_mdfy(r8a66597, ep->pipenum, CURPIPE, ep->fifosel); | ||
319 | |||
320 | ndelay(450); | ||
321 | |||
322 | r8a66597_bset(r8a66597, mbw_value(r8a66597), ep->fifosel); | ||
323 | } | ||
324 | } | ||
325 | |||
326 | static void r8a66597_ep_setting(struct r8a66597 *r8a66597, | ||
327 | struct r8a66597_ep *ep, | ||
328 | const struct usb_endpoint_descriptor *desc, | ||
329 | u16 pipenum, int dma) | ||
330 | { | ||
331 | ep->use_dma = 0; | ||
332 | ep->fifoaddr = CFIFO; | ||
333 | ep->fifosel = CFIFOSEL; | ||
334 | ep->fifoctr = CFIFOCTR; | ||
335 | ep->fifotrn = 0; | ||
336 | |||
337 | ep->pipectr = get_pipectr_addr(pipenum); | ||
338 | ep->pipenum = pipenum; | ||
339 | ep->ep.maxpacket = le16_to_cpu(desc->wMaxPacketSize); | ||
340 | r8a66597->pipenum2ep[pipenum] = ep; | ||
341 | r8a66597->epaddr2ep[desc->bEndpointAddress & USB_ENDPOINT_NUMBER_MASK] | ||
342 | = ep; | ||
343 | INIT_LIST_HEAD(&ep->queue); | ||
344 | } | ||
345 | |||
346 | static void r8a66597_ep_release(struct r8a66597_ep *ep) | ||
347 | { | ||
348 | struct r8a66597 *r8a66597 = ep->r8a66597; | ||
349 | u16 pipenum = ep->pipenum; | ||
350 | |||
351 | if (pipenum == 0) | ||
352 | return; | ||
353 | |||
354 | if (ep->use_dma) | ||
355 | r8a66597->num_dma--; | ||
356 | ep->pipenum = 0; | ||
357 | ep->busy = 0; | ||
358 | ep->use_dma = 0; | ||
359 | } | ||
360 | |||
361 | static int alloc_pipe_config(struct r8a66597_ep *ep, | ||
362 | const struct usb_endpoint_descriptor *desc) | ||
363 | { | ||
364 | struct r8a66597 *r8a66597 = ep->r8a66597; | ||
365 | struct r8a66597_pipe_info info; | ||
366 | int dma = 0; | ||
367 | unsigned char *counter; | ||
368 | int ret; | ||
369 | |||
370 | ep->desc = desc; | ||
371 | |||
372 | if (ep->pipenum) /* already allocated pipe */ | ||
373 | return 0; | ||
374 | |||
375 | switch (desc->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) { | ||
376 | case USB_ENDPOINT_XFER_BULK: | ||
377 | if (r8a66597->bulk >= R8A66597_MAX_NUM_BULK) { | ||
378 | if (r8a66597->isochronous >= R8A66597_MAX_NUM_ISOC) { | ||
379 | printk(KERN_ERR "bulk pipe is insufficient\n"); | ||
380 | return -ENODEV; | ||
381 | } else { | ||
382 | info.pipe = R8A66597_BASE_PIPENUM_ISOC | ||
383 | + r8a66597->isochronous; | ||
384 | counter = &r8a66597->isochronous; | ||
385 | } | ||
386 | } else { | ||
387 | info.pipe = R8A66597_BASE_PIPENUM_BULK + r8a66597->bulk; | ||
388 | counter = &r8a66597->bulk; | ||
389 | } | ||
390 | info.type = R8A66597_BULK; | ||
391 | dma = 1; | ||
392 | break; | ||
393 | case USB_ENDPOINT_XFER_INT: | ||
394 | if (r8a66597->interrupt >= R8A66597_MAX_NUM_INT) { | ||
395 | printk(KERN_ERR "interrupt pipe is insufficient\n"); | ||
396 | return -ENODEV; | ||
397 | } | ||
398 | info.pipe = R8A66597_BASE_PIPENUM_INT + r8a66597->interrupt; | ||
399 | info.type = R8A66597_INT; | ||
400 | counter = &r8a66597->interrupt; | ||
401 | break; | ||
402 | case USB_ENDPOINT_XFER_ISOC: | ||
403 | if (r8a66597->isochronous >= R8A66597_MAX_NUM_ISOC) { | ||
404 | printk(KERN_ERR "isochronous pipe is insufficient\n"); | ||
405 | return -ENODEV; | ||
406 | } | ||
407 | info.pipe = R8A66597_BASE_PIPENUM_ISOC + r8a66597->isochronous; | ||
408 | info.type = R8A66597_ISO; | ||
409 | counter = &r8a66597->isochronous; | ||
410 | break; | ||
411 | default: | ||
412 | printk(KERN_ERR "unexpect xfer type\n"); | ||
413 | return -EINVAL; | ||
414 | } | ||
415 | ep->type = info.type; | ||
416 | |||
417 | info.epnum = desc->bEndpointAddress & USB_ENDPOINT_NUMBER_MASK; | ||
418 | info.maxpacket = le16_to_cpu(desc->wMaxPacketSize); | ||
419 | info.interval = desc->bInterval; | ||
420 | if (desc->bEndpointAddress & USB_ENDPOINT_DIR_MASK) | ||
421 | info.dir_in = 1; | ||
422 | else | ||
423 | info.dir_in = 0; | ||
424 | |||
425 | ret = pipe_buffer_setting(r8a66597, &info); | ||
426 | if (ret < 0) { | ||
427 | printk(KERN_ERR "pipe_buffer_setting fail\n"); | ||
428 | return ret; | ||
429 | } | ||
430 | |||
431 | (*counter)++; | ||
432 | if ((counter == &r8a66597->isochronous) && info.type == R8A66597_BULK) | ||
433 | r8a66597->bulk++; | ||
434 | |||
435 | r8a66597_ep_setting(r8a66597, ep, desc, info.pipe, dma); | ||
436 | pipe_initialize(ep); | ||
437 | |||
438 | return 0; | ||
439 | } | ||
440 | |||
441 | static int free_pipe_config(struct r8a66597_ep *ep) | ||
442 | { | ||
443 | struct r8a66597 *r8a66597 = ep->r8a66597; | ||
444 | struct r8a66597_pipe_info info; | ||
445 | |||
446 | info.pipe = ep->pipenum; | ||
447 | info.type = ep->type; | ||
448 | pipe_buffer_release(r8a66597, &info); | ||
449 | r8a66597_ep_release(ep); | ||
450 | |||
451 | return 0; | ||
452 | } | ||
453 | |||
454 | /*-------------------------------------------------------------------------*/ | ||
455 | static void pipe_irq_enable(struct r8a66597 *r8a66597, u16 pipenum) | ||
456 | { | ||
457 | enable_irq_ready(r8a66597, pipenum); | ||
458 | enable_irq_nrdy(r8a66597, pipenum); | ||
459 | } | ||
460 | |||
461 | static void pipe_irq_disable(struct r8a66597 *r8a66597, u16 pipenum) | ||
462 | { | ||
463 | disable_irq_ready(r8a66597, pipenum); | ||
464 | disable_irq_nrdy(r8a66597, pipenum); | ||
465 | } | ||
466 | |||
467 | /* if complete is true, gadget driver complete function is not call */ | ||
468 | static void control_end(struct r8a66597 *r8a66597, unsigned ccpl) | ||
469 | { | ||
470 | r8a66597->ep[0].internal_ccpl = ccpl; | ||
471 | pipe_start(r8a66597, 0); | ||
472 | r8a66597_bset(r8a66597, CCPL, DCPCTR); | ||
473 | } | ||
474 | |||
475 | static void start_ep0_write(struct r8a66597_ep *ep, | ||
476 | struct r8a66597_request *req) | ||
477 | { | ||
478 | struct r8a66597 *r8a66597 = ep->r8a66597; | ||
479 | |||
480 | pipe_change(r8a66597, ep->pipenum); | ||
481 | r8a66597_mdfy(r8a66597, ISEL, (ISEL | CURPIPE), CFIFOSEL); | ||
482 | r8a66597_write(r8a66597, BCLR, ep->fifoctr); | ||
483 | if (req->req.length == 0) { | ||
484 | r8a66597_bset(r8a66597, BVAL, ep->fifoctr); | ||
485 | pipe_start(r8a66597, 0); | ||
486 | transfer_complete(ep, req, 0); | ||
487 | } else { | ||
488 | r8a66597_write(r8a66597, ~BEMP0, BEMPSTS); | ||
489 | irq_ep0_write(ep, req); | ||
490 | } | ||
491 | } | ||
492 | |||
493 | static void start_packet_write(struct r8a66597_ep *ep, | ||
494 | struct r8a66597_request *req) | ||
495 | { | ||
496 | struct r8a66597 *r8a66597 = ep->r8a66597; | ||
497 | u16 tmp; | ||
498 | |||
499 | pipe_change(r8a66597, ep->pipenum); | ||
500 | disable_irq_empty(r8a66597, ep->pipenum); | ||
501 | pipe_start(r8a66597, ep->pipenum); | ||
502 | |||
503 | tmp = r8a66597_read(r8a66597, ep->fifoctr); | ||
504 | if (unlikely((tmp & FRDY) == 0)) | ||
505 | pipe_irq_enable(r8a66597, ep->pipenum); | ||
506 | else | ||
507 | irq_packet_write(ep, req); | ||
508 | } | ||
509 | |||
510 | static void start_packet_read(struct r8a66597_ep *ep, | ||
511 | struct r8a66597_request *req) | ||
512 | { | ||
513 | struct r8a66597 *r8a66597 = ep->r8a66597; | ||
514 | u16 pipenum = ep->pipenum; | ||
515 | |||
516 | if (ep->pipenum == 0) { | ||
517 | r8a66597_mdfy(r8a66597, 0, (ISEL | CURPIPE), CFIFOSEL); | ||
518 | r8a66597_write(r8a66597, BCLR, ep->fifoctr); | ||
519 | pipe_start(r8a66597, pipenum); | ||
520 | pipe_irq_enable(r8a66597, pipenum); | ||
521 | } else { | ||
522 | if (ep->use_dma) { | ||
523 | r8a66597_bset(r8a66597, TRCLR, ep->fifosel); | ||
524 | pipe_change(r8a66597, pipenum); | ||
525 | r8a66597_bset(r8a66597, TRENB, ep->fifosel); | ||
526 | r8a66597_write(r8a66597, | ||
527 | (req->req.length + ep->ep.maxpacket - 1) | ||
528 | / ep->ep.maxpacket, | ||
529 | ep->fifotrn); | ||
530 | } | ||
531 | pipe_start(r8a66597, pipenum); /* trigger once */ | ||
532 | pipe_irq_enable(r8a66597, pipenum); | ||
533 | } | ||
534 | } | ||
535 | |||
536 | static void start_packet(struct r8a66597_ep *ep, struct r8a66597_request *req) | ||
537 | { | ||
538 | if (ep->desc->bEndpointAddress & USB_DIR_IN) | ||
539 | start_packet_write(ep, req); | ||
540 | else | ||
541 | start_packet_read(ep, req); | ||
542 | } | ||
543 | |||
544 | static void start_ep0(struct r8a66597_ep *ep, struct r8a66597_request *req) | ||
545 | { | ||
546 | u16 ctsq; | ||
547 | |||
548 | ctsq = r8a66597_read(ep->r8a66597, INTSTS0) & CTSQ; | ||
549 | |||
550 | switch (ctsq) { | ||
551 | case CS_RDDS: | ||
552 | start_ep0_write(ep, req); | ||
553 | break; | ||
554 | case CS_WRDS: | ||
555 | start_packet_read(ep, req); | ||
556 | break; | ||
557 | |||
558 | case CS_WRND: | ||
559 | control_end(ep->r8a66597, 0); | ||
560 | break; | ||
561 | default: | ||
562 | printk(KERN_ERR "start_ep0: unexpect ctsq(%x)\n", ctsq); | ||
563 | break; | ||
564 | } | ||
565 | } | ||
566 | |||
567 | static void init_controller(struct r8a66597 *r8a66597) | ||
568 | { | ||
569 | u16 vif = r8a66597->pdata->vif ? LDRV : 0; | ||
570 | u16 irq_sense = r8a66597->irq_sense_low ? INTL : 0; | ||
571 | u16 endian = r8a66597->pdata->endian ? BIGEND : 0; | ||
572 | |||
573 | if (r8a66597->pdata->on_chip) { | ||
574 | r8a66597_bset(r8a66597, 0x04, SYSCFG1); | ||
575 | r8a66597_bset(r8a66597, HSE, SYSCFG0); | ||
576 | |||
577 | r8a66597_bclr(r8a66597, USBE, SYSCFG0); | ||
578 | r8a66597_bclr(r8a66597, DPRPU, SYSCFG0); | ||
579 | r8a66597_bset(r8a66597, USBE, SYSCFG0); | ||
580 | |||
581 | r8a66597_bset(r8a66597, SCKE, SYSCFG0); | ||
582 | |||
583 | r8a66597_bset(r8a66597, irq_sense, INTENB1); | ||
584 | r8a66597_write(r8a66597, BURST | CPU_ADR_RD_WR, | ||
585 | DMA0CFG); | ||
586 | } else { | ||
587 | r8a66597_bset(r8a66597, vif | endian, PINCFG); | ||
588 | r8a66597_bset(r8a66597, HSE, SYSCFG0); /* High spd */ | ||
589 | r8a66597_mdfy(r8a66597, get_xtal_from_pdata(r8a66597->pdata), | ||
590 | XTAL, SYSCFG0); | ||
591 | |||
592 | r8a66597_bclr(r8a66597, USBE, SYSCFG0); | ||
593 | r8a66597_bclr(r8a66597, DPRPU, SYSCFG0); | ||
594 | r8a66597_bset(r8a66597, USBE, SYSCFG0); | ||
595 | |||
596 | r8a66597_bset(r8a66597, XCKE, SYSCFG0); | ||
597 | |||
598 | msleep(3); | ||
599 | |||
600 | r8a66597_bset(r8a66597, PLLC, SYSCFG0); | ||
601 | |||
602 | msleep(1); | ||
603 | |||
604 | r8a66597_bset(r8a66597, SCKE, SYSCFG0); | ||
605 | |||
606 | r8a66597_bset(r8a66597, irq_sense, INTENB1); | ||
607 | r8a66597_write(r8a66597, BURST | CPU_ADR_RD_WR, | ||
608 | DMA0CFG); | ||
609 | } | ||
610 | } | ||
611 | |||
612 | static void disable_controller(struct r8a66597 *r8a66597) | ||
613 | { | ||
614 | if (r8a66597->pdata->on_chip) { | ||
615 | r8a66597_bset(r8a66597, SCKE, SYSCFG0); | ||
616 | |||
617 | /* disable interrupts */ | ||
618 | r8a66597_write(r8a66597, 0, INTENB0); | ||
619 | r8a66597_write(r8a66597, 0, INTENB1); | ||
620 | r8a66597_write(r8a66597, 0, BRDYENB); | ||
621 | r8a66597_write(r8a66597, 0, BEMPENB); | ||
622 | r8a66597_write(r8a66597, 0, NRDYENB); | ||
623 | |||
624 | /* clear status */ | ||
625 | r8a66597_write(r8a66597, 0, BRDYSTS); | ||
626 | r8a66597_write(r8a66597, 0, NRDYSTS); | ||
627 | r8a66597_write(r8a66597, 0, BEMPSTS); | ||
628 | |||
629 | r8a66597_bclr(r8a66597, USBE, SYSCFG0); | ||
630 | r8a66597_bclr(r8a66597, SCKE, SYSCFG0); | ||
631 | |||
632 | } else { | ||
633 | r8a66597_bclr(r8a66597, SCKE, SYSCFG0); | ||
634 | udelay(1); | ||
635 | r8a66597_bclr(r8a66597, PLLC, SYSCFG0); | ||
636 | udelay(1); | ||
637 | udelay(1); | ||
638 | r8a66597_bclr(r8a66597, XCKE, SYSCFG0); | ||
639 | } | ||
640 | } | ||
641 | |||
642 | static void r8a66597_start_xclock(struct r8a66597 *r8a66597) | ||
643 | { | ||
644 | u16 tmp; | ||
645 | |||
646 | if (!r8a66597->pdata->on_chip) { | ||
647 | tmp = r8a66597_read(r8a66597, SYSCFG0); | ||
648 | if (!(tmp & XCKE)) | ||
649 | r8a66597_bset(r8a66597, XCKE, SYSCFG0); | ||
650 | } | ||
651 | } | ||
652 | |||
653 | static struct r8a66597_request *get_request_from_ep(struct r8a66597_ep *ep) | ||
654 | { | ||
655 | return list_entry(ep->queue.next, struct r8a66597_request, queue); | ||
656 | } | ||
657 | |||
658 | /*-------------------------------------------------------------------------*/ | ||
659 | static void transfer_complete(struct r8a66597_ep *ep, | ||
660 | struct r8a66597_request *req, int status) | ||
661 | __releases(r8a66597->lock) | ||
662 | __acquires(r8a66597->lock) | ||
663 | { | ||
664 | int restart = 0; | ||
665 | |||
666 | if (unlikely(ep->pipenum == 0)) { | ||
667 | if (ep->internal_ccpl) { | ||
668 | ep->internal_ccpl = 0; | ||
669 | return; | ||
670 | } | ||
671 | } | ||
672 | |||
673 | list_del_init(&req->queue); | ||
674 | if (ep->r8a66597->gadget.speed == USB_SPEED_UNKNOWN) | ||
675 | req->req.status = -ESHUTDOWN; | ||
676 | else | ||
677 | req->req.status = status; | ||
678 | |||
679 | if (!list_empty(&ep->queue)) | ||
680 | restart = 1; | ||
681 | |||
682 | spin_unlock(&ep->r8a66597->lock); | ||
683 | req->req.complete(&ep->ep, &req->req); | ||
684 | spin_lock(&ep->r8a66597->lock); | ||
685 | |||
686 | if (restart) { | ||
687 | req = get_request_from_ep(ep); | ||
688 | if (ep->desc) | ||
689 | start_packet(ep, req); | ||
690 | } | ||
691 | } | ||
692 | |||
693 | static void irq_ep0_write(struct r8a66597_ep *ep, struct r8a66597_request *req) | ||
694 | { | ||
695 | int i; | ||
696 | u16 tmp; | ||
697 | unsigned bufsize; | ||
698 | size_t size; | ||
699 | void *buf; | ||
700 | u16 pipenum = ep->pipenum; | ||
701 | struct r8a66597 *r8a66597 = ep->r8a66597; | ||
702 | |||
703 | pipe_change(r8a66597, pipenum); | ||
704 | r8a66597_bset(r8a66597, ISEL, ep->fifosel); | ||
705 | |||
706 | i = 0; | ||
707 | do { | ||
708 | tmp = r8a66597_read(r8a66597, ep->fifoctr); | ||
709 | if (i++ > 100000) { | ||
710 | printk(KERN_ERR "pipe0 is busy. maybe cpu i/o bus" | ||
711 | "conflict. please power off this controller."); | ||
712 | return; | ||
713 | } | ||
714 | ndelay(1); | ||
715 | } while ((tmp & FRDY) == 0); | ||
716 | |||
717 | /* prepare parameters */ | ||
718 | bufsize = get_buffer_size(r8a66597, pipenum); | ||
719 | buf = req->req.buf + req->req.actual; | ||
720 | size = min(bufsize, req->req.length - req->req.actual); | ||
721 | |||
722 | /* write fifo */ | ||
723 | if (req->req.buf) { | ||
724 | if (size > 0) | ||
725 | r8a66597_write_fifo(r8a66597, ep->fifoaddr, buf, size); | ||
726 | if ((size == 0) || ((size % ep->ep.maxpacket) != 0)) | ||
727 | r8a66597_bset(r8a66597, BVAL, ep->fifoctr); | ||
728 | } | ||
729 | |||
730 | /* update parameters */ | ||
731 | req->req.actual += size; | ||
732 | |||
733 | /* check transfer finish */ | ||
734 | if ((!req->req.zero && (req->req.actual == req->req.length)) | ||
735 | || (size % ep->ep.maxpacket) | ||
736 | || (size == 0)) { | ||
737 | disable_irq_ready(r8a66597, pipenum); | ||
738 | disable_irq_empty(r8a66597, pipenum); | ||
739 | } else { | ||
740 | disable_irq_ready(r8a66597, pipenum); | ||
741 | enable_irq_empty(r8a66597, pipenum); | ||
742 | } | ||
743 | pipe_start(r8a66597, pipenum); | ||
744 | } | ||
745 | |||
746 | static void irq_packet_write(struct r8a66597_ep *ep, | ||
747 | struct r8a66597_request *req) | ||
748 | { | ||
749 | u16 tmp; | ||
750 | unsigned bufsize; | ||
751 | size_t size; | ||
752 | void *buf; | ||
753 | u16 pipenum = ep->pipenum; | ||
754 | struct r8a66597 *r8a66597 = ep->r8a66597; | ||
755 | |||
756 | pipe_change(r8a66597, pipenum); | ||
757 | tmp = r8a66597_read(r8a66597, ep->fifoctr); | ||
758 | if (unlikely((tmp & FRDY) == 0)) { | ||
759 | pipe_stop(r8a66597, pipenum); | ||
760 | pipe_irq_disable(r8a66597, pipenum); | ||
761 | printk(KERN_ERR "write fifo not ready. pipnum=%d\n", pipenum); | ||
762 | return; | ||
763 | } | ||
764 | |||
765 | /* prepare parameters */ | ||
766 | bufsize = get_buffer_size(r8a66597, pipenum); | ||
767 | buf = req->req.buf + req->req.actual; | ||
768 | size = min(bufsize, req->req.length - req->req.actual); | ||
769 | |||
770 | /* write fifo */ | ||
771 | if (req->req.buf) { | ||
772 | r8a66597_write_fifo(r8a66597, ep->fifoaddr, buf, size); | ||
773 | if ((size == 0) | ||
774 | || ((size % ep->ep.maxpacket) != 0) | ||
775 | || ((bufsize != ep->ep.maxpacket) | ||
776 | && (bufsize > size))) | ||
777 | r8a66597_bset(r8a66597, BVAL, ep->fifoctr); | ||
778 | } | ||
779 | |||
780 | /* update parameters */ | ||
781 | req->req.actual += size; | ||
782 | /* check transfer finish */ | ||
783 | if ((!req->req.zero && (req->req.actual == req->req.length)) | ||
784 | || (size % ep->ep.maxpacket) | ||
785 | || (size == 0)) { | ||
786 | disable_irq_ready(r8a66597, pipenum); | ||
787 | enable_irq_empty(r8a66597, pipenum); | ||
788 | } else { | ||
789 | disable_irq_empty(r8a66597, pipenum); | ||
790 | pipe_irq_enable(r8a66597, pipenum); | ||
791 | } | ||
792 | } | ||
793 | |||
794 | static void irq_packet_read(struct r8a66597_ep *ep, | ||
795 | struct r8a66597_request *req) | ||
796 | { | ||
797 | u16 tmp; | ||
798 | int rcv_len, bufsize, req_len; | ||
799 | int size; | ||
800 | void *buf; | ||
801 | u16 pipenum = ep->pipenum; | ||
802 | struct r8a66597 *r8a66597 = ep->r8a66597; | ||
803 | int finish = 0; | ||
804 | |||
805 | pipe_change(r8a66597, pipenum); | ||
806 | tmp = r8a66597_read(r8a66597, ep->fifoctr); | ||
807 | if (unlikely((tmp & FRDY) == 0)) { | ||
808 | req->req.status = -EPIPE; | ||
809 | pipe_stop(r8a66597, pipenum); | ||
810 | pipe_irq_disable(r8a66597, pipenum); | ||
811 | printk(KERN_ERR "read fifo not ready"); | ||
812 | return; | ||
813 | } | ||
814 | |||
815 | /* prepare parameters */ | ||
816 | rcv_len = tmp & DTLN; | ||
817 | bufsize = get_buffer_size(r8a66597, pipenum); | ||
818 | |||
819 | buf = req->req.buf + req->req.actual; | ||
820 | req_len = req->req.length - req->req.actual; | ||
821 | if (rcv_len < bufsize) | ||
822 | size = min(rcv_len, req_len); | ||
823 | else | ||
824 | size = min(bufsize, req_len); | ||
825 | |||
826 | /* update parameters */ | ||
827 | req->req.actual += size; | ||
828 | |||
829 | /* check transfer finish */ | ||
830 | if ((!req->req.zero && (req->req.actual == req->req.length)) | ||
831 | || (size % ep->ep.maxpacket) | ||
832 | || (size == 0)) { | ||
833 | pipe_stop(r8a66597, pipenum); | ||
834 | pipe_irq_disable(r8a66597, pipenum); | ||
835 | finish = 1; | ||
836 | } | ||
837 | |||
838 | /* read fifo */ | ||
839 | if (req->req.buf) { | ||
840 | if (size == 0) | ||
841 | r8a66597_write(r8a66597, BCLR, ep->fifoctr); | ||
842 | else | ||
843 | r8a66597_read_fifo(r8a66597, ep->fifoaddr, buf, size); | ||
844 | |||
845 | } | ||
846 | |||
847 | if ((ep->pipenum != 0) && finish) | ||
848 | transfer_complete(ep, req, 0); | ||
849 | } | ||
850 | |||
851 | static void irq_pipe_ready(struct r8a66597 *r8a66597, u16 status, u16 enb) | ||
852 | { | ||
853 | u16 check; | ||
854 | u16 pipenum; | ||
855 | struct r8a66597_ep *ep; | ||
856 | struct r8a66597_request *req; | ||
857 | |||
858 | if ((status & BRDY0) && (enb & BRDY0)) { | ||
859 | r8a66597_write(r8a66597, ~BRDY0, BRDYSTS); | ||
860 | r8a66597_mdfy(r8a66597, 0, CURPIPE, CFIFOSEL); | ||
861 | |||
862 | ep = &r8a66597->ep[0]; | ||
863 | req = get_request_from_ep(ep); | ||
864 | irq_packet_read(ep, req); | ||
865 | } else { | ||
866 | for (pipenum = 1; pipenum < R8A66597_MAX_NUM_PIPE; pipenum++) { | ||
867 | check = 1 << pipenum; | ||
868 | if ((status & check) && (enb & check)) { | ||
869 | r8a66597_write(r8a66597, ~check, BRDYSTS); | ||
870 | ep = r8a66597->pipenum2ep[pipenum]; | ||
871 | req = get_request_from_ep(ep); | ||
872 | if (ep->desc->bEndpointAddress & USB_DIR_IN) | ||
873 | irq_packet_write(ep, req); | ||
874 | else | ||
875 | irq_packet_read(ep, req); | ||
876 | } | ||
877 | } | ||
878 | } | ||
879 | } | ||
880 | |||
881 | static void irq_pipe_empty(struct r8a66597 *r8a66597, u16 status, u16 enb) | ||
882 | { | ||
883 | u16 tmp; | ||
884 | u16 check; | ||
885 | u16 pipenum; | ||
886 | struct r8a66597_ep *ep; | ||
887 | struct r8a66597_request *req; | ||
888 | |||
889 | if ((status & BEMP0) && (enb & BEMP0)) { | ||
890 | r8a66597_write(r8a66597, ~BEMP0, BEMPSTS); | ||
891 | |||
892 | ep = &r8a66597->ep[0]; | ||
893 | req = get_request_from_ep(ep); | ||
894 | irq_ep0_write(ep, req); | ||
895 | } else { | ||
896 | for (pipenum = 1; pipenum < R8A66597_MAX_NUM_PIPE; pipenum++) { | ||
897 | check = 1 << pipenum; | ||
898 | if ((status & check) && (enb & check)) { | ||
899 | r8a66597_write(r8a66597, ~check, BEMPSTS); | ||
900 | tmp = control_reg_get(r8a66597, pipenum); | ||
901 | if ((tmp & INBUFM) == 0) { | ||
902 | disable_irq_empty(r8a66597, pipenum); | ||
903 | pipe_irq_disable(r8a66597, pipenum); | ||
904 | pipe_stop(r8a66597, pipenum); | ||
905 | ep = r8a66597->pipenum2ep[pipenum]; | ||
906 | req = get_request_from_ep(ep); | ||
907 | if (!list_empty(&ep->queue)) | ||
908 | transfer_complete(ep, req, 0); | ||
909 | } | ||
910 | } | ||
911 | } | ||
912 | } | ||
913 | } | ||
914 | |||
915 | static void get_status(struct r8a66597 *r8a66597, struct usb_ctrlrequest *ctrl) | ||
916 | __releases(r8a66597->lock) | ||
917 | __acquires(r8a66597->lock) | ||
918 | { | ||
919 | struct r8a66597_ep *ep; | ||
920 | u16 pid; | ||
921 | u16 status = 0; | ||
922 | u16 w_index = le16_to_cpu(ctrl->wIndex); | ||
923 | |||
924 | switch (ctrl->bRequestType & USB_RECIP_MASK) { | ||
925 | case USB_RECIP_DEVICE: | ||
926 | status = 1 << USB_DEVICE_SELF_POWERED; | ||
927 | break; | ||
928 | case USB_RECIP_INTERFACE: | ||
929 | status = 0; | ||
930 | break; | ||
931 | case USB_RECIP_ENDPOINT: | ||
932 | ep = r8a66597->epaddr2ep[w_index & USB_ENDPOINT_NUMBER_MASK]; | ||
933 | pid = control_reg_get_pid(r8a66597, ep->pipenum); | ||
934 | if (pid == PID_STALL) | ||
935 | status = 1 << USB_ENDPOINT_HALT; | ||
936 | else | ||
937 | status = 0; | ||
938 | break; | ||
939 | default: | ||
940 | pipe_stall(r8a66597, 0); | ||
941 | return; /* exit */ | ||
942 | } | ||
943 | |||
944 | r8a66597->ep0_data = cpu_to_le16(status); | ||
945 | r8a66597->ep0_req->buf = &r8a66597->ep0_data; | ||
946 | r8a66597->ep0_req->length = 2; | ||
947 | /* AV: what happens if we get called again before that gets through? */ | ||
948 | spin_unlock(&r8a66597->lock); | ||
949 | r8a66597_queue(r8a66597->gadget.ep0, r8a66597->ep0_req, GFP_KERNEL); | ||
950 | spin_lock(&r8a66597->lock); | ||
951 | } | ||
952 | |||
953 | static void clear_feature(struct r8a66597 *r8a66597, | ||
954 | struct usb_ctrlrequest *ctrl) | ||
955 | { | ||
956 | switch (ctrl->bRequestType & USB_RECIP_MASK) { | ||
957 | case USB_RECIP_DEVICE: | ||
958 | control_end(r8a66597, 1); | ||
959 | break; | ||
960 | case USB_RECIP_INTERFACE: | ||
961 | control_end(r8a66597, 1); | ||
962 | break; | ||
963 | case USB_RECIP_ENDPOINT: { | ||
964 | struct r8a66597_ep *ep; | ||
965 | struct r8a66597_request *req; | ||
966 | u16 w_index = le16_to_cpu(ctrl->wIndex); | ||
967 | |||
968 | ep = r8a66597->epaddr2ep[w_index & USB_ENDPOINT_NUMBER_MASK]; | ||
969 | if (!ep->wedge) { | ||
970 | pipe_stop(r8a66597, ep->pipenum); | ||
971 | control_reg_sqclr(r8a66597, ep->pipenum); | ||
972 | spin_unlock(&r8a66597->lock); | ||
973 | usb_ep_clear_halt(&ep->ep); | ||
974 | spin_lock(&r8a66597->lock); | ||
975 | } | ||
976 | |||
977 | control_end(r8a66597, 1); | ||
978 | |||
979 | req = get_request_from_ep(ep); | ||
980 | if (ep->busy) { | ||
981 | ep->busy = 0; | ||
982 | if (list_empty(&ep->queue)) | ||
983 | break; | ||
984 | start_packet(ep, req); | ||
985 | } else if (!list_empty(&ep->queue)) | ||
986 | pipe_start(r8a66597, ep->pipenum); | ||
987 | } | ||
988 | break; | ||
989 | default: | ||
990 | pipe_stall(r8a66597, 0); | ||
991 | break; | ||
992 | } | ||
993 | } | ||
994 | |||
995 | static void set_feature(struct r8a66597 *r8a66597, struct usb_ctrlrequest *ctrl) | ||
996 | { | ||
997 | |||
998 | switch (ctrl->bRequestType & USB_RECIP_MASK) { | ||
999 | case USB_RECIP_DEVICE: | ||
1000 | control_end(r8a66597, 1); | ||
1001 | break; | ||
1002 | case USB_RECIP_INTERFACE: | ||
1003 | control_end(r8a66597, 1); | ||
1004 | break; | ||
1005 | case USB_RECIP_ENDPOINT: { | ||
1006 | struct r8a66597_ep *ep; | ||
1007 | u16 w_index = le16_to_cpu(ctrl->wIndex); | ||
1008 | |||
1009 | ep = r8a66597->epaddr2ep[w_index & USB_ENDPOINT_NUMBER_MASK]; | ||
1010 | pipe_stall(r8a66597, ep->pipenum); | ||
1011 | |||
1012 | control_end(r8a66597, 1); | ||
1013 | } | ||
1014 | break; | ||
1015 | default: | ||
1016 | pipe_stall(r8a66597, 0); | ||
1017 | break; | ||
1018 | } | ||
1019 | } | ||
1020 | |||
1021 | /* if return value is true, call class driver's setup() */ | ||
1022 | static int setup_packet(struct r8a66597 *r8a66597, struct usb_ctrlrequest *ctrl) | ||
1023 | { | ||
1024 | u16 *p = (u16 *)ctrl; | ||
1025 | unsigned long offset = USBREQ; | ||
1026 | int i, ret = 0; | ||
1027 | |||
1028 | /* read fifo */ | ||
1029 | r8a66597_write(r8a66597, ~VALID, INTSTS0); | ||
1030 | |||
1031 | for (i = 0; i < 4; i++) | ||
1032 | p[i] = r8a66597_read(r8a66597, offset + i*2); | ||
1033 | |||
1034 | /* check request */ | ||
1035 | if ((ctrl->bRequestType & USB_TYPE_MASK) == USB_TYPE_STANDARD) { | ||
1036 | switch (ctrl->bRequest) { | ||
1037 | case USB_REQ_GET_STATUS: | ||
1038 | get_status(r8a66597, ctrl); | ||
1039 | break; | ||
1040 | case USB_REQ_CLEAR_FEATURE: | ||
1041 | clear_feature(r8a66597, ctrl); | ||
1042 | break; | ||
1043 | case USB_REQ_SET_FEATURE: | ||
1044 | set_feature(r8a66597, ctrl); | ||
1045 | break; | ||
1046 | default: | ||
1047 | ret = 1; | ||
1048 | break; | ||
1049 | } | ||
1050 | } else | ||
1051 | ret = 1; | ||
1052 | return ret; | ||
1053 | } | ||
1054 | |||
1055 | static void r8a66597_update_usb_speed(struct r8a66597 *r8a66597) | ||
1056 | { | ||
1057 | u16 speed = get_usb_speed(r8a66597); | ||
1058 | |||
1059 | switch (speed) { | ||
1060 | case HSMODE: | ||
1061 | r8a66597->gadget.speed = USB_SPEED_HIGH; | ||
1062 | break; | ||
1063 | case FSMODE: | ||
1064 | r8a66597->gadget.speed = USB_SPEED_FULL; | ||
1065 | break; | ||
1066 | default: | ||
1067 | r8a66597->gadget.speed = USB_SPEED_UNKNOWN; | ||
1068 | printk(KERN_ERR "USB speed unknown\n"); | ||
1069 | } | ||
1070 | } | ||
1071 | |||
1072 | static void irq_device_state(struct r8a66597 *r8a66597) | ||
1073 | { | ||
1074 | u16 dvsq; | ||
1075 | |||
1076 | dvsq = r8a66597_read(r8a66597, INTSTS0) & DVSQ; | ||
1077 | r8a66597_write(r8a66597, ~DVST, INTSTS0); | ||
1078 | |||
1079 | if (dvsq == DS_DFLT) { | ||
1080 | /* bus reset */ | ||
1081 | r8a66597->driver->disconnect(&r8a66597->gadget); | ||
1082 | r8a66597_update_usb_speed(r8a66597); | ||
1083 | } | ||
1084 | if (r8a66597->old_dvsq == DS_CNFG && dvsq != DS_CNFG) | ||
1085 | r8a66597_update_usb_speed(r8a66597); | ||
1086 | if ((dvsq == DS_CNFG || dvsq == DS_ADDS) | ||
1087 | && r8a66597->gadget.speed == USB_SPEED_UNKNOWN) | ||
1088 | r8a66597_update_usb_speed(r8a66597); | ||
1089 | |||
1090 | r8a66597->old_dvsq = dvsq; | ||
1091 | } | ||
1092 | |||
1093 | static void irq_control_stage(struct r8a66597 *r8a66597) | ||
1094 | __releases(r8a66597->lock) | ||
1095 | __acquires(r8a66597->lock) | ||
1096 | { | ||
1097 | struct usb_ctrlrequest ctrl; | ||
1098 | u16 ctsq; | ||
1099 | |||
1100 | ctsq = r8a66597_read(r8a66597, INTSTS0) & CTSQ; | ||
1101 | r8a66597_write(r8a66597, ~CTRT, INTSTS0); | ||
1102 | |||
1103 | switch (ctsq) { | ||
1104 | case CS_IDST: { | ||
1105 | struct r8a66597_ep *ep; | ||
1106 | struct r8a66597_request *req; | ||
1107 | ep = &r8a66597->ep[0]; | ||
1108 | req = get_request_from_ep(ep); | ||
1109 | transfer_complete(ep, req, 0); | ||
1110 | } | ||
1111 | break; | ||
1112 | |||
1113 | case CS_RDDS: | ||
1114 | case CS_WRDS: | ||
1115 | case CS_WRND: | ||
1116 | if (setup_packet(r8a66597, &ctrl)) { | ||
1117 | spin_unlock(&r8a66597->lock); | ||
1118 | if (r8a66597->driver->setup(&r8a66597->gadget, &ctrl) | ||
1119 | < 0) | ||
1120 | pipe_stall(r8a66597, 0); | ||
1121 | spin_lock(&r8a66597->lock); | ||
1122 | } | ||
1123 | break; | ||
1124 | case CS_RDSS: | ||
1125 | case CS_WRSS: | ||
1126 | control_end(r8a66597, 0); | ||
1127 | break; | ||
1128 | default: | ||
1129 | printk(KERN_ERR "ctrl_stage: unexpect ctsq(%x)\n", ctsq); | ||
1130 | break; | ||
1131 | } | ||
1132 | } | ||
1133 | |||
1134 | static irqreturn_t r8a66597_irq(int irq, void *_r8a66597) | ||
1135 | { | ||
1136 | struct r8a66597 *r8a66597 = _r8a66597; | ||
1137 | u16 intsts0; | ||
1138 | u16 intenb0; | ||
1139 | u16 brdysts, nrdysts, bempsts; | ||
1140 | u16 brdyenb, nrdyenb, bempenb; | ||
1141 | u16 savepipe; | ||
1142 | u16 mask0; | ||
1143 | |||
1144 | spin_lock(&r8a66597->lock); | ||
1145 | |||
1146 | intsts0 = r8a66597_read(r8a66597, INTSTS0); | ||
1147 | intenb0 = r8a66597_read(r8a66597, INTENB0); | ||
1148 | |||
1149 | savepipe = r8a66597_read(r8a66597, CFIFOSEL); | ||
1150 | |||
1151 | mask0 = intsts0 & intenb0; | ||
1152 | if (mask0) { | ||
1153 | brdysts = r8a66597_read(r8a66597, BRDYSTS); | ||
1154 | nrdysts = r8a66597_read(r8a66597, NRDYSTS); | ||
1155 | bempsts = r8a66597_read(r8a66597, BEMPSTS); | ||
1156 | brdyenb = r8a66597_read(r8a66597, BRDYENB); | ||
1157 | nrdyenb = r8a66597_read(r8a66597, NRDYENB); | ||
1158 | bempenb = r8a66597_read(r8a66597, BEMPENB); | ||
1159 | |||
1160 | if (mask0 & VBINT) { | ||
1161 | r8a66597_write(r8a66597, 0xffff & ~VBINT, | ||
1162 | INTSTS0); | ||
1163 | r8a66597_start_xclock(r8a66597); | ||
1164 | |||
1165 | /* start vbus sampling */ | ||
1166 | r8a66597->old_vbus = r8a66597_read(r8a66597, INTSTS0) | ||
1167 | & VBSTS; | ||
1168 | r8a66597->scount = R8A66597_MAX_SAMPLING; | ||
1169 | |||
1170 | mod_timer(&r8a66597->timer, | ||
1171 | jiffies + msecs_to_jiffies(50)); | ||
1172 | } | ||
1173 | if (intsts0 & DVSQ) | ||
1174 | irq_device_state(r8a66597); | ||
1175 | |||
1176 | if ((intsts0 & BRDY) && (intenb0 & BRDYE) | ||
1177 | && (brdysts & brdyenb)) | ||
1178 | irq_pipe_ready(r8a66597, brdysts, brdyenb); | ||
1179 | if ((intsts0 & BEMP) && (intenb0 & BEMPE) | ||
1180 | && (bempsts & bempenb)) | ||
1181 | irq_pipe_empty(r8a66597, bempsts, bempenb); | ||
1182 | |||
1183 | if (intsts0 & CTRT) | ||
1184 | irq_control_stage(r8a66597); | ||
1185 | } | ||
1186 | |||
1187 | r8a66597_write(r8a66597, savepipe, CFIFOSEL); | ||
1188 | |||
1189 | spin_unlock(&r8a66597->lock); | ||
1190 | return IRQ_HANDLED; | ||
1191 | } | ||
1192 | |||
1193 | static void r8a66597_timer(unsigned long _r8a66597) | ||
1194 | { | ||
1195 | struct r8a66597 *r8a66597 = (struct r8a66597 *)_r8a66597; | ||
1196 | unsigned long flags; | ||
1197 | u16 tmp; | ||
1198 | |||
1199 | spin_lock_irqsave(&r8a66597->lock, flags); | ||
1200 | tmp = r8a66597_read(r8a66597, SYSCFG0); | ||
1201 | if (r8a66597->scount > 0) { | ||
1202 | tmp = r8a66597_read(r8a66597, INTSTS0) & VBSTS; | ||
1203 | if (tmp == r8a66597->old_vbus) { | ||
1204 | r8a66597->scount--; | ||
1205 | if (r8a66597->scount == 0) { | ||
1206 | if (tmp == VBSTS) | ||
1207 | r8a66597_usb_connect(r8a66597); | ||
1208 | else | ||
1209 | r8a66597_usb_disconnect(r8a66597); | ||
1210 | } else { | ||
1211 | mod_timer(&r8a66597->timer, | ||
1212 | jiffies + msecs_to_jiffies(50)); | ||
1213 | } | ||
1214 | } else { | ||
1215 | r8a66597->scount = R8A66597_MAX_SAMPLING; | ||
1216 | r8a66597->old_vbus = tmp; | ||
1217 | mod_timer(&r8a66597->timer, | ||
1218 | jiffies + msecs_to_jiffies(50)); | ||
1219 | } | ||
1220 | } | ||
1221 | spin_unlock_irqrestore(&r8a66597->lock, flags); | ||
1222 | } | ||
1223 | |||
1224 | /*-------------------------------------------------------------------------*/ | ||
1225 | static int r8a66597_enable(struct usb_ep *_ep, | ||
1226 | const struct usb_endpoint_descriptor *desc) | ||
1227 | { | ||
1228 | struct r8a66597_ep *ep; | ||
1229 | |||
1230 | ep = container_of(_ep, struct r8a66597_ep, ep); | ||
1231 | return alloc_pipe_config(ep, desc); | ||
1232 | } | ||
1233 | |||
1234 | static int r8a66597_disable(struct usb_ep *_ep) | ||
1235 | { | ||
1236 | struct r8a66597_ep *ep; | ||
1237 | struct r8a66597_request *req; | ||
1238 | unsigned long flags; | ||
1239 | |||
1240 | ep = container_of(_ep, struct r8a66597_ep, ep); | ||
1241 | BUG_ON(!ep); | ||
1242 | |||
1243 | while (!list_empty(&ep->queue)) { | ||
1244 | req = get_request_from_ep(ep); | ||
1245 | spin_lock_irqsave(&ep->r8a66597->lock, flags); | ||
1246 | transfer_complete(ep, req, -ECONNRESET); | ||
1247 | spin_unlock_irqrestore(&ep->r8a66597->lock, flags); | ||
1248 | } | ||
1249 | |||
1250 | pipe_irq_disable(ep->r8a66597, ep->pipenum); | ||
1251 | return free_pipe_config(ep); | ||
1252 | } | ||
1253 | |||
1254 | static struct usb_request *r8a66597_alloc_request(struct usb_ep *_ep, | ||
1255 | gfp_t gfp_flags) | ||
1256 | { | ||
1257 | struct r8a66597_request *req; | ||
1258 | |||
1259 | req = kzalloc(sizeof(struct r8a66597_request), gfp_flags); | ||
1260 | if (!req) | ||
1261 | return NULL; | ||
1262 | |||
1263 | INIT_LIST_HEAD(&req->queue); | ||
1264 | |||
1265 | return &req->req; | ||
1266 | } | ||
1267 | |||
1268 | static void r8a66597_free_request(struct usb_ep *_ep, struct usb_request *_req) | ||
1269 | { | ||
1270 | struct r8a66597_request *req; | ||
1271 | |||
1272 | req = container_of(_req, struct r8a66597_request, req); | ||
1273 | kfree(req); | ||
1274 | } | ||
1275 | |||
1276 | static int r8a66597_queue(struct usb_ep *_ep, struct usb_request *_req, | ||
1277 | gfp_t gfp_flags) | ||
1278 | { | ||
1279 | struct r8a66597_ep *ep; | ||
1280 | struct r8a66597_request *req; | ||
1281 | unsigned long flags; | ||
1282 | int request = 0; | ||
1283 | |||
1284 | ep = container_of(_ep, struct r8a66597_ep, ep); | ||
1285 | req = container_of(_req, struct r8a66597_request, req); | ||
1286 | |||
1287 | if (ep->r8a66597->gadget.speed == USB_SPEED_UNKNOWN) | ||
1288 | return -ESHUTDOWN; | ||
1289 | |||
1290 | spin_lock_irqsave(&ep->r8a66597->lock, flags); | ||
1291 | |||
1292 | if (list_empty(&ep->queue)) | ||
1293 | request = 1; | ||
1294 | |||
1295 | list_add_tail(&req->queue, &ep->queue); | ||
1296 | req->req.actual = 0; | ||
1297 | req->req.status = -EINPROGRESS; | ||
1298 | |||
1299 | if (ep->desc == NULL) /* control */ | ||
1300 | start_ep0(ep, req); | ||
1301 | else { | ||
1302 | if (request && !ep->busy) | ||
1303 | start_packet(ep, req); | ||
1304 | } | ||
1305 | |||
1306 | spin_unlock_irqrestore(&ep->r8a66597->lock, flags); | ||
1307 | |||
1308 | return 0; | ||
1309 | } | ||
1310 | |||
1311 | static int r8a66597_dequeue(struct usb_ep *_ep, struct usb_request *_req) | ||
1312 | { | ||
1313 | struct r8a66597_ep *ep; | ||
1314 | struct r8a66597_request *req; | ||
1315 | unsigned long flags; | ||
1316 | |||
1317 | ep = container_of(_ep, struct r8a66597_ep, ep); | ||
1318 | req = container_of(_req, struct r8a66597_request, req); | ||
1319 | |||
1320 | spin_lock_irqsave(&ep->r8a66597->lock, flags); | ||
1321 | if (!list_empty(&ep->queue)) | ||
1322 | transfer_complete(ep, req, -ECONNRESET); | ||
1323 | spin_unlock_irqrestore(&ep->r8a66597->lock, flags); | ||
1324 | |||
1325 | return 0; | ||
1326 | } | ||
1327 | |||
1328 | static int r8a66597_set_halt(struct usb_ep *_ep, int value) | ||
1329 | { | ||
1330 | struct r8a66597_ep *ep; | ||
1331 | struct r8a66597_request *req; | ||
1332 | unsigned long flags; | ||
1333 | int ret = 0; | ||
1334 | |||
1335 | ep = container_of(_ep, struct r8a66597_ep, ep); | ||
1336 | req = get_request_from_ep(ep); | ||
1337 | |||
1338 | spin_lock_irqsave(&ep->r8a66597->lock, flags); | ||
1339 | if (!list_empty(&ep->queue)) { | ||
1340 | ret = -EAGAIN; | ||
1341 | goto out; | ||
1342 | } | ||
1343 | if (value) { | ||
1344 | ep->busy = 1; | ||
1345 | pipe_stall(ep->r8a66597, ep->pipenum); | ||
1346 | } else { | ||
1347 | ep->busy = 0; | ||
1348 | ep->wedge = 0; | ||
1349 | pipe_stop(ep->r8a66597, ep->pipenum); | ||
1350 | } | ||
1351 | |||
1352 | out: | ||
1353 | spin_unlock_irqrestore(&ep->r8a66597->lock, flags); | ||
1354 | return ret; | ||
1355 | } | ||
1356 | |||
1357 | static int r8a66597_set_wedge(struct usb_ep *_ep) | ||
1358 | { | ||
1359 | struct r8a66597_ep *ep; | ||
1360 | unsigned long flags; | ||
1361 | |||
1362 | ep = container_of(_ep, struct r8a66597_ep, ep); | ||
1363 | |||
1364 | if (!ep || !ep->desc) | ||
1365 | return -EINVAL; | ||
1366 | |||
1367 | spin_lock_irqsave(&ep->r8a66597->lock, flags); | ||
1368 | ep->wedge = 1; | ||
1369 | spin_unlock_irqrestore(&ep->r8a66597->lock, flags); | ||
1370 | |||
1371 | return usb_ep_set_halt(_ep); | ||
1372 | } | ||
1373 | |||
1374 | static void r8a66597_fifo_flush(struct usb_ep *_ep) | ||
1375 | { | ||
1376 | struct r8a66597_ep *ep; | ||
1377 | unsigned long flags; | ||
1378 | |||
1379 | ep = container_of(_ep, struct r8a66597_ep, ep); | ||
1380 | spin_lock_irqsave(&ep->r8a66597->lock, flags); | ||
1381 | if (list_empty(&ep->queue) && !ep->busy) { | ||
1382 | pipe_stop(ep->r8a66597, ep->pipenum); | ||
1383 | r8a66597_bclr(ep->r8a66597, BCLR, ep->fifoctr); | ||
1384 | } | ||
1385 | spin_unlock_irqrestore(&ep->r8a66597->lock, flags); | ||
1386 | } | ||
1387 | |||
1388 | static struct usb_ep_ops r8a66597_ep_ops = { | ||
1389 | .enable = r8a66597_enable, | ||
1390 | .disable = r8a66597_disable, | ||
1391 | |||
1392 | .alloc_request = r8a66597_alloc_request, | ||
1393 | .free_request = r8a66597_free_request, | ||
1394 | |||
1395 | .queue = r8a66597_queue, | ||
1396 | .dequeue = r8a66597_dequeue, | ||
1397 | |||
1398 | .set_halt = r8a66597_set_halt, | ||
1399 | .set_wedge = r8a66597_set_wedge, | ||
1400 | .fifo_flush = r8a66597_fifo_flush, | ||
1401 | }; | ||
1402 | |||
1403 | /*-------------------------------------------------------------------------*/ | ||
1404 | static struct r8a66597 *the_controller; | ||
1405 | |||
1406 | int usb_gadget_register_driver(struct usb_gadget_driver *driver) | ||
1407 | { | ||
1408 | struct r8a66597 *r8a66597 = the_controller; | ||
1409 | int retval; | ||
1410 | |||
1411 | if (!driver | ||
1412 | || driver->speed != USB_SPEED_HIGH | ||
1413 | || !driver->bind | ||
1414 | || !driver->setup) | ||
1415 | return -EINVAL; | ||
1416 | if (!r8a66597) | ||
1417 | return -ENODEV; | ||
1418 | if (r8a66597->driver) | ||
1419 | return -EBUSY; | ||
1420 | |||
1421 | /* hook up the driver */ | ||
1422 | driver->driver.bus = NULL; | ||
1423 | r8a66597->driver = driver; | ||
1424 | r8a66597->gadget.dev.driver = &driver->driver; | ||
1425 | |||
1426 | retval = device_add(&r8a66597->gadget.dev); | ||
1427 | if (retval) { | ||
1428 | printk(KERN_ERR "device_add error (%d)\n", retval); | ||
1429 | goto error; | ||
1430 | } | ||
1431 | |||
1432 | retval = driver->bind(&r8a66597->gadget); | ||
1433 | if (retval) { | ||
1434 | printk(KERN_ERR "bind to driver error (%d)\n", retval); | ||
1435 | device_del(&r8a66597->gadget.dev); | ||
1436 | goto error; | ||
1437 | } | ||
1438 | |||
1439 | r8a66597_bset(r8a66597, VBSE, INTENB0); | ||
1440 | if (r8a66597_read(r8a66597, INTSTS0) & VBSTS) { | ||
1441 | r8a66597_start_xclock(r8a66597); | ||
1442 | /* start vbus sampling */ | ||
1443 | r8a66597->old_vbus = r8a66597_read(r8a66597, | ||
1444 | INTSTS0) & VBSTS; | ||
1445 | r8a66597->scount = R8A66597_MAX_SAMPLING; | ||
1446 | mod_timer(&r8a66597->timer, jiffies + msecs_to_jiffies(50)); | ||
1447 | } | ||
1448 | |||
1449 | return 0; | ||
1450 | |||
1451 | error: | ||
1452 | r8a66597->driver = NULL; | ||
1453 | r8a66597->gadget.dev.driver = NULL; | ||
1454 | |||
1455 | return retval; | ||
1456 | } | ||
1457 | EXPORT_SYMBOL(usb_gadget_register_driver); | ||
1458 | |||
1459 | int usb_gadget_unregister_driver(struct usb_gadget_driver *driver) | ||
1460 | { | ||
1461 | struct r8a66597 *r8a66597 = the_controller; | ||
1462 | unsigned long flags; | ||
1463 | |||
1464 | if (driver != r8a66597->driver || !driver->unbind) | ||
1465 | return -EINVAL; | ||
1466 | |||
1467 | spin_lock_irqsave(&r8a66597->lock, flags); | ||
1468 | if (r8a66597->gadget.speed != USB_SPEED_UNKNOWN) | ||
1469 | r8a66597_usb_disconnect(r8a66597); | ||
1470 | spin_unlock_irqrestore(&r8a66597->lock, flags); | ||
1471 | |||
1472 | r8a66597_bclr(r8a66597, VBSE, INTENB0); | ||
1473 | |||
1474 | driver->unbind(&r8a66597->gadget); | ||
1475 | |||
1476 | init_controller(r8a66597); | ||
1477 | disable_controller(r8a66597); | ||
1478 | |||
1479 | device_del(&r8a66597->gadget.dev); | ||
1480 | r8a66597->driver = NULL; | ||
1481 | return 0; | ||
1482 | } | ||
1483 | EXPORT_SYMBOL(usb_gadget_unregister_driver); | ||
1484 | |||
1485 | /*-------------------------------------------------------------------------*/ | ||
1486 | static int r8a66597_get_frame(struct usb_gadget *_gadget) | ||
1487 | { | ||
1488 | struct r8a66597 *r8a66597 = gadget_to_r8a66597(_gadget); | ||
1489 | return r8a66597_read(r8a66597, FRMNUM) & 0x03FF; | ||
1490 | } | ||
1491 | |||
1492 | static struct usb_gadget_ops r8a66597_gadget_ops = { | ||
1493 | .get_frame = r8a66597_get_frame, | ||
1494 | }; | ||
1495 | |||
1496 | static int __exit r8a66597_remove(struct platform_device *pdev) | ||
1497 | { | ||
1498 | struct r8a66597 *r8a66597 = dev_get_drvdata(&pdev->dev); | ||
1499 | |||
1500 | del_timer_sync(&r8a66597->timer); | ||
1501 | iounmap((void *)r8a66597->reg); | ||
1502 | free_irq(platform_get_irq(pdev, 0), r8a66597); | ||
1503 | r8a66597_free_request(&r8a66597->ep[0].ep, r8a66597->ep0_req); | ||
1504 | #ifdef CONFIG_HAVE_CLK | ||
1505 | if (r8a66597->pdata->on_chip) { | ||
1506 | clk_disable(r8a66597->clk); | ||
1507 | clk_put(r8a66597->clk); | ||
1508 | } | ||
1509 | #endif | ||
1510 | kfree(r8a66597); | ||
1511 | return 0; | ||
1512 | } | ||
1513 | |||
1514 | static void nop_completion(struct usb_ep *ep, struct usb_request *r) | ||
1515 | { | ||
1516 | } | ||
1517 | |||
1518 | static int __init r8a66597_probe(struct platform_device *pdev) | ||
1519 | { | ||
1520 | #ifdef CONFIG_HAVE_CLK | ||
1521 | char clk_name[8]; | ||
1522 | #endif | ||
1523 | struct resource *res, *ires; | ||
1524 | int irq; | ||
1525 | void __iomem *reg = NULL; | ||
1526 | struct r8a66597 *r8a66597 = NULL; | ||
1527 | int ret = 0; | ||
1528 | int i; | ||
1529 | unsigned long irq_trigger; | ||
1530 | |||
1531 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); | ||
1532 | if (!res) { | ||
1533 | ret = -ENODEV; | ||
1534 | printk(KERN_ERR "platform_get_resource error.\n"); | ||
1535 | goto clean_up; | ||
1536 | } | ||
1537 | |||
1538 | ires = platform_get_resource(pdev, IORESOURCE_IRQ, 0); | ||
1539 | irq = ires->start; | ||
1540 | irq_trigger = ires->flags & IRQF_TRIGGER_MASK; | ||
1541 | |||
1542 | if (irq < 0) { | ||
1543 | ret = -ENODEV; | ||
1544 | printk(KERN_ERR "platform_get_irq error.\n"); | ||
1545 | goto clean_up; | ||
1546 | } | ||
1547 | |||
1548 | reg = ioremap(res->start, resource_size(res)); | ||
1549 | if (reg == NULL) { | ||
1550 | ret = -ENOMEM; | ||
1551 | printk(KERN_ERR "ioremap error.\n"); | ||
1552 | goto clean_up; | ||
1553 | } | ||
1554 | |||
1555 | /* initialize ucd */ | ||
1556 | r8a66597 = kzalloc(sizeof(struct r8a66597), GFP_KERNEL); | ||
1557 | if (r8a66597 == NULL) { | ||
1558 | printk(KERN_ERR "kzalloc error\n"); | ||
1559 | goto clean_up; | ||
1560 | } | ||
1561 | |||
1562 | spin_lock_init(&r8a66597->lock); | ||
1563 | dev_set_drvdata(&pdev->dev, r8a66597); | ||
1564 | r8a66597->pdata = pdev->dev.platform_data; | ||
1565 | r8a66597->irq_sense_low = irq_trigger == IRQF_TRIGGER_LOW; | ||
1566 | |||
1567 | r8a66597->gadget.ops = &r8a66597_gadget_ops; | ||
1568 | device_initialize(&r8a66597->gadget.dev); | ||
1569 | dev_set_name(&r8a66597->gadget.dev, "gadget"); | ||
1570 | r8a66597->gadget.is_dualspeed = 1; | ||
1571 | r8a66597->gadget.dev.parent = &pdev->dev; | ||
1572 | r8a66597->gadget.dev.dma_mask = pdev->dev.dma_mask; | ||
1573 | r8a66597->gadget.dev.release = pdev->dev.release; | ||
1574 | r8a66597->gadget.name = udc_name; | ||
1575 | |||
1576 | init_timer(&r8a66597->timer); | ||
1577 | r8a66597->timer.function = r8a66597_timer; | ||
1578 | r8a66597->timer.data = (unsigned long)r8a66597; | ||
1579 | r8a66597->reg = (unsigned long)reg; | ||
1580 | |||
1581 | #ifdef CONFIG_HAVE_CLK | ||
1582 | if (r8a66597->pdata->on_chip) { | ||
1583 | snprintf(clk_name, sizeof(clk_name), "usb%d", pdev->id); | ||
1584 | r8a66597->clk = clk_get(&pdev->dev, clk_name); | ||
1585 | if (IS_ERR(r8a66597->clk)) { | ||
1586 | dev_err(&pdev->dev, "cannot get clock \"%s\"\n", | ||
1587 | clk_name); | ||
1588 | ret = PTR_ERR(r8a66597->clk); | ||
1589 | goto clean_up; | ||
1590 | } | ||
1591 | clk_enable(r8a66597->clk); | ||
1592 | } | ||
1593 | #endif | ||
1594 | |||
1595 | disable_controller(r8a66597); /* make sure controller is disabled */ | ||
1596 | |||
1597 | ret = request_irq(irq, r8a66597_irq, IRQF_DISABLED | IRQF_SHARED, | ||
1598 | udc_name, r8a66597); | ||
1599 | if (ret < 0) { | ||
1600 | printk(KERN_ERR "request_irq error (%d)\n", ret); | ||
1601 | goto clean_up2; | ||
1602 | } | ||
1603 | |||
1604 | INIT_LIST_HEAD(&r8a66597->gadget.ep_list); | ||
1605 | r8a66597->gadget.ep0 = &r8a66597->ep[0].ep; | ||
1606 | INIT_LIST_HEAD(&r8a66597->gadget.ep0->ep_list); | ||
1607 | for (i = 0; i < R8A66597_MAX_NUM_PIPE; i++) { | ||
1608 | struct r8a66597_ep *ep = &r8a66597->ep[i]; | ||
1609 | |||
1610 | if (i != 0) { | ||
1611 | INIT_LIST_HEAD(&r8a66597->ep[i].ep.ep_list); | ||
1612 | list_add_tail(&r8a66597->ep[i].ep.ep_list, | ||
1613 | &r8a66597->gadget.ep_list); | ||
1614 | } | ||
1615 | ep->r8a66597 = r8a66597; | ||
1616 | INIT_LIST_HEAD(&ep->queue); | ||
1617 | ep->ep.name = r8a66597_ep_name[i]; | ||
1618 | ep->ep.ops = &r8a66597_ep_ops; | ||
1619 | ep->ep.maxpacket = 512; | ||
1620 | } | ||
1621 | r8a66597->ep[0].ep.maxpacket = 64; | ||
1622 | r8a66597->ep[0].pipenum = 0; | ||
1623 | r8a66597->ep[0].fifoaddr = CFIFO; | ||
1624 | r8a66597->ep[0].fifosel = CFIFOSEL; | ||
1625 | r8a66597->ep[0].fifoctr = CFIFOCTR; | ||
1626 | r8a66597->ep[0].fifotrn = 0; | ||
1627 | r8a66597->ep[0].pipectr = get_pipectr_addr(0); | ||
1628 | r8a66597->pipenum2ep[0] = &r8a66597->ep[0]; | ||
1629 | r8a66597->epaddr2ep[0] = &r8a66597->ep[0]; | ||
1630 | |||
1631 | the_controller = r8a66597; | ||
1632 | |||
1633 | r8a66597->ep0_req = r8a66597_alloc_request(&r8a66597->ep[0].ep, | ||
1634 | GFP_KERNEL); | ||
1635 | if (r8a66597->ep0_req == NULL) | ||
1636 | goto clean_up3; | ||
1637 | r8a66597->ep0_req->complete = nop_completion; | ||
1638 | |||
1639 | init_controller(r8a66597); | ||
1640 | |||
1641 | dev_info(&pdev->dev, "version %s\n", DRIVER_VERSION); | ||
1642 | return 0; | ||
1643 | |||
1644 | clean_up3: | ||
1645 | free_irq(irq, r8a66597); | ||
1646 | clean_up2: | ||
1647 | #ifdef CONFIG_HAVE_CLK | ||
1648 | if (r8a66597->pdata->on_chip) { | ||
1649 | clk_disable(r8a66597->clk); | ||
1650 | clk_put(r8a66597->clk); | ||
1651 | } | ||
1652 | #endif | ||
1653 | clean_up: | ||
1654 | if (r8a66597) { | ||
1655 | if (r8a66597->ep0_req) | ||
1656 | r8a66597_free_request(&r8a66597->ep[0].ep, | ||
1657 | r8a66597->ep0_req); | ||
1658 | kfree(r8a66597); | ||
1659 | } | ||
1660 | if (reg) | ||
1661 | iounmap(reg); | ||
1662 | |||
1663 | return ret; | ||
1664 | } | ||
1665 | |||
1666 | /*-------------------------------------------------------------------------*/ | ||
1667 | static struct platform_driver r8a66597_driver = { | ||
1668 | .remove = __exit_p(r8a66597_remove), | ||
1669 | .driver = { | ||
1670 | .name = (char *) udc_name, | ||
1671 | }, | ||
1672 | }; | ||
1673 | |||
1674 | static int __init r8a66597_udc_init(void) | ||
1675 | { | ||
1676 | return platform_driver_probe(&r8a66597_driver, r8a66597_probe); | ||
1677 | } | ||
1678 | module_init(r8a66597_udc_init); | ||
1679 | |||
1680 | static void __exit r8a66597_udc_cleanup(void) | ||
1681 | { | ||
1682 | platform_driver_unregister(&r8a66597_driver); | ||
1683 | } | ||
1684 | module_exit(r8a66597_udc_cleanup); | ||
1685 | |||
1686 | MODULE_DESCRIPTION("R8A66597 USB gadget driver"); | ||
1687 | MODULE_LICENSE("GPL"); | ||
1688 | MODULE_AUTHOR("Yoshihiro Shimoda"); | ||
1689 | |||
diff --git a/drivers/usb/gadget/r8a66597-udc.h b/drivers/usb/gadget/r8a66597-udc.h new file mode 100644 index 000000000000..03087e7b9190 --- /dev/null +++ b/drivers/usb/gadget/r8a66597-udc.h | |||
@@ -0,0 +1,256 @@ | |||
1 | /* | ||
2 | * R8A66597 UDC | ||
3 | * | ||
4 | * Copyright (C) 2007-2009 Renesas Solutions Corp. | ||
5 | * | ||
6 | * Author : Yoshihiro Shimoda <shimoda.yoshihiro@renesas.com> | ||
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; version 2 of the License. | ||
11 | * | ||
12 | * This program is distributed in the hope that it will be useful, | ||
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
15 | * GNU General Public License for more details. | ||
16 | * | ||
17 | * You should have received a copy of the GNU General Public License | ||
18 | * along with this program; if not, write to the Free Software | ||
19 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
20 | * | ||
21 | */ | ||
22 | |||
23 | #ifndef __R8A66597_H__ | ||
24 | #define __R8A66597_H__ | ||
25 | |||
26 | #ifdef CONFIG_HAVE_CLK | ||
27 | #include <linux/clk.h> | ||
28 | #endif | ||
29 | |||
30 | #include <linux/usb/r8a66597.h> | ||
31 | |||
32 | #define R8A66597_MAX_SAMPLING 10 | ||
33 | |||
34 | #define R8A66597_MAX_NUM_PIPE 8 | ||
35 | #define R8A66597_MAX_NUM_BULK 3 | ||
36 | #define R8A66597_MAX_NUM_ISOC 2 | ||
37 | #define R8A66597_MAX_NUM_INT 2 | ||
38 | |||
39 | #define R8A66597_BASE_PIPENUM_BULK 3 | ||
40 | #define R8A66597_BASE_PIPENUM_ISOC 1 | ||
41 | #define R8A66597_BASE_PIPENUM_INT 6 | ||
42 | |||
43 | #define R8A66597_BASE_BUFNUM 6 | ||
44 | #define R8A66597_MAX_BUFNUM 0x4F | ||
45 | |||
46 | #define is_bulk_pipe(pipenum) \ | ||
47 | ((pipenum >= R8A66597_BASE_PIPENUM_BULK) && \ | ||
48 | (pipenum < (R8A66597_BASE_PIPENUM_BULK + R8A66597_MAX_NUM_BULK))) | ||
49 | #define is_interrupt_pipe(pipenum) \ | ||
50 | ((pipenum >= R8A66597_BASE_PIPENUM_INT) && \ | ||
51 | (pipenum < (R8A66597_BASE_PIPENUM_INT + R8A66597_MAX_NUM_INT))) | ||
52 | #define is_isoc_pipe(pipenum) \ | ||
53 | ((pipenum >= R8A66597_BASE_PIPENUM_ISOC) && \ | ||
54 | (pipenum < (R8A66597_BASE_PIPENUM_ISOC + R8A66597_MAX_NUM_ISOC))) | ||
55 | |||
56 | struct r8a66597_pipe_info { | ||
57 | u16 pipe; | ||
58 | u16 epnum; | ||
59 | u16 maxpacket; | ||
60 | u16 type; | ||
61 | u16 interval; | ||
62 | u16 dir_in; | ||
63 | }; | ||
64 | |||
65 | struct r8a66597_request { | ||
66 | struct usb_request req; | ||
67 | struct list_head queue; | ||
68 | }; | ||
69 | |||
70 | struct r8a66597_ep { | ||
71 | struct usb_ep ep; | ||
72 | struct r8a66597 *r8a66597; | ||
73 | |||
74 | struct list_head queue; | ||
75 | unsigned busy:1; | ||
76 | unsigned wedge:1; | ||
77 | unsigned internal_ccpl:1; /* use only control */ | ||
78 | |||
79 | /* this member can able to after r8a66597_enable */ | ||
80 | unsigned use_dma:1; | ||
81 | u16 pipenum; | ||
82 | u16 type; | ||
83 | const struct usb_endpoint_descriptor *desc; | ||
84 | /* register address */ | ||
85 | unsigned char fifoaddr; | ||
86 | unsigned char fifosel; | ||
87 | unsigned char fifoctr; | ||
88 | unsigned char fifotrn; | ||
89 | unsigned char pipectr; | ||
90 | }; | ||
91 | |||
92 | struct r8a66597 { | ||
93 | spinlock_t lock; | ||
94 | unsigned long reg; | ||
95 | |||
96 | #ifdef CONFIG_HAVE_CLK | ||
97 | struct clk *clk; | ||
98 | #endif | ||
99 | struct r8a66597_platdata *pdata; | ||
100 | |||
101 | struct usb_gadget gadget; | ||
102 | struct usb_gadget_driver *driver; | ||
103 | |||
104 | struct r8a66597_ep ep[R8A66597_MAX_NUM_PIPE]; | ||
105 | struct r8a66597_ep *pipenum2ep[R8A66597_MAX_NUM_PIPE]; | ||
106 | struct r8a66597_ep *epaddr2ep[16]; | ||
107 | |||
108 | struct timer_list timer; | ||
109 | struct usb_request *ep0_req; /* for internal request */ | ||
110 | u16 ep0_data; /* for internal request */ | ||
111 | u16 old_vbus; | ||
112 | u16 scount; | ||
113 | u16 old_dvsq; | ||
114 | |||
115 | /* pipe config */ | ||
116 | unsigned char bulk; | ||
117 | unsigned char interrupt; | ||
118 | unsigned char isochronous; | ||
119 | unsigned char num_dma; | ||
120 | |||
121 | unsigned irq_sense_low:1; | ||
122 | }; | ||
123 | |||
124 | #define gadget_to_r8a66597(_gadget) \ | ||
125 | container_of(_gadget, struct r8a66597, gadget) | ||
126 | #define r8a66597_to_gadget(r8a66597) (&r8a66597->gadget) | ||
127 | |||
128 | static inline u16 r8a66597_read(struct r8a66597 *r8a66597, unsigned long offset) | ||
129 | { | ||
130 | return inw(r8a66597->reg + offset); | ||
131 | } | ||
132 | |||
133 | static inline void r8a66597_read_fifo(struct r8a66597 *r8a66597, | ||
134 | unsigned long offset, u16 *buf, | ||
135 | int len) | ||
136 | { | ||
137 | if (r8a66597->pdata->on_chip) { | ||
138 | unsigned long fifoaddr = r8a66597->reg + offset; | ||
139 | unsigned long count; | ||
140 | union { | ||
141 | unsigned long dword; | ||
142 | unsigned char byte[4]; | ||
143 | } data; | ||
144 | unsigned char *pb; | ||
145 | int i; | ||
146 | |||
147 | count = len / 4; | ||
148 | insl(fifoaddr, buf, count); | ||
149 | |||
150 | if (len & 0x00000003) { | ||
151 | data.dword = inl(fifoaddr); | ||
152 | pb = (unsigned char *)buf + count * 4; | ||
153 | for (i = 0; i < (len & 0x00000003); i++) | ||
154 | pb[i] = data.byte[i]; | ||
155 | } | ||
156 | } else { | ||
157 | len = (len + 1) / 2; | ||
158 | insw(r8a66597->reg + offset, buf, len); | ||
159 | } | ||
160 | } | ||
161 | |||
162 | static inline void r8a66597_write(struct r8a66597 *r8a66597, u16 val, | ||
163 | unsigned long offset) | ||
164 | { | ||
165 | outw(val, r8a66597->reg + offset); | ||
166 | } | ||
167 | |||
168 | static inline void r8a66597_write_fifo(struct r8a66597 *r8a66597, | ||
169 | unsigned long offset, u16 *buf, | ||
170 | int len) | ||
171 | { | ||
172 | unsigned long fifoaddr = r8a66597->reg + offset; | ||
173 | |||
174 | if (r8a66597->pdata->on_chip) { | ||
175 | unsigned long count; | ||
176 | unsigned char *pb; | ||
177 | int i; | ||
178 | |||
179 | count = len / 4; | ||
180 | outsl(fifoaddr, buf, count); | ||
181 | |||
182 | if (len & 0x00000003) { | ||
183 | pb = (unsigned char *)buf + count * 4; | ||
184 | for (i = 0; i < (len & 0x00000003); i++) { | ||
185 | if (r8a66597_read(r8a66597, CFIFOSEL) & BIGEND) | ||
186 | outb(pb[i], fifoaddr + i); | ||
187 | else | ||
188 | outb(pb[i], fifoaddr + 3 - i); | ||
189 | } | ||
190 | } | ||
191 | } else { | ||
192 | int odd = len & 0x0001; | ||
193 | |||
194 | len = len / 2; | ||
195 | outsw(fifoaddr, buf, len); | ||
196 | if (unlikely(odd)) { | ||
197 | buf = &buf[len]; | ||
198 | outb((unsigned char)*buf, fifoaddr); | ||
199 | } | ||
200 | } | ||
201 | } | ||
202 | |||
203 | static inline void r8a66597_mdfy(struct r8a66597 *r8a66597, | ||
204 | u16 val, u16 pat, unsigned long offset) | ||
205 | { | ||
206 | u16 tmp; | ||
207 | tmp = r8a66597_read(r8a66597, offset); | ||
208 | tmp = tmp & (~pat); | ||
209 | tmp = tmp | val; | ||
210 | r8a66597_write(r8a66597, tmp, offset); | ||
211 | } | ||
212 | |||
213 | static inline u16 get_xtal_from_pdata(struct r8a66597_platdata *pdata) | ||
214 | { | ||
215 | u16 clock = 0; | ||
216 | |||
217 | switch (pdata->xtal) { | ||
218 | case R8A66597_PLATDATA_XTAL_12MHZ: | ||
219 | clock = XTAL12; | ||
220 | break; | ||
221 | case R8A66597_PLATDATA_XTAL_24MHZ: | ||
222 | clock = XTAL24; | ||
223 | break; | ||
224 | case R8A66597_PLATDATA_XTAL_48MHZ: | ||
225 | clock = XTAL48; | ||
226 | break; | ||
227 | default: | ||
228 | printk(KERN_ERR "r8a66597: platdata clock is wrong.\n"); | ||
229 | break; | ||
230 | } | ||
231 | |||
232 | return clock; | ||
233 | } | ||
234 | |||
235 | #define r8a66597_bclr(r8a66597, val, offset) \ | ||
236 | r8a66597_mdfy(r8a66597, 0, val, offset) | ||
237 | #define r8a66597_bset(r8a66597, val, offset) \ | ||
238 | r8a66597_mdfy(r8a66597, val, 0, offset) | ||
239 | |||
240 | #define get_pipectr_addr(pipenum) (PIPE1CTR + (pipenum - 1) * 2) | ||
241 | |||
242 | #define enable_irq_ready(r8a66597, pipenum) \ | ||
243 | enable_pipe_irq(r8a66597, pipenum, BRDYENB) | ||
244 | #define disable_irq_ready(r8a66597, pipenum) \ | ||
245 | disable_pipe_irq(r8a66597, pipenum, BRDYENB) | ||
246 | #define enable_irq_empty(r8a66597, pipenum) \ | ||
247 | enable_pipe_irq(r8a66597, pipenum, BEMPENB) | ||
248 | #define disable_irq_empty(r8a66597, pipenum) \ | ||
249 | disable_pipe_irq(r8a66597, pipenum, BEMPENB) | ||
250 | #define enable_irq_nrdy(r8a66597, pipenum) \ | ||
251 | enable_pipe_irq(r8a66597, pipenum, NRDYENB) | ||
252 | #define disable_irq_nrdy(r8a66597, pipenum) \ | ||
253 | disable_pipe_irq(r8a66597, pipenum, NRDYENB) | ||
254 | |||
255 | #endif /* __R8A66597_H__ */ | ||
256 | |||
diff --git a/drivers/usb/gadget/rndis.c b/drivers/usb/gadget/rndis.c index ca41b0b5afb3..48267bc0b2e0 100644 --- a/drivers/usb/gadget/rndis.c +++ b/drivers/usb/gadget/rndis.c | |||
@@ -1022,22 +1022,29 @@ static rndis_resp_t *rndis_add_response (int configNr, u32 length) | |||
1022 | return r; | 1022 | return r; |
1023 | } | 1023 | } |
1024 | 1024 | ||
1025 | int rndis_rm_hdr(struct sk_buff *skb) | 1025 | int rndis_rm_hdr(struct gether *port, |
1026 | struct sk_buff *skb, | ||
1027 | struct sk_buff_head *list) | ||
1026 | { | 1028 | { |
1027 | /* tmp points to a struct rndis_packet_msg_type */ | 1029 | /* tmp points to a struct rndis_packet_msg_type */ |
1028 | __le32 *tmp = (void *) skb->data; | 1030 | __le32 *tmp = (void *) skb->data; |
1029 | 1031 | ||
1030 | /* MessageType, MessageLength */ | 1032 | /* MessageType, MessageLength */ |
1031 | if (cpu_to_le32(REMOTE_NDIS_PACKET_MSG) | 1033 | if (cpu_to_le32(REMOTE_NDIS_PACKET_MSG) |
1032 | != get_unaligned(tmp++)) | 1034 | != get_unaligned(tmp++)) { |
1035 | dev_kfree_skb_any(skb); | ||
1033 | return -EINVAL; | 1036 | return -EINVAL; |
1037 | } | ||
1034 | tmp++; | 1038 | tmp++; |
1035 | 1039 | ||
1036 | /* DataOffset, DataLength */ | 1040 | /* DataOffset, DataLength */ |
1037 | if (!skb_pull(skb, get_unaligned_le32(tmp++) + 8)) | 1041 | if (!skb_pull(skb, get_unaligned_le32(tmp++) + 8)) { |
1042 | dev_kfree_skb_any(skb); | ||
1038 | return -EOVERFLOW; | 1043 | return -EOVERFLOW; |
1044 | } | ||
1039 | skb_trim(skb, get_unaligned_le32(tmp++)); | 1045 | skb_trim(skb, get_unaligned_le32(tmp++)); |
1040 | 1046 | ||
1047 | skb_queue_tail(list, skb); | ||
1041 | return 0; | 1048 | return 0; |
1042 | } | 1049 | } |
1043 | 1050 | ||
diff --git a/drivers/usb/gadget/rndis.h b/drivers/usb/gadget/rndis.h index aac61dfe0f03..c236aaa9dcd1 100644 --- a/drivers/usb/gadget/rndis.h +++ b/drivers/usb/gadget/rndis.h | |||
@@ -251,7 +251,8 @@ int rndis_set_param_vendor (u8 configNr, u32 vendorID, | |||
251 | const char *vendorDescr); | 251 | const char *vendorDescr); |
252 | int rndis_set_param_medium (u8 configNr, u32 medium, u32 speed); | 252 | int rndis_set_param_medium (u8 configNr, u32 medium, u32 speed); |
253 | void rndis_add_hdr (struct sk_buff *skb); | 253 | void rndis_add_hdr (struct sk_buff *skb); |
254 | int rndis_rm_hdr (struct sk_buff *skb); | 254 | int rndis_rm_hdr(struct gether *port, struct sk_buff *skb, |
255 | struct sk_buff_head *list); | ||
255 | u8 *rndis_get_next_response (int configNr, u32 *length); | 256 | u8 *rndis_get_next_response (int configNr, u32 *length); |
256 | void rndis_free_response (int configNr, u8 *buf); | 257 | void rndis_free_response (int configNr, u8 *buf); |
257 | 258 | ||
diff --git a/drivers/usb/gadget/s3c-hsotg.c b/drivers/usb/gadget/s3c-hsotg.c index 50c71aae2cc2..4b5dbd0127f5 100644 --- a/drivers/usb/gadget/s3c-hsotg.c +++ b/drivers/usb/gadget/s3c-hsotg.c | |||
@@ -2392,7 +2392,7 @@ static int s3c_hsotg_corereset(struct s3c_hsotg *hsotg) | |||
2392 | grstctl = readl(hsotg->regs + S3C_GRSTCTL); | 2392 | grstctl = readl(hsotg->regs + S3C_GRSTCTL); |
2393 | } while (!(grstctl & S3C_GRSTCTL_CSftRst) && timeout-- > 0); | 2393 | } while (!(grstctl & S3C_GRSTCTL_CSftRst) && timeout-- > 0); |
2394 | 2394 | ||
2395 | if (!grstctl & S3C_GRSTCTL_CSftRst) { | 2395 | if (!(grstctl & S3C_GRSTCTL_CSftRst)) { |
2396 | dev_err(hsotg->dev, "Failed to get CSftRst asserted\n"); | 2396 | dev_err(hsotg->dev, "Failed to get CSftRst asserted\n"); |
2397 | return -EINVAL; | 2397 | return -EINVAL; |
2398 | } | 2398 | } |
@@ -2514,8 +2514,8 @@ int usb_gadget_register_driver(struct usb_gadget_driver *driver) | |||
2514 | * DMA mode we may need this. */ | 2514 | * DMA mode we may need this. */ |
2515 | writel(S3C_DOEPMSK_SetupMsk | S3C_DOEPMSK_AHBErrMsk | | 2515 | writel(S3C_DOEPMSK_SetupMsk | S3C_DOEPMSK_AHBErrMsk | |
2516 | S3C_DOEPMSK_EPDisbldMsk | | 2516 | S3C_DOEPMSK_EPDisbldMsk | |
2517 | using_dma(hsotg) ? (S3C_DIEPMSK_XferComplMsk | | 2517 | (using_dma(hsotg) ? (S3C_DIEPMSK_XferComplMsk | |
2518 | S3C_DIEPMSK_TimeOUTMsk) : 0, | 2518 | S3C_DIEPMSK_TimeOUTMsk) : 0), |
2519 | hsotg->regs + S3C_DOEPMSK); | 2519 | hsotg->regs + S3C_DOEPMSK); |
2520 | 2520 | ||
2521 | writel(0, hsotg->regs + S3C_DAINTMSK); | 2521 | writel(0, hsotg->regs + S3C_DAINTMSK); |
diff --git a/drivers/usb/gadget/s3c2410_udc.c b/drivers/usb/gadget/s3c2410_udc.c index a9b452fe6221..d5f4c1d45c97 100644 --- a/drivers/usb/gadget/s3c2410_udc.c +++ b/drivers/usb/gadget/s3c2410_udc.c | |||
@@ -1703,8 +1703,7 @@ int usb_gadget_unregister_driver(struct usb_gadget_driver *driver) | |||
1703 | dprintk(DEBUG_NORMAL,"usb_gadget_register_driver() '%s'\n", | 1703 | dprintk(DEBUG_NORMAL,"usb_gadget_register_driver() '%s'\n", |
1704 | driver->driver.name); | 1704 | driver->driver.name); |
1705 | 1705 | ||
1706 | if (driver->disconnect) | 1706 | driver->unbind(&udc->gadget); |
1707 | driver->disconnect(&udc->gadget); | ||
1708 | 1707 | ||
1709 | device_del(&udc->gadget.dev); | 1708 | device_del(&udc->gadget.dev); |
1710 | udc->driver = NULL; | 1709 | udc->driver = NULL; |
diff --git a/drivers/usb/gadget/u_audio.c b/drivers/usb/gadget/u_audio.c index 0f3d22fc030e..8252595d619d 100644 --- a/drivers/usb/gadget/u_audio.c +++ b/drivers/usb/gadget/u_audio.c | |||
@@ -10,7 +10,6 @@ | |||
10 | */ | 10 | */ |
11 | 11 | ||
12 | #include <linux/kernel.h> | 12 | #include <linux/kernel.h> |
13 | #include <linux/utsname.h> | ||
14 | #include <linux/device.h> | 13 | #include <linux/device.h> |
15 | #include <linux/delay.h> | 14 | #include <linux/delay.h> |
16 | #include <linux/ctype.h> | 15 | #include <linux/ctype.h> |
@@ -253,11 +252,13 @@ static int gaudio_open_snd_dev(struct gaudio *card) | |||
253 | snd->filp = filp_open(fn_cap, O_RDONLY, 0); | 252 | snd->filp = filp_open(fn_cap, O_RDONLY, 0); |
254 | if (IS_ERR(snd->filp)) { | 253 | if (IS_ERR(snd->filp)) { |
255 | ERROR(card, "No such PCM capture device: %s\n", fn_cap); | 254 | ERROR(card, "No such PCM capture device: %s\n", fn_cap); |
256 | snd->filp = NULL; | 255 | snd->substream = NULL; |
256 | snd->card = NULL; | ||
257 | } else { | ||
258 | pcm_file = snd->filp->private_data; | ||
259 | snd->substream = pcm_file->substream; | ||
260 | snd->card = card; | ||
257 | } | 261 | } |
258 | pcm_file = snd->filp->private_data; | ||
259 | snd->substream = pcm_file->substream; | ||
260 | snd->card = card; | ||
261 | 262 | ||
262 | return 0; | 263 | return 0; |
263 | } | 264 | } |
diff --git a/drivers/usb/gadget/u_ether.c b/drivers/usb/gadget/u_ether.c index c66521953917..2fc02bd95848 100644 --- a/drivers/usb/gadget/u_ether.c +++ b/drivers/usb/gadget/u_ether.c | |||
@@ -23,7 +23,6 @@ | |||
23 | /* #define VERBOSE_DEBUG */ | 23 | /* #define VERBOSE_DEBUG */ |
24 | 24 | ||
25 | #include <linux/kernel.h> | 25 | #include <linux/kernel.h> |
26 | #include <linux/utsname.h> | ||
27 | #include <linux/device.h> | 26 | #include <linux/device.h> |
28 | #include <linux/ctype.h> | 27 | #include <linux/ctype.h> |
29 | #include <linux/etherdevice.h> | 28 | #include <linux/etherdevice.h> |
@@ -37,8 +36,9 @@ | |||
37 | * one (!) network link through the USB gadget stack, normally "usb0". | 36 | * one (!) network link through the USB gadget stack, normally "usb0". |
38 | * | 37 | * |
39 | * The control and data models are handled by the function driver which | 38 | * The control and data models are handled by the function driver which |
40 | * connects to this code; such as CDC Ethernet, "CDC Subset", or RNDIS. | 39 | * connects to this code; such as CDC Ethernet (ECM or EEM), |
41 | * That includes all descriptor and endpoint management. | 40 | * "CDC Subset", or RNDIS. That includes all descriptor and endpoint |
41 | * management. | ||
42 | * | 42 | * |
43 | * Link level addressing is handled by this component using module | 43 | * Link level addressing is handled by this component using module |
44 | * parameters; if no such parameters are provided, random link level | 44 | * parameters; if no such parameters are provided, random link level |
@@ -68,9 +68,13 @@ struct eth_dev { | |||
68 | struct list_head tx_reqs, rx_reqs; | 68 | struct list_head tx_reqs, rx_reqs; |
69 | atomic_t tx_qlen; | 69 | atomic_t tx_qlen; |
70 | 70 | ||
71 | struct sk_buff_head rx_frames; | ||
72 | |||
71 | unsigned header_len; | 73 | unsigned header_len; |
72 | struct sk_buff *(*wrap)(struct sk_buff *skb); | 74 | struct sk_buff *(*wrap)(struct gether *, struct sk_buff *skb); |
73 | int (*unwrap)(struct sk_buff *skb); | 75 | int (*unwrap)(struct gether *, |
76 | struct sk_buff *skb, | ||
77 | struct sk_buff_head *list); | ||
74 | 78 | ||
75 | struct work_struct work; | 79 | struct work_struct work; |
76 | 80 | ||
@@ -269,7 +273,7 @@ enomem: | |||
269 | 273 | ||
270 | static void rx_complete(struct usb_ep *ep, struct usb_request *req) | 274 | static void rx_complete(struct usb_ep *ep, struct usb_request *req) |
271 | { | 275 | { |
272 | struct sk_buff *skb = req->context; | 276 | struct sk_buff *skb = req->context, *skb2; |
273 | struct eth_dev *dev = ep->driver_data; | 277 | struct eth_dev *dev = ep->driver_data; |
274 | int status = req->status; | 278 | int status = req->status; |
275 | 279 | ||
@@ -278,26 +282,47 @@ static void rx_complete(struct usb_ep *ep, struct usb_request *req) | |||
278 | /* normal completion */ | 282 | /* normal completion */ |
279 | case 0: | 283 | case 0: |
280 | skb_put(skb, req->actual); | 284 | skb_put(skb, req->actual); |
281 | if (dev->unwrap) | ||
282 | status = dev->unwrap(skb); | ||
283 | if (status < 0 | ||
284 | || ETH_HLEN > skb->len | ||
285 | || skb->len > ETH_FRAME_LEN) { | ||
286 | dev->net->stats.rx_errors++; | ||
287 | dev->net->stats.rx_length_errors++; | ||
288 | DBG(dev, "rx length %d\n", skb->len); | ||
289 | break; | ||
290 | } | ||
291 | 285 | ||
292 | skb->protocol = eth_type_trans(skb, dev->net); | 286 | if (dev->unwrap) { |
293 | dev->net->stats.rx_packets++; | 287 | unsigned long flags; |
294 | dev->net->stats.rx_bytes += skb->len; | ||
295 | 288 | ||
296 | /* no buffer copies needed, unless hardware can't | 289 | spin_lock_irqsave(&dev->lock, flags); |
297 | * use skb buffers. | 290 | if (dev->port_usb) { |
298 | */ | 291 | status = dev->unwrap(dev->port_usb, |
299 | status = netif_rx(skb); | 292 | skb, |
293 | &dev->rx_frames); | ||
294 | } else { | ||
295 | dev_kfree_skb_any(skb); | ||
296 | status = -ENOTCONN; | ||
297 | } | ||
298 | spin_unlock_irqrestore(&dev->lock, flags); | ||
299 | } else { | ||
300 | skb_queue_tail(&dev->rx_frames, skb); | ||
301 | } | ||
300 | skb = NULL; | 302 | skb = NULL; |
303 | |||
304 | skb2 = skb_dequeue(&dev->rx_frames); | ||
305 | while (skb2) { | ||
306 | if (status < 0 | ||
307 | || ETH_HLEN > skb2->len | ||
308 | || skb2->len > ETH_FRAME_LEN) { | ||
309 | dev->net->stats.rx_errors++; | ||
310 | dev->net->stats.rx_length_errors++; | ||
311 | DBG(dev, "rx length %d\n", skb2->len); | ||
312 | dev_kfree_skb_any(skb2); | ||
313 | goto next_frame; | ||
314 | } | ||
315 | skb2->protocol = eth_type_trans(skb2, dev->net); | ||
316 | dev->net->stats.rx_packets++; | ||
317 | dev->net->stats.rx_bytes += skb2->len; | ||
318 | |||
319 | /* no buffer copies needed, unless hardware can't | ||
320 | * use skb buffers. | ||
321 | */ | ||
322 | status = netif_rx(skb2); | ||
323 | next_frame: | ||
324 | skb2 = skb_dequeue(&dev->rx_frames); | ||
325 | } | ||
301 | break; | 326 | break; |
302 | 327 | ||
303 | /* software-driven interface shutdown */ | 328 | /* software-driven interface shutdown */ |
@@ -537,14 +562,15 @@ static netdev_tx_t eth_start_xmit(struct sk_buff *skb, | |||
537 | * or there's not enough space for extra headers we need | 562 | * or there's not enough space for extra headers we need |
538 | */ | 563 | */ |
539 | if (dev->wrap) { | 564 | if (dev->wrap) { |
540 | struct sk_buff *skb_new; | 565 | unsigned long flags; |
541 | 566 | ||
542 | skb_new = dev->wrap(skb); | 567 | spin_lock_irqsave(&dev->lock, flags); |
543 | if (!skb_new) | 568 | if (dev->port_usb) |
569 | skb = dev->wrap(dev->port_usb, skb); | ||
570 | spin_unlock_irqrestore(&dev->lock, flags); | ||
571 | if (!skb) | ||
544 | goto drop; | 572 | goto drop; |
545 | 573 | ||
546 | dev_kfree_skb_any(skb); | ||
547 | skb = skb_new; | ||
548 | length = skb->len; | 574 | length = skb->len; |
549 | } | 575 | } |
550 | req->buf = skb->data; | 576 | req->buf = skb->data; |
@@ -578,9 +604,9 @@ static netdev_tx_t eth_start_xmit(struct sk_buff *skb, | |||
578 | } | 604 | } |
579 | 605 | ||
580 | if (retval) { | 606 | if (retval) { |
607 | dev_kfree_skb_any(skb); | ||
581 | drop: | 608 | drop: |
582 | dev->net->stats.tx_dropped++; | 609 | dev->net->stats.tx_dropped++; |
583 | dev_kfree_skb_any(skb); | ||
584 | spin_lock_irqsave(&dev->req_lock, flags); | 610 | spin_lock_irqsave(&dev->req_lock, flags); |
585 | if (list_empty(&dev->tx_reqs)) | 611 | if (list_empty(&dev->tx_reqs)) |
586 | netif_start_queue(net); | 612 | netif_start_queue(net); |
@@ -753,6 +779,8 @@ int __init gether_setup(struct usb_gadget *g, u8 ethaddr[ETH_ALEN]) | |||
753 | INIT_LIST_HEAD(&dev->tx_reqs); | 779 | INIT_LIST_HEAD(&dev->tx_reqs); |
754 | INIT_LIST_HEAD(&dev->rx_reqs); | 780 | INIT_LIST_HEAD(&dev->rx_reqs); |
755 | 781 | ||
782 | skb_queue_head_init(&dev->rx_frames); | ||
783 | |||
756 | /* network device setup */ | 784 | /* network device setup */ |
757 | dev->net = net; | 785 | dev->net = net; |
758 | strcpy(net->name, "usb%d"); | 786 | strcpy(net->name, "usb%d"); |
diff --git a/drivers/usb/gadget/u_ether.h b/drivers/usb/gadget/u_ether.h index 0d1f7ae3b071..91b39ffdf6ea 100644 --- a/drivers/usb/gadget/u_ether.h +++ b/drivers/usb/gadget/u_ether.h | |||
@@ -60,12 +60,13 @@ struct gether { | |||
60 | 60 | ||
61 | u16 cdc_filter; | 61 | u16 cdc_filter; |
62 | 62 | ||
63 | /* hooks for added framing, as needed for RNDIS and EEM. | 63 | /* hooks for added framing, as needed for RNDIS and EEM. */ |
64 | * we currently don't support multiple frames per SKB. | ||
65 | */ | ||
66 | u32 header_len; | 64 | u32 header_len; |
67 | struct sk_buff *(*wrap)(struct sk_buff *skb); | 65 | struct sk_buff *(*wrap)(struct gether *port, |
68 | int (*unwrap)(struct sk_buff *skb); | 66 | struct sk_buff *skb); |
67 | int (*unwrap)(struct gether *port, | ||
68 | struct sk_buff *skb, | ||
69 | struct sk_buff_head *list); | ||
69 | 70 | ||
70 | /* called on network open/close */ | 71 | /* called on network open/close */ |
71 | void (*open)(struct gether *); | 72 | void (*open)(struct gether *); |
@@ -109,6 +110,7 @@ static inline bool can_support_ecm(struct usb_gadget *gadget) | |||
109 | /* each configuration may bind one instance of an ethernet link */ | 110 | /* each configuration may bind one instance of an ethernet link */ |
110 | int geth_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN]); | 111 | int geth_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN]); |
111 | int ecm_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN]); | 112 | int ecm_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN]); |
113 | int eem_bind_config(struct usb_configuration *c); | ||
112 | 114 | ||
113 | #ifdef CONFIG_USB_ETH_RNDIS | 115 | #ifdef CONFIG_USB_ETH_RNDIS |
114 | 116 | ||
diff --git a/drivers/usb/gadget/u_serial.c b/drivers/usb/gadget/u_serial.c index fc6e709f45b1..adf8260c3a6a 100644 --- a/drivers/usb/gadget/u_serial.c +++ b/drivers/usb/gadget/u_serial.c | |||
@@ -1114,7 +1114,6 @@ int __init gserial_setup(struct usb_gadget *g, unsigned count) | |||
1114 | /* export the driver ... */ | 1114 | /* export the driver ... */ |
1115 | status = tty_register_driver(gs_tty_driver); | 1115 | status = tty_register_driver(gs_tty_driver); |
1116 | if (status) { | 1116 | if (status) { |
1117 | put_tty_driver(gs_tty_driver); | ||
1118 | pr_err("%s: cannot register, err %d\n", | 1117 | pr_err("%s: cannot register, err %d\n", |
1119 | __func__, status); | 1118 | __func__, status); |
1120 | goto fail; | 1119 | goto fail; |
diff --git a/drivers/usb/host/Kconfig b/drivers/usb/host/Kconfig index 1a920c70b5a1..9b43b226817f 100644 --- a/drivers/usb/host/Kconfig +++ b/drivers/usb/host/Kconfig | |||
@@ -113,6 +113,12 @@ config USB_EHCI_HCD_PPC_OF | |||
113 | Enables support for the USB controller present on the PowerPC | 113 | Enables support for the USB controller present on the PowerPC |
114 | OpenFirmware platform bus. | 114 | OpenFirmware platform bus. |
115 | 115 | ||
116 | config USB_W90X900_EHCI | ||
117 | bool "W90X900(W90P910) EHCI support" | ||
118 | depends on USB_EHCI_HCD && ARCH_W90X900 | ||
119 | ---help--- | ||
120 | Enables support for the W90X900 USB controller | ||
121 | |||
116 | config USB_OXU210HP_HCD | 122 | config USB_OXU210HP_HCD |
117 | tristate "OXU210HP HCD support" | 123 | tristate "OXU210HP HCD support" |
118 | depends on USB | 124 | depends on USB |
@@ -153,6 +159,18 @@ config USB_ISP1760_HCD | |||
153 | To compile this driver as a module, choose M here: the | 159 | To compile this driver as a module, choose M here: the |
154 | module will be called isp1760. | 160 | module will be called isp1760. |
155 | 161 | ||
162 | config USB_ISP1362_HCD | ||
163 | tristate "ISP1362 HCD support" | ||
164 | depends on USB | ||
165 | default N | ||
166 | ---help--- | ||
167 | Supports the Philips ISP1362 chip as a host controller | ||
168 | |||
169 | This driver does not support isochronous transfers. | ||
170 | |||
171 | To compile this driver as a module, choose M here: the | ||
172 | module will be called isp1362-hcd. | ||
173 | |||
156 | config USB_OHCI_HCD | 174 | config USB_OHCI_HCD |
157 | tristate "OHCI HCD support" | 175 | tristate "OHCI HCD support" |
158 | depends on USB && USB_ARCH_HAS_OHCI | 176 | depends on USB && USB_ARCH_HAS_OHCI |
@@ -336,13 +354,6 @@ config USB_R8A66597_HCD | |||
336 | To compile this driver as a module, choose M here: the | 354 | To compile this driver as a module, choose M here: the |
337 | module will be called r8a66597-hcd. | 355 | module will be called r8a66597-hcd. |
338 | 356 | ||
339 | config SUPERH_ON_CHIP_R8A66597 | ||
340 | boolean "Enable SuperH on-chip R8A66597 USB" | ||
341 | depends on USB_R8A66597_HCD && (CPU_SUBTYPE_SH7366 || CPU_SUBTYPE_SH7723 || CPU_SUBTYPE_SH7724) | ||
342 | help | ||
343 | This driver enables support for the on-chip R8A66597 in the | ||
344 | SH7366, SH7723 and SH7724 processors. | ||
345 | |||
346 | config USB_WHCI_HCD | 357 | config USB_WHCI_HCD |
347 | tristate "Wireless USB Host Controller Interface (WHCI) driver (EXPERIMENTAL)" | 358 | tristate "Wireless USB Host Controller Interface (WHCI) driver (EXPERIMENTAL)" |
348 | depends on EXPERIMENTAL | 359 | depends on EXPERIMENTAL |
diff --git a/drivers/usb/host/Makefile b/drivers/usb/host/Makefile index 289d748bb414..f58b2494c44a 100644 --- a/drivers/usb/host/Makefile +++ b/drivers/usb/host/Makefile | |||
@@ -21,6 +21,7 @@ obj-$(CONFIG_PCI) += pci-quirks.o | |||
21 | obj-$(CONFIG_USB_EHCI_HCD) += ehci-hcd.o | 21 | obj-$(CONFIG_USB_EHCI_HCD) += ehci-hcd.o |
22 | obj-$(CONFIG_USB_OXU210HP_HCD) += oxu210hp-hcd.o | 22 | obj-$(CONFIG_USB_OXU210HP_HCD) += oxu210hp-hcd.o |
23 | obj-$(CONFIG_USB_ISP116X_HCD) += isp116x-hcd.o | 23 | obj-$(CONFIG_USB_ISP116X_HCD) += isp116x-hcd.o |
24 | obj-$(CONFIG_USB_ISP1362_HCD) += isp1362-hcd.o | ||
24 | obj-$(CONFIG_USB_OHCI_HCD) += ohci-hcd.o | 25 | obj-$(CONFIG_USB_OHCI_HCD) += ohci-hcd.o |
25 | obj-$(CONFIG_USB_UHCI_HCD) += uhci-hcd.o | 26 | obj-$(CONFIG_USB_UHCI_HCD) += uhci-hcd.o |
26 | obj-$(CONFIG_USB_FHCI_HCD) += fhci.o | 27 | obj-$(CONFIG_USB_FHCI_HCD) += fhci.o |
diff --git a/drivers/usb/host/ehci-atmel.c b/drivers/usb/host/ehci-atmel.c new file mode 100644 index 000000000000..87c1b7c34c0e --- /dev/null +++ b/drivers/usb/host/ehci-atmel.c | |||
@@ -0,0 +1,230 @@ | |||
1 | /* | ||
2 | * Driver for EHCI UHP on Atmel chips | ||
3 | * | ||
4 | * Copyright (C) 2009 Atmel Corporation, | ||
5 | * Nicolas Ferre <nicolas.ferre@atmel.com> | ||
6 | * | ||
7 | * Based on various ehci-*.c drivers | ||
8 | * | ||
9 | * This file is subject to the terms and conditions of the GNU General Public | ||
10 | * License. See the file COPYING in the main directory of this archive for | ||
11 | * more details. | ||
12 | */ | ||
13 | |||
14 | #include <linux/clk.h> | ||
15 | #include <linux/platform_device.h> | ||
16 | |||
17 | /* interface and function clocks */ | ||
18 | static struct clk *iclk, *fclk; | ||
19 | static int clocked; | ||
20 | |||
21 | /*-------------------------------------------------------------------------*/ | ||
22 | |||
23 | static void atmel_start_clock(void) | ||
24 | { | ||
25 | clk_enable(iclk); | ||
26 | clk_enable(fclk); | ||
27 | clocked = 1; | ||
28 | } | ||
29 | |||
30 | static void atmel_stop_clock(void) | ||
31 | { | ||
32 | clk_disable(fclk); | ||
33 | clk_disable(iclk); | ||
34 | clocked = 0; | ||
35 | } | ||
36 | |||
37 | static void atmel_start_ehci(struct platform_device *pdev) | ||
38 | { | ||
39 | dev_dbg(&pdev->dev, "start\n"); | ||
40 | atmel_start_clock(); | ||
41 | } | ||
42 | |||
43 | static void atmel_stop_ehci(struct platform_device *pdev) | ||
44 | { | ||
45 | dev_dbg(&pdev->dev, "stop\n"); | ||
46 | atmel_stop_clock(); | ||
47 | } | ||
48 | |||
49 | /*-------------------------------------------------------------------------*/ | ||
50 | |||
51 | static int ehci_atmel_setup(struct usb_hcd *hcd) | ||
52 | { | ||
53 | struct ehci_hcd *ehci = hcd_to_ehci(hcd); | ||
54 | int retval = 0; | ||
55 | |||
56 | /* registers start at offset 0x0 */ | ||
57 | ehci->caps = hcd->regs; | ||
58 | ehci->regs = hcd->regs + | ||
59 | HC_LENGTH(ehci_readl(ehci, &ehci->caps->hc_capbase)); | ||
60 | dbg_hcs_params(ehci, "reset"); | ||
61 | dbg_hcc_params(ehci, "reset"); | ||
62 | |||
63 | /* cache this readonly data; minimize chip reads */ | ||
64 | ehci->hcs_params = ehci_readl(ehci, &ehci->caps->hcs_params); | ||
65 | |||
66 | retval = ehci_halt(ehci); | ||
67 | if (retval) | ||
68 | return retval; | ||
69 | |||
70 | /* data structure init */ | ||
71 | retval = ehci_init(hcd); | ||
72 | if (retval) | ||
73 | return retval; | ||
74 | |||
75 | ehci->sbrn = 0x20; | ||
76 | |||
77 | ehci_reset(ehci); | ||
78 | ehci_port_power(ehci, 0); | ||
79 | |||
80 | return retval; | ||
81 | } | ||
82 | |||
83 | static const struct hc_driver ehci_atmel_hc_driver = { | ||
84 | .description = hcd_name, | ||
85 | .product_desc = "Atmel EHCI UHP HS", | ||
86 | .hcd_priv_size = sizeof(struct ehci_hcd), | ||
87 | |||
88 | /* generic hardware linkage */ | ||
89 | .irq = ehci_irq, | ||
90 | .flags = HCD_MEMORY | HCD_USB2, | ||
91 | |||
92 | /* basic lifecycle operations */ | ||
93 | .reset = ehci_atmel_setup, | ||
94 | .start = ehci_run, | ||
95 | .stop = ehci_stop, | ||
96 | .shutdown = ehci_shutdown, | ||
97 | |||
98 | /* managing i/o requests and associated device resources */ | ||
99 | .urb_enqueue = ehci_urb_enqueue, | ||
100 | .urb_dequeue = ehci_urb_dequeue, | ||
101 | .endpoint_disable = ehci_endpoint_disable, | ||
102 | |||
103 | /* scheduling support */ | ||
104 | .get_frame_number = ehci_get_frame, | ||
105 | |||
106 | /* root hub support */ | ||
107 | .hub_status_data = ehci_hub_status_data, | ||
108 | .hub_control = ehci_hub_control, | ||
109 | .bus_suspend = ehci_bus_suspend, | ||
110 | .bus_resume = ehci_bus_resume, | ||
111 | .relinquish_port = ehci_relinquish_port, | ||
112 | .port_handed_over = ehci_port_handed_over, | ||
113 | }; | ||
114 | |||
115 | static int __init ehci_atmel_drv_probe(struct platform_device *pdev) | ||
116 | { | ||
117 | struct usb_hcd *hcd; | ||
118 | const struct hc_driver *driver = &ehci_atmel_hc_driver; | ||
119 | struct resource *res; | ||
120 | int irq; | ||
121 | int retval; | ||
122 | |||
123 | if (usb_disabled()) | ||
124 | return -ENODEV; | ||
125 | |||
126 | pr_debug("Initializing Atmel-SoC USB Host Controller\n"); | ||
127 | |||
128 | irq = platform_get_irq(pdev, 0); | ||
129 | if (irq <= 0) { | ||
130 | dev_err(&pdev->dev, | ||
131 | "Found HC with no IRQ. Check %s setup!\n", | ||
132 | dev_name(&pdev->dev)); | ||
133 | retval = -ENODEV; | ||
134 | goto fail_create_hcd; | ||
135 | } | ||
136 | |||
137 | hcd = usb_create_hcd(driver, &pdev->dev, dev_name(&pdev->dev)); | ||
138 | if (!hcd) { | ||
139 | retval = -ENOMEM; | ||
140 | goto fail_create_hcd; | ||
141 | } | ||
142 | |||
143 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); | ||
144 | if (!res) { | ||
145 | dev_err(&pdev->dev, | ||
146 | "Found HC with no register addr. Check %s setup!\n", | ||
147 | dev_name(&pdev->dev)); | ||
148 | retval = -ENODEV; | ||
149 | goto fail_request_resource; | ||
150 | } | ||
151 | hcd->rsrc_start = res->start; | ||
152 | hcd->rsrc_len = res->end - res->start + 1; | ||
153 | |||
154 | if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, | ||
155 | driver->description)) { | ||
156 | dev_dbg(&pdev->dev, "controller already in use\n"); | ||
157 | retval = -EBUSY; | ||
158 | goto fail_request_resource; | ||
159 | } | ||
160 | |||
161 | hcd->regs = ioremap_nocache(hcd->rsrc_start, hcd->rsrc_len); | ||
162 | if (hcd->regs == NULL) { | ||
163 | dev_dbg(&pdev->dev, "error mapping memory\n"); | ||
164 | retval = -EFAULT; | ||
165 | goto fail_ioremap; | ||
166 | } | ||
167 | |||
168 | iclk = clk_get(&pdev->dev, "ehci_clk"); | ||
169 | if (IS_ERR(iclk)) { | ||
170 | dev_err(&pdev->dev, "Error getting interface clock\n"); | ||
171 | retval = -ENOENT; | ||
172 | goto fail_get_iclk; | ||
173 | } | ||
174 | fclk = clk_get(&pdev->dev, "uhpck"); | ||
175 | if (IS_ERR(fclk)) { | ||
176 | dev_err(&pdev->dev, "Error getting function clock\n"); | ||
177 | retval = -ENOENT; | ||
178 | goto fail_get_fclk; | ||
179 | } | ||
180 | |||
181 | atmel_start_ehci(pdev); | ||
182 | |||
183 | retval = usb_add_hcd(hcd, irq, IRQF_SHARED); | ||
184 | if (retval) | ||
185 | goto fail_add_hcd; | ||
186 | |||
187 | return retval; | ||
188 | |||
189 | fail_add_hcd: | ||
190 | atmel_stop_ehci(pdev); | ||
191 | clk_put(fclk); | ||
192 | fail_get_fclk: | ||
193 | clk_put(iclk); | ||
194 | fail_get_iclk: | ||
195 | iounmap(hcd->regs); | ||
196 | fail_ioremap: | ||
197 | release_mem_region(hcd->rsrc_start, hcd->rsrc_len); | ||
198 | fail_request_resource: | ||
199 | usb_put_hcd(hcd); | ||
200 | fail_create_hcd: | ||
201 | dev_err(&pdev->dev, "init %s fail, %d\n", | ||
202 | dev_name(&pdev->dev), retval); | ||
203 | |||
204 | return retval; | ||
205 | } | ||
206 | |||
207 | static int __exit ehci_atmel_drv_remove(struct platform_device *pdev) | ||
208 | { | ||
209 | struct usb_hcd *hcd = platform_get_drvdata(pdev); | ||
210 | |||
211 | ehci_shutdown(hcd); | ||
212 | usb_remove_hcd(hcd); | ||
213 | iounmap(hcd->regs); | ||
214 | release_mem_region(hcd->rsrc_start, hcd->rsrc_len); | ||
215 | usb_put_hcd(hcd); | ||
216 | |||
217 | atmel_stop_ehci(pdev); | ||
218 | clk_put(fclk); | ||
219 | clk_put(iclk); | ||
220 | fclk = iclk = NULL; | ||
221 | |||
222 | return 0; | ||
223 | } | ||
224 | |||
225 | static struct platform_driver ehci_atmel_driver = { | ||
226 | .probe = ehci_atmel_drv_probe, | ||
227 | .remove = __exit_p(ehci_atmel_drv_remove), | ||
228 | .shutdown = usb_hcd_platform_shutdown, | ||
229 | .driver.name = "atmel-ehci", | ||
230 | }; | ||
diff --git a/drivers/usb/host/ehci-au1xxx.c b/drivers/usb/host/ehci-au1xxx.c index 59d208d94d4e..ed77be76d6bb 100644 --- a/drivers/usb/host/ehci-au1xxx.c +++ b/drivers/usb/host/ehci-au1xxx.c | |||
@@ -199,10 +199,9 @@ static int ehci_hcd_au1xxx_drv_remove(struct platform_device *pdev) | |||
199 | } | 199 | } |
200 | 200 | ||
201 | #ifdef CONFIG_PM | 201 | #ifdef CONFIG_PM |
202 | static int ehci_hcd_au1xxx_drv_suspend(struct platform_device *pdev, | 202 | static int ehci_hcd_au1xxx_drv_suspend(struct device *dev) |
203 | pm_message_t message) | ||
204 | { | 203 | { |
205 | struct usb_hcd *hcd = platform_get_drvdata(pdev); | 204 | struct usb_hcd *hcd = dev_get_drvdata(dev); |
206 | struct ehci_hcd *ehci = hcd_to_ehci(hcd); | 205 | struct ehci_hcd *ehci = hcd_to_ehci(hcd); |
207 | unsigned long flags; | 206 | unsigned long flags; |
208 | int rc; | 207 | int rc; |
@@ -229,12 +228,6 @@ static int ehci_hcd_au1xxx_drv_suspend(struct platform_device *pdev, | |||
229 | ehci_writel(ehci, 0, &ehci->regs->intr_enable); | 228 | ehci_writel(ehci, 0, &ehci->regs->intr_enable); |
230 | (void)ehci_readl(ehci, &ehci->regs->intr_enable); | 229 | (void)ehci_readl(ehci, &ehci->regs->intr_enable); |
231 | 230 | ||
232 | /* make sure snapshot being resumed re-enumerates everything */ | ||
233 | if (message.event == PM_EVENT_PRETHAW) { | ||
234 | ehci_halt(ehci); | ||
235 | ehci_reset(ehci); | ||
236 | } | ||
237 | |||
238 | clear_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags); | 231 | clear_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags); |
239 | 232 | ||
240 | au1xxx_stop_ehc(); | 233 | au1xxx_stop_ehc(); |
@@ -248,10 +241,9 @@ bail: | |||
248 | return rc; | 241 | return rc; |
249 | } | 242 | } |
250 | 243 | ||
251 | 244 | static int ehci_hcd_au1xxx_drv_resume(struct device *dev) | |
252 | static int ehci_hcd_au1xxx_drv_resume(struct platform_device *pdev) | ||
253 | { | 245 | { |
254 | struct usb_hcd *hcd = platform_get_drvdata(pdev); | 246 | struct usb_hcd *hcd = dev_get_drvdata(dev); |
255 | struct ehci_hcd *ehci = hcd_to_ehci(hcd); | 247 | struct ehci_hcd *ehci = hcd_to_ehci(hcd); |
256 | 248 | ||
257 | au1xxx_start_ehc(); | 249 | au1xxx_start_ehc(); |
@@ -305,20 +297,25 @@ static int ehci_hcd_au1xxx_drv_resume(struct platform_device *pdev) | |||
305 | return 0; | 297 | return 0; |
306 | } | 298 | } |
307 | 299 | ||
300 | static struct dev_pm_ops au1xxx_ehci_pmops = { | ||
301 | .suspend = ehci_hcd_au1xxx_drv_suspend, | ||
302 | .resume = ehci_hcd_au1xxx_drv_resume, | ||
303 | }; | ||
304 | |||
305 | #define AU1XXX_EHCI_PMOPS &au1xxx_ehci_pmops | ||
306 | |||
308 | #else | 307 | #else |
309 | #define ehci_hcd_au1xxx_drv_suspend NULL | 308 | #define AU1XXX_EHCI_PMOPS NULL |
310 | #define ehci_hcd_au1xxx_drv_resume NULL | ||
311 | #endif | 309 | #endif |
312 | 310 | ||
313 | static struct platform_driver ehci_hcd_au1xxx_driver = { | 311 | static struct platform_driver ehci_hcd_au1xxx_driver = { |
314 | .probe = ehci_hcd_au1xxx_drv_probe, | 312 | .probe = ehci_hcd_au1xxx_drv_probe, |
315 | .remove = ehci_hcd_au1xxx_drv_remove, | 313 | .remove = ehci_hcd_au1xxx_drv_remove, |
316 | .shutdown = usb_hcd_platform_shutdown, | 314 | .shutdown = usb_hcd_platform_shutdown, |
317 | .suspend = ehci_hcd_au1xxx_drv_suspend, | ||
318 | .resume = ehci_hcd_au1xxx_drv_resume, | ||
319 | .driver = { | 315 | .driver = { |
320 | .name = "au1xxx-ehci", | 316 | .name = "au1xxx-ehci", |
321 | .owner = THIS_MODULE, | 317 | .owner = THIS_MODULE, |
318 | .pm = AU1XXX_EHCI_PMOPS, | ||
322 | } | 319 | } |
323 | }; | 320 | }; |
324 | 321 | ||
diff --git a/drivers/usb/host/ehci-dbg.c b/drivers/usb/host/ehci-dbg.c index 7f4ace73d44a..874d2000bf92 100644 --- a/drivers/usb/host/ehci-dbg.c +++ b/drivers/usb/host/ehci-dbg.c | |||
@@ -134,10 +134,11 @@ dbg_qtd (const char *label, struct ehci_hcd *ehci, struct ehci_qtd *qtd) | |||
134 | static void __maybe_unused | 134 | static void __maybe_unused |
135 | dbg_qh (const char *label, struct ehci_hcd *ehci, struct ehci_qh *qh) | 135 | dbg_qh (const char *label, struct ehci_hcd *ehci, struct ehci_qh *qh) |
136 | { | 136 | { |
137 | struct ehci_qh_hw *hw = qh->hw; | ||
138 | |||
137 | ehci_dbg (ehci, "%s qh %p n%08x info %x %x qtd %x\n", label, | 139 | ehci_dbg (ehci, "%s qh %p n%08x info %x %x qtd %x\n", label, |
138 | qh, qh->hw_next, qh->hw_info1, qh->hw_info2, | 140 | qh, hw->hw_next, hw->hw_info1, hw->hw_info2, hw->hw_current); |
139 | qh->hw_current); | 141 | dbg_qtd("overlay", ehci, (struct ehci_qtd *) &hw->hw_qtd_next); |
140 | dbg_qtd ("overlay", ehci, (struct ehci_qtd *) &qh->hw_qtd_next); | ||
141 | } | 142 | } |
142 | 143 | ||
143 | static void __maybe_unused | 144 | static void __maybe_unused |
@@ -400,31 +401,32 @@ static void qh_lines ( | |||
400 | char *next = *nextp; | 401 | char *next = *nextp; |
401 | char mark; | 402 | char mark; |
402 | __le32 list_end = EHCI_LIST_END(ehci); | 403 | __le32 list_end = EHCI_LIST_END(ehci); |
404 | struct ehci_qh_hw *hw = qh->hw; | ||
403 | 405 | ||
404 | if (qh->hw_qtd_next == list_end) /* NEC does this */ | 406 | if (hw->hw_qtd_next == list_end) /* NEC does this */ |
405 | mark = '@'; | 407 | mark = '@'; |
406 | else | 408 | else |
407 | mark = token_mark(ehci, qh->hw_token); | 409 | mark = token_mark(ehci, hw->hw_token); |
408 | if (mark == '/') { /* qh_alt_next controls qh advance? */ | 410 | if (mark == '/') { /* qh_alt_next controls qh advance? */ |
409 | if ((qh->hw_alt_next & QTD_MASK(ehci)) | 411 | if ((hw->hw_alt_next & QTD_MASK(ehci)) |
410 | == ehci->async->hw_alt_next) | 412 | == ehci->async->hw->hw_alt_next) |
411 | mark = '#'; /* blocked */ | 413 | mark = '#'; /* blocked */ |
412 | else if (qh->hw_alt_next == list_end) | 414 | else if (hw->hw_alt_next == list_end) |
413 | mark = '.'; /* use hw_qtd_next */ | 415 | mark = '.'; /* use hw_qtd_next */ |
414 | /* else alt_next points to some other qtd */ | 416 | /* else alt_next points to some other qtd */ |
415 | } | 417 | } |
416 | scratch = hc32_to_cpup(ehci, &qh->hw_info1); | 418 | scratch = hc32_to_cpup(ehci, &hw->hw_info1); |
417 | hw_curr = (mark == '*') ? hc32_to_cpup(ehci, &qh->hw_current) : 0; | 419 | hw_curr = (mark == '*') ? hc32_to_cpup(ehci, &hw->hw_current) : 0; |
418 | temp = scnprintf (next, size, | 420 | temp = scnprintf (next, size, |
419 | "qh/%p dev%d %cs ep%d %08x %08x (%08x%c %s nak%d)", | 421 | "qh/%p dev%d %cs ep%d %08x %08x (%08x%c %s nak%d)", |
420 | qh, scratch & 0x007f, | 422 | qh, scratch & 0x007f, |
421 | speed_char (scratch), | 423 | speed_char (scratch), |
422 | (scratch >> 8) & 0x000f, | 424 | (scratch >> 8) & 0x000f, |
423 | scratch, hc32_to_cpup(ehci, &qh->hw_info2), | 425 | scratch, hc32_to_cpup(ehci, &hw->hw_info2), |
424 | hc32_to_cpup(ehci, &qh->hw_token), mark, | 426 | hc32_to_cpup(ehci, &hw->hw_token), mark, |
425 | (cpu_to_hc32(ehci, QTD_TOGGLE) & qh->hw_token) | 427 | (cpu_to_hc32(ehci, QTD_TOGGLE) & hw->hw_token) |
426 | ? "data1" : "data0", | 428 | ? "data1" : "data0", |
427 | (hc32_to_cpup(ehci, &qh->hw_alt_next) >> 1) & 0x0f); | 429 | (hc32_to_cpup(ehci, &hw->hw_alt_next) >> 1) & 0x0f); |
428 | size -= temp; | 430 | size -= temp; |
429 | next += temp; | 431 | next += temp; |
430 | 432 | ||
@@ -435,10 +437,10 @@ static void qh_lines ( | |||
435 | mark = ' '; | 437 | mark = ' '; |
436 | if (hw_curr == td->qtd_dma) | 438 | if (hw_curr == td->qtd_dma) |
437 | mark = '*'; | 439 | mark = '*'; |
438 | else if (qh->hw_qtd_next == cpu_to_hc32(ehci, td->qtd_dma)) | 440 | else if (hw->hw_qtd_next == cpu_to_hc32(ehci, td->qtd_dma)) |
439 | mark = '+'; | 441 | mark = '+'; |
440 | else if (QTD_LENGTH (scratch)) { | 442 | else if (QTD_LENGTH (scratch)) { |
441 | if (td->hw_alt_next == ehci->async->hw_alt_next) | 443 | if (td->hw_alt_next == ehci->async->hw->hw_alt_next) |
442 | mark = '#'; | 444 | mark = '#'; |
443 | else if (td->hw_alt_next != list_end) | 445 | else if (td->hw_alt_next != list_end) |
444 | mark = '/'; | 446 | mark = '/'; |
@@ -550,12 +552,15 @@ static ssize_t fill_periodic_buffer(struct debug_buffer *buf) | |||
550 | next += temp; | 552 | next += temp; |
551 | 553 | ||
552 | do { | 554 | do { |
555 | struct ehci_qh_hw *hw; | ||
556 | |||
553 | switch (hc32_to_cpu(ehci, tag)) { | 557 | switch (hc32_to_cpu(ehci, tag)) { |
554 | case Q_TYPE_QH: | 558 | case Q_TYPE_QH: |
559 | hw = p.qh->hw; | ||
555 | temp = scnprintf (next, size, " qh%d-%04x/%p", | 560 | temp = scnprintf (next, size, " qh%d-%04x/%p", |
556 | p.qh->period, | 561 | p.qh->period, |
557 | hc32_to_cpup(ehci, | 562 | hc32_to_cpup(ehci, |
558 | &p.qh->hw_info2) | 563 | &hw->hw_info2) |
559 | /* uframe masks */ | 564 | /* uframe masks */ |
560 | & (QH_CMASK | QH_SMASK), | 565 | & (QH_CMASK | QH_SMASK), |
561 | p.qh); | 566 | p.qh); |
@@ -576,7 +581,7 @@ static ssize_t fill_periodic_buffer(struct debug_buffer *buf) | |||
576 | /* show more info the first time around */ | 581 | /* show more info the first time around */ |
577 | if (temp == seen_count) { | 582 | if (temp == seen_count) { |
578 | u32 scratch = hc32_to_cpup(ehci, | 583 | u32 scratch = hc32_to_cpup(ehci, |
579 | &p.qh->hw_info1); | 584 | &hw->hw_info1); |
580 | struct ehci_qtd *qtd; | 585 | struct ehci_qtd *qtd; |
581 | char *type = ""; | 586 | char *type = ""; |
582 | 587 | ||
@@ -609,7 +614,7 @@ static ssize_t fill_periodic_buffer(struct debug_buffer *buf) | |||
609 | } else | 614 | } else |
610 | temp = 0; | 615 | temp = 0; |
611 | if (p.qh) { | 616 | if (p.qh) { |
612 | tag = Q_NEXT_TYPE(ehci, p.qh->hw_next); | 617 | tag = Q_NEXT_TYPE(ehci, hw->hw_next); |
613 | p = p.qh->qh_next; | 618 | p = p.qh->qh_next; |
614 | } | 619 | } |
615 | break; | 620 | break; |
@@ -879,8 +884,7 @@ static int debug_close(struct inode *inode, struct file *file) | |||
879 | struct debug_buffer *buf = file->private_data; | 884 | struct debug_buffer *buf = file->private_data; |
880 | 885 | ||
881 | if (buf) { | 886 | if (buf) { |
882 | if (buf->output_buf) | 887 | vfree(buf->output_buf); |
883 | vfree(buf->output_buf); | ||
884 | kfree(buf); | 888 | kfree(buf); |
885 | } | 889 | } |
886 | 890 | ||
diff --git a/drivers/usb/host/ehci-hcd.c b/drivers/usb/host/ehci-hcd.c index 11c627ce6022..9835e0713943 100644 --- a/drivers/usb/host/ehci-hcd.c +++ b/drivers/usb/host/ehci-hcd.c | |||
@@ -30,7 +30,6 @@ | |||
30 | #include <linux/timer.h> | 30 | #include <linux/timer.h> |
31 | #include <linux/list.h> | 31 | #include <linux/list.h> |
32 | #include <linux/interrupt.h> | 32 | #include <linux/interrupt.h> |
33 | #include <linux/reboot.h> | ||
34 | #include <linux/usb.h> | 33 | #include <linux/usb.h> |
35 | #include <linux/moduleparam.h> | 34 | #include <linux/moduleparam.h> |
36 | #include <linux/dma-mapping.h> | 35 | #include <linux/dma-mapping.h> |
@@ -127,6 +126,8 @@ timer_action(struct ehci_hcd *ehci, enum ehci_timer_action action) | |||
127 | 126 | ||
128 | switch (action) { | 127 | switch (action) { |
129 | case TIMER_IO_WATCHDOG: | 128 | case TIMER_IO_WATCHDOG: |
129 | if (!ehci->need_io_watchdog) | ||
130 | return; | ||
130 | t = EHCI_IO_JIFFIES; | 131 | t = EHCI_IO_JIFFIES; |
131 | break; | 132 | break; |
132 | case TIMER_ASYNC_OFF: | 133 | case TIMER_ASYNC_OFF: |
@@ -239,6 +240,11 @@ static int ehci_reset (struct ehci_hcd *ehci) | |||
239 | int retval; | 240 | int retval; |
240 | u32 command = ehci_readl(ehci, &ehci->regs->command); | 241 | u32 command = ehci_readl(ehci, &ehci->regs->command); |
241 | 242 | ||
243 | /* If the EHCI debug controller is active, special care must be | ||
244 | * taken before and after a host controller reset */ | ||
245 | if (ehci->debug && !dbgp_reset_prep()) | ||
246 | ehci->debug = NULL; | ||
247 | |||
242 | command |= CMD_RESET; | 248 | command |= CMD_RESET; |
243 | dbg_cmd (ehci, "reset", command); | 249 | dbg_cmd (ehci, "reset", command); |
244 | ehci_writel(ehci, command, &ehci->regs->command); | 250 | ehci_writel(ehci, command, &ehci->regs->command); |
@@ -247,12 +253,21 @@ static int ehci_reset (struct ehci_hcd *ehci) | |||
247 | retval = handshake (ehci, &ehci->regs->command, | 253 | retval = handshake (ehci, &ehci->regs->command, |
248 | CMD_RESET, 0, 250 * 1000); | 254 | CMD_RESET, 0, 250 * 1000); |
249 | 255 | ||
256 | if (ehci->has_hostpc) { | ||
257 | ehci_writel(ehci, USBMODE_EX_HC | USBMODE_EX_VBPS, | ||
258 | (u32 __iomem *)(((u8 *)ehci->regs) + USBMODE_EX)); | ||
259 | ehci_writel(ehci, TXFIFO_DEFAULT, | ||
260 | (u32 __iomem *)(((u8 *)ehci->regs) + TXFILLTUNING)); | ||
261 | } | ||
250 | if (retval) | 262 | if (retval) |
251 | return retval; | 263 | return retval; |
252 | 264 | ||
253 | if (ehci_is_TDI(ehci)) | 265 | if (ehci_is_TDI(ehci)) |
254 | tdi_reset (ehci); | 266 | tdi_reset (ehci); |
255 | 267 | ||
268 | if (ehci->debug) | ||
269 | dbgp_external_startup(); | ||
270 | |||
256 | return retval; | 271 | return retval; |
257 | } | 272 | } |
258 | 273 | ||
@@ -505,9 +520,14 @@ static int ehci_init(struct usb_hcd *hcd) | |||
505 | u32 temp; | 520 | u32 temp; |
506 | int retval; | 521 | int retval; |
507 | u32 hcc_params; | 522 | u32 hcc_params; |
523 | struct ehci_qh_hw *hw; | ||
508 | 524 | ||
509 | spin_lock_init(&ehci->lock); | 525 | spin_lock_init(&ehci->lock); |
510 | 526 | ||
527 | /* | ||
528 | * keep io watchdog by default, those good HCDs could turn off it later | ||
529 | */ | ||
530 | ehci->need_io_watchdog = 1; | ||
511 | init_timer(&ehci->watchdog); | 531 | init_timer(&ehci->watchdog); |
512 | ehci->watchdog.function = ehci_watchdog; | 532 | ehci->watchdog.function = ehci_watchdog; |
513 | ehci->watchdog.data = (unsigned long) ehci; | 533 | ehci->watchdog.data = (unsigned long) ehci; |
@@ -544,12 +564,13 @@ static int ehci_init(struct usb_hcd *hcd) | |||
544 | * from automatically advancing to the next td after short reads. | 564 | * from automatically advancing to the next td after short reads. |
545 | */ | 565 | */ |
546 | ehci->async->qh_next.qh = NULL; | 566 | ehci->async->qh_next.qh = NULL; |
547 | ehci->async->hw_next = QH_NEXT(ehci, ehci->async->qh_dma); | 567 | hw = ehci->async->hw; |
548 | ehci->async->hw_info1 = cpu_to_hc32(ehci, QH_HEAD); | 568 | hw->hw_next = QH_NEXT(ehci, ehci->async->qh_dma); |
549 | ehci->async->hw_token = cpu_to_hc32(ehci, QTD_STS_HALT); | 569 | hw->hw_info1 = cpu_to_hc32(ehci, QH_HEAD); |
550 | ehci->async->hw_qtd_next = EHCI_LIST_END(ehci); | 570 | hw->hw_token = cpu_to_hc32(ehci, QTD_STS_HALT); |
571 | hw->hw_qtd_next = EHCI_LIST_END(ehci); | ||
551 | ehci->async->qh_state = QH_STATE_LINKED; | 572 | ehci->async->qh_state = QH_STATE_LINKED; |
552 | ehci->async->hw_alt_next = QTD_NEXT(ehci, ehci->async->dummy->qtd_dma); | 573 | hw->hw_alt_next = QTD_NEXT(ehci, ehci->async->dummy->qtd_dma); |
553 | 574 | ||
554 | /* clear interrupt enables, set irq latency */ | 575 | /* clear interrupt enables, set irq latency */ |
555 | if (log2_irq_thresh < 0 || log2_irq_thresh > 6) | 576 | if (log2_irq_thresh < 0 || log2_irq_thresh > 6) |
@@ -850,12 +871,18 @@ static void unlink_async (struct ehci_hcd *ehci, struct ehci_qh *qh) | |||
850 | if (!HC_IS_RUNNING(ehci_to_hcd(ehci)->state) && ehci->reclaim) | 871 | if (!HC_IS_RUNNING(ehci_to_hcd(ehci)->state) && ehci->reclaim) |
851 | end_unlink_async(ehci); | 872 | end_unlink_async(ehci); |
852 | 873 | ||
853 | /* if it's not linked then there's nothing to do */ | 874 | /* If the QH isn't linked then there's nothing we can do |
854 | if (qh->qh_state != QH_STATE_LINKED) | 875 | * unless we were called during a giveback, in which case |
855 | ; | 876 | * qh_completions() has to deal with it. |
877 | */ | ||
878 | if (qh->qh_state != QH_STATE_LINKED) { | ||
879 | if (qh->qh_state == QH_STATE_COMPLETING) | ||
880 | qh->needs_rescan = 1; | ||
881 | return; | ||
882 | } | ||
856 | 883 | ||
857 | /* defer till later if busy */ | 884 | /* defer till later if busy */ |
858 | else if (ehci->reclaim) { | 885 | if (ehci->reclaim) { |
859 | struct ehci_qh *last; | 886 | struct ehci_qh *last; |
860 | 887 | ||
861 | for (last = ehci->reclaim; | 888 | for (last = ehci->reclaim; |
@@ -915,8 +942,9 @@ static int ehci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status) | |||
915 | break; | 942 | break; |
916 | switch (qh->qh_state) { | 943 | switch (qh->qh_state) { |
917 | case QH_STATE_LINKED: | 944 | case QH_STATE_LINKED: |
945 | case QH_STATE_COMPLETING: | ||
918 | intr_deschedule (ehci, qh); | 946 | intr_deschedule (ehci, qh); |
919 | /* FALL THROUGH */ | 947 | break; |
920 | case QH_STATE_IDLE: | 948 | case QH_STATE_IDLE: |
921 | qh_completions (ehci, qh); | 949 | qh_completions (ehci, qh); |
922 | break; | 950 | break; |
@@ -925,23 +953,6 @@ static int ehci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status) | |||
925 | qh, qh->qh_state); | 953 | qh, qh->qh_state); |
926 | goto done; | 954 | goto done; |
927 | } | 955 | } |
928 | |||
929 | /* reschedule QH iff another request is queued */ | ||
930 | if (!list_empty (&qh->qtd_list) | ||
931 | && HC_IS_RUNNING (hcd->state)) { | ||
932 | rc = qh_schedule(ehci, qh); | ||
933 | |||
934 | /* An error here likely indicates handshake failure | ||
935 | * or no space left in the schedule. Neither fault | ||
936 | * should happen often ... | ||
937 | * | ||
938 | * FIXME kill the now-dysfunctional queued urbs | ||
939 | */ | ||
940 | if (rc != 0) | ||
941 | ehci_err(ehci, | ||
942 | "can't reschedule qh %p, err %d", | ||
943 | qh, rc); | ||
944 | } | ||
945 | break; | 956 | break; |
946 | 957 | ||
947 | case PIPE_ISOCHRONOUS: | 958 | case PIPE_ISOCHRONOUS: |
@@ -979,7 +990,7 @@ rescan: | |||
979 | /* endpoints can be iso streams. for now, we don't | 990 | /* endpoints can be iso streams. for now, we don't |
980 | * accelerate iso completions ... so spin a while. | 991 | * accelerate iso completions ... so spin a while. |
981 | */ | 992 | */ |
982 | if (qh->hw_info1 == 0) { | 993 | if (qh->hw->hw_info1 == 0) { |
983 | ehci_vdbg (ehci, "iso delay\n"); | 994 | ehci_vdbg (ehci, "iso delay\n"); |
984 | goto idle_timeout; | 995 | goto idle_timeout; |
985 | } | 996 | } |
@@ -988,6 +999,7 @@ rescan: | |||
988 | qh->qh_state = QH_STATE_IDLE; | 999 | qh->qh_state = QH_STATE_IDLE; |
989 | switch (qh->qh_state) { | 1000 | switch (qh->qh_state) { |
990 | case QH_STATE_LINKED: | 1001 | case QH_STATE_LINKED: |
1002 | case QH_STATE_COMPLETING: | ||
991 | for (tmp = ehci->async->qh_next.qh; | 1003 | for (tmp = ehci->async->qh_next.qh; |
992 | tmp && tmp != qh; | 1004 | tmp && tmp != qh; |
993 | tmp = tmp->qh_next.qh) | 1005 | tmp = tmp->qh_next.qh) |
@@ -1052,18 +1064,17 @@ ehci_endpoint_reset(struct usb_hcd *hcd, struct usb_host_endpoint *ep) | |||
1052 | usb_settoggle(qh->dev, epnum, is_out, 0); | 1064 | usb_settoggle(qh->dev, epnum, is_out, 0); |
1053 | if (!list_empty(&qh->qtd_list)) { | 1065 | if (!list_empty(&qh->qtd_list)) { |
1054 | WARN_ONCE(1, "clear_halt for a busy endpoint\n"); | 1066 | WARN_ONCE(1, "clear_halt for a busy endpoint\n"); |
1055 | } else if (qh->qh_state == QH_STATE_LINKED) { | 1067 | } else if (qh->qh_state == QH_STATE_LINKED || |
1068 | qh->qh_state == QH_STATE_COMPLETING) { | ||
1056 | 1069 | ||
1057 | /* The toggle value in the QH can't be updated | 1070 | /* The toggle value in the QH can't be updated |
1058 | * while the QH is active. Unlink it now; | 1071 | * while the QH is active. Unlink it now; |
1059 | * re-linking will call qh_refresh(). | 1072 | * re-linking will call qh_refresh(). |
1060 | */ | 1073 | */ |
1061 | if (eptype == USB_ENDPOINT_XFER_BULK) { | 1074 | if (eptype == USB_ENDPOINT_XFER_BULK) |
1062 | unlink_async(ehci, qh); | 1075 | unlink_async(ehci, qh); |
1063 | } else { | 1076 | else |
1064 | intr_deschedule(ehci, qh); | 1077 | intr_deschedule(ehci, qh); |
1065 | (void) qh_schedule(ehci, qh); | ||
1066 | } | ||
1067 | } | 1078 | } |
1068 | } | 1079 | } |
1069 | spin_unlock_irqrestore(&ehci->lock, flags); | 1080 | spin_unlock_irqrestore(&ehci->lock, flags); |
@@ -1117,6 +1128,16 @@ MODULE_LICENSE ("GPL"); | |||
1117 | #define PLATFORM_DRIVER ixp4xx_ehci_driver | 1128 | #define PLATFORM_DRIVER ixp4xx_ehci_driver |
1118 | #endif | 1129 | #endif |
1119 | 1130 | ||
1131 | #ifdef CONFIG_USB_W90X900_EHCI | ||
1132 | #include "ehci-w90x900.c" | ||
1133 | #define PLATFORM_DRIVER ehci_hcd_w90x900_driver | ||
1134 | #endif | ||
1135 | |||
1136 | #ifdef CONFIG_ARCH_AT91 | ||
1137 | #include "ehci-atmel.c" | ||
1138 | #define PLATFORM_DRIVER ehci_atmel_driver | ||
1139 | #endif | ||
1140 | |||
1120 | #if !defined(PCI_DRIVER) && !defined(PLATFORM_DRIVER) && \ | 1141 | #if !defined(PCI_DRIVER) && !defined(PLATFORM_DRIVER) && \ |
1121 | !defined(PS3_SYSTEM_BUS_DRIVER) && !defined(OF_PLATFORM_DRIVER) | 1142 | !defined(PS3_SYSTEM_BUS_DRIVER) && !defined(OF_PLATFORM_DRIVER) |
1122 | #error "missing bus glue for ehci-hcd" | 1143 | #error "missing bus glue for ehci-hcd" |
diff --git a/drivers/usb/host/ehci-hub.c b/drivers/usb/host/ehci-hub.c index f46ad27c9a90..1b6f1c0e5cee 100644 --- a/drivers/usb/host/ehci-hub.c +++ b/drivers/usb/host/ehci-hub.c | |||
@@ -111,6 +111,7 @@ static int ehci_bus_suspend (struct usb_hcd *hcd) | |||
111 | struct ehci_hcd *ehci = hcd_to_ehci (hcd); | 111 | struct ehci_hcd *ehci = hcd_to_ehci (hcd); |
112 | int port; | 112 | int port; |
113 | int mask; | 113 | int mask; |
114 | u32 __iomem *hostpc_reg = NULL; | ||
114 | 115 | ||
115 | ehci_dbg(ehci, "suspend root hub\n"); | 116 | ehci_dbg(ehci, "suspend root hub\n"); |
116 | 117 | ||
@@ -142,6 +143,9 @@ static int ehci_bus_suspend (struct usb_hcd *hcd) | |||
142 | u32 t1 = ehci_readl(ehci, reg) & ~PORT_RWC_BITS; | 143 | u32 t1 = ehci_readl(ehci, reg) & ~PORT_RWC_BITS; |
143 | u32 t2 = t1; | 144 | u32 t2 = t1; |
144 | 145 | ||
146 | if (ehci->has_hostpc) | ||
147 | hostpc_reg = (u32 __iomem *)((u8 *)ehci->regs | ||
148 | + HOSTPC0 + 4 * (port & 0xff)); | ||
145 | /* keep track of which ports we suspend */ | 149 | /* keep track of which ports we suspend */ |
146 | if (t1 & PORT_OWNER) | 150 | if (t1 & PORT_OWNER) |
147 | set_bit(port, &ehci->owned_ports); | 151 | set_bit(port, &ehci->owned_ports); |
@@ -151,15 +155,37 @@ static int ehci_bus_suspend (struct usb_hcd *hcd) | |||
151 | } | 155 | } |
152 | 156 | ||
153 | /* enable remote wakeup on all ports */ | 157 | /* enable remote wakeup on all ports */ |
154 | if (hcd->self.root_hub->do_remote_wakeup) | 158 | if (hcd->self.root_hub->do_remote_wakeup) { |
155 | t2 |= PORT_WAKE_BITS; | 159 | /* only enable appropriate wake bits, otherwise the |
156 | else | 160 | * hardware can not go phy low power mode. If a race |
161 | * condition happens here(connection change during bits | ||
162 | * set), the port change detection will finally fix it. | ||
163 | */ | ||
164 | if (t1 & PORT_CONNECT) { | ||
165 | t2 |= PORT_WKOC_E | PORT_WKDISC_E; | ||
166 | t2 &= ~PORT_WKCONN_E; | ||
167 | } else { | ||
168 | t2 |= PORT_WKOC_E | PORT_WKCONN_E; | ||
169 | t2 &= ~PORT_WKDISC_E; | ||
170 | } | ||
171 | } else | ||
157 | t2 &= ~PORT_WAKE_BITS; | 172 | t2 &= ~PORT_WAKE_BITS; |
158 | 173 | ||
159 | if (t1 != t2) { | 174 | if (t1 != t2) { |
160 | ehci_vdbg (ehci, "port %d, %08x -> %08x\n", | 175 | ehci_vdbg (ehci, "port %d, %08x -> %08x\n", |
161 | port + 1, t1, t2); | 176 | port + 1, t1, t2); |
162 | ehci_writel(ehci, t2, reg); | 177 | ehci_writel(ehci, t2, reg); |
178 | if (hostpc_reg) { | ||
179 | u32 t3; | ||
180 | |||
181 | msleep(5);/* 5ms for HCD enter low pwr mode */ | ||
182 | t3 = ehci_readl(ehci, hostpc_reg); | ||
183 | ehci_writel(ehci, t3 | HOSTPC_PHCD, hostpc_reg); | ||
184 | t3 = ehci_readl(ehci, hostpc_reg); | ||
185 | ehci_dbg(ehci, "Port%d phy low pwr mode %s\n", | ||
186 | port, (t3 & HOSTPC_PHCD) ? | ||
187 | "succeeded" : "failed"); | ||
188 | } | ||
163 | } | 189 | } |
164 | } | 190 | } |
165 | 191 | ||
@@ -183,6 +209,11 @@ static int ehci_bus_suspend (struct usb_hcd *hcd) | |||
183 | 209 | ||
184 | ehci->next_statechange = jiffies + msecs_to_jiffies(10); | 210 | ehci->next_statechange = jiffies + msecs_to_jiffies(10); |
185 | spin_unlock_irq (&ehci->lock); | 211 | spin_unlock_irq (&ehci->lock); |
212 | |||
213 | /* ehci_work() may have re-enabled the watchdog timer, which we do not | ||
214 | * want, and so we must delete any pending watchdog timer events. | ||
215 | */ | ||
216 | del_timer_sync(&ehci->watchdog); | ||
186 | return 0; | 217 | return 0; |
187 | } | 218 | } |
188 | 219 | ||
@@ -204,6 +235,13 @@ static int ehci_bus_resume (struct usb_hcd *hcd) | |||
204 | return -ESHUTDOWN; | 235 | return -ESHUTDOWN; |
205 | } | 236 | } |
206 | 237 | ||
238 | if (unlikely(ehci->debug)) { | ||
239 | if (ehci->debug && !dbgp_reset_prep()) | ||
240 | ehci->debug = NULL; | ||
241 | else | ||
242 | dbgp_external_startup(); | ||
243 | } | ||
244 | |||
207 | /* Ideally and we've got a real resume here, and no port's power | 245 | /* Ideally and we've got a real resume here, and no port's power |
208 | * was lost. (For PCI, that means Vaux was maintained.) But we | 246 | * was lost. (For PCI, that means Vaux was maintained.) But we |
209 | * could instead be restoring a swsusp snapshot -- so that BIOS was | 247 | * could instead be restoring a swsusp snapshot -- so that BIOS was |
@@ -563,7 +601,8 @@ static int ehci_hub_control ( | |||
563 | int ports = HCS_N_PORTS (ehci->hcs_params); | 601 | int ports = HCS_N_PORTS (ehci->hcs_params); |
564 | u32 __iomem *status_reg = &ehci->regs->port_status[ | 602 | u32 __iomem *status_reg = &ehci->regs->port_status[ |
565 | (wIndex & 0xff) - 1]; | 603 | (wIndex & 0xff) - 1]; |
566 | u32 temp, status; | 604 | u32 __iomem *hostpc_reg = NULL; |
605 | u32 temp, temp1, status; | ||
567 | unsigned long flags; | 606 | unsigned long flags; |
568 | int retval = 0; | 607 | int retval = 0; |
569 | unsigned selector; | 608 | unsigned selector; |
@@ -575,6 +614,9 @@ static int ehci_hub_control ( | |||
575 | * power, "this is the one", etc. EHCI spec supports this. | 614 | * power, "this is the one", etc. EHCI spec supports this. |
576 | */ | 615 | */ |
577 | 616 | ||
617 | if (ehci->has_hostpc) | ||
618 | hostpc_reg = (u32 __iomem *)((u8 *)ehci->regs | ||
619 | + HOSTPC0 + 4 * ((wIndex & 0xff) - 1)); | ||
578 | spin_lock_irqsave (&ehci->lock, flags); | 620 | spin_lock_irqsave (&ehci->lock, flags); |
579 | switch (typeReq) { | 621 | switch (typeReq) { |
580 | case ClearHubFeature: | 622 | case ClearHubFeature: |
@@ -773,7 +815,11 @@ static int ehci_hub_control ( | |||
773 | if (temp & PORT_CONNECT) { | 815 | if (temp & PORT_CONNECT) { |
774 | status |= 1 << USB_PORT_FEAT_CONNECTION; | 816 | status |= 1 << USB_PORT_FEAT_CONNECTION; |
775 | // status may be from integrated TT | 817 | // status may be from integrated TT |
776 | status |= ehci_port_speed(ehci, temp); | 818 | if (ehci->has_hostpc) { |
819 | temp1 = ehci_readl(ehci, hostpc_reg); | ||
820 | status |= ehci_port_speed(ehci, temp1); | ||
821 | } else | ||
822 | status |= ehci_port_speed(ehci, temp); | ||
777 | } | 823 | } |
778 | if (temp & PORT_PE) | 824 | if (temp & PORT_PE) |
779 | status |= 1 << USB_PORT_FEAT_ENABLE; | 825 | status |= 1 << USB_PORT_FEAT_ENABLE; |
@@ -816,6 +862,15 @@ static int ehci_hub_control ( | |||
816 | case SetPortFeature: | 862 | case SetPortFeature: |
817 | selector = wIndex >> 8; | 863 | selector = wIndex >> 8; |
818 | wIndex &= 0xff; | 864 | wIndex &= 0xff; |
865 | if (unlikely(ehci->debug)) { | ||
866 | /* If the debug port is active any port | ||
867 | * feature requests should get denied */ | ||
868 | if (wIndex == HCS_DEBUG_PORT(ehci->hcs_params) && | ||
869 | (readl(&ehci->debug->control) & DBGP_ENABLED)) { | ||
870 | retval = -ENODEV; | ||
871 | goto error_exit; | ||
872 | } | ||
873 | } | ||
819 | if (!wIndex || wIndex > ports) | 874 | if (!wIndex || wIndex > ports) |
820 | goto error; | 875 | goto error; |
821 | wIndex--; | 876 | wIndex--; |
@@ -832,6 +887,24 @@ static int ehci_hub_control ( | |||
832 | || (temp & PORT_RESET) != 0) | 887 | || (temp & PORT_RESET) != 0) |
833 | goto error; | 888 | goto error; |
834 | ehci_writel(ehci, temp | PORT_SUSPEND, status_reg); | 889 | ehci_writel(ehci, temp | PORT_SUSPEND, status_reg); |
890 | /* After above check the port must be connected. | ||
891 | * Set appropriate bit thus could put phy into low power | ||
892 | * mode if we have hostpc feature | ||
893 | */ | ||
894 | if (hostpc_reg) { | ||
895 | temp &= ~PORT_WKCONN_E; | ||
896 | temp |= (PORT_WKDISC_E | PORT_WKOC_E); | ||
897 | ehci_writel(ehci, temp | PORT_SUSPEND, | ||
898 | status_reg); | ||
899 | msleep(5);/* 5ms for HCD enter low pwr mode */ | ||
900 | temp1 = ehci_readl(ehci, hostpc_reg); | ||
901 | ehci_writel(ehci, temp1 | HOSTPC_PHCD, | ||
902 | hostpc_reg); | ||
903 | temp1 = ehci_readl(ehci, hostpc_reg); | ||
904 | ehci_dbg(ehci, "Port%d phy low pwr mode %s\n", | ||
905 | wIndex, (temp1 & HOSTPC_PHCD) ? | ||
906 | "succeeded" : "failed"); | ||
907 | } | ||
835 | set_bit(wIndex, &ehci->suspended_ports); | 908 | set_bit(wIndex, &ehci->suspended_ports); |
836 | break; | 909 | break; |
837 | case USB_PORT_FEAT_POWER: | 910 | case USB_PORT_FEAT_POWER: |
@@ -894,6 +967,7 @@ error: | |||
894 | /* "stall" on error */ | 967 | /* "stall" on error */ |
895 | retval = -EPIPE; | 968 | retval = -EPIPE; |
896 | } | 969 | } |
970 | error_exit: | ||
897 | spin_unlock_irqrestore (&ehci->lock, flags); | 971 | spin_unlock_irqrestore (&ehci->lock, flags); |
898 | return retval; | 972 | return retval; |
899 | } | 973 | } |
diff --git a/drivers/usb/host/ehci-mem.c b/drivers/usb/host/ehci-mem.c index 10d52919abbb..aeda96e0af67 100644 --- a/drivers/usb/host/ehci-mem.c +++ b/drivers/usb/host/ehci-mem.c | |||
@@ -75,7 +75,8 @@ static void qh_destroy(struct ehci_qh *qh) | |||
75 | } | 75 | } |
76 | if (qh->dummy) | 76 | if (qh->dummy) |
77 | ehci_qtd_free (ehci, qh->dummy); | 77 | ehci_qtd_free (ehci, qh->dummy); |
78 | dma_pool_free (ehci->qh_pool, qh, qh->qh_dma); | 78 | dma_pool_free(ehci->qh_pool, qh->hw, qh->qh_dma); |
79 | kfree(qh); | ||
79 | } | 80 | } |
80 | 81 | ||
81 | static struct ehci_qh *ehci_qh_alloc (struct ehci_hcd *ehci, gfp_t flags) | 82 | static struct ehci_qh *ehci_qh_alloc (struct ehci_hcd *ehci, gfp_t flags) |
@@ -83,12 +84,14 @@ static struct ehci_qh *ehci_qh_alloc (struct ehci_hcd *ehci, gfp_t flags) | |||
83 | struct ehci_qh *qh; | 84 | struct ehci_qh *qh; |
84 | dma_addr_t dma; | 85 | dma_addr_t dma; |
85 | 86 | ||
86 | qh = (struct ehci_qh *) | 87 | qh = kzalloc(sizeof *qh, GFP_ATOMIC); |
87 | dma_pool_alloc (ehci->qh_pool, flags, &dma); | ||
88 | if (!qh) | 88 | if (!qh) |
89 | return qh; | 89 | goto done; |
90 | 90 | qh->hw = (struct ehci_qh_hw *) | |
91 | memset (qh, 0, sizeof *qh); | 91 | dma_pool_alloc(ehci->qh_pool, flags, &dma); |
92 | if (!qh->hw) | ||
93 | goto fail; | ||
94 | memset(qh->hw, 0, sizeof *qh->hw); | ||
92 | qh->refcount = 1; | 95 | qh->refcount = 1; |
93 | qh->ehci = ehci; | 96 | qh->ehci = ehci; |
94 | qh->qh_dma = dma; | 97 | qh->qh_dma = dma; |
@@ -99,10 +102,15 @@ static struct ehci_qh *ehci_qh_alloc (struct ehci_hcd *ehci, gfp_t flags) | |||
99 | qh->dummy = ehci_qtd_alloc (ehci, flags); | 102 | qh->dummy = ehci_qtd_alloc (ehci, flags); |
100 | if (qh->dummy == NULL) { | 103 | if (qh->dummy == NULL) { |
101 | ehci_dbg (ehci, "no dummy td\n"); | 104 | ehci_dbg (ehci, "no dummy td\n"); |
102 | dma_pool_free (ehci->qh_pool, qh, qh->qh_dma); | 105 | goto fail1; |
103 | qh = NULL; | ||
104 | } | 106 | } |
107 | done: | ||
105 | return qh; | 108 | return qh; |
109 | fail1: | ||
110 | dma_pool_free(ehci->qh_pool, qh->hw, qh->qh_dma); | ||
111 | fail: | ||
112 | kfree(qh); | ||
113 | return NULL; | ||
106 | } | 114 | } |
107 | 115 | ||
108 | /* to share a qh (cpu threads, or hc) */ | 116 | /* to share a qh (cpu threads, or hc) */ |
@@ -180,7 +188,7 @@ static int ehci_mem_init (struct ehci_hcd *ehci, gfp_t flags) | |||
180 | /* QHs for control/bulk/intr transfers */ | 188 | /* QHs for control/bulk/intr transfers */ |
181 | ehci->qh_pool = dma_pool_create ("ehci_qh", | 189 | ehci->qh_pool = dma_pool_create ("ehci_qh", |
182 | ehci_to_hcd(ehci)->self.controller, | 190 | ehci_to_hcd(ehci)->self.controller, |
183 | sizeof (struct ehci_qh), | 191 | sizeof(struct ehci_qh_hw), |
184 | 32 /* byte alignment (for hw parts) */, | 192 | 32 /* byte alignment (for hw parts) */, |
185 | 4096 /* can't cross 4K */); | 193 | 4096 /* can't cross 4K */); |
186 | if (!ehci->qh_pool) { | 194 | if (!ehci->qh_pool) { |
diff --git a/drivers/usb/host/ehci-pci.c b/drivers/usb/host/ehci-pci.c index c2f1b7df918c..378861b9d79a 100644 --- a/drivers/usb/host/ehci-pci.c +++ b/drivers/usb/host/ehci-pci.c | |||
@@ -27,28 +27,8 @@ | |||
27 | /* called after powerup, by probe or system-pm "wakeup" */ | 27 | /* called after powerup, by probe or system-pm "wakeup" */ |
28 | static int ehci_pci_reinit(struct ehci_hcd *ehci, struct pci_dev *pdev) | 28 | static int ehci_pci_reinit(struct ehci_hcd *ehci, struct pci_dev *pdev) |
29 | { | 29 | { |
30 | u32 temp; | ||
31 | int retval; | 30 | int retval; |
32 | 31 | ||
33 | /* optional debug port, normally in the first BAR */ | ||
34 | temp = pci_find_capability(pdev, 0x0a); | ||
35 | if (temp) { | ||
36 | pci_read_config_dword(pdev, temp, &temp); | ||
37 | temp >>= 16; | ||
38 | if ((temp & (3 << 13)) == (1 << 13)) { | ||
39 | temp &= 0x1fff; | ||
40 | ehci->debug = ehci_to_hcd(ehci)->regs + temp; | ||
41 | temp = ehci_readl(ehci, &ehci->debug->control); | ||
42 | ehci_info(ehci, "debug port %d%s\n", | ||
43 | HCS_DEBUG_PORT(ehci->hcs_params), | ||
44 | (temp & DBGP_ENABLED) | ||
45 | ? " IN USE" | ||
46 | : ""); | ||
47 | if (!(temp & DBGP_ENABLED)) | ||
48 | ehci->debug = NULL; | ||
49 | } | ||
50 | } | ||
51 | |||
52 | /* we expect static quirk code to handle the "extended capabilities" | 32 | /* we expect static quirk code to handle the "extended capabilities" |
53 | * (currently just BIOS handoff) allowed starting with EHCI 0.96 | 33 | * (currently just BIOS handoff) allowed starting with EHCI 0.96 |
54 | */ | 34 | */ |
@@ -129,6 +109,9 @@ static int ehci_pci_setup(struct usb_hcd *hcd) | |||
129 | return retval; | 109 | return retval; |
130 | 110 | ||
131 | switch (pdev->vendor) { | 111 | switch (pdev->vendor) { |
112 | case PCI_VENDOR_ID_INTEL: | ||
113 | ehci->need_io_watchdog = 0; | ||
114 | break; | ||
132 | case PCI_VENDOR_ID_TDI: | 115 | case PCI_VENDOR_ID_TDI: |
133 | if (pdev->device == PCI_DEVICE_ID_TDI_EHCI) { | 116 | if (pdev->device == PCI_DEVICE_ID_TDI_EHCI) { |
134 | hcd->has_tt = 1; | 117 | hcd->has_tt = 1; |
@@ -192,6 +175,25 @@ static int ehci_pci_setup(struct usb_hcd *hcd) | |||
192 | break; | 175 | break; |
193 | } | 176 | } |
194 | 177 | ||
178 | /* optional debug port, normally in the first BAR */ | ||
179 | temp = pci_find_capability(pdev, 0x0a); | ||
180 | if (temp) { | ||
181 | pci_read_config_dword(pdev, temp, &temp); | ||
182 | temp >>= 16; | ||
183 | if ((temp & (3 << 13)) == (1 << 13)) { | ||
184 | temp &= 0x1fff; | ||
185 | ehci->debug = ehci_to_hcd(ehci)->regs + temp; | ||
186 | temp = ehci_readl(ehci, &ehci->debug->control); | ||
187 | ehci_info(ehci, "debug port %d%s\n", | ||
188 | HCS_DEBUG_PORT(ehci->hcs_params), | ||
189 | (temp & DBGP_ENABLED) | ||
190 | ? " IN USE" | ||
191 | : ""); | ||
192 | if (!(temp & DBGP_ENABLED)) | ||
193 | ehci->debug = NULL; | ||
194 | } | ||
195 | } | ||
196 | |||
195 | ehci_reset(ehci); | 197 | ehci_reset(ehci); |
196 | 198 | ||
197 | /* at least the Genesys GL880S needs fixup here */ | 199 | /* at least the Genesys GL880S needs fixup here */ |
@@ -242,7 +244,7 @@ static int ehci_pci_setup(struct usb_hcd *hcd) | |||
242 | * System suspend currently expects to be able to suspend the entire | 244 | * System suspend currently expects to be able to suspend the entire |
243 | * device tree, device-at-a-time. If we failed selective suspend | 245 | * device tree, device-at-a-time. If we failed selective suspend |
244 | * reports, system suspend would fail; so the root hub code must claim | 246 | * reports, system suspend would fail; so the root hub code must claim |
245 | * success. That's lying to usbcore, and it matters for for runtime | 247 | * success. That's lying to usbcore, and it matters for runtime |
246 | * PM scenarios with selective suspend and remote wakeup... | 248 | * PM scenarios with selective suspend and remote wakeup... |
247 | */ | 249 | */ |
248 | if (ehci->no_selective_suspend && device_can_wakeup(&pdev->dev)) | 250 | if (ehci->no_selective_suspend && device_can_wakeup(&pdev->dev)) |
diff --git a/drivers/usb/host/ehci-q.c b/drivers/usb/host/ehci-q.c index 7673554fa64d..00ad9ce392ed 100644 --- a/drivers/usb/host/ehci-q.c +++ b/drivers/usb/host/ehci-q.c | |||
@@ -87,31 +87,33 @@ qtd_fill(struct ehci_hcd *ehci, struct ehci_qtd *qtd, dma_addr_t buf, | |||
87 | static inline void | 87 | static inline void |
88 | qh_update (struct ehci_hcd *ehci, struct ehci_qh *qh, struct ehci_qtd *qtd) | 88 | qh_update (struct ehci_hcd *ehci, struct ehci_qh *qh, struct ehci_qtd *qtd) |
89 | { | 89 | { |
90 | struct ehci_qh_hw *hw = qh->hw; | ||
91 | |||
90 | /* writes to an active overlay are unsafe */ | 92 | /* writes to an active overlay are unsafe */ |
91 | BUG_ON(qh->qh_state != QH_STATE_IDLE); | 93 | BUG_ON(qh->qh_state != QH_STATE_IDLE); |
92 | 94 | ||
93 | qh->hw_qtd_next = QTD_NEXT(ehci, qtd->qtd_dma); | 95 | hw->hw_qtd_next = QTD_NEXT(ehci, qtd->qtd_dma); |
94 | qh->hw_alt_next = EHCI_LIST_END(ehci); | 96 | hw->hw_alt_next = EHCI_LIST_END(ehci); |
95 | 97 | ||
96 | /* Except for control endpoints, we make hardware maintain data | 98 | /* Except for control endpoints, we make hardware maintain data |
97 | * toggle (like OHCI) ... here (re)initialize the toggle in the QH, | 99 | * toggle (like OHCI) ... here (re)initialize the toggle in the QH, |
98 | * and set the pseudo-toggle in udev. Only usb_clear_halt() will | 100 | * and set the pseudo-toggle in udev. Only usb_clear_halt() will |
99 | * ever clear it. | 101 | * ever clear it. |
100 | */ | 102 | */ |
101 | if (!(qh->hw_info1 & cpu_to_hc32(ehci, 1 << 14))) { | 103 | if (!(hw->hw_info1 & cpu_to_hc32(ehci, 1 << 14))) { |
102 | unsigned is_out, epnum; | 104 | unsigned is_out, epnum; |
103 | 105 | ||
104 | is_out = !(qtd->hw_token & cpu_to_hc32(ehci, 1 << 8)); | 106 | is_out = !(qtd->hw_token & cpu_to_hc32(ehci, 1 << 8)); |
105 | epnum = (hc32_to_cpup(ehci, &qh->hw_info1) >> 8) & 0x0f; | 107 | epnum = (hc32_to_cpup(ehci, &hw->hw_info1) >> 8) & 0x0f; |
106 | if (unlikely (!usb_gettoggle (qh->dev, epnum, is_out))) { | 108 | if (unlikely (!usb_gettoggle (qh->dev, epnum, is_out))) { |
107 | qh->hw_token &= ~cpu_to_hc32(ehci, QTD_TOGGLE); | 109 | hw->hw_token &= ~cpu_to_hc32(ehci, QTD_TOGGLE); |
108 | usb_settoggle (qh->dev, epnum, is_out, 1); | 110 | usb_settoggle (qh->dev, epnum, is_out, 1); |
109 | } | 111 | } |
110 | } | 112 | } |
111 | 113 | ||
112 | /* HC must see latest qtd and qh data before we clear ACTIVE+HALT */ | 114 | /* HC must see latest qtd and qh data before we clear ACTIVE+HALT */ |
113 | wmb (); | 115 | wmb (); |
114 | qh->hw_token &= cpu_to_hc32(ehci, QTD_TOGGLE | QTD_STS_PING); | 116 | hw->hw_token &= cpu_to_hc32(ehci, QTD_TOGGLE | QTD_STS_PING); |
115 | } | 117 | } |
116 | 118 | ||
117 | /* if it weren't for a common silicon quirk (writing the dummy into the qh | 119 | /* if it weren't for a common silicon quirk (writing the dummy into the qh |
@@ -129,7 +131,7 @@ qh_refresh (struct ehci_hcd *ehci, struct ehci_qh *qh) | |||
129 | qtd = list_entry (qh->qtd_list.next, | 131 | qtd = list_entry (qh->qtd_list.next, |
130 | struct ehci_qtd, qtd_list); | 132 | struct ehci_qtd, qtd_list); |
131 | /* first qtd may already be partially processed */ | 133 | /* first qtd may already be partially processed */ |
132 | if (cpu_to_hc32(ehci, qtd->qtd_dma) == qh->hw_current) | 134 | if (cpu_to_hc32(ehci, qtd->qtd_dma) == qh->hw->hw_current) |
133 | qtd = NULL; | 135 | qtd = NULL; |
134 | } | 136 | } |
135 | 137 | ||
@@ -260,7 +262,7 @@ __acquires(ehci->lock) | |||
260 | struct ehci_qh *qh = (struct ehci_qh *) urb->hcpriv; | 262 | struct ehci_qh *qh = (struct ehci_qh *) urb->hcpriv; |
261 | 263 | ||
262 | /* S-mask in a QH means it's an interrupt urb */ | 264 | /* S-mask in a QH means it's an interrupt urb */ |
263 | if ((qh->hw_info2 & cpu_to_hc32(ehci, QH_SMASK)) != 0) { | 265 | if ((qh->hw->hw_info2 & cpu_to_hc32(ehci, QH_SMASK)) != 0) { |
264 | 266 | ||
265 | /* ... update hc-wide periodic stats (for usbfs) */ | 267 | /* ... update hc-wide periodic stats (for usbfs) */ |
266 | ehci_to_hcd(ehci)->self.bandwidth_int_reqs--; | 268 | ehci_to_hcd(ehci)->self.bandwidth_int_reqs--; |
@@ -297,7 +299,6 @@ __acquires(ehci->lock) | |||
297 | static void start_unlink_async (struct ehci_hcd *ehci, struct ehci_qh *qh); | 299 | static void start_unlink_async (struct ehci_hcd *ehci, struct ehci_qh *qh); |
298 | static void unlink_async (struct ehci_hcd *ehci, struct ehci_qh *qh); | 300 | static void unlink_async (struct ehci_hcd *ehci, struct ehci_qh *qh); |
299 | 301 | ||
300 | static void intr_deschedule (struct ehci_hcd *ehci, struct ehci_qh *qh); | ||
301 | static int qh_schedule (struct ehci_hcd *ehci, struct ehci_qh *qh); | 302 | static int qh_schedule (struct ehci_hcd *ehci, struct ehci_qh *qh); |
302 | 303 | ||
303 | /* | 304 | /* |
@@ -308,13 +309,14 @@ static int qh_schedule (struct ehci_hcd *ehci, struct ehci_qh *qh); | |||
308 | static unsigned | 309 | static unsigned |
309 | qh_completions (struct ehci_hcd *ehci, struct ehci_qh *qh) | 310 | qh_completions (struct ehci_hcd *ehci, struct ehci_qh *qh) |
310 | { | 311 | { |
311 | struct ehci_qtd *last = NULL, *end = qh->dummy; | 312 | struct ehci_qtd *last, *end = qh->dummy; |
312 | struct list_head *entry, *tmp; | 313 | struct list_head *entry, *tmp; |
313 | int last_status = -EINPROGRESS; | 314 | int last_status; |
314 | int stopped; | 315 | int stopped; |
315 | unsigned count = 0; | 316 | unsigned count = 0; |
316 | u8 state; | 317 | u8 state; |
317 | __le32 halt = HALT_BIT(ehci); | 318 | const __le32 halt = HALT_BIT(ehci); |
319 | struct ehci_qh_hw *hw = qh->hw; | ||
318 | 320 | ||
319 | if (unlikely (list_empty (&qh->qtd_list))) | 321 | if (unlikely (list_empty (&qh->qtd_list))) |
320 | return count; | 322 | return count; |
@@ -324,11 +326,20 @@ qh_completions (struct ehci_hcd *ehci, struct ehci_qh *qh) | |||
324 | * they add urbs to this qh's queue or mark them for unlinking. | 326 | * they add urbs to this qh's queue or mark them for unlinking. |
325 | * | 327 | * |
326 | * NOTE: unlinking expects to be done in queue order. | 328 | * NOTE: unlinking expects to be done in queue order. |
329 | * | ||
330 | * It's a bug for qh->qh_state to be anything other than | ||
331 | * QH_STATE_IDLE, unless our caller is scan_async() or | ||
332 | * scan_periodic(). | ||
327 | */ | 333 | */ |
328 | state = qh->qh_state; | 334 | state = qh->qh_state; |
329 | qh->qh_state = QH_STATE_COMPLETING; | 335 | qh->qh_state = QH_STATE_COMPLETING; |
330 | stopped = (state == QH_STATE_IDLE); | 336 | stopped = (state == QH_STATE_IDLE); |
331 | 337 | ||
338 | rescan: | ||
339 | last = NULL; | ||
340 | last_status = -EINPROGRESS; | ||
341 | qh->needs_rescan = 0; | ||
342 | |||
332 | /* remove de-activated QTDs from front of queue. | 343 | /* remove de-activated QTDs from front of queue. |
333 | * after faults (including short reads), cleanup this urb | 344 | * after faults (including short reads), cleanup this urb |
334 | * then let the queue advance. | 345 | * then let the queue advance. |
@@ -392,7 +403,8 @@ qh_completions (struct ehci_hcd *ehci, struct ehci_qh *qh) | |||
392 | qtd->hw_token = cpu_to_hc32(ehci, | 403 | qtd->hw_token = cpu_to_hc32(ehci, |
393 | token); | 404 | token); |
394 | wmb(); | 405 | wmb(); |
395 | qh->hw_token = cpu_to_hc32(ehci, token); | 406 | hw->hw_token = cpu_to_hc32(ehci, |
407 | token); | ||
396 | goto retry_xacterr; | 408 | goto retry_xacterr; |
397 | } | 409 | } |
398 | stopped = 1; | 410 | stopped = 1; |
@@ -435,8 +447,8 @@ qh_completions (struct ehci_hcd *ehci, struct ehci_qh *qh) | |||
435 | /* qh unlinked; token in overlay may be most current */ | 447 | /* qh unlinked; token in overlay may be most current */ |
436 | if (state == QH_STATE_IDLE | 448 | if (state == QH_STATE_IDLE |
437 | && cpu_to_hc32(ehci, qtd->qtd_dma) | 449 | && cpu_to_hc32(ehci, qtd->qtd_dma) |
438 | == qh->hw_current) { | 450 | == hw->hw_current) { |
439 | token = hc32_to_cpu(ehci, qh->hw_token); | 451 | token = hc32_to_cpu(ehci, hw->hw_token); |
440 | 452 | ||
441 | /* An unlink may leave an incomplete | 453 | /* An unlink may leave an incomplete |
442 | * async transaction in the TT buffer. | 454 | * async transaction in the TT buffer. |
@@ -449,9 +461,9 @@ qh_completions (struct ehci_hcd *ehci, struct ehci_qh *qh) | |||
449 | * patch the qh later and so that completions can't | 461 | * patch the qh later and so that completions can't |
450 | * activate it while we "know" it's stopped. | 462 | * activate it while we "know" it's stopped. |
451 | */ | 463 | */ |
452 | if ((halt & qh->hw_token) == 0) { | 464 | if ((halt & hw->hw_token) == 0) { |
453 | halt: | 465 | halt: |
454 | qh->hw_token |= halt; | 466 | hw->hw_token |= halt; |
455 | wmb (); | 467 | wmb (); |
456 | } | 468 | } |
457 | } | 469 | } |
@@ -503,6 +515,21 @@ halt: | |||
503 | ehci_qtd_free (ehci, last); | 515 | ehci_qtd_free (ehci, last); |
504 | } | 516 | } |
505 | 517 | ||
518 | /* Do we need to rescan for URBs dequeued during a giveback? */ | ||
519 | if (unlikely(qh->needs_rescan)) { | ||
520 | /* If the QH is already unlinked, do the rescan now. */ | ||
521 | if (state == QH_STATE_IDLE) | ||
522 | goto rescan; | ||
523 | |||
524 | /* Otherwise we have to wait until the QH is fully unlinked. | ||
525 | * Our caller will start an unlink if qh->needs_rescan is | ||
526 | * set. But if an unlink has already started, nothing needs | ||
527 | * to be done. | ||
528 | */ | ||
529 | if (state != QH_STATE_LINKED) | ||
530 | qh->needs_rescan = 0; | ||
531 | } | ||
532 | |||
506 | /* restore original state; caller must unlink or relink */ | 533 | /* restore original state; caller must unlink or relink */ |
507 | qh->qh_state = state; | 534 | qh->qh_state = state; |
508 | 535 | ||
@@ -510,7 +537,7 @@ halt: | |||
510 | * it after fault cleanup, or recovering from silicon wrongly | 537 | * it after fault cleanup, or recovering from silicon wrongly |
511 | * overlaying the dummy qtd (which reduces DMA chatter). | 538 | * overlaying the dummy qtd (which reduces DMA chatter). |
512 | */ | 539 | */ |
513 | if (stopped != 0 || qh->hw_qtd_next == EHCI_LIST_END(ehci)) { | 540 | if (stopped != 0 || hw->hw_qtd_next == EHCI_LIST_END(ehci)) { |
514 | switch (state) { | 541 | switch (state) { |
515 | case QH_STATE_IDLE: | 542 | case QH_STATE_IDLE: |
516 | qh_refresh(ehci, qh); | 543 | qh_refresh(ehci, qh); |
@@ -527,12 +554,9 @@ halt: | |||
527 | * That should be rare for interrupt transfers, | 554 | * That should be rare for interrupt transfers, |
528 | * except maybe high bandwidth ... | 555 | * except maybe high bandwidth ... |
529 | */ | 556 | */ |
530 | if ((cpu_to_hc32(ehci, QH_SMASK) | 557 | |
531 | & qh->hw_info2) != 0) { | 558 | /* Tell the caller to start an unlink */ |
532 | intr_deschedule (ehci, qh); | 559 | qh->needs_rescan = 1; |
533 | (void) qh_schedule (ehci, qh); | ||
534 | } else | ||
535 | unlink_async (ehci, qh); | ||
536 | break; | 560 | break; |
537 | /* otherwise, unlink already started */ | 561 | /* otherwise, unlink already started */ |
538 | } | 562 | } |
@@ -649,7 +673,7 @@ qh_urb_transaction ( | |||
649 | * (this will usually be overridden later.) | 673 | * (this will usually be overridden later.) |
650 | */ | 674 | */ |
651 | if (is_input) | 675 | if (is_input) |
652 | qtd->hw_alt_next = ehci->async->hw_alt_next; | 676 | qtd->hw_alt_next = ehci->async->hw->hw_alt_next; |
653 | 677 | ||
654 | /* qh makes control packets use qtd toggle; maybe switch it */ | 678 | /* qh makes control packets use qtd toggle; maybe switch it */ |
655 | if ((maxpacket & (this_qtd_len + (maxpacket - 1))) == 0) | 679 | if ((maxpacket & (this_qtd_len + (maxpacket - 1))) == 0) |
@@ -744,6 +768,7 @@ qh_make ( | |||
744 | int is_input, type; | 768 | int is_input, type; |
745 | int maxp = 0; | 769 | int maxp = 0; |
746 | struct usb_tt *tt = urb->dev->tt; | 770 | struct usb_tt *tt = urb->dev->tt; |
771 | struct ehci_qh_hw *hw; | ||
747 | 772 | ||
748 | if (!qh) | 773 | if (!qh) |
749 | return qh; | 774 | return qh; |
@@ -890,8 +915,9 @@ done: | |||
890 | 915 | ||
891 | /* init as live, toggle clear, advance to dummy */ | 916 | /* init as live, toggle clear, advance to dummy */ |
892 | qh->qh_state = QH_STATE_IDLE; | 917 | qh->qh_state = QH_STATE_IDLE; |
893 | qh->hw_info1 = cpu_to_hc32(ehci, info1); | 918 | hw = qh->hw; |
894 | qh->hw_info2 = cpu_to_hc32(ehci, info2); | 919 | hw->hw_info1 = cpu_to_hc32(ehci, info1); |
920 | hw->hw_info2 = cpu_to_hc32(ehci, info2); | ||
895 | usb_settoggle (urb->dev, usb_pipeendpoint (urb->pipe), !is_input, 1); | 921 | usb_settoggle (urb->dev, usb_pipeendpoint (urb->pipe), !is_input, 1); |
896 | qh_refresh (ehci, qh); | 922 | qh_refresh (ehci, qh); |
897 | return qh; | 923 | return qh; |
@@ -910,6 +936,8 @@ static void qh_link_async (struct ehci_hcd *ehci, struct ehci_qh *qh) | |||
910 | if (unlikely(qh->clearing_tt)) | 936 | if (unlikely(qh->clearing_tt)) |
911 | return; | 937 | return; |
912 | 938 | ||
939 | WARN_ON(qh->qh_state != QH_STATE_IDLE); | ||
940 | |||
913 | /* (re)start the async schedule? */ | 941 | /* (re)start the async schedule? */ |
914 | head = ehci->async; | 942 | head = ehci->async; |
915 | timer_action_done (ehci, TIMER_ASYNC_OFF); | 943 | timer_action_done (ehci, TIMER_ASYNC_OFF); |
@@ -928,16 +956,15 @@ static void qh_link_async (struct ehci_hcd *ehci, struct ehci_qh *qh) | |||
928 | } | 956 | } |
929 | 957 | ||
930 | /* clear halt and/or toggle; and maybe recover from silicon quirk */ | 958 | /* clear halt and/or toggle; and maybe recover from silicon quirk */ |
931 | if (qh->qh_state == QH_STATE_IDLE) | 959 | qh_refresh(ehci, qh); |
932 | qh_refresh (ehci, qh); | ||
933 | 960 | ||
934 | /* splice right after start */ | 961 | /* splice right after start */ |
935 | qh->qh_next = head->qh_next; | 962 | qh->qh_next = head->qh_next; |
936 | qh->hw_next = head->hw_next; | 963 | qh->hw->hw_next = head->hw->hw_next; |
937 | wmb (); | 964 | wmb (); |
938 | 965 | ||
939 | head->qh_next.qh = qh; | 966 | head->qh_next.qh = qh; |
940 | head->hw_next = dma; | 967 | head->hw->hw_next = dma; |
941 | 968 | ||
942 | qh_get(qh); | 969 | qh_get(qh); |
943 | qh->xacterrs = 0; | 970 | qh->xacterrs = 0; |
@@ -984,7 +1011,7 @@ static struct ehci_qh *qh_append_tds ( | |||
984 | 1011 | ||
985 | /* usb_reset_device() briefly reverts to address 0 */ | 1012 | /* usb_reset_device() briefly reverts to address 0 */ |
986 | if (usb_pipedevice (urb->pipe) == 0) | 1013 | if (usb_pipedevice (urb->pipe) == 0) |
987 | qh->hw_info1 &= ~qh_addr_mask; | 1014 | qh->hw->hw_info1 &= ~qh_addr_mask; |
988 | } | 1015 | } |
989 | 1016 | ||
990 | /* just one way to queue requests: swap with the dummy qtd. | 1017 | /* just one way to queue requests: swap with the dummy qtd. |
@@ -1169,7 +1196,7 @@ static void start_unlink_async (struct ehci_hcd *ehci, struct ehci_qh *qh) | |||
1169 | while (prev->qh_next.qh != qh) | 1196 | while (prev->qh_next.qh != qh) |
1170 | prev = prev->qh_next.qh; | 1197 | prev = prev->qh_next.qh; |
1171 | 1198 | ||
1172 | prev->hw_next = qh->hw_next; | 1199 | prev->hw->hw_next = qh->hw->hw_next; |
1173 | prev->qh_next = qh->qh_next; | 1200 | prev->qh_next = qh->qh_next; |
1174 | wmb (); | 1201 | wmb (); |
1175 | 1202 | ||
@@ -1214,6 +1241,8 @@ rescan: | |||
1214 | qh = qh_get (qh); | 1241 | qh = qh_get (qh); |
1215 | qh->stamp = ehci->stamp; | 1242 | qh->stamp = ehci->stamp; |
1216 | temp = qh_completions (ehci, qh); | 1243 | temp = qh_completions (ehci, qh); |
1244 | if (qh->needs_rescan) | ||
1245 | unlink_async(ehci, qh); | ||
1217 | qh_put (qh); | 1246 | qh_put (qh); |
1218 | if (temp != 0) { | 1247 | if (temp != 0) { |
1219 | goto rescan; | 1248 | goto rescan; |
diff --git a/drivers/usb/host/ehci-sched.c b/drivers/usb/host/ehci-sched.c index edd61ee90323..3ea05936851f 100644 --- a/drivers/usb/host/ehci-sched.c +++ b/drivers/usb/host/ehci-sched.c | |||
@@ -60,6 +60,20 @@ periodic_next_shadow(struct ehci_hcd *ehci, union ehci_shadow *periodic, | |||
60 | } | 60 | } |
61 | } | 61 | } |
62 | 62 | ||
63 | static __hc32 * | ||
64 | shadow_next_periodic(struct ehci_hcd *ehci, union ehci_shadow *periodic, | ||
65 | __hc32 tag) | ||
66 | { | ||
67 | switch (hc32_to_cpu(ehci, tag)) { | ||
68 | /* our ehci_shadow.qh is actually software part */ | ||
69 | case Q_TYPE_QH: | ||
70 | return &periodic->qh->hw->hw_next; | ||
71 | /* others are hw parts */ | ||
72 | default: | ||
73 | return periodic->hw_next; | ||
74 | } | ||
75 | } | ||
76 | |||
63 | /* caller must hold ehci->lock */ | 77 | /* caller must hold ehci->lock */ |
64 | static void periodic_unlink (struct ehci_hcd *ehci, unsigned frame, void *ptr) | 78 | static void periodic_unlink (struct ehci_hcd *ehci, unsigned frame, void *ptr) |
65 | { | 79 | { |
@@ -71,7 +85,8 @@ static void periodic_unlink (struct ehci_hcd *ehci, unsigned frame, void *ptr) | |||
71 | while (here.ptr && here.ptr != ptr) { | 85 | while (here.ptr && here.ptr != ptr) { |
72 | prev_p = periodic_next_shadow(ehci, prev_p, | 86 | prev_p = periodic_next_shadow(ehci, prev_p, |
73 | Q_NEXT_TYPE(ehci, *hw_p)); | 87 | Q_NEXT_TYPE(ehci, *hw_p)); |
74 | hw_p = here.hw_next; | 88 | hw_p = shadow_next_periodic(ehci, &here, |
89 | Q_NEXT_TYPE(ehci, *hw_p)); | ||
75 | here = *prev_p; | 90 | here = *prev_p; |
76 | } | 91 | } |
77 | /* an interrupt entry (at list end) could have been shared */ | 92 | /* an interrupt entry (at list end) could have been shared */ |
@@ -83,7 +98,7 @@ static void periodic_unlink (struct ehci_hcd *ehci, unsigned frame, void *ptr) | |||
83 | */ | 98 | */ |
84 | *prev_p = *periodic_next_shadow(ehci, &here, | 99 | *prev_p = *periodic_next_shadow(ehci, &here, |
85 | Q_NEXT_TYPE(ehci, *hw_p)); | 100 | Q_NEXT_TYPE(ehci, *hw_p)); |
86 | *hw_p = *here.hw_next; | 101 | *hw_p = *shadow_next_periodic(ehci, &here, Q_NEXT_TYPE(ehci, *hw_p)); |
87 | } | 102 | } |
88 | 103 | ||
89 | /* how many of the uframe's 125 usecs are allocated? */ | 104 | /* how many of the uframe's 125 usecs are allocated? */ |
@@ -93,18 +108,20 @@ periodic_usecs (struct ehci_hcd *ehci, unsigned frame, unsigned uframe) | |||
93 | __hc32 *hw_p = &ehci->periodic [frame]; | 108 | __hc32 *hw_p = &ehci->periodic [frame]; |
94 | union ehci_shadow *q = &ehci->pshadow [frame]; | 109 | union ehci_shadow *q = &ehci->pshadow [frame]; |
95 | unsigned usecs = 0; | 110 | unsigned usecs = 0; |
111 | struct ehci_qh_hw *hw; | ||
96 | 112 | ||
97 | while (q->ptr) { | 113 | while (q->ptr) { |
98 | switch (hc32_to_cpu(ehci, Q_NEXT_TYPE(ehci, *hw_p))) { | 114 | switch (hc32_to_cpu(ehci, Q_NEXT_TYPE(ehci, *hw_p))) { |
99 | case Q_TYPE_QH: | 115 | case Q_TYPE_QH: |
116 | hw = q->qh->hw; | ||
100 | /* is it in the S-mask? */ | 117 | /* is it in the S-mask? */ |
101 | if (q->qh->hw_info2 & cpu_to_hc32(ehci, 1 << uframe)) | 118 | if (hw->hw_info2 & cpu_to_hc32(ehci, 1 << uframe)) |
102 | usecs += q->qh->usecs; | 119 | usecs += q->qh->usecs; |
103 | /* ... or C-mask? */ | 120 | /* ... or C-mask? */ |
104 | if (q->qh->hw_info2 & cpu_to_hc32(ehci, | 121 | if (hw->hw_info2 & cpu_to_hc32(ehci, |
105 | 1 << (8 + uframe))) | 122 | 1 << (8 + uframe))) |
106 | usecs += q->qh->c_usecs; | 123 | usecs += q->qh->c_usecs; |
107 | hw_p = &q->qh->hw_next; | 124 | hw_p = &hw->hw_next; |
108 | q = &q->qh->qh_next; | 125 | q = &q->qh->qh_next; |
109 | break; | 126 | break; |
110 | // case Q_TYPE_FSTN: | 127 | // case Q_TYPE_FSTN: |
@@ -237,10 +254,10 @@ periodic_tt_usecs ( | |||
237 | continue; | 254 | continue; |
238 | case Q_TYPE_QH: | 255 | case Q_TYPE_QH: |
239 | if (same_tt(dev, q->qh->dev)) { | 256 | if (same_tt(dev, q->qh->dev)) { |
240 | uf = tt_start_uframe(ehci, q->qh->hw_info2); | 257 | uf = tt_start_uframe(ehci, q->qh->hw->hw_info2); |
241 | tt_usecs[uf] += q->qh->tt_usecs; | 258 | tt_usecs[uf] += q->qh->tt_usecs; |
242 | } | 259 | } |
243 | hw_p = &q->qh->hw_next; | 260 | hw_p = &q->qh->hw->hw_next; |
244 | q = &q->qh->qh_next; | 261 | q = &q->qh->qh_next; |
245 | continue; | 262 | continue; |
246 | case Q_TYPE_SITD: | 263 | case Q_TYPE_SITD: |
@@ -375,6 +392,7 @@ static int tt_no_collision ( | |||
375 | for (; frame < ehci->periodic_size; frame += period) { | 392 | for (; frame < ehci->periodic_size; frame += period) { |
376 | union ehci_shadow here; | 393 | union ehci_shadow here; |
377 | __hc32 type; | 394 | __hc32 type; |
395 | struct ehci_qh_hw *hw; | ||
378 | 396 | ||
379 | here = ehci->pshadow [frame]; | 397 | here = ehci->pshadow [frame]; |
380 | type = Q_NEXT_TYPE(ehci, ehci->periodic [frame]); | 398 | type = Q_NEXT_TYPE(ehci, ehci->periodic [frame]); |
@@ -385,17 +403,18 @@ static int tt_no_collision ( | |||
385 | here = here.itd->itd_next; | 403 | here = here.itd->itd_next; |
386 | continue; | 404 | continue; |
387 | case Q_TYPE_QH: | 405 | case Q_TYPE_QH: |
406 | hw = here.qh->hw; | ||
388 | if (same_tt (dev, here.qh->dev)) { | 407 | if (same_tt (dev, here.qh->dev)) { |
389 | u32 mask; | 408 | u32 mask; |
390 | 409 | ||
391 | mask = hc32_to_cpu(ehci, | 410 | mask = hc32_to_cpu(ehci, |
392 | here.qh->hw_info2); | 411 | hw->hw_info2); |
393 | /* "knows" no gap is needed */ | 412 | /* "knows" no gap is needed */ |
394 | mask |= mask >> 8; | 413 | mask |= mask >> 8; |
395 | if (mask & uf_mask) | 414 | if (mask & uf_mask) |
396 | break; | 415 | break; |
397 | } | 416 | } |
398 | type = Q_NEXT_TYPE(ehci, here.qh->hw_next); | 417 | type = Q_NEXT_TYPE(ehci, hw->hw_next); |
399 | here = here.qh->qh_next; | 418 | here = here.qh->qh_next; |
400 | continue; | 419 | continue; |
401 | case Q_TYPE_SITD: | 420 | case Q_TYPE_SITD: |
@@ -498,7 +517,8 @@ static int qh_link_periodic (struct ehci_hcd *ehci, struct ehci_qh *qh) | |||
498 | 517 | ||
499 | dev_dbg (&qh->dev->dev, | 518 | dev_dbg (&qh->dev->dev, |
500 | "link qh%d-%04x/%p start %d [%d/%d us]\n", | 519 | "link qh%d-%04x/%p start %d [%d/%d us]\n", |
501 | period, hc32_to_cpup(ehci, &qh->hw_info2) & (QH_CMASK | QH_SMASK), | 520 | period, hc32_to_cpup(ehci, &qh->hw->hw_info2) |
521 | & (QH_CMASK | QH_SMASK), | ||
502 | qh, qh->start, qh->usecs, qh->c_usecs); | 522 | qh, qh->start, qh->usecs, qh->c_usecs); |
503 | 523 | ||
504 | /* high bandwidth, or otherwise every microframe */ | 524 | /* high bandwidth, or otherwise every microframe */ |
@@ -517,7 +537,7 @@ static int qh_link_periodic (struct ehci_hcd *ehci, struct ehci_qh *qh) | |||
517 | if (type == cpu_to_hc32(ehci, Q_TYPE_QH)) | 537 | if (type == cpu_to_hc32(ehci, Q_TYPE_QH)) |
518 | break; | 538 | break; |
519 | prev = periodic_next_shadow(ehci, prev, type); | 539 | prev = periodic_next_shadow(ehci, prev, type); |
520 | hw_p = &here.qh->hw_next; | 540 | hw_p = shadow_next_periodic(ehci, &here, type); |
521 | here = *prev; | 541 | here = *prev; |
522 | } | 542 | } |
523 | 543 | ||
@@ -528,14 +548,14 @@ static int qh_link_periodic (struct ehci_hcd *ehci, struct ehci_qh *qh) | |||
528 | if (qh->period > here.qh->period) | 548 | if (qh->period > here.qh->period) |
529 | break; | 549 | break; |
530 | prev = &here.qh->qh_next; | 550 | prev = &here.qh->qh_next; |
531 | hw_p = &here.qh->hw_next; | 551 | hw_p = &here.qh->hw->hw_next; |
532 | here = *prev; | 552 | here = *prev; |
533 | } | 553 | } |
534 | /* link in this qh, unless some earlier pass did that */ | 554 | /* link in this qh, unless some earlier pass did that */ |
535 | if (qh != here.qh) { | 555 | if (qh != here.qh) { |
536 | qh->qh_next = here; | 556 | qh->qh_next = here; |
537 | if (here.qh) | 557 | if (here.qh) |
538 | qh->hw_next = *hw_p; | 558 | qh->hw->hw_next = *hw_p; |
539 | wmb (); | 559 | wmb (); |
540 | prev->qh = qh; | 560 | prev->qh = qh; |
541 | *hw_p = QH_NEXT (ehci, qh->qh_dma); | 561 | *hw_p = QH_NEXT (ehci, qh->qh_dma); |
@@ -581,7 +601,7 @@ static int qh_unlink_periodic(struct ehci_hcd *ehci, struct ehci_qh *qh) | |||
581 | dev_dbg (&qh->dev->dev, | 601 | dev_dbg (&qh->dev->dev, |
582 | "unlink qh%d-%04x/%p start %d [%d/%d us]\n", | 602 | "unlink qh%d-%04x/%p start %d [%d/%d us]\n", |
583 | qh->period, | 603 | qh->period, |
584 | hc32_to_cpup(ehci, &qh->hw_info2) & (QH_CMASK | QH_SMASK), | 604 | hc32_to_cpup(ehci, &qh->hw->hw_info2) & (QH_CMASK | QH_SMASK), |
585 | qh, qh->start, qh->usecs, qh->c_usecs); | 605 | qh, qh->start, qh->usecs, qh->c_usecs); |
586 | 606 | ||
587 | /* qh->qh_next still "live" to HC */ | 607 | /* qh->qh_next still "live" to HC */ |
@@ -595,7 +615,19 @@ static int qh_unlink_periodic(struct ehci_hcd *ehci, struct ehci_qh *qh) | |||
595 | 615 | ||
596 | static void intr_deschedule (struct ehci_hcd *ehci, struct ehci_qh *qh) | 616 | static void intr_deschedule (struct ehci_hcd *ehci, struct ehci_qh *qh) |
597 | { | 617 | { |
598 | unsigned wait; | 618 | unsigned wait; |
619 | struct ehci_qh_hw *hw = qh->hw; | ||
620 | int rc; | ||
621 | |||
622 | /* If the QH isn't linked then there's nothing we can do | ||
623 | * unless we were called during a giveback, in which case | ||
624 | * qh_completions() has to deal with it. | ||
625 | */ | ||
626 | if (qh->qh_state != QH_STATE_LINKED) { | ||
627 | if (qh->qh_state == QH_STATE_COMPLETING) | ||
628 | qh->needs_rescan = 1; | ||
629 | return; | ||
630 | } | ||
599 | 631 | ||
600 | qh_unlink_periodic (ehci, qh); | 632 | qh_unlink_periodic (ehci, qh); |
601 | 633 | ||
@@ -606,15 +638,33 @@ static void intr_deschedule (struct ehci_hcd *ehci, struct ehci_qh *qh) | |||
606 | */ | 638 | */ |
607 | if (list_empty (&qh->qtd_list) | 639 | if (list_empty (&qh->qtd_list) |
608 | || (cpu_to_hc32(ehci, QH_CMASK) | 640 | || (cpu_to_hc32(ehci, QH_CMASK) |
609 | & qh->hw_info2) != 0) | 641 | & hw->hw_info2) != 0) |
610 | wait = 2; | 642 | wait = 2; |
611 | else | 643 | else |
612 | wait = 55; /* worst case: 3 * 1024 */ | 644 | wait = 55; /* worst case: 3 * 1024 */ |
613 | 645 | ||
614 | udelay (wait); | 646 | udelay (wait); |
615 | qh->qh_state = QH_STATE_IDLE; | 647 | qh->qh_state = QH_STATE_IDLE; |
616 | qh->hw_next = EHCI_LIST_END(ehci); | 648 | hw->hw_next = EHCI_LIST_END(ehci); |
617 | wmb (); | 649 | wmb (); |
650 | |||
651 | qh_completions(ehci, qh); | ||
652 | |||
653 | /* reschedule QH iff another request is queued */ | ||
654 | if (!list_empty(&qh->qtd_list) && | ||
655 | HC_IS_RUNNING(ehci_to_hcd(ehci)->state)) { | ||
656 | rc = qh_schedule(ehci, qh); | ||
657 | |||
658 | /* An error here likely indicates handshake failure | ||
659 | * or no space left in the schedule. Neither fault | ||
660 | * should happen often ... | ||
661 | * | ||
662 | * FIXME kill the now-dysfunctional queued urbs | ||
663 | */ | ||
664 | if (rc != 0) | ||
665 | ehci_err(ehci, "can't reschedule qh %p, err %d\n", | ||
666 | qh, rc); | ||
667 | } | ||
618 | } | 668 | } |
619 | 669 | ||
620 | /*-------------------------------------------------------------------------*/ | 670 | /*-------------------------------------------------------------------------*/ |
@@ -739,14 +789,15 @@ static int qh_schedule(struct ehci_hcd *ehci, struct ehci_qh *qh) | |||
739 | unsigned uframe; | 789 | unsigned uframe; |
740 | __hc32 c_mask; | 790 | __hc32 c_mask; |
741 | unsigned frame; /* 0..(qh->period - 1), or NO_FRAME */ | 791 | unsigned frame; /* 0..(qh->period - 1), or NO_FRAME */ |
792 | struct ehci_qh_hw *hw = qh->hw; | ||
742 | 793 | ||
743 | qh_refresh(ehci, qh); | 794 | qh_refresh(ehci, qh); |
744 | qh->hw_next = EHCI_LIST_END(ehci); | 795 | hw->hw_next = EHCI_LIST_END(ehci); |
745 | frame = qh->start; | 796 | frame = qh->start; |
746 | 797 | ||
747 | /* reuse the previous schedule slots, if we can */ | 798 | /* reuse the previous schedule slots, if we can */ |
748 | if (frame < qh->period) { | 799 | if (frame < qh->period) { |
749 | uframe = ffs(hc32_to_cpup(ehci, &qh->hw_info2) & QH_SMASK); | 800 | uframe = ffs(hc32_to_cpup(ehci, &hw->hw_info2) & QH_SMASK); |
750 | status = check_intr_schedule (ehci, frame, --uframe, | 801 | status = check_intr_schedule (ehci, frame, --uframe, |
751 | qh, &c_mask); | 802 | qh, &c_mask); |
752 | } else { | 803 | } else { |
@@ -784,11 +835,11 @@ static int qh_schedule(struct ehci_hcd *ehci, struct ehci_qh *qh) | |||
784 | qh->start = frame; | 835 | qh->start = frame; |
785 | 836 | ||
786 | /* reset S-frame and (maybe) C-frame masks */ | 837 | /* reset S-frame and (maybe) C-frame masks */ |
787 | qh->hw_info2 &= cpu_to_hc32(ehci, ~(QH_CMASK | QH_SMASK)); | 838 | hw->hw_info2 &= cpu_to_hc32(ehci, ~(QH_CMASK | QH_SMASK)); |
788 | qh->hw_info2 |= qh->period | 839 | hw->hw_info2 |= qh->period |
789 | ? cpu_to_hc32(ehci, 1 << uframe) | 840 | ? cpu_to_hc32(ehci, 1 << uframe) |
790 | : cpu_to_hc32(ehci, QH_SMASK); | 841 | : cpu_to_hc32(ehci, QH_SMASK); |
791 | qh->hw_info2 |= c_mask; | 842 | hw->hw_info2 |= c_mask; |
792 | } else | 843 | } else |
793 | ehci_dbg (ehci, "reused qh %p schedule\n", qh); | 844 | ehci_dbg (ehci, "reused qh %p schedule\n", qh); |
794 | 845 | ||
@@ -2188,10 +2239,11 @@ restart: | |||
2188 | case Q_TYPE_QH: | 2239 | case Q_TYPE_QH: |
2189 | /* handle any completions */ | 2240 | /* handle any completions */ |
2190 | temp.qh = qh_get (q.qh); | 2241 | temp.qh = qh_get (q.qh); |
2191 | type = Q_NEXT_TYPE(ehci, q.qh->hw_next); | 2242 | type = Q_NEXT_TYPE(ehci, q.qh->hw->hw_next); |
2192 | q = q.qh->qh_next; | 2243 | q = q.qh->qh_next; |
2193 | modified = qh_completions (ehci, temp.qh); | 2244 | modified = qh_completions (ehci, temp.qh); |
2194 | if (unlikely (list_empty (&temp.qh->qtd_list))) | 2245 | if (unlikely(list_empty(&temp.qh->qtd_list) || |
2246 | temp.qh->needs_rescan)) | ||
2195 | intr_deschedule (ehci, temp.qh); | 2247 | intr_deschedule (ehci, temp.qh); |
2196 | qh_put (temp.qh); | 2248 | qh_put (temp.qh); |
2197 | break; | 2249 | break; |
diff --git a/drivers/usb/host/ehci-w90x900.c b/drivers/usb/host/ehci-w90x900.c new file mode 100644 index 000000000000..cfa21ea20f82 --- /dev/null +++ b/drivers/usb/host/ehci-w90x900.c | |||
@@ -0,0 +1,181 @@ | |||
1 | /* | ||
2 | * linux/driver/usb/host/ehci-w90x900.c | ||
3 | * | ||
4 | * Copyright (c) 2008 Nuvoton technology corporation. | ||
5 | * | ||
6 | * Wan ZongShun <mcuos.com@gmail.com> | ||
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;version 2 of the License. | ||
11 | * | ||
12 | */ | ||
13 | |||
14 | #include <linux/platform_device.h> | ||
15 | |||
16 | /*ebable phy0 and phy1 for w90p910*/ | ||
17 | #define ENPHY (0x01<<8) | ||
18 | #define PHY0_CTR (0xA4) | ||
19 | #define PHY1_CTR (0xA8) | ||
20 | |||
21 | static int __devinit usb_w90x900_probe(const struct hc_driver *driver, | ||
22 | struct platform_device *pdev) | ||
23 | { | ||
24 | struct usb_hcd *hcd; | ||
25 | struct ehci_hcd *ehci; | ||
26 | struct resource *res; | ||
27 | int retval = 0, irq; | ||
28 | unsigned long val; | ||
29 | |||
30 | |||
31 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); | ||
32 | if (!res) { | ||
33 | retval = -ENXIO; | ||
34 | goto err1; | ||
35 | } | ||
36 | |||
37 | hcd = usb_create_hcd(driver, &pdev->dev, "w90x900 EHCI"); | ||
38 | if (!hcd) { | ||
39 | retval = -ENOMEM; | ||
40 | goto err1; | ||
41 | } | ||
42 | |||
43 | hcd->rsrc_start = res->start; | ||
44 | hcd->rsrc_len = res->end - res->start + 1; | ||
45 | |||
46 | if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) { | ||
47 | retval = -EBUSY; | ||
48 | goto err2; | ||
49 | } | ||
50 | |||
51 | hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len); | ||
52 | if (hcd->regs == NULL) { | ||
53 | retval = -EFAULT; | ||
54 | goto err3; | ||
55 | } | ||
56 | |||
57 | ehci = hcd_to_ehci(hcd); | ||
58 | ehci->caps = hcd->regs; | ||
59 | ehci->regs = hcd->regs + | ||
60 | HC_LENGTH(ehci_readl(ehci, &ehci->caps->hc_capbase)); | ||
61 | |||
62 | /* enable PHY 0,1,the regs only apply to w90p910 | ||
63 | * 0xA4,0xA8 were offsets of PHY0 and PHY1 controller of | ||
64 | * w90p910 IC relative to ehci->regs. | ||
65 | */ | ||
66 | val = __raw_readl(ehci->regs+PHY0_CTR); | ||
67 | val |= ENPHY; | ||
68 | __raw_writel(val, ehci->regs+PHY0_CTR); | ||
69 | |||
70 | val = __raw_readl(ehci->regs+PHY1_CTR); | ||
71 | val |= ENPHY; | ||
72 | __raw_writel(val, ehci->regs+PHY1_CTR); | ||
73 | |||
74 | ehci->hcs_params = ehci_readl(ehci, &ehci->caps->hcs_params); | ||
75 | ehci->sbrn = 0x20; | ||
76 | |||
77 | irq = platform_get_irq(pdev, 0); | ||
78 | if (irq < 0) | ||
79 | goto err4; | ||
80 | |||
81 | retval = usb_add_hcd(hcd, irq, IRQF_SHARED); | ||
82 | if (retval != 0) | ||
83 | goto err4; | ||
84 | |||
85 | ehci_writel(ehci, 1, &ehci->regs->configured_flag); | ||
86 | |||
87 | return retval; | ||
88 | err4: | ||
89 | iounmap(hcd->regs); | ||
90 | err3: | ||
91 | release_mem_region(hcd->rsrc_start, hcd->rsrc_len); | ||
92 | err2: | ||
93 | usb_put_hcd(hcd); | ||
94 | err1: | ||
95 | return retval; | ||
96 | } | ||
97 | |||
98 | static | ||
99 | void usb_w90x900_remove(struct usb_hcd *hcd, struct platform_device *pdev) | ||
100 | { | ||
101 | usb_remove_hcd(hcd); | ||
102 | iounmap(hcd->regs); | ||
103 | release_mem_region(hcd->rsrc_start, hcd->rsrc_len); | ||
104 | usb_put_hcd(hcd); | ||
105 | } | ||
106 | |||
107 | static const struct hc_driver ehci_w90x900_hc_driver = { | ||
108 | .description = hcd_name, | ||
109 | .product_desc = "Nuvoton w90x900 EHCI Host Controller", | ||
110 | .hcd_priv_size = sizeof(struct ehci_hcd), | ||
111 | |||
112 | /* | ||
113 | * generic hardware linkage | ||
114 | */ | ||
115 | .irq = ehci_irq, | ||
116 | .flags = HCD_USB2|HCD_MEMORY, | ||
117 | |||
118 | /* | ||
119 | * basic lifecycle operations | ||
120 | */ | ||
121 | .reset = ehci_init, | ||
122 | .start = ehci_run, | ||
123 | |||
124 | .stop = ehci_stop, | ||
125 | .shutdown = ehci_shutdown, | ||
126 | |||
127 | /* | ||
128 | * managing i/o requests and associated device resources | ||
129 | */ | ||
130 | .urb_enqueue = ehci_urb_enqueue, | ||
131 | .urb_dequeue = ehci_urb_dequeue, | ||
132 | .endpoint_disable = ehci_endpoint_disable, | ||
133 | |||
134 | /* | ||
135 | * scheduling support | ||
136 | */ | ||
137 | .get_frame_number = ehci_get_frame, | ||
138 | |||
139 | /* | ||
140 | * root hub support | ||
141 | */ | ||
142 | .hub_status_data = ehci_hub_status_data, | ||
143 | .hub_control = ehci_hub_control, | ||
144 | #ifdef CONFIG_PM | ||
145 | .bus_suspend = ehci_bus_suspend, | ||
146 | .bus_resume = ehci_bus_resume, | ||
147 | #endif | ||
148 | .relinquish_port = ehci_relinquish_port, | ||
149 | .port_handed_over = ehci_port_handed_over, | ||
150 | }; | ||
151 | |||
152 | static int __devinit ehci_w90x900_probe(struct platform_device *pdev) | ||
153 | { | ||
154 | if (usb_disabled()) | ||
155 | return -ENODEV; | ||
156 | |||
157 | return usb_w90x900_probe(&ehci_w90x900_hc_driver, pdev); | ||
158 | } | ||
159 | |||
160 | static int __devexit ehci_w90x900_remove(struct platform_device *pdev) | ||
161 | { | ||
162 | struct usb_hcd *hcd = platform_get_drvdata(pdev); | ||
163 | |||
164 | usb_w90x900_remove(hcd, pdev); | ||
165 | |||
166 | return 0; | ||
167 | } | ||
168 | |||
169 | static struct platform_driver ehci_hcd_w90x900_driver = { | ||
170 | .probe = ehci_w90x900_probe, | ||
171 | .remove = __devexit_p(ehci_w90x900_remove), | ||
172 | .driver = { | ||
173 | .name = "w90x900-ehci", | ||
174 | .owner = THIS_MODULE, | ||
175 | }, | ||
176 | }; | ||
177 | |||
178 | MODULE_AUTHOR("Wan ZongShun <mcuos.com@gmail.com>"); | ||
179 | MODULE_DESCRIPTION("w90p910 usb ehci driver!"); | ||
180 | MODULE_LICENSE("GPL"); | ||
181 | MODULE_ALIAS("platform:w90p910-ehci"); | ||
diff --git a/drivers/usb/host/ehci.h b/drivers/usb/host/ehci.h index 2bfff30f4704..064e76821ff5 100644 --- a/drivers/usb/host/ehci.h +++ b/drivers/usb/host/ehci.h | |||
@@ -37,7 +37,7 @@ typedef __u16 __bitwise __hc16; | |||
37 | #define __hc16 __le16 | 37 | #define __hc16 __le16 |
38 | #endif | 38 | #endif |
39 | 39 | ||
40 | /* statistics can be kept for for tuning/monitoring */ | 40 | /* statistics can be kept for tuning/monitoring */ |
41 | struct ehci_stats { | 41 | struct ehci_stats { |
42 | /* irq usage */ | 42 | /* irq usage */ |
43 | unsigned long normal; | 43 | unsigned long normal; |
@@ -126,6 +126,7 @@ struct ehci_hcd { /* one per controller */ | |||
126 | unsigned big_endian_mmio:1; | 126 | unsigned big_endian_mmio:1; |
127 | unsigned big_endian_desc:1; | 127 | unsigned big_endian_desc:1; |
128 | unsigned has_amcc_usb23:1; | 128 | unsigned has_amcc_usb23:1; |
129 | unsigned need_io_watchdog:1; | ||
129 | 130 | ||
130 | /* required for usb32 quirk */ | 131 | /* required for usb32 quirk */ |
131 | #define OHCI_CTRL_HCFS (3 << 6) | 132 | #define OHCI_CTRL_HCFS (3 << 6) |
@@ -135,6 +136,7 @@ struct ehci_hcd { /* one per controller */ | |||
135 | #define OHCI_HCCTRL_OFFSET 0x4 | 136 | #define OHCI_HCCTRL_OFFSET 0x4 |
136 | #define OHCI_HCCTRL_LEN 0x4 | 137 | #define OHCI_HCCTRL_LEN 0x4 |
137 | __hc32 *ohci_hcctrl_reg; | 138 | __hc32 *ohci_hcctrl_reg; |
139 | unsigned has_hostpc:1; | ||
138 | 140 | ||
139 | u8 sbrn; /* packed release number */ | 141 | u8 sbrn; /* packed release number */ |
140 | 142 | ||
@@ -298,8 +300,8 @@ union ehci_shadow { | |||
298 | * These appear in both the async and (for interrupt) periodic schedules. | 300 | * These appear in both the async and (for interrupt) periodic schedules. |
299 | */ | 301 | */ |
300 | 302 | ||
301 | struct ehci_qh { | 303 | /* first part defined by EHCI spec */ |
302 | /* first part defined by EHCI spec */ | 304 | struct ehci_qh_hw { |
303 | __hc32 hw_next; /* see EHCI 3.6.1 */ | 305 | __hc32 hw_next; /* see EHCI 3.6.1 */ |
304 | __hc32 hw_info1; /* see EHCI 3.6.2 */ | 306 | __hc32 hw_info1; /* see EHCI 3.6.2 */ |
305 | #define QH_HEAD 0x00008000 | 307 | #define QH_HEAD 0x00008000 |
@@ -317,7 +319,10 @@ struct ehci_qh { | |||
317 | __hc32 hw_token; | 319 | __hc32 hw_token; |
318 | __hc32 hw_buf [5]; | 320 | __hc32 hw_buf [5]; |
319 | __hc32 hw_buf_hi [5]; | 321 | __hc32 hw_buf_hi [5]; |
322 | } __attribute__ ((aligned(32))); | ||
320 | 323 | ||
324 | struct ehci_qh { | ||
325 | struct ehci_qh_hw *hw; | ||
321 | /* the rest is HCD-private */ | 326 | /* the rest is HCD-private */ |
322 | dma_addr_t qh_dma; /* address of qh */ | 327 | dma_addr_t qh_dma; /* address of qh */ |
323 | union ehci_shadow qh_next; /* ptr to qh; or periodic */ | 328 | union ehci_shadow qh_next; /* ptr to qh; or periodic */ |
@@ -336,6 +341,7 @@ struct ehci_qh { | |||
336 | u32 refcount; | 341 | u32 refcount; |
337 | unsigned stamp; | 342 | unsigned stamp; |
338 | 343 | ||
344 | u8 needs_rescan; /* Dequeue during giveback */ | ||
339 | u8 qh_state; | 345 | u8 qh_state; |
340 | #define QH_STATE_LINKED 1 /* HC sees this */ | 346 | #define QH_STATE_LINKED 1 /* HC sees this */ |
341 | #define QH_STATE_UNLINK 2 /* HC may still see this */ | 347 | #define QH_STATE_UNLINK 2 /* HC may still see this */ |
@@ -357,7 +363,7 @@ struct ehci_qh { | |||
357 | 363 | ||
358 | struct usb_device *dev; /* access to TT */ | 364 | struct usb_device *dev; /* access to TT */ |
359 | unsigned clearing_tt:1; /* Clear-TT-Buf in progress */ | 365 | unsigned clearing_tt:1; /* Clear-TT-Buf in progress */ |
360 | } __attribute__ ((aligned (32))); | 366 | }; |
361 | 367 | ||
362 | /*-------------------------------------------------------------------------*/ | 368 | /*-------------------------------------------------------------------------*/ |
363 | 369 | ||
@@ -544,7 +550,7 @@ static inline unsigned int | |||
544 | ehci_port_speed(struct ehci_hcd *ehci, unsigned int portsc) | 550 | ehci_port_speed(struct ehci_hcd *ehci, unsigned int portsc) |
545 | { | 551 | { |
546 | if (ehci_is_TDI(ehci)) { | 552 | if (ehci_is_TDI(ehci)) { |
547 | switch ((portsc>>26)&3) { | 553 | switch ((portsc >> (ehci->has_hostpc ? 25 : 26)) & 3) { |
548 | case 0: | 554 | case 0: |
549 | return 0; | 555 | return 0; |
550 | case 1: | 556 | case 1: |
diff --git a/drivers/usb/host/isp1362-hcd.c b/drivers/usb/host/isp1362-hcd.c new file mode 100644 index 000000000000..e35d82808bab --- /dev/null +++ b/drivers/usb/host/isp1362-hcd.c | |||
@@ -0,0 +1,2909 @@ | |||
1 | /* | ||
2 | * ISP1362 HCD (Host Controller Driver) for USB. | ||
3 | * | ||
4 | * Copyright (C) 2005 Lothar Wassmann <LW@KARO-electronics.de> | ||
5 | * | ||
6 | * Derived from the SL811 HCD, rewritten for ISP116x. | ||
7 | * Copyright (C) 2005 Olav Kongas <ok@artecdesign.ee> | ||
8 | * | ||
9 | * Portions: | ||
10 | * Copyright (C) 2004 Psion Teklogix (for NetBook PRO) | ||
11 | * Copyright (C) 2004 David Brownell | ||
12 | */ | ||
13 | |||
14 | /* | ||
15 | * The ISP1362 chip requires a large delay (300ns and 462ns) between | ||
16 | * accesses to the address and data register. | ||
17 | * The following timing options exist: | ||
18 | * | ||
19 | * 1. Configure your memory controller to add such delays if it can (the best) | ||
20 | * 2. Implement platform-specific delay function possibly | ||
21 | * combined with configuring the memory controller; see | ||
22 | * include/linux/usb_isp1362.h for more info. | ||
23 | * 3. Use ndelay (easiest, poorest). | ||
24 | * | ||
25 | * Use the corresponding macros USE_PLATFORM_DELAY and USE_NDELAY in the | ||
26 | * platform specific section of isp1362.h to select the appropriate variant. | ||
27 | * | ||
28 | * Also note that according to the Philips "ISP1362 Errata" document | ||
29 | * Rev 1.00 from 27 May data corruption may occur when the #WR signal | ||
30 | * is reasserted (even with #CS deasserted) within 132ns after a | ||
31 | * write cycle to any controller register. If the hardware doesn't | ||
32 | * implement the recommended fix (gating the #WR with #CS) software | ||
33 | * must ensure that no further write cycle (not necessarily to the chip!) | ||
34 | * is issued by the CPU within this interval. | ||
35 | |||
36 | * For PXA25x this can be ensured by using VLIO with the maximum | ||
37 | * recovery time (MSCx = 0x7f8c) with a memory clock of 99.53 MHz. | ||
38 | */ | ||
39 | |||
40 | #ifdef CONFIG_USB_DEBUG | ||
41 | # define ISP1362_DEBUG | ||
42 | #else | ||
43 | # undef ISP1362_DEBUG | ||
44 | #endif | ||
45 | |||
46 | /* | ||
47 | * The PXA255 UDC apparently doesn't handle GET_STATUS, GET_CONFIG and | ||
48 | * GET_INTERFACE requests correctly when the SETUP and DATA stages of the | ||
49 | * requests are carried out in separate frames. This will delay any SETUP | ||
50 | * packets until the start of the next frame so that this situation is | ||
51 | * unlikely to occur (and makes usbtest happy running with a PXA255 target | ||
52 | * device). | ||
53 | */ | ||
54 | #undef BUGGY_PXA2XX_UDC_USBTEST | ||
55 | |||
56 | #undef PTD_TRACE | ||
57 | #undef URB_TRACE | ||
58 | #undef VERBOSE | ||
59 | #undef REGISTERS | ||
60 | |||
61 | /* This enables a memory test on the ISP1362 chip memory to make sure the | ||
62 | * chip access timing is correct. | ||
63 | */ | ||
64 | #undef CHIP_BUFFER_TEST | ||
65 | |||
66 | #include <linux/module.h> | ||
67 | #include <linux/moduleparam.h> | ||
68 | #include <linux/kernel.h> | ||
69 | #include <linux/delay.h> | ||
70 | #include <linux/ioport.h> | ||
71 | #include <linux/sched.h> | ||
72 | #include <linux/slab.h> | ||
73 | #include <linux/smp_lock.h> | ||
74 | #include <linux/errno.h> | ||
75 | #include <linux/init.h> | ||
76 | #include <linux/list.h> | ||
77 | #include <linux/interrupt.h> | ||
78 | #include <linux/usb.h> | ||
79 | #include <linux/usb/isp1362.h> | ||
80 | #include <linux/platform_device.h> | ||
81 | #include <linux/pm.h> | ||
82 | #include <linux/io.h> | ||
83 | #include <linux/bitops.h> | ||
84 | |||
85 | #include <asm/irq.h> | ||
86 | #include <asm/system.h> | ||
87 | #include <asm/byteorder.h> | ||
88 | #include <asm/unaligned.h> | ||
89 | |||
90 | static int dbg_level; | ||
91 | #ifdef ISP1362_DEBUG | ||
92 | module_param(dbg_level, int, 0644); | ||
93 | #else | ||
94 | module_param(dbg_level, int, 0); | ||
95 | #define STUB_DEBUG_FILE | ||
96 | #endif | ||
97 | |||
98 | #include "../core/hcd.h" | ||
99 | #include "../core/usb.h" | ||
100 | #include "isp1362.h" | ||
101 | |||
102 | |||
103 | #define DRIVER_VERSION "2005-04-04" | ||
104 | #define DRIVER_DESC "ISP1362 USB Host Controller Driver" | ||
105 | |||
106 | MODULE_DESCRIPTION(DRIVER_DESC); | ||
107 | MODULE_LICENSE("GPL"); | ||
108 | |||
109 | static const char hcd_name[] = "isp1362-hcd"; | ||
110 | |||
111 | static void isp1362_hc_stop(struct usb_hcd *hcd); | ||
112 | static int isp1362_hc_start(struct usb_hcd *hcd); | ||
113 | |||
114 | /*-------------------------------------------------------------------------*/ | ||
115 | |||
116 | /* | ||
117 | * When called from the interrupthandler only isp1362_hcd->irqenb is modified, | ||
118 | * since the interrupt handler will write isp1362_hcd->irqenb to HCuPINT upon | ||
119 | * completion. | ||
120 | * We don't need a 'disable' counterpart, since interrupts will be disabled | ||
121 | * only by the interrupt handler. | ||
122 | */ | ||
123 | static inline void isp1362_enable_int(struct isp1362_hcd *isp1362_hcd, u16 mask) | ||
124 | { | ||
125 | if ((isp1362_hcd->irqenb | mask) == isp1362_hcd->irqenb) | ||
126 | return; | ||
127 | if (mask & ~isp1362_hcd->irqenb) | ||
128 | isp1362_write_reg16(isp1362_hcd, HCuPINT, mask & ~isp1362_hcd->irqenb); | ||
129 | isp1362_hcd->irqenb |= mask; | ||
130 | if (isp1362_hcd->irq_active) | ||
131 | return; | ||
132 | isp1362_write_reg16(isp1362_hcd, HCuPINTENB, isp1362_hcd->irqenb); | ||
133 | } | ||
134 | |||
135 | /*-------------------------------------------------------------------------*/ | ||
136 | |||
137 | static inline struct isp1362_ep_queue *get_ptd_queue(struct isp1362_hcd *isp1362_hcd, | ||
138 | u16 offset) | ||
139 | { | ||
140 | struct isp1362_ep_queue *epq = NULL; | ||
141 | |||
142 | if (offset < isp1362_hcd->istl_queue[1].buf_start) | ||
143 | epq = &isp1362_hcd->istl_queue[0]; | ||
144 | else if (offset < isp1362_hcd->intl_queue.buf_start) | ||
145 | epq = &isp1362_hcd->istl_queue[1]; | ||
146 | else if (offset < isp1362_hcd->atl_queue.buf_start) | ||
147 | epq = &isp1362_hcd->intl_queue; | ||
148 | else if (offset < isp1362_hcd->atl_queue.buf_start + | ||
149 | isp1362_hcd->atl_queue.buf_size) | ||
150 | epq = &isp1362_hcd->atl_queue; | ||
151 | |||
152 | if (epq) | ||
153 | DBG(1, "%s: PTD $%04x is on %s queue\n", __func__, offset, epq->name); | ||
154 | else | ||
155 | pr_warning("%s: invalid PTD $%04x\n", __func__, offset); | ||
156 | |||
157 | return epq; | ||
158 | } | ||
159 | |||
160 | static inline int get_ptd_offset(struct isp1362_ep_queue *epq, u8 index) | ||
161 | { | ||
162 | int offset; | ||
163 | |||
164 | if (index * epq->blk_size > epq->buf_size) { | ||
165 | pr_warning("%s: Bad %s index %d(%d)\n", __func__, epq->name, index, | ||
166 | epq->buf_size / epq->blk_size); | ||
167 | return -EINVAL; | ||
168 | } | ||
169 | offset = epq->buf_start + index * epq->blk_size; | ||
170 | DBG(3, "%s: %s PTD[%02x] # %04x\n", __func__, epq->name, index, offset); | ||
171 | |||
172 | return offset; | ||
173 | } | ||
174 | |||
175 | /*-------------------------------------------------------------------------*/ | ||
176 | |||
177 | static inline u16 max_transfer_size(struct isp1362_ep_queue *epq, size_t size, | ||
178 | int mps) | ||
179 | { | ||
180 | u16 xfer_size = min_t(size_t, MAX_XFER_SIZE, size); | ||
181 | |||
182 | xfer_size = min_t(size_t, xfer_size, epq->buf_avail * epq->blk_size - PTD_HEADER_SIZE); | ||
183 | if (xfer_size < size && xfer_size % mps) | ||
184 | xfer_size -= xfer_size % mps; | ||
185 | |||
186 | return xfer_size; | ||
187 | } | ||
188 | |||
189 | static int claim_ptd_buffers(struct isp1362_ep_queue *epq, | ||
190 | struct isp1362_ep *ep, u16 len) | ||
191 | { | ||
192 | int ptd_offset = -EINVAL; | ||
193 | int index; | ||
194 | int num_ptds = ((len + PTD_HEADER_SIZE - 1) / epq->blk_size) + 1; | ||
195 | int found = -1; | ||
196 | int last = -1; | ||
197 | |||
198 | BUG_ON(len > epq->buf_size); | ||
199 | |||
200 | if (!epq->buf_avail) | ||
201 | return -ENOMEM; | ||
202 | |||
203 | if (ep->num_ptds) | ||
204 | pr_err("%s: %s len %d/%d num_ptds %d buf_map %08lx skip_map %08lx\n", __func__, | ||
205 | epq->name, len, epq->blk_size, num_ptds, epq->buf_map, epq->skip_map); | ||
206 | BUG_ON(ep->num_ptds != 0); | ||
207 | |||
208 | for (index = 0; index <= epq->buf_count - num_ptds; index++) { | ||
209 | if (test_bit(index, &epq->buf_map)) | ||
210 | continue; | ||
211 | found = index; | ||
212 | for (last = index + 1; last < index + num_ptds; last++) { | ||
213 | if (test_bit(last, &epq->buf_map)) { | ||
214 | found = -1; | ||
215 | break; | ||
216 | } | ||
217 | } | ||
218 | if (found >= 0) | ||
219 | break; | ||
220 | } | ||
221 | if (found < 0) | ||
222 | return -EOVERFLOW; | ||
223 | |||
224 | DBG(1, "%s: Found %d PTDs[%d] for %d/%d byte\n", __func__, | ||
225 | num_ptds, found, len, (int)(epq->blk_size - PTD_HEADER_SIZE)); | ||
226 | ptd_offset = get_ptd_offset(epq, found); | ||
227 | WARN_ON(ptd_offset < 0); | ||
228 | ep->ptd_offset = ptd_offset; | ||
229 | ep->num_ptds += num_ptds; | ||
230 | epq->buf_avail -= num_ptds; | ||
231 | BUG_ON(epq->buf_avail > epq->buf_count); | ||
232 | ep->ptd_index = found; | ||
233 | for (index = found; index < last; index++) | ||
234 | __set_bit(index, &epq->buf_map); | ||
235 | DBG(1, "%s: Done %s PTD[%d] $%04x, avail %d count %d claimed %d %08lx:%08lx\n", | ||
236 | __func__, epq->name, ep->ptd_index, ep->ptd_offset, | ||
237 | epq->buf_avail, epq->buf_count, num_ptds, epq->buf_map, epq->skip_map); | ||
238 | |||
239 | return found; | ||
240 | } | ||
241 | |||
242 | static inline void release_ptd_buffers(struct isp1362_ep_queue *epq, struct isp1362_ep *ep) | ||
243 | { | ||
244 | int index = ep->ptd_index; | ||
245 | int last = ep->ptd_index + ep->num_ptds; | ||
246 | |||
247 | if (last > epq->buf_count) | ||
248 | pr_err("%s: ep %p req %d len %d %s PTD[%d] $%04x num_ptds %d buf_count %d buf_avail %d buf_map %08lx skip_map %08lx\n", | ||
249 | __func__, ep, ep->num_req, ep->length, epq->name, ep->ptd_index, | ||
250 | ep->ptd_offset, ep->num_ptds, epq->buf_count, epq->buf_avail, | ||
251 | epq->buf_map, epq->skip_map); | ||
252 | BUG_ON(last > epq->buf_count); | ||
253 | |||
254 | for (; index < last; index++) { | ||
255 | __clear_bit(index, &epq->buf_map); | ||
256 | __set_bit(index, &epq->skip_map); | ||
257 | } | ||
258 | epq->buf_avail += ep->num_ptds; | ||
259 | epq->ptd_count--; | ||
260 | |||
261 | BUG_ON(epq->buf_avail > epq->buf_count); | ||
262 | BUG_ON(epq->ptd_count > epq->buf_count); | ||
263 | |||
264 | DBG(1, "%s: Done %s PTDs $%04x released %d avail %d count %d\n", | ||
265 | __func__, epq->name, | ||
266 | ep->ptd_offset, ep->num_ptds, epq->buf_avail, epq->buf_count); | ||
267 | DBG(1, "%s: buf_map %08lx skip_map %08lx\n", __func__, | ||
268 | epq->buf_map, epq->skip_map); | ||
269 | |||
270 | ep->num_ptds = 0; | ||
271 | ep->ptd_offset = -EINVAL; | ||
272 | ep->ptd_index = -EINVAL; | ||
273 | } | ||
274 | |||
275 | /*-------------------------------------------------------------------------*/ | ||
276 | |||
277 | /* | ||
278 | Set up PTD's. | ||
279 | */ | ||
280 | static void prepare_ptd(struct isp1362_hcd *isp1362_hcd, struct urb *urb, | ||
281 | struct isp1362_ep *ep, struct isp1362_ep_queue *epq, | ||
282 | u16 fno) | ||
283 | { | ||
284 | struct ptd *ptd; | ||
285 | int toggle; | ||
286 | int dir; | ||
287 | u16 len; | ||
288 | size_t buf_len = urb->transfer_buffer_length - urb->actual_length; | ||
289 | |||
290 | DBG(3, "%s: %s ep %p\n", __func__, epq->name, ep); | ||
291 | |||
292 | ptd = &ep->ptd; | ||
293 | |||
294 | ep->data = (unsigned char *)urb->transfer_buffer + urb->actual_length; | ||
295 | |||
296 | switch (ep->nextpid) { | ||
297 | case USB_PID_IN: | ||
298 | toggle = usb_gettoggle(urb->dev, ep->epnum, 0); | ||
299 | dir = PTD_DIR_IN; | ||
300 | if (usb_pipecontrol(urb->pipe)) { | ||
301 | len = min_t(size_t, ep->maxpacket, buf_len); | ||
302 | } else if (usb_pipeisoc(urb->pipe)) { | ||
303 | len = min_t(size_t, urb->iso_frame_desc[fno].length, MAX_XFER_SIZE); | ||
304 | ep->data = urb->transfer_buffer + urb->iso_frame_desc[fno].offset; | ||
305 | } else | ||
306 | len = max_transfer_size(epq, buf_len, ep->maxpacket); | ||
307 | DBG(1, "%s: IN len %d/%d/%d from URB\n", __func__, len, ep->maxpacket, | ||
308 | (int)buf_len); | ||
309 | break; | ||
310 | case USB_PID_OUT: | ||
311 | toggle = usb_gettoggle(urb->dev, ep->epnum, 1); | ||
312 | dir = PTD_DIR_OUT; | ||
313 | if (usb_pipecontrol(urb->pipe)) | ||
314 | len = min_t(size_t, ep->maxpacket, buf_len); | ||
315 | else if (usb_pipeisoc(urb->pipe)) | ||
316 | len = min_t(size_t, urb->iso_frame_desc[0].length, MAX_XFER_SIZE); | ||
317 | else | ||
318 | len = max_transfer_size(epq, buf_len, ep->maxpacket); | ||
319 | if (len == 0) | ||
320 | pr_info("%s: Sending ZERO packet: %d\n", __func__, | ||
321 | urb->transfer_flags & URB_ZERO_PACKET); | ||
322 | DBG(1, "%s: OUT len %d/%d/%d from URB\n", __func__, len, ep->maxpacket, | ||
323 | (int)buf_len); | ||
324 | break; | ||
325 | case USB_PID_SETUP: | ||
326 | toggle = 0; | ||
327 | dir = PTD_DIR_SETUP; | ||
328 | len = sizeof(struct usb_ctrlrequest); | ||
329 | DBG(1, "%s: SETUP len %d\n", __func__, len); | ||
330 | ep->data = urb->setup_packet; | ||
331 | break; | ||
332 | case USB_PID_ACK: | ||
333 | toggle = 1; | ||
334 | len = 0; | ||
335 | dir = (urb->transfer_buffer_length && usb_pipein(urb->pipe)) ? | ||
336 | PTD_DIR_OUT : PTD_DIR_IN; | ||
337 | DBG(1, "%s: ACK len %d\n", __func__, len); | ||
338 | break; | ||
339 | default: | ||
340 | toggle = dir = len = 0; | ||
341 | pr_err("%s@%d: ep->nextpid %02x\n", __func__, __LINE__, ep->nextpid); | ||
342 | BUG_ON(1); | ||
343 | } | ||
344 | |||
345 | ep->length = len; | ||
346 | if (!len) | ||
347 | ep->data = NULL; | ||
348 | |||
349 | ptd->count = PTD_CC_MSK | PTD_ACTIVE_MSK | PTD_TOGGLE(toggle); | ||
350 | ptd->mps = PTD_MPS(ep->maxpacket) | PTD_SPD(urb->dev->speed == USB_SPEED_LOW) | | ||
351 | PTD_EP(ep->epnum); | ||
352 | ptd->len = PTD_LEN(len) | PTD_DIR(dir); | ||
353 | ptd->faddr = PTD_FA(usb_pipedevice(urb->pipe)); | ||
354 | |||
355 | if (usb_pipeint(urb->pipe)) { | ||
356 | ptd->faddr |= PTD_SF_INT(ep->branch); | ||
357 | ptd->faddr |= PTD_PR(ep->interval ? __ffs(ep->interval) : 0); | ||
358 | } | ||
359 | if (usb_pipeisoc(urb->pipe)) | ||
360 | ptd->faddr |= PTD_SF_ISO(fno); | ||
361 | |||
362 | DBG(1, "%s: Finished\n", __func__); | ||
363 | } | ||
364 | |||
365 | static void isp1362_write_ptd(struct isp1362_hcd *isp1362_hcd, struct isp1362_ep *ep, | ||
366 | struct isp1362_ep_queue *epq) | ||
367 | { | ||
368 | struct ptd *ptd = &ep->ptd; | ||
369 | int len = PTD_GET_DIR(ptd) == PTD_DIR_IN ? 0 : ep->length; | ||
370 | |||
371 | _BUG_ON(ep->ptd_offset < 0); | ||
372 | |||
373 | prefetch(ptd); | ||
374 | isp1362_write_buffer(isp1362_hcd, ptd, ep->ptd_offset, PTD_HEADER_SIZE); | ||
375 | if (len) | ||
376 | isp1362_write_buffer(isp1362_hcd, ep->data, | ||
377 | ep->ptd_offset + PTD_HEADER_SIZE, len); | ||
378 | |||
379 | dump_ptd(ptd); | ||
380 | dump_ptd_out_data(ptd, ep->data); | ||
381 | } | ||
382 | |||
383 | static void isp1362_read_ptd(struct isp1362_hcd *isp1362_hcd, struct isp1362_ep *ep, | ||
384 | struct isp1362_ep_queue *epq) | ||
385 | { | ||
386 | struct ptd *ptd = &ep->ptd; | ||
387 | int act_len; | ||
388 | |||
389 | WARN_ON(list_empty(&ep->active)); | ||
390 | BUG_ON(ep->ptd_offset < 0); | ||
391 | |||
392 | list_del_init(&ep->active); | ||
393 | DBG(1, "%s: ep %p removed from active list %p\n", __func__, ep, &epq->active); | ||
394 | |||
395 | prefetchw(ptd); | ||
396 | isp1362_read_buffer(isp1362_hcd, ptd, ep->ptd_offset, PTD_HEADER_SIZE); | ||
397 | dump_ptd(ptd); | ||
398 | act_len = PTD_GET_COUNT(ptd); | ||
399 | if (PTD_GET_DIR(ptd) != PTD_DIR_IN || act_len == 0) | ||
400 | return; | ||
401 | if (act_len > ep->length) | ||
402 | pr_err("%s: ep %p PTD $%04x act_len %d ep->length %d\n", __func__, ep, | ||
403 | ep->ptd_offset, act_len, ep->length); | ||
404 | BUG_ON(act_len > ep->length); | ||
405 | /* Only transfer the amount of data that has actually been overwritten | ||
406 | * in the chip buffer. We don't want any data that doesn't belong to the | ||
407 | * transfer to leak out of the chip to the callers transfer buffer! | ||
408 | */ | ||
409 | prefetchw(ep->data); | ||
410 | isp1362_read_buffer(isp1362_hcd, ep->data, | ||
411 | ep->ptd_offset + PTD_HEADER_SIZE, act_len); | ||
412 | dump_ptd_in_data(ptd, ep->data); | ||
413 | } | ||
414 | |||
415 | /* | ||
416 | * INT PTDs will stay in the chip until data is available. | ||
417 | * This function will remove a PTD from the chip when the URB is dequeued. | ||
418 | * Must be called with the spinlock held and IRQs disabled | ||
419 | */ | ||
420 | static void remove_ptd(struct isp1362_hcd *isp1362_hcd, struct isp1362_ep *ep) | ||
421 | |||
422 | { | ||
423 | int index; | ||
424 | struct isp1362_ep_queue *epq; | ||
425 | |||
426 | DBG(1, "%s: ep %p PTD[%d] $%04x\n", __func__, ep, ep->ptd_index, ep->ptd_offset); | ||
427 | BUG_ON(ep->ptd_offset < 0); | ||
428 | |||
429 | epq = get_ptd_queue(isp1362_hcd, ep->ptd_offset); | ||
430 | BUG_ON(!epq); | ||
431 | |||
432 | /* put ep in remove_list for cleanup */ | ||
433 | WARN_ON(!list_empty(&ep->remove_list)); | ||
434 | list_add_tail(&ep->remove_list, &isp1362_hcd->remove_list); | ||
435 | /* let SOF interrupt handle the cleanup */ | ||
436 | isp1362_enable_int(isp1362_hcd, HCuPINT_SOF); | ||
437 | |||
438 | index = ep->ptd_index; | ||
439 | if (index < 0) | ||
440 | /* ISO queues don't have SKIP registers */ | ||
441 | return; | ||
442 | |||
443 | DBG(1, "%s: Disabling PTD[%02x] $%04x %08lx|%08x\n", __func__, | ||
444 | index, ep->ptd_offset, epq->skip_map, 1 << index); | ||
445 | |||
446 | /* prevent further processing of PTD (will be effective after next SOF) */ | ||
447 | epq->skip_map |= 1 << index; | ||
448 | if (epq == &isp1362_hcd->atl_queue) { | ||
449 | DBG(2, "%s: ATLSKIP = %08x -> %08lx\n", __func__, | ||
450 | isp1362_read_reg32(isp1362_hcd, HCATLSKIP), epq->skip_map); | ||
451 | isp1362_write_reg32(isp1362_hcd, HCATLSKIP, epq->skip_map); | ||
452 | if (~epq->skip_map == 0) | ||
453 | isp1362_clr_mask16(isp1362_hcd, HCBUFSTAT, HCBUFSTAT_ATL_ACTIVE); | ||
454 | } else if (epq == &isp1362_hcd->intl_queue) { | ||
455 | DBG(2, "%s: INTLSKIP = %08x -> %08lx\n", __func__, | ||
456 | isp1362_read_reg32(isp1362_hcd, HCINTLSKIP), epq->skip_map); | ||
457 | isp1362_write_reg32(isp1362_hcd, HCINTLSKIP, epq->skip_map); | ||
458 | if (~epq->skip_map == 0) | ||
459 | isp1362_clr_mask16(isp1362_hcd, HCBUFSTAT, HCBUFSTAT_INTL_ACTIVE); | ||
460 | } | ||
461 | } | ||
462 | |||
463 | /* | ||
464 | Take done or failed requests out of schedule. Give back | ||
465 | processed urbs. | ||
466 | */ | ||
467 | static void finish_request(struct isp1362_hcd *isp1362_hcd, struct isp1362_ep *ep, | ||
468 | struct urb *urb, int status) | ||
469 | __releases(isp1362_hcd->lock) | ||
470 | __acquires(isp1362_hcd->lock) | ||
471 | { | ||
472 | urb->hcpriv = NULL; | ||
473 | ep->error_count = 0; | ||
474 | |||
475 | if (usb_pipecontrol(urb->pipe)) | ||
476 | ep->nextpid = USB_PID_SETUP; | ||
477 | |||
478 | URB_DBG("%s: req %d FA %d ep%d%s %s: len %d/%d %s stat %d\n", __func__, | ||
479 | ep->num_req, usb_pipedevice(urb->pipe), | ||
480 | usb_pipeendpoint(urb->pipe), | ||
481 | !usb_pipein(urb->pipe) ? "out" : "in", | ||
482 | usb_pipecontrol(urb->pipe) ? "ctrl" : | ||
483 | usb_pipeint(urb->pipe) ? "int" : | ||
484 | usb_pipebulk(urb->pipe) ? "bulk" : | ||
485 | "iso", | ||
486 | urb->actual_length, urb->transfer_buffer_length, | ||
487 | !(urb->transfer_flags & URB_SHORT_NOT_OK) ? | ||
488 | "short_ok" : "", urb->status); | ||
489 | |||
490 | |||
491 | usb_hcd_unlink_urb_from_ep(isp1362_hcd_to_hcd(isp1362_hcd), urb); | ||
492 | spin_unlock(&isp1362_hcd->lock); | ||
493 | usb_hcd_giveback_urb(isp1362_hcd_to_hcd(isp1362_hcd), urb, status); | ||
494 | spin_lock(&isp1362_hcd->lock); | ||
495 | |||
496 | /* take idle endpoints out of the schedule right away */ | ||
497 | if (!list_empty(&ep->hep->urb_list)) | ||
498 | return; | ||
499 | |||
500 | /* async deschedule */ | ||
501 | if (!list_empty(&ep->schedule)) { | ||
502 | list_del_init(&ep->schedule); | ||
503 | return; | ||
504 | } | ||
505 | |||
506 | |||
507 | if (ep->interval) { | ||
508 | /* periodic deschedule */ | ||
509 | DBG(1, "deschedule qh%d/%p branch %d load %d bandwidth %d -> %d\n", ep->interval, | ||
510 | ep, ep->branch, ep->load, | ||
511 | isp1362_hcd->load[ep->branch], | ||
512 | isp1362_hcd->load[ep->branch] - ep->load); | ||
513 | isp1362_hcd->load[ep->branch] -= ep->load; | ||
514 | ep->branch = PERIODIC_SIZE; | ||
515 | } | ||
516 | } | ||
517 | |||
518 | /* | ||
519 | * Analyze transfer results, handle partial transfers and errors | ||
520 | */ | ||
521 | static void postproc_ep(struct isp1362_hcd *isp1362_hcd, struct isp1362_ep *ep) | ||
522 | { | ||
523 | struct urb *urb = get_urb(ep); | ||
524 | struct usb_device *udev; | ||
525 | struct ptd *ptd; | ||
526 | int short_ok; | ||
527 | u16 len; | ||
528 | int urbstat = -EINPROGRESS; | ||
529 | u8 cc; | ||
530 | |||
531 | DBG(2, "%s: ep %p req %d\n", __func__, ep, ep->num_req); | ||
532 | |||
533 | udev = urb->dev; | ||
534 | ptd = &ep->ptd; | ||
535 | cc = PTD_GET_CC(ptd); | ||
536 | if (cc == PTD_NOTACCESSED) { | ||
537 | pr_err("%s: req %d PTD %p Untouched by ISP1362\n", __func__, | ||
538 | ep->num_req, ptd); | ||
539 | cc = PTD_DEVNOTRESP; | ||
540 | } | ||
541 | |||
542 | short_ok = !(urb->transfer_flags & URB_SHORT_NOT_OK); | ||
543 | len = urb->transfer_buffer_length - urb->actual_length; | ||
544 | |||
545 | /* Data underrun is special. For allowed underrun | ||
546 | we clear the error and continue as normal. For | ||
547 | forbidden underrun we finish the DATA stage | ||
548 | immediately while for control transfer, | ||
549 | we do a STATUS stage. | ||
550 | */ | ||
551 | if (cc == PTD_DATAUNDERRUN) { | ||
552 | if (short_ok) { | ||
553 | DBG(1, "%s: req %d Allowed data underrun short_%sok %d/%d/%d byte\n", | ||
554 | __func__, ep->num_req, short_ok ? "" : "not_", | ||
555 | PTD_GET_COUNT(ptd), ep->maxpacket, len); | ||
556 | cc = PTD_CC_NOERROR; | ||
557 | urbstat = 0; | ||
558 | } else { | ||
559 | DBG(1, "%s: req %d Data Underrun %s nextpid %02x short_%sok %d/%d/%d byte\n", | ||
560 | __func__, ep->num_req, | ||
561 | usb_pipein(urb->pipe) ? "IN" : "OUT", ep->nextpid, | ||
562 | short_ok ? "" : "not_", | ||
563 | PTD_GET_COUNT(ptd), ep->maxpacket, len); | ||
564 | if (usb_pipecontrol(urb->pipe)) { | ||
565 | ep->nextpid = USB_PID_ACK; | ||
566 | /* save the data underrun error code for later and | ||
567 | * procede with the status stage | ||
568 | */ | ||
569 | urb->actual_length += PTD_GET_COUNT(ptd); | ||
570 | BUG_ON(urb->actual_length > urb->transfer_buffer_length); | ||
571 | |||
572 | if (urb->status == -EINPROGRESS) | ||
573 | urb->status = cc_to_error[PTD_DATAUNDERRUN]; | ||
574 | } else { | ||
575 | usb_settoggle(udev, ep->epnum, ep->nextpid == USB_PID_OUT, | ||
576 | PTD_GET_TOGGLE(ptd)); | ||
577 | urbstat = cc_to_error[PTD_DATAUNDERRUN]; | ||
578 | } | ||
579 | goto out; | ||
580 | } | ||
581 | } | ||
582 | |||
583 | if (cc != PTD_CC_NOERROR) { | ||
584 | if (++ep->error_count >= 3 || cc == PTD_CC_STALL || cc == PTD_DATAOVERRUN) { | ||
585 | urbstat = cc_to_error[cc]; | ||
586 | DBG(1, "%s: req %d nextpid %02x, status %d, error %d, error_count %d\n", | ||
587 | __func__, ep->num_req, ep->nextpid, urbstat, cc, | ||
588 | ep->error_count); | ||
589 | } | ||
590 | goto out; | ||
591 | } | ||
592 | |||
593 | switch (ep->nextpid) { | ||
594 | case USB_PID_OUT: | ||
595 | if (PTD_GET_COUNT(ptd) != ep->length) | ||
596 | pr_err("%s: count=%d len=%d\n", __func__, | ||
597 | PTD_GET_COUNT(ptd), ep->length); | ||
598 | BUG_ON(PTD_GET_COUNT(ptd) != ep->length); | ||
599 | urb->actual_length += ep->length; | ||
600 | BUG_ON(urb->actual_length > urb->transfer_buffer_length); | ||
601 | usb_settoggle(udev, ep->epnum, 1, PTD_GET_TOGGLE(ptd)); | ||
602 | if (urb->actual_length == urb->transfer_buffer_length) { | ||
603 | DBG(3, "%s: req %d xfer complete %d/%d status %d -> 0\n", __func__, | ||
604 | ep->num_req, len, ep->maxpacket, urbstat); | ||
605 | if (usb_pipecontrol(urb->pipe)) { | ||
606 | DBG(3, "%s: req %d %s Wait for ACK\n", __func__, | ||
607 | ep->num_req, | ||
608 | usb_pipein(urb->pipe) ? "IN" : "OUT"); | ||
609 | ep->nextpid = USB_PID_ACK; | ||
610 | } else { | ||
611 | if (len % ep->maxpacket || | ||
612 | !(urb->transfer_flags & URB_ZERO_PACKET)) { | ||
613 | urbstat = 0; | ||
614 | DBG(3, "%s: req %d URB %s status %d count %d/%d/%d\n", | ||
615 | __func__, ep->num_req, usb_pipein(urb->pipe) ? "IN" : "OUT", | ||
616 | urbstat, len, ep->maxpacket, urb->actual_length); | ||
617 | } | ||
618 | } | ||
619 | } | ||
620 | break; | ||
621 | case USB_PID_IN: | ||
622 | len = PTD_GET_COUNT(ptd); | ||
623 | BUG_ON(len > ep->length); | ||
624 | urb->actual_length += len; | ||
625 | BUG_ON(urb->actual_length > urb->transfer_buffer_length); | ||
626 | usb_settoggle(udev, ep->epnum, 0, PTD_GET_TOGGLE(ptd)); | ||
627 | /* if transfer completed or (allowed) data underrun */ | ||
628 | if ((urb->transfer_buffer_length == urb->actual_length) || | ||
629 | len % ep->maxpacket) { | ||
630 | DBG(3, "%s: req %d xfer complete %d/%d status %d -> 0\n", __func__, | ||
631 | ep->num_req, len, ep->maxpacket, urbstat); | ||
632 | if (usb_pipecontrol(urb->pipe)) { | ||
633 | DBG(3, "%s: req %d %s Wait for ACK\n", __func__, | ||
634 | ep->num_req, | ||
635 | usb_pipein(urb->pipe) ? "IN" : "OUT"); | ||
636 | ep->nextpid = USB_PID_ACK; | ||
637 | } else { | ||
638 | urbstat = 0; | ||
639 | DBG(3, "%s: req %d URB %s status %d count %d/%d/%d\n", | ||
640 | __func__, ep->num_req, usb_pipein(urb->pipe) ? "IN" : "OUT", | ||
641 | urbstat, len, ep->maxpacket, urb->actual_length); | ||
642 | } | ||
643 | } | ||
644 | break; | ||
645 | case USB_PID_SETUP: | ||
646 | if (urb->transfer_buffer_length == urb->actual_length) { | ||
647 | ep->nextpid = USB_PID_ACK; | ||
648 | } else if (usb_pipeout(urb->pipe)) { | ||
649 | usb_settoggle(udev, 0, 1, 1); | ||
650 | ep->nextpid = USB_PID_OUT; | ||
651 | } else { | ||
652 | usb_settoggle(udev, 0, 0, 1); | ||
653 | ep->nextpid = USB_PID_IN; | ||
654 | } | ||
655 | break; | ||
656 | case USB_PID_ACK: | ||
657 | DBG(3, "%s: req %d got ACK %d -> 0\n", __func__, ep->num_req, | ||
658 | urbstat); | ||
659 | WARN_ON(urbstat != -EINPROGRESS); | ||
660 | urbstat = 0; | ||
661 | ep->nextpid = 0; | ||
662 | break; | ||
663 | default: | ||
664 | BUG_ON(1); | ||
665 | } | ||
666 | |||
667 | out: | ||
668 | if (urbstat != -EINPROGRESS) { | ||
669 | DBG(2, "%s: Finishing ep %p req %d urb %p status %d\n", __func__, | ||
670 | ep, ep->num_req, urb, urbstat); | ||
671 | finish_request(isp1362_hcd, ep, urb, urbstat); | ||
672 | } | ||
673 | } | ||
674 | |||
675 | static void finish_unlinks(struct isp1362_hcd *isp1362_hcd) | ||
676 | { | ||
677 | struct isp1362_ep *ep; | ||
678 | struct isp1362_ep *tmp; | ||
679 | |||
680 | list_for_each_entry_safe(ep, tmp, &isp1362_hcd->remove_list, remove_list) { | ||
681 | struct isp1362_ep_queue *epq = | ||
682 | get_ptd_queue(isp1362_hcd, ep->ptd_offset); | ||
683 | int index = ep->ptd_index; | ||
684 | |||
685 | BUG_ON(epq == NULL); | ||
686 | if (index >= 0) { | ||
687 | DBG(1, "%s: remove PTD[%d] $%04x\n", __func__, index, ep->ptd_offset); | ||
688 | BUG_ON(ep->num_ptds == 0); | ||
689 | release_ptd_buffers(epq, ep); | ||
690 | } | ||
691 | if (!list_empty(&ep->hep->urb_list)) { | ||
692 | struct urb *urb = get_urb(ep); | ||
693 | |||
694 | DBG(1, "%s: Finishing req %d ep %p from remove_list\n", __func__, | ||
695 | ep->num_req, ep); | ||
696 | finish_request(isp1362_hcd, ep, urb, -ESHUTDOWN); | ||
697 | } | ||
698 | WARN_ON(list_empty(&ep->active)); | ||
699 | if (!list_empty(&ep->active)) { | ||
700 | list_del_init(&ep->active); | ||
701 | DBG(1, "%s: ep %p removed from active list\n", __func__, ep); | ||
702 | } | ||
703 | list_del_init(&ep->remove_list); | ||
704 | DBG(1, "%s: ep %p removed from remove_list\n", __func__, ep); | ||
705 | } | ||
706 | DBG(1, "%s: Done\n", __func__); | ||
707 | } | ||
708 | |||
709 | static inline void enable_atl_transfers(struct isp1362_hcd *isp1362_hcd, int count) | ||
710 | { | ||
711 | if (count > 0) { | ||
712 | if (count < isp1362_hcd->atl_queue.ptd_count) | ||
713 | isp1362_write_reg16(isp1362_hcd, HCATLDTC, count); | ||
714 | isp1362_enable_int(isp1362_hcd, HCuPINT_ATL); | ||
715 | isp1362_write_reg32(isp1362_hcd, HCATLSKIP, isp1362_hcd->atl_queue.skip_map); | ||
716 | isp1362_set_mask16(isp1362_hcd, HCBUFSTAT, HCBUFSTAT_ATL_ACTIVE); | ||
717 | } else | ||
718 | isp1362_enable_int(isp1362_hcd, HCuPINT_SOF); | ||
719 | } | ||
720 | |||
721 | static inline void enable_intl_transfers(struct isp1362_hcd *isp1362_hcd) | ||
722 | { | ||
723 | isp1362_enable_int(isp1362_hcd, HCuPINT_INTL); | ||
724 | isp1362_set_mask16(isp1362_hcd, HCBUFSTAT, HCBUFSTAT_INTL_ACTIVE); | ||
725 | isp1362_write_reg32(isp1362_hcd, HCINTLSKIP, isp1362_hcd->intl_queue.skip_map); | ||
726 | } | ||
727 | |||
728 | static inline void enable_istl_transfers(struct isp1362_hcd *isp1362_hcd, int flip) | ||
729 | { | ||
730 | isp1362_enable_int(isp1362_hcd, flip ? HCuPINT_ISTL1 : HCuPINT_ISTL0); | ||
731 | isp1362_set_mask16(isp1362_hcd, HCBUFSTAT, flip ? | ||
732 | HCBUFSTAT_ISTL1_FULL : HCBUFSTAT_ISTL0_FULL); | ||
733 | } | ||
734 | |||
735 | static int submit_req(struct isp1362_hcd *isp1362_hcd, struct urb *urb, | ||
736 | struct isp1362_ep *ep, struct isp1362_ep_queue *epq) | ||
737 | { | ||
738 | int index = epq->free_ptd; | ||
739 | |||
740 | prepare_ptd(isp1362_hcd, urb, ep, epq, 0); | ||
741 | index = claim_ptd_buffers(epq, ep, ep->length); | ||
742 | if (index == -ENOMEM) { | ||
743 | DBG(1, "%s: req %d No free %s PTD available: %d, %08lx:%08lx\n", __func__, | ||
744 | ep->num_req, epq->name, ep->num_ptds, epq->buf_map, epq->skip_map); | ||
745 | return index; | ||
746 | } else if (index == -EOVERFLOW) { | ||
747 | DBG(1, "%s: req %d Not enough space for %d byte %s PTD %d %08lx:%08lx\n", | ||
748 | __func__, ep->num_req, ep->length, epq->name, ep->num_ptds, | ||
749 | epq->buf_map, epq->skip_map); | ||
750 | return index; | ||
751 | } else | ||
752 | BUG_ON(index < 0); | ||
753 | list_add_tail(&ep->active, &epq->active); | ||
754 | DBG(1, "%s: ep %p req %d len %d added to active list %p\n", __func__, | ||
755 | ep, ep->num_req, ep->length, &epq->active); | ||
756 | DBG(1, "%s: Submitting %s PTD $%04x for ep %p req %d\n", __func__, epq->name, | ||
757 | ep->ptd_offset, ep, ep->num_req); | ||
758 | isp1362_write_ptd(isp1362_hcd, ep, epq); | ||
759 | __clear_bit(ep->ptd_index, &epq->skip_map); | ||
760 | |||
761 | return 0; | ||
762 | } | ||
763 | |||
764 | static void start_atl_transfers(struct isp1362_hcd *isp1362_hcd) | ||
765 | { | ||
766 | int ptd_count = 0; | ||
767 | struct isp1362_ep_queue *epq = &isp1362_hcd->atl_queue; | ||
768 | struct isp1362_ep *ep; | ||
769 | int defer = 0; | ||
770 | |||
771 | if (atomic_read(&epq->finishing)) { | ||
772 | DBG(1, "%s: finish_transfers is active for %s\n", __func__, epq->name); | ||
773 | return; | ||
774 | } | ||
775 | |||
776 | list_for_each_entry(ep, &isp1362_hcd->async, schedule) { | ||
777 | struct urb *urb = get_urb(ep); | ||
778 | int ret; | ||
779 | |||
780 | if (!list_empty(&ep->active)) { | ||
781 | DBG(2, "%s: Skipping active %s ep %p\n", __func__, epq->name, ep); | ||
782 | continue; | ||
783 | } | ||
784 | |||
785 | DBG(1, "%s: Processing %s ep %p req %d\n", __func__, epq->name, | ||
786 | ep, ep->num_req); | ||
787 | |||
788 | ret = submit_req(isp1362_hcd, urb, ep, epq); | ||
789 | if (ret == -ENOMEM) { | ||
790 | defer = 1; | ||
791 | break; | ||
792 | } else if (ret == -EOVERFLOW) { | ||
793 | defer = 1; | ||
794 | continue; | ||
795 | } | ||
796 | #ifdef BUGGY_PXA2XX_UDC_USBTEST | ||
797 | defer = ep->nextpid == USB_PID_SETUP; | ||
798 | #endif | ||
799 | ptd_count++; | ||
800 | } | ||
801 | |||
802 | /* Avoid starving of endpoints */ | ||
803 | if (isp1362_hcd->async.next != isp1362_hcd->async.prev) { | ||
804 | DBG(2, "%s: Cycling ASYNC schedule %d\n", __func__, ptd_count); | ||
805 | list_move(&isp1362_hcd->async, isp1362_hcd->async.next); | ||
806 | } | ||
807 | if (ptd_count || defer) | ||
808 | enable_atl_transfers(isp1362_hcd, defer ? 0 : ptd_count); | ||
809 | |||
810 | epq->ptd_count += ptd_count; | ||
811 | if (epq->ptd_count > epq->stat_maxptds) { | ||
812 | epq->stat_maxptds = epq->ptd_count; | ||
813 | DBG(0, "%s: max_ptds: %d\n", __func__, epq->stat_maxptds); | ||
814 | } | ||
815 | } | ||
816 | |||
817 | static void start_intl_transfers(struct isp1362_hcd *isp1362_hcd) | ||
818 | { | ||
819 | int ptd_count = 0; | ||
820 | struct isp1362_ep_queue *epq = &isp1362_hcd->intl_queue; | ||
821 | struct isp1362_ep *ep; | ||
822 | |||
823 | if (atomic_read(&epq->finishing)) { | ||
824 | DBG(1, "%s: finish_transfers is active for %s\n", __func__, epq->name); | ||
825 | return; | ||
826 | } | ||
827 | |||
828 | list_for_each_entry(ep, &isp1362_hcd->periodic, schedule) { | ||
829 | struct urb *urb = get_urb(ep); | ||
830 | int ret; | ||
831 | |||
832 | if (!list_empty(&ep->active)) { | ||
833 | DBG(1, "%s: Skipping active %s ep %p\n", __func__, | ||
834 | epq->name, ep); | ||
835 | continue; | ||
836 | } | ||
837 | |||
838 | DBG(1, "%s: Processing %s ep %p req %d\n", __func__, | ||
839 | epq->name, ep, ep->num_req); | ||
840 | ret = submit_req(isp1362_hcd, urb, ep, epq); | ||
841 | if (ret == -ENOMEM) | ||
842 | break; | ||
843 | else if (ret == -EOVERFLOW) | ||
844 | continue; | ||
845 | ptd_count++; | ||
846 | } | ||
847 | |||
848 | if (ptd_count) { | ||
849 | static int last_count; | ||
850 | |||
851 | if (ptd_count != last_count) { | ||
852 | DBG(0, "%s: ptd_count: %d\n", __func__, ptd_count); | ||
853 | last_count = ptd_count; | ||
854 | } | ||
855 | enable_intl_transfers(isp1362_hcd); | ||
856 | } | ||
857 | |||
858 | epq->ptd_count += ptd_count; | ||
859 | if (epq->ptd_count > epq->stat_maxptds) | ||
860 | epq->stat_maxptds = epq->ptd_count; | ||
861 | } | ||
862 | |||
863 | static inline int next_ptd(struct isp1362_ep_queue *epq, struct isp1362_ep *ep) | ||
864 | { | ||
865 | u16 ptd_offset = ep->ptd_offset; | ||
866 | int num_ptds = (ep->length + PTD_HEADER_SIZE + (epq->blk_size - 1)) / epq->blk_size; | ||
867 | |||
868 | DBG(2, "%s: PTD offset $%04x + %04x => %d * %04x -> $%04x\n", __func__, ptd_offset, | ||
869 | ep->length, num_ptds, epq->blk_size, ptd_offset + num_ptds * epq->blk_size); | ||
870 | |||
871 | ptd_offset += num_ptds * epq->blk_size; | ||
872 | if (ptd_offset < epq->buf_start + epq->buf_size) | ||
873 | return ptd_offset; | ||
874 | else | ||
875 | return -ENOMEM; | ||
876 | } | ||
877 | |||
878 | static void start_iso_transfers(struct isp1362_hcd *isp1362_hcd) | ||
879 | { | ||
880 | int ptd_count = 0; | ||
881 | int flip = isp1362_hcd->istl_flip; | ||
882 | struct isp1362_ep_queue *epq; | ||
883 | int ptd_offset; | ||
884 | struct isp1362_ep *ep; | ||
885 | struct isp1362_ep *tmp; | ||
886 | u16 fno = isp1362_read_reg32(isp1362_hcd, HCFMNUM); | ||
887 | |||
888 | fill2: | ||
889 | epq = &isp1362_hcd->istl_queue[flip]; | ||
890 | if (atomic_read(&epq->finishing)) { | ||
891 | DBG(1, "%s: finish_transfers is active for %s\n", __func__, epq->name); | ||
892 | return; | ||
893 | } | ||
894 | |||
895 | if (!list_empty(&epq->active)) | ||
896 | return; | ||
897 | |||
898 | ptd_offset = epq->buf_start; | ||
899 | list_for_each_entry_safe(ep, tmp, &isp1362_hcd->isoc, schedule) { | ||
900 | struct urb *urb = get_urb(ep); | ||
901 | s16 diff = fno - (u16)urb->start_frame; | ||
902 | |||
903 | DBG(1, "%s: Processing %s ep %p\n", __func__, epq->name, ep); | ||
904 | |||
905 | if (diff > urb->number_of_packets) { | ||
906 | /* time frame for this URB has elapsed */ | ||
907 | finish_request(isp1362_hcd, ep, urb, -EOVERFLOW); | ||
908 | continue; | ||
909 | } else if (diff < -1) { | ||
910 | /* URB is not due in this frame or the next one. | ||
911 | * Comparing with '-1' instead of '0' accounts for double | ||
912 | * buffering in the ISP1362 which enables us to queue the PTD | ||
913 | * one frame ahead of time | ||
914 | */ | ||
915 | } else if (diff == -1) { | ||
916 | /* submit PTD's that are due in the next frame */ | ||
917 | prepare_ptd(isp1362_hcd, urb, ep, epq, fno); | ||
918 | if (ptd_offset + PTD_HEADER_SIZE + ep->length > | ||
919 | epq->buf_start + epq->buf_size) { | ||
920 | pr_err("%s: Not enough ISO buffer space for %d byte PTD\n", | ||
921 | __func__, ep->length); | ||
922 | continue; | ||
923 | } | ||
924 | ep->ptd_offset = ptd_offset; | ||
925 | list_add_tail(&ep->active, &epq->active); | ||
926 | |||
927 | ptd_offset = next_ptd(epq, ep); | ||
928 | if (ptd_offset < 0) { | ||
929 | pr_warning("%s: req %d No more %s PTD buffers available\n", __func__, | ||
930 | ep->num_req, epq->name); | ||
931 | break; | ||
932 | } | ||
933 | } | ||
934 | } | ||
935 | list_for_each_entry(ep, &epq->active, active) { | ||
936 | if (epq->active.next == &ep->active) | ||
937 | ep->ptd.mps |= PTD_LAST_MSK; | ||
938 | isp1362_write_ptd(isp1362_hcd, ep, epq); | ||
939 | ptd_count++; | ||
940 | } | ||
941 | |||
942 | if (ptd_count) | ||
943 | enable_istl_transfers(isp1362_hcd, flip); | ||
944 | |||
945 | epq->ptd_count += ptd_count; | ||
946 | if (epq->ptd_count > epq->stat_maxptds) | ||
947 | epq->stat_maxptds = epq->ptd_count; | ||
948 | |||
949 | /* check, whether the second ISTL buffer may also be filled */ | ||
950 | if (!(isp1362_read_reg16(isp1362_hcd, HCBUFSTAT) & | ||
951 | (flip ? HCBUFSTAT_ISTL0_FULL : HCBUFSTAT_ISTL1_FULL))) { | ||
952 | fno++; | ||
953 | ptd_count = 0; | ||
954 | flip = 1 - flip; | ||
955 | goto fill2; | ||
956 | } | ||
957 | } | ||
958 | |||
959 | static void finish_transfers(struct isp1362_hcd *isp1362_hcd, unsigned long done_map, | ||
960 | struct isp1362_ep_queue *epq) | ||
961 | { | ||
962 | struct isp1362_ep *ep; | ||
963 | struct isp1362_ep *tmp; | ||
964 | |||
965 | if (list_empty(&epq->active)) { | ||
966 | DBG(1, "%s: Nothing to do for %s queue\n", __func__, epq->name); | ||
967 | return; | ||
968 | } | ||
969 | |||
970 | DBG(1, "%s: Finishing %s transfers %08lx\n", __func__, epq->name, done_map); | ||
971 | |||
972 | atomic_inc(&epq->finishing); | ||
973 | list_for_each_entry_safe(ep, tmp, &epq->active, active) { | ||
974 | int index = ep->ptd_index; | ||
975 | |||
976 | DBG(1, "%s: Checking %s PTD[%02x] $%04x\n", __func__, epq->name, | ||
977 | index, ep->ptd_offset); | ||
978 | |||
979 | BUG_ON(index < 0); | ||
980 | if (__test_and_clear_bit(index, &done_map)) { | ||
981 | isp1362_read_ptd(isp1362_hcd, ep, epq); | ||
982 | epq->free_ptd = index; | ||
983 | BUG_ON(ep->num_ptds == 0); | ||
984 | release_ptd_buffers(epq, ep); | ||
985 | |||
986 | DBG(1, "%s: ep %p req %d removed from active list\n", __func__, | ||
987 | ep, ep->num_req); | ||
988 | if (!list_empty(&ep->remove_list)) { | ||
989 | list_del_init(&ep->remove_list); | ||
990 | DBG(1, "%s: ep %p removed from remove list\n", __func__, ep); | ||
991 | } | ||
992 | DBG(1, "%s: Postprocessing %s ep %p req %d\n", __func__, epq->name, | ||
993 | ep, ep->num_req); | ||
994 | postproc_ep(isp1362_hcd, ep); | ||
995 | } | ||
996 | if (!done_map) | ||
997 | break; | ||
998 | } | ||
999 | if (done_map) | ||
1000 | pr_warning("%s: done_map not clear: %08lx:%08lx\n", __func__, done_map, | ||
1001 | epq->skip_map); | ||
1002 | atomic_dec(&epq->finishing); | ||
1003 | } | ||
1004 | |||
1005 | static void finish_iso_transfers(struct isp1362_hcd *isp1362_hcd, struct isp1362_ep_queue *epq) | ||
1006 | { | ||
1007 | struct isp1362_ep *ep; | ||
1008 | struct isp1362_ep *tmp; | ||
1009 | |||
1010 | if (list_empty(&epq->active)) { | ||
1011 | DBG(1, "%s: Nothing to do for %s queue\n", __func__, epq->name); | ||
1012 | return; | ||
1013 | } | ||
1014 | |||
1015 | DBG(1, "%s: Finishing %s transfers\n", __func__, epq->name); | ||
1016 | |||
1017 | atomic_inc(&epq->finishing); | ||
1018 | list_for_each_entry_safe(ep, tmp, &epq->active, active) { | ||
1019 | DBG(1, "%s: Checking PTD $%04x\n", __func__, ep->ptd_offset); | ||
1020 | |||
1021 | isp1362_read_ptd(isp1362_hcd, ep, epq); | ||
1022 | DBG(1, "%s: Postprocessing %s ep %p\n", __func__, epq->name, ep); | ||
1023 | postproc_ep(isp1362_hcd, ep); | ||
1024 | } | ||
1025 | WARN_ON(epq->blk_size != 0); | ||
1026 | atomic_dec(&epq->finishing); | ||
1027 | } | ||
1028 | |||
1029 | static irqreturn_t isp1362_irq(struct usb_hcd *hcd) | ||
1030 | { | ||
1031 | int handled = 0; | ||
1032 | struct isp1362_hcd *isp1362_hcd = hcd_to_isp1362_hcd(hcd); | ||
1033 | u16 irqstat; | ||
1034 | u16 svc_mask; | ||
1035 | |||
1036 | spin_lock(&isp1362_hcd->lock); | ||
1037 | |||
1038 | BUG_ON(isp1362_hcd->irq_active++); | ||
1039 | |||
1040 | isp1362_write_reg16(isp1362_hcd, HCuPINTENB, 0); | ||
1041 | |||
1042 | irqstat = isp1362_read_reg16(isp1362_hcd, HCuPINT); | ||
1043 | DBG(3, "%s: got IRQ %04x:%04x\n", __func__, irqstat, isp1362_hcd->irqenb); | ||
1044 | |||
1045 | /* only handle interrupts that are currently enabled */ | ||
1046 | irqstat &= isp1362_hcd->irqenb; | ||
1047 | isp1362_write_reg16(isp1362_hcd, HCuPINT, irqstat); | ||
1048 | svc_mask = irqstat; | ||
1049 | |||
1050 | if (irqstat & HCuPINT_SOF) { | ||
1051 | isp1362_hcd->irqenb &= ~HCuPINT_SOF; | ||
1052 | isp1362_hcd->irq_stat[ISP1362_INT_SOF]++; | ||
1053 | handled = 1; | ||
1054 | svc_mask &= ~HCuPINT_SOF; | ||
1055 | DBG(3, "%s: SOF\n", __func__); | ||
1056 | isp1362_hcd->fmindex = isp1362_read_reg32(isp1362_hcd, HCFMNUM); | ||
1057 | if (!list_empty(&isp1362_hcd->remove_list)) | ||
1058 | finish_unlinks(isp1362_hcd); | ||
1059 | if (!list_empty(&isp1362_hcd->async) && !(irqstat & HCuPINT_ATL)) { | ||
1060 | if (list_empty(&isp1362_hcd->atl_queue.active)) { | ||
1061 | start_atl_transfers(isp1362_hcd); | ||
1062 | } else { | ||
1063 | isp1362_enable_int(isp1362_hcd, HCuPINT_ATL); | ||
1064 | isp1362_write_reg32(isp1362_hcd, HCATLSKIP, | ||
1065 | isp1362_hcd->atl_queue.skip_map); | ||
1066 | isp1362_set_mask16(isp1362_hcd, HCBUFSTAT, HCBUFSTAT_ATL_ACTIVE); | ||
1067 | } | ||
1068 | } | ||
1069 | } | ||
1070 | |||
1071 | if (irqstat & HCuPINT_ISTL0) { | ||
1072 | isp1362_hcd->irq_stat[ISP1362_INT_ISTL0]++; | ||
1073 | handled = 1; | ||
1074 | svc_mask &= ~HCuPINT_ISTL0; | ||
1075 | isp1362_clr_mask16(isp1362_hcd, HCBUFSTAT, HCBUFSTAT_ISTL0_FULL); | ||
1076 | DBG(1, "%s: ISTL0\n", __func__); | ||
1077 | WARN_ON((int)!!isp1362_hcd->istl_flip); | ||
1078 | WARN_ON(isp1362_read_reg16(isp1362_hcd, HCBUFSTAT) & | ||
1079 | HCBUFSTAT_ISTL0_ACTIVE); | ||
1080 | WARN_ON(!(isp1362_read_reg16(isp1362_hcd, HCBUFSTAT) & | ||
1081 | HCBUFSTAT_ISTL0_DONE)); | ||
1082 | isp1362_hcd->irqenb &= ~HCuPINT_ISTL0; | ||
1083 | } | ||
1084 | |||
1085 | if (irqstat & HCuPINT_ISTL1) { | ||
1086 | isp1362_hcd->irq_stat[ISP1362_INT_ISTL1]++; | ||
1087 | handled = 1; | ||
1088 | svc_mask &= ~HCuPINT_ISTL1; | ||
1089 | isp1362_clr_mask16(isp1362_hcd, HCBUFSTAT, HCBUFSTAT_ISTL1_FULL); | ||
1090 | DBG(1, "%s: ISTL1\n", __func__); | ||
1091 | WARN_ON(!(int)isp1362_hcd->istl_flip); | ||
1092 | WARN_ON(isp1362_read_reg16(isp1362_hcd, HCBUFSTAT) & | ||
1093 | HCBUFSTAT_ISTL1_ACTIVE); | ||
1094 | WARN_ON(!(isp1362_read_reg16(isp1362_hcd, HCBUFSTAT) & | ||
1095 | HCBUFSTAT_ISTL1_DONE)); | ||
1096 | isp1362_hcd->irqenb &= ~HCuPINT_ISTL1; | ||
1097 | } | ||
1098 | |||
1099 | if (irqstat & (HCuPINT_ISTL0 | HCuPINT_ISTL1)) { | ||
1100 | WARN_ON((irqstat & (HCuPINT_ISTL0 | HCuPINT_ISTL1)) == | ||
1101 | (HCuPINT_ISTL0 | HCuPINT_ISTL1)); | ||
1102 | finish_iso_transfers(isp1362_hcd, | ||
1103 | &isp1362_hcd->istl_queue[isp1362_hcd->istl_flip]); | ||
1104 | start_iso_transfers(isp1362_hcd); | ||
1105 | isp1362_hcd->istl_flip = 1 - isp1362_hcd->istl_flip; | ||
1106 | } | ||
1107 | |||
1108 | if (irqstat & HCuPINT_INTL) { | ||
1109 | u32 done_map = isp1362_read_reg32(isp1362_hcd, HCINTLDONE); | ||
1110 | u32 skip_map = isp1362_read_reg32(isp1362_hcd, HCINTLSKIP); | ||
1111 | isp1362_hcd->irq_stat[ISP1362_INT_INTL]++; | ||
1112 | |||
1113 | DBG(2, "%s: INTL\n", __func__); | ||
1114 | |||
1115 | svc_mask &= ~HCuPINT_INTL; | ||
1116 | |||
1117 | isp1362_write_reg32(isp1362_hcd, HCINTLSKIP, skip_map | done_map); | ||
1118 | if (~(done_map | skip_map) == 0) | ||
1119 | /* All PTDs are finished, disable INTL processing entirely */ | ||
1120 | isp1362_clr_mask16(isp1362_hcd, HCBUFSTAT, HCBUFSTAT_INTL_ACTIVE); | ||
1121 | |||
1122 | handled = 1; | ||
1123 | WARN_ON(!done_map); | ||
1124 | if (done_map) { | ||
1125 | DBG(3, "%s: INTL done_map %08x\n", __func__, done_map); | ||
1126 | finish_transfers(isp1362_hcd, done_map, &isp1362_hcd->intl_queue); | ||
1127 | start_intl_transfers(isp1362_hcd); | ||
1128 | } | ||
1129 | } | ||
1130 | |||
1131 | if (irqstat & HCuPINT_ATL) { | ||
1132 | u32 done_map = isp1362_read_reg32(isp1362_hcd, HCATLDONE); | ||
1133 | u32 skip_map = isp1362_read_reg32(isp1362_hcd, HCATLSKIP); | ||
1134 | isp1362_hcd->irq_stat[ISP1362_INT_ATL]++; | ||
1135 | |||
1136 | DBG(2, "%s: ATL\n", __func__); | ||
1137 | |||
1138 | svc_mask &= ~HCuPINT_ATL; | ||
1139 | |||
1140 | isp1362_write_reg32(isp1362_hcd, HCATLSKIP, skip_map | done_map); | ||
1141 | if (~(done_map | skip_map) == 0) | ||
1142 | isp1362_clr_mask16(isp1362_hcd, HCBUFSTAT, HCBUFSTAT_ATL_ACTIVE); | ||
1143 | if (done_map) { | ||
1144 | DBG(3, "%s: ATL done_map %08x\n", __func__, done_map); | ||
1145 | finish_transfers(isp1362_hcd, done_map, &isp1362_hcd->atl_queue); | ||
1146 | start_atl_transfers(isp1362_hcd); | ||
1147 | } | ||
1148 | handled = 1; | ||
1149 | } | ||
1150 | |||
1151 | if (irqstat & HCuPINT_OPR) { | ||
1152 | u32 intstat = isp1362_read_reg32(isp1362_hcd, HCINTSTAT); | ||
1153 | isp1362_hcd->irq_stat[ISP1362_INT_OPR]++; | ||
1154 | |||
1155 | svc_mask &= ~HCuPINT_OPR; | ||
1156 | DBG(2, "%s: OPR %08x:%08x\n", __func__, intstat, isp1362_hcd->intenb); | ||
1157 | intstat &= isp1362_hcd->intenb; | ||
1158 | if (intstat & OHCI_INTR_UE) { | ||
1159 | pr_err("Unrecoverable error\n"); | ||
1160 | /* FIXME: do here reset or cleanup or whatever */ | ||
1161 | } | ||
1162 | if (intstat & OHCI_INTR_RHSC) { | ||
1163 | isp1362_hcd->rhstatus = isp1362_read_reg32(isp1362_hcd, HCRHSTATUS); | ||
1164 | isp1362_hcd->rhport[0] = isp1362_read_reg32(isp1362_hcd, HCRHPORT1); | ||
1165 | isp1362_hcd->rhport[1] = isp1362_read_reg32(isp1362_hcd, HCRHPORT2); | ||
1166 | } | ||
1167 | if (intstat & OHCI_INTR_RD) { | ||
1168 | pr_info("%s: RESUME DETECTED\n", __func__); | ||
1169 | isp1362_show_reg(isp1362_hcd, HCCONTROL); | ||
1170 | usb_hcd_resume_root_hub(hcd); | ||
1171 | } | ||
1172 | isp1362_write_reg32(isp1362_hcd, HCINTSTAT, intstat); | ||
1173 | irqstat &= ~HCuPINT_OPR; | ||
1174 | handled = 1; | ||
1175 | } | ||
1176 | |||
1177 | if (irqstat & HCuPINT_SUSP) { | ||
1178 | isp1362_hcd->irq_stat[ISP1362_INT_SUSP]++; | ||
1179 | handled = 1; | ||
1180 | svc_mask &= ~HCuPINT_SUSP; | ||
1181 | |||
1182 | pr_info("%s: SUSPEND IRQ\n", __func__); | ||
1183 | } | ||
1184 | |||
1185 | if (irqstat & HCuPINT_CLKRDY) { | ||
1186 | isp1362_hcd->irq_stat[ISP1362_INT_CLKRDY]++; | ||
1187 | handled = 1; | ||
1188 | isp1362_hcd->irqenb &= ~HCuPINT_CLKRDY; | ||
1189 | svc_mask &= ~HCuPINT_CLKRDY; | ||
1190 | pr_info("%s: CLKRDY IRQ\n", __func__); | ||
1191 | } | ||
1192 | |||
1193 | if (svc_mask) | ||
1194 | pr_err("%s: Unserviced interrupt(s) %04x\n", __func__, svc_mask); | ||
1195 | |||
1196 | isp1362_write_reg16(isp1362_hcd, HCuPINTENB, isp1362_hcd->irqenb); | ||
1197 | isp1362_hcd->irq_active--; | ||
1198 | spin_unlock(&isp1362_hcd->lock); | ||
1199 | |||
1200 | return IRQ_RETVAL(handled); | ||
1201 | } | ||
1202 | |||
1203 | /*-------------------------------------------------------------------------*/ | ||
1204 | |||
1205 | #define MAX_PERIODIC_LOAD 900 /* out of 1000 usec */ | ||
1206 | static int balance(struct isp1362_hcd *isp1362_hcd, u16 interval, u16 load) | ||
1207 | { | ||
1208 | int i, branch = -ENOSPC; | ||
1209 | |||
1210 | /* search for the least loaded schedule branch of that interval | ||
1211 | * which has enough bandwidth left unreserved. | ||
1212 | */ | ||
1213 | for (i = 0; i < interval; i++) { | ||
1214 | if (branch < 0 || isp1362_hcd->load[branch] > isp1362_hcd->load[i]) { | ||
1215 | int j; | ||
1216 | |||
1217 | for (j = i; j < PERIODIC_SIZE; j += interval) { | ||
1218 | if ((isp1362_hcd->load[j] + load) > MAX_PERIODIC_LOAD) { | ||
1219 | pr_err("%s: new load %d load[%02x] %d max %d\n", __func__, | ||
1220 | load, j, isp1362_hcd->load[j], MAX_PERIODIC_LOAD); | ||
1221 | break; | ||
1222 | } | ||
1223 | } | ||
1224 | if (j < PERIODIC_SIZE) | ||
1225 | continue; | ||
1226 | branch = i; | ||
1227 | } | ||
1228 | } | ||
1229 | return branch; | ||
1230 | } | ||
1231 | |||
1232 | /* NB! ALL the code above this point runs with isp1362_hcd->lock | ||
1233 | held, irqs off | ||
1234 | */ | ||
1235 | |||
1236 | /*-------------------------------------------------------------------------*/ | ||
1237 | |||
1238 | static int isp1362_urb_enqueue(struct usb_hcd *hcd, | ||
1239 | struct urb *urb, | ||
1240 | gfp_t mem_flags) | ||
1241 | { | ||
1242 | struct isp1362_hcd *isp1362_hcd = hcd_to_isp1362_hcd(hcd); | ||
1243 | struct usb_device *udev = urb->dev; | ||
1244 | unsigned int pipe = urb->pipe; | ||
1245 | int is_out = !usb_pipein(pipe); | ||
1246 | int type = usb_pipetype(pipe); | ||
1247 | int epnum = usb_pipeendpoint(pipe); | ||
1248 | struct usb_host_endpoint *hep = urb->ep; | ||
1249 | struct isp1362_ep *ep = NULL; | ||
1250 | unsigned long flags; | ||
1251 | int retval = 0; | ||
1252 | |||
1253 | DBG(3, "%s: urb %p\n", __func__, urb); | ||
1254 | |||
1255 | if (type == PIPE_ISOCHRONOUS) { | ||
1256 | pr_err("Isochronous transfers not supported\n"); | ||
1257 | return -ENOSPC; | ||
1258 | } | ||
1259 | |||
1260 | URB_DBG("%s: FA %d ep%d%s %s: len %d %s%s\n", __func__, | ||
1261 | usb_pipedevice(pipe), epnum, | ||
1262 | is_out ? "out" : "in", | ||
1263 | usb_pipecontrol(pipe) ? "ctrl" : | ||
1264 | usb_pipeint(pipe) ? "int" : | ||
1265 | usb_pipebulk(pipe) ? "bulk" : | ||
1266 | "iso", | ||
1267 | urb->transfer_buffer_length, | ||
1268 | (urb->transfer_flags & URB_ZERO_PACKET) ? "ZERO_PACKET " : "", | ||
1269 | !(urb->transfer_flags & URB_SHORT_NOT_OK) ? | ||
1270 | "short_ok" : ""); | ||
1271 | |||
1272 | /* avoid all allocations within spinlocks: request or endpoint */ | ||
1273 | if (!hep->hcpriv) { | ||
1274 | ep = kcalloc(1, sizeof *ep, mem_flags); | ||
1275 | if (!ep) | ||
1276 | return -ENOMEM; | ||
1277 | } | ||
1278 | spin_lock_irqsave(&isp1362_hcd->lock, flags); | ||
1279 | |||
1280 | /* don't submit to a dead or disabled port */ | ||
1281 | if (!((isp1362_hcd->rhport[0] | isp1362_hcd->rhport[1]) & | ||
1282 | (1 << USB_PORT_FEAT_ENABLE)) || | ||
1283 | !HC_IS_RUNNING(hcd->state)) { | ||
1284 | kfree(ep); | ||
1285 | retval = -ENODEV; | ||
1286 | goto fail_not_linked; | ||
1287 | } | ||
1288 | |||
1289 | retval = usb_hcd_link_urb_to_ep(hcd, urb); | ||
1290 | if (retval) { | ||
1291 | kfree(ep); | ||
1292 | goto fail_not_linked; | ||
1293 | } | ||
1294 | |||
1295 | if (hep->hcpriv) { | ||
1296 | ep = hep->hcpriv; | ||
1297 | } else { | ||
1298 | INIT_LIST_HEAD(&ep->schedule); | ||
1299 | INIT_LIST_HEAD(&ep->active); | ||
1300 | INIT_LIST_HEAD(&ep->remove_list); | ||
1301 | ep->udev = usb_get_dev(udev); | ||
1302 | ep->hep = hep; | ||
1303 | ep->epnum = epnum; | ||
1304 | ep->maxpacket = usb_maxpacket(udev, urb->pipe, is_out); | ||
1305 | ep->ptd_offset = -EINVAL; | ||
1306 | ep->ptd_index = -EINVAL; | ||
1307 | usb_settoggle(udev, epnum, is_out, 0); | ||
1308 | |||
1309 | if (type == PIPE_CONTROL) | ||
1310 | ep->nextpid = USB_PID_SETUP; | ||
1311 | else if (is_out) | ||
1312 | ep->nextpid = USB_PID_OUT; | ||
1313 | else | ||
1314 | ep->nextpid = USB_PID_IN; | ||
1315 | |||
1316 | switch (type) { | ||
1317 | case PIPE_ISOCHRONOUS: | ||
1318 | case PIPE_INTERRUPT: | ||
1319 | if (urb->interval > PERIODIC_SIZE) | ||
1320 | urb->interval = PERIODIC_SIZE; | ||
1321 | ep->interval = urb->interval; | ||
1322 | ep->branch = PERIODIC_SIZE; | ||
1323 | ep->load = usb_calc_bus_time(udev->speed, !is_out, | ||
1324 | (type == PIPE_ISOCHRONOUS), | ||
1325 | usb_maxpacket(udev, pipe, is_out)) / 1000; | ||
1326 | break; | ||
1327 | } | ||
1328 | hep->hcpriv = ep; | ||
1329 | } | ||
1330 | ep->num_req = isp1362_hcd->req_serial++; | ||
1331 | |||
1332 | /* maybe put endpoint into schedule */ | ||
1333 | switch (type) { | ||
1334 | case PIPE_CONTROL: | ||
1335 | case PIPE_BULK: | ||
1336 | if (list_empty(&ep->schedule)) { | ||
1337 | DBG(1, "%s: Adding ep %p req %d to async schedule\n", | ||
1338 | __func__, ep, ep->num_req); | ||
1339 | list_add_tail(&ep->schedule, &isp1362_hcd->async); | ||
1340 | } | ||
1341 | break; | ||
1342 | case PIPE_ISOCHRONOUS: | ||
1343 | case PIPE_INTERRUPT: | ||
1344 | urb->interval = ep->interval; | ||
1345 | |||
1346 | /* urb submitted for already existing EP */ | ||
1347 | if (ep->branch < PERIODIC_SIZE) | ||
1348 | break; | ||
1349 | |||
1350 | retval = balance(isp1362_hcd, ep->interval, ep->load); | ||
1351 | if (retval < 0) { | ||
1352 | pr_err("%s: balance returned %d\n", __func__, retval); | ||
1353 | goto fail; | ||
1354 | } | ||
1355 | ep->branch = retval; | ||
1356 | retval = 0; | ||
1357 | isp1362_hcd->fmindex = isp1362_read_reg32(isp1362_hcd, HCFMNUM); | ||
1358 | DBG(1, "%s: Current frame %04x branch %02x start_frame %04x(%04x)\n", | ||
1359 | __func__, isp1362_hcd->fmindex, ep->branch, | ||
1360 | ((isp1362_hcd->fmindex + PERIODIC_SIZE - 1) & | ||
1361 | ~(PERIODIC_SIZE - 1)) + ep->branch, | ||
1362 | (isp1362_hcd->fmindex & (PERIODIC_SIZE - 1)) + ep->branch); | ||
1363 | |||
1364 | if (list_empty(&ep->schedule)) { | ||
1365 | if (type == PIPE_ISOCHRONOUS) { | ||
1366 | u16 frame = isp1362_hcd->fmindex; | ||
1367 | |||
1368 | frame += max_t(u16, 8, ep->interval); | ||
1369 | frame &= ~(ep->interval - 1); | ||
1370 | frame |= ep->branch; | ||
1371 | if (frame_before(frame, isp1362_hcd->fmindex)) | ||
1372 | frame += ep->interval; | ||
1373 | urb->start_frame = frame; | ||
1374 | |||
1375 | DBG(1, "%s: Adding ep %p to isoc schedule\n", __func__, ep); | ||
1376 | list_add_tail(&ep->schedule, &isp1362_hcd->isoc); | ||
1377 | } else { | ||
1378 | DBG(1, "%s: Adding ep %p to periodic schedule\n", __func__, ep); | ||
1379 | list_add_tail(&ep->schedule, &isp1362_hcd->periodic); | ||
1380 | } | ||
1381 | } else | ||
1382 | DBG(1, "%s: ep %p already scheduled\n", __func__, ep); | ||
1383 | |||
1384 | DBG(2, "%s: load %d bandwidth %d -> %d\n", __func__, | ||
1385 | ep->load / ep->interval, isp1362_hcd->load[ep->branch], | ||
1386 | isp1362_hcd->load[ep->branch] + ep->load); | ||
1387 | isp1362_hcd->load[ep->branch] += ep->load; | ||
1388 | } | ||
1389 | |||
1390 | urb->hcpriv = hep; | ||
1391 | ALIGNSTAT(isp1362_hcd, urb->transfer_buffer); | ||
1392 | |||
1393 | switch (type) { | ||
1394 | case PIPE_CONTROL: | ||
1395 | case PIPE_BULK: | ||
1396 | start_atl_transfers(isp1362_hcd); | ||
1397 | break; | ||
1398 | case PIPE_INTERRUPT: | ||
1399 | start_intl_transfers(isp1362_hcd); | ||
1400 | break; | ||
1401 | case PIPE_ISOCHRONOUS: | ||
1402 | start_iso_transfers(isp1362_hcd); | ||
1403 | break; | ||
1404 | default: | ||
1405 | BUG(); | ||
1406 | } | ||
1407 | fail: | ||
1408 | if (retval) | ||
1409 | usb_hcd_unlink_urb_from_ep(hcd, urb); | ||
1410 | |||
1411 | |||
1412 | fail_not_linked: | ||
1413 | spin_unlock_irqrestore(&isp1362_hcd->lock, flags); | ||
1414 | if (retval) | ||
1415 | DBG(0, "%s: urb %p failed with %d\n", __func__, urb, retval); | ||
1416 | return retval; | ||
1417 | } | ||
1418 | |||
1419 | static int isp1362_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status) | ||
1420 | { | ||
1421 | struct isp1362_hcd *isp1362_hcd = hcd_to_isp1362_hcd(hcd); | ||
1422 | struct usb_host_endpoint *hep; | ||
1423 | unsigned long flags; | ||
1424 | struct isp1362_ep *ep; | ||
1425 | int retval = 0; | ||
1426 | |||
1427 | DBG(3, "%s: urb %p\n", __func__, urb); | ||
1428 | |||
1429 | spin_lock_irqsave(&isp1362_hcd->lock, flags); | ||
1430 | retval = usb_hcd_check_unlink_urb(hcd, urb, status); | ||
1431 | if (retval) | ||
1432 | goto done; | ||
1433 | |||
1434 | hep = urb->hcpriv; | ||
1435 | |||
1436 | if (!hep) { | ||
1437 | spin_unlock_irqrestore(&isp1362_hcd->lock, flags); | ||
1438 | return -EIDRM; | ||
1439 | } | ||
1440 | |||
1441 | ep = hep->hcpriv; | ||
1442 | if (ep) { | ||
1443 | /* In front of queue? */ | ||
1444 | if (ep->hep->urb_list.next == &urb->urb_list) { | ||
1445 | if (!list_empty(&ep->active)) { | ||
1446 | DBG(1, "%s: urb %p ep %p req %d active PTD[%d] $%04x\n", __func__, | ||
1447 | urb, ep, ep->num_req, ep->ptd_index, ep->ptd_offset); | ||
1448 | /* disable processing and queue PTD for removal */ | ||
1449 | remove_ptd(isp1362_hcd, ep); | ||
1450 | urb = NULL; | ||
1451 | } | ||
1452 | } | ||
1453 | if (urb) { | ||
1454 | DBG(1, "%s: Finishing ep %p req %d\n", __func__, ep, | ||
1455 | ep->num_req); | ||
1456 | finish_request(isp1362_hcd, ep, urb, status); | ||
1457 | } else | ||
1458 | DBG(1, "%s: urb %p active; wait4irq\n", __func__, urb); | ||
1459 | } else { | ||
1460 | pr_warning("%s: No EP in URB %p\n", __func__, urb); | ||
1461 | retval = -EINVAL; | ||
1462 | } | ||
1463 | done: | ||
1464 | spin_unlock_irqrestore(&isp1362_hcd->lock, flags); | ||
1465 | |||
1466 | DBG(3, "%s: exit\n", __func__); | ||
1467 | |||
1468 | return retval; | ||
1469 | } | ||
1470 | |||
1471 | static void isp1362_endpoint_disable(struct usb_hcd *hcd, struct usb_host_endpoint *hep) | ||
1472 | { | ||
1473 | struct isp1362_ep *ep = hep->hcpriv; | ||
1474 | struct isp1362_hcd *isp1362_hcd = hcd_to_isp1362_hcd(hcd); | ||
1475 | unsigned long flags; | ||
1476 | |||
1477 | DBG(1, "%s: ep %p\n", __func__, ep); | ||
1478 | if (!ep) | ||
1479 | return; | ||
1480 | spin_lock_irqsave(&isp1362_hcd->lock, flags); | ||
1481 | if (!list_empty(&hep->urb_list)) { | ||
1482 | if (!list_empty(&ep->active) && list_empty(&ep->remove_list)) { | ||
1483 | DBG(1, "%s: Removing ep %p req %d PTD[%d] $%04x\n", __func__, | ||
1484 | ep, ep->num_req, ep->ptd_index, ep->ptd_offset); | ||
1485 | remove_ptd(isp1362_hcd, ep); | ||
1486 | pr_info("%s: Waiting for Interrupt to clean up\n", __func__); | ||
1487 | } | ||
1488 | } | ||
1489 | spin_unlock_irqrestore(&isp1362_hcd->lock, flags); | ||
1490 | /* Wait for interrupt to clear out active list */ | ||
1491 | while (!list_empty(&ep->active)) | ||
1492 | msleep(1); | ||
1493 | |||
1494 | DBG(1, "%s: Freeing EP %p\n", __func__, ep); | ||
1495 | |||
1496 | usb_put_dev(ep->udev); | ||
1497 | kfree(ep); | ||
1498 | hep->hcpriv = NULL; | ||
1499 | } | ||
1500 | |||
1501 | static int isp1362_get_frame(struct usb_hcd *hcd) | ||
1502 | { | ||
1503 | struct isp1362_hcd *isp1362_hcd = hcd_to_isp1362_hcd(hcd); | ||
1504 | u32 fmnum; | ||
1505 | unsigned long flags; | ||
1506 | |||
1507 | spin_lock_irqsave(&isp1362_hcd->lock, flags); | ||
1508 | fmnum = isp1362_read_reg32(isp1362_hcd, HCFMNUM); | ||
1509 | spin_unlock_irqrestore(&isp1362_hcd->lock, flags); | ||
1510 | |||
1511 | return (int)fmnum; | ||
1512 | } | ||
1513 | |||
1514 | /*-------------------------------------------------------------------------*/ | ||
1515 | |||
1516 | /* Adapted from ohci-hub.c */ | ||
1517 | static int isp1362_hub_status_data(struct usb_hcd *hcd, char *buf) | ||
1518 | { | ||
1519 | struct isp1362_hcd *isp1362_hcd = hcd_to_isp1362_hcd(hcd); | ||
1520 | int ports, i, changed = 0; | ||
1521 | unsigned long flags; | ||
1522 | |||
1523 | if (!HC_IS_RUNNING(hcd->state)) | ||
1524 | return -ESHUTDOWN; | ||
1525 | |||
1526 | /* Report no status change now, if we are scheduled to be | ||
1527 | called later */ | ||
1528 | if (timer_pending(&hcd->rh_timer)) | ||
1529 | return 0; | ||
1530 | |||
1531 | ports = isp1362_hcd->rhdesca & RH_A_NDP; | ||
1532 | BUG_ON(ports > 2); | ||
1533 | |||
1534 | spin_lock_irqsave(&isp1362_hcd->lock, flags); | ||
1535 | /* init status */ | ||
1536 | if (isp1362_hcd->rhstatus & (RH_HS_LPSC | RH_HS_OCIC)) | ||
1537 | buf[0] = changed = 1; | ||
1538 | else | ||
1539 | buf[0] = 0; | ||
1540 | |||
1541 | for (i = 0; i < ports; i++) { | ||
1542 | u32 status = isp1362_hcd->rhport[i]; | ||
1543 | |||
1544 | if (status & (RH_PS_CSC | RH_PS_PESC | RH_PS_PSSC | | ||
1545 | RH_PS_OCIC | RH_PS_PRSC)) { | ||
1546 | changed = 1; | ||
1547 | buf[0] |= 1 << (i + 1); | ||
1548 | continue; | ||
1549 | } | ||
1550 | |||
1551 | if (!(status & RH_PS_CCS)) | ||
1552 | continue; | ||
1553 | } | ||
1554 | spin_unlock_irqrestore(&isp1362_hcd->lock, flags); | ||
1555 | return changed; | ||
1556 | } | ||
1557 | |||
1558 | static void isp1362_hub_descriptor(struct isp1362_hcd *isp1362_hcd, | ||
1559 | struct usb_hub_descriptor *desc) | ||
1560 | { | ||
1561 | u32 reg = isp1362_hcd->rhdesca; | ||
1562 | |||
1563 | DBG(3, "%s: enter\n", __func__); | ||
1564 | |||
1565 | desc->bDescriptorType = 0x29; | ||
1566 | desc->bDescLength = 9; | ||
1567 | desc->bHubContrCurrent = 0; | ||
1568 | desc->bNbrPorts = reg & 0x3; | ||
1569 | /* Power switching, device type, overcurrent. */ | ||
1570 | desc->wHubCharacteristics = cpu_to_le16((reg >> 8) & 0x1f); | ||
1571 | DBG(0, "%s: hubcharacteristics = %02x\n", __func__, cpu_to_le16((reg >> 8) & 0x1f)); | ||
1572 | desc->bPwrOn2PwrGood = (reg >> 24) & 0xff; | ||
1573 | /* two bitmaps: ports removable, and legacy PortPwrCtrlMask */ | ||
1574 | desc->bitmap[0] = desc->bNbrPorts == 1 ? 1 << 1 : 3 << 1; | ||
1575 | desc->bitmap[1] = ~0; | ||
1576 | |||
1577 | DBG(3, "%s: exit\n", __func__); | ||
1578 | } | ||
1579 | |||
1580 | /* Adapted from ohci-hub.c */ | ||
1581 | static int isp1362_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue, | ||
1582 | u16 wIndex, char *buf, u16 wLength) | ||
1583 | { | ||
1584 | struct isp1362_hcd *isp1362_hcd = hcd_to_isp1362_hcd(hcd); | ||
1585 | int retval = 0; | ||
1586 | unsigned long flags; | ||
1587 | unsigned long t1; | ||
1588 | int ports = isp1362_hcd->rhdesca & RH_A_NDP; | ||
1589 | u32 tmp = 0; | ||
1590 | |||
1591 | switch (typeReq) { | ||
1592 | case ClearHubFeature: | ||
1593 | DBG(0, "ClearHubFeature: "); | ||
1594 | switch (wValue) { | ||
1595 | case C_HUB_OVER_CURRENT: | ||
1596 | _DBG(0, "C_HUB_OVER_CURRENT\n"); | ||
1597 | spin_lock_irqsave(&isp1362_hcd->lock, flags); | ||
1598 | isp1362_write_reg32(isp1362_hcd, HCRHSTATUS, RH_HS_OCIC); | ||
1599 | spin_unlock_irqrestore(&isp1362_hcd->lock, flags); | ||
1600 | case C_HUB_LOCAL_POWER: | ||
1601 | _DBG(0, "C_HUB_LOCAL_POWER\n"); | ||
1602 | break; | ||
1603 | default: | ||
1604 | goto error; | ||
1605 | } | ||
1606 | break; | ||
1607 | case SetHubFeature: | ||
1608 | DBG(0, "SetHubFeature: "); | ||
1609 | switch (wValue) { | ||
1610 | case C_HUB_OVER_CURRENT: | ||
1611 | case C_HUB_LOCAL_POWER: | ||
1612 | _DBG(0, "C_HUB_OVER_CURRENT or C_HUB_LOCAL_POWER\n"); | ||
1613 | break; | ||
1614 | default: | ||
1615 | goto error; | ||
1616 | } | ||
1617 | break; | ||
1618 | case GetHubDescriptor: | ||
1619 | DBG(0, "GetHubDescriptor\n"); | ||
1620 | isp1362_hub_descriptor(isp1362_hcd, (struct usb_hub_descriptor *)buf); | ||
1621 | break; | ||
1622 | case GetHubStatus: | ||
1623 | DBG(0, "GetHubStatus\n"); | ||
1624 | put_unaligned(cpu_to_le32(0), (__le32 *) buf); | ||
1625 | break; | ||
1626 | case GetPortStatus: | ||
1627 | #ifndef VERBOSE | ||
1628 | DBG(0, "GetPortStatus\n"); | ||
1629 | #endif | ||
1630 | if (!wIndex || wIndex > ports) | ||
1631 | goto error; | ||
1632 | tmp = isp1362_hcd->rhport[--wIndex]; | ||
1633 | put_unaligned(cpu_to_le32(tmp), (__le32 *) buf); | ||
1634 | break; | ||
1635 | case ClearPortFeature: | ||
1636 | DBG(0, "ClearPortFeature: "); | ||
1637 | if (!wIndex || wIndex > ports) | ||
1638 | goto error; | ||
1639 | wIndex--; | ||
1640 | |||
1641 | switch (wValue) { | ||
1642 | case USB_PORT_FEAT_ENABLE: | ||
1643 | _DBG(0, "USB_PORT_FEAT_ENABLE\n"); | ||
1644 | tmp = RH_PS_CCS; | ||
1645 | break; | ||
1646 | case USB_PORT_FEAT_C_ENABLE: | ||
1647 | _DBG(0, "USB_PORT_FEAT_C_ENABLE\n"); | ||
1648 | tmp = RH_PS_PESC; | ||
1649 | break; | ||
1650 | case USB_PORT_FEAT_SUSPEND: | ||
1651 | _DBG(0, "USB_PORT_FEAT_SUSPEND\n"); | ||
1652 | tmp = RH_PS_POCI; | ||
1653 | break; | ||
1654 | case USB_PORT_FEAT_C_SUSPEND: | ||
1655 | _DBG(0, "USB_PORT_FEAT_C_SUSPEND\n"); | ||
1656 | tmp = RH_PS_PSSC; | ||
1657 | break; | ||
1658 | case USB_PORT_FEAT_POWER: | ||
1659 | _DBG(0, "USB_PORT_FEAT_POWER\n"); | ||
1660 | tmp = RH_PS_LSDA; | ||
1661 | |||
1662 | break; | ||
1663 | case USB_PORT_FEAT_C_CONNECTION: | ||
1664 | _DBG(0, "USB_PORT_FEAT_C_CONNECTION\n"); | ||
1665 | tmp = RH_PS_CSC; | ||
1666 | break; | ||
1667 | case USB_PORT_FEAT_C_OVER_CURRENT: | ||
1668 | _DBG(0, "USB_PORT_FEAT_C_OVER_CURRENT\n"); | ||
1669 | tmp = RH_PS_OCIC; | ||
1670 | break; | ||
1671 | case USB_PORT_FEAT_C_RESET: | ||
1672 | _DBG(0, "USB_PORT_FEAT_C_RESET\n"); | ||
1673 | tmp = RH_PS_PRSC; | ||
1674 | break; | ||
1675 | default: | ||
1676 | goto error; | ||
1677 | } | ||
1678 | |||
1679 | spin_lock_irqsave(&isp1362_hcd->lock, flags); | ||
1680 | isp1362_write_reg32(isp1362_hcd, HCRHPORT1 + wIndex, tmp); | ||
1681 | isp1362_hcd->rhport[wIndex] = | ||
1682 | isp1362_read_reg32(isp1362_hcd, HCRHPORT1 + wIndex); | ||
1683 | spin_unlock_irqrestore(&isp1362_hcd->lock, flags); | ||
1684 | break; | ||
1685 | case SetPortFeature: | ||
1686 | DBG(0, "SetPortFeature: "); | ||
1687 | if (!wIndex || wIndex > ports) | ||
1688 | goto error; | ||
1689 | wIndex--; | ||
1690 | switch (wValue) { | ||
1691 | case USB_PORT_FEAT_SUSPEND: | ||
1692 | _DBG(0, "USB_PORT_FEAT_SUSPEND\n"); | ||
1693 | #ifdef CONFIG_USB_OTG | ||
1694 | if (ohci->hcd.self.otg_port == (wIndex + 1) && | ||
1695 | ohci->hcd.self.b_hnp_enable) { | ||
1696 | start_hnp(ohci); | ||
1697 | break; | ||
1698 | } | ||
1699 | #endif | ||
1700 | spin_lock_irqsave(&isp1362_hcd->lock, flags); | ||
1701 | isp1362_write_reg32(isp1362_hcd, HCRHPORT1 + wIndex, RH_PS_PSS); | ||
1702 | isp1362_hcd->rhport[wIndex] = | ||
1703 | isp1362_read_reg32(isp1362_hcd, HCRHPORT1 + wIndex); | ||
1704 | spin_unlock_irqrestore(&isp1362_hcd->lock, flags); | ||
1705 | break; | ||
1706 | case USB_PORT_FEAT_POWER: | ||
1707 | _DBG(0, "USB_PORT_FEAT_POWER\n"); | ||
1708 | spin_lock_irqsave(&isp1362_hcd->lock, flags); | ||
1709 | isp1362_write_reg32(isp1362_hcd, HCRHPORT1 + wIndex, RH_PS_PPS); | ||
1710 | isp1362_hcd->rhport[wIndex] = | ||
1711 | isp1362_read_reg32(isp1362_hcd, HCRHPORT1 + wIndex); | ||
1712 | spin_unlock_irqrestore(&isp1362_hcd->lock, flags); | ||
1713 | break; | ||
1714 | case USB_PORT_FEAT_RESET: | ||
1715 | _DBG(0, "USB_PORT_FEAT_RESET\n"); | ||
1716 | spin_lock_irqsave(&isp1362_hcd->lock, flags); | ||
1717 | |||
1718 | t1 = jiffies + msecs_to_jiffies(USB_RESET_WIDTH); | ||
1719 | while (time_before(jiffies, t1)) { | ||
1720 | /* spin until any current reset finishes */ | ||
1721 | for (;;) { | ||
1722 | tmp = isp1362_read_reg32(isp1362_hcd, HCRHPORT1 + wIndex); | ||
1723 | if (!(tmp & RH_PS_PRS)) | ||
1724 | break; | ||
1725 | udelay(500); | ||
1726 | } | ||
1727 | if (!(tmp & RH_PS_CCS)) | ||
1728 | break; | ||
1729 | /* Reset lasts 10ms (claims datasheet) */ | ||
1730 | isp1362_write_reg32(isp1362_hcd, HCRHPORT1 + wIndex, (RH_PS_PRS)); | ||
1731 | |||
1732 | spin_unlock_irqrestore(&isp1362_hcd->lock, flags); | ||
1733 | msleep(10); | ||
1734 | spin_lock_irqsave(&isp1362_hcd->lock, flags); | ||
1735 | } | ||
1736 | |||
1737 | isp1362_hcd->rhport[wIndex] = isp1362_read_reg32(isp1362_hcd, | ||
1738 | HCRHPORT1 + wIndex); | ||
1739 | spin_unlock_irqrestore(&isp1362_hcd->lock, flags); | ||
1740 | break; | ||
1741 | default: | ||
1742 | goto error; | ||
1743 | } | ||
1744 | break; | ||
1745 | |||
1746 | default: | ||
1747 | error: | ||
1748 | /* "protocol stall" on error */ | ||
1749 | _DBG(0, "PROTOCOL STALL\n"); | ||
1750 | retval = -EPIPE; | ||
1751 | } | ||
1752 | |||
1753 | return retval; | ||
1754 | } | ||
1755 | |||
1756 | #ifdef CONFIG_PM | ||
1757 | static int isp1362_bus_suspend(struct usb_hcd *hcd) | ||
1758 | { | ||
1759 | int status = 0; | ||
1760 | struct isp1362_hcd *isp1362_hcd = hcd_to_isp1362_hcd(hcd); | ||
1761 | unsigned long flags; | ||
1762 | |||
1763 | if (time_before(jiffies, isp1362_hcd->next_statechange)) | ||
1764 | msleep(5); | ||
1765 | |||
1766 | spin_lock_irqsave(&isp1362_hcd->lock, flags); | ||
1767 | |||
1768 | isp1362_hcd->hc_control = isp1362_read_reg32(isp1362_hcd, HCCONTROL); | ||
1769 | switch (isp1362_hcd->hc_control & OHCI_CTRL_HCFS) { | ||
1770 | case OHCI_USB_RESUME: | ||
1771 | DBG(0, "%s: resume/suspend?\n", __func__); | ||
1772 | isp1362_hcd->hc_control &= ~OHCI_CTRL_HCFS; | ||
1773 | isp1362_hcd->hc_control |= OHCI_USB_RESET; | ||
1774 | isp1362_write_reg32(isp1362_hcd, HCCONTROL, isp1362_hcd->hc_control); | ||
1775 | /* FALL THROUGH */ | ||
1776 | case OHCI_USB_RESET: | ||
1777 | status = -EBUSY; | ||
1778 | pr_warning("%s: needs reinit!\n", __func__); | ||
1779 | goto done; | ||
1780 | case OHCI_USB_SUSPEND: | ||
1781 | pr_warning("%s: already suspended?\n", __func__); | ||
1782 | goto done; | ||
1783 | } | ||
1784 | DBG(0, "%s: suspend root hub\n", __func__); | ||
1785 | |||
1786 | /* First stop any processing */ | ||
1787 | hcd->state = HC_STATE_QUIESCING; | ||
1788 | if (!list_empty(&isp1362_hcd->atl_queue.active) || | ||
1789 | !list_empty(&isp1362_hcd->intl_queue.active) || | ||
1790 | !list_empty(&isp1362_hcd->istl_queue[0] .active) || | ||
1791 | !list_empty(&isp1362_hcd->istl_queue[1] .active)) { | ||
1792 | int limit; | ||
1793 | |||
1794 | isp1362_write_reg32(isp1362_hcd, HCATLSKIP, ~0); | ||
1795 | isp1362_write_reg32(isp1362_hcd, HCINTLSKIP, ~0); | ||
1796 | isp1362_write_reg16(isp1362_hcd, HCBUFSTAT, 0); | ||
1797 | isp1362_write_reg16(isp1362_hcd, HCuPINTENB, 0); | ||
1798 | isp1362_write_reg32(isp1362_hcd, HCINTSTAT, OHCI_INTR_SF); | ||
1799 | |||
1800 | DBG(0, "%s: stopping schedules ...\n", __func__); | ||
1801 | limit = 2000; | ||
1802 | while (limit > 0) { | ||
1803 | udelay(250); | ||
1804 | limit -= 250; | ||
1805 | if (isp1362_read_reg32(isp1362_hcd, HCINTSTAT) & OHCI_INTR_SF) | ||
1806 | break; | ||
1807 | } | ||
1808 | mdelay(7); | ||
1809 | if (isp1362_read_reg16(isp1362_hcd, HCuPINT) & HCuPINT_ATL) { | ||
1810 | u32 done_map = isp1362_read_reg32(isp1362_hcd, HCATLDONE); | ||
1811 | finish_transfers(isp1362_hcd, done_map, &isp1362_hcd->atl_queue); | ||
1812 | } | ||
1813 | if (isp1362_read_reg16(isp1362_hcd, HCuPINT) & HCuPINT_INTL) { | ||
1814 | u32 done_map = isp1362_read_reg32(isp1362_hcd, HCINTLDONE); | ||
1815 | finish_transfers(isp1362_hcd, done_map, &isp1362_hcd->intl_queue); | ||
1816 | } | ||
1817 | if (isp1362_read_reg16(isp1362_hcd, HCuPINT) & HCuPINT_ISTL0) | ||
1818 | finish_iso_transfers(isp1362_hcd, &isp1362_hcd->istl_queue[0]); | ||
1819 | if (isp1362_read_reg16(isp1362_hcd, HCuPINT) & HCuPINT_ISTL1) | ||
1820 | finish_iso_transfers(isp1362_hcd, &isp1362_hcd->istl_queue[1]); | ||
1821 | } | ||
1822 | DBG(0, "%s: HCINTSTAT: %08x\n", __func__, | ||
1823 | isp1362_read_reg32(isp1362_hcd, HCINTSTAT)); | ||
1824 | isp1362_write_reg32(isp1362_hcd, HCINTSTAT, | ||
1825 | isp1362_read_reg32(isp1362_hcd, HCINTSTAT)); | ||
1826 | |||
1827 | /* Suspend hub */ | ||
1828 | isp1362_hcd->hc_control = OHCI_USB_SUSPEND; | ||
1829 | isp1362_show_reg(isp1362_hcd, HCCONTROL); | ||
1830 | isp1362_write_reg32(isp1362_hcd, HCCONTROL, isp1362_hcd->hc_control); | ||
1831 | isp1362_show_reg(isp1362_hcd, HCCONTROL); | ||
1832 | |||
1833 | #if 1 | ||
1834 | isp1362_hcd->hc_control = isp1362_read_reg32(isp1362_hcd, HCCONTROL); | ||
1835 | if ((isp1362_hcd->hc_control & OHCI_CTRL_HCFS) != OHCI_USB_SUSPEND) { | ||
1836 | pr_err("%s: controller won't suspend %08x\n", __func__, | ||
1837 | isp1362_hcd->hc_control); | ||
1838 | status = -EBUSY; | ||
1839 | } else | ||
1840 | #endif | ||
1841 | { | ||
1842 | /* no resumes until devices finish suspending */ | ||
1843 | isp1362_hcd->next_statechange = jiffies + msecs_to_jiffies(5); | ||
1844 | } | ||
1845 | done: | ||
1846 | if (status == 0) { | ||
1847 | hcd->state = HC_STATE_SUSPENDED; | ||
1848 | DBG(0, "%s: HCD suspended: %08x\n", __func__, | ||
1849 | isp1362_read_reg32(isp1362_hcd, HCCONTROL)); | ||
1850 | } | ||
1851 | spin_unlock_irqrestore(&isp1362_hcd->lock, flags); | ||
1852 | return status; | ||
1853 | } | ||
1854 | |||
1855 | static int isp1362_bus_resume(struct usb_hcd *hcd) | ||
1856 | { | ||
1857 | struct isp1362_hcd *isp1362_hcd = hcd_to_isp1362_hcd(hcd); | ||
1858 | u32 port; | ||
1859 | unsigned long flags; | ||
1860 | int status = -EINPROGRESS; | ||
1861 | |||
1862 | if (time_before(jiffies, isp1362_hcd->next_statechange)) | ||
1863 | msleep(5); | ||
1864 | |||
1865 | spin_lock_irqsave(&isp1362_hcd->lock, flags); | ||
1866 | isp1362_hcd->hc_control = isp1362_read_reg32(isp1362_hcd, HCCONTROL); | ||
1867 | pr_info("%s: HCCONTROL: %08x\n", __func__, isp1362_hcd->hc_control); | ||
1868 | if (hcd->state == HC_STATE_RESUMING) { | ||
1869 | pr_warning("%s: duplicate resume\n", __func__); | ||
1870 | status = 0; | ||
1871 | } else | ||
1872 | switch (isp1362_hcd->hc_control & OHCI_CTRL_HCFS) { | ||
1873 | case OHCI_USB_SUSPEND: | ||
1874 | DBG(0, "%s: resume root hub\n", __func__); | ||
1875 | isp1362_hcd->hc_control &= ~OHCI_CTRL_HCFS; | ||
1876 | isp1362_hcd->hc_control |= OHCI_USB_RESUME; | ||
1877 | isp1362_write_reg32(isp1362_hcd, HCCONTROL, isp1362_hcd->hc_control); | ||
1878 | break; | ||
1879 | case OHCI_USB_RESUME: | ||
1880 | /* HCFS changes sometime after INTR_RD */ | ||
1881 | DBG(0, "%s: remote wakeup\n", __func__); | ||
1882 | break; | ||
1883 | case OHCI_USB_OPER: | ||
1884 | DBG(0, "%s: odd resume\n", __func__); | ||
1885 | status = 0; | ||
1886 | hcd->self.root_hub->dev.power.power_state = PMSG_ON; | ||
1887 | break; | ||
1888 | default: /* RESET, we lost power */ | ||
1889 | DBG(0, "%s: root hub hardware reset\n", __func__); | ||
1890 | status = -EBUSY; | ||
1891 | } | ||
1892 | spin_unlock_irqrestore(&isp1362_hcd->lock, flags); | ||
1893 | if (status == -EBUSY) { | ||
1894 | DBG(0, "%s: Restarting HC\n", __func__); | ||
1895 | isp1362_hc_stop(hcd); | ||
1896 | return isp1362_hc_start(hcd); | ||
1897 | } | ||
1898 | if (status != -EINPROGRESS) | ||
1899 | return status; | ||
1900 | spin_lock_irqsave(&isp1362_hcd->lock, flags); | ||
1901 | port = isp1362_read_reg32(isp1362_hcd, HCRHDESCA) & RH_A_NDP; | ||
1902 | while (port--) { | ||
1903 | u32 stat = isp1362_read_reg32(isp1362_hcd, HCRHPORT1 + port); | ||
1904 | |||
1905 | /* force global, not selective, resume */ | ||
1906 | if (!(stat & RH_PS_PSS)) { | ||
1907 | DBG(0, "%s: Not Resuming RH port %d\n", __func__, port); | ||
1908 | continue; | ||
1909 | } | ||
1910 | DBG(0, "%s: Resuming RH port %d\n", __func__, port); | ||
1911 | isp1362_write_reg32(isp1362_hcd, HCRHPORT1 + port, RH_PS_POCI); | ||
1912 | } | ||
1913 | spin_unlock_irqrestore(&isp1362_hcd->lock, flags); | ||
1914 | |||
1915 | /* Some controllers (lucent) need extra-long delays */ | ||
1916 | hcd->state = HC_STATE_RESUMING; | ||
1917 | mdelay(20 /* usb 11.5.1.10 */ + 15); | ||
1918 | |||
1919 | isp1362_hcd->hc_control = OHCI_USB_OPER; | ||
1920 | spin_lock_irqsave(&isp1362_hcd->lock, flags); | ||
1921 | isp1362_show_reg(isp1362_hcd, HCCONTROL); | ||
1922 | isp1362_write_reg32(isp1362_hcd, HCCONTROL, isp1362_hcd->hc_control); | ||
1923 | spin_unlock_irqrestore(&isp1362_hcd->lock, flags); | ||
1924 | /* TRSMRCY */ | ||
1925 | msleep(10); | ||
1926 | |||
1927 | /* keep it alive for ~5x suspend + resume costs */ | ||
1928 | isp1362_hcd->next_statechange = jiffies + msecs_to_jiffies(250); | ||
1929 | |||
1930 | hcd->self.root_hub->dev.power.power_state = PMSG_ON; | ||
1931 | hcd->state = HC_STATE_RUNNING; | ||
1932 | return 0; | ||
1933 | } | ||
1934 | #else | ||
1935 | #define isp1362_bus_suspend NULL | ||
1936 | #define isp1362_bus_resume NULL | ||
1937 | #endif | ||
1938 | |||
1939 | /*-------------------------------------------------------------------------*/ | ||
1940 | |||
1941 | #ifdef STUB_DEBUG_FILE | ||
1942 | |||
1943 | static inline void create_debug_file(struct isp1362_hcd *isp1362_hcd) | ||
1944 | { | ||
1945 | } | ||
1946 | static inline void remove_debug_file(struct isp1362_hcd *isp1362_hcd) | ||
1947 | { | ||
1948 | } | ||
1949 | |||
1950 | #else | ||
1951 | |||
1952 | #include <linux/proc_fs.h> | ||
1953 | #include <linux/seq_file.h> | ||
1954 | |||
1955 | static void dump_irq(struct seq_file *s, char *label, u16 mask) | ||
1956 | { | ||
1957 | seq_printf(s, "%-15s %04x%s%s%s%s%s%s\n", label, mask, | ||
1958 | mask & HCuPINT_CLKRDY ? " clkrdy" : "", | ||
1959 | mask & HCuPINT_SUSP ? " susp" : "", | ||
1960 | mask & HCuPINT_OPR ? " opr" : "", | ||
1961 | mask & HCuPINT_EOT ? " eot" : "", | ||
1962 | mask & HCuPINT_ATL ? " atl" : "", | ||
1963 | mask & HCuPINT_SOF ? " sof" : ""); | ||
1964 | } | ||
1965 | |||
1966 | static void dump_int(struct seq_file *s, char *label, u32 mask) | ||
1967 | { | ||
1968 | seq_printf(s, "%-15s %08x%s%s%s%s%s%s%s\n", label, mask, | ||
1969 | mask & OHCI_INTR_MIE ? " MIE" : "", | ||
1970 | mask & OHCI_INTR_RHSC ? " rhsc" : "", | ||
1971 | mask & OHCI_INTR_FNO ? " fno" : "", | ||
1972 | mask & OHCI_INTR_UE ? " ue" : "", | ||
1973 | mask & OHCI_INTR_RD ? " rd" : "", | ||
1974 | mask & OHCI_INTR_SF ? " sof" : "", | ||
1975 | mask & OHCI_INTR_SO ? " so" : ""); | ||
1976 | } | ||
1977 | |||
1978 | static void dump_ctrl(struct seq_file *s, char *label, u32 mask) | ||
1979 | { | ||
1980 | seq_printf(s, "%-15s %08x%s%s%s\n", label, mask, | ||
1981 | mask & OHCI_CTRL_RWC ? " rwc" : "", | ||
1982 | mask & OHCI_CTRL_RWE ? " rwe" : "", | ||
1983 | ({ | ||
1984 | char *hcfs; | ||
1985 | switch (mask & OHCI_CTRL_HCFS) { | ||
1986 | case OHCI_USB_OPER: | ||
1987 | hcfs = " oper"; | ||
1988 | break; | ||
1989 | case OHCI_USB_RESET: | ||
1990 | hcfs = " reset"; | ||
1991 | break; | ||
1992 | case OHCI_USB_RESUME: | ||
1993 | hcfs = " resume"; | ||
1994 | break; | ||
1995 | case OHCI_USB_SUSPEND: | ||
1996 | hcfs = " suspend"; | ||
1997 | break; | ||
1998 | default: | ||
1999 | hcfs = " ?"; | ||
2000 | } | ||
2001 | hcfs; | ||
2002 | })); | ||
2003 | } | ||
2004 | |||
2005 | static void dump_regs(struct seq_file *s, struct isp1362_hcd *isp1362_hcd) | ||
2006 | { | ||
2007 | seq_printf(s, "HCREVISION [%02x] %08x\n", ISP1362_REG_NO(ISP1362_REG_HCREVISION), | ||
2008 | isp1362_read_reg32(isp1362_hcd, HCREVISION)); | ||
2009 | seq_printf(s, "HCCONTROL [%02x] %08x\n", ISP1362_REG_NO(ISP1362_REG_HCCONTROL), | ||
2010 | isp1362_read_reg32(isp1362_hcd, HCCONTROL)); | ||
2011 | seq_printf(s, "HCCMDSTAT [%02x] %08x\n", ISP1362_REG_NO(ISP1362_REG_HCCMDSTAT), | ||
2012 | isp1362_read_reg32(isp1362_hcd, HCCMDSTAT)); | ||
2013 | seq_printf(s, "HCINTSTAT [%02x] %08x\n", ISP1362_REG_NO(ISP1362_REG_HCINTSTAT), | ||
2014 | isp1362_read_reg32(isp1362_hcd, HCINTSTAT)); | ||
2015 | seq_printf(s, "HCINTENB [%02x] %08x\n", ISP1362_REG_NO(ISP1362_REG_HCINTENB), | ||
2016 | isp1362_read_reg32(isp1362_hcd, HCINTENB)); | ||
2017 | seq_printf(s, "HCFMINTVL [%02x] %08x\n", ISP1362_REG_NO(ISP1362_REG_HCFMINTVL), | ||
2018 | isp1362_read_reg32(isp1362_hcd, HCFMINTVL)); | ||
2019 | seq_printf(s, "HCFMREM [%02x] %08x\n", ISP1362_REG_NO(ISP1362_REG_HCFMREM), | ||
2020 | isp1362_read_reg32(isp1362_hcd, HCFMREM)); | ||
2021 | seq_printf(s, "HCFMNUM [%02x] %08x\n", ISP1362_REG_NO(ISP1362_REG_HCFMNUM), | ||
2022 | isp1362_read_reg32(isp1362_hcd, HCFMNUM)); | ||
2023 | seq_printf(s, "HCLSTHRESH [%02x] %08x\n", ISP1362_REG_NO(ISP1362_REG_HCLSTHRESH), | ||
2024 | isp1362_read_reg32(isp1362_hcd, HCLSTHRESH)); | ||
2025 | seq_printf(s, "HCRHDESCA [%02x] %08x\n", ISP1362_REG_NO(ISP1362_REG_HCRHDESCA), | ||
2026 | isp1362_read_reg32(isp1362_hcd, HCRHDESCA)); | ||
2027 | seq_printf(s, "HCRHDESCB [%02x] %08x\n", ISP1362_REG_NO(ISP1362_REG_HCRHDESCB), | ||
2028 | isp1362_read_reg32(isp1362_hcd, HCRHDESCB)); | ||
2029 | seq_printf(s, "HCRHSTATUS [%02x] %08x\n", ISP1362_REG_NO(ISP1362_REG_HCRHSTATUS), | ||
2030 | isp1362_read_reg32(isp1362_hcd, HCRHSTATUS)); | ||
2031 | seq_printf(s, "HCRHPORT1 [%02x] %08x\n", ISP1362_REG_NO(ISP1362_REG_HCRHPORT1), | ||
2032 | isp1362_read_reg32(isp1362_hcd, HCRHPORT1)); | ||
2033 | seq_printf(s, "HCRHPORT2 [%02x] %08x\n", ISP1362_REG_NO(ISP1362_REG_HCRHPORT2), | ||
2034 | isp1362_read_reg32(isp1362_hcd, HCRHPORT2)); | ||
2035 | seq_printf(s, "\n"); | ||
2036 | seq_printf(s, "HCHWCFG [%02x] %04x\n", ISP1362_REG_NO(ISP1362_REG_HCHWCFG), | ||
2037 | isp1362_read_reg16(isp1362_hcd, HCHWCFG)); | ||
2038 | seq_printf(s, "HCDMACFG [%02x] %04x\n", ISP1362_REG_NO(ISP1362_REG_HCDMACFG), | ||
2039 | isp1362_read_reg16(isp1362_hcd, HCDMACFG)); | ||
2040 | seq_printf(s, "HCXFERCTR [%02x] %04x\n", ISP1362_REG_NO(ISP1362_REG_HCXFERCTR), | ||
2041 | isp1362_read_reg16(isp1362_hcd, HCXFERCTR)); | ||
2042 | seq_printf(s, "HCuPINT [%02x] %04x\n", ISP1362_REG_NO(ISP1362_REG_HCuPINT), | ||
2043 | isp1362_read_reg16(isp1362_hcd, HCuPINT)); | ||
2044 | seq_printf(s, "HCuPINTENB [%02x] %04x\n", ISP1362_REG_NO(ISP1362_REG_HCuPINTENB), | ||
2045 | isp1362_read_reg16(isp1362_hcd, HCuPINTENB)); | ||
2046 | seq_printf(s, "HCCHIPID [%02x] %04x\n", ISP1362_REG_NO(ISP1362_REG_HCCHIPID), | ||
2047 | isp1362_read_reg16(isp1362_hcd, HCCHIPID)); | ||
2048 | seq_printf(s, "HCSCRATCH [%02x] %04x\n", ISP1362_REG_NO(ISP1362_REG_HCSCRATCH), | ||
2049 | isp1362_read_reg16(isp1362_hcd, HCSCRATCH)); | ||
2050 | seq_printf(s, "HCBUFSTAT [%02x] %04x\n", ISP1362_REG_NO(ISP1362_REG_HCBUFSTAT), | ||
2051 | isp1362_read_reg16(isp1362_hcd, HCBUFSTAT)); | ||
2052 | seq_printf(s, "HCDIRADDR [%02x] %08x\n", ISP1362_REG_NO(ISP1362_REG_HCDIRADDR), | ||
2053 | isp1362_read_reg32(isp1362_hcd, HCDIRADDR)); | ||
2054 | #if 0 | ||
2055 | seq_printf(s, "HCDIRDATA [%02x] %04x\n", ISP1362_REG_NO(HCDIRDATA), | ||
2056 | isp1362_read_reg16(isp1362_hcd, HCDIRDATA)); | ||
2057 | #endif | ||
2058 | seq_printf(s, "HCISTLBUFSZ[%02x] %04x\n", ISP1362_REG_NO(ISP1362_REG_HCISTLBUFSZ), | ||
2059 | isp1362_read_reg16(isp1362_hcd, HCISTLBUFSZ)); | ||
2060 | seq_printf(s, "HCISTLRATE [%02x] %04x\n", ISP1362_REG_NO(ISP1362_REG_HCISTLRATE), | ||
2061 | isp1362_read_reg16(isp1362_hcd, HCISTLRATE)); | ||
2062 | seq_printf(s, "\n"); | ||
2063 | seq_printf(s, "HCINTLBUFSZ[%02x] %04x\n", ISP1362_REG_NO(ISP1362_REG_HCINTLBUFSZ), | ||
2064 | isp1362_read_reg16(isp1362_hcd, HCINTLBUFSZ)); | ||
2065 | seq_printf(s, "HCINTLBLKSZ[%02x] %04x\n", ISP1362_REG_NO(ISP1362_REG_HCINTLBLKSZ), | ||
2066 | isp1362_read_reg16(isp1362_hcd, HCINTLBLKSZ)); | ||
2067 | seq_printf(s, "HCINTLDONE [%02x] %08x\n", ISP1362_REG_NO(ISP1362_REG_HCINTLDONE), | ||
2068 | isp1362_read_reg32(isp1362_hcd, HCINTLDONE)); | ||
2069 | seq_printf(s, "HCINTLSKIP [%02x] %08x\n", ISP1362_REG_NO(ISP1362_REG_HCINTLSKIP), | ||
2070 | isp1362_read_reg32(isp1362_hcd, HCINTLSKIP)); | ||
2071 | seq_printf(s, "HCINTLLAST [%02x] %08x\n", ISP1362_REG_NO(ISP1362_REG_HCINTLLAST), | ||
2072 | isp1362_read_reg32(isp1362_hcd, HCINTLLAST)); | ||
2073 | seq_printf(s, "HCINTLCURR [%02x] %04x\n", ISP1362_REG_NO(ISP1362_REG_HCINTLCURR), | ||
2074 | isp1362_read_reg16(isp1362_hcd, HCINTLCURR)); | ||
2075 | seq_printf(s, "\n"); | ||
2076 | seq_printf(s, "HCATLBUFSZ [%02x] %04x\n", ISP1362_REG_NO(ISP1362_REG_HCATLBUFSZ), | ||
2077 | isp1362_read_reg16(isp1362_hcd, HCATLBUFSZ)); | ||
2078 | seq_printf(s, "HCATLBLKSZ [%02x] %04x\n", ISP1362_REG_NO(ISP1362_REG_HCATLBLKSZ), | ||
2079 | isp1362_read_reg16(isp1362_hcd, HCATLBLKSZ)); | ||
2080 | #if 0 | ||
2081 | seq_printf(s, "HCATLDONE [%02x] %08x\n", ISP1362_REG_NO(ISP1362_REG_HCATLDONE), | ||
2082 | isp1362_read_reg32(isp1362_hcd, HCATLDONE)); | ||
2083 | #endif | ||
2084 | seq_printf(s, "HCATLSKIP [%02x] %08x\n", ISP1362_REG_NO(ISP1362_REG_HCATLSKIP), | ||
2085 | isp1362_read_reg32(isp1362_hcd, HCATLSKIP)); | ||
2086 | seq_printf(s, "HCATLLAST [%02x] %08x\n", ISP1362_REG_NO(ISP1362_REG_HCATLLAST), | ||
2087 | isp1362_read_reg32(isp1362_hcd, HCATLLAST)); | ||
2088 | seq_printf(s, "HCATLCURR [%02x] %04x\n", ISP1362_REG_NO(ISP1362_REG_HCATLCURR), | ||
2089 | isp1362_read_reg16(isp1362_hcd, HCATLCURR)); | ||
2090 | seq_printf(s, "\n"); | ||
2091 | seq_printf(s, "HCATLDTC [%02x] %04x\n", ISP1362_REG_NO(ISP1362_REG_HCATLDTC), | ||
2092 | isp1362_read_reg16(isp1362_hcd, HCATLDTC)); | ||
2093 | seq_printf(s, "HCATLDTCTO [%02x] %04x\n", ISP1362_REG_NO(ISP1362_REG_HCATLDTCTO), | ||
2094 | isp1362_read_reg16(isp1362_hcd, HCATLDTCTO)); | ||
2095 | } | ||
2096 | |||
2097 | static int proc_isp1362_show(struct seq_file *s, void *unused) | ||
2098 | { | ||
2099 | struct isp1362_hcd *isp1362_hcd = s->private; | ||
2100 | struct isp1362_ep *ep; | ||
2101 | int i; | ||
2102 | |||
2103 | seq_printf(s, "%s\n%s version %s\n", | ||
2104 | isp1362_hcd_to_hcd(isp1362_hcd)->product_desc, hcd_name, DRIVER_VERSION); | ||
2105 | |||
2106 | /* collect statistics to help estimate potential win for | ||
2107 | * DMA engines that care about alignment (PXA) | ||
2108 | */ | ||
2109 | seq_printf(s, "alignment: 16b/%ld 8b/%ld 4b/%ld 2b/%ld 1b/%ld\n", | ||
2110 | isp1362_hcd->stat16, isp1362_hcd->stat8, isp1362_hcd->stat4, | ||
2111 | isp1362_hcd->stat2, isp1362_hcd->stat1); | ||
2112 | seq_printf(s, "max # ptds in ATL fifo: %d\n", isp1362_hcd->atl_queue.stat_maxptds); | ||
2113 | seq_printf(s, "max # ptds in INTL fifo: %d\n", isp1362_hcd->intl_queue.stat_maxptds); | ||
2114 | seq_printf(s, "max # ptds in ISTL fifo: %d\n", | ||
2115 | max(isp1362_hcd->istl_queue[0] .stat_maxptds, | ||
2116 | isp1362_hcd->istl_queue[1] .stat_maxptds)); | ||
2117 | |||
2118 | /* FIXME: don't show the following in suspended state */ | ||
2119 | spin_lock_irq(&isp1362_hcd->lock); | ||
2120 | |||
2121 | dump_irq(s, "hc_irq_enable", isp1362_read_reg16(isp1362_hcd, HCuPINTENB)); | ||
2122 | dump_irq(s, "hc_irq_status", isp1362_read_reg16(isp1362_hcd, HCuPINT)); | ||
2123 | dump_int(s, "ohci_int_enable", isp1362_read_reg32(isp1362_hcd, HCINTENB)); | ||
2124 | dump_int(s, "ohci_int_status", isp1362_read_reg32(isp1362_hcd, HCINTSTAT)); | ||
2125 | dump_ctrl(s, "ohci_control", isp1362_read_reg32(isp1362_hcd, HCCONTROL)); | ||
2126 | |||
2127 | for (i = 0; i < NUM_ISP1362_IRQS; i++) | ||
2128 | if (isp1362_hcd->irq_stat[i]) | ||
2129 | seq_printf(s, "%-15s: %d\n", | ||
2130 | ISP1362_INT_NAME(i), isp1362_hcd->irq_stat[i]); | ||
2131 | |||
2132 | dump_regs(s, isp1362_hcd); | ||
2133 | list_for_each_entry(ep, &isp1362_hcd->async, schedule) { | ||
2134 | struct urb *urb; | ||
2135 | |||
2136 | seq_printf(s, "%p, ep%d%s, maxpacket %d:\n", ep, ep->epnum, | ||
2137 | ({ | ||
2138 | char *s; | ||
2139 | switch (ep->nextpid) { | ||
2140 | case USB_PID_IN: | ||
2141 | s = "in"; | ||
2142 | break; | ||
2143 | case USB_PID_OUT: | ||
2144 | s = "out"; | ||
2145 | break; | ||
2146 | case USB_PID_SETUP: | ||
2147 | s = "setup"; | ||
2148 | break; | ||
2149 | case USB_PID_ACK: | ||
2150 | s = "status"; | ||
2151 | break; | ||
2152 | default: | ||
2153 | s = "?"; | ||
2154 | break; | ||
2155 | }; | ||
2156 | s;}), ep->maxpacket) ; | ||
2157 | list_for_each_entry(urb, &ep->hep->urb_list, urb_list) { | ||
2158 | seq_printf(s, " urb%p, %d/%d\n", urb, | ||
2159 | urb->actual_length, | ||
2160 | urb->transfer_buffer_length); | ||
2161 | } | ||
2162 | } | ||
2163 | if (!list_empty(&isp1362_hcd->async)) | ||
2164 | seq_printf(s, "\n"); | ||
2165 | dump_ptd_queue(&isp1362_hcd->atl_queue); | ||
2166 | |||
2167 | seq_printf(s, "periodic size= %d\n", PERIODIC_SIZE); | ||
2168 | |||
2169 | list_for_each_entry(ep, &isp1362_hcd->periodic, schedule) { | ||
2170 | seq_printf(s, "branch:%2d load:%3d PTD[%d] $%04x:\n", ep->branch, | ||
2171 | isp1362_hcd->load[ep->branch], ep->ptd_index, ep->ptd_offset); | ||
2172 | |||
2173 | seq_printf(s, " %d/%p (%sdev%d ep%d%s max %d)\n", | ||
2174 | ep->interval, ep, | ||
2175 | (ep->udev->speed == USB_SPEED_FULL) ? "" : "ls ", | ||
2176 | ep->udev->devnum, ep->epnum, | ||
2177 | (ep->epnum == 0) ? "" : | ||
2178 | ((ep->nextpid == USB_PID_IN) ? | ||
2179 | "in" : "out"), ep->maxpacket); | ||
2180 | } | ||
2181 | dump_ptd_queue(&isp1362_hcd->intl_queue); | ||
2182 | |||
2183 | seq_printf(s, "ISO:\n"); | ||
2184 | |||
2185 | list_for_each_entry(ep, &isp1362_hcd->isoc, schedule) { | ||
2186 | seq_printf(s, " %d/%p (%sdev%d ep%d%s max %d)\n", | ||
2187 | ep->interval, ep, | ||
2188 | (ep->udev->speed == USB_SPEED_FULL) ? "" : "ls ", | ||
2189 | ep->udev->devnum, ep->epnum, | ||
2190 | (ep->epnum == 0) ? "" : | ||
2191 | ((ep->nextpid == USB_PID_IN) ? | ||
2192 | "in" : "out"), ep->maxpacket); | ||
2193 | } | ||
2194 | |||
2195 | spin_unlock_irq(&isp1362_hcd->lock); | ||
2196 | seq_printf(s, "\n"); | ||
2197 | |||
2198 | return 0; | ||
2199 | } | ||
2200 | |||
2201 | static int proc_isp1362_open(struct inode *inode, struct file *file) | ||
2202 | { | ||
2203 | return single_open(file, proc_isp1362_show, PDE(inode)->data); | ||
2204 | } | ||
2205 | |||
2206 | static const struct file_operations proc_ops = { | ||
2207 | .open = proc_isp1362_open, | ||
2208 | .read = seq_read, | ||
2209 | .llseek = seq_lseek, | ||
2210 | .release = single_release, | ||
2211 | }; | ||
2212 | |||
2213 | /* expect just one isp1362_hcd per system */ | ||
2214 | static const char proc_filename[] = "driver/isp1362"; | ||
2215 | |||
2216 | static void create_debug_file(struct isp1362_hcd *isp1362_hcd) | ||
2217 | { | ||
2218 | struct proc_dir_entry *pde; | ||
2219 | |||
2220 | pde = create_proc_entry(proc_filename, 0, NULL); | ||
2221 | if (pde == NULL) { | ||
2222 | pr_warning("%s: Failed to create debug file '%s'\n", __func__, proc_filename); | ||
2223 | return; | ||
2224 | } | ||
2225 | |||
2226 | pde->proc_fops = &proc_ops; | ||
2227 | pde->data = isp1362_hcd; | ||
2228 | isp1362_hcd->pde = pde; | ||
2229 | } | ||
2230 | |||
2231 | static void remove_debug_file(struct isp1362_hcd *isp1362_hcd) | ||
2232 | { | ||
2233 | if (isp1362_hcd->pde) | ||
2234 | remove_proc_entry(proc_filename, 0); | ||
2235 | } | ||
2236 | |||
2237 | #endif | ||
2238 | |||
2239 | /*-------------------------------------------------------------------------*/ | ||
2240 | |||
2241 | static void isp1362_sw_reset(struct isp1362_hcd *isp1362_hcd) | ||
2242 | { | ||
2243 | int tmp = 20; | ||
2244 | unsigned long flags; | ||
2245 | |||
2246 | spin_lock_irqsave(&isp1362_hcd->lock, flags); | ||
2247 | |||
2248 | isp1362_write_reg16(isp1362_hcd, HCSWRES, HCSWRES_MAGIC); | ||
2249 | isp1362_write_reg32(isp1362_hcd, HCCMDSTAT, OHCI_HCR); | ||
2250 | while (--tmp) { | ||
2251 | mdelay(1); | ||
2252 | if (!(isp1362_read_reg32(isp1362_hcd, HCCMDSTAT) & OHCI_HCR)) | ||
2253 | break; | ||
2254 | } | ||
2255 | if (!tmp) | ||
2256 | pr_err("Software reset timeout\n"); | ||
2257 | spin_unlock_irqrestore(&isp1362_hcd->lock, flags); | ||
2258 | } | ||
2259 | |||
2260 | static int isp1362_mem_config(struct usb_hcd *hcd) | ||
2261 | { | ||
2262 | struct isp1362_hcd *isp1362_hcd = hcd_to_isp1362_hcd(hcd); | ||
2263 | unsigned long flags; | ||
2264 | u32 total; | ||
2265 | u16 istl_size = ISP1362_ISTL_BUFSIZE; | ||
2266 | u16 intl_blksize = ISP1362_INTL_BLKSIZE + PTD_HEADER_SIZE; | ||
2267 | u16 intl_size = ISP1362_INTL_BUFFERS * intl_blksize; | ||
2268 | u16 atl_blksize = ISP1362_ATL_BLKSIZE + PTD_HEADER_SIZE; | ||
2269 | u16 atl_buffers = (ISP1362_BUF_SIZE - (istl_size + intl_size)) / atl_blksize; | ||
2270 | u16 atl_size; | ||
2271 | int i; | ||
2272 | |||
2273 | WARN_ON(istl_size & 3); | ||
2274 | WARN_ON(atl_blksize & 3); | ||
2275 | WARN_ON(intl_blksize & 3); | ||
2276 | WARN_ON(atl_blksize < PTD_HEADER_SIZE); | ||
2277 | WARN_ON(intl_blksize < PTD_HEADER_SIZE); | ||
2278 | |||
2279 | BUG_ON((unsigned)ISP1362_INTL_BUFFERS > 32); | ||
2280 | if (atl_buffers > 32) | ||
2281 | atl_buffers = 32; | ||
2282 | atl_size = atl_buffers * atl_blksize; | ||
2283 | total = atl_size + intl_size + istl_size; | ||
2284 | dev_info(hcd->self.controller, "ISP1362 Memory usage:\n"); | ||
2285 | dev_info(hcd->self.controller, " ISTL: 2 * %4d: %4d @ $%04x:$%04x\n", | ||
2286 | istl_size / 2, istl_size, 0, istl_size / 2); | ||
2287 | dev_info(hcd->self.controller, " INTL: %4d * (%3u+8): %4d @ $%04x\n", | ||
2288 | ISP1362_INTL_BUFFERS, intl_blksize - PTD_HEADER_SIZE, | ||
2289 | intl_size, istl_size); | ||
2290 | dev_info(hcd->self.controller, " ATL : %4d * (%3u+8): %4d @ $%04x\n", | ||
2291 | atl_buffers, atl_blksize - PTD_HEADER_SIZE, | ||
2292 | atl_size, istl_size + intl_size); | ||
2293 | dev_info(hcd->self.controller, " USED/FREE: %4d %4d\n", total, | ||
2294 | ISP1362_BUF_SIZE - total); | ||
2295 | |||
2296 | if (total > ISP1362_BUF_SIZE) { | ||
2297 | dev_err(hcd->self.controller, "%s: Memory requested: %d, available %d\n", | ||
2298 | __func__, total, ISP1362_BUF_SIZE); | ||
2299 | return -ENOMEM; | ||
2300 | } | ||
2301 | |||
2302 | total = istl_size + intl_size + atl_size; | ||
2303 | spin_lock_irqsave(&isp1362_hcd->lock, flags); | ||
2304 | |||
2305 | for (i = 0; i < 2; i++) { | ||
2306 | isp1362_hcd->istl_queue[i].buf_start = i * istl_size / 2, | ||
2307 | isp1362_hcd->istl_queue[i].buf_size = istl_size / 2; | ||
2308 | isp1362_hcd->istl_queue[i].blk_size = 4; | ||
2309 | INIT_LIST_HEAD(&isp1362_hcd->istl_queue[i].active); | ||
2310 | snprintf(isp1362_hcd->istl_queue[i].name, | ||
2311 | sizeof(isp1362_hcd->istl_queue[i].name), "ISTL%d", i); | ||
2312 | DBG(3, "%s: %5s buf $%04x %d\n", __func__, | ||
2313 | isp1362_hcd->istl_queue[i].name, | ||
2314 | isp1362_hcd->istl_queue[i].buf_start, | ||
2315 | isp1362_hcd->istl_queue[i].buf_size); | ||
2316 | } | ||
2317 | isp1362_write_reg16(isp1362_hcd, HCISTLBUFSZ, istl_size / 2); | ||
2318 | |||
2319 | isp1362_hcd->intl_queue.buf_start = istl_size; | ||
2320 | isp1362_hcd->intl_queue.buf_size = intl_size; | ||
2321 | isp1362_hcd->intl_queue.buf_count = ISP1362_INTL_BUFFERS; | ||
2322 | isp1362_hcd->intl_queue.blk_size = intl_blksize; | ||
2323 | isp1362_hcd->intl_queue.buf_avail = isp1362_hcd->intl_queue.buf_count; | ||
2324 | isp1362_hcd->intl_queue.skip_map = ~0; | ||
2325 | INIT_LIST_HEAD(&isp1362_hcd->intl_queue.active); | ||
2326 | |||
2327 | isp1362_write_reg16(isp1362_hcd, HCINTLBUFSZ, | ||
2328 | isp1362_hcd->intl_queue.buf_size); | ||
2329 | isp1362_write_reg16(isp1362_hcd, HCINTLBLKSZ, | ||
2330 | isp1362_hcd->intl_queue.blk_size - PTD_HEADER_SIZE); | ||
2331 | isp1362_write_reg32(isp1362_hcd, HCINTLSKIP, ~0); | ||
2332 | isp1362_write_reg32(isp1362_hcd, HCINTLLAST, | ||
2333 | 1 << (ISP1362_INTL_BUFFERS - 1)); | ||
2334 | |||
2335 | isp1362_hcd->atl_queue.buf_start = istl_size + intl_size; | ||
2336 | isp1362_hcd->atl_queue.buf_size = atl_size; | ||
2337 | isp1362_hcd->atl_queue.buf_count = atl_buffers; | ||
2338 | isp1362_hcd->atl_queue.blk_size = atl_blksize; | ||
2339 | isp1362_hcd->atl_queue.buf_avail = isp1362_hcd->atl_queue.buf_count; | ||
2340 | isp1362_hcd->atl_queue.skip_map = ~0; | ||
2341 | INIT_LIST_HEAD(&isp1362_hcd->atl_queue.active); | ||
2342 | |||
2343 | isp1362_write_reg16(isp1362_hcd, HCATLBUFSZ, | ||
2344 | isp1362_hcd->atl_queue.buf_size); | ||
2345 | isp1362_write_reg16(isp1362_hcd, HCATLBLKSZ, | ||
2346 | isp1362_hcd->atl_queue.blk_size - PTD_HEADER_SIZE); | ||
2347 | isp1362_write_reg32(isp1362_hcd, HCATLSKIP, ~0); | ||
2348 | isp1362_write_reg32(isp1362_hcd, HCATLLAST, | ||
2349 | 1 << (atl_buffers - 1)); | ||
2350 | |||
2351 | snprintf(isp1362_hcd->atl_queue.name, | ||
2352 | sizeof(isp1362_hcd->atl_queue.name), "ATL"); | ||
2353 | snprintf(isp1362_hcd->intl_queue.name, | ||
2354 | sizeof(isp1362_hcd->intl_queue.name), "INTL"); | ||
2355 | DBG(3, "%s: %5s buf $%04x %2d * %4d = %4d\n", __func__, | ||
2356 | isp1362_hcd->intl_queue.name, | ||
2357 | isp1362_hcd->intl_queue.buf_start, | ||
2358 | ISP1362_INTL_BUFFERS, isp1362_hcd->intl_queue.blk_size, | ||
2359 | isp1362_hcd->intl_queue.buf_size); | ||
2360 | DBG(3, "%s: %5s buf $%04x %2d * %4d = %4d\n", __func__, | ||
2361 | isp1362_hcd->atl_queue.name, | ||
2362 | isp1362_hcd->atl_queue.buf_start, | ||
2363 | atl_buffers, isp1362_hcd->atl_queue.blk_size, | ||
2364 | isp1362_hcd->atl_queue.buf_size); | ||
2365 | |||
2366 | spin_unlock_irqrestore(&isp1362_hcd->lock, flags); | ||
2367 | |||
2368 | return 0; | ||
2369 | } | ||
2370 | |||
2371 | static int isp1362_hc_reset(struct usb_hcd *hcd) | ||
2372 | { | ||
2373 | int ret = 0; | ||
2374 | struct isp1362_hcd *isp1362_hcd = hcd_to_isp1362_hcd(hcd); | ||
2375 | unsigned long t; | ||
2376 | unsigned long timeout = 100; | ||
2377 | unsigned long flags; | ||
2378 | int clkrdy = 0; | ||
2379 | |||
2380 | pr_info("%s:\n", __func__); | ||
2381 | |||
2382 | if (isp1362_hcd->board && isp1362_hcd->board->reset) { | ||
2383 | isp1362_hcd->board->reset(hcd->self.controller, 1); | ||
2384 | msleep(20); | ||
2385 | if (isp1362_hcd->board->clock) | ||
2386 | isp1362_hcd->board->clock(hcd->self.controller, 1); | ||
2387 | isp1362_hcd->board->reset(hcd->self.controller, 0); | ||
2388 | } else | ||
2389 | isp1362_sw_reset(isp1362_hcd); | ||
2390 | |||
2391 | /* chip has been reset. First we need to see a clock */ | ||
2392 | t = jiffies + msecs_to_jiffies(timeout); | ||
2393 | while (!clkrdy && time_before_eq(jiffies, t)) { | ||
2394 | spin_lock_irqsave(&isp1362_hcd->lock, flags); | ||
2395 | clkrdy = isp1362_read_reg16(isp1362_hcd, HCuPINT) & HCuPINT_CLKRDY; | ||
2396 | spin_unlock_irqrestore(&isp1362_hcd->lock, flags); | ||
2397 | if (!clkrdy) | ||
2398 | msleep(4); | ||
2399 | } | ||
2400 | |||
2401 | spin_lock_irqsave(&isp1362_hcd->lock, flags); | ||
2402 | isp1362_write_reg16(isp1362_hcd, HCuPINT, HCuPINT_CLKRDY); | ||
2403 | spin_unlock_irqrestore(&isp1362_hcd->lock, flags); | ||
2404 | if (!clkrdy) { | ||
2405 | pr_err("Clock not ready after %lums\n", timeout); | ||
2406 | ret = -ENODEV; | ||
2407 | } | ||
2408 | return ret; | ||
2409 | } | ||
2410 | |||
2411 | static void isp1362_hc_stop(struct usb_hcd *hcd) | ||
2412 | { | ||
2413 | struct isp1362_hcd *isp1362_hcd = hcd_to_isp1362_hcd(hcd); | ||
2414 | unsigned long flags; | ||
2415 | u32 tmp; | ||
2416 | |||
2417 | pr_info("%s:\n", __func__); | ||
2418 | |||
2419 | del_timer_sync(&hcd->rh_timer); | ||
2420 | |||
2421 | spin_lock_irqsave(&isp1362_hcd->lock, flags); | ||
2422 | |||
2423 | isp1362_write_reg16(isp1362_hcd, HCuPINTENB, 0); | ||
2424 | |||
2425 | /* Switch off power for all ports */ | ||
2426 | tmp = isp1362_read_reg32(isp1362_hcd, HCRHDESCA); | ||
2427 | tmp &= ~(RH_A_NPS | RH_A_PSM); | ||
2428 | isp1362_write_reg32(isp1362_hcd, HCRHDESCA, tmp); | ||
2429 | isp1362_write_reg32(isp1362_hcd, HCRHSTATUS, RH_HS_LPS); | ||
2430 | |||
2431 | /* Reset the chip */ | ||
2432 | if (isp1362_hcd->board && isp1362_hcd->board->reset) | ||
2433 | isp1362_hcd->board->reset(hcd->self.controller, 1); | ||
2434 | else | ||
2435 | isp1362_sw_reset(isp1362_hcd); | ||
2436 | |||
2437 | if (isp1362_hcd->board && isp1362_hcd->board->clock) | ||
2438 | isp1362_hcd->board->clock(hcd->self.controller, 0); | ||
2439 | |||
2440 | spin_unlock_irqrestore(&isp1362_hcd->lock, flags); | ||
2441 | } | ||
2442 | |||
2443 | #ifdef CHIP_BUFFER_TEST | ||
2444 | static int isp1362_chip_test(struct isp1362_hcd *isp1362_hcd) | ||
2445 | { | ||
2446 | int ret = 0; | ||
2447 | u16 *ref; | ||
2448 | unsigned long flags; | ||
2449 | |||
2450 | ref = kmalloc(2 * ISP1362_BUF_SIZE, GFP_KERNEL); | ||
2451 | if (ref) { | ||
2452 | int offset; | ||
2453 | u16 *tst = &ref[ISP1362_BUF_SIZE / 2]; | ||
2454 | |||
2455 | for (offset = 0; offset < ISP1362_BUF_SIZE / 2; offset++) { | ||
2456 | ref[offset] = ~offset; | ||
2457 | tst[offset] = offset; | ||
2458 | } | ||
2459 | |||
2460 | for (offset = 0; offset < 4; offset++) { | ||
2461 | int j; | ||
2462 | |||
2463 | for (j = 0; j < 8; j++) { | ||
2464 | spin_lock_irqsave(&isp1362_hcd->lock, flags); | ||
2465 | isp1362_write_buffer(isp1362_hcd, (u8 *)ref + offset, 0, j); | ||
2466 | isp1362_read_buffer(isp1362_hcd, (u8 *)tst + offset, 0, j); | ||
2467 | spin_unlock_irqrestore(&isp1362_hcd->lock, flags); | ||
2468 | |||
2469 | if (memcmp(ref, tst, j)) { | ||
2470 | ret = -ENODEV; | ||
2471 | pr_err("%s: memory check with %d byte offset %d failed\n", | ||
2472 | __func__, j, offset); | ||
2473 | dump_data((u8 *)ref + offset, j); | ||
2474 | dump_data((u8 *)tst + offset, j); | ||
2475 | } | ||
2476 | } | ||
2477 | } | ||
2478 | |||
2479 | spin_lock_irqsave(&isp1362_hcd->lock, flags); | ||
2480 | isp1362_write_buffer(isp1362_hcd, ref, 0, ISP1362_BUF_SIZE); | ||
2481 | isp1362_read_buffer(isp1362_hcd, tst, 0, ISP1362_BUF_SIZE); | ||
2482 | spin_unlock_irqrestore(&isp1362_hcd->lock, flags); | ||
2483 | |||
2484 | if (memcmp(ref, tst, ISP1362_BUF_SIZE)) { | ||
2485 | ret = -ENODEV; | ||
2486 | pr_err("%s: memory check failed\n", __func__); | ||
2487 | dump_data((u8 *)tst, ISP1362_BUF_SIZE / 2); | ||
2488 | } | ||
2489 | |||
2490 | for (offset = 0; offset < 256; offset++) { | ||
2491 | int test_size = 0; | ||
2492 | |||
2493 | yield(); | ||
2494 | |||
2495 | memset(tst, 0, ISP1362_BUF_SIZE); | ||
2496 | spin_lock_irqsave(&isp1362_hcd->lock, flags); | ||
2497 | isp1362_write_buffer(isp1362_hcd, tst, 0, ISP1362_BUF_SIZE); | ||
2498 | isp1362_read_buffer(isp1362_hcd, tst, 0, ISP1362_BUF_SIZE); | ||
2499 | spin_unlock_irqrestore(&isp1362_hcd->lock, flags); | ||
2500 | if (memcmp(tst, tst + (ISP1362_BUF_SIZE / (2 * sizeof(*tst))), | ||
2501 | ISP1362_BUF_SIZE / 2)) { | ||
2502 | pr_err("%s: Failed to clear buffer\n", __func__); | ||
2503 | dump_data((u8 *)tst, ISP1362_BUF_SIZE); | ||
2504 | break; | ||
2505 | } | ||
2506 | spin_lock_irqsave(&isp1362_hcd->lock, flags); | ||
2507 | isp1362_write_buffer(isp1362_hcd, ref, offset * 2, PTD_HEADER_SIZE); | ||
2508 | isp1362_write_buffer(isp1362_hcd, ref + PTD_HEADER_SIZE / sizeof(*ref), | ||
2509 | offset * 2 + PTD_HEADER_SIZE, test_size); | ||
2510 | isp1362_read_buffer(isp1362_hcd, tst, offset * 2, | ||
2511 | PTD_HEADER_SIZE + test_size); | ||
2512 | spin_unlock_irqrestore(&isp1362_hcd->lock, flags); | ||
2513 | if (memcmp(ref, tst, PTD_HEADER_SIZE + test_size)) { | ||
2514 | dump_data(((u8 *)ref) + offset, PTD_HEADER_SIZE + test_size); | ||
2515 | dump_data((u8 *)tst, PTD_HEADER_SIZE + test_size); | ||
2516 | spin_lock_irqsave(&isp1362_hcd->lock, flags); | ||
2517 | isp1362_read_buffer(isp1362_hcd, tst, offset * 2, | ||
2518 | PTD_HEADER_SIZE + test_size); | ||
2519 | spin_unlock_irqrestore(&isp1362_hcd->lock, flags); | ||
2520 | if (memcmp(ref, tst, PTD_HEADER_SIZE + test_size)) { | ||
2521 | ret = -ENODEV; | ||
2522 | pr_err("%s: memory check with offset %02x failed\n", | ||
2523 | __func__, offset); | ||
2524 | break; | ||
2525 | } | ||
2526 | pr_warning("%s: memory check with offset %02x ok after second read\n", | ||
2527 | __func__, offset); | ||
2528 | } | ||
2529 | } | ||
2530 | kfree(ref); | ||
2531 | } | ||
2532 | return ret; | ||
2533 | } | ||
2534 | #endif | ||
2535 | |||
2536 | static int isp1362_hc_start(struct usb_hcd *hcd) | ||
2537 | { | ||
2538 | int ret; | ||
2539 | struct isp1362_hcd *isp1362_hcd = hcd_to_isp1362_hcd(hcd); | ||
2540 | struct isp1362_platform_data *board = isp1362_hcd->board; | ||
2541 | u16 hwcfg; | ||
2542 | u16 chipid; | ||
2543 | unsigned long flags; | ||
2544 | |||
2545 | pr_info("%s:\n", __func__); | ||
2546 | |||
2547 | spin_lock_irqsave(&isp1362_hcd->lock, flags); | ||
2548 | chipid = isp1362_read_reg16(isp1362_hcd, HCCHIPID); | ||
2549 | spin_unlock_irqrestore(&isp1362_hcd->lock, flags); | ||
2550 | |||
2551 | if ((chipid & HCCHIPID_MASK) != HCCHIPID_MAGIC) { | ||
2552 | pr_err("%s: Invalid chip ID %04x\n", __func__, chipid); | ||
2553 | return -ENODEV; | ||
2554 | } | ||
2555 | |||
2556 | #ifdef CHIP_BUFFER_TEST | ||
2557 | ret = isp1362_chip_test(isp1362_hcd); | ||
2558 | if (ret) | ||
2559 | return -ENODEV; | ||
2560 | #endif | ||
2561 | spin_lock_irqsave(&isp1362_hcd->lock, flags); | ||
2562 | /* clear interrupt status and disable all interrupt sources */ | ||
2563 | isp1362_write_reg16(isp1362_hcd, HCuPINT, 0xff); | ||
2564 | isp1362_write_reg16(isp1362_hcd, HCuPINTENB, 0); | ||
2565 | |||
2566 | /* HW conf */ | ||
2567 | hwcfg = HCHWCFG_INT_ENABLE | HCHWCFG_DBWIDTH(1); | ||
2568 | if (board->sel15Kres) | ||
2569 | hwcfg |= HCHWCFG_PULLDOWN_DS2 | | ||
2570 | ((MAX_ROOT_PORTS > 1) ? HCHWCFG_PULLDOWN_DS1 : 0); | ||
2571 | if (board->clknotstop) | ||
2572 | hwcfg |= HCHWCFG_CLKNOTSTOP; | ||
2573 | if (board->oc_enable) | ||
2574 | hwcfg |= HCHWCFG_ANALOG_OC; | ||
2575 | if (board->int_act_high) | ||
2576 | hwcfg |= HCHWCFG_INT_POL; | ||
2577 | if (board->int_edge_triggered) | ||
2578 | hwcfg |= HCHWCFG_INT_TRIGGER; | ||
2579 | if (board->dreq_act_high) | ||
2580 | hwcfg |= HCHWCFG_DREQ_POL; | ||
2581 | if (board->dack_act_high) | ||
2582 | hwcfg |= HCHWCFG_DACK_POL; | ||
2583 | isp1362_write_reg16(isp1362_hcd, HCHWCFG, hwcfg); | ||
2584 | isp1362_show_reg(isp1362_hcd, HCHWCFG); | ||
2585 | isp1362_write_reg16(isp1362_hcd, HCDMACFG, 0); | ||
2586 | spin_unlock_irqrestore(&isp1362_hcd->lock, flags); | ||
2587 | |||
2588 | ret = isp1362_mem_config(hcd); | ||
2589 | if (ret) | ||
2590 | return ret; | ||
2591 | |||
2592 | spin_lock_irqsave(&isp1362_hcd->lock, flags); | ||
2593 | |||
2594 | /* Root hub conf */ | ||
2595 | isp1362_hcd->rhdesca = 0; | ||
2596 | if (board->no_power_switching) | ||
2597 | isp1362_hcd->rhdesca |= RH_A_NPS; | ||
2598 | if (board->power_switching_mode) | ||
2599 | isp1362_hcd->rhdesca |= RH_A_PSM; | ||
2600 | if (board->potpg) | ||
2601 | isp1362_hcd->rhdesca |= (board->potpg << 24) & RH_A_POTPGT; | ||
2602 | else | ||
2603 | isp1362_hcd->rhdesca |= (25 << 24) & RH_A_POTPGT; | ||
2604 | |||
2605 | isp1362_write_reg32(isp1362_hcd, HCRHDESCA, isp1362_hcd->rhdesca & ~RH_A_OCPM); | ||
2606 | isp1362_write_reg32(isp1362_hcd, HCRHDESCA, isp1362_hcd->rhdesca | RH_A_OCPM); | ||
2607 | isp1362_hcd->rhdesca = isp1362_read_reg32(isp1362_hcd, HCRHDESCA); | ||
2608 | |||
2609 | isp1362_hcd->rhdescb = RH_B_PPCM; | ||
2610 | isp1362_write_reg32(isp1362_hcd, HCRHDESCB, isp1362_hcd->rhdescb); | ||
2611 | isp1362_hcd->rhdescb = isp1362_read_reg32(isp1362_hcd, HCRHDESCB); | ||
2612 | |||
2613 | isp1362_read_reg32(isp1362_hcd, HCFMINTVL); | ||
2614 | isp1362_write_reg32(isp1362_hcd, HCFMINTVL, (FSMP(FI) << 16) | FI); | ||
2615 | isp1362_write_reg32(isp1362_hcd, HCLSTHRESH, LSTHRESH); | ||
2616 | |||
2617 | spin_unlock_irqrestore(&isp1362_hcd->lock, flags); | ||
2618 | |||
2619 | isp1362_hcd->hc_control = OHCI_USB_OPER; | ||
2620 | hcd->state = HC_STATE_RUNNING; | ||
2621 | |||
2622 | spin_lock_irqsave(&isp1362_hcd->lock, flags); | ||
2623 | /* Set up interrupts */ | ||
2624 | isp1362_hcd->intenb = OHCI_INTR_MIE | OHCI_INTR_RHSC | OHCI_INTR_UE; | ||
2625 | isp1362_hcd->intenb |= OHCI_INTR_RD; | ||
2626 | isp1362_hcd->irqenb = HCuPINT_OPR | HCuPINT_SUSP; | ||
2627 | isp1362_write_reg32(isp1362_hcd, HCINTENB, isp1362_hcd->intenb); | ||
2628 | isp1362_write_reg16(isp1362_hcd, HCuPINTENB, isp1362_hcd->irqenb); | ||
2629 | |||
2630 | /* Go operational */ | ||
2631 | isp1362_write_reg32(isp1362_hcd, HCCONTROL, isp1362_hcd->hc_control); | ||
2632 | /* enable global power */ | ||
2633 | isp1362_write_reg32(isp1362_hcd, HCRHSTATUS, RH_HS_LPSC | RH_HS_DRWE); | ||
2634 | |||
2635 | spin_unlock_irqrestore(&isp1362_hcd->lock, flags); | ||
2636 | |||
2637 | return 0; | ||
2638 | } | ||
2639 | |||
2640 | /*-------------------------------------------------------------------------*/ | ||
2641 | |||
2642 | static struct hc_driver isp1362_hc_driver = { | ||
2643 | .description = hcd_name, | ||
2644 | .product_desc = "ISP1362 Host Controller", | ||
2645 | .hcd_priv_size = sizeof(struct isp1362_hcd), | ||
2646 | |||
2647 | .irq = isp1362_irq, | ||
2648 | .flags = HCD_USB11 | HCD_MEMORY, | ||
2649 | |||
2650 | .reset = isp1362_hc_reset, | ||
2651 | .start = isp1362_hc_start, | ||
2652 | .stop = isp1362_hc_stop, | ||
2653 | |||
2654 | .urb_enqueue = isp1362_urb_enqueue, | ||
2655 | .urb_dequeue = isp1362_urb_dequeue, | ||
2656 | .endpoint_disable = isp1362_endpoint_disable, | ||
2657 | |||
2658 | .get_frame_number = isp1362_get_frame, | ||
2659 | |||
2660 | .hub_status_data = isp1362_hub_status_data, | ||
2661 | .hub_control = isp1362_hub_control, | ||
2662 | .bus_suspend = isp1362_bus_suspend, | ||
2663 | .bus_resume = isp1362_bus_resume, | ||
2664 | }; | ||
2665 | |||
2666 | /*-------------------------------------------------------------------------*/ | ||
2667 | |||
2668 | #define resource_len(r) (((r)->end - (r)->start) + 1) | ||
2669 | |||
2670 | static int __devexit isp1362_remove(struct platform_device *pdev) | ||
2671 | { | ||
2672 | struct usb_hcd *hcd = platform_get_drvdata(pdev); | ||
2673 | struct isp1362_hcd *isp1362_hcd = hcd_to_isp1362_hcd(hcd); | ||
2674 | struct resource *res; | ||
2675 | |||
2676 | remove_debug_file(isp1362_hcd); | ||
2677 | DBG(0, "%s: Removing HCD\n", __func__); | ||
2678 | usb_remove_hcd(hcd); | ||
2679 | |||
2680 | DBG(0, "%s: Unmapping data_reg @ %08x\n", __func__, | ||
2681 | (u32)isp1362_hcd->data_reg); | ||
2682 | iounmap(isp1362_hcd->data_reg); | ||
2683 | |||
2684 | DBG(0, "%s: Unmapping addr_reg @ %08x\n", __func__, | ||
2685 | (u32)isp1362_hcd->addr_reg); | ||
2686 | iounmap(isp1362_hcd->addr_reg); | ||
2687 | |||
2688 | res = platform_get_resource(pdev, IORESOURCE_MEM, 1); | ||
2689 | DBG(0, "%s: release mem_region: %08lx\n", __func__, (long unsigned int)res->start); | ||
2690 | if (res) | ||
2691 | release_mem_region(res->start, resource_len(res)); | ||
2692 | |||
2693 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); | ||
2694 | DBG(0, "%s: release mem_region: %08lx\n", __func__, (long unsigned int)res->start); | ||
2695 | if (res) | ||
2696 | release_mem_region(res->start, resource_len(res)); | ||
2697 | |||
2698 | DBG(0, "%s: put_hcd\n", __func__); | ||
2699 | usb_put_hcd(hcd); | ||
2700 | DBG(0, "%s: Done\n", __func__); | ||
2701 | |||
2702 | return 0; | ||
2703 | } | ||
2704 | |||
2705 | static int __init isp1362_probe(struct platform_device *pdev) | ||
2706 | { | ||
2707 | struct usb_hcd *hcd; | ||
2708 | struct isp1362_hcd *isp1362_hcd; | ||
2709 | struct resource *addr, *data; | ||
2710 | void __iomem *addr_reg; | ||
2711 | void __iomem *data_reg; | ||
2712 | int irq; | ||
2713 | int retval = 0; | ||
2714 | |||
2715 | /* basic sanity checks first. board-specific init logic should | ||
2716 | * have initialized this the three resources and probably board | ||
2717 | * specific platform_data. we don't probe for IRQs, and do only | ||
2718 | * minimal sanity checking. | ||
2719 | */ | ||
2720 | if (pdev->num_resources < 3) { | ||
2721 | retval = -ENODEV; | ||
2722 | goto err1; | ||
2723 | } | ||
2724 | |||
2725 | data = platform_get_resource(pdev, IORESOURCE_MEM, 0); | ||
2726 | addr = platform_get_resource(pdev, IORESOURCE_MEM, 1); | ||
2727 | irq = platform_get_irq(pdev, 0); | ||
2728 | if (!addr || !data || irq < 0) { | ||
2729 | retval = -ENODEV; | ||
2730 | goto err1; | ||
2731 | } | ||
2732 | |||
2733 | #ifdef CONFIG_USB_HCD_DMA | ||
2734 | if (pdev->dev.dma_mask) { | ||
2735 | struct resource *dma_res = platform_get_resource(pdev, IORESOURCE_MEM, 2); | ||
2736 | |||
2737 | if (!dma_res) { | ||
2738 | retval = -ENODEV; | ||
2739 | goto err1; | ||
2740 | } | ||
2741 | isp1362_hcd->data_dma = dma_res->start; | ||
2742 | isp1362_hcd->max_dma_size = resource_len(dma_res); | ||
2743 | } | ||
2744 | #else | ||
2745 | if (pdev->dev.dma_mask) { | ||
2746 | DBG(1, "won't do DMA"); | ||
2747 | retval = -ENODEV; | ||
2748 | goto err1; | ||
2749 | } | ||
2750 | #endif | ||
2751 | |||
2752 | if (!request_mem_region(addr->start, resource_len(addr), hcd_name)) { | ||
2753 | retval = -EBUSY; | ||
2754 | goto err1; | ||
2755 | } | ||
2756 | addr_reg = ioremap(addr->start, resource_len(addr)); | ||
2757 | if (addr_reg == NULL) { | ||
2758 | retval = -ENOMEM; | ||
2759 | goto err2; | ||
2760 | } | ||
2761 | |||
2762 | if (!request_mem_region(data->start, resource_len(data), hcd_name)) { | ||
2763 | retval = -EBUSY; | ||
2764 | goto err3; | ||
2765 | } | ||
2766 | data_reg = ioremap(data->start, resource_len(data)); | ||
2767 | if (data_reg == NULL) { | ||
2768 | retval = -ENOMEM; | ||
2769 | goto err4; | ||
2770 | } | ||
2771 | |||
2772 | /* allocate and initialize hcd */ | ||
2773 | hcd = usb_create_hcd(&isp1362_hc_driver, &pdev->dev, dev_name(&pdev->dev)); | ||
2774 | if (!hcd) { | ||
2775 | retval = -ENOMEM; | ||
2776 | goto err5; | ||
2777 | } | ||
2778 | hcd->rsrc_start = data->start; | ||
2779 | isp1362_hcd = hcd_to_isp1362_hcd(hcd); | ||
2780 | isp1362_hcd->data_reg = data_reg; | ||
2781 | isp1362_hcd->addr_reg = addr_reg; | ||
2782 | |||
2783 | isp1362_hcd->next_statechange = jiffies; | ||
2784 | spin_lock_init(&isp1362_hcd->lock); | ||
2785 | INIT_LIST_HEAD(&isp1362_hcd->async); | ||
2786 | INIT_LIST_HEAD(&isp1362_hcd->periodic); | ||
2787 | INIT_LIST_HEAD(&isp1362_hcd->isoc); | ||
2788 | INIT_LIST_HEAD(&isp1362_hcd->remove_list); | ||
2789 | isp1362_hcd->board = pdev->dev.platform_data; | ||
2790 | #if USE_PLATFORM_DELAY | ||
2791 | if (!isp1362_hcd->board->delay) { | ||
2792 | dev_err(hcd->self.controller, "No platform delay function given\n"); | ||
2793 | retval = -ENODEV; | ||
2794 | goto err6; | ||
2795 | } | ||
2796 | #endif | ||
2797 | |||
2798 | #ifdef CONFIG_ARM | ||
2799 | if (isp1362_hcd->board) | ||
2800 | set_irq_type(irq, isp1362_hcd->board->int_act_high ? IRQT_RISING : IRQT_FALLING); | ||
2801 | #endif | ||
2802 | |||
2803 | retval = usb_add_hcd(hcd, irq, IRQF_TRIGGER_LOW | IRQF_DISABLED | IRQF_SHARED); | ||
2804 | if (retval != 0) | ||
2805 | goto err6; | ||
2806 | pr_info("%s, irq %d\n", hcd->product_desc, irq); | ||
2807 | |||
2808 | create_debug_file(isp1362_hcd); | ||
2809 | |||
2810 | return 0; | ||
2811 | |||
2812 | err6: | ||
2813 | DBG(0, "%s: Freeing dev %08x\n", __func__, (u32)isp1362_hcd); | ||
2814 | usb_put_hcd(hcd); | ||
2815 | err5: | ||
2816 | DBG(0, "%s: Unmapping data_reg @ %08x\n", __func__, (u32)data_reg); | ||
2817 | iounmap(data_reg); | ||
2818 | err4: | ||
2819 | DBG(0, "%s: Releasing mem region %08lx\n", __func__, (long unsigned int)data->start); | ||
2820 | release_mem_region(data->start, resource_len(data)); | ||
2821 | err3: | ||
2822 | DBG(0, "%s: Unmapping addr_reg @ %08x\n", __func__, (u32)addr_reg); | ||
2823 | iounmap(addr_reg); | ||
2824 | err2: | ||
2825 | DBG(0, "%s: Releasing mem region %08lx\n", __func__, (long unsigned int)addr->start); | ||
2826 | release_mem_region(addr->start, resource_len(addr)); | ||
2827 | err1: | ||
2828 | pr_err("%s: init error, %d\n", __func__, retval); | ||
2829 | |||
2830 | return retval; | ||
2831 | } | ||
2832 | |||
2833 | #ifdef CONFIG_PM | ||
2834 | static int isp1362_suspend(struct platform_device *pdev, pm_message_t state) | ||
2835 | { | ||
2836 | struct usb_hcd *hcd = platform_get_drvdata(pdev); | ||
2837 | struct isp1362_hcd *isp1362_hcd = hcd_to_isp1362_hcd(hcd); | ||
2838 | unsigned long flags; | ||
2839 | int retval = 0; | ||
2840 | |||
2841 | DBG(0, "%s: Suspending device\n", __func__); | ||
2842 | |||
2843 | if (state.event == PM_EVENT_FREEZE) { | ||
2844 | DBG(0, "%s: Suspending root hub\n", __func__); | ||
2845 | retval = isp1362_bus_suspend(hcd); | ||
2846 | } else { | ||
2847 | DBG(0, "%s: Suspending RH ports\n", __func__); | ||
2848 | spin_lock_irqsave(&isp1362_hcd->lock, flags); | ||
2849 | isp1362_write_reg32(isp1362_hcd, HCRHSTATUS, RH_HS_LPS); | ||
2850 | spin_unlock_irqrestore(&isp1362_hcd->lock, flags); | ||
2851 | } | ||
2852 | if (retval == 0) | ||
2853 | pdev->dev.power.power_state = state; | ||
2854 | return retval; | ||
2855 | } | ||
2856 | |||
2857 | static int isp1362_resume(struct platform_device *pdev) | ||
2858 | { | ||
2859 | struct usb_hcd *hcd = platform_get_drvdata(pdev); | ||
2860 | struct isp1362_hcd *isp1362_hcd = hcd_to_isp1362_hcd(hcd); | ||
2861 | unsigned long flags; | ||
2862 | |||
2863 | DBG(0, "%s: Resuming\n", __func__); | ||
2864 | |||
2865 | if (pdev->dev.power.power_state.event == PM_EVENT_SUSPEND) { | ||
2866 | DBG(0, "%s: Resume RH ports\n", __func__); | ||
2867 | spin_lock_irqsave(&isp1362_hcd->lock, flags); | ||
2868 | isp1362_write_reg32(isp1362_hcd, HCRHSTATUS, RH_HS_LPSC); | ||
2869 | spin_unlock_irqrestore(&isp1362_hcd->lock, flags); | ||
2870 | return 0; | ||
2871 | } | ||
2872 | |||
2873 | pdev->dev.power.power_state = PMSG_ON; | ||
2874 | |||
2875 | return isp1362_bus_resume(isp1362_hcd_to_hcd(isp1362_hcd)); | ||
2876 | } | ||
2877 | #else | ||
2878 | #define isp1362_suspend NULL | ||
2879 | #define isp1362_resume NULL | ||
2880 | #endif | ||
2881 | |||
2882 | static struct platform_driver isp1362_driver = { | ||
2883 | .probe = isp1362_probe, | ||
2884 | .remove = __devexit_p(isp1362_remove), | ||
2885 | |||
2886 | .suspend = isp1362_suspend, | ||
2887 | .resume = isp1362_resume, | ||
2888 | .driver = { | ||
2889 | .name = (char *)hcd_name, | ||
2890 | .owner = THIS_MODULE, | ||
2891 | }, | ||
2892 | }; | ||
2893 | |||
2894 | /*-------------------------------------------------------------------------*/ | ||
2895 | |||
2896 | static int __init isp1362_init(void) | ||
2897 | { | ||
2898 | if (usb_disabled()) | ||
2899 | return -ENODEV; | ||
2900 | pr_info("driver %s, %s\n", hcd_name, DRIVER_VERSION); | ||
2901 | return platform_driver_register(&isp1362_driver); | ||
2902 | } | ||
2903 | module_init(isp1362_init); | ||
2904 | |||
2905 | static void __exit isp1362_cleanup(void) | ||
2906 | { | ||
2907 | platform_driver_unregister(&isp1362_driver); | ||
2908 | } | ||
2909 | module_exit(isp1362_cleanup); | ||
diff --git a/drivers/usb/host/isp1362.h b/drivers/usb/host/isp1362.h new file mode 100644 index 000000000000..fe60f62a32f3 --- /dev/null +++ b/drivers/usb/host/isp1362.h | |||
@@ -0,0 +1,1079 @@ | |||
1 | /* | ||
2 | * ISP1362 HCD (Host Controller Driver) for USB. | ||
3 | * | ||
4 | * COPYRIGHT (C) by L. Wassmann <LW@KARO-electronics.de> | ||
5 | */ | ||
6 | |||
7 | /* ------------------------------------------------------------------------- */ | ||
8 | /* | ||
9 | * Platform specific compile time options | ||
10 | */ | ||
11 | #if defined(CONFIG_ARCH_KARO) | ||
12 | #include <asm/arch/hardware.h> | ||
13 | #include <asm/arch/pxa-regs.h> | ||
14 | #include <asm/arch/karo.h> | ||
15 | |||
16 | #define USE_32BIT 1 | ||
17 | |||
18 | |||
19 | /* These options are mutually eclusive */ | ||
20 | #define USE_PLATFORM_DELAY 1 | ||
21 | #define USE_NDELAY 0 | ||
22 | /* | ||
23 | * MAX_ROOT_PORTS: Number of downstream ports | ||
24 | * | ||
25 | * The chip has two USB ports, one of which can be configured as | ||
26 | * an USB device port, so the value of this constant is implementation | ||
27 | * specific. | ||
28 | */ | ||
29 | #define MAX_ROOT_PORTS 2 | ||
30 | #define DUMMY_DELAY_ACCESS do {} while (0) | ||
31 | |||
32 | /* insert platform specific definitions for other machines here */ | ||
33 | #elif defined(CONFIG_BLACKFIN) | ||
34 | |||
35 | #include <linux/io.h> | ||
36 | #define USE_32BIT 0 | ||
37 | #define MAX_ROOT_PORTS 2 | ||
38 | #define USE_PLATFORM_DELAY 0 | ||
39 | #define USE_NDELAY 1 | ||
40 | |||
41 | #define DUMMY_DELAY_ACCESS \ | ||
42 | do { \ | ||
43 | bfin_read16(ASYNC_BANK0_BASE); \ | ||
44 | bfin_read16(ASYNC_BANK0_BASE); \ | ||
45 | bfin_read16(ASYNC_BANK0_BASE); \ | ||
46 | } while (0) | ||
47 | |||
48 | #undef insw | ||
49 | #undef outsw | ||
50 | |||
51 | #define insw delayed_insw | ||
52 | #define outsw delayed_outsw | ||
53 | |||
54 | static inline void delayed_outsw(unsigned int addr, void *buf, int len) | ||
55 | { | ||
56 | unsigned short *bp = (unsigned short *)buf; | ||
57 | while (len--) { | ||
58 | DUMMY_DELAY_ACCESS; | ||
59 | outw(*bp++, addr); | ||
60 | } | ||
61 | } | ||
62 | |||
63 | static inline void delayed_insw(unsigned int addr, void *buf, int len) | ||
64 | { | ||
65 | unsigned short *bp = (unsigned short *)buf; | ||
66 | while (len--) { | ||
67 | DUMMY_DELAY_ACCESS; | ||
68 | *bp++ = inw((void *)addr); | ||
69 | } | ||
70 | } | ||
71 | |||
72 | #else | ||
73 | |||
74 | #define MAX_ROOT_PORTS 2 | ||
75 | |||
76 | #define USE_32BIT 0 | ||
77 | |||
78 | /* These options are mutually eclusive */ | ||
79 | #define USE_PLATFORM_DELAY 0 | ||
80 | #define USE_NDELAY 0 | ||
81 | |||
82 | #define DUMMY_DELAY_ACCESS do {} while (0) | ||
83 | |||
84 | #endif | ||
85 | |||
86 | |||
87 | /* ------------------------------------------------------------------------- */ | ||
88 | |||
89 | #define USB_RESET_WIDTH 50 | ||
90 | #define MAX_XFER_SIZE 1023 | ||
91 | |||
92 | /* Buffer sizes */ | ||
93 | #define ISP1362_BUF_SIZE 4096 | ||
94 | #define ISP1362_ISTL_BUFSIZE 512 | ||
95 | #define ISP1362_INTL_BLKSIZE 64 | ||
96 | #define ISP1362_INTL_BUFFERS 16 | ||
97 | #define ISP1362_ATL_BLKSIZE 64 | ||
98 | |||
99 | #define ISP1362_REG_WRITE_OFFSET 0x80 | ||
100 | |||
101 | #ifdef ISP1362_DEBUG | ||
102 | typedef const unsigned int isp1362_reg_t; | ||
103 | |||
104 | #define REG_WIDTH_16 0x000 | ||
105 | #define REG_WIDTH_32 0x100 | ||
106 | #define REG_WIDTH_MASK 0x100 | ||
107 | #define REG_NO_MASK 0x0ff | ||
108 | |||
109 | #define REG_ACCESS_R 0x200 | ||
110 | #define REG_ACCESS_W 0x400 | ||
111 | #define REG_ACCESS_RW 0x600 | ||
112 | #define REG_ACCESS_MASK 0x600 | ||
113 | |||
114 | #define ISP1362_REG_NO(r) ((r) & REG_NO_MASK) | ||
115 | |||
116 | #define _BUG_ON(x) BUG_ON(x) | ||
117 | #define _WARN_ON(x) WARN_ON(x) | ||
118 | |||
119 | #define ISP1362_REG(name, addr, width, rw) \ | ||
120 | static isp1362_reg_t ISP1362_REG_##name = ((addr) | (width) | (rw)) | ||
121 | |||
122 | #define REG_ACCESS_TEST(r) BUG_ON(((r) & ISP1362_REG_WRITE_OFFSET) && !((r) & REG_ACCESS_W)) | ||
123 | #define REG_WIDTH_TEST(r, w) BUG_ON(((r) & REG_WIDTH_MASK) != (w)) | ||
124 | #else | ||
125 | typedef const unsigned char isp1362_reg_t; | ||
126 | #define ISP1362_REG_NO(r) (r) | ||
127 | #define _BUG_ON(x) do {} while (0) | ||
128 | #define _WARN_ON(x) do {} while (0) | ||
129 | |||
130 | #define ISP1362_REG(name, addr, width, rw) \ | ||
131 | static isp1362_reg_t ISP1362_REG_##name = addr | ||
132 | |||
133 | #define REG_ACCESS_TEST(r) do {} while (0) | ||
134 | #define REG_WIDTH_TEST(r, w) do {} while (0) | ||
135 | #endif | ||
136 | |||
137 | /* OHCI compatible registers */ | ||
138 | /* | ||
139 | * Note: Some of the ISP1362 'OHCI' registers implement only | ||
140 | * a subset of the bits defined in the OHCI spec. | ||
141 | * | ||
142 | * Bitmasks for the individual bits of these registers are defined in "ohci.h" | ||
143 | */ | ||
144 | ISP1362_REG(HCREVISION, 0x00, REG_WIDTH_32, REG_ACCESS_R); | ||
145 | ISP1362_REG(HCCONTROL, 0x01, REG_WIDTH_32, REG_ACCESS_RW); | ||
146 | ISP1362_REG(HCCMDSTAT, 0x02, REG_WIDTH_32, REG_ACCESS_RW); | ||
147 | ISP1362_REG(HCINTSTAT, 0x03, REG_WIDTH_32, REG_ACCESS_RW); | ||
148 | ISP1362_REG(HCINTENB, 0x04, REG_WIDTH_32, REG_ACCESS_RW); | ||
149 | ISP1362_REG(HCINTDIS, 0x05, REG_WIDTH_32, REG_ACCESS_RW); | ||
150 | ISP1362_REG(HCFMINTVL, 0x0d, REG_WIDTH_32, REG_ACCESS_RW); | ||
151 | ISP1362_REG(HCFMREM, 0x0e, REG_WIDTH_32, REG_ACCESS_RW); | ||
152 | ISP1362_REG(HCFMNUM, 0x0f, REG_WIDTH_32, REG_ACCESS_RW); | ||
153 | ISP1362_REG(HCLSTHRESH, 0x11, REG_WIDTH_32, REG_ACCESS_RW); | ||
154 | ISP1362_REG(HCRHDESCA, 0x12, REG_WIDTH_32, REG_ACCESS_RW); | ||
155 | ISP1362_REG(HCRHDESCB, 0x13, REG_WIDTH_32, REG_ACCESS_RW); | ||
156 | ISP1362_REG(HCRHSTATUS, 0x14, REG_WIDTH_32, REG_ACCESS_RW); | ||
157 | ISP1362_REG(HCRHPORT1, 0x15, REG_WIDTH_32, REG_ACCESS_RW); | ||
158 | ISP1362_REG(HCRHPORT2, 0x16, REG_WIDTH_32, REG_ACCESS_RW); | ||
159 | |||
160 | /* Philips ISP1362 specific registers */ | ||
161 | ISP1362_REG(HCHWCFG, 0x20, REG_WIDTH_16, REG_ACCESS_RW); | ||
162 | #define HCHWCFG_DISABLE_SUSPEND (1 << 15) | ||
163 | #define HCHWCFG_GLOBAL_PWRDOWN (1 << 14) | ||
164 | #define HCHWCFG_PULLDOWN_DS2 (1 << 13) | ||
165 | #define HCHWCFG_PULLDOWN_DS1 (1 << 12) | ||
166 | #define HCHWCFG_CLKNOTSTOP (1 << 11) | ||
167 | #define HCHWCFG_ANALOG_OC (1 << 10) | ||
168 | #define HCHWCFG_ONEINT (1 << 9) | ||
169 | #define HCHWCFG_DACK_MODE (1 << 8) | ||
170 | #define HCHWCFG_ONEDMA (1 << 7) | ||
171 | #define HCHWCFG_DACK_POL (1 << 6) | ||
172 | #define HCHWCFG_DREQ_POL (1 << 5) | ||
173 | #define HCHWCFG_DBWIDTH_MASK (0x03 << 3) | ||
174 | #define HCHWCFG_DBWIDTH(n) (((n) << 3) & HCHWCFG_DBWIDTH_MASK) | ||
175 | #define HCHWCFG_INT_POL (1 << 2) | ||
176 | #define HCHWCFG_INT_TRIGGER (1 << 1) | ||
177 | #define HCHWCFG_INT_ENABLE (1 << 0) | ||
178 | |||
179 | ISP1362_REG(HCDMACFG, 0x21, REG_WIDTH_16, REG_ACCESS_RW); | ||
180 | #define HCDMACFG_CTR_ENABLE (1 << 7) | ||
181 | #define HCDMACFG_BURST_LEN_MASK (0x03 << 5) | ||
182 | #define HCDMACFG_BURST_LEN(n) (((n) << 5) & HCDMACFG_BURST_LEN_MASK) | ||
183 | #define HCDMACFG_BURST_LEN_1 HCDMACFG_BURST_LEN(0) | ||
184 | #define HCDMACFG_BURST_LEN_4 HCDMACFG_BURST_LEN(1) | ||
185 | #define HCDMACFG_BURST_LEN_8 HCDMACFG_BURST_LEN(2) | ||
186 | #define HCDMACFG_DMA_ENABLE (1 << 4) | ||
187 | #define HCDMACFG_BUF_TYPE_MASK (0x07 << 1) | ||
188 | #define HCDMACFG_BUF_TYPE(n) (((n) << 1) & HCDMACFG_BUF_TYPE_MASK) | ||
189 | #define HCDMACFG_BUF_ISTL0 HCDMACFG_BUF_TYPE(0) | ||
190 | #define HCDMACFG_BUF_ISTL1 HCDMACFG_BUF_TYPE(1) | ||
191 | #define HCDMACFG_BUF_INTL HCDMACFG_BUF_TYPE(2) | ||
192 | #define HCDMACFG_BUF_ATL HCDMACFG_BUF_TYPE(3) | ||
193 | #define HCDMACFG_BUF_DIRECT HCDMACFG_BUF_TYPE(4) | ||
194 | #define HCDMACFG_DMA_RW_SELECT (1 << 0) | ||
195 | |||
196 | ISP1362_REG(HCXFERCTR, 0x22, REG_WIDTH_16, REG_ACCESS_RW); | ||
197 | |||
198 | ISP1362_REG(HCuPINT, 0x24, REG_WIDTH_16, REG_ACCESS_RW); | ||
199 | #define HCuPINT_SOF (1 << 0) | ||
200 | #define HCuPINT_ISTL0 (1 << 1) | ||
201 | #define HCuPINT_ISTL1 (1 << 2) | ||
202 | #define HCuPINT_EOT (1 << 3) | ||
203 | #define HCuPINT_OPR (1 << 4) | ||
204 | #define HCuPINT_SUSP (1 << 5) | ||
205 | #define HCuPINT_CLKRDY (1 << 6) | ||
206 | #define HCuPINT_INTL (1 << 7) | ||
207 | #define HCuPINT_ATL (1 << 8) | ||
208 | #define HCuPINT_OTG (1 << 9) | ||
209 | |||
210 | ISP1362_REG(HCuPINTENB, 0x25, REG_WIDTH_16, REG_ACCESS_RW); | ||
211 | /* same bit definitions apply as for HCuPINT */ | ||
212 | |||
213 | ISP1362_REG(HCCHIPID, 0x27, REG_WIDTH_16, REG_ACCESS_R); | ||
214 | #define HCCHIPID_MASK 0xff00 | ||
215 | #define HCCHIPID_MAGIC 0x3600 | ||
216 | |||
217 | ISP1362_REG(HCSCRATCH, 0x28, REG_WIDTH_16, REG_ACCESS_RW); | ||
218 | |||
219 | ISP1362_REG(HCSWRES, 0x29, REG_WIDTH_16, REG_ACCESS_W); | ||
220 | #define HCSWRES_MAGIC 0x00f6 | ||
221 | |||
222 | ISP1362_REG(HCBUFSTAT, 0x2c, REG_WIDTH_16, REG_ACCESS_RW); | ||
223 | #define HCBUFSTAT_ISTL0_FULL (1 << 0) | ||
224 | #define HCBUFSTAT_ISTL1_FULL (1 << 1) | ||
225 | #define HCBUFSTAT_INTL_ACTIVE (1 << 2) | ||
226 | #define HCBUFSTAT_ATL_ACTIVE (1 << 3) | ||
227 | #define HCBUFSTAT_RESET_HWPP (1 << 4) | ||
228 | #define HCBUFSTAT_ISTL0_ACTIVE (1 << 5) | ||
229 | #define HCBUFSTAT_ISTL1_ACTIVE (1 << 6) | ||
230 | #define HCBUFSTAT_ISTL0_DONE (1 << 8) | ||
231 | #define HCBUFSTAT_ISTL1_DONE (1 << 9) | ||
232 | #define HCBUFSTAT_PAIRED_PTDPP (1 << 10) | ||
233 | |||
234 | ISP1362_REG(HCDIRADDR, 0x32, REG_WIDTH_32, REG_ACCESS_RW); | ||
235 | #define HCDIRADDR_ADDR_MASK 0x0000ffff | ||
236 | #define HCDIRADDR_ADDR(n) (((n) << 0) & HCDIRADDR_ADDR_MASK) | ||
237 | #define HCDIRADDR_COUNT_MASK 0xffff0000 | ||
238 | #define HCDIRADDR_COUNT(n) (((n) << 16) & HCDIRADDR_COUNT_MASK) | ||
239 | ISP1362_REG(HCDIRDATA, 0x45, REG_WIDTH_16, REG_ACCESS_RW); | ||
240 | |||
241 | ISP1362_REG(HCISTLBUFSZ, 0x30, REG_WIDTH_16, REG_ACCESS_RW); | ||
242 | ISP1362_REG(HCISTL0PORT, 0x40, REG_WIDTH_16, REG_ACCESS_RW); | ||
243 | ISP1362_REG(HCISTL1PORT, 0x42, REG_WIDTH_16, REG_ACCESS_RW); | ||
244 | ISP1362_REG(HCISTLRATE, 0x47, REG_WIDTH_16, REG_ACCESS_RW); | ||
245 | |||
246 | ISP1362_REG(HCINTLBUFSZ, 0x33, REG_WIDTH_16, REG_ACCESS_RW); | ||
247 | ISP1362_REG(HCINTLPORT, 0x43, REG_WIDTH_16, REG_ACCESS_RW); | ||
248 | ISP1362_REG(HCINTLBLKSZ, 0x53, REG_WIDTH_16, REG_ACCESS_RW); | ||
249 | ISP1362_REG(HCINTLDONE, 0x17, REG_WIDTH_32, REG_ACCESS_R); | ||
250 | ISP1362_REG(HCINTLSKIP, 0x18, REG_WIDTH_32, REG_ACCESS_RW); | ||
251 | ISP1362_REG(HCINTLLAST, 0x19, REG_WIDTH_32, REG_ACCESS_RW); | ||
252 | ISP1362_REG(HCINTLCURR, 0x1a, REG_WIDTH_16, REG_ACCESS_R); | ||
253 | |||
254 | ISP1362_REG(HCATLBUFSZ, 0x34, REG_WIDTH_16, REG_ACCESS_RW); | ||
255 | ISP1362_REG(HCATLPORT, 0x44, REG_WIDTH_16, REG_ACCESS_RW); | ||
256 | ISP1362_REG(HCATLBLKSZ, 0x54, REG_WIDTH_16, REG_ACCESS_RW); | ||
257 | ISP1362_REG(HCATLDONE, 0x1b, REG_WIDTH_32, REG_ACCESS_R); | ||
258 | ISP1362_REG(HCATLSKIP, 0x1c, REG_WIDTH_32, REG_ACCESS_RW); | ||
259 | ISP1362_REG(HCATLLAST, 0x1d, REG_WIDTH_32, REG_ACCESS_RW); | ||
260 | ISP1362_REG(HCATLCURR, 0x1e, REG_WIDTH_16, REG_ACCESS_R); | ||
261 | |||
262 | ISP1362_REG(HCATLDTC, 0x51, REG_WIDTH_16, REG_ACCESS_RW); | ||
263 | ISP1362_REG(HCATLDTCTO, 0x52, REG_WIDTH_16, REG_ACCESS_RW); | ||
264 | |||
265 | |||
266 | ISP1362_REG(OTGCONTROL, 0x62, REG_WIDTH_16, REG_ACCESS_RW); | ||
267 | ISP1362_REG(OTGSTATUS, 0x67, REG_WIDTH_16, REG_ACCESS_R); | ||
268 | ISP1362_REG(OTGINT, 0x68, REG_WIDTH_16, REG_ACCESS_RW); | ||
269 | ISP1362_REG(OTGINTENB, 0x69, REG_WIDTH_16, REG_ACCESS_RW); | ||
270 | ISP1362_REG(OTGTIMER, 0x6A, REG_WIDTH_16, REG_ACCESS_RW); | ||
271 | ISP1362_REG(OTGALTTMR, 0x6C, REG_WIDTH_16, REG_ACCESS_RW); | ||
272 | |||
273 | /* Philips transfer descriptor, cpu-endian */ | ||
274 | struct ptd { | ||
275 | u16 count; | ||
276 | #define PTD_COUNT_MSK (0x3ff << 0) | ||
277 | #define PTD_TOGGLE_MSK (1 << 10) | ||
278 | #define PTD_ACTIVE_MSK (1 << 11) | ||
279 | #define PTD_CC_MSK (0xf << 12) | ||
280 | u16 mps; | ||
281 | #define PTD_MPS_MSK (0x3ff << 0) | ||
282 | #define PTD_SPD_MSK (1 << 10) | ||
283 | #define PTD_LAST_MSK (1 << 11) | ||
284 | #define PTD_EP_MSK (0xf << 12) | ||
285 | u16 len; | ||
286 | #define PTD_LEN_MSK (0x3ff << 0) | ||
287 | #define PTD_DIR_MSK (3 << 10) | ||
288 | #define PTD_DIR_SETUP (0) | ||
289 | #define PTD_DIR_OUT (1) | ||
290 | #define PTD_DIR_IN (2) | ||
291 | u16 faddr; | ||
292 | #define PTD_FA_MSK (0x7f << 0) | ||
293 | /* PTD Byte 7: [StartingFrame (if ISO PTD) | StartingFrame[0..4], PollingRate[0..2] (if INT PTD)] */ | ||
294 | #define PTD_SF_ISO_MSK (0xff << 8) | ||
295 | #define PTD_SF_INT_MSK (0x1f << 8) | ||
296 | #define PTD_PR_MSK (0x07 << 13) | ||
297 | } __attribute__ ((packed, aligned(2))); | ||
298 | #define PTD_HEADER_SIZE sizeof(struct ptd) | ||
299 | |||
300 | /* ------------------------------------------------------------------------- */ | ||
301 | /* Copied from ohci.h: */ | ||
302 | /* | ||
303 | * Hardware transfer status codes -- CC from PTD | ||
304 | */ | ||
305 | #define PTD_CC_NOERROR 0x00 | ||
306 | #define PTD_CC_CRC 0x01 | ||
307 | #define PTD_CC_BITSTUFFING 0x02 | ||
308 | #define PTD_CC_DATATOGGLEM 0x03 | ||
309 | #define PTD_CC_STALL 0x04 | ||
310 | #define PTD_DEVNOTRESP 0x05 | ||
311 | #define PTD_PIDCHECKFAIL 0x06 | ||
312 | #define PTD_UNEXPECTEDPID 0x07 | ||
313 | #define PTD_DATAOVERRUN 0x08 | ||
314 | #define PTD_DATAUNDERRUN 0x09 | ||
315 | /* 0x0A, 0x0B reserved for hardware */ | ||
316 | #define PTD_BUFFEROVERRUN 0x0C | ||
317 | #define PTD_BUFFERUNDERRUN 0x0D | ||
318 | /* 0x0E, 0x0F reserved for HCD */ | ||
319 | #define PTD_NOTACCESSED 0x0F | ||
320 | |||
321 | |||
322 | /* map OHCI TD status codes (CC) to errno values */ | ||
323 | static const int cc_to_error[16] = { | ||
324 | /* No Error */ 0, | ||
325 | /* CRC Error */ -EILSEQ, | ||
326 | /* Bit Stuff */ -EPROTO, | ||
327 | /* Data Togg */ -EILSEQ, | ||
328 | /* Stall */ -EPIPE, | ||
329 | /* DevNotResp */ -ETIMEDOUT, | ||
330 | /* PIDCheck */ -EPROTO, | ||
331 | /* UnExpPID */ -EPROTO, | ||
332 | /* DataOver */ -EOVERFLOW, | ||
333 | /* DataUnder */ -EREMOTEIO, | ||
334 | /* (for hw) */ -EIO, | ||
335 | /* (for hw) */ -EIO, | ||
336 | /* BufferOver */ -ECOMM, | ||
337 | /* BuffUnder */ -ENOSR, | ||
338 | /* (for HCD) */ -EALREADY, | ||
339 | /* (for HCD) */ -EALREADY | ||
340 | }; | ||
341 | |||
342 | |||
343 | /* | ||
344 | * HcControl (control) register masks | ||
345 | */ | ||
346 | #define OHCI_CTRL_HCFS (3 << 6) /* host controller functional state */ | ||
347 | #define OHCI_CTRL_RWC (1 << 9) /* remote wakeup connected */ | ||
348 | #define OHCI_CTRL_RWE (1 << 10) /* remote wakeup enable */ | ||
349 | |||
350 | /* pre-shifted values for HCFS */ | ||
351 | # define OHCI_USB_RESET (0 << 6) | ||
352 | # define OHCI_USB_RESUME (1 << 6) | ||
353 | # define OHCI_USB_OPER (2 << 6) | ||
354 | # define OHCI_USB_SUSPEND (3 << 6) | ||
355 | |||
356 | /* | ||
357 | * HcCommandStatus (cmdstatus) register masks | ||
358 | */ | ||
359 | #define OHCI_HCR (1 << 0) /* host controller reset */ | ||
360 | #define OHCI_SOC (3 << 16) /* scheduling overrun count */ | ||
361 | |||
362 | /* | ||
363 | * masks used with interrupt registers: | ||
364 | * HcInterruptStatus (intrstatus) | ||
365 | * HcInterruptEnable (intrenable) | ||
366 | * HcInterruptDisable (intrdisable) | ||
367 | */ | ||
368 | #define OHCI_INTR_SO (1 << 0) /* scheduling overrun */ | ||
369 | #define OHCI_INTR_WDH (1 << 1) /* writeback of done_head */ | ||
370 | #define OHCI_INTR_SF (1 << 2) /* start frame */ | ||
371 | #define OHCI_INTR_RD (1 << 3) /* resume detect */ | ||
372 | #define OHCI_INTR_UE (1 << 4) /* unrecoverable error */ | ||
373 | #define OHCI_INTR_FNO (1 << 5) /* frame number overflow */ | ||
374 | #define OHCI_INTR_RHSC (1 << 6) /* root hub status change */ | ||
375 | #define OHCI_INTR_OC (1 << 30) /* ownership change */ | ||
376 | #define OHCI_INTR_MIE (1 << 31) /* master interrupt enable */ | ||
377 | |||
378 | /* roothub.portstatus [i] bits */ | ||
379 | #define RH_PS_CCS 0x00000001 /* current connect status */ | ||
380 | #define RH_PS_PES 0x00000002 /* port enable status*/ | ||
381 | #define RH_PS_PSS 0x00000004 /* port suspend status */ | ||
382 | #define RH_PS_POCI 0x00000008 /* port over current indicator */ | ||
383 | #define RH_PS_PRS 0x00000010 /* port reset status */ | ||
384 | #define RH_PS_PPS 0x00000100 /* port power status */ | ||
385 | #define RH_PS_LSDA 0x00000200 /* low speed device attached */ | ||
386 | #define RH_PS_CSC 0x00010000 /* connect status change */ | ||
387 | #define RH_PS_PESC 0x00020000 /* port enable status change */ | ||
388 | #define RH_PS_PSSC 0x00040000 /* port suspend status change */ | ||
389 | #define RH_PS_OCIC 0x00080000 /* over current indicator change */ | ||
390 | #define RH_PS_PRSC 0x00100000 /* port reset status change */ | ||
391 | |||
392 | /* roothub.status bits */ | ||
393 | #define RH_HS_LPS 0x00000001 /* local power status */ | ||
394 | #define RH_HS_OCI 0x00000002 /* over current indicator */ | ||
395 | #define RH_HS_DRWE 0x00008000 /* device remote wakeup enable */ | ||
396 | #define RH_HS_LPSC 0x00010000 /* local power status change */ | ||
397 | #define RH_HS_OCIC 0x00020000 /* over current indicator change */ | ||
398 | #define RH_HS_CRWE 0x80000000 /* clear remote wakeup enable */ | ||
399 | |||
400 | /* roothub.b masks */ | ||
401 | #define RH_B_DR 0x0000ffff /* device removable flags */ | ||
402 | #define RH_B_PPCM 0xffff0000 /* port power control mask */ | ||
403 | |||
404 | /* roothub.a masks */ | ||
405 | #define RH_A_NDP (0xff << 0) /* number of downstream ports */ | ||
406 | #define RH_A_PSM (1 << 8) /* power switching mode */ | ||
407 | #define RH_A_NPS (1 << 9) /* no power switching */ | ||
408 | #define RH_A_DT (1 << 10) /* device type (mbz) */ | ||
409 | #define RH_A_OCPM (1 << 11) /* over current protection mode */ | ||
410 | #define RH_A_NOCP (1 << 12) /* no over current protection */ | ||
411 | #define RH_A_POTPGT (0xff << 24) /* power on to power good time */ | ||
412 | |||
413 | #define FI 0x2edf /* 12000 bits per frame (-1) */ | ||
414 | #define FSMP(fi) (0x7fff & ((6 * ((fi) - 210)) / 7)) | ||
415 | #define LSTHRESH 0x628 /* lowspeed bit threshold */ | ||
416 | |||
417 | /* ------------------------------------------------------------------------- */ | ||
418 | |||
419 | /* PTD accessor macros. */ | ||
420 | #define PTD_GET_COUNT(p) (((p)->count & PTD_COUNT_MSK) >> 0) | ||
421 | #define PTD_COUNT(v) (((v) << 0) & PTD_COUNT_MSK) | ||
422 | #define PTD_GET_TOGGLE(p) (((p)->count & PTD_TOGGLE_MSK) >> 10) | ||
423 | #define PTD_TOGGLE(v) (((v) << 10) & PTD_TOGGLE_MSK) | ||
424 | #define PTD_GET_ACTIVE(p) (((p)->count & PTD_ACTIVE_MSK) >> 11) | ||
425 | #define PTD_ACTIVE(v) (((v) << 11) & PTD_ACTIVE_MSK) | ||
426 | #define PTD_GET_CC(p) (((p)->count & PTD_CC_MSK) >> 12) | ||
427 | #define PTD_CC(v) (((v) << 12) & PTD_CC_MSK) | ||
428 | #define PTD_GET_MPS(p) (((p)->mps & PTD_MPS_MSK) >> 0) | ||
429 | #define PTD_MPS(v) (((v) << 0) & PTD_MPS_MSK) | ||
430 | #define PTD_GET_SPD(p) (((p)->mps & PTD_SPD_MSK) >> 10) | ||
431 | #define PTD_SPD(v) (((v) << 10) & PTD_SPD_MSK) | ||
432 | #define PTD_GET_LAST(p) (((p)->mps & PTD_LAST_MSK) >> 11) | ||
433 | #define PTD_LAST(v) (((v) << 11) & PTD_LAST_MSK) | ||
434 | #define PTD_GET_EP(p) (((p)->mps & PTD_EP_MSK) >> 12) | ||
435 | #define PTD_EP(v) (((v) << 12) & PTD_EP_MSK) | ||
436 | #define PTD_GET_LEN(p) (((p)->len & PTD_LEN_MSK) >> 0) | ||
437 | #define PTD_LEN(v) (((v) << 0) & PTD_LEN_MSK) | ||
438 | #define PTD_GET_DIR(p) (((p)->len & PTD_DIR_MSK) >> 10) | ||
439 | #define PTD_DIR(v) (((v) << 10) & PTD_DIR_MSK) | ||
440 | #define PTD_GET_FA(p) (((p)->faddr & PTD_FA_MSK) >> 0) | ||
441 | #define PTD_FA(v) (((v) << 0) & PTD_FA_MSK) | ||
442 | #define PTD_GET_SF_INT(p) (((p)->faddr & PTD_SF_INT_MSK) >> 8) | ||
443 | #define PTD_SF_INT(v) (((v) << 8) & PTD_SF_INT_MSK) | ||
444 | #define PTD_GET_SF_ISO(p) (((p)->faddr & PTD_SF_ISO_MSK) >> 8) | ||
445 | #define PTD_SF_ISO(v) (((v) << 8) & PTD_SF_ISO_MSK) | ||
446 | #define PTD_GET_PR(p) (((p)->faddr & PTD_PR_MSK) >> 13) | ||
447 | #define PTD_PR(v) (((v) << 13) & PTD_PR_MSK) | ||
448 | |||
449 | #define LOG2_PERIODIC_SIZE 5 /* arbitrary; this matches OHCI */ | ||
450 | #define PERIODIC_SIZE (1 << LOG2_PERIODIC_SIZE) | ||
451 | |||
452 | struct isp1362_ep { | ||
453 | struct usb_host_endpoint *hep; | ||
454 | struct usb_device *udev; | ||
455 | |||
456 | /* philips transfer descriptor */ | ||
457 | struct ptd ptd; | ||
458 | |||
459 | u8 maxpacket; | ||
460 | u8 epnum; | ||
461 | u8 nextpid; | ||
462 | u16 error_count; | ||
463 | u16 length; /* of current packet */ | ||
464 | s16 ptd_offset; /* buffer offset in ISP1362 where | ||
465 | PTD has been stored | ||
466 | (for access thru HCDIRDATA) */ | ||
467 | int ptd_index; | ||
468 | int num_ptds; | ||
469 | void *data; /* to databuf */ | ||
470 | /* queue of active EPs (the ones transmitted to the chip) */ | ||
471 | struct list_head active; | ||
472 | |||
473 | /* periodic schedule */ | ||
474 | u8 branch; | ||
475 | u16 interval; | ||
476 | u16 load; | ||
477 | u16 last_iso; | ||
478 | |||
479 | /* async schedule */ | ||
480 | struct list_head schedule; /* list of all EPs that need processing */ | ||
481 | struct list_head remove_list; | ||
482 | int num_req; | ||
483 | }; | ||
484 | |||
485 | struct isp1362_ep_queue { | ||
486 | struct list_head active; /* list of PTDs currently processed by HC */ | ||
487 | atomic_t finishing; | ||
488 | unsigned long buf_map; | ||
489 | unsigned long skip_map; | ||
490 | int free_ptd; | ||
491 | u16 buf_start; | ||
492 | u16 buf_size; | ||
493 | u16 blk_size; /* PTD buffer block size for ATL and INTL */ | ||
494 | u8 buf_count; | ||
495 | u8 buf_avail; | ||
496 | char name[16]; | ||
497 | |||
498 | /* for statistical tracking */ | ||
499 | u8 stat_maxptds; /* Max # of ptds seen simultaneously in fifo */ | ||
500 | u8 ptd_count; /* number of ptds submitted to this queue */ | ||
501 | }; | ||
502 | |||
503 | struct isp1362_hcd { | ||
504 | spinlock_t lock; | ||
505 | void __iomem *addr_reg; | ||
506 | void __iomem *data_reg; | ||
507 | |||
508 | struct isp1362_platform_data *board; | ||
509 | |||
510 | struct proc_dir_entry *pde; | ||
511 | unsigned long stat1, stat2, stat4, stat8, stat16; | ||
512 | |||
513 | /* HC registers */ | ||
514 | u32 intenb; /* "OHCI" interrupts */ | ||
515 | u16 irqenb; /* uP interrupts */ | ||
516 | |||
517 | /* Root hub registers */ | ||
518 | u32 rhdesca; | ||
519 | u32 rhdescb; | ||
520 | u32 rhstatus; | ||
521 | u32 rhport[MAX_ROOT_PORTS]; | ||
522 | unsigned long next_statechange; | ||
523 | |||
524 | /* HC control reg shadow copy */ | ||
525 | u32 hc_control; | ||
526 | |||
527 | /* async schedule: control, bulk */ | ||
528 | struct list_head async; | ||
529 | |||
530 | /* periodic schedule: int */ | ||
531 | u16 load[PERIODIC_SIZE]; | ||
532 | struct list_head periodic; | ||
533 | u16 fmindex; | ||
534 | |||
535 | /* periodic schedule: isochronous */ | ||
536 | struct list_head isoc; | ||
537 | int istl_flip:1; | ||
538 | int irq_active:1; | ||
539 | |||
540 | /* Schedules for the current frame */ | ||
541 | struct isp1362_ep_queue atl_queue; | ||
542 | struct isp1362_ep_queue intl_queue; | ||
543 | struct isp1362_ep_queue istl_queue[2]; | ||
544 | |||
545 | /* list of PTDs retrieved from HC */ | ||
546 | struct list_head remove_list; | ||
547 | enum { | ||
548 | ISP1362_INT_SOF, | ||
549 | ISP1362_INT_ISTL0, | ||
550 | ISP1362_INT_ISTL1, | ||
551 | ISP1362_INT_EOT, | ||
552 | ISP1362_INT_OPR, | ||
553 | ISP1362_INT_SUSP, | ||
554 | ISP1362_INT_CLKRDY, | ||
555 | ISP1362_INT_INTL, | ||
556 | ISP1362_INT_ATL, | ||
557 | ISP1362_INT_OTG, | ||
558 | NUM_ISP1362_IRQS | ||
559 | } IRQ_NAMES; | ||
560 | unsigned int irq_stat[NUM_ISP1362_IRQS]; | ||
561 | int req_serial; | ||
562 | }; | ||
563 | |||
564 | static inline const char *ISP1362_INT_NAME(int n) | ||
565 | { | ||
566 | switch (n) { | ||
567 | case ISP1362_INT_SOF: return "SOF"; | ||
568 | case ISP1362_INT_ISTL0: return "ISTL0"; | ||
569 | case ISP1362_INT_ISTL1: return "ISTL1"; | ||
570 | case ISP1362_INT_EOT: return "EOT"; | ||
571 | case ISP1362_INT_OPR: return "OPR"; | ||
572 | case ISP1362_INT_SUSP: return "SUSP"; | ||
573 | case ISP1362_INT_CLKRDY: return "CLKRDY"; | ||
574 | case ISP1362_INT_INTL: return "INTL"; | ||
575 | case ISP1362_INT_ATL: return "ATL"; | ||
576 | case ISP1362_INT_OTG: return "OTG"; | ||
577 | default: return "unknown"; | ||
578 | } | ||
579 | } | ||
580 | |||
581 | static inline void ALIGNSTAT(struct isp1362_hcd *isp1362_hcd, void *ptr) | ||
582 | { | ||
583 | unsigned p = (unsigned)ptr; | ||
584 | if (!(p & 0xf)) | ||
585 | isp1362_hcd->stat16++; | ||
586 | else if (!(p & 0x7)) | ||
587 | isp1362_hcd->stat8++; | ||
588 | else if (!(p & 0x3)) | ||
589 | isp1362_hcd->stat4++; | ||
590 | else if (!(p & 0x1)) | ||
591 | isp1362_hcd->stat2++; | ||
592 | else | ||
593 | isp1362_hcd->stat1++; | ||
594 | } | ||
595 | |||
596 | static inline struct isp1362_hcd *hcd_to_isp1362_hcd(struct usb_hcd *hcd) | ||
597 | { | ||
598 | return (struct isp1362_hcd *) (hcd->hcd_priv); | ||
599 | } | ||
600 | |||
601 | static inline struct usb_hcd *isp1362_hcd_to_hcd(struct isp1362_hcd *isp1362_hcd) | ||
602 | { | ||
603 | return container_of((void *)isp1362_hcd, struct usb_hcd, hcd_priv); | ||
604 | } | ||
605 | |||
606 | #define frame_before(f1, f2) ((s16)((u16)f1 - (u16)f2) < 0) | ||
607 | |||
608 | /* | ||
609 | * ISP1362 HW Interface | ||
610 | */ | ||
611 | |||
612 | #ifdef ISP1362_DEBUG | ||
613 | #define DBG(level, fmt...) \ | ||
614 | do { \ | ||
615 | if (dbg_level > level) \ | ||
616 | pr_debug(fmt); \ | ||
617 | } while (0) | ||
618 | #define _DBG(level, fmt...) \ | ||
619 | do { \ | ||
620 | if (dbg_level > level) \ | ||
621 | printk(fmt); \ | ||
622 | } while (0) | ||
623 | #else | ||
624 | #define DBG(fmt...) do {} while (0) | ||
625 | #define _DBG DBG | ||
626 | #endif | ||
627 | |||
628 | #ifdef VERBOSE | ||
629 | # define VDBG(fmt...) DBG(3, fmt) | ||
630 | #else | ||
631 | # define VDBG(fmt...) do {} while (0) | ||
632 | #endif | ||
633 | |||
634 | #ifdef REGISTERS | ||
635 | # define RDBG(fmt...) DBG(1, fmt) | ||
636 | #else | ||
637 | # define RDBG(fmt...) do {} while (0) | ||
638 | #endif | ||
639 | |||
640 | #ifdef URB_TRACE | ||
641 | #define URB_DBG(fmt...) DBG(0, fmt) | ||
642 | #else | ||
643 | #define URB_DBG(fmt...) do {} while (0) | ||
644 | #endif | ||
645 | |||
646 | |||
647 | #if USE_PLATFORM_DELAY | ||
648 | #if USE_NDELAY | ||
649 | #error USE_PLATFORM_DELAY and USE_NDELAY defined simultaneously. | ||
650 | #endif | ||
651 | #define isp1362_delay(h, d) (h)->board->delay(isp1362_hcd_to_hcd(h)->self.controller, d) | ||
652 | #elif USE_NDELAY | ||
653 | #define isp1362_delay(h, d) ndelay(d) | ||
654 | #else | ||
655 | #define isp1362_delay(h, d) do {} while (0) | ||
656 | #endif | ||
657 | |||
658 | #define get_urb(ep) ({ \ | ||
659 | BUG_ON(list_empty(&ep->hep->urb_list)); \ | ||
660 | container_of(ep->hep->urb_list.next, struct urb, urb_list); \ | ||
661 | }) | ||
662 | |||
663 | /* basic access functions for ISP1362 chip registers */ | ||
664 | /* NOTE: The contents of the address pointer register cannot be read back! The driver must ensure, | ||
665 | * that all register accesses are performed with interrupts disabled, since the interrupt | ||
666 | * handler has no way of restoring the previous state. | ||
667 | */ | ||
668 | static void isp1362_write_addr(struct isp1362_hcd *isp1362_hcd, isp1362_reg_t reg) | ||
669 | { | ||
670 | /*_BUG_ON((reg & ISP1362_REG_WRITE_OFFSET) && !(reg & REG_ACCESS_W));*/ | ||
671 | REG_ACCESS_TEST(reg); | ||
672 | _BUG_ON(!irqs_disabled()); | ||
673 | DUMMY_DELAY_ACCESS; | ||
674 | writew(ISP1362_REG_NO(reg), isp1362_hcd->addr_reg); | ||
675 | DUMMY_DELAY_ACCESS; | ||
676 | isp1362_delay(isp1362_hcd, 1); | ||
677 | } | ||
678 | |||
679 | static void isp1362_write_data16(struct isp1362_hcd *isp1362_hcd, u16 val) | ||
680 | { | ||
681 | _BUG_ON(!irqs_disabled()); | ||
682 | DUMMY_DELAY_ACCESS; | ||
683 | writew(val, isp1362_hcd->data_reg); | ||
684 | } | ||
685 | |||
686 | static u16 isp1362_read_data16(struct isp1362_hcd *isp1362_hcd) | ||
687 | { | ||
688 | u16 val; | ||
689 | |||
690 | _BUG_ON(!irqs_disabled()); | ||
691 | DUMMY_DELAY_ACCESS; | ||
692 | val = readw(isp1362_hcd->data_reg); | ||
693 | |||
694 | return val; | ||
695 | } | ||
696 | |||
697 | static void isp1362_write_data32(struct isp1362_hcd *isp1362_hcd, u32 val) | ||
698 | { | ||
699 | _BUG_ON(!irqs_disabled()); | ||
700 | #if USE_32BIT | ||
701 | DUMMY_DELAY_ACCESS; | ||
702 | writel(val, isp1362_hcd->data_reg); | ||
703 | #else | ||
704 | DUMMY_DELAY_ACCESS; | ||
705 | writew((u16)val, isp1362_hcd->data_reg); | ||
706 | DUMMY_DELAY_ACCESS; | ||
707 | writew(val >> 16, isp1362_hcd->data_reg); | ||
708 | #endif | ||
709 | } | ||
710 | |||
711 | static u32 isp1362_read_data32(struct isp1362_hcd *isp1362_hcd) | ||
712 | { | ||
713 | u32 val; | ||
714 | |||
715 | _BUG_ON(!irqs_disabled()); | ||
716 | #if USE_32BIT | ||
717 | DUMMY_DELAY_ACCESS; | ||
718 | val = readl(isp1362_hcd->data_reg); | ||
719 | #else | ||
720 | DUMMY_DELAY_ACCESS; | ||
721 | val = (u32)readw(isp1362_hcd->data_reg); | ||
722 | DUMMY_DELAY_ACCESS; | ||
723 | val |= (u32)readw(isp1362_hcd->data_reg) << 16; | ||
724 | #endif | ||
725 | return val; | ||
726 | } | ||
727 | |||
728 | /* use readsw/writesw to access the fifo whenever possible */ | ||
729 | /* assume HCDIRDATA or XFERCTR & addr_reg have been set up */ | ||
730 | static void isp1362_read_fifo(struct isp1362_hcd *isp1362_hcd, void *buf, u16 len) | ||
731 | { | ||
732 | u8 *dp = buf; | ||
733 | u16 data; | ||
734 | |||
735 | if (!len) | ||
736 | return; | ||
737 | |||
738 | _BUG_ON(!irqs_disabled()); | ||
739 | |||
740 | RDBG("%s: Reading %d byte from fifo to mem @ %p\n", __func__, len, buf); | ||
741 | #if USE_32BIT | ||
742 | if (len >= 4) { | ||
743 | RDBG("%s: Using readsl for %d dwords\n", __func__, len >> 2); | ||
744 | readsl(isp1362_hcd->data_reg, dp, len >> 2); | ||
745 | dp += len & ~3; | ||
746 | len &= 3; | ||
747 | } | ||
748 | #endif | ||
749 | if (len >= 2) { | ||
750 | RDBG("%s: Using readsw for %d words\n", __func__, len >> 1); | ||
751 | insw((unsigned long)isp1362_hcd->data_reg, dp, len >> 1); | ||
752 | dp += len & ~1; | ||
753 | len &= 1; | ||
754 | } | ||
755 | |||
756 | BUG_ON(len & ~1); | ||
757 | if (len > 0) { | ||
758 | data = isp1362_read_data16(isp1362_hcd); | ||
759 | RDBG("%s: Reading trailing byte %02x to mem @ %08x\n", __func__, | ||
760 | (u8)data, (u32)dp); | ||
761 | *dp = (u8)data; | ||
762 | } | ||
763 | } | ||
764 | |||
765 | static void isp1362_write_fifo(struct isp1362_hcd *isp1362_hcd, void *buf, u16 len) | ||
766 | { | ||
767 | u8 *dp = buf; | ||
768 | u16 data; | ||
769 | |||
770 | if (!len) | ||
771 | return; | ||
772 | |||
773 | if ((unsigned)dp & 0x1) { | ||
774 | /* not aligned */ | ||
775 | for (; len > 1; len -= 2) { | ||
776 | data = *dp++; | ||
777 | data |= *dp++ << 8; | ||
778 | isp1362_write_data16(isp1362_hcd, data); | ||
779 | } | ||
780 | if (len) | ||
781 | isp1362_write_data16(isp1362_hcd, *dp); | ||
782 | return; | ||
783 | } | ||
784 | |||
785 | _BUG_ON(!irqs_disabled()); | ||
786 | |||
787 | RDBG("%s: Writing %d byte to fifo from memory @%p\n", __func__, len, buf); | ||
788 | #if USE_32BIT | ||
789 | if (len >= 4) { | ||
790 | RDBG("%s: Using writesl for %d dwords\n", __func__, len >> 2); | ||
791 | writesl(isp1362_hcd->data_reg, dp, len >> 2); | ||
792 | dp += len & ~3; | ||
793 | len &= 3; | ||
794 | } | ||
795 | #endif | ||
796 | if (len >= 2) { | ||
797 | RDBG("%s: Using writesw for %d words\n", __func__, len >> 1); | ||
798 | outsw((unsigned long)isp1362_hcd->data_reg, dp, len >> 1); | ||
799 | dp += len & ~1; | ||
800 | len &= 1; | ||
801 | } | ||
802 | |||
803 | BUG_ON(len & ~1); | ||
804 | if (len > 0) { | ||
805 | /* finally write any trailing byte; we don't need to care | ||
806 | * about the high byte of the last word written | ||
807 | */ | ||
808 | data = (u16)*dp; | ||
809 | RDBG("%s: Sending trailing byte %02x from mem @ %08x\n", __func__, | ||
810 | data, (u32)dp); | ||
811 | isp1362_write_data16(isp1362_hcd, data); | ||
812 | } | ||
813 | } | ||
814 | |||
815 | #define isp1362_read_reg16(d, r) ({ \ | ||
816 | u16 __v; \ | ||
817 | REG_WIDTH_TEST(ISP1362_REG_##r, REG_WIDTH_16); \ | ||
818 | isp1362_write_addr(d, ISP1362_REG_##r); \ | ||
819 | __v = isp1362_read_data16(d); \ | ||
820 | RDBG("%s: Read %04x from %s[%02x]\n", __func__, __v, #r, \ | ||
821 | ISP1362_REG_NO(ISP1362_REG_##r)); \ | ||
822 | __v; \ | ||
823 | }) | ||
824 | |||
825 | #define isp1362_read_reg32(d, r) ({ \ | ||
826 | u32 __v; \ | ||
827 | REG_WIDTH_TEST(ISP1362_REG_##r, REG_WIDTH_32); \ | ||
828 | isp1362_write_addr(d, ISP1362_REG_##r); \ | ||
829 | __v = isp1362_read_data32(d); \ | ||
830 | RDBG("%s: Read %08x from %s[%02x]\n", __func__, __v, #r, \ | ||
831 | ISP1362_REG_NO(ISP1362_REG_##r)); \ | ||
832 | __v; \ | ||
833 | }) | ||
834 | |||
835 | #define isp1362_write_reg16(d, r, v) { \ | ||
836 | REG_WIDTH_TEST(ISP1362_REG_##r, REG_WIDTH_16); \ | ||
837 | isp1362_write_addr(d, (ISP1362_REG_##r) | ISP1362_REG_WRITE_OFFSET); \ | ||
838 | isp1362_write_data16(d, (u16)(v)); \ | ||
839 | RDBG("%s: Wrote %04x to %s[%02x]\n", __func__, (u16)(v), #r, \ | ||
840 | ISP1362_REG_NO(ISP1362_REG_##r)); \ | ||
841 | } | ||
842 | |||
843 | #define isp1362_write_reg32(d, r, v) { \ | ||
844 | REG_WIDTH_TEST(ISP1362_REG_##r, REG_WIDTH_32); \ | ||
845 | isp1362_write_addr(d, (ISP1362_REG_##r) | ISP1362_REG_WRITE_OFFSET); \ | ||
846 | isp1362_write_data32(d, (u32)(v)); \ | ||
847 | RDBG("%s: Wrote %08x to %s[%02x]\n", __func__, (u32)(v), #r, \ | ||
848 | ISP1362_REG_NO(ISP1362_REG_##r)); \ | ||
849 | } | ||
850 | |||
851 | #define isp1362_set_mask16(d, r, m) { \ | ||
852 | u16 __v; \ | ||
853 | __v = isp1362_read_reg16(d, r); \ | ||
854 | if ((__v | m) != __v) \ | ||
855 | isp1362_write_reg16(d, r, __v | m); \ | ||
856 | } | ||
857 | |||
858 | #define isp1362_clr_mask16(d, r, m) { \ | ||
859 | u16 __v; \ | ||
860 | __v = isp1362_read_reg16(d, r); \ | ||
861 | if ((__v & ~m) != __v) \ | ||
862 | isp1362_write_reg16(d, r, __v & ~m); \ | ||
863 | } | ||
864 | |||
865 | #define isp1362_set_mask32(d, r, m) { \ | ||
866 | u32 __v; \ | ||
867 | __v = isp1362_read_reg32(d, r); \ | ||
868 | if ((__v | m) != __v) \ | ||
869 | isp1362_write_reg32(d, r, __v | m); \ | ||
870 | } | ||
871 | |||
872 | #define isp1362_clr_mask32(d, r, m) { \ | ||
873 | u32 __v; \ | ||
874 | __v = isp1362_read_reg32(d, r); \ | ||
875 | if ((__v & ~m) != __v) \ | ||
876 | isp1362_write_reg32(d, r, __v & ~m); \ | ||
877 | } | ||
878 | |||
879 | #ifdef ISP1362_DEBUG | ||
880 | #define isp1362_show_reg(d, r) { \ | ||
881 | if ((ISP1362_REG_##r & REG_WIDTH_MASK) == REG_WIDTH_32) \ | ||
882 | DBG(0, "%-12s[%02x]: %08x\n", #r, \ | ||
883 | ISP1362_REG_NO(ISP1362_REG_##r), isp1362_read_reg32(d, r)); \ | ||
884 | else \ | ||
885 | DBG(0, "%-12s[%02x]: %04x\n", #r, \ | ||
886 | ISP1362_REG_NO(ISP1362_REG_##r), isp1362_read_reg16(d, r)); \ | ||
887 | } | ||
888 | #else | ||
889 | #define isp1362_show_reg(d, r) do {} while (0) | ||
890 | #endif | ||
891 | |||
892 | static void __attribute__((__unused__)) isp1362_show_regs(struct isp1362_hcd *isp1362_hcd) | ||
893 | { | ||
894 | isp1362_show_reg(isp1362_hcd, HCREVISION); | ||
895 | isp1362_show_reg(isp1362_hcd, HCCONTROL); | ||
896 | isp1362_show_reg(isp1362_hcd, HCCMDSTAT); | ||
897 | isp1362_show_reg(isp1362_hcd, HCINTSTAT); | ||
898 | isp1362_show_reg(isp1362_hcd, HCINTENB); | ||
899 | isp1362_show_reg(isp1362_hcd, HCFMINTVL); | ||
900 | isp1362_show_reg(isp1362_hcd, HCFMREM); | ||
901 | isp1362_show_reg(isp1362_hcd, HCFMNUM); | ||
902 | isp1362_show_reg(isp1362_hcd, HCLSTHRESH); | ||
903 | isp1362_show_reg(isp1362_hcd, HCRHDESCA); | ||
904 | isp1362_show_reg(isp1362_hcd, HCRHDESCB); | ||
905 | isp1362_show_reg(isp1362_hcd, HCRHSTATUS); | ||
906 | isp1362_show_reg(isp1362_hcd, HCRHPORT1); | ||
907 | isp1362_show_reg(isp1362_hcd, HCRHPORT2); | ||
908 | |||
909 | isp1362_show_reg(isp1362_hcd, HCHWCFG); | ||
910 | isp1362_show_reg(isp1362_hcd, HCDMACFG); | ||
911 | isp1362_show_reg(isp1362_hcd, HCXFERCTR); | ||
912 | isp1362_show_reg(isp1362_hcd, HCuPINT); | ||
913 | |||
914 | if (in_interrupt()) | ||
915 | DBG(0, "%-12s[%02x]: %04x\n", "HCuPINTENB", | ||
916 | ISP1362_REG_NO(ISP1362_REG_HCuPINTENB), isp1362_hcd->irqenb); | ||
917 | else | ||
918 | isp1362_show_reg(isp1362_hcd, HCuPINTENB); | ||
919 | isp1362_show_reg(isp1362_hcd, HCCHIPID); | ||
920 | isp1362_show_reg(isp1362_hcd, HCSCRATCH); | ||
921 | isp1362_show_reg(isp1362_hcd, HCBUFSTAT); | ||
922 | isp1362_show_reg(isp1362_hcd, HCDIRADDR); | ||
923 | /* Access would advance fifo | ||
924 | * isp1362_show_reg(isp1362_hcd, HCDIRDATA); | ||
925 | */ | ||
926 | isp1362_show_reg(isp1362_hcd, HCISTLBUFSZ); | ||
927 | isp1362_show_reg(isp1362_hcd, HCISTLRATE); | ||
928 | isp1362_show_reg(isp1362_hcd, HCINTLBUFSZ); | ||
929 | isp1362_show_reg(isp1362_hcd, HCINTLBLKSZ); | ||
930 | isp1362_show_reg(isp1362_hcd, HCINTLDONE); | ||
931 | isp1362_show_reg(isp1362_hcd, HCINTLSKIP); | ||
932 | isp1362_show_reg(isp1362_hcd, HCINTLLAST); | ||
933 | isp1362_show_reg(isp1362_hcd, HCINTLCURR); | ||
934 | isp1362_show_reg(isp1362_hcd, HCATLBUFSZ); | ||
935 | isp1362_show_reg(isp1362_hcd, HCATLBLKSZ); | ||
936 | /* only valid after ATL_DONE interrupt | ||
937 | * isp1362_show_reg(isp1362_hcd, HCATLDONE); | ||
938 | */ | ||
939 | isp1362_show_reg(isp1362_hcd, HCATLSKIP); | ||
940 | isp1362_show_reg(isp1362_hcd, HCATLLAST); | ||
941 | isp1362_show_reg(isp1362_hcd, HCATLCURR); | ||
942 | isp1362_show_reg(isp1362_hcd, HCATLDTC); | ||
943 | isp1362_show_reg(isp1362_hcd, HCATLDTCTO); | ||
944 | } | ||
945 | |||
946 | static void isp1362_write_diraddr(struct isp1362_hcd *isp1362_hcd, u16 offset, u16 len) | ||
947 | { | ||
948 | _BUG_ON(offset & 1); | ||
949 | _BUG_ON(offset >= ISP1362_BUF_SIZE); | ||
950 | _BUG_ON(len > ISP1362_BUF_SIZE); | ||
951 | _BUG_ON(offset + len > ISP1362_BUF_SIZE); | ||
952 | len = (len + 1) & ~1; | ||
953 | |||
954 | isp1362_clr_mask16(isp1362_hcd, HCDMACFG, HCDMACFG_CTR_ENABLE); | ||
955 | isp1362_write_reg32(isp1362_hcd, HCDIRADDR, | ||
956 | HCDIRADDR_ADDR(offset) | HCDIRADDR_COUNT(len)); | ||
957 | } | ||
958 | |||
959 | static void isp1362_read_buffer(struct isp1362_hcd *isp1362_hcd, void *buf, u16 offset, int len) | ||
960 | { | ||
961 | _BUG_ON(offset & 1); | ||
962 | |||
963 | isp1362_write_diraddr(isp1362_hcd, offset, len); | ||
964 | |||
965 | DBG(3, "%s: Reading %d byte from buffer @%04x to memory @ %08x\n", __func__, | ||
966 | len, offset, (u32)buf); | ||
967 | |||
968 | isp1362_write_reg16(isp1362_hcd, HCuPINT, HCuPINT_EOT); | ||
969 | _WARN_ON((isp1362_read_reg16(isp1362_hcd, HCuPINT) & HCuPINT_EOT)); | ||
970 | |||
971 | isp1362_write_addr(isp1362_hcd, ISP1362_REG_HCDIRDATA); | ||
972 | |||
973 | isp1362_read_fifo(isp1362_hcd, buf, len); | ||
974 | _WARN_ON(!(isp1362_read_reg16(isp1362_hcd, HCuPINT) & HCuPINT_EOT)); | ||
975 | isp1362_write_reg16(isp1362_hcd, HCuPINT, HCuPINT_EOT); | ||
976 | _WARN_ON((isp1362_read_reg16(isp1362_hcd, HCuPINT) & HCuPINT_EOT)); | ||
977 | } | ||
978 | |||
979 | static void isp1362_write_buffer(struct isp1362_hcd *isp1362_hcd, void *buf, u16 offset, int len) | ||
980 | { | ||
981 | _BUG_ON(offset & 1); | ||
982 | |||
983 | isp1362_write_diraddr(isp1362_hcd, offset, len); | ||
984 | |||
985 | DBG(3, "%s: Writing %d byte to buffer @%04x from memory @ %08x\n", __func__, | ||
986 | len, offset, (u32)buf); | ||
987 | |||
988 | isp1362_write_reg16(isp1362_hcd, HCuPINT, HCuPINT_EOT); | ||
989 | _WARN_ON((isp1362_read_reg16(isp1362_hcd, HCuPINT) & HCuPINT_EOT)); | ||
990 | |||
991 | isp1362_write_addr(isp1362_hcd, ISP1362_REG_HCDIRDATA | ISP1362_REG_WRITE_OFFSET); | ||
992 | isp1362_write_fifo(isp1362_hcd, buf, len); | ||
993 | |||
994 | _WARN_ON(!(isp1362_read_reg16(isp1362_hcd, HCuPINT) & HCuPINT_EOT)); | ||
995 | isp1362_write_reg16(isp1362_hcd, HCuPINT, HCuPINT_EOT); | ||
996 | _WARN_ON((isp1362_read_reg16(isp1362_hcd, HCuPINT) & HCuPINT_EOT)); | ||
997 | } | ||
998 | |||
999 | static void __attribute__((unused)) dump_data(char *buf, int len) | ||
1000 | { | ||
1001 | if (dbg_level > 0) { | ||
1002 | int k; | ||
1003 | int lf = 0; | ||
1004 | |||
1005 | for (k = 0; k < len; ++k) { | ||
1006 | if (!lf) | ||
1007 | DBG(0, "%04x:", k); | ||
1008 | printk(" %02x", ((u8 *) buf)[k]); | ||
1009 | lf = 1; | ||
1010 | if (!k) | ||
1011 | continue; | ||
1012 | if (k % 16 == 15) { | ||
1013 | printk("\n"); | ||
1014 | lf = 0; | ||
1015 | continue; | ||
1016 | } | ||
1017 | if (k % 8 == 7) | ||
1018 | printk(" "); | ||
1019 | if (k % 4 == 3) | ||
1020 | printk(" "); | ||
1021 | } | ||
1022 | if (lf) | ||
1023 | printk("\n"); | ||
1024 | } | ||
1025 | } | ||
1026 | |||
1027 | #if defined(ISP1362_DEBUG) && defined(PTD_TRACE) | ||
1028 | |||
1029 | static void dump_ptd(struct ptd *ptd) | ||
1030 | { | ||
1031 | DBG(0, "EP %p: CC=%x EP=%d DIR=%x CNT=%d LEN=%d MPS=%d TGL=%x ACT=%x FA=%d SPD=%x SF=%x PR=%x LST=%x\n", | ||
1032 | container_of(ptd, struct isp1362_ep, ptd), | ||
1033 | PTD_GET_CC(ptd), PTD_GET_EP(ptd), PTD_GET_DIR(ptd), | ||
1034 | PTD_GET_COUNT(ptd), PTD_GET_LEN(ptd), PTD_GET_MPS(ptd), | ||
1035 | PTD_GET_TOGGLE(ptd), PTD_GET_ACTIVE(ptd), PTD_GET_FA(ptd), | ||
1036 | PTD_GET_SPD(ptd), PTD_GET_SF_INT(ptd), PTD_GET_PR(ptd), PTD_GET_LAST(ptd)); | ||
1037 | DBG(0, " %04x %04x %04x %04x\n", ptd->count, ptd->mps, ptd->len, ptd->faddr); | ||
1038 | } | ||
1039 | |||
1040 | static void dump_ptd_out_data(struct ptd *ptd, u8 *buf) | ||
1041 | { | ||
1042 | if (dbg_level > 0) { | ||
1043 | if (PTD_GET_DIR(ptd) != PTD_DIR_IN && PTD_GET_LEN(ptd)) { | ||
1044 | DBG(0, "--out->\n"); | ||
1045 | dump_data(buf, PTD_GET_LEN(ptd)); | ||
1046 | } | ||
1047 | } | ||
1048 | } | ||
1049 | |||
1050 | static void dump_ptd_in_data(struct ptd *ptd, u8 *buf) | ||
1051 | { | ||
1052 | if (dbg_level > 0) { | ||
1053 | if (PTD_GET_DIR(ptd) == PTD_DIR_IN && PTD_GET_COUNT(ptd)) { | ||
1054 | DBG(0, "<--in--\n"); | ||
1055 | dump_data(buf, PTD_GET_COUNT(ptd)); | ||
1056 | } | ||
1057 | DBG(0, "-----\n"); | ||
1058 | } | ||
1059 | } | ||
1060 | |||
1061 | static void dump_ptd_queue(struct isp1362_ep_queue *epq) | ||
1062 | { | ||
1063 | struct isp1362_ep *ep; | ||
1064 | int dbg = dbg_level; | ||
1065 | |||
1066 | dbg_level = 1; | ||
1067 | list_for_each_entry(ep, &epq->active, active) { | ||
1068 | dump_ptd(&ep->ptd); | ||
1069 | dump_data(ep->data, ep->length); | ||
1070 | } | ||
1071 | dbg_level = dbg; | ||
1072 | } | ||
1073 | #else | ||
1074 | #define dump_ptd(ptd) do {} while (0) | ||
1075 | #define dump_ptd_in_data(ptd, buf) do {} while (0) | ||
1076 | #define dump_ptd_out_data(ptd, buf) do {} while (0) | ||
1077 | #define dump_ptd_data(ptd, buf) do {} while (0) | ||
1078 | #define dump_ptd_queue(epq) do {} while (0) | ||
1079 | #endif | ||
diff --git a/drivers/usb/host/isp1760-hcd.c b/drivers/usb/host/isp1760-hcd.c index 15438469f21a..9600a58299db 100644 --- a/drivers/usb/host/isp1760-hcd.c +++ b/drivers/usb/host/isp1760-hcd.c | |||
@@ -386,6 +386,10 @@ static int isp1760_hc_setup(struct usb_hcd *hcd) | |||
386 | hwmode |= HW_DACK_POL_HIGH; | 386 | hwmode |= HW_DACK_POL_HIGH; |
387 | if (priv->devflags & ISP1760_FLAG_DREQ_POL_HIGH) | 387 | if (priv->devflags & ISP1760_FLAG_DREQ_POL_HIGH) |
388 | hwmode |= HW_DREQ_POL_HIGH; | 388 | hwmode |= HW_DREQ_POL_HIGH; |
389 | if (priv->devflags & ISP1760_FLAG_INTR_POL_HIGH) | ||
390 | hwmode |= HW_INTR_HIGH_ACT; | ||
391 | if (priv->devflags & ISP1760_FLAG_INTR_EDGE_TRIG) | ||
392 | hwmode |= HW_INTR_EDGE_TRIG; | ||
389 | 393 | ||
390 | /* | 394 | /* |
391 | * We have to set this first in case we're in 16-bit mode. | 395 | * We have to set this first in case we're in 16-bit mode. |
diff --git a/drivers/usb/host/isp1760-hcd.h b/drivers/usb/host/isp1760-hcd.h index 462f4943cb1b..6931ef5c9650 100644 --- a/drivers/usb/host/isp1760-hcd.h +++ b/drivers/usb/host/isp1760-hcd.h | |||
@@ -142,6 +142,8 @@ typedef void (packet_enqueue)(struct usb_hcd *hcd, struct isp1760_qh *qh, | |||
142 | #define ISP1760_FLAG_DACK_POL_HIGH 0x00000010 /* DACK active high */ | 142 | #define ISP1760_FLAG_DACK_POL_HIGH 0x00000010 /* DACK active high */ |
143 | #define ISP1760_FLAG_DREQ_POL_HIGH 0x00000020 /* DREQ active high */ | 143 | #define ISP1760_FLAG_DREQ_POL_HIGH 0x00000020 /* DREQ active high */ |
144 | #define ISP1760_FLAG_ISP1761 0x00000040 /* Chip is ISP1761 */ | 144 | #define ISP1760_FLAG_ISP1761 0x00000040 /* Chip is ISP1761 */ |
145 | #define ISP1760_FLAG_INTR_POL_HIGH 0x00000080 /* Interrupt polarity active high */ | ||
146 | #define ISP1760_FLAG_INTR_EDGE_TRIG 0x00000100 /* Interrupt edge triggered */ | ||
145 | 147 | ||
146 | /* chip memory management */ | 148 | /* chip memory management */ |
147 | struct memory_chunk { | 149 | struct memory_chunk { |
diff --git a/drivers/usb/host/isp1760-if.c b/drivers/usb/host/isp1760-if.c index d4feebfc63bd..1c9f977a5c9c 100644 --- a/drivers/usb/host/isp1760-if.c +++ b/drivers/usb/host/isp1760-if.c | |||
@@ -3,6 +3,7 @@ | |||
3 | * Currently there is support for | 3 | * Currently there is support for |
4 | * - OpenFirmware | 4 | * - OpenFirmware |
5 | * - PCI | 5 | * - PCI |
6 | * - PDEV (generic platform device centralized driver model) | ||
6 | * | 7 | * |
7 | * (c) 2007 Sebastian Siewior <bigeasy@linutronix.de> | 8 | * (c) 2007 Sebastian Siewior <bigeasy@linutronix.de> |
8 | * | 9 | * |
@@ -11,6 +12,7 @@ | |||
11 | #include <linux/usb.h> | 12 | #include <linux/usb.h> |
12 | #include <linux/io.h> | 13 | #include <linux/io.h> |
13 | #include <linux/platform_device.h> | 14 | #include <linux/platform_device.h> |
15 | #include <linux/usb/isp1760.h> | ||
14 | 16 | ||
15 | #include "../core/hcd.h" | 17 | #include "../core/hcd.h" |
16 | #include "isp1760-hcd.h" | 18 | #include "isp1760-hcd.h" |
@@ -308,6 +310,8 @@ static int __devinit isp1760_plat_probe(struct platform_device *pdev) | |||
308 | struct resource *mem_res; | 310 | struct resource *mem_res; |
309 | struct resource *irq_res; | 311 | struct resource *irq_res; |
310 | resource_size_t mem_size; | 312 | resource_size_t mem_size; |
313 | struct isp1760_platform_data *priv = pdev->dev.platform_data; | ||
314 | unsigned int devflags = 0; | ||
311 | unsigned long irqflags = IRQF_SHARED | IRQF_DISABLED; | 315 | unsigned long irqflags = IRQF_SHARED | IRQF_DISABLED; |
312 | 316 | ||
313 | mem_res = platform_get_resource(pdev, IORESOURCE_MEM, 0); | 317 | mem_res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
@@ -330,8 +334,23 @@ static int __devinit isp1760_plat_probe(struct platform_device *pdev) | |||
330 | } | 334 | } |
331 | irqflags |= irq_res->flags & IRQF_TRIGGER_MASK; | 335 | irqflags |= irq_res->flags & IRQF_TRIGGER_MASK; |
332 | 336 | ||
337 | if (priv) { | ||
338 | if (priv->is_isp1761) | ||
339 | devflags |= ISP1760_FLAG_ISP1761; | ||
340 | if (priv->bus_width_16) | ||
341 | devflags |= ISP1760_FLAG_BUS_WIDTH_16; | ||
342 | if (priv->port1_otg) | ||
343 | devflags |= ISP1760_FLAG_OTG_EN; | ||
344 | if (priv->analog_oc) | ||
345 | devflags |= ISP1760_FLAG_ANALOG_OC; | ||
346 | if (priv->dack_polarity_high) | ||
347 | devflags |= ISP1760_FLAG_DACK_POL_HIGH; | ||
348 | if (priv->dreq_polarity_high) | ||
349 | devflags |= ISP1760_FLAG_DREQ_POL_HIGH; | ||
350 | } | ||
351 | |||
333 | hcd = isp1760_register(mem_res->start, mem_size, irq_res->start, | 352 | hcd = isp1760_register(mem_res->start, mem_size, irq_res->start, |
334 | irqflags, &pdev->dev, dev_name(&pdev->dev), 0); | 353 | irqflags, &pdev->dev, dev_name(&pdev->dev), devflags); |
335 | if (IS_ERR(hcd)) { | 354 | if (IS_ERR(hcd)) { |
336 | pr_warning("isp1760: Failed to register the HCD device\n"); | 355 | pr_warning("isp1760: Failed to register the HCD device\n"); |
337 | ret = -ENODEV; | 356 | ret = -ENODEV; |
diff --git a/drivers/usb/host/ohci-at91.c b/drivers/usb/host/ohci-at91.c index bb5e6f671578..7ccffcbe7b6f 100644 --- a/drivers/usb/host/ohci-at91.c +++ b/drivers/usb/host/ohci-at91.c | |||
@@ -148,7 +148,7 @@ static int usb_hcd_at91_probe(const struct hc_driver *driver, | |||
148 | at91_start_hc(pdev); | 148 | at91_start_hc(pdev); |
149 | ohci_hcd_init(hcd_to_ohci(hcd)); | 149 | ohci_hcd_init(hcd_to_ohci(hcd)); |
150 | 150 | ||
151 | retval = usb_add_hcd(hcd, pdev->resource[1].start, IRQF_DISABLED); | 151 | retval = usb_add_hcd(hcd, pdev->resource[1].start, IRQF_SHARED); |
152 | if (retval == 0) | 152 | if (retval == 0) |
153 | return retval; | 153 | return retval; |
154 | 154 | ||
diff --git a/drivers/usb/host/ohci-au1xxx.c b/drivers/usb/host/ohci-au1xxx.c index 2ac4e022a13f..e4380082ebb1 100644 --- a/drivers/usb/host/ohci-au1xxx.c +++ b/drivers/usb/host/ohci-au1xxx.c | |||
@@ -248,10 +248,9 @@ static int ohci_hcd_au1xxx_drv_remove(struct platform_device *pdev) | |||
248 | } | 248 | } |
249 | 249 | ||
250 | #ifdef CONFIG_PM | 250 | #ifdef CONFIG_PM |
251 | static int ohci_hcd_au1xxx_drv_suspend(struct platform_device *pdev, | 251 | static int ohci_hcd_au1xxx_drv_suspend(struct device *dev) |
252 | pm_message_t message) | ||
253 | { | 252 | { |
254 | struct usb_hcd *hcd = platform_get_drvdata(pdev); | 253 | struct usb_hcd *hcd = dev_get_drvdata(dev); |
255 | struct ohci_hcd *ohci = hcd_to_ohci(hcd); | 254 | struct ohci_hcd *ohci = hcd_to_ohci(hcd); |
256 | unsigned long flags; | 255 | unsigned long flags; |
257 | int rc; | 256 | int rc; |
@@ -274,10 +273,6 @@ static int ohci_hcd_au1xxx_drv_suspend(struct platform_device *pdev, | |||
274 | ohci_writel(ohci, OHCI_INTR_MIE, &ohci->regs->intrdisable); | 273 | ohci_writel(ohci, OHCI_INTR_MIE, &ohci->regs->intrdisable); |
275 | (void)ohci_readl(ohci, &ohci->regs->intrdisable); | 274 | (void)ohci_readl(ohci, &ohci->regs->intrdisable); |
276 | 275 | ||
277 | /* make sure snapshot being resumed re-enumerates everything */ | ||
278 | if (message.event == PM_EVENT_PRETHAW) | ||
279 | ohci_usb_reset(ohci); | ||
280 | |||
281 | clear_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags); | 276 | clear_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags); |
282 | 277 | ||
283 | au1xxx_stop_ohc(); | 278 | au1xxx_stop_ohc(); |
@@ -287,9 +282,9 @@ bail: | |||
287 | return rc; | 282 | return rc; |
288 | } | 283 | } |
289 | 284 | ||
290 | static int ohci_hcd_au1xxx_drv_resume(struct platform_device *pdev) | 285 | static int ohci_hcd_au1xxx_drv_resume(struct device *dev) |
291 | { | 286 | { |
292 | struct usb_hcd *hcd = platform_get_drvdata(pdev); | 287 | struct usb_hcd *hcd = dev_get_drvdata(dev); |
293 | 288 | ||
294 | au1xxx_start_ohc(); | 289 | au1xxx_start_ohc(); |
295 | 290 | ||
@@ -298,20 +293,26 @@ static int ohci_hcd_au1xxx_drv_resume(struct platform_device *pdev) | |||
298 | 293 | ||
299 | return 0; | 294 | return 0; |
300 | } | 295 | } |
296 | |||
297 | static struct dev_pm_ops au1xxx_ohci_pmops = { | ||
298 | .suspend = ohci_hcd_au1xxx_drv_suspend, | ||
299 | .resume = ohci_hcd_au1xxx_drv_resume, | ||
300 | }; | ||
301 | |||
302 | #define AU1XXX_OHCI_PMOPS &au1xxx_ohci_pmops | ||
303 | |||
301 | #else | 304 | #else |
302 | #define ohci_hcd_au1xxx_drv_suspend NULL | 305 | #define AU1XXX_OHCI_PMOPS NULL |
303 | #define ohci_hcd_au1xxx_drv_resume NULL | ||
304 | #endif | 306 | #endif |
305 | 307 | ||
306 | static struct platform_driver ohci_hcd_au1xxx_driver = { | 308 | static struct platform_driver ohci_hcd_au1xxx_driver = { |
307 | .probe = ohci_hcd_au1xxx_drv_probe, | 309 | .probe = ohci_hcd_au1xxx_drv_probe, |
308 | .remove = ohci_hcd_au1xxx_drv_remove, | 310 | .remove = ohci_hcd_au1xxx_drv_remove, |
309 | .shutdown = usb_hcd_platform_shutdown, | 311 | .shutdown = usb_hcd_platform_shutdown, |
310 | .suspend = ohci_hcd_au1xxx_drv_suspend, | ||
311 | .resume = ohci_hcd_au1xxx_drv_resume, | ||
312 | .driver = { | 312 | .driver = { |
313 | .name = "au1xxx-ohci", | 313 | .name = "au1xxx-ohci", |
314 | .owner = THIS_MODULE, | 314 | .owner = THIS_MODULE, |
315 | .pm = AU1XXX_OHCI_PMOPS, | ||
315 | }, | 316 | }, |
316 | }; | 317 | }; |
317 | 318 | ||
diff --git a/drivers/usb/host/ohci-ep93xx.c b/drivers/usb/host/ohci-ep93xx.c index b0dbf4157d29..4e681613e7ae 100644 --- a/drivers/usb/host/ohci-ep93xx.c +++ b/drivers/usb/host/ohci-ep93xx.c | |||
@@ -188,7 +188,6 @@ static int ohci_hcd_ep93xx_drv_resume(struct platform_device *pdev) | |||
188 | { | 188 | { |
189 | struct usb_hcd *hcd = platform_get_drvdata(pdev); | 189 | struct usb_hcd *hcd = platform_get_drvdata(pdev); |
190 | struct ohci_hcd *ohci = hcd_to_ohci(hcd); | 190 | struct ohci_hcd *ohci = hcd_to_ohci(hcd); |
191 | int status; | ||
192 | 191 | ||
193 | if (time_before(jiffies, ohci->next_statechange)) | 192 | if (time_before(jiffies, ohci->next_statechange)) |
194 | msleep(5); | 193 | msleep(5); |
diff --git a/drivers/usb/host/ohci-hcd.c b/drivers/usb/host/ohci-hcd.c index 58151687d351..78bb7710f36d 100644 --- a/drivers/usb/host/ohci-hcd.c +++ b/drivers/usb/host/ohci-hcd.c | |||
@@ -34,7 +34,6 @@ | |||
34 | #include <linux/usb/otg.h> | 34 | #include <linux/usb/otg.h> |
35 | #include <linux/dma-mapping.h> | 35 | #include <linux/dma-mapping.h> |
36 | #include <linux/dmapool.h> | 36 | #include <linux/dmapool.h> |
37 | #include <linux/reboot.h> | ||
38 | #include <linux/workqueue.h> | 37 | #include <linux/workqueue.h> |
39 | #include <linux/debugfs.h> | 38 | #include <linux/debugfs.h> |
40 | 39 | ||
diff --git a/drivers/usb/host/ohci-pxa27x.c b/drivers/usb/host/ohci-pxa27x.c index bbc0c3b720b2..f1c06202fdf2 100644 --- a/drivers/usb/host/ohci-pxa27x.c +++ b/drivers/usb/host/ohci-pxa27x.c | |||
@@ -177,9 +177,13 @@ static inline void pxa27x_setup_hc(struct pxa27x_ohci *ohci, | |||
177 | 177 | ||
178 | if (inf->flags & NO_OC_PROTECTION) | 178 | if (inf->flags & NO_OC_PROTECTION) |
179 | uhcrhda |= UHCRHDA_NOCP; | 179 | uhcrhda |= UHCRHDA_NOCP; |
180 | else | ||
181 | uhcrhda &= ~UHCRHDA_NOCP; | ||
180 | 182 | ||
181 | if (inf->flags & OC_MODE_PERPORT) | 183 | if (inf->flags & OC_MODE_PERPORT) |
182 | uhcrhda |= UHCRHDA_OCPM; | 184 | uhcrhda |= UHCRHDA_OCPM; |
185 | else | ||
186 | uhcrhda &= ~UHCRHDA_OCPM; | ||
183 | 187 | ||
184 | if (inf->power_on_delay) { | 188 | if (inf->power_on_delay) { |
185 | uhcrhda &= ~UHCRHDA_POTPGT(0xff); | 189 | uhcrhda &= ~UHCRHDA_POTPGT(0xff); |
diff --git a/drivers/usb/host/ohci-q.c b/drivers/usb/host/ohci-q.c index c2d80f80448b..16fecb8ecc39 100644 --- a/drivers/usb/host/ohci-q.c +++ b/drivers/usb/host/ohci-q.c | |||
@@ -418,7 +418,7 @@ static struct ed *ed_get ( | |||
418 | is_out = !(ep->desc.bEndpointAddress & USB_DIR_IN); | 418 | is_out = !(ep->desc.bEndpointAddress & USB_DIR_IN); |
419 | 419 | ||
420 | /* FIXME usbcore changes dev->devnum before SET_ADDRESS | 420 | /* FIXME usbcore changes dev->devnum before SET_ADDRESS |
421 | * suceeds ... otherwise we wouldn't need "pipe". | 421 | * succeeds ... otherwise we wouldn't need "pipe". |
422 | */ | 422 | */ |
423 | info = usb_pipedevice (pipe); | 423 | info = usb_pipedevice (pipe); |
424 | ed->type = usb_pipetype(pipe); | 424 | ed->type = usb_pipetype(pipe); |
diff --git a/drivers/usb/host/oxu210hp-hcd.c b/drivers/usb/host/oxu210hp-hcd.c index 5ac489ee3dab..50f57f468836 100644 --- a/drivers/usb/host/oxu210hp-hcd.c +++ b/drivers/usb/host/oxu210hp-hcd.c | |||
@@ -33,7 +33,6 @@ | |||
33 | #include <linux/timer.h> | 33 | #include <linux/timer.h> |
34 | #include <linux/list.h> | 34 | #include <linux/list.h> |
35 | #include <linux/interrupt.h> | 35 | #include <linux/interrupt.h> |
36 | #include <linux/reboot.h> | ||
37 | #include <linux/usb.h> | 36 | #include <linux/usb.h> |
38 | #include <linux/moduleparam.h> | 37 | #include <linux/moduleparam.h> |
39 | #include <linux/dma-mapping.h> | 38 | #include <linux/dma-mapping.h> |
diff --git a/drivers/usb/host/pci-quirks.c b/drivers/usb/host/pci-quirks.c index 83b5f9cea85a..23cf3bde4762 100644 --- a/drivers/usb/host/pci-quirks.c +++ b/drivers/usb/host/pci-quirks.c | |||
@@ -475,4 +475,4 @@ static void __devinit quirk_usb_early_handoff(struct pci_dev *pdev) | |||
475 | else if (pdev->class == PCI_CLASS_SERIAL_USB_XHCI) | 475 | else if (pdev->class == PCI_CLASS_SERIAL_USB_XHCI) |
476 | quirk_usb_handoff_xhci(pdev); | 476 | quirk_usb_handoff_xhci(pdev); |
477 | } | 477 | } |
478 | DECLARE_PCI_FIXUP_FINAL(PCI_ANY_ID, PCI_ANY_ID, quirk_usb_early_handoff); | 478 | DECLARE_PCI_FIXUP_HEADER(PCI_ANY_ID, PCI_ANY_ID, quirk_usb_early_handoff); |
diff --git a/drivers/usb/host/r8a66597-hcd.c b/drivers/usb/host/r8a66597-hcd.c index e18f74946e68..749b53742828 100644 --- a/drivers/usb/host/r8a66597-hcd.c +++ b/drivers/usb/host/r8a66597-hcd.c | |||
@@ -91,43 +91,43 @@ static int r8a66597_clock_enable(struct r8a66597 *r8a66597) | |||
91 | u16 tmp; | 91 | u16 tmp; |
92 | int i = 0; | 92 | int i = 0; |
93 | 93 | ||
94 | #if defined(CONFIG_SUPERH_ON_CHIP_R8A66597) | 94 | if (r8a66597->pdata->on_chip) { |
95 | #if defined(CONFIG_HAVE_CLK) | 95 | #ifdef CONFIG_HAVE_CLK |
96 | clk_enable(r8a66597->clk); | 96 | clk_enable(r8a66597->clk); |
97 | #endif | 97 | #endif |
98 | do { | 98 | do { |
99 | r8a66597_write(r8a66597, SCKE, SYSCFG0); | 99 | r8a66597_write(r8a66597, SCKE, SYSCFG0); |
100 | tmp = r8a66597_read(r8a66597, SYSCFG0); | 100 | tmp = r8a66597_read(r8a66597, SYSCFG0); |
101 | if (i++ > 1000) { | 101 | if (i++ > 1000) { |
102 | printk(KERN_ERR "r8a66597: register access fail.\n"); | 102 | printk(KERN_ERR "r8a66597: reg access fail.\n"); |
103 | return -ENXIO; | 103 | return -ENXIO; |
104 | } | 104 | } |
105 | } while ((tmp & SCKE) != SCKE); | 105 | } while ((tmp & SCKE) != SCKE); |
106 | r8a66597_write(r8a66597, 0x04, 0x02); | 106 | r8a66597_write(r8a66597, 0x04, 0x02); |
107 | #else | 107 | } else { |
108 | do { | 108 | do { |
109 | r8a66597_write(r8a66597, USBE, SYSCFG0); | 109 | r8a66597_write(r8a66597, USBE, SYSCFG0); |
110 | tmp = r8a66597_read(r8a66597, SYSCFG0); | 110 | tmp = r8a66597_read(r8a66597, SYSCFG0); |
111 | if (i++ > 1000) { | 111 | if (i++ > 1000) { |
112 | printk(KERN_ERR "r8a66597: register access fail.\n"); | 112 | printk(KERN_ERR "r8a66597: reg access fail.\n"); |
113 | return -ENXIO; | 113 | return -ENXIO; |
114 | } | 114 | } |
115 | } while ((tmp & USBE) != USBE); | 115 | } while ((tmp & USBE) != USBE); |
116 | r8a66597_bclr(r8a66597, USBE, SYSCFG0); | 116 | r8a66597_bclr(r8a66597, USBE, SYSCFG0); |
117 | r8a66597_mdfy(r8a66597, get_xtal_from_pdata(r8a66597->pdata), XTAL, | 117 | r8a66597_mdfy(r8a66597, get_xtal_from_pdata(r8a66597->pdata), |
118 | SYSCFG0); | 118 | XTAL, SYSCFG0); |
119 | 119 | ||
120 | i = 0; | 120 | i = 0; |
121 | r8a66597_bset(r8a66597, XCKE, SYSCFG0); | 121 | r8a66597_bset(r8a66597, XCKE, SYSCFG0); |
122 | do { | 122 | do { |
123 | msleep(1); | 123 | msleep(1); |
124 | tmp = r8a66597_read(r8a66597, SYSCFG0); | 124 | tmp = r8a66597_read(r8a66597, SYSCFG0); |
125 | if (i++ > 500) { | 125 | if (i++ > 500) { |
126 | printk(KERN_ERR "r8a66597: register access fail.\n"); | 126 | printk(KERN_ERR "r8a66597: reg access fail.\n"); |
127 | return -ENXIO; | 127 | return -ENXIO; |
128 | } | 128 | } |
129 | } while ((tmp & SCKE) != SCKE); | 129 | } while ((tmp & SCKE) != SCKE); |
130 | #endif /* #if defined(CONFIG_SUPERH_ON_CHIP_R8A66597) */ | 130 | } |
131 | 131 | ||
132 | return 0; | 132 | return 0; |
133 | } | 133 | } |
@@ -136,15 +136,16 @@ static void r8a66597_clock_disable(struct r8a66597 *r8a66597) | |||
136 | { | 136 | { |
137 | r8a66597_bclr(r8a66597, SCKE, SYSCFG0); | 137 | r8a66597_bclr(r8a66597, SCKE, SYSCFG0); |
138 | udelay(1); | 138 | udelay(1); |
139 | #if defined(CONFIG_SUPERH_ON_CHIP_R8A66597) | 139 | |
140 | #if defined(CONFIG_HAVE_CLK) | 140 | if (r8a66597->pdata->on_chip) { |
141 | clk_disable(r8a66597->clk); | 141 | #ifdef CONFIG_HAVE_CLK |
142 | #endif | 142 | clk_disable(r8a66597->clk); |
143 | #else | ||
144 | r8a66597_bclr(r8a66597, PLLC, SYSCFG0); | ||
145 | r8a66597_bclr(r8a66597, XCKE, SYSCFG0); | ||
146 | r8a66597_bclr(r8a66597, USBE, SYSCFG0); | ||
147 | #endif | 143 | #endif |
144 | } else { | ||
145 | r8a66597_bclr(r8a66597, PLLC, SYSCFG0); | ||
146 | r8a66597_bclr(r8a66597, XCKE, SYSCFG0); | ||
147 | r8a66597_bclr(r8a66597, USBE, SYSCFG0); | ||
148 | } | ||
148 | } | 149 | } |
149 | 150 | ||
150 | static void r8a66597_enable_port(struct r8a66597 *r8a66597, int port) | 151 | static void r8a66597_enable_port(struct r8a66597 *r8a66597, int port) |
@@ -205,7 +206,7 @@ static int enable_controller(struct r8a66597 *r8a66597) | |||
205 | 206 | ||
206 | r8a66597_bset(r8a66597, SIGNE | SACKE, INTENB1); | 207 | r8a66597_bset(r8a66597, SIGNE | SACKE, INTENB1); |
207 | 208 | ||
208 | for (port = 0; port < R8A66597_MAX_ROOT_HUB; port++) | 209 | for (port = 0; port < r8a66597->max_root_hub; port++) |
209 | r8a66597_enable_port(r8a66597, port); | 210 | r8a66597_enable_port(r8a66597, port); |
210 | 211 | ||
211 | return 0; | 212 | return 0; |
@@ -218,7 +219,7 @@ static void disable_controller(struct r8a66597 *r8a66597) | |||
218 | r8a66597_write(r8a66597, 0, INTENB0); | 219 | r8a66597_write(r8a66597, 0, INTENB0); |
219 | r8a66597_write(r8a66597, 0, INTSTS0); | 220 | r8a66597_write(r8a66597, 0, INTSTS0); |
220 | 221 | ||
221 | for (port = 0; port < R8A66597_MAX_ROOT_HUB; port++) | 222 | for (port = 0; port < r8a66597->max_root_hub; port++) |
222 | r8a66597_disable_port(r8a66597, port); | 223 | r8a66597_disable_port(r8a66597, port); |
223 | 224 | ||
224 | r8a66597_clock_disable(r8a66597); | 225 | r8a66597_clock_disable(r8a66597); |
@@ -249,11 +250,12 @@ static int is_hub_limit(char *devpath) | |||
249 | return ((strlen(devpath) >= 4) ? 1 : 0); | 250 | return ((strlen(devpath) >= 4) ? 1 : 0); |
250 | } | 251 | } |
251 | 252 | ||
252 | static void get_port_number(char *devpath, u16 *root_port, u16 *hub_port) | 253 | static void get_port_number(struct r8a66597 *r8a66597, |
254 | char *devpath, u16 *root_port, u16 *hub_port) | ||
253 | { | 255 | { |
254 | if (root_port) { | 256 | if (root_port) { |
255 | *root_port = (devpath[0] & 0x0F) - 1; | 257 | *root_port = (devpath[0] & 0x0F) - 1; |
256 | if (*root_port >= R8A66597_MAX_ROOT_HUB) | 258 | if (*root_port >= r8a66597->max_root_hub) |
257 | printk(KERN_ERR "r8a66597: Illegal root port number.\n"); | 259 | printk(KERN_ERR "r8a66597: Illegal root port number.\n"); |
258 | } | 260 | } |
259 | if (hub_port) | 261 | if (hub_port) |
@@ -355,7 +357,8 @@ static int make_r8a66597_device(struct r8a66597 *r8a66597, | |||
355 | INIT_LIST_HEAD(&dev->device_list); | 357 | INIT_LIST_HEAD(&dev->device_list); |
356 | list_add_tail(&dev->device_list, &r8a66597->child_device); | 358 | list_add_tail(&dev->device_list, &r8a66597->child_device); |
357 | 359 | ||
358 | get_port_number(urb->dev->devpath, &dev->root_port, &dev->hub_port); | 360 | get_port_number(r8a66597, urb->dev->devpath, |
361 | &dev->root_port, &dev->hub_port); | ||
359 | if (!is_child_device(urb->dev->devpath)) | 362 | if (!is_child_device(urb->dev->devpath)) |
360 | r8a66597->root_hub[dev->root_port].dev = dev; | 363 | r8a66597->root_hub[dev->root_port].dev = dev; |
361 | 364 | ||
@@ -420,7 +423,7 @@ static void free_usb_address(struct r8a66597 *r8a66597, | |||
420 | list_del(&dev->device_list); | 423 | list_del(&dev->device_list); |
421 | kfree(dev); | 424 | kfree(dev); |
422 | 425 | ||
423 | for (port = 0; port < R8A66597_MAX_ROOT_HUB; port++) { | 426 | for (port = 0; port < r8a66597->max_root_hub; port++) { |
424 | if (r8a66597->root_hub[port].dev == dev) { | 427 | if (r8a66597->root_hub[port].dev == dev) { |
425 | r8a66597->root_hub[port].dev = NULL; | 428 | r8a66597->root_hub[port].dev = NULL; |
426 | break; | 429 | break; |
@@ -495,10 +498,20 @@ static void r8a66597_pipe_toggle(struct r8a66597 *r8a66597, | |||
495 | r8a66597_bset(r8a66597, SQCLR, pipe->pipectr); | 498 | r8a66597_bset(r8a66597, SQCLR, pipe->pipectr); |
496 | } | 499 | } |
497 | 500 | ||
501 | static inline unsigned short mbw_value(struct r8a66597 *r8a66597) | ||
502 | { | ||
503 | if (r8a66597->pdata->on_chip) | ||
504 | return MBW_32; | ||
505 | else | ||
506 | return MBW_16; | ||
507 | } | ||
508 | |||
498 | /* this function must be called with interrupt disabled */ | 509 | /* this function must be called with interrupt disabled */ |
499 | static inline void cfifo_change(struct r8a66597 *r8a66597, u16 pipenum) | 510 | static inline void cfifo_change(struct r8a66597 *r8a66597, u16 pipenum) |
500 | { | 511 | { |
501 | r8a66597_mdfy(r8a66597, MBW | pipenum, MBW | CURPIPE, CFIFOSEL); | 512 | unsigned short mbw = mbw_value(r8a66597); |
513 | |||
514 | r8a66597_mdfy(r8a66597, mbw | pipenum, mbw | CURPIPE, CFIFOSEL); | ||
502 | r8a66597_reg_wait(r8a66597, CFIFOSEL, CURPIPE, pipenum); | 515 | r8a66597_reg_wait(r8a66597, CFIFOSEL, CURPIPE, pipenum); |
503 | } | 516 | } |
504 | 517 | ||
@@ -506,11 +519,13 @@ static inline void cfifo_change(struct r8a66597 *r8a66597, u16 pipenum) | |||
506 | static inline void fifo_change_from_pipe(struct r8a66597 *r8a66597, | 519 | static inline void fifo_change_from_pipe(struct r8a66597 *r8a66597, |
507 | struct r8a66597_pipe *pipe) | 520 | struct r8a66597_pipe *pipe) |
508 | { | 521 | { |
522 | unsigned short mbw = mbw_value(r8a66597); | ||
523 | |||
509 | cfifo_change(r8a66597, 0); | 524 | cfifo_change(r8a66597, 0); |
510 | r8a66597_mdfy(r8a66597, MBW | 0, MBW | CURPIPE, D0FIFOSEL); | 525 | r8a66597_mdfy(r8a66597, mbw | 0, mbw | CURPIPE, D0FIFOSEL); |
511 | r8a66597_mdfy(r8a66597, MBW | 0, MBW | CURPIPE, D1FIFOSEL); | 526 | r8a66597_mdfy(r8a66597, mbw | 0, mbw | CURPIPE, D1FIFOSEL); |
512 | 527 | ||
513 | r8a66597_mdfy(r8a66597, MBW | pipe->info.pipenum, MBW | CURPIPE, | 528 | r8a66597_mdfy(r8a66597, mbw | pipe->info.pipenum, mbw | CURPIPE, |
514 | pipe->fifosel); | 529 | pipe->fifosel); |
515 | r8a66597_reg_wait(r8a66597, pipe->fifosel, CURPIPE, pipe->info.pipenum); | 530 | r8a66597_reg_wait(r8a66597, pipe->fifosel, CURPIPE, pipe->info.pipenum); |
516 | } | 531 | } |
@@ -742,9 +757,13 @@ static void enable_r8a66597_pipe_dma(struct r8a66597 *r8a66597, | |||
742 | struct r8a66597_pipe *pipe, | 757 | struct r8a66597_pipe *pipe, |
743 | struct urb *urb) | 758 | struct urb *urb) |
744 | { | 759 | { |
745 | #if !defined(CONFIG_SUPERH_ON_CHIP_R8A66597) | ||
746 | int i; | 760 | int i; |
747 | struct r8a66597_pipe_info *info = &pipe->info; | 761 | struct r8a66597_pipe_info *info = &pipe->info; |
762 | unsigned short mbw = mbw_value(r8a66597); | ||
763 | |||
764 | /* pipe dma is only for external controlles */ | ||
765 | if (r8a66597->pdata->on_chip) | ||
766 | return; | ||
748 | 767 | ||
749 | if ((pipe->info.pipenum != 0) && (info->type != R8A66597_INT)) { | 768 | if ((pipe->info.pipenum != 0) && (info->type != R8A66597_INT)) { |
750 | for (i = 0; i < R8A66597_MAX_DMA_CHANNEL; i++) { | 769 | for (i = 0; i < R8A66597_MAX_DMA_CHANNEL; i++) { |
@@ -763,8 +782,8 @@ static void enable_r8a66597_pipe_dma(struct r8a66597 *r8a66597, | |||
763 | set_pipe_reg_addr(pipe, i); | 782 | set_pipe_reg_addr(pipe, i); |
764 | 783 | ||
765 | cfifo_change(r8a66597, 0); | 784 | cfifo_change(r8a66597, 0); |
766 | r8a66597_mdfy(r8a66597, MBW | pipe->info.pipenum, | 785 | r8a66597_mdfy(r8a66597, mbw | pipe->info.pipenum, |
767 | MBW | CURPIPE, pipe->fifosel); | 786 | mbw | CURPIPE, pipe->fifosel); |
768 | 787 | ||
769 | r8a66597_reg_wait(r8a66597, pipe->fifosel, CURPIPE, | 788 | r8a66597_reg_wait(r8a66597, pipe->fifosel, CURPIPE, |
770 | pipe->info.pipenum); | 789 | pipe->info.pipenum); |
@@ -772,7 +791,6 @@ static void enable_r8a66597_pipe_dma(struct r8a66597 *r8a66597, | |||
772 | break; | 791 | break; |
773 | } | 792 | } |
774 | } | 793 | } |
775 | #endif /* #if defined(CONFIG_SUPERH_ON_CHIP_R8A66597) */ | ||
776 | } | 794 | } |
777 | 795 | ||
778 | /* this function must be called with interrupt disabled */ | 796 | /* this function must be called with interrupt disabled */ |
@@ -1769,7 +1787,7 @@ static void r8a66597_timer(unsigned long _r8a66597) | |||
1769 | 1787 | ||
1770 | spin_lock_irqsave(&r8a66597->lock, flags); | 1788 | spin_lock_irqsave(&r8a66597->lock, flags); |
1771 | 1789 | ||
1772 | for (port = 0; port < R8A66597_MAX_ROOT_HUB; port++) | 1790 | for (port = 0; port < r8a66597->max_root_hub; port++) |
1773 | r8a66597_root_hub_control(r8a66597, port); | 1791 | r8a66597_root_hub_control(r8a66597, port); |
1774 | 1792 | ||
1775 | spin_unlock_irqrestore(&r8a66597->lock, flags); | 1793 | spin_unlock_irqrestore(&r8a66597->lock, flags); |
@@ -1807,7 +1825,7 @@ static void set_address_zero(struct r8a66597 *r8a66597, struct urb *urb) | |||
1807 | u16 root_port, hub_port; | 1825 | u16 root_port, hub_port; |
1808 | 1826 | ||
1809 | if (usb_address == 0) { | 1827 | if (usb_address == 0) { |
1810 | get_port_number(urb->dev->devpath, | 1828 | get_port_number(r8a66597, urb->dev->devpath, |
1811 | &root_port, &hub_port); | 1829 | &root_port, &hub_port); |
1812 | set_devadd_reg(r8a66597, 0, | 1830 | set_devadd_reg(r8a66597, 0, |
1813 | get_r8a66597_usb_speed(urb->dev->speed), | 1831 | get_r8a66597_usb_speed(urb->dev->speed), |
@@ -2082,7 +2100,7 @@ static int r8a66597_hub_status_data(struct usb_hcd *hcd, char *buf) | |||
2082 | 2100 | ||
2083 | *buf = 0; /* initialize (no change) */ | 2101 | *buf = 0; /* initialize (no change) */ |
2084 | 2102 | ||
2085 | for (i = 0; i < R8A66597_MAX_ROOT_HUB; i++) { | 2103 | for (i = 0; i < r8a66597->max_root_hub; i++) { |
2086 | if (r8a66597->root_hub[i].port & 0xffff0000) | 2104 | if (r8a66597->root_hub[i].port & 0xffff0000) |
2087 | *buf |= 1 << (i + 1); | 2105 | *buf |= 1 << (i + 1); |
2088 | } | 2106 | } |
@@ -2097,11 +2115,11 @@ static void r8a66597_hub_descriptor(struct r8a66597 *r8a66597, | |||
2097 | { | 2115 | { |
2098 | desc->bDescriptorType = 0x29; | 2116 | desc->bDescriptorType = 0x29; |
2099 | desc->bHubContrCurrent = 0; | 2117 | desc->bHubContrCurrent = 0; |
2100 | desc->bNbrPorts = R8A66597_MAX_ROOT_HUB; | 2118 | desc->bNbrPorts = r8a66597->max_root_hub; |
2101 | desc->bDescLength = 9; | 2119 | desc->bDescLength = 9; |
2102 | desc->bPwrOn2PwrGood = 0; | 2120 | desc->bPwrOn2PwrGood = 0; |
2103 | desc->wHubCharacteristics = cpu_to_le16(0x0011); | 2121 | desc->wHubCharacteristics = cpu_to_le16(0x0011); |
2104 | desc->bitmap[0] = ((1 << R8A66597_MAX_ROOT_HUB) - 1) << 1; | 2122 | desc->bitmap[0] = ((1 << r8a66597->max_root_hub) - 1) << 1; |
2105 | desc->bitmap[1] = ~0; | 2123 | desc->bitmap[1] = ~0; |
2106 | } | 2124 | } |
2107 | 2125 | ||
@@ -2129,7 +2147,7 @@ static int r8a66597_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue, | |||
2129 | } | 2147 | } |
2130 | break; | 2148 | break; |
2131 | case ClearPortFeature: | 2149 | case ClearPortFeature: |
2132 | if (wIndex > R8A66597_MAX_ROOT_HUB) | 2150 | if (wIndex > r8a66597->max_root_hub) |
2133 | goto error; | 2151 | goto error; |
2134 | if (wLength != 0) | 2152 | if (wLength != 0) |
2135 | goto error; | 2153 | goto error; |
@@ -2162,12 +2180,12 @@ static int r8a66597_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue, | |||
2162 | *buf = 0x00; | 2180 | *buf = 0x00; |
2163 | break; | 2181 | break; |
2164 | case GetPortStatus: | 2182 | case GetPortStatus: |
2165 | if (wIndex > R8A66597_MAX_ROOT_HUB) | 2183 | if (wIndex > r8a66597->max_root_hub) |
2166 | goto error; | 2184 | goto error; |
2167 | *(__le32 *)buf = cpu_to_le32(rh->port); | 2185 | *(__le32 *)buf = cpu_to_le32(rh->port); |
2168 | break; | 2186 | break; |
2169 | case SetPortFeature: | 2187 | case SetPortFeature: |
2170 | if (wIndex > R8A66597_MAX_ROOT_HUB) | 2188 | if (wIndex > r8a66597->max_root_hub) |
2171 | goto error; | 2189 | goto error; |
2172 | if (wLength != 0) | 2190 | if (wLength != 0) |
2173 | goto error; | 2191 | goto error; |
@@ -2216,7 +2234,7 @@ static int r8a66597_bus_suspend(struct usb_hcd *hcd) | |||
2216 | 2234 | ||
2217 | dbg("%s", __func__); | 2235 | dbg("%s", __func__); |
2218 | 2236 | ||
2219 | for (port = 0; port < R8A66597_MAX_ROOT_HUB; port++) { | 2237 | for (port = 0; port < r8a66597->max_root_hub; port++) { |
2220 | struct r8a66597_root_hub *rh = &r8a66597->root_hub[port]; | 2238 | struct r8a66597_root_hub *rh = &r8a66597->root_hub[port]; |
2221 | unsigned long dvstctr_reg = get_dvstctr_reg(port); | 2239 | unsigned long dvstctr_reg = get_dvstctr_reg(port); |
2222 | 2240 | ||
@@ -2247,7 +2265,7 @@ static int r8a66597_bus_resume(struct usb_hcd *hcd) | |||
2247 | 2265 | ||
2248 | dbg("%s", __func__); | 2266 | dbg("%s", __func__); |
2249 | 2267 | ||
2250 | for (port = 0; port < R8A66597_MAX_ROOT_HUB; port++) { | 2268 | for (port = 0; port < r8a66597->max_root_hub; port++) { |
2251 | struct r8a66597_root_hub *rh = &r8a66597->root_hub[port]; | 2269 | struct r8a66597_root_hub *rh = &r8a66597->root_hub[port]; |
2252 | unsigned long dvstctr_reg = get_dvstctr_reg(port); | 2270 | unsigned long dvstctr_reg = get_dvstctr_reg(port); |
2253 | 2271 | ||
@@ -2305,16 +2323,16 @@ static struct hc_driver r8a66597_hc_driver = { | |||
2305 | }; | 2323 | }; |
2306 | 2324 | ||
2307 | #if defined(CONFIG_PM) | 2325 | #if defined(CONFIG_PM) |
2308 | static int r8a66597_suspend(struct platform_device *pdev, pm_message_t state) | 2326 | static int r8a66597_suspend(struct device *dev) |
2309 | { | 2327 | { |
2310 | struct r8a66597 *r8a66597 = dev_get_drvdata(&pdev->dev); | 2328 | struct r8a66597 *r8a66597 = dev_get_drvdata(dev); |
2311 | int port; | 2329 | int port; |
2312 | 2330 | ||
2313 | dbg("%s", __func__); | 2331 | dbg("%s", __func__); |
2314 | 2332 | ||
2315 | disable_controller(r8a66597); | 2333 | disable_controller(r8a66597); |
2316 | 2334 | ||
2317 | for (port = 0; port < R8A66597_MAX_ROOT_HUB; port++) { | 2335 | for (port = 0; port < r8a66597->max_root_hub; port++) { |
2318 | struct r8a66597_root_hub *rh = &r8a66597->root_hub[port]; | 2336 | struct r8a66597_root_hub *rh = &r8a66597->root_hub[port]; |
2319 | 2337 | ||
2320 | rh->port = 0x00000000; | 2338 | rh->port = 0x00000000; |
@@ -2323,9 +2341,9 @@ static int r8a66597_suspend(struct platform_device *pdev, pm_message_t state) | |||
2323 | return 0; | 2341 | return 0; |
2324 | } | 2342 | } |
2325 | 2343 | ||
2326 | static int r8a66597_resume(struct platform_device *pdev) | 2344 | static int r8a66597_resume(struct device *dev) |
2327 | { | 2345 | { |
2328 | struct r8a66597 *r8a66597 = dev_get_drvdata(&pdev->dev); | 2346 | struct r8a66597 *r8a66597 = dev_get_drvdata(dev); |
2329 | struct usb_hcd *hcd = r8a66597_to_hcd(r8a66597); | 2347 | struct usb_hcd *hcd = r8a66597_to_hcd(r8a66597); |
2330 | 2348 | ||
2331 | dbg("%s", __func__); | 2349 | dbg("%s", __func__); |
@@ -2335,9 +2353,17 @@ static int r8a66597_resume(struct platform_device *pdev) | |||
2335 | 2353 | ||
2336 | return 0; | 2354 | return 0; |
2337 | } | 2355 | } |
2356 | |||
2357 | static struct dev_pm_ops r8a66597_dev_pm_ops = { | ||
2358 | .suspend = r8a66597_suspend, | ||
2359 | .resume = r8a66597_resume, | ||
2360 | .poweroff = r8a66597_suspend, | ||
2361 | .restore = r8a66597_resume, | ||
2362 | }; | ||
2363 | |||
2364 | #define R8A66597_DEV_PM_OPS (&r8a66597_dev_pm_ops) | ||
2338 | #else /* if defined(CONFIG_PM) */ | 2365 | #else /* if defined(CONFIG_PM) */ |
2339 | #define r8a66597_suspend NULL | 2366 | #define R8A66597_DEV_PM_OPS NULL |
2340 | #define r8a66597_resume NULL | ||
2341 | #endif | 2367 | #endif |
2342 | 2368 | ||
2343 | static int __init_or_module r8a66597_remove(struct platform_device *pdev) | 2369 | static int __init_or_module r8a66597_remove(struct platform_device *pdev) |
@@ -2348,8 +2374,9 @@ static int __init_or_module r8a66597_remove(struct platform_device *pdev) | |||
2348 | del_timer_sync(&r8a66597->rh_timer); | 2374 | del_timer_sync(&r8a66597->rh_timer); |
2349 | usb_remove_hcd(hcd); | 2375 | usb_remove_hcd(hcd); |
2350 | iounmap((void *)r8a66597->reg); | 2376 | iounmap((void *)r8a66597->reg); |
2351 | #if defined(CONFIG_SUPERH_ON_CHIP_R8A66597) && defined(CONFIG_HAVE_CLK) | 2377 | #ifdef CONFIG_HAVE_CLK |
2352 | clk_put(r8a66597->clk); | 2378 | if (r8a66597->pdata->on_chip) |
2379 | clk_put(r8a66597->clk); | ||
2353 | #endif | 2380 | #endif |
2354 | usb_put_hcd(hcd); | 2381 | usb_put_hcd(hcd); |
2355 | return 0; | 2382 | return 0; |
@@ -2357,7 +2384,7 @@ static int __init_or_module r8a66597_remove(struct platform_device *pdev) | |||
2357 | 2384 | ||
2358 | static int __devinit r8a66597_probe(struct platform_device *pdev) | 2385 | static int __devinit r8a66597_probe(struct platform_device *pdev) |
2359 | { | 2386 | { |
2360 | #if defined(CONFIG_SUPERH_ON_CHIP_R8A66597) && defined(CONFIG_HAVE_CLK) | 2387 | #ifdef CONFIG_HAVE_CLK |
2361 | char clk_name[8]; | 2388 | char clk_name[8]; |
2362 | #endif | 2389 | #endif |
2363 | struct resource *res = NULL, *ires; | 2390 | struct resource *res = NULL, *ires; |
@@ -2419,15 +2446,20 @@ static int __devinit r8a66597_probe(struct platform_device *pdev) | |||
2419 | r8a66597->pdata = pdev->dev.platform_data; | 2446 | r8a66597->pdata = pdev->dev.platform_data; |
2420 | r8a66597->irq_sense_low = irq_trigger == IRQF_TRIGGER_LOW; | 2447 | r8a66597->irq_sense_low = irq_trigger == IRQF_TRIGGER_LOW; |
2421 | 2448 | ||
2422 | #if defined(CONFIG_SUPERH_ON_CHIP_R8A66597) && defined(CONFIG_HAVE_CLK) | 2449 | if (r8a66597->pdata->on_chip) { |
2423 | snprintf(clk_name, sizeof(clk_name), "usb%d", pdev->id); | 2450 | #ifdef CONFIG_HAVE_CLK |
2424 | r8a66597->clk = clk_get(&pdev->dev, clk_name); | 2451 | snprintf(clk_name, sizeof(clk_name), "usb%d", pdev->id); |
2425 | if (IS_ERR(r8a66597->clk)) { | 2452 | r8a66597->clk = clk_get(&pdev->dev, clk_name); |
2426 | dev_err(&pdev->dev, "cannot get clock \"%s\"\n", clk_name); | 2453 | if (IS_ERR(r8a66597->clk)) { |
2427 | ret = PTR_ERR(r8a66597->clk); | 2454 | dev_err(&pdev->dev, "cannot get clock \"%s\"\n", |
2428 | goto clean_up2; | 2455 | clk_name); |
2429 | } | 2456 | ret = PTR_ERR(r8a66597->clk); |
2457 | goto clean_up2; | ||
2458 | } | ||
2430 | #endif | 2459 | #endif |
2460 | r8a66597->max_root_hub = 1; | ||
2461 | } else | ||
2462 | r8a66597->max_root_hub = 2; | ||
2431 | 2463 | ||
2432 | spin_lock_init(&r8a66597->lock); | 2464 | spin_lock_init(&r8a66597->lock); |
2433 | init_timer(&r8a66597->rh_timer); | 2465 | init_timer(&r8a66597->rh_timer); |
@@ -2457,8 +2489,9 @@ static int __devinit r8a66597_probe(struct platform_device *pdev) | |||
2457 | return 0; | 2489 | return 0; |
2458 | 2490 | ||
2459 | clean_up3: | 2491 | clean_up3: |
2460 | #if defined(CONFIG_SUPERH_ON_CHIP_R8A66597) && defined(CONFIG_HAVE_CLK) | 2492 | #ifdef CONFIG_HAVE_CLK |
2461 | clk_put(r8a66597->clk); | 2493 | if (r8a66597->pdata->on_chip) |
2494 | clk_put(r8a66597->clk); | ||
2462 | clean_up2: | 2495 | clean_up2: |
2463 | #endif | 2496 | #endif |
2464 | usb_put_hcd(hcd); | 2497 | usb_put_hcd(hcd); |
@@ -2473,11 +2506,10 @@ clean_up: | |||
2473 | static struct platform_driver r8a66597_driver = { | 2506 | static struct platform_driver r8a66597_driver = { |
2474 | .probe = r8a66597_probe, | 2507 | .probe = r8a66597_probe, |
2475 | .remove = r8a66597_remove, | 2508 | .remove = r8a66597_remove, |
2476 | .suspend = r8a66597_suspend, | ||
2477 | .resume = r8a66597_resume, | ||
2478 | .driver = { | 2509 | .driver = { |
2479 | .name = (char *) hcd_name, | 2510 | .name = (char *) hcd_name, |
2480 | .owner = THIS_MODULE, | 2511 | .owner = THIS_MODULE, |
2512 | .pm = R8A66597_DEV_PM_OPS, | ||
2481 | }, | 2513 | }, |
2482 | }; | 2514 | }; |
2483 | 2515 | ||
diff --git a/drivers/usb/host/r8a66597.h b/drivers/usb/host/r8a66597.h index d72680b433f9..228e3fb23854 100644 --- a/drivers/usb/host/r8a66597.h +++ b/drivers/usb/host/r8a66597.h | |||
@@ -26,390 +26,16 @@ | |||
26 | #ifndef __R8A66597_H__ | 26 | #ifndef __R8A66597_H__ |
27 | #define __R8A66597_H__ | 27 | #define __R8A66597_H__ |
28 | 28 | ||
29 | #if defined(CONFIG_SUPERH_ON_CHIP_R8A66597) && defined(CONFIG_HAVE_CLK) | 29 | #ifdef CONFIG_HAVE_CLK |
30 | #include <linux/clk.h> | 30 | #include <linux/clk.h> |
31 | #endif | 31 | #endif |
32 | 32 | ||
33 | #include <linux/usb/r8a66597.h> | 33 | #include <linux/usb/r8a66597.h> |
34 | 34 | ||
35 | #define SYSCFG0 0x00 | ||
36 | #define SYSCFG1 0x02 | ||
37 | #define SYSSTS0 0x04 | ||
38 | #define SYSSTS1 0x06 | ||
39 | #define DVSTCTR0 0x08 | ||
40 | #define DVSTCTR1 0x0A | ||
41 | #define TESTMODE 0x0C | ||
42 | #define PINCFG 0x0E | ||
43 | #define DMA0CFG 0x10 | ||
44 | #define DMA1CFG 0x12 | ||
45 | #define CFIFO 0x14 | ||
46 | #define D0FIFO 0x18 | ||
47 | #define D1FIFO 0x1C | ||
48 | #define CFIFOSEL 0x20 | ||
49 | #define CFIFOCTR 0x22 | ||
50 | #define CFIFOSIE 0x24 | ||
51 | #define D0FIFOSEL 0x28 | ||
52 | #define D0FIFOCTR 0x2A | ||
53 | #define D1FIFOSEL 0x2C | ||
54 | #define D1FIFOCTR 0x2E | ||
55 | #define INTENB0 0x30 | ||
56 | #define INTENB1 0x32 | ||
57 | #define INTENB2 0x34 | ||
58 | #define BRDYENB 0x36 | ||
59 | #define NRDYENB 0x38 | ||
60 | #define BEMPENB 0x3A | ||
61 | #define SOFCFG 0x3C | ||
62 | #define INTSTS0 0x40 | ||
63 | #define INTSTS1 0x42 | ||
64 | #define INTSTS2 0x44 | ||
65 | #define BRDYSTS 0x46 | ||
66 | #define NRDYSTS 0x48 | ||
67 | #define BEMPSTS 0x4A | ||
68 | #define FRMNUM 0x4C | ||
69 | #define UFRMNUM 0x4E | ||
70 | #define USBADDR 0x50 | ||
71 | #define USBREQ 0x54 | ||
72 | #define USBVAL 0x56 | ||
73 | #define USBINDX 0x58 | ||
74 | #define USBLENG 0x5A | ||
75 | #define DCPCFG 0x5C | ||
76 | #define DCPMAXP 0x5E | ||
77 | #define DCPCTR 0x60 | ||
78 | #define PIPESEL 0x64 | ||
79 | #define PIPECFG 0x68 | ||
80 | #define PIPEBUF 0x6A | ||
81 | #define PIPEMAXP 0x6C | ||
82 | #define PIPEPERI 0x6E | ||
83 | #define PIPE1CTR 0x70 | ||
84 | #define PIPE2CTR 0x72 | ||
85 | #define PIPE3CTR 0x74 | ||
86 | #define PIPE4CTR 0x76 | ||
87 | #define PIPE5CTR 0x78 | ||
88 | #define PIPE6CTR 0x7A | ||
89 | #define PIPE7CTR 0x7C | ||
90 | #define PIPE8CTR 0x7E | ||
91 | #define PIPE9CTR 0x80 | ||
92 | #define PIPE1TRE 0x90 | ||
93 | #define PIPE1TRN 0x92 | ||
94 | #define PIPE2TRE 0x94 | ||
95 | #define PIPE2TRN 0x96 | ||
96 | #define PIPE3TRE 0x98 | ||
97 | #define PIPE3TRN 0x9A | ||
98 | #define PIPE4TRE 0x9C | ||
99 | #define PIPE4TRN 0x9E | ||
100 | #define PIPE5TRE 0xA0 | ||
101 | #define PIPE5TRN 0xA2 | ||
102 | #define DEVADD0 0xD0 | ||
103 | #define DEVADD1 0xD2 | ||
104 | #define DEVADD2 0xD4 | ||
105 | #define DEVADD3 0xD6 | ||
106 | #define DEVADD4 0xD8 | ||
107 | #define DEVADD5 0xDA | ||
108 | #define DEVADD6 0xDC | ||
109 | #define DEVADD7 0xDE | ||
110 | #define DEVADD8 0xE0 | ||
111 | #define DEVADD9 0xE2 | ||
112 | #define DEVADDA 0xE4 | ||
113 | |||
114 | /* System Configuration Control Register */ | ||
115 | #define XTAL 0xC000 /* b15-14: Crystal selection */ | ||
116 | #define XTAL48 0x8000 /* 48MHz */ | ||
117 | #define XTAL24 0x4000 /* 24MHz */ | ||
118 | #define XTAL12 0x0000 /* 12MHz */ | ||
119 | #define XCKE 0x2000 /* b13: External clock enable */ | ||
120 | #define PLLC 0x0800 /* b11: PLL control */ | ||
121 | #define SCKE 0x0400 /* b10: USB clock enable */ | ||
122 | #define PCSDIS 0x0200 /* b9: not CS wakeup */ | ||
123 | #define LPSME 0x0100 /* b8: Low power sleep mode */ | ||
124 | #define HSE 0x0080 /* b7: Hi-speed enable */ | ||
125 | #define DCFM 0x0040 /* b6: Controller function select */ | ||
126 | #define DRPD 0x0020 /* b5: D+/- pull down control */ | ||
127 | #define DPRPU 0x0010 /* b4: D+ pull up control */ | ||
128 | #define USBE 0x0001 /* b0: USB module operation enable */ | ||
129 | |||
130 | /* System Configuration Status Register */ | ||
131 | #define OVCBIT 0x8000 /* b15-14: Over-current bit */ | ||
132 | #define OVCMON 0xC000 /* b15-14: Over-current monitor */ | ||
133 | #define SOFEA 0x0020 /* b5: SOF monitor */ | ||
134 | #define IDMON 0x0004 /* b3: ID-pin monitor */ | ||
135 | #define LNST 0x0003 /* b1-0: D+, D- line status */ | ||
136 | #define SE1 0x0003 /* SE1 */ | ||
137 | #define FS_KSTS 0x0002 /* Full-Speed K State */ | ||
138 | #define FS_JSTS 0x0001 /* Full-Speed J State */ | ||
139 | #define LS_JSTS 0x0002 /* Low-Speed J State */ | ||
140 | #define LS_KSTS 0x0001 /* Low-Speed K State */ | ||
141 | #define SE0 0x0000 /* SE0 */ | ||
142 | |||
143 | /* Device State Control Register */ | ||
144 | #define EXTLP0 0x0400 /* b10: External port */ | ||
145 | #define VBOUT 0x0200 /* b9: VBUS output */ | ||
146 | #define WKUP 0x0100 /* b8: Remote wakeup */ | ||
147 | #define RWUPE 0x0080 /* b7: Remote wakeup sense */ | ||
148 | #define USBRST 0x0040 /* b6: USB reset enable */ | ||
149 | #define RESUME 0x0020 /* b5: Resume enable */ | ||
150 | #define UACT 0x0010 /* b4: USB bus enable */ | ||
151 | #define RHST 0x0007 /* b1-0: Reset handshake status */ | ||
152 | #define HSPROC 0x0004 /* HS handshake is processing */ | ||
153 | #define HSMODE 0x0003 /* Hi-Speed mode */ | ||
154 | #define FSMODE 0x0002 /* Full-Speed mode */ | ||
155 | #define LSMODE 0x0001 /* Low-Speed mode */ | ||
156 | #define UNDECID 0x0000 /* Undecided */ | ||
157 | |||
158 | /* Test Mode Register */ | ||
159 | #define UTST 0x000F /* b3-0: Test select */ | ||
160 | #define H_TST_PACKET 0x000C /* HOST TEST Packet */ | ||
161 | #define H_TST_SE0_NAK 0x000B /* HOST TEST SE0 NAK */ | ||
162 | #define H_TST_K 0x000A /* HOST TEST K */ | ||
163 | #define H_TST_J 0x0009 /* HOST TEST J */ | ||
164 | #define H_TST_NORMAL 0x0000 /* HOST Normal Mode */ | ||
165 | #define P_TST_PACKET 0x0004 /* PERI TEST Packet */ | ||
166 | #define P_TST_SE0_NAK 0x0003 /* PERI TEST SE0 NAK */ | ||
167 | #define P_TST_K 0x0002 /* PERI TEST K */ | ||
168 | #define P_TST_J 0x0001 /* PERI TEST J */ | ||
169 | #define P_TST_NORMAL 0x0000 /* PERI Normal Mode */ | ||
170 | |||
171 | /* Data Pin Configuration Register */ | ||
172 | #define LDRV 0x8000 /* b15: Drive Current Adjust */ | ||
173 | #define VIF1 0x0000 /* VIF = 1.8V */ | ||
174 | #define VIF3 0x8000 /* VIF = 3.3V */ | ||
175 | #define INTA 0x0001 /* b1: USB INT-pin active */ | ||
176 | |||
177 | /* DMAx Pin Configuration Register */ | ||
178 | #define DREQA 0x4000 /* b14: Dreq active select */ | ||
179 | #define BURST 0x2000 /* b13: Burst mode */ | ||
180 | #define DACKA 0x0400 /* b10: Dack active select */ | ||
181 | #define DFORM 0x0380 /* b9-7: DMA mode select */ | ||
182 | #define CPU_ADR_RD_WR 0x0000 /* Address + RD/WR mode (CPU bus) */ | ||
183 | #define CPU_DACK_RD_WR 0x0100 /* DACK + RD/WR mode (CPU bus) */ | ||
184 | #define CPU_DACK_ONLY 0x0180 /* DACK only mode (CPU bus) */ | ||
185 | #define SPLIT_DACK_ONLY 0x0200 /* DACK only mode (SPLIT bus) */ | ||
186 | #define DENDA 0x0040 /* b6: Dend active select */ | ||
187 | #define PKTM 0x0020 /* b5: Packet mode */ | ||
188 | #define DENDE 0x0010 /* b4: Dend enable */ | ||
189 | #define OBUS 0x0004 /* b2: OUTbus mode */ | ||
190 | |||
191 | /* CFIFO/DxFIFO Port Select Register */ | ||
192 | #define RCNT 0x8000 /* b15: Read count mode */ | ||
193 | #define REW 0x4000 /* b14: Buffer rewind */ | ||
194 | #define DCLRM 0x2000 /* b13: DMA buffer clear mode */ | ||
195 | #define DREQE 0x1000 /* b12: DREQ output enable */ | ||
196 | #if defined(CONFIG_SUPERH_ON_CHIP_R8A66597) | ||
197 | #define MBW 0x0800 | ||
198 | #else | ||
199 | #define MBW 0x0400 /* b10: Maximum bit width for FIFO access */ | ||
200 | #endif | ||
201 | #define MBW_8 0x0000 /* 8bit */ | ||
202 | #define MBW_16 0x0400 /* 16bit */ | ||
203 | #define BIGEND 0x0100 /* b8: Big endian mode */ | ||
204 | #define BYTE_LITTLE 0x0000 /* little dendian */ | ||
205 | #define BYTE_BIG 0x0100 /* big endifan */ | ||
206 | #define ISEL 0x0020 /* b5: DCP FIFO port direction select */ | ||
207 | #define CURPIPE 0x000F /* b2-0: PIPE select */ | ||
208 | |||
209 | /* CFIFO/DxFIFO Port Control Register */ | ||
210 | #define BVAL 0x8000 /* b15: Buffer valid flag */ | ||
211 | #define BCLR 0x4000 /* b14: Buffer clear */ | ||
212 | #define FRDY 0x2000 /* b13: FIFO ready */ | ||
213 | #define DTLN 0x0FFF /* b11-0: FIFO received data length */ | ||
214 | |||
215 | /* Interrupt Enable Register 0 */ | ||
216 | #define VBSE 0x8000 /* b15: VBUS interrupt */ | ||
217 | #define RSME 0x4000 /* b14: Resume interrupt */ | ||
218 | #define SOFE 0x2000 /* b13: Frame update interrupt */ | ||
219 | #define DVSE 0x1000 /* b12: Device state transition interrupt */ | ||
220 | #define CTRE 0x0800 /* b11: Control transfer stage transition interrupt */ | ||
221 | #define BEMPE 0x0400 /* b10: Buffer empty interrupt */ | ||
222 | #define NRDYE 0x0200 /* b9: Buffer not ready interrupt */ | ||
223 | #define BRDYE 0x0100 /* b8: Buffer ready interrupt */ | ||
224 | |||
225 | /* Interrupt Enable Register 1 */ | ||
226 | #define OVRCRE 0x8000 /* b15: Over-current interrupt */ | ||
227 | #define BCHGE 0x4000 /* b14: USB us chenge interrupt */ | ||
228 | #define DTCHE 0x1000 /* b12: Detach sense interrupt */ | ||
229 | #define ATTCHE 0x0800 /* b11: Attach sense interrupt */ | ||
230 | #define EOFERRE 0x0040 /* b6: EOF error interrupt */ | ||
231 | #define SIGNE 0x0020 /* b5: SETUP IGNORE interrupt */ | ||
232 | #define SACKE 0x0010 /* b4: SETUP ACK interrupt */ | ||
233 | |||
234 | /* BRDY Interrupt Enable/Status Register */ | ||
235 | #define BRDY9 0x0200 /* b9: PIPE9 */ | ||
236 | #define BRDY8 0x0100 /* b8: PIPE8 */ | ||
237 | #define BRDY7 0x0080 /* b7: PIPE7 */ | ||
238 | #define BRDY6 0x0040 /* b6: PIPE6 */ | ||
239 | #define BRDY5 0x0020 /* b5: PIPE5 */ | ||
240 | #define BRDY4 0x0010 /* b4: PIPE4 */ | ||
241 | #define BRDY3 0x0008 /* b3: PIPE3 */ | ||
242 | #define BRDY2 0x0004 /* b2: PIPE2 */ | ||
243 | #define BRDY1 0x0002 /* b1: PIPE1 */ | ||
244 | #define BRDY0 0x0001 /* b1: PIPE0 */ | ||
245 | |||
246 | /* NRDY Interrupt Enable/Status Register */ | ||
247 | #define NRDY9 0x0200 /* b9: PIPE9 */ | ||
248 | #define NRDY8 0x0100 /* b8: PIPE8 */ | ||
249 | #define NRDY7 0x0080 /* b7: PIPE7 */ | ||
250 | #define NRDY6 0x0040 /* b6: PIPE6 */ | ||
251 | #define NRDY5 0x0020 /* b5: PIPE5 */ | ||
252 | #define NRDY4 0x0010 /* b4: PIPE4 */ | ||
253 | #define NRDY3 0x0008 /* b3: PIPE3 */ | ||
254 | #define NRDY2 0x0004 /* b2: PIPE2 */ | ||
255 | #define NRDY1 0x0002 /* b1: PIPE1 */ | ||
256 | #define NRDY0 0x0001 /* b1: PIPE0 */ | ||
257 | |||
258 | /* BEMP Interrupt Enable/Status Register */ | ||
259 | #define BEMP9 0x0200 /* b9: PIPE9 */ | ||
260 | #define BEMP8 0x0100 /* b8: PIPE8 */ | ||
261 | #define BEMP7 0x0080 /* b7: PIPE7 */ | ||
262 | #define BEMP6 0x0040 /* b6: PIPE6 */ | ||
263 | #define BEMP5 0x0020 /* b5: PIPE5 */ | ||
264 | #define BEMP4 0x0010 /* b4: PIPE4 */ | ||
265 | #define BEMP3 0x0008 /* b3: PIPE3 */ | ||
266 | #define BEMP2 0x0004 /* b2: PIPE2 */ | ||
267 | #define BEMP1 0x0002 /* b1: PIPE1 */ | ||
268 | #define BEMP0 0x0001 /* b0: PIPE0 */ | ||
269 | |||
270 | /* SOF Pin Configuration Register */ | ||
271 | #define TRNENSEL 0x0100 /* b8: Select transaction enable period */ | ||
272 | #define BRDYM 0x0040 /* b6: BRDY clear timing */ | ||
273 | #define INTL 0x0020 /* b5: Interrupt sense select */ | ||
274 | #define EDGESTS 0x0010 /* b4: */ | ||
275 | #define SOFMODE 0x000C /* b3-2: SOF pin select */ | ||
276 | #define SOF_125US 0x0008 /* SOF OUT 125us Frame Signal */ | ||
277 | #define SOF_1MS 0x0004 /* SOF OUT 1ms Frame Signal */ | ||
278 | #define SOF_DISABLE 0x0000 /* SOF OUT Disable */ | ||
279 | |||
280 | /* Interrupt Status Register 0 */ | ||
281 | #define VBINT 0x8000 /* b15: VBUS interrupt */ | ||
282 | #define RESM 0x4000 /* b14: Resume interrupt */ | ||
283 | #define SOFR 0x2000 /* b13: SOF frame update interrupt */ | ||
284 | #define DVST 0x1000 /* b12: Device state transition interrupt */ | ||
285 | #define CTRT 0x0800 /* b11: Control transfer stage transition interrupt */ | ||
286 | #define BEMP 0x0400 /* b10: Buffer empty interrupt */ | ||
287 | #define NRDY 0x0200 /* b9: Buffer not ready interrupt */ | ||
288 | #define BRDY 0x0100 /* b8: Buffer ready interrupt */ | ||
289 | #define VBSTS 0x0080 /* b7: VBUS input port */ | ||
290 | #define DVSQ 0x0070 /* b6-4: Device state */ | ||
291 | #define DS_SPD_CNFG 0x0070 /* Suspend Configured */ | ||
292 | #define DS_SPD_ADDR 0x0060 /* Suspend Address */ | ||
293 | #define DS_SPD_DFLT 0x0050 /* Suspend Default */ | ||
294 | #define DS_SPD_POWR 0x0040 /* Suspend Powered */ | ||
295 | #define DS_SUSP 0x0040 /* Suspend */ | ||
296 | #define DS_CNFG 0x0030 /* Configured */ | ||
297 | #define DS_ADDS 0x0020 /* Address */ | ||
298 | #define DS_DFLT 0x0010 /* Default */ | ||
299 | #define DS_POWR 0x0000 /* Powered */ | ||
300 | #define DVSQS 0x0030 /* b5-4: Device state */ | ||
301 | #define VALID 0x0008 /* b3: Setup packet detected flag */ | ||
302 | #define CTSQ 0x0007 /* b2-0: Control transfer stage */ | ||
303 | #define CS_SQER 0x0006 /* Sequence error */ | ||
304 | #define CS_WRND 0x0005 /* Control write nodata status stage */ | ||
305 | #define CS_WRSS 0x0004 /* Control write status stage */ | ||
306 | #define CS_WRDS 0x0003 /* Control write data stage */ | ||
307 | #define CS_RDSS 0x0002 /* Control read status stage */ | ||
308 | #define CS_RDDS 0x0001 /* Control read data stage */ | ||
309 | #define CS_IDST 0x0000 /* Idle or setup stage */ | ||
310 | |||
311 | /* Interrupt Status Register 1 */ | ||
312 | #define OVRCR 0x8000 /* b15: Over-current interrupt */ | ||
313 | #define BCHG 0x4000 /* b14: USB bus chenge interrupt */ | ||
314 | #define DTCH 0x1000 /* b12: Detach sense interrupt */ | ||
315 | #define ATTCH 0x0800 /* b11: Attach sense interrupt */ | ||
316 | #define EOFERR 0x0040 /* b6: EOF-error interrupt */ | ||
317 | #define SIGN 0x0020 /* b5: Setup ignore interrupt */ | ||
318 | #define SACK 0x0010 /* b4: Setup acknowledge interrupt */ | ||
319 | |||
320 | /* Frame Number Register */ | ||
321 | #define OVRN 0x8000 /* b15: Overrun error */ | ||
322 | #define CRCE 0x4000 /* b14: Received data error */ | ||
323 | #define FRNM 0x07FF /* b10-0: Frame number */ | ||
324 | |||
325 | /* Micro Frame Number Register */ | ||
326 | #define UFRNM 0x0007 /* b2-0: Micro frame number */ | ||
327 | |||
328 | /* Default Control Pipe Maxpacket Size Register */ | ||
329 | /* Pipe Maxpacket Size Register */ | ||
330 | #define DEVSEL 0xF000 /* b15-14: Device address select */ | ||
331 | #define MAXP 0x007F /* b6-0: Maxpacket size of default control pipe */ | ||
332 | |||
333 | /* Default Control Pipe Control Register */ | ||
334 | #define BSTS 0x8000 /* b15: Buffer status */ | ||
335 | #define SUREQ 0x4000 /* b14: Send USB request */ | ||
336 | #define CSCLR 0x2000 /* b13: complete-split status clear */ | ||
337 | #define CSSTS 0x1000 /* b12: complete-split status */ | ||
338 | #define SUREQCLR 0x0800 /* b11: stop setup request */ | ||
339 | #define SQCLR 0x0100 /* b8: Sequence toggle bit clear */ | ||
340 | #define SQSET 0x0080 /* b7: Sequence toggle bit set */ | ||
341 | #define SQMON 0x0040 /* b6: Sequence toggle bit monitor */ | ||
342 | #define PBUSY 0x0020 /* b5: pipe busy */ | ||
343 | #define PINGE 0x0010 /* b4: ping enable */ | ||
344 | #define CCPL 0x0004 /* b2: Enable control transfer complete */ | ||
345 | #define PID 0x0003 /* b1-0: Response PID */ | ||
346 | #define PID_STALL11 0x0003 /* STALL */ | ||
347 | #define PID_STALL 0x0002 /* STALL */ | ||
348 | #define PID_BUF 0x0001 /* BUF */ | ||
349 | #define PID_NAK 0x0000 /* NAK */ | ||
350 | |||
351 | /* Pipe Window Select Register */ | ||
352 | #define PIPENM 0x0007 /* b2-0: Pipe select */ | ||
353 | |||
354 | /* Pipe Configuration Register */ | ||
355 | #define R8A66597_TYP 0xC000 /* b15-14: Transfer type */ | ||
356 | #define R8A66597_ISO 0xC000 /* Isochronous */ | ||
357 | #define R8A66597_INT 0x8000 /* Interrupt */ | ||
358 | #define R8A66597_BULK 0x4000 /* Bulk */ | ||
359 | #define R8A66597_BFRE 0x0400 /* b10: Buffer ready interrupt mode select */ | ||
360 | #define R8A66597_DBLB 0x0200 /* b9: Double buffer mode select */ | ||
361 | #define R8A66597_CNTMD 0x0100 /* b8: Continuous transfer mode select */ | ||
362 | #define R8A66597_SHTNAK 0x0080 /* b7: Transfer end NAK */ | ||
363 | #define R8A66597_DIR 0x0010 /* b4: Transfer direction select */ | ||
364 | #define R8A66597_EPNUM 0x000F /* b3-0: Eendpoint number select */ | ||
365 | |||
366 | /* Pipe Buffer Configuration Register */ | ||
367 | #define BUFSIZE 0x7C00 /* b14-10: Pipe buffer size */ | ||
368 | #define BUFNMB 0x007F /* b6-0: Pipe buffer number */ | ||
369 | #define PIPE0BUF 256 | ||
370 | #define PIPExBUF 64 | ||
371 | |||
372 | /* Pipe Maxpacket Size Register */ | ||
373 | #define MXPS 0x07FF /* b10-0: Maxpacket size */ | ||
374 | |||
375 | /* Pipe Cycle Configuration Register */ | ||
376 | #define IFIS 0x1000 /* b12: Isochronous in-buffer flush mode select */ | ||
377 | #define IITV 0x0007 /* b2-0: Isochronous interval */ | ||
378 | |||
379 | /* Pipex Control Register */ | ||
380 | #define BSTS 0x8000 /* b15: Buffer status */ | ||
381 | #define INBUFM 0x4000 /* b14: IN buffer monitor (Only for PIPE1 to 5) */ | ||
382 | #define CSCLR 0x2000 /* b13: complete-split status clear */ | ||
383 | #define CSSTS 0x1000 /* b12: complete-split status */ | ||
384 | #define ATREPM 0x0400 /* b10: Auto repeat mode */ | ||
385 | #define ACLRM 0x0200 /* b9: Out buffer auto clear mode */ | ||
386 | #define SQCLR 0x0100 /* b8: Sequence toggle bit clear */ | ||
387 | #define SQSET 0x0080 /* b7: Sequence toggle bit set */ | ||
388 | #define SQMON 0x0040 /* b6: Sequence toggle bit monitor */ | ||
389 | #define PBUSY 0x0020 /* b5: pipe busy */ | ||
390 | #define PID 0x0003 /* b1-0: Response PID */ | ||
391 | |||
392 | /* PIPExTRE */ | ||
393 | #define TRENB 0x0200 /* b9: Transaction counter enable */ | ||
394 | #define TRCLR 0x0100 /* b8: Transaction counter clear */ | ||
395 | |||
396 | /* PIPExTRN */ | ||
397 | #define TRNCNT 0xFFFF /* b15-0: Transaction counter */ | ||
398 | |||
399 | /* DEVADDx */ | ||
400 | #define UPPHUB 0x7800 | ||
401 | #define HUBPORT 0x0700 | ||
402 | #define USBSPD 0x00C0 | ||
403 | #define RTPORT 0x0001 | ||
404 | |||
405 | #define R8A66597_MAX_NUM_PIPE 10 | 35 | #define R8A66597_MAX_NUM_PIPE 10 |
406 | #define R8A66597_BUF_BSIZE 8 | 36 | #define R8A66597_BUF_BSIZE 8 |
407 | #define R8A66597_MAX_DEVICE 10 | 37 | #define R8A66597_MAX_DEVICE 10 |
408 | #if defined(CONFIG_SUPERH_ON_CHIP_R8A66597) | ||
409 | #define R8A66597_MAX_ROOT_HUB 1 | ||
410 | #else | ||
411 | #define R8A66597_MAX_ROOT_HUB 2 | 38 | #define R8A66597_MAX_ROOT_HUB 2 |
412 | #endif | ||
413 | #define R8A66597_MAX_SAMPLING 5 | 39 | #define R8A66597_MAX_SAMPLING 5 |
414 | #define R8A66597_RH_POLL_TIME 10 | 40 | #define R8A66597_RH_POLL_TIME 10 |
415 | #define R8A66597_MAX_DMA_CHANNEL 2 | 41 | #define R8A66597_MAX_DMA_CHANNEL 2 |
@@ -487,7 +113,7 @@ struct r8a66597_root_hub { | |||
487 | struct r8a66597 { | 113 | struct r8a66597 { |
488 | spinlock_t lock; | 114 | spinlock_t lock; |
489 | unsigned long reg; | 115 | unsigned long reg; |
490 | #if defined(CONFIG_SUPERH_ON_CHIP_R8A66597) && defined(CONFIG_HAVE_CLK) | 116 | #ifdef CONFIG_HAVE_CLK |
491 | struct clk *clk; | 117 | struct clk *clk; |
492 | #endif | 118 | #endif |
493 | struct r8a66597_platdata *pdata; | 119 | struct r8a66597_platdata *pdata; |
@@ -504,6 +130,7 @@ struct r8a66597 { | |||
504 | unsigned short interval_map; | 130 | unsigned short interval_map; |
505 | unsigned char pipe_cnt[R8A66597_MAX_NUM_PIPE]; | 131 | unsigned char pipe_cnt[R8A66597_MAX_NUM_PIPE]; |
506 | unsigned char dma_map; | 132 | unsigned char dma_map; |
133 | unsigned int max_root_hub; | ||
507 | 134 | ||
508 | struct list_head child_device; | 135 | struct list_head child_device; |
509 | unsigned long child_connect_map[4]; | 136 | unsigned long child_connect_map[4]; |
@@ -550,21 +177,22 @@ static inline void r8a66597_read_fifo(struct r8a66597 *r8a66597, | |||
550 | unsigned long offset, u16 *buf, | 177 | unsigned long offset, u16 *buf, |
551 | int len) | 178 | int len) |
552 | { | 179 | { |
553 | #if defined(CONFIG_SUPERH_ON_CHIP_R8A66597) | ||
554 | unsigned long fifoaddr = r8a66597->reg + offset; | 180 | unsigned long fifoaddr = r8a66597->reg + offset; |
555 | unsigned long count; | 181 | unsigned long count; |
556 | 182 | ||
557 | count = len / 4; | 183 | if (r8a66597->pdata->on_chip) { |
558 | insl(fifoaddr, buf, count); | 184 | count = len / 4; |
185 | insl(fifoaddr, buf, count); | ||
559 | 186 | ||
560 | if (len & 0x00000003) { | 187 | if (len & 0x00000003) { |
561 | unsigned long tmp = inl(fifoaddr); | 188 | unsigned long tmp = inl(fifoaddr); |
562 | memcpy((unsigned char *)buf + count * 4, &tmp, len & 0x03); | 189 | memcpy((unsigned char *)buf + count * 4, &tmp, |
190 | len & 0x03); | ||
191 | } | ||
192 | } else { | ||
193 | len = (len + 1) / 2; | ||
194 | insw(fifoaddr, buf, len); | ||
563 | } | 195 | } |
564 | #else | ||
565 | len = (len + 1) / 2; | ||
566 | insw(r8a66597->reg + offset, buf, len); | ||
567 | #endif | ||
568 | } | 196 | } |
569 | 197 | ||
570 | static inline void r8a66597_write(struct r8a66597 *r8a66597, u16 val, | 198 | static inline void r8a66597_write(struct r8a66597 *r8a66597, u16 val, |
@@ -578,33 +206,33 @@ static inline void r8a66597_write_fifo(struct r8a66597 *r8a66597, | |||
578 | int len) | 206 | int len) |
579 | { | 207 | { |
580 | unsigned long fifoaddr = r8a66597->reg + offset; | 208 | unsigned long fifoaddr = r8a66597->reg + offset; |
581 | #if defined(CONFIG_SUPERH_ON_CHIP_R8A66597) | ||
582 | unsigned long count; | 209 | unsigned long count; |
583 | unsigned char *pb; | 210 | unsigned char *pb; |
584 | int i; | 211 | int i; |
585 | 212 | ||
586 | count = len / 4; | 213 | if (r8a66597->pdata->on_chip) { |
587 | outsl(fifoaddr, buf, count); | 214 | count = len / 4; |
215 | outsl(fifoaddr, buf, count); | ||
216 | |||
217 | if (len & 0x00000003) { | ||
218 | pb = (unsigned char *)buf + count * 4; | ||
219 | for (i = 0; i < (len & 0x00000003); i++) { | ||
220 | if (r8a66597_read(r8a66597, CFIFOSEL) & BIGEND) | ||
221 | outb(pb[i], fifoaddr + i); | ||
222 | else | ||
223 | outb(pb[i], fifoaddr + 3 - i); | ||
224 | } | ||
225 | } | ||
226 | } else { | ||
227 | int odd = len & 0x0001; | ||
588 | 228 | ||
589 | if (len & 0x00000003) { | 229 | len = len / 2; |
590 | pb = (unsigned char *)buf + count * 4; | 230 | outsw(fifoaddr, buf, len); |
591 | for (i = 0; i < (len & 0x00000003); i++) { | 231 | if (unlikely(odd)) { |
592 | if (r8a66597_read(r8a66597, CFIFOSEL) & BIGEND) | 232 | buf = &buf[len]; |
593 | outb(pb[i], fifoaddr + i); | 233 | outb((unsigned char)*buf, fifoaddr); |
594 | else | ||
595 | outb(pb[i], fifoaddr + 3 - i); | ||
596 | } | 234 | } |
597 | } | 235 | } |
598 | #else | ||
599 | int odd = len & 0x0001; | ||
600 | |||
601 | len = len / 2; | ||
602 | outsw(fifoaddr, buf, len); | ||
603 | if (unlikely(odd)) { | ||
604 | buf = &buf[len]; | ||
605 | outb((unsigned char)*buf, fifoaddr); | ||
606 | } | ||
607 | #endif | ||
608 | } | 236 | } |
609 | 237 | ||
610 | static inline void r8a66597_mdfy(struct r8a66597 *r8a66597, | 238 | static inline void r8a66597_mdfy(struct r8a66597 *r8a66597, |
diff --git a/drivers/usb/host/sl811-hcd.c b/drivers/usb/host/sl811-hcd.c index a949259f18b9..5b22a4d1c9e4 100644 --- a/drivers/usb/host/sl811-hcd.c +++ b/drivers/usb/host/sl811-hcd.c | |||
@@ -719,8 +719,12 @@ retry: | |||
719 | /* port status seems weird until after reset, so | 719 | /* port status seems weird until after reset, so |
720 | * force the reset and make khubd clean up later. | 720 | * force the reset and make khubd clean up later. |
721 | */ | 721 | */ |
722 | sl811->port1 |= (1 << USB_PORT_FEAT_C_CONNECTION) | 722 | if (sl811->stat_insrmv & 1) |
723 | | (1 << USB_PORT_FEAT_CONNECTION); | 723 | sl811->port1 |= 1 << USB_PORT_FEAT_CONNECTION; |
724 | else | ||
725 | sl811->port1 &= ~(1 << USB_PORT_FEAT_CONNECTION); | ||
726 | |||
727 | sl811->port1 |= 1 << USB_PORT_FEAT_C_CONNECTION; | ||
724 | 728 | ||
725 | } else if (irqstat & SL11H_INTMASK_RD) { | 729 | } else if (irqstat & SL11H_INTMASK_RD) { |
726 | if (sl811->port1 & (1 << USB_PORT_FEAT_SUSPEND)) { | 730 | if (sl811->port1 & (1 << USB_PORT_FEAT_SUSPEND)) { |
diff --git a/drivers/usb/host/uhci-q.c b/drivers/usb/host/uhci-q.c index 64e57bfe236b..acd582c02802 100644 --- a/drivers/usb/host/uhci-q.c +++ b/drivers/usb/host/uhci-q.c | |||
@@ -1422,7 +1422,6 @@ static int uhci_urb_enqueue(struct usb_hcd *hcd, | |||
1422 | goto err_submit_failed; | 1422 | goto err_submit_failed; |
1423 | 1423 | ||
1424 | /* Add this URB to the QH */ | 1424 | /* Add this URB to the QH */ |
1425 | urbp->qh = qh; | ||
1426 | list_add_tail(&urbp->node, &qh->queue); | 1425 | list_add_tail(&urbp->node, &qh->queue); |
1427 | 1426 | ||
1428 | /* If the new URB is the first and only one on this QH then either | 1427 | /* If the new URB is the first and only one on this QH then either |
diff --git a/drivers/usb/host/whci/asl.c b/drivers/usb/host/whci/asl.c index c2050785a819..c632437c7649 100644 --- a/drivers/usb/host/whci/asl.c +++ b/drivers/usb/host/whci/asl.c | |||
@@ -227,11 +227,21 @@ void scan_async_work(struct work_struct *work) | |||
227 | /* | 227 | /* |
228 | * Now that the ASL is updated, complete the removal of any | 228 | * Now that the ASL is updated, complete the removal of any |
229 | * removed qsets. | 229 | * removed qsets. |
230 | * | ||
231 | * If the qset was to be reset, do so and reinsert it into the | ||
232 | * ASL if it has pending transfers. | ||
230 | */ | 233 | */ |
231 | spin_lock_irq(&whc->lock); | 234 | spin_lock_irq(&whc->lock); |
232 | 235 | ||
233 | list_for_each_entry_safe(qset, t, &whc->async_removed_list, list_node) { | 236 | list_for_each_entry_safe(qset, t, &whc->async_removed_list, list_node) { |
234 | qset_remove_complete(whc, qset); | 237 | qset_remove_complete(whc, qset); |
238 | if (qset->reset) { | ||
239 | qset_reset(whc, qset); | ||
240 | if (!list_empty(&qset->stds)) { | ||
241 | asl_qset_insert_begin(whc, qset); | ||
242 | queue_work(whc->workqueue, &whc->async_work); | ||
243 | } | ||
244 | } | ||
235 | } | 245 | } |
236 | 246 | ||
237 | spin_unlock_irq(&whc->lock); | 247 | spin_unlock_irq(&whc->lock); |
@@ -267,7 +277,7 @@ int asl_urb_enqueue(struct whc *whc, struct urb *urb, gfp_t mem_flags) | |||
267 | else | 277 | else |
268 | err = qset_add_urb(whc, qset, urb, GFP_ATOMIC); | 278 | err = qset_add_urb(whc, qset, urb, GFP_ATOMIC); |
269 | if (!err) { | 279 | if (!err) { |
270 | if (!qset->in_sw_list) | 280 | if (!qset->in_sw_list && !qset->remove) |
271 | asl_qset_insert_begin(whc, qset); | 281 | asl_qset_insert_begin(whc, qset); |
272 | } else | 282 | } else |
273 | usb_hcd_unlink_urb_from_ep(&whc->wusbhc.usb_hcd, urb); | 283 | usb_hcd_unlink_urb_from_ep(&whc->wusbhc.usb_hcd, urb); |
diff --git a/drivers/usb/host/whci/hcd.c b/drivers/usb/host/whci/hcd.c index e019a5058ab8..687b622a1612 100644 --- a/drivers/usb/host/whci/hcd.c +++ b/drivers/usb/host/whci/hcd.c | |||
@@ -192,19 +192,23 @@ static void whc_endpoint_reset(struct usb_hcd *usb_hcd, | |||
192 | struct wusbhc *wusbhc = usb_hcd_to_wusbhc(usb_hcd); | 192 | struct wusbhc *wusbhc = usb_hcd_to_wusbhc(usb_hcd); |
193 | struct whc *whc = wusbhc_to_whc(wusbhc); | 193 | struct whc *whc = wusbhc_to_whc(wusbhc); |
194 | struct whc_qset *qset; | 194 | struct whc_qset *qset; |
195 | unsigned long flags; | ||
196 | |||
197 | spin_lock_irqsave(&whc->lock, flags); | ||
195 | 198 | ||
196 | qset = ep->hcpriv; | 199 | qset = ep->hcpriv; |
197 | if (qset) { | 200 | if (qset) { |
198 | qset->remove = 1; | 201 | qset->remove = 1; |
202 | qset->reset = 1; | ||
199 | 203 | ||
200 | if (usb_endpoint_xfer_bulk(&ep->desc) | 204 | if (usb_endpoint_xfer_bulk(&ep->desc) |
201 | || usb_endpoint_xfer_control(&ep->desc)) | 205 | || usb_endpoint_xfer_control(&ep->desc)) |
202 | queue_work(whc->workqueue, &whc->async_work); | 206 | queue_work(whc->workqueue, &whc->async_work); |
203 | else | 207 | else |
204 | queue_work(whc->workqueue, &whc->periodic_work); | 208 | queue_work(whc->workqueue, &whc->periodic_work); |
205 | |||
206 | qset_reset(whc, qset); | ||
207 | } | 209 | } |
210 | |||
211 | spin_unlock_irqrestore(&whc->lock, flags); | ||
208 | } | 212 | } |
209 | 213 | ||
210 | 214 | ||
diff --git a/drivers/usb/host/whci/pzl.c b/drivers/usb/host/whci/pzl.c index ff4ef9e910d9..a9e05bac6646 100644 --- a/drivers/usb/host/whci/pzl.c +++ b/drivers/usb/host/whci/pzl.c | |||
@@ -255,11 +255,21 @@ void scan_periodic_work(struct work_struct *work) | |||
255 | /* | 255 | /* |
256 | * Now that the PZL is updated, complete the removal of any | 256 | * Now that the PZL is updated, complete the removal of any |
257 | * removed qsets. | 257 | * removed qsets. |
258 | * | ||
259 | * If the qset was to be reset, do so and reinsert it into the | ||
260 | * PZL if it has pending transfers. | ||
258 | */ | 261 | */ |
259 | spin_lock_irq(&whc->lock); | 262 | spin_lock_irq(&whc->lock); |
260 | 263 | ||
261 | list_for_each_entry_safe(qset, t, &whc->periodic_removed_list, list_node) { | 264 | list_for_each_entry_safe(qset, t, &whc->periodic_removed_list, list_node) { |
262 | qset_remove_complete(whc, qset); | 265 | qset_remove_complete(whc, qset); |
266 | if (qset->reset) { | ||
267 | qset_reset(whc, qset); | ||
268 | if (!list_empty(&qset->stds)) { | ||
269 | qset_insert_in_sw_list(whc, qset); | ||
270 | queue_work(whc->workqueue, &whc->periodic_work); | ||
271 | } | ||
272 | } | ||
263 | } | 273 | } |
264 | 274 | ||
265 | spin_unlock_irq(&whc->lock); | 275 | spin_unlock_irq(&whc->lock); |
@@ -295,7 +305,7 @@ int pzl_urb_enqueue(struct whc *whc, struct urb *urb, gfp_t mem_flags) | |||
295 | else | 305 | else |
296 | err = qset_add_urb(whc, qset, urb, GFP_ATOMIC); | 306 | err = qset_add_urb(whc, qset, urb, GFP_ATOMIC); |
297 | if (!err) { | 307 | if (!err) { |
298 | if (!qset->in_sw_list) | 308 | if (!qset->in_sw_list && !qset->remove) |
299 | qset_insert_in_sw_list(whc, qset); | 309 | qset_insert_in_sw_list(whc, qset); |
300 | } else | 310 | } else |
301 | usb_hcd_unlink_urb_from_ep(&whc->wusbhc.usb_hcd, urb); | 311 | usb_hcd_unlink_urb_from_ep(&whc->wusbhc.usb_hcd, urb); |
diff --git a/drivers/usb/host/whci/qset.c b/drivers/usb/host/whci/qset.c index 640b38fbd051..1b9dc1571570 100644 --- a/drivers/usb/host/whci/qset.c +++ b/drivers/usb/host/whci/qset.c | |||
@@ -103,7 +103,6 @@ static void qset_fill_qh(struct whc_qset *qset, struct urb *urb) | |||
103 | void qset_clear(struct whc *whc, struct whc_qset *qset) | 103 | void qset_clear(struct whc *whc, struct whc_qset *qset) |
104 | { | 104 | { |
105 | qset->td_start = qset->td_end = qset->ntds = 0; | 105 | qset->td_start = qset->td_end = qset->ntds = 0; |
106 | qset->remove = 0; | ||
107 | 106 | ||
108 | qset->qh.link = cpu_to_le32(QH_LINK_NTDS(8) | QH_LINK_T); | 107 | qset->qh.link = cpu_to_le32(QH_LINK_NTDS(8) | QH_LINK_T); |
109 | qset->qh.status = qset->qh.status & QH_STATUS_SEQ_MASK; | 108 | qset->qh.status = qset->qh.status & QH_STATUS_SEQ_MASK; |
@@ -125,7 +124,7 @@ void qset_clear(struct whc *whc, struct whc_qset *qset) | |||
125 | */ | 124 | */ |
126 | void qset_reset(struct whc *whc, struct whc_qset *qset) | 125 | void qset_reset(struct whc *whc, struct whc_qset *qset) |
127 | { | 126 | { |
128 | wait_for_completion(&qset->remove_complete); | 127 | qset->reset = 0; |
129 | 128 | ||
130 | qset->qh.status &= ~QH_STATUS_SEQ_MASK; | 129 | qset->qh.status &= ~QH_STATUS_SEQ_MASK; |
131 | qset->qh.cur_window = cpu_to_le32((1 << qset->max_burst) - 1); | 130 | qset->qh.cur_window = cpu_to_le32((1 << qset->max_burst) - 1); |
@@ -156,6 +155,7 @@ struct whc_qset *get_qset(struct whc *whc, struct urb *urb, | |||
156 | 155 | ||
157 | void qset_remove_complete(struct whc *whc, struct whc_qset *qset) | 156 | void qset_remove_complete(struct whc *whc, struct whc_qset *qset) |
158 | { | 157 | { |
158 | qset->remove = 0; | ||
159 | list_del_init(&qset->list_node); | 159 | list_del_init(&qset->list_node); |
160 | complete(&qset->remove_complete); | 160 | complete(&qset->remove_complete); |
161 | } | 161 | } |
diff --git a/drivers/usb/host/whci/whci-hc.h b/drivers/usb/host/whci/whci-hc.h index 794dba0d0f0a..e8d0001605be 100644 --- a/drivers/usb/host/whci/whci-hc.h +++ b/drivers/usb/host/whci/whci-hc.h | |||
@@ -264,6 +264,7 @@ struct whc_qset { | |||
264 | unsigned in_sw_list:1; | 264 | unsigned in_sw_list:1; |
265 | unsigned in_hw_list:1; | 265 | unsigned in_hw_list:1; |
266 | unsigned remove:1; | 266 | unsigned remove:1; |
267 | unsigned reset:1; | ||
267 | struct urb *pause_after_urb; | 268 | struct urb *pause_after_urb; |
268 | struct completion remove_complete; | 269 | struct completion remove_complete; |
269 | int max_burst; | 270 | int max_burst; |
diff --git a/drivers/usb/host/xhci-dbg.c b/drivers/usb/host/xhci-dbg.c index 705e34324156..33128d52f212 100644 --- a/drivers/usb/host/xhci-dbg.c +++ b/drivers/usb/host/xhci-dbg.c | |||
@@ -413,7 +413,8 @@ void xhci_dbg_slot_ctx(struct xhci_hcd *xhci, struct xhci_container_ctx *ctx) | |||
413 | int i; | 413 | int i; |
414 | 414 | ||
415 | struct xhci_slot_ctx *slot_ctx = xhci_get_slot_ctx(xhci, ctx); | 415 | struct xhci_slot_ctx *slot_ctx = xhci_get_slot_ctx(xhci, ctx); |
416 | dma_addr_t dma = ctx->dma + ((unsigned long)slot_ctx - (unsigned long)ctx); | 416 | dma_addr_t dma = ctx->dma + |
417 | ((unsigned long)slot_ctx - (unsigned long)ctx->bytes); | ||
417 | int csz = HCC_64BYTE_CONTEXT(xhci->hcc_params); | 418 | int csz = HCC_64BYTE_CONTEXT(xhci->hcc_params); |
418 | 419 | ||
419 | xhci_dbg(xhci, "Slot Context:\n"); | 420 | xhci_dbg(xhci, "Slot Context:\n"); |
@@ -459,7 +460,7 @@ void xhci_dbg_ep_ctx(struct xhci_hcd *xhci, | |||
459 | for (i = 0; i < last_ep_ctx; ++i) { | 460 | for (i = 0; i < last_ep_ctx; ++i) { |
460 | struct xhci_ep_ctx *ep_ctx = xhci_get_ep_ctx(xhci, ctx, i); | 461 | struct xhci_ep_ctx *ep_ctx = xhci_get_ep_ctx(xhci, ctx, i); |
461 | dma_addr_t dma = ctx->dma + | 462 | dma_addr_t dma = ctx->dma + |
462 | ((unsigned long)ep_ctx - (unsigned long)ctx); | 463 | ((unsigned long)ep_ctx - (unsigned long)ctx->bytes); |
463 | 464 | ||
464 | xhci_dbg(xhci, "Endpoint %02d Context:\n", i); | 465 | xhci_dbg(xhci, "Endpoint %02d Context:\n", i); |
465 | xhci_dbg(xhci, "@%p (virt) @%08llx (dma) %#08x - ep_info\n", | 466 | xhci_dbg(xhci, "@%p (virt) @%08llx (dma) %#08x - ep_info\n", |
diff --git a/drivers/usb/host/xhci-hcd.c b/drivers/usb/host/xhci-hcd.c index 816c39caca1c..99911e727e0b 100644 --- a/drivers/usb/host/xhci-hcd.c +++ b/drivers/usb/host/xhci-hcd.c | |||
@@ -22,12 +22,18 @@ | |||
22 | 22 | ||
23 | #include <linux/irq.h> | 23 | #include <linux/irq.h> |
24 | #include <linux/module.h> | 24 | #include <linux/module.h> |
25 | #include <linux/moduleparam.h> | ||
25 | 26 | ||
26 | #include "xhci.h" | 27 | #include "xhci.h" |
27 | 28 | ||
28 | #define DRIVER_AUTHOR "Sarah Sharp" | 29 | #define DRIVER_AUTHOR "Sarah Sharp" |
29 | #define DRIVER_DESC "'eXtensible' Host Controller (xHC) Driver" | 30 | #define DRIVER_DESC "'eXtensible' Host Controller (xHC) Driver" |
30 | 31 | ||
32 | /* Some 0.95 hardware can't handle the chain bit on a Link TRB being cleared */ | ||
33 | static int link_quirk; | ||
34 | module_param(link_quirk, int, S_IRUGO | S_IWUSR); | ||
35 | MODULE_PARM_DESC(link_quirk, "Don't clear the chain bit on a link TRB"); | ||
36 | |||
31 | /* TODO: copied from ehci-hcd.c - can this be refactored? */ | 37 | /* TODO: copied from ehci-hcd.c - can this be refactored? */ |
32 | /* | 38 | /* |
33 | * handshake - spin reading hc until handshake completes or fails | 39 | * handshake - spin reading hc until handshake completes or fails |
@@ -214,6 +220,12 @@ int xhci_init(struct usb_hcd *hcd) | |||
214 | 220 | ||
215 | xhci_dbg(xhci, "xhci_init\n"); | 221 | xhci_dbg(xhci, "xhci_init\n"); |
216 | spin_lock_init(&xhci->lock); | 222 | spin_lock_init(&xhci->lock); |
223 | if (link_quirk) { | ||
224 | xhci_dbg(xhci, "QUIRK: Not clearing Link TRB chain bits.\n"); | ||
225 | xhci->quirks |= XHCI_LINK_TRB_QUIRK; | ||
226 | } else { | ||
227 | xhci_dbg(xhci, "xHCI doesn't need link TRB QUIRK\n"); | ||
228 | } | ||
217 | retval = xhci_mem_init(xhci, GFP_KERNEL); | 229 | retval = xhci_mem_init(xhci, GFP_KERNEL); |
218 | xhci_dbg(xhci, "Finished xhci_init\n"); | 230 | xhci_dbg(xhci, "Finished xhci_init\n"); |
219 | 231 | ||
@@ -339,13 +351,14 @@ void xhci_event_ring_work(unsigned long arg) | |||
339 | xhci_dbg_ring_ptrs(xhci, xhci->cmd_ring); | 351 | xhci_dbg_ring_ptrs(xhci, xhci->cmd_ring); |
340 | xhci_dbg_cmd_ptrs(xhci); | 352 | xhci_dbg_cmd_ptrs(xhci); |
341 | for (i = 0; i < MAX_HC_SLOTS; ++i) { | 353 | for (i = 0; i < MAX_HC_SLOTS; ++i) { |
342 | if (xhci->devs[i]) { | 354 | if (!xhci->devs[i]) |
343 | for (j = 0; j < 31; ++j) { | 355 | continue; |
344 | if (xhci->devs[i]->ep_rings[j]) { | 356 | for (j = 0; j < 31; ++j) { |
345 | xhci_dbg(xhci, "Dev %d endpoint ring %d:\n", i, j); | 357 | struct xhci_ring *ring = xhci->devs[i]->eps[j].ring; |
346 | xhci_debug_segment(xhci, xhci->devs[i]->ep_rings[j]->deq_seg); | 358 | if (!ring) |
347 | } | 359 | continue; |
348 | } | 360 | xhci_dbg(xhci, "Dev %d endpoint ring %d:\n", i, j); |
361 | xhci_debug_segment(xhci, ring->deq_seg); | ||
349 | } | 362 | } |
350 | } | 363 | } |
351 | 364 | ||
@@ -555,13 +568,22 @@ unsigned int xhci_get_endpoint_flag(struct usb_endpoint_descriptor *desc) | |||
555 | return 1 << (xhci_get_endpoint_index(desc) + 1); | 568 | return 1 << (xhci_get_endpoint_index(desc) + 1); |
556 | } | 569 | } |
557 | 570 | ||
571 | /* Find the flag for this endpoint (for use in the control context). Use the | ||
572 | * endpoint index to create a bitmask. The slot context is bit 0, endpoint 0 is | ||
573 | * bit 1, etc. | ||
574 | */ | ||
575 | unsigned int xhci_get_endpoint_flag_from_index(unsigned int ep_index) | ||
576 | { | ||
577 | return 1 << (ep_index + 1); | ||
578 | } | ||
579 | |||
558 | /* Compute the last valid endpoint context index. Basically, this is the | 580 | /* Compute the last valid endpoint context index. Basically, this is the |
559 | * endpoint index plus one. For slot contexts with more than valid endpoint, | 581 | * endpoint index plus one. For slot contexts with more than valid endpoint, |
560 | * we find the most significant bit set in the added contexts flags. | 582 | * we find the most significant bit set in the added contexts flags. |
561 | * e.g. ep 1 IN (with epnum 0x81) => added_ctxs = 0b1000 | 583 | * e.g. ep 1 IN (with epnum 0x81) => added_ctxs = 0b1000 |
562 | * fls(0b1000) = 4, but the endpoint context index is 3, so subtract one. | 584 | * fls(0b1000) = 4, but the endpoint context index is 3, so subtract one. |
563 | */ | 585 | */ |
564 | static inline unsigned int xhci_last_valid_endpoint(u32 added_ctxs) | 586 | unsigned int xhci_last_valid_endpoint(u32 added_ctxs) |
565 | { | 587 | { |
566 | return fls(added_ctxs) - 1; | 588 | return fls(added_ctxs) - 1; |
567 | } | 589 | } |
@@ -589,6 +611,71 @@ int xhci_check_args(struct usb_hcd *hcd, struct usb_device *udev, | |||
589 | return 1; | 611 | return 1; |
590 | } | 612 | } |
591 | 613 | ||
614 | static int xhci_configure_endpoint(struct xhci_hcd *xhci, | ||
615 | struct usb_device *udev, struct xhci_command *command, | ||
616 | bool ctx_change, bool must_succeed); | ||
617 | |||
618 | /* | ||
619 | * Full speed devices may have a max packet size greater than 8 bytes, but the | ||
620 | * USB core doesn't know that until it reads the first 8 bytes of the | ||
621 | * descriptor. If the usb_device's max packet size changes after that point, | ||
622 | * we need to issue an evaluate context command and wait on it. | ||
623 | */ | ||
624 | static int xhci_check_maxpacket(struct xhci_hcd *xhci, unsigned int slot_id, | ||
625 | unsigned int ep_index, struct urb *urb) | ||
626 | { | ||
627 | struct xhci_container_ctx *in_ctx; | ||
628 | struct xhci_container_ctx *out_ctx; | ||
629 | struct xhci_input_control_ctx *ctrl_ctx; | ||
630 | struct xhci_ep_ctx *ep_ctx; | ||
631 | int max_packet_size; | ||
632 | int hw_max_packet_size; | ||
633 | int ret = 0; | ||
634 | |||
635 | out_ctx = xhci->devs[slot_id]->out_ctx; | ||
636 | ep_ctx = xhci_get_ep_ctx(xhci, out_ctx, ep_index); | ||
637 | hw_max_packet_size = MAX_PACKET_DECODED(ep_ctx->ep_info2); | ||
638 | max_packet_size = urb->dev->ep0.desc.wMaxPacketSize; | ||
639 | if (hw_max_packet_size != max_packet_size) { | ||
640 | xhci_dbg(xhci, "Max Packet Size for ep 0 changed.\n"); | ||
641 | xhci_dbg(xhci, "Max packet size in usb_device = %d\n", | ||
642 | max_packet_size); | ||
643 | xhci_dbg(xhci, "Max packet size in xHCI HW = %d\n", | ||
644 | hw_max_packet_size); | ||
645 | xhci_dbg(xhci, "Issuing evaluate context command.\n"); | ||
646 | |||
647 | /* Set up the modified control endpoint 0 */ | ||
648 | xhci_endpoint_copy(xhci, xhci->devs[slot_id]->in_ctx, | ||
649 | xhci->devs[slot_id]->out_ctx, ep_index); | ||
650 | in_ctx = xhci->devs[slot_id]->in_ctx; | ||
651 | ep_ctx = xhci_get_ep_ctx(xhci, in_ctx, ep_index); | ||
652 | ep_ctx->ep_info2 &= ~MAX_PACKET_MASK; | ||
653 | ep_ctx->ep_info2 |= MAX_PACKET(max_packet_size); | ||
654 | |||
655 | /* Set up the input context flags for the command */ | ||
656 | /* FIXME: This won't work if a non-default control endpoint | ||
657 | * changes max packet sizes. | ||
658 | */ | ||
659 | ctrl_ctx = xhci_get_input_control_ctx(xhci, in_ctx); | ||
660 | ctrl_ctx->add_flags = EP0_FLAG; | ||
661 | ctrl_ctx->drop_flags = 0; | ||
662 | |||
663 | xhci_dbg(xhci, "Slot %d input context\n", slot_id); | ||
664 | xhci_dbg_ctx(xhci, in_ctx, ep_index); | ||
665 | xhci_dbg(xhci, "Slot %d output context\n", slot_id); | ||
666 | xhci_dbg_ctx(xhci, out_ctx, ep_index); | ||
667 | |||
668 | ret = xhci_configure_endpoint(xhci, urb->dev, NULL, | ||
669 | true, false); | ||
670 | |||
671 | /* Clean up the input context for later use by bandwidth | ||
672 | * functions. | ||
673 | */ | ||
674 | ctrl_ctx->add_flags = SLOT_FLAG; | ||
675 | } | ||
676 | return ret; | ||
677 | } | ||
678 | |||
592 | /* | 679 | /* |
593 | * non-error returns are a promise to giveback() the urb later | 680 | * non-error returns are a promise to giveback() the urb later |
594 | * we drop ownership so next owner (or urb unlink) can get it | 681 | * we drop ownership so next owner (or urb unlink) can get it |
@@ -600,13 +687,13 @@ int xhci_urb_enqueue(struct usb_hcd *hcd, struct urb *urb, gfp_t mem_flags) | |||
600 | int ret = 0; | 687 | int ret = 0; |
601 | unsigned int slot_id, ep_index; | 688 | unsigned int slot_id, ep_index; |
602 | 689 | ||
690 | |||
603 | if (!urb || xhci_check_args(hcd, urb->dev, urb->ep, true, __func__) <= 0) | 691 | if (!urb || xhci_check_args(hcd, urb->dev, urb->ep, true, __func__) <= 0) |
604 | return -EINVAL; | 692 | return -EINVAL; |
605 | 693 | ||
606 | slot_id = urb->dev->slot_id; | 694 | slot_id = urb->dev->slot_id; |
607 | ep_index = xhci_get_endpoint_index(&urb->ep->desc); | 695 | ep_index = xhci_get_endpoint_index(&urb->ep->desc); |
608 | 696 | ||
609 | spin_lock_irqsave(&xhci->lock, flags); | ||
610 | if (!xhci->devs || !xhci->devs[slot_id]) { | 697 | if (!xhci->devs || !xhci->devs[slot_id]) { |
611 | if (!in_interrupt()) | 698 | if (!in_interrupt()) |
612 | dev_warn(&urb->dev->dev, "WARN: urb submitted for dev with no Slot ID\n"); | 699 | dev_warn(&urb->dev->dev, "WARN: urb submitted for dev with no Slot ID\n"); |
@@ -619,19 +706,38 @@ int xhci_urb_enqueue(struct usb_hcd *hcd, struct urb *urb, gfp_t mem_flags) | |||
619 | ret = -ESHUTDOWN; | 706 | ret = -ESHUTDOWN; |
620 | goto exit; | 707 | goto exit; |
621 | } | 708 | } |
622 | if (usb_endpoint_xfer_control(&urb->ep->desc)) | 709 | if (usb_endpoint_xfer_control(&urb->ep->desc)) { |
710 | /* Check to see if the max packet size for the default control | ||
711 | * endpoint changed during FS device enumeration | ||
712 | */ | ||
713 | if (urb->dev->speed == USB_SPEED_FULL) { | ||
714 | ret = xhci_check_maxpacket(xhci, slot_id, | ||
715 | ep_index, urb); | ||
716 | if (ret < 0) | ||
717 | return ret; | ||
718 | } | ||
719 | |||
623 | /* We have a spinlock and interrupts disabled, so we must pass | 720 | /* We have a spinlock and interrupts disabled, so we must pass |
624 | * atomic context to this function, which may allocate memory. | 721 | * atomic context to this function, which may allocate memory. |
625 | */ | 722 | */ |
723 | spin_lock_irqsave(&xhci->lock, flags); | ||
626 | ret = xhci_queue_ctrl_tx(xhci, GFP_ATOMIC, urb, | 724 | ret = xhci_queue_ctrl_tx(xhci, GFP_ATOMIC, urb, |
627 | slot_id, ep_index); | 725 | slot_id, ep_index); |
628 | else if (usb_endpoint_xfer_bulk(&urb->ep->desc)) | 726 | spin_unlock_irqrestore(&xhci->lock, flags); |
727 | } else if (usb_endpoint_xfer_bulk(&urb->ep->desc)) { | ||
728 | spin_lock_irqsave(&xhci->lock, flags); | ||
629 | ret = xhci_queue_bulk_tx(xhci, GFP_ATOMIC, urb, | 729 | ret = xhci_queue_bulk_tx(xhci, GFP_ATOMIC, urb, |
630 | slot_id, ep_index); | 730 | slot_id, ep_index); |
631 | else | 731 | spin_unlock_irqrestore(&xhci->lock, flags); |
732 | } else if (usb_endpoint_xfer_int(&urb->ep->desc)) { | ||
733 | spin_lock_irqsave(&xhci->lock, flags); | ||
734 | ret = xhci_queue_intr_tx(xhci, GFP_ATOMIC, urb, | ||
735 | slot_id, ep_index); | ||
736 | spin_unlock_irqrestore(&xhci->lock, flags); | ||
737 | } else { | ||
632 | ret = -EINVAL; | 738 | ret = -EINVAL; |
739 | } | ||
633 | exit: | 740 | exit: |
634 | spin_unlock_irqrestore(&xhci->lock, flags); | ||
635 | return ret; | 741 | return ret; |
636 | } | 742 | } |
637 | 743 | ||
@@ -674,6 +780,7 @@ int xhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status) | |||
674 | struct xhci_td *td; | 780 | struct xhci_td *td; |
675 | unsigned int ep_index; | 781 | unsigned int ep_index; |
676 | struct xhci_ring *ep_ring; | 782 | struct xhci_ring *ep_ring; |
783 | struct xhci_virt_ep *ep; | ||
677 | 784 | ||
678 | xhci = hcd_to_xhci(hcd); | 785 | xhci = hcd_to_xhci(hcd); |
679 | spin_lock_irqsave(&xhci->lock, flags); | 786 | spin_lock_irqsave(&xhci->lock, flags); |
@@ -686,17 +793,18 @@ int xhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status) | |||
686 | xhci_dbg(xhci, "Event ring:\n"); | 793 | xhci_dbg(xhci, "Event ring:\n"); |
687 | xhci_debug_ring(xhci, xhci->event_ring); | 794 | xhci_debug_ring(xhci, xhci->event_ring); |
688 | ep_index = xhci_get_endpoint_index(&urb->ep->desc); | 795 | ep_index = xhci_get_endpoint_index(&urb->ep->desc); |
689 | ep_ring = xhci->devs[urb->dev->slot_id]->ep_rings[ep_index]; | 796 | ep = &xhci->devs[urb->dev->slot_id]->eps[ep_index]; |
797 | ep_ring = ep->ring; | ||
690 | xhci_dbg(xhci, "Endpoint ring:\n"); | 798 | xhci_dbg(xhci, "Endpoint ring:\n"); |
691 | xhci_debug_ring(xhci, ep_ring); | 799 | xhci_debug_ring(xhci, ep_ring); |
692 | td = (struct xhci_td *) urb->hcpriv; | 800 | td = (struct xhci_td *) urb->hcpriv; |
693 | 801 | ||
694 | ep_ring->cancels_pending++; | 802 | ep->cancels_pending++; |
695 | list_add_tail(&td->cancelled_td_list, &ep_ring->cancelled_td_list); | 803 | list_add_tail(&td->cancelled_td_list, &ep->cancelled_td_list); |
696 | /* Queue a stop endpoint command, but only if this is | 804 | /* Queue a stop endpoint command, but only if this is |
697 | * the first cancellation to be handled. | 805 | * the first cancellation to be handled. |
698 | */ | 806 | */ |
699 | if (ep_ring->cancels_pending == 1) { | 807 | if (ep->cancels_pending == 1) { |
700 | xhci_queue_stop_endpoint(xhci, urb->dev->slot_id, ep_index); | 808 | xhci_queue_stop_endpoint(xhci, urb->dev->slot_id, ep_index); |
701 | xhci_ring_cmd_db(xhci); | 809 | xhci_ring_cmd_db(xhci); |
702 | } | 810 | } |
@@ -930,6 +1038,141 @@ static void xhci_zero_in_ctx(struct xhci_hcd *xhci, struct xhci_virt_device *vir | |||
930 | } | 1038 | } |
931 | } | 1039 | } |
932 | 1040 | ||
1041 | static int xhci_configure_endpoint_result(struct xhci_hcd *xhci, | ||
1042 | struct usb_device *udev, int *cmd_status) | ||
1043 | { | ||
1044 | int ret; | ||
1045 | |||
1046 | switch (*cmd_status) { | ||
1047 | case COMP_ENOMEM: | ||
1048 | dev_warn(&udev->dev, "Not enough host controller resources " | ||
1049 | "for new device state.\n"); | ||
1050 | ret = -ENOMEM; | ||
1051 | /* FIXME: can we allocate more resources for the HC? */ | ||
1052 | break; | ||
1053 | case COMP_BW_ERR: | ||
1054 | dev_warn(&udev->dev, "Not enough bandwidth " | ||
1055 | "for new device state.\n"); | ||
1056 | ret = -ENOSPC; | ||
1057 | /* FIXME: can we go back to the old state? */ | ||
1058 | break; | ||
1059 | case COMP_TRB_ERR: | ||
1060 | /* the HCD set up something wrong */ | ||
1061 | dev_warn(&udev->dev, "ERROR: Endpoint drop flag = 0, " | ||
1062 | "add flag = 1, " | ||
1063 | "and endpoint is not disabled.\n"); | ||
1064 | ret = -EINVAL; | ||
1065 | break; | ||
1066 | case COMP_SUCCESS: | ||
1067 | dev_dbg(&udev->dev, "Successful Endpoint Configure command\n"); | ||
1068 | ret = 0; | ||
1069 | break; | ||
1070 | default: | ||
1071 | xhci_err(xhci, "ERROR: unexpected command completion " | ||
1072 | "code 0x%x.\n", *cmd_status); | ||
1073 | ret = -EINVAL; | ||
1074 | break; | ||
1075 | } | ||
1076 | return ret; | ||
1077 | } | ||
1078 | |||
1079 | static int xhci_evaluate_context_result(struct xhci_hcd *xhci, | ||
1080 | struct usb_device *udev, int *cmd_status) | ||
1081 | { | ||
1082 | int ret; | ||
1083 | struct xhci_virt_device *virt_dev = xhci->devs[udev->slot_id]; | ||
1084 | |||
1085 | switch (*cmd_status) { | ||
1086 | case COMP_EINVAL: | ||
1087 | dev_warn(&udev->dev, "WARN: xHCI driver setup invalid evaluate " | ||
1088 | "context command.\n"); | ||
1089 | ret = -EINVAL; | ||
1090 | break; | ||
1091 | case COMP_EBADSLT: | ||
1092 | dev_warn(&udev->dev, "WARN: slot not enabled for" | ||
1093 | "evaluate context command.\n"); | ||
1094 | case COMP_CTX_STATE: | ||
1095 | dev_warn(&udev->dev, "WARN: invalid context state for " | ||
1096 | "evaluate context command.\n"); | ||
1097 | xhci_dbg_ctx(xhci, virt_dev->out_ctx, 1); | ||
1098 | ret = -EINVAL; | ||
1099 | break; | ||
1100 | case COMP_SUCCESS: | ||
1101 | dev_dbg(&udev->dev, "Successful evaluate context command\n"); | ||
1102 | ret = 0; | ||
1103 | break; | ||
1104 | default: | ||
1105 | xhci_err(xhci, "ERROR: unexpected command completion " | ||
1106 | "code 0x%x.\n", *cmd_status); | ||
1107 | ret = -EINVAL; | ||
1108 | break; | ||
1109 | } | ||
1110 | return ret; | ||
1111 | } | ||
1112 | |||
1113 | /* Issue a configure endpoint command or evaluate context command | ||
1114 | * and wait for it to finish. | ||
1115 | */ | ||
1116 | static int xhci_configure_endpoint(struct xhci_hcd *xhci, | ||
1117 | struct usb_device *udev, | ||
1118 | struct xhci_command *command, | ||
1119 | bool ctx_change, bool must_succeed) | ||
1120 | { | ||
1121 | int ret; | ||
1122 | int timeleft; | ||
1123 | unsigned long flags; | ||
1124 | struct xhci_container_ctx *in_ctx; | ||
1125 | struct completion *cmd_completion; | ||
1126 | int *cmd_status; | ||
1127 | struct xhci_virt_device *virt_dev; | ||
1128 | |||
1129 | spin_lock_irqsave(&xhci->lock, flags); | ||
1130 | virt_dev = xhci->devs[udev->slot_id]; | ||
1131 | if (command) { | ||
1132 | in_ctx = command->in_ctx; | ||
1133 | cmd_completion = command->completion; | ||
1134 | cmd_status = &command->status; | ||
1135 | command->command_trb = xhci->cmd_ring->enqueue; | ||
1136 | list_add_tail(&command->cmd_list, &virt_dev->cmd_list); | ||
1137 | } else { | ||
1138 | in_ctx = virt_dev->in_ctx; | ||
1139 | cmd_completion = &virt_dev->cmd_completion; | ||
1140 | cmd_status = &virt_dev->cmd_status; | ||
1141 | } | ||
1142 | |||
1143 | if (!ctx_change) | ||
1144 | ret = xhci_queue_configure_endpoint(xhci, in_ctx->dma, | ||
1145 | udev->slot_id, must_succeed); | ||
1146 | else | ||
1147 | ret = xhci_queue_evaluate_context(xhci, in_ctx->dma, | ||
1148 | udev->slot_id); | ||
1149 | if (ret < 0) { | ||
1150 | spin_unlock_irqrestore(&xhci->lock, flags); | ||
1151 | xhci_dbg(xhci, "FIXME allocate a new ring segment\n"); | ||
1152 | return -ENOMEM; | ||
1153 | } | ||
1154 | xhci_ring_cmd_db(xhci); | ||
1155 | spin_unlock_irqrestore(&xhci->lock, flags); | ||
1156 | |||
1157 | /* Wait for the configure endpoint command to complete */ | ||
1158 | timeleft = wait_for_completion_interruptible_timeout( | ||
1159 | cmd_completion, | ||
1160 | USB_CTRL_SET_TIMEOUT); | ||
1161 | if (timeleft <= 0) { | ||
1162 | xhci_warn(xhci, "%s while waiting for %s command\n", | ||
1163 | timeleft == 0 ? "Timeout" : "Signal", | ||
1164 | ctx_change == 0 ? | ||
1165 | "configure endpoint" : | ||
1166 | "evaluate context"); | ||
1167 | /* FIXME cancel the configure endpoint command */ | ||
1168 | return -ETIME; | ||
1169 | } | ||
1170 | |||
1171 | if (!ctx_change) | ||
1172 | return xhci_configure_endpoint_result(xhci, udev, cmd_status); | ||
1173 | return xhci_evaluate_context_result(xhci, udev, cmd_status); | ||
1174 | } | ||
1175 | |||
933 | /* Called after one or more calls to xhci_add_endpoint() or | 1176 | /* Called after one or more calls to xhci_add_endpoint() or |
934 | * xhci_drop_endpoint(). If this call fails, the USB core is expected | 1177 | * xhci_drop_endpoint(). If this call fails, the USB core is expected |
935 | * to call xhci_reset_bandwidth(). | 1178 | * to call xhci_reset_bandwidth(). |
@@ -944,8 +1187,6 @@ int xhci_check_bandwidth(struct usb_hcd *hcd, struct usb_device *udev) | |||
944 | { | 1187 | { |
945 | int i; | 1188 | int i; |
946 | int ret = 0; | 1189 | int ret = 0; |
947 | int timeleft; | ||
948 | unsigned long flags; | ||
949 | struct xhci_hcd *xhci; | 1190 | struct xhci_hcd *xhci; |
950 | struct xhci_virt_device *virt_dev; | 1191 | struct xhci_virt_device *virt_dev; |
951 | struct xhci_input_control_ctx *ctrl_ctx; | 1192 | struct xhci_input_control_ctx *ctrl_ctx; |
@@ -975,56 +1216,8 @@ int xhci_check_bandwidth(struct usb_hcd *hcd, struct usb_device *udev) | |||
975 | xhci_dbg_ctx(xhci, virt_dev->in_ctx, | 1216 | xhci_dbg_ctx(xhci, virt_dev->in_ctx, |
976 | LAST_CTX_TO_EP_NUM(slot_ctx->dev_info)); | 1217 | LAST_CTX_TO_EP_NUM(slot_ctx->dev_info)); |
977 | 1218 | ||
978 | spin_lock_irqsave(&xhci->lock, flags); | 1219 | ret = xhci_configure_endpoint(xhci, udev, NULL, |
979 | ret = xhci_queue_configure_endpoint(xhci, virt_dev->in_ctx->dma, | 1220 | false, false); |
980 | udev->slot_id); | ||
981 | if (ret < 0) { | ||
982 | spin_unlock_irqrestore(&xhci->lock, flags); | ||
983 | xhci_dbg(xhci, "FIXME allocate a new ring segment\n"); | ||
984 | return -ENOMEM; | ||
985 | } | ||
986 | xhci_ring_cmd_db(xhci); | ||
987 | spin_unlock_irqrestore(&xhci->lock, flags); | ||
988 | |||
989 | /* Wait for the configure endpoint command to complete */ | ||
990 | timeleft = wait_for_completion_interruptible_timeout( | ||
991 | &virt_dev->cmd_completion, | ||
992 | USB_CTRL_SET_TIMEOUT); | ||
993 | if (timeleft <= 0) { | ||
994 | xhci_warn(xhci, "%s while waiting for configure endpoint command\n", | ||
995 | timeleft == 0 ? "Timeout" : "Signal"); | ||
996 | /* FIXME cancel the configure endpoint command */ | ||
997 | return -ETIME; | ||
998 | } | ||
999 | |||
1000 | switch (virt_dev->cmd_status) { | ||
1001 | case COMP_ENOMEM: | ||
1002 | dev_warn(&udev->dev, "Not enough host controller resources " | ||
1003 | "for new device state.\n"); | ||
1004 | ret = -ENOMEM; | ||
1005 | /* FIXME: can we allocate more resources for the HC? */ | ||
1006 | break; | ||
1007 | case COMP_BW_ERR: | ||
1008 | dev_warn(&udev->dev, "Not enough bandwidth " | ||
1009 | "for new device state.\n"); | ||
1010 | ret = -ENOSPC; | ||
1011 | /* FIXME: can we go back to the old state? */ | ||
1012 | break; | ||
1013 | case COMP_TRB_ERR: | ||
1014 | /* the HCD set up something wrong */ | ||
1015 | dev_warn(&udev->dev, "ERROR: Endpoint drop flag = 0, add flag = 1, " | ||
1016 | "and endpoint is not disabled.\n"); | ||
1017 | ret = -EINVAL; | ||
1018 | break; | ||
1019 | case COMP_SUCCESS: | ||
1020 | dev_dbg(&udev->dev, "Successful Endpoint Configure command\n"); | ||
1021 | break; | ||
1022 | default: | ||
1023 | xhci_err(xhci, "ERROR: unexpected command completion " | ||
1024 | "code 0x%x.\n", virt_dev->cmd_status); | ||
1025 | ret = -EINVAL; | ||
1026 | break; | ||
1027 | } | ||
1028 | if (ret) { | 1221 | if (ret) { |
1029 | /* Callee should call reset_bandwidth() */ | 1222 | /* Callee should call reset_bandwidth() */ |
1030 | return ret; | 1223 | return ret; |
@@ -1037,10 +1230,10 @@ int xhci_check_bandwidth(struct usb_hcd *hcd, struct usb_device *udev) | |||
1037 | xhci_zero_in_ctx(xhci, virt_dev); | 1230 | xhci_zero_in_ctx(xhci, virt_dev); |
1038 | /* Free any old rings */ | 1231 | /* Free any old rings */ |
1039 | for (i = 1; i < 31; ++i) { | 1232 | for (i = 1; i < 31; ++i) { |
1040 | if (virt_dev->new_ep_rings[i]) { | 1233 | if (virt_dev->eps[i].new_ring) { |
1041 | xhci_ring_free(xhci, virt_dev->ep_rings[i]); | 1234 | xhci_ring_free(xhci, virt_dev->eps[i].ring); |
1042 | virt_dev->ep_rings[i] = virt_dev->new_ep_rings[i]; | 1235 | virt_dev->eps[i].ring = virt_dev->eps[i].new_ring; |
1043 | virt_dev->new_ep_rings[i] = NULL; | 1236 | virt_dev->eps[i].new_ring = NULL; |
1044 | } | 1237 | } |
1045 | } | 1238 | } |
1046 | 1239 | ||
@@ -1067,14 +1260,93 @@ void xhci_reset_bandwidth(struct usb_hcd *hcd, struct usb_device *udev) | |||
1067 | virt_dev = xhci->devs[udev->slot_id]; | 1260 | virt_dev = xhci->devs[udev->slot_id]; |
1068 | /* Free any rings allocated for added endpoints */ | 1261 | /* Free any rings allocated for added endpoints */ |
1069 | for (i = 0; i < 31; ++i) { | 1262 | for (i = 0; i < 31; ++i) { |
1070 | if (virt_dev->new_ep_rings[i]) { | 1263 | if (virt_dev->eps[i].new_ring) { |
1071 | xhci_ring_free(xhci, virt_dev->new_ep_rings[i]); | 1264 | xhci_ring_free(xhci, virt_dev->eps[i].new_ring); |
1072 | virt_dev->new_ep_rings[i] = NULL; | 1265 | virt_dev->eps[i].new_ring = NULL; |
1073 | } | 1266 | } |
1074 | } | 1267 | } |
1075 | xhci_zero_in_ctx(xhci, virt_dev); | 1268 | xhci_zero_in_ctx(xhci, virt_dev); |
1076 | } | 1269 | } |
1077 | 1270 | ||
1271 | static void xhci_setup_input_ctx_for_config_ep(struct xhci_hcd *xhci, | ||
1272 | struct xhci_container_ctx *in_ctx, | ||
1273 | struct xhci_container_ctx *out_ctx, | ||
1274 | u32 add_flags, u32 drop_flags) | ||
1275 | { | ||
1276 | struct xhci_input_control_ctx *ctrl_ctx; | ||
1277 | ctrl_ctx = xhci_get_input_control_ctx(xhci, in_ctx); | ||
1278 | ctrl_ctx->add_flags = add_flags; | ||
1279 | ctrl_ctx->drop_flags = drop_flags; | ||
1280 | xhci_slot_copy(xhci, in_ctx, out_ctx); | ||
1281 | ctrl_ctx->add_flags |= SLOT_FLAG; | ||
1282 | |||
1283 | xhci_dbg(xhci, "Input Context:\n"); | ||
1284 | xhci_dbg_ctx(xhci, in_ctx, xhci_last_valid_endpoint(add_flags)); | ||
1285 | } | ||
1286 | |||
1287 | void xhci_setup_input_ctx_for_quirk(struct xhci_hcd *xhci, | ||
1288 | unsigned int slot_id, unsigned int ep_index, | ||
1289 | struct xhci_dequeue_state *deq_state) | ||
1290 | { | ||
1291 | struct xhci_container_ctx *in_ctx; | ||
1292 | struct xhci_ep_ctx *ep_ctx; | ||
1293 | u32 added_ctxs; | ||
1294 | dma_addr_t addr; | ||
1295 | |||
1296 | xhci_endpoint_copy(xhci, xhci->devs[slot_id]->in_ctx, | ||
1297 | xhci->devs[slot_id]->out_ctx, ep_index); | ||
1298 | in_ctx = xhci->devs[slot_id]->in_ctx; | ||
1299 | ep_ctx = xhci_get_ep_ctx(xhci, in_ctx, ep_index); | ||
1300 | addr = xhci_trb_virt_to_dma(deq_state->new_deq_seg, | ||
1301 | deq_state->new_deq_ptr); | ||
1302 | if (addr == 0) { | ||
1303 | xhci_warn(xhci, "WARN Cannot submit config ep after " | ||
1304 | "reset ep command\n"); | ||
1305 | xhci_warn(xhci, "WARN deq seg = %p, deq ptr = %p\n", | ||
1306 | deq_state->new_deq_seg, | ||
1307 | deq_state->new_deq_ptr); | ||
1308 | return; | ||
1309 | } | ||
1310 | ep_ctx->deq = addr | deq_state->new_cycle_state; | ||
1311 | |||
1312 | added_ctxs = xhci_get_endpoint_flag_from_index(ep_index); | ||
1313 | xhci_setup_input_ctx_for_config_ep(xhci, xhci->devs[slot_id]->in_ctx, | ||
1314 | xhci->devs[slot_id]->out_ctx, added_ctxs, added_ctxs); | ||
1315 | } | ||
1316 | |||
1317 | void xhci_cleanup_stalled_ring(struct xhci_hcd *xhci, | ||
1318 | struct usb_device *udev, unsigned int ep_index) | ||
1319 | { | ||
1320 | struct xhci_dequeue_state deq_state; | ||
1321 | struct xhci_virt_ep *ep; | ||
1322 | |||
1323 | xhci_dbg(xhci, "Cleaning up stalled endpoint ring\n"); | ||
1324 | ep = &xhci->devs[udev->slot_id]->eps[ep_index]; | ||
1325 | /* We need to move the HW's dequeue pointer past this TD, | ||
1326 | * or it will attempt to resend it on the next doorbell ring. | ||
1327 | */ | ||
1328 | xhci_find_new_dequeue_state(xhci, udev->slot_id, | ||
1329 | ep_index, ep->stopped_td, | ||
1330 | &deq_state); | ||
1331 | |||
1332 | /* HW with the reset endpoint quirk will use the saved dequeue state to | ||
1333 | * issue a configure endpoint command later. | ||
1334 | */ | ||
1335 | if (!(xhci->quirks & XHCI_RESET_EP_QUIRK)) { | ||
1336 | xhci_dbg(xhci, "Queueing new dequeue state\n"); | ||
1337 | xhci_queue_new_dequeue_state(xhci, udev->slot_id, | ||
1338 | ep_index, &deq_state); | ||
1339 | } else { | ||
1340 | /* Better hope no one uses the input context between now and the | ||
1341 | * reset endpoint completion! | ||
1342 | */ | ||
1343 | xhci_dbg(xhci, "Setting up input context for " | ||
1344 | "configure endpoint command\n"); | ||
1345 | xhci_setup_input_ctx_for_quirk(xhci, udev->slot_id, | ||
1346 | ep_index, &deq_state); | ||
1347 | } | ||
1348 | } | ||
1349 | |||
1078 | /* Deal with stalled endpoints. The core should have sent the control message | 1350 | /* Deal with stalled endpoints. The core should have sent the control message |
1079 | * to clear the halt condition. However, we need to make the xHCI hardware | 1351 | * to clear the halt condition. However, we need to make the xHCI hardware |
1080 | * reset its sequence number, since a device will expect a sequence number of | 1352 | * reset its sequence number, since a device will expect a sequence number of |
@@ -1089,8 +1361,7 @@ void xhci_endpoint_reset(struct usb_hcd *hcd, | |||
1089 | unsigned int ep_index; | 1361 | unsigned int ep_index; |
1090 | unsigned long flags; | 1362 | unsigned long flags; |
1091 | int ret; | 1363 | int ret; |
1092 | struct xhci_dequeue_state deq_state; | 1364 | struct xhci_virt_ep *virt_ep; |
1093 | struct xhci_ring *ep_ring; | ||
1094 | 1365 | ||
1095 | xhci = hcd_to_xhci(hcd); | 1366 | xhci = hcd_to_xhci(hcd); |
1096 | udev = (struct usb_device *) ep->hcpriv; | 1367 | udev = (struct usb_device *) ep->hcpriv; |
@@ -1100,12 +1371,16 @@ void xhci_endpoint_reset(struct usb_hcd *hcd, | |||
1100 | if (!ep->hcpriv) | 1371 | if (!ep->hcpriv) |
1101 | return; | 1372 | return; |
1102 | ep_index = xhci_get_endpoint_index(&ep->desc); | 1373 | ep_index = xhci_get_endpoint_index(&ep->desc); |
1103 | ep_ring = xhci->devs[udev->slot_id]->ep_rings[ep_index]; | 1374 | virt_ep = &xhci->devs[udev->slot_id]->eps[ep_index]; |
1104 | if (!ep_ring->stopped_td) { | 1375 | if (!virt_ep->stopped_td) { |
1105 | xhci_dbg(xhci, "Endpoint 0x%x not halted, refusing to reset.\n", | 1376 | xhci_dbg(xhci, "Endpoint 0x%x not halted, refusing to reset.\n", |
1106 | ep->desc.bEndpointAddress); | 1377 | ep->desc.bEndpointAddress); |
1107 | return; | 1378 | return; |
1108 | } | 1379 | } |
1380 | if (usb_endpoint_xfer_control(&ep->desc)) { | ||
1381 | xhci_dbg(xhci, "Control endpoint stall already handled.\n"); | ||
1382 | return; | ||
1383 | } | ||
1109 | 1384 | ||
1110 | xhci_dbg(xhci, "Queueing reset endpoint command\n"); | 1385 | xhci_dbg(xhci, "Queueing reset endpoint command\n"); |
1111 | spin_lock_irqsave(&xhci->lock, flags); | 1386 | spin_lock_irqsave(&xhci->lock, flags); |
@@ -1116,17 +1391,8 @@ void xhci_endpoint_reset(struct usb_hcd *hcd, | |||
1116 | * command. Better hope that last command worked! | 1391 | * command. Better hope that last command worked! |
1117 | */ | 1392 | */ |
1118 | if (!ret) { | 1393 | if (!ret) { |
1119 | xhci_dbg(xhci, "Cleaning up stalled endpoint ring\n"); | 1394 | xhci_cleanup_stalled_ring(xhci, udev, ep_index); |
1120 | /* We need to move the HW's dequeue pointer past this TD, | 1395 | kfree(virt_ep->stopped_td); |
1121 | * or it will attempt to resend it on the next doorbell ring. | ||
1122 | */ | ||
1123 | xhci_find_new_dequeue_state(xhci, udev->slot_id, | ||
1124 | ep_index, ep_ring->stopped_td, &deq_state); | ||
1125 | xhci_dbg(xhci, "Queueing new dequeue state\n"); | ||
1126 | xhci_queue_new_dequeue_state(xhci, ep_ring, | ||
1127 | udev->slot_id, | ||
1128 | ep_index, &deq_state); | ||
1129 | kfree(ep_ring->stopped_td); | ||
1130 | xhci_ring_cmd_db(xhci); | 1396 | xhci_ring_cmd_db(xhci); |
1131 | } | 1397 | } |
1132 | spin_unlock_irqrestore(&xhci->lock, flags); | 1398 | spin_unlock_irqrestore(&xhci->lock, flags); |
@@ -1328,6 +1594,88 @@ int xhci_address_device(struct usb_hcd *hcd, struct usb_device *udev) | |||
1328 | return 0; | 1594 | return 0; |
1329 | } | 1595 | } |
1330 | 1596 | ||
1597 | /* Once a hub descriptor is fetched for a device, we need to update the xHC's | ||
1598 | * internal data structures for the device. | ||
1599 | */ | ||
1600 | int xhci_update_hub_device(struct usb_hcd *hcd, struct usb_device *hdev, | ||
1601 | struct usb_tt *tt, gfp_t mem_flags) | ||
1602 | { | ||
1603 | struct xhci_hcd *xhci = hcd_to_xhci(hcd); | ||
1604 | struct xhci_virt_device *vdev; | ||
1605 | struct xhci_command *config_cmd; | ||
1606 | struct xhci_input_control_ctx *ctrl_ctx; | ||
1607 | struct xhci_slot_ctx *slot_ctx; | ||
1608 | unsigned long flags; | ||
1609 | unsigned think_time; | ||
1610 | int ret; | ||
1611 | |||
1612 | /* Ignore root hubs */ | ||
1613 | if (!hdev->parent) | ||
1614 | return 0; | ||
1615 | |||
1616 | vdev = xhci->devs[hdev->slot_id]; | ||
1617 | if (!vdev) { | ||
1618 | xhci_warn(xhci, "Cannot update hub desc for unknown device.\n"); | ||
1619 | return -EINVAL; | ||
1620 | } | ||
1621 | config_cmd = xhci_alloc_command(xhci, true, mem_flags); | ||
1622 | if (!config_cmd) { | ||
1623 | xhci_dbg(xhci, "Could not allocate xHCI command structure.\n"); | ||
1624 | return -ENOMEM; | ||
1625 | } | ||
1626 | |||
1627 | spin_lock_irqsave(&xhci->lock, flags); | ||
1628 | xhci_slot_copy(xhci, config_cmd->in_ctx, vdev->out_ctx); | ||
1629 | ctrl_ctx = xhci_get_input_control_ctx(xhci, config_cmd->in_ctx); | ||
1630 | ctrl_ctx->add_flags |= SLOT_FLAG; | ||
1631 | slot_ctx = xhci_get_slot_ctx(xhci, config_cmd->in_ctx); | ||
1632 | slot_ctx->dev_info |= DEV_HUB; | ||
1633 | if (tt->multi) | ||
1634 | slot_ctx->dev_info |= DEV_MTT; | ||
1635 | if (xhci->hci_version > 0x95) { | ||
1636 | xhci_dbg(xhci, "xHCI version %x needs hub " | ||
1637 | "TT think time and number of ports\n", | ||
1638 | (unsigned int) xhci->hci_version); | ||
1639 | slot_ctx->dev_info2 |= XHCI_MAX_PORTS(hdev->maxchild); | ||
1640 | /* Set TT think time - convert from ns to FS bit times. | ||
1641 | * 0 = 8 FS bit times, 1 = 16 FS bit times, | ||
1642 | * 2 = 24 FS bit times, 3 = 32 FS bit times. | ||
1643 | */ | ||
1644 | think_time = tt->think_time; | ||
1645 | if (think_time != 0) | ||
1646 | think_time = (think_time / 666) - 1; | ||
1647 | slot_ctx->tt_info |= TT_THINK_TIME(think_time); | ||
1648 | } else { | ||
1649 | xhci_dbg(xhci, "xHCI version %x doesn't need hub " | ||
1650 | "TT think time or number of ports\n", | ||
1651 | (unsigned int) xhci->hci_version); | ||
1652 | } | ||
1653 | slot_ctx->dev_state = 0; | ||
1654 | spin_unlock_irqrestore(&xhci->lock, flags); | ||
1655 | |||
1656 | xhci_dbg(xhci, "Set up %s for hub device.\n", | ||
1657 | (xhci->hci_version > 0x95) ? | ||
1658 | "configure endpoint" : "evaluate context"); | ||
1659 | xhci_dbg(xhci, "Slot %u Input Context:\n", hdev->slot_id); | ||
1660 | xhci_dbg_ctx(xhci, config_cmd->in_ctx, 0); | ||
1661 | |||
1662 | /* Issue and wait for the configure endpoint or | ||
1663 | * evaluate context command. | ||
1664 | */ | ||
1665 | if (xhci->hci_version > 0x95) | ||
1666 | ret = xhci_configure_endpoint(xhci, hdev, config_cmd, | ||
1667 | false, false); | ||
1668 | else | ||
1669 | ret = xhci_configure_endpoint(xhci, hdev, config_cmd, | ||
1670 | true, false); | ||
1671 | |||
1672 | xhci_dbg(xhci, "Slot %u Output Context:\n", hdev->slot_id); | ||
1673 | xhci_dbg_ctx(xhci, vdev->out_ctx, 0); | ||
1674 | |||
1675 | xhci_free_command(xhci, config_cmd); | ||
1676 | return ret; | ||
1677 | } | ||
1678 | |||
1331 | int xhci_get_frame(struct usb_hcd *hcd) | 1679 | int xhci_get_frame(struct usb_hcd *hcd) |
1332 | { | 1680 | { |
1333 | struct xhci_hcd *xhci = hcd_to_xhci(hcd); | 1681 | struct xhci_hcd *xhci = hcd_to_xhci(hcd); |
diff --git a/drivers/usb/host/xhci-mem.c b/drivers/usb/host/xhci-mem.c index e6b9a1c6002d..1db4fea8c170 100644 --- a/drivers/usb/host/xhci-mem.c +++ b/drivers/usb/host/xhci-mem.c | |||
@@ -94,6 +94,9 @@ static void xhci_link_segments(struct xhci_hcd *xhci, struct xhci_segment *prev, | |||
94 | val = prev->trbs[TRBS_PER_SEGMENT-1].link.control; | 94 | val = prev->trbs[TRBS_PER_SEGMENT-1].link.control; |
95 | val &= ~TRB_TYPE_BITMASK; | 95 | val &= ~TRB_TYPE_BITMASK; |
96 | val |= TRB_TYPE(TRB_LINK); | 96 | val |= TRB_TYPE(TRB_LINK); |
97 | /* Always set the chain bit with 0.95 hardware */ | ||
98 | if (xhci_link_trb_quirk(xhci)) | ||
99 | val |= TRB_CHAIN; | ||
97 | prev->trbs[TRBS_PER_SEGMENT-1].link.control = val; | 100 | prev->trbs[TRBS_PER_SEGMENT-1].link.control = val; |
98 | } | 101 | } |
99 | xhci_dbg(xhci, "Linking segment 0x%llx to segment 0x%llx (DMA)\n", | 102 | xhci_dbg(xhci, "Linking segment 0x%llx to segment 0x%llx (DMA)\n", |
@@ -141,7 +144,6 @@ static struct xhci_ring *xhci_ring_alloc(struct xhci_hcd *xhci, | |||
141 | return 0; | 144 | return 0; |
142 | 145 | ||
143 | INIT_LIST_HEAD(&ring->td_list); | 146 | INIT_LIST_HEAD(&ring->td_list); |
144 | INIT_LIST_HEAD(&ring->cancelled_td_list); | ||
145 | if (num_segs == 0) | 147 | if (num_segs == 0) |
146 | return ring; | 148 | return ring; |
147 | 149 | ||
@@ -262,8 +264,8 @@ void xhci_free_virt_device(struct xhci_hcd *xhci, int slot_id) | |||
262 | return; | 264 | return; |
263 | 265 | ||
264 | for (i = 0; i < 31; ++i) | 266 | for (i = 0; i < 31; ++i) |
265 | if (dev->ep_rings[i]) | 267 | if (dev->eps[i].ring) |
266 | xhci_ring_free(xhci, dev->ep_rings[i]); | 268 | xhci_ring_free(xhci, dev->eps[i].ring); |
267 | 269 | ||
268 | if (dev->in_ctx) | 270 | if (dev->in_ctx) |
269 | xhci_free_container_ctx(xhci, dev->in_ctx); | 271 | xhci_free_container_ctx(xhci, dev->in_ctx); |
@@ -278,6 +280,7 @@ int xhci_alloc_virt_device(struct xhci_hcd *xhci, int slot_id, | |||
278 | struct usb_device *udev, gfp_t flags) | 280 | struct usb_device *udev, gfp_t flags) |
279 | { | 281 | { |
280 | struct xhci_virt_device *dev; | 282 | struct xhci_virt_device *dev; |
283 | int i; | ||
281 | 284 | ||
282 | /* Slot ID 0 is reserved */ | 285 | /* Slot ID 0 is reserved */ |
283 | if (slot_id == 0 || xhci->devs[slot_id]) { | 286 | if (slot_id == 0 || xhci->devs[slot_id]) { |
@@ -306,12 +309,17 @@ int xhci_alloc_virt_device(struct xhci_hcd *xhci, int slot_id, | |||
306 | xhci_dbg(xhci, "Slot %d input ctx = 0x%llx (dma)\n", slot_id, | 309 | xhci_dbg(xhci, "Slot %d input ctx = 0x%llx (dma)\n", slot_id, |
307 | (unsigned long long)dev->in_ctx->dma); | 310 | (unsigned long long)dev->in_ctx->dma); |
308 | 311 | ||
312 | /* Initialize the cancellation list for each endpoint */ | ||
313 | for (i = 0; i < 31; i++) | ||
314 | INIT_LIST_HEAD(&dev->eps[i].cancelled_td_list); | ||
315 | |||
309 | /* Allocate endpoint 0 ring */ | 316 | /* Allocate endpoint 0 ring */ |
310 | dev->ep_rings[0] = xhci_ring_alloc(xhci, 1, true, flags); | 317 | dev->eps[0].ring = xhci_ring_alloc(xhci, 1, true, flags); |
311 | if (!dev->ep_rings[0]) | 318 | if (!dev->eps[0].ring) |
312 | goto fail; | 319 | goto fail; |
313 | 320 | ||
314 | init_completion(&dev->cmd_completion); | 321 | init_completion(&dev->cmd_completion); |
322 | INIT_LIST_HEAD(&dev->cmd_list); | ||
315 | 323 | ||
316 | /* Point to output device context in dcbaa. */ | 324 | /* Point to output device context in dcbaa. */ |
317 | xhci->dcbaa->dev_context_ptrs[slot_id] = dev->out_ctx->dma; | 325 | xhci->dcbaa->dev_context_ptrs[slot_id] = dev->out_ctx->dma; |
@@ -352,9 +360,9 @@ int xhci_setup_addressable_virt_dev(struct xhci_hcd *xhci, struct usb_device *ud | |||
352 | /* 3) Only the control endpoint is valid - one endpoint context */ | 360 | /* 3) Only the control endpoint is valid - one endpoint context */ |
353 | slot_ctx->dev_info |= LAST_CTX(1); | 361 | slot_ctx->dev_info |= LAST_CTX(1); |
354 | 362 | ||
363 | slot_ctx->dev_info |= (u32) udev->route; | ||
355 | switch (udev->speed) { | 364 | switch (udev->speed) { |
356 | case USB_SPEED_SUPER: | 365 | case USB_SPEED_SUPER: |
357 | slot_ctx->dev_info |= (u32) udev->route; | ||
358 | slot_ctx->dev_info |= (u32) SLOT_SPEED_SS; | 366 | slot_ctx->dev_info |= (u32) SLOT_SPEED_SS; |
359 | break; | 367 | break; |
360 | case USB_SPEED_HIGH: | 368 | case USB_SPEED_HIGH: |
@@ -382,14 +390,12 @@ int xhci_setup_addressable_virt_dev(struct xhci_hcd *xhci, struct usb_device *ud | |||
382 | xhci_dbg(xhci, "Set root hub portnum to %d\n", top_dev->portnum); | 390 | xhci_dbg(xhci, "Set root hub portnum to %d\n", top_dev->portnum); |
383 | 391 | ||
384 | /* Is this a LS/FS device under a HS hub? */ | 392 | /* Is this a LS/FS device under a HS hub? */ |
385 | /* | ||
386 | * FIXME: I don't think this is right, where does the TT info for the | ||
387 | * roothub or parent hub come from? | ||
388 | */ | ||
389 | if ((udev->speed == USB_SPEED_LOW || udev->speed == USB_SPEED_FULL) && | 393 | if ((udev->speed == USB_SPEED_LOW || udev->speed == USB_SPEED_FULL) && |
390 | udev->tt) { | 394 | udev->tt) { |
391 | slot_ctx->tt_info = udev->tt->hub->slot_id; | 395 | slot_ctx->tt_info = udev->tt->hub->slot_id; |
392 | slot_ctx->tt_info |= udev->ttport << 8; | 396 | slot_ctx->tt_info |= udev->ttport << 8; |
397 | if (udev->tt->multi) | ||
398 | slot_ctx->dev_info |= DEV_MTT; | ||
393 | } | 399 | } |
394 | xhci_dbg(xhci, "udev->tt = %p\n", udev->tt); | 400 | xhci_dbg(xhci, "udev->tt = %p\n", udev->tt); |
395 | xhci_dbg(xhci, "udev->ttport = 0x%x\n", udev->ttport); | 401 | xhci_dbg(xhci, "udev->ttport = 0x%x\n", udev->ttport); |
@@ -398,22 +404,35 @@ int xhci_setup_addressable_virt_dev(struct xhci_hcd *xhci, struct usb_device *ud | |||
398 | /* Step 5 */ | 404 | /* Step 5 */ |
399 | ep0_ctx->ep_info2 = EP_TYPE(CTRL_EP); | 405 | ep0_ctx->ep_info2 = EP_TYPE(CTRL_EP); |
400 | /* | 406 | /* |
401 | * See section 4.3 bullet 6: | ||
402 | * The default Max Packet size for ep0 is "8 bytes for a USB2 | ||
403 | * LS/FS/HS device or 512 bytes for a USB3 SS device" | ||
404 | * XXX: Not sure about wireless USB devices. | 407 | * XXX: Not sure about wireless USB devices. |
405 | */ | 408 | */ |
406 | if (udev->speed == USB_SPEED_SUPER) | 409 | switch (udev->speed) { |
410 | case USB_SPEED_SUPER: | ||
407 | ep0_ctx->ep_info2 |= MAX_PACKET(512); | 411 | ep0_ctx->ep_info2 |= MAX_PACKET(512); |
408 | else | 412 | break; |
413 | case USB_SPEED_HIGH: | ||
414 | /* USB core guesses at a 64-byte max packet first for FS devices */ | ||
415 | case USB_SPEED_FULL: | ||
416 | ep0_ctx->ep_info2 |= MAX_PACKET(64); | ||
417 | break; | ||
418 | case USB_SPEED_LOW: | ||
409 | ep0_ctx->ep_info2 |= MAX_PACKET(8); | 419 | ep0_ctx->ep_info2 |= MAX_PACKET(8); |
420 | break; | ||
421 | case USB_SPEED_VARIABLE: | ||
422 | xhci_dbg(xhci, "FIXME xHCI doesn't support wireless speeds\n"); | ||
423 | return -EINVAL; | ||
424 | break; | ||
425 | default: | ||
426 | /* New speed? */ | ||
427 | BUG(); | ||
428 | } | ||
410 | /* EP 0 can handle "burst" sizes of 1, so Max Burst Size field is 0 */ | 429 | /* EP 0 can handle "burst" sizes of 1, so Max Burst Size field is 0 */ |
411 | ep0_ctx->ep_info2 |= MAX_BURST(0); | 430 | ep0_ctx->ep_info2 |= MAX_BURST(0); |
412 | ep0_ctx->ep_info2 |= ERROR_COUNT(3); | 431 | ep0_ctx->ep_info2 |= ERROR_COUNT(3); |
413 | 432 | ||
414 | ep0_ctx->deq = | 433 | ep0_ctx->deq = |
415 | dev->ep_rings[0]->first_seg->dma; | 434 | dev->eps[0].ring->first_seg->dma; |
416 | ep0_ctx->deq |= dev->ep_rings[0]->cycle_state; | 435 | ep0_ctx->deq |= dev->eps[0].ring->cycle_state; |
417 | 436 | ||
418 | /* Steps 7 and 8 were done in xhci_alloc_virt_device() */ | 437 | /* Steps 7 and 8 were done in xhci_alloc_virt_device() */ |
419 | 438 | ||
@@ -523,10 +542,11 @@ int xhci_endpoint_init(struct xhci_hcd *xhci, | |||
523 | ep_ctx = xhci_get_ep_ctx(xhci, virt_dev->in_ctx, ep_index); | 542 | ep_ctx = xhci_get_ep_ctx(xhci, virt_dev->in_ctx, ep_index); |
524 | 543 | ||
525 | /* Set up the endpoint ring */ | 544 | /* Set up the endpoint ring */ |
526 | virt_dev->new_ep_rings[ep_index] = xhci_ring_alloc(xhci, 1, true, mem_flags); | 545 | virt_dev->eps[ep_index].new_ring = |
527 | if (!virt_dev->new_ep_rings[ep_index]) | 546 | xhci_ring_alloc(xhci, 1, true, mem_flags); |
547 | if (!virt_dev->eps[ep_index].new_ring) | ||
528 | return -ENOMEM; | 548 | return -ENOMEM; |
529 | ep_ring = virt_dev->new_ep_rings[ep_index]; | 549 | ep_ring = virt_dev->eps[ep_index].new_ring; |
530 | ep_ctx->deq = ep_ring->first_seg->dma | ep_ring->cycle_state; | 550 | ep_ctx->deq = ep_ring->first_seg->dma | ep_ring->cycle_state; |
531 | 551 | ||
532 | ep_ctx->ep_info = xhci_get_endpoint_interval(udev, ep); | 552 | ep_ctx->ep_info = xhci_get_endpoint_interval(udev, ep); |
@@ -598,6 +618,48 @@ void xhci_endpoint_zero(struct xhci_hcd *xhci, | |||
598 | */ | 618 | */ |
599 | } | 619 | } |
600 | 620 | ||
621 | /* Copy output xhci_ep_ctx to the input xhci_ep_ctx copy. | ||
622 | * Useful when you want to change one particular aspect of the endpoint and then | ||
623 | * issue a configure endpoint command. | ||
624 | */ | ||
625 | void xhci_endpoint_copy(struct xhci_hcd *xhci, | ||
626 | struct xhci_container_ctx *in_ctx, | ||
627 | struct xhci_container_ctx *out_ctx, | ||
628 | unsigned int ep_index) | ||
629 | { | ||
630 | struct xhci_ep_ctx *out_ep_ctx; | ||
631 | struct xhci_ep_ctx *in_ep_ctx; | ||
632 | |||
633 | out_ep_ctx = xhci_get_ep_ctx(xhci, out_ctx, ep_index); | ||
634 | in_ep_ctx = xhci_get_ep_ctx(xhci, in_ctx, ep_index); | ||
635 | |||
636 | in_ep_ctx->ep_info = out_ep_ctx->ep_info; | ||
637 | in_ep_ctx->ep_info2 = out_ep_ctx->ep_info2; | ||
638 | in_ep_ctx->deq = out_ep_ctx->deq; | ||
639 | in_ep_ctx->tx_info = out_ep_ctx->tx_info; | ||
640 | } | ||
641 | |||
642 | /* Copy output xhci_slot_ctx to the input xhci_slot_ctx. | ||
643 | * Useful when you want to change one particular aspect of the endpoint and then | ||
644 | * issue a configure endpoint command. Only the context entries field matters, | ||
645 | * but we'll copy the whole thing anyway. | ||
646 | */ | ||
647 | void xhci_slot_copy(struct xhci_hcd *xhci, | ||
648 | struct xhci_container_ctx *in_ctx, | ||
649 | struct xhci_container_ctx *out_ctx) | ||
650 | { | ||
651 | struct xhci_slot_ctx *in_slot_ctx; | ||
652 | struct xhci_slot_ctx *out_slot_ctx; | ||
653 | |||
654 | in_slot_ctx = xhci_get_slot_ctx(xhci, in_ctx); | ||
655 | out_slot_ctx = xhci_get_slot_ctx(xhci, out_ctx); | ||
656 | |||
657 | in_slot_ctx->dev_info = out_slot_ctx->dev_info; | ||
658 | in_slot_ctx->dev_info2 = out_slot_ctx->dev_info2; | ||
659 | in_slot_ctx->tt_info = out_slot_ctx->tt_info; | ||
660 | in_slot_ctx->dev_state = out_slot_ctx->dev_state; | ||
661 | } | ||
662 | |||
601 | /* Set up the scratchpad buffer array and scratchpad buffers, if needed. */ | 663 | /* Set up the scratchpad buffer array and scratchpad buffers, if needed. */ |
602 | static int scratchpad_alloc(struct xhci_hcd *xhci, gfp_t flags) | 664 | static int scratchpad_alloc(struct xhci_hcd *xhci, gfp_t flags) |
603 | { | 665 | { |
@@ -695,6 +757,44 @@ static void scratchpad_free(struct xhci_hcd *xhci) | |||
695 | xhci->scratchpad = NULL; | 757 | xhci->scratchpad = NULL; |
696 | } | 758 | } |
697 | 759 | ||
760 | struct xhci_command *xhci_alloc_command(struct xhci_hcd *xhci, | ||
761 | bool allocate_completion, gfp_t mem_flags) | ||
762 | { | ||
763 | struct xhci_command *command; | ||
764 | |||
765 | command = kzalloc(sizeof(*command), mem_flags); | ||
766 | if (!command) | ||
767 | return NULL; | ||
768 | |||
769 | command->in_ctx = | ||
770 | xhci_alloc_container_ctx(xhci, XHCI_CTX_TYPE_INPUT, mem_flags); | ||
771 | if (!command->in_ctx) | ||
772 | return NULL; | ||
773 | |||
774 | if (allocate_completion) { | ||
775 | command->completion = | ||
776 | kzalloc(sizeof(struct completion), mem_flags); | ||
777 | if (!command->completion) { | ||
778 | xhci_free_container_ctx(xhci, command->in_ctx); | ||
779 | return NULL; | ||
780 | } | ||
781 | init_completion(command->completion); | ||
782 | } | ||
783 | |||
784 | command->status = 0; | ||
785 | INIT_LIST_HEAD(&command->cmd_list); | ||
786 | return command; | ||
787 | } | ||
788 | |||
789 | void xhci_free_command(struct xhci_hcd *xhci, | ||
790 | struct xhci_command *command) | ||
791 | { | ||
792 | xhci_free_container_ctx(xhci, | ||
793 | command->in_ctx); | ||
794 | kfree(command->completion); | ||
795 | kfree(command); | ||
796 | } | ||
797 | |||
698 | void xhci_mem_cleanup(struct xhci_hcd *xhci) | 798 | void xhci_mem_cleanup(struct xhci_hcd *xhci) |
699 | { | 799 | { |
700 | struct pci_dev *pdev = to_pci_dev(xhci_to_hcd(xhci)->self.controller); | 800 | struct pci_dev *pdev = to_pci_dev(xhci_to_hcd(xhci)->self.controller); |
diff --git a/drivers/usb/host/xhci-pci.c b/drivers/usb/host/xhci-pci.c index 592fe7e623f7..06595ec27bb7 100644 --- a/drivers/usb/host/xhci-pci.c +++ b/drivers/usb/host/xhci-pci.c | |||
@@ -24,6 +24,10 @@ | |||
24 | 24 | ||
25 | #include "xhci.h" | 25 | #include "xhci.h" |
26 | 26 | ||
27 | /* Device for a quirk */ | ||
28 | #define PCI_VENDOR_ID_FRESCO_LOGIC 0x1b73 | ||
29 | #define PCI_DEVICE_ID_FRESCO_LOGIC_PDK 0x1000 | ||
30 | |||
27 | static const char hcd_name[] = "xhci_hcd"; | 31 | static const char hcd_name[] = "xhci_hcd"; |
28 | 32 | ||
29 | /* called after powerup, by probe or system-pm "wakeup" */ | 33 | /* called after powerup, by probe or system-pm "wakeup" */ |
@@ -59,9 +63,20 @@ static int xhci_pci_setup(struct usb_hcd *hcd) | |||
59 | xhci->hcs_params1 = xhci_readl(xhci, &xhci->cap_regs->hcs_params1); | 63 | xhci->hcs_params1 = xhci_readl(xhci, &xhci->cap_regs->hcs_params1); |
60 | xhci->hcs_params2 = xhci_readl(xhci, &xhci->cap_regs->hcs_params2); | 64 | xhci->hcs_params2 = xhci_readl(xhci, &xhci->cap_regs->hcs_params2); |
61 | xhci->hcs_params3 = xhci_readl(xhci, &xhci->cap_regs->hcs_params3); | 65 | xhci->hcs_params3 = xhci_readl(xhci, &xhci->cap_regs->hcs_params3); |
66 | xhci->hcc_params = xhci_readl(xhci, &xhci->cap_regs->hc_capbase); | ||
67 | xhci->hci_version = HC_VERSION(xhci->hcc_params); | ||
62 | xhci->hcc_params = xhci_readl(xhci, &xhci->cap_regs->hcc_params); | 68 | xhci->hcc_params = xhci_readl(xhci, &xhci->cap_regs->hcc_params); |
63 | xhci_print_registers(xhci); | 69 | xhci_print_registers(xhci); |
64 | 70 | ||
71 | /* Look for vendor-specific quirks */ | ||
72 | if (pdev->vendor == PCI_VENDOR_ID_FRESCO_LOGIC && | ||
73 | pdev->device == PCI_DEVICE_ID_FRESCO_LOGIC_PDK && | ||
74 | pdev->revision == 0x0) { | ||
75 | xhci->quirks |= XHCI_RESET_EP_QUIRK; | ||
76 | xhci_dbg(xhci, "QUIRK: Fresco Logic xHC needs configure" | ||
77 | " endpoint cmd after reset endpoint\n"); | ||
78 | } | ||
79 | |||
65 | /* Make sure the HC is halted. */ | 80 | /* Make sure the HC is halted. */ |
66 | retval = xhci_halt(xhci); | 81 | retval = xhci_halt(xhci); |
67 | if (retval) | 82 | if (retval) |
@@ -121,6 +136,7 @@ static const struct hc_driver xhci_pci_hc_driver = { | |||
121 | .check_bandwidth = xhci_check_bandwidth, | 136 | .check_bandwidth = xhci_check_bandwidth, |
122 | .reset_bandwidth = xhci_reset_bandwidth, | 137 | .reset_bandwidth = xhci_reset_bandwidth, |
123 | .address_device = xhci_address_device, | 138 | .address_device = xhci_address_device, |
139 | .update_hub_device = xhci_update_hub_device, | ||
124 | 140 | ||
125 | /* | 141 | /* |
126 | * scheduling support | 142 | * scheduling support |
diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c index aa88a067148b..173c39c76489 100644 --- a/drivers/usb/host/xhci-ring.c +++ b/drivers/usb/host/xhci-ring.c | |||
@@ -172,8 +172,9 @@ static void inc_deq(struct xhci_hcd *xhci, struct xhci_ring *ring, bool consumer | |||
172 | * have their chain bit cleared (so that each Link TRB is a separate TD). | 172 | * have their chain bit cleared (so that each Link TRB is a separate TD). |
173 | * | 173 | * |
174 | * Section 6.4.4.1 of the 0.95 spec says link TRBs cannot have the chain bit | 174 | * Section 6.4.4.1 of the 0.95 spec says link TRBs cannot have the chain bit |
175 | * set, but other sections talk about dealing with the chain bit set. | 175 | * set, but other sections talk about dealing with the chain bit set. This was |
176 | * Assume section 6.4.4.1 is wrong, and the chain bit can be set in a Link TRB. | 176 | * fixed in the 0.96 specification errata, but we have to assume that all 0.95 |
177 | * xHCI hardware can't handle the chain bit being cleared on a link TRB. | ||
177 | */ | 178 | */ |
178 | static void inc_enq(struct xhci_hcd *xhci, struct xhci_ring *ring, bool consumer) | 179 | static void inc_enq(struct xhci_hcd *xhci, struct xhci_ring *ring, bool consumer) |
179 | { | 180 | { |
@@ -191,8 +192,14 @@ static void inc_enq(struct xhci_hcd *xhci, struct xhci_ring *ring, bool consumer | |||
191 | while (last_trb(xhci, ring, ring->enq_seg, next)) { | 192 | while (last_trb(xhci, ring, ring->enq_seg, next)) { |
192 | if (!consumer) { | 193 | if (!consumer) { |
193 | if (ring != xhci->event_ring) { | 194 | if (ring != xhci->event_ring) { |
194 | next->link.control &= ~TRB_CHAIN; | 195 | /* If we're not dealing with 0.95 hardware, |
195 | next->link.control |= chain; | 196 | * carry over the chain bit of the previous TRB |
197 | * (which may mean the chain bit is cleared). | ||
198 | */ | ||
199 | if (!xhci_link_trb_quirk(xhci)) { | ||
200 | next->link.control &= ~TRB_CHAIN; | ||
201 | next->link.control |= chain; | ||
202 | } | ||
196 | /* Give this link TRB to the hardware */ | 203 | /* Give this link TRB to the hardware */ |
197 | wmb(); | 204 | wmb(); |
198 | if (next->link.control & TRB_CYCLE) | 205 | if (next->link.control & TRB_CYCLE) |
@@ -289,16 +296,18 @@ static void ring_ep_doorbell(struct xhci_hcd *xhci, | |||
289 | unsigned int slot_id, | 296 | unsigned int slot_id, |
290 | unsigned int ep_index) | 297 | unsigned int ep_index) |
291 | { | 298 | { |
292 | struct xhci_ring *ep_ring; | 299 | struct xhci_virt_ep *ep; |
300 | unsigned int ep_state; | ||
293 | u32 field; | 301 | u32 field; |
294 | __u32 __iomem *db_addr = &xhci->dba->doorbell[slot_id]; | 302 | __u32 __iomem *db_addr = &xhci->dba->doorbell[slot_id]; |
295 | 303 | ||
296 | ep_ring = xhci->devs[slot_id]->ep_rings[ep_index]; | 304 | ep = &xhci->devs[slot_id]->eps[ep_index]; |
305 | ep_state = ep->ep_state; | ||
297 | /* Don't ring the doorbell for this endpoint if there are pending | 306 | /* Don't ring the doorbell for this endpoint if there are pending |
298 | * cancellations because the we don't want to interrupt processing. | 307 | * cancellations because the we don't want to interrupt processing. |
299 | */ | 308 | */ |
300 | if (!ep_ring->cancels_pending && !(ep_ring->state & SET_DEQ_PENDING) | 309 | if (!ep->cancels_pending && !(ep_state & SET_DEQ_PENDING) |
301 | && !(ep_ring->state & EP_HALTED)) { | 310 | && !(ep_state & EP_HALTED)) { |
302 | field = xhci_readl(xhci, db_addr) & DB_MASK; | 311 | field = xhci_readl(xhci, db_addr) & DB_MASK; |
303 | xhci_writel(xhci, field | EPI_TO_DB(ep_index), db_addr); | 312 | xhci_writel(xhci, field | EPI_TO_DB(ep_index), db_addr); |
304 | /* Flush PCI posted writes - FIXME Matthew Wilcox says this | 313 | /* Flush PCI posted writes - FIXME Matthew Wilcox says this |
@@ -354,7 +363,7 @@ void xhci_find_new_dequeue_state(struct xhci_hcd *xhci, | |||
354 | struct xhci_td *cur_td, struct xhci_dequeue_state *state) | 363 | struct xhci_td *cur_td, struct xhci_dequeue_state *state) |
355 | { | 364 | { |
356 | struct xhci_virt_device *dev = xhci->devs[slot_id]; | 365 | struct xhci_virt_device *dev = xhci->devs[slot_id]; |
357 | struct xhci_ring *ep_ring = dev->ep_rings[ep_index]; | 366 | struct xhci_ring *ep_ring = dev->eps[ep_index].ring; |
358 | struct xhci_generic_trb *trb; | 367 | struct xhci_generic_trb *trb; |
359 | struct xhci_ep_ctx *ep_ctx; | 368 | struct xhci_ep_ctx *ep_ctx; |
360 | dma_addr_t addr; | 369 | dma_addr_t addr; |
@@ -362,7 +371,7 @@ void xhci_find_new_dequeue_state(struct xhci_hcd *xhci, | |||
362 | state->new_cycle_state = 0; | 371 | state->new_cycle_state = 0; |
363 | xhci_dbg(xhci, "Finding segment containing stopped TRB.\n"); | 372 | xhci_dbg(xhci, "Finding segment containing stopped TRB.\n"); |
364 | state->new_deq_seg = find_trb_seg(cur_td->start_seg, | 373 | state->new_deq_seg = find_trb_seg(cur_td->start_seg, |
365 | ep_ring->stopped_trb, | 374 | dev->eps[ep_index].stopped_trb, |
366 | &state->new_cycle_state); | 375 | &state->new_cycle_state); |
367 | if (!state->new_deq_seg) | 376 | if (!state->new_deq_seg) |
368 | BUG(); | 377 | BUG(); |
@@ -442,9 +451,11 @@ static int queue_set_tr_deq(struct xhci_hcd *xhci, int slot_id, | |||
442 | union xhci_trb *deq_ptr, u32 cycle_state); | 451 | union xhci_trb *deq_ptr, u32 cycle_state); |
443 | 452 | ||
444 | void xhci_queue_new_dequeue_state(struct xhci_hcd *xhci, | 453 | void xhci_queue_new_dequeue_state(struct xhci_hcd *xhci, |
445 | struct xhci_ring *ep_ring, unsigned int slot_id, | 454 | unsigned int slot_id, unsigned int ep_index, |
446 | unsigned int ep_index, struct xhci_dequeue_state *deq_state) | 455 | struct xhci_dequeue_state *deq_state) |
447 | { | 456 | { |
457 | struct xhci_virt_ep *ep = &xhci->devs[slot_id]->eps[ep_index]; | ||
458 | |||
448 | xhci_dbg(xhci, "Set TR Deq Ptr cmd, new deq seg = %p (0x%llx dma), " | 459 | xhci_dbg(xhci, "Set TR Deq Ptr cmd, new deq seg = %p (0x%llx dma), " |
449 | "new deq ptr = %p (0x%llx dma), new cycle = %u\n", | 460 | "new deq ptr = %p (0x%llx dma), new cycle = %u\n", |
450 | deq_state->new_deq_seg, | 461 | deq_state->new_deq_seg, |
@@ -461,8 +472,7 @@ void xhci_queue_new_dequeue_state(struct xhci_hcd *xhci, | |||
461 | * if the ring is running, and ringing the doorbell starts the | 472 | * if the ring is running, and ringing the doorbell starts the |
462 | * ring running. | 473 | * ring running. |
463 | */ | 474 | */ |
464 | ep_ring->state |= SET_DEQ_PENDING; | 475 | ep->ep_state |= SET_DEQ_PENDING; |
465 | xhci_ring_cmd_db(xhci); | ||
466 | } | 476 | } |
467 | 477 | ||
468 | /* | 478 | /* |
@@ -481,6 +491,7 @@ static void handle_stopped_endpoint(struct xhci_hcd *xhci, | |||
481 | unsigned int slot_id; | 491 | unsigned int slot_id; |
482 | unsigned int ep_index; | 492 | unsigned int ep_index; |
483 | struct xhci_ring *ep_ring; | 493 | struct xhci_ring *ep_ring; |
494 | struct xhci_virt_ep *ep; | ||
484 | struct list_head *entry; | 495 | struct list_head *entry; |
485 | struct xhci_td *cur_td = 0; | 496 | struct xhci_td *cur_td = 0; |
486 | struct xhci_td *last_unlinked_td; | 497 | struct xhci_td *last_unlinked_td; |
@@ -493,9 +504,10 @@ static void handle_stopped_endpoint(struct xhci_hcd *xhci, | |||
493 | memset(&deq_state, 0, sizeof(deq_state)); | 504 | memset(&deq_state, 0, sizeof(deq_state)); |
494 | slot_id = TRB_TO_SLOT_ID(trb->generic.field[3]); | 505 | slot_id = TRB_TO_SLOT_ID(trb->generic.field[3]); |
495 | ep_index = TRB_TO_EP_INDEX(trb->generic.field[3]); | 506 | ep_index = TRB_TO_EP_INDEX(trb->generic.field[3]); |
496 | ep_ring = xhci->devs[slot_id]->ep_rings[ep_index]; | 507 | ep = &xhci->devs[slot_id]->eps[ep_index]; |
508 | ep_ring = ep->ring; | ||
497 | 509 | ||
498 | if (list_empty(&ep_ring->cancelled_td_list)) | 510 | if (list_empty(&ep->cancelled_td_list)) |
499 | return; | 511 | return; |
500 | 512 | ||
501 | /* Fix up the ep ring first, so HW stops executing cancelled TDs. | 513 | /* Fix up the ep ring first, so HW stops executing cancelled TDs. |
@@ -503,7 +515,7 @@ static void handle_stopped_endpoint(struct xhci_hcd *xhci, | |||
503 | * it. We're also in the event handler, so we can't get re-interrupted | 515 | * it. We're also in the event handler, so we can't get re-interrupted |
504 | * if another Stop Endpoint command completes | 516 | * if another Stop Endpoint command completes |
505 | */ | 517 | */ |
506 | list_for_each(entry, &ep_ring->cancelled_td_list) { | 518 | list_for_each(entry, &ep->cancelled_td_list) { |
507 | cur_td = list_entry(entry, struct xhci_td, cancelled_td_list); | 519 | cur_td = list_entry(entry, struct xhci_td, cancelled_td_list); |
508 | xhci_dbg(xhci, "Cancelling TD starting at %p, 0x%llx (dma).\n", | 520 | xhci_dbg(xhci, "Cancelling TD starting at %p, 0x%llx (dma).\n", |
509 | cur_td->first_trb, | 521 | cur_td->first_trb, |
@@ -512,7 +524,7 @@ static void handle_stopped_endpoint(struct xhci_hcd *xhci, | |||
512 | * If we stopped on the TD we need to cancel, then we have to | 524 | * If we stopped on the TD we need to cancel, then we have to |
513 | * move the xHC endpoint ring dequeue pointer past this TD. | 525 | * move the xHC endpoint ring dequeue pointer past this TD. |
514 | */ | 526 | */ |
515 | if (cur_td == ep_ring->stopped_td) | 527 | if (cur_td == ep->stopped_td) |
516 | xhci_find_new_dequeue_state(xhci, slot_id, ep_index, cur_td, | 528 | xhci_find_new_dequeue_state(xhci, slot_id, ep_index, cur_td, |
517 | &deq_state); | 529 | &deq_state); |
518 | else | 530 | else |
@@ -523,14 +535,15 @@ static void handle_stopped_endpoint(struct xhci_hcd *xhci, | |||
523 | * the cancelled TD list for URB completion later. | 535 | * the cancelled TD list for URB completion later. |
524 | */ | 536 | */ |
525 | list_del(&cur_td->td_list); | 537 | list_del(&cur_td->td_list); |
526 | ep_ring->cancels_pending--; | 538 | ep->cancels_pending--; |
527 | } | 539 | } |
528 | last_unlinked_td = cur_td; | 540 | last_unlinked_td = cur_td; |
529 | 541 | ||
530 | /* If necessary, queue a Set Transfer Ring Dequeue Pointer command */ | 542 | /* If necessary, queue a Set Transfer Ring Dequeue Pointer command */ |
531 | if (deq_state.new_deq_ptr && deq_state.new_deq_seg) { | 543 | if (deq_state.new_deq_ptr && deq_state.new_deq_seg) { |
532 | xhci_queue_new_dequeue_state(xhci, ep_ring, | 544 | xhci_queue_new_dequeue_state(xhci, |
533 | slot_id, ep_index, &deq_state); | 545 | slot_id, ep_index, &deq_state); |
546 | xhci_ring_cmd_db(xhci); | ||
534 | } else { | 547 | } else { |
535 | /* Otherwise just ring the doorbell to restart the ring */ | 548 | /* Otherwise just ring the doorbell to restart the ring */ |
536 | ring_ep_doorbell(xhci, slot_id, ep_index); | 549 | ring_ep_doorbell(xhci, slot_id, ep_index); |
@@ -543,7 +556,7 @@ static void handle_stopped_endpoint(struct xhci_hcd *xhci, | |||
543 | * So stop when we've completed the URB for the last TD we unlinked. | 556 | * So stop when we've completed the URB for the last TD we unlinked. |
544 | */ | 557 | */ |
545 | do { | 558 | do { |
546 | cur_td = list_entry(ep_ring->cancelled_td_list.next, | 559 | cur_td = list_entry(ep->cancelled_td_list.next, |
547 | struct xhci_td, cancelled_td_list); | 560 | struct xhci_td, cancelled_td_list); |
548 | list_del(&cur_td->cancelled_td_list); | 561 | list_del(&cur_td->cancelled_td_list); |
549 | 562 | ||
@@ -590,7 +603,7 @@ static void handle_set_deq_completion(struct xhci_hcd *xhci, | |||
590 | slot_id = TRB_TO_SLOT_ID(trb->generic.field[3]); | 603 | slot_id = TRB_TO_SLOT_ID(trb->generic.field[3]); |
591 | ep_index = TRB_TO_EP_INDEX(trb->generic.field[3]); | 604 | ep_index = TRB_TO_EP_INDEX(trb->generic.field[3]); |
592 | dev = xhci->devs[slot_id]; | 605 | dev = xhci->devs[slot_id]; |
593 | ep_ring = dev->ep_rings[ep_index]; | 606 | ep_ring = dev->eps[ep_index].ring; |
594 | ep_ctx = xhci_get_ep_ctx(xhci, dev->out_ctx, ep_index); | 607 | ep_ctx = xhci_get_ep_ctx(xhci, dev->out_ctx, ep_index); |
595 | slot_ctx = xhci_get_slot_ctx(xhci, dev->out_ctx); | 608 | slot_ctx = xhci_get_slot_ctx(xhci, dev->out_ctx); |
596 | 609 | ||
@@ -634,7 +647,7 @@ static void handle_set_deq_completion(struct xhci_hcd *xhci, | |||
634 | ep_ctx->deq); | 647 | ep_ctx->deq); |
635 | } | 648 | } |
636 | 649 | ||
637 | ep_ring->state &= ~SET_DEQ_PENDING; | 650 | dev->eps[ep_index].ep_state &= ~SET_DEQ_PENDING; |
638 | ring_ep_doorbell(xhci, slot_id, ep_index); | 651 | ring_ep_doorbell(xhci, slot_id, ep_index); |
639 | } | 652 | } |
640 | 653 | ||
@@ -644,18 +657,60 @@ static void handle_reset_ep_completion(struct xhci_hcd *xhci, | |||
644 | { | 657 | { |
645 | int slot_id; | 658 | int slot_id; |
646 | unsigned int ep_index; | 659 | unsigned int ep_index; |
660 | struct xhci_ring *ep_ring; | ||
647 | 661 | ||
648 | slot_id = TRB_TO_SLOT_ID(trb->generic.field[3]); | 662 | slot_id = TRB_TO_SLOT_ID(trb->generic.field[3]); |
649 | ep_index = TRB_TO_EP_INDEX(trb->generic.field[3]); | 663 | ep_index = TRB_TO_EP_INDEX(trb->generic.field[3]); |
664 | ep_ring = xhci->devs[slot_id]->eps[ep_index].ring; | ||
650 | /* This command will only fail if the endpoint wasn't halted, | 665 | /* This command will only fail if the endpoint wasn't halted, |
651 | * but we don't care. | 666 | * but we don't care. |
652 | */ | 667 | */ |
653 | xhci_dbg(xhci, "Ignoring reset ep completion code of %u\n", | 668 | xhci_dbg(xhci, "Ignoring reset ep completion code of %u\n", |
654 | (unsigned int) GET_COMP_CODE(event->status)); | 669 | (unsigned int) GET_COMP_CODE(event->status)); |
655 | 670 | ||
656 | /* Clear our internal halted state and restart the ring */ | 671 | /* HW with the reset endpoint quirk needs to have a configure endpoint |
657 | xhci->devs[slot_id]->ep_rings[ep_index]->state &= ~EP_HALTED; | 672 | * command complete before the endpoint can be used. Queue that here |
658 | ring_ep_doorbell(xhci, slot_id, ep_index); | 673 | * because the HW can't handle two commands being queued in a row. |
674 | */ | ||
675 | if (xhci->quirks & XHCI_RESET_EP_QUIRK) { | ||
676 | xhci_dbg(xhci, "Queueing configure endpoint command\n"); | ||
677 | xhci_queue_configure_endpoint(xhci, | ||
678 | xhci->devs[slot_id]->in_ctx->dma, slot_id, | ||
679 | false); | ||
680 | xhci_ring_cmd_db(xhci); | ||
681 | } else { | ||
682 | /* Clear our internal halted state and restart the ring */ | ||
683 | xhci->devs[slot_id]->eps[ep_index].ep_state &= ~EP_HALTED; | ||
684 | ring_ep_doorbell(xhci, slot_id, ep_index); | ||
685 | } | ||
686 | } | ||
687 | |||
688 | /* Check to see if a command in the device's command queue matches this one. | ||
689 | * Signal the completion or free the command, and return 1. Return 0 if the | ||
690 | * completed command isn't at the head of the command list. | ||
691 | */ | ||
692 | static int handle_cmd_in_cmd_wait_list(struct xhci_hcd *xhci, | ||
693 | struct xhci_virt_device *virt_dev, | ||
694 | struct xhci_event_cmd *event) | ||
695 | { | ||
696 | struct xhci_command *command; | ||
697 | |||
698 | if (list_empty(&virt_dev->cmd_list)) | ||
699 | return 0; | ||
700 | |||
701 | command = list_entry(virt_dev->cmd_list.next, | ||
702 | struct xhci_command, cmd_list); | ||
703 | if (xhci->cmd_ring->dequeue != command->command_trb) | ||
704 | return 0; | ||
705 | |||
706 | command->status = | ||
707 | GET_COMP_CODE(event->status); | ||
708 | list_del(&command->cmd_list); | ||
709 | if (command->completion) | ||
710 | complete(command->completion); | ||
711 | else | ||
712 | xhci_free_command(xhci, command); | ||
713 | return 1; | ||
659 | } | 714 | } |
660 | 715 | ||
661 | static void handle_cmd_completion(struct xhci_hcd *xhci, | 716 | static void handle_cmd_completion(struct xhci_hcd *xhci, |
@@ -664,6 +719,11 @@ static void handle_cmd_completion(struct xhci_hcd *xhci, | |||
664 | int slot_id = TRB_TO_SLOT_ID(event->flags); | 719 | int slot_id = TRB_TO_SLOT_ID(event->flags); |
665 | u64 cmd_dma; | 720 | u64 cmd_dma; |
666 | dma_addr_t cmd_dequeue_dma; | 721 | dma_addr_t cmd_dequeue_dma; |
722 | struct xhci_input_control_ctx *ctrl_ctx; | ||
723 | struct xhci_virt_device *virt_dev; | ||
724 | unsigned int ep_index; | ||
725 | struct xhci_ring *ep_ring; | ||
726 | unsigned int ep_state; | ||
667 | 727 | ||
668 | cmd_dma = event->cmd_trb; | 728 | cmd_dma = event->cmd_trb; |
669 | cmd_dequeue_dma = xhci_trb_virt_to_dma(xhci->cmd_ring->deq_seg, | 729 | cmd_dequeue_dma = xhci_trb_virt_to_dma(xhci->cmd_ring->deq_seg, |
@@ -691,6 +751,47 @@ static void handle_cmd_completion(struct xhci_hcd *xhci, | |||
691 | xhci_free_virt_device(xhci, slot_id); | 751 | xhci_free_virt_device(xhci, slot_id); |
692 | break; | 752 | break; |
693 | case TRB_TYPE(TRB_CONFIG_EP): | 753 | case TRB_TYPE(TRB_CONFIG_EP): |
754 | virt_dev = xhci->devs[slot_id]; | ||
755 | if (handle_cmd_in_cmd_wait_list(xhci, virt_dev, event)) | ||
756 | break; | ||
757 | /* | ||
758 | * Configure endpoint commands can come from the USB core | ||
759 | * configuration or alt setting changes, or because the HW | ||
760 | * needed an extra configure endpoint command after a reset | ||
761 | * endpoint command. In the latter case, the xHCI driver is | ||
762 | * not waiting on the configure endpoint command. | ||
763 | */ | ||
764 | ctrl_ctx = xhci_get_input_control_ctx(xhci, | ||
765 | virt_dev->in_ctx); | ||
766 | /* Input ctx add_flags are the endpoint index plus one */ | ||
767 | ep_index = xhci_last_valid_endpoint(ctrl_ctx->add_flags) - 1; | ||
768 | ep_ring = xhci->devs[slot_id]->eps[ep_index].ring; | ||
769 | if (!ep_ring) { | ||
770 | /* This must have been an initial configure endpoint */ | ||
771 | xhci->devs[slot_id]->cmd_status = | ||
772 | GET_COMP_CODE(event->status); | ||
773 | complete(&xhci->devs[slot_id]->cmd_completion); | ||
774 | break; | ||
775 | } | ||
776 | ep_state = xhci->devs[slot_id]->eps[ep_index].ep_state; | ||
777 | xhci_dbg(xhci, "Completed config ep cmd - last ep index = %d, " | ||
778 | "state = %d\n", ep_index, ep_state); | ||
779 | if (xhci->quirks & XHCI_RESET_EP_QUIRK && | ||
780 | ep_state & EP_HALTED) { | ||
781 | /* Clear our internal halted state and restart ring */ | ||
782 | xhci->devs[slot_id]->eps[ep_index].ep_state &= | ||
783 | ~EP_HALTED; | ||
784 | ring_ep_doorbell(xhci, slot_id, ep_index); | ||
785 | } else { | ||
786 | xhci->devs[slot_id]->cmd_status = | ||
787 | GET_COMP_CODE(event->status); | ||
788 | complete(&xhci->devs[slot_id]->cmd_completion); | ||
789 | } | ||
790 | break; | ||
791 | case TRB_TYPE(TRB_EVAL_CONTEXT): | ||
792 | virt_dev = xhci->devs[slot_id]; | ||
793 | if (handle_cmd_in_cmd_wait_list(xhci, virt_dev, event)) | ||
794 | break; | ||
694 | xhci->devs[slot_id]->cmd_status = GET_COMP_CODE(event->status); | 795 | xhci->devs[slot_id]->cmd_status = GET_COMP_CODE(event->status); |
695 | complete(&xhci->devs[slot_id]->cmd_completion); | 796 | complete(&xhci->devs[slot_id]->cmd_completion); |
696 | break; | 797 | break; |
@@ -805,7 +906,9 @@ static int handle_tx_event(struct xhci_hcd *xhci, | |||
805 | struct xhci_transfer_event *event) | 906 | struct xhci_transfer_event *event) |
806 | { | 907 | { |
807 | struct xhci_virt_device *xdev; | 908 | struct xhci_virt_device *xdev; |
909 | struct xhci_virt_ep *ep; | ||
808 | struct xhci_ring *ep_ring; | 910 | struct xhci_ring *ep_ring; |
911 | unsigned int slot_id; | ||
809 | int ep_index; | 912 | int ep_index; |
810 | struct xhci_td *td = 0; | 913 | struct xhci_td *td = 0; |
811 | dma_addr_t event_dma; | 914 | dma_addr_t event_dma; |
@@ -814,9 +917,11 @@ static int handle_tx_event(struct xhci_hcd *xhci, | |||
814 | struct urb *urb = 0; | 917 | struct urb *urb = 0; |
815 | int status = -EINPROGRESS; | 918 | int status = -EINPROGRESS; |
816 | struct xhci_ep_ctx *ep_ctx; | 919 | struct xhci_ep_ctx *ep_ctx; |
920 | u32 trb_comp_code; | ||
817 | 921 | ||
818 | xhci_dbg(xhci, "In %s\n", __func__); | 922 | xhci_dbg(xhci, "In %s\n", __func__); |
819 | xdev = xhci->devs[TRB_TO_SLOT_ID(event->flags)]; | 923 | slot_id = TRB_TO_SLOT_ID(event->flags); |
924 | xdev = xhci->devs[slot_id]; | ||
820 | if (!xdev) { | 925 | if (!xdev) { |
821 | xhci_err(xhci, "ERROR Transfer event pointed to bad slot\n"); | 926 | xhci_err(xhci, "ERROR Transfer event pointed to bad slot\n"); |
822 | return -ENODEV; | 927 | return -ENODEV; |
@@ -825,7 +930,8 @@ static int handle_tx_event(struct xhci_hcd *xhci, | |||
825 | /* Endpoint ID is 1 based, our index is zero based */ | 930 | /* Endpoint ID is 1 based, our index is zero based */ |
826 | ep_index = TRB_TO_EP_ID(event->flags) - 1; | 931 | ep_index = TRB_TO_EP_ID(event->flags) - 1; |
827 | xhci_dbg(xhci, "%s - ep index = %d\n", __func__, ep_index); | 932 | xhci_dbg(xhci, "%s - ep index = %d\n", __func__, ep_index); |
828 | ep_ring = xdev->ep_rings[ep_index]; | 933 | ep = &xdev->eps[ep_index]; |
934 | ep_ring = ep->ring; | ||
829 | ep_ctx = xhci_get_ep_ctx(xhci, xdev->out_ctx, ep_index); | 935 | ep_ctx = xhci_get_ep_ctx(xhci, xdev->out_ctx, ep_index); |
830 | if (!ep_ring || (ep_ctx->ep_info & EP_STATE_MASK) == EP_STATE_DISABLED) { | 936 | if (!ep_ring || (ep_ctx->ep_info & EP_STATE_MASK) == EP_STATE_DISABLED) { |
831 | xhci_err(xhci, "ERROR Transfer event pointed to disabled endpoint\n"); | 937 | xhci_err(xhci, "ERROR Transfer event pointed to disabled endpoint\n"); |
@@ -870,7 +976,8 @@ static int handle_tx_event(struct xhci_hcd *xhci, | |||
870 | (unsigned int) event->flags); | 976 | (unsigned int) event->flags); |
871 | 977 | ||
872 | /* Look for common error cases */ | 978 | /* Look for common error cases */ |
873 | switch (GET_COMP_CODE(event->transfer_len)) { | 979 | trb_comp_code = GET_COMP_CODE(event->transfer_len); |
980 | switch (trb_comp_code) { | ||
874 | /* Skip codes that require special handling depending on | 981 | /* Skip codes that require special handling depending on |
875 | * transfer type | 982 | * transfer type |
876 | */ | 983 | */ |
@@ -885,7 +992,7 @@ static int handle_tx_event(struct xhci_hcd *xhci, | |||
885 | break; | 992 | break; |
886 | case COMP_STALL: | 993 | case COMP_STALL: |
887 | xhci_warn(xhci, "WARN: Stalled endpoint\n"); | 994 | xhci_warn(xhci, "WARN: Stalled endpoint\n"); |
888 | ep_ring->state |= EP_HALTED; | 995 | ep->ep_state |= EP_HALTED; |
889 | status = -EPIPE; | 996 | status = -EPIPE; |
890 | break; | 997 | break; |
891 | case COMP_TRB_ERR: | 998 | case COMP_TRB_ERR: |
@@ -913,7 +1020,7 @@ static int handle_tx_event(struct xhci_hcd *xhci, | |||
913 | /* Was this a control transfer? */ | 1020 | /* Was this a control transfer? */ |
914 | if (usb_endpoint_xfer_control(&td->urb->ep->desc)) { | 1021 | if (usb_endpoint_xfer_control(&td->urb->ep->desc)) { |
915 | xhci_debug_trb(xhci, xhci->event_ring->dequeue); | 1022 | xhci_debug_trb(xhci, xhci->event_ring->dequeue); |
916 | switch (GET_COMP_CODE(event->transfer_len)) { | 1023 | switch (trb_comp_code) { |
917 | case COMP_SUCCESS: | 1024 | case COMP_SUCCESS: |
918 | if (event_trb == ep_ring->dequeue) { | 1025 | if (event_trb == ep_ring->dequeue) { |
919 | xhci_warn(xhci, "WARN: Success on ctrl setup TRB without IOC set??\n"); | 1026 | xhci_warn(xhci, "WARN: Success on ctrl setup TRB without IOC set??\n"); |
@@ -928,8 +1035,37 @@ static int handle_tx_event(struct xhci_hcd *xhci, | |||
928 | break; | 1035 | break; |
929 | case COMP_SHORT_TX: | 1036 | case COMP_SHORT_TX: |
930 | xhci_warn(xhci, "WARN: short transfer on control ep\n"); | 1037 | xhci_warn(xhci, "WARN: short transfer on control ep\n"); |
931 | status = -EREMOTEIO; | 1038 | if (td->urb->transfer_flags & URB_SHORT_NOT_OK) |
1039 | status = -EREMOTEIO; | ||
1040 | else | ||
1041 | status = 0; | ||
932 | break; | 1042 | break; |
1043 | case COMP_BABBLE: | ||
1044 | /* The 0.96 spec says a babbling control endpoint | ||
1045 | * is not halted. The 0.96 spec says it is. Some HW | ||
1046 | * claims to be 0.95 compliant, but it halts the control | ||
1047 | * endpoint anyway. Check if a babble halted the | ||
1048 | * endpoint. | ||
1049 | */ | ||
1050 | if (ep_ctx->ep_info != EP_STATE_HALTED) | ||
1051 | break; | ||
1052 | /* else fall through */ | ||
1053 | case COMP_STALL: | ||
1054 | /* Did we transfer part of the data (middle) phase? */ | ||
1055 | if (event_trb != ep_ring->dequeue && | ||
1056 | event_trb != td->last_trb) | ||
1057 | td->urb->actual_length = | ||
1058 | td->urb->transfer_buffer_length | ||
1059 | - TRB_LEN(event->transfer_len); | ||
1060 | else | ||
1061 | td->urb->actual_length = 0; | ||
1062 | |||
1063 | ep->stopped_td = td; | ||
1064 | ep->stopped_trb = event_trb; | ||
1065 | xhci_queue_reset_ep(xhci, slot_id, ep_index); | ||
1066 | xhci_cleanup_stalled_ring(xhci, td->urb->dev, ep_index); | ||
1067 | xhci_ring_cmd_db(xhci); | ||
1068 | goto td_cleanup; | ||
933 | default: | 1069 | default: |
934 | /* Others already handled above */ | 1070 | /* Others already handled above */ |
935 | break; | 1071 | break; |
@@ -943,7 +1079,10 @@ static int handle_tx_event(struct xhci_hcd *xhci, | |||
943 | if (event_trb == td->last_trb) { | 1079 | if (event_trb == td->last_trb) { |
944 | if (td->urb->actual_length != 0) { | 1080 | if (td->urb->actual_length != 0) { |
945 | /* Don't overwrite a previously set error code */ | 1081 | /* Don't overwrite a previously set error code */ |
946 | if (status == -EINPROGRESS || status == 0) | 1082 | if ((status == -EINPROGRESS || |
1083 | status == 0) && | ||
1084 | (td->urb->transfer_flags | ||
1085 | & URB_SHORT_NOT_OK)) | ||
947 | /* Did we already see a short data stage? */ | 1086 | /* Did we already see a short data stage? */ |
948 | status = -EREMOTEIO; | 1087 | status = -EREMOTEIO; |
949 | } else { | 1088 | } else { |
@@ -952,7 +1091,7 @@ static int handle_tx_event(struct xhci_hcd *xhci, | |||
952 | } | 1091 | } |
953 | } else { | 1092 | } else { |
954 | /* Maybe the event was for the data stage? */ | 1093 | /* Maybe the event was for the data stage? */ |
955 | if (GET_COMP_CODE(event->transfer_len) != COMP_STOP_INVAL) { | 1094 | if (trb_comp_code != COMP_STOP_INVAL) { |
956 | /* We didn't stop on a link TRB in the middle */ | 1095 | /* We didn't stop on a link TRB in the middle */ |
957 | td->urb->actual_length = | 1096 | td->urb->actual_length = |
958 | td->urb->transfer_buffer_length - | 1097 | td->urb->transfer_buffer_length - |
@@ -964,7 +1103,7 @@ static int handle_tx_event(struct xhci_hcd *xhci, | |||
964 | } | 1103 | } |
965 | } | 1104 | } |
966 | } else { | 1105 | } else { |
967 | switch (GET_COMP_CODE(event->transfer_len)) { | 1106 | switch (trb_comp_code) { |
968 | case COMP_SUCCESS: | 1107 | case COMP_SUCCESS: |
969 | /* Double check that the HW transferred everything. */ | 1108 | /* Double check that the HW transferred everything. */ |
970 | if (event_trb != td->last_trb) { | 1109 | if (event_trb != td->last_trb) { |
@@ -975,7 +1114,12 @@ static int handle_tx_event(struct xhci_hcd *xhci, | |||
975 | else | 1114 | else |
976 | status = 0; | 1115 | status = 0; |
977 | } else { | 1116 | } else { |
978 | xhci_dbg(xhci, "Successful bulk transfer!\n"); | 1117 | if (usb_endpoint_xfer_bulk(&td->urb->ep->desc)) |
1118 | xhci_dbg(xhci, "Successful bulk " | ||
1119 | "transfer!\n"); | ||
1120 | else | ||
1121 | xhci_dbg(xhci, "Successful interrupt " | ||
1122 | "transfer!\n"); | ||
979 | status = 0; | 1123 | status = 0; |
980 | } | 1124 | } |
981 | break; | 1125 | break; |
@@ -1001,11 +1145,17 @@ static int handle_tx_event(struct xhci_hcd *xhci, | |||
1001 | td->urb->actual_length = | 1145 | td->urb->actual_length = |
1002 | td->urb->transfer_buffer_length - | 1146 | td->urb->transfer_buffer_length - |
1003 | TRB_LEN(event->transfer_len); | 1147 | TRB_LEN(event->transfer_len); |
1004 | if (td->urb->actual_length < 0) { | 1148 | if (td->urb->transfer_buffer_length < |
1149 | td->urb->actual_length) { | ||
1005 | xhci_warn(xhci, "HC gave bad length " | 1150 | xhci_warn(xhci, "HC gave bad length " |
1006 | "of %d bytes left\n", | 1151 | "of %d bytes left\n", |
1007 | TRB_LEN(event->transfer_len)); | 1152 | TRB_LEN(event->transfer_len)); |
1008 | td->urb->actual_length = 0; | 1153 | td->urb->actual_length = 0; |
1154 | if (td->urb->transfer_flags & | ||
1155 | URB_SHORT_NOT_OK) | ||
1156 | status = -EREMOTEIO; | ||
1157 | else | ||
1158 | status = 0; | ||
1009 | } | 1159 | } |
1010 | /* Don't overwrite a previously set error code */ | 1160 | /* Don't overwrite a previously set error code */ |
1011 | if (status == -EINPROGRESS) { | 1161 | if (status == -EINPROGRESS) { |
@@ -1041,30 +1191,31 @@ static int handle_tx_event(struct xhci_hcd *xhci, | |||
1041 | /* If the ring didn't stop on a Link or No-op TRB, add | 1191 | /* If the ring didn't stop on a Link or No-op TRB, add |
1042 | * in the actual bytes transferred from the Normal TRB | 1192 | * in the actual bytes transferred from the Normal TRB |
1043 | */ | 1193 | */ |
1044 | if (GET_COMP_CODE(event->transfer_len) != COMP_STOP_INVAL) | 1194 | if (trb_comp_code != COMP_STOP_INVAL) |
1045 | td->urb->actual_length += | 1195 | td->urb->actual_length += |
1046 | TRB_LEN(cur_trb->generic.field[2]) - | 1196 | TRB_LEN(cur_trb->generic.field[2]) - |
1047 | TRB_LEN(event->transfer_len); | 1197 | TRB_LEN(event->transfer_len); |
1048 | } | 1198 | } |
1049 | } | 1199 | } |
1050 | if (GET_COMP_CODE(event->transfer_len) == COMP_STOP_INVAL || | 1200 | if (trb_comp_code == COMP_STOP_INVAL || |
1051 | GET_COMP_CODE(event->transfer_len) == COMP_STOP) { | 1201 | trb_comp_code == COMP_STOP) { |
1052 | /* The Endpoint Stop Command completion will take care of any | 1202 | /* The Endpoint Stop Command completion will take care of any |
1053 | * stopped TDs. A stopped TD may be restarted, so don't update | 1203 | * stopped TDs. A stopped TD may be restarted, so don't update |
1054 | * the ring dequeue pointer or take this TD off any lists yet. | 1204 | * the ring dequeue pointer or take this TD off any lists yet. |
1055 | */ | 1205 | */ |
1056 | ep_ring->stopped_td = td; | 1206 | ep->stopped_td = td; |
1057 | ep_ring->stopped_trb = event_trb; | 1207 | ep->stopped_trb = event_trb; |
1058 | } else { | 1208 | } else { |
1059 | if (GET_COMP_CODE(event->transfer_len) == COMP_STALL) { | 1209 | if (trb_comp_code == COMP_STALL || |
1210 | trb_comp_code == COMP_BABBLE) { | ||
1060 | /* The transfer is completed from the driver's | 1211 | /* The transfer is completed from the driver's |
1061 | * perspective, but we need to issue a set dequeue | 1212 | * perspective, but we need to issue a set dequeue |
1062 | * command for this stalled endpoint to move the dequeue | 1213 | * command for this stalled endpoint to move the dequeue |
1063 | * pointer past the TD. We can't do that here because | 1214 | * pointer past the TD. We can't do that here because |
1064 | * the halt condition must be cleared first. | 1215 | * the halt condition must be cleared first. |
1065 | */ | 1216 | */ |
1066 | ep_ring->stopped_td = td; | 1217 | ep->stopped_td = td; |
1067 | ep_ring->stopped_trb = event_trb; | 1218 | ep->stopped_trb = event_trb; |
1068 | } else { | 1219 | } else { |
1069 | /* Update ring dequeue pointer */ | 1220 | /* Update ring dequeue pointer */ |
1070 | while (ep_ring->dequeue != td->last_trb) | 1221 | while (ep_ring->dequeue != td->last_trb) |
@@ -1072,16 +1223,41 @@ static int handle_tx_event(struct xhci_hcd *xhci, | |||
1072 | inc_deq(xhci, ep_ring, false); | 1223 | inc_deq(xhci, ep_ring, false); |
1073 | } | 1224 | } |
1074 | 1225 | ||
1226 | td_cleanup: | ||
1075 | /* Clean up the endpoint's TD list */ | 1227 | /* Clean up the endpoint's TD list */ |
1076 | urb = td->urb; | 1228 | urb = td->urb; |
1229 | /* Do one last check of the actual transfer length. | ||
1230 | * If the host controller said we transferred more data than | ||
1231 | * the buffer length, urb->actual_length will be a very big | ||
1232 | * number (since it's unsigned). Play it safe and say we didn't | ||
1233 | * transfer anything. | ||
1234 | */ | ||
1235 | if (urb->actual_length > urb->transfer_buffer_length) { | ||
1236 | xhci_warn(xhci, "URB transfer length is wrong, " | ||
1237 | "xHC issue? req. len = %u, " | ||
1238 | "act. len = %u\n", | ||
1239 | urb->transfer_buffer_length, | ||
1240 | urb->actual_length); | ||
1241 | urb->actual_length = 0; | ||
1242 | if (td->urb->transfer_flags & URB_SHORT_NOT_OK) | ||
1243 | status = -EREMOTEIO; | ||
1244 | else | ||
1245 | status = 0; | ||
1246 | } | ||
1077 | list_del(&td->td_list); | 1247 | list_del(&td->td_list); |
1078 | /* Was this TD slated to be cancelled but completed anyway? */ | 1248 | /* Was this TD slated to be cancelled but completed anyway? */ |
1079 | if (!list_empty(&td->cancelled_td_list)) { | 1249 | if (!list_empty(&td->cancelled_td_list)) { |
1080 | list_del(&td->cancelled_td_list); | 1250 | list_del(&td->cancelled_td_list); |
1081 | ep_ring->cancels_pending--; | 1251 | ep->cancels_pending--; |
1082 | } | 1252 | } |
1083 | /* Leave the TD around for the reset endpoint function to use */ | 1253 | /* Leave the TD around for the reset endpoint function to use |
1084 | if (GET_COMP_CODE(event->transfer_len) != COMP_STALL) { | 1254 | * (but only if it's not a control endpoint, since we already |
1255 | * queued the Set TR dequeue pointer command for stalled | ||
1256 | * control endpoints). | ||
1257 | */ | ||
1258 | if (usb_endpoint_xfer_control(&urb->ep->desc) || | ||
1259 | (trb_comp_code != COMP_STALL && | ||
1260 | trb_comp_code != COMP_BABBLE)) { | ||
1085 | kfree(td); | 1261 | kfree(td); |
1086 | } | 1262 | } |
1087 | urb->hcpriv = NULL; | 1263 | urb->hcpriv = NULL; |
@@ -1094,7 +1270,7 @@ cleanup: | |||
1094 | if (urb) { | 1270 | if (urb) { |
1095 | usb_hcd_unlink_urb_from_ep(xhci_to_hcd(xhci), urb); | 1271 | usb_hcd_unlink_urb_from_ep(xhci_to_hcd(xhci), urb); |
1096 | xhci_dbg(xhci, "Giveback URB %p, len = %d, status = %d\n", | 1272 | xhci_dbg(xhci, "Giveback URB %p, len = %d, status = %d\n", |
1097 | urb, td->urb->actual_length, status); | 1273 | urb, urb->actual_length, status); |
1098 | spin_unlock(&xhci->lock); | 1274 | spin_unlock(&xhci->lock); |
1099 | usb_hcd_giveback_urb(xhci_to_hcd(xhci), urb, status); | 1275 | usb_hcd_giveback_urb(xhci_to_hcd(xhci), urb, status); |
1100 | spin_lock(&xhci->lock); | 1276 | spin_lock(&xhci->lock); |
@@ -1235,7 +1411,7 @@ static int prepare_transfer(struct xhci_hcd *xhci, | |||
1235 | { | 1411 | { |
1236 | int ret; | 1412 | int ret; |
1237 | struct xhci_ep_ctx *ep_ctx = xhci_get_ep_ctx(xhci, xdev->out_ctx, ep_index); | 1413 | struct xhci_ep_ctx *ep_ctx = xhci_get_ep_ctx(xhci, xdev->out_ctx, ep_index); |
1238 | ret = prepare_ring(xhci, xdev->ep_rings[ep_index], | 1414 | ret = prepare_ring(xhci, xdev->eps[ep_index].ring, |
1239 | ep_ctx->ep_info & EP_STATE_MASK, | 1415 | ep_ctx->ep_info & EP_STATE_MASK, |
1240 | num_trbs, mem_flags); | 1416 | num_trbs, mem_flags); |
1241 | if (ret) | 1417 | if (ret) |
@@ -1255,9 +1431,9 @@ static int prepare_transfer(struct xhci_hcd *xhci, | |||
1255 | (*td)->urb = urb; | 1431 | (*td)->urb = urb; |
1256 | urb->hcpriv = (void *) (*td); | 1432 | urb->hcpriv = (void *) (*td); |
1257 | /* Add this TD to the tail of the endpoint ring's TD list */ | 1433 | /* Add this TD to the tail of the endpoint ring's TD list */ |
1258 | list_add_tail(&(*td)->td_list, &xdev->ep_rings[ep_index]->td_list); | 1434 | list_add_tail(&(*td)->td_list, &xdev->eps[ep_index].ring->td_list); |
1259 | (*td)->start_seg = xdev->ep_rings[ep_index]->enq_seg; | 1435 | (*td)->start_seg = xdev->eps[ep_index].ring->enq_seg; |
1260 | (*td)->first_trb = xdev->ep_rings[ep_index]->enqueue; | 1436 | (*td)->first_trb = xdev->eps[ep_index].ring->enqueue; |
1261 | 1437 | ||
1262 | return 0; | 1438 | return 0; |
1263 | } | 1439 | } |
@@ -1335,6 +1511,47 @@ static void giveback_first_trb(struct xhci_hcd *xhci, int slot_id, | |||
1335 | ring_ep_doorbell(xhci, slot_id, ep_index); | 1511 | ring_ep_doorbell(xhci, slot_id, ep_index); |
1336 | } | 1512 | } |
1337 | 1513 | ||
1514 | /* | ||
1515 | * xHCI uses normal TRBs for both bulk and interrupt. When the interrupt | ||
1516 | * endpoint is to be serviced, the xHC will consume (at most) one TD. A TD | ||
1517 | * (comprised of sg list entries) can take several service intervals to | ||
1518 | * transmit. | ||
1519 | */ | ||
1520 | int xhci_queue_intr_tx(struct xhci_hcd *xhci, gfp_t mem_flags, | ||
1521 | struct urb *urb, int slot_id, unsigned int ep_index) | ||
1522 | { | ||
1523 | struct xhci_ep_ctx *ep_ctx = xhci_get_ep_ctx(xhci, | ||
1524 | xhci->devs[slot_id]->out_ctx, ep_index); | ||
1525 | int xhci_interval; | ||
1526 | int ep_interval; | ||
1527 | |||
1528 | xhci_interval = EP_INTERVAL_TO_UFRAMES(ep_ctx->ep_info); | ||
1529 | ep_interval = urb->interval; | ||
1530 | /* Convert to microframes */ | ||
1531 | if (urb->dev->speed == USB_SPEED_LOW || | ||
1532 | urb->dev->speed == USB_SPEED_FULL) | ||
1533 | ep_interval *= 8; | ||
1534 | /* FIXME change this to a warning and a suggestion to use the new API | ||
1535 | * to set the polling interval (once the API is added). | ||
1536 | */ | ||
1537 | if (xhci_interval != ep_interval) { | ||
1538 | if (!printk_ratelimit()) | ||
1539 | dev_dbg(&urb->dev->dev, "Driver uses different interval" | ||
1540 | " (%d microframe%s) than xHCI " | ||
1541 | "(%d microframe%s)\n", | ||
1542 | ep_interval, | ||
1543 | ep_interval == 1 ? "" : "s", | ||
1544 | xhci_interval, | ||
1545 | xhci_interval == 1 ? "" : "s"); | ||
1546 | urb->interval = xhci_interval; | ||
1547 | /* Convert back to frames for LS/FS devices */ | ||
1548 | if (urb->dev->speed == USB_SPEED_LOW || | ||
1549 | urb->dev->speed == USB_SPEED_FULL) | ||
1550 | urb->interval /= 8; | ||
1551 | } | ||
1552 | return xhci_queue_bulk_tx(xhci, GFP_ATOMIC, urb, slot_id, ep_index); | ||
1553 | } | ||
1554 | |||
1338 | static int queue_bulk_sg_tx(struct xhci_hcd *xhci, gfp_t mem_flags, | 1555 | static int queue_bulk_sg_tx(struct xhci_hcd *xhci, gfp_t mem_flags, |
1339 | struct urb *urb, int slot_id, unsigned int ep_index) | 1556 | struct urb *urb, int slot_id, unsigned int ep_index) |
1340 | { | 1557 | { |
@@ -1350,7 +1567,7 @@ static int queue_bulk_sg_tx(struct xhci_hcd *xhci, gfp_t mem_flags, | |||
1350 | struct xhci_generic_trb *start_trb; | 1567 | struct xhci_generic_trb *start_trb; |
1351 | int start_cycle; | 1568 | int start_cycle; |
1352 | 1569 | ||
1353 | ep_ring = xhci->devs[slot_id]->ep_rings[ep_index]; | 1570 | ep_ring = xhci->devs[slot_id]->eps[ep_index].ring; |
1354 | num_trbs = count_sg_trbs_needed(xhci, urb); | 1571 | num_trbs = count_sg_trbs_needed(xhci, urb); |
1355 | num_sgs = urb->num_sgs; | 1572 | num_sgs = urb->num_sgs; |
1356 | 1573 | ||
@@ -1483,7 +1700,7 @@ int xhci_queue_bulk_tx(struct xhci_hcd *xhci, gfp_t mem_flags, | |||
1483 | if (urb->sg) | 1700 | if (urb->sg) |
1484 | return queue_bulk_sg_tx(xhci, mem_flags, urb, slot_id, ep_index); | 1701 | return queue_bulk_sg_tx(xhci, mem_flags, urb, slot_id, ep_index); |
1485 | 1702 | ||
1486 | ep_ring = xhci->devs[slot_id]->ep_rings[ep_index]; | 1703 | ep_ring = xhci->devs[slot_id]->eps[ep_index].ring; |
1487 | 1704 | ||
1488 | num_trbs = 0; | 1705 | num_trbs = 0; |
1489 | /* How much data is (potentially) left before the 64KB boundary? */ | 1706 | /* How much data is (potentially) left before the 64KB boundary? */ |
@@ -1594,7 +1811,7 @@ int xhci_queue_ctrl_tx(struct xhci_hcd *xhci, gfp_t mem_flags, | |||
1594 | u32 field, length_field; | 1811 | u32 field, length_field; |
1595 | struct xhci_td *td; | 1812 | struct xhci_td *td; |
1596 | 1813 | ||
1597 | ep_ring = xhci->devs[slot_id]->ep_rings[ep_index]; | 1814 | ep_ring = xhci->devs[slot_id]->eps[ep_index].ring; |
1598 | 1815 | ||
1599 | /* | 1816 | /* |
1600 | * Need to copy setup packet into setup TRB, so we can't use the setup | 1817 | * Need to copy setup packet into setup TRB, so we can't use the setup |
@@ -1677,12 +1894,27 @@ int xhci_queue_ctrl_tx(struct xhci_hcd *xhci, gfp_t mem_flags, | |||
1677 | 1894 | ||
1678 | /**** Command Ring Operations ****/ | 1895 | /**** Command Ring Operations ****/ |
1679 | 1896 | ||
1680 | /* Generic function for queueing a command TRB on the command ring */ | 1897 | /* Generic function for queueing a command TRB on the command ring. |
1681 | static int queue_command(struct xhci_hcd *xhci, u32 field1, u32 field2, u32 field3, u32 field4) | 1898 | * Check to make sure there's room on the command ring for one command TRB. |
1899 | * Also check that there's room reserved for commands that must not fail. | ||
1900 | * If this is a command that must not fail, meaning command_must_succeed = TRUE, | ||
1901 | * then only check for the number of reserved spots. | ||
1902 | * Don't decrement xhci->cmd_ring_reserved_trbs after we've queued the TRB | ||
1903 | * because the command event handler may want to resubmit a failed command. | ||
1904 | */ | ||
1905 | static int queue_command(struct xhci_hcd *xhci, u32 field1, u32 field2, | ||
1906 | u32 field3, u32 field4, bool command_must_succeed) | ||
1682 | { | 1907 | { |
1683 | if (!room_on_ring(xhci, xhci->cmd_ring, 1)) { | 1908 | int reserved_trbs = xhci->cmd_ring_reserved_trbs; |
1909 | if (!command_must_succeed) | ||
1910 | reserved_trbs++; | ||
1911 | |||
1912 | if (!room_on_ring(xhci, xhci->cmd_ring, reserved_trbs)) { | ||
1684 | if (!in_interrupt()) | 1913 | if (!in_interrupt()) |
1685 | xhci_err(xhci, "ERR: No room for command on command ring\n"); | 1914 | xhci_err(xhci, "ERR: No room for command on command ring\n"); |
1915 | if (command_must_succeed) | ||
1916 | xhci_err(xhci, "ERR: Reserved TRB counting for " | ||
1917 | "unfailable commands failed.\n"); | ||
1686 | return -ENOMEM; | 1918 | return -ENOMEM; |
1687 | } | 1919 | } |
1688 | queue_trb(xhci, xhci->cmd_ring, false, field1, field2, field3, | 1920 | queue_trb(xhci, xhci->cmd_ring, false, field1, field2, field3, |
@@ -1693,7 +1925,7 @@ static int queue_command(struct xhci_hcd *xhci, u32 field1, u32 field2, u32 fiel | |||
1693 | /* Queue a no-op command on the command ring */ | 1925 | /* Queue a no-op command on the command ring */ |
1694 | static int queue_cmd_noop(struct xhci_hcd *xhci) | 1926 | static int queue_cmd_noop(struct xhci_hcd *xhci) |
1695 | { | 1927 | { |
1696 | return queue_command(xhci, 0, 0, 0, TRB_TYPE(TRB_CMD_NOOP)); | 1928 | return queue_command(xhci, 0, 0, 0, TRB_TYPE(TRB_CMD_NOOP), false); |
1697 | } | 1929 | } |
1698 | 1930 | ||
1699 | /* | 1931 | /* |
@@ -1712,7 +1944,7 @@ void *xhci_setup_one_noop(struct xhci_hcd *xhci) | |||
1712 | int xhci_queue_slot_control(struct xhci_hcd *xhci, u32 trb_type, u32 slot_id) | 1944 | int xhci_queue_slot_control(struct xhci_hcd *xhci, u32 trb_type, u32 slot_id) |
1713 | { | 1945 | { |
1714 | return queue_command(xhci, 0, 0, 0, | 1946 | return queue_command(xhci, 0, 0, 0, |
1715 | TRB_TYPE(trb_type) | SLOT_ID_FOR_TRB(slot_id)); | 1947 | TRB_TYPE(trb_type) | SLOT_ID_FOR_TRB(slot_id), false); |
1716 | } | 1948 | } |
1717 | 1949 | ||
1718 | /* Queue an address device command TRB */ | 1950 | /* Queue an address device command TRB */ |
@@ -1721,16 +1953,28 @@ int xhci_queue_address_device(struct xhci_hcd *xhci, dma_addr_t in_ctx_ptr, | |||
1721 | { | 1953 | { |
1722 | return queue_command(xhci, lower_32_bits(in_ctx_ptr), | 1954 | return queue_command(xhci, lower_32_bits(in_ctx_ptr), |
1723 | upper_32_bits(in_ctx_ptr), 0, | 1955 | upper_32_bits(in_ctx_ptr), 0, |
1724 | TRB_TYPE(TRB_ADDR_DEV) | SLOT_ID_FOR_TRB(slot_id)); | 1956 | TRB_TYPE(TRB_ADDR_DEV) | SLOT_ID_FOR_TRB(slot_id), |
1957 | false); | ||
1725 | } | 1958 | } |
1726 | 1959 | ||
1727 | /* Queue a configure endpoint command TRB */ | 1960 | /* Queue a configure endpoint command TRB */ |
1728 | int xhci_queue_configure_endpoint(struct xhci_hcd *xhci, dma_addr_t in_ctx_ptr, | 1961 | int xhci_queue_configure_endpoint(struct xhci_hcd *xhci, dma_addr_t in_ctx_ptr, |
1962 | u32 slot_id, bool command_must_succeed) | ||
1963 | { | ||
1964 | return queue_command(xhci, lower_32_bits(in_ctx_ptr), | ||
1965 | upper_32_bits(in_ctx_ptr), 0, | ||
1966 | TRB_TYPE(TRB_CONFIG_EP) | SLOT_ID_FOR_TRB(slot_id), | ||
1967 | command_must_succeed); | ||
1968 | } | ||
1969 | |||
1970 | /* Queue an evaluate context command TRB */ | ||
1971 | int xhci_queue_evaluate_context(struct xhci_hcd *xhci, dma_addr_t in_ctx_ptr, | ||
1729 | u32 slot_id) | 1972 | u32 slot_id) |
1730 | { | 1973 | { |
1731 | return queue_command(xhci, lower_32_bits(in_ctx_ptr), | 1974 | return queue_command(xhci, lower_32_bits(in_ctx_ptr), |
1732 | upper_32_bits(in_ctx_ptr), 0, | 1975 | upper_32_bits(in_ctx_ptr), 0, |
1733 | TRB_TYPE(TRB_CONFIG_EP) | SLOT_ID_FOR_TRB(slot_id)); | 1976 | TRB_TYPE(TRB_EVAL_CONTEXT) | SLOT_ID_FOR_TRB(slot_id), |
1977 | false); | ||
1734 | } | 1978 | } |
1735 | 1979 | ||
1736 | int xhci_queue_stop_endpoint(struct xhci_hcd *xhci, int slot_id, | 1980 | int xhci_queue_stop_endpoint(struct xhci_hcd *xhci, int slot_id, |
@@ -1741,7 +1985,7 @@ int xhci_queue_stop_endpoint(struct xhci_hcd *xhci, int slot_id, | |||
1741 | u32 type = TRB_TYPE(TRB_STOP_RING); | 1985 | u32 type = TRB_TYPE(TRB_STOP_RING); |
1742 | 1986 | ||
1743 | return queue_command(xhci, 0, 0, 0, | 1987 | return queue_command(xhci, 0, 0, 0, |
1744 | trb_slot_id | trb_ep_index | type); | 1988 | trb_slot_id | trb_ep_index | type, false); |
1745 | } | 1989 | } |
1746 | 1990 | ||
1747 | /* Set Transfer Ring Dequeue Pointer command. | 1991 | /* Set Transfer Ring Dequeue Pointer command. |
@@ -1765,7 +2009,7 @@ static int queue_set_tr_deq(struct xhci_hcd *xhci, int slot_id, | |||
1765 | } | 2009 | } |
1766 | return queue_command(xhci, lower_32_bits(addr) | cycle_state, | 2010 | return queue_command(xhci, lower_32_bits(addr) | cycle_state, |
1767 | upper_32_bits(addr), 0, | 2011 | upper_32_bits(addr), 0, |
1768 | trb_slot_id | trb_ep_index | type); | 2012 | trb_slot_id | trb_ep_index | type, false); |
1769 | } | 2013 | } |
1770 | 2014 | ||
1771 | int xhci_queue_reset_ep(struct xhci_hcd *xhci, int slot_id, | 2015 | int xhci_queue_reset_ep(struct xhci_hcd *xhci, int slot_id, |
@@ -1775,5 +2019,6 @@ int xhci_queue_reset_ep(struct xhci_hcd *xhci, int slot_id, | |||
1775 | u32 trb_ep_index = EP_ID_FOR_TRB(ep_index); | 2019 | u32 trb_ep_index = EP_ID_FOR_TRB(ep_index); |
1776 | u32 type = TRB_TYPE(TRB_RESET_EP); | 2020 | u32 type = TRB_TYPE(TRB_RESET_EP); |
1777 | 2021 | ||
1778 | return queue_command(xhci, 0, 0, 0, trb_slot_id | trb_ep_index | type); | 2022 | return queue_command(xhci, 0, 0, 0, trb_slot_id | trb_ep_index | type, |
2023 | false); | ||
1779 | } | 2024 | } |
diff --git a/drivers/usb/host/xhci.h b/drivers/usb/host/xhci.h index d31d32206ba3..4b254b6fa245 100644 --- a/drivers/usb/host/xhci.h +++ b/drivers/usb/host/xhci.h | |||
@@ -509,6 +509,8 @@ struct xhci_slot_ctx { | |||
509 | #define MAX_EXIT (0xffff) | 509 | #define MAX_EXIT (0xffff) |
510 | /* Root hub port number that is needed to access the USB device */ | 510 | /* Root hub port number that is needed to access the USB device */ |
511 | #define ROOT_HUB_PORT(p) (((p) & 0xff) << 16) | 511 | #define ROOT_HUB_PORT(p) (((p) & 0xff) << 16) |
512 | /* Maximum number of ports under a hub device */ | ||
513 | #define XHCI_MAX_PORTS(p) (((p) & 0xff) << 24) | ||
512 | 514 | ||
513 | /* tt_info bitmasks */ | 515 | /* tt_info bitmasks */ |
514 | /* | 516 | /* |
@@ -522,6 +524,7 @@ struct xhci_slot_ctx { | |||
522 | * '0' if the device is not low or full speed. | 524 | * '0' if the device is not low or full speed. |
523 | */ | 525 | */ |
524 | #define TT_PORT (0xff << 8) | 526 | #define TT_PORT (0xff << 8) |
527 | #define TT_THINK_TIME(p) (((p) & 0x3) << 16) | ||
525 | 528 | ||
526 | /* dev_state bitmasks */ | 529 | /* dev_state bitmasks */ |
527 | /* USB device address - assigned by the HC */ | 530 | /* USB device address - assigned by the HC */ |
@@ -581,6 +584,7 @@ struct xhci_ep_ctx { | |||
581 | /* bit 15 is Linear Stream Array */ | 584 | /* bit 15 is Linear Stream Array */ |
582 | /* Interval - period between requests to an endpoint - 125u increments. */ | 585 | /* Interval - period between requests to an endpoint - 125u increments. */ |
583 | #define EP_INTERVAL(p) ((p & 0xff) << 16) | 586 | #define EP_INTERVAL(p) ((p & 0xff) << 16) |
587 | #define EP_INTERVAL_TO_UFRAMES(p) (1 << (((p) >> 16) & 0xff)) | ||
584 | 588 | ||
585 | /* ep_info2 bitmasks */ | 589 | /* ep_info2 bitmasks */ |
586 | /* | 590 | /* |
@@ -589,6 +593,7 @@ struct xhci_ep_ctx { | |||
589 | */ | 593 | */ |
590 | #define FORCE_EVENT (0x1) | 594 | #define FORCE_EVENT (0x1) |
591 | #define ERROR_COUNT(p) (((p) & 0x3) << 1) | 595 | #define ERROR_COUNT(p) (((p) & 0x3) << 1) |
596 | #define CTX_TO_EP_TYPE(p) (((p) >> 3) & 0x7) | ||
592 | #define EP_TYPE(p) ((p) << 3) | 597 | #define EP_TYPE(p) ((p) << 3) |
593 | #define ISOC_OUT_EP 1 | 598 | #define ISOC_OUT_EP 1 |
594 | #define BULK_OUT_EP 2 | 599 | #define BULK_OUT_EP 2 |
@@ -601,6 +606,8 @@ struct xhci_ep_ctx { | |||
601 | /* bit 7 is Host Initiate Disable - for disabling stream selection */ | 606 | /* bit 7 is Host Initiate Disable - for disabling stream selection */ |
602 | #define MAX_BURST(p) (((p)&0xff) << 8) | 607 | #define MAX_BURST(p) (((p)&0xff) << 8) |
603 | #define MAX_PACKET(p) (((p)&0xffff) << 16) | 608 | #define MAX_PACKET(p) (((p)&0xffff) << 16) |
609 | #define MAX_PACKET_MASK (0xffff << 16) | ||
610 | #define MAX_PACKET_DECODED(p) (((p) >> 16) & 0xffff) | ||
604 | 611 | ||
605 | 612 | ||
606 | /** | 613 | /** |
@@ -616,11 +623,44 @@ struct xhci_input_control_ctx { | |||
616 | u32 rsvd2[6]; | 623 | u32 rsvd2[6]; |
617 | }; | 624 | }; |
618 | 625 | ||
626 | /* Represents everything that is needed to issue a command on the command ring. | ||
627 | * It's useful to pre-allocate these for commands that cannot fail due to | ||
628 | * out-of-memory errors, like freeing streams. | ||
629 | */ | ||
630 | struct xhci_command { | ||
631 | /* Input context for changing device state */ | ||
632 | struct xhci_container_ctx *in_ctx; | ||
633 | u32 status; | ||
634 | /* If completion is null, no one is waiting on this command | ||
635 | * and the structure can be freed after the command completes. | ||
636 | */ | ||
637 | struct completion *completion; | ||
638 | union xhci_trb *command_trb; | ||
639 | struct list_head cmd_list; | ||
640 | }; | ||
641 | |||
619 | /* drop context bitmasks */ | 642 | /* drop context bitmasks */ |
620 | #define DROP_EP(x) (0x1 << x) | 643 | #define DROP_EP(x) (0x1 << x) |
621 | /* add context bitmasks */ | 644 | /* add context bitmasks */ |
622 | #define ADD_EP(x) (0x1 << x) | 645 | #define ADD_EP(x) (0x1 << x) |
623 | 646 | ||
647 | struct xhci_virt_ep { | ||
648 | struct xhci_ring *ring; | ||
649 | /* Temporary storage in case the configure endpoint command fails and we | ||
650 | * have to restore the device state to the previous state | ||
651 | */ | ||
652 | struct xhci_ring *new_ring; | ||
653 | unsigned int ep_state; | ||
654 | #define SET_DEQ_PENDING (1 << 0) | ||
655 | #define EP_HALTED (1 << 1) | ||
656 | /* ---- Related to URB cancellation ---- */ | ||
657 | struct list_head cancelled_td_list; | ||
658 | unsigned int cancels_pending; | ||
659 | /* The TRB that was last reported in a stopped endpoint ring */ | ||
660 | union xhci_trb *stopped_trb; | ||
661 | struct xhci_td *stopped_td; | ||
662 | }; | ||
663 | |||
624 | struct xhci_virt_device { | 664 | struct xhci_virt_device { |
625 | /* | 665 | /* |
626 | * Commands to the hardware are passed an "input context" that | 666 | * Commands to the hardware are passed an "input context" that |
@@ -633,16 +673,11 @@ struct xhci_virt_device { | |||
633 | struct xhci_container_ctx *out_ctx; | 673 | struct xhci_container_ctx *out_ctx; |
634 | /* Used for addressing devices and configuration changes */ | 674 | /* Used for addressing devices and configuration changes */ |
635 | struct xhci_container_ctx *in_ctx; | 675 | struct xhci_container_ctx *in_ctx; |
636 | 676 | struct xhci_virt_ep eps[31]; | |
637 | /* FIXME when stream support is added */ | ||
638 | struct xhci_ring *ep_rings[31]; | ||
639 | /* Temporary storage in case the configure endpoint command fails and we | ||
640 | * have to restore the device state to the previous state | ||
641 | */ | ||
642 | struct xhci_ring *new_ep_rings[31]; | ||
643 | struct completion cmd_completion; | 677 | struct completion cmd_completion; |
644 | /* Status of the last command issued for this device */ | 678 | /* Status of the last command issued for this device */ |
645 | u32 cmd_status; | 679 | u32 cmd_status; |
680 | struct list_head cmd_list; | ||
646 | }; | 681 | }; |
647 | 682 | ||
648 | 683 | ||
@@ -905,6 +940,8 @@ union xhci_trb { | |||
905 | * It must also be greater than 16. | 940 | * It must also be greater than 16. |
906 | */ | 941 | */ |
907 | #define TRBS_PER_SEGMENT 64 | 942 | #define TRBS_PER_SEGMENT 64 |
943 | /* Allow two commands + a link TRB, along with any reserved command TRBs */ | ||
944 | #define MAX_RSVD_CMD_TRBS (TRBS_PER_SEGMENT - 3) | ||
908 | #define SEGMENT_SIZE (TRBS_PER_SEGMENT*16) | 945 | #define SEGMENT_SIZE (TRBS_PER_SEGMENT*16) |
909 | /* TRB buffer pointers can't cross 64KB boundaries */ | 946 | /* TRB buffer pointers can't cross 64KB boundaries */ |
910 | #define TRB_MAX_BUFF_SHIFT 16 | 947 | #define TRB_MAX_BUFF_SHIFT 16 |
@@ -926,6 +963,12 @@ struct xhci_td { | |||
926 | union xhci_trb *last_trb; | 963 | union xhci_trb *last_trb; |
927 | }; | 964 | }; |
928 | 965 | ||
966 | struct xhci_dequeue_state { | ||
967 | struct xhci_segment *new_deq_seg; | ||
968 | union xhci_trb *new_deq_ptr; | ||
969 | int new_cycle_state; | ||
970 | }; | ||
971 | |||
929 | struct xhci_ring { | 972 | struct xhci_ring { |
930 | struct xhci_segment *first_seg; | 973 | struct xhci_segment *first_seg; |
931 | union xhci_trb *enqueue; | 974 | union xhci_trb *enqueue; |
@@ -935,15 +978,6 @@ struct xhci_ring { | |||
935 | struct xhci_segment *deq_seg; | 978 | struct xhci_segment *deq_seg; |
936 | unsigned int deq_updates; | 979 | unsigned int deq_updates; |
937 | struct list_head td_list; | 980 | struct list_head td_list; |
938 | /* ---- Related to URB cancellation ---- */ | ||
939 | struct list_head cancelled_td_list; | ||
940 | unsigned int cancels_pending; | ||
941 | unsigned int state; | ||
942 | #define SET_DEQ_PENDING (1 << 0) | ||
943 | #define EP_HALTED (1 << 1) | ||
944 | /* The TRB that was last reported in a stopped endpoint ring */ | ||
945 | union xhci_trb *stopped_trb; | ||
946 | struct xhci_td *stopped_td; | ||
947 | /* | 981 | /* |
948 | * Write the cycle state into the TRB cycle field to give ownership of | 982 | * Write the cycle state into the TRB cycle field to give ownership of |
949 | * the TRB to the host controller (if we are the producer), or to check | 983 | * the TRB to the host controller (if we are the producer), or to check |
@@ -952,12 +986,6 @@ struct xhci_ring { | |||
952 | u32 cycle_state; | 986 | u32 cycle_state; |
953 | }; | 987 | }; |
954 | 988 | ||
955 | struct xhci_dequeue_state { | ||
956 | struct xhci_segment *new_deq_seg; | ||
957 | union xhci_trb *new_deq_ptr; | ||
958 | int new_cycle_state; | ||
959 | }; | ||
960 | |||
961 | struct xhci_erst_entry { | 989 | struct xhci_erst_entry { |
962 | /* 64-bit event ring segment address */ | 990 | /* 64-bit event ring segment address */ |
963 | u64 seg_addr; | 991 | u64 seg_addr; |
@@ -1034,6 +1062,7 @@ struct xhci_hcd { | |||
1034 | /* data structures */ | 1062 | /* data structures */ |
1035 | struct xhci_device_context_array *dcbaa; | 1063 | struct xhci_device_context_array *dcbaa; |
1036 | struct xhci_ring *cmd_ring; | 1064 | struct xhci_ring *cmd_ring; |
1065 | unsigned int cmd_ring_reserved_trbs; | ||
1037 | struct xhci_ring *event_ring; | 1066 | struct xhci_ring *event_ring; |
1038 | struct xhci_erst erst; | 1067 | struct xhci_erst erst; |
1039 | /* Scratchpad */ | 1068 | /* Scratchpad */ |
@@ -1058,6 +1087,9 @@ struct xhci_hcd { | |||
1058 | int noops_submitted; | 1087 | int noops_submitted; |
1059 | int noops_handled; | 1088 | int noops_handled; |
1060 | int error_bitmask; | 1089 | int error_bitmask; |
1090 | unsigned int quirks; | ||
1091 | #define XHCI_LINK_TRB_QUIRK (1 << 0) | ||
1092 | #define XHCI_RESET_EP_QUIRK (1 << 1) | ||
1061 | }; | 1093 | }; |
1062 | 1094 | ||
1063 | /* For testing purposes */ | 1095 | /* For testing purposes */ |
@@ -1136,6 +1168,13 @@ static inline void xhci_write_64(struct xhci_hcd *xhci, | |||
1136 | writel(val_hi, ptr + 1); | 1168 | writel(val_hi, ptr + 1); |
1137 | } | 1169 | } |
1138 | 1170 | ||
1171 | static inline int xhci_link_trb_quirk(struct xhci_hcd *xhci) | ||
1172 | { | ||
1173 | u32 temp = xhci_readl(xhci, &xhci->cap_regs->hc_capbase); | ||
1174 | return ((HC_VERSION(temp) == 0x95) && | ||
1175 | (xhci->quirks & XHCI_LINK_TRB_QUIRK)); | ||
1176 | } | ||
1177 | |||
1139 | /* xHCI debugging */ | 1178 | /* xHCI debugging */ |
1140 | void xhci_print_ir_set(struct xhci_hcd *xhci, struct xhci_intr_reg *ir_set, int set_num); | 1179 | void xhci_print_ir_set(struct xhci_hcd *xhci, struct xhci_intr_reg *ir_set, int set_num); |
1141 | void xhci_print_registers(struct xhci_hcd *xhci); | 1180 | void xhci_print_registers(struct xhci_hcd *xhci); |
@@ -1150,7 +1189,7 @@ void xhci_dbg_cmd_ptrs(struct xhci_hcd *xhci); | |||
1150 | void xhci_dbg_ring_ptrs(struct xhci_hcd *xhci, struct xhci_ring *ring); | 1189 | void xhci_dbg_ring_ptrs(struct xhci_hcd *xhci, struct xhci_ring *ring); |
1151 | void xhci_dbg_ctx(struct xhci_hcd *xhci, struct xhci_container_ctx *ctx, unsigned int last_ep); | 1190 | void xhci_dbg_ctx(struct xhci_hcd *xhci, struct xhci_container_ctx *ctx, unsigned int last_ep); |
1152 | 1191 | ||
1153 | /* xHCI memory managment */ | 1192 | /* xHCI memory management */ |
1154 | void xhci_mem_cleanup(struct xhci_hcd *xhci); | 1193 | void xhci_mem_cleanup(struct xhci_hcd *xhci); |
1155 | int xhci_mem_init(struct xhci_hcd *xhci, gfp_t flags); | 1194 | int xhci_mem_init(struct xhci_hcd *xhci, gfp_t flags); |
1156 | void xhci_free_virt_device(struct xhci_hcd *xhci, int slot_id); | 1195 | void xhci_free_virt_device(struct xhci_hcd *xhci, int slot_id); |
@@ -1158,11 +1197,24 @@ int xhci_alloc_virt_device(struct xhci_hcd *xhci, int slot_id, struct usb_device | |||
1158 | int xhci_setup_addressable_virt_dev(struct xhci_hcd *xhci, struct usb_device *udev); | 1197 | int xhci_setup_addressable_virt_dev(struct xhci_hcd *xhci, struct usb_device *udev); |
1159 | unsigned int xhci_get_endpoint_index(struct usb_endpoint_descriptor *desc); | 1198 | unsigned int xhci_get_endpoint_index(struct usb_endpoint_descriptor *desc); |
1160 | unsigned int xhci_get_endpoint_flag(struct usb_endpoint_descriptor *desc); | 1199 | unsigned int xhci_get_endpoint_flag(struct usb_endpoint_descriptor *desc); |
1200 | unsigned int xhci_get_endpoint_flag_from_index(unsigned int ep_index); | ||
1201 | unsigned int xhci_last_valid_endpoint(u32 added_ctxs); | ||
1161 | void xhci_endpoint_zero(struct xhci_hcd *xhci, struct xhci_virt_device *virt_dev, struct usb_host_endpoint *ep); | 1202 | void xhci_endpoint_zero(struct xhci_hcd *xhci, struct xhci_virt_device *virt_dev, struct usb_host_endpoint *ep); |
1203 | void xhci_endpoint_copy(struct xhci_hcd *xhci, | ||
1204 | struct xhci_container_ctx *in_ctx, | ||
1205 | struct xhci_container_ctx *out_ctx, | ||
1206 | unsigned int ep_index); | ||
1207 | void xhci_slot_copy(struct xhci_hcd *xhci, | ||
1208 | struct xhci_container_ctx *in_ctx, | ||
1209 | struct xhci_container_ctx *out_ctx); | ||
1162 | int xhci_endpoint_init(struct xhci_hcd *xhci, struct xhci_virt_device *virt_dev, | 1210 | int xhci_endpoint_init(struct xhci_hcd *xhci, struct xhci_virt_device *virt_dev, |
1163 | struct usb_device *udev, struct usb_host_endpoint *ep, | 1211 | struct usb_device *udev, struct usb_host_endpoint *ep, |
1164 | gfp_t mem_flags); | 1212 | gfp_t mem_flags); |
1165 | void xhci_ring_free(struct xhci_hcd *xhci, struct xhci_ring *ring); | 1213 | void xhci_ring_free(struct xhci_hcd *xhci, struct xhci_ring *ring); |
1214 | struct xhci_command *xhci_alloc_command(struct xhci_hcd *xhci, | ||
1215 | bool allocate_completion, gfp_t mem_flags); | ||
1216 | void xhci_free_command(struct xhci_hcd *xhci, | ||
1217 | struct xhci_command *command); | ||
1166 | 1218 | ||
1167 | #ifdef CONFIG_PCI | 1219 | #ifdef CONFIG_PCI |
1168 | /* xHCI PCI glue */ | 1220 | /* xHCI PCI glue */ |
@@ -1182,6 +1234,8 @@ irqreturn_t xhci_irq(struct usb_hcd *hcd); | |||
1182 | int xhci_alloc_dev(struct usb_hcd *hcd, struct usb_device *udev); | 1234 | int xhci_alloc_dev(struct usb_hcd *hcd, struct usb_device *udev); |
1183 | void xhci_free_dev(struct usb_hcd *hcd, struct usb_device *udev); | 1235 | void xhci_free_dev(struct usb_hcd *hcd, struct usb_device *udev); |
1184 | int xhci_address_device(struct usb_hcd *hcd, struct usb_device *udev); | 1236 | int xhci_address_device(struct usb_hcd *hcd, struct usb_device *udev); |
1237 | int xhci_update_hub_device(struct usb_hcd *hcd, struct usb_device *hdev, | ||
1238 | struct usb_tt *tt, gfp_t mem_flags); | ||
1185 | int xhci_urb_enqueue(struct usb_hcd *hcd, struct urb *urb, gfp_t mem_flags); | 1239 | int xhci_urb_enqueue(struct usb_hcd *hcd, struct urb *urb, gfp_t mem_flags); |
1186 | int xhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status); | 1240 | int xhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status); |
1187 | int xhci_add_endpoint(struct usb_hcd *hcd, struct usb_device *udev, struct usb_host_endpoint *ep); | 1241 | int xhci_add_endpoint(struct usb_hcd *hcd, struct usb_device *udev, struct usb_host_endpoint *ep); |
@@ -1205,7 +1259,11 @@ int xhci_queue_ctrl_tx(struct xhci_hcd *xhci, gfp_t mem_flags, struct urb *urb, | |||
1205 | int slot_id, unsigned int ep_index); | 1259 | int slot_id, unsigned int ep_index); |
1206 | int xhci_queue_bulk_tx(struct xhci_hcd *xhci, gfp_t mem_flags, struct urb *urb, | 1260 | int xhci_queue_bulk_tx(struct xhci_hcd *xhci, gfp_t mem_flags, struct urb *urb, |
1207 | int slot_id, unsigned int ep_index); | 1261 | int slot_id, unsigned int ep_index); |
1262 | int xhci_queue_intr_tx(struct xhci_hcd *xhci, gfp_t mem_flags, struct urb *urb, | ||
1263 | int slot_id, unsigned int ep_index); | ||
1208 | int xhci_queue_configure_endpoint(struct xhci_hcd *xhci, dma_addr_t in_ctx_ptr, | 1264 | int xhci_queue_configure_endpoint(struct xhci_hcd *xhci, dma_addr_t in_ctx_ptr, |
1265 | u32 slot_id, bool command_must_succeed); | ||
1266 | int xhci_queue_evaluate_context(struct xhci_hcd *xhci, dma_addr_t in_ctx_ptr, | ||
1209 | u32 slot_id); | 1267 | u32 slot_id); |
1210 | int xhci_queue_reset_ep(struct xhci_hcd *xhci, int slot_id, | 1268 | int xhci_queue_reset_ep(struct xhci_hcd *xhci, int slot_id, |
1211 | unsigned int ep_index); | 1269 | unsigned int ep_index); |
@@ -1213,8 +1271,13 @@ void xhci_find_new_dequeue_state(struct xhci_hcd *xhci, | |||
1213 | unsigned int slot_id, unsigned int ep_index, | 1271 | unsigned int slot_id, unsigned int ep_index, |
1214 | struct xhci_td *cur_td, struct xhci_dequeue_state *state); | 1272 | struct xhci_td *cur_td, struct xhci_dequeue_state *state); |
1215 | void xhci_queue_new_dequeue_state(struct xhci_hcd *xhci, | 1273 | void xhci_queue_new_dequeue_state(struct xhci_hcd *xhci, |
1216 | struct xhci_ring *ep_ring, unsigned int slot_id, | 1274 | unsigned int slot_id, unsigned int ep_index, |
1217 | unsigned int ep_index, struct xhci_dequeue_state *deq_state); | 1275 | struct xhci_dequeue_state *deq_state); |
1276 | void xhci_cleanup_stalled_ring(struct xhci_hcd *xhci, | ||
1277 | struct usb_device *udev, unsigned int ep_index); | ||
1278 | void xhci_queue_config_ep_quirk(struct xhci_hcd *xhci, | ||
1279 | unsigned int slot_id, unsigned int ep_index, | ||
1280 | struct xhci_dequeue_state *deq_state); | ||
1218 | 1281 | ||
1219 | /* xHCI roothub code */ | 1282 | /* xHCI roothub code */ |
1220 | int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue, u16 wIndex, | 1283 | int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue, u16 wIndex, |
diff --git a/drivers/usb/image/microtek.c b/drivers/usb/image/microtek.c index 4541dfcea88f..459a7287fe01 100644 --- a/drivers/usb/image/microtek.c +++ b/drivers/usb/image/microtek.c | |||
@@ -653,33 +653,6 @@ static struct scsi_host_template mts_scsi_host_template = { | |||
653 | .max_sectors= 256, /* 128 K */ | 653 | .max_sectors= 256, /* 128 K */ |
654 | }; | 654 | }; |
655 | 655 | ||
656 | struct vendor_product | ||
657 | { | ||
658 | char* name; | ||
659 | enum | ||
660 | { | ||
661 | mts_sup_unknown=0, | ||
662 | mts_sup_alpha, | ||
663 | mts_sup_full | ||
664 | } | ||
665 | support_status; | ||
666 | } ; | ||
667 | |||
668 | |||
669 | /* These are taken from the msmUSB.inf file on the Windows driver CD */ | ||
670 | static const struct vendor_product mts_supported_products[] = | ||
671 | { | ||
672 | { "Phantom 336CX", mts_sup_unknown}, | ||
673 | { "Phantom 336CX", mts_sup_unknown}, | ||
674 | { "Scanmaker X6", mts_sup_alpha}, | ||
675 | { "Phantom C6", mts_sup_unknown}, | ||
676 | { "Phantom 336CX", mts_sup_unknown}, | ||
677 | { "ScanMaker V6USL", mts_sup_unknown}, | ||
678 | { "ScanMaker V6USL", mts_sup_unknown}, | ||
679 | { "Scanmaker V6UL", mts_sup_unknown}, | ||
680 | { "Scanmaker V6UPL", mts_sup_alpha}, | ||
681 | }; | ||
682 | |||
683 | /* The entries of microtek_table must correspond, line-by-line to | 656 | /* The entries of microtek_table must correspond, line-by-line to |
684 | the entries of mts_supported_products[]. */ | 657 | the entries of mts_supported_products[]. */ |
685 | 658 | ||
@@ -711,7 +684,6 @@ static int mts_usb_probe(struct usb_interface *intf, | |||
711 | int err_retval = -ENOMEM; | 684 | int err_retval = -ENOMEM; |
712 | 685 | ||
713 | struct mts_desc * new_desc; | 686 | struct mts_desc * new_desc; |
714 | struct vendor_product const* p; | ||
715 | struct usb_device *dev = interface_to_usbdev (intf); | 687 | struct usb_device *dev = interface_to_usbdev (intf); |
716 | 688 | ||
717 | /* the current altsetting on the interface we're probing */ | 689 | /* the current altsetting on the interface we're probing */ |
@@ -726,15 +698,6 @@ static int mts_usb_probe(struct usb_interface *intf, | |||
726 | 698 | ||
727 | MTS_DEBUG_GOT_HERE(); | 699 | MTS_DEBUG_GOT_HERE(); |
728 | 700 | ||
729 | p = &mts_supported_products[id - mts_usb_ids]; | ||
730 | |||
731 | MTS_DEBUG_GOT_HERE(); | ||
732 | |||
733 | MTS_DEBUG( "found model %s\n", p->name ); | ||
734 | if ( p->support_status != mts_sup_full ) | ||
735 | MTS_MESSAGE( "model %s is not known to be fully supported, reports welcome!\n", | ||
736 | p->name ); | ||
737 | |||
738 | /* the current altsetting on the interface we're probing */ | 701 | /* the current altsetting on the interface we're probing */ |
739 | altsetting = intf->cur_altsetting; | 702 | altsetting = intf->cur_altsetting; |
740 | 703 | ||
diff --git a/drivers/usb/misc/idmouse.c b/drivers/usb/misc/idmouse.c index 6da8887538c7..1337a9ce80b9 100644 --- a/drivers/usb/misc/idmouse.c +++ b/drivers/usb/misc/idmouse.c | |||
@@ -96,6 +96,8 @@ static int idmouse_probe(struct usb_interface *interface, | |||
96 | const struct usb_device_id *id); | 96 | const struct usb_device_id *id); |
97 | 97 | ||
98 | static void idmouse_disconnect(struct usb_interface *interface); | 98 | static void idmouse_disconnect(struct usb_interface *interface); |
99 | static int idmouse_suspend(struct usb_interface *intf, pm_message_t message); | ||
100 | static int idmouse_resume(struct usb_interface *intf); | ||
99 | 101 | ||
100 | /* file operation pointers */ | 102 | /* file operation pointers */ |
101 | static const struct file_operations idmouse_fops = { | 103 | static const struct file_operations idmouse_fops = { |
@@ -117,7 +119,11 @@ static struct usb_driver idmouse_driver = { | |||
117 | .name = DRIVER_SHORT, | 119 | .name = DRIVER_SHORT, |
118 | .probe = idmouse_probe, | 120 | .probe = idmouse_probe, |
119 | .disconnect = idmouse_disconnect, | 121 | .disconnect = idmouse_disconnect, |
122 | .suspend = idmouse_suspend, | ||
123 | .resume = idmouse_resume, | ||
124 | .reset_resume = idmouse_resume, | ||
120 | .id_table = idmouse_table, | 125 | .id_table = idmouse_table, |
126 | .supports_autosuspend = 1, | ||
121 | }; | 127 | }; |
122 | 128 | ||
123 | static int idmouse_create_image(struct usb_idmouse *dev) | 129 | static int idmouse_create_image(struct usb_idmouse *dev) |
@@ -197,6 +203,17 @@ reset: | |||
197 | return result; | 203 | return result; |
198 | } | 204 | } |
199 | 205 | ||
206 | /* PM operations are nops as this driver does IO only during open() */ | ||
207 | static int idmouse_suspend(struct usb_interface *intf, pm_message_t message) | ||
208 | { | ||
209 | return 0; | ||
210 | } | ||
211 | |||
212 | static int idmouse_resume(struct usb_interface *intf) | ||
213 | { | ||
214 | return 0; | ||
215 | } | ||
216 | |||
200 | static inline void idmouse_delete(struct usb_idmouse *dev) | 217 | static inline void idmouse_delete(struct usb_idmouse *dev) |
201 | { | 218 | { |
202 | kfree(dev->bulk_in_buffer); | 219 | kfree(dev->bulk_in_buffer); |
@@ -235,9 +252,13 @@ static int idmouse_open(struct inode *inode, struct file *file) | |||
235 | } else { | 252 | } else { |
236 | 253 | ||
237 | /* create a new image and check for success */ | 254 | /* create a new image and check for success */ |
255 | result = usb_autopm_get_interface(interface); | ||
256 | if (result) | ||
257 | goto error; | ||
238 | result = idmouse_create_image (dev); | 258 | result = idmouse_create_image (dev); |
239 | if (result) | 259 | if (result) |
240 | goto error; | 260 | goto error; |
261 | usb_autopm_put_interface(interface); | ||
241 | 262 | ||
242 | /* increment our usage count for the driver */ | 263 | /* increment our usage count for the driver */ |
243 | ++dev->open; | 264 | ++dev->open; |
diff --git a/drivers/usb/misc/iowarrior.c b/drivers/usb/misc/iowarrior.c index 90e1a8dedfa9..e75bb87ee92b 100644 --- a/drivers/usb/misc/iowarrior.c +++ b/drivers/usb/misc/iowarrior.c | |||
@@ -727,7 +727,7 @@ static const struct file_operations iowarrior_fops = { | |||
727 | .poll = iowarrior_poll, | 727 | .poll = iowarrior_poll, |
728 | }; | 728 | }; |
729 | 729 | ||
730 | static char *iowarrior_nodename(struct device *dev) | 730 | static char *iowarrior_devnode(struct device *dev, mode_t *mode) |
731 | { | 731 | { |
732 | return kasprintf(GFP_KERNEL, "usb/%s", dev_name(dev)); | 732 | return kasprintf(GFP_KERNEL, "usb/%s", dev_name(dev)); |
733 | } | 733 | } |
@@ -738,7 +738,7 @@ static char *iowarrior_nodename(struct device *dev) | |||
738 | */ | 738 | */ |
739 | static struct usb_class_driver iowarrior_class = { | 739 | static struct usb_class_driver iowarrior_class = { |
740 | .name = "iowarrior%d", | 740 | .name = "iowarrior%d", |
741 | .nodename = iowarrior_nodename, | 741 | .devnode = iowarrior_devnode, |
742 | .fops = &iowarrior_fops, | 742 | .fops = &iowarrior_fops, |
743 | .minor_base = IOWARRIOR_MINOR_BASE, | 743 | .minor_base = IOWARRIOR_MINOR_BASE, |
744 | }; | 744 | }; |
diff --git a/drivers/usb/misc/ldusb.c b/drivers/usb/misc/ldusb.c index ad4fb15b5dcb..90f130126c10 100644 --- a/drivers/usb/misc/ldusb.c +++ b/drivers/usb/misc/ldusb.c | |||
@@ -412,6 +412,9 @@ static unsigned int ld_usb_poll(struct file *file, poll_table *wait) | |||
412 | 412 | ||
413 | dev = file->private_data; | 413 | dev = file->private_data; |
414 | 414 | ||
415 | if (!dev->intf) | ||
416 | return POLLERR | POLLHUP; | ||
417 | |||
415 | poll_wait(file, &dev->read_wait, wait); | 418 | poll_wait(file, &dev->read_wait, wait); |
416 | poll_wait(file, &dev->write_wait, wait); | 419 | poll_wait(file, &dev->write_wait, wait); |
417 | 420 | ||
@@ -767,6 +770,9 @@ static void ld_usb_disconnect(struct usb_interface *intf) | |||
767 | ld_usb_delete(dev); | 770 | ld_usb_delete(dev); |
768 | } else { | 771 | } else { |
769 | dev->intf = NULL; | 772 | dev->intf = NULL; |
773 | /* wake up pollers */ | ||
774 | wake_up_interruptible_all(&dev->read_wait); | ||
775 | wake_up_interruptible_all(&dev->write_wait); | ||
770 | mutex_unlock(&dev->mutex); | 776 | mutex_unlock(&dev->mutex); |
771 | } | 777 | } |
772 | 778 | ||
diff --git a/drivers/usb/misc/legousbtower.c b/drivers/usb/misc/legousbtower.c index c1e2433f640d..faa6d623de78 100644 --- a/drivers/usb/misc/legousbtower.c +++ b/drivers/usb/misc/legousbtower.c | |||
@@ -266,7 +266,7 @@ static const struct file_operations tower_fops = { | |||
266 | .llseek = tower_llseek, | 266 | .llseek = tower_llseek, |
267 | }; | 267 | }; |
268 | 268 | ||
269 | static char *legousbtower_nodename(struct device *dev) | 269 | static char *legousbtower_devnode(struct device *dev, mode_t *mode) |
270 | { | 270 | { |
271 | return kasprintf(GFP_KERNEL, "usb/%s", dev_name(dev)); | 271 | return kasprintf(GFP_KERNEL, "usb/%s", dev_name(dev)); |
272 | } | 272 | } |
@@ -277,7 +277,7 @@ static char *legousbtower_nodename(struct device *dev) | |||
277 | */ | 277 | */ |
278 | static struct usb_class_driver tower_class = { | 278 | static struct usb_class_driver tower_class = { |
279 | .name = "legousbtower%d", | 279 | .name = "legousbtower%d", |
280 | .nodename = legousbtower_nodename, | 280 | .devnode = legousbtower_devnode, |
281 | .fops = &tower_fops, | 281 | .fops = &tower_fops, |
282 | .minor_base = LEGO_USB_TOWER_MINOR_BASE, | 282 | .minor_base = LEGO_USB_TOWER_MINOR_BASE, |
283 | }; | 283 | }; |
@@ -552,6 +552,9 @@ static unsigned int tower_poll (struct file *file, poll_table *wait) | |||
552 | 552 | ||
553 | dev = file->private_data; | 553 | dev = file->private_data; |
554 | 554 | ||
555 | if (!dev->udev) | ||
556 | return POLLERR | POLLHUP; | ||
557 | |||
555 | poll_wait(file, &dev->read_wait, wait); | 558 | poll_wait(file, &dev->read_wait, wait); |
556 | poll_wait(file, &dev->write_wait, wait); | 559 | poll_wait(file, &dev->write_wait, wait); |
557 | 560 | ||
@@ -1025,6 +1028,9 @@ static void tower_disconnect (struct usb_interface *interface) | |||
1025 | tower_delete (dev); | 1028 | tower_delete (dev); |
1026 | } else { | 1029 | } else { |
1027 | dev->udev = NULL; | 1030 | dev->udev = NULL; |
1031 | /* wake up pollers */ | ||
1032 | wake_up_interruptible_all(&dev->read_wait); | ||
1033 | wake_up_interruptible_all(&dev->write_wait); | ||
1028 | mutex_unlock(&dev->lock); | 1034 | mutex_unlock(&dev->lock); |
1029 | } | 1035 | } |
1030 | 1036 | ||
diff --git a/drivers/usb/misc/sisusbvga/sisusb.c b/drivers/usb/misc/sisusbvga/sisusb.c index b4ec716de7da..0025847743f3 100644 --- a/drivers/usb/misc/sisusbvga/sisusb.c +++ b/drivers/usb/misc/sisusbvga/sisusb.c | |||
@@ -79,14 +79,12 @@ sisusb_free_buffers(struct sisusb_usb_data *sisusb) | |||
79 | 79 | ||
80 | for (i = 0; i < NUMOBUFS; i++) { | 80 | for (i = 0; i < NUMOBUFS; i++) { |
81 | if (sisusb->obuf[i]) { | 81 | if (sisusb->obuf[i]) { |
82 | usb_buffer_free(sisusb->sisusb_dev, sisusb->obufsize, | 82 | kfree(sisusb->obuf[i]); |
83 | sisusb->obuf[i], sisusb->transfer_dma_out[i]); | ||
84 | sisusb->obuf[i] = NULL; | 83 | sisusb->obuf[i] = NULL; |
85 | } | 84 | } |
86 | } | 85 | } |
87 | if (sisusb->ibuf) { | 86 | if (sisusb->ibuf) { |
88 | usb_buffer_free(sisusb->sisusb_dev, sisusb->ibufsize, | 87 | kfree(sisusb->ibuf); |
89 | sisusb->ibuf, sisusb->transfer_dma_in); | ||
90 | sisusb->ibuf = NULL; | 88 | sisusb->ibuf = NULL; |
91 | } | 89 | } |
92 | } | 90 | } |
@@ -230,8 +228,7 @@ sisusb_bulk_completeout(struct urb *urb) | |||
230 | 228 | ||
231 | static int | 229 | static int |
232 | sisusb_bulkout_msg(struct sisusb_usb_data *sisusb, int index, unsigned int pipe, void *data, | 230 | sisusb_bulkout_msg(struct sisusb_usb_data *sisusb, int index, unsigned int pipe, void *data, |
233 | int len, int *actual_length, int timeout, unsigned int tflags, | 231 | int len, int *actual_length, int timeout, unsigned int tflags) |
234 | dma_addr_t transfer_dma) | ||
235 | { | 232 | { |
236 | struct urb *urb = sisusb->sisurbout[index]; | 233 | struct urb *urb = sisusb->sisurbout[index]; |
237 | int retval, byteswritten = 0; | 234 | int retval, byteswritten = 0; |
@@ -245,9 +242,6 @@ sisusb_bulkout_msg(struct sisusb_usb_data *sisusb, int index, unsigned int pipe, | |||
245 | urb->transfer_flags |= tflags; | 242 | urb->transfer_flags |= tflags; |
246 | urb->actual_length = 0; | 243 | urb->actual_length = 0; |
247 | 244 | ||
248 | if ((urb->transfer_dma = transfer_dma)) | ||
249 | urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; | ||
250 | |||
251 | /* Set up context */ | 245 | /* Set up context */ |
252 | sisusb->urbout_context[index].actual_length = (timeout) ? | 246 | sisusb->urbout_context[index].actual_length = (timeout) ? |
253 | NULL : actual_length; | 247 | NULL : actual_length; |
@@ -297,8 +291,8 @@ sisusb_bulk_completein(struct urb *urb) | |||
297 | } | 291 | } |
298 | 292 | ||
299 | static int | 293 | static int |
300 | sisusb_bulkin_msg(struct sisusb_usb_data *sisusb, unsigned int pipe, void *data, int len, | 294 | sisusb_bulkin_msg(struct sisusb_usb_data *sisusb, unsigned int pipe, void *data, |
301 | int *actual_length, int timeout, unsigned int tflags, dma_addr_t transfer_dma) | 295 | int len, int *actual_length, int timeout, unsigned int tflags) |
302 | { | 296 | { |
303 | struct urb *urb = sisusb->sisurbin; | 297 | struct urb *urb = sisusb->sisurbin; |
304 | int retval, readbytes = 0; | 298 | int retval, readbytes = 0; |
@@ -311,9 +305,6 @@ sisusb_bulkin_msg(struct sisusb_usb_data *sisusb, unsigned int pipe, void *data, | |||
311 | urb->transfer_flags |= tflags; | 305 | urb->transfer_flags |= tflags; |
312 | urb->actual_length = 0; | 306 | urb->actual_length = 0; |
313 | 307 | ||
314 | if ((urb->transfer_dma = transfer_dma)) | ||
315 | urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; | ||
316 | |||
317 | sisusb->completein = 0; | 308 | sisusb->completein = 0; |
318 | retval = usb_submit_urb(urb, GFP_ATOMIC); | 309 | retval = usb_submit_urb(urb, GFP_ATOMIC); |
319 | if (retval == 0) { | 310 | if (retval == 0) { |
@@ -422,8 +413,7 @@ static int sisusb_send_bulk_msg(struct sisusb_usb_data *sisusb, int ep, int len, | |||
422 | thispass, | 413 | thispass, |
423 | &transferred_len, | 414 | &transferred_len, |
424 | async ? 0 : 5 * HZ, | 415 | async ? 0 : 5 * HZ, |
425 | tflags, | 416 | tflags); |
426 | sisusb->transfer_dma_out[index]); | ||
427 | 417 | ||
428 | if (result == -ETIMEDOUT) { | 418 | if (result == -ETIMEDOUT) { |
429 | 419 | ||
@@ -432,29 +422,16 @@ static int sisusb_send_bulk_msg(struct sisusb_usb_data *sisusb, int ep, int len, | |||
432 | return -ETIME; | 422 | return -ETIME; |
433 | 423 | ||
434 | continue; | 424 | continue; |
425 | } | ||
435 | 426 | ||
436 | } else if ((result == 0) && !async && transferred_len) { | 427 | if ((result == 0) && !async && transferred_len) { |
437 | 428 | ||
438 | thispass -= transferred_len; | 429 | thispass -= transferred_len; |
439 | if (thispass) { | 430 | buffer += transferred_len; |
440 | if (sisusb->transfer_dma_out) { | ||
441 | /* If DMA, copy remaining | ||
442 | * to beginning of buffer | ||
443 | */ | ||
444 | memcpy(buffer, | ||
445 | buffer + transferred_len, | ||
446 | thispass); | ||
447 | } else { | ||
448 | /* If not DMA, simply increase | ||
449 | * the pointer | ||
450 | */ | ||
451 | buffer += transferred_len; | ||
452 | } | ||
453 | } | ||
454 | 431 | ||
455 | } else | 432 | } else |
456 | break; | 433 | break; |
457 | }; | 434 | } |
458 | 435 | ||
459 | if (result) | 436 | if (result) |
460 | return result; | 437 | return result; |
@@ -530,8 +507,7 @@ static int sisusb_recv_bulk_msg(struct sisusb_usb_data *sisusb, int ep, int len, | |||
530 | thispass, | 507 | thispass, |
531 | &transferred_len, | 508 | &transferred_len, |
532 | 5 * HZ, | 509 | 5 * HZ, |
533 | tflags, | 510 | tflags); |
534 | sisusb->transfer_dma_in); | ||
535 | 511 | ||
536 | if (transferred_len) | 512 | if (transferred_len) |
537 | thispass = transferred_len; | 513 | thispass = transferred_len; |
@@ -3132,8 +3108,7 @@ static int sisusb_probe(struct usb_interface *intf, | |||
3132 | 3108 | ||
3133 | /* Allocate buffers */ | 3109 | /* Allocate buffers */ |
3134 | sisusb->ibufsize = SISUSB_IBUF_SIZE; | 3110 | sisusb->ibufsize = SISUSB_IBUF_SIZE; |
3135 | if (!(sisusb->ibuf = usb_buffer_alloc(dev, SISUSB_IBUF_SIZE, | 3111 | if (!(sisusb->ibuf = kmalloc(SISUSB_IBUF_SIZE, GFP_KERNEL))) { |
3136 | GFP_KERNEL, &sisusb->transfer_dma_in))) { | ||
3137 | dev_err(&sisusb->sisusb_dev->dev, "Failed to allocate memory for input buffer"); | 3112 | dev_err(&sisusb->sisusb_dev->dev, "Failed to allocate memory for input buffer"); |
3138 | retval = -ENOMEM; | 3113 | retval = -ENOMEM; |
3139 | goto error_2; | 3114 | goto error_2; |
@@ -3142,9 +3117,7 @@ static int sisusb_probe(struct usb_interface *intf, | |||
3142 | sisusb->numobufs = 0; | 3117 | sisusb->numobufs = 0; |
3143 | sisusb->obufsize = SISUSB_OBUF_SIZE; | 3118 | sisusb->obufsize = SISUSB_OBUF_SIZE; |
3144 | for (i = 0; i < NUMOBUFS; i++) { | 3119 | for (i = 0; i < NUMOBUFS; i++) { |
3145 | if (!(sisusb->obuf[i] = usb_buffer_alloc(dev, SISUSB_OBUF_SIZE, | 3120 | if (!(sisusb->obuf[i] = kmalloc(SISUSB_OBUF_SIZE, GFP_KERNEL))) { |
3146 | GFP_KERNEL, | ||
3147 | &sisusb->transfer_dma_out[i]))) { | ||
3148 | if (i == 0) { | 3121 | if (i == 0) { |
3149 | dev_err(&sisusb->sisusb_dev->dev, "Failed to allocate memory for output buffer\n"); | 3122 | dev_err(&sisusb->sisusb_dev->dev, "Failed to allocate memory for output buffer\n"); |
3150 | retval = -ENOMEM; | 3123 | retval = -ENOMEM; |
diff --git a/drivers/usb/misc/sisusbvga/sisusb.h b/drivers/usb/misc/sisusbvga/sisusb.h index cf0b4a5883f6..55492a5930bd 100644 --- a/drivers/usb/misc/sisusbvga/sisusb.h +++ b/drivers/usb/misc/sisusbvga/sisusb.h | |||
@@ -123,8 +123,6 @@ struct sisusb_usb_data { | |||
123 | int numobufs; /* number of obufs = number of out urbs */ | 123 | int numobufs; /* number of obufs = number of out urbs */ |
124 | char *obuf[NUMOBUFS], *ibuf; /* transfer buffers */ | 124 | char *obuf[NUMOBUFS], *ibuf; /* transfer buffers */ |
125 | int obufsize, ibufsize; | 125 | int obufsize, ibufsize; |
126 | dma_addr_t transfer_dma_out[NUMOBUFS]; | ||
127 | dma_addr_t transfer_dma_in; | ||
128 | struct urb *sisurbout[NUMOBUFS]; | 126 | struct urb *sisurbout[NUMOBUFS]; |
129 | struct urb *sisurbin; | 127 | struct urb *sisurbin; |
130 | unsigned char urbstatus[NUMOBUFS]; | 128 | unsigned char urbstatus[NUMOBUFS]; |
diff --git a/drivers/usb/misc/usbsevseg.c b/drivers/usb/misc/usbsevseg.c index 28a6a3a09538..3db255537e79 100644 --- a/drivers/usb/misc/usbsevseg.c +++ b/drivers/usb/misc/usbsevseg.c | |||
@@ -38,6 +38,7 @@ static char *display_textmodes[] = {"raw", "hex", "ascii", NULL}; | |||
38 | 38 | ||
39 | struct usb_sevsegdev { | 39 | struct usb_sevsegdev { |
40 | struct usb_device *udev; | 40 | struct usb_device *udev; |
41 | struct usb_interface *intf; | ||
41 | 42 | ||
42 | u8 powered; | 43 | u8 powered; |
43 | u8 mode_msb; | 44 | u8 mode_msb; |
@@ -46,6 +47,8 @@ struct usb_sevsegdev { | |||
46 | u8 textmode; | 47 | u8 textmode; |
47 | u8 text[MAXLEN]; | 48 | u8 text[MAXLEN]; |
48 | u16 textlength; | 49 | u16 textlength; |
50 | |||
51 | u8 shadow_power; /* for PM */ | ||
49 | }; | 52 | }; |
50 | 53 | ||
51 | /* sysfs_streq can't replace this completely | 54 | /* sysfs_streq can't replace this completely |
@@ -65,6 +68,12 @@ static void update_display_powered(struct usb_sevsegdev *mydev) | |||
65 | { | 68 | { |
66 | int rc; | 69 | int rc; |
67 | 70 | ||
71 | if (!mydev->shadow_power && mydev->powered) { | ||
72 | rc = usb_autopm_get_interface(mydev->intf); | ||
73 | if (rc < 0) | ||
74 | return; | ||
75 | } | ||
76 | |||
68 | rc = usb_control_msg(mydev->udev, | 77 | rc = usb_control_msg(mydev->udev, |
69 | usb_sndctrlpipe(mydev->udev, 0), | 78 | usb_sndctrlpipe(mydev->udev, 0), |
70 | 0x12, | 79 | 0x12, |
@@ -76,12 +85,18 @@ static void update_display_powered(struct usb_sevsegdev *mydev) | |||
76 | 2000); | 85 | 2000); |
77 | if (rc < 0) | 86 | if (rc < 0) |
78 | dev_dbg(&mydev->udev->dev, "power retval = %d\n", rc); | 87 | dev_dbg(&mydev->udev->dev, "power retval = %d\n", rc); |
88 | |||
89 | if (mydev->shadow_power && !mydev->powered) | ||
90 | usb_autopm_put_interface(mydev->intf); | ||
79 | } | 91 | } |
80 | 92 | ||
81 | static void update_display_mode(struct usb_sevsegdev *mydev) | 93 | static void update_display_mode(struct usb_sevsegdev *mydev) |
82 | { | 94 | { |
83 | int rc; | 95 | int rc; |
84 | 96 | ||
97 | if(mydev->shadow_power != 1) | ||
98 | return; | ||
99 | |||
85 | rc = usb_control_msg(mydev->udev, | 100 | rc = usb_control_msg(mydev->udev, |
86 | usb_sndctrlpipe(mydev->udev, 0), | 101 | usb_sndctrlpipe(mydev->udev, 0), |
87 | 0x12, | 102 | 0x12, |
@@ -96,14 +111,17 @@ static void update_display_mode(struct usb_sevsegdev *mydev) | |||
96 | dev_dbg(&mydev->udev->dev, "mode retval = %d\n", rc); | 111 | dev_dbg(&mydev->udev->dev, "mode retval = %d\n", rc); |
97 | } | 112 | } |
98 | 113 | ||
99 | static void update_display_visual(struct usb_sevsegdev *mydev) | 114 | static void update_display_visual(struct usb_sevsegdev *mydev, gfp_t mf) |
100 | { | 115 | { |
101 | int rc; | 116 | int rc; |
102 | int i; | 117 | int i; |
103 | unsigned char *buffer; | 118 | unsigned char *buffer; |
104 | u8 decimals = 0; | 119 | u8 decimals = 0; |
105 | 120 | ||
106 | buffer = kzalloc(MAXLEN, GFP_KERNEL); | 121 | if(mydev->shadow_power != 1) |
122 | return; | ||
123 | |||
124 | buffer = kzalloc(MAXLEN, mf); | ||
107 | if (!buffer) { | 125 | if (!buffer) { |
108 | dev_err(&mydev->udev->dev, "out of memory\n"); | 126 | dev_err(&mydev->udev->dev, "out of memory\n"); |
109 | return; | 127 | return; |
@@ -163,7 +181,7 @@ static ssize_t set_attr_##name(struct device *dev, \ | |||
163 | struct usb_sevsegdev *mydev = usb_get_intfdata(intf); \ | 181 | struct usb_sevsegdev *mydev = usb_get_intfdata(intf); \ |
164 | \ | 182 | \ |
165 | mydev->name = simple_strtoul(buf, NULL, 10); \ | 183 | mydev->name = simple_strtoul(buf, NULL, 10); \ |
166 | update_fcn(mydev); \ | 184 | update_fcn(mydev); \ |
167 | \ | 185 | \ |
168 | return count; \ | 186 | return count; \ |
169 | } \ | 187 | } \ |
@@ -194,7 +212,7 @@ static ssize_t set_attr_text(struct device *dev, | |||
194 | if (end > 0) | 212 | if (end > 0) |
195 | memcpy(mydev->text, buf, end); | 213 | memcpy(mydev->text, buf, end); |
196 | 214 | ||
197 | update_display_visual(mydev); | 215 | update_display_visual(mydev, GFP_KERNEL); |
198 | return count; | 216 | return count; |
199 | } | 217 | } |
200 | 218 | ||
@@ -242,7 +260,7 @@ static ssize_t set_attr_decimals(struct device *dev, | |||
242 | if (buf[i] == '1') | 260 | if (buf[i] == '1') |
243 | mydev->decimals[end-1-i] = 1; | 261 | mydev->decimals[end-1-i] = 1; |
244 | 262 | ||
245 | update_display_visual(mydev); | 263 | update_display_visual(mydev, GFP_KERNEL); |
246 | 264 | ||
247 | return count; | 265 | return count; |
248 | } | 266 | } |
@@ -286,7 +304,7 @@ static ssize_t set_attr_textmode(struct device *dev, | |||
286 | for (i = 0; display_textmodes[i]; i++) { | 304 | for (i = 0; display_textmodes[i]; i++) { |
287 | if (sysfs_streq(display_textmodes[i], buf)) { | 305 | if (sysfs_streq(display_textmodes[i], buf)) { |
288 | mydev->textmode = i; | 306 | mydev->textmode = i; |
289 | update_display_visual(mydev); | 307 | update_display_visual(mydev, GFP_KERNEL); |
290 | return count; | 308 | return count; |
291 | } | 309 | } |
292 | } | 310 | } |
@@ -330,6 +348,7 @@ static int sevseg_probe(struct usb_interface *interface, | |||
330 | } | 348 | } |
331 | 349 | ||
332 | mydev->udev = usb_get_dev(udev); | 350 | mydev->udev = usb_get_dev(udev); |
351 | mydev->intf = interface; | ||
333 | usb_set_intfdata(interface, mydev); | 352 | usb_set_intfdata(interface, mydev); |
334 | 353 | ||
335 | /*set defaults */ | 354 | /*set defaults */ |
@@ -364,11 +383,49 @@ static void sevseg_disconnect(struct usb_interface *interface) | |||
364 | dev_info(&interface->dev, "USB 7 Segment now disconnected\n"); | 383 | dev_info(&interface->dev, "USB 7 Segment now disconnected\n"); |
365 | } | 384 | } |
366 | 385 | ||
386 | static int sevseg_suspend(struct usb_interface *intf, pm_message_t message) | ||
387 | { | ||
388 | struct usb_sevsegdev *mydev; | ||
389 | |||
390 | mydev = usb_get_intfdata(intf); | ||
391 | mydev->shadow_power = 0; | ||
392 | |||
393 | return 0; | ||
394 | } | ||
395 | |||
396 | static int sevseg_resume(struct usb_interface *intf) | ||
397 | { | ||
398 | struct usb_sevsegdev *mydev; | ||
399 | |||
400 | mydev = usb_get_intfdata(intf); | ||
401 | mydev->shadow_power = 1; | ||
402 | update_display_mode(mydev); | ||
403 | update_display_visual(mydev, GFP_NOIO); | ||
404 | |||
405 | return 0; | ||
406 | } | ||
407 | |||
408 | static int sevseg_reset_resume(struct usb_interface *intf) | ||
409 | { | ||
410 | struct usb_sevsegdev *mydev; | ||
411 | |||
412 | mydev = usb_get_intfdata(intf); | ||
413 | mydev->shadow_power = 1; | ||
414 | update_display_mode(mydev); | ||
415 | update_display_visual(mydev, GFP_NOIO); | ||
416 | |||
417 | return 0; | ||
418 | } | ||
419 | |||
367 | static struct usb_driver sevseg_driver = { | 420 | static struct usb_driver sevseg_driver = { |
368 | .name = "usbsevseg", | 421 | .name = "usbsevseg", |
369 | .probe = sevseg_probe, | 422 | .probe = sevseg_probe, |
370 | .disconnect = sevseg_disconnect, | 423 | .disconnect = sevseg_disconnect, |
424 | .suspend = sevseg_suspend, | ||
425 | .resume = sevseg_resume, | ||
426 | .reset_resume = sevseg_reset_resume, | ||
371 | .id_table = id_table, | 427 | .id_table = id_table, |
428 | .supports_autosuspend = 1, | ||
372 | }; | 429 | }; |
373 | 430 | ||
374 | static int __init usb_sevseg_init(void) | 431 | static int __init usb_sevseg_init(void) |
diff --git a/drivers/usb/mon/Kconfig b/drivers/usb/mon/Kconfig index f28f350cd96a..635745f57fbd 100644 --- a/drivers/usb/mon/Kconfig +++ b/drivers/usb/mon/Kconfig | |||
@@ -5,11 +5,9 @@ | |||
5 | config USB_MON | 5 | config USB_MON |
6 | tristate "USB Monitor" | 6 | tristate "USB Monitor" |
7 | depends on USB | 7 | depends on USB |
8 | default y if USB=y | ||
9 | default m if USB=m | ||
10 | help | 8 | help |
11 | If you select this option, a component which captures the USB traffic | 9 | If you select this option, a component which captures the USB traffic |
12 | between peripheral-specific drivers and HC drivers will be built. | 10 | between peripheral-specific drivers and HC drivers will be built. |
13 | For more information, see <file:Documentation/usb/usbmon.txt>. | 11 | For more information, see <file:Documentation/usb/usbmon.txt>. |
14 | 12 | ||
15 | If unsure, say Y (if allowed), otherwise M. | 13 | If unsure, say Y, if allowed, otherwise M. |
diff --git a/drivers/usb/mon/Makefile b/drivers/usb/mon/Makefile index c6516b566731..384b198faa7c 100644 --- a/drivers/usb/mon/Makefile +++ b/drivers/usb/mon/Makefile | |||
@@ -2,6 +2,6 @@ | |||
2 | # Makefile for USB monitor | 2 | # Makefile for USB monitor |
3 | # | 3 | # |
4 | 4 | ||
5 | usbmon-objs := mon_main.o mon_stat.o mon_text.o mon_bin.o mon_dma.o | 5 | usbmon-objs := mon_main.o mon_stat.o mon_text.o mon_bin.o |
6 | 6 | ||
7 | obj-$(CONFIG_USB_MON) += usbmon.o | 7 | obj-$(CONFIG_USB_MON) += usbmon.o |
diff --git a/drivers/usb/mon/mon_bin.c b/drivers/usb/mon/mon_bin.c index 0f7a30b7d2d1..dfdc43e2e00d 100644 --- a/drivers/usb/mon/mon_bin.c +++ b/drivers/usb/mon/mon_bin.c | |||
@@ -220,9 +220,8 @@ static void mon_free_buff(struct mon_pgmap *map, int npages); | |||
220 | 220 | ||
221 | /* | 221 | /* |
222 | * This is a "chunked memcpy". It does not manipulate any counters. | 222 | * This is a "chunked memcpy". It does not manipulate any counters. |
223 | * But it returns the new offset for repeated application. | ||
224 | */ | 223 | */ |
225 | unsigned int mon_copy_to_buff(const struct mon_reader_bin *this, | 224 | static void mon_copy_to_buff(const struct mon_reader_bin *this, |
226 | unsigned int off, const unsigned char *from, unsigned int length) | 225 | unsigned int off, const unsigned char *from, unsigned int length) |
227 | { | 226 | { |
228 | unsigned int step_len; | 227 | unsigned int step_len; |
@@ -247,7 +246,6 @@ unsigned int mon_copy_to_buff(const struct mon_reader_bin *this, | |||
247 | from += step_len; | 246 | from += step_len; |
248 | length -= step_len; | 247 | length -= step_len; |
249 | } | 248 | } |
250 | return off; | ||
251 | } | 249 | } |
252 | 250 | ||
253 | /* | 251 | /* |
@@ -400,15 +398,8 @@ static char mon_bin_get_data(const struct mon_reader_bin *rp, | |||
400 | unsigned int offset, struct urb *urb, unsigned int length) | 398 | unsigned int offset, struct urb *urb, unsigned int length) |
401 | { | 399 | { |
402 | 400 | ||
403 | if (urb->dev->bus->uses_dma && | ||
404 | (urb->transfer_flags & URB_NO_TRANSFER_DMA_MAP)) { | ||
405 | mon_dmapeek_vec(rp, offset, urb->transfer_dma, length); | ||
406 | return 0; | ||
407 | } | ||
408 | |||
409 | if (urb->transfer_buffer == NULL) | 401 | if (urb->transfer_buffer == NULL) |
410 | return 'Z'; | 402 | return 'Z'; |
411 | |||
412 | mon_copy_to_buff(rp, offset, urb->transfer_buffer, length); | 403 | mon_copy_to_buff(rp, offset, urb->transfer_buffer, length); |
413 | return 0; | 404 | return 0; |
414 | } | 405 | } |
@@ -635,7 +626,6 @@ static int mon_bin_open(struct inode *inode, struct file *file) | |||
635 | spin_lock_init(&rp->b_lock); | 626 | spin_lock_init(&rp->b_lock); |
636 | init_waitqueue_head(&rp->b_wait); | 627 | init_waitqueue_head(&rp->b_wait); |
637 | mutex_init(&rp->fetch_lock); | 628 | mutex_init(&rp->fetch_lock); |
638 | |||
639 | rp->b_size = BUFF_DFL; | 629 | rp->b_size = BUFF_DFL; |
640 | 630 | ||
641 | size = sizeof(struct mon_pgmap) * (rp->b_size/CHUNK_SIZE); | 631 | size = sizeof(struct mon_pgmap) * (rp->b_size/CHUNK_SIZE); |
diff --git a/drivers/usb/mon/mon_dma.c b/drivers/usb/mon/mon_dma.c deleted file mode 100644 index 140cc80bd2b1..000000000000 --- a/drivers/usb/mon/mon_dma.c +++ /dev/null | |||
@@ -1,95 +0,0 @@ | |||
1 | /* | ||
2 | * The USB Monitor, inspired by Dave Harding's USBMon. | ||
3 | * | ||
4 | * mon_dma.c: Library which snoops on DMA areas. | ||
5 | * | ||
6 | * Copyright (C) 2005 Pete Zaitcev (zaitcev@redhat.com) | ||
7 | */ | ||
8 | #include <linux/kernel.h> | ||
9 | #include <linux/list.h> | ||
10 | #include <linux/highmem.h> | ||
11 | #include <asm/page.h> | ||
12 | |||
13 | #include <linux/usb.h> /* Only needed for declarations in usb_mon.h */ | ||
14 | #include "usb_mon.h" | ||
15 | |||
16 | /* | ||
17 | * PC-compatibles, are, fortunately, sufficiently cache-coherent for this. | ||
18 | */ | ||
19 | #if defined(__i386__) || defined(__x86_64__) /* CONFIG_ARCH_I386 doesn't exit */ | ||
20 | #define MON_HAS_UNMAP 1 | ||
21 | |||
22 | #define phys_to_page(phys) pfn_to_page((phys) >> PAGE_SHIFT) | ||
23 | |||
24 | char mon_dmapeek(unsigned char *dst, dma_addr_t dma_addr, int len) | ||
25 | { | ||
26 | struct page *pg; | ||
27 | unsigned long flags; | ||
28 | unsigned char *map; | ||
29 | unsigned char *ptr; | ||
30 | |||
31 | /* | ||
32 | * On i386, a DMA handle is the "physical" address of a page. | ||
33 | * In other words, the bus address is equal to physical address. | ||
34 | * There is no IOMMU. | ||
35 | */ | ||
36 | pg = phys_to_page(dma_addr); | ||
37 | |||
38 | /* | ||
39 | * We are called from hardware IRQs in case of callbacks. | ||
40 | * But we can be called from softirq or process context in case | ||
41 | * of submissions. In such case, we need to protect KM_IRQ0. | ||
42 | */ | ||
43 | local_irq_save(flags); | ||
44 | map = kmap_atomic(pg, KM_IRQ0); | ||
45 | ptr = map + (dma_addr & (PAGE_SIZE-1)); | ||
46 | memcpy(dst, ptr, len); | ||
47 | kunmap_atomic(map, KM_IRQ0); | ||
48 | local_irq_restore(flags); | ||
49 | return 0; | ||
50 | } | ||
51 | |||
52 | void mon_dmapeek_vec(const struct mon_reader_bin *rp, | ||
53 | unsigned int offset, dma_addr_t dma_addr, unsigned int length) | ||
54 | { | ||
55 | unsigned long flags; | ||
56 | unsigned int step_len; | ||
57 | struct page *pg; | ||
58 | unsigned char *map; | ||
59 | unsigned long page_off, page_len; | ||
60 | |||
61 | local_irq_save(flags); | ||
62 | while (length) { | ||
63 | /* compute number of bytes we are going to copy in this page */ | ||
64 | step_len = length; | ||
65 | page_off = dma_addr & (PAGE_SIZE-1); | ||
66 | page_len = PAGE_SIZE - page_off; | ||
67 | if (page_len < step_len) | ||
68 | step_len = page_len; | ||
69 | |||
70 | /* copy data and advance pointers */ | ||
71 | pg = phys_to_page(dma_addr); | ||
72 | map = kmap_atomic(pg, KM_IRQ0); | ||
73 | offset = mon_copy_to_buff(rp, offset, map + page_off, step_len); | ||
74 | kunmap_atomic(map, KM_IRQ0); | ||
75 | dma_addr += step_len; | ||
76 | length -= step_len; | ||
77 | } | ||
78 | local_irq_restore(flags); | ||
79 | } | ||
80 | |||
81 | #endif /* __i386__ */ | ||
82 | |||
83 | #ifndef MON_HAS_UNMAP | ||
84 | char mon_dmapeek(unsigned char *dst, dma_addr_t dma_addr, int len) | ||
85 | { | ||
86 | return 'D'; | ||
87 | } | ||
88 | |||
89 | void mon_dmapeek_vec(const struct mon_reader_bin *rp, | ||
90 | unsigned int offset, dma_addr_t dma_addr, unsigned int length) | ||
91 | { | ||
92 | ; | ||
93 | } | ||
94 | |||
95 | #endif /* MON_HAS_UNMAP */ | ||
diff --git a/drivers/usb/mon/mon_main.c b/drivers/usb/mon/mon_main.c index 5e0ab4201c00..e0c2db3b767b 100644 --- a/drivers/usb/mon/mon_main.c +++ b/drivers/usb/mon/mon_main.c | |||
@@ -361,7 +361,6 @@ static int __init mon_init(void) | |||
361 | } | 361 | } |
362 | // MOD_INC_USE_COUNT(which_module?); | 362 | // MOD_INC_USE_COUNT(which_module?); |
363 | 363 | ||
364 | |||
365 | mutex_lock(&usb_bus_list_lock); | 364 | mutex_lock(&usb_bus_list_lock); |
366 | list_for_each_entry (ubus, &usb_bus_list, bus_list) { | 365 | list_for_each_entry (ubus, &usb_bus_list, bus_list) { |
367 | mon_bus_init(ubus); | 366 | mon_bus_init(ubus); |
diff --git a/drivers/usb/mon/mon_text.c b/drivers/usb/mon/mon_text.c index a7eb4c99342c..9f1a9227ebe6 100644 --- a/drivers/usb/mon/mon_text.c +++ b/drivers/usb/mon/mon_text.c | |||
@@ -150,20 +150,6 @@ static inline char mon_text_get_data(struct mon_event_text *ep, struct urb *urb, | |||
150 | return '>'; | 150 | return '>'; |
151 | } | 151 | } |
152 | 152 | ||
153 | /* | ||
154 | * The check to see if it's safe to poke at data has an enormous | ||
155 | * number of corner cases, but it seems that the following is | ||
156 | * more or less safe. | ||
157 | * | ||
158 | * We do not even try to look at transfer_buffer, because it can | ||
159 | * contain non-NULL garbage in case the upper level promised to | ||
160 | * set DMA for the HCD. | ||
161 | */ | ||
162 | if (urb->dev->bus->uses_dma && | ||
163 | (urb->transfer_flags & URB_NO_TRANSFER_DMA_MAP)) { | ||
164 | return mon_dmapeek(ep->data, urb->transfer_dma, len); | ||
165 | } | ||
166 | |||
167 | if (urb->transfer_buffer == NULL) | 153 | if (urb->transfer_buffer == NULL) |
168 | return 'Z'; /* '0' would be not as pretty. */ | 154 | return 'Z'; /* '0' would be not as pretty. */ |
169 | 155 | ||
diff --git a/drivers/usb/mon/usb_mon.h b/drivers/usb/mon/usb_mon.h index f5d84ff8c101..df9a4df342c7 100644 --- a/drivers/usb/mon/usb_mon.h +++ b/drivers/usb/mon/usb_mon.h | |||
@@ -65,20 +65,6 @@ int __init mon_bin_init(void); | |||
65 | void mon_bin_exit(void); | 65 | void mon_bin_exit(void); |
66 | 66 | ||
67 | /* | 67 | /* |
68 | * DMA interface. | ||
69 | * | ||
70 | * XXX The vectored side needs a serious re-thinking. Abstracting vectors, | ||
71 | * like in Paolo's original patch, produces a double pkmap. We need an idea. | ||
72 | */ | ||
73 | extern char mon_dmapeek(unsigned char *dst, dma_addr_t dma_addr, int len); | ||
74 | |||
75 | struct mon_reader_bin; | ||
76 | extern void mon_dmapeek_vec(const struct mon_reader_bin *rp, | ||
77 | unsigned int offset, dma_addr_t dma_addr, unsigned int len); | ||
78 | extern unsigned int mon_copy_to_buff(const struct mon_reader_bin *rp, | ||
79 | unsigned int offset, const unsigned char *from, unsigned int len); | ||
80 | |||
81 | /* | ||
82 | */ | 68 | */ |
83 | extern struct mutex mon_lock; | 69 | extern struct mutex mon_lock; |
84 | 70 | ||
diff --git a/drivers/usb/musb/musb_core.c b/drivers/usb/musb/musb_core.c index 1d26beddf2ca..3a61ddb62bd2 100644 --- a/drivers/usb/musb/musb_core.c +++ b/drivers/usb/musb/musb_core.c | |||
@@ -1850,6 +1850,10 @@ static void musb_free(struct musb *musb) | |||
1850 | dma_controller_destroy(c); | 1850 | dma_controller_destroy(c); |
1851 | } | 1851 | } |
1852 | 1852 | ||
1853 | #ifdef CONFIG_USB_MUSB_OTG | ||
1854 | put_device(musb->xceiv->dev); | ||
1855 | #endif | ||
1856 | |||
1853 | musb_writeb(musb->mregs, MUSB_DEVCTL, 0); | 1857 | musb_writeb(musb->mregs, MUSB_DEVCTL, 0); |
1854 | musb_platform_exit(musb); | 1858 | musb_platform_exit(musb); |
1855 | musb_writeb(musb->mregs, MUSB_DEVCTL, 0); | 1859 | musb_writeb(musb->mregs, MUSB_DEVCTL, 0); |
@@ -1859,10 +1863,6 @@ static void musb_free(struct musb *musb) | |||
1859 | clk_put(musb->clock); | 1863 | clk_put(musb->clock); |
1860 | } | 1864 | } |
1861 | 1865 | ||
1862 | #ifdef CONFIG_USB_MUSB_OTG | ||
1863 | put_device(musb->xceiv->dev); | ||
1864 | #endif | ||
1865 | |||
1866 | #ifdef CONFIG_USB_MUSB_HDRC_HCD | 1866 | #ifdef CONFIG_USB_MUSB_HDRC_HCD |
1867 | usb_put_hcd(musb_to_hcd(musb)); | 1867 | usb_put_hcd(musb_to_hcd(musb)); |
1868 | #else | 1868 | #else |
diff --git a/drivers/usb/otg/isp1301_omap.c b/drivers/usb/otg/isp1301_omap.c index e0d56ef2bcb0..77a5f4188999 100644 --- a/drivers/usb/otg/isp1301_omap.c +++ b/drivers/usb/otg/isp1301_omap.c | |||
@@ -117,24 +117,7 @@ static void enable_vbus_draw(struct isp1301 *isp, unsigned mA) | |||
117 | pr_debug(" VBUS %d mA error %d\n", mA, status); | 117 | pr_debug(" VBUS %d mA error %d\n", mA, status); |
118 | } | 118 | } |
119 | 119 | ||
120 | static void enable_vbus_source(struct isp1301 *isp) | 120 | #else |
121 | { | ||
122 | /* this board won't supply more than 8mA vbus power. | ||
123 | * some boards can switch a 100ma "unit load" (or more). | ||
124 | */ | ||
125 | } | ||
126 | |||
127 | |||
128 | /* products will deliver OTG messages with LEDs, GUI, etc */ | ||
129 | static inline void notresponding(struct isp1301 *isp) | ||
130 | { | ||
131 | printk(KERN_NOTICE "OTG device not responding.\n"); | ||
132 | } | ||
133 | |||
134 | |||
135 | #endif | ||
136 | |||
137 | #if defined(CONFIG_MACH_OMAP_H4) | ||
138 | 121 | ||
139 | static void enable_vbus_draw(struct isp1301 *isp, unsigned mA) | 122 | static void enable_vbus_draw(struct isp1301 *isp, unsigned mA) |
140 | { | 123 | { |
@@ -144,6 +127,8 @@ static void enable_vbus_draw(struct isp1301 *isp, unsigned mA) | |||
144 | */ | 127 | */ |
145 | } | 128 | } |
146 | 129 | ||
130 | #endif | ||
131 | |||
147 | static void enable_vbus_source(struct isp1301 *isp) | 132 | static void enable_vbus_source(struct isp1301 *isp) |
148 | { | 133 | { |
149 | /* this board won't supply more than 8mA vbus power. | 134 | /* this board won't supply more than 8mA vbus power. |
@@ -159,8 +144,6 @@ static inline void notresponding(struct isp1301 *isp) | |||
159 | } | 144 | } |
160 | 145 | ||
161 | 146 | ||
162 | #endif | ||
163 | |||
164 | /*-------------------------------------------------------------------------*/ | 147 | /*-------------------------------------------------------------------------*/ |
165 | 148 | ||
166 | static struct i2c_driver isp1301_driver; | 149 | static struct i2c_driver isp1301_driver; |
diff --git a/drivers/usb/serial/ark3116.c b/drivers/usb/serial/ark3116.c index aec61880f36c..131e61adaaf7 100644 --- a/drivers/usb/serial/ark3116.c +++ b/drivers/usb/serial/ark3116.c | |||
@@ -31,14 +31,19 @@ static int debug; | |||
31 | 31 | ||
32 | static struct usb_device_id id_table [] = { | 32 | static struct usb_device_id id_table [] = { |
33 | { USB_DEVICE(0x6547, 0x0232) }, | 33 | { USB_DEVICE(0x6547, 0x0232) }, |
34 | { USB_DEVICE(0x18ec, 0x3118) }, /* USB to IrDA adapter */ | ||
34 | { }, | 35 | { }, |
35 | }; | 36 | }; |
36 | MODULE_DEVICE_TABLE(usb, id_table); | 37 | MODULE_DEVICE_TABLE(usb, id_table); |
37 | 38 | ||
38 | struct ark3116_private { | 39 | static int is_irda(struct usb_serial *serial) |
39 | spinlock_t lock; | 40 | { |
40 | u8 termios_initialized; | 41 | struct usb_device *dev = serial->dev; |
41 | }; | 42 | if (le16_to_cpu(dev->descriptor.idVendor) == 0x18ec && |
43 | le16_to_cpu(dev->descriptor.idProduct) == 0x3118) | ||
44 | return 1; | ||
45 | return 0; | ||
46 | } | ||
42 | 47 | ||
43 | static inline void ARK3116_SND(struct usb_serial *serial, int seq, | 48 | static inline void ARK3116_SND(struct usb_serial *serial, int seq, |
44 | __u8 request, __u8 requesttype, | 49 | __u8 request, __u8 requesttype, |
@@ -82,29 +87,28 @@ static inline void ARK3116_RCV_QUIET(struct usb_serial *serial, | |||
82 | static int ark3116_attach(struct usb_serial *serial) | 87 | static int ark3116_attach(struct usb_serial *serial) |
83 | { | 88 | { |
84 | char *buf; | 89 | char *buf; |
85 | struct ark3116_private *priv; | ||
86 | int i; | ||
87 | |||
88 | for (i = 0; i < serial->num_ports; ++i) { | ||
89 | priv = kzalloc(sizeof(struct ark3116_private), GFP_KERNEL); | ||
90 | if (!priv) | ||
91 | goto cleanup; | ||
92 | spin_lock_init(&priv->lock); | ||
93 | |||
94 | usb_set_serial_port_data(serial->port[i], priv); | ||
95 | } | ||
96 | 90 | ||
97 | buf = kmalloc(1, GFP_KERNEL); | 91 | buf = kmalloc(1, GFP_KERNEL); |
98 | if (!buf) { | 92 | if (!buf) { |
99 | dbg("error kmalloc -> out of mem?"); | 93 | dbg("error kmalloc -> out of mem?"); |
100 | goto cleanup; | 94 | return -ENOMEM; |
101 | } | 95 | } |
102 | 96 | ||
97 | if (is_irda(serial)) | ||
98 | dbg("IrDA mode"); | ||
99 | |||
103 | /* 3 */ | 100 | /* 3 */ |
104 | ARK3116_SND(serial, 3, 0xFE, 0x40, 0x0008, 0x0002); | 101 | ARK3116_SND(serial, 3, 0xFE, 0x40, 0x0008, 0x0002); |
105 | ARK3116_SND(serial, 4, 0xFE, 0x40, 0x0008, 0x0001); | 102 | ARK3116_SND(serial, 4, 0xFE, 0x40, 0x0008, 0x0001); |
106 | ARK3116_SND(serial, 5, 0xFE, 0x40, 0x0000, 0x0008); | 103 | ARK3116_SND(serial, 5, 0xFE, 0x40, 0x0000, 0x0008); |
107 | ARK3116_SND(serial, 6, 0xFE, 0x40, 0x0000, 0x000B); | 104 | ARK3116_SND(serial, 6, 0xFE, 0x40, is_irda(serial) ? 0x0001 : 0x0000, |
105 | 0x000B); | ||
106 | |||
107 | if (is_irda(serial)) { | ||
108 | ARK3116_SND(serial, 1001, 0xFE, 0x40, 0x0000, 0x000C); | ||
109 | ARK3116_SND(serial, 1002, 0xFE, 0x40, 0x0041, 0x000D); | ||
110 | ARK3116_SND(serial, 1003, 0xFE, 0x40, 0x0001, 0x000A); | ||
111 | } | ||
108 | 112 | ||
109 | /* <-- seq7 */ | 113 | /* <-- seq7 */ |
110 | ARK3116_RCV(serial, 7, 0xFE, 0xC0, 0x0000, 0x0003, 0x00, buf); | 114 | ARK3116_RCV(serial, 7, 0xFE, 0xC0, 0x0000, 0x0003, 0x00, buf); |
@@ -141,6 +145,8 @@ static int ark3116_attach(struct usb_serial *serial) | |||
141 | ARK3116_SND(serial, 147, 0xFE, 0x40, 0x0083, 0x0003); | 145 | ARK3116_SND(serial, 147, 0xFE, 0x40, 0x0083, 0x0003); |
142 | ARK3116_SND(serial, 148, 0xFE, 0x40, 0x0038, 0x0000); | 146 | ARK3116_SND(serial, 148, 0xFE, 0x40, 0x0038, 0x0000); |
143 | ARK3116_SND(serial, 149, 0xFE, 0x40, 0x0001, 0x0001); | 147 | ARK3116_SND(serial, 149, 0xFE, 0x40, 0x0001, 0x0001); |
148 | if (is_irda(serial)) | ||
149 | ARK3116_SND(serial, 1004, 0xFE, 0x40, 0x0000, 0x0009); | ||
144 | ARK3116_SND(serial, 150, 0xFE, 0x40, 0x0003, 0x0003); | 150 | ARK3116_SND(serial, 150, 0xFE, 0x40, 0x0003, 0x0003); |
145 | ARK3116_RCV(serial, 151, 0xFE, 0xC0, 0x0000, 0x0004, 0x03, buf); | 151 | ARK3116_RCV(serial, 151, 0xFE, 0xC0, 0x0000, 0x0004, 0x03, buf); |
146 | ARK3116_SND(serial, 152, 0xFE, 0x40, 0x0000, 0x0003); | 152 | ARK3116_SND(serial, 152, 0xFE, 0x40, 0x0000, 0x0003); |
@@ -149,13 +155,16 @@ static int ark3116_attach(struct usb_serial *serial) | |||
149 | 155 | ||
150 | kfree(buf); | 156 | kfree(buf); |
151 | return 0; | 157 | return 0; |
158 | } | ||
152 | 159 | ||
153 | cleanup: | 160 | static void ark3116_init_termios(struct tty_struct *tty) |
154 | for (--i; i >= 0; --i) { | 161 | { |
155 | kfree(usb_get_serial_port_data(serial->port[i])); | 162 | struct ktermios *termios = tty->termios; |
156 | usb_set_serial_port_data(serial->port[i], NULL); | 163 | *termios = tty_std_termios; |
157 | } | 164 | termios->c_cflag = B9600 | CS8 |
158 | return -ENOMEM; | 165 | | CREAD | HUPCL | CLOCAL; |
166 | termios->c_ispeed = 9600; | ||
167 | termios->c_ospeed = 9600; | ||
159 | } | 168 | } |
160 | 169 | ||
161 | static void ark3116_set_termios(struct tty_struct *tty, | 170 | static void ark3116_set_termios(struct tty_struct *tty, |
@@ -163,10 +172,8 @@ static void ark3116_set_termios(struct tty_struct *tty, | |||
163 | struct ktermios *old_termios) | 172 | struct ktermios *old_termios) |
164 | { | 173 | { |
165 | struct usb_serial *serial = port->serial; | 174 | struct usb_serial *serial = port->serial; |
166 | struct ark3116_private *priv = usb_get_serial_port_data(port); | ||
167 | struct ktermios *termios = tty->termios; | 175 | struct ktermios *termios = tty->termios; |
168 | unsigned int cflag = termios->c_cflag; | 176 | unsigned int cflag = termios->c_cflag; |
169 | unsigned long flags; | ||
170 | int baud; | 177 | int baud; |
171 | int ark3116_baud; | 178 | int ark3116_baud; |
172 | char *buf; | 179 | char *buf; |
@@ -176,16 +183,6 @@ static void ark3116_set_termios(struct tty_struct *tty, | |||
176 | 183 | ||
177 | dbg("%s - port %d", __func__, port->number); | 184 | dbg("%s - port %d", __func__, port->number); |
178 | 185 | ||
179 | spin_lock_irqsave(&priv->lock, flags); | ||
180 | if (!priv->termios_initialized) { | ||
181 | *termios = tty_std_termios; | ||
182 | termios->c_cflag = B9600 | CS8 | ||
183 | | CREAD | HUPCL | CLOCAL; | ||
184 | termios->c_ispeed = 9600; | ||
185 | termios->c_ospeed = 9600; | ||
186 | priv->termios_initialized = 1; | ||
187 | } | ||
188 | spin_unlock_irqrestore(&priv->lock, flags); | ||
189 | 186 | ||
190 | cflag = termios->c_cflag; | 187 | cflag = termios->c_cflag; |
191 | termios->c_cflag &= ~(CMSPAR|CRTSCTS); | 188 | termios->c_cflag &= ~(CMSPAR|CRTSCTS); |
@@ -318,8 +315,7 @@ static void ark3116_set_termios(struct tty_struct *tty, | |||
318 | return; | 315 | return; |
319 | } | 316 | } |
320 | 317 | ||
321 | static int ark3116_open(struct tty_struct *tty, struct usb_serial_port *port, | 318 | static int ark3116_open(struct tty_struct *tty, struct usb_serial_port *port) |
322 | struct file *filp) | ||
323 | { | 319 | { |
324 | struct ktermios tmp_termios; | 320 | struct ktermios tmp_termios; |
325 | struct usb_serial *serial = port->serial; | 321 | struct usb_serial *serial = port->serial; |
@@ -334,7 +330,7 @@ static int ark3116_open(struct tty_struct *tty, struct usb_serial_port *port, | |||
334 | return -ENOMEM; | 330 | return -ENOMEM; |
335 | } | 331 | } |
336 | 332 | ||
337 | result = usb_serial_generic_open(tty, port, filp); | 333 | result = usb_serial_generic_open(tty, port); |
338 | if (result) | 334 | if (result) |
339 | goto err_out; | 335 | goto err_out; |
340 | 336 | ||
@@ -455,6 +451,7 @@ static struct usb_serial_driver ark3116_device = { | |||
455 | .num_ports = 1, | 451 | .num_ports = 1, |
456 | .attach = ark3116_attach, | 452 | .attach = ark3116_attach, |
457 | .set_termios = ark3116_set_termios, | 453 | .set_termios = ark3116_set_termios, |
454 | .init_termios = ark3116_init_termios, | ||
458 | .ioctl = ark3116_ioctl, | 455 | .ioctl = ark3116_ioctl, |
459 | .tiocmget = ark3116_tiocmget, | 456 | .tiocmget = ark3116_tiocmget, |
460 | .open = ark3116_open, | 457 | .open = ark3116_open, |
diff --git a/drivers/usb/serial/belkin_sa.c b/drivers/usb/serial/belkin_sa.c index 7033b031b443..a0467bc61627 100644 --- a/drivers/usb/serial/belkin_sa.c +++ b/drivers/usb/serial/belkin_sa.c | |||
@@ -92,7 +92,7 @@ static int debug; | |||
92 | static int belkin_sa_startup(struct usb_serial *serial); | 92 | static int belkin_sa_startup(struct usb_serial *serial); |
93 | static void belkin_sa_release(struct usb_serial *serial); | 93 | static void belkin_sa_release(struct usb_serial *serial); |
94 | static int belkin_sa_open(struct tty_struct *tty, | 94 | static int belkin_sa_open(struct tty_struct *tty, |
95 | struct usb_serial_port *port, struct file *filp); | 95 | struct usb_serial_port *port); |
96 | static void belkin_sa_close(struct usb_serial_port *port); | 96 | static void belkin_sa_close(struct usb_serial_port *port); |
97 | static void belkin_sa_read_int_callback(struct urb *urb); | 97 | static void belkin_sa_read_int_callback(struct urb *urb); |
98 | static void belkin_sa_set_termios(struct tty_struct *tty, | 98 | static void belkin_sa_set_termios(struct tty_struct *tty, |
@@ -213,7 +213,7 @@ static void belkin_sa_release(struct usb_serial *serial) | |||
213 | 213 | ||
214 | 214 | ||
215 | static int belkin_sa_open(struct tty_struct *tty, | 215 | static int belkin_sa_open(struct tty_struct *tty, |
216 | struct usb_serial_port *port, struct file *filp) | 216 | struct usb_serial_port *port) |
217 | { | 217 | { |
218 | int retval = 0; | 218 | int retval = 0; |
219 | 219 | ||
diff --git a/drivers/usb/serial/ch341.c b/drivers/usb/serial/ch341.c index 2830766f5b39..59eff721fcc5 100644 --- a/drivers/usb/serial/ch341.c +++ b/drivers/usb/serial/ch341.c | |||
@@ -56,6 +56,18 @@ | |||
56 | #define CH341_BAUDBASE_FACTOR 1532620800 | 56 | #define CH341_BAUDBASE_FACTOR 1532620800 |
57 | #define CH341_BAUDBASE_DIVMAX 3 | 57 | #define CH341_BAUDBASE_DIVMAX 3 |
58 | 58 | ||
59 | /* Break support - the information used to implement this was gleaned from | ||
60 | * the Net/FreeBSD uchcom.c driver by Takanori Watanabe. Domo arigato. | ||
61 | */ | ||
62 | |||
63 | #define CH341_REQ_WRITE_REG 0x9A | ||
64 | #define CH341_REQ_READ_REG 0x95 | ||
65 | #define CH341_REG_BREAK1 0x05 | ||
66 | #define CH341_REG_BREAK2 0x18 | ||
67 | #define CH341_NBREAK_BITS_REG1 0x01 | ||
68 | #define CH341_NBREAK_BITS_REG2 0x40 | ||
69 | |||
70 | |||
59 | static int debug; | 71 | static int debug; |
60 | 72 | ||
61 | static struct usb_device_id id_table [] = { | 73 | static struct usb_device_id id_table [] = { |
@@ -300,8 +312,7 @@ static void ch341_close(struct usb_serial_port *port) | |||
300 | 312 | ||
301 | 313 | ||
302 | /* open this device, set default parameters */ | 314 | /* open this device, set default parameters */ |
303 | static int ch341_open(struct tty_struct *tty, struct usb_serial_port *port, | 315 | static int ch341_open(struct tty_struct *tty, struct usb_serial_port *port) |
304 | struct file *filp) | ||
305 | { | 316 | { |
306 | struct usb_serial *serial = port->serial; | 317 | struct usb_serial *serial = port->serial; |
307 | struct ch341_private *priv = usb_get_serial_port_data(serial->port[0]); | 318 | struct ch341_private *priv = usb_get_serial_port_data(serial->port[0]); |
@@ -333,7 +344,7 @@ static int ch341_open(struct tty_struct *tty, struct usb_serial_port *port, | |||
333 | return -EPROTO; | 344 | return -EPROTO; |
334 | } | 345 | } |
335 | 346 | ||
336 | r = usb_serial_generic_open(tty, port, filp); | 347 | r = usb_serial_generic_open(tty, port); |
337 | 348 | ||
338 | out: return r; | 349 | out: return r; |
339 | } | 350 | } |
@@ -374,6 +385,45 @@ static void ch341_set_termios(struct tty_struct *tty, | |||
374 | */ | 385 | */ |
375 | } | 386 | } |
376 | 387 | ||
388 | static void ch341_break_ctl(struct tty_struct *tty, int break_state) | ||
389 | { | ||
390 | const uint16_t ch341_break_reg = | ||
391 | CH341_REG_BREAK1 | ((uint16_t) CH341_REG_BREAK2 << 8); | ||
392 | struct usb_serial_port *port = tty->driver_data; | ||
393 | int r; | ||
394 | uint16_t reg_contents; | ||
395 | uint8_t break_reg[2]; | ||
396 | |||
397 | dbg("%s()", __func__); | ||
398 | |||
399 | r = ch341_control_in(port->serial->dev, CH341_REQ_READ_REG, | ||
400 | ch341_break_reg, 0, break_reg, sizeof(break_reg)); | ||
401 | if (r < 0) { | ||
402 | printk(KERN_WARNING "%s: USB control read error whilst getting" | ||
403 | " break register contents.\n", __FILE__); | ||
404 | return; | ||
405 | } | ||
406 | dbg("%s - initial ch341 break register contents - reg1: %x, reg2: %x", | ||
407 | __func__, break_reg[0], break_reg[1]); | ||
408 | if (break_state != 0) { | ||
409 | dbg("%s - Enter break state requested", __func__); | ||
410 | break_reg[0] &= ~CH341_NBREAK_BITS_REG1; | ||
411 | break_reg[1] &= ~CH341_NBREAK_BITS_REG2; | ||
412 | } else { | ||
413 | dbg("%s - Leave break state requested", __func__); | ||
414 | break_reg[0] |= CH341_NBREAK_BITS_REG1; | ||
415 | break_reg[1] |= CH341_NBREAK_BITS_REG2; | ||
416 | } | ||
417 | dbg("%s - New ch341 break register contents - reg1: %x, reg2: %x", | ||
418 | __func__, break_reg[0], break_reg[1]); | ||
419 | reg_contents = (uint16_t)break_reg[0] | ((uint16_t)break_reg[1] << 8); | ||
420 | r = ch341_control_out(port->serial->dev, CH341_REQ_WRITE_REG, | ||
421 | ch341_break_reg, reg_contents); | ||
422 | if (r < 0) | ||
423 | printk(KERN_WARNING "%s: USB control write error whilst setting" | ||
424 | " break register contents.\n", __FILE__); | ||
425 | } | ||
426 | |||
377 | static int ch341_tiocmset(struct tty_struct *tty, struct file *file, | 427 | static int ch341_tiocmset(struct tty_struct *tty, struct file *file, |
378 | unsigned int set, unsigned int clear) | 428 | unsigned int set, unsigned int clear) |
379 | { | 429 | { |
@@ -577,6 +627,7 @@ static struct usb_serial_driver ch341_device = { | |||
577 | .close = ch341_close, | 627 | .close = ch341_close, |
578 | .ioctl = ch341_ioctl, | 628 | .ioctl = ch341_ioctl, |
579 | .set_termios = ch341_set_termios, | 629 | .set_termios = ch341_set_termios, |
630 | .break_ctl = ch341_break_ctl, | ||
580 | .tiocmget = ch341_tiocmget, | 631 | .tiocmget = ch341_tiocmget, |
581 | .tiocmset = ch341_tiocmset, | 632 | .tiocmset = ch341_tiocmset, |
582 | .read_int_callback = ch341_read_int_callback, | 633 | .read_int_callback = ch341_read_int_callback, |
diff --git a/drivers/usb/serial/console.c b/drivers/usb/serial/console.c index 0e4f2e41ace5..b22ac3258523 100644 --- a/drivers/usb/serial/console.c +++ b/drivers/usb/serial/console.c | |||
@@ -16,6 +16,7 @@ | |||
16 | #include <linux/slab.h> | 16 | #include <linux/slab.h> |
17 | #include <linux/tty.h> | 17 | #include <linux/tty.h> |
18 | #include <linux/console.h> | 18 | #include <linux/console.h> |
19 | #include <linux/serial.h> | ||
19 | #include <linux/usb.h> | 20 | #include <linux/usb.h> |
20 | #include <linux/usb/serial.h> | 21 | #include <linux/usb/serial.h> |
21 | 22 | ||
@@ -63,7 +64,7 @@ static int usb_console_setup(struct console *co, char *options) | |||
63 | char *s; | 64 | char *s; |
64 | struct usb_serial *serial; | 65 | struct usb_serial *serial; |
65 | struct usb_serial_port *port; | 66 | struct usb_serial_port *port; |
66 | int retval = 0; | 67 | int retval; |
67 | struct tty_struct *tty = NULL; | 68 | struct tty_struct *tty = NULL; |
68 | struct ktermios *termios = NULL, dummy; | 69 | struct ktermios *termios = NULL, dummy; |
69 | 70 | ||
@@ -116,13 +117,17 @@ static int usb_console_setup(struct console *co, char *options) | |||
116 | return -ENODEV; | 117 | return -ENODEV; |
117 | } | 118 | } |
118 | 119 | ||
119 | port = serial->port[0]; | 120 | retval = usb_autopm_get_interface(serial->interface); |
121 | if (retval) | ||
122 | goto error_get_interface; | ||
123 | |||
124 | port = serial->port[co->index - serial->minor]; | ||
120 | tty_port_tty_set(&port->port, NULL); | 125 | tty_port_tty_set(&port->port, NULL); |
121 | 126 | ||
122 | info->port = port; | 127 | info->port = port; |
123 | 128 | ||
124 | ++port->port.count; | 129 | ++port->port.count; |
125 | if (port->port.count == 1) { | 130 | if (!test_bit(ASYNCB_INITIALIZED, &port->port.flags)) { |
126 | if (serial->type->set_termios) { | 131 | if (serial->type->set_termios) { |
127 | /* | 132 | /* |
128 | * allocate a fake tty so the driver can initialize | 133 | * allocate a fake tty so the driver can initialize |
@@ -150,9 +155,9 @@ static int usb_console_setup(struct console *co, char *options) | |||
150 | /* only call the device specific open if this | 155 | /* only call the device specific open if this |
151 | * is the first time the port is opened */ | 156 | * is the first time the port is opened */ |
152 | if (serial->type->open) | 157 | if (serial->type->open) |
153 | retval = serial->type->open(NULL, port, NULL); | 158 | retval = serial->type->open(NULL, port); |
154 | else | 159 | else |
155 | retval = usb_serial_generic_open(NULL, port, NULL); | 160 | retval = usb_serial_generic_open(NULL, port); |
156 | 161 | ||
157 | if (retval) { | 162 | if (retval) { |
158 | err("could not open USB console port"); | 163 | err("could not open USB console port"); |
@@ -168,6 +173,7 @@ static int usb_console_setup(struct console *co, char *options) | |||
168 | kfree(termios); | 173 | kfree(termios); |
169 | kfree(tty); | 174 | kfree(tty); |
170 | } | 175 | } |
176 | set_bit(ASYNCB_INITIALIZED, &port->port.flags); | ||
171 | } | 177 | } |
172 | /* Now that any required fake tty operations are completed restore | 178 | /* Now that any required fake tty operations are completed restore |
173 | * the tty port count */ | 179 | * the tty port count */ |
@@ -175,18 +181,22 @@ static int usb_console_setup(struct console *co, char *options) | |||
175 | /* The console is special in terms of closing the device so | 181 | /* The console is special in terms of closing the device so |
176 | * indicate this port is now acting as a system console. */ | 182 | * indicate this port is now acting as a system console. */ |
177 | port->console = 1; | 183 | port->console = 1; |
178 | retval = 0; | ||
179 | 184 | ||
180 | out: | 185 | mutex_unlock(&serial->disc_mutex); |
181 | return retval; | 186 | return retval; |
182 | free_termios: | 187 | |
188 | free_termios: | ||
183 | kfree(termios); | 189 | kfree(termios); |
184 | tty_port_tty_set(&port->port, NULL); | 190 | tty_port_tty_set(&port->port, NULL); |
185 | free_tty: | 191 | free_tty: |
186 | kfree(tty); | 192 | kfree(tty); |
187 | reset_open_count: | 193 | reset_open_count: |
188 | port->port.count = 0; | 194 | port->port.count = 0; |
189 | goto out; | 195 | usb_autopm_put_interface(serial->interface); |
196 | error_get_interface: | ||
197 | usb_serial_put(serial); | ||
198 | mutex_unlock(&serial->disc_mutex); | ||
199 | return retval; | ||
190 | } | 200 | } |
191 | 201 | ||
192 | static void usb_console_write(struct console *co, | 202 | static void usb_console_write(struct console *co, |
diff --git a/drivers/usb/serial/cp210x.c b/drivers/usb/serial/cp210x.c index 985cbcf48bda..4a208fe85bc9 100644 --- a/drivers/usb/serial/cp210x.c +++ b/drivers/usb/serial/cp210x.c | |||
@@ -33,8 +33,7 @@ | |||
33 | /* | 33 | /* |
34 | * Function Prototypes | 34 | * Function Prototypes |
35 | */ | 35 | */ |
36 | static int cp210x_open(struct tty_struct *, struct usb_serial_port *, | 36 | static int cp210x_open(struct tty_struct *tty, struct usb_serial_port *); |
37 | struct file *); | ||
38 | static void cp210x_cleanup(struct usb_serial_port *); | 37 | static void cp210x_cleanup(struct usb_serial_port *); |
39 | static void cp210x_close(struct usb_serial_port *); | 38 | static void cp210x_close(struct usb_serial_port *); |
40 | static void cp210x_get_termios(struct tty_struct *, | 39 | static void cp210x_get_termios(struct tty_struct *, |
@@ -368,8 +367,7 @@ static unsigned int cp210x_quantise_baudrate(unsigned int baud) { | |||
368 | return baud; | 367 | return baud; |
369 | } | 368 | } |
370 | 369 | ||
371 | static int cp210x_open(struct tty_struct *tty, struct usb_serial_port *port, | 370 | static int cp210x_open(struct tty_struct *tty, struct usb_serial_port *port) |
372 | struct file *filp) | ||
373 | { | 371 | { |
374 | struct usb_serial *serial = port->serial; | 372 | struct usb_serial *serial = port->serial; |
375 | int result; | 373 | int result; |
@@ -399,12 +397,6 @@ static int cp210x_open(struct tty_struct *tty, struct usb_serial_port *port, | |||
399 | 397 | ||
400 | /* Configure the termios structure */ | 398 | /* Configure the termios structure */ |
401 | cp210x_get_termios(tty, port); | 399 | cp210x_get_termios(tty, port); |
402 | |||
403 | /* Set the DTR and RTS pins low */ | ||
404 | cp210x_tiocmset_port(tty ? (struct usb_serial_port *) tty->driver_data | ||
405 | : port, | ||
406 | NULL, TIOCM_DTR | TIOCM_RTS, 0); | ||
407 | |||
408 | return 0; | 400 | return 0; |
409 | } | 401 | } |
410 | 402 | ||
diff --git a/drivers/usb/serial/cyberjack.c b/drivers/usb/serial/cyberjack.c index 336523fd7366..b0f6402a91ca 100644 --- a/drivers/usb/serial/cyberjack.c +++ b/drivers/usb/serial/cyberjack.c | |||
@@ -61,7 +61,7 @@ static int cyberjack_startup(struct usb_serial *serial); | |||
61 | static void cyberjack_disconnect(struct usb_serial *serial); | 61 | static void cyberjack_disconnect(struct usb_serial *serial); |
62 | static void cyberjack_release(struct usb_serial *serial); | 62 | static void cyberjack_release(struct usb_serial *serial); |
63 | static int cyberjack_open(struct tty_struct *tty, | 63 | static int cyberjack_open(struct tty_struct *tty, |
64 | struct usb_serial_port *port, struct file *filp); | 64 | struct usb_serial_port *port); |
65 | static void cyberjack_close(struct usb_serial_port *port); | 65 | static void cyberjack_close(struct usb_serial_port *port); |
66 | static int cyberjack_write(struct tty_struct *tty, | 66 | static int cyberjack_write(struct tty_struct *tty, |
67 | struct usb_serial_port *port, const unsigned char *buf, int count); | 67 | struct usb_serial_port *port, const unsigned char *buf, int count); |
@@ -173,7 +173,7 @@ static void cyberjack_release(struct usb_serial *serial) | |||
173 | } | 173 | } |
174 | 174 | ||
175 | static int cyberjack_open(struct tty_struct *tty, | 175 | static int cyberjack_open(struct tty_struct *tty, |
176 | struct usb_serial_port *port, struct file *filp) | 176 | struct usb_serial_port *port) |
177 | { | 177 | { |
178 | struct cyberjack_private *priv; | 178 | struct cyberjack_private *priv; |
179 | unsigned long flags; | 179 | unsigned long flags; |
diff --git a/drivers/usb/serial/cypress_m8.c b/drivers/usb/serial/cypress_m8.c index 59adfe123110..e0a8b715f2f2 100644 --- a/drivers/usb/serial/cypress_m8.c +++ b/drivers/usb/serial/cypress_m8.c | |||
@@ -172,8 +172,7 @@ static int cypress_earthmate_startup(struct usb_serial *serial); | |||
172 | static int cypress_hidcom_startup(struct usb_serial *serial); | 172 | static int cypress_hidcom_startup(struct usb_serial *serial); |
173 | static int cypress_ca42v2_startup(struct usb_serial *serial); | 173 | static int cypress_ca42v2_startup(struct usb_serial *serial); |
174 | static void cypress_release(struct usb_serial *serial); | 174 | static void cypress_release(struct usb_serial *serial); |
175 | static int cypress_open(struct tty_struct *tty, | 175 | static int cypress_open(struct tty_struct *tty, struct usb_serial_port *port); |
176 | struct usb_serial_port *port, struct file *filp); | ||
177 | static void cypress_close(struct usb_serial_port *port); | 176 | static void cypress_close(struct usb_serial_port *port); |
178 | static void cypress_dtr_rts(struct usb_serial_port *port, int on); | 177 | static void cypress_dtr_rts(struct usb_serial_port *port, int on); |
179 | static int cypress_write(struct tty_struct *tty, struct usb_serial_port *port, | 178 | static int cypress_write(struct tty_struct *tty, struct usb_serial_port *port, |
@@ -633,8 +632,7 @@ static void cypress_release(struct usb_serial *serial) | |||
633 | } | 632 | } |
634 | 633 | ||
635 | 634 | ||
636 | static int cypress_open(struct tty_struct *tty, | 635 | static int cypress_open(struct tty_struct *tty, struct usb_serial_port *port) |
637 | struct usb_serial_port *port, struct file *filp) | ||
638 | { | 636 | { |
639 | struct cypress_private *priv = usb_get_serial_port_data(port); | 637 | struct cypress_private *priv = usb_get_serial_port_data(port); |
640 | struct usb_serial *serial = port->serial; | 638 | struct usb_serial *serial = port->serial; |
@@ -659,15 +657,7 @@ static int cypress_open(struct tty_struct *tty, | |||
659 | spin_unlock_irqrestore(&priv->lock, flags); | 657 | spin_unlock_irqrestore(&priv->lock, flags); |
660 | 658 | ||
661 | /* Set termios */ | 659 | /* Set termios */ |
662 | result = cypress_write(tty, port, NULL, 0); | 660 | cypress_send(port); |
663 | |||
664 | if (result) { | ||
665 | dev_err(&port->dev, | ||
666 | "%s - failed setting the control lines - error %d\n", | ||
667 | __func__, result); | ||
668 | return result; | ||
669 | } else | ||
670 | dbg("%s - success setting the control lines", __func__); | ||
671 | 661 | ||
672 | if (tty) | 662 | if (tty) |
673 | cypress_set_termios(tty, port, &priv->tmp_termios); | 663 | cypress_set_termios(tty, port, &priv->tmp_termios); |
@@ -1005,6 +995,8 @@ static void cypress_set_termios(struct tty_struct *tty, | |||
1005 | dbg("%s - port %d", __func__, port->number); | 995 | dbg("%s - port %d", __func__, port->number); |
1006 | 996 | ||
1007 | spin_lock_irqsave(&priv->lock, flags); | 997 | spin_lock_irqsave(&priv->lock, flags); |
998 | /* We can't clean this one up as we don't know the device type | ||
999 | early enough */ | ||
1008 | if (!priv->termios_initialized) { | 1000 | if (!priv->termios_initialized) { |
1009 | if (priv->chiptype == CT_EARTHMATE) { | 1001 | if (priv->chiptype == CT_EARTHMATE) { |
1010 | *(tty->termios) = tty_std_termios; | 1002 | *(tty->termios) = tty_std_termios; |
diff --git a/drivers/usb/serial/cypress_m8.h b/drivers/usb/serial/cypress_m8.h index e772b01ac3ac..1fd360e04065 100644 --- a/drivers/usb/serial/cypress_m8.h +++ b/drivers/usb/serial/cypress_m8.h | |||
@@ -57,7 +57,7 @@ | |||
57 | #define UART_RI 0x10 /* ring indicator - modem - device to host */ | 57 | #define UART_RI 0x10 /* ring indicator - modem - device to host */ |
58 | #define UART_CD 0x40 /* carrier detect - modem - device to host */ | 58 | #define UART_CD 0x40 /* carrier detect - modem - device to host */ |
59 | #define CYP_ERROR 0x08 /* received from input report - device to host */ | 59 | #define CYP_ERROR 0x08 /* received from input report - device to host */ |
60 | /* Note - the below has nothing to to with the "feature report" reset */ | 60 | /* Note - the below has nothing to do with the "feature report" reset */ |
61 | #define CONTROL_RESET 0x08 /* sent with output report - host to device */ | 61 | #define CONTROL_RESET 0x08 /* sent with output report - host to device */ |
62 | 62 | ||
63 | /* End of RS-232 protocol definitions */ | 63 | /* End of RS-232 protocol definitions */ |
diff --git a/drivers/usb/serial/digi_acceleport.c b/drivers/usb/serial/digi_acceleport.c index f4808091c47c..ab3dd991586b 100644 --- a/drivers/usb/serial/digi_acceleport.c +++ b/drivers/usb/serial/digi_acceleport.c | |||
@@ -453,8 +453,7 @@ static int digi_write(struct tty_struct *tty, struct usb_serial_port *port, | |||
453 | static void digi_write_bulk_callback(struct urb *urb); | 453 | static void digi_write_bulk_callback(struct urb *urb); |
454 | static int digi_write_room(struct tty_struct *tty); | 454 | static int digi_write_room(struct tty_struct *tty); |
455 | static int digi_chars_in_buffer(struct tty_struct *tty); | 455 | static int digi_chars_in_buffer(struct tty_struct *tty); |
456 | static int digi_open(struct tty_struct *tty, struct usb_serial_port *port, | 456 | static int digi_open(struct tty_struct *tty, struct usb_serial_port *port); |
457 | struct file *filp); | ||
458 | static void digi_close(struct usb_serial_port *port); | 457 | static void digi_close(struct usb_serial_port *port); |
459 | static int digi_carrier_raised(struct usb_serial_port *port); | 458 | static int digi_carrier_raised(struct usb_serial_port *port); |
460 | static void digi_dtr_rts(struct usb_serial_port *port, int on); | 459 | static void digi_dtr_rts(struct usb_serial_port *port, int on); |
@@ -1347,8 +1346,7 @@ static int digi_carrier_raised(struct usb_serial_port *port) | |||
1347 | return 0; | 1346 | return 0; |
1348 | } | 1347 | } |
1349 | 1348 | ||
1350 | static int digi_open(struct tty_struct *tty, struct usb_serial_port *port, | 1349 | static int digi_open(struct tty_struct *tty, struct usb_serial_port *port) |
1351 | struct file *filp) | ||
1352 | { | 1350 | { |
1353 | int ret; | 1351 | int ret; |
1354 | unsigned char buf[32]; | 1352 | unsigned char buf[32]; |
diff --git a/drivers/usb/serial/empeg.c b/drivers/usb/serial/empeg.c index 80cb3471adbe..33c9e9cf9eb2 100644 --- a/drivers/usb/serial/empeg.c +++ b/drivers/usb/serial/empeg.c | |||
@@ -79,8 +79,7 @@ static int debug; | |||
79 | #define EMPEG_PRODUCT_ID 0x0001 | 79 | #define EMPEG_PRODUCT_ID 0x0001 |
80 | 80 | ||
81 | /* function prototypes for an empeg-car player */ | 81 | /* function prototypes for an empeg-car player */ |
82 | static int empeg_open(struct tty_struct *tty, struct usb_serial_port *port, | 82 | static int empeg_open(struct tty_struct *tty, struct usb_serial_port *port); |
83 | struct file *filp); | ||
84 | static void empeg_close(struct usb_serial_port *port); | 83 | static void empeg_close(struct usb_serial_port *port); |
85 | static int empeg_write(struct tty_struct *tty, struct usb_serial_port *port, | 84 | static int empeg_write(struct tty_struct *tty, struct usb_serial_port *port, |
86 | const unsigned char *buf, | 85 | const unsigned char *buf, |
@@ -90,8 +89,7 @@ static int empeg_chars_in_buffer(struct tty_struct *tty); | |||
90 | static void empeg_throttle(struct tty_struct *tty); | 89 | static void empeg_throttle(struct tty_struct *tty); |
91 | static void empeg_unthrottle(struct tty_struct *tty); | 90 | static void empeg_unthrottle(struct tty_struct *tty); |
92 | static int empeg_startup(struct usb_serial *serial); | 91 | static int empeg_startup(struct usb_serial *serial); |
93 | static void empeg_set_termios(struct tty_struct *tty, | 92 | static void empeg_init_termios(struct tty_struct *tty); |
94 | struct usb_serial_port *port, struct ktermios *old_termios); | ||
95 | static void empeg_write_bulk_callback(struct urb *urb); | 93 | static void empeg_write_bulk_callback(struct urb *urb); |
96 | static void empeg_read_bulk_callback(struct urb *urb); | 94 | static void empeg_read_bulk_callback(struct urb *urb); |
97 | 95 | ||
@@ -123,7 +121,7 @@ static struct usb_serial_driver empeg_device = { | |||
123 | .throttle = empeg_throttle, | 121 | .throttle = empeg_throttle, |
124 | .unthrottle = empeg_unthrottle, | 122 | .unthrottle = empeg_unthrottle, |
125 | .attach = empeg_startup, | 123 | .attach = empeg_startup, |
126 | .set_termios = empeg_set_termios, | 124 | .init_termios = empeg_init_termios, |
127 | .write = empeg_write, | 125 | .write = empeg_write, |
128 | .write_room = empeg_write_room, | 126 | .write_room = empeg_write_room, |
129 | .chars_in_buffer = empeg_chars_in_buffer, | 127 | .chars_in_buffer = empeg_chars_in_buffer, |
@@ -142,17 +140,13 @@ static int bytes_out; | |||
142 | /****************************************************************************** | 140 | /****************************************************************************** |
143 | * Empeg specific driver functions | 141 | * Empeg specific driver functions |
144 | ******************************************************************************/ | 142 | ******************************************************************************/ |
145 | static int empeg_open(struct tty_struct *tty, struct usb_serial_port *port, | 143 | static int empeg_open(struct tty_struct *tty,struct usb_serial_port *port) |
146 | struct file *filp) | ||
147 | { | 144 | { |
148 | struct usb_serial *serial = port->serial; | 145 | struct usb_serial *serial = port->serial; |
149 | int result = 0; | 146 | int result = 0; |
150 | 147 | ||
151 | dbg("%s - port %d", __func__, port->number); | 148 | dbg("%s - port %d", __func__, port->number); |
152 | 149 | ||
153 | /* Force default termio settings */ | ||
154 | empeg_set_termios(tty, port, NULL) ; | ||
155 | |||
156 | bytes_in = 0; | 150 | bytes_in = 0; |
157 | bytes_out = 0; | 151 | bytes_out = 0; |
158 | 152 | ||
@@ -425,11 +419,9 @@ static int empeg_startup(struct usb_serial *serial) | |||
425 | } | 419 | } |
426 | 420 | ||
427 | 421 | ||
428 | static void empeg_set_termios(struct tty_struct *tty, | 422 | static void empeg_init_termios(struct tty_struct *tty) |
429 | struct usb_serial_port *port, struct ktermios *old_termios) | ||
430 | { | 423 | { |
431 | struct ktermios *termios = tty->termios; | 424 | struct ktermios *termios = tty->termios; |
432 | dbg("%s - port %d", __func__, port->number); | ||
433 | 425 | ||
434 | /* | 426 | /* |
435 | * The empeg-car player wants these particular tty settings. | 427 | * The empeg-car player wants these particular tty settings. |
diff --git a/drivers/usb/serial/ftdi_sio.c b/drivers/usb/serial/ftdi_sio.c index 8fec5d4455c9..4f883b1773d0 100644 --- a/drivers/usb/serial/ftdi_sio.c +++ b/drivers/usb/serial/ftdi_sio.c | |||
@@ -176,6 +176,9 @@ static struct usb_device_id id_table_combined [] = { | |||
176 | { USB_DEVICE(FTDI_VID, FTDI_MICRO_CHAMELEON_PID) }, | 176 | { USB_DEVICE(FTDI_VID, FTDI_MICRO_CHAMELEON_PID) }, |
177 | { USB_DEVICE(FTDI_VID, FTDI_RELAIS_PID) }, | 177 | { USB_DEVICE(FTDI_VID, FTDI_RELAIS_PID) }, |
178 | { USB_DEVICE(FTDI_VID, FTDI_OPENDCC_PID) }, | 178 | { USB_DEVICE(FTDI_VID, FTDI_OPENDCC_PID) }, |
179 | { USB_DEVICE(FTDI_VID, FTDI_OPENDCC_SNIFFER_PID) }, | ||
180 | { USB_DEVICE(FTDI_VID, FTDI_OPENDCC_THROTTLE_PID) }, | ||
181 | { USB_DEVICE(FTDI_VID, FTDI_OPENDCC_GATEWAY_PID) }, | ||
179 | { USB_DEVICE(INTERBIOMETRICS_VID, INTERBIOMETRICS_IOBOARD_PID) }, | 182 | { USB_DEVICE(INTERBIOMETRICS_VID, INTERBIOMETRICS_IOBOARD_PID) }, |
180 | { USB_DEVICE(INTERBIOMETRICS_VID, INTERBIOMETRICS_MINI_IOBOARD_PID) }, | 183 | { USB_DEVICE(INTERBIOMETRICS_VID, INTERBIOMETRICS_MINI_IOBOARD_PID) }, |
181 | { USB_DEVICE(FTDI_VID, FTDI_SPROG_II) }, | 184 | { USB_DEVICE(FTDI_VID, FTDI_SPROG_II) }, |
@@ -694,6 +697,8 @@ static struct usb_device_id id_table_combined [] = { | |||
694 | { USB_DEVICE(DE_VID, WHT_PID) }, | 697 | { USB_DEVICE(DE_VID, WHT_PID) }, |
695 | { USB_DEVICE(ADI_VID, ADI_GNICE_PID), | 698 | { USB_DEVICE(ADI_VID, ADI_GNICE_PID), |
696 | .driver_info = (kernel_ulong_t)&ftdi_jtag_quirk }, | 699 | .driver_info = (kernel_ulong_t)&ftdi_jtag_quirk }, |
700 | { USB_DEVICE(ADI_VID, ADI_GNICEPLUS_PID), | ||
701 | .driver_info = (kernel_ulong_t)&ftdi_jtag_quirk }, | ||
697 | { USB_DEVICE(JETI_VID, JETI_SPC1201_PID) }, | 702 | { USB_DEVICE(JETI_VID, JETI_SPC1201_PID) }, |
698 | { USB_DEVICE(MARVELL_VID, MARVELL_SHEEVAPLUG_PID), | 703 | { USB_DEVICE(MARVELL_VID, MARVELL_SHEEVAPLUG_PID), |
699 | .driver_info = (kernel_ulong_t)&ftdi_jtag_quirk }, | 704 | .driver_info = (kernel_ulong_t)&ftdi_jtag_quirk }, |
@@ -702,6 +707,8 @@ static struct usb_device_id id_table_combined [] = { | |||
702 | { USB_DEVICE(BAYER_VID, BAYER_CONTOUR_CABLE_PID) }, | 707 | { USB_DEVICE(BAYER_VID, BAYER_CONTOUR_CABLE_PID) }, |
703 | { USB_DEVICE(FTDI_VID, MARVELL_OPENRD_PID), | 708 | { USB_DEVICE(FTDI_VID, MARVELL_OPENRD_PID), |
704 | .driver_info = (kernel_ulong_t)&ftdi_jtag_quirk }, | 709 | .driver_info = (kernel_ulong_t)&ftdi_jtag_quirk }, |
710 | { USB_DEVICE(FTDI_VID, HAMEG_HO820_PID) }, | ||
711 | { USB_DEVICE(FTDI_VID, HAMEG_HO870_PID) }, | ||
705 | { }, /* Optional parameter entry */ | 712 | { }, /* Optional parameter entry */ |
706 | { } /* Terminating entry */ | 713 | { } /* Terminating entry */ |
707 | }; | 714 | }; |
@@ -747,8 +754,7 @@ static int ftdi_sio_probe(struct usb_serial *serial, | |||
747 | const struct usb_device_id *id); | 754 | const struct usb_device_id *id); |
748 | static int ftdi_sio_port_probe(struct usb_serial_port *port); | 755 | static int ftdi_sio_port_probe(struct usb_serial_port *port); |
749 | static int ftdi_sio_port_remove(struct usb_serial_port *port); | 756 | static int ftdi_sio_port_remove(struct usb_serial_port *port); |
750 | static int ftdi_open(struct tty_struct *tty, | 757 | static int ftdi_open(struct tty_struct *tty, struct usb_serial_port *port); |
751 | struct usb_serial_port *port, struct file *filp); | ||
752 | static void ftdi_close(struct usb_serial_port *port); | 758 | static void ftdi_close(struct usb_serial_port *port); |
753 | static void ftdi_dtr_rts(struct usb_serial_port *port, int on); | 759 | static void ftdi_dtr_rts(struct usb_serial_port *port, int on); |
754 | static int ftdi_write(struct tty_struct *tty, struct usb_serial_port *port, | 760 | static int ftdi_write(struct tty_struct *tty, struct usb_serial_port *port, |
@@ -1680,8 +1686,7 @@ static int ftdi_sio_port_remove(struct usb_serial_port *port) | |||
1680 | return 0; | 1686 | return 0; |
1681 | } | 1687 | } |
1682 | 1688 | ||
1683 | static int ftdi_open(struct tty_struct *tty, | 1689 | static int ftdi_open(struct tty_struct *tty, struct usb_serial_port *port) |
1684 | struct usb_serial_port *port, struct file *filp) | ||
1685 | { /* ftdi_open */ | 1690 | { /* ftdi_open */ |
1686 | struct usb_device *dev = port->serial->dev; | 1691 | struct usb_device *dev = port->serial->dev; |
1687 | struct ftdi_private *priv = usb_get_serial_port_data(port); | 1692 | struct ftdi_private *priv = usb_get_serial_port_data(port); |
diff --git a/drivers/usb/serial/ftdi_sio.h b/drivers/usb/serial/ftdi_sio.h index 8c92b88166ae..6f31e0d71898 100644 --- a/drivers/usb/serial/ftdi_sio.h +++ b/drivers/usb/serial/ftdi_sio.h | |||
@@ -81,6 +81,9 @@ | |||
81 | 81 | ||
82 | /* OpenDCC (www.opendcc.de) product id */ | 82 | /* OpenDCC (www.opendcc.de) product id */ |
83 | #define FTDI_OPENDCC_PID 0xBFD8 | 83 | #define FTDI_OPENDCC_PID 0xBFD8 |
84 | #define FTDI_OPENDCC_SNIFFER_PID 0xBFD9 | ||
85 | #define FTDI_OPENDCC_THROTTLE_PID 0xBFDA | ||
86 | #define FTDI_OPENDCC_GATEWAY_PID 0xBFDB | ||
84 | 87 | ||
85 | /* Sprog II (Andrew Crosland's SprogII DCC interface) */ | 88 | /* Sprog II (Andrew Crosland's SprogII DCC interface) */ |
86 | #define FTDI_SPROG_II 0xF0C8 | 89 | #define FTDI_SPROG_II 0xF0C8 |
@@ -930,6 +933,7 @@ | |||
930 | */ | 933 | */ |
931 | #define ADI_VID 0x0456 | 934 | #define ADI_VID 0x0456 |
932 | #define ADI_GNICE_PID 0xF000 | 935 | #define ADI_GNICE_PID 0xF000 |
936 | #define ADI_GNICEPLUS_PID 0xF001 | ||
933 | 937 | ||
934 | /* | 938 | /* |
935 | * JETI SPECTROMETER SPECBOS 1201 | 939 | * JETI SPECTROMETER SPECBOS 1201 |
@@ -968,6 +972,12 @@ | |||
968 | #define MARVELL_OPENRD_PID 0x9e90 | 972 | #define MARVELL_OPENRD_PID 0x9e90 |
969 | 973 | ||
970 | /* | 974 | /* |
975 | * Hameg HO820 and HO870 interface (using VID 0x0403) | ||
976 | */ | ||
977 | #define HAMEG_HO820_PID 0xed74 | ||
978 | #define HAMEG_HO870_PID 0xed71 | ||
979 | |||
980 | /* | ||
971 | * BmRequestType: 1100 0000b | 981 | * BmRequestType: 1100 0000b |
972 | * bRequest: FTDI_E2_READ | 982 | * bRequest: FTDI_E2_READ |
973 | * wValue: 0 | 983 | * wValue: 0 |
diff --git a/drivers/usb/serial/garmin_gps.c b/drivers/usb/serial/garmin_gps.c index 8839f1c70b7f..20432d345529 100644 --- a/drivers/usb/serial/garmin_gps.c +++ b/drivers/usb/serial/garmin_gps.c | |||
@@ -933,8 +933,7 @@ static int garmin_init_session(struct usb_serial_port *port) | |||
933 | 933 | ||
934 | 934 | ||
935 | 935 | ||
936 | static int garmin_open(struct tty_struct *tty, | 936 | static int garmin_open(struct tty_struct *tty, struct usb_serial_port *port) |
937 | struct usb_serial_port *port, struct file *filp) | ||
938 | { | 937 | { |
939 | unsigned long flags; | 938 | unsigned long flags; |
940 | int status = 0; | 939 | int status = 0; |
diff --git a/drivers/usb/serial/generic.c b/drivers/usb/serial/generic.c index ce57f6a32bdf..deba08c7a015 100644 --- a/drivers/usb/serial/generic.c +++ b/drivers/usb/serial/generic.c | |||
@@ -19,7 +19,7 @@ | |||
19 | #include <linux/usb.h> | 19 | #include <linux/usb.h> |
20 | #include <linux/usb/serial.h> | 20 | #include <linux/usb/serial.h> |
21 | #include <linux/uaccess.h> | 21 | #include <linux/uaccess.h> |
22 | 22 | #include <linux/kfifo.h> | |
23 | 23 | ||
24 | static int debug; | 24 | static int debug; |
25 | 25 | ||
@@ -114,8 +114,7 @@ void usb_serial_generic_deregister(void) | |||
114 | #endif | 114 | #endif |
115 | } | 115 | } |
116 | 116 | ||
117 | int usb_serial_generic_open(struct tty_struct *tty, | 117 | int usb_serial_generic_open(struct tty_struct *tty, struct usb_serial_port *port) |
118 | struct usb_serial_port *port, struct file *filp) | ||
119 | { | 118 | { |
120 | struct usb_serial *serial = port->serial; | 119 | struct usb_serial *serial = port->serial; |
121 | int result = 0; | 120 | int result = 0; |
@@ -167,24 +166,6 @@ static void generic_cleanup(struct usb_serial_port *port) | |||
167 | } | 166 | } |
168 | } | 167 | } |
169 | 168 | ||
170 | int usb_serial_generic_resume(struct usb_serial *serial) | ||
171 | { | ||
172 | struct usb_serial_port *port; | ||
173 | int i, c = 0, r; | ||
174 | |||
175 | for (i = 0; i < serial->num_ports; i++) { | ||
176 | port = serial->port[i]; | ||
177 | if (port->port.count && port->read_urb) { | ||
178 | r = usb_submit_urb(port->read_urb, GFP_NOIO); | ||
179 | if (r < 0) | ||
180 | c++; | ||
181 | } | ||
182 | } | ||
183 | |||
184 | return c ? -EIO : 0; | ||
185 | } | ||
186 | EXPORT_SYMBOL_GPL(usb_serial_generic_resume); | ||
187 | |||
188 | void usb_serial_generic_close(struct usb_serial_port *port) | 169 | void usb_serial_generic_close(struct usb_serial_port *port) |
189 | { | 170 | { |
190 | dbg("%s - port %d", __func__, port->number); | 171 | dbg("%s - port %d", __func__, port->number); |
@@ -273,12 +254,81 @@ error_no_buffer: | |||
273 | return bwrite; | 254 | return bwrite; |
274 | } | 255 | } |
275 | 256 | ||
257 | /** | ||
258 | * usb_serial_generic_write_start - kick off an URB write | ||
259 | * @port: Pointer to the &struct usb_serial_port data | ||
260 | * | ||
261 | * Returns the number of bytes queued on success. This will be zero if there | ||
262 | * was nothing to send. Otherwise, it returns a negative errno value | ||
263 | */ | ||
264 | static int usb_serial_generic_write_start(struct usb_serial_port *port) | ||
265 | { | ||
266 | struct usb_serial *serial = port->serial; | ||
267 | unsigned char *data; | ||
268 | int result; | ||
269 | int count; | ||
270 | unsigned long flags; | ||
271 | bool start_io; | ||
272 | |||
273 | /* Atomically determine whether we can and need to start a USB | ||
274 | * operation. */ | ||
275 | spin_lock_irqsave(&port->lock, flags); | ||
276 | if (port->write_urb_busy) | ||
277 | start_io = false; | ||
278 | else { | ||
279 | start_io = (__kfifo_len(port->write_fifo) != 0); | ||
280 | port->write_urb_busy = start_io; | ||
281 | } | ||
282 | spin_unlock_irqrestore(&port->lock, flags); | ||
283 | |||
284 | if (!start_io) | ||
285 | return 0; | ||
286 | |||
287 | data = port->write_urb->transfer_buffer; | ||
288 | count = kfifo_get(port->write_fifo, data, port->bulk_out_size); | ||
289 | usb_serial_debug_data(debug, &port->dev, __func__, count, data); | ||
290 | |||
291 | /* set up our urb */ | ||
292 | usb_fill_bulk_urb(port->write_urb, serial->dev, | ||
293 | usb_sndbulkpipe(serial->dev, | ||
294 | port->bulk_out_endpointAddress), | ||
295 | port->write_urb->transfer_buffer, count, | ||
296 | ((serial->type->write_bulk_callback) ? | ||
297 | serial->type->write_bulk_callback : | ||
298 | usb_serial_generic_write_bulk_callback), | ||
299 | port); | ||
300 | |||
301 | /* send the data out the bulk port */ | ||
302 | result = usb_submit_urb(port->write_urb, GFP_ATOMIC); | ||
303 | if (result) { | ||
304 | dev_err(&port->dev, | ||
305 | "%s - failed submitting write urb, error %d\n", | ||
306 | __func__, result); | ||
307 | /* don't have to grab the lock here, as we will | ||
308 | retry if != 0 */ | ||
309 | port->write_urb_busy = 0; | ||
310 | } else | ||
311 | result = count; | ||
312 | |||
313 | return result; | ||
314 | } | ||
315 | |||
316 | /** | ||
317 | * usb_serial_generic_write - generic write function for serial USB devices | ||
318 | * @tty: Pointer to &struct tty_struct for the device | ||
319 | * @port: Pointer to the &usb_serial_port structure for the device | ||
320 | * @buf: Pointer to the data to write | ||
321 | * @count: Number of bytes to write | ||
322 | * | ||
323 | * Returns the number of characters actually written, which may be anything | ||
324 | * from zero to @count. If an error occurs, it returns the negative errno | ||
325 | * value. | ||
326 | */ | ||
276 | int usb_serial_generic_write(struct tty_struct *tty, | 327 | int usb_serial_generic_write(struct tty_struct *tty, |
277 | struct usb_serial_port *port, const unsigned char *buf, int count) | 328 | struct usb_serial_port *port, const unsigned char *buf, int count) |
278 | { | 329 | { |
279 | struct usb_serial *serial = port->serial; | 330 | struct usb_serial *serial = port->serial; |
280 | int result; | 331 | int result; |
281 | unsigned char *data; | ||
282 | 332 | ||
283 | dbg("%s - port %d", __func__, port->number); | 333 | dbg("%s - port %d", __func__, port->number); |
284 | 334 | ||
@@ -288,57 +338,20 @@ int usb_serial_generic_write(struct tty_struct *tty, | |||
288 | } | 338 | } |
289 | 339 | ||
290 | /* only do something if we have a bulk out endpoint */ | 340 | /* only do something if we have a bulk out endpoint */ |
291 | if (serial->num_bulk_out) { | 341 | if (!serial->num_bulk_out) |
292 | unsigned long flags; | 342 | return 0; |
293 | |||
294 | if (serial->type->max_in_flight_urbs) | ||
295 | return usb_serial_multi_urb_write(tty, port, | ||
296 | buf, count); | ||
297 | |||
298 | spin_lock_irqsave(&port->lock, flags); | ||
299 | if (port->write_urb_busy) { | ||
300 | spin_unlock_irqrestore(&port->lock, flags); | ||
301 | dbg("%s - already writing", __func__); | ||
302 | return 0; | ||
303 | } | ||
304 | port->write_urb_busy = 1; | ||
305 | spin_unlock_irqrestore(&port->lock, flags); | ||
306 | |||
307 | count = (count > port->bulk_out_size) ? | ||
308 | port->bulk_out_size : count; | ||
309 | |||
310 | memcpy(port->write_urb->transfer_buffer, buf, count); | ||
311 | data = port->write_urb->transfer_buffer; | ||
312 | usb_serial_debug_data(debug, &port->dev, __func__, count, data); | ||
313 | 343 | ||
314 | /* set up our urb */ | 344 | if (serial->type->max_in_flight_urbs) |
315 | usb_fill_bulk_urb(port->write_urb, serial->dev, | 345 | return usb_serial_multi_urb_write(tty, port, |
316 | usb_sndbulkpipe(serial->dev, | 346 | buf, count); |
317 | port->bulk_out_endpointAddress), | ||
318 | port->write_urb->transfer_buffer, count, | ||
319 | ((serial->type->write_bulk_callback) ? | ||
320 | serial->type->write_bulk_callback : | ||
321 | usb_serial_generic_write_bulk_callback), | ||
322 | port); | ||
323 | 347 | ||
324 | /* send the data out the bulk port */ | 348 | count = kfifo_put(port->write_fifo, buf, count); |
325 | port->write_urb_busy = 1; | 349 | result = usb_serial_generic_write_start(port); |
326 | result = usb_submit_urb(port->write_urb, GFP_ATOMIC); | ||
327 | if (result) { | ||
328 | dev_err(&port->dev, | ||
329 | "%s - failed submitting write urb, error %d\n", | ||
330 | __func__, result); | ||
331 | /* don't have to grab the lock here, as we will | ||
332 | retry if != 0 */ | ||
333 | port->write_urb_busy = 0; | ||
334 | } else | ||
335 | result = count; | ||
336 | 350 | ||
337 | return result; | 351 | if (result >= 0) |
338 | } | 352 | result = count; |
339 | 353 | ||
340 | /* no bulk out, so return 0 bytes written */ | 354 | return result; |
341 | return 0; | ||
342 | } | 355 | } |
343 | EXPORT_SYMBOL_GPL(usb_serial_generic_write); | 356 | EXPORT_SYMBOL_GPL(usb_serial_generic_write); |
344 | 357 | ||
@@ -356,9 +369,8 @@ int usb_serial_generic_write_room(struct tty_struct *tty) | |||
356 | room = port->bulk_out_size * | 369 | room = port->bulk_out_size * |
357 | (serial->type->max_in_flight_urbs - | 370 | (serial->type->max_in_flight_urbs - |
358 | port->urbs_in_flight); | 371 | port->urbs_in_flight); |
359 | } else if (serial->num_bulk_out && !(port->write_urb_busy)) { | 372 | } else if (serial->num_bulk_out) |
360 | room = port->bulk_out_size; | 373 | room = port->write_fifo->size - __kfifo_len(port->write_fifo); |
361 | } | ||
362 | spin_unlock_irqrestore(&port->lock, flags); | 374 | spin_unlock_irqrestore(&port->lock, flags); |
363 | 375 | ||
364 | dbg("%s - returns %d", __func__, room); | 376 | dbg("%s - returns %d", __func__, room); |
@@ -378,11 +390,8 @@ int usb_serial_generic_chars_in_buffer(struct tty_struct *tty) | |||
378 | spin_lock_irqsave(&port->lock, flags); | 390 | spin_lock_irqsave(&port->lock, flags); |
379 | chars = port->tx_bytes_flight; | 391 | chars = port->tx_bytes_flight; |
380 | spin_unlock_irqrestore(&port->lock, flags); | 392 | spin_unlock_irqrestore(&port->lock, flags); |
381 | } else if (serial->num_bulk_out) { | 393 | } else if (serial->num_bulk_out) |
382 | /* FIXME: Locking */ | 394 | chars = kfifo_len(port->write_fifo); |
383 | if (port->write_urb_busy) | ||
384 | chars = port->write_urb->transfer_buffer_length; | ||
385 | } | ||
386 | 395 | ||
387 | dbg("%s - returns %d", __func__, chars); | 396 | dbg("%s - returns %d", __func__, chars); |
388 | return chars; | 397 | return chars; |
@@ -486,16 +495,23 @@ void usb_serial_generic_write_bulk_callback(struct urb *urb) | |||
486 | if (port->urbs_in_flight < 0) | 495 | if (port->urbs_in_flight < 0) |
487 | port->urbs_in_flight = 0; | 496 | port->urbs_in_flight = 0; |
488 | spin_unlock_irqrestore(&port->lock, flags); | 497 | spin_unlock_irqrestore(&port->lock, flags); |
498 | |||
499 | if (status) { | ||
500 | dbg("%s - nonzero multi-urb write bulk status " | ||
501 | "received: %d", __func__, status); | ||
502 | return; | ||
503 | } | ||
489 | } else { | 504 | } else { |
490 | /* Handle the case for single urb mode */ | ||
491 | port->write_urb_busy = 0; | 505 | port->write_urb_busy = 0; |
492 | } | ||
493 | 506 | ||
494 | if (status) { | 507 | if (status) { |
495 | dbg("%s - nonzero write bulk status received: %d", | 508 | dbg("%s - nonzero multi-urb write bulk status " |
496 | __func__, status); | 509 | "received: %d", __func__, status); |
497 | return; | 510 | kfifo_reset(port->write_fifo); |
511 | } else | ||
512 | usb_serial_generic_write_start(port); | ||
498 | } | 513 | } |
514 | |||
499 | usb_serial_port_softint(port); | 515 | usb_serial_port_softint(port); |
500 | } | 516 | } |
501 | EXPORT_SYMBOL_GPL(usb_serial_generic_write_bulk_callback); | 517 | EXPORT_SYMBOL_GPL(usb_serial_generic_write_bulk_callback); |
@@ -560,6 +576,33 @@ int usb_serial_handle_break(struct usb_serial_port *port) | |||
560 | } | 576 | } |
561 | EXPORT_SYMBOL_GPL(usb_serial_handle_break); | 577 | EXPORT_SYMBOL_GPL(usb_serial_handle_break); |
562 | 578 | ||
579 | int usb_serial_generic_resume(struct usb_serial *serial) | ||
580 | { | ||
581 | struct usb_serial_port *port; | ||
582 | int i, c = 0, r; | ||
583 | |||
584 | for (i = 0; i < serial->num_ports; i++) { | ||
585 | port = serial->port[i]; | ||
586 | if (!port->port.count) | ||
587 | continue; | ||
588 | |||
589 | if (port->read_urb) { | ||
590 | r = usb_submit_urb(port->read_urb, GFP_NOIO); | ||
591 | if (r < 0) | ||
592 | c++; | ||
593 | } | ||
594 | |||
595 | if (port->write_urb) { | ||
596 | r = usb_serial_generic_write_start(port); | ||
597 | if (r < 0) | ||
598 | c++; | ||
599 | } | ||
600 | } | ||
601 | |||
602 | return c ? -EIO : 0; | ||
603 | } | ||
604 | EXPORT_SYMBOL_GPL(usb_serial_generic_resume); | ||
605 | |||
563 | void usb_serial_generic_disconnect(struct usb_serial *serial) | 606 | void usb_serial_generic_disconnect(struct usb_serial *serial) |
564 | { | 607 | { |
565 | int i; | 608 | int i; |
diff --git a/drivers/usb/serial/io_edgeport.c b/drivers/usb/serial/io_edgeport.c index 0191693625d6..b97960ac92f2 100644 --- a/drivers/usb/serial/io_edgeport.c +++ b/drivers/usb/serial/io_edgeport.c | |||
@@ -205,8 +205,7 @@ static void edge_bulk_out_data_callback(struct urb *urb); | |||
205 | static void edge_bulk_out_cmd_callback(struct urb *urb); | 205 | static void edge_bulk_out_cmd_callback(struct urb *urb); |
206 | 206 | ||
207 | /* function prototypes for the usbserial callbacks */ | 207 | /* function prototypes for the usbserial callbacks */ |
208 | static int edge_open(struct tty_struct *tty, struct usb_serial_port *port, | 208 | static int edge_open(struct tty_struct *tty, struct usb_serial_port *port); |
209 | struct file *filp); | ||
210 | static void edge_close(struct usb_serial_port *port); | 209 | static void edge_close(struct usb_serial_port *port); |
211 | static int edge_write(struct tty_struct *tty, struct usb_serial_port *port, | 210 | static int edge_write(struct tty_struct *tty, struct usb_serial_port *port, |
212 | const unsigned char *buf, int count); | 211 | const unsigned char *buf, int count); |
@@ -852,8 +851,7 @@ static void edge_bulk_out_cmd_callback(struct urb *urb) | |||
852 | * If successful, we return 0 | 851 | * If successful, we return 0 |
853 | * Otherwise we return a negative error number. | 852 | * Otherwise we return a negative error number. |
854 | *****************************************************************************/ | 853 | *****************************************************************************/ |
855 | static int edge_open(struct tty_struct *tty, | 854 | static int edge_open(struct tty_struct *tty, struct usb_serial_port *port) |
856 | struct usb_serial_port *port, struct file *filp) | ||
857 | { | 855 | { |
858 | struct edgeport_port *edge_port = usb_get_serial_port_data(port); | 856 | struct edgeport_port *edge_port = usb_get_serial_port_data(port); |
859 | struct usb_serial *serial; | 857 | struct usb_serial *serial; |
@@ -2542,7 +2540,7 @@ static int calc_baud_rate_divisor(int baudrate, int *divisor) | |||
2542 | 2540 | ||
2543 | /***************************************************************************** | 2541 | /***************************************************************************** |
2544 | * send_cmd_write_uart_register | 2542 | * send_cmd_write_uart_register |
2545 | * this function builds up a uart register message and sends to to the device. | 2543 | * this function builds up a uart register message and sends to the device. |
2546 | *****************************************************************************/ | 2544 | *****************************************************************************/ |
2547 | static int send_cmd_write_uart_register(struct edgeport_port *edge_port, | 2545 | static int send_cmd_write_uart_register(struct edgeport_port *edge_port, |
2548 | __u8 regNum, __u8 regValue) | 2546 | __u8 regNum, __u8 regValue) |
diff --git a/drivers/usb/serial/io_ti.c b/drivers/usb/serial/io_ti.c index e8bc42f92e79..d4cc0f7af400 100644 --- a/drivers/usb/serial/io_ti.c +++ b/drivers/usb/serial/io_ti.c | |||
@@ -1831,8 +1831,7 @@ static void edge_bulk_out_callback(struct urb *urb) | |||
1831 | tty_kref_put(tty); | 1831 | tty_kref_put(tty); |
1832 | } | 1832 | } |
1833 | 1833 | ||
1834 | static int edge_open(struct tty_struct *tty, | 1834 | static int edge_open(struct tty_struct *tty, struct usb_serial_port *port) |
1835 | struct usb_serial_port *port, struct file *filp) | ||
1836 | { | 1835 | { |
1837 | struct edgeport_port *edge_port = usb_get_serial_port_data(port); | 1836 | struct edgeport_port *edge_port = usb_get_serial_port_data(port); |
1838 | struct edgeport_serial *edge_serial; | 1837 | struct edgeport_serial *edge_serial; |
diff --git a/drivers/usb/serial/ipaq.c b/drivers/usb/serial/ipaq.c index 2545d45ce16f..24fcc64b837d 100644 --- a/drivers/usb/serial/ipaq.c +++ b/drivers/usb/serial/ipaq.c | |||
@@ -75,7 +75,7 @@ static int initial_wait; | |||
75 | 75 | ||
76 | /* Function prototypes for an ipaq */ | 76 | /* Function prototypes for an ipaq */ |
77 | static int ipaq_open(struct tty_struct *tty, | 77 | static int ipaq_open(struct tty_struct *tty, |
78 | struct usb_serial_port *port, struct file *filp); | 78 | struct usb_serial_port *port); |
79 | static void ipaq_close(struct usb_serial_port *port); | 79 | static void ipaq_close(struct usb_serial_port *port); |
80 | static int ipaq_calc_num_ports(struct usb_serial *serial); | 80 | static int ipaq_calc_num_ports(struct usb_serial *serial); |
81 | static int ipaq_startup(struct usb_serial *serial); | 81 | static int ipaq_startup(struct usb_serial *serial); |
@@ -587,7 +587,7 @@ static int bytes_in; | |||
587 | static int bytes_out; | 587 | static int bytes_out; |
588 | 588 | ||
589 | static int ipaq_open(struct tty_struct *tty, | 589 | static int ipaq_open(struct tty_struct *tty, |
590 | struct usb_serial_port *port, struct file *filp) | 590 | struct usb_serial_port *port) |
591 | { | 591 | { |
592 | struct usb_serial *serial = port->serial; | 592 | struct usb_serial *serial = port->serial; |
593 | struct ipaq_private *priv; | 593 | struct ipaq_private *priv; |
@@ -628,11 +628,6 @@ static int ipaq_open(struct tty_struct *tty, | |||
628 | priv->free_len += PACKET_SIZE; | 628 | priv->free_len += PACKET_SIZE; |
629 | } | 629 | } |
630 | 630 | ||
631 | if (tty) { | ||
632 | /* FIXME: These two are bogus */ | ||
633 | tty->raw = 1; | ||
634 | tty->real_raw = 1; | ||
635 | } | ||
636 | /* | 631 | /* |
637 | * Lose the small buffers usbserial provides. Make larger ones. | 632 | * Lose the small buffers usbserial provides. Make larger ones. |
638 | */ | 633 | */ |
diff --git a/drivers/usb/serial/ipw.c b/drivers/usb/serial/ipw.c index 29ad038b9c8d..727d323f092a 100644 --- a/drivers/usb/serial/ipw.c +++ b/drivers/usb/serial/ipw.c | |||
@@ -193,8 +193,7 @@ static void ipw_read_bulk_callback(struct urb *urb) | |||
193 | return; | 193 | return; |
194 | } | 194 | } |
195 | 195 | ||
196 | static int ipw_open(struct tty_struct *tty, | 196 | static int ipw_open(struct tty_struct *tty, struct usb_serial_port *port) |
197 | struct usb_serial_port *port, struct file *filp) | ||
198 | { | 197 | { |
199 | struct usb_device *dev = port->serial->dev; | 198 | struct usb_device *dev = port->serial->dev; |
200 | u8 buf_flow_static[16] = IPW_BYTES_FLOWINIT; | 199 | u8 buf_flow_static[16] = IPW_BYTES_FLOWINIT; |
diff --git a/drivers/usb/serial/ir-usb.c b/drivers/usb/serial/ir-usb.c index 66009b6b763a..95d8d26b9a44 100644 --- a/drivers/usb/serial/ir-usb.c +++ b/drivers/usb/serial/ir-usb.c | |||
@@ -86,8 +86,7 @@ static int buffer_size; | |||
86 | static int xbof = -1; | 86 | static int xbof = -1; |
87 | 87 | ||
88 | static int ir_startup (struct usb_serial *serial); | 88 | static int ir_startup (struct usb_serial *serial); |
89 | static int ir_open(struct tty_struct *tty, struct usb_serial_port *port, | 89 | static int ir_open(struct tty_struct *tty, struct usb_serial_port *port); |
90 | struct file *filep); | ||
91 | static void ir_close(struct usb_serial_port *port); | 90 | static void ir_close(struct usb_serial_port *port); |
92 | static int ir_write(struct tty_struct *tty, struct usb_serial_port *port, | 91 | static int ir_write(struct tty_struct *tty, struct usb_serial_port *port, |
93 | const unsigned char *buf, int count); | 92 | const unsigned char *buf, int count); |
@@ -296,8 +295,7 @@ static int ir_startup(struct usb_serial *serial) | |||
296 | return 0; | 295 | return 0; |
297 | } | 296 | } |
298 | 297 | ||
299 | static int ir_open(struct tty_struct *tty, | 298 | static int ir_open(struct tty_struct *tty, struct usb_serial_port *port) |
300 | struct usb_serial_port *port, struct file *filp) | ||
301 | { | 299 | { |
302 | char *buffer; | 300 | char *buffer; |
303 | int result = 0; | 301 | int result = 0; |
diff --git a/drivers/usb/serial/iuu_phoenix.c b/drivers/usb/serial/iuu_phoenix.c index 96873a7a32b0..e6e02b178d2b 100644 --- a/drivers/usb/serial/iuu_phoenix.c +++ b/drivers/usb/serial/iuu_phoenix.c | |||
@@ -40,7 +40,7 @@ static int debug; | |||
40 | /* | 40 | /* |
41 | * Version Information | 41 | * Version Information |
42 | */ | 42 | */ |
43 | #define DRIVER_VERSION "v0.10" | 43 | #define DRIVER_VERSION "v0.11" |
44 | #define DRIVER_DESC "Infinity USB Unlimited Phoenix driver" | 44 | #define DRIVER_DESC "Infinity USB Unlimited Phoenix driver" |
45 | 45 | ||
46 | static struct usb_device_id id_table[] = { | 46 | static struct usb_device_id id_table[] = { |
@@ -64,6 +64,7 @@ static int cdmode = 1; | |||
64 | static int iuu_cardin; | 64 | static int iuu_cardin; |
65 | static int iuu_cardout; | 65 | static int iuu_cardout; |
66 | static int xmas; | 66 | static int xmas; |
67 | static int vcc_default = 5; | ||
67 | 68 | ||
68 | static void read_rxcmd_callback(struct urb *urb); | 69 | static void read_rxcmd_callback(struct urb *urb); |
69 | 70 | ||
@@ -71,7 +72,6 @@ struct iuu_private { | |||
71 | spinlock_t lock; /* store irq state */ | 72 | spinlock_t lock; /* store irq state */ |
72 | wait_queue_head_t delta_msr_wait; | 73 | wait_queue_head_t delta_msr_wait; |
73 | u8 line_status; | 74 | u8 line_status; |
74 | u8 termios_initialized; | ||
75 | int tiostatus; /* store IUART SIGNAL for tiocmget call */ | 75 | int tiostatus; /* store IUART SIGNAL for tiocmget call */ |
76 | u8 reset; /* if 1 reset is needed */ | 76 | u8 reset; /* if 1 reset is needed */ |
77 | int poll; /* number of poll */ | 77 | int poll; /* number of poll */ |
@@ -80,6 +80,7 @@ struct iuu_private { | |||
80 | u8 *buf; /* used for initialize speed */ | 80 | u8 *buf; /* used for initialize speed */ |
81 | u8 *dbgbuf; /* debug buffer */ | 81 | u8 *dbgbuf; /* debug buffer */ |
82 | u8 len; | 82 | u8 len; |
83 | int vcc; /* vcc (either 3 or 5 V) */ | ||
83 | }; | 84 | }; |
84 | 85 | ||
85 | 86 | ||
@@ -115,6 +116,7 @@ static int iuu_startup(struct usb_serial *serial) | |||
115 | kfree(priv); | 116 | kfree(priv); |
116 | return -ENOMEM; | 117 | return -ENOMEM; |
117 | } | 118 | } |
119 | priv->vcc = vcc_default; | ||
118 | spin_lock_init(&priv->lock); | 120 | spin_lock_init(&priv->lock); |
119 | init_waitqueue_head(&priv->delta_msr_wait); | 121 | init_waitqueue_head(&priv->delta_msr_wait); |
120 | usb_set_serial_port_data(serial->port[0], priv); | 122 | usb_set_serial_port_data(serial->port[0], priv); |
@@ -1010,22 +1012,28 @@ static void iuu_close(struct usb_serial_port *port) | |||
1010 | usb_kill_urb(port->write_urb); | 1012 | usb_kill_urb(port->write_urb); |
1011 | usb_kill_urb(port->read_urb); | 1013 | usb_kill_urb(port->read_urb); |
1012 | usb_kill_urb(port->interrupt_in_urb); | 1014 | usb_kill_urb(port->interrupt_in_urb); |
1013 | msleep(1000); | ||
1014 | /* wait one second to free all buffers */ | ||
1015 | iuu_led(port, 0, 0, 0xF000, 0xFF); | 1015 | iuu_led(port, 0, 0, 0xF000, 0xFF); |
1016 | msleep(1000); | ||
1017 | usb_reset_device(port->serial->dev); | ||
1018 | } | 1016 | } |
1019 | } | 1017 | } |
1020 | 1018 | ||
1021 | static int iuu_open(struct tty_struct *tty, | 1019 | static void iuu_init_termios(struct tty_struct *tty) |
1022 | struct usb_serial_port *port, struct file *filp) | 1020 | { |
1021 | *(tty->termios) = tty_std_termios; | ||
1022 | tty->termios->c_cflag = CLOCAL | CREAD | CS8 | B9600 | ||
1023 | | TIOCM_CTS | CSTOPB | PARENB; | ||
1024 | tty->termios->c_ispeed = 9600; | ||
1025 | tty->termios->c_ospeed = 9600; | ||
1026 | tty->termios->c_lflag = 0; | ||
1027 | tty->termios->c_oflag = 0; | ||
1028 | tty->termios->c_iflag = 0; | ||
1029 | } | ||
1030 | |||
1031 | static int iuu_open(struct tty_struct *tty, struct usb_serial_port *port) | ||
1023 | { | 1032 | { |
1024 | struct usb_serial *serial = port->serial; | 1033 | struct usb_serial *serial = port->serial; |
1025 | u8 *buf; | 1034 | u8 *buf; |
1026 | int result; | 1035 | int result; |
1027 | u32 actual; | 1036 | u32 actual; |
1028 | unsigned long flags; | ||
1029 | struct iuu_private *priv = usb_get_serial_port_data(port); | 1037 | struct iuu_private *priv = usb_get_serial_port_data(port); |
1030 | 1038 | ||
1031 | dbg("%s - port %d", __func__, port->number); | 1039 | dbg("%s - port %d", __func__, port->number); |
@@ -1064,21 +1072,7 @@ static int iuu_open(struct tty_struct *tty, | |||
1064 | port->bulk_in_buffer, 512, | 1072 | port->bulk_in_buffer, 512, |
1065 | NULL, NULL); | 1073 | NULL, NULL); |
1066 | 1074 | ||
1067 | /* set the termios structure */ | 1075 | priv->poll = 0; |
1068 | spin_lock_irqsave(&priv->lock, flags); | ||
1069 | if (tty && !priv->termios_initialized) { | ||
1070 | *(tty->termios) = tty_std_termios; | ||
1071 | tty->termios->c_cflag = CLOCAL | CREAD | CS8 | B9600 | ||
1072 | | TIOCM_CTS | CSTOPB | PARENB; | ||
1073 | tty->termios->c_ispeed = 9600; | ||
1074 | tty->termios->c_ospeed = 9600; | ||
1075 | tty->termios->c_lflag = 0; | ||
1076 | tty->termios->c_oflag = 0; | ||
1077 | tty->termios->c_iflag = 0; | ||
1078 | priv->termios_initialized = 1; | ||
1079 | priv->poll = 0; | ||
1080 | } | ||
1081 | spin_unlock_irqrestore(&priv->lock, flags); | ||
1082 | 1076 | ||
1083 | /* initialize writebuf */ | 1077 | /* initialize writebuf */ |
1084 | #define FISH(a, b, c, d) do { \ | 1078 | #define FISH(a, b, c, d) do { \ |
@@ -1187,6 +1181,95 @@ static int iuu_open(struct tty_struct *tty, | |||
1187 | return result; | 1181 | return result; |
1188 | } | 1182 | } |
1189 | 1183 | ||
1184 | /* how to change VCC */ | ||
1185 | static int iuu_vcc_set(struct usb_serial_port *port, unsigned int vcc) | ||
1186 | { | ||
1187 | int status; | ||
1188 | u8 *buf; | ||
1189 | |||
1190 | buf = kmalloc(5, GFP_KERNEL); | ||
1191 | if (!buf) | ||
1192 | return -ENOMEM; | ||
1193 | |||
1194 | dbg("%s - enter", __func__); | ||
1195 | |||
1196 | buf[0] = IUU_SET_VCC; | ||
1197 | buf[1] = vcc & 0xFF; | ||
1198 | buf[2] = (vcc >> 8) & 0xFF; | ||
1199 | buf[3] = (vcc >> 16) & 0xFF; | ||
1200 | buf[4] = (vcc >> 24) & 0xFF; | ||
1201 | |||
1202 | status = bulk_immediate(port, buf, 5); | ||
1203 | kfree(buf); | ||
1204 | |||
1205 | if (status != IUU_OPERATION_OK) | ||
1206 | dbg("%s - vcc error status = %2x", __func__, status); | ||
1207 | else | ||
1208 | dbg("%s - vcc OK !", __func__); | ||
1209 | |||
1210 | return status; | ||
1211 | } | ||
1212 | |||
1213 | /* | ||
1214 | * Sysfs Attributes | ||
1215 | */ | ||
1216 | |||
1217 | static ssize_t show_vcc_mode(struct device *dev, | ||
1218 | struct device_attribute *attr, char *buf) | ||
1219 | { | ||
1220 | struct usb_serial_port *port = to_usb_serial_port(dev); | ||
1221 | struct iuu_private *priv = usb_get_serial_port_data(port); | ||
1222 | |||
1223 | return sprintf(buf, "%d\n", priv->vcc); | ||
1224 | } | ||
1225 | |||
1226 | static ssize_t store_vcc_mode(struct device *dev, | ||
1227 | struct device_attribute *attr, const char *buf, size_t count) | ||
1228 | { | ||
1229 | struct usb_serial_port *port = to_usb_serial_port(dev); | ||
1230 | struct iuu_private *priv = usb_get_serial_port_data(port); | ||
1231 | unsigned long v; | ||
1232 | |||
1233 | if (strict_strtoul(buf, 10, &v)) { | ||
1234 | dev_err(dev, "%s - vcc_mode: %s is not a unsigned long\n", | ||
1235 | __func__, buf); | ||
1236 | goto fail_store_vcc_mode; | ||
1237 | } | ||
1238 | |||
1239 | dbg("%s: setting vcc_mode = %ld", __func__, v); | ||
1240 | |||
1241 | if ((v != 3) && (v != 5)) { | ||
1242 | dev_err(dev, "%s - vcc_mode %ld is invalid\n", __func__, v); | ||
1243 | } else { | ||
1244 | iuu_vcc_set(port, v); | ||
1245 | priv->vcc = v; | ||
1246 | } | ||
1247 | fail_store_vcc_mode: | ||
1248 | return count; | ||
1249 | } | ||
1250 | |||
1251 | static DEVICE_ATTR(vcc_mode, S_IRUSR | S_IWUSR, show_vcc_mode, | ||
1252 | store_vcc_mode); | ||
1253 | |||
1254 | static int iuu_create_sysfs_attrs(struct usb_serial_port *port) | ||
1255 | { | ||
1256 | dbg("%s", __func__); | ||
1257 | |||
1258 | return device_create_file(&port->dev, &dev_attr_vcc_mode); | ||
1259 | } | ||
1260 | |||
1261 | static int iuu_remove_sysfs_attrs(struct usb_serial_port *port) | ||
1262 | { | ||
1263 | dbg("%s", __func__); | ||
1264 | |||
1265 | device_remove_file(&port->dev, &dev_attr_vcc_mode); | ||
1266 | return 0; | ||
1267 | } | ||
1268 | |||
1269 | /* | ||
1270 | * End Sysfs Attributes | ||
1271 | */ | ||
1272 | |||
1190 | static struct usb_serial_driver iuu_device = { | 1273 | static struct usb_serial_driver iuu_device = { |
1191 | .driver = { | 1274 | .driver = { |
1192 | .owner = THIS_MODULE, | 1275 | .owner = THIS_MODULE, |
@@ -1194,6 +1277,8 @@ static struct usb_serial_driver iuu_device = { | |||
1194 | }, | 1277 | }, |
1195 | .id_table = id_table, | 1278 | .id_table = id_table, |
1196 | .num_ports = 1, | 1279 | .num_ports = 1, |
1280 | .port_probe = iuu_create_sysfs_attrs, | ||
1281 | .port_remove = iuu_remove_sysfs_attrs, | ||
1197 | .open = iuu_open, | 1282 | .open = iuu_open, |
1198 | .close = iuu_close, | 1283 | .close = iuu_close, |
1199 | .write = iuu_uart_write, | 1284 | .write = iuu_uart_write, |
@@ -1201,6 +1286,7 @@ static struct usb_serial_driver iuu_device = { | |||
1201 | .tiocmget = iuu_tiocmget, | 1286 | .tiocmget = iuu_tiocmget, |
1202 | .tiocmset = iuu_tiocmset, | 1287 | .tiocmset = iuu_tiocmset, |
1203 | .set_termios = iuu_set_termios, | 1288 | .set_termios = iuu_set_termios, |
1289 | .init_termios = iuu_init_termios, | ||
1204 | .attach = iuu_startup, | 1290 | .attach = iuu_startup, |
1205 | .release = iuu_release, | 1291 | .release = iuu_release, |
1206 | }; | 1292 | }; |
@@ -1242,14 +1328,19 @@ module_param(debug, bool, S_IRUGO | S_IWUSR); | |||
1242 | MODULE_PARM_DESC(debug, "Debug enabled or not"); | 1328 | MODULE_PARM_DESC(debug, "Debug enabled or not"); |
1243 | 1329 | ||
1244 | module_param(xmas, bool, S_IRUGO | S_IWUSR); | 1330 | module_param(xmas, bool, S_IRUGO | S_IWUSR); |
1245 | MODULE_PARM_DESC(xmas, "xmas color enabled or not"); | 1331 | MODULE_PARM_DESC(xmas, "Xmas colors enabled or not"); |
1246 | 1332 | ||
1247 | module_param(boost, int, S_IRUGO | S_IWUSR); | 1333 | module_param(boost, int, S_IRUGO | S_IWUSR); |
1248 | MODULE_PARM_DESC(boost, "overclock boost percent 100 to 500"); | 1334 | MODULE_PARM_DESC(boost, "Card overclock boost (in percent 100-500)"); |
1249 | 1335 | ||
1250 | module_param(clockmode, int, S_IRUGO | S_IWUSR); | 1336 | module_param(clockmode, int, S_IRUGO | S_IWUSR); |
1251 | MODULE_PARM_DESC(clockmode, "1=3Mhz579,2=3Mhz680,3=6Mhz"); | 1337 | MODULE_PARM_DESC(clockmode, "Card clock mode (1=3.579 MHz, 2=3.680 MHz, " |
1338 | "3=6 Mhz)"); | ||
1252 | 1339 | ||
1253 | module_param(cdmode, int, S_IRUGO | S_IWUSR); | 1340 | module_param(cdmode, int, S_IRUGO | S_IWUSR); |
1254 | MODULE_PARM_DESC(cdmode, "Card detect mode 0=none, 1=CD, 2=!CD, 3=DSR, " | 1341 | MODULE_PARM_DESC(cdmode, "Card detect mode (0=none, 1=CD, 2=!CD, 3=DSR, " |
1255 | "4=!DSR, 5=CTS, 6=!CTS, 7=RING, 8=!RING"); | 1342 | "4=!DSR, 5=CTS, 6=!CTS, 7=RING, 8=!RING)"); |
1343 | |||
1344 | module_param(vcc_default, int, S_IRUGO | S_IWUSR); | ||
1345 | MODULE_PARM_DESC(vcc_default, "Set default VCC (either 3 for 3.3V or 5 " | ||
1346 | "for 5V). Default to 5."); | ||
diff --git a/drivers/usb/serial/keyspan.c b/drivers/usb/serial/keyspan.c index 2594b8743d3f..f8c4b07033ff 100644 --- a/drivers/usb/serial/keyspan.c +++ b/drivers/usb/serial/keyspan.c | |||
@@ -1209,8 +1209,7 @@ static int keyspan_write_room(struct tty_struct *tty) | |||
1209 | } | 1209 | } |
1210 | 1210 | ||
1211 | 1211 | ||
1212 | static int keyspan_open(struct tty_struct *tty, | 1212 | static int keyspan_open(struct tty_struct *tty, struct usb_serial_port *port) |
1213 | struct usb_serial_port *port, struct file *filp) | ||
1214 | { | 1213 | { |
1215 | struct keyspan_port_private *p_priv; | 1214 | struct keyspan_port_private *p_priv; |
1216 | struct keyspan_serial_private *s_priv; | 1215 | struct keyspan_serial_private *s_priv; |
diff --git a/drivers/usb/serial/keyspan.h b/drivers/usb/serial/keyspan.h index 3107ed15af64..30771e5b3973 100644 --- a/drivers/usb/serial/keyspan.h +++ b/drivers/usb/serial/keyspan.h | |||
@@ -36,8 +36,7 @@ | |||
36 | 36 | ||
37 | /* Function prototypes for Keyspan serial converter */ | 37 | /* Function prototypes for Keyspan serial converter */ |
38 | static int keyspan_open (struct tty_struct *tty, | 38 | static int keyspan_open (struct tty_struct *tty, |
39 | struct usb_serial_port *port, | 39 | struct usb_serial_port *port); |
40 | struct file *filp); | ||
41 | static void keyspan_close (struct usb_serial_port *port); | 40 | static void keyspan_close (struct usb_serial_port *port); |
42 | static void keyspan_dtr_rts (struct usb_serial_port *port, int on); | 41 | static void keyspan_dtr_rts (struct usb_serial_port *port, int on); |
43 | static int keyspan_startup (struct usb_serial *serial); | 42 | static int keyspan_startup (struct usb_serial *serial); |
diff --git a/drivers/usb/serial/keyspan_pda.c b/drivers/usb/serial/keyspan_pda.c index d0b12e40c2b1..257c16cc6b2a 100644 --- a/drivers/usb/serial/keyspan_pda.c +++ b/drivers/usb/serial/keyspan_pda.c | |||
@@ -681,7 +681,7 @@ static int keyspan_pda_carrier_raised(struct usb_serial_port *port) | |||
681 | 681 | ||
682 | 682 | ||
683 | static int keyspan_pda_open(struct tty_struct *tty, | 683 | static int keyspan_pda_open(struct tty_struct *tty, |
684 | struct usb_serial_port *port, struct file *filp) | 684 | struct usb_serial_port *port) |
685 | { | 685 | { |
686 | struct usb_serial *serial = port->serial; | 686 | struct usb_serial *serial = port->serial; |
687 | unsigned char room; | 687 | unsigned char room; |
diff --git a/drivers/usb/serial/kl5kusb105.c b/drivers/usb/serial/kl5kusb105.c index 0f44bb8e8d4f..f7373371b137 100644 --- a/drivers/usb/serial/kl5kusb105.c +++ b/drivers/usb/serial/kl5kusb105.c | |||
@@ -38,7 +38,7 @@ | |||
38 | * 0.3a - implemented pools of write URBs | 38 | * 0.3a - implemented pools of write URBs |
39 | * 0.3 - alpha version for public testing | 39 | * 0.3 - alpha version for public testing |
40 | * 0.2 - TIOCMGET works, so autopilot(1) can be used! | 40 | * 0.2 - TIOCMGET works, so autopilot(1) can be used! |
41 | * 0.1 - can be used to to pilot-xfer -p /dev/ttyUSB0 -l | 41 | * 0.1 - can be used to do pilot-xfer -p /dev/ttyUSB0 -l |
42 | * | 42 | * |
43 | * The driver skeleton is mainly based on mct_u232.c and various other | 43 | * The driver skeleton is mainly based on mct_u232.c and various other |
44 | * pieces of code shamelessly copied from the drivers/usb/serial/ directory. | 44 | * pieces of code shamelessly copied from the drivers/usb/serial/ directory. |
@@ -75,8 +75,7 @@ static int debug; | |||
75 | static int klsi_105_startup(struct usb_serial *serial); | 75 | static int klsi_105_startup(struct usb_serial *serial); |
76 | static void klsi_105_disconnect(struct usb_serial *serial); | 76 | static void klsi_105_disconnect(struct usb_serial *serial); |
77 | static void klsi_105_release(struct usb_serial *serial); | 77 | static void klsi_105_release(struct usb_serial *serial); |
78 | static int klsi_105_open(struct tty_struct *tty, | 78 | static int klsi_105_open(struct tty_struct *tty, struct usb_serial_port *port); |
79 | struct usb_serial_port *port, struct file *filp); | ||
80 | static void klsi_105_close(struct usb_serial_port *port); | 79 | static void klsi_105_close(struct usb_serial_port *port); |
81 | static int klsi_105_write(struct tty_struct *tty, | 80 | static int klsi_105_write(struct tty_struct *tty, |
82 | struct usb_serial_port *port, const unsigned char *buf, int count); | 81 | struct usb_serial_port *port, const unsigned char *buf, int count); |
@@ -358,8 +357,7 @@ static void klsi_105_release(struct usb_serial *serial) | |||
358 | } | 357 | } |
359 | } /* klsi_105_release */ | 358 | } /* klsi_105_release */ |
360 | 359 | ||
361 | static int klsi_105_open(struct tty_struct *tty, | 360 | static int klsi_105_open(struct tty_struct *tty, struct usb_serial_port *port) |
362 | struct usb_serial_port *port, struct file *filp) | ||
363 | { | 361 | { |
364 | struct klsi_105_private *priv = usb_get_serial_port_data(port); | 362 | struct klsi_105_private *priv = usb_get_serial_port_data(port); |
365 | int retval = 0; | 363 | int retval = 0; |
@@ -371,10 +369,6 @@ static int klsi_105_open(struct tty_struct *tty, | |||
371 | 369 | ||
372 | dbg("%s port %d", __func__, port->number); | 370 | dbg("%s port %d", __func__, port->number); |
373 | 371 | ||
374 | /* force low_latency on so that our tty_push actually forces | ||
375 | * the data through | ||
376 | * tty->low_latency = 1; */ | ||
377 | |||
378 | /* Do a defined restart: | 372 | /* Do a defined restart: |
379 | * Set up sane default baud rate and send the 'READ_ON' | 373 | * Set up sane default baud rate and send the 'READ_ON' |
380 | * vendor command. | 374 | * vendor command. |
diff --git a/drivers/usb/serial/kobil_sct.c b/drivers/usb/serial/kobil_sct.c index 6db0e561f680..45ea694b3ae6 100644 --- a/drivers/usb/serial/kobil_sct.c +++ b/drivers/usb/serial/kobil_sct.c | |||
@@ -70,8 +70,7 @@ static int debug; | |||
70 | /* Function prototypes */ | 70 | /* Function prototypes */ |
71 | static int kobil_startup(struct usb_serial *serial); | 71 | static int kobil_startup(struct usb_serial *serial); |
72 | static void kobil_release(struct usb_serial *serial); | 72 | static void kobil_release(struct usb_serial *serial); |
73 | static int kobil_open(struct tty_struct *tty, | 73 | static int kobil_open(struct tty_struct *tty, struct usb_serial_port *port); |
74 | struct usb_serial_port *port, struct file *filp); | ||
75 | static void kobil_close(struct usb_serial_port *port); | 74 | static void kobil_close(struct usb_serial_port *port); |
76 | static int kobil_write(struct tty_struct *tty, struct usb_serial_port *port, | 75 | static int kobil_write(struct tty_struct *tty, struct usb_serial_port *port, |
77 | const unsigned char *buf, int count); | 76 | const unsigned char *buf, int count); |
@@ -85,7 +84,7 @@ static void kobil_read_int_callback(struct urb *urb); | |||
85 | static void kobil_write_callback(struct urb *purb); | 84 | static void kobil_write_callback(struct urb *purb); |
86 | static void kobil_set_termios(struct tty_struct *tty, | 85 | static void kobil_set_termios(struct tty_struct *tty, |
87 | struct usb_serial_port *port, struct ktermios *old); | 86 | struct usb_serial_port *port, struct ktermios *old); |
88 | 87 | static void kobil_init_termios(struct tty_struct *tty); | |
89 | 88 | ||
90 | static struct usb_device_id id_table [] = { | 89 | static struct usb_device_id id_table [] = { |
91 | { USB_DEVICE(KOBIL_VENDOR_ID, KOBIL_ADAPTER_B_PRODUCT_ID) }, | 90 | { USB_DEVICE(KOBIL_VENDOR_ID, KOBIL_ADAPTER_B_PRODUCT_ID) }, |
@@ -120,6 +119,7 @@ static struct usb_serial_driver kobil_device = { | |||
120 | .release = kobil_release, | 119 | .release = kobil_release, |
121 | .ioctl = kobil_ioctl, | 120 | .ioctl = kobil_ioctl, |
122 | .set_termios = kobil_set_termios, | 121 | .set_termios = kobil_set_termios, |
122 | .init_termios = kobil_init_termios, | ||
123 | .tiocmget = kobil_tiocmget, | 123 | .tiocmget = kobil_tiocmget, |
124 | .tiocmset = kobil_tiocmset, | 124 | .tiocmset = kobil_tiocmset, |
125 | .open = kobil_open, | 125 | .open = kobil_open, |
@@ -210,9 +210,17 @@ static void kobil_release(struct usb_serial *serial) | |||
210 | kfree(usb_get_serial_port_data(serial->port[i])); | 210 | kfree(usb_get_serial_port_data(serial->port[i])); |
211 | } | 211 | } |
212 | 212 | ||
213 | static void kobil_init_termios(struct tty_struct *tty) | ||
214 | { | ||
215 | /* Default to echo off and other sane device settings */ | ||
216 | tty->termios->c_lflag = 0; | ||
217 | tty->termios->c_lflag &= ~(ISIG | ICANON | ECHO | IEXTEN | XCASE); | ||
218 | tty->termios->c_iflag = IGNBRK | IGNPAR | IXOFF; | ||
219 | /* do NOT translate CR to CR-NL (0x0A -> 0x0A 0x0D) */ | ||
220 | tty->termios->c_oflag &= ~ONLCR; | ||
221 | } | ||
213 | 222 | ||
214 | static int kobil_open(struct tty_struct *tty, | 223 | static int kobil_open(struct tty_struct *tty, struct usb_serial_port *port) |
215 | struct usb_serial_port *port, struct file *filp) | ||
216 | { | 224 | { |
217 | int result = 0; | 225 | int result = 0; |
218 | struct kobil_private *priv; | 226 | struct kobil_private *priv; |
@@ -226,16 +234,6 @@ static int kobil_open(struct tty_struct *tty, | |||
226 | /* someone sets the dev to 0 if the close method has been called */ | 234 | /* someone sets the dev to 0 if the close method has been called */ |
227 | port->interrupt_in_urb->dev = port->serial->dev; | 235 | port->interrupt_in_urb->dev = port->serial->dev; |
228 | 236 | ||
229 | if (tty) { | ||
230 | |||
231 | /* Default to echo off and other sane device settings */ | ||
232 | tty->termios->c_lflag = 0; | ||
233 | tty->termios->c_lflag &= ~(ISIG | ICANON | ECHO | IEXTEN | | ||
234 | XCASE); | ||
235 | tty->termios->c_iflag = IGNBRK | IGNPAR | IXOFF; | ||
236 | /* do NOT translate CR to CR-NL (0x0A -> 0x0A 0x0D) */ | ||
237 | tty->termios->c_oflag &= ~ONLCR; | ||
238 | } | ||
239 | /* allocate memory for transfer buffer */ | 237 | /* allocate memory for transfer buffer */ |
240 | transfer_buffer = kzalloc(transfer_buffer_length, GFP_KERNEL); | 238 | transfer_buffer = kzalloc(transfer_buffer_length, GFP_KERNEL); |
241 | if (!transfer_buffer) | 239 | if (!transfer_buffer) |
diff --git a/drivers/usb/serial/mct_u232.c b/drivers/usb/serial/mct_u232.c index d8825e159aa5..ad4998bbf16f 100644 --- a/drivers/usb/serial/mct_u232.c +++ b/drivers/usb/serial/mct_u232.c | |||
@@ -93,8 +93,7 @@ static int debug; | |||
93 | */ | 93 | */ |
94 | static int mct_u232_startup(struct usb_serial *serial); | 94 | static int mct_u232_startup(struct usb_serial *serial); |
95 | static void mct_u232_release(struct usb_serial *serial); | 95 | static void mct_u232_release(struct usb_serial *serial); |
96 | static int mct_u232_open(struct tty_struct *tty, | 96 | static int mct_u232_open(struct tty_struct *tty, struct usb_serial_port *port); |
97 | struct usb_serial_port *port, struct file *filp); | ||
98 | static void mct_u232_close(struct usb_serial_port *port); | 97 | static void mct_u232_close(struct usb_serial_port *port); |
99 | static void mct_u232_dtr_rts(struct usb_serial_port *port, int on); | 98 | static void mct_u232_dtr_rts(struct usb_serial_port *port, int on); |
100 | static void mct_u232_read_int_callback(struct urb *urb); | 99 | static void mct_u232_read_int_callback(struct urb *urb); |
@@ -421,8 +420,7 @@ static void mct_u232_release(struct usb_serial *serial) | |||
421 | } | 420 | } |
422 | } /* mct_u232_release */ | 421 | } /* mct_u232_release */ |
423 | 422 | ||
424 | static int mct_u232_open(struct tty_struct *tty, | 423 | static int mct_u232_open(struct tty_struct *tty, struct usb_serial_port *port) |
425 | struct usb_serial_port *port, struct file *filp) | ||
426 | { | 424 | { |
427 | struct usb_serial *serial = port->serial; | 425 | struct usb_serial *serial = port->serial; |
428 | struct mct_u232_private *priv = usb_get_serial_port_data(port); | 426 | struct mct_u232_private *priv = usb_get_serial_port_data(port); |
@@ -568,10 +566,13 @@ static void mct_u232_read_int_callback(struct urb *urb) | |||
568 | * Work-a-round: handle the 'usual' bulk-in pipe here | 566 | * Work-a-round: handle the 'usual' bulk-in pipe here |
569 | */ | 567 | */ |
570 | if (urb->transfer_buffer_length > 2) { | 568 | if (urb->transfer_buffer_length > 2) { |
571 | tty = tty_port_tty_get(&port->port); | ||
572 | if (urb->actual_length) { | 569 | if (urb->actual_length) { |
573 | tty_insert_flip_string(tty, data, urb->actual_length); | 570 | tty = tty_port_tty_get(&port->port); |
574 | tty_flip_buffer_push(tty); | 571 | if (tty) { |
572 | tty_insert_flip_string(tty, data, | ||
573 | urb->actual_length); | ||
574 | tty_flip_buffer_push(tty); | ||
575 | } | ||
575 | tty_kref_put(tty); | 576 | tty_kref_put(tty); |
576 | } | 577 | } |
577 | goto exit; | 578 | goto exit; |
diff --git a/drivers/usb/serial/mos7720.c b/drivers/usb/serial/mos7720.c index ccd4dd340d2c..763e32a44be0 100644 --- a/drivers/usb/serial/mos7720.c +++ b/drivers/usb/serial/mos7720.c | |||
@@ -85,7 +85,7 @@ static int debug; | |||
85 | #define MOSCHIP_DEVICE_ID_7720 0x7720 | 85 | #define MOSCHIP_DEVICE_ID_7720 0x7720 |
86 | #define MOSCHIP_DEVICE_ID_7715 0x7715 | 86 | #define MOSCHIP_DEVICE_ID_7715 0x7715 |
87 | 87 | ||
88 | static struct usb_device_id moschip_port_id_table [] = { | 88 | static struct usb_device_id moschip_port_id_table[] = { |
89 | { USB_DEVICE(USB_VENDOR_ID_MOSCHIP, MOSCHIP_DEVICE_ID_7720) }, | 89 | { USB_DEVICE(USB_VENDOR_ID_MOSCHIP, MOSCHIP_DEVICE_ID_7720) }, |
90 | { } /* terminating entry */ | 90 | { } /* terminating entry */ |
91 | }; | 91 | }; |
@@ -319,8 +319,7 @@ static int send_mos_cmd(struct usb_serial *serial, __u8 request, __u16 value, | |||
319 | return status; | 319 | return status; |
320 | } | 320 | } |
321 | 321 | ||
322 | static int mos7720_open(struct tty_struct *tty, | 322 | static int mos7720_open(struct tty_struct *tty, struct usb_serial_port *port) |
323 | struct usb_serial_port *port, struct file *filp) | ||
324 | { | 323 | { |
325 | struct usb_serial *serial; | 324 | struct usb_serial *serial; |
326 | struct usb_serial_port *port0; | 325 | struct usb_serial_port *port0; |
@@ -378,10 +377,14 @@ static int mos7720_open(struct tty_struct *tty, | |||
378 | /* Initialize MCS7720 -- Write Init values to corresponding Registers | 377 | /* Initialize MCS7720 -- Write Init values to corresponding Registers |
379 | * | 378 | * |
380 | * Register Index | 379 | * Register Index |
380 | * 0 : THR/RHR | ||
381 | * 1 : IER | 381 | * 1 : IER |
382 | * 2 : FCR | 382 | * 2 : FCR |
383 | * 3 : LCR | 383 | * 3 : LCR |
384 | * 4 : MCR | 384 | * 4 : MCR |
385 | * 5 : LSR | ||
386 | * 6 : MSR | ||
387 | * 7 : SPR | ||
385 | * | 388 | * |
386 | * 0x08 : SP1/2 Control Reg | 389 | * 0x08 : SP1/2 Control Reg |
387 | */ | 390 | */ |
@@ -1250,20 +1253,88 @@ static void mos7720_set_termios(struct tty_struct *tty, | |||
1250 | static int get_lsr_info(struct tty_struct *tty, | 1253 | static int get_lsr_info(struct tty_struct *tty, |
1251 | struct moschip_port *mos7720_port, unsigned int __user *value) | 1254 | struct moschip_port *mos7720_port, unsigned int __user *value) |
1252 | { | 1255 | { |
1253 | int count; | 1256 | struct usb_serial_port *port = tty->driver_data; |
1254 | unsigned int result = 0; | 1257 | unsigned int result = 0; |
1258 | unsigned char data = 0; | ||
1259 | int port_number = port->number - port->serial->minor; | ||
1260 | int count; | ||
1255 | 1261 | ||
1256 | count = mos7720_chars_in_buffer(tty); | 1262 | count = mos7720_chars_in_buffer(tty); |
1257 | if (count == 0) { | 1263 | if (count == 0) { |
1258 | dbg("%s -- Empty", __func__); | 1264 | send_mos_cmd(port->serial, MOS_READ, port_number, |
1259 | result = TIOCSER_TEMT; | 1265 | UART_LSR, &data); |
1266 | if ((data & (UART_LSR_TEMT | UART_LSR_THRE)) | ||
1267 | == (UART_LSR_TEMT | UART_LSR_THRE)) { | ||
1268 | dbg("%s -- Empty", __func__); | ||
1269 | result = TIOCSER_TEMT; | ||
1270 | } | ||
1260 | } | 1271 | } |
1261 | |||
1262 | if (copy_to_user(value, &result, sizeof(int))) | 1272 | if (copy_to_user(value, &result, sizeof(int))) |
1263 | return -EFAULT; | 1273 | return -EFAULT; |
1264 | return 0; | 1274 | return 0; |
1265 | } | 1275 | } |
1266 | 1276 | ||
1277 | static int mos7720_tiocmget(struct tty_struct *tty, struct file *file) | ||
1278 | { | ||
1279 | struct usb_serial_port *port = tty->driver_data; | ||
1280 | struct moschip_port *mos7720_port = usb_get_serial_port_data(port); | ||
1281 | unsigned int result = 0; | ||
1282 | unsigned int mcr ; | ||
1283 | unsigned int msr ; | ||
1284 | |||
1285 | dbg("%s - port %d", __func__, port->number); | ||
1286 | |||
1287 | mcr = mos7720_port->shadowMCR; | ||
1288 | msr = mos7720_port->shadowMSR; | ||
1289 | |||
1290 | result = ((mcr & UART_MCR_DTR) ? TIOCM_DTR : 0) /* 0x002 */ | ||
1291 | | ((mcr & UART_MCR_RTS) ? TIOCM_RTS : 0) /* 0x004 */ | ||
1292 | | ((msr & UART_MSR_CTS) ? TIOCM_CTS : 0) /* 0x020 */ | ||
1293 | | ((msr & UART_MSR_DCD) ? TIOCM_CAR : 0) /* 0x040 */ | ||
1294 | | ((msr & UART_MSR_RI) ? TIOCM_RI : 0) /* 0x080 */ | ||
1295 | | ((msr & UART_MSR_DSR) ? TIOCM_DSR : 0); /* 0x100 */ | ||
1296 | |||
1297 | dbg("%s -- %x", __func__, result); | ||
1298 | |||
1299 | return result; | ||
1300 | } | ||
1301 | |||
1302 | static int mos7720_tiocmset(struct tty_struct *tty, struct file *file, | ||
1303 | unsigned int set, unsigned int clear) | ||
1304 | { | ||
1305 | struct usb_serial_port *port = tty->driver_data; | ||
1306 | struct moschip_port *mos7720_port = usb_get_serial_port_data(port); | ||
1307 | unsigned int mcr ; | ||
1308 | unsigned char lmcr; | ||
1309 | |||
1310 | dbg("%s - port %d", __func__, port->number); | ||
1311 | dbg("he was at tiocmget"); | ||
1312 | |||
1313 | mcr = mos7720_port->shadowMCR; | ||
1314 | |||
1315 | if (set & TIOCM_RTS) | ||
1316 | mcr |= UART_MCR_RTS; | ||
1317 | if (set & TIOCM_DTR) | ||
1318 | mcr |= UART_MCR_DTR; | ||
1319 | if (set & TIOCM_LOOP) | ||
1320 | mcr |= UART_MCR_LOOP; | ||
1321 | |||
1322 | if (clear & TIOCM_RTS) | ||
1323 | mcr &= ~UART_MCR_RTS; | ||
1324 | if (clear & TIOCM_DTR) | ||
1325 | mcr &= ~UART_MCR_DTR; | ||
1326 | if (clear & TIOCM_LOOP) | ||
1327 | mcr &= ~UART_MCR_LOOP; | ||
1328 | |||
1329 | mos7720_port->shadowMCR = mcr; | ||
1330 | lmcr = mos7720_port->shadowMCR; | ||
1331 | |||
1332 | send_mos_cmd(port->serial, MOS_WRITE, | ||
1333 | port->number - port->serial->minor, UART_MCR, &lmcr); | ||
1334 | |||
1335 | return 0; | ||
1336 | } | ||
1337 | |||
1267 | static int set_modem_info(struct moschip_port *mos7720_port, unsigned int cmd, | 1338 | static int set_modem_info(struct moschip_port *mos7720_port, unsigned int cmd, |
1268 | unsigned int __user *value) | 1339 | unsigned int __user *value) |
1269 | { | 1340 | { |
@@ -1301,14 +1372,6 @@ static int set_modem_info(struct moschip_port *mos7720_port, unsigned int cmd, | |||
1301 | mcr &= ~UART_MCR_LOOP; | 1372 | mcr &= ~UART_MCR_LOOP; |
1302 | break; | 1373 | break; |
1303 | 1374 | ||
1304 | case TIOCMSET: | ||
1305 | /* turn off the RTS and DTR and LOOPBACK | ||
1306 | * and then only turn on what was asked to */ | ||
1307 | mcr &= ~(UART_MCR_RTS | UART_MCR_DTR | UART_MCR_LOOP); | ||
1308 | mcr |= ((arg & TIOCM_RTS) ? UART_MCR_RTS : 0); | ||
1309 | mcr |= ((arg & TIOCM_DTR) ? UART_MCR_DTR : 0); | ||
1310 | mcr |= ((arg & TIOCM_LOOP) ? UART_MCR_LOOP : 0); | ||
1311 | break; | ||
1312 | } | 1375 | } |
1313 | 1376 | ||
1314 | mos7720_port->shadowMCR = mcr; | 1377 | mos7720_port->shadowMCR = mcr; |
@@ -1320,28 +1383,6 @@ static int set_modem_info(struct moschip_port *mos7720_port, unsigned int cmd, | |||
1320 | return 0; | 1383 | return 0; |
1321 | } | 1384 | } |
1322 | 1385 | ||
1323 | static int get_modem_info(struct moschip_port *mos7720_port, | ||
1324 | unsigned int __user *value) | ||
1325 | { | ||
1326 | unsigned int result = 0; | ||
1327 | unsigned int msr = mos7720_port->shadowMSR; | ||
1328 | unsigned int mcr = mos7720_port->shadowMCR; | ||
1329 | |||
1330 | result = ((mcr & UART_MCR_DTR) ? TIOCM_DTR: 0) /* 0x002 */ | ||
1331 | | ((mcr & UART_MCR_RTS) ? TIOCM_RTS: 0) /* 0x004 */ | ||
1332 | | ((msr & UART_MSR_CTS) ? TIOCM_CTS: 0) /* 0x020 */ | ||
1333 | | ((msr & UART_MSR_DCD) ? TIOCM_CAR: 0) /* 0x040 */ | ||
1334 | | ((msr & UART_MSR_RI) ? TIOCM_RI: 0) /* 0x080 */ | ||
1335 | | ((msr & UART_MSR_DSR) ? TIOCM_DSR: 0); /* 0x100 */ | ||
1336 | |||
1337 | |||
1338 | dbg("%s -- %x", __func__, result); | ||
1339 | |||
1340 | if (copy_to_user(value, &result, sizeof(int))) | ||
1341 | return -EFAULT; | ||
1342 | return 0; | ||
1343 | } | ||
1344 | |||
1345 | static int get_serial_info(struct moschip_port *mos7720_port, | 1386 | static int get_serial_info(struct moschip_port *mos7720_port, |
1346 | struct serial_struct __user *retinfo) | 1387 | struct serial_struct __user *retinfo) |
1347 | { | 1388 | { |
@@ -1392,17 +1433,11 @@ static int mos7720_ioctl(struct tty_struct *tty, struct file *file, | |||
1392 | /* FIXME: These should be using the mode methods */ | 1433 | /* FIXME: These should be using the mode methods */ |
1393 | case TIOCMBIS: | 1434 | case TIOCMBIS: |
1394 | case TIOCMBIC: | 1435 | case TIOCMBIC: |
1395 | case TIOCMSET: | ||
1396 | dbg("%s (%d) TIOCMSET/TIOCMBIC/TIOCMSET", | 1436 | dbg("%s (%d) TIOCMSET/TIOCMBIC/TIOCMSET", |
1397 | __func__, port->number); | 1437 | __func__, port->number); |
1398 | return set_modem_info(mos7720_port, cmd, | 1438 | return set_modem_info(mos7720_port, cmd, |
1399 | (unsigned int __user *)arg); | 1439 | (unsigned int __user *)arg); |
1400 | 1440 | ||
1401 | case TIOCMGET: | ||
1402 | dbg("%s (%d) TIOCMGET", __func__, port->number); | ||
1403 | return get_modem_info(mos7720_port, | ||
1404 | (unsigned int __user *)arg); | ||
1405 | |||
1406 | case TIOCGSERIAL: | 1441 | case TIOCGSERIAL: |
1407 | dbg("%s (%d) TIOCGSERIAL", __func__, port->number); | 1442 | dbg("%s (%d) TIOCGSERIAL", __func__, port->number); |
1408 | return get_serial_info(mos7720_port, | 1443 | return get_serial_info(mos7720_port, |
@@ -1557,6 +1592,8 @@ static struct usb_serial_driver moschip7720_2port_driver = { | |||
1557 | .attach = mos7720_startup, | 1592 | .attach = mos7720_startup, |
1558 | .release = mos7720_release, | 1593 | .release = mos7720_release, |
1559 | .ioctl = mos7720_ioctl, | 1594 | .ioctl = mos7720_ioctl, |
1595 | .tiocmget = mos7720_tiocmget, | ||
1596 | .tiocmset = mos7720_tiocmset, | ||
1560 | .set_termios = mos7720_set_termios, | 1597 | .set_termios = mos7720_set_termios, |
1561 | .write = mos7720_write, | 1598 | .write = mos7720_write, |
1562 | .write_room = mos7720_write_room, | 1599 | .write_room = mos7720_write_room, |
diff --git a/drivers/usb/serial/mos7840.c b/drivers/usb/serial/mos7840.c index 270009afdf77..f11abf52be7d 100644 --- a/drivers/usb/serial/mos7840.c +++ b/drivers/usb/serial/mos7840.c | |||
@@ -824,8 +824,7 @@ static int mos7840_serial_probe(struct usb_serial *serial, | |||
824 | * Otherwise we return a negative error number. | 824 | * Otherwise we return a negative error number. |
825 | *****************************************************************************/ | 825 | *****************************************************************************/ |
826 | 826 | ||
827 | static int mos7840_open(struct tty_struct *tty, | 827 | static int mos7840_open(struct tty_struct *tty, struct usb_serial_port *port) |
828 | struct usb_serial_port *port, struct file *filp) | ||
829 | { | 828 | { |
830 | int response; | 829 | int response; |
831 | int j; | 830 | int j; |
@@ -2134,106 +2133,6 @@ static int mos7840_get_lsr_info(struct tty_struct *tty, | |||
2134 | } | 2133 | } |
2135 | 2134 | ||
2136 | /***************************************************************************** | 2135 | /***************************************************************************** |
2137 | * mos7840_set_modem_info | ||
2138 | * function to set modem info | ||
2139 | *****************************************************************************/ | ||
2140 | |||
2141 | /* FIXME: Should be using the model control hooks */ | ||
2142 | |||
2143 | static int mos7840_set_modem_info(struct moschip_port *mos7840_port, | ||
2144 | unsigned int cmd, unsigned int __user *value) | ||
2145 | { | ||
2146 | unsigned int mcr; | ||
2147 | unsigned int arg; | ||
2148 | __u16 Data; | ||
2149 | int status; | ||
2150 | struct usb_serial_port *port; | ||
2151 | |||
2152 | if (mos7840_port == NULL) | ||
2153 | return -1; | ||
2154 | |||
2155 | port = (struct usb_serial_port *)mos7840_port->port; | ||
2156 | if (mos7840_port_paranoia_check(port, __func__)) { | ||
2157 | dbg("%s", "Invalid port"); | ||
2158 | return -1; | ||
2159 | } | ||
2160 | |||
2161 | mcr = mos7840_port->shadowMCR; | ||
2162 | |||
2163 | if (copy_from_user(&arg, value, sizeof(int))) | ||
2164 | return -EFAULT; | ||
2165 | |||
2166 | switch (cmd) { | ||
2167 | case TIOCMBIS: | ||
2168 | if (arg & TIOCM_RTS) | ||
2169 | mcr |= MCR_RTS; | ||
2170 | if (arg & TIOCM_DTR) | ||
2171 | mcr |= MCR_RTS; | ||
2172 | if (arg & TIOCM_LOOP) | ||
2173 | mcr |= MCR_LOOPBACK; | ||
2174 | break; | ||
2175 | |||
2176 | case TIOCMBIC: | ||
2177 | if (arg & TIOCM_RTS) | ||
2178 | mcr &= ~MCR_RTS; | ||
2179 | if (arg & TIOCM_DTR) | ||
2180 | mcr &= ~MCR_RTS; | ||
2181 | if (arg & TIOCM_LOOP) | ||
2182 | mcr &= ~MCR_LOOPBACK; | ||
2183 | break; | ||
2184 | |||
2185 | case TIOCMSET: | ||
2186 | /* turn off the RTS and DTR and LOOPBACK | ||
2187 | * and then only turn on what was asked to */ | ||
2188 | mcr &= ~(MCR_RTS | MCR_DTR | MCR_LOOPBACK); | ||
2189 | mcr |= ((arg & TIOCM_RTS) ? MCR_RTS : 0); | ||
2190 | mcr |= ((arg & TIOCM_DTR) ? MCR_DTR : 0); | ||
2191 | mcr |= ((arg & TIOCM_LOOP) ? MCR_LOOPBACK : 0); | ||
2192 | break; | ||
2193 | } | ||
2194 | |||
2195 | lock_kernel(); | ||
2196 | mos7840_port->shadowMCR = mcr; | ||
2197 | |||
2198 | Data = mos7840_port->shadowMCR; | ||
2199 | status = mos7840_set_uart_reg(port, MODEM_CONTROL_REGISTER, Data); | ||
2200 | unlock_kernel(); | ||
2201 | if (status < 0) { | ||
2202 | dbg("setting MODEM_CONTROL_REGISTER Failed"); | ||
2203 | return -1; | ||
2204 | } | ||
2205 | |||
2206 | return 0; | ||
2207 | } | ||
2208 | |||
2209 | /***************************************************************************** | ||
2210 | * mos7840_get_modem_info | ||
2211 | * function to get modem info | ||
2212 | *****************************************************************************/ | ||
2213 | |||
2214 | static int mos7840_get_modem_info(struct moschip_port *mos7840_port, | ||
2215 | unsigned int __user *value) | ||
2216 | { | ||
2217 | unsigned int result = 0; | ||
2218 | __u16 msr; | ||
2219 | unsigned int mcr = mos7840_port->shadowMCR; | ||
2220 | mos7840_get_uart_reg(mos7840_port->port, | ||
2221 | MODEM_STATUS_REGISTER, &msr); | ||
2222 | result = ((mcr & MCR_DTR) ? TIOCM_DTR : 0) /* 0x002 */ | ||
2223 | |((mcr & MCR_RTS) ? TIOCM_RTS : 0) /* 0x004 */ | ||
2224 | |((msr & MOS7840_MSR_CTS) ? TIOCM_CTS : 0) /* 0x020 */ | ||
2225 | |((msr & MOS7840_MSR_CD) ? TIOCM_CAR : 0) /* 0x040 */ | ||
2226 | |((msr & MOS7840_MSR_RI) ? TIOCM_RI : 0) /* 0x080 */ | ||
2227 | |((msr & MOS7840_MSR_DSR) ? TIOCM_DSR : 0); /* 0x100 */ | ||
2228 | |||
2229 | dbg("%s -- %x", __func__, result); | ||
2230 | |||
2231 | if (copy_to_user(value, &result, sizeof(int))) | ||
2232 | return -EFAULT; | ||
2233 | return 0; | ||
2234 | } | ||
2235 | |||
2236 | /***************************************************************************** | ||
2237 | * mos7840_get_serial_info | 2136 | * mos7840_get_serial_info |
2238 | * function to get information about serial port | 2137 | * function to get information about serial port |
2239 | *****************************************************************************/ | 2138 | *****************************************************************************/ |
@@ -2281,7 +2180,6 @@ static int mos7840_ioctl(struct tty_struct *tty, struct file *file, | |||
2281 | struct async_icount cnow; | 2180 | struct async_icount cnow; |
2282 | struct async_icount cprev; | 2181 | struct async_icount cprev; |
2283 | struct serial_icounter_struct icount; | 2182 | struct serial_icounter_struct icount; |
2284 | int mosret = 0; | ||
2285 | 2183 | ||
2286 | if (mos7840_port_paranoia_check(port, __func__)) { | 2184 | if (mos7840_port_paranoia_check(port, __func__)) { |
2287 | dbg("%s", "Invalid port"); | 2185 | dbg("%s", "Invalid port"); |
@@ -2303,20 +2201,6 @@ static int mos7840_ioctl(struct tty_struct *tty, struct file *file, | |||
2303 | return mos7840_get_lsr_info(tty, argp); | 2201 | return mos7840_get_lsr_info(tty, argp); |
2304 | return 0; | 2202 | return 0; |
2305 | 2203 | ||
2306 | /* FIXME: use the modem hooks and remove this */ | ||
2307 | case TIOCMBIS: | ||
2308 | case TIOCMBIC: | ||
2309 | case TIOCMSET: | ||
2310 | dbg("%s (%d) TIOCMSET/TIOCMBIC/TIOCMSET", __func__, | ||
2311 | port->number); | ||
2312 | mosret = | ||
2313 | mos7840_set_modem_info(mos7840_port, cmd, argp); | ||
2314 | return mosret; | ||
2315 | |||
2316 | case TIOCMGET: | ||
2317 | dbg("%s (%d) TIOCMGET", __func__, port->number); | ||
2318 | return mos7840_get_modem_info(mos7840_port, argp); | ||
2319 | |||
2320 | case TIOCGSERIAL: | 2204 | case TIOCGSERIAL: |
2321 | dbg("%s (%d) TIOCGSERIAL", __func__, port->number); | 2205 | dbg("%s (%d) TIOCGSERIAL", __func__, port->number); |
2322 | return mos7840_get_serial_info(mos7840_port, argp); | 2206 | return mos7840_get_serial_info(mos7840_port, argp); |
diff --git a/drivers/usb/serial/moto_modem.c b/drivers/usb/serial/moto_modem.c index b66b71ccd12b..99bd00f5188a 100644 --- a/drivers/usb/serial/moto_modem.c +++ b/drivers/usb/serial/moto_modem.c | |||
@@ -8,7 +8,7 @@ | |||
8 | * published by the Free Software Foundation. | 8 | * published by the Free Software Foundation. |
9 | * | 9 | * |
10 | * {sigh} | 10 | * {sigh} |
11 | * Mororola should be using the CDC ACM USB spec, but instead | 11 | * Motorola should be using the CDC ACM USB spec, but instead |
12 | * they try to just "do their own thing"... This driver should handle a | 12 | * they try to just "do their own thing"... This driver should handle a |
13 | * few phones in which a basic "dumb serial connection" is needed to be | 13 | * few phones in which a basic "dumb serial connection" is needed to be |
14 | * able to get a connection through to them. | 14 | * able to get a connection through to them. |
diff --git a/drivers/usb/serial/navman.c b/drivers/usb/serial/navman.c index f5f3751a888c..5ceaa4c6be09 100644 --- a/drivers/usb/serial/navman.c +++ b/drivers/usb/serial/navman.c | |||
@@ -80,8 +80,7 @@ exit: | |||
80 | __func__, result); | 80 | __func__, result); |
81 | } | 81 | } |
82 | 82 | ||
83 | static int navman_open(struct tty_struct *tty, | 83 | static int navman_open(struct tty_struct *tty, struct usb_serial_port *port) |
84 | struct usb_serial_port *port, struct file *filp) | ||
85 | { | 84 | { |
86 | int result = 0; | 85 | int result = 0; |
87 | 86 | ||
diff --git a/drivers/usb/serial/omninet.c b/drivers/usb/serial/omninet.c index 56857ddbd70b..062265038bf0 100644 --- a/drivers/usb/serial/omninet.c +++ b/drivers/usb/serial/omninet.c | |||
@@ -64,8 +64,7 @@ static int debug; | |||
64 | #define BT_IGNITIONPRO_ID 0x2000 | 64 | #define BT_IGNITIONPRO_ID 0x2000 |
65 | 65 | ||
66 | /* function prototypes */ | 66 | /* function prototypes */ |
67 | static int omninet_open(struct tty_struct *tty, struct usb_serial_port *port, | 67 | static int omninet_open(struct tty_struct *tty, struct usb_serial_port *port); |
68 | struct file *filp); | ||
69 | static void omninet_close(struct usb_serial_port *port); | 68 | static void omninet_close(struct usb_serial_port *port); |
70 | static void omninet_read_bulk_callback(struct urb *urb); | 69 | static void omninet_read_bulk_callback(struct urb *urb); |
71 | static void omninet_write_bulk_callback(struct urb *urb); | 70 | static void omninet_write_bulk_callback(struct urb *urb); |
@@ -163,8 +162,7 @@ static int omninet_attach(struct usb_serial *serial) | |||
163 | return 0; | 162 | return 0; |
164 | } | 163 | } |
165 | 164 | ||
166 | static int omninet_open(struct tty_struct *tty, | 165 | static int omninet_open(struct tty_struct *tty, struct usb_serial_port *port) |
167 | struct usb_serial_port *port, struct file *filp) | ||
168 | { | 166 | { |
169 | struct usb_serial *serial = port->serial; | 167 | struct usb_serial *serial = port->serial; |
170 | struct usb_serial_port *wport; | 168 | struct usb_serial_port *wport; |
diff --git a/drivers/usb/serial/opticon.c b/drivers/usb/serial/opticon.c index 336bba79ad32..1085a577c5c1 100644 --- a/drivers/usb/serial/opticon.c +++ b/drivers/usb/serial/opticon.c | |||
@@ -144,8 +144,7 @@ exit: | |||
144 | spin_unlock(&priv->lock); | 144 | spin_unlock(&priv->lock); |
145 | } | 145 | } |
146 | 146 | ||
147 | static int opticon_open(struct tty_struct *tty, struct usb_serial_port *port, | 147 | static int opticon_open(struct tty_struct *tty, struct usb_serial_port *port) |
148 | struct file *filp) | ||
149 | { | 148 | { |
150 | struct opticon_private *priv = usb_get_serial_data(port->serial); | 149 | struct opticon_private *priv = usb_get_serial_data(port->serial); |
151 | unsigned long flags; | 150 | unsigned long flags; |
diff --git a/drivers/usb/serial/option.c b/drivers/usb/serial/option.c index c784ddbe7b61..f66e39883218 100644 --- a/drivers/usb/serial/option.c +++ b/drivers/usb/serial/option.c | |||
@@ -45,8 +45,7 @@ | |||
45 | /* Function prototypes */ | 45 | /* Function prototypes */ |
46 | static int option_probe(struct usb_serial *serial, | 46 | static int option_probe(struct usb_serial *serial, |
47 | const struct usb_device_id *id); | 47 | const struct usb_device_id *id); |
48 | static int option_open(struct tty_struct *tty, struct usb_serial_port *port, | 48 | static int option_open(struct tty_struct *tty, struct usb_serial_port *port); |
49 | struct file *filp); | ||
50 | static void option_close(struct usb_serial_port *port); | 49 | static void option_close(struct usb_serial_port *port); |
51 | static void option_dtr_rts(struct usb_serial_port *port, int on); | 50 | static void option_dtr_rts(struct usb_serial_port *port, int on); |
52 | 51 | ||
@@ -292,6 +291,7 @@ static int option_resume(struct usb_serial *serial); | |||
292 | 291 | ||
293 | #define TELIT_VENDOR_ID 0x1bc7 | 292 | #define TELIT_VENDOR_ID 0x1bc7 |
294 | #define TELIT_PRODUCT_UC864E 0x1003 | 293 | #define TELIT_PRODUCT_UC864E 0x1003 |
294 | #define TELIT_PRODUCT_UC864G 0x1004 | ||
295 | 295 | ||
296 | /* ZTE PRODUCTS */ | 296 | /* ZTE PRODUCTS */ |
297 | #define ZTE_VENDOR_ID 0x19d2 | 297 | #define ZTE_VENDOR_ID 0x19d2 |
@@ -300,6 +300,7 @@ static int option_resume(struct usb_serial *serial); | |||
300 | #define ZTE_PRODUCT_MF626 0x0031 | 300 | #define ZTE_PRODUCT_MF626 0x0031 |
301 | #define ZTE_PRODUCT_CDMA_TECH 0xfffe | 301 | #define ZTE_PRODUCT_CDMA_TECH 0xfffe |
302 | #define ZTE_PRODUCT_AC8710 0xfff1 | 302 | #define ZTE_PRODUCT_AC8710 0xfff1 |
303 | #define ZTE_PRODUCT_AC2726 0xfff5 | ||
303 | 304 | ||
304 | #define BENQ_VENDOR_ID 0x04a5 | 305 | #define BENQ_VENDOR_ID 0x04a5 |
305 | #define BENQ_PRODUCT_H10 0x4068 | 306 | #define BENQ_PRODUCT_H10 0x4068 |
@@ -503,6 +504,7 @@ static struct usb_device_id option_ids[] = { | |||
503 | { USB_DEVICE(QUALCOMM_VENDOR_ID, 0x6613)}, /* Onda H600/ZTE MF330 */ | 504 | { USB_DEVICE(QUALCOMM_VENDOR_ID, 0x6613)}, /* Onda H600/ZTE MF330 */ |
504 | { USB_DEVICE(MAXON_VENDOR_ID, 0x6280) }, /* BP3-USB & BP3-EXT HSDPA */ | 505 | { USB_DEVICE(MAXON_VENDOR_ID, 0x6280) }, /* BP3-USB & BP3-EXT HSDPA */ |
505 | { USB_DEVICE(TELIT_VENDOR_ID, TELIT_PRODUCT_UC864E) }, | 506 | { USB_DEVICE(TELIT_VENDOR_ID, TELIT_PRODUCT_UC864E) }, |
507 | { USB_DEVICE(TELIT_VENDOR_ID, TELIT_PRODUCT_UC864G) }, | ||
506 | { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, ZTE_PRODUCT_MF622, 0xff, 0xff, 0xff) }, /* ZTE WCDMA products */ | 508 | { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, ZTE_PRODUCT_MF622, 0xff, 0xff, 0xff) }, /* ZTE WCDMA products */ |
507 | { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0002, 0xff, 0xff, 0xff) }, | 509 | { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0002, 0xff, 0xff, 0xff) }, |
508 | { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0003, 0xff, 0xff, 0xff) }, | 510 | { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0003, 0xff, 0xff, 0xff) }, |
@@ -572,6 +574,7 @@ static struct usb_device_id option_ids[] = { | |||
572 | { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0073, 0xff, 0xff, 0xff) }, | 574 | { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0073, 0xff, 0xff, 0xff) }, |
573 | { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, ZTE_PRODUCT_CDMA_TECH, 0xff, 0xff, 0xff) }, | 575 | { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, ZTE_PRODUCT_CDMA_TECH, 0xff, 0xff, 0xff) }, |
574 | { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, ZTE_PRODUCT_AC8710, 0xff, 0xff, 0xff) }, | 576 | { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, ZTE_PRODUCT_AC8710, 0xff, 0xff, 0xff) }, |
577 | { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, ZTE_PRODUCT_AC2726, 0xff, 0xff, 0xff) }, | ||
575 | { USB_DEVICE(BENQ_VENDOR_ID, BENQ_PRODUCT_H10) }, | 578 | { USB_DEVICE(BENQ_VENDOR_ID, BENQ_PRODUCT_H10) }, |
576 | { USB_DEVICE(DLINK_VENDOR_ID, DLINK_PRODUCT_DWM_652) }, | 579 | { USB_DEVICE(DLINK_VENDOR_ID, DLINK_PRODUCT_DWM_652) }, |
577 | { USB_DEVICE(QISDA_VENDOR_ID, QISDA_PRODUCT_H21_4512) }, | 580 | { USB_DEVICE(QISDA_VENDOR_ID, QISDA_PRODUCT_H21_4512) }, |
@@ -593,6 +596,7 @@ static struct usb_driver option_driver = { | |||
593 | #ifdef CONFIG_PM | 596 | #ifdef CONFIG_PM |
594 | .suspend = usb_serial_suspend, | 597 | .suspend = usb_serial_suspend, |
595 | .resume = usb_serial_resume, | 598 | .resume = usb_serial_resume, |
599 | .supports_autosuspend = 1, | ||
596 | #endif | 600 | #endif |
597 | .id_table = option_ids, | 601 | .id_table = option_ids, |
598 | .no_dynamic_id = 1, | 602 | .no_dynamic_id = 1, |
@@ -640,6 +644,12 @@ static int debug; | |||
640 | #define IN_BUFLEN 4096 | 644 | #define IN_BUFLEN 4096 |
641 | #define OUT_BUFLEN 4096 | 645 | #define OUT_BUFLEN 4096 |
642 | 646 | ||
647 | struct option_intf_private { | ||
648 | spinlock_t susp_lock; | ||
649 | unsigned int suspended:1; | ||
650 | int in_flight; | ||
651 | }; | ||
652 | |||
643 | struct option_port_private { | 653 | struct option_port_private { |
644 | /* Input endpoints and buffer for this port */ | 654 | /* Input endpoints and buffer for this port */ |
645 | struct urb *in_urbs[N_IN_URB]; | 655 | struct urb *in_urbs[N_IN_URB]; |
@@ -648,6 +658,8 @@ struct option_port_private { | |||
648 | struct urb *out_urbs[N_OUT_URB]; | 658 | struct urb *out_urbs[N_OUT_URB]; |
649 | u8 *out_buffer[N_OUT_URB]; | 659 | u8 *out_buffer[N_OUT_URB]; |
650 | unsigned long out_busy; /* Bit vector of URBs in use */ | 660 | unsigned long out_busy; /* Bit vector of URBs in use */ |
661 | int opened; | ||
662 | struct usb_anchor delayed; | ||
651 | 663 | ||
652 | /* Settings for the port */ | 664 | /* Settings for the port */ |
653 | int rts_state; /* Handshaking pins (outputs) */ | 665 | int rts_state; /* Handshaking pins (outputs) */ |
@@ -694,12 +706,17 @@ module_exit(option_exit); | |||
694 | static int option_probe(struct usb_serial *serial, | 706 | static int option_probe(struct usb_serial *serial, |
695 | const struct usb_device_id *id) | 707 | const struct usb_device_id *id) |
696 | { | 708 | { |
709 | struct option_intf_private *data; | ||
697 | /* D-Link DWM 652 still exposes CD-Rom emulation interface in modem mode */ | 710 | /* D-Link DWM 652 still exposes CD-Rom emulation interface in modem mode */ |
698 | if (serial->dev->descriptor.idVendor == DLINK_VENDOR_ID && | 711 | if (serial->dev->descriptor.idVendor == DLINK_VENDOR_ID && |
699 | serial->dev->descriptor.idProduct == DLINK_PRODUCT_DWM_652 && | 712 | serial->dev->descriptor.idProduct == DLINK_PRODUCT_DWM_652 && |
700 | serial->interface->cur_altsetting->desc.bInterfaceClass == 0x8) | 713 | serial->interface->cur_altsetting->desc.bInterfaceClass == 0x8) |
701 | return -ENODEV; | 714 | return -ENODEV; |
702 | 715 | ||
716 | data = serial->private = kzalloc(sizeof(struct option_intf_private), GFP_KERNEL); | ||
717 | if (!data) | ||
718 | return -ENOMEM; | ||
719 | spin_lock_init(&data->susp_lock); | ||
703 | return 0; | 720 | return 0; |
704 | } | 721 | } |
705 | 722 | ||
@@ -756,12 +773,15 @@ static int option_write(struct tty_struct *tty, struct usb_serial_port *port, | |||
756 | const unsigned char *buf, int count) | 773 | const unsigned char *buf, int count) |
757 | { | 774 | { |
758 | struct option_port_private *portdata; | 775 | struct option_port_private *portdata; |
776 | struct option_intf_private *intfdata; | ||
759 | int i; | 777 | int i; |
760 | int left, todo; | 778 | int left, todo; |
761 | struct urb *this_urb = NULL; /* spurious */ | 779 | struct urb *this_urb = NULL; /* spurious */ |
762 | int err; | 780 | int err; |
781 | unsigned long flags; | ||
763 | 782 | ||
764 | portdata = usb_get_serial_port_data(port); | 783 | portdata = usb_get_serial_port_data(port); |
784 | intfdata = port->serial->private; | ||
765 | 785 | ||
766 | dbg("%s: write (%d chars)", __func__, count); | 786 | dbg("%s: write (%d chars)", __func__, count); |
767 | 787 | ||
@@ -783,17 +803,33 @@ static int option_write(struct tty_struct *tty, struct usb_serial_port *port, | |||
783 | dbg("%s: endpoint %d buf %d", __func__, | 803 | dbg("%s: endpoint %d buf %d", __func__, |
784 | usb_pipeendpoint(this_urb->pipe), i); | 804 | usb_pipeendpoint(this_urb->pipe), i); |
785 | 805 | ||
806 | err = usb_autopm_get_interface_async(port->serial->interface); | ||
807 | if (err < 0) | ||
808 | break; | ||
809 | |||
786 | /* send the data */ | 810 | /* send the data */ |
787 | memcpy(this_urb->transfer_buffer, buf, todo); | 811 | memcpy(this_urb->transfer_buffer, buf, todo); |
788 | this_urb->transfer_buffer_length = todo; | 812 | this_urb->transfer_buffer_length = todo; |
789 | 813 | ||
790 | err = usb_submit_urb(this_urb, GFP_ATOMIC); | 814 | spin_lock_irqsave(&intfdata->susp_lock, flags); |
791 | if (err) { | 815 | if (intfdata->suspended) { |
792 | dbg("usb_submit_urb %p (write bulk) failed " | 816 | usb_anchor_urb(this_urb, &portdata->delayed); |
793 | "(%d)", this_urb, err); | 817 | spin_unlock_irqrestore(&intfdata->susp_lock, flags); |
794 | clear_bit(i, &portdata->out_busy); | 818 | } else { |
795 | continue; | 819 | intfdata->in_flight++; |
820 | spin_unlock_irqrestore(&intfdata->susp_lock, flags); | ||
821 | err = usb_submit_urb(this_urb, GFP_ATOMIC); | ||
822 | if (err) { | ||
823 | dbg("usb_submit_urb %p (write bulk) failed " | ||
824 | "(%d)", this_urb, err); | ||
825 | clear_bit(i, &portdata->out_busy); | ||
826 | spin_lock_irqsave(&intfdata->susp_lock, flags); | ||
827 | intfdata->in_flight--; | ||
828 | spin_unlock_irqrestore(&intfdata->susp_lock, flags); | ||
829 | continue; | ||
830 | } | ||
796 | } | 831 | } |
832 | |||
797 | portdata->tx_start_time[i] = jiffies; | 833 | portdata->tx_start_time[i] = jiffies; |
798 | buf += todo; | 834 | buf += todo; |
799 | left -= todo; | 835 | left -= todo; |
@@ -837,7 +873,10 @@ static void option_indat_callback(struct urb *urb) | |||
837 | if (err) | 873 | if (err) |
838 | printk(KERN_ERR "%s: resubmit read urb failed. " | 874 | printk(KERN_ERR "%s: resubmit read urb failed. " |
839 | "(%d)", __func__, err); | 875 | "(%d)", __func__, err); |
876 | else | ||
877 | usb_mark_last_busy(port->serial->dev); | ||
840 | } | 878 | } |
879 | |||
841 | } | 880 | } |
842 | return; | 881 | return; |
843 | } | 882 | } |
@@ -846,15 +885,21 @@ static void option_outdat_callback(struct urb *urb) | |||
846 | { | 885 | { |
847 | struct usb_serial_port *port; | 886 | struct usb_serial_port *port; |
848 | struct option_port_private *portdata; | 887 | struct option_port_private *portdata; |
888 | struct option_intf_private *intfdata; | ||
849 | int i; | 889 | int i; |
850 | 890 | ||
851 | dbg("%s", __func__); | 891 | dbg("%s", __func__); |
852 | 892 | ||
853 | port = urb->context; | 893 | port = urb->context; |
894 | intfdata = port->serial->private; | ||
854 | 895 | ||
855 | usb_serial_port_softint(port); | 896 | usb_serial_port_softint(port); |
856 | 897 | usb_autopm_put_interface_async(port->serial->interface); | |
857 | portdata = usb_get_serial_port_data(port); | 898 | portdata = usb_get_serial_port_data(port); |
899 | spin_lock(&intfdata->susp_lock); | ||
900 | intfdata->in_flight--; | ||
901 | spin_unlock(&intfdata->susp_lock); | ||
902 | |||
858 | for (i = 0; i < N_OUT_URB; ++i) { | 903 | for (i = 0; i < N_OUT_URB; ++i) { |
859 | if (portdata->out_urbs[i] == urb) { | 904 | if (portdata->out_urbs[i] == urb) { |
860 | smp_mb__before_clear_bit(); | 905 | smp_mb__before_clear_bit(); |
@@ -961,14 +1006,16 @@ static int option_chars_in_buffer(struct tty_struct *tty) | |||
961 | return data_len; | 1006 | return data_len; |
962 | } | 1007 | } |
963 | 1008 | ||
964 | static int option_open(struct tty_struct *tty, | 1009 | static int option_open(struct tty_struct *tty, struct usb_serial_port *port) |
965 | struct usb_serial_port *port, struct file *filp) | ||
966 | { | 1010 | { |
967 | struct option_port_private *portdata; | 1011 | struct option_port_private *portdata; |
1012 | struct option_intf_private *intfdata; | ||
1013 | struct usb_serial *serial = port->serial; | ||
968 | int i, err; | 1014 | int i, err; |
969 | struct urb *urb; | 1015 | struct urb *urb; |
970 | 1016 | ||
971 | portdata = usb_get_serial_port_data(port); | 1017 | portdata = usb_get_serial_port_data(port); |
1018 | intfdata = serial->private; | ||
972 | 1019 | ||
973 | dbg("%s", __func__); | 1020 | dbg("%s", __func__); |
974 | 1021 | ||
@@ -987,6 +1034,12 @@ static int option_open(struct tty_struct *tty, | |||
987 | 1034 | ||
988 | option_send_setup(port); | 1035 | option_send_setup(port); |
989 | 1036 | ||
1037 | serial->interface->needs_remote_wakeup = 1; | ||
1038 | spin_lock_irq(&intfdata->susp_lock); | ||
1039 | portdata->opened = 1; | ||
1040 | spin_unlock_irq(&intfdata->susp_lock); | ||
1041 | usb_autopm_put_interface(serial->interface); | ||
1042 | |||
990 | return 0; | 1043 | return 0; |
991 | } | 1044 | } |
992 | 1045 | ||
@@ -1011,16 +1064,23 @@ static void option_close(struct usb_serial_port *port) | |||
1011 | int i; | 1064 | int i; |
1012 | struct usb_serial *serial = port->serial; | 1065 | struct usb_serial *serial = port->serial; |
1013 | struct option_port_private *portdata; | 1066 | struct option_port_private *portdata; |
1067 | struct option_intf_private *intfdata = port->serial->private; | ||
1014 | 1068 | ||
1015 | dbg("%s", __func__); | 1069 | dbg("%s", __func__); |
1016 | portdata = usb_get_serial_port_data(port); | 1070 | portdata = usb_get_serial_port_data(port); |
1017 | 1071 | ||
1018 | if (serial->dev) { | 1072 | if (serial->dev) { |
1019 | /* Stop reading/writing urbs */ | 1073 | /* Stop reading/writing urbs */ |
1074 | spin_lock_irq(&intfdata->susp_lock); | ||
1075 | portdata->opened = 0; | ||
1076 | spin_unlock_irq(&intfdata->susp_lock); | ||
1077 | |||
1020 | for (i = 0; i < N_IN_URB; i++) | 1078 | for (i = 0; i < N_IN_URB; i++) |
1021 | usb_kill_urb(portdata->in_urbs[i]); | 1079 | usb_kill_urb(portdata->in_urbs[i]); |
1022 | for (i = 0; i < N_OUT_URB; i++) | 1080 | for (i = 0; i < N_OUT_URB; i++) |
1023 | usb_kill_urb(portdata->out_urbs[i]); | 1081 | usb_kill_urb(portdata->out_urbs[i]); |
1082 | usb_autopm_get_interface(serial->interface); | ||
1083 | serial->interface->needs_remote_wakeup = 0; | ||
1024 | } | 1084 | } |
1025 | } | 1085 | } |
1026 | 1086 | ||
@@ -1125,6 +1185,7 @@ static int option_startup(struct usb_serial *serial) | |||
1125 | __func__, i); | 1185 | __func__, i); |
1126 | return 1; | 1186 | return 1; |
1127 | } | 1187 | } |
1188 | init_usb_anchor(&portdata->delayed); | ||
1128 | 1189 | ||
1129 | for (j = 0; j < N_IN_URB; j++) { | 1190 | for (j = 0; j < N_IN_URB; j++) { |
1130 | buffer = (u8 *)__get_free_page(GFP_KERNEL); | 1191 | buffer = (u8 *)__get_free_page(GFP_KERNEL); |
@@ -1227,18 +1288,52 @@ static void option_release(struct usb_serial *serial) | |||
1227 | #ifdef CONFIG_PM | 1288 | #ifdef CONFIG_PM |
1228 | static int option_suspend(struct usb_serial *serial, pm_message_t message) | 1289 | static int option_suspend(struct usb_serial *serial, pm_message_t message) |
1229 | { | 1290 | { |
1291 | struct option_intf_private *intfdata = serial->private; | ||
1292 | int b; | ||
1293 | |||
1230 | dbg("%s entered", __func__); | 1294 | dbg("%s entered", __func__); |
1295 | |||
1296 | if (serial->dev->auto_pm) { | ||
1297 | spin_lock_irq(&intfdata->susp_lock); | ||
1298 | b = intfdata->in_flight; | ||
1299 | spin_unlock_irq(&intfdata->susp_lock); | ||
1300 | |||
1301 | if (b) | ||
1302 | return -EBUSY; | ||
1303 | } | ||
1304 | |||
1305 | spin_lock_irq(&intfdata->susp_lock); | ||
1306 | intfdata->suspended = 1; | ||
1307 | spin_unlock_irq(&intfdata->susp_lock); | ||
1231 | stop_read_write_urbs(serial); | 1308 | stop_read_write_urbs(serial); |
1232 | 1309 | ||
1233 | return 0; | 1310 | return 0; |
1234 | } | 1311 | } |
1235 | 1312 | ||
1313 | static void play_delayed(struct usb_serial_port *port) | ||
1314 | { | ||
1315 | struct option_intf_private *data; | ||
1316 | struct option_port_private *portdata; | ||
1317 | struct urb *urb; | ||
1318 | int err; | ||
1319 | |||
1320 | portdata = usb_get_serial_port_data(port); | ||
1321 | data = port->serial->private; | ||
1322 | while ((urb = usb_get_from_anchor(&portdata->delayed))) { | ||
1323 | err = usb_submit_urb(urb, GFP_ATOMIC); | ||
1324 | if (!err) | ||
1325 | data->in_flight++; | ||
1326 | } | ||
1327 | } | ||
1328 | |||
1236 | static int option_resume(struct usb_serial *serial) | 1329 | static int option_resume(struct usb_serial *serial) |
1237 | { | 1330 | { |
1238 | int err, i, j; | 1331 | int i, j; |
1239 | struct usb_serial_port *port; | 1332 | struct usb_serial_port *port; |
1240 | struct urb *urb; | 1333 | struct option_intf_private *intfdata = serial->private; |
1241 | struct option_port_private *portdata; | 1334 | struct option_port_private *portdata; |
1335 | struct urb *urb; | ||
1336 | int err = 0; | ||
1242 | 1337 | ||
1243 | dbg("%s entered", __func__); | 1338 | dbg("%s entered", __func__); |
1244 | /* get the interrupt URBs resubmitted unconditionally */ | 1339 | /* get the interrupt URBs resubmitted unconditionally */ |
@@ -1253,7 +1348,7 @@ static int option_resume(struct usb_serial *serial) | |||
1253 | if (err < 0) { | 1348 | if (err < 0) { |
1254 | err("%s: Error %d for interrupt URB of port%d", | 1349 | err("%s: Error %d for interrupt URB of port%d", |
1255 | __func__, err, i); | 1350 | __func__, err, i); |
1256 | return err; | 1351 | goto err_out; |
1257 | } | 1352 | } |
1258 | } | 1353 | } |
1259 | 1354 | ||
@@ -1261,27 +1356,32 @@ static int option_resume(struct usb_serial *serial) | |||
1261 | /* walk all ports */ | 1356 | /* walk all ports */ |
1262 | port = serial->port[i]; | 1357 | port = serial->port[i]; |
1263 | portdata = usb_get_serial_port_data(port); | 1358 | portdata = usb_get_serial_port_data(port); |
1264 | mutex_lock(&port->mutex); | ||
1265 | 1359 | ||
1266 | /* skip closed ports */ | 1360 | /* skip closed ports */ |
1267 | if (!port->port.count) { | 1361 | spin_lock_irq(&intfdata->susp_lock); |
1268 | mutex_unlock(&port->mutex); | 1362 | if (!portdata->opened) { |
1363 | spin_unlock_irq(&intfdata->susp_lock); | ||
1269 | continue; | 1364 | continue; |
1270 | } | 1365 | } |
1271 | 1366 | ||
1272 | for (j = 0; j < N_IN_URB; j++) { | 1367 | for (j = 0; j < N_IN_URB; j++) { |
1273 | urb = portdata->in_urbs[j]; | 1368 | urb = portdata->in_urbs[j]; |
1274 | err = usb_submit_urb(urb, GFP_NOIO); | 1369 | err = usb_submit_urb(urb, GFP_ATOMIC); |
1275 | if (err < 0) { | 1370 | if (err < 0) { |
1276 | mutex_unlock(&port->mutex); | ||
1277 | err("%s: Error %d for bulk URB %d", | 1371 | err("%s: Error %d for bulk URB %d", |
1278 | __func__, err, i); | 1372 | __func__, err, i); |
1279 | return err; | 1373 | spin_unlock_irq(&intfdata->susp_lock); |
1374 | goto err_out; | ||
1280 | } | 1375 | } |
1281 | } | 1376 | } |
1282 | mutex_unlock(&port->mutex); | 1377 | play_delayed(port); |
1378 | spin_unlock_irq(&intfdata->susp_lock); | ||
1283 | } | 1379 | } |
1284 | return 0; | 1380 | spin_lock_irq(&intfdata->susp_lock); |
1381 | intfdata->suspended = 0; | ||
1382 | spin_unlock_irq(&intfdata->susp_lock); | ||
1383 | err_out: | ||
1384 | return err; | ||
1285 | } | 1385 | } |
1286 | #endif | 1386 | #endif |
1287 | 1387 | ||
diff --git a/drivers/usb/serial/oti6858.c b/drivers/usb/serial/oti6858.c index 3cece27325e7..0f4a70ce3823 100644 --- a/drivers/usb/serial/oti6858.c +++ b/drivers/usb/serial/oti6858.c | |||
@@ -141,11 +141,11 @@ struct oti6858_control_pkt { | |||
141 | && ((a)->frame_fmt == (priv)->pending_setup.frame_fmt)) | 141 | && ((a)->frame_fmt == (priv)->pending_setup.frame_fmt)) |
142 | 142 | ||
143 | /* function prototypes */ | 143 | /* function prototypes */ |
144 | static int oti6858_open(struct tty_struct *tty, | 144 | static int oti6858_open(struct tty_struct *tty, struct usb_serial_port *port); |
145 | struct usb_serial_port *port, struct file *filp); | ||
146 | static void oti6858_close(struct usb_serial_port *port); | 145 | static void oti6858_close(struct usb_serial_port *port); |
147 | static void oti6858_set_termios(struct tty_struct *tty, | 146 | static void oti6858_set_termios(struct tty_struct *tty, |
148 | struct usb_serial_port *port, struct ktermios *old); | 147 | struct usb_serial_port *port, struct ktermios *old); |
148 | static void oti6858_init_termios(struct tty_struct *tty); | ||
149 | static int oti6858_ioctl(struct tty_struct *tty, struct file *file, | 149 | static int oti6858_ioctl(struct tty_struct *tty, struct file *file, |
150 | unsigned int cmd, unsigned long arg); | 150 | unsigned int cmd, unsigned long arg); |
151 | static void oti6858_read_int_callback(struct urb *urb); | 151 | static void oti6858_read_int_callback(struct urb *urb); |
@@ -186,6 +186,7 @@ static struct usb_serial_driver oti6858_device = { | |||
186 | .write = oti6858_write, | 186 | .write = oti6858_write, |
187 | .ioctl = oti6858_ioctl, | 187 | .ioctl = oti6858_ioctl, |
188 | .set_termios = oti6858_set_termios, | 188 | .set_termios = oti6858_set_termios, |
189 | .init_termios = oti6858_init_termios, | ||
189 | .tiocmget = oti6858_tiocmget, | 190 | .tiocmget = oti6858_tiocmget, |
190 | .tiocmset = oti6858_tiocmset, | 191 | .tiocmset = oti6858_tiocmset, |
191 | .read_bulk_callback = oti6858_read_bulk_callback, | 192 | .read_bulk_callback = oti6858_read_bulk_callback, |
@@ -206,7 +207,6 @@ struct oti6858_private { | |||
206 | struct { | 207 | struct { |
207 | u8 read_urb_in_use; | 208 | u8 read_urb_in_use; |
208 | u8 write_urb_in_use; | 209 | u8 write_urb_in_use; |
209 | u8 termios_initialized; | ||
210 | } flags; | 210 | } flags; |
211 | struct delayed_work delayed_write_work; | 211 | struct delayed_work delayed_write_work; |
212 | 212 | ||
@@ -447,6 +447,14 @@ static int oti6858_chars_in_buffer(struct tty_struct *tty) | |||
447 | return chars; | 447 | return chars; |
448 | } | 448 | } |
449 | 449 | ||
450 | static void oti6858_init_termios(struct tty_struct *tty) | ||
451 | { | ||
452 | *(tty->termios) = tty_std_termios; | ||
453 | tty->termios->c_cflag = B38400 | CS8 | CREAD | HUPCL | CLOCAL; | ||
454 | tty->termios->c_ispeed = 38400; | ||
455 | tty->termios->c_ospeed = 38400; | ||
456 | } | ||
457 | |||
450 | static void oti6858_set_termios(struct tty_struct *tty, | 458 | static void oti6858_set_termios(struct tty_struct *tty, |
451 | struct usb_serial_port *port, struct ktermios *old_termios) | 459 | struct usb_serial_port *port, struct ktermios *old_termios) |
452 | { | 460 | { |
@@ -464,16 +472,6 @@ static void oti6858_set_termios(struct tty_struct *tty, | |||
464 | return; | 472 | return; |
465 | } | 473 | } |
466 | 474 | ||
467 | spin_lock_irqsave(&priv->lock, flags); | ||
468 | if (!priv->flags.termios_initialized) { | ||
469 | *(tty->termios) = tty_std_termios; | ||
470 | tty->termios->c_cflag = B38400 | CS8 | CREAD | HUPCL | CLOCAL; | ||
471 | tty->termios->c_ispeed = 38400; | ||
472 | tty->termios->c_ospeed = 38400; | ||
473 | priv->flags.termios_initialized = 1; | ||
474 | } | ||
475 | spin_unlock_irqrestore(&priv->lock, flags); | ||
476 | |||
477 | cflag = tty->termios->c_cflag; | 475 | cflag = tty->termios->c_cflag; |
478 | 476 | ||
479 | spin_lock_irqsave(&priv->lock, flags); | 477 | spin_lock_irqsave(&priv->lock, flags); |
@@ -566,8 +564,7 @@ static void oti6858_set_termios(struct tty_struct *tty, | |||
566 | spin_unlock_irqrestore(&priv->lock, flags); | 564 | spin_unlock_irqrestore(&priv->lock, flags); |
567 | } | 565 | } |
568 | 566 | ||
569 | static int oti6858_open(struct tty_struct *tty, | 567 | static int oti6858_open(struct tty_struct *tty, struct usb_serial_port *port) |
570 | struct usb_serial_port *port, struct file *filp) | ||
571 | { | 568 | { |
572 | struct oti6858_private *priv = usb_get_serial_port_data(port); | 569 | struct oti6858_private *priv = usb_get_serial_port_data(port); |
573 | struct ktermios tmp_termios; | 570 | struct ktermios tmp_termios; |
diff --git a/drivers/usb/serial/pl2303.c b/drivers/usb/serial/pl2303.c index 3e86815b2705..1128e01525b1 100644 --- a/drivers/usb/serial/pl2303.c +++ b/drivers/usb/serial/pl2303.c | |||
@@ -96,6 +96,7 @@ static struct usb_device_id id_table [] = { | |||
96 | { USB_DEVICE(HP_VENDOR_ID, HP_LD220_PRODUCT_ID) }, | 96 | { USB_DEVICE(HP_VENDOR_ID, HP_LD220_PRODUCT_ID) }, |
97 | { USB_DEVICE(CRESSI_VENDOR_ID, CRESSI_EDY_PRODUCT_ID) }, | 97 | { USB_DEVICE(CRESSI_VENDOR_ID, CRESSI_EDY_PRODUCT_ID) }, |
98 | { USB_DEVICE(SONY_VENDOR_ID, SONY_QN3USB_PRODUCT_ID) }, | 98 | { USB_DEVICE(SONY_VENDOR_ID, SONY_QN3USB_PRODUCT_ID) }, |
99 | { USB_DEVICE(SANWA_VENDOR_ID, SANWA_PRODUCT_ID) }, | ||
99 | { } /* Terminating entry */ | 100 | { } /* Terminating entry */ |
100 | }; | 101 | }; |
101 | 102 | ||
@@ -527,6 +528,12 @@ static void pl2303_set_termios(struct tty_struct *tty, | |||
527 | int baud; | 528 | int baud; |
528 | int i; | 529 | int i; |
529 | u8 control; | 530 | u8 control; |
531 | const int baud_sup[] = { 75, 150, 300, 600, 1200, 1800, 2400, 3600, | ||
532 | 4800, 7200, 9600, 14400, 19200, 28800, 38400, | ||
533 | 57600, 115200, 230400, 460800, 614400, | ||
534 | 921600, 1228800, 2457600, 3000000, 6000000 }; | ||
535 | int baud_floor, baud_ceil; | ||
536 | int k; | ||
530 | 537 | ||
531 | dbg("%s - port %d", __func__, port->number); | 538 | dbg("%s - port %d", __func__, port->number); |
532 | 539 | ||
@@ -572,9 +579,39 @@ static void pl2303_set_termios(struct tty_struct *tty, | |||
572 | dbg("%s - data bits = %d", __func__, buf[6]); | 579 | dbg("%s - data bits = %d", __func__, buf[6]); |
573 | } | 580 | } |
574 | 581 | ||
582 | /* For reference buf[0]:buf[3] baud rate value */ | ||
583 | /* NOTE: Only the values defined in baud_sup are supported ! | ||
584 | * => if unsupported values are set, the PL2303 seems to use | ||
585 | * 9600 baud (at least my PL2303X always does) | ||
586 | */ | ||
575 | baud = tty_get_baud_rate(tty); | 587 | baud = tty_get_baud_rate(tty); |
576 | dbg("%s - baud = %d", __func__, baud); | 588 | dbg("%s - baud requested = %d", __func__, baud); |
577 | if (baud) { | 589 | if (baud) { |
590 | /* Set baudrate to nearest supported value */ | ||
591 | for (k=0; k<ARRAY_SIZE(baud_sup); k++) { | ||
592 | if (baud_sup[k] / baud) { | ||
593 | baud_ceil = baud_sup[k]; | ||
594 | if (k==0) { | ||
595 | baud = baud_ceil; | ||
596 | } else { | ||
597 | baud_floor = baud_sup[k-1]; | ||
598 | if ((baud_ceil % baud) | ||
599 | > (baud % baud_floor)) | ||
600 | baud = baud_floor; | ||
601 | else | ||
602 | baud = baud_ceil; | ||
603 | } | ||
604 | break; | ||
605 | } | ||
606 | } | ||
607 | if (baud > 1228800) { | ||
608 | /* type_0, type_1 only support up to 1228800 baud */ | ||
609 | if (priv->type != HX) | ||
610 | baud = 1228800; | ||
611 | else if (baud > 6000000) | ||
612 | baud = 6000000; | ||
613 | } | ||
614 | dbg("%s - baud set = %d", __func__, baud); | ||
578 | buf[0] = baud & 0xff; | 615 | buf[0] = baud & 0xff; |
579 | buf[1] = (baud >> 8) & 0xff; | 616 | buf[1] = (baud >> 8) & 0xff; |
580 | buf[2] = (baud >> 16) & 0xff; | 617 | buf[2] = (baud >> 16) & 0xff; |
@@ -585,8 +622,16 @@ static void pl2303_set_termios(struct tty_struct *tty, | |||
585 | /* For reference buf[4]=1 is 1.5 stop bits */ | 622 | /* For reference buf[4]=1 is 1.5 stop bits */ |
586 | /* For reference buf[4]=2 is 2 stop bits */ | 623 | /* For reference buf[4]=2 is 2 stop bits */ |
587 | if (cflag & CSTOPB) { | 624 | if (cflag & CSTOPB) { |
588 | buf[4] = 2; | 625 | /* NOTE: Comply with "real" UARTs / RS232: |
589 | dbg("%s - stop bits = 2", __func__); | 626 | * use 1.5 instead of 2 stop bits with 5 data bits |
627 | */ | ||
628 | if ((cflag & CSIZE) == CS5) { | ||
629 | buf[4] = 1; | ||
630 | dbg("%s - stop bits = 1.5", __func__); | ||
631 | } else { | ||
632 | buf[4] = 2; | ||
633 | dbg("%s - stop bits = 2", __func__); | ||
634 | } | ||
590 | } else { | 635 | } else { |
591 | buf[4] = 0; | 636 | buf[4] = 0; |
592 | dbg("%s - stop bits = 1", __func__); | 637 | dbg("%s - stop bits = 1", __func__); |
@@ -599,11 +644,21 @@ static void pl2303_set_termios(struct tty_struct *tty, | |||
599 | /* For reference buf[5]=3 is mark parity */ | 644 | /* For reference buf[5]=3 is mark parity */ |
600 | /* For reference buf[5]=4 is space parity */ | 645 | /* For reference buf[5]=4 is space parity */ |
601 | if (cflag & PARODD) { | 646 | if (cflag & PARODD) { |
602 | buf[5] = 1; | 647 | if (cflag & CMSPAR) { |
603 | dbg("%s - parity = odd", __func__); | 648 | buf[5] = 3; |
649 | dbg("%s - parity = mark", __func__); | ||
650 | } else { | ||
651 | buf[5] = 1; | ||
652 | dbg("%s - parity = odd", __func__); | ||
653 | } | ||
604 | } else { | 654 | } else { |
605 | buf[5] = 2; | 655 | if (cflag & CMSPAR) { |
606 | dbg("%s - parity = even", __func__); | 656 | buf[5] = 4; |
657 | dbg("%s - parity = space", __func__); | ||
658 | } else { | ||
659 | buf[5] = 2; | ||
660 | dbg("%s - parity = even", __func__); | ||
661 | } | ||
607 | } | 662 | } |
608 | } else { | 663 | } else { |
609 | buf[5] = 0; | 664 | buf[5] = 0; |
@@ -647,7 +702,7 @@ static void pl2303_set_termios(struct tty_struct *tty, | |||
647 | pl2303_vendor_write(0x0, 0x0, serial); | 702 | pl2303_vendor_write(0x0, 0x0, serial); |
648 | } | 703 | } |
649 | 704 | ||
650 | /* FIXME: Need to read back resulting baud rate */ | 705 | /* Save resulting baud rate */ |
651 | if (baud) | 706 | if (baud) |
652 | tty_encode_baud_rate(tty, baud, baud); | 707 | tty_encode_baud_rate(tty, baud, baud); |
653 | 708 | ||
@@ -691,8 +746,7 @@ static void pl2303_close(struct usb_serial_port *port) | |||
691 | 746 | ||
692 | } | 747 | } |
693 | 748 | ||
694 | static int pl2303_open(struct tty_struct *tty, | 749 | static int pl2303_open(struct tty_struct *tty, struct usb_serial_port *port) |
695 | struct usb_serial_port *port, struct file *filp) | ||
696 | { | 750 | { |
697 | struct ktermios tmp_termios; | 751 | struct ktermios tmp_termios; |
698 | struct usb_serial *serial = port->serial; | 752 | struct usb_serial *serial = port->serial; |
@@ -714,8 +768,6 @@ static int pl2303_open(struct tty_struct *tty, | |||
714 | if (tty) | 768 | if (tty) |
715 | pl2303_set_termios(tty, port, &tmp_termios); | 769 | pl2303_set_termios(tty, port, &tmp_termios); |
716 | 770 | ||
717 | /* FIXME: need to assert RTS and DTR if CRTSCTS off */ | ||
718 | |||
719 | dbg("%s - submitting read urb", __func__); | 771 | dbg("%s - submitting read urb", __func__); |
720 | port->read_urb->dev = serial->dev; | 772 | port->read_urb->dev = serial->dev; |
721 | result = usb_submit_urb(port->read_urb, GFP_KERNEL); | 773 | result = usb_submit_urb(port->read_urb, GFP_KERNEL); |
diff --git a/drivers/usb/serial/pl2303.h b/drivers/usb/serial/pl2303.h index ee9505e1dd92..d640dc951568 100644 --- a/drivers/usb/serial/pl2303.h +++ b/drivers/usb/serial/pl2303.h | |||
@@ -130,3 +130,7 @@ | |||
130 | /* Sony, USB data cable for CMD-Jxx mobile phones */ | 130 | /* Sony, USB data cable for CMD-Jxx mobile phones */ |
131 | #define SONY_VENDOR_ID 0x054c | 131 | #define SONY_VENDOR_ID 0x054c |
132 | #define SONY_QN3USB_PRODUCT_ID 0x0437 | 132 | #define SONY_QN3USB_PRODUCT_ID 0x0437 |
133 | |||
134 | /* Sanwa KB-USB2 multimeter cable (ID: 11ad:0001) */ | ||
135 | #define SANWA_VENDOR_ID 0x11ad | ||
136 | #define SANWA_PRODUCT_ID 0x0001 | ||
diff --git a/drivers/usb/serial/sierra.c b/drivers/usb/serial/sierra.c index f48d05e0acc1..8c075b2416bb 100644 --- a/drivers/usb/serial/sierra.c +++ b/drivers/usb/serial/sierra.c | |||
@@ -51,6 +51,12 @@ struct sierra_iface_info { | |||
51 | const u8 *ifaceinfo; /* pointer to the array holding the numbers */ | 51 | const u8 *ifaceinfo; /* pointer to the array holding the numbers */ |
52 | }; | 52 | }; |
53 | 53 | ||
54 | struct sierra_intf_private { | ||
55 | spinlock_t susp_lock; | ||
56 | unsigned int suspended:1; | ||
57 | int in_flight; | ||
58 | }; | ||
59 | |||
54 | static int sierra_set_power_state(struct usb_device *udev, __u16 swiState) | 60 | static int sierra_set_power_state(struct usb_device *udev, __u16 swiState) |
55 | { | 61 | { |
56 | int result; | 62 | int result; |
@@ -144,6 +150,7 @@ static int sierra_probe(struct usb_serial *serial, | |||
144 | { | 150 | { |
145 | int result = 0; | 151 | int result = 0; |
146 | struct usb_device *udev; | 152 | struct usb_device *udev; |
153 | struct sierra_intf_private *data; | ||
147 | u8 ifnum; | 154 | u8 ifnum; |
148 | 155 | ||
149 | udev = serial->dev; | 156 | udev = serial->dev; |
@@ -171,6 +178,11 @@ static int sierra_probe(struct usb_serial *serial, | |||
171 | return -ENODEV; | 178 | return -ENODEV; |
172 | } | 179 | } |
173 | 180 | ||
181 | data = serial->private = kzalloc(sizeof(struct sierra_intf_private), GFP_KERNEL); | ||
182 | if (!data) | ||
183 | return -ENOMEM; | ||
184 | spin_lock_init(&data->susp_lock); | ||
185 | |||
174 | return result; | 186 | return result; |
175 | } | 187 | } |
176 | 188 | ||
@@ -261,13 +273,18 @@ static struct usb_driver sierra_driver = { | |||
261 | .name = "sierra", | 273 | .name = "sierra", |
262 | .probe = usb_serial_probe, | 274 | .probe = usb_serial_probe, |
263 | .disconnect = usb_serial_disconnect, | 275 | .disconnect = usb_serial_disconnect, |
276 | .suspend = usb_serial_suspend, | ||
277 | .resume = usb_serial_resume, | ||
264 | .id_table = id_table, | 278 | .id_table = id_table, |
265 | .no_dynamic_id = 1, | 279 | .no_dynamic_id = 1, |
280 | .supports_autosuspend = 1, | ||
266 | }; | 281 | }; |
267 | 282 | ||
268 | struct sierra_port_private { | 283 | struct sierra_port_private { |
269 | spinlock_t lock; /* lock the structure */ | 284 | spinlock_t lock; /* lock the structure */ |
270 | int outstanding_urbs; /* number of out urbs in flight */ | 285 | int outstanding_urbs; /* number of out urbs in flight */ |
286 | struct usb_anchor active; | ||
287 | struct usb_anchor delayed; | ||
271 | 288 | ||
272 | /* Input endpoints and buffers for this port */ | 289 | /* Input endpoints and buffers for this port */ |
273 | struct urb *in_urbs[N_IN_URB]; | 290 | struct urb *in_urbs[N_IN_URB]; |
@@ -279,6 +296,8 @@ struct sierra_port_private { | |||
279 | int dsr_state; | 296 | int dsr_state; |
280 | int dcd_state; | 297 | int dcd_state; |
281 | int ri_state; | 298 | int ri_state; |
299 | |||
300 | unsigned int opened:1; | ||
282 | }; | 301 | }; |
283 | 302 | ||
284 | static int sierra_send_setup(struct usb_serial_port *port) | 303 | static int sierra_send_setup(struct usb_serial_port *port) |
@@ -390,21 +409,25 @@ static void sierra_outdat_callback(struct urb *urb) | |||
390 | { | 409 | { |
391 | struct usb_serial_port *port = urb->context; | 410 | struct usb_serial_port *port = urb->context; |
392 | struct sierra_port_private *portdata = usb_get_serial_port_data(port); | 411 | struct sierra_port_private *portdata = usb_get_serial_port_data(port); |
412 | struct sierra_intf_private *intfdata; | ||
393 | int status = urb->status; | 413 | int status = urb->status; |
394 | unsigned long flags; | ||
395 | 414 | ||
396 | dev_dbg(&port->dev, "%s - port %d\n", __func__, port->number); | 415 | dev_dbg(&port->dev, "%s - port %d\n", __func__, port->number); |
416 | intfdata = port->serial->private; | ||
397 | 417 | ||
398 | /* free up the transfer buffer, as usb_free_urb() does not do this */ | 418 | /* free up the transfer buffer, as usb_free_urb() does not do this */ |
399 | kfree(urb->transfer_buffer); | 419 | kfree(urb->transfer_buffer); |
400 | 420 | usb_autopm_put_interface_async(port->serial->interface); | |
401 | if (status) | 421 | if (status) |
402 | dev_dbg(&port->dev, "%s - nonzero write bulk status " | 422 | dev_dbg(&port->dev, "%s - nonzero write bulk status " |
403 | "received: %d\n", __func__, status); | 423 | "received: %d\n", __func__, status); |
404 | 424 | ||
405 | spin_lock_irqsave(&portdata->lock, flags); | 425 | spin_lock(&portdata->lock); |
406 | --portdata->outstanding_urbs; | 426 | --portdata->outstanding_urbs; |
407 | spin_unlock_irqrestore(&portdata->lock, flags); | 427 | spin_unlock(&portdata->lock); |
428 | spin_lock(&intfdata->susp_lock); | ||
429 | --intfdata->in_flight; | ||
430 | spin_unlock(&intfdata->susp_lock); | ||
408 | 431 | ||
409 | usb_serial_port_softint(port); | 432 | usb_serial_port_softint(port); |
410 | } | 433 | } |
@@ -414,6 +437,7 @@ static int sierra_write(struct tty_struct *tty, struct usb_serial_port *port, | |||
414 | const unsigned char *buf, int count) | 437 | const unsigned char *buf, int count) |
415 | { | 438 | { |
416 | struct sierra_port_private *portdata = usb_get_serial_port_data(port); | 439 | struct sierra_port_private *portdata = usb_get_serial_port_data(port); |
440 | struct sierra_intf_private *intfdata; | ||
417 | struct usb_serial *serial = port->serial; | 441 | struct usb_serial *serial = port->serial; |
418 | unsigned long flags; | 442 | unsigned long flags; |
419 | unsigned char *buffer; | 443 | unsigned char *buffer; |
@@ -426,9 +450,9 @@ static int sierra_write(struct tty_struct *tty, struct usb_serial_port *port, | |||
426 | return 0; | 450 | return 0; |
427 | 451 | ||
428 | portdata = usb_get_serial_port_data(port); | 452 | portdata = usb_get_serial_port_data(port); |
453 | intfdata = serial->private; | ||
429 | 454 | ||
430 | dev_dbg(&port->dev, "%s: write (%zd bytes)\n", __func__, writesize); | 455 | dev_dbg(&port->dev, "%s: write (%zd bytes)\n", __func__, writesize); |
431 | |||
432 | spin_lock_irqsave(&portdata->lock, flags); | 456 | spin_lock_irqsave(&portdata->lock, flags); |
433 | dev_dbg(&port->dev, "%s - outstanding_urbs: %d\n", __func__, | 457 | dev_dbg(&port->dev, "%s - outstanding_urbs: %d\n", __func__, |
434 | portdata->outstanding_urbs); | 458 | portdata->outstanding_urbs); |
@@ -442,6 +466,14 @@ static int sierra_write(struct tty_struct *tty, struct usb_serial_port *port, | |||
442 | portdata->outstanding_urbs); | 466 | portdata->outstanding_urbs); |
443 | spin_unlock_irqrestore(&portdata->lock, flags); | 467 | spin_unlock_irqrestore(&portdata->lock, flags); |
444 | 468 | ||
469 | retval = usb_autopm_get_interface_async(serial->interface); | ||
470 | if (retval < 0) { | ||
471 | spin_lock_irqsave(&portdata->lock, flags); | ||
472 | portdata->outstanding_urbs--; | ||
473 | spin_unlock_irqrestore(&portdata->lock, flags); | ||
474 | goto error_simple; | ||
475 | } | ||
476 | |||
445 | buffer = kmalloc(writesize, GFP_ATOMIC); | 477 | buffer = kmalloc(writesize, GFP_ATOMIC); |
446 | if (!buffer) { | 478 | if (!buffer) { |
447 | dev_err(&port->dev, "out of memory\n"); | 479 | dev_err(&port->dev, "out of memory\n"); |
@@ -468,14 +500,29 @@ static int sierra_write(struct tty_struct *tty, struct usb_serial_port *port, | |||
468 | /* Handle the need to send a zero length packet */ | 500 | /* Handle the need to send a zero length packet */ |
469 | urb->transfer_flags |= URB_ZERO_PACKET; | 501 | urb->transfer_flags |= URB_ZERO_PACKET; |
470 | 502 | ||
503 | spin_lock_irqsave(&intfdata->susp_lock, flags); | ||
504 | |||
505 | if (intfdata->suspended) { | ||
506 | usb_anchor_urb(urb, &portdata->delayed); | ||
507 | spin_unlock_irqrestore(&intfdata->susp_lock, flags); | ||
508 | goto skip_power; | ||
509 | } else { | ||
510 | usb_anchor_urb(urb, &portdata->active); | ||
511 | } | ||
471 | /* send it down the pipe */ | 512 | /* send it down the pipe */ |
472 | retval = usb_submit_urb(urb, GFP_ATOMIC); | 513 | retval = usb_submit_urb(urb, GFP_ATOMIC); |
473 | if (retval) { | 514 | if (retval) { |
515 | usb_unanchor_urb(urb); | ||
516 | spin_unlock_irqrestore(&intfdata->susp_lock, flags); | ||
474 | dev_err(&port->dev, "%s - usb_submit_urb(write bulk) failed " | 517 | dev_err(&port->dev, "%s - usb_submit_urb(write bulk) failed " |
475 | "with status = %d\n", __func__, retval); | 518 | "with status = %d\n", __func__, retval); |
476 | goto error; | 519 | goto error; |
520 | } else { | ||
521 | intfdata->in_flight++; | ||
522 | spin_unlock_irqrestore(&intfdata->susp_lock, flags); | ||
477 | } | 523 | } |
478 | 524 | ||
525 | skip_power: | ||
479 | /* we are done with this urb, so let the host driver | 526 | /* we are done with this urb, so let the host driver |
480 | * really free it when it is finished with it */ | 527 | * really free it when it is finished with it */ |
481 | usb_free_urb(urb); | 528 | usb_free_urb(urb); |
@@ -491,6 +538,8 @@ error_no_buffer: | |||
491 | dev_dbg(&port->dev, "%s - 2. outstanding_urbs: %d\n", __func__, | 538 | dev_dbg(&port->dev, "%s - 2. outstanding_urbs: %d\n", __func__, |
492 | portdata->outstanding_urbs); | 539 | portdata->outstanding_urbs); |
493 | spin_unlock_irqrestore(&portdata->lock, flags); | 540 | spin_unlock_irqrestore(&portdata->lock, flags); |
541 | usb_autopm_put_interface_async(serial->interface); | ||
542 | error_simple: | ||
494 | return retval; | 543 | return retval; |
495 | } | 544 | } |
496 | 545 | ||
@@ -530,6 +579,7 @@ static void sierra_indat_callback(struct urb *urb) | |||
530 | 579 | ||
531 | /* Resubmit urb so we continue receiving */ | 580 | /* Resubmit urb so we continue receiving */ |
532 | if (port->port.count && status != -ESHUTDOWN && status != -EPERM) { | 581 | if (port->port.count && status != -ESHUTDOWN && status != -EPERM) { |
582 | usb_mark_last_busy(port->serial->dev); | ||
533 | err = usb_submit_urb(urb, GFP_ATOMIC); | 583 | err = usb_submit_urb(urb, GFP_ATOMIC); |
534 | if (err) | 584 | if (err) |
535 | dev_err(&port->dev, "resubmit read urb failed." | 585 | dev_err(&port->dev, "resubmit read urb failed." |
@@ -591,6 +641,7 @@ static void sierra_instat_callback(struct urb *urb) | |||
591 | 641 | ||
592 | /* Resubmit urb so we continue receiving IRQ data */ | 642 | /* Resubmit urb so we continue receiving IRQ data */ |
593 | if (port->port.count && status != -ESHUTDOWN && status != -ENOENT) { | 643 | if (port->port.count && status != -ESHUTDOWN && status != -ENOENT) { |
644 | usb_mark_last_busy(serial->dev); | ||
594 | urb->dev = serial->dev; | 645 | urb->dev = serial->dev; |
595 | err = usb_submit_urb(urb, GFP_ATOMIC); | 646 | err = usb_submit_urb(urb, GFP_ATOMIC); |
596 | if (err) | 647 | if (err) |
@@ -711,6 +762,8 @@ static void sierra_close(struct usb_serial_port *port) | |||
711 | int i; | 762 | int i; |
712 | struct usb_serial *serial = port->serial; | 763 | struct usb_serial *serial = port->serial; |
713 | struct sierra_port_private *portdata; | 764 | struct sierra_port_private *portdata; |
765 | struct sierra_intf_private *intfdata = port->serial->private; | ||
766 | |||
714 | 767 | ||
715 | dev_dbg(&port->dev, "%s\n", __func__); | 768 | dev_dbg(&port->dev, "%s\n", __func__); |
716 | portdata = usb_get_serial_port_data(port); | 769 | portdata = usb_get_serial_port_data(port); |
@@ -723,6 +776,10 @@ static void sierra_close(struct usb_serial_port *port) | |||
723 | if (!serial->disconnected) | 776 | if (!serial->disconnected) |
724 | sierra_send_setup(port); | 777 | sierra_send_setup(port); |
725 | mutex_unlock(&serial->disc_mutex); | 778 | mutex_unlock(&serial->disc_mutex); |
779 | spin_lock_irq(&intfdata->susp_lock); | ||
780 | portdata->opened = 0; | ||
781 | spin_unlock_irq(&intfdata->susp_lock); | ||
782 | |||
726 | 783 | ||
727 | /* Stop reading urbs */ | 784 | /* Stop reading urbs */ |
728 | sierra_stop_rx_urbs(port); | 785 | sierra_stop_rx_urbs(port); |
@@ -731,14 +788,16 @@ static void sierra_close(struct usb_serial_port *port) | |||
731 | sierra_release_urb(portdata->in_urbs[i]); | 788 | sierra_release_urb(portdata->in_urbs[i]); |
732 | portdata->in_urbs[i] = NULL; | 789 | portdata->in_urbs[i] = NULL; |
733 | } | 790 | } |
791 | usb_autopm_get_interface(serial->interface); | ||
792 | serial->interface->needs_remote_wakeup = 0; | ||
734 | } | 793 | } |
735 | } | 794 | } |
736 | 795 | ||
737 | static int sierra_open(struct tty_struct *tty, | 796 | static int sierra_open(struct tty_struct *tty, struct usb_serial_port *port) |
738 | struct usb_serial_port *port, struct file *filp) | ||
739 | { | 797 | { |
740 | struct sierra_port_private *portdata; | 798 | struct sierra_port_private *portdata; |
741 | struct usb_serial *serial = port->serial; | 799 | struct usb_serial *serial = port->serial; |
800 | struct sierra_intf_private *intfdata = serial->private; | ||
742 | int i; | 801 | int i; |
743 | int err; | 802 | int err; |
744 | int endpoint; | 803 | int endpoint; |
@@ -772,6 +831,12 @@ static int sierra_open(struct tty_struct *tty, | |||
772 | } | 831 | } |
773 | sierra_send_setup(port); | 832 | sierra_send_setup(port); |
774 | 833 | ||
834 | serial->interface->needs_remote_wakeup = 1; | ||
835 | spin_lock_irq(&intfdata->susp_lock); | ||
836 | portdata->opened = 1; | ||
837 | spin_unlock_irq(&intfdata->susp_lock); | ||
838 | usb_autopm_put_interface(serial->interface); | ||
839 | |||
775 | return 0; | 840 | return 0; |
776 | } | 841 | } |
777 | 842 | ||
@@ -819,6 +884,8 @@ static int sierra_startup(struct usb_serial *serial) | |||
819 | return -ENOMEM; | 884 | return -ENOMEM; |
820 | } | 885 | } |
821 | spin_lock_init(&portdata->lock); | 886 | spin_lock_init(&portdata->lock); |
887 | init_usb_anchor(&portdata->active); | ||
888 | init_usb_anchor(&portdata->delayed); | ||
822 | /* Set the port private data pointer */ | 889 | /* Set the port private data pointer */ |
823 | usb_set_serial_port_data(port, portdata); | 890 | usb_set_serial_port_data(port, portdata); |
824 | } | 891 | } |
@@ -845,6 +912,88 @@ static void sierra_release(struct usb_serial *serial) | |||
845 | } | 912 | } |
846 | } | 913 | } |
847 | 914 | ||
915 | #ifdef CONFIG_PM | ||
916 | static void stop_read_write_urbs(struct usb_serial *serial) | ||
917 | { | ||
918 | int i, j; | ||
919 | struct usb_serial_port *port; | ||
920 | struct sierra_port_private *portdata; | ||
921 | |||
922 | /* Stop reading/writing urbs */ | ||
923 | for (i = 0; i < serial->num_ports; ++i) { | ||
924 | port = serial->port[i]; | ||
925 | portdata = usb_get_serial_port_data(port); | ||
926 | for (j = 0; j < N_IN_URB; j++) | ||
927 | usb_kill_urb(portdata->in_urbs[j]); | ||
928 | usb_kill_anchored_urbs(&portdata->active); | ||
929 | } | ||
930 | } | ||
931 | |||
932 | static int sierra_suspend(struct usb_serial *serial, pm_message_t message) | ||
933 | { | ||
934 | struct sierra_intf_private *intfdata; | ||
935 | int b; | ||
936 | |||
937 | if (serial->dev->auto_pm) { | ||
938 | intfdata = serial->private; | ||
939 | spin_lock_irq(&intfdata->susp_lock); | ||
940 | b = intfdata->in_flight; | ||
941 | |||
942 | if (b) { | ||
943 | spin_unlock_irq(&intfdata->susp_lock); | ||
944 | return -EBUSY; | ||
945 | } else { | ||
946 | intfdata->suspended = 1; | ||
947 | spin_unlock_irq(&intfdata->susp_lock); | ||
948 | } | ||
949 | } | ||
950 | stop_read_write_urbs(serial); | ||
951 | |||
952 | return 0; | ||
953 | } | ||
954 | |||
955 | static int sierra_resume(struct usb_serial *serial) | ||
956 | { | ||
957 | struct usb_serial_port *port; | ||
958 | struct sierra_intf_private *intfdata = serial->private; | ||
959 | struct sierra_port_private *portdata; | ||
960 | struct urb *urb; | ||
961 | int ec = 0; | ||
962 | int i, err; | ||
963 | |||
964 | spin_lock_irq(&intfdata->susp_lock); | ||
965 | for (i = 0; i < serial->num_ports; i++) { | ||
966 | port = serial->port[i]; | ||
967 | portdata = usb_get_serial_port_data(port); | ||
968 | |||
969 | while ((urb = usb_get_from_anchor(&portdata->delayed))) { | ||
970 | usb_anchor_urb(urb, &portdata->active); | ||
971 | intfdata->in_flight++; | ||
972 | err = usb_submit_urb(urb, GFP_ATOMIC); | ||
973 | if (err < 0) { | ||
974 | intfdata->in_flight--; | ||
975 | usb_unanchor_urb(urb); | ||
976 | usb_scuttle_anchored_urbs(&portdata->delayed); | ||
977 | break; | ||
978 | } | ||
979 | } | ||
980 | |||
981 | if (portdata->opened) { | ||
982 | err = sierra_submit_rx_urbs(port, GFP_ATOMIC); | ||
983 | if (err) | ||
984 | ec++; | ||
985 | } | ||
986 | } | ||
987 | intfdata->suspended = 0; | ||
988 | spin_unlock_irq(&intfdata->susp_lock); | ||
989 | |||
990 | return ec ? -EIO : 0; | ||
991 | } | ||
992 | #else | ||
993 | #define sierra_suspend NULL | ||
994 | #define sierra_resume NULL | ||
995 | #endif | ||
996 | |||
848 | static struct usb_serial_driver sierra_device = { | 997 | static struct usb_serial_driver sierra_device = { |
849 | .driver = { | 998 | .driver = { |
850 | .owner = THIS_MODULE, | 999 | .owner = THIS_MODULE, |
@@ -865,6 +1014,8 @@ static struct usb_serial_driver sierra_device = { | |||
865 | .tiocmset = sierra_tiocmset, | 1014 | .tiocmset = sierra_tiocmset, |
866 | .attach = sierra_startup, | 1015 | .attach = sierra_startup, |
867 | .release = sierra_release, | 1016 | .release = sierra_release, |
1017 | .suspend = sierra_suspend, | ||
1018 | .resume = sierra_resume, | ||
868 | .read_int_callback = sierra_instat_callback, | 1019 | .read_int_callback = sierra_instat_callback, |
869 | }; | 1020 | }; |
870 | 1021 | ||
diff --git a/drivers/usb/serial/spcp8x5.c b/drivers/usb/serial/spcp8x5.c index 3c249d8e8b8e..1e58220403d1 100644 --- a/drivers/usb/serial/spcp8x5.c +++ b/drivers/usb/serial/spcp8x5.c | |||
@@ -299,7 +299,6 @@ struct spcp8x5_private { | |||
299 | wait_queue_head_t delta_msr_wait; | 299 | wait_queue_head_t delta_msr_wait; |
300 | u8 line_control; | 300 | u8 line_control; |
301 | u8 line_status; | 301 | u8 line_status; |
302 | u8 termios_initialized; | ||
303 | }; | 302 | }; |
304 | 303 | ||
305 | /* desc : when device plug in,this function would be called. | 304 | /* desc : when device plug in,this function would be called. |
@@ -498,6 +497,15 @@ static void spcp8x5_close(struct usb_serial_port *port) | |||
498 | dev_dbg(&port->dev, "usb_unlink_urb(read_urb) = %d\n", result); | 497 | dev_dbg(&port->dev, "usb_unlink_urb(read_urb) = %d\n", result); |
499 | } | 498 | } |
500 | 499 | ||
500 | static void spcp8x5_init_termios(struct tty_struct *tty) | ||
501 | { | ||
502 | /* for the 1st time call this function */ | ||
503 | *(tty->termios) = tty_std_termios; | ||
504 | tty->termios->c_cflag = B115200 | CS8 | CREAD | HUPCL | CLOCAL; | ||
505 | tty->termios->c_ispeed = 115200; | ||
506 | tty->termios->c_ospeed = 115200; | ||
507 | } | ||
508 | |||
501 | /* set the serial param for transfer. we should check if we really need to | 509 | /* set the serial param for transfer. we should check if we really need to |
502 | * transfer. if we set flow control we should do this too. */ | 510 | * transfer. if we set flow control we should do this too. */ |
503 | static void spcp8x5_set_termios(struct tty_struct *tty, | 511 | static void spcp8x5_set_termios(struct tty_struct *tty, |
@@ -514,16 +522,6 @@ static void spcp8x5_set_termios(struct tty_struct *tty, | |||
514 | int i; | 522 | int i; |
515 | u8 control; | 523 | u8 control; |
516 | 524 | ||
517 | /* for the 1st time call this function */ | ||
518 | spin_lock_irqsave(&priv->lock, flags); | ||
519 | if (!priv->termios_initialized) { | ||
520 | *(tty->termios) = tty_std_termios; | ||
521 | tty->termios->c_cflag = B115200 | CS8 | CREAD | HUPCL | CLOCAL; | ||
522 | tty->termios->c_ispeed = 115200; | ||
523 | tty->termios->c_ospeed = 115200; | ||
524 | priv->termios_initialized = 1; | ||
525 | } | ||
526 | spin_unlock_irqrestore(&priv->lock, flags); | ||
527 | 525 | ||
528 | /* check that they really want us to change something */ | 526 | /* check that they really want us to change something */ |
529 | if (!tty_termios_hw_change(tty->termios, old_termios)) | 527 | if (!tty_termios_hw_change(tty->termios, old_termios)) |
@@ -546,7 +544,7 @@ static void spcp8x5_set_termios(struct tty_struct *tty, | |||
546 | } | 544 | } |
547 | 545 | ||
548 | /* Set Baud Rate */ | 546 | /* Set Baud Rate */ |
549 | baud = tty_get_baud_rate(tty);; | 547 | baud = tty_get_baud_rate(tty); |
550 | switch (baud) { | 548 | switch (baud) { |
551 | case 300: buf[0] = 0x00; break; | 549 | case 300: buf[0] = 0x00; break; |
552 | case 600: buf[0] = 0x01; break; | 550 | case 600: buf[0] = 0x01; break; |
@@ -623,8 +621,7 @@ static void spcp8x5_set_termios(struct tty_struct *tty, | |||
623 | 621 | ||
624 | /* open the serial port. do some usb system call. set termios and get the line | 622 | /* open the serial port. do some usb system call. set termios and get the line |
625 | * status of the device. then submit the read urb */ | 623 | * status of the device. then submit the read urb */ |
626 | static int spcp8x5_open(struct tty_struct *tty, | 624 | static int spcp8x5_open(struct tty_struct *tty, struct usb_serial_port *port) |
627 | struct usb_serial_port *port, struct file *filp) | ||
628 | { | 625 | { |
629 | struct ktermios tmp_termios; | 626 | struct ktermios tmp_termios; |
630 | struct usb_serial *serial = port->serial; | 627 | struct usb_serial *serial = port->serial; |
@@ -658,8 +655,6 @@ static int spcp8x5_open(struct tty_struct *tty, | |||
658 | priv->line_status = status & 0xf0 ; | 655 | priv->line_status = status & 0xf0 ; |
659 | spin_unlock_irqrestore(&priv->lock, flags); | 656 | spin_unlock_irqrestore(&priv->lock, flags); |
660 | 657 | ||
661 | /* FIXME: need to assert RTS and DTR if CRTSCTS off */ | ||
662 | |||
663 | dbg("%s - submitting read urb", __func__); | 658 | dbg("%s - submitting read urb", __func__); |
664 | port->read_urb->dev = serial->dev; | 659 | port->read_urb->dev = serial->dev; |
665 | ret = usb_submit_urb(port->read_urb, GFP_KERNEL); | 660 | ret = usb_submit_urb(port->read_urb, GFP_KERNEL); |
@@ -1011,6 +1006,7 @@ static struct usb_serial_driver spcp8x5_device = { | |||
1011 | .carrier_raised = spcp8x5_carrier_raised, | 1006 | .carrier_raised = spcp8x5_carrier_raised, |
1012 | .write = spcp8x5_write, | 1007 | .write = spcp8x5_write, |
1013 | .set_termios = spcp8x5_set_termios, | 1008 | .set_termios = spcp8x5_set_termios, |
1009 | .init_termios = spcp8x5_init_termios, | ||
1014 | .ioctl = spcp8x5_ioctl, | 1010 | .ioctl = spcp8x5_ioctl, |
1015 | .tiocmget = spcp8x5_tiocmget, | 1011 | .tiocmget = spcp8x5_tiocmget, |
1016 | .tiocmset = spcp8x5_tiocmset, | 1012 | .tiocmset = spcp8x5_tiocmset, |
diff --git a/drivers/usb/serial/symbolserial.c b/drivers/usb/serial/symbolserial.c index 6157fac9366b..cb7e95f9fcbf 100644 --- a/drivers/usb/serial/symbolserial.c +++ b/drivers/usb/serial/symbolserial.c | |||
@@ -124,8 +124,7 @@ exit: | |||
124 | spin_unlock(&priv->lock); | 124 | spin_unlock(&priv->lock); |
125 | } | 125 | } |
126 | 126 | ||
127 | static int symbol_open(struct tty_struct *tty, struct usb_serial_port *port, | 127 | static int symbol_open(struct tty_struct *tty, struct usb_serial_port *port) |
128 | struct file *filp) | ||
129 | { | 128 | { |
130 | struct symbol_private *priv = usb_get_serial_data(port->serial); | 129 | struct symbol_private *priv = usb_get_serial_data(port->serial); |
131 | unsigned long flags; | 130 | unsigned long flags; |
diff --git a/drivers/usb/serial/ti_usb_3410_5052.c b/drivers/usb/serial/ti_usb_3410_5052.c index 3bc609fe2242..1e9dc8821698 100644 --- a/drivers/usb/serial/ti_usb_3410_5052.c +++ b/drivers/usb/serial/ti_usb_3410_5052.c | |||
@@ -98,8 +98,7 @@ struct ti_device { | |||
98 | 98 | ||
99 | static int ti_startup(struct usb_serial *serial); | 99 | static int ti_startup(struct usb_serial *serial); |
100 | static void ti_release(struct usb_serial *serial); | 100 | static void ti_release(struct usb_serial *serial); |
101 | static int ti_open(struct tty_struct *tty, struct usb_serial_port *port, | 101 | static int ti_open(struct tty_struct *tty, struct usb_serial_port *port); |
102 | struct file *file); | ||
103 | static void ti_close(struct usb_serial_port *port); | 102 | static void ti_close(struct usb_serial_port *port); |
104 | static int ti_write(struct tty_struct *tty, struct usb_serial_port *port, | 103 | static int ti_write(struct tty_struct *tty, struct usb_serial_port *port, |
105 | const unsigned char *data, int count); | 104 | const unsigned char *data, int count); |
@@ -492,8 +491,7 @@ static void ti_release(struct usb_serial *serial) | |||
492 | } | 491 | } |
493 | 492 | ||
494 | 493 | ||
495 | static int ti_open(struct tty_struct *tty, | 494 | static int ti_open(struct tty_struct *tty, struct usb_serial_port *port) |
496 | struct usb_serial_port *port, struct file *file) | ||
497 | { | 495 | { |
498 | struct ti_port *tport = usb_get_serial_port_data(port); | 496 | struct ti_port *tport = usb_get_serial_port_data(port); |
499 | struct ti_device *tdev; | 497 | struct ti_device *tdev; |
diff --git a/drivers/usb/serial/usb-serial.c b/drivers/usb/serial/usb-serial.c index 99188c92068b..ff75a3589e7e 100644 --- a/drivers/usb/serial/usb-serial.c +++ b/drivers/usb/serial/usb-serial.c | |||
@@ -35,6 +35,7 @@ | |||
35 | #include <linux/serial.h> | 35 | #include <linux/serial.h> |
36 | #include <linux/usb.h> | 36 | #include <linux/usb.h> |
37 | #include <linux/usb/serial.h> | 37 | #include <linux/usb/serial.h> |
38 | #include <linux/kfifo.h> | ||
38 | #include "pl2303.h" | 39 | #include "pl2303.h" |
39 | 40 | ||
40 | /* | 41 | /* |
@@ -43,8 +44,6 @@ | |||
43 | #define DRIVER_AUTHOR "Greg Kroah-Hartman, greg@kroah.com, http://www.kroah.com/linux/" | 44 | #define DRIVER_AUTHOR "Greg Kroah-Hartman, greg@kroah.com, http://www.kroah.com/linux/" |
44 | #define DRIVER_DESC "USB Serial Driver core" | 45 | #define DRIVER_DESC "USB Serial Driver core" |
45 | 46 | ||
46 | static void port_free(struct usb_serial_port *port); | ||
47 | |||
48 | /* Driver structure we register with the USB core */ | 47 | /* Driver structure we register with the USB core */ |
49 | static struct usb_driver usb_serial_driver = { | 48 | static struct usb_driver usb_serial_driver = { |
50 | .name = "usbserial", | 49 | .name = "usbserial", |
@@ -68,6 +67,11 @@ static struct usb_serial *serial_table[SERIAL_TTY_MINORS]; | |||
68 | static DEFINE_MUTEX(table_lock); | 67 | static DEFINE_MUTEX(table_lock); |
69 | static LIST_HEAD(usb_serial_driver_list); | 68 | static LIST_HEAD(usb_serial_driver_list); |
70 | 69 | ||
70 | /* | ||
71 | * Look up the serial structure. If it is found and it hasn't been | ||
72 | * disconnected, return with its disc_mutex held and its refcount | ||
73 | * incremented. Otherwise return NULL. | ||
74 | */ | ||
71 | struct usb_serial *usb_serial_get_by_index(unsigned index) | 75 | struct usb_serial *usb_serial_get_by_index(unsigned index) |
72 | { | 76 | { |
73 | struct usb_serial *serial; | 77 | struct usb_serial *serial; |
@@ -75,8 +79,15 @@ struct usb_serial *usb_serial_get_by_index(unsigned index) | |||
75 | mutex_lock(&table_lock); | 79 | mutex_lock(&table_lock); |
76 | serial = serial_table[index]; | 80 | serial = serial_table[index]; |
77 | 81 | ||
78 | if (serial) | 82 | if (serial) { |
79 | kref_get(&serial->kref); | 83 | mutex_lock(&serial->disc_mutex); |
84 | if (serial->disconnected) { | ||
85 | mutex_unlock(&serial->disc_mutex); | ||
86 | serial = NULL; | ||
87 | } else { | ||
88 | kref_get(&serial->kref); | ||
89 | } | ||
90 | } | ||
80 | mutex_unlock(&table_lock); | 91 | mutex_unlock(&table_lock); |
81 | return serial; | 92 | return serial; |
82 | } | 93 | } |
@@ -125,8 +136,10 @@ static void return_serial(struct usb_serial *serial) | |||
125 | 136 | ||
126 | dbg("%s", __func__); | 137 | dbg("%s", __func__); |
127 | 138 | ||
139 | mutex_lock(&table_lock); | ||
128 | for (i = 0; i < serial->num_ports; ++i) | 140 | for (i = 0; i < serial->num_ports; ++i) |
129 | serial_table[serial->minor + i] = NULL; | 141 | serial_table[serial->minor + i] = NULL; |
142 | mutex_unlock(&table_lock); | ||
130 | } | 143 | } |
131 | 144 | ||
132 | static void destroy_serial(struct kref *kref) | 145 | static void destroy_serial(struct kref *kref) |
@@ -145,244 +158,224 @@ static void destroy_serial(struct kref *kref) | |||
145 | 158 | ||
146 | serial->type->release(serial); | 159 | serial->type->release(serial); |
147 | 160 | ||
148 | for (i = 0; i < serial->num_ports; ++i) { | 161 | /* Now that nothing is using the ports, they can be freed */ |
162 | for (i = 0; i < serial->num_port_pointers; ++i) { | ||
149 | port = serial->port[i]; | 163 | port = serial->port[i]; |
150 | if (port) | 164 | if (port) { |
165 | port->serial = NULL; | ||
151 | put_device(&port->dev); | 166 | put_device(&port->dev); |
152 | } | ||
153 | |||
154 | /* If this is a "fake" port, we have to clean it up here, as it will | ||
155 | * not get cleaned up in port_release() as it was never registered with | ||
156 | * the driver core */ | ||
157 | if (serial->num_ports < serial->num_port_pointers) { | ||
158 | for (i = serial->num_ports; | ||
159 | i < serial->num_port_pointers; ++i) { | ||
160 | port = serial->port[i]; | ||
161 | if (port) | ||
162 | port_free(port); | ||
163 | } | 167 | } |
164 | } | 168 | } |
165 | 169 | ||
166 | usb_put_dev(serial->dev); | 170 | usb_put_dev(serial->dev); |
167 | |||
168 | /* free up any memory that we allocated */ | ||
169 | kfree(serial); | 171 | kfree(serial); |
170 | } | 172 | } |
171 | 173 | ||
172 | void usb_serial_put(struct usb_serial *serial) | 174 | void usb_serial_put(struct usb_serial *serial) |
173 | { | 175 | { |
174 | mutex_lock(&table_lock); | ||
175 | kref_put(&serial->kref, destroy_serial); | 176 | kref_put(&serial->kref, destroy_serial); |
176 | mutex_unlock(&table_lock); | ||
177 | } | 177 | } |
178 | 178 | ||
179 | /***************************************************************************** | 179 | /***************************************************************************** |
180 | * Driver tty interface functions | 180 | * Driver tty interface functions |
181 | *****************************************************************************/ | 181 | *****************************************************************************/ |
182 | static int serial_open (struct tty_struct *tty, struct file *filp) | 182 | |
183 | /** | ||
184 | * serial_install - install tty | ||
185 | * @driver: the driver (USB in our case) | ||
186 | * @tty: the tty being created | ||
187 | * | ||
188 | * Create the termios objects for this tty. We use the default | ||
189 | * USB serial settings but permit them to be overridden by | ||
190 | * serial->type->init_termios. | ||
191 | * | ||
192 | * This is the first place a new tty gets used. Hence this is where we | ||
193 | * acquire references to the usb_serial structure and the driver module, | ||
194 | * where we store a pointer to the port, and where we do an autoresume. | ||
195 | * All these actions are reversed in serial_release(). | ||
196 | */ | ||
197 | static int serial_install(struct tty_driver *driver, struct tty_struct *tty) | ||
183 | { | 198 | { |
199 | int idx = tty->index; | ||
184 | struct usb_serial *serial; | 200 | struct usb_serial *serial; |
185 | struct usb_serial_port *port; | 201 | struct usb_serial_port *port; |
186 | unsigned int portNumber; | 202 | int retval = -ENODEV; |
187 | int retval = 0; | ||
188 | int first = 0; | ||
189 | 203 | ||
190 | dbg("%s", __func__); | 204 | dbg("%s", __func__); |
191 | 205 | ||
192 | /* get the serial object associated with this tty pointer */ | 206 | serial = usb_serial_get_by_index(idx); |
193 | serial = usb_serial_get_by_index(tty->index); | 207 | if (!serial) |
194 | if (!serial) { | 208 | return retval; |
195 | tty->driver_data = NULL; | ||
196 | return -ENODEV; | ||
197 | } | ||
198 | 209 | ||
199 | mutex_lock(&serial->disc_mutex); | 210 | port = serial->port[idx - serial->minor]; |
200 | portNumber = tty->index - serial->minor; | 211 | if (!port) |
201 | port = serial->port[portNumber]; | 212 | goto error_no_port; |
202 | if (!port || serial->disconnected) | 213 | if (!try_module_get(serial->type->driver.owner)) |
203 | retval = -ENODEV; | 214 | goto error_module_get; |
204 | else | 215 | |
205 | get_device(&port->dev); | 216 | /* perform the standard setup */ |
206 | /* | 217 | retval = tty_init_termios(tty); |
207 | * Note: Our locking order requirement does not allow port->mutex | ||
208 | * to be acquired while serial->disc_mutex is held. | ||
209 | */ | ||
210 | mutex_unlock(&serial->disc_mutex); | ||
211 | if (retval) | 218 | if (retval) |
212 | goto bailout_serial_put; | 219 | goto error_init_termios; |
213 | 220 | ||
214 | if (mutex_lock_interruptible(&port->mutex)) { | 221 | retval = usb_autopm_get_interface(serial->interface); |
215 | retval = -ERESTARTSYS; | 222 | if (retval) |
216 | goto bailout_port_put; | 223 | goto error_get_interface; |
217 | } | ||
218 | 224 | ||
219 | ++port->port.count; | 225 | mutex_unlock(&serial->disc_mutex); |
226 | |||
227 | /* allow the driver to update the settings */ | ||
228 | if (serial->type->init_termios) | ||
229 | serial->type->init_termios(tty); | ||
220 | 230 | ||
221 | /* set up our port structure making the tty driver | ||
222 | * remember our port object, and us it */ | ||
223 | tty->driver_data = port; | 231 | tty->driver_data = port; |
224 | tty_port_tty_set(&port->port, tty); | ||
225 | 232 | ||
226 | /* If the console is attached, the device is already open */ | 233 | /* Final install (we use the default method) */ |
227 | if (port->port.count == 1 && !port->console) { | 234 | tty_driver_kref_get(driver); |
228 | first = 1; | 235 | tty->count++; |
229 | /* lock this module before we call it | 236 | driver->ttys[idx] = tty; |
230 | * this may fail, which means we must bail out, | 237 | return retval; |
231 | * safe because we are called with BKL held */ | 238 | |
232 | if (!try_module_get(serial->type->driver.owner)) { | 239 | error_get_interface: |
233 | retval = -ENODEV; | 240 | error_init_termios: |
234 | goto bailout_mutex_unlock; | 241 | module_put(serial->type->driver.owner); |
235 | } | 242 | error_module_get: |
243 | error_no_port: | ||
244 | usb_serial_put(serial); | ||
245 | mutex_unlock(&serial->disc_mutex); | ||
246 | return retval; | ||
247 | } | ||
236 | 248 | ||
249 | static int serial_open(struct tty_struct *tty, struct file *filp) | ||
250 | { | ||
251 | struct usb_serial_port *port = tty->driver_data; | ||
252 | struct usb_serial *serial = port->serial; | ||
253 | int retval; | ||
254 | |||
255 | dbg("%s - port %d", __func__, port->number); | ||
256 | |||
257 | spin_lock_irq(&port->port.lock); | ||
258 | if (!tty_hung_up_p(filp)) | ||
259 | ++port->port.count; | ||
260 | spin_unlock_irq(&port->port.lock); | ||
261 | tty_port_tty_set(&port->port, tty); | ||
262 | |||
263 | /* Do the device-specific open only if the hardware isn't | ||
264 | * already initialized. | ||
265 | */ | ||
266 | if (!test_bit(ASYNCB_INITIALIZED, &port->port.flags)) { | ||
267 | if (mutex_lock_interruptible(&port->mutex)) | ||
268 | return -ERESTARTSYS; | ||
237 | mutex_lock(&serial->disc_mutex); | 269 | mutex_lock(&serial->disc_mutex); |
238 | if (serial->disconnected) | 270 | if (serial->disconnected) |
239 | retval = -ENODEV; | 271 | retval = -ENODEV; |
240 | else | 272 | else |
241 | retval = usb_autopm_get_interface(serial->interface); | 273 | retval = port->serial->type->open(tty, port); |
242 | if (retval) | ||
243 | goto bailout_module_put; | ||
244 | |||
245 | /* only call the device specific open if this | ||
246 | * is the first time the port is opened */ | ||
247 | retval = serial->type->open(tty, port, filp); | ||
248 | if (retval) | ||
249 | goto bailout_interface_put; | ||
250 | mutex_unlock(&serial->disc_mutex); | 274 | mutex_unlock(&serial->disc_mutex); |
275 | mutex_unlock(&port->mutex); | ||
276 | if (retval) | ||
277 | return retval; | ||
251 | set_bit(ASYNCB_INITIALIZED, &port->port.flags); | 278 | set_bit(ASYNCB_INITIALIZED, &port->port.flags); |
252 | } | 279 | } |
253 | mutex_unlock(&port->mutex); | 280 | |
254 | /* Now do the correct tty layer semantics */ | 281 | /* Now do the correct tty layer semantics */ |
255 | retval = tty_port_block_til_ready(&port->port, tty, filp); | 282 | retval = tty_port_block_til_ready(&port->port, tty, filp); |
256 | if (retval == 0) { | ||
257 | if (!first) | ||
258 | usb_serial_put(serial); | ||
259 | return 0; | ||
260 | } | ||
261 | mutex_lock(&port->mutex); | ||
262 | if (first == 0) | ||
263 | goto bailout_mutex_unlock; | ||
264 | /* Undo the initial port actions */ | ||
265 | mutex_lock(&serial->disc_mutex); | ||
266 | bailout_interface_put: | ||
267 | usb_autopm_put_interface(serial->interface); | ||
268 | bailout_module_put: | ||
269 | mutex_unlock(&serial->disc_mutex); | ||
270 | module_put(serial->type->driver.owner); | ||
271 | bailout_mutex_unlock: | ||
272 | port->port.count = 0; | ||
273 | tty->driver_data = NULL; | ||
274 | tty_port_tty_set(&port->port, NULL); | ||
275 | mutex_unlock(&port->mutex); | ||
276 | bailout_port_put: | ||
277 | put_device(&port->dev); | ||
278 | bailout_serial_put: | ||
279 | usb_serial_put(serial); | ||
280 | return retval; | 283 | return retval; |
281 | } | 284 | } |
282 | 285 | ||
283 | /** | 286 | /** |
284 | * serial_do_down - shut down hardware | 287 | * serial_down - shut down hardware |
285 | * @port: port to shut down | 288 | * @port: port to shut down |
286 | * | ||
287 | * Shut down a USB port unless it is the console. We never shut down the | ||
288 | * console hardware as it will always be in use. | ||
289 | * | 289 | * |
290 | * Don't free any resources at this point | 290 | * Shut down a USB serial port unless it is the console. We never |
291 | * shut down the console hardware as it will always be in use. | ||
291 | */ | 292 | */ |
292 | static void serial_do_down(struct usb_serial_port *port) | 293 | static void serial_down(struct usb_serial_port *port) |
293 | { | 294 | { |
294 | struct usb_serial_driver *drv = port->serial->type; | 295 | struct usb_serial_driver *drv = port->serial->type; |
295 | struct usb_serial *serial; | ||
296 | struct module *owner; | ||
297 | 296 | ||
298 | /* The console is magical, do not hang up the console hardware | 297 | /* |
299 | or there will be tears */ | 298 | * The console is magical. Do not hang up the console hardware |
299 | * or there will be tears. | ||
300 | */ | ||
300 | if (port->console) | 301 | if (port->console) |
301 | return; | 302 | return; |
302 | 303 | ||
303 | mutex_lock(&port->mutex); | 304 | /* Don't call the close method if the hardware hasn't been |
304 | serial = port->serial; | 305 | * initialized. |
305 | owner = serial->type->driver.owner; | 306 | */ |
307 | if (!test_and_clear_bit(ASYNCB_INITIALIZED, &port->port.flags)) | ||
308 | return; | ||
306 | 309 | ||
310 | mutex_lock(&port->mutex); | ||
307 | if (drv->close) | 311 | if (drv->close) |
308 | drv->close(port); | 312 | drv->close(port); |
309 | |||
310 | mutex_unlock(&port->mutex); | 313 | mutex_unlock(&port->mutex); |
311 | } | 314 | } |
312 | 315 | ||
313 | /** | 316 | static void serial_hangup(struct tty_struct *tty) |
314 | * serial_do_free - free resources post close/hangup | ||
315 | * @port: port to free up | ||
316 | * | ||
317 | * Do the resource freeing and refcount dropping for the port. We must | ||
318 | * be careful about ordering and we must avoid freeing up the console. | ||
319 | */ | ||
320 | |||
321 | static void serial_do_free(struct usb_serial_port *port) | ||
322 | { | 317 | { |
323 | struct usb_serial *serial; | 318 | struct usb_serial_port *port = tty->driver_data; |
324 | struct module *owner; | ||
325 | 319 | ||
326 | /* The console is magical, do not hang up the console hardware | 320 | dbg("%s - port %d", __func__, port->number); |
327 | or there will be tears */ | ||
328 | if (port->console) | ||
329 | return; | ||
330 | 321 | ||
331 | serial = port->serial; | 322 | serial_down(port); |
332 | owner = serial->type->driver.owner; | 323 | tty_port_hangup(&port->port); |
333 | put_device(&port->dev); | ||
334 | /* Mustn't dereference port any more */ | ||
335 | mutex_lock(&serial->disc_mutex); | ||
336 | if (!serial->disconnected) | ||
337 | usb_autopm_put_interface(serial->interface); | ||
338 | mutex_unlock(&serial->disc_mutex); | ||
339 | usb_serial_put(serial); | ||
340 | /* Mustn't dereference serial any more */ | ||
341 | module_put(owner); | ||
342 | } | 324 | } |
343 | 325 | ||
344 | static void serial_close(struct tty_struct *tty, struct file *filp) | 326 | static void serial_close(struct tty_struct *tty, struct file *filp) |
345 | { | 327 | { |
346 | struct usb_serial_port *port = tty->driver_data; | 328 | struct usb_serial_port *port = tty->driver_data; |
347 | 329 | ||
348 | if (!port) | ||
349 | return; | ||
350 | |||
351 | dbg("%s - port %d", __func__, port->number); | 330 | dbg("%s - port %d", __func__, port->number); |
352 | 331 | ||
353 | /* FIXME: | 332 | if (tty_hung_up_p(filp)) |
354 | This leaves a very narrow race. Really we should do the | ||
355 | serial_do_free() on tty->shutdown(), but tty->shutdown can | ||
356 | be called from IRQ context and serial_do_free can sleep. | ||
357 | |||
358 | The right fix is probably to make the tty free (which is rare) | ||
359 | and thus tty->shutdown() occur via a work queue and simplify all | ||
360 | the drivers that use it. | ||
361 | */ | ||
362 | if (tty_hung_up_p(filp)) { | ||
363 | /* serial_hangup already called serial_down at this point. | ||
364 | Another user may have already reopened the port but | ||
365 | serial_do_free is refcounted */ | ||
366 | serial_do_free(port); | ||
367 | return; | 333 | return; |
368 | } | ||
369 | |||
370 | if (tty_port_close_start(&port->port, tty, filp) == 0) | 334 | if (tty_port_close_start(&port->port, tty, filp) == 0) |
371 | return; | 335 | return; |
372 | 336 | serial_down(port); | |
373 | serial_do_down(port); | ||
374 | tty_port_close_end(&port->port, tty); | 337 | tty_port_close_end(&port->port, tty); |
375 | tty_port_tty_set(&port->port, NULL); | 338 | tty_port_tty_set(&port->port, NULL); |
376 | serial_do_free(port); | ||
377 | } | 339 | } |
378 | 340 | ||
379 | static void serial_hangup(struct tty_struct *tty) | 341 | /** |
342 | * serial_release - free resources post close/hangup | ||
343 | * @port: port to free up | ||
344 | * | ||
345 | * Do the resource freeing and refcount dropping for the port. | ||
346 | * Avoid freeing the console. | ||
347 | * | ||
348 | * Called when the last tty kref is dropped. | ||
349 | */ | ||
350 | static void serial_release(struct tty_struct *tty) | ||
380 | { | 351 | { |
381 | struct usb_serial_port *port = tty->driver_data; | 352 | struct usb_serial_port *port = tty->driver_data; |
382 | serial_do_down(port); | 353 | struct usb_serial *serial; |
383 | tty_port_hangup(&port->port); | 354 | struct module *owner; |
384 | /* We must not free port yet - the USB serial layer depends on it's | 355 | |
385 | continued existence */ | 356 | /* The console is magical. Do not hang up the console hardware |
357 | * or there will be tears. | ||
358 | */ | ||
359 | if (port->console) | ||
360 | return; | ||
361 | |||
362 | dbg("%s - port %d", __func__, port->number); | ||
363 | |||
364 | /* Standard shutdown processing */ | ||
365 | tty_shutdown(tty); | ||
366 | |||
367 | tty->driver_data = NULL; | ||
368 | |||
369 | serial = port->serial; | ||
370 | owner = serial->type->driver.owner; | ||
371 | |||
372 | mutex_lock(&serial->disc_mutex); | ||
373 | if (!serial->disconnected) | ||
374 | usb_autopm_put_interface(serial->interface); | ||
375 | mutex_unlock(&serial->disc_mutex); | ||
376 | |||
377 | usb_serial_put(serial); | ||
378 | module_put(owner); | ||
386 | } | 379 | } |
387 | 380 | ||
388 | static int serial_write(struct tty_struct *tty, const unsigned char *buf, | 381 | static int serial_write(struct tty_struct *tty, const unsigned char *buf, |
@@ -527,6 +520,7 @@ static int serial_proc_show(struct seq_file *m, void *v) | |||
527 | 520 | ||
528 | seq_putc(m, '\n'); | 521 | seq_putc(m, '\n'); |
529 | usb_serial_put(serial); | 522 | usb_serial_put(serial); |
523 | mutex_unlock(&serial->disc_mutex); | ||
530 | } | 524 | } |
531 | return 0; | 525 | return 0; |
532 | } | 526 | } |
@@ -596,14 +590,6 @@ static void usb_serial_port_work(struct work_struct *work) | |||
596 | tty_kref_put(tty); | 590 | tty_kref_put(tty); |
597 | } | 591 | } |
598 | 592 | ||
599 | static void port_release(struct device *dev) | ||
600 | { | ||
601 | struct usb_serial_port *port = to_usb_serial_port(dev); | ||
602 | |||
603 | dbg ("%s - %s", __func__, dev_name(dev)); | ||
604 | port_free(port); | ||
605 | } | ||
606 | |||
607 | static void kill_traffic(struct usb_serial_port *port) | 593 | static void kill_traffic(struct usb_serial_port *port) |
608 | { | 594 | { |
609 | usb_kill_urb(port->read_urb); | 595 | usb_kill_urb(port->read_urb); |
@@ -623,8 +609,12 @@ static void kill_traffic(struct usb_serial_port *port) | |||
623 | usb_kill_urb(port->interrupt_out_urb); | 609 | usb_kill_urb(port->interrupt_out_urb); |
624 | } | 610 | } |
625 | 611 | ||
626 | static void port_free(struct usb_serial_port *port) | 612 | static void port_release(struct device *dev) |
627 | { | 613 | { |
614 | struct usb_serial_port *port = to_usb_serial_port(dev); | ||
615 | |||
616 | dbg ("%s - %s", __func__, dev_name(dev)); | ||
617 | |||
628 | /* | 618 | /* |
629 | * Stop all the traffic before cancelling the work, so that | 619 | * Stop all the traffic before cancelling the work, so that |
630 | * nobody will restart it by calling usb_serial_port_softint. | 620 | * nobody will restart it by calling usb_serial_port_softint. |
@@ -636,6 +626,8 @@ static void port_free(struct usb_serial_port *port) | |||
636 | usb_free_urb(port->write_urb); | 626 | usb_free_urb(port->write_urb); |
637 | usb_free_urb(port->interrupt_in_urb); | 627 | usb_free_urb(port->interrupt_in_urb); |
638 | usb_free_urb(port->interrupt_out_urb); | 628 | usb_free_urb(port->interrupt_out_urb); |
629 | if (!IS_ERR(port->write_fifo) && port->write_fifo) | ||
630 | kfifo_free(port->write_fifo); | ||
639 | kfree(port->bulk_in_buffer); | 631 | kfree(port->bulk_in_buffer); |
640 | kfree(port->bulk_out_buffer); | 632 | kfree(port->bulk_out_buffer); |
641 | kfree(port->interrupt_in_buffer); | 633 | kfree(port->interrupt_in_buffer); |
@@ -935,6 +927,11 @@ int usb_serial_probe(struct usb_interface *interface, | |||
935 | mutex_init(&port->mutex); | 927 | mutex_init(&port->mutex); |
936 | INIT_WORK(&port->work, usb_serial_port_work); | 928 | INIT_WORK(&port->work, usb_serial_port_work); |
937 | serial->port[i] = port; | 929 | serial->port[i] = port; |
930 | port->dev.parent = &interface->dev; | ||
931 | port->dev.driver = NULL; | ||
932 | port->dev.bus = &usb_serial_bus_type; | ||
933 | port->dev.release = &port_release; | ||
934 | device_initialize(&port->dev); | ||
938 | } | 935 | } |
939 | 936 | ||
940 | /* set up the endpoint information */ | 937 | /* set up the endpoint information */ |
@@ -970,6 +967,10 @@ int usb_serial_probe(struct usb_interface *interface, | |||
970 | dev_err(&interface->dev, "No free urbs available\n"); | 967 | dev_err(&interface->dev, "No free urbs available\n"); |
971 | goto probe_error; | 968 | goto probe_error; |
972 | } | 969 | } |
970 | port->write_fifo = kfifo_alloc(PAGE_SIZE, GFP_KERNEL, | ||
971 | &port->lock); | ||
972 | if (IS_ERR(port->write_fifo)) | ||
973 | goto probe_error; | ||
973 | buffer_size = le16_to_cpu(endpoint->wMaxPacketSize); | 974 | buffer_size = le16_to_cpu(endpoint->wMaxPacketSize); |
974 | port->bulk_out_size = buffer_size; | 975 | port->bulk_out_size = buffer_size; |
975 | port->bulk_out_endpointAddress = endpoint->bEndpointAddress; | 976 | port->bulk_out_endpointAddress = endpoint->bEndpointAddress; |
@@ -1077,15 +1078,10 @@ int usb_serial_probe(struct usb_interface *interface, | |||
1077 | /* register all of the individual ports with the driver core */ | 1078 | /* register all of the individual ports with the driver core */ |
1078 | for (i = 0; i < num_ports; ++i) { | 1079 | for (i = 0; i < num_ports; ++i) { |
1079 | port = serial->port[i]; | 1080 | port = serial->port[i]; |
1080 | port->dev.parent = &interface->dev; | ||
1081 | port->dev.driver = NULL; | ||
1082 | port->dev.bus = &usb_serial_bus_type; | ||
1083 | port->dev.release = &port_release; | ||
1084 | |||
1085 | dev_set_name(&port->dev, "ttyUSB%d", port->number); | 1081 | dev_set_name(&port->dev, "ttyUSB%d", port->number); |
1086 | dbg ("%s - registering %s", __func__, dev_name(&port->dev)); | 1082 | dbg ("%s - registering %s", __func__, dev_name(&port->dev)); |
1087 | port->dev_state = PORT_REGISTERING; | 1083 | port->dev_state = PORT_REGISTERING; |
1088 | retval = device_register(&port->dev); | 1084 | retval = device_add(&port->dev); |
1089 | if (retval) { | 1085 | if (retval) { |
1090 | dev_err(&port->dev, "Error registering port device, " | 1086 | dev_err(&port->dev, "Error registering port device, " |
1091 | "continuing\n"); | 1087 | "continuing\n"); |
@@ -1103,39 +1099,7 @@ exit: | |||
1103 | return 0; | 1099 | return 0; |
1104 | 1100 | ||
1105 | probe_error: | 1101 | probe_error: |
1106 | for (i = 0; i < num_bulk_in; ++i) { | 1102 | usb_serial_put(serial); |
1107 | port = serial->port[i]; | ||
1108 | if (!port) | ||
1109 | continue; | ||
1110 | usb_free_urb(port->read_urb); | ||
1111 | kfree(port->bulk_in_buffer); | ||
1112 | } | ||
1113 | for (i = 0; i < num_bulk_out; ++i) { | ||
1114 | port = serial->port[i]; | ||
1115 | if (!port) | ||
1116 | continue; | ||
1117 | usb_free_urb(port->write_urb); | ||
1118 | kfree(port->bulk_out_buffer); | ||
1119 | } | ||
1120 | for (i = 0; i < num_interrupt_in; ++i) { | ||
1121 | port = serial->port[i]; | ||
1122 | if (!port) | ||
1123 | continue; | ||
1124 | usb_free_urb(port->interrupt_in_urb); | ||
1125 | kfree(port->interrupt_in_buffer); | ||
1126 | } | ||
1127 | for (i = 0; i < num_interrupt_out; ++i) { | ||
1128 | port = serial->port[i]; | ||
1129 | if (!port) | ||
1130 | continue; | ||
1131 | usb_free_urb(port->interrupt_out_urb); | ||
1132 | kfree(port->interrupt_out_buffer); | ||
1133 | } | ||
1134 | |||
1135 | /* free up any memory that we allocated */ | ||
1136 | for (i = 0; i < serial->num_port_pointers; ++i) | ||
1137 | kfree(serial->port[i]); | ||
1138 | kfree(serial); | ||
1139 | return -EIO; | 1103 | return -EIO; |
1140 | } | 1104 | } |
1141 | EXPORT_SYMBOL_GPL(usb_serial_probe); | 1105 | EXPORT_SYMBOL_GPL(usb_serial_probe); |
@@ -1161,10 +1125,7 @@ void usb_serial_disconnect(struct usb_interface *interface) | |||
1161 | if (port) { | 1125 | if (port) { |
1162 | struct tty_struct *tty = tty_port_tty_get(&port->port); | 1126 | struct tty_struct *tty = tty_port_tty_get(&port->port); |
1163 | if (tty) { | 1127 | if (tty) { |
1164 | /* The hangup will occur asynchronously but | 1128 | tty_vhangup(tty); |
1165 | the object refcounts will sort out all the | ||
1166 | cleanup */ | ||
1167 | tty_hangup(tty); | ||
1168 | tty_kref_put(tty); | 1129 | tty_kref_put(tty); |
1169 | } | 1130 | } |
1170 | kill_traffic(port); | 1131 | kill_traffic(port); |
@@ -1189,8 +1150,7 @@ void usb_serial_disconnect(struct usb_interface *interface) | |||
1189 | } | 1150 | } |
1190 | serial->type->disconnect(serial); | 1151 | serial->type->disconnect(serial); |
1191 | 1152 | ||
1192 | /* let the last holder of this object | 1153 | /* let the last holder of this object cause it to be cleaned up */ |
1193 | * cause it to be cleaned up */ | ||
1194 | usb_serial_put(serial); | 1154 | usb_serial_put(serial); |
1195 | dev_info(dev, "device disconnected\n"); | 1155 | dev_info(dev, "device disconnected\n"); |
1196 | } | 1156 | } |
@@ -1204,15 +1164,19 @@ int usb_serial_suspend(struct usb_interface *intf, pm_message_t message) | |||
1204 | 1164 | ||
1205 | serial->suspending = 1; | 1165 | serial->suspending = 1; |
1206 | 1166 | ||
1167 | if (serial->type->suspend) { | ||
1168 | r = serial->type->suspend(serial, message); | ||
1169 | if (r < 0) | ||
1170 | goto err_out; | ||
1171 | } | ||
1172 | |||
1207 | for (i = 0; i < serial->num_ports; ++i) { | 1173 | for (i = 0; i < serial->num_ports; ++i) { |
1208 | port = serial->port[i]; | 1174 | port = serial->port[i]; |
1209 | if (port) | 1175 | if (port) |
1210 | kill_traffic(port); | 1176 | kill_traffic(port); |
1211 | } | 1177 | } |
1212 | 1178 | ||
1213 | if (serial->type->suspend) | 1179 | err_out: |
1214 | r = serial->type->suspend(serial, message); | ||
1215 | |||
1216 | return r; | 1180 | return r; |
1217 | } | 1181 | } |
1218 | EXPORT_SYMBOL(usb_serial_suspend); | 1182 | EXPORT_SYMBOL(usb_serial_suspend); |
@@ -1246,6 +1210,8 @@ static const struct tty_operations serial_ops = { | |||
1246 | .chars_in_buffer = serial_chars_in_buffer, | 1210 | .chars_in_buffer = serial_chars_in_buffer, |
1247 | .tiocmget = serial_tiocmget, | 1211 | .tiocmget = serial_tiocmget, |
1248 | .tiocmset = serial_tiocmset, | 1212 | .tiocmset = serial_tiocmset, |
1213 | .shutdown = serial_release, | ||
1214 | .install = serial_install, | ||
1249 | .proc_fops = &serial_proc_fops, | 1215 | .proc_fops = &serial_proc_fops, |
1250 | }; | 1216 | }; |
1251 | 1217 | ||
diff --git a/drivers/usb/serial/usb_debug.c b/drivers/usb/serial/usb_debug.c index 614800972dc3..7b5bfc4edd3d 100644 --- a/drivers/usb/serial/usb_debug.c +++ b/drivers/usb/serial/usb_debug.c | |||
@@ -43,11 +43,10 @@ static struct usb_driver debug_driver = { | |||
43 | .no_dynamic_id = 1, | 43 | .no_dynamic_id = 1, |
44 | }; | 44 | }; |
45 | 45 | ||
46 | static int usb_debug_open(struct tty_struct *tty, struct usb_serial_port *port, | 46 | static int usb_debug_open(struct tty_struct *tty, struct usb_serial_port *port) |
47 | struct file *filp) | ||
48 | { | 47 | { |
49 | port->bulk_out_size = USB_DEBUG_MAX_PACKET_SIZE; | 48 | port->bulk_out_size = USB_DEBUG_MAX_PACKET_SIZE; |
50 | return usb_serial_generic_open(tty, port, filp); | 49 | return usb_serial_generic_open(tty, port); |
51 | } | 50 | } |
52 | 51 | ||
53 | /* This HW really does not support a serial break, so one will be | 52 | /* This HW really does not support a serial break, so one will be |
diff --git a/drivers/usb/serial/visor.c b/drivers/usb/serial/visor.c index f5d0f64dcc52..1aa5d20a5d99 100644 --- a/drivers/usb/serial/visor.c +++ b/drivers/usb/serial/visor.c | |||
@@ -36,8 +36,7 @@ | |||
36 | #define DRIVER_DESC "USB HandSpring Visor / Palm OS driver" | 36 | #define DRIVER_DESC "USB HandSpring Visor / Palm OS driver" |
37 | 37 | ||
38 | /* function prototypes for a handspring visor */ | 38 | /* function prototypes for a handspring visor */ |
39 | static int visor_open(struct tty_struct *tty, struct usb_serial_port *port, | 39 | static int visor_open(struct tty_struct *tty, struct usb_serial_port *port); |
40 | struct file *filp); | ||
41 | static void visor_close(struct usb_serial_port *port); | 40 | static void visor_close(struct usb_serial_port *port); |
42 | static int visor_write(struct tty_struct *tty, struct usb_serial_port *port, | 41 | static int visor_write(struct tty_struct *tty, struct usb_serial_port *port, |
43 | const unsigned char *buf, int count); | 42 | const unsigned char *buf, int count); |
@@ -273,8 +272,7 @@ static int stats; | |||
273 | /****************************************************************************** | 272 | /****************************************************************************** |
274 | * Handspring Visor specific driver functions | 273 | * Handspring Visor specific driver functions |
275 | ******************************************************************************/ | 274 | ******************************************************************************/ |
276 | static int visor_open(struct tty_struct *tty, struct usb_serial_port *port, | 275 | static int visor_open(struct tty_struct *tty, struct usb_serial_port *port) |
277 | struct file *filp) | ||
278 | { | 276 | { |
279 | struct usb_serial *serial = port->serial; | 277 | struct usb_serial *serial = port->serial; |
280 | struct visor_private *priv = usb_get_serial_port_data(port); | 278 | struct visor_private *priv = usb_get_serial_port_data(port); |
diff --git a/drivers/usb/serial/whiteheat.c b/drivers/usb/serial/whiteheat.c index 8d126dd7a02e..62424eec33ec 100644 --- a/drivers/usb/serial/whiteheat.c +++ b/drivers/usb/serial/whiteheat.c | |||
@@ -146,7 +146,7 @@ static int whiteheat_firmware_attach(struct usb_serial *serial); | |||
146 | static int whiteheat_attach(struct usb_serial *serial); | 146 | static int whiteheat_attach(struct usb_serial *serial); |
147 | static void whiteheat_release(struct usb_serial *serial); | 147 | static void whiteheat_release(struct usb_serial *serial); |
148 | static int whiteheat_open(struct tty_struct *tty, | 148 | static int whiteheat_open(struct tty_struct *tty, |
149 | struct usb_serial_port *port, struct file *filp); | 149 | struct usb_serial_port *port); |
150 | static void whiteheat_close(struct usb_serial_port *port); | 150 | static void whiteheat_close(struct usb_serial_port *port); |
151 | static int whiteheat_write(struct tty_struct *tty, | 151 | static int whiteheat_write(struct tty_struct *tty, |
152 | struct usb_serial_port *port, | 152 | struct usb_serial_port *port, |
@@ -259,7 +259,7 @@ static int firm_send_command(struct usb_serial_port *port, __u8 command, | |||
259 | __u8 *data, __u8 datasize); | 259 | __u8 *data, __u8 datasize); |
260 | static int firm_open(struct usb_serial_port *port); | 260 | static int firm_open(struct usb_serial_port *port); |
261 | static int firm_close(struct usb_serial_port *port); | 261 | static int firm_close(struct usb_serial_port *port); |
262 | static int firm_setup_port(struct tty_struct *tty); | 262 | static void firm_setup_port(struct tty_struct *tty); |
263 | static int firm_set_rts(struct usb_serial_port *port, __u8 onoff); | 263 | static int firm_set_rts(struct usb_serial_port *port, __u8 onoff); |
264 | static int firm_set_dtr(struct usb_serial_port *port, __u8 onoff); | 264 | static int firm_set_dtr(struct usb_serial_port *port, __u8 onoff); |
265 | static int firm_set_break(struct usb_serial_port *port, __u8 onoff); | 265 | static int firm_set_break(struct usb_serial_port *port, __u8 onoff); |
@@ -659,8 +659,7 @@ static void whiteheat_release(struct usb_serial *serial) | |||
659 | return; | 659 | return; |
660 | } | 660 | } |
661 | 661 | ||
662 | static int whiteheat_open(struct tty_struct *tty, | 662 | static int whiteheat_open(struct tty_struct *tty, struct usb_serial_port *port) |
663 | struct usb_serial_port *port, struct file *filp) | ||
664 | { | 663 | { |
665 | int retval = 0; | 664 | int retval = 0; |
666 | 665 | ||
@@ -1211,7 +1210,7 @@ static int firm_close(struct usb_serial_port *port) | |||
1211 | } | 1210 | } |
1212 | 1211 | ||
1213 | 1212 | ||
1214 | static int firm_setup_port(struct tty_struct *tty) | 1213 | static void firm_setup_port(struct tty_struct *tty) |
1215 | { | 1214 | { |
1216 | struct usb_serial_port *port = tty->driver_data; | 1215 | struct usb_serial_port *port = tty->driver_data; |
1217 | struct whiteheat_port_settings port_settings; | 1216 | struct whiteheat_port_settings port_settings; |
@@ -1286,7 +1285,7 @@ static int firm_setup_port(struct tty_struct *tty) | |||
1286 | port_settings.lloop = 0; | 1285 | port_settings.lloop = 0; |
1287 | 1286 | ||
1288 | /* now send the message to the device */ | 1287 | /* now send the message to the device */ |
1289 | return firm_send_command(port, WHITEHEAT_SETUP_PORT, | 1288 | firm_send_command(port, WHITEHEAT_SETUP_PORT, |
1290 | (__u8 *)&port_settings, sizeof(port_settings)); | 1289 | (__u8 *)&port_settings, sizeof(port_settings)); |
1291 | } | 1290 | } |
1292 | 1291 | ||
diff --git a/drivers/usb/storage/datafab.c b/drivers/usb/storage/datafab.c index 2b6e565262c2..ded836b02d7b 100644 --- a/drivers/usb/storage/datafab.c +++ b/drivers/usb/storage/datafab.c | |||
@@ -334,7 +334,7 @@ static int datafab_determine_lun(struct us_data *us, | |||
334 | unsigned char *buf; | 334 | unsigned char *buf; |
335 | int count = 0, rc; | 335 | int count = 0, rc; |
336 | 336 | ||
337 | if (!us || !info) | 337 | if (!info) |
338 | return USB_STOR_TRANSPORT_ERROR; | 338 | return USB_STOR_TRANSPORT_ERROR; |
339 | 339 | ||
340 | memcpy(command, scommand, 8); | 340 | memcpy(command, scommand, 8); |
@@ -399,7 +399,7 @@ static int datafab_id_device(struct us_data *us, | |||
399 | unsigned char *reply; | 399 | unsigned char *reply; |
400 | int rc; | 400 | int rc; |
401 | 401 | ||
402 | if (!us || !info) | 402 | if (!info) |
403 | return USB_STOR_TRANSPORT_ERROR; | 403 | return USB_STOR_TRANSPORT_ERROR; |
404 | 404 | ||
405 | if (info->lun == -1) { | 405 | if (info->lun == -1) { |
diff --git a/drivers/usb/storage/initializers.c b/drivers/usb/storage/initializers.c index ec17c96371af..105d900150c1 100644 --- a/drivers/usb/storage/initializers.c +++ b/drivers/usb/storage/initializers.c | |||
@@ -102,5 +102,5 @@ int usb_stor_huawei_e220_init(struct us_data *us) | |||
102 | USB_TYPE_STANDARD | USB_RECIP_DEVICE, | 102 | USB_TYPE_STANDARD | USB_RECIP_DEVICE, |
103 | 0x01, 0x0, NULL, 0x0, 1000); | 103 | 0x01, 0x0, NULL, 0x0, 1000); |
104 | US_DEBUGP("Huawei mode set result is %d\n", result); | 104 | US_DEBUGP("Huawei mode set result is %d\n", result); |
105 | return (result ? 0 : -ENODEV); | 105 | return 0; |
106 | } | 106 | } |
diff --git a/drivers/usb/storage/jumpshot.c b/drivers/usb/storage/jumpshot.c index 1c69420e3acf..6168596c5ac6 100644 --- a/drivers/usb/storage/jumpshot.c +++ b/drivers/usb/storage/jumpshot.c | |||
@@ -335,7 +335,7 @@ static int jumpshot_id_device(struct us_data *us, | |||
335 | unsigned char *reply; | 335 | unsigned char *reply; |
336 | int rc; | 336 | int rc; |
337 | 337 | ||
338 | if (!us || !info) | 338 | if (!info) |
339 | return USB_STOR_TRANSPORT_ERROR; | 339 | return USB_STOR_TRANSPORT_ERROR; |
340 | 340 | ||
341 | command[0] = 0xE0; | 341 | command[0] = 0xE0; |
diff --git a/drivers/usb/storage/onetouch.c b/drivers/usb/storage/onetouch.c index 380233bd6a39..80e65f29921c 100644 --- a/drivers/usb/storage/onetouch.c +++ b/drivers/usb/storage/onetouch.c | |||
@@ -163,7 +163,7 @@ static void usb_onetouch_pm_hook(struct us_data *us, int action) | |||
163 | usb_kill_urb(onetouch->irq); | 163 | usb_kill_urb(onetouch->irq); |
164 | break; | 164 | break; |
165 | case US_RESUME: | 165 | case US_RESUME: |
166 | if (usb_submit_urb(onetouch->irq, GFP_KERNEL) != 0) | 166 | if (usb_submit_urb(onetouch->irq, GFP_NOIO) != 0) |
167 | dev_err(&onetouch->irq->dev->dev, | 167 | dev_err(&onetouch->irq->dev->dev, |
168 | "usb_submit_urb failed\n"); | 168 | "usb_submit_urb failed\n"); |
169 | break; | 169 | break; |
diff --git a/drivers/usb/storage/unusual_devs.h b/drivers/usb/storage/unusual_devs.h index 7477d411959f..079ae0f7bec1 100644 --- a/drivers/usb/storage/unusual_devs.h +++ b/drivers/usb/storage/unusual_devs.h | |||
@@ -66,13 +66,6 @@ UNUSUAL_DEV( 0x03eb, 0x2002, 0x0100, 0x0100, | |||
66 | US_SC_DEVICE, US_PR_DEVICE, NULL, | 66 | US_SC_DEVICE, US_PR_DEVICE, NULL, |
67 | US_FL_IGNORE_RESIDUE), | 67 | US_FL_IGNORE_RESIDUE), |
68 | 68 | ||
69 | /* modified by Tobias Lorenz <tobias.lorenz@gmx.net> */ | ||
70 | UNUSUAL_DEV( 0x03ee, 0x6901, 0x0000, 0x0200, | ||
71 | "Mitsumi", | ||
72 | "USB FDD", | ||
73 | US_SC_DEVICE, US_PR_DEVICE, NULL, | ||
74 | US_FL_SINGLE_LUN ), | ||
75 | |||
76 | /* Reported by Rodolfo Quesada <rquesada@roqz.net> */ | 69 | /* Reported by Rodolfo Quesada <rquesada@roqz.net> */ |
77 | UNUSUAL_DEV( 0x03ee, 0x6906, 0x0003, 0x0003, | 70 | UNUSUAL_DEV( 0x03ee, 0x6906, 0x0003, 0x0003, |
78 | "VIA Technologies Inc.", | 71 | "VIA Technologies Inc.", |
@@ -233,13 +226,6 @@ UNUSUAL_DEV( 0x0421, 0x0495, 0x0370, 0x0370, | |||
233 | US_SC_DEVICE, US_PR_DEVICE, NULL, | 226 | US_SC_DEVICE, US_PR_DEVICE, NULL, |
234 | US_FL_MAX_SECTORS_64 ), | 227 | US_FL_MAX_SECTORS_64 ), |
235 | 228 | ||
236 | /* Reported by Olaf Hering <olh@suse.de> from novell bug #105878 */ | ||
237 | UNUSUAL_DEV( 0x0424, 0x0fdc, 0x0210, 0x0210, | ||
238 | "SMSC", | ||
239 | "FDC GOLD-2.30", | ||
240 | US_SC_DEVICE, US_PR_DEVICE, NULL, | ||
241 | US_FL_SINGLE_LUN ), | ||
242 | |||
243 | #ifdef NO_SDDR09 | 229 | #ifdef NO_SDDR09 |
244 | UNUSUAL_DEV( 0x0436, 0x0005, 0x0100, 0x0100, | 230 | UNUSUAL_DEV( 0x0436, 0x0005, 0x0100, 0x0100, |
245 | "Microtech", | 231 | "Microtech", |
@@ -664,19 +650,13 @@ UNUSUAL_DEV( 0x055d, 0x2020, 0x0000, 0x0210, | |||
664 | US_SC_DEVICE, US_PR_DEVICE, NULL, | 650 | US_SC_DEVICE, US_PR_DEVICE, NULL, |
665 | US_FL_SINGLE_LUN ), | 651 | US_FL_SINGLE_LUN ), |
666 | 652 | ||
667 | 653 | /* We keep this entry to force the transport; firmware 3.00 and later is ok. */ | |
668 | UNUSUAL_DEV( 0x057b, 0x0000, 0x0000, 0x0299, | 654 | UNUSUAL_DEV( 0x057b, 0x0000, 0x0000, 0x0299, |
669 | "Y-E Data", | 655 | "Y-E Data", |
670 | "Flashbuster-U", | 656 | "Flashbuster-U", |
671 | US_SC_DEVICE, US_PR_CB, NULL, | 657 | US_SC_DEVICE, US_PR_CB, NULL, |
672 | US_FL_SINGLE_LUN), | 658 | US_FL_SINGLE_LUN), |
673 | 659 | ||
674 | UNUSUAL_DEV( 0x057b, 0x0000, 0x0300, 0x9999, | ||
675 | "Y-E Data", | ||
676 | "Flashbuster-U", | ||
677 | US_SC_DEVICE, US_PR_DEVICE, NULL, | ||
678 | US_FL_SINGLE_LUN), | ||
679 | |||
680 | /* Reported by Johann Cardon <johann.cardon@free.fr> | 660 | /* Reported by Johann Cardon <johann.cardon@free.fr> |
681 | * This entry is needed only because the device reports | 661 | * This entry is needed only because the device reports |
682 | * bInterfaceClass = 0xff (vendor-specific) | 662 | * bInterfaceClass = 0xff (vendor-specific) |
diff --git a/drivers/usb/usb-skeleton.c b/drivers/usb/usb-skeleton.c index 60ba631e99c2..b62f2bc064f6 100644 --- a/drivers/usb/usb-skeleton.c +++ b/drivers/usb/usb-skeleton.c | |||
@@ -18,7 +18,7 @@ | |||
18 | #include <linux/slab.h> | 18 | #include <linux/slab.h> |
19 | #include <linux/module.h> | 19 | #include <linux/module.h> |
20 | #include <linux/kref.h> | 20 | #include <linux/kref.h> |
21 | #include <asm/uaccess.h> | 21 | #include <linux/uaccess.h> |
22 | #include <linux/usb.h> | 22 | #include <linux/usb.h> |
23 | #include <linux/mutex.h> | 23 | #include <linux/mutex.h> |
24 | 24 | ||
@@ -28,7 +28,7 @@ | |||
28 | #define USB_SKEL_PRODUCT_ID 0xfff0 | 28 | #define USB_SKEL_PRODUCT_ID 0xfff0 |
29 | 29 | ||
30 | /* table of devices that work with this driver */ | 30 | /* table of devices that work with this driver */ |
31 | static struct usb_device_id skel_table [] = { | 31 | static struct usb_device_id skel_table[] = { |
32 | { USB_DEVICE(USB_SKEL_VENDOR_ID, USB_SKEL_PRODUCT_ID) }, | 32 | { USB_DEVICE(USB_SKEL_VENDOR_ID, USB_SKEL_PRODUCT_ID) }, |
33 | { } /* Terminating entry */ | 33 | { } /* Terminating entry */ |
34 | }; | 34 | }; |
@@ -52,15 +52,21 @@ struct usb_skel { | |||
52 | struct usb_interface *interface; /* the interface for this device */ | 52 | struct usb_interface *interface; /* the interface for this device */ |
53 | struct semaphore limit_sem; /* limiting the number of writes in progress */ | 53 | struct semaphore limit_sem; /* limiting the number of writes in progress */ |
54 | struct usb_anchor submitted; /* in case we need to retract our submissions */ | 54 | struct usb_anchor submitted; /* in case we need to retract our submissions */ |
55 | struct urb *bulk_in_urb; /* the urb to read data with */ | ||
55 | unsigned char *bulk_in_buffer; /* the buffer to receive data */ | 56 | unsigned char *bulk_in_buffer; /* the buffer to receive data */ |
56 | size_t bulk_in_size; /* the size of the receive buffer */ | 57 | size_t bulk_in_size; /* the size of the receive buffer */ |
58 | size_t bulk_in_filled; /* number of bytes in the buffer */ | ||
59 | size_t bulk_in_copied; /* already copied to user space */ | ||
57 | __u8 bulk_in_endpointAddr; /* the address of the bulk in endpoint */ | 60 | __u8 bulk_in_endpointAddr; /* the address of the bulk in endpoint */ |
58 | __u8 bulk_out_endpointAddr; /* the address of the bulk out endpoint */ | 61 | __u8 bulk_out_endpointAddr; /* the address of the bulk out endpoint */ |
59 | int errors; /* the last request tanked */ | 62 | int errors; /* the last request tanked */ |
60 | int open_count; /* count the number of openers */ | 63 | int open_count; /* count the number of openers */ |
64 | bool ongoing_read; /* a read is going on */ | ||
65 | bool processed_urb; /* indicates we haven't processed the urb */ | ||
61 | spinlock_t err_lock; /* lock for errors */ | 66 | spinlock_t err_lock; /* lock for errors */ |
62 | struct kref kref; | 67 | struct kref kref; |
63 | struct mutex io_mutex; /* synchronize I/O with disconnect */ | 68 | struct mutex io_mutex; /* synchronize I/O with disconnect */ |
69 | struct completion bulk_in_completion; /* to wait for an ongoing read */ | ||
64 | }; | 70 | }; |
65 | #define to_skel_dev(d) container_of(d, struct usb_skel, kref) | 71 | #define to_skel_dev(d) container_of(d, struct usb_skel, kref) |
66 | 72 | ||
@@ -71,6 +77,7 @@ static void skel_delete(struct kref *kref) | |||
71 | { | 77 | { |
72 | struct usb_skel *dev = to_skel_dev(kref); | 78 | struct usb_skel *dev = to_skel_dev(kref); |
73 | 79 | ||
80 | usb_free_urb(dev->bulk_in_urb); | ||
74 | usb_put_dev(dev->udev); | 81 | usb_put_dev(dev->udev); |
75 | kfree(dev->bulk_in_buffer); | 82 | kfree(dev->bulk_in_buffer); |
76 | kfree(dev); | 83 | kfree(dev); |
@@ -87,7 +94,7 @@ static int skel_open(struct inode *inode, struct file *file) | |||
87 | 94 | ||
88 | interface = usb_find_interface(&skel_driver, subminor); | 95 | interface = usb_find_interface(&skel_driver, subminor); |
89 | if (!interface) { | 96 | if (!interface) { |
90 | err ("%s - error, can't find device for minor %d", | 97 | err("%s - error, can't find device for minor %d", |
91 | __func__, subminor); | 98 | __func__, subminor); |
92 | retval = -ENODEV; | 99 | retval = -ENODEV; |
93 | goto exit; | 100 | goto exit; |
@@ -174,38 +181,190 @@ static int skel_flush(struct file *file, fl_owner_t id) | |||
174 | return res; | 181 | return res; |
175 | } | 182 | } |
176 | 183 | ||
177 | static ssize_t skel_read(struct file *file, char *buffer, size_t count, loff_t *ppos) | 184 | static void skel_read_bulk_callback(struct urb *urb) |
178 | { | 185 | { |
179 | struct usb_skel *dev; | 186 | struct usb_skel *dev; |
180 | int retval; | 187 | |
181 | int bytes_read; | 188 | dev = urb->context; |
189 | |||
190 | spin_lock(&dev->err_lock); | ||
191 | /* sync/async unlink faults aren't errors */ | ||
192 | if (urb->status) { | ||
193 | if (!(urb->status == -ENOENT || | ||
194 | urb->status == -ECONNRESET || | ||
195 | urb->status == -ESHUTDOWN)) | ||
196 | err("%s - nonzero write bulk status received: %d", | ||
197 | __func__, urb->status); | ||
198 | |||
199 | dev->errors = urb->status; | ||
200 | } else { | ||
201 | dev->bulk_in_filled = urb->actual_length; | ||
202 | } | ||
203 | dev->ongoing_read = 0; | ||
204 | spin_unlock(&dev->err_lock); | ||
205 | |||
206 | complete(&dev->bulk_in_completion); | ||
207 | } | ||
208 | |||
209 | static int skel_do_read_io(struct usb_skel *dev, size_t count) | ||
210 | { | ||
211 | int rv; | ||
212 | |||
213 | /* prepare a read */ | ||
214 | usb_fill_bulk_urb(dev->bulk_in_urb, | ||
215 | dev->udev, | ||
216 | usb_rcvbulkpipe(dev->udev, | ||
217 | dev->bulk_in_endpointAddr), | ||
218 | dev->bulk_in_buffer, | ||
219 | min(dev->bulk_in_size, count), | ||
220 | skel_read_bulk_callback, | ||
221 | dev); | ||
222 | /* tell everybody to leave the URB alone */ | ||
223 | spin_lock_irq(&dev->err_lock); | ||
224 | dev->ongoing_read = 1; | ||
225 | spin_unlock_irq(&dev->err_lock); | ||
226 | |||
227 | /* do it */ | ||
228 | rv = usb_submit_urb(dev->bulk_in_urb, GFP_KERNEL); | ||
229 | if (rv < 0) { | ||
230 | err("%s - failed submitting read urb, error %d", | ||
231 | __func__, rv); | ||
232 | dev->bulk_in_filled = 0; | ||
233 | rv = (rv == -ENOMEM) ? rv : -EIO; | ||
234 | spin_lock_irq(&dev->err_lock); | ||
235 | dev->ongoing_read = 0; | ||
236 | spin_unlock_irq(&dev->err_lock); | ||
237 | } | ||
238 | |||
239 | return rv; | ||
240 | } | ||
241 | |||
242 | static ssize_t skel_read(struct file *file, char *buffer, size_t count, | ||
243 | loff_t *ppos) | ||
244 | { | ||
245 | struct usb_skel *dev; | ||
246 | int rv; | ||
247 | bool ongoing_io; | ||
182 | 248 | ||
183 | dev = (struct usb_skel *)file->private_data; | 249 | dev = (struct usb_skel *)file->private_data; |
184 | 250 | ||
185 | mutex_lock(&dev->io_mutex); | 251 | /* if we cannot read at all, return EOF */ |
252 | if (!dev->bulk_in_urb || !count) | ||
253 | return 0; | ||
254 | |||
255 | /* no concurrent readers */ | ||
256 | rv = mutex_lock_interruptible(&dev->io_mutex); | ||
257 | if (rv < 0) | ||
258 | return rv; | ||
259 | |||
186 | if (!dev->interface) { /* disconnect() was called */ | 260 | if (!dev->interface) { /* disconnect() was called */ |
187 | retval = -ENODEV; | 261 | rv = -ENODEV; |
188 | goto exit; | 262 | goto exit; |
189 | } | 263 | } |
190 | 264 | ||
191 | /* do a blocking bulk read to get data from the device */ | 265 | /* if IO is under way, we must not touch things */ |
192 | retval = usb_bulk_msg(dev->udev, | 266 | retry: |
193 | usb_rcvbulkpipe(dev->udev, dev->bulk_in_endpointAddr), | 267 | spin_lock_irq(&dev->err_lock); |
194 | dev->bulk_in_buffer, | 268 | ongoing_io = dev->ongoing_read; |
195 | min(dev->bulk_in_size, count), | 269 | spin_unlock_irq(&dev->err_lock); |
196 | &bytes_read, 10000); | 270 | |
197 | 271 | if (ongoing_io) { | |
198 | /* if the read was successful, copy the data to userspace */ | 272 | /* nonblocking IO shall not wait */ |
199 | if (!retval) { | 273 | if (file->f_flags & O_NONBLOCK) { |
200 | if (copy_to_user(buffer, dev->bulk_in_buffer, bytes_read)) | 274 | rv = -EAGAIN; |
201 | retval = -EFAULT; | 275 | goto exit; |
202 | else | 276 | } |
203 | retval = bytes_read; | 277 | /* |
278 | * IO may take forever | ||
279 | * hence wait in an interruptible state | ||
280 | */ | ||
281 | rv = wait_for_completion_interruptible(&dev->bulk_in_completion); | ||
282 | if (rv < 0) | ||
283 | goto exit; | ||
284 | /* | ||
285 | * by waiting we also semiprocessed the urb | ||
286 | * we must finish now | ||
287 | */ | ||
288 | dev->bulk_in_copied = 0; | ||
289 | dev->processed_urb = 1; | ||
290 | } | ||
291 | |||
292 | if (!dev->processed_urb) { | ||
293 | /* | ||
294 | * the URB hasn't been processed | ||
295 | * do it now | ||
296 | */ | ||
297 | wait_for_completion(&dev->bulk_in_completion); | ||
298 | dev->bulk_in_copied = 0; | ||
299 | dev->processed_urb = 1; | ||
300 | } | ||
301 | |||
302 | /* errors must be reported */ | ||
303 | rv = dev->errors; | ||
304 | if (rv < 0) { | ||
305 | /* any error is reported once */ | ||
306 | dev->errors = 0; | ||
307 | /* to preserve notifications about reset */ | ||
308 | rv = (rv == -EPIPE) ? rv : -EIO; | ||
309 | /* no data to deliver */ | ||
310 | dev->bulk_in_filled = 0; | ||
311 | /* report it */ | ||
312 | goto exit; | ||
204 | } | 313 | } |
205 | 314 | ||
315 | /* | ||
316 | * if the buffer is filled we may satisfy the read | ||
317 | * else we need to start IO | ||
318 | */ | ||
319 | |||
320 | if (dev->bulk_in_filled) { | ||
321 | /* we had read data */ | ||
322 | size_t available = dev->bulk_in_filled - dev->bulk_in_copied; | ||
323 | size_t chunk = min(available, count); | ||
324 | |||
325 | if (!available) { | ||
326 | /* | ||
327 | * all data has been used | ||
328 | * actual IO needs to be done | ||
329 | */ | ||
330 | rv = skel_do_read_io(dev, count); | ||
331 | if (rv < 0) | ||
332 | goto exit; | ||
333 | else | ||
334 | goto retry; | ||
335 | } | ||
336 | /* | ||
337 | * data is available | ||
338 | * chunk tells us how much shall be copied | ||
339 | */ | ||
340 | |||
341 | if (copy_to_user(buffer, | ||
342 | dev->bulk_in_buffer + dev->bulk_in_copied, | ||
343 | chunk)) | ||
344 | rv = -EFAULT; | ||
345 | else | ||
346 | rv = chunk; | ||
347 | |||
348 | dev->bulk_in_copied += chunk; | ||
349 | |||
350 | /* | ||
351 | * if we are asked for more than we have, | ||
352 | * we start IO but don't wait | ||
353 | */ | ||
354 | if (available < count) | ||
355 | skel_do_read_io(dev, count - chunk); | ||
356 | } else { | ||
357 | /* no data in the buffer */ | ||
358 | rv = skel_do_read_io(dev, count); | ||
359 | if (rv < 0) | ||
360 | goto exit; | ||
361 | else if (!file->f_flags & O_NONBLOCK) | ||
362 | goto retry; | ||
363 | rv = -EAGAIN; | ||
364 | } | ||
206 | exit: | 365 | exit: |
207 | mutex_unlock(&dev->io_mutex); | 366 | mutex_unlock(&dev->io_mutex); |
208 | return retval; | 367 | return rv; |
209 | } | 368 | } |
210 | 369 | ||
211 | static void skel_write_bulk_callback(struct urb *urb) | 370 | static void skel_write_bulk_callback(struct urb *urb) |
@@ -216,7 +375,7 @@ static void skel_write_bulk_callback(struct urb *urb) | |||
216 | 375 | ||
217 | /* sync/async unlink faults aren't errors */ | 376 | /* sync/async unlink faults aren't errors */ |
218 | if (urb->status) { | 377 | if (urb->status) { |
219 | if(!(urb->status == -ENOENT || | 378 | if (!(urb->status == -ENOENT || |
220 | urb->status == -ECONNRESET || | 379 | urb->status == -ECONNRESET || |
221 | urb->status == -ESHUTDOWN)) | 380 | urb->status == -ESHUTDOWN)) |
222 | err("%s - nonzero write bulk status received: %d", | 381 | err("%s - nonzero write bulk status received: %d", |
@@ -233,7 +392,8 @@ static void skel_write_bulk_callback(struct urb *urb) | |||
233 | up(&dev->limit_sem); | 392 | up(&dev->limit_sem); |
234 | } | 393 | } |
235 | 394 | ||
236 | static ssize_t skel_write(struct file *file, const char *user_buffer, size_t count, loff_t *ppos) | 395 | static ssize_t skel_write(struct file *file, const char *user_buffer, |
396 | size_t count, loff_t *ppos) | ||
237 | { | 397 | { |
238 | struct usb_skel *dev; | 398 | struct usb_skel *dev; |
239 | int retval = 0; | 399 | int retval = 0; |
@@ -247,14 +407,25 @@ static ssize_t skel_write(struct file *file, const char *user_buffer, size_t cou | |||
247 | if (count == 0) | 407 | if (count == 0) |
248 | goto exit; | 408 | goto exit; |
249 | 409 | ||
250 | /* limit the number of URBs in flight to stop a user from using up all RAM */ | 410 | /* |
251 | if (down_interruptible(&dev->limit_sem)) { | 411 | * limit the number of URBs in flight to stop a user from using up all |
252 | retval = -ERESTARTSYS; | 412 | * RAM |
253 | goto exit; | 413 | */ |
414 | if (!file->f_flags & O_NONBLOCK) { | ||
415 | if (down_interruptible(&dev->limit_sem)) { | ||
416 | retval = -ERESTARTSYS; | ||
417 | goto exit; | ||
418 | } | ||
419 | } else { | ||
420 | if (down_trylock(&dev->limit_sem)) { | ||
421 | retval = -EAGAIN; | ||
422 | goto exit; | ||
423 | } | ||
254 | } | 424 | } |
255 | 425 | ||
256 | spin_lock_irq(&dev->err_lock); | 426 | spin_lock_irq(&dev->err_lock); |
257 | if ((retval = dev->errors) < 0) { | 427 | retval = dev->errors; |
428 | if (retval < 0) { | ||
258 | /* any error is reported once */ | 429 | /* any error is reported once */ |
259 | dev->errors = 0; | 430 | dev->errors = 0; |
260 | /* to preserve notifications about reset */ | 431 | /* to preserve notifications about reset */ |
@@ -271,7 +442,8 @@ static ssize_t skel_write(struct file *file, const char *user_buffer, size_t cou | |||
271 | goto error; | 442 | goto error; |
272 | } | 443 | } |
273 | 444 | ||
274 | buf = usb_buffer_alloc(dev->udev, writesize, GFP_KERNEL, &urb->transfer_dma); | 445 | buf = usb_buffer_alloc(dev->udev, writesize, GFP_KERNEL, |
446 | &urb->transfer_dma); | ||
275 | if (!buf) { | 447 | if (!buf) { |
276 | retval = -ENOMEM; | 448 | retval = -ENOMEM; |
277 | goto error; | 449 | goto error; |
@@ -301,11 +473,15 @@ static ssize_t skel_write(struct file *file, const char *user_buffer, size_t cou | |||
301 | retval = usb_submit_urb(urb, GFP_KERNEL); | 473 | retval = usb_submit_urb(urb, GFP_KERNEL); |
302 | mutex_unlock(&dev->io_mutex); | 474 | mutex_unlock(&dev->io_mutex); |
303 | if (retval) { | 475 | if (retval) { |
304 | err("%s - failed submitting write urb, error %d", __func__, retval); | 476 | err("%s - failed submitting write urb, error %d", __func__, |
477 | retval); | ||
305 | goto error_unanchor; | 478 | goto error_unanchor; |
306 | } | 479 | } |
307 | 480 | ||
308 | /* release our reference to this urb, the USB core will eventually free it entirely */ | 481 | /* |
482 | * release our reference to this urb, the USB core will eventually free | ||
483 | * it entirely | ||
484 | */ | ||
309 | usb_free_urb(urb); | 485 | usb_free_urb(urb); |
310 | 486 | ||
311 | 487 | ||
@@ -343,7 +519,8 @@ static struct usb_class_driver skel_class = { | |||
343 | .minor_base = USB_SKEL_MINOR_BASE, | 519 | .minor_base = USB_SKEL_MINOR_BASE, |
344 | }; | 520 | }; |
345 | 521 | ||
346 | static int skel_probe(struct usb_interface *interface, const struct usb_device_id *id) | 522 | static int skel_probe(struct usb_interface *interface, |
523 | const struct usb_device_id *id) | ||
347 | { | 524 | { |
348 | struct usb_skel *dev; | 525 | struct usb_skel *dev; |
349 | struct usb_host_interface *iface_desc; | 526 | struct usb_host_interface *iface_desc; |
@@ -363,6 +540,7 @@ static int skel_probe(struct usb_interface *interface, const struct usb_device_i | |||
363 | mutex_init(&dev->io_mutex); | 540 | mutex_init(&dev->io_mutex); |
364 | spin_lock_init(&dev->err_lock); | 541 | spin_lock_init(&dev->err_lock); |
365 | init_usb_anchor(&dev->submitted); | 542 | init_usb_anchor(&dev->submitted); |
543 | init_completion(&dev->bulk_in_completion); | ||
366 | 544 | ||
367 | dev->udev = usb_get_dev(interface_to_usbdev(interface)); | 545 | dev->udev = usb_get_dev(interface_to_usbdev(interface)); |
368 | dev->interface = interface; | 546 | dev->interface = interface; |
@@ -384,6 +562,11 @@ static int skel_probe(struct usb_interface *interface, const struct usb_device_i | |||
384 | err("Could not allocate bulk_in_buffer"); | 562 | err("Could not allocate bulk_in_buffer"); |
385 | goto error; | 563 | goto error; |
386 | } | 564 | } |
565 | dev->bulk_in_urb = usb_alloc_urb(0, GFP_KERNEL); | ||
566 | if (!dev->bulk_in_urb) { | ||
567 | err("Could not allocate bulk_in_urb"); | ||
568 | goto error; | ||
569 | } | ||
387 | } | 570 | } |
388 | 571 | ||
389 | if (!dev->bulk_out_endpointAddr && | 572 | if (!dev->bulk_out_endpointAddr && |
@@ -453,6 +636,7 @@ static void skel_draw_down(struct usb_skel *dev) | |||
453 | time = usb_wait_anchor_empty_timeout(&dev->submitted, 1000); | 636 | time = usb_wait_anchor_empty_timeout(&dev->submitted, 1000); |
454 | if (!time) | 637 | if (!time) |
455 | usb_kill_anchored_urbs(&dev->submitted); | 638 | usb_kill_anchored_urbs(&dev->submitted); |
639 | usb_kill_urb(dev->bulk_in_urb); | ||
456 | } | 640 | } |
457 | 641 | ||
458 | static int skel_suspend(struct usb_interface *intf, pm_message_t message) | 642 | static int skel_suspend(struct usb_interface *intf, pm_message_t message) |
@@ -465,7 +649,7 @@ static int skel_suspend(struct usb_interface *intf, pm_message_t message) | |||
465 | return 0; | 649 | return 0; |
466 | } | 650 | } |
467 | 651 | ||
468 | static int skel_resume (struct usb_interface *intf) | 652 | static int skel_resume(struct usb_interface *intf) |
469 | { | 653 | { |
470 | return 0; | 654 | return 0; |
471 | } | 655 | } |
diff --git a/drivers/usb/wusbcore/wa-hc.h b/drivers/usb/wusbcore/wa-hc.h index 586d350cdb4d..d6bea3e0b54a 100644 --- a/drivers/usb/wusbcore/wa-hc.h +++ b/drivers/usb/wusbcore/wa-hc.h | |||
@@ -47,7 +47,7 @@ | |||
47 | * to an endpoint on a WUSB device that is connected to a | 47 | * to an endpoint on a WUSB device that is connected to a |
48 | * HWA RC. | 48 | * HWA RC. |
49 | * | 49 | * |
50 | * xfer Transfer managment -- this is all the code that gets a | 50 | * xfer Transfer management -- this is all the code that gets a |
51 | * buffer and pushes it to a device (or viceversa). * | 51 | * buffer and pushes it to a device (or viceversa). * |
52 | * | 52 | * |
53 | * Some day a lot of this code will be shared between this driver and | 53 | * Some day a lot of this code will be shared between this driver and |