1 /* $Id: sab82532.c,v 1.31 1999/05/12 11:15:10 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 ((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 (!(info
->regs
->r
.star
& SAB82532_STAR_XFW
))
195 for (i
= 0; i
< info
->xmit_fifo_size
; i
++) {
196 info
->regs
->w
.xfifo
[i
] = info
->xmit_buf
[info
->xmit_tail
++];
197 info
->xmit_tail
&= (SERIAL_XMIT_SIZE
- 1);
199 if (--info
->xmit_cnt
<= 0)
203 /* Issue a Transmit Frame command. */
204 if (info
->regs
->r
.star
& SAB82532_STAR_CEC
)
206 info
->regs
->w
.cmdr
= SAB82532_CMDR_XF
;
209 restore_flags(flags
);
214 * ------------------------------------------------------------
215 * sab82532_stop() and sab82532_start()
217 * This routines are called before setting or resetting tty->stopped.
218 * They enable or disable transmitter interrupts, as necessary.
219 * ------------------------------------------------------------
221 static void sab82532_stop(struct tty_struct
*tty
)
223 struct sab82532
*info
= (struct sab82532
*)tty
->driver_data
;
226 if (serial_paranoia_check(info
, tty
->device
, "sab82532_stop"))
229 save_flags(flags
); cli();
230 info
->interrupt_mask1
|= SAB82532_IMR1_XPR
;
231 info
->regs
->w
.imr1
= info
->interrupt_mask1
;
232 restore_flags(flags
);
235 static void sab82532_start(struct tty_struct
*tty
)
237 struct sab82532
*info
= (struct sab82532
*)tty
->driver_data
;
240 if (serial_paranoia_check(info
, tty
->device
, "sab82532_start"))
243 save_flags(flags
); cli();
244 info
->interrupt_mask1
&= ~(SAB82532_IMR1_XPR
);
245 info
->regs
->w
.imr1
= info
->interrupt_mask1
;
246 sab82532_start_tx(info
);
247 restore_flags(flags
);
250 static void batten_down_hatches(struct sab82532
*info
)
252 unsigned char saved_rfc
;
254 /* If we are doing kadb, we call the debugger
255 * else we just drop into the boot monitor.
256 * Note that we must flush the user windows
257 * first before giving up control.
260 flush_user_windows();
263 * Set FIFO to single character mode.
265 saved_rfc
= info
->regs
->r
.rfc
;
266 info
->regs
->rw
.rfc
&= ~(SAB82532_RFC_RFDF
);
267 if (info
->regs
->r
.star
& SAB82532_STAR_CEC
)
269 info
->regs
->w
.cmdr
= SAB82532_CMDR_RRES
;
272 if ((((unsigned long)linux_dbvec
) >= DEBUG_FIRSTVADDR
) &&
273 (((unsigned long)linux_dbvec
) <= DEBUG_LASTVADDR
))
280 * Reset FIFO to character + status mode.
282 info
->regs
->w
.rfc
= saved_rfc
;
283 if (info
->regs
->r
.star
& SAB82532_STAR_CEC
)
285 info
->regs
->w
.cmdr
= SAB82532_CMDR_RRES
;
289 * ----------------------------------------------------------------------
291 * Here starts the interrupt handling routines. All of the following
292 * subroutines are declared as inline and are folded into
293 * sab82532_interrupt(). They were separated out for readability's sake.
295 * Note: sab82532_interrupt() is a "fast" interrupt, which means that it
296 * runs with interrupts turned off. People who may want to modify
297 * sab82532_interrupt() should try to keep the interrupt handler as fast as
298 * possible. After you are done making modifications, it is not a bad
301 * gcc -S -DKERNEL -Wall -Wstrict-prototypes -O6 -fomit-frame-pointer serial.c
303 * and look at the resulting assemble code in serial.s.
305 * - Ted Ts'o (tytso@mit.edu), 7-Mar-93
306 * -----------------------------------------------------------------------
310 * This routine is used by the interrupt handler to schedule
311 * processing in the software interrupt portion of the driver.
313 static inline void sab82532_sched_event(struct sab82532
*info
, int event
)
315 info
->event
|= 1 << event
;
316 queue_task(&info
->tqueue
, &tq_serial
);
320 static inline void receive_chars(struct sab82532
*info
,
321 union sab82532_irq_status
*stat
)
323 struct tty_struct
*tty
= info
->tty
;
324 unsigned char buf
[32];
325 unsigned char status
;
329 /* Read number of BYTES (Character + Status) available. */
330 if (stat
->sreg
.isr0
& SAB82532_ISR0_RPF
) {
331 count
= info
->recv_fifo_size
;
335 if (stat
->sreg
.isr0
& SAB82532_ISR0_TCD
) {
336 count
= info
->regs
->r
.rbcl
& (info
->recv_fifo_size
- 1);
340 /* Issue a FIFO read command in case we where idle. */
341 if (stat
->sreg
.isr0
& SAB82532_ISR0_TIME
) {
342 if (info
->regs
->r
.star
& SAB82532_STAR_CEC
)
344 info
->regs
->w
.cmdr
= SAB82532_CMDR_RFRD
;
347 if (stat
->sreg
.isr0
& SAB82532_ISR0_RFO
) {
349 printk("sab82532: receive_chars: RFO");
355 for (i
= 0; i
< count
; i
++)
356 buf
[i
] = info
->regs
->r
.rfifo
[i
];
358 /* Issue Receive Message Complete command. */
360 if (info
->regs
->r
.star
& SAB82532_STAR_CEC
)
362 info
->regs
->w
.cmdr
= SAB82532_CMDR_RMC
;
365 if (info
->is_console
)
366 wake_up(&keypress_wait
);
370 for (i
= 0; i
< count
; ) {
371 if (tty
->flip
.count
>= TTY_FLIPBUF_SIZE
) {
373 printk("sab82532: receive_chars: tty overrun\n");
375 info
->icount
.buf_overrun
++;
380 *tty
->flip
.char_buf_ptr
++ = buf
[i
++];
384 #ifdef SERIAL_DEBUG_INTR
385 printk("DR%02x:%02x...", (unsigned char)*(tty
->flip
.char_buf_ptr
- 1), status
);
388 if (status
& SAB82532_RSTAT_PE
) {
389 *tty
->flip
.flag_buf_ptr
++ = TTY_PARITY
;
390 info
->icount
.parity
++;
391 } else if (status
& SAB82532_RSTAT_FE
) {
392 *tty
->flip
.flag_buf_ptr
++ = TTY_FRAME
;
393 info
->icount
.frame
++;
396 else if (status
& SAB82532_RSTAT_PARITY
)
397 *tty
->flip
.flag_buf_ptr
++ = TTY_PARITY
;
400 *tty
->flip
.flag_buf_ptr
++ = TTY_NORMAL
;
403 queue_task(&tty
->flip
.tqueue
, &tq_timer
);
406 static inline void transmit_chars(struct sab82532
*info
,
407 union sab82532_irq_status
*stat
)
411 if (stat
->sreg
.isr1
& SAB82532_ISR1_ALLS
)
413 if (!(info
->regs
->r
.star
& SAB82532_STAR_XFW
))
417 info
->interrupt_mask1
|= SAB82532_IMR1_XPR
;
418 info
->regs
->w
.imr1
= info
->interrupt_mask1
;
422 if ((info
->xmit_cnt
<= 0) || info
->tty
->stopped
||
423 info
->tty
->hw_stopped
) {
424 info
->interrupt_mask1
|= SAB82532_IMR1_XPR
;
425 info
->regs
->w
.imr1
= info
->interrupt_mask1
;
429 /* Stuff 32 bytes into Transmit FIFO. */
431 for (i
= 0; i
< info
->xmit_fifo_size
; i
++) {
432 info
->regs
->w
.xfifo
[i
] = info
->xmit_buf
[info
->xmit_tail
++];
433 info
->xmit_tail
&= (SERIAL_XMIT_SIZE
- 1);
435 if (--info
->xmit_cnt
<= 0)
439 /* Issue a Transmit Frame command. */
440 if (info
->regs
->r
.star
& SAB82532_STAR_CEC
)
442 info
->regs
->w
.cmdr
= SAB82532_CMDR_XF
;
444 if (info
->xmit_cnt
< WAKEUP_CHARS
)
445 sab82532_sched_event(info
, RS_EVENT_WRITE_WAKEUP
);
447 #ifdef SERIAL_DEBUG_INTR
450 if (info
->xmit_cnt
<= 0) {
451 info
->interrupt_mask1
|= SAB82532_IMR1_XPR
;
452 info
->regs
->w
.imr1
= info
->interrupt_mask1
;
456 static inline void check_status(struct sab82532
*info
,
457 union sab82532_irq_status
*stat
)
459 struct tty_struct
*tty
= info
->tty
;
460 int modem_change
= 0;
462 if (stat
->sreg
.isr1
& SAB82532_ISR1_BRK
) {
463 if (info
->is_console
) {
464 batten_down_hatches(info
);
467 if (tty
->flip
.count
>= TTY_FLIPBUF_SIZE
) {
468 info
->icount
.buf_overrun
++;
472 *tty
->flip
.flag_buf_ptr
++ = TTY_PARITY
;
473 *tty
->flip
.char_buf_ptr
++ = 0;
480 if (stat
->sreg
.isr0
& SAB82532_ISR0_RFO
) {
481 if (tty
->flip
.count
>= TTY_FLIPBUF_SIZE
) {
482 info
->icount
.buf_overrun
++;
486 *tty
->flip
.flag_buf_ptr
++ = TTY_PARITY
;
487 *tty
->flip
.char_buf_ptr
++ = 0;
488 info
->icount
.overrun
++;
492 if (stat
->sreg
.isr0
& SAB82532_ISR0_CDSC
) {
493 info
->dcd
= (info
->regs
->r
.vstr
& SAB82532_VSTR_CD
) ? 0 : 1;
497 printk("DCD change: %d\n", info
->icount
.dcd
);
500 if (stat
->sreg
.isr1
& SAB82532_ISR1_CSC
) {
501 info
->cts
= info
->regs
->r
.star
& SAB82532_STAR_CTS
;
505 printk("CTS change: %d, CTS %s\n", info
->icount
.cts
, info
->cts
? "on" : "off");
508 if ((info
->regs
->r
.pvr
& info
->pvr_dsr_bit
) ^ info
->dsr
) {
509 info
->dsr
= (info
->regs
->r
.pvr
& info
->pvr_dsr_bit
) ? 0 : 1;
513 printk("DSR change: %d\n", info
->icount
.dsr
);
517 wake_up_interruptible(&info
->delta_msr_wait
);
519 if ((info
->flags
& ASYNC_CHECK_CD
) &&
520 (stat
->sreg
.isr0
& SAB82532_ISR0_CDSC
)) {
522 #if (defined(SERIAL_DEBUG_OPEN) || defined(SERIAL_DEBUG_INTR))
523 printk("ttys%d CD now %s...", info
->line
,
524 (info
->dcd
) ? "on" : "off");
528 wake_up_interruptible(&info
->open_wait
);
529 else if (!((info
->flags
& ASYNC_CALLOUT_ACTIVE
) &&
530 (info
->flags
& ASYNC_CALLOUT_NOHUP
))) {
532 #ifdef SERIAL_DEBUG_OPEN
533 printk("scheduling hangup...");
536 queue_task(&info
->tqueue_hangup
, &tq_scheduler
);
540 if (info
->flags
& ASYNC_CTS_FLOW
) {
541 if (info
->tty
->hw_stopped
) {
544 #if (defined(SERIAL_DEBUG_INTR) || defined(SERIAL_DEBUG_FLOW))
545 printk("CTS tx start...");
547 info
->tty
->hw_stopped
= 0;
548 sab82532_sched_event(info
,
549 RS_EVENT_WRITE_WAKEUP
);
550 info
->interrupt_mask1
&= ~(SAB82532_IMR1_XPR
);
551 info
->regs
->w
.imr1
= info
->interrupt_mask1
;
552 sab82532_start_tx(info
);
557 #if (defined(SERIAL_DEBUG_INTR) || defined(SERIAL_DEBUG_FLOW))
558 printk("CTS tx stop...");
560 info
->tty
->hw_stopped
= 1;
567 * This is the serial driver's generic interrupt routine
569 static void sab82532_interrupt(int irq
, void *dev_id
, struct pt_regs
*regs
)
571 struct sab82532
*info
= dev_id
;
572 union sab82532_irq_status status
;
574 #ifdef SERIAL_DEBUG_INTR
575 printk("sab82532_interrupt(%d)...", irq
);
579 if (info
->regs
->r
.gis
& SAB82532_GIS_ISA0
)
580 status
.sreg
.isr0
= info
->regs
->r
.isr0
;
581 if (info
->regs
->r
.gis
& SAB82532_GIS_ISA1
)
582 status
.sreg
.isr1
= info
->regs
->r
.isr1
;
584 #ifdef SERIAL_DEBUG_INTR
585 printk("%d<%02x.%02x>", info
->line
,
586 status
.sreg
.isr0
, status
.sreg
.isr1
);
592 if (status
.sreg
.isr0
& (SAB82532_ISR0_TCD
| SAB82532_ISR0_TIME
|
593 SAB82532_ISR0_RFO
| SAB82532_ISR0_RPF
))
594 receive_chars(info
, &status
);
595 if ((status
.sreg
.isr0
& SAB82532_ISR0_CDSC
) ||
596 (status
.sreg
.isr1
& (SAB82532_ISR1_BRK
| SAB82532_ISR1_CSC
)))
597 check_status(info
, &status
);
598 if (status
.sreg
.isr1
& (SAB82532_ISR1_ALLS
| SAB82532_ISR1_XPR
))
599 transmit_chars(info
, &status
);
604 if (info
->regs
->r
.gis
& SAB82532_GIS_ISB0
)
605 status
.sreg
.isr0
= info
->regs
->r
.isr0
;
606 if (info
->regs
->r
.gis
& SAB82532_GIS_ISB1
)
607 status
.sreg
.isr1
= info
->regs
->r
.isr1
;
609 #ifdef SERIAL_DEBUG_INTR
610 printk("%d<%02x.%02x>", info
->line
,
611 status
.sreg
.isr0
, status
.sreg
.isr1
);
617 if (status
.sreg
.isr0
& (SAB82532_ISR0_TCD
| SAB82532_ISR0_TIME
|
618 SAB82532_ISR0_RFO
| SAB82532_ISR0_RPF
))
619 receive_chars(info
, &status
);
620 if ((status
.sreg
.isr0
& SAB82532_ISR0_CDSC
) ||
621 (status
.sreg
.isr1
& (SAB82532_ISR1_BRK
| SAB82532_ISR1_CSC
)))
622 check_status(info
, &status
);
623 if (status
.sreg
.isr1
& (SAB82532_ISR1_ALLS
| SAB82532_ISR1_XPR
))
624 transmit_chars(info
, &status
);
627 #ifdef SERIAL_DEBUG_INTR
633 * -------------------------------------------------------------------
634 * Here ends the serial interrupt routines.
635 * -------------------------------------------------------------------
639 * This routine is used to handle the "bottom half" processing for the
640 * serial driver, known also the "software interrupt" processing.
641 * This processing is done at the kernel interrupt level, after the
642 * sab82532_interrupt() has returned, BUT WITH INTERRUPTS TURNED ON. This
643 * is where time-consuming activities which can not be done in the
644 * interrupt driver proper are done; the interrupt driver schedules
645 * them using sab82532_sched_event(), and they get done here.
647 static void do_serial_bh(void)
649 run_task_queue(&tq_serial
);
652 static void do_softint(void *private_
)
654 struct sab82532
*info
= (struct sab82532
*)private_
;
655 struct tty_struct
*tty
;
661 if (test_and_clear_bit(RS_EVENT_WRITE_WAKEUP
, &info
->event
)) {
662 if ((tty
->flags
& (1 << TTY_DO_WRITE_WAKEUP
)) &&
663 tty
->ldisc
.write_wakeup
)
664 (tty
->ldisc
.write_wakeup
)(tty
);
665 wake_up_interruptible(&tty
->write_wait
);
670 * This routine is called from the scheduler tqueue when the interrupt
671 * routine has signalled that a hangup has occurred. The path of
672 * hangup processing is:
674 * serial interrupt routine -> (scheduler tqueue) ->
675 * do_serial_hangup() -> tty->hangup() -> sab82532_hangup()
678 static void do_serial_hangup(void *private_
)
680 struct sab82532
*info
= (struct sab82532
*) private_
;
681 struct tty_struct
*tty
;
691 sab82532_init_line(struct sab82532
*info
)
696 * Wait for any commands or immediate characters
698 if (info
->regs
->r
.star
& SAB82532_STAR_CEC
)
700 sab82532_tec_wait(info
);
703 * Clear the FIFO buffers.
705 if (info
->regs
->r
.star
& SAB82532_STAR_CEC
)
707 info
->regs
->w
.cmdr
= SAB82532_CMDR_RRES
;
708 if (info
->regs
->r
.star
& SAB82532_STAR_CEC
)
710 info
->regs
->w
.cmdr
= SAB82532_CMDR_XRES
;
713 * Clear the interrupt registers.
715 stat
= info
->regs
->r
.isr0
;
716 stat
= info
->regs
->r
.isr1
;
719 * Now, initialize the UART
721 info
->regs
->w
.ccr0
= 0; /* power-down */
722 info
->regs
->w
.ccr0
= SAB82532_CCR0_MCE
| SAB82532_CCR0_SC_NRZ
|
723 SAB82532_CCR0_SM_ASYNC
;
724 info
->regs
->w
.ccr1
= SAB82532_CCR1_ODS
| SAB82532_CCR1_BCR
| 7;
725 info
->regs
->w
.ccr2
= SAB82532_CCR2_BDF
| SAB82532_CCR2_SSEL
|
727 info
->regs
->w
.ccr3
= 0;
728 info
->regs
->w
.ccr4
= SAB82532_CCR4_MCK4
| SAB82532_CCR4_EBRG
;
729 info
->regs
->w
.mode
= SAB82532_MODE_RTS
| SAB82532_MODE_FCTS
|
731 info
->regs
->w
.rfc
= SAB82532_RFC_DPS
| SAB82532_RFC_RFDF
;
732 switch (info
->recv_fifo_size
) {
734 info
->regs
->w
.rfc
|= SAB82532_RFC_RFTH_1
;
737 info
->regs
->w
.rfc
|= SAB82532_RFC_RFTH_4
;
740 info
->regs
->w
.rfc
|= SAB82532_RFC_RFTH_16
;
743 info
->recv_fifo_size
= 32;
746 info
->regs
->w
.rfc
|= SAB82532_RFC_RFTH_32
;
749 info
->regs
->rw
.ccr0
|= SAB82532_CCR0_PU
; /* power-up */
752 static int startup(struct sab82532
*info
)
758 page
= get_free_page(GFP_KERNEL
);
762 save_flags(flags
); cli();
764 if (info
->flags
& ASYNC_INITIALIZED
) {
771 set_bit(TTY_IO_ERROR
, &info
->tty
->flags
);
779 info
->xmit_buf
= (unsigned char *)page
;
781 #ifdef SERIAL_DEBUG_OPEN
782 printk("starting up serial port %d...", info
->line
);
786 * Initialize the Hardware
788 sab82532_init_line(info
);
790 if (info
->tty
->termios
->c_cflag
& CBAUD
) {
791 info
->regs
->rw
.mode
&= ~(SAB82532_MODE_FRTS
);
792 info
->regs
->rw
.mode
|= SAB82532_MODE_RTS
;
793 info
->regs
->rw
.pvr
&= ~(info
->pvr_dtr_bit
);
797 * Finally, enable interrupts
799 info
->interrupt_mask0
= SAB82532_IMR0_PERR
| SAB82532_IMR0_FERR
|
801 info
->regs
->w
.imr0
= info
->interrupt_mask0
;
802 info
->interrupt_mask1
= SAB82532_IMR1_BRKT
| SAB82532_IMR1_XOFF
|
803 SAB82532_IMR1_TIN
| SAB82532_IMR1_XON
|
805 info
->regs
->w
.imr1
= info
->interrupt_mask1
;
808 clear_bit(TTY_IO_ERROR
, &info
->tty
->flags
);
809 info
->xmit_cnt
= info
->xmit_head
= info
->xmit_tail
= 0;
812 * and set the speed of the serial port
816 info
->flags
|= ASYNC_INITIALIZED
;
817 restore_flags(flags
);
821 restore_flags(flags
);
826 * This routine will shutdown a serial port; interrupts are disabled, and
827 * DTR is dropped if the hangup on close termio flag is on.
829 static void shutdown(struct sab82532
*info
)
833 if (!(info
->flags
& ASYNC_INITIALIZED
))
836 #ifdef SERIAL_DEBUG_OPEN
837 printk("Shutting down serial port %d...", info
->line
);
840 save_flags(flags
); cli(); /* Disable interrupts */
843 * clear delta_msr_wait queue to avoid mem leaks: we may free the irq
844 * here so the queue might never be waken up
846 wake_up_interruptible(&info
->delta_msr_wait
);
848 if (info
->xmit_buf
) {
849 free_page((unsigned long)info
->xmit_buf
);
853 if (info
->is_console
) {
854 info
->interrupt_mask0
= SAB82532_IMR0_PERR
| SAB82532_IMR0_FERR
|
855 SAB82532_IMR0_PLLA
| SAB82532_IMR0_CDSC
;
856 info
->regs
->w
.imr0
= info
->interrupt_mask0
;
857 info
->interrupt_mask1
= SAB82532_IMR1_BRKT
| SAB82532_IMR1_ALLS
|
858 SAB82532_IMR1_XOFF
| SAB82532_IMR1_TIN
|
859 SAB82532_IMR1_CSC
| SAB82532_IMR1_XON
|
861 info
->regs
->w
.imr1
= info
->interrupt_mask1
;
863 set_bit(TTY_IO_ERROR
, &info
->tty
->flags
);
864 info
->flags
&= ~ASYNC_INITIALIZED
;
865 restore_flags(flags
);
869 /* Disable Interrupts */
870 info
->interrupt_mask0
= 0xff;
871 info
->regs
->w
.imr0
= info
->interrupt_mask0
;
872 info
->interrupt_mask1
= 0xff;
873 info
->regs
->w
.imr1
= info
->interrupt_mask1
;
875 if (!info
->tty
|| (info
->tty
->termios
->c_cflag
& HUPCL
)) {
876 info
->regs
->rw
.mode
|= SAB82532_MODE_FRTS
;
877 info
->regs
->rw
.mode
|= SAB82532_MODE_RTS
;
878 info
->regs
->rw
.pvr
|= info
->pvr_dtr_bit
;
881 /* Disable break condition */
882 info
->regs
->rw
.dafo
&= ~(SAB82532_DAFO_XBRK
);
884 /* Disable Receiver */
885 info
->regs
->rw
.mode
&= ~(SAB82532_MODE_RAC
);
888 info
->regs
->rw
.ccr0
&= ~(SAB82532_CCR0_PU
);
891 set_bit(TTY_IO_ERROR
, &info
->tty
->flags
);
893 info
->flags
&= ~ASYNC_INITIALIZED
;
894 restore_flags(flags
);
898 * This routine is called to set the UART divisor registers to match
899 * the specified baud rate for a serial port.
901 static void change_speed(struct sab82532
*info
)
909 if (!info
->tty
|| !info
->tty
->termios
)
911 cflag
= info
->tty
->termios
->c_cflag
;
913 /* Byte size and parity */
914 switch (cflag
& CSIZE
) {
915 case CS5
: dafo
= SAB82532_DAFO_CHL5
; bits
= 7; break;
916 case CS6
: dafo
= SAB82532_DAFO_CHL6
; bits
= 8; break;
917 case CS7
: dafo
= SAB82532_DAFO_CHL7
; bits
= 9; break;
918 case CS8
: dafo
= SAB82532_DAFO_CHL8
; bits
= 10; break;
919 /* Never happens, but GCC is too dumb to figure it out */
920 default: dafo
= SAB82532_DAFO_CHL5
; bits
= 7; break;
923 if (cflag
& CSTOPB
) {
924 dafo
|= SAB82532_DAFO_STOP
;
928 if (cflag
& PARENB
) {
929 dafo
|= SAB82532_DAFO_PARE
;
933 if (cflag
& PARODD
) {
936 dafo
|= SAB82532_DAFO_PAR_MARK
;
939 dafo
|= SAB82532_DAFO_PAR_ODD
;
943 dafo
|= SAB82532_DAFO_PAR_SPACE
;
946 dafo
|= SAB82532_DAFO_PAR_EVEN
;
949 /* Determine EBRG values based on baud rate */
953 if ((i
< 1) || ((i
+ 15) >= NR_EBRG_VALUES
))
954 info
->tty
->termios
->c_cflag
&= ~CBAUDEX
;
958 ebrg
= ebrg_table
[i
].n
;
959 ebrg
|= (ebrg_table
[i
].m
<< 6);
961 info
->baud
= ebrg_table
[i
].baud
;
963 info
->timeout
= (info
->xmit_fifo_size
* HZ
* bits
) / info
->baud
;
966 info
->timeout
+= HZ
/ 50; /* Add .02 seconds of slop */
968 /* CTS flow control flags */
970 info
->flags
|= ASYNC_CTS_FLOW
;
972 info
->flags
&= ~(ASYNC_CTS_FLOW
);
975 info
->flags
&= ~(ASYNC_CHECK_CD
);
977 info
->flags
|= ASYNC_CHECK_CD
;
979 info
->tty
->hw_stopped
= 0;
982 * Set up parity check flag
983 * XXX: not implemented, yet.
985 #define RELEVANT_IFLAG(iflag) (iflag & (IGNBRK|BRKINT|IGNPAR|PARMRK|INPCK))
988 * Characters to ignore
989 * XXX: not implemented, yet.
993 * !!! ignore all characters if CREAD is not set
994 * XXX: not implemented, yet.
996 if ((cflag
& CREAD
) == 0)
997 info
->ignore_status_mask
|= SAB82532_ISR0_RPF
|
1001 save_flags(flags
); cli();
1002 if (info
->regs
->r
.star
& SAB82532_STAR_CEC
)
1004 sab82532_tec_wait(info
);
1005 info
->regs
->w
.dafo
= dafo
;
1006 info
->regs
->w
.bgr
= ebrg
& 0xff;
1007 info
->regs
->rw
.ccr2
&= ~(0xc0);
1008 info
->regs
->rw
.ccr2
|= (ebrg
>> 2) & 0xc0;
1009 if (info
->flags
& ASYNC_CTS_FLOW
) {
1010 info
->regs
->rw
.mode
&= ~(SAB82532_MODE_RTS
);
1011 info
->regs
->rw
.mode
|= SAB82532_MODE_FRTS
;
1012 info
->regs
->rw
.mode
&= ~(SAB82532_MODE_FCTS
);
1014 info
->regs
->rw
.mode
|= SAB82532_MODE_RTS
;
1015 info
->regs
->rw
.mode
&= ~(SAB82532_MODE_FRTS
);
1016 info
->regs
->rw
.mode
|= SAB82532_MODE_FCTS
;
1018 info
->regs
->rw
.mode
|= SAB82532_MODE_RAC
;
1019 restore_flags(flags
);
1022 static void sab82532_put_char(struct tty_struct
*tty
, unsigned char ch
)
1024 struct sab82532
*info
= (struct sab82532
*)tty
->driver_data
;
1025 unsigned long flags
;
1027 if (serial_paranoia_check(info
, tty
->device
, "sab82532_put_char"))
1030 if (!tty
|| !info
->xmit_buf
)
1033 save_flags(flags
); cli();
1034 if (info
->xmit_cnt
>= SERIAL_XMIT_SIZE
- 1) {
1035 restore_flags(flags
);
1039 info
->xmit_buf
[info
->xmit_head
++] = ch
;
1040 info
->xmit_head
&= SERIAL_XMIT_SIZE
-1;
1042 restore_flags(flags
);
1045 static void sab82532_flush_chars(struct tty_struct
*tty
)
1047 struct sab82532
*info
= (struct sab82532
*)tty
->driver_data
;
1048 unsigned long flags
;
1050 if (serial_paranoia_check(info
, tty
->device
, "sab82532_flush_chars"))
1053 if (info
->xmit_cnt
<= 0 || tty
->stopped
|| tty
->hw_stopped
||
1057 save_flags(flags
); cli();
1058 info
->interrupt_mask1
&= ~(SAB82532_IMR1_XPR
);
1059 info
->regs
->w
.imr1
= info
->interrupt_mask1
;
1060 sab82532_start_tx(info
);
1061 restore_flags(flags
);
1064 static int sab82532_write(struct tty_struct
* tty
, int from_user
,
1065 const unsigned char *buf
, int count
)
1068 struct sab82532
*info
= (struct sab82532
*)tty
->driver_data
;
1069 unsigned long flags
;
1071 if (serial_paranoia_check(info
, tty
->device
, "sab82532_write"))
1074 if (!tty
|| !info
->xmit_buf
|| !tmp_buf
)
1082 c
= MIN(count
, MIN(SERIAL_XMIT_SIZE
- info
->xmit_cnt
- 1,
1083 SERIAL_XMIT_SIZE
- info
->xmit_head
));
1088 c
-= copy_from_user(tmp_buf
, buf
, c
);
1094 c
= MIN(c
, MIN(SERIAL_XMIT_SIZE
- info
->xmit_cnt
- 1,
1095 SERIAL_XMIT_SIZE
- info
->xmit_head
));
1096 memcpy(info
->xmit_buf
+ info
->xmit_head
, tmp_buf
, c
);
1098 memcpy(info
->xmit_buf
+ info
->xmit_head
, buf
, c
);
1099 info
->xmit_head
= (info
->xmit_head
+ c
) & (SERIAL_XMIT_SIZE
-1);
1100 info
->xmit_cnt
+= c
;
1101 restore_flags(flags
);
1109 if (info
->xmit_cnt
&& !tty
->stopped
&& !tty
->hw_stopped
) {
1110 info
->interrupt_mask1
&= ~(SAB82532_IMR1_XPR
);
1111 info
->regs
->w
.imr1
= info
->interrupt_mask1
;
1112 sab82532_start_tx(info
);
1115 restore_flags(flags
);
1119 static int sab82532_write_room(struct tty_struct
*tty
)
1121 struct sab82532
*info
= (struct sab82532
*)tty
->driver_data
;
1124 if (serial_paranoia_check(info
, tty
->device
, "sab82532_write_room"))
1126 ret
= SERIAL_XMIT_SIZE
- info
->xmit_cnt
- 1;
1132 static int sab82532_chars_in_buffer(struct tty_struct
*tty
)
1134 struct sab82532
*info
= (struct sab82532
*)tty
->driver_data
;
1136 if (serial_paranoia_check(info
, tty
->device
, "sab82532_chars_in_buffer"))
1138 return info
->xmit_cnt
;
1141 static void sab82532_flush_buffer(struct tty_struct
*tty
)
1143 struct sab82532
*info
= (struct sab82532
*)tty
->driver_data
;
1145 if (serial_paranoia_check(info
, tty
->device
, "sab82532_flush_buffer"))
1148 info
->xmit_cnt
= info
->xmit_head
= info
->xmit_tail
= 0;
1150 wake_up_interruptible(&tty
->write_wait
);
1151 if ((tty
->flags
& (1 << TTY_DO_WRITE_WAKEUP
)) &&
1152 tty
->ldisc
.write_wakeup
)
1153 (tty
->ldisc
.write_wakeup
)(tty
);
1157 * This function is used to send a high-priority XON/XOFF character to
1160 static void sab82532_send_xchar(struct tty_struct
*tty
, char ch
)
1162 struct sab82532
*info
= (struct sab82532
*)tty
->driver_data
;
1163 unsigned long flags
;
1165 if (serial_paranoia_check(info
, tty
->device
, "sab82532_send_xchar"))
1168 save_flags(flags
); cli();
1169 sab82532_tec_wait(info
);
1170 info
->regs
->w
.tic
= ch
;
1171 restore_flags(flags
);
1175 * ------------------------------------------------------------
1176 * sab82532_throttle()
1178 * This routine is called by the upper-layer tty layer to signal that
1179 * incoming characters should be throttled.
1180 * ------------------------------------------------------------
1182 static void sab82532_throttle(struct tty_struct
* tty
)
1184 struct sab82532
*info
= (struct sab82532
*)tty
->driver_data
;
1185 #ifdef SERIAL_DEBUG_THROTTLE
1188 printk("throttle %s: %d....\n", _tty_name(tty
, buf
),
1189 tty
->ldisc
.chars_in_buffer(tty
));
1192 if (serial_paranoia_check(info
, tty
->device
, "sab82532_throttle"))
1196 sab82532_send_xchar(tty
, STOP_CHAR(tty
));
1198 if (tty
->termios
->c_cflag
& CRTSCTS
)
1199 info
->regs
->rw
.mode
|= SAB82532_MODE_RTS
;
1203 static void sab82532_unthrottle(struct tty_struct
* tty
)
1205 struct sab82532
*info
= (struct sab82532
*)tty
->driver_data
;
1206 #ifdef SERIAL_DEBUG_THROTTLE
1209 printk("unthrottle %s: %d....\n", _tty_name(tty
, buf
),
1210 tty
->ldisc
.chars_in_buffer(tty
));
1213 if (serial_paranoia_check(info
, tty
->device
, "sab82532_unthrottle"))
1220 sab82532_send_xchar(tty
, START_CHAR(tty
));
1224 if (tty
->termios
->c_cflag
& CRTSCTS
)
1225 info
->regs
->rw
.mode
&= ~(SAB82532_MODE_RTS
);
1230 * ------------------------------------------------------------
1231 * sab82532_ioctl() and friends
1232 * ------------------------------------------------------------
1235 static int get_serial_info(struct sab82532
*info
,
1236 struct serial_struct
*retinfo
)
1238 struct serial_struct tmp
;
1242 memset(&tmp
, 0, sizeof(tmp
));
1243 tmp
.type
= info
->type
;
1244 tmp
.line
= info
->line
;
1245 tmp
.port
= (unsigned long)info
->regs
;
1246 tmp
.irq
= info
->irq
;
1247 tmp
.flags
= info
->flags
;
1248 tmp
.xmit_fifo_size
= info
->xmit_fifo_size
;
1249 tmp
.baud_base
= info
->baud_base
;
1250 tmp
.close_delay
= info
->close_delay
;
1251 tmp
.closing_wait
= info
->closing_wait
;
1252 tmp
.custom_divisor
= info
->custom_divisor
;
1254 if (copy_to_user(retinfo
, &tmp
, sizeof(*retinfo
)))
1259 static int set_serial_info(struct sab82532
*info
,
1260 struct serial_struct
*new_info
)
1267 * get_lsr_info - get line status register info
1269 * Purpose: Let user call ioctl() to get info when the UART physically
1270 * is emptied. On bus types like RS485, the transmitter must
1271 * release the bus after transmitting. This must be done when
1272 * the transmit shift register is empty, not be done when the
1273 * transmit holding register is empty. This functionality
1274 * allows an RS485 driver to be written in user space.
1276 static int get_lsr_info(struct sab82532
* info
, unsigned int *value
)
1278 unsigned int result
;
1280 result
= (!info
->xmit_buf
&& info
->all_sent
) ? TIOCSER_TEMT
: 0;
1281 return put_user(result
, value
);
1285 static int get_modem_info(struct sab82532
* info
, unsigned int *value
)
1287 unsigned int result
;
1289 result
= ((info
->regs
->r
.mode
& SAB82532_MODE_RTS
) ?
1290 ((info
->regs
->r
.mode
& SAB82532_MODE_FRTS
) ? 0 : TIOCM_RTS
)
1292 | ((info
->regs
->r
.pvr
& info
->pvr_dtr_bit
) ? 0 : TIOCM_DTR
)
1293 | ((info
->regs
->r
.vstr
& SAB82532_VSTR_CD
) ? 0 : TIOCM_CAR
)
1294 | ((info
->regs
->r
.pvr
& info
->pvr_dsr_bit
) ? 0 : TIOCM_DSR
)
1295 | ((info
->regs
->r
.star
& SAB82532_STAR_CTS
) ? TIOCM_CTS
: 0);
1296 return put_user(result
,value
);
1299 static int set_modem_info(struct sab82532
* info
, unsigned int cmd
,
1300 unsigned int *value
)
1305 error
= get_user(arg
, value
);
1310 if (arg
& TIOCM_RTS
) {
1311 info
->regs
->rw
.mode
&= ~(SAB82532_MODE_FRTS
);
1312 info
->regs
->rw
.mode
|= SAB82532_MODE_RTS
;
1314 if (arg
& TIOCM_DTR
) {
1315 info
->regs
->rw
.pvr
&= ~(info
->pvr_dtr_bit
);
1319 if (arg
& TIOCM_RTS
) {
1320 info
->regs
->rw
.mode
|= SAB82532_MODE_FRTS
;
1321 info
->regs
->rw
.mode
|= SAB82532_MODE_RTS
;
1323 if (arg
& TIOCM_DTR
) {
1324 info
->regs
->rw
.pvr
|= info
->pvr_dtr_bit
;
1328 if (arg
& TIOCM_RTS
) {
1329 info
->regs
->rw
.mode
&= ~(SAB82532_MODE_FRTS
);
1330 info
->regs
->rw
.mode
|= SAB82532_MODE_RTS
;
1332 info
->regs
->rw
.mode
|= SAB82532_MODE_FRTS
;
1333 info
->regs
->rw
.mode
|= SAB82532_MODE_RTS
;
1335 if (arg
& TIOCM_DTR
) {
1336 info
->regs
->rw
.pvr
&= ~(info
->pvr_dtr_bit
);
1338 info
->regs
->rw
.pvr
|= info
->pvr_dtr_bit
;
1348 * This routine sends a break character out the serial port.
1350 static void sab82532_break(struct tty_struct
*tty
, int break_state
)
1352 struct sab82532
* info
= (struct sab82532
*)tty
->driver_data
;
1353 unsigned long flags
;
1355 if (serial_paranoia_check(info
, tty
->device
, "sab82532_break"))
1361 #ifdef SERIAL_DEBUG_SEND_BREAK
1362 printk("sab82532_break(%d) jiff=%lu...", break_state
, jiffies
);
1364 save_flags(flags
); cli();
1365 if (break_state
== -1)
1366 info
->regs
->rw
.dafo
|= SAB82532_DAFO_XBRK
;
1368 info
->regs
->rw
.dafo
&= ~(SAB82532_DAFO_XBRK
);
1369 restore_flags(flags
);
1373 static int sab82532_ioctl(struct tty_struct
*tty
, struct file
* file
,
1374 unsigned int cmd
, unsigned long arg
)
1377 struct sab82532
* info
= (struct sab82532
*)tty
->driver_data
;
1378 struct async_icount cprev
, cnow
; /* kernel counter temps */
1379 struct serial_icounter_struct
*p_cuser
; /* user space */
1381 if (serial_paranoia_check(info
, tty
->device
, "sab82532_ioctl"))
1384 if ((cmd
!= TIOCGSERIAL
) && (cmd
!= TIOCSSERIAL
) &&
1385 (cmd
!= TIOCSERCONFIG
) && (cmd
!= TIOCSERGWILD
) &&
1386 (cmd
!= TIOCSERSWILD
) && (cmd
!= TIOCSERGSTRUCT
) &&
1387 (cmd
!= TIOCMIWAIT
) && (cmd
!= TIOCGICOUNT
)) {
1388 if (tty
->flags
& (1 << TTY_IO_ERROR
))
1394 return put_user(C_CLOCAL(tty
) ? 1 : 0, (int *) arg
);
1396 error
= get_user(arg
, (unsigned int *) arg
);
1399 tty
->termios
->c_cflag
=
1400 ((tty
->termios
->c_cflag
& ~CLOCAL
) |
1401 (arg
? CLOCAL
: 0));
1404 return get_modem_info(info
, (unsigned int *) arg
);
1408 return set_modem_info(info
, cmd
, (unsigned int *) arg
);
1410 return get_serial_info(info
,
1411 (struct serial_struct
*) arg
);
1413 return set_serial_info(info
,
1414 (struct serial_struct
*) arg
);
1416 case TIOCSERGETLSR
: /* Get line status register */
1417 return get_lsr_info(info
, (unsigned int *) arg
);
1419 case TIOCSERGSTRUCT
:
1420 if (copy_to_user((struct sab82532
*) arg
,
1421 info
, sizeof(struct sab82532
)))
1426 * Wait for any of the 4 modem inputs (DCD,RI,DSR,CTS) to change
1427 * - mask passed in arg for lines of interest
1428 * (use |'ed TIOCM_RNG/DSR/CD/CTS for masking)
1429 * Caller should use TIOCGICOUNT to see which one it was
1433 /* note the counters on entry */
1434 cprev
= info
->icount
;
1437 interruptible_sleep_on(&info
->delta_msr_wait
);
1438 /* see if a signal did it */
1439 if (signal_pending(current
))
1440 return -ERESTARTSYS
;
1442 cnow
= info
->icount
; /* atomic copy */
1444 if (cnow
.rng
== cprev
.rng
&& cnow
.dsr
== cprev
.dsr
&&
1445 cnow
.dcd
== cprev
.dcd
&& cnow
.cts
== cprev
.cts
)
1446 return -EIO
; /* no change => error */
1447 if ( ((arg
& TIOCM_RNG
) && (cnow
.rng
!= cprev
.rng
)) ||
1448 ((arg
& TIOCM_DSR
) && (cnow
.dsr
!= cprev
.dsr
)) ||
1449 ((arg
& TIOCM_CD
) && (cnow
.dcd
!= cprev
.dcd
)) ||
1450 ((arg
& TIOCM_CTS
) && (cnow
.cts
!= cprev
.cts
)) ) {
1458 * Get counter of input serial line interrupts (DCD,RI,DSR,CTS)
1459 * Return: write counters to the user passed counter struct
1460 * NB: both 1->0 and 0->1 transitions are counted except for
1461 * RI where only 0->1 is counted.
1465 cnow
= info
->icount
;
1467 p_cuser
= (struct serial_icounter_struct
*) arg
;
1468 error
= put_user(cnow
.cts
, &p_cuser
->cts
);
1469 if (error
) return error
;
1470 error
= put_user(cnow
.dsr
, &p_cuser
->dsr
);
1471 if (error
) return error
;
1472 error
= put_user(cnow
.rng
, &p_cuser
->rng
);
1473 if (error
) return error
;
1474 error
= put_user(cnow
.dcd
, &p_cuser
->dcd
);
1475 if (error
) return error
;
1479 return -ENOIOCTLCMD
;
1484 static void sab82532_set_termios(struct tty_struct
*tty
,
1485 struct termios
*old_termios
)
1487 struct sab82532
*info
= (struct sab82532
*)tty
->driver_data
;
1489 if ( (tty
->termios
->c_cflag
== old_termios
->c_cflag
)
1490 && ( RELEVANT_IFLAG(tty
->termios
->c_iflag
)
1491 == RELEVANT_IFLAG(old_termios
->c_iflag
)))
1496 /* Handle transition to B0 status */
1497 if ((old_termios
->c_cflag
& CBAUD
) &&
1498 !(tty
->termios
->c_cflag
& CBAUD
)) {
1499 info
->regs
->w
.mode
|= SAB82532_MODE_FRTS
;
1500 info
->regs
->w
.mode
|= SAB82532_MODE_RTS
;
1501 info
->regs
->w
.pvr
|= info
->pvr_dtr_bit
;
1504 /* Handle transition away from B0 status */
1505 if (!(old_termios
->c_cflag
& CBAUD
) &&
1506 (tty
->termios
->c_cflag
& CBAUD
)) {
1507 info
->regs
->w
.pvr
&= ~(info
->pvr_dtr_bit
);
1508 if (!tty
->hw_stopped
||
1509 !(tty
->termios
->c_cflag
& CRTSCTS
)) {
1510 info
->regs
->w
.mode
&= ~(SAB82532_MODE_FRTS
);
1511 info
->regs
->w
.mode
|= SAB82532_MODE_RTS
;
1515 /* Handle turning off CRTSCTS */
1516 if ((old_termios
->c_cflag
& CRTSCTS
) &&
1517 !(tty
->termios
->c_cflag
& CRTSCTS
)) {
1518 tty
->hw_stopped
= 0;
1519 sab82532_start(tty
);
1524 * No need to wake up processes in open wait, since they
1525 * sample the CLOCAL flag once, and don't recheck it.
1526 * XXX It's not clear whether the current behavior is correct
1527 * or not. Hence, this may change.....
1529 if (!(old_termios
->c_cflag
& CLOCAL
) &&
1530 (tty
->termios
->c_cflag
& CLOCAL
))
1531 wake_up_interruptible(&info
->open_wait
);
1536 * ------------------------------------------------------------
1539 * This routine is called when the serial port gets closed. First, we
1540 * wait for the last remaining data to be sent. Then, we unlink its
1541 * async structure from the interrupt chain if necessary, and we free
1542 * that IRQ if nothing is left in the chain.
1543 * ------------------------------------------------------------
1545 static void sab82532_close(struct tty_struct
*tty
, struct file
* filp
)
1547 struct sab82532
*info
= (struct sab82532
*)tty
->driver_data
;
1548 unsigned long flags
;
1550 if (!info
|| serial_paranoia_check(info
, tty
->device
, "sab82532_close"))
1553 save_flags(flags
); cli();
1555 if (tty_hung_up_p(filp
)) {
1557 restore_flags(flags
);
1561 #ifdef SERIAL_DEBUG_OPEN
1562 printk("sab82532_close ttys%d, count = %d\n", info
->line
, info
->count
);
1564 if ((tty
->count
== 1) && (info
->count
!= 1)) {
1566 * Uh, oh. tty->count is 1, which means that the tty
1567 * structure will be freed. info->count should always
1568 * be one in these conditions. If it's greater than
1569 * one, we've got real problems, since it means the
1570 * serial port won't be shutdown.
1572 printk("sab82532_close: bad serial port count; tty->count is 1,"
1573 " info->count is %d\n", info
->count
);
1576 if (--info
->count
< 0) {
1577 printk("sab82532_close: bad serial port count for ttys%d: %d\n",
1578 info
->line
, info
->count
);
1583 restore_flags(flags
);
1586 info
->flags
|= ASYNC_CLOSING
;
1588 * Save the termios structure, since this port may have
1589 * separate termios for callout and dialin.
1591 if (info
->flags
& ASYNC_NORMAL_ACTIVE
)
1592 info
->normal_termios
= *tty
->termios
;
1593 if (info
->flags
& ASYNC_CALLOUT_ACTIVE
)
1594 info
->callout_termios
= *tty
->termios
;
1596 * Now we wait for the transmit buffer to clear; and we notify
1597 * the line discipline to only process XON/XOFF characters.
1600 if (info
->closing_wait
!= ASYNC_CLOSING_WAIT_NONE
)
1601 tty_wait_until_sent(tty
, info
->closing_wait
);
1604 * At this point we stop accepting input. To do this, we
1605 * disable the receive line status interrupts, and turn off
1608 info
->interrupt_mask0
|= SAB82532_IMR0_TCD
;
1609 info
->regs
->w
.imr0
= info
->interrupt_mask0
;
1611 info
->regs
->rw
.mode
&= ~(SAB82532_MODE_RAC
);
1613 if (info
->flags
& ASYNC_INITIALIZED
) {
1615 * Before we drop DTR, make sure the UART transmitter
1616 * has completely drained; this is especially
1617 * important if there is a transmit FIFO!
1619 sab82532_wait_until_sent(tty
, info
->timeout
);
1622 if (tty
->driver
.flush_buffer
)
1623 tty
->driver
.flush_buffer(tty
);
1624 if (tty
->ldisc
.flush_buffer
)
1625 tty
->ldisc
.flush_buffer(tty
);
1629 if (info
->blocked_open
) {
1630 if (info
->close_delay
) {
1631 current
->state
= TASK_INTERRUPTIBLE
;
1632 schedule_timeout(info
->close_delay
);
1634 wake_up_interruptible(&info
->open_wait
);
1636 info
->flags
&= ~(ASYNC_NORMAL_ACTIVE
|ASYNC_CALLOUT_ACTIVE
|
1638 wake_up_interruptible(&info
->close_wait
);
1640 restore_flags(flags
);
1644 * sab82532_wait_until_sent() --- wait until the transmitter is empty
1646 static void sab82532_wait_until_sent(struct tty_struct
*tty
, int timeout
)
1648 struct sab82532
*info
= (struct sab82532
*)tty
->driver_data
;
1649 unsigned long orig_jiffies
, char_time
;
1651 if (serial_paranoia_check(info
,tty
->device
,"sab82532_wait_until_sent"))
1654 orig_jiffies
= jiffies
;
1656 * Set the check interval to be 1/5 of the estimated time to
1657 * send a single character, and make it at least 1. The check
1658 * interval should also be less than the timeout.
1660 * Note: we have to use pretty tight timings here to satisfy
1663 char_time
= (info
->timeout
- HZ
/50) / info
->xmit_fifo_size
;
1664 char_time
= char_time
/ 5;
1668 char_time
= MIN(char_time
, timeout
);
1669 #ifdef SERIAL_DEBUG_WAIT_UNTIL_SENT
1670 printk("In sab82532_wait_until_sent(%d) check=%lu...", timeout
, char_time
);
1671 printk("jiff=%lu...", jiffies
);
1673 while (info
->xmit_cnt
|| !info
->all_sent
) {
1674 current
->state
= TASK_INTERRUPTIBLE
;
1675 current
->counter
= 0;
1676 schedule_timeout(char_time
);
1677 if (signal_pending(current
))
1679 if (timeout
&& time_after(jiffies
, orig_jiffies
+ timeout
))
1682 current
->state
= TASK_RUNNING
;
1683 #ifdef SERIAL_DEBUG_WAIT_UNTIL_SENT
1684 printk("xmit_cnt = %d, alls = %d (jiff=%lu)...done\n", info
->xmit_cnt
, info
->all_sent
, jiffies
);
1689 * sab82532_hangup() --- called by tty_hangup() when a hangup is signaled.
1691 static void sab82532_hangup(struct tty_struct
*tty
)
1693 struct sab82532
* info
= (struct sab82532
*)tty
->driver_data
;
1695 if (serial_paranoia_check(info
, tty
->device
, "sab82532_hangup"))
1698 if (info
->is_console
)
1701 sab82532_flush_buffer(tty
);
1705 info
->flags
&= ~(ASYNC_NORMAL_ACTIVE
|ASYNC_CALLOUT_ACTIVE
);
1707 wake_up_interruptible(&info
->open_wait
);
1711 * ------------------------------------------------------------
1712 * sab82532_open() and friends
1713 * ------------------------------------------------------------
1715 static int block_til_ready(struct tty_struct
*tty
, struct file
* filp
,
1716 struct sab82532
*info
)
1718 DECLARE_WAITQUEUE(wait
, current
);
1723 * If the device is in the middle of being closed, then block
1724 * until it's done, and then try again.
1726 if (tty_hung_up_p(filp
) ||
1727 (info
->flags
& ASYNC_CLOSING
)) {
1728 if (info
->flags
& ASYNC_CLOSING
)
1729 interruptible_sleep_on(&info
->close_wait
);
1730 #ifdef SERIAL_DO_RESTART
1731 if (info
->flags
& ASYNC_HUP_NOTIFY
)
1734 return -ERESTARTSYS
;
1741 * If this is a callout device, then just make sure the normal
1742 * device isn't being used.
1744 if (tty
->driver
.subtype
== SERIAL_TYPE_CALLOUT
) {
1745 if (info
->flags
& ASYNC_NORMAL_ACTIVE
)
1747 if ((info
->flags
& ASYNC_CALLOUT_ACTIVE
) &&
1748 (info
->flags
& ASYNC_SESSION_LOCKOUT
) &&
1749 (info
->session
!= current
->session
))
1751 if ((info
->flags
& ASYNC_CALLOUT_ACTIVE
) &&
1752 (info
->flags
& ASYNC_PGRP_LOCKOUT
) &&
1753 (info
->pgrp
!= current
->pgrp
))
1755 info
->flags
|= ASYNC_CALLOUT_ACTIVE
;
1760 * If non-blocking mode is set, or the port is not enabled,
1761 * then make the check up front and then exit.
1763 if ((filp
->f_flags
& O_NONBLOCK
) ||
1764 (tty
->flags
& (1 << TTY_IO_ERROR
))) {
1765 if (info
->flags
& ASYNC_CALLOUT_ACTIVE
)
1767 info
->flags
|= ASYNC_NORMAL_ACTIVE
;
1771 if (info
->flags
& ASYNC_CALLOUT_ACTIVE
) {
1772 if (info
->normal_termios
.c_cflag
& CLOCAL
)
1775 if (tty
->termios
->c_cflag
& CLOCAL
)
1780 * Block waiting for the carrier detect and the line to become
1781 * free (i.e., not in use by the callout). While we are in
1782 * this loop, info->count is dropped by one, so that
1783 * sab82532_close() knows when to free things. We restore it upon
1784 * exit, either normal or abnormal.
1787 add_wait_queue(&info
->open_wait
, &wait
);
1788 #ifdef SERIAL_DEBUG_OPEN
1789 printk("block_til_ready before block: ttyS%d, count = %d\n",
1790 info
->line
, info
->count
);
1793 if (!tty_hung_up_p(filp
))
1796 info
->blocked_open
++;
1799 if (!(info
->flags
& ASYNC_CALLOUT_ACTIVE
) &&
1800 (tty
->termios
->c_cflag
& CBAUD
)) {
1801 info
->regs
->rw
.pvr
&= ~(info
->pvr_dtr_bit
);
1802 info
->regs
->rw
.mode
|= SAB82532_MODE_FRTS
;
1803 info
->regs
->rw
.mode
&= ~(SAB82532_MODE_RTS
);
1806 current
->state
= TASK_INTERRUPTIBLE
;
1807 if (tty_hung_up_p(filp
) ||
1808 !(info
->flags
& ASYNC_INITIALIZED
)) {
1809 #ifdef SERIAL_DO_RESTART
1810 if (info
->flags
& ASYNC_HUP_NOTIFY
)
1813 retval
= -ERESTARTSYS
;
1819 if (!(info
->flags
& ASYNC_CALLOUT_ACTIVE
) &&
1820 !(info
->flags
& ASYNC_CLOSING
) &&
1821 (do_clocal
|| !(info
->regs
->r
.vstr
& SAB82532_VSTR_CD
)))
1823 if (signal_pending(current
)) {
1824 retval
= -ERESTARTSYS
;
1827 #ifdef SERIAL_DEBUG_OPEN
1828 printk("block_til_ready blocking: ttyS%d, count = %d, flags = %x, clocal = %d, vstr = %02x\n",
1829 info
->line
, info
->count
, info
->flags
, do_clocal
, info
->regs
->r
.vstr
);
1833 current
->state
= TASK_RUNNING
;
1834 remove_wait_queue(&info
->open_wait
, &wait
);
1835 if (!tty_hung_up_p(filp
))
1837 info
->blocked_open
--;
1838 #ifdef SERIAL_DEBUG_OPEN
1839 printk("block_til_ready after blocking: ttys%d, count = %d\n",
1840 info
->line
, info
->count
);
1844 info
->flags
|= ASYNC_NORMAL_ACTIVE
;
1849 * This routine is called whenever a serial port is opened. It
1850 * enables interrupts for a serial port, linking in its async structure into
1851 * the IRQ chain. It also performs the serial-specific
1852 * initialization for the tty structure.
1854 static int sab82532_open(struct tty_struct
*tty
, struct file
* filp
)
1856 struct sab82532
*info
= sab82532_chain
;
1860 #ifdef SERIAL_DEBUG_OPEN
1861 printk("sab82532_open: count = %d\n", info
->count
);
1864 line
= MINOR(tty
->device
) - tty
->driver
.minor_start
;
1865 if ((line
< 0) || (line
>= NR_PORTS
))
1869 if (info
->line
== line
)
1874 printk("sab82532_open: can't find info for line %d\n",
1879 if (serial_paranoia_check(info
, tty
->device
, "sab82532_open"))
1882 #ifdef SERIAL_DEBUG_OPEN
1883 printk("sab82532_open %s%d, count = %d\n", tty
->driver
.name
, info
->line
,
1888 tty
->driver_data
= info
;
1892 page
= get_free_page(GFP_KERNEL
);
1898 tmp_buf
= (unsigned char *) page
;
1902 * If the port is in the middle of closing, bail out now.
1904 if (tty_hung_up_p(filp
) ||
1905 (info
->flags
& ASYNC_CLOSING
)) {
1906 if (info
->flags
& ASYNC_CLOSING
)
1907 interruptible_sleep_on(&info
->close_wait
);
1908 #ifdef SERIAL_DO_RESTART
1909 return ((info
->flags
& ASYNC_HUP_NOTIFY
) ?
1910 -EAGAIN
: -ERESTARTSYS
);
1917 * Start up serial port
1919 retval
= startup(info
);
1924 retval
= block_til_ready(tty
, filp
, info
);
1926 #ifdef SERIAL_DEBUG_OPEN
1927 printk("sab82532_open returning after block_til_ready with %d\n",
1933 if ((info
->count
== 1) &&
1934 (info
->flags
& ASYNC_SPLIT_TERMIOS
)) {
1935 if (tty
->driver
.subtype
== SERIAL_TYPE_NORMAL
)
1936 *tty
->termios
= info
->normal_termios
;
1938 *tty
->termios
= info
->callout_termios
;
1942 #ifdef CONFIG_SERIAL_CONSOLE
1943 if (sab82532_console
.cflag
&& sab82532_console
.index
== line
) {
1944 tty
->termios
->c_cflag
= sab82532_console
.cflag
;
1945 sab82532_console
.cflag
= 0;
1950 info
->session
= current
->session
;
1951 info
->pgrp
= current
->pgrp
;
1953 #ifdef SERIAL_DEBUG_OPEN
1954 printk("sab82532_open ttys%d successful... count %d", info
->line
, info
->count
);
1960 * /proc fs routines....
1963 static __inline__
int
1964 line_info(char *buf
, struct sab82532
*info
)
1966 unsigned long flags
;
1970 ret
= sprintf(buf
, "%d: uart:SAB82532 ", info
->line
);
1971 switch (info
->type
) {
1973 ret
+= sprintf(buf
+ret
, "V1.0 ");
1976 ret
+= sprintf(buf
+ret
, "V2.0 ");
1979 ret
+= sprintf(buf
+ret
, "V3.2 ");
1982 ret
+= sprintf(buf
+ret
, "V?.? ");
1985 ret
+= sprintf(buf
+ret
, "port:%lX irq:%s",
1986 (unsigned long)info
->regs
, __irq_itoa(info
->irq
));
1989 ret
+= sprintf(buf
+ret
, "\n");
1994 * Figure out the current RS-232 lines
1998 save_flags(flags
); cli();
1999 if (info
->regs
->r
.mode
& SAB82532_MODE_RTS
) {
2000 if (!(info
->regs
->r
.mode
& SAB82532_MODE_FRTS
))
2001 strcat(stat_buf
, "|RTS");
2003 strcat(stat_buf
, "|RTS");
2005 if (info
->regs
->r
.star
& SAB82532_STAR_CTS
)
2006 strcat(stat_buf
, "|CTS");
2007 if (!(info
->regs
->r
.pvr
& info
->pvr_dtr_bit
))
2008 strcat(stat_buf
, "|DTR");
2009 if (!(info
->regs
->r
.pvr
& info
->pvr_dsr_bit
))
2010 strcat(stat_buf
, "|DSR");
2011 if (!(info
->regs
->r
.vstr
& SAB82532_VSTR_CD
))
2012 strcat(stat_buf
, "|CD");
2013 restore_flags(flags
);
2016 ret
+= sprintf(buf
+ret
, " baud:%d", info
->baud
);
2018 if (info
->icount
.frame
)
2019 ret
+= sprintf(buf
+ret
, " fe:%d", info
->icount
.frame
);
2021 if (info
->icount
.parity
)
2022 ret
+= sprintf(buf
+ret
, " pe:%d", info
->icount
.parity
);
2024 if (info
->icount
.brk
)
2025 ret
+= sprintf(buf
+ret
, " brk:%d", info
->icount
.brk
);
2027 if (info
->icount
.overrun
)
2028 ret
+= sprintf(buf
+ret
, " oe:%d", info
->icount
.overrun
);
2031 * Last thing is the RS-232 status lines.
2033 ret
+= sprintf(buf
+ret
, " %s\n", stat_buf
+ 1);
2037 int sab82532_read_proc(char *page
, char **start
, off_t off
, int count
,
2038 int *eof
, void *data
)
2040 struct sab82532
*info
= sab82532_chain
;
2044 len
+= sprintf(page
, "serinfo:1.0 driver:%s\n", serial_version
);
2045 for (info
= sab82532_chain
; info
&& len
< 4000; info
= info
->next
) {
2046 len
+= line_info(page
+ len
, info
);
2047 if (len
+begin
> off
+count
)
2049 if (len
+begin
< off
) {
2056 if (off
>= len
+begin
)
2058 *start
= page
+ (begin
-off
);
2059 return ((count
< begin
+len
-off
) ? count
: begin
+len
-off
);
2063 * ---------------------------------------------------------------------
2064 * sab82532_init() and friends
2066 * sab82532_init() is called at boot-time to initialize the serial driver.
2067 * ---------------------------------------------------------------------
2069 __initfunc(static int get_sab82532(unsigned long *memory_start
))
2071 struct linux_ebus
*ebus
;
2072 struct linux_ebus_device
*edev
= 0;
2073 struct sab82532
*sab
;
2074 unsigned long regs
, offset
;
2077 for_each_ebus(ebus
) {
2078 for_each_ebusdev(edev
, ebus
) {
2079 if (!strcmp(edev
->prom_name
, "se"))
2087 regs
= edev
->base_address
[0];
2088 offset
= sizeof(union sab82532_async_regs
);
2090 for (i
= 0; i
< 2; i
++) {
2092 *memory_start
= (*memory_start
+ 7) & ~(7);
2093 sab
= (struct sab82532
*)*memory_start
;
2094 *memory_start
+= sizeof(struct sab82532
);
2096 sab
= (struct sab82532
*)kmalloc(sizeof(struct sab82532
),
2099 printk("sab82532: can't alloc sab struct\n");
2103 memset(sab
, 0, sizeof(struct sab82532
));
2105 sab
->regs
= (union sab82532_async_regs
*)(regs
+ offset
);
2106 sab
->irq
= edev
->irqs
[0];
2108 sab
->xmit_fifo_size
= 32;
2109 sab
->recv_fifo_size
= 32;
2111 if (check_region((unsigned long)sab
->regs
,
2112 sizeof(union sab82532_async_regs
))) {
2116 request_region((unsigned long)sab
->regs
,
2117 sizeof(union sab82532_async_regs
),
2118 "serial(sab82532)");
2120 sab
->regs
->w
.ipc
= SAB82532_IPC_IC_ACT_LOW
;
2122 sab
->next
= sab82532_chain
;
2123 sab82532_chain
= sab
;
2125 offset
-= sizeof(union sab82532_async_regs
);
2130 __initfunc(static void
2131 sab82532_kgdb_hook(int line
))
2133 prom_printf("sab82532: kgdb support is not implemented, yet\n");
2137 __initfunc(static inline void show_serial_version(void))
2139 char *revision
= "$Revision: 1.31 $";
2142 version
= strchr(revision
, ' ');
2143 strcpy(serial_version
, ++version
);
2144 p
= strchr(serial_version
, ' ');
2146 printk("SAB82532 serial driver version %s\n", serial_version
);
2150 * The serial driver boot-time initialization code!
2152 __initfunc(int sab82532_init(void))
2154 struct sab82532
*info
;
2157 if (!sab82532_chain
)
2159 if (!sab82532_chain
)
2162 init_bh(SERIAL_BH
, do_serial_bh
);
2164 show_serial_version();
2166 /* Initialize the tty_driver structure */
2167 memset(&serial_driver
, 0, sizeof(struct tty_driver
));
2168 serial_driver
.magic
= TTY_DRIVER_MAGIC
;
2169 serial_driver
.driver_name
= "serial";
2170 serial_driver
.name
= "ttyS";
2171 serial_driver
.major
= TTY_MAJOR
;
2172 serial_driver
.minor_start
= 64;
2173 serial_driver
.num
= NR_PORTS
;
2174 serial_driver
.type
= TTY_DRIVER_TYPE_SERIAL
;
2175 serial_driver
.subtype
= SERIAL_TYPE_NORMAL
;
2176 serial_driver
.init_termios
= tty_std_termios
;
2177 serial_driver
.init_termios
.c_cflag
=
2178 B9600
| CS8
| CREAD
| HUPCL
| CLOCAL
;
2179 serial_driver
.flags
= TTY_DRIVER_REAL_RAW
;
2180 serial_driver
.refcount
= &sab82532_refcount
;
2181 serial_driver
.table
= sab82532_table
;
2182 serial_driver
.termios
= sab82532_termios
;
2183 serial_driver
.termios_locked
= sab82532_termios_locked
;
2185 serial_driver
.open
= sab82532_open
;
2186 serial_driver
.close
= sab82532_close
;
2187 serial_driver
.write
= sab82532_write
;
2188 serial_driver
.put_char
= sab82532_put_char
;
2189 serial_driver
.flush_chars
= sab82532_flush_chars
;
2190 serial_driver
.write_room
= sab82532_write_room
;
2191 serial_driver
.chars_in_buffer
= sab82532_chars_in_buffer
;
2192 serial_driver
.flush_buffer
= sab82532_flush_buffer
;
2193 serial_driver
.ioctl
= sab82532_ioctl
;
2194 serial_driver
.throttle
= sab82532_throttle
;
2195 serial_driver
.unthrottle
= sab82532_unthrottle
;
2196 serial_driver
.send_xchar
= sab82532_send_xchar
;
2197 serial_driver
.set_termios
= sab82532_set_termios
;
2198 serial_driver
.stop
= sab82532_stop
;
2199 serial_driver
.start
= sab82532_start
;
2200 serial_driver
.hangup
= sab82532_hangup
;
2201 serial_driver
.break_ctl
= sab82532_break
;
2202 serial_driver
.wait_until_sent
= sab82532_wait_until_sent
;
2203 serial_driver
.read_proc
= sab82532_read_proc
;
2206 * The callout device is just like normal device except for
2207 * major number and the subtype code.
2209 callout_driver
= serial_driver
;
2210 callout_driver
.name
= "cua";
2211 callout_driver
.major
= TTYAUX_MAJOR
;
2212 callout_driver
.subtype
= SERIAL_TYPE_CALLOUT
;
2213 callout_driver
.read_proc
= 0;
2214 callout_driver
.proc_entry
= 0;
2216 if (tty_register_driver(&serial_driver
))
2217 panic("Couldn't register serial driver\n");
2218 if (tty_register_driver(&callout_driver
))
2219 panic("Couldn't register callout driver\n");
2221 for (info
= sab82532_chain
, i
= 0; info
; info
= info
->next
, i
++) {
2222 info
->magic
= SERIAL_MAGIC
;
2224 info
->type
= info
->regs
->r
.vstr
& 0x0f;
2225 info
->regs
->w
.pcr
= ~((1 << 1) | (1 << 2) | (1 << 4));
2226 info
->regs
->w
.pim
= 0xff;
2227 if (info
->line
== 0) {
2228 info
->pvr_dsr_bit
= (1 << 0);
2229 info
->pvr_dtr_bit
= (1 << 1);
2231 info
->pvr_dsr_bit
= (1 << 3);
2232 info
->pvr_dtr_bit
= (1 << 2);
2234 info
->regs
->w
.pvr
= (1 << 1) | (1 << 2) | (1 << 4);
2235 info
->regs
->rw
.mode
|= SAB82532_MODE_FRTS
;
2236 info
->regs
->rw
.mode
|= SAB82532_MODE_RTS
;
2238 info
->custom_divisor
= 16;
2239 info
->close_delay
= 5*HZ
/10;
2240 info
->closing_wait
= 30*HZ
;
2243 info
->blocked_open
= 0;
2244 info
->tqueue
.routine
= do_softint
;
2245 info
->tqueue
.data
= info
;
2246 info
->tqueue_hangup
.routine
= do_serial_hangup
;
2247 info
->tqueue_hangup
.data
= info
;
2248 info
->callout_termios
= callout_driver
.init_termios
;
2249 info
->normal_termios
= serial_driver
.init_termios
;
2250 init_waitqueue_head(&info
->open_wait
);
2251 init_waitqueue_head(&info
->close_wait
);
2252 init_waitqueue_head(&info
->delta_msr_wait
);
2253 info
->icount
.cts
= info
->icount
.dsr
=
2254 info
->icount
.rng
= info
->icount
.dcd
= 0;
2255 info
->icount
.rx
= info
->icount
.tx
= 0;
2256 info
->icount
.frame
= info
->icount
.parity
= 0;
2257 info
->icount
.overrun
= info
->icount
.brk
= 0;
2259 if (!(info
->line
& 0x01)) {
2260 if (request_irq(info
->irq
, sab82532_interrupt
, SA_SHIRQ
,
2261 "serial(sab82532)", info
)) {
2262 printk("sab82532: can't get IRQ %x\n",
2264 panic("sab82532 initialization failed");
2269 "ttyS%02d at 0x%lx (irq = %s) is a SAB82532 %s\n",
2270 info
->line
, (unsigned long)info
->regs
,
2271 __irq_itoa(info
->irq
), sab82532_version
[info
->type
]);
2274 #ifdef SERIAL_LOG_DEVICE
2275 dprint_init(SERIAL_LOG_DEVICE
);
2280 __initfunc(int sab82532_probe(unsigned long *memory_start
))
2282 int node
, enode
, snode
;
2286 node
= prom_getchild(prom_root_node
);
2287 node
= prom_searchsiblings(node
, "pci");
2290 * Check for SUNW,sabre on Ultra 5/10/AXi.
2292 len
= prom_getproperty(node
, "model", model
, sizeof(model
));
2293 if ((len
> 0) && !strncmp(model
, "SUNW,sabre", len
)) {
2294 node
= prom_getchild(node
);
2295 node
= prom_searchsiblings(node
, "pci");
2299 * For each PCI bus...
2302 enode
= prom_getchild(node
);
2303 enode
= prom_searchsiblings(enode
, "ebus");
2306 * For each EBus on this PCI...
2309 snode
= prom_getchild(enode
);
2310 snode
= prom_searchsiblings(snode
, "se");
2314 enode
= prom_getsibling(enode
);
2315 enode
= prom_searchsiblings(enode
, "ebus");
2317 node
= prom_getsibling(node
);
2318 node
= prom_searchsiblings(node
, "pci");
2323 #ifdef CONFIG_SERIAL_CONSOLE
2324 sunserial_setinitfunc(memory_start
, sab82532_console_init
);
2326 sunserial_setinitfunc(memory_start
, sab82532_init
);
2327 rs_ops
.rs_kgdb_hook
= sab82532_kgdb_hook
;
2332 int init_module(void)
2334 if (get_sab82532(0))
2337 return sab82532_init();
2340 void cleanup_module(void)
2342 unsigned long flags
;
2346 /* printk("Unloading %s: version %s\n", serial_name, serial_version); */
2349 timer_active
&= ~(1 << RS_TIMER
);
2350 timer_table
[RS_TIMER
].fn
= NULL
;
2351 timer_table
[RS_TIMER
].expires
= 0;
2352 remove_bh(SERIAL_BH
);
2353 if ((e1
= tty_unregister_driver(&serial_driver
)))
2354 printk("SERIAL: failed to unregister serial driver (%d)\n",
2356 if ((e2
= tty_unregister_driver(&callout_driver
)))
2357 printk("SERIAL: failed to unregister callout driver (%d)\n",
2359 restore_flags(flags
);
2361 for (i
= 0; i
< NR_PORTS
; i
++) {
2362 struct sab82532
*info
= (struct sab82532
*)sab82532_table
[i
]->driver_data
;
2363 if (info
->type
!= PORT_UNKNOWN
)
2364 release_region((unsigned long)info
->regs
,
2365 sizeof(union sab82532_async_regs
));
2368 free_page((unsigned long) tmp_buf
);
2374 #ifdef CONFIG_SERIAL_CONSOLE
2376 static __inline__
void
2377 sab82532_console_putchar(struct sab82532
*info
, char c
)
2379 unsigned long flags
;
2381 save_flags(flags
); cli();
2382 sab82532_tec_wait(info
);
2383 info
->regs
->w
.tic
= c
;
2384 restore_flags(flags
);
2388 sab82532_console_write(struct console
*con
, const char *s
, unsigned n
)
2390 struct sab82532
*info
;
2393 info
= sab82532_chain
;
2394 for (i
= con
->index
; i
; i
--) {
2400 for (i
= 0; i
< n
; i
++) {
2402 sab82532_console_putchar(info
, '\r');
2403 sab82532_console_putchar(info
, *s
++);
2405 sab82532_tec_wait(info
);
2409 sab82532_console_wait_key(struct console
*con
)
2411 sleep_on(&keypress_wait
);
2416 sab82532_console_device(struct console
*con
)
2418 return MKDEV(TTY_MAJOR
, 64 + con
->index
);
2422 sab82532_console_setup(struct console
*con
, char *options
)
2424 struct sab82532
*info
;
2429 unsigned long flags
;
2431 info
= sab82532_chain
;
2432 for (i
= con
->index
; i
; i
--) {
2437 info
->is_console
= 1;
2440 * Initialize the hardware
2442 sab82532_init_line(info
);
2445 * Finally, enable interrupts
2447 info
->interrupt_mask0
= SAB82532_IMR0_PERR
| SAB82532_IMR0_FERR
|
2448 SAB82532_IMR0_PLLA
| SAB82532_IMR0_CDSC
;
2449 info
->regs
->w
.imr0
= info
->interrupt_mask0
;
2450 info
->interrupt_mask1
= SAB82532_IMR1_BRKT
| SAB82532_IMR1_ALLS
|
2451 SAB82532_IMR1_XOFF
| SAB82532_IMR1_TIN
|
2452 SAB82532_IMR1_CSC
| SAB82532_IMR1_XON
|
2454 info
->regs
->w
.imr1
= info
->interrupt_mask1
;
2456 printk("Console: ttyS%d (SAB82532)\n", info
->line
);
2458 sunserial_console_termios(con
);
2461 /* Byte size and parity */
2462 switch (cflag
& CSIZE
) {
2463 case CS5
: dafo
= SAB82532_DAFO_CHL5
; bits
= 7; break;
2464 case CS6
: dafo
= SAB82532_DAFO_CHL6
; bits
= 8; break;
2465 case CS7
: dafo
= SAB82532_DAFO_CHL7
; bits
= 9; break;
2466 case CS8
: dafo
= SAB82532_DAFO_CHL8
; bits
= 10; break;
2467 /* Never happens, but GCC is too dumb to figure it out */
2468 default: dafo
= SAB82532_DAFO_CHL5
; bits
= 7; break;
2471 if (cflag
& CSTOPB
) {
2472 dafo
|= SAB82532_DAFO_STOP
;
2476 if (cflag
& PARENB
) {
2477 dafo
|= SAB82532_DAFO_PARE
;
2481 if (cflag
& PARODD
) {
2484 dafo
|= SAB82532_DAFO_PAR_MARK
;
2487 dafo
|= SAB82532_DAFO_PAR_ODD
;
2491 dafo
|= SAB82532_DAFO_PAR_SPACE
;
2494 dafo
|= SAB82532_DAFO_PAR_EVEN
;
2497 /* Determine EBRG values based on baud rate */
2501 if ((i
< 1) || ((i
+ 15) >= NR_EBRG_VALUES
))
2506 ebrg
= ebrg_table
[i
].n
;
2507 ebrg
|= (ebrg_table
[i
].m
<< 6);
2509 info
->baud
= ebrg_table
[i
].baud
;
2511 info
->timeout
= (info
->xmit_fifo_size
* HZ
* bits
) / info
->baud
;
2514 info
->timeout
+= HZ
/ 50; /* Add .02 seconds of slop */
2516 /* CTS flow control flags */
2517 if (cflag
& CRTSCTS
)
2518 info
->flags
|= ASYNC_CTS_FLOW
;
2520 info
->flags
&= ~(ASYNC_CTS_FLOW
);
2523 info
->flags
&= ~(ASYNC_CHECK_CD
);
2525 info
->flags
|= ASYNC_CHECK_CD
;
2527 save_flags(flags
); cli();
2528 if (info
->regs
->r
.star
& SAB82532_STAR_CEC
)
2530 sab82532_tec_wait(info
);
2531 info
->regs
->w
.dafo
= dafo
;
2532 info
->regs
->w
.bgr
= ebrg
& 0xff;
2533 info
->regs
->rw
.ccr2
&= ~(0xc0);
2534 info
->regs
->rw
.ccr2
|= (ebrg
>> 2) & 0xc0;
2535 if (info
->flags
& ASYNC_CTS_FLOW
) {
2536 info
->regs
->rw
.mode
&= ~(SAB82532_MODE_RTS
);
2537 info
->regs
->rw
.mode
|= SAB82532_MODE_FRTS
;
2538 info
->regs
->rw
.mode
&= ~(SAB82532_MODE_FCTS
);
2540 info
->regs
->rw
.mode
|= SAB82532_MODE_RTS
;
2541 info
->regs
->rw
.mode
&= ~(SAB82532_MODE_FRTS
);
2542 info
->regs
->rw
.mode
|= SAB82532_MODE_FCTS
;
2544 info
->regs
->rw
.pvr
&= ~(info
->pvr_dtr_bit
);
2545 info
->regs
->rw
.mode
|= SAB82532_MODE_RAC
;
2546 restore_flags(flags
);
2551 static struct console sab82532_console
= {
2553 sab82532_console_write
,
2555 sab82532_console_device
,
2556 sab82532_console_wait_key
,
2558 sab82532_console_setup
,
2565 __initfunc(int sab82532_console_init(void))
2567 extern int con_is_present(void);
2569 if (con_is_present())
2572 if (!sab82532_chain
) {
2573 prom_printf("sab82532_console_setup: can't get SAB82532 chain");
2577 sab82532_console
.index
= serial_console
- 1;
2578 register_console(&sab82532_console
);
2582 #ifdef SERIAL_LOG_DEVICE
2584 static int serial_log_device
= 0;
2587 dprint_init(int tty
)
2589 serial_console
= tty
+ 1;
2590 sab82532_console
.index
= tty
;
2591 sab82532_console_setup(&sab82532_console
, "");
2593 serial_log_device
= tty
+ 1;
2597 dprintf(const char *fmt
, ...)
2599 static char buffer
[4096];
2603 if (!serial_log_device
)
2606 va_start(args
, fmt
);
2607 i
= vsprintf(buffer
, fmt
, args
);
2609 sab82532_console
.write(&sab82532_console
, buffer
, i
);
2612 #endif /* SERIAL_LOG_DEVICE */
2613 #endif /* CONFIG_SERIAL_CONSOLE */