1 /************************************************************************
2 * Copyright 2003 Digi International (www.digi.com)
4 * Copyright (C) 2004 IBM Corporation. All rights reserved.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2, or (at your option)
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY, EXPRESS OR IMPLIED; without even the
13 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 * PURPOSE. See the GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 * Temple Place - Suite 330, Boston,
21 * Contact Information:
22 * Scott H Kilau <Scott_Kilau@digi.com>
23 * Wendy Xiong <wendyx@us.ibm.com>
25 ***********************************************************************/
26 #include <linux/delay.h> /* For udelay */
27 #include <linux/serial_reg.h> /* For the various UART offsets */
28 #include <linux/tty.h>
29 #include <linux/pci.h>
32 #include "jsm.h" /* Driver main header file */
34 static u32 jsm_offset_table
[8] = { 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80 };
37 * This function allows calls to ensure that all outstanding
38 * PCI writes have been completed, by doing a PCI read against
39 * a non-destructive, read-only location on the Neo card.
41 * In this case, we are reading the DVID (Read-only Device Identification)
42 * value of the Neo card.
44 static inline void neo_pci_posting_flush(struct jsm_board
*bd
)
46 readb(bd
->re_map_membase
+ 0x8D);
49 static void neo_set_cts_flow_control(struct jsm_channel
*ch
)
52 ier
= readb(&ch
->ch_neo_uart
->ier
);
53 efr
= readb(&ch
->ch_neo_uart
->efr
);
55 jsm_dbg(PARAM
, &ch
->ch_bd
->pci_dev
, "Setting CTSFLOW\n");
57 /* Turn on auto CTS flow control */
58 ier
|= (UART_17158_IER_CTSDSR
);
59 efr
|= (UART_17158_EFR_ECB
| UART_17158_EFR_CTSDSR
);
61 /* Turn off auto Xon flow control */
62 efr
&= ~(UART_17158_EFR_IXON
);
64 /* Why? Becuz Exar's spec says we have to zero it out before setting it */
65 writeb(0, &ch
->ch_neo_uart
->efr
);
67 /* Turn on UART enhanced bits */
68 writeb(efr
, &ch
->ch_neo_uart
->efr
);
70 /* Turn on table D, with 8 char hi/low watermarks */
71 writeb((UART_17158_FCTR_TRGD
| UART_17158_FCTR_RTS_4DELAY
), &ch
->ch_neo_uart
->fctr
);
73 /* Feed the UART our trigger levels */
74 writeb(8, &ch
->ch_neo_uart
->tfifo
);
77 writeb(ier
, &ch
->ch_neo_uart
->ier
);
80 static void neo_set_rts_flow_control(struct jsm_channel
*ch
)
83 ier
= readb(&ch
->ch_neo_uart
->ier
);
84 efr
= readb(&ch
->ch_neo_uart
->efr
);
86 jsm_dbg(PARAM
, &ch
->ch_bd
->pci_dev
, "Setting RTSFLOW\n");
88 /* Turn on auto RTS flow control */
89 ier
|= (UART_17158_IER_RTSDTR
);
90 efr
|= (UART_17158_EFR_ECB
| UART_17158_EFR_RTSDTR
);
92 /* Turn off auto Xoff flow control */
93 ier
&= ~(UART_17158_IER_XOFF
);
94 efr
&= ~(UART_17158_EFR_IXOFF
);
96 /* Why? Becuz Exar's spec says we have to zero it out before setting it */
97 writeb(0, &ch
->ch_neo_uart
->efr
);
99 /* Turn on UART enhanced bits */
100 writeb(efr
, &ch
->ch_neo_uart
->efr
);
102 writeb((UART_17158_FCTR_TRGD
| UART_17158_FCTR_RTS_4DELAY
), &ch
->ch_neo_uart
->fctr
);
103 ch
->ch_r_watermark
= 4;
105 writeb(56, &ch
->ch_neo_uart
->rfifo
);
106 ch
->ch_r_tlevel
= 56;
108 writeb(ier
, &ch
->ch_neo_uart
->ier
);
111 * From the Neo UART spec sheet:
112 * The auto RTS/DTR function must be started by asserting
113 * RTS/DTR# output pin (MCR bit-0 or 1 to logic 1 after
116 ch
->ch_mostat
|= (UART_MCR_RTS
);
120 static void neo_set_ixon_flow_control(struct jsm_channel
*ch
)
123 ier
= readb(&ch
->ch_neo_uart
->ier
);
124 efr
= readb(&ch
->ch_neo_uart
->efr
);
126 jsm_dbg(PARAM
, &ch
->ch_bd
->pci_dev
, "Setting IXON FLOW\n");
128 /* Turn off auto CTS flow control */
129 ier
&= ~(UART_17158_IER_CTSDSR
);
130 efr
&= ~(UART_17158_EFR_CTSDSR
);
132 /* Turn on auto Xon flow control */
133 efr
|= (UART_17158_EFR_ECB
| UART_17158_EFR_IXON
);
135 /* Why? Becuz Exar's spec says we have to zero it out before setting it */
136 writeb(0, &ch
->ch_neo_uart
->efr
);
138 /* Turn on UART enhanced bits */
139 writeb(efr
, &ch
->ch_neo_uart
->efr
);
141 writeb((UART_17158_FCTR_TRGD
| UART_17158_FCTR_RTS_8DELAY
), &ch
->ch_neo_uart
->fctr
);
142 ch
->ch_r_watermark
= 4;
144 writeb(32, &ch
->ch_neo_uart
->rfifo
);
145 ch
->ch_r_tlevel
= 32;
147 /* Tell UART what start/stop chars it should be looking for */
148 writeb(ch
->ch_startc
, &ch
->ch_neo_uart
->xonchar1
);
149 writeb(0, &ch
->ch_neo_uart
->xonchar2
);
151 writeb(ch
->ch_stopc
, &ch
->ch_neo_uart
->xoffchar1
);
152 writeb(0, &ch
->ch_neo_uart
->xoffchar2
);
154 writeb(ier
, &ch
->ch_neo_uart
->ier
);
157 static void neo_set_ixoff_flow_control(struct jsm_channel
*ch
)
160 ier
= readb(&ch
->ch_neo_uart
->ier
);
161 efr
= readb(&ch
->ch_neo_uart
->efr
);
163 jsm_dbg(PARAM
, &ch
->ch_bd
->pci_dev
, "Setting IXOFF FLOW\n");
165 /* Turn off auto RTS flow control */
166 ier
&= ~(UART_17158_IER_RTSDTR
);
167 efr
&= ~(UART_17158_EFR_RTSDTR
);
169 /* Turn on auto Xoff flow control */
170 ier
|= (UART_17158_IER_XOFF
);
171 efr
|= (UART_17158_EFR_ECB
| UART_17158_EFR_IXOFF
);
173 /* Why? Becuz Exar's spec says we have to zero it out before setting it */
174 writeb(0, &ch
->ch_neo_uart
->efr
);
176 /* Turn on UART enhanced bits */
177 writeb(efr
, &ch
->ch_neo_uart
->efr
);
179 /* Turn on table D, with 8 char hi/low watermarks */
180 writeb((UART_17158_FCTR_TRGD
| UART_17158_FCTR_RTS_8DELAY
), &ch
->ch_neo_uart
->fctr
);
182 writeb(8, &ch
->ch_neo_uart
->tfifo
);
185 /* Tell UART what start/stop chars it should be looking for */
186 writeb(ch
->ch_startc
, &ch
->ch_neo_uart
->xonchar1
);
187 writeb(0, &ch
->ch_neo_uart
->xonchar2
);
189 writeb(ch
->ch_stopc
, &ch
->ch_neo_uart
->xoffchar1
);
190 writeb(0, &ch
->ch_neo_uart
->xoffchar2
);
192 writeb(ier
, &ch
->ch_neo_uart
->ier
);
195 static void neo_set_no_input_flow_control(struct jsm_channel
*ch
)
198 ier
= readb(&ch
->ch_neo_uart
->ier
);
199 efr
= readb(&ch
->ch_neo_uart
->efr
);
201 jsm_dbg(PARAM
, &ch
->ch_bd
->pci_dev
, "Unsetting Input FLOW\n");
203 /* Turn off auto RTS flow control */
204 ier
&= ~(UART_17158_IER_RTSDTR
);
205 efr
&= ~(UART_17158_EFR_RTSDTR
);
207 /* Turn off auto Xoff flow control */
208 ier
&= ~(UART_17158_IER_XOFF
);
209 if (ch
->ch_c_iflag
& IXON
)
210 efr
&= ~(UART_17158_EFR_IXOFF
);
212 efr
&= ~(UART_17158_EFR_ECB
| UART_17158_EFR_IXOFF
);
214 /* Why? Becuz Exar's spec says we have to zero it out before setting it */
215 writeb(0, &ch
->ch_neo_uart
->efr
);
217 /* Turn on UART enhanced bits */
218 writeb(efr
, &ch
->ch_neo_uart
->efr
);
220 /* Turn on table D, with 8 char hi/low watermarks */
221 writeb((UART_17158_FCTR_TRGD
| UART_17158_FCTR_RTS_8DELAY
), &ch
->ch_neo_uart
->fctr
);
223 ch
->ch_r_watermark
= 0;
225 writeb(16, &ch
->ch_neo_uart
->tfifo
);
226 ch
->ch_t_tlevel
= 16;
228 writeb(16, &ch
->ch_neo_uart
->rfifo
);
229 ch
->ch_r_tlevel
= 16;
231 writeb(ier
, &ch
->ch_neo_uart
->ier
);
234 static void neo_set_no_output_flow_control(struct jsm_channel
*ch
)
237 ier
= readb(&ch
->ch_neo_uart
->ier
);
238 efr
= readb(&ch
->ch_neo_uart
->efr
);
240 jsm_dbg(PARAM
, &ch
->ch_bd
->pci_dev
, "Unsetting Output FLOW\n");
242 /* Turn off auto CTS flow control */
243 ier
&= ~(UART_17158_IER_CTSDSR
);
244 efr
&= ~(UART_17158_EFR_CTSDSR
);
246 /* Turn off auto Xon flow control */
247 if (ch
->ch_c_iflag
& IXOFF
)
248 efr
&= ~(UART_17158_EFR_IXON
);
250 efr
&= ~(UART_17158_EFR_ECB
| UART_17158_EFR_IXON
);
252 /* Why? Becuz Exar's spec says we have to zero it out before setting it */
253 writeb(0, &ch
->ch_neo_uart
->efr
);
255 /* Turn on UART enhanced bits */
256 writeb(efr
, &ch
->ch_neo_uart
->efr
);
258 /* Turn on table D, with 8 char hi/low watermarks */
259 writeb((UART_17158_FCTR_TRGD
| UART_17158_FCTR_RTS_8DELAY
), &ch
->ch_neo_uart
->fctr
);
261 ch
->ch_r_watermark
= 0;
263 writeb(16, &ch
->ch_neo_uart
->tfifo
);
264 ch
->ch_t_tlevel
= 16;
266 writeb(16, &ch
->ch_neo_uart
->rfifo
);
267 ch
->ch_r_tlevel
= 16;
269 writeb(ier
, &ch
->ch_neo_uart
->ier
);
272 static inline void neo_set_new_start_stop_chars(struct jsm_channel
*ch
)
275 /* if hardware flow control is set, then skip this whole thing */
276 if (ch
->ch_c_cflag
& CRTSCTS
)
279 jsm_dbg(PARAM
, &ch
->ch_bd
->pci_dev
, "start\n");
281 /* Tell UART what start/stop chars it should be looking for */
282 writeb(ch
->ch_startc
, &ch
->ch_neo_uart
->xonchar1
);
283 writeb(0, &ch
->ch_neo_uart
->xonchar2
);
285 writeb(ch
->ch_stopc
, &ch
->ch_neo_uart
->xoffchar1
);
286 writeb(0, &ch
->ch_neo_uart
->xoffchar2
);
289 static void neo_copy_data_from_uart_to_queue(struct jsm_channel
*ch
)
302 /* cache head and tail of queue */
303 head
= ch
->ch_r_head
& RQUEUEMASK
;
304 tail
= ch
->ch_r_tail
& RQUEUEMASK
;
306 /* Get our cached LSR */
307 linestatus
= ch
->ch_cached_lsr
;
308 ch
->ch_cached_lsr
= 0;
310 /* Store how much space we have left in the queue */
311 if ((qleft
= tail
- head
- 1) < 0)
312 qleft
+= RQUEUEMASK
+ 1;
315 * If the UART is not in FIFO mode, force the FIFO copy to
316 * NOT be run, by setting total to 0.
318 * On the other hand, if the UART IS in FIFO mode, then ask
319 * the UART to give us an approximation of data it has RX'ed.
321 if (!(ch
->ch_flags
& CH_FIFO_ENABLED
))
324 total
= readb(&ch
->ch_neo_uart
->rfifo
);
327 * EXAR chip bug - RX FIFO COUNT - Fudge factor.
329 * This resolves a problem/bug with the Exar chip that sometimes
330 * returns a bogus value in the rfifo register.
331 * The count can be any where from 0-3 bytes "off".
338 * Finally, bound the copy to make sure we don't overflow
340 * The byte by byte copy loop below this loop this will
341 * deal with the queue overflow possibility.
343 total
= min(total
, qleft
);
347 * Grab the linestatus register, we need to check
348 * to see if there are any errors in the FIFO.
350 linestatus
= readb(&ch
->ch_neo_uart
->lsr
);
353 * Break out if there is a FIFO error somewhere.
354 * This will allow us to go byte by byte down below,
355 * finding the exact location of the error.
357 if (linestatus
& UART_17158_RX_FIFO_DATA_ERROR
)
360 /* Make sure we don't go over the end of our queue */
361 n
= min(((u32
) total
), (RQUEUESIZE
- (u32
) head
));
364 * Cut down n even further if needed, this is to fix
365 * a problem with memcpy_fromio() with the Neo on the
366 * IBM pSeries platform.
367 * 15 bytes max appears to be the magic number.
369 n
= min((u32
) n
, (u32
) 12);
372 * Since we are grabbing the linestatus register, which
373 * will reset some bits after our read, we need to ensure
374 * we don't miss our TX FIFO emptys.
376 if (linestatus
& (UART_LSR_THRE
| UART_17158_TX_AND_FIFO_CLR
))
377 ch
->ch_flags
|= (CH_TX_FIFO_EMPTY
| CH_TX_FIFO_LWM
);
381 /* Copy data from uart to the queue */
382 memcpy_fromio(ch
->ch_rqueue
+ head
, &ch
->ch_neo_uart
->txrxburst
, n
);
384 * Since RX_FIFO_DATA_ERROR was 0, we are guaranteed
385 * that all the data currently in the FIFO is free of
386 * breaks and parity/frame/orun errors.
388 memset(ch
->ch_equeue
+ head
, 0, n
);
390 /* Add to and flip head if needed */
391 head
= (head
+ n
) & RQUEUEMASK
;
398 * Create a mask to determine whether we should
399 * insert the character (if any) into our queue.
401 if (ch
->ch_c_iflag
& IGNBRK
)
402 error_mask
|= UART_LSR_BI
;
405 * Now cleanup any leftover bytes still in the UART.
406 * Also deal with any possible queue overflow here as well.
411 * Its possible we have a linestatus from the loop above
412 * this, so we "OR" on any extra bits.
414 linestatus
|= readb(&ch
->ch_neo_uart
->lsr
);
417 * If the chip tells us there is no more data pending to
418 * be read, we can then leave.
419 * But before we do, cache the linestatus, just in case.
421 if (!(linestatus
& UART_LSR_DR
)) {
422 ch
->ch_cached_lsr
= linestatus
;
426 /* No need to store this bit */
427 linestatus
&= ~UART_LSR_DR
;
430 * Since we are grabbing the linestatus register, which
431 * will reset some bits after our read, we need to ensure
432 * we don't miss our TX FIFO emptys.
434 if (linestatus
& (UART_LSR_THRE
| UART_17158_TX_AND_FIFO_CLR
)) {
435 linestatus
&= ~(UART_LSR_THRE
| UART_17158_TX_AND_FIFO_CLR
);
436 ch
->ch_flags
|= (CH_TX_FIFO_EMPTY
| CH_TX_FIFO_LWM
);
440 * Discard character if we are ignoring the error mask.
442 if (linestatus
& error_mask
) {
445 memcpy_fromio(&discard
, &ch
->ch_neo_uart
->txrxburst
, 1);
450 * If our queue is full, we have no choice but to drop some data.
451 * The assumption is that HWFLOW or SWFLOW should have stopped
452 * things way way before we got to this point.
454 * I decided that I wanted to ditch the oldest data first,
455 * I hope thats okay with everyone? Yes? Good.
458 jsm_dbg(READ
, &ch
->ch_bd
->pci_dev
,
459 "Queue full, dropping DATA:%x LSR:%x\n",
460 ch
->ch_rqueue
[tail
], ch
->ch_equeue
[tail
]);
462 ch
->ch_r_tail
= tail
= (tail
+ 1) & RQUEUEMASK
;
463 ch
->ch_err_overrun
++;
467 memcpy_fromio(ch
->ch_rqueue
+ head
, &ch
->ch_neo_uart
->txrxburst
, 1);
468 ch
->ch_equeue
[head
] = (u8
) linestatus
;
470 jsm_dbg(READ
, &ch
->ch_bd
->pci_dev
, "DATA/LSR pair: %x %x\n",
471 ch
->ch_rqueue
[head
], ch
->ch_equeue
[head
]);
473 /* Ditch any remaining linestatus value. */
476 /* Add to and flip head if needed */
477 head
= (head
+ 1) & RQUEUEMASK
;
484 * Write new final heads to channel structure.
486 ch
->ch_r_head
= head
& RQUEUEMASK
;
487 ch
->ch_e_head
= head
& EQUEUEMASK
;
491 static void neo_copy_data_from_queue_to_uart(struct jsm_channel
*ch
)
499 struct circ_buf
*circ
;
504 circ
= &ch
->uart_port
.state
->xmit
;
506 /* No data to write to the UART */
507 if (uart_circ_empty(circ
))
510 /* If port is "stopped", don't send any data to the UART */
511 if ((ch
->ch_flags
& CH_STOP
) || (ch
->ch_flags
& CH_BREAK_SENDING
))
514 * If FIFOs are disabled. Send data directly to txrx register
516 if (!(ch
->ch_flags
& CH_FIFO_ENABLED
)) {
517 u8 lsrbits
= readb(&ch
->ch_neo_uart
->lsr
);
519 ch
->ch_cached_lsr
|= lsrbits
;
520 if (ch
->ch_cached_lsr
& UART_LSR_THRE
) {
521 ch
->ch_cached_lsr
&= ~(UART_LSR_THRE
);
523 writeb(circ
->buf
[circ
->tail
], &ch
->ch_neo_uart
->txrx
);
524 jsm_dbg(WRITE
, &ch
->ch_bd
->pci_dev
,
525 "Tx data: %x\n", circ
->buf
[circ
->tail
]);
526 circ
->tail
= (circ
->tail
+ 1) & (UART_XMIT_SIZE
- 1);
533 * We have to do it this way, because of the EXAR TXFIFO count bug.
535 if (!(ch
->ch_flags
& (CH_TX_FIFO_EMPTY
| CH_TX_FIFO_LWM
)))
538 n
= UART_17158_TX_FIFOSIZE
- ch
->ch_t_tlevel
;
540 /* cache head and tail of queue */
541 head
= circ
->head
& (UART_XMIT_SIZE
- 1);
542 tail
= circ
->tail
& (UART_XMIT_SIZE
- 1);
543 qlen
= uart_circ_chars_pending(circ
);
545 /* Find minimum of the FIFO space, versus queue length */
550 s
= ((head
>= tail
) ? head
: UART_XMIT_SIZE
) - tail
;
556 memcpy_toio(&ch
->ch_neo_uart
->txrxburst
, circ
->buf
+ tail
, s
);
557 /* Add and flip queue if needed */
558 tail
= (tail
+ s
) & (UART_XMIT_SIZE
- 1);
564 /* Update the final tail */
565 circ
->tail
= tail
& (UART_XMIT_SIZE
- 1);
567 if (len_written
>= ch
->ch_t_tlevel
)
568 ch
->ch_flags
&= ~(CH_TX_FIFO_EMPTY
| CH_TX_FIFO_LWM
);
570 if (uart_circ_empty(circ
))
571 uart_write_wakeup(&ch
->uart_port
);
574 static void neo_parse_modem(struct jsm_channel
*ch
, u8 signals
)
576 u8 msignals
= signals
;
578 jsm_dbg(MSIGS
, &ch
->ch_bd
->pci_dev
,
579 "neo_parse_modem: port: %d msignals: %x\n",
580 ch
->ch_portnum
, msignals
);
582 /* Scrub off lower bits. They signify delta's, which I don't care about */
583 /* Keep DDCD and DDSR though */
586 if (msignals
& UART_MSR_DDCD
)
587 uart_handle_dcd_change(&ch
->uart_port
, msignals
& UART_MSR_DCD
);
588 if (msignals
& UART_MSR_DDSR
)
589 uart_handle_cts_change(&ch
->uart_port
, msignals
& UART_MSR_CTS
);
590 if (msignals
& UART_MSR_DCD
)
591 ch
->ch_mistat
|= UART_MSR_DCD
;
593 ch
->ch_mistat
&= ~UART_MSR_DCD
;
595 if (msignals
& UART_MSR_DSR
)
596 ch
->ch_mistat
|= UART_MSR_DSR
;
598 ch
->ch_mistat
&= ~UART_MSR_DSR
;
600 if (msignals
& UART_MSR_RI
)
601 ch
->ch_mistat
|= UART_MSR_RI
;
603 ch
->ch_mistat
&= ~UART_MSR_RI
;
605 if (msignals
& UART_MSR_CTS
)
606 ch
->ch_mistat
|= UART_MSR_CTS
;
608 ch
->ch_mistat
&= ~UART_MSR_CTS
;
610 jsm_dbg(MSIGS
, &ch
->ch_bd
->pci_dev
,
611 "Port: %d DTR: %d RTS: %d CTS: %d DSR: %d " "RI: %d CD: %d\n",
613 !!((ch
->ch_mistat
| ch
->ch_mostat
) & UART_MCR_DTR
),
614 !!((ch
->ch_mistat
| ch
->ch_mostat
) & UART_MCR_RTS
),
615 !!((ch
->ch_mistat
| ch
->ch_mostat
) & UART_MSR_CTS
),
616 !!((ch
->ch_mistat
| ch
->ch_mostat
) & UART_MSR_DSR
),
617 !!((ch
->ch_mistat
| ch
->ch_mostat
) & UART_MSR_RI
),
618 !!((ch
->ch_mistat
| ch
->ch_mostat
) & UART_MSR_DCD
));
621 /* Make the UART raise any of the output signals we want up */
622 static void neo_assert_modem_signals(struct jsm_channel
*ch
)
627 writeb(ch
->ch_mostat
, &ch
->ch_neo_uart
->mcr
);
629 /* flush write operation */
630 neo_pci_posting_flush(ch
->ch_bd
);
634 * Flush the WRITE FIFO on the Neo.
636 * NOTE: Channel lock MUST be held before calling this function!
638 static void neo_flush_uart_write(struct jsm_channel
*ch
)
646 writeb((UART_FCR_ENABLE_FIFO
| UART_FCR_CLEAR_XMIT
), &ch
->ch_neo_uart
->isr_fcr
);
648 for (i
= 0; i
< 10; i
++) {
650 /* Check to see if the UART feels it completely flushed the FIFO. */
651 tmp
= readb(&ch
->ch_neo_uart
->isr_fcr
);
653 jsm_dbg(IOCTL
, &ch
->ch_bd
->pci_dev
,
654 "Still flushing TX UART... i: %d\n", i
);
661 ch
->ch_flags
|= (CH_TX_FIFO_EMPTY
| CH_TX_FIFO_LWM
);
666 * Flush the READ FIFO on the Neo.
668 * NOTE: Channel lock MUST be held before calling this function!
670 static void neo_flush_uart_read(struct jsm_channel
*ch
)
678 writeb((UART_FCR_ENABLE_FIFO
| UART_FCR_CLEAR_RCVR
), &ch
->ch_neo_uart
->isr_fcr
);
680 for (i
= 0; i
< 10; i
++) {
682 /* Check to see if the UART feels it completely flushed the FIFO. */
683 tmp
= readb(&ch
->ch_neo_uart
->isr_fcr
);
685 jsm_dbg(IOCTL
, &ch
->ch_bd
->pci_dev
,
686 "Still flushing RX UART... i: %d\n", i
);
695 * No locks are assumed to be held when calling this function.
697 static void neo_clear_break(struct jsm_channel
*ch
, int force
)
699 unsigned long lock_flags
;
701 spin_lock_irqsave(&ch
->ch_lock
, lock_flags
);
703 /* Turn break off, and unset some variables */
704 if (ch
->ch_flags
& CH_BREAK_SENDING
) {
705 u8 temp
= readb(&ch
->ch_neo_uart
->lcr
);
706 writeb((temp
& ~UART_LCR_SBC
), &ch
->ch_neo_uart
->lcr
);
708 ch
->ch_flags
&= ~(CH_BREAK_SENDING
);
709 jsm_dbg(IOCTL
, &ch
->ch_bd
->pci_dev
,
710 "clear break Finishing UART_LCR_SBC! finished: %lx\n",
713 /* flush write operation */
714 neo_pci_posting_flush(ch
->ch_bd
);
716 spin_unlock_irqrestore(&ch
->ch_lock
, lock_flags
);
720 * Parse the ISR register.
722 static inline void neo_parse_isr(struct jsm_board
*brd
, u32 port
)
724 struct jsm_channel
*ch
;
727 unsigned long lock_flags
;
732 if (port
> brd
->maxports
)
735 ch
= brd
->channels
[port
];
739 /* Here we try to figure out what caused the interrupt to happen */
742 isr
= readb(&ch
->ch_neo_uart
->isr_fcr
);
744 /* Bail if no pending interrupt */
745 if (isr
& UART_IIR_NO_INT
)
749 * Yank off the upper 2 bits, which just show that the FIFO's are enabled.
751 isr
&= ~(UART_17158_IIR_FIFO_ENABLED
);
753 jsm_dbg(INTR
, &ch
->ch_bd
->pci_dev
, "%s:%d isr: %x\n",
754 __FILE__
, __LINE__
, isr
);
756 if (isr
& (UART_17158_IIR_RDI_TIMEOUT
| UART_IIR_RDI
)) {
757 /* Read data from uart -> queue */
758 neo_copy_data_from_uart_to_queue(ch
);
760 /* Call our tty layer to enforce queue flow control if needed. */
761 spin_lock_irqsave(&ch
->ch_lock
, lock_flags
);
762 jsm_check_queue_flow_control(ch
);
763 spin_unlock_irqrestore(&ch
->ch_lock
, lock_flags
);
766 if (isr
& UART_IIR_THRI
) {
767 /* Transfer data (if any) from Write Queue -> UART. */
768 spin_lock_irqsave(&ch
->ch_lock
, lock_flags
);
769 ch
->ch_flags
|= (CH_TX_FIFO_EMPTY
| CH_TX_FIFO_LWM
);
770 spin_unlock_irqrestore(&ch
->ch_lock
, lock_flags
);
771 neo_copy_data_from_queue_to_uart(ch
);
774 if (isr
& UART_17158_IIR_XONXOFF
) {
775 cause
= readb(&ch
->ch_neo_uart
->xoffchar1
);
777 jsm_dbg(INTR
, &ch
->ch_bd
->pci_dev
,
778 "Port %d. Got ISR_XONXOFF: cause:%x\n",
782 * Since the UART detected either an XON or
783 * XOFF match, we need to figure out which
784 * one it was, so we can suspend or resume data flow.
786 spin_lock_irqsave(&ch
->ch_lock
, lock_flags
);
787 if (cause
== UART_17158_XON_DETECT
) {
788 /* Is output stopped right now, if so, resume it */
789 if (brd
->channels
[port
]->ch_flags
& CH_STOP
) {
790 ch
->ch_flags
&= ~(CH_STOP
);
792 jsm_dbg(INTR
, &ch
->ch_bd
->pci_dev
,
793 "Port %d. XON detected in incoming data\n",
796 else if (cause
== UART_17158_XOFF_DETECT
) {
797 if (!(brd
->channels
[port
]->ch_flags
& CH_STOP
)) {
798 ch
->ch_flags
|= CH_STOP
;
799 jsm_dbg(INTR
, &ch
->ch_bd
->pci_dev
,
800 "Setting CH_STOP\n");
802 jsm_dbg(INTR
, &ch
->ch_bd
->pci_dev
,
803 "Port: %d. XOFF detected in incoming data\n",
806 spin_unlock_irqrestore(&ch
->ch_lock
, lock_flags
);
809 if (isr
& UART_17158_IIR_HWFLOW_STATE_CHANGE
) {
811 * If we get here, this means the hardware is doing auto flow control.
812 * Check to see whether RTS/DTR or CTS/DSR caused this interrupt.
814 cause
= readb(&ch
->ch_neo_uart
->mcr
);
816 /* Which pin is doing auto flow? RTS or DTR? */
817 spin_lock_irqsave(&ch
->ch_lock
, lock_flags
);
818 if ((cause
& 0x4) == 0) {
819 if (cause
& UART_MCR_RTS
)
820 ch
->ch_mostat
|= UART_MCR_RTS
;
822 ch
->ch_mostat
&= ~(UART_MCR_RTS
);
824 if (cause
& UART_MCR_DTR
)
825 ch
->ch_mostat
|= UART_MCR_DTR
;
827 ch
->ch_mostat
&= ~(UART_MCR_DTR
);
829 spin_unlock_irqrestore(&ch
->ch_lock
, lock_flags
);
832 /* Parse any modem signal changes */
833 jsm_dbg(INTR
, &ch
->ch_bd
->pci_dev
,
834 "MOD_STAT: sending to parse_modem_sigs\n");
835 neo_parse_modem(ch
, readb(&ch
->ch_neo_uart
->msr
));
839 static inline void neo_parse_lsr(struct jsm_board
*brd
, u32 port
)
841 struct jsm_channel
*ch
;
843 unsigned long lock_flags
;
848 if (port
> brd
->maxports
)
851 ch
= brd
->channels
[port
];
855 linestatus
= readb(&ch
->ch_neo_uart
->lsr
);
857 jsm_dbg(INTR
, &ch
->ch_bd
->pci_dev
, "%s:%d port: %d linestatus: %x\n",
858 __FILE__
, __LINE__
, port
, linestatus
);
860 ch
->ch_cached_lsr
|= linestatus
;
862 if (ch
->ch_cached_lsr
& UART_LSR_DR
) {
863 /* Read data from uart -> queue */
864 neo_copy_data_from_uart_to_queue(ch
);
865 spin_lock_irqsave(&ch
->ch_lock
, lock_flags
);
866 jsm_check_queue_flow_control(ch
);
867 spin_unlock_irqrestore(&ch
->ch_lock
, lock_flags
);
871 * This is a special flag. It indicates that at least 1
872 * RX error (parity, framing, or break) has happened.
873 * Mark this in our struct, which will tell me that I have
874 *to do the special RX+LSR read for this FIFO load.
876 if (linestatus
& UART_17158_RX_FIFO_DATA_ERROR
)
877 jsm_dbg(INTR
, &ch
->ch_bd
->pci_dev
,
878 "%s:%d Port: %d Got an RX error, need to parse LSR\n",
879 __FILE__
, __LINE__
, port
);
882 * The next 3 tests should *NOT* happen, as the above test
883 * should encapsulate all 3... At least, thats what Exar says.
886 if (linestatus
& UART_LSR_PE
) {
888 jsm_dbg(INTR
, &ch
->ch_bd
->pci_dev
, "%s:%d Port: %d. PAR ERR!\n",
889 __FILE__
, __LINE__
, port
);
892 if (linestatus
& UART_LSR_FE
) {
894 jsm_dbg(INTR
, &ch
->ch_bd
->pci_dev
, "%s:%d Port: %d. FRM ERR!\n",
895 __FILE__
, __LINE__
, port
);
898 if (linestatus
& UART_LSR_BI
) {
900 jsm_dbg(INTR
, &ch
->ch_bd
->pci_dev
,
901 "%s:%d Port: %d. BRK INTR!\n",
902 __FILE__
, __LINE__
, port
);
905 if (linestatus
& UART_LSR_OE
) {
907 * Rx Oruns. Exar says that an orun will NOT corrupt
908 * the FIFO. It will just replace the holding register
909 * with this new data byte. So basically just ignore this.
910 * Probably we should eventually have an orun stat in our driver...
912 ch
->ch_err_overrun
++;
913 jsm_dbg(INTR
, &ch
->ch_bd
->pci_dev
,
914 "%s:%d Port: %d. Rx Overrun!\n",
915 __FILE__
, __LINE__
, port
);
918 if (linestatus
& UART_LSR_THRE
) {
919 spin_lock_irqsave(&ch
->ch_lock
, lock_flags
);
920 ch
->ch_flags
|= (CH_TX_FIFO_EMPTY
| CH_TX_FIFO_LWM
);
921 spin_unlock_irqrestore(&ch
->ch_lock
, lock_flags
);
923 /* Transfer data (if any) from Write Queue -> UART. */
924 neo_copy_data_from_queue_to_uart(ch
);
926 else if (linestatus
& UART_17158_TX_AND_FIFO_CLR
) {
927 spin_lock_irqsave(&ch
->ch_lock
, lock_flags
);
928 ch
->ch_flags
|= (CH_TX_FIFO_EMPTY
| CH_TX_FIFO_LWM
);
929 spin_unlock_irqrestore(&ch
->ch_lock
, lock_flags
);
931 /* Transfer data (if any) from Write Queue -> UART. */
932 neo_copy_data_from_queue_to_uart(ch
);
938 * Send any/all changes to the line to the UART.
940 static void neo_param(struct jsm_channel
*ch
)
946 struct jsm_board
*bd
;
953 * If baud rate is zero, flush queues, and set mval to drop DTR.
955 if ((ch
->ch_c_cflag
& (CBAUD
)) == 0) {
956 ch
->ch_r_head
= ch
->ch_r_tail
= 0;
957 ch
->ch_e_head
= ch
->ch_e_tail
= 0;
959 neo_flush_uart_write(ch
);
960 neo_flush_uart_read(ch
);
962 ch
->ch_flags
|= (CH_BAUD0
);
963 ch
->ch_mostat
&= ~(UART_MCR_RTS
| UART_MCR_DTR
);
964 neo_assert_modem_signals(ch
);
995 cflag
= C_BAUD(ch
->uart_port
.state
->port
.tty
);
997 for (i
= 0; i
< ARRAY_SIZE(baud_rates
); i
++) {
998 if (baud_rates
[i
].cflag
== cflag
) {
999 baud
= baud_rates
[i
].rate
;
1004 if (ch
->ch_flags
& CH_BAUD0
)
1005 ch
->ch_flags
&= ~(CH_BAUD0
);
1008 if (ch
->ch_c_cflag
& PARENB
)
1009 lcr
|= UART_LCR_PARITY
;
1011 if (!(ch
->ch_c_cflag
& PARODD
))
1012 lcr
|= UART_LCR_EPAR
;
1015 * Not all platforms support mark/space parity,
1016 * so this will hide behind an ifdef.
1019 if (ch
->ch_c_cflag
& CMSPAR
)
1020 lcr
|= UART_LCR_SPAR
;
1023 if (ch
->ch_c_cflag
& CSTOPB
)
1024 lcr
|= UART_LCR_STOP
;
1026 switch (ch
->ch_c_cflag
& CSIZE
) {
1028 lcr
|= UART_LCR_WLEN5
;
1031 lcr
|= UART_LCR_WLEN6
;
1034 lcr
|= UART_LCR_WLEN7
;
1038 lcr
|= UART_LCR_WLEN8
;
1042 ier
= readb(&ch
->ch_neo_uart
->ier
);
1043 uart_lcr
= readb(&ch
->ch_neo_uart
->lcr
);
1048 quot
= ch
->ch_bd
->bd_dividend
/ baud
;
1051 writeb(UART_LCR_DLAB
, &ch
->ch_neo_uart
->lcr
);
1052 writeb((quot
& 0xff), &ch
->ch_neo_uart
->txrx
);
1053 writeb((quot
>> 8), &ch
->ch_neo_uart
->ier
);
1054 writeb(lcr
, &ch
->ch_neo_uart
->lcr
);
1057 if (uart_lcr
!= lcr
)
1058 writeb(lcr
, &ch
->ch_neo_uart
->lcr
);
1060 if (ch
->ch_c_cflag
& CREAD
)
1061 ier
|= (UART_IER_RDI
| UART_IER_RLSI
);
1063 ier
|= (UART_IER_THRI
| UART_IER_MSI
);
1065 writeb(ier
, &ch
->ch_neo_uart
->ier
);
1067 /* Set new start/stop chars */
1068 neo_set_new_start_stop_chars(ch
);
1070 if (ch
->ch_c_cflag
& CRTSCTS
)
1071 neo_set_cts_flow_control(ch
);
1072 else if (ch
->ch_c_iflag
& IXON
) {
1073 /* If start/stop is set to disable, then we should disable flow control */
1074 if ((ch
->ch_startc
== __DISABLED_CHAR
) || (ch
->ch_stopc
== __DISABLED_CHAR
))
1075 neo_set_no_output_flow_control(ch
);
1077 neo_set_ixon_flow_control(ch
);
1080 neo_set_no_output_flow_control(ch
);
1082 if (ch
->ch_c_cflag
& CRTSCTS
)
1083 neo_set_rts_flow_control(ch
);
1084 else if (ch
->ch_c_iflag
& IXOFF
) {
1085 /* If start/stop is set to disable, then we should disable flow control */
1086 if ((ch
->ch_startc
== __DISABLED_CHAR
) || (ch
->ch_stopc
== __DISABLED_CHAR
))
1087 neo_set_no_input_flow_control(ch
);
1089 neo_set_ixoff_flow_control(ch
);
1092 neo_set_no_input_flow_control(ch
);
1094 * Adjust the RX FIFO Trigger level if baud is less than 9600.
1095 * Not exactly elegant, but this is needed because of the Exar chip's
1096 * delay on firing off the RX FIFO interrupt on slower baud rates.
1099 writeb(1, &ch
->ch_neo_uart
->rfifo
);
1100 ch
->ch_r_tlevel
= 1;
1103 neo_assert_modem_signals(ch
);
1105 /* Get current status of the modem signals now */
1106 neo_parse_modem(ch
, readb(&ch
->ch_neo_uart
->msr
));
1113 * Neo specific interrupt handler.
1115 static irqreturn_t
neo_intr(int irq
, void *voidbrd
)
1117 struct jsm_board
*brd
= voidbrd
;
1118 struct jsm_channel
*ch
;
1124 unsigned long lock_flags
;
1125 unsigned long lock_flags2
;
1126 int outofloop_count
= 0;
1128 /* Lock out the slow poller from running on this board. */
1129 spin_lock_irqsave(&brd
->bd_intr_lock
, lock_flags
);
1132 * Read in "extended" IRQ information from the 32bit Neo register.
1133 * Bits 0-7: What port triggered the interrupt.
1134 * Bits 8-31: Each 3bits indicate what type of interrupt occurred.
1136 uart_poll
= readl(brd
->re_map_membase
+ UART_17158_POLL_ADDR_OFFSET
);
1138 jsm_dbg(INTR
, &brd
->pci_dev
, "%s:%d uart_poll: %x\n",
1139 __FILE__
, __LINE__
, uart_poll
);
1142 jsm_dbg(INTR
, &brd
->pci_dev
,
1143 "Kernel interrupted to me, but no pending interrupts...\n");
1144 spin_unlock_irqrestore(&brd
->bd_intr_lock
, lock_flags
);
1148 /* At this point, we have at least SOMETHING to service, dig further... */
1152 /* Loop on each port */
1153 while (((uart_poll
& 0xff) != 0) && (outofloop_count
< 0xff)){
1158 /* Check current port to see if it has interrupt pending */
1159 if ((tmp
& jsm_offset_table
[current_port
]) != 0) {
1160 port
= current_port
;
1161 type
= tmp
>> (8 + (port
* 3));
1168 jsm_dbg(INTR
, &brd
->pci_dev
, "%s:%d port: %x type: %x\n",
1169 __FILE__
, __LINE__
, port
, type
);
1171 /* Remove this port + type from uart_poll */
1172 uart_poll
&= ~(jsm_offset_table
[port
]);
1175 /* If no type, just ignore it, and move onto next port */
1176 jsm_dbg(INTR
, &brd
->pci_dev
,
1177 "Interrupt with no type! port: %d\n", port
);
1181 /* Switch on type of interrupt we have */
1184 case UART_17158_RXRDY_TIMEOUT
:
1186 * RXRDY Time-out is cleared by reading data in the
1187 * RX FIFO until it falls below the trigger level.
1190 /* Verify the port is in range. */
1191 if (port
> brd
->nasync
)
1194 ch
= brd
->channels
[port
];
1195 neo_copy_data_from_uart_to_queue(ch
);
1197 /* Call our tty layer to enforce queue flow control if needed. */
1198 spin_lock_irqsave(&ch
->ch_lock
, lock_flags2
);
1199 jsm_check_queue_flow_control(ch
);
1200 spin_unlock_irqrestore(&ch
->ch_lock
, lock_flags2
);
1204 case UART_17158_RX_LINE_STATUS
:
1206 * RXRDY and RX LINE Status (logic OR of LSR[4:1])
1208 neo_parse_lsr(brd
, port
);
1211 case UART_17158_TXRDY
:
1213 * TXRDY interrupt clears after reading ISR register for the UART channel.
1217 * Yes, this is odd...
1218 * Why would I check EVERY possibility of type of
1219 * interrupt, when we know its TXRDY???
1220 * Becuz for some reason, even tho we got triggered for TXRDY,
1221 * it seems to be occasionally wrong. Instead of TX, which
1222 * it should be, I was getting things like RXDY too. Weird.
1224 neo_parse_isr(brd
, port
);
1227 case UART_17158_MSR
:
1229 * MSR or flow control was seen.
1231 neo_parse_isr(brd
, port
);
1236 * The UART triggered us with a bogus interrupt type.
1237 * It appears the Exar chip, when REALLY bogged down, will throw
1238 * these once and awhile.
1239 * Its harmless, just ignore it and move on.
1241 jsm_dbg(INTR
, &brd
->pci_dev
,
1242 "%s:%d Unknown Interrupt type: %x\n",
1243 __FILE__
, __LINE__
, type
);
1248 spin_unlock_irqrestore(&brd
->bd_intr_lock
, lock_flags
);
1250 jsm_dbg(INTR
, &brd
->pci_dev
, "finish\n");
1255 * Neo specific way of turning off the receiver.
1256 * Used as a way to enforce queue flow control when in
1257 * hardware flow control mode.
1259 static void neo_disable_receiver(struct jsm_channel
*ch
)
1261 u8 tmp
= readb(&ch
->ch_neo_uart
->ier
);
1262 tmp
&= ~(UART_IER_RDI
);
1263 writeb(tmp
, &ch
->ch_neo_uart
->ier
);
1265 /* flush write operation */
1266 neo_pci_posting_flush(ch
->ch_bd
);
1271 * Neo specific way of turning on the receiver.
1272 * Used as a way to un-enforce queue flow control when in
1273 * hardware flow control mode.
1275 static void neo_enable_receiver(struct jsm_channel
*ch
)
1277 u8 tmp
= readb(&ch
->ch_neo_uart
->ier
);
1278 tmp
|= (UART_IER_RDI
);
1279 writeb(tmp
, &ch
->ch_neo_uart
->ier
);
1281 /* flush write operation */
1282 neo_pci_posting_flush(ch
->ch_bd
);
1285 static void neo_send_start_character(struct jsm_channel
*ch
)
1290 if (ch
->ch_startc
!= __DISABLED_CHAR
) {
1292 writeb(ch
->ch_startc
, &ch
->ch_neo_uart
->txrx
);
1294 /* flush write operation */
1295 neo_pci_posting_flush(ch
->ch_bd
);
1299 static void neo_send_stop_character(struct jsm_channel
*ch
)
1304 if (ch
->ch_stopc
!= __DISABLED_CHAR
) {
1305 ch
->ch_xoff_sends
++;
1306 writeb(ch
->ch_stopc
, &ch
->ch_neo_uart
->txrx
);
1308 /* flush write operation */
1309 neo_pci_posting_flush(ch
->ch_bd
);
1316 static void neo_uart_init(struct jsm_channel
*ch
)
1318 writeb(0, &ch
->ch_neo_uart
->ier
);
1319 writeb(0, &ch
->ch_neo_uart
->efr
);
1320 writeb(UART_EFR_ECB
, &ch
->ch_neo_uart
->efr
);
1322 /* Clear out UART and FIFO */
1323 readb(&ch
->ch_neo_uart
->txrx
);
1324 writeb((UART_FCR_ENABLE_FIFO
|UART_FCR_CLEAR_RCVR
|UART_FCR_CLEAR_XMIT
), &ch
->ch_neo_uart
->isr_fcr
);
1325 readb(&ch
->ch_neo_uart
->lsr
);
1326 readb(&ch
->ch_neo_uart
->msr
);
1328 ch
->ch_flags
|= CH_FIFO_ENABLED
;
1330 /* Assert any signals we want up */
1331 writeb(ch
->ch_mostat
, &ch
->ch_neo_uart
->mcr
);
1335 * Make the UART completely turn off.
1337 static void neo_uart_off(struct jsm_channel
*ch
)
1339 /* Turn off UART enhanced bits */
1340 writeb(0, &ch
->ch_neo_uart
->efr
);
1342 /* Stop all interrupts from occurring. */
1343 writeb(0, &ch
->ch_neo_uart
->ier
);
1346 static u32
neo_get_uart_bytes_left(struct jsm_channel
*ch
)
1349 u8 lsr
= readb(&ch
->ch_neo_uart
->lsr
);
1351 /* We must cache the LSR as some of the bits get reset once read... */
1352 ch
->ch_cached_lsr
|= lsr
;
1354 /* Determine whether the Transmitter is empty or not */
1355 if (!(lsr
& UART_LSR_TEMT
))
1358 ch
->ch_flags
|= (CH_TX_FIFO_EMPTY
| CH_TX_FIFO_LWM
);
1365 /* Channel lock MUST be held by the calling function! */
1366 static void neo_send_break(struct jsm_channel
*ch
)
1369 * Set the time we should stop sending the break.
1370 * If we are already sending a break, toss away the existing
1371 * time to stop, and use this new value instead.
1374 /* Tell the UART to start sending the break */
1375 if (!(ch
->ch_flags
& CH_BREAK_SENDING
)) {
1376 u8 temp
= readb(&ch
->ch_neo_uart
->lcr
);
1377 writeb((temp
| UART_LCR_SBC
), &ch
->ch_neo_uart
->lcr
);
1378 ch
->ch_flags
|= (CH_BREAK_SENDING
);
1380 /* flush write operation */
1381 neo_pci_posting_flush(ch
->ch_bd
);
1386 * neo_send_immediate_char.
1388 * Sends a specific character as soon as possible to the UART,
1389 * jumping over any bytes that might be in the write queue.
1391 * The channel lock MUST be held by the calling function.
1393 static void neo_send_immediate_char(struct jsm_channel
*ch
, unsigned char c
)
1398 writeb(c
, &ch
->ch_neo_uart
->txrx
);
1400 /* flush write operation */
1401 neo_pci_posting_flush(ch
->ch_bd
);
1404 struct board_ops jsm_neo_ops
= {
1406 .uart_init
= neo_uart_init
,
1407 .uart_off
= neo_uart_off
,
1409 .assert_modem_signals
= neo_assert_modem_signals
,
1410 .flush_uart_write
= neo_flush_uart_write
,
1411 .flush_uart_read
= neo_flush_uart_read
,
1412 .disable_receiver
= neo_disable_receiver
,
1413 .enable_receiver
= neo_enable_receiver
,
1414 .send_break
= neo_send_break
,
1415 .clear_break
= neo_clear_break
,
1416 .send_start_character
= neo_send_start_character
,
1417 .send_stop_character
= neo_send_stop_character
,
1418 .copy_data_from_queue_to_uart
= neo_copy_data_from_queue_to_uart
,
1419 .get_uart_bytes_left
= neo_get_uart_bytes_left
,
1420 .send_immediate_char
= neo_send_immediate_char