Driver Core: devtmpfs - kernel-maintained tmpfs-based /dev
[linux/fpc-iii.git] / drivers / usb / serial / kobil_sct.c
blob6db0e561f6805c25a032797ffd1e25bf57c5fa18
1 /*
2 * KOBIL USB Smart Card Terminal Driver
4 * Copyright (C) 2002 KOBIL Systems GmbH
5 * Author: Thomas Wahrenbruch
7 * Contact: linuxusb@kobil.de
9 * This program is largely derived from work by the linux-usb group
10 * and associated source files. Please see the usb/serial files for
11 * individual credits and copyrights.
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
18 * Thanks to Greg Kroah-Hartman (greg@kroah.com) for his help and
19 * patience.
21 * Supported readers: USB TWIN, KAAN Standard Plus and SecOVID Reader Plus
22 * (Adapter K), B1 Professional and KAAN Professional (Adapter B)
24 * (21/05/2004) tw
25 * Fix bug with P'n'P readers
27 * (28/05/2003) tw
28 * Add support for KAAN SIM
30 * (12/09/2002) tw
31 * Adapted to 2.5.
33 * (11/08/2002) tw
34 * Initial version.
38 #include <linux/kernel.h>
39 #include <linux/errno.h>
40 #include <linux/init.h>
41 #include <linux/slab.h>
42 #include <linux/tty.h>
43 #include <linux/tty_driver.h>
44 #include <linux/tty_flip.h>
45 #include <linux/module.h>
46 #include <linux/spinlock.h>
47 #include <linux/uaccess.h>
48 #include <linux/usb.h>
49 #include <linux/usb/serial.h>
50 #include <linux/ioctl.h>
51 #include "kobil_sct.h"
53 static int debug;
55 /* Version Information */
56 #define DRIVER_VERSION "21/05/2004"
57 #define DRIVER_AUTHOR "KOBIL Systems GmbH - http://www.kobil.com"
58 #define DRIVER_DESC "KOBIL USB Smart Card Terminal Driver (experimental)"
60 #define KOBIL_VENDOR_ID 0x0D46
61 #define KOBIL_ADAPTER_B_PRODUCT_ID 0x2011
62 #define KOBIL_ADAPTER_K_PRODUCT_ID 0x2012
63 #define KOBIL_USBTWIN_PRODUCT_ID 0x0078
64 #define KOBIL_KAAN_SIM_PRODUCT_ID 0x0081
66 #define KOBIL_TIMEOUT 500
67 #define KOBIL_BUF_LENGTH 300
70 /* Function prototypes */
71 static int kobil_startup(struct usb_serial *serial);
72 static void kobil_release(struct usb_serial *serial);
73 static int kobil_open(struct tty_struct *tty,
74 struct usb_serial_port *port, struct file *filp);
75 static void kobil_close(struct usb_serial_port *port);
76 static int kobil_write(struct tty_struct *tty, struct usb_serial_port *port,
77 const unsigned char *buf, int count);
78 static int kobil_write_room(struct tty_struct *tty);
79 static int kobil_ioctl(struct tty_struct *tty, struct file *file,
80 unsigned int cmd, unsigned long arg);
81 static int kobil_tiocmget(struct tty_struct *tty, struct file *file);
82 static int kobil_tiocmset(struct tty_struct *tty, struct file *file,
83 unsigned int set, unsigned int clear);
84 static void kobil_read_int_callback(struct urb *urb);
85 static void kobil_write_callback(struct urb *purb);
86 static void kobil_set_termios(struct tty_struct *tty,
87 struct usb_serial_port *port, struct ktermios *old);
90 static struct usb_device_id id_table [] = {
91 { USB_DEVICE(KOBIL_VENDOR_ID, KOBIL_ADAPTER_B_PRODUCT_ID) },
92 { USB_DEVICE(KOBIL_VENDOR_ID, KOBIL_ADAPTER_K_PRODUCT_ID) },
93 { USB_DEVICE(KOBIL_VENDOR_ID, KOBIL_USBTWIN_PRODUCT_ID) },
94 { USB_DEVICE(KOBIL_VENDOR_ID, KOBIL_KAAN_SIM_PRODUCT_ID) },
95 { } /* Terminating entry */
99 MODULE_DEVICE_TABLE(usb, id_table);
101 static struct usb_driver kobil_driver = {
102 .name = "kobil",
103 .probe = usb_serial_probe,
104 .disconnect = usb_serial_disconnect,
105 .id_table = id_table,
106 .no_dynamic_id = 1,
110 static struct usb_serial_driver kobil_device = {
111 .driver = {
112 .owner = THIS_MODULE,
113 .name = "kobil",
115 .description = "KOBIL USB smart card terminal",
116 .usb_driver = &kobil_driver,
117 .id_table = id_table,
118 .num_ports = 1,
119 .attach = kobil_startup,
120 .release = kobil_release,
121 .ioctl = kobil_ioctl,
122 .set_termios = kobil_set_termios,
123 .tiocmget = kobil_tiocmget,
124 .tiocmset = kobil_tiocmset,
125 .open = kobil_open,
126 .close = kobil_close,
127 .write = kobil_write,
128 .write_room = kobil_write_room,
129 .read_int_callback = kobil_read_int_callback,
133 struct kobil_private {
134 int write_int_endpoint_address;
135 int read_int_endpoint_address;
136 unsigned char buf[KOBIL_BUF_LENGTH]; /* buffer for the APDU to send */
137 int filled; /* index of the last char in buf */
138 int cur_pos; /* index of the next char to send in buf */
139 __u16 device_type;
143 static int kobil_startup(struct usb_serial *serial)
145 int i;
146 struct kobil_private *priv;
147 struct usb_device *pdev;
148 struct usb_host_config *actconfig;
149 struct usb_interface *interface;
150 struct usb_host_interface *altsetting;
151 struct usb_host_endpoint *endpoint;
153 priv = kmalloc(sizeof(struct kobil_private), GFP_KERNEL);
154 if (!priv)
155 return -ENOMEM;
157 priv->filled = 0;
158 priv->cur_pos = 0;
159 priv->device_type = le16_to_cpu(serial->dev->descriptor.idProduct);
161 switch (priv->device_type) {
162 case KOBIL_ADAPTER_B_PRODUCT_ID:
163 printk(KERN_DEBUG "KOBIL B1 PRO / KAAN PRO detected\n");
164 break;
165 case KOBIL_ADAPTER_K_PRODUCT_ID:
166 printk(KERN_DEBUG
167 "KOBIL KAAN Standard Plus / SecOVID Reader Plus detected\n");
168 break;
169 case KOBIL_USBTWIN_PRODUCT_ID:
170 printk(KERN_DEBUG "KOBIL USBTWIN detected\n");
171 break;
172 case KOBIL_KAAN_SIM_PRODUCT_ID:
173 printk(KERN_DEBUG "KOBIL KAAN SIM detected\n");
174 break;
176 usb_set_serial_port_data(serial->port[0], priv);
178 /* search for the necessary endpoints */
179 pdev = serial->dev;
180 actconfig = pdev->actconfig;
181 interface = actconfig->interface[0];
182 altsetting = interface->cur_altsetting;
183 endpoint = altsetting->endpoint;
185 for (i = 0; i < altsetting->desc.bNumEndpoints; i++) {
186 endpoint = &altsetting->endpoint[i];
187 if (usb_endpoint_is_int_out(&endpoint->desc)) {
188 dbg("%s Found interrupt out endpoint. Address: %d",
189 __func__, endpoint->desc.bEndpointAddress);
190 priv->write_int_endpoint_address =
191 endpoint->desc.bEndpointAddress;
193 if (usb_endpoint_is_int_in(&endpoint->desc)) {
194 dbg("%s Found interrupt in endpoint. Address: %d",
195 __func__, endpoint->desc.bEndpointAddress);
196 priv->read_int_endpoint_address =
197 endpoint->desc.bEndpointAddress;
200 return 0;
204 static void kobil_release(struct usb_serial *serial)
206 int i;
207 dbg("%s - port %d", __func__, serial->port[0]->number);
209 for (i = 0; i < serial->num_ports; ++i)
210 kfree(usb_get_serial_port_data(serial->port[i]));
214 static int kobil_open(struct tty_struct *tty,
215 struct usb_serial_port *port, struct file *filp)
217 int result = 0;
218 struct kobil_private *priv;
219 unsigned char *transfer_buffer;
220 int transfer_buffer_length = 8;
221 int write_urb_transfer_buffer_length = 8;
223 dbg("%s - port %d", __func__, port->number);
224 priv = usb_get_serial_port_data(port);
226 /* someone sets the dev to 0 if the close method has been called */
227 port->interrupt_in_urb->dev = port->serial->dev;
229 if (tty) {
231 /* Default to echo off and other sane device settings */
232 tty->termios->c_lflag = 0;
233 tty->termios->c_lflag &= ~(ISIG | ICANON | ECHO | IEXTEN |
234 XCASE);
235 tty->termios->c_iflag = IGNBRK | IGNPAR | IXOFF;
236 /* do NOT translate CR to CR-NL (0x0A -> 0x0A 0x0D) */
237 tty->termios->c_oflag &= ~ONLCR;
239 /* allocate memory for transfer buffer */
240 transfer_buffer = kzalloc(transfer_buffer_length, GFP_KERNEL);
241 if (!transfer_buffer)
242 return -ENOMEM;
244 /* allocate write_urb */
245 if (!port->write_urb) {
246 dbg("%s - port %d Allocating port->write_urb",
247 __func__, port->number);
248 port->write_urb = usb_alloc_urb(0, GFP_KERNEL);
249 if (!port->write_urb) {
250 dbg("%s - port %d usb_alloc_urb failed",
251 __func__, port->number);
252 kfree(transfer_buffer);
253 return -ENOMEM;
257 /* allocate memory for write_urb transfer buffer */
258 port->write_urb->transfer_buffer =
259 kmalloc(write_urb_transfer_buffer_length, GFP_KERNEL);
260 if (!port->write_urb->transfer_buffer) {
261 kfree(transfer_buffer);
262 usb_free_urb(port->write_urb);
263 port->write_urb = NULL;
264 return -ENOMEM;
267 /* get hardware version */
268 result = usb_control_msg(port->serial->dev,
269 usb_rcvctrlpipe(port->serial->dev, 0),
270 SUSBCRequest_GetMisc,
271 USB_TYPE_VENDOR | USB_RECIP_ENDPOINT | USB_DIR_IN,
272 SUSBCR_MSC_GetHWVersion,
274 transfer_buffer,
275 transfer_buffer_length,
276 KOBIL_TIMEOUT
278 dbg("%s - port %d Send get_HW_version URB returns: %i",
279 __func__, port->number, result);
280 dbg("Harware version: %i.%i.%i",
281 transfer_buffer[0], transfer_buffer[1], transfer_buffer[2]);
283 /* get firmware version */
284 result = usb_control_msg(port->serial->dev,
285 usb_rcvctrlpipe(port->serial->dev, 0),
286 SUSBCRequest_GetMisc,
287 USB_TYPE_VENDOR | USB_RECIP_ENDPOINT | USB_DIR_IN,
288 SUSBCR_MSC_GetFWVersion,
290 transfer_buffer,
291 transfer_buffer_length,
292 KOBIL_TIMEOUT
294 dbg("%s - port %d Send get_FW_version URB returns: %i",
295 __func__, port->number, result);
296 dbg("Firmware version: %i.%i.%i",
297 transfer_buffer[0], transfer_buffer[1], transfer_buffer[2]);
299 if (priv->device_type == KOBIL_ADAPTER_B_PRODUCT_ID ||
300 priv->device_type == KOBIL_ADAPTER_K_PRODUCT_ID) {
301 /* Setting Baudrate, Parity and Stopbits */
302 result = usb_control_msg(port->serial->dev,
303 usb_rcvctrlpipe(port->serial->dev, 0),
304 SUSBCRequest_SetBaudRateParityAndStopBits,
305 USB_TYPE_VENDOR | USB_RECIP_ENDPOINT | USB_DIR_OUT,
306 SUSBCR_SBR_9600 | SUSBCR_SPASB_EvenParity |
307 SUSBCR_SPASB_1StopBit,
309 transfer_buffer,
311 KOBIL_TIMEOUT
313 dbg("%s - port %d Send set_baudrate URB returns: %i",
314 __func__, port->number, result);
316 /* reset all queues */
317 result = usb_control_msg(port->serial->dev,
318 usb_rcvctrlpipe(port->serial->dev, 0),
319 SUSBCRequest_Misc,
320 USB_TYPE_VENDOR | USB_RECIP_ENDPOINT | USB_DIR_OUT,
321 SUSBCR_MSC_ResetAllQueues,
323 transfer_buffer,
325 KOBIL_TIMEOUT
327 dbg("%s - port %d Send reset_all_queues URB returns: %i",
328 __func__, port->number, result);
330 if (priv->device_type == KOBIL_USBTWIN_PRODUCT_ID ||
331 priv->device_type == KOBIL_ADAPTER_B_PRODUCT_ID ||
332 priv->device_type == KOBIL_KAAN_SIM_PRODUCT_ID) {
333 /* start reading (Adapter B 'cause PNP string) */
334 result = usb_submit_urb(port->interrupt_in_urb, GFP_ATOMIC);
335 dbg("%s - port %d Send read URB returns: %i",
336 __func__, port->number, result);
339 kfree(transfer_buffer);
340 return 0;
344 static void kobil_close(struct usb_serial_port *port)
346 dbg("%s - port %d", __func__, port->number);
348 /* FIXME: Add rts/dtr methods */
349 if (port->write_urb) {
350 usb_kill_urb(port->write_urb);
351 usb_free_urb(port->write_urb);
352 port->write_urb = NULL;
354 usb_kill_urb(port->interrupt_in_urb);
358 static void kobil_read_int_callback(struct urb *urb)
360 int result;
361 struct usb_serial_port *port = urb->context;
362 struct tty_struct *tty;
363 unsigned char *data = urb->transfer_buffer;
364 int status = urb->status;
365 /* char *dbg_data; */
367 dbg("%s - port %d", __func__, port->number);
369 if (status) {
370 dbg("%s - port %d Read int status not zero: %d",
371 __func__, port->number, status);
372 return;
375 tty = tty_port_tty_get(&port->port);
376 if (urb->actual_length) {
378 /* BEGIN DEBUG */
380 dbg_data = kzalloc((3 * purb->actual_length + 10)
381 * sizeof(char), GFP_KERNEL);
382 if (! dbg_data) {
383 return;
385 for (i = 0; i < purb->actual_length; i++) {
386 sprintf(dbg_data +3*i, "%02X ", data[i]);
388 dbg(" <-- %s", dbg_data);
389 kfree(dbg_data);
391 /* END DEBUG */
393 tty_buffer_request_room(tty, urb->actual_length);
394 tty_insert_flip_string(tty, data, urb->actual_length);
395 tty_flip_buffer_push(tty);
397 tty_kref_put(tty);
398 /* someone sets the dev to 0 if the close method has been called */
399 port->interrupt_in_urb->dev = port->serial->dev;
401 result = usb_submit_urb(port->interrupt_in_urb, GFP_ATOMIC);
402 dbg("%s - port %d Send read URB returns: %i",
403 __func__, port->number, result);
407 static void kobil_write_callback(struct urb *purb)
412 static int kobil_write(struct tty_struct *tty, struct usb_serial_port *port,
413 const unsigned char *buf, int count)
415 int length = 0;
416 int result = 0;
417 int todo = 0;
418 struct kobil_private *priv;
420 if (count == 0) {
421 dbg("%s - port %d write request of 0 bytes",
422 __func__, port->number);
423 return 0;
426 priv = usb_get_serial_port_data(port);
428 if (count > (KOBIL_BUF_LENGTH - priv->filled)) {
429 dbg("%s - port %d Error: write request bigger than buffer size", __func__, port->number);
430 return -ENOMEM;
433 /* Copy data to buffer */
434 memcpy(priv->buf + priv->filled, buf, count);
435 usb_serial_debug_data(debug, &port->dev, __func__, count,
436 priv->buf + priv->filled);
437 priv->filled = priv->filled + count;
439 /* only send complete block. TWIN, KAAN SIM and adapter K
440 use the same protocol. */
441 if (((priv->device_type != KOBIL_ADAPTER_B_PRODUCT_ID) && (priv->filled > 2) && (priv->filled >= (priv->buf[1] + 3))) ||
442 ((priv->device_type == KOBIL_ADAPTER_B_PRODUCT_ID) && (priv->filled > 3) && (priv->filled >= (priv->buf[2] + 4)))) {
443 /* stop reading (except TWIN and KAAN SIM) */
444 if ((priv->device_type == KOBIL_ADAPTER_B_PRODUCT_ID)
445 || (priv->device_type == KOBIL_ADAPTER_K_PRODUCT_ID))
446 usb_kill_urb(port->interrupt_in_urb);
448 todo = priv->filled - priv->cur_pos;
450 while (todo > 0) {
451 /* max 8 byte in one urb (endpoint size) */
452 length = (todo < 8) ? todo : 8;
453 /* copy data to transfer buffer */
454 memcpy(port->write_urb->transfer_buffer,
455 priv->buf + priv->cur_pos, length);
456 usb_fill_int_urb(port->write_urb,
457 port->serial->dev,
458 usb_sndintpipe(port->serial->dev,
459 priv->write_int_endpoint_address),
460 port->write_urb->transfer_buffer,
461 length,
462 kobil_write_callback,
463 port,
467 priv->cur_pos = priv->cur_pos + length;
468 result = usb_submit_urb(port->write_urb, GFP_NOIO);
469 dbg("%s - port %d Send write URB returns: %i",
470 __func__, port->number, result);
471 todo = priv->filled - priv->cur_pos;
473 if (todo > 0)
474 msleep(24);
477 priv->filled = 0;
478 priv->cur_pos = 0;
480 /* someone sets the dev to 0 if the close method
481 has been called */
482 port->interrupt_in_urb->dev = port->serial->dev;
484 /* start reading (except TWIN and KAAN SIM) */
485 if (priv->device_type == KOBIL_ADAPTER_B_PRODUCT_ID ||
486 priv->device_type == KOBIL_ADAPTER_K_PRODUCT_ID) {
487 /* someone sets the dev to 0 if the close method has
488 been called */
489 port->interrupt_in_urb->dev = port->serial->dev;
491 result = usb_submit_urb(port->interrupt_in_urb,
492 GFP_NOIO);
493 dbg("%s - port %d Send read URB returns: %i",
494 __func__, port->number, result);
497 return count;
501 static int kobil_write_room(struct tty_struct *tty)
503 /* dbg("%s - port %d", __func__, port->number); */
504 /* FIXME */
505 return 8;
509 static int kobil_tiocmget(struct tty_struct *tty, struct file *file)
511 struct usb_serial_port *port = tty->driver_data;
512 struct kobil_private *priv;
513 int result;
514 unsigned char *transfer_buffer;
515 int transfer_buffer_length = 8;
517 priv = usb_get_serial_port_data(port);
518 if (priv->device_type == KOBIL_USBTWIN_PRODUCT_ID
519 || priv->device_type == KOBIL_KAAN_SIM_PRODUCT_ID) {
520 /* This device doesn't support ioctl calls */
521 return -EINVAL;
524 /* allocate memory for transfer buffer */
525 transfer_buffer = kzalloc(transfer_buffer_length, GFP_KERNEL);
526 if (!transfer_buffer)
527 return -ENOMEM;
529 result = usb_control_msg(port->serial->dev,
530 usb_rcvctrlpipe(port->serial->dev, 0),
531 SUSBCRequest_GetStatusLineState,
532 USB_TYPE_VENDOR | USB_RECIP_ENDPOINT | USB_DIR_IN,
535 transfer_buffer,
536 transfer_buffer_length,
537 KOBIL_TIMEOUT);
539 dbg("%s - port %d Send get_status_line_state URB returns: %i. Statusline: %02x",
540 __func__, port->number, result, transfer_buffer[0]);
542 result = 0;
543 if ((transfer_buffer[0] & SUSBCR_GSL_DSR) != 0)
544 result = TIOCM_DSR;
545 kfree(transfer_buffer);
546 return result;
549 static int kobil_tiocmset(struct tty_struct *tty, struct file *file,
550 unsigned int set, unsigned int clear)
552 struct usb_serial_port *port = tty->driver_data;
553 struct kobil_private *priv;
554 int result;
555 int dtr = 0;
556 int rts = 0;
557 unsigned char *transfer_buffer;
558 int transfer_buffer_length = 8;
560 /* FIXME: locking ? */
561 priv = usb_get_serial_port_data(port);
562 if (priv->device_type == KOBIL_USBTWIN_PRODUCT_ID
563 || priv->device_type == KOBIL_KAAN_SIM_PRODUCT_ID) {
564 /* This device doesn't support ioctl calls */
565 return -EINVAL;
568 /* allocate memory for transfer buffer */
569 transfer_buffer = kzalloc(transfer_buffer_length, GFP_KERNEL);
570 if (!transfer_buffer)
571 return -ENOMEM;
573 if (set & TIOCM_RTS)
574 rts = 1;
575 if (set & TIOCM_DTR)
576 dtr = 1;
577 if (clear & TIOCM_RTS)
578 rts = 0;
579 if (clear & TIOCM_DTR)
580 dtr = 0;
582 if (priv->device_type == KOBIL_ADAPTER_B_PRODUCT_ID) {
583 if (dtr != 0)
584 dbg("%s - port %d Setting DTR",
585 __func__, port->number);
586 else
587 dbg("%s - port %d Clearing DTR",
588 __func__, port->number);
589 result = usb_control_msg(port->serial->dev,
590 usb_rcvctrlpipe(port->serial->dev, 0),
591 SUSBCRequest_SetStatusLinesOrQueues,
592 USB_TYPE_VENDOR | USB_RECIP_ENDPOINT | USB_DIR_OUT,
593 ((dtr != 0) ? SUSBCR_SSL_SETDTR : SUSBCR_SSL_CLRDTR),
595 transfer_buffer,
597 KOBIL_TIMEOUT);
598 } else {
599 if (rts != 0)
600 dbg("%s - port %d Setting RTS",
601 __func__, port->number);
602 else
603 dbg("%s - port %d Clearing RTS",
604 __func__, port->number);
605 result = usb_control_msg(port->serial->dev,
606 usb_rcvctrlpipe(port->serial->dev, 0),
607 SUSBCRequest_SetStatusLinesOrQueues,
608 USB_TYPE_VENDOR | USB_RECIP_ENDPOINT | USB_DIR_OUT,
609 ((rts != 0) ? SUSBCR_SSL_SETRTS : SUSBCR_SSL_CLRRTS),
611 transfer_buffer,
613 KOBIL_TIMEOUT);
615 dbg("%s - port %d Send set_status_line URB returns: %i",
616 __func__, port->number, result);
617 kfree(transfer_buffer);
618 return (result < 0) ? result : 0;
621 static void kobil_set_termios(struct tty_struct *tty,
622 struct usb_serial_port *port, struct ktermios *old)
624 struct kobil_private *priv;
625 int result;
626 unsigned short urb_val = 0;
627 int c_cflag = tty->termios->c_cflag;
628 speed_t speed;
629 void *settings;
631 priv = usb_get_serial_port_data(port);
632 if (priv->device_type == KOBIL_USBTWIN_PRODUCT_ID ||
633 priv->device_type == KOBIL_KAAN_SIM_PRODUCT_ID) {
634 /* This device doesn't support ioctl calls */
635 *tty->termios = *old;
636 return;
639 speed = tty_get_baud_rate(tty);
640 switch (speed) {
641 case 1200:
642 urb_val = SUSBCR_SBR_1200;
643 break;
644 default:
645 speed = 9600;
646 case 9600:
647 urb_val = SUSBCR_SBR_9600;
648 break;
650 urb_val |= (c_cflag & CSTOPB) ? SUSBCR_SPASB_2StopBits :
651 SUSBCR_SPASB_1StopBit;
653 settings = kzalloc(50, GFP_KERNEL);
654 if (!settings)
655 return;
657 sprintf(settings, "%d ", speed);
659 if (c_cflag & PARENB) {
660 if (c_cflag & PARODD) {
661 urb_val |= SUSBCR_SPASB_OddParity;
662 strcat(settings, "Odd Parity");
663 } else {
664 urb_val |= SUSBCR_SPASB_EvenParity;
665 strcat(settings, "Even Parity");
667 } else {
668 urb_val |= SUSBCR_SPASB_NoParity;
669 strcat(settings, "No Parity");
671 tty->termios->c_cflag &= ~CMSPAR;
672 tty_encode_baud_rate(tty, speed, speed);
674 result = usb_control_msg(port->serial->dev,
675 usb_rcvctrlpipe(port->serial->dev, 0),
676 SUSBCRequest_SetBaudRateParityAndStopBits,
677 USB_TYPE_VENDOR | USB_RECIP_ENDPOINT | USB_DIR_OUT,
678 urb_val,
680 settings,
682 KOBIL_TIMEOUT
684 kfree(settings);
687 static int kobil_ioctl(struct tty_struct *tty, struct file *file,
688 unsigned int cmd, unsigned long arg)
690 struct usb_serial_port *port = tty->driver_data;
691 struct kobil_private *priv = usb_get_serial_port_data(port);
692 unsigned char *transfer_buffer;
693 int transfer_buffer_length = 8;
694 int result;
696 if (priv->device_type == KOBIL_USBTWIN_PRODUCT_ID ||
697 priv->device_type == KOBIL_KAAN_SIM_PRODUCT_ID)
698 /* This device doesn't support ioctl calls */
699 return -ENOIOCTLCMD;
701 switch (cmd) {
702 case TCFLSH:
703 transfer_buffer = kmalloc(transfer_buffer_length, GFP_KERNEL);
704 if (!transfer_buffer)
705 return -ENOBUFS;
707 result = usb_control_msg(port->serial->dev,
708 usb_rcvctrlpipe(port->serial->dev, 0),
709 SUSBCRequest_Misc,
710 USB_TYPE_VENDOR | USB_RECIP_ENDPOINT | USB_DIR_OUT,
711 SUSBCR_MSC_ResetAllQueues,
713 NULL, /* transfer_buffer, */
715 KOBIL_TIMEOUT
718 dbg("%s - port %d Send reset_all_queues (FLUSH) URB returns: %i", __func__, port->number, result);
719 kfree(transfer_buffer);
720 return (result < 0) ? -EIO: 0;
721 default:
722 return -ENOIOCTLCMD;
726 static int __init kobil_init(void)
728 int retval;
729 retval = usb_serial_register(&kobil_device);
730 if (retval)
731 goto failed_usb_serial_register;
732 retval = usb_register(&kobil_driver);
733 if (retval)
734 goto failed_usb_register;
736 printk(KERN_INFO KBUILD_MODNAME ": " DRIVER_VERSION ":"
737 DRIVER_DESC "\n");
739 return 0;
740 failed_usb_register:
741 usb_serial_deregister(&kobil_device);
742 failed_usb_serial_register:
743 return retval;
747 static void __exit kobil_exit(void)
749 usb_deregister(&kobil_driver);
750 usb_serial_deregister(&kobil_device);
753 module_init(kobil_init);
754 module_exit(kobil_exit);
756 MODULE_AUTHOR(DRIVER_AUTHOR);
757 MODULE_DESCRIPTION(DRIVER_DESC);
758 MODULE_LICENSE("GPL");
760 module_param(debug, bool, S_IRUGO | S_IWUSR);
761 MODULE_PARM_DESC(debug, "Debug enabled or not");