1 // SPDX-License-Identifier: GPL-2.0+
2 /************************************************************************
3 * Copyright 2003 Digi International (www.digi.com)
5 * Copyright (C) 2004 IBM Corporation. All rights reserved.
8 * Scott H Kilau <Scott_Kilau@digi.com>
9 * Wendy Xiong <wendyx@us.ibm.com>
11 ***********************************************************************/
12 #include <linux/delay.h> /* For udelay */
13 #include <linux/serial_reg.h> /* For the various UART offsets */
14 #include <linux/tty.h>
15 #include <linux/pci.h>
18 #include "jsm.h" /* Driver main header file */
20 static u32 jsm_offset_table
[8] = { 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80 };
23 * This function allows calls to ensure that all outstanding
24 * PCI writes have been completed, by doing a PCI read against
25 * a non-destructive, read-only location on the Neo card.
27 * In this case, we are reading the DVID (Read-only Device Identification)
28 * value of the Neo card.
30 static inline void neo_pci_posting_flush(struct jsm_board
*bd
)
32 readb(bd
->re_map_membase
+ 0x8D);
35 static void neo_set_cts_flow_control(struct jsm_channel
*ch
)
38 ier
= readb(&ch
->ch_neo_uart
->ier
);
39 efr
= readb(&ch
->ch_neo_uart
->efr
);
41 jsm_dbg(PARAM
, &ch
->ch_bd
->pci_dev
, "Setting CTSFLOW\n");
43 /* Turn on auto CTS flow control */
44 ier
|= (UART_17158_IER_CTSDSR
);
45 efr
|= (UART_17158_EFR_ECB
| UART_17158_EFR_CTSDSR
);
47 /* Turn off auto Xon flow control */
48 efr
&= ~(UART_17158_EFR_IXON
);
50 /* Why? Becuz Exar's spec says we have to zero it out before setting it */
51 writeb(0, &ch
->ch_neo_uart
->efr
);
53 /* Turn on UART enhanced bits */
54 writeb(efr
, &ch
->ch_neo_uart
->efr
);
56 /* Turn on table D, with 8 char hi/low watermarks */
57 writeb((UART_17158_FCTR_TRGD
| UART_17158_FCTR_RTS_4DELAY
), &ch
->ch_neo_uart
->fctr
);
59 /* Feed the UART our trigger levels */
60 writeb(8, &ch
->ch_neo_uart
->tfifo
);
63 writeb(ier
, &ch
->ch_neo_uart
->ier
);
66 static void neo_set_rts_flow_control(struct jsm_channel
*ch
)
69 ier
= readb(&ch
->ch_neo_uart
->ier
);
70 efr
= readb(&ch
->ch_neo_uart
->efr
);
72 jsm_dbg(PARAM
, &ch
->ch_bd
->pci_dev
, "Setting RTSFLOW\n");
74 /* Turn on auto RTS flow control */
75 ier
|= (UART_17158_IER_RTSDTR
);
76 efr
|= (UART_17158_EFR_ECB
| UART_17158_EFR_RTSDTR
);
78 /* Turn off auto Xoff flow control */
79 ier
&= ~(UART_17158_IER_XOFF
);
80 efr
&= ~(UART_17158_EFR_IXOFF
);
82 /* Why? Becuz Exar's spec says we have to zero it out before setting it */
83 writeb(0, &ch
->ch_neo_uart
->efr
);
85 /* Turn on UART enhanced bits */
86 writeb(efr
, &ch
->ch_neo_uart
->efr
);
88 writeb((UART_17158_FCTR_TRGD
| UART_17158_FCTR_RTS_4DELAY
), &ch
->ch_neo_uart
->fctr
);
89 ch
->ch_r_watermark
= 4;
91 writeb(56, &ch
->ch_neo_uart
->rfifo
);
94 writeb(ier
, &ch
->ch_neo_uart
->ier
);
97 * From the Neo UART spec sheet:
98 * The auto RTS/DTR function must be started by asserting
99 * RTS/DTR# output pin (MCR bit-0 or 1 to logic 1 after
102 ch
->ch_mostat
|= (UART_MCR_RTS
);
106 static void neo_set_ixon_flow_control(struct jsm_channel
*ch
)
109 ier
= readb(&ch
->ch_neo_uart
->ier
);
110 efr
= readb(&ch
->ch_neo_uart
->efr
);
112 jsm_dbg(PARAM
, &ch
->ch_bd
->pci_dev
, "Setting IXON FLOW\n");
114 /* Turn off auto CTS flow control */
115 ier
&= ~(UART_17158_IER_CTSDSR
);
116 efr
&= ~(UART_17158_EFR_CTSDSR
);
118 /* Turn on auto Xon flow control */
119 efr
|= (UART_17158_EFR_ECB
| UART_17158_EFR_IXON
);
121 /* Why? Becuz Exar's spec says we have to zero it out before setting it */
122 writeb(0, &ch
->ch_neo_uart
->efr
);
124 /* Turn on UART enhanced bits */
125 writeb(efr
, &ch
->ch_neo_uart
->efr
);
127 writeb((UART_17158_FCTR_TRGD
| UART_17158_FCTR_RTS_8DELAY
), &ch
->ch_neo_uart
->fctr
);
128 ch
->ch_r_watermark
= 4;
130 writeb(32, &ch
->ch_neo_uart
->rfifo
);
131 ch
->ch_r_tlevel
= 32;
133 /* Tell UART what start/stop chars it should be looking for */
134 writeb(ch
->ch_startc
, &ch
->ch_neo_uart
->xonchar1
);
135 writeb(0, &ch
->ch_neo_uart
->xonchar2
);
137 writeb(ch
->ch_stopc
, &ch
->ch_neo_uart
->xoffchar1
);
138 writeb(0, &ch
->ch_neo_uart
->xoffchar2
);
140 writeb(ier
, &ch
->ch_neo_uart
->ier
);
143 static void neo_set_ixoff_flow_control(struct jsm_channel
*ch
)
146 ier
= readb(&ch
->ch_neo_uart
->ier
);
147 efr
= readb(&ch
->ch_neo_uart
->efr
);
149 jsm_dbg(PARAM
, &ch
->ch_bd
->pci_dev
, "Setting IXOFF FLOW\n");
151 /* Turn off auto RTS flow control */
152 ier
&= ~(UART_17158_IER_RTSDTR
);
153 efr
&= ~(UART_17158_EFR_RTSDTR
);
155 /* Turn on auto Xoff flow control */
156 ier
|= (UART_17158_IER_XOFF
);
157 efr
|= (UART_17158_EFR_ECB
| UART_17158_EFR_IXOFF
);
159 /* Why? Becuz Exar's spec says we have to zero it out before setting it */
160 writeb(0, &ch
->ch_neo_uart
->efr
);
162 /* Turn on UART enhanced bits */
163 writeb(efr
, &ch
->ch_neo_uart
->efr
);
165 /* Turn on table D, with 8 char hi/low watermarks */
166 writeb((UART_17158_FCTR_TRGD
| UART_17158_FCTR_RTS_8DELAY
), &ch
->ch_neo_uart
->fctr
);
168 writeb(8, &ch
->ch_neo_uart
->tfifo
);
171 /* Tell UART what start/stop chars it should be looking for */
172 writeb(ch
->ch_startc
, &ch
->ch_neo_uart
->xonchar1
);
173 writeb(0, &ch
->ch_neo_uart
->xonchar2
);
175 writeb(ch
->ch_stopc
, &ch
->ch_neo_uart
->xoffchar1
);
176 writeb(0, &ch
->ch_neo_uart
->xoffchar2
);
178 writeb(ier
, &ch
->ch_neo_uart
->ier
);
181 static void neo_set_no_input_flow_control(struct jsm_channel
*ch
)
184 ier
= readb(&ch
->ch_neo_uart
->ier
);
185 efr
= readb(&ch
->ch_neo_uart
->efr
);
187 jsm_dbg(PARAM
, &ch
->ch_bd
->pci_dev
, "Unsetting Input FLOW\n");
189 /* Turn off auto RTS flow control */
190 ier
&= ~(UART_17158_IER_RTSDTR
);
191 efr
&= ~(UART_17158_EFR_RTSDTR
);
193 /* Turn off auto Xoff flow control */
194 ier
&= ~(UART_17158_IER_XOFF
);
195 if (ch
->ch_c_iflag
& IXON
)
196 efr
&= ~(UART_17158_EFR_IXOFF
);
198 efr
&= ~(UART_17158_EFR_ECB
| UART_17158_EFR_IXOFF
);
200 /* Why? Becuz Exar's spec says we have to zero it out before setting it */
201 writeb(0, &ch
->ch_neo_uart
->efr
);
203 /* Turn on UART enhanced bits */
204 writeb(efr
, &ch
->ch_neo_uart
->efr
);
206 /* Turn on table D, with 8 char hi/low watermarks */
207 writeb((UART_17158_FCTR_TRGD
| UART_17158_FCTR_RTS_8DELAY
), &ch
->ch_neo_uart
->fctr
);
209 ch
->ch_r_watermark
= 0;
211 writeb(16, &ch
->ch_neo_uart
->tfifo
);
212 ch
->ch_t_tlevel
= 16;
214 writeb(16, &ch
->ch_neo_uart
->rfifo
);
215 ch
->ch_r_tlevel
= 16;
217 writeb(ier
, &ch
->ch_neo_uart
->ier
);
220 static void neo_set_no_output_flow_control(struct jsm_channel
*ch
)
223 ier
= readb(&ch
->ch_neo_uart
->ier
);
224 efr
= readb(&ch
->ch_neo_uart
->efr
);
226 jsm_dbg(PARAM
, &ch
->ch_bd
->pci_dev
, "Unsetting Output FLOW\n");
228 /* Turn off auto CTS flow control */
229 ier
&= ~(UART_17158_IER_CTSDSR
);
230 efr
&= ~(UART_17158_EFR_CTSDSR
);
232 /* Turn off auto Xon flow control */
233 if (ch
->ch_c_iflag
& IXOFF
)
234 efr
&= ~(UART_17158_EFR_IXON
);
236 efr
&= ~(UART_17158_EFR_ECB
| UART_17158_EFR_IXON
);
238 /* Why? Becuz Exar's spec says we have to zero it out before setting it */
239 writeb(0, &ch
->ch_neo_uart
->efr
);
241 /* Turn on UART enhanced bits */
242 writeb(efr
, &ch
->ch_neo_uart
->efr
);
244 /* Turn on table D, with 8 char hi/low watermarks */
245 writeb((UART_17158_FCTR_TRGD
| UART_17158_FCTR_RTS_8DELAY
), &ch
->ch_neo_uart
->fctr
);
247 ch
->ch_r_watermark
= 0;
249 writeb(16, &ch
->ch_neo_uart
->tfifo
);
250 ch
->ch_t_tlevel
= 16;
252 writeb(16, &ch
->ch_neo_uart
->rfifo
);
253 ch
->ch_r_tlevel
= 16;
255 writeb(ier
, &ch
->ch_neo_uart
->ier
);
258 static inline void neo_set_new_start_stop_chars(struct jsm_channel
*ch
)
261 /* if hardware flow control is set, then skip this whole thing */
262 if (ch
->ch_c_cflag
& CRTSCTS
)
265 jsm_dbg(PARAM
, &ch
->ch_bd
->pci_dev
, "start\n");
267 /* Tell UART what start/stop chars it should be looking for */
268 writeb(ch
->ch_startc
, &ch
->ch_neo_uart
->xonchar1
);
269 writeb(0, &ch
->ch_neo_uart
->xonchar2
);
271 writeb(ch
->ch_stopc
, &ch
->ch_neo_uart
->xoffchar1
);
272 writeb(0, &ch
->ch_neo_uart
->xoffchar2
);
275 static void neo_copy_data_from_uart_to_queue(struct jsm_channel
*ch
)
285 /* cache head and tail of queue */
286 head
= ch
->ch_r_head
& RQUEUEMASK
;
287 tail
= ch
->ch_r_tail
& RQUEUEMASK
;
289 /* Get our cached LSR */
290 linestatus
= ch
->ch_cached_lsr
;
291 ch
->ch_cached_lsr
= 0;
293 /* Store how much space we have left in the queue */
294 qleft
= tail
- head
- 1;
296 qleft
+= RQUEUEMASK
+ 1;
299 * If the UART is not in FIFO mode, force the FIFO copy to
300 * NOT be run, by setting total to 0.
302 * On the other hand, if the UART IS in FIFO mode, then ask
303 * the UART to give us an approximation of data it has RX'ed.
305 if (!(ch
->ch_flags
& CH_FIFO_ENABLED
))
308 total
= readb(&ch
->ch_neo_uart
->rfifo
);
311 * EXAR chip bug - RX FIFO COUNT - Fudge factor.
313 * This resolves a problem/bug with the Exar chip that sometimes
314 * returns a bogus value in the rfifo register.
315 * The count can be any where from 0-3 bytes "off".
322 * Finally, bound the copy to make sure we don't overflow
324 * The byte by byte copy loop below this loop this will
325 * deal with the queue overflow possibility.
327 total
= min(total
, qleft
);
331 * Grab the linestatus register, we need to check
332 * to see if there are any errors in the FIFO.
334 linestatus
= readb(&ch
->ch_neo_uart
->lsr
);
337 * Break out if there is a FIFO error somewhere.
338 * This will allow us to go byte by byte down below,
339 * finding the exact location of the error.
341 if (linestatus
& UART_17158_RX_FIFO_DATA_ERROR
)
344 /* Make sure we don't go over the end of our queue */
345 n
= min(((u32
) total
), (RQUEUESIZE
- (u32
) head
));
348 * Cut down n even further if needed, this is to fix
349 * a problem with memcpy_fromio() with the Neo on the
350 * IBM pSeries platform.
351 * 15 bytes max appears to be the magic number.
353 n
= min((u32
) n
, (u32
) 12);
356 * Since we are grabbing the linestatus register, which
357 * will reset some bits after our read, we need to ensure
358 * we don't miss our TX FIFO emptys.
360 if (linestatus
& (UART_LSR_THRE
| UART_17158_TX_AND_FIFO_CLR
))
361 ch
->ch_flags
|= (CH_TX_FIFO_EMPTY
| CH_TX_FIFO_LWM
);
365 /* Copy data from uart to the queue */
366 memcpy_fromio(ch
->ch_rqueue
+ head
, &ch
->ch_neo_uart
->txrxburst
, n
);
368 * Since RX_FIFO_DATA_ERROR was 0, we are guaranteed
369 * that all the data currently in the FIFO is free of
370 * breaks and parity/frame/orun errors.
372 memset(ch
->ch_equeue
+ head
, 0, n
);
374 /* Add to and flip head if needed */
375 head
= (head
+ n
) & RQUEUEMASK
;
382 * Create a mask to determine whether we should
383 * insert the character (if any) into our queue.
385 if (ch
->ch_c_iflag
& IGNBRK
)
386 error_mask
|= UART_LSR_BI
;
389 * Now cleanup any leftover bytes still in the UART.
390 * Also deal with any possible queue overflow here as well.
395 * Its possible we have a linestatus from the loop above
396 * this, so we "OR" on any extra bits.
398 linestatus
|= readb(&ch
->ch_neo_uart
->lsr
);
401 * If the chip tells us there is no more data pending to
402 * be read, we can then leave.
403 * But before we do, cache the linestatus, just in case.
405 if (!(linestatus
& UART_LSR_DR
)) {
406 ch
->ch_cached_lsr
= linestatus
;
410 /* No need to store this bit */
411 linestatus
&= ~UART_LSR_DR
;
414 * Since we are grabbing the linestatus register, which
415 * will reset some bits after our read, we need to ensure
416 * we don't miss our TX FIFO emptys.
418 if (linestatus
& (UART_LSR_THRE
| UART_17158_TX_AND_FIFO_CLR
)) {
419 linestatus
&= ~(UART_LSR_THRE
| UART_17158_TX_AND_FIFO_CLR
);
420 ch
->ch_flags
|= (CH_TX_FIFO_EMPTY
| CH_TX_FIFO_LWM
);
424 * Discard character if we are ignoring the error mask.
426 if (linestatus
& error_mask
) {
429 memcpy_fromio(&discard
, &ch
->ch_neo_uart
->txrxburst
, 1);
434 * If our queue is full, we have no choice but to drop some data.
435 * The assumption is that HWFLOW or SWFLOW should have stopped
436 * things way way before we got to this point.
438 * I decided that I wanted to ditch the oldest data first,
439 * I hope thats okay with everyone? Yes? Good.
442 jsm_dbg(READ
, &ch
->ch_bd
->pci_dev
,
443 "Queue full, dropping DATA:%x LSR:%x\n",
444 ch
->ch_rqueue
[tail
], ch
->ch_equeue
[tail
]);
446 ch
->ch_r_tail
= tail
= (tail
+ 1) & RQUEUEMASK
;
447 ch
->ch_err_overrun
++;
451 memcpy_fromio(ch
->ch_rqueue
+ head
, &ch
->ch_neo_uart
->txrxburst
, 1);
452 ch
->ch_equeue
[head
] = (u8
) linestatus
;
454 jsm_dbg(READ
, &ch
->ch_bd
->pci_dev
, "DATA/LSR pair: %x %x\n",
455 ch
->ch_rqueue
[head
], ch
->ch_equeue
[head
]);
457 /* Ditch any remaining linestatus value. */
460 /* Add to and flip head if needed */
461 head
= (head
+ 1) & RQUEUEMASK
;
468 * Write new final heads to channel structure.
470 ch
->ch_r_head
= head
& RQUEUEMASK
;
471 ch
->ch_e_head
= head
& EQUEUEMASK
;
475 static void neo_copy_data_from_queue_to_uart(struct jsm_channel
*ch
)
477 struct tty_port
*tport
;
488 tport
= &ch
->uart_port
.state
->port
;
490 /* No data to write to the UART */
491 if (kfifo_is_empty(&tport
->xmit_fifo
))
494 /* If port is "stopped", don't send any data to the UART */
495 if ((ch
->ch_flags
& CH_STOP
) || (ch
->ch_flags
& CH_BREAK_SENDING
))
498 * If FIFOs are disabled. Send data directly to txrx register
500 if (!(ch
->ch_flags
& CH_FIFO_ENABLED
)) {
501 u8 lsrbits
= readb(&ch
->ch_neo_uart
->lsr
);
503 ch
->ch_cached_lsr
|= lsrbits
;
504 if (ch
->ch_cached_lsr
& UART_LSR_THRE
) {
505 ch
->ch_cached_lsr
&= ~(UART_LSR_THRE
);
507 WARN_ON_ONCE(!kfifo_get(&tport
->xmit_fifo
, &c
));
508 writeb(c
, &ch
->ch_neo_uart
->txrx
);
509 jsm_dbg(WRITE
, &ch
->ch_bd
->pci_dev
, "Tx data: %x\n", c
);
516 * We have to do it this way, because of the EXAR TXFIFO count bug.
518 if (!(ch
->ch_flags
& (CH_TX_FIFO_EMPTY
| CH_TX_FIFO_LWM
)))
521 n
= UART_17158_TX_FIFOSIZE
- ch
->ch_t_tlevel
;
522 qlen
= kfifo_len(&tport
->xmit_fifo
);
524 /* Find minimum of the FIFO space, versus queue length */
528 s
= kfifo_out_linear_ptr(&tport
->xmit_fifo
, &tail
, n
);
532 memcpy_toio(&ch
->ch_neo_uart
->txrxburst
, tail
, s
);
533 kfifo_skip_count(&tport
->xmit_fifo
, s
);
539 if (len_written
>= ch
->ch_t_tlevel
)
540 ch
->ch_flags
&= ~(CH_TX_FIFO_EMPTY
| CH_TX_FIFO_LWM
);
542 if (kfifo_is_empty(&tport
->xmit_fifo
))
543 uart_write_wakeup(&ch
->uart_port
);
546 static void neo_parse_modem(struct jsm_channel
*ch
, u8 signals
)
548 u8 msignals
= signals
;
550 jsm_dbg(MSIGS
, &ch
->ch_bd
->pci_dev
,
551 "neo_parse_modem: port: %d msignals: %x\n",
552 ch
->ch_portnum
, msignals
);
554 /* Scrub off lower bits. They signify delta's, which I don't care about */
555 /* Keep DDCD and DDSR though */
558 if (msignals
& UART_MSR_DDCD
)
559 uart_handle_dcd_change(&ch
->uart_port
, msignals
& UART_MSR_DCD
);
560 if (msignals
& UART_MSR_DDSR
)
561 uart_handle_cts_change(&ch
->uart_port
, msignals
& UART_MSR_CTS
);
562 if (msignals
& UART_MSR_DCD
)
563 ch
->ch_mistat
|= UART_MSR_DCD
;
565 ch
->ch_mistat
&= ~UART_MSR_DCD
;
567 if (msignals
& UART_MSR_DSR
)
568 ch
->ch_mistat
|= UART_MSR_DSR
;
570 ch
->ch_mistat
&= ~UART_MSR_DSR
;
572 if (msignals
& UART_MSR_RI
)
573 ch
->ch_mistat
|= UART_MSR_RI
;
575 ch
->ch_mistat
&= ~UART_MSR_RI
;
577 if (msignals
& UART_MSR_CTS
)
578 ch
->ch_mistat
|= UART_MSR_CTS
;
580 ch
->ch_mistat
&= ~UART_MSR_CTS
;
582 jsm_dbg(MSIGS
, &ch
->ch_bd
->pci_dev
,
583 "Port: %d DTR: %d RTS: %d CTS: %d DSR: %d " "RI: %d CD: %d\n",
585 !!((ch
->ch_mistat
| ch
->ch_mostat
) & UART_MCR_DTR
),
586 !!((ch
->ch_mistat
| ch
->ch_mostat
) & UART_MCR_RTS
),
587 !!((ch
->ch_mistat
| ch
->ch_mostat
) & UART_MSR_CTS
),
588 !!((ch
->ch_mistat
| ch
->ch_mostat
) & UART_MSR_DSR
),
589 !!((ch
->ch_mistat
| ch
->ch_mostat
) & UART_MSR_RI
),
590 !!((ch
->ch_mistat
| ch
->ch_mostat
) & UART_MSR_DCD
));
593 /* Make the UART raise any of the output signals we want up */
594 static void neo_assert_modem_signals(struct jsm_channel
*ch
)
599 writeb(ch
->ch_mostat
, &ch
->ch_neo_uart
->mcr
);
601 /* flush write operation */
602 neo_pci_posting_flush(ch
->ch_bd
);
606 * Flush the WRITE FIFO on the Neo.
608 * NOTE: Channel lock MUST be held before calling this function!
610 static void neo_flush_uart_write(struct jsm_channel
*ch
)
618 writeb((UART_FCR_ENABLE_FIFO
| UART_FCR_CLEAR_XMIT
), &ch
->ch_neo_uart
->isr_fcr
);
620 for (i
= 0; i
< 10; i
++) {
622 /* Check to see if the UART feels it completely flushed the FIFO. */
623 tmp
= readb(&ch
->ch_neo_uart
->isr_fcr
);
624 if (tmp
& UART_FCR_CLEAR_XMIT
) {
625 jsm_dbg(IOCTL
, &ch
->ch_bd
->pci_dev
,
626 "Still flushing TX UART... i: %d\n", i
);
633 ch
->ch_flags
|= (CH_TX_FIFO_EMPTY
| CH_TX_FIFO_LWM
);
638 * Flush the READ FIFO on the Neo.
640 * NOTE: Channel lock MUST be held before calling this function!
642 static void neo_flush_uart_read(struct jsm_channel
*ch
)
650 writeb((UART_FCR_ENABLE_FIFO
| UART_FCR_CLEAR_RCVR
), &ch
->ch_neo_uart
->isr_fcr
);
652 for (i
= 0; i
< 10; i
++) {
654 /* Check to see if the UART feels it completely flushed the FIFO. */
655 tmp
= readb(&ch
->ch_neo_uart
->isr_fcr
);
657 jsm_dbg(IOCTL
, &ch
->ch_bd
->pci_dev
,
658 "Still flushing RX UART... i: %d\n", i
);
667 * No locks are assumed to be held when calling this function.
669 static void neo_clear_break(struct jsm_channel
*ch
)
671 unsigned long lock_flags
;
673 spin_lock_irqsave(&ch
->ch_lock
, lock_flags
);
675 /* Turn break off, and unset some variables */
676 if (ch
->ch_flags
& CH_BREAK_SENDING
) {
677 u8 temp
= readb(&ch
->ch_neo_uart
->lcr
);
678 writeb((temp
& ~UART_LCR_SBC
), &ch
->ch_neo_uart
->lcr
);
680 ch
->ch_flags
&= ~(CH_BREAK_SENDING
);
681 jsm_dbg(IOCTL
, &ch
->ch_bd
->pci_dev
,
682 "clear break Finishing UART_LCR_SBC! finished: %lx\n",
685 /* flush write operation */
686 neo_pci_posting_flush(ch
->ch_bd
);
688 spin_unlock_irqrestore(&ch
->ch_lock
, lock_flags
);
692 * Parse the ISR register.
694 static void neo_parse_isr(struct jsm_board
*brd
, u32 port
)
696 struct jsm_channel
*ch
;
699 unsigned long lock_flags
;
704 if (port
>= brd
->maxports
)
707 ch
= brd
->channels
[port
];
711 /* Here we try to figure out what caused the interrupt to happen */
714 isr
= readb(&ch
->ch_neo_uart
->isr_fcr
);
716 /* Bail if no pending interrupt */
717 if (isr
& UART_IIR_NO_INT
)
721 * Yank off the upper 2 bits, which just show that the FIFO's are enabled.
723 isr
&= ~(UART_17158_IIR_FIFO_ENABLED
);
725 jsm_dbg(INTR
, &ch
->ch_bd
->pci_dev
, "%s:%d isr: %x\n",
726 __FILE__
, __LINE__
, isr
);
728 if (isr
& (UART_17158_IIR_RDI_TIMEOUT
| UART_IIR_RDI
)) {
729 /* Read data from uart -> queue */
730 neo_copy_data_from_uart_to_queue(ch
);
732 /* Call our tty layer to enforce queue flow control if needed. */
733 spin_lock_irqsave(&ch
->ch_lock
, lock_flags
);
734 jsm_check_queue_flow_control(ch
);
735 spin_unlock_irqrestore(&ch
->ch_lock
, lock_flags
);
738 if (isr
& UART_IIR_THRI
) {
739 /* Transfer data (if any) from Write Queue -> UART. */
740 spin_lock_irqsave(&ch
->ch_lock
, lock_flags
);
741 ch
->ch_flags
|= (CH_TX_FIFO_EMPTY
| CH_TX_FIFO_LWM
);
742 spin_unlock_irqrestore(&ch
->ch_lock
, lock_flags
);
743 neo_copy_data_from_queue_to_uart(ch
);
746 if (isr
& UART_17158_IIR_XONXOFF
) {
747 cause
= readb(&ch
->ch_neo_uart
->xoffchar1
);
749 jsm_dbg(INTR
, &ch
->ch_bd
->pci_dev
,
750 "Port %d. Got ISR_XONXOFF: cause:%x\n",
754 * Since the UART detected either an XON or
755 * XOFF match, we need to figure out which
756 * one it was, so we can suspend or resume data flow.
758 spin_lock_irqsave(&ch
->ch_lock
, lock_flags
);
759 if (cause
== UART_17158_XON_DETECT
) {
760 /* Is output stopped right now, if so, resume it */
761 if (brd
->channels
[port
]->ch_flags
& CH_STOP
) {
762 ch
->ch_flags
&= ~(CH_STOP
);
764 jsm_dbg(INTR
, &ch
->ch_bd
->pci_dev
,
765 "Port %d. XON detected in incoming data\n",
768 else if (cause
== UART_17158_XOFF_DETECT
) {
769 if (!(brd
->channels
[port
]->ch_flags
& CH_STOP
)) {
770 ch
->ch_flags
|= CH_STOP
;
771 jsm_dbg(INTR
, &ch
->ch_bd
->pci_dev
,
772 "Setting CH_STOP\n");
774 jsm_dbg(INTR
, &ch
->ch_bd
->pci_dev
,
775 "Port: %d. XOFF detected in incoming data\n",
778 spin_unlock_irqrestore(&ch
->ch_lock
, lock_flags
);
781 if (isr
& UART_17158_IIR_HWFLOW_STATE_CHANGE
) {
783 * If we get here, this means the hardware is doing auto flow control.
784 * Check to see whether RTS/DTR or CTS/DSR caused this interrupt.
786 cause
= readb(&ch
->ch_neo_uart
->mcr
);
788 /* Which pin is doing auto flow? RTS or DTR? */
789 spin_lock_irqsave(&ch
->ch_lock
, lock_flags
);
790 if ((cause
& 0x4) == 0) {
791 if (cause
& UART_MCR_RTS
)
792 ch
->ch_mostat
|= UART_MCR_RTS
;
794 ch
->ch_mostat
&= ~(UART_MCR_RTS
);
796 if (cause
& UART_MCR_DTR
)
797 ch
->ch_mostat
|= UART_MCR_DTR
;
799 ch
->ch_mostat
&= ~(UART_MCR_DTR
);
801 spin_unlock_irqrestore(&ch
->ch_lock
, lock_flags
);
804 /* Parse any modem signal changes */
805 jsm_dbg(INTR
, &ch
->ch_bd
->pci_dev
,
806 "MOD_STAT: sending to parse_modem_sigs\n");
807 uart_port_lock_irqsave(&ch
->uart_port
, &lock_flags
);
808 neo_parse_modem(ch
, readb(&ch
->ch_neo_uart
->msr
));
809 uart_port_unlock_irqrestore(&ch
->uart_port
, lock_flags
);
813 static inline void neo_parse_lsr(struct jsm_board
*brd
, u32 port
)
815 struct jsm_channel
*ch
;
817 unsigned long lock_flags
;
822 if (port
>= brd
->maxports
)
825 ch
= brd
->channels
[port
];
829 linestatus
= readb(&ch
->ch_neo_uart
->lsr
);
831 jsm_dbg(INTR
, &ch
->ch_bd
->pci_dev
, "%s:%d port: %d linestatus: %x\n",
832 __FILE__
, __LINE__
, port
, linestatus
);
834 ch
->ch_cached_lsr
|= linestatus
;
836 if (ch
->ch_cached_lsr
& UART_LSR_DR
) {
837 /* Read data from uart -> queue */
838 neo_copy_data_from_uart_to_queue(ch
);
839 spin_lock_irqsave(&ch
->ch_lock
, lock_flags
);
840 jsm_check_queue_flow_control(ch
);
841 spin_unlock_irqrestore(&ch
->ch_lock
, lock_flags
);
845 * This is a special flag. It indicates that at least 1
846 * RX error (parity, framing, or break) has happened.
847 * Mark this in our struct, which will tell me that I have
848 *to do the special RX+LSR read for this FIFO load.
850 if (linestatus
& UART_17158_RX_FIFO_DATA_ERROR
)
851 jsm_dbg(INTR
, &ch
->ch_bd
->pci_dev
,
852 "%s:%d Port: %d Got an RX error, need to parse LSR\n",
853 __FILE__
, __LINE__
, port
);
856 * The next 3 tests should *NOT* happen, as the above test
857 * should encapsulate all 3... At least, thats what Exar says.
860 if (linestatus
& UART_LSR_PE
) {
862 jsm_dbg(INTR
, &ch
->ch_bd
->pci_dev
, "%s:%d Port: %d. PAR ERR!\n",
863 __FILE__
, __LINE__
, port
);
866 if (linestatus
& UART_LSR_FE
) {
868 jsm_dbg(INTR
, &ch
->ch_bd
->pci_dev
, "%s:%d Port: %d. FRM ERR!\n",
869 __FILE__
, __LINE__
, port
);
872 if (linestatus
& UART_LSR_BI
) {
874 jsm_dbg(INTR
, &ch
->ch_bd
->pci_dev
,
875 "%s:%d Port: %d. BRK INTR!\n",
876 __FILE__
, __LINE__
, port
);
879 if (linestatus
& UART_LSR_OE
) {
881 * Rx Oruns. Exar says that an orun will NOT corrupt
882 * the FIFO. It will just replace the holding register
883 * with this new data byte. So basically just ignore this.
884 * Probably we should eventually have an orun stat in our driver...
886 ch
->ch_err_overrun
++;
887 jsm_dbg(INTR
, &ch
->ch_bd
->pci_dev
,
888 "%s:%d Port: %d. Rx Overrun!\n",
889 __FILE__
, __LINE__
, port
);
892 if (linestatus
& UART_LSR_THRE
) {
893 spin_lock_irqsave(&ch
->ch_lock
, lock_flags
);
894 ch
->ch_flags
|= (CH_TX_FIFO_EMPTY
| CH_TX_FIFO_LWM
);
895 spin_unlock_irqrestore(&ch
->ch_lock
, lock_flags
);
897 /* Transfer data (if any) from Write Queue -> UART. */
898 neo_copy_data_from_queue_to_uart(ch
);
900 else if (linestatus
& UART_17158_TX_AND_FIFO_CLR
) {
901 spin_lock_irqsave(&ch
->ch_lock
, lock_flags
);
902 ch
->ch_flags
|= (CH_TX_FIFO_EMPTY
| CH_TX_FIFO_LWM
);
903 spin_unlock_irqrestore(&ch
->ch_lock
, lock_flags
);
905 /* Transfer data (if any) from Write Queue -> UART. */
906 neo_copy_data_from_queue_to_uart(ch
);
912 * Send any/all changes to the line to the UART.
914 static void neo_param(struct jsm_channel
*ch
)
920 struct jsm_board
*bd
;
927 * If baud rate is zero, flush queues, and set mval to drop DTR.
929 if ((ch
->ch_c_cflag
& CBAUD
) == B0
) {
930 ch
->ch_r_head
= ch
->ch_r_tail
= 0;
931 ch
->ch_e_head
= ch
->ch_e_tail
= 0;
933 neo_flush_uart_write(ch
);
934 neo_flush_uart_read(ch
);
936 ch
->ch_flags
|= (CH_BAUD0
);
937 ch
->ch_mostat
&= ~(UART_MCR_RTS
| UART_MCR_DTR
);
938 neo_assert_modem_signals(ch
);
969 cflag
= C_BAUD(ch
->uart_port
.state
->port
.tty
);
971 for (i
= 0; i
< ARRAY_SIZE(baud_rates
); i
++) {
972 if (baud_rates
[i
].cflag
== cflag
) {
973 baud
= baud_rates
[i
].rate
;
978 if (ch
->ch_flags
& CH_BAUD0
)
979 ch
->ch_flags
&= ~(CH_BAUD0
);
982 if (ch
->ch_c_cflag
& PARENB
)
983 lcr
|= UART_LCR_PARITY
;
985 if (!(ch
->ch_c_cflag
& PARODD
))
986 lcr
|= UART_LCR_EPAR
;
988 if (ch
->ch_c_cflag
& CMSPAR
)
989 lcr
|= UART_LCR_SPAR
;
991 if (ch
->ch_c_cflag
& CSTOPB
)
992 lcr
|= UART_LCR_STOP
;
994 lcr
|= UART_LCR_WLEN(tty_get_char_size(ch
->ch_c_cflag
));
996 ier
= readb(&ch
->ch_neo_uart
->ier
);
997 uart_lcr
= readb(&ch
->ch_neo_uart
->lcr
);
999 quot
= ch
->ch_bd
->bd_dividend
/ baud
;
1002 writeb(UART_LCR_DLAB
, &ch
->ch_neo_uart
->lcr
);
1003 writeb((quot
& 0xff), &ch
->ch_neo_uart
->txrx
);
1004 writeb((quot
>> 8), &ch
->ch_neo_uart
->ier
);
1005 writeb(lcr
, &ch
->ch_neo_uart
->lcr
);
1008 if (uart_lcr
!= lcr
)
1009 writeb(lcr
, &ch
->ch_neo_uart
->lcr
);
1011 if (ch
->ch_c_cflag
& CREAD
)
1012 ier
|= (UART_IER_RDI
| UART_IER_RLSI
);
1014 ier
|= (UART_IER_THRI
| UART_IER_MSI
);
1016 writeb(ier
, &ch
->ch_neo_uart
->ier
);
1018 /* Set new start/stop chars */
1019 neo_set_new_start_stop_chars(ch
);
1021 if (ch
->ch_c_cflag
& CRTSCTS
)
1022 neo_set_cts_flow_control(ch
);
1023 else if (ch
->ch_c_iflag
& IXON
) {
1024 /* If start/stop is set to disable, then we should disable flow control */
1025 if ((ch
->ch_startc
== __DISABLED_CHAR
) || (ch
->ch_stopc
== __DISABLED_CHAR
))
1026 neo_set_no_output_flow_control(ch
);
1028 neo_set_ixon_flow_control(ch
);
1031 neo_set_no_output_flow_control(ch
);
1033 if (ch
->ch_c_cflag
& CRTSCTS
)
1034 neo_set_rts_flow_control(ch
);
1035 else if (ch
->ch_c_iflag
& IXOFF
) {
1036 /* If start/stop is set to disable, then we should disable flow control */
1037 if ((ch
->ch_startc
== __DISABLED_CHAR
) || (ch
->ch_stopc
== __DISABLED_CHAR
))
1038 neo_set_no_input_flow_control(ch
);
1040 neo_set_ixoff_flow_control(ch
);
1043 neo_set_no_input_flow_control(ch
);
1045 * Adjust the RX FIFO Trigger level if baud is less than 9600.
1046 * Not exactly elegant, but this is needed because of the Exar chip's
1047 * delay on firing off the RX FIFO interrupt on slower baud rates.
1050 writeb(1, &ch
->ch_neo_uart
->rfifo
);
1051 ch
->ch_r_tlevel
= 1;
1054 neo_assert_modem_signals(ch
);
1056 /* Get current status of the modem signals now */
1057 neo_parse_modem(ch
, readb(&ch
->ch_neo_uart
->msr
));
1064 * Neo specific interrupt handler.
1066 static irqreturn_t
neo_intr(int irq
, void *voidbrd
)
1068 struct jsm_board
*brd
= voidbrd
;
1069 struct jsm_channel
*ch
;
1075 unsigned long lock_flags
;
1076 unsigned long lock_flags2
;
1077 int outofloop_count
= 0;
1079 /* Lock out the slow poller from running on this board. */
1080 spin_lock_irqsave(&brd
->bd_intr_lock
, lock_flags
);
1083 * Read in "extended" IRQ information from the 32bit Neo register.
1084 * Bits 0-7: What port triggered the interrupt.
1085 * Bits 8-31: Each 3bits indicate what type of interrupt occurred.
1087 uart_poll
= readl(brd
->re_map_membase
+ UART_17158_POLL_ADDR_OFFSET
);
1089 jsm_dbg(INTR
, &brd
->pci_dev
, "%s:%d uart_poll: %x\n",
1090 __FILE__
, __LINE__
, uart_poll
);
1093 jsm_dbg(INTR
, &brd
->pci_dev
,
1094 "Kernel interrupted to me, but no pending interrupts...\n");
1095 spin_unlock_irqrestore(&brd
->bd_intr_lock
, lock_flags
);
1099 /* At this point, we have at least SOMETHING to service, dig further... */
1103 /* Loop on each port */
1104 while (((uart_poll
& 0xff) != 0) && (outofloop_count
< 0xff)){
1109 /* Check current port to see if it has interrupt pending */
1110 if ((tmp
& jsm_offset_table
[current_port
]) != 0) {
1111 port
= current_port
;
1112 type
= tmp
>> (8 + (port
* 3));
1119 jsm_dbg(INTR
, &brd
->pci_dev
, "%s:%d port: %x type: %x\n",
1120 __FILE__
, __LINE__
, port
, type
);
1122 /* Remove this port + type from uart_poll */
1123 uart_poll
&= ~(jsm_offset_table
[port
]);
1126 /* If no type, just ignore it, and move onto next port */
1127 jsm_dbg(INTR
, &brd
->pci_dev
,
1128 "Interrupt with no type! port: %d\n", port
);
1132 /* Switch on type of interrupt we have */
1135 case UART_17158_RXRDY_TIMEOUT
:
1137 * RXRDY Time-out is cleared by reading data in the
1138 * RX FIFO until it falls below the trigger level.
1141 /* Verify the port is in range. */
1142 if (port
>= brd
->nasync
)
1145 ch
= brd
->channels
[port
];
1149 neo_copy_data_from_uart_to_queue(ch
);
1151 /* Call our tty layer to enforce queue flow control if needed. */
1152 spin_lock_irqsave(&ch
->ch_lock
, lock_flags2
);
1153 jsm_check_queue_flow_control(ch
);
1154 spin_unlock_irqrestore(&ch
->ch_lock
, lock_flags2
);
1158 case UART_17158_RX_LINE_STATUS
:
1160 * RXRDY and RX LINE Status (logic OR of LSR[4:1])
1162 neo_parse_lsr(brd
, port
);
1165 case UART_17158_TXRDY
:
1167 * TXRDY interrupt clears after reading ISR register for the UART channel.
1171 * Yes, this is odd...
1172 * Why would I check EVERY possibility of type of
1173 * interrupt, when we know its TXRDY???
1174 * Becuz for some reason, even tho we got triggered for TXRDY,
1175 * it seems to be occasionally wrong. Instead of TX, which
1176 * it should be, I was getting things like RXDY too. Weird.
1178 neo_parse_isr(brd
, port
);
1181 case UART_17158_MSR
:
1183 * MSR or flow control was seen.
1185 neo_parse_isr(brd
, port
);
1190 * The UART triggered us with a bogus interrupt type.
1191 * It appears the Exar chip, when REALLY bogged down, will throw
1192 * these once and awhile.
1193 * Its harmless, just ignore it and move on.
1195 jsm_dbg(INTR
, &brd
->pci_dev
,
1196 "%s:%d Unknown Interrupt type: %x\n",
1197 __FILE__
, __LINE__
, type
);
1202 spin_unlock_irqrestore(&brd
->bd_intr_lock
, lock_flags
);
1204 jsm_dbg(INTR
, &brd
->pci_dev
, "finish\n");
1209 * Neo specific way of turning off the receiver.
1210 * Used as a way to enforce queue flow control when in
1211 * hardware flow control mode.
1213 static void neo_disable_receiver(struct jsm_channel
*ch
)
1215 u8 tmp
= readb(&ch
->ch_neo_uart
->ier
);
1216 tmp
&= ~(UART_IER_RDI
);
1217 writeb(tmp
, &ch
->ch_neo_uart
->ier
);
1219 /* flush write operation */
1220 neo_pci_posting_flush(ch
->ch_bd
);
1225 * Neo specific way of turning on the receiver.
1226 * Used as a way to un-enforce queue flow control when in
1227 * hardware flow control mode.
1229 static void neo_enable_receiver(struct jsm_channel
*ch
)
1231 u8 tmp
= readb(&ch
->ch_neo_uart
->ier
);
1232 tmp
|= (UART_IER_RDI
);
1233 writeb(tmp
, &ch
->ch_neo_uart
->ier
);
1235 /* flush write operation */
1236 neo_pci_posting_flush(ch
->ch_bd
);
1239 static void neo_send_start_character(struct jsm_channel
*ch
)
1244 if (ch
->ch_startc
!= __DISABLED_CHAR
) {
1246 writeb(ch
->ch_startc
, &ch
->ch_neo_uart
->txrx
);
1248 /* flush write operation */
1249 neo_pci_posting_flush(ch
->ch_bd
);
1253 static void neo_send_stop_character(struct jsm_channel
*ch
)
1258 if (ch
->ch_stopc
!= __DISABLED_CHAR
) {
1259 ch
->ch_xoff_sends
++;
1260 writeb(ch
->ch_stopc
, &ch
->ch_neo_uart
->txrx
);
1262 /* flush write operation */
1263 neo_pci_posting_flush(ch
->ch_bd
);
1270 static void neo_uart_init(struct jsm_channel
*ch
)
1272 writeb(0, &ch
->ch_neo_uart
->ier
);
1273 writeb(0, &ch
->ch_neo_uart
->efr
);
1274 writeb(UART_EFR_ECB
, &ch
->ch_neo_uart
->efr
);
1276 /* Clear out UART and FIFO */
1277 readb(&ch
->ch_neo_uart
->txrx
);
1278 writeb((UART_FCR_ENABLE_FIFO
|UART_FCR_CLEAR_RCVR
|UART_FCR_CLEAR_XMIT
), &ch
->ch_neo_uart
->isr_fcr
);
1279 readb(&ch
->ch_neo_uart
->lsr
);
1280 readb(&ch
->ch_neo_uart
->msr
);
1282 ch
->ch_flags
|= CH_FIFO_ENABLED
;
1284 /* Assert any signals we want up */
1285 writeb(ch
->ch_mostat
, &ch
->ch_neo_uart
->mcr
);
1289 * Make the UART completely turn off.
1291 static void neo_uart_off(struct jsm_channel
*ch
)
1293 /* Turn off UART enhanced bits */
1294 writeb(0, &ch
->ch_neo_uart
->efr
);
1296 /* Stop all interrupts from occurring. */
1297 writeb(0, &ch
->ch_neo_uart
->ier
);
1300 /* Channel lock MUST be held by the calling function! */
1301 static void neo_send_break(struct jsm_channel
*ch
)
1304 * Set the time we should stop sending the break.
1305 * If we are already sending a break, toss away the existing
1306 * time to stop, and use this new value instead.
1309 /* Tell the UART to start sending the break */
1310 if (!(ch
->ch_flags
& CH_BREAK_SENDING
)) {
1311 u8 temp
= readb(&ch
->ch_neo_uart
->lcr
);
1312 writeb((temp
| UART_LCR_SBC
), &ch
->ch_neo_uart
->lcr
);
1313 ch
->ch_flags
|= (CH_BREAK_SENDING
);
1315 /* flush write operation */
1316 neo_pci_posting_flush(ch
->ch_bd
);
1320 struct board_ops jsm_neo_ops
= {
1322 .uart_init
= neo_uart_init
,
1323 .uart_off
= neo_uart_off
,
1325 .assert_modem_signals
= neo_assert_modem_signals
,
1326 .flush_uart_write
= neo_flush_uart_write
,
1327 .flush_uart_read
= neo_flush_uart_read
,
1328 .disable_receiver
= neo_disable_receiver
,
1329 .enable_receiver
= neo_enable_receiver
,
1330 .send_break
= neo_send_break
,
1331 .clear_break
= neo_clear_break
,
1332 .send_start_character
= neo_send_start_character
,
1333 .send_stop_character
= neo_send_stop_character
,
1334 .copy_data_from_queue_to_uart
= neo_copy_data_from_queue_to_uart
,