Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * KOBIL USB Smart Card Terminal Driver |
| 3 | * |
Alan Cox | dee0a7c | 2008-07-22 11:14:10 +0100 | [diff] [blame] | 4 | * Copyright (C) 2002 KOBIL Systems GmbH |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5 | * Author: Thomas Wahrenbruch |
| 6 | * |
| 7 | * Contact: linuxusb@kobil.de |
| 8 | * |
| 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. |
| 12 | * |
| 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. |
| 17 | * |
| 18 | * Thanks to Greg Kroah-Hartman (greg@kroah.com) for his help and |
| 19 | * patience. |
| 20 | * |
| 21 | * Supported readers: USB TWIN, KAAN Standard Plus and SecOVID Reader Plus |
| 22 | * (Adapter K), B1 Professional and KAAN Professional (Adapter B) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | */ |
| 24 | |
| 25 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | #include <linux/kernel.h> |
| 27 | #include <linux/errno.h> |
| 28 | #include <linux/init.h> |
| 29 | #include <linux/slab.h> |
| 30 | #include <linux/tty.h> |
| 31 | #include <linux/tty_driver.h> |
| 32 | #include <linux/tty_flip.h> |
| 33 | #include <linux/module.h> |
| 34 | #include <linux/spinlock.h> |
Alan Cox | dee0a7c | 2008-07-22 11:14:10 +0100 | [diff] [blame] | 35 | #include <linux/uaccess.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | #include <linux/usb.h> |
Greg Kroah-Hartman | a969888 | 2006-07-11 21:22:58 -0700 | [diff] [blame] | 37 | #include <linux/usb/serial.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | #include <linux/ioctl.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | #include "kobil_sct.h" |
| 40 | |
Felipe Balbi | 3297f86 | 2012-01-24 10:18:10 +0200 | [diff] [blame] | 41 | static bool debug; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | |
| 43 | /* Version Information */ |
| 44 | #define DRIVER_VERSION "21/05/2004" |
| 45 | #define DRIVER_AUTHOR "KOBIL Systems GmbH - http://www.kobil.com" |
| 46 | #define DRIVER_DESC "KOBIL USB Smart Card Terminal Driver (experimental)" |
| 47 | |
| 48 | #define KOBIL_VENDOR_ID 0x0D46 |
| 49 | #define KOBIL_ADAPTER_B_PRODUCT_ID 0x2011 |
| 50 | #define KOBIL_ADAPTER_K_PRODUCT_ID 0x2012 |
| 51 | #define KOBIL_USBTWIN_PRODUCT_ID 0x0078 |
| 52 | #define KOBIL_KAAN_SIM_PRODUCT_ID 0x0081 |
| 53 | |
| 54 | #define KOBIL_TIMEOUT 500 |
| 55 | #define KOBIL_BUF_LENGTH 300 |
| 56 | |
| 57 | |
| 58 | /* Function prototypes */ |
Alan Cox | dee0a7c | 2008-07-22 11:14:10 +0100 | [diff] [blame] | 59 | static int kobil_startup(struct usb_serial *serial); |
Alan Stern | f9c99bb | 2009-06-02 11:53:55 -0400 | [diff] [blame] | 60 | static void kobil_release(struct usb_serial *serial); |
Alan Cox | a509a7e | 2009-09-19 13:13:26 -0700 | [diff] [blame] | 61 | static int kobil_open(struct tty_struct *tty, struct usb_serial_port *port); |
Alan Cox | 335f851 | 2009-06-11 12:26:29 +0100 | [diff] [blame] | 62 | static void kobil_close(struct usb_serial_port *port); |
Alan Cox | dee0a7c | 2008-07-22 11:14:10 +0100 | [diff] [blame] | 63 | static int kobil_write(struct tty_struct *tty, struct usb_serial_port *port, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | const unsigned char *buf, int count); |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 65 | static int kobil_write_room(struct tty_struct *tty); |
Alan Cox | 00a0d0d | 2011-02-14 16:27:06 +0000 | [diff] [blame] | 66 | static int kobil_ioctl(struct tty_struct *tty, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | unsigned int cmd, unsigned long arg); |
Alan Cox | 60b33c1 | 2011-02-14 16:26:14 +0000 | [diff] [blame] | 68 | static int kobil_tiocmget(struct tty_struct *tty); |
Alan Cox | 20b9d17 | 2011-02-14 16:26:50 +0000 | [diff] [blame] | 69 | static int kobil_tiocmset(struct tty_struct *tty, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | unsigned int set, unsigned int clear); |
Alan Cox | dee0a7c | 2008-07-22 11:14:10 +0100 | [diff] [blame] | 71 | static void kobil_read_int_callback(struct urb *urb); |
| 72 | static void kobil_write_callback(struct urb *purb); |
| 73 | static void kobil_set_termios(struct tty_struct *tty, |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 74 | struct usb_serial_port *port, struct ktermios *old); |
Alan Cox | fe1ae7f | 2009-09-19 13:13:33 -0700 | [diff] [blame] | 75 | static void kobil_init_termios(struct tty_struct *tty); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 | |
Németh Márton | 7d40d7e | 2010-01-10 15:34:24 +0100 | [diff] [blame] | 77 | static const struct usb_device_id id_table[] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 78 | { USB_DEVICE(KOBIL_VENDOR_ID, KOBIL_ADAPTER_B_PRODUCT_ID) }, |
| 79 | { USB_DEVICE(KOBIL_VENDOR_ID, KOBIL_ADAPTER_K_PRODUCT_ID) }, |
| 80 | { USB_DEVICE(KOBIL_VENDOR_ID, KOBIL_USBTWIN_PRODUCT_ID) }, |
| 81 | { USB_DEVICE(KOBIL_VENDOR_ID, KOBIL_KAAN_SIM_PRODUCT_ID) }, |
| 82 | { } /* Terminating entry */ |
| 83 | }; |
| 84 | |
| 85 | |
Alan Cox | dee0a7c | 2008-07-22 11:14:10 +0100 | [diff] [blame] | 86 | MODULE_DEVICE_TABLE(usb, id_table); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 87 | |
| 88 | static struct usb_driver kobil_driver = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | .name = "kobil", |
| 90 | .probe = usb_serial_probe, |
| 91 | .disconnect = usb_serial_disconnect, |
| 92 | .id_table = id_table, |
| 93 | }; |
| 94 | |
| 95 | |
Greg Kroah-Hartman | ea65370 | 2005-06-20 21:15:16 -0700 | [diff] [blame] | 96 | static struct usb_serial_driver kobil_device = { |
Greg Kroah-Hartman | 18fcac3 | 2005-06-20 21:15:16 -0700 | [diff] [blame] | 97 | .driver = { |
| 98 | .owner = THIS_MODULE, |
Greg Kroah-Hartman | 269bda1 | 2005-06-20 21:15:16 -0700 | [diff] [blame] | 99 | .name = "kobil", |
Greg Kroah-Hartman | 18fcac3 | 2005-06-20 21:15:16 -0700 | [diff] [blame] | 100 | }, |
Greg Kroah-Hartman | 269bda1 | 2005-06-20 21:15:16 -0700 | [diff] [blame] | 101 | .description = "KOBIL USB smart card terminal", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 102 | .id_table = id_table, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 103 | .num_ports = 1, |
| 104 | .attach = kobil_startup, |
Alan Stern | f9c99bb | 2009-06-02 11:53:55 -0400 | [diff] [blame] | 105 | .release = kobil_release, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 106 | .ioctl = kobil_ioctl, |
Alan Cox | 94d0f7e | 2007-08-22 23:09:16 +0100 | [diff] [blame] | 107 | .set_termios = kobil_set_termios, |
Alan Cox | fe1ae7f | 2009-09-19 13:13:33 -0700 | [diff] [blame] | 108 | .init_termios = kobil_init_termios, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 109 | .tiocmget = kobil_tiocmget, |
| 110 | .tiocmset = kobil_tiocmset, |
| 111 | .open = kobil_open, |
| 112 | .close = kobil_close, |
| 113 | .write = kobil_write, |
| 114 | .write_room = kobil_write_room, |
| 115 | .read_int_callback = kobil_read_int_callback, |
| 116 | }; |
| 117 | |
Alan Stern | 4d2a7af | 2012-02-23 14:57:09 -0500 | [diff] [blame] | 118 | static struct usb_serial_driver * const serial_drivers[] = { |
| 119 | &kobil_device, NULL |
| 120 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 121 | |
| 122 | struct kobil_private { |
| 123 | int write_int_endpoint_address; |
| 124 | int read_int_endpoint_address; |
Alan Cox | dee0a7c | 2008-07-22 11:14:10 +0100 | [diff] [blame] | 125 | unsigned char buf[KOBIL_BUF_LENGTH]; /* buffer for the APDU to send */ |
| 126 | int filled; /* index of the last char in buf */ |
| 127 | int cur_pos; /* index of the next char to send in buf */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 128 | __u16 device_type; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 129 | }; |
| 130 | |
| 131 | |
Alan Cox | dee0a7c | 2008-07-22 11:14:10 +0100 | [diff] [blame] | 132 | static int kobil_startup(struct usb_serial *serial) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 133 | { |
| 134 | int i; |
| 135 | struct kobil_private *priv; |
| 136 | struct usb_device *pdev; |
| 137 | struct usb_host_config *actconfig; |
| 138 | struct usb_interface *interface; |
| 139 | struct usb_host_interface *altsetting; |
| 140 | struct usb_host_endpoint *endpoint; |
| 141 | |
| 142 | priv = kmalloc(sizeof(struct kobil_private), GFP_KERNEL); |
Alan Cox | dee0a7c | 2008-07-22 11:14:10 +0100 | [diff] [blame] | 143 | if (!priv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 145 | |
| 146 | priv->filled = 0; |
| 147 | priv->cur_pos = 0; |
| 148 | priv->device_type = le16_to_cpu(serial->dev->descriptor.idProduct); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 149 | |
Alan Cox | dee0a7c | 2008-07-22 11:14:10 +0100 | [diff] [blame] | 150 | switch (priv->device_type) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 151 | case KOBIL_ADAPTER_B_PRODUCT_ID: |
| 152 | printk(KERN_DEBUG "KOBIL B1 PRO / KAAN PRO detected\n"); |
| 153 | break; |
| 154 | case KOBIL_ADAPTER_K_PRODUCT_ID: |
Alan Cox | dee0a7c | 2008-07-22 11:14:10 +0100 | [diff] [blame] | 155 | printk(KERN_DEBUG |
| 156 | "KOBIL KAAN Standard Plus / SecOVID Reader Plus detected\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 157 | break; |
| 158 | case KOBIL_USBTWIN_PRODUCT_ID: |
| 159 | printk(KERN_DEBUG "KOBIL USBTWIN detected\n"); |
| 160 | break; |
| 161 | case KOBIL_KAAN_SIM_PRODUCT_ID: |
| 162 | printk(KERN_DEBUG "KOBIL KAAN SIM detected\n"); |
| 163 | break; |
| 164 | } |
| 165 | usb_set_serial_port_data(serial->port[0], priv); |
| 166 | |
Alan Cox | dee0a7c | 2008-07-22 11:14:10 +0100 | [diff] [blame] | 167 | /* search for the necessary endpoints */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 168 | pdev = serial->dev; |
Alan Cox | dee0a7c | 2008-07-22 11:14:10 +0100 | [diff] [blame] | 169 | actconfig = pdev->actconfig; |
| 170 | interface = actconfig->interface[0]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 171 | altsetting = interface->cur_altsetting; |
Alan Cox | dee0a7c | 2008-07-22 11:14:10 +0100 | [diff] [blame] | 172 | endpoint = altsetting->endpoint; |
| 173 | |
| 174 | for (i = 0; i < altsetting->desc.bNumEndpoints; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 175 | endpoint = &altsetting->endpoint[i]; |
Luiz Fernando N. Capitulino | 4f1f1dd | 2006-10-26 13:02:53 -0300 | [diff] [blame] | 176 | if (usb_endpoint_is_int_out(&endpoint->desc)) { |
Alan Cox | dee0a7c | 2008-07-22 11:14:10 +0100 | [diff] [blame] | 177 | dbg("%s Found interrupt out endpoint. Address: %d", |
| 178 | __func__, endpoint->desc.bEndpointAddress); |
| 179 | priv->write_int_endpoint_address = |
| 180 | endpoint->desc.bEndpointAddress; |
| 181 | } |
Luiz Fernando N. Capitulino | 4f1f1dd | 2006-10-26 13:02:53 -0300 | [diff] [blame] | 182 | if (usb_endpoint_is_int_in(&endpoint->desc)) { |
Alan Cox | dee0a7c | 2008-07-22 11:14:10 +0100 | [diff] [blame] | 183 | dbg("%s Found interrupt in endpoint. Address: %d", |
| 184 | __func__, endpoint->desc.bEndpointAddress); |
| 185 | priv->read_int_endpoint_address = |
| 186 | endpoint->desc.bEndpointAddress; |
| 187 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 188 | } |
| 189 | return 0; |
| 190 | } |
| 191 | |
| 192 | |
Alan Stern | f9c99bb | 2009-06-02 11:53:55 -0400 | [diff] [blame] | 193 | static void kobil_release(struct usb_serial *serial) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 194 | { |
| 195 | int i; |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 196 | dbg("%s - port %d", __func__, serial->port[0]->number); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 197 | |
Alan Stern | f9c99bb | 2009-06-02 11:53:55 -0400 | [diff] [blame] | 198 | for (i = 0; i < serial->num_ports; ++i) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 199 | kfree(usb_get_serial_port_data(serial->port[i])); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 200 | } |
| 201 | |
Alan Cox | fe1ae7f | 2009-09-19 13:13:33 -0700 | [diff] [blame] | 202 | static void kobil_init_termios(struct tty_struct *tty) |
| 203 | { |
| 204 | /* Default to echo off and other sane device settings */ |
| 205 | tty->termios->c_lflag = 0; |
| 206 | tty->termios->c_lflag &= ~(ISIG | ICANON | ECHO | IEXTEN | XCASE); |
| 207 | tty->termios->c_iflag = IGNBRK | IGNPAR | IXOFF; |
| 208 | /* do NOT translate CR to CR-NL (0x0A -> 0x0A 0x0D) */ |
| 209 | tty->termios->c_oflag &= ~ONLCR; |
| 210 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 211 | |
Alan Cox | a509a7e | 2009-09-19 13:13:26 -0700 | [diff] [blame] | 212 | static int kobil_open(struct tty_struct *tty, struct usb_serial_port *port) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 213 | { |
Alan Cox | 94d0f7e | 2007-08-22 23:09:16 +0100 | [diff] [blame] | 214 | int result = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 215 | struct kobil_private *priv; |
| 216 | unsigned char *transfer_buffer; |
| 217 | int transfer_buffer_length = 8; |
| 218 | int write_urb_transfer_buffer_length = 8; |
| 219 | |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 220 | dbg("%s - port %d", __func__, port->number); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 221 | priv = usb_get_serial_port_data(port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 222 | |
Alan Cox | dee0a7c | 2008-07-22 11:14:10 +0100 | [diff] [blame] | 223 | /* allocate memory for transfer buffer */ |
| 224 | transfer_buffer = kzalloc(transfer_buffer_length, GFP_KERNEL); |
| 225 | if (!transfer_buffer) |
| 226 | return -ENOMEM; |
| 227 | |
| 228 | /* allocate write_urb */ |
| 229 | if (!port->write_urb) { |
| 230 | dbg("%s - port %d Allocating port->write_urb", |
| 231 | __func__, port->number); |
| 232 | port->write_urb = usb_alloc_urb(0, GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 233 | if (!port->write_urb) { |
Alan Cox | dee0a7c | 2008-07-22 11:14:10 +0100 | [diff] [blame] | 234 | dbg("%s - port %d usb_alloc_urb failed", |
| 235 | __func__, port->number); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 236 | kfree(transfer_buffer); |
| 237 | return -ENOMEM; |
| 238 | } |
| 239 | } |
| 240 | |
Alan Cox | dee0a7c | 2008-07-22 11:14:10 +0100 | [diff] [blame] | 241 | /* allocate memory for write_urb transfer buffer */ |
| 242 | port->write_urb->transfer_buffer = |
| 243 | kmalloc(write_urb_transfer_buffer_length, GFP_KERNEL); |
| 244 | if (!port->write_urb->transfer_buffer) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 245 | kfree(transfer_buffer); |
| 246 | usb_free_urb(port->write_urb); |
| 247 | port->write_urb = NULL; |
| 248 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 249 | } |
Alan Cox | dee0a7c | 2008-07-22 11:14:10 +0100 | [diff] [blame] | 250 | |
| 251 | /* get hardware version */ |
| 252 | result = usb_control_msg(port->serial->dev, |
| 253 | usb_rcvctrlpipe(port->serial->dev, 0), |
| 254 | SUSBCRequest_GetMisc, |
| 255 | USB_TYPE_VENDOR | USB_RECIP_ENDPOINT | USB_DIR_IN, |
| 256 | SUSBCR_MSC_GetHWVersion, |
| 257 | 0, |
| 258 | transfer_buffer, |
| 259 | transfer_buffer_length, |
| 260 | KOBIL_TIMEOUT |
| 261 | ); |
| 262 | dbg("%s - port %d Send get_HW_version URB returns: %i", |
| 263 | __func__, port->number, result); |
| 264 | dbg("Harware version: %i.%i.%i", |
| 265 | transfer_buffer[0], transfer_buffer[1], transfer_buffer[2]); |
| 266 | |
| 267 | /* get firmware 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_GetFWVersion, |
| 273 | 0, |
| 274 | transfer_buffer, |
| 275 | transfer_buffer_length, |
| 276 | KOBIL_TIMEOUT |
| 277 | ); |
| 278 | dbg("%s - port %d Send get_FW_version URB returns: %i", |
| 279 | __func__, port->number, result); |
| 280 | dbg("Firmware version: %i.%i.%i", |
| 281 | transfer_buffer[0], transfer_buffer[1], transfer_buffer[2]); |
| 282 | |
| 283 | if (priv->device_type == KOBIL_ADAPTER_B_PRODUCT_ID || |
| 284 | priv->device_type == KOBIL_ADAPTER_K_PRODUCT_ID) { |
| 285 | /* Setting Baudrate, Parity and Stopbits */ |
| 286 | result = usb_control_msg(port->serial->dev, |
| 287 | usb_rcvctrlpipe(port->serial->dev, 0), |
| 288 | SUSBCRequest_SetBaudRateParityAndStopBits, |
| 289 | USB_TYPE_VENDOR | USB_RECIP_ENDPOINT | USB_DIR_OUT, |
| 290 | SUSBCR_SBR_9600 | SUSBCR_SPASB_EvenParity | |
| 291 | SUSBCR_SPASB_1StopBit, |
| 292 | 0, |
| 293 | transfer_buffer, |
| 294 | 0, |
| 295 | KOBIL_TIMEOUT |
| 296 | ); |
| 297 | dbg("%s - port %d Send set_baudrate URB returns: %i", |
| 298 | __func__, port->number, result); |
| 299 | |
| 300 | /* reset all queues */ |
| 301 | result = usb_control_msg(port->serial->dev, |
| 302 | usb_rcvctrlpipe(port->serial->dev, 0), |
| 303 | SUSBCRequest_Misc, |
| 304 | USB_TYPE_VENDOR | USB_RECIP_ENDPOINT | USB_DIR_OUT, |
| 305 | SUSBCR_MSC_ResetAllQueues, |
| 306 | 0, |
| 307 | transfer_buffer, |
| 308 | 0, |
| 309 | KOBIL_TIMEOUT |
| 310 | ); |
| 311 | dbg("%s - port %d Send reset_all_queues URB returns: %i", |
| 312 | __func__, port->number, result); |
| 313 | } |
| 314 | if (priv->device_type == KOBIL_USBTWIN_PRODUCT_ID || |
| 315 | priv->device_type == KOBIL_ADAPTER_B_PRODUCT_ID || |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 316 | priv->device_type == KOBIL_KAAN_SIM_PRODUCT_ID) { |
Alan Cox | dee0a7c | 2008-07-22 11:14:10 +0100 | [diff] [blame] | 317 | /* start reading (Adapter B 'cause PNP string) */ |
| 318 | result = usb_submit_urb(port->interrupt_in_urb, GFP_ATOMIC); |
| 319 | dbg("%s - port %d Send read URB returns: %i", |
| 320 | __func__, port->number, result); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 321 | } |
| 322 | |
| 323 | kfree(transfer_buffer); |
| 324 | return 0; |
| 325 | } |
| 326 | |
| 327 | |
Alan Cox | 335f851 | 2009-06-11 12:26:29 +0100 | [diff] [blame] | 328 | static void kobil_close(struct usb_serial_port *port) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 329 | { |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 330 | dbg("%s - port %d", __func__, port->number); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 331 | |
Alan Cox | 335f851 | 2009-06-11 12:26:29 +0100 | [diff] [blame] | 332 | /* FIXME: Add rts/dtr methods */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 333 | if (port->write_urb) { |
Johan Hovold | c0f631d | 2010-05-15 17:53:43 +0200 | [diff] [blame] | 334 | usb_poison_urb(port->write_urb); |
| 335 | kfree(port->write_urb->transfer_buffer); |
Alan Cox | dee0a7c | 2008-07-22 11:14:10 +0100 | [diff] [blame] | 336 | usb_free_urb(port->write_urb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 337 | port->write_urb = NULL; |
| 338 | } |
Mariusz Kozlowski | 5505c22 | 2006-11-08 15:36:38 +0100 | [diff] [blame] | 339 | usb_kill_urb(port->interrupt_in_urb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 340 | } |
| 341 | |
| 342 | |
Greg Kroah-Hartman | 6fcdcf0 | 2007-06-15 15:44:13 -0700 | [diff] [blame] | 343 | static void kobil_read_int_callback(struct urb *urb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 344 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 345 | int result; |
Greg Kroah-Hartman | 6fcdcf0 | 2007-06-15 15:44:13 -0700 | [diff] [blame] | 346 | struct usb_serial_port *port = urb->context; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 347 | struct tty_struct *tty; |
Greg Kroah-Hartman | 6fcdcf0 | 2007-06-15 15:44:13 -0700 | [diff] [blame] | 348 | unsigned char *data = urb->transfer_buffer; |
| 349 | int status = urb->status; |
Alan Cox | dee0a7c | 2008-07-22 11:14:10 +0100 | [diff] [blame] | 350 | /* char *dbg_data; */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 351 | |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 352 | dbg("%s - port %d", __func__, port->number); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 353 | |
Greg Kroah-Hartman | 6fcdcf0 | 2007-06-15 15:44:13 -0700 | [diff] [blame] | 354 | if (status) { |
| 355 | dbg("%s - port %d Read int status not zero: %d", |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 356 | __func__, port->number, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 357 | return; |
| 358 | } |
Greg Kroah-Hartman | 6fcdcf0 | 2007-06-15 15:44:13 -0700 | [diff] [blame] | 359 | |
Alan Cox | 4a90f09 | 2008-10-13 10:39:46 +0100 | [diff] [blame] | 360 | tty = tty_port_tty_get(&port->port); |
Jiri Slaby | 6960f40 | 2011-02-28 10:34:06 +0100 | [diff] [blame] | 361 | if (tty && urb->actual_length) { |
Greg Kroah-Hartman | 6fcdcf0 | 2007-06-15 15:44:13 -0700 | [diff] [blame] | 362 | |
Alan Cox | dee0a7c | 2008-07-22 11:14:10 +0100 | [diff] [blame] | 363 | /* BEGIN DEBUG */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 364 | /* |
Alan Cox | dee0a7c | 2008-07-22 11:14:10 +0100 | [diff] [blame] | 365 | dbg_data = kzalloc((3 * purb->actual_length + 10) |
| 366 | * sizeof(char), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 367 | if (! dbg_data) { |
Alan Cox | dee0a7c | 2008-07-22 11:14:10 +0100 | [diff] [blame] | 368 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 369 | } |
Alan Cox | dee0a7c | 2008-07-22 11:14:10 +0100 | [diff] [blame] | 370 | for (i = 0; i < purb->actual_length; i++) { |
| 371 | sprintf(dbg_data +3*i, "%02X ", data[i]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 372 | } |
Alan Cox | dee0a7c | 2008-07-22 11:14:10 +0100 | [diff] [blame] | 373 | dbg(" <-- %s", dbg_data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 374 | kfree(dbg_data); |
| 375 | */ |
Alan Cox | dee0a7c | 2008-07-22 11:14:10 +0100 | [diff] [blame] | 376 | /* END DEBUG */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 377 | |
Greg Kroah-Hartman | 6fcdcf0 | 2007-06-15 15:44:13 -0700 | [diff] [blame] | 378 | tty_insert_flip_string(tty, data, urb->actual_length); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 379 | tty_flip_buffer_push(tty); |
| 380 | } |
Alan Cox | 4a90f09 | 2008-10-13 10:39:46 +0100 | [diff] [blame] | 381 | tty_kref_put(tty); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 382 | |
Greg Kroah-Hartman | 6fcdcf0 | 2007-06-15 15:44:13 -0700 | [diff] [blame] | 383 | result = usb_submit_urb(port->interrupt_in_urb, GFP_ATOMIC); |
Alan Cox | dee0a7c | 2008-07-22 11:14:10 +0100 | [diff] [blame] | 384 | dbg("%s - port %d Send read URB returns: %i", |
| 385 | __func__, port->number, result); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 386 | } |
| 387 | |
| 388 | |
Alan Cox | dee0a7c | 2008-07-22 11:14:10 +0100 | [diff] [blame] | 389 | static void kobil_write_callback(struct urb *purb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 390 | { |
| 391 | } |
| 392 | |
| 393 | |
Alan Cox | dee0a7c | 2008-07-22 11:14:10 +0100 | [diff] [blame] | 394 | static int kobil_write(struct tty_struct *tty, struct usb_serial_port *port, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 395 | const unsigned char *buf, int count) |
| 396 | { |
| 397 | int length = 0; |
| 398 | int result = 0; |
| 399 | int todo = 0; |
Alan Cox | dee0a7c | 2008-07-22 11:14:10 +0100 | [diff] [blame] | 400 | struct kobil_private *priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 401 | |
| 402 | if (count == 0) { |
Alan Cox | dee0a7c | 2008-07-22 11:14:10 +0100 | [diff] [blame] | 403 | dbg("%s - port %d write request of 0 bytes", |
| 404 | __func__, port->number); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 405 | return 0; |
| 406 | } |
| 407 | |
| 408 | priv = usb_get_serial_port_data(port); |
| 409 | |
| 410 | if (count > (KOBIL_BUF_LENGTH - priv->filled)) { |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 411 | dbg("%s - port %d Error: write request bigger than buffer size", __func__, port->number); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 412 | return -ENOMEM; |
| 413 | } |
| 414 | |
Alan Cox | dee0a7c | 2008-07-22 11:14:10 +0100 | [diff] [blame] | 415 | /* Copy data to buffer */ |
| 416 | memcpy(priv->buf + priv->filled, buf, count); |
| 417 | usb_serial_debug_data(debug, &port->dev, __func__, count, |
| 418 | priv->buf + priv->filled); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 419 | priv->filled = priv->filled + count; |
| 420 | |
Alan Cox | dee0a7c | 2008-07-22 11:14:10 +0100 | [diff] [blame] | 421 | /* only send complete block. TWIN, KAAN SIM and adapter K |
| 422 | use the same protocol. */ |
| 423 | if (((priv->device_type != KOBIL_ADAPTER_B_PRODUCT_ID) && (priv->filled > 2) && (priv->filled >= (priv->buf[1] + 3))) || |
| 424 | ((priv->device_type == KOBIL_ADAPTER_B_PRODUCT_ID) && (priv->filled > 3) && (priv->filled >= (priv->buf[2] + 4)))) { |
| 425 | /* stop reading (except TWIN and KAAN SIM) */ |
| 426 | if ((priv->device_type == KOBIL_ADAPTER_B_PRODUCT_ID) |
| 427 | || (priv->device_type == KOBIL_ADAPTER_K_PRODUCT_ID)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 428 | usb_kill_urb(port->interrupt_in_urb); |
| 429 | |
| 430 | todo = priv->filled - priv->cur_pos; |
| 431 | |
Alan Cox | dee0a7c | 2008-07-22 11:14:10 +0100 | [diff] [blame] | 432 | while (todo > 0) { |
| 433 | /* max 8 byte in one urb (endpoint size) */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 434 | length = (todo < 8) ? todo : 8; |
Alan Cox | dee0a7c | 2008-07-22 11:14:10 +0100 | [diff] [blame] | 435 | /* copy data to transfer buffer */ |
| 436 | memcpy(port->write_urb->transfer_buffer, |
| 437 | priv->buf + priv->cur_pos, length); |
| 438 | usb_fill_int_urb(port->write_urb, |
| 439 | port->serial->dev, |
| 440 | usb_sndintpipe(port->serial->dev, |
| 441 | priv->write_int_endpoint_address), |
| 442 | port->write_urb->transfer_buffer, |
| 443 | length, |
| 444 | kobil_write_callback, |
| 445 | port, |
| 446 | 8 |
| 447 | ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 448 | |
| 449 | priv->cur_pos = priv->cur_pos + length; |
Alan Cox | dee0a7c | 2008-07-22 11:14:10 +0100 | [diff] [blame] | 450 | result = usb_submit_urb(port->write_urb, GFP_NOIO); |
| 451 | dbg("%s - port %d Send write URB returns: %i", |
| 452 | __func__, port->number, result); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 453 | todo = priv->filled - priv->cur_pos; |
| 454 | |
Alan Cox | dee0a7c | 2008-07-22 11:14:10 +0100 | [diff] [blame] | 455 | if (todo > 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 456 | msleep(24); |
Alan Cox | dee0a7c | 2008-07-22 11:14:10 +0100 | [diff] [blame] | 457 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 458 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 459 | priv->filled = 0; |
| 460 | priv->cur_pos = 0; |
| 461 | |
Alan Cox | dee0a7c | 2008-07-22 11:14:10 +0100 | [diff] [blame] | 462 | /* start reading (except TWIN and KAAN SIM) */ |
| 463 | if (priv->device_type == KOBIL_ADAPTER_B_PRODUCT_ID || |
| 464 | priv->device_type == KOBIL_ADAPTER_K_PRODUCT_ID) { |
Alan Cox | dee0a7c | 2008-07-22 11:14:10 +0100 | [diff] [blame] | 465 | result = usb_submit_urb(port->interrupt_in_urb, |
| 466 | GFP_NOIO); |
| 467 | dbg("%s - port %d Send read URB returns: %i", |
| 468 | __func__, port->number, result); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 469 | } |
| 470 | } |
| 471 | return count; |
| 472 | } |
| 473 | |
| 474 | |
Alan Cox | dee0a7c | 2008-07-22 11:14:10 +0100 | [diff] [blame] | 475 | static int kobil_write_room(struct tty_struct *tty) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 476 | { |
Alan Cox | dee0a7c | 2008-07-22 11:14:10 +0100 | [diff] [blame] | 477 | /* dbg("%s - port %d", __func__, port->number); */ |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 478 | /* FIXME */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 479 | return 8; |
| 480 | } |
| 481 | |
| 482 | |
Alan Cox | 60b33c1 | 2011-02-14 16:26:14 +0000 | [diff] [blame] | 483 | static int kobil_tiocmget(struct tty_struct *tty) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 484 | { |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 485 | struct usb_serial_port *port = tty->driver_data; |
Alan Cox | dee0a7c | 2008-07-22 11:14:10 +0100 | [diff] [blame] | 486 | struct kobil_private *priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 487 | int result; |
| 488 | unsigned char *transfer_buffer; |
| 489 | int transfer_buffer_length = 8; |
| 490 | |
| 491 | priv = usb_get_serial_port_data(port); |
Alan Cox | dee0a7c | 2008-07-22 11:14:10 +0100 | [diff] [blame] | 492 | if (priv->device_type == KOBIL_USBTWIN_PRODUCT_ID |
| 493 | || priv->device_type == KOBIL_KAAN_SIM_PRODUCT_ID) { |
| 494 | /* This device doesn't support ioctl calls */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 495 | return -EINVAL; |
| 496 | } |
| 497 | |
Alan Cox | dee0a7c | 2008-07-22 11:14:10 +0100 | [diff] [blame] | 498 | /* allocate memory for transfer buffer */ |
Eric Sesterhenn | 80b6ca4 | 2006-02-27 21:29:43 +0100 | [diff] [blame] | 499 | transfer_buffer = kzalloc(transfer_buffer_length, GFP_KERNEL); |
Alan Cox | dee0a7c | 2008-07-22 11:14:10 +0100 | [diff] [blame] | 500 | if (!transfer_buffer) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 501 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 502 | |
Alan Cox | dee0a7c | 2008-07-22 11:14:10 +0100 | [diff] [blame] | 503 | result = usb_control_msg(port->serial->dev, |
| 504 | usb_rcvctrlpipe(port->serial->dev, 0), |
| 505 | SUSBCRequest_GetStatusLineState, |
| 506 | USB_TYPE_VENDOR | USB_RECIP_ENDPOINT | USB_DIR_IN, |
| 507 | 0, |
| 508 | 0, |
| 509 | transfer_buffer, |
| 510 | transfer_buffer_length, |
| 511 | KOBIL_TIMEOUT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 512 | |
Alan Cox | dee0a7c | 2008-07-22 11:14:10 +0100 | [diff] [blame] | 513 | dbg("%s - port %d Send get_status_line_state URB returns: %i. Statusline: %02x", |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 514 | __func__, port->number, result, transfer_buffer[0]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 515 | |
Alan Cox | a40d854 | 2008-02-20 21:40:34 +0000 | [diff] [blame] | 516 | result = 0; |
| 517 | if ((transfer_buffer[0] & SUSBCR_GSL_DSR) != 0) |
| 518 | result = TIOCM_DSR; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 519 | kfree(transfer_buffer); |
Alan Cox | a40d854 | 2008-02-20 21:40:34 +0000 | [diff] [blame] | 520 | return result; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 521 | } |
| 522 | |
Alan Cox | 20b9d17 | 2011-02-14 16:26:50 +0000 | [diff] [blame] | 523 | static int kobil_tiocmset(struct tty_struct *tty, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 524 | unsigned int set, unsigned int clear) |
| 525 | { |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 526 | struct usb_serial_port *port = tty->driver_data; |
Alan Cox | dee0a7c | 2008-07-22 11:14:10 +0100 | [diff] [blame] | 527 | struct kobil_private *priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 528 | int result; |
| 529 | int dtr = 0; |
| 530 | int rts = 0; |
| 531 | unsigned char *transfer_buffer; |
| 532 | int transfer_buffer_length = 8; |
| 533 | |
Alan Cox | a40d854 | 2008-02-20 21:40:34 +0000 | [diff] [blame] | 534 | /* FIXME: locking ? */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 535 | priv = usb_get_serial_port_data(port); |
Alan Cox | dee0a7c | 2008-07-22 11:14:10 +0100 | [diff] [blame] | 536 | if (priv->device_type == KOBIL_USBTWIN_PRODUCT_ID |
| 537 | || priv->device_type == KOBIL_KAAN_SIM_PRODUCT_ID) { |
| 538 | /* This device doesn't support ioctl calls */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 539 | return -EINVAL; |
| 540 | } |
| 541 | |
Alan Cox | dee0a7c | 2008-07-22 11:14:10 +0100 | [diff] [blame] | 542 | /* allocate memory for transfer buffer */ |
Eric Sesterhenn | 80b6ca4 | 2006-02-27 21:29:43 +0100 | [diff] [blame] | 543 | transfer_buffer = kzalloc(transfer_buffer_length, GFP_KERNEL); |
Alan Cox | dee0a7c | 2008-07-22 11:14:10 +0100 | [diff] [blame] | 544 | if (!transfer_buffer) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 545 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 546 | |
| 547 | if (set & TIOCM_RTS) |
| 548 | rts = 1; |
| 549 | if (set & TIOCM_DTR) |
| 550 | dtr = 1; |
| 551 | if (clear & TIOCM_RTS) |
| 552 | rts = 0; |
| 553 | if (clear & TIOCM_DTR) |
| 554 | dtr = 0; |
| 555 | |
| 556 | if (priv->device_type == KOBIL_ADAPTER_B_PRODUCT_ID) { |
| 557 | if (dtr != 0) |
Alan Cox | dee0a7c | 2008-07-22 11:14:10 +0100 | [diff] [blame] | 558 | dbg("%s - port %d Setting DTR", |
| 559 | __func__, port->number); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 560 | else |
Alan Cox | dee0a7c | 2008-07-22 11:14:10 +0100 | [diff] [blame] | 561 | dbg("%s - port %d Clearing DTR", |
| 562 | __func__, port->number); |
| 563 | result = usb_control_msg(port->serial->dev, |
| 564 | usb_rcvctrlpipe(port->serial->dev, 0), |
| 565 | SUSBCRequest_SetStatusLinesOrQueues, |
| 566 | USB_TYPE_VENDOR | USB_RECIP_ENDPOINT | USB_DIR_OUT, |
| 567 | ((dtr != 0) ? SUSBCR_SSL_SETDTR : SUSBCR_SSL_CLRDTR), |
| 568 | 0, |
| 569 | transfer_buffer, |
| 570 | 0, |
| 571 | KOBIL_TIMEOUT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 572 | } else { |
| 573 | if (rts != 0) |
Alan Cox | dee0a7c | 2008-07-22 11:14:10 +0100 | [diff] [blame] | 574 | dbg("%s - port %d Setting RTS", |
| 575 | __func__, port->number); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 576 | else |
Alan Cox | dee0a7c | 2008-07-22 11:14:10 +0100 | [diff] [blame] | 577 | dbg("%s - port %d Clearing RTS", |
| 578 | __func__, port->number); |
| 579 | result = usb_control_msg(port->serial->dev, |
| 580 | usb_rcvctrlpipe(port->serial->dev, 0), |
| 581 | SUSBCRequest_SetStatusLinesOrQueues, |
| 582 | USB_TYPE_VENDOR | USB_RECIP_ENDPOINT | USB_DIR_OUT, |
| 583 | ((rts != 0) ? SUSBCR_SSL_SETRTS : SUSBCR_SSL_CLRRTS), |
| 584 | 0, |
| 585 | transfer_buffer, |
| 586 | 0, |
| 587 | KOBIL_TIMEOUT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 588 | } |
Alan Cox | dee0a7c | 2008-07-22 11:14:10 +0100 | [diff] [blame] | 589 | dbg("%s - port %d Send set_status_line URB returns: %i", |
| 590 | __func__, port->number, result); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 591 | kfree(transfer_buffer); |
| 592 | return (result < 0) ? result : 0; |
| 593 | } |
| 594 | |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 595 | static void kobil_set_termios(struct tty_struct *tty, |
| 596 | struct usb_serial_port *port, struct ktermios *old) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 597 | { |
Alan Cox | dee0a7c | 2008-07-22 11:14:10 +0100 | [diff] [blame] | 598 | struct kobil_private *priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 599 | int result; |
| 600 | unsigned short urb_val = 0; |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 601 | int c_cflag = tty->termios->c_cflag; |
Alan Cox | 94d0f7e | 2007-08-22 23:09:16 +0100 | [diff] [blame] | 602 | speed_t speed; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 603 | |
| 604 | priv = usb_get_serial_port_data(port); |
Alan Cox | dee0a7c | 2008-07-22 11:14:10 +0100 | [diff] [blame] | 605 | if (priv->device_type == KOBIL_USBTWIN_PRODUCT_ID || |
Alan Cox | b31f658 | 2008-07-22 11:14:22 +0100 | [diff] [blame] | 606 | priv->device_type == KOBIL_KAAN_SIM_PRODUCT_ID) { |
Alan Cox | dee0a7c | 2008-07-22 11:14:10 +0100 | [diff] [blame] | 607 | /* This device doesn't support ioctl calls */ |
Alan Cox | b31f658 | 2008-07-22 11:14:22 +0100 | [diff] [blame] | 608 | *tty->termios = *old; |
Alan Cox | 94d0f7e | 2007-08-22 23:09:16 +0100 | [diff] [blame] | 609 | return; |
Alan Cox | b31f658 | 2008-07-22 11:14:22 +0100 | [diff] [blame] | 610 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 611 | |
Alan Cox | dee0a7c | 2008-07-22 11:14:10 +0100 | [diff] [blame] | 612 | speed = tty_get_baud_rate(tty); |
| 613 | switch (speed) { |
| 614 | case 1200: |
| 615 | urb_val = SUSBCR_SBR_1200; |
| 616 | break; |
| 617 | default: |
| 618 | speed = 9600; |
| 619 | case 9600: |
| 620 | urb_val = SUSBCR_SBR_9600; |
| 621 | break; |
Alan Cox | 94d0f7e | 2007-08-22 23:09:16 +0100 | [diff] [blame] | 622 | } |
Alan Cox | dee0a7c | 2008-07-22 11:14:10 +0100 | [diff] [blame] | 623 | urb_val |= (c_cflag & CSTOPB) ? SUSBCR_SPASB_2StopBits : |
| 624 | SUSBCR_SPASB_1StopBit; |
Alan Cox | 94d0f7e | 2007-08-22 23:09:16 +0100 | [diff] [blame] | 625 | if (c_cflag & PARENB) { |
Johan Hovold | 96679f6 | 2009-12-28 23:01:58 +0100 | [diff] [blame] | 626 | if (c_cflag & PARODD) |
Alan Cox | 94d0f7e | 2007-08-22 23:09:16 +0100 | [diff] [blame] | 627 | urb_val |= SUSBCR_SPASB_OddParity; |
Johan Hovold | 96679f6 | 2009-12-28 23:01:58 +0100 | [diff] [blame] | 628 | else |
Alan Cox | 94d0f7e | 2007-08-22 23:09:16 +0100 | [diff] [blame] | 629 | urb_val |= SUSBCR_SPASB_EvenParity; |
Johan Hovold | 96679f6 | 2009-12-28 23:01:58 +0100 | [diff] [blame] | 630 | } else |
Alan Cox | 94d0f7e | 2007-08-22 23:09:16 +0100 | [diff] [blame] | 631 | urb_val |= SUSBCR_SPASB_NoParity; |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 632 | tty->termios->c_cflag &= ~CMSPAR; |
| 633 | tty_encode_baud_rate(tty, speed, speed); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 634 | |
Alan Cox | dee0a7c | 2008-07-22 11:14:10 +0100 | [diff] [blame] | 635 | result = usb_control_msg(port->serial->dev, |
| 636 | usb_rcvctrlpipe(port->serial->dev, 0), |
| 637 | SUSBCRequest_SetBaudRateParityAndStopBits, |
| 638 | USB_TYPE_VENDOR | USB_RECIP_ENDPOINT | USB_DIR_OUT, |
| 639 | urb_val, |
| 640 | 0, |
Johan Hovold | 96679f6 | 2009-12-28 23:01:58 +0100 | [diff] [blame] | 641 | NULL, |
Alan Cox | dee0a7c | 2008-07-22 11:14:10 +0100 | [diff] [blame] | 642 | 0, |
| 643 | KOBIL_TIMEOUT |
Alan Cox | 94d0f7e | 2007-08-22 23:09:16 +0100 | [diff] [blame] | 644 | ); |
Alan Cox | 94d0f7e | 2007-08-22 23:09:16 +0100 | [diff] [blame] | 645 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 646 | |
Alan Cox | 00a0d0d | 2011-02-14 16:27:06 +0000 | [diff] [blame] | 647 | static int kobil_ioctl(struct tty_struct *tty, |
Alan Cox | dee0a7c | 2008-07-22 11:14:10 +0100 | [diff] [blame] | 648 | unsigned int cmd, unsigned long arg) |
Alan Cox | 94d0f7e | 2007-08-22 23:09:16 +0100 | [diff] [blame] | 649 | { |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 650 | struct usb_serial_port *port = tty->driver_data; |
Alan Cox | dee0a7c | 2008-07-22 11:14:10 +0100 | [diff] [blame] | 651 | struct kobil_private *priv = usb_get_serial_port_data(port); |
Alan Cox | 94d0f7e | 2007-08-22 23:09:16 +0100 | [diff] [blame] | 652 | unsigned char *transfer_buffer; |
| 653 | int transfer_buffer_length = 8; |
| 654 | int result; |
| 655 | |
Alan Cox | dee0a7c | 2008-07-22 11:14:10 +0100 | [diff] [blame] | 656 | if (priv->device_type == KOBIL_USBTWIN_PRODUCT_ID || |
| 657 | priv->device_type == KOBIL_KAAN_SIM_PRODUCT_ID) |
| 658 | /* This device doesn't support ioctl calls */ |
Alan Cox | b31f658 | 2008-07-22 11:14:22 +0100 | [diff] [blame] | 659 | return -ENOIOCTLCMD; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 660 | |
Alan Cox | 94d0f7e | 2007-08-22 23:09:16 +0100 | [diff] [blame] | 661 | switch (cmd) { |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 662 | case TCFLSH: |
Robert P. J. Day | 5cbded5 | 2006-12-13 00:35:56 -0800 | [diff] [blame] | 663 | transfer_buffer = kmalloc(transfer_buffer_length, GFP_KERNEL); |
Alan Cox | dee0a7c | 2008-07-22 11:14:10 +0100 | [diff] [blame] | 664 | if (!transfer_buffer) |
| 665 | return -ENOBUFS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 666 | |
Alan Cox | dee0a7c | 2008-07-22 11:14:10 +0100 | [diff] [blame] | 667 | result = usb_control_msg(port->serial->dev, |
| 668 | usb_rcvctrlpipe(port->serial->dev, 0), |
| 669 | SUSBCRequest_Misc, |
| 670 | USB_TYPE_VENDOR | USB_RECIP_ENDPOINT | USB_DIR_OUT, |
| 671 | SUSBCR_MSC_ResetAllQueues, |
| 672 | 0, |
| 673 | NULL, /* transfer_buffer, */ |
| 674 | 0, |
| 675 | KOBIL_TIMEOUT |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 676 | ); |
Alan Cox | dee0a7c | 2008-07-22 11:14:10 +0100 | [diff] [blame] | 677 | |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 678 | dbg("%s - port %d Send reset_all_queues (FLUSH) URB returns: %i", __func__, port->number, result); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 679 | kfree(transfer_buffer); |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 680 | return (result < 0) ? -EIO: 0; |
Alan Cox | 94d0f7e | 2007-08-22 23:09:16 +0100 | [diff] [blame] | 681 | default: |
| 682 | return -ENOIOCTLCMD; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 683 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 684 | } |
| 685 | |
Greg Kroah-Hartman | 8a9040b | 2012-02-28 13:12:02 -0800 | [diff] [blame] | 686 | module_usb_serial_driver(kobil_driver, serial_drivers); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 687 | |
Alan Cox | dee0a7c | 2008-07-22 11:14:10 +0100 | [diff] [blame] | 688 | MODULE_AUTHOR(DRIVER_AUTHOR); |
| 689 | MODULE_DESCRIPTION(DRIVER_DESC); |
| 690 | MODULE_LICENSE("GPL"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 691 | |
| 692 | module_param(debug, bool, S_IRUGO | S_IWUSR); |
| 693 | MODULE_PARM_DESC(debug, "Debug enabled or not"); |