2 * Copyright 2003 Digi International (www.digi.com)
3 * Scott H Kilau <Scott_Kilau at digi dot com>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2, or (at your option)
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY, EXPRESS OR IMPLIED; without even the
12 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
13 * PURPOSE. See the GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 * NOTE TO LINUX KERNEL HACKERS: DO NOT REFORMAT THIS CODE!
22 * This is shared code between Digi's CVS archive and the
23 * Linux Kernel sources.
24 * Changing the source just for reformatting needlessly breaks
25 * our CVS diff history.
27 * Send any bug fixes/changes to: Eng.Linux at digi dot com.
33 #include <linux/kernel.h>
34 #include <linux/sched.h> /* For jiffies, task states */
35 #include <linux/interrupt.h> /* For tasklet and interrupt structs/defines */
36 #include <linux/delay.h> /* For udelay */
37 #include <linux/io.h> /* For read[bwl]/write[bwl] */
38 #include <linux/serial.h> /* For struct async_serial */
39 #include <linux/serial_reg.h> /* For the various UART offsets */
41 #include "dgnc_driver.h" /* Driver main header file */
42 #include "dgnc_neo.h" /* Our header file */
45 static inline void neo_parse_lsr(struct dgnc_board *brd, uint port);
46 static inline void neo_parse_isr(struct dgnc_board *brd, uint port);
47 static void neo_copy_data_from_uart_to_queue(struct channel_t *ch);
48 static inline void neo_clear_break(struct channel_t *ch, int force);
49 static inline void neo_set_cts_flow_control(struct channel_t *ch);
50 static inline void neo_set_rts_flow_control(struct channel_t *ch);
51 static inline void neo_set_ixon_flow_control(struct channel_t *ch);
52 static inline void neo_set_ixoff_flow_control(struct channel_t *ch);
53 static inline void neo_set_no_output_flow_control(struct channel_t *ch);
54 static inline void neo_set_no_input_flow_control(struct channel_t *ch);
55 static inline void neo_set_new_start_stop_chars(struct channel_t *ch);
56 static void neo_parse_modem(struct channel_t *ch, unsigned char signals);
57 static void neo_tasklet(unsigned long data);
58 static void neo_vpd(struct dgnc_board *brd);
59 static void neo_uart_init(struct channel_t *ch);
60 static void neo_uart_off(struct channel_t *ch);
61 static int neo_drain(struct tty_struct *tty, uint seconds);
62 static void neo_param(struct tty_struct *tty);
63 static void neo_assert_modem_signals(struct channel_t *ch);
64 static void neo_flush_uart_write(struct channel_t *ch);
65 static void neo_flush_uart_read(struct channel_t *ch);
66 static void neo_disable_receiver(struct channel_t *ch);
67 static void neo_enable_receiver(struct channel_t *ch);
68 static void neo_send_break(struct channel_t *ch, int msecs);
69 static void neo_send_start_character(struct channel_t *ch);
70 static void neo_send_stop_character(struct channel_t *ch);
71 static void neo_copy_data_from_queue_to_uart(struct channel_t *ch);
72 static uint neo_get_uart_bytes_left(struct channel_t *ch);
73 static void neo_send_immediate_char(struct channel_t *ch, unsigned char c);
74 static irqreturn_t neo_intr(int irq, void *voidbrd);
77 struct board_ops dgnc_neo_ops = {
78 .tasklet = neo_tasklet,
80 .uart_init = neo_uart_init,
81 .uart_off = neo_uart_off,
85 .assert_modem_signals = neo_assert_modem_signals,
86 .flush_uart_write = neo_flush_uart_write,
87 .flush_uart_read = neo_flush_uart_read,
88 .disable_receiver = neo_disable_receiver,
89 .enable_receiver = neo_enable_receiver,
90 .send_break = neo_send_break,
91 .send_start_character = neo_send_start_character,
92 .send_stop_character = neo_send_stop_character,
93 .copy_data_from_queue_to_uart = neo_copy_data_from_queue_to_uart,
94 .get_uart_bytes_left = neo_get_uart_bytes_left,
95 .send_immediate_char = neo_send_immediate_char
98 static uint dgnc_offset_table[8] = { 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80 };
102 * This function allows calls to ensure that all outstanding
103 * PCI writes have been completed, by doing a PCI read against
104 * a non-destructive, read-only location on the Neo card.
106 * In this case, we are reading the DVID (Read-only Device Identification)
107 * value of the Neo card.
109 static inline void neo_pci_posting_flush(struct dgnc_board *bd)
111 readb(bd->re_map_membase + 0x8D);
114 static inline void neo_set_cts_flow_control(struct channel_t *ch)
116 unsigned char ier = readb(&ch->ch_neo_uart->ier);
117 unsigned char efr = readb(&ch->ch_neo_uart->efr);
120 /* Turn on auto CTS flow control */
122 ier |= (UART_17158_IER_CTSDSR);
124 ier &= ~(UART_17158_IER_CTSDSR);
127 efr |= (UART_17158_EFR_ECB | UART_17158_EFR_CTSDSR);
129 /* Turn off auto Xon flow control */
130 efr &= ~(UART_17158_EFR_IXON);
132 /* Why? Becuz Exar's spec says we have to zero it out before setting it */
133 writeb(0, &ch->ch_neo_uart->efr);
135 /* Turn on UART enhanced bits */
136 writeb(efr, &ch->ch_neo_uart->efr);
138 /* Turn on table D, with 8 char hi/low watermarks */
139 writeb((UART_17158_FCTR_TRGD | UART_17158_FCTR_RTS_4DELAY), &ch->ch_neo_uart->fctr);
141 /* Feed the UART our trigger levels */
142 writeb(8, &ch->ch_neo_uart->tfifo);
145 writeb(ier, &ch->ch_neo_uart->ier);
147 neo_pci_posting_flush(ch->ch_bd);
151 static inline void neo_set_rts_flow_control(struct channel_t *ch)
153 unsigned char ier = readb(&ch->ch_neo_uart->ier);
154 unsigned char efr = readb(&ch->ch_neo_uart->efr);
156 /* Turn on auto RTS flow control */
158 ier |= (UART_17158_IER_RTSDTR);
160 ier &= ~(UART_17158_IER_RTSDTR);
162 efr |= (UART_17158_EFR_ECB | UART_17158_EFR_RTSDTR);
164 /* Turn off auto Xoff flow control */
165 ier &= ~(UART_17158_IER_XOFF);
166 efr &= ~(UART_17158_EFR_IXOFF);
168 /* Why? Becuz Exar's spec says we have to zero it out before setting it */
169 writeb(0, &ch->ch_neo_uart->efr);
171 /* Turn on UART enhanced bits */
172 writeb(efr, &ch->ch_neo_uart->efr);
174 writeb((UART_17158_FCTR_TRGD | UART_17158_FCTR_RTS_4DELAY), &ch->ch_neo_uart->fctr);
175 ch->ch_r_watermark = 4;
177 writeb(32, &ch->ch_neo_uart->rfifo);
178 ch->ch_r_tlevel = 32;
180 writeb(ier, &ch->ch_neo_uart->ier);
183 * From the Neo UART spec sheet:
184 * The auto RTS/DTR function must be started by asserting
185 * RTS/DTR# output pin (MCR bit-0 or 1 to logic 1 after
188 ch->ch_mostat |= (UART_MCR_RTS);
190 neo_pci_posting_flush(ch->ch_bd);
194 static inline void neo_set_ixon_flow_control(struct channel_t *ch)
196 unsigned char ier = readb(&ch->ch_neo_uart->ier);
197 unsigned char efr = readb(&ch->ch_neo_uart->efr);
199 /* Turn off auto CTS flow control */
200 ier &= ~(UART_17158_IER_CTSDSR);
201 efr &= ~(UART_17158_EFR_CTSDSR);
203 /* Turn on auto Xon flow control */
204 efr |= (UART_17158_EFR_ECB | UART_17158_EFR_IXON);
206 /* Why? Becuz Exar's spec says we have to zero it out before setting it */
207 writeb(0, &ch->ch_neo_uart->efr);
209 /* Turn on UART enhanced bits */
210 writeb(efr, &ch->ch_neo_uart->efr);
212 writeb((UART_17158_FCTR_TRGD | UART_17158_FCTR_RTS_8DELAY), &ch->ch_neo_uart->fctr);
213 ch->ch_r_watermark = 4;
215 writeb(32, &ch->ch_neo_uart->rfifo);
216 ch->ch_r_tlevel = 32;
218 /* Tell UART what start/stop chars it should be looking for */
219 writeb(ch->ch_startc, &ch->ch_neo_uart->xonchar1);
220 writeb(0, &ch->ch_neo_uart->xonchar2);
222 writeb(ch->ch_stopc, &ch->ch_neo_uart->xoffchar1);
223 writeb(0, &ch->ch_neo_uart->xoffchar2);
225 writeb(ier, &ch->ch_neo_uart->ier);
227 neo_pci_posting_flush(ch->ch_bd);
231 static inline void neo_set_ixoff_flow_control(struct channel_t *ch)
233 unsigned char ier = readb(&ch->ch_neo_uart->ier);
234 unsigned char efr = readb(&ch->ch_neo_uart->efr);
236 /* Turn off auto RTS flow control */
237 ier &= ~(UART_17158_IER_RTSDTR);
238 efr &= ~(UART_17158_EFR_RTSDTR);
240 /* Turn on auto Xoff flow control */
241 ier |= (UART_17158_IER_XOFF);
242 efr |= (UART_17158_EFR_ECB | UART_17158_EFR_IXOFF);
244 /* Why? Becuz Exar's spec says we have to zero it out before setting it */
245 writeb(0, &ch->ch_neo_uart->efr);
247 /* Turn on UART enhanced bits */
248 writeb(efr, &ch->ch_neo_uart->efr);
250 /* Turn on table D, with 8 char hi/low watermarks */
251 writeb((UART_17158_FCTR_TRGD | UART_17158_FCTR_RTS_8DELAY), &ch->ch_neo_uart->fctr);
253 writeb(8, &ch->ch_neo_uart->tfifo);
256 /* Tell UART what start/stop chars it should be looking for */
257 writeb(ch->ch_startc, &ch->ch_neo_uart->xonchar1);
258 writeb(0, &ch->ch_neo_uart->xonchar2);
260 writeb(ch->ch_stopc, &ch->ch_neo_uart->xoffchar1);
261 writeb(0, &ch->ch_neo_uart->xoffchar2);
263 writeb(ier, &ch->ch_neo_uart->ier);
265 neo_pci_posting_flush(ch->ch_bd);
269 static inline void neo_set_no_input_flow_control(struct channel_t *ch)
271 unsigned char ier = readb(&ch->ch_neo_uart->ier);
272 unsigned char efr = readb(&ch->ch_neo_uart->efr);
274 /* Turn off auto RTS flow control */
275 ier &= ~(UART_17158_IER_RTSDTR);
276 efr &= ~(UART_17158_EFR_RTSDTR);
278 /* Turn off auto Xoff flow control */
279 ier &= ~(UART_17158_IER_XOFF);
280 if (ch->ch_c_iflag & IXON)
281 efr &= ~(UART_17158_EFR_IXOFF);
283 efr &= ~(UART_17158_EFR_ECB | UART_17158_EFR_IXOFF);
286 /* Why? Becuz Exar's spec says we have to zero it out before setting it */
287 writeb(0, &ch->ch_neo_uart->efr);
289 /* Turn on UART enhanced bits */
290 writeb(efr, &ch->ch_neo_uart->efr);
292 /* Turn on table D, with 8 char hi/low watermarks */
293 writeb((UART_17158_FCTR_TRGD | UART_17158_FCTR_RTS_8DELAY), &ch->ch_neo_uart->fctr);
295 ch->ch_r_watermark = 0;
297 writeb(16, &ch->ch_neo_uart->tfifo);
298 ch->ch_t_tlevel = 16;
300 writeb(16, &ch->ch_neo_uart->rfifo);
301 ch->ch_r_tlevel = 16;
303 writeb(ier, &ch->ch_neo_uart->ier);
305 neo_pci_posting_flush(ch->ch_bd);
309 static inline void neo_set_no_output_flow_control(struct channel_t *ch)
311 unsigned char ier = readb(&ch->ch_neo_uart->ier);
312 unsigned char efr = readb(&ch->ch_neo_uart->efr);
314 /* Turn off auto CTS flow control */
315 ier &= ~(UART_17158_IER_CTSDSR);
316 efr &= ~(UART_17158_EFR_CTSDSR);
318 /* Turn off auto Xon flow control */
319 if (ch->ch_c_iflag & IXOFF)
320 efr &= ~(UART_17158_EFR_IXON);
322 efr &= ~(UART_17158_EFR_ECB | UART_17158_EFR_IXON);
324 /* Why? Becuz Exar's spec says we have to zero it out before setting it */
325 writeb(0, &ch->ch_neo_uart->efr);
327 /* Turn on UART enhanced bits */
328 writeb(efr, &ch->ch_neo_uart->efr);
330 /* Turn on table D, with 8 char hi/low watermarks */
331 writeb((UART_17158_FCTR_TRGD | UART_17158_FCTR_RTS_8DELAY), &ch->ch_neo_uart->fctr);
333 ch->ch_r_watermark = 0;
335 writeb(16, &ch->ch_neo_uart->tfifo);
336 ch->ch_t_tlevel = 16;
338 writeb(16, &ch->ch_neo_uart->rfifo);
339 ch->ch_r_tlevel = 16;
341 writeb(ier, &ch->ch_neo_uart->ier);
343 neo_pci_posting_flush(ch->ch_bd);
347 /* change UARTs start/stop chars */
348 static inline void neo_set_new_start_stop_chars(struct channel_t *ch)
351 /* if hardware flow control is set, then skip this whole thing */
352 if (ch->ch_digi.digi_flags & (CTSPACE | RTSPACE) || ch->ch_c_cflag & CRTSCTS)
355 /* Tell UART what start/stop chars it should be looking for */
356 writeb(ch->ch_startc, &ch->ch_neo_uart->xonchar1);
357 writeb(0, &ch->ch_neo_uart->xonchar2);
359 writeb(ch->ch_stopc, &ch->ch_neo_uart->xoffchar1);
360 writeb(0, &ch->ch_neo_uart->xoffchar2);
362 neo_pci_posting_flush(ch->ch_bd);
367 * No locks are assumed to be held when calling this function.
369 static inline void neo_clear_break(struct channel_t *ch, int force)
373 spin_lock_irqsave(&ch->ch_lock, flags);
375 /* Bail if we aren't currently sending a break. */
376 if (!ch->ch_stop_sending_break) {
377 spin_unlock_irqrestore(&ch->ch_lock, flags);
381 /* Turn break off, and unset some variables */
382 if (ch->ch_flags & CH_BREAK_SENDING) {
383 if (time_after_eq(jiffies, ch->ch_stop_sending_break)
385 unsigned char temp = readb(&ch->ch_neo_uart->lcr);
387 writeb((temp & ~UART_LCR_SBC), &ch->ch_neo_uart->lcr);
388 neo_pci_posting_flush(ch->ch_bd);
389 ch->ch_flags &= ~(CH_BREAK_SENDING);
390 ch->ch_stop_sending_break = 0;
393 spin_unlock_irqrestore(&ch->ch_lock, flags);
398 * Parse the ISR register.
400 static inline void neo_parse_isr(struct dgnc_board *brd, uint port)
402 struct channel_t *ch;
407 if (!brd || brd->magic != DGNC_BOARD_MAGIC)
410 if (port > brd->maxports)
413 ch = brd->channels[port];
414 if (!ch || ch->magic != DGNC_CHANNEL_MAGIC)
417 /* Here we try to figure out what caused the interrupt to happen */
420 isr = readb(&ch->ch_neo_uart->isr_fcr);
422 /* Bail if no pending interrupt */
423 if (isr & UART_IIR_NO_INT)
427 * Yank off the upper 2 bits, which just show that the FIFO's are enabled.
429 isr &= ~(UART_17158_IIR_FIFO_ENABLED);
431 if (isr & (UART_17158_IIR_RDI_TIMEOUT | UART_IIR_RDI)) {
432 /* Read data from uart -> queue */
435 neo_copy_data_from_uart_to_queue(ch);
437 /* Call our tty layer to enforce queue flow control if needed. */
438 spin_lock_irqsave(&ch->ch_lock, flags);
439 dgnc_check_queue_flow_control(ch);
440 spin_unlock_irqrestore(&ch->ch_lock, flags);
443 if (isr & UART_IIR_THRI) {
446 /* Transfer data (if any) from Write Queue -> UART. */
447 spin_lock_irqsave(&ch->ch_lock, flags);
448 ch->ch_flags |= (CH_TX_FIFO_EMPTY | CH_TX_FIFO_LWM);
449 spin_unlock_irqrestore(&ch->ch_lock, flags);
450 neo_copy_data_from_queue_to_uart(ch);
453 if (isr & UART_17158_IIR_XONXOFF) {
454 cause = readb(&ch->ch_neo_uart->xoffchar1);
457 * Since the UART detected either an XON or
458 * XOFF match, we need to figure out which
459 * one it was, so we can suspend or resume data flow.
461 if (cause == UART_17158_XON_DETECT) {
462 /* Is output stopped right now, if so, resume it */
463 if (brd->channels[port]->ch_flags & CH_STOP) {
464 spin_lock_irqsave(&ch->ch_lock,
466 ch->ch_flags &= ~(CH_STOP);
467 spin_unlock_irqrestore(&ch->ch_lock,
470 } else if (cause == UART_17158_XOFF_DETECT) {
471 if (!(brd->channels[port]->ch_flags & CH_STOP)) {
472 spin_lock_irqsave(&ch->ch_lock,
474 ch->ch_flags |= CH_STOP;
475 spin_unlock_irqrestore(&ch->ch_lock,
481 if (isr & UART_17158_IIR_HWFLOW_STATE_CHANGE) {
483 * If we get here, this means the hardware is doing auto flow control.
484 * Check to see whether RTS/DTR or CTS/DSR caused this interrupt.
488 cause = readb(&ch->ch_neo_uart->mcr);
489 /* Which pin is doing auto flow? RTS or DTR? */
490 if ((cause & 0x4) == 0) {
491 if (cause & UART_MCR_RTS) {
492 spin_lock_irqsave(&ch->ch_lock,
494 ch->ch_mostat |= UART_MCR_RTS;
495 spin_unlock_irqrestore(&ch->ch_lock,
498 spin_lock_irqsave(&ch->ch_lock,
500 ch->ch_mostat &= ~(UART_MCR_RTS);
501 spin_unlock_irqrestore(&ch->ch_lock,
505 if (cause & UART_MCR_DTR) {
506 spin_lock_irqsave(&ch->ch_lock,
508 ch->ch_mostat |= UART_MCR_DTR;
509 spin_unlock_irqrestore(&ch->ch_lock,
512 spin_lock_irqsave(&ch->ch_lock,
514 ch->ch_mostat &= ~(UART_MCR_DTR);
515 spin_unlock_irqrestore(&ch->ch_lock,
521 /* Parse any modem signal changes */
522 neo_parse_modem(ch, readb(&ch->ch_neo_uart->msr));
527 static inline void neo_parse_lsr(struct dgnc_board *brd, uint port)
529 struct channel_t *ch;
536 if (brd->magic != DGNC_BOARD_MAGIC)
539 if (port > brd->maxports)
542 ch = brd->channels[port];
543 if (!ch || ch->magic != DGNC_CHANNEL_MAGIC)
546 linestatus = readb(&ch->ch_neo_uart->lsr);
548 ch->ch_cached_lsr |= linestatus;
550 if (ch->ch_cached_lsr & UART_LSR_DR) {
553 /* Read data from uart -> queue */
554 neo_copy_data_from_uart_to_queue(ch);
555 spin_lock_irqsave(&ch->ch_lock, flags);
556 dgnc_check_queue_flow_control(ch);
557 spin_unlock_irqrestore(&ch->ch_lock, flags);
561 * The next 3 tests should *NOT* happen, as the above test
562 * should encapsulate all 3... At least, thats what Exar says.
565 if (linestatus & UART_LSR_PE)
568 if (linestatus & UART_LSR_FE)
571 if (linestatus & UART_LSR_BI)
574 if (linestatus & UART_LSR_OE) {
576 * Rx Oruns. Exar says that an orun will NOT corrupt
577 * the FIFO. It will just replace the holding register
578 * with this new data byte. So basically just ignore this.
579 * Probably we should eventually have an orun stat in our driver...
581 ch->ch_err_overrun++;
584 if (linestatus & UART_LSR_THRE) {
587 spin_lock_irqsave(&ch->ch_lock, flags);
588 ch->ch_flags |= (CH_TX_FIFO_EMPTY | CH_TX_FIFO_LWM);
589 spin_unlock_irqrestore(&ch->ch_lock, flags);
591 /* Transfer data (if any) from Write Queue -> UART. */
592 neo_copy_data_from_queue_to_uart(ch);
593 } else if (linestatus & UART_17158_TX_AND_FIFO_CLR) {
596 spin_lock_irqsave(&ch->ch_lock, flags);
597 ch->ch_flags |= (CH_TX_FIFO_EMPTY | CH_TX_FIFO_LWM);
598 spin_unlock_irqrestore(&ch->ch_lock, flags);
600 /* Transfer data (if any) from Write Queue -> UART. */
601 neo_copy_data_from_queue_to_uart(ch);
608 * Send any/all changes to the line to the UART.
610 static void neo_param(struct tty_struct *tty)
612 unsigned char lcr = 0;
613 unsigned char uart_lcr = 0;
614 unsigned char ier = 0;
615 unsigned char uart_ier = 0;
618 struct dgnc_board *bd;
619 struct channel_t *ch;
622 if (!tty || tty->magic != TTY_MAGIC)
625 un = (struct un_t *) tty->driver_data;
626 if (!un || un->magic != DGNC_UNIT_MAGIC)
630 if (!ch || ch->magic != DGNC_CHANNEL_MAGIC)
634 if (!bd || bd->magic != DGNC_BOARD_MAGIC)
638 * If baud rate is zero, flush queues, and set mval to drop DTR.
640 if ((ch->ch_c_cflag & (CBAUD)) == 0) {
648 neo_flush_uart_write(ch);
649 neo_flush_uart_read(ch);
651 /* The baudrate is B0 so all modem lines are to be dropped. */
652 ch->ch_flags |= (CH_BAUD0);
653 ch->ch_mostat &= ~(UART_MCR_RTS | UART_MCR_DTR);
654 neo_assert_modem_signals(ch);
658 } else if (ch->ch_custom_speed) {
660 baud = ch->ch_custom_speed;
661 /* Handle transition from B0 */
662 if (ch->ch_flags & CH_BAUD0) {
663 ch->ch_flags &= ~(CH_BAUD0);
666 * Bring back up RTS and DTR...
667 * Also handle RTS or DTR toggle if set.
669 if (!(ch->ch_digi.digi_flags & DIGI_RTS_TOGGLE))
670 ch->ch_mostat |= (UART_MCR_RTS);
671 if (!(ch->ch_digi.digi_flags & DIGI_DTR_TOGGLE))
672 ch->ch_mostat |= (UART_MCR_DTR);
678 ulong bauds[4][16] = {
682 600, 1200, 1800, 2400,
683 4800, 9600, 19200, 38400 },
684 { /* slowbaud & CBAUDEX */
685 0, 57600, 115200, 230400,
686 460800, 150, 200, 921600,
687 600, 1200, 1800, 2400,
688 4800, 9600, 19200, 38400 },
690 0, 57600, 76800, 115200,
691 131657, 153600, 230400, 460800,
692 921600, 1200, 1800, 2400,
693 4800, 9600, 19200, 38400 },
694 { /* fastbaud & CBAUDEX */
695 0, 57600, 115200, 230400,
696 460800, 150, 200, 921600,
697 600, 1200, 1800, 2400,
698 4800, 9600, 19200, 38400 }
701 /* Only use the TXPrint baud rate if the terminal unit is NOT open */
702 if (!(ch->ch_tun.un_flags & UN_ISOPEN) && (un->un_type == DGNC_PRINT))
703 baud = C_BAUD(ch->ch_pun.un_tty) & 0xff;
705 baud = C_BAUD(ch->ch_tun.un_tty) & 0xff;
707 if (ch->ch_c_cflag & CBAUDEX)
710 if (ch->ch_digi.digi_flags & DIGI_FAST)
715 if ((iindex >= 0) && (iindex < 4) && (jindex >= 0) && (jindex < 16))
716 baud = bauds[iindex][jindex];
723 /* Handle transition from B0 */
724 if (ch->ch_flags & CH_BAUD0) {
725 ch->ch_flags &= ~(CH_BAUD0);
728 * Bring back up RTS and DTR...
729 * Also handle RTS or DTR toggle if set.
731 if (!(ch->ch_digi.digi_flags & DIGI_RTS_TOGGLE))
732 ch->ch_mostat |= (UART_MCR_RTS);
733 if (!(ch->ch_digi.digi_flags & DIGI_DTR_TOGGLE))
734 ch->ch_mostat |= (UART_MCR_DTR);
738 if (ch->ch_c_cflag & PARENB)
739 lcr |= UART_LCR_PARITY;
741 if (!(ch->ch_c_cflag & PARODD))
742 lcr |= UART_LCR_EPAR;
745 * Not all platforms support mark/space parity,
746 * so this will hide behind an ifdef.
749 if (ch->ch_c_cflag & CMSPAR)
750 lcr |= UART_LCR_SPAR;
753 if (ch->ch_c_cflag & CSTOPB)
754 lcr |= UART_LCR_STOP;
756 switch (ch->ch_c_cflag & CSIZE) {
758 lcr |= UART_LCR_WLEN5;
761 lcr |= UART_LCR_WLEN6;
764 lcr |= UART_LCR_WLEN7;
768 lcr |= UART_LCR_WLEN8;
772 uart_ier = readb(&ch->ch_neo_uart->ier);
775 uart_lcr = readb(&ch->ch_neo_uart->lcr);
780 quot = ch->ch_bd->bd_dividend / baud;
782 if (quot != 0 && ch->ch_old_baud != baud) {
783 ch->ch_old_baud = baud;
784 writeb(UART_LCR_DLAB, &ch->ch_neo_uart->lcr);
785 writeb((quot & 0xff), &ch->ch_neo_uart->txrx);
786 writeb((quot >> 8), &ch->ch_neo_uart->ier);
787 writeb(lcr, &ch->ch_neo_uart->lcr);
791 writeb(lcr, &ch->ch_neo_uart->lcr);
793 if (ch->ch_c_cflag & CREAD)
794 ier |= (UART_IER_RDI | UART_IER_RLSI);
796 ier &= ~(UART_IER_RDI | UART_IER_RLSI);
799 * Have the UART interrupt on modem signal changes ONLY when
800 * we are in hardware flow control mode, or CLOCAL/FORCEDCD is not set.
802 if ((ch->ch_digi.digi_flags & CTSPACE) ||
803 (ch->ch_digi.digi_flags & RTSPACE) ||
804 (ch->ch_c_cflag & CRTSCTS) ||
805 !(ch->ch_digi.digi_flags & DIGI_FORCEDCD) ||
806 !(ch->ch_c_cflag & CLOCAL))
809 ier &= ~UART_IER_MSI;
811 ier |= UART_IER_THRI;
814 writeb(ier, &ch->ch_neo_uart->ier);
816 /* Set new start/stop chars */
817 neo_set_new_start_stop_chars(ch);
819 if (ch->ch_digi.digi_flags & CTSPACE || ch->ch_c_cflag & CRTSCTS) {
820 neo_set_cts_flow_control(ch);
821 } else if (ch->ch_c_iflag & IXON) {
822 /* If start/stop is set to disable, then we should disable flow control */
823 if ((ch->ch_startc == _POSIX_VDISABLE) || (ch->ch_stopc == _POSIX_VDISABLE))
824 neo_set_no_output_flow_control(ch);
826 neo_set_ixon_flow_control(ch);
828 neo_set_no_output_flow_control(ch);
831 if (ch->ch_digi.digi_flags & RTSPACE || ch->ch_c_cflag & CRTSCTS) {
832 neo_set_rts_flow_control(ch);
833 } else if (ch->ch_c_iflag & IXOFF) {
834 /* If start/stop is set to disable, then we should disable flow control */
835 if ((ch->ch_startc == _POSIX_VDISABLE) || (ch->ch_stopc == _POSIX_VDISABLE))
836 neo_set_no_input_flow_control(ch);
838 neo_set_ixoff_flow_control(ch);
840 neo_set_no_input_flow_control(ch);
844 * Adjust the RX FIFO Trigger level if baud is less than 9600.
845 * Not exactly elegant, but this is needed because of the Exar chip's
846 * delay on firing off the RX FIFO interrupt on slower baud rates.
849 writeb(1, &ch->ch_neo_uart->rfifo);
853 neo_assert_modem_signals(ch);
855 /* Get current status of the modem signals now */
856 neo_parse_modem(ch, readb(&ch->ch_neo_uart->msr));
861 * Our board poller function.
863 static void neo_tasklet(unsigned long data)
865 struct dgnc_board *bd = (struct dgnc_board *) data;
866 struct channel_t *ch;
872 if (!bd || bd->magic != DGNC_BOARD_MAGIC) {
873 APR(("poll_tasklet() - NULL or bad bd.\n"));
877 /* Cache a couple board values */
878 spin_lock_irqsave(&bd->bd_lock, flags);
881 spin_unlock_irqrestore(&bd->bd_lock, flags);
884 * Do NOT allow the interrupt routine to read the intr registers
885 * Until we release this lock.
887 spin_lock_irqsave(&bd->bd_intr_lock, flags);
890 * If board is ready, parse deeper to see if there is anything to do.
892 if ((state == BOARD_READY) && (ports > 0)) {
893 /* Loop on each port */
894 for (i = 0; i < ports; i++) {
895 ch = bd->channels[i];
897 /* Just being careful... */
898 if (!ch || ch->magic != DGNC_CHANNEL_MAGIC)
902 * NOTE: Remember you CANNOT hold any channel
903 * locks when calling the input routine.
905 * During input processing, its possible we
906 * will call the Linux ld, which might in turn,
907 * do a callback right back into us, resulting
908 * in us trying to grab the channel lock twice!
913 * Channel lock is grabbed and then released
914 * inside both of these routines, but neither
915 * call anything else that could call back into us.
917 neo_copy_data_from_queue_to_uart(ch);
918 dgnc_wakeup_writes(ch);
921 * Call carrier carrier function, in case something
927 * Check to see if we need to turn off a sending break.
928 * The timing check is done inside clear_break()
930 if (ch->ch_stop_sending_break)
931 neo_clear_break(ch, 0);
935 /* Allow interrupt routine to access the interrupt register again */
936 spin_unlock_irqrestore(&bd->bd_intr_lock, flags);
944 * Neo specific interrupt handler.
946 static irqreturn_t neo_intr(int irq, void *voidbrd)
948 struct dgnc_board *brd = (struct dgnc_board *) voidbrd;
949 struct channel_t *ch;
956 unsigned long flags2;
959 APR(("Received interrupt (%d) with null board associated\n", irq));
964 * Check to make sure its for us.
966 if (brd->magic != DGNC_BOARD_MAGIC) {
967 APR(("Received interrupt (%d) with a board pointer that wasn't ours!\n", irq));
973 /* Lock out the slow poller from running on this board. */
974 spin_lock_irqsave(&brd->bd_intr_lock, flags);
977 * Read in "extended" IRQ information from the 32bit Neo register.
978 * Bits 0-7: What port triggered the interrupt.
979 * Bits 8-31: Each 3bits indicate what type of interrupt occurred.
981 uart_poll = readl(brd->re_map_membase + UART_17158_POLL_ADDR_OFFSET);
984 * If 0, no interrupts pending.
985 * This can happen if the IRQ is shared among a couple Neo/Classic boards.
988 spin_unlock_irqrestore(&brd->bd_intr_lock, flags);
992 /* At this point, we have at least SOMETHING to service, dig further... */
996 /* Loop on each port */
997 while ((uart_poll & 0xff) != 0) {
1001 /* Check current port to see if it has interrupt pending */
1002 if ((tmp & dgnc_offset_table[current_port]) != 0) {
1003 port = current_port;
1004 type = tmp >> (8 + (port * 3));
1011 /* Remove this port + type from uart_poll */
1012 uart_poll &= ~(dgnc_offset_table[port]);
1015 /* If no type, just ignore it, and move onto next port */
1019 /* Switch on type of interrupt we have */
1022 case UART_17158_RXRDY_TIMEOUT:
1024 * RXRDY Time-out is cleared by reading data in the
1025 * RX FIFO until it falls below the trigger level.
1028 /* Verify the port is in range. */
1029 if (port > brd->nasync)
1032 ch = brd->channels[port];
1033 neo_copy_data_from_uart_to_queue(ch);
1035 /* Call our tty layer to enforce queue flow control if needed. */
1036 spin_lock_irqsave(&ch->ch_lock, flags2);
1037 dgnc_check_queue_flow_control(ch);
1038 spin_unlock_irqrestore(&ch->ch_lock, flags2);
1042 case UART_17158_RX_LINE_STATUS:
1044 * RXRDY and RX LINE Status (logic OR of LSR[4:1])
1046 neo_parse_lsr(brd, port);
1049 case UART_17158_TXRDY:
1051 * TXRDY interrupt clears after reading ISR register for the UART channel.
1055 * Yes, this is odd...
1056 * Why would I check EVERY possibility of type of
1057 * interrupt, when we know its TXRDY???
1058 * Becuz for some reason, even tho we got triggered for TXRDY,
1059 * it seems to be occasionally wrong. Instead of TX, which
1060 * it should be, I was getting things like RXDY too. Weird.
1062 neo_parse_isr(brd, port);
1065 case UART_17158_MSR:
1067 * MSR or flow control was seen.
1069 neo_parse_isr(brd, port);
1074 * The UART triggered us with a bogus interrupt type.
1075 * It appears the Exar chip, when REALLY bogged down, will throw
1076 * these once and awhile.
1077 * Its harmless, just ignore it and move on.
1084 * Schedule tasklet to more in-depth servicing at a better time.
1086 tasklet_schedule(&brd->helper_tasklet);
1088 spin_unlock_irqrestore(&brd->bd_intr_lock, flags);
1095 * Neo specific way of turning off the receiver.
1096 * Used as a way to enforce queue flow control when in
1097 * hardware flow control mode.
1099 static void neo_disable_receiver(struct channel_t *ch)
1101 unsigned char tmp = readb(&ch->ch_neo_uart->ier);
1103 tmp &= ~(UART_IER_RDI);
1104 writeb(tmp, &ch->ch_neo_uart->ier);
1105 neo_pci_posting_flush(ch->ch_bd);
1110 * Neo specific way of turning on the receiver.
1111 * Used as a way to un-enforce queue flow control when in
1112 * hardware flow control mode.
1114 static void neo_enable_receiver(struct channel_t *ch)
1116 unsigned char tmp = readb(&ch->ch_neo_uart->ier);
1118 tmp |= (UART_IER_RDI);
1119 writeb(tmp, &ch->ch_neo_uart->ier);
1120 neo_pci_posting_flush(ch->ch_bd);
1124 static void neo_copy_data_from_uart_to_queue(struct channel_t *ch)
1127 unsigned char linestatus = 0;
1128 unsigned char error_mask = 0;
1133 unsigned long flags;
1135 if (!ch || ch->magic != DGNC_CHANNEL_MAGIC)
1138 spin_lock_irqsave(&ch->ch_lock, flags);
1140 /* cache head and tail of queue */
1141 head = ch->ch_r_head & RQUEUEMASK;
1142 tail = ch->ch_r_tail & RQUEUEMASK;
1144 /* Get our cached LSR */
1145 linestatus = ch->ch_cached_lsr;
1146 ch->ch_cached_lsr = 0;
1148 /* Store how much space we have left in the queue */
1149 qleft = tail - head - 1;
1151 qleft += RQUEUEMASK + 1;
1154 * If the UART is not in FIFO mode, force the FIFO copy to
1155 * NOT be run, by setting total to 0.
1157 * On the other hand, if the UART IS in FIFO mode, then ask
1158 * the UART to give us an approximation of data it has RX'ed.
1160 if (!(ch->ch_flags & CH_FIFO_ENABLED))
1163 total = readb(&ch->ch_neo_uart->rfifo);
1166 * EXAR chip bug - RX FIFO COUNT - Fudge factor.
1168 * This resolves a problem/bug with the Exar chip that sometimes
1169 * returns a bogus value in the rfifo register.
1170 * The count can be any where from 0-3 bytes "off".
1171 * Bizarre, but true.
1173 if ((ch->ch_bd->dvid & 0xf0) >= UART_XR17E158_DVID)
1181 * Finally, bound the copy to make sure we don't overflow
1183 * The byte by byte copy loop below this loop this will
1184 * deal with the queue overflow possibility.
1186 total = min(total, qleft);
1191 * Grab the linestatus register, we need to check
1192 * to see if there are any errors in the FIFO.
1194 linestatus = readb(&ch->ch_neo_uart->lsr);
1197 * Break out if there is a FIFO error somewhere.
1198 * This will allow us to go byte by byte down below,
1199 * finding the exact location of the error.
1201 if (linestatus & UART_17158_RX_FIFO_DATA_ERROR)
1204 /* Make sure we don't go over the end of our queue */
1205 n = min(((uint) total), (RQUEUESIZE - (uint) head));
1208 * Cut down n even further if needed, this is to fix
1209 * a problem with memcpy_fromio() with the Neo on the
1210 * IBM pSeries platform.
1211 * 15 bytes max appears to be the magic number.
1213 n = min((uint) n, (uint) 12);
1216 * Since we are grabbing the linestatus register, which
1217 * will reset some bits after our read, we need to ensure
1218 * we don't miss our TX FIFO emptys.
1220 if (linestatus & (UART_LSR_THRE | UART_17158_TX_AND_FIFO_CLR))
1221 ch->ch_flags |= (CH_TX_FIFO_EMPTY | CH_TX_FIFO_LWM);
1225 /* Copy data from uart to the queue */
1226 memcpy_fromio(ch->ch_rqueue + head, &ch->ch_neo_uart->txrxburst, n);
1227 dgnc_sniff_nowait_nolock(ch, "UART READ", ch->ch_rqueue + head, n);
1230 * Since RX_FIFO_DATA_ERROR was 0, we are guarenteed
1231 * that all the data currently in the FIFO is free of
1232 * breaks and parity/frame/orun errors.
1234 memset(ch->ch_equeue + head, 0, n);
1236 /* Add to and flip head if needed */
1237 head = (head + n) & RQUEUEMASK;
1240 ch->ch_rxcount += n;
1244 * Create a mask to determine whether we should
1245 * insert the character (if any) into our queue.
1247 if (ch->ch_c_iflag & IGNBRK)
1248 error_mask |= UART_LSR_BI;
1251 * Now cleanup any leftover bytes still in the UART.
1252 * Also deal with any possible queue overflow here as well.
1257 * Its possible we have a linestatus from the loop above
1258 * this, so we "OR" on any extra bits.
1260 linestatus |= readb(&ch->ch_neo_uart->lsr);
1263 * If the chip tells us there is no more data pending to
1264 * be read, we can then leave.
1265 * But before we do, cache the linestatus, just in case.
1267 if (!(linestatus & UART_LSR_DR)) {
1268 ch->ch_cached_lsr = linestatus;
1272 /* No need to store this bit */
1273 linestatus &= ~UART_LSR_DR;
1276 * Since we are grabbing the linestatus register, which
1277 * will reset some bits after our read, we need to ensure
1278 * we don't miss our TX FIFO emptys.
1280 if (linestatus & (UART_LSR_THRE | UART_17158_TX_AND_FIFO_CLR)) {
1281 linestatus &= ~(UART_LSR_THRE | UART_17158_TX_AND_FIFO_CLR);
1282 ch->ch_flags |= (CH_TX_FIFO_EMPTY | CH_TX_FIFO_LWM);
1286 * Discard character if we are ignoring the error mask.
1288 if (linestatus & error_mask) {
1289 unsigned char discard;
1292 memcpy_fromio(&discard, &ch->ch_neo_uart->txrxburst, 1);
1297 * If our queue is full, we have no choice but to drop some data.
1298 * The assumption is that HWFLOW or SWFLOW should have stopped
1299 * things way way before we got to this point.
1301 * I decided that I wanted to ditch the oldest data first,
1302 * I hope thats okay with everyone? Yes? Good.
1305 tail = (tail + 1) & RQUEUEMASK;
1306 ch->ch_r_tail = tail;
1307 ch->ch_err_overrun++;
1311 memcpy_fromio(ch->ch_rqueue + head, &ch->ch_neo_uart->txrxburst, 1);
1312 ch->ch_equeue[head] = (unsigned char) linestatus;
1313 dgnc_sniff_nowait_nolock(ch, "UART READ", ch->ch_rqueue + head, 1);
1315 /* Ditch any remaining linestatus value. */
1318 /* Add to and flip head if needed */
1319 head = (head + 1) & RQUEUEMASK;
1326 * Write new final heads to channel structure.
1328 ch->ch_r_head = head & RQUEUEMASK;
1329 ch->ch_e_head = head & EQUEUEMASK;
1331 spin_unlock_irqrestore(&ch->ch_lock, flags);
1336 * This function basically goes to sleep for secs, or until
1337 * it gets signalled that the port has fully drained.
1339 static int neo_drain(struct tty_struct *tty, uint seconds)
1341 unsigned long flags;
1342 struct channel_t *ch;
1346 if (!tty || tty->magic != TTY_MAGIC)
1349 un = (struct un_t *) tty->driver_data;
1350 if (!un || un->magic != DGNC_UNIT_MAGIC)
1354 if (!ch || ch->magic != DGNC_CHANNEL_MAGIC)
1357 spin_lock_irqsave(&ch->ch_lock, flags);
1358 un->un_flags |= UN_EMPTY;
1359 spin_unlock_irqrestore(&ch->ch_lock, flags);
1362 * Go to sleep waiting for the tty layer to wake me back up when
1363 * the empty flag goes away.
1365 * NOTE: TODO: Do something with time passed in.
1367 rc = wait_event_interruptible(un->un_flags_wait, ((un->un_flags & UN_EMPTY) == 0));
1369 /* If ret is non-zero, user ctrl-c'ed us */
1375 * Flush the WRITE FIFO on the Neo.
1377 * NOTE: Channel lock MUST be held before calling this function!
1379 static void neo_flush_uart_write(struct channel_t *ch)
1381 unsigned char tmp = 0;
1384 if (!ch || ch->magic != DGNC_CHANNEL_MAGIC)
1387 writeb((UART_FCR_ENABLE_FIFO | UART_FCR_CLEAR_XMIT), &ch->ch_neo_uart->isr_fcr);
1388 neo_pci_posting_flush(ch->ch_bd);
1390 for (i = 0; i < 10; i++) {
1392 /* Check to see if the UART feels it completely flushed the FIFO. */
1393 tmp = readb(&ch->ch_neo_uart->isr_fcr);
1400 ch->ch_flags |= (CH_TX_FIFO_EMPTY | CH_TX_FIFO_LWM);
1405 * Flush the READ FIFO on the Neo.
1407 * NOTE: Channel lock MUST be held before calling this function!
1409 static void neo_flush_uart_read(struct channel_t *ch)
1411 unsigned char tmp = 0;
1414 if (!ch || ch->magic != DGNC_CHANNEL_MAGIC)
1417 writeb((UART_FCR_ENABLE_FIFO | UART_FCR_CLEAR_RCVR), &ch->ch_neo_uart->isr_fcr);
1418 neo_pci_posting_flush(ch->ch_bd);
1420 for (i = 0; i < 10; i++) {
1422 /* Check to see if the UART feels it completely flushed the FIFO. */
1423 tmp = readb(&ch->ch_neo_uart->isr_fcr);
1432 static void neo_copy_data_from_queue_to_uart(struct channel_t *ch)
1439 uint len_written = 0;
1440 unsigned long flags;
1442 if (!ch || ch->magic != DGNC_CHANNEL_MAGIC)
1445 spin_lock_irqsave(&ch->ch_lock, flags);
1447 /* No data to write to the UART */
1448 if (ch->ch_w_tail == ch->ch_w_head) {
1449 spin_unlock_irqrestore(&ch->ch_lock, flags);
1453 /* If port is "stopped", don't send any data to the UART */
1454 if ((ch->ch_flags & CH_FORCED_STOP) || (ch->ch_flags & CH_BREAK_SENDING)) {
1455 spin_unlock_irqrestore(&ch->ch_lock, flags);
1460 * If FIFOs are disabled. Send data directly to txrx register
1462 if (!(ch->ch_flags & CH_FIFO_ENABLED)) {
1463 unsigned char lsrbits = readb(&ch->ch_neo_uart->lsr);
1465 /* Cache the LSR bits for later parsing */
1466 ch->ch_cached_lsr |= lsrbits;
1467 if (ch->ch_cached_lsr & UART_LSR_THRE) {
1468 ch->ch_cached_lsr &= ~(UART_LSR_THRE);
1471 * If RTS Toggle mode is on, turn on RTS now if not already set,
1472 * and make sure we get an event when the data transfer has completed.
1474 if (ch->ch_digi.digi_flags & DIGI_RTS_TOGGLE) {
1475 if (!(ch->ch_mostat & UART_MCR_RTS)) {
1476 ch->ch_mostat |= (UART_MCR_RTS);
1477 neo_assert_modem_signals(ch);
1479 ch->ch_tun.un_flags |= (UN_EMPTY);
1482 * If DTR Toggle mode is on, turn on DTR now if not already set,
1483 * and make sure we get an event when the data transfer has completed.
1485 if (ch->ch_digi.digi_flags & DIGI_DTR_TOGGLE) {
1486 if (!(ch->ch_mostat & UART_MCR_DTR)) {
1487 ch->ch_mostat |= (UART_MCR_DTR);
1488 neo_assert_modem_signals(ch);
1490 ch->ch_tun.un_flags |= (UN_EMPTY);
1493 writeb(ch->ch_wqueue[ch->ch_w_tail], &ch->ch_neo_uart->txrx);
1495 ch->ch_w_tail &= WQUEUEMASK;
1498 spin_unlock_irqrestore(&ch->ch_lock, flags);
1503 * We have to do it this way, because of the EXAR TXFIFO count bug.
1505 if ((ch->ch_bd->dvid & 0xf0) < UART_XR17E158_DVID) {
1506 if (!(ch->ch_flags & (CH_TX_FIFO_EMPTY | CH_TX_FIFO_LWM))) {
1507 spin_unlock_irqrestore(&ch->ch_lock, flags);
1513 n = readb(&ch->ch_neo_uart->tfifo);
1515 if ((unsigned int) n > ch->ch_t_tlevel) {
1516 spin_unlock_irqrestore(&ch->ch_lock, flags);
1520 n = UART_17158_TX_FIFOSIZE - ch->ch_t_tlevel;
1522 n = UART_17158_TX_FIFOSIZE - readb(&ch->ch_neo_uart->tfifo);
1525 /* cache head and tail of queue */
1526 head = ch->ch_w_head & WQUEUEMASK;
1527 tail = ch->ch_w_tail & WQUEUEMASK;
1528 qlen = (head - tail) & WQUEUEMASK;
1530 /* Find minimum of the FIFO space, versus queue length */
1535 s = ((head >= tail) ? head : WQUEUESIZE) - tail;
1542 * If RTS Toggle mode is on, turn on RTS now if not already set,
1543 * and make sure we get an event when the data transfer has completed.
1545 if (ch->ch_digi.digi_flags & DIGI_RTS_TOGGLE) {
1546 if (!(ch->ch_mostat & UART_MCR_RTS)) {
1547 ch->ch_mostat |= (UART_MCR_RTS);
1548 neo_assert_modem_signals(ch);
1550 ch->ch_tun.un_flags |= (UN_EMPTY);
1554 * If DTR Toggle mode is on, turn on DTR now if not already set,
1555 * and make sure we get an event when the data transfer has completed.
1557 if (ch->ch_digi.digi_flags & DIGI_DTR_TOGGLE) {
1558 if (!(ch->ch_mostat & UART_MCR_DTR)) {
1559 ch->ch_mostat |= (UART_MCR_DTR);
1560 neo_assert_modem_signals(ch);
1562 ch->ch_tun.un_flags |= (UN_EMPTY);
1565 memcpy_toio(&ch->ch_neo_uart->txrxburst, ch->ch_wqueue + tail, s);
1566 dgnc_sniff_nowait_nolock(ch, "UART WRITE", ch->ch_wqueue + tail, s);
1568 /* Add and flip queue if needed */
1569 tail = (tail + s) & WQUEUEMASK;
1571 ch->ch_txcount += s;
1575 /* Update the final tail */
1576 ch->ch_w_tail = tail & WQUEUEMASK;
1578 if (len_written > 0) {
1579 neo_pci_posting_flush(ch->ch_bd);
1580 ch->ch_flags &= ~(CH_TX_FIFO_EMPTY | CH_TX_FIFO_LWM);
1583 spin_unlock_irqrestore(&ch->ch_lock, flags);
1587 static void neo_parse_modem(struct channel_t *ch, unsigned char signals)
1589 unsigned char msignals = signals;
1591 if (!ch || ch->magic != DGNC_CHANNEL_MAGIC)
1595 * Do altpin switching. Altpin switches DCD and DSR.
1596 * This prolly breaks DSRPACE, so we should be more clever here.
1598 if (ch->ch_digi.digi_flags & DIGI_ALTPIN) {
1599 unsigned char mswap = msignals;
1601 if (mswap & UART_MSR_DDCD) {
1602 msignals &= ~UART_MSR_DDCD;
1603 msignals |= UART_MSR_DDSR;
1605 if (mswap & UART_MSR_DDSR) {
1606 msignals &= ~UART_MSR_DDSR;
1607 msignals |= UART_MSR_DDCD;
1609 if (mswap & UART_MSR_DCD) {
1610 msignals &= ~UART_MSR_DCD;
1611 msignals |= UART_MSR_DSR;
1613 if (mswap & UART_MSR_DSR) {
1614 msignals &= ~UART_MSR_DSR;
1615 msignals |= UART_MSR_DCD;
1619 /* Scrub off lower bits. They signify delta's, which I don't care about */
1622 if (msignals & UART_MSR_DCD)
1623 ch->ch_mistat |= UART_MSR_DCD;
1625 ch->ch_mistat &= ~UART_MSR_DCD;
1627 if (msignals & UART_MSR_DSR)
1628 ch->ch_mistat |= UART_MSR_DSR;
1630 ch->ch_mistat &= ~UART_MSR_DSR;
1632 if (msignals & UART_MSR_RI)
1633 ch->ch_mistat |= UART_MSR_RI;
1635 ch->ch_mistat &= ~UART_MSR_RI;
1637 if (msignals & UART_MSR_CTS)
1638 ch->ch_mistat |= UART_MSR_CTS;
1640 ch->ch_mistat &= ~UART_MSR_CTS;
1644 /* Make the UART raise any of the output signals we want up */
1645 static void neo_assert_modem_signals(struct channel_t *ch)
1649 if (!ch || ch->magic != DGNC_CHANNEL_MAGIC)
1652 out = ch->ch_mostat;
1654 if (ch->ch_flags & CH_LOOPBACK)
1655 out |= UART_MCR_LOOP;
1657 writeb(out, &ch->ch_neo_uart->mcr);
1658 neo_pci_posting_flush(ch->ch_bd);
1660 /* Give time for the UART to actually raise/drop the signals */
1665 static void neo_send_start_character(struct channel_t *ch)
1667 if (!ch || ch->magic != DGNC_CHANNEL_MAGIC)
1670 if (ch->ch_startc != _POSIX_VDISABLE) {
1672 writeb(ch->ch_startc, &ch->ch_neo_uart->txrx);
1673 neo_pci_posting_flush(ch->ch_bd);
1679 static void neo_send_stop_character(struct channel_t *ch)
1681 if (!ch || ch->magic != DGNC_CHANNEL_MAGIC)
1684 if (ch->ch_stopc != _POSIX_VDISABLE) {
1685 ch->ch_xoff_sends++;
1686 writeb(ch->ch_stopc, &ch->ch_neo_uart->txrx);
1687 neo_pci_posting_flush(ch->ch_bd);
1696 static void neo_uart_init(struct channel_t *ch)
1699 writeb(0, &ch->ch_neo_uart->ier);
1700 writeb(0, &ch->ch_neo_uart->efr);
1701 writeb(UART_EFR_ECB, &ch->ch_neo_uart->efr);
1704 /* Clear out UART and FIFO */
1705 readb(&ch->ch_neo_uart->txrx);
1706 writeb((UART_FCR_ENABLE_FIFO|UART_FCR_CLEAR_RCVR|UART_FCR_CLEAR_XMIT), &ch->ch_neo_uart->isr_fcr);
1707 readb(&ch->ch_neo_uart->lsr);
1708 readb(&ch->ch_neo_uart->msr);
1710 ch->ch_flags |= CH_FIFO_ENABLED;
1712 /* Assert any signals we want up */
1713 writeb(ch->ch_mostat, &ch->ch_neo_uart->mcr);
1714 neo_pci_posting_flush(ch->ch_bd);
1719 * Make the UART completely turn off.
1721 static void neo_uart_off(struct channel_t *ch)
1723 /* Turn off UART enhanced bits */
1724 writeb(0, &ch->ch_neo_uart->efr);
1726 /* Stop all interrupts from occurring. */
1727 writeb(0, &ch->ch_neo_uart->ier);
1728 neo_pci_posting_flush(ch->ch_bd);
1732 static uint neo_get_uart_bytes_left(struct channel_t *ch)
1734 unsigned char left = 0;
1735 unsigned char lsr = readb(&ch->ch_neo_uart->lsr);
1737 /* We must cache the LSR as some of the bits get reset once read... */
1738 ch->ch_cached_lsr |= lsr;
1740 /* Determine whether the Transmitter is empty or not */
1741 if (!(lsr & UART_LSR_TEMT)) {
1742 if (ch->ch_flags & CH_TX_FIFO_EMPTY)
1743 tasklet_schedule(&ch->ch_bd->helper_tasklet);
1746 ch->ch_flags |= (CH_TX_FIFO_EMPTY | CH_TX_FIFO_LWM);
1754 /* Channel lock MUST be held by the calling function! */
1755 static void neo_send_break(struct channel_t *ch, int msecs)
1758 * If we receive a time of 0, this means turn off the break.
1761 if (ch->ch_flags & CH_BREAK_SENDING) {
1762 unsigned char temp = readb(&ch->ch_neo_uart->lcr);
1764 writeb((temp & ~UART_LCR_SBC), &ch->ch_neo_uart->lcr);
1765 neo_pci_posting_flush(ch->ch_bd);
1766 ch->ch_flags &= ~(CH_BREAK_SENDING);
1767 ch->ch_stop_sending_break = 0;
1773 * Set the time we should stop sending the break.
1774 * If we are already sending a break, toss away the existing
1775 * time to stop, and use this new value instead.
1777 ch->ch_stop_sending_break = jiffies + dgnc_jiffies_from_ms(msecs);
1779 /* Tell the UART to start sending the break */
1780 if (!(ch->ch_flags & CH_BREAK_SENDING)) {
1781 unsigned char temp = readb(&ch->ch_neo_uart->lcr);
1783 writeb((temp | UART_LCR_SBC), &ch->ch_neo_uart->lcr);
1784 neo_pci_posting_flush(ch->ch_bd);
1785 ch->ch_flags |= (CH_BREAK_SENDING);
1791 * neo_send_immediate_char.
1793 * Sends a specific character as soon as possible to the UART,
1794 * jumping over any bytes that might be in the write queue.
1796 * The channel lock MUST be held by the calling function.
1798 static void neo_send_immediate_char(struct channel_t *ch, unsigned char c)
1800 if (!ch || ch->magic != DGNC_CHANNEL_MAGIC)
1803 writeb(c, &ch->ch_neo_uart->txrx);
1804 neo_pci_posting_flush(ch->ch_bd);
1808 static unsigned int neo_read_eeprom(unsigned char __iomem *base, unsigned int address)
1810 unsigned int enable;
1812 unsigned int databit;
1815 /* enable chip select */
1816 writeb(NEO_EECS, base + NEO_EEREG);
1818 enable = (address | 0x180);
1820 for (bits = 9; bits--; ) {
1821 databit = (enable & (1 << bits)) ? NEO_EEDI : 0;
1822 /* Set read address */
1823 writeb(databit | NEO_EECS, base + NEO_EEREG);
1824 writeb(databit | NEO_EECS | NEO_EECK, base + NEO_EEREG);
1829 for (bits = 17; bits--; ) {
1830 /* clock to EEPROM */
1831 writeb(NEO_EECS, base + NEO_EEREG);
1832 writeb(NEO_EECS | NEO_EECK, base + NEO_EEREG);
1835 if (readb(base + NEO_EEREG) & NEO_EEDO)
1839 /* clock falling edge */
1840 writeb(NEO_EECS, base + NEO_EEREG);
1842 /* drop chip select */
1843 writeb(0x00, base + NEO_EEREG);
1849 static void neo_vpd(struct dgnc_board *brd)
1854 if (!brd || brd->magic != DGNC_BOARD_MAGIC)
1857 if (!brd->re_map_membase)
1860 /* Store the VPD into our buffer */
1861 for (i = 0; i < NEO_VPD_IMAGESIZE; i++) {
1862 a = neo_read_eeprom(brd->re_map_membase, i);
1863 brd->vpd[i*2] = a & 0xff;
1864 brd->vpd[(i*2)+1] = (a >> 8) & 0xff;
1867 if (((brd->vpd[0x08] != 0x82) /* long resource name tag */
1868 && (brd->vpd[0x10] != 0x82)) /* long resource name tag (PCI-66 files)*/
1869 || (brd->vpd[0x7F] != 0x78)) { /* small resource end tag */
1871 memset(brd->vpd, '\0', NEO_VPD_IMAGESIZE);
1873 /* Search for the serial number */
1874 for (i = 0; i < NEO_VPD_IMAGEBYTES - 3; i++)
1875 if (brd->vpd[i] == 'S' && brd->vpd[i + 1] == 'N')
1876 strncpy(brd->serial_num, &(brd->vpd[i + 3]), 9);