116 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
118 #include <linux/module.h>
120 #include <linux/kernel.h>
121 #include <linux/tty.h>
124 #include <linux/fs.h>
125 #include <linux/sched.h>
126 #include <linux/serial.h>
132 #include <linux/slab.h>
137 #include <linux/pci.h>
141 #define InterruptTheCard(base) outw(0, (base) + 0xc)
142 #define ClearInterrupt(base) inw((base) + 0x0a)
145 #define isicom_paranoia_check(a, b, c) __isicom_paranoia_check((a), (b), (c))
147 #define isicom_paranoia_check(a, b, c) 0
169 .id_table = isicom_pci_tbl,
170 .probe = isicom_probe,
174 static int prev_card = 3;
177 static void isicom_tx(
unsigned long _data);
178 static void isicom_start(
struct tty_struct *tty);
184 static signed char linuxb_to_isib[] = {
185 -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 13, 15, 16, 17, 18, 19, 20, 21
223 static inline int WaitTillCardIsFree(
unsigned long base)
225 unsigned int count = 0;
228 while (!(
inw(base + 0
xe) & 0x1) && count++ < 100)
234 return !(
inw(base + 0
xe) & 0x1);
239 unsigned long base = card->
base;
242 for (retries = 0; retries < 10; retries++) {
244 for (a = 0; a < 10; a++) {
245 if (
inw(base + 0
xe) & 0x1)
257 static void unlock_card(
struct isi_board *card)
270 unsigned long base = card->
base;
273 if (WaitTillCardIsFree(base))
283 static inline void drop_dtr(
struct isi_port *port)
286 unsigned long base = card->
base;
289 if (WaitTillCardIsFree(base))
299 static inline void raise_rts(
struct isi_port *port)
302 unsigned long base = card->
base;
305 if (WaitTillCardIsFree(base))
315 static inline void drop_rts(
struct isi_port *port)
318 unsigned long base = card->
base;
321 if (WaitTillCardIsFree(base))
332 static void isicom_dtr_rts(
struct tty_port *port,
int on)
336 unsigned long base = card->
base;
339 if (!lock_card(card))
357 static void drop_dtr_rts(
struct isi_port *port)
360 unsigned long base = card->
base;
363 if (WaitTillCardIsFree(base))
377 static inline int __isicom_paranoia_check(
struct isi_port const *port,
381 pr_warning(
"Warning: bad isicom magic for dev %s in %s.\n",
386 pr_warning(
"Warning: NULL isicom port for dev %s in %s.\n",
401 static void isicom_tx(
unsigned long _data)
406 short txcount, wrd, residue, word_count,
cnt;
411 card = (prev_card + 1) & 0x0003;
412 while (count-- > 0) {
415 card = (card + 1) & 0x0003;
422 count = isi_card[
card].port_count;
423 port = isi_card[
card].ports;
424 base = isi_card[
card].base;
427 for (retries = 0; retries < 100; retries++) {
428 if (
inw(base + 0
xe) & 0x1)
439 for (; count > 0; count--, port++) {
449 if (!(
inw(base + 0x02) & (1 << port->
channel)))
452 pr_debug(
"txing %d bytes, port%d.\n",
454 outw((port->
channel << isi_card[card].shift_count) | txcount,
461 if (residue ==
YES) {
479 word_count = cnt >> 1;
483 txcount -= (word_count << 1);
484 port->
xmit_cnt -= (word_count << 1);
505 spin_unlock_irqrestore(&isi_card[card].card_lock, flags);
531 if (!(
inw(base + 0x0e) & 0x02))
540 outw(0x8000, base+0x04);
546 byte_count = header & 0xff;
549 pr_warning(
"%s(0x%lx): %d(channel) > port_count.\n",
550 __func__, base, channel+1);
551 outw(0x0000, base+0x04);
557 outw(0x0000, base+0x04);
564 word_count = byte_count >> 1;
565 while (byte_count > 1) {
569 if (byte_count & 0x01)
571 outw(0x0000, base+0x04);
576 if (header & 0x8000) {
578 switch (header & 0xff) {
603 if (tty_port_cts_enabled(&port->
port)) {
606 port->
port.tty->hw_stopped = 0;
612 }
else if (!(header &
ISI_CTS)) {
644 pr_debug(
"%s: stats!!!\n", __func__);
648 pr_debug(
"%s: Unknown code in status packet.\n",
655 pr_debug(
"%s: Can rx %d of %d bytes.\n",
656 __func__, count, byte_count);
657 word_count = count >> 1;
658 insw(base, rp, word_count);
659 byte_count -= (word_count << 1);
660 if (count & 0x0001) {
661 tty_insert_flip_char(tty,
inw(base) & 0xff,
665 if (byte_count > 0) {
666 pr_debug(
"%s(0x%lx:%d): Flip buffer overflow! dropping bytes...\n",
667 __func__, base, channel + 1);
669 while (byte_count > 0) {
676 outw(0x0000, base+0x04);
683 static void isicom_config_port(
struct tty_struct *tty)
688 unsigned long base = card->
base;
704 if (baud < 1 || baud > 4)
705 tty->termios.c_cflag &= ~CBAUDEX;
725 if (linuxb_to_isib[baud] == -1) {
732 if (WaitTillCardIsFree(base) == 0) {
734 outw(linuxb_to_isib[baud] << 8 | 0x03, base);
758 outw(channel_setup, base);
778 if (WaitTillCardIsFree(base) == 0) {
780 outw(flow_ctrl << 8 | 0x05, base);
794 static inline void isicom_setup_board(
struct isi_board *bp)
802 for (channel = 0; channel < bp->
port_count; channel++, port++)
821 isicom_setup_board(card);
826 if (WaitTillCardIsFree(card->
base) == 0) {
832 isicom_config_port(tty);
833 spin_unlock_irqrestore(&card->
card_lock, flags);
838 static int isicom_carrier_raised(
struct tty_port *port)
852 card = &isi_card[board];
858 if (line > ((board * 16) + card->
port_count - 1))
861 port = &isi_ports[line];
873 tport = isicom_find_port(tty);
885 static void isicom_shutdown_port(
struct isi_port *port)
889 if (--card->
count < 0) {
890 pr_debug(
"%s: bad board(0x%lx) count %d.\n",
899 static void isicom_flush_buffer(
struct tty_struct *tty)
910 spin_unlock_irqrestore(&card->
card_lock, flags);
915 static void isicom_shutdown(
struct tty_port *port)
926 isicom_shutdown_port(ip);
927 spin_unlock_irqrestore(&card->
card_lock, flags);
931 static void isicom_close(
struct tty_struct *tty,
struct file *filp)
946 static int isicom_write(
struct tty_struct *tty,
const unsigned char *
buf,
975 spin_unlock_irqrestore(&card->
card_lock, flags);
980 static int isicom_put_char(
struct tty_struct *tty,
unsigned char ch)
991 spin_unlock_irqrestore(&card->
card_lock, flags);
998 spin_unlock_irqrestore(&card->
card_lock, flags);
1003 static void isicom_flush_chars(
struct tty_struct *tty)
1011 !port->
port.xmit_buf)
1020 static int isicom_write_room(
struct tty_struct *tty)
1035 static int isicom_chars_in_buffer(
struct tty_struct *tty)
1048 unsigned long base = card->
base;
1053 if (!lock_card(card))
1057 outw((length & 0xff) << 8 | 0x00, base);
1058 outw((length & 0xff00), base);
1065 static int isicom_tiocmget(
struct tty_struct *tty)
1082 static int isicom_tiocmset(
struct tty_struct *tty,
1083 unsigned int set,
unsigned int clear)
1086 unsigned long flags;
1101 spin_unlock_irqrestore(&port->
card->card_lock, flags);
1106 static int isicom_set_serial_info(
struct tty_struct *tty,
1121 if ((newinfo.close_delay != port->
port.close_delay) ||
1122 (newinfo.closing_wait != port->
port.closing_wait) ||
1131 port->
port.close_delay = newinfo.close_delay;
1132 port->
port.closing_wait = newinfo.closing_wait;
1136 if (reconfig_port) {
1137 unsigned long flags;
1139 isicom_config_port(tty);
1140 spin_unlock_irqrestore(&port->
card->card_lock, flags);
1146 static int isicom_get_serial_info(
struct isi_port *port,
1152 memset(&out_info, 0,
sizeof(out_info));
1154 out_info.line = port - isi_ports;
1155 out_info.port = port->
card->base;
1156 out_info.irq = port->
card->irq;
1157 out_info.flags = port->
port.flags;
1159 out_info.close_delay = port->
port.close_delay;
1160 out_info.closing_wait = port->
port.closing_wait;
1167 static int isicom_ioctl(
struct tty_struct *tty,
1168 unsigned int cmd,
unsigned long arg)
1178 return isicom_get_serial_info(port, argp);
1181 return isicom_set_serial_info(tty, argp);
1190 static void isicom_set_termios(
struct tty_struct *tty,
1194 unsigned long flags;
1199 if (tty->termios.c_cflag == old_termios->
c_cflag &&
1200 tty->termios.c_iflag == old_termios->
c_iflag)
1204 isicom_config_port(tty);
1205 spin_unlock_irqrestore(&port->
card->card_lock, flags);
1208 !(tty->termios.c_cflag &
CRTSCTS)) {
1215 static void isicom_throttle(
struct tty_struct *tty)
1229 static void isicom_unthrottle(
struct tty_struct *tty)
1243 static void isicom_stop(
struct tty_struct *tty)
1256 static void isicom_start(
struct tty_struct *tty)
1268 static void isicom_hangup(
struct tty_struct *tty)
1283 .open = isicom_open,
1284 .close = isicom_close,
1285 .write = isicom_write,
1286 .put_char = isicom_put_char,
1287 .flush_chars = isicom_flush_chars,
1288 .write_room = isicom_write_room,
1289 .chars_in_buffer = isicom_chars_in_buffer,
1290 .ioctl = isicom_ioctl,
1291 .set_termios = isicom_set_termios,
1292 .throttle = isicom_throttle,
1293 .unthrottle = isicom_unthrottle,
1294 .stop = isicom_stop,
1295 .start = isicom_start,
1296 .hangup = isicom_hangup,
1297 .flush_buffer = isicom_flush_buffer,
1298 .tiocmget = isicom_tiocmget,
1299 .tiocmset = isicom_tiocmset,
1300 .break_ctl = isicom_send_break,
1304 .carrier_raised = isicom_carrier_raised,
1305 .dtr_rts = isicom_dtr_rts,
1306 .activate = isicom_activate,
1307 .shutdown = isicom_shutdown,
1311 const unsigned int card,
unsigned int *
signature)
1313 struct isi_board *board = pci_get_drvdata(pdev);
1314 unsigned long base = board->
base;
1315 unsigned int sig, portcount = 0;
1318 dev_dbg(&pdev->
dev,
"ISILoad:Resetting Card%d at 0x%lx\n", card + 1,
1325 outw(0, base + 0x8);
1329 sig =
inw(base + 0x4) & 0xff;
1331 if (sig != 0xa5 && sig != 0xbb && sig != 0xcc && sig != 0xdd &&
1333 dev_warn(&pdev->
dev,
"ISILoad:Card%u reset failure (Possible "
1334 "bad I/O Port Address 0x%lx).\n", card + 1, base);
1342 portcount =
inw(base + 0x2);
1343 if (!(
inw(base + 0
xe) & 0x1) || (portcount != 0 && portcount != 4 &&
1344 portcount != 8 && portcount != 16)) {
1345 dev_err(&pdev->
dev,
"ISILoad:PCI Card%d reset failure.\n",
1355 board->
port_count = (portcount == 4) ? 4 : 8;
1372 const unsigned int index,
const unsigned int signature)
1374 struct isi_board *board = pci_get_drvdata(pdev);
1376 unsigned long base = board->
base;
1389 switch (signature) {
1391 name =
"isi608.bin";
1394 name =
"isi608em.bin";
1397 name =
"isi616em.bin";
1400 name =
"isi4608.bin";
1403 name =
"isi4616.bin";
1416 for (
frame = (
struct stframe *)fw->
data;
1420 if (WaitTillCardIsFree(base))
1427 word_count =
frame->count / 2 +
frame->count % 2;
1428 outw(word_count, base);
1433 if (WaitTillCardIsFree(base))
1436 status =
inw(base + 0x4);
1438 dev_warn(&pdev->
dev,
"Card%d rejected load header:\n"
1442 index + 1,
frame->addr,
frame->count, status);
1451 if (WaitTillCardIsFree(base))
1454 status =
inw(base + 0x4);
1456 dev_err(&pdev->
dev,
"Card%d got out of sync.Card "
1457 "Status:0x%x\n", index + 1, status);
1464 for (
frame = (
struct stframe *)fw->
data;
1468 if (WaitTillCardIsFree(base))
1475 word_count = (
frame->count >> 1) +
frame->count % 2;
1476 outw(word_count + 1, base);
1481 if (WaitTillCardIsFree(base))
1484 status =
inw(base + 0x4);
1486 dev_warn(&pdev->
dev,
"Card%d rejected verify header:\n"
1490 index + 1,
frame->addr,
frame->count, status);
1496 dev_err(&pdev->
dev,
"Card%d, firmware upload "
1497 "failed, not enough memory\n", index + 1);
1501 insw(base, data, word_count);
1504 for (a = 0; a <
frame->count; a++)
1505 if (data[a] !=
frame->data[a]) {
1507 dev_err(&pdev->
dev,
"Card%d, firmware upload "
1508 "failed\n", index + 1);
1515 if (WaitTillCardIsFree(base))
1518 status =
inw(base + 0x4);
1520 dev_err(&pdev->
dev,
"Card%d verify got out of sync. "
1521 "Card Status:0x%x\n", index + 1, status);
1527 if (WaitTillCardIsFree(base))
1535 outw(0x0, base + 0x4);
1549 static unsigned int card_count;
1555 int retval = -
EPERM;
1571 if (isi_card[index].base == 0) {
1572 board = &isi_card[
index];
1576 if (index == BOARD_COUNT) {
1586 pci_set_drvdata(pdev, board);
1590 dev_err(&pdev->
dev,
"I/O Region 0x%lx-0x%lx is busy. Card%d "
1591 "will be disabled.\n", board->
base, board->
base + 15,
1600 dev_err(&pdev->
dev,
"Could not install handler at Irq %d. "
1601 "Card%d will be disabled.\n", board->
irq, index + 1);
1605 retval = reset_card(pdev, index, &signature);
1609 retval = load_firmware(pdev, index, signature);
1613 for (index = 0; index < board->
port_count; index++)
1615 isicom_normal, board->
index * 16 + index,
1635 struct isi_board *board = pci_get_drvdata(pdev);
1648 static int __init isicom_init(
void)
1654 port = &isi_ports[idx * 16];
1657 for (channel = 0; channel < 16; channel++, port++) {
1659 port->
port.ops = &isicom_port_ops;
1663 port->
port.close_delay = 50 *
HZ/100;
1664 port->
port.closing_wait = 3000 *
HZ/100;
1668 isi_card[
idx].base = 0;
1669 isi_card[
idx].irq = 0;
1673 isicom_normal = alloc_tty_driver(
PORT_COUNT);
1674 if (!isicom_normal) {
1679 isicom_normal->
name =
"ttyM";
1693 pr_debug(
"Couldn't register the dialin driver\n");
1697 retval = pci_register_driver(&isicom_driver);
1699 pr_err(
"Unable to register pci driver.\n");
1714 static void __exit isicom_exit(
void)