aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2008-02-01 22:28:57 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2008-02-01 22:28:57 -0500
commitb6cf160c4b788a31f6a4017a469b956ca77febf4 (patch)
treed4d525000e283fe08905385d91dd0170454eae9a /drivers
parented50d6cbc394cd0966469d3e249353c9dd1d38b9 (diff)
parent2c044a4803804708984931bcbd03314732e995d5 (diff)
Merge git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb-2.6
* git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb-2.6: (128 commits) USB: fix codingstyle issues in drivers/usb/core/*.c USB: fix codingstyle issues in drivers/usb/core/message.c USB: fix codingstyle issues in drivers/usb/core/hcd-pci.c USB: fix codingstyle issues in drivers/usb/core/devio.c USB: fix codingstyle issues in drivers/usb/core/devices.c USB: fix codingstyle issues in drivers/usb/core/*.h USB: fix codingstyle issues in include/linux/usb/ USB: fix codingstyle issues in include/linux/usb.h USB: mark USB drivers as being GPL only USB: use a real vendor and product id for root hubs USB: mount options: fix usbfs USB: Fix usb_serial_driver structure for Kobil cardreader driver. usb: ehci should use u16 for isochronous intervals usb: ehci, remove false clear-reset path USB: Use menuconfig objects usb: ohci-sm501 driver usb: dma bounce buffer support USB: last abuses of intfdata in close for usb-serial drivers USB: kl5kusb105 don't flush to logically disconnected devices USB: oti6858: cleanup ...
Diffstat (limited to 'drivers')
-rw-r--r--drivers/block/ub.c23
-rw-r--r--drivers/usb/Kconfig5
-rw-r--r--drivers/usb/atm/Kconfig9
-rw-r--r--drivers/usb/atm/ueagle-atm.c6
-rw-r--r--drivers/usb/class/cdc-acm.c94
-rw-r--r--drivers/usb/class/cdc-acm.h2
-rw-r--r--drivers/usb/core/Kconfig15
-rw-r--r--drivers/usb/core/buffer.c20
-rw-r--r--drivers/usb/core/config.c14
-rw-r--r--drivers/usb/core/devices.c154
-rw-r--r--drivers/usb/core/devio.c359
-rw-r--r--drivers/usb/core/driver.c44
-rw-r--r--drivers/usb/core/file.c4
-rw-r--r--drivers/usb/core/hcd-pci.c145
-rw-r--r--drivers/usb/core/hcd.c216
-rw-r--r--drivers/usb/core/hcd.h92
-rw-r--r--drivers/usb/core/hub.c88
-rw-r--r--drivers/usb/core/hub.h18
-rw-r--r--drivers/usb/core/inode.c42
-rw-r--r--drivers/usb/core/message.c430
-rw-r--r--drivers/usb/core/notify.c2
-rw-r--r--drivers/usb/core/otg_whitelist.h6
-rw-r--r--drivers/usb/core/sysfs.c69
-rw-r--r--drivers/usb/core/urb.c37
-rw-r--r--drivers/usb/core/usb.c117
-rw-r--r--drivers/usb/core/usb.h21
-rw-r--r--drivers/usb/gadget/Kconfig33
-rw-r--r--drivers/usb/gadget/Makefile3
-rw-r--r--drivers/usb/gadget/amd5536udc.c3
-rw-r--r--drivers/usb/gadget/at91_udc.c87
-rw-r--r--drivers/usb/gadget/at91_udc.h17
-rw-r--r--drivers/usb/gadget/atmel_usba_udc.c11
-rw-r--r--drivers/usb/gadget/atmel_usba_udc.h7
-rw-r--r--drivers/usb/gadget/dummy_hcd.c38
-rw-r--r--drivers/usb/gadget/ether.c6
-rw-r--r--drivers/usb/gadget/file_storage.c14
-rw-r--r--drivers/usb/gadget/fsl_usb2_udc.c4
-rw-r--r--drivers/usb/gadget/fsl_usb2_udc.h6
-rw-r--r--drivers/usb/gadget/gmidi.c6
-rw-r--r--drivers/usb/gadget/goku_udc.c1
-rw-r--r--drivers/usb/gadget/inode.c2
-rw-r--r--drivers/usb/gadget/lh7a40x_udc.c1
-rw-r--r--drivers/usb/gadget/m66592-udc.c104
-rw-r--r--drivers/usb/gadget/m66592-udc.h54
-rw-r--r--drivers/usb/gadget/net2280.c2
-rw-r--r--drivers/usb/gadget/omap_udc.c73
-rw-r--r--drivers/usb/gadget/omap_udc.h13
-rw-r--r--drivers/usb/gadget/printer.c1592
-rw-r--r--drivers/usb/gadget/pxa2xx_udc.c141
-rw-r--r--drivers/usb/gadget/pxa2xx_udc.h25
-rw-r--r--drivers/usb/gadget/rndis.c20
-rw-r--r--drivers/usb/gadget/s3c2410_udc.c4
-rw-r--r--drivers/usb/gadget/serial.c153
-rw-r--r--drivers/usb/gadget/zero.c4
-rw-r--r--drivers/usb/host/Kconfig22
-rw-r--r--drivers/usb/host/ehci-au1xxx.c1
-rw-r--r--drivers/usb/host/ehci-dbg.c231
-rw-r--r--drivers/usb/host/ehci-fsl.c3
-rw-r--r--drivers/usb/host/ehci-hcd.c159
-rw-r--r--drivers/usb/host/ehci-hub.c98
-rw-r--r--drivers/usb/host/ehci-ixp4xx.c152
-rw-r--r--drivers/usb/host/ehci-orion.c272
-rw-r--r--drivers/usb/host/ehci-pci.c3
-rw-r--r--drivers/usb/host/ehci-ppc-of.c238
-rw-r--r--drivers/usb/host/ehci-ppc-soc.c1
-rw-r--r--drivers/usb/host/ehci-ps3.c1
-rw-r--r--drivers/usb/host/ehci-q.c25
-rw-r--r--drivers/usb/host/ehci-sched.c152
-rw-r--r--drivers/usb/host/ehci.h40
-rw-r--r--drivers/usb/host/isp116x-hcd.c1
-rw-r--r--drivers/usb/host/ohci-at91.c31
-rw-r--r--drivers/usb/host/ohci-dbg.c213
-rw-r--r--drivers/usb/host/ohci-hcd.c34
-rw-r--r--drivers/usb/host/ohci-sh.c143
-rw-r--r--drivers/usb/host/ohci-sm501.c264
-rw-r--r--drivers/usb/host/ohci.h7
-rw-r--r--drivers/usb/host/r8a66597.h2
-rw-r--r--drivers/usb/image/mdc800.c2
-rw-r--r--drivers/usb/misc/cypress_cy7c63.c7
-rw-r--r--drivers/usb/misc/iowarrior.c2
-rw-r--r--drivers/usb/misc/legousbtower.c30
-rw-r--r--drivers/usb/misc/sisusbvga/sisusb.c29
-rw-r--r--drivers/usb/misc/sisusbvga/sisusb.h3
-rw-r--r--drivers/usb/misc/usbtest.c20
-rw-r--r--drivers/usb/mon/mon_bin.c22
-rw-r--r--drivers/usb/serial/Kconfig37
-rw-r--r--drivers/usb/serial/Makefile1
-rw-r--r--drivers/usb/serial/airprime.c5
-rw-r--r--drivers/usb/serial/ark3116.c4
-rw-r--r--drivers/usb/serial/belkin_sa.c37
-rw-r--r--drivers/usb/serial/console.c90
-rw-r--r--drivers/usb/serial/cp2101.c11
-rw-r--r--drivers/usb/serial/cyberjack.c1
-rw-r--r--drivers/usb/serial/cypress_m8.c25
-rw-r--r--drivers/usb/serial/digi_acceleport.c13
-rw-r--r--drivers/usb/serial/ezusb.c4
-rw-r--r--drivers/usb/serial/ftdi_sio.c293
-rw-r--r--drivers/usb/serial/ftdi_sio.h15
-rw-r--r--drivers/usb/serial/garmin_gps.c17
-rw-r--r--drivers/usb/serial/generic.c8
-rw-r--r--drivers/usb/serial/io_edgeport.c8
-rw-r--r--drivers/usb/serial/io_ti.c47
-rw-r--r--drivers/usb/serial/iuu_phoenix.c1217
-rw-r--r--drivers/usb/serial/iuu_phoenix.h122
-rw-r--r--drivers/usb/serial/keyspan.c2
-rw-r--r--drivers/usb/serial/keyspan_pda.c38
-rw-r--r--drivers/usb/serial/kl5kusb105.c26
-rw-r--r--drivers/usb/serial/kobil_sct.c1
-rw-r--r--drivers/usb/serial/mct_u232.c43
-rw-r--r--drivers/usb/serial/mct_u232.h2
-rw-r--r--drivers/usb/serial/mos7720.c61
-rw-r--r--drivers/usb/serial/mos7840.c8
-rw-r--r--drivers/usb/serial/option.c6
-rw-r--r--drivers/usb/serial/oti6858.c131
-rw-r--r--drivers/usb/serial/pl2303.c112
-rw-r--r--drivers/usb/serial/pl2303.h13
-rw-r--r--drivers/usb/serial/sierra.c227
-rw-r--r--drivers/usb/serial/ti_usb_3410_5052.c75
-rw-r--r--drivers/usb/serial/usb-serial.c42
-rw-r--r--drivers/usb/serial/visor.c22
-rw-r--r--drivers/usb/serial/whiteheat.c10
-rw-r--r--drivers/usb/storage/initializers.c3
-rw-r--r--drivers/usb/storage/isd200.c29
-rw-r--r--drivers/usb/storage/unusual_devs.h8
-rw-r--r--drivers/video/sis/sis.h8
-rw-r--r--drivers/video/sis/sis_main.c48
126 files changed, 7181 insertions, 2353 deletions
diff --git a/drivers/block/ub.c b/drivers/block/ub.c
index c6179d6ac6e4..a70c1c29a7aa 100644
--- a/drivers/block/ub.c
+++ b/drivers/block/ub.c
@@ -922,11 +922,6 @@ static int ub_scsi_cmd_start(struct ub_dev *sc, struct ub_scsi_cmd *cmd)
922 usb_fill_bulk_urb(&sc->work_urb, sc->dev, sc->send_bulk_pipe, 922 usb_fill_bulk_urb(&sc->work_urb, sc->dev, sc->send_bulk_pipe,
923 bcb, US_BULK_CB_WRAP_LEN, ub_urb_complete, sc); 923 bcb, US_BULK_CB_WRAP_LEN, ub_urb_complete, sc);
924 924
925 /* Fill what we shouldn't be filling, because usb-storage did so. */
926 sc->work_urb.actual_length = 0;
927 sc->work_urb.error_count = 0;
928 sc->work_urb.status = 0;
929
930 if ((rc = usb_submit_urb(&sc->work_urb, GFP_ATOMIC)) != 0) { 925 if ((rc = usb_submit_urb(&sc->work_urb, GFP_ATOMIC)) != 0) {
931 /* XXX Clear stalls */ 926 /* XXX Clear stalls */
932 ub_complete(&sc->work_done); 927 ub_complete(&sc->work_done);
@@ -1313,9 +1308,6 @@ static void ub_data_start(struct ub_dev *sc, struct ub_scsi_cmd *cmd)
1313 sc->last_pipe = pipe; 1308 sc->last_pipe = pipe;
1314 usb_fill_bulk_urb(&sc->work_urb, sc->dev, pipe, sg_virt(sg), 1309 usb_fill_bulk_urb(&sc->work_urb, sc->dev, pipe, sg_virt(sg),
1315 sg->length, ub_urb_complete, sc); 1310 sg->length, ub_urb_complete, sc);
1316 sc->work_urb.actual_length = 0;
1317 sc->work_urb.error_count = 0;
1318 sc->work_urb.status = 0;
1319 1311
1320 if ((rc = usb_submit_urb(&sc->work_urb, GFP_ATOMIC)) != 0) { 1312 if ((rc = usb_submit_urb(&sc->work_urb, GFP_ATOMIC)) != 0) {
1321 /* XXX Clear stalls */ 1313 /* XXX Clear stalls */
@@ -1356,9 +1348,6 @@ static int __ub_state_stat(struct ub_dev *sc, struct ub_scsi_cmd *cmd)
1356 sc->last_pipe = sc->recv_bulk_pipe; 1348 sc->last_pipe = sc->recv_bulk_pipe;
1357 usb_fill_bulk_urb(&sc->work_urb, sc->dev, sc->recv_bulk_pipe, 1349 usb_fill_bulk_urb(&sc->work_urb, sc->dev, sc->recv_bulk_pipe,
1358 &sc->work_bcs, US_BULK_CS_WRAP_LEN, ub_urb_complete, sc); 1350 &sc->work_bcs, US_BULK_CS_WRAP_LEN, ub_urb_complete, sc);
1359 sc->work_urb.actual_length = 0;
1360 sc->work_urb.error_count = 0;
1361 sc->work_urb.status = 0;
1362 1351
1363 if ((rc = usb_submit_urb(&sc->work_urb, GFP_ATOMIC)) != 0) { 1352 if ((rc = usb_submit_urb(&sc->work_urb, GFP_ATOMIC)) != 0) {
1364 /* XXX Clear stalls */ 1353 /* XXX Clear stalls */
@@ -1473,9 +1462,6 @@ static int ub_submit_clear_stall(struct ub_dev *sc, struct ub_scsi_cmd *cmd,
1473 1462
1474 usb_fill_control_urb(&sc->work_urb, sc->dev, sc->send_ctrl_pipe, 1463 usb_fill_control_urb(&sc->work_urb, sc->dev, sc->send_ctrl_pipe,
1475 (unsigned char*) cr, NULL, 0, ub_urb_complete, sc); 1464 (unsigned char*) cr, NULL, 0, ub_urb_complete, sc);
1476 sc->work_urb.actual_length = 0;
1477 sc->work_urb.error_count = 0;
1478 sc->work_urb.status = 0;
1479 1465
1480 if ((rc = usb_submit_urb(&sc->work_urb, GFP_ATOMIC)) != 0) { 1466 if ((rc = usb_submit_urb(&sc->work_urb, GFP_ATOMIC)) != 0) {
1481 ub_complete(&sc->work_done); 1467 ub_complete(&sc->work_done);
@@ -1953,9 +1939,6 @@ static int ub_sync_reset(struct ub_dev *sc)
1953 1939
1954 usb_fill_control_urb(&sc->work_urb, sc->dev, sc->send_ctrl_pipe, 1940 usb_fill_control_urb(&sc->work_urb, sc->dev, sc->send_ctrl_pipe,
1955 (unsigned char*) cr, NULL, 0, ub_probe_urb_complete, &compl); 1941 (unsigned char*) cr, NULL, 0, ub_probe_urb_complete, &compl);
1956 sc->work_urb.actual_length = 0;
1957 sc->work_urb.error_count = 0;
1958 sc->work_urb.status = 0;
1959 1942
1960 if ((rc = usb_submit_urb(&sc->work_urb, GFP_KERNEL)) != 0) { 1943 if ((rc = usb_submit_urb(&sc->work_urb, GFP_KERNEL)) != 0) {
1961 printk(KERN_WARNING 1944 printk(KERN_WARNING
@@ -2007,9 +1990,6 @@ static int ub_sync_getmaxlun(struct ub_dev *sc)
2007 1990
2008 usb_fill_control_urb(&sc->work_urb, sc->dev, sc->recv_ctrl_pipe, 1991 usb_fill_control_urb(&sc->work_urb, sc->dev, sc->recv_ctrl_pipe,
2009 (unsigned char*) cr, p, 1, ub_probe_urb_complete, &compl); 1992 (unsigned char*) cr, p, 1, ub_probe_urb_complete, &compl);
2010 sc->work_urb.actual_length = 0;
2011 sc->work_urb.error_count = 0;
2012 sc->work_urb.status = 0;
2013 1993
2014 if ((rc = usb_submit_urb(&sc->work_urb, GFP_KERNEL)) != 0) 1994 if ((rc = usb_submit_urb(&sc->work_urb, GFP_KERNEL)) != 0)
2015 goto err_submit; 1995 goto err_submit;
@@ -2077,9 +2057,6 @@ static int ub_probe_clear_stall(struct ub_dev *sc, int stalled_pipe)
2077 2057
2078 usb_fill_control_urb(&sc->work_urb, sc->dev, sc->send_ctrl_pipe, 2058 usb_fill_control_urb(&sc->work_urb, sc->dev, sc->send_ctrl_pipe,
2079 (unsigned char*) cr, NULL, 0, ub_probe_urb_complete, &compl); 2059 (unsigned char*) cr, NULL, 0, ub_probe_urb_complete, &compl);
2080 sc->work_urb.actual_length = 0;
2081 sc->work_urb.error_count = 0;
2082 sc->work_urb.status = 0;
2083 2060
2084 if ((rc = usb_submit_urb(&sc->work_urb, GFP_KERNEL)) != 0) { 2061 if ((rc = usb_submit_urb(&sc->work_urb, GFP_KERNEL)) != 0) {
2085 printk(KERN_WARNING 2062 printk(KERN_WARNING
diff --git a/drivers/usb/Kconfig b/drivers/usb/Kconfig
index 7a6499008b89..755823cdf62a 100644
--- a/drivers/usb/Kconfig
+++ b/drivers/usb/Kconfig
@@ -42,6 +42,10 @@ config USB_ARCH_HAS_OHCI
42 default y if PPC_MPC52xx 42 default y if PPC_MPC52xx
43 # MIPS: 43 # MIPS:
44 default y if SOC_AU1X00 44 default y if SOC_AU1X00
45 # SH:
46 default y if CPU_SUBTYPE_SH7720
47 default y if CPU_SUBTYPE_SH7721
48 default y if CPU_SUBTYPE_SH7763
45 # more: 49 # more:
46 default PCI 50 default PCI
47 51
@@ -50,6 +54,7 @@ config USB_ARCH_HAS_EHCI
50 boolean 54 boolean
51 default y if PPC_83xx 55 default y if PPC_83xx
52 default y if SOC_AU1200 56 default y if SOC_AU1200
57 default y if ARCH_IXP4XX
53 default PCI 58 default PCI
54 59
55# ARM SA1111 chips have a non-PCI based "OHCI-compatible" USB host interface. 60# ARM SA1111 chips have a non-PCI based "OHCI-compatible" USB host interface.
diff --git a/drivers/usb/atm/Kconfig b/drivers/usb/atm/Kconfig
index b450cbaa3a0b..86e64035edb0 100644
--- a/drivers/usb/atm/Kconfig
+++ b/drivers/usb/atm/Kconfig
@@ -2,10 +2,7 @@
2# USB/ATM DSL configuration 2# USB/ATM DSL configuration
3# 3#
4 4
5menu "USB DSL modem support" 5menuconfig USB_ATM
6 depends on USB
7
8config USB_ATM
9 tristate "USB DSL modem support" 6 tristate "USB DSL modem support"
10 depends on USB && ATM 7 depends on USB && ATM
11 select CRC32 8 select CRC32
@@ -18,6 +15,8 @@ config USB_ATM
18 To compile this driver as a module, choose M here: the 15 To compile this driver as a module, choose M here: the
19 module will be called usbatm. 16 module will be called usbatm.
20 17
18if USB_ATM
19
21config USB_SPEEDTOUCH 20config USB_SPEEDTOUCH
22 tristate "Speedtouch USB support" 21 tristate "Speedtouch USB support"
23 depends on USB_ATM 22 depends on USB_ATM
@@ -70,4 +69,4 @@ config USB_XUSBATM
70 To compile this driver as a module, choose M here: the 69 To compile this driver as a module, choose M here: the
71 module will be called xusbatm. 70 module will be called xusbatm.
72 71
73endmenu 72endif # USB_ATM
diff --git a/drivers/usb/atm/ueagle-atm.c b/drivers/usb/atm/ueagle-atm.c
index 389c5b164eb2..c5ec1a55eee3 100644
--- a/drivers/usb/atm/ueagle-atm.c
+++ b/drivers/usb/atm/ueagle-atm.c
@@ -999,7 +999,7 @@ static void __uea_load_page_e4(struct uea_softc *sc, u8 pageno, int boot)
999 bi.dwAddress = swab32(blockidx->PageAddress); 999 bi.dwAddress = swab32(blockidx->PageAddress);
1000 1000
1001 uea_dbg(INS_TO_USBDEV(sc), 1001 uea_dbg(INS_TO_USBDEV(sc),
1002 "sending block %u for DSP page %u size %u adress %x\n", 1002 "sending block %u for DSP page %u size %u address %x\n",
1003 blockno, pageno, blocksize, le32_to_cpu(blockidx->PageAddress)); 1003 blockno, pageno, blocksize, le32_to_cpu(blockidx->PageAddress));
1004 1004
1005 /* send block info through the IDMA pipe */ 1005 /* send block info through the IDMA pipe */
@@ -1990,7 +1990,7 @@ static void uea_dispatch_cmv_e1(struct uea_softc *sc, struct intr_pkt *intr)
1990 return; 1990 return;
1991 1991
1992bad2: 1992bad2:
1993 uea_err(INS_TO_USBDEV(sc), "unexpected cmv received," 1993 uea_err(INS_TO_USBDEV(sc), "unexpected cmv received, "
1994 "Function : %d, Subfunction : %d\n", 1994 "Function : %d, Subfunction : %d\n",
1995 E1_FUNCTION_TYPE(cmv->bFunction), 1995 E1_FUNCTION_TYPE(cmv->bFunction),
1996 E1_FUNCTION_SUBTYPE(cmv->bFunction)); 1996 E1_FUNCTION_SUBTYPE(cmv->bFunction));
@@ -2038,7 +2038,7 @@ static void uea_dispatch_cmv_e4(struct uea_softc *sc, struct intr_pkt *intr)
2038 return; 2038 return;
2039 2039
2040bad2: 2040bad2:
2041 uea_err(INS_TO_USBDEV(sc), "unexpected cmv received," 2041 uea_err(INS_TO_USBDEV(sc), "unexpected cmv received, "
2042 "Function : %d, Subfunction : %d\n", 2042 "Function : %d, Subfunction : %d\n",
2043 E4_FUNCTION_TYPE(cmv->wFunction), 2043 E4_FUNCTION_TYPE(cmv->wFunction),
2044 E4_FUNCTION_SUBTYPE(cmv->wFunction)); 2044 E4_FUNCTION_SUBTYPE(cmv->wFunction));
diff --git a/drivers/usb/class/cdc-acm.c b/drivers/usb/class/cdc-acm.c
index 912d97aaf9bf..bcc42136c93f 100644
--- a/drivers/usb/class/cdc-acm.c
+++ b/drivers/usb/class/cdc-acm.c
@@ -496,10 +496,19 @@ static int acm_tty_open(struct tty_struct *tty, struct file *filp)
496 otherwise it is scheduled, and with high data rates data can get lost. */ 496 otherwise it is scheduled, and with high data rates data can get lost. */
497 tty->low_latency = 1; 497 tty->low_latency = 1;
498 498
499 if (usb_autopm_get_interface(acm->control)) {
500 mutex_unlock(&open_mutex);
501 return -EIO;
502 }
503
504 mutex_lock(&acm->mutex);
505 mutex_unlock(&open_mutex);
499 if (acm->used++) { 506 if (acm->used++) {
507 usb_autopm_put_interface(acm->control);
500 goto done; 508 goto done;
501 } 509 }
502 510
511
503 acm->ctrlurb->dev = acm->dev; 512 acm->ctrlurb->dev = acm->dev;
504 if (usb_submit_urb(acm->ctrlurb, GFP_KERNEL)) { 513 if (usb_submit_urb(acm->ctrlurb, GFP_KERNEL)) {
505 dbg("usb_submit_urb(ctrl irq) failed"); 514 dbg("usb_submit_urb(ctrl irq) failed");
@@ -526,14 +535,15 @@ static int acm_tty_open(struct tty_struct *tty, struct file *filp)
526 535
527done: 536done:
528err_out: 537err_out:
529 mutex_unlock(&open_mutex); 538 mutex_unlock(&acm->mutex);
530 return rv; 539 return rv;
531 540
532full_bailout: 541full_bailout:
533 usb_kill_urb(acm->ctrlurb); 542 usb_kill_urb(acm->ctrlurb);
534bail_out: 543bail_out:
544 usb_autopm_put_interface(acm->control);
535 acm->used--; 545 acm->used--;
536 mutex_unlock(&open_mutex); 546 mutex_unlock(&acm->mutex);
537 return -EIO; 547 return -EIO;
538} 548}
539 549
@@ -570,6 +580,7 @@ static void acm_tty_close(struct tty_struct *tty, struct file *filp)
570 usb_kill_urb(acm->writeurb); 580 usb_kill_urb(acm->writeurb);
571 for (i = 0; i < nr; i++) 581 for (i = 0; i < nr; i++)
572 usb_kill_urb(acm->ru[i].urb); 582 usb_kill_urb(acm->ru[i].urb);
583 usb_autopm_put_interface(acm->control);
573 } else 584 } else
574 acm_tty_unregister(acm); 585 acm_tty_unregister(acm);
575 } 586 }
@@ -904,7 +915,7 @@ next_desc:
904 } 915 }
905 916
906 if (data_interface_num != call_interface_num) 917 if (data_interface_num != call_interface_num)
907 dev_dbg(&intf->dev,"Seperate call control interface. That is not fully supported.\n"); 918 dev_dbg(&intf->dev,"Separate call control interface. That is not fully supported.\n");
908 919
909skip_normal_probe: 920skip_normal_probe:
910 921
@@ -980,6 +991,7 @@ skip_normal_probe:
980 spin_lock_init(&acm->throttle_lock); 991 spin_lock_init(&acm->throttle_lock);
981 spin_lock_init(&acm->write_lock); 992 spin_lock_init(&acm->write_lock);
982 spin_lock_init(&acm->read_lock); 993 spin_lock_init(&acm->read_lock);
994 mutex_init(&acm->mutex);
983 acm->write_ready = 1; 995 acm->write_ready = 1;
984 acm->rx_endpoint = usb_rcvbulkpipe(usb_dev, epread->bEndpointAddress); 996 acm->rx_endpoint = usb_rcvbulkpipe(usb_dev, epread->bEndpointAddress);
985 997
@@ -1096,6 +1108,25 @@ alloc_fail:
1096 return -ENOMEM; 1108 return -ENOMEM;
1097} 1109}
1098 1110
1111static void stop_data_traffic(struct acm *acm)
1112{
1113 int i;
1114
1115 tasklet_disable(&acm->urb_task);
1116
1117 usb_kill_urb(acm->ctrlurb);
1118 usb_kill_urb(acm->writeurb);
1119 for (i = 0; i < acm->rx_buflimit; i++)
1120 usb_kill_urb(acm->ru[i].urb);
1121
1122 INIT_LIST_HEAD(&acm->filled_read_bufs);
1123 INIT_LIST_HEAD(&acm->spare_read_bufs);
1124
1125 tasklet_enable(&acm->urb_task);
1126
1127 cancel_work_sync(&acm->work);
1128}
1129
1099static void acm_disconnect(struct usb_interface *intf) 1130static void acm_disconnect(struct usb_interface *intf)
1100{ 1131{
1101 struct acm *acm = usb_get_intfdata(intf); 1132 struct acm *acm = usb_get_intfdata(intf);
@@ -1123,19 +1154,7 @@ static void acm_disconnect(struct usb_interface *intf)
1123 usb_set_intfdata(acm->control, NULL); 1154 usb_set_intfdata(acm->control, NULL);
1124 usb_set_intfdata(acm->data, NULL); 1155 usb_set_intfdata(acm->data, NULL);
1125 1156
1126 tasklet_disable(&acm->urb_task); 1157 stop_data_traffic(acm);
1127
1128 usb_kill_urb(acm->ctrlurb);
1129 usb_kill_urb(acm->writeurb);
1130 for (i = 0; i < acm->rx_buflimit; i++)
1131 usb_kill_urb(acm->ru[i].urb);
1132
1133 INIT_LIST_HEAD(&acm->filled_read_bufs);
1134 INIT_LIST_HEAD(&acm->spare_read_bufs);
1135
1136 tasklet_enable(&acm->urb_task);
1137
1138 flush_scheduled_work(); /* wait for acm_softint */
1139 1158
1140 acm_write_buffers_free(acm); 1159 acm_write_buffers_free(acm);
1141 usb_buffer_free(usb_dev, acm->ctrlsize, acm->ctrl_buffer, acm->ctrl_dma); 1160 usb_buffer_free(usb_dev, acm->ctrlsize, acm->ctrl_buffer, acm->ctrl_dma);
@@ -1156,6 +1175,46 @@ static void acm_disconnect(struct usb_interface *intf)
1156 tty_hangup(acm->tty); 1175 tty_hangup(acm->tty);
1157} 1176}
1158 1177
1178static int acm_suspend(struct usb_interface *intf, pm_message_t message)
1179{
1180 struct acm *acm = usb_get_intfdata(intf);
1181
1182 if (acm->susp_count++)
1183 return 0;
1184 /*
1185 we treat opened interfaces differently,
1186 we must guard against open
1187 */
1188 mutex_lock(&acm->mutex);
1189
1190 if (acm->used)
1191 stop_data_traffic(acm);
1192
1193 mutex_unlock(&acm->mutex);
1194 return 0;
1195}
1196
1197static int acm_resume(struct usb_interface *intf)
1198{
1199 struct acm *acm = usb_get_intfdata(intf);
1200 int rv = 0;
1201
1202 if (--acm->susp_count)
1203 return 0;
1204
1205 mutex_lock(&acm->mutex);
1206 if (acm->used) {
1207 rv = usb_submit_urb(acm->ctrlurb, GFP_NOIO);
1208 if (rv < 0)
1209 goto err_out;
1210
1211 tasklet_schedule(&acm->urb_task);
1212 }
1213
1214err_out:
1215 mutex_unlock(&acm->mutex);
1216 return rv;
1217}
1159/* 1218/*
1160 * USB driver structure. 1219 * USB driver structure.
1161 */ 1220 */
@@ -1208,7 +1267,10 @@ static struct usb_driver acm_driver = {
1208 .name = "cdc_acm", 1267 .name = "cdc_acm",
1209 .probe = acm_probe, 1268 .probe = acm_probe,
1210 .disconnect = acm_disconnect, 1269 .disconnect = acm_disconnect,
1270 .suspend = acm_suspend,
1271 .resume = acm_resume,
1211 .id_table = acm_ids, 1272 .id_table = acm_ids,
1273 .supports_autosuspend = 1,
1212}; 1274};
1213 1275
1214/* 1276/*
diff --git a/drivers/usb/class/cdc-acm.h b/drivers/usb/class/cdc-acm.h
index 09f7765dbf8d..8df6a57dcf9e 100644
--- a/drivers/usb/class/cdc-acm.h
+++ b/drivers/usb/class/cdc-acm.h
@@ -107,6 +107,7 @@ struct acm {
107 int write_used; /* number of non-empty write buffers */ 107 int write_used; /* number of non-empty write buffers */
108 int write_ready; /* write urb is not running */ 108 int write_ready; /* write urb is not running */
109 spinlock_t write_lock; 109 spinlock_t write_lock;
110 struct mutex mutex;
110 struct usb_cdc_line_coding line; /* bits, stop, parity */ 111 struct usb_cdc_line_coding line; /* bits, stop, parity */
111 struct work_struct work; /* work queue entry for line discipline waking up */ 112 struct work_struct work; /* work queue entry for line discipline waking up */
112 struct tasklet_struct urb_task; /* rx processing */ 113 struct tasklet_struct urb_task; /* rx processing */
@@ -120,6 +121,7 @@ struct acm {
120 unsigned char throttle; /* throttled by tty layer */ 121 unsigned char throttle; /* throttled by tty layer */
121 unsigned char clocal; /* termios CLOCAL */ 122 unsigned char clocal; /* termios CLOCAL */
122 unsigned int ctrl_caps; /* control capabilities from the class specific header */ 123 unsigned int ctrl_caps; /* control capabilities from the class specific header */
124 unsigned int susp_count; /* number of suspended interfaces */
123}; 125};
124 126
125#define CDC_DATA_INTERFACE_TYPE 0x0a 127#define CDC_DATA_INTERFACE_TYPE 0x0a
diff --git a/drivers/usb/core/Kconfig b/drivers/usb/core/Kconfig
index 97b09f282705..5c33cdb9cac7 100644
--- a/drivers/usb/core/Kconfig
+++ b/drivers/usb/core/Kconfig
@@ -9,6 +9,21 @@ config USB_DEBUG
9 of debug messages to the system log. Select this if you are having a 9 of debug messages to the system log. Select this if you are having a
10 problem with USB support and want to see more of what is going on. 10 problem with USB support and want to see more of what is going on.
11 11
12config USB_ANNOUNCE_NEW_DEVICES
13 bool "USB announce new devices"
14 depends on USB
15 default N
16 help
17 Say Y here if you want the USB core to always announce the
18 idVendor, idProduct, Manufacturer, Product, and SerialNumber
19 strings for every new USB device to the syslog. This option is
20 usually used by distro vendors to help with debugging and to
21 let users know what specific device was added to the machine
22 in what location.
23
24 If you do not want this kind of information sent to the system
25 log, or have any doubts about this, say N here.
26
12comment "Miscellaneous USB options" 27comment "Miscellaneous USB options"
13 depends on USB 28 depends on USB
14 29
diff --git a/drivers/usb/core/buffer.c b/drivers/usb/core/buffer.c
index 28d4972f7ad5..cadb2dc1d28a 100644
--- a/drivers/usb/core/buffer.c
+++ b/drivers/usb/core/buffer.c
@@ -53,11 +53,13 @@ int hcd_buffer_create(struct usb_hcd *hcd)
53 char name[16]; 53 char name[16];
54 int i, size; 54 int i, size;
55 55
56 if (!hcd->self.controller->dma_mask) 56 if (!hcd->self.controller->dma_mask &&
57 !(hcd->driver->flags & HCD_LOCAL_MEM))
57 return 0; 58 return 0;
58 59
59 for (i = 0; i < HCD_BUFFER_POOLS; i++) { 60 for (i = 0; i < HCD_BUFFER_POOLS; i++) {
60 if (!(size = pool_max [i])) 61 size = pool_max[i];
62 if (!size)
61 continue; 63 continue;
62 snprintf(name, sizeof name, "buffer-%d", size); 64 snprintf(name, sizeof name, "buffer-%d", size);
63 hcd->pool[i] = dma_pool_create(name, hcd->self.controller, 65 hcd->pool[i] = dma_pool_create(name, hcd->self.controller,
@@ -80,10 +82,10 @@ int hcd_buffer_create(struct usb_hcd *hcd)
80 */ 82 */
81void hcd_buffer_destroy(struct usb_hcd *hcd) 83void hcd_buffer_destroy(struct usb_hcd *hcd)
82{ 84{
83 int i; 85 int i;
84 86
85 for (i = 0; i < HCD_BUFFER_POOLS; i++) { 87 for (i = 0; i < HCD_BUFFER_POOLS; i++) {
86 struct dma_pool *pool = hcd->pool[i]; 88 struct dma_pool *pool = hcd->pool[i];
87 if (pool) { 89 if (pool) {
88 dma_pool_destroy(pool); 90 dma_pool_destroy(pool);
89 hcd->pool[i] = NULL; 91 hcd->pool[i] = NULL;
@@ -107,7 +109,8 @@ void *hcd_buffer_alloc(
107 int i; 109 int i;
108 110
109 /* some USB hosts just use PIO */ 111 /* some USB hosts just use PIO */
110 if (!bus->controller->dma_mask) { 112 if (!bus->controller->dma_mask &&
113 !(hcd->driver->flags & HCD_LOCAL_MEM)) {
111 *dma = ~(dma_addr_t) 0; 114 *dma = ~(dma_addr_t) 0;
112 return kmalloc(size, mem_flags); 115 return kmalloc(size, mem_flags);
113 } 116 }
@@ -132,7 +135,8 @@ void hcd_buffer_free(
132 if (!addr) 135 if (!addr)
133 return; 136 return;
134 137
135 if (!bus->controller->dma_mask) { 138 if (!bus->controller->dma_mask &&
139 !(hcd->driver->flags & HCD_LOCAL_MEM)) {
136 kfree(addr); 140 kfree(addr);
137 return; 141 return;
138 } 142 }
diff --git a/drivers/usb/core/config.c b/drivers/usb/core/config.c
index 1a8edcee7f30..a92122a216bc 100644
--- a/drivers/usb/core/config.c
+++ b/drivers/usb/core/config.c
@@ -238,7 +238,7 @@ static int usb_parse_interface(struct device *ddev, int cfgno,
238 238
239 /* Allocate space for the right(?) number of endpoints */ 239 /* Allocate space for the right(?) number of endpoints */
240 num_ep = num_ep_orig = alt->desc.bNumEndpoints; 240 num_ep = num_ep_orig = alt->desc.bNumEndpoints;
241 alt->desc.bNumEndpoints = 0; // Use as a counter 241 alt->desc.bNumEndpoints = 0; /* Use as a counter */
242 if (num_ep > USB_MAXENDPOINTS) { 242 if (num_ep > USB_MAXENDPOINTS) {
243 dev_warn(ddev, "too many endpoints for config %d interface %d " 243 dev_warn(ddev, "too many endpoints for config %d interface %d "
244 "altsetting %d: %d, using maximum allowed: %d\n", 244 "altsetting %d: %d, using maximum allowed: %d\n",
@@ -246,7 +246,8 @@ static int usb_parse_interface(struct device *ddev, int cfgno,
246 num_ep = USB_MAXENDPOINTS; 246 num_ep = USB_MAXENDPOINTS;
247 } 247 }
248 248
249 if (num_ep > 0) { /* Can't allocate 0 bytes */ 249 if (num_ep > 0) {
250 /* Can't allocate 0 bytes */
250 len = sizeof(struct usb_host_endpoint) * num_ep; 251 len = sizeof(struct usb_host_endpoint) * num_ep;
251 alt->endpoint = kzalloc(len, GFP_KERNEL); 252 alt->endpoint = kzalloc(len, GFP_KERNEL);
252 if (!alt->endpoint) 253 if (!alt->endpoint)
@@ -475,8 +476,9 @@ static int usb_parse_configuration(struct device *ddev, int cfgidx,
475 return 0; 476 return 0;
476} 477}
477 478
478// hub-only!! ... and only exported for reset/reinit path. 479/* hub-only!! ... and only exported for reset/reinit path.
479// otherwise used internally on disconnect/destroy path 480 * otherwise used internally on disconnect/destroy path
481 */
480void usb_destroy_configuration(struct usb_device *dev) 482void usb_destroy_configuration(struct usb_device *dev)
481{ 483{
482 int c, i; 484 int c, i;
@@ -498,7 +500,7 @@ void usb_destroy_configuration(struct usb_device *dev)
498 kfree(cf->string); 500 kfree(cf->string);
499 for (i = 0; i < cf->desc.bNumInterfaces; i++) { 501 for (i = 0; i < cf->desc.bNumInterfaces; i++) {
500 if (cf->intf_cache[i]) 502 if (cf->intf_cache[i])
501 kref_put(&cf->intf_cache[i]->ref, 503 kref_put(&cf->intf_cache[i]->ref,
502 usb_release_interface_cache); 504 usb_release_interface_cache);
503 } 505 }
504 } 506 }
@@ -525,7 +527,7 @@ int usb_get_configuration(struct usb_device *dev)
525 unsigned int cfgno, length; 527 unsigned int cfgno, length;
526 unsigned char *buffer; 528 unsigned char *buffer;
527 unsigned char *bigbuffer; 529 unsigned char *bigbuffer;
528 struct usb_config_descriptor *desc; 530 struct usb_config_descriptor *desc;
529 531
530 cfgno = 0; 532 cfgno = 0;
531 if (dev->authorized == 0) /* Not really an error */ 533 if (dev->authorized == 0) /* Not really an error */
diff --git a/drivers/usb/core/devices.c b/drivers/usb/core/devices.c
index 87c794d60aa0..83d9dc379d96 100644
--- a/drivers/usb/core/devices.c
+++ b/drivers/usb/core/devices.c
@@ -89,7 +89,7 @@ static const char *format_string_serialnumber =
89static const char *format_bandwidth = 89static const char *format_bandwidth =
90/* B: Alloc=ddd/ddd us (xx%), #Int=ddd, #Iso=ddd */ 90/* B: Alloc=ddd/ddd us (xx%), #Int=ddd, #Iso=ddd */
91 "B: Alloc=%3d/%3d us (%2d%%), #Int=%3d, #Iso=%3d\n"; 91 "B: Alloc=%3d/%3d us (%2d%%), #Int=%3d, #Iso=%3d\n";
92 92
93static const char *format_device1 = 93static const char *format_device1 =
94/* D: Ver=xx.xx Cls=xx(sssss) Sub=xx Prot=xx MxPS=dd #Cfgs=dd */ 94/* D: Ver=xx.xx Cls=xx(sssss) Sub=xx Prot=xx MxPS=dd #Cfgs=dd */
95 "D: Ver=%2x.%02x Cls=%02x(%-5s) Sub=%02x Prot=%02x MxPS=%2d #Cfgs=%3d\n"; 95 "D: Ver=%2x.%02x Cls=%02x(%-5s) Sub=%02x Prot=%02x MxPS=%2d #Cfgs=%3d\n";
@@ -101,7 +101,7 @@ static const char *format_device2 =
101static const char *format_config = 101static const char *format_config =
102/* C: #Ifs=dd Cfg#=dd Atr=xx MPwr=dddmA */ 102/* C: #Ifs=dd Cfg#=dd Atr=xx MPwr=dddmA */
103 "C:%c #Ifs=%2d Cfg#=%2d Atr=%02x MxPwr=%3dmA\n"; 103 "C:%c #Ifs=%2d Cfg#=%2d Atr=%02x MxPwr=%3dmA\n";
104 104
105static const char *format_iad = 105static const char *format_iad =
106/* A: FirstIf#=dd IfCount=dd Cls=xx(sssss) Sub=xx Prot=xx */ 106/* A: FirstIf#=dd IfCount=dd Cls=xx(sssss) Sub=xx Prot=xx */
107 "A: FirstIf#=%2d IfCount=%2d Cls=%02x(%-5s) Sub=%02x Prot=%02x\n"; 107 "A: FirstIf#=%2d IfCount=%2d Cls=%02x(%-5s) Sub=%02x Prot=%02x\n";
@@ -122,7 +122,7 @@ static const char *format_endpt =
122 */ 122 */
123 123
124static DECLARE_WAIT_QUEUE_HEAD(deviceconndiscwq); 124static DECLARE_WAIT_QUEUE_HEAD(deviceconndiscwq);
125static unsigned int conndiscevcnt = 0; 125static unsigned int conndiscevcnt;
126 126
127/* this struct stores the poll state for <mountpoint>/devices pollers */ 127/* this struct stores the poll state for <mountpoint>/devices pollers */
128struct usb_device_status { 128struct usb_device_status {
@@ -172,12 +172,8 @@ static const char *class_decode(const int class)
172 return clas_info[ix].class_name; 172 return clas_info[ix].class_name;
173} 173}
174 174
175static char *usb_dump_endpoint_descriptor( 175static char *usb_dump_endpoint_descriptor(int speed, char *start, char *end,
176 int speed, 176 const struct usb_endpoint_descriptor *desc)
177 char *start,
178 char *end,
179 const struct usb_endpoint_descriptor *desc
180)
181{ 177{
182 char dir, unit, *type; 178 char dir, unit, *type;
183 unsigned interval, bandwidth = 1; 179 unsigned interval, bandwidth = 1;
@@ -235,22 +231,24 @@ static char *usb_dump_endpoint_descriptor(
235 231
236 start += sprintf(start, format_endpt, desc->bEndpointAddress, dir, 232 start += sprintf(start, format_endpt, desc->bEndpointAddress, dir,
237 desc->bmAttributes, type, 233 desc->bmAttributes, type,
238 (le16_to_cpu(desc->wMaxPacketSize) & 0x07ff) * bandwidth, 234 (le16_to_cpu(desc->wMaxPacketSize) & 0x07ff) *
235 bandwidth,
239 interval, unit); 236 interval, unit);
240 return start; 237 return start;
241} 238}
242 239
243static char *usb_dump_interface_descriptor(char *start, char *end, 240static char *usb_dump_interface_descriptor(char *start, char *end,
244 const struct usb_interface_cache *intfc, 241 const struct usb_interface_cache *intfc,
245 const struct usb_interface *iface, 242 const struct usb_interface *iface,
246 int setno) 243 int setno)
247{ 244{
248 const struct usb_interface_descriptor *desc = &intfc->altsetting[setno].desc; 245 const struct usb_interface_descriptor *desc;
249 const char *driver_name = ""; 246 const char *driver_name = "";
250 int active = 0; 247 int active = 0;
251 248
252 if (start > end) 249 if (start > end)
253 return start; 250 return start;
251 desc = &intfc->altsetting[setno].desc;
254 if (iface) { 252 if (iface) {
255 driver_name = (iface->dev.driver 253 driver_name = (iface->dev.driver
256 ? iface->dev.driver->name 254 ? iface->dev.driver->name
@@ -270,14 +268,10 @@ static char *usb_dump_interface_descriptor(char *start, char *end,
270 return start; 268 return start;
271} 269}
272 270
273static char *usb_dump_interface( 271static char *usb_dump_interface(int speed, char *start, char *end,
274 int speed, 272 const struct usb_interface_cache *intfc,
275 char *start, 273 const struct usb_interface *iface, int setno)
276 char *end, 274{
277 const struct usb_interface_cache *intfc,
278 const struct usb_interface *iface,
279 int setno
280) {
281 const struct usb_host_interface *desc = &intfc->altsetting[setno]; 275 const struct usb_host_interface *desc = &intfc->altsetting[setno];
282 int i; 276 int i;
283 277
@@ -292,7 +286,7 @@ static char *usb_dump_interface(
292} 286}
293 287
294static char *usb_dump_iad_descriptor(char *start, char *end, 288static char *usb_dump_iad_descriptor(char *start, char *end,
295 const struct usb_interface_assoc_descriptor *iad) 289 const struct usb_interface_assoc_descriptor *iad)
296{ 290{
297 if (start > end) 291 if (start > end)
298 return start; 292 return start;
@@ -311,13 +305,15 @@ static char *usb_dump_iad_descriptor(char *start, char *end,
311 * 1. marking active interface altsettings (code lists all, but should mark 305 * 1. marking active interface altsettings (code lists all, but should mark
312 * which ones are active, if any) 306 * which ones are active, if any)
313 */ 307 */
314 308static char *usb_dump_config_descriptor(char *start, char *end,
315static char *usb_dump_config_descriptor(char *start, char *end, const struct usb_config_descriptor *desc, int active) 309 const struct usb_config_descriptor *desc,
310 int active)
316{ 311{
317 if (start > end) 312 if (start > end)
318 return start; 313 return start;
319 start += sprintf(start, format_config, 314 start += sprintf(start, format_config,
320 active ? '*' : ' ', /* mark active/actual/current cfg. */ 315 /* mark active/actual/current cfg. */
316 active ? '*' : ' ',
321 desc->bNumInterfaces, 317 desc->bNumInterfaces,
322 desc->bConfigurationValue, 318 desc->bConfigurationValue,
323 desc->bmAttributes, 319 desc->bmAttributes,
@@ -325,13 +321,8 @@ static char *usb_dump_config_descriptor(char *start, char *end, const struct usb
325 return start; 321 return start;
326} 322}
327 323
328static char *usb_dump_config ( 324static char *usb_dump_config(int speed, char *start, char *end,
329 int speed, 325 const struct usb_host_config *config, int active)
330 char *start,
331 char *end,
332 const struct usb_host_config *config,
333 int active
334)
335{ 326{
336 int i, j; 327 int i, j;
337 struct usb_interface_cache *intfc; 328 struct usb_interface_cache *intfc;
@@ -339,7 +330,8 @@ static char *usb_dump_config (
339 330
340 if (start > end) 331 if (start > end)
341 return start; 332 return start;
342 if (!config) /* getting these some in 2.3.7; none in 2.3.6 */ 333 if (!config)
334 /* getting these some in 2.3.7; none in 2.3.6 */
343 return start + sprintf(start, "(null Cfg. desc.)\n"); 335 return start + sprintf(start, "(null Cfg. desc.)\n");
344 start = usb_dump_config_descriptor(start, end, &config->desc, active); 336 start = usb_dump_config_descriptor(start, end, &config->desc, active);
345 for (i = 0; i < USB_MAXIADS; i++) { 337 for (i = 0; i < USB_MAXIADS; i++) {
@@ -364,7 +356,8 @@ static char *usb_dump_config (
364/* 356/*
365 * Dump the different USB descriptors. 357 * Dump the different USB descriptors.
366 */ 358 */
367static char *usb_dump_device_descriptor(char *start, char *end, const struct usb_device_descriptor *desc) 359static char *usb_dump_device_descriptor(char *start, char *end,
360 const struct usb_device_descriptor *desc)
368{ 361{
369 u16 bcdUSB = le16_to_cpu(desc->bcdUSB); 362 u16 bcdUSB = le16_to_cpu(desc->bcdUSB);
370 u16 bcdDevice = le16_to_cpu(desc->bcdDevice); 363 u16 bcdDevice = le16_to_cpu(desc->bcdDevice);
@@ -374,7 +367,7 @@ static char *usb_dump_device_descriptor(char *start, char *end, const struct usb
374 start += sprintf(start, format_device1, 367 start += sprintf(start, format_device1,
375 bcdUSB >> 8, bcdUSB & 0xff, 368 bcdUSB >> 8, bcdUSB & 0xff,
376 desc->bDeviceClass, 369 desc->bDeviceClass,
377 class_decode (desc->bDeviceClass), 370 class_decode(desc->bDeviceClass),
378 desc->bDeviceSubClass, 371 desc->bDeviceSubClass,
379 desc->bDeviceProtocol, 372 desc->bDeviceProtocol,
380 desc->bMaxPacketSize0, 373 desc->bMaxPacketSize0,
@@ -391,12 +384,14 @@ static char *usb_dump_device_descriptor(char *start, char *end, const struct usb
391/* 384/*
392 * Dump the different strings that this device holds. 385 * Dump the different strings that this device holds.
393 */ 386 */
394static char *usb_dump_device_strings(char *start, char *end, struct usb_device *dev) 387static char *usb_dump_device_strings(char *start, char *end,
388 struct usb_device *dev)
395{ 389{
396 if (start > end) 390 if (start > end)
397 return start; 391 return start;
398 if (dev->manufacturer) 392 if (dev->manufacturer)
399 start += sprintf(start, format_string_manufacturer, dev->manufacturer); 393 start += sprintf(start, format_string_manufacturer,
394 dev->manufacturer);
400 if (start > end) 395 if (start > end)
401 goto out; 396 goto out;
402 if (dev->product) 397 if (dev->product)
@@ -405,7 +400,8 @@ static char *usb_dump_device_strings(char *start, char *end, struct usb_device *
405 goto out; 400 goto out;
406#ifdef ALLOW_SERIAL_NUMBER 401#ifdef ALLOW_SERIAL_NUMBER
407 if (dev->serial) 402 if (dev->serial)
408 start += sprintf(start, format_string_serialnumber, dev->serial); 403 start += sprintf(start, format_string_serialnumber,
404 dev->serial);
409#endif 405#endif
410 out: 406 out:
411 return start; 407 return start;
@@ -417,12 +413,12 @@ static char *usb_dump_desc(char *start, char *end, struct usb_device *dev)
417 413
418 if (start > end) 414 if (start > end)
419 return start; 415 return start;
420 416
421 start = usb_dump_device_descriptor(start, end, &dev->descriptor); 417 start = usb_dump_device_descriptor(start, end, &dev->descriptor);
422 418
423 if (start > end) 419 if (start > end)
424 return start; 420 return start;
425 421
426 start = usb_dump_device_strings(start, end, dev); 422 start = usb_dump_device_strings(start, end, dev);
427 423
428 for (i = 0; i < dev->descriptor.bNumConfigurations; i++) { 424 for (i = 0; i < dev->descriptor.bNumConfigurations; i++) {
@@ -439,7 +435,8 @@ static char *usb_dump_desc(char *start, char *end, struct usb_device *dev)
439 435
440#ifdef PROC_EXTRA /* TBD: may want to add this code later */ 436#ifdef PROC_EXTRA /* TBD: may want to add this code later */
441 437
442static char *usb_dump_hub_descriptor(char *start, char *end, const struct usb_hub_descriptor * desc) 438static char *usb_dump_hub_descriptor(char *start, char *end,
439 const struct usb_hub_descriptor *desc)
443{ 440{
444 int leng = USB_DT_HUB_NONVAR_SIZE; 441 int leng = USB_DT_HUB_NONVAR_SIZE;
445 unsigned char *ptr = (unsigned char *)desc; 442 unsigned char *ptr = (unsigned char *)desc;
@@ -455,13 +452,16 @@ static char *usb_dump_hub_descriptor(char *start, char *end, const struct usb_hu
455 return start; 452 return start;
456} 453}
457 454
458static char *usb_dump_string(char *start, char *end, const struct usb_device *dev, char *id, int index) 455static char *usb_dump_string(char *start, char *end,
456 const struct usb_device *dev, char *id, int index)
459{ 457{
460 if (start > end) 458 if (start > end)
461 return start; 459 return start;
462 start += sprintf(start, "Interface:"); 460 start += sprintf(start, "Interface:");
463 if (index <= dev->maxstring && dev->stringindex && dev->stringindex[index]) 461 if (index <= dev->maxstring && dev->stringindex &&
464 start += sprintf(start, "%s: %.100s ", id, dev->stringindex[index]); 462 dev->stringindex[index])
463 start += sprintf(start, "%s: %.100s ", id,
464 dev->stringindex[index]);
465 return start; 465 return start;
466} 466}
467 467
@@ -476,8 +476,10 @@ static char *usb_dump_string(char *start, char *end, const struct usb_device *de
476 * file_offset - the offset into the devices file on completion 476 * file_offset - the offset into the devices file on completion
477 * The caller must own the device lock. 477 * The caller must own the device lock.
478 */ 478 */
479static ssize_t usb_device_dump(char __user **buffer, size_t *nbytes, loff_t *skip_bytes, loff_t *file_offset, 479static ssize_t usb_device_dump(char __user **buffer, size_t *nbytes,
480 struct usb_device *usbdev, struct usb_bus *bus, int level, int index, int count) 480 loff_t *skip_bytes, loff_t *file_offset,
481 struct usb_device *usbdev, struct usb_bus *bus,
482 int level, int index, int count)
481{ 483{
482 int chix; 484 int chix;
483 int ret, cnt = 0; 485 int ret, cnt = 0;
@@ -485,17 +487,19 @@ static ssize_t usb_device_dump(char __user **buffer, size_t *nbytes, loff_t *ski
485 char *pages_start, *data_end, *speed; 487 char *pages_start, *data_end, *speed;
486 unsigned int length; 488 unsigned int length;
487 ssize_t total_written = 0; 489 ssize_t total_written = 0;
488 490
489 /* don't bother with anything else if we're not writing any data */ 491 /* don't bother with anything else if we're not writing any data */
490 if (*nbytes <= 0) 492 if (*nbytes <= 0)
491 return 0; 493 return 0;
492 494
493 if (level > MAX_TOPO_LEVEL) 495 if (level > MAX_TOPO_LEVEL)
494 return 0; 496 return 0;
495 /* allocate 2^1 pages = 8K (on i386); should be more than enough for one device */ 497 /* allocate 2^1 pages = 8K (on i386);
496 if (!(pages_start = (char*) __get_free_pages(GFP_KERNEL,1))) 498 * should be more than enough for one device */
497 return -ENOMEM; 499 pages_start = (char *)__get_free_pages(GFP_KERNEL, 1);
498 500 if (!pages_start)
501 return -ENOMEM;
502
499 if (usbdev->parent && usbdev->parent->devnum != -1) 503 if (usbdev->parent && usbdev->parent->devnum != -1)
500 parent_devnum = usbdev->parent->devnum; 504 parent_devnum = usbdev->parent->devnum;
501 /* 505 /*
@@ -541,15 +545,16 @@ static ssize_t usb_device_dump(char __user **buffer, size_t *nbytes, loff_t *ski
541 bus->bandwidth_allocated, max, 545 bus->bandwidth_allocated, max,
542 (100 * bus->bandwidth_allocated + max / 2) 546 (100 * bus->bandwidth_allocated + max / 2)
543 / max, 547 / max,
544 bus->bandwidth_int_reqs, 548 bus->bandwidth_int_reqs,
545 bus->bandwidth_isoc_reqs); 549 bus->bandwidth_isoc_reqs);
546 550
547 } 551 }
548 data_end = usb_dump_desc(data_end, pages_start + (2 * PAGE_SIZE) - 256, usbdev); 552 data_end = usb_dump_desc(data_end, pages_start + (2 * PAGE_SIZE) - 256,
549 553 usbdev);
554
550 if (data_end > (pages_start + (2 * PAGE_SIZE) - 256)) 555 if (data_end > (pages_start + (2 * PAGE_SIZE) - 256))
551 data_end += sprintf(data_end, "(truncated)\n"); 556 data_end += sprintf(data_end, "(truncated)\n");
552 557
553 length = data_end - pages_start; 558 length = data_end - pages_start;
554 /* if we can start copying some data to the user */ 559 /* if we can start copying some data to the user */
555 if (length > *skip_bytes) { 560 if (length > *skip_bytes) {
@@ -567,17 +572,18 @@ static ssize_t usb_device_dump(char __user **buffer, size_t *nbytes, loff_t *ski
567 *skip_bytes = 0; 572 *skip_bytes = 0;
568 } else 573 } else
569 *skip_bytes -= length; 574 *skip_bytes -= length;
570 575
571 free_pages((unsigned long)pages_start, 1); 576 free_pages((unsigned long)pages_start, 1);
572 577
573 /* Now look at all of this device's children. */ 578 /* Now look at all of this device's children. */
574 for (chix = 0; chix < usbdev->maxchild; chix++) { 579 for (chix = 0; chix < usbdev->maxchild; chix++) {
575 struct usb_device *childdev = usbdev->children[chix]; 580 struct usb_device *childdev = usbdev->children[chix];
576 581
577 if (childdev) { 582 if (childdev) {
578 usb_lock_device(childdev); 583 usb_lock_device(childdev);
579 ret = usb_device_dump(buffer, nbytes, skip_bytes, file_offset, childdev, 584 ret = usb_device_dump(buffer, nbytes, skip_bytes,
580 bus, level + 1, chix, ++cnt); 585 file_offset, childdev, bus,
586 level + 1, chix, ++cnt);
581 usb_unlock_device(childdev); 587 usb_unlock_device(childdev);
582 if (ret == -EFAULT) 588 if (ret == -EFAULT)
583 return total_written; 589 return total_written;
@@ -587,7 +593,8 @@ static ssize_t usb_device_dump(char __user **buffer, size_t *nbytes, loff_t *ski
587 return total_written; 593 return total_written;
588} 594}
589 595
590static ssize_t usb_device_read(struct file *file, char __user *buf, size_t nbytes, loff_t *ppos) 596static ssize_t usb_device_read(struct file *file, char __user *buf,
597 size_t nbytes, loff_t *ppos)
591{ 598{
592 struct usb_bus *bus; 599 struct usb_bus *bus;
593 ssize_t ret, total_written = 0; 600 ssize_t ret, total_written = 0;
@@ -607,7 +614,8 @@ static ssize_t usb_device_read(struct file *file, char __user *buf, size_t nbyte
607 if (!bus->root_hub) 614 if (!bus->root_hub)
608 continue; 615 continue;
609 usb_lock_device(bus->root_hub); 616 usb_lock_device(bus->root_hub);
610 ret = usb_device_dump(&buf, &nbytes, &skip_bytes, ppos, bus->root_hub, bus, 0, 0, 0); 617 ret = usb_device_dump(&buf, &nbytes, &skip_bytes, ppos,
618 bus->root_hub, bus, 0, 0, 0);
611 usb_unlock_device(bus->root_hub); 619 usb_unlock_device(bus->root_hub);
612 if (ret < 0) { 620 if (ret < 0) {
613 mutex_unlock(&usb_bus_list_lock); 621 mutex_unlock(&usb_bus_list_lock);
@@ -620,7 +628,8 @@ static ssize_t usb_device_read(struct file *file, char __user *buf, size_t nbyte
620} 628}
621 629
622/* Kernel lock for "lastev" protection */ 630/* Kernel lock for "lastev" protection */
623static unsigned int usb_device_poll(struct file *file, struct poll_table_struct *wait) 631static unsigned int usb_device_poll(struct file *file,
632 struct poll_table_struct *wait)
624{ 633{
625 struct usb_device_status *st = file->private_data; 634 struct usb_device_status *st = file->private_data;
626 unsigned int mask = 0; 635 unsigned int mask = 0;
@@ -629,7 +638,8 @@ static unsigned int usb_device_poll(struct file *file, struct poll_table_struct
629 if (!st) { 638 if (!st) {
630 st = kmalloc(sizeof(struct usb_device_status), GFP_KERNEL); 639 st = kmalloc(sizeof(struct usb_device_status), GFP_KERNEL);
631 640
632 /* we may have dropped BKL - need to check for having lost the race */ 641 /* we may have dropped BKL -
642 * need to check for having lost the race */
633 if (file->private_data) { 643 if (file->private_data) {
634 kfree(st); 644 kfree(st);
635 st = file->private_data; 645 st = file->private_data;
@@ -652,7 +662,7 @@ static unsigned int usb_device_poll(struct file *file, struct poll_table_struct
652 } 662 }
653lost_race: 663lost_race:
654 if (file->f_mode & FMODE_READ) 664 if (file->f_mode & FMODE_READ)
655 poll_wait(file, &deviceconndiscwq, wait); 665 poll_wait(file, &deviceconndiscwq, wait);
656 if (st->lastev != conndiscevcnt) 666 if (st->lastev != conndiscevcnt)
657 mask |= POLLIN; 667 mask |= POLLIN;
658 st->lastev = conndiscevcnt; 668 st->lastev = conndiscevcnt;
@@ -662,18 +672,18 @@ lost_race:
662 672
663static int usb_device_open(struct inode *inode, struct file *file) 673static int usb_device_open(struct inode *inode, struct file *file)
664{ 674{
665 file->private_data = NULL; 675 file->private_data = NULL;
666 return 0; 676 return 0;
667} 677}
668 678
669static int usb_device_release(struct inode *inode, struct file *file) 679static int usb_device_release(struct inode *inode, struct file *file)
670{ 680{
671 kfree(file->private_data); 681 kfree(file->private_data);
672 file->private_data = NULL; 682 file->private_data = NULL;
673 return 0; 683 return 0;
674} 684}
675 685
676static loff_t usb_device_lseek(struct file * file, loff_t offset, int orig) 686static loff_t usb_device_lseek(struct file *file, loff_t offset, int orig)
677{ 687{
678 loff_t ret; 688 loff_t ret;
679 689
diff --git a/drivers/usb/core/devio.c b/drivers/usb/core/devio.c
index 1f4f6d02fe25..ae94176c64e4 100644
--- a/drivers/usb/core/devio.c
+++ b/drivers/usb/core/devio.c
@@ -75,14 +75,14 @@ struct async {
75 u32 secid; 75 u32 secid;
76}; 76};
77 77
78static int usbfs_snoop = 0; 78static int usbfs_snoop;
79module_param (usbfs_snoop, bool, S_IRUGO | S_IWUSR); 79module_param(usbfs_snoop, bool, S_IRUGO | S_IWUSR);
80MODULE_PARM_DESC (usbfs_snoop, "true to log all usbfs traffic"); 80MODULE_PARM_DESC(usbfs_snoop, "true to log all usbfs traffic");
81 81
82#define snoop(dev, format, arg...) \ 82#define snoop(dev, format, arg...) \
83 do { \ 83 do { \
84 if (usbfs_snoop) \ 84 if (usbfs_snoop) \
85 dev_info( dev , format , ## arg); \ 85 dev_info(dev , format , ## arg); \
86 } while (0) 86 } while (0)
87 87
88#define USB_DEVICE_DEV MKDEV(USB_DEVICE_MAJOR, 0) 88#define USB_DEVICE_DEV MKDEV(USB_DEVICE_MAJOR, 0)
@@ -90,7 +90,7 @@ MODULE_PARM_DESC (usbfs_snoop, "true to log all usbfs traffic");
90 90
91#define MAX_USBFS_BUFFER_SIZE 16384 91#define MAX_USBFS_BUFFER_SIZE 16384
92 92
93static inline int connected (struct dev_state *ps) 93static inline int connected(struct dev_state *ps)
94{ 94{
95 return (!list_empty(&ps->list) && 95 return (!list_empty(&ps->list) &&
96 ps->dev->state != USB_STATE_NOTATTACHED); 96 ps->dev->state != USB_STATE_NOTATTACHED);
@@ -120,7 +120,8 @@ static loff_t usbdev_lseek(struct file *file, loff_t offset, int orig)
120 return ret; 120 return ret;
121} 121}
122 122
123static ssize_t usbdev_read(struct file *file, char __user *buf, size_t nbytes, loff_t *ppos) 123static ssize_t usbdev_read(struct file *file, char __user *buf, size_t nbytes,
124 loff_t *ppos)
124{ 125{
125 struct dev_state *ps = file->private_data; 126 struct dev_state *ps = file->private_data;
126 struct usb_device *dev = ps->dev; 127 struct usb_device *dev = ps->dev;
@@ -140,7 +141,8 @@ static ssize_t usbdev_read(struct file *file, char __user *buf, size_t nbytes, l
140 } 141 }
141 142
142 if (pos < sizeof(struct usb_device_descriptor)) { 143 if (pos < sizeof(struct usb_device_descriptor)) {
143 struct usb_device_descriptor temp_desc ; /* 18 bytes - fits on the stack */ 144 /* 18 bytes - fits on the stack */
145 struct usb_device_descriptor temp_desc;
144 146
145 memcpy(&temp_desc, &dev->descriptor, sizeof(dev->descriptor)); 147 memcpy(&temp_desc, &dev->descriptor, sizeof(dev->descriptor));
146 le16_to_cpus(&temp_desc.bcdUSB); 148 le16_to_cpus(&temp_desc.bcdUSB);
@@ -210,17 +212,17 @@ err:
210 212
211static struct async *alloc_async(unsigned int numisoframes) 213static struct async *alloc_async(unsigned int numisoframes)
212{ 214{
213 unsigned int assize = sizeof(struct async) + numisoframes * sizeof(struct usb_iso_packet_descriptor); 215 struct async *as;
214 struct async *as = kzalloc(assize, GFP_KERNEL);
215 216
216 if (!as) 217 as = kzalloc(sizeof(struct async), GFP_KERNEL);
217 return NULL; 218 if (!as)
219 return NULL;
218 as->urb = usb_alloc_urb(numisoframes, GFP_KERNEL); 220 as->urb = usb_alloc_urb(numisoframes, GFP_KERNEL);
219 if (!as->urb) { 221 if (!as->urb) {
220 kfree(as); 222 kfree(as);
221 return NULL; 223 return NULL;
222 } 224 }
223 return as; 225 return as;
224} 226}
225 227
226static void free_async(struct async *as) 228static void free_async(struct async *as)
@@ -234,52 +236,54 @@ static void free_async(struct async *as)
234 236
235static inline void async_newpending(struct async *as) 237static inline void async_newpending(struct async *as)
236{ 238{
237 struct dev_state *ps = as->ps; 239 struct dev_state *ps = as->ps;
238 unsigned long flags; 240 unsigned long flags;
239 241
240 spin_lock_irqsave(&ps->lock, flags); 242 spin_lock_irqsave(&ps->lock, flags);
241 list_add_tail(&as->asynclist, &ps->async_pending); 243 list_add_tail(&as->asynclist, &ps->async_pending);
242 spin_unlock_irqrestore(&ps->lock, flags); 244 spin_unlock_irqrestore(&ps->lock, flags);
243} 245}
244 246
245static inline void async_removepending(struct async *as) 247static inline void async_removepending(struct async *as)
246{ 248{
247 struct dev_state *ps = as->ps; 249 struct dev_state *ps = as->ps;
248 unsigned long flags; 250 unsigned long flags;
249 251
250 spin_lock_irqsave(&ps->lock, flags); 252 spin_lock_irqsave(&ps->lock, flags);
251 list_del_init(&as->asynclist); 253 list_del_init(&as->asynclist);
252 spin_unlock_irqrestore(&ps->lock, flags); 254 spin_unlock_irqrestore(&ps->lock, flags);
253} 255}
254 256
255static inline struct async *async_getcompleted(struct dev_state *ps) 257static inline struct async *async_getcompleted(struct dev_state *ps)
256{ 258{
257 unsigned long flags; 259 unsigned long flags;
258 struct async *as = NULL; 260 struct async *as = NULL;
259 261
260 spin_lock_irqsave(&ps->lock, flags); 262 spin_lock_irqsave(&ps->lock, flags);
261 if (!list_empty(&ps->async_completed)) { 263 if (!list_empty(&ps->async_completed)) {
262 as = list_entry(ps->async_completed.next, struct async, asynclist); 264 as = list_entry(ps->async_completed.next, struct async,
263 list_del_init(&as->asynclist); 265 asynclist);
264 } 266 list_del_init(&as->asynclist);
265 spin_unlock_irqrestore(&ps->lock, flags); 267 }
266 return as; 268 spin_unlock_irqrestore(&ps->lock, flags);
269 return as;
267} 270}
268 271
269static inline struct async *async_getpending(struct dev_state *ps, void __user *userurb) 272static inline struct async *async_getpending(struct dev_state *ps,
273 void __user *userurb)
270{ 274{
271 unsigned long flags; 275 unsigned long flags;
272 struct async *as; 276 struct async *as;
273 277
274 spin_lock_irqsave(&ps->lock, flags); 278 spin_lock_irqsave(&ps->lock, flags);
275 list_for_each_entry(as, &ps->async_pending, asynclist) 279 list_for_each_entry(as, &ps->async_pending, asynclist)
276 if (as->userurb == userurb) { 280 if (as->userurb == userurb) {
277 list_del_init(&as->asynclist); 281 list_del_init(&as->asynclist);
278 spin_unlock_irqrestore(&ps->lock, flags); 282 spin_unlock_irqrestore(&ps->lock, flags);
279 return as; 283 return as;
280 } 284 }
281 spin_unlock_irqrestore(&ps->lock, flags); 285 spin_unlock_irqrestore(&ps->lock, flags);
282 return NULL; 286 return NULL;
283} 287}
284 288
285static void snoop_urb(struct urb *urb, void __user *userurb) 289static void snoop_urb(struct urb *urb, void __user *userurb)
@@ -298,19 +302,19 @@ static void snoop_urb(struct urb *urb, void __user *userurb)
298 dev_info(&urb->dev->dev, "actual_length=%d\n", urb->actual_length); 302 dev_info(&urb->dev->dev, "actual_length=%d\n", urb->actual_length);
299 dev_info(&urb->dev->dev, "data: "); 303 dev_info(&urb->dev->dev, "data: ");
300 for (j = 0; j < urb->transfer_buffer_length; ++j) 304 for (j = 0; j < urb->transfer_buffer_length; ++j)
301 printk ("%02x ", data[j]); 305 printk("%02x ", data[j]);
302 printk("\n"); 306 printk("\n");
303} 307}
304 308
305static void async_completed(struct urb *urb) 309static void async_completed(struct urb *urb)
306{ 310{
307 struct async *as = urb->context; 311 struct async *as = urb->context;
308 struct dev_state *ps = as->ps; 312 struct dev_state *ps = as->ps;
309 struct siginfo sinfo; 313 struct siginfo sinfo;
310 314
311 spin_lock(&ps->lock); 315 spin_lock(&ps->lock);
312 list_move_tail(&as->asynclist, &ps->async_completed); 316 list_move_tail(&as->asynclist, &ps->async_completed);
313 spin_unlock(&ps->lock); 317 spin_unlock(&ps->lock);
314 as->status = urb->status; 318 as->status = urb->status;
315 if (as->signr) { 319 if (as->signr) {
316 sinfo.si_signo = as->signr; 320 sinfo.si_signo = as->signr;
@@ -325,7 +329,7 @@ static void async_completed(struct urb *urb)
325 wake_up(&ps->wait); 329 wake_up(&ps->wait);
326} 330}
327 331
328static void destroy_async (struct dev_state *ps, struct list_head *list) 332static void destroy_async(struct dev_state *ps, struct list_head *list)
329{ 333{
330 struct async *as; 334 struct async *as;
331 unsigned long flags; 335 unsigned long flags;
@@ -348,7 +352,8 @@ static void destroy_async (struct dev_state *ps, struct list_head *list)
348 } 352 }
349} 353}
350 354
351static void destroy_async_on_interface (struct dev_state *ps, unsigned int ifnum) 355static void destroy_async_on_interface(struct dev_state *ps,
356 unsigned int ifnum)
352{ 357{
353 struct list_head *p, *q, hitlist; 358 struct list_head *p, *q, hitlist;
354 unsigned long flags; 359 unsigned long flags;
@@ -364,7 +369,7 @@ static void destroy_async_on_interface (struct dev_state *ps, unsigned int ifnum
364 369
365static inline void destroy_all_async(struct dev_state *ps) 370static inline void destroy_all_async(struct dev_state *ps)
366{ 371{
367 destroy_async(ps, &ps->async_pending); 372 destroy_async(ps, &ps->async_pending);
368} 373}
369 374
370/* 375/*
@@ -373,15 +378,15 @@ static inline void destroy_all_async(struct dev_state *ps)
373 * they're also undone when devices disconnect. 378 * they're also undone when devices disconnect.
374 */ 379 */
375 380
376static int driver_probe (struct usb_interface *intf, 381static int driver_probe(struct usb_interface *intf,
377 const struct usb_device_id *id) 382 const struct usb_device_id *id)
378{ 383{
379 return -ENODEV; 384 return -ENODEV;
380} 385}
381 386
382static void driver_disconnect(struct usb_interface *intf) 387static void driver_disconnect(struct usb_interface *intf)
383{ 388{
384 struct dev_state *ps = usb_get_intfdata (intf); 389 struct dev_state *ps = usb_get_intfdata(intf);
385 unsigned int ifnum = intf->altsetting->desc.bInterfaceNumber; 390 unsigned int ifnum = intf->altsetting->desc.bInterfaceNumber;
386 391
387 if (!ps) 392 if (!ps)
@@ -396,16 +401,31 @@ static void driver_disconnect(struct usb_interface *intf)
396 else 401 else
397 warn("interface number %u out of range", ifnum); 402 warn("interface number %u out of range", ifnum);
398 403
399 usb_set_intfdata (intf, NULL); 404 usb_set_intfdata(intf, NULL);
400 405
401 /* force async requests to complete */ 406 /* force async requests to complete */
402 destroy_async_on_interface(ps, ifnum); 407 destroy_async_on_interface(ps, ifnum);
403} 408}
404 409
410/* The following routines are merely placeholders. There is no way
411 * to inform a user task about suspend or resumes.
412 */
413static int driver_suspend(struct usb_interface *intf, pm_message_t msg)
414{
415 return 0;
416}
417
418static int driver_resume(struct usb_interface *intf)
419{
420 return 0;
421}
422
405struct usb_driver usbfs_driver = { 423struct usb_driver usbfs_driver = {
406 .name = "usbfs", 424 .name = "usbfs",
407 .probe = driver_probe, 425 .probe = driver_probe,
408 .disconnect = driver_disconnect, 426 .disconnect = driver_disconnect,
427 .suspend = driver_suspend,
428 .resume = driver_resume,
409}; 429};
410 430
411static int claimintf(struct dev_state *ps, unsigned int ifnum) 431static int claimintf(struct dev_state *ps, unsigned int ifnum)
@@ -459,15 +479,16 @@ static int checkintf(struct dev_state *ps, unsigned int ifnum)
459 if (test_bit(ifnum, &ps->ifclaimed)) 479 if (test_bit(ifnum, &ps->ifclaimed))
460 return 0; 480 return 0;
461 /* if not yet claimed, claim it for the driver */ 481 /* if not yet claimed, claim it for the driver */
462 dev_warn(&ps->dev->dev, "usbfs: process %d (%s) did not claim interface %u before use\n", 482 dev_warn(&ps->dev->dev, "usbfs: process %d (%s) did not claim "
463 task_pid_nr(current), current->comm, ifnum); 483 "interface %u before use\n", task_pid_nr(current),
484 current->comm, ifnum);
464 return claimintf(ps, ifnum); 485 return claimintf(ps, ifnum);
465} 486}
466 487
467static int findintfep(struct usb_device *dev, unsigned int ep) 488static int findintfep(struct usb_device *dev, unsigned int ep)
468{ 489{
469 unsigned int i, j, e; 490 unsigned int i, j, e;
470 struct usb_interface *intf; 491 struct usb_interface *intf;
471 struct usb_host_interface *alts; 492 struct usb_host_interface *alts;
472 struct usb_endpoint_descriptor *endpt; 493 struct usb_endpoint_descriptor *endpt;
473 494
@@ -478,7 +499,7 @@ static int findintfep(struct usb_device *dev, unsigned int ep)
478 for (i = 0; i < dev->actconfig->desc.bNumInterfaces; i++) { 499 for (i = 0; i < dev->actconfig->desc.bNumInterfaces; i++) {
479 intf = dev->actconfig->interface[i]; 500 intf = dev->actconfig->interface[i];
480 for (j = 0; j < intf->num_altsetting; j++) { 501 for (j = 0; j < intf->num_altsetting; j++) {
481 alts = &intf->altsetting[j]; 502 alts = &intf->altsetting[j];
482 for (e = 0; e < alts->desc.bNumEndpoints; e++) { 503 for (e = 0; e < alts->desc.bNumEndpoints; e++) {
483 endpt = &alts->endpoint[e].desc; 504 endpt = &alts->endpoint[e].desc;
484 if (endpt->bEndpointAddress == ep) 505 if (endpt->bEndpointAddress == ep)
@@ -486,10 +507,11 @@ static int findintfep(struct usb_device *dev, unsigned int ep)
486 } 507 }
487 } 508 }
488 } 509 }
489 return -ENOENT; 510 return -ENOENT;
490} 511}
491 512
492static int check_ctrlrecip(struct dev_state *ps, unsigned int requesttype, unsigned int index) 513static int check_ctrlrecip(struct dev_state *ps, unsigned int requesttype,
514 unsigned int index)
493{ 515{
494 int ret = 0; 516 int ret = 0;
495 517
@@ -502,7 +524,8 @@ static int check_ctrlrecip(struct dev_state *ps, unsigned int requesttype, unsig
502 index &= 0xff; 524 index &= 0xff;
503 switch (requesttype & USB_RECIP_MASK) { 525 switch (requesttype & USB_RECIP_MASK) {
504 case USB_RECIP_ENDPOINT: 526 case USB_RECIP_ENDPOINT:
505 if ((ret = findintfep(ps->dev, index)) >= 0) 527 ret = findintfep(ps->dev, index);
528 if (ret >= 0)
506 ret = checkintf(ps, ret); 529 ret = checkintf(ps, ret);
507 break; 530 break;
508 531
@@ -546,7 +569,8 @@ static int usbdev_open(struct inode *inode, struct file *file)
546 mutex_lock(&usbfs_mutex); 569 mutex_lock(&usbfs_mutex);
547 570
548 ret = -ENOMEM; 571 ret = -ENOMEM;
549 if (!(ps = kmalloc(sizeof(struct dev_state), GFP_KERNEL))) 572 ps = kmalloc(sizeof(struct dev_state), GFP_KERNEL);
573 if (!ps)
550 goto out; 574 goto out;
551 575
552 ret = -ENOENT; 576 ret = -ENOENT;
@@ -627,15 +651,18 @@ static int proc_control(struct dev_state *ps, void __user *arg)
627 651
628 if (copy_from_user(&ctrl, arg, sizeof(ctrl))) 652 if (copy_from_user(&ctrl, arg, sizeof(ctrl)))
629 return -EFAULT; 653 return -EFAULT;
630 if ((ret = check_ctrlrecip(ps, ctrl.bRequestType, ctrl.wIndex))) 654 ret = check_ctrlrecip(ps, ctrl.bRequestType, ctrl.wIndex);
655 if (ret)
631 return ret; 656 return ret;
632 if (ctrl.wLength > PAGE_SIZE) 657 if (ctrl.wLength > PAGE_SIZE)
633 return -EINVAL; 658 return -EINVAL;
634 if (!(tbuf = (unsigned char *)__get_free_page(GFP_KERNEL))) 659 tbuf = (unsigned char *)__get_free_page(GFP_KERNEL);
660 if (!tbuf)
635 return -ENOMEM; 661 return -ENOMEM;
636 tmo = ctrl.timeout; 662 tmo = ctrl.timeout;
637 if (ctrl.bRequestType & 0x80) { 663 if (ctrl.bRequestType & 0x80) {
638 if (ctrl.wLength && !access_ok(VERIFY_WRITE, ctrl.data, ctrl.wLength)) { 664 if (ctrl.wLength && !access_ok(VERIFY_WRITE, ctrl.data,
665 ctrl.wLength)) {
639 free_page((unsigned long)tbuf); 666 free_page((unsigned long)tbuf);
640 return -EINVAL; 667 return -EINVAL;
641 } 668 }
@@ -646,14 +673,15 @@ static int proc_control(struct dev_state *ps, void __user *arg)
646 ctrl.wIndex, ctrl.wLength); 673 ctrl.wIndex, ctrl.wLength);
647 674
648 usb_unlock_device(dev); 675 usb_unlock_device(dev);
649 i = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0), ctrl.bRequest, ctrl.bRequestType, 676 i = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0), ctrl.bRequest,
650 ctrl.wValue, ctrl.wIndex, tbuf, ctrl.wLength, tmo); 677 ctrl.bRequestType, ctrl.wValue, ctrl.wIndex,
678 tbuf, ctrl.wLength, tmo);
651 usb_lock_device(dev); 679 usb_lock_device(dev);
652 if ((i > 0) && ctrl.wLength) { 680 if ((i > 0) && ctrl.wLength) {
653 if (usbfs_snoop) { 681 if (usbfs_snoop) {
654 dev_info(&dev->dev, "control read: data "); 682 dev_info(&dev->dev, "control read: data ");
655 for (j = 0; j < i; ++j) 683 for (j = 0; j < i; ++j)
656 printk("%02x ", (unsigned char)(tbuf)[j]); 684 printk("%02x ", (u8)(tbuf)[j]);
657 printk("\n"); 685 printk("\n");
658 } 686 }
659 if (copy_to_user(ctrl.data, tbuf, i)) { 687 if (copy_to_user(ctrl.data, tbuf, i)) {
@@ -680,12 +708,13 @@ static int proc_control(struct dev_state *ps, void __user *arg)
680 printk("\n"); 708 printk("\n");
681 } 709 }
682 usb_unlock_device(dev); 710 usb_unlock_device(dev);
683 i = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), ctrl.bRequest, ctrl.bRequestType, 711 i = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), ctrl.bRequest,
684 ctrl.wValue, ctrl.wIndex, tbuf, ctrl.wLength, tmo); 712 ctrl.bRequestType, ctrl.wValue, ctrl.wIndex,
713 tbuf, ctrl.wLength, tmo);
685 usb_lock_device(dev); 714 usb_lock_device(dev);
686 } 715 }
687 free_page((unsigned long)tbuf); 716 free_page((unsigned long)tbuf);
688 if (i<0 && i != -EPIPE) { 717 if (i < 0 && i != -EPIPE) {
689 dev_printk(KERN_DEBUG, &dev->dev, "usbfs: USBDEVFS_CONTROL " 718 dev_printk(KERN_DEBUG, &dev->dev, "usbfs: USBDEVFS_CONTROL "
690 "failed cmd %s rqt %u rq %u len %u ret %d\n", 719 "failed cmd %s rqt %u rq %u len %u ret %d\n",
691 current->comm, ctrl.bRequestType, ctrl.bRequest, 720 current->comm, ctrl.bRequestType, ctrl.bRequest,
@@ -705,9 +734,11 @@ static int proc_bulk(struct dev_state *ps, void __user *arg)
705 734
706 if (copy_from_user(&bulk, arg, sizeof(bulk))) 735 if (copy_from_user(&bulk, arg, sizeof(bulk)))
707 return -EFAULT; 736 return -EFAULT;
708 if ((ret = findintfep(ps->dev, bulk.ep)) < 0) 737 ret = findintfep(ps->dev, bulk.ep);
738 if (ret < 0)
709 return ret; 739 return ret;
710 if ((ret = checkintf(ps, ret))) 740 ret = checkintf(ps, ret);
741 if (ret)
711 return ret; 742 return ret;
712 if (bulk.ep & USB_DIR_IN) 743 if (bulk.ep & USB_DIR_IN)
713 pipe = usb_rcvbulkpipe(dev, bulk.ep & 0x7f); 744 pipe = usb_rcvbulkpipe(dev, bulk.ep & 0x7f);
@@ -735,7 +766,7 @@ static int proc_bulk(struct dev_state *ps, void __user *arg)
735 if (usbfs_snoop) { 766 if (usbfs_snoop) {
736 dev_info(&dev->dev, "bulk read: data "); 767 dev_info(&dev->dev, "bulk read: data ");
737 for (j = 0; j < len2; ++j) 768 for (j = 0; j < len2; ++j)
738 printk("%02x ", (unsigned char)(tbuf)[j]); 769 printk("%02x ", (u8)(tbuf)[j]);
739 printk("\n"); 770 printk("\n");
740 } 771 }
741 if (copy_to_user(bulk.data, tbuf, len2)) { 772 if (copy_to_user(bulk.data, tbuf, len2)) {
@@ -775,9 +806,11 @@ static int proc_resetep(struct dev_state *ps, void __user *arg)
775 806
776 if (get_user(ep, (unsigned int __user *)arg)) 807 if (get_user(ep, (unsigned int __user *)arg))
777 return -EFAULT; 808 return -EFAULT;
778 if ((ret = findintfep(ps->dev, ep)) < 0) 809 ret = findintfep(ps->dev, ep);
810 if (ret < 0)
779 return ret; 811 return ret;
780 if ((ret = checkintf(ps, ret))) 812 ret = checkintf(ps, ret);
813 if (ret)
781 return ret; 814 return ret;
782 usb_settoggle(ps->dev, ep & 0xf, !(ep & USB_DIR_IN), 0); 815 usb_settoggle(ps->dev, ep & 0xf, !(ep & USB_DIR_IN), 0);
783 return 0; 816 return 0;
@@ -791,18 +824,19 @@ static int proc_clearhalt(struct dev_state *ps, void __user *arg)
791 824
792 if (get_user(ep, (unsigned int __user *)arg)) 825 if (get_user(ep, (unsigned int __user *)arg))
793 return -EFAULT; 826 return -EFAULT;
794 if ((ret = findintfep(ps->dev, ep)) < 0) 827 ret = findintfep(ps->dev, ep);
828 if (ret < 0)
795 return ret; 829 return ret;
796 if ((ret = checkintf(ps, ret))) 830 ret = checkintf(ps, ret);
831 if (ret)
797 return ret; 832 return ret;
798 if (ep & USB_DIR_IN) 833 if (ep & USB_DIR_IN)
799 pipe = usb_rcvbulkpipe(ps->dev, ep & 0x7f); 834 pipe = usb_rcvbulkpipe(ps->dev, ep & 0x7f);
800 else 835 else
801 pipe = usb_sndbulkpipe(ps->dev, ep & 0x7f); 836 pipe = usb_sndbulkpipe(ps->dev, ep & 0x7f);
802 837
803 return usb_clear_halt(ps->dev, pipe); 838 return usb_clear_halt(ps->dev, pipe);
804} 839}
805
806 840
807static int proc_getdriver(struct dev_state *ps, void __user *arg) 841static int proc_getdriver(struct dev_state *ps, void __user *arg)
808{ 842{
@@ -856,23 +890,23 @@ static int proc_setconfig(struct dev_state *ps, void __user *arg)
856{ 890{
857 int u; 891 int u;
858 int status = 0; 892 int status = 0;
859 struct usb_host_config *actconfig; 893 struct usb_host_config *actconfig;
860 894
861 if (get_user(u, (int __user *)arg)) 895 if (get_user(u, (int __user *)arg))
862 return -EFAULT; 896 return -EFAULT;
863 897
864 actconfig = ps->dev->actconfig; 898 actconfig = ps->dev->actconfig;
865 899
866 /* Don't touch the device if any interfaces are claimed. 900 /* Don't touch the device if any interfaces are claimed.
867 * It could interfere with other drivers' operations, and if 901 * It could interfere with other drivers' operations, and if
868 * an interface is claimed by usbfs it could easily deadlock. 902 * an interface is claimed by usbfs it could easily deadlock.
869 */ 903 */
870 if (actconfig) { 904 if (actconfig) {
871 int i; 905 int i;
872 906
873 for (i = 0; i < actconfig->desc.bNumInterfaces; ++i) { 907 for (i = 0; i < actconfig->desc.bNumInterfaces; ++i) {
874 if (usb_interface_claimed(actconfig->interface[i])) { 908 if (usb_interface_claimed(actconfig->interface[i])) {
875 dev_warn (&ps->dev->dev, 909 dev_warn(&ps->dev->dev,
876 "usbfs: interface %d claimed by %s " 910 "usbfs: interface %d claimed by %s "
877 "while '%s' sets config #%d\n", 911 "while '%s' sets config #%d\n",
878 actconfig->interface[i] 912 actconfig->interface[i]
@@ -881,11 +915,11 @@ static int proc_setconfig(struct dev_state *ps, void __user *arg)
881 actconfig->interface[i] 915 actconfig->interface[i]
882 ->dev.driver->name, 916 ->dev.driver->name,
883 current->comm, u); 917 current->comm, u);
884 status = -EBUSY; 918 status = -EBUSY;
885 break; 919 break;
886 } 920 }
887 } 921 }
888 } 922 }
889 923
890 /* SET_CONFIGURATION is often abused as a "cheap" driver reset, 924 /* SET_CONFIGURATION is often abused as a "cheap" driver reset,
891 * so avoid usb_set_configuration()'s kick to sysfs 925 * so avoid usb_set_configuration()'s kick to sysfs
@@ -901,8 +935,8 @@ static int proc_setconfig(struct dev_state *ps, void __user *arg)
901} 935}
902 936
903static int proc_do_submiturb(struct dev_state *ps, struct usbdevfs_urb *uurb, 937static int proc_do_submiturb(struct dev_state *ps, struct usbdevfs_urb *uurb,
904 struct usbdevfs_iso_packet_desc __user *iso_frame_desc, 938 struct usbdevfs_iso_packet_desc __user *iso_frame_desc,
905 void __user *arg) 939 void __user *arg)
906{ 940{
907 struct usbdevfs_iso_packet_desc *isopkt = NULL; 941 struct usbdevfs_iso_packet_desc *isopkt = NULL;
908 struct usb_host_endpoint *ep; 942 struct usb_host_endpoint *ep;
@@ -917,12 +951,16 @@ static int proc_do_submiturb(struct dev_state *ps, struct usbdevfs_urb *uurb,
917 return -EINVAL; 951 return -EINVAL;
918 if (!uurb->buffer) 952 if (!uurb->buffer)
919 return -EINVAL; 953 return -EINVAL;
920 if (uurb->signr != 0 && (uurb->signr < SIGRTMIN || uurb->signr > SIGRTMAX)) 954 if (uurb->signr != 0 && (uurb->signr < SIGRTMIN ||
955 uurb->signr > SIGRTMAX))
921 return -EINVAL; 956 return -EINVAL;
922 if (!(uurb->type == USBDEVFS_URB_TYPE_CONTROL && (uurb->endpoint & ~USB_ENDPOINT_DIR_MASK) == 0)) { 957 if (!(uurb->type == USBDEVFS_URB_TYPE_CONTROL &&
923 if ((ifnum = findintfep(ps->dev, uurb->endpoint)) < 0) 958 (uurb->endpoint & ~USB_ENDPOINT_DIR_MASK) == 0)) {
959 ifnum = findintfep(ps->dev, uurb->endpoint);
960 if (ifnum < 0)
924 return ifnum; 961 return ifnum;
925 if ((ret = checkintf(ps, ifnum))) 962 ret = checkintf(ps, ifnum);
963 if (ret)
926 return ret; 964 return ret;
927 } 965 }
928 if ((uurb->endpoint & USB_ENDPOINT_DIR_MASK) != 0) { 966 if ((uurb->endpoint & USB_ENDPOINT_DIR_MASK) != 0) {
@@ -938,10 +976,13 @@ static int proc_do_submiturb(struct dev_state *ps, struct usbdevfs_urb *uurb,
938 case USBDEVFS_URB_TYPE_CONTROL: 976 case USBDEVFS_URB_TYPE_CONTROL:
939 if (!usb_endpoint_xfer_control(&ep->desc)) 977 if (!usb_endpoint_xfer_control(&ep->desc))
940 return -EINVAL; 978 return -EINVAL;
941 /* min 8 byte setup packet, max 8 byte setup plus an arbitrary data stage */ 979 /* min 8 byte setup packet,
942 if (uurb->buffer_length < 8 || uurb->buffer_length > (8 + MAX_USBFS_BUFFER_SIZE)) 980 * max 8 byte setup plus an arbitrary data stage */
981 if (uurb->buffer_length < 8 ||
982 uurb->buffer_length > (8 + MAX_USBFS_BUFFER_SIZE))
943 return -EINVAL; 983 return -EINVAL;
944 if (!(dr = kmalloc(sizeof(struct usb_ctrlrequest), GFP_KERNEL))) 984 dr = kmalloc(sizeof(struct usb_ctrlrequest), GFP_KERNEL);
985 if (!dr)
945 return -ENOMEM; 986 return -ENOMEM;
946 if (copy_from_user(dr, uurb->buffer, 8)) { 987 if (copy_from_user(dr, uurb->buffer, 8)) {
947 kfree(dr); 988 kfree(dr);
@@ -951,7 +992,9 @@ static int proc_do_submiturb(struct dev_state *ps, struct usbdevfs_urb *uurb,
951 kfree(dr); 992 kfree(dr);
952 return -EINVAL; 993 return -EINVAL;
953 } 994 }
954 if ((ret = check_ctrlrecip(ps, dr->bRequestType, le16_to_cpup(&dr->wIndex)))) { 995 ret = check_ctrlrecip(ps, dr->bRequestType,
996 le16_to_cpup(&dr->wIndex));
997 if (ret) {
955 kfree(dr); 998 kfree(dr);
956 return ret; 999 return ret;
957 } 1000 }
@@ -997,11 +1040,13 @@ static int proc_do_submiturb(struct dev_state *ps, struct usbdevfs_urb *uurb,
997 1040
998 case USBDEVFS_URB_TYPE_ISO: 1041 case USBDEVFS_URB_TYPE_ISO:
999 /* arbitrary limit */ 1042 /* arbitrary limit */
1000 if (uurb->number_of_packets < 1 || uurb->number_of_packets > 128) 1043 if (uurb->number_of_packets < 1 ||
1044 uurb->number_of_packets > 128)
1001 return -EINVAL; 1045 return -EINVAL;
1002 if (!usb_endpoint_xfer_isoc(&ep->desc)) 1046 if (!usb_endpoint_xfer_isoc(&ep->desc))
1003 return -EINVAL; 1047 return -EINVAL;
1004 isofrmlen = sizeof(struct usbdevfs_iso_packet_desc) * uurb->number_of_packets; 1048 isofrmlen = sizeof(struct usbdevfs_iso_packet_desc) *
1049 uurb->number_of_packets;
1005 if (!(isopkt = kmalloc(isofrmlen, GFP_KERNEL))) 1050 if (!(isopkt = kmalloc(isofrmlen, GFP_KERNEL)))
1006 return -ENOMEM; 1051 return -ENOMEM;
1007 if (copy_from_user(isopkt, iso_frame_desc, isofrmlen)) { 1052 if (copy_from_user(isopkt, iso_frame_desc, isofrmlen)) {
@@ -1009,7 +1054,8 @@ static int proc_do_submiturb(struct dev_state *ps, struct usbdevfs_urb *uurb,
1009 return -EFAULT; 1054 return -EFAULT;
1010 } 1055 }
1011 for (totlen = u = 0; u < uurb->number_of_packets; u++) { 1056 for (totlen = u = 0; u < uurb->number_of_packets; u++) {
1012 /* arbitrary limit, sufficient for USB 2.0 high-bandwidth iso */ 1057 /* arbitrary limit,
1058 * sufficient for USB 2.0 high-bandwidth iso */
1013 if (isopkt[u].length > 8192) { 1059 if (isopkt[u].length > 8192) {
1014 kfree(isopkt); 1060 kfree(isopkt);
1015 return -EINVAL; 1061 return -EINVAL;
@@ -1039,25 +1085,27 @@ static int proc_do_submiturb(struct dev_state *ps, struct usbdevfs_urb *uurb,
1039 default: 1085 default:
1040 return -EINVAL; 1086 return -EINVAL;
1041 } 1087 }
1042 if (!(as = alloc_async(uurb->number_of_packets))) { 1088 as = alloc_async(uurb->number_of_packets);
1089 if (!as) {
1043 kfree(isopkt); 1090 kfree(isopkt);
1044 kfree(dr); 1091 kfree(dr);
1045 return -ENOMEM; 1092 return -ENOMEM;
1046 } 1093 }
1047 if (!(as->urb->transfer_buffer = kmalloc(uurb->buffer_length, GFP_KERNEL))) { 1094 as->urb->transfer_buffer = kmalloc(uurb->buffer_length, GFP_KERNEL);
1095 if (!as->urb->transfer_buffer) {
1048 kfree(isopkt); 1096 kfree(isopkt);
1049 kfree(dr); 1097 kfree(dr);
1050 free_async(as); 1098 free_async(as);
1051 return -ENOMEM; 1099 return -ENOMEM;
1052 } 1100 }
1053 as->urb->dev = ps->dev; 1101 as->urb->dev = ps->dev;
1054 as->urb->pipe = (uurb->type << 30) | 1102 as->urb->pipe = (uurb->type << 30) |
1055 __create_pipe(ps->dev, uurb->endpoint & 0xf) | 1103 __create_pipe(ps->dev, uurb->endpoint & 0xf) |
1056 (uurb->endpoint & USB_DIR_IN); 1104 (uurb->endpoint & USB_DIR_IN);
1057 as->urb->transfer_flags = uurb->flags | 1105 as->urb->transfer_flags = uurb->flags |
1058 (is_in ? URB_DIR_IN : URB_DIR_OUT); 1106 (is_in ? URB_DIR_IN : URB_DIR_OUT);
1059 as->urb->transfer_buffer_length = uurb->buffer_length; 1107 as->urb->transfer_buffer_length = uurb->buffer_length;
1060 as->urb->setup_packet = (unsigned char*)dr; 1108 as->urb->setup_packet = (unsigned char *)dr;
1061 as->urb->start_frame = uurb->start_frame; 1109 as->urb->start_frame = uurb->start_frame;
1062 as->urb->number_of_packets = uurb->number_of_packets; 1110 as->urb->number_of_packets = uurb->number_of_packets;
1063 if (uurb->type == USBDEVFS_URB_TYPE_ISO || 1111 if (uurb->type == USBDEVFS_URB_TYPE_ISO ||
@@ -1065,8 +1113,8 @@ static int proc_do_submiturb(struct dev_state *ps, struct usbdevfs_urb *uurb,
1065 as->urb->interval = 1 << min(15, ep->desc.bInterval - 1); 1113 as->urb->interval = 1 << min(15, ep->desc.bInterval - 1);
1066 else 1114 else
1067 as->urb->interval = ep->desc.bInterval; 1115 as->urb->interval = ep->desc.bInterval;
1068 as->urb->context = as; 1116 as->urb->context = as;
1069 as->urb->complete = async_completed; 1117 as->urb->complete = async_completed;
1070 for (totlen = u = 0; u < uurb->number_of_packets; u++) { 1118 for (totlen = u = 0; u < uurb->number_of_packets; u++) {
1071 as->urb->iso_frame_desc[u].offset = totlen; 1119 as->urb->iso_frame_desc[u].offset = totlen;
1072 as->urb->iso_frame_desc[u].length = isopkt[u].length; 1120 as->urb->iso_frame_desc[u].length = isopkt[u].length;
@@ -1074,7 +1122,7 @@ static int proc_do_submiturb(struct dev_state *ps, struct usbdevfs_urb *uurb,
1074 } 1122 }
1075 kfree(isopkt); 1123 kfree(isopkt);
1076 as->ps = ps; 1124 as->ps = ps;
1077 as->userurb = arg; 1125 as->userurb = arg;
1078 if (uurb->endpoint & USB_DIR_IN) 1126 if (uurb->endpoint & USB_DIR_IN)
1079 as->userbuffer = uurb->buffer; 1127 as->userbuffer = uurb->buffer;
1080 else 1128 else
@@ -1093,14 +1141,15 @@ static int proc_do_submiturb(struct dev_state *ps, struct usbdevfs_urb *uurb,
1093 } 1141 }
1094 } 1142 }
1095 snoop_urb(as->urb, as->userurb); 1143 snoop_urb(as->urb, as->userurb);
1096 async_newpending(as); 1144 async_newpending(as);
1097 if ((ret = usb_submit_urb(as->urb, GFP_KERNEL))) { 1145 if ((ret = usb_submit_urb(as->urb, GFP_KERNEL))) {
1098 dev_printk(KERN_DEBUG, &ps->dev->dev, "usbfs: usb_submit_urb returned %d\n", ret); 1146 dev_printk(KERN_DEBUG, &ps->dev->dev,
1099 async_removepending(as); 1147 "usbfs: usb_submit_urb returned %d\n", ret);
1100 free_async(as); 1148 async_removepending(as);
1101 return ret; 1149 free_async(as);
1102 } 1150 return ret;
1103 return 0; 1151 }
1152 return 0;
1104} 1153}
1105 1154
1106static int proc_submiturb(struct dev_state *ps, void __user *arg) 1155static int proc_submiturb(struct dev_state *ps, void __user *arg)
@@ -1110,7 +1159,9 @@ static int proc_submiturb(struct dev_state *ps, void __user *arg)
1110 if (copy_from_user(&uurb, arg, sizeof(uurb))) 1159 if (copy_from_user(&uurb, arg, sizeof(uurb)))
1111 return -EFAULT; 1160 return -EFAULT;
1112 1161
1113 return proc_do_submiturb(ps, &uurb, (((struct usbdevfs_urb __user *)arg)->iso_frame_desc), arg); 1162 return proc_do_submiturb(ps, &uurb,
1163 (((struct usbdevfs_urb __user *)arg)->iso_frame_desc),
1164 arg);
1114} 1165}
1115 1166
1116static int proc_unlinkurb(struct dev_state *ps, void __user *arg) 1167static int proc_unlinkurb(struct dev_state *ps, void __user *arg)
@@ -1132,7 +1183,8 @@ static int processcompl(struct async *as, void __user * __user *arg)
1132 unsigned int i; 1183 unsigned int i;
1133 1184
1134 if (as->userbuffer) 1185 if (as->userbuffer)
1135 if (copy_to_user(as->userbuffer, urb->transfer_buffer, urb->transfer_buffer_length)) 1186 if (copy_to_user(as->userbuffer, urb->transfer_buffer,
1187 urb->transfer_buffer_length))
1136 return -EFAULT; 1188 return -EFAULT;
1137 if (put_user(as->status, &userurb->status)) 1189 if (put_user(as->status, &userurb->status))
1138 return -EFAULT; 1190 return -EFAULT;
@@ -1159,16 +1211,17 @@ static int processcompl(struct async *as, void __user * __user *arg)
1159 return 0; 1211 return 0;
1160} 1212}
1161 1213
1162static struct async* reap_as(struct dev_state *ps) 1214static struct async *reap_as(struct dev_state *ps)
1163{ 1215{
1164 DECLARE_WAITQUEUE(wait, current); 1216 DECLARE_WAITQUEUE(wait, current);
1165 struct async *as = NULL; 1217 struct async *as = NULL;
1166 struct usb_device *dev = ps->dev; 1218 struct usb_device *dev = ps->dev;
1167 1219
1168 add_wait_queue(&ps->wait, &wait); 1220 add_wait_queue(&ps->wait, &wait);
1169 for (;;) { 1221 for (;;) {
1170 __set_current_state(TASK_INTERRUPTIBLE); 1222 __set_current_state(TASK_INTERRUPTIBLE);
1171 if ((as = async_getcompleted(ps))) 1223 as = async_getcompleted(ps);
1224 if (as)
1172 break; 1225 break;
1173 if (signal_pending(current)) 1226 if (signal_pending(current))
1174 break; 1227 break;
@@ -1232,10 +1285,12 @@ static int proc_submiturb_compat(struct dev_state *ps, void __user *arg)
1232{ 1285{
1233 struct usbdevfs_urb uurb; 1286 struct usbdevfs_urb uurb;
1234 1287
1235 if (get_urb32(&uurb,(struct usbdevfs_urb32 __user *)arg)) 1288 if (get_urb32(&uurb, (struct usbdevfs_urb32 __user *)arg))
1236 return -EFAULT; 1289 return -EFAULT;
1237 1290
1238 return proc_do_submiturb(ps, &uurb, ((struct usbdevfs_urb32 __user *)arg)->iso_frame_desc, arg); 1291 return proc_do_submiturb(ps, &uurb,
1292 ((struct usbdevfs_urb32 __user *)arg)->iso_frame_desc,
1293 arg);
1239} 1294}
1240 1295
1241static int processcompl_compat(struct async *as, void __user * __user *arg) 1296static int processcompl_compat(struct async *as, void __user * __user *arg)
@@ -1246,7 +1301,8 @@ static int processcompl_compat(struct async *as, void __user * __user *arg)
1246 unsigned int i; 1301 unsigned int i;
1247 1302
1248 if (as->userbuffer) 1303 if (as->userbuffer)
1249 if (copy_to_user(as->userbuffer, urb->transfer_buffer, urb->transfer_buffer_length)) 1304 if (copy_to_user(as->userbuffer, urb->transfer_buffer,
1305 urb->transfer_buffer_length))
1250 return -EFAULT; 1306 return -EFAULT;
1251 if (put_user(as->status, &userurb->status)) 1307 if (put_user(as->status, &userurb->status))
1252 return -EFAULT; 1308 return -EFAULT;
@@ -1337,16 +1393,16 @@ static int proc_ioctl(struct dev_state *ps, struct usbdevfs_ioctl *ctl)
1337 struct usb_driver *driver = NULL; 1393 struct usb_driver *driver = NULL;
1338 1394
1339 /* alloc buffer */ 1395 /* alloc buffer */
1340 if ((size = _IOC_SIZE (ctl->ioctl_code)) > 0) { 1396 if ((size = _IOC_SIZE(ctl->ioctl_code)) > 0) {
1341 if ((buf = kmalloc (size, GFP_KERNEL)) == NULL) 1397 if ((buf = kmalloc(size, GFP_KERNEL)) == NULL)
1342 return -ENOMEM; 1398 return -ENOMEM;
1343 if ((_IOC_DIR(ctl->ioctl_code) & _IOC_WRITE)) { 1399 if ((_IOC_DIR(ctl->ioctl_code) & _IOC_WRITE)) {
1344 if (copy_from_user (buf, ctl->data, size)) { 1400 if (copy_from_user(buf, ctl->data, size)) {
1345 kfree(buf); 1401 kfree(buf);
1346 return -EFAULT; 1402 return -EFAULT;
1347 } 1403 }
1348 } else { 1404 } else {
1349 memset (buf, 0, size); 1405 memset(buf, 0, size);
1350 } 1406 }
1351 } 1407 }
1352 1408
@@ -1357,15 +1413,15 @@ static int proc_ioctl(struct dev_state *ps, struct usbdevfs_ioctl *ctl)
1357 1413
1358 if (ps->dev->state != USB_STATE_CONFIGURED) 1414 if (ps->dev->state != USB_STATE_CONFIGURED)
1359 retval = -EHOSTUNREACH; 1415 retval = -EHOSTUNREACH;
1360 else if (!(intf = usb_ifnum_to_if (ps->dev, ctl->ifno))) 1416 else if (!(intf = usb_ifnum_to_if(ps->dev, ctl->ifno)))
1361 retval = -EINVAL; 1417 retval = -EINVAL;
1362 else switch (ctl->ioctl_code) { 1418 else switch (ctl->ioctl_code) {
1363 1419
1364 /* disconnect kernel driver from interface */ 1420 /* disconnect kernel driver from interface */
1365 case USBDEVFS_DISCONNECT: 1421 case USBDEVFS_DISCONNECT:
1366 if (intf->dev.driver) { 1422 if (intf->dev.driver) {
1367 driver = to_usb_driver(intf->dev.driver); 1423 driver = to_usb_driver(intf->dev.driver);
1368 dev_dbg (&intf->dev, "disconnect by usbfs\n"); 1424 dev_dbg(&intf->dev, "disconnect by usbfs\n");
1369 usb_driver_release_interface(driver, intf); 1425 usb_driver_release_interface(driver, intf);
1370 } else 1426 } else
1371 retval = -ENODATA; 1427 retval = -ENODATA;
@@ -1373,9 +1429,10 @@ static int proc_ioctl(struct dev_state *ps, struct usbdevfs_ioctl *ctl)
1373 1429
1374 /* let kernel drivers try to (re)bind to the interface */ 1430 /* let kernel drivers try to (re)bind to the interface */
1375 case USBDEVFS_CONNECT: 1431 case USBDEVFS_CONNECT:
1376 usb_unlock_device(ps->dev); 1432 if (!intf->dev.driver)
1377 retval = bus_rescan_devices(intf->dev.bus); 1433 retval = device_attach(&intf->dev);
1378 usb_lock_device(ps->dev); 1434 else
1435 retval = -EBUSY;
1379 break; 1436 break;
1380 1437
1381 /* talk directly to the interface's driver */ 1438 /* talk directly to the interface's driver */
@@ -1385,7 +1442,7 @@ static int proc_ioctl(struct dev_state *ps, struct usbdevfs_ioctl *ctl)
1385 if (driver == NULL || driver->ioctl == NULL) { 1442 if (driver == NULL || driver->ioctl == NULL) {
1386 retval = -ENOTTY; 1443 retval = -ENOTTY;
1387 } else { 1444 } else {
1388 retval = driver->ioctl (intf, ctl->ioctl_code, buf); 1445 retval = driver->ioctl(intf, ctl->ioctl_code, buf);
1389 if (retval == -ENOIOCTLCMD) 1446 if (retval == -ENOIOCTLCMD)
1390 retval = -ENOTTY; 1447 retval = -ENOTTY;
1391 } 1448 }
@@ -1393,9 +1450,9 @@ static int proc_ioctl(struct dev_state *ps, struct usbdevfs_ioctl *ctl)
1393 1450
1394 /* cleanup and return */ 1451 /* cleanup and return */
1395 if (retval >= 0 1452 if (retval >= 0
1396 && (_IOC_DIR (ctl->ioctl_code) & _IOC_READ) != 0 1453 && (_IOC_DIR(ctl->ioctl_code) & _IOC_READ) != 0
1397 && size > 0 1454 && size > 0
1398 && copy_to_user (ctl->data, buf, size) != 0) 1455 && copy_to_user(ctl->data, buf, size) != 0)
1399 retval = -EFAULT; 1456 retval = -EFAULT;
1400 1457
1401 kfree(buf); 1458 kfree(buf);
@@ -1406,7 +1463,7 @@ static int proc_ioctl_default(struct dev_state *ps, void __user *arg)
1406{ 1463{
1407 struct usbdevfs_ioctl ctrl; 1464 struct usbdevfs_ioctl ctrl;
1408 1465
1409 if (copy_from_user(&ctrl, arg, sizeof (ctrl))) 1466 if (copy_from_user(&ctrl, arg, sizeof(ctrl)))
1410 return -EFAULT; 1467 return -EFAULT;
1411 return proc_ioctl(ps, &ctrl); 1468 return proc_ioctl(ps, &ctrl);
1412} 1469}
@@ -1434,7 +1491,8 @@ static int proc_ioctl_compat(struct dev_state *ps, compat_uptr_t arg)
1434 * are assuming that somehow the configuration has been prevented from 1491 * are assuming that somehow the configuration has been prevented from
1435 * changing. But there's no mechanism to ensure that... 1492 * changing. But there's no mechanism to ensure that...
1436 */ 1493 */
1437static int usbdev_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg) 1494static int usbdev_ioctl(struct inode *inode, struct file *file,
1495 unsigned int cmd, unsigned long arg)
1438{ 1496{
1439 struct dev_state *ps = file->private_data; 1497 struct dev_state *ps = file->private_data;
1440 struct usb_device *dev = ps->dev; 1498 struct usb_device *dev = ps->dev;
@@ -1577,7 +1635,8 @@ static int usbdev_ioctl(struct inode *inode, struct file *file, unsigned int cmd
1577} 1635}
1578 1636
1579/* No kernel lock - fine */ 1637/* No kernel lock - fine */
1580static unsigned int usbdev_poll(struct file *file, struct poll_table_struct *wait) 1638static unsigned int usbdev_poll(struct file *file,
1639 struct poll_table_struct *wait)
1581{ 1640{
1582 struct dev_state *ps = file->private_data; 1641 struct dev_state *ps = file->private_data;
1583 unsigned int mask = 0; 1642 unsigned int mask = 0;
@@ -1648,7 +1707,7 @@ int __init usb_devio_init(void)
1648 int retval; 1707 int retval;
1649 1708
1650 retval = register_chrdev_region(USB_DEVICE_DEV, USB_DEVICE_MAX, 1709 retval = register_chrdev_region(USB_DEVICE_DEV, USB_DEVICE_MAX,
1651 "usb_device"); 1710 "usb_device");
1652 if (retval) { 1711 if (retval) {
1653 err("unable to register minors for usb_device"); 1712 err("unable to register minors for usb_device");
1654 goto out; 1713 goto out;
diff --git a/drivers/usb/core/driver.c b/drivers/usb/core/driver.c
index 7c3aaa9c5402..801b6f142fa7 100644
--- a/drivers/usb/core/driver.c
+++ b/drivers/usb/core/driver.c
@@ -202,10 +202,10 @@ static int usb_probe_interface(struct device *dev)
202 intf = to_usb_interface(dev); 202 intf = to_usb_interface(dev);
203 udev = interface_to_usbdev(intf); 203 udev = interface_to_usbdev(intf);
204 204
205 if (udev->authorized == 0) { 205 if (udev->authorized == 0) {
206 dev_err(&intf->dev, "Device is not authorized for usage\n"); 206 dev_err(&intf->dev, "Device is not authorized for usage\n");
207 return -ENODEV; 207 return -ENODEV;
208 } 208 }
209 209
210 id = usb_match_id(intf, driver->id_table); 210 id = usb_match_id(intf, driver->id_table);
211 if (!id) 211 if (!id)
@@ -299,7 +299,7 @@ static int usb_unbind_interface(struct device *dev)
299 * lock. 299 * lock.
300 */ 300 */
301int usb_driver_claim_interface(struct usb_driver *driver, 301int usb_driver_claim_interface(struct usb_driver *driver,
302 struct usb_interface *iface, void* priv) 302 struct usb_interface *iface, void *priv)
303{ 303{
304 struct device *dev = &iface->dev; 304 struct device *dev = &iface->dev;
305 struct usb_device *udev = interface_to_usbdev(iface); 305 struct usb_device *udev = interface_to_usbdev(iface);
@@ -325,7 +325,7 @@ int usb_driver_claim_interface(struct usb_driver *driver,
325 325
326 return retval; 326 return retval;
327} 327}
328EXPORT_SYMBOL(usb_driver_claim_interface); 328EXPORT_SYMBOL_GPL(usb_driver_claim_interface);
329 329
330/** 330/**
331 * usb_driver_release_interface - unbind a driver from an interface 331 * usb_driver_release_interface - unbind a driver from an interface
@@ -370,7 +370,7 @@ void usb_driver_release_interface(struct usb_driver *driver,
370 iface->needs_remote_wakeup = 0; 370 iface->needs_remote_wakeup = 0;
371 usb_pm_unlock(udev); 371 usb_pm_unlock(udev);
372} 372}
373EXPORT_SYMBOL(usb_driver_release_interface); 373EXPORT_SYMBOL_GPL(usb_driver_release_interface);
374 374
375/* returns 0 if no match, 1 if match */ 375/* returns 0 if no match, 1 if match */
376int usb_match_device(struct usb_device *dev, const struct usb_device_id *id) 376int usb_match_device(struct usb_device *dev, const struct usb_device_id *id)
@@ -398,7 +398,7 @@ int usb_match_device(struct usb_device *dev, const struct usb_device_id *id)
398 return 0; 398 return 0;
399 399
400 if ((id->match_flags & USB_DEVICE_ID_MATCH_DEV_SUBCLASS) && 400 if ((id->match_flags & USB_DEVICE_ID_MATCH_DEV_SUBCLASS) &&
401 (id->bDeviceSubClass!= dev->descriptor.bDeviceSubClass)) 401 (id->bDeviceSubClass != dev->descriptor.bDeviceSubClass))
402 return 0; 402 return 0;
403 403
404 if ((id->match_flags & USB_DEVICE_ID_MATCH_DEV_PROTOCOL) && 404 if ((id->match_flags & USB_DEVICE_ID_MATCH_DEV_PROTOCOL) &&
@@ -534,15 +534,15 @@ const struct usb_device_id *usb_match_id(struct usb_interface *interface,
534 id->driver_info is the way to create an entry that 534 id->driver_info is the way to create an entry that
535 indicates that the driver want to examine every 535 indicates that the driver want to examine every
536 device and interface. */ 536 device and interface. */
537 for (; id->idVendor || id->bDeviceClass || id->bInterfaceClass || 537 for (; id->idVendor || id->idProduct || id->bDeviceClass ||
538 id->driver_info; id++) { 538 id->bInterfaceClass || id->driver_info; id++) {
539 if (usb_match_one_id(interface, id)) 539 if (usb_match_one_id(interface, id))
540 return id; 540 return id;
541 } 541 }
542 542
543 return NULL; 543 return NULL;
544} 544}
545EXPORT_SYMBOL_GPL_FUTURE(usb_match_id); 545EXPORT_SYMBOL_GPL(usb_match_id);
546 546
547static int usb_device_match(struct device *dev, struct device_driver *drv) 547static int usb_device_match(struct device *dev, struct device_driver *drv)
548{ 548{
@@ -586,7 +586,7 @@ static int usb_uevent(struct device *dev, struct kobj_uevent_env *env)
586 struct usb_device *usb_dev; 586 struct usb_device *usb_dev;
587 587
588 /* driver is often null here; dev_dbg() would oops */ 588 /* driver is often null here; dev_dbg() would oops */
589 pr_debug ("usb %s: uevent\n", dev->bus_id); 589 pr_debug("usb %s: uevent\n", dev->bus_id);
590 590
591 if (is_usb_device(dev)) 591 if (is_usb_device(dev))
592 usb_dev = to_usb_device(dev); 592 usb_dev = to_usb_device(dev);
@@ -596,11 +596,11 @@ static int usb_uevent(struct device *dev, struct kobj_uevent_env *env)
596 } 596 }
597 597
598 if (usb_dev->devnum < 0) { 598 if (usb_dev->devnum < 0) {
599 pr_debug ("usb %s: already deleted?\n", dev->bus_id); 599 pr_debug("usb %s: already deleted?\n", dev->bus_id);
600 return -ENODEV; 600 return -ENODEV;
601 } 601 }
602 if (!usb_dev->bus) { 602 if (!usb_dev->bus) {
603 pr_debug ("usb %s: bus removed?\n", dev->bus_id); 603 pr_debug("usb %s: bus removed?\n", dev->bus_id);
604 return -ENODEV; 604 return -ENODEV;
605 } 605 }
606 606
@@ -745,7 +745,7 @@ int usb_register_driver(struct usb_driver *new_driver, struct module *owner,
745 745
746 return retval; 746 return retval;
747} 747}
748EXPORT_SYMBOL_GPL_FUTURE(usb_register_driver); 748EXPORT_SYMBOL_GPL(usb_register_driver);
749 749
750/** 750/**
751 * usb_deregister - unregister a USB interface driver 751 * usb_deregister - unregister a USB interface driver
@@ -769,7 +769,7 @@ void usb_deregister(struct usb_driver *driver)
769 769
770 usbfs_update_special(); 770 usbfs_update_special();
771} 771}
772EXPORT_SYMBOL_GPL_FUTURE(usb_deregister); 772EXPORT_SYMBOL_GPL(usb_deregister);
773 773
774#ifdef CONFIG_PM 774#ifdef CONFIG_PM
775 775
@@ -854,8 +854,10 @@ static int usb_suspend_interface(struct usb_interface *intf, pm_message_t msg)
854 dev_err(&intf->dev, "%s error %d\n", 854 dev_err(&intf->dev, "%s error %d\n",
855 "suspend", status); 855 "suspend", status);
856 } else { 856 } else {
857 // FIXME else if there's no suspend method, disconnect... 857 /*
858 // Not possible if auto_pm is set... 858 * FIXME else if there's no suspend method, disconnect...
859 * Not possible if auto_pm is set...
860 */
859 dev_warn(&intf->dev, "no suspend for driver %s?\n", 861 dev_warn(&intf->dev, "no suspend for driver %s?\n",
860 driver->name); 862 driver->name);
861 mark_quiesced(intf); 863 mark_quiesced(intf);
@@ -894,7 +896,7 @@ static int usb_resume_interface(struct usb_interface *intf, int reset_resume)
894 dev_err(&intf->dev, "%s error %d\n", 896 dev_err(&intf->dev, "%s error %d\n",
895 "reset_resume", status); 897 "reset_resume", status);
896 } else { 898 } else {
897 // status = -EOPNOTSUPP; 899 /* status = -EOPNOTSUPP; */
898 dev_warn(&intf->dev, "no %s for driver %s?\n", 900 dev_warn(&intf->dev, "no %s for driver %s?\n",
899 "reset_resume", driver->name); 901 "reset_resume", driver->name);
900 } 902 }
@@ -905,7 +907,7 @@ static int usb_resume_interface(struct usb_interface *intf, int reset_resume)
905 dev_err(&intf->dev, "%s error %d\n", 907 dev_err(&intf->dev, "%s error %d\n",
906 "resume", status); 908 "resume", status);
907 } else { 909 } else {
908 // status = -EOPNOTSUPP; 910 /* status = -EOPNOTSUPP; */
909 dev_warn(&intf->dev, "no %s for driver %s?\n", 911 dev_warn(&intf->dev, "no %s for driver %s?\n",
910 "resume", driver->name); 912 "resume", driver->name);
911 } 913 }
@@ -1175,7 +1177,7 @@ static int usb_resume_both(struct usb_device *udev)
1175 * so if a root hub's controller is suspended 1177 * so if a root hub's controller is suspended
1176 * then we're stuck. */ 1178 * then we're stuck. */
1177 status = usb_resume_device(udev); 1179 status = usb_resume_device(udev);
1178 } 1180 }
1179 } else { 1181 } else {
1180 1182
1181 /* Needed for setting udev->dev.power.power_state.event, 1183 /* Needed for setting udev->dev.power.power_state.event,
diff --git a/drivers/usb/core/file.c b/drivers/usb/core/file.c
index 5d860bc9b421..8133c99c6c5c 100644
--- a/drivers/usb/core/file.c
+++ b/drivers/usb/core/file.c
@@ -204,7 +204,7 @@ int usb_register_dev(struct usb_interface *intf,
204exit: 204exit:
205 return retval; 205 return retval;
206} 206}
207EXPORT_SYMBOL(usb_register_dev); 207EXPORT_SYMBOL_GPL(usb_register_dev);
208 208
209/** 209/**
210 * usb_deregister_dev - deregister a USB device's dynamic minor. 210 * usb_deregister_dev - deregister a USB device's dynamic minor.
@@ -245,4 +245,4 @@ void usb_deregister_dev(struct usb_interface *intf,
245 intf->minor = -1; 245 intf->minor = -1;
246 destroy_usb_class(); 246 destroy_usb_class();
247} 247}
248EXPORT_SYMBOL(usb_deregister_dev); 248EXPORT_SYMBOL_GPL(usb_deregister_dev);
diff --git a/drivers/usb/core/hcd-pci.c b/drivers/usb/core/hcd-pci.c
index 3fb9af80cbf4..84760ddbc332 100644
--- a/drivers/usb/core/hcd-pci.c
+++ b/drivers/usb/core/hcd-pci.c
@@ -1,6 +1,6 @@
1/* 1/*
2 * (C) Copyright David Brownell 2000-2002 2 * (C) Copyright David Brownell 2000-2002
3 * 3 *
4 * This program is free software; you can redistribute it and/or modify it 4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the 5 * under the terms of the GNU General Public License as published by the
6 * Free Software Foundation; either version 2 of the License, or (at your 6 * Free Software Foundation; either version 2 of the License, or (at your
@@ -55,7 +55,7 @@
55 * 55 *
56 * Store this function in the HCD's struct pci_driver as probe(). 56 * Store this function in the HCD's struct pci_driver as probe().
57 */ 57 */
58int usb_hcd_pci_probe (struct pci_dev *dev, const struct pci_device_id *id) 58int usb_hcd_pci_probe(struct pci_dev *dev, const struct pci_device_id *id)
59{ 59{
60 struct hc_driver *driver; 60 struct hc_driver *driver;
61 struct usb_hcd *hcd; 61 struct usb_hcd *hcd;
@@ -64,66 +64,71 @@ int usb_hcd_pci_probe (struct pci_dev *dev, const struct pci_device_id *id)
64 if (usb_disabled()) 64 if (usb_disabled())
65 return -ENODEV; 65 return -ENODEV;
66 66
67 if (!id || !(driver = (struct hc_driver *) id->driver_data)) 67 if (!id)
68 return -EINVAL;
69 driver = (struct hc_driver *)id->driver_data;
70 if (!driver)
68 return -EINVAL; 71 return -EINVAL;
69 72
70 if (pci_enable_device (dev) < 0) 73 if (pci_enable_device(dev) < 0)
71 return -ENODEV; 74 return -ENODEV;
72 dev->current_state = PCI_D0; 75 dev->current_state = PCI_D0;
73 dev->dev.power.power_state = PMSG_ON; 76 dev->dev.power.power_state = PMSG_ON;
74 77
75 if (!dev->irq) { 78 if (!dev->irq) {
76 dev_err (&dev->dev, 79 dev_err(&dev->dev,
77 "Found HC with no IRQ. Check BIOS/PCI %s setup!\n", 80 "Found HC with no IRQ. Check BIOS/PCI %s setup!\n",
78 pci_name(dev)); 81 pci_name(dev));
79 retval = -ENODEV; 82 retval = -ENODEV;
80 goto err1; 83 goto err1;
81 } 84 }
82 85
83 hcd = usb_create_hcd (driver, &dev->dev, pci_name(dev)); 86 hcd = usb_create_hcd(driver, &dev->dev, pci_name(dev));
84 if (!hcd) { 87 if (!hcd) {
85 retval = -ENOMEM; 88 retval = -ENOMEM;
86 goto err1; 89 goto err1;
87 } 90 }
88 91
89 if (driver->flags & HCD_MEMORY) { // EHCI, OHCI 92 if (driver->flags & HCD_MEMORY) {
90 hcd->rsrc_start = pci_resource_start (dev, 0); 93 /* EHCI, OHCI */
91 hcd->rsrc_len = pci_resource_len (dev, 0); 94 hcd->rsrc_start = pci_resource_start(dev, 0);
92 if (!request_mem_region (hcd->rsrc_start, hcd->rsrc_len, 95 hcd->rsrc_len = pci_resource_len(dev, 0);
96 if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len,
93 driver->description)) { 97 driver->description)) {
94 dev_dbg (&dev->dev, "controller already in use\n"); 98 dev_dbg(&dev->dev, "controller already in use\n");
95 retval = -EBUSY; 99 retval = -EBUSY;
96 goto err2; 100 goto err2;
97 } 101 }
98 hcd->regs = ioremap_nocache (hcd->rsrc_start, hcd->rsrc_len); 102 hcd->regs = ioremap_nocache(hcd->rsrc_start, hcd->rsrc_len);
99 if (hcd->regs == NULL) { 103 if (hcd->regs == NULL) {
100 dev_dbg (&dev->dev, "error mapping memory\n"); 104 dev_dbg(&dev->dev, "error mapping memory\n");
101 retval = -EFAULT; 105 retval = -EFAULT;
102 goto err3; 106 goto err3;
103 } 107 }
104 108
105 } else { // UHCI 109 } else {
110 /* UHCI */
106 int region; 111 int region;
107 112
108 for (region = 0; region < PCI_ROM_RESOURCE; region++) { 113 for (region = 0; region < PCI_ROM_RESOURCE; region++) {
109 if (!(pci_resource_flags (dev, region) & 114 if (!(pci_resource_flags(dev, region) &
110 IORESOURCE_IO)) 115 IORESOURCE_IO))
111 continue; 116 continue;
112 117
113 hcd->rsrc_start = pci_resource_start (dev, region); 118 hcd->rsrc_start = pci_resource_start(dev, region);
114 hcd->rsrc_len = pci_resource_len (dev, region); 119 hcd->rsrc_len = pci_resource_len(dev, region);
115 if (request_region (hcd->rsrc_start, hcd->rsrc_len, 120 if (request_region(hcd->rsrc_start, hcd->rsrc_len,
116 driver->description)) 121 driver->description))
117 break; 122 break;
118 } 123 }
119 if (region == PCI_ROM_RESOURCE) { 124 if (region == PCI_ROM_RESOURCE) {
120 dev_dbg (&dev->dev, "no i/o regions available\n"); 125 dev_dbg(&dev->dev, "no i/o regions available\n");
121 retval = -EBUSY; 126 retval = -EBUSY;
122 goto err1; 127 goto err1;
123 } 128 }
124 } 129 }
125 130
126 pci_set_master (dev); 131 pci_set_master(dev);
127 132
128 retval = usb_add_hcd(hcd, dev->irq, IRQF_DISABLED | IRQF_SHARED); 133 retval = usb_add_hcd(hcd, dev->irq, IRQF_DISABLED | IRQF_SHARED);
129 if (retval != 0) 134 if (retval != 0)
@@ -132,19 +137,19 @@ int usb_hcd_pci_probe (struct pci_dev *dev, const struct pci_device_id *id)
132 137
133 err4: 138 err4:
134 if (driver->flags & HCD_MEMORY) { 139 if (driver->flags & HCD_MEMORY) {
135 iounmap (hcd->regs); 140 iounmap(hcd->regs);
136 err3: 141 err3:
137 release_mem_region (hcd->rsrc_start, hcd->rsrc_len); 142 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
138 } else 143 } else
139 release_region (hcd->rsrc_start, hcd->rsrc_len); 144 release_region(hcd->rsrc_start, hcd->rsrc_len);
140 err2: 145 err2:
141 usb_put_hcd (hcd); 146 usb_put_hcd(hcd);
142 err1: 147 err1:
143 pci_disable_device (dev); 148 pci_disable_device(dev);
144 dev_err (&dev->dev, "init %s fail, %d\n", pci_name(dev), retval); 149 dev_err(&dev->dev, "init %s fail, %d\n", pci_name(dev), retval);
145 return retval; 150 return retval;
146} 151}
147EXPORT_SYMBOL (usb_hcd_pci_probe); 152EXPORT_SYMBOL_GPL(usb_hcd_pci_probe);
148 153
149 154
150/* may be called without controller electrically present */ 155/* may be called without controller electrically present */
@@ -161,7 +166,7 @@ EXPORT_SYMBOL (usb_hcd_pci_probe);
161 * 166 *
162 * Store this function in the HCD's struct pci_driver as remove(). 167 * Store this function in the HCD's struct pci_driver as remove().
163 */ 168 */
164void usb_hcd_pci_remove (struct pci_dev *dev) 169void usb_hcd_pci_remove(struct pci_dev *dev)
165{ 170{
166 struct usb_hcd *hcd; 171 struct usb_hcd *hcd;
167 172
@@ -169,17 +174,17 @@ void usb_hcd_pci_remove (struct pci_dev *dev)
169 if (!hcd) 174 if (!hcd)
170 return; 175 return;
171 176
172 usb_remove_hcd (hcd); 177 usb_remove_hcd(hcd);
173 if (hcd->driver->flags & HCD_MEMORY) { 178 if (hcd->driver->flags & HCD_MEMORY) {
174 iounmap (hcd->regs); 179 iounmap(hcd->regs);
175 release_mem_region (hcd->rsrc_start, hcd->rsrc_len); 180 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
176 } else { 181 } else {
177 release_region (hcd->rsrc_start, hcd->rsrc_len); 182 release_region(hcd->rsrc_start, hcd->rsrc_len);
178 } 183 }
179 usb_put_hcd (hcd); 184 usb_put_hcd(hcd);
180 pci_disable_device(dev); 185 pci_disable_device(dev);
181} 186}
182EXPORT_SYMBOL (usb_hcd_pci_remove); 187EXPORT_SYMBOL_GPL(usb_hcd_pci_remove);
183 188
184 189
185#ifdef CONFIG_PM 190#ifdef CONFIG_PM
@@ -191,7 +196,7 @@ EXPORT_SYMBOL (usb_hcd_pci_remove);
191 * 196 *
192 * Store this function in the HCD's struct pci_driver as suspend(). 197 * Store this function in the HCD's struct pci_driver as suspend().
193 */ 198 */
194int usb_hcd_pci_suspend (struct pci_dev *dev, pm_message_t message) 199int usb_hcd_pci_suspend(struct pci_dev *dev, pm_message_t message)
195{ 200{
196 struct usb_hcd *hcd; 201 struct usb_hcd *hcd;
197 int retval = 0; 202 int retval = 0;
@@ -246,12 +251,18 @@ int usb_hcd_pci_suspend (struct pci_dev *dev, pm_message_t message)
246 251
247 /* no DMA or IRQs except when HC is active */ 252 /* no DMA or IRQs except when HC is active */
248 if (dev->current_state == PCI_D0) { 253 if (dev->current_state == PCI_D0) {
249 pci_save_state (dev); 254 pci_save_state(dev);
250 pci_disable_device (dev); 255 pci_disable_device(dev);
256 }
257
258 if (message.event == PM_EVENT_FREEZE ||
259 message.event == PM_EVENT_PRETHAW) {
260 dev_dbg(hcd->self.controller, "--> no state change\n");
261 goto done;
251 } 262 }
252 263
253 if (!has_pci_pm) { 264 if (!has_pci_pm) {
254 dev_dbg (hcd->self.controller, "--> PCI D0/legacy\n"); 265 dev_dbg(hcd->self.controller, "--> PCI D0/legacy\n");
255 goto done; 266 goto done;
256 } 267 }
257 268
@@ -260,30 +271,30 @@ int usb_hcd_pci_suspend (struct pci_dev *dev, pm_message_t message)
260 * PCI_D3 (but not PCI_D1 or PCI_D2) is allowed to reset 271 * PCI_D3 (but not PCI_D1 or PCI_D2) is allowed to reset
261 * some device state (e.g. as part of clock reinit). 272 * some device state (e.g. as part of clock reinit).
262 */ 273 */
263 retval = pci_set_power_state (dev, PCI_D3hot); 274 retval = pci_set_power_state(dev, PCI_D3hot);
264 suspend_report_result(pci_set_power_state, retval); 275 suspend_report_result(pci_set_power_state, retval);
265 if (retval == 0) { 276 if (retval == 0) {
266 int wake = device_can_wakeup(&hcd->self.root_hub->dev); 277 int wake = device_can_wakeup(&hcd->self.root_hub->dev);
267 278
268 wake = wake && device_may_wakeup(hcd->self.controller); 279 wake = wake && device_may_wakeup(hcd->self.controller);
269 280
270 dev_dbg (hcd->self.controller, "--> PCI D3%s\n", 281 dev_dbg(hcd->self.controller, "--> PCI D3%s\n",
271 wake ? "/wakeup" : ""); 282 wake ? "/wakeup" : "");
272 283
273 /* Ignore these return values. We rely on pci code to 284 /* Ignore these return values. We rely on pci code to
274 * reject requests the hardware can't implement, rather 285 * reject requests the hardware can't implement, rather
275 * than coding the same thing. 286 * than coding the same thing.
276 */ 287 */
277 (void) pci_enable_wake (dev, PCI_D3hot, wake); 288 (void) pci_enable_wake(dev, PCI_D3hot, wake);
278 (void) pci_enable_wake (dev, PCI_D3cold, wake); 289 (void) pci_enable_wake(dev, PCI_D3cold, wake);
279 } else { 290 } else {
280 dev_dbg (&dev->dev, "PCI D3 suspend fail, %d\n", 291 dev_dbg(&dev->dev, "PCI D3 suspend fail, %d\n",
281 retval); 292 retval);
282 (void) usb_hcd_pci_resume (dev); 293 (void) usb_hcd_pci_resume(dev);
283 } 294 }
284 295
285 } else if (hcd->state != HC_STATE_HALT) { 296 } else if (hcd->state != HC_STATE_HALT) {
286 dev_dbg (hcd->self.controller, "hcd state %d; not suspended\n", 297 dev_dbg(hcd->self.controller, "hcd state %d; not suspended\n",
287 hcd->state); 298 hcd->state);
288 WARN_ON(1); 299 WARN_ON(1);
289 retval = -EINVAL; 300 retval = -EINVAL;
@@ -298,7 +309,7 @@ done:
298 if (machine_is(powermac)) { 309 if (machine_is(powermac)) {
299 struct device_node *of_node; 310 struct device_node *of_node;
300 311
301 of_node = pci_device_to_OF_node (dev); 312 of_node = pci_device_to_OF_node(dev);
302 if (of_node) 313 if (of_node)
303 pmac_call_feature(PMAC_FTR_USB_ENABLE, 314 pmac_call_feature(PMAC_FTR_USB_ENABLE,
304 of_node, 0, 0); 315 of_node, 0, 0);
@@ -308,7 +319,7 @@ done:
308 319
309 return retval; 320 return retval;
310} 321}
311EXPORT_SYMBOL (usb_hcd_pci_suspend); 322EXPORT_SYMBOL_GPL(usb_hcd_pci_suspend);
312 323
313/** 324/**
314 * usb_hcd_pci_resume - power management resume of a PCI-based HCD 325 * usb_hcd_pci_resume - power management resume of a PCI-based HCD
@@ -316,14 +327,14 @@ EXPORT_SYMBOL (usb_hcd_pci_suspend);
316 * 327 *
317 * Store this function in the HCD's struct pci_driver as resume(). 328 * Store this function in the HCD's struct pci_driver as resume().
318 */ 329 */
319int usb_hcd_pci_resume (struct pci_dev *dev) 330int usb_hcd_pci_resume(struct pci_dev *dev)
320{ 331{
321 struct usb_hcd *hcd; 332 struct usb_hcd *hcd;
322 int retval; 333 int retval;
323 334
324 hcd = pci_get_drvdata(dev); 335 hcd = pci_get_drvdata(dev);
325 if (hcd->state != HC_STATE_SUSPENDED) { 336 if (hcd->state != HC_STATE_SUSPENDED) {
326 dev_dbg (hcd->self.controller, 337 dev_dbg(hcd->self.controller,
327 "can't resume, not suspended!\n"); 338 "can't resume, not suspended!\n");
328 return 0; 339 return 0;
329 } 340 }
@@ -333,9 +344,9 @@ int usb_hcd_pci_resume (struct pci_dev *dev)
333 if (machine_is(powermac)) { 344 if (machine_is(powermac)) {
334 struct device_node *of_node; 345 struct device_node *of_node;
335 346
336 of_node = pci_device_to_OF_node (dev); 347 of_node = pci_device_to_OF_node(dev);
337 if (of_node) 348 if (of_node)
338 pmac_call_feature (PMAC_FTR_USB_ENABLE, 349 pmac_call_feature(PMAC_FTR_USB_ENABLE,
339 of_node, 0, 1); 350 of_node, 0, 1);
340 } 351 }
341#endif 352#endif
@@ -374,8 +385,8 @@ int usb_hcd_pci_resume (struct pci_dev *dev)
374 } 385 }
375#endif 386#endif
376 /* yes, ignore these results too... */ 387 /* yes, ignore these results too... */
377 (void) pci_enable_wake (dev, dev->current_state, 0); 388 (void) pci_enable_wake(dev, dev->current_state, 0);
378 (void) pci_enable_wake (dev, PCI_D3cold, 0); 389 (void) pci_enable_wake(dev, PCI_D3cold, 0);
379 } else { 390 } else {
380 /* Same basic cases: clean (powered/not), dirty */ 391 /* Same basic cases: clean (powered/not), dirty */
381 dev_dbg(hcd->self.controller, "PCI legacy resume\n"); 392 dev_dbg(hcd->self.controller, "PCI legacy resume\n");
@@ -386,14 +397,14 @@ int usb_hcd_pci_resume (struct pci_dev *dev)
386 * but that won't re-enable bus mastering. Yet pci_disable_device() 397 * but that won't re-enable bus mastering. Yet pci_disable_device()
387 * explicitly disables bus mastering... 398 * explicitly disables bus mastering...
388 */ 399 */
389 retval = pci_enable_device (dev); 400 retval = pci_enable_device(dev);
390 if (retval < 0) { 401 if (retval < 0) {
391 dev_err (hcd->self.controller, 402 dev_err(hcd->self.controller,
392 "can't re-enable after resume, %d!\n", retval); 403 "can't re-enable after resume, %d!\n", retval);
393 return retval; 404 return retval;
394 } 405 }
395 pci_set_master (dev); 406 pci_set_master(dev);
396 pci_restore_state (dev); 407 pci_restore_state(dev);
397 408
398 dev->dev.power.power_state = PMSG_ON; 409 dev->dev.power.power_state = PMSG_ON;
399 410
@@ -402,15 +413,15 @@ int usb_hcd_pci_resume (struct pci_dev *dev)
402 if (hcd->driver->resume) { 413 if (hcd->driver->resume) {
403 retval = hcd->driver->resume(hcd); 414 retval = hcd->driver->resume(hcd);
404 if (retval) { 415 if (retval) {
405 dev_err (hcd->self.controller, 416 dev_err(hcd->self.controller,
406 "PCI post-resume error %d!\n", retval); 417 "PCI post-resume error %d!\n", retval);
407 usb_hc_died (hcd); 418 usb_hc_died(hcd);
408 } 419 }
409 } 420 }
410 421
411 return retval; 422 return retval;
412} 423}
413EXPORT_SYMBOL (usb_hcd_pci_resume); 424EXPORT_SYMBOL_GPL(usb_hcd_pci_resume);
414 425
415#endif /* CONFIG_PM */ 426#endif /* CONFIG_PM */
416 427
@@ -418,7 +429,7 @@ EXPORT_SYMBOL (usb_hcd_pci_resume);
418 * usb_hcd_pci_shutdown - shutdown host controller 429 * usb_hcd_pci_shutdown - shutdown host controller
419 * @dev: USB Host Controller being shutdown 430 * @dev: USB Host Controller being shutdown
420 */ 431 */
421void usb_hcd_pci_shutdown (struct pci_dev *dev) 432void usb_hcd_pci_shutdown(struct pci_dev *dev)
422{ 433{
423 struct usb_hcd *hcd; 434 struct usb_hcd *hcd;
424 435
@@ -429,5 +440,5 @@ void usb_hcd_pci_shutdown (struct pci_dev *dev)
429 if (hcd->driver->shutdown) 440 if (hcd->driver->shutdown)
430 hcd->driver->shutdown(hcd); 441 hcd->driver->shutdown(hcd);
431} 442}
432EXPORT_SYMBOL (usb_hcd_pci_shutdown); 443EXPORT_SYMBOL_GPL(usb_hcd_pci_shutdown);
433 444
diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
index d5ed3fa9e304..e52ed1663b3c 100644
--- a/drivers/usb/core/hcd.c
+++ b/drivers/usb/core/hcd.c
@@ -35,6 +35,7 @@
35#include <linux/mutex.h> 35#include <linux/mutex.h>
36#include <asm/irq.h> 36#include <asm/irq.h>
37#include <asm/byteorder.h> 37#include <asm/byteorder.h>
38#include <asm/unaligned.h>
38#include <linux/platform_device.h> 39#include <linux/platform_device.h>
39#include <linux/workqueue.h> 40#include <linux/workqueue.h>
40 41
@@ -131,8 +132,8 @@ static const u8 usb2_rh_dev_descriptor [18] = {
131 0x01, /* __u8 bDeviceProtocol; [ usb 2.0 single TT ]*/ 132 0x01, /* __u8 bDeviceProtocol; [ usb 2.0 single TT ]*/
132 0x40, /* __u8 bMaxPacketSize0; 64 Bytes */ 133 0x40, /* __u8 bMaxPacketSize0; 64 Bytes */
133 134
134 0x00, 0x00, /* __le16 idVendor; */ 135 0x6b, 0x1d, /* __le16 idVendor; Linux Foundation */
135 0x00, 0x00, /* __le16 idProduct; */ 136 0x02, 0x00, /* __le16 idProduct; device 0x0002 */
136 KERNEL_VER, KERNEL_REL, /* __le16 bcdDevice */ 137 KERNEL_VER, KERNEL_REL, /* __le16 bcdDevice */
137 138
138 0x03, /* __u8 iManufacturer; */ 139 0x03, /* __u8 iManufacturer; */
@@ -154,8 +155,8 @@ static const u8 usb11_rh_dev_descriptor [18] = {
154 0x00, /* __u8 bDeviceProtocol; [ low/full speeds only ] */ 155 0x00, /* __u8 bDeviceProtocol; [ low/full speeds only ] */
155 0x40, /* __u8 bMaxPacketSize0; 64 Bytes */ 156 0x40, /* __u8 bMaxPacketSize0; 64 Bytes */
156 157
157 0x00, 0x00, /* __le16 idVendor; */ 158 0x6b, 0x1d, /* __le16 idVendor; Linux Foundation */
158 0x00, 0x00, /* __le16 idProduct; */ 159 0x01, 0x00, /* __le16 idProduct; device 0x0001 */
159 KERNEL_VER, KERNEL_REL, /* __le16 bcdDevice */ 160 KERNEL_VER, KERNEL_REL, /* __le16 bcdDevice */
160 161
161 0x03, /* __u8 iManufacturer; */ 162 0x03, /* __u8 iManufacturer; */
@@ -807,13 +808,13 @@ static int usb_register_bus(struct usb_bus *bus)
807 } 808 }
808 set_bit (busnum, busmap.busmap); 809 set_bit (busnum, busmap.busmap);
809 bus->busnum = busnum; 810 bus->busnum = busnum;
810 bus->class_dev = class_device_create(usb_host_class, NULL, MKDEV(0,0), 811
811 bus->controller, "usb_host%d", 812 bus->dev = device_create(usb_host_class, bus->controller, MKDEV(0, 0),
812 busnum); 813 "usb_host%d", busnum);
813 result = PTR_ERR(bus->class_dev); 814 result = PTR_ERR(bus->dev);
814 if (IS_ERR(bus->class_dev)) 815 if (IS_ERR(bus->dev))
815 goto error_create_class_dev; 816 goto error_create_class_dev;
816 class_set_devdata(bus->class_dev, bus); 817 dev_set_drvdata(bus->dev, bus);
817 818
818 /* Add it to the local list of buses */ 819 /* Add it to the local list of buses */
819 list_add (&bus->bus_list, &usb_bus_list); 820 list_add (&bus->bus_list, &usb_bus_list);
@@ -857,7 +858,7 @@ static void usb_deregister_bus (struct usb_bus *bus)
857 858
858 clear_bit (bus->busnum, busmap.busmap); 859 clear_bit (bus->busnum, busmap.busmap);
859 860
860 class_device_unregister(bus->class_dev); 861 device_unregister(bus->dev);
861} 862}
862 863
863/** 864/**
@@ -970,7 +971,7 @@ long usb_calc_bus_time (int speed, int is_input, int isoc, int bytecount)
970 return -1; 971 return -1;
971 } 972 }
972} 973}
973EXPORT_SYMBOL (usb_calc_bus_time); 974EXPORT_SYMBOL_GPL(usb_calc_bus_time);
974 975
975 976
976/*-------------------------------------------------------------------------*/ 977/*-------------------------------------------------------------------------*/
@@ -1112,48 +1113,177 @@ void usb_hcd_unlink_urb_from_ep(struct usb_hcd *hcd, struct urb *urb)
1112} 1113}
1113EXPORT_SYMBOL_GPL(usb_hcd_unlink_urb_from_ep); 1114EXPORT_SYMBOL_GPL(usb_hcd_unlink_urb_from_ep);
1114 1115
1115static void map_urb_for_dma(struct usb_hcd *hcd, struct urb *urb) 1116/*
1117 * Some usb host controllers can only perform dma using a small SRAM area.
1118 * The usb core itself is however optimized for host controllers that can dma
1119 * using regular system memory - like pci devices doing bus mastering.
1120 *
1121 * To support host controllers with limited dma capabilites we provide dma
1122 * bounce buffers. This feature can be enabled using the HCD_LOCAL_MEM flag.
1123 * For this to work properly the host controller code must first use the
1124 * function dma_declare_coherent_memory() to point out which memory area
1125 * that should be used for dma allocations.
1126 *
1127 * The HCD_LOCAL_MEM flag then tells the usb code to allocate all data for
1128 * dma using dma_alloc_coherent() which in turn allocates from the memory
1129 * area pointed out with dma_declare_coherent_memory().
1130 *
1131 * So, to summarize...
1132 *
1133 * - We need "local" memory, canonical example being
1134 * a small SRAM on a discrete controller being the
1135 * only memory that the controller can read ...
1136 * (a) "normal" kernel memory is no good, and
1137 * (b) there's not enough to share
1138 *
1139 * - The only *portable* hook for such stuff in the
1140 * DMA framework is dma_declare_coherent_memory()
1141 *
1142 * - So we use that, even though the primary requirement
1143 * is that the memory be "local" (hence addressible
1144 * by that device), not "coherent".
1145 *
1146 */
1147
1148static int hcd_alloc_coherent(struct usb_bus *bus,
1149 gfp_t mem_flags, dma_addr_t *dma_handle,
1150 void **vaddr_handle, size_t size,
1151 enum dma_data_direction dir)
1152{
1153 unsigned char *vaddr;
1154
1155 vaddr = hcd_buffer_alloc(bus, size + sizeof(vaddr),
1156 mem_flags, dma_handle);
1157 if (!vaddr)
1158 return -ENOMEM;
1159
1160 /*
1161 * Store the virtual address of the buffer at the end
1162 * of the allocated dma buffer. The size of the buffer
1163 * may be uneven so use unaligned functions instead
1164 * of just rounding up. It makes sense to optimize for
1165 * memory footprint over access speed since the amount
1166 * of memory available for dma may be limited.
1167 */
1168 put_unaligned((unsigned long)*vaddr_handle,
1169 (unsigned long *)(vaddr + size));
1170
1171 if (dir == DMA_TO_DEVICE)
1172 memcpy(vaddr, *vaddr_handle, size);
1173
1174 *vaddr_handle = vaddr;
1175 return 0;
1176}
1177
1178static void hcd_free_coherent(struct usb_bus *bus, dma_addr_t *dma_handle,
1179 void **vaddr_handle, size_t size,
1180 enum dma_data_direction dir)
1181{
1182 unsigned char *vaddr = *vaddr_handle;
1183
1184 vaddr = (void *)get_unaligned((unsigned long *)(vaddr + size));
1185
1186 if (dir == DMA_FROM_DEVICE)
1187 memcpy(vaddr, *vaddr_handle, size);
1188
1189 hcd_buffer_free(bus, size + sizeof(vaddr), *vaddr_handle, *dma_handle);
1190
1191 *vaddr_handle = vaddr;
1192 *dma_handle = 0;
1193}
1194
1195static int map_urb_for_dma(struct usb_hcd *hcd, struct urb *urb,
1196 gfp_t mem_flags)
1116{ 1197{
1198 enum dma_data_direction dir;
1199 int ret = 0;
1200
1117 /* Map the URB's buffers for DMA access. 1201 /* Map the URB's buffers for DMA access.
1118 * Lower level HCD code should use *_dma exclusively, 1202 * Lower level HCD code should use *_dma exclusively,
1119 * unless it uses pio or talks to another transport. 1203 * unless it uses pio or talks to another transport.
1120 */ 1204 */
1121 if (hcd->self.uses_dma && !is_root_hub(urb->dev)) { 1205 if (is_root_hub(urb->dev))
1122 if (usb_endpoint_xfer_control(&urb->ep->desc) 1206 return 0;
1123 && !(urb->transfer_flags & URB_NO_SETUP_DMA_MAP)) 1207
1124 urb->setup_dma = dma_map_single ( 1208 if (usb_endpoint_xfer_control(&urb->ep->desc)
1209 && !(urb->transfer_flags & URB_NO_SETUP_DMA_MAP)) {
1210 if (hcd->self.uses_dma)
1211 urb->setup_dma = dma_map_single(
1125 hcd->self.controller, 1212 hcd->self.controller,
1126 urb->setup_packet, 1213 urb->setup_packet,
1127 sizeof (struct usb_ctrlrequest), 1214 sizeof(struct usb_ctrlrequest),
1215 DMA_TO_DEVICE);
1216 else if (hcd->driver->flags & HCD_LOCAL_MEM)
1217 ret = hcd_alloc_coherent(
1218 urb->dev->bus, mem_flags,
1219 &urb->setup_dma,
1220 (void **)&urb->setup_packet,
1221 sizeof(struct usb_ctrlrequest),
1128 DMA_TO_DEVICE); 1222 DMA_TO_DEVICE);
1129 if (urb->transfer_buffer_length != 0 1223 }
1130 && !(urb->transfer_flags & URB_NO_TRANSFER_DMA_MAP)) 1224
1225 dir = usb_urb_dir_in(urb) ? DMA_FROM_DEVICE : DMA_TO_DEVICE;
1226 if (ret == 0 && urb->transfer_buffer_length != 0
1227 && !(urb->transfer_flags & URB_NO_TRANSFER_DMA_MAP)) {
1228 if (hcd->self.uses_dma)
1131 urb->transfer_dma = dma_map_single ( 1229 urb->transfer_dma = dma_map_single (
1132 hcd->self.controller, 1230 hcd->self.controller,
1133 urb->transfer_buffer, 1231 urb->transfer_buffer,
1134 urb->transfer_buffer_length, 1232 urb->transfer_buffer_length,
1135 usb_urb_dir_in(urb) 1233 dir);
1136 ? DMA_FROM_DEVICE 1234 else if (hcd->driver->flags & HCD_LOCAL_MEM) {
1137 : DMA_TO_DEVICE); 1235 ret = hcd_alloc_coherent(
1236 urb->dev->bus, mem_flags,
1237 &urb->transfer_dma,
1238 &urb->transfer_buffer,
1239 urb->transfer_buffer_length,
1240 dir);
1241
1242 if (ret && usb_endpoint_xfer_control(&urb->ep->desc)
1243 && !(urb->transfer_flags & URB_NO_SETUP_DMA_MAP))
1244 hcd_free_coherent(urb->dev->bus,
1245 &urb->setup_dma,
1246 (void **)&urb->setup_packet,
1247 sizeof(struct usb_ctrlrequest),
1248 DMA_TO_DEVICE);
1249 }
1138 } 1250 }
1251 return ret;
1139} 1252}
1140 1253
1141static void unmap_urb_for_dma(struct usb_hcd *hcd, struct urb *urb) 1254static void unmap_urb_for_dma(struct usb_hcd *hcd, struct urb *urb)
1142{ 1255{
1143 if (hcd->self.uses_dma && !is_root_hub(urb->dev)) { 1256 enum dma_data_direction dir;
1144 if (usb_endpoint_xfer_control(&urb->ep->desc) 1257
1145 && !(urb->transfer_flags & URB_NO_SETUP_DMA_MAP)) 1258 if (is_root_hub(urb->dev))
1259 return;
1260
1261 if (usb_endpoint_xfer_control(&urb->ep->desc)
1262 && !(urb->transfer_flags & URB_NO_SETUP_DMA_MAP)) {
1263 if (hcd->self.uses_dma)
1146 dma_unmap_single(hcd->self.controller, urb->setup_dma, 1264 dma_unmap_single(hcd->self.controller, urb->setup_dma,
1147 sizeof(struct usb_ctrlrequest), 1265 sizeof(struct usb_ctrlrequest),
1148 DMA_TO_DEVICE); 1266 DMA_TO_DEVICE);
1149 if (urb->transfer_buffer_length != 0 1267 else if (hcd->driver->flags & HCD_LOCAL_MEM)
1150 && !(urb->transfer_flags & URB_NO_TRANSFER_DMA_MAP)) 1268 hcd_free_coherent(urb->dev->bus, &urb->setup_dma,
1269 (void **)&urb->setup_packet,
1270 sizeof(struct usb_ctrlrequest),
1271 DMA_TO_DEVICE);
1272 }
1273
1274 dir = usb_urb_dir_in(urb) ? DMA_FROM_DEVICE : DMA_TO_DEVICE;
1275 if (urb->transfer_buffer_length != 0
1276 && !(urb->transfer_flags & URB_NO_TRANSFER_DMA_MAP)) {
1277 if (hcd->self.uses_dma)
1151 dma_unmap_single(hcd->self.controller, 1278 dma_unmap_single(hcd->self.controller,
1152 urb->transfer_dma, 1279 urb->transfer_dma,
1153 urb->transfer_buffer_length, 1280 urb->transfer_buffer_length,
1154 usb_urb_dir_in(urb) 1281 dir);
1155 ? DMA_FROM_DEVICE 1282 else if (hcd->driver->flags & HCD_LOCAL_MEM)
1156 : DMA_TO_DEVICE); 1283 hcd_free_coherent(urb->dev->bus, &urb->transfer_dma,
1284 &urb->transfer_buffer,
1285 urb->transfer_buffer_length,
1286 dir);
1157 } 1287 }
1158} 1288}
1159 1289
@@ -1185,7 +1315,12 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
1185 * URBs must be submitted in process context with interrupts 1315 * URBs must be submitted in process context with interrupts
1186 * enabled. 1316 * enabled.
1187 */ 1317 */
1188 map_urb_for_dma(hcd, urb); 1318 status = map_urb_for_dma(hcd, urb, mem_flags);
1319 if (unlikely(status)) {
1320 usbmon_urb_submit_error(&hcd->self, urb, status);
1321 goto error;
1322 }
1323
1189 if (is_root_hub(urb->dev)) 1324 if (is_root_hub(urb->dev))
1190 status = rh_urb_enqueue(hcd, urb); 1325 status = rh_urb_enqueue(hcd, urb);
1191 else 1326 else
@@ -1194,6 +1329,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
1194 if (unlikely(status)) { 1329 if (unlikely(status)) {
1195 usbmon_urb_submit_error(&hcd->self, urb, status); 1330 usbmon_urb_submit_error(&hcd->self, urb, status);
1196 unmap_urb_for_dma(hcd, urb); 1331 unmap_urb_for_dma(hcd, urb);
1332 error:
1197 urb->hcpriv = NULL; 1333 urb->hcpriv = NULL;
1198 INIT_LIST_HEAD(&urb->urb_list); 1334 INIT_LIST_HEAD(&urb->urb_list);
1199 atomic_dec(&urb->use_count); 1335 atomic_dec(&urb->use_count);
@@ -1291,7 +1427,7 @@ void usb_hcd_giveback_urb(struct usb_hcd *hcd, struct urb *urb, int status)
1291 wake_up (&usb_kill_urb_queue); 1427 wake_up (&usb_kill_urb_queue);
1292 usb_put_urb (urb); 1428 usb_put_urb (urb);
1293} 1429}
1294EXPORT_SYMBOL (usb_hcd_giveback_urb); 1430EXPORT_SYMBOL_GPL(usb_hcd_giveback_urb);
1295 1431
1296/*-------------------------------------------------------------------------*/ 1432/*-------------------------------------------------------------------------*/
1297 1433
@@ -1531,7 +1667,7 @@ int usb_bus_start_enum(struct usb_bus *bus, unsigned port_num)
1531 mod_timer(&hcd->rh_timer, jiffies + msecs_to_jiffies(10)); 1667 mod_timer(&hcd->rh_timer, jiffies + msecs_to_jiffies(10));
1532 return status; 1668 return status;
1533} 1669}
1534EXPORT_SYMBOL (usb_bus_start_enum); 1670EXPORT_SYMBOL_GPL(usb_bus_start_enum);
1535 1671
1536#endif 1672#endif
1537 1673
@@ -1638,7 +1774,7 @@ struct usb_hcd *usb_create_hcd (const struct hc_driver *driver,
1638 "USB Host Controller"; 1774 "USB Host Controller";
1639 return hcd; 1775 return hcd;
1640} 1776}
1641EXPORT_SYMBOL (usb_create_hcd); 1777EXPORT_SYMBOL_GPL(usb_create_hcd);
1642 1778
1643static void hcd_release (struct kref *kref) 1779static void hcd_release (struct kref *kref)
1644{ 1780{
@@ -1653,14 +1789,14 @@ struct usb_hcd *usb_get_hcd (struct usb_hcd *hcd)
1653 kref_get (&hcd->kref); 1789 kref_get (&hcd->kref);
1654 return hcd; 1790 return hcd;
1655} 1791}
1656EXPORT_SYMBOL (usb_get_hcd); 1792EXPORT_SYMBOL_GPL(usb_get_hcd);
1657 1793
1658void usb_put_hcd (struct usb_hcd *hcd) 1794void usb_put_hcd (struct usb_hcd *hcd)
1659{ 1795{
1660 if (hcd) 1796 if (hcd)
1661 kref_put (&hcd->kref, hcd_release); 1797 kref_put (&hcd->kref, hcd_release);
1662} 1798}
1663EXPORT_SYMBOL (usb_put_hcd); 1799EXPORT_SYMBOL_GPL(usb_put_hcd);
1664 1800
1665/** 1801/**
1666 * usb_add_hcd - finish generic HCD structure initialization and register 1802 * usb_add_hcd - finish generic HCD structure initialization and register
@@ -1786,7 +1922,7 @@ err_register_bus:
1786 hcd_buffer_destroy(hcd); 1922 hcd_buffer_destroy(hcd);
1787 return retval; 1923 return retval;
1788} 1924}
1789EXPORT_SYMBOL (usb_add_hcd); 1925EXPORT_SYMBOL_GPL(usb_add_hcd);
1790 1926
1791/** 1927/**
1792 * usb_remove_hcd - shutdown processing for generic HCDs 1928 * usb_remove_hcd - shutdown processing for generic HCDs
@@ -1828,7 +1964,7 @@ void usb_remove_hcd(struct usb_hcd *hcd)
1828 usb_deregister_bus(&hcd->self); 1964 usb_deregister_bus(&hcd->self);
1829 hcd_buffer_destroy(hcd); 1965 hcd_buffer_destroy(hcd);
1830} 1966}
1831EXPORT_SYMBOL (usb_remove_hcd); 1967EXPORT_SYMBOL_GPL(usb_remove_hcd);
1832 1968
1833void 1969void
1834usb_hcd_platform_shutdown(struct platform_device* dev) 1970usb_hcd_platform_shutdown(struct platform_device* dev)
@@ -1838,7 +1974,7 @@ usb_hcd_platform_shutdown(struct platform_device* dev)
1838 if (hcd->driver->shutdown) 1974 if (hcd->driver->shutdown)
1839 hcd->driver->shutdown(hcd); 1975 hcd->driver->shutdown(hcd);
1840} 1976}
1841EXPORT_SYMBOL (usb_hcd_platform_shutdown); 1977EXPORT_SYMBOL_GPL(usb_hcd_platform_shutdown);
1842 1978
1843/*-------------------------------------------------------------------------*/ 1979/*-------------------------------------------------------------------------*/
1844 1980
diff --git a/drivers/usb/core/hcd.h b/drivers/usb/core/hcd.h
index 98e24194a4ab..2d1c3d5e47b8 100644
--- a/drivers/usb/core/hcd.h
+++ b/drivers/usb/core/hcd.h
@@ -125,7 +125,7 @@ struct usb_hcd {
125 125
126 /* more shared queuing code would be good; it should support 126 /* more shared queuing code would be good; it should support
127 * smarter scheduling, handle transaction translators, etc; 127 * smarter scheduling, handle transaction translators, etc;
128 * input size of periodic table to an interrupt scheduler. 128 * input size of periodic table to an interrupt scheduler.
129 * (ohci 32, uhci 1024, ehci 256/512/1024). 129 * (ohci 32, uhci 1024, ehci 256/512/1024).
130 */ 130 */
131 131
@@ -133,16 +133,16 @@ struct usb_hcd {
133 * this structure. 133 * this structure.
134 */ 134 */
135 unsigned long hcd_priv[0] 135 unsigned long hcd_priv[0]
136 __attribute__ ((aligned (sizeof(unsigned long)))); 136 __attribute__ ((aligned(sizeof(unsigned long))));
137}; 137};
138 138
139/* 2.4 does this a bit differently ... */ 139/* 2.4 does this a bit differently ... */
140static inline struct usb_bus *hcd_to_bus (struct usb_hcd *hcd) 140static inline struct usb_bus *hcd_to_bus(struct usb_hcd *hcd)
141{ 141{
142 return &hcd->self; 142 return &hcd->self;
143} 143}
144 144
145static inline struct usb_hcd *bus_to_hcd (struct usb_bus *bus) 145static inline struct usb_hcd *bus_to_hcd(struct usb_bus *bus)
146{ 146{
147 return container_of(bus, struct usb_hcd, self); 147 return container_of(bus, struct usb_hcd, self);
148} 148}
@@ -165,6 +165,7 @@ struct hc_driver {
165 165
166 int flags; 166 int flags;
167#define HCD_MEMORY 0x0001 /* HC regs use memory (else I/O) */ 167#define HCD_MEMORY 0x0001 /* HC regs use memory (else I/O) */
168#define HCD_LOCAL_MEM 0x0002 /* HC needs local memory */
168#define HCD_USB11 0x0010 /* USB 1.1 */ 169#define HCD_USB11 0x0010 /* USB 1.1 */
169#define HCD_USB2 0x0020 /* USB 2.0 */ 170#define HCD_USB2 0x0020 /* USB 2.0 */
170 171
@@ -201,15 +202,18 @@ struct hc_driver {
201 struct usb_host_endpoint *ep); 202 struct usb_host_endpoint *ep);
202 203
203 /* root hub support */ 204 /* root hub support */
204 int (*hub_status_data) (struct usb_hcd *hcd, char *buf); 205 int (*hub_status_data) (struct usb_hcd *hcd, char *buf);
205 int (*hub_control) (struct usb_hcd *hcd, 206 int (*hub_control) (struct usb_hcd *hcd,
206 u16 typeReq, u16 wValue, u16 wIndex, 207 u16 typeReq, u16 wValue, u16 wIndex,
207 char *buf, u16 wLength); 208 char *buf, u16 wLength);
208 int (*bus_suspend)(struct usb_hcd *); 209 int (*bus_suspend)(struct usb_hcd *);
209 int (*bus_resume)(struct usb_hcd *); 210 int (*bus_resume)(struct usb_hcd *);
210 int (*start_port_reset)(struct usb_hcd *, unsigned port_num); 211 int (*start_port_reset)(struct usb_hcd *, unsigned port_num);
211 void (*hub_irq_enable)(struct usb_hcd *); 212 void (*hub_irq_enable)(struct usb_hcd *);
212 /* Needed only if port-change IRQs are level-triggered */ 213 /* Needed only if port-change IRQs are level-triggered */
214
215 /* force handover of high-speed port to full-speed companion */
216 void (*relinquish_port)(struct usb_hcd *, int);
213}; 217};
214 218
215extern int usb_hcd_link_urb_to_ep(struct usb_hcd *hcd, struct urb *urb); 219extern int usb_hcd_link_urb_to_ep(struct usb_hcd *hcd, struct urb *urb);
@@ -217,56 +221,56 @@ extern int usb_hcd_check_unlink_urb(struct usb_hcd *hcd, struct urb *urb,
217 int status); 221 int status);
218extern void usb_hcd_unlink_urb_from_ep(struct usb_hcd *hcd, struct urb *urb); 222extern void usb_hcd_unlink_urb_from_ep(struct usb_hcd *hcd, struct urb *urb);
219 223
220extern int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags); 224extern int usb_hcd_submit_urb(struct urb *urb, gfp_t mem_flags);
221extern int usb_hcd_unlink_urb (struct urb *urb, int status); 225extern int usb_hcd_unlink_urb(struct urb *urb, int status);
222extern void usb_hcd_giveback_urb(struct usb_hcd *hcd, struct urb *urb, 226extern void usb_hcd_giveback_urb(struct usb_hcd *hcd, struct urb *urb,
223 int status); 227 int status);
224extern void usb_hcd_flush_endpoint(struct usb_device *udev, 228extern void usb_hcd_flush_endpoint(struct usb_device *udev,
225 struct usb_host_endpoint *ep); 229 struct usb_host_endpoint *ep);
226extern void usb_hcd_disable_endpoint(struct usb_device *udev, 230extern void usb_hcd_disable_endpoint(struct usb_device *udev,
227 struct usb_host_endpoint *ep); 231 struct usb_host_endpoint *ep);
228extern int usb_hcd_get_frame_number (struct usb_device *udev); 232extern int usb_hcd_get_frame_number(struct usb_device *udev);
229 233
230extern struct usb_hcd *usb_create_hcd (const struct hc_driver *driver, 234extern struct usb_hcd *usb_create_hcd(const struct hc_driver *driver,
231 struct device *dev, char *bus_name); 235 struct device *dev, char *bus_name);
232extern struct usb_hcd *usb_get_hcd (struct usb_hcd *hcd); 236extern struct usb_hcd *usb_get_hcd(struct usb_hcd *hcd);
233extern void usb_put_hcd (struct usb_hcd *hcd); 237extern void usb_put_hcd(struct usb_hcd *hcd);
234extern int usb_add_hcd(struct usb_hcd *hcd, 238extern int usb_add_hcd(struct usb_hcd *hcd,
235 unsigned int irqnum, unsigned long irqflags); 239 unsigned int irqnum, unsigned long irqflags);
236extern void usb_remove_hcd(struct usb_hcd *hcd); 240extern void usb_remove_hcd(struct usb_hcd *hcd);
237 241
238struct platform_device; 242struct platform_device;
239extern void usb_hcd_platform_shutdown(struct platform_device* dev); 243extern void usb_hcd_platform_shutdown(struct platform_device *dev);
240 244
241#ifdef CONFIG_PCI 245#ifdef CONFIG_PCI
242struct pci_dev; 246struct pci_dev;
243struct pci_device_id; 247struct pci_device_id;
244extern int usb_hcd_pci_probe (struct pci_dev *dev, 248extern int usb_hcd_pci_probe(struct pci_dev *dev,
245 const struct pci_device_id *id); 249 const struct pci_device_id *id);
246extern void usb_hcd_pci_remove (struct pci_dev *dev); 250extern void usb_hcd_pci_remove(struct pci_dev *dev);
247 251
248#ifdef CONFIG_PM 252#ifdef CONFIG_PM
249extern int usb_hcd_pci_suspend (struct pci_dev *dev, pm_message_t state); 253extern int usb_hcd_pci_suspend(struct pci_dev *dev, pm_message_t state);
250extern int usb_hcd_pci_resume (struct pci_dev *dev); 254extern int usb_hcd_pci_resume(struct pci_dev *dev);
251#endif /* CONFIG_PM */ 255#endif /* CONFIG_PM */
252 256
253extern void usb_hcd_pci_shutdown (struct pci_dev *dev); 257extern void usb_hcd_pci_shutdown(struct pci_dev *dev);
254 258
255#endif /* CONFIG_PCI */ 259#endif /* CONFIG_PCI */
256 260
257/* pci-ish (pdev null is ok) buffer alloc/mapping support */ 261/* pci-ish (pdev null is ok) buffer alloc/mapping support */
258int hcd_buffer_create (struct usb_hcd *hcd); 262int hcd_buffer_create(struct usb_hcd *hcd);
259void hcd_buffer_destroy (struct usb_hcd *hcd); 263void hcd_buffer_destroy(struct usb_hcd *hcd);
260 264
261void *hcd_buffer_alloc (struct usb_bus *bus, size_t size, 265void *hcd_buffer_alloc(struct usb_bus *bus, size_t size,
262 gfp_t mem_flags, dma_addr_t *dma); 266 gfp_t mem_flags, dma_addr_t *dma);
263void hcd_buffer_free (struct usb_bus *bus, size_t size, 267void hcd_buffer_free(struct usb_bus *bus, size_t size,
264 void *addr, dma_addr_t dma); 268 void *addr, dma_addr_t dma);
265 269
266/* generic bus glue, needed for host controllers that don't use PCI */ 270/* generic bus glue, needed for host controllers that don't use PCI */
267extern irqreturn_t usb_hcd_irq (int irq, void *__hcd); 271extern irqreturn_t usb_hcd_irq(int irq, void *__hcd);
268 272
269extern void usb_hc_died (struct usb_hcd *hcd); 273extern void usb_hc_died(struct usb_hcd *hcd);
270extern void usb_hcd_poll_rh_status(struct usb_hcd *hcd); 274extern void usb_hcd_poll_rh_status(struct usb_hcd *hcd);
271 275
272/* -------------------------------------------------------------------------- */ 276/* -------------------------------------------------------------------------- */
@@ -319,9 +323,9 @@ extern void usb_destroy_configuration(struct usb_device *dev);
319 * Generic bandwidth allocation constants/support 323 * Generic bandwidth allocation constants/support
320 */ 324 */
321#define FRAME_TIME_USECS 1000L 325#define FRAME_TIME_USECS 1000L
322#define BitTime(bytecount) (7 * 8 * bytecount / 6) /* with integer truncation */ 326#define BitTime(bytecount) (7 * 8 * bytecount / 6) /* with integer truncation */
323 /* Trying not to use worst-case bit-stuffing 327 /* Trying not to use worst-case bit-stuffing
324 of (7/6 * 8 * bytecount) = 9.33 * bytecount */ 328 * of (7/6 * 8 * bytecount) = 9.33 * bytecount */
325 /* bytecount = data payload byte count */ 329 /* bytecount = data payload byte count */
326 330
327#define NS_TO_US(ns) ((ns + 500L) / 1000L) 331#define NS_TO_US(ns) ((ns + 500L) / 1000L)
@@ -333,9 +337,9 @@ extern void usb_destroy_configuration(struct usb_device *dev);
333 */ 337 */
334#define BW_HOST_DELAY 1000L /* nanoseconds */ 338#define BW_HOST_DELAY 1000L /* nanoseconds */
335#define BW_HUB_LS_SETUP 333L /* nanoseconds */ 339#define BW_HUB_LS_SETUP 333L /* nanoseconds */
336 /* 4 full-speed bit times (est.) */ 340 /* 4 full-speed bit times (est.) */
337 341
338#define FRAME_TIME_BITS 12000L /* frame = 1 millisecond */ 342#define FRAME_TIME_BITS 12000L /* frame = 1 millisecond */
339#define FRAME_TIME_MAX_BITS_ALLOC (90L * FRAME_TIME_BITS / 100L) 343#define FRAME_TIME_MAX_BITS_ALLOC (90L * FRAME_TIME_BITS / 100L)
340#define FRAME_TIME_MAX_USECS_ALLOC (90L * FRAME_TIME_USECS / 100L) 344#define FRAME_TIME_MAX_USECS_ALLOC (90L * FRAME_TIME_USECS / 100L)
341 345
@@ -345,16 +349,16 @@ extern void usb_destroy_configuration(struct usb_device *dev);
345 * to preallocate bandwidth) 349 * to preallocate bandwidth)
346 */ 350 */
347#define USB2_HOST_DELAY 5 /* nsec, guess */ 351#define USB2_HOST_DELAY 5 /* nsec, guess */
348#define HS_NSECS(bytes) ( ((55 * 8 * 2083) \ 352#define HS_NSECS(bytes) (((55 * 8 * 2083) \
349 + (2083UL * (3 + BitTime(bytes))))/1000 \ 353 + (2083UL * (3 + BitTime(bytes))))/1000 \
350 + USB2_HOST_DELAY) 354 + USB2_HOST_DELAY)
351#define HS_NSECS_ISO(bytes) ( ((38 * 8 * 2083) \ 355#define HS_NSECS_ISO(bytes) (((38 * 8 * 2083) \
352 + (2083UL * (3 + BitTime(bytes))))/1000 \ 356 + (2083UL * (3 + BitTime(bytes))))/1000 \
353 + USB2_HOST_DELAY) 357 + USB2_HOST_DELAY)
354#define HS_USECS(bytes) NS_TO_US (HS_NSECS(bytes)) 358#define HS_USECS(bytes) NS_TO_US (HS_NSECS(bytes))
355#define HS_USECS_ISO(bytes) NS_TO_US (HS_NSECS_ISO(bytes)) 359#define HS_USECS_ISO(bytes) NS_TO_US (HS_NSECS_ISO(bytes))
356 360
357extern long usb_calc_bus_time (int speed, int is_input, 361extern long usb_calc_bus_time(int speed, int is_input,
358 int isoc, int bytecount); 362 int isoc, int bytecount);
359 363
360/*-------------------------------------------------------------------------*/ 364/*-------------------------------------------------------------------------*/
@@ -370,16 +374,16 @@ extern struct list_head usb_bus_list;
370extern struct mutex usb_bus_list_lock; 374extern struct mutex usb_bus_list_lock;
371extern wait_queue_head_t usb_kill_urb_queue; 375extern wait_queue_head_t usb_kill_urb_queue;
372 376
373extern void usb_enable_root_hub_irq (struct usb_bus *bus); 377extern void usb_enable_root_hub_irq(struct usb_bus *bus);
374 378
375extern int usb_find_interface_driver (struct usb_device *dev, 379extern int usb_find_interface_driver(struct usb_device *dev,
376 struct usb_interface *interface); 380 struct usb_interface *interface);
377 381
378#define usb_endpoint_out(ep_dir) (!((ep_dir) & USB_DIR_IN)) 382#define usb_endpoint_out(ep_dir) (!((ep_dir) & USB_DIR_IN))
379 383
380#ifdef CONFIG_PM 384#ifdef CONFIG_PM
381extern void usb_hcd_resume_root_hub (struct usb_hcd *hcd); 385extern void usb_hcd_resume_root_hub(struct usb_hcd *hcd);
382extern void usb_root_hub_lost_power (struct usb_device *rhdev); 386extern void usb_root_hub_lost_power(struct usb_device *rhdev);
383extern int hcd_bus_suspend(struct usb_device *rhdev); 387extern int hcd_bus_suspend(struct usb_device *rhdev);
384extern int hcd_bus_resume(struct usb_device *rhdev); 388extern int hcd_bus_resume(struct usb_device *rhdev);
385#else 389#else
@@ -399,13 +403,13 @@ static inline void usb_hcd_resume_root_hub(struct usb_hcd *hcd)
399 * these are expected to be called from the USB core/hub thread 403 * these are expected to be called from the USB core/hub thread
400 * with the kernel lock held 404 * with the kernel lock held
401 */ 405 */
402extern void usbfs_update_special (void); 406extern void usbfs_update_special(void);
403extern int usbfs_init(void); 407extern int usbfs_init(void);
404extern void usbfs_cleanup(void); 408extern void usbfs_cleanup(void);
405 409
406#else /* CONFIG_USB_DEVICEFS */ 410#else /* CONFIG_USB_DEVICEFS */
407 411
408static inline void usbfs_update_special (void) {} 412static inline void usbfs_update_special(void) {}
409static inline int usbfs_init(void) { return 0; } 413static inline int usbfs_init(void) { return 0; }
410static inline void usbfs_cleanup(void) { } 414static inline void usbfs_cleanup(void) { }
411 415
@@ -460,7 +464,7 @@ static inline void usbmon_urb_complete(struct usb_bus *bus, struct urb *urb,
460/*-------------------------------------------------------------------------*/ 464/*-------------------------------------------------------------------------*/
461 465
462/* hub.h ... DeviceRemovable in 2.4.2-ac11, gone in 2.4.10 */ 466/* hub.h ... DeviceRemovable in 2.4.2-ac11, gone in 2.4.10 */
463// bleech -- resurfaced in 2.4.11 or 2.4.12 467/* bleech -- resurfaced in 2.4.11 or 2.4.12 */
464#define bitmap DeviceRemovable 468#define bitmap DeviceRemovable
465 469
466 470
@@ -468,8 +472,8 @@ static inline void usbmon_urb_complete(struct usb_bus *bus, struct urb *urb,
468 472
469/* random stuff */ 473/* random stuff */
470 474
471#define RUN_CONTEXT (in_irq () ? "in_irq" \ 475#define RUN_CONTEXT (in_irq() ? "in_irq" \
472 : (in_interrupt () ? "in_interrupt" : "can sleep")) 476 : (in_interrupt() ? "in_interrupt" : "can sleep"))
473 477
474 478
475/* This rwsem is for use only by the hub driver and ehci-hcd. 479/* This rwsem is for use only by the hub driver and ehci-hcd.
diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
index b04d232d4c65..68fc5219ca15 100644
--- a/drivers/usb/core/hub.c
+++ b/drivers/usb/core/hub.c
@@ -37,6 +37,13 @@
37#define USB_PERSIST 0 37#define USB_PERSIST 0
38#endif 38#endif
39 39
40/* if we are in debug mode, always announce new devices */
41#ifdef DEBUG
42#ifndef CONFIG_USB_ANNOUNCE_NEW_DEVICES
43#define CONFIG_USB_ANNOUNCE_NEW_DEVICES
44#endif
45#endif
46
40struct usb_hub { 47struct usb_hub {
41 struct device *intfdev; /* the "interface" device */ 48 struct device *intfdev; /* the "interface" device */
42 struct usb_device *hdev; 49 struct usb_device *hdev;
@@ -487,6 +494,7 @@ void usb_hub_tt_clear_buffer (struct usb_device *udev, int pipe)
487 schedule_work (&tt->kevent); 494 schedule_work (&tt->kevent);
488 spin_unlock_irqrestore (&tt->lock, flags); 495 spin_unlock_irqrestore (&tt->lock, flags);
489} 496}
497EXPORT_SYMBOL_GPL(usb_hub_tt_clear_buffer);
490 498
491static void hub_power_on(struct usb_hub *hub) 499static void hub_power_on(struct usb_hub *hub)
492{ 500{
@@ -1027,8 +1035,10 @@ static void recursively_mark_NOTATTACHED(struct usb_device *udev)
1027 if (udev->children[i]) 1035 if (udev->children[i])
1028 recursively_mark_NOTATTACHED(udev->children[i]); 1036 recursively_mark_NOTATTACHED(udev->children[i]);
1029 } 1037 }
1030 if (udev->state == USB_STATE_SUSPENDED) 1038 if (udev->state == USB_STATE_SUSPENDED) {
1031 udev->discon_suspended = 1; 1039 udev->discon_suspended = 1;
1040 udev->active_duration -= jiffies;
1041 }
1032 udev->state = USB_STATE_NOTATTACHED; 1042 udev->state = USB_STATE_NOTATTACHED;
1033} 1043}
1034 1044
@@ -1077,6 +1087,12 @@ void usb_set_device_state(struct usb_device *udev,
1077 else 1087 else
1078 device_init_wakeup(&udev->dev, 0); 1088 device_init_wakeup(&udev->dev, 0);
1079 } 1089 }
1090 if (udev->state == USB_STATE_SUSPENDED &&
1091 new_state != USB_STATE_SUSPENDED)
1092 udev->active_duration -= jiffies;
1093 else if (new_state == USB_STATE_SUSPENDED &&
1094 udev->state != USB_STATE_SUSPENDED)
1095 udev->active_duration += jiffies;
1080 udev->state = new_state; 1096 udev->state = new_state;
1081 } else 1097 } else
1082 recursively_mark_NOTATTACHED(udev); 1098 recursively_mark_NOTATTACHED(udev);
@@ -1207,7 +1223,7 @@ void usb_disconnect(struct usb_device **pdev)
1207 put_device(&udev->dev); 1223 put_device(&udev->dev);
1208} 1224}
1209 1225
1210#ifdef DEBUG 1226#ifdef CONFIG_USB_ANNOUNCE_NEW_DEVICES
1211static void show_string(struct usb_device *udev, char *id, char *string) 1227static void show_string(struct usb_device *udev, char *id, char *string)
1212{ 1228{
1213 if (!string) 1229 if (!string)
@@ -1215,12 +1231,24 @@ static void show_string(struct usb_device *udev, char *id, char *string)
1215 dev_printk(KERN_INFO, &udev->dev, "%s: %s\n", id, string); 1231 dev_printk(KERN_INFO, &udev->dev, "%s: %s\n", id, string);
1216} 1232}
1217 1233
1234static void announce_device(struct usb_device *udev)
1235{
1236 dev_info(&udev->dev, "New USB device found, idVendor=%04x, idProduct=%04x\n",
1237 le16_to_cpu(udev->descriptor.idVendor),
1238 le16_to_cpu(udev->descriptor.idProduct));
1239 dev_info(&udev->dev, "New USB device strings: Mfr=%d, Product=%d, "
1240 "SerialNumber=%d\n",
1241 udev->descriptor.iManufacturer,
1242 udev->descriptor.iProduct,
1243 udev->descriptor.iSerialNumber);
1244 show_string(udev, "Product", udev->product);
1245 show_string(udev, "Manufacturer", udev->manufacturer);
1246 show_string(udev, "SerialNumber", udev->serial);
1247}
1218#else 1248#else
1219static inline void show_string(struct usb_device *udev, char *id, char *string) 1249static inline void announce_device(struct usb_device *udev) { }
1220{}
1221#endif 1250#endif
1222 1251
1223
1224#ifdef CONFIG_USB_OTG 1252#ifdef CONFIG_USB_OTG
1225#include "otg_whitelist.h" 1253#include "otg_whitelist.h"
1226#endif 1254#endif
@@ -1390,14 +1418,7 @@ int usb_new_device(struct usb_device *udev)
1390 } 1418 }
1391 1419
1392 /* Tell the world! */ 1420 /* Tell the world! */
1393 dev_dbg(&udev->dev, "new device strings: Mfr=%d, Product=%d, " 1421 announce_device(udev);
1394 "SerialNumber=%d\n",
1395 udev->descriptor.iManufacturer,
1396 udev->descriptor.iProduct,
1397 udev->descriptor.iSerialNumber);
1398 show_string(udev, "Product", udev->product);
1399 show_string(udev, "Manufacturer", udev->manufacturer);
1400 show_string(udev, "SerialNumber", udev->serial);
1401 return err; 1422 return err;
1402 1423
1403fail: 1424fail:
@@ -2482,6 +2503,7 @@ static void hub_port_connect_change(struct usb_hub *hub, int port1,
2482{ 2503{
2483 struct usb_device *hdev = hub->hdev; 2504 struct usb_device *hdev = hub->hdev;
2484 struct device *hub_dev = hub->intfdev; 2505 struct device *hub_dev = hub->intfdev;
2506 struct usb_hcd *hcd = bus_to_hcd(hdev->bus);
2485 u16 wHubCharacteristics = le16_to_cpu(hub->descriptor->wHubCharacteristics); 2507 u16 wHubCharacteristics = le16_to_cpu(hub->descriptor->wHubCharacteristics);
2486 int status, i; 2508 int status, i;
2487 2509
@@ -2645,6 +2667,8 @@ loop:
2645 2667
2646done: 2668done:
2647 hub_port_disable(hub, port1, 1); 2669 hub_port_disable(hub, port1, 1);
2670 if (hcd->driver->relinquish_port && !hub->hdev->parent)
2671 hcd->driver->relinquish_port(hcd, port1);
2648} 2672}
2649 2673
2650static void hub_events(void) 2674static void hub_events(void)
@@ -2946,7 +2970,7 @@ static int config_descriptors_changed(struct usb_device *udev)
2946 if (len < le16_to_cpu(udev->config[index].desc.wTotalLength)) 2970 if (len < le16_to_cpu(udev->config[index].desc.wTotalLength))
2947 len = le16_to_cpu(udev->config[index].desc.wTotalLength); 2971 len = le16_to_cpu(udev->config[index].desc.wTotalLength);
2948 } 2972 }
2949 buf = kmalloc (len, GFP_KERNEL); 2973 buf = kmalloc(len, GFP_NOIO);
2950 if (buf == NULL) { 2974 if (buf == NULL) {
2951 dev_err(&udev->dev, "no mem to re-read configs after reset\n"); 2975 dev_err(&udev->dev, "no mem to re-read configs after reset\n");
2952 /* assume the worst */ 2976 /* assume the worst */
@@ -3093,7 +3117,7 @@ re_enumerate:
3093 hub_port_logical_disconnect(parent_hub, port1); 3117 hub_port_logical_disconnect(parent_hub, port1);
3094 return -ENODEV; 3118 return -ENODEV;
3095} 3119}
3096EXPORT_SYMBOL(usb_reset_device); 3120EXPORT_SYMBOL_GPL(usb_reset_device);
3097 3121
3098/** 3122/**
3099 * usb_reset_composite_device - warn interface drivers and perform a USB port reset 3123 * usb_reset_composite_device - warn interface drivers and perform a USB port reset
@@ -3110,16 +3134,12 @@ EXPORT_SYMBOL(usb_reset_device);
3110 * this from a driver probe() routine after downloading new firmware. 3134 * this from a driver probe() routine after downloading new firmware.
3111 * For calls that might not occur during probe(), drivers should lock 3135 * For calls that might not occur during probe(), drivers should lock
3112 * the device using usb_lock_device_for_reset(). 3136 * the device using usb_lock_device_for_reset().
3113 *
3114 * The interface locks are acquired during the pre_reset stage and released
3115 * during the post_reset stage. However if iface is not NULL and is
3116 * currently being probed, we assume that the caller already owns its
3117 * lock.
3118 */ 3137 */
3119int usb_reset_composite_device(struct usb_device *udev, 3138int usb_reset_composite_device(struct usb_device *udev,
3120 struct usb_interface *iface) 3139 struct usb_interface *iface)
3121{ 3140{
3122 int ret; 3141 int ret;
3142 int i;
3123 struct usb_host_config *config = udev->actconfig; 3143 struct usb_host_config *config = udev->actconfig;
3124 3144
3125 if (udev->state == USB_STATE_NOTATTACHED || 3145 if (udev->state == USB_STATE_NOTATTACHED ||
@@ -3136,16 +3156,11 @@ int usb_reset_composite_device(struct usb_device *udev,
3136 iface = NULL; 3156 iface = NULL;
3137 3157
3138 if (config) { 3158 if (config) {
3139 int i;
3140 struct usb_interface *cintf;
3141 struct usb_driver *drv;
3142
3143 for (i = 0; i < config->desc.bNumInterfaces; ++i) { 3159 for (i = 0; i < config->desc.bNumInterfaces; ++i) {
3144 cintf = config->interface[i]; 3160 struct usb_interface *cintf = config->interface[i];
3145 if (cintf != iface) 3161 struct usb_driver *drv;
3146 down(&cintf->dev.sem); 3162
3147 if (device_is_registered(&cintf->dev) && 3163 if (cintf->dev.driver) {
3148 cintf->dev.driver) {
3149 drv = to_usb_driver(cintf->dev.driver); 3164 drv = to_usb_driver(cintf->dev.driver);
3150 if (drv->pre_reset) 3165 if (drv->pre_reset)
3151 (drv->pre_reset)(cintf); 3166 (drv->pre_reset)(cintf);
@@ -3157,25 +3172,20 @@ int usb_reset_composite_device(struct usb_device *udev,
3157 ret = usb_reset_device(udev); 3172 ret = usb_reset_device(udev);
3158 3173
3159 if (config) { 3174 if (config) {
3160 int i;
3161 struct usb_interface *cintf;
3162 struct usb_driver *drv;
3163
3164 for (i = config->desc.bNumInterfaces - 1; i >= 0; --i) { 3175 for (i = config->desc.bNumInterfaces - 1; i >= 0; --i) {
3165 cintf = config->interface[i]; 3176 struct usb_interface *cintf = config->interface[i];
3166 if (device_is_registered(&cintf->dev) && 3177 struct usb_driver *drv;
3167 cintf->dev.driver) { 3178
3179 if (cintf->dev.driver) {
3168 drv = to_usb_driver(cintf->dev.driver); 3180 drv = to_usb_driver(cintf->dev.driver);
3169 if (drv->post_reset) 3181 if (drv->post_reset)
3170 (drv->post_reset)(cintf); 3182 (drv->post_reset)(cintf);
3171 /* FIXME: Unbind if post_reset returns an error or isn't defined */ 3183 /* FIXME: Unbind if post_reset returns an error or isn't defined */
3172 } 3184 }
3173 if (cintf != iface)
3174 up(&cintf->dev.sem);
3175 } 3185 }
3176 } 3186 }
3177 3187
3178 usb_autosuspend_device(udev); 3188 usb_autosuspend_device(udev);
3179 return ret; 3189 return ret;
3180} 3190}
3181EXPORT_SYMBOL(usb_reset_composite_device); 3191EXPORT_SYMBOL_GPL(usb_reset_composite_device);
diff --git a/drivers/usb/core/hub.h b/drivers/usb/core/hub.h
index cf9559c6c9b6..1551aed65e05 100644
--- a/drivers/usb/core/hub.h
+++ b/drivers/usb/core/hub.h
@@ -55,16 +55,16 @@
55#define USB_PORT_FEAT_TEST 21 55#define USB_PORT_FEAT_TEST 21
56#define USB_PORT_FEAT_INDICATOR 22 56#define USB_PORT_FEAT_INDICATOR 22
57 57
58/* 58/*
59 * Hub Status and Hub Change results 59 * Hub Status and Hub Change results
60 * See USB 2.0 spec Table 11-19 and Table 11-20 60 * See USB 2.0 spec Table 11-19 and Table 11-20
61 */ 61 */
62struct usb_port_status { 62struct usb_port_status {
63 __le16 wPortStatus; 63 __le16 wPortStatus;
64 __le16 wPortChange; 64 __le16 wPortChange;
65} __attribute__ ((packed)); 65} __attribute__ ((packed));
66 66
67/* 67/*
68 * wPortStatus bit field 68 * wPortStatus bit field
69 * See USB 2.0 spec Table 11-21 69 * See USB 2.0 spec Table 11-21
70 */ 70 */
@@ -81,7 +81,7 @@ struct usb_port_status {
81#define USB_PORT_STAT_INDICATOR 0x1000 81#define USB_PORT_STAT_INDICATOR 0x1000
82/* bits 13 to 15 are reserved */ 82/* bits 13 to 15 are reserved */
83 83
84/* 84/*
85 * wPortChange bit field 85 * wPortChange bit field
86 * See USB 2.0 spec Table 11-22 86 * See USB 2.0 spec Table 11-22
87 * Bits 0 to 4 shown, bits 5 to 15 are reserved 87 * Bits 0 to 4 shown, bits 5 to 15 are reserved
@@ -93,7 +93,7 @@ struct usb_port_status {
93#define USB_PORT_STAT_C_RESET 0x0010 93#define USB_PORT_STAT_C_RESET 0x0010
94 94
95/* 95/*
96 * wHubCharacteristics (masks) 96 * wHubCharacteristics (masks)
97 * See USB 2.0 spec Table 11-13, offset 3 97 * See USB 2.0 spec Table 11-13, offset 3
98 */ 98 */
99#define HUB_CHAR_LPSM 0x0003 /* D1 .. D0 */ 99#define HUB_CHAR_LPSM 0x0003 /* D1 .. D0 */
@@ -119,8 +119,8 @@ struct usb_hub_status {
119#define HUB_CHANGE_OVERCURRENT 0x0002 119#define HUB_CHANGE_OVERCURRENT 0x0002
120 120
121 121
122/* 122/*
123 * Hub descriptor 123 * Hub descriptor
124 * See USB 2.0 spec Table 11-13 124 * See USB 2.0 spec Table 11-13
125 */ 125 */
126 126
@@ -134,7 +134,7 @@ struct usb_hub_descriptor {
134 __le16 wHubCharacteristics; 134 __le16 wHubCharacteristics;
135 __u8 bPwrOn2PwrGood; 135 __u8 bPwrOn2PwrGood;
136 __u8 bHubContrCurrent; 136 __u8 bHubContrCurrent;
137 /* add 1 bit for hub status change; round to bytes */ 137 /* add 1 bit for hub status change; round to bytes */
138 __u8 DeviceRemovable[(USB_MAXCHILDREN + 1 + 7) / 8]; 138 __u8 DeviceRemovable[(USB_MAXCHILDREN + 1 + 7) / 8];
139 __u8 PortPwrCtrlMask[(USB_MAXCHILDREN + 1 + 7) / 8]; 139 __u8 PortPwrCtrlMask[(USB_MAXCHILDREN + 1 + 7) / 8];
140} __attribute__ ((packed)); 140} __attribute__ ((packed));
@@ -190,6 +190,6 @@ struct usb_tt_clear {
190 u16 devinfo; 190 u16 devinfo;
191}; 191};
192 192
193extern void usb_hub_tt_clear_buffer (struct usb_device *dev, int pipe); 193extern void usb_hub_tt_clear_buffer(struct usb_device *dev, int pipe);
194 194
195#endif /* __LINUX_HUB_H */ 195#endif /* __LINUX_HUB_H */
diff --git a/drivers/usb/core/inode.c b/drivers/usb/core/inode.c
index cd4f11157280..83a373e9cc36 100644
--- a/drivers/usb/core/inode.c
+++ b/drivers/usb/core/inode.c
@@ -38,10 +38,15 @@
38#include <linux/usbdevice_fs.h> 38#include <linux/usbdevice_fs.h>
39#include <linux/parser.h> 39#include <linux/parser.h>
40#include <linux/notifier.h> 40#include <linux/notifier.h>
41#include <linux/seq_file.h>
41#include <asm/byteorder.h> 42#include <asm/byteorder.h>
42#include "usb.h" 43#include "usb.h"
43#include "hcd.h" 44#include "hcd.h"
44 45
46#define USBFS_DEFAULT_DEVMODE (S_IWUSR | S_IRUGO)
47#define USBFS_DEFAULT_BUSMODE (S_IXUGO | S_IRUGO)
48#define USBFS_DEFAULT_LISTMODE S_IRUGO
49
45static struct super_operations usbfs_ops; 50static struct super_operations usbfs_ops;
46static const struct file_operations default_file_operations; 51static const struct file_operations default_file_operations;
47static struct vfsmount *usbfs_mount; 52static struct vfsmount *usbfs_mount;
@@ -57,9 +62,33 @@ static uid_t listuid; /* = 0 */
57static gid_t devgid; /* = 0 */ 62static gid_t devgid; /* = 0 */
58static gid_t busgid; /* = 0 */ 63static gid_t busgid; /* = 0 */
59static gid_t listgid; /* = 0 */ 64static gid_t listgid; /* = 0 */
60static umode_t devmode = S_IWUSR | S_IRUGO; 65static umode_t devmode = USBFS_DEFAULT_DEVMODE;
61static umode_t busmode = S_IXUGO | S_IRUGO; 66static umode_t busmode = USBFS_DEFAULT_BUSMODE;
62static umode_t listmode = S_IRUGO; 67static umode_t listmode = USBFS_DEFAULT_LISTMODE;
68
69static int usbfs_show_options(struct seq_file *seq, struct vfsmount *mnt)
70{
71 if (devuid != 0)
72 seq_printf(seq, ",devuid=%u", devuid);
73 if (devgid != 0)
74 seq_printf(seq, ",devgid=%u", devgid);
75 if (devmode != USBFS_DEFAULT_DEVMODE)
76 seq_printf(seq, ",devmode=%o", devmode);
77 if (busuid != 0)
78 seq_printf(seq, ",busuid=%u", busuid);
79 if (busgid != 0)
80 seq_printf(seq, ",busgid=%u", busgid);
81 if (busmode != USBFS_DEFAULT_BUSMODE)
82 seq_printf(seq, ",busmode=%o", busmode);
83 if (listuid != 0)
84 seq_printf(seq, ",listuid=%u", listuid);
85 if (listgid != 0)
86 seq_printf(seq, ",listgid=%u", listgid);
87 if (listmode != USBFS_DEFAULT_LISTMODE)
88 seq_printf(seq, ",listmode=%o", listmode);
89
90 return 0;
91}
63 92
64enum { 93enum {
65 Opt_devuid, Opt_devgid, Opt_devmode, 94 Opt_devuid, Opt_devgid, Opt_devmode,
@@ -93,9 +122,9 @@ static int parse_options(struct super_block *s, char *data)
93 devgid = 0; 122 devgid = 0;
94 busgid = 0; 123 busgid = 0;
95 listgid = 0; 124 listgid = 0;
96 devmode = S_IWUSR | S_IRUGO; 125 devmode = USBFS_DEFAULT_DEVMODE;
97 busmode = S_IXUGO | S_IRUGO; 126 busmode = USBFS_DEFAULT_BUSMODE;
98 listmode = S_IRUGO; 127 listmode = USBFS_DEFAULT_LISTMODE;
99 128
100 while ((p = strsep(&data, ",")) != NULL) { 129 while ((p = strsep(&data, ",")) != NULL) {
101 substring_t args[MAX_OPT_ARGS]; 130 substring_t args[MAX_OPT_ARGS];
@@ -418,6 +447,7 @@ static struct super_operations usbfs_ops = {
418 .statfs = simple_statfs, 447 .statfs = simple_statfs,
419 .drop_inode = generic_delete_inode, 448 .drop_inode = generic_delete_inode,
420 .remount_fs = remount, 449 .remount_fs = remount,
450 .show_options = usbfs_show_options,
421}; 451};
422 452
423static int usbfs_fill_super(struct super_block *sb, void *data, int silent) 453static int usbfs_fill_super(struct super_block *sb, void *data, int silent)
diff --git a/drivers/usb/core/message.c b/drivers/usb/core/message.c
index fcd40ecbeecc..fefb92296e8f 100644
--- a/drivers/usb/core/message.c
+++ b/drivers/usb/core/message.c
@@ -39,7 +39,7 @@ static void usb_api_blocking_completion(struct urb *urb)
39 * own interruptible routines. 39 * own interruptible routines.
40 */ 40 */
41static int usb_start_wait_urb(struct urb *urb, int timeout, int *actual_length) 41static int usb_start_wait_urb(struct urb *urb, int timeout, int *actual_length)
42{ 42{
43 struct api_context ctx; 43 struct api_context ctx;
44 unsigned long expire; 44 unsigned long expire;
45 int retval; 45 int retval;
@@ -74,9 +74,9 @@ out:
74} 74}
75 75
76/*-------------------------------------------------------------------*/ 76/*-------------------------------------------------------------------*/
77// returns status (negative) or length (positive) 77/* returns status (negative) or length (positive) */
78static int usb_internal_control_msg(struct usb_device *usb_dev, 78static int usb_internal_control_msg(struct usb_device *usb_dev,
79 unsigned int pipe, 79 unsigned int pipe,
80 struct usb_ctrlrequest *cmd, 80 struct usb_ctrlrequest *cmd,
81 void *data, int len, int timeout) 81 void *data, int len, int timeout)
82{ 82{
@@ -87,7 +87,7 @@ static int usb_internal_control_msg(struct usb_device *usb_dev,
87 urb = usb_alloc_urb(0, GFP_NOIO); 87 urb = usb_alloc_urb(0, GFP_NOIO);
88 if (!urb) 88 if (!urb)
89 return -ENOMEM; 89 return -ENOMEM;
90 90
91 usb_fill_control_urb(urb, usb_dev, pipe, (unsigned char *)cmd, data, 91 usb_fill_control_urb(urb, usb_dev, pipe, (unsigned char *)cmd, data,
92 len, usb_api_blocking_completion, NULL); 92 len, usb_api_blocking_completion, NULL);
93 93
@@ -99,47 +99,51 @@ static int usb_internal_control_msg(struct usb_device *usb_dev,
99} 99}
100 100
101/** 101/**
102 * usb_control_msg - Builds a control urb, sends it off and waits for completion 102 * usb_control_msg - Builds a control urb, sends it off and waits for completion
103 * @dev: pointer to the usb device to send the message to 103 * @dev: pointer to the usb device to send the message to
104 * @pipe: endpoint "pipe" to send the message to 104 * @pipe: endpoint "pipe" to send the message to
105 * @request: USB message request value 105 * @request: USB message request value
106 * @requesttype: USB message request type value 106 * @requesttype: USB message request type value
107 * @value: USB message value 107 * @value: USB message value
108 * @index: USB message index value 108 * @index: USB message index value
109 * @data: pointer to the data to send 109 * @data: pointer to the data to send
110 * @size: length in bytes of the data to send 110 * @size: length in bytes of the data to send
111 * @timeout: time in msecs to wait for the message to complete before 111 * @timeout: time in msecs to wait for the message to complete before timing
112 * timing out (if 0 the wait is forever) 112 * out (if 0 the wait is forever)
113 * Context: !in_interrupt () 113 *
114 * 114 * Context: !in_interrupt ()
115 * This function sends a simple control message to a specified endpoint 115 *
116 * and waits for the message to complete, or timeout. 116 * This function sends a simple control message to a specified endpoint and
117 * 117 * waits for the message to complete, or timeout.
118 * If successful, it returns the number of bytes transferred, otherwise a negative error number. 118 *
119 * 119 * If successful, it returns the number of bytes transferred, otherwise a
120 * Don't use this function from within an interrupt context, like a 120 * negative error number.
121 * bottom half handler. If you need an asynchronous message, or need to send 121 *
122 * a message from within interrupt context, use usb_submit_urb() 122 * Don't use this function from within an interrupt context, like a bottom half
123 * If a thread in your driver uses this call, make sure your disconnect() 123 * handler. If you need an asynchronous message, or need to send a message
124 * method can wait for it to complete. Since you don't have a handle on 124 * from within interrupt context, use usb_submit_urb().
125 * the URB used, you can't cancel the request. 125 * If a thread in your driver uses this call, make sure your disconnect()
126 * method can wait for it to complete. Since you don't have a handle on the
127 * URB used, you can't cancel the request.
126 */ 128 */
127int usb_control_msg(struct usb_device *dev, unsigned int pipe, __u8 request, __u8 requesttype, 129int usb_control_msg(struct usb_device *dev, unsigned int pipe, __u8 request,
128 __u16 value, __u16 index, void *data, __u16 size, int timeout) 130 __u8 requesttype, __u16 value, __u16 index, void *data,
131 __u16 size, int timeout)
129{ 132{
130 struct usb_ctrlrequest *dr = kmalloc(sizeof(struct usb_ctrlrequest), GFP_NOIO); 133 struct usb_ctrlrequest *dr;
131 int ret; 134 int ret;
132 135
136 dr = kmalloc(sizeof(struct usb_ctrlrequest), GFP_NOIO);
133 if (!dr) 137 if (!dr)
134 return -ENOMEM; 138 return -ENOMEM;
135 139
136 dr->bRequestType= requesttype; 140 dr->bRequestType = requesttype;
137 dr->bRequest = request; 141 dr->bRequest = request;
138 dr->wValue = cpu_to_le16p(&value); 142 dr->wValue = cpu_to_le16p(&value);
139 dr->wIndex = cpu_to_le16p(&index); 143 dr->wIndex = cpu_to_le16p(&index);
140 dr->wLength = cpu_to_le16p(&size); 144 dr->wLength = cpu_to_le16p(&size);
141 145
142 //dbg("usb_control_msg"); 146 /* dbg("usb_control_msg"); */
143 147
144 ret = usb_internal_control_msg(dev, pipe, dr, data, size, timeout); 148 ret = usb_internal_control_msg(dev, pipe, dr, data, size, timeout);
145 149
@@ -147,7 +151,7 @@ int usb_control_msg(struct usb_device *dev, unsigned int pipe, __u8 request, __u
147 151
148 return ret; 152 return ret;
149} 153}
150 154EXPORT_SYMBOL_GPL(usb_control_msg);
151 155
152/** 156/**
153 * usb_interrupt_msg - Builds an interrupt urb, sends it off and waits for completion 157 * usb_interrupt_msg - Builds an interrupt urb, sends it off and waits for completion
@@ -155,9 +159,11 @@ int usb_control_msg(struct usb_device *dev, unsigned int pipe, __u8 request, __u
155 * @pipe: endpoint "pipe" to send the message to 159 * @pipe: endpoint "pipe" to send the message to
156 * @data: pointer to the data to send 160 * @data: pointer to the data to send
157 * @len: length in bytes of the data to send 161 * @len: length in bytes of the data to send
158 * @actual_length: pointer to a location to put the actual length transferred in bytes 162 * @actual_length: pointer to a location to put the actual length transferred
163 * in bytes
159 * @timeout: time in msecs to wait for the message to complete before 164 * @timeout: time in msecs to wait for the message to complete before
160 * timing out (if 0 the wait is forever) 165 * timing out (if 0 the wait is forever)
166 *
161 * Context: !in_interrupt () 167 * Context: !in_interrupt ()
162 * 168 *
163 * This function sends a simple interrupt message to a specified endpoint and 169 * This function sends a simple interrupt message to a specified endpoint and
@@ -181,38 +187,38 @@ int usb_interrupt_msg(struct usb_device *usb_dev, unsigned int pipe,
181EXPORT_SYMBOL_GPL(usb_interrupt_msg); 187EXPORT_SYMBOL_GPL(usb_interrupt_msg);
182 188
183/** 189/**
184 * usb_bulk_msg - Builds a bulk urb, sends it off and waits for completion 190 * usb_bulk_msg - Builds a bulk urb, sends it off and waits for completion
185 * @usb_dev: pointer to the usb device to send the message to 191 * @usb_dev: pointer to the usb device to send the message to
186 * @pipe: endpoint "pipe" to send the message to 192 * @pipe: endpoint "pipe" to send the message to
187 * @data: pointer to the data to send 193 * @data: pointer to the data to send
188 * @len: length in bytes of the data to send 194 * @len: length in bytes of the data to send
189 * @actual_length: pointer to a location to put the actual length transferred in bytes 195 * @actual_length: pointer to a location to put the actual length transferred
190 * @timeout: time in msecs to wait for the message to complete before 196 * in bytes
191 * timing out (if 0 the wait is forever) 197 * @timeout: time in msecs to wait for the message to complete before
192 * Context: !in_interrupt () 198 * timing out (if 0 the wait is forever)
193 * 199 *
194 * This function sends a simple bulk message to a specified endpoint 200 * Context: !in_interrupt ()
195 * and waits for the message to complete, or timeout. 201 *
196 * 202 * This function sends a simple bulk message to a specified endpoint
197 * If successful, it returns 0, otherwise a negative error number. 203 * and waits for the message to complete, or timeout.
198 * The number of actual bytes transferred will be stored in the 204 *
199 * actual_length paramater. 205 * If successful, it returns 0, otherwise a negative error number. The number
200 * 206 * of actual bytes transferred will be stored in the actual_length paramater.
201 * Don't use this function from within an interrupt context, like a 207 *
202 * bottom half handler. If you need an asynchronous message, or need to 208 * Don't use this function from within an interrupt context, like a bottom half
203 * send a message from within interrupt context, use usb_submit_urb() 209 * handler. If you need an asynchronous message, or need to send a message
204 * If a thread in your driver uses this call, make sure your disconnect() 210 * from within interrupt context, use usb_submit_urb() If a thread in your
205 * method can wait for it to complete. Since you don't have a handle on 211 * driver uses this call, make sure your disconnect() method can wait for it to
206 * the URB used, you can't cancel the request. 212 * complete. Since you don't have a handle on the URB used, you can't cancel
207 * 213 * the request.
208 * Because there is no usb_interrupt_msg() and no USBDEVFS_INTERRUPT 214 *
209 * ioctl, users are forced to abuse this routine by using it to submit 215 * Because there is no usb_interrupt_msg() and no USBDEVFS_INTERRUPT ioctl,
210 * URBs for interrupt endpoints. We will take the liberty of creating 216 * users are forced to abuse this routine by using it to submit URBs for
211 * an interrupt URB (with the default interval) if the target is an 217 * interrupt endpoints. We will take the liberty of creating an interrupt URB
212 * interrupt endpoint. 218 * (with the default interval) if the target is an interrupt endpoint.
213 */ 219 */
214int usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe, 220int usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
215 void *data, int len, int *actual_length, int timeout) 221 void *data, int len, int *actual_length, int timeout)
216{ 222{
217 struct urb *urb; 223 struct urb *urb;
218 struct usb_host_endpoint *ep; 224 struct usb_host_endpoint *ep;
@@ -238,29 +244,30 @@ int usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
238 244
239 return usb_start_wait_urb(urb, timeout, actual_length); 245 return usb_start_wait_urb(urb, timeout, actual_length);
240} 246}
247EXPORT_SYMBOL_GPL(usb_bulk_msg);
241 248
242/*-------------------------------------------------------------------*/ 249/*-------------------------------------------------------------------*/
243 250
244static void sg_clean (struct usb_sg_request *io) 251static void sg_clean(struct usb_sg_request *io)
245{ 252{
246 if (io->urbs) { 253 if (io->urbs) {
247 while (io->entries--) 254 while (io->entries--)
248 usb_free_urb (io->urbs [io->entries]); 255 usb_free_urb(io->urbs [io->entries]);
249 kfree (io->urbs); 256 kfree(io->urbs);
250 io->urbs = NULL; 257 io->urbs = NULL;
251 } 258 }
252 if (io->dev->dev.dma_mask != NULL) 259 if (io->dev->dev.dma_mask != NULL)
253 usb_buffer_unmap_sg (io->dev, usb_pipein(io->pipe), 260 usb_buffer_unmap_sg(io->dev, usb_pipein(io->pipe),
254 io->sg, io->nents); 261 io->sg, io->nents);
255 io->dev = NULL; 262 io->dev = NULL;
256} 263}
257 264
258static void sg_complete (struct urb *urb) 265static void sg_complete(struct urb *urb)
259{ 266{
260 struct usb_sg_request *io = urb->context; 267 struct usb_sg_request *io = urb->context;
261 int status = urb->status; 268 int status = urb->status;
262 269
263 spin_lock (&io->lock); 270 spin_lock(&io->lock);
264 271
265 /* In 2.5 we require hcds' endpoint queues not to progress after fault 272 /* In 2.5 we require hcds' endpoint queues not to progress after fault
266 * reports, until the completion callback (this!) returns. That lets 273 * reports, until the completion callback (this!) returns. That lets
@@ -276,13 +283,13 @@ static void sg_complete (struct urb *urb)
276 && (io->status != -ECONNRESET 283 && (io->status != -ECONNRESET
277 || status != -ECONNRESET) 284 || status != -ECONNRESET)
278 && urb->actual_length) { 285 && urb->actual_length) {
279 dev_err (io->dev->bus->controller, 286 dev_err(io->dev->bus->controller,
280 "dev %s ep%d%s scatterlist error %d/%d\n", 287 "dev %s ep%d%s scatterlist error %d/%d\n",
281 io->dev->devpath, 288 io->dev->devpath,
282 usb_endpoint_num(&urb->ep->desc), 289 usb_endpoint_num(&urb->ep->desc),
283 usb_urb_dir_in(urb) ? "in" : "out", 290 usb_urb_dir_in(urb) ? "in" : "out",
284 status, io->status); 291 status, io->status);
285 // BUG (); 292 /* BUG (); */
286 } 293 }
287 294
288 if (io->status == 0 && status && status != -ECONNRESET) { 295 if (io->status == 0 && status && status != -ECONNRESET) {
@@ -294,22 +301,22 @@ static void sg_complete (struct urb *urb)
294 * unlink pending urbs so they won't rx/tx bad data. 301 * unlink pending urbs so they won't rx/tx bad data.
295 * careful: unlink can sometimes be synchronous... 302 * careful: unlink can sometimes be synchronous...
296 */ 303 */
297 spin_unlock (&io->lock); 304 spin_unlock(&io->lock);
298 for (i = 0, found = 0; i < io->entries; i++) { 305 for (i = 0, found = 0; i < io->entries; i++) {
299 if (!io->urbs [i] || !io->urbs [i]->dev) 306 if (!io->urbs [i] || !io->urbs [i]->dev)
300 continue; 307 continue;
301 if (found) { 308 if (found) {
302 retval = usb_unlink_urb (io->urbs [i]); 309 retval = usb_unlink_urb(io->urbs [i]);
303 if (retval != -EINPROGRESS && 310 if (retval != -EINPROGRESS &&
304 retval != -ENODEV && 311 retval != -ENODEV &&
305 retval != -EBUSY) 312 retval != -EBUSY)
306 dev_err (&io->dev->dev, 313 dev_err(&io->dev->dev,
307 "%s, unlink --> %d\n", 314 "%s, unlink --> %d\n",
308 __FUNCTION__, retval); 315 __FUNCTION__, retval);
309 } else if (urb == io->urbs [i]) 316 } else if (urb == io->urbs [i])
310 found = 1; 317 found = 1;
311 } 318 }
312 spin_lock (&io->lock); 319 spin_lock(&io->lock);
313 } 320 }
314 urb->dev = NULL; 321 urb->dev = NULL;
315 322
@@ -317,9 +324,9 @@ static void sg_complete (struct urb *urb)
317 io->bytes += urb->actual_length; 324 io->bytes += urb->actual_length;
318 io->count--; 325 io->count--;
319 if (!io->count) 326 if (!io->count)
320 complete (&io->complete); 327 complete(&io->complete);
321 328
322 spin_unlock (&io->lock); 329 spin_unlock(&io->lock);
323} 330}
324 331
325 332
@@ -348,28 +355,21 @@ static void sg_complete (struct urb *urb)
348 * The request may be canceled with usb_sg_cancel(), either before or after 355 * The request may be canceled with usb_sg_cancel(), either before or after
349 * usb_sg_wait() is called. 356 * usb_sg_wait() is called.
350 */ 357 */
351int usb_sg_init ( 358int usb_sg_init(struct usb_sg_request *io, struct usb_device *dev,
352 struct usb_sg_request *io, 359 unsigned pipe, unsigned period, struct scatterlist *sg,
353 struct usb_device *dev, 360 int nents, size_t length, gfp_t mem_flags)
354 unsigned pipe,
355 unsigned period,
356 struct scatterlist *sg,
357 int nents,
358 size_t length,
359 gfp_t mem_flags
360)
361{ 361{
362 int i; 362 int i;
363 int urb_flags; 363 int urb_flags;
364 int dma; 364 int dma;
365 365
366 if (!io || !dev || !sg 366 if (!io || !dev || !sg
367 || usb_pipecontrol (pipe) 367 || usb_pipecontrol(pipe)
368 || usb_pipeisoc (pipe) 368 || usb_pipeisoc(pipe)
369 || nents <= 0) 369 || nents <= 0)
370 return -EINVAL; 370 return -EINVAL;
371 371
372 spin_lock_init (&io->lock); 372 spin_lock_init(&io->lock);
373 io->dev = dev; 373 io->dev = dev;
374 io->pipe = pipe; 374 io->pipe = pipe;
375 io->sg = sg; 375 io->sg = sg;
@@ -381,7 +381,7 @@ int usb_sg_init (
381 dma = (dev->dev.dma_mask != NULL); 381 dma = (dev->dev.dma_mask != NULL);
382 if (dma) 382 if (dma)
383 io->entries = usb_buffer_map_sg(dev, usb_pipein(pipe), 383 io->entries = usb_buffer_map_sg(dev, usb_pipein(pipe),
384 sg, nents); 384 sg, nents);
385 else 385 else
386 io->entries = nents; 386 io->entries = nents;
387 387
@@ -390,30 +390,30 @@ int usb_sg_init (
390 return io->entries; 390 return io->entries;
391 391
392 io->count = io->entries; 392 io->count = io->entries;
393 io->urbs = kmalloc (io->entries * sizeof *io->urbs, mem_flags); 393 io->urbs = kmalloc(io->entries * sizeof *io->urbs, mem_flags);
394 if (!io->urbs) 394 if (!io->urbs)
395 goto nomem; 395 goto nomem;
396 396
397 urb_flags = URB_NO_TRANSFER_DMA_MAP | URB_NO_INTERRUPT; 397 urb_flags = URB_NO_TRANSFER_DMA_MAP | URB_NO_INTERRUPT;
398 if (usb_pipein (pipe)) 398 if (usb_pipein(pipe))
399 urb_flags |= URB_SHORT_NOT_OK; 399 urb_flags |= URB_SHORT_NOT_OK;
400 400
401 for (i = 0; i < io->entries; i++) { 401 for (i = 0; i < io->entries; i++) {
402 unsigned len; 402 unsigned len;
403 403
404 io->urbs [i] = usb_alloc_urb (0, mem_flags); 404 io->urbs[i] = usb_alloc_urb(0, mem_flags);
405 if (!io->urbs [i]) { 405 if (!io->urbs[i]) {
406 io->entries = i; 406 io->entries = i;
407 goto nomem; 407 goto nomem;
408 } 408 }
409 409
410 io->urbs [i]->dev = NULL; 410 io->urbs[i]->dev = NULL;
411 io->urbs [i]->pipe = pipe; 411 io->urbs[i]->pipe = pipe;
412 io->urbs [i]->interval = period; 412 io->urbs[i]->interval = period;
413 io->urbs [i]->transfer_flags = urb_flags; 413 io->urbs[i]->transfer_flags = urb_flags;
414 414
415 io->urbs [i]->complete = sg_complete; 415 io->urbs[i]->complete = sg_complete;
416 io->urbs [i]->context = io; 416 io->urbs[i]->context = io;
417 417
418 /* 418 /*
419 * Some systems need to revert to PIO when DMA is temporarily 419 * Some systems need to revert to PIO when DMA is temporarily
@@ -432,8 +432,8 @@ int usb_sg_init (
432 * to prevent stale pointers and to help spot bugs. 432 * to prevent stale pointers and to help spot bugs.
433 */ 433 */
434 if (dma) { 434 if (dma) {
435 io->urbs [i]->transfer_dma = sg_dma_address (sg + i); 435 io->urbs[i]->transfer_dma = sg_dma_address(sg + i);
436 len = sg_dma_len (sg + i); 436 len = sg_dma_len(sg + i);
437#if defined(CONFIG_HIGHMEM) || defined(CONFIG_GART_IOMMU) 437#if defined(CONFIG_HIGHMEM) || defined(CONFIG_GART_IOMMU)
438 io->urbs[i]->transfer_buffer = NULL; 438 io->urbs[i]->transfer_buffer = NULL;
439#else 439#else
@@ -441,31 +441,31 @@ int usb_sg_init (
441#endif 441#endif
442 } else { 442 } else {
443 /* hc may use _only_ transfer_buffer */ 443 /* hc may use _only_ transfer_buffer */
444 io->urbs [i]->transfer_buffer = sg_virt(&sg[i]); 444 io->urbs[i]->transfer_buffer = sg_virt(&sg[i]);
445 len = sg [i].length; 445 len = sg[i].length;
446 } 446 }
447 447
448 if (length) { 448 if (length) {
449 len = min_t (unsigned, len, length); 449 len = min_t(unsigned, len, length);
450 length -= len; 450 length -= len;
451 if (length == 0) 451 if (length == 0)
452 io->entries = i + 1; 452 io->entries = i + 1;
453 } 453 }
454 io->urbs [i]->transfer_buffer_length = len; 454 io->urbs[i]->transfer_buffer_length = len;
455 } 455 }
456 io->urbs [--i]->transfer_flags &= ~URB_NO_INTERRUPT; 456 io->urbs[--i]->transfer_flags &= ~URB_NO_INTERRUPT;
457 457
458 /* transaction state */ 458 /* transaction state */
459 io->status = 0; 459 io->status = 0;
460 io->bytes = 0; 460 io->bytes = 0;
461 init_completion (&io->complete); 461 init_completion(&io->complete);
462 return 0; 462 return 0;
463 463
464nomem: 464nomem:
465 sg_clean (io); 465 sg_clean(io);
466 return -ENOMEM; 466 return -ENOMEM;
467} 467}
468 468EXPORT_SYMBOL_GPL(usb_sg_init);
469 469
470/** 470/**
471 * usb_sg_wait - synchronously execute scatter/gather request 471 * usb_sg_wait - synchronously execute scatter/gather request
@@ -506,31 +506,32 @@ nomem:
506 * speed interrupt endpoints, which allow at most one packet per millisecond, 506 * speed interrupt endpoints, which allow at most one packet per millisecond,
507 * of at most 8 or 64 bytes (respectively). 507 * of at most 8 or 64 bytes (respectively).
508 */ 508 */
509void usb_sg_wait (struct usb_sg_request *io) 509void usb_sg_wait(struct usb_sg_request *io)
510{ 510{
511 int i, entries = io->entries; 511 int i;
512 int entries = io->entries;
512 513
513 /* queue the urbs. */ 514 /* queue the urbs. */
514 spin_lock_irq (&io->lock); 515 spin_lock_irq(&io->lock);
515 i = 0; 516 i = 0;
516 while (i < entries && !io->status) { 517 while (i < entries && !io->status) {
517 int retval; 518 int retval;
518 519
519 io->urbs [i]->dev = io->dev; 520 io->urbs[i]->dev = io->dev;
520 retval = usb_submit_urb (io->urbs [i], GFP_ATOMIC); 521 retval = usb_submit_urb(io->urbs [i], GFP_ATOMIC);
521 522
522 /* after we submit, let completions or cancelations fire; 523 /* after we submit, let completions or cancelations fire;
523 * we handshake using io->status. 524 * we handshake using io->status.
524 */ 525 */
525 spin_unlock_irq (&io->lock); 526 spin_unlock_irq(&io->lock);
526 switch (retval) { 527 switch (retval) {
527 /* maybe we retrying will recover */ 528 /* maybe we retrying will recover */
528 case -ENXIO: // hc didn't queue this one 529 case -ENXIO: /* hc didn't queue this one */
529 case -EAGAIN: 530 case -EAGAIN:
530 case -ENOMEM: 531 case -ENOMEM:
531 io->urbs[i]->dev = NULL; 532 io->urbs[i]->dev = NULL;
532 retval = 0; 533 retval = 0;
533 yield (); 534 yield();
534 break; 535 break;
535 536
536 /* no error? continue immediately. 537 /* no error? continue immediately.
@@ -541,34 +542,35 @@ void usb_sg_wait (struct usb_sg_request *io)
541 */ 542 */
542 case 0: 543 case 0:
543 ++i; 544 ++i;
544 cpu_relax (); 545 cpu_relax();
545 break; 546 break;
546 547
547 /* fail any uncompleted urbs */ 548 /* fail any uncompleted urbs */
548 default: 549 default:
549 io->urbs [i]->dev = NULL; 550 io->urbs[i]->dev = NULL;
550 io->urbs [i]->status = retval; 551 io->urbs[i]->status = retval;
551 dev_dbg (&io->dev->dev, "%s, submit --> %d\n", 552 dev_dbg(&io->dev->dev, "%s, submit --> %d\n",
552 __FUNCTION__, retval); 553 __FUNCTION__, retval);
553 usb_sg_cancel (io); 554 usb_sg_cancel(io);
554 } 555 }
555 spin_lock_irq (&io->lock); 556 spin_lock_irq(&io->lock);
556 if (retval && (io->status == 0 || io->status == -ECONNRESET)) 557 if (retval && (io->status == 0 || io->status == -ECONNRESET))
557 io->status = retval; 558 io->status = retval;
558 } 559 }
559 io->count -= entries - i; 560 io->count -= entries - i;
560 if (io->count == 0) 561 if (io->count == 0)
561 complete (&io->complete); 562 complete(&io->complete);
562 spin_unlock_irq (&io->lock); 563 spin_unlock_irq(&io->lock);
563 564
564 /* OK, yes, this could be packaged as non-blocking. 565 /* OK, yes, this could be packaged as non-blocking.
565 * So could the submit loop above ... but it's easier to 566 * So could the submit loop above ... but it's easier to
566 * solve neither problem than to solve both! 567 * solve neither problem than to solve both!
567 */ 568 */
568 wait_for_completion (&io->complete); 569 wait_for_completion(&io->complete);
569 570
570 sg_clean (io); 571 sg_clean(io);
571} 572}
573EXPORT_SYMBOL_GPL(usb_sg_wait);
572 574
573/** 575/**
574 * usb_sg_cancel - stop scatter/gather i/o issued by usb_sg_wait() 576 * usb_sg_cancel - stop scatter/gather i/o issued by usb_sg_wait()
@@ -578,32 +580,33 @@ void usb_sg_wait (struct usb_sg_request *io)
578 * It can also prevents one initialized by usb_sg_init() from starting, 580 * It can also prevents one initialized by usb_sg_init() from starting,
579 * so that call just frees resources allocated to the request. 581 * so that call just frees resources allocated to the request.
580 */ 582 */
581void usb_sg_cancel (struct usb_sg_request *io) 583void usb_sg_cancel(struct usb_sg_request *io)
582{ 584{
583 unsigned long flags; 585 unsigned long flags;
584 586
585 spin_lock_irqsave (&io->lock, flags); 587 spin_lock_irqsave(&io->lock, flags);
586 588
587 /* shut everything down, if it didn't already */ 589 /* shut everything down, if it didn't already */
588 if (!io->status) { 590 if (!io->status) {
589 int i; 591 int i;
590 592
591 io->status = -ECONNRESET; 593 io->status = -ECONNRESET;
592 spin_unlock (&io->lock); 594 spin_unlock(&io->lock);
593 for (i = 0; i < io->entries; i++) { 595 for (i = 0; i < io->entries; i++) {
594 int retval; 596 int retval;
595 597
596 if (!io->urbs [i]->dev) 598 if (!io->urbs [i]->dev)
597 continue; 599 continue;
598 retval = usb_unlink_urb (io->urbs [i]); 600 retval = usb_unlink_urb(io->urbs [i]);
599 if (retval != -EINPROGRESS && retval != -EBUSY) 601 if (retval != -EINPROGRESS && retval != -EBUSY)
600 dev_warn (&io->dev->dev, "%s, unlink --> %d\n", 602 dev_warn(&io->dev->dev, "%s, unlink --> %d\n",
601 __FUNCTION__, retval); 603 __FUNCTION__, retval);
602 } 604 }
603 spin_lock (&io->lock); 605 spin_lock(&io->lock);
604 } 606 }
605 spin_unlock_irqrestore (&io->lock, flags); 607 spin_unlock_irqrestore(&io->lock, flags);
606} 608}
609EXPORT_SYMBOL_GPL(usb_sg_cancel);
607 610
608/*-------------------------------------------------------------------*/ 611/*-------------------------------------------------------------------*/
609 612
@@ -629,12 +632,13 @@ void usb_sg_cancel (struct usb_sg_request *io)
629 * Returns the number of bytes received on success, or else the status code 632 * Returns the number of bytes received on success, or else the status code
630 * returned by the underlying usb_control_msg() call. 633 * returned by the underlying usb_control_msg() call.
631 */ 634 */
632int usb_get_descriptor(struct usb_device *dev, unsigned char type, unsigned char index, void *buf, int size) 635int usb_get_descriptor(struct usb_device *dev, unsigned char type,
636 unsigned char index, void *buf, int size)
633{ 637{
634 int i; 638 int i;
635 int result; 639 int result;
636 640
637 memset(buf,0,size); // Make sure we parse really received data 641 memset(buf, 0, size); /* Make sure we parse really received data */
638 642
639 for (i = 0; i < 3; ++i) { 643 for (i = 0; i < 3; ++i) {
640 /* retry on length 0 or error; some devices are flakey */ 644 /* retry on length 0 or error; some devices are flakey */
@@ -652,6 +656,7 @@ int usb_get_descriptor(struct usb_device *dev, unsigned char type, unsigned char
652 } 656 }
653 return result; 657 return result;
654} 658}
659EXPORT_SYMBOL_GPL(usb_get_descriptor);
655 660
656/** 661/**
657 * usb_get_string - gets a string descriptor 662 * usb_get_string - gets a string descriptor
@@ -708,7 +713,7 @@ static void usb_try_string_workarounds(unsigned char *buf, int *length)
708} 713}
709 714
710static int usb_string_sub(struct usb_device *dev, unsigned int langid, 715static int usb_string_sub(struct usb_device *dev, unsigned int langid,
711 unsigned int index, unsigned char *buf) 716 unsigned int index, unsigned char *buf)
712{ 717{
713 int rc; 718 int rc;
714 719
@@ -751,7 +756,7 @@ static int usb_string_sub(struct usb_device *dev, unsigned int langid,
751 * @buf: where to put the string 756 * @buf: where to put the string
752 * @size: how big is "buf"? 757 * @size: how big is "buf"?
753 * Context: !in_interrupt () 758 * Context: !in_interrupt ()
754 * 759 *
755 * This converts the UTF-16LE encoded strings returned by devices, from 760 * This converts the UTF-16LE encoded strings returned by devices, from
756 * usb_get_string_descriptor(), to null-terminated ISO-8859-1 encoded ones 761 * usb_get_string_descriptor(), to null-terminated ISO-8859-1 encoded ones
757 * that are more usable in most kernel contexts. Note that all characters 762 * that are more usable in most kernel contexts. Note that all characters
@@ -787,23 +792,23 @@ int usb_string(struct usb_device *dev, int index, char *buf, size_t size)
787 if (!dev->have_langid) { 792 if (!dev->have_langid) {
788 err = usb_string_sub(dev, 0, 0, tbuf); 793 err = usb_string_sub(dev, 0, 0, tbuf);
789 if (err < 0) { 794 if (err < 0) {
790 dev_err (&dev->dev, 795 dev_err(&dev->dev,
791 "string descriptor 0 read error: %d\n", 796 "string descriptor 0 read error: %d\n",
792 err); 797 err);
793 goto errout; 798 goto errout;
794 } else if (err < 4) { 799 } else if (err < 4) {
795 dev_err (&dev->dev, "string descriptor 0 too short\n"); 800 dev_err(&dev->dev, "string descriptor 0 too short\n");
796 err = -EINVAL; 801 err = -EINVAL;
797 goto errout; 802 goto errout;
798 } else { 803 } else {
799 dev->have_langid = 1; 804 dev->have_langid = 1;
800 dev->string_langid = tbuf[2] | (tbuf[3]<< 8); 805 dev->string_langid = tbuf[2] | (tbuf[3] << 8);
801 /* always use the first langid listed */ 806 /* always use the first langid listed */
802 dev_dbg (&dev->dev, "default language 0x%04x\n", 807 dev_dbg(&dev->dev, "default language 0x%04x\n",
803 dev->string_langid); 808 dev->string_langid);
804 } 809 }
805 } 810 }
806 811
807 err = usb_string_sub(dev, dev->string_langid, index, tbuf); 812 err = usb_string_sub(dev, dev->string_langid, index, tbuf);
808 if (err < 0) 813 if (err < 0)
809 goto errout; 814 goto errout;
@@ -821,12 +826,15 @@ int usb_string(struct usb_device *dev, int index, char *buf, size_t size)
821 err = idx; 826 err = idx;
822 827
823 if (tbuf[1] != USB_DT_STRING) 828 if (tbuf[1] != USB_DT_STRING)
824 dev_dbg(&dev->dev, "wrong descriptor type %02x for string %d (\"%s\")\n", tbuf[1], index, buf); 829 dev_dbg(&dev->dev,
830 "wrong descriptor type %02x for string %d (\"%s\")\n",
831 tbuf[1], index, buf);
825 832
826 errout: 833 errout:
827 kfree(tbuf); 834 kfree(tbuf);
828 return err; 835 return err;
829} 836}
837EXPORT_SYMBOL_GPL(usb_string);
830 838
831/** 839/**
832 * usb_cache_string - read a string descriptor and cache it for later use 840 * usb_cache_string - read a string descriptor and cache it for later use
@@ -842,9 +850,15 @@ char *usb_cache_string(struct usb_device *udev, int index)
842 char *smallbuf = NULL; 850 char *smallbuf = NULL;
843 int len; 851 int len;
844 852
845 if (index > 0 && (buf = kmalloc(256, GFP_KERNEL)) != NULL) { 853 if (index <= 0)
846 if ((len = usb_string(udev, index, buf, 256)) > 0) { 854 return NULL;
847 if ((smallbuf = kmalloc(++len, GFP_KERNEL)) == NULL) 855
856 buf = kmalloc(256, GFP_KERNEL);
857 if (buf) {
858 len = usb_string(udev, index, buf, 256);
859 if (len > 0) {
860 smallbuf = kmalloc(++len, GFP_KERNEL);
861 if (!smallbuf)
848 return buf; 862 return buf;
849 memcpy(smallbuf, buf, len); 863 memcpy(smallbuf, buf, len);
850 } 864 }
@@ -883,7 +897,7 @@ int usb_get_device_descriptor(struct usb_device *dev, unsigned int size)
883 return -ENOMEM; 897 return -ENOMEM;
884 898
885 ret = usb_get_descriptor(dev, USB_DT_DEVICE, 0, desc, size); 899 ret = usb_get_descriptor(dev, USB_DT_DEVICE, 0, desc, size);
886 if (ret >= 0) 900 if (ret >= 0)
887 memcpy(&dev->descriptor, desc, size); 901 memcpy(&dev->descriptor, desc, size);
888 kfree(desc); 902 kfree(desc);
889 return ret; 903 return ret;
@@ -927,6 +941,7 @@ int usb_get_status(struct usb_device *dev, int type, int target, void *data)
927 kfree(status); 941 kfree(status);
928 return ret; 942 return ret;
929} 943}
944EXPORT_SYMBOL_GPL(usb_get_status);
930 945
931/** 946/**
932 * usb_clear_halt - tells device to clear endpoint halt/stall condition 947 * usb_clear_halt - tells device to clear endpoint halt/stall condition
@@ -955,8 +970,8 @@ int usb_clear_halt(struct usb_device *dev, int pipe)
955{ 970{
956 int result; 971 int result;
957 int endp = usb_pipeendpoint(pipe); 972 int endp = usb_pipeendpoint(pipe);
958 973
959 if (usb_pipein (pipe)) 974 if (usb_pipein(pipe))
960 endp |= USB_DIR_IN; 975 endp |= USB_DIR_IN;
961 976
962 /* we don't care if it wasn't halted first. in fact some devices 977 /* we don't care if it wasn't halted first. in fact some devices
@@ -985,6 +1000,7 @@ int usb_clear_halt(struct usb_device *dev, int pipe)
985 1000
986 return 0; 1001 return 0;
987} 1002}
1003EXPORT_SYMBOL_GPL(usb_clear_halt);
988 1004
989/** 1005/**
990 * usb_disable_endpoint -- Disable an endpoint by address 1006 * usb_disable_endpoint -- Disable an endpoint by address
@@ -1038,7 +1054,7 @@ void usb_disable_interface(struct usb_device *dev, struct usb_interface *intf)
1038 } 1054 }
1039} 1055}
1040 1056
1041/* 1057/**
1042 * usb_disable_device - Disable all the endpoints for a USB device 1058 * usb_disable_device - Disable all the endpoints for a USB device
1043 * @dev: the device whose endpoints are being disabled 1059 * @dev: the device whose endpoints are being disabled
1044 * @skip_ep0: 0 to disable endpoint 0, 1 to skip it. 1060 * @skip_ep0: 0 to disable endpoint 0, 1 to skip it.
@@ -1053,7 +1069,7 @@ void usb_disable_device(struct usb_device *dev, int skip_ep0)
1053 int i; 1069 int i;
1054 1070
1055 dev_dbg(&dev->dev, "%s nuking %s URBs\n", __FUNCTION__, 1071 dev_dbg(&dev->dev, "%s nuking %s URBs\n", __FUNCTION__,
1056 skip_ep0 ? "non-ep0" : "all"); 1072 skip_ep0 ? "non-ep0" : "all");
1057 for (i = skip_ep0; i < 16; ++i) { 1073 for (i = skip_ep0; i < 16; ++i) {
1058 usb_disable_endpoint(dev, i); 1074 usb_disable_endpoint(dev, i);
1059 usb_disable_endpoint(dev, i + USB_DIR_IN); 1075 usb_disable_endpoint(dev, i + USB_DIR_IN);
@@ -1071,17 +1087,17 @@ void usb_disable_device(struct usb_device *dev, int skip_ep0)
1071 interface = dev->actconfig->interface[i]; 1087 interface = dev->actconfig->interface[i];
1072 if (!device_is_registered(&interface->dev)) 1088 if (!device_is_registered(&interface->dev))
1073 continue; 1089 continue;
1074 dev_dbg (&dev->dev, "unregistering interface %s\n", 1090 dev_dbg(&dev->dev, "unregistering interface %s\n",
1075 interface->dev.bus_id); 1091 interface->dev.bus_id);
1076 usb_remove_sysfs_intf_files(interface); 1092 usb_remove_sysfs_intf_files(interface);
1077 device_del (&interface->dev); 1093 device_del(&interface->dev);
1078 } 1094 }
1079 1095
1080 /* Now that the interfaces are unbound, nobody should 1096 /* Now that the interfaces are unbound, nobody should
1081 * try to access them. 1097 * try to access them.
1082 */ 1098 */
1083 for (i = 0; i < dev->actconfig->desc.bNumInterfaces; i++) { 1099 for (i = 0; i < dev->actconfig->desc.bNumInterfaces; i++) {
1084 put_device (&dev->actconfig->interface[i]->dev); 1100 put_device(&dev->actconfig->interface[i]->dev);
1085 dev->actconfig->interface[i] = NULL; 1101 dev->actconfig->interface[i] = NULL;
1086 } 1102 }
1087 dev->actconfig = NULL; 1103 dev->actconfig = NULL;
@@ -1090,8 +1106,7 @@ void usb_disable_device(struct usb_device *dev, int skip_ep0)
1090 } 1106 }
1091} 1107}
1092 1108
1093 1109/**
1094/*
1095 * usb_enable_endpoint - Enable an endpoint for USB communications 1110 * usb_enable_endpoint - Enable an endpoint for USB communications
1096 * @dev: the device whose interface is being enabled 1111 * @dev: the device whose interface is being enabled
1097 * @ep: the endpoint 1112 * @ep: the endpoint
@@ -1116,7 +1131,7 @@ void usb_enable_endpoint(struct usb_device *dev, struct usb_host_endpoint *ep)
1116 ep->enabled = 1; 1131 ep->enabled = 1;
1117} 1132}
1118 1133
1119/* 1134/**
1120 * usb_enable_interface - Enable all the endpoints for an interface 1135 * usb_enable_interface - Enable all the endpoints for an interface
1121 * @dev: the device whose interface is being enabled 1136 * @dev: the device whose interface is being enabled
1122 * @intf: pointer to the interface descriptor 1137 * @intf: pointer to the interface descriptor
@@ -1172,6 +1187,8 @@ int usb_set_interface(struct usb_device *dev, int interface, int alternate)
1172 struct usb_host_interface *alt; 1187 struct usb_host_interface *alt;
1173 int ret; 1188 int ret;
1174 int manual = 0; 1189 int manual = 0;
1190 unsigned int epaddr;
1191 unsigned int pipe;
1175 1192
1176 if (dev->state == USB_STATE_SUSPENDED) 1193 if (dev->state == USB_STATE_SUSPENDED)
1177 return -EHOSTUNREACH; 1194 return -EHOSTUNREACH;
@@ -1226,11 +1243,11 @@ int usb_set_interface(struct usb_device *dev, int interface, int alternate)
1226 int i; 1243 int i;
1227 1244
1228 for (i = 0; i < alt->desc.bNumEndpoints; i++) { 1245 for (i = 0; i < alt->desc.bNumEndpoints; i++) {
1229 unsigned int epaddr = 1246 epaddr = alt->endpoint[i].desc.bEndpointAddress;
1230 alt->endpoint[i].desc.bEndpointAddress; 1247 pipe = __create_pipe(dev,
1231 unsigned int pipe = 1248 USB_ENDPOINT_NUMBER_MASK & epaddr) |
1232 __create_pipe(dev, USB_ENDPOINT_NUMBER_MASK & epaddr) 1249 (usb_endpoint_out(epaddr) ?
1233 | (usb_endpoint_out(epaddr) ? USB_DIR_OUT : USB_DIR_IN); 1250 USB_DIR_OUT : USB_DIR_IN);
1234 1251
1235 usb_clear_halt(dev, pipe); 1252 usb_clear_halt(dev, pipe);
1236 } 1253 }
@@ -1253,6 +1270,7 @@ int usb_set_interface(struct usb_device *dev, int interface, int alternate)
1253 1270
1254 return 0; 1271 return 0;
1255} 1272}
1273EXPORT_SYMBOL_GPL(usb_set_interface);
1256 1274
1257/** 1275/**
1258 * usb_reset_configuration - lightweight device reset 1276 * usb_reset_configuration - lightweight device reset
@@ -1328,6 +1346,7 @@ int usb_reset_configuration(struct usb_device *dev)
1328 } 1346 }
1329 return 0; 1347 return 0;
1330} 1348}
1349EXPORT_SYMBOL_GPL(usb_reset_configuration);
1331 1350
1332static void usb_release_interface(struct device *dev) 1351static void usb_release_interface(struct device *dev)
1333{ 1352{
@@ -1357,7 +1376,8 @@ static int usb_if_uevent(struct device *dev, struct kobj_uevent_env *env)
1357 return -ENOMEM; 1376 return -ENOMEM;
1358 1377
1359 if (add_uevent_var(env, 1378 if (add_uevent_var(env,
1360 "MODALIAS=usb:v%04Xp%04Xd%04Xdc%02Xdsc%02Xdp%02Xic%02Xisc%02Xip%02X", 1379 "MODALIAS=usb:"
1380 "v%04Xp%04Xd%04Xdc%02Xdsc%02Xdp%02Xic%02Xisc%02Xip%02X",
1361 le16_to_cpu(usb_dev->descriptor.idVendor), 1381 le16_to_cpu(usb_dev->descriptor.idVendor),
1362 le16_to_cpu(usb_dev->descriptor.idProduct), 1382 le16_to_cpu(usb_dev->descriptor.idProduct),
1363 le16_to_cpu(usb_dev->descriptor.bcdDevice), 1383 le16_to_cpu(usb_dev->descriptor.bcdDevice),
@@ -1387,8 +1407,8 @@ struct device_type usb_if_device_type = {
1387}; 1407};
1388 1408
1389static struct usb_interface_assoc_descriptor *find_iad(struct usb_device *dev, 1409static struct usb_interface_assoc_descriptor *find_iad(struct usb_device *dev,
1390 struct usb_host_config *config, 1410 struct usb_host_config *config,
1391 u8 inum) 1411 u8 inum)
1392{ 1412{
1393 struct usb_interface_assoc_descriptor *retval = NULL; 1413 struct usb_interface_assoc_descriptor *retval = NULL;
1394 struct usb_interface_assoc_descriptor *intf_assoc; 1414 struct usb_interface_assoc_descriptor *intf_assoc;
@@ -1415,7 +1435,6 @@ static struct usb_interface_assoc_descriptor *find_iad(struct usb_device *dev,
1415 return retval; 1435 return retval;
1416} 1436}
1417 1437
1418
1419/* 1438/*
1420 * usb_set_configuration - Makes a particular device setting be current 1439 * usb_set_configuration - Makes a particular device setting be current
1421 * @dev: the device whose configuration is being updated 1440 * @dev: the device whose configuration is being updated
@@ -1533,12 +1552,12 @@ free_interfaces:
1533 * getting rid of old interfaces means unbinding their drivers. 1552 * getting rid of old interfaces means unbinding their drivers.
1534 */ 1553 */
1535 if (dev->state != USB_STATE_ADDRESS) 1554 if (dev->state != USB_STATE_ADDRESS)
1536 usb_disable_device (dev, 1); // Skip ep0 1555 usb_disable_device(dev, 1); /* Skip ep0 */
1537
1538 if ((ret = usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
1539 USB_REQ_SET_CONFIGURATION, 0, configuration, 0,
1540 NULL, 0, USB_CTRL_SET_TIMEOUT)) < 0) {
1541 1556
1557 ret = usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
1558 USB_REQ_SET_CONFIGURATION, 0, configuration, 0,
1559 NULL, 0, USB_CTRL_SET_TIMEOUT);
1560 if (ret < 0) {
1542 /* All the old state is gone, so what else can we do? 1561 /* All the old state is gone, so what else can we do?
1543 * The device is probably useless now anyway. 1562 * The device is probably useless now anyway.
1544 */ 1563 */
@@ -1585,11 +1604,11 @@ free_interfaces:
1585 intf->dev.bus = &usb_bus_type; 1604 intf->dev.bus = &usb_bus_type;
1586 intf->dev.type = &usb_if_device_type; 1605 intf->dev.type = &usb_if_device_type;
1587 intf->dev.dma_mask = dev->dev.dma_mask; 1606 intf->dev.dma_mask = dev->dev.dma_mask;
1588 device_initialize (&intf->dev); 1607 device_initialize(&intf->dev);
1589 mark_quiesced(intf); 1608 mark_quiesced(intf);
1590 sprintf (&intf->dev.bus_id[0], "%d-%s:%d.%d", 1609 sprintf(&intf->dev.bus_id[0], "%d-%s:%d.%d",
1591 dev->bus->busnum, dev->devpath, 1610 dev->bus->busnum, dev->devpath,
1592 configuration, alt->desc.bInterfaceNumber); 1611 configuration, alt->desc.bInterfaceNumber);
1593 } 1612 }
1594 kfree(new_interfaces); 1613 kfree(new_interfaces);
1595 1614
@@ -1605,11 +1624,11 @@ free_interfaces:
1605 for (i = 0; i < nintf; ++i) { 1624 for (i = 0; i < nintf; ++i) {
1606 struct usb_interface *intf = cp->interface[i]; 1625 struct usb_interface *intf = cp->interface[i];
1607 1626
1608 dev_dbg (&dev->dev, 1627 dev_dbg(&dev->dev,
1609 "adding %s (config #%d, interface %d)\n", 1628 "adding %s (config #%d, interface %d)\n",
1610 intf->dev.bus_id, configuration, 1629 intf->dev.bus_id, configuration,
1611 intf->cur_altsetting->desc.bInterfaceNumber); 1630 intf->cur_altsetting->desc.bInterfaceNumber);
1612 ret = device_add (&intf->dev); 1631 ret = device_add(&intf->dev);
1613 if (ret != 0) { 1632 if (ret != 0) {
1614 dev_err(&dev->dev, "device_add(%s) --> %d\n", 1633 dev_err(&dev->dev, "device_add(%s) --> %d\n",
1615 intf->dev.bus_id, ret); 1634 intf->dev.bus_id, ret);
@@ -1677,22 +1696,3 @@ int usb_driver_set_configuration(struct usb_device *udev, int config)
1677 return 0; 1696 return 0;
1678} 1697}
1679EXPORT_SYMBOL_GPL(usb_driver_set_configuration); 1698EXPORT_SYMBOL_GPL(usb_driver_set_configuration);
1680
1681// synchronous request completion model
1682EXPORT_SYMBOL(usb_control_msg);
1683EXPORT_SYMBOL(usb_bulk_msg);
1684
1685EXPORT_SYMBOL(usb_sg_init);
1686EXPORT_SYMBOL(usb_sg_cancel);
1687EXPORT_SYMBOL(usb_sg_wait);
1688
1689// synchronous control message convenience routines
1690EXPORT_SYMBOL(usb_get_descriptor);
1691EXPORT_SYMBOL(usb_get_status);
1692EXPORT_SYMBOL(usb_string);
1693
1694// synchronous calls that also maintain usbcore state
1695EXPORT_SYMBOL(usb_clear_halt);
1696EXPORT_SYMBOL(usb_reset_configuration);
1697EXPORT_SYMBOL(usb_set_interface);
1698
diff --git a/drivers/usb/core/notify.c b/drivers/usb/core/notify.c
index 6b36897ca151..7542dce3f5a1 100644
--- a/drivers/usb/core/notify.c
+++ b/drivers/usb/core/notify.c
@@ -33,7 +33,7 @@ EXPORT_SYMBOL_GPL(usb_register_notify);
33 * usb_unregister_notify - unregister a notifier callback 33 * usb_unregister_notify - unregister a notifier callback
34 * @nb: pointer to the notifier block for the callback events. 34 * @nb: pointer to the notifier block for the callback events.
35 * 35 *
36 * usb_register_notifier() must have been previously called for this function 36 * usb_register_notify() must have been previously called for this function
37 * to work properly. 37 * to work properly.
38 */ 38 */
39void usb_unregister_notify(struct notifier_block *nb) 39void usb_unregister_notify(struct notifier_block *nb)
diff --git a/drivers/usb/core/otg_whitelist.h b/drivers/usb/core/otg_whitelist.h
index 7f31a495a25d..e8cdce571bb1 100644
--- a/drivers/usb/core/otg_whitelist.h
+++ b/drivers/usb/core/otg_whitelist.h
@@ -14,7 +14,7 @@
14 * mostly use of USB_DEVICE() or USB_DEVICE_VER() entries.. 14 * mostly use of USB_DEVICE() or USB_DEVICE_VER() entries..
15 * 15 *
16 * YOU _SHOULD_ CHANGE THIS LIST TO MATCH YOUR PRODUCT AND ITS TESTING! 16 * YOU _SHOULD_ CHANGE THIS LIST TO MATCH YOUR PRODUCT AND ITS TESTING!
17 */ 17 */
18 18
19static struct usb_device_id whitelist_table [] = { 19static struct usb_device_id whitelist_table [] = {
20 20
@@ -55,7 +55,7 @@ static int is_targeted(struct usb_device *dev)
55 return 1; 55 return 1;
56 56
57 /* HNP test device is _never_ targeted (see OTG spec 6.6.6) */ 57 /* HNP test device is _never_ targeted (see OTG spec 6.6.6) */
58 if ((le16_to_cpu(dev->descriptor.idVendor) == 0x1a0a && 58 if ((le16_to_cpu(dev->descriptor.idVendor) == 0x1a0a &&
59 le16_to_cpu(dev->descriptor.idProduct) == 0xbadd)) 59 le16_to_cpu(dev->descriptor.idProduct) == 0xbadd))
60 return 0; 60 return 0;
61 61
@@ -86,7 +86,7 @@ static int is_targeted(struct usb_device *dev)
86 continue; 86 continue;
87 87
88 if ((id->match_flags & USB_DEVICE_ID_MATCH_DEV_SUBCLASS) && 88 if ((id->match_flags & USB_DEVICE_ID_MATCH_DEV_SUBCLASS) &&
89 (id->bDeviceSubClass!= dev->descriptor.bDeviceSubClass)) 89 (id->bDeviceSubClass != dev->descriptor.bDeviceSubClass))
90 continue; 90 continue;
91 91
92 if ((id->match_flags & USB_DEVICE_ID_MATCH_DEV_PROTOCOL) && 92 if ((id->match_flags & USB_DEVICE_ID_MATCH_DEV_PROTOCOL) &&
diff --git a/drivers/usb/core/sysfs.c b/drivers/usb/core/sysfs.c
index 32bd130b1eed..a37ccbd1e007 100644
--- a/drivers/usb/core/sysfs.c
+++ b/drivers/usb/core/sysfs.c
@@ -72,7 +72,7 @@ set_bConfigurationValue(struct device *dev, struct device_attribute *attr,
72 return (value < 0) ? value : count; 72 return (value < 0) ? value : count;
73} 73}
74 74
75static DEVICE_ATTR(bConfigurationValue, S_IRUGO | S_IWUSR, 75static DEVICE_ATTR(bConfigurationValue, S_IRUGO | S_IWUSR,
76 show_bConfigurationValue, set_bConfigurationValue); 76 show_bConfigurationValue, set_bConfigurationValue);
77 77
78/* String fields */ 78/* String fields */
@@ -249,6 +249,41 @@ static void remove_persist_attributes(struct device *dev)
249#ifdef CONFIG_USB_SUSPEND 249#ifdef CONFIG_USB_SUSPEND
250 250
251static ssize_t 251static ssize_t
252show_connected_duration(struct device *dev, struct device_attribute *attr,
253 char *buf)
254{
255 struct usb_device *udev = to_usb_device(dev);
256
257 return sprintf(buf, "%u\n",
258 jiffies_to_msecs(jiffies - udev->connect_time));
259}
260
261static DEVICE_ATTR(connected_duration, S_IRUGO, show_connected_duration, NULL);
262
263/*
264 * If the device is resumed, the last time the device was suspended has
265 * been pre-subtracted from active_duration. We add the current time to
266 * get the duration that the device was actually active.
267 *
268 * If the device is suspended, the active_duration is up-to-date.
269 */
270static ssize_t
271show_active_duration(struct device *dev, struct device_attribute *attr,
272 char *buf)
273{
274 struct usb_device *udev = to_usb_device(dev);
275 int duration;
276
277 if (udev->state != USB_STATE_SUSPENDED)
278 duration = jiffies_to_msecs(jiffies + udev->active_duration);
279 else
280 duration = jiffies_to_msecs(udev->active_duration);
281 return sprintf(buf, "%u\n", duration);
282}
283
284static DEVICE_ATTR(active_duration, S_IRUGO, show_active_duration, NULL);
285
286static ssize_t
252show_autosuspend(struct device *dev, struct device_attribute *attr, char *buf) 287show_autosuspend(struct device *dev, struct device_attribute *attr, char *buf)
253{ 288{
254 struct usb_device *udev = to_usb_device(dev); 289 struct usb_device *udev = to_usb_device(dev);
@@ -365,6 +400,14 @@ static int add_power_attributes(struct device *dev)
365 rc = sysfs_add_file_to_group(&dev->kobj, 400 rc = sysfs_add_file_to_group(&dev->kobj,
366 &dev_attr_level.attr, 401 &dev_attr_level.attr,
367 power_group); 402 power_group);
403 if (rc == 0)
404 rc = sysfs_add_file_to_group(&dev->kobj,
405 &dev_attr_connected_duration.attr,
406 power_group);
407 if (rc == 0)
408 rc = sysfs_add_file_to_group(&dev->kobj,
409 &dev_attr_active_duration.attr,
410 power_group);
368 } 411 }
369 return rc; 412 return rc;
370} 413}
@@ -372,6 +415,12 @@ static int add_power_attributes(struct device *dev)
372static void remove_power_attributes(struct device *dev) 415static void remove_power_attributes(struct device *dev)
373{ 416{
374 sysfs_remove_file_from_group(&dev->kobj, 417 sysfs_remove_file_from_group(&dev->kobj,
418 &dev_attr_active_duration.attr,
419 power_group);
420 sysfs_remove_file_from_group(&dev->kobj,
421 &dev_attr_connected_duration.attr,
422 power_group);
423 sysfs_remove_file_from_group(&dev->kobj,
375 &dev_attr_level.attr, 424 &dev_attr_level.attr,
376 power_group); 425 power_group);
377 sysfs_remove_file_from_group(&dev->kobj, 426 sysfs_remove_file_from_group(&dev->kobj,
@@ -601,21 +650,21 @@ void usb_remove_sysfs_dev_files(struct usb_device *udev)
601/* Interface Accociation Descriptor fields */ 650/* Interface Accociation Descriptor fields */
602#define usb_intf_assoc_attr(field, format_string) \ 651#define usb_intf_assoc_attr(field, format_string) \
603static ssize_t \ 652static ssize_t \
604show_iad_##field (struct device *dev, struct device_attribute *attr, \ 653show_iad_##field(struct device *dev, struct device_attribute *attr, \
605 char *buf) \ 654 char *buf) \
606{ \ 655{ \
607 struct usb_interface *intf = to_usb_interface (dev); \ 656 struct usb_interface *intf = to_usb_interface(dev); \
608 \ 657 \
609 return sprintf (buf, format_string, \ 658 return sprintf(buf, format_string, \
610 intf->intf_assoc->field); \ 659 intf->intf_assoc->field); \
611} \ 660} \
612static DEVICE_ATTR(iad_##field, S_IRUGO, show_iad_##field, NULL); 661static DEVICE_ATTR(iad_##field, S_IRUGO, show_iad_##field, NULL);
613 662
614usb_intf_assoc_attr (bFirstInterface, "%02x\n") 663usb_intf_assoc_attr(bFirstInterface, "%02x\n")
615usb_intf_assoc_attr (bInterfaceCount, "%02d\n") 664usb_intf_assoc_attr(bInterfaceCount, "%02d\n")
616usb_intf_assoc_attr (bFunctionClass, "%02x\n") 665usb_intf_assoc_attr(bFunctionClass, "%02x\n")
617usb_intf_assoc_attr (bFunctionSubClass, "%02x\n") 666usb_intf_assoc_attr(bFunctionSubClass, "%02x\n")
618usb_intf_assoc_attr (bFunctionProtocol, "%02x\n") 667usb_intf_assoc_attr(bFunctionProtocol, "%02x\n")
619 668
620/* Interface fields */ 669/* Interface fields */
621#define usb_intf_attr(field, format_string) \ 670#define usb_intf_attr(field, format_string) \
diff --git a/drivers/usb/core/urb.c b/drivers/usb/core/urb.c
index d05ead20081c..9d7e63292c01 100644
--- a/drivers/usb/core/urb.c
+++ b/drivers/usb/core/urb.c
@@ -42,6 +42,7 @@ void usb_init_urb(struct urb *urb)
42 INIT_LIST_HEAD(&urb->anchor_list); 42 INIT_LIST_HEAD(&urb->anchor_list);
43 } 43 }
44} 44}
45EXPORT_SYMBOL_GPL(usb_init_urb);
45 46
46/** 47/**
47 * usb_alloc_urb - creates a new urb for a USB driver to use 48 * usb_alloc_urb - creates a new urb for a USB driver to use
@@ -73,6 +74,7 @@ struct urb *usb_alloc_urb(int iso_packets, gfp_t mem_flags)
73 usb_init_urb(urb); 74 usb_init_urb(urb);
74 return urb; 75 return urb;
75} 76}
77EXPORT_SYMBOL_GPL(usb_alloc_urb);
76 78
77/** 79/**
78 * usb_free_urb - frees the memory used by a urb when all users of it are finished 80 * usb_free_urb - frees the memory used by a urb when all users of it are finished
@@ -89,6 +91,7 @@ void usb_free_urb(struct urb *urb)
89 if (urb) 91 if (urb)
90 kref_put(&urb->kref, urb_destroy); 92 kref_put(&urb->kref, urb_destroy);
91} 93}
94EXPORT_SYMBOL_GPL(usb_free_urb);
92 95
93/** 96/**
94 * usb_get_urb - increments the reference count of the urb 97 * usb_get_urb - increments the reference count of the urb
@@ -100,12 +103,13 @@ void usb_free_urb(struct urb *urb)
100 * 103 *
101 * A pointer to the urb with the incremented reference counter is returned. 104 * A pointer to the urb with the incremented reference counter is returned.
102 */ 105 */
103struct urb * usb_get_urb(struct urb *urb) 106struct urb *usb_get_urb(struct urb *urb)
104{ 107{
105 if (urb) 108 if (urb)
106 kref_get(&urb->kref); 109 kref_get(&urb->kref);
107 return urb; 110 return urb;
108} 111}
112EXPORT_SYMBOL_GPL(usb_get_urb);
109 113
110/** 114/**
111 * usb_anchor_urb - anchors an URB while it is processed 115 * usb_anchor_urb - anchors an URB while it is processed
@@ -172,7 +176,7 @@ EXPORT_SYMBOL_GPL(usb_unanchor_urb);
172 * describing that request to the USB subsystem. Request completion will 176 * describing that request to the USB subsystem. Request completion will
173 * be indicated later, asynchronously, by calling the completion handler. 177 * be indicated later, asynchronously, by calling the completion handler.
174 * The three types of completion are success, error, and unlink 178 * The three types of completion are success, error, and unlink
175 * (a software-induced fault, also called "request cancellation"). 179 * (a software-induced fault, also called "request cancellation").
176 * 180 *
177 * URBs may be submitted in interrupt context. 181 * URBs may be submitted in interrupt context.
178 * 182 *
@@ -255,7 +259,7 @@ EXPORT_SYMBOL_GPL(usb_unanchor_urb);
255 * semaphores), or 259 * semaphores), or
256 * (c) current->state != TASK_RUNNING, this is the case only after 260 * (c) current->state != TASK_RUNNING, this is the case only after
257 * you've changed it. 261 * you've changed it.
258 * 262 *
259 * GFP_NOIO is used in the block io path and error handling of storage 263 * GFP_NOIO is used in the block io path and error handling of storage
260 * devices. 264 * devices.
261 * 265 *
@@ -284,7 +288,8 @@ int usb_submit_urb(struct urb *urb, gfp_t mem_flags)
284 288
285 if (!urb || urb->hcpriv || !urb->complete) 289 if (!urb || urb->hcpriv || !urb->complete)
286 return -EINVAL; 290 return -EINVAL;
287 if (!(dev = urb->dev) || dev->state < USB_STATE_DEFAULT) 291 dev = urb->dev;
292 if ((!dev) || (dev->state < USB_STATE_DEFAULT))
288 return -ENODEV; 293 return -ENODEV;
289 294
290 /* For now, get the endpoint from the pipe. Eventually drivers 295 /* For now, get the endpoint from the pipe. Eventually drivers
@@ -347,11 +352,11 @@ int usb_submit_urb(struct urb *urb, gfp_t mem_flags)
347 max *= mult; 352 max *= mult;
348 } 353 }
349 354
350 if (urb->number_of_packets <= 0) 355 if (urb->number_of_packets <= 0)
351 return -EINVAL; 356 return -EINVAL;
352 for (n = 0; n < urb->number_of_packets; n++) { 357 for (n = 0; n < urb->number_of_packets; n++) {
353 len = urb->iso_frame_desc[n].length; 358 len = urb->iso_frame_desc[n].length;
354 if (len < 0 || len > max) 359 if (len < 0 || len > max)
355 return -EMSGSIZE; 360 return -EMSGSIZE;
356 urb->iso_frame_desc[n].status = -EXDEV; 361 urb->iso_frame_desc[n].status = -EXDEV;
357 urb->iso_frame_desc[n].actual_length = 0; 362 urb->iso_frame_desc[n].actual_length = 0;
@@ -416,7 +421,7 @@ int usb_submit_urb(struct urb *urb, gfp_t mem_flags)
416 /* too big? */ 421 /* too big? */
417 switch (dev->speed) { 422 switch (dev->speed) {
418 case USB_SPEED_HIGH: /* units are microframes */ 423 case USB_SPEED_HIGH: /* units are microframes */
419 // NOTE usb handles 2^15 424 /* NOTE usb handles 2^15 */
420 if (urb->interval > (1024 * 8)) 425 if (urb->interval > (1024 * 8))
421 urb->interval = 1024 * 8; 426 urb->interval = 1024 * 8;
422 max = 1024 * 8; 427 max = 1024 * 8;
@@ -426,12 +431,12 @@ int usb_submit_urb(struct urb *urb, gfp_t mem_flags)
426 if (xfertype == USB_ENDPOINT_XFER_INT) { 431 if (xfertype == USB_ENDPOINT_XFER_INT) {
427 if (urb->interval > 255) 432 if (urb->interval > 255)
428 return -EINVAL; 433 return -EINVAL;
429 // NOTE ohci only handles up to 32 434 /* NOTE ohci only handles up to 32 */
430 max = 128; 435 max = 128;
431 } else { 436 } else {
432 if (urb->interval > 1024) 437 if (urb->interval > 1024)
433 urb->interval = 1024; 438 urb->interval = 1024;
434 // NOTE usb and ohci handle up to 2^15 439 /* NOTE usb and ohci handle up to 2^15 */
435 max = 1024; 440 max = 1024;
436 } 441 }
437 break; 442 break;
@@ -444,6 +449,7 @@ int usb_submit_urb(struct urb *urb, gfp_t mem_flags)
444 449
445 return usb_hcd_submit_urb(urb, mem_flags); 450 return usb_hcd_submit_urb(urb, mem_flags);
446} 451}
452EXPORT_SYMBOL_GPL(usb_submit_urb);
447 453
448/*-------------------------------------------------------------------*/ 454/*-------------------------------------------------------------------*/
449 455
@@ -514,6 +520,7 @@ int usb_unlink_urb(struct urb *urb)
514 return -EIDRM; 520 return -EIDRM;
515 return usb_hcd_unlink_urb(urb, -ECONNRESET); 521 return usb_hcd_unlink_urb(urb, -ECONNRESET);
516} 522}
523EXPORT_SYMBOL_GPL(usb_unlink_urb);
517 524
518/** 525/**
519 * usb_kill_urb - cancel a transfer request and wait for it to finish 526 * usb_kill_urb - cancel a transfer request and wait for it to finish
@@ -553,6 +560,7 @@ void usb_kill_urb(struct urb *urb)
553 --urb->reject; 560 --urb->reject;
554 mutex_unlock(&reject_mutex); 561 mutex_unlock(&reject_mutex);
555} 562}
563EXPORT_SYMBOL_GPL(usb_kill_urb);
556 564
557/** 565/**
558 * usb_kill_anchored_urbs - cancel transfer requests en masse 566 * usb_kill_anchored_urbs - cancel transfer requests en masse
@@ -567,7 +575,8 @@ void usb_kill_anchored_urbs(struct usb_anchor *anchor)
567 575
568 spin_lock_irq(&anchor->lock); 576 spin_lock_irq(&anchor->lock);
569 while (!list_empty(&anchor->urb_list)) { 577 while (!list_empty(&anchor->urb_list)) {
570 victim = list_entry(anchor->urb_list.prev, struct urb, anchor_list); 578 victim = list_entry(anchor->urb_list.prev, struct urb,
579 anchor_list);
571 /* we must make sure the URB isn't freed before we kill it*/ 580 /* we must make sure the URB isn't freed before we kill it*/
572 usb_get_urb(victim); 581 usb_get_urb(victim);
573 spin_unlock_irq(&anchor->lock); 582 spin_unlock_irq(&anchor->lock);
@@ -595,11 +604,3 @@ int usb_wait_anchor_empty_timeout(struct usb_anchor *anchor,
595 msecs_to_jiffies(timeout)); 604 msecs_to_jiffies(timeout));
596} 605}
597EXPORT_SYMBOL_GPL(usb_wait_anchor_empty_timeout); 606EXPORT_SYMBOL_GPL(usb_wait_anchor_empty_timeout);
598
599EXPORT_SYMBOL(usb_init_urb);
600EXPORT_SYMBOL(usb_alloc_urb);
601EXPORT_SYMBOL(usb_free_urb);
602EXPORT_SYMBOL(usb_get_urb);
603EXPORT_SYMBOL(usb_submit_urb);
604EXPORT_SYMBOL(usb_unlink_urb);
605EXPORT_SYMBOL(usb_kill_urb);
diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c
index 8f142370103d..4e984060c984 100644
--- a/drivers/usb/core/usb.c
+++ b/drivers/usb/core/usb.c
@@ -96,6 +96,7 @@ struct usb_interface *usb_ifnum_to_if(const struct usb_device *dev,
96 96
97 return NULL; 97 return NULL;
98} 98}
99EXPORT_SYMBOL_GPL(usb_ifnum_to_if);
99 100
100/** 101/**
101 * usb_altnum_to_altsetting - get the altsetting structure with a given 102 * usb_altnum_to_altsetting - get the altsetting structure with a given
@@ -115,8 +116,9 @@ struct usb_interface *usb_ifnum_to_if(const struct usb_device *dev,
115 * Don't call this function unless you are bound to the intf interface 116 * Don't call this function unless you are bound to the intf interface
116 * or you have locked the device! 117 * or you have locked the device!
117 */ 118 */
118struct usb_host_interface *usb_altnum_to_altsetting(const struct usb_interface *intf, 119struct usb_host_interface *usb_altnum_to_altsetting(
119 unsigned int altnum) 120 const struct usb_interface *intf,
121 unsigned int altnum)
120{ 122{
121 int i; 123 int i;
122 124
@@ -126,13 +128,14 @@ struct usb_host_interface *usb_altnum_to_altsetting(const struct usb_interface *
126 } 128 }
127 return NULL; 129 return NULL;
128} 130}
131EXPORT_SYMBOL_GPL(usb_altnum_to_altsetting);
129 132
130struct find_interface_arg { 133struct find_interface_arg {
131 int minor; 134 int minor;
132 struct usb_interface *interface; 135 struct usb_interface *interface;
133}; 136};
134 137
135static int __find_interface(struct device * dev, void * data) 138static int __find_interface(struct device *dev, void *data)
136{ 139{
137 struct find_interface_arg *arg = data; 140 struct find_interface_arg *arg = data;
138 struct usb_interface *intf; 141 struct usb_interface *intf;
@@ -154,7 +157,7 @@ static int __find_interface(struct device * dev, void * data)
154 * @drv: the driver whose current configuration is considered 157 * @drv: the driver whose current configuration is considered
155 * @minor: the minor number of the desired device 158 * @minor: the minor number of the desired device
156 * 159 *
157 * This walks the driver device list and returns a pointer to the interface 160 * This walks the driver device list and returns a pointer to the interface
158 * with the matching minor. Note, this only works for devices that share the 161 * with the matching minor. Note, this only works for devices that share the
159 * USB major number. 162 * USB major number.
160 */ 163 */
@@ -170,6 +173,7 @@ struct usb_interface *usb_find_interface(struct usb_driver *drv, int minor)
170 __find_interface); 173 __find_interface);
171 return argb.interface; 174 return argb.interface;
172} 175}
176EXPORT_SYMBOL_GPL(usb_find_interface);
173 177
174/** 178/**
175 * usb_release_dev - free a usb device structure when all users of it are finished. 179 * usb_release_dev - free a usb device structure when all users of it are finished.
@@ -230,7 +234,7 @@ static int ksuspend_usb_init(void)
230 * singlethreaded. Its job doesn't justify running on more 234 * singlethreaded. Its job doesn't justify running on more
231 * than one CPU. 235 * than one CPU.
232 */ 236 */
233 ksuspend_usb_wq = create_freezeable_workqueue("ksuspend_usbd"); 237 ksuspend_usb_wq = create_singlethread_workqueue("ksuspend_usbd");
234 if (!ksuspend_usb_wq) 238 if (!ksuspend_usb_wq)
235 return -ENOMEM; 239 return -ENOMEM;
236 return 0; 240 return 0;
@@ -269,8 +273,8 @@ static unsigned usb_bus_is_wusb(struct usb_bus *bus)
269 * 273 *
270 * This call may not be used in a non-sleeping context. 274 * This call may not be used in a non-sleeping context.
271 */ 275 */
272struct usb_device * 276struct usb_device *usb_alloc_dev(struct usb_device *parent,
273usb_alloc_dev(struct usb_device *parent, struct usb_bus *bus, unsigned port1) 277 struct usb_bus *bus, unsigned port1)
274{ 278{
275 struct usb_device *dev; 279 struct usb_device *dev;
276 struct usb_hcd *usb_hcd = container_of(bus, struct usb_hcd, self); 280 struct usb_hcd *usb_hcd = container_of(bus, struct usb_hcd, self);
@@ -339,6 +343,8 @@ usb_alloc_dev(struct usb_device *parent, struct usb_bus *bus, unsigned port1)
339 mutex_init(&dev->pm_mutex); 343 mutex_init(&dev->pm_mutex);
340 INIT_DELAYED_WORK(&dev->autosuspend, usb_autosuspend_work); 344 INIT_DELAYED_WORK(&dev->autosuspend, usb_autosuspend_work);
341 dev->autosuspend_delay = usb_autosuspend_delay * HZ; 345 dev->autosuspend_delay = usb_autosuspend_delay * HZ;
346 dev->connect_time = jiffies;
347 dev->active_duration = -jiffies;
342#endif 348#endif
343 if (root_hub) /* Root hub always ok [and always wired] */ 349 if (root_hub) /* Root hub always ok [and always wired] */
344 dev->authorized = 1; 350 dev->authorized = 1;
@@ -367,6 +373,7 @@ struct usb_device *usb_get_dev(struct usb_device *dev)
367 get_device(&dev->dev); 373 get_device(&dev->dev);
368 return dev; 374 return dev;
369} 375}
376EXPORT_SYMBOL_GPL(usb_get_dev);
370 377
371/** 378/**
372 * usb_put_dev - release a use of the usb device structure 379 * usb_put_dev - release a use of the usb device structure
@@ -380,6 +387,7 @@ void usb_put_dev(struct usb_device *dev)
380 if (dev) 387 if (dev)
381 put_device(&dev->dev); 388 put_device(&dev->dev);
382} 389}
390EXPORT_SYMBOL_GPL(usb_put_dev);
383 391
384/** 392/**
385 * usb_get_intf - increments the reference count of the usb interface structure 393 * usb_get_intf - increments the reference count of the usb interface structure
@@ -400,6 +408,7 @@ struct usb_interface *usb_get_intf(struct usb_interface *intf)
400 get_device(&intf->dev); 408 get_device(&intf->dev);
401 return intf; 409 return intf;
402} 410}
411EXPORT_SYMBOL_GPL(usb_get_intf);
403 412
404/** 413/**
405 * usb_put_intf - release a use of the usb interface structure 414 * usb_put_intf - release a use of the usb interface structure
@@ -414,7 +423,7 @@ void usb_put_intf(struct usb_interface *intf)
414 if (intf) 423 if (intf)
415 put_device(&intf->dev); 424 put_device(&intf->dev);
416} 425}
417 426EXPORT_SYMBOL_GPL(usb_put_intf);
418 427
419/* USB device locking 428/* USB device locking
420 * 429 *
@@ -461,11 +470,11 @@ int usb_lock_device_for_reset(struct usb_device *udev,
461 return -EHOSTUNREACH; 470 return -EHOSTUNREACH;
462 if (iface) { 471 if (iface) {
463 switch (iface->condition) { 472 switch (iface->condition) {
464 case USB_INTERFACE_BINDING: 473 case USB_INTERFACE_BINDING:
465 return 0; 474 return 0;
466 case USB_INTERFACE_BOUND: 475 case USB_INTERFACE_BOUND:
467 break; 476 break;
468 default: 477 default:
469 return -EINTR; 478 return -EINTR;
470 } 479 }
471 } 480 }
@@ -487,7 +496,7 @@ int usb_lock_device_for_reset(struct usb_device *udev,
487 } 496 }
488 return 1; 497 return 1;
489} 498}
490 499EXPORT_SYMBOL_GPL(usb_lock_device_for_reset);
491 500
492static struct usb_device *match_device(struct usb_device *dev, 501static struct usb_device *match_device(struct usb_device *dev,
493 u16 vendor_id, u16 product_id) 502 u16 vendor_id, u16 product_id)
@@ -540,10 +549,10 @@ struct usb_device *usb_find_device(u16 vendor_id, u16 product_id)
540 struct list_head *buslist; 549 struct list_head *buslist;
541 struct usb_bus *bus; 550 struct usb_bus *bus;
542 struct usb_device *dev = NULL; 551 struct usb_device *dev = NULL;
543 552
544 mutex_lock(&usb_bus_list_lock); 553 mutex_lock(&usb_bus_list_lock);
545 for (buslist = usb_bus_list.next; 554 for (buslist = usb_bus_list.next;
546 buslist != &usb_bus_list; 555 buslist != &usb_bus_list;
547 buslist = buslist->next) { 556 buslist = buslist->next) {
548 bus = container_of(buslist, struct usb_bus, bus_list); 557 bus = container_of(buslist, struct usb_bus, bus_list);
549 if (!bus->root_hub) 558 if (!bus->root_hub)
@@ -576,6 +585,7 @@ int usb_get_current_frame_number(struct usb_device *dev)
576{ 585{
577 return usb_hcd_get_frame_number(dev); 586 return usb_hcd_get_frame_number(dev);
578} 587}
588EXPORT_SYMBOL_GPL(usb_get_current_frame_number);
579 589
580/*-------------------------------------------------------------------*/ 590/*-------------------------------------------------------------------*/
581/* 591/*
@@ -584,7 +594,7 @@ int usb_get_current_frame_number(struct usb_device *dev)
584 */ 594 */
585 595
586int __usb_get_extra_descriptor(char *buffer, unsigned size, 596int __usb_get_extra_descriptor(char *buffer, unsigned size,
587 unsigned char type, void **ptr) 597 unsigned char type, void **ptr)
588{ 598{
589 struct usb_descriptor_header *header; 599 struct usb_descriptor_header *header;
590 600
@@ -595,7 +605,7 @@ int __usb_get_extra_descriptor(char *buffer, unsigned size,
595 printk(KERN_ERR 605 printk(KERN_ERR
596 "%s: bogus descriptor, type %d length %d\n", 606 "%s: bogus descriptor, type %d length %d\n",
597 usbcore_name, 607 usbcore_name,
598 header->bDescriptorType, 608 header->bDescriptorType,
599 header->bLength); 609 header->bLength);
600 return -1; 610 return -1;
601 } 611 }
@@ -610,6 +620,7 @@ int __usb_get_extra_descriptor(char *buffer, unsigned size,
610 } 620 }
611 return -1; 621 return -1;
612} 622}
623EXPORT_SYMBOL_GPL(__usb_get_extra_descriptor);
613 624
614/** 625/**
615 * usb_buffer_alloc - allocate dma-consistent buffer for URB_NO_xxx_DMA_MAP 626 * usb_buffer_alloc - allocate dma-consistent buffer for URB_NO_xxx_DMA_MAP
@@ -633,17 +644,14 @@ int __usb_get_extra_descriptor(char *buffer, unsigned size,
633 * 644 *
634 * When the buffer is no longer used, free it with usb_buffer_free(). 645 * When the buffer is no longer used, free it with usb_buffer_free().
635 */ 646 */
636void *usb_buffer_alloc( 647void *usb_buffer_alloc(struct usb_device *dev, size_t size, gfp_t mem_flags,
637 struct usb_device *dev, 648 dma_addr_t *dma)
638 size_t size,
639 gfp_t mem_flags,
640 dma_addr_t *dma
641)
642{ 649{
643 if (!dev || !dev->bus) 650 if (!dev || !dev->bus)
644 return NULL; 651 return NULL;
645 return hcd_buffer_alloc(dev->bus, size, mem_flags, dma); 652 return hcd_buffer_alloc(dev->bus, size, mem_flags, dma);
646} 653}
654EXPORT_SYMBOL_GPL(usb_buffer_alloc);
647 655
648/** 656/**
649 * usb_buffer_free - free memory allocated with usb_buffer_alloc() 657 * usb_buffer_free - free memory allocated with usb_buffer_alloc()
@@ -656,12 +664,8 @@ void *usb_buffer_alloc(
656 * been allocated using usb_buffer_alloc(), and the parameters must match 664 * been allocated using usb_buffer_alloc(), and the parameters must match
657 * those provided in that allocation request. 665 * those provided in that allocation request.
658 */ 666 */
659void usb_buffer_free( 667void usb_buffer_free(struct usb_device *dev, size_t size, void *addr,
660 struct usb_device *dev, 668 dma_addr_t dma)
661 size_t size,
662 void *addr,
663 dma_addr_t dma
664)
665{ 669{
666 if (!dev || !dev->bus) 670 if (!dev || !dev->bus)
667 return; 671 return;
@@ -669,6 +673,7 @@ void usb_buffer_free(
669 return; 673 return;
670 hcd_buffer_free(dev->bus, size, addr, dma); 674 hcd_buffer_free(dev->bus, size, addr, dma);
671} 675}
676EXPORT_SYMBOL_GPL(usb_buffer_free);
672 677
673/** 678/**
674 * usb_buffer_map - create DMA mapping(s) for an urb 679 * usb_buffer_map - create DMA mapping(s) for an urb
@@ -708,14 +713,15 @@ struct urb *usb_buffer_map(struct urb *urb)
708 urb->setup_packet, 713 urb->setup_packet,
709 sizeof(struct usb_ctrlrequest), 714 sizeof(struct usb_ctrlrequest),
710 DMA_TO_DEVICE); 715 DMA_TO_DEVICE);
711 // FIXME generic api broken like pci, can't report errors 716 /* FIXME generic api broken like pci, can't report errors */
712 // if (urb->transfer_dma == DMA_ADDR_INVALID) return 0; 717 /* if (urb->transfer_dma == DMA_ADDR_INVALID) return 0; */
713 } else 718 } else
714 urb->transfer_dma = ~0; 719 urb->transfer_dma = ~0;
715 urb->transfer_flags |= (URB_NO_TRANSFER_DMA_MAP 720 urb->transfer_flags |= (URB_NO_TRANSFER_DMA_MAP
716 | URB_NO_SETUP_DMA_MAP); 721 | URB_NO_SETUP_DMA_MAP);
717 return urb; 722 return urb;
718} 723}
724EXPORT_SYMBOL_GPL(usb_buffer_map);
719#endif /* 0 */ 725#endif /* 0 */
720 726
721/* XXX DISABLED, no users currently. If you wish to re-enable this 727/* XXX DISABLED, no users currently. If you wish to re-enable this
@@ -753,6 +759,7 @@ void usb_buffer_dmasync(struct urb *urb)
753 DMA_TO_DEVICE); 759 DMA_TO_DEVICE);
754 } 760 }
755} 761}
762EXPORT_SYMBOL_GPL(usb_buffer_dmasync);
756#endif 763#endif
757 764
758/** 765/**
@@ -788,6 +795,7 @@ void usb_buffer_unmap(struct urb *urb)
788 urb->transfer_flags &= ~(URB_NO_TRANSFER_DMA_MAP 795 urb->transfer_flags &= ~(URB_NO_TRANSFER_DMA_MAP
789 | URB_NO_SETUP_DMA_MAP); 796 | URB_NO_SETUP_DMA_MAP);
790} 797}
798EXPORT_SYMBOL_GPL(usb_buffer_unmap);
791#endif /* 0 */ 799#endif /* 0 */
792 800
793/** 801/**
@@ -828,10 +836,11 @@ int usb_buffer_map_sg(const struct usb_device *dev, int is_in,
828 || !controller->dma_mask) 836 || !controller->dma_mask)
829 return -1; 837 return -1;
830 838
831 // FIXME generic api broken like pci, can't report errors 839 /* FIXME generic api broken like pci, can't report errors */
832 return dma_map_sg(controller, sg, nents, 840 return dma_map_sg(controller, sg, nents,
833 is_in ? DMA_FROM_DEVICE : DMA_TO_DEVICE); 841 is_in ? DMA_FROM_DEVICE : DMA_TO_DEVICE);
834} 842}
843EXPORT_SYMBOL_GPL(usb_buffer_map_sg);
835 844
836/* XXX DISABLED, no users currently. If you wish to re-enable this 845/* XXX DISABLED, no users currently. If you wish to re-enable this
837 * XXX please determine whether the sync is to transfer ownership of 846 * XXX please determine whether the sync is to transfer ownership of
@@ -865,6 +874,7 @@ void usb_buffer_dmasync_sg(const struct usb_device *dev, int is_in,
865 dma_sync_sg(controller, sg, n_hw_ents, 874 dma_sync_sg(controller, sg, n_hw_ents,
866 is_in ? DMA_FROM_DEVICE : DMA_TO_DEVICE); 875 is_in ? DMA_FROM_DEVICE : DMA_TO_DEVICE);
867} 876}
877EXPORT_SYMBOL_GPL(usb_buffer_dmasync_sg);
868#endif 878#endif
869 879
870/** 880/**
@@ -891,6 +901,7 @@ void usb_buffer_unmap_sg(const struct usb_device *dev, int is_in,
891 dma_unmap_sg(controller, sg, n_hw_ents, 901 dma_unmap_sg(controller, sg, n_hw_ents,
892 is_in ? DMA_FROM_DEVICE : DMA_TO_DEVICE); 902 is_in ? DMA_FROM_DEVICE : DMA_TO_DEVICE);
893} 903}
904EXPORT_SYMBOL_GPL(usb_buffer_unmap_sg);
894 905
895/* format to disable USB on kernel command line is: nousb */ 906/* format to disable USB on kernel command line is: nousb */
896__module_param_call("", nousb, param_set_bool, param_get_bool, &nousb, 0444); 907__module_param_call("", nousb, param_set_bool, param_get_bool, &nousb, 0444);
@@ -902,6 +913,7 @@ int usb_disabled(void)
902{ 913{
903 return nousb; 914 return nousb;
904} 915}
916EXPORT_SYMBOL_GPL(usb_disabled);
905 917
906/* 918/*
907 * Init 919 * Init
@@ -918,7 +930,7 @@ static int __init usb_init(void)
918 if (retval) 930 if (retval)
919 goto out; 931 goto out;
920 retval = bus_register(&usb_bus_type); 932 retval = bus_register(&usb_bus_type);
921 if (retval) 933 if (retval)
922 goto bus_register_failed; 934 goto bus_register_failed;
923 retval = usb_host_init(); 935 retval = usb_host_init();
924 if (retval) 936 if (retval)
@@ -983,45 +995,4 @@ static void __exit usb_exit(void)
983 995
984subsys_initcall(usb_init); 996subsys_initcall(usb_init);
985module_exit(usb_exit); 997module_exit(usb_exit);
986
987/*
988 * USB may be built into the kernel or be built as modules.
989 * These symbols are exported for device (or host controller)
990 * driver modules to use.
991 */
992
993EXPORT_SYMBOL(usb_disabled);
994
995EXPORT_SYMBOL_GPL(usb_get_intf);
996EXPORT_SYMBOL_GPL(usb_put_intf);
997
998EXPORT_SYMBOL(usb_put_dev);
999EXPORT_SYMBOL(usb_get_dev);
1000EXPORT_SYMBOL(usb_hub_tt_clear_buffer);
1001
1002EXPORT_SYMBOL(usb_lock_device_for_reset);
1003
1004EXPORT_SYMBOL(usb_find_interface);
1005EXPORT_SYMBOL(usb_ifnum_to_if);
1006EXPORT_SYMBOL(usb_altnum_to_altsetting);
1007
1008EXPORT_SYMBOL(__usb_get_extra_descriptor);
1009
1010EXPORT_SYMBOL(usb_get_current_frame_number);
1011
1012EXPORT_SYMBOL(usb_buffer_alloc);
1013EXPORT_SYMBOL(usb_buffer_free);
1014
1015#if 0
1016EXPORT_SYMBOL(usb_buffer_map);
1017EXPORT_SYMBOL(usb_buffer_dmasync);
1018EXPORT_SYMBOL(usb_buffer_unmap);
1019#endif
1020
1021EXPORT_SYMBOL(usb_buffer_map_sg);
1022#if 0
1023EXPORT_SYMBOL(usb_buffer_dmasync_sg);
1024#endif
1025EXPORT_SYMBOL(usb_buffer_unmap_sg);
1026
1027MODULE_LICENSE("GPL"); 998MODULE_LICENSE("GPL");
diff --git a/drivers/usb/core/usb.h b/drivers/usb/core/usb.h
index c52626c51f70..2375194a9d43 100644
--- a/drivers/usb/core/usb.h
+++ b/drivers/usb/core/usb.h
@@ -1,22 +1,23 @@
1/* Functions local to drivers/usb/core/ */ 1/* Functions local to drivers/usb/core/ */
2 2
3extern int usb_create_sysfs_dev_files (struct usb_device *dev); 3extern int usb_create_sysfs_dev_files(struct usb_device *dev);
4extern void usb_remove_sysfs_dev_files (struct usb_device *dev); 4extern void usb_remove_sysfs_dev_files(struct usb_device *dev);
5extern int usb_create_sysfs_intf_files (struct usb_interface *intf); 5extern int usb_create_sysfs_intf_files(struct usb_interface *intf);
6extern void usb_remove_sysfs_intf_files (struct usb_interface *intf); 6extern void usb_remove_sysfs_intf_files(struct usb_interface *intf);
7extern int usb_create_ep_files(struct device *parent, struct usb_host_endpoint *endpoint, 7extern int usb_create_ep_files(struct device *parent,
8 struct usb_host_endpoint *endpoint,
8 struct usb_device *udev); 9 struct usb_device *udev);
9extern void usb_remove_ep_files(struct usb_host_endpoint *endpoint); 10extern void usb_remove_ep_files(struct usb_host_endpoint *endpoint);
10 11
11extern void usb_enable_endpoint(struct usb_device *dev, 12extern void usb_enable_endpoint(struct usb_device *dev,
12 struct usb_host_endpoint *ep); 13 struct usb_host_endpoint *ep);
13extern void usb_disable_endpoint (struct usb_device *dev, unsigned int epaddr); 14extern void usb_disable_endpoint(struct usb_device *dev, unsigned int epaddr);
14extern void usb_disable_interface (struct usb_device *dev, 15extern void usb_disable_interface(struct usb_device *dev,
15 struct usb_interface *intf); 16 struct usb_interface *intf);
16extern void usb_release_interface_cache(struct kref *ref); 17extern void usb_release_interface_cache(struct kref *ref);
17extern void usb_disable_device (struct usb_device *dev, int skip_ep0); 18extern void usb_disable_device(struct usb_device *dev, int skip_ep0);
18extern int usb_deauthorize_device (struct usb_device *); 19extern int usb_deauthorize_device(struct usb_device *);
19extern int usb_authorize_device (struct usb_device *); 20extern int usb_authorize_device(struct usb_device *);
20extern void usb_detect_quirks(struct usb_device *udev); 21extern void usb_detect_quirks(struct usb_device *udev);
21 22
22extern int usb_get_device_descriptor(struct usb_device *dev, 23extern int usb_get_device_descriptor(struct usb_device *dev,
diff --git a/drivers/usb/gadget/Kconfig b/drivers/usb/gadget/Kconfig
index 77a3759d6fc7..c13955164686 100644
--- a/drivers/usb/gadget/Kconfig
+++ b/drivers/usb/gadget/Kconfig
@@ -12,10 +12,9 @@
12# With help from a special transceiver and a "Mini-AB" jack, systems with 12# With help from a special transceiver and a "Mini-AB" jack, systems with
13# both kinds of controller can also support "USB On-the-Go" (CONFIG_USB_OTG). 13# both kinds of controller can also support "USB On-the-Go" (CONFIG_USB_OTG).
14# 14#
15menu "USB Gadget Support"
16 15
17config USB_GADGET 16menuconfig USB_GADGET
18 tristate "Support for USB Gadgets" 17 tristate "USB Gadget Support"
19 help 18 help
20 USB is a master/slave protocol, organized with one master 19 USB is a master/slave protocol, organized with one master
21 host (such as a PC) controlling up to 127 peripheral devices. 20 host (such as a PC) controlling up to 127 peripheral devices.
@@ -42,6 +41,8 @@ config USB_GADGET
42 For more information, see <http://www.linux-usb.org/gadget> and 41 For more information, see <http://www.linux-usb.org/gadget> and
43 the kernel DocBook documentation for this API. 42 the kernel DocBook documentation for this API.
44 43
44if USB_GADGET
45
45config USB_GADGET_DEBUG 46config USB_GADGET_DEBUG
46 boolean "Debugging messages" 47 boolean "Debugging messages"
47 depends on USB_GADGET && DEBUG_KERNEL && EXPERIMENTAL 48 depends on USB_GADGET && DEBUG_KERNEL && EXPERIMENTAL
@@ -220,6 +221,16 @@ config USB_M66592
220 default USB_GADGET 221 default USB_GADGET
221 select USB_GADGET_SELECTED 222 select USB_GADGET_SELECTED
222 223
224config SUPERH_BUILT_IN_M66592
225 boolean "Enable SuperH built-in USB like the M66592"
226 depends on USB_GADGET_M66592 && CPU_SUBTYPE_SH7722
227 help
228 SH7722 has USB like the M66592.
229
230 The transfer rate is very slow when use "Ethernet Gadget".
231 However, this problem is improved if change a value of
232 NET_IP_ALIGN to 4.
233
223config USB_GADGET_GOKU 234config USB_GADGET_GOKU
224 boolean "Toshiba TC86C001 'Goku-S'" 235 boolean "Toshiba TC86C001 'Goku-S'"
225 depends on PCI 236 depends on PCI
@@ -538,6 +549,20 @@ config USB_MIDI_GADGET
538 Say "y" to link the driver statically, or "m" to build a 549 Say "y" to link the driver statically, or "m" to build a
539 dynamically linked module called "g_midi". 550 dynamically linked module called "g_midi".
540 551
552config USB_G_PRINTER
553 tristate "Printer Gadget"
554 help
555 The Printer Gadget channels data between the USB host and a
556 userspace program driving the print engine. The user space
557 program reads and writes the device file /dev/g_printer to
558 receive or send printer data. It can use ioctl calls to
559 the device file to get or set printer status.
560
561 Say "y" to link the driver statically, or "m" to build a
562 dynamically linked module called "g_printer".
563
564 For more information, see Documentation/usb/gadget_printer.txt
565 which includes sample code for accessing the device file.
541 566
542# put drivers that need isochronous transfer support (for audio 567# put drivers that need isochronous transfer support (for audio
543# or video class gadget drivers), or specific hardware, here. 568# or video class gadget drivers), or specific hardware, here.
@@ -546,4 +571,4 @@ config USB_MIDI_GADGET
546 571
547endchoice 572endchoice
548 573
549endmenu 574endif # USB_GADGET
diff --git a/drivers/usb/gadget/Makefile b/drivers/usb/gadget/Makefile
index 904e57bf6112..c3aab80b6c76 100644
--- a/drivers/usb/gadget/Makefile
+++ b/drivers/usb/gadget/Makefile
@@ -28,6 +28,8 @@ g_midi-objs := gmidi.o usbstring.o config.o epautoconf.o
28gadgetfs-objs := inode.o 28gadgetfs-objs := inode.o
29g_file_storage-objs := file_storage.o usbstring.o config.o \ 29g_file_storage-objs := file_storage.o usbstring.o config.o \
30 epautoconf.o 30 epautoconf.o
31g_printer-objs := printer.o usbstring.o config.o \
32 epautoconf.o
31 33
32ifeq ($(CONFIG_USB_ETH_RNDIS),y) 34ifeq ($(CONFIG_USB_ETH_RNDIS),y)
33 g_ether-objs += rndis.o 35 g_ether-objs += rndis.o
@@ -38,5 +40,6 @@ obj-$(CONFIG_USB_ETH) += g_ether.o
38obj-$(CONFIG_USB_GADGETFS) += gadgetfs.o 40obj-$(CONFIG_USB_GADGETFS) += gadgetfs.o
39obj-$(CONFIG_USB_FILE_STORAGE) += g_file_storage.o 41obj-$(CONFIG_USB_FILE_STORAGE) += g_file_storage.o
40obj-$(CONFIG_USB_G_SERIAL) += g_serial.o 42obj-$(CONFIG_USB_G_SERIAL) += g_serial.o
43obj-$(CONFIG_USB_G_PRINTER) += g_printer.o
41obj-$(CONFIG_USB_MIDI_GADGET) += g_midi.o 44obj-$(CONFIG_USB_MIDI_GADGET) += g_midi.o
42 45
diff --git a/drivers/usb/gadget/amd5536udc.c b/drivers/usb/gadget/amd5536udc.c
index c72e9620bf8d..b663f23f2642 100644
--- a/drivers/usb/gadget/amd5536udc.c
+++ b/drivers/usb/gadget/amd5536udc.c
@@ -1244,7 +1244,7 @@ udc_queue(struct usb_ep *usbep, struct usb_request *usbreq, gfp_t gfp)
1244 /* stop OUT naking */ 1244 /* stop OUT naking */
1245 if (!ep->in) { 1245 if (!ep->in) {
1246 if (!use_dma && udc_rxfifo_pending) { 1246 if (!use_dma && udc_rxfifo_pending) {
1247 DBG(dev, "udc_queue(): pending bytes in" 1247 DBG(dev, "udc_queue(): pending bytes in "
1248 "rxfifo after nyet\n"); 1248 "rxfifo after nyet\n");
1249 /* 1249 /*
1250 * read pending bytes afer nyet: 1250 * read pending bytes afer nyet:
@@ -2038,6 +2038,7 @@ int usb_gadget_unregister_driver(struct usb_gadget_driver *driver)
2038 spin_unlock_irqrestore(&dev->lock, flags); 2038 spin_unlock_irqrestore(&dev->lock, flags);
2039 2039
2040 driver->unbind(&dev->gadget); 2040 driver->unbind(&dev->gadget);
2041 dev->gadget.dev.driver = NULL;
2041 dev->driver = NULL; 2042 dev->driver = NULL;
2042 2043
2043 /* set SD */ 2044 /* set SD */
diff --git a/drivers/usb/gadget/at91_udc.c b/drivers/usb/gadget/at91_udc.c
index cd62b029d176..a83e8b798ec9 100644
--- a/drivers/usb/gadget/at91_udc.c
+++ b/drivers/usb/gadget/at91_udc.c
@@ -21,8 +21,7 @@
21 * Boston, MA 02111-1307, USA. 21 * Boston, MA 02111-1307, USA.
22 */ 22 */
23 23
24#undef DEBUG 24#undef VERBOSE_DEBUG
25#undef VERBOSE
26#undef PACKET_TRACE 25#undef PACKET_TRACE
27 26
28#include <linux/kernel.h> 27#include <linux/kernel.h>
@@ -46,8 +45,8 @@
46#include <asm/irq.h> 45#include <asm/irq.h>
47#include <asm/system.h> 46#include <asm/system.h>
48#include <asm/mach-types.h> 47#include <asm/mach-types.h>
48#include <asm/gpio.h>
49 49
50#include <asm/arch/gpio.h>
51#include <asm/arch/board.h> 50#include <asm/arch/board.h>
52#include <asm/arch/cpu.h> 51#include <asm/arch/cpu.h>
53#include <asm/arch/at91sam9261_matrix.h> 52#include <asm/arch/at91sam9261_matrix.h>
@@ -580,7 +579,7 @@ static int at91_ep_disable (struct usb_ep * _ep)
580 */ 579 */
581 580
582static struct usb_request * 581static struct usb_request *
583at91_ep_alloc_request(struct usb_ep *_ep, unsigned int gfp_flags) 582at91_ep_alloc_request(struct usb_ep *_ep, gfp_t gfp_flags)
584{ 583{
585 struct at91_request *req; 584 struct at91_request *req;
586 585
@@ -881,6 +880,8 @@ static void clk_off(struct at91_udc *udc)
881 */ 880 */
882static void pullup(struct at91_udc *udc, int is_on) 881static void pullup(struct at91_udc *udc, int is_on)
883{ 882{
883 int active = !udc->board.pullup_active_low;
884
884 if (!udc->enabled || !udc->vbus) 885 if (!udc->enabled || !udc->vbus)
885 is_on = 0; 886 is_on = 0;
886 DBG("%sactive\n", is_on ? "" : "in"); 887 DBG("%sactive\n", is_on ? "" : "in");
@@ -890,7 +891,7 @@ static void pullup(struct at91_udc *udc, int is_on)
890 at91_udp_write(udc, AT91_UDP_ICR, AT91_UDP_RXRSM); 891 at91_udp_write(udc, AT91_UDP_ICR, AT91_UDP_RXRSM);
891 at91_udp_write(udc, AT91_UDP_TXVC, 0); 892 at91_udp_write(udc, AT91_UDP_TXVC, 0);
892 if (cpu_is_at91rm9200()) 893 if (cpu_is_at91rm9200())
893 at91_set_gpio_value(udc->board.pullup_pin, 1); 894 gpio_set_value(udc->board.pullup_pin, active);
894 else if (cpu_is_at91sam9260() || cpu_is_at91sam9263()) { 895 else if (cpu_is_at91sam9260() || cpu_is_at91sam9263()) {
895 u32 txvc = at91_udp_read(udc, AT91_UDP_TXVC); 896 u32 txvc = at91_udp_read(udc, AT91_UDP_TXVC);
896 897
@@ -908,7 +909,7 @@ static void pullup(struct at91_udc *udc, int is_on)
908 at91_udp_write(udc, AT91_UDP_IDR, AT91_UDP_RXRSM); 909 at91_udp_write(udc, AT91_UDP_IDR, AT91_UDP_RXRSM);
909 at91_udp_write(udc, AT91_UDP_TXVC, AT91_UDP_TXVC_TXVDIS); 910 at91_udp_write(udc, AT91_UDP_TXVC, AT91_UDP_TXVC_TXVDIS);
910 if (cpu_is_at91rm9200()) 911 if (cpu_is_at91rm9200())
911 at91_set_gpio_value(udc->board.pullup_pin, 0); 912 gpio_set_value(udc->board.pullup_pin, !active);
912 else if (cpu_is_at91sam9260() || cpu_is_at91sam9263()) { 913 else if (cpu_is_at91sam9260() || cpu_is_at91sam9263()) {
913 u32 txvc = at91_udp_read(udc, AT91_UDP_TXVC); 914 u32 txvc = at91_udp_read(udc, AT91_UDP_TXVC);
914 915
@@ -1153,7 +1154,7 @@ static void handle_setup(struct at91_udc *udc, struct at91_ep *ep, u32 csr)
1153 | USB_REQ_GET_STATUS: 1154 | USB_REQ_GET_STATUS:
1154 tmp = w_index & USB_ENDPOINT_NUMBER_MASK; 1155 tmp = w_index & USB_ENDPOINT_NUMBER_MASK;
1155 ep = &udc->ep[tmp]; 1156 ep = &udc->ep[tmp];
1156 if (tmp > NUM_ENDPOINTS || (tmp && !ep->desc)) 1157 if (tmp >= NUM_ENDPOINTS || (tmp && !ep->desc))
1157 goto stall; 1158 goto stall;
1158 1159
1159 if (tmp) { 1160 if (tmp) {
@@ -1176,7 +1177,7 @@ static void handle_setup(struct at91_udc *udc, struct at91_ep *ep, u32 csr)
1176 | USB_REQ_SET_FEATURE: 1177 | USB_REQ_SET_FEATURE:
1177 tmp = w_index & USB_ENDPOINT_NUMBER_MASK; 1178 tmp = w_index & USB_ENDPOINT_NUMBER_MASK;
1178 ep = &udc->ep[tmp]; 1179 ep = &udc->ep[tmp];
1179 if (w_value != USB_ENDPOINT_HALT || tmp > NUM_ENDPOINTS) 1180 if (w_value != USB_ENDPOINT_HALT || tmp >= NUM_ENDPOINTS)
1180 goto stall; 1181 goto stall;
1181 if (!ep->desc || ep->is_iso) 1182 if (!ep->desc || ep->is_iso)
1182 goto stall; 1183 goto stall;
@@ -1195,7 +1196,7 @@ static void handle_setup(struct at91_udc *udc, struct at91_ep *ep, u32 csr)
1195 | USB_REQ_CLEAR_FEATURE: 1196 | USB_REQ_CLEAR_FEATURE:
1196 tmp = w_index & USB_ENDPOINT_NUMBER_MASK; 1197 tmp = w_index & USB_ENDPOINT_NUMBER_MASK;
1197 ep = &udc->ep[tmp]; 1198 ep = &udc->ep[tmp];
1198 if (w_value != USB_ENDPOINT_HALT || tmp > NUM_ENDPOINTS) 1199 if (w_value != USB_ENDPOINT_HALT || tmp >= NUM_ENDPOINTS)
1199 goto stall; 1200 goto stall;
1200 if (tmp == 0) 1201 if (tmp == 0)
1201 goto succeed; 1202 goto succeed;
@@ -1551,7 +1552,7 @@ static irqreturn_t at91_vbus_irq(int irq, void *_udc)
1551 1552
1552 /* vbus needs at least brief debouncing */ 1553 /* vbus needs at least brief debouncing */
1553 udelay(10); 1554 udelay(10);
1554 value = at91_get_gpio_value(udc->board.vbus_pin); 1555 value = gpio_get_value(udc->board.vbus_pin);
1555 if (value != udc->vbus) 1556 if (value != udc->vbus)
1556 at91_vbus_session(&udc->gadget, value); 1557 at91_vbus_session(&udc->gadget, value);
1557 1558
@@ -1616,6 +1617,8 @@ int usb_gadget_unregister_driver (struct usb_gadget_driver *driver)
1616 local_irq_enable(); 1617 local_irq_enable();
1617 1618
1618 driver->unbind(&udc->gadget); 1619 driver->unbind(&udc->gadget);
1620 udc->gadget.dev.driver = NULL;
1621 udc->gadget.dev.driver_data = NULL;
1619 udc->driver = NULL; 1622 udc->driver = NULL;
1620 1623
1621 DBG("unbound from %s\n", driver->driver.name); 1624 DBG("unbound from %s\n", driver->driver.name);
@@ -1645,12 +1648,12 @@ static int __init at91udc_probe(struct platform_device *pdev)
1645 } 1648 }
1646 1649
1647 if (pdev->num_resources != 2) { 1650 if (pdev->num_resources != 2) {
1648 DBG("invalid num_resources"); 1651 DBG("invalid num_resources\n");
1649 return -ENODEV; 1652 return -ENODEV;
1650 } 1653 }
1651 if ((pdev->resource[0].flags != IORESOURCE_MEM) 1654 if ((pdev->resource[0].flags != IORESOURCE_MEM)
1652 || (pdev->resource[1].flags != IORESOURCE_IRQ)) { 1655 || (pdev->resource[1].flags != IORESOURCE_IRQ)) {
1653 DBG("invalid resource type"); 1656 DBG("invalid resource type\n");
1654 return -ENODEV; 1657 return -ENODEV;
1655 } 1658 }
1656 1659
@@ -1672,10 +1675,26 @@ static int __init at91udc_probe(struct platform_device *pdev)
1672 udc->pdev = pdev; 1675 udc->pdev = pdev;
1673 udc->enabled = 0; 1676 udc->enabled = 0;
1674 1677
1678 /* rm9200 needs manual D+ pullup; off by default */
1679 if (cpu_is_at91rm9200()) {
1680 if (udc->board.pullup_pin <= 0) {
1681 DBG("no D+ pullup?\n");
1682 retval = -ENODEV;
1683 goto fail0;
1684 }
1685 retval = gpio_request(udc->board.pullup_pin, "udc_pullup");
1686 if (retval) {
1687 DBG("D+ pullup is busy\n");
1688 goto fail0;
1689 }
1690 gpio_direction_output(udc->board.pullup_pin,
1691 udc->board.pullup_active_low);
1692 }
1693
1675 udc->udp_baseaddr = ioremap(res->start, res->end - res->start + 1); 1694 udc->udp_baseaddr = ioremap(res->start, res->end - res->start + 1);
1676 if (!udc->udp_baseaddr) { 1695 if (!udc->udp_baseaddr) {
1677 release_mem_region(res->start, res->end - res->start + 1); 1696 retval = -ENOMEM;
1678 return -ENOMEM; 1697 goto fail0a;
1679 } 1698 }
1680 1699
1681 udc_reinit(udc); 1700 udc_reinit(udc);
@@ -1686,12 +1705,13 @@ static int __init at91udc_probe(struct platform_device *pdev)
1686 if (IS_ERR(udc->iclk) || IS_ERR(udc->fclk)) { 1705 if (IS_ERR(udc->iclk) || IS_ERR(udc->fclk)) {
1687 DBG("clocks missing\n"); 1706 DBG("clocks missing\n");
1688 retval = -ENODEV; 1707 retval = -ENODEV;
1689 goto fail0; 1708 /* NOTE: we "know" here that refcounts on these are NOPs */
1709 goto fail0b;
1690 } 1710 }
1691 1711
1692 retval = device_register(&udc->gadget.dev); 1712 retval = device_register(&udc->gadget.dev);
1693 if (retval < 0) 1713 if (retval < 0)
1694 goto fail0; 1714 goto fail0b;
1695 1715
1696 /* don't do anything until we have both gadget driver and VBUS */ 1716 /* don't do anything until we have both gadget driver and VBUS */
1697 clk_enable(udc->iclk); 1717 clk_enable(udc->iclk);
@@ -1703,25 +1723,32 @@ static int __init at91udc_probe(struct platform_device *pdev)
1703 1723
1704 /* request UDC and maybe VBUS irqs */ 1724 /* request UDC and maybe VBUS irqs */
1705 udc->udp_irq = platform_get_irq(pdev, 0); 1725 udc->udp_irq = platform_get_irq(pdev, 0);
1706 if (request_irq(udc->udp_irq, at91_udc_irq, 1726 retval = request_irq(udc->udp_irq, at91_udc_irq,
1707 IRQF_DISABLED, driver_name, udc)) { 1727 IRQF_DISABLED, driver_name, udc);
1728 if (retval < 0) {
1708 DBG("request irq %d failed\n", udc->udp_irq); 1729 DBG("request irq %d failed\n", udc->udp_irq);
1709 retval = -EBUSY;
1710 goto fail1; 1730 goto fail1;
1711 } 1731 }
1712 if (udc->board.vbus_pin > 0) { 1732 if (udc->board.vbus_pin > 0) {
1733 retval = gpio_request(udc->board.vbus_pin, "udc_vbus");
1734 if (retval < 0) {
1735 DBG("request vbus pin failed\n");
1736 goto fail2;
1737 }
1738 gpio_direction_input(udc->board.vbus_pin);
1739
1713 /* 1740 /*
1714 * Get the initial state of VBUS - we cannot expect 1741 * Get the initial state of VBUS - we cannot expect
1715 * a pending interrupt. 1742 * a pending interrupt.
1716 */ 1743 */
1717 udc->vbus = at91_get_gpio_value(udc->board.vbus_pin); 1744 udc->vbus = gpio_get_value(udc->board.vbus_pin);
1718 if (request_irq(udc->board.vbus_pin, at91_vbus_irq, 1745 if (request_irq(udc->board.vbus_pin, at91_vbus_irq,
1719 IRQF_DISABLED, driver_name, udc)) { 1746 IRQF_DISABLED, driver_name, udc)) {
1720 DBG("request vbus irq %d failed\n", 1747 DBG("request vbus irq %d failed\n",
1721 udc->board.vbus_pin); 1748 udc->board.vbus_pin);
1722 free_irq(udc->udp_irq, udc); 1749 free_irq(udc->udp_irq, udc);
1723 retval = -EBUSY; 1750 retval = -EBUSY;
1724 goto fail1; 1751 goto fail3;
1725 } 1752 }
1726 } else { 1753 } else {
1727 DBG("no VBUS detection, assuming always-on\n"); 1754 DBG("no VBUS detection, assuming always-on\n");
@@ -1734,8 +1761,18 @@ static int __init at91udc_probe(struct platform_device *pdev)
1734 INFO("%s version %s\n", driver_name, DRIVER_VERSION); 1761 INFO("%s version %s\n", driver_name, DRIVER_VERSION);
1735 return 0; 1762 return 0;
1736 1763
1764fail3:
1765 if (udc->board.vbus_pin > 0)
1766 gpio_free(udc->board.vbus_pin);
1767fail2:
1768 free_irq(udc->udp_irq, udc);
1737fail1: 1769fail1:
1738 device_unregister(&udc->gadget.dev); 1770 device_unregister(&udc->gadget.dev);
1771fail0b:
1772 iounmap(udc->udp_baseaddr);
1773fail0a:
1774 if (cpu_is_at91rm9200())
1775 gpio_free(udc->board.pullup_pin);
1739fail0: 1776fail0:
1740 release_mem_region(res->start, res->end - res->start + 1); 1777 release_mem_region(res->start, res->end - res->start + 1);
1741 DBG("%s probe failed, %d\n", driver_name, retval); 1778 DBG("%s probe failed, %d\n", driver_name, retval);
@@ -1756,12 +1793,18 @@ static int __exit at91udc_remove(struct platform_device *pdev)
1756 1793
1757 device_init_wakeup(&pdev->dev, 0); 1794 device_init_wakeup(&pdev->dev, 0);
1758 remove_debug_file(udc); 1795 remove_debug_file(udc);
1759 if (udc->board.vbus_pin > 0) 1796 if (udc->board.vbus_pin > 0) {
1760 free_irq(udc->board.vbus_pin, udc); 1797 free_irq(udc->board.vbus_pin, udc);
1798 gpio_free(udc->board.vbus_pin);
1799 }
1761 free_irq(udc->udp_irq, udc); 1800 free_irq(udc->udp_irq, udc);
1762 device_unregister(&udc->gadget.dev); 1801 device_unregister(&udc->gadget.dev);
1763 1802
1764 iounmap(udc->udp_baseaddr); 1803 iounmap(udc->udp_baseaddr);
1804
1805 if (cpu_is_at91rm9200())
1806 gpio_free(udc->board.pullup_pin);
1807
1765 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 1808 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1766 release_mem_region(res->start, res->end - res->start + 1); 1809 release_mem_region(res->start, res->end - res->start + 1);
1767 1810
diff --git a/drivers/usb/gadget/at91_udc.h b/drivers/usb/gadget/at91_udc.h
index 7e34e2f864f9..a973f2a50fb9 100644
--- a/drivers/usb/gadget/at91_udc.h
+++ b/drivers/usb/gadget/at91_udc.h
@@ -53,7 +53,7 @@
53#define AT91_UDP_RXRSM (1 << 9) /* USB Resume Interrupt Status */ 53#define AT91_UDP_RXRSM (1 << 9) /* USB Resume Interrupt Status */
54#define AT91_UDP_EXTRSM (1 << 10) /* External Resume Interrupt Status [AT91RM9200 only] */ 54#define AT91_UDP_EXTRSM (1 << 10) /* External Resume Interrupt Status [AT91RM9200 only] */
55#define AT91_UDP_SOFINT (1 << 11) /* Start of Frame Interrupt Status */ 55#define AT91_UDP_SOFINT (1 << 11) /* Start of Frame Interrupt Status */
56#define AT91_UDP_ENDBUSRES (1 << 12) /* End of Bus Reset Interrpt Status */ 56#define AT91_UDP_ENDBUSRES (1 << 12) /* End of Bus Reset Interrupt Status */
57#define AT91_UDP_WAKEUP (1 << 13) /* USB Wakeup Interrupt Status [AT91RM9200 only] */ 57#define AT91_UDP_WAKEUP (1 << 13) /* USB Wakeup Interrupt Status [AT91RM9200 only] */
58 58
59#define AT91_UDP_ICR 0x20 /* Interrupt Clear Register */ 59#define AT91_UDP_ICR 0x20 /* Interrupt Clear Register */
@@ -158,13 +158,7 @@ struct at91_request {
158 158
159/*-------------------------------------------------------------------------*/ 159/*-------------------------------------------------------------------------*/
160 160
161#ifdef DEBUG 161#ifdef VERBOSE_DEBUG
162#define DBG(stuff...) printk(KERN_DEBUG "udc: " stuff)
163#else
164#define DBG(stuff...) do{}while(0)
165#endif
166
167#ifdef VERBOSE
168# define VDBG DBG 162# define VDBG DBG
169#else 163#else
170# define VDBG(stuff...) do{}while(0) 164# define VDBG(stuff...) do{}while(0)
@@ -176,9 +170,10 @@ struct at91_request {
176# define PACKET(stuff...) do{}while(0) 170# define PACKET(stuff...) do{}while(0)
177#endif 171#endif
178 172
179#define ERR(stuff...) printk(KERN_ERR "udc: " stuff) 173#define ERR(stuff...) pr_err("udc: " stuff)
180#define WARN(stuff...) printk(KERN_WARNING "udc: " stuff) 174#define WARN(stuff...) pr_warning("udc: " stuff)
181#define INFO(stuff...) printk(KERN_INFO "udc: " stuff) 175#define INFO(stuff...) pr_info("udc: " stuff)
176#define DBG(stuff...) pr_debug("udc: " stuff)
182 177
183#endif 178#endif
184 179
diff --git a/drivers/usb/gadget/atmel_usba_udc.c b/drivers/usb/gadget/atmel_usba_udc.c
index 4fb5ff469574..af8b2a3a2d4a 100644
--- a/drivers/usb/gadget/atmel_usba_udc.c
+++ b/drivers/usb/gadget/atmel_usba_udc.c
@@ -1384,8 +1384,7 @@ delegate:
1384 return retval; 1384 return retval;
1385 1385
1386stall: 1386stall:
1387 printk(KERN_ERR 1387 pr_err("udc: %s: Invalid setup request: %02x.%02x v%04x i%04x l%d, "
1388 "udc: %s: Invalid setup request: %02x.%02x v%04x i%04x l%d, "
1389 "halting endpoint...\n", 1388 "halting endpoint...\n",
1390 ep->ep.name, crq->bRequestType, crq->bRequest, 1389 ep->ep.name, crq->bRequestType, crq->bRequest,
1391 le16_to_cpu(crq->wValue), le16_to_cpu(crq->wIndex), 1390 le16_to_cpu(crq->wValue), le16_to_cpu(crq->wIndex),
@@ -1456,8 +1455,7 @@ restart:
1456 set_protocol_stall(udc, ep); 1455 set_protocol_stall(udc, ep);
1457 break; 1456 break;
1458 default: 1457 default:
1459 printk(KERN_ERR 1458 pr_err("udc: %s: TXCOMP: Invalid endpoint state %d, "
1460 "udc: %s: TXCOMP: Invalid endpoint state %d, "
1461 "halting endpoint...\n", 1459 "halting endpoint...\n",
1462 ep->ep.name, ep->state); 1460 ep->ep.name, ep->state);
1463 set_protocol_stall(udc, ep); 1461 set_protocol_stall(udc, ep);
@@ -1486,8 +1484,7 @@ restart:
1486 default: 1484 default:
1487 usba_ep_writel(ep, CLR_STA, USBA_RX_BK_RDY); 1485 usba_ep_writel(ep, CLR_STA, USBA_RX_BK_RDY);
1488 usba_ep_writel(ep, CTL_DIS, USBA_RX_BK_RDY); 1486 usba_ep_writel(ep, CTL_DIS, USBA_RX_BK_RDY);
1489 printk(KERN_ERR 1487 pr_err("udc: %s: RXRDY: Invalid endpoint state %d, "
1490 "udc: %s: RXRDY: Invalid endpoint state %d, "
1491 "halting endpoint...\n", 1488 "halting endpoint...\n",
1492 ep->ep.name, ep->state); 1489 ep->ep.name, ep->state);
1493 set_protocol_stall(udc, ep); 1490 set_protocol_stall(udc, ep);
@@ -1532,7 +1529,7 @@ restart:
1532 pkt_len = USBA_BFEXT(BYTE_COUNT, usba_ep_readl(ep, STA)); 1529 pkt_len = USBA_BFEXT(BYTE_COUNT, usba_ep_readl(ep, STA));
1533 DBG(DBG_HW, "Packet length: %u\n", pkt_len); 1530 DBG(DBG_HW, "Packet length: %u\n", pkt_len);
1534 if (pkt_len != sizeof(crq)) { 1531 if (pkt_len != sizeof(crq)) {
1535 printk(KERN_WARNING "udc: Invalid packet length %u " 1532 pr_warning("udc: Invalid packet length %u "
1536 "(expected %lu)\n", pkt_len, sizeof(crq)); 1533 "(expected %lu)\n", pkt_len, sizeof(crq));
1537 set_protocol_stall(udc, ep); 1534 set_protocol_stall(udc, ep);
1538 return; 1535 return;
diff --git a/drivers/usb/gadget/atmel_usba_udc.h b/drivers/usb/gadget/atmel_usba_udc.h
index a68304e31a68..08bf6f9aaf7e 100644
--- a/drivers/usb/gadget/atmel_usba_udc.h
+++ b/drivers/usb/gadget/atmel_usba_udc.h
@@ -216,7 +216,6 @@
216#define FIFO_IOMEM_ID 0 216#define FIFO_IOMEM_ID 0
217#define CTRL_IOMEM_ID 1 217#define CTRL_IOMEM_ID 1
218 218
219#ifdef DEBUG
220#define DBG_ERR 0x0001 /* report all error returns */ 219#define DBG_ERR 0x0001 /* report all error returns */
221#define DBG_HW 0x0002 /* debug hardware initialization */ 220#define DBG_HW 0x0002 /* debug hardware initialization */
222#define DBG_GADGET 0x0004 /* calls to/from gadget driver */ 221#define DBG_GADGET 0x0004 /* calls to/from gadget driver */
@@ -230,14 +229,12 @@
230#define DBG_NONE 0x0000 229#define DBG_NONE 0x0000
231 230
232#define DEBUG_LEVEL (DBG_ERR) 231#define DEBUG_LEVEL (DBG_ERR)
232
233#define DBG(level, fmt, ...) \ 233#define DBG(level, fmt, ...) \
234 do { \ 234 do { \
235 if ((level) & DEBUG_LEVEL) \ 235 if ((level) & DEBUG_LEVEL) \
236 printk(KERN_DEBUG "udc: " fmt, ## __VA_ARGS__); \ 236 pr_debug("udc: " fmt, ## __VA_ARGS__); \
237 } while (0) 237 } while (0)
238#else
239#define DBG(level, fmt...)
240#endif
241 238
242enum usba_ctrl_state { 239enum usba_ctrl_state {
243 WAIT_FOR_SETUP, 240 WAIT_FOR_SETUP,
diff --git a/drivers/usb/gadget/dummy_hcd.c b/drivers/usb/gadget/dummy_hcd.c
index 9db2482bdfa2..cbe44535c0f0 100644
--- a/drivers/usb/gadget/dummy_hcd.c
+++ b/drivers/usb/gadget/dummy_hcd.c
@@ -61,6 +61,8 @@
61#define DRIVER_DESC "USB Host+Gadget Emulator" 61#define DRIVER_DESC "USB Host+Gadget Emulator"
62#define DRIVER_VERSION "02 May 2005" 62#define DRIVER_VERSION "02 May 2005"
63 63
64#define POWER_BUDGET 500 /* in mA; use 8 for low-power port testing */
65
64static const char driver_name [] = "dummy_hcd"; 66static const char driver_name [] = "dummy_hcd";
65static const char driver_desc [] = "USB Host+Gadget Emulator"; 67static const char driver_desc [] = "USB Host+Gadget Emulator";
66 68
@@ -772,18 +774,17 @@ usb_gadget_register_driver (struct usb_gadget_driver *driver)
772 list_del_init (&dum->ep [0].ep.ep_list); 774 list_del_init (&dum->ep [0].ep.ep_list);
773 INIT_LIST_HEAD(&dum->fifo_req.queue); 775 INIT_LIST_HEAD(&dum->fifo_req.queue);
774 776
777 driver->driver.bus = NULL;
775 dum->driver = driver; 778 dum->driver = driver;
776 dum->gadget.dev.driver = &driver->driver; 779 dum->gadget.dev.driver = &driver->driver;
777 dev_dbg (udc_dev(dum), "binding gadget driver '%s'\n", 780 dev_dbg (udc_dev(dum), "binding gadget driver '%s'\n",
778 driver->driver.name); 781 driver->driver.name);
779 if ((retval = driver->bind (&dum->gadget)) != 0) 782 retval = driver->bind(&dum->gadget);
780 goto err_bind_gadget; 783 if (retval) {
781 784 dum->driver = NULL;
782 driver->driver.bus = dum->gadget.dev.parent->bus; 785 dum->gadget.dev.driver = NULL;
783 if ((retval = driver_register (&driver->driver)) != 0) 786 return retval;
784 goto err_register; 787 }
785 if ((retval = device_bind_driver (&dum->gadget.dev)) != 0)
786 goto err_bind_driver;
787 788
788 /* khubd will enumerate this in a while */ 789 /* khubd will enumerate this in a while */
789 spin_lock_irq (&dum->lock); 790 spin_lock_irq (&dum->lock);
@@ -793,20 +794,6 @@ usb_gadget_register_driver (struct usb_gadget_driver *driver)
793 794
794 usb_hcd_poll_rh_status (dummy_to_hcd (dum)); 795 usb_hcd_poll_rh_status (dummy_to_hcd (dum));
795 return 0; 796 return 0;
796
797err_bind_driver:
798 driver_unregister (&driver->driver);
799err_register:
800 if (driver->unbind)
801 driver->unbind (&dum->gadget);
802 spin_lock_irq (&dum->lock);
803 dum->pullup = 0;
804 set_link_state (dum);
805 spin_unlock_irq (&dum->lock);
806err_bind_gadget:
807 dum->driver = NULL;
808 dum->gadget.dev.driver = NULL;
809 return retval;
810} 797}
811EXPORT_SYMBOL (usb_gadget_register_driver); 798EXPORT_SYMBOL (usb_gadget_register_driver);
812 799
@@ -830,11 +817,9 @@ usb_gadget_unregister_driver (struct usb_gadget_driver *driver)
830 spin_unlock_irqrestore (&dum->lock, flags); 817 spin_unlock_irqrestore (&dum->lock, flags);
831 818
832 driver->unbind (&dum->gadget); 819 driver->unbind (&dum->gadget);
820 dum->gadget.dev.driver = NULL;
833 dum->driver = NULL; 821 dum->driver = NULL;
834 822
835 device_release_driver (&dum->gadget.dev);
836 driver_unregister (&driver->driver);
837
838 spin_lock_irqsave (&dum->lock, flags); 823 spin_lock_irqsave (&dum->lock, flags);
839 dum->pullup = 0; 824 dum->pullup = 0;
840 set_link_state (dum); 825 set_link_state (dum);
@@ -1827,8 +1812,7 @@ static int dummy_start (struct usb_hcd *hcd)
1827 1812
1828 INIT_LIST_HEAD (&dum->urbp_list); 1813 INIT_LIST_HEAD (&dum->urbp_list);
1829 1814
1830 /* only show a low-power port: just 8mA */ 1815 hcd->power_budget = POWER_BUDGET;
1831 hcd->power_budget = 8;
1832 hcd->state = HC_STATE_RUNNING; 1816 hcd->state = HC_STATE_RUNNING;
1833 hcd->uses_new_polling = 1; 1817 hcd->uses_new_polling = 1;
1834 1818
diff --git a/drivers/usb/gadget/ether.c b/drivers/usb/gadget/ether.c
index 9e732bff9df0..a70e255402b8 100644
--- a/drivers/usb/gadget/ether.c
+++ b/drivers/usb/gadget/ether.c
@@ -1067,19 +1067,19 @@ done:
1067 1067
1068 /* on error, disable any endpoints */ 1068 /* on error, disable any endpoints */
1069 if (result < 0) { 1069 if (result < 0) {
1070 if (!subset_active(dev)) 1070 if (!subset_active(dev) && dev->status_ep)
1071 (void) usb_ep_disable (dev->status_ep); 1071 (void) usb_ep_disable (dev->status_ep);
1072 dev->status = NULL; 1072 dev->status = NULL;
1073 (void) usb_ep_disable (dev->in_ep); 1073 (void) usb_ep_disable (dev->in_ep);
1074 (void) usb_ep_disable (dev->out_ep); 1074 (void) usb_ep_disable (dev->out_ep);
1075 dev->in = NULL; 1075 dev->in = NULL;
1076 dev->out = NULL; 1076 dev->out = NULL;
1077 } else 1077 }
1078 1078
1079 /* activate non-CDC configs right away 1079 /* activate non-CDC configs right away
1080 * this isn't strictly according to the RNDIS spec 1080 * this isn't strictly according to the RNDIS spec
1081 */ 1081 */
1082 if (!cdc_active (dev)) { 1082 else if (!cdc_active (dev)) {
1083 netif_carrier_on (dev->net); 1083 netif_carrier_on (dev->net);
1084 if (netif_running (dev->net)) { 1084 if (netif_running (dev->net)) {
1085 spin_unlock (&dev->lock); 1085 spin_unlock (&dev->lock);
diff --git a/drivers/usb/gadget/file_storage.c b/drivers/usb/gadget/file_storage.c
index 1d174dcb3ac9..3301167d4f2a 100644
--- a/drivers/usb/gadget/file_storage.c
+++ b/drivers/usb/gadget/file_storage.c
@@ -275,19 +275,15 @@ MODULE_LICENSE("Dual BSD/GPL");
275 275
276/*-------------------------------------------------------------------------*/ 276/*-------------------------------------------------------------------------*/
277 277
278#ifdef DEBUG
279#define LDBG(lun,fmt,args...) \ 278#define LDBG(lun,fmt,args...) \
280 dev_dbg(&(lun)->dev , fmt , ## args) 279 dev_dbg(&(lun)->dev , fmt , ## args)
281#define MDBG(fmt,args...) \ 280#define MDBG(fmt,args...) \
282 printk(KERN_DEBUG DRIVER_NAME ": " fmt , ## args) 281 pr_debug(DRIVER_NAME ": " fmt , ## args)
283#else 282
284#define LDBG(lun,fmt,args...) \ 283#ifndef DEBUG
285 do { } while (0)
286#define MDBG(fmt,args...) \
287 do { } while (0)
288#undef VERBOSE_DEBUG 284#undef VERBOSE_DEBUG
289#undef DUMP_MSGS 285#undef DUMP_MSGS
290#endif /* DEBUG */ 286#endif /* !DEBUG */
291 287
292#ifdef VERBOSE_DEBUG 288#ifdef VERBOSE_DEBUG
293#define VLDBG LDBG 289#define VLDBG LDBG
@@ -304,7 +300,7 @@ MODULE_LICENSE("Dual BSD/GPL");
304 dev_info(&(lun)->dev , fmt , ## args) 300 dev_info(&(lun)->dev , fmt , ## args)
305 301
306#define MINFO(fmt,args...) \ 302#define MINFO(fmt,args...) \
307 printk(KERN_INFO DRIVER_NAME ": " fmt , ## args) 303 pr_info(DRIVER_NAME ": " fmt , ## args)
308 304
309#define DBG(d, fmt, args...) \ 305#define DBG(d, fmt, args...) \
310 dev_dbg(&(d)->gadget->dev , fmt , ## args) 306 dev_dbg(&(d)->gadget->dev , fmt , ## args)
diff --git a/drivers/usb/gadget/fsl_usb2_udc.c b/drivers/usb/gadget/fsl_usb2_udc.c
index 038e7d7b4da1..63e8fa3a69e1 100644
--- a/drivers/usb/gadget/fsl_usb2_udc.c
+++ b/drivers/usb/gadget/fsl_usb2_udc.c
@@ -776,7 +776,7 @@ fsl_ep_queue(struct usb_ep *_ep, struct usb_request *_req, gfp_t gfp_flags)
776 VDBG("%s, bad params\n", __FUNCTION__); 776 VDBG("%s, bad params\n", __FUNCTION__);
777 return -EINVAL; 777 return -EINVAL;
778 } 778 }
779 if (!_ep || (!ep->desc && ep_index(ep))) { 779 if (unlikely(!_ep || !ep->desc)) {
780 VDBG("%s, bad ep\n", __FUNCTION__); 780 VDBG("%s, bad ep\n", __FUNCTION__);
781 return -EINVAL; 781 return -EINVAL;
782 } 782 }
@@ -1896,7 +1896,7 @@ static int fsl_proc_read(char *page, char **start, off_t off, int count,
1896 1896
1897 spin_lock_irqsave(&udc->lock, flags); 1897 spin_lock_irqsave(&udc->lock, flags);
1898 1898
1899 /* ------basic driver infomation ---- */ 1899 /* ------basic driver information ---- */
1900 t = scnprintf(next, size, 1900 t = scnprintf(next, size,
1901 DRIVER_DESC "\n" 1901 DRIVER_DESC "\n"
1902 "%s version: %s\n" 1902 "%s version: %s\n"
diff --git a/drivers/usb/gadget/fsl_usb2_udc.h b/drivers/usb/gadget/fsl_usb2_udc.h
index 832ab82b4882..9fb0b1ec8526 100644
--- a/drivers/usb/gadget/fsl_usb2_udc.h
+++ b/drivers/usb/gadget/fsl_usb2_udc.h
@@ -551,9 +551,9 @@ static void dump_msg(const char *label, const u8 * buf, unsigned int length)
551#define VDBG(stuff...) do{}while(0) 551#define VDBG(stuff...) do{}while(0)
552#endif 552#endif
553 553
554#define ERR(stuff...) printk(KERN_ERR "udc: " stuff) 554#define ERR(stuff...) pr_err("udc: " stuff)
555#define WARN(stuff...) printk(KERN_WARNING "udc: " stuff) 555#define WARN(stuff...) pr_warning("udc: " stuff)
556#define INFO(stuff...) printk(KERN_INFO "udc: " stuff) 556#define INFO(stuff...) pr_info("udc: " stuff)
557 557
558/*-------------------------------------------------------------------------*/ 558/*-------------------------------------------------------------------------*/
559 559
diff --git a/drivers/usb/gadget/gmidi.c b/drivers/usb/gadget/gmidi.c
index 7da7fcb05640..5b42ccd0035f 100644
--- a/drivers/usb/gadget/gmidi.c
+++ b/drivers/usb/gadget/gmidi.c
@@ -1158,7 +1158,7 @@ static int __devinit gmidi_bind(struct usb_gadget *gadget)
1158 /* support optional vendor/distro customization */ 1158 /* support optional vendor/distro customization */
1159 if (idVendor) { 1159 if (idVendor) {
1160 if (!idProduct) { 1160 if (!idProduct) {
1161 printk(KERN_ERR "idVendor needs idProduct!\n"); 1161 pr_err("idVendor needs idProduct!\n");
1162 return -ENODEV; 1162 return -ENODEV;
1163 } 1163 }
1164 device_desc.idVendor = cpu_to_le16(idVendor); 1164 device_desc.idVendor = cpu_to_le16(idVendor);
@@ -1190,7 +1190,7 @@ static int __devinit gmidi_bind(struct usb_gadget *gadget)
1190 in_ep = usb_ep_autoconfig(gadget, &bulk_in_desc); 1190 in_ep = usb_ep_autoconfig(gadget, &bulk_in_desc);
1191 if (!in_ep) { 1191 if (!in_ep) {
1192autoconf_fail: 1192autoconf_fail:
1193 printk(KERN_ERR "%s: can't autoconfigure on %s\n", 1193 pr_err("%s: can't autoconfigure on %s\n",
1194 shortname, gadget->name); 1194 shortname, gadget->name);
1195 return -ENODEV; 1195 return -ENODEV;
1196 } 1196 }
@@ -1212,7 +1212,7 @@ autoconf_fail:
1212 * it SHOULD NOT have problems with bulk-capable hardware. 1212 * it SHOULD NOT have problems with bulk-capable hardware.
1213 * so warn about unrecognized controllers, don't panic. 1213 * so warn about unrecognized controllers, don't panic.
1214 */ 1214 */
1215 printk(KERN_WARNING "%s: controller '%s' not recognized\n", 1215 pr_warning("%s: controller '%s' not recognized\n",
1216 shortname, gadget->name); 1216 shortname, gadget->name);
1217 device_desc.bcdDevice = __constant_cpu_to_le16(0x9999); 1217 device_desc.bcdDevice = __constant_cpu_to_le16(0x9999);
1218 } 1218 }
diff --git a/drivers/usb/gadget/goku_udc.c b/drivers/usb/gadget/goku_udc.c
index 2ec9d196a8cf..d3e702576de6 100644
--- a/drivers/usb/gadget/goku_udc.c
+++ b/drivers/usb/gadget/goku_udc.c
@@ -1422,6 +1422,7 @@ int usb_gadget_unregister_driver(struct usb_gadget_driver *driver)
1422 spin_unlock_irqrestore(&dev->lock, flags); 1422 spin_unlock_irqrestore(&dev->lock, flags);
1423 1423
1424 driver->unbind(&dev->gadget); 1424 driver->unbind(&dev->gadget);
1425 dev->gadget.dev.driver = NULL;
1425 1426
1426 DBG(dev, "unregistered driver '%s'\n", driver->driver.name); 1427 DBG(dev, "unregistered driver '%s'\n", driver->driver.name);
1427 return 0; 1428 return 0;
diff --git a/drivers/usb/gadget/inode.c b/drivers/usb/gadget/inode.c
index 47ef8bd58a00..805602a687cb 100644
--- a/drivers/usb/gadget/inode.c
+++ b/drivers/usb/gadget/inode.c
@@ -1699,7 +1699,7 @@ gadgetfs_bind (struct usb_gadget *gadget)
1699 if (!dev) 1699 if (!dev)
1700 return -ESRCH; 1700 return -ESRCH;
1701 if (0 != strcmp (CHIP, gadget->name)) { 1701 if (0 != strcmp (CHIP, gadget->name)) {
1702 printk (KERN_ERR "%s expected %s controller not %s\n", 1702 pr_err("%s expected %s controller not %s\n",
1703 shortname, CHIP, gadget->name); 1703 shortname, CHIP, gadget->name);
1704 return -ENODEV; 1704 return -ENODEV;
1705 } 1705 }
diff --git a/drivers/usb/gadget/lh7a40x_udc.c b/drivers/usb/gadget/lh7a40x_udc.c
index 367b75c0b25b..37243ef7104e 100644
--- a/drivers/usb/gadget/lh7a40x_udc.c
+++ b/drivers/usb/gadget/lh7a40x_udc.c
@@ -474,6 +474,7 @@ int usb_gadget_unregister_driver(struct usb_gadget_driver *driver)
474 spin_unlock_irqrestore(&dev->lock, flags); 474 spin_unlock_irqrestore(&dev->lock, flags);
475 475
476 driver->unbind(&dev->gadget); 476 driver->unbind(&dev->gadget);
477 dev->gadget.dev.driver = NULL;
477 device_del(&dev->gadget.dev); 478 device_del(&dev->gadget.dev);
478 479
479 udc_disable(dev); 480 udc_disable(dev);
diff --git a/drivers/usb/gadget/m66592-udc.c b/drivers/usb/gadget/m66592-udc.c
index ebc5536aa271..835948f0715a 100644
--- a/drivers/usb/gadget/m66592-udc.c
+++ b/drivers/usb/gadget/m66592-udc.c
@@ -36,9 +36,14 @@ MODULE_DESCRIPTION("M66592 USB gadget driver");
36MODULE_LICENSE("GPL"); 36MODULE_LICENSE("GPL");
37MODULE_AUTHOR("Yoshihiro Shimoda"); 37MODULE_AUTHOR("Yoshihiro Shimoda");
38 38
39#define DRIVER_VERSION "29 May 2007" 39#define DRIVER_VERSION "18 Oct 2007"
40 40
41/* module parameters */ 41/* module parameters */
42#if defined(CONFIG_SUPERH_BUILT_IN_M66592)
43static unsigned short endian = M66592_LITTLE;
44module_param(endian, ushort, 0644);
45MODULE_PARM_DESC(endian, "data endian: big=0, little=0 (default=0)");
46#else
42static unsigned short clock = M66592_XTAL24; 47static unsigned short clock = M66592_XTAL24;
43module_param(clock, ushort, 0644); 48module_param(clock, ushort, 0644);
44MODULE_PARM_DESC(clock, "input clock: 48MHz=32768, 24MHz=16384, 12MHz=0 " 49MODULE_PARM_DESC(clock, "input clock: 48MHz=32768, 24MHz=16384, 12MHz=0 "
@@ -56,6 +61,7 @@ static unsigned short irq_sense = M66592_INTL;
56module_param(irq_sense, ushort, 0644); 61module_param(irq_sense, ushort, 0644);
57MODULE_PARM_DESC(irq_sense, "IRQ sense: low level=2, falling edge=0 " 62MODULE_PARM_DESC(irq_sense, "IRQ sense: low level=2, falling edge=0 "
58 "(default=2)"); 63 "(default=2)");
64#endif
59 65
60static const char udc_name[] = "m66592_udc"; 66static const char udc_name[] = "m66592_udc";
61static const char *m66592_ep_name[] = { 67static const char *m66592_ep_name[] = {
@@ -141,7 +147,7 @@ static inline u16 control_reg_get_pid(struct m66592 *m66592, u16 pipenum)
141 offset = get_pipectr_addr(pipenum); 147 offset = get_pipectr_addr(pipenum);
142 pid = m66592_read(m66592, offset) & M66592_PID; 148 pid = m66592_read(m66592, offset) & M66592_PID;
143 } else 149 } else
144 printk(KERN_ERR "unexpect pipe num (%d)\n", pipenum); 150 pr_err("unexpect pipe num (%d)\n", pipenum);
145 151
146 return pid; 152 return pid;
147} 153}
@@ -157,7 +163,7 @@ static inline void control_reg_set_pid(struct m66592 *m66592, u16 pipenum,
157 offset = get_pipectr_addr(pipenum); 163 offset = get_pipectr_addr(pipenum);
158 m66592_mdfy(m66592, pid, M66592_PID, offset); 164 m66592_mdfy(m66592, pid, M66592_PID, offset);
159 } else 165 } else
160 printk(KERN_ERR "unexpect pipe num (%d)\n", pipenum); 166 pr_err("unexpect pipe num (%d)\n", pipenum);
161} 167}
162 168
163static inline void pipe_start(struct m66592 *m66592, u16 pipenum) 169static inline void pipe_start(struct m66592 *m66592, u16 pipenum)
@@ -186,7 +192,7 @@ static inline u16 control_reg_get(struct m66592 *m66592, u16 pipenum)
186 offset = get_pipectr_addr(pipenum); 192 offset = get_pipectr_addr(pipenum);
187 ret = m66592_read(m66592, offset); 193 ret = m66592_read(m66592, offset);
188 } else 194 } else
189 printk(KERN_ERR "unexpect pipe num (%d)\n", pipenum); 195 pr_err("unexpect pipe num (%d)\n", pipenum);
190 196
191 return ret; 197 return ret;
192} 198}
@@ -203,7 +209,7 @@ static inline void control_reg_sqclr(struct m66592 *m66592, u16 pipenum)
203 offset = get_pipectr_addr(pipenum); 209 offset = get_pipectr_addr(pipenum);
204 m66592_bset(m66592, M66592_SQCLR, offset); 210 m66592_bset(m66592, M66592_SQCLR, offset);
205 } else 211 } else
206 printk(KERN_ERR "unexpect pipe num(%d)\n", pipenum); 212 pr_err("unexpect pipe num(%d)\n", pipenum);
207} 213}
208 214
209static inline int get_buffer_size(struct m66592 *m66592, u16 pipenum) 215static inline int get_buffer_size(struct m66592 *m66592, u16 pipenum)
@@ -285,7 +291,7 @@ static int pipe_buffer_setting(struct m66592 *m66592,
285 break; 291 break;
286 } 292 }
287 if (m66592->bi_bufnum > M66592_MAX_BUFNUM) { 293 if (m66592->bi_bufnum > M66592_MAX_BUFNUM) {
288 printk(KERN_ERR "m66592 pipe memory is insufficient(%d)\n", 294 pr_err("m66592 pipe memory is insufficient(%d)\n",
289 m66592->bi_bufnum); 295 m66592->bi_bufnum);
290 return -ENOMEM; 296 return -ENOMEM;
291 } 297 }
@@ -326,7 +332,7 @@ static void pipe_buffer_release(struct m66592 *m66592,
326 if (info->type == M66592_BULK) 332 if (info->type == M66592_BULK)
327 m66592->bulk--; 333 m66592->bulk--;
328 } else 334 } else
329 printk(KERN_ERR "ep_release: unexpect pipenum (%d)\n", 335 pr_err("ep_release: unexpect pipenum (%d)\n",
330 info->pipe); 336 info->pipe);
331} 337}
332 338
@@ -360,6 +366,7 @@ static void m66592_ep_setting(struct m66592 *m66592, struct m66592_ep *ep,
360 ep->fifosel = M66592_D0FIFOSEL; 366 ep->fifosel = M66592_D0FIFOSEL;
361 ep->fifoctr = M66592_D0FIFOCTR; 367 ep->fifoctr = M66592_D0FIFOCTR;
362 ep->fifotrn = M66592_D0FIFOTRN; 368 ep->fifotrn = M66592_D0FIFOTRN;
369#if !defined(CONFIG_SUPERH_BUILT_IN_M66592)
363 } else if (m66592->num_dma == 1) { 370 } else if (m66592->num_dma == 1) {
364 m66592->num_dma++; 371 m66592->num_dma++;
365 ep->use_dma = 1; 372 ep->use_dma = 1;
@@ -367,6 +374,7 @@ static void m66592_ep_setting(struct m66592 *m66592, struct m66592_ep *ep,
367 ep->fifosel = M66592_D1FIFOSEL; 374 ep->fifosel = M66592_D1FIFOSEL;
368 ep->fifoctr = M66592_D1FIFOCTR; 375 ep->fifoctr = M66592_D1FIFOCTR;
369 ep->fifotrn = M66592_D1FIFOTRN; 376 ep->fifotrn = M66592_D1FIFOTRN;
377#endif
370 } else { 378 } else {
371 ep->use_dma = 0; 379 ep->use_dma = 0;
372 ep->fifoaddr = M66592_CFIFO; 380 ep->fifoaddr = M66592_CFIFO;
@@ -422,7 +430,7 @@ static int alloc_pipe_config(struct m66592_ep *ep,
422 case USB_ENDPOINT_XFER_BULK: 430 case USB_ENDPOINT_XFER_BULK:
423 if (m66592->bulk >= M66592_MAX_NUM_BULK) { 431 if (m66592->bulk >= M66592_MAX_NUM_BULK) {
424 if (m66592->isochronous >= M66592_MAX_NUM_ISOC) { 432 if (m66592->isochronous >= M66592_MAX_NUM_ISOC) {
425 printk(KERN_ERR "bulk pipe is insufficient\n"); 433 pr_err("bulk pipe is insufficient\n");
426 return -ENODEV; 434 return -ENODEV;
427 } else { 435 } else {
428 info.pipe = M66592_BASE_PIPENUM_ISOC 436 info.pipe = M66592_BASE_PIPENUM_ISOC
@@ -438,7 +446,7 @@ static int alloc_pipe_config(struct m66592_ep *ep,
438 break; 446 break;
439 case USB_ENDPOINT_XFER_INT: 447 case USB_ENDPOINT_XFER_INT:
440 if (m66592->interrupt >= M66592_MAX_NUM_INT) { 448 if (m66592->interrupt >= M66592_MAX_NUM_INT) {
441 printk(KERN_ERR "interrupt pipe is insufficient\n"); 449 pr_err("interrupt pipe is insufficient\n");
442 return -ENODEV; 450 return -ENODEV;
443 } 451 }
444 info.pipe = M66592_BASE_PIPENUM_INT + m66592->interrupt; 452 info.pipe = M66592_BASE_PIPENUM_INT + m66592->interrupt;
@@ -447,7 +455,7 @@ static int alloc_pipe_config(struct m66592_ep *ep,
447 break; 455 break;
448 case USB_ENDPOINT_XFER_ISOC: 456 case USB_ENDPOINT_XFER_ISOC:
449 if (m66592->isochronous >= M66592_MAX_NUM_ISOC) { 457 if (m66592->isochronous >= M66592_MAX_NUM_ISOC) {
450 printk(KERN_ERR "isochronous pipe is insufficient\n"); 458 pr_err("isochronous pipe is insufficient\n");
451 return -ENODEV; 459 return -ENODEV;
452 } 460 }
453 info.pipe = M66592_BASE_PIPENUM_ISOC + m66592->isochronous; 461 info.pipe = M66592_BASE_PIPENUM_ISOC + m66592->isochronous;
@@ -455,7 +463,7 @@ static int alloc_pipe_config(struct m66592_ep *ep,
455 counter = &m66592->isochronous; 463 counter = &m66592->isochronous;
456 break; 464 break;
457 default: 465 default:
458 printk(KERN_ERR "unexpect xfer type\n"); 466 pr_err("unexpect xfer type\n");
459 return -EINVAL; 467 return -EINVAL;
460 } 468 }
461 ep->type = info.type; 469 ep->type = info.type;
@@ -470,7 +478,7 @@ static int alloc_pipe_config(struct m66592_ep *ep,
470 478
471 ret = pipe_buffer_setting(m66592, &info); 479 ret = pipe_buffer_setting(m66592, &info);
472 if (ret < 0) { 480 if (ret < 0) {
473 printk(KERN_ERR "pipe_buffer_setting fail\n"); 481 pr_err("pipe_buffer_setting fail\n");
474 return ret; 482 return ret;
475 } 483 }
476 484
@@ -606,11 +614,33 @@ static void start_ep0(struct m66592_ep *ep, struct m66592_request *req)
606 control_end(ep->m66592, 0); 614 control_end(ep->m66592, 0);
607 break; 615 break;
608 default: 616 default:
609 printk(KERN_ERR "start_ep0: unexpect ctsq(%x)\n", ctsq); 617 pr_err("start_ep0: unexpect ctsq(%x)\n", ctsq);
610 break; 618 break;
611 } 619 }
612} 620}
613 621
622#if defined(CONFIG_SUPERH_BUILT_IN_M66592)
623static void init_controller(struct m66592 *m66592)
624{
625 usbf_start_clock();
626 m66592_bset(m66592, M66592_HSE, M66592_SYSCFG); /* High spd */
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
631 /* This is a workaound for SH7722 2nd cut */
632 m66592_bset(m66592, 0x8000, M66592_DVSTCTR);
633 m66592_bset(m66592, 0x1000, M66592_TESTMODE);
634 m66592_bclr(m66592, 0x8000, M66592_DVSTCTR);
635
636 m66592_bset(m66592, M66592_INTL, M66592_INTENB1);
637
638 m66592_write(m66592, 0, M66592_CFBCFG);
639 m66592_write(m66592, 0, M66592_D0FBCFG);
640 m66592_bset(m66592, endian, M66592_CFBCFG);
641 m66592_bset(m66592, endian, M66592_D0FBCFG);
642}
643#else /* #if defined(CONFIG_SUPERH_BUILT_IN_M66592) */
614static void init_controller(struct m66592 *m66592) 644static void init_controller(struct m66592 *m66592)
615{ 645{
616 m66592_bset(m66592, (vif & M66592_LDRV) | (endian & M66592_BIGEND), 646 m66592_bset(m66592, (vif & M66592_LDRV) | (endian & M66592_BIGEND),
@@ -636,9 +666,13 @@ static void init_controller(struct m66592 *m66592)
636 m66592_write(m66592, M66592_BURST | M66592_CPU_ADR_RD_WR, 666 m66592_write(m66592, M66592_BURST | M66592_CPU_ADR_RD_WR,
637 M66592_DMA0CFG); 667 M66592_DMA0CFG);
638} 668}
669#endif /* #if defined(CONFIG_SUPERH_BUILT_IN_M66592) */
639 670
640static void disable_controller(struct m66592 *m66592) 671static void disable_controller(struct m66592 *m66592)
641{ 672{
673#if defined(CONFIG_SUPERH_BUILT_IN_M66592)
674 usbf_stop_clock();
675#else
642 m66592_bclr(m66592, M66592_SCKE, M66592_SYSCFG); 676 m66592_bclr(m66592, M66592_SCKE, M66592_SYSCFG);
643 udelay(1); 677 udelay(1);
644 m66592_bclr(m66592, M66592_PLLC, M66592_SYSCFG); 678 m66592_bclr(m66592, M66592_PLLC, M66592_SYSCFG);
@@ -646,15 +680,20 @@ static void disable_controller(struct m66592 *m66592)
646 m66592_bclr(m66592, M66592_RCKE, M66592_SYSCFG); 680 m66592_bclr(m66592, M66592_RCKE, M66592_SYSCFG);
647 udelay(1); 681 udelay(1);
648 m66592_bclr(m66592, M66592_XCKE, M66592_SYSCFG); 682 m66592_bclr(m66592, M66592_XCKE, M66592_SYSCFG);
683#endif
649} 684}
650 685
651static void m66592_start_xclock(struct m66592 *m66592) 686static void m66592_start_xclock(struct m66592 *m66592)
652{ 687{
688#if defined(CONFIG_SUPERH_BUILT_IN_M66592)
689 usbf_start_clock();
690#else
653 u16 tmp; 691 u16 tmp;
654 692
655 tmp = m66592_read(m66592, M66592_SYSCFG); 693 tmp = m66592_read(m66592, M66592_SYSCFG);
656 if (!(tmp & M66592_XCKE)) 694 if (!(tmp & M66592_XCKE))
657 m66592_bset(m66592, M66592_XCKE, M66592_SYSCFG); 695 m66592_bset(m66592, M66592_XCKE, M66592_SYSCFG);
696#endif
658} 697}
659 698
660/*-------------------------------------------------------------------------*/ 699/*-------------------------------------------------------------------------*/
@@ -709,7 +748,7 @@ static void irq_ep0_write(struct m66592_ep *ep, struct m66592_request *req)
709 do { 748 do {
710 tmp = m66592_read(m66592, ep->fifoctr); 749 tmp = m66592_read(m66592, ep->fifoctr);
711 if (i++ > 100000) { 750 if (i++ > 100000) {
712 printk(KERN_ERR "pipe0 is busy. maybe cpu i/o bus" 751 pr_err("pipe0 is busy. maybe cpu i/o bus "
713 "conflict. please power off this controller."); 752 "conflict. please power off this controller.");
714 return; 753 return;
715 } 754 }
@@ -759,7 +798,7 @@ static void irq_packet_write(struct m66592_ep *ep, struct m66592_request *req)
759 if (unlikely((tmp & M66592_FRDY) == 0)) { 798 if (unlikely((tmp & M66592_FRDY) == 0)) {
760 pipe_stop(m66592, pipenum); 799 pipe_stop(m66592, pipenum);
761 pipe_irq_disable(m66592, pipenum); 800 pipe_irq_disable(m66592, pipenum);
762 printk(KERN_ERR "write fifo not ready. pipnum=%d\n", pipenum); 801 pr_err("write fifo not ready. pipnum=%d\n", pipenum);
763 return; 802 return;
764 } 803 }
765 804
@@ -808,7 +847,7 @@ static void irq_packet_read(struct m66592_ep *ep, struct m66592_request *req)
808 req->req.status = -EPIPE; 847 req->req.status = -EPIPE;
809 pipe_stop(m66592, pipenum); 848 pipe_stop(m66592, pipenum);
810 pipe_irq_disable(m66592, pipenum); 849 pipe_irq_disable(m66592, pipenum);
811 printk(KERN_ERR "read fifo not ready"); 850 pr_err("read fifo not ready");
812 return; 851 return;
813 } 852 }
814 853
@@ -1063,7 +1102,7 @@ static void m66592_update_usb_speed(struct m66592 *m66592)
1063 break; 1102 break;
1064 default: 1103 default:
1065 m66592->gadget.speed = USB_SPEED_UNKNOWN; 1104 m66592->gadget.speed = USB_SPEED_UNKNOWN;
1066 printk(KERN_ERR "USB speed unknown\n"); 1105 pr_err("USB speed unknown\n");
1067 } 1106 }
1068} 1107}
1069 1108
@@ -1122,7 +1161,7 @@ __acquires(m66592->lock)
1122 control_end(m66592, 0); 1161 control_end(m66592, 0);
1123 break; 1162 break;
1124 default: 1163 default:
1125 printk(KERN_ERR "ctrl_stage: unexpect ctsq(%x)\n", ctsq); 1164 pr_err("ctrl_stage: unexpect ctsq(%x)\n", ctsq);
1126 break; 1165 break;
1127 } 1166 }
1128} 1167}
@@ -1142,6 +1181,19 @@ static irqreturn_t m66592_irq(int irq, void *_m66592)
1142 intsts0 = m66592_read(m66592, M66592_INTSTS0); 1181 intsts0 = m66592_read(m66592, M66592_INTSTS0);
1143 intenb0 = m66592_read(m66592, M66592_INTENB0); 1182 intenb0 = m66592_read(m66592, M66592_INTENB0);
1144 1183
1184#if defined(CONFIG_SUPERH_BUILT_IN_M66592)
1185 if (!intsts0 && !intenb0) {
1186 /*
1187 * When USB clock stops, it cannot read register. Even if a
1188 * clock stops, the interrupt occurs. So this driver turn on
1189 * a clock by this timing and do re-reading of register.
1190 */
1191 m66592_start_xclock(m66592);
1192 intsts0 = m66592_read(m66592, M66592_INTSTS0);
1193 intenb0 = m66592_read(m66592, M66592_INTENB0);
1194 }
1195#endif
1196
1145 savepipe = m66592_read(m66592, M66592_CFIFOSEL); 1197 savepipe = m66592_read(m66592, M66592_CFIFOSEL);
1146 1198
1147 mask0 = intsts0 & intenb0; 1199 mask0 = intsts0 & intenb0;
@@ -1409,13 +1461,13 @@ int usb_gadget_register_driver(struct usb_gadget_driver *driver)
1409 1461
1410 retval = device_add(&m66592->gadget.dev); 1462 retval = device_add(&m66592->gadget.dev);
1411 if (retval) { 1463 if (retval) {
1412 printk(KERN_ERR "device_add error (%d)\n", retval); 1464 pr_err("device_add error (%d)\n", retval);
1413 goto error; 1465 goto error;
1414 } 1466 }
1415 1467
1416 retval = driver->bind (&m66592->gadget); 1468 retval = driver->bind (&m66592->gadget);
1417 if (retval) { 1469 if (retval) {
1418 printk(KERN_ERR "bind to driver error (%d)\n", retval); 1470 pr_err("bind to driver error (%d)\n", retval);
1419 device_del(&m66592->gadget.dev); 1471 device_del(&m66592->gadget.dev);
1420 goto error; 1472 goto error;
1421 } 1473 }
@@ -1456,6 +1508,7 @@ int usb_gadget_unregister_driver(struct usb_gadget_driver *driver)
1456 m66592_bclr(m66592, M66592_VBSE | M66592_URST, M66592_INTENB0); 1508 m66592_bclr(m66592, M66592_VBSE | M66592_URST, M66592_INTENB0);
1457 1509
1458 driver->unbind(&m66592->gadget); 1510 driver->unbind(&m66592->gadget);
1511 m66592->gadget.dev.driver = NULL;
1459 1512
1460 init_controller(m66592); 1513 init_controller(m66592);
1461 disable_controller(m66592); 1514 disable_controller(m66592);
@@ -1485,6 +1538,7 @@ static int __exit m66592_remove(struct platform_device *pdev)
1485 iounmap(m66592->reg); 1538 iounmap(m66592->reg);
1486 free_irq(platform_get_irq(pdev, 0), m66592); 1539 free_irq(platform_get_irq(pdev, 0), m66592);
1487 m66592_free_request(&m66592->ep[0].ep, m66592->ep0_req); 1540 m66592_free_request(&m66592->ep[0].ep, m66592->ep0_req);
1541 usbf_stop_clock();
1488 kfree(m66592); 1542 kfree(m66592);
1489 return 0; 1543 return 0;
1490} 1544}
@@ -1508,28 +1562,28 @@ static int __init m66592_probe(struct platform_device *pdev)
1508 (char *)udc_name); 1562 (char *)udc_name);
1509 if (!res) { 1563 if (!res) {
1510 ret = -ENODEV; 1564 ret = -ENODEV;
1511 printk(KERN_ERR "platform_get_resource_byname error.\n"); 1565 pr_err("platform_get_resource_byname error.\n");
1512 goto clean_up; 1566 goto clean_up;
1513 } 1567 }
1514 1568
1515 irq = platform_get_irq(pdev, 0); 1569 irq = platform_get_irq(pdev, 0);
1516 if (irq < 0) { 1570 if (irq < 0) {
1517 ret = -ENODEV; 1571 ret = -ENODEV;
1518 printk(KERN_ERR "platform_get_irq error.\n"); 1572 pr_err("platform_get_irq error.\n");
1519 goto clean_up; 1573 goto clean_up;
1520 } 1574 }
1521 1575
1522 reg = ioremap(res->start, resource_len(res)); 1576 reg = ioremap(res->start, resource_len(res));
1523 if (reg == NULL) { 1577 if (reg == NULL) {
1524 ret = -ENOMEM; 1578 ret = -ENOMEM;
1525 printk(KERN_ERR "ioremap error.\n"); 1579 pr_err("ioremap error.\n");
1526 goto clean_up; 1580 goto clean_up;
1527 } 1581 }
1528 1582
1529 /* initialize ucd */ 1583 /* initialize ucd */
1530 m66592 = kzalloc(sizeof(struct m66592), GFP_KERNEL); 1584 m66592 = kzalloc(sizeof(struct m66592), GFP_KERNEL);
1531 if (m66592 == NULL) { 1585 if (m66592 == NULL) {
1532 printk(KERN_ERR "kzalloc error\n"); 1586 pr_err("kzalloc error\n");
1533 goto clean_up; 1587 goto clean_up;
1534 } 1588 }
1535 1589
@@ -1555,7 +1609,7 @@ static int __init m66592_probe(struct platform_device *pdev)
1555 ret = request_irq(irq, m66592_irq, IRQF_DISABLED | IRQF_SHARED, 1609 ret = request_irq(irq, m66592_irq, IRQF_DISABLED | IRQF_SHARED,
1556 udc_name, m66592); 1610 udc_name, m66592);
1557 if (ret < 0) { 1611 if (ret < 0) {
1558 printk(KERN_ERR "request_irq error (%d)\n", ret); 1612 pr_err("request_irq error (%d)\n", ret);
1559 goto clean_up; 1613 goto clean_up;
1560 } 1614 }
1561 1615
diff --git a/drivers/usb/gadget/m66592-udc.h b/drivers/usb/gadget/m66592-udc.h
index bfa0c645f229..17b792b7f6bf 100644
--- a/drivers/usb/gadget/m66592-udc.h
+++ b/drivers/usb/gadget/m66592-udc.h
@@ -72,6 +72,11 @@
72#define M66592_P_TST_J 0x0001 /* PERI TEST J */ 72#define M66592_P_TST_J 0x0001 /* PERI TEST J */
73#define M66592_P_TST_NORMAL 0x0000 /* PERI Normal Mode */ 73#define M66592_P_TST_NORMAL 0x0000 /* PERI Normal Mode */
74 74
75#if defined(CONFIG_SUPERH_BUILT_IN_M66592)
76#define M66592_CFBCFG 0x0A
77#define M66592_D0FBCFG 0x0C
78#define M66592_LITTLE 0x0100 /* b8: Little endian mode */
79#else
75#define M66592_PINCFG 0x0A 80#define M66592_PINCFG 0x0A
76#define M66592_LDRV 0x8000 /* b15: Drive Current Adjust */ 81#define M66592_LDRV 0x8000 /* b15: Drive Current Adjust */
77#define M66592_BIGEND 0x0100 /* b8: Big endian mode */ 82#define M66592_BIGEND 0x0100 /* b8: Big endian mode */
@@ -91,6 +96,7 @@
91#define M66592_PKTM 0x0020 /* b5: Packet mode */ 96#define M66592_PKTM 0x0020 /* b5: Packet mode */
92#define M66592_DENDE 0x0010 /* b4: Dend enable */ 97#define M66592_DENDE 0x0010 /* b4: Dend enable */
93#define M66592_OBUS 0x0004 /* b2: OUTbus mode */ 98#define M66592_OBUS 0x0004 /* b2: OUTbus mode */
99#endif /* #if defined(CONFIG_SUPERH_BUILT_IN_M66592) */
94 100
95#define M66592_CFIFO 0x10 101#define M66592_CFIFO 0x10
96#define M66592_D0FIFO 0x14 102#define M66592_D0FIFO 0x14
@@ -103,9 +109,13 @@
103#define M66592_REW 0x4000 /* b14: Buffer rewind */ 109#define M66592_REW 0x4000 /* b14: Buffer rewind */
104#define M66592_DCLRM 0x2000 /* b13: DMA buffer clear mode */ 110#define M66592_DCLRM 0x2000 /* b13: DMA buffer clear mode */
105#define M66592_DREQE 0x1000 /* b12: DREQ output enable */ 111#define M66592_DREQE 0x1000 /* b12: DREQ output enable */
112#if defined(CONFIG_SUPERH_BUILT_IN_M66592)
113#define M66592_MBW 0x0800 /* b11: Maximum bit width for FIFO */
114#else
106#define M66592_MBW 0x0400 /* b10: Maximum bit width for FIFO */ 115#define M66592_MBW 0x0400 /* b10: Maximum bit width for FIFO */
107#define M66592_MBW_8 0x0000 /* 8bit */ 116#define M66592_MBW_8 0x0000 /* 8bit */
108#define M66592_MBW_16 0x0400 /* 16bit */ 117#define M66592_MBW_16 0x0400 /* 16bit */
118#endif /* #if defined(CONFIG_SUPERH_BUILT_IN_M66592) */
109#define M66592_TRENB 0x0200 /* b9: Transaction counter enable */ 119#define M66592_TRENB 0x0200 /* b9: Transaction counter enable */
110#define M66592_TRCLR 0x0100 /* b8: Transaction counter clear */ 120#define M66592_TRCLR 0x0100 /* b8: Transaction counter clear */
111#define M66592_DEZPM 0x0080 /* b7: Zero-length packet mode */ 121#define M66592_DEZPM 0x0080 /* b7: Zero-length packet mode */
@@ -530,8 +540,13 @@ static inline void m66592_read_fifo(struct m66592 *m66592,
530{ 540{
531 unsigned long fifoaddr = (unsigned long)m66592->reg + offset; 541 unsigned long fifoaddr = (unsigned long)m66592->reg + offset;
532 542
543#if defined(CONFIG_SUPERH_BUILT_IN_M66592)
544 len = (len + 3) / 4;
545 insl(fifoaddr, buf, len);
546#else
533 len = (len + 1) / 2; 547 len = (len + 1) / 2;
534 insw(fifoaddr, buf, len); 548 insw(fifoaddr, buf, len);
549#endif
535} 550}
536 551
537static inline void m66592_write(struct m66592 *m66592, u16 val, 552static inline void m66592_write(struct m66592 *m66592, u16 val,
@@ -545,6 +560,24 @@ static inline void m66592_write_fifo(struct m66592 *m66592,
545 void *buf, unsigned long len) 560 void *buf, unsigned long len)
546{ 561{
547 unsigned long fifoaddr = (unsigned long)m66592->reg + offset; 562 unsigned long fifoaddr = (unsigned long)m66592->reg + offset;
563#if defined(CONFIG_SUPERH_BUILT_IN_M66592)
564 unsigned long count;
565 unsigned char *pb;
566 int i;
567
568 count = len / 4;
569 outsl(fifoaddr, buf, count);
570
571 if (len & 0x00000003) {
572 pb = buf + count * 4;
573 for (i = 0; i < (len & 0x00000003); i++) {
574 if (m66592_read(m66592, M66592_CFBCFG)) /* little */
575 outb(pb[i], fifoaddr + (3 - i));
576 else
577 outb(pb[i], fifoaddr + i);
578 }
579 }
580#else
548 unsigned long odd = len & 0x0001; 581 unsigned long odd = len & 0x0001;
549 582
550 len = len / 2; 583 len = len / 2;
@@ -553,6 +586,7 @@ static inline void m66592_write_fifo(struct m66592 *m66592,
553 unsigned char *p = buf + len*2; 586 unsigned char *p = buf + len*2;
554 outb(*p, fifoaddr); 587 outb(*p, fifoaddr);
555 } 588 }
589#endif /* #if defined(CONFIG_SUPERH_BUILT_IN_M66592) */
556} 590}
557 591
558static inline void m66592_mdfy(struct m66592 *m66592, u16 val, u16 pat, 592static inline void m66592_mdfy(struct m66592 *m66592, u16 val, u16 pat,
@@ -570,6 +604,26 @@ static inline void m66592_mdfy(struct m66592 *m66592, u16 val, u16 pat,
570#define m66592_bset(m66592, val, offset) \ 604#define m66592_bset(m66592, val, offset) \
571 m66592_mdfy(m66592, val, 0, offset) 605 m66592_mdfy(m66592, val, 0, offset)
572 606
607#if defined(CONFIG_SUPERH_BUILT_IN_M66592)
608#include <asm/io.h>
609#define MSTPCR2 0xA4150038 /* for SH7722 */
610#define MSTPCR2_USB 0x00000800
611
612static inline void usbf_start_clock(void)
613{
614 ctrl_outl(ctrl_inl(MSTPCR2) & ~MSTPCR2_USB, MSTPCR2);
615}
616
617static inline void usbf_stop_clock(void)
618{
619 ctrl_outl(ctrl_inl(MSTPCR2) | MSTPCR2_USB, MSTPCR2);
620}
621
622#else
623#define usbf_start_clock(x)
624#define usbf_stop_clock(x)
625#endif /* if defined(CONFIG_SUPERH_BUILT_IN_M66592) */
626
573#endif /* ifndef __M66592_UDC_H__ */ 627#endif /* ifndef __M66592_UDC_H__ */
574 628
575 629
diff --git a/drivers/usb/gadget/net2280.c b/drivers/usb/gadget/net2280.c
index d5d473f8144b..33469cf5aec3 100644
--- a/drivers/usb/gadget/net2280.c
+++ b/drivers/usb/gadget/net2280.c
@@ -2435,7 +2435,7 @@ static void handle_stat0_irqs (struct net2280 *dev, u32 stat)
2435 break; 2435 break;
2436 default: 2436 default:
2437delegate: 2437delegate:
2438 VDEBUG (dev, "setup %02x.%02x v%04x i%04x l%04x" 2438 VDEBUG (dev, "setup %02x.%02x v%04x i%04x l%04x "
2439 "ep_cfg %08x\n", 2439 "ep_cfg %08x\n",
2440 u.r.bRequestType, u.r.bRequest, 2440 u.r.bRequestType, u.r.bRequest,
2441 w_value, w_index, w_length, 2441 w_value, w_index, w_length,
diff --git a/drivers/usb/gadget/omap_udc.c b/drivers/usb/gadget/omap_udc.c
index d377154658b5..e6d68bda428a 100644
--- a/drivers/usb/gadget/omap_udc.c
+++ b/drivers/usb/gadget/omap_udc.c
@@ -4,6 +4,8 @@
4 * Copyright (C) 2004 Texas Instruments, Inc. 4 * Copyright (C) 2004 Texas Instruments, Inc.
5 * Copyright (C) 2004-2005 David Brownell 5 * Copyright (C) 2004-2005 David Brownell
6 * 6 *
7 * OMAP2 & DMA support by Kyungmin Park <kyungmin.park@samsung.com>
8 *
7 * This program is free software; you can redistribute it and/or modify 9 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by 10 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or 11 * the Free Software Foundation; either version 2 of the License, or
@@ -60,11 +62,6 @@
60/* bulk DMA seems to be behaving for both IN and OUT */ 62/* bulk DMA seems to be behaving for both IN and OUT */
61#define USE_DMA 63#define USE_DMA
62 64
63/* FIXME: OMAP2 currently has some problem in DMA mode */
64#ifdef CONFIG_ARCH_OMAP2
65#undef USE_DMA
66#endif
67
68/* ISO too */ 65/* ISO too */
69#define USE_ISO 66#define USE_ISO
70 67
@@ -73,6 +70,8 @@
73 70
74#define DMA_ADDR_INVALID (~(dma_addr_t)0) 71#define DMA_ADDR_INVALID (~(dma_addr_t)0)
75 72
73#define OMAP2_DMA_CH(ch) (((ch) - 1) << 1)
74#define OMAP24XX_DMA(name, ch) (OMAP24XX_DMA_##name + OMAP2_DMA_CH(ch))
76 75
77/* 76/*
78 * The OMAP UDC needs _very_ early endpoint setup: before enabling the 77 * The OMAP UDC needs _very_ early endpoint setup: before enabling the
@@ -571,20 +570,25 @@ static void next_in_dma(struct omap_ep *ep, struct omap_req *req)
571 const int sync_mode = cpu_is_omap15xx() 570 const int sync_mode = cpu_is_omap15xx()
572 ? OMAP_DMA_SYNC_FRAME 571 ? OMAP_DMA_SYNC_FRAME
573 : OMAP_DMA_SYNC_ELEMENT; 572 : OMAP_DMA_SYNC_ELEMENT;
573 int dma_trigger = 0;
574
575 if (cpu_is_omap24xx())
576 dma_trigger = OMAP24XX_DMA(USB_W2FC_TX0, ep->dma_channel);
574 577
575 /* measure length in either bytes or packets */ 578 /* measure length in either bytes or packets */
576 if ((cpu_is_omap16xx() && length <= UDC_TXN_TSC) 579 if ((cpu_is_omap16xx() && length <= UDC_TXN_TSC)
580 || (cpu_is_omap24xx() && length < ep->maxpacket)
577 || (cpu_is_omap15xx() && length < ep->maxpacket)) { 581 || (cpu_is_omap15xx() && length < ep->maxpacket)) {
578 txdma_ctrl = UDC_TXN_EOT | length; 582 txdma_ctrl = UDC_TXN_EOT | length;
579 omap_set_dma_transfer_params(ep->lch, OMAP_DMA_DATA_TYPE_S8, 583 omap_set_dma_transfer_params(ep->lch, OMAP_DMA_DATA_TYPE_S8,
580 length, 1, sync_mode, 0, 0); 584 length, 1, sync_mode, dma_trigger, 0);
581 } else { 585 } else {
582 length = min(length / ep->maxpacket, 586 length = min(length / ep->maxpacket,
583 (unsigned) UDC_TXN_TSC + 1); 587 (unsigned) UDC_TXN_TSC + 1);
584 txdma_ctrl = length; 588 txdma_ctrl = length;
585 omap_set_dma_transfer_params(ep->lch, OMAP_DMA_DATA_TYPE_S16, 589 omap_set_dma_transfer_params(ep->lch, OMAP_DMA_DATA_TYPE_S16,
586 ep->ep.maxpacket >> 1, length, sync_mode, 590 ep->ep.maxpacket >> 1, length, sync_mode,
587 0, 0); 591 dma_trigger, 0);
588 length *= ep->maxpacket; 592 length *= ep->maxpacket;
589 } 593 }
590 omap_set_dma_src_params(ep->lch, OMAP_DMA_PORT_EMIFF, 594 omap_set_dma_src_params(ep->lch, OMAP_DMA_PORT_EMIFF,
@@ -622,20 +626,31 @@ static void finish_in_dma(struct omap_ep *ep, struct omap_req *req, int status)
622 626
623static void next_out_dma(struct omap_ep *ep, struct omap_req *req) 627static void next_out_dma(struct omap_ep *ep, struct omap_req *req)
624{ 628{
625 unsigned packets; 629 unsigned packets = req->req.length - req->req.actual;
630 int dma_trigger = 0;
631
632 if (cpu_is_omap24xx())
633 dma_trigger = OMAP24XX_DMA(USB_W2FC_RX0, ep->dma_channel);
626 634
627 /* NOTE: we filtered out "short reads" before, so we know 635 /* NOTE: we filtered out "short reads" before, so we know
628 * the buffer has only whole numbers of packets. 636 * the buffer has only whole numbers of packets.
637 * except MODE SELECT(6) sent the 24 bytes data in OMAP24XX DMA mode
629 */ 638 */
630 639 if (cpu_is_omap24xx() && packets < ep->maxpacket) {
631 /* set up this DMA transfer, enable the fifo, start */ 640 omap_set_dma_transfer_params(ep->lch, OMAP_DMA_DATA_TYPE_S8,
632 packets = (req->req.length - req->req.actual) / ep->ep.maxpacket; 641 packets, 1, OMAP_DMA_SYNC_ELEMENT,
633 packets = min(packets, (unsigned)UDC_RXN_TC + 1); 642 dma_trigger, 0);
634 req->dma_bytes = packets * ep->ep.maxpacket; 643 req->dma_bytes = packets;
635 omap_set_dma_transfer_params(ep->lch, OMAP_DMA_DATA_TYPE_S16, 644 } else {
636 ep->ep.maxpacket >> 1, packets, 645 /* set up this DMA transfer, enable the fifo, start */
637 OMAP_DMA_SYNC_ELEMENT, 646 packets /= ep->ep.maxpacket;
638 0, 0); 647 packets = min(packets, (unsigned)UDC_RXN_TC + 1);
648 req->dma_bytes = packets * ep->ep.maxpacket;
649 omap_set_dma_transfer_params(ep->lch, OMAP_DMA_DATA_TYPE_S16,
650 ep->ep.maxpacket >> 1, packets,
651 OMAP_DMA_SYNC_ELEMENT,
652 dma_trigger, 0);
653 }
639 omap_set_dma_dest_params(ep->lch, OMAP_DMA_PORT_EMIFF, 654 omap_set_dma_dest_params(ep->lch, OMAP_DMA_PORT_EMIFF,
640 OMAP_DMA_AMODE_POST_INC, req->req.dma + req->req.actual, 655 OMAP_DMA_AMODE_POST_INC, req->req.dma + req->req.actual,
641 0, 0); 656 0, 0);
@@ -743,6 +758,7 @@ static void dma_channel_claim(struct omap_ep *ep, unsigned channel)
743{ 758{
744 u16 reg; 759 u16 reg;
745 int status, restart, is_in; 760 int status, restart, is_in;
761 int dma_channel;
746 762
747 is_in = ep->bEndpointAddress & USB_DIR_IN; 763 is_in = ep->bEndpointAddress & USB_DIR_IN;
748 if (is_in) 764 if (is_in)
@@ -769,11 +785,15 @@ static void dma_channel_claim(struct omap_ep *ep, unsigned channel)
769 ep->dma_channel = channel; 785 ep->dma_channel = channel;
770 786
771 if (is_in) { 787 if (is_in) {
772 status = omap_request_dma(OMAP_DMA_USB_W2FC_TX0 - 1 + channel, 788 if (cpu_is_omap24xx())
789 dma_channel = OMAP24XX_DMA(USB_W2FC_TX0, channel);
790 else
791 dma_channel = OMAP_DMA_USB_W2FC_TX0 - 1 + channel;
792 status = omap_request_dma(dma_channel,
773 ep->ep.name, dma_error, ep, &ep->lch); 793 ep->ep.name, dma_error, ep, &ep->lch);
774 if (status == 0) { 794 if (status == 0) {
775 UDC_TXDMA_CFG_REG = reg; 795 UDC_TXDMA_CFG_REG = reg;
776 /* EMIFF */ 796 /* EMIFF or SDRC */
777 omap_set_dma_src_burst_mode(ep->lch, 797 omap_set_dma_src_burst_mode(ep->lch,
778 OMAP_DMA_DATA_BURST_4); 798 OMAP_DMA_DATA_BURST_4);
779 omap_set_dma_src_data_pack(ep->lch, 1); 799 omap_set_dma_src_data_pack(ep->lch, 1);
@@ -785,7 +805,12 @@ static void dma_channel_claim(struct omap_ep *ep, unsigned channel)
785 0, 0); 805 0, 0);
786 } 806 }
787 } else { 807 } else {
788 status = omap_request_dma(OMAP_DMA_USB_W2FC_RX0 - 1 + channel, 808 if (cpu_is_omap24xx())
809 dma_channel = OMAP24XX_DMA(USB_W2FC_RX0, channel);
810 else
811 dma_channel = OMAP_DMA_USB_W2FC_RX0 - 1 + channel;
812
813 status = omap_request_dma(dma_channel,
789 ep->ep.name, dma_error, ep, &ep->lch); 814 ep->ep.name, dma_error, ep, &ep->lch);
790 if (status == 0) { 815 if (status == 0) {
791 UDC_RXDMA_CFG_REG = reg; 816 UDC_RXDMA_CFG_REG = reg;
@@ -795,7 +820,7 @@ static void dma_channel_claim(struct omap_ep *ep, unsigned channel)
795 OMAP_DMA_AMODE_CONSTANT, 820 OMAP_DMA_AMODE_CONSTANT,
796 (unsigned long) io_v2p((u32)&UDC_DATA_DMA_REG), 821 (unsigned long) io_v2p((u32)&UDC_DATA_DMA_REG),
797 0, 0); 822 0, 0);
798 /* EMIFF */ 823 /* EMIFF or SDRC */
799 omap_set_dma_dest_burst_mode(ep->lch, 824 omap_set_dma_dest_burst_mode(ep->lch,
800 OMAP_DMA_DATA_BURST_4); 825 OMAP_DMA_DATA_BURST_4);
801 omap_set_dma_dest_data_pack(ep->lch, 1); 826 omap_set_dma_dest_data_pack(ep->lch, 1);
@@ -808,7 +833,7 @@ static void dma_channel_claim(struct omap_ep *ep, unsigned channel)
808 omap_disable_dma_irq(ep->lch, OMAP_DMA_BLOCK_IRQ); 833 omap_disable_dma_irq(ep->lch, OMAP_DMA_BLOCK_IRQ);
809 834
810 /* channel type P: hw synch (fifo) */ 835 /* channel type P: hw synch (fifo) */
811 if (!cpu_is_omap15xx()) 836 if (cpu_class_is_omap1() && !cpu_is_omap15xx())
812 OMAP1_DMA_LCH_CTRL_REG(ep->lch) = 2; 837 OMAP1_DMA_LCH_CTRL_REG(ep->lch) = 2;
813 } 838 }
814 839
@@ -926,11 +951,13 @@ omap_ep_queue(struct usb_ep *_ep, struct usb_request *_req, gfp_t gfp_flags)
926 951
927 /* this isn't bogus, but OMAP DMA isn't the only hardware to 952 /* this isn't bogus, but OMAP DMA isn't the only hardware to
928 * have a hard time with partial packet reads... reject it. 953 * have a hard time with partial packet reads... reject it.
954 * Except OMAP2 can handle the small packets.
929 */ 955 */
930 if (use_dma 956 if (use_dma
931 && ep->has_dma 957 && ep->has_dma
932 && ep->bEndpointAddress != 0 958 && ep->bEndpointAddress != 0
933 && (ep->bEndpointAddress & USB_DIR_IN) == 0 959 && (ep->bEndpointAddress & USB_DIR_IN) == 0
960 && !cpu_class_is_omap2()
934 && (req->req.length % ep->ep.maxpacket) != 0) { 961 && (req->req.length % ep->ep.maxpacket) != 0) {
935 DBG("%s, no partial packet OUT reads\n", __FUNCTION__); 962 DBG("%s, no partial packet OUT reads\n", __FUNCTION__);
936 return -EMSGSIZE; 963 return -EMSGSIZE;
@@ -1001,7 +1028,7 @@ omap_ep_queue(struct usb_ep *_ep, struct usb_request *_req, gfp_t gfp_flags)
1001 1028
1002 /* STATUS for zero length DATA stages is 1029 /* STATUS for zero length DATA stages is
1003 * always an IN ... even for IN transfers, 1030 * always an IN ... even for IN transfers,
1004 * a wierd case which seem to stall OMAP. 1031 * a weird case which seem to stall OMAP.
1005 */ 1032 */
1006 UDC_EP_NUM_REG = (UDC_EP_SEL|UDC_EP_DIR); 1033 UDC_EP_NUM_REG = (UDC_EP_SEL|UDC_EP_DIR);
1007 UDC_CTRL_REG = UDC_CLR_EP; 1034 UDC_CTRL_REG = UDC_CLR_EP;
diff --git a/drivers/usb/gadget/omap_udc.h b/drivers/usb/gadget/omap_udc.h
index 1dc398bb9ab2..c6b9cbc7230a 100644
--- a/drivers/usb/gadget/omap_udc.h
+++ b/drivers/usb/gadget/omap_udc.h
@@ -182,21 +182,16 @@ struct omap_udc {
182 182
183/*-------------------------------------------------------------------------*/ 183/*-------------------------------------------------------------------------*/
184 184
185#ifdef DEBUG
186#define DBG(stuff...) printk(KERN_DEBUG "udc: " stuff)
187#else
188#define DBG(stuff...) do{}while(0)
189#endif
190
191#ifdef VERBOSE 185#ifdef VERBOSE
192# define VDBG DBG 186# define VDBG DBG
193#else 187#else
194# define VDBG(stuff...) do{}while(0) 188# define VDBG(stuff...) do{}while(0)
195#endif 189#endif
196 190
197#define ERR(stuff...) printk(KERN_ERR "udc: " stuff) 191#define ERR(stuff...) pr_err("udc: " stuff)
198#define WARN(stuff...) printk(KERN_WARNING "udc: " stuff) 192#define WARN(stuff...) pr_warning("udc: " stuff)
199#define INFO(stuff...) printk(KERN_INFO "udc: " stuff) 193#define INFO(stuff...) pr_info("udc: " stuff)
194#define DBG(stuff...) pr_debug("udc: " stuff)
200 195
201/*-------------------------------------------------------------------------*/ 196/*-------------------------------------------------------------------------*/
202 197
diff --git a/drivers/usb/gadget/printer.c b/drivers/usb/gadget/printer.c
new file mode 100644
index 000000000000..9fdabc8fcac4
--- /dev/null
+++ b/drivers/usb/gadget/printer.c
@@ -0,0 +1,1592 @@
1/*
2 * printer.c -- Printer gadget driver
3 *
4 * Copyright (C) 2003-2005 David Brownell
5 * Copyright (C) 2006 Craig W. Nadler
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 */
21
22#include <linux/module.h>
23#include <linux/kernel.h>
24#include <linux/delay.h>
25#include <linux/ioport.h>
26#include <linux/sched.h>
27#include <linux/slab.h>
28#include <linux/smp_lock.h>
29#include <linux/errno.h>
30#include <linux/init.h>
31#include <linux/timer.h>
32#include <linux/list.h>
33#include <linux/interrupt.h>
34#include <linux/utsname.h>
35#include <linux/device.h>
36#include <linux/moduleparam.h>
37#include <linux/fs.h>
38#include <linux/poll.h>
39#include <linux/types.h>
40#include <linux/ctype.h>
41#include <linux/cdev.h>
42
43#include <asm/byteorder.h>
44#include <linux/io.h>
45#include <linux/irq.h>
46#include <asm/system.h>
47#include <linux/uaccess.h>
48#include <asm/unaligned.h>
49
50#include <linux/usb/ch9.h>
51#include <linux/usb/gadget.h>
52#include <linux/usb/g_printer.h>
53
54#include "gadget_chips.h"
55
56#define DRIVER_DESC "Printer Gadget"
57#define DRIVER_VERSION "2007 OCT 06"
58
59static const char shortname [] = "printer";
60static const char driver_desc [] = DRIVER_DESC;
61
62static dev_t g_printer_devno;
63
64static struct class *usb_gadget_class;
65
66/*-------------------------------------------------------------------------*/
67
68struct printer_dev {
69 spinlock_t lock; /* lock this structure */
70 /* lock buffer lists during read/write calls */
71 spinlock_t lock_printer_io;
72 struct usb_gadget *gadget;
73 struct usb_request *req; /* for control responses */
74 u8 config;
75 s8 interface;
76 struct usb_ep *in_ep, *out_ep;
77 const struct usb_endpoint_descriptor
78 *in, *out;
79 struct list_head rx_reqs; /* List of free RX structs */
80 struct list_head rx_reqs_active; /* List of Active RX xfers */
81 struct list_head rx_buffers; /* List of completed xfers */
82 /* wait until there is data to be read. */
83 wait_queue_head_t rx_wait;
84 struct list_head tx_reqs; /* List of free TX structs */
85 struct list_head tx_reqs_active; /* List of Active TX xfers */
86 /* Wait until there are write buffers available to use. */
87 wait_queue_head_t tx_wait;
88 /* Wait until all write buffers have been sent. */
89 wait_queue_head_t tx_flush_wait;
90 struct usb_request *current_rx_req;
91 size_t current_rx_bytes;
92 u8 *current_rx_buf;
93 u8 printer_status;
94 u8 reset_printer;
95 struct class_device *printer_class_dev;
96 struct cdev printer_cdev;
97 struct device *pdev;
98 u8 printer_cdev_open;
99 wait_queue_head_t wait;
100};
101
102static struct printer_dev usb_printer_gadget;
103
104/*-------------------------------------------------------------------------*/
105
106/* DO NOT REUSE THESE IDs with a protocol-incompatible driver!! Ever!!
107 * Instead: allocate your own, using normal USB-IF procedures.
108 */
109
110/* Thanks to NetChip Technologies for donating this product ID.
111 */
112#define PRINTER_VENDOR_NUM 0x0525 /* NetChip */
113#define PRINTER_PRODUCT_NUM 0xa4a8 /* Linux-USB Printer Gadget */
114
115/* Some systems will want different product identifers published in the
116 * device descriptor, either numbers or strings or both. These string
117 * parameters are in UTF-8 (superset of ASCII's 7 bit characters).
118 */
119
120static ushort __initdata idVendor;
121module_param(idVendor, ushort, S_IRUGO);
122MODULE_PARM_DESC(idVendor, "USB Vendor ID");
123
124static ushort __initdata idProduct;
125module_param(idProduct, ushort, S_IRUGO);
126MODULE_PARM_DESC(idProduct, "USB Product ID");
127
128static ushort __initdata bcdDevice;
129module_param(bcdDevice, ushort, S_IRUGO);
130MODULE_PARM_DESC(bcdDevice, "USB Device version (BCD)");
131
132static char *__initdata iManufacturer;
133module_param(iManufacturer, charp, S_IRUGO);
134MODULE_PARM_DESC(iManufacturer, "USB Manufacturer string");
135
136static char *__initdata iProduct;
137module_param(iProduct, charp, S_IRUGO);
138MODULE_PARM_DESC(iProduct, "USB Product string");
139
140static char *__initdata iSerialNum;
141module_param(iSerialNum, charp, S_IRUGO);
142MODULE_PARM_DESC(iSerialNum, "1");
143
144static char *__initdata iPNPstring;
145module_param(iPNPstring, charp, S_IRUGO);
146MODULE_PARM_DESC(iPNPstring, "MFG:linux;MDL:g_printer;CLS:PRINTER;SN:1;");
147
148/* Number of requests to allocate per endpoint, not used for ep0. */
149static unsigned qlen = 10;
150module_param(qlen, uint, S_IRUGO|S_IWUSR);
151
152#define QLEN qlen
153
154#ifdef CONFIG_USB_GADGET_DUALSPEED
155#define DEVSPEED USB_SPEED_HIGH
156#else /* full speed (low speed doesn't do bulk) */
157#define DEVSPEED USB_SPEED_FULL
158#endif
159
160/*-------------------------------------------------------------------------*/
161
162#define xprintk(d, level, fmt, args...) \
163 printk(level "%s: " fmt, DRIVER_DESC, ## args)
164
165#ifdef DEBUG
166#define DBG(dev, fmt, args...) \
167 xprintk(dev, KERN_DEBUG, fmt, ## args)
168#else
169#define DBG(dev, fmt, args...) \
170 do { } while (0)
171#endif /* DEBUG */
172
173#ifdef VERBOSE
174#define VDBG(dev, fmt, args...) \
175 xprintk(dev, KERN_DEBUG, fmt, ## args)
176#else
177#define VDBG(dev, fmt, args...) \
178 do { } while (0)
179#endif /* VERBOSE */
180
181#define ERROR(dev, fmt, args...) \
182 xprintk(dev, KERN_ERR, fmt, ## args)
183#define WARN(dev, fmt, args...) \
184 xprintk(dev, KERN_WARNING, fmt, ## args)
185#define INFO(dev, fmt, args...) \
186 xprintk(dev, KERN_INFO, fmt, ## args)
187
188/*-------------------------------------------------------------------------*/
189
190/* USB DRIVER HOOKUP (to the hardware driver, below us), mostly
191 * ep0 implementation: descriptors, config management, setup().
192 * also optional class-specific notification interrupt transfer.
193 */
194
195/*
196 * DESCRIPTORS ... most are static, but strings and (full) configuration
197 * descriptors are built on demand.
198 */
199
200#define STRING_MANUFACTURER 1
201#define STRING_PRODUCT 2
202#define STRING_SERIALNUM 3
203
204/* holds our biggest descriptor */
205#define USB_DESC_BUFSIZE 256
206#define USB_BUFSIZE 8192
207
208/* This device advertises one configuration. */
209#define DEV_CONFIG_VALUE 1
210#define PRINTER_INTERFACE 0
211
212static struct usb_device_descriptor device_desc = {
213 .bLength = sizeof device_desc,
214 .bDescriptorType = USB_DT_DEVICE,
215 .bcdUSB = __constant_cpu_to_le16(0x0200),
216 .bDeviceClass = USB_CLASS_PER_INTERFACE,
217 .bDeviceSubClass = 0,
218 .bDeviceProtocol = 0,
219 .idVendor = __constant_cpu_to_le16(PRINTER_VENDOR_NUM),
220 .idProduct = __constant_cpu_to_le16(PRINTER_PRODUCT_NUM),
221 .iManufacturer = STRING_MANUFACTURER,
222 .iProduct = STRING_PRODUCT,
223 .iSerialNumber = STRING_SERIALNUM,
224 .bNumConfigurations = 1
225};
226
227static struct usb_otg_descriptor otg_desc = {
228 .bLength = sizeof otg_desc,
229 .bDescriptorType = USB_DT_OTG,
230 .bmAttributes = USB_OTG_SRP
231};
232
233static struct usb_config_descriptor config_desc = {
234 .bLength = sizeof config_desc,
235 .bDescriptorType = USB_DT_CONFIG,
236
237 /* compute wTotalLength on the fly */
238 .bNumInterfaces = 1,
239 .bConfigurationValue = DEV_CONFIG_VALUE,
240 .iConfiguration = 0,
241 .bmAttributes = USB_CONFIG_ATT_ONE | USB_CONFIG_ATT_SELFPOWER,
242 .bMaxPower = 1 /* Self-Powered */
243};
244
245static struct usb_interface_descriptor intf_desc = {
246 .bLength = sizeof intf_desc,
247 .bDescriptorType = USB_DT_INTERFACE,
248 .bInterfaceNumber = PRINTER_INTERFACE,
249 .bNumEndpoints = 2,
250 .bInterfaceClass = USB_CLASS_PRINTER,
251 .bInterfaceSubClass = 1, /* Printer Sub-Class */
252 .bInterfaceProtocol = 2, /* Bi-Directional */
253 .iInterface = 0
254};
255
256static struct usb_endpoint_descriptor fs_ep_in_desc = {
257 .bLength = USB_DT_ENDPOINT_SIZE,
258 .bDescriptorType = USB_DT_ENDPOINT,
259 .bEndpointAddress = USB_DIR_IN,
260 .bmAttributes = USB_ENDPOINT_XFER_BULK
261};
262
263static struct usb_endpoint_descriptor fs_ep_out_desc = {
264 .bLength = USB_DT_ENDPOINT_SIZE,
265 .bDescriptorType = USB_DT_ENDPOINT,
266 .bEndpointAddress = USB_DIR_OUT,
267 .bmAttributes = USB_ENDPOINT_XFER_BULK
268};
269
270static const struct usb_descriptor_header *fs_printer_function [11] = {
271 (struct usb_descriptor_header *) &otg_desc,
272 (struct usb_descriptor_header *) &intf_desc,
273 (struct usb_descriptor_header *) &fs_ep_in_desc,
274 (struct usb_descriptor_header *) &fs_ep_out_desc,
275 NULL
276};
277
278#ifdef CONFIG_USB_GADGET_DUALSPEED
279
280/*
281 * usb 2.0 devices need to expose both high speed and full speed
282 * descriptors, unless they only run at full speed.
283 */
284
285static struct usb_endpoint_descriptor hs_ep_in_desc = {
286 .bLength = USB_DT_ENDPOINT_SIZE,
287 .bDescriptorType = USB_DT_ENDPOINT,
288 .bmAttributes = USB_ENDPOINT_XFER_BULK,
289 .wMaxPacketSize = __constant_cpu_to_le16(512)
290};
291
292static struct usb_endpoint_descriptor hs_ep_out_desc = {
293 .bLength = USB_DT_ENDPOINT_SIZE,
294 .bDescriptorType = USB_DT_ENDPOINT,
295 .bmAttributes = USB_ENDPOINT_XFER_BULK,
296 .wMaxPacketSize = __constant_cpu_to_le16(512)
297};
298
299static struct usb_qualifier_descriptor dev_qualifier = {
300 .bLength = sizeof dev_qualifier,
301 .bDescriptorType = USB_DT_DEVICE_QUALIFIER,
302 .bcdUSB = __constant_cpu_to_le16(0x0200),
303 .bDeviceClass = USB_CLASS_PRINTER,
304 .bNumConfigurations = 1
305};
306
307static const struct usb_descriptor_header *hs_printer_function [11] = {
308 (struct usb_descriptor_header *) &otg_desc,
309 (struct usb_descriptor_header *) &intf_desc,
310 (struct usb_descriptor_header *) &hs_ep_in_desc,
311 (struct usb_descriptor_header *) &hs_ep_out_desc,
312 NULL
313};
314
315/* maxpacket and other transfer characteristics vary by speed. */
316#define ep_desc(g, hs, fs) (((g)->speed == USB_SPEED_HIGH)?(hs):(fs))
317
318#else
319
320/* if there's no high speed support, maxpacket doesn't change. */
321#define ep_desc(g, hs, fs) (((void)(g)), (fs))
322
323#endif /* !CONFIG_USB_GADGET_DUALSPEED */
324
325/*-------------------------------------------------------------------------*/
326
327/* descriptors that are built on-demand */
328
329static char manufacturer [50];
330static char product_desc [40] = DRIVER_DESC;
331static char serial_num [40] = "1";
332static char pnp_string [1024] =
333 "XXMFG:linux;MDL:g_printer;CLS:PRINTER;SN:1;";
334
335/* static strings, in UTF-8 */
336static struct usb_string strings [] = {
337 { STRING_MANUFACTURER, manufacturer, },
338 { STRING_PRODUCT, product_desc, },
339 { STRING_SERIALNUM, serial_num, },
340 { } /* end of list */
341};
342
343static struct usb_gadget_strings stringtab = {
344 .language = 0x0409, /* en-us */
345 .strings = strings,
346};
347
348/*-------------------------------------------------------------------------*/
349
350static struct usb_request *
351printer_req_alloc(struct usb_ep *ep, unsigned len, gfp_t gfp_flags)
352{
353 struct usb_request *req;
354
355 req = usb_ep_alloc_request(ep, gfp_flags);
356
357 if (req != NULL) {
358 req->length = len;
359 req->buf = kmalloc(len, gfp_flags);
360 if (req->buf == NULL) {
361 usb_ep_free_request(ep, req);
362 return NULL;
363 }
364 }
365
366 return req;
367}
368
369static void
370printer_req_free(struct usb_ep *ep, struct usb_request *req)
371{
372 if (ep != NULL && req != NULL) {
373 kfree(req->buf);
374 usb_ep_free_request(ep, req);
375 }
376}
377
378/*-------------------------------------------------------------------------*/
379
380static void rx_complete(struct usb_ep *ep, struct usb_request *req)
381{
382 struct printer_dev *dev = ep->driver_data;
383 int status = req->status;
384 unsigned long flags;
385
386 spin_lock_irqsave(&dev->lock, flags);
387
388 list_del_init(&req->list); /* Remode from Active List */
389
390 switch (status) {
391
392 /* normal completion */
393 case 0:
394 list_add_tail(&req->list, &dev->rx_buffers);
395 wake_up_interruptible(&dev->rx_wait);
396 DBG(dev, "G_Printer : rx length %d\n", req->actual);
397 break;
398
399 /* software-driven interface shutdown */
400 case -ECONNRESET: /* unlink */
401 case -ESHUTDOWN: /* disconnect etc */
402 VDBG(dev, "rx shutdown, code %d\n", status);
403 list_add(&req->list, &dev->rx_reqs);
404 break;
405
406 /* for hardware automagic (such as pxa) */
407 case -ECONNABORTED: /* endpoint reset */
408 DBG(dev, "rx %s reset\n", ep->name);
409 list_add(&req->list, &dev->rx_reqs);
410 break;
411
412 /* data overrun */
413 case -EOVERFLOW:
414 /* FALLTHROUGH */
415
416 default:
417 DBG(dev, "rx status %d\n", status);
418 list_add(&req->list, &dev->rx_reqs);
419 break;
420 }
421 spin_unlock_irqrestore(&dev->lock, flags);
422}
423
424static void tx_complete(struct usb_ep *ep, struct usb_request *req)
425{
426 struct printer_dev *dev = ep->driver_data;
427
428 switch (req->status) {
429 default:
430 VDBG(dev, "tx err %d\n", req->status);
431 /* FALLTHROUGH */
432 case -ECONNRESET: /* unlink */
433 case -ESHUTDOWN: /* disconnect etc */
434 break;
435 case 0:
436 break;
437 }
438
439 spin_lock(&dev->lock);
440 /* Take the request struct off the active list and put it on the
441 * free list.
442 */
443 list_del_init(&req->list);
444 list_add(&req->list, &dev->tx_reqs);
445 wake_up_interruptible(&dev->tx_wait);
446 if (likely(list_empty(&dev->tx_reqs_active)))
447 wake_up_interruptible(&dev->tx_flush_wait);
448
449 spin_unlock(&dev->lock);
450}
451
452/*-------------------------------------------------------------------------*/
453
454static int
455printer_open(struct inode *inode, struct file *fd)
456{
457 struct printer_dev *dev;
458 unsigned long flags;
459 int ret = -EBUSY;
460
461 dev = container_of(inode->i_cdev, struct printer_dev, printer_cdev);
462
463 spin_lock_irqsave(&dev->lock, flags);
464
465 if (!dev->printer_cdev_open) {
466 dev->printer_cdev_open = 1;
467 fd->private_data = dev;
468 ret = 0;
469 /* Change the printer status to show that it's on-line. */
470 dev->printer_status |= PRINTER_SELECTED;
471 }
472
473 spin_unlock_irqrestore(&dev->lock, flags);
474
475 DBG(dev, "printer_open returned %x\n", ret);
476
477 return ret;
478}
479
480static int
481printer_close(struct inode *inode, struct file *fd)
482{
483 struct printer_dev *dev = fd->private_data;
484 unsigned long flags;
485
486 spin_lock_irqsave(&dev->lock, flags);
487 dev->printer_cdev_open = 0;
488 fd->private_data = NULL;
489 /* Change printer status to show that the printer is off-line. */
490 dev->printer_status &= ~PRINTER_SELECTED;
491 spin_unlock_irqrestore(&dev->lock, flags);
492
493 DBG(dev, "printer_close\n");
494
495 return 0;
496}
497
498static ssize_t
499printer_read(struct file *fd, char __user *buf, size_t len, loff_t *ptr)
500{
501 struct printer_dev *dev = fd->private_data;
502 unsigned long flags;
503 size_t size;
504 size_t bytes_copied;
505 struct usb_request *req;
506 /* This is a pointer to the current USB rx request. */
507 struct usb_request *current_rx_req;
508 /* This is the number of bytes in the current rx buffer. */
509 size_t current_rx_bytes;
510 /* This is a pointer to the current rx buffer. */
511 u8 *current_rx_buf;
512
513 if (len == 0)
514 return -EINVAL;
515
516 DBG(dev, "printer_read trying to read %d bytes\n", (int)len);
517
518 spin_lock(&dev->lock_printer_io);
519 spin_lock_irqsave(&dev->lock, flags);
520
521 /* We will use this flag later to check if a printer reset happened
522 * after we turn interrupts back on.
523 */
524 dev->reset_printer = 0;
525
526 while (likely(!list_empty(&dev->rx_reqs))) {
527 int error;
528
529 req = container_of(dev->rx_reqs.next,
530 struct usb_request, list);
531 list_del_init(&req->list);
532
533 /* The USB Host sends us whatever amount of data it wants to
534 * so we always set the length field to the full USB_BUFSIZE.
535 * If the amount of data is more than the read() caller asked
536 * for it will be stored in the request buffer until it is
537 * asked for by read().
538 */
539 req->length = USB_BUFSIZE;
540 req->complete = rx_complete;
541
542 error = usb_ep_queue(dev->out_ep, req, GFP_ATOMIC);
543 if (error) {
544 DBG(dev, "rx submit --> %d\n", error);
545 list_add(&req->list, &dev->rx_reqs);
546 break;
547 } else {
548 list_add(&req->list, &dev->rx_reqs_active);
549 }
550 }
551
552 bytes_copied = 0;
553 current_rx_req = dev->current_rx_req;
554 current_rx_bytes = dev->current_rx_bytes;
555 current_rx_buf = dev->current_rx_buf;
556 dev->current_rx_req = NULL;
557 dev->current_rx_bytes = 0;
558 dev->current_rx_buf = NULL;
559
560 /* Check if there is any data in the read buffers. Please note that
561 * current_rx_bytes is the number of bytes in the current rx buffer.
562 * If it is zero then check if there are any other rx_buffers that
563 * are on the completed list. We are only out of data if all rx
564 * buffers are empty.
565 */
566 if ((current_rx_bytes == 0) &&
567 (likely(list_empty(&dev->rx_buffers)))) {
568 /* Turn interrupts back on before sleeping. */
569 spin_unlock_irqrestore(&dev->lock, flags);
570
571 /*
572 * If no data is available check if this is a NON-Blocking
573 * call or not.
574 */
575 if (fd->f_flags & (O_NONBLOCK|O_NDELAY)) {
576 spin_unlock(&dev->lock_printer_io);
577 return -EAGAIN;
578 }
579
580 /* Sleep until data is available */
581 wait_event_interruptible(dev->rx_wait,
582 (likely(!list_empty(&dev->rx_buffers))));
583 spin_lock_irqsave(&dev->lock, flags);
584 }
585
586 /* We have data to return then copy it to the caller's buffer.*/
587 while ((current_rx_bytes || likely(!list_empty(&dev->rx_buffers)))
588 && len) {
589 if (current_rx_bytes == 0) {
590 req = container_of(dev->rx_buffers.next,
591 struct usb_request, list);
592 list_del_init(&req->list);
593
594 if (req->actual && req->buf) {
595 current_rx_req = req;
596 current_rx_bytes = req->actual;
597 current_rx_buf = req->buf;
598 } else {
599 list_add(&req->list, &dev->rx_reqs);
600 continue;
601 }
602 }
603
604 /* Don't leave irqs off while doing memory copies */
605 spin_unlock_irqrestore(&dev->lock, flags);
606
607 if (len > current_rx_bytes)
608 size = current_rx_bytes;
609 else
610 size = len;
611
612 size -= copy_to_user(buf, current_rx_buf, size);
613 bytes_copied += size;
614 len -= size;
615 buf += size;
616
617 spin_lock_irqsave(&dev->lock, flags);
618
619 /* We've disconnected or reset free the req and buffer */
620 if (dev->reset_printer) {
621 printer_req_free(dev->out_ep, current_rx_req);
622 spin_unlock_irqrestore(&dev->lock, flags);
623 spin_unlock(&dev->lock_printer_io);
624 return -EAGAIN;
625 }
626
627 /* If we not returning all the data left in this RX request
628 * buffer then adjust the amount of data left in the buffer.
629 * Othewise if we are done with this RX request buffer then
630 * requeue it to get any incoming data from the USB host.
631 */
632 if (size < current_rx_bytes) {
633 current_rx_bytes -= size;
634 current_rx_buf += size;
635 } else {
636 list_add(&current_rx_req->list, &dev->rx_reqs);
637 current_rx_bytes = 0;
638 current_rx_buf = NULL;
639 current_rx_req = NULL;
640 }
641 }
642
643 dev->current_rx_req = current_rx_req;
644 dev->current_rx_bytes = current_rx_bytes;
645 dev->current_rx_buf = current_rx_buf;
646
647 spin_unlock_irqrestore(&dev->lock, flags);
648 spin_unlock(&dev->lock_printer_io);
649
650 DBG(dev, "printer_read returned %d bytes\n", (int)bytes_copied);
651
652 if (bytes_copied)
653 return bytes_copied;
654 else
655 return -EAGAIN;
656}
657
658static ssize_t
659printer_write(struct file *fd, const char __user *buf, size_t len, loff_t *ptr)
660{
661 struct printer_dev *dev = fd->private_data;
662 unsigned long flags;
663 size_t size; /* Amount of data in a TX request. */
664 size_t bytes_copied = 0;
665 struct usb_request *req;
666
667 DBG(dev, "printer_write trying to send %d bytes\n", (int)len);
668
669 if (len == 0)
670 return -EINVAL;
671
672 spin_lock(&dev->lock_printer_io);
673 spin_lock_irqsave(&dev->lock, flags);
674
675 /* Check if a printer reset happens while we have interrupts on */
676 dev->reset_printer = 0;
677
678 /* Check if there is any available write buffers */
679 if (likely(list_empty(&dev->tx_reqs))) {
680 /* Turn interrupts back on before sleeping. */
681 spin_unlock_irqrestore(&dev->lock, flags);
682
683 /*
684 * If write buffers are available check if this is
685 * a NON-Blocking call or not.
686 */
687 if (fd->f_flags & (O_NONBLOCK|O_NDELAY)) {
688 spin_unlock(&dev->lock_printer_io);
689 return -EAGAIN;
690 }
691
692 /* Sleep until a write buffer is available */
693 wait_event_interruptible(dev->tx_wait,
694 (likely(!list_empty(&dev->tx_reqs))));
695 spin_lock_irqsave(&dev->lock, flags);
696 }
697
698 while (likely(!list_empty(&dev->tx_reqs)) && len) {
699
700 if (len > USB_BUFSIZE)
701 size = USB_BUFSIZE;
702 else
703 size = len;
704
705 req = container_of(dev->tx_reqs.next, struct usb_request,
706 list);
707 list_del_init(&req->list);
708
709 req->complete = tx_complete;
710 req->length = size;
711
712 /* Check if we need to send a zero length packet. */
713 if (len > size)
714 /* They will be more TX requests so no yet. */
715 req->zero = 0;
716 else
717 /* If the data amount is not a multple of the
718 * maxpacket size then send a zero length packet.
719 */
720 req->zero = ((len % dev->in_ep->maxpacket) == 0);
721
722 /* Don't leave irqs off while doing memory copies */
723 spin_unlock_irqrestore(&dev->lock, flags);
724
725 if (copy_from_user(req->buf, buf, size)) {
726 list_add(&req->list, &dev->tx_reqs);
727 spin_unlock(&dev->lock_printer_io);
728 return bytes_copied;
729 }
730
731 bytes_copied += size;
732 len -= size;
733 buf += size;
734
735 spin_lock_irqsave(&dev->lock, flags);
736
737 /* We've disconnected or reset so free the req and buffer */
738 if (dev->reset_printer) {
739 printer_req_free(dev->in_ep, req);
740 spin_unlock_irqrestore(&dev->lock, flags);
741 spin_unlock(&dev->lock_printer_io);
742 return -EAGAIN;
743 }
744
745 if (usb_ep_queue(dev->in_ep, req, GFP_ATOMIC)) {
746 list_add(&req->list, &dev->tx_reqs);
747 spin_unlock_irqrestore(&dev->lock, flags);
748 spin_unlock(&dev->lock_printer_io);
749 return -EAGAIN;
750 }
751
752 list_add(&req->list, &dev->tx_reqs_active);
753
754 }
755
756 spin_unlock_irqrestore(&dev->lock, flags);
757 spin_unlock(&dev->lock_printer_io);
758
759 DBG(dev, "printer_write sent %d bytes\n", (int)bytes_copied);
760
761 if (bytes_copied) {
762 return bytes_copied;
763 } else {
764 return -EAGAIN;
765 }
766}
767
768static int
769printer_fsync(struct file *fd, struct dentry *dentry, int datasync)
770{
771 struct printer_dev *dev = fd->private_data;
772 unsigned long flags;
773 int tx_list_empty;
774
775 spin_lock_irqsave(&dev->lock, flags);
776 tx_list_empty = (likely(list_empty(&dev->tx_reqs)));
777 spin_unlock_irqrestore(&dev->lock, flags);
778
779 if (!tx_list_empty) {
780 /* Sleep until all data has been sent */
781 wait_event_interruptible(dev->tx_flush_wait,
782 (likely(list_empty(&dev->tx_reqs_active))));
783 }
784
785 return 0;
786}
787
788static unsigned int
789printer_poll(struct file *fd, poll_table *wait)
790{
791 struct printer_dev *dev = fd->private_data;
792 unsigned long flags;
793 int status = 0;
794
795 poll_wait(fd, &dev->rx_wait, wait);
796 poll_wait(fd, &dev->tx_wait, wait);
797
798 spin_lock_irqsave(&dev->lock, flags);
799 if (likely(!list_empty(&dev->tx_reqs)))
800 status |= POLLOUT | POLLWRNORM;
801
802 if (likely(!list_empty(&dev->rx_buffers)))
803 status |= POLLIN | POLLRDNORM;
804
805 spin_unlock_irqrestore(&dev->lock, flags);
806
807 return status;
808}
809
810static int
811printer_ioctl(struct inode *inode, struct file *fd, unsigned int code,
812 unsigned long arg)
813{
814 struct printer_dev *dev = fd->private_data;
815 unsigned long flags;
816 int status = 0;
817
818 DBG(dev, "printer_ioctl: cmd=0x%4.4x, arg=%lu\n", code, arg);
819
820 /* handle ioctls */
821
822 spin_lock_irqsave(&dev->lock, flags);
823
824 switch (code) {
825 case GADGET_GET_PRINTER_STATUS:
826 status = (int)dev->printer_status;
827 break;
828 case GADGET_SET_PRINTER_STATUS:
829 dev->printer_status = (u8)arg;
830 break;
831 default:
832 /* could not handle ioctl */
833 DBG(dev, "printer_ioctl: ERROR cmd=0x%4.4xis not supported\n",
834 code);
835 status = -ENOTTY;
836 }
837
838 spin_unlock_irqrestore(&dev->lock, flags);
839
840 return status;
841}
842
843/* used after endpoint configuration */
844static struct file_operations printer_io_operations = {
845 .owner = THIS_MODULE,
846 .open = printer_open,
847 .read = printer_read,
848 .write = printer_write,
849 .fsync = printer_fsync,
850 .poll = printer_poll,
851 .ioctl = printer_ioctl,
852 .release = printer_close
853};
854
855/*-------------------------------------------------------------------------*/
856
857static int
858set_printer_interface(struct printer_dev *dev)
859{
860 int result = 0;
861
862 dev->in = ep_desc(dev->gadget, &hs_ep_in_desc, &fs_ep_in_desc);
863 dev->in_ep->driver_data = dev;
864
865 dev->out = ep_desc(dev->gadget, &hs_ep_out_desc, &fs_ep_out_desc);
866 dev->out_ep->driver_data = dev;
867
868 result = usb_ep_enable(dev->in_ep, dev->in);
869 if (result != 0) {
870 DBG(dev, "enable %s --> %d\n", dev->in_ep->name, result);
871 goto done;
872 }
873
874 result = usb_ep_enable(dev->out_ep, dev->out);
875 if (result != 0) {
876 DBG(dev, "enable %s --> %d\n", dev->in_ep->name, result);
877 goto done;
878 }
879
880done:
881 /* on error, disable any endpoints */
882 if (result != 0) {
883 (void) usb_ep_disable(dev->in_ep);
884 (void) usb_ep_disable(dev->out_ep);
885 dev->in = NULL;
886 dev->out = NULL;
887 }
888
889 /* caller is responsible for cleanup on error */
890 return result;
891}
892
893static void printer_reset_interface(struct printer_dev *dev)
894{
895 if (dev->interface < 0)
896 return;
897
898 DBG(dev, "%s\n", __FUNCTION__);
899
900 if (dev->in)
901 usb_ep_disable(dev->in_ep);
902
903 if (dev->out)
904 usb_ep_disable(dev->out_ep);
905
906 dev->interface = -1;
907}
908
909/* change our operational config. must agree with the code
910 * that returns config descriptors, and altsetting code.
911 */
912static int
913printer_set_config(struct printer_dev *dev, unsigned number)
914{
915 int result = 0;
916 struct usb_gadget *gadget = dev->gadget;
917
918 if (gadget_is_sa1100(gadget) && dev->config) {
919 /* tx fifo is full, but we can't clear it...*/
920 INFO(dev, "can't change configurations\n");
921 return -ESPIPE;
922 }
923
924 switch (number) {
925 case DEV_CONFIG_VALUE:
926 result = 0;
927 break;
928 default:
929 result = -EINVAL;
930 /* FALL THROUGH */
931 case 0:
932 break;
933 }
934
935 if (result) {
936 usb_gadget_vbus_draw(dev->gadget,
937 dev->gadget->is_otg ? 8 : 100);
938 } else {
939 char *speed;
940 unsigned power;
941
942 power = 2 * config_desc.bMaxPower;
943 usb_gadget_vbus_draw(dev->gadget, power);
944
945 switch (gadget->speed) {
946 case USB_SPEED_FULL: speed = "full"; break;
947#ifdef CONFIG_USB_GADGET_DUALSPEED
948 case USB_SPEED_HIGH: speed = "high"; break;
949#endif
950 default: speed = "?"; break;
951 }
952
953 dev->config = number;
954 INFO(dev, "%s speed config #%d: %d mA, %s\n",
955 speed, number, power, driver_desc);
956 }
957 return result;
958}
959
960static int
961config_buf(enum usb_device_speed speed, u8 *buf, u8 type, unsigned index,
962 int is_otg)
963{
964 int len;
965 const struct usb_descriptor_header **function;
966#ifdef CONFIG_USB_GADGET_DUALSPEED
967 int hs = (speed == USB_SPEED_HIGH);
968
969 if (type == USB_DT_OTHER_SPEED_CONFIG)
970 hs = !hs;
971
972 if (hs) {
973 function = hs_printer_function;
974 } else {
975 function = fs_printer_function;
976 }
977#else
978 function = fs_printer_function;
979#endif
980
981 if (index >= device_desc.bNumConfigurations)
982 return -EINVAL;
983
984 /* for now, don't advertise srp-only devices */
985 if (!is_otg)
986 function++;
987
988 len = usb_gadget_config_buf(&config_desc, buf, USB_DESC_BUFSIZE,
989 function);
990 if (len < 0)
991 return len;
992 ((struct usb_config_descriptor *) buf)->bDescriptorType = type;
993 return len;
994}
995
996/* Change our operational Interface. */
997static int
998set_interface(struct printer_dev *dev, unsigned number)
999{
1000 int result = 0;
1001
1002 if (gadget_is_sa1100(dev->gadget) && dev->interface < 0) {
1003 /* tx fifo is full, but we can't clear it...*/
1004 INFO(dev, "can't change interfaces\n");
1005 return -ESPIPE;
1006 }
1007
1008 /* Free the current interface */
1009 switch (dev->interface) {
1010 case PRINTER_INTERFACE:
1011 printer_reset_interface(dev);
1012 break;
1013 }
1014
1015 switch (number) {
1016 case PRINTER_INTERFACE:
1017 result = set_printer_interface(dev);
1018 if (result) {
1019 printer_reset_interface(dev);
1020 } else {
1021 dev->interface = PRINTER_INTERFACE;
1022 }
1023 break;
1024 default:
1025 result = -EINVAL;
1026 /* FALL THROUGH */
1027 }
1028
1029 if (!result)
1030 INFO(dev, "Using interface %x\n", number);
1031
1032 return result;
1033}
1034
1035static void printer_setup_complete(struct usb_ep *ep, struct usb_request *req)
1036{
1037 if (req->status || req->actual != req->length)
1038 DBG((struct printer_dev *) ep->driver_data,
1039 "setup complete --> %d, %d/%d\n",
1040 req->status, req->actual, req->length);
1041}
1042
1043static void printer_soft_reset(struct printer_dev *dev)
1044{
1045 struct usb_request *req;
1046
1047 INFO(dev, "Received Printer Reset Request\n");
1048
1049 if (usb_ep_disable(dev->in_ep))
1050 DBG(dev, "Failed to disable USB in_ep\n");
1051 if (usb_ep_disable(dev->out_ep))
1052 DBG(dev, "Failed to disable USB out_ep\n");
1053
1054 if (dev->current_rx_req != NULL) {
1055 list_add(&dev->current_rx_req->list, &dev->rx_reqs);
1056 dev->current_rx_req = NULL;
1057 }
1058 dev->current_rx_bytes = 0;
1059 dev->current_rx_buf = NULL;
1060 dev->reset_printer = 1;
1061
1062 while (likely(!(list_empty(&dev->rx_buffers)))) {
1063 req = container_of(dev->rx_buffers.next, struct usb_request,
1064 list);
1065 list_del_init(&req->list);
1066 list_add(&req->list, &dev->rx_reqs);
1067 }
1068
1069 while (likely(!(list_empty(&dev->rx_reqs_active)))) {
1070 req = container_of(dev->rx_buffers.next, struct usb_request,
1071 list);
1072 list_del_init(&req->list);
1073 list_add(&req->list, &dev->rx_reqs);
1074 }
1075
1076 while (likely(!(list_empty(&dev->tx_reqs_active)))) {
1077 req = container_of(dev->tx_reqs_active.next,
1078 struct usb_request, list);
1079 list_del_init(&req->list);
1080 list_add(&req->list, &dev->tx_reqs);
1081 }
1082
1083 if (usb_ep_enable(dev->in_ep, dev->in))
1084 DBG(dev, "Failed to enable USB in_ep\n");
1085 if (usb_ep_enable(dev->out_ep, dev->out))
1086 DBG(dev, "Failed to enable USB out_ep\n");
1087
1088 wake_up_interruptible(&dev->tx_wait);
1089 wake_up_interruptible(&dev->tx_flush_wait);
1090}
1091
1092/*-------------------------------------------------------------------------*/
1093
1094/*
1095 * The setup() callback implements all the ep0 functionality that's not
1096 * handled lower down.
1097 */
1098static int
1099printer_setup(struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl)
1100{
1101 struct printer_dev *dev = get_gadget_data(gadget);
1102 struct usb_request *req = dev->req;
1103 int value = -EOPNOTSUPP;
1104 u16 wIndex = le16_to_cpu(ctrl->wIndex);
1105 u16 wValue = le16_to_cpu(ctrl->wValue);
1106 u16 wLength = le16_to_cpu(ctrl->wLength);
1107
1108 DBG(dev, "ctrl req%02x.%02x v%04x i%04x l%d\n",
1109 ctrl->bRequestType, ctrl->bRequest, wValue, wIndex, wLength);
1110
1111 req->complete = printer_setup_complete;
1112
1113 switch (ctrl->bRequestType&USB_TYPE_MASK) {
1114
1115 case USB_TYPE_STANDARD:
1116 switch (ctrl->bRequest) {
1117
1118 case USB_REQ_GET_DESCRIPTOR:
1119 if (ctrl->bRequestType != USB_DIR_IN)
1120 break;
1121 switch (wValue >> 8) {
1122
1123 case USB_DT_DEVICE:
1124 value = min(wLength, (u16) sizeof device_desc);
1125 memcpy(req->buf, &device_desc, value);
1126 break;
1127#ifdef CONFIG_USB_GADGET_DUALSPEED
1128 case USB_DT_DEVICE_QUALIFIER:
1129 if (!gadget->is_dualspeed)
1130 break;
1131 value = min(wLength,
1132 (u16) sizeof dev_qualifier);
1133 memcpy(req->buf, &dev_qualifier, value);
1134 break;
1135
1136 case USB_DT_OTHER_SPEED_CONFIG:
1137 if (!gadget->is_dualspeed)
1138 break;
1139 /* FALLTHROUGH */
1140#endif /* CONFIG_USB_GADGET_DUALSPEED */
1141 case USB_DT_CONFIG:
1142 value = config_buf(gadget->speed, req->buf,
1143 wValue >> 8,
1144 wValue & 0xff,
1145 gadget->is_otg);
1146 if (value >= 0)
1147 value = min(wLength, (u16) value);
1148 break;
1149
1150 case USB_DT_STRING:
1151 value = usb_gadget_get_string(&stringtab,
1152 wValue & 0xff, req->buf);
1153 if (value >= 0)
1154 value = min(wLength, (u16) value);
1155 break;
1156 }
1157 break;
1158
1159 case USB_REQ_SET_CONFIGURATION:
1160 if (ctrl->bRequestType != 0)
1161 break;
1162 if (gadget->a_hnp_support)
1163 DBG(dev, "HNP available\n");
1164 else if (gadget->a_alt_hnp_support)
1165 DBG(dev, "HNP needs a different root port\n");
1166 value = printer_set_config(dev, wValue);
1167 break;
1168 case USB_REQ_GET_CONFIGURATION:
1169 if (ctrl->bRequestType != USB_DIR_IN)
1170 break;
1171 *(u8 *)req->buf = dev->config;
1172 value = min(wLength, (u16) 1);
1173 break;
1174
1175 case USB_REQ_SET_INTERFACE:
1176 if (ctrl->bRequestType != USB_RECIP_INTERFACE ||
1177 !dev->config)
1178 break;
1179
1180 value = set_interface(dev, PRINTER_INTERFACE);
1181 break;
1182 case USB_REQ_GET_INTERFACE:
1183 if (ctrl->bRequestType !=
1184 (USB_DIR_IN|USB_RECIP_INTERFACE)
1185 || !dev->config)
1186 break;
1187
1188 *(u8 *)req->buf = dev->interface;
1189 value = min(wLength, (u16) 1);
1190 break;
1191
1192 default:
1193 goto unknown;
1194 }
1195 break;
1196
1197 case USB_TYPE_CLASS:
1198 switch (ctrl->bRequest) {
1199 case 0: /* Get the IEEE-1284 PNP String */
1200 /* Only one printer interface is supported. */
1201 if ((wIndex>>8) != PRINTER_INTERFACE)
1202 break;
1203
1204 value = (pnp_string[0]<<8)|pnp_string[1];
1205 memcpy(req->buf, pnp_string, value);
1206 DBG(dev, "1284 PNP String: %x %s\n", value,
1207 &pnp_string[2]);
1208 break;
1209
1210 case 1: /* Get Port Status */
1211 /* Only one printer interface is supported. */
1212 if (wIndex != PRINTER_INTERFACE)
1213 break;
1214
1215 *(u8 *)req->buf = dev->printer_status;
1216 value = min(wLength, (u16) 1);
1217 break;
1218
1219 case 2: /* Soft Reset */
1220 /* Only one printer interface is supported. */
1221 if (wIndex != PRINTER_INTERFACE)
1222 break;
1223
1224 printer_soft_reset(dev);
1225
1226 value = 0;
1227 break;
1228
1229 default:
1230 goto unknown;
1231 }
1232 break;
1233
1234 default:
1235unknown:
1236 VDBG(dev,
1237 "unknown ctrl req%02x.%02x v%04x i%04x l%d\n",
1238 ctrl->bRequestType, ctrl->bRequest,
1239 wValue, wIndex, wLength);
1240 break;
1241 }
1242
1243 /* respond with data transfer before status phase? */
1244 if (value >= 0) {
1245 req->length = value;
1246 req->zero = value < wLength
1247 && (value % gadget->ep0->maxpacket) == 0;
1248 value = usb_ep_queue(gadget->ep0, req, GFP_ATOMIC);
1249 if (value < 0) {
1250 DBG(dev, "ep_queue --> %d\n", value);
1251 req->status = 0;
1252 printer_setup_complete(gadget->ep0, req);
1253 }
1254 }
1255
1256 /* host either stalls (value < 0) or reports success */
1257 return value;
1258}
1259
1260static void
1261printer_disconnect(struct usb_gadget *gadget)
1262{
1263 struct printer_dev *dev = get_gadget_data(gadget);
1264 unsigned long flags;
1265
1266 DBG(dev, "%s\n", __FUNCTION__);
1267
1268 spin_lock_irqsave(&dev->lock, flags);
1269
1270 printer_reset_interface(dev);
1271
1272 spin_unlock_irqrestore(&dev->lock, flags);
1273}
1274
1275static void
1276printer_unbind(struct usb_gadget *gadget)
1277{
1278 struct printer_dev *dev = get_gadget_data(gadget);
1279 struct usb_request *req;
1280
1281
1282 DBG(dev, "%s\n", __FUNCTION__);
1283
1284 /* Remove sysfs files */
1285 device_destroy(usb_gadget_class, g_printer_devno);
1286
1287 /* Remove Character Device */
1288 cdev_del(&dev->printer_cdev);
1289
1290 /* we must already have been disconnected ... no i/o may be active */
1291 WARN_ON(!list_empty(&dev->tx_reqs_active));
1292 WARN_ON(!list_empty(&dev->rx_reqs_active));
1293
1294 /* Free all memory for this driver. */
1295 while (!list_empty(&dev->tx_reqs)) {
1296 req = container_of(dev->tx_reqs.next, struct usb_request,
1297 list);
1298 list_del(&req->list);
1299 printer_req_free(dev->in_ep, req);
1300 }
1301
1302 if (dev->current_rx_req != NULL);
1303 printer_req_free(dev->out_ep, dev->current_rx_req);
1304
1305 while (!list_empty(&dev->rx_reqs)) {
1306 req = container_of(dev->rx_reqs.next,
1307 struct usb_request, list);
1308 list_del(&req->list);
1309 printer_req_free(dev->out_ep, req);
1310 }
1311
1312 while (!list_empty(&dev->rx_buffers)) {
1313 req = container_of(dev->rx_buffers.next,
1314 struct usb_request, list);
1315 list_del(&req->list);
1316 printer_req_free(dev->out_ep, req);
1317 }
1318
1319 if (dev->req) {
1320 printer_req_free(gadget->ep0, dev->req);
1321 dev->req = NULL;
1322 }
1323
1324 set_gadget_data(gadget, NULL);
1325}
1326
1327static int __init
1328printer_bind(struct usb_gadget *gadget)
1329{
1330 struct printer_dev *dev;
1331 struct usb_ep *in_ep, *out_ep;
1332 int status = -ENOMEM;
1333 int gcnum;
1334 size_t len;
1335 u32 i;
1336 struct usb_request *req;
1337
1338 dev = &usb_printer_gadget;
1339
1340
1341 /* Setup the sysfs files for the printer gadget. */
1342 dev->pdev = device_create(usb_gadget_class, NULL, g_printer_devno,
1343 "g_printer");
1344 if (IS_ERR(dev->pdev)) {
1345 ERROR(dev, "Failed to create device: g_printer\n");
1346 goto fail;
1347 }
1348
1349 /*
1350 * Register a character device as an interface to a user mode
1351 * program that handles the printer specific functionality.
1352 */
1353 cdev_init(&dev->printer_cdev, &printer_io_operations);
1354 dev->printer_cdev.owner = THIS_MODULE;
1355 status = cdev_add(&dev->printer_cdev, g_printer_devno, 1);
1356 if (status) {
1357 ERROR(dev, "Failed to open char device\n");
1358 goto fail;
1359 }
1360
1361 if (gadget_is_sa1100(gadget)) {
1362 /* hardware can't write zero length packets. */
1363 ERROR(dev, "SA1100 controller is unsupport by this driver\n");
1364 goto fail;
1365 }
1366
1367 gcnum = usb_gadget_controller_number(gadget);
1368 if (gcnum >= 0) {
1369 device_desc.bcdDevice = cpu_to_le16(0x0200 + gcnum);
1370 } else {
1371 dev_warn(&gadget->dev, "controller '%s' not recognized\n",
1372 gadget->name);
1373 /* unrecognized, but safe unless bulk is REALLY quirky */
1374 device_desc.bcdDevice =
1375 __constant_cpu_to_le16(0xFFFF);
1376 }
1377 snprintf(manufacturer, sizeof(manufacturer), "%s %s with %s",
1378 init_utsname()->sysname, init_utsname()->release,
1379 gadget->name);
1380
1381 device_desc.idVendor =
1382 __constant_cpu_to_le16(PRINTER_VENDOR_NUM);
1383 device_desc.idProduct =
1384 __constant_cpu_to_le16(PRINTER_PRODUCT_NUM);
1385
1386 /* support optional vendor/distro customization */
1387 if (idVendor) {
1388 if (!idProduct) {
1389 dev_err(&gadget->dev, "idVendor needs idProduct!\n");
1390 return -ENODEV;
1391 }
1392 device_desc.idVendor = cpu_to_le16(idVendor);
1393 device_desc.idProduct = cpu_to_le16(idProduct);
1394 if (bcdDevice)
1395 device_desc.bcdDevice = cpu_to_le16(bcdDevice);
1396 }
1397
1398 if (iManufacturer)
1399 strlcpy(manufacturer, iManufacturer, sizeof manufacturer);
1400
1401 if (iProduct)
1402 strlcpy(product_desc, iProduct, sizeof product_desc);
1403
1404 if (iSerialNum)
1405 strlcpy(serial_num, iSerialNum, sizeof serial_num);
1406
1407 if (iPNPstring)
1408 strlcpy(&pnp_string[2], iPNPstring, (sizeof pnp_string)-2);
1409
1410 len = strlen(pnp_string);
1411 pnp_string[0] = (len >> 8) & 0xFF;
1412 pnp_string[1] = len & 0xFF;
1413
1414 /* all we really need is bulk IN/OUT */
1415 usb_ep_autoconfig_reset(gadget);
1416 in_ep = usb_ep_autoconfig(gadget, &fs_ep_in_desc);
1417 if (!in_ep) {
1418autoconf_fail:
1419 dev_err(&gadget->dev, "can't autoconfigure on %s\n",
1420 gadget->name);
1421 return -ENODEV;
1422 }
1423 in_ep->driver_data = in_ep; /* claim */
1424
1425 out_ep = usb_ep_autoconfig(gadget, &fs_ep_out_desc);
1426 if (!out_ep)
1427 goto autoconf_fail;
1428 out_ep->driver_data = out_ep; /* claim */
1429
1430#ifdef CONFIG_USB_GADGET_DUALSPEED
1431 /* assumes ep0 uses the same value for both speeds ... */
1432 dev_qualifier.bMaxPacketSize0 = device_desc.bMaxPacketSize0;
1433
1434 /* and that all endpoints are dual-speed */
1435 hs_ep_in_desc.bEndpointAddress = fs_ep_in_desc.bEndpointAddress;
1436 hs_ep_out_desc.bEndpointAddress = fs_ep_out_desc.bEndpointAddress;
1437#endif /* DUALSPEED */
1438
1439 device_desc.bMaxPacketSize0 = gadget->ep0->maxpacket;
1440 usb_gadget_set_selfpowered(gadget);
1441
1442 if (gadget->is_otg) {
1443 otg_desc.bmAttributes |= USB_OTG_HNP,
1444 config_desc.bmAttributes |= USB_CONFIG_ATT_WAKEUP;
1445 config_desc.bMaxPower = 4;
1446 }
1447
1448 spin_lock_init(&dev->lock);
1449 spin_lock_init(&dev->lock_printer_io);
1450 INIT_LIST_HEAD(&dev->tx_reqs);
1451 INIT_LIST_HEAD(&dev->tx_reqs_active);
1452 INIT_LIST_HEAD(&dev->rx_reqs);
1453 INIT_LIST_HEAD(&dev->rx_reqs_active);
1454 INIT_LIST_HEAD(&dev->rx_buffers);
1455 init_waitqueue_head(&dev->rx_wait);
1456 init_waitqueue_head(&dev->tx_wait);
1457 init_waitqueue_head(&dev->tx_flush_wait);
1458
1459 dev->config = 0;
1460 dev->interface = -1;
1461 dev->printer_cdev_open = 0;
1462 dev->printer_status = PRINTER_NOT_ERROR;
1463 dev->current_rx_req = NULL;
1464 dev->current_rx_bytes = 0;
1465 dev->current_rx_buf = NULL;
1466
1467 dev->in_ep = in_ep;
1468 dev->out_ep = out_ep;
1469
1470 /* preallocate control message data and buffer */
1471 dev->req = printer_req_alloc(gadget->ep0, USB_DESC_BUFSIZE,
1472 GFP_KERNEL);
1473 if (!dev->req) {
1474 status = -ENOMEM;
1475 goto fail;
1476 }
1477
1478 for (i = 0; i < QLEN; i++) {
1479 req = printer_req_alloc(dev->in_ep, USB_BUFSIZE, GFP_KERNEL);
1480 if (!req) {
1481 while (!list_empty(&dev->tx_reqs)) {
1482 req = container_of(dev->tx_reqs.next,
1483 struct usb_request, list);
1484 list_del(&req->list);
1485 printer_req_free(dev->in_ep, req);
1486 }
1487 return -ENOMEM;
1488 }
1489 list_add(&req->list, &dev->tx_reqs);
1490 }
1491
1492 for (i = 0; i < QLEN; i++) {
1493 req = printer_req_alloc(dev->out_ep, USB_BUFSIZE, GFP_KERNEL);
1494 if (!req) {
1495 while (!list_empty(&dev->rx_reqs)) {
1496 req = container_of(dev->rx_reqs.next,
1497 struct usb_request, list);
1498 list_del(&req->list);
1499 printer_req_free(dev->out_ep, req);
1500 }
1501 return -ENOMEM;
1502 }
1503 list_add(&req->list, &dev->rx_reqs);
1504 }
1505
1506 dev->req->complete = printer_setup_complete;
1507
1508 /* finish hookup to lower layer ... */
1509 dev->gadget = gadget;
1510 set_gadget_data(gadget, dev);
1511 gadget->ep0->driver_data = dev;
1512
1513 INFO(dev, "%s, version: " DRIVER_VERSION "\n", driver_desc);
1514 INFO(dev, "using %s, OUT %s IN %s\n", gadget->name, out_ep->name,
1515 in_ep->name);
1516
1517 return 0;
1518
1519fail:
1520 printer_unbind(gadget);
1521 return status;
1522}
1523
1524/*-------------------------------------------------------------------------*/
1525
1526static struct usb_gadget_driver printer_driver = {
1527 .speed = DEVSPEED,
1528
1529 .function = (char *) driver_desc,
1530 .bind = printer_bind,
1531 .unbind = printer_unbind,
1532
1533 .setup = printer_setup,
1534 .disconnect = printer_disconnect,
1535
1536 .driver = {
1537 .name = (char *) shortname,
1538 .owner = THIS_MODULE,
1539 },
1540};
1541
1542MODULE_DESCRIPTION(DRIVER_DESC);
1543MODULE_AUTHOR("Craig Nadler");
1544MODULE_LICENSE("GPL");
1545
1546static int __init
1547init(void)
1548{
1549 int status;
1550
1551 usb_gadget_class = class_create(THIS_MODULE, "usb_printer_gadget");
1552 if (IS_ERR(usb_gadget_class)) {
1553 status = PTR_ERR(usb_gadget_class);
1554 ERROR(dev, "unable to create usb_gadget class %d\n", status);
1555 return status;
1556 }
1557
1558 status = alloc_chrdev_region(&g_printer_devno, 0, 1,
1559 "USB printer gadget");
1560 if (status) {
1561 ERROR(dev, "alloc_chrdev_region %d\n", status);
1562 class_destroy(usb_gadget_class);
1563 return status;
1564 }
1565
1566 status = usb_gadget_register_driver(&printer_driver);
1567 if (status) {
1568 class_destroy(usb_gadget_class);
1569 unregister_chrdev_region(g_printer_devno, 1);
1570 DBG(dev, "usb_gadget_register_driver %x\n", status);
1571 }
1572
1573 return status;
1574}
1575module_init(init);
1576
1577static void __exit
1578cleanup(void)
1579{
1580 int status;
1581
1582 spin_lock(&usb_printer_gadget.lock_printer_io);
1583 class_destroy(usb_gadget_class);
1584 unregister_chrdev_region(g_printer_devno, 2);
1585
1586 status = usb_gadget_unregister_driver(&printer_driver);
1587 if (status)
1588 ERROR(dev, "usb_gadget_unregister_driver %x\n", status);
1589
1590 spin_unlock(&usb_printer_gadget.lock_printer_io);
1591}
1592module_exit(cleanup);
diff --git a/drivers/usb/gadget/pxa2xx_udc.c b/drivers/usb/gadget/pxa2xx_udc.c
index 3173b39f0bfd..4402d6f042d9 100644
--- a/drivers/usb/gadget/pxa2xx_udc.c
+++ b/drivers/usb/gadget/pxa2xx_udc.c
@@ -24,7 +24,7 @@
24 * 24 *
25 */ 25 */
26 26
27// #define VERBOSE DBG_VERBOSE 27/* #define VERBOSE_DEBUG */
28 28
29#include <linux/device.h> 29#include <linux/device.h>
30#include <linux/module.h> 30#include <linux/module.h>
@@ -38,13 +38,14 @@
38#include <linux/timer.h> 38#include <linux/timer.h>
39#include <linux/list.h> 39#include <linux/list.h>
40#include <linux/interrupt.h> 40#include <linux/interrupt.h>
41#include <linux/proc_fs.h>
42#include <linux/mm.h> 41#include <linux/mm.h>
43#include <linux/platform_device.h> 42#include <linux/platform_device.h>
44#include <linux/dma-mapping.h> 43#include <linux/dma-mapping.h>
45#include <linux/irq.h> 44#include <linux/irq.h>
46#include <linux/clk.h> 45#include <linux/clk.h>
47#include <linux/err.h> 46#include <linux/err.h>
47#include <linux/seq_file.h>
48#include <linux/debugfs.h>
48 49
49#include <asm/byteorder.h> 50#include <asm/byteorder.h>
50#include <asm/dma.h> 51#include <asm/dma.h>
@@ -127,8 +128,10 @@ static int is_vbus_present(void)
127{ 128{
128 struct pxa2xx_udc_mach_info *mach = the_controller->mach; 129 struct pxa2xx_udc_mach_info *mach = the_controller->mach;
129 130
130 if (mach->gpio_vbus) 131 if (mach->gpio_vbus) {
131 return gpio_get_value(mach->gpio_vbus); 132 int value = gpio_get_value(mach->gpio_vbus);
133 return mach->gpio_vbus_inverted ? !value : value;
134 }
132 if (mach->udc_is_connected) 135 if (mach->udc_is_connected)
133 return mach->udc_is_connected(); 136 return mach->udc_is_connected();
134 return 1; 137 return 1;
@@ -677,7 +680,7 @@ pxa2xx_ep_queue(struct usb_ep *_ep, struct usb_request *_req, gfp_t gfp_flags)
677 680
678 /* kickstart this i/o queue? */ 681 /* kickstart this i/o queue? */
679 if (list_empty(&ep->queue) && !ep->stopped) { 682 if (list_empty(&ep->queue) && !ep->stopped) {
680 if (ep->desc == 0 /* ep0 */) { 683 if (ep->desc == NULL/* ep0 */) {
681 unsigned length = _req->length; 684 unsigned length = _req->length;
682 685
683 switch (dev->ep0state) { 686 switch (dev->ep0state) {
@@ -731,7 +734,7 @@ pxa2xx_ep_queue(struct usb_ep *_ep, struct usb_request *_req, gfp_t gfp_flags)
731 } 734 }
732 735
733 /* pio or dma irq handler advances the queue. */ 736 /* pio or dma irq handler advances the queue. */
734 if (likely (req != 0)) 737 if (likely(req != NULL))
735 list_add_tail(&req->queue, &ep->queue); 738 list_add_tail(&req->queue, &ep->queue);
736 local_irq_restore(flags); 739 local_irq_restore(flags);
737 740
@@ -991,45 +994,32 @@ static const struct usb_gadget_ops pxa2xx_udc_ops = {
991 994
992/*-------------------------------------------------------------------------*/ 995/*-------------------------------------------------------------------------*/
993 996
994#ifdef CONFIG_USB_GADGET_DEBUG_FILES 997#ifdef CONFIG_USB_GADGET_DEBUG_FS
995
996static const char proc_node_name [] = "driver/udc";
997 998
998static int 999static int
999udc_proc_read(char *page, char **start, off_t off, int count, 1000udc_seq_show(struct seq_file *m, void *d)
1000 int *eof, void *_dev)
1001{ 1001{
1002 char *buf = page; 1002 struct pxa2xx_udc *dev = m->private;
1003 struct pxa2xx_udc *dev = _dev;
1004 char *next = buf;
1005 unsigned size = count;
1006 unsigned long flags; 1003 unsigned long flags;
1007 int i, t; 1004 int i;
1008 u32 tmp; 1005 u32 tmp;
1009 1006
1010 if (off != 0)
1011 return 0;
1012
1013 local_irq_save(flags); 1007 local_irq_save(flags);
1014 1008
1015 /* basic device status */ 1009 /* basic device status */
1016 t = scnprintf(next, size, DRIVER_DESC "\n" 1010 seq_printf(m, DRIVER_DESC "\n"
1017 "%s version: %s\nGadget driver: %s\nHost %s\n\n", 1011 "%s version: %s\nGadget driver: %s\nHost %s\n\n",
1018 driver_name, DRIVER_VERSION SIZE_STR "(pio)", 1012 driver_name, DRIVER_VERSION SIZE_STR "(pio)",
1019 dev->driver ? dev->driver->driver.name : "(none)", 1013 dev->driver ? dev->driver->driver.name : "(none)",
1020 is_vbus_present() ? "full speed" : "disconnected"); 1014 is_vbus_present() ? "full speed" : "disconnected");
1021 size -= t;
1022 next += t;
1023 1015
1024 /* registers for device and ep0 */ 1016 /* registers for device and ep0 */
1025 t = scnprintf(next, size, 1017 seq_printf(m,
1026 "uicr %02X.%02X, usir %02X.%02x, ufnr %02X.%02X\n", 1018 "uicr %02X.%02X, usir %02X.%02x, ufnr %02X.%02X\n",
1027 UICR1, UICR0, USIR1, USIR0, UFNRH, UFNRL); 1019 UICR1, UICR0, USIR1, USIR0, UFNRH, UFNRL);
1028 size -= t;
1029 next += t;
1030 1020
1031 tmp = UDCCR; 1021 tmp = UDCCR;
1032 t = scnprintf(next, size, 1022 seq_printf(m,
1033 "udccr %02X =%s%s%s%s%s%s%s%s\n", tmp, 1023 "udccr %02X =%s%s%s%s%s%s%s%s\n", tmp,
1034 (tmp & UDCCR_REM) ? " rem" : "", 1024 (tmp & UDCCR_REM) ? " rem" : "",
1035 (tmp & UDCCR_RSTIR) ? " rstir" : "", 1025 (tmp & UDCCR_RSTIR) ? " rstir" : "",
@@ -1039,11 +1029,9 @@ udc_proc_read(char *page, char **start, off_t off, int count,
1039 (tmp & UDCCR_RSM) ? " rsm" : "", 1029 (tmp & UDCCR_RSM) ? " rsm" : "",
1040 (tmp & UDCCR_UDA) ? " uda" : "", 1030 (tmp & UDCCR_UDA) ? " uda" : "",
1041 (tmp & UDCCR_UDE) ? " ude" : ""); 1031 (tmp & UDCCR_UDE) ? " ude" : "");
1042 size -= t;
1043 next += t;
1044 1032
1045 tmp = UDCCS0; 1033 tmp = UDCCS0;
1046 t = scnprintf(next, size, 1034 seq_printf(m,
1047 "udccs0 %02X =%s%s%s%s%s%s%s%s\n", tmp, 1035 "udccs0 %02X =%s%s%s%s%s%s%s%s\n", tmp,
1048 (tmp & UDCCS0_SA) ? " sa" : "", 1036 (tmp & UDCCS0_SA) ? " sa" : "",
1049 (tmp & UDCCS0_RNE) ? " rne" : "", 1037 (tmp & UDCCS0_RNE) ? " rne" : "",
@@ -1053,28 +1041,22 @@ udc_proc_read(char *page, char **start, off_t off, int count,
1053 (tmp & UDCCS0_FTF) ? " ftf" : "", 1041 (tmp & UDCCS0_FTF) ? " ftf" : "",
1054 (tmp & UDCCS0_IPR) ? " ipr" : "", 1042 (tmp & UDCCS0_IPR) ? " ipr" : "",
1055 (tmp & UDCCS0_OPR) ? " opr" : ""); 1043 (tmp & UDCCS0_OPR) ? " opr" : "");
1056 size -= t;
1057 next += t;
1058 1044
1059 if (dev->has_cfr) { 1045 if (dev->has_cfr) {
1060 tmp = UDCCFR; 1046 tmp = UDCCFR;
1061 t = scnprintf(next, size, 1047 seq_printf(m,
1062 "udccfr %02X =%s%s\n", tmp, 1048 "udccfr %02X =%s%s\n", tmp,
1063 (tmp & UDCCFR_AREN) ? " aren" : "", 1049 (tmp & UDCCFR_AREN) ? " aren" : "",
1064 (tmp & UDCCFR_ACM) ? " acm" : ""); 1050 (tmp & UDCCFR_ACM) ? " acm" : "");
1065 size -= t;
1066 next += t;
1067 } 1051 }
1068 1052
1069 if (!is_vbus_present() || !dev->driver) 1053 if (!is_vbus_present() || !dev->driver)
1070 goto done; 1054 goto done;
1071 1055
1072 t = scnprintf(next, size, "ep0 IN %lu/%lu, OUT %lu/%lu\nirqs %lu\n\n", 1056 seq_printf(m, "ep0 IN %lu/%lu, OUT %lu/%lu\nirqs %lu\n\n",
1073 dev->stats.write.bytes, dev->stats.write.ops, 1057 dev->stats.write.bytes, dev->stats.write.ops,
1074 dev->stats.read.bytes, dev->stats.read.ops, 1058 dev->stats.read.bytes, dev->stats.read.ops,
1075 dev->stats.irqs); 1059 dev->stats.irqs);
1076 size -= t;
1077 next += t;
1078 1060
1079 /* dump endpoint queues */ 1061 /* dump endpoint queues */
1080 for (i = 0; i < PXA_UDC_NUM_ENDPOINTS; i++) { 1062 for (i = 0; i < PXA_UDC_NUM_ENDPOINTS; i++) {
@@ -1082,61 +1064,68 @@ udc_proc_read(char *page, char **start, off_t off, int count,
1082 struct pxa2xx_request *req; 1064 struct pxa2xx_request *req;
1083 1065
1084 if (i != 0) { 1066 if (i != 0) {
1085 const struct usb_endpoint_descriptor *d; 1067 const struct usb_endpoint_descriptor *desc;
1086 1068
1087 d = ep->desc; 1069 desc = ep->desc;
1088 if (!d) 1070 if (!desc)
1089 continue; 1071 continue;
1090 tmp = *dev->ep [i].reg_udccs; 1072 tmp = *dev->ep [i].reg_udccs;
1091 t = scnprintf(next, size, 1073 seq_printf(m,
1092 "%s max %d %s udccs %02x irqs %lu\n", 1074 "%s max %d %s udccs %02x irqs %lu\n",
1093 ep->ep.name, le16_to_cpu (d->wMaxPacketSize), 1075 ep->ep.name, le16_to_cpu(desc->wMaxPacketSize),
1094 "pio", tmp, ep->pio_irqs); 1076 "pio", tmp, ep->pio_irqs);
1095 /* TODO translate all five groups of udccs bits! */ 1077 /* TODO translate all five groups of udccs bits! */
1096 1078
1097 } else /* ep0 should only have one transfer queued */ 1079 } else /* ep0 should only have one transfer queued */
1098 t = scnprintf(next, size, "ep0 max 16 pio irqs %lu\n", 1080 seq_printf(m, "ep0 max 16 pio irqs %lu\n",
1099 ep->pio_irqs); 1081 ep->pio_irqs);
1100 if (t <= 0 || t > size)
1101 goto done;
1102 size -= t;
1103 next += t;
1104 1082
1105 if (list_empty(&ep->queue)) { 1083 if (list_empty(&ep->queue)) {
1106 t = scnprintf(next, size, "\t(nothing queued)\n"); 1084 seq_printf(m, "\t(nothing queued)\n");
1107 if (t <= 0 || t > size)
1108 goto done;
1109 size -= t;
1110 next += t;
1111 continue; 1085 continue;
1112 } 1086 }
1113 list_for_each_entry(req, &ep->queue, queue) { 1087 list_for_each_entry(req, &ep->queue, queue) {
1114 t = scnprintf(next, size, 1088 seq_printf(m,
1115 "\treq %p len %d/%d buf %p\n", 1089 "\treq %p len %d/%d buf %p\n",
1116 &req->req, req->req.actual, 1090 &req->req, req->req.actual,
1117 req->req.length, req->req.buf); 1091 req->req.length, req->req.buf);
1118 if (t <= 0 || t > size)
1119 goto done;
1120 size -= t;
1121 next += t;
1122 } 1092 }
1123 } 1093 }
1124 1094
1125done: 1095done:
1126 local_irq_restore(flags); 1096 local_irq_restore(flags);
1127 *eof = 1; 1097 return 0;
1128 return count - size;
1129} 1098}
1130 1099
1131#define create_proc_files() \ 1100static int
1132 create_proc_read_entry(proc_node_name, 0, NULL, udc_proc_read, dev) 1101udc_debugfs_open(struct inode *inode, struct file *file)
1133#define remove_proc_files() \ 1102{
1134 remove_proc_entry(proc_node_name, NULL) 1103 return single_open(file, udc_seq_show, inode->i_private);
1104}
1105
1106static const struct file_operations debug_fops = {
1107 .open = udc_debugfs_open,
1108 .read = seq_read,
1109 .llseek = seq_lseek,
1110 .release = single_release,
1111 .owner = THIS_MODULE,
1112};
1113
1114#define create_debug_files(dev) \
1115 do { \
1116 dev->debugfs_udc = debugfs_create_file(dev->gadget.name, \
1117 S_IRUGO, NULL, dev, &debug_fops); \
1118 } while (0)
1119#define remove_debug_files(dev) \
1120 do { \
1121 if (dev->debugfs_udc) \
1122 debugfs_remove(dev->debugfs_udc); \
1123 } while (0)
1135 1124
1136#else /* !CONFIG_USB_GADGET_DEBUG_FILES */ 1125#else /* !CONFIG_USB_GADGET_DEBUG_FILES */
1137 1126
1138#define create_proc_files() do {} while (0) 1127#define create_debug_files(dev) do {} while (0)
1139#define remove_proc_files() do {} while (0) 1128#define remove_debug_files(dev) do {} while (0)
1140 1129
1141#endif /* CONFIG_USB_GADGET_DEBUG_FILES */ 1130#endif /* CONFIG_USB_GADGET_DEBUG_FILES */
1142 1131
@@ -1345,6 +1334,7 @@ int usb_gadget_unregister_driver(struct usb_gadget_driver *driver)
1345 local_irq_enable(); 1334 local_irq_enable();
1346 1335
1347 driver->unbind(&dev->gadget); 1336 driver->unbind(&dev->gadget);
1337 dev->gadget.dev.driver = NULL;
1348 dev->driver = NULL; 1338 dev->driver = NULL;
1349 1339
1350 device_del (&dev->gadget.dev); 1340 device_del (&dev->gadget.dev);
@@ -1397,6 +1387,9 @@ static irqreturn_t udc_vbus_irq(int irq, void *_dev)
1397 struct pxa2xx_udc *dev = _dev; 1387 struct pxa2xx_udc *dev = _dev;
1398 int vbus = gpio_get_value(dev->mach->gpio_vbus); 1388 int vbus = gpio_get_value(dev->mach->gpio_vbus);
1399 1389
1390 if (dev->mach->gpio_vbus_inverted)
1391 vbus = !vbus;
1392
1400 pxa2xx_udc_vbus_session(&dev->gadget, vbus); 1393 pxa2xx_udc_vbus_session(&dev->gadget, vbus);
1401 return IRQ_HANDLED; 1394 return IRQ_HANDLED;
1402} 1395}
@@ -2099,7 +2092,7 @@ static int __init pxa2xx_udc_probe(struct platform_device *pdev)
2099 /* insist on Intel/ARM/XScale */ 2092 /* insist on Intel/ARM/XScale */
2100 asm("mrc%? p15, 0, %0, c0, c0" : "=r" (chiprev)); 2093 asm("mrc%? p15, 0, %0, c0, c0" : "=r" (chiprev));
2101 if ((chiprev & CP15R0_VENDOR_MASK) != CP15R0_XSCALE_VALUE) { 2094 if ((chiprev & CP15R0_VENDOR_MASK) != CP15R0_XSCALE_VALUE) {
2102 printk(KERN_ERR "%s: not XScale!\n", driver_name); 2095 pr_err("%s: not XScale!\n", driver_name);
2103 return -ENODEV; 2096 return -ENODEV;
2104 } 2097 }
2105 2098
@@ -2128,7 +2121,7 @@ static int __init pxa2xx_udc_probe(struct platform_device *pdev)
2128 break; 2121 break;
2129#endif 2122#endif
2130 default: 2123 default:
2131 printk(KERN_ERR "%s: unrecognized processor: %08x\n", 2124 pr_err("%s: unrecognized processor: %08x\n",
2132 driver_name, chiprev); 2125 driver_name, chiprev);
2133 /* iop3xx, ixp4xx, ... */ 2126 /* iop3xx, ixp4xx, ... */
2134 return -ENODEV; 2127 return -ENODEV;
@@ -2199,7 +2192,7 @@ static int __init pxa2xx_udc_probe(struct platform_device *pdev)
2199 retval = request_irq(irq, pxa2xx_udc_irq, 2192 retval = request_irq(irq, pxa2xx_udc_irq,
2200 IRQF_DISABLED, driver_name, dev); 2193 IRQF_DISABLED, driver_name, dev);
2201 if (retval != 0) { 2194 if (retval != 0) {
2202 printk(KERN_ERR "%s: can't get irq %d, err %d\n", 2195 pr_err("%s: can't get irq %d, err %d\n",
2203 driver_name, irq, retval); 2196 driver_name, irq, retval);
2204 goto err_irq1; 2197 goto err_irq1;
2205 } 2198 }
@@ -2212,7 +2205,7 @@ static int __init pxa2xx_udc_probe(struct platform_device *pdev)
2212 IRQF_DISABLED | IRQF_SAMPLE_RANDOM, 2205 IRQF_DISABLED | IRQF_SAMPLE_RANDOM,
2213 driver_name, dev); 2206 driver_name, dev);
2214 if (retval != 0) { 2207 if (retval != 0) {
2215 printk(KERN_ERR "%s: can't get irq %i, err %d\n", 2208 pr_err("%s: can't get irq %i, err %d\n",
2216 driver_name, LUBBOCK_USB_DISC_IRQ, retval); 2209 driver_name, LUBBOCK_USB_DISC_IRQ, retval);
2217lubbock_fail0: 2210lubbock_fail0:
2218 goto err_irq_lub; 2211 goto err_irq_lub;
@@ -2222,7 +2215,7 @@ lubbock_fail0:
2222 IRQF_DISABLED | IRQF_SAMPLE_RANDOM, 2215 IRQF_DISABLED | IRQF_SAMPLE_RANDOM,
2223 driver_name, dev); 2216 driver_name, dev);
2224 if (retval != 0) { 2217 if (retval != 0) {
2225 printk(KERN_ERR "%s: can't get irq %i, err %d\n", 2218 pr_err("%s: can't get irq %i, err %d\n",
2226 driver_name, LUBBOCK_USB_IRQ, retval); 2219 driver_name, LUBBOCK_USB_IRQ, retval);
2227 free_irq(LUBBOCK_USB_DISC_IRQ, dev); 2220 free_irq(LUBBOCK_USB_DISC_IRQ, dev);
2228 goto lubbock_fail0; 2221 goto lubbock_fail0;
@@ -2235,12 +2228,12 @@ lubbock_fail0:
2235 IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING, 2228 IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING,
2236 driver_name, dev); 2229 driver_name, dev);
2237 if (retval != 0) { 2230 if (retval != 0) {
2238 printk(KERN_ERR "%s: can't get irq %i, err %d\n", 2231 pr_err("%s: can't get irq %i, err %d\n",
2239 driver_name, vbus_irq, retval); 2232 driver_name, vbus_irq, retval);
2240 goto err_vbus_irq; 2233 goto err_vbus_irq;
2241 } 2234 }
2242 } 2235 }
2243 create_proc_files(); 2236 create_debug_files(dev);
2244 2237
2245 return 0; 2238 return 0;
2246 2239
@@ -2277,7 +2270,7 @@ static int __exit pxa2xx_udc_remove(struct platform_device *pdev)
2277 return -EBUSY; 2270 return -EBUSY;
2278 2271
2279 udc_disable(dev); 2272 udc_disable(dev);
2280 remove_proc_files(); 2273 remove_debug_files(dev);
2281 2274
2282 if (dev->got_irq) { 2275 if (dev->got_irq) {
2283 free_irq(platform_get_irq(pdev, 0), dev); 2276 free_irq(platform_get_irq(pdev, 0), dev);
@@ -2361,7 +2354,7 @@ static struct platform_driver udc_driver = {
2361 2354
2362static int __init udc_init(void) 2355static int __init udc_init(void)
2363{ 2356{
2364 printk(KERN_INFO "%s: version %s\n", driver_name, DRIVER_VERSION); 2357 pr_info("%s: version %s\n", driver_name, DRIVER_VERSION);
2365 return platform_driver_probe(&udc_driver, pxa2xx_udc_probe); 2358 return platform_driver_probe(&udc_driver, pxa2xx_udc_probe);
2366} 2359}
2367module_init(udc_init); 2360module_init(udc_init);
diff --git a/drivers/usb/gadget/pxa2xx_udc.h b/drivers/usb/gadget/pxa2xx_udc.h
index 1db46d705777..b67e3ff5e4eb 100644
--- a/drivers/usb/gadget/pxa2xx_udc.h
+++ b/drivers/usb/gadget/pxa2xx_udc.h
@@ -129,6 +129,10 @@ struct pxa2xx_udc {
129 struct pxa2xx_udc_mach_info *mach; 129 struct pxa2xx_udc_mach_info *mach;
130 u64 dma_mask; 130 u64 dma_mask;
131 struct pxa2xx_ep ep [PXA_UDC_NUM_ENDPOINTS]; 131 struct pxa2xx_ep ep [PXA_UDC_NUM_ENDPOINTS];
132
133#ifdef CONFIG_USB_GADGET_DEBUG_FS
134 struct dentry *debugfs_udc;
135#endif
132}; 136};
133 137
134/*-------------------------------------------------------------------------*/ 138/*-------------------------------------------------------------------------*/
@@ -151,17 +155,19 @@ static struct pxa2xx_udc *the_controller;
151#define DBG_NOISY 3 /* ... even more: request level */ 155#define DBG_NOISY 3 /* ... even more: request level */
152#define DBG_VERY_NOISY 4 /* ... even more: packet level */ 156#define DBG_VERY_NOISY 4 /* ... even more: packet level */
153 157
158#define DMSG(stuff...) pr_debug("udc: " stuff)
159
154#ifdef DEBUG 160#ifdef DEBUG
155 161
162static int is_vbus_present(void);
163
156static const char *state_name[] = { 164static const char *state_name[] = {
157 "EP0_IDLE", 165 "EP0_IDLE",
158 "EP0_IN_DATA_PHASE", "EP0_OUT_DATA_PHASE", 166 "EP0_IN_DATA_PHASE", "EP0_OUT_DATA_PHASE",
159 "EP0_END_XFER", "EP0_STALL" 167 "EP0_END_XFER", "EP0_STALL"
160}; 168};
161 169
162#define DMSG(stuff...) printk(KERN_DEBUG "udc: " stuff) 170#ifdef VERBOSE_DEBUG
163
164#ifdef VERBOSE
165# define UDC_DEBUG DBG_VERBOSE 171# define UDC_DEBUG DBG_VERBOSE
166#else 172#else
167# define UDC_DEBUG DBG_NORMAL 173# define UDC_DEBUG DBG_NORMAL
@@ -207,7 +213,7 @@ dump_state(struct pxa2xx_udc *dev)
207 unsigned i; 213 unsigned i;
208 214
209 DMSG("%s %s, uicr %02X.%02X, usir %02X.%02x, ufnr %02X.%02X\n", 215 DMSG("%s %s, uicr %02X.%02X, usir %02X.%02x, ufnr %02X.%02X\n",
210 is_usb_connected() ? "host " : "disconnected", 216 is_vbus_present() ? "host " : "disconnected",
211 state_name[dev->ep0state], 217 state_name[dev->ep0state],
212 UICR1, UICR0, USIR1, USIR0, UFNRH, UFNRL); 218 UICR1, UICR0, USIR1, USIR0, UFNRH, UFNRL);
213 dump_udccr("udccr"); 219 dump_udccr("udccr");
@@ -224,7 +230,7 @@ dump_state(struct pxa2xx_udc *dev)
224 } else 230 } else
225 DMSG("ep0 driver '%s'\n", dev->driver->driver.name); 231 DMSG("ep0 driver '%s'\n", dev->driver->driver.name);
226 232
227 if (!is_usb_connected()) 233 if (!is_vbus_present())
228 return; 234 return;
229 235
230 dump_udccs0 ("udccs0"); 236 dump_udccs0 ("udccs0");
@@ -233,7 +239,7 @@ dump_state(struct pxa2xx_udc *dev)
233 dev->stats.read.bytes, dev->stats.read.ops); 239 dev->stats.read.bytes, dev->stats.read.ops);
234 240
235 for (i = 1; i < PXA_UDC_NUM_ENDPOINTS; i++) { 241 for (i = 1; i < PXA_UDC_NUM_ENDPOINTS; i++) {
236 if (dev->ep [i].desc == 0) 242 if (dev->ep [i].desc == NULL)
237 continue; 243 continue;
238 DMSG ("udccs%d = %02x\n", i, *dev->ep->reg_udccs); 244 DMSG ("udccs%d = %02x\n", i, *dev->ep->reg_udccs);
239 } 245 }
@@ -241,8 +247,6 @@ dump_state(struct pxa2xx_udc *dev)
241 247
242#else 248#else
243 249
244#define DMSG(stuff...) do{}while(0)
245
246#define dump_udccr(x) do{}while(0) 250#define dump_udccr(x) do{}while(0)
247#define dump_udccs0(x) do{}while(0) 251#define dump_udccs0(x) do{}while(0)
248#define dump_state(x) do{}while(0) 252#define dump_state(x) do{}while(0)
@@ -253,8 +257,9 @@ dump_state(struct pxa2xx_udc *dev)
253 257
254#define DBG(lvl, stuff...) do{if ((lvl) <= UDC_DEBUG) DMSG(stuff);}while(0) 258#define DBG(lvl, stuff...) do{if ((lvl) <= UDC_DEBUG) DMSG(stuff);}while(0)
255 259
256#define WARN(stuff...) printk(KERN_WARNING "udc: " stuff) 260#define ERR(stuff...) pr_err("udc: " stuff)
257#define INFO(stuff...) printk(KERN_INFO "udc: " stuff) 261#define WARN(stuff...) pr_warning("udc: " stuff)
262#define INFO(stuff...) pr_info("udc: " stuff)
258 263
259 264
260#endif /* __LINUX_USB_GADGET_PXA2XX_H */ 265#endif /* __LINUX_USB_GADGET_PXA2XX_H */
diff --git a/drivers/usb/gadget/rndis.c b/drivers/usb/gadget/rndis.c
index db1b2bfcee4e..3d036647431f 100644
--- a/drivers/usb/gadget/rndis.c
+++ b/drivers/usb/gadget/rndis.c
@@ -53,21 +53,18 @@
53 */ 53 */
54 54
55#if 0 55#if 0
56#define DBG(str,args...) do { \
57 if (rndis_debug) \
58 printk(KERN_DEBUG str , ## args ); \
59 } while (0)
60static int rndis_debug = 0; 56static int rndis_debug = 0;
61
62module_param (rndis_debug, int, 0); 57module_param (rndis_debug, int, 0);
63MODULE_PARM_DESC (rndis_debug, "enable debugging"); 58MODULE_PARM_DESC (rndis_debug, "enable debugging");
64
65#else 59#else
66
67#define rndis_debug 0 60#define rndis_debug 0
68#define DBG(str,args...) do{}while(0)
69#endif 61#endif
70 62
63#define DBG(str,args...) do { \
64 if (rndis_debug) \
65 pr_debug(str , ## args); \
66 } while (0)
67
71#define RNDIS_MAX_CONFIGS 1 68#define RNDIS_MAX_CONFIGS 1
72 69
73 70
@@ -679,7 +676,7 @@ gen_ndis_query_resp (int configNr, u32 OID, u8 *buf, unsigned buf_len,
679#endif 676#endif
680 677
681 default: 678 default:
682 printk (KERN_WARNING "%s: query unknown OID 0x%08X\n", 679 pr_warning("%s: query unknown OID 0x%08X\n",
683 __FUNCTION__, OID); 680 __FUNCTION__, OID);
684 } 681 }
685 if (retval < 0) 682 if (retval < 0)
@@ -804,7 +801,7 @@ update_linkstate:
804#endif /* RNDIS_PM */ 801#endif /* RNDIS_PM */
805 802
806 default: 803 default:
807 printk (KERN_WARNING "%s: set unknown OID 0x%08X, size %d\n", 804 pr_warning("%s: set unknown OID 0x%08X, size %d\n",
808 __FUNCTION__, OID, buf_len); 805 __FUNCTION__, OID, buf_len);
809 } 806 }
810 807
@@ -1126,8 +1123,7 @@ int rndis_msg_parser (u8 configNr, u8 *buf)
1126 * In one case those messages seemed to relate to the host 1123 * In one case those messages seemed to relate to the host
1127 * suspending itself. 1124 * suspending itself.
1128 */ 1125 */
1129 printk (KERN_WARNING 1126 pr_warning("%s: unknown RNDIS message 0x%08X len %d\n",
1130 "%s: unknown RNDIS message 0x%08X len %d\n",
1131 __FUNCTION__ , MsgType, MsgLength); 1127 __FUNCTION__ , MsgType, MsgLength);
1132 { 1128 {
1133 unsigned i; 1129 unsigned i;
diff --git a/drivers/usb/gadget/s3c2410_udc.c b/drivers/usb/gadget/s3c2410_udc.c
index 4ce050c3d13f..aadc4204d6f9 100644
--- a/drivers/usb/gadget/s3c2410_udc.c
+++ b/drivers/usb/gadget/s3c2410_udc.c
@@ -893,7 +893,7 @@ static void s3c2410_udc_handle_ep(struct s3c2410_ep *ep)
893/* 893/*
894 * s3c2410_udc_irq - interrupt handler 894 * s3c2410_udc_irq - interrupt handler
895 */ 895 */
896static irqreturn_t s3c2410_udc_irq(int irq, void *_dev) 896static irqreturn_t s3c2410_udc_irq(int dummy, void *_dev)
897{ 897{
898 struct s3c2410_udc *dev = _dev; 898 struct s3c2410_udc *dev = _dev;
899 int usb_status; 899 int usb_status;
@@ -1016,7 +1016,7 @@ static irqreturn_t s3c2410_udc_irq(int irq, void *_dev)
1016 } 1016 }
1017 } 1017 }
1018 1018
1019 dprintk(DEBUG_VERBOSE, "irq: %d s3c2410_udc_done.\n", irq); 1019 dprintk(DEBUG_VERBOSE, "irq: %d s3c2410_udc_done.\n", IRQ_USBD);
1020 1020
1021 /* Restore old index */ 1021 /* Restore old index */
1022 udc_write(idx, S3C2410_UDC_INDEX_REG); 1022 udc_write(idx, S3C2410_UDC_INDEX_REG);
diff --git a/drivers/usb/gadget/serial.c b/drivers/usb/gadget/serial.c
index f5738eb8e765..f5c3896b1d95 100644
--- a/drivers/usb/gadget/serial.c
+++ b/drivers/usb/gadget/serial.c
@@ -89,9 +89,9 @@ static int debug = 1;
89#endif 89#endif
90 90
91#define gs_debug(format, arg...) \ 91#define gs_debug(format, arg...) \
92 do { if (debug) printk(KERN_DEBUG format, ## arg); } while(0) 92 do { if (debug) pr_debug(format, ## arg); } while (0)
93#define gs_debug_level(level, format, arg...) \ 93#define gs_debug_level(level, format, arg...) \
94 do { if (debug>=level) printk(KERN_DEBUG format, ## arg); } while(0) 94 do { if (debug >= level) pr_debug(format, ## arg); } while (0)
95 95
96 96
97/* Thanks to NetChip Technologies for donating this product ID. 97/* Thanks to NetChip Technologies for donating this product ID.
@@ -553,7 +553,8 @@ static int __init gs_module_init(void)
553 553
554 retval = usb_gadget_register_driver(&gs_gadget_driver); 554 retval = usb_gadget_register_driver(&gs_gadget_driver);
555 if (retval) { 555 if (retval) {
556 printk(KERN_ERR "gs_module_init: cannot register gadget driver, ret=%d\n", retval); 556 pr_err("gs_module_init: cannot register gadget driver, "
557 "ret=%d\n", retval);
557 return retval; 558 return retval;
558 } 559 }
559 560
@@ -579,11 +580,13 @@ static int __init gs_module_init(void)
579 if (retval) { 580 if (retval) {
580 usb_gadget_unregister_driver(&gs_gadget_driver); 581 usb_gadget_unregister_driver(&gs_gadget_driver);
581 put_tty_driver(gs_tty_driver); 582 put_tty_driver(gs_tty_driver);
582 printk(KERN_ERR "gs_module_init: cannot register tty driver, ret=%d\n", retval); 583 pr_err("gs_module_init: cannot register tty driver, "
584 "ret=%d\n", retval);
583 return retval; 585 return retval;
584 } 586 }
585 587
586 printk(KERN_INFO "gs_module_init: %s %s loaded\n", GS_LONG_NAME, GS_VERSION_STR); 588 pr_info("gs_module_init: %s %s loaded\n",
589 GS_LONG_NAME, GS_VERSION_STR);
587 return 0; 590 return 0;
588} 591}
589 592
@@ -598,7 +601,8 @@ static void __exit gs_module_exit(void)
598 put_tty_driver(gs_tty_driver); 601 put_tty_driver(gs_tty_driver);
599 usb_gadget_unregister_driver(&gs_gadget_driver); 602 usb_gadget_unregister_driver(&gs_gadget_driver);
600 603
601 printk(KERN_INFO "gs_module_exit: %s %s unloaded\n", GS_LONG_NAME, GS_VERSION_STR); 604 pr_info("gs_module_exit: %s %s unloaded\n",
605 GS_LONG_NAME, GS_VERSION_STR);
602} 606}
603 607
604/* TTY Driver */ 608/* TTY Driver */
@@ -621,7 +625,7 @@ static int gs_open(struct tty_struct *tty, struct file *file)
621 gs_debug("gs_open: (%d,%p,%p)\n", port_num, tty, file); 625 gs_debug("gs_open: (%d,%p,%p)\n", port_num, tty, file);
622 626
623 if (port_num < 0 || port_num >= GS_NUM_PORTS) { 627 if (port_num < 0 || port_num >= GS_NUM_PORTS) {
624 printk(KERN_ERR "gs_open: (%d,%p,%p) invalid port number\n", 628 pr_err("gs_open: (%d,%p,%p) invalid port number\n",
625 port_num, tty, file); 629 port_num, tty, file);
626 return -ENODEV; 630 return -ENODEV;
627 } 631 }
@@ -629,15 +633,14 @@ static int gs_open(struct tty_struct *tty, struct file *file)
629 dev = gs_device; 633 dev = gs_device;
630 634
631 if (dev == NULL) { 635 if (dev == NULL) {
632 printk(KERN_ERR "gs_open: (%d,%p,%p) NULL device pointer\n", 636 pr_err("gs_open: (%d,%p,%p) NULL device pointer\n",
633 port_num, tty, file); 637 port_num, tty, file);
634 return -ENODEV; 638 return -ENODEV;
635 } 639 }
636 640
637 mtx = &gs_open_close_lock[port_num]; 641 mtx = &gs_open_close_lock[port_num];
638 if (mutex_lock_interruptible(mtx)) { 642 if (mutex_lock_interruptible(mtx)) {
639 printk(KERN_ERR 643 pr_err("gs_open: (%d,%p,%p) interrupted waiting for mutex\n",
640 "gs_open: (%d,%p,%p) interrupted waiting for mutex\n",
641 port_num, tty, file); 644 port_num, tty, file);
642 return -ERESTARTSYS; 645 return -ERESTARTSYS;
643 } 646 }
@@ -645,8 +648,7 @@ static int gs_open(struct tty_struct *tty, struct file *file)
645 spin_lock_irqsave(&dev->dev_lock, flags); 648 spin_lock_irqsave(&dev->dev_lock, flags);
646 649
647 if (dev->dev_config == GS_NO_CONFIG_ID) { 650 if (dev->dev_config == GS_NO_CONFIG_ID) {
648 printk(KERN_ERR 651 pr_err("gs_open: (%d,%p,%p) device is not connected\n",
649 "gs_open: (%d,%p,%p) device is not connected\n",
650 port_num, tty, file); 652 port_num, tty, file);
651 ret = -ENODEV; 653 ret = -ENODEV;
652 goto exit_unlock_dev; 654 goto exit_unlock_dev;
@@ -655,7 +657,7 @@ static int gs_open(struct tty_struct *tty, struct file *file)
655 port = dev->dev_port[port_num]; 657 port = dev->dev_port[port_num];
656 658
657 if (port == NULL) { 659 if (port == NULL) {
658 printk(KERN_ERR "gs_open: (%d,%p,%p) NULL port pointer\n", 660 pr_err("gs_open: (%d,%p,%p) NULL port pointer\n",
659 port_num, tty, file); 661 port_num, tty, file);
660 ret = -ENODEV; 662 ret = -ENODEV;
661 goto exit_unlock_dev; 663 goto exit_unlock_dev;
@@ -665,7 +667,7 @@ static int gs_open(struct tty_struct *tty, struct file *file)
665 spin_unlock(&dev->dev_lock); 667 spin_unlock(&dev->dev_lock);
666 668
667 if (port->port_dev == NULL) { 669 if (port->port_dev == NULL) {
668 printk(KERN_ERR "gs_open: (%d,%p,%p) port disconnected (1)\n", 670 pr_err("gs_open: (%d,%p,%p) port disconnected (1)\n",
669 port_num, tty, file); 671 port_num, tty, file);
670 ret = -EIO; 672 ret = -EIO;
671 goto exit_unlock_port; 673 goto exit_unlock_port;
@@ -692,8 +694,7 @@ static int gs_open(struct tty_struct *tty, struct file *file)
692 694
693 /* might have been disconnected while asleep, check */ 695 /* might have been disconnected while asleep, check */
694 if (port->port_dev == NULL) { 696 if (port->port_dev == NULL) {
695 printk(KERN_ERR 697 pr_err("gs_open: (%d,%p,%p) port disconnected (2)\n",
696 "gs_open: (%d,%p,%p) port disconnected (2)\n",
697 port_num, tty, file); 698 port_num, tty, file);
698 port->port_in_use = 0; 699 port->port_in_use = 0;
699 ret = -EIO; 700 ret = -EIO;
@@ -701,7 +702,8 @@ static int gs_open(struct tty_struct *tty, struct file *file)
701 } 702 }
702 703
703 if ((port->port_write_buf=buf) == NULL) { 704 if ((port->port_write_buf=buf) == NULL) {
704 printk(KERN_ERR "gs_open: (%d,%p,%p) cannot allocate port write buffer\n", 705 pr_err("gs_open: (%d,%p,%p) cannot allocate "
706 "port write buffer\n",
705 port_num, tty, file); 707 port_num, tty, file);
706 port->port_in_use = 0; 708 port->port_in_use = 0;
707 ret = -ENOMEM; 709 ret = -ENOMEM;
@@ -714,7 +716,7 @@ static int gs_open(struct tty_struct *tty, struct file *file)
714 716
715 /* might have been disconnected while asleep, check */ 717 /* might have been disconnected while asleep, check */
716 if (port->port_dev == NULL) { 718 if (port->port_dev == NULL) {
717 printk(KERN_ERR "gs_open: (%d,%p,%p) port disconnected (3)\n", 719 pr_err("gs_open: (%d,%p,%p) port disconnected (3)\n",
718 port_num, tty, file); 720 port_num, tty, file);
719 port->port_in_use = 0; 721 port->port_in_use = 0;
720 ret = -EIO; 722 ret = -EIO;
@@ -762,7 +764,7 @@ static void gs_close(struct tty_struct *tty, struct file *file)
762 struct mutex *mtx; 764 struct mutex *mtx;
763 765
764 if (port == NULL) { 766 if (port == NULL) {
765 printk(KERN_ERR "gs_close: NULL port pointer\n"); 767 pr_err("gs_close: NULL port pointer\n");
766 return; 768 return;
767 } 769 }
768 770
@@ -774,8 +776,7 @@ static void gs_close(struct tty_struct *tty, struct file *file)
774 spin_lock_irq(&port->port_lock); 776 spin_lock_irq(&port->port_lock);
775 777
776 if (port->port_open_count == 0) { 778 if (port->port_open_count == 0) {
777 printk(KERN_ERR 779 pr_err("gs_close: (%d,%p,%p) port is already closed\n",
778 "gs_close: (%d,%p,%p) port is already closed\n",
779 port->port_num, tty, file); 780 port->port_num, tty, file);
780 goto exit; 781 goto exit;
781 } 782 }
@@ -837,7 +838,7 @@ static int gs_write(struct tty_struct *tty, const unsigned char *buf, int count)
837 int ret; 838 int ret;
838 839
839 if (port == NULL) { 840 if (port == NULL) {
840 printk(KERN_ERR "gs_write: NULL port pointer\n"); 841 pr_err("gs_write: NULL port pointer\n");
841 return -EIO; 842 return -EIO;
842 } 843 }
843 844
@@ -850,14 +851,14 @@ static int gs_write(struct tty_struct *tty, const unsigned char *buf, int count)
850 spin_lock_irqsave(&port->port_lock, flags); 851 spin_lock_irqsave(&port->port_lock, flags);
851 852
852 if (port->port_dev == NULL) { 853 if (port->port_dev == NULL) {
853 printk(KERN_ERR "gs_write: (%d,%p) port is not connected\n", 854 pr_err("gs_write: (%d,%p) port is not connected\n",
854 port->port_num, tty); 855 port->port_num, tty);
855 ret = -EIO; 856 ret = -EIO;
856 goto exit; 857 goto exit;
857 } 858 }
858 859
859 if (port->port_open_count == 0) { 860 if (port->port_open_count == 0) {
860 printk(KERN_ERR "gs_write: (%d,%p) port is closed\n", 861 pr_err("gs_write: (%d,%p) port is closed\n",
861 port->port_num, tty); 862 port->port_num, tty);
862 ret = -EBADF; 863 ret = -EBADF;
863 goto exit; 864 goto exit;
@@ -888,7 +889,7 @@ static void gs_put_char(struct tty_struct *tty, unsigned char ch)
888 struct gs_port *port = tty->driver_data; 889 struct gs_port *port = tty->driver_data;
889 890
890 if (port == NULL) { 891 if (port == NULL) {
891 printk(KERN_ERR "gs_put_char: NULL port pointer\n"); 892 pr_err("gs_put_char: NULL port pointer\n");
892 return; 893 return;
893 } 894 }
894 895
@@ -898,13 +899,13 @@ static void gs_put_char(struct tty_struct *tty, unsigned char ch)
898 spin_lock_irqsave(&port->port_lock, flags); 899 spin_lock_irqsave(&port->port_lock, flags);
899 900
900 if (port->port_dev == NULL) { 901 if (port->port_dev == NULL) {
901 printk(KERN_ERR "gs_put_char: (%d,%p) port is not connected\n", 902 pr_err("gs_put_char: (%d,%p) port is not connected\n",
902 port->port_num, tty); 903 port->port_num, tty);
903 goto exit; 904 goto exit;
904 } 905 }
905 906
906 if (port->port_open_count == 0) { 907 if (port->port_open_count == 0) {
907 printk(KERN_ERR "gs_put_char: (%d,%p) port is closed\n", 908 pr_err("gs_put_char: (%d,%p) port is closed\n",
908 port->port_num, tty); 909 port->port_num, tty);
909 goto exit; 910 goto exit;
910 } 911 }
@@ -924,7 +925,7 @@ static void gs_flush_chars(struct tty_struct *tty)
924 struct gs_port *port = tty->driver_data; 925 struct gs_port *port = tty->driver_data;
925 926
926 if (port == NULL) { 927 if (port == NULL) {
927 printk(KERN_ERR "gs_flush_chars: NULL port pointer\n"); 928 pr_err("gs_flush_chars: NULL port pointer\n");
928 return; 929 return;
929 } 930 }
930 931
@@ -933,14 +934,13 @@ static void gs_flush_chars(struct tty_struct *tty)
933 spin_lock_irqsave(&port->port_lock, flags); 934 spin_lock_irqsave(&port->port_lock, flags);
934 935
935 if (port->port_dev == NULL) { 936 if (port->port_dev == NULL) {
936 printk(KERN_ERR 937 pr_err("gs_flush_chars: (%d,%p) port is not connected\n",
937 "gs_flush_chars: (%d,%p) port is not connected\n",
938 port->port_num, tty); 938 port->port_num, tty);
939 goto exit; 939 goto exit;
940 } 940 }
941 941
942 if (port->port_open_count == 0) { 942 if (port->port_open_count == 0) {
943 printk(KERN_ERR "gs_flush_chars: (%d,%p) port is closed\n", 943 pr_err("gs_flush_chars: (%d,%p) port is closed\n",
944 port->port_num, tty); 944 port->port_num, tty);
945 goto exit; 945 goto exit;
946 } 946 }
@@ -1038,7 +1038,7 @@ static int gs_ioctl(struct tty_struct *tty, struct file *file, unsigned int cmd,
1038 struct gs_port *port = tty->driver_data; 1038 struct gs_port *port = tty->driver_data;
1039 1039
1040 if (port == NULL) { 1040 if (port == NULL) {
1041 printk(KERN_ERR "gs_ioctl: NULL port pointer\n"); 1041 pr_err("gs_ioctl: NULL port pointer\n");
1042 return -EIO; 1042 return -EIO;
1043 } 1043 }
1044 1044
@@ -1076,7 +1076,7 @@ static int gs_send(struct gs_dev *dev)
1076 struct gs_req_entry *req_entry; 1076 struct gs_req_entry *req_entry;
1077 1077
1078 if (dev == NULL) { 1078 if (dev == NULL) {
1079 printk(KERN_ERR "gs_send: NULL device pointer\n"); 1079 pr_err("gs_send: NULL device pointer\n");
1080 return -ENODEV; 1080 return -ENODEV;
1081 } 1081 }
1082 1082
@@ -1103,7 +1103,7 @@ static int gs_send(struct gs_dev *dev)
1103 req->length = len; 1103 req->length = len;
1104 spin_unlock_irqrestore(&dev->dev_lock, flags); 1104 spin_unlock_irqrestore(&dev->dev_lock, flags);
1105 if ((ret=usb_ep_queue(ep, req, GFP_ATOMIC))) { 1105 if ((ret=usb_ep_queue(ep, req, GFP_ATOMIC))) {
1106 printk(KERN_ERR 1106 pr_err(
1107 "gs_send: cannot queue read request, ret=%d\n", 1107 "gs_send: cannot queue read request, ret=%d\n",
1108 ret); 1108 ret);
1109 spin_lock_irqsave(&dev->dev_lock, flags); 1109 spin_lock_irqsave(&dev->dev_lock, flags);
@@ -1144,9 +1144,7 @@ static int gs_send_packet(struct gs_dev *dev, char *packet, unsigned int size)
1144 port = dev->dev_port[0]; 1144 port = dev->dev_port[0];
1145 1145
1146 if (port == NULL) { 1146 if (port == NULL) {
1147 printk(KERN_ERR 1147 pr_err("gs_send_packet: port=%d, NULL port pointer\n", 0);
1148 "gs_send_packet: port=%d, NULL port pointer\n",
1149 0);
1150 return -EIO; 1148 return -EIO;
1151 } 1149 }
1152 1150
@@ -1193,7 +1191,7 @@ static int gs_recv_packet(struct gs_dev *dev, char *packet, unsigned int size)
1193 port = dev->dev_port[0]; 1191 port = dev->dev_port[0];
1194 1192
1195 if (port == NULL) { 1193 if (port == NULL) {
1196 printk(KERN_ERR "gs_recv_packet: port=%d, NULL port pointer\n", 1194 pr_err("gs_recv_packet: port=%d, NULL port pointer\n",
1197 port->port_num); 1195 port->port_num);
1198 return -EIO; 1196 return -EIO;
1199 } 1197 }
@@ -1201,7 +1199,7 @@ static int gs_recv_packet(struct gs_dev *dev, char *packet, unsigned int size)
1201 spin_lock(&port->port_lock); 1199 spin_lock(&port->port_lock);
1202 1200
1203 if (port->port_open_count == 0) { 1201 if (port->port_open_count == 0) {
1204 printk(KERN_ERR "gs_recv_packet: port=%d, port is closed\n", 1202 pr_err("gs_recv_packet: port=%d, port is closed\n",
1205 port->port_num); 1203 port->port_num);
1206 ret = -EIO; 1204 ret = -EIO;
1207 goto exit; 1205 goto exit;
@@ -1211,14 +1209,14 @@ static int gs_recv_packet(struct gs_dev *dev, char *packet, unsigned int size)
1211 tty = port->port_tty; 1209 tty = port->port_tty;
1212 1210
1213 if (tty == NULL) { 1211 if (tty == NULL) {
1214 printk(KERN_ERR "gs_recv_packet: port=%d, NULL tty pointer\n", 1212 pr_err("gs_recv_packet: port=%d, NULL tty pointer\n",
1215 port->port_num); 1213 port->port_num);
1216 ret = -EIO; 1214 ret = -EIO;
1217 goto exit; 1215 goto exit;
1218 } 1216 }
1219 1217
1220 if (port->port_tty->magic != TTY_MAGIC) { 1218 if (port->port_tty->magic != TTY_MAGIC) {
1221 printk(KERN_ERR "gs_recv_packet: port=%d, bad tty magic\n", 1219 pr_err("gs_recv_packet: port=%d, bad tty magic\n",
1222 port->port_num); 1220 port->port_num);
1223 ret = -EIO; 1221 ret = -EIO;
1224 goto exit; 1222 goto exit;
@@ -1245,7 +1243,7 @@ static void gs_read_complete(struct usb_ep *ep, struct usb_request *req)
1245 struct gs_dev *dev = ep->driver_data; 1243 struct gs_dev *dev = ep->driver_data;
1246 1244
1247 if (dev == NULL) { 1245 if (dev == NULL) {
1248 printk(KERN_ERR "gs_read_complete: NULL device pointer\n"); 1246 pr_err("gs_read_complete: NULL device pointer\n");
1249 return; 1247 return;
1250 } 1248 }
1251 1249
@@ -1256,7 +1254,7 @@ static void gs_read_complete(struct usb_ep *ep, struct usb_request *req)
1256requeue: 1254requeue:
1257 req->length = ep->maxpacket; 1255 req->length = ep->maxpacket;
1258 if ((ret=usb_ep_queue(ep, req, GFP_ATOMIC))) { 1256 if ((ret=usb_ep_queue(ep, req, GFP_ATOMIC))) {
1259 printk(KERN_ERR 1257 pr_err(
1260 "gs_read_complete: cannot queue read request, ret=%d\n", 1258 "gs_read_complete: cannot queue read request, ret=%d\n",
1261 ret); 1259 ret);
1262 } 1260 }
@@ -1270,7 +1268,7 @@ requeue:
1270 1268
1271 default: 1269 default:
1272 /* unexpected */ 1270 /* unexpected */
1273 printk(KERN_ERR 1271 pr_err(
1274 "gs_read_complete: unexpected status error, status=%d\n", 1272 "gs_read_complete: unexpected status error, status=%d\n",
1275 req->status); 1273 req->status);
1276 goto requeue; 1274 goto requeue;
@@ -1287,7 +1285,7 @@ static void gs_write_complete(struct usb_ep *ep, struct usb_request *req)
1287 struct gs_req_entry *gs_req = req->context; 1285 struct gs_req_entry *gs_req = req->context;
1288 1286
1289 if (dev == NULL) { 1287 if (dev == NULL) {
1290 printk(KERN_ERR "gs_write_complete: NULL device pointer\n"); 1288 pr_err("gs_write_complete: NULL device pointer\n");
1291 return; 1289 return;
1292 } 1290 }
1293 1291
@@ -1296,8 +1294,7 @@ static void gs_write_complete(struct usb_ep *ep, struct usb_request *req)
1296 /* normal completion */ 1294 /* normal completion */
1297requeue: 1295requeue:
1298 if (gs_req == NULL) { 1296 if (gs_req == NULL) {
1299 printk(KERN_ERR 1297 pr_err("gs_write_complete: NULL request pointer\n");
1300 "gs_write_complete: NULL request pointer\n");
1301 return; 1298 return;
1302 } 1299 }
1303 1300
@@ -1316,7 +1313,7 @@ requeue:
1316 break; 1313 break;
1317 1314
1318 default: 1315 default:
1319 printk(KERN_ERR 1316 pr_err(
1320 "gs_write_complete: unexpected status error, status=%d\n", 1317 "gs_write_complete: unexpected status error, status=%d\n",
1321 req->status); 1318 req->status);
1322 goto requeue; 1319 goto requeue;
@@ -1351,7 +1348,7 @@ static int __init gs_bind(struct usb_gadget *gadget)
1351 gs_device_desc.bcdDevice = 1348 gs_device_desc.bcdDevice =
1352 cpu_to_le16(GS_VERSION_NUM | gcnum); 1349 cpu_to_le16(GS_VERSION_NUM | gcnum);
1353 else { 1350 else {
1354 printk(KERN_WARNING "gs_bind: controller '%s' not recognized\n", 1351 pr_warning("gs_bind: controller '%s' not recognized\n",
1355 gadget->name); 1352 gadget->name);
1356 /* unrecognized, but safe unless bulk is REALLY quirky */ 1353 /* unrecognized, but safe unless bulk is REALLY quirky */
1357 gs_device_desc.bcdDevice = 1354 gs_device_desc.bcdDevice =
@@ -1375,7 +1372,7 @@ static int __init gs_bind(struct usb_gadget *gadget)
1375 if (use_acm) { 1372 if (use_acm) {
1376 ep = usb_ep_autoconfig(gadget, &gs_fullspeed_notify_desc); 1373 ep = usb_ep_autoconfig(gadget, &gs_fullspeed_notify_desc);
1377 if (!ep) { 1374 if (!ep) {
1378 printk(KERN_ERR "gs_bind: cannot run ACM on %s\n", gadget->name); 1375 pr_err("gs_bind: cannot run ACM on %s\n", gadget->name);
1379 goto autoconf_fail; 1376 goto autoconf_fail;
1380 } 1377 }
1381 gs_device_desc.idProduct = __constant_cpu_to_le16( 1378 gs_device_desc.idProduct = __constant_cpu_to_le16(
@@ -1425,7 +1422,7 @@ static int __init gs_bind(struct usb_gadget *gadget)
1425 set_gadget_data(gadget, dev); 1422 set_gadget_data(gadget, dev);
1426 1423
1427 if ((ret=gs_alloc_ports(dev, GFP_KERNEL)) != 0) { 1424 if ((ret=gs_alloc_ports(dev, GFP_KERNEL)) != 0) {
1428 printk(KERN_ERR "gs_bind: cannot allocate ports\n"); 1425 pr_err("gs_bind: cannot allocate ports\n");
1429 gs_unbind(gadget); 1426 gs_unbind(gadget);
1430 return ret; 1427 return ret;
1431 } 1428 }
@@ -1441,13 +1438,13 @@ static int __init gs_bind(struct usb_gadget *gadget)
1441 1438
1442 gadget->ep0->driver_data = dev; 1439 gadget->ep0->driver_data = dev;
1443 1440
1444 printk(KERN_INFO "gs_bind: %s %s bound\n", 1441 pr_info("gs_bind: %s %s bound\n",
1445 GS_LONG_NAME, GS_VERSION_STR); 1442 GS_LONG_NAME, GS_VERSION_STR);
1446 1443
1447 return 0; 1444 return 0;
1448 1445
1449autoconf_fail: 1446autoconf_fail:
1450 printk(KERN_ERR "gs_bind: cannot autoconfigure on %s\n", gadget->name); 1447 pr_err("gs_bind: cannot autoconfigure on %s\n", gadget->name);
1451 return -ENODEV; 1448 return -ENODEV;
1452} 1449}
1453 1450
@@ -1480,7 +1477,7 @@ static void /* __init_or_exit */ gs_unbind(struct usb_gadget *gadget)
1480 set_gadget_data(gadget, NULL); 1477 set_gadget_data(gadget, NULL);
1481 } 1478 }
1482 1479
1483 printk(KERN_INFO "gs_unbind: %s %s unbound\n", GS_LONG_NAME, 1480 pr_info("gs_unbind: %s %s unbound\n", GS_LONG_NAME,
1484 GS_VERSION_STR); 1481 GS_VERSION_STR);
1485} 1482}
1486 1483
@@ -1513,7 +1510,8 @@ static int gs_setup(struct usb_gadget *gadget,
1513 break; 1510 break;
1514 1511
1515 default: 1512 default:
1516 printk(KERN_ERR "gs_setup: unknown request, type=%02x, request=%02x, value=%04x, index=%04x, length=%d\n", 1513 pr_err("gs_setup: unknown request, type=%02x, request=%02x, "
1514 "value=%04x, index=%04x, length=%d\n",
1517 ctrl->bRequestType, ctrl->bRequest, 1515 ctrl->bRequestType, ctrl->bRequest,
1518 wValue, wIndex, wLength); 1516 wValue, wIndex, wLength);
1519 break; 1517 break;
@@ -1526,7 +1524,7 @@ static int gs_setup(struct usb_gadget *gadget,
1526 && (ret % gadget->ep0->maxpacket) == 0; 1524 && (ret % gadget->ep0->maxpacket) == 0;
1527 ret = usb_ep_queue(gadget->ep0, req, GFP_ATOMIC); 1525 ret = usb_ep_queue(gadget->ep0, req, GFP_ATOMIC);
1528 if (ret < 0) { 1526 if (ret < 0) {
1529 printk(KERN_ERR "gs_setup: cannot queue response, ret=%d\n", 1527 pr_err("gs_setup: cannot queue response, ret=%d\n",
1530 ret); 1528 ret);
1531 req->status = 0; 1529 req->status = 0;
1532 gs_setup_complete(gadget->ep0, req); 1530 gs_setup_complete(gadget->ep0, req);
@@ -1656,7 +1654,8 @@ set_interface_done:
1656 break; 1654 break;
1657 1655
1658 default: 1656 default:
1659 printk(KERN_ERR "gs_setup: unknown standard request, type=%02x, request=%02x, value=%04x, index=%04x, length=%d\n", 1657 pr_err("gs_setup: unknown standard request, type=%02x, "
1658 "request=%02x, value=%04x, index=%04x, length=%d\n",
1660 ctrl->bRequestType, ctrl->bRequest, 1659 ctrl->bRequestType, ctrl->bRequest,
1661 wValue, wIndex, wLength); 1660 wValue, wIndex, wLength);
1662 break; 1661 break;
@@ -1682,7 +1681,7 @@ static int gs_setup_class(struct usb_gadget *gadget,
1682 * handler copy that data to port->port_line_coding (iff 1681 * handler copy that data to port->port_line_coding (iff
1683 * it's valid) and maybe pass it on. Until then, fail. 1682 * it's valid) and maybe pass it on. Until then, fail.
1684 */ 1683 */
1685 printk(KERN_WARNING "gs_setup: set_line_coding " 1684 pr_warning("gs_setup: set_line_coding "
1686 "unuspported\n"); 1685 "unuspported\n");
1687 break; 1686 break;
1688 1687
@@ -1702,12 +1701,12 @@ static int gs_setup_class(struct usb_gadget *gadget,
1702 * handler use that to set the state (iff it's valid) and 1701 * handler use that to set the state (iff it's valid) and
1703 * maybe pass it on. Until then, fail. 1702 * maybe pass it on. Until then, fail.
1704 */ 1703 */
1705 printk(KERN_WARNING "gs_setup: set_control_line_state " 1704 pr_warning("gs_setup: set_control_line_state "
1706 "unuspported\n"); 1705 "unuspported\n");
1707 break; 1706 break;
1708 1707
1709 default: 1708 default:
1710 printk(KERN_ERR "gs_setup: unknown class request, " 1709 pr_err("gs_setup: unknown class request, "
1711 "type=%02x, request=%02x, value=%04x, " 1710 "type=%02x, request=%02x, value=%04x, "
1712 "index=%04x, length=%d\n", 1711 "index=%04x, length=%d\n",
1713 ctrl->bRequestType, ctrl->bRequest, 1712 ctrl->bRequestType, ctrl->bRequest,
@@ -1724,7 +1723,8 @@ static int gs_setup_class(struct usb_gadget *gadget,
1724static void gs_setup_complete(struct usb_ep *ep, struct usb_request *req) 1723static void gs_setup_complete(struct usb_ep *ep, struct usb_request *req)
1725{ 1724{
1726 if (req->status || req->actual != req->length) { 1725 if (req->status || req->actual != req->length) {
1727 printk(KERN_ERR "gs_setup_complete: status error, status=%d, actual=%d, length=%d\n", 1726 pr_err("gs_setup_complete: status error, status=%d, "
1727 "actual=%d, length=%d\n",
1728 req->status, req->actual, req->length); 1728 req->status, req->actual, req->length);
1729 } 1729 }
1730} 1730}
@@ -1751,11 +1751,11 @@ static void gs_disconnect(struct usb_gadget *gadget)
1751 1751
1752 /* re-allocate ports for the next connection */ 1752 /* re-allocate ports for the next connection */
1753 if (gs_alloc_ports(dev, GFP_ATOMIC) != 0) 1753 if (gs_alloc_ports(dev, GFP_ATOMIC) != 0)
1754 printk(KERN_ERR "gs_disconnect: cannot re-allocate ports\n"); 1754 pr_err("gs_disconnect: cannot re-allocate ports\n");
1755 1755
1756 spin_unlock_irqrestore(&dev->dev_lock, flags); 1756 spin_unlock_irqrestore(&dev->dev_lock, flags);
1757 1757
1758 printk(KERN_INFO "gs_disconnect: %s disconnected\n", GS_LONG_NAME); 1758 pr_info("gs_disconnect: %s disconnected\n", GS_LONG_NAME);
1759} 1759}
1760 1760
1761/* 1761/*
@@ -1778,7 +1778,7 @@ static int gs_set_config(struct gs_dev *dev, unsigned config)
1778 struct gs_req_entry *req_entry; 1778 struct gs_req_entry *req_entry;
1779 1779
1780 if (dev == NULL) { 1780 if (dev == NULL) {
1781 printk(KERN_ERR "gs_set_config: NULL device pointer\n"); 1781 pr_err("gs_set_config: NULL device pointer\n");
1782 return 0; 1782 return 0;
1783 } 1783 }
1784 1784
@@ -1823,7 +1823,8 @@ static int gs_set_config(struct gs_dev *dev, unsigned config)
1823 dev->dev_notify_ep = ep; 1823 dev->dev_notify_ep = ep;
1824 dev->dev_notify_ep_desc = ep_desc; 1824 dev->dev_notify_ep_desc = ep_desc;
1825 } else { 1825 } else {
1826 printk(KERN_ERR "gs_set_config: cannot enable notify endpoint %s, ret=%d\n", 1826 pr_err("gs_set_config: cannot enable NOTIFY "
1827 "endpoint %s, ret=%d\n",
1827 ep->name, ret); 1828 ep->name, ret);
1828 goto exit_reset_config; 1829 goto exit_reset_config;
1829 } 1830 }
@@ -1839,7 +1840,8 @@ static int gs_set_config(struct gs_dev *dev, unsigned config)
1839 dev->dev_in_ep = ep; 1840 dev->dev_in_ep = ep;
1840 dev->dev_in_ep_desc = ep_desc; 1841 dev->dev_in_ep_desc = ep_desc;
1841 } else { 1842 } else {
1842 printk(KERN_ERR "gs_set_config: cannot enable in endpoint %s, ret=%d\n", 1843 pr_err("gs_set_config: cannot enable IN "
1844 "endpoint %s, ret=%d\n",
1843 ep->name, ret); 1845 ep->name, ret);
1844 goto exit_reset_config; 1846 goto exit_reset_config;
1845 } 1847 }
@@ -1855,7 +1857,8 @@ static int gs_set_config(struct gs_dev *dev, unsigned config)
1855 dev->dev_out_ep = ep; 1857 dev->dev_out_ep = ep;
1856 dev->dev_out_ep_desc = ep_desc; 1858 dev->dev_out_ep_desc = ep_desc;
1857 } else { 1859 } else {
1858 printk(KERN_ERR "gs_set_config: cannot enable out endpoint %s, ret=%d\n", 1860 pr_err("gs_set_config: cannot enable OUT "
1861 "endpoint %s, ret=%d\n",
1859 ep->name, ret); 1862 ep->name, ret);
1860 goto exit_reset_config; 1863 goto exit_reset_config;
1861 } 1864 }
@@ -1865,7 +1868,7 @@ static int gs_set_config(struct gs_dev *dev, unsigned config)
1865 1868
1866 if (dev->dev_in_ep == NULL || dev->dev_out_ep == NULL 1869 if (dev->dev_in_ep == NULL || dev->dev_out_ep == NULL
1867 || (config != GS_BULK_CONFIG_ID && dev->dev_notify_ep == NULL)) { 1870 || (config != GS_BULK_CONFIG_ID && dev->dev_notify_ep == NULL)) {
1868 printk(KERN_ERR "gs_set_config: cannot find endpoints\n"); 1871 pr_err("gs_set_config: cannot find endpoints\n");
1869 ret = -ENODEV; 1872 ret = -ENODEV;
1870 goto exit_reset_config; 1873 goto exit_reset_config;
1871 } 1874 }
@@ -1876,11 +1879,12 @@ static int gs_set_config(struct gs_dev *dev, unsigned config)
1876 if ((req=gs_alloc_req(ep, ep->maxpacket, GFP_ATOMIC))) { 1879 if ((req=gs_alloc_req(ep, ep->maxpacket, GFP_ATOMIC))) {
1877 req->complete = gs_read_complete; 1880 req->complete = gs_read_complete;
1878 if ((ret=usb_ep_queue(ep, req, GFP_ATOMIC))) { 1881 if ((ret=usb_ep_queue(ep, req, GFP_ATOMIC))) {
1879 printk(KERN_ERR "gs_set_config: cannot queue read request, ret=%d\n", 1882 pr_err("gs_set_config: cannot queue read "
1880 ret); 1883 "request, ret=%d\n", ret);
1881 } 1884 }
1882 } else { 1885 } else {
1883 printk(KERN_ERR "gs_set_config: cannot allocate read requests\n"); 1886 pr_err("gs_set_config: cannot allocate "
1887 "read requests\n");
1884 ret = -ENOMEM; 1888 ret = -ENOMEM;
1885 goto exit_reset_config; 1889 goto exit_reset_config;
1886 } 1890 }
@@ -1893,13 +1897,14 @@ static int gs_set_config(struct gs_dev *dev, unsigned config)
1893 req_entry->re_req->complete = gs_write_complete; 1897 req_entry->re_req->complete = gs_write_complete;
1894 list_add(&req_entry->re_entry, &dev->dev_req_list); 1898 list_add(&req_entry->re_entry, &dev->dev_req_list);
1895 } else { 1899 } else {
1896 printk(KERN_ERR "gs_set_config: cannot allocate write requests\n"); 1900 pr_err("gs_set_config: cannot allocate "
1901 "write requests\n");
1897 ret = -ENOMEM; 1902 ret = -ENOMEM;
1898 goto exit_reset_config; 1903 goto exit_reset_config;
1899 } 1904 }
1900 } 1905 }
1901 1906
1902 printk(KERN_INFO "gs_set_config: %s configured, %s speed %s config\n", 1907 pr_info("gs_set_config: %s configured, %s speed %s config\n",
1903 GS_LONG_NAME, 1908 GS_LONG_NAME,
1904 gadget->speed == USB_SPEED_HIGH ? "high" : "full", 1909 gadget->speed == USB_SPEED_HIGH ? "high" : "full",
1905 config == GS_BULK_CONFIG_ID ? "BULK" : "CDC-ACM"); 1910 config == GS_BULK_CONFIG_ID ? "BULK" : "CDC-ACM");
@@ -1926,7 +1931,7 @@ static void gs_reset_config(struct gs_dev *dev)
1926 struct gs_req_entry *req_entry; 1931 struct gs_req_entry *req_entry;
1927 1932
1928 if (dev == NULL) { 1933 if (dev == NULL) {
1929 printk(KERN_ERR "gs_reset_config: NULL device pointer\n"); 1934 pr_err("gs_reset_config: NULL device pointer\n");
1930 return; 1935 return;
1931 } 1936 }
1932 1937
diff --git a/drivers/usb/gadget/zero.c b/drivers/usb/gadget/zero.c
index fcde5d9c87df..d3d4f4048e6c 100644
--- a/drivers/usb/gadget/zero.c
+++ b/drivers/usb/gadget/zero.c
@@ -1115,7 +1115,7 @@ zero_bind (struct usb_gadget *gadget)
1115 ep = usb_ep_autoconfig (gadget, &fs_source_desc); 1115 ep = usb_ep_autoconfig (gadget, &fs_source_desc);
1116 if (!ep) { 1116 if (!ep) {
1117autoconf_fail: 1117autoconf_fail:
1118 printk (KERN_ERR "%s: can't autoconfigure on %s\n", 1118 pr_err("%s: can't autoconfigure on %s\n",
1119 shortname, gadget->name); 1119 shortname, gadget->name);
1120 return -ENODEV; 1120 return -ENODEV;
1121 } 1121 }
@@ -1139,7 +1139,7 @@ autoconf_fail:
1139 * things like configuration and altsetting numbering 1139 * things like configuration and altsetting numbering
1140 * can need hardware-specific attention though. 1140 * can need hardware-specific attention though.
1141 */ 1141 */
1142 printk (KERN_WARNING "%s: controller '%s' not recognized\n", 1142 pr_warning("%s: controller '%s' not recognized\n",
1143 shortname, gadget->name); 1143 shortname, gadget->name);
1144 device_desc.bcdDevice = __constant_cpu_to_le16 (0x9999); 1144 device_desc.bcdDevice = __constant_cpu_to_le16 (0x9999);
1145 } 1145 }
diff --git a/drivers/usb/host/Kconfig b/drivers/usb/host/Kconfig
index 49a91c5ee51b..d97b16b52efa 100644
--- a/drivers/usb/host/Kconfig
+++ b/drivers/usb/host/Kconfig
@@ -29,15 +29,6 @@ config USB_EHCI_HCD
29 To compile this driver as a module, choose M here: the 29 To compile this driver as a module, choose M here: the
30 module will be called ehci-hcd. 30 module will be called ehci-hcd.
31 31
32config USB_EHCI_SPLIT_ISO
33 bool "Full speed ISO transactions (EXPERIMENTAL)"
34 depends on USB_EHCI_HCD && EXPERIMENTAL
35 default n
36 ---help---
37 This code is new and hasn't been used with many different
38 EHCI or USB 2.0 transaction translator implementations.
39 It should work for ISO-OUT transfers, like audio.
40
41config USB_EHCI_ROOT_HUB_TT 32config USB_EHCI_ROOT_HUB_TT
42 bool "Root Hub Transaction Translators (EXPERIMENTAL)" 33 bool "Root Hub Transaction Translators (EXPERIMENTAL)"
43 depends on USB_EHCI_HCD && EXPERIMENTAL 34 depends on USB_EHCI_HCD && EXPERIMENTAL
@@ -69,21 +60,30 @@ config USB_EHCI_TT_NEWSCHED
69 60
70config USB_EHCI_BIG_ENDIAN_MMIO 61config USB_EHCI_BIG_ENDIAN_MMIO
71 bool 62 bool
72 depends on USB_EHCI_HCD && (PPC_CELLEB || PPC_PS3 || 440EPX) 63 depends on USB_EHCI_HCD && (PPC_CELLEB || PPC_PS3 || 440EPX || ARCH_IXP4XX)
73 default y 64 default y
74 65
75config USB_EHCI_BIG_ENDIAN_DESC 66config USB_EHCI_BIG_ENDIAN_DESC
76 bool 67 bool
77 depends on USB_EHCI_HCD && 440EPX 68 depends on USB_EHCI_HCD && (440EPX || ARCH_IXP4XX)
78 default y 69 default y
79 70
80config USB_EHCI_FSL 71config USB_EHCI_FSL
81 bool 72 bool
73 depends on USB_EHCI_HCD
82 select USB_EHCI_ROOT_HUB_TT 74 select USB_EHCI_ROOT_HUB_TT
83 default y if MPC834x || PPC_MPC831x 75 default y if MPC834x || PPC_MPC831x
84 ---help--- 76 ---help---
85 Variation of ARC USB block used in some Freescale chips. 77 Variation of ARC USB block used in some Freescale chips.
86 78
79config USB_EHCI_HCD_PPC_OF
80 bool "EHCI support for PPC USB controller on OF platform bus"
81 depends on USB_EHCI_HCD && PPC_OF
82 default y
83 ---help---
84 Enables support for the USB controller present on the PowerPC
85 OpenFirmware platform bus.
86
87config USB_ISP116X_HCD 87config USB_ISP116X_HCD
88 tristate "ISP116X HCD support" 88 tristate "ISP116X HCD support"
89 depends on USB 89 depends on USB
diff --git a/drivers/usb/host/ehci-au1xxx.c b/drivers/usb/host/ehci-au1xxx.c
index 766ef68a0b43..da7532d38bf1 100644
--- a/drivers/usb/host/ehci-au1xxx.c
+++ b/drivers/usb/host/ehci-au1xxx.c
@@ -222,6 +222,7 @@ static const struct hc_driver ehci_au1xxx_hc_driver = {
222 .hub_control = ehci_hub_control, 222 .hub_control = ehci_hub_control,
223 .bus_suspend = ehci_bus_suspend, 223 .bus_suspend = ehci_bus_suspend,
224 .bus_resume = ehci_bus_resume, 224 .bus_resume = ehci_bus_resume,
225 .relinquish_port = ehci_relinquish_port,
225}; 226};
226 227
227/*-------------------------------------------------------------------------*/ 228/*-------------------------------------------------------------------------*/
diff --git a/drivers/usb/host/ehci-dbg.c b/drivers/usb/host/ehci-dbg.c
index c9cc4413198e..64ebfc5548a3 100644
--- a/drivers/usb/host/ehci-dbg.c
+++ b/drivers/usb/host/ehci-dbg.c
@@ -323,7 +323,43 @@ static inline void remove_debug_files (struct ehci_hcd *bus) { }
323 323
324#else 324#else
325 325
326/* troubleshooting help: expose state in sysfs */ 326/* troubleshooting help: expose state in debugfs */
327
328static int debug_async_open(struct inode *, struct file *);
329static int debug_periodic_open(struct inode *, struct file *);
330static int debug_registers_open(struct inode *, struct file *);
331static int debug_async_open(struct inode *, struct file *);
332static ssize_t debug_output(struct file*, char __user*, size_t, loff_t*);
333static int debug_close(struct inode *, struct file *);
334
335static const struct file_operations debug_async_fops = {
336 .owner = THIS_MODULE,
337 .open = debug_async_open,
338 .read = debug_output,
339 .release = debug_close,
340};
341static const struct file_operations debug_periodic_fops = {
342 .owner = THIS_MODULE,
343 .open = debug_periodic_open,
344 .read = debug_output,
345 .release = debug_close,
346};
347static const struct file_operations debug_registers_fops = {
348 .owner = THIS_MODULE,
349 .open = debug_registers_open,
350 .read = debug_output,
351 .release = debug_close,
352};
353
354static struct dentry *ehci_debug_root;
355
356struct debug_buffer {
357 ssize_t (*fill_func)(struct debug_buffer *); /* fill method */
358 struct usb_bus *bus;
359 struct mutex mutex; /* protect filling of buffer */
360 size_t count; /* number of characters filled into buffer */
361 char *page;
362};
327 363
328#define speed_char(info1) ({ char tmp; \ 364#define speed_char(info1) ({ char tmp; \
329 switch (info1 & (3 << 12)) { \ 365 switch (info1 & (3 << 12)) { \
@@ -441,10 +477,8 @@ done:
441 *nextp = next; 477 *nextp = next;
442} 478}
443 479
444static ssize_t 480static ssize_t fill_async_buffer(struct debug_buffer *buf)
445show_async (struct class_device *class_dev, char *buf)
446{ 481{
447 struct usb_bus *bus;
448 struct usb_hcd *hcd; 482 struct usb_hcd *hcd;
449 struct ehci_hcd *ehci; 483 struct ehci_hcd *ehci;
450 unsigned long flags; 484 unsigned long flags;
@@ -452,14 +486,13 @@ show_async (struct class_device *class_dev, char *buf)
452 char *next; 486 char *next;
453 struct ehci_qh *qh; 487 struct ehci_qh *qh;
454 488
455 *buf = 0; 489 hcd = bus_to_hcd(buf->bus);
456
457 bus = class_get_devdata(class_dev);
458 hcd = bus_to_hcd(bus);
459 ehci = hcd_to_ehci (hcd); 490 ehci = hcd_to_ehci (hcd);
460 next = buf; 491 next = buf->page;
461 size = PAGE_SIZE; 492 size = PAGE_SIZE;
462 493
494 *next = 0;
495
463 /* dumps a snapshot of the async schedule. 496 /* dumps a snapshot of the async schedule.
464 * usually empty except for long-term bulk reads, or head. 497 * usually empty except for long-term bulk reads, or head.
465 * one QH per line, and TDs we know about 498 * one QH per line, and TDs we know about
@@ -477,16 +510,12 @@ show_async (struct class_device *class_dev, char *buf)
477 } 510 }
478 spin_unlock_irqrestore (&ehci->lock, flags); 511 spin_unlock_irqrestore (&ehci->lock, flags);
479 512
480 return strlen (buf); 513 return strlen(buf->page);
481} 514}
482static CLASS_DEVICE_ATTR (async, S_IRUGO, show_async, NULL);
483 515
484#define DBG_SCHED_LIMIT 64 516#define DBG_SCHED_LIMIT 64
485 517static ssize_t fill_periodic_buffer(struct debug_buffer *buf)
486static ssize_t
487show_periodic (struct class_device *class_dev, char *buf)
488{ 518{
489 struct usb_bus *bus;
490 struct usb_hcd *hcd; 519 struct usb_hcd *hcd;
491 struct ehci_hcd *ehci; 520 struct ehci_hcd *ehci;
492 unsigned long flags; 521 unsigned long flags;
@@ -500,10 +529,9 @@ show_periodic (struct class_device *class_dev, char *buf)
500 return 0; 529 return 0;
501 seen_count = 0; 530 seen_count = 0;
502 531
503 bus = class_get_devdata(class_dev); 532 hcd = bus_to_hcd(buf->bus);
504 hcd = bus_to_hcd(bus);
505 ehci = hcd_to_ehci (hcd); 533 ehci = hcd_to_ehci (hcd);
506 next = buf; 534 next = buf->page;
507 size = PAGE_SIZE; 535 size = PAGE_SIZE;
508 536
509 temp = scnprintf (next, size, "size = %d\n", ehci->periodic_size); 537 temp = scnprintf (next, size, "size = %d\n", ehci->periodic_size);
@@ -623,14 +651,10 @@ show_periodic (struct class_device *class_dev, char *buf)
623 651
624 return PAGE_SIZE - size; 652 return PAGE_SIZE - size;
625} 653}
626static CLASS_DEVICE_ATTR (periodic, S_IRUGO, show_periodic, NULL);
627
628#undef DBG_SCHED_LIMIT 654#undef DBG_SCHED_LIMIT
629 655
630static ssize_t 656static ssize_t fill_registers_buffer(struct debug_buffer *buf)
631show_registers (struct class_device *class_dev, char *buf)
632{ 657{
633 struct usb_bus *bus;
634 struct usb_hcd *hcd; 658 struct usb_hcd *hcd;
635 struct ehci_hcd *ehci; 659 struct ehci_hcd *ehci;
636 unsigned long flags; 660 unsigned long flags;
@@ -639,15 +663,14 @@ show_registers (struct class_device *class_dev, char *buf)
639 static char fmt [] = "%*s\n"; 663 static char fmt [] = "%*s\n";
640 static char label [] = ""; 664 static char label [] = "";
641 665
642 bus = class_get_devdata(class_dev); 666 hcd = bus_to_hcd(buf->bus);
643 hcd = bus_to_hcd(bus);
644 ehci = hcd_to_ehci (hcd); 667 ehci = hcd_to_ehci (hcd);
645 next = buf; 668 next = buf->page;
646 size = PAGE_SIZE; 669 size = PAGE_SIZE;
647 670
648 spin_lock_irqsave (&ehci->lock, flags); 671 spin_lock_irqsave (&ehci->lock, flags);
649 672
650 if (bus->controller->power.power_state.event) { 673 if (buf->bus->controller->power.power_state.event) {
651 size = scnprintf (next, size, 674 size = scnprintf (next, size,
652 "bus %s, device %s (driver " DRIVER_VERSION ")\n" 675 "bus %s, device %s (driver " DRIVER_VERSION ")\n"
653 "%s\n" 676 "%s\n"
@@ -763,9 +786,7 @@ show_registers (struct class_device *class_dev, char *buf)
763 } 786 }
764 787
765 if (ehci->reclaim) { 788 if (ehci->reclaim) {
766 temp = scnprintf (next, size, "reclaim qh %p%s\n", 789 temp = scnprintf(next, size, "reclaim qh %p\n", ehci->reclaim);
767 ehci->reclaim,
768 ehci->reclaim_ready ? " ready" : "");
769 size -= temp; 790 size -= temp;
770 next += temp; 791 next += temp;
771 } 792 }
@@ -789,26 +810,150 @@ done:
789 810
790 return PAGE_SIZE - size; 811 return PAGE_SIZE - size;
791} 812}
792static CLASS_DEVICE_ATTR (registers, S_IRUGO, show_registers, NULL);
793 813
794static inline void create_debug_files (struct ehci_hcd *ehci) 814static struct debug_buffer *alloc_buffer(struct usb_bus *bus,
815 ssize_t (*fill_func)(struct debug_buffer *))
795{ 816{
796 struct class_device *cldev = ehci_to_hcd(ehci)->self.class_dev; 817 struct debug_buffer *buf;
797 int retval; 818
819 buf = kzalloc(sizeof(struct debug_buffer), GFP_KERNEL);
798 820
799 retval = class_device_create_file(cldev, &class_device_attr_async); 821 if (buf) {
800 retval = class_device_create_file(cldev, &class_device_attr_periodic); 822 buf->bus = bus;
801 retval = class_device_create_file(cldev, &class_device_attr_registers); 823 buf->fill_func = fill_func;
824 mutex_init(&buf->mutex);
825 }
826
827 return buf;
802} 828}
803 829
804static inline void remove_debug_files (struct ehci_hcd *ehci) 830static int fill_buffer(struct debug_buffer *buf)
805{ 831{
806 struct class_device *cldev = ehci_to_hcd(ehci)->self.class_dev; 832 int ret = 0;
833
834 if (!buf->page)
835 buf->page = (char *)get_zeroed_page(GFP_KERNEL);
836
837 if (!buf->page) {
838 ret = -ENOMEM;
839 goto out;
840 }
841
842 ret = buf->fill_func(buf);
807 843
808 class_device_remove_file(cldev, &class_device_attr_async); 844 if (ret >= 0) {
809 class_device_remove_file(cldev, &class_device_attr_periodic); 845 buf->count = ret;
810 class_device_remove_file(cldev, &class_device_attr_registers); 846 ret = 0;
847 }
848
849out:
850 return ret;
811} 851}
812 852
813#endif /* STUB_DEBUG_FILES */ 853static ssize_t debug_output(struct file *file, char __user *user_buf,
854 size_t len, loff_t *offset)
855{
856 struct debug_buffer *buf = file->private_data;
857 int ret = 0;
858
859 mutex_lock(&buf->mutex);
860 if (buf->count == 0) {
861 ret = fill_buffer(buf);
862 if (ret != 0) {
863 mutex_unlock(&buf->mutex);
864 goto out;
865 }
866 }
867 mutex_unlock(&buf->mutex);
868
869 ret = simple_read_from_buffer(user_buf, len, offset,
870 buf->page, buf->count);
871
872out:
873 return ret;
874
875}
876
877static int debug_close(struct inode *inode, struct file *file)
878{
879 struct debug_buffer *buf = file->private_data;
814 880
881 if (buf) {
882 if (buf->page)
883 free_page((unsigned long)buf->page);
884 kfree(buf);
885 }
886
887 return 0;
888}
889static int debug_async_open(struct inode *inode, struct file *file)
890{
891 file->private_data = alloc_buffer(inode->i_private, fill_async_buffer);
892
893 return file->private_data ? 0 : -ENOMEM;
894}
895
896static int debug_periodic_open(struct inode *inode, struct file *file)
897{
898 file->private_data = alloc_buffer(inode->i_private,
899 fill_periodic_buffer);
900
901 return file->private_data ? 0 : -ENOMEM;
902}
903
904static int debug_registers_open(struct inode *inode, struct file *file)
905{
906 file->private_data = alloc_buffer(inode->i_private,
907 fill_registers_buffer);
908
909 return file->private_data ? 0 : -ENOMEM;
910}
911
912static inline void create_debug_files (struct ehci_hcd *ehci)
913{
914 struct usb_bus *bus = &ehci_to_hcd(ehci)->self;
915
916 ehci->debug_dir = debugfs_create_dir(bus->bus_name, ehci_debug_root);
917 if (!ehci->debug_dir)
918 goto dir_error;
919
920 ehci->debug_async = debugfs_create_file("async", S_IRUGO,
921 ehci->debug_dir, bus,
922 &debug_async_fops);
923 if (!ehci->debug_async)
924 goto async_error;
925
926 ehci->debug_periodic = debugfs_create_file("periodic", S_IRUGO,
927 ehci->debug_dir, bus,
928 &debug_periodic_fops);
929 if (!ehci->debug_periodic)
930 goto periodic_error;
931
932 ehci->debug_registers = debugfs_create_file("registers", S_IRUGO,
933 ehci->debug_dir, bus,
934 &debug_registers_fops);
935 if (!ehci->debug_registers)
936 goto registers_error;
937 return;
938
939registers_error:
940 debugfs_remove(ehci->debug_periodic);
941periodic_error:
942 debugfs_remove(ehci->debug_async);
943async_error:
944 debugfs_remove(ehci->debug_dir);
945dir_error:
946 ehci->debug_periodic = NULL;
947 ehci->debug_async = NULL;
948 ehci->debug_dir = NULL;
949}
950
951static inline void remove_debug_files (struct ehci_hcd *ehci)
952{
953 debugfs_remove(ehci->debug_registers);
954 debugfs_remove(ehci->debug_periodic);
955 debugfs_remove(ehci->debug_async);
956 debugfs_remove(ehci->debug_dir);
957}
958
959#endif /* STUB_DEBUG_FILES */
diff --git a/drivers/usb/host/ehci-fsl.c b/drivers/usb/host/ehci-fsl.c
index 430821cb95c8..adb0defa1631 100644
--- a/drivers/usb/host/ehci-fsl.c
+++ b/drivers/usb/host/ehci-fsl.c
@@ -25,7 +25,7 @@
25 25
26#include "ehci-fsl.h" 26#include "ehci-fsl.h"
27 27
28/* FIXME: Power Managment is un-ported so temporarily disable it */ 28/* FIXME: Power Management is un-ported so temporarily disable it */
29#undef CONFIG_PM 29#undef CONFIG_PM
30 30
31/* PCI-based HCs are common, but plenty of non-PCI HCs are used too */ 31/* PCI-based HCs are common, but plenty of non-PCI HCs are used too */
@@ -323,6 +323,7 @@ static const struct hc_driver ehci_fsl_hc_driver = {
323 .hub_control = ehci_hub_control, 323 .hub_control = ehci_hub_control,
324 .bus_suspend = ehci_bus_suspend, 324 .bus_suspend = ehci_bus_suspend,
325 .bus_resume = ehci_bus_resume, 325 .bus_resume = ehci_bus_resume,
326 .relinquish_port = ehci_relinquish_port,
326}; 327};
327 328
328static int ehci_fsl_drv_probe(struct platform_device *pdev) 329static int ehci_fsl_drv_probe(struct platform_device *pdev)
diff --git a/drivers/usb/host/ehci-hcd.c b/drivers/usb/host/ehci-hcd.c
index 5f2d74ed5ad7..4caa6a8b9a37 100644
--- a/drivers/usb/host/ehci-hcd.c
+++ b/drivers/usb/host/ehci-hcd.c
@@ -33,6 +33,7 @@
33#include <linux/usb.h> 33#include <linux/usb.h>
34#include <linux/moduleparam.h> 34#include <linux/moduleparam.h>
35#include <linux/dma-mapping.h> 35#include <linux/dma-mapping.h>
36#include <linux/debugfs.h>
36 37
37#include "../core/hcd.h" 38#include "../core/hcd.h"
38 39
@@ -109,7 +110,7 @@ static const char hcd_name [] = "ehci_hcd";
109#define EHCI_TUNE_MULT_TT 1 110#define EHCI_TUNE_MULT_TT 1
110#define EHCI_TUNE_FLS 2 /* (small) 256 frame schedule */ 111#define EHCI_TUNE_FLS 2 /* (small) 256 frame schedule */
111 112
112#define EHCI_IAA_JIFFIES (HZ/100) /* arbitrary; ~10 msec */ 113#define EHCI_IAA_MSECS 10 /* arbitrary */
113#define EHCI_IO_JIFFIES (HZ/10) /* io watchdog > irq_thresh */ 114#define EHCI_IO_JIFFIES (HZ/10) /* io watchdog > irq_thresh */
114#define EHCI_ASYNC_JIFFIES (HZ/20) /* async idle timeout */ 115#define EHCI_ASYNC_JIFFIES (HZ/20) /* async idle timeout */
115#define EHCI_SHRINK_JIFFIES (HZ/200) /* async qh unlink delay */ 116#define EHCI_SHRINK_JIFFIES (HZ/200) /* async qh unlink delay */
@@ -266,6 +267,7 @@ static void ehci_quiesce (struct ehci_hcd *ehci)
266 267
267/*-------------------------------------------------------------------------*/ 268/*-------------------------------------------------------------------------*/
268 269
270static void end_unlink_async(struct ehci_hcd *ehci);
269static void ehci_work(struct ehci_hcd *ehci); 271static void ehci_work(struct ehci_hcd *ehci);
270 272
271#include "ehci-hub.c" 273#include "ehci-hub.c"
@@ -275,25 +277,41 @@ static void ehci_work(struct ehci_hcd *ehci);
275 277
276/*-------------------------------------------------------------------------*/ 278/*-------------------------------------------------------------------------*/
277 279
278static void ehci_watchdog (unsigned long param) 280static void ehci_iaa_watchdog(unsigned long param)
279{ 281{
280 struct ehci_hcd *ehci = (struct ehci_hcd *) param; 282 struct ehci_hcd *ehci = (struct ehci_hcd *) param;
281 unsigned long flags; 283 unsigned long flags;
284 u32 status, cmd;
282 285
283 spin_lock_irqsave (&ehci->lock, flags); 286 spin_lock_irqsave (&ehci->lock, flags);
287 WARN_ON(!ehci->reclaim);
284 288
285 /* lost IAA irqs wedge things badly; seen with a vt8235 */ 289 status = ehci_readl(ehci, &ehci->regs->status);
290 cmd = ehci_readl(ehci, &ehci->regs->command);
291 ehci_dbg(ehci, "IAA watchdog: status %x cmd %x\n", status, cmd);
292
293 /* lost IAA irqs wedge things badly; seen first with a vt8235 */
286 if (ehci->reclaim) { 294 if (ehci->reclaim) {
287 u32 status = ehci_readl(ehci, &ehci->regs->status);
288 if (status & STS_IAA) { 295 if (status & STS_IAA) {
289 ehci_vdbg (ehci, "lost IAA\n"); 296 ehci_vdbg (ehci, "lost IAA\n");
290 COUNT (ehci->stats.lost_iaa); 297 COUNT (ehci->stats.lost_iaa);
291 ehci_writel(ehci, STS_IAA, &ehci->regs->status); 298 ehci_writel(ehci, STS_IAA, &ehci->regs->status);
292 ehci->reclaim_ready = 1;
293 } 299 }
300 ehci_writel(ehci, cmd & ~CMD_IAAD, &ehci->regs->command);
301 end_unlink_async(ehci);
294 } 302 }
295 303
296 /* stop async processing after it's idled a bit */ 304 spin_unlock_irqrestore(&ehci->lock, flags);
305}
306
307static void ehci_watchdog(unsigned long param)
308{
309 struct ehci_hcd *ehci = (struct ehci_hcd *) param;
310 unsigned long flags;
311
312 spin_lock_irqsave(&ehci->lock, flags);
313
314 /* stop async processing after it's idled a bit */
297 if (test_bit (TIMER_ASYNC_OFF, &ehci->actions)) 315 if (test_bit (TIMER_ASYNC_OFF, &ehci->actions))
298 start_unlink_async (ehci, ehci->async); 316 start_unlink_async (ehci, ehci->async);
299 317
@@ -363,8 +381,6 @@ static void ehci_port_power (struct ehci_hcd *ehci, int is_on)
363static void ehci_work (struct ehci_hcd *ehci) 381static void ehci_work (struct ehci_hcd *ehci)
364{ 382{
365 timer_action_done (ehci, TIMER_IO_WATCHDOG); 383 timer_action_done (ehci, TIMER_IO_WATCHDOG);
366 if (ehci->reclaim_ready)
367 end_unlink_async (ehci);
368 384
369 /* another CPU may drop ehci->lock during a schedule scan while 385 /* another CPU may drop ehci->lock during a schedule scan while
370 * it reports urb completions. this flag guards against bogus 386 * it reports urb completions. this flag guards against bogus
@@ -399,6 +415,7 @@ static void ehci_stop (struct usb_hcd *hcd)
399 415
400 /* no more interrupts ... */ 416 /* no more interrupts ... */
401 del_timer_sync (&ehci->watchdog); 417 del_timer_sync (&ehci->watchdog);
418 del_timer_sync(&ehci->iaa_watchdog);
402 419
403 spin_lock_irq(&ehci->lock); 420 spin_lock_irq(&ehci->lock);
404 if (HC_IS_RUNNING (hcd->state)) 421 if (HC_IS_RUNNING (hcd->state))
@@ -447,6 +464,10 @@ static int ehci_init(struct usb_hcd *hcd)
447 ehci->watchdog.function = ehci_watchdog; 464 ehci->watchdog.function = ehci_watchdog;
448 ehci->watchdog.data = (unsigned long) ehci; 465 ehci->watchdog.data = (unsigned long) ehci;
449 466
467 init_timer(&ehci->iaa_watchdog);
468 ehci->iaa_watchdog.function = ehci_iaa_watchdog;
469 ehci->iaa_watchdog.data = (unsigned long) ehci;
470
450 /* 471 /*
451 * hw default: 1K periodic list heads, one per frame. 472 * hw default: 1K periodic list heads, one per frame.
452 * periodic_size can shrink by USBCMD update if hcc_params allows. 473 * periodic_size can shrink by USBCMD update if hcc_params allows.
@@ -463,7 +484,6 @@ static int ehci_init(struct usb_hcd *hcd)
463 ehci->i_thresh = 2 + HCC_ISOC_THRES(hcc_params); 484 ehci->i_thresh = 2 + HCC_ISOC_THRES(hcc_params);
464 485
465 ehci->reclaim = NULL; 486 ehci->reclaim = NULL;
466 ehci->reclaim_ready = 0;
467 ehci->next_uframe = -1; 487 ehci->next_uframe = -1;
468 488
469 /* 489 /*
@@ -654,8 +674,7 @@ static irqreturn_t ehci_irq (struct usb_hcd *hcd)
654 /* complete the unlinking of some qh [4.15.2.3] */ 674 /* complete the unlinking of some qh [4.15.2.3] */
655 if (status & STS_IAA) { 675 if (status & STS_IAA) {
656 COUNT (ehci->stats.reclaim); 676 COUNT (ehci->stats.reclaim);
657 ehci->reclaim_ready = 1; 677 end_unlink_async(ehci);
658 bh = 1;
659 } 678 }
660 679
661 /* remote wakeup [4.3.1] */ 680 /* remote wakeup [4.3.1] */
@@ -761,10 +780,16 @@ static int ehci_urb_enqueue (
761 780
762static void unlink_async (struct ehci_hcd *ehci, struct ehci_qh *qh) 781static void unlink_async (struct ehci_hcd *ehci, struct ehci_qh *qh)
763{ 782{
764 /* if we need to use IAA and it's busy, defer */ 783 /* failfast */
765 if (qh->qh_state == QH_STATE_LINKED 784 if (!HC_IS_RUNNING(ehci_to_hcd(ehci)->state))
766 && ehci->reclaim 785 end_unlink_async(ehci);
767 && HC_IS_RUNNING (ehci_to_hcd(ehci)->state)) { 786
787 /* if it's not linked then there's nothing to do */
788 if (qh->qh_state != QH_STATE_LINKED)
789 ;
790
791 /* defer till later if busy */
792 else if (ehci->reclaim) {
768 struct ehci_qh *last; 793 struct ehci_qh *last;
769 794
770 for (last = ehci->reclaim; 795 for (last = ehci->reclaim;
@@ -774,12 +799,8 @@ static void unlink_async (struct ehci_hcd *ehci, struct ehci_qh *qh)
774 qh->qh_state = QH_STATE_UNLINK_WAIT; 799 qh->qh_state = QH_STATE_UNLINK_WAIT;
775 last->reclaim = qh; 800 last->reclaim = qh;
776 801
777 /* bypass IAA if the hc can't care */ 802 /* start IAA cycle */
778 } else if (!HC_IS_RUNNING (ehci_to_hcd(ehci)->state) && ehci->reclaim) 803 } else
779 end_unlink_async (ehci);
780
781 /* something else might have unlinked the qh by now */
782 if (qh->qh_state == QH_STATE_LINKED)
783 start_unlink_async (ehci, qh); 804 start_unlink_async (ehci, qh);
784} 805}
785 806
@@ -806,7 +827,19 @@ static int ehci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
806 qh = (struct ehci_qh *) urb->hcpriv; 827 qh = (struct ehci_qh *) urb->hcpriv;
807 if (!qh) 828 if (!qh)
808 break; 829 break;
809 unlink_async (ehci, qh); 830 switch (qh->qh_state) {
831 case QH_STATE_LINKED:
832 case QH_STATE_COMPLETING:
833 unlink_async(ehci, qh);
834 break;
835 case QH_STATE_UNLINK:
836 case QH_STATE_UNLINK_WAIT:
837 /* already started */
838 break;
839 case QH_STATE_IDLE:
840 WARN_ON(1);
841 break;
842 }
810 break; 843 break;
811 844
812 case PIPE_INTERRUPT: 845 case PIPE_INTERRUPT:
@@ -829,16 +862,16 @@ static int ehci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
829 /* reschedule QH iff another request is queued */ 862 /* reschedule QH iff another request is queued */
830 if (!list_empty (&qh->qtd_list) 863 if (!list_empty (&qh->qtd_list)
831 && HC_IS_RUNNING (hcd->state)) { 864 && HC_IS_RUNNING (hcd->state)) {
832 int status; 865 int schedule_status;
833 866
834 status = qh_schedule (ehci, qh); 867 schedule_status = qh_schedule (ehci, qh);
835 spin_unlock_irqrestore (&ehci->lock, flags); 868 spin_unlock_irqrestore (&ehci->lock, flags);
836 869
837 if (status != 0) { 870 if (schedule_status != 0) {
838 // shouldn't happen often, but ... 871 // shouldn't happen often, but ...
839 // FIXME kill those tds' urbs 872 // FIXME kill those tds' urbs
840 err ("can't reschedule qh %p, err %d", 873 err ("can't reschedule qh %p, err %d",
841 qh, status); 874 qh, schedule_status);
842 } 875 }
843 return status; 876 return status;
844 } 877 }
@@ -898,6 +931,7 @@ rescan:
898 unlink_async (ehci, qh); 931 unlink_async (ehci, qh);
899 /* FALL THROUGH */ 932 /* FALL THROUGH */
900 case QH_STATE_UNLINK: /* wait for hw to finish? */ 933 case QH_STATE_UNLINK: /* wait for hw to finish? */
934 case QH_STATE_UNLINK_WAIT:
901idle_timeout: 935idle_timeout:
902 spin_unlock_irqrestore (&ehci->lock, flags); 936 spin_unlock_irqrestore (&ehci->lock, flags);
903 schedule_timeout_uninterruptible(1); 937 schedule_timeout_uninterruptible(1);
@@ -959,11 +993,26 @@ MODULE_LICENSE ("GPL");
959#define PS3_SYSTEM_BUS_DRIVER ps3_ehci_driver 993#define PS3_SYSTEM_BUS_DRIVER ps3_ehci_driver
960#endif 994#endif
961 995
962#ifdef CONFIG_440EPX 996#if defined(CONFIG_440EPX) && !defined(CONFIG_PPC_MERGE)
963#include "ehci-ppc-soc.c" 997#include "ehci-ppc-soc.c"
964#define PLATFORM_DRIVER ehci_ppc_soc_driver 998#define PLATFORM_DRIVER ehci_ppc_soc_driver
965#endif 999#endif
966 1000
1001#ifdef CONFIG_USB_EHCI_HCD_PPC_OF
1002#include "ehci-ppc-of.c"
1003#define OF_PLATFORM_DRIVER ehci_hcd_ppc_of_driver
1004#endif
1005
1006#ifdef CONFIG_ARCH_ORION
1007#include "ehci-orion.c"
1008#define PLATFORM_DRIVER ehci_orion_driver
1009#endif
1010
1011#ifdef CONFIG_ARCH_IXP4XX
1012#include "ehci-ixp4xx.c"
1013#define PLATFORM_DRIVER ixp4xx_ehci_driver
1014#endif
1015
967#if !defined(PCI_DRIVER) && !defined(PLATFORM_DRIVER) && \ 1016#if !defined(PCI_DRIVER) && !defined(PLATFORM_DRIVER) && \
968 !defined(PS3_SYSTEM_BUS_DRIVER) 1017 !defined(PS3_SYSTEM_BUS_DRIVER)
969#error "missing bus glue for ehci-hcd" 1018#error "missing bus glue for ehci-hcd"
@@ -978,41 +1027,66 @@ static int __init ehci_hcd_init(void)
978 sizeof(struct ehci_qh), sizeof(struct ehci_qtd), 1027 sizeof(struct ehci_qh), sizeof(struct ehci_qtd),
979 sizeof(struct ehci_itd), sizeof(struct ehci_sitd)); 1028 sizeof(struct ehci_itd), sizeof(struct ehci_sitd));
980 1029
1030#ifdef DEBUG
1031 ehci_debug_root = debugfs_create_dir("ehci", NULL);
1032 if (!ehci_debug_root)
1033 return -ENOENT;
1034#endif
1035
981#ifdef PLATFORM_DRIVER 1036#ifdef PLATFORM_DRIVER
982 retval = platform_driver_register(&PLATFORM_DRIVER); 1037 retval = platform_driver_register(&PLATFORM_DRIVER);
983 if (retval < 0) 1038 if (retval < 0)
984 return retval; 1039 goto clean0;
985#endif 1040#endif
986 1041
987#ifdef PCI_DRIVER 1042#ifdef PCI_DRIVER
988 retval = pci_register_driver(&PCI_DRIVER); 1043 retval = pci_register_driver(&PCI_DRIVER);
989 if (retval < 0) { 1044 if (retval < 0)
990#ifdef PLATFORM_DRIVER 1045 goto clean1;
991 platform_driver_unregister(&PLATFORM_DRIVER);
992#endif
993 return retval;
994 }
995#endif 1046#endif
996 1047
997#ifdef PS3_SYSTEM_BUS_DRIVER 1048#ifdef PS3_SYSTEM_BUS_DRIVER
998 retval = ps3_ehci_driver_register(&PS3_SYSTEM_BUS_DRIVER); 1049 retval = ps3_ehci_driver_register(&PS3_SYSTEM_BUS_DRIVER);
999 if (retval < 0) { 1050 if (retval < 0)
1000#ifdef PLATFORM_DRIVER 1051 goto clean2;
1001 platform_driver_unregister(&PLATFORM_DRIVER); 1052#endif
1053
1054#ifdef OF_PLATFORM_DRIVER
1055 retval = of_register_platform_driver(&OF_PLATFORM_DRIVER);
1056 if (retval < 0)
1057 goto clean3;
1058#endif
1059 return retval;
1060
1061#ifdef OF_PLATFORM_DRIVER
1062 /* of_unregister_platform_driver(&OF_PLATFORM_DRIVER); */
1063clean3:
1064#endif
1065#ifdef PS3_SYSTEM_BUS_DRIVER
1066 ps3_ehci_driver_unregister(&PS3_SYSTEM_BUS_DRIVER);
1067clean2:
1002#endif 1068#endif
1003#ifdef PCI_DRIVER 1069#ifdef PCI_DRIVER
1004 pci_unregister_driver(&PCI_DRIVER); 1070 pci_unregister_driver(&PCI_DRIVER);
1071clean1:
1005#endif 1072#endif
1006 return retval; 1073#ifdef PLATFORM_DRIVER
1007 } 1074 platform_driver_unregister(&PLATFORM_DRIVER);
1075clean0:
1076#endif
1077#ifdef DEBUG
1078 debugfs_remove(ehci_debug_root);
1079 ehci_debug_root = NULL;
1008#endif 1080#endif
1009
1010 return retval; 1081 return retval;
1011} 1082}
1012module_init(ehci_hcd_init); 1083module_init(ehci_hcd_init);
1013 1084
1014static void __exit ehci_hcd_cleanup(void) 1085static void __exit ehci_hcd_cleanup(void)
1015{ 1086{
1087#ifdef OF_PLATFORM_DRIVER
1088 of_unregister_platform_driver(&OF_PLATFORM_DRIVER);
1089#endif
1016#ifdef PLATFORM_DRIVER 1090#ifdef PLATFORM_DRIVER
1017 platform_driver_unregister(&PLATFORM_DRIVER); 1091 platform_driver_unregister(&PLATFORM_DRIVER);
1018#endif 1092#endif
@@ -1022,6 +1096,9 @@ static void __exit ehci_hcd_cleanup(void)
1022#ifdef PS3_SYSTEM_BUS_DRIVER 1096#ifdef PS3_SYSTEM_BUS_DRIVER
1023 ps3_ehci_driver_unregister(&PS3_SYSTEM_BUS_DRIVER); 1097 ps3_ehci_driver_unregister(&PS3_SYSTEM_BUS_DRIVER);
1024#endif 1098#endif
1099#ifdef DEBUG
1100 debugfs_remove(ehci_debug_root);
1101#endif
1025} 1102}
1026module_exit(ehci_hcd_cleanup); 1103module_exit(ehci_hcd_cleanup);
1027 1104
diff --git a/drivers/usb/host/ehci-hub.c b/drivers/usb/host/ehci-hub.c
index 735db4aec831..40e8240b7851 100644
--- a/drivers/usb/host/ehci-hub.c
+++ b/drivers/usb/host/ehci-hub.c
@@ -123,6 +123,8 @@ static int ehci_bus_suspend (struct usb_hcd *hcd)
123 123
124 if (time_before (jiffies, ehci->next_statechange)) 124 if (time_before (jiffies, ehci->next_statechange))
125 msleep(5); 125 msleep(5);
126 del_timer_sync(&ehci->watchdog);
127 del_timer_sync(&ehci->iaa_watchdog);
126 128
127 port = HCS_N_PORTS (ehci->hcs_params); 129 port = HCS_N_PORTS (ehci->hcs_params);
128 spin_lock_irq (&ehci->lock); 130 spin_lock_irq (&ehci->lock);
@@ -134,7 +136,7 @@ static int ehci_bus_suspend (struct usb_hcd *hcd)
134 } 136 }
135 ehci->command = ehci_readl(ehci, &ehci->regs->command); 137 ehci->command = ehci_readl(ehci, &ehci->regs->command);
136 if (ehci->reclaim) 138 if (ehci->reclaim)
137 ehci->reclaim_ready = 1; 139 end_unlink_async(ehci);
138 ehci_work(ehci); 140 ehci_work(ehci);
139 141
140 /* Unlike other USB host controller types, EHCI doesn't have 142 /* Unlike other USB host controller types, EHCI doesn't have
@@ -170,8 +172,11 @@ static int ehci_bus_suspend (struct usb_hcd *hcd)
170 } 172 }
171 } 173 }
172 174
175 /* Apparently some devices need a >= 1-uframe delay here */
176 if (ehci->bus_suspended)
177 udelay(150);
178
173 /* turn off now-idle HC */ 179 /* turn off now-idle HC */
174 del_timer_sync (&ehci->watchdog);
175 ehci_halt (ehci); 180 ehci_halt (ehci);
176 hcd->state = HC_STATE_SUSPENDED; 181 hcd->state = HC_STATE_SUSPENDED;
177 182
@@ -291,14 +296,16 @@ static int ehci_bus_resume (struct usb_hcd *hcd)
291/*-------------------------------------------------------------------------*/ 296/*-------------------------------------------------------------------------*/
292 297
293/* Display the ports dedicated to the companion controller */ 298/* Display the ports dedicated to the companion controller */
294static ssize_t show_companion(struct class_device *class_dev, char *buf) 299static ssize_t show_companion(struct device *dev,
300 struct device_attribute *attr,
301 char *buf)
295{ 302{
296 struct ehci_hcd *ehci; 303 struct ehci_hcd *ehci;
297 int nports, index, n; 304 int nports, index, n;
298 int count = PAGE_SIZE; 305 int count = PAGE_SIZE;
299 char *ptr = buf; 306 char *ptr = buf;
300 307
301 ehci = hcd_to_ehci(bus_to_hcd(class_get_devdata(class_dev))); 308 ehci = hcd_to_ehci(bus_to_hcd(dev_get_drvdata(dev)));
302 nports = HCS_N_PORTS(ehci->hcs_params); 309 nports = HCS_N_PORTS(ehci->hcs_params);
303 310
304 for (index = 0; index < nports; ++index) { 311 for (index = 0; index < nports; ++index) {
@@ -312,40 +319,21 @@ static ssize_t show_companion(struct class_device *class_dev, char *buf)
312} 319}
313 320
314/* 321/*
315 * Dedicate or undedicate a port to the companion controller. 322 * Sets the owner of a port
316 * Syntax is "[-]portnum", where a leading '-' sign means
317 * return control of the port to the EHCI controller.
318 */ 323 */
319static ssize_t store_companion(struct class_device *class_dev, 324static void set_owner(struct ehci_hcd *ehci, int portnum, int new_owner)
320 const char *buf, size_t count)
321{ 325{
322 struct ehci_hcd *ehci;
323 int portnum, new_owner, try;
324 u32 __iomem *status_reg; 326 u32 __iomem *status_reg;
325 u32 port_status; 327 u32 port_status;
328 int try;
326 329
327 ehci = hcd_to_ehci(bus_to_hcd(class_get_devdata(class_dev))); 330 status_reg = &ehci->regs->port_status[portnum];
328 new_owner = PORT_OWNER; /* Owned by companion */
329 if (sscanf(buf, "%d", &portnum) != 1)
330 return -EINVAL;
331 if (portnum < 0) {
332 portnum = - portnum;
333 new_owner = 0; /* Owned by EHCI */
334 }
335 if (portnum <= 0 || portnum > HCS_N_PORTS(ehci->hcs_params))
336 return -ENOENT;
337 status_reg = &ehci->regs->port_status[--portnum];
338 if (new_owner)
339 set_bit(portnum, &ehci->companion_ports);
340 else
341 clear_bit(portnum, &ehci->companion_ports);
342 331
343 /* 332 /*
344 * The controller won't set the OWNER bit if the port is 333 * The controller won't set the OWNER bit if the port is
345 * enabled, so this loop will sometimes require at least two 334 * enabled, so this loop will sometimes require at least two
346 * iterations: one to disable the port and one to set OWNER. 335 * iterations: one to disable the port and one to set OWNER.
347 */ 336 */
348
349 for (try = 4; try > 0; --try) { 337 for (try = 4; try > 0; --try) {
350 spin_lock_irq(&ehci->lock); 338 spin_lock_irq(&ehci->lock);
351 port_status = ehci_readl(ehci, status_reg); 339 port_status = ehci_readl(ehci, status_reg);
@@ -362,9 +350,39 @@ static ssize_t store_companion(struct class_device *class_dev,
362 if (try > 1) 350 if (try > 1)
363 msleep(5); 351 msleep(5);
364 } 352 }
353}
354
355/*
356 * Dedicate or undedicate a port to the companion controller.
357 * Syntax is "[-]portnum", where a leading '-' sign means
358 * return control of the port to the EHCI controller.
359 */
360static ssize_t store_companion(struct device *dev,
361 struct device_attribute *attr,
362 const char *buf, size_t count)
363{
364 struct ehci_hcd *ehci;
365 int portnum, new_owner;
366
367 ehci = hcd_to_ehci(bus_to_hcd(dev_get_drvdata(dev)));
368 new_owner = PORT_OWNER; /* Owned by companion */
369 if (sscanf(buf, "%d", &portnum) != 1)
370 return -EINVAL;
371 if (portnum < 0) {
372 portnum = - portnum;
373 new_owner = 0; /* Owned by EHCI */
374 }
375 if (portnum <= 0 || portnum > HCS_N_PORTS(ehci->hcs_params))
376 return -ENOENT;
377 portnum--;
378 if (new_owner)
379 set_bit(portnum, &ehci->companion_ports);
380 else
381 clear_bit(portnum, &ehci->companion_ports);
382 set_owner(ehci, portnum, new_owner);
365 return count; 383 return count;
366} 384}
367static CLASS_DEVICE_ATTR(companion, 0644, show_companion, store_companion); 385static DEVICE_ATTR(companion, 0644, show_companion, store_companion);
368 386
369static inline void create_companion_file(struct ehci_hcd *ehci) 387static inline void create_companion_file(struct ehci_hcd *ehci)
370{ 388{
@@ -372,16 +390,16 @@ static inline void create_companion_file(struct ehci_hcd *ehci)
372 390
373 /* with integrated TT there is no companion! */ 391 /* with integrated TT there is no companion! */
374 if (!ehci_is_TDI(ehci)) 392 if (!ehci_is_TDI(ehci))
375 i = class_device_create_file(ehci_to_hcd(ehci)->self.class_dev, 393 i = device_create_file(ehci_to_hcd(ehci)->self.dev,
376 &class_device_attr_companion); 394 &dev_attr_companion);
377} 395}
378 396
379static inline void remove_companion_file(struct ehci_hcd *ehci) 397static inline void remove_companion_file(struct ehci_hcd *ehci)
380{ 398{
381 /* with integrated TT there is no companion! */ 399 /* with integrated TT there is no companion! */
382 if (!ehci_is_TDI(ehci)) 400 if (!ehci_is_TDI(ehci))
383 class_device_remove_file(ehci_to_hcd(ehci)->self.class_dev, 401 device_remove_file(ehci_to_hcd(ehci)->self.dev,
384 &class_device_attr_companion); 402 &dev_attr_companion);
385} 403}
386 404
387 405
@@ -393,10 +411,8 @@ static int check_reset_complete (
393 u32 __iomem *status_reg, 411 u32 __iomem *status_reg,
394 int port_status 412 int port_status
395) { 413) {
396 if (!(port_status & PORT_CONNECT)) { 414 if (!(port_status & PORT_CONNECT))
397 ehci->reset_done [index] = 0;
398 return port_status; 415 return port_status;
399 }
400 416
401 /* if reset finished and it's still not enabled -- handoff */ 417 /* if reset finished and it's still not enabled -- handoff */
402 if (!(port_status & PORT_PE)) { 418 if (!(port_status & PORT_PE)) {
@@ -475,8 +491,6 @@ ehci_hub_status_data (struct usb_hcd *hcd, char *buf)
475 * controller by the user. 491 * controller by the user.
476 */ 492 */
477 493
478 if (!(temp & PORT_CONNECT))
479 ehci->reset_done [i] = 0;
480 if ((temp & mask) != 0 494 if ((temp & mask) != 0
481 || ((temp & PORT_RESUME) != 0 495 || ((temp & PORT_RESUME) != 0
482 && time_after_eq(jiffies, 496 && time_after_eq(jiffies,
@@ -864,3 +878,13 @@ error:
864 spin_unlock_irqrestore (&ehci->lock, flags); 878 spin_unlock_irqrestore (&ehci->lock, flags);
865 return retval; 879 return retval;
866} 880}
881
882static void ehci_relinquish_port(struct usb_hcd *hcd, int portnum)
883{
884 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
885
886 if (ehci_is_TDI(ehci))
887 return;
888 set_owner(ehci, --portnum, PORT_OWNER);
889}
890
diff --git a/drivers/usb/host/ehci-ixp4xx.c b/drivers/usb/host/ehci-ixp4xx.c
new file mode 100644
index 000000000000..3041d8f055f4
--- /dev/null
+++ b/drivers/usb/host/ehci-ixp4xx.c
@@ -0,0 +1,152 @@
1/*
2 * IXP4XX EHCI Host Controller Driver
3 *
4 * Author: Vladimir Barinov <vbarinov@ru.mvista.com>
5 *
6 * Based on "ehci-fsl.c" by Randy Vinson <rvinson@mvista.com>
7 *
8 * 2007 (c) MontaVista Software, Inc. This file is licensed under
9 * the terms of the GNU General Public License version 2. This program
10 * is licensed "as is" without any warranty of any kind, whether express
11 * or implied.
12 */
13
14#include <linux/platform_device.h>
15
16static int ixp4xx_ehci_init(struct usb_hcd *hcd)
17{
18 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
19 int retval = 0;
20
21 ehci->big_endian_desc = 1;
22 ehci->big_endian_mmio = 1;
23
24 ehci->caps = hcd->regs + 0x100;
25 ehci->regs = hcd->regs + 0x100
26 + HC_LENGTH(ehci_readl(ehci, &ehci->caps->hc_capbase));
27 ehci->hcs_params = ehci_readl(ehci, &ehci->caps->hcs_params);
28
29 ehci->is_tdi_rh_tt = 1;
30 ehci_reset(ehci);
31
32 retval = ehci_init(hcd);
33 if (retval)
34 return retval;
35
36 ehci_port_power(ehci, 0);
37
38 return retval;
39}
40
41static const struct hc_driver ixp4xx_ehci_hc_driver = {
42 .description = hcd_name,
43 .product_desc = "IXP4XX EHCI Host Controller",
44 .hcd_priv_size = sizeof(struct ehci_hcd),
45 .irq = ehci_irq,
46 .flags = HCD_MEMORY | HCD_USB2,
47 .reset = ixp4xx_ehci_init,
48 .start = ehci_run,
49 .stop = ehci_stop,
50 .shutdown = ehci_shutdown,
51 .urb_enqueue = ehci_urb_enqueue,
52 .urb_dequeue = ehci_urb_dequeue,
53 .endpoint_disable = ehci_endpoint_disable,
54 .get_frame_number = ehci_get_frame,
55 .hub_status_data = ehci_hub_status_data,
56 .hub_control = ehci_hub_control,
57#if defined(CONFIG_PM)
58 .bus_suspend = ehci_bus_suspend,
59 .bus_resume = ehci_bus_resume,
60#endif
61};
62
63static int ixp4xx_ehci_probe(struct platform_device *pdev)
64{
65 struct usb_hcd *hcd;
66 const struct hc_driver *driver = &ixp4xx_ehci_hc_driver;
67 struct resource *res;
68 int irq;
69 int retval;
70
71 if (usb_disabled())
72 return -ENODEV;
73
74 res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
75 if (!res) {
76 dev_err(&pdev->dev,
77 "Found HC with no IRQ. Check %s setup!\n",
78 pdev->dev.bus_id);
79 return -ENODEV;
80 }
81 irq = res->start;
82
83 hcd = usb_create_hcd(driver, &pdev->dev, pdev->dev.bus_id);
84 if (!hcd) {
85 retval = -ENOMEM;
86 goto fail_create_hcd;
87 }
88
89 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
90 if (!res) {
91 dev_err(&pdev->dev,
92 "Found HC with no register addr. Check %s setup!\n",
93 pdev->dev.bus_id);
94 retval = -ENODEV;
95 goto fail_request_resource;
96 }
97 hcd->rsrc_start = res->start;
98 hcd->rsrc_len = res->end - res->start + 1;
99
100 if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len,
101 driver->description)) {
102 dev_dbg(&pdev->dev, "controller already in use\n");
103 retval = -EBUSY;
104 goto fail_request_resource;
105 }
106
107 hcd->regs = ioremap_nocache(hcd->rsrc_start, hcd->rsrc_len);
108 if (hcd->regs == NULL) {
109 dev_dbg(&pdev->dev, "error mapping memory\n");
110 retval = -EFAULT;
111 goto fail_ioremap;
112 }
113
114 retval = usb_add_hcd(hcd, irq, IRQF_SHARED);
115 if (retval)
116 goto fail_add_hcd;
117
118 return retval;
119
120fail_add_hcd:
121 iounmap(hcd->regs);
122fail_ioremap:
123 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
124fail_request_resource:
125 usb_put_hcd(hcd);
126fail_create_hcd:
127 dev_err(&pdev->dev, "init %s fail, %d\n", pdev->dev.bus_id, retval);
128 return retval;
129}
130
131static int ixp4xx_ehci_remove(struct platform_device *pdev)
132{
133 struct usb_hcd *hcd = platform_get_drvdata(pdev);
134
135 usb_remove_hcd(hcd);
136 iounmap(hcd->regs);
137 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
138 usb_put_hcd(hcd);
139
140 return 0;
141}
142
143MODULE_ALIAS("ixp4xx-ehci");
144
145static struct platform_driver ixp4xx_ehci_driver = {
146 .probe = ixp4xx_ehci_probe,
147 .remove = ixp4xx_ehci_remove,
148 .driver = {
149 .name = "ixp4xx-ehci",
150 .bus = &platform_bus_type
151 },
152};
diff --git a/drivers/usb/host/ehci-orion.c b/drivers/usb/host/ehci-orion.c
new file mode 100644
index 000000000000..e129981f139f
--- /dev/null
+++ b/drivers/usb/host/ehci-orion.c
@@ -0,0 +1,272 @@
1/*
2 * drivers/usb/host/ehci-orion.c
3 *
4 * Tzachi Perelstein <tzachi@marvell.com>
5 *
6 * This file is licensed under the terms of the GNU General Public
7 * License version 2. This program is licensed "as is" without any
8 * warranty of any kind, whether express or implied.
9 */
10
11#include <linux/kernel.h>
12#include <linux/module.h>
13#include <linux/platform_device.h>
14#include <asm/arch/orion.h>
15
16#define rdl(off) __raw_readl(hcd->regs + (off))
17#define wrl(off, val) __raw_writel((val), hcd->regs + (off))
18
19#define USB_CAUSE 0x310
20#define USB_MASK 0x314
21#define USB_CMD 0x140
22#define USB_MODE 0x1a8
23#define USB_IPG 0x360
24#define USB_PHY_PWR_CTRL 0x400
25#define USB_PHY_TX_CTRL 0x420
26#define USB_PHY_RX_CTRL 0x430
27#define USB_PHY_IVREF_CTRL 0x440
28#define USB_PHY_TST_GRP_CTRL 0x450
29
30/*
31 * Implement Orion USB controller specification guidelines
32 */
33static void orion_usb_setup(struct usb_hcd *hcd)
34{
35 /*
36 * Clear interrupt cause and mask
37 */
38 wrl(USB_CAUSE, 0);
39 wrl(USB_MASK, 0);
40
41 /*
42 * Reset controller
43 */
44 wrl(USB_CMD, rdl(USB_CMD) | 0x2);
45 while (rdl(USB_CMD) & 0x2);
46
47 /*
48 * GL# USB-10: Set IPG for non start of frame packets
49 * Bits[14:8]=0xc
50 */
51 wrl(USB_IPG, (rdl(USB_IPG) & ~0x7f00) | 0xc00);
52
53 /*
54 * GL# USB-9: USB 2.0 Power Control
55 * BG_VSEL[7:6]=0x1
56 */
57 wrl(USB_PHY_PWR_CTRL, (rdl(USB_PHY_PWR_CTRL) & ~0xc0)| 0x40);
58
59 /*
60 * GL# USB-1: USB PHY Tx Control - force calibration to '8'
61 * TXDATA_BLOCK_EN[21]=0x1, EXT_RCAL_EN[13]=0x1, IMP_CAL[6:3]=0x8
62 */
63 wrl(USB_PHY_TX_CTRL, (rdl(USB_PHY_TX_CTRL) & ~0x78) | 0x202040);
64
65 /*
66 * GL# USB-3 GL# USB-9: USB PHY Rx Control
67 * RXDATA_BLOCK_LENGHT[31:30]=0x3, EDGE_DET_SEL[27:26]=0,
68 * CDR_FASTLOCK_EN[21]=0, DISCON_THRESHOLD[9:8]=0, SQ_THRESH[7:4]=0x1
69 */
70 wrl(USB_PHY_RX_CTRL, (rdl(USB_PHY_RX_CTRL) & ~0xc2003f0) | 0xc0000010);
71
72 /*
73 * GL# USB-3 GL# USB-9: USB PHY IVREF Control
74 * PLLVDD12[1:0]=0x2, RXVDD[5:4]=0x3, Reserved[19]=0
75 */
76 wrl(USB_PHY_IVREF_CTRL, (rdl(USB_PHY_IVREF_CTRL) & ~0x80003 ) | 0x32);
77
78 /*
79 * GL# USB-3 GL# USB-9: USB PHY Test Group Control
80 * REG_FIFO_SQ_RST[15]=0
81 */
82 wrl(USB_PHY_TST_GRP_CTRL, rdl(USB_PHY_TST_GRP_CTRL) & ~0x8000);
83
84 /*
85 * Stop and reset controller
86 */
87 wrl(USB_CMD, rdl(USB_CMD) & ~0x1);
88 wrl(USB_CMD, rdl(USB_CMD) | 0x2);
89 while (rdl(USB_CMD) & 0x2);
90
91 /*
92 * GL# USB-5 Streaming disable REG_USB_MODE[4]=1
93 * TBD: This need to be done after each reset!
94 * GL# USB-4 Setup USB Host mode
95 */
96 wrl(USB_MODE, 0x13);
97}
98
99static int ehci_orion_setup(struct usb_hcd *hcd)
100{
101 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
102 int retval;
103
104 retval = ehci_halt(ehci);
105 if (retval)
106 return retval;
107
108 /*
109 * data structure init
110 */
111 retval = ehci_init(hcd);
112 if (retval)
113 return retval;
114
115 ehci_reset(ehci);
116 ehci_port_power(ehci, 0);
117
118 return retval;
119}
120
121static const struct hc_driver ehci_orion_hc_driver = {
122 .description = hcd_name,
123 .product_desc = "Marvell Orion EHCI",
124 .hcd_priv_size = sizeof(struct ehci_hcd),
125
126 /*
127 * generic hardware linkage
128 */
129 .irq = ehci_irq,
130 .flags = HCD_MEMORY | HCD_USB2,
131
132 /*
133 * basic lifecycle operations
134 */
135 .reset = ehci_orion_setup,
136 .start = ehci_run,
137#ifdef CONFIG_PM
138 .suspend = ehci_bus_suspend,
139 .resume = ehci_bus_resume,
140#endif
141 .stop = ehci_stop,
142 .shutdown = ehci_shutdown,
143
144 /*
145 * managing i/o requests and associated device resources
146 */
147 .urb_enqueue = ehci_urb_enqueue,
148 .urb_dequeue = ehci_urb_dequeue,
149 .endpoint_disable = ehci_endpoint_disable,
150
151 /*
152 * scheduling support
153 */
154 .get_frame_number = ehci_get_frame,
155
156 /*
157 * root hub support
158 */
159 .hub_status_data = ehci_hub_status_data,
160 .hub_control = ehci_hub_control,
161 .bus_suspend = ehci_bus_suspend,
162 .bus_resume = ehci_bus_resume,
163};
164
165static int __init ehci_orion_drv_probe(struct platform_device *pdev)
166{
167 struct resource *res;
168 struct usb_hcd *hcd;
169 struct ehci_hcd *ehci;
170 void __iomem *regs;
171 int irq, err;
172
173 if (usb_disabled())
174 return -ENODEV;
175
176 pr_debug("Initializing Orion-SoC USB Host Controller\n");
177
178 irq = platform_get_irq(pdev, 0);
179 if (irq <= 0) {
180 dev_err(&pdev->dev,
181 "Found HC with no IRQ. Check %s setup!\n",
182 pdev->dev.bus_id);
183 err = -ENODEV;
184 goto err1;
185 }
186
187 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
188 if (!res) {
189 dev_err(&pdev->dev,
190 "Found HC with no register addr. Check %s setup!\n",
191 pdev->dev.bus_id);
192 err = -ENODEV;
193 goto err1;
194 }
195
196 if (!request_mem_region(res->start, res->end - res->start + 1,
197 ehci_orion_hc_driver.description)) {
198 dev_dbg(&pdev->dev, "controller already in use\n");
199 err = -EBUSY;
200 goto err1;
201 }
202
203 regs = ioremap(res->start, res->end - res->start + 1);
204 if (regs == NULL) {
205 dev_dbg(&pdev->dev, "error mapping memory\n");
206 err = -EFAULT;
207 goto err2;
208 }
209
210 hcd = usb_create_hcd(&ehci_orion_hc_driver,
211 &pdev->dev, pdev->dev.bus_id);
212 if (!hcd) {
213 err = -ENOMEM;
214 goto err3;
215 }
216
217 hcd->rsrc_start = res->start;
218 hcd->rsrc_len = res->end - res->start + 1;
219 hcd->regs = regs;
220
221 ehci = hcd_to_ehci(hcd);
222 ehci->caps = hcd->regs + 0x100;
223 ehci->regs = hcd->regs + 0x100 +
224 HC_LENGTH(ehci_readl(ehci, &ehci->caps->hc_capbase));
225 ehci->hcs_params = ehci_readl(ehci, &ehci->caps->hcs_params);
226 ehci->is_tdi_rh_tt = 1;
227 ehci->sbrn = 0x20;
228
229 /*
230 * setup Orion USB controller
231 */
232 orion_usb_setup(hcd);
233
234 err = usb_add_hcd(hcd, irq, IRQF_SHARED | IRQF_DISABLED);
235 if (err)
236 goto err4;
237
238 return 0;
239
240err4:
241 usb_put_hcd(hcd);
242err3:
243 iounmap(regs);
244err2:
245 release_mem_region(res->start, res->end - res->start + 1);
246err1:
247 dev_err(&pdev->dev, "init %s fail, %d\n",
248 pdev->dev.bus_id, err);
249
250 return err;
251}
252
253static int __exit ehci_orion_drv_remove(struct platform_device *pdev)
254{
255 struct usb_hcd *hcd = platform_get_drvdata(pdev);
256
257 usb_remove_hcd(hcd);
258 iounmap(hcd->regs);
259 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
260 usb_put_hcd(hcd);
261
262 return 0;
263}
264
265MODULE_ALIAS("platform:orion-ehci");
266
267static struct platform_driver ehci_orion_driver = {
268 .probe = ehci_orion_drv_probe,
269 .remove = __exit_p(ehci_orion_drv_remove),
270 .shutdown = usb_hcd_platform_shutdown,
271 .driver.name = "orion-ehci",
272};
diff --git a/drivers/usb/host/ehci-pci.c b/drivers/usb/host/ehci-pci.c
index ad0d4965f2fb..3ba01664f821 100644
--- a/drivers/usb/host/ehci-pci.c
+++ b/drivers/usb/host/ehci-pci.c
@@ -305,7 +305,7 @@ static int ehci_pci_resume(struct usb_hcd *hcd)
305 /* emptying the schedule aborts any urbs */ 305 /* emptying the schedule aborts any urbs */
306 spin_lock_irq(&ehci->lock); 306 spin_lock_irq(&ehci->lock);
307 if (ehci->reclaim) 307 if (ehci->reclaim)
308 ehci->reclaim_ready = 1; 308 end_unlink_async(ehci);
309 ehci_work(ehci); 309 ehci_work(ehci);
310 spin_unlock_irq(&ehci->lock); 310 spin_unlock_irq(&ehci->lock);
311 311
@@ -364,6 +364,7 @@ static const struct hc_driver ehci_pci_hc_driver = {
364 .hub_control = ehci_hub_control, 364 .hub_control = ehci_hub_control,
365 .bus_suspend = ehci_bus_suspend, 365 .bus_suspend = ehci_bus_suspend,
366 .bus_resume = ehci_bus_resume, 366 .bus_resume = ehci_bus_resume,
367 .relinquish_port = ehci_relinquish_port,
367}; 368};
368 369
369/*-------------------------------------------------------------------------*/ 370/*-------------------------------------------------------------------------*/
diff --git a/drivers/usb/host/ehci-ppc-of.c b/drivers/usb/host/ehci-ppc-of.c
new file mode 100644
index 000000000000..ee305b1f99ff
--- /dev/null
+++ b/drivers/usb/host/ehci-ppc-of.c
@@ -0,0 +1,238 @@
1/*
2 * EHCI HCD (Host Controller Driver) for USB.
3 *
4 * Bus Glue for PPC On-Chip EHCI driver on the of_platform bus
5 * Tested on AMCC PPC 440EPx
6 *
7 * Valentine Barshak <vbarshak@ru.mvista.com>
8 *
9 * Based on "ehci-ppc-soc.c" by Stefan Roese <sr@denx.de>
10 * and "ohci-ppc-of.c" by Sylvain Munaut <tnt@246tNt.com>
11 *
12 * This file is licenced under the GPL.
13 */
14
15#include <linux/signal.h>
16
17#include <linux/of.h>
18#include <linux/of_platform.h>
19
20/* called during probe() after chip reset completes */
21static int ehci_ppc_of_setup(struct usb_hcd *hcd)
22{
23 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
24 int retval;
25
26 retval = ehci_halt(ehci);
27 if (retval)
28 return retval;
29
30 retval = ehci_init(hcd);
31 if (retval)
32 return retval;
33
34 ehci->sbrn = 0x20;
35 return ehci_reset(ehci);
36}
37
38
39static const struct hc_driver ehci_ppc_of_hc_driver = {
40 .description = hcd_name,
41 .product_desc = "OF EHCI",
42 .hcd_priv_size = sizeof(struct ehci_hcd),
43
44 /*
45 * generic hardware linkage
46 */
47 .irq = ehci_irq,
48 .flags = HCD_MEMORY | HCD_USB2,
49
50 /*
51 * basic lifecycle operations
52 */
53 .reset = ehci_ppc_of_setup,
54 .start = ehci_run,
55 .stop = ehci_stop,
56 .shutdown = ehci_shutdown,
57
58 /*
59 * managing i/o requests and associated device resources
60 */
61 .urb_enqueue = ehci_urb_enqueue,
62 .urb_dequeue = ehci_urb_dequeue,
63 .endpoint_disable = ehci_endpoint_disable,
64
65 /*
66 * scheduling support
67 */
68 .get_frame_number = ehci_get_frame,
69
70 /*
71 * root hub support
72 */
73 .hub_status_data = ehci_hub_status_data,
74 .hub_control = ehci_hub_control,
75#ifdef CONFIG_PM
76 .bus_suspend = ehci_bus_suspend,
77 .bus_resume = ehci_bus_resume,
78#endif
79};
80
81
82/*
83 * 440EPx Errata USBH_3
84 * Fix: Enable Break Memory Transfer (BMT) in INSNREG3
85 */
86#define PPC440EPX_EHCI0_INSREG_BMT (0x1 << 0)
87static int __devinit
88ppc44x_enable_bmt(struct device_node *dn)
89{
90 __iomem u32 *insreg_virt;
91
92 insreg_virt = of_iomap(dn, 1);
93 if (!insreg_virt)
94 return -EINVAL;
95
96 out_be32(insreg_virt + 3, PPC440EPX_EHCI0_INSREG_BMT);
97
98 iounmap(insreg_virt);
99 return 0;
100}
101
102
103static int __devinit
104ehci_hcd_ppc_of_probe(struct of_device *op, const struct of_device_id *match)
105{
106 struct device_node *dn = op->node;
107 struct usb_hcd *hcd;
108 struct ehci_hcd *ehci;
109 struct resource res;
110 int irq;
111 int rv;
112
113 if (usb_disabled())
114 return -ENODEV;
115
116 dev_dbg(&op->dev, "initializing PPC-OF USB Controller\n");
117
118 rv = of_address_to_resource(dn, 0, &res);
119 if (rv)
120 return rv;
121
122 hcd = usb_create_hcd(&ehci_ppc_of_hc_driver, &op->dev, "PPC-OF USB");
123 if (!hcd)
124 return -ENOMEM;
125
126 hcd->rsrc_start = res.start;
127 hcd->rsrc_len = res.end - res.start + 1;
128
129 if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) {
130 printk(KERN_ERR __FILE__ ": request_mem_region failed\n");
131 rv = -EBUSY;
132 goto err_rmr;
133 }
134
135 irq = irq_of_parse_and_map(dn, 0);
136 if (irq == NO_IRQ) {
137 printk(KERN_ERR __FILE__ ": irq_of_parse_and_map failed\n");
138 rv = -EBUSY;
139 goto err_irq;
140 }
141
142 hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
143 if (!hcd->regs) {
144 printk(KERN_ERR __FILE__ ": ioremap failed\n");
145 rv = -ENOMEM;
146 goto err_ioremap;
147 }
148
149 ehci = hcd_to_ehci(hcd);
150
151 if (of_get_property(dn, "big-endian", NULL)) {
152 ehci->big_endian_mmio = 1;
153 ehci->big_endian_desc = 1;
154 }
155 if (of_get_property(dn, "big-endian-regs", NULL))
156 ehci->big_endian_mmio = 1;
157 if (of_get_property(dn, "big-endian-desc", NULL))
158 ehci->big_endian_desc = 1;
159
160 ehci->caps = hcd->regs;
161 ehci->regs = hcd->regs +
162 HC_LENGTH(ehci_readl(ehci, &ehci->caps->hc_capbase));
163
164 /* cache this readonly data; minimize chip reads */
165 ehci->hcs_params = ehci_readl(ehci, &ehci->caps->hcs_params);
166
167 if (of_device_is_compatible(dn, "ibm,usb-ehci-440epx")) {
168 rv = ppc44x_enable_bmt(dn);
169 ehci_dbg(ehci, "Break Memory Transfer (BMT) is %senabled!\n",
170 rv ? "NOT ": "");
171 }
172
173 rv = usb_add_hcd(hcd, irq, 0);
174 if (rv == 0)
175 return 0;
176
177 iounmap(hcd->regs);
178err_ioremap:
179 irq_dispose_mapping(irq);
180err_irq:
181 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
182err_rmr:
183 usb_put_hcd(hcd);
184
185 return rv;
186}
187
188
189static int ehci_hcd_ppc_of_remove(struct of_device *op)
190{
191 struct usb_hcd *hcd = dev_get_drvdata(&op->dev);
192 dev_set_drvdata(&op->dev, NULL);
193
194 dev_dbg(&op->dev, "stopping PPC-OF USB Controller\n");
195
196 usb_remove_hcd(hcd);
197
198 iounmap(hcd->regs);
199 irq_dispose_mapping(hcd->irq);
200 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
201
202 usb_put_hcd(hcd);
203
204 return 0;
205}
206
207
208static int ehci_hcd_ppc_of_shutdown(struct of_device *op)
209{
210 struct usb_hcd *hcd = dev_get_drvdata(&op->dev);
211
212 if (hcd->driver->shutdown)
213 hcd->driver->shutdown(hcd);
214
215 return 0;
216}
217
218
219static struct of_device_id ehci_hcd_ppc_of_match[] = {
220 {
221 .compatible = "usb-ehci",
222 },
223 {},
224};
225MODULE_DEVICE_TABLE(of, ehci_hcd_ppc_of_match);
226
227
228static struct of_platform_driver ehci_hcd_ppc_of_driver = {
229 .name = "ppc-of-ehci",
230 .match_table = ehci_hcd_ppc_of_match,
231 .probe = ehci_hcd_ppc_of_probe,
232 .remove = ehci_hcd_ppc_of_remove,
233 .shutdown = ehci_hcd_ppc_of_shutdown,
234 .driver = {
235 .name = "ppc-of-ehci",
236 .owner = THIS_MODULE,
237 },
238};
diff --git a/drivers/usb/host/ehci-ppc-soc.c b/drivers/usb/host/ehci-ppc-soc.c
index 452d4b1bc859..a3249078c808 100644
--- a/drivers/usb/host/ehci-ppc-soc.c
+++ b/drivers/usb/host/ehci-ppc-soc.c
@@ -162,6 +162,7 @@ static const struct hc_driver ehci_ppc_soc_hc_driver = {
162 .hub_control = ehci_hub_control, 162 .hub_control = ehci_hub_control,
163 .bus_suspend = ehci_bus_suspend, 163 .bus_suspend = ehci_bus_suspend,
164 .bus_resume = ehci_bus_resume, 164 .bus_resume = ehci_bus_resume,
165 .relinquish_port = ehci_relinquish_port,
165}; 166};
166 167
167static int ehci_hcd_ppc_soc_drv_probe(struct platform_device *pdev) 168static int ehci_hcd_ppc_soc_drv_probe(struct platform_device *pdev)
diff --git a/drivers/usb/host/ehci-ps3.c b/drivers/usb/host/ehci-ps3.c
index 03a6b2f4e6ed..bbda58eb8813 100644
--- a/drivers/usb/host/ehci-ps3.c
+++ b/drivers/usb/host/ehci-ps3.c
@@ -72,6 +72,7 @@ static const struct hc_driver ps3_ehci_hc_driver = {
72 .bus_suspend = ehci_bus_suspend, 72 .bus_suspend = ehci_bus_suspend,
73 .bus_resume = ehci_bus_resume, 73 .bus_resume = ehci_bus_resume,
74#endif 74#endif
75 .relinquish_port = ehci_relinquish_port,
75}; 76};
76 77
77static int ps3_ehci_probe(struct ps3_system_bus_device *dev) 78static int ps3_ehci_probe(struct ps3_system_bus_device *dev)
diff --git a/drivers/usb/host/ehci-q.c b/drivers/usb/host/ehci-q.c
index b10f39c047e9..776a97f33914 100644
--- a/drivers/usb/host/ehci-q.c
+++ b/drivers/usb/host/ehci-q.c
@@ -198,7 +198,8 @@ static int qtd_copy_status (
198 198
199 /* if async CSPLIT failed, try cleaning out the TT buffer */ 199 /* if async CSPLIT failed, try cleaning out the TT buffer */
200 if (status != -EPIPE 200 if (status != -EPIPE
201 && urb->dev->tt && !usb_pipeint (urb->pipe) 201 && urb->dev->tt
202 && !usb_pipeint(urb->pipe)
202 && ((token & QTD_STS_MMF) != 0 203 && ((token & QTD_STS_MMF) != 0
203 || QTD_CERR(token) == 0) 204 || QTD_CERR(token) == 0)
204 && (!ehci_is_TDI(ehci) 205 && (!ehci_is_TDI(ehci)
@@ -211,6 +212,9 @@ static int qtd_copy_status (
211 urb->dev->ttport, urb->dev->devnum, 212 urb->dev->ttport, urb->dev->devnum,
212 usb_pipeendpoint (urb->pipe), token); 213 usb_pipeendpoint (urb->pipe), token);
213#endif /* DEBUG */ 214#endif /* DEBUG */
215 /* REVISIT ARC-derived cores don't clear the root
216 * hub TT buffer in this way...
217 */
214 usb_hub_tt_clear_buffer (urb->dev, urb->pipe); 218 usb_hub_tt_clear_buffer (urb->dev, urb->pipe);
215 } 219 }
216 } 220 }
@@ -638,6 +642,7 @@ qh_make (
638 u32 info1 = 0, info2 = 0; 642 u32 info1 = 0, info2 = 0;
639 int is_input, type; 643 int is_input, type;
640 int maxp = 0; 644 int maxp = 0;
645 struct usb_tt *tt = urb->dev->tt;
641 646
642 if (!qh) 647 if (!qh)
643 return qh; 648 return qh;
@@ -661,8 +666,9 @@ qh_make (
661 * For control/bulk requests, the HC or TT handles these. 666 * For control/bulk requests, the HC or TT handles these.
662 */ 667 */
663 if (type == PIPE_INTERRUPT) { 668 if (type == PIPE_INTERRUPT) {
664 qh->usecs = NS_TO_US (usb_calc_bus_time (USB_SPEED_HIGH, is_input, 0, 669 qh->usecs = NS_TO_US(usb_calc_bus_time(USB_SPEED_HIGH,
665 hb_mult (maxp) * max_packet (maxp))); 670 is_input, 0,
671 hb_mult(maxp) * max_packet(maxp)));
666 qh->start = NO_FRAME; 672 qh->start = NO_FRAME;
667 673
668 if (urb->dev->speed == USB_SPEED_HIGH) { 674 if (urb->dev->speed == USB_SPEED_HIGH) {
@@ -680,7 +686,6 @@ qh_make (
680 goto done; 686 goto done;
681 } 687 }
682 } else { 688 } else {
683 struct usb_tt *tt = urb->dev->tt;
684 int think_time; 689 int think_time;
685 690
686 /* gap is f(FS/LS transfer times) */ 691 /* gap is f(FS/LS transfer times) */
@@ -736,10 +741,8 @@ qh_make (
736 /* set the address of the TT; for TDI's integrated 741 /* set the address of the TT; for TDI's integrated
737 * root hub tt, leave it zeroed. 742 * root hub tt, leave it zeroed.
738 */ 743 */
739 if (!ehci_is_TDI(ehci) 744 if (tt && tt->hub != ehci_to_hcd(ehci)->self.root_hub)
740 || urb->dev->tt->hub != 745 info2 |= tt->hub->devnum << 16;
741 ehci_to_hcd(ehci)->self.root_hub)
742 info2 |= urb->dev->tt->hub->devnum << 16;
743 746
744 /* NOTE: if (PIPE_INTERRUPT) { scheduler sets c-mask } */ 747 /* NOTE: if (PIPE_INTERRUPT) { scheduler sets c-mask } */
745 748
@@ -973,7 +976,7 @@ static void end_unlink_async (struct ehci_hcd *ehci)
973 struct ehci_qh *qh = ehci->reclaim; 976 struct ehci_qh *qh = ehci->reclaim;
974 struct ehci_qh *next; 977 struct ehci_qh *next;
975 978
976 timer_action_done (ehci, TIMER_IAA_WATCHDOG); 979 iaa_watchdog_done(ehci);
977 980
978 // qh->hw_next = cpu_to_hc32(qh->qh_dma); 981 // qh->hw_next = cpu_to_hc32(qh->qh_dma);
979 qh->qh_state = QH_STATE_IDLE; 982 qh->qh_state = QH_STATE_IDLE;
@@ -983,7 +986,6 @@ static void end_unlink_async (struct ehci_hcd *ehci)
983 /* other unlink(s) may be pending (in QH_STATE_UNLINK_WAIT) */ 986 /* other unlink(s) may be pending (in QH_STATE_UNLINK_WAIT) */
984 next = qh->reclaim; 987 next = qh->reclaim;
985 ehci->reclaim = next; 988 ehci->reclaim = next;
986 ehci->reclaim_ready = 0;
987 qh->reclaim = NULL; 989 qh->reclaim = NULL;
988 990
989 qh_completions (ehci, qh); 991 qh_completions (ehci, qh);
@@ -1059,11 +1061,10 @@ static void start_unlink_async (struct ehci_hcd *ehci, struct ehci_qh *qh)
1059 return; 1061 return;
1060 } 1062 }
1061 1063
1062 ehci->reclaim_ready = 0;
1063 cmd |= CMD_IAAD; 1064 cmd |= CMD_IAAD;
1064 ehci_writel(ehci, cmd, &ehci->regs->command); 1065 ehci_writel(ehci, cmd, &ehci->regs->command);
1065 (void)ehci_readl(ehci, &ehci->regs->command); 1066 (void)ehci_readl(ehci, &ehci->regs->command);
1066 timer_action (ehci, TIMER_IAA_WATCHDOG); 1067 iaa_watchdog_start(ehci);
1067} 1068}
1068 1069
1069/*-------------------------------------------------------------------------*/ 1070/*-------------------------------------------------------------------------*/
diff --git a/drivers/usb/host/ehci-sched.c b/drivers/usb/host/ehci-sched.c
index 80d99bce2b38..8a8e08a51ba3 100644
--- a/drivers/usb/host/ehci-sched.c
+++ b/drivers/usb/host/ehci-sched.c
@@ -119,7 +119,8 @@ periodic_usecs (struct ehci_hcd *ehci, unsigned frame, unsigned uframe)
119 q = &q->fstn->fstn_next; 119 q = &q->fstn->fstn_next;
120 break; 120 break;
121 case Q_TYPE_ITD: 121 case Q_TYPE_ITD:
122 usecs += q->itd->usecs [uframe]; 122 if (q->itd->hw_transaction[uframe])
123 usecs += q->itd->stream->usecs;
123 hw_p = &q->itd->hw_next; 124 hw_p = &q->itd->hw_next;
124 q = &q->itd->itd_next; 125 q = &q->itd->itd_next;
125 break; 126 break;
@@ -211,7 +212,7 @@ static inline void carryover_tt_bandwidth(unsigned short tt_usecs[8])
211 * low/fullspeed transfer can "carry over" from one uframe to the next, 212 * low/fullspeed transfer can "carry over" from one uframe to the next,
212 * since the TT just performs downstream transfers in sequence. 213 * since the TT just performs downstream transfers in sequence.
213 * 214 *
214 * For example two seperate 100 usec transfers can start in the same uframe, 215 * For example two separate 100 usec transfers can start in the same uframe,
215 * and the second one would "carry over" 75 usecs into the next uframe. 216 * and the second one would "carry over" 75 usecs into the next uframe.
216 */ 217 */
217static void 218static void
@@ -1536,7 +1537,6 @@ itd_link_urb (
1536 uframe = next_uframe & 0x07; 1537 uframe = next_uframe & 0x07;
1537 frame = next_uframe >> 3; 1538 frame = next_uframe >> 3;
1538 1539
1539 itd->usecs [uframe] = stream->usecs;
1540 itd_patch(ehci, itd, iso_sched, packet, uframe); 1540 itd_patch(ehci, itd, iso_sched, packet, uframe);
1541 1541
1542 next_uframe += stream->interval; 1542 next_uframe += stream->interval;
@@ -1565,6 +1565,16 @@ itd_link_urb (
1565 1565
1566#define ISO_ERRS (EHCI_ISOC_BUF_ERR | EHCI_ISOC_BABBLE | EHCI_ISOC_XACTERR) 1566#define ISO_ERRS (EHCI_ISOC_BUF_ERR | EHCI_ISOC_BABBLE | EHCI_ISOC_XACTERR)
1567 1567
1568/* Process and recycle a completed ITD. Return true iff its urb completed,
1569 * and hence its completion callback probably added things to the hardware
1570 * schedule.
1571 *
1572 * Note that we carefully avoid recycling this descriptor until after any
1573 * completion callback runs, so that it won't be reused quickly. That is,
1574 * assuming (a) no more than two urbs per frame on this endpoint, and also
1575 * (b) only this endpoint's completions submit URBs. It seems some silicon
1576 * corrupts things if you reuse completed descriptors very quickly...
1577 */
1568static unsigned 1578static unsigned
1569itd_complete ( 1579itd_complete (
1570 struct ehci_hcd *ehci, 1580 struct ehci_hcd *ehci,
@@ -1577,6 +1587,7 @@ itd_complete (
1577 int urb_index = -1; 1587 int urb_index = -1;
1578 struct ehci_iso_stream *stream = itd->stream; 1588 struct ehci_iso_stream *stream = itd->stream;
1579 struct usb_device *dev; 1589 struct usb_device *dev;
1590 unsigned retval = false;
1580 1591
1581 /* for each uframe with a packet */ 1592 /* for each uframe with a packet */
1582 for (uframe = 0; uframe < 8; uframe++) { 1593 for (uframe = 0; uframe < 8; uframe++) {
@@ -1610,30 +1621,21 @@ itd_complete (
1610 } 1621 }
1611 } 1622 }
1612 1623
1613 usb_put_urb (urb);
1614 itd->urb = NULL;
1615 itd->stream = NULL;
1616 list_move (&itd->itd_list, &stream->free_list);
1617 iso_stream_put (ehci, stream);
1618
1619 /* handle completion now? */ 1624 /* handle completion now? */
1620 if (likely ((urb_index + 1) != urb->number_of_packets)) 1625 if (likely ((urb_index + 1) != urb->number_of_packets))
1621 return 0; 1626 goto done;
1622 1627
1623 /* ASSERT: it's really the last itd for this urb 1628 /* ASSERT: it's really the last itd for this urb
1624 list_for_each_entry (itd, &stream->td_list, itd_list) 1629 list_for_each_entry (itd, &stream->td_list, itd_list)
1625 BUG_ON (itd->urb == urb); 1630 BUG_ON (itd->urb == urb);
1626 */ 1631 */
1627 1632
1628 /* give urb back to the driver ... can be out-of-order */ 1633 /* give urb back to the driver; completion often (re)submits */
1629 dev = urb->dev; 1634 dev = urb->dev;
1630 ehci_urb_done(ehci, urb, 0); 1635 ehci_urb_done(ehci, urb, 0);
1636 retval = true;
1631 urb = NULL; 1637 urb = NULL;
1632
1633 /* defer stopping schedule; completion can submit */
1634 ehci->periodic_sched--; 1638 ehci->periodic_sched--;
1635 if (unlikely (!ehci->periodic_sched))
1636 (void) disable_periodic (ehci);
1637 ehci_to_hcd(ehci)->self.bandwidth_isoc_reqs--; 1639 ehci_to_hcd(ehci)->self.bandwidth_isoc_reqs--;
1638 1640
1639 if (unlikely (list_empty (&stream->td_list))) { 1641 if (unlikely (list_empty (&stream->td_list))) {
@@ -1645,8 +1647,15 @@ itd_complete (
1645 (stream->bEndpointAddress & USB_DIR_IN) ? "in" : "out"); 1647 (stream->bEndpointAddress & USB_DIR_IN) ? "in" : "out");
1646 } 1648 }
1647 iso_stream_put (ehci, stream); 1649 iso_stream_put (ehci, stream);
1650 /* OK to recycle this ITD now that its completion callback ran. */
1651done:
1652 usb_put_urb(urb);
1653 itd->urb = NULL;
1654 itd->stream = NULL;
1655 list_move(&itd->itd_list, &stream->free_list);
1656 iso_stream_put(ehci, stream);
1648 1657
1649 return 1; 1658 return retval;
1650} 1659}
1651 1660
1652/*-------------------------------------------------------------------------*/ 1661/*-------------------------------------------------------------------------*/
@@ -1712,8 +1721,6 @@ done:
1712 return status; 1721 return status;
1713} 1722}
1714 1723
1715#ifdef CONFIG_USB_EHCI_SPLIT_ISO
1716
1717/*-------------------------------------------------------------------------*/ 1724/*-------------------------------------------------------------------------*/
1718 1725
1719/* 1726/*
@@ -1950,6 +1957,16 @@ sitd_link_urb (
1950#define SITD_ERRS (SITD_STS_ERR | SITD_STS_DBE | SITD_STS_BABBLE \ 1957#define SITD_ERRS (SITD_STS_ERR | SITD_STS_DBE | SITD_STS_BABBLE \
1951 | SITD_STS_XACT | SITD_STS_MMF) 1958 | SITD_STS_XACT | SITD_STS_MMF)
1952 1959
1960/* Process and recycle a completed SITD. Return true iff its urb completed,
1961 * and hence its completion callback probably added things to the hardware
1962 * schedule.
1963 *
1964 * Note that we carefully avoid recycling this descriptor until after any
1965 * completion callback runs, so that it won't be reused quickly. That is,
1966 * assuming (a) no more than two urbs per frame on this endpoint, and also
1967 * (b) only this endpoint's completions submit URBs. It seems some silicon
1968 * corrupts things if you reuse completed descriptors very quickly...
1969 */
1953static unsigned 1970static unsigned
1954sitd_complete ( 1971sitd_complete (
1955 struct ehci_hcd *ehci, 1972 struct ehci_hcd *ehci,
@@ -1961,6 +1978,7 @@ sitd_complete (
1961 int urb_index = -1; 1978 int urb_index = -1;
1962 struct ehci_iso_stream *stream = sitd->stream; 1979 struct ehci_iso_stream *stream = sitd->stream;
1963 struct usb_device *dev; 1980 struct usb_device *dev;
1981 unsigned retval = false;
1964 1982
1965 urb_index = sitd->index; 1983 urb_index = sitd->index;
1966 desc = &urb->iso_frame_desc [urb_index]; 1984 desc = &urb->iso_frame_desc [urb_index];
@@ -1981,32 +1999,23 @@ sitd_complete (
1981 desc->status = 0; 1999 desc->status = 0;
1982 desc->actual_length = desc->length - SITD_LENGTH (t); 2000 desc->actual_length = desc->length - SITD_LENGTH (t);
1983 } 2001 }
1984
1985 usb_put_urb (urb);
1986 sitd->urb = NULL;
1987 sitd->stream = NULL;
1988 list_move (&sitd->sitd_list, &stream->free_list);
1989 stream->depth -= stream->interval << 3; 2002 stream->depth -= stream->interval << 3;
1990 iso_stream_put (ehci, stream);
1991 2003
1992 /* handle completion now? */ 2004 /* handle completion now? */
1993 if ((urb_index + 1) != urb->number_of_packets) 2005 if ((urb_index + 1) != urb->number_of_packets)
1994 return 0; 2006 goto done;
1995 2007
1996 /* ASSERT: it's really the last sitd for this urb 2008 /* ASSERT: it's really the last sitd for this urb
1997 list_for_each_entry (sitd, &stream->td_list, sitd_list) 2009 list_for_each_entry (sitd, &stream->td_list, sitd_list)
1998 BUG_ON (sitd->urb == urb); 2010 BUG_ON (sitd->urb == urb);
1999 */ 2011 */
2000 2012
2001 /* give urb back to the driver */ 2013 /* give urb back to the driver; completion often (re)submits */
2002 dev = urb->dev; 2014 dev = urb->dev;
2003 ehci_urb_done(ehci, urb, 0); 2015 ehci_urb_done(ehci, urb, 0);
2016 retval = true;
2004 urb = NULL; 2017 urb = NULL;
2005
2006 /* defer stopping schedule; completion can submit */
2007 ehci->periodic_sched--; 2018 ehci->periodic_sched--;
2008 if (!ehci->periodic_sched)
2009 (void) disable_periodic (ehci);
2010 ehci_to_hcd(ehci)->self.bandwidth_isoc_reqs--; 2019 ehci_to_hcd(ehci)->self.bandwidth_isoc_reqs--;
2011 2020
2012 if (list_empty (&stream->td_list)) { 2021 if (list_empty (&stream->td_list)) {
@@ -2018,8 +2027,15 @@ sitd_complete (
2018 (stream->bEndpointAddress & USB_DIR_IN) ? "in" : "out"); 2027 (stream->bEndpointAddress & USB_DIR_IN) ? "in" : "out");
2019 } 2028 }
2020 iso_stream_put (ehci, stream); 2029 iso_stream_put (ehci, stream);
2030 /* OK to recycle this SITD now that its completion callback ran. */
2031done:
2032 usb_put_urb(urb);
2033 sitd->urb = NULL;
2034 sitd->stream = NULL;
2035 list_move(&sitd->sitd_list, &stream->free_list);
2036 iso_stream_put(ehci, stream);
2021 2037
2022 return 1; 2038 return retval;
2023} 2039}
2024 2040
2025 2041
@@ -2082,26 +2098,6 @@ done:
2082 return status; 2098 return status;
2083} 2099}
2084 2100
2085#else
2086
2087static inline int
2088sitd_submit (struct ehci_hcd *ehci, struct urb *urb, gfp_t mem_flags)
2089{
2090 ehci_dbg (ehci, "split iso support is disabled\n");
2091 return -ENOSYS;
2092}
2093
2094static inline unsigned
2095sitd_complete (
2096 struct ehci_hcd *ehci,
2097 struct ehci_sitd *sitd
2098) {
2099 ehci_err (ehci, "sitd_complete %p?\n", sitd);
2100 return 0;
2101}
2102
2103#endif /* USB_EHCI_SPLIT_ISO */
2104
2105/*-------------------------------------------------------------------------*/ 2101/*-------------------------------------------------------------------------*/
2106 2102
2107static void 2103static void
@@ -2127,17 +2123,9 @@ scan_periodic (struct ehci_hcd *ehci)
2127 for (;;) { 2123 for (;;) {
2128 union ehci_shadow q, *q_p; 2124 union ehci_shadow q, *q_p;
2129 __hc32 type, *hw_p; 2125 __hc32 type, *hw_p;
2130 unsigned uframes; 2126 unsigned incomplete = false;
2131 2127
2132 /* don't scan past the live uframe */
2133 frame = now_uframe >> 3; 2128 frame = now_uframe >> 3;
2134 if (frame == (clock >> 3))
2135 uframes = now_uframe & 0x07;
2136 else {
2137 /* safe to scan the whole frame at once */
2138 now_uframe |= 0x07;
2139 uframes = 8;
2140 }
2141 2129
2142restart: 2130restart:
2143 /* scan each element in frame's queue for completions */ 2131 /* scan each element in frame's queue for completions */
@@ -2175,12 +2163,15 @@ restart:
2175 q = q.fstn->fstn_next; 2163 q = q.fstn->fstn_next;
2176 break; 2164 break;
2177 case Q_TYPE_ITD: 2165 case Q_TYPE_ITD:
2178 /* skip itds for later in the frame */ 2166 /* If this ITD is still active, leave it for
2167 * later processing ... check the next entry.
2168 */
2179 rmb (); 2169 rmb ();
2180 for (uf = live ? uframes : 8; uf < 8; uf++) { 2170 for (uf = 0; uf < 8 && live; uf++) {
2181 if (0 == (q.itd->hw_transaction [uf] 2171 if (0 == (q.itd->hw_transaction [uf]
2182 & ITD_ACTIVE(ehci))) 2172 & ITD_ACTIVE(ehci)))
2183 continue; 2173 continue;
2174 incomplete = true;
2184 q_p = &q.itd->itd_next; 2175 q_p = &q.itd->itd_next;
2185 hw_p = &q.itd->hw_next; 2176 hw_p = &q.itd->hw_next;
2186 type = Q_NEXT_TYPE(ehci, 2177 type = Q_NEXT_TYPE(ehci,
@@ -2188,10 +2179,12 @@ restart:
2188 q = *q_p; 2179 q = *q_p;
2189 break; 2180 break;
2190 } 2181 }
2191 if (uf != 8) 2182 if (uf < 8 && live)
2192 break; 2183 break;
2193 2184
2194 /* this one's ready ... HC won't cache the 2185 /* Take finished ITDs out of the schedule
2186 * and process them: recycle, maybe report
2187 * URB completion. HC won't cache the
2195 * pointer for much longer, if at all. 2188 * pointer for much longer, if at all.
2196 */ 2189 */
2197 *q_p = q.itd->itd_next; 2190 *q_p = q.itd->itd_next;
@@ -2202,8 +2195,12 @@ restart:
2202 q = *q_p; 2195 q = *q_p;
2203 break; 2196 break;
2204 case Q_TYPE_SITD: 2197 case Q_TYPE_SITD:
2198 /* If this SITD is still active, leave it for
2199 * later processing ... check the next entry.
2200 */
2205 if ((q.sitd->hw_results & SITD_ACTIVE(ehci)) 2201 if ((q.sitd->hw_results & SITD_ACTIVE(ehci))
2206 && live) { 2202 && live) {
2203 incomplete = true;
2207 q_p = &q.sitd->sitd_next; 2204 q_p = &q.sitd->sitd_next;
2208 hw_p = &q.sitd->hw_next; 2205 hw_p = &q.sitd->hw_next;
2209 type = Q_NEXT_TYPE(ehci, 2206 type = Q_NEXT_TYPE(ehci,
@@ -2211,6 +2208,11 @@ restart:
2211 q = *q_p; 2208 q = *q_p;
2212 break; 2209 break;
2213 } 2210 }
2211
2212 /* Take finished SITDs out of the schedule
2213 * and process them: recycle, maybe report
2214 * URB completion.
2215 */
2214 *q_p = q.sitd->sitd_next; 2216 *q_p = q.sitd->sitd_next;
2215 *hw_p = q.sitd->hw_next; 2217 *hw_p = q.sitd->hw_next;
2216 type = Q_NEXT_TYPE(ehci, q.sitd->hw_next); 2218 type = Q_NEXT_TYPE(ehci, q.sitd->hw_next);
@@ -2226,11 +2228,24 @@ restart:
2226 } 2228 }
2227 2229
2228 /* assume completion callbacks modify the queue */ 2230 /* assume completion callbacks modify the queue */
2229 if (unlikely (modified)) 2231 if (unlikely (modified)) {
2230 goto restart; 2232 if (likely(ehci->periodic_sched > 0))
2233 goto restart;
2234 /* maybe we can short-circuit this scan! */
2235 disable_periodic(ehci);
2236 now_uframe = clock;
2237 break;
2238 }
2231 } 2239 }
2232 2240
2233 /* stop when we catch up to the HC */ 2241 /* If we can tell we caught up to the hardware, stop now.
2242 * We can't advance our scan without collecting the ISO
2243 * transfers that are still pending in this frame.
2244 */
2245 if (incomplete && HC_IS_RUNNING(ehci_to_hcd(ehci)->state)) {
2246 ehci->next_uframe = now_uframe;
2247 break;
2248 }
2234 2249
2235 // FIXME: this assumes we won't get lapped when 2250 // FIXME: this assumes we won't get lapped when
2236 // latencies climb; that should be rare, but... 2251 // latencies climb; that should be rare, but...
@@ -2243,7 +2258,8 @@ restart:
2243 if (now_uframe == clock) { 2258 if (now_uframe == clock) {
2244 unsigned now; 2259 unsigned now;
2245 2260
2246 if (!HC_IS_RUNNING (ehci_to_hcd(ehci)->state)) 2261 if (!HC_IS_RUNNING (ehci_to_hcd(ehci)->state)
2262 || ehci->periodic_sched == 0)
2247 break; 2263 break;
2248 ehci->next_uframe = now_uframe; 2264 ehci->next_uframe = now_uframe;
2249 now = ehci_readl(ehci, &ehci->regs->frame_index) % mod; 2265 now = ehci_readl(ehci, &ehci->regs->frame_index) % mod;
diff --git a/drivers/usb/host/ehci.h b/drivers/usb/host/ehci.h
index 951d69fec513..bf92d209a1a9 100644
--- a/drivers/usb/host/ehci.h
+++ b/drivers/usb/host/ehci.h
@@ -74,7 +74,6 @@ struct ehci_hcd { /* one per controller */
74 /* async schedule support */ 74 /* async schedule support */
75 struct ehci_qh *async; 75 struct ehci_qh *async;
76 struct ehci_qh *reclaim; 76 struct ehci_qh *reclaim;
77 unsigned reclaim_ready : 1;
78 unsigned scanning : 1; 77 unsigned scanning : 1;
79 78
80 /* periodic schedule support */ 79 /* periodic schedule support */
@@ -105,6 +104,7 @@ struct ehci_hcd { /* one per controller */
105 struct dma_pool *itd_pool; /* itd per iso urb */ 104 struct dma_pool *itd_pool; /* itd per iso urb */
106 struct dma_pool *sitd_pool; /* sitd per split iso urb */ 105 struct dma_pool *sitd_pool; /* sitd per split iso urb */
107 106
107 struct timer_list iaa_watchdog;
108 struct timer_list watchdog; 108 struct timer_list watchdog;
109 unsigned long actions; 109 unsigned long actions;
110 unsigned stamp; 110 unsigned stamp;
@@ -127,6 +127,14 @@ struct ehci_hcd { /* one per controller */
127#else 127#else
128# define COUNT(x) do {} while (0) 128# define COUNT(x) do {} while (0)
129#endif 129#endif
130
131 /* debug files */
132#ifdef DEBUG
133 struct dentry *debug_dir;
134 struct dentry *debug_async;
135 struct dentry *debug_periodic;
136 struct dentry *debug_registers;
137#endif
130}; 138};
131 139
132/* convert between an HCD pointer and the corresponding EHCI_HCD */ 140/* convert between an HCD pointer and the corresponding EHCI_HCD */
@@ -140,9 +148,21 @@ static inline struct usb_hcd *ehci_to_hcd (struct ehci_hcd *ehci)
140} 148}
141 149
142 150
151static inline void
152iaa_watchdog_start(struct ehci_hcd *ehci)
153{
154 WARN_ON(timer_pending(&ehci->iaa_watchdog));
155 mod_timer(&ehci->iaa_watchdog,
156 jiffies + msecs_to_jiffies(EHCI_IAA_MSECS));
157}
158
159static inline void iaa_watchdog_done(struct ehci_hcd *ehci)
160{
161 del_timer(&ehci->iaa_watchdog);
162}
163
143enum ehci_timer_action { 164enum ehci_timer_action {
144 TIMER_IO_WATCHDOG, 165 TIMER_IO_WATCHDOG,
145 TIMER_IAA_WATCHDOG,
146 TIMER_ASYNC_SHRINK, 166 TIMER_ASYNC_SHRINK,
147 TIMER_ASYNC_OFF, 167 TIMER_ASYNC_OFF,
148}; 168};
@@ -160,9 +180,6 @@ timer_action (struct ehci_hcd *ehci, enum ehci_timer_action action)
160 unsigned long t; 180 unsigned long t;
161 181
162 switch (action) { 182 switch (action) {
163 case TIMER_IAA_WATCHDOG:
164 t = EHCI_IAA_JIFFIES;
165 break;
166 case TIMER_IO_WATCHDOG: 183 case TIMER_IO_WATCHDOG:
167 t = EHCI_IO_JIFFIES; 184 t = EHCI_IO_JIFFIES;
168 break; 185 break;
@@ -179,8 +196,7 @@ timer_action (struct ehci_hcd *ehci, enum ehci_timer_action action)
179 // async queue SHRINK often precedes IAA. while it's ready 196 // async queue SHRINK often precedes IAA. while it's ready
180 // to go OFF neither can matter, and afterwards the IO 197 // to go OFF neither can matter, and afterwards the IO
181 // watchdog stops unless there's still periodic traffic. 198 // watchdog stops unless there's still periodic traffic.
182 if (action != TIMER_IAA_WATCHDOG 199 if (time_before_eq(t, ehci->watchdog.expires)
183 && t > ehci->watchdog.expires
184 && timer_pending (&ehci->watchdog)) 200 && timer_pending (&ehci->watchdog))
185 return; 201 return;
186 mod_timer (&ehci->watchdog, t); 202 mod_timer (&ehci->watchdog, t);
@@ -534,8 +550,8 @@ struct ehci_iso_stream {
534 * trusting urb->interval == f(epdesc->bInterval) and 550 * trusting urb->interval == f(epdesc->bInterval) and
535 * including the extra info for hw_bufp[0..2] 551 * including the extra info for hw_bufp[0..2]
536 */ 552 */
537 u8 interval;
538 u8 usecs, c_usecs; 553 u8 usecs, c_usecs;
554 u16 interval;
539 u16 tt_usecs; 555 u16 tt_usecs;
540 u16 maxp; 556 u16 maxp;
541 u16 raw_mask; 557 u16 raw_mask;
@@ -586,7 +602,6 @@ struct ehci_itd {
586 unsigned frame; /* where scheduled */ 602 unsigned frame; /* where scheduled */
587 unsigned pg; 603 unsigned pg;
588 unsigned index[8]; /* in urb->iso_frame_desc */ 604 unsigned index[8]; /* in urb->iso_frame_desc */
589 u8 usecs[8];
590} __attribute__ ((aligned (32))); 605} __attribute__ ((aligned (32)));
591 606
592/*-------------------------------------------------------------------------*/ 607/*-------------------------------------------------------------------------*/
@@ -725,11 +740,16 @@ ehci_port_speed(struct ehci_hcd *ehci, unsigned int portsc)
725 * definition below can die once the 4xx support is 740 * definition below can die once the 4xx support is
726 * finally ported over. 741 * finally ported over.
727 */ 742 */
728#if defined(CONFIG_PPC) 743#if defined(CONFIG_PPC) && !defined(CONFIG_PPC_MERGE)
729#define readl_be(addr) in_be32((__force unsigned *)addr) 744#define readl_be(addr) in_be32((__force unsigned *)addr)
730#define writel_be(val, addr) out_be32((__force unsigned *)addr, val) 745#define writel_be(val, addr) out_be32((__force unsigned *)addr, val)
731#endif 746#endif
732 747
748#if defined(CONFIG_ARM) && defined(CONFIG_ARCH_IXP4XX)
749#define readl_be(addr) __raw_readl((__force unsigned *)addr)
750#define writel_be(val, addr) __raw_writel(val, (__force unsigned *)addr)
751#endif
752
733static inline unsigned int ehci_readl(const struct ehci_hcd *ehci, 753static inline unsigned int ehci_readl(const struct ehci_hcd *ehci,
734 __u32 __iomem * regs) 754 __u32 __iomem * regs)
735{ 755{
diff --git a/drivers/usb/host/isp116x-hcd.c b/drivers/usb/host/isp116x-hcd.c
index c27417f5b9d8..0130fd8571e4 100644
--- a/drivers/usb/host/isp116x-hcd.c
+++ b/drivers/usb/host/isp116x-hcd.c
@@ -918,7 +918,6 @@ static int isp116x_hub_status_data(struct usb_hcd *hcd, char *buf)
918 | RH_PS_OCIC | RH_PS_PRSC)) { 918 | RH_PS_OCIC | RH_PS_PRSC)) {
919 changed = 1; 919 changed = 1;
920 buf[0] |= 1 << (i + 1); 920 buf[0] |= 1 << (i + 1);
921 continue;
922 } 921 }
923 } 922 }
924 spin_unlock_irqrestore(&isp116x->lock, flags); 923 spin_unlock_irqrestore(&isp116x->lock, flags);
diff --git a/drivers/usb/host/ohci-at91.c b/drivers/usb/host/ohci-at91.c
index d849c809acbd..126fcbdd6408 100644
--- a/drivers/usb/host/ohci-at91.c
+++ b/drivers/usb/host/ohci-at91.c
@@ -17,6 +17,8 @@
17 17
18#include <asm/mach-types.h> 18#include <asm/mach-types.h>
19#include <asm/hardware.h> 19#include <asm/hardware.h>
20#include <asm/gpio.h>
21
20#include <asm/arch/board.h> 22#include <asm/arch/board.h>
21#include <asm/arch/cpu.h> 23#include <asm/arch/cpu.h>
22 24
@@ -271,12 +273,41 @@ static const struct hc_driver ohci_at91_hc_driver = {
271 273
272static int ohci_hcd_at91_drv_probe(struct platform_device *pdev) 274static int ohci_hcd_at91_drv_probe(struct platform_device *pdev)
273{ 275{
276 struct at91_usbh_data *pdata = pdev->dev.platform_data;
277 int i;
278
279 if (pdata) {
280 /* REVISIT make the driver support per-port power switching,
281 * and also overcurrent detection. Here we assume the ports
282 * are always powered while this driver is active, and use
283 * active-low power switches.
284 */
285 for (i = 0; i < pdata->ports; i++) {
286 if (pdata->vbus_pin[i] <= 0)
287 continue;
288 gpio_request(pdata->vbus_pin[i], "ohci_vbus");
289 gpio_direction_output(pdata->vbus_pin[i], 0);
290 }
291 }
292
274 device_init_wakeup(&pdev->dev, 1); 293 device_init_wakeup(&pdev->dev, 1);
275 return usb_hcd_at91_probe(&ohci_at91_hc_driver, pdev); 294 return usb_hcd_at91_probe(&ohci_at91_hc_driver, pdev);
276} 295}
277 296
278static int ohci_hcd_at91_drv_remove(struct platform_device *pdev) 297static int ohci_hcd_at91_drv_remove(struct platform_device *pdev)
279{ 298{
299 struct at91_usbh_data *pdata = pdev->dev.platform_data;
300 int i;
301
302 if (pdata) {
303 for (i = 0; i < pdata->ports; i++) {
304 if (pdata->vbus_pin[i] <= 0)
305 continue;
306 gpio_direction_output(pdata->vbus_pin[i], 1);
307 gpio_free(pdata->vbus_pin[i]);
308 }
309 }
310
280 device_init_wakeup(&pdev->dev, 0); 311 device_init_wakeup(&pdev->dev, 0);
281 return usb_hcd_at91_remove(platform_get_drvdata(pdev), pdev); 312 return usb_hcd_at91_remove(platform_get_drvdata(pdev), pdev);
282} 313}
diff --git a/drivers/usb/host/ohci-dbg.c b/drivers/usb/host/ohci-dbg.c
index ebab5ce8f5ce..a22c30aa745d 100644
--- a/drivers/usb/host/ohci-dbg.c
+++ b/drivers/usb/host/ohci-dbg.c
@@ -401,6 +401,42 @@ static inline void remove_debug_files (struct ohci_hcd *bus) { }
401 401
402#else 402#else
403 403
404static int debug_async_open(struct inode *, struct file *);
405static int debug_periodic_open(struct inode *, struct file *);
406static int debug_registers_open(struct inode *, struct file *);
407static int debug_async_open(struct inode *, struct file *);
408static ssize_t debug_output(struct file*, char __user*, size_t, loff_t*);
409static int debug_close(struct inode *, struct file *);
410
411static const struct file_operations debug_async_fops = {
412 .owner = THIS_MODULE,
413 .open = debug_async_open,
414 .read = debug_output,
415 .release = debug_close,
416};
417static const struct file_operations debug_periodic_fops = {
418 .owner = THIS_MODULE,
419 .open = debug_periodic_open,
420 .read = debug_output,
421 .release = debug_close,
422};
423static const struct file_operations debug_registers_fops = {
424 .owner = THIS_MODULE,
425 .open = debug_registers_open,
426 .read = debug_output,
427 .release = debug_close,
428};
429
430static struct dentry *ohci_debug_root;
431
432struct debug_buffer {
433 ssize_t (*fill_func)(struct debug_buffer *); /* fill method */
434 struct device *dev;
435 struct mutex mutex; /* protect filling of buffer */
436 size_t count; /* number of characters filled into buffer */
437 char *page;
438};
439
404static ssize_t 440static ssize_t
405show_list (struct ohci_hcd *ohci, char *buf, size_t count, struct ed *ed) 441show_list (struct ohci_hcd *ohci, char *buf, size_t count, struct ed *ed)
406{ 442{
@@ -467,8 +503,7 @@ show_list (struct ohci_hcd *ohci, char *buf, size_t count, struct ed *ed)
467 return count - size; 503 return count - size;
468} 504}
469 505
470static ssize_t 506static ssize_t fill_async_buffer(struct debug_buffer *buf)
471show_async (struct class_device *class_dev, char *buf)
472{ 507{
473 struct usb_bus *bus; 508 struct usb_bus *bus;
474 struct usb_hcd *hcd; 509 struct usb_hcd *hcd;
@@ -476,25 +511,23 @@ show_async (struct class_device *class_dev, char *buf)
476 size_t temp; 511 size_t temp;
477 unsigned long flags; 512 unsigned long flags;
478 513
479 bus = class_get_devdata(class_dev); 514 bus = dev_get_drvdata(buf->dev);
480 hcd = bus_to_hcd(bus); 515 hcd = bus_to_hcd(bus);
481 ohci = hcd_to_ohci(hcd); 516 ohci = hcd_to_ohci(hcd);
482 517
483 /* display control and bulk lists together, for simplicity */ 518 /* display control and bulk lists together, for simplicity */
484 spin_lock_irqsave (&ohci->lock, flags); 519 spin_lock_irqsave (&ohci->lock, flags);
485 temp = show_list (ohci, buf, PAGE_SIZE, ohci->ed_controltail); 520 temp = show_list(ohci, buf->page, buf->count, ohci->ed_controltail);
486 temp += show_list (ohci, buf + temp, PAGE_SIZE - temp, ohci->ed_bulktail); 521 temp += show_list(ohci, buf->page + temp, buf->count - temp,
522 ohci->ed_bulktail);
487 spin_unlock_irqrestore (&ohci->lock, flags); 523 spin_unlock_irqrestore (&ohci->lock, flags);
488 524
489 return temp; 525 return temp;
490} 526}
491static CLASS_DEVICE_ATTR (async, S_IRUGO, show_async, NULL);
492
493 527
494#define DBG_SCHED_LIMIT 64 528#define DBG_SCHED_LIMIT 64
495 529
496static ssize_t 530static ssize_t fill_periodic_buffer(struct debug_buffer *buf)
497show_periodic (struct class_device *class_dev, char *buf)
498{ 531{
499 struct usb_bus *bus; 532 struct usb_bus *bus;
500 struct usb_hcd *hcd; 533 struct usb_hcd *hcd;
@@ -509,10 +542,10 @@ show_periodic (struct class_device *class_dev, char *buf)
509 return 0; 542 return 0;
510 seen_count = 0; 543 seen_count = 0;
511 544
512 bus = class_get_devdata(class_dev); 545 bus = (struct usb_bus *)dev_get_drvdata(buf->dev);
513 hcd = bus_to_hcd(bus); 546 hcd = bus_to_hcd(bus);
514 ohci = hcd_to_ohci(hcd); 547 ohci = hcd_to_ohci(hcd);
515 next = buf; 548 next = buf->page;
516 size = PAGE_SIZE; 549 size = PAGE_SIZE;
517 550
518 temp = scnprintf (next, size, "size = %d\n", NUM_INTS); 551 temp = scnprintf (next, size, "size = %d\n", NUM_INTS);
@@ -589,13 +622,9 @@ show_periodic (struct class_device *class_dev, char *buf)
589 622
590 return PAGE_SIZE - size; 623 return PAGE_SIZE - size;
591} 624}
592static CLASS_DEVICE_ATTR (periodic, S_IRUGO, show_periodic, NULL);
593
594
595#undef DBG_SCHED_LIMIT 625#undef DBG_SCHED_LIMIT
596 626
597static ssize_t 627static ssize_t fill_registers_buffer(struct debug_buffer *buf)
598show_registers (struct class_device *class_dev, char *buf)
599{ 628{
600 struct usb_bus *bus; 629 struct usb_bus *bus;
601 struct usb_hcd *hcd; 630 struct usb_hcd *hcd;
@@ -606,11 +635,11 @@ show_registers (struct class_device *class_dev, char *buf)
606 char *next; 635 char *next;
607 u32 rdata; 636 u32 rdata;
608 637
609 bus = class_get_devdata(class_dev); 638 bus = (struct usb_bus *)dev_get_drvdata(buf->dev);
610 hcd = bus_to_hcd(bus); 639 hcd = bus_to_hcd(bus);
611 ohci = hcd_to_ohci(hcd); 640 ohci = hcd_to_ohci(hcd);
612 regs = ohci->regs; 641 regs = ohci->regs;
613 next = buf; 642 next = buf->page;
614 size = PAGE_SIZE; 643 size = PAGE_SIZE;
615 644
616 spin_lock_irqsave (&ohci->lock, flags); 645 spin_lock_irqsave (&ohci->lock, flags);
@@ -677,29 +706,155 @@ show_registers (struct class_device *class_dev, char *buf)
677 706
678done: 707done:
679 spin_unlock_irqrestore (&ohci->lock, flags); 708 spin_unlock_irqrestore (&ohci->lock, flags);
709
680 return PAGE_SIZE - size; 710 return PAGE_SIZE - size;
681} 711}
682static CLASS_DEVICE_ATTR (registers, S_IRUGO, show_registers, NULL);
683 712
713static struct debug_buffer *alloc_buffer(struct device *dev,
714 ssize_t (*fill_func)(struct debug_buffer *))
715{
716 struct debug_buffer *buf;
717
718 buf = kzalloc(sizeof(struct debug_buffer), GFP_KERNEL);
684 719
720 if (buf) {
721 buf->dev = dev;
722 buf->fill_func = fill_func;
723 mutex_init(&buf->mutex);
724 }
725
726 return buf;
727}
728
729static int fill_buffer(struct debug_buffer *buf)
730{
731 int ret = 0;
732
733 if (!buf->page)
734 buf->page = (char *)get_zeroed_page(GFP_KERNEL);
735
736 if (!buf->page) {
737 ret = -ENOMEM;
738 goto out;
739 }
740
741 ret = buf->fill_func(buf);
742
743 if (ret >= 0) {
744 buf->count = ret;
745 ret = 0;
746 }
747
748out:
749 return ret;
750}
751
752static ssize_t debug_output(struct file *file, char __user *user_buf,
753 size_t len, loff_t *offset)
754{
755 struct debug_buffer *buf = file->private_data;
756 int ret = 0;
757
758 mutex_lock(&buf->mutex);
759 if (buf->count == 0) {
760 ret = fill_buffer(buf);
761 if (ret != 0) {
762 mutex_unlock(&buf->mutex);
763 goto out;
764 }
765 }
766 mutex_unlock(&buf->mutex);
767
768 ret = simple_read_from_buffer(user_buf, len, offset,
769 buf->page, buf->count);
770
771out:
772 return ret;
773
774}
775
776static int debug_close(struct inode *inode, struct file *file)
777{
778 struct debug_buffer *buf = file->private_data;
779
780 if (buf) {
781 if (buf->page)
782 free_page((unsigned long)buf->page);
783 kfree(buf);
784 }
785
786 return 0;
787}
788static int debug_async_open(struct inode *inode, struct file *file)
789{
790 file->private_data = alloc_buffer(inode->i_private, fill_async_buffer);
791
792 return file->private_data ? 0 : -ENOMEM;
793}
794
795static int debug_periodic_open(struct inode *inode, struct file *file)
796{
797 file->private_data = alloc_buffer(inode->i_private,
798 fill_periodic_buffer);
799
800 return file->private_data ? 0 : -ENOMEM;
801}
802
803static int debug_registers_open(struct inode *inode, struct file *file)
804{
805 file->private_data = alloc_buffer(inode->i_private,
806 fill_registers_buffer);
807
808 return file->private_data ? 0 : -ENOMEM;
809}
685static inline void create_debug_files (struct ohci_hcd *ohci) 810static inline void create_debug_files (struct ohci_hcd *ohci)
686{ 811{
687 struct class_device *cldev = ohci_to_hcd(ohci)->self.class_dev; 812 struct usb_bus *bus = &ohci_to_hcd(ohci)->self;
688 int retval; 813 struct device *dev = bus->dev;
814
815 ohci->debug_dir = debugfs_create_dir(bus->bus_name, ohci_debug_root);
816 if (!ohci->debug_dir)
817 goto dir_error;
818
819 ohci->debug_async = debugfs_create_file("async", S_IRUGO,
820 ohci->debug_dir, dev,
821 &debug_async_fops);
822 if (!ohci->debug_async)
823 goto async_error;
824
825 ohci->debug_periodic = debugfs_create_file("periodic", S_IRUGO,
826 ohci->debug_dir, dev,
827 &debug_periodic_fops);
828 if (!ohci->debug_periodic)
829 goto periodic_error;
830
831 ohci->debug_registers = debugfs_create_file("registers", S_IRUGO,
832 ohci->debug_dir, dev,
833 &debug_registers_fops);
834 if (!ohci->debug_registers)
835 goto registers_error;
689 836
690 retval = class_device_create_file(cldev, &class_device_attr_async);
691 retval = class_device_create_file(cldev, &class_device_attr_periodic);
692 retval = class_device_create_file(cldev, &class_device_attr_registers);
693 ohci_dbg (ohci, "created debug files\n"); 837 ohci_dbg (ohci, "created debug files\n");
838 return;
839
840registers_error:
841 debugfs_remove(ohci->debug_periodic);
842periodic_error:
843 debugfs_remove(ohci->debug_async);
844async_error:
845 debugfs_remove(ohci->debug_dir);
846dir_error:
847 ohci->debug_periodic = NULL;
848 ohci->debug_async = NULL;
849 ohci->debug_dir = NULL;
694} 850}
695 851
696static inline void remove_debug_files (struct ohci_hcd *ohci) 852static inline void remove_debug_files (struct ohci_hcd *ohci)
697{ 853{
698 struct class_device *cldev = ohci_to_hcd(ohci)->self.class_dev; 854 debugfs_remove(ohci->debug_registers);
699 855 debugfs_remove(ohci->debug_periodic);
700 class_device_remove_file(cldev, &class_device_attr_async); 856 debugfs_remove(ohci->debug_async);
701 class_device_remove_file(cldev, &class_device_attr_periodic); 857 debugfs_remove(ohci->debug_dir);
702 class_device_remove_file(cldev, &class_device_attr_registers);
703} 858}
704 859
705#endif 860#endif
diff --git a/drivers/usb/host/ohci-hcd.c b/drivers/usb/host/ohci-hcd.c
index ddd4ee1f2413..dd4798ee028e 100644
--- a/drivers/usb/host/ohci-hcd.c
+++ b/drivers/usb/host/ohci-hcd.c
@@ -36,6 +36,7 @@
36#include <linux/dmapool.h> 36#include <linux/dmapool.h>
37#include <linux/reboot.h> 37#include <linux/reboot.h>
38#include <linux/workqueue.h> 38#include <linux/workqueue.h>
39#include <linux/debugfs.h>
39 40
40#include <asm/io.h> 41#include <asm/io.h>
41#include <asm/irq.h> 42#include <asm/irq.h>
@@ -809,13 +810,9 @@ static irqreturn_t ohci_irq (struct usb_hcd *hcd)
809 } 810 }
810 811
811 if (ints & OHCI_INTR_WDH) { 812 if (ints & OHCI_INTR_WDH) {
812 if (HC_IS_RUNNING(hcd->state))
813 ohci_writel (ohci, OHCI_INTR_WDH, &regs->intrdisable);
814 spin_lock (&ohci->lock); 813 spin_lock (&ohci->lock);
815 dl_done_list (ohci); 814 dl_done_list (ohci);
816 spin_unlock (&ohci->lock); 815 spin_unlock (&ohci->lock);
817 if (HC_IS_RUNNING(hcd->state))
818 ohci_writel (ohci, OHCI_INTR_WDH, &regs->intrenable);
819 } 816 }
820 817
821 if (quirk_zfmicro(ohci) && (ints & OHCI_INTR_SF)) { 818 if (quirk_zfmicro(ohci) && (ints & OHCI_INTR_SF)) {
@@ -1032,6 +1029,13 @@ MODULE_LICENSE ("GPL");
1032#define PLATFORM_DRIVER usb_hcd_pnx4008_driver 1029#define PLATFORM_DRIVER usb_hcd_pnx4008_driver
1033#endif 1030#endif
1034 1031
1032#if defined(CONFIG_CPU_SUBTYPE_SH7720) || \
1033 defined(CONFIG_CPU_SUBTYPE_SH7721) || \
1034 defined(CONFIG_CPU_SUBTYPE_SH7763)
1035#include "ohci-sh.c"
1036#define PLATFORM_DRIVER ohci_hcd_sh_driver
1037#endif
1038
1035 1039
1036#ifdef CONFIG_USB_OHCI_HCD_PPC_OF 1040#ifdef CONFIG_USB_OHCI_HCD_PPC_OF
1037#include "ohci-ppc-of.c" 1041#include "ohci-ppc-of.c"
@@ -1048,6 +1052,11 @@ MODULE_LICENSE ("GPL");
1048#define SSB_OHCI_DRIVER ssb_ohci_driver 1052#define SSB_OHCI_DRIVER ssb_ohci_driver
1049#endif 1053#endif
1050 1054
1055#ifdef CONFIG_MFD_SM501
1056#include "ohci-sm501.c"
1057#define PLATFORM_DRIVER ohci_hcd_sm501_driver
1058#endif
1059
1051#if !defined(PCI_DRIVER) && \ 1060#if !defined(PCI_DRIVER) && \
1052 !defined(PLATFORM_DRIVER) && \ 1061 !defined(PLATFORM_DRIVER) && \
1053 !defined(OF_PLATFORM_DRIVER) && \ 1062 !defined(OF_PLATFORM_DRIVER) && \
@@ -1068,6 +1077,14 @@ static int __init ohci_hcd_mod_init(void)
1068 pr_debug ("%s: block sizes: ed %Zd td %Zd\n", hcd_name, 1077 pr_debug ("%s: block sizes: ed %Zd td %Zd\n", hcd_name,
1069 sizeof (struct ed), sizeof (struct td)); 1078 sizeof (struct ed), sizeof (struct td));
1070 1079
1080#ifdef DEBUG
1081 ohci_debug_root = debugfs_create_dir("ohci", NULL);
1082 if (!ohci_debug_root) {
1083 retval = -ENOENT;
1084 goto error_debug;
1085 }
1086#endif
1087
1071#ifdef PS3_SYSTEM_BUS_DRIVER 1088#ifdef PS3_SYSTEM_BUS_DRIVER
1072 retval = ps3_ohci_driver_register(&PS3_SYSTEM_BUS_DRIVER); 1089 retval = ps3_ohci_driver_register(&PS3_SYSTEM_BUS_DRIVER);
1073 if (retval < 0) 1090 if (retval < 0)
@@ -1130,6 +1147,12 @@ static int __init ohci_hcd_mod_init(void)
1130 ps3_ohci_driver_unregister(&PS3_SYSTEM_BUS_DRIVER); 1147 ps3_ohci_driver_unregister(&PS3_SYSTEM_BUS_DRIVER);
1131 error_ps3: 1148 error_ps3:
1132#endif 1149#endif
1150#ifdef DEBUG
1151 debugfs_remove(ohci_debug_root);
1152 ohci_debug_root = NULL;
1153 error_debug:
1154#endif
1155
1133 return retval; 1156 return retval;
1134} 1157}
1135module_init(ohci_hcd_mod_init); 1158module_init(ohci_hcd_mod_init);
@@ -1154,6 +1177,9 @@ static void __exit ohci_hcd_mod_exit(void)
1154#ifdef PS3_SYSTEM_BUS_DRIVER 1177#ifdef PS3_SYSTEM_BUS_DRIVER
1155 ps3_ohci_driver_unregister(&PS3_SYSTEM_BUS_DRIVER); 1178 ps3_ohci_driver_unregister(&PS3_SYSTEM_BUS_DRIVER);
1156#endif 1179#endif
1180#ifdef DEBUG
1181 debugfs_remove(ohci_debug_root);
1182#endif
1157} 1183}
1158module_exit(ohci_hcd_mod_exit); 1184module_exit(ohci_hcd_mod_exit);
1159 1185
diff --git a/drivers/usb/host/ohci-sh.c b/drivers/usb/host/ohci-sh.c
new file mode 100644
index 000000000000..5309ac039e15
--- /dev/null
+++ b/drivers/usb/host/ohci-sh.c
@@ -0,0 +1,143 @@
1/*
2 * OHCI HCD (Host Controller Driver) for USB.
3 *
4 * Copyright (C) 2008 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/platform_device.h>
24
25static int ohci_sh_start(struct usb_hcd *hcd)
26{
27 struct ohci_hcd *ohci = hcd_to_ohci(hcd);
28
29 ohci_hcd_init(ohci);
30 ohci_init(ohci);
31 ohci_run(ohci);
32 hcd->state = HC_STATE_RUNNING;
33 return 0;
34}
35
36static const struct hc_driver ohci_sh_hc_driver = {
37 .description = hcd_name,
38 .product_desc = "SuperH OHCI",
39 .hcd_priv_size = sizeof(struct ohci_hcd),
40
41 /*
42 * generic hardware linkage
43 */
44 .irq = ohci_irq,
45 .flags = HCD_USB11 | HCD_MEMORY,
46
47 /*
48 * basic lifecycle operations
49 */
50 .start = ohci_sh_start,
51 .stop = ohci_stop,
52 .shutdown = ohci_shutdown,
53
54 /*
55 * managing i/o requests and associated device resources
56 */
57 .urb_enqueue = ohci_urb_enqueue,
58 .urb_dequeue = ohci_urb_dequeue,
59 .endpoint_disable = ohci_endpoint_disable,
60
61 /*
62 * scheduling support
63 */
64 .get_frame_number = ohci_get_frame,
65
66 /*
67 * root hub support
68 */
69 .hub_status_data = ohci_hub_status_data,
70 .hub_control = ohci_hub_control,
71 .hub_irq_enable = ohci_rhsc_enable,
72#ifdef CONFIG_PM
73 .bus_suspend = ohci_bus_suspend,
74 .bus_resume = ohci_bus_resume,
75#endif
76 .start_port_reset = ohci_start_port_reset,
77};
78
79/*-------------------------------------------------------------------------*/
80
81#define resource_len(r) (((r)->end - (r)->start) + 1)
82static int ohci_hcd_sh_probe(struct platform_device *pdev)
83{
84 struct resource *res = NULL;
85 struct usb_hcd *hcd = NULL;
86 int irq = -1;
87 int ret;
88
89 if (usb_disabled())
90 return -ENODEV;
91
92 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
93 if (!res) {
94 err("platform_get_resource error.");
95 return -ENODEV;
96 }
97
98 irq = platform_get_irq(pdev, 0);
99 if (irq < 0) {
100 err("platform_get_irq error.");
101 return -ENODEV;
102 }
103
104 /* initialize hcd */
105 hcd = usb_create_hcd(&ohci_sh_hc_driver, &pdev->dev, (char *)hcd_name);
106 if (!hcd) {
107 err("Failed to create hcd");
108 return -ENOMEM;
109 }
110
111 hcd->regs = (void __iomem *)res->start;
112 hcd->rsrc_start = res->start;
113 hcd->rsrc_len = resource_len(res);
114 ret = usb_add_hcd(hcd, irq, IRQF_DISABLED);
115 if (ret != 0) {
116 err("Failed to add hcd");
117 usb_put_hcd(hcd);
118 return ret;
119 }
120
121 return ret;
122}
123
124static int ohci_hcd_sh_remove(struct platform_device *pdev)
125{
126 struct usb_hcd *hcd = platform_get_drvdata(pdev);
127
128 usb_remove_hcd(hcd);
129 usb_put_hcd(hcd);
130
131 return 0;
132}
133
134static struct platform_driver ohci_hcd_sh_driver = {
135 .probe = ohci_hcd_sh_probe,
136 .remove = ohci_hcd_sh_remove,
137 .shutdown = usb_hcd_platform_shutdown,
138 .driver = {
139 .name = "sh_ohci",
140 .owner = THIS_MODULE,
141 },
142};
143
diff --git a/drivers/usb/host/ohci-sm501.c b/drivers/usb/host/ohci-sm501.c
new file mode 100644
index 000000000000..a97070142869
--- /dev/null
+++ b/drivers/usb/host/ohci-sm501.c
@@ -0,0 +1,264 @@
1/*
2 * OHCI HCD (Host Controller Driver) for USB.
3 *
4 * (C) Copyright 1999 Roman Weissgaerber <weissg@vienna.at>
5 * (C) Copyright 2000-2005 David Brownell
6 * (C) Copyright 2002 Hewlett-Packard Company
7 * (C) Copyright 2008 Magnus Damm
8 *
9 * SM501 Bus Glue - based on ohci-omap.c
10 *
11 * This file is licenced under the GPL.
12 */
13
14#include <linux/interrupt.h>
15#include <linux/jiffies.h>
16#include <linux/platform_device.h>
17#include <linux/dma-mapping.h>
18#include <linux/sm501.h>
19#include <linux/sm501-regs.h>
20
21static int ohci_sm501_init(struct usb_hcd *hcd)
22{
23 return ohci_init(hcd_to_ohci(hcd));
24}
25
26static int ohci_sm501_start(struct usb_hcd *hcd)
27{
28 struct device *dev = hcd->self.controller;
29 int ret;
30
31 ret = ohci_run(hcd_to_ohci(hcd));
32 if (ret < 0) {
33 dev_err(dev, "can't start %s", hcd->self.bus_name);
34 ohci_stop(hcd);
35 }
36
37 return ret;
38}
39
40/*-------------------------------------------------------------------------*/
41
42static const struct hc_driver ohci_sm501_hc_driver = {
43 .description = hcd_name,
44 .product_desc = "SM501 OHCI",
45 .hcd_priv_size = sizeof(struct ohci_hcd),
46
47 /*
48 * generic hardware linkage
49 */
50 .irq = ohci_irq,
51 .flags = HCD_USB11 | HCD_MEMORY | HCD_LOCAL_MEM,
52
53 /*
54 * basic lifecycle operations
55 */
56 .reset = ohci_sm501_init,
57 .start = ohci_sm501_start,
58 .stop = ohci_stop,
59 .shutdown = ohci_shutdown,
60
61 /*
62 * managing i/o requests and associated device resources
63 */
64 .urb_enqueue = ohci_urb_enqueue,
65 .urb_dequeue = ohci_urb_dequeue,
66 .endpoint_disable = ohci_endpoint_disable,
67
68 /*
69 * scheduling support
70 */
71 .get_frame_number = ohci_get_frame,
72
73 /*
74 * root hub support
75 */
76 .hub_status_data = ohci_hub_status_data,
77 .hub_control = ohci_hub_control,
78 .hub_irq_enable = ohci_rhsc_enable,
79#ifdef CONFIG_PM
80 .bus_suspend = ohci_bus_suspend,
81 .bus_resume = ohci_bus_resume,
82#endif
83 .start_port_reset = ohci_start_port_reset,
84};
85
86/*-------------------------------------------------------------------------*/
87
88static int ohci_hcd_sm501_drv_probe(struct platform_device *pdev)
89{
90 const struct hc_driver *driver = &ohci_sm501_hc_driver;
91 struct device *dev = &pdev->dev;
92 struct resource *res, *mem;
93 int retval, irq;
94 struct usb_hcd *hcd = 0;
95
96 irq = retval = platform_get_irq(pdev, 0);
97 if (retval < 0)
98 goto err0;
99
100 mem = platform_get_resource(pdev, IORESOURCE_MEM, 1);
101 if (mem == NULL) {
102 dev_err(dev, "no resource definition for memory\n");
103 retval = -ENOENT;
104 goto err0;
105 }
106
107 if (!request_mem_region(mem->start, mem->end - mem->start + 1,
108 pdev->name)) {
109 dev_err(dev, "request_mem_region failed\n");
110 retval = -EBUSY;
111 goto err0;
112 }
113
114 /* The sm501 chip is equipped with local memory that may be used
115 * by on-chip devices such as the video controller and the usb host.
116 * This driver uses dma_declare_coherent_memory() to make sure
117 * usb allocations with dma_alloc_coherent() allocate from
118 * this local memory. The dma_handle returned by dma_alloc_coherent()
119 * will be an offset starting from 0 for the first local memory byte.
120 *
121 * So as long as data is allocated using dma_alloc_coherent() all is
122 * fine. This is however not always the case - buffers may be allocated
123 * using kmalloc() - so the usb core needs to be told that it must copy
124 * data into our local memory if the buffers happen to be placed in
125 * regular memory. The HCD_LOCAL_MEM flag does just that.
126 */
127
128 if (!dma_declare_coherent_memory(dev, mem->start,
129 mem->start - mem->parent->start,
130 (mem->end - mem->start) + 1,
131 DMA_MEMORY_MAP |
132 DMA_MEMORY_EXCLUSIVE)) {
133 dev_err(dev, "cannot declare coherent memory\n");
134 retval = -ENXIO;
135 goto err1;
136 }
137
138 /* allocate, reserve and remap resources for registers */
139 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
140 if (res == NULL) {
141 dev_err(dev, "no resource definition for registers\n");
142 retval = -ENOENT;
143 goto err2;
144 }
145
146 hcd = usb_create_hcd(driver, &pdev->dev, pdev->dev.bus_id);
147 if (!hcd) {
148 retval = -ENOMEM;
149 goto err2;
150 }
151
152 hcd->rsrc_start = res->start;
153 hcd->rsrc_len = res->end - res->start + 1;
154
155 if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, pdev->name)) {
156 dev_err(dev, "request_mem_region failed\n");
157 retval = -EBUSY;
158 goto err3;
159 }
160
161 hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
162 if (hcd->regs == NULL) {
163 dev_err(dev, "cannot remap registers\n");
164 retval = -ENXIO;
165 goto err4;
166 }
167
168 ohci_hcd_init(hcd_to_ohci(hcd));
169
170 retval = usb_add_hcd(hcd, irq, IRQF_DISABLED | IRQF_SHARED);
171 if (retval)
172 goto err4;
173
174 /* enable power and unmask interrupts */
175
176 sm501_unit_power(dev->parent, SM501_GATE_USB_HOST, 1);
177 sm501_modify_reg(dev->parent, SM501_IRQ_MASK, 1 << 6, 0);
178
179 return 0;
180err4:
181 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
182err3:
183 usb_put_hcd(hcd);
184err2:
185 dma_release_declared_memory(dev);
186err1:
187 release_mem_region(mem->start, mem->end - mem->start + 1);
188err0:
189 return retval;
190}
191
192static int ohci_hcd_sm501_drv_remove(struct platform_device *pdev)
193{
194 struct usb_hcd *hcd = platform_get_drvdata(pdev);
195 struct resource *mem;
196
197 usb_remove_hcd(hcd);
198 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
199 usb_put_hcd(hcd);
200 dma_release_declared_memory(&pdev->dev);
201 mem = platform_get_resource(pdev, IORESOURCE_MEM, 1);
202 release_mem_region(mem->start, mem->end - mem->start + 1);
203
204 /* mask interrupts and disable power */
205
206 sm501_modify_reg(pdev->dev.parent, SM501_IRQ_MASK, 0, 1 << 6);
207 sm501_unit_power(pdev->dev.parent, SM501_GATE_USB_HOST, 0);
208
209 platform_set_drvdata(pdev, NULL);
210 return 0;
211}
212
213/*-------------------------------------------------------------------------*/
214
215#ifdef CONFIG_PM
216static int ohci_sm501_suspend(struct platform_device *pdev, pm_message_t msg)
217{
218 struct device *dev = &pdev->dev;
219 struct ohci_hcd *ohci = hcd_to_ohci(platform_get_drvdata(pdev));
220
221 if (time_before(jiffies, ohci->next_statechange))
222 msleep(5);
223 ohci->next_statechange = jiffies;
224
225 sm501_unit_power(dev->parent, SM501_GATE_USB_HOST, 0);
226 ohci_to_hcd(ohci)->state = HC_STATE_SUSPENDED;
227 dev->power.power_state = PMSG_SUSPEND;
228 return 0;
229}
230
231static int ohci_sm501_resume(struct platform_device *pdev)
232{
233 struct device *dev = &pdev->dev;
234 struct ohci_hcd *ohci = hcd_to_ohci(platform_get_drvdata(pdev));
235
236 if (time_before(jiffies, ohci->next_statechange))
237 msleep(5);
238 ohci->next_statechange = jiffies;
239
240 sm501_unit_power(dev->parent, SM501_GATE_USB_HOST, 1);
241 dev->power.power_state = PMSG_ON;
242 usb_hcd_resume_root_hub(platform_get_drvdata(pdev));
243 return 0;
244}
245#endif
246
247/*-------------------------------------------------------------------------*/
248
249/*
250 * Driver definition to register with the SM501 bus
251 */
252static struct platform_driver ohci_hcd_sm501_driver = {
253 .probe = ohci_hcd_sm501_drv_probe,
254 .remove = ohci_hcd_sm501_drv_remove,
255 .shutdown = usb_hcd_platform_shutdown,
256#ifdef CONFIG_PM
257 .suspend = ohci_sm501_suspend,
258 .resume = ohci_sm501_resume,
259#endif
260 .driver = {
261 .owner = THIS_MODULE,
262 .name = "sm501-usb",
263 },
264};
diff --git a/drivers/usb/host/ohci.h b/drivers/usb/host/ohci.h
index 47c5c66a282c..dc544ddc7849 100644
--- a/drivers/usb/host/ohci.h
+++ b/drivers/usb/host/ohci.h
@@ -408,6 +408,13 @@ struct ohci_hcd {
408 unsigned eds_scheduled; 408 unsigned eds_scheduled;
409 struct ed *ed_to_check; 409 struct ed *ed_to_check;
410 unsigned zf_delay; 410 unsigned zf_delay;
411
412#ifdef DEBUG
413 struct dentry *debug_dir;
414 struct dentry *debug_async;
415 struct dentry *debug_periodic;
416 struct dentry *debug_registers;
417#endif
411}; 418};
412 419
413#ifdef CONFIG_PCI 420#ifdef CONFIG_PCI
diff --git a/drivers/usb/host/r8a66597.h b/drivers/usb/host/r8a66597.h
index fe9ceb077d9b..57388252b693 100644
--- a/drivers/usb/host/r8a66597.h
+++ b/drivers/usb/host/r8a66597.h
@@ -405,7 +405,7 @@
405 405
406struct r8a66597_pipe_info { 406struct r8a66597_pipe_info {
407 u16 pipenum; 407 u16 pipenum;
408 u16 address; /* R8A66597 HCD usb addres */ 408 u16 address; /* R8A66597 HCD usb address */
409 u16 epnum; 409 u16 epnum;
410 u16 maxpacket; 410 u16 maxpacket;
411 u16 type; 411 u16 type;
diff --git a/drivers/usb/image/mdc800.c b/drivers/usb/image/mdc800.c
index d1131a87a5b1..0fb114ca1eba 100644
--- a/drivers/usb/image/mdc800.c
+++ b/drivers/usb/image/mdc800.c
@@ -478,8 +478,6 @@ static int mdc800_usb_probe (struct usb_interface *intf,
478 { 478 {
479 irq_interval=intf_desc->endpoint [j].desc.bInterval; 479 irq_interval=intf_desc->endpoint [j].desc.bInterval;
480 } 480 }
481
482 continue;
483 } 481 }
484 } 482 }
485 if (mdc800->endpoint[i] == -1) 483 if (mdc800->endpoint[i] == -1)
diff --git a/drivers/usb/misc/cypress_cy7c63.c b/drivers/usb/misc/cypress_cy7c63.c
index d721380b242d..937940404b7a 100644
--- a/drivers/usb/misc/cypress_cy7c63.c
+++ b/drivers/usb/misc/cypress_cy7c63.c
@@ -1,7 +1,7 @@
1/* 1/*
2* cypress_cy7c63.c 2* cypress_cy7c63.c
3* 3*
4* Copyright (c) 2006 Oliver Bock (o.bock@fh-wolfenbuettel.de) 4* Copyright (c) 2006-2007 Oliver Bock (bock@tfh-berlin.de)
5* 5*
6* This driver is based on the Cypress USB Driver by Marcus Maul 6* This driver is based on the Cypress USB Driver by Marcus Maul
7* (cyport) and the 2.0 version of Greg Kroah-Hartman's 7* (cyport) and the 2.0 version of Greg Kroah-Hartman's
@@ -21,6 +21,9 @@
21* Supported functions: Read/Write Ports 21* Supported functions: Read/Write Ports
22* 22*
23* 23*
24* For up-to-date information please visit:
25* http://www.obock.de/kernel/cypress
26*
24* This program is free software; you can redistribute it and/or 27* This program is free software; you can redistribute it and/or
25* modify it under the terms of the GNU General Public License as 28* modify it under the terms of the GNU General Public License as
26* published by the Free Software Foundation, version 2. 29* published by the Free Software Foundation, version 2.
@@ -31,7 +34,7 @@
31#include <linux/kernel.h> 34#include <linux/kernel.h>
32#include <linux/usb.h> 35#include <linux/usb.h>
33 36
34#define DRIVER_AUTHOR "Oliver Bock (o.bock@fh-wolfenbuettel.de)" 37#define DRIVER_AUTHOR "Oliver Bock (bock@tfh-berlin.de)"
35#define DRIVER_DESC "Cypress CY7C63xxx USB driver" 38#define DRIVER_DESC "Cypress CY7C63xxx USB driver"
36 39
37#define CYPRESS_VENDOR_ID 0xa2c 40#define CYPRESS_VENDOR_ID 0xa2c
diff --git a/drivers/usb/misc/iowarrior.c b/drivers/usb/misc/iowarrior.c
index 764696ff1e8e..801070502cc1 100644
--- a/drivers/usb/misc/iowarrior.c
+++ b/drivers/usb/misc/iowarrior.c
@@ -715,7 +715,7 @@ static unsigned iowarrior_poll(struct file *file, poll_table * wait)
715 * would use "struct net_driver" instead, and a serial 715 * would use "struct net_driver" instead, and a serial
716 * device would use "struct tty_driver". 716 * device would use "struct tty_driver".
717 */ 717 */
718static struct file_operations iowarrior_fops = { 718static const struct file_operations iowarrior_fops = {
719 .owner = THIS_MODULE, 719 .owner = THIS_MODULE,
720 .write = iowarrior_write, 720 .write = iowarrior_write,
721 .read = iowarrior_read, 721 .read = iowarrior_read,
diff --git a/drivers/usb/misc/legousbtower.c b/drivers/usb/misc/legousbtower.c
index aab320085ebf..6664043f4645 100644
--- a/drivers/usb/misc/legousbtower.c
+++ b/drivers/usb/misc/legousbtower.c
@@ -205,7 +205,7 @@ static DEFINE_MUTEX(open_disc_mutex);
205 205
206/* Structure to hold all of our device specific stuff */ 206/* Structure to hold all of our device specific stuff */
207struct lego_usb_tower { 207struct lego_usb_tower {
208 struct semaphore sem; /* locks this structure */ 208 struct mutex lock; /* locks this structure */
209 struct usb_device* udev; /* save off the usb device pointer */ 209 struct usb_device* udev; /* save off the usb device pointer */
210 unsigned char minor; /* the starting minor number for this device */ 210 unsigned char minor; /* the starting minor number for this device */
211 211
@@ -361,7 +361,7 @@ static int tower_open (struct inode *inode, struct file *file)
361 } 361 }
362 362
363 /* lock this device */ 363 /* lock this device */
364 if (down_interruptible (&dev->sem)) { 364 if (mutex_lock_interruptible(&dev->lock)) {
365 mutex_unlock(&open_disc_mutex); 365 mutex_unlock(&open_disc_mutex);
366 retval = -ERESTARTSYS; 366 retval = -ERESTARTSYS;
367 goto exit; 367 goto exit;
@@ -421,7 +421,7 @@ static int tower_open (struct inode *inode, struct file *file)
421 file->private_data = dev; 421 file->private_data = dev;
422 422
423unlock_exit: 423unlock_exit:
424 up (&dev->sem); 424 mutex_unlock(&dev->lock);
425 425
426exit: 426exit:
427 dbg(2, "%s: leave, return value %d ", __FUNCTION__, retval); 427 dbg(2, "%s: leave, return value %d ", __FUNCTION__, retval);
@@ -448,7 +448,7 @@ static int tower_release (struct inode *inode, struct file *file)
448 } 448 }
449 449
450 mutex_lock(&open_disc_mutex); 450 mutex_lock(&open_disc_mutex);
451 if (down_interruptible (&dev->sem)) { 451 if (mutex_lock_interruptible(&dev->lock)) {
452 retval = -ERESTARTSYS; 452 retval = -ERESTARTSYS;
453 goto exit; 453 goto exit;
454 } 454 }
@@ -460,7 +460,9 @@ static int tower_release (struct inode *inode, struct file *file)
460 } 460 }
461 if (dev->udev == NULL) { 461 if (dev->udev == NULL) {
462 /* the device was unplugged before the file was released */ 462 /* the device was unplugged before the file was released */
463 up (&dev->sem); /* unlock here as tower_delete frees dev */ 463
464 /* unlock here as tower_delete frees dev */
465 mutex_unlock(&dev->lock);
464 tower_delete (dev); 466 tower_delete (dev);
465 goto exit; 467 goto exit;
466 } 468 }
@@ -473,7 +475,7 @@ static int tower_release (struct inode *inode, struct file *file)
473 dev->open_count = 0; 475 dev->open_count = 0;
474 476
475unlock_exit: 477unlock_exit:
476 up (&dev->sem); 478 mutex_unlock(&dev->lock);
477 479
478exit: 480exit:
479 mutex_unlock(&open_disc_mutex); 481 mutex_unlock(&open_disc_mutex);
@@ -586,7 +588,7 @@ static ssize_t tower_read (struct file *file, char __user *buffer, size_t count,
586 dev = (struct lego_usb_tower *)file->private_data; 588 dev = (struct lego_usb_tower *)file->private_data;
587 589
588 /* lock this object */ 590 /* lock this object */
589 if (down_interruptible (&dev->sem)) { 591 if (mutex_lock_interruptible(&dev->lock)) {
590 retval = -ERESTARTSYS; 592 retval = -ERESTARTSYS;
591 goto exit; 593 goto exit;
592 } 594 }
@@ -653,7 +655,7 @@ static ssize_t tower_read (struct file *file, char __user *buffer, size_t count,
653 655
654unlock_exit: 656unlock_exit:
655 /* unlock the device */ 657 /* unlock the device */
656 up (&dev->sem); 658 mutex_unlock(&dev->lock);
657 659
658exit: 660exit:
659 dbg(2, "%s: leave, return value %d", __FUNCTION__, retval); 661 dbg(2, "%s: leave, return value %d", __FUNCTION__, retval);
@@ -675,7 +677,7 @@ static ssize_t tower_write (struct file *file, const char __user *buffer, size_t
675 dev = (struct lego_usb_tower *)file->private_data; 677 dev = (struct lego_usb_tower *)file->private_data;
676 678
677 /* lock this object */ 679 /* lock this object */
678 if (down_interruptible (&dev->sem)) { 680 if (mutex_lock_interruptible(&dev->lock)) {
679 retval = -ERESTARTSYS; 681 retval = -ERESTARTSYS;
680 goto exit; 682 goto exit;
681 } 683 }
@@ -737,7 +739,7 @@ static ssize_t tower_write (struct file *file, const char __user *buffer, size_t
737 739
738unlock_exit: 740unlock_exit:
739 /* unlock the device */ 741 /* unlock the device */
740 up (&dev->sem); 742 mutex_unlock(&dev->lock);
741 743
742exit: 744exit:
743 dbg(2, "%s: leave, return value %d", __FUNCTION__, retval); 745 dbg(2, "%s: leave, return value %d", __FUNCTION__, retval);
@@ -862,7 +864,7 @@ static int tower_probe (struct usb_interface *interface, const struct usb_device
862 goto exit; 864 goto exit;
863 } 865 }
864 866
865 init_MUTEX (&dev->sem); 867 mutex_init(&dev->lock);
866 868
867 dev->udev = udev; 869 dev->udev = udev;
868 dev->open_count = 0; 870 dev->open_count = 0;
@@ -1007,16 +1009,16 @@ static void tower_disconnect (struct usb_interface *interface)
1007 /* give back our minor */ 1009 /* give back our minor */
1008 usb_deregister_dev (interface, &tower_class); 1010 usb_deregister_dev (interface, &tower_class);
1009 1011
1010 down (&dev->sem); 1012 mutex_lock(&dev->lock);
1011 mutex_unlock(&open_disc_mutex); 1013 mutex_unlock(&open_disc_mutex);
1012 1014
1013 /* if the device is not opened, then we clean up right now */ 1015 /* if the device is not opened, then we clean up right now */
1014 if (!dev->open_count) { 1016 if (!dev->open_count) {
1015 up (&dev->sem); 1017 mutex_unlock(&dev->lock);
1016 tower_delete (dev); 1018 tower_delete (dev);
1017 } else { 1019 } else {
1018 dev->udev = NULL; 1020 dev->udev = NULL;
1019 up (&dev->sem); 1021 mutex_unlock(&dev->lock);
1020 } 1022 }
1021 1023
1022 info("LEGO USB Tower #%d now disconnected", (minor - LEGO_USB_TOWER_MINOR_BASE)); 1024 info("LEGO USB Tower #%d now disconnected", (minor - LEGO_USB_TOWER_MINOR_BASE));
diff --git a/drivers/usb/misc/sisusbvga/sisusb.c b/drivers/usb/misc/sisusbvga/sisusb.c
index 9244d067cec1..cb7fa0eaf3ae 100644
--- a/drivers/usb/misc/sisusbvga/sisusb.c
+++ b/drivers/usb/misc/sisusbvga/sisusb.c
@@ -323,7 +323,7 @@ sisusb_bulkin_msg(struct sisusb_usb_data *sisusb, unsigned int pipe, void *data,
323 usb_kill_urb(urb); 323 usb_kill_urb(urb);
324 retval = -ETIMEDOUT; 324 retval = -ETIMEDOUT;
325 } else { 325 } else {
326 /* URB completed within timout */ 326 /* URB completed within timeout */
327 retval = urb->status; 327 retval = urb->status;
328 readbytes = urb->actual_length; 328 readbytes = urb->actual_length;
329 } 329 }
@@ -3195,20 +3195,6 @@ static int sisusb_probe(struct usb_interface *intf,
3195 3195
3196 sisusb->present = 1; 3196 sisusb->present = 1;
3197 3197
3198#ifdef SISUSB_OLD_CONFIG_COMPAT
3199 {
3200 int ret;
3201 /* Our ioctls are all "32/64bit compatible" */
3202 ret = register_ioctl32_conversion(SISUSB_GET_CONFIG_SIZE, NULL);
3203 ret |= register_ioctl32_conversion(SISUSB_GET_CONFIG, NULL);
3204 ret |= register_ioctl32_conversion(SISUSB_COMMAND, NULL);
3205 if (ret)
3206 dev_err(&sisusb->sisusb_dev->dev, "Error registering ioctl32 translations\n");
3207 else
3208 sisusb->ioctl32registered = 1;
3209 }
3210#endif
3211
3212 if (dev->speed == USB_SPEED_HIGH) { 3198 if (dev->speed == USB_SPEED_HIGH) {
3213 int initscreen = 1; 3199 int initscreen = 1;
3214#ifdef INCL_SISUSB_CON 3200#ifdef INCL_SISUSB_CON
@@ -3271,19 +3257,6 @@ static void sisusb_disconnect(struct usb_interface *intf)
3271 3257
3272 usb_set_intfdata(intf, NULL); 3258 usb_set_intfdata(intf, NULL);
3273 3259
3274#ifdef SISUSB_OLD_CONFIG_COMPAT
3275 if (sisusb->ioctl32registered) {
3276 int ret;
3277 sisusb->ioctl32registered = 0;
3278 ret = unregister_ioctl32_conversion(SISUSB_GET_CONFIG_SIZE);
3279 ret |= unregister_ioctl32_conversion(SISUSB_GET_CONFIG);
3280 ret |= unregister_ioctl32_conversion(SISUSB_COMMAND);
3281 if (ret) {
3282 dev_err(&sisusb->sisusb_dev->dev, "Error unregistering ioctl32 translations\n");
3283 }
3284 }
3285#endif
3286
3287 sisusb->present = 0; 3260 sisusb->present = 0;
3288 sisusb->ready = 0; 3261 sisusb->ready = 0;
3289 3262
diff --git a/drivers/usb/misc/sisusbvga/sisusb.h b/drivers/usb/misc/sisusbvga/sisusb.h
index d2d7872cd022..cf0b4a5883f6 100644
--- a/drivers/usb/misc/sisusbvga/sisusb.h
+++ b/drivers/usb/misc/sisusbvga/sisusb.h
@@ -120,9 +120,6 @@ struct sisusb_usb_data {
120 int isopen; /* !=0 if open */ 120 int isopen; /* !=0 if open */
121 int present; /* !=0 if device is present on the bus */ 121 int present; /* !=0 if device is present on the bus */
122 int ready; /* !=0 if device is ready for userland */ 122 int ready; /* !=0 if device is ready for userland */
123#ifdef SISUSB_OLD_CONFIG_COMPAT
124 int ioctl32registered;
125#endif
126 int numobufs; /* number of obufs = number of out urbs */ 123 int numobufs; /* number of obufs = number of out urbs */
127 char *obuf[NUMOBUFS], *ibuf; /* transfer buffers */ 124 char *obuf[NUMOBUFS], *ibuf; /* transfer buffers */
128 int obufsize, ibufsize; 125 int obufsize, ibufsize;
diff --git a/drivers/usb/misc/usbtest.c b/drivers/usb/misc/usbtest.c
index ea3162146481..da922dfc0dcc 100644
--- a/drivers/usb/misc/usbtest.c
+++ b/drivers/usb/misc/usbtest.c
@@ -6,6 +6,7 @@
6#include <linux/module.h> 6#include <linux/module.h>
7#include <linux/moduleparam.h> 7#include <linux/moduleparam.h>
8#include <linux/scatterlist.h> 8#include <linux/scatterlist.h>
9#include <linux/mutex.h>
9 10
10#include <linux/usb.h> 11#include <linux/usb.h>
11 12
@@ -64,7 +65,7 @@ struct usbtest_dev {
64 int in_iso_pipe; 65 int in_iso_pipe;
65 int out_iso_pipe; 66 int out_iso_pipe;
66 struct usb_endpoint_descriptor *iso_in, *iso_out; 67 struct usb_endpoint_descriptor *iso_in, *iso_out;
67 struct semaphore sem; 68 struct mutex lock;
68 69
69#define TBUF_SIZE 256 70#define TBUF_SIZE 256
70 u8 *buf; 71 u8 *buf;
@@ -1151,6 +1152,7 @@ static int verify_halted (int ep, struct urb *urb)
1151 dbg ("ep %02x couldn't get halt status, %d", ep, retval); 1152 dbg ("ep %02x couldn't get halt status, %d", ep, retval);
1152 return retval; 1153 return retval;
1153 } 1154 }
1155 le16_to_cpus(&status);
1154 if (status != 1) { 1156 if (status != 1) {
1155 dbg ("ep %02x bogus status: %04x != 1", ep, status); 1157 dbg ("ep %02x bogus status: %04x != 1", ep, status);
1156 return -EINVAL; 1158 return -EINVAL;
@@ -1310,7 +1312,7 @@ static int ctrl_out (struct usbtest_dev *dev,
1310 len += vary; 1312 len += vary;
1311 1313
1312 /* [real world] the "zero bytes IN" case isn't really used. 1314 /* [real world] the "zero bytes IN" case isn't really used.
1313 * hardware can easily trip up in this wierd case, since its 1315 * hardware can easily trip up in this weird case, since its
1314 * status stage is IN, not OUT like other ep0in transfers. 1316 * status stage is IN, not OUT like other ep0in transfers.
1315 */ 1317 */
1316 if (len > length) 1318 if (len > length)
@@ -1558,11 +1560,11 @@ usbtest_ioctl (struct usb_interface *intf, unsigned int code, void *buf)
1558 || param->sglen < 0 || param->vary < 0) 1560 || param->sglen < 0 || param->vary < 0)
1559 return -EINVAL; 1561 return -EINVAL;
1560 1562
1561 if (down_interruptible (&dev->sem)) 1563 if (mutex_lock_interruptible(&dev->lock))
1562 return -ERESTARTSYS; 1564 return -ERESTARTSYS;
1563 1565
1564 if (intf->dev.power.power_state.event != PM_EVENT_ON) { 1566 if (intf->dev.power.power_state.event != PM_EVENT_ON) {
1565 up (&dev->sem); 1567 mutex_unlock(&dev->lock);
1566 return -EHOSTUNREACH; 1568 return -EHOSTUNREACH;
1567 } 1569 }
1568 1570
@@ -1574,7 +1576,7 @@ usbtest_ioctl (struct usb_interface *intf, unsigned int code, void *buf)
1574 int res; 1576 int res;
1575 1577
1576 if (intf->altsetting->desc.bInterfaceNumber) { 1578 if (intf->altsetting->desc.bInterfaceNumber) {
1577 up (&dev->sem); 1579 mutex_unlock(&dev->lock);
1578 return -ENODEV; 1580 return -ENODEV;
1579 } 1581 }
1580 res = set_altsetting (dev, dev->info->alt); 1582 res = set_altsetting (dev, dev->info->alt);
@@ -1582,7 +1584,7 @@ usbtest_ioctl (struct usb_interface *intf, unsigned int code, void *buf)
1582 dev_err (&intf->dev, 1584 dev_err (&intf->dev,
1583 "set altsetting to %d failed, %d\n", 1585 "set altsetting to %d failed, %d\n",
1584 dev->info->alt, res); 1586 dev->info->alt, res);
1585 up (&dev->sem); 1587 mutex_unlock(&dev->lock);
1586 return res; 1588 return res;
1587 } 1589 }
1588 } 1590 }
@@ -1855,7 +1857,7 @@ usbtest_ioctl (struct usb_interface *intf, unsigned int code, void *buf)
1855 param->duration.tv_usec += 1000 * 1000; 1857 param->duration.tv_usec += 1000 * 1000;
1856 param->duration.tv_sec -= 1; 1858 param->duration.tv_sec -= 1;
1857 } 1859 }
1858 up (&dev->sem); 1860 mutex_unlock(&dev->lock);
1859 return retval; 1861 return retval;
1860} 1862}
1861 1863
@@ -1905,7 +1907,7 @@ usbtest_probe (struct usb_interface *intf, const struct usb_device_id *id)
1905 return -ENOMEM; 1907 return -ENOMEM;
1906 info = (struct usbtest_info *) id->driver_info; 1908 info = (struct usbtest_info *) id->driver_info;
1907 dev->info = info; 1909 dev->info = info;
1908 init_MUTEX (&dev->sem); 1910 mutex_init(&dev->lock);
1909 1911
1910 dev->intf = intf; 1912 dev->intf = intf;
1911 1913
@@ -1990,8 +1992,6 @@ static void usbtest_disconnect (struct usb_interface *intf)
1990{ 1992{
1991 struct usbtest_dev *dev = usb_get_intfdata (intf); 1993 struct usbtest_dev *dev = usb_get_intfdata (intf);
1992 1994
1993 down (&dev->sem);
1994
1995 usb_set_intfdata (intf, NULL); 1995 usb_set_intfdata (intf, NULL);
1996 dev_dbg (&intf->dev, "disconnect\n"); 1996 dev_dbg (&intf->dev, "disconnect\n");
1997 kfree (dev); 1997 kfree (dev);
diff --git a/drivers/usb/mon/mon_bin.c b/drivers/usb/mon/mon_bin.c
index f06e4e2b49d3..1774ba5c4c3b 100644
--- a/drivers/usb/mon/mon_bin.c
+++ b/drivers/usb/mon/mon_bin.c
@@ -1026,6 +1026,8 @@ mon_bin_poll(struct file *file, struct poll_table_struct *wait)
1026 return mask; 1026 return mask;
1027} 1027}
1028 1028
1029#if 0
1030
1029/* 1031/*
1030 * open and close: just keep track of how many times the device is 1032 * open and close: just keep track of how many times the device is
1031 * mapped, to use the proper memory allocation function. 1033 * mapped, to use the proper memory allocation function.
@@ -1045,33 +1047,31 @@ static void mon_bin_vma_close(struct vm_area_struct *vma)
1045/* 1047/*
1046 * Map ring pages to user space. 1048 * Map ring pages to user space.
1047 */ 1049 */
1048struct page *mon_bin_vma_nopage(struct vm_area_struct *vma, 1050static int mon_bin_vma_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
1049 unsigned long address, int *type)
1050{ 1051{
1051 struct mon_reader_bin *rp = vma->vm_private_data; 1052 struct mon_reader_bin *rp = vma->vm_private_data;
1052 unsigned long offset, chunk_idx; 1053 unsigned long offset, chunk_idx;
1053 struct page *pageptr; 1054 struct page *pageptr;
1054 1055
1055 offset = (address - vma->vm_start) + (vma->vm_pgoff << PAGE_SHIFT); 1056 offset = vmf->pgoff << PAGE_SHIFT;
1056 if (offset >= rp->b_size) 1057 if (offset >= rp->b_size)
1057 return NOPAGE_SIGBUS; 1058 return VM_FAULT_SIGBUS;
1058 chunk_idx = offset / CHUNK_SIZE; 1059 chunk_idx = offset / CHUNK_SIZE;
1059 pageptr = rp->b_vec[chunk_idx].pg; 1060 pageptr = rp->b_vec[chunk_idx].pg;
1060 get_page(pageptr); 1061 get_page(pageptr);
1061 if (type) 1062 vmf->page = pageptr;
1062 *type = VM_FAULT_MINOR; 1063 return 0;
1063 return pageptr;
1064} 1064}
1065 1065
1066struct vm_operations_struct mon_bin_vm_ops = { 1066struct vm_operations_struct mon_bin_vm_ops = {
1067 .open = mon_bin_vma_open, 1067 .open = mon_bin_vma_open,
1068 .close = mon_bin_vma_close, 1068 .close = mon_bin_vma_close,
1069 .nopage = mon_bin_vma_nopage, 1069 .fault = mon_bin_vma_fault,
1070}; 1070};
1071 1071
1072int mon_bin_mmap(struct file *filp, struct vm_area_struct *vma) 1072int mon_bin_mmap(struct file *filp, struct vm_area_struct *vma)
1073{ 1073{
1074 /* don't do anything here: "nopage" will set up page table entries */ 1074 /* don't do anything here: "fault" will set up page table entries */
1075 vma->vm_ops = &mon_bin_vm_ops; 1075 vma->vm_ops = &mon_bin_vm_ops;
1076 vma->vm_flags |= VM_RESERVED; 1076 vma->vm_flags |= VM_RESERVED;
1077 vma->vm_private_data = filp->private_data; 1077 vma->vm_private_data = filp->private_data;
@@ -1079,7 +1079,9 @@ int mon_bin_mmap(struct file *filp, struct vm_area_struct *vma)
1079 return 0; 1079 return 0;
1080} 1080}
1081 1081
1082struct file_operations mon_fops_binary = { 1082#endif /* 0 */
1083
1084static const struct file_operations mon_fops_binary = {
1083 .owner = THIS_MODULE, 1085 .owner = THIS_MODULE,
1084 .open = mon_bin_open, 1086 .open = mon_bin_open,
1085 .llseek = no_llseek, 1087 .llseek = no_llseek,
diff --git a/drivers/usb/serial/Kconfig b/drivers/usb/serial/Kconfig
index 4a86696e6c7d..c1e65dfd9353 100644
--- a/drivers/usb/serial/Kconfig
+++ b/drivers/usb/serial/Kconfig
@@ -2,10 +2,7 @@
2# USB Serial device configuration 2# USB Serial device configuration
3# 3#
4 4
5menu "USB Serial Converter support" 5menuconfig USB_SERIAL
6 depends on USB!=n
7
8config USB_SERIAL
9 tristate "USB Serial Converter support" 6 tristate "USB Serial Converter support"
10 depends on USB 7 depends on USB
11 ---help--- 8 ---help---
@@ -20,6 +17,8 @@ config USB_SERIAL
20 To compile this driver as a module, choose M here: the 17 To compile this driver as a module, choose M here: the
21 module will be called usbserial. 18 module will be called usbserial.
22 19
20if USB_SERIAL
21
23config USB_SERIAL_CONSOLE 22config USB_SERIAL_CONSOLE
24 bool "USB Serial Console device support (EXPERIMENTAL)" 23 bool "USB Serial Console device support (EXPERIMENTAL)"
25 depends on USB_SERIAL=y && EXPERIMENTAL 24 depends on USB_SERIAL=y && EXPERIMENTAL
@@ -43,6 +42,12 @@ config USB_SERIAL_CONSOLE
43 42
44 If unsure, say N. 43 If unsure, say N.
45 44
45config USB_EZUSB
46 bool "Functions for loading firmware on EZUSB chips"
47 depends on USB_SERIAL
48 help
49 Say Y here if you need EZUSB device support.
50
46config USB_SERIAL_GENERIC 51config USB_SERIAL_GENERIC
47 bool "USB Generic Serial Driver" 52 bool "USB Generic Serial Driver"
48 depends on USB_SERIAL 53 depends on USB_SERIAL
@@ -105,6 +110,7 @@ config USB_SERIAL_CH341
105config USB_SERIAL_WHITEHEAT 110config USB_SERIAL_WHITEHEAT
106 tristate "USB ConnectTech WhiteHEAT Serial Driver" 111 tristate "USB ConnectTech WhiteHEAT Serial Driver"
107 depends on USB_SERIAL 112 depends on USB_SERIAL
113 select USB_EZUSB
108 help 114 help
109 Say Y here if you want to use a ConnectTech WhiteHEAT 4 port 115 Say Y here if you want to use a ConnectTech WhiteHEAT 4 port
110 USB to serial converter device. 116 USB to serial converter device.
@@ -282,9 +288,21 @@ config USB_SERIAL_IPW
282 To compile this driver as a module, choose M here: the 288 To compile this driver as a module, choose M here: the
283 module will be called ipw. 289 module will be called ipw.
284 290
291config USB_SERIAL_IUU
292 tristate "USB Infinity USB Unlimited Phoenix Driver (Experimental)"
293 depends on USB_SERIAL && EXPERIMENTAL
294 help
295 Say Y here if you want to use a IUU in phoenix mode and get
296 an extra ttyUSBx device. More information available on
297 http://eczema.ecze.com/iuu_phoenix.html
298
299 To compile this driver as a module, choose M here: the
300 module will be called iuu_phoenix.o
301
285config USB_SERIAL_KEYSPAN_PDA 302config USB_SERIAL_KEYSPAN_PDA
286 tristate "USB Keyspan PDA Single Port Serial Driver" 303 tristate "USB Keyspan PDA Single Port Serial Driver"
287 depends on USB_SERIAL 304 depends on USB_SERIAL
305 select USB_EZUSB
288 help 306 help
289 Say Y here if you want to use a Keyspan PDA single port USB to 307 Say Y here if you want to use a Keyspan PDA single port USB to
290 serial converter device. This driver makes use of firmware 308 serial converter device. This driver makes use of firmware
@@ -296,6 +314,7 @@ config USB_SERIAL_KEYSPAN_PDA
296config USB_SERIAL_KEYSPAN 314config USB_SERIAL_KEYSPAN
297 tristate "USB Keyspan USA-xxx Serial Driver" 315 tristate "USB Keyspan USA-xxx Serial Driver"
298 depends on USB_SERIAL 316 depends on USB_SERIAL
317 select USB_EZUSB
299 ---help--- 318 ---help---
300 Say Y here if you want to use Keyspan USB to serial converter 319 Say Y here if you want to use Keyspan USB to serial converter
301 devices. This driver makes use of Keyspan's official firmware 320 devices. This driver makes use of Keyspan's official firmware
@@ -538,6 +557,7 @@ config USB_SERIAL_CYBERJACK
538config USB_SERIAL_XIRCOM 557config USB_SERIAL_XIRCOM
539 tristate "USB Xircom / Entregra Single Port Serial Driver" 558 tristate "USB Xircom / Entregra Single Port Serial Driver"
540 depends on USB_SERIAL 559 depends on USB_SERIAL
560 select USB_EZUSB
541 help 561 help
542 Say Y here if you want to use a Xircom or Entregra single port USB to 562 Say Y here if you want to use a Xircom or Entregra single port USB to
543 serial converter device. This driver makes use of firmware 563 serial converter device. This driver makes use of firmware
@@ -585,11 +605,4 @@ config USB_SERIAL_DEBUG
585 To compile this driver as a module, choose M here: the 605 To compile this driver as a module, choose M here: the
586 module will be called usb-debug. 606 module will be called usb-debug.
587 607
588config USB_EZUSB 608endif # USB_SERIAL
589 bool
590 depends on USB_SERIAL_KEYSPAN_PDA || USB_SERIAL_XIRCOM || USB_SERIAL_KEYSPAN || USB_SERIAL_WHITEHEAT
591 default y
592
593
594endmenu
595
diff --git a/drivers/usb/serial/Makefile b/drivers/usb/serial/Makefile
index d6fb384e52b2..0db109a54d10 100644
--- a/drivers/usb/serial/Makefile
+++ b/drivers/usb/serial/Makefile
@@ -30,6 +30,7 @@ obj-$(CONFIG_USB_SERIAL_GARMIN) += garmin_gps.o
30obj-$(CONFIG_USB_SERIAL_HP4X) += hp4x.o 30obj-$(CONFIG_USB_SERIAL_HP4X) += hp4x.o
31obj-$(CONFIG_USB_SERIAL_IPAQ) += ipaq.o 31obj-$(CONFIG_USB_SERIAL_IPAQ) += ipaq.o
32obj-$(CONFIG_USB_SERIAL_IPW) += ipw.o 32obj-$(CONFIG_USB_SERIAL_IPW) += ipw.o
33obj-$(CONFIG_USB_SERIAL_IUU) += iuu_phoenix.o
33obj-$(CONFIG_USB_SERIAL_IR) += ir-usb.o 34obj-$(CONFIG_USB_SERIAL_IR) += ir-usb.o
34obj-$(CONFIG_USB_SERIAL_KEYSPAN) += keyspan.o 35obj-$(CONFIG_USB_SERIAL_KEYSPAN) += keyspan.o
35obj-$(CONFIG_USB_SERIAL_KEYSPAN_PDA) += keyspan_pda.o 36obj-$(CONFIG_USB_SERIAL_KEYSPAN_PDA) += keyspan_pda.o
diff --git a/drivers/usb/serial/airprime.c b/drivers/usb/serial/airprime.c
index 77bb893bf2e9..f156dba0300f 100644
--- a/drivers/usb/serial/airprime.c
+++ b/drivers/usb/serial/airprime.c
@@ -217,7 +217,10 @@ static void airprime_close(struct usb_serial_port *port, struct file * filp)
217 priv->rts_state = 0; 217 priv->rts_state = 0;
218 priv->dtr_state = 0; 218 priv->dtr_state = 0;
219 219
220 airprime_send_setup(port); 220 mutex_lock(&port->serial->disc_mutex);
221 if (!port->serial->disconnected)
222 airprime_send_setup(port);
223 mutex_lock(&port->serial->disc_mutex);
221 224
222 for (i = 0; i < NUM_READ_URBS; ++i) { 225 for (i = 0; i < NUM_READ_URBS; ++i) {
223 usb_kill_urb (priv->read_urbp[i]); 226 usb_kill_urb (priv->read_urbp[i]);
diff --git a/drivers/usb/serial/ark3116.c b/drivers/usb/serial/ark3116.c
index ddfee918000d..fe2bfd67ba8e 100644
--- a/drivers/usb/serial/ark3116.c
+++ b/drivers/usb/serial/ark3116.c
@@ -151,8 +151,10 @@ static int ark3116_attach(struct usb_serial *serial)
151 return 0; 151 return 0;
152 152
153cleanup: 153cleanup:
154 for (--i; i >= 0; --i) 154 for (--i; i >= 0; --i) {
155 kfree(usb_get_serial_port_data(serial->port[i]));
155 usb_set_serial_port_data(serial->port[i], NULL); 156 usb_set_serial_port_data(serial->port[i], NULL);
157 }
156 return -ENOMEM; 158 return -ENOMEM;
157} 159}
158 160
diff --git a/drivers/usb/serial/belkin_sa.c b/drivers/usb/serial/belkin_sa.c
index 86724e885704..df0a2b3b0294 100644
--- a/drivers/usb/serial/belkin_sa.c
+++ b/drivers/usb/serial/belkin_sa.c
@@ -350,14 +350,12 @@ static void belkin_sa_set_termios (struct usb_serial_port *port, struct ktermios
350 unsigned long control_state; 350 unsigned long control_state;
351 int bad_flow_control; 351 int bad_flow_control;
352 speed_t baud; 352 speed_t baud;
353 struct ktermios *termios = port->tty->termios;
353 354
354 if ((!port->tty) || (!port->tty->termios)) { 355 iflag = termios->c_iflag;
355 dbg ("%s - no tty or termios structure", __FUNCTION__); 356 cflag = termios->c_cflag;
356 return;
357 }
358 357
359 iflag = port->tty->termios->c_iflag; 358 termios->c_cflag &= ~CMSPAR;
360 cflag = port->tty->termios->c_cflag;
361 359
362 /* get a local copy of the current port settings */ 360 /* get a local copy of the current port settings */
363 spin_lock_irqsave(&priv->lock, flags); 361 spin_lock_irqsave(&priv->lock, flags);
@@ -369,33 +367,30 @@ static void belkin_sa_set_termios (struct usb_serial_port *port, struct ktermios
369 old_cflag = old_termios->c_cflag; 367 old_cflag = old_termios->c_cflag;
370 368
371 /* Set the baud rate */ 369 /* Set the baud rate */
372 if( (cflag&CBAUD) != (old_cflag&CBAUD) ) { 370 if ((cflag & CBAUD) != (old_cflag & CBAUD)) {
373 /* reassert DTR and (maybe) RTS on transition from B0 */ 371 /* reassert DTR and (maybe) RTS on transition from B0 */
374 if( (old_cflag&CBAUD) == B0 ) { 372 if( (old_cflag&CBAUD) == B0 ) {
375 control_state |= (TIOCM_DTR|TIOCM_RTS); 373 control_state |= (TIOCM_DTR|TIOCM_RTS);
376 if (BSA_USB_CMD(BELKIN_SA_SET_DTR_REQUEST, 1) < 0) 374 if (BSA_USB_CMD(BELKIN_SA_SET_DTR_REQUEST, 1) < 0)
377 err("Set DTR error"); 375 err("Set DTR error");
378 /* don't set RTS if using hardware flow control */ 376 /* don't set RTS if using hardware flow control */
379 if (!(old_cflag&CRTSCTS) ) 377 if (!(old_cflag & CRTSCTS))
380 if (BSA_USB_CMD(BELKIN_SA_SET_RTS_REQUEST, 1) < 0) 378 if (BSA_USB_CMD(BELKIN_SA_SET_RTS_REQUEST, 1) < 0)
381 err("Set RTS error"); 379 err("Set RTS error");
382 } 380 }
383 } 381 }
384 382
385 baud = tty_get_baud_rate(port->tty); 383 baud = tty_get_baud_rate(port->tty);
386 if (baud == 0) { 384 if (baud) {
387 dbg("%s - tty_get_baud_rate says 0 baud", __FUNCTION__); 385 urb_value = BELKIN_SA_BAUD(baud);
388 return; 386 /* Clip to maximum speed */
389 } 387 if (urb_value == 0)
390 urb_value = BELKIN_SA_BAUD(baud); 388 urb_value = 1;
391 /* Clip to maximum speed */ 389 /* Turn it back into a resulting real baud rate */
392 if (urb_value == 0) 390 baud = BELKIN_SA_BAUD(urb_value);
393 urb_value = 1; 391
394 /* Turn it back into a resulting real baud rate */ 392 /* Report the actual baud rate back to the caller */
395 baud = BELKIN_SA_BAUD(urb_value); 393 tty_encode_baud_rate(port->tty, baud, baud);
396 /* FIXME: Once the tty updates are done then push this back to the tty */
397
398 if ((cflag & CBAUD) != B0 ) {
399 if (BSA_USB_CMD(BELKIN_SA_SET_BAUDRATE_REQUEST, urb_value) < 0) 394 if (BSA_USB_CMD(BELKIN_SA_SET_BAUDRATE_REQUEST, urb_value) < 0)
400 err("Set baudrate error"); 395 err("Set baudrate error");
401 } else { 396 } else {
diff --git a/drivers/usb/serial/console.c b/drivers/usb/serial/console.c
index 0362654d3b52..66ce30c1b75b 100644
--- a/drivers/usb/serial/console.c
+++ b/drivers/usb/serial/console.c
@@ -64,8 +64,8 @@ static int usb_console_setup(struct console *co, char *options)
64 struct usb_serial *serial; 64 struct usb_serial *serial;
65 struct usb_serial_port *port; 65 struct usb_serial_port *port;
66 int retval = 0; 66 int retval = 0;
67 struct tty_struct *tty; 67 struct tty_struct *tty = NULL;
68 struct ktermios *termios; 68 struct ktermios *termios = NULL, dummy;
69 69
70 dbg ("%s", __FUNCTION__); 70 dbg ("%s", __FUNCTION__);
71 71
@@ -133,11 +133,14 @@ static int usb_console_setup(struct console *co, char *options)
133 } 133 }
134 co->cflag = cflag; 134 co->cflag = cflag;
135 135
136 /* grab the first serial port that happens to be connected */ 136 /*
137 serial = usb_serial_get_by_index(0); 137 * no need to check the index here: if the index is wrong, console
138 * code won't call us
139 */
140 serial = usb_serial_get_by_index(co->index);
138 if (serial == NULL) { 141 if (serial == NULL) {
139 /* no device is connected yet, sorry :( */ 142 /* no device is connected yet, sorry :( */
140 err ("No USB device connected to ttyUSB0"); 143 err ("No USB device connected to ttyUSB%i", co->index);
141 return -ENODEV; 144 return -ENODEV;
142 } 145 }
143 146
@@ -148,49 +151,64 @@ static int usb_console_setup(struct console *co, char *options)
148 151
149 ++port->open_count; 152 ++port->open_count;
150 if (port->open_count == 1) { 153 if (port->open_count == 1) {
154 if (serial->type->set_termios) {
155 /*
156 * allocate a fake tty so the driver can initialize
157 * the termios structure, then later call set_termios to
158 * configure according to command line arguments
159 */
160 tty = kzalloc(sizeof(*tty), GFP_KERNEL);
161 if (!tty) {
162 retval = -ENOMEM;
163 err("no more memory");
164 goto reset_open_count;
165 }
166 termios = kzalloc(sizeof(*termios), GFP_KERNEL);
167 if (!termios) {
168 retval = -ENOMEM;
169 err("no more memory");
170 goto free_tty;
171 }
172 memset(&dummy, 0, sizeof(struct ktermios));
173 tty->termios = termios;
174 port->tty = tty;
175 }
176
151 /* only call the device specific open if this 177 /* only call the device specific open if this
152 * is the first time the port is opened */ 178 * is the first time the port is opened */
153 if (serial->type->open) 179 if (serial->type->open)
154 retval = serial->type->open(port, NULL); 180 retval = serial->type->open(port, NULL);
155 else 181 else
156 retval = usb_serial_generic_open(port, NULL); 182 retval = usb_serial_generic_open(port, NULL);
157 if (retval)
158 port->open_count = 0;
159 }
160 183
161 if (retval) { 184 if (retval) {
162 err ("could not open USB console port"); 185 err("could not open USB console port");
163 return retval; 186 goto free_termios;
164 }
165
166 if (serial->type->set_termios) {
167 struct ktermios dummy;
168 /* build up a fake tty structure so that the open call has something
169 * to look at to get the cflag value */
170 tty = kzalloc(sizeof(*tty), GFP_KERNEL);
171 if (!tty) {
172 err ("no more memory");
173 return -ENOMEM;
174 } 187 }
175 termios = kzalloc(sizeof(*termios), GFP_KERNEL);
176 if (!termios) {
177 err ("no more memory");
178 kfree (tty);
179 return -ENOMEM;
180 }
181 memset(&dummy, 0, sizeof(struct ktermios));
182 termios->c_cflag = cflag;
183 tty->termios = termios;
184 port->tty = tty;
185 188
186 /* set up the initial termios settings */ 189 if (serial->type->set_termios) {
187 serial->type->set_termios(port, &dummy); 190 termios->c_cflag = cflag;
188 port->tty = NULL; 191 serial->type->set_termios(port, &dummy);
189 kfree (termios); 192
190 kfree (tty); 193 port->tty = NULL;
194 kfree(termios);
195 kfree(tty);
196 }
191 } 197 }
192 198
199 port->console = 1;
200 retval = 0;
201
202out:
193 return retval; 203 return retval;
204free_termios:
205 kfree(termios);
206 port->tty = NULL;
207free_tty:
208 kfree(tty);
209reset_open_count:
210 port->open_count = 0;
211goto out;
194} 212}
195 213
196static void usb_console_write(struct console *co, const char *buf, unsigned count) 214static void usb_console_write(struct console *co, const char *buf, unsigned count)
diff --git a/drivers/usb/serial/cp2101.c b/drivers/usb/serial/cp2101.c
index 22833589c4be..f3ca66017a03 100644
--- a/drivers/usb/serial/cp2101.c
+++ b/drivers/usb/serial/cp2101.c
@@ -59,6 +59,7 @@ static struct usb_device_id id_table [] = {
59 { USB_DEVICE(0x10A6, 0xAA26) }, /* Knock-off DCU-11 cable */ 59 { USB_DEVICE(0x10A6, 0xAA26) }, /* Knock-off DCU-11 cable */
60 { USB_DEVICE(0x10AB, 0x10C5) }, /* Siemens MC60 Cable */ 60 { USB_DEVICE(0x10AB, 0x10C5) }, /* Siemens MC60 Cable */
61 { USB_DEVICE(0x10B5, 0xAC70) }, /* Nokia CA-42 USB */ 61 { USB_DEVICE(0x10B5, 0xAC70) }, /* Nokia CA-42 USB */
62 { USB_DEVICE(0x10C4, 0x800A) }, /* SPORTident BSM7-D-USB main station */
62 { USB_DEVICE(0x10C4, 0x803B) }, /* Pololu USB-serial converter */ 63 { USB_DEVICE(0x10C4, 0x803B) }, /* Pololu USB-serial converter */
63 { USB_DEVICE(0x10C4, 0x8053) }, /* Enfora EDG1228 */ 64 { USB_DEVICE(0x10C4, 0x8053) }, /* Enfora EDG1228 */
64 { USB_DEVICE(0x10C4, 0x8066) }, /* Argussoft In-System Programmer */ 65 { USB_DEVICE(0x10C4, 0x8066) }, /* Argussoft In-System Programmer */
@@ -76,8 +77,13 @@ static struct usb_device_id id_table [] = {
76 { USB_DEVICE(0x10C4, 0x8218) }, /* Lipowsky Industrie Elektronik GmbH, HARP-1 */ 77 { USB_DEVICE(0x10C4, 0x8218) }, /* Lipowsky Industrie Elektronik GmbH, HARP-1 */
77 { USB_DEVICE(0x10C4, 0xEA60) }, /* Silicon Labs factory default */ 78 { USB_DEVICE(0x10C4, 0xEA60) }, /* Silicon Labs factory default */
78 { USB_DEVICE(0x10C4, 0xEA61) }, /* Silicon Labs factory default */ 79 { USB_DEVICE(0x10C4, 0xEA61) }, /* Silicon Labs factory default */
80 { USB_DEVICE(0x10C4, 0xF001) }, /* Elan Digital Systems USBscope50 */
81 { USB_DEVICE(0x10C4, 0xF002) }, /* Elan Digital Systems USBwave12 */
82 { USB_DEVICE(0x10C4, 0xF003) }, /* Elan Digital Systems USBpulse100 */
83 { USB_DEVICE(0x10C4, 0xF004) }, /* Elan Digital Systems USBcount50 */
79 { USB_DEVICE(0x10C5, 0xEA61) }, /* Silicon Labs MobiData GPRS USB Modem */ 84 { USB_DEVICE(0x10C5, 0xEA61) }, /* Silicon Labs MobiData GPRS USB Modem */
80 { USB_DEVICE(0x13AD, 0x9999) }, /* Baltech card reader */ 85 { USB_DEVICE(0x13AD, 0x9999) }, /* Baltech card reader */
86 { USB_DEVICE(0x166A, 0x0303) }, /* Clipsal 5500PCU C-Bus USB interface */
81 { USB_DEVICE(0x16D6, 0x0001) }, /* Jablotron serial interface */ 87 { USB_DEVICE(0x16D6, 0x0001) }, /* Jablotron serial interface */
82 { } /* Terminating Entry */ 88 { } /* Terminating Entry */
83}; 89};
@@ -342,7 +348,10 @@ static void cp2101_close (struct usb_serial_port *port, struct file * filp)
342 usb_kill_urb(port->write_urb); 348 usb_kill_urb(port->write_urb);
343 usb_kill_urb(port->read_urb); 349 usb_kill_urb(port->read_urb);
344 350
345 cp2101_set_config_single(port, CP2101_UART, UART_DISABLE); 351 mutex_lock(&port->serial->disc_mutex);
352 if (!port->serial->disconnected)
353 cp2101_set_config_single(port, CP2101_UART, UART_DISABLE);
354 mutex_unlock(&port->serial->disc_mutex);
346} 355}
347 356
348/* 357/*
diff --git a/drivers/usb/serial/cyberjack.c b/drivers/usb/serial/cyberjack.c
index 4353df92487f..8d9b045aa7e8 100644
--- a/drivers/usb/serial/cyberjack.c
+++ b/drivers/usb/serial/cyberjack.c
@@ -319,7 +319,6 @@ static void cyberjack_read_int_callback( struct urb *urb )
319 /* React only to interrupts signaling a bulk_in transfer */ 319 /* React only to interrupts signaling a bulk_in transfer */
320 if( (urb->actual_length==4) && (data[0]==0x01) ) { 320 if( (urb->actual_length==4) && (data[0]==0x01) ) {
321 short old_rdtodo; 321 short old_rdtodo;
322 int result;
323 322
324 /* This is a announcement of coming bulk_ins. */ 323 /* This is a announcement of coming bulk_ins. */
325 unsigned short size = ((unsigned short)data[3]<<8)+data[2]+3; 324 unsigned short size = ((unsigned short)data[3]<<8)+data[2]+3;
diff --git a/drivers/usb/serial/cypress_m8.c b/drivers/usb/serial/cypress_m8.c
index 163386336a5d..08c65c1a3771 100644
--- a/drivers/usb/serial/cypress_m8.c
+++ b/drivers/usb/serial/cypress_m8.c
@@ -682,7 +682,6 @@ static void cypress_close(struct usb_serial_port *port, struct file * filp)
682{ 682{
683 struct cypress_private *priv = usb_get_serial_port_data(port); 683 struct cypress_private *priv = usb_get_serial_port_data(port);
684 unsigned int c_cflag; 684 unsigned int c_cflag;
685 unsigned long flags;
686 int bps; 685 int bps;
687 long timeout; 686 long timeout;
688 wait_queue_t wait; 687 wait_queue_t wait;
@@ -690,7 +689,7 @@ static void cypress_close(struct usb_serial_port *port, struct file * filp)
690 dbg("%s - port %d", __FUNCTION__, port->number); 689 dbg("%s - port %d", __FUNCTION__, port->number);
691 690
692 /* wait for data to drain from buffer */ 691 /* wait for data to drain from buffer */
693 spin_lock_irqsave(&priv->lock, flags); 692 spin_lock_irq(&priv->lock);
694 timeout = CYPRESS_CLOSING_WAIT; 693 timeout = CYPRESS_CLOSING_WAIT;
695 init_waitqueue_entry(&wait, current); 694 init_waitqueue_entry(&wait, current);
696 add_wait_queue(&port->tty->write_wait, &wait); 695 add_wait_queue(&port->tty->write_wait, &wait);
@@ -698,18 +697,25 @@ static void cypress_close(struct usb_serial_port *port, struct file * filp)
698 set_current_state(TASK_INTERRUPTIBLE); 697 set_current_state(TASK_INTERRUPTIBLE);
699 if (cypress_buf_data_avail(priv->buf) == 0 698 if (cypress_buf_data_avail(priv->buf) == 0
700 || timeout == 0 || signal_pending(current) 699 || timeout == 0 || signal_pending(current)
701 || !usb_get_intfdata(port->serial->interface)) 700 /* without mutex, allowed due to harmless failure mode */
701 || port->serial->disconnected)
702 break; 702 break;
703 spin_unlock_irqrestore(&priv->lock, flags); 703 spin_unlock_irq(&priv->lock);
704 timeout = schedule_timeout(timeout); 704 timeout = schedule_timeout(timeout);
705 spin_lock_irqsave(&priv->lock, flags); 705 spin_lock_irq(&priv->lock);
706 } 706 }
707 set_current_state(TASK_RUNNING); 707 set_current_state(TASK_RUNNING);
708 remove_wait_queue(&port->tty->write_wait, &wait); 708 remove_wait_queue(&port->tty->write_wait, &wait);
709 /* clear out any remaining data in the buffer */ 709 /* clear out any remaining data in the buffer */
710 cypress_buf_clear(priv->buf); 710 cypress_buf_clear(priv->buf);
711 spin_unlock_irqrestore(&priv->lock, flags); 711 spin_unlock_irq(&priv->lock);
712 712
713 /* writing is potentially harmful, lock must be taken */
714 mutex_lock(&port->serial->disc_mutex);
715 if (port->serial->disconnected) {
716 mutex_unlock(&port->serial->disc_mutex);
717 return;
718 }
713 /* wait for characters to drain from device */ 719 /* wait for characters to drain from device */
714 bps = tty_get_baud_rate(port->tty); 720 bps = tty_get_baud_rate(port->tty);
715 if (bps > 1200) 721 if (bps > 1200)
@@ -727,10 +733,10 @@ static void cypress_close(struct usb_serial_port *port, struct file * filp)
727 if (c_cflag & HUPCL) { 733 if (c_cflag & HUPCL) {
728 /* drop dtr and rts */ 734 /* drop dtr and rts */
729 priv = usb_get_serial_port_data(port); 735 priv = usb_get_serial_port_data(port);
730 spin_lock_irqsave(&priv->lock, flags); 736 spin_lock_irq(&priv->lock);
731 priv->line_control = 0; 737 priv->line_control = 0;
732 priv->cmd_ctrl = 1; 738 priv->cmd_ctrl = 1;
733 spin_unlock_irqrestore(&priv->lock, flags); 739 spin_unlock_irq(&priv->lock);
734 cypress_write(port, NULL, 0); 740 cypress_write(port, NULL, 0);
735 } 741 }
736 } 742 }
@@ -738,6 +744,7 @@ static void cypress_close(struct usb_serial_port *port, struct file * filp)
738 if (stats) 744 if (stats)
739 dev_info (&port->dev, "Statistics: %d Bytes In | %d Bytes Out | %d Commands Issued\n", 745 dev_info (&port->dev, "Statistics: %d Bytes In | %d Bytes Out | %d Commands Issued\n",
740 priv->bytes_in, priv->bytes_out, priv->cmd_count); 746 priv->bytes_in, priv->bytes_out, priv->cmd_count);
747 mutex_unlock(&port->serial->disc_mutex);
741} /* cypress_close */ 748} /* cypress_close */
742 749
743 750
diff --git a/drivers/usb/serial/digi_acceleport.c b/drivers/usb/serial/digi_acceleport.c
index ae410c4678ea..5f9c6e46bee5 100644
--- a/drivers/usb/serial/digi_acceleport.c
+++ b/drivers/usb/serial/digi_acceleport.c
@@ -1405,19 +1405,19 @@ static void digi_close(struct usb_serial_port *port, struct file *filp)
1405 unsigned char buf[32]; 1405 unsigned char buf[32];
1406 struct tty_struct *tty = port->tty; 1406 struct tty_struct *tty = port->tty;
1407 struct digi_port *priv = usb_get_serial_port_data(port); 1407 struct digi_port *priv = usb_get_serial_port_data(port);
1408 unsigned long flags = 0;
1409 1408
1410 dbg("digi_close: TOP: port=%d, open_count=%d", 1409 dbg("digi_close: TOP: port=%d, open_count=%d",
1411 priv->dp_port_num, port->open_count); 1410 priv->dp_port_num, port->open_count);
1412 1411
1412 mutex_lock(&port->serial->disc_mutex);
1413 /* if disconnected, just clear flags */ 1413 /* if disconnected, just clear flags */
1414 if (!usb_get_intfdata(port->serial->interface)) 1414 if (port->serial->disconnected)
1415 goto exit; 1415 goto exit;
1416 1416
1417 /* do cleanup only after final close on this port */ 1417 /* do cleanup only after final close on this port */
1418 spin_lock_irqsave(&priv->dp_port_lock, flags); 1418 spin_lock_irq(&priv->dp_port_lock);
1419 priv->dp_in_close = 1; 1419 priv->dp_in_close = 1;
1420 spin_unlock_irqrestore(&priv->dp_port_lock, flags); 1420 spin_unlock_irq(&priv->dp_port_lock);
1421 1421
1422 /* tell line discipline to process only XON/XOFF */ 1422 /* tell line discipline to process only XON/XOFF */
1423 tty->closing = 1; 1423 tty->closing = 1;
@@ -1482,11 +1482,12 @@ static void digi_close(struct usb_serial_port *port, struct file *filp)
1482 } 1482 }
1483 tty->closing = 0; 1483 tty->closing = 0;
1484exit: 1484exit:
1485 spin_lock_irqsave(&priv->dp_port_lock, flags); 1485 spin_lock_irq(&priv->dp_port_lock);
1486 priv->dp_write_urb_in_use = 0; 1486 priv->dp_write_urb_in_use = 0;
1487 priv->dp_in_close = 0; 1487 priv->dp_in_close = 0;
1488 wake_up_interruptible(&priv->dp_close_wait); 1488 wake_up_interruptible(&priv->dp_close_wait);
1489 spin_unlock_irqrestore(&priv->dp_port_lock, flags); 1489 spin_unlock_irq(&priv->dp_port_lock);
1490 mutex_unlock(&port->serial->disc_mutex);
1490 dbg("digi_close: done"); 1491 dbg("digi_close: done");
1491} 1492}
1492 1493
diff --git a/drivers/usb/serial/ezusb.c b/drivers/usb/serial/ezusb.c
index 97ee718b1da2..3f698baa0abb 100644
--- a/drivers/usb/serial/ezusb.c
+++ b/drivers/usb/serial/ezusb.c
@@ -53,6 +53,6 @@ int ezusb_set_reset (struct usb_serial *serial, unsigned char reset_bit)
53} 53}
54 54
55 55
56EXPORT_SYMBOL(ezusb_writememory); 56EXPORT_SYMBOL_GPL(ezusb_writememory);
57EXPORT_SYMBOL(ezusb_set_reset); 57EXPORT_SYMBOL_GPL(ezusb_set_reset);
58 58
diff --git a/drivers/usb/serial/ftdi_sio.c b/drivers/usb/serial/ftdi_sio.c
index c40e77dccf8e..90dcc625f70d 100644
--- a/drivers/usb/serial/ftdi_sio.c
+++ b/drivers/usb/serial/ftdi_sio.c
@@ -17,226 +17,8 @@
17 * See http://ftdi-usb-sio.sourceforge.net for upto date testing info 17 * See http://ftdi-usb-sio.sourceforge.net for upto date testing info
18 * and extra documentation 18 * and extra documentation
19 * 19 *
20 * (21/Jul/2004) Ian Abbott 20 * Change entries from 2004 and earlier can be found in versions of this
21 * Incorporated Steven Turner's code to add support for the FT2232C chip. 21 * file in kernel versions prior to the 2.6.24 release.
22 * The prelimilary port to the 2.6 kernel was by Rus V. Brushkoff. I have
23 * fixed a couple of things.
24 *
25 * (27/May/2004) Ian Abbott
26 * Improved throttling code, mostly stolen from the WhiteHEAT driver.
27 *
28 * (26/Mar/2004) Jan Capek
29 * Added PID's for ICD-U20/ICD-U40 - incircuit PIC debuggers from CCS Inc.
30 *
31 * (09/Feb/2004) Ian Abbott
32 * Changed full name of USB-UIRT device to avoid "/" character.
33 * Added FTDI's alternate PID (0x6006) for FT232/245 devices.
34 * Added PID for "ELV USB Module UO100" from Stefan Frings.
35 *
36 * (21/Oct/2003) Ian Abbott
37 * Renamed some VID/PID macros for Matrix Orbital and Perle Systems
38 * devices. Removed Matrix Orbital and Perle Systems devices from the
39 * 8U232AM device table, but left them in the FT232BM table, as they are
40 * known to use only FT232BM.
41 *
42 * (17/Oct/2003) Scott Allen
43 * Added vid/pid for Perle Systems UltraPort USB serial converters
44 *
45 * (21/Sep/2003) Ian Abbott
46 * Added VID/PID for Omnidirectional Control Technology US101 USB to
47 * RS-232 adapter (also rebadged as Dick Smith Electronics XH6381).
48 * VID/PID supplied by Donald Gordon.
49 *
50 * (19/Aug/2003) Ian Abbott
51 * Freed urb's transfer buffer in write bulk callback.
52 * Omitted some paranoid checks in write bulk callback that don't matter.
53 * Scheduled work in write bulk callback regardless of port's open count.
54 *
55 * (05/Aug/2003) Ian Abbott
56 * Added VID/PID for ID TECH IDT1221U USB to RS-232 adapter.
57 * VID/PID provided by Steve Briggs.
58 *
59 * (23/Jul/2003) Ian Abbott
60 * Added PIDs for CrystalFontz 547, 633, 631, 635, 640 and 640 from
61 * Wayne Wylupski.
62 *
63 * (10/Jul/2003) David Glance
64 * Added PID for DSS-20 SyncStation cradle for Sony-Ericsson P800.
65 *
66 * (27/Jun/2003) Ian Abbott
67 * Reworked the urb handling logic. We have no more pool, but dynamically
68 * allocate the urb and the transfer buffer on the fly. In testing this
69 * does not incure any measurable overhead. This also relies on the fact
70 * that we have proper reference counting logic for urbs. I nicked this
71 * from Greg KH's Visor driver.
72 *
73 * (23/Jun/2003) Ian Abbott
74 * Reduced flip buffer pushes and corrected a data length test in
75 * ftdi_read_bulk_callback.
76 * Defererence pointers after any paranoid checks, not before.
77 *
78 * (21/Jun/2003) Erik Nygren
79 * Added support for Home Electronics Tira-1 IR transceiver using FT232BM chip.
80 * See <http://www.home-electro.com/tira1.htm>. Only operates properly
81 * at 100000 and RTS-CTS, so set custom divisor mode on startup.
82 * Also force the Tira-1 and USB-UIRT to only use their custom baud rates.
83 *
84 * (18/Jun/2003) Ian Abbott
85 * Added Device ID of the USB relais from Rudolf Gugler (backported from
86 * Philipp Gühring's patch for 2.5.x kernel).
87 * Moved read transfer buffer reallocation into startup function.
88 * Free existing write urb and transfer buffer in startup function.
89 * Only use urbs in write urb pool that were successfully allocated.
90 * Moved some constant macros out of functions.
91 * Minor whitespace and comment changes.
92 *
93 * (12/Jun/2003) David Norwood
94 * Added support for USB-UIRT IR transceiver using 8U232AM chip.
95 * See <http://home.earthlink.net/~jrhees/USBUIRT/index.htm>. Only
96 * operates properly at 312500, so set custom divisor mode on startup.
97 *
98 * (12/Jun/2003) Ian Abbott
99 * Added Sealevel SeaLINK+ 210x, 220x, 240x, 280x vid/pids from Tuan Hoang
100 * - I've eliminated some that don't seem to exist!
101 * Added Home Electronics Tira-1 IR transceiver pid from Chris Horn
102 * Some whitespace/coding-style cleanups
103 *
104 * (11/Jun/2003) Ian Abbott
105 * Fixed unsafe spinlock usage in ftdi_write
106 *
107 * (24/Feb/2003) Richard Shooter
108 * Increase read buffer size to improve read speeds at higher baud rates
109 * (specifically tested with up to 1Mb/sec at 1.5M baud)
110 *
111 * (23/Feb/2003) John Wilkins
112 * Added Xon/xoff flow control (activating support in the ftdi device)
113 * Added vid/pid for Videonetworks/Homechoice (UK ISP)
114 *
115 * (23/Feb/2003) Bill Ryder
116 * Added matrix orb device vid/pids from Wayne Wylupski
117 *
118 * (19/Feb/2003) Ian Abbott
119 * For TIOCSSERIAL, set alt_speed to 0 when ASYNC_SPD_MASK value has
120 * changed to something other than ASYNC_SPD_HI, ASYNC_SPD_VHI,
121 * ASYNC_SPD_SHI or ASYNC_SPD_WARP. Also, unless ASYNC_SPD_CUST is in
122 * force, don't bother changing baud rate when custom_divisor has changed.
123 *
124 * (18/Feb/2003) Ian Abbott
125 * Fixed TIOCMGET handling to include state of DTR and RTS, the state
126 * of which are now saved by set_dtr() and set_rts().
127 * Fixed improper storage class for buf in set_dtr() and set_rts().
128 * Added FT232BM chip type and support for its extra baud rates (compared
129 * to FT8U232AM).
130 * Took account of special case divisor values for highest baud rates of
131 * FT8U232AM and FT232BM.
132 * For TIOCSSERIAL, forced alt_speed to 0 when ASYNC_SPD_CUST kludge used,
133 * as previous alt_speed setting is now stale.
134 * Moved startup code common between the startup routines for the
135 * different chip types into a common subroutine.
136 *
137 * (17/Feb/2003) Bill Ryder
138 * Added write urb buffer pool on a per device basis
139 * Added more checking for open file on callbacks (fixed OOPS)
140 * Added CrystalFontz 632 and 634 PIDs
141 * (thanx to CrystalFontz for the sample devices - they flushed out
142 * some driver bugs)
143 * Minor debugging message changes
144 * Added throttle, unthrottle and chars_in_buffer functions
145 * Fixed FTDI_SIO (the original device) bug
146 * Fixed some shutdown handling
147 *
148 *
149 *
150 *
151 * (07/Jun/2002) Kuba Ober
152 * Changed FTDI_SIO_BASE_BAUD_TO_DIVISOR macro into ftdi_baud_to_divisor
153 * function. It was getting too complex.
154 * Fix the divisor calculation logic which was setting divisor of 0.125
155 * instead of 0.5 for fractional parts of divisor equal to 5/8, 6/8, 7/8.
156 * Also make it bump up the divisor to next integer in case of 7/8 - it's
157 * a better approximation.
158 *
159 * (25/Jul/2002) Bill Ryder inserted Dmitri's TIOCMIWAIT patch
160 * Not tested by me but it doesn't break anything I use.
161 *
162 * (04/Jan/2002) Kuba Ober
163 * Implemented 38400 baudrate kludge, where it can be substituted with other
164 * values. That's the only way to set custom baudrates.
165 * Implemented TIOCSSERIAL, TIOCGSERIAL ioctl's so that setserial is happy.
166 * FIXME: both baudrate things should eventually go to usbserial.c as other
167 * devices may need that functionality too. Actually, it can probably be
168 * merged in serial.c somehow - too many drivers repeat this code over
169 * and over.
170 * Fixed baudrate forgetfulness - open() used to reset baudrate to 9600 every time.
171 * Divisors for baudrates are calculated by a macro.
172 * Small code cleanups. Ugly whitespace changes for Plato's sake only ;-].
173 *
174 * (04/Nov/2001) Bill Ryder
175 * Fixed bug in read_bulk_callback where incorrect urb buffer was used.
176 * Cleaned up write offset calculation
177 * Added write_room since default values can be incorrect for sio
178 * Changed write_bulk_callback to use same queue_task as other drivers
179 * (the previous version caused panics)
180 * Removed port iteration code since the device only has one I/O port and it
181 * was wrong anyway.
182 *
183 * (31/May/2001) gkh
184 * Switched from using spinlock to a semaphore, which fixes lots of problems.
185 *
186 * (23/May/2001) Bill Ryder
187 * Added runtime debug patch (thanx Tyson D Sawyer).
188 * Cleaned up comments for 8U232
189 * Added parity, framing and overrun error handling
190 * Added receive break handling.
191 *
192 * (04/08/2001) gb
193 * Identify version on module load.
194 *
195 * (18/March/2001) Bill Ryder
196 * (Not released)
197 * Added send break handling. (requires kernel patch too)
198 * Fixed 8U232AM hardware RTS/CTS etc status reporting.
199 * Added flipbuf fix copied from generic device
200 *
201 * (12/3/2000) Bill Ryder
202 * Added support for 8U232AM device.
203 * Moved PID and VIDs into header file only.
204 * Turned on low-latency for the tty (device will do high baudrates)
205 * Added shutdown routine to close files when device removed.
206 * More debug and error message cleanups.
207 *
208 * (11/13/2000) Bill Ryder
209 * Added spinlock protected open code and close code.
210 * Multiple opens work (sort of - see webpage mentioned above).
211 * Cleaned up comments. Removed multiple PID/VID definitions.
212 * Factorised cts/dtr code
213 * Made use of __FUNCTION__ in dbg's
214 *
215 * (11/01/2000) Adam J. Richter
216 * usb_device_id table support
217 *
218 * (10/05/2000) gkh
219 * Fixed bug with urb->dev not being set properly, now that the usb
220 * core needs it.
221 *
222 * (09/11/2000) gkh
223 * Removed DEBUG #ifdefs with call to usb_serial_debug_data
224 *
225 * (07/19/2000) gkh
226 * Added module_init and module_exit functions to handle the fact that this
227 * driver is a loadable module now.
228 *
229 * (04/04/2000) Bill Ryder
230 * Fixed bugs in TCGET/TCSET ioctls (by removing them - they are
231 * handled elsewhere in the tty io driver chain).
232 *
233 * (03/30/2000) Bill Ryder
234 * Implemented lots of ioctls
235 * Fixed a race condition in write
236 * Changed some dbg's to errs
237 *
238 * (03/26/2000) gkh
239 * Split driver up into device specific pieces.
240 * 22 *
241 */ 23 */
242 24
@@ -309,12 +91,12 @@ struct ftdi_sio_quirk {
309 void (*port_probe)(struct ftdi_private *); /* Special settings for probed ports. */ 91 void (*port_probe)(struct ftdi_private *); /* Special settings for probed ports. */
310}; 92};
311 93
312static int ftdi_olimex_probe (struct usb_serial *serial); 94static int ftdi_jtag_probe (struct usb_serial *serial);
313static void ftdi_USB_UIRT_setup (struct ftdi_private *priv); 95static void ftdi_USB_UIRT_setup (struct ftdi_private *priv);
314static void ftdi_HE_TIRA1_setup (struct ftdi_private *priv); 96static void ftdi_HE_TIRA1_setup (struct ftdi_private *priv);
315 97
316static struct ftdi_sio_quirk ftdi_olimex_quirk = { 98static struct ftdi_sio_quirk ftdi_jtag_quirk = {
317 .probe = ftdi_olimex_probe, 99 .probe = ftdi_jtag_probe,
318}; 100};
319 101
320static struct ftdi_sio_quirk ftdi_USB_UIRT_quirk = { 102static struct ftdi_sio_quirk ftdi_USB_UIRT_quirk = {
@@ -471,30 +253,28 @@ static struct usb_device_id id_table_combined [] = {
471 { USB_DEVICE(FTDI_VID, FTDI_IBS_PEDO_PID) }, 253 { USB_DEVICE(FTDI_VID, FTDI_IBS_PEDO_PID) },
472 { USB_DEVICE(FTDI_VID, FTDI_IBS_PROD_PID) }, 254 { USB_DEVICE(FTDI_VID, FTDI_IBS_PROD_PID) },
473 /* 255 /*
474 * These will probably use user-space drivers. Uncomment them if 256 * Due to many user requests for multiple ELV devices we enable
475 * you need them or use the user-specified vendor/product module 257 * them by default.
476 * parameters (see ftdi_sio.h for the numbers). Make a fuss if
477 * you think the driver should recognize any of them by default.
478 */ 258 */
479 /* { USB_DEVICE(FTDI_VID, FTDI_ELV_CLI7000_PID) }, */ 259 { USB_DEVICE(FTDI_VID, FTDI_ELV_CLI7000_PID) },
480 /* { USB_DEVICE(FTDI_VID, FTDI_ELV_PPS7330_PID) }, */ 260 { USB_DEVICE(FTDI_VID, FTDI_ELV_PPS7330_PID) },
481 /* { USB_DEVICE(FTDI_VID, FTDI_ELV_TFM100_PID) }, */ 261 { USB_DEVICE(FTDI_VID, FTDI_ELV_TFM100_PID) },
482 /* { USB_DEVICE(FTDI_VID, FTDI_ELV_UDF77_PID) }, */ 262 { USB_DEVICE(FTDI_VID, FTDI_ELV_UDF77_PID) },
483 /* { USB_DEVICE(FTDI_VID, FTDI_ELV_UIO88_PID) }, */ 263 { USB_DEVICE(FTDI_VID, FTDI_ELV_UIO88_PID) },
484 /* { USB_DEVICE(FTDI_VID, FTDI_ELV_UAD8_PID) }, */ 264 { USB_DEVICE(FTDI_VID, FTDI_ELV_UAD8_PID) },
485 /* { USB_DEVICE(FTDI_VID, FTDI_ELV_UDA7_PID) }, */ 265 { USB_DEVICE(FTDI_VID, FTDI_ELV_UDA7_PID) },
486 /* { USB_DEVICE(FTDI_VID, FTDI_ELV_USI2_PID) }, */ 266 { USB_DEVICE(FTDI_VID, FTDI_ELV_USI2_PID) },
487 /* { USB_DEVICE(FTDI_VID, FTDI_ELV_T1100_PID) }, */ 267 { USB_DEVICE(FTDI_VID, FTDI_ELV_T1100_PID) },
488 /* { USB_DEVICE(FTDI_VID, FTDI_ELV_PCD200_PID) }, */ 268 { USB_DEVICE(FTDI_VID, FTDI_ELV_PCD200_PID) },
489 /* { USB_DEVICE(FTDI_VID, FTDI_ELV_ULA200_PID) }, */ 269 { USB_DEVICE(FTDI_VID, FTDI_ELV_ULA200_PID) },
490 /* { USB_DEVICE(FTDI_VID, FTDI_ELV_CSI8_PID) }, */ 270 { USB_DEVICE(FTDI_VID, FTDI_ELV_CSI8_PID) },
491 /* { USB_DEVICE(FTDI_VID, FTDI_ELV_EM1000DL_PID) }, */ 271 { USB_DEVICE(FTDI_VID, FTDI_ELV_EM1000DL_PID) },
492 /* { USB_DEVICE(FTDI_VID, FTDI_ELV_PCK100_PID) }, */ 272 { USB_DEVICE(FTDI_VID, FTDI_ELV_PCK100_PID) },
493 /* { USB_DEVICE(FTDI_VID, FTDI_ELV_RFP500_PID) }, */ 273 { USB_DEVICE(FTDI_VID, FTDI_ELV_RFP500_PID) },
494 /* { USB_DEVICE(FTDI_VID, FTDI_ELV_FS20SIG_PID) }, */ 274 { USB_DEVICE(FTDI_VID, FTDI_ELV_FS20SIG_PID) },
495 /* { USB_DEVICE(FTDI_VID, FTDI_ELV_WS300PC_PID) }, */ 275 { USB_DEVICE(FTDI_VID, FTDI_ELV_WS300PC_PID) },
496 /* { USB_DEVICE(FTDI_VID, FTDI_ELV_FHZ1300PC_PID) }, */ 276 { USB_DEVICE(FTDI_VID, FTDI_ELV_FHZ1300PC_PID) },
497 /* { USB_DEVICE(FTDI_VID, FTDI_ELV_WS500_PID) }, */ 277 { USB_DEVICE(FTDI_VID, FTDI_ELV_WS500_PID) },
498 { USB_DEVICE(FTDI_VID, LINX_SDMUSBQSS_PID) }, 278 { USB_DEVICE(FTDI_VID, LINX_SDMUSBQSS_PID) },
499 { USB_DEVICE(FTDI_VID, LINX_MASTERDEVEL2_PID) }, 279 { USB_DEVICE(FTDI_VID, LINX_MASTERDEVEL2_PID) },
500 { USB_DEVICE(FTDI_VID, LINX_FUTURE_0_PID) }, 280 { USB_DEVICE(FTDI_VID, LINX_FUTURE_0_PID) },
@@ -545,6 +325,7 @@ static struct usb_device_id id_table_combined [] = {
545 { USB_DEVICE(FTDI_VID, FTDI_ATIK_ATK16C_PID) }, 325 { USB_DEVICE(FTDI_VID, FTDI_ATIK_ATK16C_PID) },
546 { USB_DEVICE(FTDI_VID, FTDI_ATIK_ATK16HR_PID) }, 326 { USB_DEVICE(FTDI_VID, FTDI_ATIK_ATK16HR_PID) },
547 { USB_DEVICE(FTDI_VID, FTDI_ATIK_ATK16HRC_PID) }, 327 { USB_DEVICE(FTDI_VID, FTDI_ATIK_ATK16HRC_PID) },
328 { USB_DEVICE(FTDI_VID, FTDI_ATIK_ATK16IC_PID) },
548 { USB_DEVICE(KOBIL_VID, KOBIL_CONV_B1_PID) }, 329 { USB_DEVICE(KOBIL_VID, KOBIL_CONV_B1_PID) },
549 { USB_DEVICE(KOBIL_VID, KOBIL_CONV_KAAN_PID) }, 330 { USB_DEVICE(KOBIL_VID, KOBIL_CONV_KAAN_PID) },
550 { USB_DEVICE(POSIFLEX_VID, POSIFLEX_PP7000_PID) }, 331 { USB_DEVICE(POSIFLEX_VID, POSIFLEX_PP7000_PID) },
@@ -569,8 +350,13 @@ static struct usb_device_id id_table_combined [] = {
569 { USB_DEVICE(TELLDUS_VID, TELLDUS_TELLSTICK_PID) }, 350 { USB_DEVICE(TELLDUS_VID, TELLDUS_TELLSTICK_PID) },
570 { USB_DEVICE(FTDI_VID, FTDI_MAXSTREAM_PID) }, 351 { USB_DEVICE(FTDI_VID, FTDI_MAXSTREAM_PID) },
571 { USB_DEVICE(TML_VID, TML_USB_SERIAL_PID) }, 352 { USB_DEVICE(TML_VID, TML_USB_SERIAL_PID) },
353 { USB_DEVICE(FTDI_VID, FTDI_ELSTER_UNICOM_PID) },
572 { USB_DEVICE(OLIMEX_VID, OLIMEX_ARM_USB_OCD_PID), 354 { USB_DEVICE(OLIMEX_VID, OLIMEX_ARM_USB_OCD_PID),
573 .driver_info = (kernel_ulong_t)&ftdi_olimex_quirk }, 355 .driver_info = (kernel_ulong_t)&ftdi_jtag_quirk },
356 { USB_DEVICE(FIC_VID, FIC_NEO1973_DEBUG_PID),
357 .driver_info = (kernel_ulong_t)&ftdi_jtag_quirk },
358 { USB_DEVICE(FTDI_VID, FTDI_OOCDLINK_PID),
359 .driver_info = (kernel_ulong_t)&ftdi_jtag_quirk },
574 { }, /* Optional parameter entry */ 360 { }, /* Optional parameter entry */
575 { } /* Terminating entry */ 361 { } /* Terminating entry */
576}; 362};
@@ -1283,10 +1069,11 @@ static void ftdi_HE_TIRA1_setup (struct ftdi_private *priv)
1283} /* ftdi_HE_TIRA1_setup */ 1069} /* ftdi_HE_TIRA1_setup */
1284 1070
1285/* 1071/*
1286 * First port on Olimex arm-usb-ocd is reserved for JTAG interface 1072 * First port on JTAG adaptors such as Olimex arm-usb-ocd or the FIC/OpenMoko
1287 * and can be accessed from userspace using openocd. 1073 * Neo1973 Debug Board is reserved for JTAG interface and can be accessed from
1074 * userspace using openocd.
1288 */ 1075 */
1289static int ftdi_olimex_probe(struct usb_serial *serial) 1076static int ftdi_jtag_probe(struct usb_serial *serial)
1290{ 1077{
1291 struct usb_device *udev = serial->dev; 1078 struct usb_device *udev = serial->dev;
1292 struct usb_interface *interface = serial->interface; 1079 struct usb_interface *interface = serial->interface;
@@ -1294,7 +1081,7 @@ static int ftdi_olimex_probe(struct usb_serial *serial)
1294 dbg("%s",__FUNCTION__); 1081 dbg("%s",__FUNCTION__);
1295 1082
1296 if (interface == udev->actconfig->interface[0]) { 1083 if (interface == udev->actconfig->interface[0]) {
1297 info("Ignoring reserved serial port on Olimex arm-usb-ocd\n"); 1084 info("Ignoring serial port reserved for JTAG");
1298 return -ENODEV; 1085 return -ENODEV;
1299 } 1086 }
1300 1087
@@ -1411,7 +1198,8 @@ static void ftdi_close (struct usb_serial_port *port, struct file *filp)
1411 1198
1412 dbg("%s", __FUNCTION__); 1199 dbg("%s", __FUNCTION__);
1413 1200
1414 if (c_cflag & HUPCL){ 1201 mutex_lock(&port->serial->disc_mutex);
1202 if (c_cflag & HUPCL && !port->serial->disconnected){
1415 /* Disable flow control */ 1203 /* Disable flow control */
1416 if (usb_control_msg(port->serial->dev, 1204 if (usb_control_msg(port->serial->dev,
1417 usb_sndctrlpipe(port->serial->dev, 0), 1205 usb_sndctrlpipe(port->serial->dev, 0),
@@ -1425,6 +1213,7 @@ static void ftdi_close (struct usb_serial_port *port, struct file *filp)
1425 /* drop RTS and DTR */ 1213 /* drop RTS and DTR */
1426 clear_mctrl(port, TIOCM_DTR | TIOCM_RTS); 1214 clear_mctrl(port, TIOCM_DTR | TIOCM_RTS);
1427 } /* Note change no line if hupcl is off */ 1215 } /* Note change no line if hupcl is off */
1216 mutex_unlock(&port->serial->disc_mutex);
1428 1217
1429 /* cancel any scheduled reading */ 1218 /* cancel any scheduled reading */
1430 cancel_delayed_work(&priv->rx_work); 1219 cancel_delayed_work(&priv->rx_work);
diff --git a/drivers/usb/serial/ftdi_sio.h b/drivers/usb/serial/ftdi_sio.h
index b51cbb0eaa05..6eee2ab914ec 100644
--- a/drivers/usb/serial/ftdi_sio.h
+++ b/drivers/usb/serial/ftdi_sio.h
@@ -98,6 +98,10 @@
98#define FTDI_MTXORB_5_PID 0xFA05 /* Matrix Orbital Product Id */ 98#define FTDI_MTXORB_5_PID 0xFA05 /* Matrix Orbital Product Id */
99#define FTDI_MTXORB_6_PID 0xFA06 /* Matrix Orbital Product Id */ 99#define FTDI_MTXORB_6_PID 0xFA06 /* Matrix Orbital Product Id */
100 100
101/* OOCDlink by Joern Kaipf <joernk@web.de>
102 * (http://www.joernonline.de/dw/doku.php?id=start&idx=projects:oocdlink) */
103#define FTDI_OOCDLINK_PID 0xbaf8 /* Amontec JTAGkey */
104
101/* Interbiometrics USB I/O Board */ 105/* Interbiometrics USB I/O Board */
102/* Developed for Interbiometrics by Rudolf Gugler */ 106/* Developed for Interbiometrics by Rudolf Gugler */
103#define INTERBIOMETRICS_VID 0x1209 107#define INTERBIOMETRICS_VID 0x1209
@@ -245,6 +249,7 @@
245#define FTDI_ELV_WS300PC_PID 0xE0F6 /* PC-Wetterstation (WS 300 PC) */ 249#define FTDI_ELV_WS300PC_PID 0xE0F6 /* PC-Wetterstation (WS 300 PC) */
246#define FTDI_ELV_FHZ1300PC_PID 0xE0E8 /* FHZ 1300 PC */ 250#define FTDI_ELV_FHZ1300PC_PID 0xE0E8 /* FHZ 1300 PC */
247#define FTDI_ELV_WS500_PID 0xE0E9 /* PC-Wetterstation (WS 500) */ 251#define FTDI_ELV_WS500_PID 0xE0E9 /* PC-Wetterstation (WS 500) */
252#define FTDI_ELV_EM1010PC_PID 0xE0EF /* Engery monitor EM 1010 PC */
248 253
249/* 254/*
250 * Definitions for ID TECH (www.idt-net.com) devices 255 * Definitions for ID TECH (www.idt-net.com) devices
@@ -278,6 +283,7 @@
278#define FTDI_ATIK_ATK16C_PID 0xDF32 /* ATIK ATK-16C Colour Camera */ 283#define FTDI_ATIK_ATK16C_PID 0xDF32 /* ATIK ATK-16C Colour Camera */
279#define FTDI_ATIK_ATK16HR_PID 0xDF31 /* ATIK ATK-16HR Grayscale Camera */ 284#define FTDI_ATIK_ATK16HR_PID 0xDF31 /* ATIK ATK-16HR Grayscale Camera */
280#define FTDI_ATIK_ATK16HRC_PID 0xDF33 /* ATIK ATK-16HRC Colour Camera */ 285#define FTDI_ATIK_ATK16HRC_PID 0xDF33 /* ATIK ATK-16HRC Colour Camera */
286#define FTDI_ATIK_ATK16IC_PID 0xDF35 /* ATIK ATK-16IC Grayscale Camera */
281 287
282/* 288/*
283 * Protego product ids 289 * Protego product ids
@@ -534,6 +540,8 @@
534#define OLIMEX_VID 0x15BA 540#define OLIMEX_VID 0x15BA
535#define OLIMEX_ARM_USB_OCD_PID 0x0003 541#define OLIMEX_ARM_USB_OCD_PID 0x0003
536 542
543/* www.elsterelectricity.com Elster Unicom III Optical Probe */
544#define FTDI_ELSTER_UNICOM_PID 0xE700 /* Product Id */
537 545
538/* 546/*
539 * The Mobility Lab (TML) 547 * The Mobility Lab (TML)
@@ -556,6 +564,13 @@
556 564
557 565
558/* 566/*
567 * FIC / OpenMoko, Inc. http://wiki.openmoko.org/wiki/Neo1973_Debug_Board_v3
568 * Submitted by Harald Welte <laforge@openmoko.org>
569 */
570#define FIC_VID 0x1457
571#define FIC_NEO1973_DEBUG_PID 0x5118
572
573/*
559 * BmRequestType: 1100 0000b 574 * BmRequestType: 1100 0000b
560 * bRequest: FTDI_E2_READ 575 * bRequest: FTDI_E2_READ
561 * wValue: 0 576 * wValue: 0
diff --git a/drivers/usb/serial/garmin_gps.c b/drivers/usb/serial/garmin_gps.c
index f1c90cfe7251..d74e43d69230 100644
--- a/drivers/usb/serial/garmin_gps.c
+++ b/drivers/usb/serial/garmin_gps.c
@@ -1020,19 +1020,26 @@ static void garmin_close (struct usb_serial_port *port, struct file * filp)
1020 if (!serial) 1020 if (!serial)
1021 return; 1021 return;
1022 1022
1023 garmin_clear(garmin_data_p); 1023 mutex_lock(&port->serial->disc_mutex);
1024 if (!port->serial->disconnected)
1025 garmin_clear(garmin_data_p);
1024 1026
1025 /* shutdown our urbs */ 1027 /* shutdown our urbs */
1026 usb_kill_urb (port->read_urb); 1028 usb_kill_urb (port->read_urb);
1027 usb_kill_urb (port->write_urb); 1029 usb_kill_urb (port->write_urb);
1028 1030
1029 if (noResponseFromAppLayer(garmin_data_p) || 1031 if (!port->serial->disconnected) {
1030 ((garmin_data_p->flags & CLEAR_HALT_REQUIRED) != 0)) { 1032 if (noResponseFromAppLayer(garmin_data_p) ||
1031 process_resetdev_request(port); 1033 ((garmin_data_p->flags & CLEAR_HALT_REQUIRED) != 0)) {
1032 garmin_data_p->state = STATE_RESET; 1034 process_resetdev_request(port);
1035 garmin_data_p->state = STATE_RESET;
1036 } else {
1037 garmin_data_p->state = STATE_DISCONNECTED;
1038 }
1033 } else { 1039 } else {
1034 garmin_data_p->state = STATE_DISCONNECTED; 1040 garmin_data_p->state = STATE_DISCONNECTED;
1035 } 1041 }
1042 mutex_unlock(&port->serial->disc_mutex);
1036} 1043}
1037 1044
1038 1045
diff --git a/drivers/usb/serial/generic.c b/drivers/usb/serial/generic.c
index d41531139c55..97fa3c428435 100644
--- a/drivers/usb/serial/generic.c
+++ b/drivers/usb/serial/generic.c
@@ -175,6 +175,14 @@ int usb_serial_generic_resume(struct usb_serial *serial)
175 struct usb_serial_port *port; 175 struct usb_serial_port *port;
176 int i, c = 0, r; 176 int i, c = 0, r;
177 177
178#ifdef CONFIG_PM
179 /*
180 * If this is an autoresume, don't submit URBs.
181 * They will be submitted in the open function instead.
182 */
183 if (serial->dev->auto_pm)
184 return 0;
185#endif
178 for (i = 0; i < serial->num_ports; i++) { 186 for (i = 0; i < serial->num_ports; i++) {
179 port = serial->port[i]; 187 port = serial->port[i];
180 if (port->open_count && port->read_urb) { 188 if (port->open_count && port->read_urb) {
diff --git a/drivers/usb/serial/io_edgeport.c b/drivers/usb/serial/io_edgeport.c
index a5d2e115e167..3428ccc28da7 100644
--- a/drivers/usb/serial/io_edgeport.c
+++ b/drivers/usb/serial/io_edgeport.c
@@ -959,7 +959,7 @@ static int edge_open (struct usb_serial_port *port, struct file * filp)
959 * 959 *
960 * This function will block the close until one of the following: 960 * This function will block the close until one of the following:
961 * 1. Response to our Chase comes from Edgeport 961 * 1. Response to our Chase comes from Edgeport
962 * 2. A timout of 10 seconds without activity has expired 962 * 2. A timeout of 10 seconds without activity has expired
963 * (1K of Edgeport data @ 2400 baud ==> 4 sec to empty) 963 * (1K of Edgeport data @ 2400 baud ==> 4 sec to empty)
964 * 964 *
965 ************************************************************************/ 965 ************************************************************************/
@@ -999,7 +999,7 @@ static void block_until_chase_response(struct edgeport_port *edge_port)
999 return; 999 return;
1000 } 1000 }
1001 } else { 1001 } else {
1002 // Reset timout value back to 10 seconds 1002 // Reset timeout value back to 10 seconds
1003 dbg("%s - Last %d, Current %d", __FUNCTION__, lastCredits, edge_port->txCredits); 1003 dbg("%s - Last %d, Current %d", __FUNCTION__, lastCredits, edge_port->txCredits);
1004 loop = 10; 1004 loop = 10;
1005 } 1005 }
@@ -1014,7 +1014,7 @@ static void block_until_chase_response(struct edgeport_port *edge_port)
1014 * This function will block the close until one of the following: 1014 * This function will block the close until one of the following:
1015 * 1. TX count are 0 1015 * 1. TX count are 0
1016 * 2. The edgeport has stopped 1016 * 2. The edgeport has stopped
1017 * 3. A timout of 3 seconds without activity has expired 1017 * 3. A timeout of 3 seconds without activity has expired
1018 * 1018 *
1019 ************************************************************************/ 1019 ************************************************************************/
1020static void block_until_tx_empty (struct edgeport_port *edge_port) 1020static void block_until_tx_empty (struct edgeport_port *edge_port)
@@ -1050,7 +1050,7 @@ static void block_until_tx_empty (struct edgeport_port *edge_port)
1050 return; 1050 return;
1051 } 1051 }
1052 } else { 1052 } else {
1053 // Reset timout value back to seconds 1053 // Reset timeout value back to seconds
1054 loop = 30; 1054 loop = 30;
1055 } 1055 }
1056 } 1056 }
diff --git a/drivers/usb/serial/io_ti.c b/drivers/usb/serial/io_ti.c
index b8670905bc3a..cd3405953f74 100644
--- a/drivers/usb/serial/io_ti.c
+++ b/drivers/usb/serial/io_ti.c
@@ -34,6 +34,7 @@
34#include <linux/tty_flip.h> 34#include <linux/tty_flip.h>
35#include <linux/module.h> 35#include <linux/module.h>
36#include <linux/spinlock.h> 36#include <linux/spinlock.h>
37#include <linux/mutex.h>
37#include <linux/serial.h> 38#include <linux/serial.h>
38#include <linux/ioctl.h> 39#include <linux/ioctl.h>
39#include <asm/uaccess.h> 40#include <asm/uaccess.h>
@@ -133,7 +134,7 @@ struct edgeport_serial {
133 struct product_info product_info; 134 struct product_info product_info;
134 u8 TI_I2C_Type; // Type of I2C in UMP 135 u8 TI_I2C_Type; // Type of I2C in UMP
135 u8 TiReadI2C; // Set to TRUE if we have read the I2c in Boot Mode 136 u8 TiReadI2C; // Set to TRUE if we have read the I2c in Boot Mode
136 struct semaphore es_sem; 137 struct mutex es_lock;
137 int num_ports_open; 138 int num_ports_open;
138 struct usb_serial *serial; 139 struct usb_serial *serial;
139}; 140};
@@ -1978,7 +1979,7 @@ static int edge_open (struct usb_serial_port *port, struct file * filp)
1978 } 1979 }
1979 1980
1980 /* set up the port settings */ 1981 /* set up the port settings */
1981 edge_set_termios (port, NULL); 1982 edge_set_termios (port, port->tty->termios);
1982 1983
1983 /* open up the port */ 1984 /* open up the port */
1984 1985
@@ -2044,7 +2045,7 @@ static int edge_open (struct usb_serial_port *port, struct file * filp)
2044 dbg ("ShadowMCR 0x%X", edge_port->shadow_mcr); 2045 dbg ("ShadowMCR 0x%X", edge_port->shadow_mcr);
2045 2046
2046 edge_serial = edge_port->edge_serial; 2047 edge_serial = edge_port->edge_serial;
2047 if (down_interruptible(&edge_serial->es_sem)) 2048 if (mutex_lock_interruptible(&edge_serial->es_lock))
2048 return -ERESTARTSYS; 2049 return -ERESTARTSYS;
2049 if (edge_serial->num_ports_open == 0) { 2050 if (edge_serial->num_ports_open == 0) {
2050 /* we are the first port to be opened, let's post the interrupt urb */ 2051 /* we are the first port to be opened, let's post the interrupt urb */
@@ -2052,7 +2053,7 @@ static int edge_open (struct usb_serial_port *port, struct file * filp)
2052 if (!urb) { 2053 if (!urb) {
2053 dev_err (&port->dev, "%s - no interrupt urb present, exiting\n", __FUNCTION__); 2054 dev_err (&port->dev, "%s - no interrupt urb present, exiting\n", __FUNCTION__);
2054 status = -EINVAL; 2055 status = -EINVAL;
2055 goto up_es_sem; 2056 goto release_es_lock;
2056 } 2057 }
2057 urb->complete = edge_interrupt_callback; 2058 urb->complete = edge_interrupt_callback;
2058 urb->context = edge_serial; 2059 urb->context = edge_serial;
@@ -2060,7 +2061,7 @@ static int edge_open (struct usb_serial_port *port, struct file * filp)
2060 status = usb_submit_urb (urb, GFP_KERNEL); 2061 status = usb_submit_urb (urb, GFP_KERNEL);
2061 if (status) { 2062 if (status) {
2062 dev_err (&port->dev, "%s - usb_submit_urb failed with value %d\n", __FUNCTION__, status); 2063 dev_err (&port->dev, "%s - usb_submit_urb failed with value %d\n", __FUNCTION__, status);
2063 goto up_es_sem; 2064 goto release_es_lock;
2064 } 2065 }
2065 } 2066 }
2066 2067
@@ -2092,13 +2093,13 @@ static int edge_open (struct usb_serial_port *port, struct file * filp)
2092 2093
2093 dbg("%s - exited", __FUNCTION__); 2094 dbg("%s - exited", __FUNCTION__);
2094 2095
2095 goto up_es_sem; 2096 goto release_es_lock;
2096 2097
2097unlink_int_urb: 2098unlink_int_urb:
2098 if (edge_port->edge_serial->num_ports_open == 0) 2099 if (edge_port->edge_serial->num_ports_open == 0)
2099 usb_kill_urb(port->serial->port[0]->interrupt_in_urb); 2100 usb_kill_urb(port->serial->port[0]->interrupt_in_urb);
2100up_es_sem: 2101release_es_lock:
2101 up(&edge_serial->es_sem); 2102 mutex_unlock(&edge_serial->es_lock);
2102 return status; 2103 return status;
2103} 2104}
2104 2105
@@ -2137,14 +2138,14 @@ static void edge_close (struct usb_serial_port *port, struct file *filp)
2137 0, 2138 0,
2138 NULL, 2139 NULL,
2139 0); 2140 0);
2140 down(&edge_serial->es_sem); 2141 mutex_lock(&edge_serial->es_lock);
2141 --edge_port->edge_serial->num_ports_open; 2142 --edge_port->edge_serial->num_ports_open;
2142 if (edge_port->edge_serial->num_ports_open <= 0) { 2143 if (edge_port->edge_serial->num_ports_open <= 0) {
2143 /* last port is now closed, let's shut down our interrupt urb */ 2144 /* last port is now closed, let's shut down our interrupt urb */
2144 usb_kill_urb(port->serial->port[0]->interrupt_in_urb); 2145 usb_kill_urb(port->serial->port[0]->interrupt_in_urb);
2145 edge_port->edge_serial->num_ports_open = 0; 2146 edge_port->edge_serial->num_ports_open = 0;
2146 } 2147 }
2147 up(&edge_serial->es_sem); 2148 mutex_unlock(&edge_serial->es_lock);
2148 edge_port->close_pending = 0; 2149 edge_port->close_pending = 0;
2149 2150
2150 dbg("%s - exited", __FUNCTION__); 2151 dbg("%s - exited", __FUNCTION__);
@@ -2393,11 +2394,6 @@ static void change_port_settings (struct edgeport_port *edge_port, struct ktermi
2393 dbg("%s - port %d", __FUNCTION__, edge_port->port->number); 2394 dbg("%s - port %d", __FUNCTION__, edge_port->port->number);
2394 2395
2395 tty = edge_port->port->tty; 2396 tty = edge_port->port->tty;
2396 if ((!tty) ||
2397 (!tty->termios)) {
2398 dbg("%s - no tty structures", __FUNCTION__);
2399 return;
2400 }
2401 2397
2402 config = kmalloc (sizeof (*config), GFP_KERNEL); 2398 config = kmalloc (sizeof (*config), GFP_KERNEL);
2403 if (!config) { 2399 if (!config) {
@@ -2492,15 +2488,21 @@ static void change_port_settings (struct edgeport_port *edge_port, struct ktermi
2492 } 2488 }
2493 } 2489 }
2494 2490
2491 tty->termios->c_cflag &= ~CMSPAR;
2492
2495 /* Round the baud rate */ 2493 /* Round the baud rate */
2496 baud = tty_get_baud_rate(tty); 2494 baud = tty_get_baud_rate(tty);
2497 if (!baud) { 2495 if (!baud) {
2498 /* pick a default, any default... */ 2496 /* pick a default, any default... */
2499 baud = 9600; 2497 baud = 9600;
2500 } 2498 } else
2499 tty_encode_baud_rate(tty, baud, baud);
2500
2501 edge_port->baud_rate = baud; 2501 edge_port->baud_rate = baud;
2502 config->wBaudRate = (__u16)((461550L + baud/2) / baud); 2502 config->wBaudRate = (__u16)((461550L + baud/2) / baud);
2503 2503
2504 /* FIXME: Recompute actual baud from divisor here */
2505
2504 dbg ("%s - baud rate = %d, wBaudRate = %d", __FUNCTION__, baud, config->wBaudRate); 2506 dbg ("%s - baud rate = %d, wBaudRate = %d", __FUNCTION__, baud, config->wBaudRate);
2505 2507
2506 dbg ("wBaudRate: %d", (int)(461550L / config->wBaudRate)); 2508 dbg ("wBaudRate: %d", (int)(461550L / config->wBaudRate));
@@ -2538,19 +2540,12 @@ static void edge_set_termios (struct usb_serial_port *port, struct ktermios *old
2538 struct tty_struct *tty = port->tty; 2540 struct tty_struct *tty = port->tty;
2539 unsigned int cflag; 2541 unsigned int cflag;
2540 2542
2541 if (!port->tty || !port->tty->termios) {
2542 dbg ("%s - no tty or termios", __FUNCTION__);
2543 return;
2544 }
2545
2546 cflag = tty->termios->c_cflag; 2543 cflag = tty->termios->c_cflag;
2547 2544
2548 dbg("%s - clfag %08x iflag %08x", __FUNCTION__, 2545 dbg("%s - clfag %08x iflag %08x", __FUNCTION__,
2549 tty->termios->c_cflag, tty->termios->c_iflag); 2546 tty->termios->c_cflag, tty->termios->c_iflag);
2550 if (old_termios) { 2547 dbg("%s - old clfag %08x old iflag %08x", __FUNCTION__,
2551 dbg("%s - old clfag %08x old iflag %08x", __FUNCTION__, 2548 old_termios->c_cflag, old_termios->c_iflag);
2552 old_termios->c_cflag, old_termios->c_iflag);
2553 }
2554 2549
2555 dbg("%s - port %d", __FUNCTION__, port->number); 2550 dbg("%s - port %d", __FUNCTION__, port->number);
2556 2551
@@ -2743,7 +2738,7 @@ static int edge_startup (struct usb_serial *serial)
2743 dev_err(&serial->dev->dev, "%s - Out of memory\n", __FUNCTION__); 2738 dev_err(&serial->dev->dev, "%s - Out of memory\n", __FUNCTION__);
2744 return -ENOMEM; 2739 return -ENOMEM;
2745 } 2740 }
2746 sema_init(&edge_serial->es_sem, 1); 2741 mutex_init(&edge_serial->es_lock);
2747 edge_serial->serial = serial; 2742 edge_serial->serial = serial;
2748 usb_set_serial_data(serial, edge_serial); 2743 usb_set_serial_data(serial, edge_serial);
2749 2744
diff --git a/drivers/usb/serial/iuu_phoenix.c b/drivers/usb/serial/iuu_phoenix.c
new file mode 100644
index 000000000000..fde188e23ce1
--- /dev/null
+++ b/drivers/usb/serial/iuu_phoenix.c
@@ -0,0 +1,1217 @@
1/*
2 * Infinity Unlimited USB Phoenix driver
3 *
4 * Copyright (C) 2007 Alain Degreffe (eczema@ecze.com)
5 *
6 * Original code taken from iuutool (Copyright (C) 2006 Juan Carlos Borrás)
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 * And tested with help of WB Electronics
14 *
15 */
16#include <linux/kernel.h>
17#include <linux/errno.h>
18#include <linux/init.h>
19#include <linux/slab.h>
20#include <linux/tty.h>
21#include <linux/tty_driver.h>
22#include <linux/tty_flip.h>
23#include <linux/serial.h>
24#include <linux/module.h>
25#include <linux/moduleparam.h>
26#include <linux/spinlock.h>
27#include <linux/uaccess.h>
28#include <linux/usb.h>
29#include <linux/usb/serial.h>
30#include "iuu_phoenix.h"
31#include <linux/random.h>
32
33
34#ifdef CONFIG_USB_SERIAL_DEBUG
35static int debug = 1;
36#else
37static int debug;
38#endif
39
40/*
41 * Version Information
42 */
43#define DRIVER_VERSION "v0.5"
44#define DRIVER_DESC "Infinity USB Unlimited Phoenix driver"
45
46static struct usb_device_id id_table[] = {
47 {USB_DEVICE(IUU_USB_VENDOR_ID, IUU_USB_PRODUCT_ID)},
48 {} /* Terminating entry */
49};
50MODULE_DEVICE_TABLE(usb, id_table);
51
52static struct usb_driver iuu_driver = {
53 .name = "iuu_phoenix",
54 .probe = usb_serial_probe,
55 .disconnect = usb_serial_disconnect,
56 .id_table = id_table,
57 .no_dynamic_id = 1,
58};
59
60/* turbo parameter */
61static int boost = 100;
62static int clockmode = 1;
63static int cdmode = 1;
64static int iuu_cardin;
65static int iuu_cardout;
66static int xmas;
67
68static void read_rxcmd_callback(struct urb *urb);
69
70struct iuu_private {
71 spinlock_t lock; /* store irq state */
72 wait_queue_head_t delta_msr_wait;
73 u8 line_control;
74 u8 line_status;
75 u8 termios_initialized;
76 int tiostatus; /* store IUART SIGNAL for tiocmget call */
77 u8 reset; /* if 1 reset is needed */
78 int poll; /* number of poll */
79 u8 *writebuf; /* buffer for writing to device */
80 int writelen; /* num of byte to write to device */
81 u8 *buf; /* used for initialize speed */
82 u8 *dbgbuf; /* debug buffer */
83 u8 len;
84};
85
86
87static void iuu_free_buf(struct iuu_private *priv)
88{
89 kfree(priv->buf);
90 kfree(priv->dbgbuf);
91 kfree(priv->writebuf);
92}
93
94static int iuu_alloc_buf(struct iuu_private *priv)
95{
96 priv->buf = kzalloc(256, GFP_KERNEL);
97 priv->dbgbuf = kzalloc(256, GFP_KERNEL);
98 priv->writebuf = kzalloc(256, GFP_KERNEL);
99 if (!priv->buf || !priv->dbgbuf || !priv->writebuf) {
100 iuu_free_buf(priv);
101 dbg("%s problem allocation buffer", __FUNCTION__);
102 return -ENOMEM;
103 }
104 dbg("%s - Privates buffers allocation success", __FUNCTION__);
105 return 0;
106}
107
108static int iuu_startup(struct usb_serial *serial)
109{
110 struct iuu_private *priv;
111 priv = kzalloc(sizeof(struct iuu_private), GFP_KERNEL);
112 dbg("%s- priv allocation success", __FUNCTION__);
113 if (!priv)
114 return -ENOMEM;
115 if (iuu_alloc_buf(priv)) {
116 kfree(priv);
117 return -ENOMEM;
118 }
119 spin_lock_init(&priv->lock);
120 init_waitqueue_head(&priv->delta_msr_wait);
121 usb_set_serial_port_data(serial->port[0], priv);
122 return 0;
123}
124
125/* Shutdown function */
126static void iuu_shutdown(struct usb_serial *serial)
127{
128 struct usb_serial_port *port = serial->port[0];
129 struct iuu_private *priv = usb_get_serial_port_data(port);
130 if (!port)
131 return;
132
133 dbg("%s", __FUNCTION__);
134
135 if (priv) {
136 iuu_free_buf(priv);
137 dbg("%s - I will free all", __FUNCTION__);
138 usb_set_serial_port_data(port, NULL);
139
140 dbg("%s - priv is not anymore in port structure", __FUNCTION__);
141 kfree(priv);
142
143 dbg("%s priv is now kfree", __FUNCTION__);
144 }
145}
146
147static int iuu_tiocmset(struct usb_serial_port *port, struct file *file,
148 unsigned int set, unsigned int clear)
149{
150 struct iuu_private *priv = usb_get_serial_port_data(port);
151 struct tty_struct *tty;
152 tty = port->tty;
153
154 dbg("%s (%d) msg : SET = 0x%04x, CLEAR = 0x%04x ", __FUNCTION__,
155 port->number, set, clear);
156 if (set & TIOCM_RTS)
157 priv->tiostatus = TIOCM_RTS;
158
159 if (!(set & TIOCM_RTS) && priv->tiostatus == TIOCM_RTS) {
160 dbg("%s TIOCMSET RESET called !!!", __FUNCTION__);
161 priv->reset = 1;
162 return 0;
163 }
164
165 return 0;
166}
167
168/* This is used to provide a carrier detect mechanism
169 * When a card is present, the response is 0x00
170 * When no card , the reader respond with TIOCM_CD
171 * This is known as CD autodetect mechanism
172 */
173static int iuu_tiocmget(struct usb_serial_port *port, struct file *file)
174{
175 struct iuu_private *priv = usb_get_serial_port_data(port);
176 return priv->tiostatus;
177}
178
179static void iuu_rxcmd(struct urb *urb)
180{
181 struct usb_serial_port *port = (struct usb_serial_port *)urb->context;
182 int result;
183 dbg("%s - enter", __FUNCTION__);
184
185 if (urb->status) {
186 dbg("%s - urb->status = %d", __FUNCTION__, urb->status);
187 /* error stop all */
188 return;
189 }
190
191
192 memset(port->write_urb->transfer_buffer, IUU_UART_RX, 1);
193 usb_fill_bulk_urb(port->write_urb, port->serial->dev,
194 usb_sndbulkpipe(port->serial->dev,
195 port->bulk_out_endpointAddress),
196 port->write_urb->transfer_buffer, 1,
197 read_rxcmd_callback, port);
198 result = usb_submit_urb(port->write_urb, GFP_ATOMIC);
199}
200
201static int iuu_reset(struct usb_serial_port *port, u8 wt)
202{
203 struct iuu_private *priv = usb_get_serial_port_data(port);
204 int result;
205 char *buf_ptr = port->write_urb->transfer_buffer;
206 dbg("%s - enter", __FUNCTION__);
207
208 /* Prepare the reset sequence */
209
210 *buf_ptr++ = IUU_RST_SET;
211 *buf_ptr++ = IUU_DELAY_MS;
212 *buf_ptr++ = wt;
213 *buf_ptr = IUU_RST_CLEAR;
214
215 /* send the sequence */
216
217 usb_fill_bulk_urb(port->write_urb,
218 port->serial->dev,
219 usb_sndbulkpipe(port->serial->dev,
220 port->bulk_out_endpointAddress),
221 port->write_urb->transfer_buffer, 4, iuu_rxcmd, port);
222 result = usb_submit_urb(port->write_urb, GFP_ATOMIC);
223 priv->reset = 0;
224 return result;
225}
226
227/* Status Function
228 * Return value is
229 * 0x00 = no card
230 * 0x01 = smartcard
231 * 0x02 = sim card
232 */
233static void iuu_update_status_callback(struct urb *urb)
234{
235 struct usb_serial_port *port = (struct usb_serial_port *)urb->context;
236 struct iuu_private *priv = usb_get_serial_port_data(port);
237 u8 *st;
238 dbg("%s - enter", __FUNCTION__);
239
240 if (urb->status) {
241 dbg("%s - urb->status = %d", __FUNCTION__, urb->status);
242 /* error stop all */
243 return;
244 }
245
246 st = urb->transfer_buffer;
247 dbg("%s - enter", __FUNCTION__);
248 if (urb->actual_length == 1) {
249 switch (st[0]) {
250 case 0x1:
251 priv->tiostatus = iuu_cardout;
252 break;
253 case 0x0:
254 priv->tiostatus = iuu_cardin;
255 break;
256 default:
257 priv->tiostatus = iuu_cardin;
258 }
259 }
260 iuu_rxcmd(urb);
261}
262
263static void iuu_status_callback(struct urb *urb)
264{
265 struct usb_serial_port *port = (struct usb_serial_port *)urb->context;
266 int result;
267 dbg("%s - enter", __FUNCTION__);
268
269 dbg("%s - urb->status = %d", __FUNCTION__, urb->status);
270 usb_fill_bulk_urb(port->read_urb, port->serial->dev,
271 usb_rcvbulkpipe(port->serial->dev,
272 port->bulk_in_endpointAddress),
273 port->read_urb->transfer_buffer, 256,
274 iuu_update_status_callback, port);
275 result = usb_submit_urb(port->read_urb, GFP_ATOMIC);
276}
277
278static int iuu_status(struct usb_serial_port *port)
279{
280 int result;
281
282 dbg("%s - enter", __FUNCTION__);
283
284 memset(port->write_urb->transfer_buffer, IUU_GET_STATE_REGISTER, 1);
285 usb_fill_bulk_urb(port->write_urb, port->serial->dev,
286 usb_sndbulkpipe(port->serial->dev,
287 port->bulk_out_endpointAddress),
288 port->write_urb->transfer_buffer, 1,
289 iuu_status_callback, port);
290 result = usb_submit_urb(port->write_urb, GFP_ATOMIC);
291 return result;
292
293}
294
295static int bulk_immediate(struct usb_serial_port *port, u8 *buf, u8 count)
296{
297 int status;
298 struct usb_serial *serial = port->serial;
299 int actual = 0;
300
301 dbg("%s - enter", __FUNCTION__);
302
303 /* send the data out the bulk port */
304
305 status =
306 usb_bulk_msg(serial->dev,
307 usb_sndbulkpipe(serial->dev,
308 port->bulk_out_endpointAddress), buf,
309 count, &actual, HZ * 1);
310
311 if (status != IUU_OPERATION_OK) {
312 dbg("%s - error = %2x", __FUNCTION__, status);
313 } else {
314 dbg("%s - write OK !", __FUNCTION__);
315 }
316 return status;
317}
318
319static int read_immediate(struct usb_serial_port *port, u8 *buf, u8 count)
320{
321 int status;
322 struct usb_serial *serial = port->serial;
323 int actual = 0;
324
325 dbg("%s - enter", __FUNCTION__);
326
327 /* send the data out the bulk port */
328
329 status =
330 usb_bulk_msg(serial->dev,
331 usb_rcvbulkpipe(serial->dev,
332 port->bulk_in_endpointAddress), buf,
333 count, &actual, HZ * 1);
334
335 if (status != IUU_OPERATION_OK) {
336 dbg("%s - error = %2x", __FUNCTION__, status);
337 } else {
338 dbg("%s - read OK !", __FUNCTION__);
339 }
340
341 return status;
342}
343
344static int iuu_led(struct usb_serial_port *port, unsigned int R,
345 unsigned int G, unsigned int B, u8 f)
346{
347 int status;
348 u8 *buf;
349 buf = kmalloc(8, GFP_KERNEL);
350 if (!buf)
351 return -ENOMEM;
352
353 dbg("%s - enter", __FUNCTION__);
354
355 buf[0] = IUU_SET_LED;
356 buf[1] = R & 0xFF;
357 buf[2] = (R >> 8) & 0xFF;
358 buf[3] = G & 0xFF;
359 buf[4] = (G >> 8) & 0xFF;
360 buf[5] = B & 0xFF;
361 buf[6] = (B >> 8) & 0xFF;
362 buf[7] = f;
363 status = bulk_immediate(port, buf, 8);
364 kfree(buf);
365 if (status != IUU_OPERATION_OK)
366 dbg("%s - led error status = %2x", __FUNCTION__, status);
367 else
368 dbg("%s - led OK !", __FUNCTION__);
369 return IUU_OPERATION_OK;
370}
371
372static void iuu_rgbf_fill_buffer(u8 *buf, u8 r1, u8 r2, u8 g1, u8 g2, u8 b1,
373 u8 b2, u8 freq)
374{
375 *buf++ = IUU_SET_LED;
376 *buf++ = r1;
377 *buf++ = r2;
378 *buf++ = g1;
379 *buf++ = g2;
380 *buf++ = b1;
381 *buf++ = b2;
382 *buf = freq;
383}
384
385static void iuu_led_activity_on(struct urb *urb)
386{
387 struct usb_serial_port *port = (struct usb_serial_port *)urb->context;
388 int result;
389 char *buf_ptr = port->write_urb->transfer_buffer;
390 *buf_ptr++ = IUU_SET_LED;
391 if (xmas == 1) {
392 get_random_bytes(buf_ptr, 6);
393 *(buf_ptr+7) = 1;
394 } else {
395 iuu_rgbf_fill_buffer(buf_ptr, 255, 255, 0, 0, 0, 0, 255);
396 }
397
398 usb_fill_bulk_urb(port->write_urb, port->serial->dev,
399 usb_sndbulkpipe(port->serial->dev,
400 port->bulk_out_endpointAddress),
401 port->write_urb->transfer_buffer, 8 ,
402 iuu_rxcmd, port);
403 result = usb_submit_urb(port->write_urb, GFP_ATOMIC);
404}
405
406static void iuu_led_activity_off(struct urb *urb)
407{
408 struct usb_serial_port *port = (struct usb_serial_port *)urb->context;
409 int result;
410 char *buf_ptr = port->write_urb->transfer_buffer;
411 if (xmas == 1) {
412 iuu_rxcmd(urb);
413 return;
414 } else {
415 *buf_ptr++ = IUU_SET_LED;
416 iuu_rgbf_fill_buffer(buf_ptr, 0, 0, 255, 255, 0, 0, 255);
417 }
418 usb_fill_bulk_urb(port->write_urb, port->serial->dev,
419 usb_sndbulkpipe(port->serial->dev,
420 port->bulk_out_endpointAddress),
421 port->write_urb->transfer_buffer, 8 ,
422 iuu_rxcmd, port);
423 result = usb_submit_urb(port->write_urb, GFP_ATOMIC);
424}
425
426
427
428static int iuu_clk(struct usb_serial_port *port, int dwFrq)
429{
430 int status;
431 struct iuu_private *priv = usb_get_serial_port_data(port);
432 int Count = 0;
433 u8 FrqGenAdr = 0x69;
434 u8 DIV = 0; /* 8bit */
435 u8 XDRV = 0; /* 8bit */
436 u8 PUMP = 0; /* 3bit */
437 u8 PBmsb = 0; /* 2bit */
438 u8 PBlsb = 0; /* 8bit */
439 u8 PO = 0; /* 1bit */
440 u8 Q = 0; /* 7bit */
441 /* 24bit = 3bytes */
442 unsigned int P = 0;
443 unsigned int P2 = 0;
444 int frq = (int)dwFrq;
445
446 dbg("%s - enter", __FUNCTION__);
447
448 if (frq == 0) {
449 priv->buf[Count++] = IUU_UART_WRITE_I2C;
450 priv->buf[Count++] = FrqGenAdr << 1;
451 priv->buf[Count++] = 0x09;
452 priv->buf[Count++] = 0x00;
453
454 status = bulk_immediate(port, (u8 *) priv->buf, Count);
455 if (status != 0) {
456 dbg("%s - write error ", __FUNCTION__);
457 return status;
458 }
459 } else if (frq == 3579000) {
460 DIV = 100;
461 P = 1193;
462 Q = 40;
463 XDRV = 0;
464 } else if (frq == 3680000) {
465 DIV = 105;
466 P = 161;
467 Q = 5;
468 XDRV = 0;
469 } else if (frq == 6000000) {
470 DIV = 66;
471 P = 66;
472 Q = 2;
473 XDRV = 0x28;
474 } else {
475 unsigned int result = 0;
476 unsigned int tmp = 0;
477 unsigned int check;
478 unsigned int check2;
479 char found = 0x00;
480 unsigned int lQ = 2;
481 unsigned int lP = 2055;
482 unsigned int lDiv = 4;
483
484 for (lQ = 2; lQ <= 47 && !found; lQ++)
485 for (lP = 2055; lP >= 8 && !found; lP--)
486 for (lDiv = 4; lDiv <= 127 && !found; lDiv++) {
487 tmp = (12000000 / lDiv) * (lP / lQ);
488 if (abs((int)(tmp - frq)) <
489 abs((int)(frq - result))) {
490 check2 = (12000000 / lQ);
491 if (check2 < 250000)
492 continue;
493 check = (12000000 / lQ) * lP;
494 if (check > 400000000)
495 continue;
496 if (check < 100000000)
497 continue;
498 if (lDiv < 4 || lDiv > 127)
499 continue;
500 result = tmp;
501 P = lP;
502 DIV = lDiv;
503 Q = lQ;
504 if (result == frq)
505 found = 0x01;
506 }
507 }
508 }
509 P2 = ((P - PO) / 2) - 4;
510 DIV = DIV;
511 PUMP = 0x04;
512 PBmsb = (P2 >> 8 & 0x03);
513 PBlsb = P2 & 0xFF;
514 PO = (P >> 10) & 0x01;
515 Q = Q - 2;
516
517 priv->buf[Count++] = IUU_UART_WRITE_I2C; /* 0x4C */
518 priv->buf[Count++] = FrqGenAdr << 1;
519 priv->buf[Count++] = 0x09;
520 priv->buf[Count++] = 0x20; /* Adr = 0x09 */
521 priv->buf[Count++] = IUU_UART_WRITE_I2C; /* 0x4C */
522 priv->buf[Count++] = FrqGenAdr << 1;
523 priv->buf[Count++] = 0x0C;
524 priv->buf[Count++] = DIV; /* Adr = 0x0C */
525 priv->buf[Count++] = IUU_UART_WRITE_I2C; /* 0x4C */
526 priv->buf[Count++] = FrqGenAdr << 1;
527 priv->buf[Count++] = 0x12;
528 priv->buf[Count++] = XDRV; /* Adr = 0x12 */
529 priv->buf[Count++] = IUU_UART_WRITE_I2C; /* 0x4C */
530 priv->buf[Count++] = FrqGenAdr << 1;
531 priv->buf[Count++] = 0x13;
532 priv->buf[Count++] = 0x6B; /* Adr = 0x13 */
533 priv->buf[Count++] = IUU_UART_WRITE_I2C; /* 0x4C */
534 priv->buf[Count++] = FrqGenAdr << 1;
535 priv->buf[Count++] = 0x40;
536 priv->buf[Count++] = (0xC0 | ((PUMP & 0x07) << 2)) |
537 (PBmsb & 0x03); /* Adr = 0x40 */
538 priv->buf[Count++] = IUU_UART_WRITE_I2C; /* 0x4C */
539 priv->buf[Count++] = FrqGenAdr << 1;
540 priv->buf[Count++] = 0x41;
541 priv->buf[Count++] = PBlsb; /* Adr = 0x41 */
542 priv->buf[Count++] = IUU_UART_WRITE_I2C; /* 0x4C */
543 priv->buf[Count++] = FrqGenAdr << 1;
544 priv->buf[Count++] = 0x42;
545 priv->buf[Count++] = Q | (((PO & 0x01) << 7)); /* Adr = 0x42 */
546 priv->buf[Count++] = IUU_UART_WRITE_I2C; /* 0x4C */
547 priv->buf[Count++] = FrqGenAdr << 1;
548 priv->buf[Count++] = 0x44;
549 priv->buf[Count++] = (char)0xFF; /* Adr = 0x44 */
550 priv->buf[Count++] = IUU_UART_WRITE_I2C; /* 0x4C */
551 priv->buf[Count++] = FrqGenAdr << 1;
552 priv->buf[Count++] = 0x45;
553 priv->buf[Count++] = (char)0xFE; /* Adr = 0x45 */
554 priv->buf[Count++] = IUU_UART_WRITE_I2C; /* 0x4C */
555 priv->buf[Count++] = FrqGenAdr << 1;
556 priv->buf[Count++] = 0x46;
557 priv->buf[Count++] = 0x7F; /* Adr = 0x46 */
558 priv->buf[Count++] = IUU_UART_WRITE_I2C; /* 0x4C */
559 priv->buf[Count++] = FrqGenAdr << 1;
560 priv->buf[Count++] = 0x47;
561 priv->buf[Count++] = (char)0x84; /* Adr = 0x47 */
562
563 status = bulk_immediate(port, (u8 *) priv->buf, Count);
564 if (status != IUU_OPERATION_OK)
565 dbg("%s - write error ", __FUNCTION__);
566 return status;
567}
568
569static int iuu_uart_flush(struct usb_serial_port *port)
570{
571 int i;
572 int status;
573 u8 rxcmd = IUU_UART_RX;
574 struct iuu_private *priv = usb_get_serial_port_data(port);
575
576 dbg("%s - enter", __FUNCTION__);
577
578 if (iuu_led(port, 0xF000, 0, 0, 0xFF) < 0)
579 return -EIO;
580
581 for (i = 0; i < 2; i++) {
582 status = bulk_immediate(port, &rxcmd, 1);
583 if (status != IUU_OPERATION_OK) {
584 dbg("%s - uart_flush_write error", __FUNCTION__);
585 return status;
586 }
587
588 status = read_immediate(port, &priv->len, 1);
589 if (status != IUU_OPERATION_OK) {
590 dbg("%s - uart_flush_read error", __FUNCTION__);
591 return status;
592 }
593
594 if (priv->len > 0) {
595 dbg("%s - uart_flush datalen is : %i ", __FUNCTION__,
596 priv->len);
597 status = read_immediate(port, priv->buf, priv->len);
598 if (status != IUU_OPERATION_OK) {
599 dbg("%s - uart_flush_read error", __FUNCTION__);
600 return status;
601 }
602 }
603 }
604 dbg("%s - uart_flush_read OK!", __FUNCTION__);
605 iuu_led(port, 0, 0xF000, 0, 0xFF);
606 return status;
607}
608
609static void read_buf_callback(struct urb *urb)
610{
611 struct usb_serial_port *port = (struct usb_serial_port *)urb->context;
612 unsigned char *data = urb->transfer_buffer;
613 struct tty_struct *tty;
614 dbg("%s - urb->status = %d", __FUNCTION__, urb->status);
615
616 if (urb->status) {
617 dbg("%s - urb->status = %d", __FUNCTION__, urb->status);
618 if (urb->status == -EPROTO) {
619 /* reschedule needed */
620 }
621 return;
622 }
623
624 dbg("%s - %i chars to write", __FUNCTION__, urb->actual_length);
625 tty = port->tty;
626 if (data == NULL)
627 dbg("%s - data is NULL !!!", __FUNCTION__);
628 if (tty && urb->actual_length && data) {
629 tty_insert_flip_string(tty, data, urb->actual_length);
630 tty_flip_buffer_push(tty);
631 }
632 iuu_led_activity_on(urb);
633}
634
635static int iuu_bulk_write(struct usb_serial_port *port)
636{
637 struct iuu_private *priv = usb_get_serial_port_data(port);
638 unsigned int flags;
639 int result;
640 int i;
641 char *buf_ptr = port->write_urb->transfer_buffer;
642 dbg("%s - enter", __FUNCTION__);
643
644 *buf_ptr++ = IUU_UART_ESC;
645 *buf_ptr++ = IUU_UART_TX;
646 *buf_ptr++ = priv->writelen;
647
648 memcpy(buf_ptr, priv->writebuf,
649 priv->writelen);
650 if (debug == 1) {
651 for (i = 0; i < priv->writelen; i++)
652 sprintf(priv->dbgbuf + i*2 ,
653 "%02X", priv->writebuf[i]);
654 priv->dbgbuf[priv->writelen+i*2] = 0;
655 dbg("%s - writing %i chars : %s", __FUNCTION__,
656 priv->writelen, priv->dbgbuf);
657 }
658 usb_fill_bulk_urb(port->write_urb, port->serial->dev,
659 usb_sndbulkpipe(port->serial->dev,
660 port->bulk_out_endpointAddress),
661 port->write_urb->transfer_buffer, priv->writelen + 3,
662 iuu_rxcmd, port);
663 result = usb_submit_urb(port->write_urb, GFP_ATOMIC);
664 spin_lock_irqsave(&priv->lock, flags);
665 priv->writelen = 0;
666 spin_unlock_irqrestore(&priv->lock, flags);
667 usb_serial_port_softint(port);
668 return result;
669}
670
671static int iuu_read_buf(struct usb_serial_port *port, int len)
672{
673 int result;
674 dbg("%s - enter", __FUNCTION__);
675
676 usb_fill_bulk_urb(port->read_urb, port->serial->dev,
677 usb_rcvbulkpipe(port->serial->dev,
678 port->bulk_in_endpointAddress),
679 port->read_urb->transfer_buffer, len,
680 read_buf_callback, port);
681 result = usb_submit_urb(port->read_urb, GFP_ATOMIC);
682 return result;
683}
684
685static void iuu_uart_read_callback(struct urb *urb)
686{
687 struct usb_serial_port *port = (struct usb_serial_port *)urb->context;
688 struct iuu_private *priv = usb_get_serial_port_data(port);
689 unsigned int flags;
690 int status;
691 int error = 0;
692 int len = 0;
693 unsigned char *data = urb->transfer_buffer;
694 priv->poll++;
695
696 dbg("%s - enter", __FUNCTION__);
697
698 if (urb->status) {
699 dbg("%s - urb->status = %d", __FUNCTION__, urb->status);
700 /* error stop all */
701 return;
702 }
703 if (data == NULL)
704 dbg("%s - data is NULL !!!", __FUNCTION__);
705
706 if (urb->actual_length == 1 && data != NULL)
707 len = (int) data[0];
708
709 if (urb->actual_length > 1) {
710 dbg("%s - urb->actual_length = %i", __FUNCTION__,
711 urb->actual_length);
712 error = 1;
713 return;
714 }
715 /* if len > 0 call readbuf */
716
717 if (len > 0 && error == 0) {
718 dbg("%s - call read buf - len to read is %i ",
719 __FUNCTION__, len);
720 status = iuu_read_buf(port, len);
721 return;
722 }
723 /* need to update status ? */
724 if (priv->poll > 99) {
725 status = iuu_status(port);
726 priv->poll = 0;
727 return;
728 }
729
730 /* reset waiting ? */
731
732 if (priv->reset == 1) {
733 status = iuu_reset(port, 0xC);
734 return;
735 }
736 /* Writebuf is waiting */
737 spin_lock_irqsave(&priv->lock, flags);
738 if (priv->writelen > 0) {
739 spin_unlock_irqrestore(&priv->lock, flags);
740 status = iuu_bulk_write(port);
741 return;
742 }
743 spin_unlock_irqrestore(&priv->lock, flags);
744 /* if nothing to write call again rxcmd */
745 dbg("%s - rxcmd recall", __FUNCTION__);
746 iuu_led_activity_off(urb);
747 return;
748}
749
750static int iuu_uart_write(struct usb_serial_port *port, const u8 *buf,
751 int count)
752{
753 struct iuu_private *priv = usb_get_serial_port_data(port);
754 unsigned int flags;
755 dbg("%s - enter", __FUNCTION__);
756
757 if (count > 256)
758 return -ENOMEM;
759
760 spin_lock_irqsave(&priv->lock, flags);
761 if (priv->writelen > 0) {
762 /* buffer already filled but not commited */
763 spin_unlock_irqrestore(&priv->lock, flags);
764 return (0);
765 }
766 /* fill the buffer */
767 memcpy(priv->writebuf, buf, count);
768 priv->writelen = count;
769 spin_unlock_irqrestore(&priv->lock, flags);
770
771 return (count);
772}
773
774static void read_rxcmd_callback(struct urb *urb)
775{
776 struct usb_serial_port *port = (struct usb_serial_port *)urb->context;
777 int result;
778 dbg("%s - enter", __FUNCTION__);
779
780 dbg("%s - urb->status = %d", __FUNCTION__, urb->status);
781
782 if (urb->status) {
783 dbg("%s - urb->status = %d", __FUNCTION__, urb->status);
784 /* error stop all */
785 return;
786 }
787
788 usb_fill_bulk_urb(port->read_urb, port->serial->dev,
789 usb_rcvbulkpipe(port->serial->dev,
790 port->bulk_in_endpointAddress),
791 port->read_urb->transfer_buffer, 256,
792 iuu_uart_read_callback, port);
793 result = usb_submit_urb(port->read_urb, GFP_ATOMIC);
794 dbg("%s - submit result = %d", __FUNCTION__, result);
795 return;
796}
797
798static int iuu_uart_on(struct usb_serial_port *port)
799{
800 int status;
801 u8 *buf;
802
803 buf = kmalloc(sizeof(u8) * 4, GFP_KERNEL);
804
805 if (!buf)
806 return -ENOMEM;
807
808 buf[0] = IUU_UART_ENABLE;
809 buf[1] = (u8) ((IUU_BAUD_9600 >> 8) & 0x00FF);
810 buf[2] = (u8) (0x00FF & IUU_BAUD_9600);
811 buf[3] = (u8) (0x0F0 & IUU_TWO_STOP_BITS) | (0x07 & IUU_PARITY_EVEN);
812
813 status = bulk_immediate(port, buf, 4);
814 if (status != IUU_OPERATION_OK) {
815 dbg("%s - uart_on error", __FUNCTION__);
816 goto uart_enable_failed;
817 }
818 /* iuu_reset() the card after iuu_uart_on() */
819 status = iuu_uart_flush(port);
820 if (status != IUU_OPERATION_OK)
821 dbg("%s - uart_flush error", __FUNCTION__);
822uart_enable_failed:
823 kfree(buf);
824 return status;
825}
826
827/* Diables the IUU UART (a.k.a. the Phoenix voiderface) */
828static int iuu_uart_off(struct usb_serial_port *port)
829{
830 int status;
831 u8 *buf;
832 buf = kmalloc(1, GFP_KERNEL);
833 if (!buf)
834 return -ENOMEM;
835 buf[0] = IUU_UART_DISABLE;
836
837 status = bulk_immediate(port, buf, 1);
838 if (status != IUU_OPERATION_OK)
839 dbg("%s - uart_off error", __FUNCTION__);
840
841 kfree(buf);
842 return status;
843}
844
845static int iuu_uart_baud(struct usb_serial_port *port, u32 baud,
846 u32 *actual, u8 parity)
847{
848 int status;
849 u8 *dataout;
850 u8 DataCount = 0;
851 u8 T1Frekvens = 0;
852 u8 T1reload = 0;
853 unsigned int T1FrekvensHZ = 0;
854
855 dataout = kmalloc(sizeof(u8) * 5, GFP_KERNEL);
856
857 if (!dataout)
858 return -ENOMEM;
859
860 if (baud < 1200 || baud > 230400) {
861 kfree(dataout);
862 return IUU_INVALID_PARAMETER;
863 }
864 if (baud > 977) {
865 T1Frekvens = 3;
866 T1FrekvensHZ = 500000;
867 }
868
869 if (baud > 3906) {
870 T1Frekvens = 2;
871 T1FrekvensHZ = 2000000;
872 }
873
874 if (baud > 11718) {
875 T1Frekvens = 1;
876 T1FrekvensHZ = 6000000;
877 }
878
879 if (baud > 46875) {
880 T1Frekvens = 0;
881 T1FrekvensHZ = 24000000;
882 }
883
884 T1reload = 256 - (u8) (T1FrekvensHZ / (baud * 2));
885
886 /* magic number here: ENTER_FIRMWARE_UPDATE; */
887 dataout[DataCount++] = IUU_UART_ESC;
888 /* magic number here: CHANGE_BAUD; */
889 dataout[DataCount++] = IUU_UART_CHANGE;
890 dataout[DataCount++] = T1Frekvens;
891 dataout[DataCount++] = T1reload;
892
893 *actual = (T1FrekvensHZ / (256 - T1reload)) / 2;
894
895 switch (parity & 0x0F) {
896 case IUU_PARITY_NONE:
897 dataout[DataCount++] = 0x00;
898 break;
899 case IUU_PARITY_EVEN:
900 dataout[DataCount++] = 0x01;
901 break;
902 case IUU_PARITY_ODD:
903 dataout[DataCount++] = 0x02;
904 break;
905 case IUU_PARITY_MARK:
906 dataout[DataCount++] = 0x03;
907 break;
908 case IUU_PARITY_SPACE:
909 dataout[DataCount++] = 0x04;
910 break;
911 default:
912 kfree(dataout);
913 return IUU_INVALID_PARAMETER;
914 break;
915 }
916
917 switch (parity & 0xF0) {
918 case IUU_ONE_STOP_BIT:
919 dataout[DataCount - 1] |= IUU_ONE_STOP_BIT;
920 break;
921
922 case IUU_TWO_STOP_BITS:
923 dataout[DataCount - 1] |= IUU_TWO_STOP_BITS;
924 break;
925 default:
926 kfree(dataout);
927 return IUU_INVALID_PARAMETER;
928 break;
929 }
930
931 status = bulk_immediate(port, dataout, DataCount);
932 if (status != IUU_OPERATION_OK)
933 dbg("%s - uart_off error", __FUNCTION__);
934 kfree(dataout);
935 return status;
936}
937
938static int set_control_lines(struct usb_device *dev, u8 value)
939{
940 return 0;
941}
942
943static void iuu_close(struct usb_serial_port *port, struct file *filp)
944{
945 /* iuu_led (port,255,0,0,0); */
946 struct usb_serial *serial;
947 struct iuu_private *priv = usb_get_serial_port_data(port);
948 unsigned long flags;
949 unsigned int c_cflag;
950
951 serial = port->serial;
952 if (!serial)
953 return;
954
955 dbg("%s - port %d", __FUNCTION__, port->number);
956
957 iuu_uart_off(port);
958 if (serial->dev) {
959 if (port->tty) {
960 c_cflag = port->tty->termios->c_cflag;
961 if (c_cflag & HUPCL) {
962 /* drop DTR and RTS */
963 priv = usb_get_serial_port_data(port);
964 spin_lock_irqsave(&priv->lock, flags);
965 priv->line_control = 0;
966 spin_unlock_irqrestore(&priv->lock, flags);
967 set_control_lines(port->serial->dev, 0);
968 }
969 }
970 /* free writebuf */
971 /* shutdown our urbs */
972 dbg("%s - shutting down urbs", __FUNCTION__);
973 usb_kill_urb(port->write_urb);
974 usb_kill_urb(port->read_urb);
975 usb_kill_urb(port->interrupt_in_urb);
976 msleep(1000);
977 /* wait one second to free all buffers */
978 iuu_led(port, 0, 0, 0xF000, 0xFF);
979 msleep(1000);
980 usb_reset_device(port->serial->dev);
981 }
982}
983
984static int iuu_open(struct usb_serial_port *port, struct file *filp)
985{
986 struct usb_serial *serial = port->serial;
987 u8 *buf;
988 int result;
989 u32 actual;
990 unsigned long flags;
991 struct iuu_private *priv = usb_get_serial_port_data(port);
992
993 dbg("%s - port %d", __FUNCTION__, port->number);
994 usb_clear_halt(serial->dev, port->write_urb->pipe);
995 usb_clear_halt(serial->dev, port->read_urb->pipe);
996
997 buf = kmalloc(10, GFP_KERNEL);
998 if (buf == NULL)
999 return -ENOMEM;
1000
1001 /* fixup the endpoint buffer size */
1002 kfree(port->bulk_out_buffer);
1003 port->bulk_out_buffer = kmalloc(512, GFP_KERNEL);
1004 port->bulk_out_size = 512;
1005 kfree(port->bulk_in_buffer);
1006 port->bulk_in_buffer = kmalloc(512, GFP_KERNEL);
1007 port->bulk_in_size = 512;
1008
1009 if (!port->bulk_out_buffer || !port->bulk_in_buffer) {
1010 kfree(port->bulk_out_buffer);
1011 kfree(port->bulk_in_buffer);
1012 kfree(buf);
1013 return -ENOMEM;
1014 }
1015
1016 usb_fill_bulk_urb(port->write_urb, port->serial->dev,
1017 usb_sndbulkpipe(port->serial->dev,
1018 port->bulk_out_endpointAddress),
1019 port->bulk_out_buffer, 512,
1020 NULL, NULL);
1021
1022
1023 usb_fill_bulk_urb(port->read_urb, port->serial->dev,
1024 usb_rcvbulkpipe(port->serial->dev,
1025 port->bulk_in_endpointAddress),
1026 port->bulk_in_buffer, 512,
1027 NULL, NULL);
1028
1029 /* set the termios structure */
1030 spin_lock_irqsave(&priv->lock, flags);
1031 if (!priv->termios_initialized) {
1032 *(port->tty->termios) = tty_std_termios;
1033 port->tty->termios->c_cflag = CLOCAL | CREAD | CS8 | B9600
1034 | TIOCM_CTS | CSTOPB | PARENB;
1035 port->tty->termios->c_lflag = 0;
1036 port->tty->termios->c_oflag = 0;
1037 port->tty->termios->c_iflag = 0;
1038 priv->termios_initialized = 1;
1039 port->tty->low_latency = 1;
1040 priv->poll = 0;
1041 }
1042 spin_unlock_irqrestore(&priv->lock, flags);
1043
1044 /* initialize writebuf */
1045#define FISH(a, b, c, d) do { \
1046 result = usb_control_msg(port->serial->dev, \
1047 usb_rcvctrlpipe(port->serial->dev, 0), \
1048 b, a, c, d, buf, 1, 1000); \
1049 dbg("0x%x:0x%x:0x%x:0x%x %d - %x", a, b, c, d, result, \
1050 buf[0]); } while (0);
1051
1052#define SOUP(a, b, c, d) do { \
1053 result = usb_control_msg(port->serial->dev, \
1054 usb_sndctrlpipe(port->serial->dev, 0), \
1055 b, a, c, d, NULL, 0, 1000); \
1056 dbg("0x%x:0x%x:0x%x:0x%x %d", a, b, c, d, result); } while (0)
1057
1058 /* This is not UART related but IUU USB driver related or something */
1059 /* like that. Basically no IUU will accept any commands from the USB */
1060 /* host unless it has received the following message */
1061 /* sprintf(buf ,"%c%c%c%c",0x03,0x02,0x02,0x0); */
1062
1063 SOUP(0x03, 0x02, 0x02, 0x0);
1064 kfree(buf);
1065 iuu_led(port, 0xF000, 0xF000, 0, 0xFF);
1066 iuu_uart_on(port);
1067 if (boost < 100)
1068 boost = 100;
1069 switch (clockmode) {
1070 case 2: /* 3.680 Mhz */
1071 iuu_clk(port, IUU_CLK_3680000 * boost / 100);
1072 result =
1073 iuu_uart_baud(port, 9600 * boost / 100, &actual,
1074 IUU_PARITY_EVEN);
1075 break;
1076 case 3: /* 6.00 Mhz */
1077 iuu_clk(port, IUU_CLK_6000000 * boost / 100);
1078 result =
1079 iuu_uart_baud(port, 16457 * boost / 100, &actual,
1080 IUU_PARITY_EVEN);
1081 break;
1082 default: /* 3.579 Mhz */
1083 iuu_clk(port, IUU_CLK_3579000 * boost / 100);
1084 result =
1085 iuu_uart_baud(port, 9600 * boost / 100, &actual,
1086 IUU_PARITY_EVEN);
1087 }
1088
1089 /* set the cardin cardout signals */
1090 switch (cdmode) {
1091 case 0:
1092 iuu_cardin = 0;
1093 iuu_cardout = 0;
1094 break;
1095 case 1:
1096 iuu_cardin = TIOCM_CD;
1097 iuu_cardout = 0;
1098 break;
1099 case 2:
1100 iuu_cardin = 0;
1101 iuu_cardout = TIOCM_CD;
1102 break;
1103 case 3:
1104 iuu_cardin = TIOCM_DSR;
1105 iuu_cardout = 0;
1106 break;
1107 case 4:
1108 iuu_cardin = 0;
1109 iuu_cardout = TIOCM_DSR;
1110 break;
1111 case 5:
1112 iuu_cardin = TIOCM_CTS;
1113 iuu_cardout = 0;
1114 break;
1115 case 6:
1116 iuu_cardin = 0;
1117 iuu_cardout = TIOCM_CTS;
1118 break;
1119 case 7:
1120 iuu_cardin = TIOCM_RNG;
1121 iuu_cardout = 0;
1122 break;
1123 case 8:
1124 iuu_cardin = 0;
1125 iuu_cardout = TIOCM_RNG;
1126 }
1127
1128 iuu_uart_flush(port);
1129
1130 dbg("%s - initialization done", __FUNCTION__);
1131
1132 memset(port->write_urb->transfer_buffer, IUU_UART_RX, 1);
1133 usb_fill_bulk_urb(port->write_urb, port->serial->dev,
1134 usb_sndbulkpipe(port->serial->dev,
1135 port->bulk_out_endpointAddress),
1136 port->write_urb->transfer_buffer, 1,
1137 read_rxcmd_callback, port);
1138 result = usb_submit_urb(port->write_urb, GFP_KERNEL);
1139
1140 if (result) {
1141 dev_err(&port->dev, "%s - failed submitting read urb,"
1142 " error %d\n", __FUNCTION__, result);
1143 iuu_close(port, NULL);
1144 return -EPROTO;
1145 } else {
1146 dbg("%s - rxcmd OK", __FUNCTION__);
1147 }
1148 return result;
1149}
1150
1151static struct usb_serial_driver iuu_device = {
1152 .driver = {
1153 .owner = THIS_MODULE,
1154 .name = "iuu_phoenix",
1155 },
1156 .id_table = id_table,
1157 .num_interrupt_in = NUM_DONT_CARE,
1158 .num_bulk_in = 1,
1159 .num_bulk_out = 1,
1160 .num_ports = 1,
1161 .open = iuu_open,
1162 .close = iuu_close,
1163 .write = iuu_uart_write,
1164 .read_bulk_callback = iuu_uart_read_callback,
1165 .tiocmget = iuu_tiocmget,
1166 .tiocmset = iuu_tiocmset,
1167 .attach = iuu_startup,
1168 .shutdown = iuu_shutdown,
1169};
1170
1171static int __init iuu_init(void)
1172{
1173 int retval;
1174 retval = usb_serial_register(&iuu_device);
1175 if (retval)
1176 goto failed_usb_serial_register;
1177 retval = usb_register(&iuu_driver);
1178 if (retval)
1179 goto failed_usb_register;
1180 info(DRIVER_DESC " " DRIVER_VERSION);
1181 return 0;
1182failed_usb_register:
1183 usb_serial_deregister(&iuu_device);
1184failed_usb_serial_register:
1185 return retval;
1186}
1187
1188static void __exit iuu_exit(void)
1189{
1190 usb_deregister(&iuu_driver);
1191 usb_serial_deregister(&iuu_device);
1192}
1193
1194module_init(iuu_init);
1195module_exit(iuu_exit);
1196
1197MODULE_AUTHOR("Alain Degreffe eczema@ecze.com");
1198
1199MODULE_DESCRIPTION(DRIVER_DESC);
1200MODULE_LICENSE("GPL");
1201
1202MODULE_VERSION(DRIVER_VERSION);
1203module_param(debug, bool, S_IRUGO | S_IWUSR);
1204MODULE_PARM_DESC(debug, "Debug enabled or not");
1205
1206module_param(xmas, bool, S_IRUGO | S_IWUSR);
1207MODULE_PARM_DESC(xmas, "xmas color enabled or not");
1208
1209module_param(boost, int, S_IRUGO | S_IWUSR);
1210MODULE_PARM_DESC(boost, "overclock boost percent 100 to 500");
1211
1212module_param(clockmode, int, S_IRUGO | S_IWUSR);
1213MODULE_PARM_DESC(clockmode, "1=3Mhz579,2=3Mhz680,3=6Mhz");
1214
1215module_param(cdmode, int, S_IRUGO | S_IWUSR);
1216MODULE_PARM_DESC(cdmode, "Card detect mode 0=none, 1=CD, 2=!CD, 3=DSR, "
1217 "4=!DSR, 5=CTS, 6=!CTS, 7=RING, 8=!RING");
diff --git a/drivers/usb/serial/iuu_phoenix.h b/drivers/usb/serial/iuu_phoenix.h
new file mode 100644
index 000000000000..b82630a3b8fd
--- /dev/null
+++ b/drivers/usb/serial/iuu_phoenix.h
@@ -0,0 +1,122 @@
1/*
2 * Infinity Unlimited USB Phoenix driver
3 *
4 * Copyright (C) 2007 Alain Degreffe (eczema@ecze.com)
5 *
6 *
7 * Original code taken from iuutool ( Copyright (C) 2006 Juan Carlos Borrás )
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * And tested with help of WB Electronics
15 *
16 */
17
18#define IUU_USB_VENDOR_ID 0x104f
19#define IUU_USB_PRODUCT_ID 0x0004
20#define IUU_USB_OP_TIMEOUT 0x0200
21
22/* Programmer commands */
23
24#define IUU_NO_OPERATION 0x00
25#define IUU_GET_FIRMWARE_VERSION 0x01
26#define IUU_GET_PRODUCT_NAME 0x02
27#define IUU_GET_STATE_REGISTER 0x03
28#define IUU_SET_LED 0x04
29#define IUU_WAIT_MUS 0x05
30#define IUU_WAIT_MS 0x06
31#define IUU_GET_LOADER_VERSION 0x50
32#define IUU_RST_SET 0x52
33#define IUU_RST_CLEAR 0x53
34#define IUU_SET_VCC 0x59
35#define IUU_UART_ENABLE 0x49
36#define IUU_UART_DISABLE 0x4A
37#define IUU_UART_WRITE_I2C 0x4C
38#define IUU_UART_ESC 0x5E
39#define IUU_UART_TRAP 0x54
40#define IUU_UART_TRAP_BREAK 0x5B
41#define IUU_UART_RX 0x56
42#define IUU_AVR_ON 0x21
43#define IUU_AVR_OFF 0x22
44#define IUU_AVR_1CLK 0x23
45#define IUU_AVR_RESET 0x24
46#define IUU_AVR_RESET_PC 0x25
47#define IUU_AVR_INC_PC 0x26
48#define IUU_AVR_INCN_PC 0x27
49#define IUU_AVR_PREAD 0x29
50#define IUU_AVR_PREADN 0x2A
51#define IUU_AVR_PWRITE 0x28
52#define IUU_AVR_DREAD 0x2C
53#define IUU_AVR_DREADN 0x2D
54#define IUU_AVR_DWRITE 0x2B
55#define IUU_AVR_PWRITEN 0x2E
56#define IUU_EEPROM_ON 0x37
57#define IUU_EEPROM_OFF 0x38
58#define IUU_EEPROM_WRITE 0x39
59#define IUU_EEPROM_WRITEX 0x3A
60#define IUU_EEPROM_WRITE8 0x3B
61#define IUU_EEPROM_WRITE16 0x3C
62#define IUU_EEPROM_WRITEX32 0x3D
63#define IUU_EEPROM_WRITEX64 0x3E
64#define IUU_EEPROM_READ 0x3F
65#define IUU_EEPROM_READX 0x40
66#define IUU_EEPROM_BREAD 0x41
67#define IUU_EEPROM_BREADX 0x42
68#define IUU_PIC_CMD 0x0A
69#define IUU_PIC_CMD_LOAD 0x0B
70#define IUU_PIC_CMD_READ 0x0C
71#define IUU_PIC_ON 0x0D
72#define IUU_PIC_OFF 0x0E
73#define IUU_PIC_RESET 0x16
74#define IUU_PIC_INC_PC 0x0F
75#define IUU_PIC_INCN_PC 0x10
76#define IUU_PIC_PWRITE 0x11
77#define IUU_PIC_PREAD 0x12
78#define IUU_PIC_PREADN 0x13
79#define IUU_PIC_DWRITE 0x14
80#define IUU_PIC_DREAD 0x15
81#define IUU_UART_NOP 0x00
82#define IUU_UART_CHANGE 0x02
83#define IUU_UART_TX 0x04
84#define IUU_DELAY_MS 0x06
85
86#define IUU_OPERATION_OK 0x00
87#define IUU_DEVICE_NOT_FOUND 0x01
88#define IUU_INVALID_HANDLE 0x02
89#define IUU_INVALID_PARAMETER 0x03
90#define IUU_INVALID_voidERFACE 0x04
91#define IUU_INVALID_REQUEST_LENGTH 0x05
92#define IUU_UART_NOT_ENABLED 0x06
93#define IUU_WRITE_ERROR 0x07
94#define IUU_READ_ERROR 0x08
95#define IUU_TX_ERROR 0x09
96#define IUU_RX_ERROR 0x0A
97
98#define IUU_PARITY_NONE 0x00
99#define IUU_PARITY_EVEN 0x01
100#define IUU_PARITY_ODD 0x02
101#define IUU_PARITY_MARK 0x03
102#define IUU_PARITY_SPACE 0x04
103#define IUU_SC_INSERTED 0x01
104#define IUU_VERIFY_ERROR 0x02
105#define IUU_SIM_INSERTED 0x04
106#define IUU_TWO_STOP_BITS 0x00
107#define IUU_ONE_STOP_BIT 0x20
108#define IUU_BAUD_2400 0x0398
109#define IUU_BAUD_9600 0x0298
110#define IUU_BAUD_19200 0x0164
111#define IUU_BAUD_28800 0x0198
112#define IUU_BAUD_38400 0x01B2
113#define IUU_BAUD_57600 0x0030
114#define IUU_BAUD_115200 0x0098
115#define IUU_CLK_3579000 3579000
116#define IUU_CLK_3680000 3680000
117#define IUU_CLK_6000000 6000000
118#define IUU_FULLCARD_IN 0x01
119#define IUU_DEV_ERROR 0x02
120#define IUU_MINICARD_IN 0x04
121#define IUU_VCC_5V 0x00
122#define IUU_VCC_3V 0x01
diff --git a/drivers/usb/serial/keyspan.c b/drivers/usb/serial/keyspan.c
index 7c069a02c1dd..ea7bba69f4da 100644
--- a/drivers/usb/serial/keyspan.c
+++ b/drivers/usb/serial/keyspan.c
@@ -838,7 +838,7 @@ static void usa49_indat_callback(struct urb *urb)
838 838
839 port = (struct usb_serial_port *) urb->context; 839 port = (struct usb_serial_port *) urb->context;
840 tty = port->tty; 840 tty = port->tty;
841 if (urb->actual_length) { 841 if (tty && urb->actual_length) {
842 /* 0x80 bit is error flag */ 842 /* 0x80 bit is error flag */
843 if ((data[0] & 0x80) == 0) { 843 if ((data[0] & 0x80) == 0) {
844 /* no error on any byte */ 844 /* no error on any byte */
diff --git a/drivers/usb/serial/keyspan_pda.c b/drivers/usb/serial/keyspan_pda.c
index be9ac20a8f10..b1fa5a376e96 100644
--- a/drivers/usb/serial/keyspan_pda.c
+++ b/drivers/usb/serial/keyspan_pda.c
@@ -303,7 +303,7 @@ static void keyspan_pda_rx_unthrottle (struct usb_serial_port *port)
303} 303}
304 304
305 305
306static int keyspan_pda_setbaud (struct usb_serial *serial, int baud) 306static speed_t keyspan_pda_setbaud (struct usb_serial *serial, speed_t baud)
307{ 307{
308 int rc; 308 int rc;
309 int bindex; 309 int bindex;
@@ -319,7 +319,9 @@ static int keyspan_pda_setbaud (struct usb_serial *serial, int baud)
319 case 38400: bindex = 7; break; 319 case 38400: bindex = 7; break;
320 case 57600: bindex = 8; break; 320 case 57600: bindex = 8; break;
321 case 115200: bindex = 9; break; 321 case 115200: bindex = 9; break;
322 default: return -EINVAL; 322 default:
323 bindex = 5; /* Default to 9600 */
324 baud = 9600;
323 } 325 }
324 326
325 /* rather than figure out how to sleep while waiting for this 327 /* rather than figure out how to sleep while waiting for this
@@ -334,7 +336,9 @@ static int keyspan_pda_setbaud (struct usb_serial *serial, int baud)
334 NULL, /* &data */ 336 NULL, /* &data */
335 0, /* size */ 337 0, /* size */
336 2000); /* timeout */ 338 2000); /* timeout */
337 return(rc); 339 if (rc < 0)
340 return 0;
341 return baud;
338} 342}
339 343
340 344
@@ -366,7 +370,7 @@ static void keyspan_pda_set_termios (struct usb_serial_port *port,
366 struct ktermios *old_termios) 370 struct ktermios *old_termios)
367{ 371{
368 struct usb_serial *serial = port->serial; 372 struct usb_serial *serial = port->serial;
369 unsigned int cflag = port->tty->termios->c_cflag; 373 speed_t speed;
370 374
371 /* cflag specifies lots of stuff: number of stop bits, parity, number 375 /* cflag specifies lots of stuff: number of stop bits, parity, number
372 of data bits, baud. What can the device actually handle?: 376 of data bits, baud. What can the device actually handle?:
@@ -388,22 +392,18 @@ static void keyspan_pda_set_termios (struct usb_serial_port *port,
388 392
389 For now, just do baud. */ 393 For now, just do baud. */
390 394
391 switch (cflag & CBAUD) { 395 speed = tty_get_baud_rate(port->tty);
392 /* we could support more values here, just need to calculate 396 speed = keyspan_pda_setbaud(serial, speed);
393 the necessary divisors in the firmware. <asm/termbits.h> 397
394 has the Bnnn constants. */ 398 if (speed == 0) {
395 case B110: keyspan_pda_setbaud(serial, 110); break; 399 dbg("can't handle requested baud rate");
396 case B300: keyspan_pda_setbaud(serial, 300); break; 400 /* It hasn't changed so.. */
397 case B1200: keyspan_pda_setbaud(serial, 1200); break; 401 speed = tty_termios_baud_rate(old_termios);
398 case B2400: keyspan_pda_setbaud(serial, 2400); break;
399 case B4800: keyspan_pda_setbaud(serial, 4800); break;
400 case B9600: keyspan_pda_setbaud(serial, 9600); break;
401 case B19200: keyspan_pda_setbaud(serial, 19200); break;
402 case B38400: keyspan_pda_setbaud(serial, 38400); break;
403 case B57600: keyspan_pda_setbaud(serial, 57600); break;
404 case B115200: keyspan_pda_setbaud(serial, 115200); break;
405 default: dbg("can't handle requested baud rate"); break;
406 } 402 }
403 /* Only speed can change so copy the old h/w parameters
404 then encode the new speed */
405 tty_termios_copy_hw(port->tty->termios, old_termios);
406 tty_encode_baud_rate(port->tty, speed, speed);
407} 407}
408 408
409 409
diff --git a/drivers/usb/serial/kl5kusb105.c b/drivers/usb/serial/kl5kusb105.c
index 90e3216abd1f..55736df7d2f4 100644
--- a/drivers/usb/serial/kl5kusb105.c
+++ b/drivers/usb/serial/kl5kusb105.c
@@ -461,17 +461,21 @@ static void klsi_105_close (struct usb_serial_port *port, struct file *filp)
461 461
462 dbg("%s port %d", __FUNCTION__, port->number); 462 dbg("%s port %d", __FUNCTION__, port->number);
463 463
464 /* send READ_OFF */ 464 mutex_lock(&port->serial->disc_mutex);
465 rc = usb_control_msg (port->serial->dev, 465 if (!port->serial->disconnected) {
466 usb_sndctrlpipe(port->serial->dev, 0), 466 /* send READ_OFF */
467 KL5KUSB105A_SIO_CONFIGURE, 467 rc = usb_control_msg (port->serial->dev,
468 USB_TYPE_VENDOR | USB_DIR_OUT, 468 usb_sndctrlpipe(port->serial->dev, 0),
469 KL5KUSB105A_SIO_CONFIGURE_READ_OFF, 469 KL5KUSB105A_SIO_CONFIGURE,
470 0, /* index */ 470 USB_TYPE_VENDOR | USB_DIR_OUT,
471 NULL, 0, 471 KL5KUSB105A_SIO_CONFIGURE_READ_OFF,
472 KLSI_TIMEOUT); 472 0, /* index */
473 if (rc < 0) 473 NULL, 0,
474 err("Disabling read failed (error = %d)", rc); 474 KLSI_TIMEOUT);
475 if (rc < 0)
476 err("Disabling read failed (error = %d)", rc);
477 }
478 mutex_unlock(&port->serial->disc_mutex);
475 479
476 /* shutdown our bulk reads and writes */ 480 /* shutdown our bulk reads and writes */
477 usb_kill_urb(port->write_urb); 481 usb_kill_urb(port->write_urb);
diff --git a/drivers/usb/serial/kobil_sct.c b/drivers/usb/serial/kobil_sct.c
index aee450246bfd..17b3baead4ad 100644
--- a/drivers/usb/serial/kobil_sct.c
+++ b/drivers/usb/serial/kobil_sct.c
@@ -114,6 +114,7 @@ static struct usb_serial_driver kobil_device = {
114 .usb_driver = &kobil_driver, 114 .usb_driver = &kobil_driver,
115 .id_table = id_table, 115 .id_table = id_table,
116 .num_interrupt_in = NUM_DONT_CARE, 116 .num_interrupt_in = NUM_DONT_CARE,
117 .num_interrupt_out = NUM_DONT_CARE,
117 .num_bulk_in = 0, 118 .num_bulk_in = 0,
118 .num_bulk_out = 0, 119 .num_bulk_out = 0,
119 .num_ports = 1, 120 .num_ports = 1,
diff --git a/drivers/usb/serial/mct_u232.c b/drivers/usb/serial/mct_u232.c
index 0dc99f75bb09..fc1cea4aba13 100644
--- a/drivers/usb/serial/mct_u232.c
+++ b/drivers/usb/serial/mct_u232.c
@@ -182,10 +182,11 @@ struct mct_u232_private {
182/* 182/*
183 * Later day 2.6.0-test kernels have new baud rates like B230400 which 183 * Later day 2.6.0-test kernels have new baud rates like B230400 which
184 * we do not know how to support. We ignore them for the moment. 184 * we do not know how to support. We ignore them for the moment.
185 * XXX Rate-limit the error message, it's user triggerable.
186 */ 185 */
187static int mct_u232_calculate_baud_rate(struct usb_serial *serial, speed_t value) 186static int mct_u232_calculate_baud_rate(struct usb_serial *serial, speed_t value, speed_t *result)
188{ 187{
188 *result = value;
189
189 if (le16_to_cpu(serial->dev->descriptor.idProduct) == MCT_U232_SITECOM_PID 190 if (le16_to_cpu(serial->dev->descriptor.idProduct) == MCT_U232_SITECOM_PID
190 || le16_to_cpu(serial->dev->descriptor.idProduct) == MCT_U232_BELKIN_F5U109_PID) { 191 || le16_to_cpu(serial->dev->descriptor.idProduct) == MCT_U232_BELKIN_F5U109_PID) {
191 switch (value) { 192 switch (value) {
@@ -200,11 +201,13 @@ static int mct_u232_calculate_baud_rate(struct usb_serial *serial, speed_t value
200 case 57600: return 0x0b; 201 case 57600: return 0x0b;
201 case 115200: return 0x0c; 202 case 115200: return 0x0c;
202 default: 203 default:
203 err("MCT USB-RS232: unsupported baudrate request 0x%x," 204 *result = 9600;
204 " using default of B9600", value);
205 return 0x08; 205 return 0x08;
206 } 206 }
207 } else { 207 } else {
208 /* FIXME: Can we use any divider - should we do
209 divider = 115200/value;
210 real baud = 115200/divider */
208 switch (value) { 211 switch (value) {
209 case 300: break; 212 case 300: break;
210 case 600: break; 213 case 600: break;
@@ -217,9 +220,8 @@ static int mct_u232_calculate_baud_rate(struct usb_serial *serial, speed_t value
217 case 57600: break; 220 case 57600: break;
218 case 115200: break; 221 case 115200: break;
219 default: 222 default:
220 err("MCT USB-RS232: unsupported baudrate request 0x%x,"
221 " using default of B9600", value);
222 value = 9600; 223 value = 9600;
224 *result = 9600;
223 } 225 }
224 return 115200/value; 226 return 115200/value;
225 } 227 }
@@ -232,16 +234,19 @@ static int mct_u232_set_baud_rate(struct usb_serial *serial, struct usb_serial_p
232 int rc; 234 int rc;
233 unsigned char zero_byte = 0; 235 unsigned char zero_byte = 0;
234 unsigned char cts_enable_byte = 0; 236 unsigned char cts_enable_byte = 0;
237 speed_t speed;
235 238
236 divisor = cpu_to_le32(mct_u232_calculate_baud_rate(serial, value)); 239 divisor = cpu_to_le32(mct_u232_calculate_baud_rate(serial, value, &speed));
237 240
238 rc = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0), 241 rc = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0),
239 MCT_U232_SET_BAUD_RATE_REQUEST, 242 MCT_U232_SET_BAUD_RATE_REQUEST,
240 MCT_U232_SET_REQUEST_TYPE, 243 MCT_U232_SET_REQUEST_TYPE,
241 0, 0, &divisor, MCT_U232_SET_BAUD_RATE_SIZE, 244 0, 0, &divisor, MCT_U232_SET_BAUD_RATE_SIZE,
242 WDR_TIMEOUT); 245 WDR_TIMEOUT);
243 if (rc < 0) 246 if (rc < 0) /*FIXME: What value speed results */
244 err("Set BAUD RATE %d failed (error = %d)", value, rc); 247 err("Set BAUD RATE %d failed (error = %d)", value, rc);
248 else
249 tty_encode_baud_rate(port->tty, speed, speed);
245 dbg("set_baud_rate: value: 0x%x, divisor: 0x%x", value, divisor); 250 dbg("set_baud_rate: value: 0x%x, divisor: 0x%x", value, divisor);
246 251
247 /* Mimic the MCT-supplied Windows driver (version 1.21P.0104), which 252 /* Mimic the MCT-supplied Windows driver (version 1.21P.0104), which
@@ -482,21 +487,22 @@ error:
482static void mct_u232_close (struct usb_serial_port *port, struct file *filp) 487static void mct_u232_close (struct usb_serial_port *port, struct file *filp)
483{ 488{
484 unsigned int c_cflag; 489 unsigned int c_cflag;
485 unsigned long flags;
486 unsigned int control_state; 490 unsigned int control_state;
487 struct mct_u232_private *priv = usb_get_serial_port_data(port); 491 struct mct_u232_private *priv = usb_get_serial_port_data(port);
488 dbg("%s port %d", __FUNCTION__, port->number); 492 dbg("%s port %d", __FUNCTION__, port->number);
489 493
490 if (port->tty) { 494 if (port->tty) {
491 c_cflag = port->tty->termios->c_cflag; 495 c_cflag = port->tty->termios->c_cflag;
492 if (c_cflag & HUPCL) { 496 mutex_lock(&port->serial->disc_mutex);
493 /* drop DTR and RTS */ 497 if (c_cflag & HUPCL && !port->serial->disconnected) {
494 spin_lock_irqsave(&priv->lock, flags); 498 /* drop DTR and RTS */
495 priv->control_state &= ~(TIOCM_DTR | TIOCM_RTS); 499 spin_lock_irq(&priv->lock);
496 control_state = priv->control_state; 500 priv->control_state &= ~(TIOCM_DTR | TIOCM_RTS);
497 spin_unlock_irqrestore(&priv->lock, flags); 501 control_state = priv->control_state;
498 mct_u232_set_modem_ctrl(port->serial, control_state); 502 spin_unlock_irq(&priv->lock);
503 mct_u232_set_modem_ctrl(port->serial, control_state);
499 } 504 }
505 mutex_unlock(&port->serial->disc_mutex);
500 } 506 }
501 507
502 508
@@ -608,7 +614,8 @@ static void mct_u232_set_termios (struct usb_serial_port *port,
608{ 614{
609 struct usb_serial *serial = port->serial; 615 struct usb_serial *serial = port->serial;
610 struct mct_u232_private *priv = usb_get_serial_port_data(port); 616 struct mct_u232_private *priv = usb_get_serial_port_data(port);
611 unsigned int cflag = port->tty->termios->c_cflag; 617 struct ktermios *termios = port->tty->termios;
618 unsigned int cflag = termios->c_cflag;
612 unsigned int old_cflag = old_termios->c_cflag; 619 unsigned int old_cflag = old_termios->c_cflag;
613 unsigned long flags; 620 unsigned long flags;
614 unsigned int control_state; 621 unsigned int control_state;
@@ -670,6 +677,8 @@ static void mct_u232_set_termios (struct usb_serial_port *port,
670 break; 677 break;
671 } 678 }
672 679
680 termios->c_cflag &= ~CMSPAR;
681
673 /* set the number of stop bits */ 682 /* set the number of stop bits */
674 last_lcr |= (cflag & CSTOPB) ? 683 last_lcr |= (cflag & CSTOPB) ?
675 MCT_U232_STOP_BITS_2 : MCT_U232_STOP_BITS_1; 684 MCT_U232_STOP_BITS_2 : MCT_U232_STOP_BITS_1;
diff --git a/drivers/usb/serial/mct_u232.h b/drivers/usb/serial/mct_u232.h
index aae10c8174d6..07b6bec31dc8 100644
--- a/drivers/usb/serial/mct_u232.h
+++ b/drivers/usb/serial/mct_u232.h
@@ -79,7 +79,7 @@
79 * and "Intel solution". They are the regular MCT and "Sitecom" for us. 79 * and "Intel solution". They are the regular MCT and "Sitecom" for us.
80 * This is pointless to document in the header, see the code for the bits. 80 * This is pointless to document in the header, see the code for the bits.
81 */ 81 */
82static int mct_u232_calculate_baud_rate(struct usb_serial *serial, speed_t value); 82static int mct_u232_calculate_baud_rate(struct usb_serial *serial, speed_t value, speed_t *result);
83 83
84/* 84/*
85 * Line Control Register (LCR) 85 * Line Control Register (LCR)
diff --git a/drivers/usb/serial/mos7720.c b/drivers/usb/serial/mos7720.c
index e02c198016b0..40f3a0188807 100644
--- a/drivers/usb/serial/mos7720.c
+++ b/drivers/usb/serial/mos7720.c
@@ -564,22 +564,25 @@ static void mos7720_close(struct usb_serial_port *port, struct file *filp)
564 } 564 }
565 565
566 /* While closing port, shutdown all bulk read, write * 566 /* While closing port, shutdown all bulk read, write *
567 * and interrupt read if they exists */ 567 * and interrupt read if they exists, otherwise nop */
568 if (serial->dev) { 568 dbg("Shutdown bulk write");
569 dbg("Shutdown bulk write"); 569 usb_kill_urb(port->write_urb);
570 usb_kill_urb(port->write_urb); 570 dbg("Shutdown bulk read");
571 dbg("Shutdown bulk read"); 571 usb_kill_urb(port->read_urb);
572 usb_kill_urb(port->read_urb); 572
573 mutex_lock(&serial->disc_mutex);
574 /* these commands must not be issued if the device has
575 * been disconnected */
576 if (!serial->disconnected) {
577 data = 0x00;
578 send_mos_cmd(serial, MOS_WRITE, port->number - port->serial->minor,
579 0x04, &data);
580
581 data = 0x00;
582 send_mos_cmd(serial, MOS_WRITE, port->number - port->serial->minor,
583 0x01, &data);
573 } 584 }
574 585 mutex_unlock(&serial->disc_mutex);
575 data = 0x00;
576 send_mos_cmd(serial, MOS_WRITE, port->number - port->serial->minor,
577 0x04, &data);
578
579 data = 0x00;
580 send_mos_cmd(serial, MOS_WRITE, port->number - port->serial->minor,
581 0x01, &data);
582
583 mos7720_port->open = 0; 586 mos7720_port->open = 0;
584 587
585 dbg("Leaving %s", __FUNCTION__); 588 dbg("Leaving %s", __FUNCTION__);
@@ -1040,11 +1043,6 @@ static void change_port_settings(struct moschip_port *mos7720_port,
1040 1043
1041 tty = mos7720_port->port->tty; 1044 tty = mos7720_port->port->tty;
1042 1045
1043 if ((!tty) || (!tty->termios)) {
1044 dbg("%s - no tty structures", __FUNCTION__);
1045 return;
1046 }
1047
1048 dbg("%s: Entering ..........", __FUNCTION__); 1046 dbg("%s: Entering ..........", __FUNCTION__);
1049 1047
1050 lData = UART_LCR_WLEN8; 1048 lData = UART_LCR_WLEN8;
@@ -1175,7 +1173,10 @@ static void change_port_settings(struct moschip_port *mos7720_port,
1175 1173
1176 dbg("%s - baud rate = %d", __FUNCTION__, baud); 1174 dbg("%s - baud rate = %d", __FUNCTION__, baud);
1177 status = send_cmd_write_baud_rate(mos7720_port, baud); 1175 status = send_cmd_write_baud_rate(mos7720_port, baud);
1178 1176 /* FIXME: needs to write actual resulting baud back not just
1177 blindly do so */
1178 if (cflag & CBAUD)
1179 tty_encode_baud_rate(tty, baud, baud);
1179 /* Enable Interrupts */ 1180 /* Enable Interrupts */
1180 data = 0x0c; 1181 data = 0x0c;
1181 send_mos_cmd(serial, MOS_WRITE, port_number, UART_IER, &data); 1182 send_mos_cmd(serial, MOS_WRITE, port_number, UART_IER, &data);
@@ -1214,10 +1215,6 @@ static void mos7720_set_termios(struct usb_serial_port *port,
1214 1215
1215 tty = port->tty; 1216 tty = port->tty;
1216 1217
1217 if (!port->tty || !port->tty->termios) {
1218 dbg("%s - no tty or termios", __FUNCTION__);
1219 return;
1220 }
1221 1218
1222 if (!mos7720_port->open) { 1219 if (!mos7720_port->open) {
1223 dbg("%s - port not opened", __FUNCTION__); 1220 dbg("%s - port not opened", __FUNCTION__);
@@ -1228,19 +1225,13 @@ static void mos7720_set_termios(struct usb_serial_port *port,
1228 1225
1229 cflag = tty->termios->c_cflag; 1226 cflag = tty->termios->c_cflag;
1230 1227
1231 if (!cflag) { 1228 dbg("%s - cflag %08x iflag %08x", __FUNCTION__,
1232 printk("%s %s\n",__FUNCTION__,"cflag is NULL");
1233 return;
1234 }
1235
1236 dbg("%s - clfag %08x iflag %08x", __FUNCTION__,
1237 tty->termios->c_cflag, 1229 tty->termios->c_cflag,
1238 RELEVANT_IFLAG(tty->termios->c_iflag)); 1230 RELEVANT_IFLAG(tty->termios->c_iflag));
1239 1231
1240 if (old_termios) 1232 dbg("%s - old cflag %08x old iflag %08x", __FUNCTION__,
1241 dbg("%s - old clfag %08x old iflag %08x", __FUNCTION__, 1233 old_termios->c_cflag,
1242 old_termios->c_cflag, 1234 RELEVANT_IFLAG(old_termios->c_iflag));
1243 RELEVANT_IFLAG(old_termios->c_iflag));
1244 1235
1245 dbg("%s - port %d", __FUNCTION__, port->number); 1236 dbg("%s - port %d", __FUNCTION__, port->number);
1246 1237
diff --git a/drivers/usb/serial/mos7840.c b/drivers/usb/serial/mos7840.c
index c29c91271133..869ecd374cb4 100644
--- a/drivers/usb/serial/mos7840.c
+++ b/drivers/usb/serial/mos7840.c
@@ -1133,7 +1133,7 @@ static int mos7840_chars_in_buffer(struct usb_serial_port *port)
1133 * This function will block the close until one of the following: 1133 * This function will block the close until one of the following:
1134 * 1. TX count are 0 1134 * 1. TX count are 0
1135 * 2. The mos7840 has stopped 1135 * 2. The mos7840 has stopped
1136 * 3. A timout of 3 seconds without activity has expired 1136 * 3. A timeout of 3 seconds without activity has expired
1137 * 1137 *
1138 ************************************************************************/ 1138 ************************************************************************/
1139static void mos7840_block_until_tx_empty(struct moschip_port *mos7840_port) 1139static void mos7840_block_until_tx_empty(struct moschip_port *mos7840_port)
@@ -1161,7 +1161,7 @@ static void mos7840_block_until_tx_empty(struct moschip_port *mos7840_port)
1161 dbg("%s - TIMEOUT", __FUNCTION__); 1161 dbg("%s - TIMEOUT", __FUNCTION__);
1162 return; 1162 return;
1163 } else { 1163 } else {
1164 /* Reset timout value back to seconds */ 1164 /* Reset timeout value back to seconds */
1165 wait = 30; 1165 wait = 30;
1166 } 1166 }
1167 } 1167 }
@@ -1275,7 +1275,7 @@ static void mos7840_close(struct usb_serial_port *port, struct file *filp)
1275 * 1275 *
1276 * This function will block the close until one of the following: 1276 * This function will block the close until one of the following:
1277 * 1. Response to our Chase comes from mos7840 1277 * 1. Response to our Chase comes from mos7840
1278 * 2. A timout of 10 seconds without activity has expired 1278 * 2. A timeout of 10 seconds without activity has expired
1279 * (1K of mos7840 data @ 2400 baud ==> 4 sec to empty) 1279 * (1K of mos7840 data @ 2400 baud ==> 4 sec to empty)
1280 * 1280 *
1281 ************************************************************************/ 1281 ************************************************************************/
@@ -1304,7 +1304,7 @@ static void mos7840_block_until_chase_response(struct moschip_port
1304 dbg("%s - TIMEOUT", __FUNCTION__); 1304 dbg("%s - TIMEOUT", __FUNCTION__);
1305 return; 1305 return;
1306 } else { 1306 } else {
1307 /* Reset timout value back to seconds */ 1307 /* Reset timeout value back to seconds */
1308 wait = 10; 1308 wait = 10;
1309 } 1309 }
1310 } 1310 }
diff --git a/drivers/usb/serial/option.c b/drivers/usb/serial/option.c
index d1185f53447b..5e8bf1bc1e50 100644
--- a/drivers/usb/serial/option.c
+++ b/drivers/usb/serial/option.c
@@ -180,6 +180,7 @@ static struct usb_device_id option_ids[] = {
180 { USB_DEVICE(DELL_VENDOR_ID, 0x8117) }, /* Dell Wireless 5700 Mobile Broadband CDMA/EVDO ExpressCard == Novatel Merlin XV620 CDMA/EV-DO */ 180 { USB_DEVICE(DELL_VENDOR_ID, 0x8117) }, /* Dell Wireless 5700 Mobile Broadband CDMA/EVDO ExpressCard == Novatel Merlin XV620 CDMA/EV-DO */
181 { USB_DEVICE(DELL_VENDOR_ID, 0x8118) }, /* Dell Wireless 5510 Mobile Broadband HSDPA ExpressCard == Novatel Merlin XU870 HSDPA/3G */ 181 { USB_DEVICE(DELL_VENDOR_ID, 0x8118) }, /* Dell Wireless 5510 Mobile Broadband HSDPA ExpressCard == Novatel Merlin XU870 HSDPA/3G */
182 { USB_DEVICE(DELL_VENDOR_ID, 0x8128) }, /* Dell Wireless 5700 Mobile Broadband CDMA/EVDO Mini-Card == Novatel Expedite E720 CDMA/EV-DO */ 182 { USB_DEVICE(DELL_VENDOR_ID, 0x8128) }, /* Dell Wireless 5700 Mobile Broadband CDMA/EVDO Mini-Card == Novatel Expedite E720 CDMA/EV-DO */
183 { USB_DEVICE(DELL_VENDOR_ID, 0x8136) }, /* Dell Wireless HSDPA 5520 == Novatel Expedite EU860D */
183 { USB_DEVICE(DELL_VENDOR_ID, 0x8137) }, /* Dell Wireless HSDPA 5520 */ 184 { USB_DEVICE(DELL_VENDOR_ID, 0x8137) }, /* Dell Wireless HSDPA 5520 */
184 { USB_DEVICE(ANYDATA_VENDOR_ID, ANYDATA_PRODUCT_ADU_E100A) }, 185 { USB_DEVICE(ANYDATA_VENDOR_ID, ANYDATA_PRODUCT_ADU_E100A) },
185 { USB_DEVICE(ANYDATA_VENDOR_ID, ANYDATA_PRODUCT_ADU_500A) }, 186 { USB_DEVICE(ANYDATA_VENDOR_ID, ANYDATA_PRODUCT_ADU_500A) },
@@ -640,7 +641,10 @@ static void option_close(struct usb_serial_port *port, struct file *filp)
640 portdata->dtr_state = 0; 641 portdata->dtr_state = 0;
641 642
642 if (serial->dev) { 643 if (serial->dev) {
643 option_send_setup(port); 644 mutex_lock(&serial->disc_mutex);
645 if (!serial->disconnected)
646 option_send_setup(port);
647 mutex_unlock(&serial->disc_mutex);
644 648
645 /* Stop reading/writing urbs */ 649 /* Stop reading/writing urbs */
646 for (i = 0; i < N_IN_URB; i++) 650 for (i = 0; i < N_IN_URB; i++)
diff --git a/drivers/usb/serial/oti6858.c b/drivers/usb/serial/oti6858.c
index eea226ae37bd..a3847d6c946e 100644
--- a/drivers/usb/serial/oti6858.c
+++ b/drivers/usb/serial/oti6858.c
@@ -79,7 +79,7 @@ static int debug;
79#define PL2303_BUF_SIZE 1024 79#define PL2303_BUF_SIZE 1024
80#define PL2303_TMP_BUF_SIZE 1024 80#define PL2303_TMP_BUF_SIZE 1024
81 81
82struct pl2303_buf { 82struct oti6858_buf {
83 unsigned int buf_size; 83 unsigned int buf_size;
84 char *buf_buf; 84 char *buf_buf;
85 char *buf_get; 85 char *buf_get;
@@ -161,14 +161,14 @@ static int oti6858_startup(struct usb_serial *serial);
161static void oti6858_shutdown(struct usb_serial *serial); 161static void oti6858_shutdown(struct usb_serial *serial);
162 162
163/* functions operating on buffers */ 163/* functions operating on buffers */
164static struct pl2303_buf *pl2303_buf_alloc(unsigned int size); 164static struct oti6858_buf *oti6858_buf_alloc(unsigned int size);
165static void pl2303_buf_free(struct pl2303_buf *pb); 165static void oti6858_buf_free(struct oti6858_buf *pb);
166static void pl2303_buf_clear(struct pl2303_buf *pb); 166static void oti6858_buf_clear(struct oti6858_buf *pb);
167static unsigned int pl2303_buf_data_avail(struct pl2303_buf *pb); 167static unsigned int oti6858_buf_data_avail(struct oti6858_buf *pb);
168static unsigned int pl2303_buf_space_avail(struct pl2303_buf *pb); 168static unsigned int oti6858_buf_space_avail(struct oti6858_buf *pb);
169static unsigned int pl2303_buf_put(struct pl2303_buf *pb, const char *buf, 169static unsigned int oti6858_buf_put(struct oti6858_buf *pb, const char *buf,
170 unsigned int count); 170 unsigned int count);
171static unsigned int pl2303_buf_get(struct pl2303_buf *pb, char *buf, 171static unsigned int oti6858_buf_get(struct oti6858_buf *pb, char *buf,
172 unsigned int count); 172 unsigned int count);
173 173
174 174
@@ -203,7 +203,7 @@ static struct usb_serial_driver oti6858_device = {
203struct oti6858_private { 203struct oti6858_private {
204 spinlock_t lock; 204 spinlock_t lock;
205 205
206 struct pl2303_buf *buf; 206 struct oti6858_buf *buf;
207 struct oti6858_control_pkt status; 207 struct oti6858_control_pkt status;
208 208
209 struct { 209 struct {
@@ -316,7 +316,7 @@ void send_data(struct work_struct *work)
316 } 316 }
317 priv->flags.write_urb_in_use = 1; 317 priv->flags.write_urb_in_use = 1;
318 318
319 count = pl2303_buf_data_avail(priv->buf); 319 count = oti6858_buf_data_avail(priv->buf);
320 spin_unlock_irqrestore(&priv->lock, flags); 320 spin_unlock_irqrestore(&priv->lock, flags);
321 if (count > port->bulk_out_size) 321 if (count > port->bulk_out_size)
322 count = port->bulk_out_size; 322 count = port->bulk_out_size;
@@ -345,7 +345,7 @@ void send_data(struct work_struct *work)
345 } 345 }
346 346
347 spin_lock_irqsave(&priv->lock, flags); 347 spin_lock_irqsave(&priv->lock, flags);
348 pl2303_buf_get(priv->buf, port->write_urb->transfer_buffer, count); 348 oti6858_buf_get(priv->buf, port->write_urb->transfer_buffer, count);
349 spin_unlock_irqrestore(&priv->lock, flags); 349 spin_unlock_irqrestore(&priv->lock, flags);
350 350
351 port->write_urb->transfer_buffer_length = count; 351 port->write_urb->transfer_buffer_length = count;
@@ -370,7 +370,7 @@ static int oti6858_startup(struct usb_serial *serial)
370 priv = kzalloc(sizeof(struct oti6858_private), GFP_KERNEL); 370 priv = kzalloc(sizeof(struct oti6858_private), GFP_KERNEL);
371 if (!priv) 371 if (!priv)
372 break; 372 break;
373 priv->buf = pl2303_buf_alloc(PL2303_BUF_SIZE); 373 priv->buf = oti6858_buf_alloc(PL2303_BUF_SIZE);
374 if (priv->buf == NULL) { 374 if (priv->buf == NULL) {
375 kfree(priv); 375 kfree(priv);
376 break; 376 break;
@@ -391,7 +391,7 @@ static int oti6858_startup(struct usb_serial *serial)
391 391
392 for (--i; i >= 0; --i) { 392 for (--i; i >= 0; --i) {
393 priv = usb_get_serial_port_data(serial->port[i]); 393 priv = usb_get_serial_port_data(serial->port[i]);
394 pl2303_buf_free(priv->buf); 394 oti6858_buf_free(priv->buf);
395 kfree(priv); 395 kfree(priv);
396 usb_set_serial_port_data(serial->port[i], NULL); 396 usb_set_serial_port_data(serial->port[i], NULL);
397 } 397 }
@@ -410,7 +410,7 @@ static int oti6858_write(struct usb_serial_port *port,
410 return count; 410 return count;
411 411
412 spin_lock_irqsave(&priv->lock, flags); 412 spin_lock_irqsave(&priv->lock, flags);
413 count = pl2303_buf_put(priv->buf, buf, count); 413 count = oti6858_buf_put(priv->buf, buf, count);
414 spin_unlock_irqrestore(&priv->lock, flags); 414 spin_unlock_irqrestore(&priv->lock, flags);
415 415
416 return count; 416 return count;
@@ -425,7 +425,7 @@ static int oti6858_write_room(struct usb_serial_port *port)
425 dbg("%s(port = %d)", __FUNCTION__, port->number); 425 dbg("%s(port = %d)", __FUNCTION__, port->number);
426 426
427 spin_lock_irqsave(&priv->lock, flags); 427 spin_lock_irqsave(&priv->lock, flags);
428 room = pl2303_buf_space_avail(priv->buf); 428 room = oti6858_buf_space_avail(priv->buf);
429 spin_unlock_irqrestore(&priv->lock, flags); 429 spin_unlock_irqrestore(&priv->lock, flags);
430 430
431 return room; 431 return room;
@@ -440,7 +440,7 @@ static int oti6858_chars_in_buffer(struct usb_serial_port *port)
440 dbg("%s(port = %d)", __FUNCTION__, port->number); 440 dbg("%s(port = %d)", __FUNCTION__, port->number);
441 441
442 spin_lock_irqsave(&priv->lock, flags); 442 spin_lock_irqsave(&priv->lock, flags);
443 chars = pl2303_buf_data_avail(priv->buf); 443 chars = oti6858_buf_data_avail(priv->buf);
444 spin_unlock_irqrestore(&priv->lock, flags); 444 spin_unlock_irqrestore(&priv->lock, flags);
445 445
446 return chars; 446 return chars;
@@ -458,7 +458,7 @@ static void oti6858_set_termios(struct usb_serial_port *port,
458 458
459 dbg("%s(port = %d)", __FUNCTION__, port->number); 459 dbg("%s(port = %d)", __FUNCTION__, port->number);
460 460
461 if ((!port->tty) || (!port->tty->termios)) { 461 if (!port->tty || !port->tty->termios) {
462 dbg("%s(): no tty structures", __FUNCTION__); 462 dbg("%s(): no tty structures", __FUNCTION__);
463 return; 463 return;
464 } 464 }
@@ -468,6 +468,8 @@ static void oti6858_set_termios(struct usb_serial_port *port,
468 *(port->tty->termios) = tty_std_termios; 468 *(port->tty->termios) = tty_std_termios;
469 port->tty->termios->c_cflag = B38400 | CS8 | CREAD | HUPCL | CLOCAL; 469 port->tty->termios->c_cflag = B38400 | CS8 | CREAD | HUPCL | CLOCAL;
470 priv->flags.termios_initialized = 1; 470 priv->flags.termios_initialized = 1;
471 port->tty->termios->c_ispeed = 38400;
472 port->tty->termios->c_ospeed = 38400;
471 } 473 }
472 spin_unlock_irqrestore(&priv->lock, flags); 474 spin_unlock_irqrestore(&priv->lock, flags);
473 475
@@ -504,19 +506,14 @@ static void oti6858_set_termios(struct usb_serial_port *port,
504 br = tty_get_baud_rate(port->tty); 506 br = tty_get_baud_rate(port->tty);
505 if (br == 0) { 507 if (br == 0) {
506 divisor = 0; 508 divisor = 0;
507 } else if (br <= OTI6858_MAX_BAUD_RATE) { 509 } else {
508 int real_br; 510 int real_br;
511 br = min(br, OTI6858_MAX_BAUD_RATE);
509 512
510 divisor = (96000000 + 8 * br) / (16 * br); 513 divisor = (96000000 + 8 * br) / (16 * br);
511 real_br = 96000000 / (16 * divisor); 514 real_br = 96000000 / (16 * divisor);
512 if ((((real_br - br) * 100 + br - 1) / br) > 2) {
513 dbg("%s(): baud rate %d is invalid", __FUNCTION__, br);
514 return;
515 }
516 divisor = cpu_to_le16(divisor); 515 divisor = cpu_to_le16(divisor);
517 } else { 516 tty_encode_baud_rate(port->tty, real_br, real_br);
518 dbg("%s(): baud rate %d is too high", __FUNCTION__, br);
519 return;
520 } 517 }
521 518
522 frame_fmt &= ~FMT_STOP_BITS_MASK; 519 frame_fmt &= ~FMT_STOP_BITS_MASK;
@@ -650,9 +647,9 @@ static void oti6858_close(struct usb_serial_port *port, struct file *filp)
650 dbg("%s(): entering wait loop", __FUNCTION__); 647 dbg("%s(): entering wait loop", __FUNCTION__);
651 for (;;) { 648 for (;;) {
652 set_current_state(TASK_INTERRUPTIBLE); 649 set_current_state(TASK_INTERRUPTIBLE);
653 if (pl2303_buf_data_avail(priv->buf) == 0 650 if (oti6858_buf_data_avail(priv->buf) == 0
654 || timeout == 0 || signal_pending(current) 651 || timeout == 0 || signal_pending(current)
655 || !usb_get_intfdata(port->serial->interface)) /* disconnect */ 652 || port->serial->disconnected)
656 break; 653 break;
657 spin_unlock_irqrestore(&priv->lock, flags); 654 spin_unlock_irqrestore(&priv->lock, flags);
658 timeout = schedule_timeout(timeout); 655 timeout = schedule_timeout(timeout);
@@ -663,7 +660,7 @@ static void oti6858_close(struct usb_serial_port *port, struct file *filp)
663 dbg("%s(): after wait loop", __FUNCTION__); 660 dbg("%s(): after wait loop", __FUNCTION__);
664 661
665 /* clear out any remaining data in the buffer */ 662 /* clear out any remaining data in the buffer */
666 pl2303_buf_clear(priv->buf); 663 oti6858_buf_clear(priv->buf);
667 spin_unlock_irqrestore(&priv->lock, flags); 664 spin_unlock_irqrestore(&priv->lock, flags);
668 665
669 /* wait for characters to drain from the device */ 666 /* wait for characters to drain from the device */
@@ -831,21 +828,6 @@ static int oti6858_ioctl(struct usb_serial_port *port, struct file *file,
831 return -EFAULT; 828 return -EFAULT;
832 return oti6858_tiocmset(port, NULL, 0, x); 829 return oti6858_tiocmset(port, NULL, 0, x);
833 830
834 case TIOCGSERIAL:
835 if (copy_to_user(user_arg, port->tty->termios,
836 sizeof(struct ktermios))) {
837 return -EFAULT;
838 }
839 return 0;
840
841 case TIOCSSERIAL:
842 if (copy_from_user(port->tty->termios, user_arg,
843 sizeof(struct ktermios))) {
844 return -EFAULT;
845 }
846 oti6858_set_termios(port, NULL);
847 return 0;
848
849 case TIOCMIWAIT: 831 case TIOCMIWAIT:
850 dbg("%s(): TIOCMIWAIT", __FUNCTION__); 832 dbg("%s(): TIOCMIWAIT", __FUNCTION__);
851 return wait_modem_info(port, arg); 833 return wait_modem_info(port, arg);
@@ -887,7 +869,7 @@ static void oti6858_shutdown(struct usb_serial *serial)
887 for (i = 0; i < serial->num_ports; ++i) { 869 for (i = 0; i < serial->num_ports; ++i) {
888 priv = usb_get_serial_port_data(serial->port[i]); 870 priv = usb_get_serial_port_data(serial->port[i]);
889 if (priv) { 871 if (priv) {
890 pl2303_buf_free(priv->buf); 872 oti6858_buf_free(priv->buf);
891 kfree(priv); 873 kfree(priv);
892 usb_set_serial_port_data(serial->port[i], NULL); 874 usb_set_serial_port_data(serial->port[i], NULL);
893 } 875 }
@@ -987,7 +969,7 @@ static void oti6858_read_int_callback(struct urb *urb)
987 969
988 spin_lock_irqsave(&priv->lock, flags); 970 spin_lock_irqsave(&priv->lock, flags);
989 if (priv->flags.write_urb_in_use == 0 971 if (priv->flags.write_urb_in_use == 0
990 && pl2303_buf_data_avail(priv->buf) != 0) { 972 && oti6858_buf_data_avail(priv->buf) != 0) {
991 schedule_delayed_work(&priv->delayed_write_work,0); 973 schedule_delayed_work(&priv->delayed_write_work,0);
992 resubmit = 0; 974 resubmit = 0;
993 } 975 }
@@ -1015,9 +997,8 @@ static void oti6858_read_bulk_callback(struct urb *urb)
1015 struct tty_struct *tty; 997 struct tty_struct *tty;
1016 unsigned char *data = urb->transfer_buffer; 998 unsigned char *data = urb->transfer_buffer;
1017 unsigned long flags; 999 unsigned long flags;
1018 int i, result;
1019 int status = urb->status; 1000 int status = urb->status;
1020 char tty_flag; 1001 int result;
1021 1002
1022 dbg("%s(port = %d, status = %d)", 1003 dbg("%s(port = %d, status = %d)",
1023 __FUNCTION__, port->number, status); 1004 __FUNCTION__, port->number, status);
@@ -1045,27 +1026,9 @@ static void oti6858_read_bulk_callback(struct urb *urb)
1045 return; 1026 return;
1046 } 1027 }
1047 1028
1048 // get tty_flag from status
1049 tty_flag = TTY_NORMAL;
1050
1051/* FIXME: probably, errors will be signalled using interrupt pipe! */
1052/*
1053 // break takes precedence over parity,
1054 // which takes precedence over framing errors
1055 if (status & UART_BREAK_ERROR )
1056 tty_flag = TTY_BREAK;
1057 else if (status & UART_PARITY_ERROR)
1058 tty_flag = TTY_PARITY;
1059 else if (status & UART_FRAME_ERROR)
1060 tty_flag = TTY_FRAME;
1061 dbg("%s - tty_flag = %d", __FUNCTION__, tty_flag);
1062*/
1063
1064 tty = port->tty; 1029 tty = port->tty;
1065 if (tty != NULL && urb->actual_length > 0) { 1030 if (tty != NULL && urb->actual_length > 0) {
1066 tty_buffer_request_room(tty, urb->actual_length); 1031 tty_insert_flip_string(tty, data, urb->actual_length);
1067 for (i = 0; i < urb->actual_length; ++i)
1068 tty_insert_flip_char(tty, data[i], tty_flag);
1069 tty_flip_buffer_push(tty); 1032 tty_flip_buffer_push(tty);
1070 } 1033 }
1071 1034
@@ -1133,18 +1096,18 @@ static void oti6858_write_bulk_callback(struct urb *urb)
1133 1096
1134 1097
1135/* 1098/*
1136 * pl2303_buf_alloc 1099 * oti6858_buf_alloc
1137 * 1100 *
1138 * Allocate a circular buffer and all associated memory. 1101 * Allocate a circular buffer and all associated memory.
1139 */ 1102 */
1140static struct pl2303_buf *pl2303_buf_alloc(unsigned int size) 1103static struct oti6858_buf *oti6858_buf_alloc(unsigned int size)
1141{ 1104{
1142 struct pl2303_buf *pb; 1105 struct oti6858_buf *pb;
1143 1106
1144 if (size == 0) 1107 if (size == 0)
1145 return NULL; 1108 return NULL;
1146 1109
1147 pb = kmalloc(sizeof(struct pl2303_buf), GFP_KERNEL); 1110 pb = kmalloc(sizeof(struct oti6858_buf), GFP_KERNEL);
1148 if (pb == NULL) 1111 if (pb == NULL)
1149 return NULL; 1112 return NULL;
1150 1113
@@ -1161,11 +1124,11 @@ static struct pl2303_buf *pl2303_buf_alloc(unsigned int size)
1161} 1124}
1162 1125
1163/* 1126/*
1164 * pl2303_buf_free 1127 * oti6858_buf_free
1165 * 1128 *
1166 * Free the buffer and all associated memory. 1129 * Free the buffer and all associated memory.
1167 */ 1130 */
1168static void pl2303_buf_free(struct pl2303_buf *pb) 1131static void oti6858_buf_free(struct oti6858_buf *pb)
1169{ 1132{
1170 if (pb) { 1133 if (pb) {
1171 kfree(pb->buf_buf); 1134 kfree(pb->buf_buf);
@@ -1174,11 +1137,11 @@ static void pl2303_buf_free(struct pl2303_buf *pb)
1174} 1137}
1175 1138
1176/* 1139/*
1177 * pl2303_buf_clear 1140 * oti6858_buf_clear
1178 * 1141 *
1179 * Clear out all data in the circular buffer. 1142 * Clear out all data in the circular buffer.
1180 */ 1143 */
1181static void pl2303_buf_clear(struct pl2303_buf *pb) 1144static void oti6858_buf_clear(struct oti6858_buf *pb)
1182{ 1145{
1183 if (pb != NULL) { 1146 if (pb != NULL) {
1184 /* equivalent to a get of all data available */ 1147 /* equivalent to a get of all data available */
@@ -1187,12 +1150,12 @@ static void pl2303_buf_clear(struct pl2303_buf *pb)
1187} 1150}
1188 1151
1189/* 1152/*
1190 * pl2303_buf_data_avail 1153 * oti6858_buf_data_avail
1191 * 1154 *
1192 * Return the number of bytes of data available in the circular 1155 * Return the number of bytes of data available in the circular
1193 * buffer. 1156 * buffer.
1194 */ 1157 */
1195static unsigned int pl2303_buf_data_avail(struct pl2303_buf *pb) 1158static unsigned int oti6858_buf_data_avail(struct oti6858_buf *pb)
1196{ 1159{
1197 if (pb == NULL) 1160 if (pb == NULL)
1198 return 0; 1161 return 0;
@@ -1200,12 +1163,12 @@ static unsigned int pl2303_buf_data_avail(struct pl2303_buf *pb)
1200} 1163}
1201 1164
1202/* 1165/*
1203 * pl2303_buf_space_avail 1166 * oti6858_buf_space_avail
1204 * 1167 *
1205 * Return the number of bytes of space available in the circular 1168 * Return the number of bytes of space available in the circular
1206 * buffer. 1169 * buffer.
1207 */ 1170 */
1208static unsigned int pl2303_buf_space_avail(struct pl2303_buf *pb) 1171static unsigned int oti6858_buf_space_avail(struct oti6858_buf *pb)
1209{ 1172{
1210 if (pb == NULL) 1173 if (pb == NULL)
1211 return 0; 1174 return 0;
@@ -1213,14 +1176,14 @@ static unsigned int pl2303_buf_space_avail(struct pl2303_buf *pb)
1213} 1176}
1214 1177
1215/* 1178/*
1216 * pl2303_buf_put 1179 * oti6858_buf_put
1217 * 1180 *
1218 * Copy data data from a user buffer and put it into the circular buffer. 1181 * Copy data data from a user buffer and put it into the circular buffer.
1219 * Restrict to the amount of space available. 1182 * Restrict to the amount of space available.
1220 * 1183 *
1221 * Return the number of bytes copied. 1184 * Return the number of bytes copied.
1222 */ 1185 */
1223static unsigned int pl2303_buf_put(struct pl2303_buf *pb, const char *buf, 1186static unsigned int oti6858_buf_put(struct oti6858_buf *pb, const char *buf,
1224 unsigned int count) 1187 unsigned int count)
1225{ 1188{
1226 unsigned int len; 1189 unsigned int len;
@@ -1228,7 +1191,7 @@ static unsigned int pl2303_buf_put(struct pl2303_buf *pb, const char *buf,
1228 if (pb == NULL) 1191 if (pb == NULL)
1229 return 0; 1192 return 0;
1230 1193
1231 len = pl2303_buf_space_avail(pb); 1194 len = oti6858_buf_space_avail(pb);
1232 if (count > len) 1195 if (count > len)
1233 count = len; 1196 count = len;
1234 1197
@@ -1252,14 +1215,14 @@ static unsigned int pl2303_buf_put(struct pl2303_buf *pb, const char *buf,
1252} 1215}
1253 1216
1254/* 1217/*
1255 * pl2303_buf_get 1218 * oti6858_buf_get
1256 * 1219 *
1257 * Get data from the circular buffer and copy to the given buffer. 1220 * Get data from the circular buffer and copy to the given buffer.
1258 * Restrict to the amount of data available. 1221 * Restrict to the amount of data available.
1259 * 1222 *
1260 * Return the number of bytes copied. 1223 * Return the number of bytes copied.
1261 */ 1224 */
1262static unsigned int pl2303_buf_get(struct pl2303_buf *pb, char *buf, 1225static unsigned int oti6858_buf_get(struct oti6858_buf *pb, char *buf,
1263 unsigned int count) 1226 unsigned int count)
1264{ 1227{
1265 unsigned int len; 1228 unsigned int len;
@@ -1267,7 +1230,7 @@ static unsigned int pl2303_buf_get(struct pl2303_buf *pb, char *buf,
1267 if (pb == NULL) 1230 if (pb == NULL)
1268 return 0; 1231 return 0;
1269 1232
1270 len = pl2303_buf_data_avail(pb); 1233 len = oti6858_buf_data_avail(pb);
1271 if (count > len) 1234 if (count > len)
1272 count = len; 1235 count = len;
1273 1236
diff --git a/drivers/usb/serial/pl2303.c b/drivers/usb/serial/pl2303.c
index 0da1df9c79bf..ae3ec1a64008 100644
--- a/drivers/usb/serial/pl2303.c
+++ b/drivers/usb/serial/pl2303.c
@@ -65,6 +65,7 @@ static struct usb_device_id id_table [] = {
65 { USB_DEVICE(ITEGNO_VENDOR_ID, ITEGNO_PRODUCT_ID_2080) }, 65 { USB_DEVICE(ITEGNO_VENDOR_ID, ITEGNO_PRODUCT_ID_2080) },
66 { USB_DEVICE(MA620_VENDOR_ID, MA620_PRODUCT_ID) }, 66 { USB_DEVICE(MA620_VENDOR_ID, MA620_PRODUCT_ID) },
67 { USB_DEVICE(RATOC_VENDOR_ID, RATOC_PRODUCT_ID) }, 67 { USB_DEVICE(RATOC_VENDOR_ID, RATOC_PRODUCT_ID) },
68 { USB_DEVICE(RATOC_VENDOR_ID, RATOC_PRODUCT_ID_USB60F) },
68 { USB_DEVICE(TRIPP_VENDOR_ID, TRIPP_PRODUCT_ID) }, 69 { USB_DEVICE(TRIPP_VENDOR_ID, TRIPP_PRODUCT_ID) },
69 { USB_DEVICE(RADIOSHACK_VENDOR_ID, RADIOSHACK_PRODUCT_ID) }, 70 { USB_DEVICE(RADIOSHACK_VENDOR_ID, RADIOSHACK_PRODUCT_ID) },
70 { USB_DEVICE(DCU10_VENDOR_ID, DCU10_PRODUCT_ID) }, 71 { USB_DEVICE(DCU10_VENDOR_ID, DCU10_PRODUCT_ID) },
@@ -84,9 +85,10 @@ static struct usb_device_id id_table [] = {
84 { USB_DEVICE(DATAPILOT_U2_VENDOR_ID, DATAPILOT_U2_PRODUCT_ID) }, 85 { USB_DEVICE(DATAPILOT_U2_VENDOR_ID, DATAPILOT_U2_PRODUCT_ID) },
85 { USB_DEVICE(BELKIN_VENDOR_ID, BELKIN_PRODUCT_ID) }, 86 { USB_DEVICE(BELKIN_VENDOR_ID, BELKIN_PRODUCT_ID) },
86 { USB_DEVICE(ALCOR_VENDOR_ID, ALCOR_PRODUCT_ID) }, 87 { USB_DEVICE(ALCOR_VENDOR_ID, ALCOR_PRODUCT_ID) },
87 { USB_DEVICE(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_ID) },
88 { USB_DEVICE(WS002IN_VENDOR_ID, WS002IN_PRODUCT_ID) }, 88 { USB_DEVICE(WS002IN_VENDOR_ID, WS002IN_PRODUCT_ID) },
89 { USB_DEVICE(COREGA_VENDOR_ID, COREGA_PRODUCT_ID) }, 89 { USB_DEVICE(COREGA_VENDOR_ID, COREGA_PRODUCT_ID) },
90 { USB_DEVICE(HL340_VENDOR_ID, HL340_PRODUCT_ID) },
91 { USB_DEVICE(YCCABLE_VENDOR_ID, YCCABLE_PRODUCT_ID) },
90 { } /* Terminating entry */ 92 { } /* Terminating entry */
91}; 93};
92 94
@@ -97,7 +99,10 @@ static struct usb_driver pl2303_driver = {
97 .probe = usb_serial_probe, 99 .probe = usb_serial_probe,
98 .disconnect = usb_serial_disconnect, 100 .disconnect = usb_serial_disconnect,
99 .id_table = id_table, 101 .id_table = id_table,
102 .suspend = usb_serial_suspend,
103 .resume = usb_serial_resume,
100 .no_dynamic_id = 1, 104 .no_dynamic_id = 1,
105 .supports_autosuspend = 1,
101}; 106};
102 107
103#define SET_LINE_REQUEST_TYPE 0x21 108#define SET_LINE_REQUEST_TYPE 0x21
@@ -310,12 +315,39 @@ static unsigned int pl2303_buf_get(struct pl2303_buf *pb, char *buf,
310 return count; 315 return count;
311} 316}
312 317
318static int pl2303_vendor_read(__u16 value, __u16 index,
319 struct usb_serial *serial, unsigned char *buf)
320{
321 int res = usb_control_msg(serial->dev, usb_rcvctrlpipe(serial->dev, 0),
322 VENDOR_READ_REQUEST, VENDOR_READ_REQUEST_TYPE,
323 value, index, buf, 1, 100);
324 dbg("0x%x:0x%x:0x%x:0x%x %d - %x", VENDOR_READ_REQUEST_TYPE,
325 VENDOR_READ_REQUEST, value, index, res, buf[0]);
326 return res;
327}
328
329static int pl2303_vendor_write(__u16 value, __u16 index,
330 struct usb_serial *serial)
331{
332 int res = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0),
333 VENDOR_WRITE_REQUEST, VENDOR_WRITE_REQUEST_TYPE,
334 value, index, NULL, 0, 100);
335 dbg("0x%x:0x%x:0x%x:0x%x %d", VENDOR_WRITE_REQUEST_TYPE,
336 VENDOR_WRITE_REQUEST, value, index, res);
337 return res;
338}
339
313static int pl2303_startup(struct usb_serial *serial) 340static int pl2303_startup(struct usb_serial *serial)
314{ 341{
315 struct pl2303_private *priv; 342 struct pl2303_private *priv;
316 enum pl2303_type type = type_0; 343 enum pl2303_type type = type_0;
344 unsigned char *buf;
317 int i; 345 int i;
318 346
347 buf = kmalloc(10, GFP_KERNEL);
348 if (buf == NULL)
349 return -ENOMEM;
350
319 if (serial->dev->descriptor.bDeviceClass == 0x02) 351 if (serial->dev->descriptor.bDeviceClass == 0x02)
320 type = type_0; 352 type = type_0;
321 else if (serial->dev->descriptor.bMaxPacketSize0 == 0x40) 353 else if (serial->dev->descriptor.bMaxPacketSize0 == 0x40)
@@ -340,9 +372,27 @@ static int pl2303_startup(struct usb_serial *serial)
340 priv->type = type; 372 priv->type = type;
341 usb_set_serial_port_data(serial->port[i], priv); 373 usb_set_serial_port_data(serial->port[i], priv);
342 } 374 }
375
376 pl2303_vendor_read(0x8484, 0, serial, buf);
377 pl2303_vendor_write(0x0404, 0, serial);
378 pl2303_vendor_read(0x8484, 0, serial, buf);
379 pl2303_vendor_read(0x8383, 0, serial, buf);
380 pl2303_vendor_read(0x8484, 0, serial, buf);
381 pl2303_vendor_write(0x0404, 1, serial);
382 pl2303_vendor_read(0x8484, 0, serial, buf);
383 pl2303_vendor_read(0x8383, 0, serial, buf);
384 pl2303_vendor_write(0, 1, serial);
385 pl2303_vendor_write(1, 0, serial);
386 if (type == HX)
387 pl2303_vendor_write(2, 0x44, serial);
388 else
389 pl2303_vendor_write(2, 0x24, serial);
390
391 kfree(buf);
343 return 0; 392 return 0;
344 393
345cleanup: 394cleanup:
395 kfree(buf);
346 for (--i; i>=0; --i) { 396 for (--i; i>=0; --i) {
347 priv = usb_get_serial_port_data(serial->port[i]); 397 priv = usb_get_serial_port_data(serial->port[i]);
348 pl2303_buf_free(priv->buf); 398 pl2303_buf_free(priv->buf);
@@ -582,24 +632,12 @@ static void pl2303_set_termios(struct usb_serial_port *port,
582 buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6]); 632 buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6]);
583 633
584 if (cflag & CRTSCTS) { 634 if (cflag & CRTSCTS) {
585 __u16 index;
586 if (priv->type == HX) 635 if (priv->type == HX)
587 index = 0x61; 636 pl2303_vendor_write(0x0, 0x61, serial);
588 else 637 else
589 index = 0x41; 638 pl2303_vendor_write(0x0, 0x41, serial);
590 i = usb_control_msg(serial->dev,
591 usb_sndctrlpipe(serial->dev, 0),
592 VENDOR_WRITE_REQUEST,
593 VENDOR_WRITE_REQUEST_TYPE,
594 0x0, index, NULL, 0, 100);
595 dbg("0x40:0x1:0x0:0x%x %d", index, i);
596 } else { 639 } else {
597 i = usb_control_msg(serial->dev, 640 pl2303_vendor_write(0x0, 0x0, serial);
598 usb_sndctrlpipe(serial->dev, 0),
599 VENDOR_WRITE_REQUEST,
600 VENDOR_WRITE_REQUEST_TYPE,
601 0x0, 0x0, NULL, 0, 100);
602 dbg ("0x40:0x1:0x0:0x0 %d", i);
603 } 641 }
604 642
605 /* FIXME: Need to read back resulting baud rate */ 643 /* FIXME: Need to read back resulting baud rate */
@@ -629,7 +667,7 @@ static void pl2303_close(struct usb_serial_port *port, struct file *filp)
629 set_current_state(TASK_INTERRUPTIBLE); 667 set_current_state(TASK_INTERRUPTIBLE);
630 if (pl2303_buf_data_avail(priv->buf) == 0 || 668 if (pl2303_buf_data_avail(priv->buf) == 0 ||
631 timeout == 0 || signal_pending(current) || 669 timeout == 0 || signal_pending(current) ||
632 !usb_get_intfdata(port->serial->interface)) /* disconnect */ 670 port->serial->disconnected)
633 break; 671 break;
634 spin_unlock_irqrestore(&priv->lock, flags); 672 spin_unlock_irqrestore(&priv->lock, flags);
635 timeout = schedule_timeout(timeout); 673 timeout = schedule_timeout(timeout);
@@ -678,7 +716,6 @@ static int pl2303_open(struct usb_serial_port *port, struct file *filp)
678 struct ktermios tmp_termios; 716 struct ktermios tmp_termios;
679 struct usb_serial *serial = port->serial; 717 struct usb_serial *serial = port->serial;
680 struct pl2303_private *priv = usb_get_serial_port_data(port); 718 struct pl2303_private *priv = usb_get_serial_port_data(port);
681 unsigned char *buf;
682 int result; 719 int result;
683 720
684 dbg("%s - port %d", __FUNCTION__, port->number); 721 dbg("%s - port %d", __FUNCTION__, port->number);
@@ -686,45 +723,12 @@ static int pl2303_open(struct usb_serial_port *port, struct file *filp)
686 if (priv->type != HX) { 723 if (priv->type != HX) {
687 usb_clear_halt(serial->dev, port->write_urb->pipe); 724 usb_clear_halt(serial->dev, port->write_urb->pipe);
688 usb_clear_halt(serial->dev, port->read_urb->pipe); 725 usb_clear_halt(serial->dev, port->read_urb->pipe);
689 }
690
691 buf = kmalloc(10, GFP_KERNEL);
692 if (buf==NULL)
693 return -ENOMEM;
694
695#define FISH(a,b,c,d) \
696 result=usb_control_msg(serial->dev, usb_rcvctrlpipe(serial->dev,0), \
697 b, a, c, d, buf, 1, 100); \
698 dbg("0x%x:0x%x:0x%x:0x%x %d - %x",a,b,c,d,result,buf[0]);
699
700#define SOUP(a,b,c,d) \
701 result=usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev,0), \
702 b, a, c, d, NULL, 0, 100); \
703 dbg("0x%x:0x%x:0x%x:0x%x %d",a,b,c,d,result);
704
705 FISH (VENDOR_READ_REQUEST_TYPE, VENDOR_READ_REQUEST, 0x8484, 0);
706 SOUP (VENDOR_WRITE_REQUEST_TYPE, VENDOR_WRITE_REQUEST, 0x0404, 0);
707 FISH (VENDOR_READ_REQUEST_TYPE, VENDOR_READ_REQUEST, 0x8484, 0);
708 FISH (VENDOR_READ_REQUEST_TYPE, VENDOR_READ_REQUEST, 0x8383, 0);
709 FISH (VENDOR_READ_REQUEST_TYPE, VENDOR_READ_REQUEST, 0x8484, 0);
710 SOUP (VENDOR_WRITE_REQUEST_TYPE, VENDOR_WRITE_REQUEST, 0x0404, 1);
711 FISH (VENDOR_READ_REQUEST_TYPE, VENDOR_READ_REQUEST, 0x8484, 0);
712 FISH (VENDOR_READ_REQUEST_TYPE, VENDOR_READ_REQUEST, 0x8383, 0);
713 SOUP (VENDOR_WRITE_REQUEST_TYPE, VENDOR_WRITE_REQUEST, 0, 1);
714 SOUP (VENDOR_WRITE_REQUEST_TYPE, VENDOR_WRITE_REQUEST, 1, 0);
715
716 if (priv->type == HX) {
717 /* HX chip */
718 SOUP (VENDOR_WRITE_REQUEST_TYPE, VENDOR_WRITE_REQUEST, 2, 0x44);
719 /* reset upstream data pipes */
720 SOUP (VENDOR_WRITE_REQUEST_TYPE, VENDOR_WRITE_REQUEST, 8, 0);
721 SOUP (VENDOR_WRITE_REQUEST_TYPE, VENDOR_WRITE_REQUEST, 9, 0);
722 } else { 726 } else {
723 SOUP (VENDOR_WRITE_REQUEST_TYPE, VENDOR_WRITE_REQUEST, 2, 0x24); 727 /* reset upstream data pipes */
728 pl2303_vendor_write(8, 0, serial);
729 pl2303_vendor_write(9, 0, serial);
724 } 730 }
725 731
726 kfree(buf);
727
728 /* Setup termios */ 732 /* Setup termios */
729 if (port->tty) { 733 if (port->tty) {
730 pl2303_set_termios(port, &tmp_termios); 734 pl2303_set_termios(port, &tmp_termios);
diff --git a/drivers/usb/serial/pl2303.h b/drivers/usb/serial/pl2303.h
index d31f5d299989..237a41f6638a 100644
--- a/drivers/usb/serial/pl2303.h
+++ b/drivers/usb/serial/pl2303.h
@@ -35,6 +35,7 @@
35 35
36#define RATOC_VENDOR_ID 0x0584 36#define RATOC_VENDOR_ID 0x0584
37#define RATOC_PRODUCT_ID 0xb000 37#define RATOC_PRODUCT_ID 0xb000
38#define RATOC_PRODUCT_ID_USB60F 0xb020
38 39
39#define TRIPP_VENDOR_ID 0x2478 40#define TRIPP_VENDOR_ID 0x2478
40#define TRIPP_PRODUCT_ID 0x2008 41#define TRIPP_PRODUCT_ID 0x2008
@@ -96,10 +97,6 @@
96#define ALCOR_VENDOR_ID 0x058F 97#define ALCOR_VENDOR_ID 0x058F
97#define ALCOR_PRODUCT_ID 0x9720 98#define ALCOR_PRODUCT_ID 0x9720
98 99
99/* Huawei E620 UMTS/HSDPA card (ID: 12d1:1001) */
100#define HUAWEI_VENDOR_ID 0x12d1
101#define HUAWEI_PRODUCT_ID 0x1001
102
103/* Willcom WS002IN Data Driver (by NetIndex Inc.) */ 100/* Willcom WS002IN Data Driver (by NetIndex Inc.) */
104#define WS002IN_VENDOR_ID 0x11f6 101#define WS002IN_VENDOR_ID 0x11f6
105#define WS002IN_PRODUCT_ID 0x2001 102#define WS002IN_PRODUCT_ID 0x2001
@@ -107,3 +104,11 @@
107/* Corega CG-USBRS232R Serial Adapter */ 104/* Corega CG-USBRS232R Serial Adapter */
108#define COREGA_VENDOR_ID 0x07aa 105#define COREGA_VENDOR_ID 0x07aa
109#define COREGA_PRODUCT_ID 0x002a 106#define COREGA_PRODUCT_ID 0x002a
107
108/* HL HL-340 (ID: 4348:5523) */
109#define HL340_VENDOR_ID 0x4348
110#define HL340_PRODUCT_ID 0x5523
111
112/* Y.C. Cable U.S.A., Inc - USB to RS-232 */
113#define YCCABLE_VENDOR_ID 0x05ad
114#define YCCABLE_PRODUCT_ID 0x0fba
diff --git a/drivers/usb/serial/sierra.c b/drivers/usb/serial/sierra.c
index c295d0495f96..4c925e3e8a63 100644
--- a/drivers/usb/serial/sierra.c
+++ b/drivers/usb/serial/sierra.c
@@ -1,7 +1,7 @@
1/* 1/*
2 USB Driver for Sierra Wireless 2 USB Driver for Sierra Wireless
3 3
4 Copyright (C) 2006, 2007 Kevin Lloyd <linux@sierrawireless.com> 4 Copyright (C) 2006, 2007, 2008 Kevin Lloyd <linux@sierrawireless.com>
5 5
6 IMPORTANT DISCLAIMER: This driver is not commercially supported by 6 IMPORTANT DISCLAIMER: This driver is not commercially supported by
7 Sierra Wireless. Use at your own risk. 7 Sierra Wireless. Use at your own risk.
@@ -14,7 +14,7 @@
14 Whom based his on the Keyspan driver by Hugh Blemings <hugh@blemings.org> 14 Whom based his on the Keyspan driver by Hugh Blemings <hugh@blemings.org>
15*/ 15*/
16 16
17#define DRIVER_VERSION "v.1.2.5b" 17#define DRIVER_VERSION "v.1.2.7"
18#define DRIVER_AUTHOR "Kevin Lloyd <linux@sierrawireless.com>" 18#define DRIVER_AUTHOR "Kevin Lloyd <linux@sierrawireless.com>"
19#define DRIVER_DESC "USB Driver for Sierra Wireless USB modems" 19#define DRIVER_DESC "USB Driver for Sierra Wireless USB modems"
20 20
@@ -26,10 +26,12 @@
26#include <linux/module.h> 26#include <linux/module.h>
27#include <linux/usb.h> 27#include <linux/usb.h>
28#include <linux/usb/serial.h> 28#include <linux/usb/serial.h>
29#include <linux/usb/ch9.h>
29 30
31#define SWIMS_USB_REQUEST_SetPower 0x00
32#define SWIMS_USB_REQUEST_SetNmea 0x07
30#define SWIMS_USB_REQUEST_SetMode 0x0B 33#define SWIMS_USB_REQUEST_SetMode 0x0B
31#define SWIMS_USB_REQUEST_TYPE_SetMode 0x40 34#define SWIMS_USB_REQUEST_TYPE_VSC_SET 0x40
32#define SWIMS_USB_INDEX_SetMode 0x0000
33#define SWIMS_SET_MODE_Modem 0x0001 35#define SWIMS_SET_MODE_Modem 0x0001
34 36
35/* per port private data */ 37/* per port private data */
@@ -38,6 +40,8 @@
38#define IN_BUFLEN 4096 40#define IN_BUFLEN 4096
39 41
40static int debug; 42static int debug;
43static int nmea;
44static int truinstall = 1;
41 45
42enum devicetype { 46enum devicetype {
43 DEVICE_3_PORT = 0, 47 DEVICE_3_PORT = 0,
@@ -50,48 +54,96 @@ static int sierra_set_power_state(struct usb_device *udev, __u16 swiState)
50 int result; 54 int result;
51 dev_dbg(&udev->dev, "%s", "SET POWER STATE\n"); 55 dev_dbg(&udev->dev, "%s", "SET POWER STATE\n");
52 result = usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 56 result = usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
53 0x00, /* __u8 request */ 57 SWIMS_USB_REQUEST_SetPower, /* __u8 request */
54 0x40, /* __u8 request type */ 58 SWIMS_USB_REQUEST_TYPE_VSC_SET, /* __u8 request type */
55 swiState, /* __u16 value */ 59 swiState, /* __u16 value */
56 0, /* __u16 index */ 60 0, /* __u16 index */
57 NULL, /* void *data */ 61 NULL, /* void *data */
58 0, /* __u16 size */ 62 0, /* __u16 size */
59 USB_CTRL_SET_TIMEOUT); /* int timeout */ 63 USB_CTRL_SET_TIMEOUT); /* int timeout */
60 return result; 64 return result;
61} 65}
62 66
63static int sierra_set_ms_mode(struct usb_device *udev, __u16 eSocMode) 67static int sierra_set_ms_mode(struct usb_device *udev, __u16 eSWocMode)
64{ 68{
65 int result; 69 int result;
66 dev_dbg(&udev->dev, "%s", "DEVICE MODE SWITCH\n"); 70 dev_dbg(&udev->dev, "%s", "DEVICE MODE SWITCH\n");
67 result = usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 71 result = usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
68 SWIMS_USB_REQUEST_SetMode, /* __u8 request */ 72 SWIMS_USB_REQUEST_SetMode, /* __u8 request */
69 SWIMS_USB_REQUEST_TYPE_SetMode, /* __u8 request type */ 73 SWIMS_USB_REQUEST_TYPE_VSC_SET, /* __u8 request type */
70 eSocMode, /* __u16 value */ 74 eSWocMode, /* __u16 value */
71 SWIMS_USB_INDEX_SetMode, /* __u16 index */ 75 0x0000, /* __u16 index */
72 NULL, /* void *data */ 76 NULL, /* void *data */
73 0, /* __u16 size */ 77 0, /* __u16 size */
74 USB_CTRL_SET_TIMEOUT); /* int timeout */ 78 USB_CTRL_SET_TIMEOUT); /* int timeout */
75 return result; 79 return result;
76} 80}
77 81
78static int sierra_probe(struct usb_interface *iface, 82static int sierra_vsc_set_nmea(struct usb_device *udev, __u16 enable)
79 const struct usb_device_id *id) 83{
84 int result;
85 dev_dbg(&udev->dev, "%s", "NMEA Enable sent\n");
86 result = usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
87 SWIMS_USB_REQUEST_SetNmea, /* __u8 request */
88 SWIMS_USB_REQUEST_TYPE_VSC_SET, /* __u8 request type */
89 enable, /* __u16 value */
90 0x0000, /* __u16 index */
91 NULL, /* void *data */
92 0, /* __u16 size */
93 USB_CTRL_SET_TIMEOUT); /* int timeout */
94 return result;
95}
96
97static int sierra_calc_num_ports(struct usb_serial *serial)
80{ 98{
81 int result; 99 int result;
100 int *num_ports = usb_get_serial_data(serial);
101
102 result = *num_ports;
103
104 if (result) {
105 kfree(num_ports);
106 usb_set_serial_data(serial, NULL);
107 }
108
109 return result;
110}
111
112static int sierra_probe(struct usb_serial *serial,
113 const struct usb_device_id *id)
114{
115 int result = 0;
82 struct usb_device *udev; 116 struct usb_device *udev;
117 int *num_ports;
118 u8 ifnum;
119
120 num_ports = kmalloc(sizeof(*num_ports), GFP_KERNEL);
121 if (!num_ports)
122 return -ENOMEM;
83 123
84 udev = usb_get_dev(interface_to_usbdev(iface)); 124 ifnum = serial->interface->cur_altsetting->desc.bInterfaceNumber;
125 udev = serial->dev;
85 126
86 /* Check if in installer mode */ 127 /* Check if in installer mode */
87 if (id->driver_info == DEVICE_INSTALLER) { 128 if (truinstall && id->driver_info == DEVICE_INSTALLER) {
88 dev_dbg(&udev->dev, "%s", "FOUND DEVICE(SW)\n"); 129 dev_dbg(&udev->dev, "%s", "FOUND TRU-INSTALL DEVICE(SW)\n");
89 result = sierra_set_ms_mode(udev, SWIMS_SET_MODE_Modem); 130 result = sierra_set_ms_mode(udev, SWIMS_SET_MODE_Modem);
90 /*We do not want to bind to the device when in installer mode*/ 131 /* Don't bind to the device when in installer mode */
132 kfree(num_ports);
91 return -EIO; 133 return -EIO;
92 } 134 } else if (id->driver_info == DEVICE_1_PORT)
135 *num_ports = 1;
136 else if (ifnum == 0x99)
137 *num_ports = 0;
138 else
139 *num_ports = 3;
140 /*
141 * save off our num_ports info so that we can use it in the
142 * calc_num_ports callback
143 */
144 usb_set_serial_data(serial, (void *)num_ports);
93 145
94 return usb_serial_probe(iface, id); 146 return result;
95} 147}
96 148
97static struct usb_device_id id_table [] = { 149static struct usb_device_id id_table [] = {
@@ -104,6 +156,7 @@ static struct usb_device_id id_table [] = {
104 { USB_DEVICE(0x1199, 0x0019) }, /* Sierra Wireless AirCard 595 */ 156 { USB_DEVICE(0x1199, 0x0019) }, /* Sierra Wireless AirCard 595 */
105 { USB_DEVICE(0x1199, 0x0021) }, /* Sierra Wireless AirCard 597E */ 157 { USB_DEVICE(0x1199, 0x0021) }, /* Sierra Wireless AirCard 597E */
106 { USB_DEVICE(0x1199, 0x0120) }, /* Sierra Wireless USB Dongle 595U */ 158 { USB_DEVICE(0x1199, 0x0120) }, /* Sierra Wireless USB Dongle 595U */
159 { USB_DEVICE(0x1199, 0x0023) }, /* Sierra Wireless AirCard */
107 160
108 { USB_DEVICE(0x1199, 0x6802) }, /* Sierra Wireless MC8755 */ 161 { USB_DEVICE(0x1199, 0x6802) }, /* Sierra Wireless MC8755 */
109 { USB_DEVICE(0x1199, 0x6804) }, /* Sierra Wireless MC8755 */ 162 { USB_DEVICE(0x1199, 0x6804) }, /* Sierra Wireless MC8755 */
@@ -117,56 +170,29 @@ static struct usb_device_id id_table [] = {
117 { USB_DEVICE(0x1199, 0x6851) }, /* Sierra Wireless AirCard 881 */ 170 { USB_DEVICE(0x1199, 0x6851) }, /* Sierra Wireless AirCard 881 */
118 { USB_DEVICE(0x1199, 0x6852) }, /* Sierra Wireless AirCard 880 E */ 171 { USB_DEVICE(0x1199, 0x6852) }, /* Sierra Wireless AirCard 880 E */
119 { USB_DEVICE(0x1199, 0x6853) }, /* Sierra Wireless AirCard 881 E */ 172 { USB_DEVICE(0x1199, 0x6853) }, /* Sierra Wireless AirCard 881 E */
173 { USB_DEVICE(0x1199, 0x6855) }, /* Sierra Wireless AirCard 880 U */
174 { USB_DEVICE(0x1199, 0x6856) }, /* Sierra Wireless AirCard 881 U */
175
176 { USB_DEVICE(0x1199, 0x6468) }, /* Sierra Wireless MP3G - EVDO */
177 { USB_DEVICE(0x1199, 0x6469) }, /* Sierra Wireless MP3G - UMTS/HSPA */
120 178
121 { USB_DEVICE(0x1199, 0x0112), .driver_info = DEVICE_1_PORT }, /* Sierra Wireless AirCard 580 */ 179 { USB_DEVICE(0x1199, 0x0112), .driver_info = DEVICE_1_PORT }, /* Sierra Wireless AirCard 580 */
122 { USB_DEVICE(0x0F3D, 0x0112), .driver_info = DEVICE_1_PORT }, /* Airprime/Sierra PC 5220 */ 180 { USB_DEVICE(0x0F3D, 0x0112), .driver_info = DEVICE_1_PORT }, /* Airprime/Sierra PC 5220 */
181 { USB_DEVICE(0x05C6, 0x6613), .driver_info = DEVICE_1_PORT }, /* Onda H600/ZTE MF330 */
123 182
124 { USB_DEVICE(0x1199, 0x0FFF), .driver_info = DEVICE_INSTALLER}, 183 { USB_DEVICE(0x1199, 0x0FFF), .driver_info = DEVICE_INSTALLER},
125 { } 184 { }
126}; 185};
127MODULE_DEVICE_TABLE(usb, id_table); 186MODULE_DEVICE_TABLE(usb, id_table);
128 187
129static struct usb_device_id id_table_1port [] = {
130 { USB_DEVICE(0x1199, 0x0112) }, /* Sierra Wireless AirCard 580 */
131 { USB_DEVICE(0x0F3D, 0x0112) }, /* AirPrime/Sierra PC 5220 */
132 { }
133};
134
135static struct usb_device_id id_table_3port [] = {
136 { USB_DEVICE(0x1199, 0x0017) }, /* Sierra Wireless EM5625 */
137 { USB_DEVICE(0x1199, 0x0018) }, /* Sierra Wireless MC5720 */
138 { USB_DEVICE(0x0f30, 0x1b1d) }, /* Sierra Wireless MC5720 */
139 { USB_DEVICE(0x1199, 0x0218) }, /* Sierra Wireless MC5720 */
140 { USB_DEVICE(0x1199, 0x0020) }, /* Sierra Wireless MC5725 */
141 { USB_DEVICE(0x1199, 0x0220) }, /* Sierra Wireless MC5725 */
142 { USB_DEVICE(0x1199, 0x0019) }, /* Sierra Wireless AirCard 595 */
143 { USB_DEVICE(0x1199, 0x0021) }, /* Sierra Wireless AirCard 597E */
144 { USB_DEVICE(0x1199, 0x0120) }, /* Sierra Wireless USB Dongle 595U*/
145
146 { USB_DEVICE(0x1199, 0x6802) }, /* Sierra Wireless MC8755 */
147 { USB_DEVICE(0x1199, 0x6804) }, /* Sierra Wireless MC8755 */
148 { USB_DEVICE(0x1199, 0x6803) }, /* Sierra Wireless MC8765 */
149 { USB_DEVICE(0x1199, 0x6812) }, /* Sierra Wireless MC8775 & AC 875U */
150 { USB_DEVICE(0x1199, 0x6813) }, /* Sierra Wireless MC8775 (Thinkpad internal) */
151 { USB_DEVICE(0x1199, 0x6820) }, /* Sierra Wireless AirCard 875 */
152 { USB_DEVICE(0x1199, 0x6832) }, /* Sierra Wireless MC8780*/
153 { USB_DEVICE(0x1199, 0x6833) }, /* Sierra Wireless MC8781*/
154 { USB_DEVICE(0x1199, 0x6850) }, /* Sierra Wireless AirCard 880 */
155 { USB_DEVICE(0x1199, 0x6851) }, /* Sierra Wireless AirCard 881 */
156 { USB_DEVICE(0x1199, 0x6852) }, /* Sierra Wireless AirCard 880E */
157 { USB_DEVICE(0x1199, 0x6853) }, /* Sierra Wireless AirCard 881E */
158 { }
159};
160
161static struct usb_driver sierra_driver = { 188static struct usb_driver sierra_driver = {
162 .name = "sierra", 189 .name = "sierra",
163 .probe = sierra_probe, 190 .probe = usb_serial_probe,
164 .disconnect = usb_serial_disconnect, 191 .disconnect = usb_serial_disconnect,
165 .id_table = id_table, 192 .id_table = id_table,
166 .no_dynamic_id = 1, 193 .no_dynamic_id = 1,
167}; 194};
168 195
169
170struct sierra_port_private { 196struct sierra_port_private {
171 spinlock_t lock; /* lock the structure */ 197 spinlock_t lock; /* lock the structure */
172 int outstanding_urbs; /* number of out urbs in flight */ 198 int outstanding_urbs; /* number of out urbs in flight */
@@ -188,6 +214,7 @@ static int sierra_send_setup(struct usb_serial_port *port)
188{ 214{
189 struct usb_serial *serial = port->serial; 215 struct usb_serial *serial = port->serial;
190 struct sierra_port_private *portdata; 216 struct sierra_port_private *portdata;
217 __u16 interface = 0;
191 218
192 dbg("%s", __FUNCTION__); 219 dbg("%s", __FUNCTION__);
193 220
@@ -200,9 +227,18 @@ static int sierra_send_setup(struct usb_serial_port *port)
200 if (portdata->rts_state) 227 if (portdata->rts_state)
201 val |= 0x02; 228 val |= 0x02;
202 229
230 /* Determine which port is targeted */
231 if (port->bulk_out_endpointAddress == 2)
232 interface = 0;
233 else if (port->bulk_out_endpointAddress == 4)
234 interface = 1;
235 else if (port->bulk_out_endpointAddress == 5)
236 interface = 2;
237
203 return usb_control_msg(serial->dev, 238 return usb_control_msg(serial->dev,
204 usb_rcvctrlpipe(serial->dev, 0), 239 usb_rcvctrlpipe(serial->dev, 0),
205 0x22,0x21,val,0,NULL,0,USB_CTRL_SET_TIMEOUT); 240 0x22, 0x21, val, interface,
241 NULL, 0, USB_CTRL_SET_TIMEOUT);
206 } 242 }
207 243
208 return 0; 244 return 0;
@@ -561,7 +597,10 @@ static void sierra_close(struct usb_serial_port *port, struct file *filp)
561 portdata->dtr_state = 0; 597 portdata->dtr_state = 0;
562 598
563 if (serial->dev) { 599 if (serial->dev) {
564 sierra_send_setup(port); 600 mutex_lock(&serial->disc_mutex);
601 if (!serial->disconnected)
602 sierra_send_setup(port);
603 mutex_unlock(&serial->disc_mutex);
565 604
566 /* Stop reading/writing urbs */ 605 /* Stop reading/writing urbs */
567 for (i = 0; i < N_IN_URB; i++) 606 for (i = 0; i < N_IN_URB; i++)
@@ -583,9 +622,13 @@ static int sierra_startup(struct usb_serial *serial)
583 622
584 dbg("%s", __FUNCTION__); 623 dbg("%s", __FUNCTION__);
585 624
586 /*Set Device mode to D0 */ 625 /* Set Device mode to D0 */
587 sierra_set_power_state(serial->dev, 0x0000); 626 sierra_set_power_state(serial->dev, 0x0000);
588 627
628 /* Check NMEA and set */
629 if (nmea)
630 sierra_vsc_set_nmea(serial->dev, 1);
631
589 /* Now setup per port private data */ 632 /* Now setup per port private data */
590 for (i = 0; i < serial->num_ports; i++) { 633 for (i = 0; i < serial->num_ports; i++) {
591 port = serial->port[i]; 634 port = serial->port[i];
@@ -646,47 +689,19 @@ static void sierra_shutdown(struct usb_serial *serial)
646 } 689 }
647} 690}
648 691
649static struct usb_serial_driver sierra_1port_device = { 692static struct usb_serial_driver sierra_device = {
650 .driver = { 693 .driver = {
651 .owner = THIS_MODULE, 694 .owner = THIS_MODULE,
652 .name = "sierra1", 695 .name = "sierra1",
653 }, 696 },
654 .description = "Sierra USB modem (1 port)", 697 .description = "Sierra USB modem",
655 .id_table = id_table_1port, 698 .id_table = id_table,
656 .usb_driver = &sierra_driver,
657 .num_interrupt_in = NUM_DONT_CARE,
658 .num_bulk_in = 1,
659 .num_bulk_out = 1,
660 .num_ports = 1,
661 .open = sierra_open,
662 .close = sierra_close,
663 .write = sierra_write,
664 .write_room = sierra_write_room,
665 .chars_in_buffer = sierra_chars_in_buffer,
666 .throttle = sierra_rx_throttle,
667 .unthrottle = sierra_rx_unthrottle,
668 .ioctl = sierra_ioctl,
669 .set_termios = sierra_set_termios,
670 .break_ctl = sierra_break_ctl,
671 .tiocmget = sierra_tiocmget,
672 .tiocmset = sierra_tiocmset,
673 .attach = sierra_startup,
674 .shutdown = sierra_shutdown,
675 .read_int_callback = sierra_instat_callback,
676};
677
678static struct usb_serial_driver sierra_3port_device = {
679 .driver = {
680 .owner = THIS_MODULE,
681 .name = "sierra3",
682 },
683 .description = "Sierra USB modem (3 port)",
684 .id_table = id_table_3port,
685 .usb_driver = &sierra_driver, 699 .usb_driver = &sierra_driver,
686 .num_interrupt_in = NUM_DONT_CARE, 700 .num_interrupt_in = NUM_DONT_CARE,
687 .num_bulk_in = 3, 701 .num_bulk_in = NUM_DONT_CARE,
688 .num_bulk_out = 3, 702 .num_bulk_out = NUM_DONT_CARE,
689 .num_ports = 3, 703 .calc_num_ports = sierra_calc_num_ports,
704 .probe = sierra_probe,
690 .open = sierra_open, 705 .open = sierra_open,
691 .close = sierra_close, 706 .close = sierra_close,
692 .write = sierra_write, 707 .write = sierra_write,
@@ -708,12 +723,9 @@ static struct usb_serial_driver sierra_3port_device = {
708static int __init sierra_init(void) 723static int __init sierra_init(void)
709{ 724{
710 int retval; 725 int retval;
711 retval = usb_serial_register(&sierra_1port_device); 726 retval = usb_serial_register(&sierra_device);
712 if (retval)
713 goto failed_1port_device_register;
714 retval = usb_serial_register(&sierra_3port_device);
715 if (retval) 727 if (retval)
716 goto failed_3port_device_register; 728 goto failed_device_register;
717 729
718 730
719 retval = usb_register(&sierra_driver); 731 retval = usb_register(&sierra_driver);
@@ -725,18 +737,15 @@ static int __init sierra_init(void)
725 return 0; 737 return 0;
726 738
727failed_driver_register: 739failed_driver_register:
728 usb_serial_deregister(&sierra_3port_device); 740 usb_serial_deregister(&sierra_device);
729failed_3port_device_register: 741failed_device_register:
730 usb_serial_deregister(&sierra_1port_device);
731failed_1port_device_register:
732 return retval; 742 return retval;
733} 743}
734 744
735static void __exit sierra_exit(void) 745static void __exit sierra_exit(void)
736{ 746{
737 usb_deregister (&sierra_driver); 747 usb_deregister (&sierra_driver);
738 usb_serial_deregister(&sierra_1port_device); 748 usb_serial_deregister(&sierra_device);
739 usb_serial_deregister(&sierra_3port_device);
740} 749}
741 750
742module_init(sierra_init); 751module_init(sierra_init);
@@ -747,6 +756,12 @@ MODULE_DESCRIPTION(DRIVER_DESC);
747MODULE_VERSION(DRIVER_VERSION); 756MODULE_VERSION(DRIVER_VERSION);
748MODULE_LICENSE("GPL"); 757MODULE_LICENSE("GPL");
749 758
759module_param(truinstall, bool, 0);
760MODULE_PARM_DESC(truinstall, "TRU-Install support");
761
762module_param(nmea, bool, 0);
763MODULE_PARM_DESC(nmea, "NMEA streaming");
764
750#ifdef CONFIG_USB_DEBUG 765#ifdef CONFIG_USB_DEBUG
751module_param(debug, bool, S_IRUGO | S_IWUSR); 766module_param(debug, bool, S_IRUGO | S_IWUSR);
752MODULE_PARM_DESC(debug, "Debug messages"); 767MODULE_PARM_DESC(debug, "Debug messages");
diff --git a/drivers/usb/serial/ti_usb_3410_5052.c b/drivers/usb/serial/ti_usb_3410_5052.c
index 1f0149495fb4..b517f93352ec 100644
--- a/drivers/usb/serial/ti_usb_3410_5052.c
+++ b/drivers/usb/serial/ti_usb_3410_5052.c
@@ -80,6 +80,7 @@
80#include <linux/ioctl.h> 80#include <linux/ioctl.h>
81#include <linux/serial.h> 81#include <linux/serial.h>
82#include <linux/circ_buf.h> 82#include <linux/circ_buf.h>
83#include <linux/mutex.h>
83#include <asm/uaccess.h> 84#include <asm/uaccess.h>
84#include <asm/semaphore.h> 85#include <asm/semaphore.h>
85#include <linux/usb.h> 86#include <linux/usb.h>
@@ -139,7 +140,7 @@ struct ti_port {
139}; 140};
140 141
141struct ti_device { 142struct ti_device {
142 struct semaphore td_open_close_sem; 143 struct mutex td_open_close_lock;
143 int td_open_port_count; 144 int td_open_port_count;
144 struct usb_serial *td_serial; 145 struct usb_serial *td_serial;
145 int td_is_3410; 146 int td_is_3410;
@@ -424,7 +425,7 @@ static int ti_startup(struct usb_serial *serial)
424 dev_err(&dev->dev, "%s - out of memory\n", __FUNCTION__); 425 dev_err(&dev->dev, "%s - out of memory\n", __FUNCTION__);
425 return -ENOMEM; 426 return -ENOMEM;
426 } 427 }
427 sema_init(&tdev->td_open_close_sem, 1); 428 mutex_init(&tdev->td_open_close_lock);
428 tdev->td_serial = serial; 429 tdev->td_serial = serial;
429 usb_set_serial_data(serial, tdev); 430 usb_set_serial_data(serial, tdev);
430 431
@@ -547,7 +548,7 @@ static int ti_open(struct usb_serial_port *port, struct file *file)
547 tdev = tport->tp_tdev; 548 tdev = tport->tp_tdev;
548 549
549 /* only one open on any port on a device at a time */ 550 /* only one open on any port on a device at a time */
550 if (down_interruptible(&tdev->td_open_close_sem)) 551 if (mutex_lock_interruptible(&tdev->td_open_close_lock))
551 return -ERESTARTSYS; 552 return -ERESTARTSYS;
552 553
553 if (port->tty) 554 if (port->tty)
@@ -568,7 +569,7 @@ static int ti_open(struct usb_serial_port *port, struct file *file)
568 if (!urb) { 569 if (!urb) {
569 dev_err(&port->dev, "%s - no interrupt urb\n", __FUNCTION__); 570 dev_err(&port->dev, "%s - no interrupt urb\n", __FUNCTION__);
570 status = -EINVAL; 571 status = -EINVAL;
571 goto up_sem; 572 goto release_lock;
572 } 573 }
573 urb->complete = ti_interrupt_callback; 574 urb->complete = ti_interrupt_callback;
574 urb->context = tdev; 575 urb->context = tdev;
@@ -576,11 +577,11 @@ static int ti_open(struct usb_serial_port *port, struct file *file)
576 status = usb_submit_urb(urb, GFP_KERNEL); 577 status = usb_submit_urb(urb, GFP_KERNEL);
577 if (status) { 578 if (status) {
578 dev_err(&port->dev, "%s - submit interrupt urb failed, %d\n", __FUNCTION__, status); 579 dev_err(&port->dev, "%s - submit interrupt urb failed, %d\n", __FUNCTION__, status);
579 goto up_sem; 580 goto release_lock;
580 } 581 }
581 } 582 }
582 583
583 ti_set_termios(port, NULL); 584 ti_set_termios(port, port->tty->termios);
584 585
585 dbg("%s - sending TI_OPEN_PORT", __FUNCTION__); 586 dbg("%s - sending TI_OPEN_PORT", __FUNCTION__);
586 status = ti_command_out_sync(tdev, TI_OPEN_PORT, 587 status = ti_command_out_sync(tdev, TI_OPEN_PORT,
@@ -617,7 +618,7 @@ static int ti_open(struct usb_serial_port *port, struct file *file)
617 usb_clear_halt(dev, port->write_urb->pipe); 618 usb_clear_halt(dev, port->write_urb->pipe);
618 usb_clear_halt(dev, port->read_urb->pipe); 619 usb_clear_halt(dev, port->read_urb->pipe);
619 620
620 ti_set_termios(port, NULL); 621 ti_set_termios(port, port->tty->termios);
621 622
622 dbg("%s - sending TI_OPEN_PORT (2)", __FUNCTION__); 623 dbg("%s - sending TI_OPEN_PORT (2)", __FUNCTION__);
623 status = ti_command_out_sync(tdev, TI_OPEN_PORT, 624 status = ti_command_out_sync(tdev, TI_OPEN_PORT,
@@ -656,13 +657,13 @@ static int ti_open(struct usb_serial_port *port, struct file *file)
656 tport->tp_is_open = 1; 657 tport->tp_is_open = 1;
657 ++tdev->td_open_port_count; 658 ++tdev->td_open_port_count;
658 659
659 goto up_sem; 660 goto release_lock;
660 661
661unlink_int_urb: 662unlink_int_urb:
662 if (tdev->td_open_port_count == 0) 663 if (tdev->td_open_port_count == 0)
663 usb_kill_urb(port->serial->port[0]->interrupt_in_urb); 664 usb_kill_urb(port->serial->port[0]->interrupt_in_urb);
664up_sem: 665release_lock:
665 up(&tdev->td_open_close_sem); 666 mutex_unlock(&tdev->td_open_close_lock);
666 dbg("%s - exit %d", __FUNCTION__, status); 667 dbg("%s - exit %d", __FUNCTION__, status);
667 return status; 668 return status;
668} 669}
@@ -674,7 +675,7 @@ static void ti_close(struct usb_serial_port *port, struct file *file)
674 struct ti_port *tport; 675 struct ti_port *tport;
675 int port_number; 676 int port_number;
676 int status; 677 int status;
677 int do_up; 678 int do_unlock;
678 679
679 dbg("%s - port %d", __FUNCTION__, port->number); 680 dbg("%s - port %d", __FUNCTION__, port->number);
680 681
@@ -699,16 +700,16 @@ static void ti_close(struct usb_serial_port *port, struct file *file)
699 if (status) 700 if (status)
700 dev_err(&port->dev, "%s - cannot send close port command, %d\n" , __FUNCTION__, status); 701 dev_err(&port->dev, "%s - cannot send close port command, %d\n" , __FUNCTION__, status);
701 702
702 /* if down is interrupted, continue anyway */ 703 /* if mutex_lock is interrupted, continue anyway */
703 do_up = !down_interruptible(&tdev->td_open_close_sem); 704 do_unlock = !mutex_lock_interruptible(&tdev->td_open_close_lock);
704 --tport->tp_tdev->td_open_port_count; 705 --tport->tp_tdev->td_open_port_count;
705 if (tport->tp_tdev->td_open_port_count <= 0) { 706 if (tport->tp_tdev->td_open_port_count <= 0) {
706 /* last port is closed, shut down interrupt urb */ 707 /* last port is closed, shut down interrupt urb */
707 usb_kill_urb(port->serial->port[0]->interrupt_in_urb); 708 usb_kill_urb(port->serial->port[0]->interrupt_in_urb);
708 tport->tp_tdev->td_open_port_count = 0; 709 tport->tp_tdev->td_open_port_count = 0;
709 } 710 }
710 if (do_up) 711 if (do_unlock)
711 up(&tdev->td_open_close_sem); 712 mutex_unlock(&tdev->td_open_close_lock);
712 713
713 dbg("%s - exit", __FUNCTION__); 714 dbg("%s - exit", __FUNCTION__);
714} 715}
@@ -896,24 +897,11 @@ static void ti_set_termios(struct usb_serial_port *port,
896 897
897 dbg("%s - port %d", __FUNCTION__, port->number); 898 dbg("%s - port %d", __FUNCTION__, port->number);
898 899
899 if (!tty || !tty->termios) {
900 dbg("%s - no tty or termios", __FUNCTION__);
901 return;
902 }
903
904 cflag = tty->termios->c_cflag; 900 cflag = tty->termios->c_cflag;
905 iflag = tty->termios->c_iflag; 901 iflag = tty->termios->c_iflag;
906 902
907 if (old_termios && cflag == old_termios->c_cflag 903 dbg("%s - cflag %08x, iflag %08x", __FUNCTION__, cflag, iflag);
908 && iflag == old_termios->c_iflag) { 904 dbg("%s - old clfag %08x, old iflag %08x", __FUNCTION__, old_termios->c_cflag, old_termios->c_iflag);
909 dbg("%s - nothing to change", __FUNCTION__);
910 return;
911 }
912
913 dbg("%s - clfag %08x, iflag %08x", __FUNCTION__, cflag, iflag);
914
915 if (old_termios)
916 dbg("%s - old clfag %08x, old iflag %08x", __FUNCTION__, old_termios->c_cflag, old_termios->c_iflag);
917 905
918 if (tport == NULL) 906 if (tport == NULL)
919 return; 907 return;
@@ -947,6 +935,9 @@ static void ti_set_termios(struct usb_serial_port *port,
947 break; 935 break;
948 } 936 }
949 937
938 /* CMSPAR isn't supported by this driver */
939 tty->termios->c_cflag &= ~CMSPAR;
940
950 if (cflag & PARENB) { 941 if (cflag & PARENB) {
951 if (cflag & PARODD) { 942 if (cflag & PARODD) {
952 config->wFlags |= TI_UART_ENABLE_PARITY_CHECKING; 943 config->wFlags |= TI_UART_ENABLE_PARITY_CHECKING;
@@ -989,12 +980,17 @@ static void ti_set_termios(struct usb_serial_port *port,
989 } 980 }
990 981
991 baud = tty_get_baud_rate(tty); 982 baud = tty_get_baud_rate(tty);
992 if (!baud) baud = 9600; 983 if (!baud)
984 baud = 9600;
993 if (tport->tp_tdev->td_is_3410) 985 if (tport->tp_tdev->td_is_3410)
994 config->wBaudRate = (__u16)((923077 + baud/2) / baud); 986 config->wBaudRate = (__u16)((923077 + baud/2) / baud);
995 else 987 else
996 config->wBaudRate = (__u16)((461538 + baud/2) / baud); 988 config->wBaudRate = (__u16)((461538 + baud/2) / baud);
997 989
990 /* FIXME: Should calculate resulting baud here and report it back */
991 if ((cflag & CBAUD) != B0)
992 tty_encode_baud_rate(tty, baud, baud);
993
998 dbg("%s - BaudRate=%d, wBaudRate=%d, wFlags=0x%04X, bDataBits=%d, bParity=%d, bStopBits=%d, cXon=%d, cXoff=%d, bUartMode=%d", 994 dbg("%s - BaudRate=%d, wBaudRate=%d, wFlags=0x%04X, bDataBits=%d, bParity=%d, bStopBits=%d, cXon=%d, cXoff=%d, bUartMode=%d",
999 __FUNCTION__, baud, config->wBaudRate, config->wFlags, config->bDataBits, config->bParity, config->bStopBits, config->cXon, config->cXoff, config->bUartMode); 995 __FUNCTION__, baud, config->wBaudRate, config->wFlags, config->bDataBits, config->bParity, config->bStopBits, config->cXon, config->cXoff, config->bUartMode);
1000 996
@@ -1497,11 +1493,10 @@ static void ti_drain(struct ti_port *tport, unsigned long timeout, int flush)
1497 struct ti_device *tdev = tport->tp_tdev; 1493 struct ti_device *tdev = tport->tp_tdev;
1498 struct usb_serial_port *port = tport->tp_port; 1494 struct usb_serial_port *port = tport->tp_port;
1499 wait_queue_t wait; 1495 wait_queue_t wait;
1500 unsigned long flags;
1501 1496
1502 dbg("%s - port %d", __FUNCTION__, port->number); 1497 dbg("%s - port %d", __FUNCTION__, port->number);
1503 1498
1504 spin_lock_irqsave(&tport->tp_lock, flags); 1499 spin_lock_irq(&tport->tp_lock);
1505 1500
1506 /* wait for data to drain from the buffer */ 1501 /* wait for data to drain from the buffer */
1507 tdev->td_urb_error = 0; 1502 tdev->td_urb_error = 0;
@@ -1512,11 +1507,11 @@ static void ti_drain(struct ti_port *tport, unsigned long timeout, int flush)
1512 if (ti_buf_data_avail(tport->tp_write_buf) == 0 1507 if (ti_buf_data_avail(tport->tp_write_buf) == 0
1513 || timeout == 0 || signal_pending(current) 1508 || timeout == 0 || signal_pending(current)
1514 || tdev->td_urb_error 1509 || tdev->td_urb_error
1515 || !usb_get_intfdata(port->serial->interface)) /* disconnect */ 1510 || port->serial->disconnected) /* disconnect */
1516 break; 1511 break;
1517 spin_unlock_irqrestore(&tport->tp_lock, flags); 1512 spin_unlock_irq(&tport->tp_lock);
1518 timeout = schedule_timeout(timeout); 1513 timeout = schedule_timeout(timeout);
1519 spin_lock_irqsave(&tport->tp_lock, flags); 1514 spin_lock_irq(&tport->tp_lock);
1520 } 1515 }
1521 set_current_state(TASK_RUNNING); 1516 set_current_state(TASK_RUNNING);
1522 remove_wait_queue(&tport->tp_write_wait, &wait); 1517 remove_wait_queue(&tport->tp_write_wait, &wait);
@@ -1525,19 +1520,23 @@ static void ti_drain(struct ti_port *tport, unsigned long timeout, int flush)
1525 if (flush) 1520 if (flush)
1526 ti_buf_clear(tport->tp_write_buf); 1521 ti_buf_clear(tport->tp_write_buf);
1527 1522
1528 spin_unlock_irqrestore(&tport->tp_lock, flags); 1523 spin_unlock_irq(&tport->tp_lock);
1529 1524
1525 mutex_lock(&port->serial->disc_mutex);
1530 /* wait for data to drain from the device */ 1526 /* wait for data to drain from the device */
1531 /* wait for empty tx register, plus 20 ms */ 1527 /* wait for empty tx register, plus 20 ms */
1532 timeout += jiffies; 1528 timeout += jiffies;
1533 tport->tp_lsr &= ~TI_LSR_TX_EMPTY; 1529 tport->tp_lsr &= ~TI_LSR_TX_EMPTY;
1534 while ((long)(jiffies - timeout) < 0 && !signal_pending(current) 1530 while ((long)(jiffies - timeout) < 0 && !signal_pending(current)
1535 && !(tport->tp_lsr&TI_LSR_TX_EMPTY) && !tdev->td_urb_error 1531 && !(tport->tp_lsr&TI_LSR_TX_EMPTY) && !tdev->td_urb_error
1536 && usb_get_intfdata(port->serial->interface)) { /* not disconnected */ 1532 && !port->serial->disconnected) {
1537 if (ti_get_lsr(tport)) 1533 if (ti_get_lsr(tport))
1538 break; 1534 break;
1535 mutex_unlock(&port->serial->disc_mutex);
1539 msleep_interruptible(20); 1536 msleep_interruptible(20);
1537 mutex_lock(&port->serial->disc_mutex);
1540 } 1538 }
1539 mutex_unlock(&port->serial->disc_mutex);
1541} 1540}
1542 1541
1543 1542
diff --git a/drivers/usb/serial/usb-serial.c b/drivers/usb/serial/usb-serial.c
index 497e29a700ca..3ce98e8d7bce 100644
--- a/drivers/usb/serial/usb-serial.c
+++ b/drivers/usb/serial/usb-serial.c
@@ -225,16 +225,21 @@ static int serial_open (struct tty_struct *tty, struct file * filp)
225 goto bailout_mutex_unlock; 225 goto bailout_mutex_unlock;
226 } 226 }
227 227
228 retval = usb_autopm_get_interface(serial->interface);
229 if (retval)
230 goto bailout_module_put;
228 /* only call the device specific open if this 231 /* only call the device specific open if this
229 * is the first time the port is opened */ 232 * is the first time the port is opened */
230 retval = serial->type->open(port, filp); 233 retval = serial->type->open(port, filp);
231 if (retval) 234 if (retval)
232 goto bailout_module_put; 235 goto bailout_interface_put;
233 } 236 }
234 237
235 mutex_unlock(&port->mutex); 238 mutex_unlock(&port->mutex);
236 return 0; 239 return 0;
237 240
241bailout_interface_put:
242 usb_autopm_put_interface(serial->interface);
238bailout_module_put: 243bailout_module_put:
239 module_put(serial->type->driver.owner); 244 module_put(serial->type->driver.owner);
240bailout_mutex_unlock: 245bailout_mutex_unlock:
@@ -264,17 +269,21 @@ static void serial_close(struct tty_struct *tty, struct file * filp)
264 } 269 }
265 270
266 --port->open_count; 271 --port->open_count;
267 if (port->open_count == 0) { 272 if (port->open_count == 0)
268 /* only call the device specific close if this 273 /* only call the device specific close if this
269 * port is being closed by the last owner */ 274 * port is being closed by the last owner */
270 port->serial->type->close(port, filp); 275 port->serial->type->close(port, filp);
271 276
277 if (port->open_count == (port->console? 1 : 0)) {
272 if (port->tty) { 278 if (port->tty) {
273 if (port->tty->driver_data) 279 if (port->tty->driver_data)
274 port->tty->driver_data = NULL; 280 port->tty->driver_data = NULL;
275 port->tty = NULL; 281 port->tty = NULL;
276 } 282 }
283 }
277 284
285 if (port->open_count == 0) {
286 usb_autopm_put_interface(port->serial->interface);
278 module_put(port->serial->type->driver.owner); 287 module_put(port->serial->type->driver.owner);
279 } 288 }
280 289
@@ -625,6 +634,7 @@ static struct usb_serial * create_serial (struct usb_device *dev,
625 serial->type = driver; 634 serial->type = driver;
626 serial->interface = interface; 635 serial->interface = interface;
627 kref_init(&serial->kref); 636 kref_init(&serial->kref);
637 mutex_init(&serial->disc_mutex);
628 638
629 return serial; 639 return serial;
630} 640}
@@ -1080,20 +1090,22 @@ void usb_serial_disconnect(struct usb_interface *interface)
1080 usb_serial_console_disconnect(serial); 1090 usb_serial_console_disconnect(serial);
1081 dbg ("%s", __FUNCTION__); 1091 dbg ("%s", __FUNCTION__);
1082 1092
1093 mutex_lock(&serial->disc_mutex);
1083 usb_set_intfdata (interface, NULL); 1094 usb_set_intfdata (interface, NULL);
1084 if (serial) { 1095 /* must set a flag, to signal subdrivers */
1085 for (i = 0; i < serial->num_ports; ++i) { 1096 serial->disconnected = 1;
1086 port = serial->port[i]; 1097 for (i = 0; i < serial->num_ports; ++i) {
1087 if (port) { 1098 port = serial->port[i];
1088 if (port->tty) 1099 if (port) {
1089 tty_hangup(port->tty); 1100 if (port->tty)
1090 kill_traffic(port); 1101 tty_hangup(port->tty);
1091 } 1102 kill_traffic(port);
1092 } 1103 }
1093 /* let the last holder of this object
1094 * cause it to be cleaned up */
1095 usb_serial_put(serial);
1096 } 1104 }
1105 /* let the last holder of this object
1106 * cause it to be cleaned up */
1107 mutex_unlock(&serial->disc_mutex);
1108 usb_serial_put(serial);
1097 dev_info(dev, "device disconnected\n"); 1109 dev_info(dev, "device disconnected\n");
1098} 1110}
1099 1111
@@ -1103,9 +1115,6 @@ int usb_serial_suspend(struct usb_interface *intf, pm_message_t message)
1103 struct usb_serial_port *port; 1115 struct usb_serial_port *port;
1104 int i, r = 0; 1116 int i, r = 0;
1105 1117
1106 if (!serial) /* device has been disconnected */
1107 return 0;
1108
1109 for (i = 0; i < serial->num_ports; ++i) { 1118 for (i = 0; i < serial->num_ports; ++i) {
1110 port = serial->port[i]; 1119 port = serial->port[i];
1111 if (port) 1120 if (port)
@@ -1253,6 +1262,7 @@ static void fixup_generic(struct usb_serial_driver *device)
1253 set_to_generic_if_null(device, read_bulk_callback); 1262 set_to_generic_if_null(device, read_bulk_callback);
1254 set_to_generic_if_null(device, write_bulk_callback); 1263 set_to_generic_if_null(device, write_bulk_callback);
1255 set_to_generic_if_null(device, shutdown); 1264 set_to_generic_if_null(device, shutdown);
1265 set_to_generic_if_null(device, resume);
1256} 1266}
1257 1267
1258int usb_serial_register(struct usb_serial_driver *driver) /* must be called with BKL held */ 1268int usb_serial_register(struct usb_serial_driver *driver) /* must be called with BKL held */
diff --git a/drivers/usb/serial/visor.c b/drivers/usb/serial/visor.c
index 7ee087fed913..22b3f78a388c 100644
--- a/drivers/usb/serial/visor.c
+++ b/drivers/usb/serial/visor.c
@@ -349,16 +349,20 @@ static void visor_close (struct usb_serial_port *port, struct file * filp)
349 usb_kill_urb(port->read_urb); 349 usb_kill_urb(port->read_urb);
350 usb_kill_urb(port->interrupt_in_urb); 350 usb_kill_urb(port->interrupt_in_urb);
351 351
352 /* Try to send shutdown message, if the device is gone, this will just fail. */ 352 mutex_lock(&port->serial->disc_mutex);
353 transfer_buffer = kmalloc (0x12, GFP_KERNEL); 353 if (!port->serial->disconnected) {
354 if (transfer_buffer) { 354 /* Try to send shutdown message, unless the device is gone */
355 usb_control_msg (port->serial->dev, 355 transfer_buffer = kmalloc (0x12, GFP_KERNEL);
356 usb_rcvctrlpipe(port->serial->dev, 0), 356 if (transfer_buffer) {
357 VISOR_CLOSE_NOTIFICATION, 0xc2, 357 usb_control_msg (port->serial->dev,
358 0x0000, 0x0000, 358 usb_rcvctrlpipe(port->serial->dev, 0),
359 transfer_buffer, 0x12, 300); 359 VISOR_CLOSE_NOTIFICATION, 0xc2,
360 kfree (transfer_buffer); 360 0x0000, 0x0000,
361 transfer_buffer, 0x12, 300);
362 kfree (transfer_buffer);
363 }
361 } 364 }
365 mutex_unlock(&port->serial->disc_mutex);
362 366
363 if (stats) 367 if (stats)
364 dev_info(&port->dev, "Bytes In = %d Bytes Out = %d\n", 368 dev_info(&port->dev, "Bytes In = %d Bytes Out = %d\n",
diff --git a/drivers/usb/serial/whiteheat.c b/drivers/usb/serial/whiteheat.c
index ee5dd8b5a713..38726ef3132b 100644
--- a/drivers/usb/serial/whiteheat.c
+++ b/drivers/usb/serial/whiteheat.c
@@ -610,8 +610,7 @@ static int whiteheat_open (struct usb_serial_port *port, struct file *filp)
610 if (retval) 610 if (retval)
611 goto exit; 611 goto exit;
612 612
613 if (port->tty) 613 port->tty->low_latency = 1;
614 port->tty->low_latency = 1;
615 614
616 /* send an open port command */ 615 /* send an open port command */
617 retval = firm_open(port); 616 retval = firm_open(port);
@@ -659,11 +658,14 @@ static void whiteheat_close(struct usb_serial_port *port, struct file * filp)
659 struct list_head *tmp2; 658 struct list_head *tmp2;
660 659
661 dbg("%s - port %d", __FUNCTION__, port->number); 660 dbg("%s - port %d", __FUNCTION__, port->number);
662 661
662 mutex_lock(&port->serial->disc_mutex);
663 /* filp is NULL when called from usb_serial_disconnect */ 663 /* filp is NULL when called from usb_serial_disconnect */
664 if (filp && (tty_hung_up_p(filp))) { 664 if ((filp && (tty_hung_up_p(filp))) || port->serial->disconnected) {
665 mutex_unlock(&port->serial->disc_mutex);
665 return; 666 return;
666 } 667 }
668 mutex_unlock(&port->serial->disc_mutex);
667 669
668 port->tty->closing = 1; 670 port->tty->closing = 1;
669 671
diff --git a/drivers/usb/storage/initializers.c b/drivers/usb/storage/initializers.c
index ee5b42aa5363..187dd1e01093 100644
--- a/drivers/usb/storage/initializers.c
+++ b/drivers/usb/storage/initializers.c
@@ -66,7 +66,8 @@ int usb_stor_ucr61s2b_init(struct us_data *us)
66{ 66{
67 struct bulk_cb_wrap *bcb = (struct bulk_cb_wrap*) us->iobuf; 67 struct bulk_cb_wrap *bcb = (struct bulk_cb_wrap*) us->iobuf;
68 struct bulk_cs_wrap *bcs = (struct bulk_cs_wrap*) us->iobuf; 68 struct bulk_cs_wrap *bcs = (struct bulk_cs_wrap*) us->iobuf;
69 int res, partial; 69 int res;
70 unsigned int partial;
70 static char init_string[] = "\xec\x0a\x06\x00$PCCHIPS"; 71 static char init_string[] = "\xec\x0a\x06\x00$PCCHIPS";
71 72
72 US_DEBUGP("Sending UCR-61S2B initialization packet...\n"); 73 US_DEBUGP("Sending UCR-61S2B initialization packet...\n");
diff --git a/drivers/usb/storage/isd200.c b/drivers/usb/storage/isd200.c
index 0db488624ab1..2ae1e8673b19 100644
--- a/drivers/usb/storage/isd200.c
+++ b/drivers/usb/storage/isd200.c
@@ -48,7 +48,6 @@
48#include <linux/errno.h> 48#include <linux/errno.h>
49#include <linux/slab.h> 49#include <linux/slab.h>
50#include <linux/hdreg.h> 50#include <linux/hdreg.h>
51#include <linux/ide.h>
52#include <linux/scatterlist.h> 51#include <linux/scatterlist.h>
53 52
54#include <scsi/scsi.h> 53#include <scsi/scsi.h>
@@ -110,6 +109,12 @@
110#define REG_STATUS 0x80 109#define REG_STATUS 0x80
111#define REG_COMMAND 0x80 110#define REG_COMMAND 0x80
112 111
112/* ATA registers offset definitions */
113#define ATA_REG_ERROR_OFFSET 1
114#define ATA_REG_LCYL_OFFSET 4
115#define ATA_REG_HCYL_OFFSET 5
116#define ATA_REG_STATUS_OFFSET 7
117
113/* ATA error definitions not in <linux/hdreg.h> */ 118/* ATA error definitions not in <linux/hdreg.h> */
114#define ATA_ERROR_MEDIA_CHANGE 0x20 119#define ATA_ERROR_MEDIA_CHANGE 0x20
115 120
@@ -360,7 +365,7 @@ static void isd200_build_sense(struct us_data *us, struct scsi_cmnd *srb)
360{ 365{
361 struct isd200_info *info = (struct isd200_info *)us->extra; 366 struct isd200_info *info = (struct isd200_info *)us->extra;
362 struct sense_data *buf = (struct sense_data *) &srb->sense_buffer[0]; 367 struct sense_data *buf = (struct sense_data *) &srb->sense_buffer[0];
363 unsigned char error = info->ATARegs[IDE_ERROR_OFFSET]; 368 unsigned char error = info->ATARegs[ATA_REG_ERROR_OFFSET];
364 369
365 if(error & ATA_ERROR_MEDIA_CHANGE) { 370 if(error & ATA_ERROR_MEDIA_CHANGE) {
366 buf->ErrorCode = 0x70 | SENSE_ERRCODE_VALID; 371 buf->ErrorCode = 0x70 | SENSE_ERRCODE_VALID;
@@ -549,8 +554,8 @@ static int isd200_read_regs( struct us_data *us )
549 retStatus = ISD200_ERROR; 554 retStatus = ISD200_ERROR;
550 } else { 555 } else {
551 memcpy(info->ATARegs, info->RegsBuf, sizeof(info->ATARegs)); 556 memcpy(info->ATARegs, info->RegsBuf, sizeof(info->ATARegs));
552 US_DEBUGP(" Got ATA Register[IDE_ERROR_OFFSET] = 0x%x\n", 557 US_DEBUGP(" Got ATA Register[ATA_REG_ERROR_OFFSET] = 0x%x\n",
553 info->ATARegs[IDE_ERROR_OFFSET]); 558 info->ATARegs[ATA_REG_ERROR_OFFSET]);
554 } 559 }
555 560
556 return retStatus; 561 return retStatus;
@@ -892,7 +897,7 @@ static int isd200_try_enum(struct us_data *us, unsigned char master_slave,
892 break; 897 break;
893 898
894 if (!detect) { 899 if (!detect) {
895 if (regs[IDE_STATUS_OFFSET] & BUSY_STAT ) { 900 if (regs[ATA_REG_STATUS_OFFSET] & BUSY_STAT) {
896 US_DEBUGP(" %s status is still BSY, try again...\n",mstr); 901 US_DEBUGP(" %s status is still BSY, try again...\n",mstr);
897 } else { 902 } else {
898 US_DEBUGP(" %s status !BSY, continue with next operation\n",mstr); 903 US_DEBUGP(" %s status !BSY, continue with next operation\n",mstr);
@@ -902,12 +907,12 @@ static int isd200_try_enum(struct us_data *us, unsigned char master_slave,
902 /* check for BUSY_STAT and */ 907 /* check for BUSY_STAT and */
903 /* WRERR_STAT (workaround ATA Zip drive) and */ 908 /* WRERR_STAT (workaround ATA Zip drive) and */
904 /* ERR_STAT (workaround for Archos CD-ROM) */ 909 /* ERR_STAT (workaround for Archos CD-ROM) */
905 else if (regs[IDE_STATUS_OFFSET] & 910 else if (regs[ATA_REG_STATUS_OFFSET] &
906 (BUSY_STAT | WRERR_STAT | ERR_STAT )) { 911 (BUSY_STAT | WRERR_STAT | ERR_STAT )) {
907 US_DEBUGP(" Status indicates it is not ready, try again...\n"); 912 US_DEBUGP(" Status indicates it is not ready, try again...\n");
908 } 913 }
909 /* check for DRDY, ATA devices set DRDY after SRST */ 914 /* check for DRDY, ATA devices set DRDY after SRST */
910 else if (regs[IDE_STATUS_OFFSET] & READY_STAT) { 915 else if (regs[ATA_REG_STATUS_OFFSET] & READY_STAT) {
911 US_DEBUGP(" Identified ATA device\n"); 916 US_DEBUGP(" Identified ATA device\n");
912 info->DeviceFlags |= DF_ATA_DEVICE; 917 info->DeviceFlags |= DF_ATA_DEVICE;
913 info->DeviceHead = master_slave; 918 info->DeviceHead = master_slave;
@@ -916,8 +921,8 @@ static int isd200_try_enum(struct us_data *us, unsigned char master_slave,
916 /* check Cylinder High/Low to 921 /* check Cylinder High/Low to
917 determine if it is an ATAPI device 922 determine if it is an ATAPI device
918 */ 923 */
919 else if ((regs[IDE_HCYL_OFFSET] == 0xEB) && 924 else if (regs[ATA_REG_HCYL_OFFSET] == 0xEB &&
920 (regs[IDE_LCYL_OFFSET] == 0x14)) { 925 regs[ATA_REG_LCYL_OFFSET] == 0x14) {
921 /* It seems that the RICOH 926 /* It seems that the RICOH
922 MP6200A CD/RW drive will 927 MP6200A CD/RW drive will
923 report itself okay as a 928 report itself okay as a
@@ -1001,12 +1006,6 @@ static int isd200_manual_enum(struct us_data *us)
1001 return(retStatus); 1006 return(retStatus);
1002} 1007}
1003 1008
1004/*
1005 * We are the last non IDE user of the legacy IDE ident structures
1006 * and we thus want to keep a private copy of this function so the
1007 * driver can be used without the obsolete drivers/ide layer
1008 */
1009
1010static void isd200_fix_driveid (struct hd_driveid *id) 1009static void isd200_fix_driveid (struct hd_driveid *id)
1011{ 1010{
1012#ifndef __LITTLE_ENDIAN 1011#ifndef __LITTLE_ENDIAN
diff --git a/drivers/usb/storage/unusual_devs.h b/drivers/usb/storage/unusual_devs.h
index 6d6108b3993b..fe12737e0e2b 100644
--- a/drivers/usb/storage/unusual_devs.h
+++ b/drivers/usb/storage/unusual_devs.h
@@ -86,6 +86,14 @@ UNUSUAL_DEV( 0x03f0, 0x0307, 0x0001, 0x0001,
86 US_SC_8070, US_PR_USBAT, init_usbat_cd, 0), 86 US_SC_8070, US_PR_USBAT, init_usbat_cd, 0),
87#endif 87#endif
88 88
89/* Reported by Grant Grundler <grundler@parisc-linux.org>
90 * HP r707 camera in "Disk" mode with 2.00.23 or 2.00.24 firmware.
91 */
92UNUSUAL_DEV( 0x03f0, 0x4002, 0x0001, 0x0001,
93 "HP",
94 "PhotoSmart R707",
95 US_SC_DEVICE, US_PR_DEVICE, NULL, US_FL_FIX_CAPACITY),
96
89/* Reported by Sebastian Kapfer <sebastian_kapfer@gmx.net> 97/* Reported by Sebastian Kapfer <sebastian_kapfer@gmx.net>
90 * and Olaf Hering <olh@suse.de> (different bcd's, same vendor/product) 98 * and Olaf Hering <olh@suse.de> (different bcd's, same vendor/product)
91 * for USB floppies that need the SINGLE_LUN enforcement. 99 * for USB floppies that need the SINGLE_LUN enforcement.
diff --git a/drivers/video/sis/sis.h b/drivers/video/sis/sis.h
index d53bf6945f0c..9b05da6268f7 100644
--- a/drivers/video/sis/sis.h
+++ b/drivers/video/sis/sis.h
@@ -39,12 +39,7 @@
39#include <linux/spinlock.h> 39#include <linux/spinlock.h>
40 40
41#ifdef CONFIG_COMPAT 41#ifdef CONFIG_COMPAT
42#if LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,10)
43#include <linux/ioctl32.h>
44#define SIS_OLD_CONFIG_COMPAT
45#else
46#define SIS_NEW_CONFIG_COMPAT 42#define SIS_NEW_CONFIG_COMPAT
47#endif
48#endif /* CONFIG_COMPAT */ 43#endif /* CONFIG_COMPAT */
49 44
50#if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,8) 45#if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,8)
@@ -607,9 +602,6 @@ struct sis_video_info {
607 int haveXGIROM; 602 int haveXGIROM;
608 int registered; 603 int registered;
609 int warncount; 604 int warncount;
610#ifdef SIS_OLD_CONFIG_COMPAT
611 int ioctl32registered;
612#endif
613 605
614 int sisvga_engine; 606 int sisvga_engine;
615 int hwcursor_size; 607 int hwcursor_size;
diff --git a/drivers/video/sis/sis_main.c b/drivers/video/sis/sis_main.c
index 37bd24b8d83b..93ae747440cb 100644
--- a/drivers/video/sis/sis_main.c
+++ b/drivers/video/sis/sis_main.c
@@ -5805,9 +5805,6 @@ sisfb_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
5805 ivideo->pcifunc = PCI_FUNC(pdev->devfn); 5805 ivideo->pcifunc = PCI_FUNC(pdev->devfn);
5806 ivideo->subsysvendor = pdev->subsystem_vendor; 5806 ivideo->subsysvendor = pdev->subsystem_vendor;
5807 ivideo->subsysdevice = pdev->subsystem_device; 5807 ivideo->subsysdevice = pdev->subsystem_device;
5808#ifdef SIS_OLD_CONFIG_COMPAT
5809 ivideo->ioctl32registered = 0;
5810#endif
5811 5808
5812#ifndef MODULE 5809#ifndef MODULE
5813 if(sisfb_mode_idx == -1) { 5810 if(sisfb_mode_idx == -1) {
@@ -6420,30 +6417,6 @@ error_3: vfree(ivideo->bios_abase);
6420 ivideo->next = card_list; 6417 ivideo->next = card_list;
6421 card_list = ivideo; 6418 card_list = ivideo;
6422 6419
6423#ifdef SIS_OLD_CONFIG_COMPAT
6424 {
6425 int ret;
6426 /* Our ioctls are all "32/64bit compatible" */
6427 ret = register_ioctl32_conversion(FBIO_ALLOC, NULL);
6428 ret |= register_ioctl32_conversion(FBIO_FREE, NULL);
6429 ret |= register_ioctl32_conversion(FBIOGET_VBLANK, NULL);
6430 ret |= register_ioctl32_conversion(SISFB_GET_INFO_SIZE, NULL);
6431 ret |= register_ioctl32_conversion(SISFB_GET_INFO, NULL);
6432 ret |= register_ioctl32_conversion(SISFB_GET_TVPOSOFFSET, NULL);
6433 ret |= register_ioctl32_conversion(SISFB_SET_TVPOSOFFSET, NULL);
6434 ret |= register_ioctl32_conversion(SISFB_SET_LOCK, NULL);
6435 ret |= register_ioctl32_conversion(SISFB_GET_VBRSTATUS, NULL);
6436 ret |= register_ioctl32_conversion(SISFB_GET_AUTOMAXIMIZE, NULL);
6437 ret |= register_ioctl32_conversion(SISFB_SET_AUTOMAXIMIZE, NULL);
6438 ret |= register_ioctl32_conversion(SISFB_COMMAND, NULL);
6439 if(ret)
6440 printk(KERN_ERR
6441 "sisfb: Error registering ioctl32 translations\n");
6442 else
6443 ivideo->ioctl32registered = 1;
6444 }
6445#endif
6446
6447 printk(KERN_INFO "sisfb: 2D acceleration is %s, y-panning %s\n", 6420 printk(KERN_INFO "sisfb: 2D acceleration is %s, y-panning %s\n",
6448 ivideo->sisfb_accel ? "enabled" : "disabled", 6421 ivideo->sisfb_accel ? "enabled" : "disabled",
6449 ivideo->sisfb_ypan ? 6422 ivideo->sisfb_ypan ?
@@ -6473,27 +6446,6 @@ static void __devexit sisfb_remove(struct pci_dev *pdev)
6473 int registered = ivideo->registered; 6446 int registered = ivideo->registered;
6474 int modechanged = ivideo->modechanged; 6447 int modechanged = ivideo->modechanged;
6475 6448
6476#ifdef SIS_OLD_CONFIG_COMPAT
6477 if(ivideo->ioctl32registered) {
6478 int ret;
6479 ret = unregister_ioctl32_conversion(FBIO_ALLOC);
6480 ret |= unregister_ioctl32_conversion(FBIO_FREE);
6481 ret |= unregister_ioctl32_conversion(FBIOGET_VBLANK);
6482 ret |= unregister_ioctl32_conversion(SISFB_GET_INFO_SIZE);
6483 ret |= unregister_ioctl32_conversion(SISFB_GET_INFO);
6484 ret |= unregister_ioctl32_conversion(SISFB_GET_TVPOSOFFSET);
6485 ret |= unregister_ioctl32_conversion(SISFB_SET_TVPOSOFFSET);
6486 ret |= unregister_ioctl32_conversion(SISFB_SET_LOCK);
6487 ret |= unregister_ioctl32_conversion(SISFB_GET_VBRSTATUS);
6488 ret |= unregister_ioctl32_conversion(SISFB_GET_AUTOMAXIMIZE);
6489 ret |= unregister_ioctl32_conversion(SISFB_SET_AUTOMAXIMIZE);
6490 ret |= unregister_ioctl32_conversion(SISFB_COMMAND);
6491 if(ret)
6492 printk(KERN_ERR
6493 "sisfb: Error unregistering ioctl32 translations\n");
6494 }
6495#endif
6496
6497 /* Unmap */ 6449 /* Unmap */
6498 iounmap(ivideo->mmio_vbase); 6450 iounmap(ivideo->mmio_vbase);
6499 iounmap(ivideo->video_vbase); 6451 iounmap(ivideo->video_vbase);