32 #include <linux/kernel.h>
34 #include <linux/errno.h>
36 #include <linux/slab.h>
37 #include <linux/tty.h>
40 #include <linux/module.h>
42 #include <linux/serial.h>
44 #include <linux/wait.h>
57 #define DRIVER_VERSION "v2.7"
59 #define DRIVER_DESC "Edgeport USB Serial Driver"
61 #define MAX_NAME_LEN 64
63 #define CHASE_TIMEOUT (5*HZ)
64 #define OPEN_TIMEOUT (5*HZ)
65 #define COMMAND_TIMEOUT (5*HZ)
200 static void edge_interrupt_callback(
struct urb *
urb);
201 static void edge_bulk_in_callback(
struct urb *
urb);
202 static void edge_bulk_out_data_callback(
struct urb *
urb);
203 static void edge_bulk_out_cmd_callback(
struct urb *
urb);
209 const unsigned char *
buf,
int count);
210 static int edge_write_room(
struct tty_struct *tty);
211 static int edge_chars_in_buffer(
struct tty_struct *tty);
212 static void edge_throttle(
struct tty_struct *tty);
213 static void edge_unthrottle(
struct tty_struct *tty);
214 static void edge_set_termios(
struct tty_struct *tty,
218 unsigned int cmd,
unsigned long arg);
219 static void edge_break(
struct tty_struct *tty,
int break_state);
220 static int edge_tiocmget(
struct tty_struct *tty);
221 static int edge_tiocmset(
struct tty_struct *tty,
222 unsigned int set,
unsigned int clear);
223 static int edge_get_icount(
struct tty_struct *tty,
246 static int calc_baud_rate_divisor(
struct device *
dev,
int baud_rate,
int *
divisor);
247 static int send_cmd_write_baud_rate(
struct edgeport_port *edge_port,
249 static void change_port_settings(
struct tty_struct *tty,
252 static int send_cmd_write_uart_register(
struct edgeport_port *edge_port,
255 unsigned char *
buffer,
int writeLength);
265 static void get_manufacturing_desc(
struct edgeport_serial *edge_serial);
267 static void load_application_firmware(
struct edgeport_serial *edge_serial);
269 static void unicode_to_ascii(
char *
string,
int buflen,
286 static void update_edgeport_E2PROM(
struct edgeport_serial *edge_serial)
291 __u8 BootMajorVersion;
292 __u8 BootMinorVersion;
293 __u16 BootBuildNumber;
302 fw_name =
"edgeport/boot.fw";
305 fw_name =
"edgeport/boot2.fw";
311 response = request_ihex_firmware(&fw, fw_name,
312 &edge_serial->
serial->dev->dev);
314 dev_err(dev,
"Failed to load image \"%s\" err %d\n",
320 BootMajorVersion = rec->
data[0];
321 BootMinorVersion = rec->
data[1];
322 BootBuildNumber = (rec->
data[2] << 8) | rec->
data[3];
329 BootNewVer = (BootMajorVersion << 24) +
330 (BootMinorVersion << 16) +
333 dev_dbg(dev,
"Current Boot Image version %d.%d.%d\n",
339 if (BootNewVer > BootCurVer) {
340 dev_dbg(dev,
"**Update Boot Image from %d.%d.%d to %d.%d.%d\n",
344 BootMajorVersion, BootMinorVersion, BootBuildNumber);
346 dev_dbg(dev,
"Downloading new Boot Image\n");
348 for (rec = ihex_next_binrec(rec); rec;
349 rec = ihex_next_binrec(rec)) {
351 response = rom_write(edge_serial->
serial,
358 "rom_write failed (%x, %x, %d)\n",
359 Bootaddr >> 16, Bootaddr & 0xFFFF,
365 dev_dbg(dev,
"Boot Image -- already up to date\n");
376 static int get_string_desc(
struct usb_device *dev,
int Id,
382 dev_dbg(&dev->dev,
"%s - USB String ID = %d\n", __func__, Id);
398 *pRetDesc = pStringDesc;
409 dev_dbg(dev,
"**Product Information:\n");
421 dev_dbg(dev,
" BootMajorVersion %d.%d.%d\n",
425 dev_dbg(dev,
" FirmwareMajorVersion %d.%d.%d\n",
429 dev_dbg(dev,
" ManufactureDescDate %d/%d/%d\n",
433 dev_dbg(dev,
" iDownloadFile 0x%x\n",
498 dump_product_info(edge_serial, product_info);
531 dump_product_info(ep, product_info);
534 dev_dbg(dev,
"**EPIC descriptor:\n");
566 static void edge_interrupt_callback(
struct urb *
urb)
573 unsigned char *
data = urb->transfer_buffer;
574 int length = urb->actual_length;
590 dev_dbg(&urb->dev->dev,
"%s - urb shutting down with status: %d\n", __func__, status);
593 dev_dbg(&urb->dev->dev,
"%s - nonzero urb status received: %d\n", __func__, status);
597 dev = &edge_serial->
serial->dev->dev;
601 usb_serial_debug_data(dev, __func__, length, data);
604 bytes_avail = data[0] | (data[1] << 8);
606 spin_lock(&edge_serial->
es_lock);
609 "%s - bytes_avail=%d, rxBytesAvail=%d, read_in_progress=%d\n",
610 __func__, bytes_avail,
616 dev_dbg(dev,
"%s - posting a read\n", __func__);
624 "%s - usb_submit_urb(read bulk) failed with result = %d\n",
629 spin_unlock(&edge_serial->
es_lock);
635 while ((position < length) &&
636 (portNumber < edge_serial->serial->
num_ports)) {
637 txCredits = data[position] | (data[position+1] << 8);
639 port = edge_serial->
serial->port[portNumber];
640 edge_port = usb_get_serial_port_data(port);
641 if (edge_port->
open) {
642 spin_lock(&edge_port->
ep_lock);
644 spin_unlock(&edge_port->
ep_lock);
645 dev_dbg(dev,
"%s - txcredits for port%d = %d\n",
646 __func__, portNumber,
652 &edge_port->
port->port);
659 send_more_port_data(edge_serial,
672 "%s - Error %d submitting control urb\n",
682 static void edge_bulk_in_callback(
struct urb *urb)
686 unsigned char *data = urb->transfer_buffer;
688 __u16 raw_data_length;
689 int status = urb->status;
692 dev_dbg(&urb->dev->dev,
"%s - nonzero read bulk status received: %d\n",
698 if (urb->actual_length == 0) {
699 dev_dbg(&urb->dev->dev,
"%s - read bulk callback with no data\n", __func__);
704 dev = &edge_serial->
serial->dev->dev;
705 raw_data_length = urb->actual_length;
707 usb_serial_debug_data(dev, __func__, raw_data_length, data);
709 spin_lock(&edge_serial->
es_lock);
714 dev_dbg(dev,
"%s - Received = %d, rxBytesAvail %d\n", __func__,
717 process_rcvd_data(edge_serial, data, urb->actual_length);
721 dev_dbg(dev,
"%s - posting a read\n", __func__);
725 "%s - usb_submit_urb(read bulk) failed, retval = %d\n",
733 spin_unlock(&edge_serial->
es_lock);
742 static void edge_bulk_out_data_callback(
struct urb *urb)
746 int status = urb->status;
750 "%s - nonzero write bulk status received: %d\n",
756 if (tty && edge_port->
open) {
768 (usb_get_serial_data(edge_port->
port->serial)), edge_port);
777 static void edge_bulk_out_cmd_callback(
struct urb *urb)
781 int status = urb->status;
784 dev_dbg(&urb->dev->dev,
"%s - FREE URB %p (outstanding %d)\n",
789 kfree(urb->transfer_buffer);
796 "%s - nonzero write bulk status received: %d\n",
805 if (tty && edge_port->
open)
827 struct edgeport_port *edge_port = usb_get_serial_port_data(port);
833 if (edge_port ==
NULL)
839 edge_serial = usb_get_serial_data(serial);
840 if (edge_serial ==
NULL)
861 usb_rcvintpipe(serial->
dev,
865 edge_interrupt_callback, edge_serial,
869 usb_fill_bulk_urb(edge_serial->
read_urb, serial->
dev,
870 usb_rcvbulkpipe(serial->
dev,
873 edge_serial->
read_urb->transfer_buffer_length,
874 edge_bulk_in_callback, edge_serial);
883 dev_err(dev,
"%s - Error %d submitting control urb\n",
905 edge_port->
open =
false;
909 dev_err(dev,
"%s - error sending open port command\n", __func__);
918 if (!edge_port->
open) {
920 dev_dbg(dev,
"%s - open timedout\n", __func__);
926 edge_port->
txfifo.head = 0;
927 edge_port->
txfifo.tail = 0;
928 edge_port->
txfifo.count = 0;
932 if (!edge_port->
txfifo.fifo) {
933 dev_dbg(dev,
"%s - no memory\n", __func__);
943 dev_dbg(dev,
"%s - no memory\n", __func__);
948 dev_dbg(dev,
"%s(%d) - Initialize TX fifo to %d bytes\n",
965 static void block_until_chase_response(
struct edgeport_port *edge_port)
979 dev_dbg(dev,
"%s - Got Chase Response\n", __func__);
983 dev_dbg(dev,
"%s - Got all credits\n", __func__);
994 if (lastCredits == edge_port->
txCredits) {
999 dev_dbg(dev,
"%s - Chase TIMEOUT\n", __func__);
1004 dev_dbg(dev,
"%s - Last %d, Current %d\n", __func__,
1022 static void block_until_tx_empty(
struct edgeport_port *edge_port)
1028 int timeout =
HZ/10;
1033 lastCount = fifo->
count;
1036 if (lastCount == 0) {
1037 dev_dbg(dev,
"%s - TX Buffer Empty\n", __func__);
1047 dev_dbg(dev,
"%s wait\n", __func__);
1049 if (lastCount == fifo->
count) {
1053 dev_dbg(dev,
"%s - TIMEOUT\n", __func__);
1074 edge_serial = usb_get_serial_data(port->
serial);
1075 edge_port = usb_get_serial_port_data(port);
1076 if (edge_serial ==
NULL || edge_port ==
NULL)
1080 block_until_tx_empty(edge_port);
1084 if ((!edge_serial->
is_epic) ||
1090 dev_dbg(&port->
dev,
"%s - Sending IOSP_CMD_CHASE_PORT\n", __func__);
1094 block_until_chase_response(edge_port);
1099 if ((!edge_serial->
is_epic) ||
1103 dev_dbg(&port->
dev,
"%s - Sending IOSP_CMD_CLOSE_PORT\n", __func__);
1109 edge_port->
open =
false;
1133 const unsigned char *data,
int count)
1135 struct edgeport_port *edge_port = usb_get_serial_port_data(port);
1141 unsigned long flags;
1143 if (edge_port ==
NULL)
1147 fifo = &edge_port->
txfifo;
1152 copySize =
min((
unsigned int)count,
1155 dev_dbg(&port->
dev,
"%s(%d) of %d byte(s) Fifo room %d -- will copy %d bytes\n",
1156 __func__, port->
number, count,
1161 if (copySize == 0) {
1162 dev_dbg(&port->
dev,
"%s - copySize = Zero\n", __func__);
1173 bytesleft = fifo->
size - fifo->
head;
1174 firsthalf =
min(bytesleft, copySize);
1175 dev_dbg(&port->
dev,
"%s - copy %d bytes of %d into fifo \n", __func__,
1176 firsthalf, bytesleft);
1180 usb_serial_debug_data(&port->
dev, __func__, firsthalf, &fifo->
fifo[fifo->
head]);
1183 fifo->
head += firsthalf;
1184 fifo->
count += firsthalf;
1190 secondhalf = copySize-firsthalf;
1193 dev_dbg(&port->
dev,
"%s - copy rest of data %d\n", __func__, secondhalf);
1195 usb_serial_debug_data(&port->
dev, __func__, secondhalf, &fifo->
fifo[fifo->
head]);
1197 fifo->
count += secondhalf;
1198 fifo->
head += secondhalf;
1205 spin_unlock_irqrestore(&edge_port->
ep_lock, flags);
1208 usb_get_serial_data(port->
serial), edge_port);
1210 dev_dbg(&port->
dev,
"%s wrote %d byte(s) TxCredits %d, Fifo %d\n",
1242 unsigned long flags;
1248 (fifo->
count == 0)) {
1249 dev_dbg(dev,
"%s(%d) EXIT - fifo %d, PendingWrite = %d\n",
1250 __func__, edge_port->
port->number,
1263 dev_dbg(dev,
"%s(%d) Not enough credit - fifo %d TxCredit %d\n",
1264 __func__, edge_port->
port->number, fifo->
count,
1276 kfree(urb->transfer_buffer);
1277 urb->transfer_buffer =
NULL;
1281 count = fifo->
count;
1283 if (buffer ==
NULL) {
1285 "%s - no more kernel memory...\n", __func__);
1290 - edge_port->
port->serial->minor, count);
1292 - edge_port->
port->serial->minor, count);
1295 bytesleft = fifo->
size - fifo->
tail;
1296 firsthalf =
min(bytesleft, count);
1298 fifo->
tail += firsthalf;
1299 fifo->
count -= firsthalf;
1303 secondhalf = count-firsthalf;
1307 fifo->
tail += secondhalf;
1308 fifo->
count -= secondhalf;
1312 usb_serial_debug_data(&edge_port->
port->dev, __func__, count, &buffer[2]);
1315 usb_fill_bulk_urb(urb, edge_serial->
serial->dev,
1316 usb_sndbulkpipe(edge_serial->
serial->dev,
1319 edge_bulk_out_data_callback, edge_port);
1329 "%s - usb_submit_urb(write bulk) failed, status = %d, data lost\n",
1337 dev_dbg(dev,
"%s wrote %d byte(s) TxCredit %d, Fifo %d\n",
1341 spin_unlock_irqrestore(&edge_port->
ep_lock, flags);
1352 static int edge_write_room(
struct tty_struct *tty)
1355 struct edgeport_port *edge_port = usb_get_serial_port_data(port);
1357 unsigned long flags;
1359 if (edge_port ==
NULL)
1364 if (!edge_port->
open) {
1365 dev_dbg(&port->
dev,
"%s - port not opened\n", __func__);
1372 spin_unlock_irqrestore(&edge_port->
ep_lock, flags);
1374 dev_dbg(&port->
dev,
"%s - returns %d\n", __func__, room);
1388 static int edge_chars_in_buffer(
struct tty_struct *tty)
1391 struct edgeport_port *edge_port = usb_get_serial_port_data(port);
1393 unsigned long flags;
1395 if (edge_port ==
NULL)
1400 if (!edge_port->
open) {
1401 dev_dbg(&port->
dev,
"%s - port not opened\n", __func__);
1408 spin_unlock_irqrestore(&edge_port->
ep_lock, flags);
1410 dev_dbg(&port->
dev,
"%s(port %d) - returns %d\n", __func__,
1411 port->
number, num_chars);
1423 static void edge_throttle(
struct tty_struct *tty)
1426 struct edgeport_port *edge_port = usb_get_serial_port_data(port);
1429 if (edge_port ==
NULL)
1432 if (!edge_port->
open) {
1433 dev_dbg(&port->
dev,
"%s - port not opened\n", __func__);
1439 unsigned char stop_char =
STOP_CHAR(tty);
1440 status = edge_write(tty, port, &stop_char, 1);
1446 if (tty->termios.c_cflag &
CRTSCTS) {
1448 status = send_cmd_write_uart_register(edge_port,
MCR,
1461 static void edge_unthrottle(
struct tty_struct *tty)
1464 struct edgeport_port *edge_port = usb_get_serial_port_data(port);
1467 if (edge_port ==
NULL)
1470 if (!edge_port->
open) {
1471 dev_dbg(&port->
dev,
"%s - port not opened\n", __func__);
1478 status = edge_write(tty, port, &start_char, 1);
1483 if (tty->termios.c_cflag &
CRTSCTS) {
1485 send_cmd_write_uart_register(edge_port,
MCR,
1496 static void edge_set_termios(
struct tty_struct *tty,
1499 struct edgeport_port *edge_port = usb_get_serial_port_data(port);
1502 cflag = tty->termios.c_cflag;
1503 dev_dbg(&port->
dev,
"%s - clfag %08x iflag %08x\n", __func__, tty->termios.c_cflag, tty->termios.c_iflag);
1506 if (edge_port ==
NULL)
1509 if (!edge_port->
open) {
1510 dev_dbg(&port->
dev,
"%s - port not opened\n", __func__);
1515 change_port_settings(tty, edge_port, old_termios);
1530 unsigned int __user *
value)
1532 unsigned int result = 0;
1533 unsigned long flags;
1537 edge_port->
txfifo.count == 0) {
1538 dev_dbg(&edge_port->
port->dev,
"%s -- Empty\n", __func__);
1541 spin_unlock_irqrestore(&edge_port->
ep_lock, flags);
1548 static int edge_tiocmset(
struct tty_struct *tty,
1549 unsigned int set,
unsigned int clear)
1552 struct edgeport_port *edge_port = usb_get_serial_port_data(port);
1572 send_cmd_write_uart_register(edge_port,
MCR, edge_port->
shadowMCR);
1577 static int edge_tiocmget(
struct tty_struct *tty)
1580 struct edgeport_port *edge_port = usb_get_serial_port_data(port);
1581 unsigned int result = 0;
1587 result = ((mcr &
MCR_DTR) ? TIOCM_DTR: 0)
1588 | ((mcr &
MCR_RTS) ? TIOCM_RTS: 0)
1597 static int edge_get_icount(
struct tty_struct *tty,
1601 struct edgeport_port *edge_port = usb_get_serial_port_data(port);
1603 cnow = edge_port->
icount;
1605 icount->
cts = cnow.cts;
1606 icount->
dsr = cnow.dsr;
1607 icount->
rng = cnow.rng;
1608 icount->
dcd = cnow.dcd;
1609 icount->
rx = cnow.rx;
1610 icount->
tx = cnow.tx;
1611 icount->
frame = cnow.frame;
1612 icount->
overrun = cnow.overrun;
1613 icount->
parity = cnow.parity;
1614 icount->
brk = cnow.brk;
1617 dev_dbg(&port->
dev,
"%s (%d) TIOCGICOUNT RX=%d, TX=%d\n", __func__,
1633 tmp.line = edge_port->
port->serial->minor;
1634 tmp.port = edge_port->
port->number;
1638 tmp.baud_base = 9600;
1639 tmp.close_delay = 5*
HZ;
1640 tmp.closing_wait = 30*
HZ;
1652 static int edge_ioctl(
struct tty_struct *tty,
1653 unsigned int cmd,
unsigned long arg)
1657 struct edgeport_port *edge_port = usb_get_serial_port_data(port);
1661 dev_dbg(&port->
dev,
"%s - port %d, cmd = 0x%x\n", __func__, port->
number, cmd);
1666 return get_lsr_info(edge_port, (
unsigned int __user *) arg);
1670 return get_serial_info(edge_port, (
struct serial_struct __user *) arg);
1674 cprev = edge_port->
icount;
1683 cnow = edge_port->
icount;
1684 if (cnow.rng == cprev.rng && cnow.dsr == cprev.dsr &&
1685 cnow.dcd == cprev.dcd && cnow.cts == cprev.cts)
1687 if (((arg &
TIOCM_RNG) && (cnow.rng != cprev.rng)) ||
1688 ((arg &
TIOCM_DSR) && (cnow.dsr != cprev.dsr)) ||
1689 ((arg &
TIOCM_CD) && (cnow.dcd != cprev.dcd)) ||
1690 ((arg &
TIOCM_CTS) && (cnow.cts != cprev.cts))) {
1707 static void edge_break(
struct tty_struct *tty,
int break_state)
1710 struct edgeport_port *edge_port = usb_get_serial_port_data(port);
1714 if ((!edge_serial->
is_epic) ||
1720 dev_dbg(&port->
dev,
"%s - Sending IOSP_CMD_CHASE_PORT\n", __func__);
1724 block_until_chase_response(edge_port);
1730 if ((!edge_serial->
is_epic) ||
1733 if (break_state == -1) {
1734 dev_dbg(&port->
dev,
"%s - Sending IOSP_CMD_SET_BREAK\n", __func__);
1735 status = send_iosp_ext_cmd(edge_port,
1738 dev_dbg(&port->
dev,
"%s - Sending IOSP_CMD_CLEAR_BREAK\n", __func__);
1739 status = send_iosp_ext_cmd(edge_port,
1743 dev_dbg(&port->
dev,
"%s - error sending break set/clear command.\n",
1754 unsigned char *buffer,
__u16 bufferLength)
1760 __u16 lastBufferLength;
1763 lastBufferLength = bufferLength + 1;
1765 while (bufferLength > 0) {
1767 if (lastBufferLength == bufferLength) {
1768 dev_dbg(dev,
"%s - stuck in loop, exiting it.\n", __func__);
1771 lastBufferLength = bufferLength;
1773 switch (edge_serial->
rxState) {
1779 if (bufferLength == 0) {
1789 dev_dbg(dev,
"%s - Hdr1=%02X Hdr2=%02X\n", __func__,
1818 process_rcvd_status(edge_serial,
1829 dev_dbg(dev,
"%s - Data for Port %u Len %u\n",
1839 if (bufferLength == 0) {
1846 if (bufferLength < edge_serial->rxBytesRemaining) {
1847 rxLen = bufferLength;
1857 bufferLength -= rxLen;
1863 port = edge_serial->
serial->port[
1865 edge_port = usb_get_serial_port_data(port);
1866 if (edge_port->
open) {
1868 &edge_port->
port->port);
1870 dev_dbg(dev,
"%s - Sending %d bytes to TTY for port %d\n",
1871 __func__, rxLen, edge_serial->
rxPort);
1872 edge_tty_recv(&edge_serial->
serial->dev->dev, tty, buffer, rxLen);
1875 edge_port->
icount.rx += rxLen;
1888 process_rcvd_status(edge_serial,
1914 edge_port = usb_get_serial_port_data(port);
1915 if (edge_port ==
NULL) {
1917 "%s - edge_port == NULL for port %d\n",
1918 __func__, edge_serial->
rxPort);
1928 dev_dbg(dev,
"%s - Port %u EXT CHASE_RSP Data = %02x\n",
1929 __func__, edge_serial->
rxPort, byte3);
1944 dev_dbg(dev,
"%s ========== Port %u CHECK_RSP Sequence = %02x =============\n",
1945 __func__, edge_serial->
rxPort, byte3);
1954 dev_dbg(dev,
"%s - Port %u Open Response Initial MSR = %02x TxBufferSize = %d\n",
1956 handle_new_msr(edge_port, byte2);
1962 change_port_settings(tty,
1963 edge_port, &tty->termios);
1969 edge_port->
open =
true;
1984 dev_dbg(dev,
"%s - Port %u LSR Status = %02x\n",
1985 __func__, edge_serial->
rxPort, byte2);
1986 handle_new_lsr(edge_port,
false, byte2, 0);
1990 dev_dbg(dev,
"%s - Port %u LSR Status = %02x, Data = %02x\n",
1991 __func__, edge_serial->
rxPort, byte2, byte3);
1994 handle_new_lsr(edge_port,
true, byte2, byte3);
2003 dev_dbg(dev,
"%s - Port %u MSR Status = %02x\n",
2004 __func__, edge_serial->
rxPort, byte2);
2010 handle_new_msr(edge_port, byte2);
2014 dev_dbg(dev,
"%s - Unrecognized IOSP status code %u\n", __func__, code);
2025 unsigned char *data,
int length)
2029 cnt = tty_insert_flip_string(tty, data, length);
2031 dev_err(dev,
"%s - dropping data, %d bytes lost\n",
2032 __func__, length - cnt);
2051 icount = &edge_port->
icount;
2097 edge_tty_recv(&edge_port->
port->dev, tty, &data, 1);
2102 icount = &edge_port->
icount;
2103 if (newLsr & LSR_BREAK)
2125 __u16 current_length;
2128 dev_dbg(&serial->
dev->dev,
"%s - %x, %x, %d\n", __func__, extAddr, addr, length);
2131 if (!transfer_buffer) {
2132 dev_err(&serial->
dev->dev,
"%s - kmalloc(%d) failed.\n",
2139 while (length > 0) {
2141 current_length = 64;
2146 memcpy(transfer_buffer, data, current_length);
2148 usb_sndctrlpipe(serial->
dev, 0),
2150 0x40, addr, extAddr, transfer_buffer,
2151 current_length, 300);
2154 length -= current_length;
2155 addr += current_length;
2156 data += current_length;
2159 kfree(transfer_buffer);
2175 __u16 current_length;
2179 if (!transfer_buffer) {
2180 dev_err(&serial->
dev->dev,
"%s - kmalloc(%d) failed.\n",
2187 while (length > 0) {
2189 current_length = 64;
2192 memcpy(transfer_buffer, data, current_length);
2194 usb_sndctrlpipe(serial->
dev, 0),
2197 transfer_buffer, current_length, 300);
2200 length -= current_length;
2201 addr += current_length;
2202 data += current_length;
2205 kfree(transfer_buffer);
2221 __u16 current_length;
2225 if (!transfer_buffer) {
2227 "%s - kmalloc(%d) failed.\n", __func__, 64);
2233 while (length > 0) {
2235 current_length = 64;
2239 usb_rcvctrlpipe(serial->
dev, 0),
2241 0xC0, addr, extAddr, transfer_buffer,
2242 current_length, 300);
2245 memcpy(data, transfer_buffer, current_length);
2246 length -= current_length;
2247 addr += current_length;
2248 data += current_length;
2251 kfree(transfer_buffer);
2260 static int send_iosp_ext_cmd(
struct edgeport_port *edge_port,
2264 unsigned char *currentCommand;
2271 "%s - kmalloc(%d) failed.\n", __func__, 10);
2278 edge_port->
port->number - edge_port->
port->serial->minor,
2281 status = write_cmd_usb(edge_port, buffer, length);
2296 unsigned char *buffer,
int length)
2299 usb_get_serial_data(edge_port->
port->serial);
2304 usb_serial_debug_data(dev, __func__, length, buffer);
2312 dev_dbg(dev,
"%s - ALLOCATE URB %p (outstanding %d)\n",
2315 usb_fill_bulk_urb(urb, edge_serial->
serial->dev,
2316 usb_sndbulkpipe(edge_serial->
serial->dev,
2318 buffer, length, edge_bulk_out_cmd_callback, edge_port);
2325 dev_err(dev,
"%s - usb_submit_urb(write command) failed, status = %d\n",
2338 dev_dbg(dev,
"%s - command timed out\n", __func__);
2351 static int send_cmd_write_baud_rate(
struct edgeport_port *edge_port,
2355 usb_get_serial_data(edge_port->
port->serial);
2357 unsigned char *cmdBuffer;
2358 unsigned char *currCmd;
2363 edge_port->
port->number - edge_port->
port->serial->minor;
2367 dev_dbg(dev,
"SendCmdWriteBaudRate - NOT Setting baud rate for port = %d, baud = %d\n",
2368 edge_port->
port->number, baudRate);
2372 dev_dbg(dev,
"%s - port = %d, baud = %d\n", __func__,
2373 edge_port->
port->number, baudRate);
2375 status = calc_baud_rate_divisor(dev, baudRate, &divisor);
2377 dev_err(dev,
"%s - bad baud rate\n", __func__);
2384 dev_err(dev,
"%s - kmalloc(%d) failed.\n", __func__, 0x100);
2387 currCmd = cmdBuffer;
2400 status = write_cmd_usb(edge_port, cmdBuffer, cmdLen);
2415 static int calc_baud_rate_divisor(
struct device *dev,
int baudrate,
int *divisor)
2420 for (i = 0; i <
ARRAY_SIZE(divisor_table); i++) {
2421 if (divisor_table[i].BaudRate == baudrate) {
2422 *divisor = divisor_table[
i].
Divisor;
2430 if (baudrate > 50 && baudrate < 230400) {
2436 dev_dbg(dev,
"%s - Baud %d = %d\n", __func__, baudrate, custom);
2448 static int send_cmd_write_uart_register(
struct edgeport_port *edge_port,
2452 usb_get_serial_data(edge_port->
port->serial);
2454 unsigned char *cmdBuffer;
2455 unsigned char *currCmd;
2456 unsigned long cmdLen = 0;
2459 dev_dbg(dev,
"%s - write to %s register 0x%02x\n",
2460 (regNum ==
MCR) ?
"MCR" :
"LCR", __func__, regValue);
2465 dev_dbg(dev,
"SendCmdWriteUartReg - Not writing to MCR Register\n");
2472 dev_dbg(dev,
"SendCmdWriteUartReg - Not writing to LCR Register\n");
2478 if (cmdBuffer ==
NULL)
2481 currCmd = cmdBuffer;
2485 edge_port->
port->number - edge_port->
port->serial->minor,
2488 status = write_cmd_usb(edge_port, cmdBuffer, cmdLen);
2504 static void change_port_settings(
struct tty_struct *tty,
2509 usb_get_serial_data(edge_port->
port->serial);
2520 dev_dbg(dev,
"%s - port %d\n", __func__, edge_port->
port->number);
2522 if (!edge_port->
open &&
2524 dev_dbg(dev,
"%s - port not opened\n", __func__);
2528 cflag = tty->termios.c_cflag;
2530 switch (cflag &
CSIZE) {
2533 dev_dbg(dev,
"%s - data bits = 5\n", __func__);
2537 dev_dbg(dev,
"%s - data bits = 6\n", __func__);
2541 dev_dbg(dev,
"%s - data bits = 7\n", __func__);
2546 dev_dbg(dev,
"%s - data bits = 8\n", __func__);
2555 dev_dbg(dev,
"%s - parity = mark\n", __func__);
2558 dev_dbg(dev,
"%s - parity = space\n", __func__);
2560 }
else if (cflag &
PARODD) {
2562 dev_dbg(dev,
"%s - parity = odd\n", __func__);
2565 dev_dbg(dev,
"%s - parity = even\n", __func__);
2568 dev_dbg(dev,
"%s - parity = none\n", __func__);
2573 dev_dbg(dev,
"%s - stop bits = 2\n", __func__);
2576 dev_dbg(dev,
"%s - stop bits = 1\n", __func__);
2580 rxFlow = txFlow = 0x00;
2584 dev_dbg(dev,
"%s - RTS/CTS is enabled\n", __func__);
2586 dev_dbg(dev,
"%s - RTS/CTS is disabled\n", __func__);
2592 unsigned char stop_char =
STOP_CHAR(tty);
2595 if ((!edge_serial->
is_epic) ||
2598 send_iosp_ext_cmd(edge_port,
2600 send_iosp_ext_cmd(edge_port,
2607 dev_dbg(dev,
"%s - INBOUND XON/XOFF is enabled, XON = %2x, XOFF = %2x\n",
2608 __func__, start_char, stop_char);
2610 dev_dbg(dev,
"%s - INBOUND XON/XOFF is disabled\n", __func__);
2616 dev_dbg(dev,
"%s - OUTBOUND XON/XOFF is enabled, XON = %2x, XOFF = %2x\n",
2617 __func__, start_char, stop_char);
2619 dev_dbg(dev,
"%s - OUTBOUND XON/XOFF is disabled\n", __func__);
2624 if ((!edge_serial->
is_epic) ||
2628 if ((!edge_serial->
is_epic) ||
2635 edge_port->
shadowLCR |= (lData | lParity | lStop);
2640 status = send_cmd_write_uart_register(edge_port,
LCR,
2650 status = send_cmd_write_uart_register(edge_port,
MCR,
2662 dev_dbg(dev,
"%s - baud rate = %d\n", __func__, baud);
2663 status = send_cmd_write_baud_rate(edge_port, baud);
2679 static void unicode_to_ascii(
char *
string,
int buflen,
2688 for (i = 0; i < unicode_size; i++) {
2702 static void get_manufacturing_desc(
struct edgeport_serial *edge_serial)
2707 dev_dbg(dev,
"getting manufacturer descriptor\n");
2709 response = rom_read(edge_serial->
serial,
2716 dev_err(dev,
"error in getting manufacturer descriptor\n");
2719 dev_dbg(dev,
"**Manufacturer Descriptor\n");
2720 dev_dbg(dev,
" RomSize: %dK\n",
2722 dev_dbg(dev,
" RamSize: %dK\n",
2726 dev_dbg(dev,
" BoardRev: %d\n",
2728 dev_dbg(dev,
" NumPorts: %d\n",
2730 dev_dbg(dev,
" DescDate: %d/%d/%d\n",
2734 unicode_to_ascii(
string,
sizeof(
string),
2737 dev_dbg(dev,
" SerialNumber: %s\n",
string);
2738 unicode_to_ascii(
string,
sizeof(
string),
2741 dev_dbg(dev,
" AssemblyNumber: %s\n",
string);
2742 unicode_to_ascii(
string,
sizeof(
string),
2745 dev_dbg(dev,
" OemAssyNumber: %s\n",
string);
2746 dev_dbg(dev,
" UartType: %d\n",
2750 dev_dbg(dev,
" IonConfig: %d\n",
2766 dev_dbg(dev,
"getting boot descriptor\n");
2768 response = rom_read(edge_serial->
serial,
2775 dev_err(dev,
"error in getting boot descriptor\n");
2777 dev_dbg(dev,
"**Boot Descriptor:\n");
2778 dev_dbg(dev,
" BootCodeLength: %d\n",
2780 dev_dbg(dev,
" MajorVersion: %d\n",
2782 dev_dbg(dev,
" MinorVersion: %d\n",
2784 dev_dbg(dev,
" BuildNumber: %d\n",
2786 dev_dbg(dev,
" Capabilities: 0x%x\n",
2788 dev_dbg(dev,
" UConfig0: %d\n",
2790 dev_dbg(dev,
" UConfig1: %d\n",
2800 static void load_application_firmware(
struct edgeport_serial *edge_serial)
2813 fw_info =
"downloading firmware version (930)";
2814 fw_name =
"edgeport/down.fw";
2818 fw_info =
"downloading firmware version (80251)";
2819 fw_name =
"edgeport/down2.fw";
2823 dev_dbg(dev,
"No download file specified, skipping download\n");
2830 response = request_ihex_firmware(&fw, fw_name,
2831 &edge_serial->
serial->dev->dev);
2833 dev_err(dev,
"Failed to load image \"%s\" err %d\n",
2839 build = (rec->
data[2] << 8) | rec->
data[3];
2841 dev_dbg(dev,
"%s %d.%d.%d\n", fw_info, rec->
data[0], rec->
data[1], build);
2847 for (rec = ihex_next_binrec(rec); rec;
2848 rec = ihex_next_binrec(rec)) {
2850 response = sram_write(edge_serial->
serial,
2857 "sram_write failed (%x, %x, %d)\n",
2858 Operaddr >> 16, Operaddr & 0xFFFF,
2864 dev_dbg(dev,
"sending exec_dl_code\n");
2866 usb_sndctrlpipe(edge_serial->
serial->dev, 0),
2868 0x40, 0x4000, 0x0001,
NULL, 0, 3000);
2877 static int edge_startup(
struct usb_serial *serial)
2880 struct usb_device *
dev;
2881 struct device *ddev = &serial->
dev->dev;
2884 bool interrupt_in_found;
2886 bool bulk_out_found;
2895 if (edge_serial ==
NULL) {
2896 dev_err(&serial->
dev->dev,
"%s - Out of memory\n", __func__);
2901 usb_set_serial_data(serial, edge_serial);
2904 i =
usb_string(dev, dev->descriptor.iManufacturer,
2908 edge_serial->
name[i++] =
' ';
2915 if (get_epic_descriptor(edge_serial) <= 0) {
2921 get_manufacturing_desc(edge_serial);
2924 get_boot_desc(edge_serial);
2926 get_product_info(edge_serial);
2931 if ((!edge_serial->
is_epic) &&
2934 "Device Reported %d serial ports vs. core thinking we have %d ports, email [email protected] this information.\n",
2939 dev_dbg(ddev,
"%s - time 1 %ld\n", __func__, jiffies);
2944 load_application_firmware(edge_serial);
2946 dev_dbg(ddev,
"%s - time 2 %ld\n", __func__, jiffies);
2949 update_edgeport_E2PROM(edge_serial);
2951 dev_dbg(ddev,
"%s - time 3 %ld\n", __func__, jiffies);
2957 dev_dbg(ddev,
" FirmwareMajorVersion %d.%d.%d\n",
2970 interrupt_in_found = bulk_in_found = bulk_out_found =
false;
2971 for (i = 0; i < serial->
interface->altsetting[0]
2972 .desc.bNumEndpoints; ++
i) {
2976 endpoint = &serial->
interface->altsetting[0].
2978 buffer_size = usb_endpoint_maxp(endpoint);
2979 if (!interrupt_in_found &&
2980 (usb_endpoint_is_int_in(endpoint))) {
2982 dev_dbg(ddev,
"found interrupt in\n");
2988 dev_err(ddev,
"out of memory\n");
2994 dev_err(ddev,
"out of memory\n");
3009 edge_interrupt_callback,
3013 interrupt_in_found =
true;
3016 if (!bulk_in_found &&
3017 (usb_endpoint_is_bulk_in(endpoint))) {
3019 dev_dbg(ddev,
"found bulk in\n");
3025 dev_err(ddev,
"out of memory\n");
3031 dev_err(&dev->dev,
"out of memory\n");
3039 usb_fill_bulk_urb(edge_serial->
read_urb, dev,
3040 usb_rcvbulkpipe(dev,
3043 usb_endpoint_maxp(endpoint),
3044 edge_bulk_in_callback,
3046 bulk_in_found =
true;
3049 if (!bulk_out_found &&
3050 (usb_endpoint_is_bulk_out(endpoint))) {
3052 dev_dbg(ddev,
"found bulk out\n");
3055 bulk_out_found =
true;
3059 if (!interrupt_in_found || !bulk_in_found || !bulk_out_found) {
3060 dev_err(ddev,
"Error - the proper endpoints were not found!\n");
3069 dev_err(ddev,
"%s - Error %d submitting control urb\n",
3070 __func__, response);
3080 static void edge_disconnect(
struct usb_serial *serial)
3102 static void edge_release(
struct usb_serial *serial)
3113 edge_port = kzalloc(
sizeof(*edge_port),
GFP_KERNEL);
3120 usb_set_serial_port_data(port, edge_port);
3129 edge_port = usb_get_serial_port_data(port);