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