Aleksey Babahin | 43d186f | 2012-03-08 13:18:43 -0800 | [diff] [blame] | 1 | /* |
Greg Kroah-Hartman | d4cbd6e | 2012-03-08 13:50:54 -0800 | [diff] [blame] | 2 | Some of this code is credited to Linux USB open source files that are |
| 3 | distributed with Linux. |
Aleksey Babahin | 43d186f | 2012-03-08 13:18:43 -0800 | [diff] [blame] | 4 | |
| 5 | Copyright: 2007 Metrologic Instruments. All rights reserved. |
| 6 | Copyright: 2011 Azimut Ltd. <http://azimutrzn.ru/> |
Aleksey Babahin | 43d186f | 2012-03-08 13:18:43 -0800 | [diff] [blame] | 7 | */ |
| 8 | |
| 9 | #include <linux/kernel.h> |
| 10 | #include <linux/init.h> |
| 11 | #include <linux/tty.h> |
| 12 | #include <linux/module.h> |
| 13 | #include <linux/usb.h> |
| 14 | #include <linux/errno.h> |
| 15 | #include <linux/slab.h> |
| 16 | #include <linux/tty_driver.h> |
| 17 | #include <linux/tty_flip.h> |
| 18 | #include <linux/moduleparam.h> |
| 19 | #include <linux/spinlock.h> |
Aleksey Babahin | 43d186f | 2012-03-08 13:18:43 -0800 | [diff] [blame] | 20 | #include <linux/errno.h> |
Greg Kroah-Hartman | d4cbd6e | 2012-03-08 13:50:54 -0800 | [diff] [blame] | 21 | #include <linux/uaccess.h> |
Aleksey Babahin | 43d186f | 2012-03-08 13:18:43 -0800 | [diff] [blame] | 22 | #include <linux/usb/serial.h> |
| 23 | |
| 24 | /* Version Information */ |
| 25 | #define DRIVER_VERSION "v1.2.0.0" |
| 26 | #define DRIVER_DESC "Metrologic Instruments Inc. - USB-POS driver" |
| 27 | |
Greg Kroah-Hartman | 159d4d8 | 2012-03-08 13:42:41 -0800 | [diff] [blame] | 28 | /* Product information. */ |
| 29 | #define FOCUS_VENDOR_ID 0x0C2E |
Aleksey Babahin | 810ec78 | 2012-03-20 00:46:31 +0400 | [diff] [blame] | 30 | #define FOCUS_PRODUCT_ID_BI 0x0720 |
| 31 | #define FOCUS_PRODUCT_ID_UNI 0x0700 |
Greg Kroah-Hartman | 159d4d8 | 2012-03-08 13:42:41 -0800 | [diff] [blame] | 32 | |
| 33 | #define METROUSB_SET_REQUEST_TYPE 0x40 |
| 34 | #define METROUSB_SET_MODEM_CTRL_REQUEST 10 |
| 35 | #define METROUSB_SET_BREAK_REQUEST 0x40 |
| 36 | #define METROUSB_MCR_NONE 0x08 /* Deactivate DTR and RTS. */ |
| 37 | #define METROUSB_MCR_RTS 0x0a /* Activate RTS. */ |
| 38 | #define METROUSB_MCR_DTR 0x09 /* Activate DTR. */ |
Greg Kroah-Hartman | d4cbd6e | 2012-03-08 13:50:54 -0800 | [diff] [blame] | 39 | #define WDR_TIMEOUT 5000 /* default urb timeout. */ |
Greg Kroah-Hartman | 159d4d8 | 2012-03-08 13:42:41 -0800 | [diff] [blame] | 40 | |
| 41 | /* Private data structure. */ |
| 42 | struct metrousb_private { |
| 43 | spinlock_t lock; |
| 44 | int throttled; |
| 45 | unsigned long control_state; |
| 46 | }; |
| 47 | |
Aleksey Babahin | 43d186f | 2012-03-08 13:18:43 -0800 | [diff] [blame] | 48 | /* Device table list. */ |
Greg Kroah-Hartman | d4cbd6e | 2012-03-08 13:50:54 -0800 | [diff] [blame] | 49 | static struct usb_device_id id_table[] = { |
Aleksey Babahin | 810ec78 | 2012-03-20 00:46:31 +0400 | [diff] [blame] | 50 | { USB_DEVICE(FOCUS_VENDOR_ID, FOCUS_PRODUCT_ID_BI) }, |
Aleksey Babahin | 43d186f | 2012-03-08 13:18:43 -0800 | [diff] [blame] | 51 | { USB_DEVICE(FOCUS_VENDOR_ID, FOCUS_PRODUCT_ID_UNI) }, |
Aleksey Babahin | 43d186f | 2012-03-08 13:18:43 -0800 | [diff] [blame] | 52 | { }, /* Terminating entry. */ |
| 53 | }; |
| 54 | MODULE_DEVICE_TABLE(usb, id_table); |
| 55 | |
| 56 | /* Input parameter constants. */ |
Greg Kroah-Hartman | fdac0f6 | 2012-03-08 13:37:32 -0800 | [diff] [blame] | 57 | static bool debug; |
Aleksey Babahin | 43d186f | 2012-03-08 13:18:43 -0800 | [diff] [blame] | 58 | |
Greg Kroah-Hartman | d4cbd6e | 2012-03-08 13:50:54 -0800 | [diff] [blame] | 59 | static void metrousb_read_int_callback(struct urb *urb) |
Aleksey Babahin | 43d186f | 2012-03-08 13:18:43 -0800 | [diff] [blame] | 60 | { |
Greg Kroah-Hartman | 8111e4e | 2012-03-08 14:00:11 -0800 | [diff] [blame] | 61 | struct usb_serial_port *port = urb->context; |
Aleksey Babahin | 43d186f | 2012-03-08 13:18:43 -0800 | [diff] [blame] | 62 | struct metrousb_private *metro_priv = usb_get_serial_port_data(port); |
| 63 | struct tty_struct *tty; |
| 64 | unsigned char *data = urb->transfer_buffer; |
| 65 | int throttled = 0; |
| 66 | int result = 0; |
| 67 | unsigned long flags = 0; |
| 68 | |
Greg Kroah-Hartman | 5db51b5 | 2012-03-08 14:16:12 -0800 | [diff] [blame] | 69 | dev_dbg(&port->dev, "%s\n", __func__); |
Aleksey Babahin | 43d186f | 2012-03-08 13:18:43 -0800 | [diff] [blame] | 70 | |
| 71 | switch (urb->status) { |
Greg Kroah-Hartman | d4cbd6e | 2012-03-08 13:50:54 -0800 | [diff] [blame] | 72 | case 0: |
| 73 | /* Success status, read from the port. */ |
| 74 | break; |
| 75 | case -ECONNRESET: |
| 76 | case -ENOENT: |
| 77 | case -ESHUTDOWN: |
| 78 | /* urb has been terminated. */ |
Greg Kroah-Hartman | 5db51b5 | 2012-03-08 14:16:12 -0800 | [diff] [blame] | 79 | dev_dbg(&port->dev, |
| 80 | "%s - urb shutting down, error code=%d\n", |
| 81 | __func__, result); |
Greg Kroah-Hartman | d4cbd6e | 2012-03-08 13:50:54 -0800 | [diff] [blame] | 82 | return; |
| 83 | default: |
Greg Kroah-Hartman | 5db51b5 | 2012-03-08 14:16:12 -0800 | [diff] [blame] | 84 | dev_dbg(&port->dev, |
| 85 | "%s - non-zero urb received, error code=%d\n", |
| 86 | __func__, result); |
Greg Kroah-Hartman | d4cbd6e | 2012-03-08 13:50:54 -0800 | [diff] [blame] | 87 | goto exit; |
Aleksey Babahin | 43d186f | 2012-03-08 13:18:43 -0800 | [diff] [blame] | 88 | } |
| 89 | |
| 90 | |
| 91 | /* Set the data read from the usb port into the serial port buffer. */ |
| 92 | tty = tty_port_tty_get(&port->port); |
| 93 | if (!tty) { |
Greg Kroah-Hartman | 5db51b5 | 2012-03-08 14:16:12 -0800 | [diff] [blame] | 94 | dev_dbg(&port->dev, "%s - bad tty pointer - exiting\n", |
| 95 | __func__); |
Aleksey Babahin | 43d186f | 2012-03-08 13:18:43 -0800 | [diff] [blame] | 96 | return; |
| 97 | } |
| 98 | |
| 99 | if (tty && urb->actual_length) { |
Greg Kroah-Hartman | d4cbd6e | 2012-03-08 13:50:54 -0800 | [diff] [blame] | 100 | /* Loop through the data copying each byte to the tty layer. */ |
Aleksey Babahin | 43d186f | 2012-03-08 13:18:43 -0800 | [diff] [blame] | 101 | tty_insert_flip_string(tty, data, urb->actual_length); |
| 102 | |
Greg Kroah-Hartman | d4cbd6e | 2012-03-08 13:50:54 -0800 | [diff] [blame] | 103 | /* Force the data to the tty layer. */ |
Aleksey Babahin | 43d186f | 2012-03-08 13:18:43 -0800 | [diff] [blame] | 104 | tty_flip_buffer_push(tty); |
| 105 | } |
| 106 | tty_kref_put(tty); |
| 107 | |
| 108 | /* Set any port variables. */ |
| 109 | spin_lock_irqsave(&metro_priv->lock, flags); |
| 110 | throttled = metro_priv->throttled; |
| 111 | spin_unlock_irqrestore(&metro_priv->lock, flags); |
| 112 | |
| 113 | /* Continue trying to read if set. */ |
| 114 | if (!throttled) { |
Greg Kroah-Hartman | d4cbd6e | 2012-03-08 13:50:54 -0800 | [diff] [blame] | 115 | usb_fill_int_urb(port->interrupt_in_urb, port->serial->dev, |
| 116 | usb_rcvintpipe(port->serial->dev, port->interrupt_in_endpointAddress), |
| 117 | port->interrupt_in_urb->transfer_buffer, |
| 118 | port->interrupt_in_urb->transfer_buffer_length, |
| 119 | metrousb_read_int_callback, port, 1); |
Aleksey Babahin | 43d186f | 2012-03-08 13:18:43 -0800 | [diff] [blame] | 120 | |
| 121 | result = usb_submit_urb(port->interrupt_in_urb, GFP_ATOMIC); |
| 122 | |
Greg Kroah-Hartman | 5db51b5 | 2012-03-08 14:16:12 -0800 | [diff] [blame] | 123 | if (result) |
| 124 | dev_dbg(&port->dev, |
| 125 | "%s - failed submitting interrupt in urb, error code=%d\n", |
| 126 | __func__, result); |
Aleksey Babahin | 43d186f | 2012-03-08 13:18:43 -0800 | [diff] [blame] | 127 | } |
| 128 | return; |
| 129 | |
| 130 | exit: |
| 131 | /* Try to resubmit the urb. */ |
Greg Kroah-Hartman | d4cbd6e | 2012-03-08 13:50:54 -0800 | [diff] [blame] | 132 | result = usb_submit_urb(urb, GFP_ATOMIC); |
Greg Kroah-Hartman | 5db51b5 | 2012-03-08 14:16:12 -0800 | [diff] [blame] | 133 | if (result) |
| 134 | dev_dbg(&port->dev, |
| 135 | "%s - failed submitting interrupt in urb, error code=%d\n", |
| 136 | __func__, result); |
Aleksey Babahin | 43d186f | 2012-03-08 13:18:43 -0800 | [diff] [blame] | 137 | } |
| 138 | |
Aleksey Babahin | 28a4b6a | 2012-03-20 00:46:32 +0400 | [diff] [blame^] | 139 | static void metrousb_write_int_callback(struct urb *urb) |
| 140 | { |
| 141 | struct usb_serial_port *port = urb->context; |
| 142 | |
| 143 | dev_warn(&port->dev, "%s not implemented yet.\n", |
| 144 | __func__); |
| 145 | } |
| 146 | |
Greg Kroah-Hartman | 9fbd164 | 2012-03-08 13:55:41 -0800 | [diff] [blame] | 147 | static void metrousb_cleanup(struct usb_serial_port *port) |
| 148 | { |
Greg Kroah-Hartman | 5db51b5 | 2012-03-08 14:16:12 -0800 | [diff] [blame] | 149 | dev_dbg(&port->dev, "%s\n", __func__); |
Greg Kroah-Hartman | 9fbd164 | 2012-03-08 13:55:41 -0800 | [diff] [blame] | 150 | |
| 151 | if (port->serial->dev) { |
| 152 | /* Shutdown any interrupt in urbs. */ |
| 153 | if (port->interrupt_in_urb) { |
| 154 | usb_unlink_urb(port->interrupt_in_urb); |
| 155 | usb_kill_urb(port->interrupt_in_urb); |
| 156 | } |
| 157 | } |
| 158 | } |
| 159 | |
Greg Kroah-Hartman | 9fbd164 | 2012-03-08 13:55:41 -0800 | [diff] [blame] | 160 | static int metrousb_open(struct tty_struct *tty, struct usb_serial_port *port) |
| 161 | { |
| 162 | struct usb_serial *serial = port->serial; |
| 163 | struct metrousb_private *metro_priv = usb_get_serial_port_data(port); |
| 164 | unsigned long flags = 0; |
| 165 | int result = 0; |
| 166 | |
Greg Kroah-Hartman | 5db51b5 | 2012-03-08 14:16:12 -0800 | [diff] [blame] | 167 | dev_dbg(&port->dev, "%s\n", __func__); |
Greg Kroah-Hartman | 9fbd164 | 2012-03-08 13:55:41 -0800 | [diff] [blame] | 168 | |
| 169 | /* Make sure the urb is initialized. */ |
| 170 | if (!port->interrupt_in_urb) { |
Greg Kroah-Hartman | 5db51b5 | 2012-03-08 14:16:12 -0800 | [diff] [blame] | 171 | dev_dbg(&port->dev, "%s - interrupt urb not initialized\n", |
| 172 | __func__); |
Greg Kroah-Hartman | 9fbd164 | 2012-03-08 13:55:41 -0800 | [diff] [blame] | 173 | return -ENODEV; |
| 174 | } |
| 175 | |
| 176 | /* Set the private data information for the port. */ |
| 177 | spin_lock_irqsave(&metro_priv->lock, flags); |
| 178 | metro_priv->control_state = 0; |
| 179 | metro_priv->throttled = 0; |
| 180 | spin_unlock_irqrestore(&metro_priv->lock, flags); |
| 181 | |
| 182 | /* |
| 183 | * Force low_latency on so that our tty_push actually forces the data |
| 184 | * through, otherwise it is scheduled, and with high data rates (like |
| 185 | * with OHCI) data can get lost. |
| 186 | */ |
| 187 | if (tty) |
| 188 | tty->low_latency = 1; |
| 189 | |
| 190 | /* Clear the urb pipe. */ |
| 191 | usb_clear_halt(serial->dev, port->interrupt_in_urb->pipe); |
| 192 | |
| 193 | /* Start reading from the device */ |
| 194 | usb_fill_int_urb(port->interrupt_in_urb, serial->dev, |
| 195 | usb_rcvintpipe(serial->dev, port->interrupt_in_endpointAddress), |
| 196 | port->interrupt_in_urb->transfer_buffer, |
| 197 | port->interrupt_in_urb->transfer_buffer_length, |
| 198 | metrousb_read_int_callback, port, 1); |
| 199 | result = usb_submit_urb(port->interrupt_in_urb, GFP_KERNEL); |
| 200 | |
| 201 | if (result) { |
Greg Kroah-Hartman | 5db51b5 | 2012-03-08 14:16:12 -0800 | [diff] [blame] | 202 | dev_dbg(&port->dev, |
| 203 | "%s - failed submitting interrupt in urb, error code=%d\n", |
| 204 | __func__, result); |
Greg Kroah-Hartman | 9fbd164 | 2012-03-08 13:55:41 -0800 | [diff] [blame] | 205 | goto exit; |
| 206 | } |
| 207 | |
Greg Kroah-Hartman | 5db51b5 | 2012-03-08 14:16:12 -0800 | [diff] [blame] | 208 | dev_dbg(&port->dev, "%s - port open\n", __func__); |
Greg Kroah-Hartman | 9fbd164 | 2012-03-08 13:55:41 -0800 | [diff] [blame] | 209 | exit: |
| 210 | return result; |
| 211 | } |
| 212 | |
Aleksey Babahin | 43d186f | 2012-03-08 13:18:43 -0800 | [diff] [blame] | 213 | static int metrousb_set_modem_ctrl(struct usb_serial *serial, unsigned int control_state) |
| 214 | { |
| 215 | int retval = 0; |
| 216 | unsigned char mcr = METROUSB_MCR_NONE; |
| 217 | |
Greg Kroah-Hartman | 5db51b5 | 2012-03-08 14:16:12 -0800 | [diff] [blame] | 218 | dev_dbg(&serial->dev->dev, "%s - control state = %d\n", |
| 219 | __func__, control_state); |
Aleksey Babahin | 43d186f | 2012-03-08 13:18:43 -0800 | [diff] [blame] | 220 | |
| 221 | /* Set the modem control value. */ |
| 222 | if (control_state & TIOCM_DTR) |
| 223 | mcr |= METROUSB_MCR_DTR; |
| 224 | if (control_state & TIOCM_RTS) |
| 225 | mcr |= METROUSB_MCR_RTS; |
| 226 | |
| 227 | /* Send the command to the usb port. */ |
| 228 | retval = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0), |
| 229 | METROUSB_SET_REQUEST_TYPE, METROUSB_SET_MODEM_CTRL_REQUEST, |
| 230 | control_state, 0, NULL, 0, WDR_TIMEOUT); |
| 231 | if (retval < 0) |
Greg Kroah-Hartman | 5db51b5 | 2012-03-08 14:16:12 -0800 | [diff] [blame] | 232 | dev_dbg(&serial->dev->dev, |
| 233 | "%s - set modem ctrl=0x%x failed, error code=%d\n", |
| 234 | __func__, mcr, retval); |
Aleksey Babahin | 43d186f | 2012-03-08 13:18:43 -0800 | [diff] [blame] | 235 | |
| 236 | return retval; |
| 237 | } |
| 238 | |
Greg Kroah-Hartman | d4cbd6e | 2012-03-08 13:50:54 -0800 | [diff] [blame] | 239 | static void metrousb_shutdown(struct usb_serial *serial) |
Aleksey Babahin | 43d186f | 2012-03-08 13:18:43 -0800 | [diff] [blame] | 240 | { |
| 241 | int i = 0; |
| 242 | |
Greg Kroah-Hartman | 5db51b5 | 2012-03-08 14:16:12 -0800 | [diff] [blame] | 243 | dev_dbg(&serial->dev->dev, "%s\n", __func__); |
Aleksey Babahin | 43d186f | 2012-03-08 13:18:43 -0800 | [diff] [blame] | 244 | |
| 245 | /* Stop reading and writing on all ports. */ |
Greg Kroah-Hartman | d4cbd6e | 2012-03-08 13:50:54 -0800 | [diff] [blame] | 246 | for (i = 0; i < serial->num_ports; ++i) { |
Aleksey Babahin | 43d186f | 2012-03-08 13:18:43 -0800 | [diff] [blame] | 247 | /* Close any open urbs. */ |
| 248 | metrousb_cleanup(serial->port[i]); |
| 249 | |
| 250 | /* Free memory. */ |
| 251 | kfree(usb_get_serial_port_data(serial->port[i])); |
| 252 | usb_set_serial_port_data(serial->port[i], NULL); |
| 253 | |
Greg Kroah-Hartman | 5db51b5 | 2012-03-08 14:16:12 -0800 | [diff] [blame] | 254 | dev_dbg(&serial->dev->dev, "%s - freed port number=%d\n", |
| 255 | __func__, serial->port[i]->number); |
Aleksey Babahin | 43d186f | 2012-03-08 13:18:43 -0800 | [diff] [blame] | 256 | } |
| 257 | } |
| 258 | |
Aleksey Babahin | 43d186f | 2012-03-08 13:18:43 -0800 | [diff] [blame] | 259 | static int metrousb_startup(struct usb_serial *serial) |
| 260 | { |
| 261 | struct metrousb_private *metro_priv; |
| 262 | struct usb_serial_port *port; |
| 263 | int i = 0; |
| 264 | |
Greg Kroah-Hartman | 5db51b5 | 2012-03-08 14:16:12 -0800 | [diff] [blame] | 265 | dev_dbg(&serial->dev->dev, "%s\n", __func__); |
Aleksey Babahin | 43d186f | 2012-03-08 13:18:43 -0800 | [diff] [blame] | 266 | |
| 267 | /* Loop through the serial ports setting up the private structures. |
| 268 | * Currently we only use one port. */ |
| 269 | for (i = 0; i < serial->num_ports; ++i) { |
| 270 | port = serial->port[i]; |
| 271 | |
| 272 | /* Declare memory. */ |
Greg Kroah-Hartman | 8111e4e | 2012-03-08 14:00:11 -0800 | [diff] [blame] | 273 | metro_priv = kzalloc(sizeof(struct metrousb_private), GFP_KERNEL); |
Aleksey Babahin | 43d186f | 2012-03-08 13:18:43 -0800 | [diff] [blame] | 274 | if (!metro_priv) |
| 275 | return -ENOMEM; |
| 276 | |
Aleksey Babahin | 43d186f | 2012-03-08 13:18:43 -0800 | [diff] [blame] | 277 | /* Initialize memory. */ |
| 278 | spin_lock_init(&metro_priv->lock); |
| 279 | usb_set_serial_port_data(port, metro_priv); |
| 280 | |
Greg Kroah-Hartman | 5db51b5 | 2012-03-08 14:16:12 -0800 | [diff] [blame] | 281 | dev_dbg(&serial->dev->dev, "%s - port number=%d\n ", |
| 282 | __func__, port->number); |
Aleksey Babahin | 43d186f | 2012-03-08 13:18:43 -0800 | [diff] [blame] | 283 | } |
| 284 | |
| 285 | return 0; |
| 286 | } |
| 287 | |
Greg Kroah-Hartman | d4cbd6e | 2012-03-08 13:50:54 -0800 | [diff] [blame] | 288 | static void metrousb_throttle(struct tty_struct *tty) |
Aleksey Babahin | 43d186f | 2012-03-08 13:18:43 -0800 | [diff] [blame] | 289 | { |
| 290 | struct usb_serial_port *port = tty->driver_data; |
| 291 | struct metrousb_private *metro_priv = usb_get_serial_port_data(port); |
| 292 | unsigned long flags = 0; |
| 293 | |
Greg Kroah-Hartman | 5db51b5 | 2012-03-08 14:16:12 -0800 | [diff] [blame] | 294 | dev_dbg(tty->dev, "%s\n", __func__); |
Aleksey Babahin | 43d186f | 2012-03-08 13:18:43 -0800 | [diff] [blame] | 295 | |
| 296 | /* Set the private information for the port to stop reading data. */ |
| 297 | spin_lock_irqsave(&metro_priv->lock, flags); |
| 298 | metro_priv->throttled = 1; |
| 299 | spin_unlock_irqrestore(&metro_priv->lock, flags); |
| 300 | } |
| 301 | |
Greg Kroah-Hartman | d4cbd6e | 2012-03-08 13:50:54 -0800 | [diff] [blame] | 302 | static int metrousb_tiocmget(struct tty_struct *tty) |
Aleksey Babahin | 43d186f | 2012-03-08 13:18:43 -0800 | [diff] [blame] | 303 | { |
| 304 | unsigned long control_state = 0; |
| 305 | struct usb_serial_port *port = tty->driver_data; |
| 306 | struct metrousb_private *metro_priv = usb_get_serial_port_data(port); |
| 307 | unsigned long flags = 0; |
| 308 | |
Greg Kroah-Hartman | 5db51b5 | 2012-03-08 14:16:12 -0800 | [diff] [blame] | 309 | dev_dbg(tty->dev, "%s\n", __func__); |
Aleksey Babahin | 43d186f | 2012-03-08 13:18:43 -0800 | [diff] [blame] | 310 | |
| 311 | spin_lock_irqsave(&metro_priv->lock, flags); |
| 312 | control_state = metro_priv->control_state; |
| 313 | spin_unlock_irqrestore(&metro_priv->lock, flags); |
| 314 | |
| 315 | return control_state; |
| 316 | } |
| 317 | |
Greg Kroah-Hartman | d4cbd6e | 2012-03-08 13:50:54 -0800 | [diff] [blame] | 318 | static int metrousb_tiocmset(struct tty_struct *tty, |
| 319 | unsigned int set, unsigned int clear) |
Aleksey Babahin | 43d186f | 2012-03-08 13:18:43 -0800 | [diff] [blame] | 320 | { |
| 321 | struct usb_serial_port *port = tty->driver_data; |
| 322 | struct usb_serial *serial = port->serial; |
| 323 | struct metrousb_private *metro_priv = usb_get_serial_port_data(port); |
| 324 | unsigned long flags = 0; |
| 325 | unsigned long control_state = 0; |
| 326 | |
Greg Kroah-Hartman | 5db51b5 | 2012-03-08 14:16:12 -0800 | [diff] [blame] | 327 | dev_dbg(tty->dev, "%s - set=%d, clear=%d\n", __func__, set, clear); |
Aleksey Babahin | 43d186f | 2012-03-08 13:18:43 -0800 | [diff] [blame] | 328 | |
| 329 | spin_lock_irqsave(&metro_priv->lock, flags); |
| 330 | control_state = metro_priv->control_state; |
| 331 | |
Greg Kroah-Hartman | d4cbd6e | 2012-03-08 13:50:54 -0800 | [diff] [blame] | 332 | /* Set the RTS and DTR values. */ |
Aleksey Babahin | 43d186f | 2012-03-08 13:18:43 -0800 | [diff] [blame] | 333 | if (set & TIOCM_RTS) |
| 334 | control_state |= TIOCM_RTS; |
| 335 | if (set & TIOCM_DTR) |
| 336 | control_state |= TIOCM_DTR; |
| 337 | if (clear & TIOCM_RTS) |
| 338 | control_state &= ~TIOCM_RTS; |
| 339 | if (clear & TIOCM_DTR) |
| 340 | control_state &= ~TIOCM_DTR; |
| 341 | |
| 342 | metro_priv->control_state = control_state; |
| 343 | spin_unlock_irqrestore(&metro_priv->lock, flags); |
| 344 | return metrousb_set_modem_ctrl(serial, control_state); |
| 345 | } |
| 346 | |
Greg Kroah-Hartman | d4cbd6e | 2012-03-08 13:50:54 -0800 | [diff] [blame] | 347 | static void metrousb_unthrottle(struct tty_struct *tty) |
Aleksey Babahin | 43d186f | 2012-03-08 13:18:43 -0800 | [diff] [blame] | 348 | { |
| 349 | struct usb_serial_port *port = tty->driver_data; |
| 350 | struct metrousb_private *metro_priv = usb_get_serial_port_data(port); |
| 351 | unsigned long flags = 0; |
| 352 | int result = 0; |
| 353 | |
Greg Kroah-Hartman | 5db51b5 | 2012-03-08 14:16:12 -0800 | [diff] [blame] | 354 | dev_dbg(tty->dev, "%s\n", __func__); |
Aleksey Babahin | 43d186f | 2012-03-08 13:18:43 -0800 | [diff] [blame] | 355 | |
| 356 | /* Set the private information for the port to resume reading data. */ |
| 357 | spin_lock_irqsave(&metro_priv->lock, flags); |
| 358 | metro_priv->throttled = 0; |
| 359 | spin_unlock_irqrestore(&metro_priv->lock, flags); |
| 360 | |
| 361 | /* Submit the urb to read from the port. */ |
| 362 | port->interrupt_in_urb->dev = port->serial->dev; |
| 363 | result = usb_submit_urb(port->interrupt_in_urb, GFP_ATOMIC); |
Greg Kroah-Hartman | 5db51b5 | 2012-03-08 14:16:12 -0800 | [diff] [blame] | 364 | if (result) |
| 365 | dev_dbg(tty->dev, |
| 366 | "failed submitting interrupt in urb error code=%d\n", |
| 367 | result); |
Aleksey Babahin | 43d186f | 2012-03-08 13:18:43 -0800 | [diff] [blame] | 368 | } |
| 369 | |
Greg Kroah-Hartman | 9fbd164 | 2012-03-08 13:55:41 -0800 | [diff] [blame] | 370 | static struct usb_driver metrousb_driver = { |
| 371 | .name = "metro-usb", |
| 372 | .probe = usb_serial_probe, |
| 373 | .disconnect = usb_serial_disconnect, |
| 374 | .id_table = id_table |
| 375 | }; |
| 376 | |
Greg Kroah-Hartman | 9fbd164 | 2012-03-08 13:55:41 -0800 | [diff] [blame] | 377 | static struct usb_serial_driver metrousb_device = { |
| 378 | .driver = { |
| 379 | .owner = THIS_MODULE, |
| 380 | .name = "metro-usb", |
| 381 | }, |
| 382 | .description = "Metrologic USB to serial converter.", |
| 383 | .id_table = id_table, |
| 384 | .num_ports = 1, |
| 385 | .open = metrousb_open, |
| 386 | .close = metrousb_cleanup, |
| 387 | .read_int_callback = metrousb_read_int_callback, |
Aleksey Babahin | 28a4b6a | 2012-03-20 00:46:32 +0400 | [diff] [blame^] | 388 | .write_int_callback = metrousb_write_int_callback, |
Greg Kroah-Hartman | 9fbd164 | 2012-03-08 13:55:41 -0800 | [diff] [blame] | 389 | .attach = metrousb_startup, |
| 390 | .release = metrousb_shutdown, |
| 391 | .throttle = metrousb_throttle, |
| 392 | .unthrottle = metrousb_unthrottle, |
| 393 | .tiocmget = metrousb_tiocmget, |
| 394 | .tiocmset = metrousb_tiocmset, |
| 395 | }; |
| 396 | |
| 397 | static struct usb_serial_driver * const serial_drivers[] = { |
| 398 | &metrousb_device, |
| 399 | NULL, |
| 400 | }; |
| 401 | |
Greg Kroah-Hartman | 1935e35 | 2012-03-08 13:39:53 -0800 | [diff] [blame] | 402 | module_usb_serial_driver(metrousb_driver, serial_drivers); |
| 403 | |
Aleksey Babahin | 43d186f | 2012-03-08 13:18:43 -0800 | [diff] [blame] | 404 | MODULE_LICENSE("GPL"); |
Greg Kroah-Hartman | d4cbd6e | 2012-03-08 13:50:54 -0800 | [diff] [blame] | 405 | MODULE_AUTHOR("Philip Nicastro"); |
| 406 | MODULE_AUTHOR("Aleksey Babahin <tamerlan311@gmail.com>"); |
| 407 | MODULE_DESCRIPTION(DRIVER_DESC); |
Aleksey Babahin | 43d186f | 2012-03-08 13:18:43 -0800 | [diff] [blame] | 408 | |
| 409 | /* Module input parameters */ |
| 410 | module_param(debug, bool, S_IRUGO | S_IWUSR); |
| 411 | MODULE_PARM_DESC(debug, "Print debug info (bool 1=on, 0=off)"); |