]> oss.titaniummirror.com Git - cp210x.git/blob - src/cp210x.c
Remove unnecessary file.
[cp210x.git] / src / cp210x.c
1 /*
2 * Silicon Laboratories CP210x 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 *
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 */
15
16 #include <linux/kernel.h>
17 #include <linux/errno.h>
18 #include <linux/slab.h>
19 #include <linux/tty.h>
20 #include <linux/tty_flip.h>
21 #include <linux/module.h>
22 #include <linux/moduleparam.h>
23 #include <linux/usb.h>
24 #include <asm/uaccess.h>
25 #include <linux/usb/serial.h>
26 #include "cp210x.h"
27
28 /*
29 * Version Information
30 */
31 #define DRIVER_VERSION "vxxPKGVERxxtmi"
32 #define DRIVER_DESC "Silicon Labs CP210x RS232 serial adaptor driver"
33
34 /*
35 * Function Prototypes
36 */
37 static int cp210x_open(struct usb_serial_port*, struct file*);
38 static void cp210x_cleanup(struct usb_serial_port*);
39 static void cp210x_close(struct usb_serial_port*, struct file*);
40 static void cp210x_get_termios(struct usb_serial_port*);
41 static void cp210x_set_termios(struct usb_serial_port*, struct ktermios*);
42 static int cp210x_tiocmget(struct usb_serial_port *, struct file *);
43 static int cp210x_tiocmset(struct usb_serial_port *, struct file *,
44 unsigned int, unsigned int);
45 static void cp210x_break_ctl(struct usb_serial_port*, int);
46 static int cp210x_startup(struct usb_serial *);
47 static void cp210x_shutdown(struct usb_serial*);
48 static int cp210x_ioctl(struct usb_serial_port *, struct file *,
49 unsigned int, unsigned long);
50
51 static int debug;
52
53 static const struct usb_device_id id_table[] = {
54 { USB_DEVICE(0x0471, 0x066A) }, /* AKTAKOM ACE-1001 cable */
55 { USB_DEVICE(0x0489, 0xE000) }, /* Pirelli Broadband S.p.A, DP-L10 SIP/GSM Mobile */
56 { USB_DEVICE(0x0745, 0x1000) }, /* CipherLab USB CCD Barcode Scanner 1000 */
57 { USB_DEVICE(0x08e6, 0x5501) }, /* Gemalto Prox-PU/CU contactless smartcard reader */
58 { USB_DEVICE(0x08FD, 0x000A) }, /* Digianswer A/S , ZigBee/802.15.4 MAC Device */
59 { USB_DEVICE(0x0FCF, 0x1003) }, /* Dynastream ANT development board */
60 { USB_DEVICE(0x0FCF, 0x1004) }, /* Dynastream ANT2USB */
61 { USB_DEVICE(0x0FCF, 0x1006) }, /* Dynastream ANT development board */
62 { USB_DEVICE(0x10A6, 0xAA26) }, /* Knock-off DCU-11 cable */
63 { USB_DEVICE(0x10AB, 0x10C5) }, /* Siemens MC60 Cable */
64 { USB_DEVICE(0x10B5, 0xAC70) }, /* Nokia CA-42 USB */
65 { USB_DEVICE(0x10C4, 0x0F91) }, /* Vstabi */
66 { USB_DEVICE(0x10C4, 0x1101) }, /* Arkham Technology DS101 Bus Monitor */
67 { USB_DEVICE(0x10C4, 0x1601) }, /* Arkham Technology DS101 Adapter */
68 { USB_DEVICE(0x10C4, 0x800A) }, /* SPORTident BSM7-D-USB main station */
69 { USB_DEVICE(0x10C4, 0x803B) }, /* Pololu USB-serial converter */
70 { USB_DEVICE(0x10C4, 0x8053) }, /* Enfora EDG1228 */
71 { USB_DEVICE(0x10C4, 0x8054) }, /* Enfora GSM2228 */
72 { USB_DEVICE(0x10C4, 0x8066) }, /* Argussoft In-System Programmer */
73 { USB_DEVICE(0x10C4, 0x807A) }, /* Crumb128 board */
74 { USB_DEVICE(0x10C4, 0x80CA) }, /* Degree Controls Inc */
75 { USB_DEVICE(0x10C4, 0x80DD) }, /* Tracient RFID */
76 { USB_DEVICE(0x10C4, 0x80F6) }, /* Suunto sports instrument */
77 { USB_DEVICE(0x10C4, 0x8115) }, /* Arygon NFC/Mifare Reader */
78 { USB_DEVICE(0x10C4, 0x813D) }, /* Burnside Telecom Deskmobile */
79 { USB_DEVICE(0x10C4, 0x813F) }, /* Tams Master Easy Control */
80 { USB_DEVICE(0x10C4, 0x814A) }, /* West Mountain Radio RIGblaster P&P */
81 { USB_DEVICE(0x10C4, 0x814B) }, /* West Mountain Radio RIGtalk */
82 { USB_DEVICE(0x10C4, 0x815E) }, /* Helicomm IP-Link 1220-DVM */
83 { USB_DEVICE(0x10C4, 0x819F) }, /* MJS USB Toslink Switcher */
84 { USB_DEVICE(0x10C4, 0x81A6) }, /* ThinkOptics WavIt */
85 { USB_DEVICE(0x10C4, 0x81AC) }, /* MSD Dash Hawk */
86 { USB_DEVICE(0x10C4, 0x81C8) }, /* Lipowsky Industrie Elektronik GmbH, Baby-JTAG */
87 { USB_DEVICE(0x10C4, 0x81E2) }, /* Lipowsky Industrie Elektronik GmbH, Baby-LIN */
88 { USB_DEVICE(0x10C4, 0x81E7) }, /* Aerocomm Radio */
89 { USB_DEVICE(0x10C4, 0x81E8) }, /* Zephyr Bioharness */
90 { USB_DEVICE(0x10C4, 0x81F2) }, /* C1007 HF band RFID controller */
91 { USB_DEVICE(0x10C4, 0x8218) }, /* Lipowsky Industrie Elektronik GmbH, HARP-1 */
92 { USB_DEVICE(0x10C4, 0x822B) }, /* Modem EDGE(GSM) Comander 2 */
93 { USB_DEVICE(0x10C4, 0x826B) }, /* Cygnal Integrated Products, Inc., Fasttrax GPS demostration module */
94 { USB_DEVICE(0x10C4, 0x8293) }, /* Telegesys ETRX2USB */
95 { USB_DEVICE(0x10C4, 0x82F9) }, /* Procyon AVS */
96 { USB_DEVICE(0x10C4, 0x8341) }, /* Siemens MC35PU GPRS Modem */
97 { USB_DEVICE(0x10C4, 0x8382) }, /* Cygnal Integrated Products, Inc. */
98 { USB_DEVICE(0x10C4, 0x83A8) }, /* Amber Wireless AMB2560 */
99 { USB_DEVICE(0x10C4, 0x8411) }, /* Kyocera GPS Module */
100 { USB_DEVICE(0x10C4, 0x846E) }, /* BEI USB Sensor Interface (VCP) */
101 { USB_DEVICE(0x10C4, 0xEA60) }, /* Silicon Labs factory default */
102 { USB_DEVICE(0x10C4, 0xEA61) }, /* Silicon Labs factory default */
103 { USB_DEVICE(0x10C4, 0xF001) }, /* Elan Digital Systems USBscope50 */
104 { USB_DEVICE(0x10C4, 0xF002) }, /* Elan Digital Systems USBwave12 */
105 { USB_DEVICE(0x10C4, 0xF003) }, /* Elan Digital Systems USBpulse100 */
106 { USB_DEVICE(0x10C4, 0xF004) }, /* Elan Digital Systems USBcount50 */
107 { USB_DEVICE(0x10C5, 0xEA61) }, /* Silicon Labs MobiData GPRS USB Modem */
108 { USB_DEVICE(0x10CE, 0xEA6A) }, /* Silicon Labs MobiData GPRS USB Modem 100EU */
109 { USB_DEVICE(0x13AD, 0x9999) }, /* Baltech card reader */
110 { USB_DEVICE(0x1555, 0x0004) }, /* Owen AC4 USB-RS485 Converter */
111 { USB_DEVICE(0x166A, 0x0303) }, /* Clipsal 5500PCU C-Bus USB interface */
112 { USB_DEVICE(0x16D6, 0x0001) }, /* Jablotron serial interface */
113 { USB_DEVICE(0x18EF, 0xE00F) }, /* ELV USB-I2C-Interface */
114 { USB_DEVICE(0x413C, 0x9500) }, /* DW700 GPS USB interface */
115 { } /* Terminating Entry */
116 };
117
118 MODULE_DEVICE_TABLE(usb, id_table);
119
120 static struct usb_driver cp210x_driver = {
121 .name = "cp210x",
122 .probe = usb_serial_probe,
123 .disconnect = usb_serial_disconnect,
124 .id_table = id_table,
125 .no_dynamic_id = 1,
126 };
127
128 static struct usb_serial_driver cp210x_device = {
129 .driver = {
130 .owner = THIS_MODULE,
131 .name = "cp210x",
132 },
133 .usb_driver = &cp210x_driver,
134 .id_table = id_table,
135 .num_interrupt_in = 0,
136 .num_bulk_in = NUM_DONT_CARE,
137 .num_bulk_out = NUM_DONT_CARE,
138 .num_ports = 1,
139 .open = cp210x_open,
140 .close = cp210x_close,
141 .ioctl = cp210x_ioctl,
142 .break_ctl = cp210x_break_ctl,
143 .set_termios = cp210x_set_termios,
144 .tiocmget = cp210x_tiocmget,
145 .tiocmset = cp210x_tiocmset,
146 .attach = cp210x_startup,
147 .shutdown = cp210x_shutdown,
148 };
149
150 /* Config request types */
151 #define REQTYPE_HOST_TO_DEVICE 0x41
152 #define REQTYPE_DEVICE_TO_HOST 0xc1
153
154 /* Config SET requests. To GET, add 1 to the request number */
155 #define CP2101_UART 0x00 /* Enable / Disable */
156 #define CP2101_BAUDRATE 0x01 /* (BAUD_RATE_GEN_FREQ / baudrate) */
157 #define CP2101_BITS 0x03 /* 0x(0)(databits)(parity)(stopbits) */
158 #define CP2101_BREAK 0x05 /* On / Off */
159 #define CP2101_CONTROL 0x07 /* Flow control line states */
160 #define CP2101_MODEMCTL 0x13 /* Modem controls */
161 #define CP2101_CONFIG_6 0x19 /* 6 bytes of config data ??? */
162
163 /* CP2101_UART */
164 #define UART_ENABLE 0x0001
165 #define UART_DISABLE 0x0000
166
167 /* CP2101_BAUDRATE */
168 #define BAUD_RATE_GEN_FREQ 0x384000
169
170 /* CP2101_BITS */
171 #define BITS_DATA_MASK 0X0f00
172 #define BITS_DATA_5 0X0500
173 #define BITS_DATA_6 0X0600
174 #define BITS_DATA_7 0X0700
175 #define BITS_DATA_8 0X0800
176 #define BITS_DATA_9 0X0900
177
178 #define BITS_PARITY_MASK 0x00f0
179 #define BITS_PARITY_NONE 0x0000
180 #define BITS_PARITY_ODD 0x0010
181 #define BITS_PARITY_EVEN 0x0020
182 #define BITS_PARITY_MARK 0x0030
183 #define BITS_PARITY_SPACE 0x0040
184
185 #define BITS_STOP_MASK 0x000f
186 #define BITS_STOP_1 0x0000
187 #define BITS_STOP_1_5 0x0001
188 #define BITS_STOP_2 0x0002
189
190 /* CP2101_BREAK */
191 #define BREAK_ON 0x0000
192 #define BREAK_OFF 0x0001
193
194 /* CP2101_CONTROL */
195 #define CONTROL_DTR 0x0001
196 #define CONTROL_RTS 0x0002
197 #define CONTROL_CTS 0x0010
198 #define CONTROL_DSR 0x0020
199 #define CONTROL_RING 0x0040
200 #define CONTROL_DCD 0x0080
201 #define CONTROL_WRITE_DTR 0x0100
202 #define CONTROL_WRITE_RTS 0x0200
203
204 /* cp210x_get_partnum() return codes */
205 #define CP210x_PART_UNKNOWN 0x00
206 #define CP210x_PART_CP2101 0x01
207 #define CP210x_PART_CP2102 0x02
208 #define CP210x_PART_CP2103 0x03
209
210 /* Helper to make usb string size */
211 #define USBSTRLEN(x) (x * 2 + 2)
212
213 /* Populates usbstr with: (len) + (0x03) + unicode(str). Each char in str
214 * takes two bytes in unicode format.
215 * Returns the resulting length of the string in usbstr.
216 * This function can accept overlapping usbstr and str as long as the overlap
217 * does not cause data written to usbstr to overwrite data not yet read from
218 * str.
219 */
220 static int make_usb_string(char *usbstr, size_t usblen, char *src,
221 size_t srclen)
222 {
223 int len = 0;
224
225 if (usbstr && usblen >= 2 && src && *src && srclen) {
226 char *p;
227
228 if (usblen > 255)
229 usblen = 255;
230
231 p = usbstr + 1;
232 *p++ = 0x03;
233 len = 2;
234 while (srclen && len < usblen) {
235 *p++ = *src++;
236 *p++ = 0;
237 len += 2;
238 srclen--;
239 }
240 *usbstr = (char)len;
241 }
242 return len;
243 }
244
245 /*
246 * cp210x_usbstr_from_user
247 * Populate kbuf with a usb string derived from a user space variable. klen
248 * is the size of the buffer at kbuf.
249 * Returns the number of bytes used in kbuf.
250 */
251 static size_t cp210x_usbstr_from_user(char *kbuf, unsigned long ubuf, size_t klen)
252 {
253 struct cp210x_buffer t;
254 char* str;
255 size_t slen;
256
257 if (!kbuf || !ubuf || !klen)
258 return 0;
259 if (copy_from_user(&t, (struct cp210x_buffer __user *)ubuf, sizeof(t)))
260 return 0;
261 if (!t.buf || !t.len || USBSTRLEN(t.len) > klen)
262 return 0;
263 slen = (klen - 2) / 2;
264 if (t.len < slen)
265 slen = t.len;
266 str = kbuf + klen - slen;
267 if (copy_from_user(str, (u8 __user *)t.buf, slen))
268 return 0;
269 return make_usb_string(kbuf, klen, str, slen);
270 }
271
272 /* cp210x_has_setmfg
273 * Returns 1 if the CP210X part includes firmware that allows setting the
274 * USB MFG descriptor, else 0. As of this writing, no CP210X firmware allows
275 * this. SiLabs has suggested this may change in future firmware versions or
276 * parts.
277 */
278 static inline int cp210x_has_setmfg(void)
279 {
280 return 0;
281 }
282
283 /*
284 * cp210x_ctlmsg
285 * A generic usb control message interface.
286 * Returns the actual size of the data read or written within the message, 0
287 * if no data were read or written, or a negative value to indicate an error.
288 */
289 static int cp210x_ctlmsg(struct usb_serial_port *port, u8 request,
290 u8 requestype, u16 value, u16 index, void *data, u16 size)
291 {
292 struct usb_device *dev = port->serial->dev;
293 u8 *tbuf;
294 int ret;
295
296 if (!(tbuf = kmalloc(size, GFP_KERNEL)))
297 return -ENOMEM;
298 if (requestype & 0x80) {
299 ret = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0), request,
300 requestype, value, index, tbuf, size, 300);
301 if (ret > 0 && size)
302 memcpy(data, tbuf, size);
303 } else {
304 if (size)
305 memcpy(tbuf, data, size);
306 ret = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), request,
307 requestype, value, index, tbuf, size, 300);
308 }
309 kfree(tbuf);
310 if (ret < 0 && ret != -EPIPE) {
311 dev_printk(KERN_DEBUG, &dev->dev, "cp210x: control failed cmd rqt %u "
312 "rq %u len %u ret %d\n", requestype, request, size, ret);
313 }
314 return ret;
315 }
316
317 static int cp210x_reset(struct usb_serial_port *port)
318 {
319 dbg("%s", __FUNCTION__);
320
321 #if 1
322 /* Is this better than usb_device_reset? It may be. Once a client issues
323 * the reset ioctl, it must disconnect and reconnect, since the USB
324 * connections are torn down. We also ignore the error return, since
325 * the part resets and doesn't send one...
326 */
327 cp210x_ctlmsg(port, 0xff, 0x40, 0x0008, 0x00, NULL, 0);
328 #else
329 usb_reset_device(port->serial->dev);
330 #endif
331 return 0;
332 }
333
334 static int cp210x_get_partnum(struct usb_serial_port *port)
335 {
336 static u8 _partnum = CP210x_PART_UNKNOWN;
337
338 if (_partnum == CP210x_PART_UNKNOWN) {
339 u8 addr = port->serial->dev->actconfig->interface[0]->
340 cur_altsetting->endpoint[0].desc.bEndpointAddress &
341 USB_ENDPOINT_NUMBER_MASK;
342
343 if (addr == 0x03 || addr == 0x02)
344 _partnum = CP210x_PART_CP2101;
345 else if (addr == 0x01) {
346 /* Must query part to determine part number */
347 if (cp210x_ctlmsg(port, 0xff, 0xc0, 0x370b, 0x00,
348 &_partnum, 1) != 1)
349 _partnum = CP210x_PART_UNKNOWN;
350 }
351 }
352 dbg("%s - partnum %u", __FUNCTION__, _partnum);
353 return _partnum;
354 }
355
356 static inline int cp210x_setu16(struct usb_serial_port *port, int cmd,
357 unsigned int value)
358 {
359 return cp210x_ctlmsg(port, 0xff, 0x40, 0x3700 | (cmd & 0xff),
360 value, NULL, 0);
361 }
362
363 /*
364 * cp210x_setstr
365 *
366 * Set a USB string descriptor using proprietary cp210x control messages.
367 * Return the number of characters actually written.
368 */
369 static int cp210x_setstr(struct usb_serial_port *port, int cmd, char *usbstr)
370 {
371 unsigned len = usbstr[0];
372 int ret = cp210x_ctlmsg(port, 0xff, 0x40, 0x3700 | (cmd & 0xff), 0,
373 usbstr, len);
374 dbg("%s - cmd 0x%02x len %d ret %d", __FUNCTION__, cmd, len, ret);
375 return ret;
376 }
377
378 /* Set all gpio simultaneously */
379 static int cp210x_gpioset(struct usb_serial_port *port, u8 gpio)
380 {
381 dbg("%s - port %d, gpio = 0x%.2x", __FUNCTION__, port->number, gpio);
382
383 return cp210x_ctlmsg(port, 0xff, 0x40, 0x37e1,
384 ((uint16_t)gpio << 8) | GPIO_MASK, NULL, 0);
385 }
386
387 /* Set select gpio bits */
388 static int cp210x_gpiosetb(struct usb_serial_port *port, u8 set, u8 clear)
389 {
390 u16 gpio = 0;
391
392 /* The bitmask is in the LSB, the values in the MSB */
393 if (set & GPIO_0)
394 gpio |= (GPIO_0 << 8)|GPIO_0;
395 if (set & GPIO_1)
396 gpio |= (GPIO_1 << 8)|GPIO_1;
397 if (set & GPIO_2)
398 gpio |= (GPIO_2 << 8)|GPIO_2;
399 if (set & GPIO_3)
400 gpio |= (GPIO_3 << 8)|GPIO_3;
401 if (clear & GPIO_0)
402 gpio = (gpio & ~(GPIO_0 << 8))|GPIO_0;
403 if (clear & GPIO_1)
404 gpio = (gpio & ~(GPIO_1 << 8))|GPIO_1;
405 if (clear & GPIO_2)
406 gpio = (gpio & ~(GPIO_2 << 8))|GPIO_2;
407 if (clear & GPIO_3)
408 gpio = (gpio & ~(GPIO_3 << 8))|GPIO_3;
409
410 dbg("%s - port %d, gpiob = 0x%.4x", __FUNCTION__, port->number, gpio);
411
412 /* FIXME: how about REQTYPE_HOST_TO_DEVICE instead of 0x40? */
413 return cp210x_ctlmsg(port, 0xff, 0x40, 0x37e1, gpio, NULL, 0);
414 }
415
416 static int cp210x_gpioget(struct usb_serial_port *port, u8 *gpio)
417 {
418 int ret;
419
420 dbg("%s - port %d", __FUNCTION__, port->number);
421
422 /* FIXME: how about REQTYPE_DEVICE_TO_HOST instead of 0xc0? */
423 ret = cp210x_ctlmsg(port, 0xff, 0xc0, 0x00c2, 0, gpio, 1);
424
425 dbg("%s - gpio = 0x%.2x (%d)", __FUNCTION__, *gpio, ret);
426
427 return (ret == 1) ? 0 : -1;
428 }
429
430 static int cp210x_portconfset(struct usb_serial_port *port,
431 struct cp210x_port_config *config)
432 {
433 struct cp210x_port_config lconfig;
434 int ret;
435
436 dbg("%s", __FUNCTION__);
437
438 memcpy(&lconfig, config, sizeof(lconfig));
439
440 /* Words from cp2103 are MSB */
441 lconfig.reset.mode = cpu_to_be16(config->reset.mode);
442 lconfig.reset.latch = cpu_to_be16(config->reset.latch);
443 lconfig.suspend.mode = cpu_to_be16(config->suspend.mode);
444 lconfig.suspend.latch = cpu_to_be16(config->suspend.latch);
445 #if 0 /* apparently not implemented by CP210X firmware */
446 lconfig.reset.lowPower = cpu_to_be16(config->reset.lowPower);
447 lconfig.suspend.lowPower = cpu_to_be16(config->suspend.lowPower);
448 #else
449 lconfig.suspend.lowPower = 0;
450 lconfig.reset.lowPower = 0;
451 #endif
452
453 ret = cp210x_ctlmsg(port, 0xff, 0x40, 0x370c, 0, &lconfig,
454 sizeof(struct cp210x_port_config));
455 if (ret == sizeof(struct cp210x_port_config))
456 return 0;
457 else if (ret >= 0)
458 return -1;
459 else
460 return ret;
461 }
462
463 static int cp210x_portconfget(struct usb_serial_port *port,
464 struct cp210x_port_config *config)
465 {
466 int ret;
467
468 dbg("%s", __FUNCTION__);
469
470 ret = cp210x_ctlmsg(port, 0xff, 0xc0, 0x370c, 0, config,
471 sizeof(struct cp210x_port_config));
472 if (ret == sizeof(struct cp210x_port_config)) {
473 /* Words from cp2103 are MSB */
474 config->reset.mode = be16_to_cpu(config->reset.mode);
475 config->reset.lowPower = be16_to_cpu(config->reset.lowPower);
476 config->reset.latch = be16_to_cpu(config->reset.latch);
477 config->suspend.mode = be16_to_cpu(config->suspend.mode);
478 config->suspend.lowPower =
479 be16_to_cpu(config->suspend.lowPower);
480 config->suspend.latch = be16_to_cpu(config->suspend.latch);
481
482 /* apparently not implemented yet */
483 config->reset.lowPower = 0;
484 config->suspend.lowPower = 0;
485
486 return 0;
487 } else if (ret >= 0)
488 return -1;
489 else
490 return ret;
491
492 }
493
494 /*
495 * cp210x_get_config
496 * Reads from the CP210x configuration registers
497 * 'size' is specified in bytes.
498 * 'data' is a pointer to a pre-allocated array of integers large
499 * enough to hold 'size' bytes (with 4 bytes to each integer)
500 */
501 static int cp210x_get_config(struct usb_serial_port *port, u8 request,
502 unsigned int *data, int size)
503 {
504 struct usb_serial *serial = port->serial;
505 __le32 *buf;
506 int result, i, length;
507
508 /* Number of integers required to contain the array */
509 length = (((size - 1) | 3) + 1)/4;
510
511 buf = kcalloc(length, sizeof(__le32), GFP_KERNEL);
512 if (!buf) {
513 dev_err(&port->dev, "%s - out of memory.\n", __FUNCTION__);
514 return -ENOMEM;
515 }
516
517 /* For get requests, the request number must be incremented */
518 request++;
519
520 /* Issue the request, attempting to read 'size' bytes */
521 result = usb_control_msg(serial->dev, usb_rcvctrlpipe(serial->dev, 0),
522 request, REQTYPE_DEVICE_TO_HOST, 0x0000,
523 0, buf, size, 300);
524
525 /* Convert data into an array of integers */
526 for (i = 0; i < length; i++)
527 data[i] = le32_to_cpu(buf[i]);
528
529 kfree(buf);
530
531 if (result != size) {
532 dev_err(&port->dev, "%s - Unable to send config request, "
533 "request=0x%x size=%d result=%d\n",
534 __FUNCTION__, request, size, result);
535 return -EPROTO;
536 }
537
538 return 0;
539 }
540
541 /*
542 * cp210x_set_config
543 * Writes to the CP210x configuration registers
544 * Values less than 16 bits wide are sent directly
545 * 'size' is specified in bytes.
546 */
547 static int cp210x_set_config(struct usb_serial_port *port, u8 request,
548 unsigned int *data, int size)
549 {
550 struct usb_serial *serial = port->serial;
551 __le32 *buf;
552 int result, i, length;
553
554 /* Number of integers required to contain the array */
555 length = (((size - 1) | 3) + 1)/4;
556
557 buf = kmalloc(length * sizeof(__le32), GFP_KERNEL);
558 if (!buf) {
559 dev_err(&port->dev, "%s - out of memory.\n",
560 __FUNCTION__);
561 return -ENOMEM;
562 }
563
564 /* Array of integers into bytes */
565 for (i = 0; i < length; i++)
566 buf[i] = cpu_to_le32(data[i]);
567
568 if (size > 2) {
569 result = usb_control_msg(serial->dev,
570 usb_sndctrlpipe(serial->dev, 0),
571 request, REQTYPE_HOST_TO_DEVICE, 0x0000,
572 0, buf, size, 300);
573 } else {
574 result = usb_control_msg(serial->dev,
575 usb_sndctrlpipe(serial->dev, 0),
576 request, REQTYPE_HOST_TO_DEVICE, data[0],
577 0, NULL, 0, 300);
578 }
579
580 kfree(buf);
581
582 if ((size > 2 && result != size) || result < 0) {
583 dev_err(&port->dev, "%s - Unable to send request, "
584 "request=0x%x size=%d result=%d\n",
585 __FUNCTION__, request, size, result);
586 return -EPROTO;
587 }
588
589 return 0;
590 }
591
592 /*
593 * cp210x_set_config_single
594 * Convenience function for calling cp210x_set_config on single data values
595 * without requiring an integer pointer
596 */
597 static inline int cp210x_set_config_single(struct usb_serial_port *port,
598 u8 request, unsigned int data)
599 {
600 return cp210x_set_config(port, request, &data, 2);
601 }
602
603 static int cp210x_open(struct usb_serial_port *port, struct file *filp)
604 {
605 struct usb_serial *serial = port->serial;
606 int result;
607
608 dbg("%s - port %d", __FUNCTION__, port->number);
609
610 if (cp210x_set_config_single(port, CP2101_UART, UART_ENABLE)) {
611 dev_err(&port->dev, "%s - Unable to enable UART\n",
612 __FUNCTION__);
613 return -EPROTO;
614 }
615
616 /* Start reading from the device */
617 usb_fill_bulk_urb(port->read_urb, serial->dev,
618 usb_rcvbulkpipe(serial->dev,
619 port->bulk_in_endpointAddress),
620 port->read_urb->transfer_buffer,
621 port->read_urb->transfer_buffer_length,
622 serial->type->read_bulk_callback,
623 port);
624 result = usb_submit_urb(port->read_urb, GFP_KERNEL);
625 if (result) {
626 dev_err(&port->dev, "%s - failed resubmitting read urb, "
627 "error %d\n", __FUNCTION__, result);
628 return result;
629 }
630
631 /* Configure the termios structure */
632 cp210x_get_termios(port);
633
634 /* Set the DTR and RTS pins low */
635 cp210x_tiocmset(port, NULL, TIOCM_DTR | TIOCM_RTS, 0);
636
637 return 0;
638 }
639
640 static void cp210x_cleanup(struct usb_serial_port *port)
641 {
642 struct usb_serial *serial = port->serial;
643
644 dbg("%s - port %d", __FUNCTION__, port->number);
645
646 if (serial->dev) {
647 /* shutdown any bulk reads that might be going on */
648 if (serial->num_bulk_out)
649 usb_kill_urb(port->write_urb);
650 if (serial->num_bulk_in)
651 usb_kill_urb(port->read_urb);
652 }
653 }
654
655 static void cp210x_close(struct usb_serial_port *port, struct file *filp)
656 {
657 dbg("%s - port %d", __FUNCTION__, port->number);
658
659 /* shutdown our urbs */
660 dbg("%s - shutting down urbs", __FUNCTION__);
661 usb_kill_urb(port->write_urb);
662 usb_kill_urb(port->read_urb);
663
664 cp210x_set_config_single(port, CP2101_UART, UART_DISABLE);
665 }
666
667 static int cp210x_ioctl(struct usb_serial_port *port, struct file *file,
668 unsigned int cmd, unsigned long arg)
669 {
670 dbg("%s (%d) cmd = 0x%04x", __FUNCTION__, port->number, cmd);
671
672 switch (cmd) {
673
674 case TIOCMGET:
675 {
676 int result = cp210x_tiocmget(port, file);
677 if (copy_to_user((int __user *)&arg, &result, sizeof(int)))
678 return -EFAULT;
679 return 0;
680 }
681 break;
682
683 case TIOCMSET:
684 case TIOCMBIS:
685 case TIOCMBIC:
686 {
687 int val = 0;
688
689 if (copy_from_user(&val, (int __user *)&arg, sizeof(int)))
690 return -EFAULT;
691
692 /* this looks wrong: TIOCMSET isn't going to work right */
693 if (cp210x_tiocmset(port, file, cmd==TIOCMBIC ? 0 : val,
694 cmd==TIOCMBIC ? val : 0))
695 return -EFAULT;
696 return 0;
697 }
698 break;
699
700 case CP210x_IOCTL_GPIOGET:
701 if (cp210x_get_partnum(port) == CP210x_PART_CP2103) {
702 u8 gpio = 0;
703 if (!cp210x_gpioget(port, &gpio) && !copy_to_user(
704 (u8 __user *)arg, &gpio, sizeof(gpio)))
705 return 0;
706 }
707 return -EFAULT;
708 break;
709
710 case CP210x_IOCTL_GPIOSET:
711 if (cp210x_get_partnum(port) == CP210x_PART_CP2103 &&
712 !cp210x_gpioset(port, arg))
713 return 0;
714 return -EFAULT;
715 break;
716
717 case CP210x_IOCTL_GPIOBIC:
718 case CP210x_IOCTL_GPIOBIS:
719 if (cp210x_get_partnum(port) == CP210x_PART_CP2103 &&
720 !cp210x_gpiosetb(port,
721 (cmd==CP210x_IOCTL_GPIOBIC) ? 0 : arg,
722 (cmd==CP210x_IOCTL_GPIOBIC) ? arg : 0))
723 return 0;
724 return -EFAULT;
725 break;
726
727 case CP210x_IOCTL_DEVICERESET:
728 return cp210x_reset(port);
729 break;
730
731 case CP210x_IOCTL_PORTCONFGET:
732 {
733 struct cp210x_port_config config;
734 if (!cp210x_portconfget(port, &config) && !copy_to_user(
735 (struct cp210x_port_config __user *)arg,
736 &config, sizeof(config)))
737 return 0;
738 }
739 return -EFAULT;
740 break;
741
742 case CP210x_IOCTL_PORTCONFSET:
743 {
744 struct cp210x_port_config config;
745 if (!copy_from_user(&config, (struct cp210x_port_config __user *)arg,
746 sizeof(config)) &&
747 !cp210x_portconfset(port, &config))
748 return 0;
749 return -EFAULT;
750 }
751 break;
752
753 case CP210x_IOCTL_SETVID:
754 {
755 unsigned int vid;
756 if (!copy_from_user(&vid, (unsigned int __user *)arg,
757 sizeof(unsigned int)) &&
758 !cp210x_setu16(port, 0x01, vid))
759 return 0;
760 return -EFAULT;
761 }
762 break;
763
764 case CP210x_IOCTL_SETPID:
765 {
766 unsigned int pid;
767 if (!copy_from_user(&pid, (unsigned int __user *)arg,
768 sizeof(unsigned int)) &&
769 !cp210x_setu16(port, 0x02, pid))
770 return 0;
771 return -EFAULT;
772 }
773 break;
774
775 case CP210x_IOCTL_SETMFG:
776 if (cp210x_has_setmfg()) {
777 char usbstr[USBSTRLEN(CP210x_MAX_MFG_STRLEN)];
778 size_t len = cp210x_usbstr_from_user(usbstr, arg,
779 sizeof(usbstr));
780 if (len && cp210x_setstr(port, 0x00, usbstr) == len)
781 return 0;
782 }
783 return -EFAULT;
784 break;
785
786 case CP210x_IOCTL_SETPRODUCT:
787 {
788 char usbstr[USBSTRLEN(CP210x_MAX_PRODUCT_STRLEN)];
789 size_t len = cp210x_usbstr_from_user(usbstr, arg,
790 sizeof(usbstr));
791 if (len && cp210x_setstr(port, 0x03, usbstr) == len)
792 return 0;
793 return -EFAULT;
794 }
795 break;
796
797 case CP210x_IOCTL_SETSERIAL:
798 {
799 char usbstr[USBSTRLEN(CP210x_MAX_SERIAL_STRLEN)];
800 size_t len = cp210x_usbstr_from_user(usbstr, arg,
801 sizeof(usbstr));
802 if (len && cp210x_setstr(port, 0x04, usbstr) == len)
803 return 0;
804 return -EFAULT;
805 }
806 break;
807
808 case CP210x_IOCTL_SETDEVVER:
809 {
810 unsigned int ver;
811 if (!copy_from_user(&ver, (unsigned int __user *)arg,
812 sizeof(unsigned int)) &&
813 !cp210x_setu16(port, 0x07, ver))
814 return 0;
815 return -EFAULT;
816 }
817 break;
818
819 default:
820 dbg("%s not supported = 0x%04x", __FUNCTION__, cmd);
821 break;
822 }
823
824 return -ENOIOCTLCMD;
825 }
826
827 /*
828 * cp210x_get_termios
829 * Reads the baud rate, data bits, parity, stop bits and flow control mode
830 * from the device, corrects any unsupported values, and configures the
831 * termios structure to reflect the state of the device
832 */
833 static void cp210x_get_termios(struct usb_serial_port *port)
834 {
835 unsigned int cflag, modem_ctl[4];
836 int baud;
837 int bits;
838
839 dbg("%s - port %d", __FUNCTION__, port->number);
840
841 if (!port->tty || !port->tty->termios) {
842 dbg("%s - no tty structures", __FUNCTION__);
843 return;
844 }
845
846 cp210x_get_config(port, CP2101_BAUDRATE, &baud, 2);
847 /* Convert to baudrate */
848 if (baud)
849 baud = BAUD_RATE_GEN_FREQ / baud;
850
851 dbg("%s - baud rate = %d", __FUNCTION__, baud);
852
853 tty_encode_baud_rate(port->tty, baud, baud);
854 cflag = port->tty->termios->c_cflag;
855
856 cp210x_get_config(port, CP2101_BITS, &bits, 2);
857 cflag &= ~CSIZE;
858 switch(bits & BITS_DATA_MASK) {
859 case BITS_DATA_5:
860 dbg("%s - data bits = 5", __FUNCTION__);
861 cflag |= CS5;
862 break;
863 case BITS_DATA_6:
864 dbg("%s - data bits = 6", __FUNCTION__);
865 cflag |= CS6;
866 break;
867 case BITS_DATA_7:
868 dbg("%s - data bits = 7", __FUNCTION__);
869 cflag |= CS7;
870 break;
871 case BITS_DATA_8:
872 dbg("%s - data bits = 8", __FUNCTION__);
873 cflag |= CS8;
874 break;
875 case BITS_DATA_9:
876 dbg("%s - data bits = 9 (not supported, "
877 "using 8 data bits)", __FUNCTION__);
878 cflag |= CS8;
879 bits &= ~BITS_DATA_MASK;
880 bits |= BITS_DATA_8;
881 cp210x_set_config(port, CP2101_BITS, &bits, 2);
882 break;
883 default:
884 dbg("%s - Unknown number of data bits, "
885 "using 8", __FUNCTION__);
886 cflag |= CS8;
887 bits &= ~BITS_DATA_MASK;
888 bits |= BITS_DATA_8;
889 cp210x_set_config(port, CP2101_BITS, &bits, 2);
890 break;
891 }
892
893 switch(bits & BITS_PARITY_MASK) {
894 case BITS_PARITY_NONE:
895 dbg("%s - parity = NONE", __FUNCTION__);
896 cflag &= ~PARENB;
897 break;
898 case BITS_PARITY_ODD:
899 dbg("%s - parity = ODD", __FUNCTION__);
900 cflag |= (PARENB|PARODD);
901 break;
902 case BITS_PARITY_EVEN:
903 dbg("%s - parity = EVEN", __FUNCTION__);
904 cflag &= ~PARODD;
905 cflag |= PARENB;
906 break;
907 case BITS_PARITY_MARK:
908 dbg("%s - parity = MARK (not supported, "
909 "disabling parity)", __FUNCTION__);
910 cflag &= ~PARENB;
911 bits &= ~BITS_PARITY_MASK;
912 cp210x_set_config(port, CP2101_BITS, &bits, 2);
913 break;
914 case BITS_PARITY_SPACE:
915 dbg("%s - parity = SPACE (not supported, "
916 "disabling parity)", __FUNCTION__);
917 cflag &= ~PARENB;
918 bits &= ~BITS_PARITY_MASK;
919 cp210x_set_config(port, CP2101_BITS, &bits, 2);
920 break;
921 default:
922 dbg("%s - Unknown parity mode, "
923 "disabling parity", __FUNCTION__);
924 cflag &= ~PARENB;
925 bits &= ~BITS_PARITY_MASK;
926 cp210x_set_config(port, CP2101_BITS, &bits, 2);
927 break;
928 }
929
930 cflag &= ~CSTOPB;
931 switch(bits & BITS_STOP_MASK) {
932 case BITS_STOP_1:
933 dbg("%s - stop bits = 1", __FUNCTION__);
934 break;
935 case BITS_STOP_1_5:
936 dbg("%s - stop bits = 1.5 (not supported, "
937 "using 1 stop bit)", __FUNCTION__);
938 bits &= ~BITS_STOP_MASK;
939 cp210x_set_config(port, CP2101_BITS, &bits, 2);
940 break;
941 case BITS_STOP_2:
942 dbg("%s - stop bits = 2", __FUNCTION__);
943 cflag |= CSTOPB;
944 break;
945 default:
946 dbg("%s - Unknown number of stop bits, "
947 "using 1 stop bit", __FUNCTION__);
948 bits &= ~BITS_STOP_MASK;
949 cp210x_set_config(port, CP2101_BITS, &bits, 2);
950 break;
951 }
952
953 cp210x_get_config(port, CP2101_MODEMCTL, modem_ctl, 16);
954 if (modem_ctl[0] & 0x0008) {
955 dbg("%s - flow control = CRTSCTS", __FUNCTION__);
956 cflag |= CRTSCTS;
957 } else {
958 dbg("%s - flow control = NONE", __FUNCTION__);
959 cflag &= ~CRTSCTS;
960 }
961
962 port->tty->termios->c_cflag = cflag;
963 }
964
965 static void cp210x_set_termios(struct usb_serial_port *port,
966 struct ktermios *old_termios)
967 {
968 unsigned int cflag, old_cflag;
969 int baud = 0, bits;
970 unsigned int modem_ctl[4];
971
972 dbg("%s - port %d", __FUNCTION__, port->number);
973
974 if (!port->tty || !port->tty->termios) {
975 dbg("%s - no tty structures", __FUNCTION__);
976 return;
977 }
978 port->tty->termios->c_cflag &= ~CMSPAR;
979
980 cflag = port->tty->termios->c_cflag;
981 old_cflag = old_termios->c_cflag;
982 baud = tty_get_baud_rate(port->tty);
983
984 /* If the baud rate is to be updated*/
985 if (baud != tty_termios_baud_rate(old_termios)) {
986 switch (baud) {
987 case 0:
988 case 600:
989 case 1200:
990 case 1800:
991 case 2400:
992 case 4800:
993 case 7200:
994 case 9600:
995 case 14400:
996 case 19200:
997 case 28800:
998 case 38400:
999 case 55854:
1000 case 57600:
1001 case 115200:
1002 case 127117:
1003 case 230400:
1004 case 460800:
1005 case 921600:
1006 case 3686400:
1007 break;
1008 default:
1009 baud = 9600;
1010 break;
1011 }
1012
1013 if (baud) {
1014 dbg("%s - Setting baud rate to %d baud", __FUNCTION__,
1015 baud);
1016 if (cp210x_set_config_single(port, CP2101_BAUDRATE,
1017 (BAUD_RATE_GEN_FREQ / baud))) {
1018 dev_err(&port->dev, "Baud rate requested not "
1019 "supported by device\n");
1020 baud = tty_termios_baud_rate(old_termios);
1021 }
1022 }
1023 }
1024 /* Report back the resulting baud rate */
1025 tty_encode_baud_rate(port->tty, baud, baud);
1026
1027 /* If the number of data bits is to be updated */
1028 if ((cflag & CSIZE) != (old_cflag & CSIZE)) {
1029 cp210x_get_config(port, CP2101_BITS, &bits, 2);
1030 bits &= ~BITS_DATA_MASK;
1031 switch (cflag & CSIZE) {
1032 case CS5:
1033 bits |= BITS_DATA_5;
1034 dbg("%s - data bits = 5", __FUNCTION__);
1035 break;
1036 case CS6:
1037 bits |= BITS_DATA_6;
1038 dbg("%s - data bits = 6", __FUNCTION__);
1039 break;
1040 case CS7:
1041 bits |= BITS_DATA_7;
1042 dbg("%s - data bits = 7", __FUNCTION__);
1043 break;
1044 case CS8:
1045 bits |= BITS_DATA_8;
1046 dbg("%s - data bits = 8", __FUNCTION__);
1047 break;
1048 /*case CS9:
1049 bits |= BITS_DATA_9;
1050 dbg("%s - data bits = 9", __FUNCTION__);
1051 break;*/
1052 default:
1053 dev_err(&port->dev, "cp210x driver does not "
1054 "support the number of bits requested,"
1055 " using 8 bit mode\n");
1056 bits |= BITS_DATA_8;
1057 break;
1058 }
1059 if (cp210x_set_config(port, CP2101_BITS, &bits, 2))
1060 dev_err(&port->dev, "Number of data bits requested "
1061 "not supported by device\n");
1062 }
1063
1064 if ((cflag & (PARENB|PARODD)) != (old_cflag & (PARENB|PARODD))) {
1065 cp210x_get_config(port, CP2101_BITS, &bits, 2);
1066 bits &= ~BITS_PARITY_MASK;
1067 if (cflag & PARENB) {
1068 if (cflag & PARODD) {
1069 bits |= BITS_PARITY_ODD;
1070 dbg("%s - parity = ODD", __FUNCTION__);
1071 } else {
1072 bits |= BITS_PARITY_EVEN;
1073 dbg("%s - parity = EVEN", __FUNCTION__);
1074 }
1075 }
1076 if (cp210x_set_config(port, CP2101_BITS, &bits, 2))
1077 dev_err(&port->dev, "Parity mode not supported "
1078 "by device\n");
1079 }
1080
1081 if ((cflag & CSTOPB) != (old_cflag & CSTOPB)) {
1082 cp210x_get_config(port, CP2101_BITS, &bits, 2);
1083 bits &= ~BITS_STOP_MASK;
1084 if (cflag & CSTOPB) {
1085 bits |= BITS_STOP_2;
1086 dbg("%s - stop bits = 2", __FUNCTION__);
1087 } else {
1088 bits |= BITS_STOP_1;
1089 dbg("%s - stop bits = 1", __FUNCTION__);
1090 }
1091 if (cp210x_set_config(port, CP2101_BITS, &bits, 2))
1092 dev_err(&port->dev, "Number of stop bits requested "
1093 "not supported by device\n");
1094 }
1095
1096 if ((cflag & CRTSCTS) != (old_cflag & CRTSCTS)) {
1097 cp210x_get_config(port, CP2101_MODEMCTL, modem_ctl, 16);
1098 dbg("%s - read modem controls = 0x%.4x 0x%.4x 0x%.4x 0x%.4x",
1099 __FUNCTION__, modem_ctl[0], modem_ctl[1],
1100 modem_ctl[2], modem_ctl[3]);
1101
1102 if (cflag & CRTSCTS) {
1103 modem_ctl[0] &= ~0x7B;
1104 modem_ctl[0] |= 0x09;
1105 modem_ctl[1] = 0x80;
1106 dbg("%s - flow control = CRTSCTS", __FUNCTION__);
1107 } else {
1108 modem_ctl[0] &= ~0x7B;
1109 modem_ctl[0] |= 0x01;
1110 modem_ctl[1] |= 0x40;
1111 dbg("%s - flow control = NONE", __FUNCTION__);
1112 }
1113
1114 dbg("%s - write modem controls = 0x%.4x 0x%.4x 0x%.4x 0x%.4x",
1115 __FUNCTION__, modem_ctl[0], modem_ctl[1],
1116 modem_ctl[2], modem_ctl[3]);
1117 cp210x_set_config(port, CP2101_MODEMCTL, modem_ctl, 16);
1118 }
1119
1120 }
1121
1122 static int cp210x_tiocmset(struct usb_serial_port *port, struct file *file,
1123 unsigned int set, unsigned int clear)
1124 {
1125 int control = 0;
1126
1127 dbg("%s - port %d", __FUNCTION__, port->number);
1128
1129 if (set & TIOCM_RTS) {
1130 control |= CONTROL_RTS;
1131 control |= CONTROL_WRITE_RTS;
1132 }
1133 if (set & TIOCM_DTR) {
1134 control |= CONTROL_DTR;
1135 control |= CONTROL_WRITE_DTR;
1136 }
1137 if (clear & TIOCM_RTS) {
1138 control &= ~CONTROL_RTS;
1139 control |= CONTROL_WRITE_RTS;
1140 }
1141 if (clear & TIOCM_DTR) {
1142 control &= ~CONTROL_DTR;
1143 control |= CONTROL_WRITE_DTR;
1144 }
1145
1146 dbg("%s - control = 0x%.4x", __FUNCTION__, control);
1147
1148 return cp210x_set_config(port, CP2101_CONTROL, &control, 2);
1149
1150 }
1151
1152 static int cp210x_tiocmget(struct usb_serial_port *port, struct file *file)
1153 {
1154 int control, result;
1155
1156 dbg("%s - port %d", __FUNCTION__, port->number);
1157
1158 cp210x_get_config(port, CP2101_CONTROL, &control, 1);
1159
1160 result = ((control & CONTROL_DTR) ? TIOCM_DTR : 0)
1161 |((control & CONTROL_RTS) ? TIOCM_RTS : 0)
1162 |((control & CONTROL_CTS) ? TIOCM_CTS : 0)
1163 |((control & CONTROL_DSR) ? TIOCM_DSR : 0)
1164 |((control & CONTROL_RING)? TIOCM_RI : 0)
1165 |((control & CONTROL_DCD) ? TIOCM_CD : 0);
1166
1167 dbg("%s - control = 0x%.2x", __FUNCTION__, control);
1168
1169 return result;
1170 }
1171
1172 static void cp210x_break_ctl(struct usb_serial_port *port, int break_state)
1173 {
1174 int state;
1175
1176 dbg("%s - port %d", __FUNCTION__, port->number);
1177 if (break_state == 0)
1178 state = BREAK_OFF;
1179 else
1180 state = BREAK_ON;
1181 dbg("%s - turning break %s", __FUNCTION__,
1182 state==BREAK_OFF ? "off" : "on");
1183 cp210x_set_config(port, CP2101_BREAK, &state, 2);
1184 }
1185
1186 static int cp210x_startup(struct usb_serial *serial)
1187 {
1188 /* CP2101 buffers behave strangely unless device is reset */
1189 usb_reset_device(serial->dev);
1190 return 0;
1191 }
1192
1193 static void cp210x_shutdown(struct usb_serial *serial)
1194 {
1195 int i;
1196
1197 dbg("%s", __FUNCTION__);
1198
1199 /* Stop reads and writes on all ports */
1200 for (i = 0; i < serial->num_ports; ++i) {
1201 cp210x_cleanup(serial->port[i]);
1202 }
1203 }
1204
1205 static int __init cp210x_init(void)
1206 {
1207 int retval;
1208
1209 retval = usb_serial_register(&cp210x_device);
1210 if (retval)
1211 return retval; /* Failed to register */
1212
1213 retval = usb_register(&cp210x_driver);
1214 if (retval) {
1215 /* Failed to register */
1216 usb_serial_deregister(&cp210x_device);
1217 return retval;
1218 }
1219
1220 /* Success */
1221 info(DRIVER_DESC " " DRIVER_VERSION);
1222 return 0;
1223 }
1224
1225 static void __exit cp210x_exit(void)
1226 {
1227 usb_deregister(&cp210x_driver);
1228 usb_serial_deregister(&cp210x_device);
1229 }
1230
1231 module_init(cp210x_init);
1232 module_exit(cp210x_exit);
1233
1234 MODULE_DESCRIPTION(DRIVER_DESC);
1235 MODULE_VERSION(DRIVER_VERSION);
1236 MODULE_LICENSE("GPL");
1237
1238 module_param(debug, bool, S_IRUGO | S_IWUSR);
1239 MODULE_PARM_DESC(debug, "Enable verbose debugging messages");