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