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