Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Edgeport USB Serial Converter driver |
| 3 | * |
| 4 | * Copyright (C) 2000 Inside Out Networks, All rights reserved. |
| 5 | * Copyright (C) 2001-2002 Greg Kroah-Hartman <greg@kroah.com> |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License as published by |
| 9 | * the Free Software Foundation; either version 2 of the License, or |
| 10 | * (at your option) any later version. |
| 11 | * |
| 12 | * Supports the following devices: |
| 13 | * Edgeport/4 |
| 14 | * Edgeport/4t |
| 15 | * Edgeport/2 |
| 16 | * Edgeport/4i |
| 17 | * Edgeport/2i |
| 18 | * Edgeport/421 |
| 19 | * Edgeport/21 |
| 20 | * Rapidport/4 |
| 21 | * Edgeport/8 |
| 22 | * Edgeport/2D8 |
| 23 | * Edgeport/4D8 |
| 24 | * Edgeport/8i |
| 25 | * |
| 26 | * For questions or problems with this driver, contact Inside Out |
| 27 | * Networks technical support, or Peter Berger <pberger@brimson.com>, |
| 28 | * or Al Borchers <alborchers@steinerpoint.com>. |
| 29 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | */ |
| 31 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | #include <linux/kernel.h> |
| 33 | #include <linux/jiffies.h> |
| 34 | #include <linux/errno.h> |
| 35 | #include <linux/init.h> |
| 36 | #include <linux/slab.h> |
| 37 | #include <linux/tty.h> |
| 38 | #include <linux/tty_driver.h> |
| 39 | #include <linux/tty_flip.h> |
| 40 | #include <linux/module.h> |
| 41 | #include <linux/spinlock.h> |
| 42 | #include <linux/serial.h> |
| 43 | #include <linux/ioctl.h> |
| 44 | #include <linux/wait.h> |
Jaswinder Singh | 5b9ea93 | 2008-07-03 17:00:23 +0530 | [diff] [blame] | 45 | #include <linux/firmware.h> |
| 46 | #include <linux/ihex.h> |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 47 | #include <linux/uaccess.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | #include <linux/usb.h> |
Greg Kroah-Hartman | a969888 | 2006-07-11 21:22:58 -0700 | [diff] [blame] | 49 | #include <linux/usb/serial.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | #include "io_edgeport.h" |
| 51 | #include "io_ionsp.h" /* info for the iosp messages */ |
| 52 | #include "io_16654.h" /* 16654 UART defines */ |
| 53 | |
| 54 | /* |
| 55 | * Version Information |
| 56 | */ |
| 57 | #define DRIVER_VERSION "v2.7" |
| 58 | #define DRIVER_AUTHOR "Greg Kroah-Hartman <greg@kroah.com> and David Iacovelli" |
| 59 | #define DRIVER_DESC "Edgeport USB Serial Driver" |
| 60 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | #define MAX_NAME_LEN 64 |
| 62 | |
| 63 | #define CHASE_TIMEOUT (5*HZ) /* 5 seconds */ |
| 64 | #define OPEN_TIMEOUT (5*HZ) /* 5 seconds */ |
| 65 | #define COMMAND_TIMEOUT (5*HZ) /* 5 seconds */ |
| 66 | |
| 67 | /* receive port state */ |
| 68 | enum RXSTATE { |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 69 | EXPECT_HDR1 = 0, /* Expect header byte 1 */ |
| 70 | EXPECT_HDR2 = 1, /* Expect header byte 2 */ |
| 71 | EXPECT_DATA = 2, /* Expect 'RxBytesRemaining' data */ |
| 72 | EXPECT_HDR3 = 3, /* Expect header byte 3 (for status hdrs only) */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | }; |
| 74 | |
| 75 | |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 76 | /* Transmit Fifo |
| 77 | * This Transmit queue is an extension of the edgeport Rx buffer. |
| 78 | * The maximum amount of data buffered in both the edgeport |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | * Rx buffer (maxTxCredits) and this buffer will never exceed maxTxCredits. |
| 80 | */ |
| 81 | struct TxFifo { |
| 82 | unsigned int head; /* index to head pointer (write) */ |
| 83 | unsigned int tail; /* index to tail pointer (read) */ |
| 84 | unsigned int count; /* Bytes in queue */ |
| 85 | unsigned int size; /* Max size of queue (equal to Max number of TxCredits) */ |
| 86 | unsigned char *fifo; /* allocated Buffer */ |
| 87 | }; |
| 88 | |
| 89 | /* This structure holds all of the local port information */ |
| 90 | struct edgeport_port { |
| 91 | __u16 txCredits; /* our current credits for this port */ |
| 92 | __u16 maxTxCredits; /* the max size of the port */ |
| 93 | |
| 94 | struct TxFifo txfifo; /* transmit fifo -- size will be maxTxCredits */ |
| 95 | struct urb *write_urb; /* write URB for this port */ |
Richard Knutsson | cb8eaa8 | 2007-03-17 01:35:53 +0100 | [diff] [blame] | 96 | bool write_in_progress; /* 'true' while a write URB is outstanding */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 | spinlock_t ep_lock; |
| 98 | |
| 99 | __u8 shadowLCR; /* last LCR value received */ |
| 100 | __u8 shadowMCR; /* last MCR value received */ |
| 101 | __u8 shadowMSR; /* last MSR value received */ |
| 102 | __u8 shadowLSR; /* last LSR value received */ |
| 103 | __u8 shadowXonChar; /* last value set as XON char in Edgeport */ |
| 104 | __u8 shadowXoffChar; /* last value set as XOFF char in Edgeport */ |
| 105 | __u8 validDataMask; |
| 106 | __u32 baudRate; |
| 107 | |
Richard Knutsson | cb8eaa8 | 2007-03-17 01:35:53 +0100 | [diff] [blame] | 108 | bool open; |
| 109 | bool openPending; |
| 110 | bool commandPending; |
| 111 | bool closePending; |
| 112 | bool chaseResponsePending; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 113 | |
| 114 | wait_queue_head_t wait_chase; /* for handling sleeping while waiting for chase to finish */ |
| 115 | wait_queue_head_t wait_open; /* for handling sleeping while waiting for open to finish */ |
| 116 | wait_queue_head_t wait_command; /* for handling sleeping while waiting for command to finish */ |
| 117 | wait_queue_head_t delta_msr_wait; /* for handling sleeping while waiting for msr change to happen */ |
| 118 | |
| 119 | struct async_icount icount; |
| 120 | struct usb_serial_port *port; /* loop back to the owner of this object */ |
| 121 | }; |
| 122 | |
| 123 | |
| 124 | /* This structure holds all of the individual device information */ |
| 125 | struct edgeport_serial { |
Pete Zaitcev | ad93375 | 2006-05-22 21:49:44 -0700 | [diff] [blame] | 126 | char name[MAX_NAME_LEN+2]; /* string name of this device */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 127 | |
| 128 | struct edge_manuf_descriptor manuf_descriptor; /* the manufacturer descriptor */ |
| 129 | struct edge_boot_descriptor boot_descriptor; /* the boot firmware descriptor */ |
| 130 | struct edgeport_product_info product_info; /* Product Info */ |
Greg Kroah-Hartman | 6e8cf77 | 2007-01-18 00:20:19 -0800 | [diff] [blame] | 131 | struct edge_compatibility_descriptor epic_descriptor; /* Edgeport compatible descriptor */ |
| 132 | int is_epic; /* flag if EPiC device or not */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 133 | |
| 134 | __u8 interrupt_in_endpoint; /* the interrupt endpoint handle */ |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 135 | unsigned char *interrupt_in_buffer; /* the buffer we use for the interrupt endpoint */ |
| 136 | struct urb *interrupt_read_urb; /* our interrupt urb */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 137 | |
| 138 | __u8 bulk_in_endpoint; /* the bulk in endpoint handle */ |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 139 | unsigned char *bulk_in_buffer; /* the buffer we use for the bulk in endpoint */ |
| 140 | struct urb *read_urb; /* our bulk read urb */ |
Richard Knutsson | cb8eaa8 | 2007-03-17 01:35:53 +0100 | [diff] [blame] | 141 | bool read_in_progress; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 142 | spinlock_t es_lock; |
| 143 | |
| 144 | __u8 bulk_out_endpoint; /* the bulk out endpoint handle */ |
| 145 | |
| 146 | __s16 rxBytesAvail; /* the number of bytes that we need to read from this device */ |
| 147 | |
| 148 | enum RXSTATE rxState; /* the current state of the bulk receive processor */ |
| 149 | __u8 rxHeader1; /* receive header byte 1 */ |
| 150 | __u8 rxHeader2; /* receive header byte 2 */ |
| 151 | __u8 rxHeader3; /* receive header byte 3 */ |
| 152 | __u8 rxPort; /* the port that we are currently receiving data for */ |
| 153 | __u8 rxStatusCode; /* the receive status code */ |
| 154 | __u8 rxStatusParam; /* the receive status paramater */ |
| 155 | __s16 rxBytesRemaining; /* the number of port bytes left to read */ |
| 156 | struct usb_serial *serial; /* loop back to the owner of this object */ |
| 157 | }; |
| 158 | |
| 159 | /* baud rate information */ |
| 160 | struct divisor_table_entry { |
| 161 | __u32 BaudRate; |
| 162 | __u16 Divisor; |
| 163 | }; |
| 164 | |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 165 | /* |
| 166 | * Define table of divisors for Rev A EdgePort/4 hardware |
| 167 | * These assume a 3.6864MHz crystal, the standard /16, and |
| 168 | * MCR.7 = 0. |
| 169 | */ |
| 170 | |
Arjan van de Ven | 4c4c943 | 2005-11-29 09:43:42 +0100 | [diff] [blame] | 171 | static const struct divisor_table_entry divisor_table[] = { |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 172 | { 50, 4608}, |
| 173 | { 75, 3072}, |
| 174 | { 110, 2095}, /* 2094.545455 => 230450 => .0217 % over */ |
| 175 | { 134, 1713}, /* 1713.011152 => 230398.5 => .00065% under */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 176 | { 150, 1536}, |
| 177 | { 300, 768}, |
| 178 | { 600, 384}, |
| 179 | { 1200, 192}, |
| 180 | { 1800, 128}, |
| 181 | { 2400, 96}, |
| 182 | { 4800, 48}, |
| 183 | { 7200, 32}, |
| 184 | { 9600, 24}, |
| 185 | { 14400, 16}, |
| 186 | { 19200, 12}, |
| 187 | { 38400, 6}, |
| 188 | { 57600, 4}, |
| 189 | { 115200, 2}, |
| 190 | { 230400, 1}, |
| 191 | }; |
| 192 | |
| 193 | /* local variables */ |
| 194 | static int debug; |
| 195 | |
| 196 | static int low_latency = 1; /* tty low latency flag, on by default */ |
| 197 | |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 198 | static atomic_t CmdUrbs; /* Number of outstanding Command Write Urbs */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 199 | |
| 200 | |
| 201 | /* local function prototypes */ |
| 202 | |
| 203 | /* function prototypes for all URB callbacks */ |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 204 | static void edge_interrupt_callback(struct urb *urb); |
| 205 | static void edge_bulk_in_callback(struct urb *urb); |
| 206 | static void edge_bulk_out_data_callback(struct urb *urb); |
| 207 | static void edge_bulk_out_cmd_callback(struct urb *urb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 208 | |
| 209 | /* function prototypes for the usbserial callbacks */ |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 210 | static int edge_open(struct tty_struct *tty, struct usb_serial_port *port, |
| 211 | struct file *filp); |
| 212 | static void edge_close(struct tty_struct *tty, struct usb_serial_port *port, |
| 213 | struct file *filp); |
| 214 | static int edge_write(struct tty_struct *tty, struct usb_serial_port *port, |
| 215 | const unsigned char *buf, int count); |
| 216 | static int edge_write_room(struct tty_struct *tty); |
| 217 | static int edge_chars_in_buffer(struct tty_struct *tty); |
| 218 | static void edge_throttle(struct tty_struct *tty); |
| 219 | static void edge_unthrottle(struct tty_struct *tty); |
| 220 | static void edge_set_termios(struct tty_struct *tty, |
| 221 | struct usb_serial_port *port, |
| 222 | struct ktermios *old_termios); |
| 223 | static int edge_ioctl(struct tty_struct *tty, struct file *file, |
| 224 | unsigned int cmd, unsigned long arg); |
| 225 | static void edge_break(struct tty_struct *tty, int break_state); |
| 226 | static int edge_tiocmget(struct tty_struct *tty, struct file *file); |
| 227 | static int edge_tiocmset(struct tty_struct *tty, struct file *file, |
| 228 | unsigned int set, unsigned int clear); |
| 229 | static int edge_startup(struct usb_serial *serial); |
| 230 | static void edge_shutdown(struct usb_serial *serial); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 231 | |
| 232 | #include "io_tables.h" /* all of the devices that this driver supports */ |
| 233 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 234 | /* function prototypes for all of our local functions */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 235 | |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 236 | static void process_rcvd_data(struct edgeport_serial *edge_serial, |
| 237 | unsigned char *buffer, __u16 bufferLength); |
| 238 | static void process_rcvd_status(struct edgeport_serial *edge_serial, |
| 239 | __u8 byte2, __u8 byte3); |
| 240 | static void edge_tty_recv(struct device *dev, struct tty_struct *tty, |
| 241 | unsigned char *data, int length); |
| 242 | static void handle_new_msr(struct edgeport_port *edge_port, __u8 newMsr); |
| 243 | static void handle_new_lsr(struct edgeport_port *edge_port, __u8 lsrData, |
| 244 | __u8 lsr, __u8 data); |
| 245 | static int send_iosp_ext_cmd(struct edgeport_port *edge_port, __u8 command, |
| 246 | __u8 param); |
| 247 | static int calc_baud_rate_divisor(int baud_rate, int *divisor); |
| 248 | static int send_cmd_write_baud_rate(struct edgeport_port *edge_port, |
| 249 | int baudRate); |
| 250 | static void change_port_settings(struct tty_struct *tty, |
| 251 | struct edgeport_port *edge_port, |
| 252 | struct ktermios *old_termios); |
| 253 | static int send_cmd_write_uart_register(struct edgeport_port *edge_port, |
| 254 | __u8 regNum, __u8 regValue); |
| 255 | static int write_cmd_usb(struct edgeport_port *edge_port, |
| 256 | unsigned char *buffer, int writeLength); |
| 257 | static void send_more_port_data(struct edgeport_serial *edge_serial, |
| 258 | struct edgeport_port *edge_port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 259 | |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 260 | static int sram_write(struct usb_serial *serial, __u16 extAddr, __u16 addr, |
| 261 | __u16 length, const __u8 *data); |
| 262 | static int rom_read(struct usb_serial *serial, __u16 extAddr, __u16 addr, |
| 263 | __u16 length, __u8 *data); |
| 264 | static int rom_write(struct usb_serial *serial, __u16 extAddr, __u16 addr, |
| 265 | __u16 length, const __u8 *data); |
| 266 | static void get_manufacturing_desc(struct edgeport_serial *edge_serial); |
| 267 | static void get_boot_desc(struct edgeport_serial *edge_serial); |
| 268 | static void load_application_firmware(struct edgeport_serial *edge_serial); |
| 269 | |
| 270 | static void unicode_to_ascii(char *string, int buflen, |
| 271 | __le16 *unicode, int unicode_size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 272 | |
| 273 | |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 274 | /* ************************************************************************ */ |
| 275 | /* ************************************************************************ */ |
| 276 | /* ************************************************************************ */ |
| 277 | /* ************************************************************************ */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 278 | |
| 279 | /************************************************************************ |
| 280 | * * |
| 281 | * update_edgeport_E2PROM() Compare current versions of * |
| 282 | * Boot ROM and Manufacture * |
| 283 | * Descriptors with versions * |
| 284 | * embedded in this driver * |
| 285 | * * |
| 286 | ************************************************************************/ |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 287 | static void update_edgeport_E2PROM(struct edgeport_serial *edge_serial) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 288 | { |
| 289 | __u32 BootCurVer; |
| 290 | __u32 BootNewVer; |
Jaswinder Singh | 5b9ea93 | 2008-07-03 17:00:23 +0530 | [diff] [blame] | 291 | __u8 BootMajorVersion; |
| 292 | __u8 BootMinorVersion; |
| 293 | __u16 BootBuildNumber; |
| 294 | __u32 Bootaddr; |
| 295 | const struct ihex_binrec *rec; |
| 296 | const struct firmware *fw; |
| 297 | const char *fw_name; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 298 | int response; |
| 299 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 300 | switch (edge_serial->product_info.iDownloadFile) { |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 301 | case EDGE_DOWNLOAD_FILE_I930: |
| 302 | fw_name = "edgeport/boot.fw"; |
| 303 | break; |
| 304 | case EDGE_DOWNLOAD_FILE_80251: |
| 305 | fw_name = "edgeport/boot2.fw"; |
| 306 | break; |
| 307 | default: |
| 308 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 309 | } |
| 310 | |
Jaswinder Singh | 5b9ea93 | 2008-07-03 17:00:23 +0530 | [diff] [blame] | 311 | response = request_ihex_firmware(&fw, fw_name, |
| 312 | &edge_serial->serial->dev->dev); |
| 313 | if (response) { |
| 314 | printk(KERN_ERR "Failed to load image \"%s\" err %d\n", |
| 315 | fw_name, response); |
| 316 | return; |
| 317 | } |
| 318 | |
| 319 | rec = (const struct ihex_binrec *)fw->data; |
| 320 | BootMajorVersion = rec->data[0]; |
| 321 | BootMinorVersion = rec->data[1]; |
| 322 | BootBuildNumber = (rec->data[2] << 8) | rec->data[3]; |
| 323 | |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 324 | /* Check Boot Image Version */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 325 | BootCurVer = (edge_serial->boot_descriptor.MajorVersion << 24) + |
| 326 | (edge_serial->boot_descriptor.MinorVersion << 16) + |
| 327 | le16_to_cpu(edge_serial->boot_descriptor.BuildNumber); |
| 328 | |
| 329 | BootNewVer = (BootMajorVersion << 24) + |
| 330 | (BootMinorVersion << 16) + |
Jaswinder Singh | 5b9ea93 | 2008-07-03 17:00:23 +0530 | [diff] [blame] | 331 | BootBuildNumber; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 332 | |
| 333 | dbg("Current Boot Image version %d.%d.%d", |
| 334 | edge_serial->boot_descriptor.MajorVersion, |
| 335 | edge_serial->boot_descriptor.MinorVersion, |
| 336 | le16_to_cpu(edge_serial->boot_descriptor.BuildNumber)); |
| 337 | |
| 338 | |
| 339 | if (BootNewVer > BootCurVer) { |
| 340 | dbg("**Update Boot Image from %d.%d.%d to %d.%d.%d", |
| 341 | edge_serial->boot_descriptor.MajorVersion, |
| 342 | edge_serial->boot_descriptor.MinorVersion, |
| 343 | le16_to_cpu(edge_serial->boot_descriptor.BuildNumber), |
Jaswinder Singh | 5b9ea93 | 2008-07-03 17:00:23 +0530 | [diff] [blame] | 344 | BootMajorVersion, BootMinorVersion, BootBuildNumber); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 345 | |
| 346 | dbg("Downloading new Boot Image"); |
| 347 | |
Jaswinder Singh | 5b9ea93 | 2008-07-03 17:00:23 +0530 | [diff] [blame] | 348 | for (rec = ihex_next_binrec(rec); rec; |
| 349 | rec = ihex_next_binrec(rec)) { |
| 350 | Bootaddr = be32_to_cpu(rec->addr); |
| 351 | response = rom_write(edge_serial->serial, |
| 352 | Bootaddr >> 16, |
| 353 | Bootaddr & 0xFFFF, |
| 354 | be16_to_cpu(rec->len), |
| 355 | &rec->data[0]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 356 | if (response < 0) { |
Jaswinder Singh | 5b9ea93 | 2008-07-03 17:00:23 +0530 | [diff] [blame] | 357 | dev_err(&edge_serial->serial->dev->dev, |
| 358 | "rom_write failed (%x, %x, %d)\n", |
| 359 | Bootaddr >> 16, Bootaddr & 0xFFFF, |
| 360 | be16_to_cpu(rec->len)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 361 | break; |
| 362 | } |
| 363 | } |
| 364 | } else { |
| 365 | dbg("Boot Image -- already up to date"); |
| 366 | } |
Jaswinder Singh | 5b9ea93 | 2008-07-03 17:00:23 +0530 | [diff] [blame] | 367 | release_firmware(fw); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 368 | } |
| 369 | |
| 370 | |
| 371 | /************************************************************************ |
| 372 | * * |
| 373 | * Get string descriptor from device * |
| 374 | * * |
| 375 | ************************************************************************/ |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 376 | static int get_string(struct usb_device *dev, int Id, char *string, int buflen) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 377 | { |
| 378 | struct usb_string_descriptor StringDesc; |
| 379 | struct usb_string_descriptor *pStringDesc; |
| 380 | |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 381 | dbg("%s - USB String ID = %d", __func__, Id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 382 | |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 383 | if (!usb_get_descriptor(dev, USB_DT_STRING, Id, |
| 384 | &StringDesc, sizeof(StringDesc))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 385 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 386 | |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 387 | pStringDesc = kmalloc(StringDesc.bLength, GFP_KERNEL); |
| 388 | if (!pStringDesc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 389 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 390 | |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 391 | if (!usb_get_descriptor(dev, USB_DT_STRING, Id, |
| 392 | pStringDesc, StringDesc.bLength)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 393 | kfree(pStringDesc); |
| 394 | return 0; |
| 395 | } |
| 396 | |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 397 | unicode_to_ascii(string, buflen, |
| 398 | pStringDesc->wData, pStringDesc->bLength/2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 399 | |
| 400 | kfree(pStringDesc); |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 401 | dbg("%s - USB String %s", __func__, string); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 402 | return strlen(string); |
| 403 | } |
| 404 | |
| 405 | |
| 406 | #if 0 |
| 407 | /************************************************************************ |
| 408 | * |
| 409 | * Get string descriptor from device |
| 410 | * |
| 411 | ************************************************************************/ |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 412 | static int get_string_desc(struct usb_device *dev, int Id, |
| 413 | struct usb_string_descriptor **pRetDesc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 414 | { |
| 415 | struct usb_string_descriptor StringDesc; |
| 416 | struct usb_string_descriptor *pStringDesc; |
| 417 | |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 418 | dbg("%s - USB String ID = %d", __func__, Id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 419 | |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 420 | if (!usb_get_descriptor(dev, USB_DT_STRING, Id, &StringDesc, |
| 421 | sizeof(StringDesc))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 422 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 423 | |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 424 | pStringDesc = kmalloc(StringDesc.bLength, GFP_KERNEL); |
| 425 | if (!pStringDesc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 426 | return -1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 427 | |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 428 | if (!usb_get_descriptor(dev, USB_DT_STRING, Id, pStringDesc, |
| 429 | StringDesc.bLength)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 430 | kfree(pStringDesc); |
| 431 | return -1; |
| 432 | } |
| 433 | |
| 434 | *pRetDesc = pStringDesc; |
| 435 | return 0; |
| 436 | } |
| 437 | #endif |
| 438 | |
Greg Kroah-Hartman | 6e8cf77 | 2007-01-18 00:20:19 -0800 | [diff] [blame] | 439 | static void dump_product_info(struct edgeport_product_info *product_info) |
| 440 | { |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 441 | /* Dump Product Info structure */ |
Greg Kroah-Hartman | 6e8cf77 | 2007-01-18 00:20:19 -0800 | [diff] [blame] | 442 | dbg("**Product Information:"); |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 443 | dbg(" ProductId %x", product_info->ProductId); |
| 444 | dbg(" NumPorts %d", product_info->NumPorts); |
| 445 | dbg(" ProdInfoVer %d", product_info->ProdInfoVer); |
Greg Kroah-Hartman | 6e8cf77 | 2007-01-18 00:20:19 -0800 | [diff] [blame] | 446 | dbg(" IsServer %d", product_info->IsServer); |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 447 | dbg(" IsRS232 %d", product_info->IsRS232); |
| 448 | dbg(" IsRS422 %d", product_info->IsRS422); |
| 449 | dbg(" IsRS485 %d", product_info->IsRS485); |
| 450 | dbg(" RomSize %d", product_info->RomSize); |
| 451 | dbg(" RamSize %d", product_info->RamSize); |
| 452 | dbg(" CpuRev %x", product_info->CpuRev); |
Greg Kroah-Hartman | 6e8cf77 | 2007-01-18 00:20:19 -0800 | [diff] [blame] | 453 | dbg(" BoardRev %x", product_info->BoardRev); |
| 454 | dbg(" BootMajorVersion %d.%d.%d", product_info->BootMajorVersion, |
| 455 | product_info->BootMinorVersion, |
| 456 | le16_to_cpu(product_info->BootBuildNumber)); |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 457 | dbg(" FirmwareMajorVersion %d.%d.%d", |
| 458 | product_info->FirmwareMajorVersion, |
| 459 | product_info->FirmwareMinorVersion, |
| 460 | le16_to_cpu(product_info->FirmwareBuildNumber)); |
| 461 | dbg(" ManufactureDescDate %d/%d/%d", |
| 462 | product_info->ManufactureDescDate[0], |
| 463 | product_info->ManufactureDescDate[1], |
| 464 | product_info->ManufactureDescDate[2]+1900); |
Greg Kroah-Hartman | 6e8cf77 | 2007-01-18 00:20:19 -0800 | [diff] [blame] | 465 | dbg(" iDownloadFile 0x%x", product_info->iDownloadFile); |
| 466 | dbg(" EpicVer %d", product_info->EpicVer); |
| 467 | } |
| 468 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 469 | static void get_product_info(struct edgeport_serial *edge_serial) |
| 470 | { |
| 471 | struct edgeport_product_info *product_info = &edge_serial->product_info; |
| 472 | |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 473 | memset(product_info, 0, sizeof(struct edgeport_product_info)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 474 | |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 475 | product_info->ProductId = (__u16)(le16_to_cpu(edge_serial->serial->dev->descriptor.idProduct) & ~ION_DEVICE_ID_80251_NETCHIP); |
| 476 | product_info->NumPorts = edge_serial->manuf_descriptor.NumPorts; |
| 477 | product_info->ProdInfoVer = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 478 | |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 479 | product_info->RomSize = edge_serial->manuf_descriptor.RomSize; |
| 480 | product_info->RamSize = edge_serial->manuf_descriptor.RamSize; |
| 481 | product_info->CpuRev = edge_serial->manuf_descriptor.CpuRev; |
| 482 | product_info->BoardRev = edge_serial->manuf_descriptor.BoardRev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 483 | |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 484 | product_info->BootMajorVersion = |
| 485 | edge_serial->boot_descriptor.MajorVersion; |
| 486 | product_info->BootMinorVersion = |
| 487 | edge_serial->boot_descriptor.MinorVersion; |
| 488 | product_info->BootBuildNumber = |
| 489 | edge_serial->boot_descriptor.BuildNumber; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 490 | |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 491 | memcpy(product_info->ManufactureDescDate, |
| 492 | edge_serial->manuf_descriptor.DescDate, |
| 493 | sizeof(edge_serial->manuf_descriptor.DescDate)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 494 | |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 495 | /* check if this is 2nd generation hardware */ |
| 496 | if (le16_to_cpu(edge_serial->serial->dev->descriptor.idProduct) |
| 497 | & ION_DEVICE_ID_80251_NETCHIP) |
| 498 | product_info->iDownloadFile = EDGE_DOWNLOAD_FILE_80251; |
| 499 | else |
| 500 | product_info->iDownloadFile = EDGE_DOWNLOAD_FILE_I930; |
| 501 | |
| 502 | /* Determine Product type and set appropriate flags */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 503 | switch (DEVICE_ID_FROM_USB_PRODUCT_ID(product_info->ProductId)) { |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 504 | case ION_DEVICE_ID_EDGEPORT_COMPATIBLE: |
| 505 | case ION_DEVICE_ID_EDGEPORT_4T: |
| 506 | case ION_DEVICE_ID_EDGEPORT_4: |
| 507 | case ION_DEVICE_ID_EDGEPORT_2: |
| 508 | case ION_DEVICE_ID_EDGEPORT_8_DUAL_CPU: |
| 509 | case ION_DEVICE_ID_EDGEPORT_8: |
| 510 | case ION_DEVICE_ID_EDGEPORT_421: |
| 511 | case ION_DEVICE_ID_EDGEPORT_21: |
| 512 | case ION_DEVICE_ID_EDGEPORT_2_DIN: |
| 513 | case ION_DEVICE_ID_EDGEPORT_4_DIN: |
| 514 | case ION_DEVICE_ID_EDGEPORT_16_DUAL_CPU: |
| 515 | product_info->IsRS232 = 1; |
| 516 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 517 | |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 518 | case ION_DEVICE_ID_EDGEPORT_2I: /* Edgeport/2 RS422/RS485 */ |
| 519 | product_info->IsRS422 = 1; |
| 520 | product_info->IsRS485 = 1; |
| 521 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 522 | |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 523 | case ION_DEVICE_ID_EDGEPORT_8I: /* Edgeport/4 RS422 */ |
| 524 | case ION_DEVICE_ID_EDGEPORT_4I: /* Edgeport/4 RS422 */ |
| 525 | product_info->IsRS422 = 1; |
| 526 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 527 | } |
| 528 | |
Greg Kroah-Hartman | 6e8cf77 | 2007-01-18 00:20:19 -0800 | [diff] [blame] | 529 | dump_product_info(product_info); |
| 530 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 531 | |
Greg Kroah-Hartman | 6e8cf77 | 2007-01-18 00:20:19 -0800 | [diff] [blame] | 532 | static int get_epic_descriptor(struct edgeport_serial *ep) |
| 533 | { |
| 534 | int result; |
| 535 | struct usb_serial *serial = ep->serial; |
| 536 | struct edgeport_product_info *product_info = &ep->product_info; |
| 537 | struct edge_compatibility_descriptor *epic = &ep->epic_descriptor; |
| 538 | struct edge_compatibility_bits *bits; |
| 539 | |
| 540 | ep->is_epic = 0; |
| 541 | result = usb_control_msg(serial->dev, usb_rcvctrlpipe(serial->dev, 0), |
| 542 | USB_REQUEST_ION_GET_EPIC_DESC, |
| 543 | 0xC0, 0x00, 0x00, |
| 544 | &ep->epic_descriptor, |
| 545 | sizeof(struct edge_compatibility_descriptor), |
| 546 | 300); |
| 547 | |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 548 | dbg("%s result = %d", __func__, result); |
Greg Kroah-Hartman | 6e8cf77 | 2007-01-18 00:20:19 -0800 | [diff] [blame] | 549 | |
| 550 | if (result > 0) { |
| 551 | ep->is_epic = 1; |
| 552 | memset(product_info, 0, sizeof(struct edgeport_product_info)); |
| 553 | |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 554 | product_info->NumPorts = epic->NumPorts; |
| 555 | product_info->ProdInfoVer = 0; |
| 556 | product_info->FirmwareMajorVersion = epic->MajorVersion; |
| 557 | product_info->FirmwareMinorVersion = epic->MinorVersion; |
| 558 | product_info->FirmwareBuildNumber = epic->BuildNumber; |
| 559 | product_info->iDownloadFile = epic->iDownloadFile; |
| 560 | product_info->EpicVer = epic->EpicVer; |
| 561 | product_info->Epic = epic->Supports; |
| 562 | product_info->ProductId = ION_DEVICE_ID_EDGEPORT_COMPATIBLE; |
Greg Kroah-Hartman | 6e8cf77 | 2007-01-18 00:20:19 -0800 | [diff] [blame] | 563 | dump_product_info(product_info); |
| 564 | |
| 565 | bits = &ep->epic_descriptor.Supports; |
| 566 | dbg("**EPIC descriptor:"); |
| 567 | dbg(" VendEnableSuspend: %s", bits->VendEnableSuspend ? "TRUE": "FALSE"); |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 568 | dbg(" IOSPOpen : %s", bits->IOSPOpen ? "TRUE": "FALSE"); |
| 569 | dbg(" IOSPClose : %s", bits->IOSPClose ? "TRUE": "FALSE"); |
| 570 | dbg(" IOSPChase : %s", bits->IOSPChase ? "TRUE": "FALSE"); |
| 571 | dbg(" IOSPSetRxFlow : %s", bits->IOSPSetRxFlow ? "TRUE": "FALSE"); |
| 572 | dbg(" IOSPSetTxFlow : %s", bits->IOSPSetTxFlow ? "TRUE": "FALSE"); |
| 573 | dbg(" IOSPSetXChar : %s", bits->IOSPSetXChar ? "TRUE": "FALSE"); |
| 574 | dbg(" IOSPRxCheck : %s", bits->IOSPRxCheck ? "TRUE": "FALSE"); |
| 575 | dbg(" IOSPSetClrBreak : %s", bits->IOSPSetClrBreak ? "TRUE": "FALSE"); |
| 576 | dbg(" IOSPWriteMCR : %s", bits->IOSPWriteMCR ? "TRUE": "FALSE"); |
| 577 | dbg(" IOSPWriteLCR : %s", bits->IOSPWriteLCR ? "TRUE": "FALSE"); |
| 578 | dbg(" IOSPSetBaudRate : %s", bits->IOSPSetBaudRate ? "TRUE": "FALSE"); |
| 579 | dbg(" TrueEdgeport : %s", bits->TrueEdgeport ? "TRUE": "FALSE"); |
Greg Kroah-Hartman | 6e8cf77 | 2007-01-18 00:20:19 -0800 | [diff] [blame] | 580 | } |
| 581 | |
| 582 | return result; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 583 | } |
| 584 | |
| 585 | |
| 586 | /************************************************************************/ |
| 587 | /************************************************************************/ |
| 588 | /* U S B C A L L B A C K F U N C T I O N S */ |
| 589 | /* U S B C A L L B A C K F U N C T I O N S */ |
| 590 | /************************************************************************/ |
| 591 | /************************************************************************/ |
| 592 | |
| 593 | /***************************************************************************** |
| 594 | * edge_interrupt_callback |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 595 | * this is the callback function for when we have received data on the |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 596 | * interrupt endpoint. |
| 597 | *****************************************************************************/ |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 598 | static void edge_interrupt_callback(struct urb *urb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 599 | { |
Ming Lei | cdc9779 | 2008-02-24 18:41:47 +0800 | [diff] [blame] | 600 | struct edgeport_serial *edge_serial = urb->context; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 601 | struct edgeport_port *edge_port; |
| 602 | struct usb_serial_port *port; |
Alan Cox | 4a90f09 | 2008-10-13 10:39:46 +0100 | [diff] [blame] | 603 | struct tty_struct *tty; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 604 | unsigned char *data = urb->transfer_buffer; |
| 605 | int length = urb->actual_length; |
| 606 | int bytes_avail; |
| 607 | int position; |
| 608 | int txCredits; |
| 609 | int portNumber; |
| 610 | int result; |
Greg Kroah-Hartman | 2a393f5 | 2007-06-15 15:44:13 -0700 | [diff] [blame] | 611 | int status = urb->status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 612 | |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 613 | dbg("%s", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 614 | |
Greg Kroah-Hartman | 2a393f5 | 2007-06-15 15:44:13 -0700 | [diff] [blame] | 615 | switch (status) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 616 | case 0: |
| 617 | /* success */ |
| 618 | break; |
| 619 | case -ECONNRESET: |
| 620 | case -ENOENT: |
| 621 | case -ESHUTDOWN: |
| 622 | /* this urb is terminated, clean up */ |
Greg Kroah-Hartman | 2a393f5 | 2007-06-15 15:44:13 -0700 | [diff] [blame] | 623 | dbg("%s - urb shutting down with status: %d", |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 624 | __func__, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 625 | return; |
| 626 | default: |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 627 | dbg("%s - nonzero urb status received: %d", __func__, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 628 | goto exit; |
| 629 | } |
| 630 | |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 631 | /* process this interrupt-read even if there are no ports open */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 632 | if (length) { |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 633 | usb_serial_debug_data(debug, &edge_serial->serial->dev->dev, |
| 634 | __func__, length, data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 635 | |
| 636 | if (length > 1) { |
| 637 | bytes_avail = data[0] | (data[1] << 8); |
| 638 | if (bytes_avail) { |
| 639 | spin_lock(&edge_serial->es_lock); |
| 640 | edge_serial->rxBytesAvail += bytes_avail; |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 641 | dbg("%s - bytes_avail=%d, rxBytesAvail=%d, read_in_progress=%d", __func__, bytes_avail, edge_serial->rxBytesAvail, edge_serial->read_in_progress); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 642 | |
| 643 | if (edge_serial->rxBytesAvail > 0 && |
| 644 | !edge_serial->read_in_progress) { |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 645 | dbg("%s - posting a read", __func__); |
Richard Knutsson | cb8eaa8 | 2007-03-17 01:35:53 +0100 | [diff] [blame] | 646 | edge_serial->read_in_progress = true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 647 | |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 648 | /* we have pending bytes on the |
| 649 | bulk in pipe, send a request */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 650 | edge_serial->read_urb->dev = edge_serial->serial->dev; |
| 651 | result = usb_submit_urb(edge_serial->read_urb, GFP_ATOMIC); |
| 652 | if (result) { |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 653 | dev_err(&edge_serial->serial->dev->dev, "%s - usb_submit_urb(read bulk) failed with result = %d\n", __func__, result); |
Richard Knutsson | cb8eaa8 | 2007-03-17 01:35:53 +0100 | [diff] [blame] | 654 | edge_serial->read_in_progress = false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 655 | } |
| 656 | } |
| 657 | spin_unlock(&edge_serial->es_lock); |
| 658 | } |
| 659 | } |
| 660 | /* grab the txcredits for the ports if available */ |
| 661 | position = 2; |
| 662 | portNumber = 0; |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 663 | while ((position < length) && |
| 664 | (portNumber < edge_serial->serial->num_ports)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 665 | txCredits = data[position] | (data[position+1] << 8); |
| 666 | if (txCredits) { |
| 667 | port = edge_serial->serial->port[portNumber]; |
| 668 | edge_port = usb_get_serial_port_data(port); |
| 669 | if (edge_port->open) { |
| 670 | spin_lock(&edge_port->ep_lock); |
| 671 | edge_port->txCredits += txCredits; |
| 672 | spin_unlock(&edge_port->ep_lock); |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 673 | dbg("%s - txcredits for port%d = %d", |
| 674 | __func__, portNumber, |
| 675 | edge_port->txCredits); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 676 | |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 677 | /* tell the tty driver that something |
| 678 | has changed */ |
Alan Cox | 4a90f09 | 2008-10-13 10:39:46 +0100 | [diff] [blame] | 679 | tty = tty_port_tty_get( |
| 680 | &edge_port->port->port); |
| 681 | if (tty) { |
| 682 | tty_wakeup(tty); |
| 683 | tty_kref_put(tty); |
| 684 | } |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 685 | /* Since we have more credit, check |
| 686 | if more data can be sent */ |
| 687 | send_more_port_data(edge_serial, |
| 688 | edge_port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 689 | } |
| 690 | } |
| 691 | position += 2; |
| 692 | ++portNumber; |
| 693 | } |
| 694 | } |
| 695 | |
| 696 | exit: |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 697 | result = usb_submit_urb(urb, GFP_ATOMIC); |
| 698 | if (result) |
| 699 | dev_err(&urb->dev->dev, |
| 700 | "%s - Error %d submitting control urb\n", |
| 701 | __func__, result); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 702 | } |
| 703 | |
| 704 | |
| 705 | /***************************************************************************** |
| 706 | * edge_bulk_in_callback |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 707 | * this is the callback function for when we have received data on the |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 708 | * bulk in endpoint. |
| 709 | *****************************************************************************/ |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 710 | static void edge_bulk_in_callback(struct urb *urb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 711 | { |
Ming Lei | cdc9779 | 2008-02-24 18:41:47 +0800 | [diff] [blame] | 712 | struct edgeport_serial *edge_serial = urb->context; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 713 | unsigned char *data = urb->transfer_buffer; |
Greg Kroah-Hartman | 2a393f5 | 2007-06-15 15:44:13 -0700 | [diff] [blame] | 714 | int retval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 715 | __u16 raw_data_length; |
Greg Kroah-Hartman | 2a393f5 | 2007-06-15 15:44:13 -0700 | [diff] [blame] | 716 | int status = urb->status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 717 | |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 718 | dbg("%s", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 719 | |
Greg Kroah-Hartman | 2a393f5 | 2007-06-15 15:44:13 -0700 | [diff] [blame] | 720 | if (status) { |
| 721 | dbg("%s - nonzero read bulk status received: %d", |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 722 | __func__, status); |
Richard Knutsson | cb8eaa8 | 2007-03-17 01:35:53 +0100 | [diff] [blame] | 723 | edge_serial->read_in_progress = false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 724 | return; |
| 725 | } |
| 726 | |
| 727 | if (urb->actual_length == 0) { |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 728 | dbg("%s - read bulk callback with no data", __func__); |
Richard Knutsson | cb8eaa8 | 2007-03-17 01:35:53 +0100 | [diff] [blame] | 729 | edge_serial->read_in_progress = false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 730 | return; |
| 731 | } |
| 732 | |
| 733 | raw_data_length = urb->actual_length; |
| 734 | |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 735 | usb_serial_debug_data(debug, &edge_serial->serial->dev->dev, |
| 736 | __func__, raw_data_length, data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 737 | |
| 738 | spin_lock(&edge_serial->es_lock); |
| 739 | |
| 740 | /* decrement our rxBytes available by the number that we just got */ |
| 741 | edge_serial->rxBytesAvail -= raw_data_length; |
| 742 | |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 743 | dbg("%s - Received = %d, rxBytesAvail %d", __func__, |
| 744 | raw_data_length, edge_serial->rxBytesAvail); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 745 | |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 746 | process_rcvd_data(edge_serial, data, urb->actual_length); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 747 | |
| 748 | /* check to see if there's any more data for us to read */ |
| 749 | if (edge_serial->rxBytesAvail > 0) { |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 750 | dbg("%s - posting a read", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 751 | edge_serial->read_urb->dev = edge_serial->serial->dev; |
Greg Kroah-Hartman | 2a393f5 | 2007-06-15 15:44:13 -0700 | [diff] [blame] | 752 | retval = usb_submit_urb(edge_serial->read_urb, GFP_ATOMIC); |
| 753 | if (retval) { |
| 754 | dev_err(&urb->dev->dev, |
| 755 | "%s - usb_submit_urb(read bulk) failed, " |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 756 | "retval = %d\n", __func__, retval); |
Richard Knutsson | cb8eaa8 | 2007-03-17 01:35:53 +0100 | [diff] [blame] | 757 | edge_serial->read_in_progress = false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 758 | } |
| 759 | } else { |
Richard Knutsson | cb8eaa8 | 2007-03-17 01:35:53 +0100 | [diff] [blame] | 760 | edge_serial->read_in_progress = false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 761 | } |
| 762 | |
| 763 | spin_unlock(&edge_serial->es_lock); |
| 764 | } |
| 765 | |
| 766 | |
| 767 | /***************************************************************************** |
| 768 | * edge_bulk_out_data_callback |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 769 | * this is the callback function for when we have finished sending |
| 770 | * serial data on the bulk out endpoint. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 771 | *****************************************************************************/ |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 772 | static void edge_bulk_out_data_callback(struct urb *urb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 773 | { |
Ming Lei | cdc9779 | 2008-02-24 18:41:47 +0800 | [diff] [blame] | 774 | struct edgeport_port *edge_port = urb->context; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 775 | struct tty_struct *tty; |
Greg Kroah-Hartman | 2a393f5 | 2007-06-15 15:44:13 -0700 | [diff] [blame] | 776 | int status = urb->status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 777 | |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 778 | dbg("%s", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 779 | |
Greg Kroah-Hartman | 2a393f5 | 2007-06-15 15:44:13 -0700 | [diff] [blame] | 780 | if (status) { |
| 781 | dbg("%s - nonzero write bulk status received: %d", |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 782 | __func__, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 783 | } |
| 784 | |
Alan Cox | 4a90f09 | 2008-10-13 10:39:46 +0100 | [diff] [blame] | 785 | tty = tty_port_tty_get(&edge_port->port->port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 786 | |
| 787 | if (tty && edge_port->open) { |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 788 | /* let the tty driver wakeup if it has a special |
| 789 | write_wakeup function */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 790 | tty_wakeup(tty); |
| 791 | } |
Alan Cox | 4a90f09 | 2008-10-13 10:39:46 +0100 | [diff] [blame] | 792 | tty_kref_put(tty); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 793 | |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 794 | /* Release the Write URB */ |
Richard Knutsson | cb8eaa8 | 2007-03-17 01:35:53 +0100 | [diff] [blame] | 795 | edge_port->write_in_progress = false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 796 | |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 797 | /* Check if more data needs to be sent */ |
| 798 | send_more_port_data((struct edgeport_serial *) |
| 799 | (usb_get_serial_data(edge_port->port->serial)), edge_port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 800 | } |
| 801 | |
| 802 | |
| 803 | /***************************************************************************** |
| 804 | * BulkOutCmdCallback |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 805 | * this is the callback function for when we have finished sending a |
| 806 | * command on the bulk out endpoint. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 807 | *****************************************************************************/ |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 808 | static void edge_bulk_out_cmd_callback(struct urb *urb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 809 | { |
Ming Lei | cdc9779 | 2008-02-24 18:41:47 +0800 | [diff] [blame] | 810 | struct edgeport_port *edge_port = urb->context; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 811 | struct tty_struct *tty; |
| 812 | int status = urb->status; |
| 813 | |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 814 | dbg("%s", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 815 | |
Oliver Neukum | 96c706e | 2007-03-15 15:27:17 +0100 | [diff] [blame] | 816 | atomic_dec(&CmdUrbs); |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 817 | dbg("%s - FREE URB %p (outstanding %d)", __func__, |
| 818 | urb, atomic_read(&CmdUrbs)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 819 | |
| 820 | |
| 821 | /* clean up the transfer buffer */ |
Jesper Juhl | 1bc3c9e | 2005-04-18 17:39:34 -0700 | [diff] [blame] | 822 | kfree(urb->transfer_buffer); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 823 | |
| 824 | /* Free the command urb */ |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 825 | usb_free_urb(urb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 826 | |
| 827 | if (status) { |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 828 | dbg("%s - nonzero write bulk status received: %d", |
| 829 | __func__, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 830 | return; |
| 831 | } |
| 832 | |
| 833 | /* Get pointer to tty */ |
Alan Cox | 4a90f09 | 2008-10-13 10:39:46 +0100 | [diff] [blame] | 834 | tty = tty_port_tty_get(&edge_port->port->port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 835 | |
| 836 | /* tell the tty driver that something has changed */ |
| 837 | if (tty && edge_port->open) |
| 838 | tty_wakeup(tty); |
Alan Cox | 4a90f09 | 2008-10-13 10:39:46 +0100 | [diff] [blame] | 839 | tty_kref_put(tty); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 840 | |
| 841 | /* we have completed the command */ |
Richard Knutsson | cb8eaa8 | 2007-03-17 01:35:53 +0100 | [diff] [blame] | 842 | edge_port->commandPending = false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 843 | wake_up(&edge_port->wait_command); |
| 844 | } |
| 845 | |
| 846 | |
| 847 | /***************************************************************************** |
| 848 | * Driver tty interface functions |
| 849 | *****************************************************************************/ |
| 850 | |
| 851 | /***************************************************************************** |
| 852 | * SerialOpen |
| 853 | * this function is called by the tty driver when a port is opened |
| 854 | * If successful, we return 0 |
| 855 | * Otherwise we return a negative error number. |
| 856 | *****************************************************************************/ |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 857 | static int edge_open(struct tty_struct *tty, |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 858 | struct usb_serial_port *port, struct file *filp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 859 | { |
| 860 | struct edgeport_port *edge_port = usb_get_serial_port_data(port); |
| 861 | struct usb_serial *serial; |
| 862 | struct edgeport_serial *edge_serial; |
| 863 | int response; |
| 864 | |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 865 | dbg("%s - port %d", __func__, port->number); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 866 | |
| 867 | if (edge_port == NULL) |
| 868 | return -ENODEV; |
| 869 | |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 870 | if (tty) |
| 871 | tty->low_latency = low_latency; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 872 | |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 873 | /* see if we've set up our endpoint info yet (can't set it up |
| 874 | in edge_startup as the structures were not set up at that time.) */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 875 | serial = port->serial; |
| 876 | edge_serial = usb_get_serial_data(serial); |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 877 | if (edge_serial == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 878 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 879 | if (edge_serial->interrupt_in_buffer == NULL) { |
| 880 | struct usb_serial_port *port0 = serial->port[0]; |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 881 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 882 | /* not set up yet, so do it now */ |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 883 | edge_serial->interrupt_in_buffer = |
| 884 | port0->interrupt_in_buffer; |
| 885 | edge_serial->interrupt_in_endpoint = |
| 886 | port0->interrupt_in_endpointAddress; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 887 | edge_serial->interrupt_read_urb = port0->interrupt_in_urb; |
| 888 | edge_serial->bulk_in_buffer = port0->bulk_in_buffer; |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 889 | edge_serial->bulk_in_endpoint = |
| 890 | port0->bulk_in_endpointAddress; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 891 | edge_serial->read_urb = port0->read_urb; |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 892 | edge_serial->bulk_out_endpoint = |
| 893 | port0->bulk_out_endpointAddress; |
| 894 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 895 | /* set up our interrupt urb */ |
| 896 | usb_fill_int_urb(edge_serial->interrupt_read_urb, |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 897 | serial->dev, |
| 898 | usb_rcvintpipe(serial->dev, |
| 899 | port0->interrupt_in_endpointAddress), |
| 900 | port0->interrupt_in_buffer, |
| 901 | edge_serial->interrupt_read_urb->transfer_buffer_length, |
| 902 | edge_interrupt_callback, edge_serial, |
| 903 | edge_serial->interrupt_read_urb->interval); |
| 904 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 905 | /* set up our bulk in urb */ |
| 906 | usb_fill_bulk_urb(edge_serial->read_urb, serial->dev, |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 907 | usb_rcvbulkpipe(serial->dev, |
| 908 | port0->bulk_in_endpointAddress), |
| 909 | port0->bulk_in_buffer, |
| 910 | edge_serial->read_urb->transfer_buffer_length, |
| 911 | edge_bulk_in_callback, edge_serial); |
Richard Knutsson | cb8eaa8 | 2007-03-17 01:35:53 +0100 | [diff] [blame] | 912 | edge_serial->read_in_progress = false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 913 | |
| 914 | /* start interrupt read for this edgeport |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 915 | * this interrupt will continue as long |
| 916 | * as the edgeport is connected */ |
| 917 | response = usb_submit_urb(edge_serial->interrupt_read_urb, |
| 918 | GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 919 | if (response) { |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 920 | dev_err(&port->dev, |
| 921 | "%s - Error %d submitting control urb\n", |
| 922 | __func__, response); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 923 | } |
| 924 | } |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 925 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 926 | /* initialize our wait queues */ |
| 927 | init_waitqueue_head(&edge_port->wait_open); |
| 928 | init_waitqueue_head(&edge_port->wait_chase); |
| 929 | init_waitqueue_head(&edge_port->delta_msr_wait); |
| 930 | init_waitqueue_head(&edge_port->wait_command); |
| 931 | |
| 932 | /* initialize our icount structure */ |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 933 | memset(&(edge_port->icount), 0x00, sizeof(edge_port->icount)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 934 | |
| 935 | /* initialize our port settings */ |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 936 | edge_port->txCredits = 0; /* Can't send any data yet */ |
| 937 | /* Must always set this bit to enable ints! */ |
| 938 | edge_port->shadowMCR = MCR_MASTER_IE; |
Richard Knutsson | cb8eaa8 | 2007-03-17 01:35:53 +0100 | [diff] [blame] | 939 | edge_port->chaseResponsePending = false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 940 | |
| 941 | /* send a open port command */ |
Richard Knutsson | cb8eaa8 | 2007-03-17 01:35:53 +0100 | [diff] [blame] | 942 | edge_port->openPending = true; |
| 943 | edge_port->open = false; |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 944 | response = send_iosp_ext_cmd(edge_port, IOSP_CMD_OPEN_PORT, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 945 | |
| 946 | if (response < 0) { |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 947 | dev_err(&port->dev, "%s - error sending open port command\n", |
| 948 | __func__); |
Richard Knutsson | cb8eaa8 | 2007-03-17 01:35:53 +0100 | [diff] [blame] | 949 | edge_port->openPending = false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 950 | return -ENODEV; |
| 951 | } |
| 952 | |
| 953 | /* now wait for the port to be completely opened */ |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 954 | wait_event_timeout(edge_port->wait_open, !edge_port->openPending, |
| 955 | OPEN_TIMEOUT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 956 | |
Richard Knutsson | cb8eaa8 | 2007-03-17 01:35:53 +0100 | [diff] [blame] | 957 | if (!edge_port->open) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 958 | /* open timed out */ |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 959 | dbg("%s - open timedout", __func__); |
Richard Knutsson | cb8eaa8 | 2007-03-17 01:35:53 +0100 | [diff] [blame] | 960 | edge_port->openPending = false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 961 | return -ENODEV; |
| 962 | } |
| 963 | |
| 964 | /* create the txfifo */ |
| 965 | edge_port->txfifo.head = 0; |
| 966 | edge_port->txfifo.tail = 0; |
| 967 | edge_port->txfifo.count = 0; |
| 968 | edge_port->txfifo.size = edge_port->maxTxCredits; |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 969 | edge_port->txfifo.fifo = kmalloc(edge_port->maxTxCredits, GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 970 | |
| 971 | if (!edge_port->txfifo.fifo) { |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 972 | dbg("%s - no memory", __func__); |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 973 | edge_close(tty, port, filp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 974 | return -ENOMEM; |
| 975 | } |
| 976 | |
| 977 | /* Allocate a URB for the write */ |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 978 | edge_port->write_urb = usb_alloc_urb(0, GFP_KERNEL); |
Richard Knutsson | cb8eaa8 | 2007-03-17 01:35:53 +0100 | [diff] [blame] | 979 | edge_port->write_in_progress = false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 980 | |
| 981 | if (!edge_port->write_urb) { |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 982 | dbg("%s - no memory", __func__); |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 983 | edge_close(tty, port, filp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 984 | return -ENOMEM; |
| 985 | } |
| 986 | |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 987 | dbg("%s(%d) - Initialize TX fifo to %d bytes", |
| 988 | __func__, port->number, edge_port->maxTxCredits); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 989 | |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 990 | dbg("%s exited", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 991 | |
| 992 | return 0; |
| 993 | } |
| 994 | |
| 995 | |
| 996 | /************************************************************************ |
| 997 | * |
| 998 | * block_until_chase_response |
| 999 | * |
| 1000 | * This function will block the close until one of the following: |
| 1001 | * 1. Response to our Chase comes from Edgeport |
Joe Perches | dc0d5c1 | 2007-12-17 11:40:18 -0800 | [diff] [blame] | 1002 | * 2. A timeout of 10 seconds without activity has expired |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1003 | * (1K of Edgeport data @ 2400 baud ==> 4 sec to empty) |
| 1004 | * |
| 1005 | ************************************************************************/ |
| 1006 | static void block_until_chase_response(struct edgeport_port *edge_port) |
| 1007 | { |
| 1008 | DEFINE_WAIT(wait); |
| 1009 | __u16 lastCredits; |
| 1010 | int timeout = 1*HZ; |
| 1011 | int loop = 10; |
| 1012 | |
| 1013 | while (1) { |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 1014 | /* Save Last credits */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1015 | lastCredits = edge_port->txCredits; |
| 1016 | |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 1017 | /* Did we get our Chase response */ |
Richard Knutsson | cb8eaa8 | 2007-03-17 01:35:53 +0100 | [diff] [blame] | 1018 | if (!edge_port->chaseResponsePending) { |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 1019 | dbg("%s - Got Chase Response", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1020 | |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 1021 | /* did we get all of our credit back? */ |
| 1022 | if (edge_port->txCredits == edge_port->maxTxCredits) { |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 1023 | dbg("%s - Got all credits", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1024 | return; |
| 1025 | } |
| 1026 | } |
| 1027 | |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 1028 | /* Block the thread for a while */ |
| 1029 | prepare_to_wait(&edge_port->wait_chase, &wait, |
| 1030 | TASK_UNINTERRUPTIBLE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1031 | schedule_timeout(timeout); |
| 1032 | finish_wait(&edge_port->wait_chase, &wait); |
| 1033 | |
| 1034 | if (lastCredits == edge_port->txCredits) { |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 1035 | /* No activity.. count down. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1036 | loop--; |
| 1037 | if (loop == 0) { |
Richard Knutsson | cb8eaa8 | 2007-03-17 01:35:53 +0100 | [diff] [blame] | 1038 | edge_port->chaseResponsePending = false; |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 1039 | dbg("%s - Chase TIMEOUT", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1040 | return; |
| 1041 | } |
| 1042 | } else { |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 1043 | /* Reset timeout value back to 10 seconds */ |
| 1044 | dbg("%s - Last %d, Current %d", __func__, |
| 1045 | lastCredits, edge_port->txCredits); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1046 | loop = 10; |
| 1047 | } |
| 1048 | } |
| 1049 | } |
| 1050 | |
| 1051 | |
| 1052 | /************************************************************************ |
| 1053 | * |
| 1054 | * block_until_tx_empty |
| 1055 | * |
| 1056 | * This function will block the close until one of the following: |
| 1057 | * 1. TX count are 0 |
| 1058 | * 2. The edgeport has stopped |
Joe Perches | dc0d5c1 | 2007-12-17 11:40:18 -0800 | [diff] [blame] | 1059 | * 3. A timeout of 3 seconds without activity has expired |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1060 | * |
| 1061 | ************************************************************************/ |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 1062 | static void block_until_tx_empty(struct edgeport_port *edge_port) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1063 | { |
| 1064 | DEFINE_WAIT(wait); |
| 1065 | struct TxFifo *fifo = &edge_port->txfifo; |
| 1066 | __u32 lastCount; |
| 1067 | int timeout = HZ/10; |
| 1068 | int loop = 30; |
| 1069 | |
| 1070 | while (1) { |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 1071 | /* Save Last count */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1072 | lastCount = fifo->count; |
| 1073 | |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 1074 | /* Is the Edgeport Buffer empty? */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1075 | if (lastCount == 0) { |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 1076 | dbg("%s - TX Buffer Empty", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1077 | return; |
| 1078 | } |
| 1079 | |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 1080 | /* Block the thread for a while */ |
| 1081 | prepare_to_wait(&edge_port->wait_chase, &wait, |
| 1082 | TASK_UNINTERRUPTIBLE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1083 | schedule_timeout(timeout); |
| 1084 | finish_wait(&edge_port->wait_chase, &wait); |
| 1085 | |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 1086 | dbg("%s wait", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1087 | |
| 1088 | if (lastCount == fifo->count) { |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 1089 | /* No activity.. count down. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1090 | loop--; |
| 1091 | if (loop == 0) { |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 1092 | dbg("%s - TIMEOUT", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1093 | return; |
| 1094 | } |
| 1095 | } else { |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 1096 | /* Reset timeout value back to seconds */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1097 | loop = 30; |
| 1098 | } |
| 1099 | } |
| 1100 | } |
| 1101 | |
| 1102 | |
| 1103 | /***************************************************************************** |
| 1104 | * edge_close |
| 1105 | * this function is called by the tty driver when a port is closed |
| 1106 | *****************************************************************************/ |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 1107 | static void edge_close(struct tty_struct *tty, |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 1108 | struct usb_serial_port *port, struct file *filp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1109 | { |
| 1110 | struct edgeport_serial *edge_serial; |
| 1111 | struct edgeport_port *edge_port; |
| 1112 | int status; |
| 1113 | |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 1114 | dbg("%s - port %d", __func__, port->number); |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 1115 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1116 | edge_serial = usb_get_serial_data(port->serial); |
| 1117 | edge_port = usb_get_serial_port_data(port); |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 1118 | if (edge_serial == NULL || edge_port == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1119 | return; |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 1120 | |
| 1121 | /* block until tx is empty */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1122 | block_until_tx_empty(edge_port); |
| 1123 | |
Richard Knutsson | cb8eaa8 | 2007-03-17 01:35:53 +0100 | [diff] [blame] | 1124 | edge_port->closePending = true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1125 | |
Greg Kroah-Hartman | 6e8cf77 | 2007-01-18 00:20:19 -0800 | [diff] [blame] | 1126 | if ((!edge_serial->is_epic) || |
| 1127 | ((edge_serial->is_epic) && |
| 1128 | (edge_serial->epic_descriptor.Supports.IOSPChase))) { |
| 1129 | /* flush and chase */ |
Richard Knutsson | cb8eaa8 | 2007-03-17 01:35:53 +0100 | [diff] [blame] | 1130 | edge_port->chaseResponsePending = true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1131 | |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 1132 | dbg("%s - Sending IOSP_CMD_CHASE_PORT", __func__); |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 1133 | status = send_iosp_ext_cmd(edge_port, IOSP_CMD_CHASE_PORT, 0); |
| 1134 | if (status == 0) |
| 1135 | /* block until chase finished */ |
Greg Kroah-Hartman | 6e8cf77 | 2007-01-18 00:20:19 -0800 | [diff] [blame] | 1136 | block_until_chase_response(edge_port); |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 1137 | else |
Richard Knutsson | cb8eaa8 | 2007-03-17 01:35:53 +0100 | [diff] [blame] | 1138 | edge_port->chaseResponsePending = false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1139 | } |
| 1140 | |
Greg Kroah-Hartman | 6e8cf77 | 2007-01-18 00:20:19 -0800 | [diff] [blame] | 1141 | if ((!edge_serial->is_epic) || |
| 1142 | ((edge_serial->is_epic) && |
| 1143 | (edge_serial->epic_descriptor.Supports.IOSPClose))) { |
| 1144 | /* close the port */ |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 1145 | dbg("%s - Sending IOSP_CMD_CLOSE_PORT", __func__); |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 1146 | send_iosp_ext_cmd(edge_port, IOSP_CMD_CLOSE_PORT, 0); |
Greg Kroah-Hartman | 6e8cf77 | 2007-01-18 00:20:19 -0800 | [diff] [blame] | 1147 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1148 | |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 1149 | /* port->close = true; */ |
Richard Knutsson | cb8eaa8 | 2007-03-17 01:35:53 +0100 | [diff] [blame] | 1150 | edge_port->closePending = false; |
| 1151 | edge_port->open = false; |
| 1152 | edge_port->openPending = false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1153 | |
Mariusz Kozlowski | 9a25f44 | 2006-11-08 15:36:29 +0100 | [diff] [blame] | 1154 | usb_kill_urb(edge_port->write_urb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1155 | |
| 1156 | if (edge_port->write_urb) { |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 1157 | /* if this urb had a transfer buffer already |
| 1158 | (old transfer) free it */ |
Jesper Juhl | 1bc3c9e | 2005-04-18 17:39:34 -0700 | [diff] [blame] | 1159 | kfree(edge_port->write_urb->transfer_buffer); |
| 1160 | usb_free_urb(edge_port->write_urb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1161 | edge_port->write_urb = NULL; |
| 1162 | } |
Jesper Juhl | 1bc3c9e | 2005-04-18 17:39:34 -0700 | [diff] [blame] | 1163 | kfree(edge_port->txfifo.fifo); |
| 1164 | edge_port->txfifo.fifo = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1165 | |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 1166 | dbg("%s exited", __func__); |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 1167 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1168 | |
| 1169 | /***************************************************************************** |
| 1170 | * SerialWrite |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 1171 | * this function is called by the tty driver when data should be written |
| 1172 | * to the port. |
| 1173 | * If successful, we return the number of bytes written, otherwise we |
| 1174 | * return a negative error number. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1175 | *****************************************************************************/ |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 1176 | static int edge_write(struct tty_struct *tty, struct usb_serial_port *port, |
| 1177 | const unsigned char *data, int count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1178 | { |
| 1179 | struct edgeport_port *edge_port = usb_get_serial_port_data(port); |
| 1180 | struct TxFifo *fifo; |
| 1181 | int copySize; |
| 1182 | int bytesleft; |
| 1183 | int firsthalf; |
| 1184 | int secondhalf; |
| 1185 | unsigned long flags; |
| 1186 | |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 1187 | dbg("%s - port %d", __func__, port->number); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1188 | |
| 1189 | if (edge_port == NULL) |
| 1190 | return -ENODEV; |
| 1191 | |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 1192 | /* get a pointer to the Tx fifo */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1193 | fifo = &edge_port->txfifo; |
| 1194 | |
| 1195 | spin_lock_irqsave(&edge_port->ep_lock, flags); |
| 1196 | |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 1197 | /* calculate number of bytes to put in fifo */ |
| 1198 | copySize = min((unsigned int)count, |
| 1199 | (edge_port->txCredits - fifo->count)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1200 | |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 1201 | dbg("%s(%d) of %d byte(s) Fifo room %d -- will copy %d bytes", |
| 1202 | __func__, port->number, count, |
| 1203 | edge_port->txCredits - fifo->count, copySize); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1204 | |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 1205 | /* catch writes of 0 bytes which the tty driver likes to give us, |
| 1206 | and when txCredits is empty */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1207 | if (copySize == 0) { |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 1208 | dbg("%s - copySize = Zero", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1209 | goto finish_write; |
| 1210 | } |
| 1211 | |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 1212 | /* queue the data |
| 1213 | * since we can never overflow the buffer we do not have to check for a |
| 1214 | * full condition |
| 1215 | * |
| 1216 | * the copy is done is two parts -- first fill to the end of the buffer |
| 1217 | * then copy the reset from the start of the buffer |
| 1218 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1219 | bytesleft = fifo->size - fifo->head; |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 1220 | firsthalf = min(bytesleft, copySize); |
| 1221 | dbg("%s - copy %d bytes of %d into fifo ", __func__, |
| 1222 | firsthalf, bytesleft); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1223 | |
| 1224 | /* now copy our data */ |
| 1225 | memcpy(&fifo->fifo[fifo->head], data, firsthalf); |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 1226 | usb_serial_debug_data(debug, &port->dev, __func__, |
| 1227 | firsthalf, &fifo->fifo[fifo->head]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1228 | |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 1229 | /* update the index and size */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1230 | fifo->head += firsthalf; |
| 1231 | fifo->count += firsthalf; |
| 1232 | |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 1233 | /* wrap the index */ |
| 1234 | if (fifo->head == fifo->size) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1235 | fifo->head = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1236 | |
| 1237 | secondhalf = copySize-firsthalf; |
| 1238 | |
| 1239 | if (secondhalf) { |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 1240 | dbg("%s - copy rest of data %d", __func__, secondhalf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1241 | memcpy(&fifo->fifo[fifo->head], &data[firsthalf], secondhalf); |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 1242 | usb_serial_debug_data(debug, &port->dev, __func__, |
| 1243 | secondhalf, &fifo->fifo[fifo->head]); |
| 1244 | /* update the index and size */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1245 | fifo->count += secondhalf; |
| 1246 | fifo->head += secondhalf; |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 1247 | /* No need to check for wrap since we can not get to end of |
| 1248 | * the fifo in this part |
| 1249 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1250 | } |
| 1251 | |
| 1252 | finish_write: |
| 1253 | spin_unlock_irqrestore(&edge_port->ep_lock, flags); |
| 1254 | |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 1255 | send_more_port_data((struct edgeport_serial *) |
| 1256 | usb_get_serial_data(port->serial), edge_port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1257 | |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 1258 | dbg("%s wrote %d byte(s) TxCredits %d, Fifo %d", __func__, |
| 1259 | copySize, edge_port->txCredits, fifo->count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1260 | |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 1261 | return copySize; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1262 | } |
| 1263 | |
| 1264 | |
| 1265 | /************************************************************************ |
| 1266 | * |
| 1267 | * send_more_port_data() |
| 1268 | * |
| 1269 | * This routine attempts to write additional UART transmit data |
| 1270 | * to a port over the USB bulk pipe. It is called (1) when new |
| 1271 | * data has been written to a port's TxBuffer from higher layers |
| 1272 | * (2) when the peripheral sends us additional TxCredits indicating |
| 1273 | * that it can accept more Tx data for a given port; and (3) when |
| 1274 | * a bulk write completes successfully and we want to see if we |
| 1275 | * can transmit more. |
| 1276 | * |
| 1277 | ************************************************************************/ |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 1278 | static void send_more_port_data(struct edgeport_serial *edge_serial, |
| 1279 | struct edgeport_port *edge_port) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1280 | { |
| 1281 | struct TxFifo *fifo = &edge_port->txfifo; |
| 1282 | struct urb *urb; |
| 1283 | unsigned char *buffer; |
| 1284 | int status; |
| 1285 | int count; |
| 1286 | int bytesleft; |
| 1287 | int firsthalf; |
| 1288 | int secondhalf; |
| 1289 | unsigned long flags; |
| 1290 | |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 1291 | dbg("%s(%d)", __func__, edge_port->port->number); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1292 | |
| 1293 | spin_lock_irqsave(&edge_port->ep_lock, flags); |
| 1294 | |
| 1295 | if (edge_port->write_in_progress || |
| 1296 | !edge_port->open || |
| 1297 | (fifo->count == 0)) { |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 1298 | dbg("%s(%d) EXIT - fifo %d, PendingWrite = %d", |
| 1299 | __func__, edge_port->port->number, |
| 1300 | fifo->count, edge_port->write_in_progress); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1301 | goto exit_send; |
| 1302 | } |
| 1303 | |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 1304 | /* since the amount of data in the fifo will always fit into the |
| 1305 | * edgeport buffer we do not need to check the write length |
| 1306 | * |
| 1307 | * Do we have enough credits for this port to make it worthwhile |
| 1308 | * to bother queueing a write. If it's too small, say a few bytes, |
| 1309 | * it's better to wait for more credits so we can do a larger write. |
| 1310 | */ |
| 1311 | if (edge_port->txCredits < EDGE_FW_GET_TX_CREDITS_SEND_THRESHOLD(edge_port->maxTxCredits, EDGE_FW_BULK_MAX_PACKET_SIZE)) { |
| 1312 | dbg("%s(%d) Not enough credit - fifo %d TxCredit %d", |
| 1313 | __func__, edge_port->port->number, fifo->count, |
| 1314 | edge_port->txCredits); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1315 | goto exit_send; |
| 1316 | } |
| 1317 | |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 1318 | /* lock this write */ |
Richard Knutsson | cb8eaa8 | 2007-03-17 01:35:53 +0100 | [diff] [blame] | 1319 | edge_port->write_in_progress = true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1320 | |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 1321 | /* get a pointer to the write_urb */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1322 | urb = edge_port->write_urb; |
| 1323 | |
Jesper Juhl | 1bc3c9e | 2005-04-18 17:39:34 -0700 | [diff] [blame] | 1324 | /* make sure transfer buffer is freed */ |
| 1325 | kfree(urb->transfer_buffer); |
| 1326 | urb->transfer_buffer = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1327 | |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 1328 | /* build the data header for the buffer and port that we are about |
| 1329 | to send out */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1330 | count = fifo->count; |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 1331 | buffer = kmalloc(count+2, GFP_ATOMIC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1332 | if (buffer == NULL) { |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 1333 | dev_err(&edge_port->port->dev, |
| 1334 | "%s - no more kernel memory...\n", __func__); |
Richard Knutsson | cb8eaa8 | 2007-03-17 01:35:53 +0100 | [diff] [blame] | 1335 | edge_port->write_in_progress = false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1336 | goto exit_send; |
| 1337 | } |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 1338 | buffer[0] = IOSP_BUILD_DATA_HDR1(edge_port->port->number |
| 1339 | - edge_port->port->serial->minor, count); |
| 1340 | buffer[1] = IOSP_BUILD_DATA_HDR2(edge_port->port->number |
| 1341 | - edge_port->port->serial->minor, count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1342 | |
| 1343 | /* now copy our data */ |
| 1344 | bytesleft = fifo->size - fifo->tail; |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 1345 | firsthalf = min(bytesleft, count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1346 | memcpy(&buffer[2], &fifo->fifo[fifo->tail], firsthalf); |
| 1347 | fifo->tail += firsthalf; |
| 1348 | fifo->count -= firsthalf; |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 1349 | if (fifo->tail == fifo->size) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1350 | fifo->tail = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1351 | |
| 1352 | secondhalf = count-firsthalf; |
| 1353 | if (secondhalf) { |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 1354 | memcpy(&buffer[2+firsthalf], &fifo->fifo[fifo->tail], |
| 1355 | secondhalf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1356 | fifo->tail += secondhalf; |
| 1357 | fifo->count -= secondhalf; |
| 1358 | } |
| 1359 | |
| 1360 | if (count) |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 1361 | usb_serial_debug_data(debug, &edge_port->port->dev, |
| 1362 | __func__, count, &buffer[2]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1363 | |
| 1364 | /* fill up the urb with all of our data and submit it */ |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 1365 | usb_fill_bulk_urb(urb, edge_serial->serial->dev, |
| 1366 | usb_sndbulkpipe(edge_serial->serial->dev, |
| 1367 | edge_serial->bulk_out_endpoint), |
| 1368 | buffer, count+2, |
| 1369 | edge_bulk_out_data_callback, edge_port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1370 | |
| 1371 | /* decrement the number of credits we have by the number we just sent */ |
| 1372 | edge_port->txCredits -= count; |
| 1373 | edge_port->icount.tx += count; |
| 1374 | |
| 1375 | urb->dev = edge_serial->serial->dev; |
| 1376 | status = usb_submit_urb(urb, GFP_ATOMIC); |
| 1377 | if (status) { |
| 1378 | /* something went wrong */ |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 1379 | dev_err(&edge_port->port->dev, |
| 1380 | "%s - usb_submit_urb(write bulk) failed, status = %d, data lost\n", |
| 1381 | __func__, status); |
Richard Knutsson | cb8eaa8 | 2007-03-17 01:35:53 +0100 | [diff] [blame] | 1382 | edge_port->write_in_progress = false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1383 | |
| 1384 | /* revert the credits as something bad happened. */ |
| 1385 | edge_port->txCredits += count; |
| 1386 | edge_port->icount.tx -= count; |
| 1387 | } |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 1388 | dbg("%s wrote %d byte(s) TxCredit %d, Fifo %d", |
| 1389 | __func__, count, edge_port->txCredits, fifo->count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1390 | |
| 1391 | exit_send: |
| 1392 | spin_unlock_irqrestore(&edge_port->ep_lock, flags); |
| 1393 | } |
| 1394 | |
| 1395 | |
| 1396 | /***************************************************************************** |
| 1397 | * edge_write_room |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 1398 | * this function is called by the tty driver when it wants to know how |
| 1399 | * many bytes of data we can accept for a specific port. If successful, |
| 1400 | * we return the amount of room that we have for this port (the txCredits) |
| 1401 | * otherwise we return a negative error number. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1402 | *****************************************************************************/ |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 1403 | static int edge_write_room(struct tty_struct *tty) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1404 | { |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 1405 | struct usb_serial_port *port = tty->driver_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1406 | struct edgeport_port *edge_port = usb_get_serial_port_data(port); |
| 1407 | int room; |
| 1408 | unsigned long flags; |
| 1409 | |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 1410 | dbg("%s", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1411 | |
| 1412 | if (edge_port == NULL) |
Alan Cox | d76f2f4 | 2008-07-22 11:16:42 +0100 | [diff] [blame] | 1413 | return 0; |
Richard Knutsson | cb8eaa8 | 2007-03-17 01:35:53 +0100 | [diff] [blame] | 1414 | if (edge_port->closePending) |
Alan Cox | d76f2f4 | 2008-07-22 11:16:42 +0100 | [diff] [blame] | 1415 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1416 | |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 1417 | dbg("%s - port %d", __func__, port->number); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1418 | |
| 1419 | if (!edge_port->open) { |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 1420 | dbg("%s - port not opened", __func__); |
Alan Cox | d76f2f4 | 2008-07-22 11:16:42 +0100 | [diff] [blame] | 1421 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1422 | } |
| 1423 | |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 1424 | /* total of both buffers is still txCredit */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1425 | spin_lock_irqsave(&edge_port->ep_lock, flags); |
| 1426 | room = edge_port->txCredits - edge_port->txfifo.count; |
| 1427 | spin_unlock_irqrestore(&edge_port->ep_lock, flags); |
| 1428 | |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 1429 | dbg("%s - returns %d", __func__, room); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1430 | return room; |
| 1431 | } |
| 1432 | |
| 1433 | |
| 1434 | /***************************************************************************** |
| 1435 | * edge_chars_in_buffer |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 1436 | * this function is called by the tty driver when it wants to know how |
| 1437 | * many bytes of data we currently have outstanding in the port (data that |
| 1438 | * has been written, but hasn't made it out the port yet) |
| 1439 | * If successful, we return the number of bytes left to be written in the |
| 1440 | * system, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1441 | * Otherwise we return a negative error number. |
| 1442 | *****************************************************************************/ |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 1443 | static int edge_chars_in_buffer(struct tty_struct *tty) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1444 | { |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 1445 | struct usb_serial_port *port = tty->driver_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1446 | struct edgeport_port *edge_port = usb_get_serial_port_data(port); |
| 1447 | int num_chars; |
| 1448 | unsigned long flags; |
| 1449 | |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 1450 | dbg("%s", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1451 | |
| 1452 | if (edge_port == NULL) |
Alan Cox | d76f2f4 | 2008-07-22 11:16:42 +0100 | [diff] [blame] | 1453 | return 0; |
Richard Knutsson | cb8eaa8 | 2007-03-17 01:35:53 +0100 | [diff] [blame] | 1454 | if (edge_port->closePending) |
Alan Cox | d76f2f4 | 2008-07-22 11:16:42 +0100 | [diff] [blame] | 1455 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1456 | |
| 1457 | if (!edge_port->open) { |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 1458 | dbg("%s - port not opened", __func__); |
Alan Cox | d76f2f4 | 2008-07-22 11:16:42 +0100 | [diff] [blame] | 1459 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1460 | } |
| 1461 | |
| 1462 | spin_lock_irqsave(&edge_port->ep_lock, flags); |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 1463 | num_chars = edge_port->maxTxCredits - edge_port->txCredits + |
| 1464 | edge_port->txfifo.count; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1465 | spin_unlock_irqrestore(&edge_port->ep_lock, flags); |
| 1466 | if (num_chars) { |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 1467 | dbg("%s(port %d) - returns %d", __func__, |
| 1468 | port->number, num_chars); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1469 | } |
| 1470 | |
| 1471 | return num_chars; |
| 1472 | } |
| 1473 | |
| 1474 | |
| 1475 | /***************************************************************************** |
| 1476 | * SerialThrottle |
| 1477 | * this function is called by the tty driver when it wants to stop the data |
| 1478 | * being read from the port. |
| 1479 | *****************************************************************************/ |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 1480 | static void edge_throttle(struct tty_struct *tty) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1481 | { |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 1482 | struct usb_serial_port *port = tty->driver_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1483 | struct edgeport_port *edge_port = usb_get_serial_port_data(port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1484 | int status; |
| 1485 | |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 1486 | dbg("%s - port %d", __func__, port->number); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1487 | |
| 1488 | if (edge_port == NULL) |
| 1489 | return; |
| 1490 | |
| 1491 | if (!edge_port->open) { |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 1492 | dbg("%s - port not opened", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1493 | return; |
| 1494 | } |
| 1495 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1496 | /* if we are implementing XON/XOFF, send the stop character */ |
| 1497 | if (I_IXOFF(tty)) { |
| 1498 | unsigned char stop_char = STOP_CHAR(tty); |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 1499 | status = edge_write(tty, port, &stop_char, 1); |
| 1500 | if (status <= 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1501 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1502 | } |
| 1503 | |
| 1504 | /* if we are implementing RTS/CTS, toggle that line */ |
| 1505 | if (tty->termios->c_cflag & CRTSCTS) { |
| 1506 | edge_port->shadowMCR &= ~MCR_RTS; |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 1507 | status = send_cmd_write_uart_register(edge_port, MCR, |
| 1508 | edge_port->shadowMCR); |
| 1509 | if (status != 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1510 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1511 | } |
| 1512 | |
| 1513 | return; |
| 1514 | } |
| 1515 | |
| 1516 | |
| 1517 | /***************************************************************************** |
| 1518 | * edge_unthrottle |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 1519 | * this function is called by the tty driver when it wants to resume the |
| 1520 | * data being read from the port (called after SerialThrottle is called) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1521 | *****************************************************************************/ |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 1522 | static void edge_unthrottle(struct tty_struct *tty) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1523 | { |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 1524 | struct usb_serial_port *port = tty->driver_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1525 | struct edgeport_port *edge_port = usb_get_serial_port_data(port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1526 | int status; |
| 1527 | |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 1528 | dbg("%s - port %d", __func__, port->number); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1529 | |
| 1530 | if (edge_port == NULL) |
| 1531 | return; |
| 1532 | |
| 1533 | if (!edge_port->open) { |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 1534 | dbg("%s - port not opened", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1535 | return; |
| 1536 | } |
| 1537 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1538 | /* if we are implementing XON/XOFF, send the start character */ |
| 1539 | if (I_IXOFF(tty)) { |
| 1540 | unsigned char start_char = START_CHAR(tty); |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 1541 | status = edge_write(tty, port, &start_char, 1); |
| 1542 | if (status <= 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1543 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1544 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1545 | /* if we are implementing RTS/CTS, toggle that line */ |
| 1546 | if (tty->termios->c_cflag & CRTSCTS) { |
| 1547 | edge_port->shadowMCR |= MCR_RTS; |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 1548 | send_cmd_write_uart_register(edge_port, MCR, |
| 1549 | edge_port->shadowMCR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1550 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1551 | } |
| 1552 | |
| 1553 | |
| 1554 | /***************************************************************************** |
| 1555 | * SerialSetTermios |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 1556 | * this function is called by the tty driver when it wants to change |
| 1557 | * the termios structure |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1558 | *****************************************************************************/ |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 1559 | static void edge_set_termios(struct tty_struct *tty, |
| 1560 | struct usb_serial_port *port, struct ktermios *old_termios) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1561 | { |
| 1562 | struct edgeport_port *edge_port = usb_get_serial_port_data(port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1563 | unsigned int cflag; |
| 1564 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1565 | cflag = tty->termios->c_cflag; |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 1566 | dbg("%s - clfag %08x iflag %08x", __func__, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1567 | tty->termios->c_cflag, tty->termios->c_iflag); |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 1568 | dbg("%s - old clfag %08x old iflag %08x", __func__, |
Alan Cox | 6ce073b | 2007-10-18 01:24:25 -0700 | [diff] [blame] | 1569 | old_termios->c_cflag, old_termios->c_iflag); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1570 | |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 1571 | dbg("%s - port %d", __func__, port->number); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1572 | |
| 1573 | if (edge_port == NULL) |
| 1574 | return; |
| 1575 | |
| 1576 | if (!edge_port->open) { |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 1577 | dbg("%s - port not opened", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1578 | return; |
| 1579 | } |
| 1580 | |
| 1581 | /* change the port settings to the new ones specified */ |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 1582 | change_port_settings(tty, edge_port, old_termios); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1583 | } |
| 1584 | |
| 1585 | |
| 1586 | /***************************************************************************** |
| 1587 | * get_lsr_info - get line status register info |
| 1588 | * |
| 1589 | * Purpose: Let user call ioctl() to get info when the UART physically |
| 1590 | * is emptied. On bus types like RS485, the transmitter must |
| 1591 | * release the bus after transmitting. This must be done when |
| 1592 | * the transmit shift register is empty, not be done when the |
| 1593 | * transmit holding register is empty. This functionality |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 1594 | * allows an RS485 driver to be written in user space. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1595 | *****************************************************************************/ |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 1596 | static int get_lsr_info(struct edgeport_port *edge_port, |
| 1597 | unsigned int __user *value) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1598 | { |
| 1599 | unsigned int result = 0; |
| 1600 | unsigned long flags; |
| 1601 | |
| 1602 | spin_lock_irqsave(&edge_port->ep_lock, flags); |
| 1603 | if (edge_port->maxTxCredits == edge_port->txCredits && |
| 1604 | edge_port->txfifo.count == 0) { |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 1605 | dbg("%s -- Empty", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1606 | result = TIOCSER_TEMT; |
| 1607 | } |
| 1608 | spin_unlock_irqrestore(&edge_port->ep_lock, flags); |
| 1609 | |
| 1610 | if (copy_to_user(value, &result, sizeof(int))) |
| 1611 | return -EFAULT; |
| 1612 | return 0; |
| 1613 | } |
| 1614 | |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 1615 | static int edge_tiocmset(struct tty_struct *tty, struct file *file, |
| 1616 | unsigned int set, unsigned int clear) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1617 | { |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 1618 | struct usb_serial_port *port = tty->driver_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1619 | struct edgeport_port *edge_port = usb_get_serial_port_data(port); |
| 1620 | unsigned int mcr; |
| 1621 | |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 1622 | dbg("%s - port %d", __func__, port->number); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1623 | |
| 1624 | mcr = edge_port->shadowMCR; |
| 1625 | if (set & TIOCM_RTS) |
| 1626 | mcr |= MCR_RTS; |
| 1627 | if (set & TIOCM_DTR) |
| 1628 | mcr |= MCR_DTR; |
| 1629 | if (set & TIOCM_LOOP) |
| 1630 | mcr |= MCR_LOOPBACK; |
| 1631 | |
| 1632 | if (clear & TIOCM_RTS) |
| 1633 | mcr &= ~MCR_RTS; |
| 1634 | if (clear & TIOCM_DTR) |
| 1635 | mcr &= ~MCR_DTR; |
| 1636 | if (clear & TIOCM_LOOP) |
| 1637 | mcr &= ~MCR_LOOPBACK; |
| 1638 | |
| 1639 | edge_port->shadowMCR = mcr; |
| 1640 | |
| 1641 | send_cmd_write_uart_register(edge_port, MCR, edge_port->shadowMCR); |
| 1642 | |
| 1643 | return 0; |
| 1644 | } |
| 1645 | |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 1646 | static int edge_tiocmget(struct tty_struct *tty, struct file *file) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1647 | { |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 1648 | struct usb_serial_port *port = tty->driver_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1649 | struct edgeport_port *edge_port = usb_get_serial_port_data(port); |
| 1650 | unsigned int result = 0; |
| 1651 | unsigned int msr; |
| 1652 | unsigned int mcr; |
| 1653 | |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 1654 | dbg("%s - port %d", __func__, port->number); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1655 | |
| 1656 | msr = edge_port->shadowMSR; |
| 1657 | mcr = edge_port->shadowMCR; |
| 1658 | result = ((mcr & MCR_DTR) ? TIOCM_DTR: 0) /* 0x002 */ |
| 1659 | | ((mcr & MCR_RTS) ? TIOCM_RTS: 0) /* 0x004 */ |
| 1660 | | ((msr & EDGEPORT_MSR_CTS) ? TIOCM_CTS: 0) /* 0x020 */ |
| 1661 | | ((msr & EDGEPORT_MSR_CD) ? TIOCM_CAR: 0) /* 0x040 */ |
| 1662 | | ((msr & EDGEPORT_MSR_RI) ? TIOCM_RI: 0) /* 0x080 */ |
| 1663 | | ((msr & EDGEPORT_MSR_DSR) ? TIOCM_DSR: 0); /* 0x100 */ |
| 1664 | |
| 1665 | |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 1666 | dbg("%s -- %x", __func__, result); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1667 | |
| 1668 | return result; |
| 1669 | } |
| 1670 | |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 1671 | static int get_serial_info(struct edgeport_port *edge_port, |
| 1672 | struct serial_struct __user *retinfo) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1673 | { |
| 1674 | struct serial_struct tmp; |
| 1675 | |
| 1676 | if (!retinfo) |
| 1677 | return -EFAULT; |
| 1678 | |
| 1679 | memset(&tmp, 0, sizeof(tmp)); |
| 1680 | |
| 1681 | tmp.type = PORT_16550A; |
| 1682 | tmp.line = edge_port->port->serial->minor; |
| 1683 | tmp.port = edge_port->port->number; |
| 1684 | tmp.irq = 0; |
| 1685 | tmp.flags = ASYNC_SKIP_TEST | ASYNC_AUTO_IRQ; |
| 1686 | tmp.xmit_fifo_size = edge_port->maxTxCredits; |
| 1687 | tmp.baud_base = 9600; |
| 1688 | tmp.close_delay = 5*HZ; |
| 1689 | tmp.closing_wait = 30*HZ; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1690 | |
| 1691 | if (copy_to_user(retinfo, &tmp, sizeof(*retinfo))) |
| 1692 | return -EFAULT; |
| 1693 | return 0; |
| 1694 | } |
| 1695 | |
| 1696 | |
| 1697 | |
| 1698 | /***************************************************************************** |
| 1699 | * SerialIoctl |
| 1700 | * this function handles any ioctl calls to the driver |
| 1701 | *****************************************************************************/ |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 1702 | static int edge_ioctl(struct tty_struct *tty, struct file *file, |
| 1703 | unsigned int cmd, unsigned long arg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1704 | { |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 1705 | struct usb_serial_port *port = tty->driver_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1706 | DEFINE_WAIT(wait); |
| 1707 | struct edgeport_port *edge_port = usb_get_serial_port_data(port); |
| 1708 | struct async_icount cnow; |
| 1709 | struct async_icount cprev; |
| 1710 | struct serial_icounter_struct icount; |
| 1711 | |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 1712 | dbg("%s - port %d, cmd = 0x%x", __func__, port->number, cmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1713 | |
| 1714 | switch (cmd) { |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 1715 | case TIOCSERGETLSR: |
| 1716 | dbg("%s (%d) TIOCSERGETLSR", __func__, port->number); |
| 1717 | return get_lsr_info(edge_port, (unsigned int __user *) arg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1718 | |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 1719 | case TIOCGSERIAL: |
| 1720 | dbg("%s (%d) TIOCGSERIAL", __func__, port->number); |
| 1721 | return get_serial_info(edge_port, (struct serial_struct __user *) arg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1722 | |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 1723 | case TIOCMIWAIT: |
| 1724 | dbg("%s (%d) TIOCMIWAIT", __func__, port->number); |
| 1725 | cprev = edge_port->icount; |
| 1726 | while (1) { |
| 1727 | prepare_to_wait(&edge_port->delta_msr_wait, |
| 1728 | &wait, TASK_INTERRUPTIBLE); |
| 1729 | schedule(); |
| 1730 | finish_wait(&edge_port->delta_msr_wait, &wait); |
| 1731 | /* see if a signal did it */ |
| 1732 | if (signal_pending(current)) |
| 1733 | return -ERESTARTSYS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1734 | cnow = edge_port->icount; |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 1735 | if (cnow.rng == cprev.rng && cnow.dsr == cprev.dsr && |
| 1736 | cnow.dcd == cprev.dcd && cnow.cts == cprev.cts) |
| 1737 | return -EIO; /* no change => error */ |
| 1738 | if (((arg & TIOCM_RNG) && (cnow.rng != cprev.rng)) || |
| 1739 | ((arg & TIOCM_DSR) && (cnow.dsr != cprev.dsr)) || |
| 1740 | ((arg & TIOCM_CD) && (cnow.dcd != cprev.dcd)) || |
| 1741 | ((arg & TIOCM_CTS) && (cnow.cts != cprev.cts))) { |
| 1742 | return 0; |
| 1743 | } |
| 1744 | cprev = cnow; |
| 1745 | } |
| 1746 | /* NOTREACHED */ |
| 1747 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1748 | |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 1749 | case TIOCGICOUNT: |
| 1750 | cnow = edge_port->icount; |
| 1751 | memset(&icount, 0, sizeof(icount)); |
| 1752 | icount.cts = cnow.cts; |
| 1753 | icount.dsr = cnow.dsr; |
| 1754 | icount.rng = cnow.rng; |
| 1755 | icount.dcd = cnow.dcd; |
| 1756 | icount.rx = cnow.rx; |
| 1757 | icount.tx = cnow.tx; |
| 1758 | icount.frame = cnow.frame; |
| 1759 | icount.overrun = cnow.overrun; |
| 1760 | icount.parity = cnow.parity; |
| 1761 | icount.brk = cnow.brk; |
| 1762 | icount.buf_overrun = cnow.buf_overrun; |
| 1763 | |
| 1764 | dbg("%s (%d) TIOCGICOUNT RX=%d, TX=%d", |
| 1765 | __func__, port->number, icount.rx, icount.tx); |
| 1766 | if (copy_to_user((void __user *)arg, &icount, sizeof(icount))) |
| 1767 | return -EFAULT; |
| 1768 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1769 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1770 | return -ENOIOCTLCMD; |
| 1771 | } |
| 1772 | |
| 1773 | |
| 1774 | /***************************************************************************** |
| 1775 | * SerialBreak |
| 1776 | * this function sends a break to the port |
| 1777 | *****************************************************************************/ |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 1778 | static void edge_break(struct tty_struct *tty, int break_state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1779 | { |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 1780 | struct usb_serial_port *port = tty->driver_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1781 | struct edgeport_port *edge_port = usb_get_serial_port_data(port); |
Greg Kroah-Hartman | 6e8cf77 | 2007-01-18 00:20:19 -0800 | [diff] [blame] | 1782 | struct edgeport_serial *edge_serial = usb_get_serial_data(port->serial); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1783 | int status; |
| 1784 | |
Greg Kroah-Hartman | 6e8cf77 | 2007-01-18 00:20:19 -0800 | [diff] [blame] | 1785 | if ((!edge_serial->is_epic) || |
| 1786 | ((edge_serial->is_epic) && |
| 1787 | (edge_serial->epic_descriptor.Supports.IOSPChase))) { |
| 1788 | /* flush and chase */ |
Richard Knutsson | cb8eaa8 | 2007-03-17 01:35:53 +0100 | [diff] [blame] | 1789 | edge_port->chaseResponsePending = true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1790 | |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 1791 | dbg("%s - Sending IOSP_CMD_CHASE_PORT", __func__); |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 1792 | status = send_iosp_ext_cmd(edge_port, IOSP_CMD_CHASE_PORT, 0); |
Greg Kroah-Hartman | 6e8cf77 | 2007-01-18 00:20:19 -0800 | [diff] [blame] | 1793 | if (status == 0) { |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 1794 | /* block until chase finished */ |
Greg Kroah-Hartman | 6e8cf77 | 2007-01-18 00:20:19 -0800 | [diff] [blame] | 1795 | block_until_chase_response(edge_port); |
| 1796 | } else { |
Richard Knutsson | cb8eaa8 | 2007-03-17 01:35:53 +0100 | [diff] [blame] | 1797 | edge_port->chaseResponsePending = false; |
Greg Kroah-Hartman | 6e8cf77 | 2007-01-18 00:20:19 -0800 | [diff] [blame] | 1798 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1799 | } |
| 1800 | |
Greg Kroah-Hartman | 6e8cf77 | 2007-01-18 00:20:19 -0800 | [diff] [blame] | 1801 | if ((!edge_serial->is_epic) || |
| 1802 | ((edge_serial->is_epic) && |
| 1803 | (edge_serial->epic_descriptor.Supports.IOSPSetClrBreak))) { |
| 1804 | if (break_state == -1) { |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 1805 | dbg("%s - Sending IOSP_CMD_SET_BREAK", __func__); |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 1806 | status = send_iosp_ext_cmd(edge_port, |
| 1807 | IOSP_CMD_SET_BREAK, 0); |
Greg Kroah-Hartman | 6e8cf77 | 2007-01-18 00:20:19 -0800 | [diff] [blame] | 1808 | } else { |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 1809 | dbg("%s - Sending IOSP_CMD_CLEAR_BREAK", __func__); |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 1810 | status = send_iosp_ext_cmd(edge_port, |
| 1811 | IOSP_CMD_CLEAR_BREAK, 0); |
Greg Kroah-Hartman | 6e8cf77 | 2007-01-18 00:20:19 -0800 | [diff] [blame] | 1812 | } |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 1813 | if (status) |
| 1814 | dbg("%s - error sending break set/clear command.", |
| 1815 | __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1816 | } |
| 1817 | |
| 1818 | return; |
| 1819 | } |
| 1820 | |
| 1821 | |
| 1822 | /***************************************************************************** |
| 1823 | * process_rcvd_data |
| 1824 | * this function handles the data received on the bulk in pipe. |
| 1825 | *****************************************************************************/ |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 1826 | static void process_rcvd_data(struct edgeport_serial *edge_serial, |
| 1827 | unsigned char *buffer, __u16 bufferLength) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1828 | { |
| 1829 | struct usb_serial_port *port; |
| 1830 | struct edgeport_port *edge_port; |
| 1831 | struct tty_struct *tty; |
| 1832 | __u16 lastBufferLength; |
| 1833 | __u16 rxLen; |
| 1834 | |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 1835 | dbg("%s", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1836 | |
| 1837 | lastBufferLength = bufferLength + 1; |
| 1838 | |
| 1839 | while (bufferLength > 0) { |
| 1840 | /* failsafe incase we get a message that we don't understand */ |
| 1841 | if (lastBufferLength == bufferLength) { |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 1842 | dbg("%s - stuck in loop, exiting it.", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1843 | break; |
| 1844 | } |
| 1845 | lastBufferLength = bufferLength; |
| 1846 | |
| 1847 | switch (edge_serial->rxState) { |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 1848 | case EXPECT_HDR1: |
| 1849 | edge_serial->rxHeader1 = *buffer; |
| 1850 | ++buffer; |
| 1851 | --bufferLength; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1852 | |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 1853 | if (bufferLength == 0) { |
| 1854 | edge_serial->rxState = EXPECT_HDR2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1855 | break; |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 1856 | } |
| 1857 | /* otherwise, drop on through */ |
| 1858 | case EXPECT_HDR2: |
| 1859 | edge_serial->rxHeader2 = *buffer; |
| 1860 | ++buffer; |
| 1861 | --bufferLength; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1862 | |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 1863 | dbg("%s - Hdr1=%02X Hdr2=%02X", __func__, |
| 1864 | edge_serial->rxHeader1, edge_serial->rxHeader2); |
| 1865 | /* Process depending on whether this header is |
| 1866 | * data or status */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1867 | |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 1868 | if (IS_CMD_STAT_HDR(edge_serial->rxHeader1)) { |
| 1869 | /* Decode this status header and go to |
| 1870 | * EXPECT_HDR1 (if we can process the status |
| 1871 | * with only 2 bytes), or go to EXPECT_HDR3 to |
| 1872 | * get the third byte. */ |
| 1873 | edge_serial->rxPort = |
| 1874 | IOSP_GET_HDR_PORT(edge_serial->rxHeader1); |
| 1875 | edge_serial->rxStatusCode = |
| 1876 | IOSP_GET_STATUS_CODE( |
| 1877 | edge_serial->rxHeader1); |
| 1878 | |
| 1879 | if (!IOSP_STATUS_IS_2BYTE( |
| 1880 | edge_serial->rxStatusCode)) { |
| 1881 | /* This status needs additional bytes. |
| 1882 | * Save what we have and then wait for |
| 1883 | * more data. |
| 1884 | */ |
| 1885 | edge_serial->rxStatusParam |
| 1886 | = edge_serial->rxHeader2; |
| 1887 | edge_serial->rxState = EXPECT_HDR3; |
| 1888 | break; |
| 1889 | } |
| 1890 | /* We have all the header bytes, process the |
| 1891 | status now */ |
| 1892 | process_rcvd_status(edge_serial, |
| 1893 | edge_serial->rxHeader2, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1894 | edge_serial->rxState = EXPECT_HDR1; |
| 1895 | break; |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 1896 | } else { |
| 1897 | edge_serial->rxPort = |
| 1898 | IOSP_GET_HDR_PORT(edge_serial->rxHeader1); |
| 1899 | edge_serial->rxBytesRemaining = |
| 1900 | IOSP_GET_HDR_DATA_LEN( |
| 1901 | edge_serial->rxHeader1, |
| 1902 | edge_serial->rxHeader2); |
| 1903 | dbg("%s - Data for Port %u Len %u", |
| 1904 | __func__, |
| 1905 | edge_serial->rxPort, |
| 1906 | edge_serial->rxBytesRemaining); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1907 | |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 1908 | /* ASSERT(DevExt->RxPort < DevExt->NumPorts); |
| 1909 | * ASSERT(DevExt->RxBytesRemaining < |
| 1910 | * IOSP_MAX_DATA_LENGTH); |
| 1911 | */ |
| 1912 | |
| 1913 | if (bufferLength == 0) { |
| 1914 | edge_serial->rxState = EXPECT_DATA; |
| 1915 | break; |
| 1916 | } |
| 1917 | /* Else, drop through */ |
| 1918 | } |
| 1919 | case EXPECT_DATA: /* Expect data */ |
| 1920 | if (bufferLength < edge_serial->rxBytesRemaining) { |
| 1921 | rxLen = bufferLength; |
| 1922 | /* Expect data to start next buffer */ |
| 1923 | edge_serial->rxState = EXPECT_DATA; |
| 1924 | } else { |
| 1925 | /* BufLen >= RxBytesRemaining */ |
| 1926 | rxLen = edge_serial->rxBytesRemaining; |
| 1927 | /* Start another header next time */ |
| 1928 | edge_serial->rxState = EXPECT_HDR1; |
| 1929 | } |
| 1930 | |
| 1931 | bufferLength -= rxLen; |
| 1932 | edge_serial->rxBytesRemaining -= rxLen; |
| 1933 | |
| 1934 | /* spit this data back into the tty driver if this |
| 1935 | port is open */ |
| 1936 | if (rxLen) { |
| 1937 | port = edge_serial->serial->port[ |
| 1938 | edge_serial->rxPort]; |
| 1939 | edge_port = usb_get_serial_port_data(port); |
| 1940 | if (edge_port->open) { |
Alan Cox | 4a90f09 | 2008-10-13 10:39:46 +0100 | [diff] [blame] | 1941 | tty = tty_port_tty_get( |
| 1942 | &edge_port->port->port); |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 1943 | if (tty) { |
| 1944 | dbg("%s - Sending %d bytes to TTY for port %d", |
| 1945 | __func__, rxLen, edge_serial->rxPort); |
| 1946 | edge_tty_recv(&edge_serial->serial->dev->dev, tty, buffer, rxLen); |
Alan Cox | 4a90f09 | 2008-10-13 10:39:46 +0100 | [diff] [blame] | 1947 | tty_kref_put(tty); |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 1948 | } |
| 1949 | edge_port->icount.rx += rxLen; |
| 1950 | } |
| 1951 | buffer += rxLen; |
| 1952 | } |
| 1953 | break; |
| 1954 | |
| 1955 | case EXPECT_HDR3: /* Expect 3rd byte of status header */ |
| 1956 | edge_serial->rxHeader3 = *buffer; |
| 1957 | ++buffer; |
| 1958 | --bufferLength; |
| 1959 | |
| 1960 | /* We have all the header bytes, process the |
| 1961 | status now */ |
| 1962 | process_rcvd_status(edge_serial, |
| 1963 | edge_serial->rxStatusParam, |
| 1964 | edge_serial->rxHeader3); |
| 1965 | edge_serial->rxState = EXPECT_HDR1; |
| 1966 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1967 | } |
| 1968 | } |
| 1969 | } |
| 1970 | |
| 1971 | |
| 1972 | /***************************************************************************** |
| 1973 | * process_rcvd_status |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 1974 | * this function handles the any status messages received on the |
| 1975 | * bulk in pipe. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1976 | *****************************************************************************/ |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 1977 | static void process_rcvd_status(struct edgeport_serial *edge_serial, |
| 1978 | __u8 byte2, __u8 byte3) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1979 | { |
| 1980 | struct usb_serial_port *port; |
| 1981 | struct edgeport_port *edge_port; |
Alan Cox | 4a90f09 | 2008-10-13 10:39:46 +0100 | [diff] [blame] | 1982 | struct tty_struct *tty; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1983 | __u8 code = edge_serial->rxStatusCode; |
| 1984 | |
| 1985 | /* switch the port pointer to the one being currently talked about */ |
| 1986 | port = edge_serial->serial->port[edge_serial->rxPort]; |
| 1987 | edge_port = usb_get_serial_port_data(port); |
| 1988 | if (edge_port == NULL) { |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 1989 | dev_err(&edge_serial->serial->dev->dev, |
| 1990 | "%s - edge_port == NULL for port %d\n", |
| 1991 | __func__, edge_serial->rxPort); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1992 | return; |
| 1993 | } |
| 1994 | |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 1995 | dbg("%s - port %d", __func__, edge_serial->rxPort); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1996 | |
| 1997 | if (code == IOSP_EXT_STATUS) { |
| 1998 | switch (byte2) { |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 1999 | case IOSP_EXT_STATUS_CHASE_RSP: |
| 2000 | /* we want to do EXT status regardless of port |
| 2001 | * open/closed */ |
| 2002 | dbg("%s - Port %u EXT CHASE_RSP Data = %02x", |
| 2003 | __func__, edge_serial->rxPort, byte3); |
| 2004 | /* Currently, the only EXT_STATUS is Chase, so process |
| 2005 | * here instead of one more call to one more subroutine |
| 2006 | * If/when more EXT_STATUS, there'll be more work to do |
| 2007 | * Also, we currently clear flag and close the port |
| 2008 | * regardless of content of above's Byte3. |
| 2009 | * We could choose to do something else when Byte3 says |
| 2010 | * Timeout on Chase from Edgeport, like wait longer in |
| 2011 | * block_until_chase_response, but for now we don't. |
| 2012 | */ |
| 2013 | edge_port->chaseResponsePending = false; |
| 2014 | wake_up(&edge_port->wait_chase); |
| 2015 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2016 | |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 2017 | case IOSP_EXT_STATUS_RX_CHECK_RSP: |
| 2018 | dbg("%s ========== Port %u CHECK_RSP Sequence = %02x =============\n", __func__, edge_serial->rxPort, byte3); |
| 2019 | /* Port->RxCheckRsp = true; */ |
| 2020 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2021 | } |
| 2022 | } |
| 2023 | |
| 2024 | if (code == IOSP_STATUS_OPEN_RSP) { |
| 2025 | edge_port->txCredits = GET_TX_BUFFER_SIZE(byte3); |
| 2026 | edge_port->maxTxCredits = edge_port->txCredits; |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 2027 | dbg("%s - Port %u Open Response Inital MSR = %02x TxBufferSize = %d", __func__, edge_serial->rxPort, byte2, edge_port->txCredits); |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 2028 | handle_new_msr(edge_port, byte2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2029 | |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 2030 | /* send the current line settings to the port so we are |
| 2031 | in sync with any further termios calls */ |
Alan Cox | 4a90f09 | 2008-10-13 10:39:46 +0100 | [diff] [blame] | 2032 | tty = tty_port_tty_get(&edge_port->port->port); |
| 2033 | if (tty) { |
| 2034 | change_port_settings(tty, |
| 2035 | edge_port, tty->termios); |
| 2036 | tty_kref_put(tty); |
| 2037 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2038 | |
| 2039 | /* we have completed the open */ |
Richard Knutsson | cb8eaa8 | 2007-03-17 01:35:53 +0100 | [diff] [blame] | 2040 | edge_port->openPending = false; |
| 2041 | edge_port->open = true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2042 | wake_up(&edge_port->wait_open); |
| 2043 | return; |
| 2044 | } |
| 2045 | |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 2046 | /* If port is closed, silently discard all rcvd status. We can |
| 2047 | * have cases where buffered status is received AFTER the close |
| 2048 | * port command is sent to the Edgeport. |
| 2049 | */ |
| 2050 | if (!edge_port->open || edge_port->closePending) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2051 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2052 | |
| 2053 | switch (code) { |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 2054 | /* Not currently sent by Edgeport */ |
| 2055 | case IOSP_STATUS_LSR: |
| 2056 | dbg("%s - Port %u LSR Status = %02x", |
| 2057 | __func__, edge_serial->rxPort, byte2); |
| 2058 | handle_new_lsr(edge_port, false, byte2, 0); |
| 2059 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2060 | |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 2061 | case IOSP_STATUS_LSR_DATA: |
| 2062 | dbg("%s - Port %u LSR Status = %02x, Data = %02x", |
| 2063 | __func__, edge_serial->rxPort, byte2, byte3); |
| 2064 | /* byte2 is LSR Register */ |
| 2065 | /* byte3 is broken data byte */ |
| 2066 | handle_new_lsr(edge_port, true, byte2, byte3); |
| 2067 | break; |
| 2068 | /* |
| 2069 | * case IOSP_EXT_4_STATUS: |
| 2070 | * dbg("%s - Port %u LSR Status = %02x Data = %02x", |
| 2071 | * __func__, edge_serial->rxPort, byte2, byte3); |
| 2072 | * break; |
| 2073 | */ |
| 2074 | case IOSP_STATUS_MSR: |
| 2075 | dbg("%s - Port %u MSR Status = %02x", |
| 2076 | __func__, edge_serial->rxPort, byte2); |
| 2077 | /* |
| 2078 | * Process this new modem status and generate appropriate |
| 2079 | * events, etc, based on the new status. This routine |
| 2080 | * also saves the MSR in Port->ShadowMsr. |
| 2081 | */ |
| 2082 | handle_new_msr(edge_port, byte2); |
| 2083 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2084 | |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 2085 | default: |
| 2086 | dbg("%s - Unrecognized IOSP status code %u\n", __func__, code); |
| 2087 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2088 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2089 | return; |
| 2090 | } |
| 2091 | |
| 2092 | |
| 2093 | /***************************************************************************** |
| 2094 | * edge_tty_recv |
| 2095 | * this function passes data on to the tty flip buffer |
| 2096 | *****************************************************************************/ |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 2097 | static void edge_tty_recv(struct device *dev, struct tty_struct *tty, |
| 2098 | unsigned char *data, int length) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2099 | { |
| 2100 | int cnt; |
| 2101 | |
| 2102 | do { |
Alan Cox | 33f0f88 | 2006-01-09 20:54:13 -0800 | [diff] [blame] | 2103 | cnt = tty_buffer_request_room(tty, length); |
| 2104 | if (cnt < length) { |
| 2105 | dev_err(dev, "%s - dropping data, %d bytes lost\n", |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 2106 | __func__, length - cnt); |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 2107 | if (cnt == 0) |
Alan Cox | 33f0f88 | 2006-01-09 20:54:13 -0800 | [diff] [blame] | 2108 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2109 | } |
Alan Cox | 33f0f88 | 2006-01-09 20:54:13 -0800 | [diff] [blame] | 2110 | tty_insert_flip_string(tty, data, cnt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2111 | data += cnt; |
| 2112 | length -= cnt; |
| 2113 | } while (length > 0); |
| 2114 | |
| 2115 | tty_flip_buffer_push(tty); |
| 2116 | } |
| 2117 | |
| 2118 | |
| 2119 | /***************************************************************************** |
| 2120 | * handle_new_msr |
| 2121 | * this function handles any change to the msr register for a port. |
| 2122 | *****************************************************************************/ |
| 2123 | static void handle_new_msr(struct edgeport_port *edge_port, __u8 newMsr) |
| 2124 | { |
| 2125 | struct async_icount *icount; |
| 2126 | |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 2127 | dbg("%s %02x", __func__, newMsr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2128 | |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 2129 | if (newMsr & (EDGEPORT_MSR_DELTA_CTS | EDGEPORT_MSR_DELTA_DSR | |
| 2130 | EDGEPORT_MSR_DELTA_RI | EDGEPORT_MSR_DELTA_CD)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2131 | icount = &edge_port->icount; |
| 2132 | |
| 2133 | /* update input line counters */ |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 2134 | if (newMsr & EDGEPORT_MSR_DELTA_CTS) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2135 | icount->cts++; |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 2136 | if (newMsr & EDGEPORT_MSR_DELTA_DSR) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2137 | icount->dsr++; |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 2138 | if (newMsr & EDGEPORT_MSR_DELTA_CD) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2139 | icount->dcd++; |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 2140 | if (newMsr & EDGEPORT_MSR_DELTA_RI) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2141 | icount->rng++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2142 | wake_up_interruptible(&edge_port->delta_msr_wait); |
| 2143 | } |
| 2144 | |
| 2145 | /* Save the new modem status */ |
| 2146 | edge_port->shadowMSR = newMsr & 0xf0; |
| 2147 | |
| 2148 | return; |
| 2149 | } |
| 2150 | |
| 2151 | |
| 2152 | /***************************************************************************** |
| 2153 | * handle_new_lsr |
| 2154 | * this function handles any change to the lsr register for a port. |
| 2155 | *****************************************************************************/ |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 2156 | static void handle_new_lsr(struct edgeport_port *edge_port, __u8 lsrData, |
| 2157 | __u8 lsr, __u8 data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2158 | { |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 2159 | __u8 newLsr = (__u8) (lsr & (__u8) |
| 2160 | (LSR_OVER_ERR | LSR_PAR_ERR | LSR_FRM_ERR | LSR_BREAK)); |
| 2161 | struct async_icount *icount; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2162 | |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 2163 | dbg("%s - %02x", __func__, newLsr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2164 | |
| 2165 | edge_port->shadowLSR = lsr; |
| 2166 | |
| 2167 | if (newLsr & LSR_BREAK) { |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 2168 | /* |
| 2169 | * Parity and Framing errors only count if they |
| 2170 | * occur exclusive of a break being |
| 2171 | * received. |
| 2172 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2173 | newLsr &= (__u8)(LSR_OVER_ERR | LSR_BREAK); |
| 2174 | } |
| 2175 | |
| 2176 | /* Place LSR data byte into Rx buffer */ |
Alan Cox | 4a90f09 | 2008-10-13 10:39:46 +0100 | [diff] [blame] | 2177 | if (lsrData) { |
| 2178 | struct tty_struct *tty = |
| 2179 | tty_port_tty_get(&edge_port->port->port); |
| 2180 | if (tty) { |
| 2181 | edge_tty_recv(&edge_port->port->dev, tty, &data, 1); |
| 2182 | tty_kref_put(tty); |
| 2183 | } |
| 2184 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2185 | /* update input line counters */ |
| 2186 | icount = &edge_port->icount; |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 2187 | if (newLsr & LSR_BREAK) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2188 | icount->brk++; |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 2189 | if (newLsr & LSR_OVER_ERR) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2190 | icount->overrun++; |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 2191 | if (newLsr & LSR_PAR_ERR) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2192 | icount->parity++; |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 2193 | if (newLsr & LSR_FRM_ERR) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2194 | icount->frame++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2195 | |
| 2196 | return; |
| 2197 | } |
| 2198 | |
| 2199 | |
| 2200 | /**************************************************************************** |
| 2201 | * sram_write |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 2202 | * writes a number of bytes to the Edgeport device's sram starting at the |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2203 | * given address. |
| 2204 | * If successful returns the number of bytes written, otherwise it returns |
| 2205 | * a negative error number of the problem. |
| 2206 | ****************************************************************************/ |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 2207 | static int sram_write(struct usb_serial *serial, __u16 extAddr, __u16 addr, |
| 2208 | __u16 length, const __u8 *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2209 | { |
| 2210 | int result; |
| 2211 | __u16 current_length; |
| 2212 | unsigned char *transfer_buffer; |
| 2213 | |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 2214 | dbg("%s - %x, %x, %d", __func__, extAddr, addr, length); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2215 | |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 2216 | transfer_buffer = kmalloc(64, GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2217 | if (!transfer_buffer) { |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 2218 | dev_err(&serial->dev->dev, "%s - kmalloc(%d) failed.\n", |
| 2219 | __func__, 64); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2220 | return -ENOMEM; |
| 2221 | } |
| 2222 | |
| 2223 | /* need to split these writes up into 64 byte chunks */ |
| 2224 | result = 0; |
| 2225 | while (length > 0) { |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 2226 | if (length > 64) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2227 | current_length = 64; |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 2228 | else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2229 | current_length = length; |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 2230 | |
| 2231 | /* dbg("%s - writing %x, %x, %d", __func__, |
| 2232 | extAddr, addr, current_length); */ |
| 2233 | memcpy(transfer_buffer, data, current_length); |
| 2234 | result = usb_control_msg(serial->dev, |
| 2235 | usb_sndctrlpipe(serial->dev, 0), |
| 2236 | USB_REQUEST_ION_WRITE_RAM, |
| 2237 | 0x40, addr, extAddr, transfer_buffer, |
| 2238 | current_length, 300); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2239 | if (result < 0) |
| 2240 | break; |
| 2241 | length -= current_length; |
| 2242 | addr += current_length; |
| 2243 | data += current_length; |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 2244 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2245 | |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 2246 | kfree(transfer_buffer); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2247 | return result; |
| 2248 | } |
| 2249 | |
| 2250 | |
| 2251 | /**************************************************************************** |
| 2252 | * rom_write |
| 2253 | * writes a number of bytes to the Edgeport device's ROM starting at the |
| 2254 | * given address. |
| 2255 | * If successful returns the number of bytes written, otherwise it returns |
| 2256 | * a negative error number of the problem. |
| 2257 | ****************************************************************************/ |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 2258 | static int rom_write(struct usb_serial *serial, __u16 extAddr, __u16 addr, |
| 2259 | __u16 length, const __u8 *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2260 | { |
| 2261 | int result; |
| 2262 | __u16 current_length; |
| 2263 | unsigned char *transfer_buffer; |
| 2264 | |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 2265 | /* dbg("%s - %x, %x, %d", __func__, extAddr, addr, length); */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2266 | |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 2267 | transfer_buffer = kmalloc(64, GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2268 | if (!transfer_buffer) { |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 2269 | dev_err(&serial->dev->dev, "%s - kmalloc(%d) failed.\n", |
| 2270 | __func__, 64); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2271 | return -ENOMEM; |
| 2272 | } |
| 2273 | |
| 2274 | /* need to split these writes up into 64 byte chunks */ |
| 2275 | result = 0; |
| 2276 | while (length > 0) { |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 2277 | if (length > 64) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2278 | current_length = 64; |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 2279 | else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2280 | current_length = length; |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 2281 | /* dbg("%s - writing %x, %x, %d", __func__, |
| 2282 | extAddr, addr, current_length); */ |
| 2283 | memcpy(transfer_buffer, data, current_length); |
| 2284 | result = usb_control_msg(serial->dev, |
| 2285 | usb_sndctrlpipe(serial->dev, 0), |
| 2286 | USB_REQUEST_ION_WRITE_ROM, 0x40, |
| 2287 | addr, extAddr, |
| 2288 | transfer_buffer, current_length, 300); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2289 | if (result < 0) |
| 2290 | break; |
| 2291 | length -= current_length; |
| 2292 | addr += current_length; |
| 2293 | data += current_length; |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 2294 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2295 | |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 2296 | kfree(transfer_buffer); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2297 | return result; |
| 2298 | } |
| 2299 | |
| 2300 | |
| 2301 | /**************************************************************************** |
| 2302 | * rom_read |
| 2303 | * reads a number of bytes from the Edgeport device starting at the given |
| 2304 | * address. |
| 2305 | * If successful returns the number of bytes read, otherwise it returns |
| 2306 | * a negative error number of the problem. |
| 2307 | ****************************************************************************/ |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 2308 | static int rom_read(struct usb_serial *serial, __u16 extAddr, |
| 2309 | __u16 addr, __u16 length, __u8 *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2310 | { |
| 2311 | int result; |
| 2312 | __u16 current_length; |
| 2313 | unsigned char *transfer_buffer; |
| 2314 | |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 2315 | dbg("%s - %x, %x, %d", __func__, extAddr, addr, length); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2316 | |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 2317 | transfer_buffer = kmalloc(64, GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2318 | if (!transfer_buffer) { |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 2319 | dev_err(&serial->dev->dev, |
| 2320 | "%s - kmalloc(%d) failed.\n", __func__, 64); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2321 | return -ENOMEM; |
| 2322 | } |
| 2323 | |
| 2324 | /* need to split these reads up into 64 byte chunks */ |
| 2325 | result = 0; |
| 2326 | while (length > 0) { |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 2327 | if (length > 64) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2328 | current_length = 64; |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 2329 | else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2330 | current_length = length; |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 2331 | /* dbg("%s - %x, %x, %d", __func__, |
| 2332 | extAddr, addr, current_length); */ |
| 2333 | result = usb_control_msg(serial->dev, |
| 2334 | usb_rcvctrlpipe(serial->dev, 0), |
| 2335 | USB_REQUEST_ION_READ_ROM, |
| 2336 | 0xC0, addr, extAddr, transfer_buffer, |
| 2337 | current_length, 300); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2338 | if (result < 0) |
| 2339 | break; |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 2340 | memcpy(data, transfer_buffer, current_length); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2341 | length -= current_length; |
| 2342 | addr += current_length; |
| 2343 | data += current_length; |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 2344 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2345 | |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 2346 | kfree(transfer_buffer); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2347 | return result; |
| 2348 | } |
| 2349 | |
| 2350 | |
| 2351 | /**************************************************************************** |
| 2352 | * send_iosp_ext_cmd |
| 2353 | * Is used to send a IOSP message to the Edgeport device |
| 2354 | ****************************************************************************/ |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 2355 | static int send_iosp_ext_cmd(struct edgeport_port *edge_port, |
| 2356 | __u8 command, __u8 param) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2357 | { |
| 2358 | unsigned char *buffer; |
| 2359 | unsigned char *currentCommand; |
| 2360 | int length = 0; |
| 2361 | int status = 0; |
| 2362 | |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 2363 | dbg("%s - %d, %d", __func__, command, param); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2364 | |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 2365 | buffer = kmalloc(10, GFP_ATOMIC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2366 | if (!buffer) { |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 2367 | dev_err(&edge_port->port->dev, |
| 2368 | "%s - kmalloc(%d) failed.\n", __func__, 10); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2369 | return -ENOMEM; |
| 2370 | } |
| 2371 | |
| 2372 | currentCommand = buffer; |
| 2373 | |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 2374 | MAKE_CMD_EXT_CMD(¤tCommand, &length, |
| 2375 | edge_port->port->number - edge_port->port->serial->minor, |
| 2376 | command, param); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2377 | |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 2378 | status = write_cmd_usb(edge_port, buffer, length); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2379 | if (status) { |
| 2380 | /* something bad happened, let's free up the memory */ |
| 2381 | kfree(buffer); |
| 2382 | } |
| 2383 | |
| 2384 | return status; |
| 2385 | } |
| 2386 | |
| 2387 | |
| 2388 | /***************************************************************************** |
| 2389 | * write_cmd_usb |
| 2390 | * this function writes the given buffer out to the bulk write endpoint. |
| 2391 | *****************************************************************************/ |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 2392 | static int write_cmd_usb(struct edgeport_port *edge_port, |
| 2393 | unsigned char *buffer, int length) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2394 | { |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 2395 | struct edgeport_serial *edge_serial = |
| 2396 | usb_get_serial_data(edge_port->port->serial); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2397 | int status = 0; |
| 2398 | struct urb *urb; |
| 2399 | int timeout; |
| 2400 | |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 2401 | usb_serial_debug_data(debug, &edge_port->port->dev, |
| 2402 | __func__, length, buffer); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2403 | |
| 2404 | /* Allocate our next urb */ |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 2405 | urb = usb_alloc_urb(0, GFP_ATOMIC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2406 | if (!urb) |
| 2407 | return -ENOMEM; |
| 2408 | |
Oliver Neukum | 96c706e | 2007-03-15 15:27:17 +0100 | [diff] [blame] | 2409 | atomic_inc(&CmdUrbs); |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 2410 | dbg("%s - ALLOCATE URB %p (outstanding %d)", |
| 2411 | __func__, urb, atomic_read(&CmdUrbs)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2412 | |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 2413 | usb_fill_bulk_urb(urb, edge_serial->serial->dev, |
| 2414 | usb_sndbulkpipe(edge_serial->serial->dev, |
| 2415 | edge_serial->bulk_out_endpoint), |
| 2416 | buffer, length, edge_bulk_out_cmd_callback, edge_port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2417 | |
Richard Knutsson | cb8eaa8 | 2007-03-17 01:35:53 +0100 | [diff] [blame] | 2418 | edge_port->commandPending = true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2419 | status = usb_submit_urb(urb, GFP_ATOMIC); |
| 2420 | |
| 2421 | if (status) { |
| 2422 | /* something went wrong */ |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 2423 | dev_err(&edge_port->port->dev, |
| 2424 | "%s - usb_submit_urb(write command) failed, status = %d\n", |
| 2425 | __func__, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2426 | usb_kill_urb(urb); |
| 2427 | usb_free_urb(urb); |
Oliver Neukum | 96c706e | 2007-03-15 15:27:17 +0100 | [diff] [blame] | 2428 | atomic_dec(&CmdUrbs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2429 | return status; |
| 2430 | } |
| 2431 | |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 2432 | /* wait for command to finish */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2433 | timeout = COMMAND_TIMEOUT; |
| 2434 | #if 0 |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 2435 | wait_event(&edge_port->wait_command, !edge_port->commandPending); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2436 | |
Richard Knutsson | cb8eaa8 | 2007-03-17 01:35:53 +0100 | [diff] [blame] | 2437 | if (edge_port->commandPending) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2438 | /* command timed out */ |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 2439 | dbg("%s - command timed out", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2440 | status = -EINVAL; |
| 2441 | } |
| 2442 | #endif |
| 2443 | return status; |
| 2444 | } |
| 2445 | |
| 2446 | |
| 2447 | /***************************************************************************** |
| 2448 | * send_cmd_write_baud_rate |
| 2449 | * this function sends the proper command to change the baud rate of the |
| 2450 | * specified port. |
| 2451 | *****************************************************************************/ |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 2452 | static int send_cmd_write_baud_rate(struct edgeport_port *edge_port, |
| 2453 | int baudRate) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2454 | { |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 2455 | struct edgeport_serial *edge_serial = |
| 2456 | usb_get_serial_data(edge_port->port->serial); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2457 | unsigned char *cmdBuffer; |
| 2458 | unsigned char *currCmd; |
| 2459 | int cmdLen = 0; |
| 2460 | int divisor; |
| 2461 | int status; |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 2462 | unsigned char number = |
| 2463 | edge_port->port->number - edge_port->port->serial->minor; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2464 | |
Adam Kropelin | bc71e47 | 2007-07-29 11:03:29 -0400 | [diff] [blame] | 2465 | if (edge_serial->is_epic && |
| 2466 | !edge_serial->epic_descriptor.Supports.IOSPSetBaudRate) { |
Greg Kroah-Hartman | 6e8cf77 | 2007-01-18 00:20:19 -0800 | [diff] [blame] | 2467 | dbg("SendCmdWriteBaudRate - NOT Setting baud rate for port = %d, baud = %d", |
| 2468 | edge_port->port->number, baudRate); |
| 2469 | return 0; |
| 2470 | } |
| 2471 | |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 2472 | dbg("%s - port = %d, baud = %d", __func__, |
| 2473 | edge_port->port->number, baudRate); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2474 | |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 2475 | status = calc_baud_rate_divisor(baudRate, &divisor); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2476 | if (status) { |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 2477 | dev_err(&edge_port->port->dev, "%s - bad baud rate\n", |
| 2478 | __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2479 | return status; |
| 2480 | } |
| 2481 | |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 2482 | /* Alloc memory for the string of commands. */ |
| 2483 | cmdBuffer = kmalloc(0x100, GFP_ATOMIC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2484 | if (!cmdBuffer) { |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 2485 | dev_err(&edge_port->port->dev, |
| 2486 | "%s - kmalloc(%d) failed.\n", __func__, 0x100); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2487 | return -ENOMEM; |
| 2488 | } |
| 2489 | currCmd = cmdBuffer; |
| 2490 | |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 2491 | /* Enable access to divisor latch */ |
| 2492 | MAKE_CMD_WRITE_REG(&currCmd, &cmdLen, number, LCR, LCR_DL_ENABLE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2493 | |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 2494 | /* Write the divisor itself */ |
| 2495 | MAKE_CMD_WRITE_REG(&currCmd, &cmdLen, number, DLL, LOW8(divisor)); |
| 2496 | MAKE_CMD_WRITE_REG(&currCmd, &cmdLen, number, DLM, HIGH8(divisor)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2497 | |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 2498 | /* Restore original value to disable access to divisor latch */ |
| 2499 | MAKE_CMD_WRITE_REG(&currCmd, &cmdLen, number, LCR, |
| 2500 | edge_port->shadowLCR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2501 | |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 2502 | status = write_cmd_usb(edge_port, cmdBuffer, cmdLen); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2503 | if (status) { |
| 2504 | /* something bad happened, let's free up the memory */ |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 2505 | kfree(cmdBuffer); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2506 | } |
| 2507 | |
| 2508 | return status; |
| 2509 | } |
| 2510 | |
| 2511 | |
| 2512 | /***************************************************************************** |
| 2513 | * calc_baud_rate_divisor |
| 2514 | * this function calculates the proper baud rate divisor for the specified |
| 2515 | * baud rate. |
| 2516 | *****************************************************************************/ |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 2517 | static int calc_baud_rate_divisor(int baudrate, int *divisor) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2518 | { |
| 2519 | int i; |
| 2520 | __u16 custom; |
| 2521 | |
| 2522 | |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 2523 | dbg("%s - %d", __func__, baudrate); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2524 | |
Tobias Klauser | 52950ed | 2005-12-11 16:20:08 +0100 | [diff] [blame] | 2525 | for (i = 0; i < ARRAY_SIZE(divisor_table); i++) { |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 2526 | if (divisor_table[i].BaudRate == baudrate) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2527 | *divisor = divisor_table[i].Divisor; |
| 2528 | return 0; |
| 2529 | } |
| 2530 | } |
| 2531 | |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 2532 | /* We have tried all of the standard baud rates |
| 2533 | * lets try to calculate the divisor for this baud rate |
| 2534 | * Make sure the baud rate is reasonable */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2535 | if (baudrate > 50 && baudrate < 230400) { |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 2536 | /* get divisor */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2537 | custom = (__u16)((230400L + baudrate/2) / baudrate); |
| 2538 | |
| 2539 | *divisor = custom; |
| 2540 | |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 2541 | dbg("%s - Baud %d = %d\n", __func__, baudrate, custom); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2542 | return 0; |
| 2543 | } |
| 2544 | |
| 2545 | return -1; |
| 2546 | } |
| 2547 | |
| 2548 | |
| 2549 | /***************************************************************************** |
| 2550 | * send_cmd_write_uart_register |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 2551 | * this function builds up a uart register message and sends to to the device. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2552 | *****************************************************************************/ |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 2553 | static int send_cmd_write_uart_register(struct edgeport_port *edge_port, |
| 2554 | __u8 regNum, __u8 regValue) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2555 | { |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 2556 | struct edgeport_serial *edge_serial = |
| 2557 | usb_get_serial_data(edge_port->port->serial); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2558 | unsigned char *cmdBuffer; |
| 2559 | unsigned char *currCmd; |
| 2560 | unsigned long cmdLen = 0; |
| 2561 | int status; |
| 2562 | |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 2563 | dbg("%s - write to %s register 0x%02x", |
| 2564 | (regNum == MCR) ? "MCR" : "LCR", __func__, regValue); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2565 | |
Adam Kropelin | bc71e47 | 2007-07-29 11:03:29 -0400 | [diff] [blame] | 2566 | if (edge_serial->is_epic && |
| 2567 | !edge_serial->epic_descriptor.Supports.IOSPWriteMCR && |
| 2568 | regNum == MCR) { |
Robert P. J. Day | beb7dd8 | 2007-05-09 07:14:03 +0200 | [diff] [blame] | 2569 | dbg("SendCmdWriteUartReg - Not writing to MCR Register"); |
Greg Kroah-Hartman | 6e8cf77 | 2007-01-18 00:20:19 -0800 | [diff] [blame] | 2570 | return 0; |
| 2571 | } |
| 2572 | |
Adam Kropelin | bc71e47 | 2007-07-29 11:03:29 -0400 | [diff] [blame] | 2573 | if (edge_serial->is_epic && |
| 2574 | !edge_serial->epic_descriptor.Supports.IOSPWriteLCR && |
| 2575 | regNum == LCR) { |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 2576 | dbg("SendCmdWriteUartReg - Not writing to LCR Register"); |
Greg Kroah-Hartman | 6e8cf77 | 2007-01-18 00:20:19 -0800 | [diff] [blame] | 2577 | return 0; |
| 2578 | } |
| 2579 | |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 2580 | /* Alloc memory for the string of commands. */ |
| 2581 | cmdBuffer = kmalloc(0x10, GFP_ATOMIC); |
| 2582 | if (cmdBuffer == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2583 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2584 | |
| 2585 | currCmd = cmdBuffer; |
| 2586 | |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 2587 | /* Build a cmd in the buffer to write the given register */ |
| 2588 | MAKE_CMD_WRITE_REG(&currCmd, &cmdLen, |
| 2589 | edge_port->port->number - edge_port->port->serial->minor, |
| 2590 | regNum, regValue); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2591 | |
| 2592 | status = write_cmd_usb(edge_port, cmdBuffer, cmdLen); |
| 2593 | if (status) { |
| 2594 | /* something bad happened, let's free up the memory */ |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 2595 | kfree(cmdBuffer); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2596 | } |
| 2597 | |
| 2598 | return status; |
| 2599 | } |
| 2600 | |
| 2601 | |
| 2602 | /***************************************************************************** |
| 2603 | * change_port_settings |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 2604 | * This routine is called to set the UART on the device to match the |
| 2605 | * specified new settings. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2606 | *****************************************************************************/ |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 2607 | |
| 2608 | static void change_port_settings(struct tty_struct *tty, |
| 2609 | struct edgeport_port *edge_port, struct ktermios *old_termios) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2610 | { |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 2611 | struct edgeport_serial *edge_serial = |
| 2612 | usb_get_serial_data(edge_port->port->serial); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2613 | int baud; |
| 2614 | unsigned cflag; |
| 2615 | __u8 mask = 0xff; |
| 2616 | __u8 lData; |
| 2617 | __u8 lParity; |
| 2618 | __u8 lStop; |
| 2619 | __u8 rxFlow; |
| 2620 | __u8 txFlow; |
| 2621 | int status; |
| 2622 | |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 2623 | dbg("%s - port %d", __func__, edge_port->port->number); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2624 | |
Richard Knutsson | cb8eaa8 | 2007-03-17 01:35:53 +0100 | [diff] [blame] | 2625 | if (!edge_port->open && |
| 2626 | !edge_port->openPending) { |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 2627 | dbg("%s - port not opened", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2628 | return; |
| 2629 | } |
| 2630 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2631 | cflag = tty->termios->c_cflag; |
| 2632 | |
| 2633 | switch (cflag & CSIZE) { |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 2634 | case CS5: |
| 2635 | lData = LCR_BITS_5; mask = 0x1f; |
| 2636 | dbg("%s - data bits = 5", __func__); |
| 2637 | break; |
| 2638 | case CS6: |
| 2639 | lData = LCR_BITS_6; mask = 0x3f; |
| 2640 | dbg("%s - data bits = 6", __func__); |
| 2641 | break; |
| 2642 | case CS7: |
| 2643 | lData = LCR_BITS_7; mask = 0x7f; |
| 2644 | dbg("%s - data bits = 7", __func__); |
| 2645 | break; |
| 2646 | default: |
| 2647 | case CS8: |
| 2648 | lData = LCR_BITS_8; |
| 2649 | dbg("%s - data bits = 8", __func__); |
| 2650 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2651 | } |
| 2652 | |
| 2653 | lParity = LCR_PAR_NONE; |
| 2654 | if (cflag & PARENB) { |
| 2655 | if (cflag & CMSPAR) { |
| 2656 | if (cflag & PARODD) { |
| 2657 | lParity = LCR_PAR_MARK; |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 2658 | dbg("%s - parity = mark", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2659 | } else { |
| 2660 | lParity = LCR_PAR_SPACE; |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 2661 | dbg("%s - parity = space", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2662 | } |
| 2663 | } else if (cflag & PARODD) { |
| 2664 | lParity = LCR_PAR_ODD; |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 2665 | dbg("%s - parity = odd", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2666 | } else { |
| 2667 | lParity = LCR_PAR_EVEN; |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 2668 | dbg("%s - parity = even", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2669 | } |
| 2670 | } else { |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 2671 | dbg("%s - parity = none", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2672 | } |
| 2673 | |
| 2674 | if (cflag & CSTOPB) { |
| 2675 | lStop = LCR_STOP_2; |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 2676 | dbg("%s - stop bits = 2", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2677 | } else { |
| 2678 | lStop = LCR_STOP_1; |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 2679 | dbg("%s - stop bits = 1", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2680 | } |
| 2681 | |
| 2682 | /* figure out the flow control settings */ |
| 2683 | rxFlow = txFlow = 0x00; |
| 2684 | if (cflag & CRTSCTS) { |
| 2685 | rxFlow |= IOSP_RX_FLOW_RTS; |
| 2686 | txFlow |= IOSP_TX_FLOW_CTS; |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 2687 | dbg("%s - RTS/CTS is enabled", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2688 | } else { |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 2689 | dbg("%s - RTS/CTS is disabled", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2690 | } |
| 2691 | |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 2692 | /* if we are implementing XON/XOFF, set the start and stop character |
| 2693 | in the device */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2694 | if (I_IXOFF(tty) || I_IXON(tty)) { |
| 2695 | unsigned char stop_char = STOP_CHAR(tty); |
| 2696 | unsigned char start_char = START_CHAR(tty); |
| 2697 | |
Greg Kroah-Hartman | 6e8cf77 | 2007-01-18 00:20:19 -0800 | [diff] [blame] | 2698 | if ((!edge_serial->is_epic) || |
| 2699 | ((edge_serial->is_epic) && |
| 2700 | (edge_serial->epic_descriptor.Supports.IOSPSetXChar))) { |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 2701 | send_iosp_ext_cmd(edge_port, |
| 2702 | IOSP_CMD_SET_XON_CHAR, start_char); |
| 2703 | send_iosp_ext_cmd(edge_port, |
| 2704 | IOSP_CMD_SET_XOFF_CHAR, stop_char); |
Greg Kroah-Hartman | 6e8cf77 | 2007-01-18 00:20:19 -0800 | [diff] [blame] | 2705 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2706 | |
| 2707 | /* if we are implementing INBOUND XON/XOFF */ |
| 2708 | if (I_IXOFF(tty)) { |
| 2709 | rxFlow |= IOSP_RX_FLOW_XON_XOFF; |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 2710 | dbg("%s - INBOUND XON/XOFF is enabled, XON = %2x, XOFF = %2x", |
| 2711 | __func__, start_char, stop_char); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2712 | } else { |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 2713 | dbg("%s - INBOUND XON/XOFF is disabled", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2714 | } |
| 2715 | |
| 2716 | /* if we are implementing OUTBOUND XON/XOFF */ |
| 2717 | if (I_IXON(tty)) { |
| 2718 | txFlow |= IOSP_TX_FLOW_XON_XOFF; |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 2719 | dbg("%s - OUTBOUND XON/XOFF is enabled, XON = %2x, XOFF = %2x", |
| 2720 | __func__, start_char, stop_char); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2721 | } else { |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 2722 | dbg("%s - OUTBOUND XON/XOFF is disabled", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2723 | } |
| 2724 | } |
| 2725 | |
| 2726 | /* Set flow control to the configured value */ |
Greg Kroah-Hartman | 6e8cf77 | 2007-01-18 00:20:19 -0800 | [diff] [blame] | 2727 | if ((!edge_serial->is_epic) || |
| 2728 | ((edge_serial->is_epic) && |
| 2729 | (edge_serial->epic_descriptor.Supports.IOSPSetRxFlow))) |
| 2730 | send_iosp_ext_cmd(edge_port, IOSP_CMD_SET_RX_FLOW, rxFlow); |
| 2731 | if ((!edge_serial->is_epic) || |
| 2732 | ((edge_serial->is_epic) && |
| 2733 | (edge_serial->epic_descriptor.Supports.IOSPSetTxFlow))) |
| 2734 | send_iosp_ext_cmd(edge_port, IOSP_CMD_SET_TX_FLOW, txFlow); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2735 | |
| 2736 | |
| 2737 | edge_port->shadowLCR &= ~(LCR_BITS_MASK | LCR_STOP_MASK | LCR_PAR_MASK); |
| 2738 | edge_port->shadowLCR |= (lData | lParity | lStop); |
| 2739 | |
| 2740 | edge_port->validDataMask = mask; |
| 2741 | |
| 2742 | /* Send the updated LCR value to the EdgePort */ |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 2743 | status = send_cmd_write_uart_register(edge_port, LCR, |
| 2744 | edge_port->shadowLCR); |
| 2745 | if (status != 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2746 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2747 | |
| 2748 | /* set up the MCR register and send it to the EdgePort */ |
| 2749 | edge_port->shadowMCR = MCR_MASTER_IE; |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 2750 | if (cflag & CBAUD) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2751 | edge_port->shadowMCR |= (MCR_DTR | MCR_RTS); |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 2752 | |
| 2753 | status = send_cmd_write_uart_register(edge_port, MCR, |
| 2754 | edge_port->shadowMCR); |
| 2755 | if (status != 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2756 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2757 | |
| 2758 | /* Determine divisor based on baud rate */ |
| 2759 | baud = tty_get_baud_rate(tty); |
| 2760 | if (!baud) { |
| 2761 | /* pick a default, any default... */ |
| 2762 | baud = 9600; |
| 2763 | } |
| 2764 | |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 2765 | dbg("%s - baud rate = %d", __func__, baud); |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 2766 | status = send_cmd_write_baud_rate(edge_port, baud); |
Alan Cox | 6ce073b | 2007-10-18 01:24:25 -0700 | [diff] [blame] | 2767 | if (status == -1) { |
| 2768 | /* Speed change was not possible - put back the old speed */ |
| 2769 | baud = tty_termios_baud_rate(old_termios); |
| 2770 | tty_encode_baud_rate(tty, baud, baud); |
| 2771 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2772 | return; |
| 2773 | } |
| 2774 | |
| 2775 | |
| 2776 | /**************************************************************************** |
| 2777 | * unicode_to_ascii |
| 2778 | * Turns a string from Unicode into ASCII. |
| 2779 | * Doesn't do a good job with any characters that are outside the normal |
| 2780 | * ASCII range, but it's only for debugging... |
| 2781 | * NOTE: expects the unicode in LE format |
| 2782 | ****************************************************************************/ |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 2783 | static void unicode_to_ascii(char *string, int buflen, |
| 2784 | __le16 *unicode, int unicode_size) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2785 | { |
| 2786 | int i; |
| 2787 | |
Pete Zaitcev | ad93375 | 2006-05-22 21:49:44 -0700 | [diff] [blame] | 2788 | if (buflen <= 0) /* never happens, but... */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2789 | return; |
Pete Zaitcev | ad93375 | 2006-05-22 21:49:44 -0700 | [diff] [blame] | 2790 | --buflen; /* space for nul */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2791 | |
Pete Zaitcev | ad93375 | 2006-05-22 21:49:44 -0700 | [diff] [blame] | 2792 | for (i = 0; i < unicode_size; i++) { |
| 2793 | if (i >= buflen) |
| 2794 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2795 | string[i] = (char)(le16_to_cpu(unicode[i])); |
Pete Zaitcev | ad93375 | 2006-05-22 21:49:44 -0700 | [diff] [blame] | 2796 | } |
| 2797 | string[i] = 0x00; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2798 | } |
| 2799 | |
| 2800 | |
| 2801 | /**************************************************************************** |
| 2802 | * get_manufacturing_desc |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 2803 | * reads in the manufacturing descriptor and stores it into the serial |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2804 | * structure. |
| 2805 | ****************************************************************************/ |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 2806 | static void get_manufacturing_desc(struct edgeport_serial *edge_serial) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2807 | { |
| 2808 | int response; |
| 2809 | |
| 2810 | dbg("getting manufacturer descriptor"); |
| 2811 | |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 2812 | response = rom_read(edge_serial->serial, |
| 2813 | (EDGE_MANUF_DESC_ADDR & 0xffff0000) >> 16, |
| 2814 | (__u16)(EDGE_MANUF_DESC_ADDR & 0x0000ffff), |
| 2815 | EDGE_MANUF_DESC_LEN, |
| 2816 | (__u8 *)(&edge_serial->manuf_descriptor)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2817 | |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 2818 | if (response < 1) |
| 2819 | dev_err(&edge_serial->serial->dev->dev, |
| 2820 | "error in getting manufacturer descriptor\n"); |
| 2821 | else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2822 | char string[30]; |
| 2823 | dbg("**Manufacturer Descriptor"); |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 2824 | dbg(" RomSize: %dK", |
| 2825 | edge_serial->manuf_descriptor.RomSize); |
| 2826 | dbg(" RamSize: %dK", |
| 2827 | edge_serial->manuf_descriptor.RamSize); |
| 2828 | dbg(" CpuRev: %d", |
| 2829 | edge_serial->manuf_descriptor.CpuRev); |
| 2830 | dbg(" BoardRev: %d", |
| 2831 | edge_serial->manuf_descriptor.BoardRev); |
| 2832 | dbg(" NumPorts: %d", |
| 2833 | edge_serial->manuf_descriptor.NumPorts); |
| 2834 | dbg(" DescDate: %d/%d/%d", |
| 2835 | edge_serial->manuf_descriptor.DescDate[0], |
| 2836 | edge_serial->manuf_descriptor.DescDate[1], |
| 2837 | edge_serial->manuf_descriptor.DescDate[2]+1900); |
Pete Zaitcev | 4bc203d | 2006-06-06 18:18:33 -0700 | [diff] [blame] | 2838 | unicode_to_ascii(string, sizeof(string), |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 2839 | edge_serial->manuf_descriptor.SerialNumber, |
| 2840 | edge_serial->manuf_descriptor.SerNumLength/2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2841 | dbg(" SerialNumber: %s", string); |
Pete Zaitcev | 4bc203d | 2006-06-06 18:18:33 -0700 | [diff] [blame] | 2842 | unicode_to_ascii(string, sizeof(string), |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 2843 | edge_serial->manuf_descriptor.AssemblyNumber, |
| 2844 | edge_serial->manuf_descriptor.AssemblyNumLength/2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2845 | dbg(" AssemblyNumber: %s", string); |
Pete Zaitcev | 4bc203d | 2006-06-06 18:18:33 -0700 | [diff] [blame] | 2846 | unicode_to_ascii(string, sizeof(string), |
Pete Zaitcev | ad93375 | 2006-05-22 21:49:44 -0700 | [diff] [blame] | 2847 | edge_serial->manuf_descriptor.OemAssyNumber, |
| 2848 | edge_serial->manuf_descriptor.OemAssyNumLength/2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2849 | dbg(" OemAssyNumber: %s", string); |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 2850 | dbg(" UartType: %d", |
| 2851 | edge_serial->manuf_descriptor.UartType); |
| 2852 | dbg(" IonPid: %d", |
| 2853 | edge_serial->manuf_descriptor.IonPid); |
| 2854 | dbg(" IonConfig: %d", |
| 2855 | edge_serial->manuf_descriptor.IonConfig); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2856 | } |
| 2857 | } |
| 2858 | |
| 2859 | |
| 2860 | /**************************************************************************** |
| 2861 | * get_boot_desc |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 2862 | * reads in the bootloader descriptor and stores it into the serial |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2863 | * structure. |
| 2864 | ****************************************************************************/ |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 2865 | static void get_boot_desc(struct edgeport_serial *edge_serial) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2866 | { |
| 2867 | int response; |
| 2868 | |
| 2869 | dbg("getting boot descriptor"); |
| 2870 | |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 2871 | response = rom_read(edge_serial->serial, |
| 2872 | (EDGE_BOOT_DESC_ADDR & 0xffff0000) >> 16, |
| 2873 | (__u16)(EDGE_BOOT_DESC_ADDR & 0x0000ffff), |
| 2874 | EDGE_BOOT_DESC_LEN, |
| 2875 | (__u8 *)(&edge_serial->boot_descriptor)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2876 | |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 2877 | if (response < 1) |
| 2878 | dev_err(&edge_serial->serial->dev->dev, |
| 2879 | "error in getting boot descriptor\n"); |
| 2880 | else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2881 | dbg("**Boot Descriptor:"); |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 2882 | dbg(" BootCodeLength: %d", |
| 2883 | le16_to_cpu(edge_serial->boot_descriptor.BootCodeLength)); |
| 2884 | dbg(" MajorVersion: %d", |
| 2885 | edge_serial->boot_descriptor.MajorVersion); |
| 2886 | dbg(" MinorVersion: %d", |
| 2887 | edge_serial->boot_descriptor.MinorVersion); |
| 2888 | dbg(" BuildNumber: %d", |
| 2889 | le16_to_cpu(edge_serial->boot_descriptor.BuildNumber)); |
| 2890 | dbg(" Capabilities: 0x%x", |
| 2891 | le16_to_cpu(edge_serial->boot_descriptor.Capabilities)); |
| 2892 | dbg(" UConfig0: %d", |
| 2893 | edge_serial->boot_descriptor.UConfig0); |
| 2894 | dbg(" UConfig1: %d", |
| 2895 | edge_serial->boot_descriptor.UConfig1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2896 | } |
| 2897 | } |
| 2898 | |
| 2899 | |
| 2900 | /**************************************************************************** |
| 2901 | * load_application_firmware |
| 2902 | * This is called to load the application firmware to the device |
| 2903 | ****************************************************************************/ |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 2904 | static void load_application_firmware(struct edgeport_serial *edge_serial) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2905 | { |
Jaswinder Singh | 5b9ea93 | 2008-07-03 17:00:23 +0530 | [diff] [blame] | 2906 | const struct ihex_binrec *rec; |
| 2907 | const struct firmware *fw; |
| 2908 | const char *fw_name; |
| 2909 | const char *fw_info; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2910 | int response; |
Jaswinder Singh | 5b9ea93 | 2008-07-03 17:00:23 +0530 | [diff] [blame] | 2911 | __u32 Operaddr; |
| 2912 | __u16 build; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2913 | |
| 2914 | switch (edge_serial->product_info.iDownloadFile) { |
| 2915 | case EDGE_DOWNLOAD_FILE_I930: |
Jaswinder Singh | 5b9ea93 | 2008-07-03 17:00:23 +0530 | [diff] [blame] | 2916 | fw_info = "downloading firmware version (930)"; |
| 2917 | fw_name = "edgeport/down.fw"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2918 | break; |
| 2919 | |
| 2920 | case EDGE_DOWNLOAD_FILE_80251: |
Jaswinder Singh | 5b9ea93 | 2008-07-03 17:00:23 +0530 | [diff] [blame] | 2921 | fw_info = "downloading firmware version (80251)"; |
| 2922 | fw_name = "edgeport/down2.fw"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2923 | break; |
| 2924 | |
| 2925 | case EDGE_DOWNLOAD_FILE_NONE: |
| 2926 | dbg ("No download file specified, skipping download\n"); |
| 2927 | return; |
| 2928 | |
| 2929 | default: |
| 2930 | return; |
| 2931 | } |
| 2932 | |
Jaswinder Singh | 5b9ea93 | 2008-07-03 17:00:23 +0530 | [diff] [blame] | 2933 | response = request_ihex_firmware(&fw, fw_name, |
| 2934 | &edge_serial->serial->dev->dev); |
| 2935 | if (response) { |
| 2936 | printk(KERN_ERR "Failed to load image \"%s\" err %d\n", |
| 2937 | fw_name, response); |
| 2938 | return; |
| 2939 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2940 | |
Jaswinder Singh | 5b9ea93 | 2008-07-03 17:00:23 +0530 | [diff] [blame] | 2941 | rec = (const struct ihex_binrec *)fw->data; |
| 2942 | build = (rec->data[2] << 8) | rec->data[3]; |
| 2943 | |
| 2944 | dbg("%s %d.%d.%d", fw_info, rec->data[0], rec->data[1], build); |
| 2945 | |
| 2946 | edge_serial->product_info.FirmwareMajorVersion = fw->data[0]; |
| 2947 | edge_serial->product_info.FirmwareMinorVersion = fw->data[1]; |
| 2948 | edge_serial->product_info.FirmwareBuildNumber = cpu_to_le16(build); |
| 2949 | |
| 2950 | for (rec = ihex_next_binrec(rec); rec; |
| 2951 | rec = ihex_next_binrec(rec)) { |
| 2952 | Operaddr = be32_to_cpu(rec->addr); |
| 2953 | response = sram_write(edge_serial->serial, |
| 2954 | Operaddr >> 16, |
| 2955 | Operaddr & 0xFFFF, |
| 2956 | be16_to_cpu(rec->len), |
| 2957 | &rec->data[0]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2958 | if (response < 0) { |
Jaswinder Singh | 5b9ea93 | 2008-07-03 17:00:23 +0530 | [diff] [blame] | 2959 | dev_err(&edge_serial->serial->dev->dev, |
| 2960 | "sram_write failed (%x, %x, %d)\n", |
| 2961 | Operaddr >> 16, Operaddr & 0xFFFF, |
| 2962 | be16_to_cpu(rec->len)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2963 | break; |
| 2964 | } |
| 2965 | } |
| 2966 | |
| 2967 | dbg("sending exec_dl_code"); |
| 2968 | response = usb_control_msg (edge_serial->serial->dev, |
| 2969 | usb_sndctrlpipe(edge_serial->serial->dev, 0), |
| 2970 | USB_REQUEST_ION_EXEC_DL_CODE, |
| 2971 | 0x40, 0x4000, 0x0001, NULL, 0, 3000); |
| 2972 | |
Jaswinder Singh | 5b9ea93 | 2008-07-03 17:00:23 +0530 | [diff] [blame] | 2973 | release_firmware(fw); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2974 | return; |
| 2975 | } |
| 2976 | |
| 2977 | |
| 2978 | /**************************************************************************** |
| 2979 | * edge_startup |
| 2980 | ****************************************************************************/ |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 2981 | static int edge_startup(struct usb_serial *serial) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2982 | { |
| 2983 | struct edgeport_serial *edge_serial; |
| 2984 | struct edgeport_port *edge_port; |
| 2985 | struct usb_device *dev; |
Chris Lund | bfd5df3 | 2006-06-03 13:58:19 -0700 | [diff] [blame] | 2986 | int i, j; |
Greg Kroah-Hartman | 6e8cf77 | 2007-01-18 00:20:19 -0800 | [diff] [blame] | 2987 | int response; |
Richard Knutsson | cb8eaa8 | 2007-03-17 01:35:53 +0100 | [diff] [blame] | 2988 | bool interrupt_in_found; |
| 2989 | bool bulk_in_found; |
| 2990 | bool bulk_out_found; |
Greg Kroah-Hartman | 6e8cf77 | 2007-01-18 00:20:19 -0800 | [diff] [blame] | 2991 | static __u32 descriptor[3] = { EDGE_COMPATIBILITY_MASK0, |
| 2992 | EDGE_COMPATIBILITY_MASK1, |
| 2993 | EDGE_COMPATIBILITY_MASK2 }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2994 | |
| 2995 | dev = serial->dev; |
| 2996 | |
| 2997 | /* create our private serial structure */ |
Eric Sesterhenn | 80b6ca4 | 2006-02-27 21:29:43 +0100 | [diff] [blame] | 2998 | edge_serial = kzalloc(sizeof(struct edgeport_serial), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2999 | if (edge_serial == NULL) { |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 3000 | dev_err(&serial->dev->dev, "%s - Out of memory\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3001 | return -ENOMEM; |
| 3002 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3003 | spin_lock_init(&edge_serial->es_lock); |
| 3004 | edge_serial->serial = serial; |
| 3005 | usb_set_serial_data(serial, edge_serial); |
| 3006 | |
| 3007 | /* get the name for the device from the device */ |
Pete Zaitcev | ad93375 | 2006-05-22 21:49:44 -0700 | [diff] [blame] | 3008 | i = get_string(dev, dev->descriptor.iManufacturer, |
| 3009 | &edge_serial->name[0], MAX_NAME_LEN+1); |
| 3010 | edge_serial->name[i++] = ' '; |
| 3011 | get_string(dev, dev->descriptor.iProduct, |
| 3012 | &edge_serial->name[i], MAX_NAME_LEN+2 - i); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3013 | |
| 3014 | dev_info(&serial->dev->dev, "%s detected\n", edge_serial->name); |
| 3015 | |
Greg Kroah-Hartman | 6e8cf77 | 2007-01-18 00:20:19 -0800 | [diff] [blame] | 3016 | /* Read the epic descriptor */ |
| 3017 | if (get_epic_descriptor(edge_serial) <= 0) { |
| 3018 | /* memcpy descriptor to Supports structures */ |
| 3019 | memcpy(&edge_serial->epic_descriptor.Supports, descriptor, |
| 3020 | sizeof(struct edge_compatibility_bits)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3021 | |
Greg Kroah-Hartman | 6e8cf77 | 2007-01-18 00:20:19 -0800 | [diff] [blame] | 3022 | /* get the manufacturing descriptor for this device */ |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 3023 | get_manufacturing_desc(edge_serial); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3024 | |
Greg Kroah-Hartman | 6e8cf77 | 2007-01-18 00:20:19 -0800 | [diff] [blame] | 3025 | /* get the boot descriptor */ |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 3026 | get_boot_desc(edge_serial); |
Greg Kroah-Hartman | 6e8cf77 | 2007-01-18 00:20:19 -0800 | [diff] [blame] | 3027 | |
| 3028 | get_product_info(edge_serial); |
| 3029 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3030 | |
| 3031 | /* set the number of ports from the manufacturing description */ |
| 3032 | /* serial->num_ports = serial->product_info.NumPorts; */ |
Greg Kroah-Hartman | 6e8cf77 | 2007-01-18 00:20:19 -0800 | [diff] [blame] | 3033 | if ((!edge_serial->is_epic) && |
| 3034 | (edge_serial->product_info.NumPorts != serial->num_ports)) { |
| 3035 | dev_warn(&serial->dev->dev, "Device Reported %d serial ports " |
| 3036 | "vs. core thinking we have %d ports, email " |
Joe Perches | 898eb71 | 2007-10-18 03:06:30 -0700 | [diff] [blame] | 3037 | "greg@kroah.com this information.\n", |
Greg Kroah-Hartman | 6e8cf77 | 2007-01-18 00:20:19 -0800 | [diff] [blame] | 3038 | edge_serial->product_info.NumPorts, |
| 3039 | serial->num_ports); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3040 | } |
| 3041 | |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 3042 | dbg("%s - time 1 %ld", __func__, jiffies); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3043 | |
Greg Kroah-Hartman | 6e8cf77 | 2007-01-18 00:20:19 -0800 | [diff] [blame] | 3044 | /* If not an EPiC device */ |
| 3045 | if (!edge_serial->is_epic) { |
| 3046 | /* now load the application firmware into this device */ |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 3047 | load_application_firmware(edge_serial); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3048 | |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 3049 | dbg("%s - time 2 %ld", __func__, jiffies); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3050 | |
Greg Kroah-Hartman | 6e8cf77 | 2007-01-18 00:20:19 -0800 | [diff] [blame] | 3051 | /* Check current Edgeport EEPROM and update if necessary */ |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 3052 | update_edgeport_E2PROM(edge_serial); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3053 | |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 3054 | dbg("%s - time 3 %ld", __func__, jiffies); |
Greg Kroah-Hartman | 6e8cf77 | 2007-01-18 00:20:19 -0800 | [diff] [blame] | 3055 | |
| 3056 | /* set the configuration to use #1 */ |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 3057 | /* dbg("set_configuration 1"); */ |
| 3058 | /* usb_set_configuration (dev, 1); */ |
Greg Kroah-Hartman | 6e8cf77 | 2007-01-18 00:20:19 -0800 | [diff] [blame] | 3059 | } |
Jaswinder Singh | 5b9ea93 | 2008-07-03 17:00:23 +0530 | [diff] [blame] | 3060 | dbg(" FirmwareMajorVersion %d.%d.%d", |
| 3061 | edge_serial->product_info.FirmwareMajorVersion, |
| 3062 | edge_serial->product_info.FirmwareMinorVersion, |
| 3063 | le16_to_cpu(edge_serial->product_info.FirmwareBuildNumber)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3064 | |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 3065 | /* we set up the pointers to the endpoints in the edge_open function, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3066 | * as the structures aren't created yet. */ |
| 3067 | |
| 3068 | /* set up our port private structures */ |
| 3069 | for (i = 0; i < serial->num_ports; ++i) { |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 3070 | edge_port = kmalloc(sizeof(struct edgeport_port), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3071 | if (edge_port == NULL) { |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 3072 | dev_err(&serial->dev->dev, "%s - Out of memory\n", |
| 3073 | __func__); |
Chris Lund | bfd5df3 | 2006-06-03 13:58:19 -0700 | [diff] [blame] | 3074 | for (j = 0; j < i; ++j) { |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 3075 | kfree(usb_get_serial_port_data(serial->port[j])); |
| 3076 | usb_set_serial_port_data(serial->port[j], |
| 3077 | NULL); |
Chris Lund | bfd5df3 | 2006-06-03 13:58:19 -0700 | [diff] [blame] | 3078 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3079 | usb_set_serial_data(serial, NULL); |
| 3080 | kfree(edge_serial); |
| 3081 | return -ENOMEM; |
| 3082 | } |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 3083 | memset(edge_port, 0, sizeof(struct edgeport_port)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3084 | spin_lock_init(&edge_port->ep_lock); |
| 3085 | edge_port->port = serial->port[i]; |
| 3086 | usb_set_serial_port_data(serial->port[i], edge_port); |
| 3087 | } |
Greg Kroah-Hartman | 6e8cf77 | 2007-01-18 00:20:19 -0800 | [diff] [blame] | 3088 | |
| 3089 | response = 0; |
| 3090 | |
| 3091 | if (edge_serial->is_epic) { |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 3092 | /* EPIC thing, set up our interrupt polling now and our read |
| 3093 | * urb, so that the device knows it really is connected. */ |
Richard Knutsson | cb8eaa8 | 2007-03-17 01:35:53 +0100 | [diff] [blame] | 3094 | interrupt_in_found = bulk_in_found = bulk_out_found = false; |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 3095 | for (i = 0; i < serial->interface->altsetting[0] |
| 3096 | .desc.bNumEndpoints; ++i) { |
Greg Kroah-Hartman | 6e8cf77 | 2007-01-18 00:20:19 -0800 | [diff] [blame] | 3097 | struct usb_endpoint_descriptor *endpoint; |
| 3098 | int buffer_size; |
| 3099 | |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 3100 | endpoint = &serial->interface->altsetting[0]. |
| 3101 | endpoint[i].desc; |
Greg Kroah-Hartman | 6e8cf77 | 2007-01-18 00:20:19 -0800 | [diff] [blame] | 3102 | buffer_size = le16_to_cpu(endpoint->wMaxPacketSize); |
Richard Knutsson | cb8eaa8 | 2007-03-17 01:35:53 +0100 | [diff] [blame] | 3103 | if (!interrupt_in_found && |
Greg Kroah-Hartman | 6e8cf77 | 2007-01-18 00:20:19 -0800 | [diff] [blame] | 3104 | (usb_endpoint_is_int_in(endpoint))) { |
| 3105 | /* we found a interrupt in endpoint */ |
| 3106 | dbg("found interrupt in"); |
| 3107 | |
| 3108 | /* not set up yet, so do it now */ |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 3109 | edge_serial->interrupt_read_urb = |
| 3110 | usb_alloc_urb(0, GFP_KERNEL); |
Greg Kroah-Hartman | 6e8cf77 | 2007-01-18 00:20:19 -0800 | [diff] [blame] | 3111 | if (!edge_serial->interrupt_read_urb) { |
Greg Kroah-Hartman | 194343d | 2008-08-20 16:56:34 -0700 | [diff] [blame] | 3112 | dev_err(&dev->dev, "out of memory\n"); |
Greg Kroah-Hartman | 6e8cf77 | 2007-01-18 00:20:19 -0800 | [diff] [blame] | 3113 | return -ENOMEM; |
| 3114 | } |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 3115 | edge_serial->interrupt_in_buffer = |
| 3116 | kmalloc(buffer_size, GFP_KERNEL); |
Greg Kroah-Hartman | 6e8cf77 | 2007-01-18 00:20:19 -0800 | [diff] [blame] | 3117 | if (!edge_serial->interrupt_in_buffer) { |
Greg Kroah-Hartman | 194343d | 2008-08-20 16:56:34 -0700 | [diff] [blame] | 3118 | dev_err(&dev->dev, "out of memory\n"); |
Greg Kroah-Hartman | 6e8cf77 | 2007-01-18 00:20:19 -0800 | [diff] [blame] | 3119 | usb_free_urb(edge_serial->interrupt_read_urb); |
| 3120 | return -ENOMEM; |
| 3121 | } |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 3122 | edge_serial->interrupt_in_endpoint = |
| 3123 | endpoint->bEndpointAddress; |
Greg Kroah-Hartman | 6e8cf77 | 2007-01-18 00:20:19 -0800 | [diff] [blame] | 3124 | |
| 3125 | /* set up our interrupt urb */ |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 3126 | usb_fill_int_urb( |
| 3127 | edge_serial->interrupt_read_urb, |
| 3128 | dev, |
| 3129 | usb_rcvintpipe(dev, |
| 3130 | endpoint->bEndpointAddress), |
| 3131 | edge_serial->interrupt_in_buffer, |
| 3132 | buffer_size, |
| 3133 | edge_interrupt_callback, |
| 3134 | edge_serial, |
| 3135 | endpoint->bInterval); |
Greg Kroah-Hartman | 6e8cf77 | 2007-01-18 00:20:19 -0800 | [diff] [blame] | 3136 | |
Richard Knutsson | cb8eaa8 | 2007-03-17 01:35:53 +0100 | [diff] [blame] | 3137 | interrupt_in_found = true; |
Greg Kroah-Hartman | 6e8cf77 | 2007-01-18 00:20:19 -0800 | [diff] [blame] | 3138 | } |
| 3139 | |
Richard Knutsson | cb8eaa8 | 2007-03-17 01:35:53 +0100 | [diff] [blame] | 3140 | if (!bulk_in_found && |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 3141 | (usb_endpoint_is_bulk_in(endpoint))) { |
Greg Kroah-Hartman | 6e8cf77 | 2007-01-18 00:20:19 -0800 | [diff] [blame] | 3142 | /* we found a bulk in endpoint */ |
| 3143 | dbg("found bulk in"); |
| 3144 | |
| 3145 | /* not set up yet, so do it now */ |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 3146 | edge_serial->read_urb = |
| 3147 | usb_alloc_urb(0, GFP_KERNEL); |
Greg Kroah-Hartman | 6e8cf77 | 2007-01-18 00:20:19 -0800 | [diff] [blame] | 3148 | if (!edge_serial->read_urb) { |
Greg Kroah-Hartman | 194343d | 2008-08-20 16:56:34 -0700 | [diff] [blame] | 3149 | dev_err(&dev->dev, "out of memory\n"); |
Greg Kroah-Hartman | 6e8cf77 | 2007-01-18 00:20:19 -0800 | [diff] [blame] | 3150 | return -ENOMEM; |
| 3151 | } |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 3152 | edge_serial->bulk_in_buffer = |
| 3153 | kmalloc(buffer_size, GFP_KERNEL); |
Greg Kroah-Hartman | 6e8cf77 | 2007-01-18 00:20:19 -0800 | [diff] [blame] | 3154 | if (!edge_serial->bulk_in_buffer) { |
Greg Kroah-Hartman | 194343d | 2008-08-20 16:56:34 -0700 | [diff] [blame] | 3155 | dev_err(&dev->dev, "out of memory\n"); |
Greg Kroah-Hartman | 6e8cf77 | 2007-01-18 00:20:19 -0800 | [diff] [blame] | 3156 | usb_free_urb(edge_serial->read_urb); |
| 3157 | return -ENOMEM; |
| 3158 | } |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 3159 | edge_serial->bulk_in_endpoint = |
| 3160 | endpoint->bEndpointAddress; |
Greg Kroah-Hartman | 6e8cf77 | 2007-01-18 00:20:19 -0800 | [diff] [blame] | 3161 | |
| 3162 | /* set up our bulk in urb */ |
| 3163 | usb_fill_bulk_urb(edge_serial->read_urb, dev, |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 3164 | usb_rcvbulkpipe(dev, |
| 3165 | endpoint->bEndpointAddress), |
| 3166 | edge_serial->bulk_in_buffer, |
| 3167 | le16_to_cpu(endpoint->wMaxPacketSize), |
| 3168 | edge_bulk_in_callback, |
| 3169 | edge_serial); |
Richard Knutsson | cb8eaa8 | 2007-03-17 01:35:53 +0100 | [diff] [blame] | 3170 | bulk_in_found = true; |
Greg Kroah-Hartman | 6e8cf77 | 2007-01-18 00:20:19 -0800 | [diff] [blame] | 3171 | } |
| 3172 | |
Richard Knutsson | cb8eaa8 | 2007-03-17 01:35:53 +0100 | [diff] [blame] | 3173 | if (!bulk_out_found && |
Greg Kroah-Hartman | 6e8cf77 | 2007-01-18 00:20:19 -0800 | [diff] [blame] | 3174 | (usb_endpoint_is_bulk_out(endpoint))) { |
| 3175 | /* we found a bulk out endpoint */ |
| 3176 | dbg("found bulk out"); |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 3177 | edge_serial->bulk_out_endpoint = |
| 3178 | endpoint->bEndpointAddress; |
Richard Knutsson | cb8eaa8 | 2007-03-17 01:35:53 +0100 | [diff] [blame] | 3179 | bulk_out_found = true; |
Greg Kroah-Hartman | 6e8cf77 | 2007-01-18 00:20:19 -0800 | [diff] [blame] | 3180 | } |
| 3181 | } |
| 3182 | |
Richard Knutsson | cb8eaa8 | 2007-03-17 01:35:53 +0100 | [diff] [blame] | 3183 | if (!interrupt_in_found || !bulk_in_found || !bulk_out_found) { |
Greg Kroah-Hartman | 194343d | 2008-08-20 16:56:34 -0700 | [diff] [blame] | 3184 | dev_err(&dev->dev, "Error - the proper endpoints " |
| 3185 | "were not found!\n"); |
Greg Kroah-Hartman | 6e8cf77 | 2007-01-18 00:20:19 -0800 | [diff] [blame] | 3186 | return -ENODEV; |
| 3187 | } |
| 3188 | |
| 3189 | /* start interrupt read for this edgeport this interrupt will |
| 3190 | * continue as long as the edgeport is connected */ |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 3191 | response = usb_submit_urb(edge_serial->interrupt_read_urb, |
| 3192 | GFP_KERNEL); |
Greg Kroah-Hartman | 6e8cf77 | 2007-01-18 00:20:19 -0800 | [diff] [blame] | 3193 | if (response) |
Greg Kroah-Hartman | 194343d | 2008-08-20 16:56:34 -0700 | [diff] [blame] | 3194 | dev_err(&dev->dev, |
| 3195 | "%s - Error %d submitting control urb\n", |
| 3196 | __func__, response); |
Greg Kroah-Hartman | 6e8cf77 | 2007-01-18 00:20:19 -0800 | [diff] [blame] | 3197 | } |
| 3198 | return response; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3199 | } |
| 3200 | |
| 3201 | |
| 3202 | /**************************************************************************** |
| 3203 | * edge_shutdown |
| 3204 | * This function is called whenever the device is removed from the usb bus. |
| 3205 | ****************************************************************************/ |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 3206 | static void edge_shutdown(struct usb_serial *serial) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3207 | { |
Greg Kroah-Hartman | 6e8cf77 | 2007-01-18 00:20:19 -0800 | [diff] [blame] | 3208 | struct edgeport_serial *edge_serial = usb_get_serial_data(serial); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3209 | int i; |
| 3210 | |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 3211 | dbg("%s", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3212 | |
| 3213 | /* stop reads and writes on all ports */ |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 3214 | for (i = 0; i < serial->num_ports; ++i) { |
| 3215 | kfree(usb_get_serial_port_data(serial->port[i])); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3216 | usb_set_serial_port_data(serial->port[i], NULL); |
| 3217 | } |
Greg Kroah-Hartman | 6e8cf77 | 2007-01-18 00:20:19 -0800 | [diff] [blame] | 3218 | /* free up our endpoint stuff */ |
| 3219 | if (edge_serial->is_epic) { |
Oliver Neukum | 74ac07e | 2007-06-13 18:50:41 +0200 | [diff] [blame] | 3220 | usb_kill_urb(edge_serial->interrupt_read_urb); |
Greg Kroah-Hartman | 6e8cf77 | 2007-01-18 00:20:19 -0800 | [diff] [blame] | 3221 | usb_free_urb(edge_serial->interrupt_read_urb); |
| 3222 | kfree(edge_serial->interrupt_in_buffer); |
| 3223 | |
Oliver Neukum | 74ac07e | 2007-06-13 18:50:41 +0200 | [diff] [blame] | 3224 | usb_kill_urb(edge_serial->read_urb); |
Greg Kroah-Hartman | 6e8cf77 | 2007-01-18 00:20:19 -0800 | [diff] [blame] | 3225 | usb_free_urb(edge_serial->read_urb); |
| 3226 | kfree(edge_serial->bulk_in_buffer); |
| 3227 | } |
| 3228 | |
| 3229 | kfree(edge_serial); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3230 | usb_set_serial_data(serial, NULL); |
| 3231 | } |
| 3232 | |
| 3233 | |
| 3234 | /**************************************************************************** |
| 3235 | * edgeport_init |
| 3236 | * This is called by the module subsystem, or on startup to initialize us |
| 3237 | ****************************************************************************/ |
| 3238 | static int __init edgeport_init(void) |
| 3239 | { |
| 3240 | int retval; |
| 3241 | |
| 3242 | retval = usb_serial_register(&edgeport_2port_device); |
| 3243 | if (retval) |
| 3244 | goto failed_2port_device_register; |
| 3245 | retval = usb_serial_register(&edgeport_4port_device); |
| 3246 | if (retval) |
| 3247 | goto failed_4port_device_register; |
| 3248 | retval = usb_serial_register(&edgeport_8port_device); |
| 3249 | if (retval) |
| 3250 | goto failed_8port_device_register; |
Greg Kroah-Hartman | 6e8cf77 | 2007-01-18 00:20:19 -0800 | [diff] [blame] | 3251 | retval = usb_serial_register(&epic_device); |
| 3252 | if (retval) |
| 3253 | goto failed_epic_device_register; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3254 | retval = usb_register(&io_driver); |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 3255 | if (retval) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3256 | goto failed_usb_register; |
Oliver Neukum | 96c706e | 2007-03-15 15:27:17 +0100 | [diff] [blame] | 3257 | atomic_set(&CmdUrbs, 0); |
Greg Kroah-Hartman | c197a8d | 2008-08-18 13:21:04 -0700 | [diff] [blame] | 3258 | printk(KERN_INFO KBUILD_MODNAME ": " DRIVER_VERSION ":" |
| 3259 | DRIVER_DESC "\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3260 | return 0; |
| 3261 | |
| 3262 | failed_usb_register: |
Greg Kroah-Hartman | 6e8cf77 | 2007-01-18 00:20:19 -0800 | [diff] [blame] | 3263 | usb_serial_deregister(&epic_device); |
| 3264 | failed_epic_device_register: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3265 | usb_serial_deregister(&edgeport_8port_device); |
| 3266 | failed_8port_device_register: |
| 3267 | usb_serial_deregister(&edgeport_4port_device); |
| 3268 | failed_4port_device_register: |
| 3269 | usb_serial_deregister(&edgeport_2port_device); |
| 3270 | failed_2port_device_register: |
| 3271 | return retval; |
| 3272 | } |
| 3273 | |
| 3274 | |
| 3275 | /**************************************************************************** |
| 3276 | * edgeport_exit |
| 3277 | * Called when the driver is about to be unloaded. |
| 3278 | ****************************************************************************/ |
| 3279 | static void __exit edgeport_exit (void) |
| 3280 | { |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 3281 | usb_deregister(&io_driver); |
| 3282 | usb_serial_deregister(&edgeport_2port_device); |
| 3283 | usb_serial_deregister(&edgeport_4port_device); |
| 3284 | usb_serial_deregister(&edgeport_8port_device); |
| 3285 | usb_serial_deregister(&epic_device); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3286 | } |
| 3287 | |
| 3288 | module_init(edgeport_init); |
| 3289 | module_exit(edgeport_exit); |
| 3290 | |
| 3291 | /* Module information */ |
Alan Cox | 03f0dbf | 2008-07-22 11:16:34 +0100 | [diff] [blame] | 3292 | MODULE_AUTHOR(DRIVER_AUTHOR); |
| 3293 | MODULE_DESCRIPTION(DRIVER_DESC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3294 | MODULE_LICENSE("GPL"); |
Jaswinder Singh | 5b9ea93 | 2008-07-03 17:00:23 +0530 | [diff] [blame] | 3295 | MODULE_FIRMWARE("edgeport/boot.fw"); |
| 3296 | MODULE_FIRMWARE("edgeport/boot2.fw"); |
| 3297 | MODULE_FIRMWARE("edgeport/down.fw"); |
| 3298 | MODULE_FIRMWARE("edgeport/down2.fw"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3299 | |
| 3300 | module_param(debug, bool, S_IRUGO | S_IWUSR); |
| 3301 | MODULE_PARM_DESC(debug, "Debug enabled or not"); |
| 3302 | |
| 3303 | module_param(low_latency, bool, S_IRUGO | S_IWUSR); |
| 3304 | MODULE_PARM_DESC(low_latency, "Low latency enabled or not"); |