From 43d186fe992da93bb1dd34a7dd4534719624431c Mon Sep 17 00:00:00 2001 From: Aleksey Babahin Date: Thu, 8 Mar 2012 13:18:43 -0800 Subject: USB: serial: add metro-usb driver to the tree This driver is for the Metrologic barcode scanner. Signed-off-by: Greg Kroah-Hartman --- drivers/usb/serial/metro-usb.c | 622 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 622 insertions(+) create mode 100644 drivers/usb/serial/metro-usb.c (limited to 'drivers/usb/serial/metro-usb.c') diff --git a/drivers/usb/serial/metro-usb.c b/drivers/usb/serial/metro-usb.c new file mode 100644 index 000000000000..5b8ed50e5dda --- /dev/null +++ b/drivers/usb/serial/metro-usb.c @@ -0,0 +1,622 @@ +/* + Date Created: 9/15/2006 + File Name: metro-usb.c + Description: metro-usb.c is the drivers main source file. The driver is a USB to Serial converter. + The driver takes USB data and sends it to a virtual ttyUSB# serial port. + The driver interfaces with the usbserial.ko driver supplied by Linux. + + NOTES: + To install the driver: + 1. Install the usbserial.ko module supplied by Linux with: # insmod usbserial.ko + 2. Install the metro-usb.ko module with: # insmod metro-usb.ko vender=0x#### product=0x#### debug=1 + The vendor, product and debug parameters are optional. + + Some of this code is credited to Linux USB open source files that are distributed with Linux. + + Copyright: 2007 Metrologic Instruments. All rights reserved. + Copyright: 2011 Azimut Ltd. + Requirements: gedit.exe, notepad.exe + + Revision History: + + Date: Developer: Revisions: + ------------------------------------------------------------------------------ + 1/30/2007 Philip Nicastro Initial release. (v1.0.0.0) + 2/27/2007 Philip Nicastro Changed the metrousb_read_int_callback function to use a loop with the tty_insert_flip_char function to copy each byte to the tty layer. Removed the tty_buffer_request_room and the tty_insert_flip_string function calls. These calls were not supported on Fedora. + 2/27/2007 Philip Nicastro Released. (v1.1.0.0) + 10/07/2011 Aleksey Babahin Update for new kernel (tested on 2.6.38) + Add unidirection mode support + + +*/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "metro-usb.h" +#include + +/* Version Information */ +#define DRIVER_VERSION "v1.2.0.0" +#define DRIVER_DESC "Metrologic Instruments Inc. - USB-POS driver" + +/* Device table list. */ +static struct usb_device_id id_table [] = { + { USB_DEVICE(FOCUS_VENDOR_ID, FOCUS_PRODUCT_ID) }, + { USB_DEVICE(FOCUS_VENDOR_ID, FOCUS_PRODUCT_ID_UNI) }, + { }, /* Optional paramenter entry. */ + { }, /* Terminating entry. */ +}; +MODULE_DEVICE_TABLE(usb, id_table); + +/* Input parameter constants. */ +static int debug; +static __u16 vendor; +static __u16 product; + +/* Function prototypes. */ +static void metrousb_cleanup (struct usb_serial_port *port); +static void metrousb_close (struct usb_serial_port *port); +static int metrousb_open (struct tty_struct *tty, struct usb_serial_port *port); +static void metrousb_read_int_callback (struct urb *urb); +static void metrousb_shutdown (struct usb_serial *serial); +static int metrousb_startup (struct usb_serial *serial); +static void metrousb_throttle(struct tty_struct *tty); +static int metrousb_tiocmget(struct tty_struct *tty); +static int metrousb_tiocmset(struct tty_struct *tty, unsigned int set, unsigned int clear); +static void metrousb_unthrottle(struct tty_struct *tty); + +/* Driver structure. */ +static struct usb_driver metrousb_driver = { + .name = "metro-usb", + .probe = usb_serial_probe, + .disconnect = usb_serial_disconnect, + .id_table = id_table +}; + +/* Device structure. */ +static struct usb_serial_driver metrousb_device = { + .driver = { + .owner = THIS_MODULE, + .name = "metro-usb", + }, + .description = "Metrologic USB to serial converter.", + .id_table = id_table, + .usb_driver = &metrousb_driver, + .num_ports = 1, + .open = metrousb_open, + .close = metrousb_close, + .read_int_callback = metrousb_read_int_callback, + .attach = metrousb_startup, + .release = metrousb_shutdown, + .throttle = metrousb_throttle, + .unthrottle = metrousb_unthrottle, + .tiocmget = metrousb_tiocmget, + .tiocmset = metrousb_tiocmset, +}; + +/* ---------------------------------------------------------------------------------------------- + Description: + Clean up any urbs and port information. + + Input: + struct usb_serial_port *: pointer to a usb_serial_port structure. + + Output: + int: Returns true (0) if successful, false otherwise. +*/ +static void metrousb_cleanup (struct usb_serial_port *port) +{ + dbg("METRO-USB - %s - port number=%d", __FUNCTION__, port->number); + + if (port->serial->dev) { + /* Shutdown any interrupt in urbs. */ + if (port->interrupt_in_urb) { + usb_unlink_urb(port->interrupt_in_urb); + usb_kill_urb(port->interrupt_in_urb); + } + + // temp + // this will be needed for the write urb + /* Shutdown any interrupt_out_urbs. */ + //if (serial->num_bulk_in) + // usb_kill_urb(port->read_urb); + } +} + +/* ---------------------------------------------------------------------------------------------- + Description: + Close the open serial port. Cleanup any open serial port information. + + Input: + struct usb_serial_port *: pointer to a usb_serial_port structure. + struct file *: pointer to a file structure. + + Output: + int: Returns true (0) if successful, false otherwise. +*/ +static void metrousb_close (struct usb_serial_port *port) +{ + dbg("METRO-USB - %s - port number=%d", __FUNCTION__, port->number); + metrousb_cleanup(port); +} + +/* ---------------------------------------------------------------------------------------------- + Description: + Driver exit. + + Input: + None: + + Output: + None: +*/ +static void __exit metrousb_exit(void) +{ + dbg("METRO-USB - %s", __FUNCTION__); + + usb_deregister(&metrousb_driver); + usb_serial_deregister(&metrousb_device); +} + +/* ---------------------------------------------------------------------------------------------- + Description: + Driver initialization. + + Input: + None: + + Output: + int: Returns true (0) if successful, false otherwise. +*/ +static int __init metrousb_init(void) +{ + int retval = 0; + int i = 0; + + dbg("METRO-USB - %s", __FUNCTION__); + + /* Add the device parameters if entered. */ + if ((vendor > 0) && (product > 0)) { + struct usb_device_id usb_dev_temp[] = { {USB_DEVICE(vendor, product) } }; + + /* Find the last entry in id_table */ + for (i=0; i < ARRAY_SIZE(id_table); i++) { + if (id_table[i].idVendor == 0) { + id_table[i] = usb_dev_temp[0]; + break; + } + } + + dbg("METRO-USB - %s - support added for unknown device: vendor=0x%x - product=0x%x", __FUNCTION__, vendor, product); + printk(KERN_INFO "Metro USB-POS support added for unknown device: vendor=0x%x - product=0x%x", vendor, product); + } + + /* Register the devices. */ + retval = usb_serial_register(&metrousb_device); + if (retval) + return retval; + + /* Register the driver. */ + retval = usb_register(&metrousb_driver); + if (retval) + usb_serial_deregister(&metrousb_device); + + printk(KERN_INFO DRIVER_DESC " : " DRIVER_VERSION); + + return retval; +} + +/* ---------------------------------------------------------------------------------------------- + Description: + Open the drivers serial port. + + Input: + struct usb_serial_port *: pointer to a usb_serial_port structure. + struct file *: pointer to a file structure. + + Output: + int: Returns true (0) if successful, false otherwise. +*/ +static int metrousb_open (struct tty_struct *tty, struct usb_serial_port *port) +{ + struct usb_serial *serial = port->serial; + struct metrousb_private *metro_priv = usb_get_serial_port_data(port); + unsigned long flags = 0; + int result = 0; + + dbg("METRO-USB - %s - port number=%d", __FUNCTION__, port->number); + + /* Make sure the urb is initialized. */ + if (!port->interrupt_in_urb) { + dbg("METRO-USB - %s - interrupt urb not initialized for port number=%d", __FUNCTION__, port->number); + return -ENODEV; + } + + /* Set the private data information for the port. */ + spin_lock_irqsave(&metro_priv->lock, flags); + metro_priv->control_state = 0; + metro_priv->throttled = 0; + spin_unlock_irqrestore(&metro_priv->lock, flags); + + /* + * Force low_latency on so that our tty_push actually forces the data + * through, otherwise it is scheduled, and with high data rates (like + * with OHCI) data can get lost. + */ + if (tty) { + tty->low_latency = 1; + } + + /* Clear the urb pipe. */ + usb_clear_halt(serial->dev, port->interrupt_in_urb->pipe); + + /* Start reading from the device */ + usb_fill_int_urb (port->interrupt_in_urb, serial->dev, + usb_rcvintpipe (serial->dev, port->interrupt_in_endpointAddress), + port->interrupt_in_urb->transfer_buffer, + port->interrupt_in_urb->transfer_buffer_length, + metrousb_read_int_callback, port, 1); + result = usb_submit_urb(port->interrupt_in_urb, GFP_KERNEL); + + if (result) { + dbg("METRO-USB - %s - failed submitting interrupt in urb for port number=%d, error code=%d" + , __FUNCTION__, port->number, result); + goto exit; + } + + dbg("METRO-USB - %s - port open for port number=%d", __FUNCTION__, port->number); +exit: + return result; +} + +/* ---------------------------------------------------------------------------------------------- + Description: + Read the port from the read interrupt. + + Input: + struct urb *: urb structure to get data. + struct pt_regs *: pt_regs structure. + + Output: + None: +*/ +static void metrousb_read_int_callback (struct urb *urb) +{ + struct usb_serial_port *port = (struct usb_serial_port *)urb->context; + struct metrousb_private *metro_priv = usb_get_serial_port_data(port); + struct tty_struct *tty; + unsigned char *data = urb->transfer_buffer; + int throttled = 0; + int result = 0; + unsigned long flags = 0; + + dbg("METRO-USB - %s - port number=%d", __FUNCTION__, port->number); + + switch (urb->status) { + case 0: + /* Success status, read from the port. */ + break; + case -ECONNRESET: + case -ENOENT: + case -ESHUTDOWN: + /* urb has been terminated. */ + dbg("METRO-USB - %s - urb shutting down, port number=%d, error code=%d", + __FUNCTION__, port->number, result); + return; + default: + dbg("METRO-USB - %s - non-zero urb received, port number=%d, error code=%d", + __FUNCTION__, port->number, result); + goto exit; + } + + + /* Set the data read from the usb port into the serial port buffer. */ + tty = tty_port_tty_get(&port->port); + if (!tty) { + dbg("%s - bad tty pointer - exiting", __func__); + return; + } + + if (tty && urb->actual_length) { + // Loop through the data copying each byte to the tty layer. + tty_insert_flip_string(tty, data, urb->actual_length); + + // Force the data to the tty layer. + tty_flip_buffer_push(tty); + } + tty_kref_put(tty); + + /* Set any port variables. */ + spin_lock_irqsave(&metro_priv->lock, flags); + throttled = metro_priv->throttled; + spin_unlock_irqrestore(&metro_priv->lock, flags); + + /* Continue trying to read if set. */ + if (!throttled) { + usb_fill_int_urb (port->interrupt_in_urb, port->serial->dev, + usb_rcvintpipe (port->serial->dev, port->interrupt_in_endpointAddress), + port->interrupt_in_urb->transfer_buffer, + port->interrupt_in_urb->transfer_buffer_length, + metrousb_read_int_callback, port, 1); + + result = usb_submit_urb(port->interrupt_in_urb, GFP_ATOMIC); + + if (result) { + dbg("METRO-USB - %s - failed submitting interrupt in urb for port number=%d, error code=%d", + __FUNCTION__, port->number, result); + } + } + return; + +exit: + /* Try to resubmit the urb. */ + result = usb_submit_urb (urb, GFP_ATOMIC); + if (result) { + dbg("METRO-USB - %s - failed submitting interrupt in urb for port number=%d, error code=%d", + __FUNCTION__, port->number, result); + } +} + +/* ---------------------------------------------------------------------------------------------- + Description: + Set the modem control state for the entered serial port. + + Input: + struct usb_serial_port *: pointer to a usb_serial_port structure. + unsigned int: control state value to set. + + Output: + int: Returns true (0) if successful, false otherwise. +*/ +static int metrousb_set_modem_ctrl(struct usb_serial *serial, unsigned int control_state) +{ + int retval = 0; + unsigned char mcr = METROUSB_MCR_NONE; + + dbg("METRO-USB - %s - control state=%d", __FUNCTION__, control_state); + + /* Set the modem control value. */ + if (control_state & TIOCM_DTR) + mcr |= METROUSB_MCR_DTR; + if (control_state & TIOCM_RTS) + mcr |= METROUSB_MCR_RTS; + + /* Send the command to the usb port. */ + retval = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0), + METROUSB_SET_REQUEST_TYPE, METROUSB_SET_MODEM_CTRL_REQUEST, + control_state, 0, NULL, 0, WDR_TIMEOUT); + if (retval < 0) + dbg("METRO-USB - %s - set modem ctrl=0x%x failed, error code=%d", __FUNCTION__, mcr, retval); + + return retval; +} + + +/* ---------------------------------------------------------------------------------------------- + Description: + Shutdown the driver. + + Input: + struct usb_serial *: pointer to a usb-serial structure. + + Output: + int: Returns true (0) if successful, false otherwise. +*/ +static void metrousb_shutdown (struct usb_serial *serial) +{ + int i = 0; + + dbg("METRO-USB - %s", __FUNCTION__); + + /* Stop reading and writing on all ports. */ + for (i=0; i < serial->num_ports; ++i) { + /* Close any open urbs. */ + metrousb_cleanup(serial->port[i]); + + /* Free memory. */ + kfree(usb_get_serial_port_data(serial->port[i])); + usb_set_serial_port_data(serial->port[i], NULL); + + dbg("METRO-USB - %s - freed port number=%d", __FUNCTION__, serial->port[i]->number); + } +} + +/* ---------------------------------------------------------------------------------------------- + Description: + Startup the driver. + + Input: + struct usb_serial *: pointer to a usb-serial structure. + + Output: + int: Returns true (0) if successful, false otherwise. +*/ +static int metrousb_startup(struct usb_serial *serial) +{ + struct metrousb_private *metro_priv; + struct usb_serial_port *port; + int i = 0; + + dbg("METRO-USB - %s", __FUNCTION__); + + /* Loop through the serial ports setting up the private structures. + * Currently we only use one port. */ + for (i = 0; i < serial->num_ports; ++i) { + port = serial->port[i]; + + /* Declare memory. */ + metro_priv = (struct metrousb_private *) kmalloc (sizeof(struct metrousb_private), GFP_KERNEL); + if (!metro_priv) + return -ENOMEM; + + /* Clear memory. */ + memset (metro_priv, 0x00, sizeof(struct metrousb_private)); + + /* Initialize memory. */ + spin_lock_init(&metro_priv->lock); + usb_set_serial_port_data(port, metro_priv); + + dbg("METRO-USB - %s - port number=%d.", __FUNCTION__, port->number); + } + + return 0; +} + +/* ---------------------------------------------------------------------------------------------- + Description: + Set the serial port throttle to stop reading from the port. + + Input: + struct usb_serial_port *: pointer to a usb_serial_port structure. + + Output: + None: +*/ +static void metrousb_throttle (struct tty_struct *tty) +{ + struct usb_serial_port *port = tty->driver_data; + struct metrousb_private *metro_priv = usb_get_serial_port_data(port); + unsigned long flags = 0; + + dbg("METRO-USB - %s - port number=%d", __FUNCTION__, port->number); + + /* Set the private information for the port to stop reading data. */ + spin_lock_irqsave(&metro_priv->lock, flags); + metro_priv->throttled = 1; + spin_unlock_irqrestore(&metro_priv->lock, flags); +} + +/* ---------------------------------------------------------------------------------------------- + Description: + Get the serial port control line states. + + Input: + struct usb_serial_port *: pointer to a usb_serial_port structure. + struct file *: pointer to a file structure. + + Output: + int: Returns the state of the control lines. +*/ +static int metrousb_tiocmget (struct tty_struct *tty) +{ + unsigned long control_state = 0; + struct usb_serial_port *port = tty->driver_data; + struct metrousb_private *metro_priv = usb_get_serial_port_data(port); + unsigned long flags = 0; + + dbg("METRO-USB - %s - port number=%d", __FUNCTION__, port->number); + + spin_lock_irqsave(&metro_priv->lock, flags); + control_state = metro_priv->control_state; + spin_unlock_irqrestore(&metro_priv->lock, flags); + + return control_state; +} + +/* ---------------------------------------------------------------------------------------------- + Description: + Set the serial port control line states. + + Input: + struct usb_serial_port *: pointer to a usb_serial_port structure. + struct file *: pointer to a file structure. + unsigned int: line state to set. + unsigned int: line state to clear. + + Output: + int: Returns the state of the control lines. +*/ +static int metrousb_tiocmset (struct tty_struct *tty, + unsigned int set, unsigned int clear) +{ + struct usb_serial_port *port = tty->driver_data; + struct usb_serial *serial = port->serial; + struct metrousb_private *metro_priv = usb_get_serial_port_data(port); + unsigned long flags = 0; + unsigned long control_state = 0; + + dbg("METRO-USB - %s - port number=%d, set=%d, clear=%d", __FUNCTION__, port->number, set, clear); + + spin_lock_irqsave(&metro_priv->lock, flags); + control_state = metro_priv->control_state; + + // Set the RTS and DTR values. + if (set & TIOCM_RTS) + control_state |= TIOCM_RTS; + if (set & TIOCM_DTR) + control_state |= TIOCM_DTR; + if (clear & TIOCM_RTS) + control_state &= ~TIOCM_RTS; + if (clear & TIOCM_DTR) + control_state &= ~TIOCM_DTR; + + metro_priv->control_state = control_state; + spin_unlock_irqrestore(&metro_priv->lock, flags); + return metrousb_set_modem_ctrl(serial, control_state); +} + +/* ---------------------------------------------------------------------------------------------- + Description: + Set the serial port unthrottle to resume reading from the port. + + Input: + struct usb_serial_port *: pointer to a usb_serial_port structure. + + Output: + None: +*/ +static void metrousb_unthrottle (struct tty_struct *tty) +{ + struct usb_serial_port *port = tty->driver_data; + struct metrousb_private *metro_priv = usb_get_serial_port_data(port); + unsigned long flags = 0; + int result = 0; + + dbg("METRO-USB - %s - port number=%d", __FUNCTION__, port->number); + + /* Set the private information for the port to resume reading data. */ + spin_lock_irqsave(&metro_priv->lock, flags); + metro_priv->throttled = 0; + spin_unlock_irqrestore(&metro_priv->lock, flags); + + /* Submit the urb to read from the port. */ + port->interrupt_in_urb->dev = port->serial->dev; + result = usb_submit_urb(port->interrupt_in_urb, GFP_ATOMIC); + if (result) { + dbg("METRO-USB - %s - failed submitting interrupt in urb for port number=%d, error code=%d", + __FUNCTION__, port->number, result); + } +} + +/* Standard module function. */ +module_init(metrousb_init); +module_exit(metrousb_exit); +MODULE_LICENSE("GPL"); +MODULE_AUTHOR( "Philip Nicastro" ); +MODULE_AUTHOR( "Aleksey Babahin " ); +MODULE_DESCRIPTION( DRIVER_DESC ); + +/* Module input parameters */ +module_param(debug, bool, S_IRUGO | S_IWUSR); +MODULE_PARM_DESC(debug, "Print debug info (bool 1=on, 0=off)"); + +module_param(vendor, ushort, 0); +MODULE_PARM_DESC(vendor, "User specified vendor ID (ushort)"); + +module_param(product, ushort, 0); +MODULE_PARM_DESC(product, "User specified product ID (ushort)"); + + + + -- cgit v1.2.3-55-g7522 From 11a4f40064f38dcc369d716bea2020f6b5e290ff Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Thu, 8 Mar 2012 13:33:04 -0800 Subject: USB: serial: metro-usb: fix up usb_serial_register calls The usb serial core has changed how the driver is to be registered and unregistered recently. Make these changes to the driver so that it will properly build and work. Cc: Aleksey Babahin Signed-off-by: Greg Kroah-Hartman --- drivers/usb/serial/metro-usb.c | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) (limited to 'drivers/usb/serial/metro-usb.c') diff --git a/drivers/usb/serial/metro-usb.c b/drivers/usb/serial/metro-usb.c index 5b8ed50e5dda..bb6838959876 100644 --- a/drivers/usb/serial/metro-usb.c +++ b/drivers/usb/serial/metro-usb.c @@ -92,7 +92,6 @@ static struct usb_serial_driver metrousb_device = { }, .description = "Metrologic USB to serial converter.", .id_table = id_table, - .usb_driver = &metrousb_driver, .num_ports = 1, .open = metrousb_open, .close = metrousb_close, @@ -105,6 +104,11 @@ static struct usb_serial_driver metrousb_device = { .tiocmset = metrousb_tiocmset, }; +static struct usb_serial_driver * const serial_drivers[] = { + &metrousb_device, + NULL, +}; + /* ---------------------------------------------------------------------------------------------- Description: Clean up any urbs and port information. @@ -163,10 +167,7 @@ static void metrousb_close (struct usb_serial_port *port) */ static void __exit metrousb_exit(void) { - dbg("METRO-USB - %s", __FUNCTION__); - - usb_deregister(&metrousb_driver); - usb_serial_deregister(&metrousb_device); + usb_serial_deregister_drivers(&metrousb_driver, serial_drivers); } /* ---------------------------------------------------------------------------------------------- @@ -203,15 +204,10 @@ static int __init metrousb_init(void) } /* Register the devices. */ - retval = usb_serial_register(&metrousb_device); + retval = usb_serial_register_drivers(&metrousb_driver, serial_drivers); if (retval) return retval; - /* Register the driver. */ - retval = usb_register(&metrousb_driver); - if (retval) - usb_serial_deregister(&metrousb_device); - printk(KERN_INFO DRIVER_DESC " : " DRIVER_VERSION); return retval; -- cgit v1.2.3-55-g7522 From fdac0f647a2cf12e7152dc1d94dd08a1af4a2a82 Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Thu, 8 Mar 2012 13:37:32 -0800 Subject: USB: serial: metro-usb: remove vendor and product module parameters All new usb serial drivers should be using the dynamic id function, not having module parameters for this type of thing. So remove them before anyone gets used to them being there. Cc: Aleksey Babahin Signed-off-by: Greg Kroah-Hartman --- drivers/usb/serial/metro-usb.c | 35 ++--------------------------------- 1 file changed, 2 insertions(+), 33 deletions(-) (limited to 'drivers/usb/serial/metro-usb.c') diff --git a/drivers/usb/serial/metro-usb.c b/drivers/usb/serial/metro-usb.c index bb6838959876..d0c47e1dab10 100644 --- a/drivers/usb/serial/metro-usb.c +++ b/drivers/usb/serial/metro-usb.c @@ -8,8 +8,7 @@ NOTES: To install the driver: 1. Install the usbserial.ko module supplied by Linux with: # insmod usbserial.ko - 2. Install the metro-usb.ko module with: # insmod metro-usb.ko vender=0x#### product=0x#### debug=1 - The vendor, product and debug parameters are optional. + 2. Install the metro-usb.ko module with: # insmod metro-usb.ko Some of this code is credited to Linux USB open source files that are distributed with Linux. @@ -54,15 +53,12 @@ static struct usb_device_id id_table [] = { { USB_DEVICE(FOCUS_VENDOR_ID, FOCUS_PRODUCT_ID) }, { USB_DEVICE(FOCUS_VENDOR_ID, FOCUS_PRODUCT_ID_UNI) }, - { }, /* Optional paramenter entry. */ { }, /* Terminating entry. */ }; MODULE_DEVICE_TABLE(usb, id_table); /* Input parameter constants. */ -static int debug; -static __u16 vendor; -static __u16 product; +static bool debug; /* Function prototypes. */ static void metrousb_cleanup (struct usb_serial_port *port); @@ -183,26 +179,9 @@ static void __exit metrousb_exit(void) static int __init metrousb_init(void) { int retval = 0; - int i = 0; dbg("METRO-USB - %s", __FUNCTION__); - /* Add the device parameters if entered. */ - if ((vendor > 0) && (product > 0)) { - struct usb_device_id usb_dev_temp[] = { {USB_DEVICE(vendor, product) } }; - - /* Find the last entry in id_table */ - for (i=0; i < ARRAY_SIZE(id_table); i++) { - if (id_table[i].idVendor == 0) { - id_table[i] = usb_dev_temp[0]; - break; - } - } - - dbg("METRO-USB - %s - support added for unknown device: vendor=0x%x - product=0x%x", __FUNCTION__, vendor, product); - printk(KERN_INFO "Metro USB-POS support added for unknown device: vendor=0x%x - product=0x%x", vendor, product); - } - /* Register the devices. */ retval = usb_serial_register_drivers(&metrousb_driver, serial_drivers); if (retval) @@ -606,13 +585,3 @@ MODULE_DESCRIPTION( DRIVER_DESC ); /* Module input parameters */ module_param(debug, bool, S_IRUGO | S_IWUSR); MODULE_PARM_DESC(debug, "Print debug info (bool 1=on, 0=off)"); - -module_param(vendor, ushort, 0); -MODULE_PARM_DESC(vendor, "User specified vendor ID (ushort)"); - -module_param(product, ushort, 0); -MODULE_PARM_DESC(product, "User specified product ID (ushort)"); - - - - -- cgit v1.2.3-55-g7522 From 1935e357bb2a3031772730293a3725e3cca07778 Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Thu, 8 Mar 2012 13:39:53 -0800 Subject: USB: serial: metro-usb: convert to use module_usb_serial_driver Now that we aren't doing anything special in the init function, move to use the easier module_usb_serial_driver() call instead, saving a lot of lines of unnecessary code. Cc: Aleksey Babahin Signed-off-by: Greg Kroah-Hartman --- drivers/usb/serial/metro-usb.c | 46 ++---------------------------------------- 1 file changed, 2 insertions(+), 44 deletions(-) (limited to 'drivers/usb/serial/metro-usb.c') diff --git a/drivers/usb/serial/metro-usb.c b/drivers/usb/serial/metro-usb.c index d0c47e1dab10..919dd47ab46f 100644 --- a/drivers/usb/serial/metro-usb.c +++ b/drivers/usb/serial/metro-usb.c @@ -151,47 +151,6 @@ static void metrousb_close (struct usb_serial_port *port) metrousb_cleanup(port); } -/* ---------------------------------------------------------------------------------------------- - Description: - Driver exit. - - Input: - None: - - Output: - None: -*/ -static void __exit metrousb_exit(void) -{ - usb_serial_deregister_drivers(&metrousb_driver, serial_drivers); -} - -/* ---------------------------------------------------------------------------------------------- - Description: - Driver initialization. - - Input: - None: - - Output: - int: Returns true (0) if successful, false otherwise. -*/ -static int __init metrousb_init(void) -{ - int retval = 0; - - dbg("METRO-USB - %s", __FUNCTION__); - - /* Register the devices. */ - retval = usb_serial_register_drivers(&metrousb_driver, serial_drivers); - if (retval) - return retval; - - printk(KERN_INFO DRIVER_DESC " : " DRIVER_VERSION); - - return retval; -} - /* ---------------------------------------------------------------------------------------------- Description: Open the drivers serial port. @@ -574,9 +533,8 @@ static void metrousb_unthrottle (struct tty_struct *tty) } } -/* Standard module function. */ -module_init(metrousb_init); -module_exit(metrousb_exit); +module_usb_serial_driver(metrousb_driver, serial_drivers); + MODULE_LICENSE("GPL"); MODULE_AUTHOR( "Philip Nicastro" ); MODULE_AUTHOR( "Aleksey Babahin " ); -- cgit v1.2.3-55-g7522 From 159d4d8d5e9416dba78b84d4be10d7b1172728ee Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Thu, 8 Mar 2012 13:42:41 -0800 Subject: USB: serial: metro-usb: remove the .h file A driver doesn't need a .h file just for simple things like vendor ids and a private structure. So move it into the .c file instead, saving some overall lines. Cc: Aleksey Babahin Signed-off-by: Greg Kroah-Hartman --- drivers/usb/serial/metro-usb.c | 23 +++++++++++++++++-- drivers/usb/serial/metro-usb.h | 52 ------------------------------------------ 2 files changed, 21 insertions(+), 54 deletions(-) delete mode 100644 drivers/usb/serial/metro-usb.h (limited to 'drivers/usb/serial/metro-usb.c') diff --git a/drivers/usb/serial/metro-usb.c b/drivers/usb/serial/metro-usb.c index 919dd47ab46f..d22a603597e8 100644 --- a/drivers/usb/serial/metro-usb.c +++ b/drivers/usb/serial/metro-usb.c @@ -40,15 +40,34 @@ #include #include #include -#include #include -#include "metro-usb.h" #include +#include /* Version Information */ #define DRIVER_VERSION "v1.2.0.0" #define DRIVER_DESC "Metrologic Instruments Inc. - USB-POS driver" +/* Product information. */ +#define FOCUS_VENDOR_ID 0x0C2E +#define FOCUS_PRODUCT_ID 0x0720 +#define FOCUS_PRODUCT_ID_UNI 0x0710 + +#define METROUSB_SET_REQUEST_TYPE 0x40 +#define METROUSB_SET_MODEM_CTRL_REQUEST 10 +#define METROUSB_SET_BREAK_REQUEST 0x40 +#define METROUSB_MCR_NONE 0x08 /* Deactivate DTR and RTS. */ +#define METROUSB_MCR_RTS 0x0a /* Activate RTS. */ +#define METROUSB_MCR_DTR 0x09 /* Activate DTR. */ +#define WDR_TIMEOUT 5000 /* default urb timeout. */ + +/* Private data structure. */ +struct metrousb_private { + spinlock_t lock; + int throttled; + unsigned long control_state; +}; + /* Device table list. */ static struct usb_device_id id_table [] = { { USB_DEVICE(FOCUS_VENDOR_ID, FOCUS_PRODUCT_ID) }, diff --git a/drivers/usb/serial/metro-usb.h b/drivers/usb/serial/metro-usb.h deleted file mode 100644 index 0367b6c8df07..000000000000 --- a/drivers/usb/serial/metro-usb.h +++ /dev/null @@ -1,52 +0,0 @@ -/* - Date Created: 1/12/2007 - File Name: metro-usb.h - Description: metro-usb.h is the drivers header file. The driver is a USB to Serial converter. - The driver takes USB data and sends it to a virtual ttyUSB# serial port. - The driver interfaces with the usbserial.ko driver supplied by Linux. - - NOTES: - To install the driver: - 1. Install the usbserial.ko module supplied by Linux with: # insmod usbserial.ko - 2. Install the metro-usb.ko module with: # insmod metro-usb.ko vender=0x#### product=0x#### debug=1 - The vendor, product and debug parameters are optional. - - Copyright: 2007 Metrologic Instruments. All rights reserved. - Copyright: 2011 Azimut Ltd. - Requirements: Notepad.exe - - Revision History: - - Date: Developer: Revisions: - ------------------------------------------------------------------------------ - 1/12/2007 Philip Nicastro Initial release. (v1.0.0.0) - 10/07/2011 Aleksey Babahin Update for new kernel (tested on 2.6.38) - Add unidirection mode support - - -*/ - -#ifndef __LINUX_USB_SERIAL_METRO -#define __LINUX_USB_SERIAL_METRO - -/* Product information. */ -#define FOCUS_VENDOR_ID 0x0C2E -#define FOCUS_PRODUCT_ID 0x0720 -#define FOCUS_PRODUCT_ID_UNI 0x0710 - -#define METROUSB_SET_REQUEST_TYPE 0x40 -#define METROUSB_SET_MODEM_CTRL_REQUEST 10 -#define METROUSB_SET_BREAK_REQUEST 0x40 -#define METROUSB_MCR_NONE 0x8 /* Deactivate DTR and RTS. */ -#define METROUSB_MCR_RTS 0xa /* Activate RTS. */ -#define METROUSB_MCR_DTR 0x9 /* Activate DTR. */ -#define WDR_TIMEOUT 5000 /* default urb timeout. */ - -/* Private data structure. */ -struct metrousb_private { - spinlock_t lock; - int throttled; - unsigned long control_state; -}; - -#endif -- cgit v1.2.3-55-g7522 From d4cbd6e990a798d21577ee2f42a3880da09edf3a Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Thu, 8 Mar 2012 13:50:54 -0800 Subject: USB: serial: metro-usb: fix up coding style errors This fixes up all of the coding style errors, and removes the initial, unneeded comments on how to load the module and the old changelog which are no longer needed. There are still a number of coding style warnings left, I'll get to them later. Cc: Aleksey Babahin Signed-off-by: Greg Kroah-Hartman --- drivers/usb/serial/metro-usb.c | 160 +++++++++++++++++------------------------ 1 file changed, 65 insertions(+), 95 deletions(-) (limited to 'drivers/usb/serial/metro-usb.c') diff --git a/drivers/usb/serial/metro-usb.c b/drivers/usb/serial/metro-usb.c index d22a603597e8..66e9355cfd00 100644 --- a/drivers/usb/serial/metro-usb.c +++ b/drivers/usb/serial/metro-usb.c @@ -1,32 +1,9 @@ /* - Date Created: 9/15/2006 - File Name: metro-usb.c - Description: metro-usb.c is the drivers main source file. The driver is a USB to Serial converter. - The driver takes USB data and sends it to a virtual ttyUSB# serial port. - The driver interfaces with the usbserial.ko driver supplied by Linux. - - NOTES: - To install the driver: - 1. Install the usbserial.ko module supplied by Linux with: # insmod usbserial.ko - 2. Install the metro-usb.ko module with: # insmod metro-usb.ko - - Some of this code is credited to Linux USB open source files that are distributed with Linux. + Some of this code is credited to Linux USB open source files that are + distributed with Linux. Copyright: 2007 Metrologic Instruments. All rights reserved. Copyright: 2011 Azimut Ltd. - Requirements: gedit.exe, notepad.exe - - Revision History: - - Date: Developer: Revisions: - ------------------------------------------------------------------------------ - 1/30/2007 Philip Nicastro Initial release. (v1.0.0.0) - 2/27/2007 Philip Nicastro Changed the metrousb_read_int_callback function to use a loop with the tty_insert_flip_char function to copy each byte to the tty layer. Removed the tty_buffer_request_room and the tty_insert_flip_string function calls. These calls were not supported on Fedora. - 2/27/2007 Philip Nicastro Released. (v1.1.0.0) - 10/07/2011 Aleksey Babahin Update for new kernel (tested on 2.6.38) - Add unidirection mode support - - */ #include @@ -41,8 +18,8 @@ #include #include #include +#include #include -#include /* Version Information */ #define DRIVER_VERSION "v1.2.0.0" @@ -59,7 +36,7 @@ #define METROUSB_MCR_NONE 0x08 /* Deactivate DTR and RTS. */ #define METROUSB_MCR_RTS 0x0a /* Activate RTS. */ #define METROUSB_MCR_DTR 0x09 /* Activate DTR. */ -#define WDR_TIMEOUT 5000 /* default urb timeout. */ +#define WDR_TIMEOUT 5000 /* default urb timeout. */ /* Private data structure. */ struct metrousb_private { @@ -69,7 +46,7 @@ struct metrousb_private { }; /* Device table list. */ -static struct usb_device_id id_table [] = { +static struct usb_device_id id_table[] = { { USB_DEVICE(FOCUS_VENDOR_ID, FOCUS_PRODUCT_ID) }, { USB_DEVICE(FOCUS_VENDOR_ID, FOCUS_PRODUCT_ID_UNI) }, { }, /* Terminating entry. */ @@ -80,12 +57,12 @@ MODULE_DEVICE_TABLE(usb, id_table); static bool debug; /* Function prototypes. */ -static void metrousb_cleanup (struct usb_serial_port *port); -static void metrousb_close (struct usb_serial_port *port); -static int metrousb_open (struct tty_struct *tty, struct usb_serial_port *port); -static void metrousb_read_int_callback (struct urb *urb); -static void metrousb_shutdown (struct usb_serial *serial); -static int metrousb_startup (struct usb_serial *serial); +static void metrousb_cleanup(struct usb_serial_port *port); +static void metrousb_close(struct usb_serial_port *port); +static int metrousb_open(struct tty_struct *tty, struct usb_serial_port *port); +static void metrousb_read_int_callback(struct urb *urb); +static void metrousb_shutdown(struct usb_serial *serial); +static int metrousb_startup(struct usb_serial *serial); static void metrousb_throttle(struct tty_struct *tty); static int metrousb_tiocmget(struct tty_struct *tty); static int metrousb_tiocmset(struct tty_struct *tty, unsigned int set, unsigned int clear); @@ -105,18 +82,18 @@ static struct usb_serial_driver metrousb_device = { .owner = THIS_MODULE, .name = "metro-usb", }, - .description = "Metrologic USB to serial converter.", - .id_table = id_table, - .num_ports = 1, - .open = metrousb_open, - .close = metrousb_close, - .read_int_callback = metrousb_read_int_callback, - .attach = metrousb_startup, - .release = metrousb_shutdown, - .throttle = metrousb_throttle, - .unthrottle = metrousb_unthrottle, - .tiocmget = metrousb_tiocmget, - .tiocmset = metrousb_tiocmset, + .description = "Metrologic USB to serial converter.", + .id_table = id_table, + .num_ports = 1, + .open = metrousb_open, + .close = metrousb_close, + .read_int_callback = metrousb_read_int_callback, + .attach = metrousb_startup, + .release = metrousb_shutdown, + .throttle = metrousb_throttle, + .unthrottle = metrousb_unthrottle, + .tiocmget = metrousb_tiocmget, + .tiocmset = metrousb_tiocmset, }; static struct usb_serial_driver * const serial_drivers[] = { @@ -134,7 +111,7 @@ static struct usb_serial_driver * const serial_drivers[] = { Output: int: Returns true (0) if successful, false otherwise. */ -static void metrousb_cleanup (struct usb_serial_port *port) +static void metrousb_cleanup(struct usb_serial_port *port) { dbg("METRO-USB - %s - port number=%d", __FUNCTION__, port->number); @@ -144,12 +121,6 @@ static void metrousb_cleanup (struct usb_serial_port *port) usb_unlink_urb(port->interrupt_in_urb); usb_kill_urb(port->interrupt_in_urb); } - - // temp - // this will be needed for the write urb - /* Shutdown any interrupt_out_urbs. */ - //if (serial->num_bulk_in) - // usb_kill_urb(port->read_urb); } } @@ -164,7 +135,7 @@ static void metrousb_cleanup (struct usb_serial_port *port) Output: int: Returns true (0) if successful, false otherwise. */ -static void metrousb_close (struct usb_serial_port *port) +static void metrousb_close(struct usb_serial_port *port) { dbg("METRO-USB - %s - port number=%d", __FUNCTION__, port->number); metrousb_cleanup(port); @@ -181,7 +152,7 @@ static void metrousb_close (struct usb_serial_port *port) Output: int: Returns true (0) if successful, false otherwise. */ -static int metrousb_open (struct tty_struct *tty, struct usb_serial_port *port) +static int metrousb_open(struct tty_struct *tty, struct usb_serial_port *port) { struct usb_serial *serial = port->serial; struct metrousb_private *metro_priv = usb_get_serial_port_data(port); @@ -207,16 +178,15 @@ static int metrousb_open (struct tty_struct *tty, struct usb_serial_port *port) * through, otherwise it is scheduled, and with high data rates (like * with OHCI) data can get lost. */ - if (tty) { + if (tty) tty->low_latency = 1; - } /* Clear the urb pipe. */ usb_clear_halt(serial->dev, port->interrupt_in_urb->pipe); /* Start reading from the device */ - usb_fill_int_urb (port->interrupt_in_urb, serial->dev, - usb_rcvintpipe (serial->dev, port->interrupt_in_endpointAddress), + usb_fill_int_urb(port->interrupt_in_urb, serial->dev, + usb_rcvintpipe(serial->dev, port->interrupt_in_endpointAddress), port->interrupt_in_urb->transfer_buffer, port->interrupt_in_urb->transfer_buffer_length, metrousb_read_int_callback, port, 1); @@ -244,7 +214,7 @@ exit: Output: None: */ -static void metrousb_read_int_callback (struct urb *urb) +static void metrousb_read_int_callback(struct urb *urb) { struct usb_serial_port *port = (struct usb_serial_port *)urb->context; struct metrousb_private *metro_priv = usb_get_serial_port_data(port); @@ -257,20 +227,20 @@ static void metrousb_read_int_callback (struct urb *urb) dbg("METRO-USB - %s - port number=%d", __FUNCTION__, port->number); switch (urb->status) { - case 0: - /* Success status, read from the port. */ - break; - case -ECONNRESET: - case -ENOENT: - case -ESHUTDOWN: - /* urb has been terminated. */ - dbg("METRO-USB - %s - urb shutting down, port number=%d, error code=%d", - __FUNCTION__, port->number, result); - return; - default: - dbg("METRO-USB - %s - non-zero urb received, port number=%d, error code=%d", - __FUNCTION__, port->number, result); - goto exit; + case 0: + /* Success status, read from the port. */ + break; + case -ECONNRESET: + case -ENOENT: + case -ESHUTDOWN: + /* urb has been terminated. */ + dbg("METRO-USB - %s - urb shutting down, port number=%d, error code=%d", + __FUNCTION__, port->number, result); + return; + default: + dbg("METRO-USB - %s - non-zero urb received, port number=%d, error code=%d", + __FUNCTION__, port->number, result); + goto exit; } @@ -282,10 +252,10 @@ static void metrousb_read_int_callback (struct urb *urb) } if (tty && urb->actual_length) { - // Loop through the data copying each byte to the tty layer. + /* Loop through the data copying each byte to the tty layer. */ tty_insert_flip_string(tty, data, urb->actual_length); - // Force the data to the tty layer. + /* Force the data to the tty layer. */ tty_flip_buffer_push(tty); } tty_kref_put(tty); @@ -297,11 +267,11 @@ static void metrousb_read_int_callback (struct urb *urb) /* Continue trying to read if set. */ if (!throttled) { - usb_fill_int_urb (port->interrupt_in_urb, port->serial->dev, - usb_rcvintpipe (port->serial->dev, port->interrupt_in_endpointAddress), - port->interrupt_in_urb->transfer_buffer, - port->interrupt_in_urb->transfer_buffer_length, - metrousb_read_int_callback, port, 1); + usb_fill_int_urb(port->interrupt_in_urb, port->serial->dev, + usb_rcvintpipe(port->serial->dev, port->interrupt_in_endpointAddress), + port->interrupt_in_urb->transfer_buffer, + port->interrupt_in_urb->transfer_buffer_length, + metrousb_read_int_callback, port, 1); result = usb_submit_urb(port->interrupt_in_urb, GFP_ATOMIC); @@ -314,7 +284,7 @@ static void metrousb_read_int_callback (struct urb *urb) exit: /* Try to resubmit the urb. */ - result = usb_submit_urb (urb, GFP_ATOMIC); + result = usb_submit_urb(urb, GFP_ATOMIC); if (result) { dbg("METRO-USB - %s - failed submitting interrupt in urb for port number=%d, error code=%d", __FUNCTION__, port->number, result); @@ -366,14 +336,14 @@ static int metrousb_set_modem_ctrl(struct usb_serial *serial, unsigned int contr Output: int: Returns true (0) if successful, false otherwise. */ -static void metrousb_shutdown (struct usb_serial *serial) +static void metrousb_shutdown(struct usb_serial *serial) { int i = 0; dbg("METRO-USB - %s", __FUNCTION__); /* Stop reading and writing on all ports. */ - for (i=0; i < serial->num_ports; ++i) { + for (i = 0; i < serial->num_ports; ++i) { /* Close any open urbs. */ metrousb_cleanup(serial->port[i]); @@ -409,12 +379,12 @@ static int metrousb_startup(struct usb_serial *serial) port = serial->port[i]; /* Declare memory. */ - metro_priv = (struct metrousb_private *) kmalloc (sizeof(struct metrousb_private), GFP_KERNEL); + metro_priv = kmalloc(sizeof(struct metrousb_private), GFP_KERNEL); if (!metro_priv) return -ENOMEM; /* Clear memory. */ - memset (metro_priv, 0x00, sizeof(struct metrousb_private)); + memset(metro_priv, 0x00, sizeof(struct metrousb_private)); /* Initialize memory. */ spin_lock_init(&metro_priv->lock); @@ -436,7 +406,7 @@ static int metrousb_startup(struct usb_serial *serial) Output: None: */ -static void metrousb_throttle (struct tty_struct *tty) +static void metrousb_throttle(struct tty_struct *tty) { struct usb_serial_port *port = tty->driver_data; struct metrousb_private *metro_priv = usb_get_serial_port_data(port); @@ -461,7 +431,7 @@ static void metrousb_throttle (struct tty_struct *tty) Output: int: Returns the state of the control lines. */ -static int metrousb_tiocmget (struct tty_struct *tty) +static int metrousb_tiocmget(struct tty_struct *tty) { unsigned long control_state = 0; struct usb_serial_port *port = tty->driver_data; @@ -490,8 +460,8 @@ static int metrousb_tiocmget (struct tty_struct *tty) Output: int: Returns the state of the control lines. */ -static int metrousb_tiocmset (struct tty_struct *tty, - unsigned int set, unsigned int clear) +static int metrousb_tiocmset(struct tty_struct *tty, + unsigned int set, unsigned int clear) { struct usb_serial_port *port = tty->driver_data; struct usb_serial *serial = port->serial; @@ -504,7 +474,7 @@ static int metrousb_tiocmset (struct tty_struct *tty, spin_lock_irqsave(&metro_priv->lock, flags); control_state = metro_priv->control_state; - // Set the RTS and DTR values. + /* Set the RTS and DTR values. */ if (set & TIOCM_RTS) control_state |= TIOCM_RTS; if (set & TIOCM_DTR) @@ -529,7 +499,7 @@ static int metrousb_tiocmset (struct tty_struct *tty, Output: None: */ -static void metrousb_unthrottle (struct tty_struct *tty) +static void metrousb_unthrottle(struct tty_struct *tty) { struct usb_serial_port *port = tty->driver_data; struct metrousb_private *metro_priv = usb_get_serial_port_data(port); @@ -555,9 +525,9 @@ static void metrousb_unthrottle (struct tty_struct *tty) module_usb_serial_driver(metrousb_driver, serial_drivers); MODULE_LICENSE("GPL"); -MODULE_AUTHOR( "Philip Nicastro" ); -MODULE_AUTHOR( "Aleksey Babahin " ); -MODULE_DESCRIPTION( DRIVER_DESC ); +MODULE_AUTHOR("Philip Nicastro"); +MODULE_AUTHOR("Aleksey Babahin "); +MODULE_DESCRIPTION(DRIVER_DESC); /* Module input parameters */ module_param(debug, bool, S_IRUGO | S_IWUSR); -- cgit v1.2.3-55-g7522 From 9fbd1649d54edc614c64ab075f7485622fd6450a Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Thu, 8 Mar 2012 13:55:41 -0800 Subject: USB: serial: metro-usb: remove function prototypes By rearranging the functions a bit, we can remove all function prototypes. Note, this also deleted the _close function, as it wasn't needed, it was doing the same thing the cleanup function did, so just call that instead. Cc: Aleksey Babahin Signed-off-by: Greg Kroah-Hartman --- drivers/usb/serial/metro-usb.c | 263 ++++++++++++++++++----------------------- 1 file changed, 117 insertions(+), 146 deletions(-) (limited to 'drivers/usb/serial/metro-usb.c') diff --git a/drivers/usb/serial/metro-usb.c b/drivers/usb/serial/metro-usb.c index 66e9355cfd00..8758e01289b9 100644 --- a/drivers/usb/serial/metro-usb.c +++ b/drivers/usb/serial/metro-usb.c @@ -56,89 +56,115 @@ MODULE_DEVICE_TABLE(usb, id_table); /* Input parameter constants. */ static bool debug; -/* Function prototypes. */ -static void metrousb_cleanup(struct usb_serial_port *port); -static void metrousb_close(struct usb_serial_port *port); -static int metrousb_open(struct tty_struct *tty, struct usb_serial_port *port); -static void metrousb_read_int_callback(struct urb *urb); -static void metrousb_shutdown(struct usb_serial *serial); -static int metrousb_startup(struct usb_serial *serial); -static void metrousb_throttle(struct tty_struct *tty); -static int metrousb_tiocmget(struct tty_struct *tty); -static int metrousb_tiocmset(struct tty_struct *tty, unsigned int set, unsigned int clear); -static void metrousb_unthrottle(struct tty_struct *tty); - -/* Driver structure. */ -static struct usb_driver metrousb_driver = { - .name = "metro-usb", - .probe = usb_serial_probe, - .disconnect = usb_serial_disconnect, - .id_table = id_table -}; - -/* Device structure. */ -static struct usb_serial_driver metrousb_device = { - .driver = { - .owner = THIS_MODULE, - .name = "metro-usb", - }, - .description = "Metrologic USB to serial converter.", - .id_table = id_table, - .num_ports = 1, - .open = metrousb_open, - .close = metrousb_close, - .read_int_callback = metrousb_read_int_callback, - .attach = metrousb_startup, - .release = metrousb_shutdown, - .throttle = metrousb_throttle, - .unthrottle = metrousb_unthrottle, - .tiocmget = metrousb_tiocmget, - .tiocmset = metrousb_tiocmset, -}; - -static struct usb_serial_driver * const serial_drivers[] = { - &metrousb_device, - NULL, -}; - /* ---------------------------------------------------------------------------------------------- Description: - Clean up any urbs and port information. + Read the port from the read interrupt. Input: - struct usb_serial_port *: pointer to a usb_serial_port structure. + struct urb *: urb structure to get data. + struct pt_regs *: pt_regs structure. Output: - int: Returns true (0) if successful, false otherwise. + None: */ -static void metrousb_cleanup(struct usb_serial_port *port) +static void metrousb_read_int_callback(struct urb *urb) { + struct usb_serial_port *port = (struct usb_serial_port *)urb->context; + struct metrousb_private *metro_priv = usb_get_serial_port_data(port); + struct tty_struct *tty; + unsigned char *data = urb->transfer_buffer; + int throttled = 0; + int result = 0; + unsigned long flags = 0; + dbg("METRO-USB - %s - port number=%d", __FUNCTION__, port->number); - if (port->serial->dev) { - /* Shutdown any interrupt in urbs. */ - if (port->interrupt_in_urb) { - usb_unlink_urb(port->interrupt_in_urb); - usb_kill_urb(port->interrupt_in_urb); + switch (urb->status) { + case 0: + /* Success status, read from the port. */ + break; + case -ECONNRESET: + case -ENOENT: + case -ESHUTDOWN: + /* urb has been terminated. */ + dbg("METRO-USB - %s - urb shutting down, port number=%d, error code=%d", + __FUNCTION__, port->number, result); + return; + default: + dbg("METRO-USB - %s - non-zero urb received, port number=%d, error code=%d", + __FUNCTION__, port->number, result); + goto exit; + } + + + /* Set the data read from the usb port into the serial port buffer. */ + tty = tty_port_tty_get(&port->port); + if (!tty) { + dbg("%s - bad tty pointer - exiting", __func__); + return; + } + + if (tty && urb->actual_length) { + /* Loop through the data copying each byte to the tty layer. */ + tty_insert_flip_string(tty, data, urb->actual_length); + + /* Force the data to the tty layer. */ + tty_flip_buffer_push(tty); + } + tty_kref_put(tty); + + /* Set any port variables. */ + spin_lock_irqsave(&metro_priv->lock, flags); + throttled = metro_priv->throttled; + spin_unlock_irqrestore(&metro_priv->lock, flags); + + /* Continue trying to read if set. */ + if (!throttled) { + usb_fill_int_urb(port->interrupt_in_urb, port->serial->dev, + usb_rcvintpipe(port->serial->dev, port->interrupt_in_endpointAddress), + port->interrupt_in_urb->transfer_buffer, + port->interrupt_in_urb->transfer_buffer_length, + metrousb_read_int_callback, port, 1); + + result = usb_submit_urb(port->interrupt_in_urb, GFP_ATOMIC); + + if (result) { + dbg("METRO-USB - %s - failed submitting interrupt in urb for port number=%d, error code=%d", + __FUNCTION__, port->number, result); } } + return; + +exit: + /* Try to resubmit the urb. */ + result = usb_submit_urb(urb, GFP_ATOMIC); + if (result) { + dbg("METRO-USB - %s - failed submitting interrupt in urb for port number=%d, error code=%d", + __FUNCTION__, port->number, result); + } } /* ---------------------------------------------------------------------------------------------- Description: - Close the open serial port. Cleanup any open serial port information. + Clean up any urbs and port information. Input: struct usb_serial_port *: pointer to a usb_serial_port structure. - struct file *: pointer to a file structure. Output: int: Returns true (0) if successful, false otherwise. */ -static void metrousb_close(struct usb_serial_port *port) +static void metrousb_cleanup(struct usb_serial_port *port) { dbg("METRO-USB - %s - port number=%d", __FUNCTION__, port->number); - metrousb_cleanup(port); + + if (port->serial->dev) { + /* Shutdown any interrupt in urbs. */ + if (port->interrupt_in_urb) { + usb_unlink_urb(port->interrupt_in_urb); + usb_kill_urb(port->interrupt_in_urb); + } + } } /* ---------------------------------------------------------------------------------------------- @@ -203,94 +229,6 @@ exit: return result; } -/* ---------------------------------------------------------------------------------------------- - Description: - Read the port from the read interrupt. - - Input: - struct urb *: urb structure to get data. - struct pt_regs *: pt_regs structure. - - Output: - None: -*/ -static void metrousb_read_int_callback(struct urb *urb) -{ - struct usb_serial_port *port = (struct usb_serial_port *)urb->context; - struct metrousb_private *metro_priv = usb_get_serial_port_data(port); - struct tty_struct *tty; - unsigned char *data = urb->transfer_buffer; - int throttled = 0; - int result = 0; - unsigned long flags = 0; - - dbg("METRO-USB - %s - port number=%d", __FUNCTION__, port->number); - - switch (urb->status) { - case 0: - /* Success status, read from the port. */ - break; - case -ECONNRESET: - case -ENOENT: - case -ESHUTDOWN: - /* urb has been terminated. */ - dbg("METRO-USB - %s - urb shutting down, port number=%d, error code=%d", - __FUNCTION__, port->number, result); - return; - default: - dbg("METRO-USB - %s - non-zero urb received, port number=%d, error code=%d", - __FUNCTION__, port->number, result); - goto exit; - } - - - /* Set the data read from the usb port into the serial port buffer. */ - tty = tty_port_tty_get(&port->port); - if (!tty) { - dbg("%s - bad tty pointer - exiting", __func__); - return; - } - - if (tty && urb->actual_length) { - /* Loop through the data copying each byte to the tty layer. */ - tty_insert_flip_string(tty, data, urb->actual_length); - - /* Force the data to the tty layer. */ - tty_flip_buffer_push(tty); - } - tty_kref_put(tty); - - /* Set any port variables. */ - spin_lock_irqsave(&metro_priv->lock, flags); - throttled = metro_priv->throttled; - spin_unlock_irqrestore(&metro_priv->lock, flags); - - /* Continue trying to read if set. */ - if (!throttled) { - usb_fill_int_urb(port->interrupt_in_urb, port->serial->dev, - usb_rcvintpipe(port->serial->dev, port->interrupt_in_endpointAddress), - port->interrupt_in_urb->transfer_buffer, - port->interrupt_in_urb->transfer_buffer_length, - metrousb_read_int_callback, port, 1); - - result = usb_submit_urb(port->interrupt_in_urb, GFP_ATOMIC); - - if (result) { - dbg("METRO-USB - %s - failed submitting interrupt in urb for port number=%d, error code=%d", - __FUNCTION__, port->number, result); - } - } - return; - -exit: - /* Try to resubmit the urb. */ - result = usb_submit_urb(urb, GFP_ATOMIC); - if (result) { - dbg("METRO-USB - %s - failed submitting interrupt in urb for port number=%d, error code=%d", - __FUNCTION__, port->number, result); - } -} - /* ---------------------------------------------------------------------------------------------- Description: Set the modem control state for the entered serial port. @@ -522,6 +460,39 @@ static void metrousb_unthrottle(struct tty_struct *tty) } } +/* Driver structure. */ +static struct usb_driver metrousb_driver = { + .name = "metro-usb", + .probe = usb_serial_probe, + .disconnect = usb_serial_disconnect, + .id_table = id_table +}; + +/* Device structure. */ +static struct usb_serial_driver metrousb_device = { + .driver = { + .owner = THIS_MODULE, + .name = "metro-usb", + }, + .description = "Metrologic USB to serial converter.", + .id_table = id_table, + .num_ports = 1, + .open = metrousb_open, + .close = metrousb_cleanup, + .read_int_callback = metrousb_read_int_callback, + .attach = metrousb_startup, + .release = metrousb_shutdown, + .throttle = metrousb_throttle, + .unthrottle = metrousb_unthrottle, + .tiocmget = metrousb_tiocmget, + .tiocmset = metrousb_tiocmset, +}; + +static struct usb_serial_driver * const serial_drivers[] = { + &metrousb_device, + NULL, +}; + module_usb_serial_driver(metrousb_driver, serial_drivers); MODULE_LICENSE("GPL"); -- cgit v1.2.3-55-g7522 From dd63b0b4d6d036e1d5f7008c97c30789415489de Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Thu, 8 Mar 2012 13:58:13 -0800 Subject: USB: serial: metro-usb: remove function header comments They aren't needed, make the checkpatch tool unhappy, and in some places, aren't even correct. So just remove them, they get in the way and are messy. Cc: Aleksey Babahin Signed-off-by: Greg Kroah-Hartman --- drivers/usb/serial/metro-usb.c | 110 ----------------------------------------- 1 file changed, 110 deletions(-) (limited to 'drivers/usb/serial/metro-usb.c') diff --git a/drivers/usb/serial/metro-usb.c b/drivers/usb/serial/metro-usb.c index 8758e01289b9..e968d3396813 100644 --- a/drivers/usb/serial/metro-usb.c +++ b/drivers/usb/serial/metro-usb.c @@ -56,17 +56,6 @@ MODULE_DEVICE_TABLE(usb, id_table); /* Input parameter constants. */ static bool debug; -/* ---------------------------------------------------------------------------------------------- - Description: - Read the port from the read interrupt. - - Input: - struct urb *: urb structure to get data. - struct pt_regs *: pt_regs structure. - - Output: - None: -*/ static void metrousb_read_int_callback(struct urb *urb) { struct usb_serial_port *port = (struct usb_serial_port *)urb->context; @@ -144,16 +133,6 @@ exit: } } -/* ---------------------------------------------------------------------------------------------- - Description: - Clean up any urbs and port information. - - Input: - struct usb_serial_port *: pointer to a usb_serial_port structure. - - Output: - int: Returns true (0) if successful, false otherwise. -*/ static void metrousb_cleanup(struct usb_serial_port *port) { dbg("METRO-USB - %s - port number=%d", __FUNCTION__, port->number); @@ -167,17 +146,6 @@ static void metrousb_cleanup(struct usb_serial_port *port) } } -/* ---------------------------------------------------------------------------------------------- - Description: - Open the drivers serial port. - - Input: - struct usb_serial_port *: pointer to a usb_serial_port structure. - struct file *: pointer to a file structure. - - Output: - int: Returns true (0) if successful, false otherwise. -*/ static int metrousb_open(struct tty_struct *tty, struct usb_serial_port *port) { struct usb_serial *serial = port->serial; @@ -229,17 +197,6 @@ exit: return result; } -/* ---------------------------------------------------------------------------------------------- - Description: - Set the modem control state for the entered serial port. - - Input: - struct usb_serial_port *: pointer to a usb_serial_port structure. - unsigned int: control state value to set. - - Output: - int: Returns true (0) if successful, false otherwise. -*/ static int metrousb_set_modem_ctrl(struct usb_serial *serial, unsigned int control_state) { int retval = 0; @@ -263,17 +220,6 @@ static int metrousb_set_modem_ctrl(struct usb_serial *serial, unsigned int contr return retval; } - -/* ---------------------------------------------------------------------------------------------- - Description: - Shutdown the driver. - - Input: - struct usb_serial *: pointer to a usb-serial structure. - - Output: - int: Returns true (0) if successful, false otherwise. -*/ static void metrousb_shutdown(struct usb_serial *serial) { int i = 0; @@ -293,16 +239,6 @@ static void metrousb_shutdown(struct usb_serial *serial) } } -/* ---------------------------------------------------------------------------------------------- - Description: - Startup the driver. - - Input: - struct usb_serial *: pointer to a usb-serial structure. - - Output: - int: Returns true (0) if successful, false otherwise. -*/ static int metrousb_startup(struct usb_serial *serial) { struct metrousb_private *metro_priv; @@ -334,16 +270,6 @@ static int metrousb_startup(struct usb_serial *serial) return 0; } -/* ---------------------------------------------------------------------------------------------- - Description: - Set the serial port throttle to stop reading from the port. - - Input: - struct usb_serial_port *: pointer to a usb_serial_port structure. - - Output: - None: -*/ static void metrousb_throttle(struct tty_struct *tty) { struct usb_serial_port *port = tty->driver_data; @@ -358,17 +284,6 @@ static void metrousb_throttle(struct tty_struct *tty) spin_unlock_irqrestore(&metro_priv->lock, flags); } -/* ---------------------------------------------------------------------------------------------- - Description: - Get the serial port control line states. - - Input: - struct usb_serial_port *: pointer to a usb_serial_port structure. - struct file *: pointer to a file structure. - - Output: - int: Returns the state of the control lines. -*/ static int metrousb_tiocmget(struct tty_struct *tty) { unsigned long control_state = 0; @@ -385,19 +300,6 @@ static int metrousb_tiocmget(struct tty_struct *tty) return control_state; } -/* ---------------------------------------------------------------------------------------------- - Description: - Set the serial port control line states. - - Input: - struct usb_serial_port *: pointer to a usb_serial_port structure. - struct file *: pointer to a file structure. - unsigned int: line state to set. - unsigned int: line state to clear. - - Output: - int: Returns the state of the control lines. -*/ static int metrousb_tiocmset(struct tty_struct *tty, unsigned int set, unsigned int clear) { @@ -427,16 +329,6 @@ static int metrousb_tiocmset(struct tty_struct *tty, return metrousb_set_modem_ctrl(serial, control_state); } -/* ---------------------------------------------------------------------------------------------- - Description: - Set the serial port unthrottle to resume reading from the port. - - Input: - struct usb_serial_port *: pointer to a usb_serial_port structure. - - Output: - None: -*/ static void metrousb_unthrottle(struct tty_struct *tty) { struct usb_serial_port *port = tty->driver_data; @@ -460,7 +352,6 @@ static void metrousb_unthrottle(struct tty_struct *tty) } } -/* Driver structure. */ static struct usb_driver metrousb_driver = { .name = "metro-usb", .probe = usb_serial_probe, @@ -468,7 +359,6 @@ static struct usb_driver metrousb_driver = { .id_table = id_table }; -/* Device structure. */ static struct usb_serial_driver metrousb_device = { .driver = { .owner = THIS_MODULE, -- cgit v1.2.3-55-g7522 From 8111e4ecf9373f6d76504416b0e76b18372f3598 Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Thu, 8 Mar 2012 14:00:11 -0800 Subject: USB: serial: metro-usb: remove unneeded cast and function call We should use kzalloc() instead of kmalloc() and memset(), and remove an unneeded void * cast as well. Cc: Aleksey Babahin Signed-off-by: Greg Kroah-Hartman --- drivers/usb/serial/metro-usb.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) (limited to 'drivers/usb/serial/metro-usb.c') diff --git a/drivers/usb/serial/metro-usb.c b/drivers/usb/serial/metro-usb.c index e968d3396813..6b7d2779148c 100644 --- a/drivers/usb/serial/metro-usb.c +++ b/drivers/usb/serial/metro-usb.c @@ -58,7 +58,7 @@ static bool debug; static void metrousb_read_int_callback(struct urb *urb) { - struct usb_serial_port *port = (struct usb_serial_port *)urb->context; + struct usb_serial_port *port = urb->context; struct metrousb_private *metro_priv = usb_get_serial_port_data(port); struct tty_struct *tty; unsigned char *data = urb->transfer_buffer; @@ -253,13 +253,10 @@ static int metrousb_startup(struct usb_serial *serial) port = serial->port[i]; /* Declare memory. */ - metro_priv = kmalloc(sizeof(struct metrousb_private), GFP_KERNEL); + metro_priv = kzalloc(sizeof(struct metrousb_private), GFP_KERNEL); if (!metro_priv) return -ENOMEM; - /* Clear memory. */ - memset(metro_priv, 0x00, sizeof(struct metrousb_private)); - /* Initialize memory. */ spin_lock_init(&metro_priv->lock); usb_set_serial_port_data(port, metro_priv); -- cgit v1.2.3-55-g7522 From 5db51b50c10f3bf56d5c636832c5556ead90562d Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Thu, 8 Mar 2012 14:16:12 -0800 Subject: USB: serial: metro-usb: move to use dev_dbg() instead of dbg() This properly ties the driver into the dynamic debug system and provides the needed device identification when the messages are printed out. It also removes a ton of checkpatch warnings as well, which is always a nice validation that it's the correct thing to do. Cc: Aleksey Babahin Signed-off-by: Greg Kroah-Hartman --- drivers/usb/serial/metro-usb.c | 78 ++++++++++++++++++++++++------------------ 1 file changed, 44 insertions(+), 34 deletions(-) (limited to 'drivers/usb/serial/metro-usb.c') diff --git a/drivers/usb/serial/metro-usb.c b/drivers/usb/serial/metro-usb.c index 6b7d2779148c..6e1622f2a297 100644 --- a/drivers/usb/serial/metro-usb.c +++ b/drivers/usb/serial/metro-usb.c @@ -66,7 +66,7 @@ static void metrousb_read_int_callback(struct urb *urb) int result = 0; unsigned long flags = 0; - dbg("METRO-USB - %s - port number=%d", __FUNCTION__, port->number); + dev_dbg(&port->dev, "%s\n", __func__); switch (urb->status) { case 0: @@ -76,12 +76,14 @@ static void metrousb_read_int_callback(struct urb *urb) case -ENOENT: case -ESHUTDOWN: /* urb has been terminated. */ - dbg("METRO-USB - %s - urb shutting down, port number=%d, error code=%d", - __FUNCTION__, port->number, result); + dev_dbg(&port->dev, + "%s - urb shutting down, error code=%d\n", + __func__, result); return; default: - dbg("METRO-USB - %s - non-zero urb received, port number=%d, error code=%d", - __FUNCTION__, port->number, result); + dev_dbg(&port->dev, + "%s - non-zero urb received, error code=%d\n", + __func__, result); goto exit; } @@ -89,7 +91,8 @@ static void metrousb_read_int_callback(struct urb *urb) /* Set the data read from the usb port into the serial port buffer. */ tty = tty_port_tty_get(&port->port); if (!tty) { - dbg("%s - bad tty pointer - exiting", __func__); + dev_dbg(&port->dev, "%s - bad tty pointer - exiting\n", + __func__); return; } @@ -117,25 +120,25 @@ static void metrousb_read_int_callback(struct urb *urb) result = usb_submit_urb(port->interrupt_in_urb, GFP_ATOMIC); - if (result) { - dbg("METRO-USB - %s - failed submitting interrupt in urb for port number=%d, error code=%d", - __FUNCTION__, port->number, result); - } + if (result) + dev_dbg(&port->dev, + "%s - failed submitting interrupt in urb, error code=%d\n", + __func__, result); } return; exit: /* Try to resubmit the urb. */ result = usb_submit_urb(urb, GFP_ATOMIC); - if (result) { - dbg("METRO-USB - %s - failed submitting interrupt in urb for port number=%d, error code=%d", - __FUNCTION__, port->number, result); - } + if (result) + dev_dbg(&port->dev, + "%s - failed submitting interrupt in urb, error code=%d\n", + __func__, result); } static void metrousb_cleanup(struct usb_serial_port *port) { - dbg("METRO-USB - %s - port number=%d", __FUNCTION__, port->number); + dev_dbg(&port->dev, "%s\n", __func__); if (port->serial->dev) { /* Shutdown any interrupt in urbs. */ @@ -153,11 +156,12 @@ static int metrousb_open(struct tty_struct *tty, struct usb_serial_port *port) unsigned long flags = 0; int result = 0; - dbg("METRO-USB - %s - port number=%d", __FUNCTION__, port->number); + dev_dbg(&port->dev, "%s\n", __func__); /* Make sure the urb is initialized. */ if (!port->interrupt_in_urb) { - dbg("METRO-USB - %s - interrupt urb not initialized for port number=%d", __FUNCTION__, port->number); + dev_dbg(&port->dev, "%s - interrupt urb not initialized\n", + __func__); return -ENODEV; } @@ -187,12 +191,13 @@ static int metrousb_open(struct tty_struct *tty, struct usb_serial_port *port) result = usb_submit_urb(port->interrupt_in_urb, GFP_KERNEL); if (result) { - dbg("METRO-USB - %s - failed submitting interrupt in urb for port number=%d, error code=%d" - , __FUNCTION__, port->number, result); + dev_dbg(&port->dev, + "%s - failed submitting interrupt in urb, error code=%d\n", + __func__, result); goto exit; } - dbg("METRO-USB - %s - port open for port number=%d", __FUNCTION__, port->number); + dev_dbg(&port->dev, "%s - port open\n", __func__); exit: return result; } @@ -202,7 +207,8 @@ static int metrousb_set_modem_ctrl(struct usb_serial *serial, unsigned int contr int retval = 0; unsigned char mcr = METROUSB_MCR_NONE; - dbg("METRO-USB - %s - control state=%d", __FUNCTION__, control_state); + dev_dbg(&serial->dev->dev, "%s - control state = %d\n", + __func__, control_state); /* Set the modem control value. */ if (control_state & TIOCM_DTR) @@ -215,7 +221,9 @@ static int metrousb_set_modem_ctrl(struct usb_serial *serial, unsigned int contr METROUSB_SET_REQUEST_TYPE, METROUSB_SET_MODEM_CTRL_REQUEST, control_state, 0, NULL, 0, WDR_TIMEOUT); if (retval < 0) - dbg("METRO-USB - %s - set modem ctrl=0x%x failed, error code=%d", __FUNCTION__, mcr, retval); + dev_dbg(&serial->dev->dev, + "%s - set modem ctrl=0x%x failed, error code=%d\n", + __func__, mcr, retval); return retval; } @@ -224,7 +232,7 @@ static void metrousb_shutdown(struct usb_serial *serial) { int i = 0; - dbg("METRO-USB - %s", __FUNCTION__); + dev_dbg(&serial->dev->dev, "%s\n", __func__); /* Stop reading and writing on all ports. */ for (i = 0; i < serial->num_ports; ++i) { @@ -235,7 +243,8 @@ static void metrousb_shutdown(struct usb_serial *serial) kfree(usb_get_serial_port_data(serial->port[i])); usb_set_serial_port_data(serial->port[i], NULL); - dbg("METRO-USB - %s - freed port number=%d", __FUNCTION__, serial->port[i]->number); + dev_dbg(&serial->dev->dev, "%s - freed port number=%d\n", + __func__, serial->port[i]->number); } } @@ -245,7 +254,7 @@ static int metrousb_startup(struct usb_serial *serial) struct usb_serial_port *port; int i = 0; - dbg("METRO-USB - %s", __FUNCTION__); + dev_dbg(&serial->dev->dev, "%s\n", __func__); /* Loop through the serial ports setting up the private structures. * Currently we only use one port. */ @@ -261,7 +270,8 @@ static int metrousb_startup(struct usb_serial *serial) spin_lock_init(&metro_priv->lock); usb_set_serial_port_data(port, metro_priv); - dbg("METRO-USB - %s - port number=%d.", __FUNCTION__, port->number); + dev_dbg(&serial->dev->dev, "%s - port number=%d\n ", + __func__, port->number); } return 0; @@ -273,7 +283,7 @@ static void metrousb_throttle(struct tty_struct *tty) struct metrousb_private *metro_priv = usb_get_serial_port_data(port); unsigned long flags = 0; - dbg("METRO-USB - %s - port number=%d", __FUNCTION__, port->number); + dev_dbg(tty->dev, "%s\n", __func__); /* Set the private information for the port to stop reading data. */ spin_lock_irqsave(&metro_priv->lock, flags); @@ -288,7 +298,7 @@ static int metrousb_tiocmget(struct tty_struct *tty) struct metrousb_private *metro_priv = usb_get_serial_port_data(port); unsigned long flags = 0; - dbg("METRO-USB - %s - port number=%d", __FUNCTION__, port->number); + dev_dbg(tty->dev, "%s\n", __func__); spin_lock_irqsave(&metro_priv->lock, flags); control_state = metro_priv->control_state; @@ -306,7 +316,7 @@ static int metrousb_tiocmset(struct tty_struct *tty, unsigned long flags = 0; unsigned long control_state = 0; - dbg("METRO-USB - %s - port number=%d, set=%d, clear=%d", __FUNCTION__, port->number, set, clear); + dev_dbg(tty->dev, "%s - set=%d, clear=%d\n", __func__, set, clear); spin_lock_irqsave(&metro_priv->lock, flags); control_state = metro_priv->control_state; @@ -333,7 +343,7 @@ static void metrousb_unthrottle(struct tty_struct *tty) unsigned long flags = 0; int result = 0; - dbg("METRO-USB - %s - port number=%d", __FUNCTION__, port->number); + dev_dbg(tty->dev, "%s\n", __func__); /* Set the private information for the port to resume reading data. */ spin_lock_irqsave(&metro_priv->lock, flags); @@ -343,10 +353,10 @@ static void metrousb_unthrottle(struct tty_struct *tty) /* Submit the urb to read from the port. */ port->interrupt_in_urb->dev = port->serial->dev; result = usb_submit_urb(port->interrupt_in_urb, GFP_ATOMIC); - if (result) { - dbg("METRO-USB - %s - failed submitting interrupt in urb for port number=%d, error code=%d", - __FUNCTION__, port->number, result); - } + if (result) + dev_dbg(tty->dev, + "failed submitting interrupt in urb error code=%d\n", + result); } static struct usb_driver metrousb_driver = { -- cgit v1.2.3-55-g7522