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