3 #undef Z_EXT_CHARS_IN_BUFFER
22 #define CY_VERSION "2.6"
41 #define SERIAL_PARANOIA_CHECK
43 #undef CY_DEBUG_THROTTLE
48 #undef CY_DEBUG_INTERRUPTS
50 #undef CY_ENABLE_MONITORING
56 #include <linux/module.h>
57 #include <linux/errno.h>
58 #include <linux/signal.h>
59 #include <linux/sched.h>
62 #include <linux/tty.h>
64 #include <linux/serial.h>
66 #include <linux/string.h>
67 #include <linux/fcntl.h>
68 #include <linux/ptrace.h>
69 #include <linux/cyclades.h>
75 #include <linux/bitops.h>
77 #include <linux/device.h>
78 #include <linux/slab.h>
83 #include <linux/kernel.h>
84 #include <linux/pci.h>
86 #include <linux/stat.h>
90 static void cy_send_xchar(
struct tty_struct *tty,
char ch);
92 #ifndef SERIAL_XMIT_SIZE
93 #define SERIAL_XMIT_SIZE (min(PAGE_SIZE, 4096))
96 #define STD_COM_FLAGS (0)
99 #define ZL_MAX_BLOCKS 16
100 #define DRIVER_VERSION 0x02010203
101 #define RAM_SIZE 0x80000
144 static unsigned int cy_isa_addresses[] = {
153 0, 0, 0, 0, 0, 0, 0, 0
156 #define NR_ISA_ADDRS ARRAY_SIZE(cy_isa_addresses)
171 static int cy_next_channel;
183 0, 50, 75, 110, 134, 150, 200, 300, 600, 1200,
184 1800, 2400, 4800, 9600, 19200, 38400, 57600, 76800, 115200, 150000,
188 static const char baud_co_25[] = {
191 0x00, 0x04, 0x04, 0x04, 0x04, 0x04, 0x03, 0x03, 0x03, 0x02,
192 0x02, 0x02, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
195 static const char baud_bpr_25[] = {
196 0x00, 0xf5, 0xa3, 0x6f, 0x5c, 0x51, 0xf5, 0xa3, 0x51, 0xa3,
197 0x6d, 0x51, 0xa3, 0x51, 0xa3, 0x51, 0x36, 0x29, 0x1b, 0x15
200 static const char baud_co_60[] = {
203 0x00, 0x00, 0x00, 0x04, 0x04, 0x04, 0x04, 0x04, 0x03, 0x03,
204 0x03, 0x02, 0x02, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
208 static const char baud_bpr_60[] = {
209 0x00, 0x82, 0x21, 0xff, 0xdb, 0xc3, 0x92, 0x62, 0xc3, 0x62,
210 0x41, 0xc3, 0x62, 0xc3, 0x62, 0xc3, 0x82, 0x62, 0x41, 0x32,
214 static const char baud_cor3[] = {
215 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a,
216 0x0a, 0x0a, 0x0a, 0x09, 0x09, 0x08, 0x08, 0x08, 0x08, 0x07,
231 static const char rflow_thr[] = {
232 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
233 0x00, 0x00, 0x00, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a,
240 static const unsigned int cy_chip_offset[] = { 0x0000,
279 static unsigned detect_isa_irq(
void __iomem *);
282 #ifndef CONFIG_CYZ_INTR
283 static void cyz_poll(
unsigned long);
291 static void cyz_rx_restart(
unsigned long);
316 return readl(&ctl_addr->init_ctrl) & (1 << 17);
328 return (card->
hw_ver ==
ZO_V1 || cyz_fpga_loaded(card)) &&
335 #ifdef SERIAL_PARANOIA_CHECK
338 "in %s\n", name, routine);
344 "struct (%s) in %s\n", name, routine);
367 for (i = 0; i < 100; i++) {
385 return __cyy_issue_cmd(port->
u.
cyy.base_addr, cmd,
386 port->
card->bus_index);
394 unsigned long irqs,
flags;
395 int save_xir, save_car;
436 return (irq > 0) ? irq : 0;
448 #ifdef CY_DEBUG_INTERRUPTS
452 save_xir =
readb(base_addr + (
CyRIR << index));
454 info = &cinfo->
ports[channel + chip * 4];
455 save_car = cyy_readb(info,
CyCAR);
456 cyy_writeb(info,
CyCAR, save_xir);
463 data = cyy_readb(info,
CyRDSR);
465 char_count = cyy_readb(info,
CyRDCR);
467 data = cyy_readb(info,
CyRDSR);
473 data = cyy_readb(info,
CyRDSR);
492 if (data & CyBREAK) {
493 tty_insert_flip_char(tty,
499 }
else if (data & CyFRAME) {
500 tty_insert_flip_char(tty,
505 }
else if (data & CyPARITY) {
507 tty_insert_flip_char(tty,
512 }
else if (data & CyOVERRUN) {
513 tty_insert_flip_char(tty, 0,
520 tty_insert_flip_char(tty,
530 tty_insert_flip_char(tty, 0,
541 info->
icount.buf_overrun++;
546 char_count = cyy_readb(info,
CyRDCR);
548 #ifdef CY_ENABLE_MONITORING
549 ++info->
mon.int_count;
550 info->
mon.char_count += char_count;
551 if (char_count > info->
mon.char_max)
552 info->
mon.char_max = char_count;
553 info->
mon.char_last = char_count;
557 data = cyy_readb(info,
CyRDSR);
571 cyy_writeb(info,
CyRIR, save_xir & 0x3f);
572 cyy_writeb(info,
CyCAR, save_car);
575 static void cyy_chip_tx(
struct cyclades_card *cinfo,
unsigned int chip,
580 int char_count, index = cinfo->
bus_index;
586 #ifdef CY_DEBUG_INTERRUPTS
591 save_xir =
readb(base_addr + (
CyTIR << index));
593 save_car =
readb(base_addr + (
CyCAR << index));
596 info = &cinfo->
ports[channel + chip * 4];
608 cyy_writeb(info,
CyTDR, outch);
616 cyy_writeb(info,
CyTDR, 0);
617 cyy_writeb(info,
CyTDR, 0x81);
622 cyy_writeb(info,
CyTDR, 0);
623 cyy_writeb(info,
CyTDR, 0x83);
629 while (char_count-- > 0) {
633 cyy_readb(info,
CySRER) & ~CyTxMpty);
635 cyy_writeb(info,
CySRER, CyTxMpty |
664 cyy_writeb(info,
CyTDR, outch);
667 if (char_count > 1) {
671 cyy_writeb(info,
CyTDR, outch);
672 cyy_writeb(info,
CyTDR, 0);
684 cyy_writeb(info,
CyTIR, save_xir & 0x3f);
685 cyy_writeb(info,
CyCAR, save_car);
688 static void cyy_chip_modem(
struct cyclades_card *cinfo,
int chip,
694 u8 save_xir,
channel, save_car, mdm_change, mdm_status;
697 save_xir =
readb(base_addr + (
CyMIR << index));
699 info = &cinfo->
ports[channel + chip * 4];
700 save_car = cyy_readb(info,
CyCAR);
701 cyy_writeb(info,
CyCAR, save_xir);
703 mdm_change = cyy_readb(info,
CyMISR);
704 mdm_status = cyy_readb(info,
CyMSVR1);
712 if (mdm_change &
CyDCD)
714 if (mdm_change &
CyCTS)
716 if (mdm_change &
CyDSR)
718 if (mdm_change &
CyRI)
725 if (mdm_status & CyDCD)
730 if ((mdm_change & CyCTS) && tty_port_cts_enabled(&info->
port)) {
732 if (mdm_status & CyCTS) {
741 if (!(mdm_status & CyCTS)) {
757 cyy_writeb(info,
CyMIR, save_xir & 0x3f);
758 cyy_writeb(info,
CyCAR, save_car);
770 unsigned int chip, too_many, had_work;
774 #ifdef CY_DEBUG_INTERRUPTS
795 for (chip = 0; chip < cinfo->
num_chips; chip++) {
799 while ((status =
readb(base_addr +
800 (
CySVRR << index))) != 0x00) {
807 if (1000 < too_many++)
811 cyy_chip_rx(cinfo, chip, base_addr);
813 cyy_chip_tx(cinfo, chip, base_addr);
815 cyy_chip_modem(cinfo, chip, base_addr);
829 static void cyy_change_rts_dtr(
struct cyclades_port *info,
unsigned int set,
850 cyy_writeb(info,
CyCAR, channel);
851 cyy_writeb(info, msvrr, rts);
854 cyy_writeb(info,
CyCAR, channel);
855 cyy_writeb(info, msvrr, ~rts);
858 cyy_writeb(info,
CyCAR, channel);
859 cyy_writeb(info, msvrd, dtr);
868 cyy_writeb(info,
CyCAR, channel);
869 cyy_writeb(info, msvrd, ~dtr);
889 unsigned long loc_doorbell;
893 *cmd = (
char)(0xff & loc_doorbell);
910 if (!cyz_is_loaded(cinfo))
915 while ((
readl(pci_doorbell) & 0xff) != 0) {
917 return (
int)(
readl(pci_doorbell) & 0xff);
931 unsigned int char_count;
938 __u32 rx_put, rx_get, new_rx_get, rx_bufsize, rx_bufaddr;
944 if (rx_put >= rx_get)
945 char_count = rx_put - rx_get;
947 char_count = rx_put - rx_get + rx_bufsize;
950 #ifdef CY_ENABLE_MONITORING
951 info->
mon.int_count++;
952 info->
mon.char_count += char_count;
953 if (char_count > info->
mon.char_max)
954 info->
mon.char_max = char_count;
955 info->
mon.char_last = char_count;
959 new_rx_get = (new_rx_get + char_count) &
973 len =
min_t(
unsigned int,
min(len, char_count),
974 rx_bufsize - new_rx_get);
977 rx_bufaddr + new_rx_get, len);
979 new_rx_get = (new_rx_get + len) &
990 new_rx_get = (new_rx_get + 1) &
997 #ifdef CONFIG_CYZ_INTR
1001 if (rx_put >= rx_get)
1002 char_count = rx_put - rx_get;
1004 char_count = rx_put - rx_get + rx_bufsize;
1006 !timer_pending(&cyz_rx_full_timer[
1024 unsigned int char_count;
1028 __u32 tx_put, tx_get, tx_bufsize, tx_bufaddr;
1037 if (tx_put >= tx_get)
1038 char_count = tx_get - tx_put - 1 + tx_bufsize;
1040 char_count = tx_get - tx_put - 1;
1051 tx_put = (tx_put + 1) & (tx_bufsize - 1);
1057 while (0 < (small_count =
min_t(
unsigned int,
1058 tx_bufsize - tx_put,
min_t(
unsigned int,
1068 tx_put = (tx_put + small_count) & (tx_bufsize - 1);
1069 char_count -= small_count;
1070 info->
icount.tx += small_count;
1076 while (info->
xmit_cnt && char_count) {
1083 tx_put = (tx_put + 1) & (tx_bufsize - 1);
1107 while (cyz_fetch_msg(cinfo, &channel, &cmd, ¶m) == 1) {
1122 tty_insert_flip_char(tty, 0,
TTY_FRAME);
1127 tty_insert_flip_char(tty, 0,
TTY_BREAK);
1135 u32 dcd = fw_ver > 241 ? param :
1160 #ifdef CONFIG_CYZ_INTR
1165 #ifdef CY_DEBUG_INTERRUPTS
1167 "port %ld\n", info->
card, channel);
1169 cyz_handle_rx(info, tty);
1175 #ifdef CY_DEBUG_INTERRUPTS
1177 "port %ld\n", info->
card, channel);
1179 cyz_handle_tx(info, tty);
1196 #ifdef CONFIG_CYZ_INTR
1197 static irqreturn_t cyz_interrupt(
int irq,
void *dev_id)
1201 if (
unlikely(!cyz_is_loaded(cinfo))) {
1202 #ifdef CY_DEBUG_INTERRUPTS
1210 cyz_handle_cmd(cinfo);
1215 static void cyz_rx_restart(
unsigned long arg)
1221 unsigned long flags;
1227 info->
line, retval);
1229 spin_unlock_irqrestore(&card->
card_lock, flags);
1234 static void cyz_poll(
unsigned long arg)
1241 for (card = 0; card <
NR_CARDS; card++) {
1242 cinfo = &cy_card[
card];
1244 if (!cy_is_Z(cinfo))
1246 if (!cyz_is_loaded(cinfo))
1255 cyz_handle_cmd(cinfo);
1257 for (port = 0; port < cinfo->
nports; port++) {
1266 cyz_handle_rx(info, tty);
1267 cyz_handle_tx(info, tty);
1271 expires =
jiffies + cyz_polling_cycle;
1287 unsigned long flags;
1309 if (info->
port.xmit_buf)
1312 info->
port.xmit_buf = (
unsigned char *)page;
1314 spin_unlock_irqrestore(&card->
card_lock, flags);
1316 cy_set_line_char(info, tty);
1318 if (!cy_is_Z(card)) {
1323 cyy_writeb(info,
CyCAR, channel);
1331 cyy_change_rts_dtr(info, TIOCM_RTS | TIOCM_DTR, 0);
1337 if (!cyz_is_loaded(card))
1340 #ifdef CY_DEBUG_OPEN
1342 "base_addr %p\n", card, channel, card->
base_addr);
1348 #ifdef CONFIG_CYZ_INTR
1357 #ifdef CONFIG_CYZ_INTR
1366 retval = cyz_issue_cmd(card, channel,
C_CM_IOCTL, 0L);
1369 "%x\n", info->
line, retval);
1376 "%x\n", info->
line, retval);
1396 spin_unlock_irqrestore(&card->
card_lock, flags);
1398 #ifdef CY_DEBUG_OPEN
1404 spin_unlock_irqrestore(&card->
card_lock, flags);
1412 unsigned long flags;
1415 if (!cy_is_Z(card)) {
1417 cyy_writeb(info,
CyCAR, channel & 0x03);
1419 spin_unlock_irqrestore(&card->
card_lock, flags);
1421 #ifdef CONFIG_CYZ_INTR
1425 retval = cyz_issue_cmd(card, channel,
C_CM_INTBACK, 0L);
1428 "%x\n", info->
line, retval);
1430 spin_unlock_irqrestore(&card->
card_lock, flags);
1444 unsigned long flags;
1450 if (!cy_is_Z(card)) {
1456 if (info->
port.xmit_buf) {
1457 unsigned char *
temp;
1458 temp = info->
port.xmit_buf;
1462 if (tty->termios.c_cflag &
HUPCL)
1463 cyy_change_rts_dtr(info, 0, TIOCM_RTS | TIOCM_DTR);
1471 spin_unlock_irqrestore(&card->
card_lock, flags);
1473 #ifdef CY_DEBUG_OPEN
1476 "base_addr %p\n", card, channel, card->
base_addr);
1479 if (!cyz_is_loaded(card))
1484 if (info->
port.xmit_buf) {
1485 unsigned char *
temp;
1486 temp = info->
port.xmit_buf;
1491 if (tty->termios.c_cflag &
HUPCL)
1497 spin_unlock_irqrestore(&card->
card_lock, flags);
1500 #ifdef CY_DEBUG_OPEN
1522 if (line < cy_card[i].first_line + cy_card[i].nports &&
1523 line >= cy_card[i].first_line)
1527 info = &cy_card[
i].ports[line - cy_card[
i].first_line];
1535 if (cy_is_Z(info->
card)) {
1539 if (!cyz_is_loaded(cinfo)) {
1540 if (cinfo->
hw_ver ==
ZE_V1 && cyz_fpga_loaded(cinfo) &&
1544 "need an external power supply for "
1545 "this number of ports.\nFirmware "
1553 #ifdef CONFIG_CYZ_INTR
1563 intr_ctrl_stat) | 0x0900;
1565 intr_ctrl_stat, intr);
1567 retval = cyz_issue_cmd(cinfo, 0,
1571 "was %x\n", retval);
1581 #ifdef CY_DEBUG_OTHER
1585 if (serial_paranoia_check(info, tty->
name,
"cy_open"))
1588 #ifdef CY_DEBUG_OPEN
1593 #ifdef CY_DEBUG_COUNT
1610 retval = cy_startup(info, tty);
1616 #ifdef CY_DEBUG_OPEN
1618 "with %d\n", retval);
1626 #ifdef CY_DEBUG_OPEN
1635 static void cy_wait_until_sent(
struct tty_struct *tty,
int timeout)
1639 unsigned long orig_jiffies;
1642 if (serial_paranoia_check(info, tty->
name,
"cy_wait_until_sent"))
1658 char_time = char_time / 5;
1664 char_time =
min(char_time, timeout);
1674 if (!timeout || timeout > 2 * info->
timeout)
1678 if (!cy_is_Z(card)) {
1682 if (timeout &&
time_after(jiffies, orig_jiffies +
1691 static void cy_flush_buffer(
struct tty_struct *tty)
1696 unsigned long flags;
1702 if (serial_paranoia_check(info, tty->
name,
"cy_flush_buffer"))
1710 spin_unlock_irqrestore(&card->
card_lock, flags);
1712 if (cy_is_Z(card)) {
1718 "was %x\n", info->
line, retval);
1720 spin_unlock_irqrestore(&card->
card_lock, flags);
1726 static void cy_do_close(
struct tty_port *port)
1731 unsigned long flags;
1738 if (!cy_is_Z(card)) {
1740 cyy_writeb(info,
CyCAR, channel & 0x03);
1745 spin_unlock_irqrestore(&card->
card_lock, flags);
1746 cy_wait_until_sent(port->
tty, info->
timeout);
1757 retval = cyz_issue_cmd(card, channel,
C_CM_IOCTLW, 0L);
1760 "ttyC%d was %x\n", info->
line, retval);
1762 spin_unlock_irqrestore(&card->
card_lock, flags);
1768 spin_unlock_irqrestore(&card->
card_lock, flags);
1769 cy_shutdown(info, port->
tty);
1778 if (!info || serial_paranoia_check(info, tty->
name,
"cy_close"))
1796 static int cy_write(
struct tty_struct *tty,
const unsigned char *buf,
int count)
1799 unsigned long flags;
1806 if (serial_paranoia_check(info, tty->
name,
"cy_write"))
1809 if (!info->
port.xmit_buf)
1828 spin_unlock_irqrestore(&info->
card->card_lock, flags);
1846 static int cy_put_char(
struct tty_struct *tty,
unsigned char ch)
1849 unsigned long flags;
1855 if (serial_paranoia_check(info, tty->
name,
"cy_put_char"))
1858 if (!info->
port.xmit_buf)
1863 spin_unlock_irqrestore(&info->
card->card_lock, flags);
1872 spin_unlock_irqrestore(&info->
card->card_lock, flags);
1880 static void cy_flush_chars(
struct tty_struct *tty)
1888 if (serial_paranoia_check(info, tty->
name,
"cy_flush_chars"))
1892 !info->
port.xmit_buf)
1904 static int cy_write_room(
struct tty_struct *tty)
1913 if (serial_paranoia_check(info, tty->
name,
"cy_write_room"))
1921 static int cy_chars_in_buffer(
struct tty_struct *tty)
1925 if (serial_paranoia_check(info, tty->
name,
"cy_chars_in_buffer"))
1928 #ifdef Z_EXT_CHARS_IN_BUFFER
1929 if (!cy_is_Z(info->
card)) {
1936 #ifdef Z_EXT_CHARS_IN_BUFFER
1945 if (tx_put >= tx_get)
1946 char_count = tx_put -
tx_get;
1953 return info->
xmit_cnt + char_count;
1966 int co, co_val, bpr;
1976 for (co = 4, co_val = 2048; co; co--, co_val >>= 2) {
1977 if (cy_clock / co_val / baud > 63)
1981 bpr = (cy_clock / co_val * 2 / baud + 1) / 2;
1986 info->
tco = info->
rco = co;
1996 unsigned long flags;
1998 unsigned cflag, iflag;
1999 int baud, baud_rate = 0;
2002 if (info->
line == -1)
2005 cflag = tty->termios.c_cflag;
2006 iflag = tty->termios.c_iflag;
2023 if (!cy_is_Z(card)) {
2033 baud_rate = info->
baud;
2038 for (i = 0; i < 20; i++) {
2039 if (baud == baud_table[i])
2047 cyy_baud_calc(info, baud_rate);
2051 info->
tbpr = baud_bpr_60[
i];
2052 info->
tco = baud_co_60[
i];
2053 info->
rbpr = baud_bpr_60[
i];
2054 info->
rco = baud_co_60[
i];
2056 info->
tbpr = baud_bpr_25[
i];
2057 info->
tco = baud_co_25[
i];
2058 info->
rbpr = baud_bpr_25[
i];
2059 info->
rco = baud_co_25[
i];
2062 if (baud_table[i] == 134) {
2070 }
else if (baud_table[i]) {
2088 switch (cflag &
CSIZE) {
2139 cyy_writeb(info,
CyCAR, channel);
2162 cyy_writeb(info,
CyCAR, channel);
2173 if ((cflag & CRTSCTS) && info->
rflow)
2174 cyy_writeb(info,
CyMCOR1, cflags | rflow_thr[i]);
2176 cyy_writeb(info,
CyMCOR1, cflags);
2178 cyy_writeb(info,
CyMCOR2, cflags);
2181 cyy_change_rts_dtr(info, 0, TIOCM_DTR);
2183 cyy_change_rts_dtr(info, TIOCM_DTR, 0);
2186 spin_unlock_irqrestore(&card->
card_lock, flags);
2193 if (!cyz_is_loaded(card))
2203 baud_rate = info->
baud;
2226 switch (cflag & CSIZE) {
2240 if (cflag & CSTOPB) {
2247 if (cflag & PARENB) {
2256 if (cflag & CRTSCTS) {
2276 retval = cyz_issue_cmd(card, channel,
C_CM_IOCTL, 0L);
2279 "was %x\n", info->
line, retval);
2302 retval = cyz_issue_cmd(card, channel,
C_CM_IOCTLM, 0L);
2305 "was %x\n", info->
line, retval);
2319 .port = (info->
card - cy_card) * 0x100 + info->
line -
2322 .flags = info->
port.flags,
2323 .close_delay = info->
port.close_delay,
2324 .closing_wait = info->
port.closing_wait,
2325 .baud_base = info->
baud,
2344 if (new_serial.close_delay != info->
port.close_delay ||
2345 new_serial.baud_base != info->
baud ||
2355 info->
baud = new_serial.baud_base;
2357 goto check_and_exit;
2365 info->
baud = new_serial.baud_base;
2369 info->
port.close_delay = new_serial.close_delay * HZ / 100;
2370 info->
port.closing_wait = new_serial.closing_wait * HZ / 100;
2374 cy_set_line_char(info, tty);
2377 ret = cy_startup(info, tty);
2397 unsigned long flags;
2400 if (!cy_is_Z(card)) {
2403 spin_unlock_irqrestore(&card->
card_lock, flags);
2412 static int cy_tiocmget(
struct tty_struct *tty)
2418 if (serial_paranoia_check(info, tty->
name, __func__))
2423 if (!cy_is_Z(card)) {
2424 unsigned long flags;
2429 cyy_writeb(info,
CyCAR, channel & 0x03);
2430 status = cyy_readb(info,
CyMSVR1);
2431 status |= cyy_readb(info,
CyMSVR2);
2432 spin_unlock_irqrestore(&card->
card_lock, flags);
2435 result = ((status &
CyRTS) ? TIOCM_DTR : 0) |
2436 ((status &
CyDTR) ? TIOCM_RTS : 0);
2438 result = ((status &
CyRTS) ? TIOCM_RTS : 0) |
2439 ((status &
CyDTR) ? TIOCM_DTR : 0);
2448 if (!cyz_is_loaded(card)) {
2453 lstatus =
readl(&info->
u.
cyz.ch_ctrl->rs_status);
2454 result = ((lstatus &
C_RS_RTS) ? TIOCM_RTS : 0) |
2455 ((lstatus &
C_RS_DTR) ? TIOCM_DTR : 0) |
2467 unsigned int set,
unsigned int clear)
2471 unsigned long flags;
2473 if (serial_paranoia_check(info, tty->
name, __func__))
2477 if (!cy_is_Z(card)) {
2479 cyy_change_rts_dtr(info,
set, clear);
2480 spin_unlock_irqrestore(&card->
card_lock, flags);
2486 if (!cyz_is_loaded(card))
2491 if (
set & TIOCM_RTS)
2493 if (clear & TIOCM_RTS)
2495 if (
set & TIOCM_DTR) {
2501 if (clear & TIOCM_DTR) {
2509 retval = cyz_issue_cmd(card, channel,
C_CM_IOCTLM, 0L);
2510 spin_unlock_irqrestore(&card->
card_lock, flags);
2513 "was %x\n", info->
line, retval);
2522 static int cy_break(
struct tty_struct *tty,
int break_state)
2526 unsigned long flags;
2529 if (serial_paranoia_check(info, tty->
name,
"cy_break"))
2535 if (!cy_is_Z(card)) {
2539 if (break_state == -1) {
2543 spin_unlock_irqrestore(&card->
card_lock, flags);
2552 spin_unlock_irqrestore(&card->
card_lock, flags);
2559 if (break_state == -1) {
2560 retval = cyz_issue_cmd(card,
2565 "ttyC%d was %x\n", info->
line, retval);
2568 retval = cyz_issue_cmd(card,
2573 "on ttyC%d was %x\n", info->
line,
2578 spin_unlock_irqrestore(&card->
card_lock, flags);
2582 static int set_threshold(
struct cyclades_port *info,
unsigned long value)
2585 unsigned long flags;
2587 if (!cy_is_Z(card)) {
2594 spin_unlock_irqrestore(&card->
card_lock, flags);
2600 unsigned long __user *value)
2604 if (!cy_is_Z(card)) {
2611 static int set_timeout(
struct cyclades_port *info,
unsigned long value)
2614 unsigned long flags;
2616 if (!cy_is_Z(card)) {
2618 cyy_writeb(info,
CyRTPR, value & 0xff);
2619 spin_unlock_irqrestore(&card->
card_lock, flags);
2625 unsigned long __user *value)
2629 if (!cy_is_Z(card)) {
2636 static int cy_cflags_changed(
struct cyclades_port *info,
unsigned long arg,
2640 unsigned long flags;
2645 spin_unlock_irqrestore(&info->
card->card_lock, flags);
2647 ret = ((arg &
TIOCM_RNG) && (cnow.rng != cprev->
rng)) ||
2664 unsigned int cmd,
unsigned long arg)
2669 unsigned long flags;
2672 if (serial_paranoia_check(info, tty->
name,
"cy_ioctl"))
2675 #ifdef CY_DEBUG_OTHER
2677 info->
line, cmd, arg);
2689 ret_val = get_threshold(info, argp);
2692 ret_val = set_threshold(info, arg);
2696 (
unsigned long __user *)argp);
2702 ret_val = get_timeout(info, argp);
2705 ret_val = set_timeout(info, arg);
2709 (
unsigned long __user *)argp);
2718 ret_val = info->
rflow;
2729 #ifndef CONFIG_CYZ_INTR
2731 cyz_polling_cycle = (arg *
HZ) / 1000;
2734 ret_val = (cyz_polling_cycle * 1000) / HZ;
2738 info->
port.closing_wait = (
unsigned short)arg * HZ / 100;
2741 ret_val = info->
port.closing_wait / (HZ / 100);
2744 ret_val = cy_get_serial_info(info, argp);
2747 ret_val = cy_set_serial_info(info, tty, argp);
2750 ret_val = get_lsr_info(info, argp);
2762 spin_unlock_irqrestore(&info->
card->card_lock, flags);
2764 cy_cflags_changed(info, arg, &cnow));
2777 #ifdef CY_DEBUG_OTHER
2783 static int cy_get_icount(
struct tty_struct *tty,
2788 unsigned long flags;
2792 spin_unlock_irqrestore(&info->
card->card_lock, flags);
2794 sic->
cts = cnow.cts;
2795 sic->
dsr = cnow.dsr;
2796 sic->
rng = cnow.rng;
2797 sic->
dcd = cnow.dcd;
2800 sic->
frame = cnow.frame;
2802 sic->
parity = cnow.parity;
2803 sic->
brk = cnow.brk;
2818 #ifdef CY_DEBUG_OTHER
2822 cy_set_line_char(info, tty);
2824 if ((old_termios->
c_cflag & CRTSCTS) &&
2825 !(tty->termios.c_cflag & CRTSCTS)) {
2836 if (!(old_termios->
c_cflag & CLOCAL) &&
2837 (tty->termios.c_cflag & CLOCAL))
2845 static void cy_send_xchar(
struct tty_struct *tty,
char ch)
2851 if (serial_paranoia_check(info, tty->
name,
"cy_send_xchar"))
2862 if (cy_is_Z(card)) {
2874 static void cy_throttle(
struct tty_struct *tty)
2878 unsigned long flags;
2880 #ifdef CY_DEBUG_THROTTLE
2884 tty->
ldisc.chars_in_buffer(tty), info->
line);
2887 if (serial_paranoia_check(info, tty->
name,
"cy_throttle"))
2899 if (tty->termios.c_cflag & CRTSCTS) {
2900 if (!cy_is_Z(card)) {
2902 cyy_change_rts_dtr(info, 0, TIOCM_RTS);
2903 spin_unlock_irqrestore(&card->
card_lock, flags);
2915 static void cy_unthrottle(
struct tty_struct *tty)
2919 unsigned long flags;
2921 #ifdef CY_DEBUG_THROTTLE
2928 if (serial_paranoia_check(info, tty->
name,
"cy_unthrottle"))
2938 if (tty->termios.c_cflag & CRTSCTS) {
2940 if (!cy_is_Z(card)) {
2942 cyy_change_rts_dtr(info, TIOCM_RTS, 0);
2943 spin_unlock_irqrestore(&card->
card_lock, flags);
2958 unsigned long flags;
2960 #ifdef CY_DEBUG_OTHER
2964 if (serial_paranoia_check(info, tty->
name,
"cy_stop"))
2969 if (!cy_is_Z(cinfo)) {
2971 cyy_writeb(info,
CyCAR, channel & 0x03);
2972 cyy_writeb(info,
CySRER, cyy_readb(info,
CySRER) & ~CyTxRdy);
2973 spin_unlock_irqrestore(&cinfo->
card_lock, flags);
2982 unsigned long flags;
2984 #ifdef CY_DEBUG_OTHER
2988 if (serial_paranoia_check(info, tty->
name,
"cy_start"))
2993 if (!cy_is_Z(cinfo)) {
2995 cyy_writeb(info,
CyCAR, channel & 0x03);
2996 cyy_writeb(info,
CySRER, cyy_readb(info,
CySRER) | CyTxRdy);
2997 spin_unlock_irqrestore(&cinfo->
card_lock, flags);
3004 static void cy_hangup(
struct tty_struct *tty)
3008 #ifdef CY_DEBUG_OTHER
3012 if (serial_paranoia_check(info, tty->
name,
"cy_hangup"))
3015 cy_flush_buffer(tty);
3016 cy_shutdown(info, tty);
3020 static int cyy_carrier_raised(
struct tty_port *port)
3025 unsigned long flags;
3030 cyy_writeb(info,
CyCAR, channel & 0x03);
3032 spin_unlock_irqrestore(&cinfo->
card_lock, flags);
3037 static void cyy_dtr_rts(
struct tty_port *port,
int raise)
3042 unsigned long flags;
3045 cyy_change_rts_dtr(info,
raise ? TIOCM_RTS | TIOCM_DTR : 0,
3046 raise ? 0 : TIOCM_RTS | TIOCM_DTR);
3047 spin_unlock_irqrestore(&cinfo->
card_lock, flags);
3050 static int cyz_carrier_raised(
struct tty_port *port)
3058 static void cyz_dtr_rts(
struct tty_port *port,
int raise)
3073 ret = cyz_issue_cmd(cinfo, channel,
C_CM_IOCTLM, 0L);
3076 __func__, info->
line, ret);
3083 .carrier_raised = cyy_carrier_raised,
3084 .dtr_rts = cyy_dtr_rts,
3085 .shutdown = cy_do_close,
3089 .carrier_raised = cyz_carrier_raised,
3090 .dtr_rts = cyz_dtr_rts,
3091 .shutdown = cy_do_close,
3118 channel++, port++) {
3126 info->
port.close_delay = 5 * HZ / 10;
3130 if (cy_is_Z(cinfo)) {
3134 info->
port.ops = &cyz_port_ops;
3146 #ifdef CONFIG_CYZ_INTR
3148 cyz_rx_restart, (
unsigned long)info);
3151 unsigned short chip_number;
3154 info->
port.ops = &cyy_port_ops;
3163 (cy_chip_offset[chip_number] <<
index);
3168 info->
tbpr = baud_bpr_60[13];
3169 info->
tco = baud_co_60[13];
3170 info->
rbpr = baud_bpr_60[13];
3171 info->
rco = baud_co_60[13];
3174 info->
tbpr = baud_bpr_25[13];
3175 info->
tco = baud_co_25[13];
3176 info->
rbpr = baud_bpr_25[13];
3177 info->
rco = baud_co_25[13];
3181 CyBREAK | CyPARITY | CyFRAME |
CyOVERRUN;
3186 #ifndef CONFIG_CYZ_INTR
3187 if (cy_is_Z(cinfo) && !timer_pending(&cyz_timerlist)) {
3199 static unsigned short __devinit cyy_init_card(
void __iomem *true_base_addr,
3202 unsigned int chip_number;
3214 true_base_addr + (cy_chip_offset[chip_number] <<
index);
3216 if (
readb(base_addr + (
CyCCR << index)) != 0x00) {
3233 if (chip_number == 4 &&
readb(true_base_addr +
3234 (cy_chip_offset[0] << index) +
3250 if ((0xf0 & (
readb(base_addr + (
CyGFRCR << index)))) !=
3286 static int __init cy_detect_isa(
void)
3290 unsigned short cy_isa_irq, nboard;
3292 unsigned short i,
j,
k, cy_isa_nchan;
3299 if (maddr[i] || i) {
3301 cy_isa_addresses[
i] = maddr[
i];
3308 for (i = 0; i < NR_ISA_ADDRS; i++) {
3309 unsigned int isa_address = cy_isa_addresses[
i];
3310 if (isa_address == 0x0000)
3315 if (cy_isa_address ==
NULL) {
3321 cyy_init_card(cy_isa_address, 0);
3322 if (cy_isa_nchan == 0) {
3327 if (isparam && i < NR_CARDS && irq[i])
3328 cy_isa_irq = irq[
i];
3331 cy_isa_irq = detect_isa_irq(cy_isa_address);
3332 if (cy_isa_irq == 0) {
3334 "IRQ could not be detected.\n",
3335 (
unsigned long)cy_isa_address);
3340 if ((cy_next_channel + cy_isa_nchan) >
NR_PORTS) {
3342 "more channels are available. Change NR_PORTS "
3343 "in cyclades.c and recompile kernel.\n",
3344 (
unsigned long)cy_isa_address);
3354 if (j == NR_CARDS) {
3356 "more cards can be used. Change NR_CARDS in "
3357 "cyclades.c and recompile kernel.\n",
3358 (
unsigned long)cy_isa_address);
3365 0,
"Cyclom-Y", card)) {
3367 "could not allocate IRQ#%d.\n",
3368 (
unsigned long)cy_isa_address, cy_isa_irq);
3376 card->
irq = (
int)cy_isa_irq;
3380 card->
nports = cy_isa_nchan;
3381 if (cy_init_card(card)) {
3390 "%d channels starting from port %d\n",
3391 j + 1, (
unsigned long)cy_isa_address,
3392 (
unsigned long)(cy_isa_address + (
CyISA_Ywin - 1)),
3393 cy_isa_irq, cy_isa_nchan, cy_next_channel);
3395 for (k = 0, j = cy_next_channel;
3396 j < cy_next_channel + cy_isa_nchan; j++, k++)
3398 cy_serial_driver, j,
NULL);
3399 cy_next_channel += cy_isa_nchan;
3408 static inline int __devinit cyc_isfwstr(
const char *
str,
unsigned int size)
3412 for (a = 0; a < size && *
str; a++, str++)
3416 for (; a <
size; a++, str++)
3426 for (; size > 0; size--) {
3436 cy_writel(&addr->init_ctrl,
readl(&addr->init_ctrl) | 0x40000000);
3438 cy_writel(&addr->init_ctrl,
readl(&addr->init_ctrl) & ~0x40000000);
3441 cy_writel(&addr->init_ctrl,
readl(&addr->init_ctrl) | 0x20000000);
3443 cy_writel(&addr->init_ctrl,
readl(&addr->init_ctrl) & ~0x20000000);
3460 unsigned int a,
tmp, len = fw->
size;
3461 #define BAD_FW KERN_ERR "Bad firmware: "
3462 if (len <
sizeof(*h)) {
3463 printk(BAD_FW
"too short: %u<%zu\n", len,
sizeof(*h));
3470 if ((
void *)(cs + h->
n_config) > ptr + len ||
3471 (
void *)(bs + h->
n_blocks) > ptr + len) {
3472 printk(BAD_FW
"too short");
3476 if (cyc_isfwstr(h->
name,
sizeof(h->
name)) ||
3477 cyc_isfwstr(h->
date,
sizeof(h->
date))) {
3478 printk(BAD_FW
"bad formatted header string\n");
3483 printk(BAD_FW
"bad name '%s' (expected '%s')\n", h->
name, name);
3488 for (c = cs; c < cs + h->
n_config; c++) {
3491 printk(BAD_FW
"bad block ref number in cfgs\n");
3498 printk(BAD_FW
"nothing appropriate\n");
3502 for (b = bs; b < bs + h->
n_blocks; b++)
3504 printk(BAD_FW
"bad block data offset\n");
3509 for (c = cs; c < cs + h->
n_config; c++)
3513 for (a = 0; a < c->
n_blocks; a++) {
3550 u32 cntval =
readl(base_addr + 0x190);
3553 if (cntval !=
readl(base_addr + 0x190)) {
3555 dev_dbg(&pdev->
dev,
"Cyclades-Z FW already loaded. "
3556 "Skipping board.\n");
3563 cy_writel(&ctl_addr->intr_ctrl_stat,
readl(&ctl_addr->intr_ctrl_stat) &
3566 mailbox =
readl(&ctl_addr->mail_box_0);
3568 if (mailbox == 0 || __cyz_fpga_loaded(ctl_addr)) {
3576 plx_init(pdev, irq, ctl_addr);
3580 retval = __cyz_load_fw(fw,
"Cyclom-Z", mailbox,
NULL,
3584 if (!__cyz_fpga_loaded(ctl_addr)) {
3585 dev_err(&pdev->
dev,
"fw upload successful, but fw is "
3598 for (tmp = base_addr; tmp < base_addr +
RAM_SIZE; tmp++)
3603 for (tmp = base_addr; tmp < base_addr +
RAM_SIZE; tmp++)
3609 retval = __cyz_load_fw(fw,
"Cyclom-Z", mailbox, base_addr,
NULL);
3623 dev_err(&pdev->
dev,
"you need an external power supply "
3624 "for this number of ports. Firmware halted and "
3629 dev_warn(&pdev->
dev,
"fid->signature = 0x%x... Waiting "
3630 "some more time\n", status);
3635 dev_err(&pdev->
dev,
"Board not started in 20 seconds! "
3636 "Giving up. (fid->signature = 0x%x)\n",
3638 dev_info(&pdev->
dev,
"*** Warning ***: if you are "
3639 "upgrading the FW, please power cycle the "
3640 "system before loading the new FW to the "
3643 if (__cyz_fpga_loaded(ctl_addr))
3644 plx_init(pdev, irq, ctl_addr);
3649 dev_dbg(&pdev->
dev,
"Firmware started after %d seconds.\n",
3654 dev_dbg(&pdev->
dev,
"fid=> %p, zfwctrl_addr=> %x, npt_zfwctrl=> %p\n",
3659 dev_info(&pdev->
dev,
"Cyclades-Z FW loaded: version = %x, ports = %u\n",
3663 dev_warn(&pdev->
dev,
"no Cyclades-Z ports were found. Please "
3664 "check the connection between the Z host card and the "
3665 "serial expanders.\n");
3667 if (__cyz_fpga_loaded(ctl_addr))
3668 plx_init(pdev, irq, ctl_addr);
3670 dev_info(&pdev->
dev,
"Null number of ports detected. Board "
3683 cy_writel(&ctl_addr->intr_ctrl_stat,
readl(&ctl_addr->intr_ctrl_stat) |
3685 cy_writel(&ctl_addr->intr_ctrl_stat,
readl(&ctl_addr->intr_ctrl_stat) |
3700 char *card_name =
NULL;
3703 unsigned char plx_ver;
3708 dev_err(&pdev->
dev,
"cannot enable device\n");
3716 #if defined(__alpha__)
3718 dev_err(&pdev->
dev,
"Cyclom-Y/PCI not supported for low "
3719 "addresses on Alpha systems.\n");
3725 dev_err(&pdev->
dev,
"Cyclades-Z/PCI not supported for low "
3732 dev_warn(&pdev->
dev,
"PCI I/O bit incorrectly set. Ignoring "
3739 dev_err(&pdev->
dev,
"failed to reserve resources\n");
3746 card_name =
"Cyclom-Y";
3750 if (addr0 ==
NULL) {
3751 dev_err(&pdev->
dev,
"can't remap ctl region\n");
3756 if (addr2 ==
NULL) {
3757 dev_err(&pdev->
dev,
"can't remap base region\n");
3763 dev_err(&pdev->
dev,
"Cyclom-Y PCI host card with no "
3764 "Serial-Modules\n");
3772 if (addr0 ==
NULL) {
3773 dev_err(&pdev->
dev,
"can't remap ctl region\n");
3781 plx_init(pdev, irq, addr0);
3787 if (addr2 ==
NULL) {
3788 dev_err(&pdev->
dev,
"can't remap base region\n");
3792 if (mailbox ==
ZE_V1) {
3793 card_name =
"Cyclades-Ze";
3795 card_name =
"Cyclades-8Zo";
3797 if (mailbox ==
ZO_V1) {
3800 "id %lx, ver %lx\n", (
ulong)(0xff &
3802 fpga_id)), (
ulong)(0xff &
3808 "Cyclades-Z board. FPGA not loaded\n");
3815 if ((mailbox ==
ZO_V1) || (mailbox ==
ZO_V2))
3819 retval = cyz_load_fw(pdev, addr2, addr0, irq);
3825 if ((cy_next_channel + nchan) >
NR_PORTS) {
3826 dev_err(&pdev->
dev,
"Cyclades-8Zo/PCI found, but no "
3827 "channels are available. Change NR_PORTS in "
3828 "cyclades.c and recompile kernel.\n");
3832 for (card_no = 0; card_no <
NR_CARDS; card_no++) {
3833 card = &cy_card[card_no];
3837 if (card_no == NR_CARDS) {
3838 dev_err(&pdev->
dev,
"Cyclades-8Zo/PCI found, but no "
3839 "more cards can be used. Change NR_CARDS in "
3840 "cyclades.c and recompile kernel.\n");
3850 dev_err(&pdev->
dev,
"could not allocate IRQ\n");
3863 #ifdef CONFIG_CYZ_INTR
3865 if (irq != 0 && irq != 255) {
3869 dev_err(&pdev->
dev,
"could not allocate IRQ\n");
3883 retval = cy_init_card(card);
3887 pci_set_drvdata(pdev, card);
3903 plx_init(pdev, irq, ctl_addr);
3911 dev_info(&pdev->
dev,
"%s/PCI #%d found: %d channels starting from "
3912 "port %d.\n", card_name, card_no + 1, nchan, cy_next_channel);
3913 for (j = 0, i = cy_next_channel; i < cy_next_channel + nchan; i++, j++)
3915 cy_serial_driver, i, &pdev->
dev);
3916 cy_next_channel += nchan;
3944 #ifndef CONFIG_CYZ_INTR
3945 if (!cy_is_Z(cinfo))
3955 #ifndef CONFIG_CYZ_INTR
3963 for (i = cinfo->
first_line; i < cinfo->first_line +
3972 .id_table = cy_pci_dev_id,
3973 .probe = cy_pci_probe,
3978 static int cyclades_proc_show(
struct seq_file *
m,
void *
v)
3984 seq_puts(m,
"Dev TimeOpen BytesOut IdleOut BytesIn "
3985 "IdleIn Overruns Ldisc\n");
3989 for (j = 0; j < cy_card[
i].nports; j++) {
3990 info = &cy_card[
i].ports[
j];
3992 if (info->
port.count) {
4007 "%10lu %8lu %9lu %6d\n", info->
line,
4017 "%10lu %8lu %9lu %6ld\n",
4018 info->
line, 0L, 0L, 0L, 0L, 0L, 0L, 0L);
4030 .open = cyclades_proc_open,
4058 .put_char = cy_put_char,
4059 .flush_chars = cy_flush_chars,
4060 .write_room = cy_write_room,
4061 .chars_in_buffer = cy_chars_in_buffer,
4062 .flush_buffer = cy_flush_buffer,
4064 .throttle = cy_throttle,
4065 .unthrottle = cy_unthrottle,
4066 .set_termios = cy_set_termios,
4069 .hangup = cy_hangup,
4070 .break_ctl = cy_break,
4071 .wait_until_sent = cy_wait_until_sent,
4072 .tiocmget = cy_tiocmget,
4073 .tiocmset = cy_tiocmset,
4074 .get_icount = cy_get_icount,
4075 .proc_fops = &cyclades_proc_fops,
4078 static int __init cy_init(
void)
4080 unsigned int nboards;
4083 cy_serial_driver = alloc_tty_driver(
NR_PORTS);
4084 if (!cy_serial_driver)
4092 cy_serial_driver->
name =
"ttyC";
4117 nboards = cy_detect_isa();
4121 retval = pci_register_driver(&cy_pci_driver);
4122 if (retval && !nboards) {
4135 static void __exit cy_cleanup_module(
void)
4140 #ifndef CONFIG_CYZ_INTR
4147 "driver(%d)\n", e1);
4162 #ifndef CONFIG_CYZ_INTR
4167 for (e1 = card->
first_line; e1 < card->first_line +