From 3004e5379a525d848bbe8ddff2c534ac0fb04e2c Mon Sep 17 00:00:00 2001 From: Alan Cox Date: Thu, 3 Jan 2008 16:59:04 +0000 Subject: USB: keyspan: Fix oops If we get a data URB back from the hardware after we have put the tty to bed we go kaboom. Fortunately all we need to do is process the URB without trying to ram its contents down the throat of an ex-tty. Cc: stable Signed-off-by: Alan Cox Signed-off-by: Greg Kroah-Hartman --- drivers/usb/serial/keyspan.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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) port = (struct usb_serial_port *) urb->context; tty = port->tty; - if (urb->actual_length) { + if (tty && urb->actual_length) { /* 0x80 bit is error flag */ if ((data[0] & 0x80) == 0) { /* no error on any byte */ -- cgit v1.2.3 From 2336a986793c771008b181ec65334c240ce512ca Mon Sep 17 00:00:00 2001 From: Li Yang Date: Thu, 3 Jan 2008 10:04:40 -0800 Subject: usb gadget: fix fsl_usb2_udc potential OOPS For fsl_usb2_udc driver, ep0 also has a descriptor. Current code is misleading and contains a logical mistake. Here is the patch to fix it. http://bugzilla.kernel.org/show_bug.cgi?id=9595 Cc: stable Signed-off-by: David Brownell Signed-off-by: Greg Kroah-Hartman --- drivers/usb/gadget/fsl_usb2_udc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/usb/gadget/fsl_usb2_udc.c b/drivers/usb/gadget/fsl_usb2_udc.c index 038e7d7b4da1..d59eb92a847d 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) VDBG("%s, bad params\n", __FUNCTION__); return -EINVAL; } - if (!_ep || (!ep->desc && ep_index(ep))) { + if (unlikely(!_ep || !ep->desc)) { VDBG("%s, bad ep\n", __FUNCTION__); return -EINVAL; } -- cgit v1.2.3 From 5de8b3acda2d03f8aeb21b5a267645088718c356 Mon Sep 17 00:00:00 2001 From: Craig Shelley Date: Thu, 3 Jan 2008 12:45:59 +0000 Subject: USB: CP2101 New Device IDs Six new device IDs for CP2101 driver. Cc: stable Signed-off-by: Craig Shelley Signed-off-by: Greg Kroah-Hartman --- drivers/usb/serial/cp2101.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/drivers/usb/serial/cp2101.c b/drivers/usb/serial/cp2101.c index 22833589c4be..cd5f71b7f637 100644 --- a/drivers/usb/serial/cp2101.c +++ b/drivers/usb/serial/cp2101.c @@ -59,6 +59,7 @@ static struct usb_device_id id_table [] = { { USB_DEVICE(0x10A6, 0xAA26) }, /* Knock-off DCU-11 cable */ { USB_DEVICE(0x10AB, 0x10C5) }, /* Siemens MC60 Cable */ { USB_DEVICE(0x10B5, 0xAC70) }, /* Nokia CA-42 USB */ + { USB_DEVICE(0x10C4, 0x800A) }, /* SPORTident BSM7-D-USB main station */ { USB_DEVICE(0x10C4, 0x803B) }, /* Pololu USB-serial converter */ { USB_DEVICE(0x10C4, 0x8053) }, /* Enfora EDG1228 */ { USB_DEVICE(0x10C4, 0x8066) }, /* Argussoft In-System Programmer */ @@ -76,8 +77,13 @@ static struct usb_device_id id_table [] = { { USB_DEVICE(0x10C4, 0x8218) }, /* Lipowsky Industrie Elektronik GmbH, HARP-1 */ { USB_DEVICE(0x10C4, 0xEA60) }, /* Silicon Labs factory default */ { USB_DEVICE(0x10C4, 0xEA61) }, /* Silicon Labs factory default */ + { USB_DEVICE(0x10C4, 0xF001) }, /* Elan Digital Systems USBscope50 */ + { USB_DEVICE(0x10C4, 0xF002) }, /* Elan Digital Systems USBwave12 */ + { USB_DEVICE(0x10C4, 0xF003) }, /* Elan Digital Systems USBpulse100 */ + { USB_DEVICE(0x10C4, 0xF004) }, /* Elan Digital Systems USBcount50 */ { USB_DEVICE(0x10C5, 0xEA61) }, /* Silicon Labs MobiData GPRS USB Modem */ { USB_DEVICE(0x13AD, 0x9999) }, /* Baltech card reader */ + { USB_DEVICE(0x166A, 0x0303) }, /* Clipsal 5500PCU C-Bus USB interface */ { USB_DEVICE(0x16D6, 0x0001) }, /* Jablotron serial interface */ { } /* Terminating Entry */ }; -- cgit v1.2.3 From 002e8f2c80c6be76bb312940bc278fc10b2b2487 Mon Sep 17 00:00:00 2001 From: Piotr Roszatycki Date: Wed, 2 Jan 2008 11:16:57 +0100 Subject: USB: add support for 4348:5523 WinChipHead USB->RS 232 adapter add support for: 4348:5523 WinChipHead USB->RS 232 adapter with Prolifec PL 2303 chipset [ mingo@elte.hu: merged it and nursed it upstream ] Cc: stable Signed-off-by: Ingo Molnar Signed-off-by: Greg Kroah-Hartman --- drivers/usb/serial/pl2303.c | 1 + drivers/usb/serial/pl2303.h | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/drivers/usb/serial/pl2303.c b/drivers/usb/serial/pl2303.c index 0da1df9c79bf..fbce1ba333b0 100644 --- a/drivers/usb/serial/pl2303.c +++ b/drivers/usb/serial/pl2303.c @@ -87,6 +87,7 @@ static struct usb_device_id id_table [] = { { USB_DEVICE(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_ID) }, { USB_DEVICE(WS002IN_VENDOR_ID, WS002IN_PRODUCT_ID) }, { USB_DEVICE(COREGA_VENDOR_ID, COREGA_PRODUCT_ID) }, + { USB_DEVICE(HL340_VENDOR_ID, HL340_PRODUCT_ID) }, { } /* Terminating entry */ }; diff --git a/drivers/usb/serial/pl2303.h b/drivers/usb/serial/pl2303.h index d31f5d299989..226997d7cda8 100644 --- a/drivers/usb/serial/pl2303.h +++ b/drivers/usb/serial/pl2303.h @@ -107,3 +107,8 @@ /* Corega CG-USBRS232R Serial Adapter */ #define COREGA_VENDOR_ID 0x07aa #define COREGA_PRODUCT_ID 0x002a + +/* HL HL-340 (ID: 4348:5523) */ +#define HL340_VENDOR_ID 0x4348 +#define HL340_PRODUCT_ID 0x5523 + -- cgit v1.2.3 From 62aad3ab11fb4e7c43447ac655595b9cbba3f431 Mon Sep 17 00:00:00 2001 From: "Jessica L. Blank" Date: Sun, 30 Dec 2007 20:11:35 -0600 Subject: USB: Sierra - Add support for Aircard 881U Adds the appropriate vendor and device IDs for the AirCard 881U to sierra.c. (This device is often rebadged by AT&T as the USBConnect 881). Cc: stable Signed-off-by: Jessica L Blank Signed-off-by: Greg Kroah-Hartman --- drivers/usb/serial/sierra.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/usb/serial/sierra.c b/drivers/usb/serial/sierra.c index c295d0495f96..7aea2de4161e 100644 --- a/drivers/usb/serial/sierra.c +++ b/drivers/usb/serial/sierra.c @@ -117,6 +117,7 @@ static struct usb_device_id id_table [] = { { USB_DEVICE(0x1199, 0x6851) }, /* Sierra Wireless AirCard 881 */ { USB_DEVICE(0x1199, 0x6852) }, /* Sierra Wireless AirCard 880 E */ { USB_DEVICE(0x1199, 0x6853) }, /* Sierra Wireless AirCard 881 E */ + { USB_DEVICE(0x1199, 0x6856) }, /* Sierra Wireless AirCard 881 U */ { USB_DEVICE(0x1199, 0x0112), .driver_info = DEVICE_1_PORT }, /* Sierra Wireless AirCard 580 */ { USB_DEVICE(0x0F3D, 0x0112), .driver_info = DEVICE_1_PORT }, /* Airprime/Sierra PC 5220 */ @@ -155,6 +156,7 @@ static struct usb_device_id id_table_3port [] = { { USB_DEVICE(0x1199, 0x6851) }, /* Sierra Wireless AirCard 881 */ { USB_DEVICE(0x1199, 0x6852) }, /* Sierra Wireless AirCard 880E */ { USB_DEVICE(0x1199, 0x6853) }, /* Sierra Wireless AirCard 881E */ + { USB_DEVICE(0x1199, 0x6856) }, /* Sierra Wireless AirCard 881U */ { } }; -- cgit v1.2.3 From cc311ee7d29d96f0bf15599f4456012d6f5ea23c Mon Sep 17 00:00:00 2001 From: Damien Stuart Date: Sun, 6 Jan 2008 13:51:39 -0500 Subject: USB: Adding YC Cable USB Serial device to pl2303 This simply adds the "YC Cable" as a vendor and its pl2303-based USB<->Serial adapter as a product. This particular adapter is sold by Radio Shack. I've done limited testing on a few different systems with no issues. Cc: stable Signed-off-by: Greg Kroah-Hartman --- drivers/usb/serial/pl2303.c | 1 + drivers/usb/serial/pl2303.h | 3 +++ 2 files changed, 4 insertions(+) diff --git a/drivers/usb/serial/pl2303.c b/drivers/usb/serial/pl2303.c index fbce1ba333b0..3f499fcfd83c 100644 --- a/drivers/usb/serial/pl2303.c +++ b/drivers/usb/serial/pl2303.c @@ -88,6 +88,7 @@ static struct usb_device_id id_table [] = { { USB_DEVICE(WS002IN_VENDOR_ID, WS002IN_PRODUCT_ID) }, { USB_DEVICE(COREGA_VENDOR_ID, COREGA_PRODUCT_ID) }, { USB_DEVICE(HL340_VENDOR_ID, HL340_PRODUCT_ID) }, + { USB_DEVICE(YCCABLE_VENDOR_ID, YCCABLE_PRODUCT_ID) }, { } /* Terminating entry */ }; diff --git a/drivers/usb/serial/pl2303.h b/drivers/usb/serial/pl2303.h index 226997d7cda8..f1f67bd20376 100644 --- a/drivers/usb/serial/pl2303.h +++ b/drivers/usb/serial/pl2303.h @@ -112,3 +112,6 @@ #define HL340_VENDOR_ID 0x4348 #define HL340_PRODUCT_ID 0x5523 +/* Y.C. Cable U.S.A., Inc - USB to RS-232 */ +#define YCCABLE_VENDOR_ID 0x05ad +#define YCCABLE_PRODUCT_ID 0x0fba -- cgit v1.2.3 From 6835b32c38d3a64669f04a3e864f6933c5fdbd73 Mon Sep 17 00:00:00 2001 From: Kevin Lloyd Date: Thu, 10 Jan 2008 11:11:04 -0800 Subject: USB: sierra driver - add devices The following improvements were made: - Added new product support: MC5725, AC 880 U, MP 3G (UMTS & CDMA) Cc: stable Signed-off-by: Kevin Lloyd Signed-off-by: Greg Kroah-Hartman --- drivers/usb/serial/sierra.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/drivers/usb/serial/sierra.c b/drivers/usb/serial/sierra.c index 7aea2de4161e..47bce35fd484 100644 --- a/drivers/usb/serial/sierra.c +++ b/drivers/usb/serial/sierra.c @@ -104,6 +104,7 @@ static struct usb_device_id id_table [] = { { USB_DEVICE(0x1199, 0x0019) }, /* Sierra Wireless AirCard 595 */ { USB_DEVICE(0x1199, 0x0021) }, /* Sierra Wireless AirCard 597E */ { USB_DEVICE(0x1199, 0x0120) }, /* Sierra Wireless USB Dongle 595U */ + { USB_DEVICE(0x1199, 0x0023) }, /* Sierra Wireless AirCard */ { USB_DEVICE(0x1199, 0x6802) }, /* Sierra Wireless MC8755 */ { USB_DEVICE(0x1199, 0x6804) }, /* Sierra Wireless MC8755 */ @@ -117,8 +118,12 @@ static struct usb_device_id id_table [] = { { USB_DEVICE(0x1199, 0x6851) }, /* Sierra Wireless AirCard 881 */ { USB_DEVICE(0x1199, 0x6852) }, /* Sierra Wireless AirCard 880 E */ { USB_DEVICE(0x1199, 0x6853) }, /* Sierra Wireless AirCard 881 E */ + { USB_DEVICE(0x1199, 0x6855) }, /* Sierra Wireless AirCard 880 U */ { USB_DEVICE(0x1199, 0x6856) }, /* Sierra Wireless AirCard 881 U */ + { USB_DEVICE(0x1199, 0x6468) }, /* Sierra Wireless MP3G - EVDO */ + { USB_DEVICE(0x1199, 0x6469) }, /* Sierra Wireless MP3G - UMTS/HSPA */ + { USB_DEVICE(0x1199, 0x0112), .driver_info = DEVICE_1_PORT }, /* Sierra Wireless AirCard 580 */ { USB_DEVICE(0x0F3D, 0x0112), .driver_info = DEVICE_1_PORT }, /* Airprime/Sierra PC 5220 */ @@ -143,6 +148,7 @@ static struct usb_device_id id_table_3port [] = { { USB_DEVICE(0x1199, 0x0019) }, /* Sierra Wireless AirCard 595 */ { USB_DEVICE(0x1199, 0x0021) }, /* Sierra Wireless AirCard 597E */ { USB_DEVICE(0x1199, 0x0120) }, /* Sierra Wireless USB Dongle 595U*/ + { USB_DEVICE(0x1199, 0x0023) }, /* Sierra Wireless AirCard */ { USB_DEVICE(0x1199, 0x6802) }, /* Sierra Wireless MC8755 */ { USB_DEVICE(0x1199, 0x6804) }, /* Sierra Wireless MC8755 */ @@ -156,7 +162,10 @@ static struct usb_device_id id_table_3port [] = { { USB_DEVICE(0x1199, 0x6851) }, /* Sierra Wireless AirCard 881 */ { USB_DEVICE(0x1199, 0x6852) }, /* Sierra Wireless AirCard 880E */ { USB_DEVICE(0x1199, 0x6853) }, /* Sierra Wireless AirCard 881E */ + { USB_DEVICE(0x1199, 0x6855) }, /* Sierra Wireless AirCard 880 U */ { USB_DEVICE(0x1199, 0x6856) }, /* Sierra Wireless AirCard 881U */ + { USB_DEVICE(0x1199, 0x6468) }, /* Sierra Wireless MP3G - EVDO */ + { USB_DEVICE(0x1199, 0x6469) }, /* Sierra Wireless MP3G - UMTS/HSPA */ { } }; -- cgit v1.2.3 From da287623723f97939cdae8db44735228de15f3b5 Mon Sep 17 00:00:00 2001 From: Manish Katiyar Date: Sat, 15 Dec 2007 11:01:14 +0530 Subject: USB : correct comments in usb/core/notify.c This patch corrects the wrong function name mentioned in the comments of usb_unregister_notify function. Signed-off-by: Manish Katiyar Signed-off-by: Greg Kroah-Hartman --- drivers/usb/core/notify.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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); * usb_unregister_notify - unregister a notifier callback * @nb: pointer to the notifier block for the callback events. * - * usb_register_notifier() must have been previously called for this function + * usb_register_notify() must have been previously called for this function * to work properly. */ void usb_unregister_notify(struct notifier_block *nb) -- cgit v1.2.3 From 42f8aa945660b901a3c7f25447aa948bf03f208a Mon Sep 17 00:00:00 2001 From: Peter Stark Date: Tue, 25 Dec 2007 18:32:08 +0100 Subject: USB: ftdi_sio - enabling multiple ELV devices, adding EM1010PC I work with a group of people on a free home automation tool called FHEM. Some of the users own more than one USB-serial device by ELV. The ftdi_sio driver has most of the ELV devices disabled by default and needs to be re-enabled every time you get a new kernel. Additionally a new device (EM 1010 PC - enegry monitor) is missing in the list. Currently our users have to follow the instructions we provide at http://www.koeniglich.de/fhem/linux.html ... However, to some users it is too complicated to compile their own kernel module. We are aware that you can specify one additional device using the vendor/product option of the module. But lot's of users own more than one device. Cc: stable Signed-off-by: Peter Stark Signed-off-by: Greg Kroah-Hartman --- drivers/usb/serial/ftdi_sio.c | 44 +++++++++++++++++++++---------------------- drivers/usb/serial/ftdi_sio.h | 1 + 2 files changed, 22 insertions(+), 23 deletions(-) diff --git a/drivers/usb/serial/ftdi_sio.c b/drivers/usb/serial/ftdi_sio.c index c40e77dccf8e..0ea28b081c80 100644 --- a/drivers/usb/serial/ftdi_sio.c +++ b/drivers/usb/serial/ftdi_sio.c @@ -471,30 +471,28 @@ static struct usb_device_id id_table_combined [] = { { USB_DEVICE(FTDI_VID, FTDI_IBS_PEDO_PID) }, { USB_DEVICE(FTDI_VID, FTDI_IBS_PROD_PID) }, /* - * These will probably use user-space drivers. Uncomment them if - * you need them or use the user-specified vendor/product module - * parameters (see ftdi_sio.h for the numbers). Make a fuss if - * you think the driver should recognize any of them by default. + * Due to many user requests for multiple ELV devices we enable + * them by default. */ - /* { USB_DEVICE(FTDI_VID, FTDI_ELV_CLI7000_PID) }, */ - /* { USB_DEVICE(FTDI_VID, FTDI_ELV_PPS7330_PID) }, */ - /* { USB_DEVICE(FTDI_VID, FTDI_ELV_TFM100_PID) }, */ - /* { USB_DEVICE(FTDI_VID, FTDI_ELV_UDF77_PID) }, */ - /* { USB_DEVICE(FTDI_VID, FTDI_ELV_UIO88_PID) }, */ - /* { USB_DEVICE(FTDI_VID, FTDI_ELV_UAD8_PID) }, */ - /* { USB_DEVICE(FTDI_VID, FTDI_ELV_UDA7_PID) }, */ - /* { USB_DEVICE(FTDI_VID, FTDI_ELV_USI2_PID) }, */ - /* { USB_DEVICE(FTDI_VID, FTDI_ELV_T1100_PID) }, */ - /* { USB_DEVICE(FTDI_VID, FTDI_ELV_PCD200_PID) }, */ - /* { USB_DEVICE(FTDI_VID, FTDI_ELV_ULA200_PID) }, */ - /* { USB_DEVICE(FTDI_VID, FTDI_ELV_CSI8_PID) }, */ - /* { USB_DEVICE(FTDI_VID, FTDI_ELV_EM1000DL_PID) }, */ - /* { USB_DEVICE(FTDI_VID, FTDI_ELV_PCK100_PID) }, */ - /* { USB_DEVICE(FTDI_VID, FTDI_ELV_RFP500_PID) }, */ - /* { USB_DEVICE(FTDI_VID, FTDI_ELV_FS20SIG_PID) }, */ - /* { USB_DEVICE(FTDI_VID, FTDI_ELV_WS300PC_PID) }, */ - /* { USB_DEVICE(FTDI_VID, FTDI_ELV_FHZ1300PC_PID) }, */ - /* { USB_DEVICE(FTDI_VID, FTDI_ELV_WS500_PID) }, */ + { USB_DEVICE(FTDI_VID, FTDI_ELV_CLI7000_PID) }, + { USB_DEVICE(FTDI_VID, FTDI_ELV_PPS7330_PID) }, + { USB_DEVICE(FTDI_VID, FTDI_ELV_TFM100_PID) }, + { USB_DEVICE(FTDI_VID, FTDI_ELV_UDF77_PID) }, + { USB_DEVICE(FTDI_VID, FTDI_ELV_UIO88_PID) }, + { USB_DEVICE(FTDI_VID, FTDI_ELV_UAD8_PID) }, + { USB_DEVICE(FTDI_VID, FTDI_ELV_UDA7_PID) }, + { USB_DEVICE(FTDI_VID, FTDI_ELV_USI2_PID) }, + { USB_DEVICE(FTDI_VID, FTDI_ELV_T1100_PID) }, + { USB_DEVICE(FTDI_VID, FTDI_ELV_PCD200_PID) }, + { USB_DEVICE(FTDI_VID, FTDI_ELV_ULA200_PID) }, + { USB_DEVICE(FTDI_VID, FTDI_ELV_CSI8_PID) }, + { USB_DEVICE(FTDI_VID, FTDI_ELV_EM1000DL_PID) }, + { USB_DEVICE(FTDI_VID, FTDI_ELV_PCK100_PID) }, + { USB_DEVICE(FTDI_VID, FTDI_ELV_RFP500_PID) }, + { USB_DEVICE(FTDI_VID, FTDI_ELV_FS20SIG_PID) }, + { USB_DEVICE(FTDI_VID, FTDI_ELV_WS300PC_PID) }, + { USB_DEVICE(FTDI_VID, FTDI_ELV_FHZ1300PC_PID) }, + { USB_DEVICE(FTDI_VID, FTDI_ELV_WS500_PID) }, { USB_DEVICE(FTDI_VID, LINX_SDMUSBQSS_PID) }, { USB_DEVICE(FTDI_VID, LINX_MASTERDEVEL2_PID) }, { USB_DEVICE(FTDI_VID, LINX_FUTURE_0_PID) }, diff --git a/drivers/usb/serial/ftdi_sio.h b/drivers/usb/serial/ftdi_sio.h index b51cbb0eaa05..a242bcf27157 100644 --- a/drivers/usb/serial/ftdi_sio.h +++ b/drivers/usb/serial/ftdi_sio.h @@ -245,6 +245,7 @@ #define FTDI_ELV_WS300PC_PID 0xE0F6 /* PC-Wetterstation (WS 300 PC) */ #define FTDI_ELV_FHZ1300PC_PID 0xE0E8 /* FHZ 1300 PC */ #define FTDI_ELV_WS500_PID 0xE0E9 /* PC-Wetterstation (WS 500) */ +#define FTDI_ELV_EM1010PC_PID 0xE0EF /* Engery monitor EM 1010 PC */ /* * Definitions for ID TECH (www.idt-net.com) devices -- cgit v1.2.3 From 34910434a2c5556c3b44f78c1c0347709b59a4da Mon Sep 17 00:00:00 2001 From: Franco Lanza Date: Wed, 26 Dec 2007 03:29:33 +0100 Subject: USB: ftdi-sio: Patch to add vendor/device id for ATK_16IC CCD little patches only to add vendor/device id of ATK_16IC CCD cam for astronomy. From: Franco Lanza Cc: stable Signed-off-by: Greg Kroah-Hartman --- drivers/usb/serial/ftdi_sio.c | 1 + drivers/usb/serial/ftdi_sio.h | 1 + 2 files changed, 2 insertions(+) diff --git a/drivers/usb/serial/ftdi_sio.c b/drivers/usb/serial/ftdi_sio.c index 0ea28b081c80..c06fa4837232 100644 --- a/drivers/usb/serial/ftdi_sio.c +++ b/drivers/usb/serial/ftdi_sio.c @@ -543,6 +543,7 @@ static struct usb_device_id id_table_combined [] = { { USB_DEVICE(FTDI_VID, FTDI_ATIK_ATK16C_PID) }, { USB_DEVICE(FTDI_VID, FTDI_ATIK_ATK16HR_PID) }, { USB_DEVICE(FTDI_VID, FTDI_ATIK_ATK16HRC_PID) }, + { USB_DEVICE(FTDI_VID, FTDI_ATIK_ATK16IC_PID) }, { USB_DEVICE(KOBIL_VID, KOBIL_CONV_B1_PID) }, { USB_DEVICE(KOBIL_VID, KOBIL_CONV_KAAN_PID) }, { USB_DEVICE(POSIFLEX_VID, POSIFLEX_PP7000_PID) }, diff --git a/drivers/usb/serial/ftdi_sio.h b/drivers/usb/serial/ftdi_sio.h index a242bcf27157..abd632cdba9d 100644 --- a/drivers/usb/serial/ftdi_sio.h +++ b/drivers/usb/serial/ftdi_sio.h @@ -279,6 +279,7 @@ #define FTDI_ATIK_ATK16C_PID 0xDF32 /* ATIK ATK-16C Colour Camera */ #define FTDI_ATIK_ATK16HR_PID 0xDF31 /* ATIK ATK-16HR Grayscale Camera */ #define FTDI_ATIK_ATK16HRC_PID 0xDF33 /* ATIK ATK-16HRC Colour Camera */ +#define FTDI_ATIK_ATK16IC_PID 0xDF35 /* ATIK ATK-16IC Grayscale Camera */ /* * Protego product ids -- cgit v1.2.3 From e3e73c90e529fd882a402296581644062be0e46c Mon Sep 17 00:00:00 2001 From: Bruno Redondi Date: Fri, 11 Jan 2008 22:00:59 +0100 Subject: USB: sierra: add support for Onda H600/Zte MF330 datacard to USB Driver for Sierra Wireless Added support for Onda H600/Zte MF330 GPRS/UMTS/HSDPA datacard Cc: stable Signed-off-by: Bruno Redondi Signed-off-by: Greg Kroah-Hartman --- drivers/usb/serial/sierra.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/usb/serial/sierra.c b/drivers/usb/serial/sierra.c index 47bce35fd484..b4d7ac948533 100644 --- a/drivers/usb/serial/sierra.c +++ b/drivers/usb/serial/sierra.c @@ -126,6 +126,7 @@ static struct usb_device_id id_table [] = { { USB_DEVICE(0x1199, 0x0112), .driver_info = DEVICE_1_PORT }, /* Sierra Wireless AirCard 580 */ { USB_DEVICE(0x0F3D, 0x0112), .driver_info = DEVICE_1_PORT }, /* Airprime/Sierra PC 5220 */ + { USB_DEVICE(0x05C6, 0x6613), .driver_info = DEVICE_1_PORT }, /* Onda H600/ZTE MF330 */ { USB_DEVICE(0x1199, 0x0FFF), .driver_info = DEVICE_INSTALLER}, { } @@ -135,6 +136,7 @@ MODULE_DEVICE_TABLE(usb, id_table); static struct usb_device_id id_table_1port [] = { { USB_DEVICE(0x1199, 0x0112) }, /* Sierra Wireless AirCard 580 */ { USB_DEVICE(0x0F3D, 0x0112) }, /* AirPrime/Sierra PC 5220 */ + { USB_DEVICE(0x05C6, 0x6613) }, /* Onda H600/ZTE MF330 */ { } }; -- cgit v1.2.3 From 94cb373a75a903a6246d3e671cabd3e7b7084105 Mon Sep 17 00:00:00 2001 From: Daniel Kozák Date: Sat, 12 Jan 2008 11:53:09 +0100 Subject: USB: remove duplicate entry in Option driver and Pl2303 driver for Huawei modem MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Remove entry for Huawei E620 UMTS/HSDPA card (ID: 12d1:1001) in pl2303 driver Option driver is use instead Cc: stable Signed-off-by: Daniel Kozák Signed-off-by: Greg Kroah-Hartman --- drivers/usb/serial/pl2303.c | 1 - drivers/usb/serial/pl2303.h | 4 ---- 2 files changed, 5 deletions(-) diff --git a/drivers/usb/serial/pl2303.c b/drivers/usb/serial/pl2303.c index 3f499fcfd83c..1509fba26219 100644 --- a/drivers/usb/serial/pl2303.c +++ b/drivers/usb/serial/pl2303.c @@ -84,7 +84,6 @@ static struct usb_device_id id_table [] = { { USB_DEVICE(DATAPILOT_U2_VENDOR_ID, DATAPILOT_U2_PRODUCT_ID) }, { USB_DEVICE(BELKIN_VENDOR_ID, BELKIN_PRODUCT_ID) }, { USB_DEVICE(ALCOR_VENDOR_ID, ALCOR_PRODUCT_ID) }, - { USB_DEVICE(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_ID) }, { USB_DEVICE(WS002IN_VENDOR_ID, WS002IN_PRODUCT_ID) }, { USB_DEVICE(COREGA_VENDOR_ID, COREGA_PRODUCT_ID) }, { USB_DEVICE(HL340_VENDOR_ID, HL340_PRODUCT_ID) }, diff --git a/drivers/usb/serial/pl2303.h b/drivers/usb/serial/pl2303.h index f1f67bd20376..f061f30ec16f 100644 --- a/drivers/usb/serial/pl2303.h +++ b/drivers/usb/serial/pl2303.h @@ -96,10 +96,6 @@ #define ALCOR_VENDOR_ID 0x058F #define ALCOR_PRODUCT_ID 0x9720 -/* Huawei E620 UMTS/HSDPA card (ID: 12d1:1001) */ -#define HUAWEI_VENDOR_ID 0x12d1 -#define HUAWEI_PRODUCT_ID 0x1001 - /* Willcom WS002IN Data Driver (by NetIndex Inc.) */ #define WS002IN_VENDOR_ID 0x11f6 #define WS002IN_PRODUCT_ID 0x2001 -- cgit v1.2.3 From 57833ea6b95a3995149f1f6d1a8d8862ab7a0ba2 Mon Sep 17 00:00:00 2001 From: Akira Tsukamoto Date: Fri, 18 Jan 2008 18:58:28 +0900 Subject: USB: pl2303: add support for RATOC REX-USB60F pl2303: add support for RATOC REX-USB60F This patch adds support for RATOC REX-USB60F Serial Adapters, which is widely used in Japan recently. Cc: stable Signed-off-by: Akira Tsukamoto Signed-off-by: Greg Kroah-Hartman --- drivers/usb/serial/pl2303.c | 1 + drivers/usb/serial/pl2303.h | 1 + 2 files changed, 2 insertions(+) diff --git a/drivers/usb/serial/pl2303.c b/drivers/usb/serial/pl2303.c index 1509fba26219..b7da8b5c3a86 100644 --- a/drivers/usb/serial/pl2303.c +++ b/drivers/usb/serial/pl2303.c @@ -65,6 +65,7 @@ static struct usb_device_id id_table [] = { { USB_DEVICE(ITEGNO_VENDOR_ID, ITEGNO_PRODUCT_ID_2080) }, { USB_DEVICE(MA620_VENDOR_ID, MA620_PRODUCT_ID) }, { USB_DEVICE(RATOC_VENDOR_ID, RATOC_PRODUCT_ID) }, + { USB_DEVICE(RATOC_VENDOR_ID, RATOC_PRODUCT_ID_USB60F) }, { USB_DEVICE(TRIPP_VENDOR_ID, TRIPP_PRODUCT_ID) }, { USB_DEVICE(RADIOSHACK_VENDOR_ID, RADIOSHACK_PRODUCT_ID) }, { USB_DEVICE(DCU10_VENDOR_ID, DCU10_PRODUCT_ID) }, diff --git a/drivers/usb/serial/pl2303.h b/drivers/usb/serial/pl2303.h index f061f30ec16f..237a41f6638a 100644 --- a/drivers/usb/serial/pl2303.h +++ b/drivers/usb/serial/pl2303.h @@ -35,6 +35,7 @@ #define RATOC_VENDOR_ID 0x0584 #define RATOC_PRODUCT_ID 0xb000 +#define RATOC_PRODUCT_ID_USB60F 0xb020 #define TRIPP_VENDOR_ID 0x2478 #define TRIPP_PRODUCT_ID 0x2008 -- cgit v1.2.3 From 4bb0ef193bae8ca881d14fa713a831c042147041 Mon Sep 17 00:00:00 2001 From: Ed Beroset Date: Thu, 17 Jan 2008 17:37:46 -0500 Subject: USB: ftdi driver - add support for optical probe device Added support for the Elster Unicom III Optical Probe. The device ID has already been added to the usb.ids file. Cc: stable Signed-off-by: Ed Beroset Signed-off-by: Greg Kroah-Hartman --- drivers/usb/serial/ftdi_sio.c | 1 + drivers/usb/serial/ftdi_sio.h | 2 ++ 2 files changed, 3 insertions(+) diff --git a/drivers/usb/serial/ftdi_sio.c b/drivers/usb/serial/ftdi_sio.c index c06fa4837232..1382af97db72 100644 --- a/drivers/usb/serial/ftdi_sio.c +++ b/drivers/usb/serial/ftdi_sio.c @@ -568,6 +568,7 @@ static struct usb_device_id id_table_combined [] = { { USB_DEVICE(TELLDUS_VID, TELLDUS_TELLSTICK_PID) }, { USB_DEVICE(FTDI_VID, FTDI_MAXSTREAM_PID) }, { USB_DEVICE(TML_VID, TML_USB_SERIAL_PID) }, + { USB_DEVICE(FTDI_VID, FTDI_ELSTER_UNICOM_PID) }, { USB_DEVICE(OLIMEX_VID, OLIMEX_ARM_USB_OCD_PID), .driver_info = (kernel_ulong_t)&ftdi_olimex_quirk }, { }, /* Optional parameter entry */ diff --git a/drivers/usb/serial/ftdi_sio.h b/drivers/usb/serial/ftdi_sio.h index abd632cdba9d..f6053daf02fb 100644 --- a/drivers/usb/serial/ftdi_sio.h +++ b/drivers/usb/serial/ftdi_sio.h @@ -536,6 +536,8 @@ #define OLIMEX_VID 0x15BA #define OLIMEX_ARM_USB_OCD_PID 0x0003 +/* www.elsterelectricity.com Elster Unicom III Optical Probe */ +#define FTDI_ELSTER_UNICOM_PID 0xE700 /* Product Id */ /* * The Mobility Lab (TML) -- cgit v1.2.3 From 0cc1a51ff32cd54881a7e4d92ed89cee49843265 Mon Sep 17 00:00:00 2001 From: Oliver Neukum Date: Thu, 10 Jan 2008 10:31:48 +0100 Subject: USB: use GFP_NOIO in reset path this function will run in the context of the scsi error handler thread. It must use GFP_NOIO instead of GFP_KERNEL to avoid a possible deadlock. Cc: stable Signed-off-by: Oliver Neukum Signed-off-by: Greg Kroah-Hartman --- drivers/usb/core/hub.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c index b04d232d4c65..1b17f636f49c 100644 --- a/drivers/usb/core/hub.c +++ b/drivers/usb/core/hub.c @@ -2946,7 +2946,7 @@ static int config_descriptors_changed(struct usb_device *udev) if (len < le16_to_cpu(udev->config[index].desc.wTotalLength)) len = le16_to_cpu(udev->config[index].desc.wTotalLength); } - buf = kmalloc (len, GFP_KERNEL); + buf = kmalloc(len, GFP_NOIO); if (buf == NULL) { dev_err(&udev->dev, "no mem to re-read configs after reset\n"); /* assume the worst */ -- cgit v1.2.3 From ab91d346c82e794e9dce29cf4fda067b4961ca64 Mon Sep 17 00:00:00 2001 From: Nate Carlson Date: Thu, 24 Jan 2008 12:45:07 -0600 Subject: USB: Variant of the Dell Wireless 5520 driver I've got a Dell wireless 5520 card with a different USB ID - specifically, 8136 instead of 8137. Attached a small patch to add support, and the output of an 'ati3'. If we could get this in, that'd be sweet. ;) Thanks! nc@knight:~/tmp/linux-2.6.24-rc8/drivers/usb/serial$ lsusb | grep 8136 Bus 001 Device 005: ID 413c:8136 Dell Computer Corp. nc@knight:~/tmp/linux-source-2.6.23/drivers/usb/serial$ cu -l ttyUSB0 -s 115200 Connected. ati3 Manufacturer: Novatel Wireless Incorporated Model: Expedite EU860D MiniCard Revision: 10.10.04.01-01 [2007-04-11 14:07:19] IMEI: 011186000228043 +GCAP: +CGSM,+DS,+ES From: Nate Carlson Cc: stable Signed-off-by: Greg Kroah-Hartman --- drivers/usb/serial/option.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/usb/serial/option.c b/drivers/usb/serial/option.c index d1185f53447b..bbbe1b962008 100644 --- a/drivers/usb/serial/option.c +++ b/drivers/usb/serial/option.c @@ -180,6 +180,7 @@ static struct usb_device_id option_ids[] = { { USB_DEVICE(DELL_VENDOR_ID, 0x8117) }, /* Dell Wireless 5700 Mobile Broadband CDMA/EVDO ExpressCard == Novatel Merlin XV620 CDMA/EV-DO */ { USB_DEVICE(DELL_VENDOR_ID, 0x8118) }, /* Dell Wireless 5510 Mobile Broadband HSDPA ExpressCard == Novatel Merlin XU870 HSDPA/3G */ { USB_DEVICE(DELL_VENDOR_ID, 0x8128) }, /* Dell Wireless 5700 Mobile Broadband CDMA/EVDO Mini-Card == Novatel Expedite E720 CDMA/EV-DO */ + { USB_DEVICE(DELL_VENDOR_ID, 0x8136) }, /* Dell Wireless HSDPA 5520 == Novatel Expedite EU860D */ { USB_DEVICE(DELL_VENDOR_ID, 0x8137) }, /* Dell Wireless HSDPA 5520 */ { USB_DEVICE(ANYDATA_VENDOR_ID, ANYDATA_PRODUCT_ADU_E100A) }, { USB_DEVICE(ANYDATA_VENDOR_ID, ANYDATA_PRODUCT_ADU_500A) }, -- cgit v1.2.3 From 4b24f91c24e27ec7746549d1180b9cbd18f06000 Mon Sep 17 00:00:00 2001 From: Grant Grundler Date: Wed, 23 Jan 2008 21:31:03 -0800 Subject: USB: storage: Add unusual_dev for HP r707 Add "FIX_CAPACITY" entry for HP Photosmart r707 Camera in "Disk" mode. Camera will wedge when /lib/udev/vol_id attempts to access the last sector, EIO gets reported to dmesg, and block device is marked "offline" (it is). Reproduced vol_id behavior with: "dd if=/dev/sda of=/dev/null skip=60800 count=1" Cc: stable Signed-off-by: Grant Grundler Signed-off-by: Phil Dibowitz Signed-off-by: Greg Kroah-Hartman --- drivers/usb/storage/unusual_devs.h | 8 ++++++++ 1 file changed, 8 insertions(+) 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, US_SC_8070, US_PR_USBAT, init_usbat_cd, 0), #endif +/* Reported by Grant Grundler + * HP r707 camera in "Disk" mode with 2.00.23 or 2.00.24 firmware. + */ +UNUSUAL_DEV( 0x03f0, 0x4002, 0x0001, 0x0001, + "HP", + "PhotoSmart R707", + US_SC_DEVICE, US_PR_DEVICE, NULL, US_FL_FIX_CAPACITY), + /* Reported by Sebastian Kapfer * and Olaf Hering (different bcd's, same vendor/product) * for USB floppies that need the SINGLE_LUN enforcement. -- cgit v1.2.3 From 6ce4560a39f72e45a273c652ee116f8b0fc6386f Mon Sep 17 00:00:00 2001 From: Jan Andersson Date: Tue, 8 Jan 2008 16:39:49 +0100 Subject: usb: fix usbtest halt check on big endian systems usbtest did not swap the received status information when checking for a non-zero value and failed to discover halted endpoints on big endian systems. Cc: stable Signed-off-by: Jan Andersson Acked-by: David Brownell Signed-off-by: Greg Kroah-Hartman --- drivers/usb/misc/usbtest.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/usb/misc/usbtest.c b/drivers/usb/misc/usbtest.c index ea3162146481..81755d06a419 100644 --- a/drivers/usb/misc/usbtest.c +++ b/drivers/usb/misc/usbtest.c @@ -1151,6 +1151,7 @@ static int verify_halted (int ep, struct urb *urb) dbg ("ep %02x couldn't get halt status, %d", ep, retval); return retval; } + le16_to_cpus(&status); if (status != 1) { dbg ("ep %02x bogus status: %04x != 1", ep, status); return -EINVAL; -- cgit v1.2.3 From de6f92b9ee00e9f841fb1a63d0bd60593ec55dbe Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Mon, 28 Jan 2008 09:50:12 -0800 Subject: USB: handle idVendor of 0x0000 Some crazy devices in the wild have a vendor id of 0x0000. If we try to add a module alias with this id, we just can't do it due to a check in the file2alias.c file. Change the test to verify that both the vendor and product ids are 0x0000 to show a real "blank" module alias. Note, the module-init-tools package also needs to be changed to properly generate the depmod tables. Cc: Janusz Cc: stable Cc: Jon Masters Signed-off-by: Greg Kroah-Hartman --- drivers/usb/core/driver.c | 4 ++-- scripts/mod/file2alias.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/usb/core/driver.c b/drivers/usb/core/driver.c index 7c3aaa9c5402..96d3f852f4ad 100644 --- a/drivers/usb/core/driver.c +++ b/drivers/usb/core/driver.c @@ -534,8 +534,8 @@ const struct usb_device_id *usb_match_id(struct usb_interface *interface, id->driver_info is the way to create an entry that indicates that the driver want to examine every device and interface. */ - for (; id->idVendor || id->bDeviceClass || id->bInterfaceClass || - id->driver_info; id++) { + for (; id->idVendor || id->idProduct || id->bDeviceClass || + id->bInterfaceClass || id->driver_info; id++) { if (usb_match_one_id(interface, id)) return id; } diff --git a/scripts/mod/file2alias.c b/scripts/mod/file2alias.c index d802b5afae89..9ddf944cce29 100644 --- a/scripts/mod/file2alias.c +++ b/scripts/mod/file2alias.c @@ -155,7 +155,7 @@ static void do_usb_entry_multi(struct usb_device_id *id, struct module *mod) * Some modules (visor) have empty slots as placeholder for * run-time specification that results in catch-all alias */ - if (!(id->idVendor | id->bDeviceClass | id->bInterfaceClass)) + if (!(id->idVendor | id->idProduct | id->bDeviceClass | id->bInterfaceClass)) return; /* Convert numeric bcdDevice range into fnmatch-able pattern(s) */ -- cgit v1.2.3 From 5a3201b2809a9f7bcda8413c445483f5b5e490a3 Mon Sep 17 00:00:00 2001 From: Tony Jones Date: Tue, 11 Sep 2007 14:07:31 -0700 Subject: USB: Convert from class_device to device for USB core Convert from class_device to device for drivers/usb/core. Signed-off-by: Tony Jones Cc: Kay Sievers Signed-off-by: Greg Kroah-Hartman --- drivers/usb/core/hcd.c | 14 +++++++------- drivers/usb/host/ehci-dbg.c | 34 +++++++++++++++++----------------- drivers/usb/host/ehci-hub.c | 23 +++++++++++++---------- drivers/usb/host/ohci-dbg.c | 34 +++++++++++++++++----------------- include/linux/usb.h | 2 +- 5 files changed, 55 insertions(+), 52 deletions(-) diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c index d5ed3fa9e304..372372116bb0 100644 --- a/drivers/usb/core/hcd.c +++ b/drivers/usb/core/hcd.c @@ -807,13 +807,13 @@ static int usb_register_bus(struct usb_bus *bus) } set_bit (busnum, busmap.busmap); bus->busnum = busnum; - bus->class_dev = class_device_create(usb_host_class, NULL, MKDEV(0,0), - bus->controller, "usb_host%d", - busnum); - result = PTR_ERR(bus->class_dev); - if (IS_ERR(bus->class_dev)) + + bus->dev = device_create(usb_host_class, bus->controller, MKDEV(0, 0), + "usb_host%d", busnum); + result = PTR_ERR(bus->dev); + if (IS_ERR(bus->dev)) goto error_create_class_dev; - class_set_devdata(bus->class_dev, bus); + dev_set_drvdata(bus->dev, bus); /* Add it to the local list of buses */ list_add (&bus->bus_list, &usb_bus_list); @@ -857,7 +857,7 @@ static void usb_deregister_bus (struct usb_bus *bus) clear_bit (bus->busnum, busmap.busmap); - class_device_unregister(bus->class_dev); + device_unregister(bus->dev); } /** diff --git a/drivers/usb/host/ehci-dbg.c b/drivers/usb/host/ehci-dbg.c index c9cc4413198e..754a146cf828 100644 --- a/drivers/usb/host/ehci-dbg.c +++ b/drivers/usb/host/ehci-dbg.c @@ -442,7 +442,7 @@ done: } static ssize_t -show_async (struct class_device *class_dev, char *buf) +show_async(struct device *dev, struct device_attribute *attr, char *buf) { struct usb_bus *bus; struct usb_hcd *hcd; @@ -454,7 +454,7 @@ show_async (struct class_device *class_dev, char *buf) *buf = 0; - bus = class_get_devdata(class_dev); + bus = dev_get_drvdata(dev); hcd = bus_to_hcd(bus); ehci = hcd_to_ehci (hcd); next = buf; @@ -479,12 +479,12 @@ show_async (struct class_device *class_dev, char *buf) return strlen (buf); } -static CLASS_DEVICE_ATTR (async, S_IRUGO, show_async, NULL); +static DEVICE_ATTR(async, S_IRUGO, show_async, NULL); #define DBG_SCHED_LIMIT 64 static ssize_t -show_periodic (struct class_device *class_dev, char *buf) +show_periodic(struct device *dev, struct device_attribute *attr, char *buf) { struct usb_bus *bus; struct usb_hcd *hcd; @@ -500,7 +500,7 @@ show_periodic (struct class_device *class_dev, char *buf) return 0; seen_count = 0; - bus = class_get_devdata(class_dev); + bus = dev_get_drvdata(dev); hcd = bus_to_hcd(bus); ehci = hcd_to_ehci (hcd); next = buf; @@ -623,12 +623,12 @@ show_periodic (struct class_device *class_dev, char *buf) return PAGE_SIZE - size; } -static CLASS_DEVICE_ATTR (periodic, S_IRUGO, show_periodic, NULL); +static DEVICE_ATTR(periodic, S_IRUGO, show_periodic, NULL); #undef DBG_SCHED_LIMIT static ssize_t -show_registers (struct class_device *class_dev, char *buf) +show_registers(struct device *dev, struct device_attribute *attr, char *buf) { struct usb_bus *bus; struct usb_hcd *hcd; @@ -639,7 +639,7 @@ show_registers (struct class_device *class_dev, char *buf) static char fmt [] = "%*s\n"; static char label [] = ""; - bus = class_get_devdata(class_dev); + bus = dev_get_drvdata(dev); hcd = bus_to_hcd(bus); ehci = hcd_to_ehci (hcd); next = buf; @@ -789,25 +789,25 @@ done: return PAGE_SIZE - size; } -static CLASS_DEVICE_ATTR (registers, S_IRUGO, show_registers, NULL); +static DEVICE_ATTR(registers, S_IRUGO, show_registers, NULL); static inline void create_debug_files (struct ehci_hcd *ehci) { - struct class_device *cldev = ehci_to_hcd(ehci)->self.class_dev; + struct device *dev = ehci_to_hcd(ehci)->self.dev; int retval; - retval = class_device_create_file(cldev, &class_device_attr_async); - retval = class_device_create_file(cldev, &class_device_attr_periodic); - retval = class_device_create_file(cldev, &class_device_attr_registers); + retval = device_create_file(dev, &dev_attr_async); + retval = device_create_file(dev, &dev_attr_periodic); + retval = device_create_file(dev, &dev_attr_registers); } static inline void remove_debug_files (struct ehci_hcd *ehci) { - struct class_device *cldev = ehci_to_hcd(ehci)->self.class_dev; + struct device *dev = ehci_to_hcd(ehci)->self.dev; - class_device_remove_file(cldev, &class_device_attr_async); - class_device_remove_file(cldev, &class_device_attr_periodic); - class_device_remove_file(cldev, &class_device_attr_registers); + device_remove_file(dev, &dev_attr_async); + device_remove_file(dev, &dev_attr_periodic); + device_remove_file(dev, &dev_attr_registers); } #endif /* STUB_DEBUG_FILES */ diff --git a/drivers/usb/host/ehci-hub.c b/drivers/usb/host/ehci-hub.c index 735db4aec831..1ad7a6572826 100644 --- a/drivers/usb/host/ehci-hub.c +++ b/drivers/usb/host/ehci-hub.c @@ -291,14 +291,16 @@ static int ehci_bus_resume (struct usb_hcd *hcd) /*-------------------------------------------------------------------------*/ /* Display the ports dedicated to the companion controller */ -static ssize_t show_companion(struct class_device *class_dev, char *buf) +static ssize_t show_companion(struct device *dev, + struct device_attribute *attr, + char *buf) { struct ehci_hcd *ehci; int nports, index, n; int count = PAGE_SIZE; char *ptr = buf; - ehci = hcd_to_ehci(bus_to_hcd(class_get_devdata(class_dev))); + ehci = hcd_to_ehci(bus_to_hcd(dev_get_drvdata(dev))); nports = HCS_N_PORTS(ehci->hcs_params); for (index = 0; index < nports; ++index) { @@ -316,15 +318,16 @@ static ssize_t show_companion(struct class_device *class_dev, char *buf) * Syntax is "[-]portnum", where a leading '-' sign means * return control of the port to the EHCI controller. */ -static ssize_t store_companion(struct class_device *class_dev, - const char *buf, size_t count) +static ssize_t store_companion(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t count) { struct ehci_hcd *ehci; int portnum, new_owner, try; u32 __iomem *status_reg; u32 port_status; - ehci = hcd_to_ehci(bus_to_hcd(class_get_devdata(class_dev))); + ehci = hcd_to_ehci(bus_to_hcd(dev_get_drvdata(dev))); new_owner = PORT_OWNER; /* Owned by companion */ if (sscanf(buf, "%d", &portnum) != 1) return -EINVAL; @@ -364,7 +367,7 @@ static ssize_t store_companion(struct class_device *class_dev, } return count; } -static CLASS_DEVICE_ATTR(companion, 0644, show_companion, store_companion); +static DEVICE_ATTR(companion, 0644, show_companion, store_companion); static inline void create_companion_file(struct ehci_hcd *ehci) { @@ -372,16 +375,16 @@ static inline void create_companion_file(struct ehci_hcd *ehci) /* with integrated TT there is no companion! */ if (!ehci_is_TDI(ehci)) - i = class_device_create_file(ehci_to_hcd(ehci)->self.class_dev, - &class_device_attr_companion); + i = device_create_file(ehci_to_hcd(ehci)->self.dev, + &dev_attr_companion); } static inline void remove_companion_file(struct ehci_hcd *ehci) { /* with integrated TT there is no companion! */ if (!ehci_is_TDI(ehci)) - class_device_remove_file(ehci_to_hcd(ehci)->self.class_dev, - &class_device_attr_companion); + device_remove_file(ehci_to_hcd(ehci)->self.dev, + &dev_attr_companion); } diff --git a/drivers/usb/host/ohci-dbg.c b/drivers/usb/host/ohci-dbg.c index ebab5ce8f5ce..9bd589806245 100644 --- a/drivers/usb/host/ohci-dbg.c +++ b/drivers/usb/host/ohci-dbg.c @@ -468,7 +468,7 @@ show_list (struct ohci_hcd *ohci, char *buf, size_t count, struct ed *ed) } static ssize_t -show_async (struct class_device *class_dev, char *buf) +show_async(struct device *dev, struct device_attribute *attr, char *buf) { struct usb_bus *bus; struct usb_hcd *hcd; @@ -476,7 +476,7 @@ show_async (struct class_device *class_dev, char *buf) size_t temp; unsigned long flags; - bus = class_get_devdata(class_dev); + bus = dev_get_drvdata(dev); hcd = bus_to_hcd(bus); ohci = hcd_to_ohci(hcd); @@ -488,13 +488,13 @@ show_async (struct class_device *class_dev, char *buf) return temp; } -static CLASS_DEVICE_ATTR (async, S_IRUGO, show_async, NULL); +static DEVICE_ATTR(async, S_IRUGO, show_async, NULL); #define DBG_SCHED_LIMIT 64 static ssize_t -show_periodic (struct class_device *class_dev, char *buf) +show_periodic(struct device *dev, struct device_attribute *attr, char *buf) { struct usb_bus *bus; struct usb_hcd *hcd; @@ -509,7 +509,7 @@ show_periodic (struct class_device *class_dev, char *buf) return 0; seen_count = 0; - bus = class_get_devdata(class_dev); + bus = dev_get_drvdata(dev); hcd = bus_to_hcd(bus); ohci = hcd_to_ohci(hcd); next = buf; @@ -589,13 +589,13 @@ show_periodic (struct class_device *class_dev, char *buf) return PAGE_SIZE - size; } -static CLASS_DEVICE_ATTR (periodic, S_IRUGO, show_periodic, NULL); +static DEVICE_ATTR(periodic, S_IRUGO, show_periodic, NULL); #undef DBG_SCHED_LIMIT static ssize_t -show_registers (struct class_device *class_dev, char *buf) +show_registers(struct device *dev, struct device_attribute *attr, char *buf) { struct usb_bus *bus; struct usb_hcd *hcd; @@ -606,7 +606,7 @@ show_registers (struct class_device *class_dev, char *buf) char *next; u32 rdata; - bus = class_get_devdata(class_dev); + bus = dev_get_drvdata(dev); hcd = bus_to_hcd(bus); ohci = hcd_to_ohci(hcd); regs = ohci->regs; @@ -679,27 +679,27 @@ done: spin_unlock_irqrestore (&ohci->lock, flags); return PAGE_SIZE - size; } -static CLASS_DEVICE_ATTR (registers, S_IRUGO, show_registers, NULL); +static DEVICE_ATTR(registers, S_IRUGO, show_registers, NULL); static inline void create_debug_files (struct ohci_hcd *ohci) { - struct class_device *cldev = ohci_to_hcd(ohci)->self.class_dev; + struct device *dev = ohci_to_hcd(ohci)->self.dev; int retval; - retval = class_device_create_file(cldev, &class_device_attr_async); - retval = class_device_create_file(cldev, &class_device_attr_periodic); - retval = class_device_create_file(cldev, &class_device_attr_registers); + retval = device_create_file(dev, &dev_attr_async); + retval = device_create_file(dev, &dev_attr_periodic); + retval = device_create_file(dev, &dev_attr_registers); ohci_dbg (ohci, "created debug files\n"); } static inline void remove_debug_files (struct ohci_hcd *ohci) { - struct class_device *cldev = ohci_to_hcd(ohci)->self.class_dev; + struct device *dev = ohci_to_hcd(ohci)->self.dev; - class_device_remove_file(cldev, &class_device_attr_async); - class_device_remove_file(cldev, &class_device_attr_periodic); - class_device_remove_file(cldev, &class_device_attr_registers); + device_remove_file(dev, &dev_attr_async); + device_remove_file(dev, &dev_attr_periodic); + device_remove_file(dev, &dev_attr_registers); } #endif diff --git a/include/linux/usb.h b/include/linux/usb.h index 5fc8ff73b7bb..8aae045e9a2e 100644 --- a/include/linux/usb.h +++ b/include/linux/usb.h @@ -318,7 +318,7 @@ struct usb_bus { #ifdef CONFIG_USB_DEVICEFS struct dentry *usbfs_dentry; /* usbfs dentry entry for the bus */ #endif - struct class_device *class_dev; /* class device for this bus */ + struct device *dev; /* device for this bus */ #if defined(CONFIG_USB_MON) struct mon_bus *mon_bus; /* non-null when associated */ -- cgit v1.2.3 From eedffd12e07d8fd150618d603d010b491dc90354 Mon Sep 17 00:00:00 2001 From: Pete Zaitcev Date: Tue, 23 Oct 2007 18:57:25 -0700 Subject: USB: Remove unnecessary zeroing from ub These zeroings were taken from usb-storage long time ago. I examined the submission paths and usb_fill_bulk_urb and found them unnecessary. Signed-off-by: Pete Zaitcev Signed-off-by: Greg Kroah-Hartman --- drivers/block/ub.c | 23 ----------------------- 1 file changed, 23 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) usb_fill_bulk_urb(&sc->work_urb, sc->dev, sc->send_bulk_pipe, bcb, US_BULK_CB_WRAP_LEN, ub_urb_complete, sc); - /* Fill what we shouldn't be filling, because usb-storage did so. */ - sc->work_urb.actual_length = 0; - sc->work_urb.error_count = 0; - sc->work_urb.status = 0; - if ((rc = usb_submit_urb(&sc->work_urb, GFP_ATOMIC)) != 0) { /* XXX Clear stalls */ ub_complete(&sc->work_done); @@ -1313,9 +1308,6 @@ static void ub_data_start(struct ub_dev *sc, struct ub_scsi_cmd *cmd) sc->last_pipe = pipe; usb_fill_bulk_urb(&sc->work_urb, sc->dev, pipe, sg_virt(sg), sg->length, ub_urb_complete, sc); - sc->work_urb.actual_length = 0; - sc->work_urb.error_count = 0; - sc->work_urb.status = 0; if ((rc = usb_submit_urb(&sc->work_urb, GFP_ATOMIC)) != 0) { /* XXX Clear stalls */ @@ -1356,9 +1348,6 @@ static int __ub_state_stat(struct ub_dev *sc, struct ub_scsi_cmd *cmd) sc->last_pipe = sc->recv_bulk_pipe; usb_fill_bulk_urb(&sc->work_urb, sc->dev, sc->recv_bulk_pipe, &sc->work_bcs, US_BULK_CS_WRAP_LEN, ub_urb_complete, sc); - sc->work_urb.actual_length = 0; - sc->work_urb.error_count = 0; - sc->work_urb.status = 0; if ((rc = usb_submit_urb(&sc->work_urb, GFP_ATOMIC)) != 0) { /* XXX Clear stalls */ @@ -1473,9 +1462,6 @@ static int ub_submit_clear_stall(struct ub_dev *sc, struct ub_scsi_cmd *cmd, usb_fill_control_urb(&sc->work_urb, sc->dev, sc->send_ctrl_pipe, (unsigned char*) cr, NULL, 0, ub_urb_complete, sc); - sc->work_urb.actual_length = 0; - sc->work_urb.error_count = 0; - sc->work_urb.status = 0; if ((rc = usb_submit_urb(&sc->work_urb, GFP_ATOMIC)) != 0) { ub_complete(&sc->work_done); @@ -1953,9 +1939,6 @@ static int ub_sync_reset(struct ub_dev *sc) usb_fill_control_urb(&sc->work_urb, sc->dev, sc->send_ctrl_pipe, (unsigned char*) cr, NULL, 0, ub_probe_urb_complete, &compl); - sc->work_urb.actual_length = 0; - sc->work_urb.error_count = 0; - sc->work_urb.status = 0; if ((rc = usb_submit_urb(&sc->work_urb, GFP_KERNEL)) != 0) { printk(KERN_WARNING @@ -2007,9 +1990,6 @@ static int ub_sync_getmaxlun(struct ub_dev *sc) usb_fill_control_urb(&sc->work_urb, sc->dev, sc->recv_ctrl_pipe, (unsigned char*) cr, p, 1, ub_probe_urb_complete, &compl); - sc->work_urb.actual_length = 0; - sc->work_urb.error_count = 0; - sc->work_urb.status = 0; if ((rc = usb_submit_urb(&sc->work_urb, GFP_KERNEL)) != 0) goto err_submit; @@ -2077,9 +2057,6 @@ static int ub_probe_clear_stall(struct ub_dev *sc, int stalled_pipe) usb_fill_control_urb(&sc->work_urb, sc->dev, sc->send_ctrl_pipe, (unsigned char*) cr, NULL, 0, ub_probe_urb_complete, &compl); - sc->work_urb.actual_length = 0; - sc->work_urb.error_count = 0; - sc->work_urb.status = 0; if ((rc = usb_submit_urb(&sc->work_urb, GFP_KERNEL)) != 0) { printk(KERN_WARNING -- cgit v1.2.3 From 1365baf7249bb2d05e774e7681237b8e86f5007a Mon Sep 17 00:00:00 2001 From: Oliver Neukum Date: Fri, 12 Oct 2007 17:24:28 +0200 Subject: USB: autosuspend for cdc-acm Here we go. This patch implements suspend/resume and autosuspend for the CDC ACM driver. Signed-off-by: Oliver Neukum Signed-off-by: Greg Kroah-Hartman --- drivers/usb/class/cdc-acm.c | 92 +++++++++++++++++++++++++++++++++++++-------- drivers/usb/class/cdc-acm.h | 2 + 2 files changed, 79 insertions(+), 15 deletions(-) diff --git a/drivers/usb/class/cdc-acm.c b/drivers/usb/class/cdc-acm.c index 912d97aaf9bf..b0f9873ce6b7 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) otherwise it is scheduled, and with high data rates data can get lost. */ tty->low_latency = 1; + if (usb_autopm_get_interface(acm->control)) { + mutex_unlock(&open_mutex); + return -EIO; + } + + mutex_lock(&acm->mutex); + mutex_unlock(&open_mutex); if (acm->used++) { + usb_autopm_put_interface(acm->control); goto done; } + acm->ctrlurb->dev = acm->dev; if (usb_submit_urb(acm->ctrlurb, GFP_KERNEL)) { dbg("usb_submit_urb(ctrl irq) failed"); @@ -526,14 +535,15 @@ static int acm_tty_open(struct tty_struct *tty, struct file *filp) done: err_out: - mutex_unlock(&open_mutex); + mutex_unlock(&acm->mutex); return rv; full_bailout: usb_kill_urb(acm->ctrlurb); bail_out: + usb_autopm_put_interface(acm->control); acm->used--; - mutex_unlock(&open_mutex); + mutex_unlock(&acm->mutex); return -EIO; } @@ -570,6 +580,7 @@ static void acm_tty_close(struct tty_struct *tty, struct file *filp) usb_kill_urb(acm->writeurb); for (i = 0; i < nr; i++) usb_kill_urb(acm->ru[i].urb); + usb_autopm_put_interface(acm->control); } else acm_tty_unregister(acm); } @@ -980,6 +991,7 @@ skip_normal_probe: spin_lock_init(&acm->throttle_lock); spin_lock_init(&acm->write_lock); spin_lock_init(&acm->read_lock); + mutex_init(&acm->mutex); acm->write_ready = 1; acm->rx_endpoint = usb_rcvbulkpipe(usb_dev, epread->bEndpointAddress); @@ -1096,6 +1108,25 @@ alloc_fail: return -ENOMEM; } +static void stop_data_traffic(struct acm *acm) +{ + int i; + + tasklet_disable(&acm->urb_task); + + usb_kill_urb(acm->ctrlurb); + usb_kill_urb(acm->writeurb); + for (i = 0; i < acm->rx_buflimit; i++) + usb_kill_urb(acm->ru[i].urb); + + INIT_LIST_HEAD(&acm->filled_read_bufs); + INIT_LIST_HEAD(&acm->spare_read_bufs); + + tasklet_enable(&acm->urb_task); + + cancel_work_sync(&acm->work); +} + static void acm_disconnect(struct usb_interface *intf) { struct acm *acm = usb_get_intfdata(intf); @@ -1123,19 +1154,7 @@ static void acm_disconnect(struct usb_interface *intf) usb_set_intfdata(acm->control, NULL); usb_set_intfdata(acm->data, NULL); - tasklet_disable(&acm->urb_task); - - usb_kill_urb(acm->ctrlurb); - usb_kill_urb(acm->writeurb); - for (i = 0; i < acm->rx_buflimit; i++) - usb_kill_urb(acm->ru[i].urb); - - INIT_LIST_HEAD(&acm->filled_read_bufs); - INIT_LIST_HEAD(&acm->spare_read_bufs); - - tasklet_enable(&acm->urb_task); - - flush_scheduled_work(); /* wait for acm_softint */ + stop_data_traffic(acm); acm_write_buffers_free(acm); 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) tty_hangup(acm->tty); } +static int acm_suspend(struct usb_interface *intf, pm_message_t message) +{ + struct acm *acm = usb_get_intfdata(intf); + + if (acm->susp_count++) + return 0; + /* + we treat opened interfaces differently, + we must guard against open + */ + mutex_lock(&acm->mutex); + + if (acm->used) + stop_data_traffic(acm); + + mutex_unlock(&acm->mutex); + return 0; +} + +static int acm_resume(struct usb_interface *intf) +{ + struct acm *acm = usb_get_intfdata(intf); + int rv = 0; + + if (--acm->susp_count) + return 0; + + mutex_lock(&acm->mutex); + if (acm->used) { + rv = usb_submit_urb(acm->ctrlurb, GFP_NOIO); + if (rv < 0) + goto err_out; + + tasklet_schedule(&acm->urb_task); + } + +err_out: + mutex_unlock(&acm->mutex); + return rv; +} /* * USB driver structure. */ @@ -1208,7 +1267,10 @@ static struct usb_driver acm_driver = { .name = "cdc_acm", .probe = acm_probe, .disconnect = acm_disconnect, + .suspend = acm_suspend, + .resume = acm_resume, .id_table = acm_ids, + .supports_autosuspend = 1, }; /* 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 { int write_used; /* number of non-empty write buffers */ int write_ready; /* write urb is not running */ spinlock_t write_lock; + struct mutex mutex; struct usb_cdc_line_coding line; /* bits, stop, parity */ struct work_struct work; /* work queue entry for line discipline waking up */ struct tasklet_struct urb_task; /* rx processing */ @@ -120,6 +121,7 @@ struct acm { unsigned char throttle; /* throttled by tty layer */ unsigned char clocal; /* termios CLOCAL */ unsigned int ctrl_caps; /* control capabilities from the class specific header */ + unsigned int susp_count; /* number of suspended interfaces */ }; #define CDC_DATA_INTERFACE_TYPE 0x0a -- cgit v1.2.3 From c74e809565b27085519c723a949761cea7badb4b Mon Sep 17 00:00:00 2001 From: Bartlomiej Zolnierkiewicz Date: Sat, 27 Oct 2007 18:01:04 +0200 Subject: USB: isd200: don't include Now that commit 3794ade5b286cbd4551009dd341dbe9aeead2bc3 removed incorrect dependency on CONFIG_IDE we can fix the driver to not include : * add ATA_REG_{ERROR,LCYL,HCYL,STATUS}_OFFSET defines and use them instead of IDE_{ERROR,LCYL,HCYL,STATUS}_OFFSET from * remove no longer needed include * remove incorrect comment added by the last commit: - isd200.c is not the only user of struct hd_driveid besides IDE (see drivers/block/xsysace.c and arch/um/drivers/ubd_kern.c) Cc: Alan Cox Signed-off-by: Bartlomiej Zolnierkiewicz Signed-off-by: Greg Kroah-Hartman --- drivers/usb/storage/isd200.c | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) 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 @@ #include #include #include -#include #include #include @@ -110,6 +109,12 @@ #define REG_STATUS 0x80 #define REG_COMMAND 0x80 +/* ATA registers offset definitions */ +#define ATA_REG_ERROR_OFFSET 1 +#define ATA_REG_LCYL_OFFSET 4 +#define ATA_REG_HCYL_OFFSET 5 +#define ATA_REG_STATUS_OFFSET 7 + /* ATA error definitions not in */ #define ATA_ERROR_MEDIA_CHANGE 0x20 @@ -360,7 +365,7 @@ static void isd200_build_sense(struct us_data *us, struct scsi_cmnd *srb) { struct isd200_info *info = (struct isd200_info *)us->extra; struct sense_data *buf = (struct sense_data *) &srb->sense_buffer[0]; - unsigned char error = info->ATARegs[IDE_ERROR_OFFSET]; + unsigned char error = info->ATARegs[ATA_REG_ERROR_OFFSET]; if(error & ATA_ERROR_MEDIA_CHANGE) { buf->ErrorCode = 0x70 | SENSE_ERRCODE_VALID; @@ -549,8 +554,8 @@ static int isd200_read_regs( struct us_data *us ) retStatus = ISD200_ERROR; } else { memcpy(info->ATARegs, info->RegsBuf, sizeof(info->ATARegs)); - US_DEBUGP(" Got ATA Register[IDE_ERROR_OFFSET] = 0x%x\n", - info->ATARegs[IDE_ERROR_OFFSET]); + US_DEBUGP(" Got ATA Register[ATA_REG_ERROR_OFFSET] = 0x%x\n", + info->ATARegs[ATA_REG_ERROR_OFFSET]); } return retStatus; @@ -892,7 +897,7 @@ static int isd200_try_enum(struct us_data *us, unsigned char master_slave, break; if (!detect) { - if (regs[IDE_STATUS_OFFSET] & BUSY_STAT ) { + if (regs[ATA_REG_STATUS_OFFSET] & BUSY_STAT) { US_DEBUGP(" %s status is still BSY, try again...\n",mstr); } else { 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, /* check for BUSY_STAT and */ /* WRERR_STAT (workaround ATA Zip drive) and */ /* ERR_STAT (workaround for Archos CD-ROM) */ - else if (regs[IDE_STATUS_OFFSET] & + else if (regs[ATA_REG_STATUS_OFFSET] & (BUSY_STAT | WRERR_STAT | ERR_STAT )) { US_DEBUGP(" Status indicates it is not ready, try again...\n"); } /* check for DRDY, ATA devices set DRDY after SRST */ - else if (regs[IDE_STATUS_OFFSET] & READY_STAT) { + else if (regs[ATA_REG_STATUS_OFFSET] & READY_STAT) { US_DEBUGP(" Identified ATA device\n"); info->DeviceFlags |= DF_ATA_DEVICE; info->DeviceHead = master_slave; @@ -916,8 +921,8 @@ static int isd200_try_enum(struct us_data *us, unsigned char master_slave, /* check Cylinder High/Low to determine if it is an ATAPI device */ - else if ((regs[IDE_HCYL_OFFSET] == 0xEB) && - (regs[IDE_LCYL_OFFSET] == 0x14)) { + else if (regs[ATA_REG_HCYL_OFFSET] == 0xEB && + regs[ATA_REG_LCYL_OFFSET] == 0x14) { /* It seems that the RICOH MP6200A CD/RW drive will report itself okay as a @@ -1001,12 +1006,6 @@ static int isd200_manual_enum(struct us_data *us) return(retStatus); } -/* - * We are the last non IDE user of the legacy IDE ident structures - * and we thus want to keep a private copy of this function so the - * driver can be used without the obsolete drivers/ide layer - */ - static void isd200_fix_driveid (struct hd_driveid *id) { #ifndef __LITTLE_ENDIAN -- cgit v1.2.3 From 60a8fc017103325db4b56e4f175f060a6aaac147 Mon Sep 17 00:00:00 2001 From: Alain Degreffe Date: Fri, 26 Oct 2007 13:51:49 +0200 Subject: USB: add iuu_phoenix driver Signed-off-by: Alain Degreffe Cc: Alan Cox Cc: Oliver Neukum Signed-off-by: Greg Kroah-Hartman --- Documentation/usb/iuu_phoenix.txt | 84 +++ drivers/usb/serial/Kconfig | 11 + drivers/usb/serial/Makefile | 1 + drivers/usb/serial/iuu_phoenix.c | 1217 +++++++++++++++++++++++++++++++++++++ drivers/usb/serial/iuu_phoenix.h | 122 ++++ 5 files changed, 1435 insertions(+) create mode 100644 Documentation/usb/iuu_phoenix.txt create mode 100644 drivers/usb/serial/iuu_phoenix.c create mode 100644 drivers/usb/serial/iuu_phoenix.h diff --git a/Documentation/usb/iuu_phoenix.txt b/Documentation/usb/iuu_phoenix.txt new file mode 100644 index 000000000000..e5f048067da4 --- /dev/null +++ b/Documentation/usb/iuu_phoenix.txt @@ -0,0 +1,84 @@ +Infinity Usb Unlimited Readme +----------------------------- + +Hi all, + + +This module provide a serial interface to use your +IUU unit in phoenix mode. Loading this module will +bring a ttyUSB[0-x] interface. This driver must be +used by your favorite application to pilot the IUU + +This driver is still in beta stage, so bugs can +occur and your system may freeze. As far I now, +I never had any problem with it, but I'm not a real +guru, so don't blame me if your system is unstable + +You can plug more than one IUU. Every unit will +have his own device file(/dev/ttyUSB0,/dev/ttyUSB1,...) + + + +How to tune the reader speed ? + + A few parameters can be used at load time + To use parameters, just unload the module if it is + already loaded and use modprobe iuu_phoenix param=value. + In case of prebuilt module, use the command + insmod iuu_phoenix param=value. + + Example: + + modprobe iuu_phoenix clockmode=3 + + The parameters are: + + parm: clockmode:1=3Mhz579,2=3Mhz680,3=6Mhz (int) + parm: boost:overclock boost percent 100 to 500 (int) + parm: cdmode:Card detect mode 0=none, 1=CD, 2=!CD, 3=DSR, 4=!DSR, 5=CTS, 6=!CTS, 7=RING, 8=!RING (int) + parm: xmas:xmas color enabled or not (bool) + parm: debug:Debug enabled or not (bool) + +- clockmode will provide 3 different base settings commonly adopted by + different software: + 1. 3Mhz579 + 2. 3Mhz680 + 3. 6Mhz + +- boost provide a way to overclock the reader ( my favorite :-) ) + For example to have best performance than a simple clockmode=3, try this: + + modprobe boost=195 + + This will put the reader in a base of 3Mhz579 but boosted a 195 % ! + the real clock will be now : 6979050 Hz ( 6Mhz979 ) and will increase + the speed to a score 10 to 20% better than the simple clockmode=3 !!! + + +- cdmode permit to setup the signal used to inform the userland ( ioctl answer ) + if the card is present or not. Eight signals are possible. + +- xmas is completely useless except for your eyes. This is one of my friend who was + so sad to have a nice device like the iuu without seeing all color range available. + So I have added this option to permit him to see a lot of color ( each activity change the color + and the frequency randomly ) + +- debug will produce a lot of debugging messages... + + + Last notes: + + Don't worry about the serial settings, the serial emulation + is an abstraction, so use any speed or parity setting will + work. ( This will not change anything ).Later I will perhaps + use this settings to deduce de boost but is that feature + really necessary ? + The autodetect feature used is the serial CD. If that doesn't + work for your software, disable detection mechanism in it. + + + Have fun ! + + Alain Degreffe + + eczema(at)ecze.com diff --git a/drivers/usb/serial/Kconfig b/drivers/usb/serial/Kconfig index 4a86696e6c7d..e2d1d928a1e4 100644 --- a/drivers/usb/serial/Kconfig +++ b/drivers/usb/serial/Kconfig @@ -282,6 +282,17 @@ config USB_SERIAL_IPW To compile this driver as a module, choose M here: the module will be called ipw. +config USB_SERIAL_IUU + tristate "USB Infinity USB Unlimited Phoenix Driver (Experimental)" + depends on USB_SERIAL && EXPERIMENTAL + help + Say Y here if you want to use a IUU in phoenix mode and get + an extra ttyUSBx device. More information available on + http://eczema.ecze.com/iuu_phoenix.html + + To compile this driver as a module, choose M here: the + module will be called iuu_phoenix.o + config USB_SERIAL_KEYSPAN_PDA tristate "USB Keyspan PDA Single Port Serial Driver" depends on USB_SERIAL 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 obj-$(CONFIG_USB_SERIAL_HP4X) += hp4x.o obj-$(CONFIG_USB_SERIAL_IPAQ) += ipaq.o obj-$(CONFIG_USB_SERIAL_IPW) += ipw.o +obj-$(CONFIG_USB_SERIAL_IUU) += iuu_phoenix.o obj-$(CONFIG_USB_SERIAL_IR) += ir-usb.o obj-$(CONFIG_USB_SERIAL_KEYSPAN) += keyspan.o obj-$(CONFIG_USB_SERIAL_KEYSPAN_PDA) += keyspan_pda.o 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 @@ +/* + * Infinity Unlimited USB Phoenix driver + * + * Copyright (C) 2007 Alain Degreffe (eczema@ecze.com) + * + * Original code taken from iuutool (Copyright (C) 2006 Juan Carlos Borrás) + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * And tested with help of WB Electronics + * + */ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "iuu_phoenix.h" +#include + + +#ifdef CONFIG_USB_SERIAL_DEBUG +static int debug = 1; +#else +static int debug; +#endif + +/* + * Version Information + */ +#define DRIVER_VERSION "v0.5" +#define DRIVER_DESC "Infinity USB Unlimited Phoenix driver" + +static struct usb_device_id id_table[] = { + {USB_DEVICE(IUU_USB_VENDOR_ID, IUU_USB_PRODUCT_ID)}, + {} /* Terminating entry */ +}; +MODULE_DEVICE_TABLE(usb, id_table); + +static struct usb_driver iuu_driver = { + .name = "iuu_phoenix", + .probe = usb_serial_probe, + .disconnect = usb_serial_disconnect, + .id_table = id_table, + .no_dynamic_id = 1, +}; + +/* turbo parameter */ +static int boost = 100; +static int clockmode = 1; +static int cdmode = 1; +static int iuu_cardin; +static int iuu_cardout; +static int xmas; + +static void read_rxcmd_callback(struct urb *urb); + +struct iuu_private { + spinlock_t lock; /* store irq state */ + wait_queue_head_t delta_msr_wait; + u8 line_control; + u8 line_status; + u8 termios_initialized; + int tiostatus; /* store IUART SIGNAL for tiocmget call */ + u8 reset; /* if 1 reset is needed */ + int poll; /* number of poll */ + u8 *writebuf; /* buffer for writing to device */ + int writelen; /* num of byte to write to device */ + u8 *buf; /* used for initialize speed */ + u8 *dbgbuf; /* debug buffer */ + u8 len; +}; + + +static void iuu_free_buf(struct iuu_private *priv) +{ + kfree(priv->buf); + kfree(priv->dbgbuf); + kfree(priv->writebuf); +} + +static int iuu_alloc_buf(struct iuu_private *priv) +{ + priv->buf = kzalloc(256, GFP_KERNEL); + priv->dbgbuf = kzalloc(256, GFP_KERNEL); + priv->writebuf = kzalloc(256, GFP_KERNEL); + if (!priv->buf || !priv->dbgbuf || !priv->writebuf) { + iuu_free_buf(priv); + dbg("%s problem allocation buffer", __FUNCTION__); + return -ENOMEM; + } + dbg("%s - Privates buffers allocation success", __FUNCTION__); + return 0; +} + +static int iuu_startup(struct usb_serial *serial) +{ + struct iuu_private *priv; + priv = kzalloc(sizeof(struct iuu_private), GFP_KERNEL); + dbg("%s- priv allocation success", __FUNCTION__); + if (!priv) + return -ENOMEM; + if (iuu_alloc_buf(priv)) { + kfree(priv); + return -ENOMEM; + } + spin_lock_init(&priv->lock); + init_waitqueue_head(&priv->delta_msr_wait); + usb_set_serial_port_data(serial->port[0], priv); + return 0; +} + +/* Shutdown function */ +static void iuu_shutdown(struct usb_serial *serial) +{ + struct usb_serial_port *port = serial->port[0]; + struct iuu_private *priv = usb_get_serial_port_data(port); + if (!port) + return; + + dbg("%s", __FUNCTION__); + + if (priv) { + iuu_free_buf(priv); + dbg("%s - I will free all", __FUNCTION__); + usb_set_serial_port_data(port, NULL); + + dbg("%s - priv is not anymore in port structure", __FUNCTION__); + kfree(priv); + + dbg("%s priv is now kfree", __FUNCTION__); + } +} + +static int iuu_tiocmset(struct usb_serial_port *port, struct file *file, + unsigned int set, unsigned int clear) +{ + struct iuu_private *priv = usb_get_serial_port_data(port); + struct tty_struct *tty; + tty = port->tty; + + dbg("%s (%d) msg : SET = 0x%04x, CLEAR = 0x%04x ", __FUNCTION__, + port->number, set, clear); + if (set & TIOCM_RTS) + priv->tiostatus = TIOCM_RTS; + + if (!(set & TIOCM_RTS) && priv->tiostatus == TIOCM_RTS) { + dbg("%s TIOCMSET RESET called !!!", __FUNCTION__); + priv->reset = 1; + return 0; + } + + return 0; +} + +/* This is used to provide a carrier detect mechanism + * When a card is present, the response is 0x00 + * When no card , the reader respond with TIOCM_CD + * This is known as CD autodetect mechanism + */ +static int iuu_tiocmget(struct usb_serial_port *port, struct file *file) +{ + struct iuu_private *priv = usb_get_serial_port_data(port); + return priv->tiostatus; +} + +static void iuu_rxcmd(struct urb *urb) +{ + struct usb_serial_port *port = (struct usb_serial_port *)urb->context; + int result; + dbg("%s - enter", __FUNCTION__); + + if (urb->status) { + dbg("%s - urb->status = %d", __FUNCTION__, urb->status); + /* error stop all */ + return; + } + + + memset(port->write_urb->transfer_buffer, IUU_UART_RX, 1); + usb_fill_bulk_urb(port->write_urb, port->serial->dev, + usb_sndbulkpipe(port->serial->dev, + port->bulk_out_endpointAddress), + port->write_urb->transfer_buffer, 1, + read_rxcmd_callback, port); + result = usb_submit_urb(port->write_urb, GFP_ATOMIC); +} + +static int iuu_reset(struct usb_serial_port *port, u8 wt) +{ + struct iuu_private *priv = usb_get_serial_port_data(port); + int result; + char *buf_ptr = port->write_urb->transfer_buffer; + dbg("%s - enter", __FUNCTION__); + + /* Prepare the reset sequence */ + + *buf_ptr++ = IUU_RST_SET; + *buf_ptr++ = IUU_DELAY_MS; + *buf_ptr++ = wt; + *buf_ptr = IUU_RST_CLEAR; + + /* send the sequence */ + + usb_fill_bulk_urb(port->write_urb, + port->serial->dev, + usb_sndbulkpipe(port->serial->dev, + port->bulk_out_endpointAddress), + port->write_urb->transfer_buffer, 4, iuu_rxcmd, port); + result = usb_submit_urb(port->write_urb, GFP_ATOMIC); + priv->reset = 0; + return result; +} + +/* Status Function + * Return value is + * 0x00 = no card + * 0x01 = smartcard + * 0x02 = sim card + */ +static void iuu_update_status_callback(struct urb *urb) +{ + struct usb_serial_port *port = (struct usb_serial_port *)urb->context; + struct iuu_private *priv = usb_get_serial_port_data(port); + u8 *st; + dbg("%s - enter", __FUNCTION__); + + if (urb->status) { + dbg("%s - urb->status = %d", __FUNCTION__, urb->status); + /* error stop all */ + return; + } + + st = urb->transfer_buffer; + dbg("%s - enter", __FUNCTION__); + if (urb->actual_length == 1) { + switch (st[0]) { + case 0x1: + priv->tiostatus = iuu_cardout; + break; + case 0x0: + priv->tiostatus = iuu_cardin; + break; + default: + priv->tiostatus = iuu_cardin; + } + } + iuu_rxcmd(urb); +} + +static void iuu_status_callback(struct urb *urb) +{ + struct usb_serial_port *port = (struct usb_serial_port *)urb->context; + int result; + dbg("%s - enter", __FUNCTION__); + + dbg("%s - urb->status = %d", __FUNCTION__, urb->status); + usb_fill_bulk_urb(port->read_urb, port->serial->dev, + usb_rcvbulkpipe(port->serial->dev, + port->bulk_in_endpointAddress), + port->read_urb->transfer_buffer, 256, + iuu_update_status_callback, port); + result = usb_submit_urb(port->read_urb, GFP_ATOMIC); +} + +static int iuu_status(struct usb_serial_port *port) +{ + int result; + + dbg("%s - enter", __FUNCTION__); + + memset(port->write_urb->transfer_buffer, IUU_GET_STATE_REGISTER, 1); + usb_fill_bulk_urb(port->write_urb, port->serial->dev, + usb_sndbulkpipe(port->serial->dev, + port->bulk_out_endpointAddress), + port->write_urb->transfer_buffer, 1, + iuu_status_callback, port); + result = usb_submit_urb(port->write_urb, GFP_ATOMIC); + return result; + +} + +static int bulk_immediate(struct usb_serial_port *port, u8 *buf, u8 count) +{ + int status; + struct usb_serial *serial = port->serial; + int actual = 0; + + dbg("%s - enter", __FUNCTION__); + + /* send the data out the bulk port */ + + status = + usb_bulk_msg(serial->dev, + usb_sndbulkpipe(serial->dev, + port->bulk_out_endpointAddress), buf, + count, &actual, HZ * 1); + + if (status != IUU_OPERATION_OK) { + dbg("%s - error = %2x", __FUNCTION__, status); + } else { + dbg("%s - write OK !", __FUNCTION__); + } + return status; +} + +static int read_immediate(struct usb_serial_port *port, u8 *buf, u8 count) +{ + int status; + struct usb_serial *serial = port->serial; + int actual = 0; + + dbg("%s - enter", __FUNCTION__); + + /* send the data out the bulk port */ + + status = + usb_bulk_msg(serial->dev, + usb_rcvbulkpipe(serial->dev, + port->bulk_in_endpointAddress), buf, + count, &actual, HZ * 1); + + if (status != IUU_OPERATION_OK) { + dbg("%s - error = %2x", __FUNCTION__, status); + } else { + dbg("%s - read OK !", __FUNCTION__); + } + + return status; +} + +static int iuu_led(struct usb_serial_port *port, unsigned int R, + unsigned int G, unsigned int B, u8 f) +{ + int status; + u8 *buf; + buf = kmalloc(8, GFP_KERNEL); + if (!buf) + return -ENOMEM; + + dbg("%s - enter", __FUNCTION__); + + buf[0] = IUU_SET_LED; + buf[1] = R & 0xFF; + buf[2] = (R >> 8) & 0xFF; + buf[3] = G & 0xFF; + buf[4] = (G >> 8) & 0xFF; + buf[5] = B & 0xFF; + buf[6] = (B >> 8) & 0xFF; + buf[7] = f; + status = bulk_immediate(port, buf, 8); + kfree(buf); + if (status != IUU_OPERATION_OK) + dbg("%s - led error status = %2x", __FUNCTION__, status); + else + dbg("%s - led OK !", __FUNCTION__); + return IUU_OPERATION_OK; +} + +static void iuu_rgbf_fill_buffer(u8 *buf, u8 r1, u8 r2, u8 g1, u8 g2, u8 b1, + u8 b2, u8 freq) +{ + *buf++ = IUU_SET_LED; + *buf++ = r1; + *buf++ = r2; + *buf++ = g1; + *buf++ = g2; + *buf++ = b1; + *buf++ = b2; + *buf = freq; +} + +static void iuu_led_activity_on(struct urb *urb) +{ + struct usb_serial_port *port = (struct usb_serial_port *)urb->context; + int result; + char *buf_ptr = port->write_urb->transfer_buffer; + *buf_ptr++ = IUU_SET_LED; + if (xmas == 1) { + get_random_bytes(buf_ptr, 6); + *(buf_ptr+7) = 1; + } else { + iuu_rgbf_fill_buffer(buf_ptr, 255, 255, 0, 0, 0, 0, 255); + } + + usb_fill_bulk_urb(port->write_urb, port->serial->dev, + usb_sndbulkpipe(port->serial->dev, + port->bulk_out_endpointAddress), + port->write_urb->transfer_buffer, 8 , + iuu_rxcmd, port); + result = usb_submit_urb(port->write_urb, GFP_ATOMIC); +} + +static void iuu_led_activity_off(struct urb *urb) +{ + struct usb_serial_port *port = (struct usb_serial_port *)urb->context; + int result; + char *buf_ptr = port->write_urb->transfer_buffer; + if (xmas == 1) { + iuu_rxcmd(urb); + return; + } else { + *buf_ptr++ = IUU_SET_LED; + iuu_rgbf_fill_buffer(buf_ptr, 0, 0, 255, 255, 0, 0, 255); + } + usb_fill_bulk_urb(port->write_urb, port->serial->dev, + usb_sndbulkpipe(port->serial->dev, + port->bulk_out_endpointAddress), + port->write_urb->transfer_buffer, 8 , + iuu_rxcmd, port); + result = usb_submit_urb(port->write_urb, GFP_ATOMIC); +} + + + +static int iuu_clk(struct usb_serial_port *port, int dwFrq) +{ + int status; + struct iuu_private *priv = usb_get_serial_port_data(port); + int Count = 0; + u8 FrqGenAdr = 0x69; + u8 DIV = 0; /* 8bit */ + u8 XDRV = 0; /* 8bit */ + u8 PUMP = 0; /* 3bit */ + u8 PBmsb = 0; /* 2bit */ + u8 PBlsb = 0; /* 8bit */ + u8 PO = 0; /* 1bit */ + u8 Q = 0; /* 7bit */ + /* 24bit = 3bytes */ + unsigned int P = 0; + unsigned int P2 = 0; + int frq = (int)dwFrq; + + dbg("%s - enter", __FUNCTION__); + + if (frq == 0) { + priv->buf[Count++] = IUU_UART_WRITE_I2C; + priv->buf[Count++] = FrqGenAdr << 1; + priv->buf[Count++] = 0x09; + priv->buf[Count++] = 0x00; + + status = bulk_immediate(port, (u8 *) priv->buf, Count); + if (status != 0) { + dbg("%s - write error ", __FUNCTION__); + return status; + } + } else if (frq == 3579000) { + DIV = 100; + P = 1193; + Q = 40; + XDRV = 0; + } else if (frq == 3680000) { + DIV = 105; + P = 161; + Q = 5; + XDRV = 0; + } else if (frq == 6000000) { + DIV = 66; + P = 66; + Q = 2; + XDRV = 0x28; + } else { + unsigned int result = 0; + unsigned int tmp = 0; + unsigned int check; + unsigned int check2; + char found = 0x00; + unsigned int lQ = 2; + unsigned int lP = 2055; + unsigned int lDiv = 4; + + for (lQ = 2; lQ <= 47 && !found; lQ++) + for (lP = 2055; lP >= 8 && !found; lP--) + for (lDiv = 4; lDiv <= 127 && !found; lDiv++) { + tmp = (12000000 / lDiv) * (lP / lQ); + if (abs((int)(tmp - frq)) < + abs((int)(frq - result))) { + check2 = (12000000 / lQ); + if (check2 < 250000) + continue; + check = (12000000 / lQ) * lP; + if (check > 400000000) + continue; + if (check < 100000000) + continue; + if (lDiv < 4 || lDiv > 127) + continue; + result = tmp; + P = lP; + DIV = lDiv; + Q = lQ; + if (result == frq) + found = 0x01; + } + } + } + P2 = ((P - PO) / 2) - 4; + DIV = DIV; + PUMP = 0x04; + PBmsb = (P2 >> 8 & 0x03); + PBlsb = P2 & 0xFF; + PO = (P >> 10) & 0x01; + Q = Q - 2; + + priv->buf[Count++] = IUU_UART_WRITE_I2C; /* 0x4C */ + priv->buf[Count++] = FrqGenAdr << 1; + priv->buf[Count++] = 0x09; + priv->buf[Count++] = 0x20; /* Adr = 0x09 */ + priv->buf[Count++] = IUU_UART_WRITE_I2C; /* 0x4C */ + priv->buf[Count++] = FrqGenAdr << 1; + priv->buf[Count++] = 0x0C; + priv->buf[Count++] = DIV; /* Adr = 0x0C */ + priv->buf[Count++] = IUU_UART_WRITE_I2C; /* 0x4C */ + priv->buf[Count++] = FrqGenAdr << 1; + priv->buf[Count++] = 0x12; + priv->buf[Count++] = XDRV; /* Adr = 0x12 */ + priv->buf[Count++] = IUU_UART_WRITE_I2C; /* 0x4C */ + priv->buf[Count++] = FrqGenAdr << 1; + priv->buf[Count++] = 0x13; + priv->buf[Count++] = 0x6B; /* Adr = 0x13 */ + priv->buf[Count++] = IUU_UART_WRITE_I2C; /* 0x4C */ + priv->buf[Count++] = FrqGenAdr << 1; + priv->buf[Count++] = 0x40; + priv->buf[Count++] = (0xC0 | ((PUMP & 0x07) << 2)) | + (PBmsb & 0x03); /* Adr = 0x40 */ + priv->buf[Count++] = IUU_UART_WRITE_I2C; /* 0x4C */ + priv->buf[Count++] = FrqGenAdr << 1; + priv->buf[Count++] = 0x41; + priv->buf[Count++] = PBlsb; /* Adr = 0x41 */ + priv->buf[Count++] = IUU_UART_WRITE_I2C; /* 0x4C */ + priv->buf[Count++] = FrqGenAdr << 1; + priv->buf[Count++] = 0x42; + priv->buf[Count++] = Q | (((PO & 0x01) << 7)); /* Adr = 0x42 */ + priv->buf[Count++] = IUU_UART_WRITE_I2C; /* 0x4C */ + priv->buf[Count++] = FrqGenAdr << 1; + priv->buf[Count++] = 0x44; + priv->buf[Count++] = (char)0xFF; /* Adr = 0x44 */ + priv->buf[Count++] = IUU_UART_WRITE_I2C; /* 0x4C */ + priv->buf[Count++] = FrqGenAdr << 1; + priv->buf[Count++] = 0x45; + priv->buf[Count++] = (char)0xFE; /* Adr = 0x45 */ + priv->buf[Count++] = IUU_UART_WRITE_I2C; /* 0x4C */ + priv->buf[Count++] = FrqGenAdr << 1; + priv->buf[Count++] = 0x46; + priv->buf[Count++] = 0x7F; /* Adr = 0x46 */ + priv->buf[Count++] = IUU_UART_WRITE_I2C; /* 0x4C */ + priv->buf[Count++] = FrqGenAdr << 1; + priv->buf[Count++] = 0x47; + priv->buf[Count++] = (char)0x84; /* Adr = 0x47 */ + + status = bulk_immediate(port, (u8 *) priv->buf, Count); + if (status != IUU_OPERATION_OK) + dbg("%s - write error ", __FUNCTION__); + return status; +} + +static int iuu_uart_flush(struct usb_serial_port *port) +{ + int i; + int status; + u8 rxcmd = IUU_UART_RX; + struct iuu_private *priv = usb_get_serial_port_data(port); + + dbg("%s - enter", __FUNCTION__); + + if (iuu_led(port, 0xF000, 0, 0, 0xFF) < 0) + return -EIO; + + for (i = 0; i < 2; i++) { + status = bulk_immediate(port, &rxcmd, 1); + if (status != IUU_OPERATION_OK) { + dbg("%s - uart_flush_write error", __FUNCTION__); + return status; + } + + status = read_immediate(port, &priv->len, 1); + if (status != IUU_OPERATION_OK) { + dbg("%s - uart_flush_read error", __FUNCTION__); + return status; + } + + if (priv->len > 0) { + dbg("%s - uart_flush datalen is : %i ", __FUNCTION__, + priv->len); + status = read_immediate(port, priv->buf, priv->len); + if (status != IUU_OPERATION_OK) { + dbg("%s - uart_flush_read error", __FUNCTION__); + return status; + } + } + } + dbg("%s - uart_flush_read OK!", __FUNCTION__); + iuu_led(port, 0, 0xF000, 0, 0xFF); + return status; +} + +static void read_buf_callback(struct urb *urb) +{ + struct usb_serial_port *port = (struct usb_serial_port *)urb->context; + unsigned char *data = urb->transfer_buffer; + struct tty_struct *tty; + dbg("%s - urb->status = %d", __FUNCTION__, urb->status); + + if (urb->status) { + dbg("%s - urb->status = %d", __FUNCTION__, urb->status); + if (urb->status == -EPROTO) { + /* reschedule needed */ + } + return; + } + + dbg("%s - %i chars to write", __FUNCTION__, urb->actual_length); + tty = port->tty; + if (data == NULL) + dbg("%s - data is NULL !!!", __FUNCTION__); + if (tty && urb->actual_length && data) { + tty_insert_flip_string(tty, data, urb->actual_length); + tty_flip_buffer_push(tty); + } + iuu_led_activity_on(urb); +} + +static int iuu_bulk_write(struct usb_serial_port *port) +{ + struct iuu_private *priv = usb_get_serial_port_data(port); + unsigned int flags; + int result; + int i; + char *buf_ptr = port->write_urb->transfer_buffer; + dbg("%s - enter", __FUNCTION__); + + *buf_ptr++ = IUU_UART_ESC; + *buf_ptr++ = IUU_UART_TX; + *buf_ptr++ = priv->writelen; + + memcpy(buf_ptr, priv->writebuf, + priv->writelen); + if (debug == 1) { + for (i = 0; i < priv->writelen; i++) + sprintf(priv->dbgbuf + i*2 , + "%02X", priv->writebuf[i]); + priv->dbgbuf[priv->writelen+i*2] = 0; + dbg("%s - writing %i chars : %s", __FUNCTION__, + priv->writelen, priv->dbgbuf); + } + usb_fill_bulk_urb(port->write_urb, port->serial->dev, + usb_sndbulkpipe(port->serial->dev, + port->bulk_out_endpointAddress), + port->write_urb->transfer_buffer, priv->writelen + 3, + iuu_rxcmd, port); + result = usb_submit_urb(port->write_urb, GFP_ATOMIC); + spin_lock_irqsave(&priv->lock, flags); + priv->writelen = 0; + spin_unlock_irqrestore(&priv->lock, flags); + usb_serial_port_softint(port); + return result; +} + +static int iuu_read_buf(struct usb_serial_port *port, int len) +{ + int result; + dbg("%s - enter", __FUNCTION__); + + usb_fill_bulk_urb(port->read_urb, port->serial->dev, + usb_rcvbulkpipe(port->serial->dev, + port->bulk_in_endpointAddress), + port->read_urb->transfer_buffer, len, + read_buf_callback, port); + result = usb_submit_urb(port->read_urb, GFP_ATOMIC); + return result; +} + +static void iuu_uart_read_callback(struct urb *urb) +{ + struct usb_serial_port *port = (struct usb_serial_port *)urb->context; + struct iuu_private *priv = usb_get_serial_port_data(port); + unsigned int flags; + int status; + int error = 0; + int len = 0; + unsigned char *data = urb->transfer_buffer; + priv->poll++; + + dbg("%s - enter", __FUNCTION__); + + if (urb->status) { + dbg("%s - urb->status = %d", __FUNCTION__, urb->status); + /* error stop all */ + return; + } + if (data == NULL) + dbg("%s - data is NULL !!!", __FUNCTION__); + + if (urb->actual_length == 1 && data != NULL) + len = (int) data[0]; + + if (urb->actual_length > 1) { + dbg("%s - urb->actual_length = %i", __FUNCTION__, + urb->actual_length); + error = 1; + return; + } + /* if len > 0 call readbuf */ + + if (len > 0 && error == 0) { + dbg("%s - call read buf - len to read is %i ", + __FUNCTION__, len); + status = iuu_read_buf(port, len); + return; + } + /* need to update status ? */ + if (priv->poll > 99) { + status = iuu_status(port); + priv->poll = 0; + return; + } + + /* reset waiting ? */ + + if (priv->reset == 1) { + status = iuu_reset(port, 0xC); + return; + } + /* Writebuf is waiting */ + spin_lock_irqsave(&priv->lock, flags); + if (priv->writelen > 0) { + spin_unlock_irqrestore(&priv->lock, flags); + status = iuu_bulk_write(port); + return; + } + spin_unlock_irqrestore(&priv->lock, flags); + /* if nothing to write call again rxcmd */ + dbg("%s - rxcmd recall", __FUNCTION__); + iuu_led_activity_off(urb); + return; +} + +static int iuu_uart_write(struct usb_serial_port *port, const u8 *buf, + int count) +{ + struct iuu_private *priv = usb_get_serial_port_data(port); + unsigned int flags; + dbg("%s - enter", __FUNCTION__); + + if (count > 256) + return -ENOMEM; + + spin_lock_irqsave(&priv->lock, flags); + if (priv->writelen > 0) { + /* buffer already filled but not commited */ + spin_unlock_irqrestore(&priv->lock, flags); + return (0); + } + /* fill the buffer */ + memcpy(priv->writebuf, buf, count); + priv->writelen = count; + spin_unlock_irqrestore(&priv->lock, flags); + + return (count); +} + +static void read_rxcmd_callback(struct urb *urb) +{ + struct usb_serial_port *port = (struct usb_serial_port *)urb->context; + int result; + dbg("%s - enter", __FUNCTION__); + + dbg("%s - urb->status = %d", __FUNCTION__, urb->status); + + if (urb->status) { + dbg("%s - urb->status = %d", __FUNCTION__, urb->status); + /* error stop all */ + return; + } + + usb_fill_bulk_urb(port->read_urb, port->serial->dev, + usb_rcvbulkpipe(port->serial->dev, + port->bulk_in_endpointAddress), + port->read_urb->transfer_buffer, 256, + iuu_uart_read_callback, port); + result = usb_submit_urb(port->read_urb, GFP_ATOMIC); + dbg("%s - submit result = %d", __FUNCTION__, result); + return; +} + +static int iuu_uart_on(struct usb_serial_port *port) +{ + int status; + u8 *buf; + + buf = kmalloc(sizeof(u8) * 4, GFP_KERNEL); + + if (!buf) + return -ENOMEM; + + buf[0] = IUU_UART_ENABLE; + buf[1] = (u8) ((IUU_BAUD_9600 >> 8) & 0x00FF); + buf[2] = (u8) (0x00FF & IUU_BAUD_9600); + buf[3] = (u8) (0x0F0 & IUU_TWO_STOP_BITS) | (0x07 & IUU_PARITY_EVEN); + + status = bulk_immediate(port, buf, 4); + if (status != IUU_OPERATION_OK) { + dbg("%s - uart_on error", __FUNCTION__); + goto uart_enable_failed; + } + /* iuu_reset() the card after iuu_uart_on() */ + status = iuu_uart_flush(port); + if (status != IUU_OPERATION_OK) + dbg("%s - uart_flush error", __FUNCTION__); +uart_enable_failed: + kfree(buf); + return status; +} + +/* Diables the IUU UART (a.k.a. the Phoenix voiderface) */ +static int iuu_uart_off(struct usb_serial_port *port) +{ + int status; + u8 *buf; + buf = kmalloc(1, GFP_KERNEL); + if (!buf) + return -ENOMEM; + buf[0] = IUU_UART_DISABLE; + + status = bulk_immediate(port, buf, 1); + if (status != IUU_OPERATION_OK) + dbg("%s - uart_off error", __FUNCTION__); + + kfree(buf); + return status; +} + +static int iuu_uart_baud(struct usb_serial_port *port, u32 baud, + u32 *actual, u8 parity) +{ + int status; + u8 *dataout; + u8 DataCount = 0; + u8 T1Frekvens = 0; + u8 T1reload = 0; + unsigned int T1FrekvensHZ = 0; + + dataout = kmalloc(sizeof(u8) * 5, GFP_KERNEL); + + if (!dataout) + return -ENOMEM; + + if (baud < 1200 || baud > 230400) { + kfree(dataout); + return IUU_INVALID_PARAMETER; + } + if (baud > 977) { + T1Frekvens = 3; + T1FrekvensHZ = 500000; + } + + if (baud > 3906) { + T1Frekvens = 2; + T1FrekvensHZ = 2000000; + } + + if (baud > 11718) { + T1Frekvens = 1; + T1FrekvensHZ = 6000000; + } + + if (baud > 46875) { + T1Frekvens = 0; + T1FrekvensHZ = 24000000; + } + + T1reload = 256 - (u8) (T1FrekvensHZ / (baud * 2)); + + /* magic number here: ENTER_FIRMWARE_UPDATE; */ + dataout[DataCount++] = IUU_UART_ESC; + /* magic number here: CHANGE_BAUD; */ + dataout[DataCount++] = IUU_UART_CHANGE; + dataout[DataCount++] = T1Frekvens; + dataout[DataCount++] = T1reload; + + *actual = (T1FrekvensHZ / (256 - T1reload)) / 2; + + switch (parity & 0x0F) { + case IUU_PARITY_NONE: + dataout[DataCount++] = 0x00; + break; + case IUU_PARITY_EVEN: + dataout[DataCount++] = 0x01; + break; + case IUU_PARITY_ODD: + dataout[DataCount++] = 0x02; + break; + case IUU_PARITY_MARK: + dataout[DataCount++] = 0x03; + break; + case IUU_PARITY_SPACE: + dataout[DataCount++] = 0x04; + break; + default: + kfree(dataout); + return IUU_INVALID_PARAMETER; + break; + } + + switch (parity & 0xF0) { + case IUU_ONE_STOP_BIT: + dataout[DataCount - 1] |= IUU_ONE_STOP_BIT; + break; + + case IUU_TWO_STOP_BITS: + dataout[DataCount - 1] |= IUU_TWO_STOP_BITS; + break; + default: + kfree(dataout); + return IUU_INVALID_PARAMETER; + break; + } + + status = bulk_immediate(port, dataout, DataCount); + if (status != IUU_OPERATION_OK) + dbg("%s - uart_off error", __FUNCTION__); + kfree(dataout); + return status; +} + +static int set_control_lines(struct usb_device *dev, u8 value) +{ + return 0; +} + +static void iuu_close(struct usb_serial_port *port, struct file *filp) +{ + /* iuu_led (port,255,0,0,0); */ + struct usb_serial *serial; + struct iuu_private *priv = usb_get_serial_port_data(port); + unsigned long flags; + unsigned int c_cflag; + + serial = port->serial; + if (!serial) + return; + + dbg("%s - port %d", __FUNCTION__, port->number); + + iuu_uart_off(port); + if (serial->dev) { + if (port->tty) { + c_cflag = port->tty->termios->c_cflag; + if (c_cflag & HUPCL) { + /* drop DTR and RTS */ + priv = usb_get_serial_port_data(port); + spin_lock_irqsave(&priv->lock, flags); + priv->line_control = 0; + spin_unlock_irqrestore(&priv->lock, flags); + set_control_lines(port->serial->dev, 0); + } + } + /* free writebuf */ + /* shutdown our urbs */ + dbg("%s - shutting down urbs", __FUNCTION__); + usb_kill_urb(port->write_urb); + usb_kill_urb(port->read_urb); + usb_kill_urb(port->interrupt_in_urb); + msleep(1000); + /* wait one second to free all buffers */ + iuu_led(port, 0, 0, 0xF000, 0xFF); + msleep(1000); + usb_reset_device(port->serial->dev); + } +} + +static int iuu_open(struct usb_serial_port *port, struct file *filp) +{ + struct usb_serial *serial = port->serial; + u8 *buf; + int result; + u32 actual; + unsigned long flags; + struct iuu_private *priv = usb_get_serial_port_data(port); + + dbg("%s - port %d", __FUNCTION__, port->number); + usb_clear_halt(serial->dev, port->write_urb->pipe); + usb_clear_halt(serial->dev, port->read_urb->pipe); + + buf = kmalloc(10, GFP_KERNEL); + if (buf == NULL) + return -ENOMEM; + + /* fixup the endpoint buffer size */ + kfree(port->bulk_out_buffer); + port->bulk_out_buffer = kmalloc(512, GFP_KERNEL); + port->bulk_out_size = 512; + kfree(port->bulk_in_buffer); + port->bulk_in_buffer = kmalloc(512, GFP_KERNEL); + port->bulk_in_size = 512; + + if (!port->bulk_out_buffer || !port->bulk_in_buffer) { + kfree(port->bulk_out_buffer); + kfree(port->bulk_in_buffer); + kfree(buf); + return -ENOMEM; + } + + usb_fill_bulk_urb(port->write_urb, port->serial->dev, + usb_sndbulkpipe(port->serial->dev, + port->bulk_out_endpointAddress), + port->bulk_out_buffer, 512, + NULL, NULL); + + + usb_fill_bulk_urb(port->read_urb, port->serial->dev, + usb_rcvbulkpipe(port->serial->dev, + port->bulk_in_endpointAddress), + port->bulk_in_buffer, 512, + NULL, NULL); + + /* set the termios structure */ + spin_lock_irqsave(&priv->lock, flags); + if (!priv->termios_initialized) { + *(port->tty->termios) = tty_std_termios; + port->tty->termios->c_cflag = CLOCAL | CREAD | CS8 | B9600 + | TIOCM_CTS | CSTOPB | PARENB; + port->tty->termios->c_lflag = 0; + port->tty->termios->c_oflag = 0; + port->tty->termios->c_iflag = 0; + priv->termios_initialized = 1; + port->tty->low_latency = 1; + priv->poll = 0; + } + spin_unlock_irqrestore(&priv->lock, flags); + + /* initialize writebuf */ +#define FISH(a, b, c, d) do { \ + result = usb_control_msg(port->serial->dev, \ + usb_rcvctrlpipe(port->serial->dev, 0), \ + b, a, c, d, buf, 1, 1000); \ + dbg("0x%x:0x%x:0x%x:0x%x %d - %x", a, b, c, d, result, \ + buf[0]); } while (0); + +#define SOUP(a, b, c, d) do { \ + result = usb_control_msg(port->serial->dev, \ + usb_sndctrlpipe(port->serial->dev, 0), \ + b, a, c, d, NULL, 0, 1000); \ + dbg("0x%x:0x%x:0x%x:0x%x %d", a, b, c, d, result); } while (0) + + /* This is not UART related but IUU USB driver related or something */ + /* like that. Basically no IUU will accept any commands from the USB */ + /* host unless it has received the following message */ + /* sprintf(buf ,"%c%c%c%c",0x03,0x02,0x02,0x0); */ + + SOUP(0x03, 0x02, 0x02, 0x0); + kfree(buf); + iuu_led(port, 0xF000, 0xF000, 0, 0xFF); + iuu_uart_on(port); + if (boost < 100) + boost = 100; + switch (clockmode) { + case 2: /* 3.680 Mhz */ + iuu_clk(port, IUU_CLK_3680000 * boost / 100); + result = + iuu_uart_baud(port, 9600 * boost / 100, &actual, + IUU_PARITY_EVEN); + break; + case 3: /* 6.00 Mhz */ + iuu_clk(port, IUU_CLK_6000000 * boost / 100); + result = + iuu_uart_baud(port, 16457 * boost / 100, &actual, + IUU_PARITY_EVEN); + break; + default: /* 3.579 Mhz */ + iuu_clk(port, IUU_CLK_3579000 * boost / 100); + result = + iuu_uart_baud(port, 9600 * boost / 100, &actual, + IUU_PARITY_EVEN); + } + + /* set the cardin cardout signals */ + switch (cdmode) { + case 0: + iuu_cardin = 0; + iuu_cardout = 0; + break; + case 1: + iuu_cardin = TIOCM_CD; + iuu_cardout = 0; + break; + case 2: + iuu_cardin = 0; + iuu_cardout = TIOCM_CD; + break; + case 3: + iuu_cardin = TIOCM_DSR; + iuu_cardout = 0; + break; + case 4: + iuu_cardin = 0; + iuu_cardout = TIOCM_DSR; + break; + case 5: + iuu_cardin = TIOCM_CTS; + iuu_cardout = 0; + break; + case 6: + iuu_cardin = 0; + iuu_cardout = TIOCM_CTS; + break; + case 7: + iuu_cardin = TIOCM_RNG; + iuu_cardout = 0; + break; + case 8: + iuu_cardin = 0; + iuu_cardout = TIOCM_RNG; + } + + iuu_uart_flush(port); + + dbg("%s - initialization done", __FUNCTION__); + + memset(port->write_urb->transfer_buffer, IUU_UART_RX, 1); + usb_fill_bulk_urb(port->write_urb, port->serial->dev, + usb_sndbulkpipe(port->serial->dev, + port->bulk_out_endpointAddress), + port->write_urb->transfer_buffer, 1, + read_rxcmd_callback, port); + result = usb_submit_urb(port->write_urb, GFP_KERNEL); + + if (result) { + dev_err(&port->dev, "%s - failed submitting read urb," + " error %d\n", __FUNCTION__, result); + iuu_close(port, NULL); + return -EPROTO; + } else { + dbg("%s - rxcmd OK", __FUNCTION__); + } + return result; +} + +static struct usb_serial_driver iuu_device = { + .driver = { + .owner = THIS_MODULE, + .name = "iuu_phoenix", + }, + .id_table = id_table, + .num_interrupt_in = NUM_DONT_CARE, + .num_bulk_in = 1, + .num_bulk_out = 1, + .num_ports = 1, + .open = iuu_open, + .close = iuu_close, + .write = iuu_uart_write, + .read_bulk_callback = iuu_uart_read_callback, + .tiocmget = iuu_tiocmget, + .tiocmset = iuu_tiocmset, + .attach = iuu_startup, + .shutdown = iuu_shutdown, +}; + +static int __init iuu_init(void) +{ + int retval; + retval = usb_serial_register(&iuu_device); + if (retval) + goto failed_usb_serial_register; + retval = usb_register(&iuu_driver); + if (retval) + goto failed_usb_register; + info(DRIVER_DESC " " DRIVER_VERSION); + return 0; +failed_usb_register: + usb_serial_deregister(&iuu_device); +failed_usb_serial_register: + return retval; +} + +static void __exit iuu_exit(void) +{ + usb_deregister(&iuu_driver); + usb_serial_deregister(&iuu_device); +} + +module_init(iuu_init); +module_exit(iuu_exit); + +MODULE_AUTHOR("Alain Degreffe eczema@ecze.com"); + +MODULE_DESCRIPTION(DRIVER_DESC); +MODULE_LICENSE("GPL"); + +MODULE_VERSION(DRIVER_VERSION); +module_param(debug, bool, S_IRUGO | S_IWUSR); +MODULE_PARM_DESC(debug, "Debug enabled or not"); + +module_param(xmas, bool, S_IRUGO | S_IWUSR); +MODULE_PARM_DESC(xmas, "xmas color enabled or not"); + +module_param(boost, int, S_IRUGO | S_IWUSR); +MODULE_PARM_DESC(boost, "overclock boost percent 100 to 500"); + +module_param(clockmode, int, S_IRUGO | S_IWUSR); +MODULE_PARM_DESC(clockmode, "1=3Mhz579,2=3Mhz680,3=6Mhz"); + +module_param(cdmode, int, S_IRUGO | S_IWUSR); +MODULE_PARM_DESC(cdmode, "Card detect mode 0=none, 1=CD, 2=!CD, 3=DSR, " + "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 @@ +/* + * Infinity Unlimited USB Phoenix driver + * + * Copyright (C) 2007 Alain Degreffe (eczema@ecze.com) + * + * + * Original code taken from iuutool ( Copyright (C) 2006 Juan Carlos Borrás ) + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * And tested with help of WB Electronics + * + */ + +#define IUU_USB_VENDOR_ID 0x104f +#define IUU_USB_PRODUCT_ID 0x0004 +#define IUU_USB_OP_TIMEOUT 0x0200 + +/* Programmer commands */ + +#define IUU_NO_OPERATION 0x00 +#define IUU_GET_FIRMWARE_VERSION 0x01 +#define IUU_GET_PRODUCT_NAME 0x02 +#define IUU_GET_STATE_REGISTER 0x03 +#define IUU_SET_LED 0x04 +#define IUU_WAIT_MUS 0x05 +#define IUU_WAIT_MS 0x06 +#define IUU_GET_LOADER_VERSION 0x50 +#define IUU_RST_SET 0x52 +#define IUU_RST_CLEAR 0x53 +#define IUU_SET_VCC 0x59 +#define IUU_UART_ENABLE 0x49 +#define IUU_UART_DISABLE 0x4A +#define IUU_UART_WRITE_I2C 0x4C +#define IUU_UART_ESC 0x5E +#define IUU_UART_TRAP 0x54 +#define IUU_UART_TRAP_BREAK 0x5B +#define IUU_UART_RX 0x56 +#define IUU_AVR_ON 0x21 +#define IUU_AVR_OFF 0x22 +#define IUU_AVR_1CLK 0x23 +#define IUU_AVR_RESET 0x24 +#define IUU_AVR_RESET_PC 0x25 +#define IUU_AVR_INC_PC 0x26 +#define IUU_AVR_INCN_PC 0x27 +#define IUU_AVR_PREAD 0x29 +#define IUU_AVR_PREADN 0x2A +#define IUU_AVR_PWRITE 0x28 +#define IUU_AVR_DREAD 0x2C +#define IUU_AVR_DREADN 0x2D +#define IUU_AVR_DWRITE 0x2B +#define IUU_AVR_PWRITEN 0x2E +#define IUU_EEPROM_ON 0x37 +#define IUU_EEPROM_OFF 0x38 +#define IUU_EEPROM_WRITE 0x39 +#define IUU_EEPROM_WRITEX 0x3A +#define IUU_EEPROM_WRITE8 0x3B +#define IUU_EEPROM_WRITE16 0x3C +#define IUU_EEPROM_WRITEX32 0x3D +#define IUU_EEPROM_WRITEX64 0x3E +#define IUU_EEPROM_READ 0x3F +#define IUU_EEPROM_READX 0x40 +#define IUU_EEPROM_BREAD 0x41 +#define IUU_EEPROM_BREADX 0x42 +#define IUU_PIC_CMD 0x0A +#define IUU_PIC_CMD_LOAD 0x0B +#define IUU_PIC_CMD_READ 0x0C +#define IUU_PIC_ON 0x0D +#define IUU_PIC_OFF 0x0E +#define IUU_PIC_RESET 0x16 +#define IUU_PIC_INC_PC 0x0F +#define IUU_PIC_INCN_PC 0x10 +#define IUU_PIC_PWRITE 0x11 +#define IUU_PIC_PREAD 0x12 +#define IUU_PIC_PREADN 0x13 +#define IUU_PIC_DWRITE 0x14 +#define IUU_PIC_DREAD 0x15 +#define IUU_UART_NOP 0x00 +#define IUU_UART_CHANGE 0x02 +#define IUU_UART_TX 0x04 +#define IUU_DELAY_MS 0x06 + +#define IUU_OPERATION_OK 0x00 +#define IUU_DEVICE_NOT_FOUND 0x01 +#define IUU_INVALID_HANDLE 0x02 +#define IUU_INVALID_PARAMETER 0x03 +#define IUU_INVALID_voidERFACE 0x04 +#define IUU_INVALID_REQUEST_LENGTH 0x05 +#define IUU_UART_NOT_ENABLED 0x06 +#define IUU_WRITE_ERROR 0x07 +#define IUU_READ_ERROR 0x08 +#define IUU_TX_ERROR 0x09 +#define IUU_RX_ERROR 0x0A + +#define IUU_PARITY_NONE 0x00 +#define IUU_PARITY_EVEN 0x01 +#define IUU_PARITY_ODD 0x02 +#define IUU_PARITY_MARK 0x03 +#define IUU_PARITY_SPACE 0x04 +#define IUU_SC_INSERTED 0x01 +#define IUU_VERIFY_ERROR 0x02 +#define IUU_SIM_INSERTED 0x04 +#define IUU_TWO_STOP_BITS 0x00 +#define IUU_ONE_STOP_BIT 0x20 +#define IUU_BAUD_2400 0x0398 +#define IUU_BAUD_9600 0x0298 +#define IUU_BAUD_19200 0x0164 +#define IUU_BAUD_28800 0x0198 +#define IUU_BAUD_38400 0x01B2 +#define IUU_BAUD_57600 0x0030 +#define IUU_BAUD_115200 0x0098 +#define IUU_CLK_3579000 3579000 +#define IUU_CLK_3680000 3680000 +#define IUU_CLK_6000000 6000000 +#define IUU_FULLCARD_IN 0x01 +#define IUU_DEV_ERROR 0x02 +#define IUU_MINICARD_IN 0x04 +#define IUU_VCC_5V 0x00 +#define IUU_VCC_3V 0x01 -- cgit v1.2.3 From 63bfb1f18a50e879c5cb9684ed241052ad38efcb Mon Sep 17 00:00:00 2001 From: Fernando Luis Vazquez Cao Date: Wed, 21 Nov 2007 15:13:12 -0800 Subject: USB: sis FB driver: *_ioctl32_conversion functions do not exist in recent kernels Remove dead code while at it. Signed-off-by: Fernando Luis Vazquez Cao Cc: Thomas Winischhofer Cc: Greg KH Cc: "Antonino A. Daplas" Signed-off-by: Andrew Morton Signed-off-by: Greg Kroah-Hartman --- drivers/usb/misc/sisusbvga/sisusb.c | 27 --------------------------- drivers/usb/misc/sisusbvga/sisusb.h | 3 --- 2 files changed, 30 deletions(-) diff --git a/drivers/usb/misc/sisusbvga/sisusb.c b/drivers/usb/misc/sisusbvga/sisusb.c index 9244d067cec1..8832a72bb1fb 100644 --- a/drivers/usb/misc/sisusbvga/sisusb.c +++ b/drivers/usb/misc/sisusbvga/sisusb.c @@ -3195,20 +3195,6 @@ static int sisusb_probe(struct usb_interface *intf, sisusb->present = 1; -#ifdef SISUSB_OLD_CONFIG_COMPAT - { - int ret; - /* Our ioctls are all "32/64bit compatible" */ - ret = register_ioctl32_conversion(SISUSB_GET_CONFIG_SIZE, NULL); - ret |= register_ioctl32_conversion(SISUSB_GET_CONFIG, NULL); - ret |= register_ioctl32_conversion(SISUSB_COMMAND, NULL); - if (ret) - dev_err(&sisusb->sisusb_dev->dev, "Error registering ioctl32 translations\n"); - else - sisusb->ioctl32registered = 1; - } -#endif - if (dev->speed == USB_SPEED_HIGH) { int initscreen = 1; #ifdef INCL_SISUSB_CON @@ -3271,19 +3257,6 @@ static void sisusb_disconnect(struct usb_interface *intf) usb_set_intfdata(intf, NULL); -#ifdef SISUSB_OLD_CONFIG_COMPAT - if (sisusb->ioctl32registered) { - int ret; - sisusb->ioctl32registered = 0; - ret = unregister_ioctl32_conversion(SISUSB_GET_CONFIG_SIZE); - ret |= unregister_ioctl32_conversion(SISUSB_GET_CONFIG); - ret |= unregister_ioctl32_conversion(SISUSB_COMMAND); - if (ret) { - dev_err(&sisusb->sisusb_dev->dev, "Error unregistering ioctl32 translations\n"); - } - } -#endif - sisusb->present = 0; sisusb->ready = 0; 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 { int isopen; /* !=0 if open */ int present; /* !=0 if device is present on the bus */ int ready; /* !=0 if device is ready for userland */ -#ifdef SISUSB_OLD_CONFIG_COMPAT - int ioctl32registered; -#endif int numobufs; /* number of obufs = number of out urbs */ char *obuf[NUMOBUFS], *ibuf; /* transfer buffers */ int obufsize, ibufsize; -- cgit v1.2.3 From ed8a5d49a0d4b5cf411a71476e6582f153df54e3 Mon Sep 17 00:00:00 2001 From: Fernando Luis Vázquez Cao Date: Mon, 5 Nov 2007 16:21:11 +0900 Subject: USB: sisusb: *_ioctl32_conversion functions do not exist in recent kernels Remove dead code while at it. Signed-off-by: Fernando Luis Vazquez Cao Signed-off-by: Greg Kroah-Hartman --- drivers/video/sis/sis.h | 8 -------- drivers/video/sis/sis_main.c | 48 -------------------------------------------- 2 files changed, 56 deletions(-) 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 @@ #include #ifdef CONFIG_COMPAT -#if LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,10) -#include -#define SIS_OLD_CONFIG_COMPAT -#else #define SIS_NEW_CONFIG_COMPAT -#endif #endif /* CONFIG_COMPAT */ #if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,8) @@ -607,9 +602,6 @@ struct sis_video_info { int haveXGIROM; int registered; int warncount; -#ifdef SIS_OLD_CONFIG_COMPAT - int ioctl32registered; -#endif int sisvga_engine; 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) ivideo->pcifunc = PCI_FUNC(pdev->devfn); ivideo->subsysvendor = pdev->subsystem_vendor; ivideo->subsysdevice = pdev->subsystem_device; -#ifdef SIS_OLD_CONFIG_COMPAT - ivideo->ioctl32registered = 0; -#endif #ifndef MODULE if(sisfb_mode_idx == -1) { @@ -6420,30 +6417,6 @@ error_3: vfree(ivideo->bios_abase); ivideo->next = card_list; card_list = ivideo; -#ifdef SIS_OLD_CONFIG_COMPAT - { - int ret; - /* Our ioctls are all "32/64bit compatible" */ - ret = register_ioctl32_conversion(FBIO_ALLOC, NULL); - ret |= register_ioctl32_conversion(FBIO_FREE, NULL); - ret |= register_ioctl32_conversion(FBIOGET_VBLANK, NULL); - ret |= register_ioctl32_conversion(SISFB_GET_INFO_SIZE, NULL); - ret |= register_ioctl32_conversion(SISFB_GET_INFO, NULL); - ret |= register_ioctl32_conversion(SISFB_GET_TVPOSOFFSET, NULL); - ret |= register_ioctl32_conversion(SISFB_SET_TVPOSOFFSET, NULL); - ret |= register_ioctl32_conversion(SISFB_SET_LOCK, NULL); - ret |= register_ioctl32_conversion(SISFB_GET_VBRSTATUS, NULL); - ret |= register_ioctl32_conversion(SISFB_GET_AUTOMAXIMIZE, NULL); - ret |= register_ioctl32_conversion(SISFB_SET_AUTOMAXIMIZE, NULL); - ret |= register_ioctl32_conversion(SISFB_COMMAND, NULL); - if(ret) - printk(KERN_ERR - "sisfb: Error registering ioctl32 translations\n"); - else - ivideo->ioctl32registered = 1; - } -#endif - printk(KERN_INFO "sisfb: 2D acceleration is %s, y-panning %s\n", ivideo->sisfb_accel ? "enabled" : "disabled", ivideo->sisfb_ypan ? @@ -6473,27 +6446,6 @@ static void __devexit sisfb_remove(struct pci_dev *pdev) int registered = ivideo->registered; int modechanged = ivideo->modechanged; -#ifdef SIS_OLD_CONFIG_COMPAT - if(ivideo->ioctl32registered) { - int ret; - ret = unregister_ioctl32_conversion(FBIO_ALLOC); - ret |= unregister_ioctl32_conversion(FBIO_FREE); - ret |= unregister_ioctl32_conversion(FBIOGET_VBLANK); - ret |= unregister_ioctl32_conversion(SISFB_GET_INFO_SIZE); - ret |= unregister_ioctl32_conversion(SISFB_GET_INFO); - ret |= unregister_ioctl32_conversion(SISFB_GET_TVPOSOFFSET); - ret |= unregister_ioctl32_conversion(SISFB_SET_TVPOSOFFSET); - ret |= unregister_ioctl32_conversion(SISFB_SET_LOCK); - ret |= unregister_ioctl32_conversion(SISFB_GET_VBRSTATUS); - ret |= unregister_ioctl32_conversion(SISFB_GET_AUTOMAXIMIZE); - ret |= unregister_ioctl32_conversion(SISFB_SET_AUTOMAXIMIZE); - ret |= unregister_ioctl32_conversion(SISFB_COMMAND); - if(ret) - printk(KERN_ERR - "sisfb: Error unregistering ioctl32 translations\n"); - } -#endif - /* Unmap */ iounmap(ivideo->mmio_vbase); iounmap(ivideo->video_vbase); -- cgit v1.2.3 From d8d42233d4dd3b37623b27408316ffb8cf2b5e9b Mon Sep 17 00:00:00 2001 From: Jeff Garzik Date: Wed, 21 Nov 2007 15:13:10 -0800 Subject: USB: s3c2410_udc: minor irq handler cleanups - 'irq' argument is merely used in place of a constant; replace its usage with that constant. Signed-off-by: Jeff Garzik Cc: David Brownell Cc: Greg KH Signed-off-by: Andrew Morton Signed-off-by: Greg Kroah-Hartman --- drivers/usb/gadget/s3c2410_udc.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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) /* * s3c2410_udc_irq - interrupt handler */ -static irqreturn_t s3c2410_udc_irq(int irq, void *_dev) +static irqreturn_t s3c2410_udc_irq(int dummy, void *_dev) { struct s3c2410_udc *dev = _dev; int usb_status; @@ -1016,7 +1016,7 @@ static irqreturn_t s3c2410_udc_irq(int irq, void *_dev) } } - dprintk(DEBUG_VERBOSE, "irq: %d s3c2410_udc_done.\n", irq); + dprintk(DEBUG_VERBOSE, "irq: %d s3c2410_udc_done.\n", IRQ_USBD); /* Restore old index */ udc_write(idx, S3C2410_UDC_INDEX_REG); -- cgit v1.2.3 From 568fdade1415196a4835a9add48586e36a044d82 Mon Sep 17 00:00:00 2001 From: Adrian Bunk Date: Wed, 21 Nov 2007 15:13:15 -0800 Subject: USB: usb/mon/mon_bin.c: cleanups - make the needlessly global struct mon_fops_binary static - #if 0 the unused mon_bin_mmap() and related code Signed-off-by: Adrian Bunk Cc: Alan Stern Cc: Greg KH Cc: Pete Zaitcev Signed-off-by: Andrew Morton Signed-off-by: Greg Kroah-Hartman --- drivers/usb/mon/mon_bin.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/drivers/usb/mon/mon_bin.c b/drivers/usb/mon/mon_bin.c index f06e4e2b49d3..81aab527024c 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) return mask; } +#if 0 + /* * open and close: just keep track of how many times the device is * mapped, to use the proper memory allocation function. @@ -1079,7 +1081,9 @@ int mon_bin_mmap(struct file *filp, struct vm_area_struct *vma) return 0; } -struct file_operations mon_fops_binary = { +#endif /* 0 */ + +static struct file_operations mon_fops_binary = { .owner = THIS_MODULE, .open = mon_bin_open, .llseek = no_llseek, -- cgit v1.2.3 From 527ea73eaea4600120117edd19ac88864a488d57 Mon Sep 17 00:00:00 2001 From: Kyungmin Park Date: Wed, 21 Nov 2007 15:13:15 -0800 Subject: USB: device DMA support on OMAP2 The current omap udc dosen't support the DMA mode and it has some problem at setup time on OMAP2 with previous patch file. I found that the code assumes bulk out required the big data transfer. But MODE SELECT(6) sent the only 24 bytes. it makes a problem. So I implement the small packets handling for it. It is tested with both linux and windows. Signed-off-by: Kyungmin Park Cc: David Brownell Cc: Tony Lindgren Signed-off-by: Andrew Morton Signed-off-by: Greg Kroah-Hartman --- drivers/usb/gadget/omap_udc.c | 71 +++++++++++++++++++++++++++++-------------- 1 file changed, 49 insertions(+), 22 deletions(-) diff --git a/drivers/usb/gadget/omap_udc.c b/drivers/usb/gadget/omap_udc.c index d377154658b5..7d6bef56cb01 100644 --- a/drivers/usb/gadget/omap_udc.c +++ b/drivers/usb/gadget/omap_udc.c @@ -4,6 +4,8 @@ * Copyright (C) 2004 Texas Instruments, Inc. * Copyright (C) 2004-2005 David Brownell * + * OMAP2 & DMA support by Kyungmin Park + * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or @@ -60,11 +62,6 @@ /* bulk DMA seems to be behaving for both IN and OUT */ #define USE_DMA -/* FIXME: OMAP2 currently has some problem in DMA mode */ -#ifdef CONFIG_ARCH_OMAP2 -#undef USE_DMA -#endif - /* ISO too */ #define USE_ISO @@ -73,6 +70,8 @@ #define DMA_ADDR_INVALID (~(dma_addr_t)0) +#define OMAP2_DMA_CH(ch) (((ch) - 1) << 1) +#define OMAP24XX_DMA(name, ch) (OMAP24XX_DMA_##name + OMAP2_DMA_CH(ch)) /* * 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) const int sync_mode = cpu_is_omap15xx() ? OMAP_DMA_SYNC_FRAME : OMAP_DMA_SYNC_ELEMENT; + int dma_trigger = 0; + + if (cpu_is_omap24xx()) + dma_trigger = OMAP24XX_DMA(USB_W2FC_TX0, ep->dma_channel); /* measure length in either bytes or packets */ if ((cpu_is_omap16xx() && length <= UDC_TXN_TSC) + || (cpu_is_omap24xx() && length < ep->maxpacket) || (cpu_is_omap15xx() && length < ep->maxpacket)) { txdma_ctrl = UDC_TXN_EOT | length; omap_set_dma_transfer_params(ep->lch, OMAP_DMA_DATA_TYPE_S8, - length, 1, sync_mode, 0, 0); + length, 1, sync_mode, dma_trigger, 0); } else { length = min(length / ep->maxpacket, (unsigned) UDC_TXN_TSC + 1); txdma_ctrl = length; omap_set_dma_transfer_params(ep->lch, OMAP_DMA_DATA_TYPE_S16, ep->ep.maxpacket >> 1, length, sync_mode, - 0, 0); + dma_trigger, 0); length *= ep->maxpacket; } 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) static void next_out_dma(struct omap_ep *ep, struct omap_req *req) { - unsigned packets; + unsigned packets = req->req.length - req->req.actual; + int dma_trigger = 0; + + if (cpu_is_omap24xx()) + dma_trigger = OMAP24XX_DMA(USB_W2FC_RX0, ep->dma_channel); /* NOTE: we filtered out "short reads" before, so we know * the buffer has only whole numbers of packets. + * except MODE SELECT(6) sent the 24 bytes data in OMAP24XX DMA mode */ - - /* set up this DMA transfer, enable the fifo, start */ - packets = (req->req.length - req->req.actual) / ep->ep.maxpacket; - packets = min(packets, (unsigned)UDC_RXN_TC + 1); - req->dma_bytes = packets * ep->ep.maxpacket; - omap_set_dma_transfer_params(ep->lch, OMAP_DMA_DATA_TYPE_S16, - ep->ep.maxpacket >> 1, packets, - OMAP_DMA_SYNC_ELEMENT, - 0, 0); + if (cpu_is_omap24xx() && packets < ep->maxpacket) { + omap_set_dma_transfer_params(ep->lch, OMAP_DMA_DATA_TYPE_S8, + packets, 1, OMAP_DMA_SYNC_ELEMENT, + dma_trigger, 0); + req->dma_bytes = packets; + } else { + /* set up this DMA transfer, enable the fifo, start */ + packets /= ep->ep.maxpacket; + packets = min(packets, (unsigned)UDC_RXN_TC + 1); + req->dma_bytes = packets * ep->ep.maxpacket; + omap_set_dma_transfer_params(ep->lch, OMAP_DMA_DATA_TYPE_S16, + ep->ep.maxpacket >> 1, packets, + OMAP_DMA_SYNC_ELEMENT, + dma_trigger, 0); + } omap_set_dma_dest_params(ep->lch, OMAP_DMA_PORT_EMIFF, OMAP_DMA_AMODE_POST_INC, req->req.dma + req->req.actual, 0, 0); @@ -743,6 +758,7 @@ static void dma_channel_claim(struct omap_ep *ep, unsigned channel) { u16 reg; int status, restart, is_in; + int dma_channel; is_in = ep->bEndpointAddress & USB_DIR_IN; if (is_in) @@ -769,11 +785,15 @@ static void dma_channel_claim(struct omap_ep *ep, unsigned channel) ep->dma_channel = channel; if (is_in) { - status = omap_request_dma(OMAP_DMA_USB_W2FC_TX0 - 1 + channel, + if (cpu_is_omap24xx()) + dma_channel = OMAP24XX_DMA(USB_W2FC_TX0, channel); + else + dma_channel = OMAP_DMA_USB_W2FC_TX0 - 1 + channel; + status = omap_request_dma(dma_channel, ep->ep.name, dma_error, ep, &ep->lch); if (status == 0) { UDC_TXDMA_CFG_REG = reg; - /* EMIFF */ + /* EMIFF or SDRC */ omap_set_dma_src_burst_mode(ep->lch, OMAP_DMA_DATA_BURST_4); omap_set_dma_src_data_pack(ep->lch, 1); @@ -785,7 +805,12 @@ static void dma_channel_claim(struct omap_ep *ep, unsigned channel) 0, 0); } } else { - status = omap_request_dma(OMAP_DMA_USB_W2FC_RX0 - 1 + channel, + if (cpu_is_omap24xx()) + dma_channel = OMAP24XX_DMA(USB_W2FC_RX0, channel); + else + dma_channel = OMAP_DMA_USB_W2FC_RX0 - 1 + channel; + + status = omap_request_dma(dma_channel, ep->ep.name, dma_error, ep, &ep->lch); if (status == 0) { UDC_RXDMA_CFG_REG = reg; @@ -795,7 +820,7 @@ static void dma_channel_claim(struct omap_ep *ep, unsigned channel) OMAP_DMA_AMODE_CONSTANT, (unsigned long) io_v2p((u32)&UDC_DATA_DMA_REG), 0, 0); - /* EMIFF */ + /* EMIFF or SDRC */ omap_set_dma_dest_burst_mode(ep->lch, OMAP_DMA_DATA_BURST_4); omap_set_dma_dest_data_pack(ep->lch, 1); @@ -808,7 +833,7 @@ static void dma_channel_claim(struct omap_ep *ep, unsigned channel) omap_disable_dma_irq(ep->lch, OMAP_DMA_BLOCK_IRQ); /* channel type P: hw synch (fifo) */ - if (!cpu_is_omap15xx()) + if (cpu_class_is_omap1() && !cpu_is_omap15xx()) OMAP1_DMA_LCH_CTRL_REG(ep->lch) = 2; } @@ -926,11 +951,13 @@ omap_ep_queue(struct usb_ep *_ep, struct usb_request *_req, gfp_t gfp_flags) /* this isn't bogus, but OMAP DMA isn't the only hardware to * have a hard time with partial packet reads... reject it. + * Except OMAP2 can handle the small packets. */ if (use_dma && ep->has_dma && ep->bEndpointAddress != 0 && (ep->bEndpointAddress & USB_DIR_IN) == 0 + && !cpu_class_is_omap2() && (req->req.length % ep->ep.maxpacket) != 0) { DBG("%s, no partial packet OUT reads\n", __FUNCTION__); return -EMSGSIZE; -- cgit v1.2.3 From 9da0068a4964540d8d1caa8455fe193b544d846d Mon Sep 17 00:00:00 2001 From: Matthias Kaehlcke Date: Wed, 21 Nov 2007 15:13:16 -0800 Subject: USB: TI 3410/5052 USB Serial: convert td_open_close_lock to mutex TI 3410/5052 USB Serial: convert semaphore td_open_close_lock to the mutex API. Signed-off-by: Matthias Kaehlcke Signed-off-by: Andrew Morton Signed-off-by: Greg Kroah-Hartman --- drivers/usb/serial/ti_usb_3410_5052.c | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/drivers/usb/serial/ti_usb_3410_5052.c b/drivers/usb/serial/ti_usb_3410_5052.c index 1f0149495fb4..995fdf3c4898 100644 --- a/drivers/usb/serial/ti_usb_3410_5052.c +++ b/drivers/usb/serial/ti_usb_3410_5052.c @@ -80,6 +80,7 @@ #include #include #include +#include #include #include #include @@ -139,7 +140,7 @@ struct ti_port { }; struct ti_device { - struct semaphore td_open_close_sem; + struct mutex td_open_close_lock; int td_open_port_count; struct usb_serial *td_serial; int td_is_3410; @@ -424,7 +425,7 @@ static int ti_startup(struct usb_serial *serial) dev_err(&dev->dev, "%s - out of memory\n", __FUNCTION__); return -ENOMEM; } - sema_init(&tdev->td_open_close_sem, 1); + mutex_init(&tdev->td_open_close_lock); tdev->td_serial = serial; usb_set_serial_data(serial, tdev); @@ -547,7 +548,7 @@ static int ti_open(struct usb_serial_port *port, struct file *file) tdev = tport->tp_tdev; /* only one open on any port on a device at a time */ - if (down_interruptible(&tdev->td_open_close_sem)) + if (mutex_lock_interruptible(&tdev->td_open_close_lock)) return -ERESTARTSYS; if (port->tty) @@ -568,7 +569,7 @@ static int ti_open(struct usb_serial_port *port, struct file *file) if (!urb) { dev_err(&port->dev, "%s - no interrupt urb\n", __FUNCTION__); status = -EINVAL; - goto up_sem; + goto release_lock; } urb->complete = ti_interrupt_callback; urb->context = tdev; @@ -576,7 +577,7 @@ static int ti_open(struct usb_serial_port *port, struct file *file) status = usb_submit_urb(urb, GFP_KERNEL); if (status) { dev_err(&port->dev, "%s - submit interrupt urb failed, %d\n", __FUNCTION__, status); - goto up_sem; + goto release_lock; } } @@ -656,13 +657,13 @@ static int ti_open(struct usb_serial_port *port, struct file *file) tport->tp_is_open = 1; ++tdev->td_open_port_count; - goto up_sem; + goto release_lock; unlink_int_urb: if (tdev->td_open_port_count == 0) usb_kill_urb(port->serial->port[0]->interrupt_in_urb); -up_sem: - up(&tdev->td_open_close_sem); +release_lock: + mutex_unlock(&tdev->td_open_close_lock); dbg("%s - exit %d", __FUNCTION__, status); return status; } @@ -674,7 +675,7 @@ static void ti_close(struct usb_serial_port *port, struct file *file) struct ti_port *tport; int port_number; int status; - int do_up; + int do_unlock; dbg("%s - port %d", __FUNCTION__, port->number); @@ -699,16 +700,16 @@ static void ti_close(struct usb_serial_port *port, struct file *file) if (status) dev_err(&port->dev, "%s - cannot send close port command, %d\n" , __FUNCTION__, status); - /* if down is interrupted, continue anyway */ - do_up = !down_interruptible(&tdev->td_open_close_sem); + /* if mutex_lock is interrupted, continue anyway */ + do_unlock = !mutex_lock_interruptible(&tdev->td_open_close_lock); --tport->tp_tdev->td_open_port_count; if (tport->tp_tdev->td_open_port_count <= 0) { /* last port is closed, shut down interrupt urb */ usb_kill_urb(port->serial->port[0]->interrupt_in_urb); tport->tp_tdev->td_open_port_count = 0; } - if (do_up) - up(&tdev->td_open_close_sem); + if (do_unlock) + mutex_unlock(&tdev->td_open_close_lock); dbg("%s - exit", __FUNCTION__); } -- cgit v1.2.3 From 8c73aff6d3b772e5f373d78bc34fd47b10b35fef Mon Sep 17 00:00:00 2001 From: Yoshihiro Shimoda Date: Thu, 22 Nov 2007 21:00:30 +0900 Subject: USB: m66592-udc: Add support for SH7722 USBF Add support for SuperH SH7722 USB Function. M66592 is similar to SH7722 USBF. It can support SH7722 USBF by changing several M66592 code. Signed-off-by: Yoshihiro Shimoda Acked-by: David Brownell Signed-off-by: Greg Kroah-Hartman --- drivers/usb/gadget/Kconfig | 10 ++++++++ drivers/usb/gadget/m66592-udc.c | 55 ++++++++++++++++++++++++++++++++++++++++- drivers/usb/gadget/m66592-udc.h | 54 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 118 insertions(+), 1 deletion(-) diff --git a/drivers/usb/gadget/Kconfig b/drivers/usb/gadget/Kconfig index 77a3759d6fc7..e706882a8e6f 100644 --- a/drivers/usb/gadget/Kconfig +++ b/drivers/usb/gadget/Kconfig @@ -220,6 +220,16 @@ config USB_M66592 default USB_GADGET select USB_GADGET_SELECTED +config SUPERH_BUILT_IN_M66592 + boolean "Enable SuperH built-in USB like the M66592" + depends on USB_GADGET_M66592 && CPU_SUBTYPE_SH7722 + help + SH7722 has USB like the M66592. + + The transfer rate is very slow when use "Ethernet Gadget". + However, this problem is improved if change a value of + NET_IP_ALIGN to 4. + config USB_GADGET_GOKU boolean "Toshiba TC86C001 'Goku-S'" depends on PCI diff --git a/drivers/usb/gadget/m66592-udc.c b/drivers/usb/gadget/m66592-udc.c index ebc5536aa271..154007aa8d30 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"); MODULE_LICENSE("GPL"); MODULE_AUTHOR("Yoshihiro Shimoda"); -#define DRIVER_VERSION "29 May 2007" +#define DRIVER_VERSION "18 Oct 2007" /* module parameters */ +#if defined(CONFIG_SUPERH_BUILT_IN_M66592) +static unsigned short endian = M66592_LITTLE; +module_param(endian, ushort, 0644); +MODULE_PARM_DESC(endian, "data endian: big=0, little=0 (default=0)"); +#else static unsigned short clock = M66592_XTAL24; module_param(clock, ushort, 0644); MODULE_PARM_DESC(clock, "input clock: 48MHz=32768, 24MHz=16384, 12MHz=0 " @@ -56,6 +61,7 @@ static unsigned short irq_sense = M66592_INTL; module_param(irq_sense, ushort, 0644); MODULE_PARM_DESC(irq_sense, "IRQ sense: low level=2, falling edge=0 " "(default=2)"); +#endif static const char udc_name[] = "m66592_udc"; static const char *m66592_ep_name[] = { @@ -360,6 +366,7 @@ static void m66592_ep_setting(struct m66592 *m66592, struct m66592_ep *ep, ep->fifosel = M66592_D0FIFOSEL; ep->fifoctr = M66592_D0FIFOCTR; ep->fifotrn = M66592_D0FIFOTRN; +#if !defined(CONFIG_SUPERH_BUILT_IN_M66592) } else if (m66592->num_dma == 1) { m66592->num_dma++; ep->use_dma = 1; @@ -367,6 +374,7 @@ static void m66592_ep_setting(struct m66592 *m66592, struct m66592_ep *ep, ep->fifosel = M66592_D1FIFOSEL; ep->fifoctr = M66592_D1FIFOCTR; ep->fifotrn = M66592_D1FIFOTRN; +#endif } else { ep->use_dma = 0; ep->fifoaddr = M66592_CFIFO; @@ -611,6 +619,28 @@ static void start_ep0(struct m66592_ep *ep, struct m66592_request *req) } } +#if defined(CONFIG_SUPERH_BUILT_IN_M66592) +static void init_controller(struct m66592 *m66592) +{ + usbf_start_clock(); + m66592_bset(m66592, M66592_HSE, M66592_SYSCFG); /* High spd */ + m66592_bclr(m66592, M66592_USBE, M66592_SYSCFG); + m66592_bclr(m66592, M66592_DPRPU, M66592_SYSCFG); + m66592_bset(m66592, M66592_USBE, M66592_SYSCFG); + + /* This is a workaound for SH7722 2nd cut */ + m66592_bset(m66592, 0x8000, M66592_DVSTCTR); + m66592_bset(m66592, 0x1000, M66592_TESTMODE); + m66592_bclr(m66592, 0x8000, M66592_DVSTCTR); + + m66592_bset(m66592, M66592_INTL, M66592_INTENB1); + + m66592_write(m66592, 0, M66592_CFBCFG); + m66592_write(m66592, 0, M66592_D0FBCFG); + m66592_bset(m66592, endian, M66592_CFBCFG); + m66592_bset(m66592, endian, M66592_D0FBCFG); +} +#else /* #if defined(CONFIG_SUPERH_BUILT_IN_M66592) */ static void init_controller(struct m66592 *m66592) { m66592_bset(m66592, (vif & M66592_LDRV) | (endian & M66592_BIGEND), @@ -636,9 +666,13 @@ static void init_controller(struct m66592 *m66592) m66592_write(m66592, M66592_BURST | M66592_CPU_ADR_RD_WR, M66592_DMA0CFG); } +#endif /* #if defined(CONFIG_SUPERH_BUILT_IN_M66592) */ static void disable_controller(struct m66592 *m66592) { +#if defined(CONFIG_SUPERH_BUILT_IN_M66592) + usbf_stop_clock(); +#else m66592_bclr(m66592, M66592_SCKE, M66592_SYSCFG); udelay(1); m66592_bclr(m66592, M66592_PLLC, M66592_SYSCFG); @@ -646,15 +680,20 @@ static void disable_controller(struct m66592 *m66592) m66592_bclr(m66592, M66592_RCKE, M66592_SYSCFG); udelay(1); m66592_bclr(m66592, M66592_XCKE, M66592_SYSCFG); +#endif } static void m66592_start_xclock(struct m66592 *m66592) { +#if defined(CONFIG_SUPERH_BUILT_IN_M66592) + usbf_start_clock(); +#else u16 tmp; tmp = m66592_read(m66592, M66592_SYSCFG); if (!(tmp & M66592_XCKE)) m66592_bset(m66592, M66592_XCKE, M66592_SYSCFG); +#endif } /*-------------------------------------------------------------------------*/ @@ -1142,6 +1181,19 @@ static irqreturn_t m66592_irq(int irq, void *_m66592) intsts0 = m66592_read(m66592, M66592_INTSTS0); intenb0 = m66592_read(m66592, M66592_INTENB0); +#if defined(CONFIG_SUPERH_BUILT_IN_M66592) + if (!intsts0 && !intenb0) { + /* + * When USB clock stops, it cannot read register. Even if a + * clock stops, the interrupt occurs. So this driver turn on + * a clock by this timing and do re-reading of register. + */ + m66592_start_xclock(m66592); + intsts0 = m66592_read(m66592, M66592_INTSTS0); + intenb0 = m66592_read(m66592, M66592_INTENB0); + } +#endif + savepipe = m66592_read(m66592, M66592_CFIFOSEL); mask0 = intsts0 & intenb0; @@ -1485,6 +1537,7 @@ static int __exit m66592_remove(struct platform_device *pdev) iounmap(m66592->reg); free_irq(platform_get_irq(pdev, 0), m66592); m66592_free_request(&m66592->ep[0].ep, m66592->ep0_req); + usbf_stop_clock(); kfree(m66592); return 0; } 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 @@ #define M66592_P_TST_J 0x0001 /* PERI TEST J */ #define M66592_P_TST_NORMAL 0x0000 /* PERI Normal Mode */ +#if defined(CONFIG_SUPERH_BUILT_IN_M66592) +#define M66592_CFBCFG 0x0A +#define M66592_D0FBCFG 0x0C +#define M66592_LITTLE 0x0100 /* b8: Little endian mode */ +#else #define M66592_PINCFG 0x0A #define M66592_LDRV 0x8000 /* b15: Drive Current Adjust */ #define M66592_BIGEND 0x0100 /* b8: Big endian mode */ @@ -91,6 +96,7 @@ #define M66592_PKTM 0x0020 /* b5: Packet mode */ #define M66592_DENDE 0x0010 /* b4: Dend enable */ #define M66592_OBUS 0x0004 /* b2: OUTbus mode */ +#endif /* #if defined(CONFIG_SUPERH_BUILT_IN_M66592) */ #define M66592_CFIFO 0x10 #define M66592_D0FIFO 0x14 @@ -103,9 +109,13 @@ #define M66592_REW 0x4000 /* b14: Buffer rewind */ #define M66592_DCLRM 0x2000 /* b13: DMA buffer clear mode */ #define M66592_DREQE 0x1000 /* b12: DREQ output enable */ +#if defined(CONFIG_SUPERH_BUILT_IN_M66592) +#define M66592_MBW 0x0800 /* b11: Maximum bit width for FIFO */ +#else #define M66592_MBW 0x0400 /* b10: Maximum bit width for FIFO */ #define M66592_MBW_8 0x0000 /* 8bit */ #define M66592_MBW_16 0x0400 /* 16bit */ +#endif /* #if defined(CONFIG_SUPERH_BUILT_IN_M66592) */ #define M66592_TRENB 0x0200 /* b9: Transaction counter enable */ #define M66592_TRCLR 0x0100 /* b8: Transaction counter clear */ #define M66592_DEZPM 0x0080 /* b7: Zero-length packet mode */ @@ -530,8 +540,13 @@ static inline void m66592_read_fifo(struct m66592 *m66592, { unsigned long fifoaddr = (unsigned long)m66592->reg + offset; +#if defined(CONFIG_SUPERH_BUILT_IN_M66592) + len = (len + 3) / 4; + insl(fifoaddr, buf, len); +#else len = (len + 1) / 2; insw(fifoaddr, buf, len); +#endif } static inline void m66592_write(struct m66592 *m66592, u16 val, @@ -545,6 +560,24 @@ static inline void m66592_write_fifo(struct m66592 *m66592, void *buf, unsigned long len) { unsigned long fifoaddr = (unsigned long)m66592->reg + offset; +#if defined(CONFIG_SUPERH_BUILT_IN_M66592) + unsigned long count; + unsigned char *pb; + int i; + + count = len / 4; + outsl(fifoaddr, buf, count); + + if (len & 0x00000003) { + pb = buf + count * 4; + for (i = 0; i < (len & 0x00000003); i++) { + if (m66592_read(m66592, M66592_CFBCFG)) /* little */ + outb(pb[i], fifoaddr + (3 - i)); + else + outb(pb[i], fifoaddr + i); + } + } +#else unsigned long odd = len & 0x0001; len = len / 2; @@ -553,6 +586,7 @@ static inline void m66592_write_fifo(struct m66592 *m66592, unsigned char *p = buf + len*2; outb(*p, fifoaddr); } +#endif /* #if defined(CONFIG_SUPERH_BUILT_IN_M66592) */ } static 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, #define m66592_bset(m66592, val, offset) \ m66592_mdfy(m66592, val, 0, offset) +#if defined(CONFIG_SUPERH_BUILT_IN_M66592) +#include +#define MSTPCR2 0xA4150038 /* for SH7722 */ +#define MSTPCR2_USB 0x00000800 + +static inline void usbf_start_clock(void) +{ + ctrl_outl(ctrl_inl(MSTPCR2) & ~MSTPCR2_USB, MSTPCR2); +} + +static inline void usbf_stop_clock(void) +{ + ctrl_outl(ctrl_inl(MSTPCR2) | MSTPCR2_USB, MSTPCR2); +} + +#else +#define usbf_start_clock(x) +#define usbf_stop_clock(x) +#endif /* if defined(CONFIG_SUPERH_BUILT_IN_M66592) */ + #endif /* ifndef __M66592_UDC_H__ */ -- cgit v1.2.3 From fec8de3aada6338a4069ee1df4726dd7bbbdf476 Mon Sep 17 00:00:00 2001 From: Joe Perches Date: Mon, 19 Nov 2007 17:53:33 -0800 Subject: USB: Add missing "space" to printk messages Signed-off-by: Joe Perches Acked-by: David Brownell Signed-off-by: Greg Kroah-Hartman --- drivers/usb/atm/ueagle-atm.c | 4 ++-- drivers/usb/gadget/amd5536udc.c | 2 +- drivers/usb/gadget/m66592-udc.c | 2 +- drivers/usb/gadget/net2280.c | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/drivers/usb/atm/ueagle-atm.c b/drivers/usb/atm/ueagle-atm.c index 389c5b164eb2..fad5d916564c 100644 --- a/drivers/usb/atm/ueagle-atm.c +++ b/drivers/usb/atm/ueagle-atm.c @@ -1990,7 +1990,7 @@ static void uea_dispatch_cmv_e1(struct uea_softc *sc, struct intr_pkt *intr) return; bad2: - uea_err(INS_TO_USBDEV(sc), "unexpected cmv received," + uea_err(INS_TO_USBDEV(sc), "unexpected cmv received, " "Function : %d, Subfunction : %d\n", E1_FUNCTION_TYPE(cmv->bFunction), E1_FUNCTION_SUBTYPE(cmv->bFunction)); @@ -2038,7 +2038,7 @@ static void uea_dispatch_cmv_e4(struct uea_softc *sc, struct intr_pkt *intr) return; bad2: - uea_err(INS_TO_USBDEV(sc), "unexpected cmv received," + uea_err(INS_TO_USBDEV(sc), "unexpected cmv received, " "Function : %d, Subfunction : %d\n", E4_FUNCTION_TYPE(cmv->wFunction), E4_FUNCTION_SUBTYPE(cmv->wFunction)); diff --git a/drivers/usb/gadget/amd5536udc.c b/drivers/usb/gadget/amd5536udc.c index c72e9620bf8d..66e10da8a490 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) /* stop OUT naking */ if (!ep->in) { if (!use_dma && udc_rxfifo_pending) { - DBG(dev, "udc_queue(): pending bytes in" + DBG(dev, "udc_queue(): pending bytes in " "rxfifo after nyet\n"); /* * read pending bytes afer nyet: diff --git a/drivers/usb/gadget/m66592-udc.c b/drivers/usb/gadget/m66592-udc.c index 154007aa8d30..478d8349cf00 100644 --- a/drivers/usb/gadget/m66592-udc.c +++ b/drivers/usb/gadget/m66592-udc.c @@ -748,7 +748,7 @@ static void irq_ep0_write(struct m66592_ep *ep, struct m66592_request *req) do { tmp = m66592_read(m66592, ep->fifoctr); if (i++ > 100000) { - printk(KERN_ERR "pipe0 is busy. maybe cpu i/o bus" + printk(KERN_ERR "pipe0 is busy. maybe cpu i/o bus " "conflict. please power off this controller."); return; } 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) break; default: delegate: - VDEBUG (dev, "setup %02x.%02x v%04x i%04x l%04x" + VDEBUG (dev, "setup %02x.%02x v%04x i%04x l%04x " "ep_cfg %08x\n", u.r.bRequestType, u.r.bRequest, w_value, w_index, w_length, -- cgit v1.2.3 From 676d3aa16f66d94bf5654781b77d1e070c8b0514 Mon Sep 17 00:00:00 2001 From: Alan Stern Date: Thu, 8 Nov 2007 15:15:28 -0500 Subject: USB: usb-storage: new "lockable" subclass 0x07 This patch (as1011) adds a #define for the newly-created Lockable (i.e., password-protected) subclass 0x07 for USB mass-storage devices. The private ISD200 entry (which had been mapped to subclass 0x07) is moved to 0xf0, which is unlikely to conflict with any official subclass designation. The US_SC_MIN and US_SC_MAX constants aren't used anywhere, so the patch removes them. Signed-off-by: Alan Stern Cc: Matthew Dharm Signed-off-by: Greg Kroah-Hartman --- include/linux/usb_usual.h | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/include/linux/usb_usual.h b/include/linux/usb_usual.h index a417b09b8b3d..cee0623b3c7b 100644 --- a/include/linux/usb_usual.h +++ b/include/linux/usb_usual.h @@ -80,10 +80,9 @@ enum { US_DO_ALL_FLAGS }; #define US_SC_UFI 0x04 /* Floppy */ #define US_SC_8070 0x05 /* Removable media */ #define US_SC_SCSI 0x06 /* Transparent */ -#define US_SC_ISD200 0x07 /* ISD200 ATA */ -#define US_SC_MIN US_SC_RBC -#define US_SC_MAX US_SC_ISD200 +#define US_SC_LOCKABLE 0x07 /* Password-protected */ +#define US_SC_ISD200 0xf0 /* ISD200 ATA */ #define US_SC_DEVICE 0xff /* Use device's value */ /* Protocols */ -- cgit v1.2.3 From 25a010c8c1a5f0cc2e2794adf969e2df2ad1f0b6 Mon Sep 17 00:00:00 2001 From: "Craig W. Nadler" Date: Sun, 11 Nov 2007 15:00:15 -0800 Subject: USB: add Printer Gadget Driver G_PRINTER: Adds a USB printer gadget driver for use in printer firmware. This adds a USB printer gadget driver for use in printer firmware. The printer gadget channels data between the USB host and a userspace program driving the print engine. The user space program reads and writes the device file /dev/g_printer to receive or send printer data. It can use ioctl calls to the device file to get or set printer status. Signed-off-by: Craig W. Nadler Signed-off-by: David Brownell Signed-off-by: Greg Kroah-Hartman --- Documentation/usb/gadget_printer.txt | 510 +++++++++++ drivers/usb/gadget/Kconfig | 14 + drivers/usb/gadget/Makefile | 3 + drivers/usb/gadget/printer.c | 1592 ++++++++++++++++++++++++++++++++++ include/linux/usb/Kbuild | 1 + include/linux/usb/g_printer.h | 31 + include/linux/usb/gadgetfs.h | 5 + 7 files changed, 2156 insertions(+) create mode 100644 Documentation/usb/gadget_printer.txt create mode 100644 drivers/usb/gadget/printer.c create mode 100644 include/linux/usb/g_printer.h diff --git a/Documentation/usb/gadget_printer.txt b/Documentation/usb/gadget_printer.txt new file mode 100644 index 000000000000..ad995bf0db41 --- /dev/null +++ b/Documentation/usb/gadget_printer.txt @@ -0,0 +1,510 @@ + + Linux USB Printer Gadget Driver + 06/04/2007 + + Copyright (C) 2007 Craig W. Nadler + + + +GENERAL +======= + +This driver may be used if you are writing printer firmware using Linux as +the embedded OS. This driver has nothing to do with using a printer with +your Linux host system. + +You will need a USB device controller and a Linux driver for it that accepts +a gadget / "device class" driver using the Linux USB Gadget API. After the +USB device controller driver is loaded then load the printer gadget driver. +This will present a printer interface to the USB Host that your USB Device +port is connected to. + +This driver is structured for printer firmware that runs in user mode. The +user mode printer firmware will read and write data from the kernel mode +printer gadget driver using a device file. The printer returns a printer status +byte when the USB HOST sends a device request to get the printer status. The +user space firmware can read or write this status byte using a device file +/dev/g_printer . Both blocking and non-blocking read/write calls are supported. + + + + +HOWTO USE THIS DRIVER +===================== + +To load the USB device controller driver and the printer gadget driver. The +following example uses the Netchip 2280 USB device controller driver: + +modprobe net2280 +modprobe g_printer + + +The follow command line parameter can be used when loading the printer gadget +(ex: modprobe g_printer idVendor=0x0525 idProduct=0xa4a8 ): + +idVendor - This is the Vendor ID used in the device descriptor. The default is + the Netchip vendor id 0x0525. YOU MUST CHANGE TO YOUR OWN VENDOR ID + BEFORE RELEASING A PRODUCT. If you plan to release a product and don't + already have a Vendor ID please see www.usb.org for details on how to + get one. + +idProduct - This is the Product ID used in the device descriptor. The default + is 0xa4a8, you should change this to an ID that's not used by any of + your other USB products if you have any. It would be a good idea to + start numbering your products starting with say 0x0001. + +bcdDevice - This is the version number of your product. It would be a good idea + to put your firmware version here. + +iManufacturer - A string containing the name of the Vendor. + +iProduct - A string containing the Product Name. + +iSerialNum - A string containing the Serial Number. This should be changed for + each unit of your product. + +iPNPstring - The PNP ID string used for this printer. You will want to set + either on the command line or hard code the PNP ID string used for + your printer product. + +qlen - The number of 8k buffers to use per endpoint. The default is 10, you + should tune this for your product. You may also want to tune the + size of each buffer for your product. + + + + +USING THE EXAMPLE CODE +====================== + +This example code talks to stdout, instead of a print engine. + +To compile the test code below: + +1) save it to a file called prn_example.c +2) compile the code with the follow command: + gcc prn_example.c -o prn_example + + + +To read printer data from the host to stdout: + + # prn_example -read_data + + +To write printer data from a file (data_file) to the host: + + # cat data_file | prn_example -write_data + + +To get the current printer status for the gadget driver: + + # prn_example -get_status + + Printer status is: + Printer is NOT Selected + Paper is Out + Printer OK + + +To set printer to Selected/On-line: + + # prn_example -selected + + +To set printer to Not Selected/Off-line: + + # prn_example -not_selected + + +To set paper status to paper out: + + # prn_example -paper_out + + +To set paper status to paper loaded: + + # prn_example -paper_loaded + + +To set error status to printer OK: + + # prn_example -no_error + + +To set error status to ERROR: + + # prn_example -error + + + + +EXAMPLE CODE +============ + + +#include +#include +#include +#include +#include +#include + +#define PRINTER_FILE "/dev/g_printer" +#define BUF_SIZE 512 + + +/* + * 'usage()' - Show program usage. + */ + +static void +usage(const char *option) /* I - Option string or NULL */ +{ + if (option) { + fprintf(stderr,"prn_example: Unknown option \"%s\"!\n", + option); + } + + fputs("\n", stderr); + fputs("Usage: prn_example -[options]\n", stderr); + fputs("Options:\n", stderr); + fputs("\n", stderr); + fputs("-get_status Get the current printer status.\n", stderr); + fputs("-selected Set the selected status to selected.\n", stderr); + fputs("-not_selected Set the selected status to NOT selected.\n", + stderr); + fputs("-error Set the error status to error.\n", stderr); + fputs("-no_error Set the error status to NO error.\n", stderr); + fputs("-paper_out Set the paper status to paper out.\n", stderr); + fputs("-paper_loaded Set the paper status to paper loaded.\n", + stderr); + fputs("-read_data Read printer data from driver.\n", stderr); + fputs("-write_data Write printer sata to driver.\n", stderr); + fputs("-NB_read_data (Non-Blocking) Read printer data from driver.\n", + stderr); + fputs("\n\n", stderr); + + exit(1); +} + + +static int +read_printer_data() +{ + struct pollfd fd[1]; + + /* Open device file for printer gadget. */ + fd[0].fd = open(PRINTER_FILE, O_RDWR); + if (fd[0].fd < 0) { + printf("Error %d opening %s\n", fd[0].fd, PRINTER_FILE); + close(fd[0].fd); + return(-1); + } + + fd[0].events = POLLIN | POLLRDNORM; + + while (1) { + static char buf[BUF_SIZE]; + int bytes_read; + int retval; + + /* Wait for up to 1 second for data. */ + retval = poll(fd, 1, 1000); + + if (retval && (fd[0].revents & POLLRDNORM)) { + + /* Read data from printer gadget driver. */ + bytes_read = read(fd[0].fd, buf, BUF_SIZE); + + if (bytes_read < 0) { + printf("Error %d reading from %s\n", + fd[0].fd, PRINTER_FILE); + close(fd[0].fd); + return(-1); + } else if (bytes_read > 0) { + /* Write data to standard OUTPUT (stdout). */ + fwrite(buf, 1, bytes_read, stdout); + fflush(stdout); + } + + } + + } + + /* Close the device file. */ + close(fd[0].fd); + + return 0; +} + + +static int +write_printer_data() +{ + struct pollfd fd[1]; + + /* Open device file for printer gadget. */ + fd[0].fd = open (PRINTER_FILE, O_RDWR); + if (fd[0].fd < 0) { + printf("Error %d opening %s\n", fd[0].fd, PRINTER_FILE); + close(fd[0].fd); + return(-1); + } + + fd[0].events = POLLOUT | POLLWRNORM; + + while (1) { + int retval; + static char buf[BUF_SIZE]; + /* Read data from standard INPUT (stdin). */ + int bytes_read = fread(buf, 1, BUF_SIZE, stdin); + + if (!bytes_read) { + break; + } + + while (bytes_read) { + + /* Wait for up to 1 second to sent data. */ + retval = poll(fd, 1, 1000); + + /* Write data to printer gadget driver. */ + if (retval && (fd[0].revents & POLLWRNORM)) { + retval = write(fd[0].fd, buf, bytes_read); + if (retval < 0) { + printf("Error %d writing to %s\n", + fd[0].fd, + PRINTER_FILE); + close(fd[0].fd); + return(-1); + } else { + bytes_read -= retval; + } + + } + + } + + } + + /* Wait until the data has been sent. */ + fsync(fd[0].fd); + + /* Close the device file. */ + close(fd[0].fd); + + return 0; +} + + +static int +read_NB_printer_data() +{ + int fd; + static char buf[BUF_SIZE]; + int bytes_read; + + /* Open device file for printer gadget. */ + fd = open(PRINTER_FILE, O_RDWR|O_NONBLOCK); + if (fd < 0) { + printf("Error %d opening %s\n", fd, PRINTER_FILE); + close(fd); + return(-1); + } + + while (1) { + /* Read data from printer gadget driver. */ + bytes_read = read(fd, buf, BUF_SIZE); + if (bytes_read <= 0) { + break; + } + + /* Write data to standard OUTPUT (stdout). */ + fwrite(buf, 1, bytes_read, stdout); + fflush(stdout); + } + + /* Close the device file. */ + close(fd); + + return 0; +} + + +static int +get_printer_status() +{ + int retval; + int fd; + + /* Open device file for printer gadget. */ + fd = open(PRINTER_FILE, O_RDWR); + if (fd < 0) { + printf("Error %d opening %s\n", fd, PRINTER_FILE); + close(fd); + return(-1); + } + + /* Make the IOCTL call. */ + retval = ioctl(fd, GADGET_GET_PRINTER_STATUS); + if (retval < 0) { + fprintf(stderr, "ERROR: Failed to set printer status\n"); + return(-1); + } + + /* Close the device file. */ + close(fd); + + return(retval); +} + + +static int +set_printer_status(unsigned char buf, int clear_printer_status_bit) +{ + int retval; + int fd; + + retval = get_printer_status(); + if (retval < 0) { + fprintf(stderr, "ERROR: Failed to get printer status\n"); + return(-1); + } + + /* Open device file for printer gadget. */ + fd = open(PRINTER_FILE, O_RDWR); + + if (fd < 0) { + printf("Error %d opening %s\n", fd, PRINTER_FILE); + close(fd); + return(-1); + } + + if (clear_printer_status_bit) { + retval &= ~buf; + } else { + retval |= buf; + } + + /* Make the IOCTL call. */ + if (ioctl(fd, GADGET_SET_PRINTER_STATUS, (unsigned char)retval)) { + fprintf(stderr, "ERROR: Failed to set printer status\n"); + return(-1); + } + + /* Close the device file. */ + close(fd); + + return 0; +} + + +static int +display_printer_status() +{ + char printer_status; + + printer_status = get_printer_status(); + if (printer_status < 0) { + fprintf(stderr, "ERROR: Failed to get printer status\n"); + return(-1); + } + + printf("Printer status is:\n"); + if (printer_status & PRINTER_SELECTED) { + printf(" Printer is Selected\n"); + } else { + printf(" Printer is NOT Selected\n"); + } + if (printer_status & PRINTER_PAPER_EMPTY) { + printf(" Paper is Out\n"); + } else { + printf(" Paper is Loaded\n"); + } + if (printer_status & PRINTER_NOT_ERROR) { + printf(" Printer OK\n"); + } else { + printf(" Printer ERROR\n"); + } + + return(0); +} + + +int +main(int argc, char *argv[]) +{ + int i; /* Looping var */ + int retval = 0; + + /* No Args */ + if (argc == 1) { + usage(0); + exit(0); + } + + for (i = 1; i < argc && !retval; i ++) { + + if (argv[i][0] != '-') { + continue; + } + + if (!strcmp(argv[i], "-get_status")) { + if (display_printer_status()) { + retval = 1; + } + + } else if (!strcmp(argv[i], "-paper_loaded")) { + if (set_printer_status(PRINTER_PAPER_EMPTY, 1)) { + retval = 1; + } + + } else if (!strcmp(argv[i], "-paper_out")) { + if (set_printer_status(PRINTER_PAPER_EMPTY, 0)) { + retval = 1; + } + + } else if (!strcmp(argv[i], "-selected")) { + if (set_printer_status(PRINTER_SELECTED, 0)) { + retval = 1; + } + + } else if (!strcmp(argv[i], "-not_selected")) { + if (set_printer_status(PRINTER_SELECTED, 1)) { + retval = 1; + } + + } else if (!strcmp(argv[i], "-error")) { + if (set_printer_status(PRINTER_NOT_ERROR, 1)) { + retval = 1; + } + + } else if (!strcmp(argv[i], "-no_error")) { + if (set_printer_status(PRINTER_NOT_ERROR, 0)) { + retval = 1; + } + + } else if (!strcmp(argv[i], "-read_data")) { + if (read_printer_data()) { + retval = 1; + } + + } else if (!strcmp(argv[i], "-write_data")) { + if (write_printer_data()) { + retval = 1; + } + + } else if (!strcmp(argv[i], "-NB_read_data")) { + if (read_NB_printer_data()) { + retval = 1; + } + + } else { + usage(argv[i]); + retval = 1; + } + } + + exit(retval); +} diff --git a/drivers/usb/gadget/Kconfig b/drivers/usb/gadget/Kconfig index e706882a8e6f..8a88f24270be 100644 --- a/drivers/usb/gadget/Kconfig +++ b/drivers/usb/gadget/Kconfig @@ -548,6 +548,20 @@ config USB_MIDI_GADGET Say "y" to link the driver statically, or "m" to build a dynamically linked module called "g_midi". +config USB_G_PRINTER + tristate "Printer Gadget" + help + The Printer Gadget channels data between the USB host and a + userspace program driving the print engine. The user space + program reads and writes the device file /dev/g_printer to + receive or send printer data. It can use ioctl calls to + the device file to get or set printer status. + + Say "y" to link the driver statically, or "m" to build a + dynamically linked module called "g_printer". + + For more information, see Documentation/usb/gadget_printer.txt + which includes sample code for accessing the device file. # put drivers that need isochronous transfer support (for audio # or video class gadget drivers), or specific hardware, here. 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 gadgetfs-objs := inode.o g_file_storage-objs := file_storage.o usbstring.o config.o \ epautoconf.o +g_printer-objs := printer.o usbstring.o config.o \ + epautoconf.o ifeq ($(CONFIG_USB_ETH_RNDIS),y) g_ether-objs += rndis.o @@ -38,5 +40,6 @@ obj-$(CONFIG_USB_ETH) += g_ether.o obj-$(CONFIG_USB_GADGETFS) += gadgetfs.o obj-$(CONFIG_USB_FILE_STORAGE) += g_file_storage.o obj-$(CONFIG_USB_G_SERIAL) += g_serial.o +obj-$(CONFIG_USB_G_PRINTER) += g_printer.o obj-$(CONFIG_USB_MIDI_GADGET) += g_midi.o 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 @@ +/* + * printer.c -- Printer gadget driver + * + * Copyright (C) 2003-2005 David Brownell + * Copyright (C) 2006 Craig W. Nadler + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#include "gadget_chips.h" + +#define DRIVER_DESC "Printer Gadget" +#define DRIVER_VERSION "2007 OCT 06" + +static const char shortname [] = "printer"; +static const char driver_desc [] = DRIVER_DESC; + +static dev_t g_printer_devno; + +static struct class *usb_gadget_class; + +/*-------------------------------------------------------------------------*/ + +struct printer_dev { + spinlock_t lock; /* lock this structure */ + /* lock buffer lists during read/write calls */ + spinlock_t lock_printer_io; + struct usb_gadget *gadget; + struct usb_request *req; /* for control responses */ + u8 config; + s8 interface; + struct usb_ep *in_ep, *out_ep; + const struct usb_endpoint_descriptor + *in, *out; + struct list_head rx_reqs; /* List of free RX structs */ + struct list_head rx_reqs_active; /* List of Active RX xfers */ + struct list_head rx_buffers; /* List of completed xfers */ + /* wait until there is data to be read. */ + wait_queue_head_t rx_wait; + struct list_head tx_reqs; /* List of free TX structs */ + struct list_head tx_reqs_active; /* List of Active TX xfers */ + /* Wait until there are write buffers available to use. */ + wait_queue_head_t tx_wait; + /* Wait until all write buffers have been sent. */ + wait_queue_head_t tx_flush_wait; + struct usb_request *current_rx_req; + size_t current_rx_bytes; + u8 *current_rx_buf; + u8 printer_status; + u8 reset_printer; + struct class_device *printer_class_dev; + struct cdev printer_cdev; + struct device *pdev; + u8 printer_cdev_open; + wait_queue_head_t wait; +}; + +static struct printer_dev usb_printer_gadget; + +/*-------------------------------------------------------------------------*/ + +/* DO NOT REUSE THESE IDs with a protocol-incompatible driver!! Ever!! + * Instead: allocate your own, using normal USB-IF procedures. + */ + +/* Thanks to NetChip Technologies for donating this product ID. + */ +#define PRINTER_VENDOR_NUM 0x0525 /* NetChip */ +#define PRINTER_PRODUCT_NUM 0xa4a8 /* Linux-USB Printer Gadget */ + +/* Some systems will want different product identifers published in the + * device descriptor, either numbers or strings or both. These string + * parameters are in UTF-8 (superset of ASCII's 7 bit characters). + */ + +static ushort __initdata idVendor; +module_param(idVendor, ushort, S_IRUGO); +MODULE_PARM_DESC(idVendor, "USB Vendor ID"); + +static ushort __initdata idProduct; +module_param(idProduct, ushort, S_IRUGO); +MODULE_PARM_DESC(idProduct, "USB Product ID"); + +static ushort __initdata bcdDevice; +module_param(bcdDevice, ushort, S_IRUGO); +MODULE_PARM_DESC(bcdDevice, "USB Device version (BCD)"); + +static char *__initdata iManufacturer; +module_param(iManufacturer, charp, S_IRUGO); +MODULE_PARM_DESC(iManufacturer, "USB Manufacturer string"); + +static char *__initdata iProduct; +module_param(iProduct, charp, S_IRUGO); +MODULE_PARM_DESC(iProduct, "USB Product string"); + +static char *__initdata iSerialNum; +module_param(iSerialNum, charp, S_IRUGO); +MODULE_PARM_DESC(iSerialNum, "1"); + +static char *__initdata iPNPstring; +module_param(iPNPstring, charp, S_IRUGO); +MODULE_PARM_DESC(iPNPstring, "MFG:linux;MDL:g_printer;CLS:PRINTER;SN:1;"); + +/* Number of requests to allocate per endpoint, not used for ep0. */ +static unsigned qlen = 10; +module_param(qlen, uint, S_IRUGO|S_IWUSR); + +#define QLEN qlen + +#ifdef CONFIG_USB_GADGET_DUALSPEED +#define DEVSPEED USB_SPEED_HIGH +#else /* full speed (low speed doesn't do bulk) */ +#define DEVSPEED USB_SPEED_FULL +#endif + +/*-------------------------------------------------------------------------*/ + +#define xprintk(d, level, fmt, args...) \ + printk(level "%s: " fmt, DRIVER_DESC, ## args) + +#ifdef DEBUG +#define DBG(dev, fmt, args...) \ + xprintk(dev, KERN_DEBUG, fmt, ## args) +#else +#define DBG(dev, fmt, args...) \ + do { } while (0) +#endif /* DEBUG */ + +#ifdef VERBOSE +#define VDBG(dev, fmt, args...) \ + xprintk(dev, KERN_DEBUG, fmt, ## args) +#else +#define VDBG(dev, fmt, args...) \ + do { } while (0) +#endif /* VERBOSE */ + +#define ERROR(dev, fmt, args...) \ + xprintk(dev, KERN_ERR, fmt, ## args) +#define WARN(dev, fmt, args...) \ + xprintk(dev, KERN_WARNING, fmt, ## args) +#define INFO(dev, fmt, args...) \ + xprintk(dev, KERN_INFO, fmt, ## args) + +/*-------------------------------------------------------------------------*/ + +/* USB DRIVER HOOKUP (to the hardware driver, below us), mostly + * ep0 implementation: descriptors, config management, setup(). + * also optional class-specific notification interrupt transfer. + */ + +/* + * DESCRIPTORS ... most are static, but strings and (full) configuration + * descriptors are built on demand. + */ + +#define STRING_MANUFACTURER 1 +#define STRING_PRODUCT 2 +#define STRING_SERIALNUM 3 + +/* holds our biggest descriptor */ +#define USB_DESC_BUFSIZE 256 +#define USB_BUFSIZE 8192 + +/* This device advertises one configuration. */ +#define DEV_CONFIG_VALUE 1 +#define PRINTER_INTERFACE 0 + +static struct usb_device_descriptor device_desc = { + .bLength = sizeof device_desc, + .bDescriptorType = USB_DT_DEVICE, + .bcdUSB = __constant_cpu_to_le16(0x0200), + .bDeviceClass = USB_CLASS_PER_INTERFACE, + .bDeviceSubClass = 0, + .bDeviceProtocol = 0, + .idVendor = __constant_cpu_to_le16(PRINTER_VENDOR_NUM), + .idProduct = __constant_cpu_to_le16(PRINTER_PRODUCT_NUM), + .iManufacturer = STRING_MANUFACTURER, + .iProduct = STRING_PRODUCT, + .iSerialNumber = STRING_SERIALNUM, + .bNumConfigurations = 1 +}; + +static struct usb_otg_descriptor otg_desc = { + .bLength = sizeof otg_desc, + .bDescriptorType = USB_DT_OTG, + .bmAttributes = USB_OTG_SRP +}; + +static struct usb_config_descriptor config_desc = { + .bLength = sizeof config_desc, + .bDescriptorType = USB_DT_CONFIG, + + /* compute wTotalLength on the fly */ + .bNumInterfaces = 1, + .bConfigurationValue = DEV_CONFIG_VALUE, + .iConfiguration = 0, + .bmAttributes = USB_CONFIG_ATT_ONE | USB_CONFIG_ATT_SELFPOWER, + .bMaxPower = 1 /* Self-Powered */ +}; + +static struct usb_interface_descriptor intf_desc = { + .bLength = sizeof intf_desc, + .bDescriptorType = USB_DT_INTERFACE, + .bInterfaceNumber = PRINTER_INTERFACE, + .bNumEndpoints = 2, + .bInterfaceClass = USB_CLASS_PRINTER, + .bInterfaceSubClass = 1, /* Printer Sub-Class */ + .bInterfaceProtocol = 2, /* Bi-Directional */ + .iInterface = 0 +}; + +static struct usb_endpoint_descriptor fs_ep_in_desc = { + .bLength = USB_DT_ENDPOINT_SIZE, + .bDescriptorType = USB_DT_ENDPOINT, + .bEndpointAddress = USB_DIR_IN, + .bmAttributes = USB_ENDPOINT_XFER_BULK +}; + +static struct usb_endpoint_descriptor fs_ep_out_desc = { + .bLength = USB_DT_ENDPOINT_SIZE, + .bDescriptorType = USB_DT_ENDPOINT, + .bEndpointAddress = USB_DIR_OUT, + .bmAttributes = USB_ENDPOINT_XFER_BULK +}; + +static const struct usb_descriptor_header *fs_printer_function [11] = { + (struct usb_descriptor_header *) &otg_desc, + (struct usb_descriptor_header *) &intf_desc, + (struct usb_descriptor_header *) &fs_ep_in_desc, + (struct usb_descriptor_header *) &fs_ep_out_desc, + NULL +}; + +#ifdef CONFIG_USB_GADGET_DUALSPEED + +/* + * usb 2.0 devices need to expose both high speed and full speed + * descriptors, unless they only run at full speed. + */ + +static struct usb_endpoint_descriptor hs_ep_in_desc = { + .bLength = USB_DT_ENDPOINT_SIZE, + .bDescriptorType = USB_DT_ENDPOINT, + .bmAttributes = USB_ENDPOINT_XFER_BULK, + .wMaxPacketSize = __constant_cpu_to_le16(512) +}; + +static struct usb_endpoint_descriptor hs_ep_out_desc = { + .bLength = USB_DT_ENDPOINT_SIZE, + .bDescriptorType = USB_DT_ENDPOINT, + .bmAttributes = USB_ENDPOINT_XFER_BULK, + .wMaxPacketSize = __constant_cpu_to_le16(512) +}; + +static struct usb_qualifier_descriptor dev_qualifier = { + .bLength = sizeof dev_qualifier, + .bDescriptorType = USB_DT_DEVICE_QUALIFIER, + .bcdUSB = __constant_cpu_to_le16(0x0200), + .bDeviceClass = USB_CLASS_PRINTER, + .bNumConfigurations = 1 +}; + +static const struct usb_descriptor_header *hs_printer_function [11] = { + (struct usb_descriptor_header *) &otg_desc, + (struct usb_descriptor_header *) &intf_desc, + (struct usb_descriptor_header *) &hs_ep_in_desc, + (struct usb_descriptor_header *) &hs_ep_out_desc, + NULL +}; + +/* maxpacket and other transfer characteristics vary by speed. */ +#define ep_desc(g, hs, fs) (((g)->speed == USB_SPEED_HIGH)?(hs):(fs)) + +#else + +/* if there's no high speed support, maxpacket doesn't change. */ +#define ep_desc(g, hs, fs) (((void)(g)), (fs)) + +#endif /* !CONFIG_USB_GADGET_DUALSPEED */ + +/*-------------------------------------------------------------------------*/ + +/* descriptors that are built on-demand */ + +static char manufacturer [50]; +static char product_desc [40] = DRIVER_DESC; +static char serial_num [40] = "1"; +static char pnp_string [1024] = + "XXMFG:linux;MDL:g_printer;CLS:PRINTER;SN:1;"; + +/* static strings, in UTF-8 */ +static struct usb_string strings [] = { + { STRING_MANUFACTURER, manufacturer, }, + { STRING_PRODUCT, product_desc, }, + { STRING_SERIALNUM, serial_num, }, + { } /* end of list */ +}; + +static struct usb_gadget_strings stringtab = { + .language = 0x0409, /* en-us */ + .strings = strings, +}; + +/*-------------------------------------------------------------------------*/ + +static struct usb_request * +printer_req_alloc(struct usb_ep *ep, unsigned len, gfp_t gfp_flags) +{ + struct usb_request *req; + + req = usb_ep_alloc_request(ep, gfp_flags); + + if (req != NULL) { + req->length = len; + req->buf = kmalloc(len, gfp_flags); + if (req->buf == NULL) { + usb_ep_free_request(ep, req); + return NULL; + } + } + + return req; +} + +static void +printer_req_free(struct usb_ep *ep, struct usb_request *req) +{ + if (ep != NULL && req != NULL) { + kfree(req->buf); + usb_ep_free_request(ep, req); + } +} + +/*-------------------------------------------------------------------------*/ + +static void rx_complete(struct usb_ep *ep, struct usb_request *req) +{ + struct printer_dev *dev = ep->driver_data; + int status = req->status; + unsigned long flags; + + spin_lock_irqsave(&dev->lock, flags); + + list_del_init(&req->list); /* Remode from Active List */ + + switch (status) { + + /* normal completion */ + case 0: + list_add_tail(&req->list, &dev->rx_buffers); + wake_up_interruptible(&dev->rx_wait); + DBG(dev, "G_Printer : rx length %d\n", req->actual); + break; + + /* software-driven interface shutdown */ + case -ECONNRESET: /* unlink */ + case -ESHUTDOWN: /* disconnect etc */ + VDBG(dev, "rx shutdown, code %d\n", status); + list_add(&req->list, &dev->rx_reqs); + break; + + /* for hardware automagic (such as pxa) */ + case -ECONNABORTED: /* endpoint reset */ + DBG(dev, "rx %s reset\n", ep->name); + list_add(&req->list, &dev->rx_reqs); + break; + + /* data overrun */ + case -EOVERFLOW: + /* FALLTHROUGH */ + + default: + DBG(dev, "rx status %d\n", status); + list_add(&req->list, &dev->rx_reqs); + break; + } + spin_unlock_irqrestore(&dev->lock, flags); +} + +static void tx_complete(struct usb_ep *ep, struct usb_request *req) +{ + struct printer_dev *dev = ep->driver_data; + + switch (req->status) { + default: + VDBG(dev, "tx err %d\n", req->status); + /* FALLTHROUGH */ + case -ECONNRESET: /* unlink */ + case -ESHUTDOWN: /* disconnect etc */ + break; + case 0: + break; + } + + spin_lock(&dev->lock); + /* Take the request struct off the active list and put it on the + * free list. + */ + list_del_init(&req->list); + list_add(&req->list, &dev->tx_reqs); + wake_up_interruptible(&dev->tx_wait); + if (likely(list_empty(&dev->tx_reqs_active))) + wake_up_interruptible(&dev->tx_flush_wait); + + spin_unlock(&dev->lock); +} + +/*-------------------------------------------------------------------------*/ + +static int +printer_open(struct inode *inode, struct file *fd) +{ + struct printer_dev *dev; + unsigned long flags; + int ret = -EBUSY; + + dev = container_of(inode->i_cdev, struct printer_dev, printer_cdev); + + spin_lock_irqsave(&dev->lock, flags); + + if (!dev->printer_cdev_open) { + dev->printer_cdev_open = 1; + fd->private_data = dev; + ret = 0; + /* Change the printer status to show that it's on-line. */ + dev->printer_status |= PRINTER_SELECTED; + } + + spin_unlock_irqrestore(&dev->lock, flags); + + DBG(dev, "printer_open returned %x\n", ret); + + return ret; +} + +static int +printer_close(struct inode *inode, struct file *fd) +{ + struct printer_dev *dev = fd->private_data; + unsigned long flags; + + spin_lock_irqsave(&dev->lock, flags); + dev->printer_cdev_open = 0; + fd->private_data = NULL; + /* Change printer status to show that the printer is off-line. */ + dev->printer_status &= ~PRINTER_SELECTED; + spin_unlock_irqrestore(&dev->lock, flags); + + DBG(dev, "printer_close\n"); + + return 0; +} + +static ssize_t +printer_read(struct file *fd, char __user *buf, size_t len, loff_t *ptr) +{ + struct printer_dev *dev = fd->private_data; + unsigned long flags; + size_t size; + size_t bytes_copied; + struct usb_request *req; + /* This is a pointer to the current USB rx request. */ + struct usb_request *current_rx_req; + /* This is the number of bytes in the current rx buffer. */ + size_t current_rx_bytes; + /* This is a pointer to the current rx buffer. */ + u8 *current_rx_buf; + + if (len == 0) + return -EINVAL; + + DBG(dev, "printer_read trying to read %d bytes\n", (int)len); + + spin_lock(&dev->lock_printer_io); + spin_lock_irqsave(&dev->lock, flags); + + /* We will use this flag later to check if a printer reset happened + * after we turn interrupts back on. + */ + dev->reset_printer = 0; + + while (likely(!list_empty(&dev->rx_reqs))) { + int error; + + req = container_of(dev->rx_reqs.next, + struct usb_request, list); + list_del_init(&req->list); + + /* The USB Host sends us whatever amount of data it wants to + * so we always set the length field to the full USB_BUFSIZE. + * If the amount of data is more than the read() caller asked + * for it will be stored in the request buffer until it is + * asked for by read(). + */ + req->length = USB_BUFSIZE; + req->complete = rx_complete; + + error = usb_ep_queue(dev->out_ep, req, GFP_ATOMIC); + if (error) { + DBG(dev, "rx submit --> %d\n", error); + list_add(&req->list, &dev->rx_reqs); + break; + } else { + list_add(&req->list, &dev->rx_reqs_active); + } + } + + bytes_copied = 0; + current_rx_req = dev->current_rx_req; + current_rx_bytes = dev->current_rx_bytes; + current_rx_buf = dev->current_rx_buf; + dev->current_rx_req = NULL; + dev->current_rx_bytes = 0; + dev->current_rx_buf = NULL; + + /* Check if there is any data in the read buffers. Please note that + * current_rx_bytes is the number of bytes in the current rx buffer. + * If it is zero then check if there are any other rx_buffers that + * are on the completed list. We are only out of data if all rx + * buffers are empty. + */ + if ((current_rx_bytes == 0) && + (likely(list_empty(&dev->rx_buffers)))) { + /* Turn interrupts back on before sleeping. */ + spin_unlock_irqrestore(&dev->lock, flags); + + /* + * If no data is available check if this is a NON-Blocking + * call or not. + */ + if (fd->f_flags & (O_NONBLOCK|O_NDELAY)) { + spin_unlock(&dev->lock_printer_io); + return -EAGAIN; + } + + /* Sleep until data is available */ + wait_event_interruptible(dev->rx_wait, + (likely(!list_empty(&dev->rx_buffers)))); + spin_lock_irqsave(&dev->lock, flags); + } + + /* We have data to return then copy it to the caller's buffer.*/ + while ((current_rx_bytes || likely(!list_empty(&dev->rx_buffers))) + && len) { + if (current_rx_bytes == 0) { + req = container_of(dev->rx_buffers.next, + struct usb_request, list); + list_del_init(&req->list); + + if (req->actual && req->buf) { + current_rx_req = req; + current_rx_bytes = req->actual; + current_rx_buf = req->buf; + } else { + list_add(&req->list, &dev->rx_reqs); + continue; + } + } + + /* Don't leave irqs off while doing memory copies */ + spin_unlock_irqrestore(&dev->lock, flags); + + if (len > current_rx_bytes) + size = current_rx_bytes; + else + size = len; + + size -= copy_to_user(buf, current_rx_buf, size); + bytes_copied += size; + len -= size; + buf += size; + + spin_lock_irqsave(&dev->lock, flags); + + /* We've disconnected or reset free the req and buffer */ + if (dev->reset_printer) { + printer_req_free(dev->out_ep, current_rx_req); + spin_unlock_irqrestore(&dev->lock, flags); + spin_unlock(&dev->lock_printer_io); + return -EAGAIN; + } + + /* If we not returning all the data left in this RX request + * buffer then adjust the amount of data left in the buffer. + * Othewise if we are done with this RX request buffer then + * requeue it to get any incoming data from the USB host. + */ + if (size < current_rx_bytes) { + current_rx_bytes -= size; + current_rx_buf += size; + } else { + list_add(¤t_rx_req->list, &dev->rx_reqs); + current_rx_bytes = 0; + current_rx_buf = NULL; + current_rx_req = NULL; + } + } + + dev->current_rx_req = current_rx_req; + dev->current_rx_bytes = current_rx_bytes; + dev->current_rx_buf = current_rx_buf; + + spin_unlock_irqrestore(&dev->lock, flags); + spin_unlock(&dev->lock_printer_io); + + DBG(dev, "printer_read returned %d bytes\n", (int)bytes_copied); + + if (bytes_copied) + return bytes_copied; + else + return -EAGAIN; +} + +static ssize_t +printer_write(struct file *fd, const char __user *buf, size_t len, loff_t *ptr) +{ + struct printer_dev *dev = fd->private_data; + unsigned long flags; + size_t size; /* Amount of data in a TX request. */ + size_t bytes_copied = 0; + struct usb_request *req; + + DBG(dev, "printer_write trying to send %d bytes\n", (int)len); + + if (len == 0) + return -EINVAL; + + spin_lock(&dev->lock_printer_io); + spin_lock_irqsave(&dev->lock, flags); + + /* Check if a printer reset happens while we have interrupts on */ + dev->reset_printer = 0; + + /* Check if there is any available write buffers */ + if (likely(list_empty(&dev->tx_reqs))) { + /* Turn interrupts back on before sleeping. */ + spin_unlock_irqrestore(&dev->lock, flags); + + /* + * If write buffers are available check if this is + * a NON-Blocking call or not. + */ + if (fd->f_flags & (O_NONBLOCK|O_NDELAY)) { + spin_unlock(&dev->lock_printer_io); + return -EAGAIN; + } + + /* Sleep until a write buffer is available */ + wait_event_interruptible(dev->tx_wait, + (likely(!list_empty(&dev->tx_reqs)))); + spin_lock_irqsave(&dev->lock, flags); + } + + while (likely(!list_empty(&dev->tx_reqs)) && len) { + + if (len > USB_BUFSIZE) + size = USB_BUFSIZE; + else + size = len; + + req = container_of(dev->tx_reqs.next, struct usb_request, + list); + list_del_init(&req->list); + + req->complete = tx_complete; + req->length = size; + + /* Check if we need to send a zero length packet. */ + if (len > size) + /* They will be more TX requests so no yet. */ + req->zero = 0; + else + /* If the data amount is not a multple of the + * maxpacket size then send a zero length packet. + */ + req->zero = ((len % dev->in_ep->maxpacket) == 0); + + /* Don't leave irqs off while doing memory copies */ + spin_unlock_irqrestore(&dev->lock, flags); + + if (copy_from_user(req->buf, buf, size)) { + list_add(&req->list, &dev->tx_reqs); + spin_unlock(&dev->lock_printer_io); + return bytes_copied; + } + + bytes_copied += size; + len -= size; + buf += size; + + spin_lock_irqsave(&dev->lock, flags); + + /* We've disconnected or reset so free the req and buffer */ + if (dev->reset_printer) { + printer_req_free(dev->in_ep, req); + spin_unlock_irqrestore(&dev->lock, flags); + spin_unlock(&dev->lock_printer_io); + return -EAGAIN; + } + + if (usb_ep_queue(dev->in_ep, req, GFP_ATOMIC)) { + list_add(&req->list, &dev->tx_reqs); + spin_unlock_irqrestore(&dev->lock, flags); + spin_unlock(&dev->lock_printer_io); + return -EAGAIN; + } + + list_add(&req->list, &dev->tx_reqs_active); + + } + + spin_unlock_irqrestore(&dev->lock, flags); + spin_unlock(&dev->lock_printer_io); + + DBG(dev, "printer_write sent %d bytes\n", (int)bytes_copied); + + if (bytes_copied) { + return bytes_copied; + } else { + return -EAGAIN; + } +} + +static int +printer_fsync(struct file *fd, struct dentry *dentry, int datasync) +{ + struct printer_dev *dev = fd->private_data; + unsigned long flags; + int tx_list_empty; + + spin_lock_irqsave(&dev->lock, flags); + tx_list_empty = (likely(list_empty(&dev->tx_reqs))); + spin_unlock_irqrestore(&dev->lock, flags); + + if (!tx_list_empty) { + /* Sleep until all data has been sent */ + wait_event_interruptible(dev->tx_flush_wait, + (likely(list_empty(&dev->tx_reqs_active)))); + } + + return 0; +} + +static unsigned int +printer_poll(struct file *fd, poll_table *wait) +{ + struct printer_dev *dev = fd->private_data; + unsigned long flags; + int status = 0; + + poll_wait(fd, &dev->rx_wait, wait); + poll_wait(fd, &dev->tx_wait, wait); + + spin_lock_irqsave(&dev->lock, flags); + if (likely(!list_empty(&dev->tx_reqs))) + status |= POLLOUT | POLLWRNORM; + + if (likely(!list_empty(&dev->rx_buffers))) + status |= POLLIN | POLLRDNORM; + + spin_unlock_irqrestore(&dev->lock, flags); + + return status; +} + +static int +printer_ioctl(struct inode *inode, struct file *fd, unsigned int code, + unsigned long arg) +{ + struct printer_dev *dev = fd->private_data; + unsigned long flags; + int status = 0; + + DBG(dev, "printer_ioctl: cmd=0x%4.4x, arg=%lu\n", code, arg); + + /* handle ioctls */ + + spin_lock_irqsave(&dev->lock, flags); + + switch (code) { + case GADGET_GET_PRINTER_STATUS: + status = (int)dev->printer_status; + break; + case GADGET_SET_PRINTER_STATUS: + dev->printer_status = (u8)arg; + break; + default: + /* could not handle ioctl */ + DBG(dev, "printer_ioctl: ERROR cmd=0x%4.4xis not supported\n", + code); + status = -ENOTTY; + } + + spin_unlock_irqrestore(&dev->lock, flags); + + return status; +} + +/* used after endpoint configuration */ +static struct file_operations printer_io_operations = { + .owner = THIS_MODULE, + .open = printer_open, + .read = printer_read, + .write = printer_write, + .fsync = printer_fsync, + .poll = printer_poll, + .ioctl = printer_ioctl, + .release = printer_close +}; + +/*-------------------------------------------------------------------------*/ + +static int +set_printer_interface(struct printer_dev *dev) +{ + int result = 0; + + dev->in = ep_desc(dev->gadget, &hs_ep_in_desc, &fs_ep_in_desc); + dev->in_ep->driver_data = dev; + + dev->out = ep_desc(dev->gadget, &hs_ep_out_desc, &fs_ep_out_desc); + dev->out_ep->driver_data = dev; + + result = usb_ep_enable(dev->in_ep, dev->in); + if (result != 0) { + DBG(dev, "enable %s --> %d\n", dev->in_ep->name, result); + goto done; + } + + result = usb_ep_enable(dev->out_ep, dev->out); + if (result != 0) { + DBG(dev, "enable %s --> %d\n", dev->in_ep->name, result); + goto done; + } + +done: + /* on error, disable any endpoints */ + if (result != 0) { + (void) usb_ep_disable(dev->in_ep); + (void) usb_ep_disable(dev->out_ep); + dev->in = NULL; + dev->out = NULL; + } + + /* caller is responsible for cleanup on error */ + return result; +} + +static void printer_reset_interface(struct printer_dev *dev) +{ + if (dev->interface < 0) + return; + + DBG(dev, "%s\n", __FUNCTION__); + + if (dev->in) + usb_ep_disable(dev->in_ep); + + if (dev->out) + usb_ep_disable(dev->out_ep); + + dev->interface = -1; +} + +/* change our operational config. must agree with the code + * that returns config descriptors, and altsetting code. + */ +static int +printer_set_config(struct printer_dev *dev, unsigned number) +{ + int result = 0; + struct usb_gadget *gadget = dev->gadget; + + if (gadget_is_sa1100(gadget) && dev->config) { + /* tx fifo is full, but we can't clear it...*/ + INFO(dev, "can't change configurations\n"); + return -ESPIPE; + } + + switch (number) { + case DEV_CONFIG_VALUE: + result = 0; + break; + default: + result = -EINVAL; + /* FALL THROUGH */ + case 0: + break; + } + + if (result) { + usb_gadget_vbus_draw(dev->gadget, + dev->gadget->is_otg ? 8 : 100); + } else { + char *speed; + unsigned power; + + power = 2 * config_desc.bMaxPower; + usb_gadget_vbus_draw(dev->gadget, power); + + switch (gadget->speed) { + case USB_SPEED_FULL: speed = "full"; break; +#ifdef CONFIG_USB_GADGET_DUALSPEED + case USB_SPEED_HIGH: speed = "high"; break; +#endif + default: speed = "?"; break; + } + + dev->config = number; + INFO(dev, "%s speed config #%d: %d mA, %s\n", + speed, number, power, driver_desc); + } + return result; +} + +static int +config_buf(enum usb_device_speed speed, u8 *buf, u8 type, unsigned index, + int is_otg) +{ + int len; + const struct usb_descriptor_header **function; +#ifdef CONFIG_USB_GADGET_DUALSPEED + int hs = (speed == USB_SPEED_HIGH); + + if (type == USB_DT_OTHER_SPEED_CONFIG) + hs = !hs; + + if (hs) { + function = hs_printer_function; + } else { + function = fs_printer_function; + } +#else + function = fs_printer_function; +#endif + + if (index >= device_desc.bNumConfigurations) + return -EINVAL; + + /* for now, don't advertise srp-only devices */ + if (!is_otg) + function++; + + len = usb_gadget_config_buf(&config_desc, buf, USB_DESC_BUFSIZE, + function); + if (len < 0) + return len; + ((struct usb_config_descriptor *) buf)->bDescriptorType = type; + return len; +} + +/* Change our operational Interface. */ +static int +set_interface(struct printer_dev *dev, unsigned number) +{ + int result = 0; + + if (gadget_is_sa1100(dev->gadget) && dev->interface < 0) { + /* tx fifo is full, but we can't clear it...*/ + INFO(dev, "can't change interfaces\n"); + return -ESPIPE; + } + + /* Free the current interface */ + switch (dev->interface) { + case PRINTER_INTERFACE: + printer_reset_interface(dev); + break; + } + + switch (number) { + case PRINTER_INTERFACE: + result = set_printer_interface(dev); + if (result) { + printer_reset_interface(dev); + } else { + dev->interface = PRINTER_INTERFACE; + } + break; + default: + result = -EINVAL; + /* FALL THROUGH */ + } + + if (!result) + INFO(dev, "Using interface %x\n", number); + + return result; +} + +static void printer_setup_complete(struct usb_ep *ep, struct usb_request *req) +{ + if (req->status || req->actual != req->length) + DBG((struct printer_dev *) ep->driver_data, + "setup complete --> %d, %d/%d\n", + req->status, req->actual, req->length); +} + +static void printer_soft_reset(struct printer_dev *dev) +{ + struct usb_request *req; + + INFO(dev, "Received Printer Reset Request\n"); + + if (usb_ep_disable(dev->in_ep)) + DBG(dev, "Failed to disable USB in_ep\n"); + if (usb_ep_disable(dev->out_ep)) + DBG(dev, "Failed to disable USB out_ep\n"); + + if (dev->current_rx_req != NULL) { + list_add(&dev->current_rx_req->list, &dev->rx_reqs); + dev->current_rx_req = NULL; + } + dev->current_rx_bytes = 0; + dev->current_rx_buf = NULL; + dev->reset_printer = 1; + + while (likely(!(list_empty(&dev->rx_buffers)))) { + req = container_of(dev->rx_buffers.next, struct usb_request, + list); + list_del_init(&req->list); + list_add(&req->list, &dev->rx_reqs); + } + + while (likely(!(list_empty(&dev->rx_reqs_active)))) { + req = container_of(dev->rx_buffers.next, struct usb_request, + list); + list_del_init(&req->list); + list_add(&req->list, &dev->rx_reqs); + } + + while (likely(!(list_empty(&dev->tx_reqs_active)))) { + req = container_of(dev->tx_reqs_active.next, + struct usb_request, list); + list_del_init(&req->list); + list_add(&req->list, &dev->tx_reqs); + } + + if (usb_ep_enable(dev->in_ep, dev->in)) + DBG(dev, "Failed to enable USB in_ep\n"); + if (usb_ep_enable(dev->out_ep, dev->out)) + DBG(dev, "Failed to enable USB out_ep\n"); + + wake_up_interruptible(&dev->tx_wait); + wake_up_interruptible(&dev->tx_flush_wait); +} + +/*-------------------------------------------------------------------------*/ + +/* + * The setup() callback implements all the ep0 functionality that's not + * handled lower down. + */ +static int +printer_setup(struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl) +{ + struct printer_dev *dev = get_gadget_data(gadget); + struct usb_request *req = dev->req; + int value = -EOPNOTSUPP; + u16 wIndex = le16_to_cpu(ctrl->wIndex); + u16 wValue = le16_to_cpu(ctrl->wValue); + u16 wLength = le16_to_cpu(ctrl->wLength); + + DBG(dev, "ctrl req%02x.%02x v%04x i%04x l%d\n", + ctrl->bRequestType, ctrl->bRequest, wValue, wIndex, wLength); + + req->complete = printer_setup_complete; + + switch (ctrl->bRequestType&USB_TYPE_MASK) { + + case USB_TYPE_STANDARD: + switch (ctrl->bRequest) { + + case USB_REQ_GET_DESCRIPTOR: + if (ctrl->bRequestType != USB_DIR_IN) + break; + switch (wValue >> 8) { + + case USB_DT_DEVICE: + value = min(wLength, (u16) sizeof device_desc); + memcpy(req->buf, &device_desc, value); + break; +#ifdef CONFIG_USB_GADGET_DUALSPEED + case USB_DT_DEVICE_QUALIFIER: + if (!gadget->is_dualspeed) + break; + value = min(wLength, + (u16) sizeof dev_qualifier); + memcpy(req->buf, &dev_qualifier, value); + break; + + case USB_DT_OTHER_SPEED_CONFIG: + if (!gadget->is_dualspeed) + break; + /* FALLTHROUGH */ +#endif /* CONFIG_USB_GADGET_DUALSPEED */ + case USB_DT_CONFIG: + value = config_buf(gadget->speed, req->buf, + wValue >> 8, + wValue & 0xff, + gadget->is_otg); + if (value >= 0) + value = min(wLength, (u16) value); + break; + + case USB_DT_STRING: + value = usb_gadget_get_string(&stringtab, + wValue & 0xff, req->buf); + if (value >= 0) + value = min(wLength, (u16) value); + break; + } + break; + + case USB_REQ_SET_CONFIGURATION: + if (ctrl->bRequestType != 0) + break; + if (gadget->a_hnp_support) + DBG(dev, "HNP available\n"); + else if (gadget->a_alt_hnp_support) + DBG(dev, "HNP needs a different root port\n"); + value = printer_set_config(dev, wValue); + break; + case USB_REQ_GET_CONFIGURATION: + if (ctrl->bRequestType != USB_DIR_IN) + break; + *(u8 *)req->buf = dev->config; + value = min(wLength, (u16) 1); + break; + + case USB_REQ_SET_INTERFACE: + if (ctrl->bRequestType != USB_RECIP_INTERFACE || + !dev->config) + break; + + value = set_interface(dev, PRINTER_INTERFACE); + break; + case USB_REQ_GET_INTERFACE: + if (ctrl->bRequestType != + (USB_DIR_IN|USB_RECIP_INTERFACE) + || !dev->config) + break; + + *(u8 *)req->buf = dev->interface; + value = min(wLength, (u16) 1); + break; + + default: + goto unknown; + } + break; + + case USB_TYPE_CLASS: + switch (ctrl->bRequest) { + case 0: /* Get the IEEE-1284 PNP String */ + /* Only one printer interface is supported. */ + if ((wIndex>>8) != PRINTER_INTERFACE) + break; + + value = (pnp_string[0]<<8)|pnp_string[1]; + memcpy(req->buf, pnp_string, value); + DBG(dev, "1284 PNP String: %x %s\n", value, + &pnp_string[2]); + break; + + case 1: /* Get Port Status */ + /* Only one printer interface is supported. */ + if (wIndex != PRINTER_INTERFACE) + break; + + *(u8 *)req->buf = dev->printer_status; + value = min(wLength, (u16) 1); + break; + + case 2: /* Soft Reset */ + /* Only one printer interface is supported. */ + if (wIndex != PRINTER_INTERFACE) + break; + + printer_soft_reset(dev); + + value = 0; + break; + + default: + goto unknown; + } + break; + + default: +unknown: + VDBG(dev, + "unknown ctrl req%02x.%02x v%04x i%04x l%d\n", + ctrl->bRequestType, ctrl->bRequest, + wValue, wIndex, wLength); + break; + } + + /* respond with data transfer before status phase? */ + if (value >= 0) { + req->length = value; + req->zero = value < wLength + && (value % gadget->ep0->maxpacket) == 0; + value = usb_ep_queue(gadget->ep0, req, GFP_ATOMIC); + if (value < 0) { + DBG(dev, "ep_queue --> %d\n", value); + req->status = 0; + printer_setup_complete(gadget->ep0, req); + } + } + + /* host either stalls (value < 0) or reports success */ + return value; +} + +static void +printer_disconnect(struct usb_gadget *gadget) +{ + struct printer_dev *dev = get_gadget_data(gadget); + unsigned long flags; + + DBG(dev, "%s\n", __FUNCTION__); + + spin_lock_irqsave(&dev->lock, flags); + + printer_reset_interface(dev); + + spin_unlock_irqrestore(&dev->lock, flags); +} + +static void +printer_unbind(struct usb_gadget *gadget) +{ + struct printer_dev *dev = get_gadget_data(gadget); + struct usb_request *req; + + + DBG(dev, "%s\n", __FUNCTION__); + + /* Remove sysfs files */ + device_destroy(usb_gadget_class, g_printer_devno); + + /* Remove Character Device */ + cdev_del(&dev->printer_cdev); + + /* we must already have been disconnected ... no i/o may be active */ + WARN_ON(!list_empty(&dev->tx_reqs_active)); + WARN_ON(!list_empty(&dev->rx_reqs_active)); + + /* Free all memory for this driver. */ + while (!list_empty(&dev->tx_reqs)) { + req = container_of(dev->tx_reqs.next, struct usb_request, + list); + list_del(&req->list); + printer_req_free(dev->in_ep, req); + } + + if (dev->current_rx_req != NULL); + printer_req_free(dev->out_ep, dev->current_rx_req); + + while (!list_empty(&dev->rx_reqs)) { + req = container_of(dev->rx_reqs.next, + struct usb_request, list); + list_del(&req->list); + printer_req_free(dev->out_ep, req); + } + + while (!list_empty(&dev->rx_buffers)) { + req = container_of(dev->rx_buffers.next, + struct usb_request, list); + list_del(&req->list); + printer_req_free(dev->out_ep, req); + } + + if (dev->req) { + printer_req_free(gadget->ep0, dev->req); + dev->req = NULL; + } + + set_gadget_data(gadget, NULL); +} + +static int __init +printer_bind(struct usb_gadget *gadget) +{ + struct printer_dev *dev; + struct usb_ep *in_ep, *out_ep; + int status = -ENOMEM; + int gcnum; + size_t len; + u32 i; + struct usb_request *req; + + dev = &usb_printer_gadget; + + + /* Setup the sysfs files for the printer gadget. */ + dev->pdev = device_create(usb_gadget_class, NULL, g_printer_devno, + "g_printer"); + if (IS_ERR(dev->pdev)) { + ERROR(dev, "Failed to create device: g_printer\n"); + goto fail; + } + + /* + * Register a character device as an interface to a user mode + * program that handles the printer specific functionality. + */ + cdev_init(&dev->printer_cdev, &printer_io_operations); + dev->printer_cdev.owner = THIS_MODULE; + status = cdev_add(&dev->printer_cdev, g_printer_devno, 1); + if (status) { + ERROR(dev, "Failed to open char device\n"); + goto fail; + } + + if (gadget_is_sa1100(gadget)) { + /* hardware can't write zero length packets. */ + ERROR(dev, "SA1100 controller is unsupport by this driver\n"); + goto fail; + } + + gcnum = usb_gadget_controller_number(gadget); + if (gcnum >= 0) { + device_desc.bcdDevice = cpu_to_le16(0x0200 + gcnum); + } else { + dev_warn(&gadget->dev, "controller '%s' not recognized\n", + gadget->name); + /* unrecognized, but safe unless bulk is REALLY quirky */ + device_desc.bcdDevice = + __constant_cpu_to_le16(0xFFFF); + } + snprintf(manufacturer, sizeof(manufacturer), "%s %s with %s", + init_utsname()->sysname, init_utsname()->release, + gadget->name); + + device_desc.idVendor = + __constant_cpu_to_le16(PRINTER_VENDOR_NUM); + device_desc.idProduct = + __constant_cpu_to_le16(PRINTER_PRODUCT_NUM); + + /* support optional vendor/distro customization */ + if (idVendor) { + if (!idProduct) { + dev_err(&gadget->dev, "idVendor needs idProduct!\n"); + return -ENODEV; + } + device_desc.idVendor = cpu_to_le16(idVendor); + device_desc.idProduct = cpu_to_le16(idProduct); + if (bcdDevice) + device_desc.bcdDevice = cpu_to_le16(bcdDevice); + } + + if (iManufacturer) + strlcpy(manufacturer, iManufacturer, sizeof manufacturer); + + if (iProduct) + strlcpy(product_desc, iProduct, sizeof product_desc); + + if (iSerialNum) + strlcpy(serial_num, iSerialNum, sizeof serial_num); + + if (iPNPstring) + strlcpy(&pnp_string[2], iPNPstring, (sizeof pnp_string)-2); + + len = strlen(pnp_string); + pnp_string[0] = (len >> 8) & 0xFF; + pnp_string[1] = len & 0xFF; + + /* all we really need is bulk IN/OUT */ + usb_ep_autoconfig_reset(gadget); + in_ep = usb_ep_autoconfig(gadget, &fs_ep_in_desc); + if (!in_ep) { +autoconf_fail: + dev_err(&gadget->dev, "can't autoconfigure on %s\n", + gadget->name); + return -ENODEV; + } + in_ep->driver_data = in_ep; /* claim */ + + out_ep = usb_ep_autoconfig(gadget, &fs_ep_out_desc); + if (!out_ep) + goto autoconf_fail; + out_ep->driver_data = out_ep; /* claim */ + +#ifdef CONFIG_USB_GADGET_DUALSPEED + /* assumes ep0 uses the same value for both speeds ... */ + dev_qualifier.bMaxPacketSize0 = device_desc.bMaxPacketSize0; + + /* and that all endpoints are dual-speed */ + hs_ep_in_desc.bEndpointAddress = fs_ep_in_desc.bEndpointAddress; + hs_ep_out_desc.bEndpointAddress = fs_ep_out_desc.bEndpointAddress; +#endif /* DUALSPEED */ + + device_desc.bMaxPacketSize0 = gadget->ep0->maxpacket; + usb_gadget_set_selfpowered(gadget); + + if (gadget->is_otg) { + otg_desc.bmAttributes |= USB_OTG_HNP, + config_desc.bmAttributes |= USB_CONFIG_ATT_WAKEUP; + config_desc.bMaxPower = 4; + } + + spin_lock_init(&dev->lock); + spin_lock_init(&dev->lock_printer_io); + INIT_LIST_HEAD(&dev->tx_reqs); + INIT_LIST_HEAD(&dev->tx_reqs_active); + INIT_LIST_HEAD(&dev->rx_reqs); + INIT_LIST_HEAD(&dev->rx_reqs_active); + INIT_LIST_HEAD(&dev->rx_buffers); + init_waitqueue_head(&dev->rx_wait); + init_waitqueue_head(&dev->tx_wait); + init_waitqueue_head(&dev->tx_flush_wait); + + dev->config = 0; + dev->interface = -1; + dev->printer_cdev_open = 0; + dev->printer_status = PRINTER_NOT_ERROR; + dev->current_rx_req = NULL; + dev->current_rx_bytes = 0; + dev->current_rx_buf = NULL; + + dev->in_ep = in_ep; + dev->out_ep = out_ep; + + /* preallocate control message data and buffer */ + dev->req = printer_req_alloc(gadget->ep0, USB_DESC_BUFSIZE, + GFP_KERNEL); + if (!dev->req) { + status = -ENOMEM; + goto fail; + } + + for (i = 0; i < QLEN; i++) { + req = printer_req_alloc(dev->in_ep, USB_BUFSIZE, GFP_KERNEL); + if (!req) { + while (!list_empty(&dev->tx_reqs)) { + req = container_of(dev->tx_reqs.next, + struct usb_request, list); + list_del(&req->list); + printer_req_free(dev->in_ep, req); + } + return -ENOMEM; + } + list_add(&req->list, &dev->tx_reqs); + } + + for (i = 0; i < QLEN; i++) { + req = printer_req_alloc(dev->out_ep, USB_BUFSIZE, GFP_KERNEL); + if (!req) { + while (!list_empty(&dev->rx_reqs)) { + req = container_of(dev->rx_reqs.next, + struct usb_request, list); + list_del(&req->list); + printer_req_free(dev->out_ep, req); + } + return -ENOMEM; + } + list_add(&req->list, &dev->rx_reqs); + } + + dev->req->complete = printer_setup_complete; + + /* finish hookup to lower layer ... */ + dev->gadget = gadget; + set_gadget_data(gadget, dev); + gadget->ep0->driver_data = dev; + + INFO(dev, "%s, version: " DRIVER_VERSION "\n", driver_desc); + INFO(dev, "using %s, OUT %s IN %s\n", gadget->name, out_ep->name, + in_ep->name); + + return 0; + +fail: + printer_unbind(gadget); + return status; +} + +/*-------------------------------------------------------------------------*/ + +static struct usb_gadget_driver printer_driver = { + .speed = DEVSPEED, + + .function = (char *) driver_desc, + .bind = printer_bind, + .unbind = printer_unbind, + + .setup = printer_setup, + .disconnect = printer_disconnect, + + .driver = { + .name = (char *) shortname, + .owner = THIS_MODULE, + }, +}; + +MODULE_DESCRIPTION(DRIVER_DESC); +MODULE_AUTHOR("Craig Nadler"); +MODULE_LICENSE("GPL"); + +static int __init +init(void) +{ + int status; + + usb_gadget_class = class_create(THIS_MODULE, "usb_printer_gadget"); + if (IS_ERR(usb_gadget_class)) { + status = PTR_ERR(usb_gadget_class); + ERROR(dev, "unable to create usb_gadget class %d\n", status); + return status; + } + + status = alloc_chrdev_region(&g_printer_devno, 0, 1, + "USB printer gadget"); + if (status) { + ERROR(dev, "alloc_chrdev_region %d\n", status); + class_destroy(usb_gadget_class); + return status; + } + + status = usb_gadget_register_driver(&printer_driver); + if (status) { + class_destroy(usb_gadget_class); + unregister_chrdev_region(g_printer_devno, 1); + DBG(dev, "usb_gadget_register_driver %x\n", status); + } + + return status; +} +module_init(init); + +static void __exit +cleanup(void) +{ + int status; + + spin_lock(&usb_printer_gadget.lock_printer_io); + class_destroy(usb_gadget_class); + unregister_chrdev_region(g_printer_devno, 2); + + status = usb_gadget_unregister_driver(&printer_driver); + if (status) + ERROR(dev, "usb_gadget_unregister_driver %x\n", status); + + spin_unlock(&usb_printer_gadget.lock_printer_io); +} +module_exit(cleanup); diff --git a/include/linux/usb/Kbuild b/include/linux/usb/Kbuild index 6ce42bf9f743..74a9ce78e7a9 100644 --- a/include/linux/usb/Kbuild +++ b/include/linux/usb/Kbuild @@ -3,4 +3,5 @@ unifdef-y += cdc.h unifdef-y += ch9.h unifdef-y += gadgetfs.h unifdef-y += midi.h +unifdef-y += g_printer.h diff --git a/include/linux/usb/g_printer.h b/include/linux/usb/g_printer.h new file mode 100644 index 000000000000..0c5ea1e3eb98 --- /dev/null +++ b/include/linux/usb/g_printer.h @@ -0,0 +1,31 @@ +/* + * g_printer.h -- Header file for USB Printer gadget driver + * + * Copyright (C) 2007 Craig W. Nadler + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + + +#define PRINTER_NOT_ERROR 0x08 +#define PRINTER_SELECTED 0x10 +#define PRINTER_PAPER_EMPTY 0x20 + +/* The 'g' code is also used by gadgetfs ioctl requests. + * Don't add any colliding codes to either driver, and keep + * them in unique ranges (size 0x20 for now). + */ +#define GADGET_GET_PRINTER_STATUS _IOR('g', 0x21, unsigned char) +#define GADGET_SET_PRINTER_STATUS _IOWR('g', 0x22, unsigned char) diff --git a/include/linux/usb/gadgetfs.h b/include/linux/usb/gadgetfs.h index e8654c338729..981e9ceb8fe7 100644 --- a/include/linux/usb/gadgetfs.h +++ b/include/linux/usb/gadgetfs.h @@ -59,6 +59,11 @@ struct usb_gadgetfs_event { }; +/* The 'g' code is also used by printer gadget ioctl requests. + * Don't add any colliding codes to either driver, and keep + * them in unique ranges (size 0x20 for now). + */ + /* endpoint ioctls */ /* IN transfers may be reported to the gadget driver as complete -- cgit v1.2.3 From d09d6a351498fcd6195f05c3964320ae6fbeadb1 Mon Sep 17 00:00:00 2001 From: Oliver Bock Date: Mon, 12 Nov 2007 00:42:16 +0100 Subject: USB: cypress_cy7c63: updated contact/usage information here's a minor update to the cypress_cy7c63 driver providing new contact and usage information. From: Oliver Bock Signed-off-by: Greg Kroah-Hartman --- drivers/usb/misc/cypress_cy7c63.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) 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 @@ /* * cypress_cy7c63.c * -* Copyright (c) 2006 Oliver Bock (o.bock@fh-wolfenbuettel.de) +* Copyright (c) 2006-2007 Oliver Bock (bock@tfh-berlin.de) * * This driver is based on the Cypress USB Driver by Marcus Maul * (cyport) and the 2.0 version of Greg Kroah-Hartman's @@ -21,6 +21,9 @@ * Supported functions: Read/Write Ports * * +* For up-to-date information please visit: +* http://www.obock.de/kernel/cypress +* * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation, version 2. @@ -31,7 +34,7 @@ #include #include -#define DRIVER_AUTHOR "Oliver Bock (o.bock@fh-wolfenbuettel.de)" +#define DRIVER_AUTHOR "Oliver Bock (bock@tfh-berlin.de)" #define DRIVER_DESC "Cypress CY7C63xxx USB driver" #define CYPRESS_VENDOR_ID 0xa2c -- cgit v1.2.3 From 27680d232b04d434d8d49a8417429b9512ffb7c6 Mon Sep 17 00:00:00 2001 From: Aristeu Rozanski Date: Mon, 12 Nov 2007 15:14:49 -0500 Subject: USB: usb_serial_console: fix command line parsing Currently usb serial console support ignores the device and always use ttyUSB0. Signed-off-by: Aristeu Rozanski Signed-off-by: Greg Kroah-Hartman --- drivers/usb/serial/console.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/drivers/usb/serial/console.c b/drivers/usb/serial/console.c index 0362654d3b52..72ab3bbf0f2e 100644 --- a/drivers/usb/serial/console.c +++ b/drivers/usb/serial/console.c @@ -133,11 +133,14 @@ static int usb_console_setup(struct console *co, char *options) } co->cflag = cflag; - /* grab the first serial port that happens to be connected */ - serial = usb_serial_get_by_index(0); + /* + * no need to check the index here: if the index is wrong, console + * code won't call us + */ + serial = usb_serial_get_by_index(co->index); if (serial == NULL) { /* no device is connected yet, sorry :( */ - err ("No USB device connected to ttyUSB0"); + err ("No USB device connected to ttyUSB%i", co->index); return -ENODEV; } -- cgit v1.2.3 From 9a6b1efa6fd1ee022fdf42c91a9868c589cc95b7 Mon Sep 17 00:00:00 2001 From: Aristeu Rozanski Date: Mon, 12 Nov 2007 15:15:02 -0500 Subject: USB: usb_serial: clean tty reference in the last close When a usb serial adapter is used as console, the usb serial console driver bumps the open_count on the port struct used but doesn't attach a real tty to it (only a fake one temporaly). If this port is opened later using the regular character device interface, the open method won't initialize the port, which is the expected, and will receive a brand new tty struct created by tty layer, which will be stored in port->tty. When the last close is issued, open_count won't be 0 because of the console usage and the port->tty will still contain the old tty value. This is the last ttyUSB close so the allocated tty will be freed by the tty layer. The usb_serial and usb_serial_port are still in use by the console, so port_free() won't be called (serial_close() -> usb_serial_put() -> destroy_serial() -> port_free()), so the scheduled work (port->work, usb_serial_port_work()) will still run. And usb_serial_port_work() does: (...) tty = port->tty; if (!tty) return; tty_wakeup(tty); which causes (manually copied): Faulting instruction address: 0x6b6b6b68 Oops: Kernel access of bad area, sig: 11 [#1] PREEMPT PowerMac Modules linked in: binfmt_misc ipv6 nfs lockd nfs_acl sunrpc dm_snapshot dm_mirror dm_mod hfsplus uinput ams input_polldev genrtc cpufreq_powersave i2c_powermac therm_adt746x snd_aoa_codec_tas snd_aoa_fabric_layout snd_aoa joydev snd_aoa_i2sbus snd_pcm_oss snd_mixer_oss snd_pcm snd_timer snd_page_alloc pmac_zilog serial_core evdev ide_cd cdrom snd appletouch soundcore snd_aoa_soundbus bcm43xx firmware_class usbhid ieee80211softmac ff_memless firewire_ohci firewire_core ieee80211 ieee80211_crypt crc_itu_t sungem sungem_phy uninorth_agp agpart ssb NIP: 6b6b6b68 LR: c01b2108 CTR: 6b6b6b6b REGS: c106de80 TRAP: 0400 Not tainted (2.6.24-rc2) MSR: 40009032 CR: 82004024 XER: 00000000 TASK = c106b4c0[5] 'events/0' THREAD: c106c000 GPR00: 6b6b6b6b c106df30 c106b4c0 c2d613a0 00009032 00000001 00001a00 00000001 GPR08: 00000008 00000000 00000000 c106c000 42004028 00000000 016ffbe0 0171a724 GPR16: 016ffcf4 00240e24 00240e70 016fee68 016ff9a4 c03046c4 c0327f50 c03046fc GPR24: c106b6b9 c106b4c0 c101d610 c106c000 c02160fc c1eac1dc c2d613ac c2d613a0 NIP [6b6b6b68] 0x6b6b6b68 LR [c01b2108] tty_wakeup+0x6c/0x9c Call Trace: [c106df30] [c01b20e8] tty_wakeup+0x4c/0x9c (unreliable) [c106df40] [c0216138] usb_serial_port_work+0x3c/0x78 [c106df50] [c00432e8] run_workqueue+0xc4/0x15c [c106df90] [c0043798] worker_thread+0xa0/0x124 [c106dfd0] [c0048224] kthread+0x48/0x84 [c106dff0] [c00129bc] kernel_thread+0x44/0x60 Instruction dump: XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX Slab corruption: size-2048 start=c2d613a0, len=2048 Redzone: 0x9f911029d74e35b/0x9f911029d74e35b. Last user: [](release_one_tty+0xbc/0xf4) 050: 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b Prev obj: start=c2d60b88, len=2048 Redzone: 0x9f911029d74e35b/0x9f911029d74e35b. Last user: [](show_stat+0x410/0x428) 000: 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 010: 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b This patch avoids this, clearing port->tty considering if the port is used as serial console or not Signed-off-by: Aristeu Rozanski Signed-off-by: Greg Kroah-Hartman --- drivers/usb/serial/console.c | 3 ++- drivers/usb/serial/usb-serial.c | 6 ++++-- include/linux/usb/serial.h | 1 + 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/drivers/usb/serial/console.c b/drivers/usb/serial/console.c index 72ab3bbf0f2e..04007c31d88d 100644 --- a/drivers/usb/serial/console.c +++ b/drivers/usb/serial/console.c @@ -192,8 +192,9 @@ static int usb_console_setup(struct console *co, char *options) kfree (termios); kfree (tty); } + port->console = 1; - return retval; + return 0; } static void usb_console_write(struct console *co, const char *buf, unsigned count) diff --git a/drivers/usb/serial/usb-serial.c b/drivers/usb/serial/usb-serial.c index 497e29a700ca..5c33e2471be8 100644 --- a/drivers/usb/serial/usb-serial.c +++ b/drivers/usb/serial/usb-serial.c @@ -264,19 +264,21 @@ static void serial_close(struct tty_struct *tty, struct file * filp) } --port->open_count; - if (port->open_count == 0) { + if (port->open_count == 0) /* only call the device specific close if this * port is being closed by the last owner */ port->serial->type->close(port, filp); + if (port->open_count == (port->console? 1 : 0)) { if (port->tty) { if (port->tty->driver_data) port->tty->driver_data = NULL; port->tty = NULL; } + } + if (port->open_count == 0) module_put(port->serial->type->driver.owner); - } mutex_unlock(&port->mutex); usb_serial_put(port->serial); diff --git a/include/linux/usb/serial.h b/include/linux/usb/serial.h index 488ce128885c..ef1e430f7bfa 100644 --- a/include/linux/usb/serial.h +++ b/include/linux/usb/serial.h @@ -92,6 +92,7 @@ struct usb_serial_port { int open_count; char throttled; char throttle_req; + char console; struct device dev; }; #define to_usb_serial_port(d) container_of(d, struct usb_serial_port, dev) -- cgit v1.2.3 From c87d6a4f67657f4f1b992eea43796c7e7c09fb17 Mon Sep 17 00:00:00 2001 From: Aristeu Rozanski Date: Tue, 13 Nov 2007 17:22:07 -0500 Subject: USB: usb_serial_console: allocate fake tty and termios before calling driver open() method The usb serial method set_termios() is called for the first time from open() method in order to set up the termios structure with the default device's settings, ignoring the current settings. Once it's initialized, the next set_termios() calls will update the device with the tty->termios settings. Currently USB serial console code calls the driver open() method without a tty and after that will allocate a fake tty and termios so the command line arguments can be applied to the device (console=ttyUSB0,115200,...). This makes the driver overwrite the termios with the default settings and not applying the command line options. This patch changes usb_console_setup() to allocate the fake tty and termios before the open() method is called. Tested successfully with a pl2303 Signed-off-by: Aristeu Rozanski Signed-off-by: Greg Kroah-Hartman --- drivers/usb/serial/console.c | 82 ++++++++++++++++++++++++++------------------ 1 file changed, 48 insertions(+), 34 deletions(-) diff --git a/drivers/usb/serial/console.c b/drivers/usb/serial/console.c index 04007c31d88d..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) struct usb_serial *serial; struct usb_serial_port *port; int retval = 0; - struct tty_struct *tty; - struct ktermios *termios; + struct tty_struct *tty = NULL; + struct ktermios *termios = NULL, dummy; dbg ("%s", __FUNCTION__); @@ -151,50 +151,64 @@ static int usb_console_setup(struct console *co, char *options) ++port->open_count; if (port->open_count == 1) { + if (serial->type->set_termios) { + /* + * allocate a fake tty so the driver can initialize + * the termios structure, then later call set_termios to + * configure according to command line arguments + */ + tty = kzalloc(sizeof(*tty), GFP_KERNEL); + if (!tty) { + retval = -ENOMEM; + err("no more memory"); + goto reset_open_count; + } + termios = kzalloc(sizeof(*termios), GFP_KERNEL); + if (!termios) { + retval = -ENOMEM; + err("no more memory"); + goto free_tty; + } + memset(&dummy, 0, sizeof(struct ktermios)); + tty->termios = termios; + port->tty = tty; + } + /* only call the device specific open if this * is the first time the port is opened */ if (serial->type->open) retval = serial->type->open(port, NULL); else retval = usb_serial_generic_open(port, NULL); - if (retval) - port->open_count = 0; - } - if (retval) { - err ("could not open USB console port"); - return retval; - } - - if (serial->type->set_termios) { - struct ktermios dummy; - /* build up a fake tty structure so that the open call has something - * to look at to get the cflag value */ - tty = kzalloc(sizeof(*tty), GFP_KERNEL); - if (!tty) { - err ("no more memory"); - return -ENOMEM; + if (retval) { + err("could not open USB console port"); + goto free_termios; } - termios = kzalloc(sizeof(*termios), GFP_KERNEL); - if (!termios) { - err ("no more memory"); - kfree (tty); - return -ENOMEM; - } - memset(&dummy, 0, sizeof(struct ktermios)); - termios->c_cflag = cflag; - tty->termios = termios; - port->tty = tty; - /* set up the initial termios settings */ - serial->type->set_termios(port, &dummy); - port->tty = NULL; - kfree (termios); - kfree (tty); + if (serial->type->set_termios) { + termios->c_cflag = cflag; + serial->type->set_termios(port, &dummy); + + port->tty = NULL; + kfree(termios); + kfree(tty); + } } + port->console = 1; + retval = 0; - return 0; +out: + return retval; +free_termios: + kfree(termios); + port->tty = NULL; +free_tty: + kfree(tty); +reset_open_count: + port->open_count = 0; +goto out; } static void usb_console_write(struct console *co, const char *buf, unsigned count) -- cgit v1.2.3 From 6d71190e945d31617324e8320965946ad17e6e8c Mon Sep 17 00:00:00 2001 From: "Robert P. J. Day" Date: Wed, 14 Nov 2007 16:21:00 -0500 Subject: USB: linux/usb/Kbuild needs only "header-y", not "unifdef-y" Given that none of the referenced header files test the proprocessor conditional __KERNEL__, there's no point "unifdef"fing them. Signed-off-by: Robert P. J. Day Signed-off-by: Greg Kroah-Hartman --- include/linux/usb/Kbuild | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/include/linux/usb/Kbuild b/include/linux/usb/Kbuild index 74a9ce78e7a9..b8cba1dcb2c6 100644 --- a/include/linux/usb/Kbuild +++ b/include/linux/usb/Kbuild @@ -1,7 +1,7 @@ -unifdef-y += audio.h -unifdef-y += cdc.h -unifdef-y += ch9.h -unifdef-y += gadgetfs.h -unifdef-y += midi.h +header-y += audio.h +header-y += cdc.h +header-y += ch9.h +header-y += gadgetfs.h +header-y += midi.h unifdef-y += g_printer.h -- cgit v1.2.3 From a6a01369fdf7c1376421b243ae740465a527b96c Mon Sep 17 00:00:00 2001 From: Julia Lawall Date: Wed, 14 Nov 2007 09:15:16 +0100 Subject: USB: Drop unnecessary continue in a few drivers Continue is not needed at the bottom of a loop. The semantic patch implementing this change is as follows: @@ @@ for (...;...;...) { ... if (...) { ... - continue; } } Signed-off-by: Julia Lawall Signed-off-by: Greg Kroah-Hartman --- drivers/usb/host/isp116x-hcd.c | 1 - drivers/usb/image/mdc800.c | 2 -- 2 files changed, 3 deletions(-) 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) | RH_PS_OCIC | RH_PS_PRSC)) { changed = 1; buf[0] |= 1 << (i + 1); - continue; } } spin_unlock_irqrestore(&isp116x->lock, flags); 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, { irq_interval=intf_desc->endpoint [j].desc.bInterval; } - - continue; } } if (mdc800->endpoint[i] == -1) -- cgit v1.2.3 From 4145ed6dc597a9bea5f6ae8c574653b2de10620f Mon Sep 17 00:00:00 2001 From: Alan Stern Date: Mon, 19 Nov 2007 10:15:02 -0500 Subject: USB: make ksuspend_usbd thread non-freezable This patch (as1012b) makes the ksuspend_usbd kernel thread non-freezable. Since the PM core has been changed to lock all devices during a system sleep, the thread no longer needs to be frozen. It won't interfere with a system sleep because before trying to resume a root hub device, it acquires the device's lock. Signed-off-by: Alan Stern Signed-off-by: Greg Kroah-Hartman --- drivers/usb/core/usb.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c index 8f142370103d..bc5edacb0c34 100644 --- a/drivers/usb/core/usb.c +++ b/drivers/usb/core/usb.c @@ -230,7 +230,7 @@ static int ksuspend_usb_init(void) * singlethreaded. Its job doesn't justify running on more * than one CPU. */ - ksuspend_usb_wq = create_freezeable_workqueue("ksuspend_usbd"); + ksuspend_usb_wq = create_singlethread_workqueue("ksuspend_usbd"); if (!ksuspend_usb_wq) return -ENOMEM; return 0; -- cgit v1.2.3 From 269954e542328f014fc07fbb0a986192f7a1cced Mon Sep 17 00:00:00 2001 From: Alan Stern Date: Mon, 19 Nov 2007 15:57:45 -0500 Subject: USB: don't change HC power state for a FREEZE This patch (as1016) prevents PCI-based host controllers from undergoing a power-state change during a FREEZE or a PRETHAW. Such changes are needed only during a SUSPEND. Signed-off-by: Alan Stern CC: David Brownell Signed-off-by: Greg Kroah-Hartman --- drivers/usb/core/hcd-pci.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/drivers/usb/core/hcd-pci.c b/drivers/usb/core/hcd-pci.c index 3fb9af80cbf4..424674203fd3 100644 --- a/drivers/usb/core/hcd-pci.c +++ b/drivers/usb/core/hcd-pci.c @@ -250,6 +250,12 @@ int usb_hcd_pci_suspend (struct pci_dev *dev, pm_message_t message) pci_disable_device (dev); } + if (message.event == PM_EVENT_FREEZE || + message.event == PM_EVENT_PRETHAW) { + dev_dbg(hcd->self.controller, "--> no state change\n"); + goto done; + } + if (!has_pci_pm) { dev_dbg (hcd->self.controller, "--> PCI D0/legacy\n"); goto done; -- cgit v1.2.3 From 00274921a052d3232d9f00856387fb269ac0af11 Mon Sep 17 00:00:00 2001 From: David Brownell Date: Mon, 19 Nov 2007 12:58:36 -0800 Subject: USB: gadget code switches to pr_err() and friends We now have pr_err(), pr_warning(), and friends ... start using them in the gadget stack instead of printk(KERN_ERR) and friends. This gives us shorter lines and somewhat increased readability. Signed-off-by: David Brownell Signed-off-by: Greg Kroah-Hartman --- drivers/usb/gadget/at91_udc.h | 13 +-- drivers/usb/gadget/atmel_usba_udc.c | 11 +-- drivers/usb/gadget/atmel_usba_udc.h | 7 +- drivers/usb/gadget/file_storage.c | 14 ++-- drivers/usb/gadget/fsl_usb2_udc.h | 6 +- drivers/usb/gadget/gmidi.c | 6 +- drivers/usb/gadget/inode.c | 2 +- drivers/usb/gadget/m66592-udc.c | 48 +++++------ drivers/usb/gadget/omap_udc.h | 13 +-- drivers/usb/gadget/pxa2xx_udc.c | 14 ++-- drivers/usb/gadget/pxa2xx_udc.h | 11 ++- drivers/usb/gadget/rndis.c | 20 ++--- drivers/usb/gadget/serial.c | 153 +++++++++++++++++++----------------- drivers/usb/gadget/zero.c | 4 +- 14 files changed, 151 insertions(+), 171 deletions(-) diff --git a/drivers/usb/gadget/at91_udc.h b/drivers/usb/gadget/at91_udc.h index 7e34e2f864f9..aecc7225a8c6 100644 --- a/drivers/usb/gadget/at91_udc.h +++ b/drivers/usb/gadget/at91_udc.h @@ -158,12 +158,6 @@ struct at91_request { /*-------------------------------------------------------------------------*/ -#ifdef DEBUG -#define DBG(stuff...) printk(KERN_DEBUG "udc: " stuff) -#else -#define DBG(stuff...) do{}while(0) -#endif - #ifdef VERBOSE # define VDBG DBG #else @@ -176,9 +170,10 @@ struct at91_request { # define PACKET(stuff...) do{}while(0) #endif -#define ERR(stuff...) printk(KERN_ERR "udc: " stuff) -#define WARN(stuff...) printk(KERN_WARNING "udc: " stuff) -#define INFO(stuff...) printk(KERN_INFO "udc: " stuff) +#define ERR(stuff...) pr_err("udc: " stuff) +#define WARN(stuff...) pr_warning("udc: " stuff) +#define INFO(stuff...) pr_info("udc: " stuff) +#define DBG(stuff...) pr_debug("udc: " stuff) #endif 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: return retval; stall: - printk(KERN_ERR - "udc: %s: Invalid setup request: %02x.%02x v%04x i%04x l%d, " + pr_err("udc: %s: Invalid setup request: %02x.%02x v%04x i%04x l%d, " "halting endpoint...\n", ep->ep.name, crq->bRequestType, crq->bRequest, le16_to_cpu(crq->wValue), le16_to_cpu(crq->wIndex), @@ -1456,8 +1455,7 @@ restart: set_protocol_stall(udc, ep); break; default: - printk(KERN_ERR - "udc: %s: TXCOMP: Invalid endpoint state %d, " + pr_err("udc: %s: TXCOMP: Invalid endpoint state %d, " "halting endpoint...\n", ep->ep.name, ep->state); set_protocol_stall(udc, ep); @@ -1486,8 +1484,7 @@ restart: default: usba_ep_writel(ep, CLR_STA, USBA_RX_BK_RDY); usba_ep_writel(ep, CTL_DIS, USBA_RX_BK_RDY); - printk(KERN_ERR - "udc: %s: RXRDY: Invalid endpoint state %d, " + pr_err("udc: %s: RXRDY: Invalid endpoint state %d, " "halting endpoint...\n", ep->ep.name, ep->state); set_protocol_stall(udc, ep); @@ -1532,7 +1529,7 @@ restart: pkt_len = USBA_BFEXT(BYTE_COUNT, usba_ep_readl(ep, STA)); DBG(DBG_HW, "Packet length: %u\n", pkt_len); if (pkt_len != sizeof(crq)) { - printk(KERN_WARNING "udc: Invalid packet length %u " + pr_warning("udc: Invalid packet length %u " "(expected %lu)\n", pkt_len, sizeof(crq)); set_protocol_stall(udc, ep); 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 @@ #define FIFO_IOMEM_ID 0 #define CTRL_IOMEM_ID 1 -#ifdef DEBUG #define DBG_ERR 0x0001 /* report all error returns */ #define DBG_HW 0x0002 /* debug hardware initialization */ #define DBG_GADGET 0x0004 /* calls to/from gadget driver */ @@ -230,14 +229,12 @@ #define DBG_NONE 0x0000 #define DEBUG_LEVEL (DBG_ERR) + #define DBG(level, fmt, ...) \ do { \ if ((level) & DEBUG_LEVEL) \ - printk(KERN_DEBUG "udc: " fmt, ## __VA_ARGS__); \ + pr_debug("udc: " fmt, ## __VA_ARGS__); \ } while (0) -#else -#define DBG(level, fmt...) -#endif enum usba_ctrl_state { WAIT_FOR_SETUP, 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"); /*-------------------------------------------------------------------------*/ -#ifdef DEBUG #define LDBG(lun,fmt,args...) \ dev_dbg(&(lun)->dev , fmt , ## args) #define MDBG(fmt,args...) \ - printk(KERN_DEBUG DRIVER_NAME ": " fmt , ## args) -#else -#define LDBG(lun,fmt,args...) \ - do { } while (0) -#define MDBG(fmt,args...) \ - do { } while (0) + pr_debug(DRIVER_NAME ": " fmt , ## args) + +#ifndef DEBUG #undef VERBOSE_DEBUG #undef DUMP_MSGS -#endif /* DEBUG */ +#endif /* !DEBUG */ #ifdef VERBOSE_DEBUG #define VLDBG LDBG @@ -304,7 +300,7 @@ MODULE_LICENSE("Dual BSD/GPL"); dev_info(&(lun)->dev , fmt , ## args) #define MINFO(fmt,args...) \ - printk(KERN_INFO DRIVER_NAME ": " fmt , ## args) + pr_info(DRIVER_NAME ": " fmt , ## args) #define DBG(d, fmt, args...) \ dev_dbg(&(d)->gadget->dev , fmt , ## args) 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) #define VDBG(stuff...) do{}while(0) #endif -#define ERR(stuff...) printk(KERN_ERR "udc: " stuff) -#define WARN(stuff...) printk(KERN_WARNING "udc: " stuff) -#define INFO(stuff...) printk(KERN_INFO "udc: " stuff) +#define ERR(stuff...) pr_err("udc: " stuff) +#define WARN(stuff...) pr_warning("udc: " stuff) +#define INFO(stuff...) pr_info("udc: " stuff) /*-------------------------------------------------------------------------*/ 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) /* support optional vendor/distro customization */ if (idVendor) { if (!idProduct) { - printk(KERN_ERR "idVendor needs idProduct!\n"); + pr_err("idVendor needs idProduct!\n"); return -ENODEV; } device_desc.idVendor = cpu_to_le16(idVendor); @@ -1190,7 +1190,7 @@ static int __devinit gmidi_bind(struct usb_gadget *gadget) in_ep = usb_ep_autoconfig(gadget, &bulk_in_desc); if (!in_ep) { autoconf_fail: - printk(KERN_ERR "%s: can't autoconfigure on %s\n", + pr_err("%s: can't autoconfigure on %s\n", shortname, gadget->name); return -ENODEV; } @@ -1212,7 +1212,7 @@ autoconf_fail: * it SHOULD NOT have problems with bulk-capable hardware. * so warn about unrecognized controllers, don't panic. */ - printk(KERN_WARNING "%s: controller '%s' not recognized\n", + pr_warning("%s: controller '%s' not recognized\n", shortname, gadget->name); device_desc.bcdDevice = __constant_cpu_to_le16(0x9999); } 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) if (!dev) return -ESRCH; if (0 != strcmp (CHIP, gadget->name)) { - printk (KERN_ERR "%s expected %s controller not %s\n", + pr_err("%s expected %s controller not %s\n", shortname, CHIP, gadget->name); return -ENODEV; } diff --git a/drivers/usb/gadget/m66592-udc.c b/drivers/usb/gadget/m66592-udc.c index 478d8349cf00..43f02189dc44 100644 --- a/drivers/usb/gadget/m66592-udc.c +++ b/drivers/usb/gadget/m66592-udc.c @@ -147,7 +147,7 @@ static inline u16 control_reg_get_pid(struct m66592 *m66592, u16 pipenum) offset = get_pipectr_addr(pipenum); pid = m66592_read(m66592, offset) & M66592_PID; } else - printk(KERN_ERR "unexpect pipe num (%d)\n", pipenum); + pr_err("unexpect pipe num (%d)\n", pipenum); return pid; } @@ -163,7 +163,7 @@ static inline void control_reg_set_pid(struct m66592 *m66592, u16 pipenum, offset = get_pipectr_addr(pipenum); m66592_mdfy(m66592, pid, M66592_PID, offset); } else - printk(KERN_ERR "unexpect pipe num (%d)\n", pipenum); + pr_err("unexpect pipe num (%d)\n", pipenum); } static inline void pipe_start(struct m66592 *m66592, u16 pipenum) @@ -192,7 +192,7 @@ static inline u16 control_reg_get(struct m66592 *m66592, u16 pipenum) offset = get_pipectr_addr(pipenum); ret = m66592_read(m66592, offset); } else - printk(KERN_ERR "unexpect pipe num (%d)\n", pipenum); + pr_err("unexpect pipe num (%d)\n", pipenum); return ret; } @@ -209,7 +209,7 @@ static inline void control_reg_sqclr(struct m66592 *m66592, u16 pipenum) offset = get_pipectr_addr(pipenum); m66592_bset(m66592, M66592_SQCLR, offset); } else - printk(KERN_ERR "unexpect pipe num(%d)\n", pipenum); + pr_err("unexpect pipe num(%d)\n", pipenum); } static inline int get_buffer_size(struct m66592 *m66592, u16 pipenum) @@ -291,7 +291,7 @@ static int pipe_buffer_setting(struct m66592 *m66592, break; } if (m66592->bi_bufnum > M66592_MAX_BUFNUM) { - printk(KERN_ERR "m66592 pipe memory is insufficient(%d)\n", + pr_err("m66592 pipe memory is insufficient(%d)\n", m66592->bi_bufnum); return -ENOMEM; } @@ -332,7 +332,7 @@ static void pipe_buffer_release(struct m66592 *m66592, if (info->type == M66592_BULK) m66592->bulk--; } else - printk(KERN_ERR "ep_release: unexpect pipenum (%d)\n", + pr_err("ep_release: unexpect pipenum (%d)\n", info->pipe); } @@ -430,7 +430,7 @@ static int alloc_pipe_config(struct m66592_ep *ep, case USB_ENDPOINT_XFER_BULK: if (m66592->bulk >= M66592_MAX_NUM_BULK) { if (m66592->isochronous >= M66592_MAX_NUM_ISOC) { - printk(KERN_ERR "bulk pipe is insufficient\n"); + pr_err("bulk pipe is insufficient\n"); return -ENODEV; } else { info.pipe = M66592_BASE_PIPENUM_ISOC @@ -446,7 +446,7 @@ static int alloc_pipe_config(struct m66592_ep *ep, break; case USB_ENDPOINT_XFER_INT: if (m66592->interrupt >= M66592_MAX_NUM_INT) { - printk(KERN_ERR "interrupt pipe is insufficient\n"); + pr_err("interrupt pipe is insufficient\n"); return -ENODEV; } info.pipe = M66592_BASE_PIPENUM_INT + m66592->interrupt; @@ -455,7 +455,7 @@ static int alloc_pipe_config(struct m66592_ep *ep, break; case USB_ENDPOINT_XFER_ISOC: if (m66592->isochronous >= M66592_MAX_NUM_ISOC) { - printk(KERN_ERR "isochronous pipe is insufficient\n"); + pr_err("isochronous pipe is insufficient\n"); return -ENODEV; } info.pipe = M66592_BASE_PIPENUM_ISOC + m66592->isochronous; @@ -463,7 +463,7 @@ static int alloc_pipe_config(struct m66592_ep *ep, counter = &m66592->isochronous; break; default: - printk(KERN_ERR "unexpect xfer type\n"); + pr_err("unexpect xfer type\n"); return -EINVAL; } ep->type = info.type; @@ -478,7 +478,7 @@ static int alloc_pipe_config(struct m66592_ep *ep, ret = pipe_buffer_setting(m66592, &info); if (ret < 0) { - printk(KERN_ERR "pipe_buffer_setting fail\n"); + pr_err("pipe_buffer_setting fail\n"); return ret; } @@ -614,7 +614,7 @@ static void start_ep0(struct m66592_ep *ep, struct m66592_request *req) control_end(ep->m66592, 0); break; default: - printk(KERN_ERR "start_ep0: unexpect ctsq(%x)\n", ctsq); + pr_err("start_ep0: unexpect ctsq(%x)\n", ctsq); break; } } @@ -748,7 +748,7 @@ static void irq_ep0_write(struct m66592_ep *ep, struct m66592_request *req) do { tmp = m66592_read(m66592, ep->fifoctr); if (i++ > 100000) { - printk(KERN_ERR "pipe0 is busy. maybe cpu i/o bus " + pr_err("pipe0 is busy. maybe cpu i/o bus " "conflict. please power off this controller."); return; } @@ -798,7 +798,7 @@ static void irq_packet_write(struct m66592_ep *ep, struct m66592_request *req) if (unlikely((tmp & M66592_FRDY) == 0)) { pipe_stop(m66592, pipenum); pipe_irq_disable(m66592, pipenum); - printk(KERN_ERR "write fifo not ready. pipnum=%d\n", pipenum); + pr_err("write fifo not ready. pipnum=%d\n", pipenum); return; } @@ -847,7 +847,7 @@ static void irq_packet_read(struct m66592_ep *ep, struct m66592_request *req) req->req.status = -EPIPE; pipe_stop(m66592, pipenum); pipe_irq_disable(m66592, pipenum); - printk(KERN_ERR "read fifo not ready"); + pr_err("read fifo not ready"); return; } @@ -1102,7 +1102,7 @@ static void m66592_update_usb_speed(struct m66592 *m66592) break; default: m66592->gadget.speed = USB_SPEED_UNKNOWN; - printk(KERN_ERR "USB speed unknown\n"); + pr_err("USB speed unknown\n"); } } @@ -1161,7 +1161,7 @@ __acquires(m66592->lock) control_end(m66592, 0); break; default: - printk(KERN_ERR "ctrl_stage: unexpect ctsq(%x)\n", ctsq); + pr_err("ctrl_stage: unexpect ctsq(%x)\n", ctsq); break; } } @@ -1461,13 +1461,13 @@ int usb_gadget_register_driver(struct usb_gadget_driver *driver) retval = device_add(&m66592->gadget.dev); if (retval) { - printk(KERN_ERR "device_add error (%d)\n", retval); + pr_err("device_add error (%d)\n", retval); goto error; } retval = driver->bind (&m66592->gadget); if (retval) { - printk(KERN_ERR "bind to driver error (%d)\n", retval); + pr_err("bind to driver error (%d)\n", retval); device_del(&m66592->gadget.dev); goto error; } @@ -1561,28 +1561,28 @@ static int __init m66592_probe(struct platform_device *pdev) (char *)udc_name); if (!res) { ret = -ENODEV; - printk(KERN_ERR "platform_get_resource_byname error.\n"); + pr_err("platform_get_resource_byname error.\n"); goto clean_up; } irq = platform_get_irq(pdev, 0); if (irq < 0) { ret = -ENODEV; - printk(KERN_ERR "platform_get_irq error.\n"); + pr_err("platform_get_irq error.\n"); goto clean_up; } reg = ioremap(res->start, resource_len(res)); if (reg == NULL) { ret = -ENOMEM; - printk(KERN_ERR "ioremap error.\n"); + pr_err("ioremap error.\n"); goto clean_up; } /* initialize ucd */ m66592 = kzalloc(sizeof(struct m66592), GFP_KERNEL); if (m66592 == NULL) { - printk(KERN_ERR "kzalloc error\n"); + pr_err("kzalloc error\n"); goto clean_up; } @@ -1608,7 +1608,7 @@ static int __init m66592_probe(struct platform_device *pdev) ret = request_irq(irq, m66592_irq, IRQF_DISABLED | IRQF_SHARED, udc_name, m66592); if (ret < 0) { - printk(KERN_ERR "request_irq error (%d)\n", ret); + pr_err("request_irq error (%d)\n", ret); goto clean_up; } 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 { /*-------------------------------------------------------------------------*/ -#ifdef DEBUG -#define DBG(stuff...) printk(KERN_DEBUG "udc: " stuff) -#else -#define DBG(stuff...) do{}while(0) -#endif - #ifdef VERBOSE # define VDBG DBG #else # define VDBG(stuff...) do{}while(0) #endif -#define ERR(stuff...) printk(KERN_ERR "udc: " stuff) -#define WARN(stuff...) printk(KERN_WARNING "udc: " stuff) -#define INFO(stuff...) printk(KERN_INFO "udc: " stuff) +#define ERR(stuff...) pr_err("udc: " stuff) +#define WARN(stuff...) pr_warning("udc: " stuff) +#define INFO(stuff...) pr_info("udc: " stuff) +#define DBG(stuff...) pr_debug("udc: " stuff) /*-------------------------------------------------------------------------*/ diff --git a/drivers/usb/gadget/pxa2xx_udc.c b/drivers/usb/gadget/pxa2xx_udc.c index 3173b39f0bfd..8c139d416ac4 100644 --- a/drivers/usb/gadget/pxa2xx_udc.c +++ b/drivers/usb/gadget/pxa2xx_udc.c @@ -2099,7 +2099,7 @@ static int __init pxa2xx_udc_probe(struct platform_device *pdev) /* insist on Intel/ARM/XScale */ asm("mrc%? p15, 0, %0, c0, c0" : "=r" (chiprev)); if ((chiprev & CP15R0_VENDOR_MASK) != CP15R0_XSCALE_VALUE) { - printk(KERN_ERR "%s: not XScale!\n", driver_name); + pr_err("%s: not XScale!\n", driver_name); return -ENODEV; } @@ -2128,7 +2128,7 @@ static int __init pxa2xx_udc_probe(struct platform_device *pdev) break; #endif default: - printk(KERN_ERR "%s: unrecognized processor: %08x\n", + pr_err("%s: unrecognized processor: %08x\n", driver_name, chiprev); /* iop3xx, ixp4xx, ... */ return -ENODEV; @@ -2199,7 +2199,7 @@ static int __init pxa2xx_udc_probe(struct platform_device *pdev) retval = request_irq(irq, pxa2xx_udc_irq, IRQF_DISABLED, driver_name, dev); if (retval != 0) { - printk(KERN_ERR "%s: can't get irq %d, err %d\n", + pr_err("%s: can't get irq %d, err %d\n", driver_name, irq, retval); goto err_irq1; } @@ -2212,7 +2212,7 @@ static int __init pxa2xx_udc_probe(struct platform_device *pdev) IRQF_DISABLED | IRQF_SAMPLE_RANDOM, driver_name, dev); if (retval != 0) { - printk(KERN_ERR "%s: can't get irq %i, err %d\n", + pr_err("%s: can't get irq %i, err %d\n", driver_name, LUBBOCK_USB_DISC_IRQ, retval); lubbock_fail0: goto err_irq_lub; @@ -2222,7 +2222,7 @@ lubbock_fail0: IRQF_DISABLED | IRQF_SAMPLE_RANDOM, driver_name, dev); if (retval != 0) { - printk(KERN_ERR "%s: can't get irq %i, err %d\n", + pr_err("%s: can't get irq %i, err %d\n", driver_name, LUBBOCK_USB_IRQ, retval); free_irq(LUBBOCK_USB_DISC_IRQ, dev); goto lubbock_fail0; @@ -2235,7 +2235,7 @@ lubbock_fail0: IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING, driver_name, dev); if (retval != 0) { - printk(KERN_ERR "%s: can't get irq %i, err %d\n", + pr_err("%s: can't get irq %i, err %d\n", driver_name, vbus_irq, retval); goto err_vbus_irq; } @@ -2361,7 +2361,7 @@ static struct platform_driver udc_driver = { static int __init udc_init(void) { - printk(KERN_INFO "%s: version %s\n", driver_name, DRIVER_VERSION); + pr_info("%s: version %s\n", driver_name, DRIVER_VERSION); return platform_driver_probe(&udc_driver, pxa2xx_udc_probe); } module_init(udc_init); diff --git a/drivers/usb/gadget/pxa2xx_udc.h b/drivers/usb/gadget/pxa2xx_udc.h index 1db46d705777..97a8c45ccd81 100644 --- a/drivers/usb/gadget/pxa2xx_udc.h +++ b/drivers/usb/gadget/pxa2xx_udc.h @@ -151,6 +151,8 @@ static struct pxa2xx_udc *the_controller; #define DBG_NOISY 3 /* ... even more: request level */ #define DBG_VERY_NOISY 4 /* ... even more: packet level */ +#define DMSG(stuff...) pr_debug("udc: " stuff) + #ifdef DEBUG static const char *state_name[] = { @@ -159,8 +161,6 @@ static const char *state_name[] = { "EP0_END_XFER", "EP0_STALL" }; -#define DMSG(stuff...) printk(KERN_DEBUG "udc: " stuff) - #ifdef VERBOSE # define UDC_DEBUG DBG_VERBOSE #else @@ -241,8 +241,6 @@ dump_state(struct pxa2xx_udc *dev) #else -#define DMSG(stuff...) do{}while(0) - #define dump_udccr(x) do{}while(0) #define dump_udccs0(x) do{}while(0) #define dump_state(x) do{}while(0) @@ -253,8 +251,9 @@ dump_state(struct pxa2xx_udc *dev) #define DBG(lvl, stuff...) do{if ((lvl) <= UDC_DEBUG) DMSG(stuff);}while(0) -#define WARN(stuff...) printk(KERN_WARNING "udc: " stuff) -#define INFO(stuff...) printk(KERN_INFO "udc: " stuff) +#define ERR(stuff...) pr_err("udc: " stuff) +#define WARN(stuff...) pr_warning("udc: " stuff) +#define INFO(stuff...) pr_info("udc: " stuff) #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 @@ */ #if 0 -#define DBG(str,args...) do { \ - if (rndis_debug) \ - printk(KERN_DEBUG str , ## args ); \ - } while (0) static int rndis_debug = 0; - module_param (rndis_debug, int, 0); MODULE_PARM_DESC (rndis_debug, "enable debugging"); - #else - #define rndis_debug 0 -#define DBG(str,args...) do{}while(0) #endif +#define DBG(str,args...) do { \ + if (rndis_debug) \ + pr_debug(str , ## args); \ + } while (0) + #define RNDIS_MAX_CONFIGS 1 @@ -679,7 +676,7 @@ gen_ndis_query_resp (int configNr, u32 OID, u8 *buf, unsigned buf_len, #endif default: - printk (KERN_WARNING "%s: query unknown OID 0x%08X\n", + pr_warning("%s: query unknown OID 0x%08X\n", __FUNCTION__, OID); } if (retval < 0) @@ -804,7 +801,7 @@ update_linkstate: #endif /* RNDIS_PM */ default: - printk (KERN_WARNING "%s: set unknown OID 0x%08X, size %d\n", + pr_warning("%s: set unknown OID 0x%08X, size %d\n", __FUNCTION__, OID, buf_len); } @@ -1126,8 +1123,7 @@ int rndis_msg_parser (u8 configNr, u8 *buf) * In one case those messages seemed to relate to the host * suspending itself. */ - printk (KERN_WARNING - "%s: unknown RNDIS message 0x%08X len %d\n", + pr_warning("%s: unknown RNDIS message 0x%08X len %d\n", __FUNCTION__ , MsgType, MsgLength); { unsigned i; 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; #endif #define gs_debug(format, arg...) \ - do { if (debug) printk(KERN_DEBUG format, ## arg); } while(0) + do { if (debug) pr_debug(format, ## arg); } while (0) #define gs_debug_level(level, format, arg...) \ - do { if (debug>=level) printk(KERN_DEBUG format, ## arg); } while(0) + do { if (debug >= level) pr_debug(format, ## arg); } while (0) /* Thanks to NetChip Technologies for donating this product ID. @@ -553,7 +553,8 @@ static int __init gs_module_init(void) retval = usb_gadget_register_driver(&gs_gadget_driver); if (retval) { - printk(KERN_ERR "gs_module_init: cannot register gadget driver, ret=%d\n", retval); + pr_err("gs_module_init: cannot register gadget driver, " + "ret=%d\n", retval); return retval; } @@ -579,11 +580,13 @@ static int __init gs_module_init(void) if (retval) { usb_gadget_unregister_driver(&gs_gadget_driver); put_tty_driver(gs_tty_driver); - printk(KERN_ERR "gs_module_init: cannot register tty driver, ret=%d\n", retval); + pr_err("gs_module_init: cannot register tty driver, " + "ret=%d\n", retval); return retval; } - printk(KERN_INFO "gs_module_init: %s %s loaded\n", GS_LONG_NAME, GS_VERSION_STR); + pr_info("gs_module_init: %s %s loaded\n", + GS_LONG_NAME, GS_VERSION_STR); return 0; } @@ -598,7 +601,8 @@ static void __exit gs_module_exit(void) put_tty_driver(gs_tty_driver); usb_gadget_unregister_driver(&gs_gadget_driver); - printk(KERN_INFO "gs_module_exit: %s %s unloaded\n", GS_LONG_NAME, GS_VERSION_STR); + pr_info("gs_module_exit: %s %s unloaded\n", + GS_LONG_NAME, GS_VERSION_STR); } /* TTY Driver */ @@ -621,7 +625,7 @@ static int gs_open(struct tty_struct *tty, struct file *file) gs_debug("gs_open: (%d,%p,%p)\n", port_num, tty, file); if (port_num < 0 || port_num >= GS_NUM_PORTS) { - printk(KERN_ERR "gs_open: (%d,%p,%p) invalid port number\n", + pr_err("gs_open: (%d,%p,%p) invalid port number\n", port_num, tty, file); return -ENODEV; } @@ -629,15 +633,14 @@ static int gs_open(struct tty_struct *tty, struct file *file) dev = gs_device; if (dev == NULL) { - printk(KERN_ERR "gs_open: (%d,%p,%p) NULL device pointer\n", + pr_err("gs_open: (%d,%p,%p) NULL device pointer\n", port_num, tty, file); return -ENODEV; } mtx = &gs_open_close_lock[port_num]; if (mutex_lock_interruptible(mtx)) { - printk(KERN_ERR - "gs_open: (%d,%p,%p) interrupted waiting for mutex\n", + pr_err("gs_open: (%d,%p,%p) interrupted waiting for mutex\n", port_num, tty, file); return -ERESTARTSYS; } @@ -645,8 +648,7 @@ static int gs_open(struct tty_struct *tty, struct file *file) spin_lock_irqsave(&dev->dev_lock, flags); if (dev->dev_config == GS_NO_CONFIG_ID) { - printk(KERN_ERR - "gs_open: (%d,%p,%p) device is not connected\n", + pr_err("gs_open: (%d,%p,%p) device is not connected\n", port_num, tty, file); ret = -ENODEV; goto exit_unlock_dev; @@ -655,7 +657,7 @@ static int gs_open(struct tty_struct *tty, struct file *file) port = dev->dev_port[port_num]; if (port == NULL) { - printk(KERN_ERR "gs_open: (%d,%p,%p) NULL port pointer\n", + pr_err("gs_open: (%d,%p,%p) NULL port pointer\n", port_num, tty, file); ret = -ENODEV; goto exit_unlock_dev; @@ -665,7 +667,7 @@ static int gs_open(struct tty_struct *tty, struct file *file) spin_unlock(&dev->dev_lock); if (port->port_dev == NULL) { - printk(KERN_ERR "gs_open: (%d,%p,%p) port disconnected (1)\n", + pr_err("gs_open: (%d,%p,%p) port disconnected (1)\n", port_num, tty, file); ret = -EIO; goto exit_unlock_port; @@ -692,8 +694,7 @@ static int gs_open(struct tty_struct *tty, struct file *file) /* might have been disconnected while asleep, check */ if (port->port_dev == NULL) { - printk(KERN_ERR - "gs_open: (%d,%p,%p) port disconnected (2)\n", + pr_err("gs_open: (%d,%p,%p) port disconnected (2)\n", port_num, tty, file); port->port_in_use = 0; ret = -EIO; @@ -701,7 +702,8 @@ static int gs_open(struct tty_struct *tty, struct file *file) } if ((port->port_write_buf=buf) == NULL) { - printk(KERN_ERR "gs_open: (%d,%p,%p) cannot allocate port write buffer\n", + pr_err("gs_open: (%d,%p,%p) cannot allocate " + "port write buffer\n", port_num, tty, file); port->port_in_use = 0; ret = -ENOMEM; @@ -714,7 +716,7 @@ static int gs_open(struct tty_struct *tty, struct file *file) /* might have been disconnected while asleep, check */ if (port->port_dev == NULL) { - printk(KERN_ERR "gs_open: (%d,%p,%p) port disconnected (3)\n", + pr_err("gs_open: (%d,%p,%p) port disconnected (3)\n", port_num, tty, file); port->port_in_use = 0; ret = -EIO; @@ -762,7 +764,7 @@ static void gs_close(struct tty_struct *tty, struct file *file) struct mutex *mtx; if (port == NULL) { - printk(KERN_ERR "gs_close: NULL port pointer\n"); + pr_err("gs_close: NULL port pointer\n"); return; } @@ -774,8 +776,7 @@ static void gs_close(struct tty_struct *tty, struct file *file) spin_lock_irq(&port->port_lock); if (port->port_open_count == 0) { - printk(KERN_ERR - "gs_close: (%d,%p,%p) port is already closed\n", + pr_err("gs_close: (%d,%p,%p) port is already closed\n", port->port_num, tty, file); goto exit; } @@ -837,7 +838,7 @@ static int gs_write(struct tty_struct *tty, const unsigned char *buf, int count) int ret; if (port == NULL) { - printk(KERN_ERR "gs_write: NULL port pointer\n"); + pr_err("gs_write: NULL port pointer\n"); return -EIO; } @@ -850,14 +851,14 @@ static int gs_write(struct tty_struct *tty, const unsigned char *buf, int count) spin_lock_irqsave(&port->port_lock, flags); if (port->port_dev == NULL) { - printk(KERN_ERR "gs_write: (%d,%p) port is not connected\n", + pr_err("gs_write: (%d,%p) port is not connected\n", port->port_num, tty); ret = -EIO; goto exit; } if (port->port_open_count == 0) { - printk(KERN_ERR "gs_write: (%d,%p) port is closed\n", + pr_err("gs_write: (%d,%p) port is closed\n", port->port_num, tty); ret = -EBADF; goto exit; @@ -888,7 +889,7 @@ static void gs_put_char(struct tty_struct *tty, unsigned char ch) struct gs_port *port = tty->driver_data; if (port == NULL) { - printk(KERN_ERR "gs_put_char: NULL port pointer\n"); + pr_err("gs_put_char: NULL port pointer\n"); return; } @@ -898,13 +899,13 @@ static void gs_put_char(struct tty_struct *tty, unsigned char ch) spin_lock_irqsave(&port->port_lock, flags); if (port->port_dev == NULL) { - printk(KERN_ERR "gs_put_char: (%d,%p) port is not connected\n", + pr_err("gs_put_char: (%d,%p) port is not connected\n", port->port_num, tty); goto exit; } if (port->port_open_count == 0) { - printk(KERN_ERR "gs_put_char: (%d,%p) port is closed\n", + pr_err("gs_put_char: (%d,%p) port is closed\n", port->port_num, tty); goto exit; } @@ -924,7 +925,7 @@ static void gs_flush_chars(struct tty_struct *tty) struct gs_port *port = tty->driver_data; if (port == NULL) { - printk(KERN_ERR "gs_flush_chars: NULL port pointer\n"); + pr_err("gs_flush_chars: NULL port pointer\n"); return; } @@ -933,14 +934,13 @@ static void gs_flush_chars(struct tty_struct *tty) spin_lock_irqsave(&port->port_lock, flags); if (port->port_dev == NULL) { - printk(KERN_ERR - "gs_flush_chars: (%d,%p) port is not connected\n", + pr_err("gs_flush_chars: (%d,%p) port is not connected\n", port->port_num, tty); goto exit; } if (port->port_open_count == 0) { - printk(KERN_ERR "gs_flush_chars: (%d,%p) port is closed\n", + pr_err("gs_flush_chars: (%d,%p) port is closed\n", port->port_num, tty); goto exit; } @@ -1038,7 +1038,7 @@ static int gs_ioctl(struct tty_struct *tty, struct file *file, unsigned int cmd, struct gs_port *port = tty->driver_data; if (port == NULL) { - printk(KERN_ERR "gs_ioctl: NULL port pointer\n"); + pr_err("gs_ioctl: NULL port pointer\n"); return -EIO; } @@ -1076,7 +1076,7 @@ static int gs_send(struct gs_dev *dev) struct gs_req_entry *req_entry; if (dev == NULL) { - printk(KERN_ERR "gs_send: NULL device pointer\n"); + pr_err("gs_send: NULL device pointer\n"); return -ENODEV; } @@ -1103,7 +1103,7 @@ static int gs_send(struct gs_dev *dev) req->length = len; spin_unlock_irqrestore(&dev->dev_lock, flags); if ((ret=usb_ep_queue(ep, req, GFP_ATOMIC))) { - printk(KERN_ERR + pr_err( "gs_send: cannot queue read request, ret=%d\n", ret); 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) port = dev->dev_port[0]; if (port == NULL) { - printk(KERN_ERR - "gs_send_packet: port=%d, NULL port pointer\n", - 0); + pr_err("gs_send_packet: port=%d, NULL port pointer\n", 0); return -EIO; } @@ -1193,7 +1191,7 @@ static int gs_recv_packet(struct gs_dev *dev, char *packet, unsigned int size) port = dev->dev_port[0]; if (port == NULL) { - printk(KERN_ERR "gs_recv_packet: port=%d, NULL port pointer\n", + pr_err("gs_recv_packet: port=%d, NULL port pointer\n", port->port_num); return -EIO; } @@ -1201,7 +1199,7 @@ static int gs_recv_packet(struct gs_dev *dev, char *packet, unsigned int size) spin_lock(&port->port_lock); if (port->port_open_count == 0) { - printk(KERN_ERR "gs_recv_packet: port=%d, port is closed\n", + pr_err("gs_recv_packet: port=%d, port is closed\n", port->port_num); ret = -EIO; goto exit; @@ -1211,14 +1209,14 @@ static int gs_recv_packet(struct gs_dev *dev, char *packet, unsigned int size) tty = port->port_tty; if (tty == NULL) { - printk(KERN_ERR "gs_recv_packet: port=%d, NULL tty pointer\n", + pr_err("gs_recv_packet: port=%d, NULL tty pointer\n", port->port_num); ret = -EIO; goto exit; } if (port->port_tty->magic != TTY_MAGIC) { - printk(KERN_ERR "gs_recv_packet: port=%d, bad tty magic\n", + pr_err("gs_recv_packet: port=%d, bad tty magic\n", port->port_num); ret = -EIO; goto exit; @@ -1245,7 +1243,7 @@ static void gs_read_complete(struct usb_ep *ep, struct usb_request *req) struct gs_dev *dev = ep->driver_data; if (dev == NULL) { - printk(KERN_ERR "gs_read_complete: NULL device pointer\n"); + pr_err("gs_read_complete: NULL device pointer\n"); return; } @@ -1256,7 +1254,7 @@ static void gs_read_complete(struct usb_ep *ep, struct usb_request *req) requeue: req->length = ep->maxpacket; if ((ret=usb_ep_queue(ep, req, GFP_ATOMIC))) { - printk(KERN_ERR + pr_err( "gs_read_complete: cannot queue read request, ret=%d\n", ret); } @@ -1270,7 +1268,7 @@ requeue: default: /* unexpected */ - printk(KERN_ERR + pr_err( "gs_read_complete: unexpected status error, status=%d\n", req->status); goto requeue; @@ -1287,7 +1285,7 @@ static void gs_write_complete(struct usb_ep *ep, struct usb_request *req) struct gs_req_entry *gs_req = req->context; if (dev == NULL) { - printk(KERN_ERR "gs_write_complete: NULL device pointer\n"); + pr_err("gs_write_complete: NULL device pointer\n"); return; } @@ -1296,8 +1294,7 @@ static void gs_write_complete(struct usb_ep *ep, struct usb_request *req) /* normal completion */ requeue: if (gs_req == NULL) { - printk(KERN_ERR - "gs_write_complete: NULL request pointer\n"); + pr_err("gs_write_complete: NULL request pointer\n"); return; } @@ -1316,7 +1313,7 @@ requeue: break; default: - printk(KERN_ERR + pr_err( "gs_write_complete: unexpected status error, status=%d\n", req->status); goto requeue; @@ -1351,7 +1348,7 @@ static int __init gs_bind(struct usb_gadget *gadget) gs_device_desc.bcdDevice = cpu_to_le16(GS_VERSION_NUM | gcnum); else { - printk(KERN_WARNING "gs_bind: controller '%s' not recognized\n", + pr_warning("gs_bind: controller '%s' not recognized\n", gadget->name); /* unrecognized, but safe unless bulk is REALLY quirky */ gs_device_desc.bcdDevice = @@ -1375,7 +1372,7 @@ static int __init gs_bind(struct usb_gadget *gadget) if (use_acm) { ep = usb_ep_autoconfig(gadget, &gs_fullspeed_notify_desc); if (!ep) { - printk(KERN_ERR "gs_bind: cannot run ACM on %s\n", gadget->name); + pr_err("gs_bind: cannot run ACM on %s\n", gadget->name); goto autoconf_fail; } gs_device_desc.idProduct = __constant_cpu_to_le16( @@ -1425,7 +1422,7 @@ static int __init gs_bind(struct usb_gadget *gadget) set_gadget_data(gadget, dev); if ((ret=gs_alloc_ports(dev, GFP_KERNEL)) != 0) { - printk(KERN_ERR "gs_bind: cannot allocate ports\n"); + pr_err("gs_bind: cannot allocate ports\n"); gs_unbind(gadget); return ret; } @@ -1441,13 +1438,13 @@ static int __init gs_bind(struct usb_gadget *gadget) gadget->ep0->driver_data = dev; - printk(KERN_INFO "gs_bind: %s %s bound\n", + pr_info("gs_bind: %s %s bound\n", GS_LONG_NAME, GS_VERSION_STR); return 0; autoconf_fail: - printk(KERN_ERR "gs_bind: cannot autoconfigure on %s\n", gadget->name); + pr_err("gs_bind: cannot autoconfigure on %s\n", gadget->name); return -ENODEV; } @@ -1480,7 +1477,7 @@ static void /* __init_or_exit */ gs_unbind(struct usb_gadget *gadget) set_gadget_data(gadget, NULL); } - printk(KERN_INFO "gs_unbind: %s %s unbound\n", GS_LONG_NAME, + pr_info("gs_unbind: %s %s unbound\n", GS_LONG_NAME, GS_VERSION_STR); } @@ -1513,7 +1510,8 @@ static int gs_setup(struct usb_gadget *gadget, break; default: - printk(KERN_ERR "gs_setup: unknown request, type=%02x, request=%02x, value=%04x, index=%04x, length=%d\n", + pr_err("gs_setup: unknown request, type=%02x, request=%02x, " + "value=%04x, index=%04x, length=%d\n", ctrl->bRequestType, ctrl->bRequest, wValue, wIndex, wLength); break; @@ -1526,7 +1524,7 @@ static int gs_setup(struct usb_gadget *gadget, && (ret % gadget->ep0->maxpacket) == 0; ret = usb_ep_queue(gadget->ep0, req, GFP_ATOMIC); if (ret < 0) { - printk(KERN_ERR "gs_setup: cannot queue response, ret=%d\n", + pr_err("gs_setup: cannot queue response, ret=%d\n", ret); req->status = 0; gs_setup_complete(gadget->ep0, req); @@ -1656,7 +1654,8 @@ set_interface_done: break; default: - printk(KERN_ERR "gs_setup: unknown standard request, type=%02x, request=%02x, value=%04x, index=%04x, length=%d\n", + pr_err("gs_setup: unknown standard request, type=%02x, " + "request=%02x, value=%04x, index=%04x, length=%d\n", ctrl->bRequestType, ctrl->bRequest, wValue, wIndex, wLength); break; @@ -1682,7 +1681,7 @@ static int gs_setup_class(struct usb_gadget *gadget, * handler copy that data to port->port_line_coding (iff * it's valid) and maybe pass it on. Until then, fail. */ - printk(KERN_WARNING "gs_setup: set_line_coding " + pr_warning("gs_setup: set_line_coding " "unuspported\n"); break; @@ -1702,12 +1701,12 @@ static int gs_setup_class(struct usb_gadget *gadget, * handler use that to set the state (iff it's valid) and * maybe pass it on. Until then, fail. */ - printk(KERN_WARNING "gs_setup: set_control_line_state " + pr_warning("gs_setup: set_control_line_state " "unuspported\n"); break; default: - printk(KERN_ERR "gs_setup: unknown class request, " + pr_err("gs_setup: unknown class request, " "type=%02x, request=%02x, value=%04x, " "index=%04x, length=%d\n", ctrl->bRequestType, ctrl->bRequest, @@ -1724,7 +1723,8 @@ static int gs_setup_class(struct usb_gadget *gadget, static void gs_setup_complete(struct usb_ep *ep, struct usb_request *req) { if (req->status || req->actual != req->length) { - printk(KERN_ERR "gs_setup_complete: status error, status=%d, actual=%d, length=%d\n", + pr_err("gs_setup_complete: status error, status=%d, " + "actual=%d, length=%d\n", req->status, req->actual, req->length); } } @@ -1751,11 +1751,11 @@ static void gs_disconnect(struct usb_gadget *gadget) /* re-allocate ports for the next connection */ if (gs_alloc_ports(dev, GFP_ATOMIC) != 0) - printk(KERN_ERR "gs_disconnect: cannot re-allocate ports\n"); + pr_err("gs_disconnect: cannot re-allocate ports\n"); spin_unlock_irqrestore(&dev->dev_lock, flags); - printk(KERN_INFO "gs_disconnect: %s disconnected\n", GS_LONG_NAME); + pr_info("gs_disconnect: %s disconnected\n", GS_LONG_NAME); } /* @@ -1778,7 +1778,7 @@ static int gs_set_config(struct gs_dev *dev, unsigned config) struct gs_req_entry *req_entry; if (dev == NULL) { - printk(KERN_ERR "gs_set_config: NULL device pointer\n"); + pr_err("gs_set_config: NULL device pointer\n"); return 0; } @@ -1823,7 +1823,8 @@ static int gs_set_config(struct gs_dev *dev, unsigned config) dev->dev_notify_ep = ep; dev->dev_notify_ep_desc = ep_desc; } else { - printk(KERN_ERR "gs_set_config: cannot enable notify endpoint %s, ret=%d\n", + pr_err("gs_set_config: cannot enable NOTIFY " + "endpoint %s, ret=%d\n", ep->name, ret); goto exit_reset_config; } @@ -1839,7 +1840,8 @@ static int gs_set_config(struct gs_dev *dev, unsigned config) dev->dev_in_ep = ep; dev->dev_in_ep_desc = ep_desc; } else { - printk(KERN_ERR "gs_set_config: cannot enable in endpoint %s, ret=%d\n", + pr_err("gs_set_config: cannot enable IN " + "endpoint %s, ret=%d\n", ep->name, ret); goto exit_reset_config; } @@ -1855,7 +1857,8 @@ static int gs_set_config(struct gs_dev *dev, unsigned config) dev->dev_out_ep = ep; dev->dev_out_ep_desc = ep_desc; } else { - printk(KERN_ERR "gs_set_config: cannot enable out endpoint %s, ret=%d\n", + pr_err("gs_set_config: cannot enable OUT " + "endpoint %s, ret=%d\n", ep->name, ret); goto exit_reset_config; } @@ -1865,7 +1868,7 @@ static int gs_set_config(struct gs_dev *dev, unsigned config) if (dev->dev_in_ep == NULL || dev->dev_out_ep == NULL || (config != GS_BULK_CONFIG_ID && dev->dev_notify_ep == NULL)) { - printk(KERN_ERR "gs_set_config: cannot find endpoints\n"); + pr_err("gs_set_config: cannot find endpoints\n"); ret = -ENODEV; goto exit_reset_config; } @@ -1876,11 +1879,12 @@ static int gs_set_config(struct gs_dev *dev, unsigned config) if ((req=gs_alloc_req(ep, ep->maxpacket, GFP_ATOMIC))) { req->complete = gs_read_complete; if ((ret=usb_ep_queue(ep, req, GFP_ATOMIC))) { - printk(KERN_ERR "gs_set_config: cannot queue read request, ret=%d\n", - ret); + pr_err("gs_set_config: cannot queue read " + "request, ret=%d\n", ret); } } else { - printk(KERN_ERR "gs_set_config: cannot allocate read requests\n"); + pr_err("gs_set_config: cannot allocate " + "read requests\n"); ret = -ENOMEM; goto exit_reset_config; } @@ -1893,13 +1897,14 @@ static int gs_set_config(struct gs_dev *dev, unsigned config) req_entry->re_req->complete = gs_write_complete; list_add(&req_entry->re_entry, &dev->dev_req_list); } else { - printk(KERN_ERR "gs_set_config: cannot allocate write requests\n"); + pr_err("gs_set_config: cannot allocate " + "write requests\n"); ret = -ENOMEM; goto exit_reset_config; } } - printk(KERN_INFO "gs_set_config: %s configured, %s speed %s config\n", + pr_info("gs_set_config: %s configured, %s speed %s config\n", GS_LONG_NAME, gadget->speed == USB_SPEED_HIGH ? "high" : "full", config == GS_BULK_CONFIG_ID ? "BULK" : "CDC-ACM"); @@ -1926,7 +1931,7 @@ static void gs_reset_config(struct gs_dev *dev) struct gs_req_entry *req_entry; if (dev == NULL) { - printk(KERN_ERR "gs_reset_config: NULL device pointer\n"); + pr_err("gs_reset_config: NULL device pointer\n"); return; } 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) ep = usb_ep_autoconfig (gadget, &fs_source_desc); if (!ep) { autoconf_fail: - printk (KERN_ERR "%s: can't autoconfigure on %s\n", + pr_err("%s: can't autoconfigure on %s\n", shortname, gadget->name); return -ENODEV; } @@ -1139,7 +1139,7 @@ autoconf_fail: * things like configuration and altsetting numbering * can need hardware-specific attention though. */ - printk (KERN_WARNING "%s: controller '%s' not recognized\n", + pr_warning("%s: controller '%s' not recognized\n", shortname, gadget->name); device_desc.bcdDevice = __constant_cpu_to_le16 (0x9999); } -- cgit v1.2.3 From f0fbd5b9ba893b965b2892c1971e3433092b98c7 Mon Sep 17 00:00:00 2001 From: Sarah Sharp Date: Tue, 13 Nov 2007 17:10:09 -0800 Subject: USB: Prepare serial core for autosuspend. Claim the interface for a USB to serial converter when the tty is open, and release the interface when the tty is closed. If a driver doesn't provide a resume function, use the generic resume instead. Make sure the generic resume function does not submit the URBs if we're coming back from autosuspend. On autoresume, we know that the open function will be called next, which will attempt to submit the URBs. If we submit them in the resume function, the open will fail. This works for: - autosuspend - suspending with the tty open or closed - hibernate with the tty closed A hibernate (or a suspend that causes the USB subsystem to lose power) has issues. If you have the tty open when you hibernate, a new tty will be created when the device re-enumerates during resume. Signed-off-by: Sarah Sharp Signed-off-by: Greg Kroah-Hartman --- drivers/usb/serial/generic.c | 8 ++++++++ drivers/usb/serial/usb-serial.c | 12 ++++++++++-- 2 files changed, 18 insertions(+), 2 deletions(-) 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) struct usb_serial_port *port; int i, c = 0, r; +#ifdef CONFIG_PM + /* + * If this is an autoresume, don't submit URBs. + * They will be submitted in the open function instead. + */ + if (serial->dev->auto_pm) + return 0; +#endif for (i = 0; i < serial->num_ports; i++) { port = serial->port[i]; if (port->open_count && port->read_urb) { diff --git a/drivers/usb/serial/usb-serial.c b/drivers/usb/serial/usb-serial.c index 5c33e2471be8..28315b05c9cc 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) goto bailout_mutex_unlock; } + retval = usb_autopm_get_interface(serial->interface); + if (retval) + goto bailout_module_put; /* only call the device specific open if this * is the first time the port is opened */ retval = serial->type->open(port, filp); if (retval) - goto bailout_module_put; + goto bailout_interface_put; } mutex_unlock(&port->mutex); return 0; +bailout_interface_put: + usb_autopm_put_interface(serial->interface); bailout_module_put: module_put(serial->type->driver.owner); bailout_mutex_unlock: @@ -277,8 +282,10 @@ static void serial_close(struct tty_struct *tty, struct file * filp) } } - if (port->open_count == 0) + if (port->open_count == 0) { + usb_autopm_put_interface(port->serial->interface); module_put(port->serial->type->driver.owner); + } mutex_unlock(&port->mutex); usb_serial_put(port->serial); @@ -1255,6 +1262,7 @@ static void fixup_generic(struct usb_serial_driver *device) set_to_generic_if_null(device, read_bulk_callback); set_to_generic_if_null(device, write_bulk_callback); set_to_generic_if_null(device, shutdown); + set_to_generic_if_null(device, resume); } int usb_serial_register(struct usb_serial_driver *driver) /* must be called with BKL held */ -- cgit v1.2.3 From 7b62cc86689e721f0aae87e88cb04ca841cf6c38 Mon Sep 17 00:00:00 2001 From: Andre Haupt Date: Tue, 20 Nov 2007 11:41:37 +0100 Subject: USB: cyberjack: remove a unnecessary variable. This also fixes a sparse warning that symbol 'result' shadows an earlier one. Signed-off-by: Andre Haupt Signed-off-by: Greg Kroah-Hartman --- drivers/usb/serial/cyberjack.c | 1 - 1 file changed, 1 deletion(-) 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 ) /* React only to interrupts signaling a bulk_in transfer */ if( (urb->actual_length==4) && (data[0]==0x01) ) { short old_rdtodo; - int result; /* This is a announcement of coming bulk_ins. */ unsigned short size = ((unsigned short)data[3]<<8)+data[2]+3; -- cgit v1.2.3 From eb0be47dbbdca133b1b94adc564297f25176b3ab Mon Sep 17 00:00:00 2001 From: Patrik Sevallius Date: Tue, 20 Nov 2007 09:32:00 -0800 Subject: USB: usb peripheral controller driver oops avoidance I'm having problem with oopses when rebooting, if I modprobe g_serial and rmmod g_serial and do a reboot I get an oops in device_shutdown(). The reason seems to be that usb_gadget_unregister_driver() doesn't do enough cleanup. With this at91_udc patch I don't get the oops. Signed-off-by: Patrik Sevallius [ Same bug was in other peripheral controller drivers; fixed ] Signed-off-by: David Brownell Signed-off-by: Greg Kroah-Hartman --- drivers/usb/gadget/amd5536udc.c | 1 + drivers/usb/gadget/at91_udc.c | 2 ++ drivers/usb/gadget/goku_udc.c | 1 + drivers/usb/gadget/lh7a40x_udc.c | 1 + drivers/usb/gadget/m66592-udc.c | 1 + drivers/usb/gadget/pxa2xx_udc.c | 1 + 6 files changed, 7 insertions(+) diff --git a/drivers/usb/gadget/amd5536udc.c b/drivers/usb/gadget/amd5536udc.c index 66e10da8a490..b663f23f2642 100644 --- a/drivers/usb/gadget/amd5536udc.c +++ b/drivers/usb/gadget/amd5536udc.c @@ -2038,6 +2038,7 @@ int usb_gadget_unregister_driver(struct usb_gadget_driver *driver) spin_unlock_irqrestore(&dev->lock, flags); driver->unbind(&dev->gadget); + dev->gadget.dev.driver = NULL; dev->driver = NULL; /* set SD */ diff --git a/drivers/usb/gadget/at91_udc.c b/drivers/usb/gadget/at91_udc.c index cd62b029d176..4b6ed353ae36 100644 --- a/drivers/usb/gadget/at91_udc.c +++ b/drivers/usb/gadget/at91_udc.c @@ -1616,6 +1616,8 @@ int usb_gadget_unregister_driver (struct usb_gadget_driver *driver) local_irq_enable(); driver->unbind(&udc->gadget); + udc->gadget.dev.driver = NULL; + udc->gadget.dev.driver_data = NULL; udc->driver = NULL; DBG("unbound from %s\n", driver->driver.name); 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) spin_unlock_irqrestore(&dev->lock, flags); driver->unbind(&dev->gadget); + dev->gadget.dev.driver = NULL; DBG(dev, "unregistered driver '%s'\n", driver->driver.name); return 0; 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) spin_unlock_irqrestore(&dev->lock, flags); driver->unbind(&dev->gadget); + dev->gadget.dev.driver = NULL; device_del(&dev->gadget.dev); udc_disable(dev); diff --git a/drivers/usb/gadget/m66592-udc.c b/drivers/usb/gadget/m66592-udc.c index 43f02189dc44..835948f0715a 100644 --- a/drivers/usb/gadget/m66592-udc.c +++ b/drivers/usb/gadget/m66592-udc.c @@ -1508,6 +1508,7 @@ int usb_gadget_unregister_driver(struct usb_gadget_driver *driver) m66592_bclr(m66592, M66592_VBSE | M66592_URST, M66592_INTENB0); driver->unbind(&m66592->gadget); + m66592->gadget.dev.driver = NULL; init_controller(m66592); disable_controller(m66592); diff --git a/drivers/usb/gadget/pxa2xx_udc.c b/drivers/usb/gadget/pxa2xx_udc.c index 8c139d416ac4..4abf9d26d615 100644 --- a/drivers/usb/gadget/pxa2xx_udc.c +++ b/drivers/usb/gadget/pxa2xx_udc.c @@ -1345,6 +1345,7 @@ int usb_gadget_unregister_driver(struct usb_gadget_driver *driver) local_irq_enable(); driver->unbind(&dev->gadget); + dev->gadget.dev.driver = NULL; dev->driver = NULL; device_del (&dev->gadget.dev); -- cgit v1.2.3 From 90da096ee46b682011b7d549e52b81cf9742e60b Mon Sep 17 00:00:00 2001 From: Balaji Rao Date: Thu, 22 Nov 2007 01:58:14 +0530 Subject: USB: force handover port to companion when hub_port_connect_change fails This patch hands over the port to the companion when the hub_port_connect_change fails. Signed-off-by: Balaji Rao Signed-off-by: Alan Stern Signed-off-by: Greg Kroah-Hartman --- drivers/usb/core/hcd.h | 3 ++ drivers/usb/core/hub.c | 3 ++ drivers/usb/host/ehci-au1xxx.c | 1 + drivers/usb/host/ehci-fsl.c | 1 + drivers/usb/host/ehci-hub.c | 68 ++++++++++++++++++++++++++--------------- drivers/usb/host/ehci-pci.c | 1 + drivers/usb/host/ehci-ppc-soc.c | 1 + drivers/usb/host/ehci-ps3.c | 1 + 8 files changed, 55 insertions(+), 24 deletions(-) diff --git a/drivers/usb/core/hcd.h b/drivers/usb/core/hcd.h index 98e24194a4ab..080298ad5990 100644 --- a/drivers/usb/core/hcd.h +++ b/drivers/usb/core/hcd.h @@ -210,6 +210,9 @@ struct hc_driver { int (*start_port_reset)(struct usb_hcd *, unsigned port_num); void (*hub_irq_enable)(struct usb_hcd *); /* Needed only if port-change IRQs are level-triggered */ + + /* force handover of high-speed port to full-speed companion */ + void (*relinquish_port)(struct usb_hcd *, int); }; extern int usb_hcd_link_urb_to_ep(struct usb_hcd *hcd, struct urb *urb); diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c index 1b17f636f49c..24c411697d1e 100644 --- a/drivers/usb/core/hub.c +++ b/drivers/usb/core/hub.c @@ -2482,6 +2482,7 @@ static void hub_port_connect_change(struct usb_hub *hub, int port1, { struct usb_device *hdev = hub->hdev; struct device *hub_dev = hub->intfdev; + struct usb_hcd *hcd = bus_to_hcd(hdev->bus); u16 wHubCharacteristics = le16_to_cpu(hub->descriptor->wHubCharacteristics); int status, i; @@ -2645,6 +2646,8 @@ loop: done: hub_port_disable(hub, port1, 1); + if (hcd->driver->relinquish_port && !hub->hdev->parent) + hcd->driver->relinquish_port(hcd, port1); } static void hub_events(void) 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 = { .hub_control = ehci_hub_control, .bus_suspend = ehci_bus_suspend, .bus_resume = ehci_bus_resume, + .relinquish_port = ehci_relinquish_port, }; /*-------------------------------------------------------------------------*/ diff --git a/drivers/usb/host/ehci-fsl.c b/drivers/usb/host/ehci-fsl.c index 430821cb95c8..f35795fbd896 100644 --- a/drivers/usb/host/ehci-fsl.c +++ b/drivers/usb/host/ehci-fsl.c @@ -323,6 +323,7 @@ static const struct hc_driver ehci_fsl_hc_driver = { .hub_control = ehci_hub_control, .bus_suspend = ehci_bus_suspend, .bus_resume = ehci_bus_resume, + .relinquish_port = ehci_relinquish_port, }; static int ehci_fsl_drv_probe(struct platform_device *pdev) diff --git a/drivers/usb/host/ehci-hub.c b/drivers/usb/host/ehci-hub.c index 1ad7a6572826..a165e0a0961c 100644 --- a/drivers/usb/host/ehci-hub.c +++ b/drivers/usb/host/ehci-hub.c @@ -314,41 +314,21 @@ static ssize_t show_companion(struct device *dev, } /* - * Dedicate or undedicate a port to the companion controller. - * Syntax is "[-]portnum", where a leading '-' sign means - * return control of the port to the EHCI controller. + * Sets the owner of a port */ -static ssize_t store_companion(struct device *dev, - struct device_attribute *attr, - const char *buf, size_t count) +static void set_owner(struct ehci_hcd *ehci, int portnum, int new_owner) { - struct ehci_hcd *ehci; - int portnum, new_owner, try; u32 __iomem *status_reg; u32 port_status; + int try; - ehci = hcd_to_ehci(bus_to_hcd(dev_get_drvdata(dev))); - new_owner = PORT_OWNER; /* Owned by companion */ - if (sscanf(buf, "%d", &portnum) != 1) - return -EINVAL; - if (portnum < 0) { - portnum = - portnum; - new_owner = 0; /* Owned by EHCI */ - } - if (portnum <= 0 || portnum > HCS_N_PORTS(ehci->hcs_params)) - return -ENOENT; - status_reg = &ehci->regs->port_status[--portnum]; - if (new_owner) - set_bit(portnum, &ehci->companion_ports); - else - clear_bit(portnum, &ehci->companion_ports); + status_reg = &ehci->regs->port_status[portnum]; /* * The controller won't set the OWNER bit if the port is * enabled, so this loop will sometimes require at least two * iterations: one to disable the port and one to set OWNER. */ - for (try = 4; try > 0; --try) { spin_lock_irq(&ehci->lock); port_status = ehci_readl(ehci, status_reg); @@ -365,6 +345,36 @@ static ssize_t store_companion(struct device *dev, if (try > 1) msleep(5); } +} + +/* + * Dedicate or undedicate a port to the companion controller. + * Syntax is "[-]portnum", where a leading '-' sign means + * return control of the port to the EHCI controller. + */ +static ssize_t store_companion(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t count) +{ + struct ehci_hcd *ehci; + int portnum, new_owner; + + ehci = hcd_to_ehci(bus_to_hcd(dev_get_drvdata(dev))); + new_owner = PORT_OWNER; /* Owned by companion */ + if (sscanf(buf, "%d", &portnum) != 1) + return -EINVAL; + if (portnum < 0) { + portnum = - portnum; + new_owner = 0; /* Owned by EHCI */ + } + if (portnum <= 0 || portnum > HCS_N_PORTS(ehci->hcs_params)) + return -ENOENT; + portnum--; + if (new_owner) + set_bit(portnum, &ehci->companion_ports); + else + clear_bit(portnum, &ehci->companion_ports); + set_owner(ehci, portnum, new_owner); return count; } static DEVICE_ATTR(companion, 0644, show_companion, store_companion); @@ -867,3 +877,13 @@ error: spin_unlock_irqrestore (&ehci->lock, flags); return retval; } + +static void ehci_relinquish_port(struct usb_hcd *hcd, int portnum) +{ + struct ehci_hcd *ehci = hcd_to_ehci(hcd); + + if (ehci_is_TDI(ehci)) + return; + set_owner(ehci, --portnum, PORT_OWNER); +} + diff --git a/drivers/usb/host/ehci-pci.c b/drivers/usb/host/ehci-pci.c index ad0d4965f2fb..45e040000280 100644 --- a/drivers/usb/host/ehci-pci.c +++ b/drivers/usb/host/ehci-pci.c @@ -364,6 +364,7 @@ static const struct hc_driver ehci_pci_hc_driver = { .hub_control = ehci_hub_control, .bus_suspend = ehci_bus_suspend, .bus_resume = ehci_bus_resume, + .relinquish_port = ehci_relinquish_port, }; /*-------------------------------------------------------------------------*/ 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 = { .hub_control = ehci_hub_control, .bus_suspend = ehci_bus_suspend, .bus_resume = ehci_bus_resume, + .relinquish_port = ehci_relinquish_port, }; static 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 = { .bus_suspend = ehci_bus_suspend, .bus_resume = ehci_bus_resume, #endif + .relinquish_port = ehci_relinquish_port, }; static int ps3_ehci_probe(struct ps3_system_bus_device *dev) -- cgit v1.2.3 From 5933101718ea3d283983a923c5524c88138e5564 Mon Sep 17 00:00:00 2001 From: Alan Stern Date: Tue, 20 Nov 2007 16:28:55 -0500 Subject: USB: dummy_hcd: don't register drivers on the platform bus This patch (as1017) makes dummy_hcd behave more like the other USB peripheral controller drivers by no longer registering its gadget driver on the platform bus. Doing that has always been a mistake, since a usb_gadget_driver isn't a platform_driver. Instead the gadget driver is left unregistered in sysfs. Signed-off-by: Alan Stern CC: David Brownell Signed-off-by: Greg Kroah-Hartman --- drivers/usb/gadget/dummy_hcd.c | 33 ++++++++------------------------- 1 file changed, 8 insertions(+), 25 deletions(-) diff --git a/drivers/usb/gadget/dummy_hcd.c b/drivers/usb/gadget/dummy_hcd.c index 9db2482bdfa2..1a8a5f33443e 100644 --- a/drivers/usb/gadget/dummy_hcd.c +++ b/drivers/usb/gadget/dummy_hcd.c @@ -772,18 +772,17 @@ usb_gadget_register_driver (struct usb_gadget_driver *driver) list_del_init (&dum->ep [0].ep.ep_list); INIT_LIST_HEAD(&dum->fifo_req.queue); + driver->driver.bus = NULL; dum->driver = driver; dum->gadget.dev.driver = &driver->driver; dev_dbg (udc_dev(dum), "binding gadget driver '%s'\n", driver->driver.name); - if ((retval = driver->bind (&dum->gadget)) != 0) - goto err_bind_gadget; - - driver->driver.bus = dum->gadget.dev.parent->bus; - if ((retval = driver_register (&driver->driver)) != 0) - goto err_register; - if ((retval = device_bind_driver (&dum->gadget.dev)) != 0) - goto err_bind_driver; + retval = driver->bind(&dum->gadget); + if (retval) { + dum->driver = NULL; + dum->gadget.dev.driver = NULL; + return retval; + } /* khubd will enumerate this in a while */ spin_lock_irq (&dum->lock); @@ -793,20 +792,6 @@ usb_gadget_register_driver (struct usb_gadget_driver *driver) usb_hcd_poll_rh_status (dummy_to_hcd (dum)); return 0; - -err_bind_driver: - driver_unregister (&driver->driver); -err_register: - if (driver->unbind) - driver->unbind (&dum->gadget); - spin_lock_irq (&dum->lock); - dum->pullup = 0; - set_link_state (dum); - spin_unlock_irq (&dum->lock); -err_bind_gadget: - dum->driver = NULL; - dum->gadget.dev.driver = NULL; - return retval; } EXPORT_SYMBOL (usb_gadget_register_driver); @@ -830,11 +815,9 @@ usb_gadget_unregister_driver (struct usb_gadget_driver *driver) spin_unlock_irqrestore (&dum->lock, flags); driver->unbind (&dum->gadget); + dum->gadget.dev.driver = NULL; dum->driver = NULL; - device_release_driver (&dum->gadget.dev); - driver_unregister (&driver->driver); - spin_lock_irqsave (&dum->lock, flags); dum->pullup = 0; set_link_state (dum); -- cgit v1.2.3 From f2a383e4de50ad9c03676e57703a97d081798e55 Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Mon, 26 Nov 2007 22:11:55 -0800 Subject: USB: always announce a device has been added to the system Distros (like SuSE) want to know this information, to make it easier to handle support issues. Might as well let everyone benefit from this. This is also enabled whenever CONFIG_USB_DEBUG is enabled, to help with debugging. Signed-off-by: Greg Kroah-Hartman --- drivers/usb/core/Kconfig | 15 +++++++++++++++ drivers/usb/core/hub.c | 36 ++++++++++++++++++++++++------------ 2 files changed, 39 insertions(+), 12 deletions(-) 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 of debug messages to the system log. Select this if you are having a problem with USB support and want to see more of what is going on. +config USB_ANNOUNCE_NEW_DEVICES + bool "USB announce new devices" + depends on USB + default N + help + Say Y here if you want the USB core to always announce the + idVendor, idProduct, Manufacturer, Product, and SerialNumber + strings for every new USB device to the syslog. This option is + usually used by distro vendors to help with debugging and to + let users know what specific device was added to the machine + in what location. + + If you do not want this kind of information sent to the system + log, or have any doubts about this, say N here. + comment "Miscellaneous USB options" depends on USB diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c index 24c411697d1e..f7c2219c800f 100644 --- a/drivers/usb/core/hub.c +++ b/drivers/usb/core/hub.c @@ -37,6 +37,13 @@ #define USB_PERSIST 0 #endif +/* if we are in debug mode, always announce new devices */ +#ifdef DEBUG +#ifndef CONFIG_USB_ANNOUNCE_NEW_DEVICES +#define CONFIG_USB_ANNOUNCE_NEW_DEVICES +#endif +#endif + struct usb_hub { struct device *intfdev; /* the "interface" device */ struct usb_device *hdev; @@ -1207,7 +1214,7 @@ void usb_disconnect(struct usb_device **pdev) put_device(&udev->dev); } -#ifdef DEBUG +#ifdef CONFIG_USB_ANNOUNCE_NEW_DEVICES static void show_string(struct usb_device *udev, char *id, char *string) { if (!string) @@ -1215,12 +1222,24 @@ static void show_string(struct usb_device *udev, char *id, char *string) dev_printk(KERN_INFO, &udev->dev, "%s: %s\n", id, string); } +static void announce_device(struct usb_device *udev) +{ + dev_info(&udev->dev, "New USB device found, idVendor=%04x, idProduct=%04x\n", + le16_to_cpu(udev->descriptor.idVendor), + le16_to_cpu(udev->descriptor.idProduct)); + dev_info(&udev->dev, "New USB device strings: Mfr=%d, Product=%d, " + "SerialNumber=%d\n", + udev->descriptor.iManufacturer, + udev->descriptor.iProduct, + udev->descriptor.iSerialNumber); + show_string(udev, "Product", udev->product); + show_string(udev, "Manufacturer", udev->manufacturer); + show_string(udev, "SerialNumber", udev->serial); +} #else -static inline void show_string(struct usb_device *udev, char *id, char *string) -{} +static inline void announce_device(struct usb_device *udev) { } #endif - #ifdef CONFIG_USB_OTG #include "otg_whitelist.h" #endif @@ -1390,14 +1409,7 @@ int usb_new_device(struct usb_device *udev) } /* Tell the world! */ - dev_dbg(&udev->dev, "new device strings: Mfr=%d, Product=%d, " - "SerialNumber=%d\n", - udev->descriptor.iManufacturer, - udev->descriptor.iProduct, - udev->descriptor.iSerialNumber); - show_string(udev, "Product", udev->product); - show_string(udev, "Manufacturer", udev->manufacturer); - show_string(udev, "SerialNumber", udev->serial); + announce_device(udev); return err; fail: -- cgit v1.2.3 From 684c19e0d95f4640998a358a34226115a34b5eea Mon Sep 17 00:00:00 2001 From: Tony Jones Date: Tue, 11 Sep 2007 14:07:31 -0700 Subject: USB: convert ohci debug files to use debugfs instead of sysfs We should not have multiple line files in sysfs, this moves the data to debugfs instead, like the UHCI driver. Signed-off-by: Tony Jones Cc: Kay Sievers Cc: David Brownell Signed-off-by: Greg Kroah-Hartman --- drivers/usb/host/ohci-dbg.c | 213 ++++++++++++++++++++++++++++++++++++++------ drivers/usb/host/ohci-hcd.c | 18 ++++ drivers/usb/host/ohci.h | 7 ++ 3 files changed, 209 insertions(+), 29 deletions(-) diff --git a/drivers/usb/host/ohci-dbg.c b/drivers/usb/host/ohci-dbg.c index 9bd589806245..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) { } #else +static int debug_async_open(struct inode *, struct file *); +static int debug_periodic_open(struct inode *, struct file *); +static int debug_registers_open(struct inode *, struct file *); +static int debug_async_open(struct inode *, struct file *); +static ssize_t debug_output(struct file*, char __user*, size_t, loff_t*); +static int debug_close(struct inode *, struct file *); + +static const struct file_operations debug_async_fops = { + .owner = THIS_MODULE, + .open = debug_async_open, + .read = debug_output, + .release = debug_close, +}; +static const struct file_operations debug_periodic_fops = { + .owner = THIS_MODULE, + .open = debug_periodic_open, + .read = debug_output, + .release = debug_close, +}; +static const struct file_operations debug_registers_fops = { + .owner = THIS_MODULE, + .open = debug_registers_open, + .read = debug_output, + .release = debug_close, +}; + +static struct dentry *ohci_debug_root; + +struct debug_buffer { + ssize_t (*fill_func)(struct debug_buffer *); /* fill method */ + struct device *dev; + struct mutex mutex; /* protect filling of buffer */ + size_t count; /* number of characters filled into buffer */ + char *page; +}; + static ssize_t show_list (struct ohci_hcd *ohci, char *buf, size_t count, struct ed *ed) { @@ -467,8 +503,7 @@ show_list (struct ohci_hcd *ohci, char *buf, size_t count, struct ed *ed) return count - size; } -static ssize_t -show_async(struct device *dev, struct device_attribute *attr, char *buf) +static ssize_t fill_async_buffer(struct debug_buffer *buf) { struct usb_bus *bus; struct usb_hcd *hcd; @@ -476,25 +511,23 @@ show_async(struct device *dev, struct device_attribute *attr, char *buf) size_t temp; unsigned long flags; - bus = dev_get_drvdata(dev); + bus = dev_get_drvdata(buf->dev); hcd = bus_to_hcd(bus); ohci = hcd_to_ohci(hcd); /* display control and bulk lists together, for simplicity */ spin_lock_irqsave (&ohci->lock, flags); - temp = show_list (ohci, buf, PAGE_SIZE, ohci->ed_controltail); - temp += show_list (ohci, buf + temp, PAGE_SIZE - temp, ohci->ed_bulktail); + temp = show_list(ohci, buf->page, buf->count, ohci->ed_controltail); + temp += show_list(ohci, buf->page + temp, buf->count - temp, + ohci->ed_bulktail); spin_unlock_irqrestore (&ohci->lock, flags); return temp; } -static DEVICE_ATTR(async, S_IRUGO, show_async, NULL); - #define DBG_SCHED_LIMIT 64 -static ssize_t -show_periodic(struct device *dev, struct device_attribute *attr, char *buf) +static ssize_t fill_periodic_buffer(struct debug_buffer *buf) { struct usb_bus *bus; struct usb_hcd *hcd; @@ -509,10 +542,10 @@ show_periodic(struct device *dev, struct device_attribute *attr, char *buf) return 0; seen_count = 0; - bus = dev_get_drvdata(dev); + bus = (struct usb_bus *)dev_get_drvdata(buf->dev); hcd = bus_to_hcd(bus); ohci = hcd_to_ohci(hcd); - next = buf; + next = buf->page; size = PAGE_SIZE; temp = scnprintf (next, size, "size = %d\n", NUM_INTS); @@ -589,13 +622,9 @@ show_periodic(struct device *dev, struct device_attribute *attr, char *buf) return PAGE_SIZE - size; } -static DEVICE_ATTR(periodic, S_IRUGO, show_periodic, NULL); - - #undef DBG_SCHED_LIMIT -static ssize_t -show_registers(struct device *dev, struct device_attribute *attr, char *buf) +static ssize_t fill_registers_buffer(struct debug_buffer *buf) { struct usb_bus *bus; struct usb_hcd *hcd; @@ -606,11 +635,11 @@ show_registers(struct device *dev, struct device_attribute *attr, char *buf) char *next; u32 rdata; - bus = dev_get_drvdata(dev); + bus = (struct usb_bus *)dev_get_drvdata(buf->dev); hcd = bus_to_hcd(bus); ohci = hcd_to_ohci(hcd); regs = ohci->regs; - next = buf; + next = buf->page; size = PAGE_SIZE; spin_lock_irqsave (&ohci->lock, flags); @@ -677,29 +706,155 @@ show_registers(struct device *dev, struct device_attribute *attr, char *buf) done: spin_unlock_irqrestore (&ohci->lock, flags); + return PAGE_SIZE - size; } -static DEVICE_ATTR(registers, S_IRUGO, show_registers, NULL); +static struct debug_buffer *alloc_buffer(struct device *dev, + ssize_t (*fill_func)(struct debug_buffer *)) +{ + struct debug_buffer *buf; + + buf = kzalloc(sizeof(struct debug_buffer), GFP_KERNEL); + if (buf) { + buf->dev = dev; + buf->fill_func = fill_func; + mutex_init(&buf->mutex); + } + + return buf; +} + +static int fill_buffer(struct debug_buffer *buf) +{ + int ret = 0; + + if (!buf->page) + buf->page = (char *)get_zeroed_page(GFP_KERNEL); + + if (!buf->page) { + ret = -ENOMEM; + goto out; + } + + ret = buf->fill_func(buf); + + if (ret >= 0) { + buf->count = ret; + ret = 0; + } + +out: + return ret; +} + +static ssize_t debug_output(struct file *file, char __user *user_buf, + size_t len, loff_t *offset) +{ + struct debug_buffer *buf = file->private_data; + int ret = 0; + + mutex_lock(&buf->mutex); + if (buf->count == 0) { + ret = fill_buffer(buf); + if (ret != 0) { + mutex_unlock(&buf->mutex); + goto out; + } + } + mutex_unlock(&buf->mutex); + + ret = simple_read_from_buffer(user_buf, len, offset, + buf->page, buf->count); + +out: + return ret; + +} + +static int debug_close(struct inode *inode, struct file *file) +{ + struct debug_buffer *buf = file->private_data; + + if (buf) { + if (buf->page) + free_page((unsigned long)buf->page); + kfree(buf); + } + + return 0; +} +static int debug_async_open(struct inode *inode, struct file *file) +{ + file->private_data = alloc_buffer(inode->i_private, fill_async_buffer); + + return file->private_data ? 0 : -ENOMEM; +} + +static int debug_periodic_open(struct inode *inode, struct file *file) +{ + file->private_data = alloc_buffer(inode->i_private, + fill_periodic_buffer); + + return file->private_data ? 0 : -ENOMEM; +} + +static int debug_registers_open(struct inode *inode, struct file *file) +{ + file->private_data = alloc_buffer(inode->i_private, + fill_registers_buffer); + + return file->private_data ? 0 : -ENOMEM; +} static inline void create_debug_files (struct ohci_hcd *ohci) { - struct device *dev = ohci_to_hcd(ohci)->self.dev; - int retval; + struct usb_bus *bus = &ohci_to_hcd(ohci)->self; + struct device *dev = bus->dev; + + ohci->debug_dir = debugfs_create_dir(bus->bus_name, ohci_debug_root); + if (!ohci->debug_dir) + goto dir_error; + + ohci->debug_async = debugfs_create_file("async", S_IRUGO, + ohci->debug_dir, dev, + &debug_async_fops); + if (!ohci->debug_async) + goto async_error; + + ohci->debug_periodic = debugfs_create_file("periodic", S_IRUGO, + ohci->debug_dir, dev, + &debug_periodic_fops); + if (!ohci->debug_periodic) + goto periodic_error; + + ohci->debug_registers = debugfs_create_file("registers", S_IRUGO, + ohci->debug_dir, dev, + &debug_registers_fops); + if (!ohci->debug_registers) + goto registers_error; - retval = device_create_file(dev, &dev_attr_async); - retval = device_create_file(dev, &dev_attr_periodic); - retval = device_create_file(dev, &dev_attr_registers); ohci_dbg (ohci, "created debug files\n"); + return; + +registers_error: + debugfs_remove(ohci->debug_periodic); +periodic_error: + debugfs_remove(ohci->debug_async); +async_error: + debugfs_remove(ohci->debug_dir); +dir_error: + ohci->debug_periodic = NULL; + ohci->debug_async = NULL; + ohci->debug_dir = NULL; } static inline void remove_debug_files (struct ohci_hcd *ohci) { - struct device *dev = ohci_to_hcd(ohci)->self.dev; - - device_remove_file(dev, &dev_attr_async); - device_remove_file(dev, &dev_attr_periodic); - device_remove_file(dev, &dev_attr_registers); + debugfs_remove(ohci->debug_registers); + debugfs_remove(ohci->debug_periodic); + debugfs_remove(ohci->debug_async); + debugfs_remove(ohci->debug_dir); } #endif diff --git a/drivers/usb/host/ohci-hcd.c b/drivers/usb/host/ohci-hcd.c index ddd4ee1f2413..baca09af6076 100644 --- a/drivers/usb/host/ohci-hcd.c +++ b/drivers/usb/host/ohci-hcd.c @@ -36,6 +36,7 @@ #include #include #include +#include #include #include @@ -1068,6 +1069,14 @@ static int __init ohci_hcd_mod_init(void) pr_debug ("%s: block sizes: ed %Zd td %Zd\n", hcd_name, sizeof (struct ed), sizeof (struct td)); +#ifdef DEBUG + ohci_debug_root = debugfs_create_dir("ohci", NULL); + if (!ohci_debug_root) { + retval = -ENOENT; + goto error_debug; + } +#endif + #ifdef PS3_SYSTEM_BUS_DRIVER retval = ps3_ohci_driver_register(&PS3_SYSTEM_BUS_DRIVER); if (retval < 0) @@ -1130,6 +1139,12 @@ static int __init ohci_hcd_mod_init(void) ps3_ohci_driver_unregister(&PS3_SYSTEM_BUS_DRIVER); error_ps3: #endif +#ifdef DEBUG + debugfs_remove(ohci_debug_root); + ohci_debug_root = NULL; + error_debug: +#endif + return retval; } module_init(ohci_hcd_mod_init); @@ -1154,6 +1169,9 @@ static void __exit ohci_hcd_mod_exit(void) #ifdef PS3_SYSTEM_BUS_DRIVER ps3_ohci_driver_unregister(&PS3_SYSTEM_BUS_DRIVER); #endif +#ifdef DEBUG + debugfs_remove(ohci_debug_root); +#endif } module_exit(ohci_hcd_mod_exit); 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 { unsigned eds_scheduled; struct ed *ed_to_check; unsigned zf_delay; + +#ifdef DEBUG + struct dentry *debug_dir; + struct dentry *debug_async; + struct dentry *debug_periodic; + struct dentry *debug_registers; +#endif }; #ifdef CONFIG_PCI -- cgit v1.2.3 From 694cc2087e26f3f62b9f07c5d563564ed77ef203 Mon Sep 17 00:00:00 2001 From: Tony Jones Date: Tue, 11 Sep 2007 14:07:31 -0700 Subject: USB: convert ehci debug files to use debugfs instead of sysfs We should not have multiple line files in sysfs, this moves the data to debugfs instead, like the UHCI driver. Signed-off-by: Tony Jones Cc: Kay Sievers Cc: David Brownell Signed-off-by: Greg Kroah-Hartman --- drivers/usb/host/ehci-dbg.c | 227 ++++++++++++++++++++++++++++++++++++-------- drivers/usb/host/ehci-hcd.c | 25 ++++- drivers/usb/host/ehci.h | 8 ++ 3 files changed, 219 insertions(+), 41 deletions(-) diff --git a/drivers/usb/host/ehci-dbg.c b/drivers/usb/host/ehci-dbg.c index 754a146cf828..39673f8194d9 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) { } #else -/* troubleshooting help: expose state in sysfs */ +/* troubleshooting help: expose state in debugfs */ + +static int debug_async_open(struct inode *, struct file *); +static int debug_periodic_open(struct inode *, struct file *); +static int debug_registers_open(struct inode *, struct file *); +static int debug_async_open(struct inode *, struct file *); +static ssize_t debug_output(struct file*, char __user*, size_t, loff_t*); +static int debug_close(struct inode *, struct file *); + +static const struct file_operations debug_async_fops = { + .owner = THIS_MODULE, + .open = debug_async_open, + .read = debug_output, + .release = debug_close, +}; +static const struct file_operations debug_periodic_fops = { + .owner = THIS_MODULE, + .open = debug_periodic_open, + .read = debug_output, + .release = debug_close, +}; +static const struct file_operations debug_registers_fops = { + .owner = THIS_MODULE, + .open = debug_registers_open, + .read = debug_output, + .release = debug_close, +}; + +static struct dentry *ehci_debug_root; + +struct debug_buffer { + ssize_t (*fill_func)(struct debug_buffer *); /* fill method */ + struct usb_bus *bus; + struct mutex mutex; /* protect filling of buffer */ + size_t count; /* number of characters filled into buffer */ + char *page; +}; #define speed_char(info1) ({ char tmp; \ switch (info1 & (3 << 12)) { \ @@ -441,10 +477,8 @@ done: *nextp = next; } -static ssize_t -show_async(struct device *dev, struct device_attribute *attr, char *buf) +static ssize_t fill_async_buffer(struct debug_buffer *buf) { - struct usb_bus *bus; struct usb_hcd *hcd; struct ehci_hcd *ehci; unsigned long flags; @@ -452,14 +486,13 @@ show_async(struct device *dev, struct device_attribute *attr, char *buf) char *next; struct ehci_qh *qh; - *buf = 0; - - bus = dev_get_drvdata(dev); - hcd = bus_to_hcd(bus); + hcd = bus_to_hcd(buf->bus); ehci = hcd_to_ehci (hcd); - next = buf; + next = buf->page; size = PAGE_SIZE; + *next = 0; + /* dumps a snapshot of the async schedule. * usually empty except for long-term bulk reads, or head. * one QH per line, and TDs we know about @@ -477,16 +510,12 @@ show_async(struct device *dev, struct device_attribute *attr, char *buf) } spin_unlock_irqrestore (&ehci->lock, flags); - return strlen (buf); + return strlen(buf->page); } -static DEVICE_ATTR(async, S_IRUGO, show_async, NULL); #define DBG_SCHED_LIMIT 64 - -static ssize_t -show_periodic(struct device *dev, struct device_attribute *attr, char *buf) +static ssize_t fill_periodic_buffer(struct debug_buffer *buf) { - struct usb_bus *bus; struct usb_hcd *hcd; struct ehci_hcd *ehci; unsigned long flags; @@ -500,10 +529,9 @@ show_periodic(struct device *dev, struct device_attribute *attr, char *buf) return 0; seen_count = 0; - bus = dev_get_drvdata(dev); - hcd = bus_to_hcd(bus); + hcd = bus_to_hcd(buf->bus); ehci = hcd_to_ehci (hcd); - next = buf; + next = buf->page; size = PAGE_SIZE; temp = scnprintf (next, size, "size = %d\n", ehci->periodic_size); @@ -623,14 +651,10 @@ show_periodic(struct device *dev, struct device_attribute *attr, char *buf) return PAGE_SIZE - size; } -static DEVICE_ATTR(periodic, S_IRUGO, show_periodic, NULL); - #undef DBG_SCHED_LIMIT -static ssize_t -show_registers(struct device *dev, struct device_attribute *attr, char *buf) +static ssize_t fill_registers_buffer(struct debug_buffer *buf) { - struct usb_bus *bus; struct usb_hcd *hcd; struct ehci_hcd *ehci; unsigned long flags; @@ -639,15 +663,14 @@ show_registers(struct device *dev, struct device_attribute *attr, char *buf) static char fmt [] = "%*s\n"; static char label [] = ""; - bus = dev_get_drvdata(dev); - hcd = bus_to_hcd(bus); + hcd = bus_to_hcd(buf->bus); ehci = hcd_to_ehci (hcd); - next = buf; + next = buf->page; size = PAGE_SIZE; spin_lock_irqsave (&ehci->lock, flags); - if (bus->controller->power.power_state.event) { + if (buf->bus->controller->power.power_state.event) { size = scnprintf (next, size, "bus %s, device %s (driver " DRIVER_VERSION ")\n" "%s\n" @@ -789,26 +812,150 @@ done: return PAGE_SIZE - size; } -static DEVICE_ATTR(registers, S_IRUGO, show_registers, NULL); -static inline void create_debug_files (struct ehci_hcd *ehci) +static struct debug_buffer *alloc_buffer(struct usb_bus *bus, + ssize_t (*fill_func)(struct debug_buffer *)) { - struct device *dev = ehci_to_hcd(ehci)->self.dev; - int retval; + struct debug_buffer *buf; + + buf = kzalloc(sizeof(struct debug_buffer), GFP_KERNEL); - retval = device_create_file(dev, &dev_attr_async); - retval = device_create_file(dev, &dev_attr_periodic); - retval = device_create_file(dev, &dev_attr_registers); + if (buf) { + buf->bus = bus; + buf->fill_func = fill_func; + mutex_init(&buf->mutex); + } + + return buf; } -static inline void remove_debug_files (struct ehci_hcd *ehci) +static int fill_buffer(struct debug_buffer *buf) { - struct device *dev = ehci_to_hcd(ehci)->self.dev; + int ret = 0; + + if (!buf->page) + buf->page = (char *)get_zeroed_page(GFP_KERNEL); + + if (!buf->page) { + ret = -ENOMEM; + goto out; + } + + ret = buf->fill_func(buf); - device_remove_file(dev, &dev_attr_async); - device_remove_file(dev, &dev_attr_periodic); - device_remove_file(dev, &dev_attr_registers); + if (ret >= 0) { + buf->count = ret; + ret = 0; + } + +out: + return ret; } -#endif /* STUB_DEBUG_FILES */ +static ssize_t debug_output(struct file *file, char __user *user_buf, + size_t len, loff_t *offset) +{ + struct debug_buffer *buf = file->private_data; + int ret = 0; + + mutex_lock(&buf->mutex); + if (buf->count == 0) { + ret = fill_buffer(buf); + if (ret != 0) { + mutex_unlock(&buf->mutex); + goto out; + } + } + mutex_unlock(&buf->mutex); + + ret = simple_read_from_buffer(user_buf, len, offset, + buf->page, buf->count); + +out: + return ret; + +} + +static int debug_close(struct inode *inode, struct file *file) +{ + struct debug_buffer *buf = file->private_data; + if (buf) { + if (buf->page) + free_page((unsigned long)buf->page); + kfree(buf); + } + + return 0; +} +static int debug_async_open(struct inode *inode, struct file *file) +{ + file->private_data = alloc_buffer(inode->i_private, fill_async_buffer); + + return file->private_data ? 0 : -ENOMEM; +} + +static int debug_periodic_open(struct inode *inode, struct file *file) +{ + file->private_data = alloc_buffer(inode->i_private, + fill_periodic_buffer); + + return file->private_data ? 0 : -ENOMEM; +} + +static int debug_registers_open(struct inode *inode, struct file *file) +{ + file->private_data = alloc_buffer(inode->i_private, + fill_registers_buffer); + + return file->private_data ? 0 : -ENOMEM; +} + +static inline void create_debug_files (struct ehci_hcd *ehci) +{ + struct usb_bus *bus = &ehci_to_hcd(ehci)->self; + + ehci->debug_dir = debugfs_create_dir(bus->bus_name, ehci_debug_root); + if (!ehci->debug_dir) + goto dir_error; + + ehci->debug_async = debugfs_create_file("async", S_IRUGO, + ehci->debug_dir, bus, + &debug_async_fops); + if (!ehci->debug_async) + goto async_error; + + ehci->debug_periodic = debugfs_create_file("periodic", S_IRUGO, + ehci->debug_dir, bus, + &debug_periodic_fops); + if (!ehci->debug_periodic) + goto periodic_error; + + ehci->debug_registers = debugfs_create_file("registers", S_IRUGO, + ehci->debug_dir, bus, + &debug_registers_fops); + if (!ehci->debug_registers) + goto registers_error; + return; + +registers_error: + debugfs_remove(ehci->debug_periodic); +periodic_error: + debugfs_remove(ehci->debug_async); +async_error: + debugfs_remove(ehci->debug_dir); +dir_error: + ehci->debug_periodic = NULL; + ehci->debug_async = NULL; + ehci->debug_dir = NULL; +} + +static inline void remove_debug_files (struct ehci_hcd *ehci) +{ + debugfs_remove(ehci->debug_registers); + debugfs_remove(ehci->debug_periodic); + debugfs_remove(ehci->debug_async); + debugfs_remove(ehci->debug_dir); +} + +#endif /* STUB_DEBUG_FILES */ diff --git a/drivers/usb/host/ehci-hcd.c b/drivers/usb/host/ehci-hcd.c index 5f2d74ed5ad7..264182654f4c 100644 --- a/drivers/usb/host/ehci-hcd.c +++ b/drivers/usb/host/ehci-hcd.c @@ -33,6 +33,7 @@ #include #include #include +#include #include "../core/hcd.h" @@ -978,15 +979,30 @@ static int __init ehci_hcd_init(void) sizeof(struct ehci_qh), sizeof(struct ehci_qtd), sizeof(struct ehci_itd), sizeof(struct ehci_sitd)); +#ifdef DEBUG + ehci_debug_root = debugfs_create_dir("ehci", NULL); + if (!ehci_debug_root) + return -ENOENT; +#endif + #ifdef PLATFORM_DRIVER retval = platform_driver_register(&PLATFORM_DRIVER); - if (retval < 0) + if (retval < 0) { +#ifdef DEBUG + debugfs_remove(ehci_debug_root); + ehci_debug_root = NULL; +#endif return retval; + } #endif #ifdef PCI_DRIVER retval = pci_register_driver(&PCI_DRIVER); if (retval < 0) { +#ifdef DEBUG + debugfs_remove(ehci_debug_root); + ehci_debug_root = NULL; +#endif #ifdef PLATFORM_DRIVER platform_driver_unregister(&PLATFORM_DRIVER); #endif @@ -997,6 +1013,10 @@ static int __init ehci_hcd_init(void) #ifdef PS3_SYSTEM_BUS_DRIVER retval = ps3_ehci_driver_register(&PS3_SYSTEM_BUS_DRIVER); if (retval < 0) { +#ifdef DEBUG + debugfs_remove(ehci_debug_root); + ehci_debug_root = NULL; +#endif #ifdef PLATFORM_DRIVER platform_driver_unregister(&PLATFORM_DRIVER); #endif @@ -1022,6 +1042,9 @@ static void __exit ehci_hcd_cleanup(void) #ifdef PS3_SYSTEM_BUS_DRIVER ps3_ehci_driver_unregister(&PS3_SYSTEM_BUS_DRIVER); #endif +#ifdef DEBUG + debugfs_remove(ehci_debug_root); +#endif } module_exit(ehci_hcd_cleanup); diff --git a/drivers/usb/host/ehci.h b/drivers/usb/host/ehci.h index 951d69fec513..10e71417c352 100644 --- a/drivers/usb/host/ehci.h +++ b/drivers/usb/host/ehci.h @@ -126,6 +126,14 @@ struct ehci_hcd { /* one per controller */ # define COUNT(x) do { (x)++; } while (0) #else # define COUNT(x) do {} while (0) +#endif + + /* debug files */ +#ifdef DEBUG + struct dentry *debug_dir; + struct dentry *debug_async; + struct dentry *debug_periodic; + struct dentry *debug_registers; #endif }; -- cgit v1.2.3 From badef819229d455493ba97253dd0e4097b995624 Mon Sep 17 00:00:00 2001 From: Benjamin Herrenschmidt Date: Thu, 6 Dec 2007 13:29:46 -0800 Subject: usb: Remove OHCI useless masking/unmasking of WDH interrupt The OHCI driver's IRQ handler, while processing a WDH interrupt, masks and unmasks it. I believe this is both broken (the write may still be posted during the donelist processing it's trying to safeguard) and useless as this IRQ may not be reissued until it's acked (unless this legacy code is an uncommented workaround for some chip erratum). Signed-off-by: Benjamin Herrenschmidt Signed-off-by: David Brownell Signed-off-by: Greg Kroah-Hartman --- drivers/usb/host/ohci-hcd.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/drivers/usb/host/ohci-hcd.c b/drivers/usb/host/ohci-hcd.c index baca09af6076..8dd5d25f2f06 100644 --- a/drivers/usb/host/ohci-hcd.c +++ b/drivers/usb/host/ohci-hcd.c @@ -810,13 +810,9 @@ static irqreturn_t ohci_irq (struct usb_hcd *hcd) } if (ints & OHCI_INTR_WDH) { - if (HC_IS_RUNNING(hcd->state)) - ohci_writel (ohci, OHCI_INTR_WDH, ®s->intrdisable); spin_lock (&ohci->lock); dl_done_list (ohci); spin_unlock (&ohci->lock); - if (HC_IS_RUNNING(hcd->state)) - ohci_writel (ohci, OHCI_INTR_WDH, ®s->intrenable); } if (quirk_zfmicro(ohci) && (ints & OHCI_INTR_SF)) { -- cgit v1.2.3 From 885e97478bf95b46a7cff40df49c2bb1a5503afd Mon Sep 17 00:00:00 2001 From: Alan Stern Date: Mon, 3 Dec 2007 15:42:10 -0500 Subject: USB: repair USBDEVFS_CONNECT ioctl For as long as I've known about it, the USBDEVFS_CONNECT ioctl hasn't done what it's supposed to. The current code reprobes _all_ the unbound USB interfaces; this patch (as1021) makes it reprobe only the interface for which it was called. Signed-off-by: Alan Stern Signed-off-by: Greg Kroah-Hartman --- drivers/usb/core/devio.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/drivers/usb/core/devio.c b/drivers/usb/core/devio.c index 1f4f6d02fe25..85ec65ada123 100644 --- a/drivers/usb/core/devio.c +++ b/drivers/usb/core/devio.c @@ -1373,9 +1373,10 @@ static int proc_ioctl(struct dev_state *ps, struct usbdevfs_ioctl *ctl) /* let kernel drivers try to (re)bind to the interface */ case USBDEVFS_CONNECT: - usb_unlock_device(ps->dev); - retval = bus_rescan_devices(intf->dev.bus); - usb_lock_device(ps->dev); + if (!intf->dev.driver) + retval = device_attach(&intf->dev); + else + retval = -EBUSY; break; /* talk directly to the interface's driver */ -- cgit v1.2.3 From 852c4b43bdd0953483e93bb97ca2fac7e5111dcb Mon Sep 17 00:00:00 2001 From: Alan Stern Date: Mon, 3 Dec 2007 15:44:29 -0500 Subject: USB: updates to usb_reset_composite_device() This patch (as1023) updates the code in usb_reset_composite_device(): Some local variable declarations are moved to inner loops. The interface locks are not acquired. This isn't necessary any more; its only reason was to prevent an interface from being suspended or resumed during the reset. But now interface power management is controlled by the USB device lock, not by the interface lock. The check for whether the interface is registered is removed. There doesn't seem to be any reason for checking; a driver for a non-registered interface deserves to be informed of device resets just as much as any other. Signed-off-by: Alan Stern Signed-off-by: Greg Kroah-Hartman --- drivers/usb/core/hub.c | 32 +++++++++----------------------- 1 file changed, 9 insertions(+), 23 deletions(-) diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c index f7c2219c800f..cc93aa9336fe 100644 --- a/drivers/usb/core/hub.c +++ b/drivers/usb/core/hub.c @@ -3125,16 +3125,12 @@ EXPORT_SYMBOL(usb_reset_device); * this from a driver probe() routine after downloading new firmware. * For calls that might not occur during probe(), drivers should lock * the device using usb_lock_device_for_reset(). - * - * The interface locks are acquired during the pre_reset stage and released - * during the post_reset stage. However if iface is not NULL and is - * currently being probed, we assume that the caller already owns its - * lock. */ int usb_reset_composite_device(struct usb_device *udev, struct usb_interface *iface) { int ret; + int i; struct usb_host_config *config = udev->actconfig; if (udev->state == USB_STATE_NOTATTACHED || @@ -3151,16 +3147,11 @@ int usb_reset_composite_device(struct usb_device *udev, iface = NULL; if (config) { - int i; - struct usb_interface *cintf; - struct usb_driver *drv; - for (i = 0; i < config->desc.bNumInterfaces; ++i) { - cintf = config->interface[i]; - if (cintf != iface) - down(&cintf->dev.sem); - if (device_is_registered(&cintf->dev) && - cintf->dev.driver) { + struct usb_interface *cintf = config->interface[i]; + struct usb_driver *drv; + + if (cintf->dev.driver) { drv = to_usb_driver(cintf->dev.driver); if (drv->pre_reset) (drv->pre_reset)(cintf); @@ -3172,21 +3163,16 @@ int usb_reset_composite_device(struct usb_device *udev, ret = usb_reset_device(udev); if (config) { - int i; - struct usb_interface *cintf; - struct usb_driver *drv; - for (i = config->desc.bNumInterfaces - 1; i >= 0; --i) { - cintf = config->interface[i]; - if (device_is_registered(&cintf->dev) && - cintf->dev.driver) { + struct usb_interface *cintf = config->interface[i]; + struct usb_driver *drv; + + if (cintf->dev.driver) { drv = to_usb_driver(cintf->dev.driver); if (drv->post_reset) (drv->post_reset)(cintf); /* FIXME: Unbind if post_reset returns an error or isn't defined */ } - if (cintf != iface) - up(&cintf->dev.sem); } } -- cgit v1.2.3 From 241ca64fc55bd2b676890472880e2d2d86cfae82 Mon Sep 17 00:00:00 2001 From: Matthias Kaehlcke Date: Tue, 4 Dec 2007 16:15:40 +0100 Subject: USB: Edgeport USB Serial Converter: convert es_sem to mutex Edgeport USB Serial Converter: convert semaphore es_sem to the mutex API Signed-off-by: Matthias Kaehlcke Signed-off-by: Greg Kroah-Hartman --- drivers/usb/serial/io_ti.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/drivers/usb/serial/io_ti.c b/drivers/usb/serial/io_ti.c index b8670905bc3a..f7fdf1ce6bf3 100644 --- a/drivers/usb/serial/io_ti.c +++ b/drivers/usb/serial/io_ti.c @@ -34,6 +34,7 @@ #include #include #include +#include #include #include #include @@ -133,7 +134,7 @@ struct edgeport_serial { struct product_info product_info; u8 TI_I2C_Type; // Type of I2C in UMP u8 TiReadI2C; // Set to TRUE if we have read the I2c in Boot Mode - struct semaphore es_sem; + struct mutex es_lock; int num_ports_open; struct usb_serial *serial; }; @@ -2044,7 +2045,7 @@ static int edge_open (struct usb_serial_port *port, struct file * filp) dbg ("ShadowMCR 0x%X", edge_port->shadow_mcr); edge_serial = edge_port->edge_serial; - if (down_interruptible(&edge_serial->es_sem)) + if (mutex_lock_interruptible(&edge_serial->es_lock)) return -ERESTARTSYS; if (edge_serial->num_ports_open == 0) { /* 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) if (!urb) { dev_err (&port->dev, "%s - no interrupt urb present, exiting\n", __FUNCTION__); status = -EINVAL; - goto up_es_sem; + goto release_es_lock; } urb->complete = edge_interrupt_callback; urb->context = edge_serial; @@ -2060,7 +2061,7 @@ static int edge_open (struct usb_serial_port *port, struct file * filp) status = usb_submit_urb (urb, GFP_KERNEL); if (status) { dev_err (&port->dev, "%s - usb_submit_urb failed with value %d\n", __FUNCTION__, status); - goto up_es_sem; + goto release_es_lock; } } @@ -2092,13 +2093,13 @@ static int edge_open (struct usb_serial_port *port, struct file * filp) dbg("%s - exited", __FUNCTION__); - goto up_es_sem; + goto release_es_lock; unlink_int_urb: if (edge_port->edge_serial->num_ports_open == 0) usb_kill_urb(port->serial->port[0]->interrupt_in_urb); -up_es_sem: - up(&edge_serial->es_sem); +release_es_lock: + mutex_unlock(&edge_serial->es_lock); return status; } @@ -2137,14 +2138,14 @@ static void edge_close (struct usb_serial_port *port, struct file *filp) 0, NULL, 0); - down(&edge_serial->es_sem); + mutex_lock(&edge_serial->es_lock); --edge_port->edge_serial->num_ports_open; if (edge_port->edge_serial->num_ports_open <= 0) { /* last port is now closed, let's shut down our interrupt urb */ usb_kill_urb(port->serial->port[0]->interrupt_in_urb); edge_port->edge_serial->num_ports_open = 0; } - up(&edge_serial->es_sem); + mutex_unlock(&edge_serial->es_lock); edge_port->close_pending = 0; dbg("%s - exited", __FUNCTION__); @@ -2743,7 +2744,7 @@ static int edge_startup (struct usb_serial *serial) dev_err(&serial->dev->dev, "%s - Out of memory\n", __FUNCTION__); return -ENOMEM; } - sema_init(&edge_serial->es_sem, 1); + mutex_init(&edge_serial->es_lock); edge_serial->serial = serial; usb_set_serial_data(serial, edge_serial); -- cgit v1.2.3 From 2e2eb83ffd1aeb92bf8793eea892b5bc05a993ea Mon Sep 17 00:00:00 2001 From: Alan Stern Date: Tue, 4 Dec 2007 14:35:15 -0500 Subject: USB: add usbfs stubs for suspend and resume This patch (as1022b) adds stub methods for suspend and resume to the usbfs driver. There isn't much they can do since there's no way to inform a user task about the events. But it's important to have the stubs, because an upcoming change to usbcore will automatically unbind drivers that don't have those methods when a suspend occurs. Signed-off-by: Alan Stern Signed-off-by: Greg Kroah-Hartman --- drivers/usb/core/devio.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/drivers/usb/core/devio.c b/drivers/usb/core/devio.c index 85ec65ada123..32e5591ae7b1 100644 --- a/drivers/usb/core/devio.c +++ b/drivers/usb/core/devio.c @@ -402,10 +402,25 @@ static void driver_disconnect(struct usb_interface *intf) destroy_async_on_interface(ps, ifnum); } +/* The following routines are merely placeholders. There is no way + * to inform a user task about suspend or resumes. + */ +static int driver_suspend(struct usb_interface *intf, pm_message_t msg) +{ + return 0; +} + +static int driver_resume(struct usb_interface *intf) +{ + return 0; +} + struct usb_driver usbfs_driver = { .name = "usbfs", .probe = driver_probe, .disconnect = driver_disconnect, + .suspend = driver_suspend, + .resume = driver_resume, }; static int claimintf(struct dev_state *ps, unsigned int ifnum) -- cgit v1.2.3 From 07d29b63ef6b39963ab37818653284d861cf55af Mon Sep 17 00:00:00 2001 From: Alan Stern Date: Tue, 11 Dec 2007 16:05:30 -0500 Subject: USB: EHCI: add separate IAA watchdog timer This patch (as1028) was mostly written by David Brownell; I made only a few changes (extra log info and a small bug fix -- which might account for why David's version had to be reverted). It adds a new watchdog timer to the ehci-hcd driver to be used exclusively for detecting lost or missing IAA notifications. Previously a shared timer had been used, which may have led to some problems as reported by Christian Hoffmann. Signed-off-by: Alan Stern Cc: David Brownell Signed-off-by: Greg Kroah-Hartman --- drivers/usb/host/ehci-dbg.c | 4 +-- drivers/usb/host/ehci-hcd.c | 77 ++++++++++++++++++++++++++++++++------------- drivers/usb/host/ehci-hub.c | 2 +- drivers/usb/host/ehci-pci.c | 2 +- drivers/usb/host/ehci-q.c | 6 ++-- drivers/usb/host/ehci.h | 22 ++++++++----- 6 files changed, 75 insertions(+), 38 deletions(-) diff --git a/drivers/usb/host/ehci-dbg.c b/drivers/usb/host/ehci-dbg.c index 39673f8194d9..64ebfc5548a3 100644 --- a/drivers/usb/host/ehci-dbg.c +++ b/drivers/usb/host/ehci-dbg.c @@ -786,9 +786,7 @@ static ssize_t fill_registers_buffer(struct debug_buffer *buf) } if (ehci->reclaim) { - temp = scnprintf (next, size, "reclaim qh %p%s\n", - ehci->reclaim, - ehci->reclaim_ready ? " ready" : ""); + temp = scnprintf(next, size, "reclaim qh %p\n", ehci->reclaim); size -= temp; next += temp; } diff --git a/drivers/usb/host/ehci-hcd.c b/drivers/usb/host/ehci-hcd.c index 264182654f4c..5917c6b7ce33 100644 --- a/drivers/usb/host/ehci-hcd.c +++ b/drivers/usb/host/ehci-hcd.c @@ -110,7 +110,7 @@ static const char hcd_name [] = "ehci_hcd"; #define EHCI_TUNE_MULT_TT 1 #define EHCI_TUNE_FLS 2 /* (small) 256 frame schedule */ -#define EHCI_IAA_JIFFIES (HZ/100) /* arbitrary; ~10 msec */ +#define EHCI_IAA_MSECS 10 /* arbitrary */ #define EHCI_IO_JIFFIES (HZ/10) /* io watchdog > irq_thresh */ #define EHCI_ASYNC_JIFFIES (HZ/20) /* async idle timeout */ #define EHCI_SHRINK_JIFFIES (HZ/200) /* async qh unlink delay */ @@ -267,6 +267,7 @@ static void ehci_quiesce (struct ehci_hcd *ehci) /*-------------------------------------------------------------------------*/ +static void end_unlink_async(struct ehci_hcd *ehci); static void ehci_work(struct ehci_hcd *ehci); #include "ehci-hub.c" @@ -276,25 +277,41 @@ static void ehci_work(struct ehci_hcd *ehci); /*-------------------------------------------------------------------------*/ -static void ehci_watchdog (unsigned long param) +static void ehci_iaa_watchdog(unsigned long param) { struct ehci_hcd *ehci = (struct ehci_hcd *) param; unsigned long flags; + u32 status, cmd; spin_lock_irqsave (&ehci->lock, flags); + WARN_ON(!ehci->reclaim); - /* lost IAA irqs wedge things badly; seen with a vt8235 */ + status = ehci_readl(ehci, &ehci->regs->status); + cmd = ehci_readl(ehci, &ehci->regs->command); + ehci_dbg(ehci, "IAA watchdog: status %x cmd %x\n", status, cmd); + + /* lost IAA irqs wedge things badly; seen first with a vt8235 */ if (ehci->reclaim) { - u32 status = ehci_readl(ehci, &ehci->regs->status); if (status & STS_IAA) { ehci_vdbg (ehci, "lost IAA\n"); COUNT (ehci->stats.lost_iaa); ehci_writel(ehci, STS_IAA, &ehci->regs->status); - ehci->reclaim_ready = 1; } + ehci_writel(ehci, cmd & ~CMD_IAAD, &ehci->regs->command); + end_unlink_async(ehci); } - /* stop async processing after it's idled a bit */ + spin_unlock_irqrestore(&ehci->lock, flags); +} + +static void ehci_watchdog(unsigned long param) +{ + struct ehci_hcd *ehci = (struct ehci_hcd *) param; + unsigned long flags; + + spin_lock_irqsave(&ehci->lock, flags); + + /* stop async processing after it's idled a bit */ if (test_bit (TIMER_ASYNC_OFF, &ehci->actions)) start_unlink_async (ehci, ehci->async); @@ -364,8 +381,6 @@ static void ehci_port_power (struct ehci_hcd *ehci, int is_on) static void ehci_work (struct ehci_hcd *ehci) { timer_action_done (ehci, TIMER_IO_WATCHDOG); - if (ehci->reclaim_ready) - end_unlink_async (ehci); /* another CPU may drop ehci->lock during a schedule scan while * it reports urb completions. this flag guards against bogus @@ -400,6 +415,7 @@ static void ehci_stop (struct usb_hcd *hcd) /* no more interrupts ... */ del_timer_sync (&ehci->watchdog); + del_timer_sync(&ehci->iaa_watchdog); spin_lock_irq(&ehci->lock); if (HC_IS_RUNNING (hcd->state)) @@ -448,6 +464,10 @@ static int ehci_init(struct usb_hcd *hcd) ehci->watchdog.function = ehci_watchdog; ehci->watchdog.data = (unsigned long) ehci; + init_timer(&ehci->iaa_watchdog); + ehci->iaa_watchdog.function = ehci_iaa_watchdog; + ehci->iaa_watchdog.data = (unsigned long) ehci; + /* * hw default: 1K periodic list heads, one per frame. * periodic_size can shrink by USBCMD update if hcc_params allows. @@ -464,7 +484,6 @@ static int ehci_init(struct usb_hcd *hcd) ehci->i_thresh = 2 + HCC_ISOC_THRES(hcc_params); ehci->reclaim = NULL; - ehci->reclaim_ready = 0; ehci->next_uframe = -1; /* @@ -655,8 +674,7 @@ static irqreturn_t ehci_irq (struct usb_hcd *hcd) /* complete the unlinking of some qh [4.15.2.3] */ if (status & STS_IAA) { COUNT (ehci->stats.reclaim); - ehci->reclaim_ready = 1; - bh = 1; + end_unlink_async(ehci); } /* remote wakeup [4.3.1] */ @@ -762,10 +780,16 @@ static int ehci_urb_enqueue ( static void unlink_async (struct ehci_hcd *ehci, struct ehci_qh *qh) { - /* if we need to use IAA and it's busy, defer */ - if (qh->qh_state == QH_STATE_LINKED - && ehci->reclaim - && HC_IS_RUNNING (ehci_to_hcd(ehci)->state)) { + /* failfast */ + if (!HC_IS_RUNNING(ehci_to_hcd(ehci)->state)) + end_unlink_async(ehci); + + /* if it's not linked then there's nothing to do */ + if (qh->qh_state != QH_STATE_LINKED) + ; + + /* defer till later if busy */ + else if (ehci->reclaim) { struct ehci_qh *last; for (last = ehci->reclaim; @@ -775,12 +799,8 @@ static void unlink_async (struct ehci_hcd *ehci, struct ehci_qh *qh) qh->qh_state = QH_STATE_UNLINK_WAIT; last->reclaim = qh; - /* bypass IAA if the hc can't care */ - } else if (!HC_IS_RUNNING (ehci_to_hcd(ehci)->state) && ehci->reclaim) - end_unlink_async (ehci); - - /* something else might have unlinked the qh by now */ - if (qh->qh_state == QH_STATE_LINKED) + /* start IAA cycle */ + } else start_unlink_async (ehci, qh); } @@ -807,7 +827,19 @@ static int ehci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status) qh = (struct ehci_qh *) urb->hcpriv; if (!qh) break; - unlink_async (ehci, qh); + switch (qh->qh_state) { + case QH_STATE_LINKED: + case QH_STATE_COMPLETING: + unlink_async(ehci, qh); + break; + case QH_STATE_UNLINK: + case QH_STATE_UNLINK_WAIT: + /* already started */ + break; + case QH_STATE_IDLE: + WARN_ON(1); + break; + } break; case PIPE_INTERRUPT: @@ -899,6 +931,7 @@ rescan: unlink_async (ehci, qh); /* FALL THROUGH */ case QH_STATE_UNLINK: /* wait for hw to finish? */ + case QH_STATE_UNLINK_WAIT: idle_timeout: spin_unlock_irqrestore (&ehci->lock, flags); schedule_timeout_uninterruptible(1); diff --git a/drivers/usb/host/ehci-hub.c b/drivers/usb/host/ehci-hub.c index a165e0a0961c..a249d03a5024 100644 --- a/drivers/usb/host/ehci-hub.c +++ b/drivers/usb/host/ehci-hub.c @@ -134,7 +134,7 @@ static int ehci_bus_suspend (struct usb_hcd *hcd) } ehci->command = ehci_readl(ehci, &ehci->regs->command); if (ehci->reclaim) - ehci->reclaim_ready = 1; + end_unlink_async(ehci); ehci_work(ehci); /* Unlike other USB host controller types, EHCI doesn't have diff --git a/drivers/usb/host/ehci-pci.c b/drivers/usb/host/ehci-pci.c index 45e040000280..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) /* emptying the schedule aborts any urbs */ spin_lock_irq(&ehci->lock); if (ehci->reclaim) - ehci->reclaim_ready = 1; + end_unlink_async(ehci); ehci_work(ehci); spin_unlock_irq(&ehci->lock); diff --git a/drivers/usb/host/ehci-q.c b/drivers/usb/host/ehci-q.c index b10f39c047e9..853e5e6396a5 100644 --- a/drivers/usb/host/ehci-q.c +++ b/drivers/usb/host/ehci-q.c @@ -973,7 +973,7 @@ static void end_unlink_async (struct ehci_hcd *ehci) struct ehci_qh *qh = ehci->reclaim; struct ehci_qh *next; - timer_action_done (ehci, TIMER_IAA_WATCHDOG); + iaa_watchdog_done(ehci); // qh->hw_next = cpu_to_hc32(qh->qh_dma); qh->qh_state = QH_STATE_IDLE; @@ -983,7 +983,6 @@ static void end_unlink_async (struct ehci_hcd *ehci) /* other unlink(s) may be pending (in QH_STATE_UNLINK_WAIT) */ next = qh->reclaim; ehci->reclaim = next; - ehci->reclaim_ready = 0; qh->reclaim = NULL; qh_completions (ehci, qh); @@ -1059,11 +1058,10 @@ static void start_unlink_async (struct ehci_hcd *ehci, struct ehci_qh *qh) return; } - ehci->reclaim_ready = 0; cmd |= CMD_IAAD; ehci_writel(ehci, cmd, &ehci->regs->command); (void)ehci_readl(ehci, &ehci->regs->command); - timer_action (ehci, TIMER_IAA_WATCHDOG); + iaa_watchdog_start(ehci); } /*-------------------------------------------------------------------------*/ diff --git a/drivers/usb/host/ehci.h b/drivers/usb/host/ehci.h index 10e71417c352..eeda4c88ebae 100644 --- a/drivers/usb/host/ehci.h +++ b/drivers/usb/host/ehci.h @@ -74,7 +74,6 @@ struct ehci_hcd { /* one per controller */ /* async schedule support */ struct ehci_qh *async; struct ehci_qh *reclaim; - unsigned reclaim_ready : 1; unsigned scanning : 1; /* periodic schedule support */ @@ -105,6 +104,7 @@ struct ehci_hcd { /* one per controller */ struct dma_pool *itd_pool; /* itd per iso urb */ struct dma_pool *sitd_pool; /* sitd per split iso urb */ + struct timer_list iaa_watchdog; struct timer_list watchdog; unsigned long actions; unsigned stamp; @@ -148,9 +148,21 @@ static inline struct usb_hcd *ehci_to_hcd (struct ehci_hcd *ehci) } +static inline void +iaa_watchdog_start(struct ehci_hcd *ehci) +{ + WARN_ON(timer_pending(&ehci->iaa_watchdog)); + mod_timer(&ehci->iaa_watchdog, + jiffies + msecs_to_jiffies(EHCI_IAA_MSECS)); +} + +static inline void iaa_watchdog_done(struct ehci_hcd *ehci) +{ + del_timer(&ehci->iaa_watchdog); +} + enum ehci_timer_action { TIMER_IO_WATCHDOG, - TIMER_IAA_WATCHDOG, TIMER_ASYNC_SHRINK, TIMER_ASYNC_OFF, }; @@ -168,9 +180,6 @@ timer_action (struct ehci_hcd *ehci, enum ehci_timer_action action) unsigned long t; switch (action) { - case TIMER_IAA_WATCHDOG: - t = EHCI_IAA_JIFFIES; - break; case TIMER_IO_WATCHDOG: t = EHCI_IO_JIFFIES; break; @@ -187,8 +196,7 @@ timer_action (struct ehci_hcd *ehci, enum ehci_timer_action action) // async queue SHRINK often precedes IAA. while it's ready // to go OFF neither can matter, and afterwards the IO // watchdog stops unless there's still periodic traffic. - if (action != TIMER_IAA_WATCHDOG - && t > ehci->watchdog.expires + if (time_before_eq(t, ehci->watchdog.expires) && timer_pending (&ehci->watchdog)) return; mod_timer (&ehci->watchdog, t); -- cgit v1.2.3 From caf29f62655e7aa57996821535d11fa3b0537b6b Mon Sep 17 00:00:00 2001 From: Alan Stern Date: Thu, 6 Dec 2007 11:10:39 -0500 Subject: USB: dummy_hcd: change the default power budget This patch (as1025) changes the default power budget for dummy-hcd to 500 mA and makes it a preprocessor parameter for easier testing. Signed-off-by: Alan Stern Signed-off-by: Greg Kroah-Hartman --- drivers/usb/gadget/dummy_hcd.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/usb/gadget/dummy_hcd.c b/drivers/usb/gadget/dummy_hcd.c index 1a8a5f33443e..cbe44535c0f0 100644 --- a/drivers/usb/gadget/dummy_hcd.c +++ b/drivers/usb/gadget/dummy_hcd.c @@ -61,6 +61,8 @@ #define DRIVER_DESC "USB Host+Gadget Emulator" #define DRIVER_VERSION "02 May 2005" +#define POWER_BUDGET 500 /* in mA; use 8 for low-power port testing */ + static const char driver_name [] = "dummy_hcd"; static const char driver_desc [] = "USB Host+Gadget Emulator"; @@ -1810,8 +1812,7 @@ static int dummy_start (struct usb_hcd *hcd) INIT_LIST_HEAD (&dum->urbp_list); - /* only show a low-power port: just 8mA */ - hcd->power_budget = 8; + hcd->power_budget = POWER_BUDGET; hcd->state = HC_STATE_RUNNING; hcd->uses_new_polling = 1; -- cgit v1.2.3 From eb44da0b3aa0105cb38d81c5747a8feae64834be Mon Sep 17 00:00:00 2001 From: Sarah Sharp Date: Fri, 14 Dec 2007 14:08:00 -0800 Subject: USB: pl2303: Cleanup FISH and SOUP macros in pl2303 driver. Replace the FISH and SOUP macros that violated the macro guidelines in CodingStyle. Turn them into function calls with clearer variable names. Signed-off-by: Sarah Sharp Signed-off-by: Greg Kroah-Hartman --- drivers/usb/serial/pl2303.c | 78 ++++++++++++++++++++++----------------------- 1 file changed, 39 insertions(+), 39 deletions(-) diff --git a/drivers/usb/serial/pl2303.c b/drivers/usb/serial/pl2303.c index b7da8b5c3a86..fd8c09fd3288 100644 --- a/drivers/usb/serial/pl2303.c +++ b/drivers/usb/serial/pl2303.c @@ -312,6 +312,28 @@ static unsigned int pl2303_buf_get(struct pl2303_buf *pb, char *buf, return count; } +static int pl2303_vendor_read(__u16 value, __u16 index, + struct usb_serial *serial, unsigned char *buf) +{ + int res = usb_control_msg(serial->dev, usb_rcvctrlpipe(serial->dev, 0), + VENDOR_READ_REQUEST, VENDOR_READ_REQUEST_TYPE, + value, index, buf, 1, 100); + dbg("0x%x:0x%x:0x%x:0x%x %d - %x", VENDOR_READ_REQUEST_TYPE, + VENDOR_READ_REQUEST, value, index, res, buf[0]); + return res; +} + +static int pl2303_vendor_write(__u16 value, __u16 index, + struct usb_serial *serial) +{ + int res = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0), + VENDOR_WRITE_REQUEST, VENDOR_WRITE_REQUEST_TYPE, + value, index, NULL, 0, 100); + dbg("0x%x:0x%x:0x%x:0x%x %d", VENDOR_WRITE_REQUEST_TYPE, + VENDOR_WRITE_REQUEST, value, index, res); + return res; +} + static int pl2303_startup(struct usb_serial *serial) { struct pl2303_private *priv; @@ -584,24 +606,12 @@ static void pl2303_set_termios(struct usb_serial_port *port, buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6]); if (cflag & CRTSCTS) { - __u16 index; if (priv->type == HX) - index = 0x61; + pl2303_vendor_write(0x0, 0x61, serial); else - index = 0x41; - i = usb_control_msg(serial->dev, - usb_sndctrlpipe(serial->dev, 0), - VENDOR_WRITE_REQUEST, - VENDOR_WRITE_REQUEST_TYPE, - 0x0, index, NULL, 0, 100); - dbg("0x40:0x1:0x0:0x%x %d", index, i); + pl2303_vendor_write(0x0, 0x41, serial); } else { - i = usb_control_msg(serial->dev, - usb_sndctrlpipe(serial->dev, 0), - VENDOR_WRITE_REQUEST, - VENDOR_WRITE_REQUEST_TYPE, - 0x0, 0x0, NULL, 0, 100); - dbg ("0x40:0x1:0x0:0x0 %d", i); + pl2303_vendor_write(0x0, 0x0, serial); } /* FIXME: Need to read back resulting baud rate */ @@ -694,35 +704,25 @@ static int pl2303_open(struct usb_serial_port *port, struct file *filp) if (buf==NULL) return -ENOMEM; -#define FISH(a,b,c,d) \ - result=usb_control_msg(serial->dev, usb_rcvctrlpipe(serial->dev,0), \ - b, a, c, d, buf, 1, 100); \ - dbg("0x%x:0x%x:0x%x:0x%x %d - %x",a,b,c,d,result,buf[0]); - -#define SOUP(a,b,c,d) \ - result=usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev,0), \ - b, a, c, d, NULL, 0, 100); \ - dbg("0x%x:0x%x:0x%x:0x%x %d",a,b,c,d,result); - - FISH (VENDOR_READ_REQUEST_TYPE, VENDOR_READ_REQUEST, 0x8484, 0); - SOUP (VENDOR_WRITE_REQUEST_TYPE, VENDOR_WRITE_REQUEST, 0x0404, 0); - FISH (VENDOR_READ_REQUEST_TYPE, VENDOR_READ_REQUEST, 0x8484, 0); - FISH (VENDOR_READ_REQUEST_TYPE, VENDOR_READ_REQUEST, 0x8383, 0); - FISH (VENDOR_READ_REQUEST_TYPE, VENDOR_READ_REQUEST, 0x8484, 0); - SOUP (VENDOR_WRITE_REQUEST_TYPE, VENDOR_WRITE_REQUEST, 0x0404, 1); - FISH (VENDOR_READ_REQUEST_TYPE, VENDOR_READ_REQUEST, 0x8484, 0); - FISH (VENDOR_READ_REQUEST_TYPE, VENDOR_READ_REQUEST, 0x8383, 0); - SOUP (VENDOR_WRITE_REQUEST_TYPE, VENDOR_WRITE_REQUEST, 0, 1); - SOUP (VENDOR_WRITE_REQUEST_TYPE, VENDOR_WRITE_REQUEST, 1, 0); + pl2303_vendor_read(0x8484, 0, serial, buf); + pl2303_vendor_write(0x0404, 0, serial); + pl2303_vendor_read(0x8484, 0, serial, buf); + pl2303_vendor_read(0x8383, 0, serial, buf); + pl2303_vendor_read(0x8484, 0, serial, buf); + pl2303_vendor_write(0x0404, 1, serial); + pl2303_vendor_read(0x8484, 0, serial, buf); + pl2303_vendor_read(0x8383, 0, serial, buf); + pl2303_vendor_write(0, 1, serial); + pl2303_vendor_write(1, 0, serial); if (priv->type == HX) { /* HX chip */ - SOUP (VENDOR_WRITE_REQUEST_TYPE, VENDOR_WRITE_REQUEST, 2, 0x44); + pl2303_vendor_write(2, 0x44, serial); /* reset upstream data pipes */ - SOUP (VENDOR_WRITE_REQUEST_TYPE, VENDOR_WRITE_REQUEST, 8, 0); - SOUP (VENDOR_WRITE_REQUEST_TYPE, VENDOR_WRITE_REQUEST, 9, 0); + pl2303_vendor_write(8, 0, serial); + pl2303_vendor_write(9, 0, serial); } else { - SOUP (VENDOR_WRITE_REQUEST_TYPE, VENDOR_WRITE_REQUEST, 2, 0x24); + pl2303_vendor_write(2, 0x24, serial); } kfree(buf); -- cgit v1.2.3 From 3e152505a57db6622deb1322c22551c046e33d16 Mon Sep 17 00:00:00 2001 From: Sarah Sharp Date: Fri, 14 Dec 2007 14:08:35 -0800 Subject: USB: pl2303: Move pl2303 vendor specific init to probe function. Without this fix, the pl2303 usb-serial adapter would not suspend properly unless it had been opened first. A pl2303 type_1 chip will still break if the system is hibernated while the RS-232 connector is powered by another system. This was broken before, and a reset resume does not fix it. All other suspend and autosuspend scenarios work with ATEN pl2303 adaptors with HX and type_1 chips. Signed-off-by: Sarah Sharp Signed-off-by: Greg Kroah-Hartman --- drivers/usb/serial/pl2303.c | 49 ++++++++++++++++++++++----------------------- 1 file changed, 24 insertions(+), 25 deletions(-) diff --git a/drivers/usb/serial/pl2303.c b/drivers/usb/serial/pl2303.c index fd8c09fd3288..c27f2f822f13 100644 --- a/drivers/usb/serial/pl2303.c +++ b/drivers/usb/serial/pl2303.c @@ -338,8 +338,13 @@ static int pl2303_startup(struct usb_serial *serial) { struct pl2303_private *priv; enum pl2303_type type = type_0; + unsigned char *buf; int i; + buf = kmalloc(10, GFP_KERNEL); + if (buf == NULL) + return -ENOMEM; + if (serial->dev->descriptor.bDeviceClass == 0x02) type = type_0; else if (serial->dev->descriptor.bMaxPacketSize0 == 0x40) @@ -364,9 +369,27 @@ static int pl2303_startup(struct usb_serial *serial) priv->type = type; usb_set_serial_port_data(serial->port[i], priv); } + + pl2303_vendor_read(0x8484, 0, serial, buf); + pl2303_vendor_write(0x0404, 0, serial); + pl2303_vendor_read(0x8484, 0, serial, buf); + pl2303_vendor_read(0x8383, 0, serial, buf); + pl2303_vendor_read(0x8484, 0, serial, buf); + pl2303_vendor_write(0x0404, 1, serial); + pl2303_vendor_read(0x8484, 0, serial, buf); + pl2303_vendor_read(0x8383, 0, serial, buf); + pl2303_vendor_write(0, 1, serial); + pl2303_vendor_write(1, 0, serial); + if (type == HX) + pl2303_vendor_write(2, 0x44, serial); + else + pl2303_vendor_write(2, 0x24, serial); + + kfree(buf); return 0; cleanup: + kfree(buf); for (--i; i>=0; --i) { priv = usb_get_serial_port_data(serial->port[i]); pl2303_buf_free(priv->buf); @@ -690,7 +713,6 @@ static int pl2303_open(struct usb_serial_port *port, struct file *filp) struct ktermios tmp_termios; struct usb_serial *serial = port->serial; struct pl2303_private *priv = usb_get_serial_port_data(port); - unsigned char *buf; int result; dbg("%s - port %d", __FUNCTION__, port->number); @@ -698,35 +720,12 @@ static int pl2303_open(struct usb_serial_port *port, struct file *filp) if (priv->type != HX) { usb_clear_halt(serial->dev, port->write_urb->pipe); usb_clear_halt(serial->dev, port->read_urb->pipe); - } - - buf = kmalloc(10, GFP_KERNEL); - if (buf==NULL) - return -ENOMEM; - - pl2303_vendor_read(0x8484, 0, serial, buf); - pl2303_vendor_write(0x0404, 0, serial); - pl2303_vendor_read(0x8484, 0, serial, buf); - pl2303_vendor_read(0x8383, 0, serial, buf); - pl2303_vendor_read(0x8484, 0, serial, buf); - pl2303_vendor_write(0x0404, 1, serial); - pl2303_vendor_read(0x8484, 0, serial, buf); - pl2303_vendor_read(0x8383, 0, serial, buf); - pl2303_vendor_write(0, 1, serial); - pl2303_vendor_write(1, 0, serial); - - if (priv->type == HX) { - /* HX chip */ - pl2303_vendor_write(2, 0x44, serial); + } else { /* reset upstream data pipes */ pl2303_vendor_write(8, 0, serial); pl2303_vendor_write(9, 0, serial); - } else { - pl2303_vendor_write(2, 0x24, serial); } - kfree(buf); - /* Setup termios */ if (port->tty) { pl2303_set_termios(port, &tmp_termios); -- cgit v1.2.3 From fcf9e55e066d12c18add7c8a292bf879b45b1d55 Mon Sep 17 00:00:00 2001 From: Sarah Sharp Date: Fri, 14 Dec 2007 14:09:30 -0800 Subject: USB: pl2303: Add autosuspend support to pl2303 usb serial converter. Signed-off-by: Sarah Sharp Signed-off-by: Greg Kroah-Hartman --- drivers/usb/serial/pl2303.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/usb/serial/pl2303.c b/drivers/usb/serial/pl2303.c index c27f2f822f13..ac3d8765f482 100644 --- a/drivers/usb/serial/pl2303.c +++ b/drivers/usb/serial/pl2303.c @@ -99,7 +99,10 @@ static struct usb_driver pl2303_driver = { .probe = usb_serial_probe, .disconnect = usb_serial_disconnect, .id_table = id_table, + .suspend = usb_serial_suspend, + .resume = usb_serial_resume, .no_dynamic_id = 1, + .supports_autosuspend = 1, }; #define SET_LINE_REQUEST_TYPE 0x21 -- cgit v1.2.3 From 3ec466b49636c89866f7681813443c3abcefcbc2 Mon Sep 17 00:00:00 2001 From: Alan Cox Date: Thu, 13 Dec 2007 16:15:26 -0800 Subject: USB: belkin_sa: clean up for new style termios and speed handling, plus style A tester with actual hardware would be useful Signed-off-by: Alan Cox Signed-off-by: Andrew Morton Signed-off-by: Greg Kroah-Hartman --- drivers/usb/serial/belkin_sa.c | 37 ++++++++++++++++--------------------- 1 file changed, 16 insertions(+), 21 deletions(-) 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 unsigned long control_state; int bad_flow_control; speed_t baud; + struct ktermios *termios = port->tty->termios; - if ((!port->tty) || (!port->tty->termios)) { - dbg ("%s - no tty or termios structure", __FUNCTION__); - return; - } + iflag = termios->c_iflag; + cflag = termios->c_cflag; - iflag = port->tty->termios->c_iflag; - cflag = port->tty->termios->c_cflag; + termios->c_cflag &= ~CMSPAR; /* get a local copy of the current port settings */ spin_lock_irqsave(&priv->lock, flags); @@ -369,33 +367,30 @@ static void belkin_sa_set_termios (struct usb_serial_port *port, struct ktermios old_cflag = old_termios->c_cflag; /* Set the baud rate */ - if( (cflag&CBAUD) != (old_cflag&CBAUD) ) { + if ((cflag & CBAUD) != (old_cflag & CBAUD)) { /* reassert DTR and (maybe) RTS on transition from B0 */ if( (old_cflag&CBAUD) == B0 ) { control_state |= (TIOCM_DTR|TIOCM_RTS); if (BSA_USB_CMD(BELKIN_SA_SET_DTR_REQUEST, 1) < 0) err("Set DTR error"); /* don't set RTS if using hardware flow control */ - if (!(old_cflag&CRTSCTS) ) + if (!(old_cflag & CRTSCTS)) if (BSA_USB_CMD(BELKIN_SA_SET_RTS_REQUEST, 1) < 0) err("Set RTS error"); } } baud = tty_get_baud_rate(port->tty); - if (baud == 0) { - dbg("%s - tty_get_baud_rate says 0 baud", __FUNCTION__); - return; - } - urb_value = BELKIN_SA_BAUD(baud); - /* Clip to maximum speed */ - if (urb_value == 0) - urb_value = 1; - /* Turn it back into a resulting real baud rate */ - baud = BELKIN_SA_BAUD(urb_value); - /* FIXME: Once the tty updates are done then push this back to the tty */ - - if ((cflag & CBAUD) != B0 ) { + if (baud) { + urb_value = BELKIN_SA_BAUD(baud); + /* Clip to maximum speed */ + if (urb_value == 0) + urb_value = 1; + /* Turn it back into a resulting real baud rate */ + baud = BELKIN_SA_BAUD(urb_value); + + /* Report the actual baud rate back to the caller */ + tty_encode_baud_rate(port->tty, baud, baud); if (BSA_USB_CMD(BELKIN_SA_SET_BAUDRATE_REQUEST, urb_value) < 0) err("Set baudrate error"); } else { -- cgit v1.2.3 From e7806e366bcab561a6ecc1a6c4a5337f1714ece1 Mon Sep 17 00:00:00 2001 From: Alan Cox Date: Thu, 13 Dec 2007 16:15:28 -0800 Subject: USB: keyspan_pda: clean up speed handling Signed-off-by: Alan Cox Signed-off-by: Andrew Morton Signed-off-by: Greg Kroah-Hartman --- drivers/usb/serial/keyspan_pda.c | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) 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) } -static int keyspan_pda_setbaud (struct usb_serial *serial, int baud) +static speed_t keyspan_pda_setbaud (struct usb_serial *serial, speed_t baud) { int rc; int bindex; @@ -319,7 +319,9 @@ static int keyspan_pda_setbaud (struct usb_serial *serial, int baud) case 38400: bindex = 7; break; case 57600: bindex = 8; break; case 115200: bindex = 9; break; - default: return -EINVAL; + default: + bindex = 5; /* Default to 9600 */ + baud = 9600; } /* 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) NULL, /* &data */ 0, /* size */ 2000); /* timeout */ - return(rc); + if (rc < 0) + return 0; + return baud; } @@ -366,7 +370,7 @@ static void keyspan_pda_set_termios (struct usb_serial_port *port, struct ktermios *old_termios) { struct usb_serial *serial = port->serial; - unsigned int cflag = port->tty->termios->c_cflag; + speed_t speed; /* cflag specifies lots of stuff: number of stop bits, parity, number 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, For now, just do baud. */ - switch (cflag & CBAUD) { - /* we could support more values here, just need to calculate - the necessary divisors in the firmware. - has the Bnnn constants. */ - case B110: keyspan_pda_setbaud(serial, 110); break; - case B300: keyspan_pda_setbaud(serial, 300); break; - case B1200: keyspan_pda_setbaud(serial, 1200); break; - case B2400: keyspan_pda_setbaud(serial, 2400); break; - case B4800: keyspan_pda_setbaud(serial, 4800); break; - case B9600: keyspan_pda_setbaud(serial, 9600); break; - case B19200: keyspan_pda_setbaud(serial, 19200); break; - case B38400: keyspan_pda_setbaud(serial, 38400); break; - case B57600: keyspan_pda_setbaud(serial, 57600); break; - case B115200: keyspan_pda_setbaud(serial, 115200); break; - default: dbg("can't handle requested baud rate"); break; + speed = tty_get_baud_rate(port->tty); + speed = keyspan_pda_setbaud(serial, speed); + + if (speed == 0) { + dbg("can't handle requested baud rate"); + /* It hasn't changed so.. */ + speed = tty_termios_baud_rate(old_termios); } + /* Only speed can change so copy the old h/w parameters + then encode the new speed */ + tty_termios_copy_hw(port->tty->termios, old_termios); + tty_encode_baud_rate(port->tty, speed, speed); } -- cgit v1.2.3 From d0fab0ddf3fca22f73b95d2e15b598fa17876c69 Mon Sep 17 00:00:00 2001 From: Alan Cox Date: Thu, 13 Dec 2007 16:15:29 -0800 Subject: USB: mct232: speed, new termios and compliance cleanups Signed-off-by: Alan Cox Cc: Pete Zaitcev Signed-off-by: Andrew Morton Signed-off-by: Greg Kroah-Hartman --- drivers/usb/serial/mct_u232.c | 26 +++++++++++++++++--------- drivers/usb/serial/mct_u232.h | 2 +- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/drivers/usb/serial/mct_u232.c b/drivers/usb/serial/mct_u232.c index 0dc99f75bb09..88b2074867c5 100644 --- a/drivers/usb/serial/mct_u232.c +++ b/drivers/usb/serial/mct_u232.c @@ -182,10 +182,11 @@ struct mct_u232_private { /* * Later day 2.6.0-test kernels have new baud rates like B230400 which * we do not know how to support. We ignore them for the moment. - * XXX Rate-limit the error message, it's user triggerable. */ -static int mct_u232_calculate_baud_rate(struct usb_serial *serial, speed_t value) +static int mct_u232_calculate_baud_rate(struct usb_serial *serial, speed_t value, speed_t *result) { + *result = value; + if (le16_to_cpu(serial->dev->descriptor.idProduct) == MCT_U232_SITECOM_PID || le16_to_cpu(serial->dev->descriptor.idProduct) == MCT_U232_BELKIN_F5U109_PID) { switch (value) { @@ -200,11 +201,13 @@ static int mct_u232_calculate_baud_rate(struct usb_serial *serial, speed_t value case 57600: return 0x0b; case 115200: return 0x0c; default: - err("MCT USB-RS232: unsupported baudrate request 0x%x," - " using default of B9600", value); + *result = 9600; return 0x08; } } else { + /* FIXME: Can we use any divider - should we do + divider = 115200/value; + real baud = 115200/divider */ switch (value) { case 300: break; case 600: break; @@ -217,9 +220,8 @@ static int mct_u232_calculate_baud_rate(struct usb_serial *serial, speed_t value case 57600: break; case 115200: break; default: - err("MCT USB-RS232: unsupported baudrate request 0x%x," - " using default of B9600", value); value = 9600; + *result = 9600; } return 115200/value; } @@ -232,16 +234,19 @@ static int mct_u232_set_baud_rate(struct usb_serial *serial, struct usb_serial_p int rc; unsigned char zero_byte = 0; unsigned char cts_enable_byte = 0; + speed_t speed; - divisor = cpu_to_le32(mct_u232_calculate_baud_rate(serial, value)); + divisor = cpu_to_le32(mct_u232_calculate_baud_rate(serial, value, &speed)); rc = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0), MCT_U232_SET_BAUD_RATE_REQUEST, MCT_U232_SET_REQUEST_TYPE, 0, 0, &divisor, MCT_U232_SET_BAUD_RATE_SIZE, WDR_TIMEOUT); - if (rc < 0) + if (rc < 0) /*FIXME: What value speed results */ err("Set BAUD RATE %d failed (error = %d)", value, rc); + else + tty_encode_baud_rate(port->tty, speed, speed); dbg("set_baud_rate: value: 0x%x, divisor: 0x%x", value, divisor); /* Mimic the MCT-supplied Windows driver (version 1.21P.0104), which @@ -608,7 +613,8 @@ static void mct_u232_set_termios (struct usb_serial_port *port, { struct usb_serial *serial = port->serial; struct mct_u232_private *priv = usb_get_serial_port_data(port); - unsigned int cflag = port->tty->termios->c_cflag; + struct ktermios *termios = port->tty->termios; + unsigned int cflag = termios->c_cflag; unsigned int old_cflag = old_termios->c_cflag; unsigned long flags; unsigned int control_state; @@ -670,6 +676,8 @@ static void mct_u232_set_termios (struct usb_serial_port *port, break; } + termios->c_cflag &= ~CMSPAR; + /* set the number of stop bits */ last_lcr |= (cflag & CSTOPB) ? 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 @@ * and "Intel solution". They are the regular MCT and "Sitecom" for us. * This is pointless to document in the header, see the code for the bits. */ -static int mct_u232_calculate_baud_rate(struct usb_serial *serial, speed_t value); +static int mct_u232_calculate_baud_rate(struct usb_serial *serial, speed_t value, speed_t *result); /* * Line Control Register (LCR) -- cgit v1.2.3 From 041509db390cf97b09df0f51024f5d40407938db Mon Sep 17 00:00:00 2001 From: Nick Piggin Date: Thu, 13 Dec 2007 16:15:35 -0800 Subject: USB: mon nopage Convert USB mon driver from nopage to fault. Signed-off-by: Nick Piggin Acked-by: Pete Zaitcev Signed-off-by: Andrew Morton Signed-off-by: Greg Kroah-Hartman --- drivers/usb/mon/mon_bin.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/drivers/usb/mon/mon_bin.c b/drivers/usb/mon/mon_bin.c index 81aab527024c..d70666f1a90d 100644 --- a/drivers/usb/mon/mon_bin.c +++ b/drivers/usb/mon/mon_bin.c @@ -1047,33 +1047,31 @@ static void mon_bin_vma_close(struct vm_area_struct *vma) /* * Map ring pages to user space. */ -struct page *mon_bin_vma_nopage(struct vm_area_struct *vma, - unsigned long address, int *type) +static int mon_bin_vma_fault(struct vm_area_struct *vma, struct vm_fault *vmf) { struct mon_reader_bin *rp = vma->vm_private_data; unsigned long offset, chunk_idx; struct page *pageptr; - offset = (address - vma->vm_start) + (vma->vm_pgoff << PAGE_SHIFT); + offset = vmf->pgoff << PAGE_SHIFT; if (offset >= rp->b_size) - return NOPAGE_SIGBUS; + return VM_FAULT_SIGBUS; chunk_idx = offset / CHUNK_SIZE; pageptr = rp->b_vec[chunk_idx].pg; get_page(pageptr); - if (type) - *type = VM_FAULT_MINOR; - return pageptr; + vmf->page = pageptr; + return 0; } struct vm_operations_struct mon_bin_vm_ops = { .open = mon_bin_vma_open, .close = mon_bin_vma_close, - .nopage = mon_bin_vma_nopage, + .fault = mon_bin_vma_fault, }; int mon_bin_mmap(struct file *filp, struct vm_area_struct *vma) { - /* don't do anything here: "nopage" will set up page table entries */ + /* don't do anything here: "fault" will set up page table entries */ vma->vm_ops = &mon_bin_vm_ops; vma->vm_flags |= VM_RESERVED; vma->vm_private_data = filp->private_data; -- cgit v1.2.3 From 1cfab028afe5827433195c57b6f36d61a79beb50 Mon Sep 17 00:00:00 2001 From: Matthias Kaehlcke Date: Thu, 13 Dec 2007 16:15:33 -0800 Subject: USB: testing driver: convert dev->sem to mutex USB testing driver: convert semaphore dev->sem to the mutex API Signed-off-by: Matthias Kaehlcke Signed-off-by: Andrew Morton Signed-off-by: Greg Kroah-Hartman --- drivers/usb/misc/usbtest.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/drivers/usb/misc/usbtest.c b/drivers/usb/misc/usbtest.c index 81755d06a419..e3851359d653 100644 --- a/drivers/usb/misc/usbtest.c +++ b/drivers/usb/misc/usbtest.c @@ -6,6 +6,7 @@ #include #include #include +#include #include @@ -64,7 +65,7 @@ struct usbtest_dev { int in_iso_pipe; int out_iso_pipe; struct usb_endpoint_descriptor *iso_in, *iso_out; - struct semaphore sem; + struct mutex lock; #define TBUF_SIZE 256 u8 *buf; @@ -1559,11 +1560,11 @@ usbtest_ioctl (struct usb_interface *intf, unsigned int code, void *buf) || param->sglen < 0 || param->vary < 0) return -EINVAL; - if (down_interruptible (&dev->sem)) + if (mutex_lock_interruptible(&dev->lock)) return -ERESTARTSYS; if (intf->dev.power.power_state.event != PM_EVENT_ON) { - up (&dev->sem); + mutex_unlock(&dev->lock); return -EHOSTUNREACH; } @@ -1575,7 +1576,7 @@ usbtest_ioctl (struct usb_interface *intf, unsigned int code, void *buf) int res; if (intf->altsetting->desc.bInterfaceNumber) { - up (&dev->sem); + mutex_unlock(&dev->lock); return -ENODEV; } res = set_altsetting (dev, dev->info->alt); @@ -1583,7 +1584,7 @@ usbtest_ioctl (struct usb_interface *intf, unsigned int code, void *buf) dev_err (&intf->dev, "set altsetting to %d failed, %d\n", dev->info->alt, res); - up (&dev->sem); + mutex_unlock(&dev->lock); return res; } } @@ -1856,7 +1857,7 @@ usbtest_ioctl (struct usb_interface *intf, unsigned int code, void *buf) param->duration.tv_usec += 1000 * 1000; param->duration.tv_sec -= 1; } - up (&dev->sem); + mutex_unlock(&dev->lock); return retval; } @@ -1906,7 +1907,7 @@ usbtest_probe (struct usb_interface *intf, const struct usb_device_id *id) return -ENOMEM; info = (struct usbtest_info *) id->driver_info; dev->info = info; - init_MUTEX (&dev->sem); + mutex_init(&dev->lock); dev->intf = intf; @@ -1991,7 +1992,7 @@ static void usbtest_disconnect (struct usb_interface *intf) { struct usbtest_dev *dev = usb_get_intfdata (intf); - down (&dev->sem); + mutex_lock(&dev->lock); usb_set_intfdata (intf, NULL); dev_dbg (&intf->dev, "disconnect\n"); -- cgit v1.2.3 From 26e109b0a90b5ef7b025e44a969836ab9a598ffc Mon Sep 17 00:00:00 2001 From: Andrew Morton Date: Thu, 13 Dec 2007 16:15:34 -0800 Subject: USB: testing driver: don't free a locked mutex Dopey thing to do and lockdep will (or should) warn. Spotted by Daniel Walker. Cc: Matthias Kaehlcke Cc: Daniel Walker Cc: Ingo Molnar Signed-off-by: Andrew Morton Signed-off-by: Greg Kroah-Hartman --- drivers/usb/misc/usbtest.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/drivers/usb/misc/usbtest.c b/drivers/usb/misc/usbtest.c index e3851359d653..f1b886c204c0 100644 --- a/drivers/usb/misc/usbtest.c +++ b/drivers/usb/misc/usbtest.c @@ -1992,8 +1992,6 @@ static void usbtest_disconnect (struct usb_interface *intf) { struct usbtest_dev *dev = usb_get_intfdata (intf); - mutex_lock(&dev->lock); - usb_set_intfdata (intf, NULL); dev_dbg (&intf->dev, "disconnect\n"); kfree (dev); -- cgit v1.2.3 From d4a8d46d9129fbb26b4c2d3143b1b0975a9b4ae4 Mon Sep 17 00:00:00 2001 From: Dmitry Baryshkov Date: Thu, 6 Dec 2007 18:18:03 -0800 Subject: USB: gadget: pxa2xx_udc supports inverted vbus Some boards (like e.g. Tosa) invert the VBUS-detection signal: it's low when a host is supplying VBUS, and high otherwise. Allow specifying whether gpio_vbus value is inverted. Signed-off-by: Dmitry Baryshkov Signed-off-by: David Brownell Signed-off-by: Greg Kroah-Hartman --- drivers/usb/gadget/pxa2xx_udc.c | 9 +++++++-- include/asm-arm/mach/udc_pxa2xx.h | 2 ++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/drivers/usb/gadget/pxa2xx_udc.c b/drivers/usb/gadget/pxa2xx_udc.c index 4abf9d26d615..8bd9ce26bd95 100644 --- a/drivers/usb/gadget/pxa2xx_udc.c +++ b/drivers/usb/gadget/pxa2xx_udc.c @@ -127,8 +127,10 @@ static int is_vbus_present(void) { struct pxa2xx_udc_mach_info *mach = the_controller->mach; - if (mach->gpio_vbus) - return gpio_get_value(mach->gpio_vbus); + if (mach->gpio_vbus) { + int value = gpio_get_value(mach->gpio_vbus); + return mach->gpio_vbus_inverted ? !value : value; + } if (mach->udc_is_connected) return mach->udc_is_connected(); return 1; @@ -1398,6 +1400,9 @@ static irqreturn_t udc_vbus_irq(int irq, void *_dev) struct pxa2xx_udc *dev = _dev; int vbus = gpio_get_value(dev->mach->gpio_vbus); + if (dev->mach->gpio_vbus_inverted) + vbus = !vbus; + pxa2xx_udc_vbus_session(&dev->gadget, vbus); return IRQ_HANDLED; } diff --git a/include/asm-arm/mach/udc_pxa2xx.h b/include/asm-arm/mach/udc_pxa2xx.h index ff0a95715a07..f191e147ea90 100644 --- a/include/asm-arm/mach/udc_pxa2xx.h +++ b/include/asm-arm/mach/udc_pxa2xx.h @@ -19,7 +19,9 @@ struct pxa2xx_udc_mach_info { * with on-chip GPIOs not Lubbock's wierd hardware, can have a sane * VBUS IRQ and omit the methods above. Store the GPIO number * here; for GPIO 0, also mask in one of the pxa_gpio_mode() bits. + * Note that sometimes the signals go through inverters... */ + bool gpio_vbus_inverted; u16 gpio_vbus; /* high == vbus present */ u16 gpio_pullup; /* high == pullup activated */ }; -- cgit v1.2.3 From dc0d5c1e5c7532e800fff6e313cd4af44af99976 Mon Sep 17 00:00:00 2001 From: Joe Perches Date: Mon, 17 Dec 2007 11:40:18 -0800 Subject: USB: Spelling fixes Signed-off-by: Joe Perches Signed-off-by: Greg Kroah-Hartman --- drivers/usb/atm/ueagle-atm.c | 2 +- drivers/usb/class/cdc-acm.c | 2 +- drivers/usb/gadget/at91_udc.h | 2 +- drivers/usb/gadget/fsl_usb2_udc.c | 2 +- drivers/usb/gadget/omap_udc.c | 2 +- drivers/usb/host/ehci-fsl.c | 2 +- drivers/usb/host/ehci-sched.c | 2 +- drivers/usb/host/r8a66597.h | 2 +- drivers/usb/misc/sisusbvga/sisusb.c | 2 +- drivers/usb/misc/usbtest.c | 2 +- drivers/usb/serial/io_edgeport.c | 8 ++++---- drivers/usb/serial/mos7840.c | 8 ++++---- 12 files changed, 18 insertions(+), 18 deletions(-) diff --git a/drivers/usb/atm/ueagle-atm.c b/drivers/usb/atm/ueagle-atm.c index fad5d916564c..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) bi.dwAddress = swab32(blockidx->PageAddress); uea_dbg(INS_TO_USBDEV(sc), - "sending block %u for DSP page %u size %u adress %x\n", + "sending block %u for DSP page %u size %u address %x\n", blockno, pageno, blocksize, le32_to_cpu(blockidx->PageAddress)); /* send block info through the IDMA pipe */ diff --git a/drivers/usb/class/cdc-acm.c b/drivers/usb/class/cdc-acm.c index b0f9873ce6b7..bcc42136c93f 100644 --- a/drivers/usb/class/cdc-acm.c +++ b/drivers/usb/class/cdc-acm.c @@ -915,7 +915,7 @@ next_desc: } if (data_interface_num != call_interface_num) - dev_dbg(&intf->dev,"Seperate call control interface. That is not fully supported.\n"); + dev_dbg(&intf->dev,"Separate call control interface. That is not fully supported.\n"); skip_normal_probe: diff --git a/drivers/usb/gadget/at91_udc.h b/drivers/usb/gadget/at91_udc.h index aecc7225a8c6..f3095a90a0ee 100644 --- a/drivers/usb/gadget/at91_udc.h +++ b/drivers/usb/gadget/at91_udc.h @@ -53,7 +53,7 @@ #define AT91_UDP_RXRSM (1 << 9) /* USB Resume Interrupt Status */ #define AT91_UDP_EXTRSM (1 << 10) /* External Resume Interrupt Status [AT91RM9200 only] */ #define AT91_UDP_SOFINT (1 << 11) /* Start of Frame Interrupt Status */ -#define AT91_UDP_ENDBUSRES (1 << 12) /* End of Bus Reset Interrpt Status */ +#define AT91_UDP_ENDBUSRES (1 << 12) /* End of Bus Reset Interrupt Status */ #define AT91_UDP_WAKEUP (1 << 13) /* USB Wakeup Interrupt Status [AT91RM9200 only] */ #define AT91_UDP_ICR 0x20 /* Interrupt Clear Register */ diff --git a/drivers/usb/gadget/fsl_usb2_udc.c b/drivers/usb/gadget/fsl_usb2_udc.c index d59eb92a847d..63e8fa3a69e1 100644 --- a/drivers/usb/gadget/fsl_usb2_udc.c +++ b/drivers/usb/gadget/fsl_usb2_udc.c @@ -1896,7 +1896,7 @@ static int fsl_proc_read(char *page, char **start, off_t off, int count, spin_lock_irqsave(&udc->lock, flags); - /* ------basic driver infomation ---- */ + /* ------basic driver information ---- */ t = scnprintf(next, size, DRIVER_DESC "\n" "%s version: %s\n" diff --git a/drivers/usb/gadget/omap_udc.c b/drivers/usb/gadget/omap_udc.c index 7d6bef56cb01..e6d68bda428a 100644 --- a/drivers/usb/gadget/omap_udc.c +++ b/drivers/usb/gadget/omap_udc.c @@ -1028,7 +1028,7 @@ omap_ep_queue(struct usb_ep *_ep, struct usb_request *_req, gfp_t gfp_flags) /* STATUS for zero length DATA stages is * always an IN ... even for IN transfers, - * a wierd case which seem to stall OMAP. + * a weird case which seem to stall OMAP. */ UDC_EP_NUM_REG = (UDC_EP_SEL|UDC_EP_DIR); UDC_CTRL_REG = UDC_CLR_EP; diff --git a/drivers/usb/host/ehci-fsl.c b/drivers/usb/host/ehci-fsl.c index f35795fbd896..adb0defa1631 100644 --- a/drivers/usb/host/ehci-fsl.c +++ b/drivers/usb/host/ehci-fsl.c @@ -25,7 +25,7 @@ #include "ehci-fsl.h" -/* FIXME: Power Managment is un-ported so temporarily disable it */ +/* FIXME: Power Management is un-ported so temporarily disable it */ #undef CONFIG_PM /* PCI-based HCs are common, but plenty of non-PCI HCs are used too */ diff --git a/drivers/usb/host/ehci-sched.c b/drivers/usb/host/ehci-sched.c index 80d99bce2b38..dce305bd62a5 100644 --- a/drivers/usb/host/ehci-sched.c +++ b/drivers/usb/host/ehci-sched.c @@ -211,7 +211,7 @@ static inline void carryover_tt_bandwidth(unsigned short tt_usecs[8]) * low/fullspeed transfer can "carry over" from one uframe to the next, * since the TT just performs downstream transfers in sequence. * - * For example two seperate 100 usec transfers can start in the same uframe, + * For example two separate 100 usec transfers can start in the same uframe, * and the second one would "carry over" 75 usecs into the next uframe. */ static void 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 @@ struct r8a66597_pipe_info { u16 pipenum; - u16 address; /* R8A66597 HCD usb addres */ + u16 address; /* R8A66597 HCD usb address */ u16 epnum; u16 maxpacket; u16 type; diff --git a/drivers/usb/misc/sisusbvga/sisusb.c b/drivers/usb/misc/sisusbvga/sisusb.c index 8832a72bb1fb..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, usb_kill_urb(urb); retval = -ETIMEDOUT; } else { - /* URB completed within timout */ + /* URB completed within timeout */ retval = urb->status; readbytes = urb->actual_length; } diff --git a/drivers/usb/misc/usbtest.c b/drivers/usb/misc/usbtest.c index f1b886c204c0..da922dfc0dcc 100644 --- a/drivers/usb/misc/usbtest.c +++ b/drivers/usb/misc/usbtest.c @@ -1312,7 +1312,7 @@ static int ctrl_out (struct usbtest_dev *dev, len += vary; /* [real world] the "zero bytes IN" case isn't really used. - * hardware can easily trip up in this wierd case, since its + * hardware can easily trip up in this weird case, since its * status stage is IN, not OUT like other ep0in transfers. */ if (len > length) 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) * * This function will block the close until one of the following: * 1. Response to our Chase comes from Edgeport - * 2. A timout of 10 seconds without activity has expired + * 2. A timeout of 10 seconds without activity has expired * (1K of Edgeport data @ 2400 baud ==> 4 sec to empty) * ************************************************************************/ @@ -999,7 +999,7 @@ static void block_until_chase_response(struct edgeport_port *edge_port) return; } } else { - // Reset timout value back to 10 seconds + // Reset timeout value back to 10 seconds dbg("%s - Last %d, Current %d", __FUNCTION__, lastCredits, edge_port->txCredits); loop = 10; } @@ -1014,7 +1014,7 @@ static void block_until_chase_response(struct edgeport_port *edge_port) * This function will block the close until one of the following: * 1. TX count are 0 * 2. The edgeport has stopped - * 3. A timout of 3 seconds without activity has expired + * 3. A timeout of 3 seconds without activity has expired * ************************************************************************/ static 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) return; } } else { - // Reset timout value back to seconds + // Reset timeout value back to seconds loop = 30; } } 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) * This function will block the close until one of the following: * 1. TX count are 0 * 2. The mos7840 has stopped - * 3. A timout of 3 seconds without activity has expired + * 3. A timeout of 3 seconds without activity has expired * ************************************************************************/ static 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) dbg("%s - TIMEOUT", __FUNCTION__); return; } else { - /* Reset timout value back to seconds */ + /* Reset timeout value back to seconds */ wait = 30; } } @@ -1275,7 +1275,7 @@ static void mos7840_close(struct usb_serial_port *port, struct file *filp) * * This function will block the close until one of the following: * 1. Response to our Chase comes from mos7840 - * 2. A timout of 10 seconds without activity has expired + * 2. A timeout of 10 seconds without activity has expired * (1K of mos7840 data @ 2400 baud ==> 4 sec to empty) * ************************************************************************/ @@ -1304,7 +1304,7 @@ static void mos7840_block_until_chase_response(struct moschip_port dbg("%s - TIMEOUT", __FUNCTION__); return; } else { - /* Reset timout value back to seconds */ + /* Reset timeout value back to seconds */ wait = 10; } } -- cgit v1.2.3 From 30bf54e62a7926a483b4e36015bb4eb1372e6303 Mon Sep 17 00:00:00 2001 From: David Brownell Date: Sun, 16 Dec 2007 22:37:40 -0800 Subject: USB: PS3: Fix EHCI ISO transfer bug This adds a workaround for an issue reported with ISO transfers on some EHCI controllers, most recently with VIA KT800 and PS3 EHCI silicon. The issue is that the silicon doesn't necessarily seem to be done using ISO DMA descriptors (itd, sitd) when it marks them inactive. (One theory is that the ill-defined mechanism where hardware caches periodic transfer descriptors isn't invalidating their state...) With such silicon, quick re-use of those descriptors makes trouble. Waiting until the next frame seems to be a sufficient workaround. This patch ensures that the relevant descriptors aren't available for immediate re-use. It does so by not recycling them until after issuing the completion callback which would reuse them by enqueueing an URB and thus (re)allocating ISO DMA descriptors. Signed-off-by: David Brownell Acked-by: Geoff Levand Cc: Masashi Kimoto Signed-off-by: Greg Kroah-Hartman --- drivers/usb/host/ehci-sched.c | 58 +++++++++++++++++++++++++++++++------------ 1 file changed, 42 insertions(+), 16 deletions(-) diff --git a/drivers/usb/host/ehci-sched.c b/drivers/usb/host/ehci-sched.c index dce305bd62a5..1c771045ccaa 100644 --- a/drivers/usb/host/ehci-sched.c +++ b/drivers/usb/host/ehci-sched.c @@ -1565,6 +1565,16 @@ itd_link_urb ( #define ISO_ERRS (EHCI_ISOC_BUF_ERR | EHCI_ISOC_BABBLE | EHCI_ISOC_XACTERR) +/* Process and recycle a completed ITD. Return true iff its urb completed, + * and hence its completion callback probably added things to the hardware + * schedule. + * + * Note that we carefully avoid recycling this descriptor until after any + * completion callback runs, so that it won't be reused quickly. That is, + * assuming (a) no more than two urbs per frame on this endpoint, and also + * (b) only this endpoint's completions submit URBs. It seems some silicon + * corrupts things if you reuse completed descriptors very quickly... + */ static unsigned itd_complete ( struct ehci_hcd *ehci, @@ -1577,6 +1587,7 @@ itd_complete ( int urb_index = -1; struct ehci_iso_stream *stream = itd->stream; struct usb_device *dev; + unsigned retval = false; /* for each uframe with a packet */ for (uframe = 0; uframe < 8; uframe++) { @@ -1610,15 +1621,9 @@ itd_complete ( } } - usb_put_urb (urb); - itd->urb = NULL; - itd->stream = NULL; - list_move (&itd->itd_list, &stream->free_list); - iso_stream_put (ehci, stream); - /* handle completion now? */ if (likely ((urb_index + 1) != urb->number_of_packets)) - return 0; + goto done; /* ASSERT: it's really the last itd for this urb list_for_each_entry (itd, &stream->td_list, itd_list) @@ -1628,6 +1633,7 @@ itd_complete ( /* give urb back to the driver ... can be out-of-order */ dev = urb->dev; ehci_urb_done(ehci, urb, 0); + retval = true; urb = NULL; /* defer stopping schedule; completion can submit */ @@ -1645,8 +1651,15 @@ itd_complete ( (stream->bEndpointAddress & USB_DIR_IN) ? "in" : "out"); } iso_stream_put (ehci, stream); + /* OK to recycle this ITD now that its completion callback ran. */ +done: + usb_put_urb(urb); + itd->urb = NULL; + itd->stream = NULL; + list_move(&itd->itd_list, &stream->free_list); + iso_stream_put(ehci, stream); - return 1; + return retval; } /*-------------------------------------------------------------------------*/ @@ -1950,6 +1963,16 @@ sitd_link_urb ( #define SITD_ERRS (SITD_STS_ERR | SITD_STS_DBE | SITD_STS_BABBLE \ | SITD_STS_XACT | SITD_STS_MMF) +/* Process and recycle a completed SITD. Return true iff its urb completed, + * and hence its completion callback probably added things to the hardware + * schedule. + * + * Note that we carefully avoid recycling this descriptor until after any + * completion callback runs, so that it won't be reused quickly. That is, + * assuming (a) no more than two urbs per frame on this endpoint, and also + * (b) only this endpoint's completions submit URBs. It seems some silicon + * corrupts things if you reuse completed descriptors very quickly... + */ static unsigned sitd_complete ( struct ehci_hcd *ehci, @@ -1961,6 +1984,7 @@ sitd_complete ( int urb_index = -1; struct ehci_iso_stream *stream = sitd->stream; struct usb_device *dev; + unsigned retval = false; urb_index = sitd->index; desc = &urb->iso_frame_desc [urb_index]; @@ -1981,17 +2005,11 @@ sitd_complete ( desc->status = 0; desc->actual_length = desc->length - SITD_LENGTH (t); } - - usb_put_urb (urb); - sitd->urb = NULL; - sitd->stream = NULL; - list_move (&sitd->sitd_list, &stream->free_list); stream->depth -= stream->interval << 3; - iso_stream_put (ehci, stream); /* handle completion now? */ if ((urb_index + 1) != urb->number_of_packets) - return 0; + goto done; /* ASSERT: it's really the last sitd for this urb list_for_each_entry (sitd, &stream->td_list, sitd_list) @@ -2001,6 +2019,7 @@ sitd_complete ( /* give urb back to the driver */ dev = urb->dev; ehci_urb_done(ehci, urb, 0); + retval = true; urb = NULL; /* defer stopping schedule; completion can submit */ @@ -2018,8 +2037,15 @@ sitd_complete ( (stream->bEndpointAddress & USB_DIR_IN) ? "in" : "out"); } iso_stream_put (ehci, stream); + /* OK to recycle this SITD now that its completion callback ran. */ +done: + usb_put_urb(urb); + sitd->urb = NULL; + sitd->stream = NULL; + list_move(&sitd->sitd_list, &stream->free_list); + iso_stream_put(ehci, stream); - return 1; + return retval; } -- cgit v1.2.3 From 0354c1acd8f74e7bda752108c052972a1d1b6c3f Mon Sep 17 00:00:00 2001 From: Marcin Slusarz Date: Sun, 16 Dec 2007 03:21:29 +0100 Subject: USB: usb/storage/initializers.c: fix signedness difference fix warnings: drivers/usb/storage/initializers.c:83:26: warning: incorrect type in argument 5 (different signedness) drivers/usb/storage/initializers.c:83:26: expected unsigned int *act_len drivers/usb/storage/initializers.c:83:26: got int * drivers/usb/storage/initializers.c:89:26: warning: incorrect type in argument 5 (different signedness) drivers/usb/storage/initializers.c:89:26: expected unsigned int *act_len drivers/usb/storage/initializers.c:89:26: got int * Signed-off-by: Marcin Slusarz Signed-off-by: Greg Kroah-Hartman --- drivers/usb/storage/initializers.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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) { struct bulk_cb_wrap *bcb = (struct bulk_cb_wrap*) us->iobuf; struct bulk_cs_wrap *bcs = (struct bulk_cs_wrap*) us->iobuf; - int res, partial; + int res; + unsigned int partial; static char init_string[] = "\xec\x0a\x06\x00$PCCHIPS"; US_DEBUGP("Sending UCR-61S2B initialization packet...\n"); -- cgit v1.2.3 From 7f9705b04c1638b3682f63ece7931384f4542f17 Mon Sep 17 00:00:00 2001 From: Marcin Slusarz Date: Sun, 16 Dec 2007 03:23:20 +0100 Subject: USB: usbdevfs_urb: __user annotation fix warning: drivers/usb/core/devio.c:1226:20: warning: incorrect type in assignment (different address spaces) drivers/usb/core/devio.c:1226:20: expected void *usercontext drivers/usb/core/devio.c:1226:20: got void [noderef] * Signed-off-by: Marcin Slusarz Signed-off-by: Greg Kroah-Hartman --- include/linux/usbdevice_fs.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/linux/usbdevice_fs.h b/include/linux/usbdevice_fs.h index 8ca5a7fbc9ec..17cb108b7db0 100644 --- a/include/linux/usbdevice_fs.h +++ b/include/linux/usbdevice_fs.h @@ -104,7 +104,7 @@ struct usbdevfs_urb { int error_count; unsigned int signr; /* signal to be sent on completion, or 0 if none should be sent. */ - void *usercontext; + void __user *usercontext; struct usbdevfs_iso_packet_desc iso_frame_desc[0]; }; -- cgit v1.2.3 From f570728f89c9d4b262f7c180e5a8e230e675af0c Mon Sep 17 00:00:00 2001 From: Marcin Slusarz Date: Sun, 16 Dec 2007 03:25:13 +0100 Subject: USB: ehci-hcd: fix sparse warning about shadowing 'status' symbol fix warning: drivers/usb/host/ehci-hcd.c:832:8: warning: symbol 'status' shadows an earlier one drivers/usb/host/ehci-hcd.c:790:71: originally declared here Signed-off-by: Marcin Slusarz Signed-off-by: Greg Kroah-Hartman --- drivers/usb/host/ehci-hcd.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/usb/host/ehci-hcd.c b/drivers/usb/host/ehci-hcd.c index 5917c6b7ce33..fb2b227afc4f 100644 --- a/drivers/usb/host/ehci-hcd.c +++ b/drivers/usb/host/ehci-hcd.c @@ -862,16 +862,16 @@ static int ehci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status) /* reschedule QH iff another request is queued */ if (!list_empty (&qh->qtd_list) && HC_IS_RUNNING (hcd->state)) { - int status; + int schedule_status; - status = qh_schedule (ehci, qh); + schedule_status = qh_schedule (ehci, qh); spin_unlock_irqrestore (&ehci->lock, flags); - if (status != 0) { + if (schedule_status != 0) { // shouldn't happen often, but ... // FIXME kill those tds' urbs err ("can't reschedule qh %p, err %d", - qh, status); + qh, schedule_status); } return status; } -- cgit v1.2.3 From e96ffe2f9debd5fdc53144259d9e5faa514736b9 Mon Sep 17 00:00:00 2001 From: Tzachi Perelstein Date: Sat, 1 Dec 2007 11:07:04 -0500 Subject: USB: add Marvell Orion USB host support Some glue bits for the on-chip USB host controller in the Marvell Orion family of ARM SoCs, which is basically EHCI compatible. Signed-off-by: Tzachi Perelstein Reviewed-by: Lennert Buytenhek Signed-off-by: David Brownell Signed-off-by: Greg Kroah-Hartman --- drivers/usb/host/ehci-hcd.c | 5 + drivers/usb/host/ehci-orion.c | 272 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 277 insertions(+) create mode 100644 drivers/usb/host/ehci-orion.c diff --git a/drivers/usb/host/ehci-hcd.c b/drivers/usb/host/ehci-hcd.c index fb2b227afc4f..7c5c8796d175 100644 --- a/drivers/usb/host/ehci-hcd.c +++ b/drivers/usb/host/ehci-hcd.c @@ -998,6 +998,11 @@ MODULE_LICENSE ("GPL"); #define PLATFORM_DRIVER ehci_ppc_soc_driver #endif +#ifdef CONFIG_ARCH_ORION +#include "ehci-orion.c" +#define PLATFORM_DRIVER ehci_orion_driver +#endif + #if !defined(PCI_DRIVER) && !defined(PLATFORM_DRIVER) && \ !defined(PS3_SYSTEM_BUS_DRIVER) #error "missing bus glue for ehci-hcd" 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 @@ +/* + * drivers/usb/host/ehci-orion.c + * + * Tzachi Perelstein + * + * This file is licensed under the terms of the GNU General Public + * License version 2. This program is licensed "as is" without any + * warranty of any kind, whether express or implied. + */ + +#include +#include +#include +#include + +#define rdl(off) __raw_readl(hcd->regs + (off)) +#define wrl(off, val) __raw_writel((val), hcd->regs + (off)) + +#define USB_CAUSE 0x310 +#define USB_MASK 0x314 +#define USB_CMD 0x140 +#define USB_MODE 0x1a8 +#define USB_IPG 0x360 +#define USB_PHY_PWR_CTRL 0x400 +#define USB_PHY_TX_CTRL 0x420 +#define USB_PHY_RX_CTRL 0x430 +#define USB_PHY_IVREF_CTRL 0x440 +#define USB_PHY_TST_GRP_CTRL 0x450 + +/* + * Implement Orion USB controller specification guidelines + */ +static void orion_usb_setup(struct usb_hcd *hcd) +{ + /* + * Clear interrupt cause and mask + */ + wrl(USB_CAUSE, 0); + wrl(USB_MASK, 0); + + /* + * Reset controller + */ + wrl(USB_CMD, rdl(USB_CMD) | 0x2); + while (rdl(USB_CMD) & 0x2); + + /* + * GL# USB-10: Set IPG for non start of frame packets + * Bits[14:8]=0xc + */ + wrl(USB_IPG, (rdl(USB_IPG) & ~0x7f00) | 0xc00); + + /* + * GL# USB-9: USB 2.0 Power Control + * BG_VSEL[7:6]=0x1 + */ + wrl(USB_PHY_PWR_CTRL, (rdl(USB_PHY_PWR_CTRL) & ~0xc0)| 0x40); + + /* + * GL# USB-1: USB PHY Tx Control - force calibration to '8' + * TXDATA_BLOCK_EN[21]=0x1, EXT_RCAL_EN[13]=0x1, IMP_CAL[6:3]=0x8 + */ + wrl(USB_PHY_TX_CTRL, (rdl(USB_PHY_TX_CTRL) & ~0x78) | 0x202040); + + /* + * GL# USB-3 GL# USB-9: USB PHY Rx Control + * RXDATA_BLOCK_LENGHT[31:30]=0x3, EDGE_DET_SEL[27:26]=0, + * CDR_FASTLOCK_EN[21]=0, DISCON_THRESHOLD[9:8]=0, SQ_THRESH[7:4]=0x1 + */ + wrl(USB_PHY_RX_CTRL, (rdl(USB_PHY_RX_CTRL) & ~0xc2003f0) | 0xc0000010); + + /* + * GL# USB-3 GL# USB-9: USB PHY IVREF Control + * PLLVDD12[1:0]=0x2, RXVDD[5:4]=0x3, Reserved[19]=0 + */ + wrl(USB_PHY_IVREF_CTRL, (rdl(USB_PHY_IVREF_CTRL) & ~0x80003 ) | 0x32); + + /* + * GL# USB-3 GL# USB-9: USB PHY Test Group Control + * REG_FIFO_SQ_RST[15]=0 + */ + wrl(USB_PHY_TST_GRP_CTRL, rdl(USB_PHY_TST_GRP_CTRL) & ~0x8000); + + /* + * Stop and reset controller + */ + wrl(USB_CMD, rdl(USB_CMD) & ~0x1); + wrl(USB_CMD, rdl(USB_CMD) | 0x2); + while (rdl(USB_CMD) & 0x2); + + /* + * GL# USB-5 Streaming disable REG_USB_MODE[4]=1 + * TBD: This need to be done after each reset! + * GL# USB-4 Setup USB Host mode + */ + wrl(USB_MODE, 0x13); +} + +static int ehci_orion_setup(struct usb_hcd *hcd) +{ + struct ehci_hcd *ehci = hcd_to_ehci(hcd); + int retval; + + retval = ehci_halt(ehci); + if (retval) + return retval; + + /* + * data structure init + */ + retval = ehci_init(hcd); + if (retval) + return retval; + + ehci_reset(ehci); + ehci_port_power(ehci, 0); + + return retval; +} + +static const struct hc_driver ehci_orion_hc_driver = { + .description = hcd_name, + .product_desc = "Marvell Orion EHCI", + .hcd_priv_size = sizeof(struct ehci_hcd), + + /* + * generic hardware linkage + */ + .irq = ehci_irq, + .flags = HCD_MEMORY | HCD_USB2, + + /* + * basic lifecycle operations + */ + .reset = ehci_orion_setup, + .start = ehci_run, +#ifdef CONFIG_PM + .suspend = ehci_bus_suspend, + .resume = ehci_bus_resume, +#endif + .stop = ehci_stop, + .shutdown = ehci_shutdown, + + /* + * managing i/o requests and associated device resources + */ + .urb_enqueue = ehci_urb_enqueue, + .urb_dequeue = ehci_urb_dequeue, + .endpoint_disable = ehci_endpoint_disable, + + /* + * scheduling support + */ + .get_frame_number = ehci_get_frame, + + /* + * root hub support + */ + .hub_status_data = ehci_hub_status_data, + .hub_control = ehci_hub_control, + .bus_suspend = ehci_bus_suspend, + .bus_resume = ehci_bus_resume, +}; + +static int __init ehci_orion_drv_probe(struct platform_device *pdev) +{ + struct resource *res; + struct usb_hcd *hcd; + struct ehci_hcd *ehci; + void __iomem *regs; + int irq, err; + + if (usb_disabled()) + return -ENODEV; + + pr_debug("Initializing Orion-SoC USB Host Controller\n"); + + irq = platform_get_irq(pdev, 0); + if (irq <= 0) { + dev_err(&pdev->dev, + "Found HC with no IRQ. Check %s setup!\n", + pdev->dev.bus_id); + err = -ENODEV; + goto err1; + } + + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); + if (!res) { + dev_err(&pdev->dev, + "Found HC with no register addr. Check %s setup!\n", + pdev->dev.bus_id); + err = -ENODEV; + goto err1; + } + + if (!request_mem_region(res->start, res->end - res->start + 1, + ehci_orion_hc_driver.description)) { + dev_dbg(&pdev->dev, "controller already in use\n"); + err = -EBUSY; + goto err1; + } + + regs = ioremap(res->start, res->end - res->start + 1); + if (regs == NULL) { + dev_dbg(&pdev->dev, "error mapping memory\n"); + err = -EFAULT; + goto err2; + } + + hcd = usb_create_hcd(&ehci_orion_hc_driver, + &pdev->dev, pdev->dev.bus_id); + if (!hcd) { + err = -ENOMEM; + goto err3; + } + + hcd->rsrc_start = res->start; + hcd->rsrc_len = res->end - res->start + 1; + hcd->regs = regs; + + ehci = hcd_to_ehci(hcd); + ehci->caps = hcd->regs + 0x100; + ehci->regs = hcd->regs + 0x100 + + HC_LENGTH(ehci_readl(ehci, &ehci->caps->hc_capbase)); + ehci->hcs_params = ehci_readl(ehci, &ehci->caps->hcs_params); + ehci->is_tdi_rh_tt = 1; + ehci->sbrn = 0x20; + + /* + * setup Orion USB controller + */ + orion_usb_setup(hcd); + + err = usb_add_hcd(hcd, irq, IRQF_SHARED | IRQF_DISABLED); + if (err) + goto err4; + + return 0; + +err4: + usb_put_hcd(hcd); +err3: + iounmap(regs); +err2: + release_mem_region(res->start, res->end - res->start + 1); +err1: + dev_err(&pdev->dev, "init %s fail, %d\n", + pdev->dev.bus_id, err); + + return err; +} + +static int __exit ehci_orion_drv_remove(struct platform_device *pdev) +{ + struct usb_hcd *hcd = platform_get_drvdata(pdev); + + usb_remove_hcd(hcd); + iounmap(hcd->regs); + release_mem_region(hcd->rsrc_start, hcd->rsrc_len); + usb_put_hcd(hcd); + + return 0; +} + +MODULE_ALIAS("platform:orion-ehci"); + +static struct platform_driver ehci_orion_driver = { + .probe = ehci_orion_drv_probe, + .remove = __exit_p(ehci_orion_drv_remove), + .shutdown = usb_hcd_platform_shutdown, + .driver.name = "orion-ehci", +}; -- cgit v1.2.3 From 340ba5f9cee6c7096162bfb2e0f7589f1ce0e142 Mon Sep 17 00:00:00 2001 From: David Brownell Date: Wed, 19 Dec 2007 11:30:39 -0800 Subject: USB: ehci potential oops fix on ARC/TDI cores Kernel bugzilla entry #9569 reports a potential OOPS in some code supporting the integrated root hub TT support used on ARC/TDI derived cores. (This seems to have been a longstanding issue.) This patch cleans up usage of urb->dev->tt to avoid that potential oops and also fixes some overly long lines. Signed-off-by: David Brownell Signed-off-by: Greg Kroah-Hartman --- drivers/usb/host/ehci-q.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/drivers/usb/host/ehci-q.c b/drivers/usb/host/ehci-q.c index 853e5e6396a5..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 ( /* if async CSPLIT failed, try cleaning out the TT buffer */ if (status != -EPIPE - && urb->dev->tt && !usb_pipeint (urb->pipe) + && urb->dev->tt + && !usb_pipeint(urb->pipe) && ((token & QTD_STS_MMF) != 0 || QTD_CERR(token) == 0) && (!ehci_is_TDI(ehci) @@ -211,6 +212,9 @@ static int qtd_copy_status ( urb->dev->ttport, urb->dev->devnum, usb_pipeendpoint (urb->pipe), token); #endif /* DEBUG */ + /* REVISIT ARC-derived cores don't clear the root + * hub TT buffer in this way... + */ usb_hub_tt_clear_buffer (urb->dev, urb->pipe); } } @@ -638,6 +642,7 @@ qh_make ( u32 info1 = 0, info2 = 0; int is_input, type; int maxp = 0; + struct usb_tt *tt = urb->dev->tt; if (!qh) return qh; @@ -661,8 +666,9 @@ qh_make ( * For control/bulk requests, the HC or TT handles these. */ if (type == PIPE_INTERRUPT) { - qh->usecs = NS_TO_US (usb_calc_bus_time (USB_SPEED_HIGH, is_input, 0, - hb_mult (maxp) * max_packet (maxp))); + qh->usecs = NS_TO_US(usb_calc_bus_time(USB_SPEED_HIGH, + is_input, 0, + hb_mult(maxp) * max_packet(maxp))); qh->start = NO_FRAME; if (urb->dev->speed == USB_SPEED_HIGH) { @@ -680,7 +686,6 @@ qh_make ( goto done; } } else { - struct usb_tt *tt = urb->dev->tt; int think_time; /* gap is f(FS/LS transfer times) */ @@ -736,10 +741,8 @@ qh_make ( /* set the address of the TT; for TDI's integrated * root hub tt, leave it zeroed. */ - if (!ehci_is_TDI(ehci) - || urb->dev->tt->hub != - ehci_to_hcd(ehci)->self.root_hub) - info2 |= urb->dev->tt->hub->devnum << 16; + if (tt && tt->hub != ehci_to_hcd(ehci)->self.root_hub) + info2 |= tt->hub->devnum << 16; /* NOTE: if (PIPE_INTERRUPT) { scheduler sets c-mask } */ -- cgit v1.2.3 From e7b13ec9235b9fded90f826ceeb8c34548631351 Mon Sep 17 00:00:00 2001 From: David Brownell Date: Wed, 19 Dec 2007 11:27:51 -0800 Subject: USB: gadget: ethernet error path potential oops fix Fix potential (never-observed) oops on rare error path, bugzilla #9594. Fix uses the same test as used earlier. Also make the adjacent "else" block look like an "else" block instead of hiding like a bug. Signed-off-by: David Brownell Signed-off-by: Greg Kroah-Hartman --- drivers/usb/gadget/ether.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 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: /* on error, disable any endpoints */ if (result < 0) { - if (!subset_active(dev)) + if (!subset_active(dev) && dev->status_ep) (void) usb_ep_disable (dev->status_ep); dev->status = NULL; (void) usb_ep_disable (dev->in_ep); (void) usb_ep_disable (dev->out_ep); dev->in = NULL; dev->out = NULL; - } else + } /* activate non-CDC configs right away * this isn't strictly according to the RNDIS spec */ - if (!cdc_active (dev)) { + else if (!cdc_active (dev)) { netif_carrier_on (dev->net); if (netif_running (dev->net)) { spin_unlock (&dev->lock); -- cgit v1.2.3 From e58679805dab3fb75df88141d9d869904a93337f Mon Sep 17 00:00:00 2001 From: Oliver Neukum Date: Thu, 20 Dec 2007 12:23:03 +0100 Subject: USB: fix NULL pointer dereference on drivers/usb/serial/whiteheat.c Am Sonntag, 16. Dezember 2007 05:23:47 schrieb Andrew Morton: > On Sat, 15 Dec 2007 07:08:52 -0800 (PST) bugme-daemon@bugzilla.kernel.org wrote: > > > http://bugzilla.kernel.org/show_bug.cgi?id=9573 > > There's a null pointer dereference on drivers/usb/serial/whiteheat.c as > > follows: > > > > (1) line 613: the test "if (port->tty)" implies that null is a legal value > > for "port->tty" at that point > > > > (2) neither firm_open nor firm_purge initialize "port->tty" drivers/usb/serial/usb-serial::serial_open() sets port->tty The check for NULL is bogus. This patch removes the check. Signed-off-by: Oliver Neukum Acked-by: Alan Cox Signed-off-by: Greg Kroah-Hartman --- drivers/usb/serial/whiteheat.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/usb/serial/whiteheat.c b/drivers/usb/serial/whiteheat.c index ee5dd8b5a713..f5033d482eee 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) if (retval) goto exit; - if (port->tty) - port->tty->low_latency = 1; + port->tty->low_latency = 1; /* send an open port command */ retval = firm_open(port); -- cgit v1.2.3 From 1440e0967de8c598dae96d741652d498b3eb8f27 Mon Sep 17 00:00:00 2001 From: David Brownell Date: Sun, 9 Dec 2007 22:53:09 -0800 Subject: USB: gadget: at91_udc minor fix (there is no number six) Fix a small glitch noted by Yannick Cote. There is no endpoint number six, so if a (broken) host wrongly tried to change or read status of that endpoint, the driver could access reserved register space. Signed-off-by: David Brownell Cc: Yannick Cote Signed-off-by: Greg Kroah-Hartman --- drivers/usb/gadget/at91_udc.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/usb/gadget/at91_udc.c b/drivers/usb/gadget/at91_udc.c index 4b6ed353ae36..305db36a3b1c 100644 --- a/drivers/usb/gadget/at91_udc.c +++ b/drivers/usb/gadget/at91_udc.c @@ -1153,7 +1153,7 @@ static void handle_setup(struct at91_udc *udc, struct at91_ep *ep, u32 csr) | USB_REQ_GET_STATUS: tmp = w_index & USB_ENDPOINT_NUMBER_MASK; ep = &udc->ep[tmp]; - if (tmp > NUM_ENDPOINTS || (tmp && !ep->desc)) + if (tmp >= NUM_ENDPOINTS || (tmp && !ep->desc)) goto stall; if (tmp) { @@ -1176,7 +1176,7 @@ static void handle_setup(struct at91_udc *udc, struct at91_ep *ep, u32 csr) | USB_REQ_SET_FEATURE: tmp = w_index & USB_ENDPOINT_NUMBER_MASK; ep = &udc->ep[tmp]; - if (w_value != USB_ENDPOINT_HALT || tmp > NUM_ENDPOINTS) + if (w_value != USB_ENDPOINT_HALT || tmp >= NUM_ENDPOINTS) goto stall; if (!ep->desc || ep->is_iso) goto stall; @@ -1195,7 +1195,7 @@ static void handle_setup(struct at91_udc *udc, struct at91_ep *ep, u32 csr) | USB_REQ_CLEAR_FEATURE: tmp = w_index & USB_ENDPOINT_NUMBER_MASK; ep = &udc->ep[tmp]; - if (w_value != USB_ENDPOINT_HALT || tmp > NUM_ENDPOINTS) + if (w_value != USB_ENDPOINT_HALT || tmp >= NUM_ENDPOINTS) goto stall; if (tmp == 0) goto succeed; -- cgit v1.2.3 From e057a35aa140b5e5d01603f78845ad328dde302a Mon Sep 17 00:00:00 2001 From: David Brownell Date: Fri, 21 Dec 2007 00:29:05 -0800 Subject: USB: fix HCD Kconfig goofage Add a missing dependency which goofs up the xconfig display. Signed-off-by: David Brownell Signed-off-by: Greg Kroah-Hartman --- drivers/usb/host/Kconfig | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/usb/host/Kconfig b/drivers/usb/host/Kconfig index 49a91c5ee51b..9b202d5f88c0 100644 --- a/drivers/usb/host/Kconfig +++ b/drivers/usb/host/Kconfig @@ -79,6 +79,7 @@ config USB_EHCI_BIG_ENDIAN_DESC config USB_EHCI_FSL bool + depends on USB_EHCI_HCD select USB_EHCI_ROOT_HUB_TT default y if MPC834x || PPC_MPC831x ---help--- -- cgit v1.2.3 From 487dc9225a8e7cc522177316abee7b1e272a2863 Mon Sep 17 00:00:00 2001 From: Dmitry Baryshkov Date: Fri, 21 Dec 2007 12:18:01 +0300 Subject: USB: tosa_udc_use_gpio_vbus.patch Use gpio_vbus instead of udc_is_connected for udc on tosa. Signed-off-by: Dmitry Baryshkov Acked-by: Russell King Signed-off-by: Greg Kroah-Hartman --- arch/arm/mach-pxa/tosa.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/arch/arm/mach-pxa/tosa.c b/arch/arm/mach-pxa/tosa.c index 1919756900f4..1a9c844ac7eb 100644 --- a/arch/arm/mach-pxa/tosa.c +++ b/arch/arm/mach-pxa/tosa.c @@ -157,15 +157,10 @@ static void tosa_udc_command(int cmd) } } -static int tosa_udc_is_connected(void) -{ - return ((GPLR(TOSA_GPIO_USB_IN) & GPIO_bit(TOSA_GPIO_USB_IN)) == 0); -} - - static struct pxa2xx_udc_mach_info udc_info __initdata = { .udc_command = tosa_udc_command, - .udc_is_connected = tosa_udc_is_connected, + .gpio_vbus = TOSA_GPIO_USB_IN, + .gpio_vbus_inverted = 1, }; /* -- cgit v1.2.3 From 65d063ab21feea8cf65d64fba50a5c4fa7bfd6be Mon Sep 17 00:00:00 2001 From: Alan Cox Date: Thu, 3 Jan 2008 17:01:18 +0000 Subject: USB: mos7720: clean up termios Remove lots of NULL checks that can no longer occur Encode the baud rate back into the termios (again someone with docs see FIXME to improve this further) Signed-off-by: Alan Cox Signed-off-by: Greg Kroah-Hartman --- drivers/usb/serial/mos7720.c | 28 ++++++++-------------------- 1 file changed, 8 insertions(+), 20 deletions(-) diff --git a/drivers/usb/serial/mos7720.c b/drivers/usb/serial/mos7720.c index e02c198016b0..725991fadc26 100644 --- a/drivers/usb/serial/mos7720.c +++ b/drivers/usb/serial/mos7720.c @@ -1040,11 +1040,6 @@ static void change_port_settings(struct moschip_port *mos7720_port, tty = mos7720_port->port->tty; - if ((!tty) || (!tty->termios)) { - dbg("%s - no tty structures", __FUNCTION__); - return; - } - dbg("%s: Entering ..........", __FUNCTION__); lData = UART_LCR_WLEN8; @@ -1175,7 +1170,10 @@ static void change_port_settings(struct moschip_port *mos7720_port, dbg("%s - baud rate = %d", __FUNCTION__, baud); status = send_cmd_write_baud_rate(mos7720_port, baud); - + /* FIXME: needs to write actual resulting baud back not just + blindly do so */ + if (cflag & CBAUD) + tty_encode_baud_rate(tty, baud, baud); /* Enable Interrupts */ data = 0x0c; send_mos_cmd(serial, MOS_WRITE, port_number, UART_IER, &data); @@ -1214,10 +1212,6 @@ static void mos7720_set_termios(struct usb_serial_port *port, tty = port->tty; - if (!port->tty || !port->tty->termios) { - dbg("%s - no tty or termios", __FUNCTION__); - return; - } if (!mos7720_port->open) { dbg("%s - port not opened", __FUNCTION__); @@ -1228,19 +1222,13 @@ static void mos7720_set_termios(struct usb_serial_port *port, cflag = tty->termios->c_cflag; - if (!cflag) { - printk("%s %s\n",__FUNCTION__,"cflag is NULL"); - return; - } - - dbg("%s - clfag %08x iflag %08x", __FUNCTION__, + dbg("%s - cflag %08x iflag %08x", __FUNCTION__, tty->termios->c_cflag, RELEVANT_IFLAG(tty->termios->c_iflag)); - if (old_termios) - dbg("%s - old clfag %08x old iflag %08x", __FUNCTION__, - old_termios->c_cflag, - RELEVANT_IFLAG(old_termios->c_iflag)); + dbg("%s - old cflag %08x old iflag %08x", __FUNCTION__, + old_termios->c_cflag, + RELEVANT_IFLAG(old_termios->c_iflag)); dbg("%s - port %d", __FUNCTION__, port->number); -- cgit v1.2.3 From 537699ef53f8b97546f0845bf51a49c9ab114a13 Mon Sep 17 00:00:00 2001 From: Alan Cox Date: Thu, 3 Jan 2008 17:03:11 +0000 Subject: USB: ti_usb: termios cleanups Remove internal NULL passing in termios code Remove all the if checks it causes Encode the baud rate back properly Clear CMSPAR as it is not supported Signed-off-by: Alan Cox Signed-off-by: Greg Kroah-Hartman --- drivers/usb/serial/ti_usb_3410_5052.c | 31 +++++++++++++------------------ 1 file changed, 13 insertions(+), 18 deletions(-) diff --git a/drivers/usb/serial/ti_usb_3410_5052.c b/drivers/usb/serial/ti_usb_3410_5052.c index 995fdf3c4898..70f56c8aef99 100644 --- a/drivers/usb/serial/ti_usb_3410_5052.c +++ b/drivers/usb/serial/ti_usb_3410_5052.c @@ -581,7 +581,7 @@ static int ti_open(struct usb_serial_port *port, struct file *file) } } - ti_set_termios(port, NULL); + ti_set_termios(port, port->tty->termios); dbg("%s - sending TI_OPEN_PORT", __FUNCTION__); status = ti_command_out_sync(tdev, TI_OPEN_PORT, @@ -618,7 +618,7 @@ static int ti_open(struct usb_serial_port *port, struct file *file) usb_clear_halt(dev, port->write_urb->pipe); usb_clear_halt(dev, port->read_urb->pipe); - ti_set_termios(port, NULL); + ti_set_termios(port, port->tty->termios); dbg("%s - sending TI_OPEN_PORT (2)", __FUNCTION__); status = ti_command_out_sync(tdev, TI_OPEN_PORT, @@ -897,24 +897,11 @@ static void ti_set_termios(struct usb_serial_port *port, dbg("%s - port %d", __FUNCTION__, port->number); - if (!tty || !tty->termios) { - dbg("%s - no tty or termios", __FUNCTION__); - return; - } - cflag = tty->termios->c_cflag; iflag = tty->termios->c_iflag; - if (old_termios && cflag == old_termios->c_cflag - && iflag == old_termios->c_iflag) { - dbg("%s - nothing to change", __FUNCTION__); - return; - } - - dbg("%s - clfag %08x, iflag %08x", __FUNCTION__, cflag, iflag); - - if (old_termios) - dbg("%s - old clfag %08x, old iflag %08x", __FUNCTION__, old_termios->c_cflag, old_termios->c_iflag); + dbg("%s - cflag %08x, iflag %08x", __FUNCTION__, cflag, iflag); + dbg("%s - old clfag %08x, old iflag %08x", __FUNCTION__, old_termios->c_cflag, old_termios->c_iflag); if (tport == NULL) return; @@ -948,6 +935,9 @@ static void ti_set_termios(struct usb_serial_port *port, break; } + /* CMSPAR isn't supported by this driver */ + tty->termios->c_cflag &= ~CMSPAR; + if (cflag & PARENB) { if (cflag & PARODD) { config->wFlags |= TI_UART_ENABLE_PARITY_CHECKING; @@ -990,12 +980,17 @@ static void ti_set_termios(struct usb_serial_port *port, } baud = tty_get_baud_rate(tty); - if (!baud) baud = 9600; + if (!baud) + baud = 9600; if (tport->tp_tdev->td_is_3410) config->wBaudRate = (__u16)((923077 + baud/2) / baud); else config->wBaudRate = (__u16)((461538 + baud/2) / baud); + /* FIXME: Should calculate resulting baud here and report it back */ + if ((cflag & CBAUD) != B0) + tty_encode_baud_rate(tty, baud, baud); + dbg("%s - BaudRate=%d, wBaudRate=%d, wFlags=0x%04X, bDataBits=%d, bParity=%d, bStopBits=%d, cXon=%d, cXoff=%d, bUartMode=%d", __FUNCTION__, baud, config->wBaudRate, config->wFlags, config->bDataBits, config->bParity, config->bStopBits, config->cXon, config->cXoff, config->bUartMode); -- cgit v1.2.3 From d5f5bcd425b771c0b7ff5a650b2ce061ac8bbb87 Mon Sep 17 00:00:00 2001 From: Alan Cox Date: Thu, 3 Jan 2008 16:57:33 +0000 Subject: USB: io_ti: clean up termios handling Don't pass NULL into termios functions when calling them internally Remove all the crap which then checks for NULL which can't occur now Clear CMSPAR as it is not supported Report the baud rate back to the caller properly (See FIXME someone with the docs) Signed-off-by: Alan Cox Signed-off-by: Greg Kroah-Hartman --- drivers/usb/serial/io_ti.c | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/drivers/usb/serial/io_ti.c b/drivers/usb/serial/io_ti.c index f7fdf1ce6bf3..cd3405953f74 100644 --- a/drivers/usb/serial/io_ti.c +++ b/drivers/usb/serial/io_ti.c @@ -1979,7 +1979,7 @@ static int edge_open (struct usb_serial_port *port, struct file * filp) } /* set up the port settings */ - edge_set_termios (port, NULL); + edge_set_termios (port, port->tty->termios); /* open up the port */ @@ -2394,11 +2394,6 @@ static void change_port_settings (struct edgeport_port *edge_port, struct ktermi dbg("%s - port %d", __FUNCTION__, edge_port->port->number); tty = edge_port->port->tty; - if ((!tty) || - (!tty->termios)) { - dbg("%s - no tty structures", __FUNCTION__); - return; - } config = kmalloc (sizeof (*config), GFP_KERNEL); if (!config) { @@ -2493,15 +2488,21 @@ static void change_port_settings (struct edgeport_port *edge_port, struct ktermi } } + tty->termios->c_cflag &= ~CMSPAR; + /* Round the baud rate */ baud = tty_get_baud_rate(tty); if (!baud) { /* pick a default, any default... */ baud = 9600; - } + } else + tty_encode_baud_rate(tty, baud, baud); + edge_port->baud_rate = baud; config->wBaudRate = (__u16)((461550L + baud/2) / baud); + /* FIXME: Recompute actual baud from divisor here */ + dbg ("%s - baud rate = %d, wBaudRate = %d", __FUNCTION__, baud, config->wBaudRate); dbg ("wBaudRate: %d", (int)(461550L / config->wBaudRate)); @@ -2539,19 +2540,12 @@ static void edge_set_termios (struct usb_serial_port *port, struct ktermios *old struct tty_struct *tty = port->tty; unsigned int cflag; - if (!port->tty || !port->tty->termios) { - dbg ("%s - no tty or termios", __FUNCTION__); - return; - } - cflag = tty->termios->c_cflag; dbg("%s - clfag %08x iflag %08x", __FUNCTION__, tty->termios->c_cflag, tty->termios->c_iflag); - if (old_termios) { - dbg("%s - old clfag %08x old iflag %08x", __FUNCTION__, - old_termios->c_cflag, old_termios->c_iflag); - } + dbg("%s - old clfag %08x old iflag %08x", __FUNCTION__, + old_termios->c_cflag, old_termios->c_iflag); dbg("%s - port %d", __FUNCTION__, port->number); -- cgit v1.2.3 From 20734345b35a5ff661293fcca1e376522bcf01de Mon Sep 17 00:00:00 2001 From: Harald Welte Date: Tue, 1 Jan 2008 15:08:35 +0100 Subject: USB: ftdi_sio: Support for more JTAG adaptors [PATCH] ftdi_sio: add support for more FTDI based JTAG adaptors There are more devices similar to the Olimex JTAG adaptor, in that the first port of the FT2232C is used for JTAG, and only the second port is available as UART. I have thus renamed ftdi_olimex_{probe,quirk} to ftdi_jtag_{probe,quirk} and added vendor/product ID's for the OpenMoko Neo1973 Debug Board as well as the OOCDlink device. I've also updated the KERN_INFO message sent to userspace to remove the word 'olimex' and an extra '\n' that was causing an empty line in dmesg. Signed-off-by: Harald Welte Signed-off-by: Greg Kroah-Hartman --- drivers/usb/serial/ftdi_sio.c | 21 +++++++++++++-------- drivers/usb/serial/ftdi_sio.h | 11 +++++++++++ 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/drivers/usb/serial/ftdi_sio.c b/drivers/usb/serial/ftdi_sio.c index 1382af97db72..7200eaeb513b 100644 --- a/drivers/usb/serial/ftdi_sio.c +++ b/drivers/usb/serial/ftdi_sio.c @@ -309,12 +309,12 @@ struct ftdi_sio_quirk { void (*port_probe)(struct ftdi_private *); /* Special settings for probed ports. */ }; -static int ftdi_olimex_probe (struct usb_serial *serial); +static int ftdi_jtag_probe (struct usb_serial *serial); static void ftdi_USB_UIRT_setup (struct ftdi_private *priv); static void ftdi_HE_TIRA1_setup (struct ftdi_private *priv); -static struct ftdi_sio_quirk ftdi_olimex_quirk = { - .probe = ftdi_olimex_probe, +static struct ftdi_sio_quirk ftdi_jtag_quirk = { + .probe = ftdi_jtag_probe, }; static struct ftdi_sio_quirk ftdi_USB_UIRT_quirk = { @@ -570,7 +570,11 @@ static struct usb_device_id id_table_combined [] = { { USB_DEVICE(TML_VID, TML_USB_SERIAL_PID) }, { USB_DEVICE(FTDI_VID, FTDI_ELSTER_UNICOM_PID) }, { USB_DEVICE(OLIMEX_VID, OLIMEX_ARM_USB_OCD_PID), - .driver_info = (kernel_ulong_t)&ftdi_olimex_quirk }, + .driver_info = (kernel_ulong_t)&ftdi_jtag_quirk }, + { USB_DEVICE(FIC_VID, FIC_NEO1973_DEBUG_PID), + .driver_info = (kernel_ulong_t)&ftdi_jtag_quirk }, + { USB_DEVICE(FTDI_VID, FTDI_OOCDLINK_PID), + .driver_info = (kernel_ulong_t)&ftdi_jtag_quirk }, { }, /* Optional parameter entry */ { } /* Terminating entry */ }; @@ -1283,10 +1287,11 @@ static void ftdi_HE_TIRA1_setup (struct ftdi_private *priv) } /* ftdi_HE_TIRA1_setup */ /* - * First port on Olimex arm-usb-ocd is reserved for JTAG interface - * and can be accessed from userspace using openocd. + * First port on JTAG adaptors such as Olimex arm-usb-ocd or the FIC/OpenMoko + * Neo1973 Debug Board is reserved for JTAG interface and can be accessed from + * userspace using openocd. */ -static int ftdi_olimex_probe(struct usb_serial *serial) +static int ftdi_jtag_probe(struct usb_serial *serial) { struct usb_device *udev = serial->dev; struct usb_interface *interface = serial->interface; @@ -1294,7 +1299,7 @@ static int ftdi_olimex_probe(struct usb_serial *serial) dbg("%s",__FUNCTION__); if (interface == udev->actconfig->interface[0]) { - info("Ignoring reserved serial port on Olimex arm-usb-ocd\n"); + info("Ignoring serial port reserved for JTAG"); return -ENODEV; } diff --git a/drivers/usb/serial/ftdi_sio.h b/drivers/usb/serial/ftdi_sio.h index f6053daf02fb..6eee2ab914ec 100644 --- a/drivers/usb/serial/ftdi_sio.h +++ b/drivers/usb/serial/ftdi_sio.h @@ -98,6 +98,10 @@ #define FTDI_MTXORB_5_PID 0xFA05 /* Matrix Orbital Product Id */ #define FTDI_MTXORB_6_PID 0xFA06 /* Matrix Orbital Product Id */ +/* OOCDlink by Joern Kaipf + * (http://www.joernonline.de/dw/doku.php?id=start&idx=projects:oocdlink) */ +#define FTDI_OOCDLINK_PID 0xbaf8 /* Amontec JTAGkey */ + /* Interbiometrics USB I/O Board */ /* Developed for Interbiometrics by Rudolf Gugler */ #define INTERBIOMETRICS_VID 0x1209 @@ -559,6 +563,13 @@ #define FTDI_SIO_GET_LATENCY_TIMER 10 /* Get the latency timer */ +/* + * FIC / OpenMoko, Inc. http://wiki.openmoko.org/wiki/Neo1973_Debug_Board_v3 + * Submitted by Harald Welte + */ +#define FIC_VID 0x1457 +#define FIC_NEO1973_DEBUG_PID 0x5118 + /* * BmRequestType: 1100 0000b * bRequest: FTDI_E2_READ -- cgit v1.2.3 From 228426edac844a2c9270528e9cd7ab6260ef7628 Mon Sep 17 00:00:00 2001 From: Kevin Lloyd Date: Thu, 10 Jan 2008 11:11:04 -0800 Subject: USB: sierra driver - add update dtr logic The following improvements were made: - Fixed control line issue where asserting DTR on ep5 would close ep2 - Added support for calc_num_ports (will help support future composite devices) Signed-off-by: Kevin Lloyd Signed-off-by: Greg Kroah-Hartman --- drivers/usb/serial/sierra.c | 221 ++++++++++++++++++++++---------------------- 1 file changed, 110 insertions(+), 111 deletions(-) diff --git a/drivers/usb/serial/sierra.c b/drivers/usb/serial/sierra.c index b4d7ac948533..953bdf8827d2 100644 --- a/drivers/usb/serial/sierra.c +++ b/drivers/usb/serial/sierra.c @@ -1,7 +1,7 @@ /* USB Driver for Sierra Wireless - Copyright (C) 2006, 2007 Kevin Lloyd + Copyright (C) 2006, 2007, 2008 Kevin Lloyd IMPORTANT DISCLAIMER: This driver is not commercially supported by Sierra Wireless. Use at your own risk. @@ -14,7 +14,7 @@ Whom based his on the Keyspan driver by Hugh Blemings */ -#define DRIVER_VERSION "v.1.2.5b" +#define DRIVER_VERSION "v.1.2.7" #define DRIVER_AUTHOR "Kevin Lloyd " #define DRIVER_DESC "USB Driver for Sierra Wireless USB modems" @@ -26,10 +26,12 @@ #include #include #include +#include +#define SWIMS_USB_REQUEST_SetPower 0x00 +#define SWIMS_USB_REQUEST_SetNmea 0x07 #define SWIMS_USB_REQUEST_SetMode 0x0B -#define SWIMS_USB_REQUEST_TYPE_SetMode 0x40 -#define SWIMS_USB_INDEX_SetMode 0x0000 +#define SWIMS_USB_REQUEST_TYPE_VSC_SET 0x40 #define SWIMS_SET_MODE_Modem 0x0001 /* per port private data */ @@ -38,6 +40,8 @@ #define IN_BUFLEN 4096 static int debug; +static int nmea; +static int truinstall = 1; enum devicetype { DEVICE_3_PORT = 0, @@ -50,48 +54,96 @@ static int sierra_set_power_state(struct usb_device *udev, __u16 swiState) int result; dev_dbg(&udev->dev, "%s", "SET POWER STATE\n"); result = usb_control_msg(udev, usb_sndctrlpipe(udev, 0), - 0x00, /* __u8 request */ - 0x40, /* __u8 request type */ - swiState, /* __u16 value */ - 0, /* __u16 index */ - NULL, /* void *data */ - 0, /* __u16 size */ - USB_CTRL_SET_TIMEOUT); /* int timeout */ + SWIMS_USB_REQUEST_SetPower, /* __u8 request */ + SWIMS_USB_REQUEST_TYPE_VSC_SET, /* __u8 request type */ + swiState, /* __u16 value */ + 0, /* __u16 index */ + NULL, /* void *data */ + 0, /* __u16 size */ + USB_CTRL_SET_TIMEOUT); /* int timeout */ return result; } -static int sierra_set_ms_mode(struct usb_device *udev, __u16 eSocMode) +static int sierra_set_ms_mode(struct usb_device *udev, __u16 eSWocMode) { int result; dev_dbg(&udev->dev, "%s", "DEVICE MODE SWITCH\n"); result = usb_control_msg(udev, usb_sndctrlpipe(udev, 0), SWIMS_USB_REQUEST_SetMode, /* __u8 request */ - SWIMS_USB_REQUEST_TYPE_SetMode, /* __u8 request type */ - eSocMode, /* __u16 value */ - SWIMS_USB_INDEX_SetMode, /* __u16 index */ + SWIMS_USB_REQUEST_TYPE_VSC_SET, /* __u8 request type */ + eSWocMode, /* __u16 value */ + 0x0000, /* __u16 index */ NULL, /* void *data */ 0, /* __u16 size */ USB_CTRL_SET_TIMEOUT); /* int timeout */ return result; } -static int sierra_probe(struct usb_interface *iface, - const struct usb_device_id *id) +static int sierra_vsc_set_nmea(struct usb_device *udev, __u16 enable) { int result; + dev_dbg(&udev->dev, "%s", "NMEA Enable sent\n"); + result = usb_control_msg(udev, usb_sndctrlpipe(udev, 0), + SWIMS_USB_REQUEST_SetNmea, /* __u8 request */ + SWIMS_USB_REQUEST_TYPE_VSC_SET, /* __u8 request type */ + enable, /* __u16 value */ + 0x0000, /* __u16 index */ + NULL, /* void *data */ + 0, /* __u16 size */ + USB_CTRL_SET_TIMEOUT); /* int timeout */ + return result; +} + +static int sierra_calc_num_ports(struct usb_serial *serial) +{ + int result; + int *num_ports = usb_get_serial_data(serial); + + result = *num_ports; + + if (result) { + kfree(num_ports); + usb_set_serial_data(serial, NULL); + } + + return result; +} + +static int sierra_probe(struct usb_serial *serial, + const struct usb_device_id *id) +{ + int result = 0; struct usb_device *udev; + int *num_ports; + u8 ifnum; - udev = usb_get_dev(interface_to_usbdev(iface)); + num_ports = kmalloc(sizeof(*num_ports), GFP_KERNEL); + if (!num_ports) + return -ENOMEM; + + ifnum = serial->interface->cur_altsetting->desc.bInterfaceNumber; + udev = serial->dev; /* Check if in installer mode */ - if (id->driver_info == DEVICE_INSTALLER) { - dev_dbg(&udev->dev, "%s", "FOUND DEVICE(SW)\n"); + if (truinstall && id->driver_info == DEVICE_INSTALLER) { + dev_dbg(&udev->dev, "%s", "FOUND TRU-INSTALL DEVICE(SW)\n"); result = sierra_set_ms_mode(udev, SWIMS_SET_MODE_Modem); - /*We do not want to bind to the device when in installer mode*/ + /* Don't bind to the device when in installer mode */ + kfree(num_ports); return -EIO; - } + } else if (id->driver_info == DEVICE_1_PORT) + *num_ports = 1; + else if (ifnum == 0x99) + *num_ports = 0; + else + *num_ports = 3; + /* + * save off our num_ports info so that we can use it in the + * calc_num_ports callback + */ + usb_set_serial_data(serial, (void *)num_ports); - return usb_serial_probe(iface, id); + return result; } static struct usb_device_id id_table [] = { @@ -133,53 +185,14 @@ static struct usb_device_id id_table [] = { }; MODULE_DEVICE_TABLE(usb, id_table); -static struct usb_device_id id_table_1port [] = { - { USB_DEVICE(0x1199, 0x0112) }, /* Sierra Wireless AirCard 580 */ - { USB_DEVICE(0x0F3D, 0x0112) }, /* AirPrime/Sierra PC 5220 */ - { USB_DEVICE(0x05C6, 0x6613) }, /* Onda H600/ZTE MF330 */ - { } -}; - -static struct usb_device_id id_table_3port [] = { - { USB_DEVICE(0x1199, 0x0017) }, /* Sierra Wireless EM5625 */ - { USB_DEVICE(0x1199, 0x0018) }, /* Sierra Wireless MC5720 */ - { USB_DEVICE(0x0f30, 0x1b1d) }, /* Sierra Wireless MC5720 */ - { USB_DEVICE(0x1199, 0x0218) }, /* Sierra Wireless MC5720 */ - { USB_DEVICE(0x1199, 0x0020) }, /* Sierra Wireless MC5725 */ - { USB_DEVICE(0x1199, 0x0220) }, /* Sierra Wireless MC5725 */ - { USB_DEVICE(0x1199, 0x0019) }, /* Sierra Wireless AirCard 595 */ - { USB_DEVICE(0x1199, 0x0021) }, /* Sierra Wireless AirCard 597E */ - { USB_DEVICE(0x1199, 0x0120) }, /* Sierra Wireless USB Dongle 595U*/ - { USB_DEVICE(0x1199, 0x0023) }, /* Sierra Wireless AirCard */ - - { USB_DEVICE(0x1199, 0x6802) }, /* Sierra Wireless MC8755 */ - { USB_DEVICE(0x1199, 0x6804) }, /* Sierra Wireless MC8755 */ - { USB_DEVICE(0x1199, 0x6803) }, /* Sierra Wireless MC8765 */ - { USB_DEVICE(0x1199, 0x6812) }, /* Sierra Wireless MC8775 & AC 875U */ - { USB_DEVICE(0x1199, 0x6813) }, /* Sierra Wireless MC8775 (Thinkpad internal) */ - { USB_DEVICE(0x1199, 0x6820) }, /* Sierra Wireless AirCard 875 */ - { USB_DEVICE(0x1199, 0x6832) }, /* Sierra Wireless MC8780*/ - { USB_DEVICE(0x1199, 0x6833) }, /* Sierra Wireless MC8781*/ - { USB_DEVICE(0x1199, 0x6850) }, /* Sierra Wireless AirCard 880 */ - { USB_DEVICE(0x1199, 0x6851) }, /* Sierra Wireless AirCard 881 */ - { USB_DEVICE(0x1199, 0x6852) }, /* Sierra Wireless AirCard 880E */ - { USB_DEVICE(0x1199, 0x6853) }, /* Sierra Wireless AirCard 881E */ - { USB_DEVICE(0x1199, 0x6855) }, /* Sierra Wireless AirCard 880 U */ - { USB_DEVICE(0x1199, 0x6856) }, /* Sierra Wireless AirCard 881U */ - { USB_DEVICE(0x1199, 0x6468) }, /* Sierra Wireless MP3G - EVDO */ - { USB_DEVICE(0x1199, 0x6469) }, /* Sierra Wireless MP3G - UMTS/HSPA */ - { } -}; - static struct usb_driver sierra_driver = { .name = "sierra", - .probe = sierra_probe, + .probe = usb_serial_probe, .disconnect = usb_serial_disconnect, .id_table = id_table, .no_dynamic_id = 1, }; - struct sierra_port_private { spinlock_t lock; /* lock the structure */ int outstanding_urbs; /* number of out urbs in flight */ @@ -201,6 +214,7 @@ static int sierra_send_setup(struct usb_serial_port *port) { struct usb_serial *serial = port->serial; struct sierra_port_private *portdata; + __u16 interface = 0; dbg("%s", __FUNCTION__); @@ -213,9 +227,18 @@ static int sierra_send_setup(struct usb_serial_port *port) if (portdata->rts_state) val |= 0x02; + /* Determine which port is targeted */ + if (port->bulk_out_endpointAddress == 2) + interface = 0; + else if (port->bulk_out_endpointAddress == 4) + interface = 1; + else if (port->bulk_out_endpointAddress == 5) + interface = 2; + return usb_control_msg(serial->dev, usb_rcvctrlpipe(serial->dev, 0), - 0x22,0x21,val,0,NULL,0,USB_CTRL_SET_TIMEOUT); + 0x22, 0x21, val, interface, + NULL, 0, USB_CTRL_SET_TIMEOUT); } return 0; @@ -596,9 +619,13 @@ static int sierra_startup(struct usb_serial *serial) dbg("%s", __FUNCTION__); - /*Set Device mode to D0 */ + /* Set Device mode to D0 */ sierra_set_power_state(serial->dev, 0x0000); + /* Check NMEA and set */ + if (nmea) + sierra_vsc_set_nmea(serial->dev, 1); + /* Now setup per port private data */ for (i = 0; i < serial->num_ports; i++) { port = serial->port[i]; @@ -659,47 +686,19 @@ static void sierra_shutdown(struct usb_serial *serial) } } -static struct usb_serial_driver sierra_1port_device = { +static struct usb_serial_driver sierra_device = { .driver = { .owner = THIS_MODULE, .name = "sierra1", }, - .description = "Sierra USB modem (1 port)", - .id_table = id_table_1port, + .description = "Sierra USB modem", + .id_table = id_table, .usb_driver = &sierra_driver, .num_interrupt_in = NUM_DONT_CARE, - .num_bulk_in = 1, - .num_bulk_out = 1, - .num_ports = 1, - .open = sierra_open, - .close = sierra_close, - .write = sierra_write, - .write_room = sierra_write_room, - .chars_in_buffer = sierra_chars_in_buffer, - .throttle = sierra_rx_throttle, - .unthrottle = sierra_rx_unthrottle, - .ioctl = sierra_ioctl, - .set_termios = sierra_set_termios, - .break_ctl = sierra_break_ctl, - .tiocmget = sierra_tiocmget, - .tiocmset = sierra_tiocmset, - .attach = sierra_startup, - .shutdown = sierra_shutdown, - .read_int_callback = sierra_instat_callback, -}; - -static struct usb_serial_driver sierra_3port_device = { - .driver = { - .owner = THIS_MODULE, - .name = "sierra3", - }, - .description = "Sierra USB modem (3 port)", - .id_table = id_table_3port, - .usb_driver = &sierra_driver, - .num_interrupt_in = NUM_DONT_CARE, - .num_bulk_in = 3, - .num_bulk_out = 3, - .num_ports = 3, + .num_bulk_in = NUM_DONT_CARE, + .num_bulk_out = NUM_DONT_CARE, + .calc_num_ports = sierra_calc_num_ports, + .probe = sierra_probe, .open = sierra_open, .close = sierra_close, .write = sierra_write, @@ -721,12 +720,9 @@ static struct usb_serial_driver sierra_3port_device = { static int __init sierra_init(void) { int retval; - retval = usb_serial_register(&sierra_1port_device); - if (retval) - goto failed_1port_device_register; - retval = usb_serial_register(&sierra_3port_device); + retval = usb_serial_register(&sierra_device); if (retval) - goto failed_3port_device_register; + goto failed_device_register; retval = usb_register(&sierra_driver); @@ -738,18 +734,15 @@ static int __init sierra_init(void) return 0; failed_driver_register: - usb_serial_deregister(&sierra_3port_device); -failed_3port_device_register: - usb_serial_deregister(&sierra_1port_device); -failed_1port_device_register: + usb_serial_deregister(&sierra_device); +failed_device_register: return retval; } static void __exit sierra_exit(void) { usb_deregister (&sierra_driver); - usb_serial_deregister(&sierra_1port_device); - usb_serial_deregister(&sierra_3port_device); + usb_serial_deregister(&sierra_device); } module_init(sierra_init); @@ -760,6 +753,12 @@ MODULE_DESCRIPTION(DRIVER_DESC); MODULE_VERSION(DRIVER_VERSION); MODULE_LICENSE("GPL"); +module_param(truinstall, bool, 0); +MODULE_PARM_DESC(truinstall, "TRU-Install support"); + +module_param(nmea, bool, 0); +MODULE_PARM_DESC(nmea, "NMEA streaming"); + #ifdef CONFIG_USB_DEBUG module_param(debug, bool, S_IRUGO | S_IWUSR); MODULE_PARM_DESC(debug, "Debug messages"); -- cgit v1.2.3 From 1512300689426cb98bfd7e567ee9fdfaaf61b7c7 Mon Sep 17 00:00:00 2001 From: Sarah Sharp Date: Fri, 21 Dec 2007 16:54:15 -0800 Subject: USB: Export suspend statistics This patch exports two statistics to userspace: /sys/bus/usb/device/.../power/connected_duration /sys/bus/usb/device/.../power/active_duration connected_duration is the total time (in msec) that the device has been connected. active_duration is the total time the device has not been suspended. With these two statistics, tools like PowerTOP can calculate the percentage time that a device is active, i.e. not suspended or auto-suspended. Users can also use the active_duration to check if a device is actually autosuspended. Currently, they can set power/level to auto and power/autosuspend to a positive timeout, but there's no way to know from userspace if a device was actually autosuspended without looking at the dmesg output. These statistics will be useful in creating an automated userspace script to test autosuspend for USB devices. Signed-off-by: Sarah Sharp Signed-off-by: Greg Kroah-Hartman --- drivers/usb/core/hub.c | 10 +++++++++- drivers/usb/core/sysfs.c | 49 ++++++++++++++++++++++++++++++++++++++++++++++++ drivers/usb/core/usb.c | 2 ++ include/linux/usb.h | 3 +++ 4 files changed, 63 insertions(+), 1 deletion(-) diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c index cc93aa9336fe..53fe049b40f5 100644 --- a/drivers/usb/core/hub.c +++ b/drivers/usb/core/hub.c @@ -1034,8 +1034,10 @@ static void recursively_mark_NOTATTACHED(struct usb_device *udev) if (udev->children[i]) recursively_mark_NOTATTACHED(udev->children[i]); } - if (udev->state == USB_STATE_SUSPENDED) + if (udev->state == USB_STATE_SUSPENDED) { udev->discon_suspended = 1; + udev->active_duration -= jiffies; + } udev->state = USB_STATE_NOTATTACHED; } @@ -1084,6 +1086,12 @@ void usb_set_device_state(struct usb_device *udev, else device_init_wakeup(&udev->dev, 0); } + if (udev->state == USB_STATE_SUSPENDED && + new_state != USB_STATE_SUSPENDED) + udev->active_duration -= jiffies; + else if (new_state == USB_STATE_SUSPENDED && + udev->state != USB_STATE_SUSPENDED) + udev->active_duration += jiffies; udev->state = new_state; } else recursively_mark_NOTATTACHED(udev); diff --git a/drivers/usb/core/sysfs.c b/drivers/usb/core/sysfs.c index 32bd130b1eed..021b1d37462c 100644 --- a/drivers/usb/core/sysfs.c +++ b/drivers/usb/core/sysfs.c @@ -248,6 +248,41 @@ static void remove_persist_attributes(struct device *dev) #ifdef CONFIG_USB_SUSPEND +static ssize_t +show_connected_duration(struct device *dev, struct device_attribute *attr, + char *buf) +{ + struct usb_device *udev = to_usb_device(dev); + + return sprintf(buf, "%u\n", + jiffies_to_msecs(jiffies - udev->connect_time)); +} + +static DEVICE_ATTR(connected_duration, S_IRUGO, show_connected_duration, NULL); + +/* + * If the device is resumed, the last time the device was suspended has + * been pre-subtracted from active_duration. We add the current time to + * get the duration that the device was actually active. + * + * If the device is suspended, the active_duration is up-to-date. + */ +static ssize_t +show_active_duration(struct device *dev, struct device_attribute *attr, + char *buf) +{ + struct usb_device *udev = to_usb_device(dev); + int duration; + + if (udev->state != USB_STATE_SUSPENDED) + duration = jiffies_to_msecs(jiffies + udev->active_duration); + else + duration = jiffies_to_msecs(udev->active_duration); + return sprintf(buf, "%u\n", duration); +} + +static DEVICE_ATTR(active_duration, S_IRUGO, show_active_duration, NULL); + static ssize_t show_autosuspend(struct device *dev, struct device_attribute *attr, char *buf) { @@ -365,12 +400,26 @@ static int add_power_attributes(struct device *dev) rc = sysfs_add_file_to_group(&dev->kobj, &dev_attr_level.attr, power_group); + if (rc == 0) + rc = sysfs_add_file_to_group(&dev->kobj, + &dev_attr_connected_duration.attr, + power_group); + if (rc == 0) + rc = sysfs_add_file_to_group(&dev->kobj, + &dev_attr_active_duration.attr, + power_group); } return rc; } static void remove_power_attributes(struct device *dev) { + sysfs_remove_file_from_group(&dev->kobj, + &dev_attr_active_duration.attr, + power_group); + sysfs_remove_file_from_group(&dev->kobj, + &dev_attr_connected_duration.attr, + power_group); sysfs_remove_file_from_group(&dev->kobj, &dev_attr_level.attr, power_group); diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c index bc5edacb0c34..fdb444d81271 100644 --- a/drivers/usb/core/usb.c +++ b/drivers/usb/core/usb.c @@ -339,6 +339,8 @@ usb_alloc_dev(struct usb_device *parent, struct usb_bus *bus, unsigned port1) mutex_init(&dev->pm_mutex); INIT_DELAYED_WORK(&dev->autosuspend, usb_autosuspend_work); dev->autosuspend_delay = usb_autosuspend_delay * HZ; + dev->connect_time = jiffies; + dev->active_duration = -jiffies; #endif if (root_hub) /* Root hub always ok [and always wired] */ dev->authorized = 1; diff --git a/include/linux/usb.h b/include/linux/usb.h index 8aae045e9a2e..f8a60756fe2a 100644 --- a/include/linux/usb.h +++ b/include/linux/usb.h @@ -419,12 +419,15 @@ struct usb_device { u32 quirks; /* quirks of the whole device */ atomic_t urbnum; /* number of URBs submitted for the whole device */ + unsigned long active_duration; /* total time device is not suspended */ + #ifdef CONFIG_PM struct delayed_work autosuspend; /* for delayed autosuspends */ struct mutex pm_mutex; /* protects PM operations */ unsigned long last_busy; /* time of last use */ int autosuspend_delay; /* in jiffies */ + unsigned long connect_time; /* time device was first connected */ unsigned auto_pm:1; /* autosuspend/resume in progress */ unsigned do_remote_wakeup:1; /* remote wakeup should be enabled */ -- cgit v1.2.3 From 979e524a9c563376af096d2d8629b9969fc06659 Mon Sep 17 00:00:00 2001 From: Sarah Sharp Date: Thu, 17 Jan 2008 10:24:38 -0800 Subject: USB: Add documentation for USB suspend statistics. This documents two newly created files: /sys/bus/usb/device/.../power/connected_duration /sys/bus/usb/device/.../power/active_duration Documentation was placed in Documentation/ABI/testing, since that's where the documentation is for the other USB sysfs power files. Signed-off-by: Sarah Sharp Signed-off-by: Greg Kroah-Hartman --- Documentation/ABI/testing/sysfs-bus-usb | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/Documentation/ABI/testing/sysfs-bus-usb b/Documentation/ABI/testing/sysfs-bus-usb index 9734577d1711..11a3c1682cec 100644 --- a/Documentation/ABI/testing/sysfs-bus-usb +++ b/Documentation/ABI/testing/sysfs-bus-usb @@ -52,3 +52,36 @@ Description: facility is inherently dangerous, it is disabled by default for all devices except hubs. For more information, see Documentation/usb/persist.txt. + +What: /sys/bus/usb/device/.../power/connected_duration +Date: January 2008 +KernelVersion: 2.6.25 +Contact: Sarah Sharp +Description: + If CONFIG_PM and CONFIG_USB_SUSPEND are enabled, then this file + is present. When read, it returns the total time (in msec) + that the USB device has been connected to the machine. This + file is read-only. +Users: + PowerTOP + http://www.lesswatts.org/projects/powertop/ + +What: /sys/bus/usb/device/.../power/active_duration +Date: January 2008 +KernelVersion: 2.6.25 +Contact: Sarah Sharp +Description: + If CONFIG_PM and CONFIG_USB_SUSPEND are enabled, then this file + is present. When read, it returns the total time (in msec) + that the USB device has been active, i.e. not in a suspended + state. This file is read-only. + + Tools can use this file and the connected_duration file to + compute the percentage of time that a device has been active. + For example, + echo $((100 * `cat active_duration` / `cat connected_duration`)) + will give an integer percentage. Note that this does not + account for counter wrap. +Users: + PowerTOP + http://www.lesswatts.org/projects/powertop/ -- cgit v1.2.3 From 4bde4a4c4ff53e67cde4b0fe630d6fc28106bff8 Mon Sep 17 00:00:00 2001 From: David Brownell Date: Thu, 27 Dec 2007 11:19:49 -0800 Subject: USB: ohci-at91 uses generic GPIO calls Update the ohci-at91 bus glue to start understanding about the per-port power switch GPIOs it's given (on the sam9263-ek and potentially other boards). For the moment this just claims them and forces them active (assuming active-low power enables) whenever the HCD is loaded. The assumption is still that board setup configures the GPIOs. Using gpio_request() tracks actual usage and guards against conflict. Signed-off-by: David Brownell Signed-off-by: Greg Kroah-Hartman --- drivers/usb/host/ohci-at91.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) 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 @@ #include #include +#include + #include #include @@ -271,12 +273,41 @@ static const struct hc_driver ohci_at91_hc_driver = { static int ohci_hcd_at91_drv_probe(struct platform_device *pdev) { + struct at91_usbh_data *pdata = pdev->dev.platform_data; + int i; + + if (pdata) { + /* REVISIT make the driver support per-port power switching, + * and also overcurrent detection. Here we assume the ports + * are always powered while this driver is active, and use + * active-low power switches. + */ + for (i = 0; i < pdata->ports; i++) { + if (pdata->vbus_pin[i] <= 0) + continue; + gpio_request(pdata->vbus_pin[i], "ohci_vbus"); + gpio_direction_output(pdata->vbus_pin[i], 0); + } + } + device_init_wakeup(&pdev->dev, 1); return usb_hcd_at91_probe(&ohci_at91_hc_driver, pdev); } static int ohci_hcd_at91_drv_remove(struct platform_device *pdev) { + struct at91_usbh_data *pdata = pdev->dev.platform_data; + int i; + + if (pdata) { + for (i = 0; i < pdata->ports; i++) { + if (pdata->vbus_pin[i] <= 0) + continue; + gpio_direction_output(pdata->vbus_pin[i], 1); + gpio_free(pdata->vbus_pin[i]); + } + } + device_init_wakeup(&pdev->dev, 0); return usb_hcd_at91_remove(platform_get_drvdata(pdev), pdev); } -- cgit v1.2.3 From f3db6e82034a6ea89191fdcc6b9a984dc0d5d533 Mon Sep 17 00:00:00 2001 From: David Brownell Date: Sat, 5 Jan 2008 13:21:43 -0800 Subject: USB: at91_udc uses generic GPIO calls; minor cleanup Various small at91_udc cleanups: - Use generic GPIO calls, not older platform-specific ones - Use gpio_request()/gpio_free() - Use VERBOSE_DEBUG convention, not older VERBOSE - Fix sparse complaint about parameter type (changed to gfp_t) - Add missing newline to some rarely-seen debug messages - Fix some old cleanup bugs on probe() fault paths Also add a mechanism whereby rm9200 gpios can drive the D+ pullup through an inverting transistor, based on a patch from Steve Birtles. Most UDC drivers supporting a GPIO based pullup should probably have such an option, but testing it requries such a board in hand! Signed-off-by: David Brownell Cc: Steve Birtles Signed-off-by: Greg Kroah-Hartman --- drivers/usb/gadget/at91_udc.c | 79 +++++++++++++++++++++++++++++---------- drivers/usb/gadget/at91_udc.h | 2 +- include/asm-arm/arch-at91/board.h | 3 +- 3 files changed, 63 insertions(+), 21 deletions(-) diff --git a/drivers/usb/gadget/at91_udc.c b/drivers/usb/gadget/at91_udc.c index 305db36a3b1c..a83e8b798ec9 100644 --- a/drivers/usb/gadget/at91_udc.c +++ b/drivers/usb/gadget/at91_udc.c @@ -21,8 +21,7 @@ * Boston, MA 02111-1307, USA. */ -#undef DEBUG -#undef VERBOSE +#undef VERBOSE_DEBUG #undef PACKET_TRACE #include @@ -46,8 +45,8 @@ #include #include #include +#include -#include #include #include #include @@ -580,7 +579,7 @@ static int at91_ep_disable (struct usb_ep * _ep) */ static struct usb_request * -at91_ep_alloc_request(struct usb_ep *_ep, unsigned int gfp_flags) +at91_ep_alloc_request(struct usb_ep *_ep, gfp_t gfp_flags) { struct at91_request *req; @@ -881,6 +880,8 @@ static void clk_off(struct at91_udc *udc) */ static void pullup(struct at91_udc *udc, int is_on) { + int active = !udc->board.pullup_active_low; + if (!udc->enabled || !udc->vbus) is_on = 0; DBG("%sactive\n", is_on ? "" : "in"); @@ -890,7 +891,7 @@ static void pullup(struct at91_udc *udc, int is_on) at91_udp_write(udc, AT91_UDP_ICR, AT91_UDP_RXRSM); at91_udp_write(udc, AT91_UDP_TXVC, 0); if (cpu_is_at91rm9200()) - at91_set_gpio_value(udc->board.pullup_pin, 1); + gpio_set_value(udc->board.pullup_pin, active); else if (cpu_is_at91sam9260() || cpu_is_at91sam9263()) { u32 txvc = at91_udp_read(udc, AT91_UDP_TXVC); @@ -908,7 +909,7 @@ static void pullup(struct at91_udc *udc, int is_on) at91_udp_write(udc, AT91_UDP_IDR, AT91_UDP_RXRSM); at91_udp_write(udc, AT91_UDP_TXVC, AT91_UDP_TXVC_TXVDIS); if (cpu_is_at91rm9200()) - at91_set_gpio_value(udc->board.pullup_pin, 0); + gpio_set_value(udc->board.pullup_pin, !active); else if (cpu_is_at91sam9260() || cpu_is_at91sam9263()) { u32 txvc = at91_udp_read(udc, AT91_UDP_TXVC); @@ -1551,7 +1552,7 @@ static irqreturn_t at91_vbus_irq(int irq, void *_udc) /* vbus needs at least brief debouncing */ udelay(10); - value = at91_get_gpio_value(udc->board.vbus_pin); + value = gpio_get_value(udc->board.vbus_pin); if (value != udc->vbus) at91_vbus_session(&udc->gadget, value); @@ -1647,12 +1648,12 @@ static int __init at91udc_probe(struct platform_device *pdev) } if (pdev->num_resources != 2) { - DBG("invalid num_resources"); + DBG("invalid num_resources\n"); return -ENODEV; } if ((pdev->resource[0].flags != IORESOURCE_MEM) || (pdev->resource[1].flags != IORESOURCE_IRQ)) { - DBG("invalid resource type"); + DBG("invalid resource type\n"); return -ENODEV; } @@ -1674,10 +1675,26 @@ static int __init at91udc_probe(struct platform_device *pdev) udc->pdev = pdev; udc->enabled = 0; + /* rm9200 needs manual D+ pullup; off by default */ + if (cpu_is_at91rm9200()) { + if (udc->board.pullup_pin <= 0) { + DBG("no D+ pullup?\n"); + retval = -ENODEV; + goto fail0; + } + retval = gpio_request(udc->board.pullup_pin, "udc_pullup"); + if (retval) { + DBG("D+ pullup is busy\n"); + goto fail0; + } + gpio_direction_output(udc->board.pullup_pin, + udc->board.pullup_active_low); + } + udc->udp_baseaddr = ioremap(res->start, res->end - res->start + 1); if (!udc->udp_baseaddr) { - release_mem_region(res->start, res->end - res->start + 1); - return -ENOMEM; + retval = -ENOMEM; + goto fail0a; } udc_reinit(udc); @@ -1688,12 +1705,13 @@ static int __init at91udc_probe(struct platform_device *pdev) if (IS_ERR(udc->iclk) || IS_ERR(udc->fclk)) { DBG("clocks missing\n"); retval = -ENODEV; - goto fail0; + /* NOTE: we "know" here that refcounts on these are NOPs */ + goto fail0b; } retval = device_register(&udc->gadget.dev); if (retval < 0) - goto fail0; + goto fail0b; /* don't do anything until we have both gadget driver and VBUS */ clk_enable(udc->iclk); @@ -1705,25 +1723,32 @@ static int __init at91udc_probe(struct platform_device *pdev) /* request UDC and maybe VBUS irqs */ udc->udp_irq = platform_get_irq(pdev, 0); - if (request_irq(udc->udp_irq, at91_udc_irq, - IRQF_DISABLED, driver_name, udc)) { + retval = request_irq(udc->udp_irq, at91_udc_irq, + IRQF_DISABLED, driver_name, udc); + if (retval < 0) { DBG("request irq %d failed\n", udc->udp_irq); - retval = -EBUSY; goto fail1; } if (udc->board.vbus_pin > 0) { + retval = gpio_request(udc->board.vbus_pin, "udc_vbus"); + if (retval < 0) { + DBG("request vbus pin failed\n"); + goto fail2; + } + gpio_direction_input(udc->board.vbus_pin); + /* * Get the initial state of VBUS - we cannot expect * a pending interrupt. */ - udc->vbus = at91_get_gpio_value(udc->board.vbus_pin); + udc->vbus = gpio_get_value(udc->board.vbus_pin); if (request_irq(udc->board.vbus_pin, at91_vbus_irq, IRQF_DISABLED, driver_name, udc)) { DBG("request vbus irq %d failed\n", udc->board.vbus_pin); free_irq(udc->udp_irq, udc); retval = -EBUSY; - goto fail1; + goto fail3; } } else { DBG("no VBUS detection, assuming always-on\n"); @@ -1736,8 +1761,18 @@ static int __init at91udc_probe(struct platform_device *pdev) INFO("%s version %s\n", driver_name, DRIVER_VERSION); return 0; +fail3: + if (udc->board.vbus_pin > 0) + gpio_free(udc->board.vbus_pin); +fail2: + free_irq(udc->udp_irq, udc); fail1: device_unregister(&udc->gadget.dev); +fail0b: + iounmap(udc->udp_baseaddr); +fail0a: + if (cpu_is_at91rm9200()) + gpio_free(udc->board.pullup_pin); fail0: release_mem_region(res->start, res->end - res->start + 1); DBG("%s probe failed, %d\n", driver_name, retval); @@ -1758,12 +1793,18 @@ static int __exit at91udc_remove(struct platform_device *pdev) device_init_wakeup(&pdev->dev, 0); remove_debug_file(udc); - if (udc->board.vbus_pin > 0) + if (udc->board.vbus_pin > 0) { free_irq(udc->board.vbus_pin, udc); + gpio_free(udc->board.vbus_pin); + } free_irq(udc->udp_irq, udc); device_unregister(&udc->gadget.dev); iounmap(udc->udp_baseaddr); + + if (cpu_is_at91rm9200()) + gpio_free(udc->board.pullup_pin); + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); release_mem_region(res->start, res->end - res->start + 1); diff --git a/drivers/usb/gadget/at91_udc.h b/drivers/usb/gadget/at91_udc.h index f3095a90a0ee..a973f2a50fb9 100644 --- a/drivers/usb/gadget/at91_udc.h +++ b/drivers/usb/gadget/at91_udc.h @@ -158,7 +158,7 @@ struct at91_request { /*-------------------------------------------------------------------------*/ -#ifdef VERBOSE +#ifdef VERBOSE_DEBUG # define VDBG DBG #else # define VDBG(stuff...) do{}while(0) diff --git a/include/asm-arm/arch-at91/board.h b/include/asm-arm/arch-at91/board.h index 55b07bd5316c..dc189f01c5b3 100644 --- a/include/asm-arm/arch-at91/board.h +++ b/include/asm-arm/arch-at91/board.h @@ -40,7 +40,8 @@ /* USB Device */ struct at91_udc_data { u8 vbus_pin; /* high == host powering us */ - u8 pullup_pin; /* high == D+ pulled up */ + u8 pullup_pin; /* active == D+ pulled up */ + u8 pullup_active_low; /* true == pullup_pin is active low */ }; extern void __init at91_add_device_udc(struct at91_udc_data *data); -- cgit v1.2.3 From 040fa1b9620cd019349414505828b2ffbeded7f8 Mon Sep 17 00:00:00 2001 From: Dmitry Baryshkov Date: Sun, 30 Dec 2007 11:56:27 -0800 Subject: USB: pxa2xx_udc: use debugfs not procfs Use debugfs instead of /proc/driver/udc Signed-off-by: Dmitry Baryshkov Signed-off-by: David Brownell Signed-off-by: Greg Kroah-Hartman --- drivers/usb/gadget/pxa2xx_udc.c | 117 ++++++++++++++++++---------------------- drivers/usb/gadget/pxa2xx_udc.h | 14 +++-- 2 files changed, 62 insertions(+), 69 deletions(-) diff --git a/drivers/usb/gadget/pxa2xx_udc.c b/drivers/usb/gadget/pxa2xx_udc.c index 8bd9ce26bd95..4402d6f042d9 100644 --- a/drivers/usb/gadget/pxa2xx_udc.c +++ b/drivers/usb/gadget/pxa2xx_udc.c @@ -24,7 +24,7 @@ * */ -// #define VERBOSE DBG_VERBOSE +/* #define VERBOSE_DEBUG */ #include #include @@ -38,13 +38,14 @@ #include #include #include -#include #include #include #include #include #include #include +#include +#include #include #include @@ -679,7 +680,7 @@ pxa2xx_ep_queue(struct usb_ep *_ep, struct usb_request *_req, gfp_t gfp_flags) /* kickstart this i/o queue? */ if (list_empty(&ep->queue) && !ep->stopped) { - if (ep->desc == 0 /* ep0 */) { + if (ep->desc == NULL/* ep0 */) { unsigned length = _req->length; switch (dev->ep0state) { @@ -733,7 +734,7 @@ pxa2xx_ep_queue(struct usb_ep *_ep, struct usb_request *_req, gfp_t gfp_flags) } /* pio or dma irq handler advances the queue. */ - if (likely (req != 0)) + if (likely(req != NULL)) list_add_tail(&req->queue, &ep->queue); local_irq_restore(flags); @@ -993,45 +994,32 @@ static const struct usb_gadget_ops pxa2xx_udc_ops = { /*-------------------------------------------------------------------------*/ -#ifdef CONFIG_USB_GADGET_DEBUG_FILES - -static const char proc_node_name [] = "driver/udc"; +#ifdef CONFIG_USB_GADGET_DEBUG_FS static int -udc_proc_read(char *page, char **start, off_t off, int count, - int *eof, void *_dev) +udc_seq_show(struct seq_file *m, void *d) { - char *buf = page; - struct pxa2xx_udc *dev = _dev; - char *next = buf; - unsigned size = count; + struct pxa2xx_udc *dev = m->private; unsigned long flags; - int i, t; + int i; u32 tmp; - if (off != 0) - return 0; - local_irq_save(flags); /* basic device status */ - t = scnprintf(next, size, DRIVER_DESC "\n" + seq_printf(m, DRIVER_DESC "\n" "%s version: %s\nGadget driver: %s\nHost %s\n\n", driver_name, DRIVER_VERSION SIZE_STR "(pio)", dev->driver ? dev->driver->driver.name : "(none)", is_vbus_present() ? "full speed" : "disconnected"); - size -= t; - next += t; /* registers for device and ep0 */ - t = scnprintf(next, size, + seq_printf(m, "uicr %02X.%02X, usir %02X.%02x, ufnr %02X.%02X\n", UICR1, UICR0, USIR1, USIR0, UFNRH, UFNRL); - size -= t; - next += t; tmp = UDCCR; - t = scnprintf(next, size, + seq_printf(m, "udccr %02X =%s%s%s%s%s%s%s%s\n", tmp, (tmp & UDCCR_REM) ? " rem" : "", (tmp & UDCCR_RSTIR) ? " rstir" : "", @@ -1041,11 +1029,9 @@ udc_proc_read(char *page, char **start, off_t off, int count, (tmp & UDCCR_RSM) ? " rsm" : "", (tmp & UDCCR_UDA) ? " uda" : "", (tmp & UDCCR_UDE) ? " ude" : ""); - size -= t; - next += t; tmp = UDCCS0; - t = scnprintf(next, size, + seq_printf(m, "udccs0 %02X =%s%s%s%s%s%s%s%s\n", tmp, (tmp & UDCCS0_SA) ? " sa" : "", (tmp & UDCCS0_RNE) ? " rne" : "", @@ -1055,28 +1041,22 @@ udc_proc_read(char *page, char **start, off_t off, int count, (tmp & UDCCS0_FTF) ? " ftf" : "", (tmp & UDCCS0_IPR) ? " ipr" : "", (tmp & UDCCS0_OPR) ? " opr" : ""); - size -= t; - next += t; if (dev->has_cfr) { tmp = UDCCFR; - t = scnprintf(next, size, + seq_printf(m, "udccfr %02X =%s%s\n", tmp, (tmp & UDCCFR_AREN) ? " aren" : "", (tmp & UDCCFR_ACM) ? " acm" : ""); - size -= t; - next += t; } if (!is_vbus_present() || !dev->driver) goto done; - t = scnprintf(next, size, "ep0 IN %lu/%lu, OUT %lu/%lu\nirqs %lu\n\n", + seq_printf(m, "ep0 IN %lu/%lu, OUT %lu/%lu\nirqs %lu\n\n", dev->stats.write.bytes, dev->stats.write.ops, dev->stats.read.bytes, dev->stats.read.ops, dev->stats.irqs); - size -= t; - next += t; /* dump endpoint queues */ for (i = 0; i < PXA_UDC_NUM_ENDPOINTS; i++) { @@ -1084,61 +1064,68 @@ udc_proc_read(char *page, char **start, off_t off, int count, struct pxa2xx_request *req; if (i != 0) { - const struct usb_endpoint_descriptor *d; + const struct usb_endpoint_descriptor *desc; - d = ep->desc; - if (!d) + desc = ep->desc; + if (!desc) continue; tmp = *dev->ep [i].reg_udccs; - t = scnprintf(next, size, + seq_printf(m, "%s max %d %s udccs %02x irqs %lu\n", - ep->ep.name, le16_to_cpu (d->wMaxPacketSize), + ep->ep.name, le16_to_cpu(desc->wMaxPacketSize), "pio", tmp, ep->pio_irqs); /* TODO translate all five groups of udccs bits! */ } else /* ep0 should only have one transfer queued */ - t = scnprintf(next, size, "ep0 max 16 pio irqs %lu\n", + seq_printf(m, "ep0 max 16 pio irqs %lu\n", ep->pio_irqs); - if (t <= 0 || t > size) - goto done; - size -= t; - next += t; if (list_empty(&ep->queue)) { - t = scnprintf(next, size, "\t(nothing queued)\n"); - if (t <= 0 || t > size) - goto done; - size -= t; - next += t; + seq_printf(m, "\t(nothing queued)\n"); continue; } list_for_each_entry(req, &ep->queue, queue) { - t = scnprintf(next, size, + seq_printf(m, "\treq %p len %d/%d buf %p\n", &req->req, req->req.actual, req->req.length, req->req.buf); - if (t <= 0 || t > size) - goto done; - size -= t; - next += t; } } done: local_irq_restore(flags); - *eof = 1; - return count - size; + return 0; } -#define create_proc_files() \ - create_proc_read_entry(proc_node_name, 0, NULL, udc_proc_read, dev) -#define remove_proc_files() \ - remove_proc_entry(proc_node_name, NULL) +static int +udc_debugfs_open(struct inode *inode, struct file *file) +{ + return single_open(file, udc_seq_show, inode->i_private); +} + +static const struct file_operations debug_fops = { + .open = udc_debugfs_open, + .read = seq_read, + .llseek = seq_lseek, + .release = single_release, + .owner = THIS_MODULE, +}; + +#define create_debug_files(dev) \ + do { \ + dev->debugfs_udc = debugfs_create_file(dev->gadget.name, \ + S_IRUGO, NULL, dev, &debug_fops); \ + } while (0) +#define remove_debug_files(dev) \ + do { \ + if (dev->debugfs_udc) \ + debugfs_remove(dev->debugfs_udc); \ + } while (0) #else /* !CONFIG_USB_GADGET_DEBUG_FILES */ -#define create_proc_files() do {} while (0) -#define remove_proc_files() do {} while (0) +#define create_debug_files(dev) do {} while (0) +#define remove_debug_files(dev) do {} while (0) #endif /* CONFIG_USB_GADGET_DEBUG_FILES */ @@ -2246,7 +2233,7 @@ lubbock_fail0: goto err_vbus_irq; } } - create_proc_files(); + create_debug_files(dev); return 0; @@ -2283,7 +2270,7 @@ static int __exit pxa2xx_udc_remove(struct platform_device *pdev) return -EBUSY; udc_disable(dev); - remove_proc_files(); + remove_debug_files(dev); if (dev->got_irq) { free_irq(platform_get_irq(pdev, 0), dev); diff --git a/drivers/usb/gadget/pxa2xx_udc.h b/drivers/usb/gadget/pxa2xx_udc.h index 97a8c45ccd81..b67e3ff5e4eb 100644 --- a/drivers/usb/gadget/pxa2xx_udc.h +++ b/drivers/usb/gadget/pxa2xx_udc.h @@ -129,6 +129,10 @@ struct pxa2xx_udc { struct pxa2xx_udc_mach_info *mach; u64 dma_mask; struct pxa2xx_ep ep [PXA_UDC_NUM_ENDPOINTS]; + +#ifdef CONFIG_USB_GADGET_DEBUG_FS + struct dentry *debugfs_udc; +#endif }; /*-------------------------------------------------------------------------*/ @@ -155,13 +159,15 @@ static struct pxa2xx_udc *the_controller; #ifdef DEBUG +static int is_vbus_present(void); + static const char *state_name[] = { "EP0_IDLE", "EP0_IN_DATA_PHASE", "EP0_OUT_DATA_PHASE", "EP0_END_XFER", "EP0_STALL" }; -#ifdef VERBOSE +#ifdef VERBOSE_DEBUG # define UDC_DEBUG DBG_VERBOSE #else # define UDC_DEBUG DBG_NORMAL @@ -207,7 +213,7 @@ dump_state(struct pxa2xx_udc *dev) unsigned i; DMSG("%s %s, uicr %02X.%02X, usir %02X.%02x, ufnr %02X.%02X\n", - is_usb_connected() ? "host " : "disconnected", + is_vbus_present() ? "host " : "disconnected", state_name[dev->ep0state], UICR1, UICR0, USIR1, USIR0, UFNRH, UFNRL); dump_udccr("udccr"); @@ -224,7 +230,7 @@ dump_state(struct pxa2xx_udc *dev) } else DMSG("ep0 driver '%s'\n", dev->driver->driver.name); - if (!is_usb_connected()) + if (!is_vbus_present()) return; dump_udccs0 ("udccs0"); @@ -233,7 +239,7 @@ dump_state(struct pxa2xx_udc *dev) dev->stats.read.bytes, dev->stats.read.ops); for (i = 1; i < PXA_UDC_NUM_ENDPOINTS; i++) { - if (dev->ep [i].desc == 0) + if (dev->ep [i].desc == NULL) continue; DMSG ("udccs%d = %02x\n", i, *dev->ep->reg_udccs); } -- cgit v1.2.3 From da0e8fb00b862aa10265f0c64930b432cd44420b Mon Sep 17 00:00:00 2001 From: Valentine Barshak Date: Sun, 30 Dec 2007 15:28:50 -0800 Subject: USB: add ehci-ppc-of bus glue (device-tree aware) This adds device-tree-aware ehci-ppc-of driver. The code is based on the ehci-ppc-soc driver by Stefan Roese . Signed-off-by: Valentine Barshak Acked-by: Arnd Bergmann Acked-by: Stefan Roese Signed-off-by: David Brownell Signed-off-by: Greg Kroah-Hartman --- drivers/usb/host/Kconfig | 8 ++ drivers/usb/host/ehci-hcd.c | 67 +++++++----- drivers/usb/host/ehci-ppc-of.c | 238 +++++++++++++++++++++++++++++++++++++++++ drivers/usb/host/ehci.h | 2 +- 4 files changed, 286 insertions(+), 29 deletions(-) create mode 100644 drivers/usb/host/ehci-ppc-of.c diff --git a/drivers/usb/host/Kconfig b/drivers/usb/host/Kconfig index 9b202d5f88c0..1f45aa25608e 100644 --- a/drivers/usb/host/Kconfig +++ b/drivers/usb/host/Kconfig @@ -85,6 +85,14 @@ config USB_EHCI_FSL ---help--- Variation of ARC USB block used in some Freescale chips. +config USB_EHCI_HCD_PPC_OF + bool "EHCI support for PPC USB controller on OF platform bus" + depends on USB_EHCI_HCD && PPC_OF + default y + ---help--- + Enables support for the USB controller present on the PowerPC + OpenFirmware platform bus. + config USB_ISP116X_HCD tristate "ISP116X HCD support" depends on USB diff --git a/drivers/usb/host/ehci-hcd.c b/drivers/usb/host/ehci-hcd.c index 7c5c8796d175..53fc97fced20 100644 --- a/drivers/usb/host/ehci-hcd.c +++ b/drivers/usb/host/ehci-hcd.c @@ -993,11 +993,16 @@ MODULE_LICENSE ("GPL"); #define PS3_SYSTEM_BUS_DRIVER ps3_ehci_driver #endif -#ifdef CONFIG_440EPX +#if defined(CONFIG_440EPX) && !defined(CONFIG_PPC_MERGE) #include "ehci-ppc-soc.c" #define PLATFORM_DRIVER ehci_ppc_soc_driver #endif +#ifdef CONFIG_USB_EHCI_HCD_PPC_OF +#include "ehci-ppc-of.c" +#define OF_PLATFORM_DRIVER ehci_hcd_ppc_of_driver +#endif + #ifdef CONFIG_ARCH_ORION #include "ehci-orion.c" #define PLATFORM_DRIVER ehci_orion_driver @@ -1025,52 +1030,58 @@ static int __init ehci_hcd_init(void) #ifdef PLATFORM_DRIVER retval = platform_driver_register(&PLATFORM_DRIVER); - if (retval < 0) { -#ifdef DEBUG - debugfs_remove(ehci_debug_root); - ehci_debug_root = NULL; -#endif - return retval; - } + if (retval < 0) + goto clean0; #endif #ifdef PCI_DRIVER retval = pci_register_driver(&PCI_DRIVER); - if (retval < 0) { -#ifdef DEBUG - debugfs_remove(ehci_debug_root); - ehci_debug_root = NULL; -#endif -#ifdef PLATFORM_DRIVER - platform_driver_unregister(&PLATFORM_DRIVER); -#endif - return retval; - } + if (retval < 0) + goto clean1; #endif #ifdef PS3_SYSTEM_BUS_DRIVER retval = ps3_ehci_driver_register(&PS3_SYSTEM_BUS_DRIVER); - if (retval < 0) { -#ifdef DEBUG - debugfs_remove(ehci_debug_root); - ehci_debug_root = NULL; + if (retval < 0) + goto clean2; #endif -#ifdef PLATFORM_DRIVER - platform_driver_unregister(&PLATFORM_DRIVER); + +#ifdef OF_PLATFORM_DRIVER + retval = of_register_platform_driver(&OF_PLATFORM_DRIVER); + if (retval < 0) + goto clean3; +#endif + return retval; + +#ifdef OF_PLATFORM_DRIVER + /* of_unregister_platform_driver(&OF_PLATFORM_DRIVER); */ +clean3: +#endif +#ifdef PS3_SYSTEM_BUS_DRIVER + ps3_ehci_driver_unregister(&PS3_SYSTEM_BUS_DRIVER); +clean2: #endif #ifdef PCI_DRIVER - pci_unregister_driver(&PCI_DRIVER); + pci_unregister_driver(&PCI_DRIVER); +clean1: #endif - return retval; - } +#ifdef PLATFORM_DRIVER + platform_driver_unregister(&PLATFORM_DRIVER); +clean0: +#endif +#ifdef DEBUG + debugfs_remove(ehci_debug_root); + ehci_debug_root = NULL; #endif - return retval; } module_init(ehci_hcd_init); static void __exit ehci_hcd_cleanup(void) { +#ifdef OF_PLATFORM_DRIVER + of_unregister_platform_driver(&OF_PLATFORM_DRIVER); +#endif #ifdef PLATFORM_DRIVER platform_driver_unregister(&PLATFORM_DRIVER); #endif 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 @@ +/* + * EHCI HCD (Host Controller Driver) for USB. + * + * Bus Glue for PPC On-Chip EHCI driver on the of_platform bus + * Tested on AMCC PPC 440EPx + * + * Valentine Barshak + * + * Based on "ehci-ppc-soc.c" by Stefan Roese + * and "ohci-ppc-of.c" by Sylvain Munaut + * + * This file is licenced under the GPL. + */ + +#include + +#include +#include + +/* called during probe() after chip reset completes */ +static int ehci_ppc_of_setup(struct usb_hcd *hcd) +{ + struct ehci_hcd *ehci = hcd_to_ehci(hcd); + int retval; + + retval = ehci_halt(ehci); + if (retval) + return retval; + + retval = ehci_init(hcd); + if (retval) + return retval; + + ehci->sbrn = 0x20; + return ehci_reset(ehci); +} + + +static const struct hc_driver ehci_ppc_of_hc_driver = { + .description = hcd_name, + .product_desc = "OF EHCI", + .hcd_priv_size = sizeof(struct ehci_hcd), + + /* + * generic hardware linkage + */ + .irq = ehci_irq, + .flags = HCD_MEMORY | HCD_USB2, + + /* + * basic lifecycle operations + */ + .reset = ehci_ppc_of_setup, + .start = ehci_run, + .stop = ehci_stop, + .shutdown = ehci_shutdown, + + /* + * managing i/o requests and associated device resources + */ + .urb_enqueue = ehci_urb_enqueue, + .urb_dequeue = ehci_urb_dequeue, + .endpoint_disable = ehci_endpoint_disable, + + /* + * scheduling support + */ + .get_frame_number = ehci_get_frame, + + /* + * root hub support + */ + .hub_status_data = ehci_hub_status_data, + .hub_control = ehci_hub_control, +#ifdef CONFIG_PM + .bus_suspend = ehci_bus_suspend, + .bus_resume = ehci_bus_resume, +#endif +}; + + +/* + * 440EPx Errata USBH_3 + * Fix: Enable Break Memory Transfer (BMT) in INSNREG3 + */ +#define PPC440EPX_EHCI0_INSREG_BMT (0x1 << 0) +static int __devinit +ppc44x_enable_bmt(struct device_node *dn) +{ + __iomem u32 *insreg_virt; + + insreg_virt = of_iomap(dn, 1); + if (!insreg_virt) + return -EINVAL; + + out_be32(insreg_virt + 3, PPC440EPX_EHCI0_INSREG_BMT); + + iounmap(insreg_virt); + return 0; +} + + +static int __devinit +ehci_hcd_ppc_of_probe(struct of_device *op, const struct of_device_id *match) +{ + struct device_node *dn = op->node; + struct usb_hcd *hcd; + struct ehci_hcd *ehci; + struct resource res; + int irq; + int rv; + + if (usb_disabled()) + return -ENODEV; + + dev_dbg(&op->dev, "initializing PPC-OF USB Controller\n"); + + rv = of_address_to_resource(dn, 0, &res); + if (rv) + return rv; + + hcd = usb_create_hcd(&ehci_ppc_of_hc_driver, &op->dev, "PPC-OF USB"); + if (!hcd) + return -ENOMEM; + + hcd->rsrc_start = res.start; + hcd->rsrc_len = res.end - res.start + 1; + + if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) { + printk(KERN_ERR __FILE__ ": request_mem_region failed\n"); + rv = -EBUSY; + goto err_rmr; + } + + irq = irq_of_parse_and_map(dn, 0); + if (irq == NO_IRQ) { + printk(KERN_ERR __FILE__ ": irq_of_parse_and_map failed\n"); + rv = -EBUSY; + goto err_irq; + } + + hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len); + if (!hcd->regs) { + printk(KERN_ERR __FILE__ ": ioremap failed\n"); + rv = -ENOMEM; + goto err_ioremap; + } + + ehci = hcd_to_ehci(hcd); + + if (of_get_property(dn, "big-endian", NULL)) { + ehci->big_endian_mmio = 1; + ehci->big_endian_desc = 1; + } + if (of_get_property(dn, "big-endian-regs", NULL)) + ehci->big_endian_mmio = 1; + if (of_get_property(dn, "big-endian-desc", NULL)) + ehci->big_endian_desc = 1; + + ehci->caps = hcd->regs; + ehci->regs = hcd->regs + + HC_LENGTH(ehci_readl(ehci, &ehci->caps->hc_capbase)); + + /* cache this readonly data; minimize chip reads */ + ehci->hcs_params = ehci_readl(ehci, &ehci->caps->hcs_params); + + if (of_device_is_compatible(dn, "ibm,usb-ehci-440epx")) { + rv = ppc44x_enable_bmt(dn); + ehci_dbg(ehci, "Break Memory Transfer (BMT) is %senabled!\n", + rv ? "NOT ": ""); + } + + rv = usb_add_hcd(hcd, irq, 0); + if (rv == 0) + return 0; + + iounmap(hcd->regs); +err_ioremap: + irq_dispose_mapping(irq); +err_irq: + release_mem_region(hcd->rsrc_start, hcd->rsrc_len); +err_rmr: + usb_put_hcd(hcd); + + return rv; +} + + +static int ehci_hcd_ppc_of_remove(struct of_device *op) +{ + struct usb_hcd *hcd = dev_get_drvdata(&op->dev); + dev_set_drvdata(&op->dev, NULL); + + dev_dbg(&op->dev, "stopping PPC-OF USB Controller\n"); + + usb_remove_hcd(hcd); + + iounmap(hcd->regs); + irq_dispose_mapping(hcd->irq); + release_mem_region(hcd->rsrc_start, hcd->rsrc_len); + + usb_put_hcd(hcd); + + return 0; +} + + +static int ehci_hcd_ppc_of_shutdown(struct of_device *op) +{ + struct usb_hcd *hcd = dev_get_drvdata(&op->dev); + + if (hcd->driver->shutdown) + hcd->driver->shutdown(hcd); + + return 0; +} + + +static struct of_device_id ehci_hcd_ppc_of_match[] = { + { + .compatible = "usb-ehci", + }, + {}, +}; +MODULE_DEVICE_TABLE(of, ehci_hcd_ppc_of_match); + + +static struct of_platform_driver ehci_hcd_ppc_of_driver = { + .name = "ppc-of-ehci", + .match_table = ehci_hcd_ppc_of_match, + .probe = ehci_hcd_ppc_of_probe, + .remove = ehci_hcd_ppc_of_remove, + .shutdown = ehci_hcd_ppc_of_shutdown, + .driver = { + .name = "ppc-of-ehci", + .owner = THIS_MODULE, + }, +}; diff --git a/drivers/usb/host/ehci.h b/drivers/usb/host/ehci.h index eeda4c88ebae..c78c52771e64 100644 --- a/drivers/usb/host/ehci.h +++ b/drivers/usb/host/ehci.h @@ -741,7 +741,7 @@ ehci_port_speed(struct ehci_hcd *ehci, unsigned int portsc) * definition below can die once the 4xx support is * finally ported over. */ -#if defined(CONFIG_PPC) +#if defined(CONFIG_PPC) && !defined(CONFIG_PPC_MERGE) #define readl_be(addr) in_be32((__force unsigned *)addr) #define writel_be(val, addr) out_be32((__force unsigned *)addr, val) #endif -- cgit v1.2.3 From 18bcbcfe9ca2308ebffb40068b51803da9315d97 Mon Sep 17 00:00:00 2001 From: Daniel Walker Date: Fri, 11 Jan 2008 08:45:44 -0800 Subject: USB: misc: legousbtower: semaphore to mutex The dev->sem conforms to mutex style usage. This patch converts it to use the struct mutex type, and new API. There is also a small style fix around this comment, /* unlock here as tower_delete frees dev */ Where I broke the line up to meet the 80 char limit. Signed-off-by: Daniel Walker Signed-off-by: Greg Kroah-Hartman --- drivers/usb/misc/legousbtower.c | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) 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); /* Structure to hold all of our device specific stuff */ struct lego_usb_tower { - struct semaphore sem; /* locks this structure */ + struct mutex lock; /* locks this structure */ struct usb_device* udev; /* save off the usb device pointer */ unsigned char minor; /* the starting minor number for this device */ @@ -361,7 +361,7 @@ static int tower_open (struct inode *inode, struct file *file) } /* lock this device */ - if (down_interruptible (&dev->sem)) { + if (mutex_lock_interruptible(&dev->lock)) { mutex_unlock(&open_disc_mutex); retval = -ERESTARTSYS; goto exit; @@ -421,7 +421,7 @@ static int tower_open (struct inode *inode, struct file *file) file->private_data = dev; unlock_exit: - up (&dev->sem); + mutex_unlock(&dev->lock); exit: dbg(2, "%s: leave, return value %d ", __FUNCTION__, retval); @@ -448,7 +448,7 @@ static int tower_release (struct inode *inode, struct file *file) } mutex_lock(&open_disc_mutex); - if (down_interruptible (&dev->sem)) { + if (mutex_lock_interruptible(&dev->lock)) { retval = -ERESTARTSYS; goto exit; } @@ -460,7 +460,9 @@ static int tower_release (struct inode *inode, struct file *file) } if (dev->udev == NULL) { /* the device was unplugged before the file was released */ - up (&dev->sem); /* unlock here as tower_delete frees dev */ + + /* unlock here as tower_delete frees dev */ + mutex_unlock(&dev->lock); tower_delete (dev); goto exit; } @@ -473,7 +475,7 @@ static int tower_release (struct inode *inode, struct file *file) dev->open_count = 0; unlock_exit: - up (&dev->sem); + mutex_unlock(&dev->lock); exit: mutex_unlock(&open_disc_mutex); @@ -586,7 +588,7 @@ static ssize_t tower_read (struct file *file, char __user *buffer, size_t count, dev = (struct lego_usb_tower *)file->private_data; /* lock this object */ - if (down_interruptible (&dev->sem)) { + if (mutex_lock_interruptible(&dev->lock)) { retval = -ERESTARTSYS; goto exit; } @@ -653,7 +655,7 @@ static ssize_t tower_read (struct file *file, char __user *buffer, size_t count, unlock_exit: /* unlock the device */ - up (&dev->sem); + mutex_unlock(&dev->lock); exit: 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 dev = (struct lego_usb_tower *)file->private_data; /* lock this object */ - if (down_interruptible (&dev->sem)) { + if (mutex_lock_interruptible(&dev->lock)) { retval = -ERESTARTSYS; goto exit; } @@ -737,7 +739,7 @@ static ssize_t tower_write (struct file *file, const char __user *buffer, size_t unlock_exit: /* unlock the device */ - up (&dev->sem); + mutex_unlock(&dev->lock); exit: 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 goto exit; } - init_MUTEX (&dev->sem); + mutex_init(&dev->lock); dev->udev = udev; dev->open_count = 0; @@ -1007,16 +1009,16 @@ static void tower_disconnect (struct usb_interface *interface) /* give back our minor */ usb_deregister_dev (interface, &tower_class); - down (&dev->sem); + mutex_lock(&dev->lock); mutex_unlock(&open_disc_mutex); /* if the device is not opened, then we clean up right now */ if (!dev->open_count) { - up (&dev->sem); + mutex_unlock(&dev->lock); tower_delete (dev); } else { dev->udev = NULL; - up (&dev->sem); + mutex_unlock(&dev->lock); } info("LEGO USB Tower #%d now disconnected", (minor - LEGO_USB_TOWER_MINOR_BASE)); -- cgit v1.2.3 From 91bc4d31e81b15aa6e2d075307b8727041f2e2d1 Mon Sep 17 00:00:00 2001 From: Vladimir Barinov Date: Sun, 30 Dec 2007 15:21:11 -0800 Subject: USB: add ehci-ixp bus glue EHCI Glue driver for Intel IXP4XX EHCI USB controller Signed-off-by: Vladimir Barinov Signed-off-by: David Brownell Signed-off-by: Greg Kroah-Hartman --- drivers/usb/Kconfig | 1 + drivers/usb/host/Kconfig | 4 +- drivers/usb/host/ehci-hcd.c | 5 ++ drivers/usb/host/ehci-ixp4xx.c | 152 +++++++++++++++++++++++++++++++++++++++++ drivers/usb/host/ehci.h | 5 ++ 5 files changed, 165 insertions(+), 2 deletions(-) create mode 100644 drivers/usb/host/ehci-ixp4xx.c diff --git a/drivers/usb/Kconfig b/drivers/usb/Kconfig index 7a6499008b89..8d48d973efcb 100644 --- a/drivers/usb/Kconfig +++ b/drivers/usb/Kconfig @@ -50,6 +50,7 @@ config USB_ARCH_HAS_EHCI boolean default y if PPC_83xx default y if SOC_AU1200 + default y if ARCH_IXP4XX default PCI # ARM SA1111 chips have a non-PCI based "OHCI-compatible" USB host interface. diff --git a/drivers/usb/host/Kconfig b/drivers/usb/host/Kconfig index 1f45aa25608e..3a42bcd27d30 100644 --- a/drivers/usb/host/Kconfig +++ b/drivers/usb/host/Kconfig @@ -69,12 +69,12 @@ config USB_EHCI_TT_NEWSCHED config USB_EHCI_BIG_ENDIAN_MMIO bool - depends on USB_EHCI_HCD && (PPC_CELLEB || PPC_PS3 || 440EPX) + depends on USB_EHCI_HCD && (PPC_CELLEB || PPC_PS3 || 440EPX || ARCH_IXP4XX) default y config USB_EHCI_BIG_ENDIAN_DESC bool - depends on USB_EHCI_HCD && 440EPX + depends on USB_EHCI_HCD && (440EPX || ARCH_IXP4XX) default y config USB_EHCI_FSL diff --git a/drivers/usb/host/ehci-hcd.c b/drivers/usb/host/ehci-hcd.c index 53fc97fced20..4caa6a8b9a37 100644 --- a/drivers/usb/host/ehci-hcd.c +++ b/drivers/usb/host/ehci-hcd.c @@ -1008,6 +1008,11 @@ MODULE_LICENSE ("GPL"); #define PLATFORM_DRIVER ehci_orion_driver #endif +#ifdef CONFIG_ARCH_IXP4XX +#include "ehci-ixp4xx.c" +#define PLATFORM_DRIVER ixp4xx_ehci_driver +#endif + #if !defined(PCI_DRIVER) && !defined(PLATFORM_DRIVER) && \ !defined(PS3_SYSTEM_BUS_DRIVER) #error "missing bus glue for ehci-hcd" 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 @@ +/* + * IXP4XX EHCI Host Controller Driver + * + * Author: Vladimir Barinov + * + * Based on "ehci-fsl.c" by Randy Vinson + * + * 2007 (c) MontaVista Software, Inc. This file is licensed under + * the terms of the GNU General Public License version 2. This program + * is licensed "as is" without any warranty of any kind, whether express + * or implied. + */ + +#include + +static int ixp4xx_ehci_init(struct usb_hcd *hcd) +{ + struct ehci_hcd *ehci = hcd_to_ehci(hcd); + int retval = 0; + + ehci->big_endian_desc = 1; + ehci->big_endian_mmio = 1; + + ehci->caps = hcd->regs + 0x100; + ehci->regs = hcd->regs + 0x100 + + HC_LENGTH(ehci_readl(ehci, &ehci->caps->hc_capbase)); + ehci->hcs_params = ehci_readl(ehci, &ehci->caps->hcs_params); + + ehci->is_tdi_rh_tt = 1; + ehci_reset(ehci); + + retval = ehci_init(hcd); + if (retval) + return retval; + + ehci_port_power(ehci, 0); + + return retval; +} + +static const struct hc_driver ixp4xx_ehci_hc_driver = { + .description = hcd_name, + .product_desc = "IXP4XX EHCI Host Controller", + .hcd_priv_size = sizeof(struct ehci_hcd), + .irq = ehci_irq, + .flags = HCD_MEMORY | HCD_USB2, + .reset = ixp4xx_ehci_init, + .start = ehci_run, + .stop = ehci_stop, + .shutdown = ehci_shutdown, + .urb_enqueue = ehci_urb_enqueue, + .urb_dequeue = ehci_urb_dequeue, + .endpoint_disable = ehci_endpoint_disable, + .get_frame_number = ehci_get_frame, + .hub_status_data = ehci_hub_status_data, + .hub_control = ehci_hub_control, +#if defined(CONFIG_PM) + .bus_suspend = ehci_bus_suspend, + .bus_resume = ehci_bus_resume, +#endif +}; + +static int ixp4xx_ehci_probe(struct platform_device *pdev) +{ + struct usb_hcd *hcd; + const struct hc_driver *driver = &ixp4xx_ehci_hc_driver; + struct resource *res; + int irq; + int retval; + + if (usb_disabled()) + return -ENODEV; + + res = platform_get_resource(pdev, IORESOURCE_IRQ, 0); + if (!res) { + dev_err(&pdev->dev, + "Found HC with no IRQ. Check %s setup!\n", + pdev->dev.bus_id); + return -ENODEV; + } + irq = res->start; + + hcd = usb_create_hcd(driver, &pdev->dev, pdev->dev.bus_id); + if (!hcd) { + retval = -ENOMEM; + goto fail_create_hcd; + } + + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); + if (!res) { + dev_err(&pdev->dev, + "Found HC with no register addr. Check %s setup!\n", + pdev->dev.bus_id); + retval = -ENODEV; + goto fail_request_resource; + } + hcd->rsrc_start = res->start; + hcd->rsrc_len = res->end - res->start + 1; + + if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, + driver->description)) { + dev_dbg(&pdev->dev, "controller already in use\n"); + retval = -EBUSY; + goto fail_request_resource; + } + + hcd->regs = ioremap_nocache(hcd->rsrc_start, hcd->rsrc_len); + if (hcd->regs == NULL) { + dev_dbg(&pdev->dev, "error mapping memory\n"); + retval = -EFAULT; + goto fail_ioremap; + } + + retval = usb_add_hcd(hcd, irq, IRQF_SHARED); + if (retval) + goto fail_add_hcd; + + return retval; + +fail_add_hcd: + iounmap(hcd->regs); +fail_ioremap: + release_mem_region(hcd->rsrc_start, hcd->rsrc_len); +fail_request_resource: + usb_put_hcd(hcd); +fail_create_hcd: + dev_err(&pdev->dev, "init %s fail, %d\n", pdev->dev.bus_id, retval); + return retval; +} + +static int ixp4xx_ehci_remove(struct platform_device *pdev) +{ + struct usb_hcd *hcd = platform_get_drvdata(pdev); + + usb_remove_hcd(hcd); + iounmap(hcd->regs); + release_mem_region(hcd->rsrc_start, hcd->rsrc_len); + usb_put_hcd(hcd); + + return 0; +} + +MODULE_ALIAS("ixp4xx-ehci"); + +static struct platform_driver ixp4xx_ehci_driver = { + .probe = ixp4xx_ehci_probe, + .remove = ixp4xx_ehci_remove, + .driver = { + .name = "ixp4xx-ehci", + .bus = &platform_bus_type + }, +}; diff --git a/drivers/usb/host/ehci.h b/drivers/usb/host/ehci.h index c78c52771e64..f83472856a80 100644 --- a/drivers/usb/host/ehci.h +++ b/drivers/usb/host/ehci.h @@ -746,6 +746,11 @@ ehci_port_speed(struct ehci_hcd *ehci, unsigned int portsc) #define writel_be(val, addr) out_be32((__force unsigned *)addr, val) #endif +#if defined(CONFIG_ARM) && defined(CONFIG_ARCH_IXP4XX) +#define readl_be(addr) __raw_readl((__force unsigned *)addr) +#define writel_be(val, addr) __raw_writel(val, (__force unsigned *)addr) +#endif + static inline unsigned int ehci_readl(const struct ehci_hcd *ehci, __u32 __iomem * regs) { -- cgit v1.2.3 From 3b6fcfd0664aeac6ae2fd1231f04b3ed24723c1e Mon Sep 17 00:00:00 2001 From: Karsten Wiese Date: Sun, 30 Dec 2007 21:55:05 -0800 Subject: USB: ehci saves some memory in ISO transfer descriptors In the EHCI driver, itd->usecs[8] is used in periodic_usecs(), indexed by uframe. For an ITD's unused uframes it is 0, else it contains the same value as itd->stream->usecs. To check if an ITD's uframe is used, we can instead test itd->hw_transaction[uframe]: if used, it will be nonzero no matter what endianess is used. This patch replaces those two uses, eliminates itd->usecs[], and saves eight bytes from each ITD. Signed-off-by: Karsten Wiese Signed-off-by: David Brownell Signed-off-by: Greg Kroah-Hartman --- drivers/usb/host/ehci-sched.c | 4 ++-- drivers/usb/host/ehci.h | 1 - 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/drivers/usb/host/ehci-sched.c b/drivers/usb/host/ehci-sched.c index 1c771045ccaa..1a94e6cec419 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) q = &q->fstn->fstn_next; break; case Q_TYPE_ITD: - usecs += q->itd->usecs [uframe]; + if (q->itd->hw_transaction[uframe]) + usecs += q->itd->stream->usecs; hw_p = &q->itd->hw_next; q = &q->itd->itd_next; break; @@ -1536,7 +1537,6 @@ itd_link_urb ( uframe = next_uframe & 0x07; frame = next_uframe >> 3; - itd->usecs [uframe] = stream->usecs; itd_patch(ehci, itd, iso_sched, packet, uframe); next_uframe += stream->interval; diff --git a/drivers/usb/host/ehci.h b/drivers/usb/host/ehci.h index f83472856a80..42969e9d8c44 100644 --- a/drivers/usb/host/ehci.h +++ b/drivers/usb/host/ehci.h @@ -602,7 +602,6 @@ struct ehci_itd { unsigned frame; /* where scheduled */ unsigned pg; unsigned index[8]; /* in urb->iso_frame_desc */ - u8 usecs[8]; } __attribute__ ((aligned (32))); /*-------------------------------------------------------------------------*/ -- cgit v1.2.3 From aa16ca307ee2da304d3a5fc0fc5e50ef8047c9e9 Mon Sep 17 00:00:00 2001 From: David Brownell Date: Sun, 30 Dec 2007 23:45:19 -0800 Subject: USB: ehci: minor ISO updates, always support split ISO Small updates to the EHCI driver's ISO support: - Get rid of the Kconfig option for full speed ISO. It may not be perfect yet, but it hasn't appeared to be dangerous and pretty much every configuration wants it. - Instead of two places to disable an empty periodic schedule after an ISO transfer completes, just have one. - After the periodic schedule is disabled, we can short-circuit the schedule scan ... it can't possibly have more work to do. Assuming a typical config with split iso enabled, the only change in behavior should be almost unobservable: quicker termination of periodic scans when the schedule gets emptied. Signed-off-by: David Brownell Signed-off-by: Greg Kroah-Hartman --- drivers/usb/host/Kconfig | 9 --------- drivers/usb/host/ehci-sched.c | 47 +++++++++++-------------------------------- 2 files changed, 12 insertions(+), 44 deletions(-) diff --git a/drivers/usb/host/Kconfig b/drivers/usb/host/Kconfig index 3a42bcd27d30..d97b16b52efa 100644 --- a/drivers/usb/host/Kconfig +++ b/drivers/usb/host/Kconfig @@ -29,15 +29,6 @@ config USB_EHCI_HCD To compile this driver as a module, choose M here: the module will be called ehci-hcd. -config USB_EHCI_SPLIT_ISO - bool "Full speed ISO transactions (EXPERIMENTAL)" - depends on USB_EHCI_HCD && EXPERIMENTAL - default n - ---help--- - This code is new and hasn't been used with many different - EHCI or USB 2.0 transaction translator implementations. - It should work for ISO-OUT transfers, like audio. - config USB_EHCI_ROOT_HUB_TT bool "Root Hub Transaction Translators (EXPERIMENTAL)" depends on USB_EHCI_HCD && EXPERIMENTAL diff --git a/drivers/usb/host/ehci-sched.c b/drivers/usb/host/ehci-sched.c index 1a94e6cec419..001b2c389be2 100644 --- a/drivers/usb/host/ehci-sched.c +++ b/drivers/usb/host/ehci-sched.c @@ -1630,16 +1630,12 @@ itd_complete ( BUG_ON (itd->urb == urb); */ - /* give urb back to the driver ... can be out-of-order */ + /* give urb back to the driver; completion often (re)submits */ dev = urb->dev; ehci_urb_done(ehci, urb, 0); retval = true; urb = NULL; - - /* defer stopping schedule; completion can submit */ ehci->periodic_sched--; - if (unlikely (!ehci->periodic_sched)) - (void) disable_periodic (ehci); ehci_to_hcd(ehci)->self.bandwidth_isoc_reqs--; if (unlikely (list_empty (&stream->td_list))) { @@ -1725,8 +1721,6 @@ done: return status; } -#ifdef CONFIG_USB_EHCI_SPLIT_ISO - /*-------------------------------------------------------------------------*/ /* @@ -2016,16 +2010,12 @@ sitd_complete ( BUG_ON (sitd->urb == urb); */ - /* give urb back to the driver */ + /* give urb back to the driver; completion often (re)submits */ dev = urb->dev; ehci_urb_done(ehci, urb, 0); retval = true; urb = NULL; - - /* defer stopping schedule; completion can submit */ ehci->periodic_sched--; - if (!ehci->periodic_sched) - (void) disable_periodic (ehci); ehci_to_hcd(ehci)->self.bandwidth_isoc_reqs--; if (list_empty (&stream->td_list)) { @@ -2108,26 +2098,6 @@ done: return status; } -#else - -static inline int -sitd_submit (struct ehci_hcd *ehci, struct urb *urb, gfp_t mem_flags) -{ - ehci_dbg (ehci, "split iso support is disabled\n"); - return -ENOSYS; -} - -static inline unsigned -sitd_complete ( - struct ehci_hcd *ehci, - struct ehci_sitd *sitd -) { - ehci_err (ehci, "sitd_complete %p?\n", sitd); - return 0; -} - -#endif /* USB_EHCI_SPLIT_ISO */ - /*-------------------------------------------------------------------------*/ static void @@ -2252,8 +2222,14 @@ restart: } /* assume completion callbacks modify the queue */ - if (unlikely (modified)) - goto restart; + if (unlikely (modified)) { + if (likely(ehci->periodic_sched > 0)) + goto restart; + /* maybe we can short-circuit this scan! */ + disable_periodic(ehci); + now_uframe = clock; + break; + } } /* stop when we catch up to the HC */ @@ -2269,7 +2245,8 @@ restart: if (now_uframe == clock) { unsigned now; - if (!HC_IS_RUNNING (ehci_to_hcd(ehci)->state)) + if (!HC_IS_RUNNING (ehci_to_hcd(ehci)->state) + || ehci->periodic_sched == 0) break; ehci->next_uframe = now_uframe; now = ehci_readl(ehci, &ehci->regs->frame_index) % mod; -- cgit v1.2.3 From 79592b722e7a8476680197d97352d2cc0f1bffd2 Mon Sep 17 00:00:00 2001 From: David Brownell Date: Mon, 7 Jan 2008 00:47:42 -0800 Subject: USB: ehci completes high speed ISO URBs sooner This has some bugfixes for the EHCI driver's ISO transfer scanning logic. It was leaving ITDs and SITDs on the schedule too long, for a few different reasons, which caused trouble. (a) Look at all microframes for high speed transfers, not just the ones we expect to have finished. This way transfers ending mid-frame will complete without needing another IRQ. This also minimizes bogus scheduling underruns (e.g. EL2NSYNC). (b) When we encounter an ISO transfer (either speed, but this hits mostly at full speed) that's not yet been completed, immediately stop scanning; we've caught up to the hardware, no matter what other indications might say. (c) Always clean up ITDs (for high speed transfers) when the HC is no longer running. I'm not sure whether the last one has been observed before, but both the others have been reported with "real world" audio and video code. Signed-off-by: David Brownell Signed-off-by: Greg Kroah-Hartman --- drivers/usb/host/ehci-sched.c | 41 +++++++++++++++++++++++++++-------------- 1 file changed, 27 insertions(+), 14 deletions(-) diff --git a/drivers/usb/host/ehci-sched.c b/drivers/usb/host/ehci-sched.c index 001b2c389be2..8a8e08a51ba3 100644 --- a/drivers/usb/host/ehci-sched.c +++ b/drivers/usb/host/ehci-sched.c @@ -2123,17 +2123,9 @@ scan_periodic (struct ehci_hcd *ehci) for (;;) { union ehci_shadow q, *q_p; __hc32 type, *hw_p; - unsigned uframes; + unsigned incomplete = false; - /* don't scan past the live uframe */ frame = now_uframe >> 3; - if (frame == (clock >> 3)) - uframes = now_uframe & 0x07; - else { - /* safe to scan the whole frame at once */ - now_uframe |= 0x07; - uframes = 8; - } restart: /* scan each element in frame's queue for completions */ @@ -2171,12 +2163,15 @@ restart: q = q.fstn->fstn_next; break; case Q_TYPE_ITD: - /* skip itds for later in the frame */ + /* If this ITD is still active, leave it for + * later processing ... check the next entry. + */ rmb (); - for (uf = live ? uframes : 8; uf < 8; uf++) { + for (uf = 0; uf < 8 && live; uf++) { if (0 == (q.itd->hw_transaction [uf] & ITD_ACTIVE(ehci))) continue; + incomplete = true; q_p = &q.itd->itd_next; hw_p = &q.itd->hw_next; type = Q_NEXT_TYPE(ehci, @@ -2184,10 +2179,12 @@ restart: q = *q_p; break; } - if (uf != 8) + if (uf < 8 && live) break; - /* this one's ready ... HC won't cache the + /* Take finished ITDs out of the schedule + * and process them: recycle, maybe report + * URB completion. HC won't cache the * pointer for much longer, if at all. */ *q_p = q.itd->itd_next; @@ -2198,8 +2195,12 @@ restart: q = *q_p; break; case Q_TYPE_SITD: + /* If this SITD is still active, leave it for + * later processing ... check the next entry. + */ if ((q.sitd->hw_results & SITD_ACTIVE(ehci)) && live) { + incomplete = true; q_p = &q.sitd->sitd_next; hw_p = &q.sitd->hw_next; type = Q_NEXT_TYPE(ehci, @@ -2207,6 +2208,11 @@ restart: q = *q_p; break; } + + /* Take finished SITDs out of the schedule + * and process them: recycle, maybe report + * URB completion. + */ *q_p = q.sitd->sitd_next; *hw_p = q.sitd->hw_next; type = Q_NEXT_TYPE(ehci, q.sitd->hw_next); @@ -2232,7 +2238,14 @@ restart: } } - /* stop when we catch up to the HC */ + /* If we can tell we caught up to the hardware, stop now. + * We can't advance our scan without collecting the ISO + * transfers that are still pending in this frame. + */ + if (incomplete && HC_IS_RUNNING(ehci_to_hcd(ehci)->state)) { + ehci->next_uframe = now_uframe; + break; + } // FIXME: this assumes we won't get lapped when // latencies climb; that should be rare, but... -- cgit v1.2.3 From dd95b814115e45e0bf800f2950b9941c86e68172 Mon Sep 17 00:00:00 2001 From: Pete Zaitcev Date: Sat, 5 Jan 2008 02:01:07 -0800 Subject: USB: usbfs: struct async is a fixed size structure The ISO descriptors are allocated separately in proc_submiturb for a fetch from user mode, then tucked at the end of URB. This seems like a dead code. Signed-off-by: Pete Zaitcev Signed-off-by: Greg Kroah-Hartman --- drivers/usb/core/devio.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/usb/core/devio.c b/drivers/usb/core/devio.c index 32e5591ae7b1..e661994ad18d 100644 --- a/drivers/usb/core/devio.c +++ b/drivers/usb/core/devio.c @@ -210,9 +210,9 @@ err: static struct async *alloc_async(unsigned int numisoframes) { - unsigned int assize = sizeof(struct async) + numisoframes * sizeof(struct usb_iso_packet_descriptor); - struct async *as = kzalloc(assize, GFP_KERNEL); + struct async *as; + as = kzalloc(sizeof(struct async), GFP_KERNEL); if (!as) return NULL; as->urb = usb_alloc_urb(numisoframes, GFP_KERNEL); -- cgit v1.2.3 From f8fa7571a928d6d0e1b7444b0ea69ec7dc7db3b6 Mon Sep 17 00:00:00 2001 From: Alan Stern Date: Thu, 10 Jan 2008 16:43:15 -0500 Subject: USB: EHCI: move del_timer_sync calls outside spinlocked region This patch (as1030b) moves a del_timer_sync() call outside the scope of a spinlock, where it could cause a deadlock, and adds a new del_timer_sync() call for the new IAA watchdog timer (it was omitted by mistake). Signed-off-by: Alan Stern Acked-by: David Brownell Signed-off-by: Greg Kroah-Hartman --- drivers/usb/host/ehci-hub.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/usb/host/ehci-hub.c b/drivers/usb/host/ehci-hub.c index a249d03a5024..7919a411d5f9 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) if (time_before (jiffies, ehci->next_statechange)) msleep(5); + del_timer_sync(&ehci->watchdog); + del_timer_sync(&ehci->iaa_watchdog); port = HCS_N_PORTS (ehci->hcs_params); spin_lock_irq (&ehci->lock); @@ -171,7 +173,6 @@ static int ehci_bus_suspend (struct usb_hcd *hcd) } /* turn off now-idle HC */ - del_timer_sync (&ehci->watchdog); ehci_halt (ehci); hcd->state = HC_STATE_SUSPENDED; -- cgit v1.2.3 From cd930c931417295ac6b4d9fea62accc67192ac34 Mon Sep 17 00:00:00 2001 From: Alan Stern Date: Thu, 10 Jan 2008 11:14:53 -0500 Subject: USB: EHCI: add a short delay to the bus_suspend routine This patch (as1031) adds a short delay to the bus-suspend routine in ehci-hcd. Without it some devices disconnect when they should suspend. Signed-off-by: Alan Stern Acked-by: David Brownell Signed-off-by: Greg Kroah-Hartman --- drivers/usb/host/ehci-hub.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/usb/host/ehci-hub.c b/drivers/usb/host/ehci-hub.c index 7919a411d5f9..ccd88ae011c6 100644 --- a/drivers/usb/host/ehci-hub.c +++ b/drivers/usb/host/ehci-hub.c @@ -172,6 +172,10 @@ static int ehci_bus_suspend (struct usb_hcd *hcd) } } + /* Apparently some devices need a >= 1-uframe delay here */ + if (ehci->bus_suspended) + udelay(150); + /* turn off now-idle HC */ ehci_halt (ehci); hcd->state = HC_STATE_SUSPENDED; -- cgit v1.2.3 From 7bd4b20c876e5f7aa8e1405657aee9078f896d26 Mon Sep 17 00:00:00 2001 From: Paul Chavent Date: Sat, 12 Jan 2008 15:23:17 +0100 Subject: USB: usbserial: provide ezusb functions for an external module. When building an external module, the ezusb_* functions are not defined if we haven't loaded any built'in module that use them (whiteheat, keyspan, ...). This patch allow to build those functions even if we only have selected the usbserial generic driver. Signed-off-by: Paul Chavent Signed-off-by: Greg Kroah-Hartman --- drivers/usb/serial/Kconfig | 15 ++++++++++----- drivers/usb/serial/ezusb.c | 4 ++-- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/drivers/usb/serial/Kconfig b/drivers/usb/serial/Kconfig index e2d1d928a1e4..5df5d0fe258a 100644 --- a/drivers/usb/serial/Kconfig +++ b/drivers/usb/serial/Kconfig @@ -43,6 +43,12 @@ config USB_SERIAL_CONSOLE If unsure, say N. +config USB_EZUSB + bool "Functions for loading firmware on EZUSB chips" + depends on USB_SERIAL + help + Say Y here if you need EZUSB device support. + config USB_SERIAL_GENERIC bool "USB Generic Serial Driver" depends on USB_SERIAL @@ -105,6 +111,7 @@ config USB_SERIAL_CH341 config USB_SERIAL_WHITEHEAT tristate "USB ConnectTech WhiteHEAT Serial Driver" depends on USB_SERIAL + select USB_EZUSB help Say Y here if you want to use a ConnectTech WhiteHEAT 4 port USB to serial converter device. @@ -296,6 +303,7 @@ config USB_SERIAL_IUU config USB_SERIAL_KEYSPAN_PDA tristate "USB Keyspan PDA Single Port Serial Driver" depends on USB_SERIAL + select USB_EZUSB help Say Y here if you want to use a Keyspan PDA single port USB to serial converter device. This driver makes use of firmware @@ -307,6 +315,7 @@ config USB_SERIAL_KEYSPAN_PDA config USB_SERIAL_KEYSPAN tristate "USB Keyspan USA-xxx Serial Driver" depends on USB_SERIAL + select USB_EZUSB ---help--- Say Y here if you want to use Keyspan USB to serial converter devices. This driver makes use of Keyspan's official firmware @@ -549,6 +558,7 @@ config USB_SERIAL_CYBERJACK config USB_SERIAL_XIRCOM tristate "USB Xircom / Entregra Single Port Serial Driver" depends on USB_SERIAL + select USB_EZUSB help Say Y here if you want to use a Xircom or Entregra single port USB to serial converter device. This driver makes use of firmware @@ -596,11 +606,6 @@ config USB_SERIAL_DEBUG To compile this driver as a module, choose M here: the module will be called usb-debug. -config USB_EZUSB - bool - depends on USB_SERIAL_KEYSPAN_PDA || USB_SERIAL_XIRCOM || USB_SERIAL_KEYSPAN || USB_SERIAL_WHITEHEAT - default y - endmenu 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) } -EXPORT_SYMBOL(ezusb_writememory); -EXPORT_SYMBOL(ezusb_set_reset); +EXPORT_SYMBOL_GPL(ezusb_writememory); +EXPORT_SYMBOL_GPL(ezusb_set_reset); -- cgit v1.2.3 From 504b55cc8bca420856159833629da8f9f92d5adc Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Tue, 9 Apr 2002 12:14:34 -0700 Subject: USB: ftdi_sio: remove very old changelog entries from the file. People keep trying to add entries to this section of the driver for things. That's what the Changelog is supposed to be for, not the .c file. Signed-off-by: Greg Kroah-Hartman --- drivers/usb/serial/ftdi_sio.c | 222 +----------------------------------------- 1 file changed, 2 insertions(+), 220 deletions(-) diff --git a/drivers/usb/serial/ftdi_sio.c b/drivers/usb/serial/ftdi_sio.c index 7200eaeb513b..2c142bb04fe1 100644 --- a/drivers/usb/serial/ftdi_sio.c +++ b/drivers/usb/serial/ftdi_sio.c @@ -17,226 +17,8 @@ * See http://ftdi-usb-sio.sourceforge.net for upto date testing info * and extra documentation * - * (21/Jul/2004) Ian Abbott - * Incorporated Steven Turner's code to add support for the FT2232C chip. - * The prelimilary port to the 2.6 kernel was by Rus V. Brushkoff. I have - * fixed a couple of things. - * - * (27/May/2004) Ian Abbott - * Improved throttling code, mostly stolen from the WhiteHEAT driver. - * - * (26/Mar/2004) Jan Capek - * Added PID's for ICD-U20/ICD-U40 - incircuit PIC debuggers from CCS Inc. - * - * (09/Feb/2004) Ian Abbott - * Changed full name of USB-UIRT device to avoid "/" character. - * Added FTDI's alternate PID (0x6006) for FT232/245 devices. - * Added PID for "ELV USB Module UO100" from Stefan Frings. - * - * (21/Oct/2003) Ian Abbott - * Renamed some VID/PID macros for Matrix Orbital and Perle Systems - * devices. Removed Matrix Orbital and Perle Systems devices from the - * 8U232AM device table, but left them in the FT232BM table, as they are - * known to use only FT232BM. - * - * (17/Oct/2003) Scott Allen - * Added vid/pid for Perle Systems UltraPort USB serial converters - * - * (21/Sep/2003) Ian Abbott - * Added VID/PID for Omnidirectional Control Technology US101 USB to - * RS-232 adapter (also rebadged as Dick Smith Electronics XH6381). - * VID/PID supplied by Donald Gordon. - * - * (19/Aug/2003) Ian Abbott - * Freed urb's transfer buffer in write bulk callback. - * Omitted some paranoid checks in write bulk callback that don't matter. - * Scheduled work in write bulk callback regardless of port's open count. - * - * (05/Aug/2003) Ian Abbott - * Added VID/PID for ID TECH IDT1221U USB to RS-232 adapter. - * VID/PID provided by Steve Briggs. - * - * (23/Jul/2003) Ian Abbott - * Added PIDs for CrystalFontz 547, 633, 631, 635, 640 and 640 from - * Wayne Wylupski. - * - * (10/Jul/2003) David Glance - * Added PID for DSS-20 SyncStation cradle for Sony-Ericsson P800. - * - * (27/Jun/2003) Ian Abbott - * Reworked the urb handling logic. We have no more pool, but dynamically - * allocate the urb and the transfer buffer on the fly. In testing this - * does not incure any measurable overhead. This also relies on the fact - * that we have proper reference counting logic for urbs. I nicked this - * from Greg KH's Visor driver. - * - * (23/Jun/2003) Ian Abbott - * Reduced flip buffer pushes and corrected a data length test in - * ftdi_read_bulk_callback. - * Defererence pointers after any paranoid checks, not before. - * - * (21/Jun/2003) Erik Nygren - * Added support for Home Electronics Tira-1 IR transceiver using FT232BM chip. - * See . Only operates properly - * at 100000 and RTS-CTS, so set custom divisor mode on startup. - * Also force the Tira-1 and USB-UIRT to only use their custom baud rates. - * - * (18/Jun/2003) Ian Abbott - * Added Device ID of the USB relais from Rudolf Gugler (backported from - * Philipp Gühring's patch for 2.5.x kernel). - * Moved read transfer buffer reallocation into startup function. - * Free existing write urb and transfer buffer in startup function. - * Only use urbs in write urb pool that were successfully allocated. - * Moved some constant macros out of functions. - * Minor whitespace and comment changes. - * - * (12/Jun/2003) David Norwood - * Added support for USB-UIRT IR transceiver using 8U232AM chip. - * See . Only - * operates properly at 312500, so set custom divisor mode on startup. - * - * (12/Jun/2003) Ian Abbott - * Added Sealevel SeaLINK+ 210x, 220x, 240x, 280x vid/pids from Tuan Hoang - * - I've eliminated some that don't seem to exist! - * Added Home Electronics Tira-1 IR transceiver pid from Chris Horn - * Some whitespace/coding-style cleanups - * - * (11/Jun/2003) Ian Abbott - * Fixed unsafe spinlock usage in ftdi_write - * - * (24/Feb/2003) Richard Shooter - * Increase read buffer size to improve read speeds at higher baud rates - * (specifically tested with up to 1Mb/sec at 1.5M baud) - * - * (23/Feb/2003) John Wilkins - * Added Xon/xoff flow control (activating support in the ftdi device) - * Added vid/pid for Videonetworks/Homechoice (UK ISP) - * - * (23/Feb/2003) Bill Ryder - * Added matrix orb device vid/pids from Wayne Wylupski - * - * (19/Feb/2003) Ian Abbott - * For TIOCSSERIAL, set alt_speed to 0 when ASYNC_SPD_MASK value has - * changed to something other than ASYNC_SPD_HI, ASYNC_SPD_VHI, - * ASYNC_SPD_SHI or ASYNC_SPD_WARP. Also, unless ASYNC_SPD_CUST is in - * force, don't bother changing baud rate when custom_divisor has changed. - * - * (18/Feb/2003) Ian Abbott - * Fixed TIOCMGET handling to include state of DTR and RTS, the state - * of which are now saved by set_dtr() and set_rts(). - * Fixed improper storage class for buf in set_dtr() and set_rts(). - * Added FT232BM chip type and support for its extra baud rates (compared - * to FT8U232AM). - * Took account of special case divisor values for highest baud rates of - * FT8U232AM and FT232BM. - * For TIOCSSERIAL, forced alt_speed to 0 when ASYNC_SPD_CUST kludge used, - * as previous alt_speed setting is now stale. - * Moved startup code common between the startup routines for the - * different chip types into a common subroutine. - * - * (17/Feb/2003) Bill Ryder - * Added write urb buffer pool on a per device basis - * Added more checking for open file on callbacks (fixed OOPS) - * Added CrystalFontz 632 and 634 PIDs - * (thanx to CrystalFontz for the sample devices - they flushed out - * some driver bugs) - * Minor debugging message changes - * Added throttle, unthrottle and chars_in_buffer functions - * Fixed FTDI_SIO (the original device) bug - * Fixed some shutdown handling - * - * - * - * - * (07/Jun/2002) Kuba Ober - * Changed FTDI_SIO_BASE_BAUD_TO_DIVISOR macro into ftdi_baud_to_divisor - * function. It was getting too complex. - * Fix the divisor calculation logic which was setting divisor of 0.125 - * instead of 0.5 for fractional parts of divisor equal to 5/8, 6/8, 7/8. - * Also make it bump up the divisor to next integer in case of 7/8 - it's - * a better approximation. - * - * (25/Jul/2002) Bill Ryder inserted Dmitri's TIOCMIWAIT patch - * Not tested by me but it doesn't break anything I use. - * - * (04/Jan/2002) Kuba Ober - * Implemented 38400 baudrate kludge, where it can be substituted with other - * values. That's the only way to set custom baudrates. - * Implemented TIOCSSERIAL, TIOCGSERIAL ioctl's so that setserial is happy. - * FIXME: both baudrate things should eventually go to usbserial.c as other - * devices may need that functionality too. Actually, it can probably be - * merged in serial.c somehow - too many drivers repeat this code over - * and over. - * Fixed baudrate forgetfulness - open() used to reset baudrate to 9600 every time. - * Divisors for baudrates are calculated by a macro. - * Small code cleanups. Ugly whitespace changes for Plato's sake only ;-]. - * - * (04/Nov/2001) Bill Ryder - * Fixed bug in read_bulk_callback where incorrect urb buffer was used. - * Cleaned up write offset calculation - * Added write_room since default values can be incorrect for sio - * Changed write_bulk_callback to use same queue_task as other drivers - * (the previous version caused panics) - * Removed port iteration code since the device only has one I/O port and it - * was wrong anyway. - * - * (31/May/2001) gkh - * Switched from using spinlock to a semaphore, which fixes lots of problems. - * - * (23/May/2001) Bill Ryder - * Added runtime debug patch (thanx Tyson D Sawyer). - * Cleaned up comments for 8U232 - * Added parity, framing and overrun error handling - * Added receive break handling. - * - * (04/08/2001) gb - * Identify version on module load. - * - * (18/March/2001) Bill Ryder - * (Not released) - * Added send break handling. (requires kernel patch too) - * Fixed 8U232AM hardware RTS/CTS etc status reporting. - * Added flipbuf fix copied from generic device - * - * (12/3/2000) Bill Ryder - * Added support for 8U232AM device. - * Moved PID and VIDs into header file only. - * Turned on low-latency for the tty (device will do high baudrates) - * Added shutdown routine to close files when device removed. - * More debug and error message cleanups. - * - * (11/13/2000) Bill Ryder - * Added spinlock protected open code and close code. - * Multiple opens work (sort of - see webpage mentioned above). - * Cleaned up comments. Removed multiple PID/VID definitions. - * Factorised cts/dtr code - * Made use of __FUNCTION__ in dbg's - * - * (11/01/2000) Adam J. Richter - * usb_device_id table support - * - * (10/05/2000) gkh - * Fixed bug with urb->dev not being set properly, now that the usb - * core needs it. - * - * (09/11/2000) gkh - * Removed DEBUG #ifdefs with call to usb_serial_debug_data - * - * (07/19/2000) gkh - * Added module_init and module_exit functions to handle the fact that this - * driver is a loadable module now. - * - * (04/04/2000) Bill Ryder - * Fixed bugs in TCGET/TCSET ioctls (by removing them - they are - * handled elsewhere in the tty io driver chain). - * - * (03/30/2000) Bill Ryder - * Implemented lots of ioctls - * Fixed a race condition in write - * Changed some dbg's to errs - * - * (03/26/2000) gkh - * Split driver up into device specific pieces. + * Change entries from 2004 and earlier can be found in versions of this + * file in kernel versions prior to the 2.6.24 release. * */ -- cgit v1.2.3 From 828d55c58cba6b652fd30e00c3d940cb7c523e3c Mon Sep 17 00:00:00 2001 From: Yoshihiro Shimoda Date: Fri, 11 Jan 2008 22:56:15 +0900 Subject: USB: add support for SuperH OHCI add support for SuperH OHCI. supported CPU are: - SH7720 - SH7721 - SH7763 Signed-off-by: Yoshihiro Shimoda Acked-by: David Brownell Signed-off-by: Greg Kroah-Hartman --- drivers/usb/Kconfig | 4 ++ drivers/usb/host/ohci-hcd.c | 7 +++ drivers/usb/host/ohci-sh.c | 143 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 154 insertions(+) create mode 100644 drivers/usb/host/ohci-sh.c diff --git a/drivers/usb/Kconfig b/drivers/usb/Kconfig index 8d48d973efcb..755823cdf62a 100644 --- a/drivers/usb/Kconfig +++ b/drivers/usb/Kconfig @@ -42,6 +42,10 @@ config USB_ARCH_HAS_OHCI default y if PPC_MPC52xx # MIPS: default y if SOC_AU1X00 + # SH: + default y if CPU_SUBTYPE_SH7720 + default y if CPU_SUBTYPE_SH7721 + default y if CPU_SUBTYPE_SH7763 # more: default PCI diff --git a/drivers/usb/host/ohci-hcd.c b/drivers/usb/host/ohci-hcd.c index 8dd5d25f2f06..b8ed84d5406d 100644 --- a/drivers/usb/host/ohci-hcd.c +++ b/drivers/usb/host/ohci-hcd.c @@ -1029,6 +1029,13 @@ MODULE_LICENSE ("GPL"); #define PLATFORM_DRIVER usb_hcd_pnx4008_driver #endif +#if defined(CONFIG_CPU_SUBTYPE_SH7720) || \ + defined(CONFIG_CPU_SUBTYPE_SH7721) || \ + defined(CONFIG_CPU_SUBTYPE_SH7763) +#include "ohci-sh.c" +#define PLATFORM_DRIVER ohci_hcd_sh_driver +#endif + #ifdef CONFIG_USB_OHCI_HCD_PPC_OF #include "ohci-ppc-of.c" 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 @@ +/* + * OHCI HCD (Host Controller Driver) for USB. + * + * Copyright (C) 2008 Renesas Solutions Corp. + * + * Author : Yoshihiro Shimoda + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +#include + +static int ohci_sh_start(struct usb_hcd *hcd) +{ + struct ohci_hcd *ohci = hcd_to_ohci(hcd); + + ohci_hcd_init(ohci); + ohci_init(ohci); + ohci_run(ohci); + hcd->state = HC_STATE_RUNNING; + return 0; +} + +static const struct hc_driver ohci_sh_hc_driver = { + .description = hcd_name, + .product_desc = "SuperH OHCI", + .hcd_priv_size = sizeof(struct ohci_hcd), + + /* + * generic hardware linkage + */ + .irq = ohci_irq, + .flags = HCD_USB11 | HCD_MEMORY, + + /* + * basic lifecycle operations + */ + .start = ohci_sh_start, + .stop = ohci_stop, + .shutdown = ohci_shutdown, + + /* + * managing i/o requests and associated device resources + */ + .urb_enqueue = ohci_urb_enqueue, + .urb_dequeue = ohci_urb_dequeue, + .endpoint_disable = ohci_endpoint_disable, + + /* + * scheduling support + */ + .get_frame_number = ohci_get_frame, + + /* + * root hub support + */ + .hub_status_data = ohci_hub_status_data, + .hub_control = ohci_hub_control, + .hub_irq_enable = ohci_rhsc_enable, +#ifdef CONFIG_PM + .bus_suspend = ohci_bus_suspend, + .bus_resume = ohci_bus_resume, +#endif + .start_port_reset = ohci_start_port_reset, +}; + +/*-------------------------------------------------------------------------*/ + +#define resource_len(r) (((r)->end - (r)->start) + 1) +static int ohci_hcd_sh_probe(struct platform_device *pdev) +{ + struct resource *res = NULL; + struct usb_hcd *hcd = NULL; + int irq = -1; + int ret; + + if (usb_disabled()) + return -ENODEV; + + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); + if (!res) { + err("platform_get_resource error."); + return -ENODEV; + } + + irq = platform_get_irq(pdev, 0); + if (irq < 0) { + err("platform_get_irq error."); + return -ENODEV; + } + + /* initialize hcd */ + hcd = usb_create_hcd(&ohci_sh_hc_driver, &pdev->dev, (char *)hcd_name); + if (!hcd) { + err("Failed to create hcd"); + return -ENOMEM; + } + + hcd->regs = (void __iomem *)res->start; + hcd->rsrc_start = res->start; + hcd->rsrc_len = resource_len(res); + ret = usb_add_hcd(hcd, irq, IRQF_DISABLED); + if (ret != 0) { + err("Failed to add hcd"); + usb_put_hcd(hcd); + return ret; + } + + return ret; +} + +static int ohci_hcd_sh_remove(struct platform_device *pdev) +{ + struct usb_hcd *hcd = platform_get_drvdata(pdev); + + usb_remove_hcd(hcd); + usb_put_hcd(hcd); + + return 0; +} + +static struct platform_driver ohci_hcd_sh_driver = { + .probe = ohci_hcd_sh_probe, + .remove = ohci_hcd_sh_remove, + .shutdown = usb_hcd_platform_shutdown, + .driver = { + .name = "sh_ohci", + .owner = THIS_MODULE, + }, +}; + -- cgit v1.2.3 From a1cd7e99b343543af2be4c8c5755e26f6bfd725a Mon Sep 17 00:00:00 2001 From: Oliver Neukum Date: Wed, 16 Jan 2008 17:18:52 +0100 Subject: USB: stop io performed by mos7720 upon close() This fixes a problem where the mos7720 driver will make io to a device from which it has been logically disconnected. It does so by introducing a flag by which the generic usb serial code can signal the subdrivers their disconnection and appropriate locking. Signed-off-by: Oliver Neukum Signed-off-by: Greg Kroah-Hartman --- drivers/usb/serial/mos7720.c | 33 ++++++++++++++++++--------------- drivers/usb/serial/usb-serial.c | 28 ++++++++++++++-------------- include/linux/usb/serial.h | 2 ++ 3 files changed, 34 insertions(+), 29 deletions(-) diff --git a/drivers/usb/serial/mos7720.c b/drivers/usb/serial/mos7720.c index 725991fadc26..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) } /* While closing port, shutdown all bulk read, write * - * and interrupt read if they exists */ - if (serial->dev) { - dbg("Shutdown bulk write"); - usb_kill_urb(port->write_urb); - dbg("Shutdown bulk read"); - usb_kill_urb(port->read_urb); + * and interrupt read if they exists, otherwise nop */ + dbg("Shutdown bulk write"); + usb_kill_urb(port->write_urb); + dbg("Shutdown bulk read"); + usb_kill_urb(port->read_urb); + + mutex_lock(&serial->disc_mutex); + /* these commands must not be issued if the device has + * been disconnected */ + if (!serial->disconnected) { + data = 0x00; + send_mos_cmd(serial, MOS_WRITE, port->number - port->serial->minor, + 0x04, &data); + + data = 0x00; + send_mos_cmd(serial, MOS_WRITE, port->number - port->serial->minor, + 0x01, &data); } - - data = 0x00; - send_mos_cmd(serial, MOS_WRITE, port->number - port->serial->minor, - 0x04, &data); - - data = 0x00; - send_mos_cmd(serial, MOS_WRITE, port->number - port->serial->minor, - 0x01, &data); - + mutex_unlock(&serial->disc_mutex); mos7720_port->open = 0; dbg("Leaving %s", __FUNCTION__); diff --git a/drivers/usb/serial/usb-serial.c b/drivers/usb/serial/usb-serial.c index 28315b05c9cc..3ce98e8d7bce 100644 --- a/drivers/usb/serial/usb-serial.c +++ b/drivers/usb/serial/usb-serial.c @@ -634,6 +634,7 @@ static struct usb_serial * create_serial (struct usb_device *dev, serial->type = driver; serial->interface = interface; kref_init(&serial->kref); + mutex_init(&serial->disc_mutex); return serial; } @@ -1089,20 +1090,22 @@ void usb_serial_disconnect(struct usb_interface *interface) usb_serial_console_disconnect(serial); dbg ("%s", __FUNCTION__); + mutex_lock(&serial->disc_mutex); usb_set_intfdata (interface, NULL); - if (serial) { - for (i = 0; i < serial->num_ports; ++i) { - port = serial->port[i]; - if (port) { - if (port->tty) - tty_hangup(port->tty); - kill_traffic(port); - } + /* must set a flag, to signal subdrivers */ + serial->disconnected = 1; + for (i = 0; i < serial->num_ports; ++i) { + port = serial->port[i]; + if (port) { + if (port->tty) + tty_hangup(port->tty); + kill_traffic(port); } - /* let the last holder of this object - * cause it to be cleaned up */ - usb_serial_put(serial); } + /* let the last holder of this object + * cause it to be cleaned up */ + mutex_unlock(&serial->disc_mutex); + usb_serial_put(serial); dev_info(dev, "device disconnected\n"); } @@ -1112,9 +1115,6 @@ int usb_serial_suspend(struct usb_interface *intf, pm_message_t message) struct usb_serial_port *port; int i, r = 0; - if (!serial) /* device has been disconnected */ - return 0; - for (i = 0; i < serial->num_ports; ++i) { port = serial->port[i]; if (port) diff --git a/include/linux/usb/serial.h b/include/linux/usb/serial.h index ef1e430f7bfa..63b29b5332e6 100644 --- a/include/linux/usb/serial.h +++ b/include/linux/usb/serial.h @@ -129,6 +129,7 @@ struct usb_serial { struct usb_device * dev; struct usb_serial_driver * type; struct usb_interface * interface; + unsigned char disconnected; unsigned char minor; unsigned char num_ports; unsigned char num_port_pointers; @@ -138,6 +139,7 @@ struct usb_serial { char num_bulk_out; struct usb_serial_port * port[MAX_NUM_PORTS]; struct kref kref; + struct mutex disc_mutex; void * private; }; #define to_usb_serial(d) container_of(d, struct usb_serial, kref) -- cgit v1.2.3 From 0b3f5fe673d4626ea91816ca9c486b43b39a2fd1 Mon Sep 17 00:00:00 2001 From: Jan Engelhardt Date: Tue, 22 Jan 2008 20:51:11 +0100 Subject: USB: constify function pointer tables Signed-off-by: Jan Engelhardt Signed-off-by: Greg Kroah-Hartman --- drivers/usb/misc/iowarrior.c | 2 +- drivers/usb/mon/mon_bin.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) 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) * would use "struct net_driver" instead, and a serial * device would use "struct tty_driver". */ -static struct file_operations iowarrior_fops = { +static const struct file_operations iowarrior_fops = { .owner = THIS_MODULE, .write = iowarrior_write, .read = iowarrior_read, diff --git a/drivers/usb/mon/mon_bin.c b/drivers/usb/mon/mon_bin.c index d70666f1a90d..1774ba5c4c3b 100644 --- a/drivers/usb/mon/mon_bin.c +++ b/drivers/usb/mon/mon_bin.c @@ -1081,7 +1081,7 @@ int mon_bin_mmap(struct file *filp, struct vm_area_struct *vma) #endif /* 0 */ -static struct file_operations mon_fops_binary = { +static const struct file_operations mon_fops_binary = { .owner = THIS_MODULE, .open = mon_bin_open, .llseek = no_llseek, -- cgit v1.2.3 From 9e3b1d8e3d5d135ac7be43f6710b7a67b569c292 Mon Sep 17 00:00:00 2001 From: Oliver Neukum Date: Tue, 22 Jan 2008 15:54:54 +0100 Subject: USB: stop abuse of intfdata in cypress_m8 this driver uses usb_get_intfdata() == NULL as a test for disconnect(). You must not do that as this races with probe(). By the time you test your erstwhile interface may already be somebody else's interface. This fixes the close() method of cypress_m8 to use the recently introduced flag and use locking against disconnect() where required in close(). Signed-off-by: Oliver Neukum Signed-off-by: Greg Kroah-Hartman --- drivers/usb/serial/cypress_m8.c | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) 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) { struct cypress_private *priv = usb_get_serial_port_data(port); unsigned int c_cflag; - unsigned long flags; int bps; long timeout; wait_queue_t wait; @@ -690,7 +689,7 @@ static void cypress_close(struct usb_serial_port *port, struct file * filp) dbg("%s - port %d", __FUNCTION__, port->number); /* wait for data to drain from buffer */ - spin_lock_irqsave(&priv->lock, flags); + spin_lock_irq(&priv->lock); timeout = CYPRESS_CLOSING_WAIT; init_waitqueue_entry(&wait, current); add_wait_queue(&port->tty->write_wait, &wait); @@ -698,18 +697,25 @@ static void cypress_close(struct usb_serial_port *port, struct file * filp) set_current_state(TASK_INTERRUPTIBLE); if (cypress_buf_data_avail(priv->buf) == 0 || timeout == 0 || signal_pending(current) - || !usb_get_intfdata(port->serial->interface)) + /* without mutex, allowed due to harmless failure mode */ + || port->serial->disconnected) break; - spin_unlock_irqrestore(&priv->lock, flags); + spin_unlock_irq(&priv->lock); timeout = schedule_timeout(timeout); - spin_lock_irqsave(&priv->lock, flags); + spin_lock_irq(&priv->lock); } set_current_state(TASK_RUNNING); remove_wait_queue(&port->tty->write_wait, &wait); /* clear out any remaining data in the buffer */ cypress_buf_clear(priv->buf); - spin_unlock_irqrestore(&priv->lock, flags); - + spin_unlock_irq(&priv->lock); + + /* writing is potentially harmful, lock must be taken */ + mutex_lock(&port->serial->disc_mutex); + if (port->serial->disconnected) { + mutex_unlock(&port->serial->disc_mutex); + return; + } /* wait for characters to drain from device */ bps = tty_get_baud_rate(port->tty); if (bps > 1200) @@ -727,10 +733,10 @@ static void cypress_close(struct usb_serial_port *port, struct file * filp) if (c_cflag & HUPCL) { /* drop dtr and rts */ priv = usb_get_serial_port_data(port); - spin_lock_irqsave(&priv->lock, flags); + spin_lock_irq(&priv->lock); priv->line_control = 0; priv->cmd_ctrl = 1; - spin_unlock_irqrestore(&priv->lock, flags); + spin_unlock_irq(&priv->lock); cypress_write(port, NULL, 0); } } @@ -738,6 +744,7 @@ static void cypress_close(struct usb_serial_port *port, struct file * filp) if (stats) dev_info (&port->dev, "Statistics: %d Bytes In | %d Bytes Out | %d Commands Issued\n", priv->bytes_in, priv->bytes_out, priv->cmd_count); + mutex_unlock(&port->serial->disc_mutex); } /* cypress_close */ -- cgit v1.2.3 From 004b4f2d4448cff7f13871c05d744b00a7c74d4a Mon Sep 17 00:00:00 2001 From: Oliver Neukum Date: Tue, 22 Jan 2008 14:24:56 +0100 Subject: USB: fix memleak in ark3116 serial driver in an error case memory already allocated must be freed again. Signed-off-by: Oliver Neukum Signed-off-by: Greg Kroah-Hartman --- drivers/usb/serial/ark3116.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) 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) return 0; cleanup: - for (--i; i >= 0; --i) + for (--i; i >= 0; --i) { + kfree(usb_get_serial_port_data(serial->port[i])); usb_set_serial_port_data(serial->port[i], NULL); + } return -ENOMEM; } -- cgit v1.2.3 From e33fe4d86f91127f6f7d931ff59ed6cbda06e72b Mon Sep 17 00:00:00 2001 From: Oliver Neukum Date: Mon, 21 Jan 2008 17:44:10 +0100 Subject: USB: make sure usb serial drivers don't flush to logically disconnected devices If disconnect() is called for a logical disconnect, no more IO must be done after disconnect() returns, or the old and new drivers may conflict. This patch avoids this by using the flag and lock introduced by the earlier patch for the mos7720 driver. Signed-off-by: Oliver Neukum Signed-off-by: Greg Kroah-Hartman --- drivers/usb/serial/mct_u232.c | 17 +++++++++-------- drivers/usb/serial/option.c | 5 ++++- drivers/usb/serial/sierra.c | 5 ++++- drivers/usb/serial/visor.c | 22 +++++++++++++--------- drivers/usb/serial/whiteheat.c | 7 +++++-- 5 files changed, 35 insertions(+), 21 deletions(-) diff --git a/drivers/usb/serial/mct_u232.c b/drivers/usb/serial/mct_u232.c index 88b2074867c5..fc1cea4aba13 100644 --- a/drivers/usb/serial/mct_u232.c +++ b/drivers/usb/serial/mct_u232.c @@ -487,21 +487,22 @@ error: static void mct_u232_close (struct usb_serial_port *port, struct file *filp) { unsigned int c_cflag; - unsigned long flags; unsigned int control_state; struct mct_u232_private *priv = usb_get_serial_port_data(port); dbg("%s port %d", __FUNCTION__, port->number); if (port->tty) { c_cflag = port->tty->termios->c_cflag; - if (c_cflag & HUPCL) { - /* drop DTR and RTS */ - spin_lock_irqsave(&priv->lock, flags); - priv->control_state &= ~(TIOCM_DTR | TIOCM_RTS); - control_state = priv->control_state; - spin_unlock_irqrestore(&priv->lock, flags); - mct_u232_set_modem_ctrl(port->serial, control_state); + mutex_lock(&port->serial->disc_mutex); + if (c_cflag & HUPCL && !port->serial->disconnected) { + /* drop DTR and RTS */ + spin_lock_irq(&priv->lock); + priv->control_state &= ~(TIOCM_DTR | TIOCM_RTS); + control_state = priv->control_state; + spin_unlock_irq(&priv->lock); + mct_u232_set_modem_ctrl(port->serial, control_state); } + mutex_unlock(&port->serial->disc_mutex); } diff --git a/drivers/usb/serial/option.c b/drivers/usb/serial/option.c index bbbe1b962008..5e8bf1bc1e50 100644 --- a/drivers/usb/serial/option.c +++ b/drivers/usb/serial/option.c @@ -641,7 +641,10 @@ static void option_close(struct usb_serial_port *port, struct file *filp) portdata->dtr_state = 0; if (serial->dev) { - option_send_setup(port); + mutex_lock(&serial->disc_mutex); + if (!serial->disconnected) + option_send_setup(port); + mutex_unlock(&serial->disc_mutex); /* Stop reading/writing urbs */ for (i = 0; i < N_IN_URB; i++) diff --git a/drivers/usb/serial/sierra.c b/drivers/usb/serial/sierra.c index 953bdf8827d2..4c925e3e8a63 100644 --- a/drivers/usb/serial/sierra.c +++ b/drivers/usb/serial/sierra.c @@ -597,7 +597,10 @@ static void sierra_close(struct usb_serial_port *port, struct file *filp) portdata->dtr_state = 0; if (serial->dev) { - sierra_send_setup(port); + mutex_lock(&serial->disc_mutex); + if (!serial->disconnected) + sierra_send_setup(port); + mutex_unlock(&serial->disc_mutex); /* Stop reading/writing urbs */ for (i = 0; i < N_IN_URB; i++) diff --git a/drivers/usb/serial/visor.c b/drivers/usb/serial/visor.c index 7ee087fed913..c2347995c786 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) usb_kill_urb(port->read_urb); usb_kill_urb(port->interrupt_in_urb); - /* Try to send shutdown message, if the device is gone, this will just fail. */ - transfer_buffer = kmalloc (0x12, GFP_KERNEL); - if (transfer_buffer) { - usb_control_msg (port->serial->dev, - usb_rcvctrlpipe(port->serial->dev, 0), - VISOR_CLOSE_NOTIFICATION, 0xc2, - 0x0000, 0x0000, - transfer_buffer, 0x12, 300); - kfree (transfer_buffer); + mutex_lock(&port->serial->disc_mutex); + if (!port->serial->disconnected) { + /* Try to send shutdown message, unless the device is gone */ + transfer_buffer = kmalloc (0x12, GFP_KERNEL); + if (transfer_buffer) { + usb_control_msg (port->serial->dev, + usb_rcvctrlpipe(port->serial->dev, 0), + VISOR_CLOSE_NOTIFICATION, 0xc2, + 0x0000, 0x0000, + transfer_buffer, 0x12, 300); + kfree (transfer_buffer); + } } + mutex_lock(&port->serial->disc_mutex); if (stats) 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 f5033d482eee..38726ef3132b 100644 --- a/drivers/usb/serial/whiteheat.c +++ b/drivers/usb/serial/whiteheat.c @@ -658,11 +658,14 @@ static void whiteheat_close(struct usb_serial_port *port, struct file * filp) struct list_head *tmp2; dbg("%s - port %d", __FUNCTION__, port->number); - + + mutex_lock(&port->serial->disc_mutex); /* filp is NULL when called from usb_serial_disconnect */ - if (filp && (tty_hung_up_p(filp))) { + if ((filp && (tty_hung_up_p(filp))) || port->serial->disconnected) { + mutex_unlock(&port->serial->disc_mutex); return; } + mutex_unlock(&port->serial->disc_mutex); port->tty->closing = 1; -- cgit v1.2.3 From 95bef012ea4a3cce437a4fcf59bb097d14944b0d Mon Sep 17 00:00:00 2001 From: Oliver Neukum Date: Tue, 22 Jan 2008 13:56:18 +0100 Subject: USB: more serial drivers writing after disconnect this covers the rest of the obvious cases by using the flags and locks to guard against disconnect which were introduced in the earlier patch against mos7720. Signed-off-by: Oliver Neukum Signed-off-by: Greg Kroah-Hartman --- drivers/usb/serial/airprime.c | 5 ++++- drivers/usb/serial/cp2101.c | 5 ++++- drivers/usb/serial/ftdi_sio.c | 4 +++- drivers/usb/serial/garmin_gps.c | 17 ++++++++++++----- drivers/usb/serial/visor.c | 2 +- 5 files changed, 24 insertions(+), 9 deletions(-) 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) priv->rts_state = 0; priv->dtr_state = 0; - airprime_send_setup(port); + mutex_lock(&port->serial->disc_mutex); + if (!port->serial->disconnected) + airprime_send_setup(port); + mutex_lock(&port->serial->disc_mutex); for (i = 0; i < NUM_READ_URBS; ++i) { usb_kill_urb (priv->read_urbp[i]); diff --git a/drivers/usb/serial/cp2101.c b/drivers/usb/serial/cp2101.c index cd5f71b7f637..f3ca66017a03 100644 --- a/drivers/usb/serial/cp2101.c +++ b/drivers/usb/serial/cp2101.c @@ -348,7 +348,10 @@ static void cp2101_close (struct usb_serial_port *port, struct file * filp) usb_kill_urb(port->write_urb); usb_kill_urb(port->read_urb); - cp2101_set_config_single(port, CP2101_UART, UART_DISABLE); + mutex_lock(&port->serial->disc_mutex); + if (!port->serial->disconnected) + cp2101_set_config_single(port, CP2101_UART, UART_DISABLE); + mutex_unlock(&port->serial->disc_mutex); } /* diff --git a/drivers/usb/serial/ftdi_sio.c b/drivers/usb/serial/ftdi_sio.c index 2c142bb04fe1..90dcc625f70d 100644 --- a/drivers/usb/serial/ftdi_sio.c +++ b/drivers/usb/serial/ftdi_sio.c @@ -1198,7 +1198,8 @@ static void ftdi_close (struct usb_serial_port *port, struct file *filp) dbg("%s", __FUNCTION__); - if (c_cflag & HUPCL){ + mutex_lock(&port->serial->disc_mutex); + if (c_cflag & HUPCL && !port->serial->disconnected){ /* Disable flow control */ if (usb_control_msg(port->serial->dev, usb_sndctrlpipe(port->serial->dev, 0), @@ -1212,6 +1213,7 @@ static void ftdi_close (struct usb_serial_port *port, struct file *filp) /* drop RTS and DTR */ clear_mctrl(port, TIOCM_DTR | TIOCM_RTS); } /* Note change no line if hupcl is off */ + mutex_unlock(&port->serial->disc_mutex); /* cancel any scheduled reading */ cancel_delayed_work(&priv->rx_work); 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) if (!serial) return; - garmin_clear(garmin_data_p); + mutex_lock(&port->serial->disc_mutex); + if (!port->serial->disconnected) + garmin_clear(garmin_data_p); /* shutdown our urbs */ usb_kill_urb (port->read_urb); usb_kill_urb (port->write_urb); - if (noResponseFromAppLayer(garmin_data_p) || - ((garmin_data_p->flags & CLEAR_HALT_REQUIRED) != 0)) { - process_resetdev_request(port); - garmin_data_p->state = STATE_RESET; + if (!port->serial->disconnected) { + if (noResponseFromAppLayer(garmin_data_p) || + ((garmin_data_p->flags & CLEAR_HALT_REQUIRED) != 0)) { + process_resetdev_request(port); + garmin_data_p->state = STATE_RESET; + } else { + garmin_data_p->state = STATE_DISCONNECTED; + } } else { garmin_data_p->state = STATE_DISCONNECTED; } + mutex_unlock(&port->serial->disc_mutex); } diff --git a/drivers/usb/serial/visor.c b/drivers/usb/serial/visor.c index c2347995c786..22b3f78a388c 100644 --- a/drivers/usb/serial/visor.c +++ b/drivers/usb/serial/visor.c @@ -362,7 +362,7 @@ static void visor_close (struct usb_serial_port *port, struct file * filp) kfree (transfer_buffer); } } - mutex_lock(&port->serial->disc_mutex); + mutex_unlock(&port->serial->disc_mutex); if (stats) dev_info(&port->dev, "Bytes In = %d Bytes Out = %d\n", -- cgit v1.2.3 From b0a239da17beb34354181bebb744c0b0d534967f Mon Sep 17 00:00:00 2001 From: Alan Cox Date: Sat, 19 Jan 2008 16:02:37 +0000 Subject: USB: oti6858: cleanup - Rename the copied buffer functions from pl2303 to oti6858 to avodi confusion - Initialise speeds properly - Use modern baud rate handling - Remove GSERIAL/SSERIAL ioctl hacks that reference termios unlocked Signed-off-by: Alan Cox Signed-off-by: Greg Kroah-Hartman --- drivers/usb/serial/oti6858.c | 129 +++++++++++++++---------------------------- 1 file changed, 46 insertions(+), 83 deletions(-) diff --git a/drivers/usb/serial/oti6858.c b/drivers/usb/serial/oti6858.c index eea226ae37bd..db725aaf7d19 100644 --- a/drivers/usb/serial/oti6858.c +++ b/drivers/usb/serial/oti6858.c @@ -79,7 +79,7 @@ static int debug; #define PL2303_BUF_SIZE 1024 #define PL2303_TMP_BUF_SIZE 1024 -struct pl2303_buf { +struct oti6858_buf { unsigned int buf_size; char *buf_buf; char *buf_get; @@ -161,14 +161,14 @@ static int oti6858_startup(struct usb_serial *serial); static void oti6858_shutdown(struct usb_serial *serial); /* functions operating on buffers */ -static struct pl2303_buf *pl2303_buf_alloc(unsigned int size); -static void pl2303_buf_free(struct pl2303_buf *pb); -static void pl2303_buf_clear(struct pl2303_buf *pb); -static unsigned int pl2303_buf_data_avail(struct pl2303_buf *pb); -static unsigned int pl2303_buf_space_avail(struct pl2303_buf *pb); -static unsigned int pl2303_buf_put(struct pl2303_buf *pb, const char *buf, +static struct oti6858_buf *oti6858_buf_alloc(unsigned int size); +static void oti6858_buf_free(struct oti6858_buf *pb); +static void oti6858_buf_clear(struct oti6858_buf *pb); +static unsigned int oti6858_buf_data_avail(struct oti6858_buf *pb); +static unsigned int oti6858_buf_space_avail(struct oti6858_buf *pb); +static unsigned int oti6858_buf_put(struct oti6858_buf *pb, const char *buf, unsigned int count); -static unsigned int pl2303_buf_get(struct pl2303_buf *pb, char *buf, +static unsigned int oti6858_buf_get(struct oti6858_buf *pb, char *buf, unsigned int count); @@ -203,7 +203,7 @@ static struct usb_serial_driver oti6858_device = { struct oti6858_private { spinlock_t lock; - struct pl2303_buf *buf; + struct oti6858_buf *buf; struct oti6858_control_pkt status; struct { @@ -316,7 +316,7 @@ void send_data(struct work_struct *work) } priv->flags.write_urb_in_use = 1; - count = pl2303_buf_data_avail(priv->buf); + count = oti6858_buf_data_avail(priv->buf); spin_unlock_irqrestore(&priv->lock, flags); if (count > port->bulk_out_size) count = port->bulk_out_size; @@ -345,7 +345,7 @@ void send_data(struct work_struct *work) } spin_lock_irqsave(&priv->lock, flags); - pl2303_buf_get(priv->buf, port->write_urb->transfer_buffer, count); + oti6858_buf_get(priv->buf, port->write_urb->transfer_buffer, count); spin_unlock_irqrestore(&priv->lock, flags); port->write_urb->transfer_buffer_length = count; @@ -370,7 +370,7 @@ static int oti6858_startup(struct usb_serial *serial) priv = kzalloc(sizeof(struct oti6858_private), GFP_KERNEL); if (!priv) break; - priv->buf = pl2303_buf_alloc(PL2303_BUF_SIZE); + priv->buf = oti6858_buf_alloc(PL2303_BUF_SIZE); if (priv->buf == NULL) { kfree(priv); break; @@ -391,7 +391,7 @@ static int oti6858_startup(struct usb_serial *serial) for (--i; i >= 0; --i) { priv = usb_get_serial_port_data(serial->port[i]); - pl2303_buf_free(priv->buf); + oti6858_buf_free(priv->buf); kfree(priv); usb_set_serial_port_data(serial->port[i], NULL); } @@ -410,7 +410,7 @@ static int oti6858_write(struct usb_serial_port *port, return count; spin_lock_irqsave(&priv->lock, flags); - count = pl2303_buf_put(priv->buf, buf, count); + count = oti6858_buf_put(priv->buf, buf, count); spin_unlock_irqrestore(&priv->lock, flags); return count; @@ -425,7 +425,7 @@ static int oti6858_write_room(struct usb_serial_port *port) dbg("%s(port = %d)", __FUNCTION__, port->number); spin_lock_irqsave(&priv->lock, flags); - room = pl2303_buf_space_avail(priv->buf); + room = oti6858_buf_space_avail(priv->buf); spin_unlock_irqrestore(&priv->lock, flags); return room; @@ -440,7 +440,7 @@ static int oti6858_chars_in_buffer(struct usb_serial_port *port) dbg("%s(port = %d)", __FUNCTION__, port->number); spin_lock_irqsave(&priv->lock, flags); - chars = pl2303_buf_data_avail(priv->buf); + chars = oti6858_buf_data_avail(priv->buf); spin_unlock_irqrestore(&priv->lock, flags); return chars; @@ -458,7 +458,7 @@ static void oti6858_set_termios(struct usb_serial_port *port, dbg("%s(port = %d)", __FUNCTION__, port->number); - if ((!port->tty) || (!port->tty->termios)) { + if (!port->tty || !port->tty->termios) { dbg("%s(): no tty structures", __FUNCTION__); return; } @@ -468,6 +468,8 @@ static void oti6858_set_termios(struct usb_serial_port *port, *(port->tty->termios) = tty_std_termios; port->tty->termios->c_cflag = B38400 | CS8 | CREAD | HUPCL | CLOCAL; priv->flags.termios_initialized = 1; + port->tty->termios->c_ispeed = 38400; + port->tty->termios->c_ospeed = 38400; } spin_unlock_irqrestore(&priv->lock, flags); @@ -504,19 +506,14 @@ static void oti6858_set_termios(struct usb_serial_port *port, br = tty_get_baud_rate(port->tty); if (br == 0) { divisor = 0; - } else if (br <= OTI6858_MAX_BAUD_RATE) { + } else { int real_br; + br = min(br, OTI6858_MAX_BAUD_RATE); divisor = (96000000 + 8 * br) / (16 * br); real_br = 96000000 / (16 * divisor); - if ((((real_br - br) * 100 + br - 1) / br) > 2) { - dbg("%s(): baud rate %d is invalid", __FUNCTION__, br); - return; - } divisor = cpu_to_le16(divisor); - } else { - dbg("%s(): baud rate %d is too high", __FUNCTION__, br); - return; + tty_encode_baud_rate(port->tty, real_br, real_br); } frame_fmt &= ~FMT_STOP_BITS_MASK; @@ -650,7 +647,7 @@ static void oti6858_close(struct usb_serial_port *port, struct file *filp) dbg("%s(): entering wait loop", __FUNCTION__); for (;;) { set_current_state(TASK_INTERRUPTIBLE); - if (pl2303_buf_data_avail(priv->buf) == 0 + if (oti6858_buf_data_avail(priv->buf) == 0 || timeout == 0 || signal_pending(current) || !usb_get_intfdata(port->serial->interface)) /* disconnect */ break; @@ -663,7 +660,7 @@ static void oti6858_close(struct usb_serial_port *port, struct file *filp) dbg("%s(): after wait loop", __FUNCTION__); /* clear out any remaining data in the buffer */ - pl2303_buf_clear(priv->buf); + oti6858_buf_clear(priv->buf); spin_unlock_irqrestore(&priv->lock, flags); /* wait for characters to drain from the device */ @@ -831,21 +828,6 @@ static int oti6858_ioctl(struct usb_serial_port *port, struct file *file, return -EFAULT; return oti6858_tiocmset(port, NULL, 0, x); - case TIOCGSERIAL: - if (copy_to_user(user_arg, port->tty->termios, - sizeof(struct ktermios))) { - return -EFAULT; - } - return 0; - - case TIOCSSERIAL: - if (copy_from_user(port->tty->termios, user_arg, - sizeof(struct ktermios))) { - return -EFAULT; - } - oti6858_set_termios(port, NULL); - return 0; - case TIOCMIWAIT: dbg("%s(): TIOCMIWAIT", __FUNCTION__); return wait_modem_info(port, arg); @@ -887,7 +869,7 @@ static void oti6858_shutdown(struct usb_serial *serial) for (i = 0; i < serial->num_ports; ++i) { priv = usb_get_serial_port_data(serial->port[i]); if (priv) { - pl2303_buf_free(priv->buf); + oti6858_buf_free(priv->buf); kfree(priv); usb_set_serial_port_data(serial->port[i], NULL); } @@ -987,7 +969,7 @@ static void oti6858_read_int_callback(struct urb *urb) spin_lock_irqsave(&priv->lock, flags); if (priv->flags.write_urb_in_use == 0 - && pl2303_buf_data_avail(priv->buf) != 0) { + && oti6858_buf_data_avail(priv->buf) != 0) { schedule_delayed_work(&priv->delayed_write_work,0); resubmit = 0; } @@ -1015,9 +997,8 @@ static void oti6858_read_bulk_callback(struct urb *urb) struct tty_struct *tty; unsigned char *data = urb->transfer_buffer; unsigned long flags; - int i, result; int status = urb->status; - char tty_flag; + int result; dbg("%s(port = %d, status = %d)", __FUNCTION__, port->number, status); @@ -1045,27 +1026,9 @@ static void oti6858_read_bulk_callback(struct urb *urb) return; } - // get tty_flag from status - tty_flag = TTY_NORMAL; - -/* FIXME: probably, errors will be signalled using interrupt pipe! */ -/* - // break takes precedence over parity, - // which takes precedence over framing errors - if (status & UART_BREAK_ERROR ) - tty_flag = TTY_BREAK; - else if (status & UART_PARITY_ERROR) - tty_flag = TTY_PARITY; - else if (status & UART_FRAME_ERROR) - tty_flag = TTY_FRAME; - dbg("%s - tty_flag = %d", __FUNCTION__, tty_flag); -*/ - tty = port->tty; if (tty != NULL && urb->actual_length > 0) { - tty_buffer_request_room(tty, urb->actual_length); - for (i = 0; i < urb->actual_length; ++i) - tty_insert_flip_char(tty, data[i], tty_flag); + tty_insert_flip_string(tty, data, urb->actual_length); tty_flip_buffer_push(tty); } @@ -1133,18 +1096,18 @@ static void oti6858_write_bulk_callback(struct urb *urb) /* - * pl2303_buf_alloc + * oti6858_buf_alloc * * Allocate a circular buffer and all associated memory. */ -static struct pl2303_buf *pl2303_buf_alloc(unsigned int size) +static struct oti6858_buf *oti6858_buf_alloc(unsigned int size) { - struct pl2303_buf *pb; + struct oti6858_buf *pb; if (size == 0) return NULL; - pb = kmalloc(sizeof(struct pl2303_buf), GFP_KERNEL); + pb = kmalloc(sizeof(struct oti6858_buf), GFP_KERNEL); if (pb == NULL) return NULL; @@ -1161,11 +1124,11 @@ static struct pl2303_buf *pl2303_buf_alloc(unsigned int size) } /* - * pl2303_buf_free + * oti6858_buf_free * * Free the buffer and all associated memory. */ -static void pl2303_buf_free(struct pl2303_buf *pb) +static void oti6858_buf_free(struct oti6858_buf *pb) { if (pb) { kfree(pb->buf_buf); @@ -1174,11 +1137,11 @@ static void pl2303_buf_free(struct pl2303_buf *pb) } /* - * pl2303_buf_clear + * oti6858_buf_clear * * Clear out all data in the circular buffer. */ -static void pl2303_buf_clear(struct pl2303_buf *pb) +static void oti6858_buf_clear(struct oti6858_buf *pb) { if (pb != NULL) { /* equivalent to a get of all data available */ @@ -1187,12 +1150,12 @@ static void pl2303_buf_clear(struct pl2303_buf *pb) } /* - * pl2303_buf_data_avail + * oti6858_buf_data_avail * * Return the number of bytes of data available in the circular * buffer. */ -static unsigned int pl2303_buf_data_avail(struct pl2303_buf *pb) +static unsigned int oti6858_buf_data_avail(struct oti6858_buf *pb) { if (pb == NULL) return 0; @@ -1200,12 +1163,12 @@ static unsigned int pl2303_buf_data_avail(struct pl2303_buf *pb) } /* - * pl2303_buf_space_avail + * oti6858_buf_space_avail * * Return the number of bytes of space available in the circular * buffer. */ -static unsigned int pl2303_buf_space_avail(struct pl2303_buf *pb) +static unsigned int oti6858_buf_space_avail(struct oti6858_buf *pb) { if (pb == NULL) return 0; @@ -1213,14 +1176,14 @@ static unsigned int pl2303_buf_space_avail(struct pl2303_buf *pb) } /* - * pl2303_buf_put + * oti6858_buf_put * * Copy data data from a user buffer and put it into the circular buffer. * Restrict to the amount of space available. * * Return the number of bytes copied. */ -static unsigned int pl2303_buf_put(struct pl2303_buf *pb, const char *buf, +static unsigned int oti6858_buf_put(struct oti6858_buf *pb, const char *buf, unsigned int count) { unsigned int len; @@ -1228,7 +1191,7 @@ static unsigned int pl2303_buf_put(struct pl2303_buf *pb, const char *buf, if (pb == NULL) return 0; - len = pl2303_buf_space_avail(pb); + len = oti6858_buf_space_avail(pb); if (count > len) count = len; @@ -1252,14 +1215,14 @@ static unsigned int pl2303_buf_put(struct pl2303_buf *pb, const char *buf, } /* - * pl2303_buf_get + * oti6858_buf_get * * Get data from the circular buffer and copy to the given buffer. * Restrict to the amount of data available. * * Return the number of bytes copied. */ -static unsigned int pl2303_buf_get(struct pl2303_buf *pb, char *buf, +static unsigned int oti6858_buf_get(struct oti6858_buf *pb, char *buf, unsigned int count) { unsigned int len; @@ -1267,7 +1230,7 @@ static unsigned int pl2303_buf_get(struct pl2303_buf *pb, char *buf, if (pb == NULL) return 0; - len = pl2303_buf_data_avail(pb); + len = oti6858_buf_data_avail(pb); if (count > len) count = len; -- cgit v1.2.3 From 3edbc986509888fa9977cc180c1fe458d2f89076 Mon Sep 17 00:00:00 2001 From: Oliver Neukum Date: Tue, 22 Jan 2008 12:47:15 +0100 Subject: USB: kl5kusb105 don't flush to logically disconnected devices If disconnect() is called for a logical disconnect, no more IO must be done after disconnect() returns, or the old and new drivers may conflict. This patch avoids this by using the flag and lock introduced by the earlier patch for the mos7720 driver. Signed-off-by: Oliver Neukum Signed-off-by: Greg Kroah-Hartman --- drivers/usb/serial/kl5kusb105.c | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) 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) dbg("%s port %d", __FUNCTION__, port->number); - /* send READ_OFF */ - rc = usb_control_msg (port->serial->dev, - usb_sndctrlpipe(port->serial->dev, 0), - KL5KUSB105A_SIO_CONFIGURE, - USB_TYPE_VENDOR | USB_DIR_OUT, - KL5KUSB105A_SIO_CONFIGURE_READ_OFF, - 0, /* index */ - NULL, 0, - KLSI_TIMEOUT); - if (rc < 0) - err("Disabling read failed (error = %d)", rc); + mutex_lock(&port->serial->disc_mutex); + if (!port->serial->disconnected) { + /* send READ_OFF */ + rc = usb_control_msg (port->serial->dev, + usb_sndctrlpipe(port->serial->dev, 0), + KL5KUSB105A_SIO_CONFIGURE, + USB_TYPE_VENDOR | USB_DIR_OUT, + KL5KUSB105A_SIO_CONFIGURE_READ_OFF, + 0, /* index */ + NULL, 0, + KLSI_TIMEOUT); + if (rc < 0) + err("Disabling read failed (error = %d)", rc); + } + mutex_unlock(&port->serial->disc_mutex); /* shutdown our bulk reads and writes */ usb_kill_urb(port->write_urb); -- cgit v1.2.3 From 0915f490d81c1a5098b399ec6c0be45bd421ee1d Mon Sep 17 00:00:00 2001 From: Oliver Neukum Date: Wed, 23 Jan 2008 12:28:45 +0100 Subject: USB: last abuses of intfdata in close for usb-serial drivers these drivers abused intfdata in close() as flags for binding. That races with reprobing of those devices. This patch fixes that by using the flag and the locks introduced with the patch against mos7720. Signed-off-by: Oliver Neukum Signed-off-by: Greg Kroah-Hartman --- drivers/usb/serial/digi_acceleport.c | 13 +++++++------ drivers/usb/serial/oti6858.c | 2 +- drivers/usb/serial/pl2303.c | 2 +- drivers/usb/serial/ti_usb_3410_5052.c | 17 ++++++++++------- 4 files changed, 19 insertions(+), 15 deletions(-) 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) unsigned char buf[32]; struct tty_struct *tty = port->tty; struct digi_port *priv = usb_get_serial_port_data(port); - unsigned long flags = 0; dbg("digi_close: TOP: port=%d, open_count=%d", priv->dp_port_num, port->open_count); + mutex_lock(&port->serial->disc_mutex); /* if disconnected, just clear flags */ - if (!usb_get_intfdata(port->serial->interface)) + if (port->serial->disconnected) goto exit; /* do cleanup only after final close on this port */ - spin_lock_irqsave(&priv->dp_port_lock, flags); + spin_lock_irq(&priv->dp_port_lock); priv->dp_in_close = 1; - spin_unlock_irqrestore(&priv->dp_port_lock, flags); + spin_unlock_irq(&priv->dp_port_lock); /* tell line discipline to process only XON/XOFF */ tty->closing = 1; @@ -1482,11 +1482,12 @@ static void digi_close(struct usb_serial_port *port, struct file *filp) } tty->closing = 0; exit: - spin_lock_irqsave(&priv->dp_port_lock, flags); + spin_lock_irq(&priv->dp_port_lock); priv->dp_write_urb_in_use = 0; priv->dp_in_close = 0; wake_up_interruptible(&priv->dp_close_wait); - spin_unlock_irqrestore(&priv->dp_port_lock, flags); + spin_unlock_irq(&priv->dp_port_lock); + mutex_unlock(&port->serial->disc_mutex); dbg("digi_close: done"); } diff --git a/drivers/usb/serial/oti6858.c b/drivers/usb/serial/oti6858.c index db725aaf7d19..a3847d6c946e 100644 --- a/drivers/usb/serial/oti6858.c +++ b/drivers/usb/serial/oti6858.c @@ -649,7 +649,7 @@ static void oti6858_close(struct usb_serial_port *port, struct file *filp) set_current_state(TASK_INTERRUPTIBLE); if (oti6858_buf_data_avail(priv->buf) == 0 || timeout == 0 || signal_pending(current) - || !usb_get_intfdata(port->serial->interface)) /* disconnect */ + || port->serial->disconnected) break; spin_unlock_irqrestore(&priv->lock, flags); timeout = schedule_timeout(timeout); diff --git a/drivers/usb/serial/pl2303.c b/drivers/usb/serial/pl2303.c index ac3d8765f482..ae3ec1a64008 100644 --- a/drivers/usb/serial/pl2303.c +++ b/drivers/usb/serial/pl2303.c @@ -667,7 +667,7 @@ static void pl2303_close(struct usb_serial_port *port, struct file *filp) set_current_state(TASK_INTERRUPTIBLE); if (pl2303_buf_data_avail(priv->buf) == 0 || timeout == 0 || signal_pending(current) || - !usb_get_intfdata(port->serial->interface)) /* disconnect */ + port->serial->disconnected) break; spin_unlock_irqrestore(&priv->lock, flags); timeout = schedule_timeout(timeout); diff --git a/drivers/usb/serial/ti_usb_3410_5052.c b/drivers/usb/serial/ti_usb_3410_5052.c index 70f56c8aef99..b517f93352ec 100644 --- a/drivers/usb/serial/ti_usb_3410_5052.c +++ b/drivers/usb/serial/ti_usb_3410_5052.c @@ -1493,11 +1493,10 @@ static void ti_drain(struct ti_port *tport, unsigned long timeout, int flush) struct ti_device *tdev = tport->tp_tdev; struct usb_serial_port *port = tport->tp_port; wait_queue_t wait; - unsigned long flags; dbg("%s - port %d", __FUNCTION__, port->number); - spin_lock_irqsave(&tport->tp_lock, flags); + spin_lock_irq(&tport->tp_lock); /* wait for data to drain from the buffer */ tdev->td_urb_error = 0; @@ -1508,11 +1507,11 @@ static void ti_drain(struct ti_port *tport, unsigned long timeout, int flush) if (ti_buf_data_avail(tport->tp_write_buf) == 0 || timeout == 0 || signal_pending(current) || tdev->td_urb_error - || !usb_get_intfdata(port->serial->interface)) /* disconnect */ + || port->serial->disconnected) /* disconnect */ break; - spin_unlock_irqrestore(&tport->tp_lock, flags); + spin_unlock_irq(&tport->tp_lock); timeout = schedule_timeout(timeout); - spin_lock_irqsave(&tport->tp_lock, flags); + spin_lock_irq(&tport->tp_lock); } set_current_state(TASK_RUNNING); remove_wait_queue(&tport->tp_write_wait, &wait); @@ -1521,19 +1520,23 @@ static void ti_drain(struct ti_port *tport, unsigned long timeout, int flush) if (flush) ti_buf_clear(tport->tp_write_buf); - spin_unlock_irqrestore(&tport->tp_lock, flags); + spin_unlock_irq(&tport->tp_lock); + mutex_lock(&port->serial->disc_mutex); /* wait for data to drain from the device */ /* wait for empty tx register, plus 20 ms */ timeout += jiffies; tport->tp_lsr &= ~TI_LSR_TX_EMPTY; while ((long)(jiffies - timeout) < 0 && !signal_pending(current) && !(tport->tp_lsr&TI_LSR_TX_EMPTY) && !tdev->td_urb_error - && usb_get_intfdata(port->serial->interface)) { /* not disconnected */ + && !port->serial->disconnected) { if (ti_get_lsr(tport)) break; + mutex_unlock(&port->serial->disc_mutex); msleep_interruptible(20); + mutex_lock(&port->serial->disc_mutex); } + mutex_unlock(&port->serial->disc_mutex); } -- cgit v1.2.3 From b3476675320eda83cf061a686cdc80b76f2bfdc4 Mon Sep 17 00:00:00 2001 From: Magnus Damm Date: Wed, 23 Jan 2008 15:58:35 +0900 Subject: usb: dma bounce buffer support usb: dma bounce buffer support V4 This patch adds dma bounce buffer support to the usb core. These buffers can be enabled with the HCD_LOCAL_MEM flag, and they make sure that all data passed to the host controller is allocated using dma_alloc_coherent(). Signed-off-by: Magnus Damm Acked-by: Alan Stern Acked-by: David Brownell Signed-off-by: Greg Kroah-Hartman --- drivers/usb/core/buffer.c | 9 ++- drivers/usb/core/hcd.c | 176 ++++++++++++++++++++++++++++++++++++++++------ drivers/usb/core/hcd.h | 1 + 3 files changed, 163 insertions(+), 23 deletions(-) diff --git a/drivers/usb/core/buffer.c b/drivers/usb/core/buffer.c index 28d4972f7ad5..acd9f00a0b76 100644 --- a/drivers/usb/core/buffer.c +++ b/drivers/usb/core/buffer.c @@ -53,7 +53,8 @@ int hcd_buffer_create(struct usb_hcd *hcd) char name[16]; int i, size; - if (!hcd->self.controller->dma_mask) + if (!hcd->self.controller->dma_mask && + !(hcd->driver->flags & HCD_LOCAL_MEM)) return 0; for (i = 0; i < HCD_BUFFER_POOLS; i++) { @@ -107,7 +108,8 @@ void *hcd_buffer_alloc( int i; /* some USB hosts just use PIO */ - if (!bus->controller->dma_mask) { + if (!bus->controller->dma_mask && + !(hcd->driver->flags & HCD_LOCAL_MEM)) { *dma = ~(dma_addr_t) 0; return kmalloc(size, mem_flags); } @@ -132,7 +134,8 @@ void hcd_buffer_free( if (!addr) return; - if (!bus->controller->dma_mask) { + if (!bus->controller->dma_mask && + !(hcd->driver->flags & HCD_LOCAL_MEM)) { kfree(addr); return; } diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c index 372372116bb0..febd6b40da3b 100644 --- a/drivers/usb/core/hcd.c +++ b/drivers/usb/core/hcd.c @@ -35,6 +35,7 @@ #include #include #include +#include #include #include @@ -1112,48 +1113,177 @@ void usb_hcd_unlink_urb_from_ep(struct usb_hcd *hcd, struct urb *urb) } EXPORT_SYMBOL_GPL(usb_hcd_unlink_urb_from_ep); -static void map_urb_for_dma(struct usb_hcd *hcd, struct urb *urb) +/* + * Some usb host controllers can only perform dma using a small SRAM area. + * The usb core itself is however optimized for host controllers that can dma + * using regular system memory - like pci devices doing bus mastering. + * + * To support host controllers with limited dma capabilites we provide dma + * bounce buffers. This feature can be enabled using the HCD_LOCAL_MEM flag. + * For this to work properly the host controller code must first use the + * function dma_declare_coherent_memory() to point out which memory area + * that should be used for dma allocations. + * + * The HCD_LOCAL_MEM flag then tells the usb code to allocate all data for + * dma using dma_alloc_coherent() which in turn allocates from the memory + * area pointed out with dma_declare_coherent_memory(). + * + * So, to summarize... + * + * - We need "local" memory, canonical example being + * a small SRAM on a discrete controller being the + * only memory that the controller can read ... + * (a) "normal" kernel memory is no good, and + * (b) there's not enough to share + * + * - The only *portable* hook for such stuff in the + * DMA framework is dma_declare_coherent_memory() + * + * - So we use that, even though the primary requirement + * is that the memory be "local" (hence addressible + * by that device), not "coherent". + * + */ + +static int hcd_alloc_coherent(struct usb_bus *bus, + gfp_t mem_flags, dma_addr_t *dma_handle, + void **vaddr_handle, size_t size, + enum dma_data_direction dir) +{ + unsigned char *vaddr; + + vaddr = hcd_buffer_alloc(bus, size + sizeof(vaddr), + mem_flags, dma_handle); + if (!vaddr) + return -ENOMEM; + + /* + * Store the virtual address of the buffer at the end + * of the allocated dma buffer. The size of the buffer + * may be uneven so use unaligned functions instead + * of just rounding up. It makes sense to optimize for + * memory footprint over access speed since the amount + * of memory available for dma may be limited. + */ + put_unaligned((unsigned long)*vaddr_handle, + (unsigned long *)(vaddr + size)); + + if (dir == DMA_TO_DEVICE) + memcpy(vaddr, *vaddr_handle, size); + + *vaddr_handle = vaddr; + return 0; +} + +static void hcd_free_coherent(struct usb_bus *bus, dma_addr_t *dma_handle, + void **vaddr_handle, size_t size, + enum dma_data_direction dir) +{ + unsigned char *vaddr = *vaddr_handle; + + vaddr = (void *)get_unaligned((unsigned long *)(vaddr + size)); + + if (dir == DMA_FROM_DEVICE) + memcpy(vaddr, *vaddr_handle, size); + + hcd_buffer_free(bus, size + sizeof(vaddr), *vaddr_handle, *dma_handle); + + *vaddr_handle = vaddr; + *dma_handle = 0; +} + +static int map_urb_for_dma(struct usb_hcd *hcd, struct urb *urb, + gfp_t mem_flags) { + enum dma_data_direction dir; + int ret = 0; + /* Map the URB's buffers for DMA access. * Lower level HCD code should use *_dma exclusively, * unless it uses pio or talks to another transport. */ - if (hcd->self.uses_dma && !is_root_hub(urb->dev)) { - if (usb_endpoint_xfer_control(&urb->ep->desc) - && !(urb->transfer_flags & URB_NO_SETUP_DMA_MAP)) - urb->setup_dma = dma_map_single ( + if (is_root_hub(urb->dev)) + return 0; + + if (usb_endpoint_xfer_control(&urb->ep->desc) + && !(urb->transfer_flags & URB_NO_SETUP_DMA_MAP)) { + if (hcd->self.uses_dma) + urb->setup_dma = dma_map_single( hcd->self.controller, urb->setup_packet, - sizeof (struct usb_ctrlrequest), + sizeof(struct usb_ctrlrequest), DMA_TO_DEVICE); - if (urb->transfer_buffer_length != 0 - && !(urb->transfer_flags & URB_NO_TRANSFER_DMA_MAP)) + else if (hcd->driver->flags & HCD_LOCAL_MEM) + ret = hcd_alloc_coherent( + urb->dev->bus, mem_flags, + &urb->setup_dma, + (void **)&urb->setup_packet, + sizeof(struct usb_ctrlrequest), + DMA_TO_DEVICE); + } + + dir = usb_urb_dir_in(urb) ? DMA_FROM_DEVICE : DMA_TO_DEVICE; + if (ret == 0 && urb->transfer_buffer_length != 0 + && !(urb->transfer_flags & URB_NO_TRANSFER_DMA_MAP)) { + if (hcd->self.uses_dma) urb->transfer_dma = dma_map_single ( hcd->self.controller, urb->transfer_buffer, urb->transfer_buffer_length, - usb_urb_dir_in(urb) - ? DMA_FROM_DEVICE - : DMA_TO_DEVICE); + dir); + else if (hcd->driver->flags & HCD_LOCAL_MEM) { + ret = hcd_alloc_coherent( + urb->dev->bus, mem_flags, + &urb->transfer_dma, + &urb->transfer_buffer, + urb->transfer_buffer_length, + dir); + + if (ret && usb_endpoint_xfer_control(&urb->ep->desc) + && !(urb->transfer_flags & URB_NO_SETUP_DMA_MAP)) + hcd_free_coherent(urb->dev->bus, + &urb->setup_dma, + (void **)&urb->setup_packet, + sizeof(struct usb_ctrlrequest), + DMA_TO_DEVICE); + } } + return ret; } static void unmap_urb_for_dma(struct usb_hcd *hcd, struct urb *urb) { - if (hcd->self.uses_dma && !is_root_hub(urb->dev)) { - if (usb_endpoint_xfer_control(&urb->ep->desc) - && !(urb->transfer_flags & URB_NO_SETUP_DMA_MAP)) + enum dma_data_direction dir; + + if (is_root_hub(urb->dev)) + return; + + if (usb_endpoint_xfer_control(&urb->ep->desc) + && !(urb->transfer_flags & URB_NO_SETUP_DMA_MAP)) { + if (hcd->self.uses_dma) dma_unmap_single(hcd->self.controller, urb->setup_dma, sizeof(struct usb_ctrlrequest), DMA_TO_DEVICE); - if (urb->transfer_buffer_length != 0 - && !(urb->transfer_flags & URB_NO_TRANSFER_DMA_MAP)) + else if (hcd->driver->flags & HCD_LOCAL_MEM) + hcd_free_coherent(urb->dev->bus, &urb->setup_dma, + (void **)&urb->setup_packet, + sizeof(struct usb_ctrlrequest), + DMA_TO_DEVICE); + } + + dir = usb_urb_dir_in(urb) ? DMA_FROM_DEVICE : DMA_TO_DEVICE; + if (urb->transfer_buffer_length != 0 + && !(urb->transfer_flags & URB_NO_TRANSFER_DMA_MAP)) { + if (hcd->self.uses_dma) dma_unmap_single(hcd->self.controller, urb->transfer_dma, urb->transfer_buffer_length, - usb_urb_dir_in(urb) - ? DMA_FROM_DEVICE - : DMA_TO_DEVICE); + dir); + else if (hcd->driver->flags & HCD_LOCAL_MEM) + hcd_free_coherent(urb->dev->bus, &urb->transfer_dma, + &urb->transfer_buffer, + urb->transfer_buffer_length, + dir); } } @@ -1185,7 +1315,12 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags) * URBs must be submitted in process context with interrupts * enabled. */ - map_urb_for_dma(hcd, urb); + status = map_urb_for_dma(hcd, urb, mem_flags); + if (unlikely(status)) { + usbmon_urb_submit_error(&hcd->self, urb, status); + goto error; + } + if (is_root_hub(urb->dev)) status = rh_urb_enqueue(hcd, urb); else @@ -1194,6 +1329,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags) if (unlikely(status)) { usbmon_urb_submit_error(&hcd->self, urb, status); unmap_urb_for_dma(hcd, urb); + error: urb->hcpriv = NULL; INIT_LIST_HEAD(&urb->urb_list); atomic_dec(&urb->use_count); diff --git a/drivers/usb/core/hcd.h b/drivers/usb/core/hcd.h index 080298ad5990..0095641c51fa 100644 --- a/drivers/usb/core/hcd.h +++ b/drivers/usb/core/hcd.h @@ -165,6 +165,7 @@ struct hc_driver { int flags; #define HCD_MEMORY 0x0001 /* HC regs use memory (else I/O) */ +#define HCD_LOCAL_MEM 0x0002 /* HC needs local memory */ #define HCD_USB11 0x0010 /* USB 1.1 */ #define HCD_USB2 0x0020 /* USB 2.0 */ -- cgit v1.2.3 From f54aab6ebcecd93e86cea34ddba5f3d454382041 Mon Sep 17 00:00:00 2001 From: Magnus Damm Date: Wed, 23 Jan 2008 15:58:46 +0900 Subject: usb: ohci-sm501 driver usb: ohci-sm501 driver V2 This patch adds sm501 ohci support. It's all very straightforward with the exception of dma_declare_coherent_memory() and HCD_LOCAL_MEM. Together they are used to ensure that usb data is allocated using dma_alloc_coherent(), and that only valid dma memory is used to allocate from. This driver is a platform device, and the mfd driver sm501.c is already creating one usb host controller instance per sm501. Signed-off-by: Magnus Damm Cc: David Brownell Signed-off-by: Greg Kroah-Hartman --- drivers/usb/host/ohci-hcd.c | 5 + drivers/usb/host/ohci-sm501.c | 264 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 269 insertions(+) create mode 100644 drivers/usb/host/ohci-sm501.c diff --git a/drivers/usb/host/ohci-hcd.c b/drivers/usb/host/ohci-hcd.c index b8ed84d5406d..dd4798ee028e 100644 --- a/drivers/usb/host/ohci-hcd.c +++ b/drivers/usb/host/ohci-hcd.c @@ -1052,6 +1052,11 @@ MODULE_LICENSE ("GPL"); #define SSB_OHCI_DRIVER ssb_ohci_driver #endif +#ifdef CONFIG_MFD_SM501 +#include "ohci-sm501.c" +#define PLATFORM_DRIVER ohci_hcd_sm501_driver +#endif + #if !defined(PCI_DRIVER) && \ !defined(PLATFORM_DRIVER) && \ !defined(OF_PLATFORM_DRIVER) && \ 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 @@ +/* + * OHCI HCD (Host Controller Driver) for USB. + * + * (C) Copyright 1999 Roman Weissgaerber + * (C) Copyright 2000-2005 David Brownell + * (C) Copyright 2002 Hewlett-Packard Company + * (C) Copyright 2008 Magnus Damm + * + * SM501 Bus Glue - based on ohci-omap.c + * + * This file is licenced under the GPL. + */ + +#include +#include +#include +#include +#include +#include + +static int ohci_sm501_init(struct usb_hcd *hcd) +{ + return ohci_init(hcd_to_ohci(hcd)); +} + +static int ohci_sm501_start(struct usb_hcd *hcd) +{ + struct device *dev = hcd->self.controller; + int ret; + + ret = ohci_run(hcd_to_ohci(hcd)); + if (ret < 0) { + dev_err(dev, "can't start %s", hcd->self.bus_name); + ohci_stop(hcd); + } + + return ret; +} + +/*-------------------------------------------------------------------------*/ + +static const struct hc_driver ohci_sm501_hc_driver = { + .description = hcd_name, + .product_desc = "SM501 OHCI", + .hcd_priv_size = sizeof(struct ohci_hcd), + + /* + * generic hardware linkage + */ + .irq = ohci_irq, + .flags = HCD_USB11 | HCD_MEMORY | HCD_LOCAL_MEM, + + /* + * basic lifecycle operations + */ + .reset = ohci_sm501_init, + .start = ohci_sm501_start, + .stop = ohci_stop, + .shutdown = ohci_shutdown, + + /* + * managing i/o requests and associated device resources + */ + .urb_enqueue = ohci_urb_enqueue, + .urb_dequeue = ohci_urb_dequeue, + .endpoint_disable = ohci_endpoint_disable, + + /* + * scheduling support + */ + .get_frame_number = ohci_get_frame, + + /* + * root hub support + */ + .hub_status_data = ohci_hub_status_data, + .hub_control = ohci_hub_control, + .hub_irq_enable = ohci_rhsc_enable, +#ifdef CONFIG_PM + .bus_suspend = ohci_bus_suspend, + .bus_resume = ohci_bus_resume, +#endif + .start_port_reset = ohci_start_port_reset, +}; + +/*-------------------------------------------------------------------------*/ + +static int ohci_hcd_sm501_drv_probe(struct platform_device *pdev) +{ + const struct hc_driver *driver = &ohci_sm501_hc_driver; + struct device *dev = &pdev->dev; + struct resource *res, *mem; + int retval, irq; + struct usb_hcd *hcd = 0; + + irq = retval = platform_get_irq(pdev, 0); + if (retval < 0) + goto err0; + + mem = platform_get_resource(pdev, IORESOURCE_MEM, 1); + if (mem == NULL) { + dev_err(dev, "no resource definition for memory\n"); + retval = -ENOENT; + goto err0; + } + + if (!request_mem_region(mem->start, mem->end - mem->start + 1, + pdev->name)) { + dev_err(dev, "request_mem_region failed\n"); + retval = -EBUSY; + goto err0; + } + + /* The sm501 chip is equipped with local memory that may be used + * by on-chip devices such as the video controller and the usb host. + * This driver uses dma_declare_coherent_memory() to make sure + * usb allocations with dma_alloc_coherent() allocate from + * this local memory. The dma_handle returned by dma_alloc_coherent() + * will be an offset starting from 0 for the first local memory byte. + * + * So as long as data is allocated using dma_alloc_coherent() all is + * fine. This is however not always the case - buffers may be allocated + * using kmalloc() - so the usb core needs to be told that it must copy + * data into our local memory if the buffers happen to be placed in + * regular memory. The HCD_LOCAL_MEM flag does just that. + */ + + if (!dma_declare_coherent_memory(dev, mem->start, + mem->start - mem->parent->start, + (mem->end - mem->start) + 1, + DMA_MEMORY_MAP | + DMA_MEMORY_EXCLUSIVE)) { + dev_err(dev, "cannot declare coherent memory\n"); + retval = -ENXIO; + goto err1; + } + + /* allocate, reserve and remap resources for registers */ + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); + if (res == NULL) { + dev_err(dev, "no resource definition for registers\n"); + retval = -ENOENT; + goto err2; + } + + hcd = usb_create_hcd(driver, &pdev->dev, pdev->dev.bus_id); + if (!hcd) { + retval = -ENOMEM; + goto err2; + } + + hcd->rsrc_start = res->start; + hcd->rsrc_len = res->end - res->start + 1; + + if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, pdev->name)) { + dev_err(dev, "request_mem_region failed\n"); + retval = -EBUSY; + goto err3; + } + + hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len); + if (hcd->regs == NULL) { + dev_err(dev, "cannot remap registers\n"); + retval = -ENXIO; + goto err4; + } + + ohci_hcd_init(hcd_to_ohci(hcd)); + + retval = usb_add_hcd(hcd, irq, IRQF_DISABLED | IRQF_SHARED); + if (retval) + goto err4; + + /* enable power and unmask interrupts */ + + sm501_unit_power(dev->parent, SM501_GATE_USB_HOST, 1); + sm501_modify_reg(dev->parent, SM501_IRQ_MASK, 1 << 6, 0); + + return 0; +err4: + release_mem_region(hcd->rsrc_start, hcd->rsrc_len); +err3: + usb_put_hcd(hcd); +err2: + dma_release_declared_memory(dev); +err1: + release_mem_region(mem->start, mem->end - mem->start + 1); +err0: + return retval; +} + +static int ohci_hcd_sm501_drv_remove(struct platform_device *pdev) +{ + struct usb_hcd *hcd = platform_get_drvdata(pdev); + struct resource *mem; + + usb_remove_hcd(hcd); + release_mem_region(hcd->rsrc_start, hcd->rsrc_len); + usb_put_hcd(hcd); + dma_release_declared_memory(&pdev->dev); + mem = platform_get_resource(pdev, IORESOURCE_MEM, 1); + release_mem_region(mem->start, mem->end - mem->start + 1); + + /* mask interrupts and disable power */ + + sm501_modify_reg(pdev->dev.parent, SM501_IRQ_MASK, 0, 1 << 6); + sm501_unit_power(pdev->dev.parent, SM501_GATE_USB_HOST, 0); + + platform_set_drvdata(pdev, NULL); + return 0; +} + +/*-------------------------------------------------------------------------*/ + +#ifdef CONFIG_PM +static int ohci_sm501_suspend(struct platform_device *pdev, pm_message_t msg) +{ + struct device *dev = &pdev->dev; + struct ohci_hcd *ohci = hcd_to_ohci(platform_get_drvdata(pdev)); + + if (time_before(jiffies, ohci->next_statechange)) + msleep(5); + ohci->next_statechange = jiffies; + + sm501_unit_power(dev->parent, SM501_GATE_USB_HOST, 0); + ohci_to_hcd(ohci)->state = HC_STATE_SUSPENDED; + dev->power.power_state = PMSG_SUSPEND; + return 0; +} + +static int ohci_sm501_resume(struct platform_device *pdev) +{ + struct device *dev = &pdev->dev; + struct ohci_hcd *ohci = hcd_to_ohci(platform_get_drvdata(pdev)); + + if (time_before(jiffies, ohci->next_statechange)) + msleep(5); + ohci->next_statechange = jiffies; + + sm501_unit_power(dev->parent, SM501_GATE_USB_HOST, 1); + dev->power.power_state = PMSG_ON; + usb_hcd_resume_root_hub(platform_get_drvdata(pdev)); + return 0; +} +#endif + +/*-------------------------------------------------------------------------*/ + +/* + * Driver definition to register with the SM501 bus + */ +static struct platform_driver ohci_hcd_sm501_driver = { + .probe = ohci_hcd_sm501_drv_probe, + .remove = ohci_hcd_sm501_drv_remove, + .shutdown = usb_hcd_platform_shutdown, +#ifdef CONFIG_PM + .suspend = ohci_sm501_suspend, + .resume = ohci_sm501_resume, +#endif + .driver = { + .owner = THIS_MODULE, + .name = "sm501-usb", + }, +}; -- cgit v1.2.3 From b75be4abf18e9725766ed835f0d2cf201b52de7e Mon Sep 17 00:00:00 2001 From: Denis Cheng Date: Thu, 24 Jan 2008 16:36:31 +0800 Subject: USB: Use menuconfig objects commit 04d06ad0f1fdb499af84ae3d7969e2136a462f38 have added menuconfig support for the whole USB Kconfig, but there are still menuconfig need for usb/serial, usb/atm, and usb/gadget, so that the user can disable all the options in that menu at once instead of having to disable each option separately. Signed-off-by: Denis Cheng Signed-off-by: Greg Kroah-Hartman --- drivers/usb/atm/Kconfig | 9 ++++----- drivers/usb/gadget/Kconfig | 9 +++++---- drivers/usb/serial/Kconfig | 11 ++++------- 3 files changed, 13 insertions(+), 16 deletions(-) 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 @@ # USB/ATM DSL configuration # -menu "USB DSL modem support" - depends on USB - -config USB_ATM +menuconfig USB_ATM tristate "USB DSL modem support" depends on USB && ATM select CRC32 @@ -18,6 +15,8 @@ config USB_ATM To compile this driver as a module, choose M here: the module will be called usbatm. +if USB_ATM + config USB_SPEEDTOUCH tristate "Speedtouch USB support" depends on USB_ATM @@ -70,4 +69,4 @@ config USB_XUSBATM To compile this driver as a module, choose M here: the module will be called xusbatm. -endmenu +endif # USB_ATM diff --git a/drivers/usb/gadget/Kconfig b/drivers/usb/gadget/Kconfig index 8a88f24270be..c13955164686 100644 --- a/drivers/usb/gadget/Kconfig +++ b/drivers/usb/gadget/Kconfig @@ -12,10 +12,9 @@ # With help from a special transceiver and a "Mini-AB" jack, systems with # both kinds of controller can also support "USB On-the-Go" (CONFIG_USB_OTG). # -menu "USB Gadget Support" -config USB_GADGET - tristate "Support for USB Gadgets" +menuconfig USB_GADGET + tristate "USB Gadget Support" help USB is a master/slave protocol, organized with one master host (such as a PC) controlling up to 127 peripheral devices. @@ -42,6 +41,8 @@ config USB_GADGET For more information, see and the kernel DocBook documentation for this API. +if USB_GADGET + config USB_GADGET_DEBUG boolean "Debugging messages" depends on USB_GADGET && DEBUG_KERNEL && EXPERIMENTAL @@ -570,4 +571,4 @@ config USB_G_PRINTER endchoice -endmenu +endif # USB_GADGET diff --git a/drivers/usb/serial/Kconfig b/drivers/usb/serial/Kconfig index 5df5d0fe258a..c1e65dfd9353 100644 --- a/drivers/usb/serial/Kconfig +++ b/drivers/usb/serial/Kconfig @@ -2,10 +2,7 @@ # USB Serial device configuration # -menu "USB Serial Converter support" - depends on USB!=n - -config USB_SERIAL +menuconfig USB_SERIAL tristate "USB Serial Converter support" depends on USB ---help--- @@ -20,6 +17,8 @@ config USB_SERIAL To compile this driver as a module, choose M here: the module will be called usbserial. +if USB_SERIAL + config USB_SERIAL_CONSOLE bool "USB Serial Console device support (EXPERIMENTAL)" depends on USB_SERIAL=y && EXPERIMENTAL @@ -606,6 +605,4 @@ config USB_SERIAL_DEBUG To compile this driver as a module, choose M here: the module will be called usb-debug. - -endmenu - +endif # USB_SERIAL -- cgit v1.2.3 From cd4cdc93ce04b562412df6c0cf25c564ab2522ac Mon Sep 17 00:00:00 2001 From: David Brownell Date: Thu, 24 Jan 2008 12:39:43 -0800 Subject: usb: ehci, remove false clear-reset path Some of the "EHCI ports reset forever" problems may be explained by code paths which wrongly flagged resets as complete. This removes two such paths; the ehci_hub_status_data() path should be the only one to have an effect, since it was already properly flagged on the other path. (Issue noted by Minhyoung Kim .) Signed-off-by: David Brownell Signed-off-by: Greg Kroah-Hartman --- drivers/usb/host/ehci-hub.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/drivers/usb/host/ehci-hub.c b/drivers/usb/host/ehci-hub.c index ccd88ae011c6..40e8240b7851 100644 --- a/drivers/usb/host/ehci-hub.c +++ b/drivers/usb/host/ehci-hub.c @@ -411,10 +411,8 @@ static int check_reset_complete ( u32 __iomem *status_reg, int port_status ) { - if (!(port_status & PORT_CONNECT)) { - ehci->reset_done [index] = 0; + if (!(port_status & PORT_CONNECT)) return port_status; - } /* if reset finished and it's still not enabled -- handoff */ if (!(port_status & PORT_PE)) { @@ -493,8 +491,6 @@ ehci_hub_status_data (struct usb_hcd *hcd, char *buf) * controller by the user. */ - if (!(temp & PORT_CONNECT)) - ehci->reset_done [i] = 0; if ((temp & mask) != 0 || ((temp & PORT_RESUME) != 0 && time_after_eq(jiffies, -- cgit v1.2.3 From c06d4dcf5034ee2289a921b9b2c547f3fed2d878 Mon Sep 17 00:00:00 2001 From: David Brownell Date: Thu, 24 Jan 2008 12:30:34 -0800 Subject: usb: ehci should use u16 for isochronous intervals While most isochronous endpoints have short polling intervals, the EHCI driver won't necessarily handle larger ones correctly. This patch switches to use a "u16" to represent those periods, not a u8, since it can always work: the largest expressible period is 2^15 units ... not the previous too-short limit of 128 frames (full or low speeds) or microframes (high speed, 32 frames). This bug is essentially theoretical, since the few ISO endpoints I've seen which don't use one transfer per frame are high speed ones using more than that (including high bandwidth, 24 KB/msec). Signed-off-by: David Brownell Signed-off-by: Greg Kroah-Hartman --- drivers/usb/host/ehci.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/usb/host/ehci.h b/drivers/usb/host/ehci.h index 42969e9d8c44..bf92d209a1a9 100644 --- a/drivers/usb/host/ehci.h +++ b/drivers/usb/host/ehci.h @@ -550,8 +550,8 @@ struct ehci_iso_stream { * trusting urb->interval == f(epdesc->bInterval) and * including the extra info for hw_bufp[0..2] */ - u8 interval; u8 usecs, c_usecs; + u16 interval; u16 tt_usecs; u16 maxp; u16 raw_mask; -- cgit v1.2.3 From 8dd70705c4a7a3110076da412333c90d773bbb63 Mon Sep 17 00:00:00 2001 From: Stefan Bader Date: Fri, 25 Jan 2008 08:09:41 -0500 Subject: USB: Fix usb_serial_driver structure for Kobil cardreader driver. The device setup did miss to initialize the num_interrupt_out field, thus failing to successfully complete the probe function. Signed-off-by: Stefan Bader Cc: stable Cc: Alan Cox Signed-off-by: Greg Kroah-Hartman --- drivers/usb/serial/kobil_sct.c | 1 + 1 file changed, 1 insertion(+) 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 = { .usb_driver = &kobil_driver, .id_table = id_table, .num_interrupt_in = NUM_DONT_CARE, + .num_interrupt_out = NUM_DONT_CARE, .num_bulk_in = 0, .num_bulk_out = 0, .num_ports = 1, -- cgit v1.2.3 From 2e4f3c02239d4c7c454604715db619bc971b15eb Mon Sep 17 00:00:00 2001 From: Miklos Szeredi Date: Thu, 24 Jan 2008 20:34:07 +0100 Subject: USB: mount options: fix usbfs Add a .show_options super operation to usbfs. Signed-off-by: Miklos Szeredi Signed-off-by: Greg Kroah-Hartman --- drivers/usb/core/inode.c | 42 ++++++++++++++++++++++++++++++++++++------ 1 file changed, 36 insertions(+), 6 deletions(-) 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 @@ #include #include #include +#include #include #include "usb.h" #include "hcd.h" +#define USBFS_DEFAULT_DEVMODE (S_IWUSR | S_IRUGO) +#define USBFS_DEFAULT_BUSMODE (S_IXUGO | S_IRUGO) +#define USBFS_DEFAULT_LISTMODE S_IRUGO + static struct super_operations usbfs_ops; static const struct file_operations default_file_operations; static struct vfsmount *usbfs_mount; @@ -57,9 +62,33 @@ static uid_t listuid; /* = 0 */ static gid_t devgid; /* = 0 */ static gid_t busgid; /* = 0 */ static gid_t listgid; /* = 0 */ -static umode_t devmode = S_IWUSR | S_IRUGO; -static umode_t busmode = S_IXUGO | S_IRUGO; -static umode_t listmode = S_IRUGO; +static umode_t devmode = USBFS_DEFAULT_DEVMODE; +static umode_t busmode = USBFS_DEFAULT_BUSMODE; +static umode_t listmode = USBFS_DEFAULT_LISTMODE; + +static int usbfs_show_options(struct seq_file *seq, struct vfsmount *mnt) +{ + if (devuid != 0) + seq_printf(seq, ",devuid=%u", devuid); + if (devgid != 0) + seq_printf(seq, ",devgid=%u", devgid); + if (devmode != USBFS_DEFAULT_DEVMODE) + seq_printf(seq, ",devmode=%o", devmode); + if (busuid != 0) + seq_printf(seq, ",busuid=%u", busuid); + if (busgid != 0) + seq_printf(seq, ",busgid=%u", busgid); + if (busmode != USBFS_DEFAULT_BUSMODE) + seq_printf(seq, ",busmode=%o", busmode); + if (listuid != 0) + seq_printf(seq, ",listuid=%u", listuid); + if (listgid != 0) + seq_printf(seq, ",listgid=%u", listgid); + if (listmode != USBFS_DEFAULT_LISTMODE) + seq_printf(seq, ",listmode=%o", listmode); + + return 0; +} enum { Opt_devuid, Opt_devgid, Opt_devmode, @@ -93,9 +122,9 @@ static int parse_options(struct super_block *s, char *data) devgid = 0; busgid = 0; listgid = 0; - devmode = S_IWUSR | S_IRUGO; - busmode = S_IXUGO | S_IRUGO; - listmode = S_IRUGO; + devmode = USBFS_DEFAULT_DEVMODE; + busmode = USBFS_DEFAULT_BUSMODE; + listmode = USBFS_DEFAULT_LISTMODE; while ((p = strsep(&data, ",")) != NULL) { substring_t args[MAX_OPT_ARGS]; @@ -418,6 +447,7 @@ static struct super_operations usbfs_ops = { .statfs = simple_statfs, .drop_inode = generic_delete_inode, .remount_fs = remount, + .show_options = usbfs_show_options, }; static int usbfs_fill_super(struct super_block *sb, void *data, int silent) -- cgit v1.2.3 From 667d691ed7a70c9a9fde5b6bd663a5f38326e026 Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Mon, 28 Jan 2008 09:50:12 -0800 Subject: USB: use a real vendor and product id for root hubs Turns out that a company is out there using the vendor id of 0x0000 in the wild, so use a real vendor/product id for the root hubs. Now that the Linux Foundation has a real vendor id, we use that, and the first product id: 0x1d6b is the vendor id of the Linux Foundation 0x0001 is the product id for Linux 1.1 root hubs 0x0002 is the product id for Linux 2.0 root hubs The usb.ids file has already been updated with these values. Signed-off-by: Greg Kroah-Hartman --- drivers/usb/core/hcd.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c index febd6b40da3b..a1906908d3b1 100644 --- a/drivers/usb/core/hcd.c +++ b/drivers/usb/core/hcd.c @@ -132,8 +132,8 @@ static const u8 usb2_rh_dev_descriptor [18] = { 0x01, /* __u8 bDeviceProtocol; [ usb 2.0 single TT ]*/ 0x40, /* __u8 bMaxPacketSize0; 64 Bytes */ - 0x00, 0x00, /* __le16 idVendor; */ - 0x00, 0x00, /* __le16 idProduct; */ + 0x6b, 0x1d, /* __le16 idVendor; Linux Foundation */ + 0x02, 0x00, /* __le16 idProduct; device 0x0002 */ KERNEL_VER, KERNEL_REL, /* __le16 bcdDevice */ 0x03, /* __u8 iManufacturer; */ @@ -155,8 +155,8 @@ static const u8 usb11_rh_dev_descriptor [18] = { 0x00, /* __u8 bDeviceProtocol; [ low/full speeds only ] */ 0x40, /* __u8 bMaxPacketSize0; 64 Bytes */ - 0x00, 0x00, /* __le16 idVendor; */ - 0x00, 0x00, /* __le16 idProduct; */ + 0x6b, 0x1d, /* __le16 idVendor; Linux Foundation */ + 0x01, 0x00, /* __le16 idProduct; device 0x0001 */ KERNEL_VER, KERNEL_REL, /* __le16 bcdDevice */ 0x03, /* __u8 iManufacturer; */ -- cgit v1.2.3 From 782e70c6fc2290a0395850e8e02583b8b62264d8 Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Fri, 25 Jan 2008 11:12:21 -0600 Subject: USB: mark USB drivers as being GPL only Over two years ago, the Linux USB developers stated that they believed there was no way to create a USB kernel driver that was not under the GPL. This patch moves the USB apis to enforce that decision. There are no known closed source USB drivers in the wild, so this patch should cause no problems. Signed-off-by: Greg Kroah-Hartman --- Documentation/feature-removal-schedule.txt | 16 -------- drivers/usb/core/driver.c | 10 ++--- drivers/usb/core/file.c | 4 +- drivers/usb/core/hcd-pci.c | 10 ++--- drivers/usb/core/hcd.c | 18 ++++----- drivers/usb/core/hub.c | 5 ++- drivers/usb/core/message.c | 32 ++++++--------- drivers/usb/core/urb.c | 15 ++++---- drivers/usb/core/usb.c | 62 +++++++++--------------------- 9 files changed, 61 insertions(+), 111 deletions(-) diff --git a/Documentation/feature-removal-schedule.txt b/Documentation/feature-removal-schedule.txt index 181bff005167..a7d9d179131a 100644 --- a/Documentation/feature-removal-schedule.txt +++ b/Documentation/feature-removal-schedule.txt @@ -156,22 +156,6 @@ Who: Arjan van de Ven --------------------------- -What: USB driver API moves to EXPORT_SYMBOL_GPL -When: February 2008 -Files: include/linux/usb.h, drivers/usb/core/driver.c -Why: The USB subsystem has changed a lot over time, and it has been - possible to create userspace USB drivers using usbfs/libusb/gadgetfs - that operate as fast as the USB bus allows. Because of this, the USB - subsystem will not be allowing closed source kernel drivers to - register with it, after this grace period is over. If anyone needs - any help in converting their closed source drivers over to use the - userspace filesystems, please contact the - linux-usb-devel@lists.sourceforge.net mailing list, and the developers - there will be glad to help you out. -Who: Greg Kroah-Hartman - ---------------------------- - What: vm_ops.nopage When: Soon, provided in-kernel callers have been converted Why: This interface is replaced by vm_ops.fault, but it has been around diff --git a/drivers/usb/core/driver.c b/drivers/usb/core/driver.c index 96d3f852f4ad..7e7f2c42494c 100644 --- a/drivers/usb/core/driver.c +++ b/drivers/usb/core/driver.c @@ -325,7 +325,7 @@ int usb_driver_claim_interface(struct usb_driver *driver, return retval; } -EXPORT_SYMBOL(usb_driver_claim_interface); +EXPORT_SYMBOL_GPL(usb_driver_claim_interface); /** * usb_driver_release_interface - unbind a driver from an interface @@ -370,7 +370,7 @@ void usb_driver_release_interface(struct usb_driver *driver, iface->needs_remote_wakeup = 0; usb_pm_unlock(udev); } -EXPORT_SYMBOL(usb_driver_release_interface); +EXPORT_SYMBOL_GPL(usb_driver_release_interface); /* returns 0 if no match, 1 if match */ int usb_match_device(struct usb_device *dev, const struct usb_device_id *id) @@ -542,7 +542,7 @@ const struct usb_device_id *usb_match_id(struct usb_interface *interface, return NULL; } -EXPORT_SYMBOL_GPL_FUTURE(usb_match_id); +EXPORT_SYMBOL_GPL(usb_match_id); static int usb_device_match(struct device *dev, struct device_driver *drv) { @@ -745,7 +745,7 @@ int usb_register_driver(struct usb_driver *new_driver, struct module *owner, return retval; } -EXPORT_SYMBOL_GPL_FUTURE(usb_register_driver); +EXPORT_SYMBOL_GPL(usb_register_driver); /** * usb_deregister - unregister a USB interface driver @@ -769,7 +769,7 @@ void usb_deregister(struct usb_driver *driver) usbfs_update_special(); } -EXPORT_SYMBOL_GPL_FUTURE(usb_deregister); +EXPORT_SYMBOL_GPL(usb_deregister); #ifdef CONFIG_PM 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, exit: return retval; } -EXPORT_SYMBOL(usb_register_dev); +EXPORT_SYMBOL_GPL(usb_register_dev); /** * usb_deregister_dev - deregister a USB device's dynamic minor. @@ -245,4 +245,4 @@ void usb_deregister_dev(struct usb_interface *intf, intf->minor = -1; destroy_usb_class(); } -EXPORT_SYMBOL(usb_deregister_dev); +EXPORT_SYMBOL_GPL(usb_deregister_dev); diff --git a/drivers/usb/core/hcd-pci.c b/drivers/usb/core/hcd-pci.c index 424674203fd3..851d5e1625d9 100644 --- a/drivers/usb/core/hcd-pci.c +++ b/drivers/usb/core/hcd-pci.c @@ -144,7 +144,7 @@ int usb_hcd_pci_probe (struct pci_dev *dev, const struct pci_device_id *id) dev_err (&dev->dev, "init %s fail, %d\n", pci_name(dev), retval); return retval; } -EXPORT_SYMBOL (usb_hcd_pci_probe); +EXPORT_SYMBOL_GPL(usb_hcd_pci_probe); /* may be called without controller electrically present */ @@ -179,7 +179,7 @@ void usb_hcd_pci_remove (struct pci_dev *dev) usb_put_hcd (hcd); pci_disable_device(dev); } -EXPORT_SYMBOL (usb_hcd_pci_remove); +EXPORT_SYMBOL_GPL(usb_hcd_pci_remove); #ifdef CONFIG_PM @@ -314,7 +314,7 @@ done: return retval; } -EXPORT_SYMBOL (usb_hcd_pci_suspend); +EXPORT_SYMBOL_GPL(usb_hcd_pci_suspend); /** * usb_hcd_pci_resume - power management resume of a PCI-based HCD @@ -416,7 +416,7 @@ int usb_hcd_pci_resume (struct pci_dev *dev) return retval; } -EXPORT_SYMBOL (usb_hcd_pci_resume); +EXPORT_SYMBOL_GPL(usb_hcd_pci_resume); #endif /* CONFIG_PM */ @@ -435,5 +435,5 @@ void usb_hcd_pci_shutdown (struct pci_dev *dev) if (hcd->driver->shutdown) hcd->driver->shutdown(hcd); } -EXPORT_SYMBOL (usb_hcd_pci_shutdown); +EXPORT_SYMBOL_GPL(usb_hcd_pci_shutdown); diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c index a1906908d3b1..e52ed1663b3c 100644 --- a/drivers/usb/core/hcd.c +++ b/drivers/usb/core/hcd.c @@ -971,7 +971,7 @@ long usb_calc_bus_time (int speed, int is_input, int isoc, int bytecount) return -1; } } -EXPORT_SYMBOL (usb_calc_bus_time); +EXPORT_SYMBOL_GPL(usb_calc_bus_time); /*-------------------------------------------------------------------------*/ @@ -1427,7 +1427,7 @@ void usb_hcd_giveback_urb(struct usb_hcd *hcd, struct urb *urb, int status) wake_up (&usb_kill_urb_queue); usb_put_urb (urb); } -EXPORT_SYMBOL (usb_hcd_giveback_urb); +EXPORT_SYMBOL_GPL(usb_hcd_giveback_urb); /*-------------------------------------------------------------------------*/ @@ -1667,7 +1667,7 @@ int usb_bus_start_enum(struct usb_bus *bus, unsigned port_num) mod_timer(&hcd->rh_timer, jiffies + msecs_to_jiffies(10)); return status; } -EXPORT_SYMBOL (usb_bus_start_enum); +EXPORT_SYMBOL_GPL(usb_bus_start_enum); #endif @@ -1774,7 +1774,7 @@ struct usb_hcd *usb_create_hcd (const struct hc_driver *driver, "USB Host Controller"; return hcd; } -EXPORT_SYMBOL (usb_create_hcd); +EXPORT_SYMBOL_GPL(usb_create_hcd); static void hcd_release (struct kref *kref) { @@ -1789,14 +1789,14 @@ struct usb_hcd *usb_get_hcd (struct usb_hcd *hcd) kref_get (&hcd->kref); return hcd; } -EXPORT_SYMBOL (usb_get_hcd); +EXPORT_SYMBOL_GPL(usb_get_hcd); void usb_put_hcd (struct usb_hcd *hcd) { if (hcd) kref_put (&hcd->kref, hcd_release); } -EXPORT_SYMBOL (usb_put_hcd); +EXPORT_SYMBOL_GPL(usb_put_hcd); /** * usb_add_hcd - finish generic HCD structure initialization and register @@ -1922,7 +1922,7 @@ err_register_bus: hcd_buffer_destroy(hcd); return retval; } -EXPORT_SYMBOL (usb_add_hcd); +EXPORT_SYMBOL_GPL(usb_add_hcd); /** * usb_remove_hcd - shutdown processing for generic HCDs @@ -1964,7 +1964,7 @@ void usb_remove_hcd(struct usb_hcd *hcd) usb_deregister_bus(&hcd->self); hcd_buffer_destroy(hcd); } -EXPORT_SYMBOL (usb_remove_hcd); +EXPORT_SYMBOL_GPL(usb_remove_hcd); void usb_hcd_platform_shutdown(struct platform_device* dev) @@ -1974,7 +1974,7 @@ usb_hcd_platform_shutdown(struct platform_device* dev) if (hcd->driver->shutdown) hcd->driver->shutdown(hcd); } -EXPORT_SYMBOL (usb_hcd_platform_shutdown); +EXPORT_SYMBOL_GPL(usb_hcd_platform_shutdown); /*-------------------------------------------------------------------------*/ diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c index 53fe049b40f5..68fc5219ca15 100644 --- a/drivers/usb/core/hub.c +++ b/drivers/usb/core/hub.c @@ -494,6 +494,7 @@ void usb_hub_tt_clear_buffer (struct usb_device *udev, int pipe) schedule_work (&tt->kevent); spin_unlock_irqrestore (&tt->lock, flags); } +EXPORT_SYMBOL_GPL(usb_hub_tt_clear_buffer); static void hub_power_on(struct usb_hub *hub) { @@ -3116,7 +3117,7 @@ re_enumerate: hub_port_logical_disconnect(parent_hub, port1); return -ENODEV; } -EXPORT_SYMBOL(usb_reset_device); +EXPORT_SYMBOL_GPL(usb_reset_device); /** * usb_reset_composite_device - warn interface drivers and perform a USB port reset @@ -3187,4 +3188,4 @@ int usb_reset_composite_device(struct usb_device *udev, usb_autosuspend_device(udev); return ret; } -EXPORT_SYMBOL(usb_reset_composite_device); +EXPORT_SYMBOL_GPL(usb_reset_composite_device); diff --git a/drivers/usb/core/message.c b/drivers/usb/core/message.c index fcd40ecbeecc..58b8e1c6b9a6 100644 --- a/drivers/usb/core/message.c +++ b/drivers/usb/core/message.c @@ -147,7 +147,7 @@ int usb_control_msg(struct usb_device *dev, unsigned int pipe, __u8 request, __u return ret; } - +EXPORT_SYMBOL_GPL(usb_control_msg); /** * usb_interrupt_msg - Builds an interrupt urb, sends it off and waits for completion @@ -238,6 +238,7 @@ int usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe, return usb_start_wait_urb(urb, timeout, actual_length); } +EXPORT_SYMBOL_GPL(usb_bulk_msg); /*-------------------------------------------------------------------*/ @@ -465,7 +466,7 @@ nomem: sg_clean (io); return -ENOMEM; } - +EXPORT_SYMBOL_GPL(usb_sg_init); /** * usb_sg_wait - synchronously execute scatter/gather request @@ -569,6 +570,7 @@ void usb_sg_wait (struct usb_sg_request *io) sg_clean (io); } +EXPORT_SYMBOL_GPL(usb_sg_wait); /** * usb_sg_cancel - stop scatter/gather i/o issued by usb_sg_wait() @@ -604,6 +606,7 @@ void usb_sg_cancel (struct usb_sg_request *io) } spin_unlock_irqrestore (&io->lock, flags); } +EXPORT_SYMBOL_GPL(usb_sg_cancel); /*-------------------------------------------------------------------*/ @@ -652,6 +655,7 @@ int usb_get_descriptor(struct usb_device *dev, unsigned char type, unsigned char } return result; } +EXPORT_SYMBOL_GPL(usb_get_descriptor); /** * usb_get_string - gets a string descriptor @@ -827,6 +831,7 @@ int usb_string(struct usb_device *dev, int index, char *buf, size_t size) kfree(tbuf); return err; } +EXPORT_SYMBOL_GPL(usb_string); /** * usb_cache_string - read a string descriptor and cache it for later use @@ -927,6 +932,7 @@ int usb_get_status(struct usb_device *dev, int type, int target, void *data) kfree(status); return ret; } +EXPORT_SYMBOL_GPL(usb_get_status); /** * usb_clear_halt - tells device to clear endpoint halt/stall condition @@ -985,6 +991,7 @@ int usb_clear_halt(struct usb_device *dev, int pipe) return 0; } +EXPORT_SYMBOL_GPL(usb_clear_halt); /** * usb_disable_endpoint -- Disable an endpoint by address @@ -1253,6 +1260,7 @@ int usb_set_interface(struct usb_device *dev, int interface, int alternate) return 0; } +EXPORT_SYMBOL_GPL(usb_set_interface); /** * usb_reset_configuration - lightweight device reset @@ -1328,6 +1336,7 @@ int usb_reset_configuration(struct usb_device *dev) } return 0; } +EXPORT_SYMBOL_GPL(usb_reset_configuration); static void usb_release_interface(struct device *dev) { @@ -1677,22 +1686,3 @@ int usb_driver_set_configuration(struct usb_device *udev, int config) return 0; } EXPORT_SYMBOL_GPL(usb_driver_set_configuration); - -// synchronous request completion model -EXPORT_SYMBOL(usb_control_msg); -EXPORT_SYMBOL(usb_bulk_msg); - -EXPORT_SYMBOL(usb_sg_init); -EXPORT_SYMBOL(usb_sg_cancel); -EXPORT_SYMBOL(usb_sg_wait); - -// synchronous control message convenience routines -EXPORT_SYMBOL(usb_get_descriptor); -EXPORT_SYMBOL(usb_get_status); -EXPORT_SYMBOL(usb_string); - -// synchronous calls that also maintain usbcore state -EXPORT_SYMBOL(usb_clear_halt); -EXPORT_SYMBOL(usb_reset_configuration); -EXPORT_SYMBOL(usb_set_interface); - diff --git a/drivers/usb/core/urb.c b/drivers/usb/core/urb.c index d05ead20081c..0b54dc174e2c 100644 --- a/drivers/usb/core/urb.c +++ b/drivers/usb/core/urb.c @@ -42,6 +42,7 @@ void usb_init_urb(struct urb *urb) INIT_LIST_HEAD(&urb->anchor_list); } } +EXPORT_SYMBOL_GPL(usb_init_urb); /** * 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) usb_init_urb(urb); return urb; } +EXPORT_SYMBOL_GPL(usb_alloc_urb); /** * 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) if (urb) kref_put(&urb->kref, urb_destroy); } +EXPORT_SYMBOL_GPL(usb_free_urb); /** * usb_get_urb - increments the reference count of the urb @@ -106,6 +109,7 @@ struct urb * usb_get_urb(struct urb *urb) kref_get(&urb->kref); return urb; } +EXPORT_SYMBOL_GPL(usb_get_urb); /** * usb_anchor_urb - anchors an URB while it is processed @@ -444,6 +448,7 @@ int usb_submit_urb(struct urb *urb, gfp_t mem_flags) return usb_hcd_submit_urb(urb, mem_flags); } +EXPORT_SYMBOL_GPL(usb_submit_urb); /*-------------------------------------------------------------------*/ @@ -514,6 +519,7 @@ int usb_unlink_urb(struct urb *urb) return -EIDRM; return usb_hcd_unlink_urb(urb, -ECONNRESET); } +EXPORT_SYMBOL_GPL(usb_unlink_urb); /** * usb_kill_urb - cancel a transfer request and wait for it to finish @@ -553,6 +559,7 @@ void usb_kill_urb(struct urb *urb) --urb->reject; mutex_unlock(&reject_mutex); } +EXPORT_SYMBOL_GPL(usb_kill_urb); /** * usb_kill_anchored_urbs - cancel transfer requests en masse @@ -595,11 +602,3 @@ int usb_wait_anchor_empty_timeout(struct usb_anchor *anchor, msecs_to_jiffies(timeout)); } EXPORT_SYMBOL_GPL(usb_wait_anchor_empty_timeout); - -EXPORT_SYMBOL(usb_init_urb); -EXPORT_SYMBOL(usb_alloc_urb); -EXPORT_SYMBOL(usb_free_urb); -EXPORT_SYMBOL(usb_get_urb); -EXPORT_SYMBOL(usb_submit_urb); -EXPORT_SYMBOL(usb_unlink_urb); -EXPORT_SYMBOL(usb_kill_urb); diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c index fdb444d81271..8c6319afa757 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, return NULL; } +EXPORT_SYMBOL_GPL(usb_ifnum_to_if); /** * usb_altnum_to_altsetting - get the altsetting structure with a given @@ -126,6 +127,7 @@ struct usb_host_interface *usb_altnum_to_altsetting(const struct usb_interface * } return NULL; } +EXPORT_SYMBOL_GPL(usb_altnum_to_altsetting); struct find_interface_arg { int minor; @@ -170,6 +172,7 @@ struct usb_interface *usb_find_interface(struct usb_driver *drv, int minor) __find_interface); return argb.interface; } +EXPORT_SYMBOL_GPL(usb_find_interface); /** * usb_release_dev - free a usb device structure when all users of it are finished. @@ -369,6 +372,7 @@ struct usb_device *usb_get_dev(struct usb_device *dev) get_device(&dev->dev); return dev; } +EXPORT_SYMBOL_GPL(usb_get_dev); /** * usb_put_dev - release a use of the usb device structure @@ -382,6 +386,7 @@ void usb_put_dev(struct usb_device *dev) if (dev) put_device(&dev->dev); } +EXPORT_SYMBOL_GPL(usb_put_dev); /** * usb_get_intf - increments the reference count of the usb interface structure @@ -402,6 +407,7 @@ struct usb_interface *usb_get_intf(struct usb_interface *intf) get_device(&intf->dev); return intf; } +EXPORT_SYMBOL_GPL(usb_get_intf); /** * usb_put_intf - release a use of the usb interface structure @@ -416,7 +422,7 @@ void usb_put_intf(struct usb_interface *intf) if (intf) put_device(&intf->dev); } - +EXPORT_SYMBOL_GPL(usb_put_intf); /* USB device locking * @@ -489,7 +495,7 @@ int usb_lock_device_for_reset(struct usb_device *udev, } return 1; } - +EXPORT_SYMBOL_GPL(usb_lock_device_for_reset); static struct usb_device *match_device(struct usb_device *dev, u16 vendor_id, u16 product_id) @@ -578,6 +584,7 @@ int usb_get_current_frame_number(struct usb_device *dev) { return usb_hcd_get_frame_number(dev); } +EXPORT_SYMBOL_GPL(usb_get_current_frame_number); /*-------------------------------------------------------------------*/ /* @@ -612,6 +619,7 @@ int __usb_get_extra_descriptor(char *buffer, unsigned size, } return -1; } +EXPORT_SYMBOL_GPL(__usb_get_extra_descriptor); /** * usb_buffer_alloc - allocate dma-consistent buffer for URB_NO_xxx_DMA_MAP @@ -646,6 +654,7 @@ void *usb_buffer_alloc( return NULL; return hcd_buffer_alloc(dev->bus, size, mem_flags, dma); } +EXPORT_SYMBOL_GPL(usb_buffer_alloc); /** * usb_buffer_free - free memory allocated with usb_buffer_alloc() @@ -671,6 +680,7 @@ void usb_buffer_free( return; hcd_buffer_free(dev->bus, size, addr, dma); } +EXPORT_SYMBOL_GPL(usb_buffer_free); /** * usb_buffer_map - create DMA mapping(s) for an urb @@ -718,6 +728,7 @@ struct urb *usb_buffer_map(struct urb *urb) | URB_NO_SETUP_DMA_MAP); return urb; } +EXPORT_SYMBOL_GPL(usb_buffer_map); #endif /* 0 */ /* XXX DISABLED, no users currently. If you wish to re-enable this @@ -755,6 +766,7 @@ void usb_buffer_dmasync(struct urb *urb) DMA_TO_DEVICE); } } +EXPORT_SYMBOL_GPL(usb_buffer_dmasync); #endif /** @@ -790,6 +802,7 @@ void usb_buffer_unmap(struct urb *urb) urb->transfer_flags &= ~(URB_NO_TRANSFER_DMA_MAP | URB_NO_SETUP_DMA_MAP); } +EXPORT_SYMBOL_GPL(usb_buffer_unmap); #endif /* 0 */ /** @@ -834,6 +847,7 @@ int usb_buffer_map_sg(const struct usb_device *dev, int is_in, return dma_map_sg(controller, sg, nents, is_in ? DMA_FROM_DEVICE : DMA_TO_DEVICE); } +EXPORT_SYMBOL_GPL(usb_buffer_map_sg); /* XXX DISABLED, no users currently. If you wish to re-enable this * XXX please determine whether the sync is to transfer ownership of @@ -867,6 +881,7 @@ void usb_buffer_dmasync_sg(const struct usb_device *dev, int is_in, dma_sync_sg(controller, sg, n_hw_ents, is_in ? DMA_FROM_DEVICE : DMA_TO_DEVICE); } +EXPORT_SYMBOL_GPL(usb_buffer_dmasync_sg); #endif /** @@ -893,6 +908,7 @@ void usb_buffer_unmap_sg(const struct usb_device *dev, int is_in, dma_unmap_sg(controller, sg, n_hw_ents, is_in ? DMA_FROM_DEVICE : DMA_TO_DEVICE); } +EXPORT_SYMBOL_GPL(usb_buffer_unmap_sg); /* format to disable USB on kernel command line is: nousb */ __module_param_call("", nousb, param_set_bool, param_get_bool, &nousb, 0444); @@ -904,6 +920,7 @@ int usb_disabled(void) { return nousb; } +EXPORT_SYMBOL_GPL(usb_disabled); /* * Init @@ -985,45 +1002,4 @@ static void __exit usb_exit(void) subsys_initcall(usb_init); module_exit(usb_exit); - -/* - * USB may be built into the kernel or be built as modules. - * These symbols are exported for device (or host controller) - * driver modules to use. - */ - -EXPORT_SYMBOL(usb_disabled); - -EXPORT_SYMBOL_GPL(usb_get_intf); -EXPORT_SYMBOL_GPL(usb_put_intf); - -EXPORT_SYMBOL(usb_put_dev); -EXPORT_SYMBOL(usb_get_dev); -EXPORT_SYMBOL(usb_hub_tt_clear_buffer); - -EXPORT_SYMBOL(usb_lock_device_for_reset); - -EXPORT_SYMBOL(usb_find_interface); -EXPORT_SYMBOL(usb_ifnum_to_if); -EXPORT_SYMBOL(usb_altnum_to_altsetting); - -EXPORT_SYMBOL(__usb_get_extra_descriptor); - -EXPORT_SYMBOL(usb_get_current_frame_number); - -EXPORT_SYMBOL(usb_buffer_alloc); -EXPORT_SYMBOL(usb_buffer_free); - -#if 0 -EXPORT_SYMBOL(usb_buffer_map); -EXPORT_SYMBOL(usb_buffer_dmasync); -EXPORT_SYMBOL(usb_buffer_unmap); -#endif - -EXPORT_SYMBOL(usb_buffer_map_sg); -#if 0 -EXPORT_SYMBOL(usb_buffer_dmasync_sg); -#endif -EXPORT_SYMBOL(usb_buffer_unmap_sg); - MODULE_LICENSE("GPL"); -- cgit v1.2.3 From 969ab2ee9d68bd037e2db7ea12ff78baae5d2f94 Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Wed, 30 Jan 2008 15:20:32 -0800 Subject: USB: fix codingstyle issues in include/linux/usb.h No logical code changes were made, but checkpatch.pl is much happier now. Signed-off-by: Greg Kroah-Hartman --- include/linux/usb.h | 204 +++++++++++++++++++++++++++++----------------------- 1 file changed, 113 insertions(+), 91 deletions(-) diff --git a/include/linux/usb.h b/include/linux/usb.h index f8a60756fe2a..2372e2e6b527 100644 --- a/include/linux/usb.h +++ b/include/linux/usb.h @@ -162,19 +162,19 @@ struct usb_interface { unsigned needs_remote_wakeup:1; /* driver requires remote wakeup */ struct device dev; /* interface specific device info */ - struct device *usb_dev; /* pointer to the usb class's device, if any */ + struct device *usb_dev; int pm_usage_cnt; /* usage counter for autosuspend */ }; #define to_usb_interface(d) container_of(d, struct usb_interface, dev) #define interface_to_usbdev(intf) \ container_of(intf->dev.parent, struct usb_device, dev) -static inline void *usb_get_intfdata (struct usb_interface *intf) +static inline void *usb_get_intfdata(struct usb_interface *intf) { - return dev_get_drvdata (&intf->dev); + return dev_get_drvdata(&intf->dev); } -static inline void usb_set_intfdata (struct usb_interface *intf, void *data) +static inline void usb_set_intfdata(struct usb_interface *intf, void *data) { dev_set_drvdata(&intf->dev, data); } @@ -275,9 +275,10 @@ struct usb_host_config { int __usb_get_extra_descriptor(char *buffer, unsigned size, unsigned char type, void **ptr); -#define usb_get_extra_descriptor(ifpoint,type,ptr)\ - __usb_get_extra_descriptor((ifpoint)->extra,(ifpoint)->extralen,\ - type,(void**)ptr) +#define usb_get_extra_descriptor(ifpoint, type, ptr) \ + __usb_get_extra_descriptor((ifpoint)->extra, \ + (ifpoint)->extralen, \ + type, (void **)ptr) /* ----------------------------------------------------------------------- */ @@ -388,7 +389,7 @@ struct usb_device { unsigned can_submit:1; /* URBs may be submitted */ unsigned discon_suspended:1; /* Disconnected while suspended */ unsigned have_langid:1; /* whether string_langid is valid */ - unsigned authorized:1; /* Policy has determined we can use it */ + unsigned authorized:1; /* Policy has said we can use it */ unsigned wusb:1; /* Device is Wireless USB */ int string_langid; /* language ID for strings */ @@ -417,7 +418,8 @@ struct usb_device { int pm_usage_cnt; /* usage counter for autosuspend */ u32 quirks; /* quirks of the whole device */ - atomic_t urbnum; /* number of URBs submitted for the whole device */ + atomic_t urbnum; /* number of URBs submitted for + the whole device */ unsigned long active_duration; /* total time device is not suspended */ @@ -501,11 +503,11 @@ static inline void usb_mark_last_busy(struct usb_device *udev) /*-------------------------------------------------------------------------*/ /* for drivers using iso endpoints */ -extern int usb_get_current_frame_number (struct usb_device *usb_dev); +extern int usb_get_current_frame_number(struct usb_device *usb_dev); /* used these for multi-interface device registration */ extern int usb_driver_claim_interface(struct usb_driver *driver, - struct usb_interface *iface, void* priv); + struct usb_interface *iface, void *priv); /** * usb_interface_claimed - returns true iff an interface is claimed @@ -517,7 +519,8 @@ extern int usb_driver_claim_interface(struct usb_driver *driver, * may need to explicitly claim that lock. * */ -static inline int usb_interface_claimed(struct usb_interface *iface) { +static inline int usb_interface_claimed(struct usb_interface *iface) +{ return (iface->dev.driver != NULL); } @@ -560,12 +563,11 @@ extern struct usb_host_interface *usb_altnum_to_altsetting( * USB 2.0 root hubs (EHCI host controllers) will get one path ID if they are * high speed, and a different one if they are full or low speed. */ -static inline int usb_make_path (struct usb_device *dev, char *buf, - size_t size) +static inline int usb_make_path(struct usb_device *dev, char *buf, size_t size) { int actual; - actual = snprintf (buf, size, "usb-%s-%s", dev->bus->bus_name, - dev->devpath); + actual = snprintf(buf, size, "usb-%s-%s", dev->bus->bus_name, + dev->devpath); return (actual >= (int)size) ? -1 : actual; } @@ -611,7 +613,8 @@ static inline int usb_endpoint_dir_in(const struct usb_endpoint_descriptor *epd) * * Returns true if the endpoint is of type OUT, otherwise it returns false. */ -static inline int usb_endpoint_dir_out(const struct usb_endpoint_descriptor *epd) +static inline int usb_endpoint_dir_out( + const struct usb_endpoint_descriptor *epd) { return ((epd->bEndpointAddress & USB_ENDPOINT_DIR_MASK) == USB_DIR_OUT); } @@ -622,7 +625,8 @@ static inline int usb_endpoint_dir_out(const struct usb_endpoint_descriptor *epd * * Returns true if the endpoint is of type bulk, otherwise it returns false. */ -static inline int usb_endpoint_xfer_bulk(const struct usb_endpoint_descriptor *epd) +static inline int usb_endpoint_xfer_bulk( + const struct usb_endpoint_descriptor *epd) { return ((epd->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) == USB_ENDPOINT_XFER_BULK); @@ -634,7 +638,8 @@ static inline int usb_endpoint_xfer_bulk(const struct usb_endpoint_descriptor *e * * Returns true if the endpoint is of type control, otherwise it returns false. */ -static inline int usb_endpoint_xfer_control(const struct usb_endpoint_descriptor *epd) +static inline int usb_endpoint_xfer_control( + const struct usb_endpoint_descriptor *epd) { return ((epd->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) == USB_ENDPOINT_XFER_CONTROL); @@ -647,7 +652,8 @@ static inline int usb_endpoint_xfer_control(const struct usb_endpoint_descriptor * Returns true if the endpoint is of type interrupt, otherwise it returns * false. */ -static inline int usb_endpoint_xfer_int(const struct usb_endpoint_descriptor *epd) +static inline int usb_endpoint_xfer_int( + const struct usb_endpoint_descriptor *epd) { return ((epd->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) == USB_ENDPOINT_XFER_INT); @@ -660,7 +666,8 @@ static inline int usb_endpoint_xfer_int(const struct usb_endpoint_descriptor *ep * Returns true if the endpoint is of type isochronous, otherwise it returns * false. */ -static inline int usb_endpoint_xfer_isoc(const struct usb_endpoint_descriptor *epd) +static inline int usb_endpoint_xfer_isoc( + const struct usb_endpoint_descriptor *epd) { return ((epd->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) == USB_ENDPOINT_XFER_ISOC); @@ -673,7 +680,8 @@ static inline int usb_endpoint_xfer_isoc(const struct usb_endpoint_descriptor *e * Returns true if the endpoint has bulk transfer type and IN direction, * otherwise it returns false. */ -static inline int usb_endpoint_is_bulk_in(const struct usb_endpoint_descriptor *epd) +static inline int usb_endpoint_is_bulk_in( + const struct usb_endpoint_descriptor *epd) { return (usb_endpoint_xfer_bulk(epd) && usb_endpoint_dir_in(epd)); } @@ -685,7 +693,8 @@ static inline int usb_endpoint_is_bulk_in(const struct usb_endpoint_descriptor * * Returns true if the endpoint has bulk transfer type and OUT direction, * otherwise it returns false. */ -static inline int usb_endpoint_is_bulk_out(const struct usb_endpoint_descriptor *epd) +static inline int usb_endpoint_is_bulk_out( + const struct usb_endpoint_descriptor *epd) { return (usb_endpoint_xfer_bulk(epd) && usb_endpoint_dir_out(epd)); } @@ -697,7 +706,8 @@ static inline int usb_endpoint_is_bulk_out(const struct usb_endpoint_descriptor * Returns true if the endpoint has interrupt transfer type and IN direction, * otherwise it returns false. */ -static inline int usb_endpoint_is_int_in(const struct usb_endpoint_descriptor *epd) +static inline int usb_endpoint_is_int_in( + const struct usb_endpoint_descriptor *epd) { return (usb_endpoint_xfer_int(epd) && usb_endpoint_dir_in(epd)); } @@ -709,7 +719,8 @@ static inline int usb_endpoint_is_int_in(const struct usb_endpoint_descriptor *e * Returns true if the endpoint has interrupt transfer type and OUT direction, * otherwise it returns false. */ -static inline int usb_endpoint_is_int_out(const struct usb_endpoint_descriptor *epd) +static inline int usb_endpoint_is_int_out( + const struct usb_endpoint_descriptor *epd) { return (usb_endpoint_xfer_int(epd) && usb_endpoint_dir_out(epd)); } @@ -721,7 +732,8 @@ static inline int usb_endpoint_is_int_out(const struct usb_endpoint_descriptor * * Returns true if the endpoint has isochronous transfer type and IN direction, * otherwise it returns false. */ -static inline int usb_endpoint_is_isoc_in(const struct usb_endpoint_descriptor *epd) +static inline int usb_endpoint_is_isoc_in( + const struct usb_endpoint_descriptor *epd) { return (usb_endpoint_xfer_isoc(epd) && usb_endpoint_dir_in(epd)); } @@ -733,7 +745,8 @@ static inline int usb_endpoint_is_isoc_in(const struct usb_endpoint_descriptor * * Returns true if the endpoint has isochronous transfer type and OUT direction, * otherwise it returns false. */ -static inline int usb_endpoint_is_isoc_out(const struct usb_endpoint_descriptor *epd) +static inline int usb_endpoint_is_isoc_out( + const struct usb_endpoint_descriptor *epd) { return (usb_endpoint_xfer_isoc(epd) && usb_endpoint_dir_out(epd)); } @@ -764,8 +777,9 @@ static inline int usb_endpoint_is_isoc_out(const struct usb_endpoint_descriptor * specific device. */ #define USB_DEVICE(vend,prod) \ - .match_flags = USB_DEVICE_ID_MATCH_DEVICE, .idVendor = (vend), \ - .idProduct = (prod) + .match_flags = USB_DEVICE_ID_MATCH_DEVICE, \ + .idVendor = (vend), \ + .idProduct = (prod) /** * USB_DEVICE_VER - macro used to describe a specific usb device with a * version range @@ -777,10 +791,12 @@ static inline int usb_endpoint_is_isoc_out(const struct usb_endpoint_descriptor * This macro is used to create a struct usb_device_id that matches a * specific device, with a version range. */ -#define USB_DEVICE_VER(vend,prod,lo,hi) \ +#define USB_DEVICE_VER(vend, prod, lo, hi) \ .match_flags = USB_DEVICE_ID_MATCH_DEVICE_AND_VERSION, \ - .idVendor = (vend), .idProduct = (prod), \ - .bcdDevice_lo = (lo), .bcdDevice_hi = (hi) + .idVendor = (vend), \ + .idProduct = (prod), \ + .bcdDevice_lo = (lo), \ + .bcdDevice_hi = (hi) /** * USB_DEVICE_INTERFACE_PROTOCOL - macro used to describe a usb @@ -792,8 +808,9 @@ static inline int usb_endpoint_is_isoc_out(const struct usb_endpoint_descriptor * This macro is used to create a struct usb_device_id that matches a * specific interface protocol of devices. */ -#define USB_DEVICE_INTERFACE_PROTOCOL(vend,prod,pr) \ - .match_flags = USB_DEVICE_ID_MATCH_DEVICE | USB_DEVICE_ID_MATCH_INT_PROTOCOL, \ +#define USB_DEVICE_INTERFACE_PROTOCOL(vend, prod, pr) \ + .match_flags = USB_DEVICE_ID_MATCH_DEVICE | \ + USB_DEVICE_ID_MATCH_INT_PROTOCOL, \ .idVendor = (vend), \ .idProduct = (prod), \ .bInterfaceProtocol = (pr) @@ -807,12 +824,14 @@ static inline int usb_endpoint_is_isoc_out(const struct usb_endpoint_descriptor * This macro is used to create a struct usb_device_id that matches a * specific class of devices. */ -#define USB_DEVICE_INFO(cl,sc,pr) \ - .match_flags = USB_DEVICE_ID_MATCH_DEV_INFO, .bDeviceClass = (cl), \ - .bDeviceSubClass = (sc), .bDeviceProtocol = (pr) +#define USB_DEVICE_INFO(cl, sc, pr) \ + .match_flags = USB_DEVICE_ID_MATCH_DEV_INFO, \ + .bDeviceClass = (cl), \ + .bDeviceSubClass = (sc), \ + .bDeviceProtocol = (pr) /** - * USB_INTERFACE_INFO - macro used to describe a class of usb interfaces + * USB_INTERFACE_INFO - macro used to describe a class of usb interfaces * @cl: bInterfaceClass value * @sc: bInterfaceSubClass value * @pr: bInterfaceProtocol value @@ -820,9 +839,11 @@ static inline int usb_endpoint_is_isoc_out(const struct usb_endpoint_descriptor * This macro is used to create a struct usb_device_id that matches a * specific class of interfaces. */ -#define USB_INTERFACE_INFO(cl,sc,pr) \ - .match_flags = USB_DEVICE_ID_MATCH_INT_INFO, .bInterfaceClass = (cl), \ - .bInterfaceSubClass = (sc), .bInterfaceProtocol = (pr) +#define USB_INTERFACE_INFO(cl, sc, pr) \ + .match_flags = USB_DEVICE_ID_MATCH_INT_INFO, \ + .bInterfaceClass = (cl), \ + .bInterfaceSubClass = (sc), \ + .bInterfaceProtocol = (pr) /** * USB_DEVICE_AND_INTERFACE_INFO - macro used to describe a specific usb device @@ -839,12 +860,14 @@ static inline int usb_endpoint_is_isoc_out(const struct usb_endpoint_descriptor * This is especially useful when explicitly matching devices that have * vendor specific bDeviceClass values, but standards-compliant interfaces. */ -#define USB_DEVICE_AND_INTERFACE_INFO(vend,prod,cl,sc,pr) \ +#define USB_DEVICE_AND_INTERFACE_INFO(vend, prod, cl, sc, pr) \ .match_flags = USB_DEVICE_ID_MATCH_INT_INFO \ | USB_DEVICE_ID_MATCH_DEVICE, \ - .idVendor = (vend), .idProduct = (prod), \ + .idVendor = (vend), \ + .idProduct = (prod), \ .bInterfaceClass = (cl), \ - .bInterfaceSubClass = (sc), .bInterfaceProtocol = (pr) + .bInterfaceSubClass = (sc), \ + .bInterfaceProtocol = (pr) /* ----------------------------------------------------------------------- */ @@ -1122,7 +1145,7 @@ typedef void (*usb_complete_t)(struct urb *); * transferred. It will normally be the same as requested, unless * either an error was reported or a short read was performed. * The URB_SHORT_NOT_OK transfer flag may be used to make such - * short reads be reported as errors. + * short reads be reported as errors. * @setup_packet: Only used for control transfers, this points to eight bytes * of setup data. Control transfers always start by sending this data * to the device. Then transfer_buffer is read or written, if needed. @@ -1141,7 +1164,7 @@ typedef void (*usb_complete_t)(struct urb *); * @complete: Completion handler. This URB is passed as the parameter to the * completion function. The completion function may then do what * it likes with the URB, including resubmitting or freeing it. - * @iso_frame_desc: Used to provide arrays of ISO transfer buffers and to + * @iso_frame_desc: Used to provide arrays of ISO transfer buffers and to * collect the transfer status for each buffer. * * This structure identifies USB transfer requests. URBs must be allocated by @@ -1245,8 +1268,7 @@ typedef void (*usb_complete_t)(struct urb *); * when the urb is owned by the hcd, that is, since the call to * usb_submit_urb() till the entry into the completion routine. */ -struct urb -{ +struct urb { /* private: usb core and host controller only fields in the urb */ struct kref kref; /* reference count of the URB */ void *hcpriv; /* private data for host controller */ @@ -1257,10 +1279,10 @@ struct urb /* public: documented fields in the urb that can be used by drivers */ struct list_head urb_list; /* list head for use by the urb's * current owner */ - struct list_head anchor_list; /* the URB may be anchored by the driver */ + struct list_head anchor_list; /* the URB may be anchored */ struct usb_anchor *anchor; struct usb_device *dev; /* (in) pointer to associated device */ - struct usb_host_endpoint *ep; /* (internal) pointer to endpoint struct */ + struct usb_host_endpoint *ep; /* (internal) pointer to endpoint */ unsigned int pipe; /* (in) pipe information */ int status; /* (return) non-ISO status */ unsigned int transfer_flags; /* (in) URB_SHORT_NOT_OK | ...*/ @@ -1297,14 +1319,14 @@ struct urb * Initializes a control urb with the proper information needed to submit * it to a device. */ -static inline void usb_fill_control_urb (struct urb *urb, - struct usb_device *dev, - unsigned int pipe, - unsigned char *setup_packet, - void *transfer_buffer, - int buffer_length, - usb_complete_t complete_fn, - void *context) +static inline void usb_fill_control_urb(struct urb *urb, + struct usb_device *dev, + unsigned int pipe, + unsigned char *setup_packet, + void *transfer_buffer, + int buffer_length, + usb_complete_t complete_fn, + void *context) { urb->dev = dev; urb->pipe = pipe; @@ -1328,13 +1350,13 @@ static inline void usb_fill_control_urb (struct urb *urb, * Initializes a bulk urb with the proper information needed to submit it * to a device. */ -static inline void usb_fill_bulk_urb (struct urb *urb, - struct usb_device *dev, - unsigned int pipe, - void *transfer_buffer, - int buffer_length, - usb_complete_t complete_fn, - void *context) +static inline void usb_fill_bulk_urb(struct urb *urb, + struct usb_device *dev, + unsigned int pipe, + void *transfer_buffer, + int buffer_length, + usb_complete_t complete_fn, + void *context) { urb->dev = dev; urb->pipe = pipe; @@ -1362,14 +1384,14 @@ static inline void usb_fill_bulk_urb (struct urb *urb, * the endpoint interval, and express polling intervals in microframes * (eight per millisecond) rather than in frames (one per millisecond). */ -static inline void usb_fill_int_urb (struct urb *urb, - struct usb_device *dev, - unsigned int pipe, - void *transfer_buffer, - int buffer_length, - usb_complete_t complete_fn, - void *context, - int interval) +static inline void usb_fill_int_urb(struct urb *urb, + struct usb_device *dev, + unsigned int pipe, + void *transfer_buffer, + int buffer_length, + usb_complete_t complete_fn, + void *context, + int interval) { urb->dev = dev; urb->pipe = pipe; @@ -1422,15 +1444,15 @@ static inline int usb_urb_dir_out(struct urb *urb) return (urb->transfer_flags & URB_DIR_MASK) == URB_DIR_OUT; } -void *usb_buffer_alloc (struct usb_device *dev, size_t size, +void *usb_buffer_alloc(struct usb_device *dev, size_t size, gfp_t mem_flags, dma_addr_t *dma); -void usb_buffer_free (struct usb_device *dev, size_t size, +void usb_buffer_free(struct usb_device *dev, size_t size, void *addr, dma_addr_t dma); #if 0 -struct urb *usb_buffer_map (struct urb *urb); -void usb_buffer_dmasync (struct urb *urb); -void usb_buffer_unmap (struct urb *urb); +struct urb *usb_buffer_map(struct urb *urb); +void usb_buffer_dmasync(struct urb *urb); +void usb_buffer_unmap(struct urb *urb); #endif struct scatterlist; @@ -1502,7 +1524,7 @@ struct usb_sg_request { int status; size_t bytes; - /* + /* * members below are private: to usbcore, * and are not provided for driver access! */ @@ -1520,18 +1542,18 @@ struct usb_sg_request { struct completion complete; }; -int usb_sg_init ( +int usb_sg_init( struct usb_sg_request *io, struct usb_device *dev, - unsigned pipe, + unsigned pipe, unsigned period, struct scatterlist *sg, int nents, size_t length, gfp_t mem_flags ); -void usb_sg_cancel (struct usb_sg_request *io); -void usb_sg_wait (struct usb_sg_request *io); +void usb_sg_cancel(struct usb_sg_request *io); +void usb_sg_wait(struct usb_sg_request *io); /* ----------------------------------------------------------------------- */ @@ -1588,21 +1610,21 @@ static inline unsigned int __create_pipe(struct usb_device *dev, /* Create various pipes... */ #define usb_sndctrlpipe(dev,endpoint) \ - ((PIPE_CONTROL << 30) | __create_pipe(dev,endpoint)) + ((PIPE_CONTROL << 30) | __create_pipe(dev, endpoint)) #define usb_rcvctrlpipe(dev,endpoint) \ - ((PIPE_CONTROL << 30) | __create_pipe(dev,endpoint) | USB_DIR_IN) + ((PIPE_CONTROL << 30) | __create_pipe(dev, endpoint) | USB_DIR_IN) #define usb_sndisocpipe(dev,endpoint) \ - ((PIPE_ISOCHRONOUS << 30) | __create_pipe(dev,endpoint)) + ((PIPE_ISOCHRONOUS << 30) | __create_pipe(dev, endpoint)) #define usb_rcvisocpipe(dev,endpoint) \ - ((PIPE_ISOCHRONOUS << 30) | __create_pipe(dev,endpoint) | USB_DIR_IN) + ((PIPE_ISOCHRONOUS << 30) | __create_pipe(dev, endpoint) | USB_DIR_IN) #define usb_sndbulkpipe(dev,endpoint) \ - ((PIPE_BULK << 30) | __create_pipe(dev,endpoint)) + ((PIPE_BULK << 30) | __create_pipe(dev, endpoint)) #define usb_rcvbulkpipe(dev,endpoint) \ - ((PIPE_BULK << 30) | __create_pipe(dev,endpoint) | USB_DIR_IN) + ((PIPE_BULK << 30) | __create_pipe(dev, endpoint) | USB_DIR_IN) #define usb_sndintpipe(dev,endpoint) \ - ((PIPE_INTERRUPT << 30) | __create_pipe(dev,endpoint)) + ((PIPE_INTERRUPT << 30) | __create_pipe(dev, endpoint)) #define usb_rcvintpipe(dev,endpoint) \ - ((PIPE_INTERRUPT << 30) | __create_pipe(dev,endpoint) | USB_DIR_IN) + ((PIPE_INTERRUPT << 30) | __create_pipe(dev, endpoint) | USB_DIR_IN) /*-------------------------------------------------------------------------*/ -- cgit v1.2.3 From 41dceed51f0e6105ca2bf45c3835a7cd9eaa077b Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Wed, 30 Jan 2008 15:21:33 -0800 Subject: USB: fix codingstyle issues in include/linux/usb/ Fixes a number of coding style issues in the USB public header files. Signed-off-by: Greg Kroah-Hartman --- include/linux/usb/audio.h | 14 ++-- include/linux/usb/cdc.h | 16 ++--- include/linux/usb/gadget.h | 123 +++++++++++++++------------------ include/linux/usb/gadgetfs.h | 22 +++--- include/linux/usb/iowarrior.h | 25 ++++--- include/linux/usb/isp116x.h | 2 +- include/linux/usb/midi.h | 26 +++---- include/linux/usb/net2280.h | 32 ++++----- include/linux/usb/otg.h | 2 +- include/linux/usb/serial.h | 157 +++++++++++++++++++++++------------------- include/linux/usb/sl811.h | 6 +- 11 files changed, 220 insertions(+), 205 deletions(-) diff --git a/include/linux/usb/audio.h b/include/linux/usb/audio.h index 6bd235994dc2..2dfeef16b221 100644 --- a/include/linux/usb/audio.h +++ b/include/linux/usb/audio.h @@ -27,13 +27,13 @@ /* 4.3.2 Class-Specific AC Interface Descriptor */ struct usb_ac_header_descriptor { - __u8 bLength; // 8+n - __u8 bDescriptorType; // USB_DT_CS_INTERFACE - __u8 bDescriptorSubtype; // USB_MS_HEADER - __le16 bcdADC; // 0x0100 - __le16 wTotalLength; // includes Unit and Terminal desc. - __u8 bInCollection; // n - __u8 baInterfaceNr[]; // [n] + __u8 bLength; /* 8+n */ + __u8 bDescriptorType; /* USB_DT_CS_INTERFACE */ + __u8 bDescriptorSubtype; /* USB_MS_HEADER */ + __le16 bcdADC; /* 0x0100 */ + __le16 wTotalLength; /* includes Unit and Terminal desc. */ + __u8 bInCollection; /* n */ + __u8 baInterfaceNr[]; /* [n] */ } __attribute__ ((packed)); #define USB_DT_AC_HEADER_SIZE(n) (8+(n)) diff --git a/include/linux/usb/cdc.h b/include/linux/usb/cdc.h index 2204ae22c381..94ee4ecf0564 100644 --- a/include/linux/usb/cdc.h +++ b/include/linux/usb/cdc.h @@ -29,16 +29,16 @@ * Class-Specific descriptors ... there are a couple dozen of them */ -#define USB_CDC_HEADER_TYPE 0x00 /* header_desc */ -#define USB_CDC_CALL_MANAGEMENT_TYPE 0x01 /* call_mgmt_descriptor */ -#define USB_CDC_ACM_TYPE 0x02 /* acm_descriptor */ -#define USB_CDC_UNION_TYPE 0x06 /* union_desc */ +#define USB_CDC_HEADER_TYPE 0x00 /* header_desc */ +#define USB_CDC_CALL_MANAGEMENT_TYPE 0x01 /* call_mgmt_descriptor */ +#define USB_CDC_ACM_TYPE 0x02 /* acm_descriptor */ +#define USB_CDC_UNION_TYPE 0x06 /* union_desc */ #define USB_CDC_COUNTRY_TYPE 0x07 -#define USB_CDC_NETWORK_TERMINAL_TYPE 0x0a /* network_terminal_desc */ -#define USB_CDC_ETHERNET_TYPE 0x0f /* ether_desc */ +#define USB_CDC_NETWORK_TERMINAL_TYPE 0x0a /* network_terminal_desc */ +#define USB_CDC_ETHERNET_TYPE 0x0f /* ether_desc */ #define USB_CDC_WHCM_TYPE 0x11 -#define USB_CDC_MDLM_TYPE 0x12 /* mdlm_desc */ -#define USB_CDC_MDLM_DETAIL_TYPE 0x13 /* mdlm_detail_desc */ +#define USB_CDC_MDLM_TYPE 0x12 /* mdlm_desc */ +#define USB_CDC_MDLM_DETAIL_TYPE 0x13 /* mdlm_detail_desc */ #define USB_CDC_DMM_TYPE 0x14 #define USB_CDC_OBEX_TYPE 0x15 diff --git a/include/linux/usb/gadget.h b/include/linux/usb/gadget.h index c1527c2ef3cb..aa3047ff00d1 100644 --- a/include/linux/usb/gadget.h +++ b/include/linux/usb/gadget.h @@ -70,9 +70,10 @@ struct usb_ep; * * Bulk endpoints can use any size buffers, and can also be used for interrupt * transfers. interrupt-only endpoints can be much less functional. + * + * NOTE: this is analagous to 'struct urb' on the host side, except that + * it's thinner and promotes more pre-allocation. */ - // NOTE this is analagous to 'struct urb' on the host side, - // except that it's thinner and promotes more pre-allocation. struct usb_request { void *buf; @@ -168,10 +169,10 @@ struct usb_ep { * * returns zero, or a negative error code. */ -static inline int -usb_ep_enable (struct usb_ep *ep, const struct usb_endpoint_descriptor *desc) +static inline int usb_ep_enable(struct usb_ep *ep, + const struct usb_endpoint_descriptor *desc) { - return ep->ops->enable (ep, desc); + return ep->ops->enable(ep, desc); } /** @@ -186,10 +187,9 @@ usb_ep_enable (struct usb_ep *ep, const struct usb_endpoint_descriptor *desc) * * returns zero, or a negative error code. */ -static inline int -usb_ep_disable (struct usb_ep *ep) +static inline int usb_ep_disable(struct usb_ep *ep) { - return ep->ops->disable (ep); + return ep->ops->disable(ep); } /** @@ -206,10 +206,10 @@ usb_ep_disable (struct usb_ep *ep) * * Returns the request, or null if one could not be allocated. */ -static inline struct usb_request * -usb_ep_alloc_request (struct usb_ep *ep, gfp_t gfp_flags) +static inline struct usb_request *usb_ep_alloc_request(struct usb_ep *ep, + gfp_t gfp_flags) { - return ep->ops->alloc_request (ep, gfp_flags); + return ep->ops->alloc_request(ep, gfp_flags); } /** @@ -221,10 +221,10 @@ usb_ep_alloc_request (struct usb_ep *ep, gfp_t gfp_flags) * Caller guarantees the request is not queued, and that it will * no longer be requeued (or otherwise used). */ -static inline void -usb_ep_free_request (struct usb_ep *ep, struct usb_request *req) +static inline void usb_ep_free_request(struct usb_ep *ep, + struct usb_request *req) { - ep->ops->free_request (ep, req); + ep->ops->free_request(ep, req); } /** @@ -281,10 +281,10 @@ usb_ep_free_request (struct usb_ep *ep, struct usb_request *req) * report errors; errors will also be * reported when the usb peripheral is disconnected. */ -static inline int -usb_ep_queue (struct usb_ep *ep, struct usb_request *req, gfp_t gfp_flags) +static inline int usb_ep_queue(struct usb_ep *ep, + struct usb_request *req, gfp_t gfp_flags) { - return ep->ops->queue (ep, req, gfp_flags); + return ep->ops->queue(ep, req, gfp_flags); } /** @@ -301,9 +301,9 @@ usb_ep_queue (struct usb_ep *ep, struct usb_request *req, gfp_t gfp_flags) * restrictions prevent drivers from supporting configuration changes, * even to configuration zero (a "chapter 9" requirement). */ -static inline int usb_ep_dequeue (struct usb_ep *ep, struct usb_request *req) +static inline int usb_ep_dequeue(struct usb_ep *ep, struct usb_request *req) { - return ep->ops->dequeue (ep, req); + return ep->ops->dequeue(ep, req); } /** @@ -327,10 +327,9 @@ static inline int usb_ep_dequeue (struct usb_ep *ep, struct usb_request *req) * transfer requests are still queued, or if the controller hardware * (usually a FIFO) still holds bytes that the host hasn't collected. */ -static inline int -usb_ep_set_halt (struct usb_ep *ep) +static inline int usb_ep_set_halt(struct usb_ep *ep) { - return ep->ops->set_halt (ep, 1); + return ep->ops->set_halt(ep, 1); } /** @@ -346,10 +345,9 @@ usb_ep_set_halt (struct usb_ep *ep) * Note that some hardware can't support this request (like pxa2xx_udc), * and accordingly can't correctly implement interface altsettings. */ -static inline int -usb_ep_clear_halt (struct usb_ep *ep) +static inline int usb_ep_clear_halt(struct usb_ep *ep) { - return ep->ops->set_halt (ep, 0); + return ep->ops->set_halt(ep, 0); } /** @@ -367,11 +365,10 @@ usb_ep_clear_halt (struct usb_ep *ep) * errno if the endpoint doesn't use a FIFO or doesn't support such * precise handling. */ -static inline int -usb_ep_fifo_status (struct usb_ep *ep) +static inline int usb_ep_fifo_status(struct usb_ep *ep) { if (ep->ops->fifo_status) - return ep->ops->fifo_status (ep); + return ep->ops->fifo_status(ep); else return -EOPNOTSUPP; } @@ -385,11 +382,10 @@ usb_ep_fifo_status (struct usb_ep *ep) * must never be used except when endpoint is not being used for any * protocol translation. */ -static inline void -usb_ep_fifo_flush (struct usb_ep *ep) +static inline void usb_ep_fifo_flush(struct usb_ep *ep) { if (ep->ops->fifo_flush) - ep->ops->fifo_flush (ep); + ep->ops->fifo_flush(ep); } @@ -469,10 +465,10 @@ struct usb_gadget { struct device dev; }; -static inline void set_gadget_data (struct usb_gadget *gadget, void *data) - { dev_set_drvdata (&gadget->dev, data); } -static inline void *get_gadget_data (struct usb_gadget *gadget) - { return dev_get_drvdata (&gadget->dev); } +static inline void set_gadget_data(struct usb_gadget *gadget, void *data) + { dev_set_drvdata(&gadget->dev, data); } +static inline void *get_gadget_data(struct usb_gadget *gadget) + { return dev_get_drvdata(&gadget->dev); } /* iterates the non-control endpoints; 'tmp' is a struct usb_ep pointer */ #define gadget_for_each_ep(tmp,gadget) \ @@ -511,7 +507,6 @@ static inline int gadget_is_otg(struct usb_gadget *g) #endif } - /** * usb_gadget_frame_number - returns the current frame number * @gadget: controller that reports the frame number @@ -519,9 +514,9 @@ static inline int gadget_is_otg(struct usb_gadget *g) * Returns the usb frame number, normally eleven bits from a SOF packet, * or negative errno if this device doesn't support this capability. */ -static inline int usb_gadget_frame_number (struct usb_gadget *gadget) +static inline int usb_gadget_frame_number(struct usb_gadget *gadget) { - return gadget->ops->get_frame (gadget); + return gadget->ops->get_frame(gadget); } /** @@ -537,11 +532,11 @@ static inline int usb_gadget_frame_number (struct usb_gadget *gadget) * even if OTG isn't otherwise in use. OTG devices may also start * remote wakeup even when hosts don't explicitly enable it. */ -static inline int usb_gadget_wakeup (struct usb_gadget *gadget) +static inline int usb_gadget_wakeup(struct usb_gadget *gadget) { if (!gadget->ops->wakeup) return -EOPNOTSUPP; - return gadget->ops->wakeup (gadget); + return gadget->ops->wakeup(gadget); } /** @@ -553,12 +548,11 @@ static inline int usb_gadget_wakeup (struct usb_gadget *gadget) * * returns zero on success, else negative errno. */ -static inline int -usb_gadget_set_selfpowered (struct usb_gadget *gadget) +static inline int usb_gadget_set_selfpowered(struct usb_gadget *gadget) { if (!gadget->ops->set_selfpowered) return -EOPNOTSUPP; - return gadget->ops->set_selfpowered (gadget, 1); + return gadget->ops->set_selfpowered(gadget, 1); } /** @@ -571,12 +565,11 @@ usb_gadget_set_selfpowered (struct usb_gadget *gadget) * * returns zero on success, else negative errno. */ -static inline int -usb_gadget_clear_selfpowered (struct usb_gadget *gadget) +static inline int usb_gadget_clear_selfpowered(struct usb_gadget *gadget) { if (!gadget->ops->set_selfpowered) return -EOPNOTSUPP; - return gadget->ops->set_selfpowered (gadget, 0); + return gadget->ops->set_selfpowered(gadget, 0); } /** @@ -591,12 +584,11 @@ usb_gadget_clear_selfpowered (struct usb_gadget *gadget) * * Returns zero on success, else negative errno. */ -static inline int -usb_gadget_vbus_connect(struct usb_gadget *gadget) +static inline int usb_gadget_vbus_connect(struct usb_gadget *gadget) { if (!gadget->ops->vbus_session) return -EOPNOTSUPP; - return gadget->ops->vbus_session (gadget, 1); + return gadget->ops->vbus_session(gadget, 1); } /** @@ -611,12 +603,11 @@ usb_gadget_vbus_connect(struct usb_gadget *gadget) * * Returns zero on success, else negative errno. */ -static inline int -usb_gadget_vbus_draw(struct usb_gadget *gadget, unsigned mA) +static inline int usb_gadget_vbus_draw(struct usb_gadget *gadget, unsigned mA) { if (!gadget->ops->vbus_draw) return -EOPNOTSUPP; - return gadget->ops->vbus_draw (gadget, mA); + return gadget->ops->vbus_draw(gadget, mA); } /** @@ -629,12 +620,11 @@ usb_gadget_vbus_draw(struct usb_gadget *gadget, unsigned mA) * * Returns zero on success, else negative errno. */ -static inline int -usb_gadget_vbus_disconnect(struct usb_gadget *gadget) +static inline int usb_gadget_vbus_disconnect(struct usb_gadget *gadget) { if (!gadget->ops->vbus_session) return -EOPNOTSUPP; - return gadget->ops->vbus_session (gadget, 0); + return gadget->ops->vbus_session(gadget, 0); } /** @@ -648,12 +638,11 @@ usb_gadget_vbus_disconnect(struct usb_gadget *gadget) * * Returns zero on success, else negative errno. */ -static inline int -usb_gadget_connect (struct usb_gadget *gadget) +static inline int usb_gadget_connect(struct usb_gadget *gadget) { if (!gadget->ops->pullup) return -EOPNOTSUPP; - return gadget->ops->pullup (gadget, 1); + return gadget->ops->pullup(gadget, 1); } /** @@ -671,16 +660,14 @@ usb_gadget_connect (struct usb_gadget *gadget) * * Returns zero on success, else negative errno. */ -static inline int -usb_gadget_disconnect (struct usb_gadget *gadget) +static inline int usb_gadget_disconnect(struct usb_gadget *gadget) { if (!gadget->ops->pullup) return -EOPNOTSUPP; - return gadget->ops->pullup (gadget, 0); + return gadget->ops->pullup(gadget, 0); } - /*-------------------------------------------------------------------------*/ /** @@ -764,7 +751,7 @@ struct usb_gadget_driver { void (*suspend)(struct usb_gadget *); void (*resume)(struct usb_gadget *); - // FIXME support safe rmmod + /* FIXME support safe rmmod */ struct device_driver driver; }; @@ -790,7 +777,7 @@ struct usb_gadget_driver { * the bind() functions will be in init sections. * This function must be called in a context that can sleep. */ -int usb_gadget_register_driver (struct usb_gadget_driver *driver); +int usb_gadget_register_driver(struct usb_gadget_driver *driver); /** * usb_gadget_unregister_driver - unregister a gadget driver @@ -805,7 +792,7 @@ int usb_gadget_register_driver (struct usb_gadget_driver *driver); * will in in exit sections, so may not be linked in some kernels. * This function must be called in a context that can sleep. */ -int usb_gadget_unregister_driver (struct usb_gadget_driver *driver); +int usb_gadget_unregister_driver(struct usb_gadget_driver *driver); /*-------------------------------------------------------------------------*/ @@ -838,7 +825,7 @@ struct usb_gadget_strings { }; /* put descriptor for string with that id into buf (buflen >= 256) */ -int usb_gadget_get_string (struct usb_gadget_strings *table, int id, u8 *buf); +int usb_gadget_get_string(struct usb_gadget_strings *table, int id, u8 *buf); /*-------------------------------------------------------------------------*/ @@ -856,10 +843,10 @@ int usb_gadget_config_buf(const struct usb_config_descriptor *config, /* utility wrapping a simple endpoint selection policy */ -extern struct usb_ep *usb_ep_autoconfig (struct usb_gadget *, +extern struct usb_ep *usb_ep_autoconfig(struct usb_gadget *, struct usb_endpoint_descriptor *) __devinit; -extern void usb_ep_autoconfig_reset (struct usb_gadget *) __devinit; +extern void usb_ep_autoconfig_reset(struct usb_gadget *) __devinit; #endif /* __KERNEL__ */ diff --git a/include/linux/usb/gadgetfs.h b/include/linux/usb/gadgetfs.h index 981e9ceb8fe7..c291ab1af747 100644 --- a/include/linux/usb/gadgetfs.h +++ b/include/linux/usb/gadgetfs.h @@ -36,7 +36,7 @@ enum usb_gadgetfs_event_type { GADGETFS_DISCONNECT, GADGETFS_SETUP, GADGETFS_SUSPEND, - // and likely more ! + /* and likely more ! */ }; /* NOTE: this structure must stay the same size and layout on @@ -44,15 +44,17 @@ enum usb_gadgetfs_event_type { */ struct usb_gadgetfs_event { union { - // NOP, DISCONNECT, SUSPEND: nothing - // ... some hardware can't report disconnection + /* NOP, DISCONNECT, SUSPEND: nothing + * ... some hardware can't report disconnection + */ - // CONNECT: just the speed + /* CONNECT: just the speed */ enum usb_device_speed speed; - // SETUP: packet; DATA phase i/o precedes next event - // (setup.bmRequestType & USB_DIR_IN) flags direction - // ... includes SET_CONFIGURATION, SET_INTERFACE + /* SETUP: packet; DATA phase i/o precedes next event + *(setup.bmRequestType & USB_DIR_IN) flags direction + * ... includes SET_CONFIGURATION, SET_INTERFACE + */ struct usb_ctrlrequest setup; } u; enum usb_gadgetfs_event_type type; @@ -73,14 +75,14 @@ struct usb_gadgetfs_event { * THIS returns how many bytes are "unclaimed" in the endpoint fifo * (needed for precise fault handling, when the hardware allows it) */ -#define GADGETFS_FIFO_STATUS _IO('g',1) +#define GADGETFS_FIFO_STATUS _IO('g', 1) /* discards any unclaimed data in the fifo. */ -#define GADGETFS_FIFO_FLUSH _IO('g',2) +#define GADGETFS_FIFO_FLUSH _IO('g', 2) /* resets endpoint halt+toggle; used to implement set_interface. * some hardware (like pxa2xx) can't support this. */ -#define GADGETFS_CLEAR_HALT _IO('g',3) +#define GADGETFS_CLEAR_HALT _IO('g', 3) #endif /* __LINUX_USB_GADGETFS_H */ diff --git a/include/linux/usb/iowarrior.h b/include/linux/usb/iowarrior.h index cbbe020a4f5c..de6f380e17a2 100644 --- a/include/linux/usb/iowarrior.h +++ b/include/linux/usb/iowarrior.h @@ -14,14 +14,23 @@ this information. */ struct iowarrior_info { - __u32 vendor; /* vendor id : supposed to be USB_VENDOR_ID_CODEMERCS in all cases */ - __u32 product; /* product id : depends on type of chip (USB_DEVICE_ID_CODEMERCS_XXXXX) */ - __u8 serial[9]; /* the serial number of our chip (if a serial-number is not available this is empty string) */ - __u32 revision; /* revision number of the chip */ - __u32 speed; /* USB-speed of the device (0=UNKNOWN, 1=LOW, 2=FULL 3=HIGH) */ - __u32 power; /* power consumption of the device in mA */ - __u32 if_num; /* the number of the endpoint */ - __u32 report_size; /* size of the data-packets on this interface */ + /* vendor id : supposed to be USB_VENDOR_ID_CODEMERCS in all cases */ + __u32 vendor; + /* product id : depends on type of chip (USB_DEVICE_ID_CODEMERCS_X) */ + __u32 product; + /* the serial number of our chip (if a serial-number is not available + * this is empty string) */ + __u8 serial[9]; + /* revision number of the chip */ + __u32 revision; + /* USB-speed of the device (0=UNKNOWN, 1=LOW, 2=FULL 3=HIGH) */ + __u32 speed; + /* power consumption of the device in mA */ + __u32 power; + /* the number of the endpoint */ + __u32 if_num; + /* size of the data-packets on this interface */ + __u32 report_size; }; /* diff --git a/include/linux/usb/isp116x.h b/include/linux/usb/isp116x.h index 436dd8a2b64a..67d2826f34fe 100644 --- a/include/linux/usb/isp116x.h +++ b/include/linux/usb/isp116x.h @@ -25,5 +25,5 @@ struct isp116x_platform_data { 300ns delay between access to ADDR_REG and DATA_REG OE, WE MUST NOT be changed during these intervals */ - void (*delay) (struct device * dev, int delay); + void (*delay) (struct device *dev, int delay); }; diff --git a/include/linux/usb/midi.h b/include/linux/usb/midi.h index 11a97d5ffd34..80624c562921 100644 --- a/include/linux/usb/midi.h +++ b/include/linux/usb/midi.h @@ -47,9 +47,9 @@ struct usb_ms_header_descriptor { /* 6.1.2.2 MIDI IN Jack Descriptor */ struct usb_midi_in_jack_descriptor { __u8 bLength; - __u8 bDescriptorType; // USB_DT_CS_INTERFACE - __u8 bDescriptorSubtype; // USB_MS_MIDI_IN_JACK - __u8 bJackType; // USB_MS_EMBEDDED/EXTERNAL + __u8 bDescriptorType; /* USB_DT_CS_INTERFACE */ + __u8 bDescriptorSubtype; /* USB_MS_MIDI_IN_JACK */ + __u8 bJackType; /* USB_MS_EMBEDDED/EXTERNAL */ __u8 bJackID; __u8 iJack; } __attribute__ ((packed)); @@ -64,12 +64,12 @@ struct usb_midi_source_pin { /* 6.1.2.3 MIDI OUT Jack Descriptor */ struct usb_midi_out_jack_descriptor { __u8 bLength; - __u8 bDescriptorType; // USB_DT_CS_INTERFACE - __u8 bDescriptorSubtype; // USB_MS_MIDI_OUT_JACK - __u8 bJackType; // USB_MS_EMBEDDED/EXTERNAL + __u8 bDescriptorType; /* USB_DT_CS_INTERFACE */ + __u8 bDescriptorSubtype; /* USB_MS_MIDI_OUT_JACK */ + __u8 bJackType; /* USB_MS_EMBEDDED/EXTERNAL */ __u8 bJackID; - __u8 bNrInputPins; // p - struct usb_midi_source_pin pins[]; // [p] + __u8 bNrInputPins; /* p */ + struct usb_midi_source_pin pins[]; /* [p] */ /*__u8 iJack; -- ommitted due to variable-sized pins[] */ } __attribute__ ((packed)); @@ -90,11 +90,11 @@ struct usb_midi_out_jack_descriptor_##p { \ /* 6.2.2 Class-Specific MS Bulk Data Endpoint Descriptor */ struct usb_ms_endpoint_descriptor { - __u8 bLength; // 4+n - __u8 bDescriptorType; // USB_DT_CS_ENDPOINT - __u8 bDescriptorSubtype; // USB_MS_GENERAL - __u8 bNumEmbMIDIJack; // n - __u8 baAssocJackID[]; // [n] + __u8 bLength; /* 4+n */ + __u8 bDescriptorType; /* USB_DT_CS_ENDPOINT */ + __u8 bDescriptorSubtype; /* USB_MS_GENERAL */ + __u8 bNumEmbMIDIJack; /* n */ + __u8 baAssocJackID[]; /* [n] */ } __attribute__ ((packed)); #define USB_DT_MS_ENDPOINT_SIZE(n) (4 + (n)) diff --git a/include/linux/usb/net2280.h b/include/linux/usb/net2280.h index c602f884f182..ec897cb844ab 100644 --- a/include/linux/usb/net2280.h +++ b/include/linux/usb/net2280.h @@ -37,7 +37,7 @@ /* main registers, BAR0 + 0x0000 */ struct net2280_regs { - // offset 0x0000 + /* offset 0x0000 */ u32 devinit; #define LOCAL_CLOCK_FREQUENCY 8 #define FORCE_PCI_RESET 7 @@ -61,7 +61,7 @@ struct net2280_regs { #define EEPROM_WRITE_DATA 0 u32 eeclkfreq; u32 _unused0; - // offset 0x0010 + /* offset 0x0010 */ u32 pciirqenb0; /* interrupt PCI master ... */ #define SETUP_PACKET_INTERRUPT_ENABLE 7 @@ -131,7 +131,7 @@ struct net2280_regs { #define RESUME_INTERRUPT_ENABLE 1 #define SOF_INTERRUPT_ENABLE 0 - // offset 0x0020 + /* offset 0x0020 */ u32 _unused1; u32 usbirqenb1; #define USB_INTERRUPT_ENABLE 31 @@ -195,7 +195,7 @@ struct net2280_regs { #define SUSPEND_REQUEST_CHANGE_INTERRUPT 2 #define RESUME_INTERRUPT 1 #define SOF_INTERRUPT 0 - // offset 0x0030 + /* offset 0x0030 */ u32 idxaddr; u32 idxdata; u32 fifoctl; @@ -204,7 +204,7 @@ struct net2280_regs { #define PCI_BASE2_SELECT 2 #define FIFO_CONFIGURATION_SELECT 0 u32 _unused2; - // offset 0x0040 + /* offset 0x0040 */ u32 memaddr; #define START 28 #define DIRECTION 27 @@ -213,7 +213,7 @@ struct net2280_regs { u32 memdata0; u32 memdata1; u32 _unused3; - // offset 0x0050 + /* offset 0x0050 */ u32 gpioctl; #define GPIO3_LED_SELECT 12 #define GPIO3_INTERRUPT_ENABLE 11 @@ -237,7 +237,7 @@ struct net2280_regs { /* usb control, BAR0 + 0x0080 */ struct net2280_usb_regs { - // offset 0x0080 + /* offset 0x0080 */ u32 stdrsp; #define STALL_UNSUPPORTED_REQUESTS 31 #define SET_TEST_MODE 16 @@ -275,7 +275,7 @@ struct net2280_usb_regs { #define PME_WAKEUP_ENABLE 2 #define DEVICE_REMOTE_WAKEUP_ENABLE 1 #define SELF_POWERED_STATUS 0 - // offset 0x0090 + /* offset 0x0090 */ u32 usbstat; #define HIGH_SPEED 7 #define FULL_SPEED 6 @@ -291,7 +291,7 @@ struct net2280_usb_regs { #define TERMINATION_SELECT 0 u32 setup0123; u32 setup4567; - // offset 0x0090 + /* offset 0x0090 */ u32 _unused0; u32 ouraddr; #define FORCE_IMMEDIATE 7 @@ -301,7 +301,7 @@ struct net2280_usb_regs { /* pci control, BAR0 + 0x0100 */ struct net2280_pci_regs { - // offset 0x0100 + /* offset 0x0100 */ u32 pcimstctl; #define PCI_ARBITER_PARK_SELECT 13 #define PCI_MULTI LEVEL_ARBITER 12 @@ -331,7 +331,7 @@ struct net2280_pci_regs { * that can be loaded into some of these registers. */ struct net2280_dma_regs { /* [11.7] */ - // offset 0x0180, 0x01a0, 0x01c0, 0x01e0, + /* offset 0x0180, 0x01a0, 0x01c0, 0x01e0, */ u32 dmactl; #define DMA_SCATTER_GATHER_DONE_INTERRUPT_ENABLE 25 #define DMA_CLEAR_COUNT_ENABLE 21 @@ -355,7 +355,7 @@ struct net2280_dma_regs { /* [11.7] */ #define DMA_ABORT 1 #define DMA_START 0 u32 _unused0 [2]; - // offset 0x0190, 0x01b0, 0x01d0, 0x01f0, + /* offset 0x0190, 0x01b0, 0x01d0, 0x01f0, */ u32 dmacount; #define VALID_BIT 31 #define DMA_DIRECTION 30 @@ -371,9 +371,9 @@ struct net2280_dma_regs { /* [11.7] */ /* dedicated endpoint registers, BAR0 + 0x0200 */ struct net2280_dep_regs { /* [11.8] */ - // offset 0x0200, 0x0210, 0x220, 0x230, 0x240 + /* offset 0x0200, 0x0210, 0x220, 0x230, 0x240 */ u32 dep_cfg; - // offset 0x0204, 0x0214, 0x224, 0x234, 0x244 + /* offset 0x0204, 0x0214, 0x224, 0x234, 0x244 */ u32 dep_rsp; u32 _unused [2]; } __attribute__ ((packed)); @@ -383,7 +383,7 @@ struct net2280_dep_regs { /* [11.8] */ * ep0 reserved for control; E and F have only 64 bytes of fifo */ struct net2280_ep_regs { /* [11.9] */ - // offset 0x0300, 0x0320, 0x0340, 0x0360, 0x0380, 0x03a0, 0x03c0 + /* offset 0x0300, 0x0320, 0x0340, 0x0360, 0x0380, 0x03a0, 0x03c0 */ u32 ep_cfg; #define ENDPOINT_BYTE_COUNT 16 #define ENDPOINT_ENABLE 10 @@ -435,7 +435,7 @@ struct net2280_ep_regs { /* [11.9] */ #define DATA_PACKET_TRANSMITTED_INTERRUPT 2 #define DATA_OUT_PING_TOKEN_INTERRUPT 1 #define DATA_IN_TOKEN_INTERRUPT 0 - // offset 0x0310, 0x0330, 0x0350, 0x0370, 0x0390, 0x03b0, 0x03d0 + /* offset 0x0310, 0x0330, 0x0350, 0x0370, 0x0390, 0x03b0, 0x03d0 */ u32 ep_avail; u32 ep_data; u32 _unused0 [2]; diff --git a/include/linux/usb/otg.h b/include/linux/usb/otg.h index 9897f7a818c5..e007074ebe41 100644 --- a/include/linux/usb/otg.h +++ b/include/linux/usb/otg.h @@ -1,4 +1,4 @@ -// include/linux/usb/otg.h +/* USB OTG (On The Go) defines */ /* * These APIs may be used between USB controllers. USB device drivers diff --git a/include/linux/usb/serial.h b/include/linux/usb/serial.h index 63b29b5332e6..21b4a1c6f585 100644 --- a/include/linux/usb/serial.h +++ b/include/linux/usb/serial.h @@ -20,7 +20,8 @@ #define SERIAL_TTY_MAJOR 188 /* Nice legal number now */ #define SERIAL_TTY_MINORS 255 /* loads of devices :) */ -#define MAX_NUM_PORTS 8 /* The maximum number of ports one device can grab at once */ +/* The maximum number of ports one device can grab at once */ +#define MAX_NUM_PORTS 8 /* parity check flag */ #define RELEVANT_IFLAG(iflag) (iflag & (IGNBRK|BRKINT|IGNPAR|PARMRK|INPCK)) @@ -61,29 +62,29 @@ * ports of a device. */ struct usb_serial_port { - struct usb_serial * serial; - struct tty_struct * tty; + struct usb_serial *serial; + struct tty_struct *tty; spinlock_t lock; struct mutex mutex; unsigned char number; - unsigned char * interrupt_in_buffer; - struct urb * interrupt_in_urb; + unsigned char *interrupt_in_buffer; + struct urb *interrupt_in_urb; __u8 interrupt_in_endpointAddress; - unsigned char * interrupt_out_buffer; + unsigned char *interrupt_out_buffer; int interrupt_out_size; - struct urb * interrupt_out_urb; + struct urb *interrupt_out_urb; __u8 interrupt_out_endpointAddress; - unsigned char * bulk_in_buffer; + unsigned char *bulk_in_buffer; int bulk_in_size; - struct urb * read_urb; + struct urb *read_urb; __u8 bulk_in_endpointAddress; - unsigned char * bulk_out_buffer; + unsigned char *bulk_out_buffer; int bulk_out_size; - struct urb * write_urb; + struct urb *write_urb; int write_urb_busy; __u8 bulk_out_endpointAddress; @@ -98,12 +99,13 @@ struct usb_serial_port { #define to_usb_serial_port(d) container_of(d, struct usb_serial_port, dev) /* get and set the port private data pointer helper functions */ -static inline void *usb_get_serial_port_data (struct usb_serial_port *port) +static inline void *usb_get_serial_port_data(struct usb_serial_port *port) { return dev_get_drvdata(&port->dev); } -static inline void usb_set_serial_port_data (struct usb_serial_port *port, void *data) +static inline void usb_set_serial_port_data(struct usb_serial_port *port, + void *data) { dev_set_drvdata(&port->dev, data); } @@ -126,9 +128,9 @@ static inline void usb_set_serial_port_data (struct usb_serial_port *port, void * usb_set_serial_data() to access this. */ struct usb_serial { - struct usb_device * dev; - struct usb_serial_driver * type; - struct usb_interface * interface; + struct usb_device *dev; + struct usb_serial_driver *type; + struct usb_interface *interface; unsigned char disconnected; unsigned char minor; unsigned char num_ports; @@ -137,30 +139,30 @@ struct usb_serial { char num_interrupt_out; char num_bulk_in; char num_bulk_out; - struct usb_serial_port * port[MAX_NUM_PORTS]; + struct usb_serial_port *port[MAX_NUM_PORTS]; struct kref kref; struct mutex disc_mutex; - void * private; + void *private; }; #define to_usb_serial(d) container_of(d, struct usb_serial, kref) #define NUM_DONT_CARE 99 /* get and set the serial private data pointer helper functions */ -static inline void *usb_get_serial_data (struct usb_serial *serial) +static inline void *usb_get_serial_data(struct usb_serial *serial) { return serial->private; } -static inline void usb_set_serial_data (struct usb_serial *serial, void *data) +static inline void usb_set_serial_data(struct usb_serial *serial, void *data) { serial->private = data; } /** * usb_serial_driver - describes a usb serial driver - * @description: pointer to a string that describes this driver. This string used - * in the syslog messages when a device is inserted or removed. + * @description: pointer to a string that describes this driver. This string + * used in the syslog messages when a device is inserted or removed. * @id_table: pointer to a list of usb_device_id structures that define all * of the devices this structure can support. * @num_interrupt_in: If a device doesn't have this many interrupt-in @@ -221,82 +223,91 @@ struct usb_serial_driver { struct usb_driver *usb_driver; struct usb_dynids dynids; - int (*probe) (struct usb_serial *serial, const struct usb_device_id *id); - int (*attach) (struct usb_serial *serial); + int (*probe)(struct usb_serial *serial, const struct usb_device_id *id); + int (*attach)(struct usb_serial *serial); int (*calc_num_ports) (struct usb_serial *serial); - void (*shutdown) (struct usb_serial *serial); + void (*shutdown)(struct usb_serial *serial); - int (*port_probe) (struct usb_serial_port *port); - int (*port_remove) (struct usb_serial_port *port); + int (*port_probe)(struct usb_serial_port *port); + int (*port_remove)(struct usb_serial_port *port); - int (*suspend) (struct usb_serial *serial, pm_message_t message); - int (*resume) (struct usb_serial *serial); + int (*suspend)(struct usb_serial *serial, pm_message_t message); + int (*resume)(struct usb_serial *serial); /* serial function calls */ - int (*open) (struct usb_serial_port *port, struct file * filp); - void (*close) (struct usb_serial_port *port, struct file * filp); - int (*write) (struct usb_serial_port *port, const unsigned char *buf, int count); - int (*write_room) (struct usb_serial_port *port); - int (*ioctl) (struct usb_serial_port *port, struct file * file, unsigned int cmd, unsigned long arg); - void (*set_termios) (struct usb_serial_port *port, struct ktermios * old); - void (*break_ctl) (struct usb_serial_port *port, int break_state); - int (*chars_in_buffer) (struct usb_serial_port *port); - void (*throttle) (struct usb_serial_port *port); - void (*unthrottle) (struct usb_serial_port *port); - int (*tiocmget) (struct usb_serial_port *port, struct file *file); - int (*tiocmset) (struct usb_serial_port *port, struct file *file, unsigned int set, unsigned int clear); + int (*open)(struct usb_serial_port *port, struct file *filp); + void (*close)(struct usb_serial_port *port, struct file *filp); + int (*write)(struct usb_serial_port *port, const unsigned char *buf, + int count); + int (*write_room)(struct usb_serial_port *port); + int (*ioctl)(struct usb_serial_port *port, struct file *file, + unsigned int cmd, unsigned long arg); + void (*set_termios)(struct usb_serial_port *port, struct ktermios *old); + void (*break_ctl)(struct usb_serial_port *port, int break_state); + int (*chars_in_buffer)(struct usb_serial_port *port); + void (*throttle)(struct usb_serial_port *port); + void (*unthrottle)(struct usb_serial_port *port); + int (*tiocmget)(struct usb_serial_port *port, struct file *file); + int (*tiocmset)(struct usb_serial_port *port, struct file *file, + unsigned int set, unsigned int clear); void (*read_int_callback)(struct urb *urb); void (*write_int_callback)(struct urb *urb); void (*read_bulk_callback)(struct urb *urb); void (*write_bulk_callback)(struct urb *urb); }; -#define to_usb_serial_driver(d) container_of(d, struct usb_serial_driver, driver) +#define to_usb_serial_driver(d) \ + container_of(d, struct usb_serial_driver, driver) extern int usb_serial_register(struct usb_serial_driver *driver); extern void usb_serial_deregister(struct usb_serial_driver *driver); extern void usb_serial_port_softint(struct usb_serial_port *port); -extern int usb_serial_probe(struct usb_interface *iface, const struct usb_device_id *id); +extern int usb_serial_probe(struct usb_interface *iface, + const struct usb_device_id *id); extern void usb_serial_disconnect(struct usb_interface *iface); extern int usb_serial_suspend(struct usb_interface *intf, pm_message_t message); extern int usb_serial_resume(struct usb_interface *intf); -extern int ezusb_writememory (struct usb_serial *serial, int address, unsigned char *data, int length, __u8 bRequest); -extern int ezusb_set_reset (struct usb_serial *serial, unsigned char reset_bit); +extern int ezusb_writememory(struct usb_serial *serial, int address, + unsigned char *data, int length, __u8 bRequest); +extern int ezusb_set_reset(struct usb_serial *serial, unsigned char reset_bit); /* USB Serial console functions */ #ifdef CONFIG_USB_SERIAL_CONSOLE -extern void usb_serial_console_init (int debug, int minor); -extern void usb_serial_console_exit (void); +extern void usb_serial_console_init(int debug, int minor); +extern void usb_serial_console_exit(void); extern void usb_serial_console_disconnect(struct usb_serial *serial); #else -static inline void usb_serial_console_init (int debug, int minor) { } -static inline void usb_serial_console_exit (void) { } +static inline void usb_serial_console_init(int debug, int minor) { } +static inline void usb_serial_console_exit(void) { } static inline void usb_serial_console_disconnect(struct usb_serial *serial) {} #endif /* Functions needed by other parts of the usbserial core */ -extern struct usb_serial *usb_serial_get_by_index (unsigned int minor); +extern struct usb_serial *usb_serial_get_by_index(unsigned int minor); extern void usb_serial_put(struct usb_serial *serial); -extern int usb_serial_generic_open (struct usb_serial_port *port, struct file *filp); -extern int usb_serial_generic_write (struct usb_serial_port *port, const unsigned char *buf, int count); -extern void usb_serial_generic_close (struct usb_serial_port *port, struct file *filp); -extern int usb_serial_generic_resume (struct usb_serial *serial); -extern int usb_serial_generic_write_room (struct usb_serial_port *port); -extern int usb_serial_generic_chars_in_buffer (struct usb_serial_port *port); -extern void usb_serial_generic_read_bulk_callback (struct urb *urb); -extern void usb_serial_generic_write_bulk_callback (struct urb *urb); -extern void usb_serial_generic_throttle (struct usb_serial_port *port); -extern void usb_serial_generic_unthrottle (struct usb_serial_port *port); -extern void usb_serial_generic_shutdown (struct usb_serial *serial); -extern int usb_serial_generic_register (int debug); -extern void usb_serial_generic_deregister (void); - -extern int usb_serial_bus_register (struct usb_serial_driver *device); -extern void usb_serial_bus_deregister (struct usb_serial_driver *device); +extern int usb_serial_generic_open(struct usb_serial_port *port, + struct file *filp); +extern int usb_serial_generic_write(struct usb_serial_port *port, + const unsigned char *buf, int count); +extern void usb_serial_generic_close(struct usb_serial_port *port, + struct file *filp); +extern int usb_serial_generic_resume(struct usb_serial *serial); +extern int usb_serial_generic_write_room(struct usb_serial_port *port); +extern int usb_serial_generic_chars_in_buffer(struct usb_serial_port *port); +extern void usb_serial_generic_read_bulk_callback(struct urb *urb); +extern void usb_serial_generic_write_bulk_callback(struct urb *urb); +extern void usb_serial_generic_throttle(struct usb_serial_port *port); +extern void usb_serial_generic_unthrottle(struct usb_serial_port *port); +extern void usb_serial_generic_shutdown(struct usb_serial *serial); +extern int usb_serial_generic_register(int debug); +extern void usb_serial_generic_deregister(void); + +extern int usb_serial_bus_register(struct usb_serial_driver *device); +extern void usb_serial_bus_deregister(struct usb_serial_driver *device); extern struct usb_serial_driver usb_serial_generic_device; extern struct bus_type usb_serial_bus_type; @@ -310,16 +321,22 @@ static inline void usb_serial_debug_data(int debug, int i; if (debug) { - dev_printk(KERN_DEBUG, dev, "%s - length = %d, data = ", function, size); + dev_printk(KERN_DEBUG, dev, "%s - length = %d, data = ", + function, size); for (i = 0; i < size; ++i) - printk ("%.2x ", data[i]); - printk ("\n"); + printk("%.2x ", data[i]); + printk("\n"); } } /* Use our own dbg macro */ #undef dbg -#define dbg(format, arg...) do { if (debug) printk(KERN_DEBUG "%s: " format "\n" , __FILE__ , ## arg); } while (0) +#define dbg(format, arg...) \ + do { \ + if (debug) \ + printk(KERN_DEBUG "%s: " format "\n" , __FILE__ , \ + ## arg); \ + } while (0) diff --git a/include/linux/usb/sl811.h b/include/linux/usb/sl811.h index 397ee3b3d7f3..877373da410d 100644 --- a/include/linux/usb/sl811.h +++ b/include/linux/usb/sl811.h @@ -19,8 +19,8 @@ struct sl811_platform_data { /* pulse sl811 nRST (probably with a GPIO) */ void (*reset)(struct device *dev); - // some boards need something like these: - // int (*check_overcurrent)(struct device *dev); - // void (*clock_enable)(struct device *dev, int is_on); + /* some boards need something like these: */ + /* int (*check_overcurrent)(struct device *dev); */ + /* void (*clock_enable)(struct device *dev, int is_on); */ }; -- cgit v1.2.3 From 84cca820ee798a6bc8b01a4ccc9548943bc41f7f Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Wed, 30 Jan 2008 15:21:33 -0800 Subject: USB: fix codingstyle issues in drivers/usb/core/*.h Fixes a number of coding style issues in the USB internal header files. Signed-off-by: Greg Kroah-Hartman --- drivers/usb/core/hcd.h | 90 ++++++++++++++++++++-------------------- drivers/usb/core/hub.h | 18 ++++---- drivers/usb/core/otg_whitelist.h | 6 +-- drivers/usb/core/usb.h | 21 +++++----- 4 files changed, 68 insertions(+), 67 deletions(-) diff --git a/drivers/usb/core/hcd.h b/drivers/usb/core/hcd.h index 0095641c51fa..2d1c3d5e47b8 100644 --- a/drivers/usb/core/hcd.h +++ b/drivers/usb/core/hcd.h @@ -125,7 +125,7 @@ struct usb_hcd { /* more shared queuing code would be good; it should support * smarter scheduling, handle transaction translators, etc; - * input size of periodic table to an interrupt scheduler. + * input size of periodic table to an interrupt scheduler. * (ohci 32, uhci 1024, ehci 256/512/1024). */ @@ -133,16 +133,16 @@ struct usb_hcd { * this structure. */ unsigned long hcd_priv[0] - __attribute__ ((aligned (sizeof(unsigned long)))); + __attribute__ ((aligned(sizeof(unsigned long)))); }; /* 2.4 does this a bit differently ... */ -static inline struct usb_bus *hcd_to_bus (struct usb_hcd *hcd) +static inline struct usb_bus *hcd_to_bus(struct usb_hcd *hcd) { return &hcd->self; } -static inline struct usb_hcd *bus_to_hcd (struct usb_bus *bus) +static inline struct usb_hcd *bus_to_hcd(struct usb_bus *bus) { return container_of(bus, struct usb_hcd, self); } @@ -202,18 +202,18 @@ struct hc_driver { struct usb_host_endpoint *ep); /* root hub support */ - int (*hub_status_data) (struct usb_hcd *hcd, char *buf); - int (*hub_control) (struct usb_hcd *hcd, + int (*hub_status_data) (struct usb_hcd *hcd, char *buf); + int (*hub_control) (struct usb_hcd *hcd, u16 typeReq, u16 wValue, u16 wIndex, char *buf, u16 wLength); - int (*bus_suspend)(struct usb_hcd *); - int (*bus_resume)(struct usb_hcd *); - int (*start_port_reset)(struct usb_hcd *, unsigned port_num); - void (*hub_irq_enable)(struct usb_hcd *); + int (*bus_suspend)(struct usb_hcd *); + int (*bus_resume)(struct usb_hcd *); + int (*start_port_reset)(struct usb_hcd *, unsigned port_num); + void (*hub_irq_enable)(struct usb_hcd *); /* Needed only if port-change IRQs are level-triggered */ /* force handover of high-speed port to full-speed companion */ - void (*relinquish_port)(struct usb_hcd *, int); + void (*relinquish_port)(struct usb_hcd *, int); }; extern int usb_hcd_link_urb_to_ep(struct usb_hcd *hcd, struct urb *urb); @@ -221,56 +221,56 @@ extern int usb_hcd_check_unlink_urb(struct usb_hcd *hcd, struct urb *urb, int status); extern void usb_hcd_unlink_urb_from_ep(struct usb_hcd *hcd, struct urb *urb); -extern int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags); -extern int usb_hcd_unlink_urb (struct urb *urb, int status); +extern int usb_hcd_submit_urb(struct urb *urb, gfp_t mem_flags); +extern int usb_hcd_unlink_urb(struct urb *urb, int status); extern void usb_hcd_giveback_urb(struct usb_hcd *hcd, struct urb *urb, int status); extern void usb_hcd_flush_endpoint(struct usb_device *udev, struct usb_host_endpoint *ep); extern void usb_hcd_disable_endpoint(struct usb_device *udev, struct usb_host_endpoint *ep); -extern int usb_hcd_get_frame_number (struct usb_device *udev); +extern int usb_hcd_get_frame_number(struct usb_device *udev); -extern struct usb_hcd *usb_create_hcd (const struct hc_driver *driver, +extern struct usb_hcd *usb_create_hcd(const struct hc_driver *driver, struct device *dev, char *bus_name); -extern struct usb_hcd *usb_get_hcd (struct usb_hcd *hcd); -extern void usb_put_hcd (struct usb_hcd *hcd); +extern struct usb_hcd *usb_get_hcd(struct usb_hcd *hcd); +extern void usb_put_hcd(struct usb_hcd *hcd); extern int usb_add_hcd(struct usb_hcd *hcd, unsigned int irqnum, unsigned long irqflags); extern void usb_remove_hcd(struct usb_hcd *hcd); struct platform_device; -extern void usb_hcd_platform_shutdown(struct platform_device* dev); +extern void usb_hcd_platform_shutdown(struct platform_device *dev); #ifdef CONFIG_PCI struct pci_dev; struct pci_device_id; -extern int usb_hcd_pci_probe (struct pci_dev *dev, +extern int usb_hcd_pci_probe(struct pci_dev *dev, const struct pci_device_id *id); -extern void usb_hcd_pci_remove (struct pci_dev *dev); +extern void usb_hcd_pci_remove(struct pci_dev *dev); #ifdef CONFIG_PM -extern int usb_hcd_pci_suspend (struct pci_dev *dev, pm_message_t state); -extern int usb_hcd_pci_resume (struct pci_dev *dev); +extern int usb_hcd_pci_suspend(struct pci_dev *dev, pm_message_t state); +extern int usb_hcd_pci_resume(struct pci_dev *dev); #endif /* CONFIG_PM */ -extern void usb_hcd_pci_shutdown (struct pci_dev *dev); +extern void usb_hcd_pci_shutdown(struct pci_dev *dev); #endif /* CONFIG_PCI */ /* pci-ish (pdev null is ok) buffer alloc/mapping support */ -int hcd_buffer_create (struct usb_hcd *hcd); -void hcd_buffer_destroy (struct usb_hcd *hcd); +int hcd_buffer_create(struct usb_hcd *hcd); +void hcd_buffer_destroy(struct usb_hcd *hcd); -void *hcd_buffer_alloc (struct usb_bus *bus, size_t size, +void *hcd_buffer_alloc(struct usb_bus *bus, size_t size, gfp_t mem_flags, dma_addr_t *dma); -void hcd_buffer_free (struct usb_bus *bus, size_t size, +void hcd_buffer_free(struct usb_bus *bus, size_t size, void *addr, dma_addr_t dma); /* generic bus glue, needed for host controllers that don't use PCI */ -extern irqreturn_t usb_hcd_irq (int irq, void *__hcd); +extern irqreturn_t usb_hcd_irq(int irq, void *__hcd); -extern void usb_hc_died (struct usb_hcd *hcd); +extern void usb_hc_died(struct usb_hcd *hcd); extern void usb_hcd_poll_rh_status(struct usb_hcd *hcd); /* -------------------------------------------------------------------------- */ @@ -323,9 +323,9 @@ extern void usb_destroy_configuration(struct usb_device *dev); * Generic bandwidth allocation constants/support */ #define FRAME_TIME_USECS 1000L -#define BitTime(bytecount) (7 * 8 * bytecount / 6) /* with integer truncation */ +#define BitTime(bytecount) (7 * 8 * bytecount / 6) /* with integer truncation */ /* Trying not to use worst-case bit-stuffing - of (7/6 * 8 * bytecount) = 9.33 * bytecount */ + * of (7/6 * 8 * bytecount) = 9.33 * bytecount */ /* bytecount = data payload byte count */ #define NS_TO_US(ns) ((ns + 500L) / 1000L) @@ -337,9 +337,9 @@ extern void usb_destroy_configuration(struct usb_device *dev); */ #define BW_HOST_DELAY 1000L /* nanoseconds */ #define BW_HUB_LS_SETUP 333L /* nanoseconds */ - /* 4 full-speed bit times (est.) */ + /* 4 full-speed bit times (est.) */ -#define FRAME_TIME_BITS 12000L /* frame = 1 millisecond */ +#define FRAME_TIME_BITS 12000L /* frame = 1 millisecond */ #define FRAME_TIME_MAX_BITS_ALLOC (90L * FRAME_TIME_BITS / 100L) #define FRAME_TIME_MAX_USECS_ALLOC (90L * FRAME_TIME_USECS / 100L) @@ -349,16 +349,16 @@ extern void usb_destroy_configuration(struct usb_device *dev); * to preallocate bandwidth) */ #define USB2_HOST_DELAY 5 /* nsec, guess */ -#define HS_NSECS(bytes) ( ((55 * 8 * 2083) \ +#define HS_NSECS(bytes) (((55 * 8 * 2083) \ + (2083UL * (3 + BitTime(bytes))))/1000 \ + USB2_HOST_DELAY) -#define HS_NSECS_ISO(bytes) ( ((38 * 8 * 2083) \ +#define HS_NSECS_ISO(bytes) (((38 * 8 * 2083) \ + (2083UL * (3 + BitTime(bytes))))/1000 \ + USB2_HOST_DELAY) #define HS_USECS(bytes) NS_TO_US (HS_NSECS(bytes)) #define HS_USECS_ISO(bytes) NS_TO_US (HS_NSECS_ISO(bytes)) -extern long usb_calc_bus_time (int speed, int is_input, +extern long usb_calc_bus_time(int speed, int is_input, int isoc, int bytecount); /*-------------------------------------------------------------------------*/ @@ -374,16 +374,16 @@ extern struct list_head usb_bus_list; extern struct mutex usb_bus_list_lock; extern wait_queue_head_t usb_kill_urb_queue; -extern void usb_enable_root_hub_irq (struct usb_bus *bus); +extern void usb_enable_root_hub_irq(struct usb_bus *bus); -extern int usb_find_interface_driver (struct usb_device *dev, +extern int usb_find_interface_driver(struct usb_device *dev, struct usb_interface *interface); #define usb_endpoint_out(ep_dir) (!((ep_dir) & USB_DIR_IN)) #ifdef CONFIG_PM -extern void usb_hcd_resume_root_hub (struct usb_hcd *hcd); -extern void usb_root_hub_lost_power (struct usb_device *rhdev); +extern void usb_hcd_resume_root_hub(struct usb_hcd *hcd); +extern void usb_root_hub_lost_power(struct usb_device *rhdev); extern int hcd_bus_suspend(struct usb_device *rhdev); extern int hcd_bus_resume(struct usb_device *rhdev); #else @@ -403,13 +403,13 @@ static inline void usb_hcd_resume_root_hub(struct usb_hcd *hcd) * these are expected to be called from the USB core/hub thread * with the kernel lock held */ -extern void usbfs_update_special (void); +extern void usbfs_update_special(void); extern int usbfs_init(void); extern void usbfs_cleanup(void); #else /* CONFIG_USB_DEVICEFS */ -static inline void usbfs_update_special (void) {} +static inline void usbfs_update_special(void) {} static inline int usbfs_init(void) { return 0; } static inline void usbfs_cleanup(void) { } @@ -464,7 +464,7 @@ static inline void usbmon_urb_complete(struct usb_bus *bus, struct urb *urb, /*-------------------------------------------------------------------------*/ /* hub.h ... DeviceRemovable in 2.4.2-ac11, gone in 2.4.10 */ -// bleech -- resurfaced in 2.4.11 or 2.4.12 +/* bleech -- resurfaced in 2.4.11 or 2.4.12 */ #define bitmap DeviceRemovable @@ -472,8 +472,8 @@ static inline void usbmon_urb_complete(struct usb_bus *bus, struct urb *urb, /* random stuff */ -#define RUN_CONTEXT (in_irq () ? "in_irq" \ - : (in_interrupt () ? "in_interrupt" : "can sleep")) +#define RUN_CONTEXT (in_irq() ? "in_irq" \ + : (in_interrupt() ? "in_interrupt" : "can sleep")) /* This rwsem is for use only by the hub driver and ehci-hcd. 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 @@ #define USB_PORT_FEAT_TEST 21 #define USB_PORT_FEAT_INDICATOR 22 -/* +/* * Hub Status and Hub Change results * See USB 2.0 spec Table 11-19 and Table 11-20 */ struct usb_port_status { __le16 wPortStatus; - __le16 wPortChange; + __le16 wPortChange; } __attribute__ ((packed)); -/* +/* * wPortStatus bit field * See USB 2.0 spec Table 11-21 */ @@ -81,7 +81,7 @@ struct usb_port_status { #define USB_PORT_STAT_INDICATOR 0x1000 /* bits 13 to 15 are reserved */ -/* +/* * wPortChange bit field * See USB 2.0 spec Table 11-22 * Bits 0 to 4 shown, bits 5 to 15 are reserved @@ -93,7 +93,7 @@ struct usb_port_status { #define USB_PORT_STAT_C_RESET 0x0010 /* - * wHubCharacteristics (masks) + * wHubCharacteristics (masks) * See USB 2.0 spec Table 11-13, offset 3 */ #define HUB_CHAR_LPSM 0x0003 /* D1 .. D0 */ @@ -119,8 +119,8 @@ struct usb_hub_status { #define HUB_CHANGE_OVERCURRENT 0x0002 -/* - * Hub descriptor +/* + * Hub descriptor * See USB 2.0 spec Table 11-13 */ @@ -134,7 +134,7 @@ struct usb_hub_descriptor { __le16 wHubCharacteristics; __u8 bPwrOn2PwrGood; __u8 bHubContrCurrent; - /* add 1 bit for hub status change; round to bytes */ + /* add 1 bit for hub status change; round to bytes */ __u8 DeviceRemovable[(USB_MAXCHILDREN + 1 + 7) / 8]; __u8 PortPwrCtrlMask[(USB_MAXCHILDREN + 1 + 7) / 8]; } __attribute__ ((packed)); @@ -190,6 +190,6 @@ struct usb_tt_clear { u16 devinfo; }; -extern void usb_hub_tt_clear_buffer (struct usb_device *dev, int pipe); +extern void usb_hub_tt_clear_buffer(struct usb_device *dev, int pipe); #endif /* __LINUX_HUB_H */ 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 @@ * mostly use of USB_DEVICE() or USB_DEVICE_VER() entries.. * * YOU _SHOULD_ CHANGE THIS LIST TO MATCH YOUR PRODUCT AND ITS TESTING! - */ + */ static struct usb_device_id whitelist_table [] = { @@ -55,7 +55,7 @@ static int is_targeted(struct usb_device *dev) return 1; /* HNP test device is _never_ targeted (see OTG spec 6.6.6) */ - if ((le16_to_cpu(dev->descriptor.idVendor) == 0x1a0a && + if ((le16_to_cpu(dev->descriptor.idVendor) == 0x1a0a && le16_to_cpu(dev->descriptor.idProduct) == 0xbadd)) return 0; @@ -86,7 +86,7 @@ static int is_targeted(struct usb_device *dev) continue; if ((id->match_flags & USB_DEVICE_ID_MATCH_DEV_SUBCLASS) && - (id->bDeviceSubClass!= dev->descriptor.bDeviceSubClass)) + (id->bDeviceSubClass != dev->descriptor.bDeviceSubClass)) continue; if ((id->match_flags & USB_DEVICE_ID_MATCH_DEV_PROTOCOL) && 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 @@ /* Functions local to drivers/usb/core/ */ -extern int usb_create_sysfs_dev_files (struct usb_device *dev); -extern void usb_remove_sysfs_dev_files (struct usb_device *dev); -extern int usb_create_sysfs_intf_files (struct usb_interface *intf); -extern void usb_remove_sysfs_intf_files (struct usb_interface *intf); -extern int usb_create_ep_files(struct device *parent, struct usb_host_endpoint *endpoint, +extern int usb_create_sysfs_dev_files(struct usb_device *dev); +extern void usb_remove_sysfs_dev_files(struct usb_device *dev); +extern int usb_create_sysfs_intf_files(struct usb_interface *intf); +extern void usb_remove_sysfs_intf_files(struct usb_interface *intf); +extern int usb_create_ep_files(struct device *parent, + struct usb_host_endpoint *endpoint, struct usb_device *udev); extern void usb_remove_ep_files(struct usb_host_endpoint *endpoint); extern void usb_enable_endpoint(struct usb_device *dev, struct usb_host_endpoint *ep); -extern void usb_disable_endpoint (struct usb_device *dev, unsigned int epaddr); -extern void usb_disable_interface (struct usb_device *dev, +extern void usb_disable_endpoint(struct usb_device *dev, unsigned int epaddr); +extern void usb_disable_interface(struct usb_device *dev, struct usb_interface *intf); extern void usb_release_interface_cache(struct kref *ref); -extern void usb_disable_device (struct usb_device *dev, int skip_ep0); -extern int usb_deauthorize_device (struct usb_device *); -extern int usb_authorize_device (struct usb_device *); +extern void usb_disable_device(struct usb_device *dev, int skip_ep0); +extern int usb_deauthorize_device(struct usb_device *); +extern int usb_authorize_device(struct usb_device *); extern void usb_detect_quirks(struct usb_device *udev); extern int usb_get_device_descriptor(struct usb_device *dev, -- cgit v1.2.3 From 376c0d3f1413d5cb6a146fb2fea127b96bd512aa Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Wed, 30 Jan 2008 15:21:33 -0800 Subject: USB: fix codingstyle issues in drivers/usb/core/devices.c Fixes a number of coding style issues in the devices.c file. Signed-off-by: Greg Kroah-Hartman --- drivers/usb/core/devices.c | 154 ++++++++++++++++++++++++--------------------- 1 file changed, 82 insertions(+), 72 deletions(-) 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 = static const char *format_bandwidth = /* B: Alloc=ddd/ddd us (xx%), #Int=ddd, #Iso=ddd */ "B: Alloc=%3d/%3d us (%2d%%), #Int=%3d, #Iso=%3d\n"; - + static const char *format_device1 = /* D: Ver=xx.xx Cls=xx(sssss) Sub=xx Prot=xx MxPS=dd #Cfgs=dd */ "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 = static const char *format_config = /* C: #Ifs=dd Cfg#=dd Atr=xx MPwr=dddmA */ "C:%c #Ifs=%2d Cfg#=%2d Atr=%02x MxPwr=%3dmA\n"; - + static const char *format_iad = /* A: FirstIf#=dd IfCount=dd Cls=xx(sssss) Sub=xx Prot=xx */ "A: FirstIf#=%2d IfCount=%2d Cls=%02x(%-5s) Sub=%02x Prot=%02x\n"; @@ -122,7 +122,7 @@ static const char *format_endpt = */ static DECLARE_WAIT_QUEUE_HEAD(deviceconndiscwq); -static unsigned int conndiscevcnt = 0; +static unsigned int conndiscevcnt; /* this struct stores the poll state for /devices pollers */ struct usb_device_status { @@ -172,12 +172,8 @@ static const char *class_decode(const int class) return clas_info[ix].class_name; } -static char *usb_dump_endpoint_descriptor( - int speed, - char *start, - char *end, - const struct usb_endpoint_descriptor *desc -) +static char *usb_dump_endpoint_descriptor(int speed, char *start, char *end, + const struct usb_endpoint_descriptor *desc) { char dir, unit, *type; unsigned interval, bandwidth = 1; @@ -235,22 +231,24 @@ static char *usb_dump_endpoint_descriptor( start += sprintf(start, format_endpt, desc->bEndpointAddress, dir, desc->bmAttributes, type, - (le16_to_cpu(desc->wMaxPacketSize) & 0x07ff) * bandwidth, + (le16_to_cpu(desc->wMaxPacketSize) & 0x07ff) * + bandwidth, interval, unit); return start; } static char *usb_dump_interface_descriptor(char *start, char *end, - const struct usb_interface_cache *intfc, - const struct usb_interface *iface, - int setno) + const struct usb_interface_cache *intfc, + const struct usb_interface *iface, + int setno) { - const struct usb_interface_descriptor *desc = &intfc->altsetting[setno].desc; + const struct usb_interface_descriptor *desc; const char *driver_name = ""; int active = 0; if (start > end) return start; + desc = &intfc->altsetting[setno].desc; if (iface) { driver_name = (iface->dev.driver ? iface->dev.driver->name @@ -270,14 +268,10 @@ static char *usb_dump_interface_descriptor(char *start, char *end, return start; } -static char *usb_dump_interface( - int speed, - char *start, - char *end, - const struct usb_interface_cache *intfc, - const struct usb_interface *iface, - int setno -) { +static char *usb_dump_interface(int speed, char *start, char *end, + const struct usb_interface_cache *intfc, + const struct usb_interface *iface, int setno) +{ const struct usb_host_interface *desc = &intfc->altsetting[setno]; int i; @@ -292,7 +286,7 @@ static char *usb_dump_interface( } static char *usb_dump_iad_descriptor(char *start, char *end, - const struct usb_interface_assoc_descriptor *iad) + const struct usb_interface_assoc_descriptor *iad) { if (start > end) return start; @@ -311,13 +305,15 @@ static char *usb_dump_iad_descriptor(char *start, char *end, * 1. marking active interface altsettings (code lists all, but should mark * which ones are active, if any) */ - -static char *usb_dump_config_descriptor(char *start, char *end, const struct usb_config_descriptor *desc, int active) +static char *usb_dump_config_descriptor(char *start, char *end, + const struct usb_config_descriptor *desc, + int active) { if (start > end) return start; start += sprintf(start, format_config, - active ? '*' : ' ', /* mark active/actual/current cfg. */ + /* mark active/actual/current cfg. */ + active ? '*' : ' ', desc->bNumInterfaces, desc->bConfigurationValue, desc->bmAttributes, @@ -325,13 +321,8 @@ static char *usb_dump_config_descriptor(char *start, char *end, const struct usb return start; } -static char *usb_dump_config ( - int speed, - char *start, - char *end, - const struct usb_host_config *config, - int active -) +static char *usb_dump_config(int speed, char *start, char *end, + const struct usb_host_config *config, int active) { int i, j; struct usb_interface_cache *intfc; @@ -339,7 +330,8 @@ static char *usb_dump_config ( if (start > end) return start; - if (!config) /* getting these some in 2.3.7; none in 2.3.6 */ + if (!config) + /* getting these some in 2.3.7; none in 2.3.6 */ return start + sprintf(start, "(null Cfg. desc.)\n"); start = usb_dump_config_descriptor(start, end, &config->desc, active); for (i = 0; i < USB_MAXIADS; i++) { @@ -364,7 +356,8 @@ static char *usb_dump_config ( /* * Dump the different USB descriptors. */ -static char *usb_dump_device_descriptor(char *start, char *end, const struct usb_device_descriptor *desc) +static char *usb_dump_device_descriptor(char *start, char *end, + const struct usb_device_descriptor *desc) { u16 bcdUSB = le16_to_cpu(desc->bcdUSB); u16 bcdDevice = le16_to_cpu(desc->bcdDevice); @@ -374,7 +367,7 @@ static char *usb_dump_device_descriptor(char *start, char *end, const struct usb start += sprintf(start, format_device1, bcdUSB >> 8, bcdUSB & 0xff, desc->bDeviceClass, - class_decode (desc->bDeviceClass), + class_decode(desc->bDeviceClass), desc->bDeviceSubClass, desc->bDeviceProtocol, desc->bMaxPacketSize0, @@ -391,12 +384,14 @@ static char *usb_dump_device_descriptor(char *start, char *end, const struct usb /* * Dump the different strings that this device holds. */ -static char *usb_dump_device_strings(char *start, char *end, struct usb_device *dev) +static char *usb_dump_device_strings(char *start, char *end, + struct usb_device *dev) { if (start > end) return start; if (dev->manufacturer) - start += sprintf(start, format_string_manufacturer, dev->manufacturer); + start += sprintf(start, format_string_manufacturer, + dev->manufacturer); if (start > end) goto out; if (dev->product) @@ -405,7 +400,8 @@ static char *usb_dump_device_strings(char *start, char *end, struct usb_device * goto out; #ifdef ALLOW_SERIAL_NUMBER if (dev->serial) - start += sprintf(start, format_string_serialnumber, dev->serial); + start += sprintf(start, format_string_serialnumber, + dev->serial); #endif out: return start; @@ -417,12 +413,12 @@ static char *usb_dump_desc(char *start, char *end, struct usb_device *dev) if (start > end) return start; - + start = usb_dump_device_descriptor(start, end, &dev->descriptor); if (start > end) return start; - + start = usb_dump_device_strings(start, end, dev); 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) #ifdef PROC_EXTRA /* TBD: may want to add this code later */ -static char *usb_dump_hub_descriptor(char *start, char *end, const struct usb_hub_descriptor * desc) +static char *usb_dump_hub_descriptor(char *start, char *end, + const struct usb_hub_descriptor *desc) { int leng = USB_DT_HUB_NONVAR_SIZE; unsigned char *ptr = (unsigned char *)desc; @@ -455,13 +452,16 @@ static char *usb_dump_hub_descriptor(char *start, char *end, const struct usb_hu return start; } -static char *usb_dump_string(char *start, char *end, const struct usb_device *dev, char *id, int index) +static char *usb_dump_string(char *start, char *end, + const struct usb_device *dev, char *id, int index) { if (start > end) return start; start += sprintf(start, "Interface:"); - if (index <= dev->maxstring && dev->stringindex && dev->stringindex[index]) - start += sprintf(start, "%s: %.100s ", id, dev->stringindex[index]); + if (index <= dev->maxstring && dev->stringindex && + dev->stringindex[index]) + start += sprintf(start, "%s: %.100s ", id, + dev->stringindex[index]); return start; } @@ -476,8 +476,10 @@ static char *usb_dump_string(char *start, char *end, const struct usb_device *de * file_offset - the offset into the devices file on completion * The caller must own the device lock. */ -static ssize_t usb_device_dump(char __user **buffer, size_t *nbytes, loff_t *skip_bytes, loff_t *file_offset, - struct usb_device *usbdev, struct usb_bus *bus, int level, int index, int count) +static ssize_t usb_device_dump(char __user **buffer, size_t *nbytes, + loff_t *skip_bytes, loff_t *file_offset, + struct usb_device *usbdev, struct usb_bus *bus, + int level, int index, int count) { int chix; int ret, cnt = 0; @@ -485,17 +487,19 @@ static ssize_t usb_device_dump(char __user **buffer, size_t *nbytes, loff_t *ski char *pages_start, *data_end, *speed; unsigned int length; ssize_t total_written = 0; - + /* don't bother with anything else if we're not writing any data */ if (*nbytes <= 0) return 0; - + if (level > MAX_TOPO_LEVEL) return 0; - /* allocate 2^1 pages = 8K (on i386); should be more than enough for one device */ - if (!(pages_start = (char*) __get_free_pages(GFP_KERNEL,1))) - return -ENOMEM; - + /* allocate 2^1 pages = 8K (on i386); + * should be more than enough for one device */ + pages_start = (char *)__get_free_pages(GFP_KERNEL, 1); + if (!pages_start) + return -ENOMEM; + if (usbdev->parent && usbdev->parent->devnum != -1) parent_devnum = usbdev->parent->devnum; /* @@ -541,15 +545,16 @@ static ssize_t usb_device_dump(char __user **buffer, size_t *nbytes, loff_t *ski bus->bandwidth_allocated, max, (100 * bus->bandwidth_allocated + max / 2) / max, - bus->bandwidth_int_reqs, - bus->bandwidth_isoc_reqs); - + bus->bandwidth_int_reqs, + bus->bandwidth_isoc_reqs); + } - data_end = usb_dump_desc(data_end, pages_start + (2 * PAGE_SIZE) - 256, usbdev); - + data_end = usb_dump_desc(data_end, pages_start + (2 * PAGE_SIZE) - 256, + usbdev); + if (data_end > (pages_start + (2 * PAGE_SIZE) - 256)) data_end += sprintf(data_end, "(truncated)\n"); - + length = data_end - pages_start; /* if we can start copying some data to the user */ if (length > *skip_bytes) { @@ -567,17 +572,18 @@ static ssize_t usb_device_dump(char __user **buffer, size_t *nbytes, loff_t *ski *skip_bytes = 0; } else *skip_bytes -= length; - + free_pages((unsigned long)pages_start, 1); - + /* Now look at all of this device's children. */ for (chix = 0; chix < usbdev->maxchild; chix++) { struct usb_device *childdev = usbdev->children[chix]; if (childdev) { usb_lock_device(childdev); - ret = usb_device_dump(buffer, nbytes, skip_bytes, file_offset, childdev, - bus, level + 1, chix, ++cnt); + ret = usb_device_dump(buffer, nbytes, skip_bytes, + file_offset, childdev, bus, + level + 1, chix, ++cnt); usb_unlock_device(childdev); if (ret == -EFAULT) return total_written; @@ -587,7 +593,8 @@ static ssize_t usb_device_dump(char __user **buffer, size_t *nbytes, loff_t *ski return total_written; } -static ssize_t usb_device_read(struct file *file, char __user *buf, size_t nbytes, loff_t *ppos) +static ssize_t usb_device_read(struct file *file, char __user *buf, + size_t nbytes, loff_t *ppos) { struct usb_bus *bus; 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 if (!bus->root_hub) continue; usb_lock_device(bus->root_hub); - ret = usb_device_dump(&buf, &nbytes, &skip_bytes, ppos, bus->root_hub, bus, 0, 0, 0); + ret = usb_device_dump(&buf, &nbytes, &skip_bytes, ppos, + bus->root_hub, bus, 0, 0, 0); usb_unlock_device(bus->root_hub); if (ret < 0) { 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 } /* Kernel lock for "lastev" protection */ -static unsigned int usb_device_poll(struct file *file, struct poll_table_struct *wait) +static unsigned int usb_device_poll(struct file *file, + struct poll_table_struct *wait) { struct usb_device_status *st = file->private_data; unsigned int mask = 0; @@ -629,7 +638,8 @@ static unsigned int usb_device_poll(struct file *file, struct poll_table_struct if (!st) { st = kmalloc(sizeof(struct usb_device_status), GFP_KERNEL); - /* we may have dropped BKL - need to check for having lost the race */ + /* we may have dropped BKL - + * need to check for having lost the race */ if (file->private_data) { kfree(st); st = file->private_data; @@ -652,7 +662,7 @@ static unsigned int usb_device_poll(struct file *file, struct poll_table_struct } lost_race: if (file->f_mode & FMODE_READ) - poll_wait(file, &deviceconndiscwq, wait); + poll_wait(file, &deviceconndiscwq, wait); if (st->lastev != conndiscevcnt) mask |= POLLIN; st->lastev = conndiscevcnt; @@ -662,18 +672,18 @@ lost_race: static int usb_device_open(struct inode *inode, struct file *file) { - file->private_data = NULL; - return 0; + file->private_data = NULL; + return 0; } static int usb_device_release(struct inode *inode, struct file *file) { kfree(file->private_data); file->private_data = NULL; - return 0; + return 0; } -static loff_t usb_device_lseek(struct file * file, loff_t offset, int orig) +static loff_t usb_device_lseek(struct file *file, loff_t offset, int orig) { loff_t ret; -- cgit v1.2.3 From 04e482ffd81437e7f551373d56c72c237e163000 Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Wed, 30 Jan 2008 15:21:33 -0800 Subject: USB: fix codingstyle issues in drivers/usb/core/devio.c Fixes a number of coding style issues in the devio.c file. Signed-off-by: Greg Kroah-Hartman --- drivers/usb/core/devio.c | 333 ++++++++++++++++++++++++++--------------------- 1 file changed, 188 insertions(+), 145 deletions(-) diff --git a/drivers/usb/core/devio.c b/drivers/usb/core/devio.c index e661994ad18d..ae94176c64e4 100644 --- a/drivers/usb/core/devio.c +++ b/drivers/usb/core/devio.c @@ -75,14 +75,14 @@ struct async { u32 secid; }; -static int usbfs_snoop = 0; -module_param (usbfs_snoop, bool, S_IRUGO | S_IWUSR); -MODULE_PARM_DESC (usbfs_snoop, "true to log all usbfs traffic"); +static int usbfs_snoop; +module_param(usbfs_snoop, bool, S_IRUGO | S_IWUSR); +MODULE_PARM_DESC(usbfs_snoop, "true to log all usbfs traffic"); #define snoop(dev, format, arg...) \ do { \ if (usbfs_snoop) \ - dev_info( dev , format , ## arg); \ + dev_info(dev , format , ## arg); \ } while (0) #define USB_DEVICE_DEV MKDEV(USB_DEVICE_MAJOR, 0) @@ -90,7 +90,7 @@ MODULE_PARM_DESC (usbfs_snoop, "true to log all usbfs traffic"); #define MAX_USBFS_BUFFER_SIZE 16384 -static inline int connected (struct dev_state *ps) +static inline int connected(struct dev_state *ps) { return (!list_empty(&ps->list) && ps->dev->state != USB_STATE_NOTATTACHED); @@ -120,7 +120,8 @@ static loff_t usbdev_lseek(struct file *file, loff_t offset, int orig) return ret; } -static ssize_t usbdev_read(struct file *file, char __user *buf, size_t nbytes, loff_t *ppos) +static ssize_t usbdev_read(struct file *file, char __user *buf, size_t nbytes, + loff_t *ppos) { struct dev_state *ps = file->private_data; 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 } if (pos < sizeof(struct usb_device_descriptor)) { - struct usb_device_descriptor temp_desc ; /* 18 bytes - fits on the stack */ + /* 18 bytes - fits on the stack */ + struct usb_device_descriptor temp_desc; memcpy(&temp_desc, &dev->descriptor, sizeof(dev->descriptor)); le16_to_cpus(&temp_desc.bcdUSB); @@ -213,14 +215,14 @@ static struct async *alloc_async(unsigned int numisoframes) struct async *as; as = kzalloc(sizeof(struct async), GFP_KERNEL); - if (!as) - return NULL; + if (!as) + return NULL; as->urb = usb_alloc_urb(numisoframes, GFP_KERNEL); if (!as->urb) { kfree(as); return NULL; } - return as; + return as; } static void free_async(struct async *as) @@ -234,52 +236,54 @@ static void free_async(struct async *as) static inline void async_newpending(struct async *as) { - struct dev_state *ps = as->ps; - unsigned long flags; - - spin_lock_irqsave(&ps->lock, flags); - list_add_tail(&as->asynclist, &ps->async_pending); - spin_unlock_irqrestore(&ps->lock, flags); + struct dev_state *ps = as->ps; + unsigned long flags; + + spin_lock_irqsave(&ps->lock, flags); + list_add_tail(&as->asynclist, &ps->async_pending); + spin_unlock_irqrestore(&ps->lock, flags); } static inline void async_removepending(struct async *as) { - struct dev_state *ps = as->ps; - unsigned long flags; - - spin_lock_irqsave(&ps->lock, flags); - list_del_init(&as->asynclist); - spin_unlock_irqrestore(&ps->lock, flags); + struct dev_state *ps = as->ps; + unsigned long flags; + + spin_lock_irqsave(&ps->lock, flags); + list_del_init(&as->asynclist); + spin_unlock_irqrestore(&ps->lock, flags); } static inline struct async *async_getcompleted(struct dev_state *ps) { - unsigned long flags; - struct async *as = NULL; - - spin_lock_irqsave(&ps->lock, flags); - if (!list_empty(&ps->async_completed)) { - as = list_entry(ps->async_completed.next, struct async, asynclist); - list_del_init(&as->asynclist); - } - spin_unlock_irqrestore(&ps->lock, flags); - return as; + unsigned long flags; + struct async *as = NULL; + + spin_lock_irqsave(&ps->lock, flags); + if (!list_empty(&ps->async_completed)) { + as = list_entry(ps->async_completed.next, struct async, + asynclist); + list_del_init(&as->asynclist); + } + spin_unlock_irqrestore(&ps->lock, flags); + return as; } -static inline struct async *async_getpending(struct dev_state *ps, void __user *userurb) +static inline struct async *async_getpending(struct dev_state *ps, + void __user *userurb) { - unsigned long flags; - struct async *as; + unsigned long flags; + struct async *as; - spin_lock_irqsave(&ps->lock, flags); + spin_lock_irqsave(&ps->lock, flags); list_for_each_entry(as, &ps->async_pending, asynclist) if (as->userurb == userurb) { list_del_init(&as->asynclist); spin_unlock_irqrestore(&ps->lock, flags); return as; } - spin_unlock_irqrestore(&ps->lock, flags); - return NULL; + spin_unlock_irqrestore(&ps->lock, flags); + return NULL; } static void snoop_urb(struct urb *urb, void __user *userurb) @@ -298,19 +302,19 @@ static void snoop_urb(struct urb *urb, void __user *userurb) dev_info(&urb->dev->dev, "actual_length=%d\n", urb->actual_length); dev_info(&urb->dev->dev, "data: "); for (j = 0; j < urb->transfer_buffer_length; ++j) - printk ("%02x ", data[j]); + printk("%02x ", data[j]); printk("\n"); } static void async_completed(struct urb *urb) { - struct async *as = urb->context; - struct dev_state *ps = as->ps; + struct async *as = urb->context; + struct dev_state *ps = as->ps; struct siginfo sinfo; - spin_lock(&ps->lock); - list_move_tail(&as->asynclist, &ps->async_completed); - spin_unlock(&ps->lock); + spin_lock(&ps->lock); + list_move_tail(&as->asynclist, &ps->async_completed); + spin_unlock(&ps->lock); as->status = urb->status; if (as->signr) { sinfo.si_signo = as->signr; @@ -325,7 +329,7 @@ static void async_completed(struct urb *urb) wake_up(&ps->wait); } -static void destroy_async (struct dev_state *ps, struct list_head *list) +static void destroy_async(struct dev_state *ps, struct list_head *list) { struct async *as; unsigned long flags; @@ -348,7 +352,8 @@ static void destroy_async (struct dev_state *ps, struct list_head *list) } } -static void destroy_async_on_interface (struct dev_state *ps, unsigned int ifnum) +static void destroy_async_on_interface(struct dev_state *ps, + unsigned int ifnum) { struct list_head *p, *q, hitlist; unsigned long flags; @@ -364,7 +369,7 @@ static void destroy_async_on_interface (struct dev_state *ps, unsigned int ifnum static inline void destroy_all_async(struct dev_state *ps) { - destroy_async(ps, &ps->async_pending); + destroy_async(ps, &ps->async_pending); } /* @@ -373,15 +378,15 @@ static inline void destroy_all_async(struct dev_state *ps) * they're also undone when devices disconnect. */ -static int driver_probe (struct usb_interface *intf, - const struct usb_device_id *id) +static int driver_probe(struct usb_interface *intf, + const struct usb_device_id *id) { return -ENODEV; } static void driver_disconnect(struct usb_interface *intf) { - struct dev_state *ps = usb_get_intfdata (intf); + struct dev_state *ps = usb_get_intfdata(intf); unsigned int ifnum = intf->altsetting->desc.bInterfaceNumber; if (!ps) @@ -396,7 +401,7 @@ static void driver_disconnect(struct usb_interface *intf) else warn("interface number %u out of range", ifnum); - usb_set_intfdata (intf, NULL); + usb_set_intfdata(intf, NULL); /* force async requests to complete */ destroy_async_on_interface(ps, ifnum); @@ -474,15 +479,16 @@ static int checkintf(struct dev_state *ps, unsigned int ifnum) if (test_bit(ifnum, &ps->ifclaimed)) return 0; /* if not yet claimed, claim it for the driver */ - dev_warn(&ps->dev->dev, "usbfs: process %d (%s) did not claim interface %u before use\n", - task_pid_nr(current), current->comm, ifnum); + dev_warn(&ps->dev->dev, "usbfs: process %d (%s) did not claim " + "interface %u before use\n", task_pid_nr(current), + current->comm, ifnum); return claimintf(ps, ifnum); } static int findintfep(struct usb_device *dev, unsigned int ep) { unsigned int i, j, e; - struct usb_interface *intf; + struct usb_interface *intf; struct usb_host_interface *alts; struct usb_endpoint_descriptor *endpt; @@ -493,7 +499,7 @@ static int findintfep(struct usb_device *dev, unsigned int ep) for (i = 0; i < dev->actconfig->desc.bNumInterfaces; i++) { intf = dev->actconfig->interface[i]; for (j = 0; j < intf->num_altsetting; j++) { - alts = &intf->altsetting[j]; + alts = &intf->altsetting[j]; for (e = 0; e < alts->desc.bNumEndpoints; e++) { endpt = &alts->endpoint[e].desc; if (endpt->bEndpointAddress == ep) @@ -501,10 +507,11 @@ static int findintfep(struct usb_device *dev, unsigned int ep) } } } - return -ENOENT; + return -ENOENT; } -static int check_ctrlrecip(struct dev_state *ps, unsigned int requesttype, unsigned int index) +static int check_ctrlrecip(struct dev_state *ps, unsigned int requesttype, + unsigned int index) { int ret = 0; @@ -517,7 +524,8 @@ static int check_ctrlrecip(struct dev_state *ps, unsigned int requesttype, unsig index &= 0xff; switch (requesttype & USB_RECIP_MASK) { case USB_RECIP_ENDPOINT: - if ((ret = findintfep(ps->dev, index)) >= 0) + ret = findintfep(ps->dev, index); + if (ret >= 0) ret = checkintf(ps, ret); break; @@ -561,7 +569,8 @@ static int usbdev_open(struct inode *inode, struct file *file) mutex_lock(&usbfs_mutex); ret = -ENOMEM; - if (!(ps = kmalloc(sizeof(struct dev_state), GFP_KERNEL))) + ps = kmalloc(sizeof(struct dev_state), GFP_KERNEL); + if (!ps) goto out; ret = -ENOENT; @@ -642,15 +651,18 @@ static int proc_control(struct dev_state *ps, void __user *arg) if (copy_from_user(&ctrl, arg, sizeof(ctrl))) return -EFAULT; - if ((ret = check_ctrlrecip(ps, ctrl.bRequestType, ctrl.wIndex))) + ret = check_ctrlrecip(ps, ctrl.bRequestType, ctrl.wIndex); + if (ret) return ret; if (ctrl.wLength > PAGE_SIZE) return -EINVAL; - if (!(tbuf = (unsigned char *)__get_free_page(GFP_KERNEL))) + tbuf = (unsigned char *)__get_free_page(GFP_KERNEL); + if (!tbuf) return -ENOMEM; tmo = ctrl.timeout; if (ctrl.bRequestType & 0x80) { - if (ctrl.wLength && !access_ok(VERIFY_WRITE, ctrl.data, ctrl.wLength)) { + if (ctrl.wLength && !access_ok(VERIFY_WRITE, ctrl.data, + ctrl.wLength)) { free_page((unsigned long)tbuf); return -EINVAL; } @@ -661,14 +673,15 @@ static int proc_control(struct dev_state *ps, void __user *arg) ctrl.wIndex, ctrl.wLength); usb_unlock_device(dev); - i = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0), ctrl.bRequest, ctrl.bRequestType, - ctrl.wValue, ctrl.wIndex, tbuf, ctrl.wLength, tmo); + i = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0), ctrl.bRequest, + ctrl.bRequestType, ctrl.wValue, ctrl.wIndex, + tbuf, ctrl.wLength, tmo); usb_lock_device(dev); if ((i > 0) && ctrl.wLength) { if (usbfs_snoop) { dev_info(&dev->dev, "control read: data "); for (j = 0; j < i; ++j) - printk("%02x ", (unsigned char)(tbuf)[j]); + printk("%02x ", (u8)(tbuf)[j]); printk("\n"); } if (copy_to_user(ctrl.data, tbuf, i)) { @@ -695,12 +708,13 @@ static int proc_control(struct dev_state *ps, void __user *arg) printk("\n"); } usb_unlock_device(dev); - i = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), ctrl.bRequest, ctrl.bRequestType, - ctrl.wValue, ctrl.wIndex, tbuf, ctrl.wLength, tmo); + i = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), ctrl.bRequest, + ctrl.bRequestType, ctrl.wValue, ctrl.wIndex, + tbuf, ctrl.wLength, tmo); usb_lock_device(dev); } free_page((unsigned long)tbuf); - if (i<0 && i != -EPIPE) { + if (i < 0 && i != -EPIPE) { dev_printk(KERN_DEBUG, &dev->dev, "usbfs: USBDEVFS_CONTROL " "failed cmd %s rqt %u rq %u len %u ret %d\n", current->comm, ctrl.bRequestType, ctrl.bRequest, @@ -720,9 +734,11 @@ static int proc_bulk(struct dev_state *ps, void __user *arg) if (copy_from_user(&bulk, arg, sizeof(bulk))) return -EFAULT; - if ((ret = findintfep(ps->dev, bulk.ep)) < 0) + ret = findintfep(ps->dev, bulk.ep); + if (ret < 0) return ret; - if ((ret = checkintf(ps, ret))) + ret = checkintf(ps, ret); + if (ret) return ret; if (bulk.ep & USB_DIR_IN) pipe = usb_rcvbulkpipe(dev, bulk.ep & 0x7f); @@ -750,7 +766,7 @@ static int proc_bulk(struct dev_state *ps, void __user *arg) if (usbfs_snoop) { dev_info(&dev->dev, "bulk read: data "); for (j = 0; j < len2; ++j) - printk("%02x ", (unsigned char)(tbuf)[j]); + printk("%02x ", (u8)(tbuf)[j]); printk("\n"); } if (copy_to_user(bulk.data, tbuf, len2)) { @@ -790,9 +806,11 @@ static int proc_resetep(struct dev_state *ps, void __user *arg) if (get_user(ep, (unsigned int __user *)arg)) return -EFAULT; - if ((ret = findintfep(ps->dev, ep)) < 0) + ret = findintfep(ps->dev, ep); + if (ret < 0) return ret; - if ((ret = checkintf(ps, ret))) + ret = checkintf(ps, ret); + if (ret) return ret; usb_settoggle(ps->dev, ep & 0xf, !(ep & USB_DIR_IN), 0); return 0; @@ -806,18 +824,19 @@ static int proc_clearhalt(struct dev_state *ps, void __user *arg) if (get_user(ep, (unsigned int __user *)arg)) return -EFAULT; - if ((ret = findintfep(ps->dev, ep)) < 0) + ret = findintfep(ps->dev, ep); + if (ret < 0) return ret; - if ((ret = checkintf(ps, ret))) + ret = checkintf(ps, ret); + if (ret) return ret; if (ep & USB_DIR_IN) - pipe = usb_rcvbulkpipe(ps->dev, ep & 0x7f); - else - pipe = usb_sndbulkpipe(ps->dev, ep & 0x7f); + pipe = usb_rcvbulkpipe(ps->dev, ep & 0x7f); + else + pipe = usb_sndbulkpipe(ps->dev, ep & 0x7f); return usb_clear_halt(ps->dev, pipe); } - static int proc_getdriver(struct dev_state *ps, void __user *arg) { @@ -871,23 +890,23 @@ static int proc_setconfig(struct dev_state *ps, void __user *arg) { int u; int status = 0; - struct usb_host_config *actconfig; + struct usb_host_config *actconfig; if (get_user(u, (int __user *)arg)) return -EFAULT; - actconfig = ps->dev->actconfig; - - /* Don't touch the device if any interfaces are claimed. - * It could interfere with other drivers' operations, and if + actconfig = ps->dev->actconfig; + + /* Don't touch the device if any interfaces are claimed. + * It could interfere with other drivers' operations, and if * an interface is claimed by usbfs it could easily deadlock. */ - if (actconfig) { - int i; - - for (i = 0; i < actconfig->desc.bNumInterfaces; ++i) { - if (usb_interface_claimed(actconfig->interface[i])) { - dev_warn (&ps->dev->dev, + if (actconfig) { + int i; + + for (i = 0; i < actconfig->desc.bNumInterfaces; ++i) { + if (usb_interface_claimed(actconfig->interface[i])) { + dev_warn(&ps->dev->dev, "usbfs: interface %d claimed by %s " "while '%s' sets config #%d\n", actconfig->interface[i] @@ -896,11 +915,11 @@ static int proc_setconfig(struct dev_state *ps, void __user *arg) actconfig->interface[i] ->dev.driver->name, current->comm, u); - status = -EBUSY; + status = -EBUSY; break; } - } - } + } + } /* SET_CONFIGURATION is often abused as a "cheap" driver reset, * so avoid usb_set_configuration()'s kick to sysfs @@ -916,8 +935,8 @@ static int proc_setconfig(struct dev_state *ps, void __user *arg) } static int proc_do_submiturb(struct dev_state *ps, struct usbdevfs_urb *uurb, - struct usbdevfs_iso_packet_desc __user *iso_frame_desc, - void __user *arg) + struct usbdevfs_iso_packet_desc __user *iso_frame_desc, + void __user *arg) { struct usbdevfs_iso_packet_desc *isopkt = NULL; struct usb_host_endpoint *ep; @@ -932,12 +951,16 @@ static int proc_do_submiturb(struct dev_state *ps, struct usbdevfs_urb *uurb, return -EINVAL; if (!uurb->buffer) return -EINVAL; - if (uurb->signr != 0 && (uurb->signr < SIGRTMIN || uurb->signr > SIGRTMAX)) + if (uurb->signr != 0 && (uurb->signr < SIGRTMIN || + uurb->signr > SIGRTMAX)) return -EINVAL; - if (!(uurb->type == USBDEVFS_URB_TYPE_CONTROL && (uurb->endpoint & ~USB_ENDPOINT_DIR_MASK) == 0)) { - if ((ifnum = findintfep(ps->dev, uurb->endpoint)) < 0) + if (!(uurb->type == USBDEVFS_URB_TYPE_CONTROL && + (uurb->endpoint & ~USB_ENDPOINT_DIR_MASK) == 0)) { + ifnum = findintfep(ps->dev, uurb->endpoint); + if (ifnum < 0) return ifnum; - if ((ret = checkintf(ps, ifnum))) + ret = checkintf(ps, ifnum); + if (ret) return ret; } if ((uurb->endpoint & USB_ENDPOINT_DIR_MASK) != 0) { @@ -953,10 +976,13 @@ static int proc_do_submiturb(struct dev_state *ps, struct usbdevfs_urb *uurb, case USBDEVFS_URB_TYPE_CONTROL: if (!usb_endpoint_xfer_control(&ep->desc)) return -EINVAL; - /* min 8 byte setup packet, max 8 byte setup plus an arbitrary data stage */ - if (uurb->buffer_length < 8 || uurb->buffer_length > (8 + MAX_USBFS_BUFFER_SIZE)) + /* min 8 byte setup packet, + * max 8 byte setup plus an arbitrary data stage */ + if (uurb->buffer_length < 8 || + uurb->buffer_length > (8 + MAX_USBFS_BUFFER_SIZE)) return -EINVAL; - if (!(dr = kmalloc(sizeof(struct usb_ctrlrequest), GFP_KERNEL))) + dr = kmalloc(sizeof(struct usb_ctrlrequest), GFP_KERNEL); + if (!dr) return -ENOMEM; if (copy_from_user(dr, uurb->buffer, 8)) { kfree(dr); @@ -966,7 +992,9 @@ static int proc_do_submiturb(struct dev_state *ps, struct usbdevfs_urb *uurb, kfree(dr); return -EINVAL; } - if ((ret = check_ctrlrecip(ps, dr->bRequestType, le16_to_cpup(&dr->wIndex)))) { + ret = check_ctrlrecip(ps, dr->bRequestType, + le16_to_cpup(&dr->wIndex)); + if (ret) { kfree(dr); return ret; } @@ -1012,11 +1040,13 @@ static int proc_do_submiturb(struct dev_state *ps, struct usbdevfs_urb *uurb, case USBDEVFS_URB_TYPE_ISO: /* arbitrary limit */ - if (uurb->number_of_packets < 1 || uurb->number_of_packets > 128) + if (uurb->number_of_packets < 1 || + uurb->number_of_packets > 128) return -EINVAL; if (!usb_endpoint_xfer_isoc(&ep->desc)) return -EINVAL; - isofrmlen = sizeof(struct usbdevfs_iso_packet_desc) * uurb->number_of_packets; + isofrmlen = sizeof(struct usbdevfs_iso_packet_desc) * + uurb->number_of_packets; if (!(isopkt = kmalloc(isofrmlen, GFP_KERNEL))) return -ENOMEM; if (copy_from_user(isopkt, iso_frame_desc, isofrmlen)) { @@ -1024,7 +1054,8 @@ static int proc_do_submiturb(struct dev_state *ps, struct usbdevfs_urb *uurb, return -EFAULT; } for (totlen = u = 0; u < uurb->number_of_packets; u++) { - /* arbitrary limit, sufficient for USB 2.0 high-bandwidth iso */ + /* arbitrary limit, + * sufficient for USB 2.0 high-bandwidth iso */ if (isopkt[u].length > 8192) { kfree(isopkt); return -EINVAL; @@ -1054,25 +1085,27 @@ static int proc_do_submiturb(struct dev_state *ps, struct usbdevfs_urb *uurb, default: return -EINVAL; } - if (!(as = alloc_async(uurb->number_of_packets))) { + as = alloc_async(uurb->number_of_packets); + if (!as) { kfree(isopkt); kfree(dr); return -ENOMEM; } - if (!(as->urb->transfer_buffer = kmalloc(uurb->buffer_length, GFP_KERNEL))) { + as->urb->transfer_buffer = kmalloc(uurb->buffer_length, GFP_KERNEL); + if (!as->urb->transfer_buffer) { kfree(isopkt); kfree(dr); free_async(as); return -ENOMEM; } - as->urb->dev = ps->dev; - as->urb->pipe = (uurb->type << 30) | + as->urb->dev = ps->dev; + as->urb->pipe = (uurb->type << 30) | __create_pipe(ps->dev, uurb->endpoint & 0xf) | (uurb->endpoint & USB_DIR_IN); - as->urb->transfer_flags = uurb->flags | + as->urb->transfer_flags = uurb->flags | (is_in ? URB_DIR_IN : URB_DIR_OUT); as->urb->transfer_buffer_length = uurb->buffer_length; - as->urb->setup_packet = (unsigned char*)dr; + as->urb->setup_packet = (unsigned char *)dr; as->urb->start_frame = uurb->start_frame; as->urb->number_of_packets = uurb->number_of_packets; if (uurb->type == USBDEVFS_URB_TYPE_ISO || @@ -1080,8 +1113,8 @@ static int proc_do_submiturb(struct dev_state *ps, struct usbdevfs_urb *uurb, as->urb->interval = 1 << min(15, ep->desc.bInterval - 1); else as->urb->interval = ep->desc.bInterval; - as->urb->context = as; - as->urb->complete = async_completed; + as->urb->context = as; + as->urb->complete = async_completed; for (totlen = u = 0; u < uurb->number_of_packets; u++) { as->urb->iso_frame_desc[u].offset = totlen; as->urb->iso_frame_desc[u].length = isopkt[u].length; @@ -1089,7 +1122,7 @@ static int proc_do_submiturb(struct dev_state *ps, struct usbdevfs_urb *uurb, } kfree(isopkt); as->ps = ps; - as->userurb = arg; + as->userurb = arg; if (uurb->endpoint & USB_DIR_IN) as->userbuffer = uurb->buffer; else @@ -1108,14 +1141,15 @@ static int proc_do_submiturb(struct dev_state *ps, struct usbdevfs_urb *uurb, } } snoop_urb(as->urb, as->userurb); - async_newpending(as); - if ((ret = usb_submit_urb(as->urb, GFP_KERNEL))) { - dev_printk(KERN_DEBUG, &ps->dev->dev, "usbfs: usb_submit_urb returned %d\n", ret); - async_removepending(as); - free_async(as); - return ret; - } - return 0; + async_newpending(as); + if ((ret = usb_submit_urb(as->urb, GFP_KERNEL))) { + dev_printk(KERN_DEBUG, &ps->dev->dev, + "usbfs: usb_submit_urb returned %d\n", ret); + async_removepending(as); + free_async(as); + return ret; + } + return 0; } static int proc_submiturb(struct dev_state *ps, void __user *arg) @@ -1125,7 +1159,9 @@ static int proc_submiturb(struct dev_state *ps, void __user *arg) if (copy_from_user(&uurb, arg, sizeof(uurb))) return -EFAULT; - return proc_do_submiturb(ps, &uurb, (((struct usbdevfs_urb __user *)arg)->iso_frame_desc), arg); + return proc_do_submiturb(ps, &uurb, + (((struct usbdevfs_urb __user *)arg)->iso_frame_desc), + arg); } static int proc_unlinkurb(struct dev_state *ps, void __user *arg) @@ -1147,7 +1183,8 @@ static int processcompl(struct async *as, void __user * __user *arg) unsigned int i; if (as->userbuffer) - if (copy_to_user(as->userbuffer, urb->transfer_buffer, urb->transfer_buffer_length)) + if (copy_to_user(as->userbuffer, urb->transfer_buffer, + urb->transfer_buffer_length)) return -EFAULT; if (put_user(as->status, &userurb->status)) return -EFAULT; @@ -1174,16 +1211,17 @@ static int processcompl(struct async *as, void __user * __user *arg) return 0; } -static struct async* reap_as(struct dev_state *ps) +static struct async *reap_as(struct dev_state *ps) { - DECLARE_WAITQUEUE(wait, current); + DECLARE_WAITQUEUE(wait, current); struct async *as = NULL; struct usb_device *dev = ps->dev; add_wait_queue(&ps->wait, &wait); for (;;) { __set_current_state(TASK_INTERRUPTIBLE); - if ((as = async_getcompleted(ps))) + as = async_getcompleted(ps); + if (as) break; if (signal_pending(current)) break; @@ -1247,10 +1285,12 @@ static int proc_submiturb_compat(struct dev_state *ps, void __user *arg) { struct usbdevfs_urb uurb; - if (get_urb32(&uurb,(struct usbdevfs_urb32 __user *)arg)) + if (get_urb32(&uurb, (struct usbdevfs_urb32 __user *)arg)) return -EFAULT; - return proc_do_submiturb(ps, &uurb, ((struct usbdevfs_urb32 __user *)arg)->iso_frame_desc, arg); + return proc_do_submiturb(ps, &uurb, + ((struct usbdevfs_urb32 __user *)arg)->iso_frame_desc, + arg); } static int processcompl_compat(struct async *as, void __user * __user *arg) @@ -1261,7 +1301,8 @@ static int processcompl_compat(struct async *as, void __user * __user *arg) unsigned int i; if (as->userbuffer) - if (copy_to_user(as->userbuffer, urb->transfer_buffer, urb->transfer_buffer_length)) + if (copy_to_user(as->userbuffer, urb->transfer_buffer, + urb->transfer_buffer_length)) return -EFAULT; if (put_user(as->status, &userurb->status)) return -EFAULT; @@ -1352,16 +1393,16 @@ static int proc_ioctl(struct dev_state *ps, struct usbdevfs_ioctl *ctl) struct usb_driver *driver = NULL; /* alloc buffer */ - if ((size = _IOC_SIZE (ctl->ioctl_code)) > 0) { - if ((buf = kmalloc (size, GFP_KERNEL)) == NULL) + if ((size = _IOC_SIZE(ctl->ioctl_code)) > 0) { + if ((buf = kmalloc(size, GFP_KERNEL)) == NULL) return -ENOMEM; if ((_IOC_DIR(ctl->ioctl_code) & _IOC_WRITE)) { - if (copy_from_user (buf, ctl->data, size)) { + if (copy_from_user(buf, ctl->data, size)) { kfree(buf); return -EFAULT; } } else { - memset (buf, 0, size); + memset(buf, 0, size); } } @@ -1372,15 +1413,15 @@ static int proc_ioctl(struct dev_state *ps, struct usbdevfs_ioctl *ctl) if (ps->dev->state != USB_STATE_CONFIGURED) retval = -EHOSTUNREACH; - else if (!(intf = usb_ifnum_to_if (ps->dev, ctl->ifno))) - retval = -EINVAL; + else if (!(intf = usb_ifnum_to_if(ps->dev, ctl->ifno))) + retval = -EINVAL; else switch (ctl->ioctl_code) { /* disconnect kernel driver from interface */ case USBDEVFS_DISCONNECT: if (intf->dev.driver) { driver = to_usb_driver(intf->dev.driver); - dev_dbg (&intf->dev, "disconnect by usbfs\n"); + dev_dbg(&intf->dev, "disconnect by usbfs\n"); usb_driver_release_interface(driver, intf); } else retval = -ENODATA; @@ -1401,7 +1442,7 @@ static int proc_ioctl(struct dev_state *ps, struct usbdevfs_ioctl *ctl) if (driver == NULL || driver->ioctl == NULL) { retval = -ENOTTY; } else { - retval = driver->ioctl (intf, ctl->ioctl_code, buf); + retval = driver->ioctl(intf, ctl->ioctl_code, buf); if (retval == -ENOIOCTLCMD) retval = -ENOTTY; } @@ -1409,9 +1450,9 @@ static int proc_ioctl(struct dev_state *ps, struct usbdevfs_ioctl *ctl) /* cleanup and return */ if (retval >= 0 - && (_IOC_DIR (ctl->ioctl_code) & _IOC_READ) != 0 + && (_IOC_DIR(ctl->ioctl_code) & _IOC_READ) != 0 && size > 0 - && copy_to_user (ctl->data, buf, size) != 0) + && copy_to_user(ctl->data, buf, size) != 0) retval = -EFAULT; kfree(buf); @@ -1422,7 +1463,7 @@ static int proc_ioctl_default(struct dev_state *ps, void __user *arg) { struct usbdevfs_ioctl ctrl; - if (copy_from_user(&ctrl, arg, sizeof (ctrl))) + if (copy_from_user(&ctrl, arg, sizeof(ctrl))) return -EFAULT; return proc_ioctl(ps, &ctrl); } @@ -1450,7 +1491,8 @@ static int proc_ioctl_compat(struct dev_state *ps, compat_uptr_t arg) * are assuming that somehow the configuration has been prevented from * changing. But there's no mechanism to ensure that... */ -static int usbdev_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg) +static int usbdev_ioctl(struct inode *inode, struct file *file, + unsigned int cmd, unsigned long arg) { struct dev_state *ps = file->private_data; struct usb_device *dev = ps->dev; @@ -1593,7 +1635,8 @@ static int usbdev_ioctl(struct inode *inode, struct file *file, unsigned int cmd } /* No kernel lock - fine */ -static unsigned int usbdev_poll(struct file *file, struct poll_table_struct *wait) +static unsigned int usbdev_poll(struct file *file, + struct poll_table_struct *wait) { struct dev_state *ps = file->private_data; unsigned int mask = 0; @@ -1664,7 +1707,7 @@ int __init usb_devio_init(void) int retval; retval = register_chrdev_region(USB_DEVICE_DEV, USB_DEVICE_MAX, - "usb_device"); + "usb_device"); if (retval) { err("unable to register minors for usb_device"); goto out; -- cgit v1.2.3 From 34bbe4c16ca06cb762b99a6263832cfdbbe154ad Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Wed, 30 Jan 2008 15:21:33 -0800 Subject: USB: fix codingstyle issues in drivers/usb/core/hcd-pci.c Fixes a number of coding style issues in the hcd-pci.c file. Signed-off-by: Greg Kroah-Hartman --- drivers/usb/core/hcd-pci.c | 129 +++++++++++++++++++++++---------------------- 1 file changed, 67 insertions(+), 62 deletions(-) diff --git a/drivers/usb/core/hcd-pci.c b/drivers/usb/core/hcd-pci.c index 851d5e1625d9..84760ddbc332 100644 --- a/drivers/usb/core/hcd-pci.c +++ b/drivers/usb/core/hcd-pci.c @@ -1,6 +1,6 @@ /* * (C) Copyright David Brownell 2000-2002 - * + * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the * Free Software Foundation; either version 2 of the License, or (at your @@ -55,7 +55,7 @@ * * Store this function in the HCD's struct pci_driver as probe(). */ -int usb_hcd_pci_probe (struct pci_dev *dev, const struct pci_device_id *id) +int usb_hcd_pci_probe(struct pci_dev *dev, const struct pci_device_id *id) { struct hc_driver *driver; struct usb_hcd *hcd; @@ -64,66 +64,71 @@ int usb_hcd_pci_probe (struct pci_dev *dev, const struct pci_device_id *id) if (usb_disabled()) return -ENODEV; - if (!id || !(driver = (struct hc_driver *) id->driver_data)) + if (!id) + return -EINVAL; + driver = (struct hc_driver *)id->driver_data; + if (!driver) return -EINVAL; - if (pci_enable_device (dev) < 0) + if (pci_enable_device(dev) < 0) return -ENODEV; dev->current_state = PCI_D0; dev->dev.power.power_state = PMSG_ON; - - if (!dev->irq) { - dev_err (&dev->dev, + + if (!dev->irq) { + dev_err(&dev->dev, "Found HC with no IRQ. Check BIOS/PCI %s setup!\n", pci_name(dev)); - retval = -ENODEV; + retval = -ENODEV; goto err1; - } + } - hcd = usb_create_hcd (driver, &dev->dev, pci_name(dev)); + hcd = usb_create_hcd(driver, &dev->dev, pci_name(dev)); if (!hcd) { retval = -ENOMEM; goto err1; } - if (driver->flags & HCD_MEMORY) { // EHCI, OHCI - hcd->rsrc_start = pci_resource_start (dev, 0); - hcd->rsrc_len = pci_resource_len (dev, 0); - if (!request_mem_region (hcd->rsrc_start, hcd->rsrc_len, + if (driver->flags & HCD_MEMORY) { + /* EHCI, OHCI */ + hcd->rsrc_start = pci_resource_start(dev, 0); + hcd->rsrc_len = pci_resource_len(dev, 0); + if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, driver->description)) { - dev_dbg (&dev->dev, "controller already in use\n"); + dev_dbg(&dev->dev, "controller already in use\n"); retval = -EBUSY; goto err2; } - hcd->regs = ioremap_nocache (hcd->rsrc_start, hcd->rsrc_len); + hcd->regs = ioremap_nocache(hcd->rsrc_start, hcd->rsrc_len); if (hcd->regs == NULL) { - dev_dbg (&dev->dev, "error mapping memory\n"); + dev_dbg(&dev->dev, "error mapping memory\n"); retval = -EFAULT; goto err3; } - } else { // UHCI + } else { + /* UHCI */ int region; for (region = 0; region < PCI_ROM_RESOURCE; region++) { - if (!(pci_resource_flags (dev, region) & + if (!(pci_resource_flags(dev, region) & IORESOURCE_IO)) continue; - hcd->rsrc_start = pci_resource_start (dev, region); - hcd->rsrc_len = pci_resource_len (dev, region); - if (request_region (hcd->rsrc_start, hcd->rsrc_len, + hcd->rsrc_start = pci_resource_start(dev, region); + hcd->rsrc_len = pci_resource_len(dev, region); + if (request_region(hcd->rsrc_start, hcd->rsrc_len, driver->description)) break; } if (region == PCI_ROM_RESOURCE) { - dev_dbg (&dev->dev, "no i/o regions available\n"); + dev_dbg(&dev->dev, "no i/o regions available\n"); retval = -EBUSY; goto err1; } } - pci_set_master (dev); + pci_set_master(dev); retval = usb_add_hcd(hcd, dev->irq, IRQF_DISABLED | IRQF_SHARED); if (retval != 0) @@ -132,18 +137,18 @@ int usb_hcd_pci_probe (struct pci_dev *dev, const struct pci_device_id *id) err4: if (driver->flags & HCD_MEMORY) { - iounmap (hcd->regs); + iounmap(hcd->regs); err3: - release_mem_region (hcd->rsrc_start, hcd->rsrc_len); + release_mem_region(hcd->rsrc_start, hcd->rsrc_len); } else - release_region (hcd->rsrc_start, hcd->rsrc_len); + release_region(hcd->rsrc_start, hcd->rsrc_len); err2: - usb_put_hcd (hcd); + usb_put_hcd(hcd); err1: - pci_disable_device (dev); - dev_err (&dev->dev, "init %s fail, %d\n", pci_name(dev), retval); + pci_disable_device(dev); + dev_err(&dev->dev, "init %s fail, %d\n", pci_name(dev), retval); return retval; -} +} EXPORT_SYMBOL_GPL(usb_hcd_pci_probe); @@ -161,7 +166,7 @@ EXPORT_SYMBOL_GPL(usb_hcd_pci_probe); * * Store this function in the HCD's struct pci_driver as remove(). */ -void usb_hcd_pci_remove (struct pci_dev *dev) +void usb_hcd_pci_remove(struct pci_dev *dev) { struct usb_hcd *hcd; @@ -169,14 +174,14 @@ void usb_hcd_pci_remove (struct pci_dev *dev) if (!hcd) return; - usb_remove_hcd (hcd); + usb_remove_hcd(hcd); if (hcd->driver->flags & HCD_MEMORY) { - iounmap (hcd->regs); - release_mem_region (hcd->rsrc_start, hcd->rsrc_len); + iounmap(hcd->regs); + release_mem_region(hcd->rsrc_start, hcd->rsrc_len); } else { - release_region (hcd->rsrc_start, hcd->rsrc_len); + release_region(hcd->rsrc_start, hcd->rsrc_len); } - usb_put_hcd (hcd); + usb_put_hcd(hcd); pci_disable_device(dev); } EXPORT_SYMBOL_GPL(usb_hcd_pci_remove); @@ -191,7 +196,7 @@ EXPORT_SYMBOL_GPL(usb_hcd_pci_remove); * * Store this function in the HCD's struct pci_driver as suspend(). */ -int usb_hcd_pci_suspend (struct pci_dev *dev, pm_message_t message) +int usb_hcd_pci_suspend(struct pci_dev *dev, pm_message_t message) { struct usb_hcd *hcd; int retval = 0; @@ -246,8 +251,8 @@ int usb_hcd_pci_suspend (struct pci_dev *dev, pm_message_t message) /* no DMA or IRQs except when HC is active */ if (dev->current_state == PCI_D0) { - pci_save_state (dev); - pci_disable_device (dev); + pci_save_state(dev); + pci_disable_device(dev); } if (message.event == PM_EVENT_FREEZE || @@ -257,7 +262,7 @@ int usb_hcd_pci_suspend (struct pci_dev *dev, pm_message_t message) } if (!has_pci_pm) { - dev_dbg (hcd->self.controller, "--> PCI D0/legacy\n"); + dev_dbg(hcd->self.controller, "--> PCI D0/legacy\n"); goto done; } @@ -266,30 +271,30 @@ int usb_hcd_pci_suspend (struct pci_dev *dev, pm_message_t message) * PCI_D3 (but not PCI_D1 or PCI_D2) is allowed to reset * some device state (e.g. as part of clock reinit). */ - retval = pci_set_power_state (dev, PCI_D3hot); + retval = pci_set_power_state(dev, PCI_D3hot); suspend_report_result(pci_set_power_state, retval); if (retval == 0) { int wake = device_can_wakeup(&hcd->self.root_hub->dev); wake = wake && device_may_wakeup(hcd->self.controller); - dev_dbg (hcd->self.controller, "--> PCI D3%s\n", + dev_dbg(hcd->self.controller, "--> PCI D3%s\n", wake ? "/wakeup" : ""); /* Ignore these return values. We rely on pci code to * reject requests the hardware can't implement, rather * than coding the same thing. */ - (void) pci_enable_wake (dev, PCI_D3hot, wake); - (void) pci_enable_wake (dev, PCI_D3cold, wake); + (void) pci_enable_wake(dev, PCI_D3hot, wake); + (void) pci_enable_wake(dev, PCI_D3cold, wake); } else { - dev_dbg (&dev->dev, "PCI D3 suspend fail, %d\n", + dev_dbg(&dev->dev, "PCI D3 suspend fail, %d\n", retval); - (void) usb_hcd_pci_resume (dev); + (void) usb_hcd_pci_resume(dev); } } else if (hcd->state != HC_STATE_HALT) { - dev_dbg (hcd->self.controller, "hcd state %d; not suspended\n", + dev_dbg(hcd->self.controller, "hcd state %d; not suspended\n", hcd->state); WARN_ON(1); retval = -EINVAL; @@ -304,7 +309,7 @@ done: if (machine_is(powermac)) { struct device_node *of_node; - of_node = pci_device_to_OF_node (dev); + of_node = pci_device_to_OF_node(dev); if (of_node) pmac_call_feature(PMAC_FTR_USB_ENABLE, of_node, 0, 0); @@ -322,14 +327,14 @@ EXPORT_SYMBOL_GPL(usb_hcd_pci_suspend); * * Store this function in the HCD's struct pci_driver as resume(). */ -int usb_hcd_pci_resume (struct pci_dev *dev) +int usb_hcd_pci_resume(struct pci_dev *dev) { struct usb_hcd *hcd; int retval; hcd = pci_get_drvdata(dev); if (hcd->state != HC_STATE_SUSPENDED) { - dev_dbg (hcd->self.controller, + dev_dbg(hcd->self.controller, "can't resume, not suspended!\n"); return 0; } @@ -339,9 +344,9 @@ int usb_hcd_pci_resume (struct pci_dev *dev) if (machine_is(powermac)) { struct device_node *of_node; - of_node = pci_device_to_OF_node (dev); + of_node = pci_device_to_OF_node(dev); if (of_node) - pmac_call_feature (PMAC_FTR_USB_ENABLE, + pmac_call_feature(PMAC_FTR_USB_ENABLE, of_node, 0, 1); } #endif @@ -380,8 +385,8 @@ int usb_hcd_pci_resume (struct pci_dev *dev) } #endif /* yes, ignore these results too... */ - (void) pci_enable_wake (dev, dev->current_state, 0); - (void) pci_enable_wake (dev, PCI_D3cold, 0); + (void) pci_enable_wake(dev, dev->current_state, 0); + (void) pci_enable_wake(dev, PCI_D3cold, 0); } else { /* Same basic cases: clean (powered/not), dirty */ dev_dbg(hcd->self.controller, "PCI legacy resume\n"); @@ -392,14 +397,14 @@ int usb_hcd_pci_resume (struct pci_dev *dev) * but that won't re-enable bus mastering. Yet pci_disable_device() * explicitly disables bus mastering... */ - retval = pci_enable_device (dev); + retval = pci_enable_device(dev); if (retval < 0) { - dev_err (hcd->self.controller, + dev_err(hcd->self.controller, "can't re-enable after resume, %d!\n", retval); return retval; } - pci_set_master (dev); - pci_restore_state (dev); + pci_set_master(dev); + pci_restore_state(dev); dev->dev.power.power_state = PMSG_ON; @@ -408,9 +413,9 @@ int usb_hcd_pci_resume (struct pci_dev *dev) if (hcd->driver->resume) { retval = hcd->driver->resume(hcd); if (retval) { - dev_err (hcd->self.controller, + dev_err(hcd->self.controller, "PCI post-resume error %d!\n", retval); - usb_hc_died (hcd); + usb_hc_died(hcd); } } @@ -424,7 +429,7 @@ EXPORT_SYMBOL_GPL(usb_hcd_pci_resume); * usb_hcd_pci_shutdown - shutdown host controller * @dev: USB Host Controller being shutdown */ -void usb_hcd_pci_shutdown (struct pci_dev *dev) +void usb_hcd_pci_shutdown(struct pci_dev *dev) { struct usb_hcd *hcd; -- cgit v1.2.3 From 3e35bf39e0b9091d47a40e26fc2704b3b24e1ec4 Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Wed, 30 Jan 2008 15:21:33 -0800 Subject: USB: fix codingstyle issues in drivers/usb/core/message.c Fixes a number of coding style issues in the message.c file. Signed-off-by: Greg Kroah-Hartman --- drivers/usb/core/message.c | 398 +++++++++++++++++++++++---------------------- 1 file changed, 204 insertions(+), 194 deletions(-) diff --git a/drivers/usb/core/message.c b/drivers/usb/core/message.c index 58b8e1c6b9a6..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) * own interruptible routines. */ static int usb_start_wait_urb(struct urb *urb, int timeout, int *actual_length) -{ +{ struct api_context ctx; unsigned long expire; int retval; @@ -74,9 +74,9 @@ out: } /*-------------------------------------------------------------------*/ -// returns status (negative) or length (positive) +/* returns status (negative) or length (positive) */ static int usb_internal_control_msg(struct usb_device *usb_dev, - unsigned int pipe, + unsigned int pipe, struct usb_ctrlrequest *cmd, void *data, int len, int timeout) { @@ -87,7 +87,7 @@ static int usb_internal_control_msg(struct usb_device *usb_dev, urb = usb_alloc_urb(0, GFP_NOIO); if (!urb) return -ENOMEM; - + usb_fill_control_urb(urb, usb_dev, pipe, (unsigned char *)cmd, data, len, usb_api_blocking_completion, NULL); @@ -99,47 +99,51 @@ static int usb_internal_control_msg(struct usb_device *usb_dev, } /** - * usb_control_msg - Builds a control urb, sends it off and waits for completion - * @dev: pointer to the usb device to send the message to - * @pipe: endpoint "pipe" to send the message to - * @request: USB message request value - * @requesttype: USB message request type value - * @value: USB message value - * @index: USB message index value - * @data: pointer to the data to send - * @size: length in bytes of the data to send - * @timeout: time in msecs to wait for the message to complete before - * timing out (if 0 the wait is forever) - * Context: !in_interrupt () - * - * This function sends a simple control message to a specified endpoint - * and waits for the message to complete, or timeout. - * - * If successful, it returns the number of bytes transferred, otherwise a negative error number. - * - * Don't use this function from within an interrupt context, like a - * bottom half handler. If you need an asynchronous message, or need to send - * a message from within interrupt context, use usb_submit_urb() - * If a thread in your driver uses this call, make sure your disconnect() - * method can wait for it to complete. Since you don't have a handle on - * the URB used, you can't cancel the request. + * usb_control_msg - Builds a control urb, sends it off and waits for completion + * @dev: pointer to the usb device to send the message to + * @pipe: endpoint "pipe" to send the message to + * @request: USB message request value + * @requesttype: USB message request type value + * @value: USB message value + * @index: USB message index value + * @data: pointer to the data to send + * @size: length in bytes of the data to send + * @timeout: time in msecs to wait for the message to complete before timing + * out (if 0 the wait is forever) + * + * Context: !in_interrupt () + * + * This function sends a simple control message to a specified endpoint and + * waits for the message to complete, or timeout. + * + * If successful, it returns the number of bytes transferred, otherwise a + * negative error number. + * + * Don't use this function from within an interrupt context, like a bottom half + * handler. If you need an asynchronous message, or need to send a message + * from within interrupt context, use usb_submit_urb(). + * If a thread in your driver uses this call, make sure your disconnect() + * method can wait for it to complete. Since you don't have a handle on the + * URB used, you can't cancel the request. */ -int usb_control_msg(struct usb_device *dev, unsigned int pipe, __u8 request, __u8 requesttype, - __u16 value, __u16 index, void *data, __u16 size, int timeout) +int usb_control_msg(struct usb_device *dev, unsigned int pipe, __u8 request, + __u8 requesttype, __u16 value, __u16 index, void *data, + __u16 size, int timeout) { - struct usb_ctrlrequest *dr = kmalloc(sizeof(struct usb_ctrlrequest), GFP_NOIO); + struct usb_ctrlrequest *dr; int ret; - + + dr = kmalloc(sizeof(struct usb_ctrlrequest), GFP_NOIO); if (!dr) return -ENOMEM; - dr->bRequestType= requesttype; + dr->bRequestType = requesttype; dr->bRequest = request; dr->wValue = cpu_to_le16p(&value); dr->wIndex = cpu_to_le16p(&index); dr->wLength = cpu_to_le16p(&size); - //dbg("usb_control_msg"); + /* dbg("usb_control_msg"); */ ret = usb_internal_control_msg(dev, pipe, dr, data, size, timeout); @@ -155,9 +159,11 @@ EXPORT_SYMBOL_GPL(usb_control_msg); * @pipe: endpoint "pipe" to send the message to * @data: pointer to the data to send * @len: length in bytes of the data to send - * @actual_length: pointer to a location to put the actual length transferred in bytes + * @actual_length: pointer to a location to put the actual length transferred + * in bytes * @timeout: time in msecs to wait for the message to complete before * timing out (if 0 the wait is forever) + * * Context: !in_interrupt () * * 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, EXPORT_SYMBOL_GPL(usb_interrupt_msg); /** - * usb_bulk_msg - Builds a bulk urb, sends it off and waits for completion - * @usb_dev: pointer to the usb device to send the message to - * @pipe: endpoint "pipe" to send the message to - * @data: pointer to the data to send - * @len: length in bytes of the data to send - * @actual_length: pointer to a location to put the actual length transferred in bytes - * @timeout: time in msecs to wait for the message to complete before - * timing out (if 0 the wait is forever) - * Context: !in_interrupt () - * - * This function sends a simple bulk message to a specified endpoint - * and waits for the message to complete, or timeout. - * - * If successful, it returns 0, otherwise a negative error number. - * The number of actual bytes transferred will be stored in the - * actual_length paramater. - * - * Don't use this function from within an interrupt context, like a - * bottom half handler. If you need an asynchronous message, or need to - * send a message from within interrupt context, use usb_submit_urb() - * If a thread in your driver uses this call, make sure your disconnect() - * method can wait for it to complete. Since you don't have a handle on - * the URB used, you can't cancel the request. - * - * Because there is no usb_interrupt_msg() and no USBDEVFS_INTERRUPT - * ioctl, users are forced to abuse this routine by using it to submit - * URBs for interrupt endpoints. We will take the liberty of creating - * an interrupt URB (with the default interval) if the target is an - * interrupt endpoint. + * usb_bulk_msg - Builds a bulk urb, sends it off and waits for completion + * @usb_dev: pointer to the usb device to send the message to + * @pipe: endpoint "pipe" to send the message to + * @data: pointer to the data to send + * @len: length in bytes of the data to send + * @actual_length: pointer to a location to put the actual length transferred + * in bytes + * @timeout: time in msecs to wait for the message to complete before + * timing out (if 0 the wait is forever) + * + * Context: !in_interrupt () + * + * This function sends a simple bulk message to a specified endpoint + * and waits for the message to complete, or timeout. + * + * If successful, it returns 0, otherwise a negative error number. The number + * of actual bytes transferred will be stored in the actual_length paramater. + * + * Don't use this function from within an interrupt context, like a bottom half + * handler. If you need an asynchronous message, or need to send a message + * from within interrupt context, use usb_submit_urb() If a thread in your + * driver uses this call, make sure your disconnect() method can wait for it to + * complete. Since you don't have a handle on the URB used, you can't cancel + * the request. + * + * Because there is no usb_interrupt_msg() and no USBDEVFS_INTERRUPT ioctl, + * users are forced to abuse this routine by using it to submit URBs for + * interrupt endpoints. We will take the liberty of creating an interrupt URB + * (with the default interval) if the target is an interrupt endpoint. */ -int usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe, - void *data, int len, int *actual_length, int timeout) +int usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe, + void *data, int len, int *actual_length, int timeout) { struct urb *urb; struct usb_host_endpoint *ep; @@ -242,26 +248,26 @@ EXPORT_SYMBOL_GPL(usb_bulk_msg); /*-------------------------------------------------------------------*/ -static void sg_clean (struct usb_sg_request *io) +static void sg_clean(struct usb_sg_request *io) { if (io->urbs) { while (io->entries--) - usb_free_urb (io->urbs [io->entries]); - kfree (io->urbs); + usb_free_urb(io->urbs [io->entries]); + kfree(io->urbs); io->urbs = NULL; } if (io->dev->dev.dma_mask != NULL) - usb_buffer_unmap_sg (io->dev, usb_pipein(io->pipe), - io->sg, io->nents); + usb_buffer_unmap_sg(io->dev, usb_pipein(io->pipe), + io->sg, io->nents); io->dev = NULL; } -static void sg_complete (struct urb *urb) +static void sg_complete(struct urb *urb) { - struct usb_sg_request *io = urb->context; + struct usb_sg_request *io = urb->context; int status = urb->status; - spin_lock (&io->lock); + spin_lock(&io->lock); /* In 2.5 we require hcds' endpoint queues not to progress after fault * reports, until the completion callback (this!) returns. That lets @@ -277,13 +283,13 @@ static void sg_complete (struct urb *urb) && (io->status != -ECONNRESET || status != -ECONNRESET) && urb->actual_length) { - dev_err (io->dev->bus->controller, + dev_err(io->dev->bus->controller, "dev %s ep%d%s scatterlist error %d/%d\n", io->dev->devpath, usb_endpoint_num(&urb->ep->desc), usb_urb_dir_in(urb) ? "in" : "out", status, io->status); - // BUG (); + /* BUG (); */ } if (io->status == 0 && status && status != -ECONNRESET) { @@ -295,22 +301,22 @@ static void sg_complete (struct urb *urb) * unlink pending urbs so they won't rx/tx bad data. * careful: unlink can sometimes be synchronous... */ - spin_unlock (&io->lock); + spin_unlock(&io->lock); for (i = 0, found = 0; i < io->entries; i++) { if (!io->urbs [i] || !io->urbs [i]->dev) continue; if (found) { - retval = usb_unlink_urb (io->urbs [i]); + retval = usb_unlink_urb(io->urbs [i]); if (retval != -EINPROGRESS && retval != -ENODEV && retval != -EBUSY) - dev_err (&io->dev->dev, + dev_err(&io->dev->dev, "%s, unlink --> %d\n", __FUNCTION__, retval); } else if (urb == io->urbs [i]) found = 1; } - spin_lock (&io->lock); + spin_lock(&io->lock); } urb->dev = NULL; @@ -318,9 +324,9 @@ static void sg_complete (struct urb *urb) io->bytes += urb->actual_length; io->count--; if (!io->count) - complete (&io->complete); + complete(&io->complete); - spin_unlock (&io->lock); + spin_unlock(&io->lock); } @@ -349,28 +355,21 @@ static void sg_complete (struct urb *urb) * The request may be canceled with usb_sg_cancel(), either before or after * usb_sg_wait() is called. */ -int usb_sg_init ( - struct usb_sg_request *io, - struct usb_device *dev, - unsigned pipe, - unsigned period, - struct scatterlist *sg, - int nents, - size_t length, - gfp_t mem_flags -) +int usb_sg_init(struct usb_sg_request *io, struct usb_device *dev, + unsigned pipe, unsigned period, struct scatterlist *sg, + int nents, size_t length, gfp_t mem_flags) { - int i; - int urb_flags; - int dma; + int i; + int urb_flags; + int dma; if (!io || !dev || !sg - || usb_pipecontrol (pipe) - || usb_pipeisoc (pipe) + || usb_pipecontrol(pipe) + || usb_pipeisoc(pipe) || nents <= 0) return -EINVAL; - spin_lock_init (&io->lock); + spin_lock_init(&io->lock); io->dev = dev; io->pipe = pipe; io->sg = sg; @@ -382,7 +381,7 @@ int usb_sg_init ( dma = (dev->dev.dma_mask != NULL); if (dma) io->entries = usb_buffer_map_sg(dev, usb_pipein(pipe), - sg, nents); + sg, nents); else io->entries = nents; @@ -391,30 +390,30 @@ int usb_sg_init ( return io->entries; io->count = io->entries; - io->urbs = kmalloc (io->entries * sizeof *io->urbs, mem_flags); + io->urbs = kmalloc(io->entries * sizeof *io->urbs, mem_flags); if (!io->urbs) goto nomem; urb_flags = URB_NO_TRANSFER_DMA_MAP | URB_NO_INTERRUPT; - if (usb_pipein (pipe)) + if (usb_pipein(pipe)) urb_flags |= URB_SHORT_NOT_OK; for (i = 0; i < io->entries; i++) { - unsigned len; + unsigned len; - io->urbs [i] = usb_alloc_urb (0, mem_flags); - if (!io->urbs [i]) { + io->urbs[i] = usb_alloc_urb(0, mem_flags); + if (!io->urbs[i]) { io->entries = i; goto nomem; } - io->urbs [i]->dev = NULL; - io->urbs [i]->pipe = pipe; - io->urbs [i]->interval = period; - io->urbs [i]->transfer_flags = urb_flags; + io->urbs[i]->dev = NULL; + io->urbs[i]->pipe = pipe; + io->urbs[i]->interval = period; + io->urbs[i]->transfer_flags = urb_flags; - io->urbs [i]->complete = sg_complete; - io->urbs [i]->context = io; + io->urbs[i]->complete = sg_complete; + io->urbs[i]->context = io; /* * Some systems need to revert to PIO when DMA is temporarily @@ -433,8 +432,8 @@ int usb_sg_init ( * to prevent stale pointers and to help spot bugs. */ if (dma) { - io->urbs [i]->transfer_dma = sg_dma_address (sg + i); - len = sg_dma_len (sg + i); + io->urbs[i]->transfer_dma = sg_dma_address(sg + i); + len = sg_dma_len(sg + i); #if defined(CONFIG_HIGHMEM) || defined(CONFIG_GART_IOMMU) io->urbs[i]->transfer_buffer = NULL; #else @@ -442,28 +441,28 @@ int usb_sg_init ( #endif } else { /* hc may use _only_ transfer_buffer */ - io->urbs [i]->transfer_buffer = sg_virt(&sg[i]); - len = sg [i].length; + io->urbs[i]->transfer_buffer = sg_virt(&sg[i]); + len = sg[i].length; } if (length) { - len = min_t (unsigned, len, length); + len = min_t(unsigned, len, length); length -= len; if (length == 0) io->entries = i + 1; } - io->urbs [i]->transfer_buffer_length = len; + io->urbs[i]->transfer_buffer_length = len; } - io->urbs [--i]->transfer_flags &= ~URB_NO_INTERRUPT; + io->urbs[--i]->transfer_flags &= ~URB_NO_INTERRUPT; /* transaction state */ io->status = 0; io->bytes = 0; - init_completion (&io->complete); + init_completion(&io->complete); return 0; nomem: - sg_clean (io); + sg_clean(io); return -ENOMEM; } EXPORT_SYMBOL_GPL(usb_sg_init); @@ -507,31 +506,32 @@ EXPORT_SYMBOL_GPL(usb_sg_init); * speed interrupt endpoints, which allow at most one packet per millisecond, * of at most 8 or 64 bytes (respectively). */ -void usb_sg_wait (struct usb_sg_request *io) +void usb_sg_wait(struct usb_sg_request *io) { - int i, entries = io->entries; + int i; + int entries = io->entries; /* queue the urbs. */ - spin_lock_irq (&io->lock); + spin_lock_irq(&io->lock); i = 0; while (i < entries && !io->status) { - int retval; + int retval; - io->urbs [i]->dev = io->dev; - retval = usb_submit_urb (io->urbs [i], GFP_ATOMIC); + io->urbs[i]->dev = io->dev; + retval = usb_submit_urb(io->urbs [i], GFP_ATOMIC); /* after we submit, let completions or cancelations fire; * we handshake using io->status. */ - spin_unlock_irq (&io->lock); + spin_unlock_irq(&io->lock); switch (retval) { /* maybe we retrying will recover */ - case -ENXIO: // hc didn't queue this one + case -ENXIO: /* hc didn't queue this one */ case -EAGAIN: case -ENOMEM: io->urbs[i]->dev = NULL; retval = 0; - yield (); + yield(); break; /* no error? continue immediately. @@ -542,33 +542,33 @@ void usb_sg_wait (struct usb_sg_request *io) */ case 0: ++i; - cpu_relax (); + cpu_relax(); break; /* fail any uncompleted urbs */ default: - io->urbs [i]->dev = NULL; - io->urbs [i]->status = retval; - dev_dbg (&io->dev->dev, "%s, submit --> %d\n", + io->urbs[i]->dev = NULL; + io->urbs[i]->status = retval; + dev_dbg(&io->dev->dev, "%s, submit --> %d\n", __FUNCTION__, retval); - usb_sg_cancel (io); + usb_sg_cancel(io); } - spin_lock_irq (&io->lock); + spin_lock_irq(&io->lock); if (retval && (io->status == 0 || io->status == -ECONNRESET)) io->status = retval; } io->count -= entries - i; if (io->count == 0) - complete (&io->complete); - spin_unlock_irq (&io->lock); + complete(&io->complete); + spin_unlock_irq(&io->lock); /* OK, yes, this could be packaged as non-blocking. * So could the submit loop above ... but it's easier to * solve neither problem than to solve both! */ - wait_for_completion (&io->complete); + wait_for_completion(&io->complete); - sg_clean (io); + sg_clean(io); } EXPORT_SYMBOL_GPL(usb_sg_wait); @@ -580,31 +580,31 @@ EXPORT_SYMBOL_GPL(usb_sg_wait); * It can also prevents one initialized by usb_sg_init() from starting, * so that call just frees resources allocated to the request. */ -void usb_sg_cancel (struct usb_sg_request *io) +void usb_sg_cancel(struct usb_sg_request *io) { - unsigned long flags; + unsigned long flags; - spin_lock_irqsave (&io->lock, flags); + spin_lock_irqsave(&io->lock, flags); /* shut everything down, if it didn't already */ if (!io->status) { - int i; + int i; io->status = -ECONNRESET; - spin_unlock (&io->lock); + spin_unlock(&io->lock); for (i = 0; i < io->entries; i++) { - int retval; + int retval; if (!io->urbs [i]->dev) continue; - retval = usb_unlink_urb (io->urbs [i]); + retval = usb_unlink_urb(io->urbs [i]); if (retval != -EINPROGRESS && retval != -EBUSY) - dev_warn (&io->dev->dev, "%s, unlink --> %d\n", + dev_warn(&io->dev->dev, "%s, unlink --> %d\n", __FUNCTION__, retval); } - spin_lock (&io->lock); + spin_lock(&io->lock); } - spin_unlock_irqrestore (&io->lock, flags); + spin_unlock_irqrestore(&io->lock, flags); } EXPORT_SYMBOL_GPL(usb_sg_cancel); @@ -632,12 +632,13 @@ EXPORT_SYMBOL_GPL(usb_sg_cancel); * Returns the number of bytes received on success, or else the status code * returned by the underlying usb_control_msg() call. */ -int usb_get_descriptor(struct usb_device *dev, unsigned char type, unsigned char index, void *buf, int size) +int usb_get_descriptor(struct usb_device *dev, unsigned char type, + unsigned char index, void *buf, int size) { int i; int result; - - memset(buf,0,size); // Make sure we parse really received data + + memset(buf, 0, size); /* Make sure we parse really received data */ for (i = 0; i < 3; ++i) { /* retry on length 0 or error; some devices are flakey */ @@ -712,7 +713,7 @@ static void usb_try_string_workarounds(unsigned char *buf, int *length) } static int usb_string_sub(struct usb_device *dev, unsigned int langid, - unsigned int index, unsigned char *buf) + unsigned int index, unsigned char *buf) { int rc; @@ -755,7 +756,7 @@ static int usb_string_sub(struct usb_device *dev, unsigned int langid, * @buf: where to put the string * @size: how big is "buf"? * Context: !in_interrupt () - * + * * This converts the UTF-16LE encoded strings returned by devices, from * usb_get_string_descriptor(), to null-terminated ISO-8859-1 encoded ones * that are more usable in most kernel contexts. Note that all characters @@ -791,23 +792,23 @@ int usb_string(struct usb_device *dev, int index, char *buf, size_t size) if (!dev->have_langid) { err = usb_string_sub(dev, 0, 0, tbuf); if (err < 0) { - dev_err (&dev->dev, + dev_err(&dev->dev, "string descriptor 0 read error: %d\n", err); goto errout; } else if (err < 4) { - dev_err (&dev->dev, "string descriptor 0 too short\n"); + dev_err(&dev->dev, "string descriptor 0 too short\n"); err = -EINVAL; goto errout; } else { dev->have_langid = 1; - dev->string_langid = tbuf[2] | (tbuf[3]<< 8); - /* always use the first langid listed */ - dev_dbg (&dev->dev, "default language 0x%04x\n", + dev->string_langid = tbuf[2] | (tbuf[3] << 8); + /* always use the first langid listed */ + dev_dbg(&dev->dev, "default language 0x%04x\n", dev->string_langid); } } - + err = usb_string_sub(dev, dev->string_langid, index, tbuf); if (err < 0) goto errout; @@ -825,7 +826,9 @@ int usb_string(struct usb_device *dev, int index, char *buf, size_t size) err = idx; if (tbuf[1] != USB_DT_STRING) - dev_dbg(&dev->dev, "wrong descriptor type %02x for string %d (\"%s\")\n", tbuf[1], index, buf); + dev_dbg(&dev->dev, + "wrong descriptor type %02x for string %d (\"%s\")\n", + tbuf[1], index, buf); errout: kfree(tbuf); @@ -847,9 +850,15 @@ char *usb_cache_string(struct usb_device *udev, int index) char *smallbuf = NULL; int len; - if (index > 0 && (buf = kmalloc(256, GFP_KERNEL)) != NULL) { - if ((len = usb_string(udev, index, buf, 256)) > 0) { - if ((smallbuf = kmalloc(++len, GFP_KERNEL)) == NULL) + if (index <= 0) + return NULL; + + buf = kmalloc(256, GFP_KERNEL); + if (buf) { + len = usb_string(udev, index, buf, 256); + if (len > 0) { + smallbuf = kmalloc(++len, GFP_KERNEL); + if (!smallbuf) return buf; memcpy(smallbuf, buf, len); } @@ -888,7 +897,7 @@ int usb_get_device_descriptor(struct usb_device *dev, unsigned int size) return -ENOMEM; ret = usb_get_descriptor(dev, USB_DT_DEVICE, 0, desc, size); - if (ret >= 0) + if (ret >= 0) memcpy(&dev->descriptor, desc, size); kfree(desc); return ret; @@ -961,8 +970,8 @@ int usb_clear_halt(struct usb_device *dev, int pipe) { int result; int endp = usb_pipeendpoint(pipe); - - if (usb_pipein (pipe)) + + if (usb_pipein(pipe)) endp |= USB_DIR_IN; /* we don't care if it wasn't halted first. in fact some devices @@ -1045,7 +1054,7 @@ void usb_disable_interface(struct usb_device *dev, struct usb_interface *intf) } } -/* +/** * usb_disable_device - Disable all the endpoints for a USB device * @dev: the device whose endpoints are being disabled * @skip_ep0: 0 to disable endpoint 0, 1 to skip it. @@ -1060,7 +1069,7 @@ void usb_disable_device(struct usb_device *dev, int skip_ep0) int i; dev_dbg(&dev->dev, "%s nuking %s URBs\n", __FUNCTION__, - skip_ep0 ? "non-ep0" : "all"); + skip_ep0 ? "non-ep0" : "all"); for (i = skip_ep0; i < 16; ++i) { usb_disable_endpoint(dev, i); usb_disable_endpoint(dev, i + USB_DIR_IN); @@ -1078,17 +1087,17 @@ void usb_disable_device(struct usb_device *dev, int skip_ep0) interface = dev->actconfig->interface[i]; if (!device_is_registered(&interface->dev)) continue; - dev_dbg (&dev->dev, "unregistering interface %s\n", + dev_dbg(&dev->dev, "unregistering interface %s\n", interface->dev.bus_id); usb_remove_sysfs_intf_files(interface); - device_del (&interface->dev); + device_del(&interface->dev); } /* Now that the interfaces are unbound, nobody should * try to access them. */ for (i = 0; i < dev->actconfig->desc.bNumInterfaces; i++) { - put_device (&dev->actconfig->interface[i]->dev); + put_device(&dev->actconfig->interface[i]->dev); dev->actconfig->interface[i] = NULL; } dev->actconfig = NULL; @@ -1097,8 +1106,7 @@ void usb_disable_device(struct usb_device *dev, int skip_ep0) } } - -/* +/** * usb_enable_endpoint - Enable an endpoint for USB communications * @dev: the device whose interface is being enabled * @ep: the endpoint @@ -1123,7 +1131,7 @@ void usb_enable_endpoint(struct usb_device *dev, struct usb_host_endpoint *ep) ep->enabled = 1; } -/* +/** * usb_enable_interface - Enable all the endpoints for an interface * @dev: the device whose interface is being enabled * @intf: pointer to the interface descriptor @@ -1179,6 +1187,8 @@ int usb_set_interface(struct usb_device *dev, int interface, int alternate) struct usb_host_interface *alt; int ret; int manual = 0; + unsigned int epaddr; + unsigned int pipe; if (dev->state == USB_STATE_SUSPENDED) return -EHOSTUNREACH; @@ -1233,11 +1243,11 @@ int usb_set_interface(struct usb_device *dev, int interface, int alternate) int i; for (i = 0; i < alt->desc.bNumEndpoints; i++) { - unsigned int epaddr = - alt->endpoint[i].desc.bEndpointAddress; - unsigned int pipe = - __create_pipe(dev, USB_ENDPOINT_NUMBER_MASK & epaddr) - | (usb_endpoint_out(epaddr) ? USB_DIR_OUT : USB_DIR_IN); + epaddr = alt->endpoint[i].desc.bEndpointAddress; + pipe = __create_pipe(dev, + USB_ENDPOINT_NUMBER_MASK & epaddr) | + (usb_endpoint_out(epaddr) ? + USB_DIR_OUT : USB_DIR_IN); usb_clear_halt(dev, pipe); } @@ -1366,7 +1376,8 @@ static int usb_if_uevent(struct device *dev, struct kobj_uevent_env *env) return -ENOMEM; if (add_uevent_var(env, - "MODALIAS=usb:v%04Xp%04Xd%04Xdc%02Xdsc%02Xdp%02Xic%02Xisc%02Xip%02X", + "MODALIAS=usb:" + "v%04Xp%04Xd%04Xdc%02Xdsc%02Xdp%02Xic%02Xisc%02Xip%02X", le16_to_cpu(usb_dev->descriptor.idVendor), le16_to_cpu(usb_dev->descriptor.idProduct), le16_to_cpu(usb_dev->descriptor.bcdDevice), @@ -1396,8 +1407,8 @@ struct device_type usb_if_device_type = { }; static struct usb_interface_assoc_descriptor *find_iad(struct usb_device *dev, - struct usb_host_config *config, - u8 inum) + struct usb_host_config *config, + u8 inum) { struct usb_interface_assoc_descriptor *retval = NULL; struct usb_interface_assoc_descriptor *intf_assoc; @@ -1424,7 +1435,6 @@ static struct usb_interface_assoc_descriptor *find_iad(struct usb_device *dev, return retval; } - /* * usb_set_configuration - Makes a particular device setting be current * @dev: the device whose configuration is being updated @@ -1542,12 +1552,12 @@ free_interfaces: * getting rid of old interfaces means unbinding their drivers. */ if (dev->state != USB_STATE_ADDRESS) - usb_disable_device (dev, 1); // Skip ep0 - - if ((ret = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), - USB_REQ_SET_CONFIGURATION, 0, configuration, 0, - NULL, 0, USB_CTRL_SET_TIMEOUT)) < 0) { + usb_disable_device(dev, 1); /* Skip ep0 */ + ret = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), + USB_REQ_SET_CONFIGURATION, 0, configuration, 0, + NULL, 0, USB_CTRL_SET_TIMEOUT); + if (ret < 0) { /* All the old state is gone, so what else can we do? * The device is probably useless now anyway. */ @@ -1594,11 +1604,11 @@ free_interfaces: intf->dev.bus = &usb_bus_type; intf->dev.type = &usb_if_device_type; intf->dev.dma_mask = dev->dev.dma_mask; - device_initialize (&intf->dev); + device_initialize(&intf->dev); mark_quiesced(intf); - sprintf (&intf->dev.bus_id[0], "%d-%s:%d.%d", - dev->bus->busnum, dev->devpath, - configuration, alt->desc.bInterfaceNumber); + sprintf(&intf->dev.bus_id[0], "%d-%s:%d.%d", + dev->bus->busnum, dev->devpath, + configuration, alt->desc.bInterfaceNumber); } kfree(new_interfaces); @@ -1614,11 +1624,11 @@ free_interfaces: for (i = 0; i < nintf; ++i) { struct usb_interface *intf = cp->interface[i]; - dev_dbg (&dev->dev, + dev_dbg(&dev->dev, "adding %s (config #%d, interface %d)\n", intf->dev.bus_id, configuration, intf->cur_altsetting->desc.bInterfaceNumber); - ret = device_add (&intf->dev); + ret = device_add(&intf->dev); if (ret != 0) { dev_err(&dev->dev, "device_add(%s) --> %d\n", intf->dev.bus_id, ret); -- cgit v1.2.3 From 2c044a4803804708984931bcbd03314732e995d5 Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Wed, 30 Jan 2008 15:21:33 -0800 Subject: USB: fix codingstyle issues in drivers/usb/core/*.c Fixes a number of coding style issues in the remaining .c files in drivers/usb/core/ Signed-off-by: Greg Kroah-Hartman --- drivers/usb/core/buffer.c | 11 +++++----- drivers/usb/core/config.c | 14 +++++++------ drivers/usb/core/driver.c | 30 +++++++++++++++------------- drivers/usb/core/sysfs.c | 20 +++++++++---------- drivers/usb/core/urb.c | 22 ++++++++++---------- drivers/usb/core/usb.c | 51 ++++++++++++++++++++--------------------------- 6 files changed, 74 insertions(+), 74 deletions(-) diff --git a/drivers/usb/core/buffer.c b/drivers/usb/core/buffer.c index acd9f00a0b76..cadb2dc1d28a 100644 --- a/drivers/usb/core/buffer.c +++ b/drivers/usb/core/buffer.c @@ -57,8 +57,9 @@ int hcd_buffer_create(struct usb_hcd *hcd) !(hcd->driver->flags & HCD_LOCAL_MEM)) return 0; - for (i = 0; i < HCD_BUFFER_POOLS; i++) { - if (!(size = pool_max [i])) + for (i = 0; i < HCD_BUFFER_POOLS; i++) { + size = pool_max[i]; + if (!size) continue; snprintf(name, sizeof name, "buffer-%d", size); hcd->pool[i] = dma_pool_create(name, hcd->self.controller, @@ -81,10 +82,10 @@ int hcd_buffer_create(struct usb_hcd *hcd) */ void hcd_buffer_destroy(struct usb_hcd *hcd) { - int i; + int i; - for (i = 0; i < HCD_BUFFER_POOLS; i++) { - struct dma_pool *pool = hcd->pool[i]; + for (i = 0; i < HCD_BUFFER_POOLS; i++) { + struct dma_pool *pool = hcd->pool[i]; if (pool) { dma_pool_destroy(pool); hcd->pool[i] = NULL; 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, /* Allocate space for the right(?) number of endpoints */ num_ep = num_ep_orig = alt->desc.bNumEndpoints; - alt->desc.bNumEndpoints = 0; // Use as a counter + alt->desc.bNumEndpoints = 0; /* Use as a counter */ if (num_ep > USB_MAXENDPOINTS) { dev_warn(ddev, "too many endpoints for config %d interface %d " "altsetting %d: %d, using maximum allowed: %d\n", @@ -246,7 +246,8 @@ static int usb_parse_interface(struct device *ddev, int cfgno, num_ep = USB_MAXENDPOINTS; } - if (num_ep > 0) { /* Can't allocate 0 bytes */ + if (num_ep > 0) { + /* Can't allocate 0 bytes */ len = sizeof(struct usb_host_endpoint) * num_ep; alt->endpoint = kzalloc(len, GFP_KERNEL); if (!alt->endpoint) @@ -475,8 +476,9 @@ static int usb_parse_configuration(struct device *ddev, int cfgidx, return 0; } -// hub-only!! ... and only exported for reset/reinit path. -// otherwise used internally on disconnect/destroy path +/* hub-only!! ... and only exported for reset/reinit path. + * otherwise used internally on disconnect/destroy path + */ void usb_destroy_configuration(struct usb_device *dev) { int c, i; @@ -498,7 +500,7 @@ void usb_destroy_configuration(struct usb_device *dev) kfree(cf->string); for (i = 0; i < cf->desc.bNumInterfaces; i++) { if (cf->intf_cache[i]) - kref_put(&cf->intf_cache[i]->ref, + kref_put(&cf->intf_cache[i]->ref, usb_release_interface_cache); } } @@ -525,7 +527,7 @@ int usb_get_configuration(struct usb_device *dev) unsigned int cfgno, length; unsigned char *buffer; unsigned char *bigbuffer; - struct usb_config_descriptor *desc; + struct usb_config_descriptor *desc; cfgno = 0; if (dev->authorized == 0) /* Not really an error */ diff --git a/drivers/usb/core/driver.c b/drivers/usb/core/driver.c index 7e7f2c42494c..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) intf = to_usb_interface(dev); udev = interface_to_usbdev(intf); - if (udev->authorized == 0) { - dev_err(&intf->dev, "Device is not authorized for usage\n"); - return -ENODEV; - } + if (udev->authorized == 0) { + dev_err(&intf->dev, "Device is not authorized for usage\n"); + return -ENODEV; + } id = usb_match_id(intf, driver->id_table); if (!id) @@ -299,7 +299,7 @@ static int usb_unbind_interface(struct device *dev) * lock. */ int usb_driver_claim_interface(struct usb_driver *driver, - struct usb_interface *iface, void* priv) + struct usb_interface *iface, void *priv) { struct device *dev = &iface->dev; struct usb_device *udev = interface_to_usbdev(iface); @@ -398,7 +398,7 @@ int usb_match_device(struct usb_device *dev, const struct usb_device_id *id) return 0; if ((id->match_flags & USB_DEVICE_ID_MATCH_DEV_SUBCLASS) && - (id->bDeviceSubClass!= dev->descriptor.bDeviceSubClass)) + (id->bDeviceSubClass != dev->descriptor.bDeviceSubClass)) return 0; if ((id->match_flags & USB_DEVICE_ID_MATCH_DEV_PROTOCOL) && @@ -586,7 +586,7 @@ static int usb_uevent(struct device *dev, struct kobj_uevent_env *env) struct usb_device *usb_dev; /* driver is often null here; dev_dbg() would oops */ - pr_debug ("usb %s: uevent\n", dev->bus_id); + pr_debug("usb %s: uevent\n", dev->bus_id); if (is_usb_device(dev)) usb_dev = to_usb_device(dev); @@ -596,11 +596,11 @@ static int usb_uevent(struct device *dev, struct kobj_uevent_env *env) } if (usb_dev->devnum < 0) { - pr_debug ("usb %s: already deleted?\n", dev->bus_id); + pr_debug("usb %s: already deleted?\n", dev->bus_id); return -ENODEV; } if (!usb_dev->bus) { - pr_debug ("usb %s: bus removed?\n", dev->bus_id); + pr_debug("usb %s: bus removed?\n", dev->bus_id); return -ENODEV; } @@ -854,8 +854,10 @@ static int usb_suspend_interface(struct usb_interface *intf, pm_message_t msg) dev_err(&intf->dev, "%s error %d\n", "suspend", status); } else { - // FIXME else if there's no suspend method, disconnect... - // Not possible if auto_pm is set... + /* + * FIXME else if there's no suspend method, disconnect... + * Not possible if auto_pm is set... + */ dev_warn(&intf->dev, "no suspend for driver %s?\n", driver->name); mark_quiesced(intf); @@ -894,7 +896,7 @@ static int usb_resume_interface(struct usb_interface *intf, int reset_resume) dev_err(&intf->dev, "%s error %d\n", "reset_resume", status); } else { - // status = -EOPNOTSUPP; + /* status = -EOPNOTSUPP; */ dev_warn(&intf->dev, "no %s for driver %s?\n", "reset_resume", driver->name); } @@ -905,7 +907,7 @@ static int usb_resume_interface(struct usb_interface *intf, int reset_resume) dev_err(&intf->dev, "%s error %d\n", "resume", status); } else { - // status = -EOPNOTSUPP; + /* status = -EOPNOTSUPP; */ dev_warn(&intf->dev, "no %s for driver %s?\n", "resume", driver->name); } @@ -1175,7 +1177,7 @@ static int usb_resume_both(struct usb_device *udev) * so if a root hub's controller is suspended * then we're stuck. */ status = usb_resume_device(udev); - } + } } else { /* Needed for setting udev->dev.power.power_state.event, diff --git a/drivers/usb/core/sysfs.c b/drivers/usb/core/sysfs.c index 021b1d37462c..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, return (value < 0) ? value : count; } -static DEVICE_ATTR(bConfigurationValue, S_IRUGO | S_IWUSR, +static DEVICE_ATTR(bConfigurationValue, S_IRUGO | S_IWUSR, show_bConfigurationValue, set_bConfigurationValue); /* String fields */ @@ -650,21 +650,21 @@ void usb_remove_sysfs_dev_files(struct usb_device *udev) /* Interface Accociation Descriptor fields */ #define usb_intf_assoc_attr(field, format_string) \ static ssize_t \ -show_iad_##field (struct device *dev, struct device_attribute *attr, \ +show_iad_##field(struct device *dev, struct device_attribute *attr, \ char *buf) \ { \ - struct usb_interface *intf = to_usb_interface (dev); \ + struct usb_interface *intf = to_usb_interface(dev); \ \ - return sprintf (buf, format_string, \ - intf->intf_assoc->field); \ + return sprintf(buf, format_string, \ + intf->intf_assoc->field); \ } \ static DEVICE_ATTR(iad_##field, S_IRUGO, show_iad_##field, NULL); -usb_intf_assoc_attr (bFirstInterface, "%02x\n") -usb_intf_assoc_attr (bInterfaceCount, "%02d\n") -usb_intf_assoc_attr (bFunctionClass, "%02x\n") -usb_intf_assoc_attr (bFunctionSubClass, "%02x\n") -usb_intf_assoc_attr (bFunctionProtocol, "%02x\n") +usb_intf_assoc_attr(bFirstInterface, "%02x\n") +usb_intf_assoc_attr(bInterfaceCount, "%02d\n") +usb_intf_assoc_attr(bFunctionClass, "%02x\n") +usb_intf_assoc_attr(bFunctionSubClass, "%02x\n") +usb_intf_assoc_attr(bFunctionProtocol, "%02x\n") /* Interface fields */ #define usb_intf_attr(field, format_string) \ diff --git a/drivers/usb/core/urb.c b/drivers/usb/core/urb.c index 0b54dc174e2c..9d7e63292c01 100644 --- a/drivers/usb/core/urb.c +++ b/drivers/usb/core/urb.c @@ -103,7 +103,7 @@ EXPORT_SYMBOL_GPL(usb_free_urb); * * A pointer to the urb with the incremented reference counter is returned. */ -struct urb * usb_get_urb(struct urb *urb) +struct urb *usb_get_urb(struct urb *urb) { if (urb) kref_get(&urb->kref); @@ -176,7 +176,7 @@ EXPORT_SYMBOL_GPL(usb_unanchor_urb); * describing that request to the USB subsystem. Request completion will * be indicated later, asynchronously, by calling the completion handler. * The three types of completion are success, error, and unlink - * (a software-induced fault, also called "request cancellation"). + * (a software-induced fault, also called "request cancellation"). * * URBs may be submitted in interrupt context. * @@ -259,7 +259,7 @@ EXPORT_SYMBOL_GPL(usb_unanchor_urb); * semaphores), or * (c) current->state != TASK_RUNNING, this is the case only after * you've changed it. - * + * * GFP_NOIO is used in the block io path and error handling of storage * devices. * @@ -288,7 +288,8 @@ int usb_submit_urb(struct urb *urb, gfp_t mem_flags) if (!urb || urb->hcpriv || !urb->complete) return -EINVAL; - if (!(dev = urb->dev) || dev->state < USB_STATE_DEFAULT) + dev = urb->dev; + if ((!dev) || (dev->state < USB_STATE_DEFAULT)) return -ENODEV; /* For now, get the endpoint from the pipe. Eventually drivers @@ -351,11 +352,11 @@ int usb_submit_urb(struct urb *urb, gfp_t mem_flags) max *= mult; } - if (urb->number_of_packets <= 0) + if (urb->number_of_packets <= 0) return -EINVAL; for (n = 0; n < urb->number_of_packets; n++) { len = urb->iso_frame_desc[n].length; - if (len < 0 || len > max) + if (len < 0 || len > max) return -EMSGSIZE; urb->iso_frame_desc[n].status = -EXDEV; urb->iso_frame_desc[n].actual_length = 0; @@ -420,7 +421,7 @@ int usb_submit_urb(struct urb *urb, gfp_t mem_flags) /* too big? */ switch (dev->speed) { case USB_SPEED_HIGH: /* units are microframes */ - // NOTE usb handles 2^15 + /* NOTE usb handles 2^15 */ if (urb->interval > (1024 * 8)) urb->interval = 1024 * 8; max = 1024 * 8; @@ -430,12 +431,12 @@ int usb_submit_urb(struct urb *urb, gfp_t mem_flags) if (xfertype == USB_ENDPOINT_XFER_INT) { if (urb->interval > 255) return -EINVAL; - // NOTE ohci only handles up to 32 + /* NOTE ohci only handles up to 32 */ max = 128; } else { if (urb->interval > 1024) urb->interval = 1024; - // NOTE usb and ohci handle up to 2^15 + /* NOTE usb and ohci handle up to 2^15 */ max = 1024; } break; @@ -574,7 +575,8 @@ void usb_kill_anchored_urbs(struct usb_anchor *anchor) spin_lock_irq(&anchor->lock); while (!list_empty(&anchor->urb_list)) { - victim = list_entry(anchor->urb_list.prev, struct urb, anchor_list); + victim = list_entry(anchor->urb_list.prev, struct urb, + anchor_list); /* we must make sure the URB isn't freed before we kill it*/ usb_get_urb(victim); spin_unlock_irq(&anchor->lock); diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c index 8c6319afa757..4e984060c984 100644 --- a/drivers/usb/core/usb.c +++ b/drivers/usb/core/usb.c @@ -116,8 +116,9 @@ EXPORT_SYMBOL_GPL(usb_ifnum_to_if); * Don't call this function unless you are bound to the intf interface * or you have locked the device! */ -struct usb_host_interface *usb_altnum_to_altsetting(const struct usb_interface *intf, - unsigned int altnum) +struct usb_host_interface *usb_altnum_to_altsetting( + const struct usb_interface *intf, + unsigned int altnum) { int i; @@ -134,7 +135,7 @@ struct find_interface_arg { struct usb_interface *interface; }; -static int __find_interface(struct device * dev, void * data) +static int __find_interface(struct device *dev, void *data) { struct find_interface_arg *arg = data; struct usb_interface *intf; @@ -156,7 +157,7 @@ static int __find_interface(struct device * dev, void * data) * @drv: the driver whose current configuration is considered * @minor: the minor number of the desired device * - * This walks the driver device list and returns a pointer to the interface + * This walks the driver device list and returns a pointer to the interface * with the matching minor. Note, this only works for devices that share the * USB major number. */ @@ -272,8 +273,8 @@ static unsigned usb_bus_is_wusb(struct usb_bus *bus) * * This call may not be used in a non-sleeping context. */ -struct usb_device * -usb_alloc_dev(struct usb_device *parent, struct usb_bus *bus, unsigned port1) +struct usb_device *usb_alloc_dev(struct usb_device *parent, + struct usb_bus *bus, unsigned port1) { struct usb_device *dev; struct usb_hcd *usb_hcd = container_of(bus, struct usb_hcd, self); @@ -469,11 +470,11 @@ int usb_lock_device_for_reset(struct usb_device *udev, return -EHOSTUNREACH; if (iface) { switch (iface->condition) { - case USB_INTERFACE_BINDING: + case USB_INTERFACE_BINDING: return 0; - case USB_INTERFACE_BOUND: + case USB_INTERFACE_BOUND: break; - default: + default: return -EINTR; } } @@ -548,10 +549,10 @@ struct usb_device *usb_find_device(u16 vendor_id, u16 product_id) struct list_head *buslist; struct usb_bus *bus; struct usb_device *dev = NULL; - + mutex_lock(&usb_bus_list_lock); for (buslist = usb_bus_list.next; - buslist != &usb_bus_list; + buslist != &usb_bus_list; buslist = buslist->next) { bus = container_of(buslist, struct usb_bus, bus_list); if (!bus->root_hub) @@ -593,7 +594,7 @@ EXPORT_SYMBOL_GPL(usb_get_current_frame_number); */ int __usb_get_extra_descriptor(char *buffer, unsigned size, - unsigned char type, void **ptr) + unsigned char type, void **ptr) { struct usb_descriptor_header *header; @@ -604,7 +605,7 @@ int __usb_get_extra_descriptor(char *buffer, unsigned size, printk(KERN_ERR "%s: bogus descriptor, type %d length %d\n", usbcore_name, - header->bDescriptorType, + header->bDescriptorType, header->bLength); return -1; } @@ -643,12 +644,8 @@ EXPORT_SYMBOL_GPL(__usb_get_extra_descriptor); * * When the buffer is no longer used, free it with usb_buffer_free(). */ -void *usb_buffer_alloc( - struct usb_device *dev, - size_t size, - gfp_t mem_flags, - dma_addr_t *dma -) +void *usb_buffer_alloc(struct usb_device *dev, size_t size, gfp_t mem_flags, + dma_addr_t *dma) { if (!dev || !dev->bus) return NULL; @@ -667,12 +664,8 @@ EXPORT_SYMBOL_GPL(usb_buffer_alloc); * been allocated using usb_buffer_alloc(), and the parameters must match * those provided in that allocation request. */ -void usb_buffer_free( - struct usb_device *dev, - size_t size, - void *addr, - dma_addr_t dma -) +void usb_buffer_free(struct usb_device *dev, size_t size, void *addr, + dma_addr_t dma) { if (!dev || !dev->bus) return; @@ -720,8 +713,8 @@ struct urb *usb_buffer_map(struct urb *urb) urb->setup_packet, sizeof(struct usb_ctrlrequest), DMA_TO_DEVICE); - // FIXME generic api broken like pci, can't report errors - // if (urb->transfer_dma == DMA_ADDR_INVALID) return 0; + /* FIXME generic api broken like pci, can't report errors */ + /* if (urb->transfer_dma == DMA_ADDR_INVALID) return 0; */ } else urb->transfer_dma = ~0; urb->transfer_flags |= (URB_NO_TRANSFER_DMA_MAP @@ -843,7 +836,7 @@ int usb_buffer_map_sg(const struct usb_device *dev, int is_in, || !controller->dma_mask) return -1; - // FIXME generic api broken like pci, can't report errors + /* FIXME generic api broken like pci, can't report errors */ return dma_map_sg(controller, sg, nents, is_in ? DMA_FROM_DEVICE : DMA_TO_DEVICE); } @@ -937,7 +930,7 @@ static int __init usb_init(void) if (retval) goto out; retval = bus_register(&usb_bus_type); - if (retval) + if (retval) goto bus_register_failed; retval = usb_host_init(); if (retval) -- cgit v1.2.3