[PATCH] USB: CP2101 Add support for flow control

Added support to get/set flow control line levels using TIOCMGET and
TIOCMSET.
Added support for RTSCTS hardware flow control.
cp2101_get_config and cp2101_set_config modified to support long request
strings, required for configuring flow control.

Signed-off-by: Craig Shelley craig@microtron.org.uk
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>

authored by Craig Shelley and committed by Greg KH 39a66b8d 719df469

+283 -96
+283 -96
drivers/usb/serial/cp2101.c
··· 7 7 * modify it under the terms of the GNU General Public License version 8 8 * 2 as published by the Free Software Foundation. 9 9 * 10 + * Support to set flow control line levels using TIOCMGET and TIOCMSET 11 + * thanks to Karl Hiramoto karl@hiramoto.org. RTSCTS hardware flow 12 + * control thanks to Munir Nassar nassarmu@real-time.com 13 + * 14 + * Outstanding Issues: 15 + * Buffers are not flushed when the port is opened. 16 + * Multiple calls to write() may fail with "Resource temporarily unavailable" 17 + * 10 18 */ 11 19 12 20 #include <linux/config.h> ··· 32 24 /* 33 25 * Version Information 34 26 */ 35 - #define DRIVER_VERSION "v0.03" 27 + #define DRIVER_VERSION "v0.04" 36 28 #define DRIVER_DESC "Silicon Labs CP2101/CP2102 RS232 serial adaptor driver" 37 29 38 30 /* ··· 43 35 static void cp2101_close(struct usb_serial_port*, struct file*); 44 36 static void cp2101_get_termios(struct usb_serial_port*); 45 37 static void cp2101_set_termios(struct usb_serial_port*, struct termios*); 38 + static int cp2101_tiocmget (struct usb_serial_port *, struct file *); 39 + static int cp2101_tiocmset (struct usb_serial_port *, struct file *, 40 + unsigned int, unsigned int); 46 41 static void cp2101_break_ctl(struct usb_serial_port*, int); 47 42 static int cp2101_startup (struct usb_serial *); 48 43 static void cp2101_shutdown(struct usb_serial*); ··· 54 43 static int debug; 55 44 56 45 static struct usb_device_id id_table [] = { 57 - {USB_DEVICE(0x10c4, 0xea60) }, /*Silicon labs factory default*/ 58 - {USB_DEVICE(0x10ab, 0x10c5) }, /*Siemens MC60 Cable*/ 59 - { } /* Terminating Entry*/ 46 + { USB_DEVICE(0x10C4, 0xEA60) }, /* Silicon Labs factory default */ 47 + { USB_DEVICE(0x10C4, 0x80CA) }, /* Degree Controls Inc */ 48 + { USB_DEVICE(0x10AB, 0x10C5) }, /* Siemens MC60 Cable */ 49 + { } /* Terminating Entry */ 60 50 }; 61 51 62 52 MODULE_DEVICE_TABLE (usb, id_table); ··· 82 70 .close = cp2101_close, 83 71 .break_ctl = cp2101_break_ctl, 84 72 .set_termios = cp2101_set_termios, 73 + .tiocmget = cp2101_tiocmget, 74 + .tiocmset = cp2101_tiocmset, 85 75 .attach = cp2101_startup, 86 76 .shutdown = cp2101_shutdown, 87 77 }; 88 78 89 - /*Config request types*/ 79 + /* Config request types */ 90 80 #define REQTYPE_HOST_TO_DEVICE 0x41 91 81 #define REQTYPE_DEVICE_TO_HOST 0xc1 92 82 93 - /*Config SET requests. To GET, add 1 to the request number*/ 94 - #define CP2101_UART 0x00 /*Enable / Disable*/ 95 - #define CP2101_BAUDRATE 0x01 /*(BAUD_RATE_GEN_FREQ / baudrate)*/ 96 - #define CP2101_BITS 0x03 /*0x(0)(data bits)(parity)(stop bits)*/ 97 - #define CP2101_BREAK 0x05 /*On / Off*/ 98 - #define CP2101_DTRRTS 0x07 /*101 / 202 ???*/ 99 - #define CP2101_CONFIG_16 0x13 /*16 bytes of config data ???*/ 100 - #define CP2101_CONFIG_6 0x19 /*6 bytes of config data ???*/ 83 + /* Config SET requests. To GET, add 1 to the request number */ 84 + #define CP2101_UART 0x00 /* Enable / Disable */ 85 + #define CP2101_BAUDRATE 0x01 /* (BAUD_RATE_GEN_FREQ / baudrate) */ 86 + #define CP2101_BITS 0x03 /* 0x(0)(databits)(parity)(stopbits) */ 87 + #define CP2101_BREAK 0x05 /* On / Off */ 88 + #define CP2101_CONTROL 0x07 /* Flow control line states */ 89 + #define CP2101_MODEMCTL 0x13 /* Modem controls */ 90 + #define CP2101_CONFIG_6 0x19 /* 6 bytes of config data ??? */ 101 91 102 - /*CP2101_UART*/ 92 + /* CP2101_UART */ 103 93 #define UART_ENABLE 0x0001 104 94 #define UART_DISABLE 0x0000 105 95 106 - /*CP2101_BAUDRATE*/ 96 + /* CP2101_BAUDRATE */ 107 97 #define BAUD_RATE_GEN_FREQ 0x384000 108 98 109 - /*CP2101_BITS*/ 99 + /* CP2101_BITS */ 110 100 #define BITS_DATA_MASK 0X0f00 101 + #define BITS_DATA_5 0X0500 111 102 #define BITS_DATA_6 0X0600 112 103 #define BITS_DATA_7 0X0700 113 104 #define BITS_DATA_8 0X0800 ··· 127 112 #define BITS_STOP_1 0x0000 128 113 #define BITS_STOP_1_5 0x0001 129 114 #define BITS_STOP_2 0x0002 115 + 116 + /* CP2101_BREAK */ 130 117 #define BREAK_ON 0x0000 131 118 #define BREAK_OFF 0x0001 132 119 120 + /* CP2101_CONTROL */ 121 + #define CONTROL_DTR 0x0001 122 + #define CONTROL_RTS 0x0002 123 + #define CONTROL_CTS 0x0010 124 + #define CONTROL_DSR 0x0020 125 + #define CONTROL_RING 0x0040 126 + #define CONTROL_DCD 0x0080 127 + #define CONTROL_WRITE_DTR 0x0100 128 + #define CONTROL_WRITE_RTS 0x0200 133 129 134 - static int cp2101_get_config(struct usb_serial_port* port, u8 request) 130 + /* 131 + * cp2101_get_config 132 + * Reads from the CP2101 configuration registers 133 + * 'size' is specified in bytes. 134 + * 'data' is a pointer to a pre-allocated array of integers large 135 + * enough to hold 'size' bytes (with 4 bytes to each integer) 136 + */ 137 + static int cp2101_get_config(struct usb_serial_port* port, u8 request, 138 + unsigned int *data, int size) 135 139 { 136 140 struct usb_serial *serial = port->serial; 137 - unsigned char buf[4]; 138 - unsigned int value; 139 - int result, i; 141 + u32 *buf; 142 + int result, i, length; 140 143 141 - /*For get requests, the request number must be incremented*/ 144 + /* Number of integers required to contain the array */ 145 + length = (((size - 1) | 3) + 1)/4; 146 + 147 + buf = kmalloc (length * sizeof(u32), GFP_KERNEL); 148 + memset(buf, 0, length * sizeof(u32)); 149 + 150 + if (!buf) { 151 + dev_err(&port->dev, "%s - out of memory.\n", __FUNCTION__); 152 + return -ENOMEM; 153 + } 154 + 155 + /* For get requests, the request number must be incremented */ 142 156 request++; 143 157 144 - /*Issue the request, attempting to read 4 bytes*/ 158 + /* Issue the request, attempting to read 'size' bytes */ 145 159 result = usb_control_msg (serial->dev,usb_rcvctrlpipe (serial->dev, 0), 146 160 request, REQTYPE_DEVICE_TO_HOST, 0x0000, 147 - 0, buf, 4, 300); 161 + 0, buf, size, 300); 148 162 149 - if (result < 0) { 163 + /* Convert data into an array of integers */ 164 + for (i=0; i<length; i++) 165 + data[i] = le32_to_cpu(buf[i]); 166 + 167 + kfree(buf); 168 + 169 + if (result != size) { 150 170 dev_err(&port->dev, "%s - Unable to send config request, " 151 - "request=0x%x result=%d\n", 152 - __FUNCTION__, request, result); 153 - return result; 171 + "request=0x%x size=%d result=%d\n", 172 + __FUNCTION__, request, size, result); 173 + return -EPROTO; 154 174 } 155 - 156 - /*Assemble each byte read into an integer value*/ 157 - value = 0; 158 - for (i=0; i<4 && i<result; i++) 159 - value |= (buf[i] << (i * 8)); 160 - 161 - dbg( " %s - request=0x%x result=%d value=0x%x", 162 - __FUNCTION__, request, result, value); 163 - 164 - return value; 165 - } 166 - 167 - static int cp2101_set_config(struct usb_serial_port* port, u8 request, u16 value) 168 - { 169 - struct usb_serial *serial = port->serial; 170 - int result; 171 - result = usb_control_msg (serial->dev, usb_sndctrlpipe(serial->dev, 0), 172 - request, REQTYPE_HOST_TO_DEVICE, value, 173 - 0, NULL, 0, 300); 174 - 175 - if (result <0) { 176 - dev_err(&port->dev, "%s - Unable to send config request, " 177 - "request=0x%x value=0x%x result=%d\n", 178 - __FUNCTION__, request, value, result); 179 - return result; 180 - } 181 - 182 - dbg(" %s - request=0x%x value=0x%x result=%d", 183 - __FUNCTION__, request, value, result); 184 175 185 176 return 0; 177 + } 178 + 179 + /* 180 + * cp2101_set_config 181 + * Writes to the CP2101 configuration registers 182 + * Values less than 16 bits wide are sent directly 183 + * 'size' is specified in bytes. 184 + */ 185 + static int cp2101_set_config(struct usb_serial_port* port, u8 request, 186 + unsigned int *data, int size) 187 + { 188 + struct usb_serial *serial = port->serial; 189 + u32 *buf; 190 + int result, i, length; 191 + 192 + /* Number of integers required to contain the array */ 193 + length = (((size - 1) | 3) + 1)/4; 194 + 195 + buf = kmalloc(length * sizeof(u32), GFP_KERNEL); 196 + if (!buf) { 197 + dev_err(&port->dev, "%s - out of memory.\n", 198 + __FUNCTION__); 199 + return -ENOMEM; 200 + } 201 + 202 + /* Array of integers into bytes */ 203 + for (i = 0; i < length; i++) 204 + buf[i] = cpu_to_le32(data[i]); 205 + 206 + if (size > 2) { 207 + result = usb_control_msg (serial->dev, 208 + usb_sndctrlpipe(serial->dev, 0), 209 + request, REQTYPE_HOST_TO_DEVICE, 0x0000, 210 + 0, buf, size, 300); 211 + } else { 212 + result = usb_control_msg (serial->dev, 213 + usb_sndctrlpipe(serial->dev, 0), 214 + request, REQTYPE_HOST_TO_DEVICE, data[0], 215 + 0, NULL, 0, 300); 216 + } 217 + 218 + kfree(buf); 219 + 220 + if ((size > 2 && result != size) || result < 0) { 221 + dev_err(&port->dev, "%s - Unable to send request, " 222 + "request=0x%x size=%d result=%d\n", 223 + __FUNCTION__, request, size, result); 224 + return -EPROTO; 225 + } 226 + 227 + /* Single data value */ 228 + result = usb_control_msg (serial->dev, 229 + usb_sndctrlpipe(serial->dev, 0), 230 + request, REQTYPE_HOST_TO_DEVICE, data[0], 231 + 0, NULL, 0, 300); 232 + return 0; 233 + } 234 + 235 + /* 236 + * cp2101_set_config_single 237 + * Convenience function for calling cp2101_set_config on single data values 238 + * without requiring an integer pointer 239 + */ 240 + static inline int cp2101_set_config_single(struct usb_serial_port* port, 241 + u8 request, unsigned int data) 242 + { 243 + return cp2101_set_config(port, request, &data, 2); 186 244 } 187 245 188 246 static int cp2101_open (struct usb_serial_port *port, struct file *filp) ··· 265 177 266 178 dbg("%s - port %d", __FUNCTION__, port->number); 267 179 268 - if (cp2101_set_config(port, CP2101_UART, UART_ENABLE)) { 180 + if (cp2101_set_config_single(port, CP2101_UART, UART_ENABLE)) { 269 181 dev_err(&port->dev, "%s - Unable to enable UART\n", 270 182 __FUNCTION__); 271 183 return -EPROTO; ··· 286 198 return result; 287 199 } 288 200 289 - /*Configure the termios structure*/ 201 + /* Configure the termios structure */ 290 202 cp2101_get_termios(port); 203 + 204 + /* Set the DTR and RTS pins low */ 205 + cp2101_tiocmset(port, NULL, TIOCM_DTR | TIOCM_RTS, 0); 291 206 292 207 return 0; 293 208 } ··· 319 228 usb_kill_urb(port->write_urb); 320 229 usb_kill_urb(port->read_urb); 321 230 322 - cp2101_set_config(port, CP2101_UART, UART_DISABLE); 231 + cp2101_set_config_single(port, CP2101_UART, UART_DISABLE); 323 232 } 324 233 325 - /* cp2101_get_termios*/ 326 - /* Reads the baud rate, data bits, parity and stop bits from the device*/ 327 - /* Corrects any unsupported values*/ 328 - /* Configures the termios structure to reflect the state of the device*/ 234 + /* 235 + * cp2101_get_termios 236 + * Reads the baud rate, data bits, parity, stop bits and flow control mode 237 + * from the device, corrects any unsupported values, and configures the 238 + * termios structure to reflect the state of the device 239 + */ 329 240 static void cp2101_get_termios (struct usb_serial_port *port) 330 241 { 331 - unsigned int cflag; 242 + unsigned int cflag, modem_ctl[4]; 332 243 int baud; 333 244 int bits; 334 245 ··· 342 249 } 343 250 cflag = port->tty->termios->c_cflag; 344 251 345 - baud = cp2101_get_config(port, CP2101_BAUDRATE); 346 - /*Convert to baudrate*/ 252 + cp2101_get_config(port, CP2101_BAUDRATE, &baud, 2); 253 + /* Convert to baudrate */ 347 254 if (baud) 348 255 baud = BAUD_RATE_GEN_FREQ / baud; 349 256 350 257 dbg("%s - baud rate = %d", __FUNCTION__, baud); 351 258 cflag &= ~CBAUD; 352 259 switch (baud) { 353 - /* The baud rates which are commented out below 260 + /* 261 + * The baud rates which are commented out below 354 262 * appear to be supported by the device 355 263 * but are non-standard 356 264 */ ··· 378 284 dbg("%s - Baud rate is not supported, " 379 285 "using 9600 baud", __FUNCTION__); 380 286 cflag |= B9600; 381 - cp2101_set_config(port, CP2101_BAUDRATE, 287 + cp2101_set_config_single(port, CP2101_BAUDRATE, 382 288 (BAUD_RATE_GEN_FREQ/9600)); 383 289 break; 384 290 } 385 291 386 - bits = cp2101_get_config(port, CP2101_BITS); 292 + cp2101_get_config(port, CP2101_BITS, &bits, 2); 387 293 cflag &= ~CSIZE; 388 294 switch(bits & BITS_DATA_MASK) { 295 + case BITS_DATA_5: 296 + dbg("%s - data bits = 5", __FUNCTION__); 297 + cflag |= CS5; 298 + break; 389 299 case BITS_DATA_6: 390 300 dbg("%s - data bits = 6", __FUNCTION__); 391 301 cflag |= CS6; ··· 408 310 cflag |= CS8; 409 311 bits &= ~BITS_DATA_MASK; 410 312 bits |= BITS_DATA_8; 411 - cp2101_set_config(port, CP2101_BITS, bits); 313 + cp2101_set_config(port, CP2101_BITS, &bits, 2); 412 314 break; 413 315 default: 414 316 dbg("%s - Unknown number of data bits, " ··· 416 318 cflag |= CS8; 417 319 bits &= ~BITS_DATA_MASK; 418 320 bits |= BITS_DATA_8; 419 - cp2101_set_config(port, CP2101_BITS, bits); 321 + cp2101_set_config(port, CP2101_BITS, &bits, 2); 420 322 break; 421 323 } 422 324 ··· 439 341 "disabling parity)", __FUNCTION__); 440 342 cflag &= ~PARENB; 441 343 bits &= ~BITS_PARITY_MASK; 442 - cp2101_set_config(port, CP2101_BITS, bits); 344 + cp2101_set_config(port, CP2101_BITS, &bits, 2); 443 345 break; 444 346 case BITS_PARITY_SPACE: 445 347 dbg("%s - parity = SPACE (not supported, " 446 348 "disabling parity)", __FUNCTION__); 447 349 cflag &= ~PARENB; 448 350 bits &= ~BITS_PARITY_MASK; 449 - cp2101_set_config(port, CP2101_BITS, bits); 351 + cp2101_set_config(port, CP2101_BITS, &bits, 2); 450 352 break; 451 353 default: 452 354 dbg("%s - Unknown parity mode, " 453 355 "disabling parity", __FUNCTION__); 454 356 cflag &= ~PARENB; 455 357 bits &= ~BITS_PARITY_MASK; 456 - cp2101_set_config(port, CP2101_BITS, bits); 358 + cp2101_set_config(port, CP2101_BITS, &bits, 2); 457 359 break; 458 360 } 459 361 ··· 464 366 break; 465 367 case BITS_STOP_1_5: 466 368 dbg("%s - stop bits = 1.5 (not supported, " 467 - "using 1 stop bit", __FUNCTION__); 369 + "using 1 stop bit)", __FUNCTION__); 468 370 bits &= ~BITS_STOP_MASK; 469 - cp2101_set_config(port, CP2101_BITS, bits); 371 + cp2101_set_config(port, CP2101_BITS, &bits, 2); 470 372 break; 471 373 case BITS_STOP_2: 472 374 dbg("%s - stop bits = 2", __FUNCTION__); ··· 476 378 dbg("%s - Unknown number of stop bits, " 477 379 "using 1 stop bit", __FUNCTION__); 478 380 bits &= ~BITS_STOP_MASK; 479 - cp2101_set_config(port, CP2101_BITS, bits); 381 + cp2101_set_config(port, CP2101_BITS, &bits, 2); 480 382 break; 383 + } 384 + 385 + cp2101_get_config(port, CP2101_MODEMCTL, modem_ctl, 16); 386 + if (modem_ctl[0] & 0x0008) { 387 + dbg("%s - flow control = CRTSCTS", __FUNCTION__); 388 + cflag |= CRTSCTS; 389 + } else { 390 + dbg("%s - flow control = NONE", __FUNCTION__); 391 + cflag &= ~CRTSCTS; 481 392 } 482 393 483 394 port->tty->termios->c_cflag = cflag; ··· 496 389 struct termios *old_termios) 497 390 { 498 391 unsigned int cflag, old_cflag=0; 499 - int baud=0; 500 - int bits; 392 + int baud=0, bits; 393 + unsigned int modem_ctl[4]; 501 394 502 395 dbg("%s - port %d", __FUNCTION__, port->number); 503 396 ··· 507 400 } 508 401 cflag = port->tty->termios->c_cflag; 509 402 510 - /* check that they really want us to change something */ 403 + /* Check that they really want us to change something */ 511 404 if (old_termios) { 512 405 if ((cflag == old_termios->c_cflag) && 513 406 (RELEVANT_IFLAG(port->tty->termios->c_iflag) ··· 522 415 /* If the baud rate is to be updated*/ 523 416 if ((cflag & CBAUD) != (old_cflag & CBAUD)) { 524 417 switch (cflag & CBAUD) { 525 - /* The baud rates which are commented out below 418 + /* 419 + * The baud rates which are commented out below 526 420 * appear to be supported by the device 527 421 * but are non-standard 528 422 */ ··· 556 448 if (baud) { 557 449 dbg("%s - Setting baud rate to %d baud", __FUNCTION__, 558 450 baud); 559 - if (cp2101_set_config(port, CP2101_BAUDRATE, 451 + if (cp2101_set_config_single(port, CP2101_BAUDRATE, 560 452 (BAUD_RATE_GEN_FREQ / baud))) 561 453 dev_err(&port->dev, "Baud rate requested not " 562 454 "supported by device\n"); 563 455 } 564 456 } 565 457 566 - /*If the number of data bits is to be updated*/ 458 + /* If the number of data bits is to be updated */ 567 459 if ((cflag & CSIZE) != (old_cflag & CSIZE)) { 568 - bits = cp2101_get_config(port, CP2101_BITS); 460 + cp2101_get_config(port, CP2101_BITS, &bits, 2); 569 461 bits &= ~BITS_DATA_MASK; 570 462 switch (cflag & CSIZE) { 463 + case CS5: 464 + bits |= BITS_DATA_5; 465 + dbg("%s - data bits = 5", __FUNCTION__); 466 + break; 571 467 case CS6: 572 468 bits |= BITS_DATA_6; 573 469 dbg("%s - data bits = 6", __FUNCTION__); ··· 595 483 bits |= BITS_DATA_8; 596 484 break; 597 485 } 598 - if (cp2101_set_config(port, CP2101_BITS, bits)) 486 + if (cp2101_set_config(port, CP2101_BITS, &bits, 2)) 599 487 dev_err(&port->dev, "Number of data bits requested " 600 488 "not supported by device\n"); 601 489 } 602 490 603 491 if ((cflag & (PARENB|PARODD)) != (old_cflag & (PARENB|PARODD))) { 604 - bits = cp2101_get_config(port, CP2101_BITS); 492 + cp2101_get_config(port, CP2101_BITS, &bits, 2); 605 493 bits &= ~BITS_PARITY_MASK; 606 494 if (cflag & PARENB) { 607 495 if (cflag & PARODD) { ··· 612 500 dbg("%s - parity = EVEN", __FUNCTION__); 613 501 } 614 502 } 615 - if (cp2101_set_config(port, CP2101_BITS, bits)) 503 + if (cp2101_set_config(port, CP2101_BITS, &bits, 2)) 616 504 dev_err(&port->dev, "Parity mode not supported " 617 505 "by device\n"); 618 506 } 619 507 620 508 if ((cflag & CSTOPB) != (old_cflag & CSTOPB)) { 621 - bits = cp2101_get_config(port, CP2101_BITS); 509 + cp2101_get_config(port, CP2101_BITS, &bits, 2); 622 510 bits &= ~BITS_STOP_MASK; 623 511 if (cflag & CSTOPB) { 624 512 bits |= BITS_STOP_2; ··· 627 515 bits |= BITS_STOP_1; 628 516 dbg("%s - stop bits = 1", __FUNCTION__); 629 517 } 630 - if (cp2101_set_config(port, CP2101_BITS, bits)) 518 + if (cp2101_set_config(port, CP2101_BITS, &bits, 2)) 631 519 dev_err(&port->dev, "Number of stop bits requested " 632 520 "not supported by device\n"); 633 521 } 522 + 523 + if ((cflag & CRTSCTS) != (old_cflag & CRTSCTS)) { 524 + cp2101_get_config(port, CP2101_MODEMCTL, modem_ctl, 16); 525 + dbg("%s - read modem controls = 0x%.4x 0x%.4x 0x%.4x 0x%.4x", 526 + __FUNCTION__, modem_ctl[0], modem_ctl[1], 527 + modem_ctl[2], modem_ctl[3]); 528 + 529 + if (cflag & CRTSCTS) { 530 + modem_ctl[0] &= ~0x7B; 531 + modem_ctl[0] |= 0x09; 532 + modem_ctl[1] = 0x80; 533 + dbg("%s - flow control = CRTSCTS", __FUNCTION__); 534 + } else { 535 + modem_ctl[0] &= ~0x7B; 536 + modem_ctl[0] |= 0x01; 537 + modem_ctl[1] |= 0x40; 538 + dbg("%s - flow control = NONE", __FUNCTION__); 539 + } 540 + 541 + dbg("%s - write modem controls = 0x%.4x 0x%.4x 0x%.4x 0x%.4x", 542 + __FUNCTION__, modem_ctl[0], modem_ctl[1], 543 + modem_ctl[2], modem_ctl[3]); 544 + cp2101_set_config(port, CP2101_MODEMCTL, modem_ctl, 16); 545 + } 546 + 547 + } 548 + 549 + static int cp2101_tiocmset (struct usb_serial_port *port, struct file *file, 550 + unsigned int set, unsigned int clear) 551 + { 552 + int control = 0; 553 + 554 + dbg("%s - port %d", __FUNCTION__, port->number); 555 + 556 + if (set & TIOCM_RTS) { 557 + control |= CONTROL_RTS; 558 + control |= CONTROL_WRITE_RTS; 559 + } 560 + if (set & TIOCM_DTR) { 561 + control |= CONTROL_DTR; 562 + control |= CONTROL_WRITE_DTR; 563 + } 564 + if (clear & TIOCM_RTS) { 565 + control &= ~CONTROL_RTS; 566 + control |= CONTROL_WRITE_RTS; 567 + } 568 + if (clear & TIOCM_DTR) { 569 + control &= ~CONTROL_DTR; 570 + control |= CONTROL_WRITE_DTR; 571 + } 572 + 573 + dbg("%s - control = 0x%.4x", __FUNCTION__, control); 574 + 575 + return cp2101_set_config(port, CP2101_CONTROL, &control, 2); 576 + 577 + } 578 + 579 + static int cp2101_tiocmget (struct usb_serial_port *port, struct file *file) 580 + { 581 + int control, result; 582 + 583 + dbg("%s - port %d", __FUNCTION__, port->number); 584 + 585 + cp2101_get_config(port, CP2101_CONTROL, &control, 1); 586 + 587 + result = ((control & CONTROL_DTR) ? TIOCM_DTR : 0) 588 + |((control & CONTROL_RTS) ? TIOCM_RTS : 0) 589 + |((control & CONTROL_CTS) ? TIOCM_CTS : 0) 590 + |((control & CONTROL_DSR) ? TIOCM_DSR : 0) 591 + |((control & CONTROL_RING)? TIOCM_RI : 0) 592 + |((control & CONTROL_DCD) ? TIOCM_CD : 0); 593 + 594 + dbg("%s - control = 0x%.2x", __FUNCTION__, control); 595 + 596 + return result; 634 597 } 635 598 636 599 static void cp2101_break_ctl (struct usb_serial_port *port, int break_state) 637 600 { 638 - u16 state; 601 + int state; 639 602 640 603 dbg("%s - port %d", __FUNCTION__, port->number); 641 604 if (break_state == 0) ··· 719 532 state = BREAK_ON; 720 533 dbg("%s - turning break %s", __FUNCTION__, 721 534 state==BREAK_OFF ? "off" : "on"); 722 - cp2101_set_config(port, CP2101_BREAK, state); 535 + cp2101_set_config(port, CP2101_BREAK, &state, 2); 723 536 } 724 537 725 538 static int cp2101_startup (struct usb_serial *serial) 726 539 { 727 - /*CP2101 buffers behave strangely unless device is reset*/ 540 + /* CP2101 buffers behave strangely unless device is reset */ 728 541 usb_reset_device(serial->dev); 729 542 return 0; 730 543 } ··· 735 548 736 549 dbg("%s", __FUNCTION__); 737 550 738 - /* stop reads and writes on all ports */ 551 + /* Stop reads and writes on all ports */ 739 552 for (i=0; i < serial->num_ports; ++i) { 740 553 cp2101_cleanup(serial->port[i]); 741 554 } ··· 747 560 748 561 retval = usb_serial_register(&cp2101_device); 749 562 if (retval) 750 - return retval; /*Failed to register*/ 563 + return retval; /* Failed to register */ 751 564 752 565 retval = usb_register(&cp2101_driver); 753 566 if (retval) { 754 - /*Failed to register*/ 567 + /* Failed to register */ 755 568 usb_serial_deregister(&cp2101_device); 756 569 return retval; 757 570 } 758 571 759 - /*Success*/ 572 + /* Success */ 760 573 info(DRIVER_DESC " " DRIVER_VERSION); 761 574 return 0; 762 575 }