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;
534 * Check to make sure it didn't receive interrupt with a null board
535 * associated or a board pointer that wasn't ours.
537 if (!brd || brd->magic != DGNC_BOARD_MAGIC)
540 if (port > brd->maxports)
543 ch = brd->channels[port];
544 if (!ch || ch->magic != DGNC_CHANNEL_MAGIC)
547 linestatus = readb(&ch->ch_neo_uart->lsr);
549 ch->ch_cached_lsr |= linestatus;
551 if (ch->ch_cached_lsr & UART_LSR_DR) {
554 /* Read data from uart -> queue */
555 neo_copy_data_from_uart_to_queue(ch);
556 spin_lock_irqsave(&ch->ch_lock, flags);
557 dgnc_check_queue_flow_control(ch);
558 spin_unlock_irqrestore(&ch->ch_lock, flags);
562 * The next 3 tests should *NOT* happen, as the above test
563 * should encapsulate all 3... At least, thats what Exar says.
566 if (linestatus & UART_LSR_PE)
569 if (linestatus & UART_LSR_FE)
572 if (linestatus & UART_LSR_BI)
575 if (linestatus & UART_LSR_OE) {
577 * Rx Oruns. Exar says that an orun will NOT corrupt
578 * the FIFO. It will just replace the holding register
579 * with this new data byte. So basically just ignore this.
580 * Probably we should eventually have an orun stat in our driver...
582 ch->ch_err_overrun++;
585 if (linestatus & UART_LSR_THRE) {
588 spin_lock_irqsave(&ch->ch_lock, flags);
589 ch->ch_flags |= (CH_TX_FIFO_EMPTY | CH_TX_FIFO_LWM);
590 spin_unlock_irqrestore(&ch->ch_lock, flags);
592 /* Transfer data (if any) from Write Queue -> UART. */
593 neo_copy_data_from_queue_to_uart(ch);
594 } else if (linestatus & UART_17158_TX_AND_FIFO_CLR) {
597 spin_lock_irqsave(&ch->ch_lock, flags);
598 ch->ch_flags |= (CH_TX_FIFO_EMPTY | CH_TX_FIFO_LWM);
599 spin_unlock_irqrestore(&ch->ch_lock, flags);
601 /* Transfer data (if any) from Write Queue -> UART. */
602 neo_copy_data_from_queue_to_uart(ch);
609 * Send any/all changes to the line to the UART.
611 static void neo_param(struct tty_struct *tty)
613 unsigned char lcr = 0;
614 unsigned char uart_lcr = 0;
615 unsigned char ier = 0;
616 unsigned char uart_ier = 0;
619 struct dgnc_board *bd;
620 struct channel_t *ch;
623 if (!tty || tty->magic != TTY_MAGIC)
626 un = (struct un_t *) tty->driver_data;
627 if (!un || un->magic != DGNC_UNIT_MAGIC)
631 if (!ch || ch->magic != DGNC_CHANNEL_MAGIC)
635 if (!bd || bd->magic != DGNC_BOARD_MAGIC)
639 * If baud rate is zero, flush queues, and set mval to drop DTR.
641 if ((ch->ch_c_cflag & (CBAUD)) == 0) {
649 neo_flush_uart_write(ch);
650 neo_flush_uart_read(ch);
652 /* The baudrate is B0 so all modem lines are to be dropped. */
653 ch->ch_flags |= (CH_BAUD0);
654 ch->ch_mostat &= ~(UART_MCR_RTS | UART_MCR_DTR);
655 neo_assert_modem_signals(ch);
659 } else if (ch->ch_custom_speed) {
661 baud = ch->ch_custom_speed;
662 /* Handle transition from B0 */
663 if (ch->ch_flags & CH_BAUD0) {
664 ch->ch_flags &= ~(CH_BAUD0);
667 * Bring back up RTS and DTR...
668 * Also handle RTS or DTR toggle if set.
670 if (!(ch->ch_digi.digi_flags & DIGI_RTS_TOGGLE))
671 ch->ch_mostat |= (UART_MCR_RTS);
672 if (!(ch->ch_digi.digi_flags & DIGI_DTR_TOGGLE))
673 ch->ch_mostat |= (UART_MCR_DTR);
679 ulong bauds[4][16] = {
683 600, 1200, 1800, 2400,
684 4800, 9600, 19200, 38400 },
685 { /* slowbaud & CBAUDEX */
686 0, 57600, 115200, 230400,
687 460800, 150, 200, 921600,
688 600, 1200, 1800, 2400,
689 4800, 9600, 19200, 38400 },
691 0, 57600, 76800, 115200,
692 131657, 153600, 230400, 460800,
693 921600, 1200, 1800, 2400,
694 4800, 9600, 19200, 38400 },
695 { /* fastbaud & CBAUDEX */
696 0, 57600, 115200, 230400,
697 460800, 150, 200, 921600,
698 600, 1200, 1800, 2400,
699 4800, 9600, 19200, 38400 }
702 /* Only use the TXPrint baud rate if the terminal unit is NOT open */
703 if (!(ch->ch_tun.un_flags & UN_ISOPEN) && (un->un_type == DGNC_PRINT))
704 baud = C_BAUD(ch->ch_pun.un_tty) & 0xff;
706 baud = C_BAUD(ch->ch_tun.un_tty) & 0xff;
708 if (ch->ch_c_cflag & CBAUDEX)
711 if (ch->ch_digi.digi_flags & DIGI_FAST)
716 if ((iindex >= 0) && (iindex < 4) && (jindex >= 0) && (jindex < 16))
717 baud = bauds[iindex][jindex];
724 /* Handle transition from B0 */
725 if (ch->ch_flags & CH_BAUD0) {
726 ch->ch_flags &= ~(CH_BAUD0);
729 * Bring back up RTS and DTR...
730 * Also handle RTS or DTR toggle if set.
732 if (!(ch->ch_digi.digi_flags & DIGI_RTS_TOGGLE))
733 ch->ch_mostat |= (UART_MCR_RTS);
734 if (!(ch->ch_digi.digi_flags & DIGI_DTR_TOGGLE))
735 ch->ch_mostat |= (UART_MCR_DTR);
739 if (ch->ch_c_cflag & PARENB)
740 lcr |= UART_LCR_PARITY;
742 if (!(ch->ch_c_cflag & PARODD))
743 lcr |= UART_LCR_EPAR;
746 * Not all platforms support mark/space parity,
747 * so this will hide behind an ifdef.
750 if (ch->ch_c_cflag & CMSPAR)
751 lcr |= UART_LCR_SPAR;
754 if (ch->ch_c_cflag & CSTOPB)
755 lcr |= UART_LCR_STOP;
757 switch (ch->ch_c_cflag & CSIZE) {
759 lcr |= UART_LCR_WLEN5;
762 lcr |= UART_LCR_WLEN6;
765 lcr |= UART_LCR_WLEN7;
769 lcr |= UART_LCR_WLEN8;
773 uart_ier = readb(&ch->ch_neo_uart->ier);
776 uart_lcr = readb(&ch->ch_neo_uart->lcr);
781 quot = ch->ch_bd->bd_dividend / baud;
783 if (quot != 0 && ch->ch_old_baud != baud) {
784 ch->ch_old_baud = baud;
785 writeb(UART_LCR_DLAB, &ch->ch_neo_uart->lcr);
786 writeb((quot & 0xff), &ch->ch_neo_uart->txrx);
787 writeb((quot >> 8), &ch->ch_neo_uart->ier);
788 writeb(lcr, &ch->ch_neo_uart->lcr);
792 writeb(lcr, &ch->ch_neo_uart->lcr);
794 if (ch->ch_c_cflag & CREAD)
795 ier |= (UART_IER_RDI | UART_IER_RLSI);
797 ier &= ~(UART_IER_RDI | UART_IER_RLSI);
800 * Have the UART interrupt on modem signal changes ONLY when
801 * we are in hardware flow control mode, or CLOCAL/FORCEDCD is not set.
803 if ((ch->ch_digi.digi_flags & CTSPACE) ||
804 (ch->ch_digi.digi_flags & RTSPACE) ||
805 (ch->ch_c_cflag & CRTSCTS) ||
806 !(ch->ch_digi.digi_flags & DIGI_FORCEDCD) ||
807 !(ch->ch_c_cflag & CLOCAL))
810 ier &= ~UART_IER_MSI;
812 ier |= UART_IER_THRI;
815 writeb(ier, &ch->ch_neo_uart->ier);
817 /* Set new start/stop chars */
818 neo_set_new_start_stop_chars(ch);
820 if (ch->ch_digi.digi_flags & CTSPACE || ch->ch_c_cflag & CRTSCTS) {
821 neo_set_cts_flow_control(ch);
822 } else if (ch->ch_c_iflag & IXON) {
823 /* If start/stop is set to disable, then we should disable flow control */
824 if ((ch->ch_startc == _POSIX_VDISABLE) || (ch->ch_stopc == _POSIX_VDISABLE))
825 neo_set_no_output_flow_control(ch);
827 neo_set_ixon_flow_control(ch);
829 neo_set_no_output_flow_control(ch);
832 if (ch->ch_digi.digi_flags & RTSPACE || ch->ch_c_cflag & CRTSCTS) {
833 neo_set_rts_flow_control(ch);
834 } else if (ch->ch_c_iflag & IXOFF) {
835 /* If start/stop is set to disable, then we should disable flow control */
836 if ((ch->ch_startc == _POSIX_VDISABLE) || (ch->ch_stopc == _POSIX_VDISABLE))
837 neo_set_no_input_flow_control(ch);
839 neo_set_ixoff_flow_control(ch);
841 neo_set_no_input_flow_control(ch);
845 * Adjust the RX FIFO Trigger level if baud is less than 9600.
846 * Not exactly elegant, but this is needed because of the Exar chip's
847 * delay on firing off the RX FIFO interrupt on slower baud rates.
850 writeb(1, &ch->ch_neo_uart->rfifo);
854 neo_assert_modem_signals(ch);
856 /* Get current status of the modem signals now */
857 neo_parse_modem(ch, readb(&ch->ch_neo_uart->msr));
862 * Our board poller function.
864 static void neo_tasklet(unsigned long data)
866 struct dgnc_board *bd = (struct dgnc_board *) data;
867 struct channel_t *ch;
873 if (!bd || bd->magic != DGNC_BOARD_MAGIC)
876 /* Cache a couple board values */
877 spin_lock_irqsave(&bd->bd_lock, flags);
880 spin_unlock_irqrestore(&bd->bd_lock, flags);
883 * Do NOT allow the interrupt routine to read the intr registers
884 * Until we release this lock.
886 spin_lock_irqsave(&bd->bd_intr_lock, flags);
889 * If board is ready, parse deeper to see if there is anything to do.
891 if ((state == BOARD_READY) && (ports > 0)) {
892 /* Loop on each port */
893 for (i = 0; i < ports; i++) {
894 ch = bd->channels[i];
896 /* Just being careful... */
897 if (!ch || ch->magic != DGNC_CHANNEL_MAGIC)
901 * NOTE: Remember you CANNOT hold any channel
902 * locks when calling the input routine.
904 * During input processing, its possible we
905 * will call the Linux ld, which might in turn,
906 * do a callback right back into us, resulting
907 * in us trying to grab the channel lock twice!
912 * Channel lock is grabbed and then released
913 * inside both of these routines, but neither
914 * call anything else that could call back into us.
916 neo_copy_data_from_queue_to_uart(ch);
917 dgnc_wakeup_writes(ch);
920 * Call carrier carrier function, in case something
926 * Check to see if we need to turn off a sending break.
927 * The timing check is done inside clear_break()
929 if (ch->ch_stop_sending_break)
930 neo_clear_break(ch, 0);
934 /* Allow interrupt routine to access the interrupt register again */
935 spin_unlock_irqrestore(&bd->bd_intr_lock, flags);
943 * Neo specific interrupt handler.
945 static irqreturn_t neo_intr(int irq, void *voidbrd)
947 struct dgnc_board *brd = voidbrd;
948 struct channel_t *ch;
955 unsigned long flags2;
958 * Check to make sure it didn't receive interrupt with a null board
959 * associated or a board pointer that wasn't ours.
961 if (!brd || brd->magic != DGNC_BOARD_MAGIC)
966 /* Lock out the slow poller from running on this board. */
967 spin_lock_irqsave(&brd->bd_intr_lock, flags);
970 * Read in "extended" IRQ information from the 32bit Neo register.
971 * Bits 0-7: What port triggered the interrupt.
972 * Bits 8-31: Each 3bits indicate what type of interrupt occurred.
974 uart_poll = readl(brd->re_map_membase + UART_17158_POLL_ADDR_OFFSET);
977 * If 0, no interrupts pending.
978 * This can happen if the IRQ is shared among a couple Neo/Classic boards.
981 spin_unlock_irqrestore(&brd->bd_intr_lock, flags);
985 /* At this point, we have at least SOMETHING to service, dig further... */
989 /* Loop on each port */
990 while ((uart_poll & 0xff) != 0) {
994 /* Check current port to see if it has interrupt pending */
995 if ((tmp & dgnc_offset_table[current_port]) != 0) {
997 type = tmp >> (8 + (port * 3));
1004 /* Remove this port + type from uart_poll */
1005 uart_poll &= ~(dgnc_offset_table[port]);
1008 /* If no type, just ignore it, and move onto next port */
1012 /* Switch on type of interrupt we have */
1015 case UART_17158_RXRDY_TIMEOUT:
1017 * RXRDY Time-out is cleared by reading data in the
1018 * RX FIFO until it falls below the trigger level.
1021 /* Verify the port is in range. */
1022 if (port > brd->nasync)
1025 ch = brd->channels[port];
1026 neo_copy_data_from_uart_to_queue(ch);
1028 /* Call our tty layer to enforce queue flow control if needed. */
1029 spin_lock_irqsave(&ch->ch_lock, flags2);
1030 dgnc_check_queue_flow_control(ch);
1031 spin_unlock_irqrestore(&ch->ch_lock, flags2);
1035 case UART_17158_RX_LINE_STATUS:
1037 * RXRDY and RX LINE Status (logic OR of LSR[4:1])
1039 neo_parse_lsr(brd, port);
1042 case UART_17158_TXRDY:
1044 * TXRDY interrupt clears after reading ISR register for the UART channel.
1048 * Yes, this is odd...
1049 * Why would I check EVERY possibility of type of
1050 * interrupt, when we know its TXRDY???
1051 * Becuz for some reason, even tho we got triggered for TXRDY,
1052 * it seems to be occasionally wrong. Instead of TX, which
1053 * it should be, I was getting things like RXDY too. Weird.
1055 neo_parse_isr(brd, port);
1058 case UART_17158_MSR:
1060 * MSR or flow control was seen.
1062 neo_parse_isr(brd, port);
1067 * The UART triggered us with a bogus interrupt type.
1068 * It appears the Exar chip, when REALLY bogged down, will throw
1069 * these once and awhile.
1070 * Its harmless, just ignore it and move on.
1077 * Schedule tasklet to more in-depth servicing at a better time.
1079 tasklet_schedule(&brd->helper_tasklet);
1081 spin_unlock_irqrestore(&brd->bd_intr_lock, flags);
1088 * Neo specific way of turning off the receiver.
1089 * Used as a way to enforce queue flow control when in
1090 * hardware flow control mode.
1092 static void neo_disable_receiver(struct channel_t *ch)
1094 unsigned char tmp = readb(&ch->ch_neo_uart->ier);
1096 tmp &= ~(UART_IER_RDI);
1097 writeb(tmp, &ch->ch_neo_uart->ier);
1098 neo_pci_posting_flush(ch->ch_bd);
1103 * Neo specific way of turning on the receiver.
1104 * Used as a way to un-enforce queue flow control when in
1105 * hardware flow control mode.
1107 static void neo_enable_receiver(struct channel_t *ch)
1109 unsigned char tmp = readb(&ch->ch_neo_uart->ier);
1111 tmp |= (UART_IER_RDI);
1112 writeb(tmp, &ch->ch_neo_uart->ier);
1113 neo_pci_posting_flush(ch->ch_bd);
1117 static void neo_copy_data_from_uart_to_queue(struct channel_t *ch)
1120 unsigned char linestatus = 0;
1121 unsigned char error_mask = 0;
1126 unsigned long flags;
1128 if (!ch || ch->magic != DGNC_CHANNEL_MAGIC)
1131 spin_lock_irqsave(&ch->ch_lock, flags);
1133 /* cache head and tail of queue */
1134 head = ch->ch_r_head & RQUEUEMASK;
1135 tail = ch->ch_r_tail & RQUEUEMASK;
1137 /* Get our cached LSR */
1138 linestatus = ch->ch_cached_lsr;
1139 ch->ch_cached_lsr = 0;
1141 /* Store how much space we have left in the queue */
1142 qleft = tail - head - 1;
1144 qleft += RQUEUEMASK + 1;
1147 * If the UART is not in FIFO mode, force the FIFO copy to
1148 * NOT be run, by setting total to 0.
1150 * On the other hand, if the UART IS in FIFO mode, then ask
1151 * the UART to give us an approximation of data it has RX'ed.
1153 if (!(ch->ch_flags & CH_FIFO_ENABLED))
1156 total = readb(&ch->ch_neo_uart->rfifo);
1159 * EXAR chip bug - RX FIFO COUNT - Fudge factor.
1161 * This resolves a problem/bug with the Exar chip that sometimes
1162 * returns a bogus value in the rfifo register.
1163 * The count can be any where from 0-3 bytes "off".
1164 * Bizarre, but true.
1166 if ((ch->ch_bd->dvid & 0xf0) >= UART_XR17E158_DVID)
1174 * Finally, bound the copy to make sure we don't overflow
1176 * The byte by byte copy loop below this loop this will
1177 * deal with the queue overflow possibility.
1179 total = min(total, qleft);
1184 * Grab the linestatus register, we need to check
1185 * to see if there are any errors in the FIFO.
1187 linestatus = readb(&ch->ch_neo_uart->lsr);
1190 * Break out if there is a FIFO error somewhere.
1191 * This will allow us to go byte by byte down below,
1192 * finding the exact location of the error.
1194 if (linestatus & UART_17158_RX_FIFO_DATA_ERROR)
1197 /* Make sure we don't go over the end of our queue */
1198 n = min(((uint) total), (RQUEUESIZE - (uint) head));
1201 * Cut down n even further if needed, this is to fix
1202 * a problem with memcpy_fromio() with the Neo on the
1203 * IBM pSeries platform.
1204 * 15 bytes max appears to be the magic number.
1206 n = min((uint) n, (uint) 12);
1209 * Since we are grabbing the linestatus register, which
1210 * will reset some bits after our read, we need to ensure
1211 * we don't miss our TX FIFO emptys.
1213 if (linestatus & (UART_LSR_THRE | UART_17158_TX_AND_FIFO_CLR))
1214 ch->ch_flags |= (CH_TX_FIFO_EMPTY | CH_TX_FIFO_LWM);
1218 /* Copy data from uart to the queue */
1219 memcpy_fromio(ch->ch_rqueue + head, &ch->ch_neo_uart->txrxburst, n);
1222 * Since RX_FIFO_DATA_ERROR was 0, we are guarenteed
1223 * that all the data currently in the FIFO is free of
1224 * breaks and parity/frame/orun errors.
1226 memset(ch->ch_equeue + head, 0, n);
1228 /* Add to and flip head if needed */
1229 head = (head + n) & RQUEUEMASK;
1232 ch->ch_rxcount += n;
1236 * Create a mask to determine whether we should
1237 * insert the character (if any) into our queue.
1239 if (ch->ch_c_iflag & IGNBRK)
1240 error_mask |= UART_LSR_BI;
1243 * Now cleanup any leftover bytes still in the UART.
1244 * Also deal with any possible queue overflow here as well.
1249 * Its possible we have a linestatus from the loop above
1250 * this, so we "OR" on any extra bits.
1252 linestatus |= readb(&ch->ch_neo_uart->lsr);
1255 * If the chip tells us there is no more data pending to
1256 * be read, we can then leave.
1257 * But before we do, cache the linestatus, just in case.
1259 if (!(linestatus & UART_LSR_DR)) {
1260 ch->ch_cached_lsr = linestatus;
1264 /* No need to store this bit */
1265 linestatus &= ~UART_LSR_DR;
1268 * Since we are grabbing the linestatus register, which
1269 * will reset some bits after our read, we need to ensure
1270 * we don't miss our TX FIFO emptys.
1272 if (linestatus & (UART_LSR_THRE | UART_17158_TX_AND_FIFO_CLR)) {
1273 linestatus &= ~(UART_LSR_THRE | UART_17158_TX_AND_FIFO_CLR);
1274 ch->ch_flags |= (CH_TX_FIFO_EMPTY | CH_TX_FIFO_LWM);
1278 * Discard character if we are ignoring the error mask.
1280 if (linestatus & error_mask) {
1281 unsigned char discard;
1284 memcpy_fromio(&discard, &ch->ch_neo_uart->txrxburst, 1);
1289 * If our queue is full, we have no choice but to drop some data.
1290 * The assumption is that HWFLOW or SWFLOW should have stopped
1291 * things way way before we got to this point.
1293 * I decided that I wanted to ditch the oldest data first,
1294 * I hope thats okay with everyone? Yes? Good.
1297 tail = (tail + 1) & RQUEUEMASK;
1298 ch->ch_r_tail = tail;
1299 ch->ch_err_overrun++;
1303 memcpy_fromio(ch->ch_rqueue + head, &ch->ch_neo_uart->txrxburst, 1);
1304 ch->ch_equeue[head] = (unsigned char) linestatus;
1306 /* Ditch any remaining linestatus value. */
1309 /* Add to and flip head if needed */
1310 head = (head + 1) & RQUEUEMASK;
1317 * Write new final heads to channel structure.
1319 ch->ch_r_head = head & RQUEUEMASK;
1320 ch->ch_e_head = head & EQUEUEMASK;
1322 spin_unlock_irqrestore(&ch->ch_lock, flags);
1327 * This function basically goes to sleep for secs, or until
1328 * it gets signalled that the port has fully drained.
1330 static int neo_drain(struct tty_struct *tty, uint seconds)
1332 unsigned long flags;
1333 struct channel_t *ch;
1337 if (!tty || tty->magic != TTY_MAGIC)
1340 un = (struct un_t *) tty->driver_data;
1341 if (!un || un->magic != DGNC_UNIT_MAGIC)
1345 if (!ch || ch->magic != DGNC_CHANNEL_MAGIC)
1348 spin_lock_irqsave(&ch->ch_lock, flags);
1349 un->un_flags |= UN_EMPTY;
1350 spin_unlock_irqrestore(&ch->ch_lock, flags);
1353 * Go to sleep waiting for the tty layer to wake me back up when
1354 * the empty flag goes away.
1356 * NOTE: TODO: Do something with time passed in.
1358 rc = wait_event_interruptible(un->un_flags_wait, ((un->un_flags & UN_EMPTY) == 0));
1360 /* If ret is non-zero, user ctrl-c'ed us */
1366 * Flush the WRITE FIFO on the Neo.
1368 * NOTE: Channel lock MUST be held before calling this function!
1370 static void neo_flush_uart_write(struct channel_t *ch)
1372 unsigned char tmp = 0;
1375 if (!ch || ch->magic != DGNC_CHANNEL_MAGIC)
1378 writeb((UART_FCR_ENABLE_FIFO | UART_FCR_CLEAR_XMIT), &ch->ch_neo_uart->isr_fcr);
1379 neo_pci_posting_flush(ch->ch_bd);
1381 for (i = 0; i < 10; i++) {
1383 /* Check to see if the UART feels it completely flushed the FIFO. */
1384 tmp = readb(&ch->ch_neo_uart->isr_fcr);
1391 ch->ch_flags |= (CH_TX_FIFO_EMPTY | CH_TX_FIFO_LWM);
1396 * Flush the READ FIFO on the Neo.
1398 * NOTE: Channel lock MUST be held before calling this function!
1400 static void neo_flush_uart_read(struct channel_t *ch)
1402 unsigned char tmp = 0;
1405 if (!ch || ch->magic != DGNC_CHANNEL_MAGIC)
1408 writeb((UART_FCR_ENABLE_FIFO | UART_FCR_CLEAR_RCVR), &ch->ch_neo_uart->isr_fcr);
1409 neo_pci_posting_flush(ch->ch_bd);
1411 for (i = 0; i < 10; i++) {
1413 /* Check to see if the UART feels it completely flushed the FIFO. */
1414 tmp = readb(&ch->ch_neo_uart->isr_fcr);
1423 static void neo_copy_data_from_queue_to_uart(struct channel_t *ch)
1430 uint len_written = 0;
1431 unsigned long flags;
1433 if (!ch || ch->magic != DGNC_CHANNEL_MAGIC)
1436 spin_lock_irqsave(&ch->ch_lock, flags);
1438 /* No data to write to the UART */
1439 if (ch->ch_w_tail == ch->ch_w_head) {
1440 spin_unlock_irqrestore(&ch->ch_lock, flags);
1444 /* If port is "stopped", don't send any data to the UART */
1445 if ((ch->ch_flags & CH_FORCED_STOP) || (ch->ch_flags & CH_BREAK_SENDING)) {
1446 spin_unlock_irqrestore(&ch->ch_lock, flags);
1451 * If FIFOs are disabled. Send data directly to txrx register
1453 if (!(ch->ch_flags & CH_FIFO_ENABLED)) {
1454 unsigned char lsrbits = readb(&ch->ch_neo_uart->lsr);
1456 /* Cache the LSR bits for later parsing */
1457 ch->ch_cached_lsr |= lsrbits;
1458 if (ch->ch_cached_lsr & UART_LSR_THRE) {
1459 ch->ch_cached_lsr &= ~(UART_LSR_THRE);
1462 * If RTS Toggle mode is on, turn on RTS now if not already set,
1463 * and make sure we get an event when the data transfer has completed.
1465 if (ch->ch_digi.digi_flags & DIGI_RTS_TOGGLE) {
1466 if (!(ch->ch_mostat & UART_MCR_RTS)) {
1467 ch->ch_mostat |= (UART_MCR_RTS);
1468 neo_assert_modem_signals(ch);
1470 ch->ch_tun.un_flags |= (UN_EMPTY);
1473 * If DTR Toggle mode is on, turn on DTR now if not already set,
1474 * and make sure we get an event when the data transfer has completed.
1476 if (ch->ch_digi.digi_flags & DIGI_DTR_TOGGLE) {
1477 if (!(ch->ch_mostat & UART_MCR_DTR)) {
1478 ch->ch_mostat |= (UART_MCR_DTR);
1479 neo_assert_modem_signals(ch);
1481 ch->ch_tun.un_flags |= (UN_EMPTY);
1484 writeb(ch->ch_wqueue[ch->ch_w_tail], &ch->ch_neo_uart->txrx);
1486 ch->ch_w_tail &= WQUEUEMASK;
1489 spin_unlock_irqrestore(&ch->ch_lock, flags);
1494 * We have to do it this way, because of the EXAR TXFIFO count bug.
1496 if ((ch->ch_bd->dvid & 0xf0) < UART_XR17E158_DVID) {
1497 if (!(ch->ch_flags & (CH_TX_FIFO_EMPTY | CH_TX_FIFO_LWM))) {
1498 spin_unlock_irqrestore(&ch->ch_lock, flags);
1504 n = readb(&ch->ch_neo_uart->tfifo);
1506 if ((unsigned int) n > ch->ch_t_tlevel) {
1507 spin_unlock_irqrestore(&ch->ch_lock, flags);
1511 n = UART_17158_TX_FIFOSIZE - ch->ch_t_tlevel;
1513 n = UART_17158_TX_FIFOSIZE - readb(&ch->ch_neo_uart->tfifo);
1516 /* cache head and tail of queue */
1517 head = ch->ch_w_head & WQUEUEMASK;
1518 tail = ch->ch_w_tail & WQUEUEMASK;
1519 qlen = (head - tail) & WQUEUEMASK;
1521 /* Find minimum of the FIFO space, versus queue length */
1526 s = ((head >= tail) ? head : WQUEUESIZE) - tail;
1533 * If RTS Toggle mode is on, turn on RTS now if not already set,
1534 * and make sure we get an event when the data transfer has completed.
1536 if (ch->ch_digi.digi_flags & DIGI_RTS_TOGGLE) {
1537 if (!(ch->ch_mostat & UART_MCR_RTS)) {
1538 ch->ch_mostat |= (UART_MCR_RTS);
1539 neo_assert_modem_signals(ch);
1541 ch->ch_tun.un_flags |= (UN_EMPTY);
1545 * If DTR Toggle mode is on, turn on DTR now if not already set,
1546 * and make sure we get an event when the data transfer has completed.
1548 if (ch->ch_digi.digi_flags & DIGI_DTR_TOGGLE) {
1549 if (!(ch->ch_mostat & UART_MCR_DTR)) {
1550 ch->ch_mostat |= (UART_MCR_DTR);
1551 neo_assert_modem_signals(ch);
1553 ch->ch_tun.un_flags |= (UN_EMPTY);
1556 memcpy_toio(&ch->ch_neo_uart->txrxburst, ch->ch_wqueue + tail, s);
1558 /* Add and flip queue if needed */
1559 tail = (tail + s) & WQUEUEMASK;
1561 ch->ch_txcount += s;
1565 /* Update the final tail */
1566 ch->ch_w_tail = tail & WQUEUEMASK;
1568 if (len_written > 0) {
1569 neo_pci_posting_flush(ch->ch_bd);
1570 ch->ch_flags &= ~(CH_TX_FIFO_EMPTY | CH_TX_FIFO_LWM);
1573 spin_unlock_irqrestore(&ch->ch_lock, flags);
1577 static void neo_parse_modem(struct channel_t *ch, unsigned char signals)
1579 unsigned char msignals = signals;
1581 if (!ch || ch->magic != DGNC_CHANNEL_MAGIC)
1585 * Do altpin switching. Altpin switches DCD and DSR.
1586 * This prolly breaks DSRPACE, so we should be more clever here.
1588 if (ch->ch_digi.digi_flags & DIGI_ALTPIN) {
1589 unsigned char mswap = msignals;
1591 if (mswap & UART_MSR_DDCD) {
1592 msignals &= ~UART_MSR_DDCD;
1593 msignals |= UART_MSR_DDSR;
1595 if (mswap & UART_MSR_DDSR) {
1596 msignals &= ~UART_MSR_DDSR;
1597 msignals |= UART_MSR_DDCD;
1599 if (mswap & UART_MSR_DCD) {
1600 msignals &= ~UART_MSR_DCD;
1601 msignals |= UART_MSR_DSR;
1603 if (mswap & UART_MSR_DSR) {
1604 msignals &= ~UART_MSR_DSR;
1605 msignals |= UART_MSR_DCD;
1609 /* Scrub off lower bits. They signify delta's, which I don't care about */
1612 if (msignals & UART_MSR_DCD)
1613 ch->ch_mistat |= UART_MSR_DCD;
1615 ch->ch_mistat &= ~UART_MSR_DCD;
1617 if (msignals & UART_MSR_DSR)
1618 ch->ch_mistat |= UART_MSR_DSR;
1620 ch->ch_mistat &= ~UART_MSR_DSR;
1622 if (msignals & UART_MSR_RI)
1623 ch->ch_mistat |= UART_MSR_RI;
1625 ch->ch_mistat &= ~UART_MSR_RI;
1627 if (msignals & UART_MSR_CTS)
1628 ch->ch_mistat |= UART_MSR_CTS;
1630 ch->ch_mistat &= ~UART_MSR_CTS;
1634 /* Make the UART raise any of the output signals we want up */
1635 static void neo_assert_modem_signals(struct channel_t *ch)
1639 if (!ch || ch->magic != DGNC_CHANNEL_MAGIC)
1642 out = ch->ch_mostat;
1644 if (ch->ch_flags & CH_LOOPBACK)
1645 out |= UART_MCR_LOOP;
1647 writeb(out, &ch->ch_neo_uart->mcr);
1648 neo_pci_posting_flush(ch->ch_bd);
1650 /* Give time for the UART to actually raise/drop the signals */
1655 static void neo_send_start_character(struct channel_t *ch)
1657 if (!ch || ch->magic != DGNC_CHANNEL_MAGIC)
1660 if (ch->ch_startc != _POSIX_VDISABLE) {
1662 writeb(ch->ch_startc, &ch->ch_neo_uart->txrx);
1663 neo_pci_posting_flush(ch->ch_bd);
1669 static void neo_send_stop_character(struct channel_t *ch)
1671 if (!ch || ch->magic != DGNC_CHANNEL_MAGIC)
1674 if (ch->ch_stopc != _POSIX_VDISABLE) {
1675 ch->ch_xoff_sends++;
1676 writeb(ch->ch_stopc, &ch->ch_neo_uart->txrx);
1677 neo_pci_posting_flush(ch->ch_bd);
1686 static void neo_uart_init(struct channel_t *ch)
1689 writeb(0, &ch->ch_neo_uart->ier);
1690 writeb(0, &ch->ch_neo_uart->efr);
1691 writeb(UART_EFR_ECB, &ch->ch_neo_uart->efr);
1694 /* Clear out UART and FIFO */
1695 readb(&ch->ch_neo_uart->txrx);
1696 writeb((UART_FCR_ENABLE_FIFO|UART_FCR_CLEAR_RCVR|UART_FCR_CLEAR_XMIT), &ch->ch_neo_uart->isr_fcr);
1697 readb(&ch->ch_neo_uart->lsr);
1698 readb(&ch->ch_neo_uart->msr);
1700 ch->ch_flags |= CH_FIFO_ENABLED;
1702 /* Assert any signals we want up */
1703 writeb(ch->ch_mostat, &ch->ch_neo_uart->mcr);
1704 neo_pci_posting_flush(ch->ch_bd);
1709 * Make the UART completely turn off.
1711 static void neo_uart_off(struct channel_t *ch)
1713 /* Turn off UART enhanced bits */
1714 writeb(0, &ch->ch_neo_uart->efr);
1716 /* Stop all interrupts from occurring. */
1717 writeb(0, &ch->ch_neo_uart->ier);
1718 neo_pci_posting_flush(ch->ch_bd);
1722 static uint neo_get_uart_bytes_left(struct channel_t *ch)
1724 unsigned char left = 0;
1725 unsigned char lsr = readb(&ch->ch_neo_uart->lsr);
1727 /* We must cache the LSR as some of the bits get reset once read... */
1728 ch->ch_cached_lsr |= lsr;
1730 /* Determine whether the Transmitter is empty or not */
1731 if (!(lsr & UART_LSR_TEMT)) {
1732 if (ch->ch_flags & CH_TX_FIFO_EMPTY)
1733 tasklet_schedule(&ch->ch_bd->helper_tasklet);
1736 ch->ch_flags |= (CH_TX_FIFO_EMPTY | CH_TX_FIFO_LWM);
1744 /* Channel lock MUST be held by the calling function! */
1745 static void neo_send_break(struct channel_t *ch, int msecs)
1748 * If we receive a time of 0, this means turn off the break.
1751 if (ch->ch_flags & CH_BREAK_SENDING) {
1752 unsigned char temp = readb(&ch->ch_neo_uart->lcr);
1754 writeb((temp & ~UART_LCR_SBC), &ch->ch_neo_uart->lcr);
1755 neo_pci_posting_flush(ch->ch_bd);
1756 ch->ch_flags &= ~(CH_BREAK_SENDING);
1757 ch->ch_stop_sending_break = 0;
1763 * Set the time we should stop sending the break.
1764 * If we are already sending a break, toss away the existing
1765 * time to stop, and use this new value instead.
1767 ch->ch_stop_sending_break = jiffies + dgnc_jiffies_from_ms(msecs);
1769 /* Tell the UART to start sending the break */
1770 if (!(ch->ch_flags & CH_BREAK_SENDING)) {
1771 unsigned char temp = readb(&ch->ch_neo_uart->lcr);
1773 writeb((temp | UART_LCR_SBC), &ch->ch_neo_uart->lcr);
1774 neo_pci_posting_flush(ch->ch_bd);
1775 ch->ch_flags |= (CH_BREAK_SENDING);
1781 * neo_send_immediate_char.
1783 * Sends a specific character as soon as possible to the UART,
1784 * jumping over any bytes that might be in the write queue.
1786 * The channel lock MUST be held by the calling function.
1788 static void neo_send_immediate_char(struct channel_t *ch, unsigned char c)
1790 if (!ch || ch->magic != DGNC_CHANNEL_MAGIC)
1793 writeb(c, &ch->ch_neo_uart->txrx);
1794 neo_pci_posting_flush(ch->ch_bd);
1798 static unsigned int neo_read_eeprom(unsigned char __iomem *base, unsigned int address)
1800 unsigned int enable;
1802 unsigned int databit;
1805 /* enable chip select */
1806 writeb(NEO_EECS, base + NEO_EEREG);
1808 enable = (address | 0x180);
1810 for (bits = 9; bits--; ) {
1811 databit = (enable & (1 << bits)) ? NEO_EEDI : 0;
1812 /* Set read address */
1813 writeb(databit | NEO_EECS, base + NEO_EEREG);
1814 writeb(databit | NEO_EECS | NEO_EECK, base + NEO_EEREG);
1819 for (bits = 17; bits--; ) {
1820 /* clock to EEPROM */
1821 writeb(NEO_EECS, base + NEO_EEREG);
1822 writeb(NEO_EECS | NEO_EECK, base + NEO_EEREG);
1825 if (readb(base + NEO_EEREG) & NEO_EEDO)
1829 /* clock falling edge */
1830 writeb(NEO_EECS, base + NEO_EEREG);
1832 /* drop chip select */
1833 writeb(0x00, base + NEO_EEREG);
1839 static void neo_vpd(struct dgnc_board *brd)
1844 if (!brd || brd->magic != DGNC_BOARD_MAGIC)
1847 if (!brd->re_map_membase)
1850 /* Store the VPD into our buffer */
1851 for (i = 0; i < NEO_VPD_IMAGESIZE; i++) {
1852 a = neo_read_eeprom(brd->re_map_membase, i);
1853 brd->vpd[i*2] = a & 0xff;
1854 brd->vpd[(i*2)+1] = (a >> 8) & 0xff;
1857 if (((brd->vpd[0x08] != 0x82) /* long resource name tag */
1858 && (brd->vpd[0x10] != 0x82)) /* long resource name tag (PCI-66 files)*/
1859 || (brd->vpd[0x7F] != 0x78)) { /* small resource end tag */
1861 memset(brd->vpd, '\0', NEO_VPD_IMAGESIZE);
1863 /* Search for the serial number */
1864 for (i = 0; i < NEO_VPD_IMAGEBYTES - 3; i++)
1865 if (brd->vpd[i] == 'S' && brd->vpd[i + 1] == 'N')
1866 strncpy(brd->serial_num, &(brd->vpd[i + 3]), 9);