1 /* $Id: sab82532.c,v 1.35 1999/09/01 08:09:29 davem Exp $
2 * sab82532.c: ASYNC Driver for the SIEMENS SAB82532 DUSCC.
4 * Copyright (C) 1997 Eddie C. Dost (ecd@skynet.be)
8 #include <linux/config.h>
9 #include <linux/module.h>
10 #include <linux/errno.h>
11 #include <linux/signal.h>
12 #include <linux/sched.h>
13 #include <linux/timer.h>
14 #include <linux/interrupt.h>
15 #include <linux/tty.h>
16 #include <linux/tty_flip.h>
17 #include <linux/serial.h>
18 #include <linux/serial_reg.h>
19 #include <linux/console.h>
20 #include <linux/major.h>
21 #include <linux/string.h>
22 #include <linux/fcntl.h>
23 #include <linux/ptrace.h>
24 #include <linux/ioport.h>
26 #include <linux/malloc.h>
27 #include <linux/init.h>
28 #include <linux/delay.h>
30 #include <asm/sab82532.h>
31 #include <asm/uaccess.h>
35 #include "sunserial.h"
37 static DECLARE_TASK_QUEUE(tq_serial
);
39 static struct tty_driver serial_driver
, callout_driver
;
40 static int sab82532_refcount
;
42 /* number of characters left in xmit buffer before we ask for more */
43 #define WAKEUP_CHARS 256
45 #define SERIAL_PARANOIA_CHECK
46 #define SERIAL_DO_RESTART
48 /* Set of debugging defines */
49 #undef SERIAL_DEBUG_OPEN
50 #undef SERIAL_DEBUG_FLOW
51 #undef SERIAL_DEBUG_WAIT_UNTIL_SENT
52 #undef SERIAL_DEBUG_SEND_BREAK
53 #undef SERIAL_DEBUG_INTR
55 /* Trace things on serial device, useful for console debugging: */
56 #undef SERIAL_LOG_DEVICE
58 #ifdef SERIAL_LOG_DEVICE
59 static void dprint_init(int tty
);
62 static void change_speed(struct sab82532
*info
);
63 static void sab82532_wait_until_sent(struct tty_struct
*tty
, int timeout
);
66 * This assumes you have a 29.4912 MHz clock for your UART.
68 #define BASE_BAUD ( 29491200 / 16 )
70 static struct sab82532
*sab82532_chain
= 0;
71 static struct tty_struct
*sab82532_table
[NR_PORTS
];
72 static struct termios
*sab82532_termios
[NR_PORTS
];
73 static struct termios
*sab82532_termios_locked
[NR_PORTS
];
75 #ifdef CONFIG_SERIAL_CONSOLE
76 extern int serial_console
;
77 static struct console sab82532_console
;
78 static int sab82532_console_init(void);
82 #define MIN(a,b) ((a) < (b) ? (a) : (b))
85 static char *sab82532_version
[16] = {
86 "V1.0", "V2.0", "V3.2", "V(0x03)",
87 "V(0x04)", "V(0x05)", "V(0x06)", "V(0x07)",
88 "V(0x08)", "V(0x09)", "V(0x0a)", "V(0x0b)",
89 "V(0x0c)", "V(0x0d)", "V(0x0e)", "V(0x0f)"
91 static char serial_version
[16];
94 * tmp_buf is used as a temporary buffer by sab82532_write. We need to
95 * lock it in case the copy_from_user blocks while swapping in a page,
96 * and some other program tries to do a serial write at the same time.
97 * Since the lock will only come under contention when the system is
98 * swapping and available memory is low, it makes sense to share one
99 * buffer across all the serial ports, since it significantly saves
100 * memory if large numbers of serial ports are open.
102 static unsigned char *tmp_buf
= 0;
103 static DECLARE_MUTEX(tmp_buf_sem
);
105 static inline int serial_paranoia_check(struct sab82532
*info
,
106 kdev_t device
, const char *routine
)
108 #ifdef SERIAL_PARANOIA_CHECK
109 static const char *badmagic
=
110 "Warning: bad magic number for serial struct (%s) in %s\n";
111 static const char *badinfo
=
112 "Warning: null sab82532 for (%s) in %s\n";
115 printk(badinfo
, kdevname(device
), routine
);
118 if (info
->magic
!= SERIAL_MAGIC
) {
119 printk(badmagic
, kdevname(device
), routine
);
127 * This is used to figure out the divisor speeds.
129 * The formula is: Baud = BASE_BAUD / ((N + 1) * (1 << M)),
131 * with 0 <= N < 64 and 0 <= M < 16
133 * XXX: Speeds with M = 0 might not work properly for XTAL frequencies
142 static struct ebrg_struct ebrg_table
[] = {
170 #define NR_EBRG_VALUES (sizeof(ebrg_table)/sizeof(struct ebrg_struct))
172 #define SAB82532_MAX_TEC_DELAY 2000 /* 2 ms */
174 static __inline__
void sab82532_tec_wait(struct sab82532
*info
)
176 int count
= SAB82532_MAX_TEC_DELAY
;
177 while ((readb(&info
->regs
->r
.star
) & SAB82532_STAR_TEC
) && --count
)
181 static __inline__
void sab82532_start_tx(struct sab82532
*info
)
186 save_flags(flags
); cli();
188 if (info
->xmit_cnt
<= 0)
191 if (!(readb(&info
->regs
->r
.star
) & SAB82532_STAR_XFW
))
195 for (i
= 0; i
< info
->xmit_fifo_size
; i
++) {
196 u8 val
= info
->xmit_buf
[info
->xmit_tail
++];
197 writeb(val
, &info
->regs
->w
.xfifo
[i
]);
198 info
->xmit_tail
&= (SERIAL_XMIT_SIZE
- 1);
200 if (--info
->xmit_cnt
<= 0)
204 /* Issue a Transmit Frame command. */
205 if (readb(&info
->regs
->r
.star
) & SAB82532_STAR_CEC
)
207 writeb(SAB82532_CMDR_XF
, &info
->regs
->w
.cmdr
);
210 restore_flags(flags
);
215 * ------------------------------------------------------------
216 * sab82532_stop() and sab82532_start()
218 * This routines are called before setting or resetting tty->stopped.
219 * They enable or disable transmitter interrupts, as necessary.
220 * ------------------------------------------------------------
222 static void sab82532_stop(struct tty_struct
*tty
)
224 struct sab82532
*info
= (struct sab82532
*)tty
->driver_data
;
227 if (serial_paranoia_check(info
, tty
->device
, "sab82532_stop"))
230 save_flags(flags
); cli();
231 info
->interrupt_mask1
|= SAB82532_IMR1_XPR
;
232 writeb(info
->interrupt_mask1
, &info
->regs
->w
.imr1
);
233 restore_flags(flags
);
236 static void sab82532_start(struct tty_struct
*tty
)
238 struct sab82532
*info
= (struct sab82532
*)tty
->driver_data
;
241 if (serial_paranoia_check(info
, tty
->device
, "sab82532_start"))
244 save_flags(flags
); cli();
245 info
->interrupt_mask1
&= ~(SAB82532_IMR1_XPR
);
246 writeb(info
->interrupt_mask1
, &info
->regs
->w
.imr1
);
247 sab82532_start_tx(info
);
248 restore_flags(flags
);
251 static void batten_down_hatches(struct sab82532
*info
)
253 unsigned char saved_rfc
, tmp
;
255 /* If we are doing kadb, we call the debugger
256 * else we just drop into the boot monitor.
257 * Note that we must flush the user windows
258 * first before giving up control.
261 flush_user_windows();
264 * Set FIFO to single character mode.
266 saved_rfc
= readb(&info
->regs
->r
.rfc
);
267 tmp
= readb(&info
->regs
->rw
.rfc
);
268 tmp
&= ~(SAB82532_RFC_RFDF
);
269 writeb(tmp
, &info
->regs
->rw
.rfc
);
270 if (readb(&info
->regs
->r
.star
) & SAB82532_STAR_CEC
)
272 writeb(SAB82532_CMDR_RRES
, &info
->regs
->w
.cmdr
);
275 if ((((unsigned long)linux_dbvec
) >= DEBUG_FIRSTVADDR
) &&
276 (((unsigned long)linux_dbvec
) <= DEBUG_LASTVADDR
))
283 * Reset FIFO to character + status mode.
285 writeb(saved_rfc
, &info
->regs
->w
.rfc
);
286 if (readb(&info
->regs
->r
.star
) & SAB82532_STAR_CEC
)
288 writeb(SAB82532_CMDR_RRES
, &info
->regs
->w
.cmdr
);
292 * ----------------------------------------------------------------------
294 * Here starts the interrupt handling routines. All of the following
295 * subroutines are declared as inline and are folded into
296 * sab82532_interrupt(). They were separated out for readability's sake.
298 * Note: sab82532_interrupt() is a "fast" interrupt, which means that it
299 * runs with interrupts turned off. People who may want to modify
300 * sab82532_interrupt() should try to keep the interrupt handler as fast as
301 * possible. After you are done making modifications, it is not a bad
304 * gcc -S -DKERNEL -Wall -Wstrict-prototypes -O6 -fomit-frame-pointer serial.c
306 * and look at the resulting assemble code in serial.s.
308 * - Ted Ts'o (tytso@mit.edu), 7-Mar-93
309 * -----------------------------------------------------------------------
313 * This routine is used by the interrupt handler to schedule
314 * processing in the software interrupt portion of the driver.
316 static inline void sab82532_sched_event(struct sab82532
*info
, int event
)
318 info
->event
|= 1 << event
;
319 queue_task(&info
->tqueue
, &tq_serial
);
323 static inline void receive_chars(struct sab82532
*info
,
324 union sab82532_irq_status
*stat
)
326 struct tty_struct
*tty
= info
->tty
;
327 unsigned char buf
[32];
328 unsigned char status
;
332 /* Read number of BYTES (Character + Status) available. */
333 if (stat
->sreg
.isr0
& SAB82532_ISR0_RPF
) {
334 count
= info
->recv_fifo_size
;
338 if (stat
->sreg
.isr0
& SAB82532_ISR0_TCD
) {
339 count
= readb(&info
->regs
->r
.rbcl
) & (info
->recv_fifo_size
- 1);
343 /* Issue a FIFO read command in case we where idle. */
344 if (stat
->sreg
.isr0
& SAB82532_ISR0_TIME
) {
345 if (readb(&info
->regs
->r
.star
) & SAB82532_STAR_CEC
)
347 writeb(SAB82532_CMDR_RFRD
, &info
->regs
->w
.cmdr
);
350 if (stat
->sreg
.isr0
& SAB82532_ISR0_RFO
) {
352 printk("sab82532: receive_chars: RFO");
358 for (i
= 0; i
< count
; i
++)
359 buf
[i
] = readb(&info
->regs
->r
.rfifo
[i
]);
361 /* Issue Receive Message Complete command. */
363 if (readb(&info
->regs
->r
.star
) & SAB82532_STAR_CEC
)
365 writeb(SAB82532_CMDR_RMC
, &info
->regs
->w
.cmdr
);
368 if (info
->is_console
)
369 wake_up(&keypress_wait
);
373 for (i
= 0; i
< count
; ) {
374 if (tty
->flip
.count
>= TTY_FLIPBUF_SIZE
) {
376 printk("sab82532: receive_chars: tty overrun\n");
378 info
->icount
.buf_overrun
++;
383 *tty
->flip
.char_buf_ptr
++ = buf
[i
++];
387 #ifdef SERIAL_DEBUG_INTR
388 printk("DR%02x:%02x...", (unsigned char)*(tty
->flip
.char_buf_ptr
- 1), status
);
391 if (status
& SAB82532_RSTAT_PE
) {
392 *tty
->flip
.flag_buf_ptr
++ = TTY_PARITY
;
393 info
->icount
.parity
++;
394 } else if (status
& SAB82532_RSTAT_FE
) {
395 *tty
->flip
.flag_buf_ptr
++ = TTY_FRAME
;
396 info
->icount
.frame
++;
399 else if (status
& SAB82532_RSTAT_PARITY
)
400 *tty
->flip
.flag_buf_ptr
++ = TTY_PARITY
;
403 *tty
->flip
.flag_buf_ptr
++ = TTY_NORMAL
;
406 queue_task(&tty
->flip
.tqueue
, &tq_timer
);
409 static inline void transmit_chars(struct sab82532
*info
,
410 union sab82532_irq_status
*stat
)
414 if (stat
->sreg
.isr1
& SAB82532_ISR1_ALLS
)
416 if (!(readb(&info
->regs
->r
.star
) & SAB82532_STAR_XFW
))
420 info
->interrupt_mask1
|= SAB82532_IMR1_XPR
;
421 writeb(info
->interrupt_mask1
, &info
->regs
->w
.imr1
);
425 if ((info
->xmit_cnt
<= 0) || info
->tty
->stopped
||
426 info
->tty
->hw_stopped
) {
427 info
->interrupt_mask1
|= SAB82532_IMR1_XPR
;
428 writeb(info
->interrupt_mask1
, &info
->regs
->w
.imr1
);
432 /* Stuff 32 bytes into Transmit FIFO. */
434 for (i
= 0; i
< info
->xmit_fifo_size
; i
++) {
435 u8 val
= info
->xmit_buf
[info
->xmit_tail
++];
436 writeb(val
, &info
->regs
->w
.xfifo
[i
]);
437 info
->xmit_tail
&= (SERIAL_XMIT_SIZE
- 1);
439 if (--info
->xmit_cnt
<= 0)
443 /* Issue a Transmit Frame command. */
444 if (readb(&info
->regs
->r
.star
) & SAB82532_STAR_CEC
)
446 writeb(SAB82532_CMDR_XF
, &info
->regs
->w
.cmdr
);
448 if (info
->xmit_cnt
< WAKEUP_CHARS
)
449 sab82532_sched_event(info
, RS_EVENT_WRITE_WAKEUP
);
451 #ifdef SERIAL_DEBUG_INTR
454 if (info
->xmit_cnt
<= 0) {
455 info
->interrupt_mask1
|= SAB82532_IMR1_XPR
;
456 writeb(info
->interrupt_mask1
, &info
->regs
->w
.imr1
);
460 static inline void check_status(struct sab82532
*info
,
461 union sab82532_irq_status
*stat
)
463 struct tty_struct
*tty
= info
->tty
;
464 int modem_change
= 0;
466 if (stat
->sreg
.isr1
& SAB82532_ISR1_BRK
) {
467 if (info
->is_console
) {
468 batten_down_hatches(info
);
471 if (tty
->flip
.count
>= TTY_FLIPBUF_SIZE
) {
472 info
->icount
.buf_overrun
++;
476 *tty
->flip
.flag_buf_ptr
++ = TTY_PARITY
;
477 *tty
->flip
.char_buf_ptr
++ = 0;
484 if (stat
->sreg
.isr0
& SAB82532_ISR0_RFO
) {
485 if (tty
->flip
.count
>= TTY_FLIPBUF_SIZE
) {
486 info
->icount
.buf_overrun
++;
490 *tty
->flip
.flag_buf_ptr
++ = TTY_PARITY
;
491 *tty
->flip
.char_buf_ptr
++ = 0;
492 info
->icount
.overrun
++;
496 if (stat
->sreg
.isr0
& SAB82532_ISR0_CDSC
) {
497 info
->dcd
= (readb(&info
->regs
->r
.vstr
) & SAB82532_VSTR_CD
) ? 0 : 1;
501 printk("DCD change: %d\n", info
->icount
.dcd
);
504 if (stat
->sreg
.isr1
& SAB82532_ISR1_CSC
) {
505 info
->cts
= readb(&info
->regs
->r
.star
) & SAB82532_STAR_CTS
;
509 printk("CTS change: %d, CTS %s\n", info
->icount
.cts
, info
->cts
? "on" : "off");
512 if ((readb(&info
->regs
->r
.pvr
) & info
->pvr_dsr_bit
) ^ info
->dsr
) {
513 info
->dsr
= (readb(&info
->regs
->r
.pvr
) & info
->pvr_dsr_bit
) ? 0 : 1;
517 printk("DSR change: %d\n", info
->icount
.dsr
);
521 wake_up_interruptible(&info
->delta_msr_wait
);
523 if ((info
->flags
& ASYNC_CHECK_CD
) &&
524 (stat
->sreg
.isr0
& SAB82532_ISR0_CDSC
)) {
526 #if (defined(SERIAL_DEBUG_OPEN) || defined(SERIAL_DEBUG_INTR))
527 printk("ttys%d CD now %s...", info
->line
,
528 (info
->dcd
) ? "on" : "off");
532 wake_up_interruptible(&info
->open_wait
);
533 else if (!((info
->flags
& ASYNC_CALLOUT_ACTIVE
) &&
534 (info
->flags
& ASYNC_CALLOUT_NOHUP
))) {
536 #ifdef SERIAL_DEBUG_OPEN
537 printk("scheduling hangup...");
540 queue_task(&info
->tqueue_hangup
, &tq_scheduler
);
544 if (info
->flags
& ASYNC_CTS_FLOW
) {
545 if (info
->tty
->hw_stopped
) {
548 #if (defined(SERIAL_DEBUG_INTR) || defined(SERIAL_DEBUG_FLOW))
549 printk("CTS tx start...");
551 info
->tty
->hw_stopped
= 0;
552 sab82532_sched_event(info
,
553 RS_EVENT_WRITE_WAKEUP
);
554 info
->interrupt_mask1
&= ~(SAB82532_IMR1_XPR
);
555 writeb(info
->interrupt_mask1
, &info
->regs
->w
.imr1
);
556 sab82532_start_tx(info
);
561 #if (defined(SERIAL_DEBUG_INTR) || defined(SERIAL_DEBUG_FLOW))
562 printk("CTS tx stop...");
564 info
->tty
->hw_stopped
= 1;
571 * This is the serial driver's generic interrupt routine
573 static void sab82532_interrupt(int irq
, void *dev_id
, struct pt_regs
*regs
)
575 struct sab82532
*info
= dev_id
;
576 union sab82532_irq_status status
;
578 #ifdef SERIAL_DEBUG_INTR
579 printk("sab82532_interrupt(%d)...", irq
);
583 if (readb(&info
->regs
->r
.gis
) & SAB82532_GIS_ISA0
)
584 status
.sreg
.isr0
= readb(&info
->regs
->r
.isr0
);
585 if (readb(&info
->regs
->r
.gis
) & SAB82532_GIS_ISA1
)
586 status
.sreg
.isr1
= readb(&info
->regs
->r
.isr1
);
588 #ifdef SERIAL_DEBUG_INTR
589 printk("%d<%02x.%02x>", info
->line
,
590 status
.sreg
.isr0
, status
.sreg
.isr1
);
596 if (status
.sreg
.isr0
& (SAB82532_ISR0_TCD
| SAB82532_ISR0_TIME
|
597 SAB82532_ISR0_RFO
| SAB82532_ISR0_RPF
))
598 receive_chars(info
, &status
);
599 if ((status
.sreg
.isr0
& SAB82532_ISR0_CDSC
) ||
600 (status
.sreg
.isr1
& (SAB82532_ISR1_BRK
| SAB82532_ISR1_CSC
)))
601 check_status(info
, &status
);
602 if (status
.sreg
.isr1
& (SAB82532_ISR1_ALLS
| SAB82532_ISR1_XPR
))
603 transmit_chars(info
, &status
);
608 if (readb(&info
->regs
->r
.gis
) & SAB82532_GIS_ISB0
)
609 status
.sreg
.isr0
= readb(&info
->regs
->r
.isr0
);
610 if (readb(&info
->regs
->r
.gis
) & SAB82532_GIS_ISB1
)
611 status
.sreg
.isr1
= readb(&info
->regs
->r
.isr1
);
613 #ifdef SERIAL_DEBUG_INTR
614 printk("%d<%02x.%02x>", info
->line
,
615 status
.sreg
.isr0
, status
.sreg
.isr1
);
621 if (status
.sreg
.isr0
& (SAB82532_ISR0_TCD
| SAB82532_ISR0_TIME
|
622 SAB82532_ISR0_RFO
| SAB82532_ISR0_RPF
))
623 receive_chars(info
, &status
);
624 if ((status
.sreg
.isr0
& SAB82532_ISR0_CDSC
) ||
625 (status
.sreg
.isr1
& (SAB82532_ISR1_BRK
| SAB82532_ISR1_CSC
)))
626 check_status(info
, &status
);
627 if (status
.sreg
.isr1
& (SAB82532_ISR1_ALLS
| SAB82532_ISR1_XPR
))
628 transmit_chars(info
, &status
);
631 #ifdef SERIAL_DEBUG_INTR
637 * -------------------------------------------------------------------
638 * Here ends the serial interrupt routines.
639 * -------------------------------------------------------------------
643 * This routine is used to handle the "bottom half" processing for the
644 * serial driver, known also the "software interrupt" processing.
645 * This processing is done at the kernel interrupt level, after the
646 * sab82532_interrupt() has returned, BUT WITH INTERRUPTS TURNED ON. This
647 * is where time-consuming activities which can not be done in the
648 * interrupt driver proper are done; the interrupt driver schedules
649 * them using sab82532_sched_event(), and they get done here.
651 static void do_serial_bh(void)
653 run_task_queue(&tq_serial
);
656 static void do_softint(void *private_
)
658 struct sab82532
*info
= (struct sab82532
*)private_
;
659 struct tty_struct
*tty
;
665 if (test_and_clear_bit(RS_EVENT_WRITE_WAKEUP
, &info
->event
)) {
666 if ((tty
->flags
& (1 << TTY_DO_WRITE_WAKEUP
)) &&
667 tty
->ldisc
.write_wakeup
)
668 (tty
->ldisc
.write_wakeup
)(tty
);
669 wake_up_interruptible(&tty
->write_wait
);
674 * This routine is called from the scheduler tqueue when the interrupt
675 * routine has signalled that a hangup has occurred. The path of
676 * hangup processing is:
678 * serial interrupt routine -> (scheduler tqueue) ->
679 * do_serial_hangup() -> tty->hangup() -> sab82532_hangup()
682 static void do_serial_hangup(void *private_
)
684 struct sab82532
*info
= (struct sab82532
*) private_
;
685 struct tty_struct
*tty
;
695 sab82532_init_line(struct sab82532
*info
)
697 unsigned char stat
, tmp
;
700 * Wait for any commands or immediate characters
702 if (readb(&info
->regs
->r
.star
) & SAB82532_STAR_CEC
)
704 sab82532_tec_wait(info
);
707 * Clear the FIFO buffers.
709 if (readb(&info
->regs
->r
.star
) & SAB82532_STAR_CEC
)
711 writeb(SAB82532_CMDR_RRES
, &info
->regs
->w
.cmdr
);
712 if (readb(&info
->regs
->r
.star
) & SAB82532_STAR_CEC
)
714 writeb(SAB82532_CMDR_XRES
, &info
->regs
->w
.cmdr
);
717 * Clear the interrupt registers.
719 stat
= readb(&info
->regs
->r
.isr0
);
720 stat
= readb(&info
->regs
->r
.isr1
);
723 * Now, initialize the UART
725 writeb(0, &info
->regs
->w
.ccr0
); /* power-down */
726 writeb(SAB82532_CCR0_MCE
| SAB82532_CCR0_SC_NRZ
|
727 SAB82532_CCR0_SM_ASYNC
, &info
->regs
->w
.ccr0
);
728 writeb(SAB82532_CCR1_ODS
| SAB82532_CCR1_BCR
| 7, &info
->regs
->w
.ccr1
);
729 writeb(SAB82532_CCR2_BDF
| SAB82532_CCR2_SSEL
|
730 SAB82532_CCR2_TOE
, &info
->regs
->w
.ccr2
);
731 writeb(0, &info
->regs
->w
.ccr3
);
732 writeb(SAB82532_CCR4_MCK4
| SAB82532_CCR4_EBRG
, &info
->regs
->w
.ccr4
);
733 writeb(SAB82532_MODE_RTS
| SAB82532_MODE_FCTS
|
734 SAB82532_MODE_RAC
, &info
->regs
->w
.mode
);
735 writeb(SAB82532_RFC_DPS
| SAB82532_RFC_RFDF
, &info
->regs
->w
.rfc
);
736 switch (info
->recv_fifo_size
) {
738 tmp
= readb(&info
->regs
->w
.rfc
);
739 tmp
|= SAB82532_RFC_RFTH_1
;
740 writeb(tmp
, &info
->regs
->w
.rfc
);
743 tmp
= readb(&info
->regs
->w
.rfc
);
744 tmp
|= SAB82532_RFC_RFTH_4
;
745 writeb(tmp
, &info
->regs
->w
.rfc
);
748 tmp
= readb(&info
->regs
->w
.rfc
);
749 tmp
|= SAB82532_RFC_RFTH_16
;
750 writeb(tmp
, &info
->regs
->w
.rfc
);
753 info
->recv_fifo_size
= 32;
756 tmp
= readb(&info
->regs
->w
.rfc
);
757 tmp
|= SAB82532_RFC_RFTH_32
;
758 writeb(tmp
, &info
->regs
->w
.rfc
);
761 tmp
= readb(&info
->regs
->rw
.ccr0
);
762 tmp
|= SAB82532_CCR0_PU
; /* power-up */
763 writeb(tmp
, &info
->regs
->rw
.ccr0
);
766 static int startup(struct sab82532
*info
)
772 page
= get_free_page(GFP_KERNEL
);
776 save_flags(flags
); cli();
778 if (info
->flags
& ASYNC_INITIALIZED
) {
785 set_bit(TTY_IO_ERROR
, &info
->tty
->flags
);
793 info
->xmit_buf
= (unsigned char *)page
;
795 #ifdef SERIAL_DEBUG_OPEN
796 printk("starting up serial port %d...", info
->line
);
800 * Initialize the Hardware
802 sab82532_init_line(info
);
804 if (info
->tty
->termios
->c_cflag
& CBAUD
) {
807 tmp
= readb(&info
->regs
->rw
.mode
);
808 tmp
&= ~(SAB82532_MODE_FRTS
);
809 tmp
|= SAB82532_MODE_RTS
;
810 writeb(tmp
, &info
->regs
->rw
.mode
);
812 tmp
= readb(&info
->regs
->rw
.pvr
);
813 tmp
&= ~(info
->pvr_dtr_bit
);
814 writeb(tmp
, &info
->regs
->rw
.pvr
);
818 * Finally, enable interrupts
820 info
->interrupt_mask0
= SAB82532_IMR0_PERR
| SAB82532_IMR0_FERR
|
822 writeb(info
->interrupt_mask0
, &info
->regs
->w
.imr0
);
823 info
->interrupt_mask1
= SAB82532_IMR1_BRKT
| SAB82532_IMR1_XOFF
|
824 SAB82532_IMR1_TIN
| SAB82532_IMR1_XON
|
826 writeb(info
->interrupt_mask1
, &info
->regs
->w
.imr1
);
829 clear_bit(TTY_IO_ERROR
, &info
->tty
->flags
);
830 info
->xmit_cnt
= info
->xmit_head
= info
->xmit_tail
= 0;
833 * and set the speed of the serial port
837 info
->flags
|= ASYNC_INITIALIZED
;
838 restore_flags(flags
);
842 restore_flags(flags
);
847 * This routine will shutdown a serial port; interrupts are disabled, and
848 * DTR is dropped if the hangup on close termio flag is on.
850 static void shutdown(struct sab82532
*info
)
855 if (!(info
->flags
& ASYNC_INITIALIZED
))
858 #ifdef SERIAL_DEBUG_OPEN
859 printk("Shutting down serial port %d...", info
->line
);
862 save_flags(flags
); cli(); /* Disable interrupts */
865 * clear delta_msr_wait queue to avoid mem leaks: we may free the irq
866 * here so the queue might never be waken up
868 wake_up_interruptible(&info
->delta_msr_wait
);
870 if (info
->xmit_buf
) {
871 free_page((unsigned long)info
->xmit_buf
);
875 if (info
->is_console
) {
876 info
->interrupt_mask0
= SAB82532_IMR0_PERR
| SAB82532_IMR0_FERR
|
877 SAB82532_IMR0_PLLA
| SAB82532_IMR0_CDSC
;
878 writeb(info
->interrupt_mask0
, &info
->regs
->w
.imr0
);
879 info
->interrupt_mask1
= SAB82532_IMR1_BRKT
| SAB82532_IMR1_ALLS
|
880 SAB82532_IMR1_XOFF
| SAB82532_IMR1_TIN
|
881 SAB82532_IMR1_CSC
| SAB82532_IMR1_XON
|
883 writeb(info
->interrupt_mask1
, &info
->regs
->w
.imr1
);
885 set_bit(TTY_IO_ERROR
, &info
->tty
->flags
);
886 info
->flags
&= ~ASYNC_INITIALIZED
;
887 restore_flags(flags
);
891 /* Disable Interrupts */
892 info
->interrupt_mask0
= 0xff;
893 writeb(info
->interrupt_mask0
, &info
->regs
->w
.imr0
);
894 info
->interrupt_mask1
= 0xff;
895 writeb(info
->interrupt_mask1
, &info
->regs
->w
.imr1
);
897 if (!info
->tty
|| (info
->tty
->termios
->c_cflag
& HUPCL
)) {
898 writeb(readb(&info
->regs
->rw
.mode
) | SAB82532_MODE_FRTS
, &info
->regs
->rw
.mode
);
899 writeb(readb(&info
->regs
->rw
.mode
) | SAB82532_MODE_RTS
, &info
->regs
->rw
.mode
);
900 writeb(readb(&info
->regs
->rw
.pvr
) | info
->pvr_dtr_bit
, &info
->regs
->rw
.pvr
);
903 /* Disable break condition */
904 tmp
= readb(&info
->regs
->rw
.dafo
);
905 tmp
&= ~(SAB82532_DAFO_XBRK
);
906 writeb(tmp
, &info
->regs
->rw
.dafo
);
908 /* Disable Receiver */
909 tmp
= readb(&info
->regs
->rw
.mode
);
910 tmp
&= ~(SAB82532_MODE_RAC
);
911 writeb(tmp
, &info
->regs
->rw
.mode
);
914 tmp
= readb(&info
->regs
->rw
.ccr0
);
915 tmp
&= ~(SAB82532_CCR0_PU
);
916 writeb(tmp
, &info
->regs
->rw
.ccr0
);
919 set_bit(TTY_IO_ERROR
, &info
->tty
->flags
);
921 info
->flags
&= ~ASYNC_INITIALIZED
;
922 restore_flags(flags
);
926 * This routine is called to set the UART divisor registers to match
927 * the specified baud rate for a serial port.
929 static void change_speed(struct sab82532
*info
)
937 if (!info
->tty
|| !info
->tty
->termios
)
939 cflag
= info
->tty
->termios
->c_cflag
;
941 /* Byte size and parity */
942 switch (cflag
& CSIZE
) {
943 case CS5
: dafo
= SAB82532_DAFO_CHL5
; bits
= 7; break;
944 case CS6
: dafo
= SAB82532_DAFO_CHL6
; bits
= 8; break;
945 case CS7
: dafo
= SAB82532_DAFO_CHL7
; bits
= 9; break;
946 case CS8
: dafo
= SAB82532_DAFO_CHL8
; bits
= 10; break;
947 /* Never happens, but GCC is too dumb to figure it out */
948 default: dafo
= SAB82532_DAFO_CHL5
; bits
= 7; break;
951 if (cflag
& CSTOPB
) {
952 dafo
|= SAB82532_DAFO_STOP
;
956 if (cflag
& PARENB
) {
957 dafo
|= SAB82532_DAFO_PARE
;
961 if (cflag
& PARODD
) {
964 dafo
|= SAB82532_DAFO_PAR_MARK
;
967 dafo
|= SAB82532_DAFO_PAR_ODD
;
971 dafo
|= SAB82532_DAFO_PAR_SPACE
;
974 dafo
|= SAB82532_DAFO_PAR_EVEN
;
977 /* Determine EBRG values based on baud rate */
981 if ((i
< 1) || ((i
+ 15) >= NR_EBRG_VALUES
))
982 info
->tty
->termios
->c_cflag
&= ~CBAUDEX
;
986 ebrg
= ebrg_table
[i
].n
;
987 ebrg
|= (ebrg_table
[i
].m
<< 6);
989 info
->baud
= ebrg_table
[i
].baud
;
991 info
->timeout
= (info
->xmit_fifo_size
* HZ
* bits
) / info
->baud
;
994 info
->timeout
+= HZ
/ 50; /* Add .02 seconds of slop */
996 /* CTS flow control flags */
998 info
->flags
|= ASYNC_CTS_FLOW
;
1000 info
->flags
&= ~(ASYNC_CTS_FLOW
);
1003 info
->flags
&= ~(ASYNC_CHECK_CD
);
1005 info
->flags
|= ASYNC_CHECK_CD
;
1007 info
->tty
->hw_stopped
= 0;
1010 * Set up parity check flag
1011 * XXX: not implemented, yet.
1013 #define RELEVANT_IFLAG(iflag) (iflag & (IGNBRK|BRKINT|IGNPAR|PARMRK|INPCK))
1016 * Characters to ignore
1017 * XXX: not implemented, yet.
1021 * !!! ignore all characters if CREAD is not set
1022 * XXX: not implemented, yet.
1024 if ((cflag
& CREAD
) == 0)
1025 info
->ignore_status_mask
|= SAB82532_ISR0_RPF
|
1029 save_flags(flags
); cli();
1030 if (readb(&info
->regs
->r
.star
) & SAB82532_STAR_CEC
)
1032 sab82532_tec_wait(info
);
1033 writeb(dafo
, &info
->regs
->w
.dafo
);
1034 writeb(ebrg
& 0xff, &info
->regs
->w
.bgr
);
1035 writeb(readb(&info
->regs
->rw
.ccr2
) & ~(0xc0), &info
->regs
->rw
.ccr2
);
1036 writeb(readb(&info
->regs
->rw
.ccr2
) | ((ebrg
>> 2) & 0xc0), &info
->regs
->rw
.ccr2
);
1037 if (info
->flags
& ASYNC_CTS_FLOW
) {
1038 writeb(readb(&info
->regs
->rw
.mode
) & ~(SAB82532_MODE_RTS
), &info
->regs
->rw
.mode
);
1039 writeb(readb(&info
->regs
->rw
.mode
) | SAB82532_MODE_FRTS
, &info
->regs
->rw
.mode
);
1040 writeb(readb(&info
->regs
->rw
.mode
) & ~(SAB82532_MODE_FCTS
), &info
->regs
->rw
.mode
);
1042 writeb(readb(&info
->regs
->rw
.mode
) | SAB82532_MODE_RTS
, &info
->regs
->rw
.mode
);
1043 writeb(readb(&info
->regs
->rw
.mode
) & ~(SAB82532_MODE_FRTS
), &info
->regs
->rw
.mode
);
1044 writeb(readb(&info
->regs
->rw
.mode
) | SAB82532_MODE_FCTS
, &info
->regs
->rw
.mode
);
1046 writeb(readb(&info
->regs
->rw
.mode
) | SAB82532_MODE_RAC
, &info
->regs
->rw
.mode
);
1047 restore_flags(flags
);
1050 static void sab82532_put_char(struct tty_struct
*tty
, unsigned char ch
)
1052 struct sab82532
*info
= (struct sab82532
*)tty
->driver_data
;
1053 unsigned long flags
;
1055 if (serial_paranoia_check(info
, tty
->device
, "sab82532_put_char"))
1058 if (!tty
|| !info
->xmit_buf
)
1061 save_flags(flags
); cli();
1062 if (info
->xmit_cnt
>= SERIAL_XMIT_SIZE
- 1) {
1063 restore_flags(flags
);
1067 info
->xmit_buf
[info
->xmit_head
++] = ch
;
1068 info
->xmit_head
&= SERIAL_XMIT_SIZE
-1;
1070 restore_flags(flags
);
1073 static void sab82532_flush_chars(struct tty_struct
*tty
)
1075 struct sab82532
*info
= (struct sab82532
*)tty
->driver_data
;
1076 unsigned long flags
;
1078 if (serial_paranoia_check(info
, tty
->device
, "sab82532_flush_chars"))
1081 if (info
->xmit_cnt
<= 0 || tty
->stopped
|| tty
->hw_stopped
||
1085 save_flags(flags
); cli();
1086 info
->interrupt_mask1
&= ~(SAB82532_IMR1_XPR
);
1087 writeb(info
->interrupt_mask1
, &info
->regs
->w
.imr1
);
1088 sab82532_start_tx(info
);
1089 restore_flags(flags
);
1092 static int sab82532_write(struct tty_struct
* tty
, int from_user
,
1093 const unsigned char *buf
, int count
)
1096 struct sab82532
*info
= (struct sab82532
*)tty
->driver_data
;
1097 unsigned long flags
;
1099 if (serial_paranoia_check(info
, tty
->device
, "sab82532_write"))
1102 if (!tty
|| !info
->xmit_buf
|| !tmp_buf
)
1110 c
= MIN(count
, MIN(SERIAL_XMIT_SIZE
- info
->xmit_cnt
- 1,
1111 SERIAL_XMIT_SIZE
- info
->xmit_head
));
1116 c
-= copy_from_user(tmp_buf
, buf
, c
);
1122 c
= MIN(c
, MIN(SERIAL_XMIT_SIZE
- info
->xmit_cnt
- 1,
1123 SERIAL_XMIT_SIZE
- info
->xmit_head
));
1124 memcpy(info
->xmit_buf
+ info
->xmit_head
, tmp_buf
, c
);
1126 memcpy(info
->xmit_buf
+ info
->xmit_head
, buf
, c
);
1127 info
->xmit_head
= (info
->xmit_head
+ c
) & (SERIAL_XMIT_SIZE
-1);
1128 info
->xmit_cnt
+= c
;
1129 restore_flags(flags
);
1137 if (info
->xmit_cnt
&& !tty
->stopped
&& !tty
->hw_stopped
) {
1138 info
->interrupt_mask1
&= ~(SAB82532_IMR1_XPR
);
1139 writeb(info
->interrupt_mask1
, &info
->regs
->w
.imr1
);
1140 sab82532_start_tx(info
);
1143 restore_flags(flags
);
1147 static int sab82532_write_room(struct tty_struct
*tty
)
1149 struct sab82532
*info
= (struct sab82532
*)tty
->driver_data
;
1152 if (serial_paranoia_check(info
, tty
->device
, "sab82532_write_room"))
1154 ret
= SERIAL_XMIT_SIZE
- info
->xmit_cnt
- 1;
1160 static int sab82532_chars_in_buffer(struct tty_struct
*tty
)
1162 struct sab82532
*info
= (struct sab82532
*)tty
->driver_data
;
1164 if (serial_paranoia_check(info
, tty
->device
, "sab82532_chars_in_buffer"))
1166 return info
->xmit_cnt
;
1169 static void sab82532_flush_buffer(struct tty_struct
*tty
)
1171 struct sab82532
*info
= (struct sab82532
*)tty
->driver_data
;
1173 if (serial_paranoia_check(info
, tty
->device
, "sab82532_flush_buffer"))
1176 info
->xmit_cnt
= info
->xmit_head
= info
->xmit_tail
= 0;
1178 wake_up_interruptible(&tty
->write_wait
);
1179 if ((tty
->flags
& (1 << TTY_DO_WRITE_WAKEUP
)) &&
1180 tty
->ldisc
.write_wakeup
)
1181 (tty
->ldisc
.write_wakeup
)(tty
);
1185 * This function is used to send a high-priority XON/XOFF character to
1188 static void sab82532_send_xchar(struct tty_struct
*tty
, char ch
)
1190 struct sab82532
*info
= (struct sab82532
*)tty
->driver_data
;
1191 unsigned long flags
;
1193 if (serial_paranoia_check(info
, tty
->device
, "sab82532_send_xchar"))
1196 save_flags(flags
); cli();
1197 sab82532_tec_wait(info
);
1198 writeb(ch
, &info
->regs
->w
.tic
);
1199 restore_flags(flags
);
1203 * ------------------------------------------------------------
1204 * sab82532_throttle()
1206 * This routine is called by the upper-layer tty layer to signal that
1207 * incoming characters should be throttled.
1208 * ------------------------------------------------------------
1210 static void sab82532_throttle(struct tty_struct
* tty
)
1212 struct sab82532
*info
= (struct sab82532
*)tty
->driver_data
;
1213 #ifdef SERIAL_DEBUG_THROTTLE
1216 printk("throttle %s: %d....\n", _tty_name(tty
, buf
),
1217 tty
->ldisc
.chars_in_buffer(tty
));
1220 if (serial_paranoia_check(info
, tty
->device
, "sab82532_throttle"))
1224 sab82532_send_xchar(tty
, STOP_CHAR(tty
));
1226 if (tty
->termios
->c_cflag
& CRTSCTS
)
1227 writeb(readb(&info
->regs
->rw
.mode
) | SAB82532_MODE_RTS
, &info
->regs
->rw
.mode
);
1231 static void sab82532_unthrottle(struct tty_struct
* tty
)
1233 struct sab82532
*info
= (struct sab82532
*)tty
->driver_data
;
1234 #ifdef SERIAL_DEBUG_THROTTLE
1237 printk("unthrottle %s: %d....\n", _tty_name(tty
, buf
),
1238 tty
->ldisc
.chars_in_buffer(tty
));
1241 if (serial_paranoia_check(info
, tty
->device
, "sab82532_unthrottle"))
1248 sab82532_send_xchar(tty
, START_CHAR(tty
));
1252 if (tty
->termios
->c_cflag
& CRTSCTS
)
1253 writeb(readb(&info
->regs
->rw
.mode
) & ~(SAB82532_MODE_RTS
), &info
->regs
->rw
.mode
);
1258 * ------------------------------------------------------------
1259 * sab82532_ioctl() and friends
1260 * ------------------------------------------------------------
1263 static int get_serial_info(struct sab82532
*info
,
1264 struct serial_struct
*retinfo
)
1266 struct serial_struct tmp
;
1270 memset(&tmp
, 0, sizeof(tmp
));
1271 tmp
.type
= info
->type
;
1272 tmp
.line
= info
->line
;
1273 tmp
.port
= (unsigned long)info
->regs
;
1274 tmp
.irq
= info
->irq
;
1275 tmp
.flags
= info
->flags
;
1276 tmp
.xmit_fifo_size
= info
->xmit_fifo_size
;
1277 tmp
.baud_base
= info
->baud_base
;
1278 tmp
.close_delay
= info
->close_delay
;
1279 tmp
.closing_wait
= info
->closing_wait
;
1280 tmp
.custom_divisor
= info
->custom_divisor
;
1282 if (copy_to_user(retinfo
, &tmp
, sizeof(*retinfo
)))
1287 static int set_serial_info(struct sab82532
*info
,
1288 struct serial_struct
*new_info
)
1295 * get_lsr_info - get line status register info
1297 * Purpose: Let user call ioctl() to get info when the UART physically
1298 * is emptied. On bus types like RS485, the transmitter must
1299 * release the bus after transmitting. This must be done when
1300 * the transmit shift register is empty, not be done when the
1301 * transmit holding register is empty. This functionality
1302 * allows an RS485 driver to be written in user space.
1304 static int get_lsr_info(struct sab82532
* info
, unsigned int *value
)
1306 unsigned int result
;
1308 result
= (!info
->xmit_buf
&& info
->all_sent
) ? TIOCSER_TEMT
: 0;
1309 return put_user(result
, value
);
1313 static int get_modem_info(struct sab82532
* info
, unsigned int *value
)
1315 unsigned int result
;
1317 result
= ((readb(&info
->regs
->r
.mode
) & SAB82532_MODE_RTS
) ?
1318 ((readb(&info
->regs
->r
.mode
) & SAB82532_MODE_FRTS
) ? 0 : TIOCM_RTS
)
1320 | ((readb(&info
->regs
->r
.pvr
) & info
->pvr_dtr_bit
) ? 0 : TIOCM_DTR
)
1321 | ((readb(&info
->regs
->r
.vstr
) & SAB82532_VSTR_CD
) ? 0 : TIOCM_CAR
)
1322 | ((readb(&info
->regs
->r
.pvr
) & info
->pvr_dsr_bit
) ? 0 : TIOCM_DSR
)
1323 | ((readb(&info
->regs
->r
.star
) & SAB82532_STAR_CTS
) ? TIOCM_CTS
: 0);
1324 return put_user(result
,value
);
1327 static int set_modem_info(struct sab82532
* info
, unsigned int cmd
,
1328 unsigned int *value
)
1333 error
= get_user(arg
, value
);
1338 if (arg
& TIOCM_RTS
) {
1339 writeb(readb(&info
->regs
->rw
.mode
) & ~(SAB82532_MODE_FRTS
), &info
->regs
->rw
.mode
);
1340 writeb(readb(&info
->regs
->rw
.mode
) | SAB82532_MODE_RTS
, &info
->regs
->rw
.mode
);
1342 if (arg
& TIOCM_DTR
) {
1343 writeb(readb(&info
->regs
->rw
.pvr
) & ~(info
->pvr_dtr_bit
), &info
->regs
->rw
.pvr
);
1347 if (arg
& TIOCM_RTS
) {
1348 writeb(readb(&info
->regs
->rw
.mode
) | SAB82532_MODE_FRTS
, &info
->regs
->rw
.mode
);
1349 writeb(readb(&info
->regs
->rw
.mode
) | SAB82532_MODE_RTS
, &info
->regs
->rw
.mode
);
1351 if (arg
& TIOCM_DTR
) {
1352 writeb(readb(&info
->regs
->rw
.pvr
) | info
->pvr_dtr_bit
, &info
->regs
->rw
.pvr
);
1356 if (arg
& TIOCM_RTS
) {
1357 writeb(readb(&info
->regs
->rw
.mode
) & ~(SAB82532_MODE_FRTS
), &info
->regs
->rw
.mode
);
1358 writeb(readb(&info
->regs
->rw
.mode
) | SAB82532_MODE_RTS
, &info
->regs
->rw
.mode
);
1360 writeb(readb(&info
->regs
->rw
.mode
) | SAB82532_MODE_FRTS
, &info
->regs
->rw
.mode
);
1361 writeb(readb(&info
->regs
->rw
.mode
) | SAB82532_MODE_RTS
, &info
->regs
->rw
.mode
);
1363 if (arg
& TIOCM_DTR
) {
1364 writeb(readb(&info
->regs
->rw
.pvr
) & ~(info
->pvr_dtr_bit
), &info
->regs
->rw
.pvr
);
1366 writeb(readb(&info
->regs
->rw
.pvr
) | info
->pvr_dtr_bit
, &info
->regs
->rw
.pvr
);
1376 * This routine sends a break character out the serial port.
1378 static void sab82532_break(struct tty_struct
*tty
, int break_state
)
1380 struct sab82532
* info
= (struct sab82532
*)tty
->driver_data
;
1381 unsigned long flags
;
1383 if (serial_paranoia_check(info
, tty
->device
, "sab82532_break"))
1389 #ifdef SERIAL_DEBUG_SEND_BREAK
1390 printk("sab82532_break(%d) jiff=%lu...", break_state
, jiffies
);
1392 save_flags(flags
); cli();
1393 if (break_state
== -1)
1394 writeb(readb(&info
->regs
->rw
.dafo
) | SAB82532_DAFO_XBRK
, &info
->regs
->rw
.dafo
);
1396 writeb(readb(&info
->regs
->rw
.dafo
) & ~(SAB82532_DAFO_XBRK
), &info
->regs
->rw
.dafo
);
1397 restore_flags(flags
);
1401 static int sab82532_ioctl(struct tty_struct
*tty
, struct file
* file
,
1402 unsigned int cmd
, unsigned long arg
)
1405 struct sab82532
* info
= (struct sab82532
*)tty
->driver_data
;
1406 struct async_icount cprev
, cnow
; /* kernel counter temps */
1407 struct serial_icounter_struct
*p_cuser
; /* user space */
1409 if (serial_paranoia_check(info
, tty
->device
, "sab82532_ioctl"))
1412 if ((cmd
!= TIOCGSERIAL
) && (cmd
!= TIOCSSERIAL
) &&
1413 (cmd
!= TIOCSERCONFIG
) && (cmd
!= TIOCSERGWILD
) &&
1414 (cmd
!= TIOCSERSWILD
) && (cmd
!= TIOCSERGSTRUCT
) &&
1415 (cmd
!= TIOCMIWAIT
) && (cmd
!= TIOCGICOUNT
)) {
1416 if (tty
->flags
& (1 << TTY_IO_ERROR
))
1422 return put_user(C_CLOCAL(tty
) ? 1 : 0, (int *) arg
);
1424 error
= get_user(arg
, (unsigned int *) arg
);
1427 tty
->termios
->c_cflag
=
1428 ((tty
->termios
->c_cflag
& ~CLOCAL
) |
1429 (arg
? CLOCAL
: 0));
1432 return get_modem_info(info
, (unsigned int *) arg
);
1436 return set_modem_info(info
, cmd
, (unsigned int *) arg
);
1438 return get_serial_info(info
,
1439 (struct serial_struct
*) arg
);
1441 return set_serial_info(info
,
1442 (struct serial_struct
*) arg
);
1444 case TIOCSERGETLSR
: /* Get line status register */
1445 return get_lsr_info(info
, (unsigned int *) arg
);
1447 case TIOCSERGSTRUCT
:
1448 if (copy_to_user((struct sab82532
*) arg
,
1449 info
, sizeof(struct sab82532
)))
1454 * Wait for any of the 4 modem inputs (DCD,RI,DSR,CTS) to change
1455 * - mask passed in arg for lines of interest
1456 * (use |'ed TIOCM_RNG/DSR/CD/CTS for masking)
1457 * Caller should use TIOCGICOUNT to see which one it was
1461 /* note the counters on entry */
1462 cprev
= info
->icount
;
1465 interruptible_sleep_on(&info
->delta_msr_wait
);
1466 /* see if a signal did it */
1467 if (signal_pending(current
))
1468 return -ERESTARTSYS
;
1470 cnow
= info
->icount
; /* atomic copy */
1472 if (cnow
.rng
== cprev
.rng
&& cnow
.dsr
== cprev
.dsr
&&
1473 cnow
.dcd
== cprev
.dcd
&& cnow
.cts
== cprev
.cts
)
1474 return -EIO
; /* no change => error */
1475 if ( ((arg
& TIOCM_RNG
) && (cnow
.rng
!= cprev
.rng
)) ||
1476 ((arg
& TIOCM_DSR
) && (cnow
.dsr
!= cprev
.dsr
)) ||
1477 ((arg
& TIOCM_CD
) && (cnow
.dcd
!= cprev
.dcd
)) ||
1478 ((arg
& TIOCM_CTS
) && (cnow
.cts
!= cprev
.cts
)) ) {
1486 * Get counter of input serial line interrupts (DCD,RI,DSR,CTS)
1487 * Return: write counters to the user passed counter struct
1488 * NB: both 1->0 and 0->1 transitions are counted except for
1489 * RI where only 0->1 is counted.
1493 cnow
= info
->icount
;
1495 p_cuser
= (struct serial_icounter_struct
*) arg
;
1496 error
= put_user(cnow
.cts
, &p_cuser
->cts
);
1497 if (error
) return error
;
1498 error
= put_user(cnow
.dsr
, &p_cuser
->dsr
);
1499 if (error
) return error
;
1500 error
= put_user(cnow
.rng
, &p_cuser
->rng
);
1501 if (error
) return error
;
1502 error
= put_user(cnow
.dcd
, &p_cuser
->dcd
);
1503 if (error
) return error
;
1507 return -ENOIOCTLCMD
;
1512 static void sab82532_set_termios(struct tty_struct
*tty
,
1513 struct termios
*old_termios
)
1515 struct sab82532
*info
= (struct sab82532
*)tty
->driver_data
;
1517 if ( (tty
->termios
->c_cflag
== old_termios
->c_cflag
)
1518 && ( RELEVANT_IFLAG(tty
->termios
->c_iflag
)
1519 == RELEVANT_IFLAG(old_termios
->c_iflag
)))
1524 /* Handle transition to B0 status */
1525 if ((old_termios
->c_cflag
& CBAUD
) &&
1526 !(tty
->termios
->c_cflag
& CBAUD
)) {
1527 writeb(readb(&info
->regs
->w
.mode
) | SAB82532_MODE_FRTS
, &info
->regs
->w
.mode
);
1528 writeb(readb(&info
->regs
->w
.mode
) | SAB82532_MODE_RTS
, &info
->regs
->w
.mode
);
1529 writeb(readb(&info
->regs
->w
.pvr
) | info
->pvr_dtr_bit
, &info
->regs
->w
.pvr
);
1532 /* Handle transition away from B0 status */
1533 if (!(old_termios
->c_cflag
& CBAUD
) &&
1534 (tty
->termios
->c_cflag
& CBAUD
)) {
1535 writeb(readb(&info
->regs
->w
.pvr
) & ~(info
->pvr_dtr_bit
), &info
->regs
->w
.pvr
);
1536 if (!tty
->hw_stopped
||
1537 !(tty
->termios
->c_cflag
& CRTSCTS
)) {
1538 writeb(readb(&info
->regs
->w
.mode
) & ~(SAB82532_MODE_FRTS
), &info
->regs
->w
.mode
);
1539 writeb(readb(&info
->regs
->w
.mode
) | SAB82532_MODE_RTS
, &info
->regs
->w
.mode
);
1543 /* Handle turning off CRTSCTS */
1544 if ((old_termios
->c_cflag
& CRTSCTS
) &&
1545 !(tty
->termios
->c_cflag
& CRTSCTS
)) {
1546 tty
->hw_stopped
= 0;
1547 sab82532_start(tty
);
1552 * No need to wake up processes in open wait, since they
1553 * sample the CLOCAL flag once, and don't recheck it.
1554 * XXX It's not clear whether the current behavior is correct
1555 * or not. Hence, this may change.....
1557 if (!(old_termios
->c_cflag
& CLOCAL
) &&
1558 (tty
->termios
->c_cflag
& CLOCAL
))
1559 wake_up_interruptible(&info
->open_wait
);
1564 * ------------------------------------------------------------
1567 * This routine is called when the serial port gets closed. First, we
1568 * wait for the last remaining data to be sent. Then, we unlink its
1569 * async structure from the interrupt chain if necessary, and we free
1570 * that IRQ if nothing is left in the chain.
1571 * ------------------------------------------------------------
1573 static void sab82532_close(struct tty_struct
*tty
, struct file
* filp
)
1575 struct sab82532
*info
= (struct sab82532
*)tty
->driver_data
;
1576 unsigned long flags
;
1578 if (!info
|| serial_paranoia_check(info
, tty
->device
, "sab82532_close"))
1581 save_flags(flags
); cli();
1583 if (tty_hung_up_p(filp
)) {
1585 restore_flags(flags
);
1589 #ifdef SERIAL_DEBUG_OPEN
1590 printk("sab82532_close ttys%d, count = %d\n", info
->line
, info
->count
);
1592 if ((tty
->count
== 1) && (info
->count
!= 1)) {
1594 * Uh, oh. tty->count is 1, which means that the tty
1595 * structure will be freed. info->count should always
1596 * be one in these conditions. If it's greater than
1597 * one, we've got real problems, since it means the
1598 * serial port won't be shutdown.
1600 printk("sab82532_close: bad serial port count; tty->count is 1,"
1601 " info->count is %d\n", info
->count
);
1604 if (--info
->count
< 0) {
1605 printk("sab82532_close: bad serial port count for ttys%d: %d\n",
1606 info
->line
, info
->count
);
1611 restore_flags(flags
);
1614 info
->flags
|= ASYNC_CLOSING
;
1616 * Save the termios structure, since this port may have
1617 * separate termios for callout and dialin.
1619 if (info
->flags
& ASYNC_NORMAL_ACTIVE
)
1620 info
->normal_termios
= *tty
->termios
;
1621 if (info
->flags
& ASYNC_CALLOUT_ACTIVE
)
1622 info
->callout_termios
= *tty
->termios
;
1624 * Now we wait for the transmit buffer to clear; and we notify
1625 * the line discipline to only process XON/XOFF characters.
1628 if (info
->closing_wait
!= ASYNC_CLOSING_WAIT_NONE
)
1629 tty_wait_until_sent(tty
, info
->closing_wait
);
1632 * At this point we stop accepting input. To do this, we
1633 * disable the receive line status interrupts, and turn off
1636 info
->interrupt_mask0
|= SAB82532_IMR0_TCD
;
1637 writeb(info
->interrupt_mask0
, &info
->regs
->w
.imr0
);
1639 writeb(readb(&info
->regs
->rw
.mode
) & ~(SAB82532_MODE_RAC
), &info
->regs
->rw
.mode
);
1641 if (info
->flags
& ASYNC_INITIALIZED
) {
1643 * Before we drop DTR, make sure the UART transmitter
1644 * has completely drained; this is especially
1645 * important if there is a transmit FIFO!
1647 sab82532_wait_until_sent(tty
, info
->timeout
);
1650 if (tty
->driver
.flush_buffer
)
1651 tty
->driver
.flush_buffer(tty
);
1652 if (tty
->ldisc
.flush_buffer
)
1653 tty
->ldisc
.flush_buffer(tty
);
1657 if (info
->blocked_open
) {
1658 if (info
->close_delay
) {
1659 current
->state
= TASK_INTERRUPTIBLE
;
1660 schedule_timeout(info
->close_delay
);
1662 wake_up_interruptible(&info
->open_wait
);
1664 info
->flags
&= ~(ASYNC_NORMAL_ACTIVE
|ASYNC_CALLOUT_ACTIVE
|
1666 wake_up_interruptible(&info
->close_wait
);
1668 restore_flags(flags
);
1672 * sab82532_wait_until_sent() --- wait until the transmitter is empty
1674 static void sab82532_wait_until_sent(struct tty_struct
*tty
, int timeout
)
1676 struct sab82532
*info
= (struct sab82532
*)tty
->driver_data
;
1677 unsigned long orig_jiffies
, char_time
;
1679 if (serial_paranoia_check(info
,tty
->device
,"sab82532_wait_until_sent"))
1682 orig_jiffies
= jiffies
;
1684 * Set the check interval to be 1/5 of the estimated time to
1685 * send a single character, and make it at least 1. The check
1686 * interval should also be less than the timeout.
1688 * Note: we have to use pretty tight timings here to satisfy
1691 char_time
= (info
->timeout
- HZ
/50) / info
->xmit_fifo_size
;
1692 char_time
= char_time
/ 5;
1696 char_time
= MIN(char_time
, timeout
);
1697 #ifdef SERIAL_DEBUG_WAIT_UNTIL_SENT
1698 printk("In sab82532_wait_until_sent(%d) check=%lu...", timeout
, char_time
);
1699 printk("jiff=%lu...", jiffies
);
1701 while (info
->xmit_cnt
|| !info
->all_sent
) {
1702 current
->state
= TASK_INTERRUPTIBLE
;
1703 schedule_timeout(char_time
);
1704 if (signal_pending(current
))
1706 if (timeout
&& time_after(jiffies
, orig_jiffies
+ timeout
))
1709 current
->state
= TASK_RUNNING
;
1710 #ifdef SERIAL_DEBUG_WAIT_UNTIL_SENT
1711 printk("xmit_cnt = %d, alls = %d (jiff=%lu)...done\n", info
->xmit_cnt
, info
->all_sent
, jiffies
);
1716 * sab82532_hangup() --- called by tty_hangup() when a hangup is signaled.
1718 static void sab82532_hangup(struct tty_struct
*tty
)
1720 struct sab82532
* info
= (struct sab82532
*)tty
->driver_data
;
1722 if (serial_paranoia_check(info
, tty
->device
, "sab82532_hangup"))
1725 if (info
->is_console
)
1728 sab82532_flush_buffer(tty
);
1732 info
->flags
&= ~(ASYNC_NORMAL_ACTIVE
|ASYNC_CALLOUT_ACTIVE
);
1734 wake_up_interruptible(&info
->open_wait
);
1738 * ------------------------------------------------------------
1739 * sab82532_open() and friends
1740 * ------------------------------------------------------------
1742 static int block_til_ready(struct tty_struct
*tty
, struct file
* filp
,
1743 struct sab82532
*info
)
1745 DECLARE_WAITQUEUE(wait
, current
);
1750 * If the device is in the middle of being closed, then block
1751 * until it's done, and then try again.
1753 if (tty_hung_up_p(filp
) ||
1754 (info
->flags
& ASYNC_CLOSING
)) {
1755 if (info
->flags
& ASYNC_CLOSING
)
1756 interruptible_sleep_on(&info
->close_wait
);
1757 #ifdef SERIAL_DO_RESTART
1758 if (info
->flags
& ASYNC_HUP_NOTIFY
)
1761 return -ERESTARTSYS
;
1768 * If this is a callout device, then just make sure the normal
1769 * device isn't being used.
1771 if (tty
->driver
.subtype
== SERIAL_TYPE_CALLOUT
) {
1772 if (info
->flags
& ASYNC_NORMAL_ACTIVE
)
1774 if ((info
->flags
& ASYNC_CALLOUT_ACTIVE
) &&
1775 (info
->flags
& ASYNC_SESSION_LOCKOUT
) &&
1776 (info
->session
!= current
->session
))
1778 if ((info
->flags
& ASYNC_CALLOUT_ACTIVE
) &&
1779 (info
->flags
& ASYNC_PGRP_LOCKOUT
) &&
1780 (info
->pgrp
!= current
->pgrp
))
1782 info
->flags
|= ASYNC_CALLOUT_ACTIVE
;
1787 * If non-blocking mode is set, or the port is not enabled,
1788 * then make the check up front and then exit.
1790 if ((filp
->f_flags
& O_NONBLOCK
) ||
1791 (tty
->flags
& (1 << TTY_IO_ERROR
))) {
1792 if (info
->flags
& ASYNC_CALLOUT_ACTIVE
)
1794 info
->flags
|= ASYNC_NORMAL_ACTIVE
;
1798 if (info
->flags
& ASYNC_CALLOUT_ACTIVE
) {
1799 if (info
->normal_termios
.c_cflag
& CLOCAL
)
1802 if (tty
->termios
->c_cflag
& CLOCAL
)
1807 * Block waiting for the carrier detect and the line to become
1808 * free (i.e., not in use by the callout). While we are in
1809 * this loop, info->count is dropped by one, so that
1810 * sab82532_close() knows when to free things. We restore it upon
1811 * exit, either normal or abnormal.
1814 add_wait_queue(&info
->open_wait
, &wait
);
1815 #ifdef SERIAL_DEBUG_OPEN
1816 printk("block_til_ready before block: ttyS%d, count = %d\n",
1817 info
->line
, info
->count
);
1820 if (!tty_hung_up_p(filp
))
1823 info
->blocked_open
++;
1826 if (!(info
->flags
& ASYNC_CALLOUT_ACTIVE
) &&
1827 (tty
->termios
->c_cflag
& CBAUD
)) {
1828 writeb(readb(&info
->regs
->rw
.pvr
) & ~(info
->pvr_dtr_bit
), &info
->regs
->rw
.pvr
);
1829 writeb(readb(&info
->regs
->rw
.mode
) | SAB82532_MODE_FRTS
, &info
->regs
->rw
.mode
);
1830 writeb(readb(&info
->regs
->rw
.mode
) & ~(SAB82532_MODE_RTS
), &info
->regs
->rw
.mode
);
1833 set_current_state(TASK_INTERRUPTIBLE
);
1834 if (tty_hung_up_p(filp
) ||
1835 !(info
->flags
& ASYNC_INITIALIZED
)) {
1836 #ifdef SERIAL_DO_RESTART
1837 if (info
->flags
& ASYNC_HUP_NOTIFY
)
1840 retval
= -ERESTARTSYS
;
1846 if (!(info
->flags
& ASYNC_CALLOUT_ACTIVE
) &&
1847 !(info
->flags
& ASYNC_CLOSING
) &&
1848 (do_clocal
|| !(readb(&info
->regs
->r
.vstr
) & SAB82532_VSTR_CD
)))
1850 if (signal_pending(current
)) {
1851 retval
= -ERESTARTSYS
;
1854 #ifdef SERIAL_DEBUG_OPEN
1855 printk("block_til_ready blocking: ttyS%d, count = %d, flags = %x, clocal = %d, vstr = %02x\n",
1856 info
->line
, info
->count
, info
->flags
, do_clocal
, readb(&info
->regs
->r
.vstr
));
1860 current
->state
= TASK_RUNNING
;
1861 remove_wait_queue(&info
->open_wait
, &wait
);
1862 if (!tty_hung_up_p(filp
))
1864 info
->blocked_open
--;
1865 #ifdef SERIAL_DEBUG_OPEN
1866 printk("block_til_ready after blocking: ttys%d, count = %d\n",
1867 info
->line
, info
->count
);
1871 info
->flags
|= ASYNC_NORMAL_ACTIVE
;
1876 * This routine is called whenever a serial port is opened. It
1877 * enables interrupts for a serial port, linking in its async structure into
1878 * the IRQ chain. It also performs the serial-specific
1879 * initialization for the tty structure.
1881 static int sab82532_open(struct tty_struct
*tty
, struct file
* filp
)
1883 struct sab82532
*info
= sab82532_chain
;
1887 #ifdef SERIAL_DEBUG_OPEN
1888 printk("sab82532_open: count = %d\n", info
->count
);
1891 line
= MINOR(tty
->device
) - tty
->driver
.minor_start
;
1892 if ((line
< 0) || (line
>= NR_PORTS
))
1896 if (info
->line
== line
)
1901 printk("sab82532_open: can't find info for line %d\n",
1906 if (serial_paranoia_check(info
, tty
->device
, "sab82532_open"))
1909 #ifdef SERIAL_DEBUG_OPEN
1910 printk("sab82532_open %s%d, count = %d\n", tty
->driver
.name
, info
->line
,
1915 tty
->driver_data
= info
;
1919 page
= get_free_page(GFP_KERNEL
);
1925 tmp_buf
= (unsigned char *) page
;
1929 * If the port is in the middle of closing, bail out now.
1931 if (tty_hung_up_p(filp
) ||
1932 (info
->flags
& ASYNC_CLOSING
)) {
1933 if (info
->flags
& ASYNC_CLOSING
)
1934 interruptible_sleep_on(&info
->close_wait
);
1935 #ifdef SERIAL_DO_RESTART
1936 return ((info
->flags
& ASYNC_HUP_NOTIFY
) ?
1937 -EAGAIN
: -ERESTARTSYS
);
1944 * Start up serial port
1946 retval
= startup(info
);
1951 retval
= block_til_ready(tty
, filp
, info
);
1953 #ifdef SERIAL_DEBUG_OPEN
1954 printk("sab82532_open returning after block_til_ready with %d\n",
1960 if ((info
->count
== 1) &&
1961 (info
->flags
& ASYNC_SPLIT_TERMIOS
)) {
1962 if (tty
->driver
.subtype
== SERIAL_TYPE_NORMAL
)
1963 *tty
->termios
= info
->normal_termios
;
1965 *tty
->termios
= info
->callout_termios
;
1969 #ifdef CONFIG_SERIAL_CONSOLE
1970 if (sab82532_console
.cflag
&& sab82532_console
.index
== line
) {
1971 tty
->termios
->c_cflag
= sab82532_console
.cflag
;
1972 sab82532_console
.cflag
= 0;
1977 info
->session
= current
->session
;
1978 info
->pgrp
= current
->pgrp
;
1980 #ifdef SERIAL_DEBUG_OPEN
1981 printk("sab82532_open ttys%d successful... count %d", info
->line
, info
->count
);
1987 * /proc fs routines....
1990 static __inline__
int
1991 line_info(char *buf
, struct sab82532
*info
)
1993 unsigned long flags
;
1997 ret
= sprintf(buf
, "%d: uart:SAB82532 ", info
->line
);
1998 switch (info
->type
) {
2000 ret
+= sprintf(buf
+ret
, "V1.0 ");
2003 ret
+= sprintf(buf
+ret
, "V2.0 ");
2006 ret
+= sprintf(buf
+ret
, "V3.2 ");
2009 ret
+= sprintf(buf
+ret
, "V?.? ");
2012 ret
+= sprintf(buf
+ret
, "port:%lX irq:%s",
2013 (unsigned long)info
->regs
, __irq_itoa(info
->irq
));
2016 ret
+= sprintf(buf
+ret
, "\n");
2021 * Figure out the current RS-232 lines
2025 save_flags(flags
); cli();
2026 if (readb(&info
->regs
->r
.mode
) & SAB82532_MODE_RTS
) {
2027 if (!(readb(&info
->regs
->r
.mode
) & SAB82532_MODE_FRTS
))
2028 strcat(stat_buf
, "|RTS");
2030 strcat(stat_buf
, "|RTS");
2032 if (readb(&info
->regs
->r
.star
) & SAB82532_STAR_CTS
)
2033 strcat(stat_buf
, "|CTS");
2034 if (!(readb(&info
->regs
->r
.pvr
) & info
->pvr_dtr_bit
))
2035 strcat(stat_buf
, "|DTR");
2036 if (!(readb(&info
->regs
->r
.pvr
) & info
->pvr_dsr_bit
))
2037 strcat(stat_buf
, "|DSR");
2038 if (!(readb(&info
->regs
->r
.vstr
) & SAB82532_VSTR_CD
))
2039 strcat(stat_buf
, "|CD");
2040 restore_flags(flags
);
2043 ret
+= sprintf(buf
+ret
, " baud:%d", info
->baud
);
2045 if (info
->icount
.frame
)
2046 ret
+= sprintf(buf
+ret
, " fe:%d", info
->icount
.frame
);
2048 if (info
->icount
.parity
)
2049 ret
+= sprintf(buf
+ret
, " pe:%d", info
->icount
.parity
);
2051 if (info
->icount
.brk
)
2052 ret
+= sprintf(buf
+ret
, " brk:%d", info
->icount
.brk
);
2054 if (info
->icount
.overrun
)
2055 ret
+= sprintf(buf
+ret
, " oe:%d", info
->icount
.overrun
);
2058 * Last thing is the RS-232 status lines.
2060 ret
+= sprintf(buf
+ret
, " %s\n", stat_buf
+ 1);
2064 int sab82532_read_proc(char *page
, char **start
, off_t off
, int count
,
2065 int *eof
, void *data
)
2067 struct sab82532
*info
= sab82532_chain
;
2071 len
+= sprintf(page
, "serinfo:1.0 driver:%s\n", serial_version
);
2072 for (info
= sab82532_chain
; info
&& len
< 4000; info
= info
->next
) {
2073 len
+= line_info(page
+ len
, info
);
2074 if (len
+begin
> off
+count
)
2076 if (len
+begin
< off
) {
2083 if (off
>= len
+begin
)
2085 *start
= page
+ (begin
-off
);
2086 return ((count
< begin
+len
-off
) ? count
: begin
+len
-off
);
2090 * ---------------------------------------------------------------------
2091 * sab82532_init() and friends
2093 * sab82532_init() is called at boot-time to initialize the serial driver.
2094 * ---------------------------------------------------------------------
2096 static int __init
get_sab82532(unsigned long *memory_start
)
2098 struct linux_ebus
*ebus
;
2099 struct linux_ebus_device
*edev
= 0;
2100 struct sab82532
*sab
;
2101 unsigned long regs
, offset
;
2104 for_each_ebus(ebus
) {
2105 for_each_ebusdev(edev
, ebus
) {
2106 if (!strcmp(edev
->prom_name
, "se"))
2114 regs
= edev
->resource
[0].start
;
2115 offset
= sizeof(union sab82532_async_regs
);
2117 for (i
= 0; i
< 2; i
++) {
2119 *memory_start
= (*memory_start
+ 7) & ~(7);
2120 sab
= (struct sab82532
*)*memory_start
;
2121 *memory_start
+= sizeof(struct sab82532
);
2123 sab
= (struct sab82532
*)kmalloc(sizeof(struct sab82532
),
2126 printk("sab82532: can't alloc sab struct\n");
2130 memset(sab
, 0, sizeof(struct sab82532
));
2132 sab
->regs
= (union sab82532_async_regs
*)(regs
+ offset
);
2133 sab
->irq
= edev
->irqs
[0];
2135 sab
->xmit_fifo_size
= 32;
2136 sab
->recv_fifo_size
= 32;
2138 writeb(SAB82532_IPC_IC_ACT_LOW
, &sab
->regs
->w
.ipc
);
2140 sab
->next
= sab82532_chain
;
2141 sab82532_chain
= sab
;
2143 offset
-= sizeof(union sab82532_async_regs
);
2148 static void __init
sab82532_kgdb_hook(int line
)
2150 prom_printf("sab82532: kgdb support is not implemented, yet\n");
2154 static inline void __init
show_serial_version(void)
2156 char *revision
= "$Revision: 1.35 $";
2159 version
= strchr(revision
, ' ');
2160 strcpy(serial_version
, ++version
);
2161 p
= strchr(serial_version
, ' ');
2163 printk("SAB82532 serial driver version %s\n", serial_version
);
2167 * The serial driver boot-time initialization code!
2169 int __init
sab82532_init(void)
2171 struct sab82532
*info
;
2174 if (!sab82532_chain
)
2176 if (!sab82532_chain
)
2179 init_bh(SERIAL_BH
, do_serial_bh
);
2181 show_serial_version();
2183 /* Initialize the tty_driver structure */
2184 memset(&serial_driver
, 0, sizeof(struct tty_driver
));
2185 serial_driver
.magic
= TTY_DRIVER_MAGIC
;
2186 serial_driver
.driver_name
= "serial";
2187 serial_driver
.name
= "ttyS";
2188 serial_driver
.major
= TTY_MAJOR
;
2189 serial_driver
.minor_start
= 64;
2190 serial_driver
.num
= NR_PORTS
;
2191 serial_driver
.type
= TTY_DRIVER_TYPE_SERIAL
;
2192 serial_driver
.subtype
= SERIAL_TYPE_NORMAL
;
2193 serial_driver
.init_termios
= tty_std_termios
;
2194 serial_driver
.init_termios
.c_cflag
=
2195 B9600
| CS8
| CREAD
| HUPCL
| CLOCAL
;
2196 serial_driver
.flags
= TTY_DRIVER_REAL_RAW
;
2197 serial_driver
.refcount
= &sab82532_refcount
;
2198 serial_driver
.table
= sab82532_table
;
2199 serial_driver
.termios
= sab82532_termios
;
2200 serial_driver
.termios_locked
= sab82532_termios_locked
;
2202 serial_driver
.open
= sab82532_open
;
2203 serial_driver
.close
= sab82532_close
;
2204 serial_driver
.write
= sab82532_write
;
2205 serial_driver
.put_char
= sab82532_put_char
;
2206 serial_driver
.flush_chars
= sab82532_flush_chars
;
2207 serial_driver
.write_room
= sab82532_write_room
;
2208 serial_driver
.chars_in_buffer
= sab82532_chars_in_buffer
;
2209 serial_driver
.flush_buffer
= sab82532_flush_buffer
;
2210 serial_driver
.ioctl
= sab82532_ioctl
;
2211 serial_driver
.throttle
= sab82532_throttle
;
2212 serial_driver
.unthrottle
= sab82532_unthrottle
;
2213 serial_driver
.send_xchar
= sab82532_send_xchar
;
2214 serial_driver
.set_termios
= sab82532_set_termios
;
2215 serial_driver
.stop
= sab82532_stop
;
2216 serial_driver
.start
= sab82532_start
;
2217 serial_driver
.hangup
= sab82532_hangup
;
2218 serial_driver
.break_ctl
= sab82532_break
;
2219 serial_driver
.wait_until_sent
= sab82532_wait_until_sent
;
2220 serial_driver
.read_proc
= sab82532_read_proc
;
2223 * The callout device is just like normal device except for
2224 * major number and the subtype code.
2226 callout_driver
= serial_driver
;
2227 callout_driver
.name
= "cua";
2228 callout_driver
.major
= TTYAUX_MAJOR
;
2229 callout_driver
.subtype
= SERIAL_TYPE_CALLOUT
;
2230 callout_driver
.read_proc
= 0;
2231 callout_driver
.proc_entry
= 0;
2233 if (tty_register_driver(&serial_driver
))
2234 panic("Couldn't register serial driver\n");
2235 if (tty_register_driver(&callout_driver
))
2236 panic("Couldn't register callout driver\n");
2238 for (info
= sab82532_chain
, i
= 0; info
; info
= info
->next
, i
++) {
2239 info
->magic
= SERIAL_MAGIC
;
2241 info
->type
= readb(&info
->regs
->r
.vstr
) & 0x0f;
2242 writeb(~((1 << 1) | (1 << 2) | (1 << 4)), &info
->regs
->w
.pcr
);
2243 writeb(0xff, &info
->regs
->w
.pim
);
2244 if (info
->line
== 0) {
2245 info
->pvr_dsr_bit
= (1 << 0);
2246 info
->pvr_dtr_bit
= (1 << 1);
2248 info
->pvr_dsr_bit
= (1 << 3);
2249 info
->pvr_dtr_bit
= (1 << 2);
2251 writeb((1 << 1) | (1 << 2) | (1 << 4), &info
->regs
->w
.pvr
);
2252 writeb(readb(&info
->regs
->rw
.mode
) | SAB82532_MODE_FRTS
, &info
->regs
->rw
.mode
);
2253 writeb(readb(&info
->regs
->rw
.mode
) | SAB82532_MODE_RTS
, &info
->regs
->rw
.mode
);
2255 info
->custom_divisor
= 16;
2256 info
->close_delay
= 5*HZ
/10;
2257 info
->closing_wait
= 30*HZ
;
2260 info
->blocked_open
= 0;
2261 info
->tqueue
.routine
= do_softint
;
2262 info
->tqueue
.data
= info
;
2263 info
->tqueue_hangup
.routine
= do_serial_hangup
;
2264 info
->tqueue_hangup
.data
= info
;
2265 info
->callout_termios
= callout_driver
.init_termios
;
2266 info
->normal_termios
= serial_driver
.init_termios
;
2267 init_waitqueue_head(&info
->open_wait
);
2268 init_waitqueue_head(&info
->close_wait
);
2269 init_waitqueue_head(&info
->delta_msr_wait
);
2270 info
->icount
.cts
= info
->icount
.dsr
=
2271 info
->icount
.rng
= info
->icount
.dcd
= 0;
2272 info
->icount
.rx
= info
->icount
.tx
= 0;
2273 info
->icount
.frame
= info
->icount
.parity
= 0;
2274 info
->icount
.overrun
= info
->icount
.brk
= 0;
2276 if (!(info
->line
& 0x01)) {
2277 if (request_irq(info
->irq
, sab82532_interrupt
, SA_SHIRQ
,
2278 "serial(sab82532)", info
)) {
2279 printk("sab82532: can't get IRQ %x\n",
2281 panic("sab82532 initialization failed");
2286 "ttyS%02d at 0x%lx (irq = %s) is a SAB82532 %s\n",
2287 info
->line
, (unsigned long)info
->regs
,
2288 __irq_itoa(info
->irq
), sab82532_version
[info
->type
]);
2291 #ifdef SERIAL_LOG_DEVICE
2292 dprint_init(SERIAL_LOG_DEVICE
);
2297 int __init
sab82532_probe(unsigned long *memory_start
)
2299 int node
, enode
, snode
;
2303 node
= prom_getchild(prom_root_node
);
2304 node
= prom_searchsiblings(node
, "pci");
2307 * Check for SUNW,sabre on Ultra 5/10/AXi.
2309 len
= prom_getproperty(node
, "model", model
, sizeof(model
));
2310 if ((len
> 0) && !strncmp(model
, "SUNW,sabre", len
)) {
2311 node
= prom_getchild(node
);
2312 node
= prom_searchsiblings(node
, "pci");
2316 * For each PCI bus...
2319 enode
= prom_getchild(node
);
2320 enode
= prom_searchsiblings(enode
, "ebus");
2323 * For each EBus on this PCI...
2326 snode
= prom_getchild(enode
);
2327 snode
= prom_searchsiblings(snode
, "se");
2331 enode
= prom_getsibling(enode
);
2332 enode
= prom_searchsiblings(enode
, "ebus");
2334 node
= prom_getsibling(node
);
2335 node
= prom_searchsiblings(node
, "pci");
2340 #ifdef CONFIG_SERIAL_CONSOLE
2341 sunserial_setinitfunc(memory_start
, sab82532_console_init
);
2343 sunserial_setinitfunc(memory_start
, sab82532_init
);
2344 rs_ops
.rs_kgdb_hook
= sab82532_kgdb_hook
;
2349 int init_module(void)
2351 if (get_sab82532(0))
2354 return sab82532_init();
2357 void cleanup_module(void)
2359 unsigned long flags
;
2362 /* printk("Unloading %s: version %s\n", serial_name, serial_version); */
2365 timer_active
&= ~(1 << RS_TIMER
);
2366 timer_table
[RS_TIMER
].fn
= NULL
;
2367 timer_table
[RS_TIMER
].expires
= 0;
2368 remove_bh(SERIAL_BH
);
2369 if ((e1
= tty_unregister_driver(&serial_driver
)))
2370 printk("SERIAL: failed to unregister serial driver (%d)\n",
2372 if ((e2
= tty_unregister_driver(&callout_driver
)))
2373 printk("SERIAL: failed to unregister callout driver (%d)\n",
2375 restore_flags(flags
);
2378 free_page((unsigned long) tmp_buf
);
2384 #ifdef CONFIG_SERIAL_CONSOLE
2386 static __inline__
void
2387 sab82532_console_putchar(struct sab82532
*info
, char c
)
2389 unsigned long flags
;
2391 save_flags(flags
); cli();
2392 sab82532_tec_wait(info
);
2393 writeb(c
, &info
->regs
->w
.tic
);
2394 restore_flags(flags
);
2398 sab82532_console_write(struct console
*con
, const char *s
, unsigned n
)
2400 struct sab82532
*info
;
2403 info
= sab82532_chain
;
2404 for (i
= con
->index
; i
; i
--) {
2410 for (i
= 0; i
< n
; i
++) {
2412 sab82532_console_putchar(info
, '\r');
2413 sab82532_console_putchar(info
, *s
++);
2415 sab82532_tec_wait(info
);
2419 sab82532_console_wait_key(struct console
*con
)
2421 sleep_on(&keypress_wait
);
2426 sab82532_console_device(struct console
*con
)
2428 return MKDEV(TTY_MAJOR
, 64 + con
->index
);
2432 sab82532_console_setup(struct console
*con
, char *options
)
2434 struct sab82532
*info
;
2439 unsigned long flags
;
2441 info
= sab82532_chain
;
2442 for (i
= con
->index
; i
; i
--) {
2447 info
->is_console
= 1;
2450 * Initialize the hardware
2452 sab82532_init_line(info
);
2455 * Finally, enable interrupts
2457 info
->interrupt_mask0
= SAB82532_IMR0_PERR
| SAB82532_IMR0_FERR
|
2458 SAB82532_IMR0_PLLA
| SAB82532_IMR0_CDSC
;
2459 writeb(info
->interrupt_mask0
, &info
->regs
->w
.imr0
);
2460 info
->interrupt_mask1
= SAB82532_IMR1_BRKT
| SAB82532_IMR1_ALLS
|
2461 SAB82532_IMR1_XOFF
| SAB82532_IMR1_TIN
|
2462 SAB82532_IMR1_CSC
| SAB82532_IMR1_XON
|
2464 writeb(info
->interrupt_mask1
, &info
->regs
->w
.imr1
);
2466 printk("Console: ttyS%d (SAB82532)\n", info
->line
);
2468 sunserial_console_termios(con
);
2471 /* Byte size and parity */
2472 switch (cflag
& CSIZE
) {
2473 case CS5
: dafo
= SAB82532_DAFO_CHL5
; bits
= 7; break;
2474 case CS6
: dafo
= SAB82532_DAFO_CHL6
; bits
= 8; break;
2475 case CS7
: dafo
= SAB82532_DAFO_CHL7
; bits
= 9; break;
2476 case CS8
: dafo
= SAB82532_DAFO_CHL8
; bits
= 10; break;
2477 /* Never happens, but GCC is too dumb to figure it out */
2478 default: dafo
= SAB82532_DAFO_CHL5
; bits
= 7; break;
2481 if (cflag
& CSTOPB
) {
2482 dafo
|= SAB82532_DAFO_STOP
;
2486 if (cflag
& PARENB
) {
2487 dafo
|= SAB82532_DAFO_PARE
;
2491 if (cflag
& PARODD
) {
2494 dafo
|= SAB82532_DAFO_PAR_MARK
;
2497 dafo
|= SAB82532_DAFO_PAR_ODD
;
2501 dafo
|= SAB82532_DAFO_PAR_SPACE
;
2504 dafo
|= SAB82532_DAFO_PAR_EVEN
;
2507 /* Determine EBRG values based on baud rate */
2511 if ((i
< 1) || ((i
+ 15) >= NR_EBRG_VALUES
))
2516 ebrg
= ebrg_table
[i
].n
;
2517 ebrg
|= (ebrg_table
[i
].m
<< 6);
2519 info
->baud
= ebrg_table
[i
].baud
;
2521 info
->timeout
= (info
->xmit_fifo_size
* HZ
* bits
) / info
->baud
;
2524 info
->timeout
+= HZ
/ 50; /* Add .02 seconds of slop */
2526 /* CTS flow control flags */
2527 if (cflag
& CRTSCTS
)
2528 info
->flags
|= ASYNC_CTS_FLOW
;
2530 info
->flags
&= ~(ASYNC_CTS_FLOW
);
2533 info
->flags
&= ~(ASYNC_CHECK_CD
);
2535 info
->flags
|= ASYNC_CHECK_CD
;
2537 save_flags(flags
); cli();
2538 if (readb(&info
->regs
->r
.star
) & SAB82532_STAR_CEC
)
2540 sab82532_tec_wait(info
);
2541 writeb(dafo
, &info
->regs
->w
.dafo
);
2542 writeb(ebrg
& 0xff, &info
->regs
->w
.bgr
);
2543 writeb(readb(&info
->regs
->rw
.ccr2
) & ~(0xc0), &info
->regs
->rw
.ccr2
);
2544 writeb(readb(&info
->regs
->rw
.ccr2
) | ((ebrg
>> 2) & 0xc0), &info
->regs
->rw
.ccr2
);
2545 if (info
->flags
& ASYNC_CTS_FLOW
) {
2546 writeb(readb(&info
->regs
->rw
.mode
) & ~(SAB82532_MODE_RTS
), &info
->regs
->rw
.mode
);
2547 writeb(readb(&info
->regs
->rw
.mode
) | SAB82532_MODE_FRTS
, &info
->regs
->rw
.mode
);
2548 writeb(readb(&info
->regs
->rw
.mode
) & ~(SAB82532_MODE_FCTS
), &info
->regs
->rw
.mode
);
2550 writeb(readb(&info
->regs
->rw
.mode
) | SAB82532_MODE_RTS
, &info
->regs
->rw
.mode
);
2551 writeb(readb(&info
->regs
->rw
.mode
) & ~(SAB82532_MODE_FRTS
), &info
->regs
->rw
.mode
);
2552 writeb(readb(&info
->regs
->rw
.mode
) | SAB82532_MODE_FCTS
, &info
->regs
->rw
.mode
);
2554 writeb(~(info
->pvr_dtr_bit
), &info
->regs
->rw
.pvr
);
2555 writeb(readb(&info
->regs
->rw
.mode
) | SAB82532_MODE_RAC
, &info
->regs
->rw
.mode
);
2556 restore_flags(flags
);
2561 static struct console sab82532_console
= {
2563 sab82532_console_write
,
2565 sab82532_console_device
,
2566 sab82532_console_wait_key
,
2568 sab82532_console_setup
,
2575 int __init
sab82532_console_init(void)
2577 extern int con_is_present(void);
2579 if (con_is_present())
2582 if (!sab82532_chain
) {
2583 prom_printf("sab82532_console_setup: can't get SAB82532 chain");
2587 sab82532_console
.index
= serial_console
- 1;
2588 register_console(&sab82532_console
);
2592 #ifdef SERIAL_LOG_DEVICE
2594 static int serial_log_device
= 0;
2597 dprint_init(int tty
)
2599 serial_console
= tty
+ 1;
2600 sab82532_console
.index
= tty
;
2601 sab82532_console_setup(&sab82532_console
, "");
2603 serial_log_device
= tty
+ 1;
2607 dprintf(const char *fmt
, ...)
2609 static char buffer
[4096];
2613 if (!serial_log_device
)
2616 va_start(args
, fmt
);
2617 i
= vsprintf(buffer
, fmt
, args
);
2619 sab82532_console
.write(&sab82532_console
, buffer
, i
);
2622 #endif /* SERIAL_LOG_DEVICE */
2623 #endif /* CONFIG_SERIAL_CONSOLE */