1 /* $Id: su.c,v 1.43 2000/11/15 07:28:09 davem Exp $
2 * su.c: Small serial driver for keyboard/mouse interface on sparc32/PCI
4 * Copyright (C) 1997 Eddie C. Dost (ecd@skynet.be)
5 * Copyright (C) 1998-1999 Pete Zaitcev (zaitcev@metabyte.com)
7 * This is mainly a variation of drivers/char/serial.c,
8 * credits go to authors mentioned therein.
12 * Configuration section.
14 #define SERIAL_PARANOIA_CHECK
15 #define CONFIG_SERIAL_NOPAUSE_IO /* Unused on sparc */
16 #define SERIAL_DO_RESTART
18 /* Set of debugging defines */
20 #undef SERIAL_DEBUG_INTR
21 #undef SERIAL_DEBUG_OPEN
22 #undef SERIAL_DEBUG_FLOW
23 #undef SERIAL_DEBUG_RS_WAIT_UNTIL_SENT
24 #undef SERIAL_DEBUG_THROTTLE
26 #define RS_ISR_PASS_LIMIT 256
29 * 0x20 is sun4m thing, Dave Redman heritage.
30 * See arch/sparc/kernel/irq.c.
32 #define IRQ_4M(n) ((n)|0x20)
34 #if defined(MODULE) && defined(SERIAL_DEBUG_MCOUNT)
37 printk("(%s): [%x] refc=%d, serc=%d, ttyc=%d -> %s\n", \
38 kdevname(tty->device), (info->flags), serial_refcount, \
39 info->count,tty->count,s); \
46 * End of serial driver configuration section.
48 #include <linux/config.h>
49 #include <linux/module.h>
50 #include <linux/errno.h>
51 #include <linux/signal.h>
52 #include <linux/sched.h>
53 #include <linux/interrupt.h>
54 #include <linux/tty.h>
55 #include <linux/tty_flip.h>
56 #include <linux/serial.h>
57 #include <linux/serialP.h>
58 #include <linux/serial_reg.h>
59 #include <linux/string.h>
60 #include <linux/fcntl.h>
61 #include <linux/ptrace.h>
62 #include <linux/ioport.h>
64 #include <linux/malloc.h>
65 #include <linux/init.h>
66 #include <linux/bootmem.h>
67 #include <linux/delay.h>
68 #ifdef CONFIG_SERIAL_CONSOLE
69 #include <linux/console.h>
70 #include <linux/major.h>
72 #include <linux/sysrq.h>
74 #include <asm/system.h>
75 #include <asm/oplib.h>
79 #include <asm/uaccess.h>
80 #include <asm/bitops.h>
82 #include "sunserial.h"
86 /* We are on a NS PC87303 clocked with 24.0 MHz, which results
87 * in a UART clock of 1.8462 MHz.
89 #define BAUD_BASE (1846200 / 16)
91 #ifdef CONFIG_SERIAL_CONSOLE
92 extern int serial_console
;
93 static struct console sercons
;
94 int su_serial_console_init(void);
97 enum su_type
{ SU_PORT_NONE
, SU_PORT_MS
, SU_PORT_KBD
, SU_PORT_PORT
};
98 static char *su_typev
[] = { "???", "mouse", "kbd", "serial" };
100 #define SU_PROPSIZE 128
103 * serial.c saves memory when it allocates async_info upon first open.
104 * We have parts of state structure together because we do call startup
105 * for keyboard and mouse.
111 int type
; /* Hardware type: e.g. 16550 */
117 enum su_type port_type
; /* Hookup type: e.g. mouse */
125 unsigned short close_delay
;
126 unsigned short closing_wait
; /* time to wait before closing */
128 struct tty_struct
*tty
;
129 int read_status_mask
;
130 int ignore_status_mask
;
133 int x_char
; /* xon/xoff character */
134 int IER
; /* Interrupt Enable Register */
135 int MCR
; /* Modem control register */
137 int blocked_open
; /* # of blocked opens */
138 long session
; /* Session of opening process */
139 long pgrp
; /* pgrp of opening process */
140 unsigned char *xmit_buf
;
144 struct tq_struct tqueue
;
145 wait_queue_head_t open_wait
;
146 wait_queue_head_t close_wait
;
147 wait_queue_head_t delta_msr_wait
;
150 struct async_icount icount
;
151 struct termios normal_termios
, callout_termios
;
152 unsigned long last_active
; /* For async_struct, to be */
156 * Scan status structure.
157 * "prop" is a local variable but it eats stack to keep it in each
158 * stack frame of a recursive procedure.
160 struct su_probe_scan
{
161 int msnode
, kbnode
; /* PROM nodes for mouse and keyboard */
162 int msx
, kbx
; /* minors for mouse and keyboard */
163 int devices
; /* scan index */
164 char prop
[SU_PROPSIZE
];
167 static char *serial_name
= "PCIO serial driver";
168 static char serial_version
[16];
170 static DECLARE_TASK_QUEUE(tq_serial
);
172 static struct tty_driver serial_driver
, callout_driver
;
173 static int serial_refcount
;
175 /* number of characters left in xmit buffer before we ask for more */
176 #define WAKEUP_CHARS 256
178 static void autoconfig(struct su_struct
*info
);
179 static void change_speed(struct su_struct
*info
, struct termios
*old
);
180 static void su_wait_until_sent(struct tty_struct
*tty
, int timeout
);
183 * Here we define the default xmit fifo size used for each type of
186 static struct serial_uart_config uart_config
[] = {
191 { "16550A", 16, UART_CLEAR_FIFO
| UART_USE_FIFO
},
193 { "ST16650", 1, UART_CLEAR_FIFO
|UART_STARTECH
},
194 { "ST16650V2", 32, UART_CLEAR_FIFO
| UART_USE_FIFO
|
196 { "TI16750", 64, UART_CLEAR_FIFO
| UART_USE_FIFO
},
203 static struct su_struct su_table
[NR_PORTS
];
204 static struct tty_struct
*serial_table
[NR_PORTS
];
205 static struct termios
*serial_termios
[NR_PORTS
];
206 static struct termios
*serial_termios_locked
[NR_PORTS
];
209 #define MIN(a,b) ((a) < (b) ? (a) : (b))
213 * tmp_buf is used as a temporary buffer by serial_write. We need to
214 * lock it in case the copy_from_user blocks while swapping in a page,
215 * and some other program tries to do a serial write at the same time.
216 * Since the lock will only come under contention when the system is
217 * swapping and available memory is low, it makes sense to share one
218 * buffer across all the serial ports, since it significantly saves
219 * memory if large numbers of serial ports are open.
221 static unsigned char *tmp_buf
;
222 static DECLARE_MUTEX(tmp_buf_sem
);
224 static inline int serial_paranoia_check(struct su_struct
*info
,
225 kdev_t device
, const char *routine
)
227 #ifdef SERIAL_PARANOIA_CHECK
228 static const char *badmagic
=
229 "Warning: bad magic number for serial struct (%s) in %s\n";
230 static const char *badinfo
=
231 "Warning: null su_struct for (%s) in %s\n";
234 printk(badinfo
, kdevname(device
), routine
);
237 if (info
->magic
!= SERIAL_MAGIC
) {
238 printk(badmagic
, kdevname(device
), routine
);
246 unsigned int su_inb(struct su_struct
*info
, unsigned long offset
)
248 return inb(info
->port
+ offset
);
252 su_outb(struct su_struct
*info
, unsigned long offset
, int value
)
256 * MrCoffee has weird schematics: IRQ4 & P10(?) pins of SuperIO are
257 * connected with a gate then go to SlavIO. When IRQ4 goes tristated
258 * gate outputs a logical one. Since we use level triggered interrupts
259 * we have lockup and watchdog reset. We cannot mask IRQ because
260 * keyboard shares IRQ with us (Word has it as Bob Smelik's design).
261 * This problem is similar to what Alpha people suffer, see serial.c.
263 if (offset
== UART_MCR
) value
|= UART_MCR_OUT2
;
265 outb(value
, info
->port
+ offset
);
268 #define serial_in(info, off) su_inb(info, off)
269 #define serial_inp(info, off) su_inb(info, off)
270 #define serial_out(info, off, val) su_outb(info, off, val)
271 #define serial_outp(info, off, val) su_outb(info, off, val)
274 * ------------------------------------------------------------
275 * su_stop() and su_start()
277 * This routines are called before setting or resetting tty->stopped.
278 * They enable or disable transmitter interrupts, as necessary.
279 * ------------------------------------------------------------
281 static void su_stop(struct tty_struct
*tty
)
283 struct su_struct
*info
= (struct su_struct
*)tty
->driver_data
;
286 if (serial_paranoia_check(info
, tty
->device
, "su_stop"))
289 save_flags(flags
); cli();
290 if (info
->IER
& UART_IER_THRI
) {
291 info
->IER
&= ~UART_IER_THRI
;
292 serial_out(info
, UART_IER
, info
->IER
);
294 restore_flags(flags
);
297 static void su_start(struct tty_struct
*tty
)
299 struct su_struct
*info
= (struct su_struct
*)tty
->driver_data
;
302 if (serial_paranoia_check(info
, tty
->device
, "su_start"))
305 save_flags(flags
); cli();
306 if (info
->xmit_cnt
&& info
->xmit_buf
&& !(info
->IER
& UART_IER_THRI
)) {
307 info
->IER
|= UART_IER_THRI
;
308 serial_out(info
, UART_IER
, info
->IER
);
310 restore_flags(flags
);
314 * ----------------------------------------------------------------------
316 * Here starts the interrupt handling routines. All of the following
317 * subroutines are declared as inline and are folded into
318 * su_interrupt(). They were separated out for readability's sake.
320 * Note: rs_interrupt() is a "fast" interrupt, which means that it
321 * runs with interrupts turned off. People who may want to modify
322 * rs_interrupt() should try to keep the interrupt handler as fast as
323 * possible. After you are done making modifications, it is not a bad
326 * gcc -S -DKERNEL -Wall -Wstrict-prototypes -O6 -fomit-frame-pointer serial.c
328 * and look at the resulting assemble code in serial.s.
330 * - Ted Ts'o (tytso@mit.edu), 7-Mar-93
331 * -----------------------------------------------------------------------
335 * This routine is used by the interrupt handler to schedule
336 * processing in the software interrupt portion of the driver.
338 static __inline__
void
339 su_sched_event(struct su_struct
*info
, int event
)
341 info
->event
|= 1 << event
;
342 queue_task(&info
->tqueue
, &tq_serial
);
346 static __inline__
void
347 receive_kbd_ms_chars(struct su_struct
*info
, struct pt_regs
*regs
, int is_brk
)
349 unsigned char status
= 0;
353 ch
= serial_inp(info
, UART_RX
);
354 if (info
->port_type
== SU_PORT_KBD
) {
355 if(ch
== SUNKBD_RESET
) {
356 l1a_state
.kbd_id
= 1;
357 l1a_state
.l1_down
= 0;
358 } else if(l1a_state
.kbd_id
) {
359 l1a_state
.kbd_id
= 0;
360 } else if(ch
== SUNKBD_L1
) {
361 l1a_state
.l1_down
= 1;
362 } else if(ch
== (SUNKBD_L1
|SUNKBD_UP
)) {
363 l1a_state
.l1_down
= 0;
364 } else if(ch
== SUNKBD_A
&& l1a_state
.l1_down
) {
366 batten_down_hatches();
367 /* Continue execution... */
368 l1a_state
.l1_down
= 0;
369 l1a_state
.kbd_id
= 0;
372 sunkbd_inchar(ch
, regs
);
374 sun_mouse_inbyte(ch
, is_brk
);
377 status
= su_inb(info
, UART_LSR
);
378 } while (status
& UART_LSR_DR
);
381 static __inline__
void
382 receive_serial_chars(struct su_struct
*info
, int *status
, struct pt_regs
*regs
)
384 struct tty_struct
*tty
= info
->tty
;
386 int ignored
= 0, saw_console_brk
= 0;
387 struct async_icount
*icount
;
389 icount
= &info
->icount
;
391 ch
= serial_inp(info
, UART_RX
);
392 if (info
->is_console
&&
393 (ch
== 0 || (*status
&UART_LSR_BI
)))
395 if (tty
->flip
.count
>= TTY_FLIPBUF_SIZE
)
397 *tty
->flip
.char_buf_ptr
= ch
;
400 #ifdef SERIAL_DEBUG_INTR
401 printk("D%02x:%02x.", ch
, *status
);
403 *tty
->flip
.flag_buf_ptr
= 0;
404 if (*status
& (UART_LSR_BI
| UART_LSR_PE
|
405 UART_LSR_FE
| UART_LSR_OE
)) {
407 * For statistics only
409 if (*status
& UART_LSR_BI
) {
410 *status
&= ~(UART_LSR_FE
| UART_LSR_PE
);
412 } else if (*status
& UART_LSR_PE
)
414 else if (*status
& UART_LSR_FE
)
416 if (*status
& UART_LSR_OE
)
420 * Now check to see if character should be
421 * ignored, and mask off conditions which
424 if (*status
& info
->ignore_status_mask
) {
425 if (++ignored
> 100) {
426 #ifdef SERIAL_DEBUG_INTR
433 *status
&= info
->read_status_mask
;
435 if (*status
& (UART_LSR_BI
)) {
436 #ifdef SERIAL_DEBUG_INTR
437 printk("handling break....");
439 *tty
->flip
.flag_buf_ptr
= TTY_BREAK
;
440 if (info
->flags
& ASYNC_SAK
)
442 } else if (*status
& UART_LSR_PE
)
443 *tty
->flip
.flag_buf_ptr
= TTY_PARITY
;
444 else if (*status
& UART_LSR_FE
)
445 *tty
->flip
.flag_buf_ptr
= TTY_FRAME
;
446 if (*status
& UART_LSR_OE
) {
448 * Overrun is special, since it's
449 * reported immediately, and doesn't
450 * affect the current character
452 if (tty
->flip
.count
< TTY_FLIPBUF_SIZE
) {
454 tty
->flip
.flag_buf_ptr
++;
455 tty
->flip
.char_buf_ptr
++;
456 *tty
->flip
.flag_buf_ptr
= TTY_OVERRUN
;
460 tty
->flip
.flag_buf_ptr
++;
461 tty
->flip
.char_buf_ptr
++;
464 *status
= serial_inp(info
, UART_LSR
);
465 } while (*status
& UART_LSR_DR
);
466 #ifdef SERIAL_DEBUG_INTR
467 printk("E%02x.R%d", *status
, tty
->flip
.count
);
469 tty_flip_buffer_push(tty
);
470 if (saw_console_brk
!= 0)
471 batten_down_hatches();
474 static __inline__
void
475 transmit_chars(struct su_struct
*info
, int *intr_done
)
480 serial_outp(info
, UART_TX
, info
->x_char
);
487 if ((info
->xmit_cnt
<= 0) || info
->tty
->stopped
||
488 info
->tty
->hw_stopped
) {
489 info
->IER
&= ~UART_IER_THRI
;
490 serial_out(info
, UART_IER
, info
->IER
);
494 count
= info
->xmit_fifo_size
;
496 serial_out(info
, UART_TX
, info
->xmit_buf
[info
->xmit_tail
++]);
497 info
->xmit_tail
= info
->xmit_tail
& (SERIAL_XMIT_SIZE
-1);
499 if (--info
->xmit_cnt
<= 0)
501 } while (--count
> 0);
503 if (info
->xmit_cnt
< WAKEUP_CHARS
)
504 su_sched_event(info
, RS_EVENT_WRITE_WAKEUP
);
506 #ifdef SERIAL_DEBUG_INTR
507 printk("T%d...", info
->xmit_cnt
);
512 if (info
->xmit_cnt
<= 0) {
513 info
->IER
&= ~UART_IER_THRI
;
514 serial_out(info
, UART_IER
, info
->IER
);
518 static __inline__
void
519 check_modem_status(struct su_struct
*info
)
522 struct async_icount
*icount
;
524 status
= serial_in(info
, UART_MSR
);
526 if (status
& UART_MSR_ANY_DELTA
) {
527 icount
= &info
->icount
;
528 /* update input line counters */
529 if (status
& UART_MSR_TERI
)
531 if (status
& UART_MSR_DDSR
)
533 if (status
& UART_MSR_DDCD
) {
535 #ifdef CONFIG_HARD_PPS
536 if ((info
->flags
& ASYNC_HARDPPS_CD
) &&
537 (status
& UART_MSR_DCD
))
541 if (status
& UART_MSR_DCTS
)
543 wake_up_interruptible(&info
->delta_msr_wait
);
546 if ((info
->flags
& ASYNC_CHECK_CD
) && (status
& UART_MSR_DDCD
)) {
547 #if (defined(SERIAL_DEBUG_OPEN) || defined(SERIAL_DEBUG_INTR))
548 printk("ttys%d CD now %s...", info
->line
,
549 (status
& UART_MSR_DCD
) ? "on" : "off");
551 if (status
& UART_MSR_DCD
)
552 wake_up_interruptible(&info
->open_wait
);
553 else if (!((info
->flags
& ASYNC_CALLOUT_ACTIVE
) &&
554 (info
->flags
& ASYNC_CALLOUT_NOHUP
))) {
555 #ifdef SERIAL_DEBUG_OPEN
556 printk("doing serial hangup...");
559 tty_hangup(info
->tty
);
562 if (info
->flags
& ASYNC_CTS_FLOW
) {
563 if (info
->tty
->hw_stopped
) {
564 if (status
& UART_MSR_CTS
) {
565 #if (defined(SERIAL_DEBUG_INTR) || defined(SERIAL_DEBUG_FLOW))
566 printk("CTS tx start...");
568 info
->tty
->hw_stopped
= 0;
569 info
->IER
|= UART_IER_THRI
;
570 serial_out(info
, UART_IER
, info
->IER
);
571 su_sched_event(info
, RS_EVENT_WRITE_WAKEUP
);
575 if (!(status
& UART_MSR_CTS
)) {
576 #if (defined(SERIAL_DEBUG_INTR) || defined(SERIAL_DEBUG_FLOW))
577 printk("CTS tx stop...");
579 info
->tty
->hw_stopped
= 1;
580 info
->IER
&= ~UART_IER_THRI
;
581 serial_out(info
, UART_IER
, info
->IER
);
588 * This is the kbd/mouse serial driver's interrupt routine
591 su_kbd_ms_interrupt(int irq
, void *dev_id
, struct pt_regs
* regs
)
593 struct su_struct
*info
= (struct su_struct
*)dev_id
;
594 unsigned char status
;
596 #ifdef SERIAL_DEBUG_INTR
597 printk("su_kbd_ms_interrupt(%s)...", __irq_itoa(irq
));
602 if (serial_in(info
, UART_IIR
) & UART_IIR_NO_INT
)
605 status
= serial_inp(info
, UART_LSR
);
606 #ifdef SERIAL_DEBUG_INTR
607 printk("status = %x...", status
);
609 if ((status
& UART_LSR_DR
) || (status
& UART_LSR_BI
))
610 receive_kbd_ms_chars(info
, regs
,
611 (status
& UART_LSR_BI
) != 0);
613 #ifdef SERIAL_DEBUG_INTR
619 * This is the serial driver's generic interrupt routine
622 su_serial_interrupt(int irq
, void *dev_id
, struct pt_regs
* regs
)
625 struct su_struct
*info
;
626 int pass_counter
= 0;
628 #ifdef SERIAL_DEBUG_INTR
629 printk("su_serial_interrupt(%s)...", __irq_itoa(irq
));
631 info
= (struct su_struct
*)dev_id
;
632 if (!info
|| !info
->tty
) {
633 #ifdef SERIAL_DEBUG_INTR
640 status
= serial_inp(info
, UART_LSR
);
641 #ifdef SERIAL_DEBUG_INTR
642 printk("status = %x...", status
);
644 if (status
& UART_LSR_DR
)
645 receive_serial_chars(info
, &status
, regs
);
646 check_modem_status(info
);
647 if (status
& UART_LSR_THRE
)
648 transmit_chars(info
, 0);
650 if (pass_counter
++ > RS_ISR_PASS_LIMIT
) {
651 #ifdef SERIAL_DEBUG_INTR
652 printk("rs loop break");
654 break; /* Prevent infinite loops */
656 } while (!(serial_in(info
, UART_IIR
) & UART_IIR_NO_INT
));
658 info
->last_active
= jiffies
;
660 #ifdef SERIAL_DEBUG_INTR
666 * -------------------------------------------------------------------
667 * Here ends the serial interrupt routines.
668 * -------------------------------------------------------------------
672 * This routine is used to handle the "bottom half" processing for the
673 * serial driver, known also the "software interrupt" processing.
674 * This processing is done at the kernel interrupt level, after the
675 * su_interrupt() has returned, BUT WITH INTERRUPTS TURNED ON. This
676 * is where time-consuming activities which can not be done in the
677 * interrupt driver proper are done; the interrupt driver schedules
678 * them using su_sched_event(), and they get done here.
680 static void do_serial_bh(void)
682 run_task_queue(&tq_serial
);
685 static void do_softint(void *private_
)
687 struct su_struct
*info
= (struct su_struct
*) private_
;
688 struct tty_struct
*tty
;
694 if (test_and_clear_bit(RS_EVENT_WRITE_WAKEUP
, &info
->event
)) {
695 if ((tty
->flags
& (1 << TTY_DO_WRITE_WAKEUP
)) &&
696 tty
->ldisc
.write_wakeup
)
697 (tty
->ldisc
.write_wakeup
)(tty
);
698 wake_up_interruptible(&tty
->write_wait
);
703 * ---------------------------------------------------------------
704 * Low level utility subroutines for the serial driver: routines to
705 * figure out the appropriate timeout for an interrupt chain, routines
706 * to initialize and startup a serial port, and routines to shutdown a
707 * serial port. Useful stuff like that.
708 * ---------------------------------------------------------------
712 startup(struct su_struct
*info
)
720 page
= get_free_page(GFP_KERNEL
);
726 if (info
->flags
& ASYNC_INITIALIZED
) {
731 if (info
->port
== 0 || info
->type
== PORT_UNKNOWN
) {
732 set_bit(TTY_IO_ERROR
, &info
->tty
->flags
);
739 info
->xmit_buf
= (unsigned char *) page
;
743 #ifdef SERIAL_DEBUG_OPEN
744 printk("starting up ttys%d (irq %s)...", info
->line
,
745 __irq_itoa(info
->irq
));
748 if (uart_config
[info
->type
].flags
& UART_STARTECH
) {
750 serial_outp(info
, UART_LCR
, 0xBF);
751 serial_outp(info
, UART_EFR
, UART_EFR_ECB
);
752 serial_outp(info
, UART_IER
, 0);
753 serial_outp(info
, UART_EFR
, 0);
754 serial_outp(info
, UART_LCR
, 0);
757 if (info
->type
== PORT_16750
) {
759 serial_outp(info
, UART_IER
, 0);
763 * Clear the FIFO buffers and disable them
764 * (they will be reenabled in change_speed())
766 if (uart_config
[info
->type
].flags
& UART_CLEAR_FIFO
)
767 serial_outp(info
, UART_FCR
, (UART_FCR_CLEAR_RCVR
|
768 UART_FCR_CLEAR_XMIT
));
771 * At this point there's no way the LSR could still be 0xFF;
772 * if it is, then bail out, because there's likely no UART
775 if (serial_inp(info
, UART_LSR
) == 0xff) {
776 if (capable(CAP_SYS_ADMIN
)) {
778 set_bit(TTY_IO_ERROR
, &info
->tty
->flags
);
785 * Allocate the IRQ if necessary
787 if (info
->port_type
!= SU_PORT_PORT
) {
788 retval
= request_irq(info
->irq
, su_kbd_ms_interrupt
,
789 SA_SHIRQ
, info
->name
, info
);
791 retval
= request_irq(info
->irq
, su_serial_interrupt
,
792 SA_SHIRQ
, info
->name
, info
);
795 if (capable(CAP_SYS_ADMIN
)) {
797 set_bit(TTY_IO_ERROR
, &info
->tty
->flags
);
804 * Clear the interrupt registers.
806 (void) serial_inp(info
, UART_RX
);
807 (void) serial_inp(info
, UART_IIR
);
808 (void) serial_inp(info
, UART_MSR
);
811 * Now, initialize the UART
813 serial_outp(info
, UART_LCR
, UART_LCR_WLEN8
); /* reset DLAB */
816 if (info
->tty
&& info
->tty
->termios
->c_cflag
& CBAUD
)
817 info
->MCR
= UART_MCR_DTR
| UART_MCR_RTS
;
819 info
->MCR
|= UART_MCR_OUT2
;
820 serial_outp(info
, UART_MCR
, info
->MCR
);
823 * Finally, enable interrupts
825 info
->IER
= UART_IER_MSI
| UART_IER_RLSI
| UART_IER_RDI
;
826 serial_outp(info
, UART_IER
, info
->IER
); /* enable interrupts */
829 * And clear the interrupt registers again for luck.
831 (void)serial_inp(info
, UART_LSR
);
832 (void)serial_inp(info
, UART_RX
);
833 (void)serial_inp(info
, UART_IIR
);
834 (void)serial_inp(info
, UART_MSR
);
837 clear_bit(TTY_IO_ERROR
, &info
->tty
->flags
);
838 info
->xmit_cnt
= info
->xmit_head
= info
->xmit_tail
= 0;
841 * Set up the tty->alt_speed kludge
844 if ((info
->flags
& ASYNC_SPD_MASK
) == ASYNC_SPD_HI
)
845 info
->tty
->alt_speed
= 57600;
846 if ((info
->flags
& ASYNC_SPD_MASK
) == ASYNC_SPD_VHI
)
847 info
->tty
->alt_speed
= 115200;
848 if ((info
->flags
& ASYNC_SPD_MASK
) == ASYNC_SPD_SHI
)
849 info
->tty
->alt_speed
= 230400;
850 if ((info
->flags
& ASYNC_SPD_MASK
) == ASYNC_SPD_WARP
)
851 info
->tty
->alt_speed
= 460800;
855 * and set the speed of the serial port
857 change_speed(info
, 0);
859 info
->flags
|= ASYNC_INITIALIZED
;
860 restore_flags(flags
);
864 restore_flags(flags
);
869 * This routine will shutdown a serial port; interrupts are disabled, and
870 * DTR is dropped if the hangup on close termio flag is on.
873 shutdown(struct su_struct
*info
)
877 if (!(info
->flags
& ASYNC_INITIALIZED
))
880 save_flags(flags
); cli(); /* Disable interrupts */
883 * clear delta_msr_wait queue to avoid mem leaks: we may free the irq
884 * here so the queue might never be waken up
886 wake_up_interruptible(&info
->delta_msr_wait
);
889 * Free the IRQ, if necessary
891 free_irq(info
->irq
, info
);
893 if (info
->xmit_buf
) {
894 free_page((unsigned long) info
->xmit_buf
);
899 serial_outp(info
, UART_IER
, 0x00); /* disable all intrs */
900 info
->MCR
&= ~UART_MCR_OUT2
;
902 /* disable break condition */
903 serial_out(info
, UART_LCR
, serial_inp(info
, UART_LCR
) & ~UART_LCR_SBC
);
905 if (!info
->tty
|| (info
->tty
->termios
->c_cflag
& HUPCL
))
906 info
->MCR
&= ~(UART_MCR_DTR
|UART_MCR_RTS
);
907 serial_outp(info
, UART_MCR
, info
->MCR
);
910 serial_outp(info
, UART_FCR
, (UART_FCR_CLEAR_RCVR
|
911 UART_FCR_CLEAR_XMIT
));
912 (void)serial_in(info
, UART_RX
); /* read data port to reset things */
915 set_bit(TTY_IO_ERROR
, &info
->tty
->flags
);
917 if (uart_config
[info
->type
].flags
& UART_STARTECH
) {
918 /* Arrange to enter sleep mode */
919 serial_outp(info
, UART_LCR
, 0xBF);
920 serial_outp(info
, UART_EFR
, UART_EFR_ECB
);
921 serial_outp(info
, UART_IER
, UART_IERX_SLEEP
);
922 serial_outp(info
, UART_LCR
, 0);
924 if (info
->type
== PORT_16750
) {
925 /* Arrange to enter sleep mode */
926 serial_outp(info
, UART_IER
, UART_IERX_SLEEP
);
928 info
->flags
&= ~ASYNC_INITIALIZED
;
929 restore_flags(flags
);
932 static __inline__
int
933 su_get_baud_rate(struct su_struct
*info
)
935 static int baud_table
[] = {
936 0, 50, 75, 110, 134, 150, 200, 300, 600, 1200, 1800, 2400,
937 4800, 9600, 19200, 38400, 57600, 115200, 230400, 460800, 0
942 return tty_get_baud_rate(info
->tty
);
944 i
= info
->cflag
& CBAUD
;
948 info
->cflag
&= ~(CBAUDEX
);
952 return baud_table
[i
];
956 * This routine is called to set the UART divisor registers to match
957 * the specified baud rate for a serial port.
960 change_speed(struct su_struct
*info
,
961 struct termios
*old_termios
)
964 unsigned int cval
, fcr
= 0;
968 if (info
->port_type
== SU_PORT_PORT
) {
969 if (!info
->tty
|| !info
->tty
->termios
)
973 info
->cflag
= info
->tty
->termios
->c_cflag
;
976 /* byte size and parity */
977 switch (info
->cflag
& CSIZE
) {
978 case CS5
: cval
= 0x00; bits
= 7; break;
979 case CS6
: cval
= 0x01; bits
= 8; break;
980 case CS7
: cval
= 0x02; bits
= 9; break;
981 case CS8
: cval
= 0x03; bits
= 10; break;
982 /* Never happens, but GCC is too dumb to figure it out */
983 default: cval
= 0x00; bits
= 7; break;
985 if (info
->cflag
& CSTOPB
) {
989 if (info
->cflag
& PARENB
) {
990 cval
|= UART_LCR_PARITY
;
993 if (!(info
->cflag
& PARODD
))
994 cval
|= UART_LCR_EPAR
;
996 if (info
->cflag
& CMSPAR
)
997 cval
|= UART_LCR_SPAR
;
1000 /* Determine divisor based on baud rate */
1001 baud
= su_get_baud_rate(info
);
1002 if (baud
== 38400 &&
1003 ((info
->flags
& ASYNC_SPD_MASK
) == ASYNC_SPD_CUST
))
1004 quot
= info
->custom_divisor
;
1007 /* Special case since 134 is really 134.5 */
1008 quot
= (2 * info
->baud_base
/ 269);
1010 quot
= info
->baud_base
/ baud
;
1012 /* If the quotient is zero refuse the change */
1013 if (!quot
&& old_termios
) {
1014 info
->tty
->termios
->c_cflag
&= ~CBAUD
;
1015 info
->tty
->termios
->c_cflag
|= (old_termios
->c_cflag
& CBAUD
);
1016 baud
= tty_get_baud_rate(info
->tty
);
1019 if (baud
== 38400 &&
1020 ((info
->flags
& ASYNC_SPD_MASK
) == ASYNC_SPD_CUST
))
1021 quot
= info
->custom_divisor
;
1024 /* Special case since 134 is really 134.5 */
1025 quot
= (2*info
->baud_base
/ 269);
1027 quot
= info
->baud_base
/ baud
;
1030 /* As a last resort, if the quotient is zero, default to 9600 bps */
1032 quot
= info
->baud_base
/ 9600;
1033 info
->timeout
= ((info
->xmit_fifo_size
*HZ
*bits
*quot
) / info
->baud_base
);
1034 info
->timeout
+= HZ
/50; /* Add .02 seconds of slop */
1037 if (uart_config
[info
->type
].flags
& UART_USE_FIFO
) {
1038 if ((info
->baud_base
/ quot
) < 9600)
1039 fcr
= UART_FCR_ENABLE_FIFO
| UART_FCR_TRIGGER_1
;
1041 fcr
= UART_FCR_ENABLE_FIFO
| UART_FCR_TRIGGER_8
;
1043 if (info
->type
== PORT_16750
)
1044 fcr
|= UART_FCR7_64BYTE
;
1046 /* CTS flow control flag and modem status interrupts */
1047 info
->IER
&= ~UART_IER_MSI
;
1048 if (info
->flags
& ASYNC_HARDPPS_CD
)
1049 info
->IER
|= UART_IER_MSI
;
1050 if (info
->cflag
& CRTSCTS
) {
1051 info
->flags
|= ASYNC_CTS_FLOW
;
1052 info
->IER
|= UART_IER_MSI
;
1054 info
->flags
&= ~ASYNC_CTS_FLOW
;
1055 if (info
->cflag
& CLOCAL
)
1056 info
->flags
&= ~ASYNC_CHECK_CD
;
1058 info
->flags
|= ASYNC_CHECK_CD
;
1059 info
->IER
|= UART_IER_MSI
;
1061 serial_out(info
, UART_IER
, info
->IER
);
1064 * Set up parity check flag
1067 #define RELEVANT_IFLAG(iflag) (iflag & (IGNBRK|BRKINT|IGNPAR|PARMRK|INPCK))
1069 info
->read_status_mask
= UART_LSR_OE
| UART_LSR_THRE
|
1071 if (I_INPCK(info
->tty
))
1072 info
->read_status_mask
|= UART_LSR_FE
| UART_LSR_PE
;
1073 if (I_BRKINT(info
->tty
) || I_PARMRK(info
->tty
))
1074 info
->read_status_mask
|= UART_LSR_BI
;
1077 * Characters to ignore
1079 info
->ignore_status_mask
= 0;
1080 if (I_IGNPAR(info
->tty
))
1081 info
->ignore_status_mask
|= UART_LSR_PE
| UART_LSR_FE
;
1082 if (I_IGNBRK(info
->tty
)) {
1083 info
->ignore_status_mask
|= UART_LSR_BI
;
1085 * If we're ignore parity and break indicators, ignore
1086 * overruns too. (For real raw support).
1088 if (I_IGNPAR(info
->tty
))
1089 info
->ignore_status_mask
|= UART_LSR_OE
;
1092 * !!! ignore all characters if CREAD is not set
1094 if ((info
->cflag
& CREAD
) == 0)
1095 info
->ignore_status_mask
|= UART_LSR_DR
;
1098 save_flags(flags
); cli();
1099 if (uart_config
[info
->type
].flags
& UART_STARTECH
) {
1100 serial_outp(info
, UART_LCR
, 0xBF);
1101 serial_outp(info
, UART_EFR
,
1102 (info
->cflag
& CRTSCTS
) ? UART_EFR_CTS
: 0);
1104 serial_outp(info
, UART_LCR
, cval
| UART_LCR_DLAB
); /* set DLAB */
1105 serial_outp(info
, UART_DLL
, quot
& 0xff); /* LS of divisor */
1106 serial_outp(info
, UART_DLM
, quot
>> 8); /* MS of divisor */
1107 if (info
->type
== PORT_16750
)
1108 serial_outp(info
, UART_FCR
, fcr
); /* set fcr */
1109 serial_outp(info
, UART_LCR
, cval
); /* reset DLAB */
1110 if (info
->type
!= PORT_16750
)
1111 serial_outp(info
, UART_FCR
, fcr
); /* set fcr */
1112 restore_flags(flags
);
1117 su_put_char(struct tty_struct
*tty
, unsigned char ch
)
1119 struct su_struct
*info
= (struct su_struct
*)tty
->driver_data
;
1120 unsigned long flags
;
1122 if (serial_paranoia_check(info
, tty
->device
, "su_put_char"))
1125 if (!tty
|| !info
->xmit_buf
)
1128 save_flags(flags
); cli();
1129 if (info
->xmit_cnt
>= SERIAL_XMIT_SIZE
- 1) {
1130 restore_flags(flags
);
1134 info
->xmit_buf
[info
->xmit_head
++] = ch
;
1135 info
->xmit_head
&= SERIAL_XMIT_SIZE
-1;
1137 restore_flags(flags
);
1140 static void su_put_char_kbd(unsigned char c
)
1142 struct su_struct
*info
= su_table
;
1145 if (info
->port_type
!= SU_PORT_KBD
)
1147 if (info
->port_type
!= SU_PORT_KBD
)
1151 lsr
= serial_in(info
, UART_LSR
);
1152 } while (!(lsr
& UART_LSR_THRE
));
1154 /* Send the character out. */
1155 su_outb(info
, UART_TX
, c
);
1159 su_change_mouse_baud(int baud
)
1161 struct su_struct
*info
= su_table
;
1163 if (info
->port_type
!= SU_PORT_MS
)
1165 if (info
->port_type
!= SU_PORT_MS
)
1168 info
->cflag
&= ~(CBAUDEX
| CBAUD
);
1171 info
->cflag
|= B1200
;
1174 info
->cflag
|= B2400
;
1177 info
->cflag
|= B4800
;
1180 info
->cflag
|= B9600
;
1183 printk("su_change_mouse_baud: unknown baud rate %d, "
1184 "defaulting to 1200\n", baud
);
1185 info
->cflag
|= 1200;
1188 change_speed(info
, 0);
1192 su_flush_chars(struct tty_struct
*tty
)
1194 struct su_struct
*info
= (struct su_struct
*)tty
->driver_data
;
1195 unsigned long flags
;
1197 if (serial_paranoia_check(info
, tty
->device
, "su_flush_chars"))
1200 if (info
->xmit_cnt
<= 0 || tty
->stopped
|| tty
->hw_stopped
||
1204 save_flags(flags
); cli();
1205 info
->IER
|= UART_IER_THRI
;
1206 serial_out(info
, UART_IER
, info
->IER
);
1207 restore_flags(flags
);
1211 su_write(struct tty_struct
* tty
, int from_user
,
1212 const unsigned char *buf
, int count
)
1215 struct su_struct
*info
= (struct su_struct
*)tty
->driver_data
;
1216 unsigned long flags
;
1218 if (serial_paranoia_check(info
, tty
->device
, "su_write"))
1221 if (!tty
|| !info
->xmit_buf
|| !tmp_buf
)
1229 MIN(SERIAL_XMIT_SIZE
- info
->xmit_cnt
- 1,
1230 SERIAL_XMIT_SIZE
- info
->xmit_head
));
1234 c
-= copy_from_user(tmp_buf
, buf
, c
);
1241 c
= MIN(c
, MIN(SERIAL_XMIT_SIZE
- info
->xmit_cnt
- 1,
1242 SERIAL_XMIT_SIZE
- info
->xmit_head
));
1243 memcpy(info
->xmit_buf
+ info
->xmit_head
, tmp_buf
, c
);
1244 info
->xmit_head
= ((info
->xmit_head
+ c
) &
1245 (SERIAL_XMIT_SIZE
-1));
1246 info
->xmit_cnt
+= c
;
1247 restore_flags(flags
);
1257 MIN(SERIAL_XMIT_SIZE
- info
->xmit_cnt
- 1,
1258 SERIAL_XMIT_SIZE
- info
->xmit_head
));
1260 restore_flags(flags
);
1263 memcpy(info
->xmit_buf
+ info
->xmit_head
, buf
, c
);
1264 info
->xmit_head
= ((info
->xmit_head
+ c
) &
1265 (SERIAL_XMIT_SIZE
-1));
1266 info
->xmit_cnt
+= c
;
1267 restore_flags(flags
);
1273 if (info
->xmit_cnt
&& !tty
->stopped
&& !tty
->hw_stopped
&&
1274 !(info
->IER
& UART_IER_THRI
)) {
1275 info
->IER
|= UART_IER_THRI
;
1276 serial_out(info
, UART_IER
, info
->IER
);
1282 su_write_room(struct tty_struct
*tty
)
1284 struct su_struct
*info
= (struct su_struct
*)tty
->driver_data
;
1287 if (serial_paranoia_check(info
, tty
->device
, "su_write_room"))
1289 ret
= SERIAL_XMIT_SIZE
- info
->xmit_cnt
- 1;
1296 su_chars_in_buffer(struct tty_struct
*tty
)
1298 struct su_struct
*info
= (struct su_struct
*)tty
->driver_data
;
1300 if (serial_paranoia_check(info
, tty
->device
, "su_chars_in_buffer"))
1302 return info
->xmit_cnt
;
1306 su_flush_buffer(struct tty_struct
*tty
)
1308 struct su_struct
*info
= (struct su_struct
*)tty
->driver_data
;
1309 unsigned long flags
;
1311 if (serial_paranoia_check(info
, tty
->device
, "su_flush_buffer"))
1313 save_flags(flags
); cli();
1314 info
->xmit_cnt
= info
->xmit_head
= info
->xmit_tail
= 0;
1315 restore_flags(flags
);
1316 wake_up_interruptible(&tty
->write_wait
);
1317 if ((tty
->flags
& (1 << TTY_DO_WRITE_WAKEUP
)) &&
1318 tty
->ldisc
.write_wakeup
)
1319 (tty
->ldisc
.write_wakeup
)(tty
);
1323 * This function is used to send a high-priority XON/XOFF character to
1327 su_send_xchar(struct tty_struct
*tty
, char ch
)
1329 struct su_struct
*info
= (struct su_struct
*)tty
->driver_data
;
1331 if (serial_paranoia_check(info
, tty
->device
, "su_send_char"))
1334 if (!(info
->flags
& ASYNC_INITIALIZED
))
1339 /* Make sure transmit interrupts are on */
1340 info
->IER
|= UART_IER_THRI
;
1341 serial_out(info
, UART_IER
, info
->IER
);
1346 * ------------------------------------------------------------
1349 * This routine is called by the upper-layer tty layer to signal that
1350 * incoming characters should be throttled.
1351 * ------------------------------------------------------------
1354 su_throttle(struct tty_struct
* tty
)
1356 struct su_struct
*info
= (struct su_struct
*)tty
->driver_data
;
1357 unsigned long flags
;
1358 #ifdef SERIAL_DEBUG_THROTTLE
1361 printk("throttle %s: %d....\n", tty_name(tty
, buf
),
1362 tty
->ldisc
.chars_in_buffer(tty
));
1365 if (serial_paranoia_check(info
, tty
->device
, "su_throttle"))
1369 su_send_xchar(tty
, STOP_CHAR(tty
));
1371 if (tty
->termios
->c_cflag
& CRTSCTS
)
1372 info
->MCR
&= ~UART_MCR_RTS
;
1374 save_flags(flags
); cli();
1375 serial_out(info
, UART_MCR
, info
->MCR
);
1376 restore_flags(flags
);
1380 su_unthrottle(struct tty_struct
* tty
)
1382 struct su_struct
*info
= (struct su_struct
*)tty
->driver_data
;
1383 unsigned long flags
;
1384 #ifdef SERIAL_DEBUG_THROTTLE
1387 printk("unthrottle %s: %d....\n", tty_name(tty
, buf
),
1388 tty
->ldisc
.chars_in_buffer(tty
));
1391 if (serial_paranoia_check(info
, tty
->device
, "su_unthrottle"))
1398 su_send_xchar(tty
, START_CHAR(tty
));
1400 if (tty
->termios
->c_cflag
& CRTSCTS
)
1401 info
->MCR
|= UART_MCR_RTS
;
1402 save_flags(flags
); cli();
1403 serial_out(info
, UART_MCR
, info
->MCR
);
1404 restore_flags(flags
);
1408 * ------------------------------------------------------------
1409 * su_ioctl() and friends
1410 * ------------------------------------------------------------
1414 * get_lsr_info - get line status register info
1416 * Purpose: Let user call ioctl() to get info when the UART physically
1417 * is emptied. On bus types like RS485, the transmitter must
1418 * release the bus after transmitting. This must be done when
1419 * the transmit shift register is empty, not be done when the
1420 * transmit holding register is empty. This functionality
1421 * allows an RS485 driver to be written in user space.
1424 get_lsr_info(struct su_struct
* info
, unsigned int *value
)
1426 unsigned char status
;
1427 unsigned int result
;
1428 unsigned long flags
;
1430 save_flags(flags
); cli();
1431 status
= serial_in(info
, UART_LSR
);
1432 restore_flags(flags
);
1433 result
= ((status
& UART_LSR_TEMT
) ? TIOCSER_TEMT
: 0);
1434 return put_user(result
,value
);
1439 get_modem_info(struct su_struct
* info
, unsigned int *value
)
1441 unsigned char control
, status
;
1442 unsigned int result
;
1443 unsigned long flags
;
1445 control
= info
->MCR
;
1446 save_flags(flags
); cli();
1447 status
= serial_in(info
, UART_MSR
);
1448 restore_flags(flags
);
1449 result
= ((control
& UART_MCR_RTS
) ? TIOCM_RTS
: 0)
1450 | ((control
& UART_MCR_DTR
) ? TIOCM_DTR
: 0)
1452 | ((control
& UART_MCR_OUT1
) ? TIOCM_OUT1
: 0)
1453 | ((control
& UART_MCR_OUT2
) ? TIOCM_OUT2
: 0)
1455 | ((status
& UART_MSR_DCD
) ? TIOCM_CAR
: 0)
1456 | ((status
& UART_MSR_RI
) ? TIOCM_RNG
: 0)
1457 | ((status
& UART_MSR_DSR
) ? TIOCM_DSR
: 0)
1458 | ((status
& UART_MSR_CTS
) ? TIOCM_CTS
: 0);
1459 return put_user(result
,value
);
1463 set_modem_info(struct su_struct
* info
, unsigned int cmd
, unsigned int *value
)
1467 unsigned long flags
;
1469 error
= get_user(arg
, value
);
1474 if (arg
& TIOCM_RTS
)
1475 info
->MCR
|= UART_MCR_RTS
;
1476 if (arg
& TIOCM_DTR
)
1477 info
->MCR
|= UART_MCR_DTR
;
1479 if (arg
& TIOCM_OUT1
)
1480 info
->MCR
|= UART_MCR_OUT1
;
1481 if (arg
& TIOCM_OUT2
)
1482 info
->MCR
|= UART_MCR_OUT2
;
1486 if (arg
& TIOCM_RTS
)
1487 info
->MCR
&= ~UART_MCR_RTS
;
1488 if (arg
& TIOCM_DTR
)
1489 info
->MCR
&= ~UART_MCR_DTR
;
1491 if (arg
& TIOCM_OUT1
)
1492 info
->MCR
&= ~UART_MCR_OUT1
;
1493 if (arg
& TIOCM_OUT2
)
1494 info
->MCR
&= ~UART_MCR_OUT2
;
1498 info
->MCR
= ((info
->MCR
& ~(UART_MCR_RTS
|
1504 | ((arg
& TIOCM_RTS
) ? UART_MCR_RTS
: 0)
1506 | ((arg
& TIOCM_OUT1
) ? UART_MCR_OUT1
: 0)
1507 | ((arg
& TIOCM_OUT2
) ? UART_MCR_OUT2
: 0)
1509 | ((arg
& TIOCM_DTR
) ? UART_MCR_DTR
: 0));
1514 save_flags(flags
); cli();
1515 serial_out(info
, UART_MCR
, info
->MCR
);
1516 restore_flags(flags
);
1521 * su_break() --- routine which turns the break handling on or off
1524 su_break(struct tty_struct
*tty
, int break_state
)
1526 struct su_struct
* info
= (struct su_struct
*)tty
->driver_data
;
1527 unsigned long flags
;
1529 if (serial_paranoia_check(info
, tty
->device
, "su_break"))
1534 save_flags(flags
); cli();
1535 if (break_state
== -1)
1536 serial_out(info
, UART_LCR
,
1537 serial_inp(info
, UART_LCR
) | UART_LCR_SBC
);
1539 serial_out(info
, UART_LCR
,
1540 serial_inp(info
, UART_LCR
) & ~UART_LCR_SBC
);
1541 restore_flags(flags
);
1545 su_ioctl(struct tty_struct
*tty
, struct file
* file
,
1546 unsigned int cmd
, unsigned long arg
)
1549 struct su_struct
* info
= (struct su_struct
*)tty
->driver_data
;
1550 struct async_icount cprev
, cnow
; /* kernel counter temps */
1551 struct serial_icounter_struct
*p_cuser
; /* user space */
1553 if (serial_paranoia_check(info
, tty
->device
, "su_ioctl"))
1556 if ((cmd
!= TIOCGSERIAL
) && (cmd
!= TIOCSSERIAL
) &&
1557 (cmd
!= TIOCSERCONFIG
) && (cmd
!= TIOCSERGSTRUCT
) &&
1558 (cmd
!= TIOCMIWAIT
) && (cmd
!= TIOCGICOUNT
)) {
1559 if (tty
->flags
& (1 << TTY_IO_ERROR
))
1565 return get_modem_info(info
, (unsigned int *) arg
);
1569 return set_modem_info(info
, cmd
, (unsigned int *) arg
);
1571 case TIOCSERGETLSR
: /* Get line status register */
1572 return get_lsr_info(info
, (unsigned int *) arg
);
1575 case TIOCSERGSTRUCT
:
1576 if (copy_to_user((struct async_struct
*) arg
,
1577 info
, sizeof(struct async_struct
)))
1583 * Wait for any of the 4 modem inputs (DCD,RI,DSR,CTS) to change
1584 * - mask passed in arg for lines of interest
1585 * (use |'ed TIOCM_RNG/DSR/CD/CTS for masking)
1586 * Caller should use TIOCGICOUNT to see which one it was
1590 /* note the counters on entry */
1591 cprev
= info
->icount
;
1594 interruptible_sleep_on(&info
->delta_msr_wait
);
1595 /* see if a signal did it */
1596 if (signal_pending(current
))
1597 return -ERESTARTSYS
;
1599 cnow
= info
->icount
; /* atomic copy */
1601 if (cnow
.rng
== cprev
.rng
&& cnow
.dsr
== cprev
.dsr
&&
1602 cnow
.dcd
== cprev
.dcd
&& cnow
.cts
== cprev
.cts
)
1603 return -EIO
; /* no change => error */
1604 if ( ((arg
& TIOCM_RNG
) && (cnow
.rng
!= cprev
.rng
)) ||
1605 ((arg
& TIOCM_DSR
) && (cnow
.dsr
!= cprev
.dsr
)) ||
1606 ((arg
& TIOCM_CD
) && (cnow
.dcd
!= cprev
.dcd
)) ||
1607 ((arg
& TIOCM_CTS
) && (cnow
.cts
!= cprev
.cts
)) ) {
1615 * Get counter of input serial line interrupts (DCD,RI,DSR,CTS)
1616 * Return: write counters to the user passed counter struct
1617 * NB: both 1->0 and 0->1 transitions are counted except for
1618 * RI where only 0->1 is counted.
1622 cnow
= info
->icount
;
1624 p_cuser
= (struct serial_icounter_struct
*) arg
;
1625 error
= put_user(cnow
.cts
, &p_cuser
->cts
);
1626 if (error
) return error
;
1627 error
= put_user(cnow
.dsr
, &p_cuser
->dsr
);
1628 if (error
) return error
;
1629 error
= put_user(cnow
.rng
, &p_cuser
->rng
);
1630 if (error
) return error
;
1631 error
= put_user(cnow
.dcd
, &p_cuser
->dcd
);
1632 if (error
) return error
;
1636 return -ENOIOCTLCMD
;
1638 /* return 0; */ /* Trigger warnings if fall through by a chance. */
1642 su_set_termios(struct tty_struct
*tty
, struct termios
*old_termios
)
1644 struct su_struct
*info
= (struct su_struct
*)tty
->driver_data
;
1645 unsigned long flags
;
1647 if ( (tty
->termios
->c_cflag
== old_termios
->c_cflag
)
1648 && ( RELEVANT_IFLAG(tty
->termios
->c_iflag
)
1649 == RELEVANT_IFLAG(old_termios
->c_iflag
)))
1652 change_speed(info
, old_termios
);
1654 /* Handle transition to B0 status */
1655 if ((old_termios
->c_cflag
& CBAUD
) &&
1656 !(tty
->termios
->c_cflag
& CBAUD
)) {
1657 info
->MCR
&= ~(UART_MCR_DTR
|UART_MCR_RTS
);
1658 save_flags(flags
); cli();
1659 serial_out(info
, UART_MCR
, info
->MCR
);
1660 restore_flags(flags
);
1663 /* Handle transition away from B0 status */
1664 if (!(old_termios
->c_cflag
& CBAUD
) &&
1665 (tty
->termios
->c_cflag
& CBAUD
)) {
1666 info
->MCR
|= UART_MCR_DTR
;
1667 if (!(tty
->termios
->c_cflag
& CRTSCTS
) ||
1668 !test_bit(TTY_THROTTLED
, &tty
->flags
)) {
1669 info
->MCR
|= UART_MCR_RTS
;
1671 save_flags(flags
); cli();
1672 serial_out(info
, UART_MCR
, info
->MCR
);
1673 restore_flags(flags
);
1676 /* Handle turning off CRTSCTS */
1677 if ((old_termios
->c_cflag
& CRTSCTS
) &&
1678 !(tty
->termios
->c_cflag
& CRTSCTS
)) {
1679 tty
->hw_stopped
= 0;
1685 * No need to wake up processes in open wait, since they
1686 * sample the CLOCAL flag once, and don't recheck it.
1687 * XXX It's not clear whether the current behavior is correct
1688 * or not. Hence, this may change.....
1690 if (!(old_termios
->c_cflag
& CLOCAL
) &&
1691 (tty
->termios
->c_cflag
& CLOCAL
))
1692 wake_up_interruptible(&info
->open_wait
);
1697 * ------------------------------------------------------------
1700 * This routine is called when the serial port gets closed. First, we
1701 * wait for the last remaining data to be sent. Then, we unlink its
1702 * async structure from the interrupt chain if necessary, and we free
1703 * that IRQ if nothing is left in the chain.
1704 * ------------------------------------------------------------
1707 su_close(struct tty_struct
*tty
, struct file
* filp
)
1709 struct su_struct
*info
= (struct su_struct
*)tty
->driver_data
;
1710 unsigned long flags
;
1712 if (!info
|| serial_paranoia_check(info
, tty
->device
, "su_close"))
1715 save_flags(flags
); cli();
1717 if (tty_hung_up_p(filp
)) {
1718 DBG_CNT("before DEC-hung");
1720 restore_flags(flags
);
1724 #ifdef SERIAL_DEBUG_OPEN
1725 printk("su_close ttys%d, count = %d\n", info
->line
, info
->count
);
1727 if ((tty
->count
== 1) && (info
->count
!= 1)) {
1729 * Uh, oh. tty->count is 1, which means that the tty
1730 * structure will be freed. info->count should always
1731 * be one in these conditions. If it's greater than
1732 * one, we've got real problems, since it means the
1733 * serial port won't be shutdown.
1735 printk("su_close: bad serial port count; tty->count is 1, "
1736 "info->count is %d\n", info
->count
);
1739 if (--info
->count
< 0) {
1740 printk("su_close: bad serial port count for ttys%d: %d\n",
1741 info
->line
, info
->count
);
1745 DBG_CNT("before DEC-2");
1747 restore_flags(flags
);
1750 info
->flags
|= ASYNC_CLOSING
;
1752 * Save the termios structure, since this port may have
1753 * separate termios for callout and dialin.
1755 if (info
->flags
& ASYNC_NORMAL_ACTIVE
)
1756 info
->normal_termios
= *tty
->termios
;
1757 if (info
->flags
& ASYNC_CALLOUT_ACTIVE
)
1758 info
->callout_termios
= *tty
->termios
;
1760 * Now we wait for the transmit buffer to clear; and we notify
1761 * the line discipline to only process XON/XOFF characters.
1764 if (info
->closing_wait
!= ASYNC_CLOSING_WAIT_NONE
)
1765 tty_wait_until_sent(tty
, info
->closing_wait
);
1767 * At this point we stop accepting input. To do this, we
1768 * disable the receive line status interrupts, and tell the
1769 * interrupt driver to stop checking the data ready bit in the
1770 * line status register.
1772 info
->IER
&= ~UART_IER_RLSI
;
1773 info
->read_status_mask
&= ~UART_LSR_DR
;
1774 if (info
->flags
& ASYNC_INITIALIZED
) {
1775 serial_out(info
, UART_IER
, info
->IER
);
1777 * Before we drop DTR, make sure the UART transmitter
1778 * has completely drained; this is especially
1779 * important if there is a transmit FIFO!
1781 su_wait_until_sent(tty
, info
->timeout
);
1784 if (tty
->driver
.flush_buffer
)
1785 tty
->driver
.flush_buffer(tty
);
1786 if (tty
->ldisc
.flush_buffer
)
1787 tty
->ldisc
.flush_buffer(tty
);
1791 if (info
->blocked_open
) {
1792 if (info
->close_delay
) {
1793 current
->state
= TASK_INTERRUPTIBLE
;
1794 schedule_timeout(info
->close_delay
);
1796 wake_up_interruptible(&info
->open_wait
);
1798 info
->flags
&= ~(ASYNC_NORMAL_ACTIVE
|ASYNC_CALLOUT_ACTIVE
|
1800 wake_up_interruptible(&info
->close_wait
);
1802 restore_flags(flags
);
1806 * su_wait_until_sent() --- wait until the transmitter is empty
1809 su_wait_until_sent(struct tty_struct
*tty
, int timeout
)
1811 struct su_struct
* info
= (struct su_struct
*)tty
->driver_data
;
1812 unsigned long orig_jiffies
, char_time
;
1815 if (serial_paranoia_check(info
, tty
->device
, "su_wait_until_sent"))
1818 if (info
->type
== PORT_UNKNOWN
)
1821 if (info
->xmit_fifo_size
== 0)
1822 return; /* Just in case ... */
1824 orig_jiffies
= jiffies
;
1826 * Set the check interval to be 1/5 of the estimated time to
1827 * send a single character, and make it at least 1. The check
1828 * interval should also be less than the timeout.
1830 * Note: we have to use pretty tight timings here to satisfy
1833 char_time
= (info
->timeout
- HZ
/50) / info
->xmit_fifo_size
;
1834 char_time
= char_time
/ 5;
1838 char_time
= MIN(char_time
, timeout
);
1839 #ifdef SERIAL_DEBUG_RS_WAIT_UNTIL_SENT
1840 printk("In su_wait_until_sent(%d) check=%lu...", timeout
, char_time
);
1841 printk("jiff=%lu...", jiffies
);
1843 while (!((lsr
= serial_inp(info
, UART_LSR
)) & UART_LSR_TEMT
)) {
1844 #ifdef SERIAL_DEBUG_RS_WAIT_UNTIL_SENT
1845 printk("lsr = %d (jiff=%lu)...", lsr
, jiffies
);
1847 current
->state
= TASK_INTERRUPTIBLE
;
1848 schedule_timeout(char_time
);
1849 if (signal_pending(current
))
1851 if (timeout
&& time_after(jiffies
, orig_jiffies
+ timeout
))
1854 #ifdef SERIAL_DEBUG_RS_WAIT_UNTIL_SENT
1855 printk("lsr = %d (jiff=%lu)...done\n", lsr
, jiffies
);
1860 * su_hangup() --- called by tty_hangup() when a hangup is signaled.
1863 su_hangup(struct tty_struct
*tty
)
1865 struct su_struct
* info
= (struct su_struct
*)tty
->driver_data
;
1867 if (serial_paranoia_check(info
, tty
->device
, "su_hangup"))
1870 su_flush_buffer(tty
);
1874 info
->flags
&= ~(ASYNC_NORMAL_ACTIVE
|ASYNC_CALLOUT_ACTIVE
);
1876 wake_up_interruptible(&info
->open_wait
);
1880 * ------------------------------------------------------------
1881 * su_open() and friends
1882 * ------------------------------------------------------------
1885 block_til_ready(struct tty_struct
*tty
, struct file
* filp
,
1886 struct su_struct
*info
)
1888 DECLARE_WAITQUEUE(wait
, current
);
1890 int do_clocal
= 0, extra_count
= 0;
1891 unsigned long flags
;
1894 * If the device is in the middle of being closed, then block
1895 * until it's done, and then try again.
1897 if (tty_hung_up_p(filp
) ||
1898 (info
->flags
& ASYNC_CLOSING
)) {
1899 if (info
->flags
& ASYNC_CLOSING
)
1900 interruptible_sleep_on(&info
->close_wait
);
1901 #ifdef SERIAL_DO_RESTART
1902 return ((info
->flags
& ASYNC_HUP_NOTIFY
) ?
1903 -EAGAIN
: -ERESTARTSYS
);
1910 * If this is a callout device, then just make sure the normal
1911 * device isn't being used.
1913 if (tty
->driver
.subtype
== SERIAL_TYPE_CALLOUT
) {
1914 if (info
->flags
& ASYNC_NORMAL_ACTIVE
)
1916 if ((info
->flags
& ASYNC_CALLOUT_ACTIVE
) &&
1917 (info
->flags
& ASYNC_SESSION_LOCKOUT
) &&
1918 (info
->session
!= current
->session
))
1920 if ((info
->flags
& ASYNC_CALLOUT_ACTIVE
) &&
1921 (info
->flags
& ASYNC_PGRP_LOCKOUT
) &&
1922 (info
->pgrp
!= current
->pgrp
))
1924 info
->flags
|= ASYNC_CALLOUT_ACTIVE
;
1929 * If non-blocking mode is set, or the port is not enabled,
1930 * then make the check up front and then exit.
1932 if ((filp
->f_flags
& O_NONBLOCK
) ||
1933 (tty
->flags
& (1 << TTY_IO_ERROR
))) {
1934 if (info
->flags
& ASYNC_CALLOUT_ACTIVE
)
1936 info
->flags
|= ASYNC_NORMAL_ACTIVE
;
1940 if (info
->flags
& ASYNC_CALLOUT_ACTIVE
) {
1941 if (info
->normal_termios
.c_cflag
& CLOCAL
)
1944 if (tty
->termios
->c_cflag
& CLOCAL
)
1949 * Block waiting for the carrier detect and the line to become
1950 * free (i.e., not in use by the callout). While we are in
1951 * this loop, info->count is dropped by one, so that
1952 * su_close() knows when to free things. We restore it upon
1953 * exit, either normal or abnormal.
1956 add_wait_queue(&info
->open_wait
, &wait
);
1957 #ifdef SERIAL_DEBUG_OPEN
1958 printk("block_til_ready before block: ttys%d, count = %d\n",
1959 info
->line
, info
->count
);
1961 save_flags(flags
); cli();
1962 if (!tty_hung_up_p(filp
)) {
1966 restore_flags(flags
);
1967 info
->blocked_open
++;
1969 save_flags(flags
); cli();
1970 if (!(info
->flags
& ASYNC_CALLOUT_ACTIVE
) &&
1971 (tty
->termios
->c_cflag
& CBAUD
))
1972 serial_out(info
, UART_MCR
,
1973 serial_inp(info
, UART_MCR
) |
1974 (UART_MCR_DTR
| UART_MCR_RTS
));
1975 restore_flags(flags
);
1976 set_current_state(TASK_INTERRUPTIBLE
);
1977 if (tty_hung_up_p(filp
) ||
1978 !(info
->flags
& ASYNC_INITIALIZED
)) {
1979 #ifdef SERIAL_DO_RESTART
1980 if (info
->flags
& ASYNC_HUP_NOTIFY
)
1983 retval
= -ERESTARTSYS
;
1989 if (!(info
->flags
& ASYNC_CALLOUT_ACTIVE
) &&
1990 !(info
->flags
& ASYNC_CLOSING
) &&
1991 (do_clocal
|| (serial_in(info
, UART_MSR
) &
1994 if (signal_pending(current
)) {
1995 retval
= -ERESTARTSYS
;
1998 #ifdef SERIAL_DEBUG_OPEN
1999 printk("block_til_ready blocking: ttys%d, count = %d\n",
2000 info
->line
, info
->count
);
2004 current
->state
= TASK_RUNNING
;
2005 remove_wait_queue(&info
->open_wait
, &wait
);
2008 info
->blocked_open
--;
2009 #ifdef SERIAL_DEBUG_OPEN
2010 printk("block_til_ready after blocking: ttys%d, count = %d\n",
2011 info
->line
, info
->count
);
2015 info
->flags
|= ASYNC_NORMAL_ACTIVE
;
2020 * This routine is called whenever a serial port is opened. It
2021 * enables interrupts for a serial port, linking in its async structure into
2022 * the IRQ chain. It also performs the serial-specific
2023 * initialization for the tty structure.
2026 su_open(struct tty_struct
*tty
, struct file
* filp
)
2028 struct su_struct
*info
;
2032 line
= MINOR(tty
->device
) - tty
->driver
.minor_start
;
2033 if ((line
< 0) || (line
>= NR_PORTS
))
2035 info
= su_table
+ line
;
2037 tty
->driver_data
= info
;
2040 if (serial_paranoia_check(info
, tty
->device
, "su_open")) {
2045 #ifdef SERIAL_DEBUG_OPEN
2046 printk("su_open %s%d, count = %d\n", tty
->driver
.name
, info
->line
,
2049 info
->tty
->low_latency
= (info
->flags
& ASYNC_LOW_LATENCY
) ? 1 : 0;
2052 page
= get_free_page(GFP_KERNEL
);
2058 tmp_buf
= (unsigned char *) page
;
2062 * If the port is the middle of closing, bail out now
2064 if (tty_hung_up_p(filp
) ||
2065 (info
->flags
& ASYNC_CLOSING
)) {
2066 if (info
->flags
& ASYNC_CLOSING
)
2067 interruptible_sleep_on(&info
->close_wait
);
2068 #ifdef SERIAL_DO_RESTART
2069 return ((info
->flags
& ASYNC_HUP_NOTIFY
) ?
2070 -EAGAIN
: -ERESTARTSYS
);
2077 * Start up serial port
2079 retval
= startup(info
);
2084 retval
= block_til_ready(tty
, filp
, info
);
2086 #ifdef SERIAL_DEBUG_OPEN
2087 printk("su_open returning after block_til_ready with %d\n",
2093 if ((info
->count
== 1) &&
2094 (info
->flags
& ASYNC_SPLIT_TERMIOS
)) {
2095 if (tty
->driver
.subtype
== SERIAL_TYPE_NORMAL
)
2096 *tty
->termios
= info
->normal_termios
;
2098 *tty
->termios
= info
->callout_termios
;
2099 change_speed(info
, 0);
2101 #ifdef CONFIG_SERIAL_CONSOLE
2102 if (sercons
.cflag
&& sercons
.index
== line
) {
2103 tty
->termios
->c_cflag
= sercons
.cflag
;
2105 change_speed(info
, 0);
2108 info
->session
= current
->session
;
2109 info
->pgrp
= current
->pgrp
;
2111 #ifdef SERIAL_DEBUG_OPEN
2112 printk("su_open ttys%d successful...", info
->line
);
2118 * /proc fs routines....
2120 static __inline__
int
2121 line_info(char *buf
, struct su_struct
*info
)
2123 char stat_buf
[30], control
, status
;
2125 unsigned long flags
;
2127 if (info
->port
== 0 || info
->type
== PORT_UNKNOWN
)
2130 ret
= sprintf(buf
, "%u: uart:%s port:%lX irq:%s",
2131 info
->line
, uart_config
[info
->type
].name
,
2132 (unsigned long)info
->port
, __irq_itoa(info
->irq
));
2135 * Figure out the current RS-232 lines
2137 save_flags(flags
); cli();
2138 status
= serial_in(info
, UART_MSR
);
2139 control
= info
? info
->MCR
: serial_in(info
, UART_MCR
);
2140 restore_flags(flags
);
2144 if (control
& UART_MCR_RTS
)
2145 strcat(stat_buf
, "|RTS");
2146 if (status
& UART_MSR_CTS
)
2147 strcat(stat_buf
, "|CTS");
2148 if (control
& UART_MCR_DTR
)
2149 strcat(stat_buf
, "|DTR");
2150 if (status
& UART_MSR_DSR
)
2151 strcat(stat_buf
, "|DSR");
2152 if (status
& UART_MSR_DCD
)
2153 strcat(stat_buf
, "|CD");
2154 if (status
& UART_MSR_RI
)
2155 strcat(stat_buf
, "|RI");
2158 ret
+= sprintf(buf
+ret
, " baud:%u",
2159 info
->baud_base
/ info
->quot
);
2162 ret
+= sprintf(buf
+ret
, " tx:%u rx:%u",
2163 info
->icount
.tx
, info
->icount
.rx
);
2165 if (info
->icount
.frame
)
2166 ret
+= sprintf(buf
+ret
, " fe:%u", info
->icount
.frame
);
2168 if (info
->icount
.parity
)
2169 ret
+= sprintf(buf
+ret
, " pe:%u", info
->icount
.parity
);
2171 if (info
->icount
.brk
)
2172 ret
+= sprintf(buf
+ret
, " brk:%u", info
->icount
.brk
);
2174 if (info
->icount
.overrun
)
2175 ret
+= sprintf(buf
+ret
, " oe:%u", info
->icount
.overrun
);
2178 * Last thing is the RS-232 status lines
2180 ret
+= sprintf(buf
+ret
, " %s\n", stat_buf
+1);
2184 int su_read_proc(char *page
, char **start
, off_t off
, int count
,
2185 int *eof
, void *data
)
2190 len
+= sprintf(page
, "serinfo:1.0 driver:%s\n", serial_version
);
2191 for (i
= 0; i
< NR_PORTS
&& len
< 4000; i
++) {
2192 len
+= line_info(page
+ len
, &su_table
[i
]);
2193 if (len
+begin
> off
+count
)
2195 if (len
+begin
< off
) {
2202 if (off
>= len
+begin
)
2204 *start
= page
+ (off
-begin
);
2205 return ((count
< begin
+len
-off
) ? count
: begin
+len
-off
);
2209 * ---------------------------------------------------------------------
2210 * su_XXX_init() and friends
2212 * su_XXX_init() is called at boot-time to initialize the serial driver.
2213 * ---------------------------------------------------------------------
2217 * This routine prints out the appropriate serial driver version
2218 * number, and identifies which options were configured into this
2221 static __inline__
void __init
show_su_version(void)
2223 char *revision
= "$Revision: 1.43 $";
2226 version
= strchr(revision
, ' ');
2227 strcpy(serial_version
, ++version
);
2228 p
= strchr(serial_version
, ' ');
2230 printk(KERN_INFO
"%s version %s\n", serial_name
, serial_version
);
2234 * This routine is called by su_{serial|kbd_ms}_init() to initialize a specific
2235 * serial port. It determines what type of UART chip this serial port is
2236 * using: 8250, 16450, 16550, 16550A. The important question is
2237 * whether or not this UART is a 16550A, since this will determine
2238 * whether or not we can use its FIFO features.
2241 autoconfig(struct su_struct
*info
)
2243 unsigned char status1
, status2
, scratch
, scratch2
;
2244 struct linux_ebus_device
*dev
= 0;
2245 struct linux_ebus
*ebus
;
2246 #ifndef __sparc_v9__
2247 struct linux_prom_registers reg0
;
2249 unsigned long flags
;
2251 if (!info
->port_node
|| !info
->port_type
)
2255 * First we look for Ebus-bases su's
2257 for_each_ebus(ebus
) {
2258 for_each_ebusdev(dev
, ebus
) {
2259 if (dev
->prom_node
== info
->port_node
) {
2260 info
->port
= dev
->resource
[0].start
;
2261 info
->irq
= dev
->irqs
[0];
2269 * Not on Ebus, bailing.
2274 * Not on Ebus, must be OBIO.
2276 if (prom_getproperty(info
->port_node
, "reg",
2277 (char *)®0
, sizeof(reg0
)) == -1) {
2278 prom_printf("su: no \"reg\" property\n");
2281 prom_apply_obio_ranges(®0
, 1);
2282 if (reg0
.which_io
!= 0) { /* Just in case... */
2283 prom_printf("su: bus number nonzero: 0x%x:%x\n",
2284 reg0
.which_io
, reg0
.phys_addr
);
2287 if ((info
->port
= (unsigned long) ioremap(reg0
.phys_addr
,
2288 reg0
.reg_size
)) == 0) {
2289 prom_printf("su: cannot map\n");
2294 * There is no intr property on MrCoffee, so hardwire it.
2296 info
->irq
= IRQ_4M(13);
2301 #ifdef SERIAL_DEBUG_OPEN
2302 printk("Found 'su' at %016lx IRQ %s\n", info
->port
,
2303 __irq_itoa(info
->irq
));
2306 info
->magic
= SERIAL_MAGIC
;
2308 save_flags(flags
); cli();
2311 * Do a simple existence test first; if we fail this, there's
2312 * no point trying anything else.
2314 * 0x80 is used as a nonsense port to prevent against false
2315 * positives due to ISA bus float. The assumption is that
2316 * 0x80 is a non-existent port; which should be safe since
2317 * include/asm/io.h also makes this assumption.
2319 scratch
= serial_inp(info
, UART_IER
);
2320 serial_outp(info
, UART_IER
, 0);
2321 scratch2
= serial_inp(info
, UART_IER
);
2322 serial_outp(info
, UART_IER
, scratch
);
2324 restore_flags(flags
);
2325 return; /* We failed; there's nothing here */
2328 scratch
= serial_inp(info
, UART_MCR
);
2329 serial_outp(info
, UART_MCR
, UART_MCR_LOOP
| scratch
);
2330 serial_outp(info
, UART_MCR
, UART_MCR_LOOP
| 0x0A);
2331 status1
= serial_inp(info
, UART_MSR
) & 0xF0;
2332 serial_outp(info
, UART_MCR
, scratch
);
2333 if (status1
!= 0x90) {
2335 * This code fragment used to fail, now it fixed itself.
2336 * We keep the printout for a case.
2338 printk("su: loopback returned status 0x%02x\n", status1
);
2339 restore_flags(flags
);
2343 scratch2
= serial_in(info
, UART_LCR
);
2344 serial_outp(info
, UART_LCR
, 0xBF); /* set up for StarTech test */
2345 serial_outp(info
, UART_EFR
, 0); /* EFR is the same as FCR */
2346 serial_outp(info
, UART_LCR
, 0);
2347 serial_outp(info
, UART_FCR
, UART_FCR_ENABLE_FIFO
);
2348 scratch
= serial_in(info
, UART_IIR
) >> 6;
2351 info
->type
= PORT_16450
;
2354 info
->type
= PORT_UNKNOWN
;
2357 info
->type
= PORT_16550
;
2360 info
->type
= PORT_16550A
;
2363 if (info
->type
== PORT_16550A
) {
2364 /* Check for Startech UART's */
2365 serial_outp(info
, UART_LCR
, scratch2
| UART_LCR_DLAB
);
2366 if (serial_in(info
, UART_EFR
) == 0) {
2367 info
->type
= PORT_16650
;
2369 serial_outp(info
, UART_LCR
, 0xBF);
2370 if (serial_in(info
, UART_EFR
) == 0)
2371 info
->type
= PORT_16650V2
;
2374 if (info
->type
== PORT_16550A
) {
2375 /* Check for TI 16750 */
2376 serial_outp(info
, UART_LCR
, scratch2
| UART_LCR_DLAB
);
2377 serial_outp(info
, UART_FCR
,
2378 UART_FCR_ENABLE_FIFO
| UART_FCR7_64BYTE
);
2379 scratch
= serial_in(info
, UART_IIR
) >> 5;
2381 serial_outp(info
, UART_LCR
, 0);
2382 serial_outp(info
, UART_FCR
, UART_FCR_ENABLE_FIFO
);
2383 scratch
= serial_in(info
, UART_IIR
) >> 5;
2385 info
->type
= PORT_16750
;
2387 serial_outp(info
, UART_FCR
, UART_FCR_ENABLE_FIFO
);
2389 serial_outp(info
, UART_LCR
, scratch2
);
2390 if (info
->type
== PORT_16450
) {
2391 scratch
= serial_in(info
, UART_SCR
);
2392 serial_outp(info
, UART_SCR
, 0xa5);
2393 status1
= serial_in(info
, UART_SCR
);
2394 serial_outp(info
, UART_SCR
, 0x5a);
2395 status2
= serial_in(info
, UART_SCR
);
2396 serial_outp(info
, UART_SCR
, scratch
);
2398 if ((status1
!= 0xa5) || (status2
!= 0x5a))
2399 info
->type
= PORT_8250
;
2401 info
->xmit_fifo_size
= uart_config
[info
->type
].dfl_xmit_fifo_size
;
2403 if (info
->type
== PORT_UNKNOWN
) {
2404 restore_flags(flags
);
2408 sprintf(info
->name
, "su(%s)", su_typev
[info
->port_type
]);
2413 serial_outp(info
, UART_MCR
, 0x00);
2414 serial_outp(info
, UART_FCR
, (UART_FCR_CLEAR_RCVR
|UART_FCR_CLEAR_XMIT
));
2415 (void)serial_in(info
, UART_RX
);
2416 serial_outp(info
, UART_IER
, 0x00);
2418 restore_flags(flags
);
2421 /* This is used by the SAB driver to adjust where its minor
2422 * numbers start, we always are probed for first.
2424 int su_num_ports
= 0;
2425 EXPORT_SYMBOL(su_num_ports
);
2428 * The serial driver boot-time initialization code!
2430 int __init
su_serial_init(void)
2433 struct su_struct
*info
;
2435 init_bh(SERIAL_BH
, do_serial_bh
);
2438 /* Initialize the tty_driver structure */
2440 memset(&serial_driver
, 0, sizeof(struct tty_driver
));
2441 serial_driver
.magic
= TTY_DRIVER_MAGIC
;
2442 serial_driver
.driver_name
= "su";
2443 #ifdef CONFIG_DEVFS_FS
2444 serial_driver
.name
= "tts/%d";
2446 serial_driver
.name
= "ttyS";
2448 serial_driver
.major
= TTY_MAJOR
;
2449 serial_driver
.minor_start
= 64;
2450 serial_driver
.num
= NR_PORTS
;
2451 serial_driver
.type
= TTY_DRIVER_TYPE_SERIAL
;
2452 serial_driver
.subtype
= SERIAL_TYPE_NORMAL
;
2453 serial_driver
.init_termios
= tty_std_termios
;
2454 serial_driver
.init_termios
.c_cflag
=
2455 B9600
| CS8
| CREAD
| HUPCL
| CLOCAL
;
2456 serial_driver
.flags
= TTY_DRIVER_REAL_RAW
;
2457 serial_driver
.refcount
= &serial_refcount
;
2458 serial_driver
.table
= serial_table
;
2459 serial_driver
.termios
= serial_termios
;
2460 serial_driver
.termios_locked
= serial_termios_locked
;
2462 serial_driver
.open
= su_open
;
2463 serial_driver
.close
= su_close
;
2464 serial_driver
.write
= su_write
;
2465 serial_driver
.put_char
= su_put_char
;
2466 serial_driver
.flush_chars
= su_flush_chars
;
2467 serial_driver
.write_room
= su_write_room
;
2468 serial_driver
.chars_in_buffer
= su_chars_in_buffer
;
2469 serial_driver
.flush_buffer
= su_flush_buffer
;
2470 serial_driver
.ioctl
= su_ioctl
;
2471 serial_driver
.throttle
= su_throttle
;
2472 serial_driver
.unthrottle
= su_unthrottle
;
2473 serial_driver
.send_xchar
= su_send_xchar
;
2474 serial_driver
.set_termios
= su_set_termios
;
2475 serial_driver
.stop
= su_stop
;
2476 serial_driver
.start
= su_start
;
2477 serial_driver
.hangup
= su_hangup
;
2478 serial_driver
.break_ctl
= su_break
;
2479 serial_driver
.wait_until_sent
= su_wait_until_sent
;
2480 serial_driver
.read_proc
= su_read_proc
;
2483 * The callout device is just like normal device except for
2484 * major number and the subtype code.
2486 callout_driver
= serial_driver
;
2487 #ifdef CONFIG_DEVFS_FS
2488 callout_driver
.name
= "cua/%d";
2490 callout_driver
.name
= "cua";
2492 callout_driver
.major
= TTYAUX_MAJOR
;
2493 callout_driver
.subtype
= SERIAL_TYPE_CALLOUT
;
2494 callout_driver
.read_proc
= 0;
2495 callout_driver
.proc_entry
= 0;
2497 if (tty_register_driver(&serial_driver
))
2498 panic("Couldn't register regular su\n");
2499 if (tty_register_driver(&callout_driver
))
2500 panic("Couldn't register callout su\n");
2502 for (i
= 0, info
= su_table
; i
< NR_PORTS
; i
++, info
++) {
2504 info
->type
= PORT_UNKNOWN
;
2505 info
->baud_base
= BAUD_BASE
;
2506 /* info->flags = 0; */
2507 info
->custom_divisor
= 0;
2508 info
->close_delay
= 5*HZ
/10;
2509 info
->closing_wait
= 30*HZ
;
2510 info
->callout_termios
= callout_driver
.init_termios
;
2511 info
->normal_termios
= serial_driver
.init_termios
;
2512 info
->icount
.cts
= info
->icount
.dsr
=
2513 info
->icount
.rng
= info
->icount
.dcd
= 0;
2514 info
->icount
.rx
= info
->icount
.tx
= 0;
2515 info
->icount
.frame
= info
->icount
.parity
= 0;
2516 info
->icount
.overrun
= info
->icount
.brk
= 0;
2517 info
->tqueue
.routine
= do_softint
;
2518 info
->tqueue
.data
= info
;
2519 info
->cflag
= serial_driver
.init_termios
.c_cflag
;
2520 init_waitqueue_head(&info
->open_wait
);
2521 init_waitqueue_head(&info
->close_wait
);
2522 init_waitqueue_head(&info
->delta_msr_wait
);
2525 if (info
->type
== PORT_UNKNOWN
)
2528 printk(KERN_INFO
"%s at 0x%lx (tty %d irq %s) is a %s\n",
2529 info
->name
, (long)info
->port
, i
, __irq_itoa(info
->irq
),
2530 uart_config
[info
->type
].name
);
2533 for (i
= 0, info
= su_table
; i
< NR_PORTS
; i
++, info
++)
2534 if (info
->type
== PORT_UNKNOWN
)
2538 serial_driver
.num
= callout_driver
.num
= i
;
2543 int __init
su_kbd_ms_init(void)
2546 struct su_struct
*info
;
2550 for (i
= 0, info
= su_table
; i
< 2; i
++, info
++) {
2552 info
->type
= PORT_UNKNOWN
;
2553 info
->baud_base
= BAUD_BASE
;
2555 if (info
->port_type
== SU_PORT_KBD
)
2556 info
->cflag
= B1200
| CS8
| CLOCAL
| CREAD
;
2558 info
->cflag
= B4800
| CS8
| CLOCAL
| CREAD
;
2560 init_waitqueue_head(&info
->open_wait
);
2561 init_waitqueue_head(&info
->close_wait
);
2562 init_waitqueue_head(&info
->delta_msr_wait
);
2565 if (info
->type
== PORT_UNKNOWN
)
2568 printk(KERN_INFO
"%s at 0x%lx (irq = %s) is a %s\n",
2569 info
->name
, info
->port
, __irq_itoa(info
->irq
),
2570 uart_config
[info
->type
].name
);
2573 if (info
->port_type
== SU_PORT_KBD
)
2574 keyboard_zsinit(su_put_char_kbd
);
2582 * We got several platforms which present 'su' in different parts
2583 * of device tree. 'su' may be found under obio, ebus, isa and pci.
2584 * We walk over the tree and find them wherever PROM hides them.
2586 void __init
su_probe_any(struct su_probe_scan
*t
, int sunode
)
2588 struct su_struct
*info
;
2591 if (t
->devices
>= NR_PORTS
) return;
2593 for (; sunode
!= 0; sunode
= prom_getsibling(sunode
)) {
2594 len
= prom_getproperty(sunode
, "name", t
->prop
, SU_PROPSIZE
);
2595 if (len
<= 1) continue; /* Broken PROM node */
2596 if (strncmp(t
->prop
, "su", len
) == 0 ||
2597 strncmp(t
->prop
, "serial", len
) == 0 ||
2598 strncmp(t
->prop
, "su_pnp", len
) == 0) {
2599 info
= &su_table
[t
->devices
];
2600 if (t
->kbnode
!= 0 && sunode
== t
->kbnode
) {
2601 t
->kbx
= t
->devices
;
2602 info
->port_type
= SU_PORT_KBD
;
2603 } else if (t
->msnode
!= 0 && sunode
== t
->msnode
) {
2604 t
->msx
= t
->devices
;
2605 info
->port_type
= SU_PORT_MS
;
2609 * Do not attempt to use the truncated
2610 * keyboard/mouse ports as serial ports
2611 * on Ultras with PC keyboard attached.
2613 if (prom_getbool(sunode
, "mouse"))
2615 if (prom_getbool(sunode
, "keyboard"))
2618 info
->port_type
= SU_PORT_PORT
;
2620 info
->is_console
= 0;
2621 info
->port_node
= sunode
;
2624 su_probe_any(t
, prom_getchild(sunode
));
2629 int __init
su_probe(void)
2633 struct su_probe_scan scan
;
2636 * First, we scan the tree.
2645 * Get the nodes for keyboard and mouse from 'aliases'...
2647 node
= prom_getchild(prom_root_node
);
2648 node
= prom_searchsiblings(node
, "aliases");
2651 len
= prom_getproperty(node
, "keyboard", scan
.prop
,SU_PROPSIZE
);
2654 scan
.kbnode
= prom_finddevice(scan
.prop
);
2657 len
= prom_getproperty(node
, "mouse", scan
.prop
, SU_PROPSIZE
);
2660 scan
.msnode
= prom_finddevice(scan
.prop
);
2664 su_probe_any(&scan
, prom_getchild(prom_root_node
));
2667 * Second, we process the special case of keyboard and mouse.
2669 * Currently if we got keyboard and mouse hooked to "su" ports
2670 * we do not use any possible remaining "su" as a serial port.
2671 * Thus, we ignore values of .msx and .kbx, then compact ports.
2672 * Those who want to address this issue need to merge
2673 * su_serial_init() and su_ms_kbd_init().
2675 if (scan
.msx
!= -1 && scan
.kbx
!= -1) {
2676 su_table
[0].port_type
= SU_PORT_MS
;
2677 su_table
[0].is_console
= 0;
2678 su_table
[0].port_node
= scan
.msnode
;
2679 su_table
[1].port_type
= SU_PORT_KBD
;
2680 su_table
[1].is_console
= 0;
2681 su_table
[1].port_node
= scan
.kbnode
;
2683 sunserial_setinitfunc(su_kbd_ms_init
);
2684 rs_ops
.rs_change_mouse_baud
= su_change_mouse_baud
;
2685 sunkbd_setinitfunc(sun_kbd_init
);
2686 kbd_ops
.compute_shiftstate
= sun_compute_shiftstate
;
2687 kbd_ops
.setledstate
= sun_setledstate
;
2688 kbd_ops
.getledstate
= sun_getledstate
;
2689 kbd_ops
.setkeycode
= sun_setkeycode
;
2690 kbd_ops
.getkeycode
= sun_getkeycode
;
2692 sunkbd_install_keymaps(sun_key_maps
,
2693 sun_keymap_count
, sun_func_buf
, sun_func_table
,
2694 sun_funcbufsize
, sun_funcbufleft
,
2695 sun_accent_table
, sun_accent_table_size
);
2699 if (scan
.msx
!= -1 || scan
.kbx
!= -1) {
2700 printk("su_probe: cannot match keyboard and mouse, confused\n");
2704 if (scan
.devices
== 0)
2707 #ifdef CONFIG_SERIAL_CONSOLE
2709 * Console must be initiated after the generic initialization.
2710 * sunserial_setinitfunc inverts order, so call this before next one.
2712 sunserial_setinitfunc(su_serial_console_init
);
2714 sunserial_setinitfunc(su_serial_init
);
2719 * ------------------------------------------------------------
2720 * Serial console driver
2721 * ------------------------------------------------------------
2723 #ifdef CONFIG_SERIAL_CONSOLE
2725 #define BOTH_EMPTY (UART_LSR_TEMT | UART_LSR_THRE)
2728 * Wait for transmitter & holding register to empty
2730 static __inline__
void
2731 wait_for_xmitr(struct su_struct
*info
)
2734 unsigned int tmout
= 1000000;
2737 lsr
= su_inb(info
, UART_LSR
);
2740 } while ((lsr
& BOTH_EMPTY
) != BOTH_EMPTY
);
2744 * Print a string to the serial port trying not to disturb
2745 * any possible real use of the port...
2748 serial_console_write(struct console
*co
, const char *s
,
2751 struct su_struct
*info
;
2755 info
= su_table
+ co
->index
;
2757 * First save the IER then disable the interrupts
2759 ier
= su_inb(info
, UART_IER
);
2760 su_outb(info
, UART_IER
, 0x00);
2763 * Now, do each character
2765 for (i
= 0; i
< count
; i
++, s
++) {
2766 wait_for_xmitr(info
);
2769 * Send the character out.
2770 * If a LF, also do CR...
2772 su_outb(info
, UART_TX
, *s
);
2774 wait_for_xmitr(info
);
2775 su_outb(info
, UART_TX
, 13);
2780 * Finally, Wait for transmitter & holding register to empty
2781 * and restore the IER
2783 wait_for_xmitr(info
);
2784 su_outb(info
, UART_IER
, ier
);
2788 * Receive character from the serial port
2791 serial_console_wait_key(struct console
*co
)
2793 struct su_struct
*info
;
2798 info
= su_table
+ co
->index
;
2801 * First save the IER then disable the interrupts so
2802 * that the real driver for the port does not get the
2805 ier
= su_inb(info
, UART_IER
);
2806 su_outb(info
, UART_IER
, 0x00);
2809 lsr
= su_inb(info
, UART_LSR
);
2810 } while (!(lsr
& UART_LSR_DR
));
2811 c
= su_inb(info
, UART_RX
);
2814 * Restore the interrupts
2816 su_outb(info
, UART_IER
, ier
);
2822 serial_console_device(struct console
*c
)
2824 return MKDEV(TTY_MAJOR
, 64 + c
->index
);
2828 * Setup initial baud/bits/parity. We do two things here:
2829 * - construct a cflag setting for the first su_open()
2830 * - initialize the serial port
2831 * Return non-zero if we didn't find a serial port.
2833 static int __init
serial_console_setup(struct console
*co
, char *options
)
2835 struct su_struct
*info
;
2840 int cflag
= CREAD
| HUPCL
| CLOCAL
;
2845 baud
= simple_strtoul(options
, NULL
, 10);
2847 while(*s
>= '0' && *s
<= '9')
2849 if (*s
) parity
= *s
++;
2850 if (*s
) bits
= *s
- '0';
2854 * Now construct a cflag setting.
2903 * Divisor, bytesize and parity
2905 info
= su_table
+ co
->index
;
2906 quot
= BAUD_BASE
/ baud
;
2907 cval
= cflag
& (CSIZE
| CSTOPB
);
2908 #if defined(__powerpc__) || defined(__alpha__)
2910 #else /* !__powerpc__ && !__alpha__ */
2912 #endif /* !__powerpc__ && !__alpha__ */
2914 cval
|= UART_LCR_PARITY
;
2915 if (!(cflag
& PARODD
))
2916 cval
|= UART_LCR_EPAR
;
2919 * Disable UART interrupts, set DTR and RTS high
2922 su_outb(info
, UART_IER
, 0);
2923 su_outb(info
, UART_MCR
, UART_MCR_DTR
| UART_MCR_RTS
);
2924 su_outb(info
, UART_LCR
, cval
| UART_LCR_DLAB
); /* set DLAB */
2925 su_outb(info
, UART_DLL
, quot
& 0xff); /* LS of divisor */
2926 su_outb(info
, UART_DLM
, quot
>> 8); /* MS of divisor */
2927 su_outb(info
, UART_LCR
, cval
); /* reset DLAB */
2931 * If we read 0xff from the LSR, there is no UART here.
2933 if (su_inb(info
, UART_LSR
) == 0xff)
2936 info
->is_console
= 1;
2941 static struct console sercons
= {
2943 write
: serial_console_write
,
2944 device
: serial_console_device
,
2945 wait_key
: serial_console_wait_key
,
2946 setup
: serial_console_setup
,
2947 flags
: CON_PRINTBUFFER
,
2951 int su_console_registered
= 0;
2956 int __init
su_serial_console_init(void)
2958 extern int con_is_present(void);
2960 if (con_is_present())
2962 if (serial_console
== 0)
2964 if (su_table
[0].port
== 0 || su_table
[0].port_node
== 0)
2967 register_console(&sercons
);
2968 su_console_registered
= 1;
2972 #endif /* CONFIG_SERIAL_CONSOLE */