1 /* $Id: sab82532.c,v 1.54 2000/12/07 04:35:39 anton 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/serialP.h>
19 #include <linux/serial_reg.h>
20 #include <linux/console.h>
21 #include <linux/major.h>
22 #include <linux/string.h>
23 #include <linux/fcntl.h>
24 #include <linux/ptrace.h>
25 #include <linux/ioport.h>
27 #include <linux/malloc.h>
28 #include <linux/init.h>
29 #include <linux/delay.h>
31 #include <asm/sab82532.h>
32 #include <asm/uaccess.h>
36 #include "sunserial.h"
38 static DECLARE_TASK_QUEUE(tq_serial
);
40 /* This is (one of many) a special gross hack to allow SU and
41 * SAB serials to co-exist on the same machine. -DaveM
44 #define SERIAL_BH AURORA_BH
46 static struct tty_driver serial_driver
, callout_driver
;
47 static int sab82532_refcount
;
49 /* number of characters left in xmit buffer before we ask for more */
50 #define WAKEUP_CHARS 256
52 #define SERIAL_PARANOIA_CHECK
53 #define SERIAL_DO_RESTART
55 /* Set of debugging defines */
56 #undef SERIAL_DEBUG_OPEN
57 #undef SERIAL_DEBUG_FLOW
58 #undef SERIAL_DEBUG_MODEM
59 #undef SERIAL_DEBUG_WAIT_UNTIL_SENT
60 #undef SERIAL_DEBUG_SEND_BREAK
61 #undef SERIAL_DEBUG_INTR
62 #define SERIAL_DEBUG_OVERFLOW 1
64 /* Trace things on serial device, useful for console debugging: */
65 #undef SERIAL_LOG_DEVICE
67 #ifdef SERIAL_LOG_DEVICE
68 static void dprint_init(int tty
);
71 static void change_speed(struct sab82532
*info
);
72 static void sab82532_wait_until_sent(struct tty_struct
*tty
, int timeout
);
75 * This assumes you have a 29.4912 MHz clock for your UART.
77 #define BASE_BAUD ( 29491200 / 16 )
79 static struct sab82532
*sab82532_chain
= 0;
80 static struct tty_struct
*sab82532_table
[NR_PORTS
];
81 static struct termios
*sab82532_termios
[NR_PORTS
];
82 static struct termios
*sab82532_termios_locked
[NR_PORTS
];
85 #undef CONFIG_SERIAL_CONSOLE
88 #ifdef CONFIG_SERIAL_CONSOLE
89 extern int serial_console
;
90 static struct console sab82532_console
;
91 static int sab82532_console_init(void);
92 static void batten_down_hatches(struct sab82532
*info
);
96 #define MIN(a,b) ((a) < (b) ? (a) : (b))
99 static char *sab82532_version
[16] = {
100 "V1.0", "V2.0", "V3.2", "V(0x03)",
101 "V(0x04)", "V(0x05)", "V(0x06)", "V(0x07)",
102 "V(0x08)", "V(0x09)", "V(0x0a)", "V(0x0b)",
103 "V(0x0c)", "V(0x0d)", "V(0x0e)", "V(0x0f)"
105 static char serial_version
[16];
108 * tmp_buf is used as a temporary buffer by sab82532_write. We need to
109 * lock it in case the copy_from_user blocks while swapping in a page,
110 * and some other program tries to do a serial write at the same time.
111 * Since the lock will only come under contention when the system is
112 * swapping and available memory is low, it makes sense to share one
113 * buffer across all the serial ports, since it significantly saves
114 * memory if large numbers of serial ports are open.
116 static unsigned char *tmp_buf
= 0;
117 static DECLARE_MUTEX(tmp_buf_sem
);
119 static inline int serial_paranoia_check(struct sab82532
*info
,
120 kdev_t device
, const char *routine
)
122 #ifdef SERIAL_PARANOIA_CHECK
123 static const char *badmagic
=
124 "Warning: bad magic number for serial struct (%s) in %s\n";
125 static const char *badinfo
=
126 "Warning: null sab82532 for (%s) in %s\n";
129 printk(badinfo
, kdevname(device
), routine
);
132 if (info
->magic
!= SERIAL_MAGIC
) {
133 printk(badmagic
, kdevname(device
), routine
);
141 * This is used to figure out the divisor speeds.
143 * The formula is: Baud = BASE_BAUD / ((N + 1) * (1 << M)),
145 * with 0 <= N < 64 and 0 <= M < 16
147 * XXX: Speeds with M = 0 might not work properly for XTAL frequencies
156 static struct ebrg_struct ebrg_table
[] = {
184 #define NR_EBRG_VALUES (sizeof(ebrg_table)/sizeof(struct ebrg_struct))
186 #define SAB82532_MAX_TEC_TIMEOUT 200000 /* 1 character time (at 50 baud) */
187 #define SAB82532_MAX_CEC_TIMEOUT 50000 /* 2.5 TX CLKs (at 50 baud) */
189 static __inline__
void sab82532_tec_wait(struct sab82532
*info
)
191 int timeout
= info
->tec_timeout
;
193 while ((readb(&info
->regs
->r
.star
) & SAB82532_STAR_TEC
) && --timeout
)
197 static __inline__
void sab82532_cec_wait(struct sab82532
*info
)
199 int timeout
= info
->cec_timeout
;
201 while ((readb(&info
->regs
->r
.star
) & SAB82532_STAR_CEC
) && --timeout
)
205 static __inline__
void sab82532_start_tx(struct sab82532
*info
)
210 save_flags(flags
); cli();
212 if (info
->xmit_cnt
<= 0)
215 if (!(readb(&info
->regs
->r
.star
) & SAB82532_STAR_XFW
))
218 info
->interrupt_mask1
&= ~(SAB82532_IMR1_ALLS
);
219 writeb(info
->interrupt_mask1
, &info
->regs
->w
.imr1
);
222 for (i
= 0; i
< info
->xmit_fifo_size
; i
++) {
223 u8 val
= info
->xmit_buf
[info
->xmit_tail
++];
224 writeb(val
, &info
->regs
->w
.xfifo
[i
]);
225 info
->xmit_tail
&= (SERIAL_XMIT_SIZE
- 1);
227 if (--info
->xmit_cnt
<= 0)
231 /* Issue a Transmit Frame command. */
232 sab82532_cec_wait(info
);
233 writeb(SAB82532_CMDR_XF
, &info
->regs
->w
.cmdr
);
236 restore_flags(flags
);
241 * ------------------------------------------------------------
242 * sab82532_stop() and sab82532_start()
244 * This routines are called before setting or resetting tty->stopped.
245 * They enable or disable transmitter interrupts, as necessary.
246 * ------------------------------------------------------------
248 static void sab82532_stop(struct tty_struct
*tty
)
250 struct sab82532
*info
= (struct sab82532
*)tty
->driver_data
;
253 if (serial_paranoia_check(info
, tty
->device
, "sab82532_stop"))
256 save_flags(flags
); cli();
257 info
->interrupt_mask1
|= SAB82532_IMR1_XPR
;
258 writeb(info
->interrupt_mask1
, &info
->regs
->w
.imr1
);
259 restore_flags(flags
);
262 static void sab82532_start(struct tty_struct
*tty
)
264 struct sab82532
*info
= (struct sab82532
*)tty
->driver_data
;
267 if (serial_paranoia_check(info
, tty
->device
, "sab82532_start"))
270 save_flags(flags
); cli();
271 info
->interrupt_mask1
&= ~(SAB82532_IMR1_XPR
);
272 writeb(info
->interrupt_mask1
, &info
->regs
->w
.imr1
);
273 sab82532_start_tx(info
);
274 restore_flags(flags
);
278 * ----------------------------------------------------------------------
280 * Here starts the interrupt handling routines. All of the following
281 * subroutines are declared as inline and are folded into
282 * sab82532_interrupt(). They were separated out for readability's sake.
284 * Note: sab82532_interrupt() is a "fast" interrupt, which means that it
285 * runs with interrupts turned off. People who may want to modify
286 * sab82532_interrupt() should try to keep the interrupt handler as fast as
287 * possible. After you are done making modifications, it is not a bad
290 * gcc -S -DKERNEL -Wall -Wstrict-prototypes -O6 -fomit-frame-pointer serial.c
292 * and look at the resulting assemble code in serial.s.
294 * - Ted Ts'o (tytso@mit.edu), 7-Mar-93
295 * -----------------------------------------------------------------------
299 * This routine is used by the interrupt handler to schedule
300 * processing in the software interrupt portion of the driver.
302 static inline void sab82532_sched_event(struct sab82532
*info
, int event
)
304 info
->event
|= 1 << event
;
305 queue_task(&info
->tqueue
, &tq_serial
);
309 static inline void receive_chars(struct sab82532
*info
,
310 union sab82532_irq_status
*stat
)
312 struct tty_struct
*tty
= info
->tty
;
313 unsigned char buf
[32];
314 unsigned char status
;
318 /* Read number of BYTES (Character + Status) available. */
319 if (stat
->sreg
.isr0
& SAB82532_ISR0_RPF
) {
320 count
= info
->recv_fifo_size
;
324 if (stat
->sreg
.isr0
& SAB82532_ISR0_TCD
) {
325 count
= readb(&info
->regs
->r
.rbcl
) & (info
->recv_fifo_size
- 1);
329 /* Issue a FIFO read command in case we where idle. */
330 if (stat
->sreg
.isr0
& SAB82532_ISR0_TIME
) {
331 sab82532_cec_wait(info
);
332 writeb(SAB82532_CMDR_RFRD
, &info
->regs
->w
.cmdr
);
336 if (stat
->sreg
.isr0
& SAB82532_ISR0_RFO
) {
337 #ifdef SERIAL_DEBUG_OVERFLOW
338 printk("sab82532: receive_chars: RFO");
344 for (i
= 0; i
< count
; i
++)
345 buf
[i
] = readb(&info
->regs
->r
.rfifo
[i
]);
347 /* Issue Receive Message Complete command. */
349 sab82532_cec_wait(info
);
350 writeb(SAB82532_CMDR_RMC
, &info
->regs
->w
.cmdr
);
353 #ifdef CONFIG_SERIAL_CONSOLE
354 if (info
->is_console
)
355 wake_up(&keypress_wait
);
360 for (i
= 0; i
< count
; ) {
361 if (tty
->flip
.count
>= TTY_FLIPBUF_SIZE
) {
362 #ifdef SERIAL_DEBUG_OVERFLOW
363 printk("sab82532: receive_chars: tty overrun\n");
365 info
->icount
.buf_overrun
++;
370 *tty
->flip
.char_buf_ptr
++ = buf
[i
++];
374 #ifdef SERIAL_DEBUG_INTR
375 printk("DR%02x:%02x...", (unsigned char)*(tty
->flip
.char_buf_ptr
- 1), status
);
378 if (status
& SAB82532_RSTAT_PE
) {
379 *tty
->flip
.flag_buf_ptr
++ = TTY_PARITY
;
380 info
->icount
.parity
++;
381 } else if (status
& SAB82532_RSTAT_FE
) {
382 *tty
->flip
.flag_buf_ptr
++ = TTY_FRAME
;
383 info
->icount
.frame
++;
386 *tty
->flip
.flag_buf_ptr
++ = TTY_NORMAL
;
389 queue_task(&tty
->flip
.tqueue
, &tq_timer
);
392 static inline void transmit_chars(struct sab82532
*info
,
393 union sab82532_irq_status
*stat
)
397 if (stat
->sreg
.isr1
& SAB82532_ISR1_ALLS
) {
398 info
->interrupt_mask1
|= SAB82532_IMR1_ALLS
;
399 writeb(info
->interrupt_mask1
, &info
->regs
->w
.imr1
);
403 if (!(stat
->sreg
.isr1
& SAB82532_ISR1_XPR
))
407 info
->interrupt_mask1
|= SAB82532_IMR1_XPR
;
408 writeb(info
->interrupt_mask1
, &info
->regs
->w
.imr1
);
412 if ((info
->xmit_cnt
<= 0) || info
->tty
->stopped
||
413 info
->tty
->hw_stopped
) {
414 info
->interrupt_mask1
|= SAB82532_IMR1_XPR
;
415 writeb(info
->interrupt_mask1
, &info
->regs
->w
.imr1
);
419 info
->interrupt_mask1
&= ~(SAB82532_IMR1_ALLS
);
420 writeb(info
->interrupt_mask1
, &info
->regs
->w
.imr1
);
423 /* Stuff 32 bytes into Transmit FIFO. */
424 for (i
= 0; i
< info
->xmit_fifo_size
; i
++) {
425 u8 val
= info
->xmit_buf
[info
->xmit_tail
++];
426 writeb(val
, &info
->regs
->w
.xfifo
[i
]);
427 info
->xmit_tail
&= (SERIAL_XMIT_SIZE
- 1);
429 if (--info
->xmit_cnt
<= 0)
433 /* Issue a Transmit Frame command. */
434 sab82532_cec_wait(info
);
435 writeb(SAB82532_CMDR_XF
, &info
->regs
->w
.cmdr
);
437 if (info
->xmit_cnt
< WAKEUP_CHARS
)
438 sab82532_sched_event(info
, RS_EVENT_WRITE_WAKEUP
);
440 #ifdef SERIAL_DEBUG_INTR
443 if (info
->xmit_cnt
<= 0) {
444 info
->interrupt_mask1
|= SAB82532_IMR1_XPR
;
445 writeb(info
->interrupt_mask1
, &info
->regs
->w
.imr1
);
449 static inline void check_status(struct sab82532
*info
,
450 union sab82532_irq_status
*stat
)
452 struct tty_struct
*tty
= info
->tty
;
453 int modem_change
= 0;
455 if (stat
->sreg
.isr1
& SAB82532_ISR1_BRK
) {
456 #ifdef CONFIG_SERIAL_CONSOLE
457 if (info
->is_console
) {
458 batten_down_hatches(info
);
462 if (tty
->flip
.count
>= TTY_FLIPBUF_SIZE
) {
463 info
->icount
.buf_overrun
++;
467 *tty
->flip
.flag_buf_ptr
++ = TTY_PARITY
;
468 *tty
->flip
.char_buf_ptr
++ = 0;
475 if (stat
->sreg
.isr0
& SAB82532_ISR0_RFO
) {
476 if (tty
->flip
.count
>= TTY_FLIPBUF_SIZE
) {
477 info
->icount
.buf_overrun
++;
481 *tty
->flip
.flag_buf_ptr
++ = TTY_PARITY
;
482 *tty
->flip
.char_buf_ptr
++ = 0;
483 info
->icount
.overrun
++;
487 if (stat
->sreg
.isr0
& SAB82532_ISR0_CDSC
) {
488 info
->dcd
= (readb(&info
->regs
->r
.vstr
) & SAB82532_VSTR_CD
) ? 0 : 1;
491 #ifdef SERIAL_DEBUG_MODEM
492 printk("DCD change: %d\n", info
->icount
.dcd
);
495 if (stat
->sreg
.isr1
& SAB82532_ISR1_CSC
) {
496 info
->cts
= readb(&info
->regs
->r
.star
) & SAB82532_STAR_CTS
;
499 #ifdef SERIAL_DEBUG_MODEM
500 printk("CTS change: %d, CTS %s\n", info
->icount
.cts
, info
->cts
? "on" : "off");
503 if ((readb(&info
->regs
->r
.pvr
) & info
->pvr_dsr_bit
) ^ info
->dsr
) {
504 info
->dsr
= (readb(&info
->regs
->r
.pvr
) & info
->pvr_dsr_bit
) ? 0 : 1;
507 #ifdef SERIAL_DEBUG_MODEM
508 printk("DSR change: %d\n", info
->icount
.dsr
);
512 wake_up_interruptible(&info
->delta_msr_wait
);
514 if ((info
->flags
& ASYNC_CHECK_CD
) &&
515 (stat
->sreg
.isr0
& SAB82532_ISR0_CDSC
)) {
517 #if (defined(SERIAL_DEBUG_OPEN) || defined(SERIAL_DEBUG_INTR))
518 printk("ttys%d CD now %s...", info
->line
,
519 (info
->dcd
) ? "on" : "off");
523 wake_up_interruptible(&info
->open_wait
);
524 else if (!((info
->flags
& ASYNC_CALLOUT_ACTIVE
) &&
525 (info
->flags
& ASYNC_CALLOUT_NOHUP
))) {
527 #ifdef SERIAL_DEBUG_OPEN
528 printk("scheduling hangup...");
531 if (schedule_task(&info
->tqueue_hangup
) == 0)
536 if (info
->flags
& ASYNC_CTS_FLOW
) {
537 if (info
->tty
->hw_stopped
) {
540 #if (defined(SERIAL_DEBUG_INTR) || defined(SERIAL_DEBUG_FLOW))
541 printk("CTS tx start...");
543 info
->tty
->hw_stopped
= 0;
544 sab82532_sched_event(info
,
545 RS_EVENT_WRITE_WAKEUP
);
546 info
->interrupt_mask1
&= ~(SAB82532_IMR1_XPR
);
547 writeb(info
->interrupt_mask1
, &info
->regs
->w
.imr1
);
548 sab82532_start_tx(info
);
553 #if (defined(SERIAL_DEBUG_INTR) || defined(SERIAL_DEBUG_FLOW))
554 printk("CTS tx stop...");
556 info
->tty
->hw_stopped
= 1;
563 * This is the serial driver's generic interrupt routine
565 static void sab82532_interrupt(int irq
, void *dev_id
, struct pt_regs
*regs
)
567 struct sab82532
*info
= dev_id
;
568 union sab82532_irq_status status
;
570 #ifdef SERIAL_DEBUG_INTR
571 printk("sab82532_interrupt(%d)...", irq
);
575 if (readb(&info
->regs
->r
.gis
) & SAB82532_GIS_ISA0
)
576 status
.sreg
.isr0
= readb(&info
->regs
->r
.isr0
);
577 if (readb(&info
->regs
->r
.gis
) & SAB82532_GIS_ISA1
)
578 status
.sreg
.isr1
= readb(&info
->regs
->r
.isr1
);
580 #ifdef SERIAL_DEBUG_INTR
581 printk("%d<%02x.%02x>", info
->line
,
582 status
.sreg
.isr0
, status
.sreg
.isr1
);
588 if (status
.sreg
.isr0
& (SAB82532_ISR0_TCD
| SAB82532_ISR0_TIME
|
589 SAB82532_ISR0_RFO
| SAB82532_ISR0_RPF
))
590 receive_chars(info
, &status
);
591 if ((status
.sreg
.isr0
& SAB82532_ISR0_CDSC
) ||
592 (status
.sreg
.isr1
& (SAB82532_ISR1_BRK
| SAB82532_ISR1_CSC
)))
593 check_status(info
, &status
);
594 if (status
.sreg
.isr1
& (SAB82532_ISR1_ALLS
| SAB82532_ISR1_XPR
))
595 transmit_chars(info
, &status
);
600 if (readb(&info
->regs
->r
.gis
) & SAB82532_GIS_ISB0
)
601 status
.sreg
.isr0
= readb(&info
->regs
->r
.isr0
);
602 if (readb(&info
->regs
->r
.gis
) & SAB82532_GIS_ISB1
)
603 status
.sreg
.isr1
= readb(&info
->regs
->r
.isr1
);
605 #ifdef SERIAL_DEBUG_INTR
606 printk("%d<%02x.%02x>", info
->line
,
607 status
.sreg
.isr0
, status
.sreg
.isr1
);
613 if (status
.sreg
.isr0
& (SAB82532_ISR0_TCD
| SAB82532_ISR0_TIME
|
614 SAB82532_ISR0_RFO
| SAB82532_ISR0_RPF
))
615 receive_chars(info
, &status
);
616 if ((status
.sreg
.isr0
& SAB82532_ISR0_CDSC
) ||
617 (status
.sreg
.isr1
& (SAB82532_ISR1_BRK
| SAB82532_ISR1_CSC
)))
618 check_status(info
, &status
);
619 if (status
.sreg
.isr1
& (SAB82532_ISR1_ALLS
| SAB82532_ISR1_XPR
))
620 transmit_chars(info
, &status
);
623 #ifdef SERIAL_DEBUG_INTR
629 * -------------------------------------------------------------------
630 * Here ends the serial interrupt routines.
631 * -------------------------------------------------------------------
635 * This routine is used to handle the "bottom half" processing for the
636 * serial driver, known also the "software interrupt" processing.
637 * This processing is done at the kernel interrupt level, after the
638 * sab82532_interrupt() has returned, BUT WITH INTERRUPTS TURNED ON. This
639 * is where time-consuming activities which can not be done in the
640 * interrupt driver proper are done; the interrupt driver schedules
641 * them using sab82532_sched_event(), and they get done here.
643 static void do_serial_bh(void)
645 run_task_queue(&tq_serial
);
648 static void do_softint(void *private_
)
650 struct sab82532
*info
= (struct sab82532
*)private_
;
651 struct tty_struct
*tty
;
657 if (test_and_clear_bit(RS_EVENT_WRITE_WAKEUP
, &info
->event
)) {
658 if ((tty
->flags
& (1 << TTY_DO_WRITE_WAKEUP
)) &&
659 tty
->ldisc
.write_wakeup
)
660 (tty
->ldisc
.write_wakeup
)(tty
);
661 wake_up_interruptible(&tty
->write_wait
);
666 * This routine is called from the scheduler tqueue when the interrupt
667 * routine has signalled that a hangup has occurred. The path of
668 * hangup processing is:
670 * serial interrupt routine -> (scheduler tqueue) ->
671 * do_serial_hangup() -> tty->hangup() -> sab82532_hangup()
674 static void do_serial_hangup(void *private_
)
676 struct sab82532
*info
= (struct sab82532
*) private_
;
677 struct tty_struct
*tty
;
686 sab82532_init_line(struct sab82532
*info
)
688 unsigned char stat
, tmp
;
691 * Wait for any commands or immediate characters
693 sab82532_cec_wait(info
);
694 sab82532_tec_wait(info
);
697 * Clear the FIFO buffers.
699 writeb(SAB82532_CMDR_RRES
, &info
->regs
->w
.cmdr
);
700 sab82532_cec_wait(info
);
701 writeb(SAB82532_CMDR_XRES
, &info
->regs
->w
.cmdr
);
704 * Clear the interrupt registers.
706 stat
= readb(&info
->regs
->r
.isr0
);
707 stat
= readb(&info
->regs
->r
.isr1
);
710 * Now, initialize the UART
712 writeb(0, &info
->regs
->w
.ccr0
); /* power-down */
713 writeb(SAB82532_CCR0_MCE
| SAB82532_CCR0_SC_NRZ
|
714 SAB82532_CCR0_SM_ASYNC
, &info
->regs
->w
.ccr0
);
715 writeb(SAB82532_CCR1_ODS
| SAB82532_CCR1_BCR
| 7, &info
->regs
->w
.ccr1
);
716 writeb(SAB82532_CCR2_BDF
| SAB82532_CCR2_SSEL
|
717 SAB82532_CCR2_TOE
, &info
->regs
->w
.ccr2
);
718 writeb(0, &info
->regs
->w
.ccr3
);
719 writeb(SAB82532_CCR4_MCK4
| SAB82532_CCR4_EBRG
, &info
->regs
->w
.ccr4
);
720 writeb(SAB82532_MODE_RTS
| SAB82532_MODE_FCTS
|
721 SAB82532_MODE_RAC
, &info
->regs
->w
.mode
);
722 writeb(SAB82532_RFC_DPS
| SAB82532_RFC_RFDF
, &info
->regs
->w
.rfc
);
723 switch (info
->recv_fifo_size
) {
725 tmp
= readb(&info
->regs
->w
.rfc
);
726 tmp
|= SAB82532_RFC_RFTH_1
;
727 writeb(tmp
, &info
->regs
->w
.rfc
);
730 tmp
= readb(&info
->regs
->w
.rfc
);
731 tmp
|= SAB82532_RFC_RFTH_4
;
732 writeb(tmp
, &info
->regs
->w
.rfc
);
735 tmp
= readb(&info
->regs
->w
.rfc
);
736 tmp
|= SAB82532_RFC_RFTH_16
;
737 writeb(tmp
, &info
->regs
->w
.rfc
);
740 info
->recv_fifo_size
= 32;
743 tmp
= readb(&info
->regs
->w
.rfc
);
744 tmp
|= SAB82532_RFC_RFTH_32
;
745 writeb(tmp
, &info
->regs
->w
.rfc
);
748 tmp
= readb(&info
->regs
->rw
.ccr0
);
749 tmp
|= SAB82532_CCR0_PU
; /* power-up */
750 writeb(tmp
, &info
->regs
->rw
.ccr0
);
753 static int startup(struct sab82532
*info
)
759 page
= get_free_page(GFP_KERNEL
);
763 save_flags(flags
); cli();
765 if (info
->flags
& ASYNC_INITIALIZED
) {
772 set_bit(TTY_IO_ERROR
, &info
->tty
->flags
);
780 info
->xmit_buf
= (unsigned char *)page
;
782 #ifdef SERIAL_DEBUG_OPEN
783 printk("starting up serial port %d...", info
->line
);
787 * Initialize the Hardware
789 sab82532_init_line(info
);
791 if (info
->tty
->termios
->c_cflag
& CBAUD
) {
794 tmp
= readb(&info
->regs
->rw
.mode
);
795 tmp
&= ~(SAB82532_MODE_FRTS
);
796 tmp
|= SAB82532_MODE_RTS
;
797 writeb(tmp
, &info
->regs
->rw
.mode
);
799 tmp
= readb(&info
->regs
->rw
.pvr
);
800 tmp
&= ~(info
->pvr_dtr_bit
);
801 writeb(tmp
, &info
->regs
->rw
.pvr
);
805 * Finally, enable interrupts
807 info
->interrupt_mask0
= SAB82532_IMR0_PERR
| SAB82532_IMR0_FERR
|
809 writeb(info
->interrupt_mask0
, &info
->regs
->w
.imr0
);
810 info
->interrupt_mask1
= SAB82532_IMR1_BRKT
| SAB82532_IMR1_ALLS
|
811 SAB82532_IMR1_XOFF
| SAB82532_IMR1_TIN
|
812 SAB82532_IMR1_CSC
| SAB82532_IMR1_XON
|
814 writeb(info
->interrupt_mask1
, &info
->regs
->w
.imr1
);
818 clear_bit(TTY_IO_ERROR
, &info
->tty
->flags
);
819 info
->xmit_cnt
= info
->xmit_head
= info
->xmit_tail
= 0;
822 * and set the speed of the serial port
826 info
->flags
|= ASYNC_INITIALIZED
;
827 restore_flags(flags
);
831 restore_flags(flags
);
836 * This routine will shutdown a serial port; interrupts are disabled, and
837 * DTR is dropped if the hangup on close termio flag is on.
839 static void shutdown(struct sab82532
*info
)
844 if (!(info
->flags
& ASYNC_INITIALIZED
))
847 #ifdef SERIAL_DEBUG_OPEN
848 printk("Shutting down serial port %d...", info
->line
);
851 save_flags(flags
); cli(); /* Disable interrupts */
854 * clear delta_msr_wait queue to avoid mem leaks: we may free the irq
855 * here so the queue might never be waken up
857 wake_up_interruptible(&info
->delta_msr_wait
);
859 if (info
->xmit_buf
) {
860 free_page((unsigned long)info
->xmit_buf
);
864 #ifdef CONFIG_SERIAL_CONSOLE
865 if (info
->is_console
) {
866 info
->interrupt_mask0
= SAB82532_IMR0_PERR
| SAB82532_IMR0_FERR
|
867 SAB82532_IMR0_PLLA
| SAB82532_IMR0_CDSC
;
868 writeb(info
->interrupt_mask0
, &info
->regs
->w
.imr0
);
869 info
->interrupt_mask1
= SAB82532_IMR1_BRKT
| SAB82532_IMR1_ALLS
|
870 SAB82532_IMR1_XOFF
| SAB82532_IMR1_TIN
|
871 SAB82532_IMR1_CSC
| SAB82532_IMR1_XON
|
873 writeb(info
->interrupt_mask1
, &info
->regs
->w
.imr1
);
875 set_bit(TTY_IO_ERROR
, &info
->tty
->flags
);
876 info
->flags
&= ~ASYNC_INITIALIZED
;
877 restore_flags(flags
);
882 /* Disable Interrupts */
883 info
->interrupt_mask0
= 0xff;
884 writeb(info
->interrupt_mask0
, &info
->regs
->w
.imr0
);
885 info
->interrupt_mask1
= 0xff;
886 writeb(info
->interrupt_mask1
, &info
->regs
->w
.imr1
);
888 if (!info
->tty
|| (info
->tty
->termios
->c_cflag
& HUPCL
)) {
889 writeb(readb(&info
->regs
->rw
.mode
) | SAB82532_MODE_FRTS
, &info
->regs
->rw
.mode
);
890 writeb(readb(&info
->regs
->rw
.mode
) | SAB82532_MODE_RTS
, &info
->regs
->rw
.mode
);
891 writeb(readb(&info
->regs
->rw
.pvr
) | info
->pvr_dtr_bit
, &info
->regs
->rw
.pvr
);
894 /* Disable break condition */
895 tmp
= readb(&info
->regs
->rw
.dafo
);
896 tmp
&= ~(SAB82532_DAFO_XBRK
);
897 writeb(tmp
, &info
->regs
->rw
.dafo
);
899 /* Disable Receiver */
900 tmp
= readb(&info
->regs
->rw
.mode
);
901 tmp
&= ~(SAB82532_MODE_RAC
);
902 writeb(tmp
, &info
->regs
->rw
.mode
);
905 tmp
= readb(&info
->regs
->rw
.ccr0
);
906 tmp
&= ~(SAB82532_CCR0_PU
);
907 writeb(tmp
, &info
->regs
->rw
.ccr0
);
910 set_bit(TTY_IO_ERROR
, &info
->tty
->flags
);
912 info
->flags
&= ~ASYNC_INITIALIZED
;
913 restore_flags(flags
);
917 * This routine is called to set the UART divisor registers to match
918 * the specified baud rate for a serial port.
920 static void change_speed(struct sab82532
*info
)
928 if (!info
->tty
|| !info
->tty
->termios
)
930 cflag
= info
->tty
->termios
->c_cflag
;
932 /* Byte size and parity */
933 switch (cflag
& CSIZE
) {
934 case CS5
: dafo
= SAB82532_DAFO_CHL5
; bits
= 7; break;
935 case CS6
: dafo
= SAB82532_DAFO_CHL6
; bits
= 8; break;
936 case CS7
: dafo
= SAB82532_DAFO_CHL7
; bits
= 9; break;
937 case CS8
: dafo
= SAB82532_DAFO_CHL8
; bits
= 10; break;
938 /* Never happens, but GCC is too dumb to figure it out */
939 default: dafo
= SAB82532_DAFO_CHL5
; bits
= 7; break;
942 if (cflag
& CSTOPB
) {
943 dafo
|= SAB82532_DAFO_STOP
;
947 if (cflag
& PARENB
) {
948 dafo
|= SAB82532_DAFO_PARE
;
952 if (cflag
& PARODD
) {
955 dafo
|= SAB82532_DAFO_PAR_MARK
;
958 dafo
|= SAB82532_DAFO_PAR_ODD
;
962 dafo
|= SAB82532_DAFO_PAR_SPACE
;
965 dafo
|= SAB82532_DAFO_PAR_EVEN
;
968 /* Determine EBRG values based on baud rate */
972 if ((i
< 1) || ((i
+ 15) >= NR_EBRG_VALUES
))
973 info
->tty
->termios
->c_cflag
&= ~CBAUDEX
;
977 ebrg
= ebrg_table
[i
].n
;
978 ebrg
|= (ebrg_table
[i
].m
<< 6);
980 info
->baud
= ebrg_table
[i
].baud
;
982 info
->timeout
= (info
->xmit_fifo_size
* HZ
* bits
) / info
->baud
;
983 info
->tec_timeout
= (10 * 1000000) / info
->baud
;
984 info
->cec_timeout
= info
->tec_timeout
>> 2;
987 info
->tec_timeout
= SAB82532_MAX_TEC_TIMEOUT
;
988 info
->cec_timeout
= SAB82532_MAX_CEC_TIMEOUT
;
990 info
->timeout
+= HZ
/ 50; /* Add .02 seconds of slop */
992 /* CTS flow control flags */
994 info
->flags
|= ASYNC_CTS_FLOW
;
996 info
->flags
&= ~(ASYNC_CTS_FLOW
);
999 info
->flags
&= ~(ASYNC_CHECK_CD
);
1001 info
->flags
|= ASYNC_CHECK_CD
;
1003 info
->tty
->hw_stopped
= 0;
1006 * Set up parity check flag
1007 * XXX: not implemented, yet.
1009 #define RELEVANT_IFLAG(iflag) (iflag & (IGNBRK|BRKINT|IGNPAR|PARMRK|INPCK))
1012 * Characters to ignore
1013 * XXX: not implemented, yet.
1017 * !!! ignore all characters if CREAD is not set
1018 * XXX: not implemented, yet.
1020 if ((cflag
& CREAD
) == 0)
1021 info
->ignore_status_mask
|= SAB82532_ISR0_RPF
|
1025 save_flags(flags
); cli();
1026 sab82532_cec_wait(info
);
1027 sab82532_tec_wait(info
);
1028 writeb(dafo
, &info
->regs
->w
.dafo
);
1029 writeb(ebrg
& 0xff, &info
->regs
->w
.bgr
);
1030 writeb(readb(&info
->regs
->rw
.ccr2
) & ~(0xc0), &info
->regs
->rw
.ccr2
);
1031 writeb(readb(&info
->regs
->rw
.ccr2
) | ((ebrg
>> 2) & 0xc0), &info
->regs
->rw
.ccr2
);
1032 if (info
->flags
& ASYNC_CTS_FLOW
) {
1033 writeb(readb(&info
->regs
->rw
.mode
) & ~(SAB82532_MODE_RTS
), &info
->regs
->rw
.mode
);
1034 writeb(readb(&info
->regs
->rw
.mode
) | SAB82532_MODE_FRTS
, &info
->regs
->rw
.mode
);
1035 writeb(readb(&info
->regs
->rw
.mode
) & ~(SAB82532_MODE_FCTS
), &info
->regs
->rw
.mode
);
1036 info
->interrupt_mask1
&= ~(SAB82532_IMR1_CSC
);
1037 writeb(info
->interrupt_mask1
, &info
->regs
->w
.imr1
);
1039 writeb(readb(&info
->regs
->rw
.mode
) | SAB82532_MODE_RTS
, &info
->regs
->rw
.mode
);
1040 writeb(readb(&info
->regs
->rw
.mode
) & ~(SAB82532_MODE_FRTS
), &info
->regs
->rw
.mode
);
1041 writeb(readb(&info
->regs
->rw
.mode
) | SAB82532_MODE_FCTS
, &info
->regs
->rw
.mode
);
1042 info
->interrupt_mask1
|= SAB82532_IMR1_CSC
;
1043 writeb(info
->interrupt_mask1
, &info
->regs
->w
.imr1
);
1045 writeb(readb(&info
->regs
->rw
.mode
) | SAB82532_MODE_RAC
, &info
->regs
->rw
.mode
);
1046 restore_flags(flags
);
1049 static void sab82532_put_char(struct tty_struct
*tty
, unsigned char ch
)
1051 struct sab82532
*info
= (struct sab82532
*)tty
->driver_data
;
1052 unsigned long flags
;
1054 if (serial_paranoia_check(info
, tty
->device
, "sab82532_put_char"))
1057 if (!tty
|| !info
->xmit_buf
)
1060 save_flags(flags
); cli();
1061 if (info
->xmit_cnt
>= SERIAL_XMIT_SIZE
- 1) {
1062 restore_flags(flags
);
1066 info
->xmit_buf
[info
->xmit_head
++] = ch
;
1067 info
->xmit_head
&= SERIAL_XMIT_SIZE
-1;
1069 restore_flags(flags
);
1072 static void sab82532_flush_chars(struct tty_struct
*tty
)
1074 struct sab82532
*info
= (struct sab82532
*)tty
->driver_data
;
1075 unsigned long flags
;
1077 if (serial_paranoia_check(info
, tty
->device
, "sab82532_flush_chars"))
1080 if (info
->xmit_cnt
<= 0 || tty
->stopped
|| tty
->hw_stopped
||
1084 save_flags(flags
); cli();
1085 info
->interrupt_mask1
&= ~(SAB82532_IMR1_XPR
);
1086 writeb(info
->interrupt_mask1
, &info
->regs
->w
.imr1
);
1087 sab82532_start_tx(info
);
1088 restore_flags(flags
);
1091 static int sab82532_write(struct tty_struct
* tty
, int from_user
,
1092 const unsigned char *buf
, int count
)
1095 struct sab82532
*info
= (struct sab82532
*)tty
->driver_data
;
1096 unsigned long flags
;
1098 if (serial_paranoia_check(info
, tty
->device
, "sab82532_write"))
1101 if (!tty
|| !info
->xmit_buf
|| !tmp_buf
)
1109 c
= MIN(count
, MIN(SERIAL_XMIT_SIZE
- info
->xmit_cnt
- 1,
1110 SERIAL_XMIT_SIZE
- info
->xmit_head
));
1115 c
-= copy_from_user(tmp_buf
, buf
, c
);
1121 c
= MIN(c
, MIN(SERIAL_XMIT_SIZE
- info
->xmit_cnt
- 1,
1122 SERIAL_XMIT_SIZE
- info
->xmit_head
));
1123 memcpy(info
->xmit_buf
+ info
->xmit_head
, tmp_buf
, c
);
1125 memcpy(info
->xmit_buf
+ info
->xmit_head
, buf
, c
);
1126 info
->xmit_head
= (info
->xmit_head
+ c
) & (SERIAL_XMIT_SIZE
-1);
1127 info
->xmit_cnt
+= c
;
1128 restore_flags(flags
);
1136 if (info
->xmit_cnt
&& !tty
->stopped
&& !tty
->hw_stopped
) {
1137 info
->interrupt_mask1
&= ~(SAB82532_IMR1_XPR
);
1138 writeb(info
->interrupt_mask1
, &info
->regs
->w
.imr1
);
1139 sab82532_start_tx(info
);
1142 restore_flags(flags
);
1146 static int sab82532_write_room(struct tty_struct
*tty
)
1148 struct sab82532
*info
= (struct sab82532
*)tty
->driver_data
;
1151 if (serial_paranoia_check(info
, tty
->device
, "sab82532_write_room"))
1153 ret
= SERIAL_XMIT_SIZE
- info
->xmit_cnt
- 1;
1159 static int sab82532_chars_in_buffer(struct tty_struct
*tty
)
1161 struct sab82532
*info
= (struct sab82532
*)tty
->driver_data
;
1163 if (serial_paranoia_check(info
, tty
->device
, "sab82532_chars_in_buffer"))
1165 return info
->xmit_cnt
;
1168 static void sab82532_flush_buffer(struct tty_struct
*tty
)
1170 struct sab82532
*info
= (struct sab82532
*)tty
->driver_data
;
1172 if (serial_paranoia_check(info
, tty
->device
, "sab82532_flush_buffer"))
1175 info
->xmit_cnt
= info
->xmit_head
= info
->xmit_tail
= 0;
1177 wake_up_interruptible(&tty
->write_wait
);
1178 if ((tty
->flags
& (1 << TTY_DO_WRITE_WAKEUP
)) &&
1179 tty
->ldisc
.write_wakeup
)
1180 (tty
->ldisc
.write_wakeup
)(tty
);
1184 * This function is used to send a high-priority XON/XOFF character to
1187 static void sab82532_send_xchar(struct tty_struct
*tty
, char ch
)
1189 struct sab82532
*info
= (struct sab82532
*)tty
->driver_data
;
1190 unsigned long flags
;
1192 if (serial_paranoia_check(info
, tty
->device
, "sab82532_send_xchar"))
1195 save_flags(flags
); cli();
1196 sab82532_tec_wait(info
);
1197 writeb(ch
, &info
->regs
->w
.tic
);
1198 restore_flags(flags
);
1202 * ------------------------------------------------------------
1203 * sab82532_throttle()
1205 * This routine is called by the upper-layer tty layer to signal that
1206 * incoming characters should be throttled.
1207 * ------------------------------------------------------------
1209 static void sab82532_throttle(struct tty_struct
* tty
)
1211 struct sab82532
*info
= (struct sab82532
*)tty
->driver_data
;
1212 #ifdef SERIAL_DEBUG_THROTTLE
1215 printk("throttle %s: %d....\n", _tty_name(tty
, buf
),
1216 tty
->ldisc
.chars_in_buffer(tty
));
1219 if (serial_paranoia_check(info
, tty
->device
, "sab82532_throttle"))
1223 sab82532_send_xchar(tty
, STOP_CHAR(tty
));
1226 static void sab82532_unthrottle(struct tty_struct
* tty
)
1228 struct sab82532
*info
= (struct sab82532
*)tty
->driver_data
;
1229 #ifdef SERIAL_DEBUG_THROTTLE
1232 printk("unthrottle %s: %d....\n", _tty_name(tty
, buf
),
1233 tty
->ldisc
.chars_in_buffer(tty
));
1236 if (serial_paranoia_check(info
, tty
->device
, "sab82532_unthrottle"))
1243 sab82532_send_xchar(tty
, START_CHAR(tty
));
1248 * ------------------------------------------------------------
1249 * sab82532_ioctl() and friends
1250 * ------------------------------------------------------------
1253 static int get_serial_info(struct sab82532
*info
,
1254 struct serial_struct
*retinfo
)
1256 struct serial_struct tmp
;
1260 memset(&tmp
, 0, sizeof(tmp
));
1261 tmp
.type
= info
->type
;
1262 tmp
.line
= info
->line
;
1263 tmp
.port
= (unsigned long)info
->regs
;
1264 tmp
.irq
= info
->irq
;
1265 tmp
.flags
= info
->flags
;
1266 tmp
.xmit_fifo_size
= info
->xmit_fifo_size
;
1267 tmp
.baud_base
= info
->baud_base
;
1268 tmp
.close_delay
= info
->close_delay
;
1269 tmp
.closing_wait
= info
->closing_wait
;
1270 tmp
.custom_divisor
= info
->custom_divisor
;
1272 if (copy_to_user(retinfo
, &tmp
, sizeof(*retinfo
)))
1277 static int set_serial_info(struct sab82532
*info
,
1278 struct serial_struct
*new_info
)
1285 * get_lsr_info - get line status register info
1287 * Purpose: Let user call ioctl() to get info when the UART physically
1288 * is emptied. On bus types like RS485, the transmitter must
1289 * release the bus after transmitting. This must be done when
1290 * the transmit shift register is empty, not be done when the
1291 * transmit holding register is empty. This functionality
1292 * allows an RS485 driver to be written in user space.
1294 static int get_lsr_info(struct sab82532
* info
, unsigned int *value
)
1296 unsigned int result
;
1298 result
= (!info
->xmit_buf
&& info
->all_sent
) ? TIOCSER_TEMT
: 0;
1299 return put_user(result
, value
);
1303 static int get_modem_info(struct sab82532
* info
, unsigned int *value
)
1305 unsigned int result
;
1307 result
= ((readb(&info
->regs
->r
.mode
) & SAB82532_MODE_RTS
) ?
1308 ((readb(&info
->regs
->r
.mode
) & SAB82532_MODE_FRTS
) ? 0 : TIOCM_RTS
)
1310 | ((readb(&info
->regs
->r
.pvr
) & info
->pvr_dtr_bit
) ? 0 : TIOCM_DTR
)
1311 | ((readb(&info
->regs
->r
.vstr
) & SAB82532_VSTR_CD
) ? 0 : TIOCM_CAR
)
1312 | ((readb(&info
->regs
->r
.pvr
) & info
->pvr_dsr_bit
) ? 0 : TIOCM_DSR
)
1313 | ((readb(&info
->regs
->r
.star
) & SAB82532_STAR_CTS
) ? TIOCM_CTS
: 0);
1314 return put_user(result
,value
);
1317 static int set_modem_info(struct sab82532
* info
, unsigned int cmd
,
1318 unsigned int *value
)
1323 error
= get_user(arg
, value
);
1328 if (arg
& TIOCM_RTS
) {
1329 writeb(readb(&info
->regs
->rw
.mode
) & ~(SAB82532_MODE_FRTS
), &info
->regs
->rw
.mode
);
1330 writeb(readb(&info
->regs
->rw
.mode
) | SAB82532_MODE_RTS
, &info
->regs
->rw
.mode
);
1332 if (arg
& TIOCM_DTR
) {
1333 writeb(readb(&info
->regs
->rw
.pvr
) & ~(info
->pvr_dtr_bit
), &info
->regs
->rw
.pvr
);
1337 if (arg
& TIOCM_RTS
) {
1338 writeb(readb(&info
->regs
->rw
.mode
) | SAB82532_MODE_FRTS
, &info
->regs
->rw
.mode
);
1339 writeb(readb(&info
->regs
->rw
.mode
) | SAB82532_MODE_RTS
, &info
->regs
->rw
.mode
);
1341 if (arg
& TIOCM_DTR
) {
1342 writeb(readb(&info
->regs
->rw
.pvr
) | info
->pvr_dtr_bit
, &info
->regs
->rw
.pvr
);
1346 if (arg
& TIOCM_RTS
) {
1347 writeb(readb(&info
->regs
->rw
.mode
) & ~(SAB82532_MODE_FRTS
), &info
->regs
->rw
.mode
);
1348 writeb(readb(&info
->regs
->rw
.mode
) | SAB82532_MODE_RTS
, &info
->regs
->rw
.mode
);
1350 writeb(readb(&info
->regs
->rw
.mode
) | SAB82532_MODE_FRTS
, &info
->regs
->rw
.mode
);
1351 writeb(readb(&info
->regs
->rw
.mode
) | SAB82532_MODE_RTS
, &info
->regs
->rw
.mode
);
1353 if (arg
& TIOCM_DTR
) {
1354 writeb(readb(&info
->regs
->rw
.pvr
) & ~(info
->pvr_dtr_bit
), &info
->regs
->rw
.pvr
);
1356 writeb(readb(&info
->regs
->rw
.pvr
) | info
->pvr_dtr_bit
, &info
->regs
->rw
.pvr
);
1366 * This routine sends a break character out the serial port.
1368 static void sab82532_break(struct tty_struct
*tty
, int break_state
)
1370 struct sab82532
* info
= (struct sab82532
*)tty
->driver_data
;
1371 unsigned long flags
;
1373 if (serial_paranoia_check(info
, tty
->device
, "sab82532_break"))
1379 #ifdef SERIAL_DEBUG_SEND_BREAK
1380 printk("sab82532_break(%d) jiff=%lu...", break_state
, jiffies
);
1382 save_flags(flags
); cli();
1383 if (break_state
== -1)
1384 writeb(readb(&info
->regs
->rw
.dafo
) | SAB82532_DAFO_XBRK
, &info
->regs
->rw
.dafo
);
1386 writeb(readb(&info
->regs
->rw
.dafo
) & ~(SAB82532_DAFO_XBRK
), &info
->regs
->rw
.dafo
);
1387 restore_flags(flags
);
1391 static int sab82532_ioctl(struct tty_struct
*tty
, struct file
* file
,
1392 unsigned int cmd
, unsigned long arg
)
1395 struct sab82532
* info
= (struct sab82532
*)tty
->driver_data
;
1396 struct async_icount cprev
, cnow
; /* kernel counter temps */
1397 struct serial_icounter_struct
*p_cuser
; /* user space */
1399 if (serial_paranoia_check(info
, tty
->device
, "sab82532_ioctl"))
1402 if ((cmd
!= TIOCGSERIAL
) && (cmd
!= TIOCSSERIAL
) &&
1403 (cmd
!= TIOCSERCONFIG
) && (cmd
!= TIOCSERGWILD
) &&
1404 (cmd
!= TIOCSERSWILD
) && (cmd
!= TIOCSERGSTRUCT
) &&
1405 (cmd
!= TIOCMIWAIT
) && (cmd
!= TIOCGICOUNT
)) {
1406 if (tty
->flags
& (1 << TTY_IO_ERROR
))
1412 return put_user(C_CLOCAL(tty
) ? 1 : 0, (int *) arg
);
1414 error
= get_user(arg
, (unsigned int *) arg
);
1417 tty
->termios
->c_cflag
=
1418 ((tty
->termios
->c_cflag
& ~CLOCAL
) |
1419 (arg
? CLOCAL
: 0));
1422 return get_modem_info(info
, (unsigned int *) arg
);
1426 return set_modem_info(info
, cmd
, (unsigned int *) arg
);
1428 return get_serial_info(info
,
1429 (struct serial_struct
*) arg
);
1431 return set_serial_info(info
,
1432 (struct serial_struct
*) arg
);
1434 case TIOCSERGETLSR
: /* Get line status register */
1435 return get_lsr_info(info
, (unsigned int *) arg
);
1437 case TIOCSERGSTRUCT
:
1438 if (copy_to_user((struct sab82532
*) arg
,
1439 info
, sizeof(struct sab82532
)))
1444 * Wait for any of the 4 modem inputs (DCD,RI,DSR,CTS) to change
1445 * - mask passed in arg for lines of interest
1446 * (use |'ed TIOCM_RNG/DSR/CD/CTS for masking)
1447 * Caller should use TIOCGICOUNT to see which one it was
1451 /* note the counters on entry */
1452 cprev
= info
->icount
;
1455 interruptible_sleep_on(&info
->delta_msr_wait
);
1456 /* see if a signal did it */
1457 if (signal_pending(current
))
1458 return -ERESTARTSYS
;
1460 cnow
= info
->icount
; /* atomic copy */
1462 if (cnow
.rng
== cprev
.rng
&& cnow
.dsr
== cprev
.dsr
&&
1463 cnow
.dcd
== cprev
.dcd
&& cnow
.cts
== cprev
.cts
)
1464 return -EIO
; /* no change => error */
1465 if ( ((arg
& TIOCM_RNG
) && (cnow
.rng
!= cprev
.rng
)) ||
1466 ((arg
& TIOCM_DSR
) && (cnow
.dsr
!= cprev
.dsr
)) ||
1467 ((arg
& TIOCM_CD
) && (cnow
.dcd
!= cprev
.dcd
)) ||
1468 ((arg
& TIOCM_CTS
) && (cnow
.cts
!= cprev
.cts
)) ) {
1476 * Get counter of input serial line interrupts (DCD,RI,DSR,CTS)
1477 * Return: write counters to the user passed counter struct
1478 * NB: both 1->0 and 0->1 transitions are counted except for
1479 * RI where only 0->1 is counted.
1483 cnow
= info
->icount
;
1485 p_cuser
= (struct serial_icounter_struct
*) arg
;
1486 error
= put_user(cnow
.cts
, &p_cuser
->cts
);
1487 if (error
) return error
;
1488 error
= put_user(cnow
.dsr
, &p_cuser
->dsr
);
1489 if (error
) return error
;
1490 error
= put_user(cnow
.rng
, &p_cuser
->rng
);
1491 if (error
) return error
;
1492 error
= put_user(cnow
.dcd
, &p_cuser
->dcd
);
1493 if (error
) return error
;
1497 return -ENOIOCTLCMD
;
1502 static void sab82532_set_termios(struct tty_struct
*tty
,
1503 struct termios
*old_termios
)
1505 struct sab82532
*info
= (struct sab82532
*)tty
->driver_data
;
1507 if ( (tty
->termios
->c_cflag
== old_termios
->c_cflag
)
1508 && ( RELEVANT_IFLAG(tty
->termios
->c_iflag
)
1509 == RELEVANT_IFLAG(old_termios
->c_iflag
)))
1514 /* Handle transition to B0 status */
1515 if ((old_termios
->c_cflag
& CBAUD
) &&
1516 !(tty
->termios
->c_cflag
& CBAUD
)) {
1517 writeb(readb(&info
->regs
->w
.mode
) | SAB82532_MODE_FRTS
, &info
->regs
->w
.mode
);
1518 writeb(readb(&info
->regs
->w
.mode
) | SAB82532_MODE_RTS
, &info
->regs
->w
.mode
);
1519 writeb(readb(&info
->regs
->w
.pvr
) | info
->pvr_dtr_bit
, &info
->regs
->w
.pvr
);
1522 /* Handle transition away from B0 status */
1523 if (!(old_termios
->c_cflag
& CBAUD
) &&
1524 (tty
->termios
->c_cflag
& CBAUD
)) {
1525 writeb(readb(&info
->regs
->w
.pvr
) & ~(info
->pvr_dtr_bit
), &info
->regs
->w
.pvr
);
1526 if (!tty
->hw_stopped
||
1527 !(tty
->termios
->c_cflag
& CRTSCTS
)) {
1528 writeb(readb(&info
->regs
->w
.mode
) & ~(SAB82532_MODE_FRTS
), &info
->regs
->w
.mode
);
1529 writeb(readb(&info
->regs
->w
.mode
) | SAB82532_MODE_RTS
, &info
->regs
->w
.mode
);
1533 /* Handle turning off CRTSCTS */
1534 if ((old_termios
->c_cflag
& CRTSCTS
) &&
1535 !(tty
->termios
->c_cflag
& CRTSCTS
)) {
1536 tty
->hw_stopped
= 0;
1537 sab82532_start(tty
);
1542 * ------------------------------------------------------------
1545 * This routine is called when the serial port gets closed. First, we
1546 * wait for the last remaining data to be sent. Then, we unlink its
1547 * async structure from the interrupt chain if necessary, and we free
1548 * that IRQ if nothing is left in the chain.
1549 * ------------------------------------------------------------
1551 static void sab82532_close(struct tty_struct
*tty
, struct file
* filp
)
1553 struct sab82532
*info
= (struct sab82532
*)tty
->driver_data
;
1554 unsigned long flags
;
1556 if (!info
|| serial_paranoia_check(info
, tty
->device
, "sab82532_close"))
1559 save_flags(flags
); cli();
1561 if (tty_hung_up_p(filp
)) {
1563 restore_flags(flags
);
1567 #ifdef SERIAL_DEBUG_OPEN
1568 printk("sab82532_close ttys%d, count = %d\n", info
->line
, info
->count
);
1570 if ((tty
->count
== 1) && (info
->count
!= 1)) {
1572 * Uh, oh. tty->count is 1, which means that the tty
1573 * structure will be freed. info->count should always
1574 * be one in these conditions. If it's greater than
1575 * one, we've got real problems, since it means the
1576 * serial port won't be shutdown.
1578 printk("sab82532_close: bad serial port count; tty->count is 1,"
1579 " info->count is %d\n", info
->count
);
1582 if (--info
->count
< 0) {
1583 printk("sab82532_close: bad serial port count for ttys%d: %d\n",
1584 info
->line
, info
->count
);
1589 restore_flags(flags
);
1592 info
->flags
|= ASYNC_CLOSING
;
1594 * Save the termios structure, since this port may have
1595 * separate termios for callout and dialin.
1597 if (info
->flags
& ASYNC_NORMAL_ACTIVE
)
1598 info
->normal_termios
= *tty
->termios
;
1599 if (info
->flags
& ASYNC_CALLOUT_ACTIVE
)
1600 info
->callout_termios
= *tty
->termios
;
1602 * Now we wait for the transmit buffer to clear; and we notify
1603 * the line discipline to only process XON/XOFF characters.
1606 if (info
->closing_wait
!= ASYNC_CLOSING_WAIT_NONE
)
1607 tty_wait_until_sent(tty
, info
->closing_wait
);
1610 * At this point we stop accepting input. To do this, we
1611 * disable the receive line status interrupts, and turn off
1614 info
->interrupt_mask0
|= SAB82532_IMR0_TCD
;
1615 writeb(info
->interrupt_mask0
, &info
->regs
->w
.imr0
);
1616 if (info
->flags
& ASYNC_INITIALIZED
) {
1618 * Before we drop DTR, make sure the UART transmitter
1619 * has completely drained; this is especially
1620 * important if there is a transmit FIFO!
1622 sab82532_wait_until_sent(tty
, info
->timeout
);
1625 if (tty
->driver
.flush_buffer
)
1626 tty
->driver
.flush_buffer(tty
);
1627 if (tty
->ldisc
.flush_buffer
)
1628 tty
->ldisc
.flush_buffer(tty
);
1632 if (info
->blocked_open
) {
1633 if (info
->close_delay
) {
1634 current
->state
= TASK_INTERRUPTIBLE
;
1635 schedule_timeout(info
->close_delay
);
1637 wake_up_interruptible(&info
->open_wait
);
1639 info
->flags
&= ~(ASYNC_NORMAL_ACTIVE
|ASYNC_CALLOUT_ACTIVE
|
1641 wake_up_interruptible(&info
->close_wait
);
1643 restore_flags(flags
);
1647 * sab82532_wait_until_sent() --- wait until the transmitter is empty
1649 static void sab82532_wait_until_sent(struct tty_struct
*tty
, int timeout
)
1651 struct sab82532
*info
= (struct sab82532
*)tty
->driver_data
;
1652 unsigned long orig_jiffies
, char_time
;
1654 if (serial_paranoia_check(info
,tty
->device
,"sab82532_wait_until_sent"))
1657 orig_jiffies
= jiffies
;
1659 * Set the check interval to be 1/5 of the estimated time to
1660 * send a single character, and make it at least 1. The check
1661 * interval should also be less than the timeout.
1663 * Note: we have to use pretty tight timings here to satisfy
1666 char_time
= (info
->timeout
- HZ
/50) / info
->xmit_fifo_size
;
1667 char_time
= char_time
/ 5;
1671 char_time
= MIN(char_time
, timeout
);
1672 #ifdef SERIAL_DEBUG_WAIT_UNTIL_SENT
1673 printk("In sab82532_wait_until_sent(%d) check=%lu...", timeout
, char_time
);
1674 printk("jiff=%lu...", jiffies
);
1676 while (info
->xmit_cnt
|| !info
->all_sent
) {
1677 current
->state
= TASK_INTERRUPTIBLE
;
1678 schedule_timeout(char_time
);
1679 if (signal_pending(current
))
1681 if (timeout
&& time_after(jiffies
, orig_jiffies
+ timeout
))
1684 #ifdef SERIAL_DEBUG_WAIT_UNTIL_SENT
1685 printk("xmit_cnt = %d, alls = %d (jiff=%lu)...done\n", info
->xmit_cnt
, info
->all_sent
, jiffies
);
1690 * sab82532_hangup() --- called by tty_hangup() when a hangup is signaled.
1692 static void sab82532_hangup(struct tty_struct
*tty
)
1694 struct sab82532
* info
= (struct sab82532
*)tty
->driver_data
;
1696 if (serial_paranoia_check(info
, tty
->device
, "sab82532_hangup"))
1699 #ifdef CONFIG_SERIAL_CONSOLE
1700 if (info
->is_console
)
1704 sab82532_flush_buffer(tty
);
1708 info
->flags
&= ~(ASYNC_NORMAL_ACTIVE
|ASYNC_CALLOUT_ACTIVE
);
1710 wake_up_interruptible(&info
->open_wait
);
1714 * ------------------------------------------------------------
1715 * sab82532_open() and friends
1716 * ------------------------------------------------------------
1718 static int block_til_ready(struct tty_struct
*tty
, struct file
* filp
,
1719 struct sab82532
*info
)
1721 DECLARE_WAITQUEUE(wait
, current
);
1726 * If the device is in the middle of being closed, then block
1727 * until it's done, and then try again.
1729 if (tty_hung_up_p(filp
) ||
1730 (info
->flags
& ASYNC_CLOSING
)) {
1731 if (info
->flags
& ASYNC_CLOSING
)
1732 interruptible_sleep_on(&info
->close_wait
);
1733 #ifdef SERIAL_DO_RESTART
1734 if (info
->flags
& ASYNC_HUP_NOTIFY
)
1737 return -ERESTARTSYS
;
1744 * If this is a callout device, then just make sure the normal
1745 * device isn't being used.
1747 if (tty
->driver
.subtype
== SERIAL_TYPE_CALLOUT
) {
1748 if (info
->flags
& ASYNC_NORMAL_ACTIVE
)
1750 if ((info
->flags
& ASYNC_CALLOUT_ACTIVE
) &&
1751 (info
->flags
& ASYNC_SESSION_LOCKOUT
) &&
1752 (info
->session
!= current
->session
))
1754 if ((info
->flags
& ASYNC_CALLOUT_ACTIVE
) &&
1755 (info
->flags
& ASYNC_PGRP_LOCKOUT
) &&
1756 (info
->pgrp
!= current
->pgrp
))
1758 info
->flags
|= ASYNC_CALLOUT_ACTIVE
;
1763 * If non-blocking mode is set, or the port is not enabled,
1764 * then make the check up front and then exit.
1766 if ((filp
->f_flags
& O_NONBLOCK
) ||
1767 (tty
->flags
& (1 << TTY_IO_ERROR
))) {
1768 if (info
->flags
& ASYNC_CALLOUT_ACTIVE
)
1770 info
->flags
|= ASYNC_NORMAL_ACTIVE
;
1774 if (info
->flags
& ASYNC_CALLOUT_ACTIVE
) {
1775 if (info
->normal_termios
.c_cflag
& CLOCAL
)
1778 if (tty
->termios
->c_cflag
& CLOCAL
)
1783 * Block waiting for the carrier detect and the line to become
1784 * free (i.e., not in use by the callout). While we are in
1785 * this loop, info->count is dropped by one, so that
1786 * sab82532_close() knows when to free things. We restore it upon
1787 * exit, either normal or abnormal.
1790 add_wait_queue(&info
->open_wait
, &wait
);
1791 #ifdef SERIAL_DEBUG_OPEN
1792 printk("block_til_ready before block: ttyS%d, count = %d\n",
1793 info
->line
, info
->count
);
1796 if (!tty_hung_up_p(filp
))
1799 info
->blocked_open
++;
1802 if (!(info
->flags
& ASYNC_CALLOUT_ACTIVE
) &&
1803 (tty
->termios
->c_cflag
& CBAUD
)) {
1804 writeb(readb(&info
->regs
->rw
.pvr
) & ~(info
->pvr_dtr_bit
), &info
->regs
->rw
.pvr
);
1805 writeb(readb(&info
->regs
->rw
.mode
) | SAB82532_MODE_FRTS
, &info
->regs
->rw
.mode
);
1806 writeb(readb(&info
->regs
->rw
.mode
) & ~(SAB82532_MODE_RTS
), &info
->regs
->rw
.mode
);
1809 set_current_state(TASK_INTERRUPTIBLE
);
1810 if (tty_hung_up_p(filp
) ||
1811 !(info
->flags
& ASYNC_INITIALIZED
)) {
1812 #ifdef SERIAL_DO_RESTART
1813 if (info
->flags
& ASYNC_HUP_NOTIFY
)
1816 retval
= -ERESTARTSYS
;
1822 if (!(info
->flags
& ASYNC_CALLOUT_ACTIVE
) &&
1823 !(info
->flags
& ASYNC_CLOSING
) &&
1824 (do_clocal
|| !(readb(&info
->regs
->r
.vstr
) & SAB82532_VSTR_CD
)))
1826 if (signal_pending(current
)) {
1827 retval
= -ERESTARTSYS
;
1830 #ifdef SERIAL_DEBUG_OPEN
1831 printk("block_til_ready blocking: ttyS%d, count = %d, flags = %x, clocal = %d, vstr = %02x\n",
1832 info
->line
, info
->count
, info
->flags
, do_clocal
, readb(&info
->regs
->r
.vstr
));
1836 current
->state
= TASK_RUNNING
;
1837 remove_wait_queue(&info
->open_wait
, &wait
);
1838 if (!tty_hung_up_p(filp
))
1840 info
->blocked_open
--;
1841 #ifdef SERIAL_DEBUG_OPEN
1842 printk("block_til_ready after blocking: ttys%d, count = %d\n",
1843 info
->line
, info
->count
);
1847 info
->flags
|= ASYNC_NORMAL_ACTIVE
;
1852 * This routine is called whenever a serial port is opened. It
1853 * enables interrupts for a serial port, linking in its async structure into
1854 * the IRQ chain. It also performs the serial-specific
1855 * initialization for the tty structure.
1857 static int sab82532_open(struct tty_struct
*tty
, struct file
* filp
)
1859 struct sab82532
*info
= sab82532_chain
;
1863 #ifdef SERIAL_DEBUG_OPEN
1864 printk("sab82532_open: count = %d\n", info
->count
);
1867 line
= MINOR(tty
->device
) - tty
->driver
.minor_start
;
1868 if ((line
< 0) || (line
>= NR_PORTS
))
1872 if (info
->line
== line
)
1877 printk("sab82532_open: can't find info for line %d\n",
1882 if (serial_paranoia_check(info
, tty
->device
, "sab82532_open"))
1885 #ifdef SERIAL_DEBUG_OPEN
1886 printk("sab82532_open %s%d, count = %d\n", tty
->driver
.name
, info
->line
,
1891 tty
->driver_data
= info
;
1895 page
= get_free_page(GFP_KERNEL
);
1901 tmp_buf
= (unsigned char *) page
;
1905 * If the port is in the middle of closing, bail out now.
1907 if (tty_hung_up_p(filp
) ||
1908 (info
->flags
& ASYNC_CLOSING
)) {
1909 if (info
->flags
& ASYNC_CLOSING
)
1910 interruptible_sleep_on(&info
->close_wait
);
1911 #ifdef SERIAL_DO_RESTART
1912 return ((info
->flags
& ASYNC_HUP_NOTIFY
) ?
1913 -EAGAIN
: -ERESTARTSYS
);
1920 * Start up serial port
1922 retval
= startup(info
);
1927 retval
= block_til_ready(tty
, filp
, info
);
1929 #ifdef SERIAL_DEBUG_OPEN
1930 printk("sab82532_open returning after block_til_ready with %d\n",
1936 if ((info
->count
== 1) &&
1937 (info
->flags
& ASYNC_SPLIT_TERMIOS
)) {
1938 if (tty
->driver
.subtype
== SERIAL_TYPE_NORMAL
)
1939 *tty
->termios
= info
->normal_termios
;
1941 *tty
->termios
= info
->callout_termios
;
1945 #ifdef CONFIG_SERIAL_CONSOLE
1946 if (sab82532_console
.cflag
&& sab82532_console
.index
== line
) {
1947 tty
->termios
->c_cflag
= sab82532_console
.cflag
;
1948 sab82532_console
.cflag
= 0;
1953 info
->session
= current
->session
;
1954 info
->pgrp
= current
->pgrp
;
1956 #ifdef SERIAL_DEBUG_OPEN
1957 printk("sab82532_open ttys%d successful... count %d", info
->line
, info
->count
);
1963 * /proc fs routines....
1966 static __inline__
int
1967 line_info(char *buf
, struct sab82532
*info
)
1969 unsigned long flags
;
1973 ret
= sprintf(buf
, "%u: uart:SAB82532 ", info
->line
);
1974 switch (info
->type
) {
1976 ret
+= sprintf(buf
+ret
, "V1.0 ");
1979 ret
+= sprintf(buf
+ret
, "V2.0 ");
1982 ret
+= sprintf(buf
+ret
, "V3.2 ");
1985 ret
+= sprintf(buf
+ret
, "V?.? ");
1988 ret
+= sprintf(buf
+ret
, "port:%lX irq:%s",
1989 (unsigned long)info
->regs
, __irq_itoa(info
->irq
));
1992 ret
+= sprintf(buf
+ret
, "\n");
1997 * Figure out the current RS-232 lines
2001 save_flags(flags
); cli();
2002 if (readb(&info
->regs
->r
.mode
) & SAB82532_MODE_RTS
) {
2003 if (!(readb(&info
->regs
->r
.mode
) & SAB82532_MODE_FRTS
))
2004 strcat(stat_buf
, "|RTS");
2006 strcat(stat_buf
, "|RTS");
2008 if (readb(&info
->regs
->r
.star
) & SAB82532_STAR_CTS
)
2009 strcat(stat_buf
, "|CTS");
2010 if (!(readb(&info
->regs
->r
.pvr
) & info
->pvr_dtr_bit
))
2011 strcat(stat_buf
, "|DTR");
2012 if (!(readb(&info
->regs
->r
.pvr
) & info
->pvr_dsr_bit
))
2013 strcat(stat_buf
, "|DSR");
2014 if (!(readb(&info
->regs
->r
.vstr
) & SAB82532_VSTR_CD
))
2015 strcat(stat_buf
, "|CD");
2016 restore_flags(flags
);
2019 ret
+= sprintf(buf
+ret
, " baud:%u", info
->baud
);
2021 ret
+= sprintf(buf
+ret
, " tx:%u rx:%u",
2022 info
->icount
.tx
, info
->icount
.rx
);
2024 if (info
->icount
.frame
)
2025 ret
+= sprintf(buf
+ret
, " fe:%u", info
->icount
.frame
);
2027 if (info
->icount
.parity
)
2028 ret
+= sprintf(buf
+ret
, " pe:%u", info
->icount
.parity
);
2030 if (info
->icount
.brk
)
2031 ret
+= sprintf(buf
+ret
, " brk:%u", info
->icount
.brk
);
2033 if (info
->icount
.overrun
)
2034 ret
+= sprintf(buf
+ret
, " oe:%u", info
->icount
.overrun
);
2037 * Last thing is the RS-232 status lines.
2039 ret
+= sprintf(buf
+ret
, " %s\n", stat_buf
+ 1);
2043 int sab82532_read_proc(char *page
, char **start
, off_t off
, int count
,
2044 int *eof
, void *data
)
2046 struct sab82532
*info
= sab82532_chain
;
2050 len
+= sprintf(page
, "serinfo:1.0 driver:%s\n", serial_version
);
2051 for (info
= sab82532_chain
; info
&& len
< 4000; info
= info
->next
) {
2052 len
+= line_info(page
+ len
, info
);
2053 if (len
+begin
> off
+count
)
2055 if (len
+begin
< off
) {
2062 if (off
>= len
+begin
)
2064 *start
= page
+ (off
-begin
);
2065 return ((count
< begin
+len
-off
) ? count
: begin
+len
-off
);
2069 * ---------------------------------------------------------------------
2070 * sab82532_init() and friends
2072 * sab82532_init() is called at boot-time to initialize the serial driver.
2073 * ---------------------------------------------------------------------
2075 static int __init
get_sab82532(unsigned long *memory_start
)
2077 struct linux_ebus
*ebus
;
2078 struct linux_ebus_device
*edev
= 0;
2079 struct sab82532
*sab
;
2080 unsigned long regs
, offset
;
2083 for_each_ebus(ebus
) {
2084 for_each_ebusdev(edev
, ebus
) {
2085 if (!strcmp(edev
->prom_name
, "se"))
2093 regs
= edev
->resource
[0].start
;
2094 offset
= sizeof(union sab82532_async_regs
);
2096 for (i
= 0; i
< 2; i
++) {
2098 *memory_start
= (*memory_start
+ 7) & ~(7);
2099 sab
= (struct sab82532
*)*memory_start
;
2100 *memory_start
+= sizeof(struct sab82532
);
2102 sab
= (struct sab82532
*)kmalloc(sizeof(struct sab82532
),
2105 printk("sab82532: can't alloc sab struct\n");
2109 memset(sab
, 0, sizeof(struct sab82532
));
2111 sab
->regs
= ioremap(regs
+ offset
, sizeof(union sab82532_async_regs
));
2112 sab
->irq
= edev
->irqs
[0];
2114 sab
->xmit_fifo_size
= 32;
2115 sab
->recv_fifo_size
= 32;
2117 writeb(SAB82532_IPC_IC_ACT_LOW
, &sab
->regs
->w
.ipc
);
2119 sab
->next
= sab82532_chain
;
2120 sab82532_chain
= sab
;
2122 offset
-= sizeof(union sab82532_async_regs
);
2128 static void __init
sab82532_kgdb_hook(int line
)
2130 prom_printf("sab82532: kgdb support is not implemented, yet\n");
2135 static inline void __init
show_serial_version(void)
2137 char *revision
= "$Revision: 1.54 $";
2140 version
= strchr(revision
, ' ');
2141 strcpy(serial_version
, ++version
);
2142 p
= strchr(serial_version
, ' ');
2144 printk("SAB82532 serial driver version %s\n", serial_version
);
2147 extern int su_num_ports
;
2150 * The serial driver boot-time initialization code!
2152 int __init
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 #ifdef CONFIG_DEVFS_FS
2171 serial_driver
.name
= "tts/%d";
2173 serial_driver
.name
= "ttyS";
2175 serial_driver
.major
= TTY_MAJOR
;
2176 serial_driver
.minor_start
= 64 + su_num_ports
;
2177 serial_driver
.num
= NR_PORTS
;
2178 serial_driver
.type
= TTY_DRIVER_TYPE_SERIAL
;
2179 serial_driver
.subtype
= SERIAL_TYPE_NORMAL
;
2180 serial_driver
.init_termios
= tty_std_termios
;
2181 serial_driver
.init_termios
.c_cflag
=
2182 B9600
| CS8
| CREAD
| HUPCL
| CLOCAL
;
2183 serial_driver
.flags
= TTY_DRIVER_REAL_RAW
;
2184 serial_driver
.refcount
= &sab82532_refcount
;
2185 serial_driver
.table
= sab82532_table
;
2186 serial_driver
.termios
= sab82532_termios
;
2187 serial_driver
.termios_locked
= sab82532_termios_locked
;
2189 serial_driver
.open
= sab82532_open
;
2190 serial_driver
.close
= sab82532_close
;
2191 serial_driver
.write
= sab82532_write
;
2192 serial_driver
.put_char
= sab82532_put_char
;
2193 serial_driver
.flush_chars
= sab82532_flush_chars
;
2194 serial_driver
.write_room
= sab82532_write_room
;
2195 serial_driver
.chars_in_buffer
= sab82532_chars_in_buffer
;
2196 serial_driver
.flush_buffer
= sab82532_flush_buffer
;
2197 serial_driver
.ioctl
= sab82532_ioctl
;
2198 serial_driver
.throttle
= sab82532_throttle
;
2199 serial_driver
.unthrottle
= sab82532_unthrottle
;
2200 serial_driver
.send_xchar
= sab82532_send_xchar
;
2201 serial_driver
.set_termios
= sab82532_set_termios
;
2202 serial_driver
.stop
= sab82532_stop
;
2203 serial_driver
.start
= sab82532_start
;
2204 serial_driver
.hangup
= sab82532_hangup
;
2205 serial_driver
.break_ctl
= sab82532_break
;
2206 serial_driver
.wait_until_sent
= sab82532_wait_until_sent
;
2207 serial_driver
.read_proc
= sab82532_read_proc
;
2210 * The callout device is just like normal device except for
2211 * major number and the subtype code.
2213 callout_driver
= serial_driver
;
2214 #ifdef CONFIG_DEVFS_FS
2215 callout_driver
.name
= "cua/%d";
2217 callout_driver
.name
= "cua";
2219 callout_driver
.major
= TTYAUX_MAJOR
;
2220 callout_driver
.subtype
= SERIAL_TYPE_CALLOUT
;
2221 callout_driver
.read_proc
= 0;
2222 callout_driver
.proc_entry
= 0;
2224 if (tty_register_driver(&serial_driver
))
2225 panic("Couldn't register serial driver\n");
2226 if (tty_register_driver(&callout_driver
))
2227 panic("Couldn't register callout driver\n");
2229 for (info
= sab82532_chain
, i
= 0; info
; info
= info
->next
, i
++) {
2230 info
->magic
= SERIAL_MAGIC
;
2232 info
->type
= readb(&info
->regs
->r
.vstr
) & 0x0f;
2233 writeb(~((1 << 1) | (1 << 2) | (1 << 4)), &info
->regs
->w
.pcr
);
2234 writeb(0xff, &info
->regs
->w
.pim
);
2235 if (info
->line
== 0) {
2236 info
->pvr_dsr_bit
= (1 << 0);
2237 info
->pvr_dtr_bit
= (1 << 1);
2239 info
->pvr_dsr_bit
= (1 << 3);
2240 info
->pvr_dtr_bit
= (1 << 2);
2242 writeb((1 << 1) | (1 << 2) | (1 << 4), &info
->regs
->w
.pvr
);
2243 writeb(readb(&info
->regs
->rw
.mode
) | SAB82532_MODE_FRTS
, &info
->regs
->rw
.mode
);
2244 writeb(readb(&info
->regs
->rw
.mode
) | SAB82532_MODE_RTS
, &info
->regs
->rw
.mode
);
2246 info
->custom_divisor
= 16;
2247 info
->close_delay
= 5*HZ
/10;
2248 info
->closing_wait
= 30*HZ
;
2249 info
->tec_timeout
= SAB82532_MAX_TEC_TIMEOUT
;
2250 info
->cec_timeout
= SAB82532_MAX_CEC_TIMEOUT
;
2253 info
->blocked_open
= 0;
2254 info
->tqueue
.routine
= do_softint
;
2255 info
->tqueue
.data
= info
;
2256 info
->tqueue_hangup
.routine
= do_serial_hangup
;
2257 info
->tqueue_hangup
.data
= info
;
2258 info
->callout_termios
= callout_driver
.init_termios
;
2259 info
->normal_termios
= serial_driver
.init_termios
;
2260 init_waitqueue_head(&info
->open_wait
);
2261 init_waitqueue_head(&info
->close_wait
);
2262 init_waitqueue_head(&info
->delta_msr_wait
);
2263 info
->icount
.cts
= info
->icount
.dsr
=
2264 info
->icount
.rng
= info
->icount
.dcd
= 0;
2265 info
->icount
.rx
= info
->icount
.tx
= 0;
2266 info
->icount
.frame
= info
->icount
.parity
= 0;
2267 info
->icount
.overrun
= info
->icount
.brk
= 0;
2269 if (!(info
->line
& 0x01)) {
2270 if (request_irq(info
->irq
, sab82532_interrupt
, SA_SHIRQ
,
2271 "serial(sab82532)", info
)) {
2272 printk("sab82532: can't get IRQ %x\n",
2274 panic("sab82532 initialization failed");
2279 "ttyS%02d at 0x%lx (irq = %s) is a SAB82532 %s\n",
2280 info
->line
+ su_num_ports
, (unsigned long)info
->regs
,
2281 __irq_itoa(info
->irq
), sab82532_version
[info
->type
]);
2284 #ifdef SERIAL_LOG_DEVICE
2285 dprint_init(SERIAL_LOG_DEVICE
);
2290 int __init
sab82532_probe(void)
2292 int node
, enode
, snode
;
2296 node
= prom_getchild(prom_root_node
);
2297 node
= prom_searchsiblings(node
, "pci");
2300 * Check for SUNW,sabre on Ultra 5/10/AXi.
2302 len
= prom_getproperty(node
, "model", model
, sizeof(model
));
2303 if ((len
> 0) && !strncmp(model
, "SUNW,sabre", len
)) {
2304 node
= prom_getchild(node
);
2305 node
= prom_searchsiblings(node
, "pci");
2309 * For each PCI bus...
2312 enode
= prom_getchild(node
);
2313 enode
= prom_searchsiblings(enode
, "ebus");
2316 * For each EBus on this PCI...
2319 snode
= prom_getchild(enode
);
2320 snode
= prom_searchsiblings(snode
, "se");
2324 enode
= prom_getsibling(enode
);
2325 enode
= prom_searchsiblings(enode
, "ebus");
2327 node
= prom_getsibling(node
);
2328 node
= prom_searchsiblings(node
, "pci");
2333 #ifdef CONFIG_SERIAL_CONSOLE
2334 sunserial_setinitfunc(sab82532_console_init
);
2337 sunserial_setinitfunc(sab82532_init
);
2338 rs_ops
.rs_kgdb_hook
= sab82532_kgdb_hook
;
2344 int init_module(void)
2346 if (get_sab82532(0))
2349 return sab82532_init();
2352 void cleanup_module(void)
2354 struct sab82532
*sab
;
2355 unsigned long flags
;
2358 /* printk("Unloading %s: version %s\n", serial_name, serial_version); */
2361 remove_bh(SERIAL_BH
);
2362 if ((e1
= tty_unregister_driver(&serial_driver
)))
2363 printk("SERIAL: failed to unregister serial driver (%d)\n",
2365 if ((e2
= tty_unregister_driver(&callout_driver
)))
2366 printk("SERIAL: failed to unregister callout driver (%d)\n",
2368 restore_flags(flags
);
2371 free_page((unsigned long) tmp_buf
);
2374 for (sab
= sab82532_chain
; sab
; sab
= sab
->next
) {
2375 if (!(sab
->line
& 0x01))
2376 free_irq(sab
->irq
, sab
);
2382 #ifdef CONFIG_SERIAL_CONSOLE
2384 batten_down_hatches(struct sab82532
*info
)
2386 unsigned char saved_rfc
, tmp
;
2388 if (!stop_a_enabled
)
2391 /* If we are doing kadb, we call the debugger
2392 * else we just drop into the boot monitor.
2393 * Note that we must flush the user windows
2394 * first before giving up control.
2397 flush_user_windows();
2400 * Set FIFO to single character mode.
2402 saved_rfc
= readb(&info
->regs
->r
.rfc
);
2403 tmp
= readb(&info
->regs
->rw
.rfc
);
2404 tmp
&= ~(SAB82532_RFC_RFDF
);
2405 writeb(tmp
, &info
->regs
->rw
.rfc
);
2406 sab82532_cec_wait(info
);
2407 writeb(SAB82532_CMDR_RRES
, &info
->regs
->w
.cmdr
);
2409 #ifndef __sparc_v9__
2410 if ((((unsigned long)linux_dbvec
) >= DEBUG_FIRSTVADDR
) &&
2411 (((unsigned long)linux_dbvec
) <= DEBUG_LASTVADDR
))
2412 sp_enter_debugger();
2418 * Reset FIFO to character + status mode.
2420 writeb(saved_rfc
, &info
->regs
->w
.rfc
);
2421 sab82532_cec_wait(info
);
2422 writeb(SAB82532_CMDR_RRES
, &info
->regs
->w
.cmdr
);
2425 static __inline__
void
2426 sab82532_console_putchar(struct sab82532
*info
, char c
)
2428 unsigned long flags
;
2430 save_flags(flags
); cli();
2431 sab82532_tec_wait(info
);
2432 writeb(c
, &info
->regs
->w
.tic
);
2433 restore_flags(flags
);
2437 sab82532_console_write(struct console
*con
, const char *s
, unsigned n
)
2439 struct sab82532
*info
;
2442 info
= sab82532_chain
;
2443 for (i
= con
->index
; i
; i
--) {
2449 for (i
= 0; i
< n
; i
++) {
2451 sab82532_console_putchar(info
, '\r');
2452 sab82532_console_putchar(info
, *s
++);
2454 sab82532_tec_wait(info
);
2458 sab82532_console_wait_key(struct console
*con
)
2460 sleep_on(&keypress_wait
);
2465 sab82532_console_device(struct console
*con
)
2467 return MKDEV(TTY_MAJOR
, 64 + con
->index
);
2471 sab82532_console_setup(struct console
*con
, char *options
)
2473 struct sab82532
*info
;
2478 unsigned long flags
;
2480 info
= sab82532_chain
;
2481 for (i
= con
->index
; i
; i
--) {
2486 info
->is_console
= 1;
2489 * Initialize the hardware
2491 sab82532_init_line(info
);
2494 * Finally, enable interrupts
2496 info
->interrupt_mask0
= SAB82532_IMR0_PERR
| SAB82532_IMR0_FERR
|
2497 SAB82532_IMR0_PLLA
| SAB82532_IMR0_CDSC
;
2498 writeb(info
->interrupt_mask0
, &info
->regs
->w
.imr0
);
2499 info
->interrupt_mask1
= SAB82532_IMR1_BRKT
| SAB82532_IMR1_ALLS
|
2500 SAB82532_IMR1_XOFF
| SAB82532_IMR1_TIN
|
2501 SAB82532_IMR1_CSC
| SAB82532_IMR1_XON
|
2503 writeb(info
->interrupt_mask1
, &info
->regs
->w
.imr1
);
2505 printk("Console: ttyS%d (SAB82532)\n", info
->line
);
2507 sunserial_console_termios(con
);
2510 /* Byte size and parity */
2511 switch (cflag
& CSIZE
) {
2512 case CS5
: dafo
= SAB82532_DAFO_CHL5
; bits
= 7; break;
2513 case CS6
: dafo
= SAB82532_DAFO_CHL6
; bits
= 8; break;
2514 case CS7
: dafo
= SAB82532_DAFO_CHL7
; bits
= 9; break;
2515 case CS8
: dafo
= SAB82532_DAFO_CHL8
; bits
= 10; break;
2516 /* Never happens, but GCC is too dumb to figure it out */
2517 default: dafo
= SAB82532_DAFO_CHL5
; bits
= 7; break;
2520 if (cflag
& CSTOPB
) {
2521 dafo
|= SAB82532_DAFO_STOP
;
2525 if (cflag
& PARENB
) {
2526 dafo
|= SAB82532_DAFO_PARE
;
2530 if (cflag
& PARODD
) {
2533 dafo
|= SAB82532_DAFO_PAR_MARK
;
2536 dafo
|= SAB82532_DAFO_PAR_ODD
;
2540 dafo
|= SAB82532_DAFO_PAR_SPACE
;
2543 dafo
|= SAB82532_DAFO_PAR_EVEN
;
2546 /* Determine EBRG values based on baud rate */
2550 if ((i
< 1) || ((i
+ 15) >= NR_EBRG_VALUES
))
2555 ebrg
= ebrg_table
[i
].n
;
2556 ebrg
|= (ebrg_table
[i
].m
<< 6);
2558 info
->baud
= ebrg_table
[i
].baud
;
2560 info
->timeout
= (info
->xmit_fifo_size
* HZ
* bits
) / info
->baud
;
2563 info
->timeout
+= HZ
/ 50; /* Add .02 seconds of slop */
2565 /* CTS flow control flags */
2566 if (cflag
& CRTSCTS
)
2567 info
->flags
|= ASYNC_CTS_FLOW
;
2569 info
->flags
&= ~(ASYNC_CTS_FLOW
);
2572 info
->flags
&= ~(ASYNC_CHECK_CD
);
2574 info
->flags
|= ASYNC_CHECK_CD
;
2576 save_flags(flags
); cli();
2577 sab82532_cec_wait(info
);
2578 sab82532_tec_wait(info
);
2579 writeb(dafo
, &info
->regs
->w
.dafo
);
2580 writeb(ebrg
& 0xff, &info
->regs
->w
.bgr
);
2581 writeb(readb(&info
->regs
->rw
.ccr2
) & ~(0xc0), &info
->regs
->rw
.ccr2
);
2582 writeb(readb(&info
->regs
->rw
.ccr2
) | ((ebrg
>> 2) & 0xc0), &info
->regs
->rw
.ccr2
);
2583 if (info
->flags
& ASYNC_CTS_FLOW
) {
2584 writeb(readb(&info
->regs
->rw
.mode
) & ~(SAB82532_MODE_RTS
), &info
->regs
->rw
.mode
);
2585 writeb(readb(&info
->regs
->rw
.mode
) | SAB82532_MODE_FRTS
, &info
->regs
->rw
.mode
);
2586 writeb(readb(&info
->regs
->rw
.mode
) & ~(SAB82532_MODE_FCTS
), &info
->regs
->rw
.mode
);
2588 writeb(readb(&info
->regs
->rw
.mode
) | SAB82532_MODE_RTS
, &info
->regs
->rw
.mode
);
2589 writeb(readb(&info
->regs
->rw
.mode
) & ~(SAB82532_MODE_FRTS
), &info
->regs
->rw
.mode
);
2590 writeb(readb(&info
->regs
->rw
.mode
) | SAB82532_MODE_FCTS
, &info
->regs
->rw
.mode
);
2592 writeb(~(info
->pvr_dtr_bit
), &info
->regs
->rw
.pvr
);
2593 writeb(readb(&info
->regs
->rw
.mode
) | SAB82532_MODE_RAC
, &info
->regs
->rw
.mode
);
2594 restore_flags(flags
);
2599 static struct console sab82532_console
= {
2601 write
: sab82532_console_write
,
2602 device
: sab82532_console_device
,
2603 wait_key
: sab82532_console_wait_key
,
2604 setup
: sab82532_console_setup
,
2605 flags
: CON_PRINTBUFFER
,
2609 int __init
sab82532_console_init(void)
2611 extern int con_is_present(void);
2612 extern int su_console_registered
;
2614 if (con_is_present() || su_console_registered
)
2617 if (!sab82532_chain
) {
2618 prom_printf("sab82532_console_setup: can't get SAB82532 chain");
2622 sab82532_console
.index
= serial_console
- 1;
2623 register_console(&sab82532_console
);
2627 #ifdef SERIAL_LOG_DEVICE
2629 static int serial_log_device
= 0;
2632 dprint_init(int tty
)
2634 serial_console
= tty
+ 1;
2635 sab82532_console
.index
= tty
;
2636 sab82532_console_setup(&sab82532_console
, "");
2638 serial_log_device
= tty
+ 1;
2642 dprintf(const char *fmt
, ...)
2644 static char buffer
[4096];
2648 if (!serial_log_device
)
2651 va_start(args
, fmt
);
2652 i
= vsprintf(buffer
, fmt
, args
);
2654 sab82532_console
.write(&sab82532_console
, buffer
, i
);
2657 #endif /* SERIAL_LOG_DEVICE */
2658 #endif /* CONFIG_SERIAL_CONSOLE */