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