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