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