Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Silicon Laboratories CP2101/CP2102 USB to RS232 serial adaptor driver |
| 3 | * |
| 4 | * Copyright (C) 2005 Craig Shelley (craig@microtron.org.uk) |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or |
| 7 | * modify it under the terms of the GNU General Public License version |
| 8 | * 2 as published by the Free Software Foundation. |
| 9 | * |
Craig Shelley | 39a66b8 | 2005-05-27 00:09:56 +0100 | [diff] [blame] | 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 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | */ |
| 19 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 | #include <linux/kernel.h> |
| 21 | #include <linux/errno.h> |
| 22 | #include <linux/slab.h> |
| 23 | #include <linux/tty.h> |
| 24 | #include <linux/tty_flip.h> |
| 25 | #include <linux/module.h> |
| 26 | #include <linux/moduleparam.h> |
| 27 | #include <linux/usb.h> |
| 28 | #include <asm/uaccess.h> |
Greg Kroah-Hartman | a969888 | 2006-07-11 21:22:58 -0700 | [diff] [blame] | 29 | #include <linux/usb/serial.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | |
| 31 | /* |
| 32 | * Version Information |
| 33 | */ |
Craig Shelley | 59224f5 | 2006-03-11 11:29:02 +0000 | [diff] [blame] | 34 | #define DRIVER_VERSION "v0.07" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | #define DRIVER_DESC "Silicon Labs CP2101/CP2102 RS232 serial adaptor driver" |
| 36 | |
| 37 | /* |
| 38 | * Function Prototypes |
| 39 | */ |
| 40 | static int cp2101_open(struct usb_serial_port*, struct file*); |
| 41 | static void cp2101_cleanup(struct usb_serial_port*); |
| 42 | static void cp2101_close(struct usb_serial_port*, struct file*); |
| 43 | static void cp2101_get_termios(struct usb_serial_port*); |
Alan Cox | 606d099 | 2006-12-08 02:38:45 -0800 | [diff] [blame^] | 44 | static void cp2101_set_termios(struct usb_serial_port*, struct ktermios*); |
Craig Shelley | 39a66b8 | 2005-05-27 00:09:56 +0100 | [diff] [blame] | 45 | static int cp2101_tiocmget (struct usb_serial_port *, struct file *); |
| 46 | static int cp2101_tiocmset (struct usb_serial_port *, struct file *, |
| 47 | unsigned int, unsigned int); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | static void cp2101_break_ctl(struct usb_serial_port*, int); |
| 49 | static int cp2101_startup (struct usb_serial *); |
| 50 | static void cp2101_shutdown(struct usb_serial*); |
| 51 | |
| 52 | |
| 53 | static int debug; |
| 54 | |
| 55 | static struct usb_device_id id_table [] = { |
Craig Shelley | 198b951 | 2005-08-28 09:51:15 +0100 | [diff] [blame] | 56 | { USB_DEVICE(0x0FCF, 0x1003) }, /* Dynastream ANT development board */ |
Craig Shelley | 198b951 | 2005-08-28 09:51:15 +0100 | [diff] [blame] | 57 | { USB_DEVICE(0x10A6, 0xAA26) }, /* Knock-off DCU-11 cable */ |
Craig Shelley | e988fc8 | 2006-01-20 00:06:19 +0000 | [diff] [blame] | 58 | { USB_DEVICE(0x10AB, 0x10C5) }, /* Siemens MC60 Cable */ |
| 59 | { USB_DEVICE(0x10B5, 0xAC70) }, /* Nokia CA-42 USB */ |
Craig Shelley | 59224f5 | 2006-03-11 11:29:02 +0000 | [diff] [blame] | 60 | { USB_DEVICE(0x10C4, 0x803B) }, /* Pololu USB-serial converter */ |
Vitja Makarov | 212a4b4 | 2006-05-31 00:40:06 +0400 | [diff] [blame] | 61 | { USB_DEVICE(0x10C4, 0x8066) }, /* Argussoft In-System Programmer */ |
Craig Shelley | e988fc8 | 2006-01-20 00:06:19 +0000 | [diff] [blame] | 62 | { USB_DEVICE(0x10C4, 0x807A) }, /* Crumb128 board */ |
| 63 | { USB_DEVICE(0x10C4, 0x80CA) }, /* Degree Controls Inc */ |
| 64 | { USB_DEVICE(0x10C4, 0x80F6) }, /* Suunto sports instrument */ |
| 65 | { USB_DEVICE(0x10C4, 0x813D) }, /* Burnside Telecom Deskmobile */ |
| 66 | { USB_DEVICE(0x10C4, 0x815E) }, /* Helicomm IP-Link 1220-DVM */ |
Bjorn Schneider | 78001e3 | 2006-10-28 12:42:04 +0200 | [diff] [blame] | 67 | { USB_DEVICE(0x10C4, 0x81C8) }, /* Lipowsky Industrie Elektronik GmbH, Baby-JTAG */ |
| 68 | { USB_DEVICE(0x10C4, 0x81E2) }, /* Lipowsky Industrie Elektronik GmbH, Baby-LIN */ |
| 69 | { USB_DEVICE(0x10C4, 0x8218) }, /* Lipowsky Industrie Elektronik GmbH, HARP-1 */ |
Craig Shelley | e988fc8 | 2006-01-20 00:06:19 +0000 | [diff] [blame] | 70 | { USB_DEVICE(0x10C4, 0xEA60) }, /* Silicon Labs factory default */ |
Craig Shelley | 61926b9 | 2006-10-12 22:09:56 +0100 | [diff] [blame] | 71 | { USB_DEVICE(0x10C4, 0xEA61) }, /* Silicon Labs factory default */ |
Josef Balatka | b0ce84d | 2005-11-17 09:47:24 -0800 | [diff] [blame] | 72 | { USB_DEVICE(0x16D6, 0x0001) }, /* Jablotron serial interface */ |
Craig Shelley | 39a66b8 | 2005-05-27 00:09:56 +0100 | [diff] [blame] | 73 | { } /* Terminating Entry */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | }; |
| 75 | |
| 76 | MODULE_DEVICE_TABLE (usb, id_table); |
| 77 | |
| 78 | static struct usb_driver cp2101_driver = { |
Greg Kroah-Hartman | 269bda1 | 2005-06-20 21:15:16 -0700 | [diff] [blame] | 79 | .name = "cp2101", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | .probe = usb_serial_probe, |
| 81 | .disconnect = usb_serial_disconnect, |
| 82 | .id_table = id_table, |
Greg Kroah-Hartman | ba9dc65 | 2005-11-16 13:41:28 -0800 | [diff] [blame] | 83 | .no_dynamic_id = 1, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 84 | }; |
| 85 | |
Greg Kroah-Hartman | ea65370 | 2005-06-20 21:15:16 -0700 | [diff] [blame] | 86 | static struct usb_serial_driver cp2101_device = { |
Greg Kroah-Hartman | 18fcac3 | 2005-06-20 21:15:16 -0700 | [diff] [blame] | 87 | .driver = { |
| 88 | .owner = THIS_MODULE, |
Greg Kroah-Hartman | 269bda1 | 2005-06-20 21:15:16 -0700 | [diff] [blame] | 89 | .name = "cp2101", |
Greg Kroah-Hartman | 18fcac3 | 2005-06-20 21:15:16 -0700 | [diff] [blame] | 90 | }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | .id_table = id_table, |
| 92 | .num_interrupt_in = 0, |
| 93 | .num_bulk_in = 0, |
| 94 | .num_bulk_out = 0, |
| 95 | .num_ports = 1, |
| 96 | .open = cp2101_open, |
| 97 | .close = cp2101_close, |
| 98 | .break_ctl = cp2101_break_ctl, |
| 99 | .set_termios = cp2101_set_termios, |
Craig Shelley | 39a66b8 | 2005-05-27 00:09:56 +0100 | [diff] [blame] | 100 | .tiocmget = cp2101_tiocmget, |
| 101 | .tiocmset = cp2101_tiocmset, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 102 | .attach = cp2101_startup, |
| 103 | .shutdown = cp2101_shutdown, |
| 104 | }; |
| 105 | |
Craig Shelley | 39a66b8 | 2005-05-27 00:09:56 +0100 | [diff] [blame] | 106 | /* Config request types */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | #define REQTYPE_HOST_TO_DEVICE 0x41 |
| 108 | #define REQTYPE_DEVICE_TO_HOST 0xc1 |
| 109 | |
Craig Shelley | 39a66b8 | 2005-05-27 00:09:56 +0100 | [diff] [blame] | 110 | /* Config SET requests. To GET, add 1 to the request number */ |
| 111 | #define CP2101_UART 0x00 /* Enable / Disable */ |
| 112 | #define CP2101_BAUDRATE 0x01 /* (BAUD_RATE_GEN_FREQ / baudrate) */ |
| 113 | #define CP2101_BITS 0x03 /* 0x(0)(databits)(parity)(stopbits) */ |
| 114 | #define CP2101_BREAK 0x05 /* On / Off */ |
| 115 | #define CP2101_CONTROL 0x07 /* Flow control line states */ |
| 116 | #define CP2101_MODEMCTL 0x13 /* Modem controls */ |
| 117 | #define CP2101_CONFIG_6 0x19 /* 6 bytes of config data ??? */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 118 | |
Craig Shelley | 39a66b8 | 2005-05-27 00:09:56 +0100 | [diff] [blame] | 119 | /* CP2101_UART */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 120 | #define UART_ENABLE 0x0001 |
| 121 | #define UART_DISABLE 0x0000 |
| 122 | |
Craig Shelley | 39a66b8 | 2005-05-27 00:09:56 +0100 | [diff] [blame] | 123 | /* CP2101_BAUDRATE */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 124 | #define BAUD_RATE_GEN_FREQ 0x384000 |
| 125 | |
Craig Shelley | 39a66b8 | 2005-05-27 00:09:56 +0100 | [diff] [blame] | 126 | /* CP2101_BITS */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 127 | #define BITS_DATA_MASK 0X0f00 |
Craig Shelley | 39a66b8 | 2005-05-27 00:09:56 +0100 | [diff] [blame] | 128 | #define BITS_DATA_5 0X0500 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 129 | #define BITS_DATA_6 0X0600 |
| 130 | #define BITS_DATA_7 0X0700 |
| 131 | #define BITS_DATA_8 0X0800 |
| 132 | #define BITS_DATA_9 0X0900 |
| 133 | |
| 134 | #define BITS_PARITY_MASK 0x00f0 |
| 135 | #define BITS_PARITY_NONE 0x0000 |
| 136 | #define BITS_PARITY_ODD 0x0010 |
| 137 | #define BITS_PARITY_EVEN 0x0020 |
| 138 | #define BITS_PARITY_MARK 0x0030 |
| 139 | #define BITS_PARITY_SPACE 0x0040 |
| 140 | |
| 141 | #define BITS_STOP_MASK 0x000f |
| 142 | #define BITS_STOP_1 0x0000 |
| 143 | #define BITS_STOP_1_5 0x0001 |
| 144 | #define BITS_STOP_2 0x0002 |
Craig Shelley | 39a66b8 | 2005-05-27 00:09:56 +0100 | [diff] [blame] | 145 | |
| 146 | /* CP2101_BREAK */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 147 | #define BREAK_ON 0x0000 |
| 148 | #define BREAK_OFF 0x0001 |
| 149 | |
Craig Shelley | 39a66b8 | 2005-05-27 00:09:56 +0100 | [diff] [blame] | 150 | /* CP2101_CONTROL */ |
| 151 | #define CONTROL_DTR 0x0001 |
| 152 | #define CONTROL_RTS 0x0002 |
| 153 | #define CONTROL_CTS 0x0010 |
| 154 | #define CONTROL_DSR 0x0020 |
| 155 | #define CONTROL_RING 0x0040 |
| 156 | #define CONTROL_DCD 0x0080 |
| 157 | #define CONTROL_WRITE_DTR 0x0100 |
| 158 | #define CONTROL_WRITE_RTS 0x0200 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 159 | |
Craig Shelley | 39a66b8 | 2005-05-27 00:09:56 +0100 | [diff] [blame] | 160 | /* |
| 161 | * cp2101_get_config |
| 162 | * Reads from the CP2101 configuration registers |
| 163 | * 'size' is specified in bytes. |
| 164 | * 'data' is a pointer to a pre-allocated array of integers large |
| 165 | * enough to hold 'size' bytes (with 4 bytes to each integer) |
| 166 | */ |
| 167 | static int cp2101_get_config(struct usb_serial_port* port, u8 request, |
| 168 | unsigned int *data, int size) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 169 | { |
| 170 | struct usb_serial *serial = port->serial; |
Craig Shelley | 39a66b8 | 2005-05-27 00:09:56 +0100 | [diff] [blame] | 171 | u32 *buf; |
| 172 | int result, i, length; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 173 | |
Craig Shelley | 39a66b8 | 2005-05-27 00:09:56 +0100 | [diff] [blame] | 174 | /* Number of integers required to contain the array */ |
| 175 | length = (((size - 1) | 3) + 1)/4; |
| 176 | |
Eric Sesterhenn | 80b6ca4 | 2006-02-27 21:29:43 +0100 | [diff] [blame] | 177 | buf = kcalloc(length, sizeof(u32), GFP_KERNEL); |
Craig Shelley | 39a66b8 | 2005-05-27 00:09:56 +0100 | [diff] [blame] | 178 | if (!buf) { |
| 179 | dev_err(&port->dev, "%s - out of memory.\n", __FUNCTION__); |
| 180 | return -ENOMEM; |
| 181 | } |
| 182 | |
| 183 | /* For get requests, the request number must be incremented */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 184 | request++; |
| 185 | |
Craig Shelley | 39a66b8 | 2005-05-27 00:09:56 +0100 | [diff] [blame] | 186 | /* Issue the request, attempting to read 'size' bytes */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 187 | result = usb_control_msg (serial->dev,usb_rcvctrlpipe (serial->dev, 0), |
| 188 | request, REQTYPE_DEVICE_TO_HOST, 0x0000, |
Craig Shelley | 39a66b8 | 2005-05-27 00:09:56 +0100 | [diff] [blame] | 189 | 0, buf, size, 300); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 190 | |
Craig Shelley | 39a66b8 | 2005-05-27 00:09:56 +0100 | [diff] [blame] | 191 | /* Convert data into an array of integers */ |
| 192 | for (i=0; i<length; i++) |
| 193 | data[i] = le32_to_cpu(buf[i]); |
| 194 | |
| 195 | kfree(buf); |
| 196 | |
| 197 | if (result != size) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 198 | dev_err(&port->dev, "%s - Unable to send config request, " |
Craig Shelley | 39a66b8 | 2005-05-27 00:09:56 +0100 | [diff] [blame] | 199 | "request=0x%x size=%d result=%d\n", |
| 200 | __FUNCTION__, request, size, result); |
| 201 | return -EPROTO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 202 | } |
| 203 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 204 | return 0; |
| 205 | } |
| 206 | |
Craig Shelley | 39a66b8 | 2005-05-27 00:09:56 +0100 | [diff] [blame] | 207 | /* |
| 208 | * cp2101_set_config |
| 209 | * Writes to the CP2101 configuration registers |
| 210 | * Values less than 16 bits wide are sent directly |
| 211 | * 'size' is specified in bytes. |
| 212 | */ |
| 213 | static int cp2101_set_config(struct usb_serial_port* port, u8 request, |
| 214 | unsigned int *data, int size) |
| 215 | { |
| 216 | struct usb_serial *serial = port->serial; |
| 217 | u32 *buf; |
| 218 | int result, i, length; |
| 219 | |
| 220 | /* Number of integers required to contain the array */ |
| 221 | length = (((size - 1) | 3) + 1)/4; |
| 222 | |
| 223 | buf = kmalloc(length * sizeof(u32), GFP_KERNEL); |
| 224 | if (!buf) { |
| 225 | dev_err(&port->dev, "%s - out of memory.\n", |
| 226 | __FUNCTION__); |
| 227 | return -ENOMEM; |
| 228 | } |
| 229 | |
| 230 | /* Array of integers into bytes */ |
| 231 | for (i = 0; i < length; i++) |
| 232 | buf[i] = cpu_to_le32(data[i]); |
| 233 | |
| 234 | if (size > 2) { |
| 235 | result = usb_control_msg (serial->dev, |
| 236 | usb_sndctrlpipe(serial->dev, 0), |
| 237 | request, REQTYPE_HOST_TO_DEVICE, 0x0000, |
| 238 | 0, buf, size, 300); |
| 239 | } else { |
| 240 | result = usb_control_msg (serial->dev, |
| 241 | usb_sndctrlpipe(serial->dev, 0), |
| 242 | request, REQTYPE_HOST_TO_DEVICE, data[0], |
| 243 | 0, NULL, 0, 300); |
| 244 | } |
| 245 | |
| 246 | kfree(buf); |
| 247 | |
| 248 | if ((size > 2 && result != size) || result < 0) { |
| 249 | dev_err(&port->dev, "%s - Unable to send request, " |
| 250 | "request=0x%x size=%d result=%d\n", |
| 251 | __FUNCTION__, request, size, result); |
| 252 | return -EPROTO; |
| 253 | } |
| 254 | |
| 255 | /* Single data value */ |
| 256 | result = usb_control_msg (serial->dev, |
| 257 | usb_sndctrlpipe(serial->dev, 0), |
| 258 | request, REQTYPE_HOST_TO_DEVICE, data[0], |
| 259 | 0, NULL, 0, 300); |
| 260 | return 0; |
| 261 | } |
| 262 | |
| 263 | /* |
| 264 | * cp2101_set_config_single |
| 265 | * Convenience function for calling cp2101_set_config on single data values |
| 266 | * without requiring an integer pointer |
| 267 | */ |
| 268 | static inline int cp2101_set_config_single(struct usb_serial_port* port, |
| 269 | u8 request, unsigned int data) |
| 270 | { |
| 271 | return cp2101_set_config(port, request, &data, 2); |
| 272 | } |
| 273 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 274 | static int cp2101_open (struct usb_serial_port *port, struct file *filp) |
| 275 | { |
| 276 | struct usb_serial *serial = port->serial; |
| 277 | int result; |
| 278 | |
| 279 | dbg("%s - port %d", __FUNCTION__, port->number); |
| 280 | |
Craig Shelley | 39a66b8 | 2005-05-27 00:09:56 +0100 | [diff] [blame] | 281 | if (cp2101_set_config_single(port, CP2101_UART, UART_ENABLE)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 282 | dev_err(&port->dev, "%s - Unable to enable UART\n", |
| 283 | __FUNCTION__); |
| 284 | return -EPROTO; |
| 285 | } |
| 286 | |
| 287 | /* Start reading from the device */ |
| 288 | usb_fill_bulk_urb (port->read_urb, serial->dev, |
| 289 | usb_rcvbulkpipe(serial->dev, |
| 290 | port->bulk_in_endpointAddress), |
| 291 | port->read_urb->transfer_buffer, |
| 292 | port->read_urb->transfer_buffer_length, |
| 293 | serial->type->read_bulk_callback, |
| 294 | port); |
| 295 | result = usb_submit_urb(port->read_urb, GFP_KERNEL); |
| 296 | if (result) { |
| 297 | dev_err(&port->dev, "%s - failed resubmitting read urb, " |
| 298 | "error %d\n", __FUNCTION__, result); |
| 299 | return result; |
| 300 | } |
| 301 | |
Craig Shelley | 39a66b8 | 2005-05-27 00:09:56 +0100 | [diff] [blame] | 302 | /* Configure the termios structure */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 303 | cp2101_get_termios(port); |
| 304 | |
Craig Shelley | 39a66b8 | 2005-05-27 00:09:56 +0100 | [diff] [blame] | 305 | /* Set the DTR and RTS pins low */ |
| 306 | cp2101_tiocmset(port, NULL, TIOCM_DTR | TIOCM_RTS, 0); |
| 307 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 308 | return 0; |
| 309 | } |
| 310 | |
| 311 | static void cp2101_cleanup (struct usb_serial_port *port) |
| 312 | { |
| 313 | struct usb_serial *serial = port->serial; |
| 314 | |
| 315 | dbg("%s - port %d", __FUNCTION__, port->number); |
| 316 | |
| 317 | if (serial->dev) { |
| 318 | /* shutdown any bulk reads that might be going on */ |
| 319 | if (serial->num_bulk_out) |
| 320 | usb_kill_urb(port->write_urb); |
| 321 | if (serial->num_bulk_in) |
| 322 | usb_kill_urb(port->read_urb); |
| 323 | } |
| 324 | } |
| 325 | |
| 326 | static void cp2101_close (struct usb_serial_port *port, struct file * filp) |
| 327 | { |
| 328 | dbg("%s - port %d", __FUNCTION__, port->number); |
| 329 | |
| 330 | /* shutdown our urbs */ |
| 331 | dbg("%s - shutting down urbs", __FUNCTION__); |
| 332 | usb_kill_urb(port->write_urb); |
| 333 | usb_kill_urb(port->read_urb); |
| 334 | |
Craig Shelley | 39a66b8 | 2005-05-27 00:09:56 +0100 | [diff] [blame] | 335 | cp2101_set_config_single(port, CP2101_UART, UART_DISABLE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 336 | } |
| 337 | |
Craig Shelley | 39a66b8 | 2005-05-27 00:09:56 +0100 | [diff] [blame] | 338 | /* |
| 339 | * cp2101_get_termios |
| 340 | * Reads the baud rate, data bits, parity, stop bits and flow control mode |
| 341 | * from the device, corrects any unsupported values, and configures the |
| 342 | * termios structure to reflect the state of the device |
| 343 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 344 | static void cp2101_get_termios (struct usb_serial_port *port) |
| 345 | { |
Craig Shelley | 39a66b8 | 2005-05-27 00:09:56 +0100 | [diff] [blame] | 346 | unsigned int cflag, modem_ctl[4]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 347 | int baud; |
| 348 | int bits; |
| 349 | |
| 350 | dbg("%s - port %d", __FUNCTION__, port->number); |
| 351 | |
| 352 | if ((!port->tty) || (!port->tty->termios)) { |
| 353 | dbg("%s - no tty structures", __FUNCTION__); |
| 354 | return; |
| 355 | } |
| 356 | cflag = port->tty->termios->c_cflag; |
| 357 | |
Craig Shelley | 39a66b8 | 2005-05-27 00:09:56 +0100 | [diff] [blame] | 358 | cp2101_get_config(port, CP2101_BAUDRATE, &baud, 2); |
| 359 | /* Convert to baudrate */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 360 | if (baud) |
| 361 | baud = BAUD_RATE_GEN_FREQ / baud; |
| 362 | |
| 363 | dbg("%s - baud rate = %d", __FUNCTION__, baud); |
| 364 | cflag &= ~CBAUD; |
| 365 | switch (baud) { |
Craig Shelley | 39a66b8 | 2005-05-27 00:09:56 +0100 | [diff] [blame] | 366 | /* |
| 367 | * The baud rates which are commented out below |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 368 | * appear to be supported by the device |
| 369 | * but are non-standard |
| 370 | */ |
| 371 | case 600: cflag |= B600; break; |
| 372 | case 1200: cflag |= B1200; break; |
| 373 | case 1800: cflag |= B1800; break; |
| 374 | case 2400: cflag |= B2400; break; |
| 375 | case 4800: cflag |= B4800; break; |
| 376 | /*case 7200: cflag |= B7200; break;*/ |
| 377 | case 9600: cflag |= B9600; break; |
| 378 | /*case 14400: cflag |= B14400; break;*/ |
| 379 | case 19200: cflag |= B19200; break; |
| 380 | /*case 28800: cflag |= B28800; break;*/ |
| 381 | case 38400: cflag |= B38400; break; |
| 382 | /*case 55854: cflag |= B55054; break;*/ |
| 383 | case 57600: cflag |= B57600; break; |
| 384 | case 115200: cflag |= B115200; break; |
| 385 | /*case 127117: cflag |= B127117; break;*/ |
| 386 | case 230400: cflag |= B230400; break; |
| 387 | case 460800: cflag |= B460800; break; |
| 388 | case 921600: cflag |= B921600; break; |
| 389 | /*case 3686400: cflag |= B3686400; break;*/ |
| 390 | default: |
| 391 | dbg("%s - Baud rate is not supported, " |
| 392 | "using 9600 baud", __FUNCTION__); |
| 393 | cflag |= B9600; |
Craig Shelley | 39a66b8 | 2005-05-27 00:09:56 +0100 | [diff] [blame] | 394 | cp2101_set_config_single(port, CP2101_BAUDRATE, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 395 | (BAUD_RATE_GEN_FREQ/9600)); |
| 396 | break; |
| 397 | } |
| 398 | |
Craig Shelley | 39a66b8 | 2005-05-27 00:09:56 +0100 | [diff] [blame] | 399 | cp2101_get_config(port, CP2101_BITS, &bits, 2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 400 | cflag &= ~CSIZE; |
| 401 | switch(bits & BITS_DATA_MASK) { |
Craig Shelley | 39a66b8 | 2005-05-27 00:09:56 +0100 | [diff] [blame] | 402 | case BITS_DATA_5: |
| 403 | dbg("%s - data bits = 5", __FUNCTION__); |
| 404 | cflag |= CS5; |
| 405 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 406 | case BITS_DATA_6: |
| 407 | dbg("%s - data bits = 6", __FUNCTION__); |
| 408 | cflag |= CS6; |
| 409 | break; |
| 410 | case BITS_DATA_7: |
| 411 | dbg("%s - data bits = 7", __FUNCTION__); |
| 412 | cflag |= CS7; |
| 413 | break; |
| 414 | case BITS_DATA_8: |
| 415 | dbg("%s - data bits = 8", __FUNCTION__); |
| 416 | cflag |= CS8; |
| 417 | break; |
| 418 | case BITS_DATA_9: |
| 419 | dbg("%s - data bits = 9 (not supported, " |
| 420 | "using 8 data bits)", __FUNCTION__); |
| 421 | cflag |= CS8; |
| 422 | bits &= ~BITS_DATA_MASK; |
| 423 | bits |= BITS_DATA_8; |
Craig Shelley | 39a66b8 | 2005-05-27 00:09:56 +0100 | [diff] [blame] | 424 | cp2101_set_config(port, CP2101_BITS, &bits, 2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 425 | break; |
| 426 | default: |
| 427 | dbg("%s - Unknown number of data bits, " |
| 428 | "using 8", __FUNCTION__); |
| 429 | cflag |= CS8; |
| 430 | bits &= ~BITS_DATA_MASK; |
| 431 | bits |= BITS_DATA_8; |
Craig Shelley | 39a66b8 | 2005-05-27 00:09:56 +0100 | [diff] [blame] | 432 | cp2101_set_config(port, CP2101_BITS, &bits, 2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 433 | break; |
| 434 | } |
| 435 | |
| 436 | switch(bits & BITS_PARITY_MASK) { |
| 437 | case BITS_PARITY_NONE: |
| 438 | dbg("%s - parity = NONE", __FUNCTION__); |
| 439 | cflag &= ~PARENB; |
| 440 | break; |
| 441 | case BITS_PARITY_ODD: |
| 442 | dbg("%s - parity = ODD", __FUNCTION__); |
| 443 | cflag |= (PARENB|PARODD); |
| 444 | break; |
| 445 | case BITS_PARITY_EVEN: |
| 446 | dbg("%s - parity = EVEN", __FUNCTION__); |
| 447 | cflag &= ~PARODD; |
| 448 | cflag |= PARENB; |
| 449 | break; |
| 450 | case BITS_PARITY_MARK: |
| 451 | dbg("%s - parity = MARK (not supported, " |
| 452 | "disabling parity)", __FUNCTION__); |
| 453 | cflag &= ~PARENB; |
| 454 | bits &= ~BITS_PARITY_MASK; |
Craig Shelley | 39a66b8 | 2005-05-27 00:09:56 +0100 | [diff] [blame] | 455 | cp2101_set_config(port, CP2101_BITS, &bits, 2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 456 | break; |
| 457 | case BITS_PARITY_SPACE: |
| 458 | dbg("%s - parity = SPACE (not supported, " |
| 459 | "disabling parity)", __FUNCTION__); |
| 460 | cflag &= ~PARENB; |
| 461 | bits &= ~BITS_PARITY_MASK; |
Craig Shelley | 39a66b8 | 2005-05-27 00:09:56 +0100 | [diff] [blame] | 462 | cp2101_set_config(port, CP2101_BITS, &bits, 2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 463 | break; |
| 464 | default: |
| 465 | dbg("%s - Unknown parity mode, " |
| 466 | "disabling parity", __FUNCTION__); |
| 467 | cflag &= ~PARENB; |
| 468 | bits &= ~BITS_PARITY_MASK; |
Craig Shelley | 39a66b8 | 2005-05-27 00:09:56 +0100 | [diff] [blame] | 469 | cp2101_set_config(port, CP2101_BITS, &bits, 2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 470 | break; |
| 471 | } |
| 472 | |
| 473 | cflag &= ~CSTOPB; |
| 474 | switch(bits & BITS_STOP_MASK) { |
| 475 | case BITS_STOP_1: |
| 476 | dbg("%s - stop bits = 1", __FUNCTION__); |
| 477 | break; |
| 478 | case BITS_STOP_1_5: |
| 479 | dbg("%s - stop bits = 1.5 (not supported, " |
Craig Shelley | 39a66b8 | 2005-05-27 00:09:56 +0100 | [diff] [blame] | 480 | "using 1 stop bit)", __FUNCTION__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 481 | bits &= ~BITS_STOP_MASK; |
Craig Shelley | 39a66b8 | 2005-05-27 00:09:56 +0100 | [diff] [blame] | 482 | cp2101_set_config(port, CP2101_BITS, &bits, 2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 483 | break; |
| 484 | case BITS_STOP_2: |
| 485 | dbg("%s - stop bits = 2", __FUNCTION__); |
| 486 | cflag |= CSTOPB; |
| 487 | break; |
| 488 | default: |
| 489 | dbg("%s - Unknown number of stop bits, " |
| 490 | "using 1 stop bit", __FUNCTION__); |
| 491 | bits &= ~BITS_STOP_MASK; |
Craig Shelley | 39a66b8 | 2005-05-27 00:09:56 +0100 | [diff] [blame] | 492 | cp2101_set_config(port, CP2101_BITS, &bits, 2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 493 | break; |
| 494 | } |
| 495 | |
Craig Shelley | 39a66b8 | 2005-05-27 00:09:56 +0100 | [diff] [blame] | 496 | cp2101_get_config(port, CP2101_MODEMCTL, modem_ctl, 16); |
| 497 | if (modem_ctl[0] & 0x0008) { |
| 498 | dbg("%s - flow control = CRTSCTS", __FUNCTION__); |
| 499 | cflag |= CRTSCTS; |
| 500 | } else { |
| 501 | dbg("%s - flow control = NONE", __FUNCTION__); |
| 502 | cflag &= ~CRTSCTS; |
| 503 | } |
| 504 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 505 | port->tty->termios->c_cflag = cflag; |
| 506 | } |
| 507 | |
| 508 | static void cp2101_set_termios (struct usb_serial_port *port, |
Alan Cox | 606d099 | 2006-12-08 02:38:45 -0800 | [diff] [blame^] | 509 | struct ktermios *old_termios) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 510 | { |
| 511 | unsigned int cflag, old_cflag=0; |
Craig Shelley | 39a66b8 | 2005-05-27 00:09:56 +0100 | [diff] [blame] | 512 | int baud=0, bits; |
| 513 | unsigned int modem_ctl[4]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 514 | |
| 515 | dbg("%s - port %d", __FUNCTION__, port->number); |
| 516 | |
| 517 | if ((!port->tty) || (!port->tty->termios)) { |
| 518 | dbg("%s - no tty structures", __FUNCTION__); |
| 519 | return; |
| 520 | } |
| 521 | cflag = port->tty->termios->c_cflag; |
| 522 | |
Craig Shelley | 39a66b8 | 2005-05-27 00:09:56 +0100 | [diff] [blame] | 523 | /* Check that they really want us to change something */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 524 | if (old_termios) { |
| 525 | if ((cflag == old_termios->c_cflag) && |
| 526 | (RELEVANT_IFLAG(port->tty->termios->c_iflag) |
| 527 | == RELEVANT_IFLAG(old_termios->c_iflag))) { |
| 528 | dbg("%s - nothing to change...", __FUNCTION__); |
| 529 | return; |
| 530 | } |
| 531 | |
| 532 | old_cflag = old_termios->c_cflag; |
| 533 | } |
| 534 | |
| 535 | /* If the baud rate is to be updated*/ |
| 536 | if ((cflag & CBAUD) != (old_cflag & CBAUD)) { |
| 537 | switch (cflag & CBAUD) { |
Craig Shelley | 39a66b8 | 2005-05-27 00:09:56 +0100 | [diff] [blame] | 538 | /* |
| 539 | * The baud rates which are commented out below |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 540 | * appear to be supported by the device |
| 541 | * but are non-standard |
| 542 | */ |
| 543 | case B0: baud = 0; break; |
| 544 | case B600: baud = 600; break; |
| 545 | case B1200: baud = 1200; break; |
| 546 | case B1800: baud = 1800; break; |
| 547 | case B2400: baud = 2400; break; |
| 548 | case B4800: baud = 4800; break; |
| 549 | /*case B7200: baud = 7200; break;*/ |
| 550 | case B9600: baud = 9600; break; |
| 551 | /*ase B14400: baud = 14400; break;*/ |
| 552 | case B19200: baud = 19200; break; |
| 553 | /*case B28800: baud = 28800; break;*/ |
| 554 | case B38400: baud = 38400; break; |
| 555 | /*case B55854: baud = 55054; break;*/ |
| 556 | case B57600: baud = 57600; break; |
| 557 | case B115200: baud = 115200; break; |
| 558 | /*case B127117: baud = 127117; break;*/ |
| 559 | case B230400: baud = 230400; break; |
| 560 | case B460800: baud = 460800; break; |
| 561 | case B921600: baud = 921600; break; |
| 562 | /*case B3686400: baud = 3686400; break;*/ |
| 563 | default: |
| 564 | dev_err(&port->dev, "cp2101 driver does not " |
| 565 | "support the baudrate requested\n"); |
| 566 | break; |
| 567 | } |
| 568 | |
| 569 | if (baud) { |
| 570 | dbg("%s - Setting baud rate to %d baud", __FUNCTION__, |
| 571 | baud); |
Craig Shelley | 39a66b8 | 2005-05-27 00:09:56 +0100 | [diff] [blame] | 572 | if (cp2101_set_config_single(port, CP2101_BAUDRATE, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 573 | (BAUD_RATE_GEN_FREQ / baud))) |
| 574 | dev_err(&port->dev, "Baud rate requested not " |
| 575 | "supported by device\n"); |
| 576 | } |
| 577 | } |
| 578 | |
Craig Shelley | 39a66b8 | 2005-05-27 00:09:56 +0100 | [diff] [blame] | 579 | /* If the number of data bits is to be updated */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 580 | if ((cflag & CSIZE) != (old_cflag & CSIZE)) { |
Craig Shelley | 39a66b8 | 2005-05-27 00:09:56 +0100 | [diff] [blame] | 581 | cp2101_get_config(port, CP2101_BITS, &bits, 2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 582 | bits &= ~BITS_DATA_MASK; |
| 583 | switch (cflag & CSIZE) { |
Craig Shelley | 39a66b8 | 2005-05-27 00:09:56 +0100 | [diff] [blame] | 584 | case CS5: |
| 585 | bits |= BITS_DATA_5; |
| 586 | dbg("%s - data bits = 5", __FUNCTION__); |
| 587 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 588 | case CS6: |
| 589 | bits |= BITS_DATA_6; |
| 590 | dbg("%s - data bits = 6", __FUNCTION__); |
| 591 | break; |
| 592 | case CS7: |
| 593 | bits |= BITS_DATA_7; |
| 594 | dbg("%s - data bits = 7", __FUNCTION__); |
| 595 | break; |
| 596 | case CS8: |
| 597 | bits |= BITS_DATA_8; |
| 598 | dbg("%s - data bits = 8", __FUNCTION__); |
| 599 | break; |
| 600 | /*case CS9: |
| 601 | bits |= BITS_DATA_9; |
| 602 | dbg("%s - data bits = 9", __FUNCTION__); |
| 603 | break;*/ |
| 604 | default: |
| 605 | dev_err(&port->dev, "cp2101 driver does not " |
| 606 | "support the number of bits requested," |
| 607 | " using 8 bit mode\n"); |
| 608 | bits |= BITS_DATA_8; |
| 609 | break; |
| 610 | } |
Craig Shelley | 39a66b8 | 2005-05-27 00:09:56 +0100 | [diff] [blame] | 611 | if (cp2101_set_config(port, CP2101_BITS, &bits, 2)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 612 | dev_err(&port->dev, "Number of data bits requested " |
| 613 | "not supported by device\n"); |
| 614 | } |
| 615 | |
| 616 | if ((cflag & (PARENB|PARODD)) != (old_cflag & (PARENB|PARODD))) { |
Craig Shelley | 39a66b8 | 2005-05-27 00:09:56 +0100 | [diff] [blame] | 617 | cp2101_get_config(port, CP2101_BITS, &bits, 2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 618 | bits &= ~BITS_PARITY_MASK; |
| 619 | if (cflag & PARENB) { |
| 620 | if (cflag & PARODD) { |
| 621 | bits |= BITS_PARITY_ODD; |
| 622 | dbg("%s - parity = ODD", __FUNCTION__); |
| 623 | } else { |
| 624 | bits |= BITS_PARITY_EVEN; |
| 625 | dbg("%s - parity = EVEN", __FUNCTION__); |
| 626 | } |
| 627 | } |
Craig Shelley | 39a66b8 | 2005-05-27 00:09:56 +0100 | [diff] [blame] | 628 | if (cp2101_set_config(port, CP2101_BITS, &bits, 2)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 629 | dev_err(&port->dev, "Parity mode not supported " |
| 630 | "by device\n"); |
| 631 | } |
| 632 | |
| 633 | if ((cflag & CSTOPB) != (old_cflag & CSTOPB)) { |
Craig Shelley | 39a66b8 | 2005-05-27 00:09:56 +0100 | [diff] [blame] | 634 | cp2101_get_config(port, CP2101_BITS, &bits, 2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 635 | bits &= ~BITS_STOP_MASK; |
| 636 | if (cflag & CSTOPB) { |
| 637 | bits |= BITS_STOP_2; |
| 638 | dbg("%s - stop bits = 2", __FUNCTION__); |
| 639 | } else { |
| 640 | bits |= BITS_STOP_1; |
| 641 | dbg("%s - stop bits = 1", __FUNCTION__); |
| 642 | } |
Craig Shelley | 39a66b8 | 2005-05-27 00:09:56 +0100 | [diff] [blame] | 643 | if (cp2101_set_config(port, CP2101_BITS, &bits, 2)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 644 | dev_err(&port->dev, "Number of stop bits requested " |
| 645 | "not supported by device\n"); |
| 646 | } |
Craig Shelley | 39a66b8 | 2005-05-27 00:09:56 +0100 | [diff] [blame] | 647 | |
| 648 | if ((cflag & CRTSCTS) != (old_cflag & CRTSCTS)) { |
| 649 | cp2101_get_config(port, CP2101_MODEMCTL, modem_ctl, 16); |
| 650 | dbg("%s - read modem controls = 0x%.4x 0x%.4x 0x%.4x 0x%.4x", |
| 651 | __FUNCTION__, modem_ctl[0], modem_ctl[1], |
| 652 | modem_ctl[2], modem_ctl[3]); |
| 653 | |
| 654 | if (cflag & CRTSCTS) { |
| 655 | modem_ctl[0] &= ~0x7B; |
| 656 | modem_ctl[0] |= 0x09; |
| 657 | modem_ctl[1] = 0x80; |
| 658 | dbg("%s - flow control = CRTSCTS", __FUNCTION__); |
| 659 | } else { |
| 660 | modem_ctl[0] &= ~0x7B; |
| 661 | modem_ctl[0] |= 0x01; |
| 662 | modem_ctl[1] |= 0x40; |
| 663 | dbg("%s - flow control = NONE", __FUNCTION__); |
| 664 | } |
| 665 | |
| 666 | dbg("%s - write modem controls = 0x%.4x 0x%.4x 0x%.4x 0x%.4x", |
| 667 | __FUNCTION__, modem_ctl[0], modem_ctl[1], |
| 668 | modem_ctl[2], modem_ctl[3]); |
| 669 | cp2101_set_config(port, CP2101_MODEMCTL, modem_ctl, 16); |
| 670 | } |
| 671 | |
| 672 | } |
| 673 | |
| 674 | static int cp2101_tiocmset (struct usb_serial_port *port, struct file *file, |
| 675 | unsigned int set, unsigned int clear) |
| 676 | { |
| 677 | int control = 0; |
| 678 | |
| 679 | dbg("%s - port %d", __FUNCTION__, port->number); |
| 680 | |
| 681 | if (set & TIOCM_RTS) { |
| 682 | control |= CONTROL_RTS; |
| 683 | control |= CONTROL_WRITE_RTS; |
| 684 | } |
| 685 | if (set & TIOCM_DTR) { |
| 686 | control |= CONTROL_DTR; |
| 687 | control |= CONTROL_WRITE_DTR; |
| 688 | } |
| 689 | if (clear & TIOCM_RTS) { |
| 690 | control &= ~CONTROL_RTS; |
| 691 | control |= CONTROL_WRITE_RTS; |
| 692 | } |
| 693 | if (clear & TIOCM_DTR) { |
| 694 | control &= ~CONTROL_DTR; |
| 695 | control |= CONTROL_WRITE_DTR; |
| 696 | } |
| 697 | |
| 698 | dbg("%s - control = 0x%.4x", __FUNCTION__, control); |
| 699 | |
| 700 | return cp2101_set_config(port, CP2101_CONTROL, &control, 2); |
| 701 | |
| 702 | } |
| 703 | |
| 704 | static int cp2101_tiocmget (struct usb_serial_port *port, struct file *file) |
| 705 | { |
| 706 | int control, result; |
| 707 | |
| 708 | dbg("%s - port %d", __FUNCTION__, port->number); |
| 709 | |
| 710 | cp2101_get_config(port, CP2101_CONTROL, &control, 1); |
| 711 | |
| 712 | result = ((control & CONTROL_DTR) ? TIOCM_DTR : 0) |
| 713 | |((control & CONTROL_RTS) ? TIOCM_RTS : 0) |
| 714 | |((control & CONTROL_CTS) ? TIOCM_CTS : 0) |
| 715 | |((control & CONTROL_DSR) ? TIOCM_DSR : 0) |
| 716 | |((control & CONTROL_RING)? TIOCM_RI : 0) |
| 717 | |((control & CONTROL_DCD) ? TIOCM_CD : 0); |
| 718 | |
| 719 | dbg("%s - control = 0x%.2x", __FUNCTION__, control); |
| 720 | |
| 721 | return result; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 722 | } |
| 723 | |
| 724 | static void cp2101_break_ctl (struct usb_serial_port *port, int break_state) |
| 725 | { |
Craig Shelley | 39a66b8 | 2005-05-27 00:09:56 +0100 | [diff] [blame] | 726 | int state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 727 | |
| 728 | dbg("%s - port %d", __FUNCTION__, port->number); |
| 729 | if (break_state == 0) |
| 730 | state = BREAK_OFF; |
| 731 | else |
| 732 | state = BREAK_ON; |
| 733 | dbg("%s - turning break %s", __FUNCTION__, |
| 734 | state==BREAK_OFF ? "off" : "on"); |
Craig Shelley | 39a66b8 | 2005-05-27 00:09:56 +0100 | [diff] [blame] | 735 | cp2101_set_config(port, CP2101_BREAK, &state, 2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 736 | } |
| 737 | |
| 738 | static int cp2101_startup (struct usb_serial *serial) |
| 739 | { |
Craig Shelley | 39a66b8 | 2005-05-27 00:09:56 +0100 | [diff] [blame] | 740 | /* CP2101 buffers behave strangely unless device is reset */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 741 | usb_reset_device(serial->dev); |
| 742 | return 0; |
| 743 | } |
| 744 | |
| 745 | static void cp2101_shutdown (struct usb_serial *serial) |
| 746 | { |
| 747 | int i; |
| 748 | |
| 749 | dbg("%s", __FUNCTION__); |
| 750 | |
Craig Shelley | 39a66b8 | 2005-05-27 00:09:56 +0100 | [diff] [blame] | 751 | /* Stop reads and writes on all ports */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 752 | for (i=0; i < serial->num_ports; ++i) { |
| 753 | cp2101_cleanup(serial->port[i]); |
| 754 | } |
| 755 | } |
| 756 | |
| 757 | static int __init cp2101_init (void) |
| 758 | { |
| 759 | int retval; |
| 760 | |
| 761 | retval = usb_serial_register(&cp2101_device); |
| 762 | if (retval) |
Craig Shelley | 39a66b8 | 2005-05-27 00:09:56 +0100 | [diff] [blame] | 763 | return retval; /* Failed to register */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 764 | |
| 765 | retval = usb_register(&cp2101_driver); |
| 766 | if (retval) { |
Craig Shelley | 39a66b8 | 2005-05-27 00:09:56 +0100 | [diff] [blame] | 767 | /* Failed to register */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 768 | usb_serial_deregister(&cp2101_device); |
| 769 | return retval; |
| 770 | } |
| 771 | |
Craig Shelley | 39a66b8 | 2005-05-27 00:09:56 +0100 | [diff] [blame] | 772 | /* Success */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 773 | info(DRIVER_DESC " " DRIVER_VERSION); |
| 774 | return 0; |
| 775 | } |
| 776 | |
| 777 | static void __exit cp2101_exit (void) |
| 778 | { |
| 779 | usb_deregister (&cp2101_driver); |
| 780 | usb_serial_deregister (&cp2101_device); |
| 781 | } |
| 782 | |
| 783 | module_init(cp2101_init); |
| 784 | module_exit(cp2101_exit); |
| 785 | |
| 786 | MODULE_DESCRIPTION(DRIVER_DESC); |
| 787 | MODULE_VERSION(DRIVER_VERSION); |
| 788 | MODULE_LICENSE("GPL"); |
| 789 | |
| 790 | module_param(debug, bool, S_IRUGO | S_IWUSR); |
| 791 | MODULE_PARM_DESC(debug, "Enable verbose debugging messages"); |