1 /* $Id: su.c,v 1.28 1999/09/01 08:09:32 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/serial_reg.h>
58 #include <linux/string.h>
59 #include <linux/fcntl.h>
60 #include <linux/ptrace.h>
61 #include <linux/ioport.h>
63 #include <linux/malloc.h>
64 #include <linux/init.h>
65 #include <linux/delay.h>
66 #ifdef CONFIG_SERIAL_CONSOLE
67 #include <linux/console.h>
68 #include <linux/major.h>
70 #include <linux/sysrq.h>
72 #include <asm/system.h>
73 #include <asm/oplib.h>
77 #include <asm/uaccess.h>
78 #include <asm/bitops.h>
80 #include "sunserial.h"
84 /* We are on a NS PC87303 clocked with 24.0 MHz, which results
85 * in a UART clock of 1.8462 MHz.
87 #define BAUD_BASE (1846200 / 16)
89 #ifdef CONFIG_SERIAL_CONSOLE
90 extern int serial_console
;
91 static struct console sercons
;
92 int su_serial_console_init(void);
95 enum su_type
{ SU_PORT_NONE
, SU_PORT_MS
, SU_PORT_KBD
, SU_PORT_PORT
};
96 static char *su_typev
[] = { "???", "mouse", "kbd", "serial" };
98 #define SU_PROPSIZE 128
101 * serial.c saves memory when it allocates async_info upon first open.
102 * We have parts of state structure together because we do call startup
103 * for keyboard and mouse.
109 int type
; /* Hardware type: e.g. 16550 */
115 enum su_type port_type
; /* Hookup type: e.g. mouse */
122 unsigned short close_delay
;
123 unsigned short closing_wait
; /* time to wait before closing */
125 struct tty_struct
*tty
;
126 int read_status_mask
;
127 int ignore_status_mask
;
130 int x_char
; /* xon/xoff character */
131 int IER
; /* Interrupt Enable Register */
132 int MCR
; /* Modem control register */
134 int blocked_open
; /* # of blocked opens */
135 long session
; /* Session of opening process */
136 long pgrp
; /* pgrp of opening process */
137 unsigned char *xmit_buf
;
141 struct tq_struct tqueue
;
142 wait_queue_head_t open_wait
;
143 wait_queue_head_t close_wait
;
144 wait_queue_head_t delta_msr_wait
;
147 struct async_icount icount
;
148 struct termios normal_termios
, callout_termios
;
149 unsigned long last_active
; /* For async_struct, to be */
153 * Scan status structure.
154 * "prop" is a local variable but it eats stack to keep it in each
155 * stack frame of a recursive procedure.
157 struct su_probe_scan
{
158 int msnode
, kbnode
; /* PROM nodes for mouse and keyboard */
159 int msx
, kbx
; /* minors for mouse and keyboard */
160 int devices
; /* scan index */
161 char prop
[SU_PROPSIZE
];
164 static char *serial_name
= "PCIO serial driver";
165 static char serial_version
[16];
167 static DECLARE_TASK_QUEUE(tq_serial
);
169 static struct tty_driver serial_driver
, callout_driver
;
170 static int serial_refcount
;
172 /* number of characters left in xmit buffer before we ask for more */
173 #define WAKEUP_CHARS 256
175 static void autoconfig(struct su_struct
*info
);
176 static void change_speed(struct su_struct
*info
, struct termios
*old
);
177 static void su_wait_until_sent(struct tty_struct
*tty
, int timeout
);
180 * Here we define the default xmit fifo size used for each type of
183 static struct serial_uart_config uart_config
[] = {
188 { "16550A", 16, UART_CLEAR_FIFO
| UART_USE_FIFO
},
190 { "ST16650", 1, UART_CLEAR_FIFO
|UART_STARTECH
},
191 { "ST16650V2", 32, UART_CLEAR_FIFO
| UART_USE_FIFO
|
193 { "TI16750", 64, UART_CLEAR_FIFO
| UART_USE_FIFO
},
200 static struct su_struct su_table
[NR_PORTS
];
201 static struct tty_struct
*serial_table
[NR_PORTS
];
202 static struct termios
*serial_termios
[NR_PORTS
];
203 static struct termios
*serial_termios_locked
[NR_PORTS
];
206 #define MIN(a,b) ((a) < (b) ? (a) : (b))
210 * tmp_buf is used as a temporary buffer by serial_write. We need to
211 * lock it in case the copy_from_user blocks while swapping in a page,
212 * and some other program tries to do a serial write at the same time.
213 * Since the lock will only come under contention when the system is
214 * swapping and available memory is low, it makes sense to share one
215 * buffer across all the serial ports, since it significantly saves
216 * memory if large numbers of serial ports are open.
218 static unsigned char *tmp_buf
;
219 static DECLARE_MUTEX(tmp_buf_sem
);
221 static inline int serial_paranoia_check(struct su_struct
*info
,
222 kdev_t device
, const char *routine
)
224 #ifdef SERIAL_PARANOIA_CHECK
225 static const char *badmagic
=
226 "Warning: bad magic number for serial struct (%s) in %s\n";
227 static const char *badinfo
=
228 "Warning: null su_struct for (%s) in %s\n";
231 printk(badinfo
, kdevname(device
), routine
);
234 if (info
->magic
!= SERIAL_MAGIC
) {
235 printk(badmagic
, kdevname(device
), routine
);
243 unsigned int su_inb(struct su_struct
*info
, unsigned long offset
)
245 return inb(info
->port
+ offset
);
249 su_outb(struct su_struct
*info
, unsigned long offset
, int value
)
253 * MrCoffee has weird schematics: IRQ4 & P10(?) pins of SuperIO are
254 * connected with a gate then go to SlavIO. When IRQ4 goes tristated
255 * gate outputs a logical one. Since we use level triggered interrupts
256 * we have lockup and watchdog reset. We cannot mask IRQ because
257 * keyboard shares IRQ with us (Word has it as Bob Smelik's design).
258 * This problem is similar to what Alpha people suffer, see serial.c.
260 if (offset
== UART_MCR
) value
|= UART_MCR_OUT2
;
262 outb(value
, info
->port
+ offset
);
265 #define serial_in(info, off) su_inb(info, off)
266 #define serial_inp(info, off) su_inb(info, off)
267 #define serial_out(info, off, val) su_outb(info, off, val)
268 #define serial_outp(info, off, val) su_outb(info, off, val)
271 * ------------------------------------------------------------
272 * su_stop() and su_start()
274 * This routines are called before setting or resetting tty->stopped.
275 * They enable or disable transmitter interrupts, as necessary.
276 * ------------------------------------------------------------
278 static void su_stop(struct tty_struct
*tty
)
280 struct su_struct
*info
= (struct su_struct
*)tty
->driver_data
;
283 if (serial_paranoia_check(info
, tty
->device
, "su_stop"))
286 save_flags(flags
); cli();
287 if (info
->IER
& UART_IER_THRI
) {
288 info
->IER
&= ~UART_IER_THRI
;
289 serial_out(info
, UART_IER
, info
->IER
);
291 restore_flags(flags
);
294 static void su_start(struct tty_struct
*tty
)
296 struct su_struct
*info
= (struct su_struct
*)tty
->driver_data
;
299 if (serial_paranoia_check(info
, tty
->device
, "su_start"))
302 save_flags(flags
); cli();
303 if (info
->xmit_cnt
&& info
->xmit_buf
&& !(info
->IER
& UART_IER_THRI
)) {
304 info
->IER
|= UART_IER_THRI
;
305 serial_out(info
, UART_IER
, info
->IER
);
307 restore_flags(flags
);
311 * ----------------------------------------------------------------------
313 * Here starts the interrupt handling routines. All of the following
314 * subroutines are declared as inline and are folded into
315 * su_interrupt(). They were separated out for readability's sake.
317 * Note: rs_interrupt() is a "fast" interrupt, which means that it
318 * runs with interrupts turned off. People who may want to modify
319 * rs_interrupt() should try to keep the interrupt handler as fast as
320 * possible. After you are done making modifications, it is not a bad
323 * gcc -S -DKERNEL -Wall -Wstrict-prototypes -O6 -fomit-frame-pointer serial.c
325 * and look at the resulting assemble code in serial.s.
327 * - Ted Ts'o (tytso@mit.edu), 7-Mar-93
328 * -----------------------------------------------------------------------
332 * This routine is used by the interrupt handler to schedule
333 * processing in the software interrupt portion of the driver.
335 static __inline__
void
336 su_sched_event(struct su_struct
*info
, int event
)
338 info
->event
|= 1 << event
;
339 queue_task(&info
->tqueue
, &tq_serial
);
343 static __inline__
void
344 receive_kbd_ms_chars(struct su_struct
*info
, struct pt_regs
*regs
)
346 unsigned char status
= 0;
350 ch
= serial_inp(info
, UART_RX
);
351 if (info
->port_type
== SU_PORT_KBD
) {
352 if(ch
== SUNKBD_RESET
) {
353 l1a_state
.kbd_id
= 1;
354 l1a_state
.l1_down
= 0;
355 } else if(l1a_state
.kbd_id
) {
356 l1a_state
.kbd_id
= 0;
357 } else if(ch
== SUNKBD_L1
) {
358 l1a_state
.l1_down
= 1;
359 } else if(ch
== (SUNKBD_L1
|SUNKBD_UP
)) {
360 l1a_state
.l1_down
= 0;
361 } else if(ch
== SUNKBD_A
&& l1a_state
.l1_down
) {
363 batten_down_hatches();
364 /* Continue execution... */
365 l1a_state
.l1_down
= 0;
366 l1a_state
.kbd_id
= 0;
369 sunkbd_inchar(ch
, regs
);
371 sun_mouse_inbyte(ch
);
374 status
= su_inb(info
, UART_LSR
);
375 } while (status
& UART_LSR_DR
);
378 static __inline__
void
379 receive_serial_chars(struct su_struct
*info
, int *status
, struct pt_regs
*regs
)
381 struct tty_struct
*tty
= info
->tty
;
384 struct async_icount
*icount
;
386 icount
= &info
->icount
;
388 ch
= serial_inp(info
, UART_RX
);
389 if (tty
->flip
.count
>= TTY_FLIPBUF_SIZE
)
391 *tty
->flip
.char_buf_ptr
= ch
;
394 #ifdef SERIAL_DEBUG_INTR
395 printk("D%02x:%02x.", ch
, *status
);
397 *tty
->flip
.flag_buf_ptr
= 0;
398 if (*status
& (UART_LSR_BI
| UART_LSR_PE
|
399 UART_LSR_FE
| UART_LSR_OE
)) {
401 * For statistics only
403 if (*status
& UART_LSR_BI
) {
404 *status
&= ~(UART_LSR_FE
| UART_LSR_PE
);
406 } else if (*status
& UART_LSR_PE
)
408 else if (*status
& UART_LSR_FE
)
410 if (*status
& UART_LSR_OE
)
414 * Now check to see if character should be
415 * ignored, and mask off conditions which
418 if (*status
& info
->ignore_status_mask
) {
419 if (++ignored
> 100) {
420 #ifdef SERIAL_DEBUG_INTR
427 *status
&= info
->read_status_mask
;
429 if (*status
& (UART_LSR_BI
)) {
430 #ifdef SERIAL_DEBUG_INTR
431 printk("handling break....");
433 *tty
->flip
.flag_buf_ptr
= TTY_BREAK
;
434 if (info
->flags
& ASYNC_SAK
)
436 } else if (*status
& UART_LSR_PE
)
437 *tty
->flip
.flag_buf_ptr
= TTY_PARITY
;
438 else if (*status
& UART_LSR_FE
)
439 *tty
->flip
.flag_buf_ptr
= TTY_FRAME
;
440 if (*status
& UART_LSR_OE
) {
442 * Overrun is special, since it's
443 * reported immediately, and doesn't
444 * affect the current character
446 if (tty
->flip
.count
< TTY_FLIPBUF_SIZE
) {
448 tty
->flip
.flag_buf_ptr
++;
449 tty
->flip
.char_buf_ptr
++;
450 *tty
->flip
.flag_buf_ptr
= TTY_OVERRUN
;
454 tty
->flip
.flag_buf_ptr
++;
455 tty
->flip
.char_buf_ptr
++;
458 *status
= serial_inp(info
, UART_LSR
);
459 } while (*status
& UART_LSR_DR
);
460 #ifdef SERIAL_DEBUG_INTR
461 printk("E%02x.R%d", *status
, tty
->flip
.count
);
463 tty_flip_buffer_push(tty
);
466 static __inline__
void
467 transmit_chars(struct su_struct
*info
, int *intr_done
)
472 serial_outp(info
, UART_TX
, info
->x_char
);
479 if ((info
->xmit_cnt
<= 0) || info
->tty
->stopped
||
480 info
->tty
->hw_stopped
) {
481 info
->IER
&= ~UART_IER_THRI
;
482 serial_out(info
, UART_IER
, info
->IER
);
486 count
= info
->xmit_fifo_size
;
488 serial_out(info
, UART_TX
, info
->xmit_buf
[info
->xmit_tail
++]);
489 info
->xmit_tail
= info
->xmit_tail
& (SERIAL_XMIT_SIZE
-1);
491 if (--info
->xmit_cnt
<= 0)
493 } while (--count
> 0);
495 if (info
->xmit_cnt
< WAKEUP_CHARS
)
496 su_sched_event(info
, RS_EVENT_WRITE_WAKEUP
);
498 #ifdef SERIAL_DEBUG_INTR
499 printk("T%d...", info
->xmit_cnt
);
504 if (info
->xmit_cnt
<= 0) {
505 info
->IER
&= ~UART_IER_THRI
;
506 serial_out(info
, UART_IER
, info
->IER
);
510 static __inline__
void
511 check_modem_status(struct su_struct
*info
)
514 struct async_icount
*icount
;
516 status
= serial_in(info
, UART_MSR
);
518 if (status
& UART_MSR_ANY_DELTA
) {
519 icount
= &info
->icount
;
520 /* update input line counters */
521 if (status
& UART_MSR_TERI
)
523 if (status
& UART_MSR_DDSR
)
525 if (status
& UART_MSR_DDCD
) {
527 #ifdef CONFIG_HARD_PPS
528 if ((info
->flags
& ASYNC_HARDPPS_CD
) &&
529 (status
& UART_MSR_DCD
))
533 if (status
& UART_MSR_DCTS
)
535 wake_up_interruptible(&info
->delta_msr_wait
);
538 if ((info
->flags
& ASYNC_CHECK_CD
) && (status
& UART_MSR_DDCD
)) {
539 #if (defined(SERIAL_DEBUG_OPEN) || defined(SERIAL_DEBUG_INTR))
540 printk("ttys%d CD now %s...", info
->line
,
541 (status
& UART_MSR_DCD
) ? "on" : "off");
543 if (status
& UART_MSR_DCD
)
544 wake_up_interruptible(&info
->open_wait
);
545 else if (!((info
->flags
& ASYNC_CALLOUT_ACTIVE
) &&
546 (info
->flags
& ASYNC_CALLOUT_NOHUP
))) {
547 #ifdef SERIAL_DEBUG_OPEN
548 printk("doing serial hangup...");
551 tty_hangup(info
->tty
);
554 if (info
->flags
& ASYNC_CTS_FLOW
) {
555 if (info
->tty
->hw_stopped
) {
556 if (status
& UART_MSR_CTS
) {
557 #if (defined(SERIAL_DEBUG_INTR) || defined(SERIAL_DEBUG_FLOW))
558 printk("CTS tx start...");
560 info
->tty
->hw_stopped
= 0;
561 info
->IER
|= UART_IER_THRI
;
562 serial_out(info
, UART_IER
, info
->IER
);
563 su_sched_event(info
, RS_EVENT_WRITE_WAKEUP
);
567 if (!(status
& UART_MSR_CTS
)) {
568 #if (defined(SERIAL_DEBUG_INTR) || defined(SERIAL_DEBUG_FLOW))
569 printk("CTS tx stop...");
571 info
->tty
->hw_stopped
= 1;
572 info
->IER
&= ~UART_IER_THRI
;
573 serial_out(info
, UART_IER
, info
->IER
);
580 * This is the kbd/mouse serial driver's interrupt routine
583 su_kbd_ms_interrupt(int irq
, void *dev_id
, struct pt_regs
* regs
)
585 struct su_struct
*info
= (struct su_struct
*)dev_id
;
586 unsigned char status
;
588 #ifdef SERIAL_DEBUG_INTR
589 printk("su_kbd_ms_interrupt(%s)...", __irq_itoa(irq
));
594 if (serial_in(info
, UART_IIR
) & UART_IIR_NO_INT
)
597 status
= serial_inp(info
, UART_LSR
);
598 #ifdef SERIAL_DEBUG_INTR
599 printk("status = %x...", status
);
601 if (status
& UART_LSR_DR
)
602 receive_kbd_ms_chars(info
, regs
);
604 #ifdef SERIAL_DEBUG_INTR
610 * This is the serial driver's generic interrupt routine
613 su_serial_interrupt(int irq
, void *dev_id
, struct pt_regs
* regs
)
616 struct su_struct
*info
;
617 int pass_counter
= 0;
619 #ifdef SERIAL_DEBUG_INTR
620 printk("su_serial_interrupt(%s)...", __irq_itoa(irq
));
622 info
= (struct su_struct
*)dev_id
;
623 if (!info
|| !info
->tty
) {
624 #ifdef SERIAL_DEBUG_INTR
631 status
= serial_inp(info
, UART_LSR
);
632 #ifdef SERIAL_DEBUG_INTR
633 printk("status = %x...", status
);
635 if (status
& UART_LSR_DR
)
636 receive_serial_chars(info
, &status
, regs
);
637 check_modem_status(info
);
638 if (status
& UART_LSR_THRE
)
639 transmit_chars(info
, 0);
641 if (pass_counter
++ > RS_ISR_PASS_LIMIT
) {
642 #ifdef SERIAL_DEBUG_INTR
643 printk("rs loop break");
645 break; /* Prevent infinite loops */
647 } while (!(serial_in(info
, UART_IIR
) & UART_IIR_NO_INT
));
649 info
->last_active
= jiffies
;
651 #ifdef SERIAL_DEBUG_INTR
657 * -------------------------------------------------------------------
658 * Here ends the serial interrupt routines.
659 * -------------------------------------------------------------------
663 * This routine is used to handle the "bottom half" processing for the
664 * serial driver, known also the "software interrupt" processing.
665 * This processing is done at the kernel interrupt level, after the
666 * su_interrupt() has returned, BUT WITH INTERRUPTS TURNED ON. This
667 * is where time-consuming activities which can not be done in the
668 * interrupt driver proper are done; the interrupt driver schedules
669 * them using su_sched_event(), and they get done here.
671 static void do_serial_bh(void)
673 run_task_queue(&tq_serial
);
676 static void do_softint(void *private_
)
678 struct su_struct
*info
= (struct su_struct
*) private_
;
679 struct tty_struct
*tty
;
685 if (test_and_clear_bit(RS_EVENT_WRITE_WAKEUP
, &info
->event
)) {
686 if ((tty
->flags
& (1 << TTY_DO_WRITE_WAKEUP
)) &&
687 tty
->ldisc
.write_wakeup
)
688 (tty
->ldisc
.write_wakeup
)(tty
);
689 wake_up_interruptible(&tty
->write_wait
);
694 * ---------------------------------------------------------------
695 * Low level utility subroutines for the serial driver: routines to
696 * figure out the appropriate timeout for an interrupt chain, routines
697 * to initialize and startup a serial port, and routines to shutdown a
698 * serial port. Useful stuff like that.
699 * ---------------------------------------------------------------
703 startup(struct su_struct
*info
)
711 page
= get_free_page(GFP_KERNEL
);
717 if (info
->flags
& ASYNC_INITIALIZED
) {
722 if (info
->port
== 0 || info
->type
== PORT_UNKNOWN
) {
723 set_bit(TTY_IO_ERROR
, &info
->tty
->flags
);
730 info
->xmit_buf
= (unsigned char *) page
;
734 #ifdef SERIAL_DEBUG_OPEN
735 printk("starting up ttys%d (irq %s)...", info
->line
,
736 __irq_itoa(info
->irq
));
739 if (uart_config
[info
->type
].flags
& UART_STARTECH
) {
741 serial_outp(info
, UART_LCR
, 0xBF);
742 serial_outp(info
, UART_EFR
, UART_EFR_ECB
);
743 serial_outp(info
, UART_IER
, 0);
744 serial_outp(info
, UART_EFR
, 0);
745 serial_outp(info
, UART_LCR
, 0);
748 if (info
->type
== PORT_16750
) {
750 serial_outp(info
, UART_IER
, 0);
754 * Clear the FIFO buffers and disable them
755 * (they will be reenabled in change_speed())
757 if (uart_config
[info
->type
].flags
& UART_CLEAR_FIFO
)
758 serial_outp(info
, UART_FCR
, (UART_FCR_CLEAR_RCVR
|
759 UART_FCR_CLEAR_XMIT
));
762 * At this point there's no way the LSR could still be 0xFF;
763 * if it is, then bail out, because there's likely no UART
766 if (serial_inp(info
, UART_LSR
) == 0xff) {
767 if (capable(CAP_SYS_ADMIN
)) {
769 set_bit(TTY_IO_ERROR
, &info
->tty
->flags
);
776 * Allocate the IRQ if necessary
778 if (info
->port_type
!= SU_PORT_PORT
) {
779 retval
= request_irq(info
->irq
, su_kbd_ms_interrupt
,
780 SA_SHIRQ
, info
->name
, info
);
782 retval
= request_irq(info
->irq
, su_serial_interrupt
,
783 SA_SHIRQ
, info
->name
, info
);
786 if (capable(CAP_SYS_ADMIN
)) {
788 set_bit(TTY_IO_ERROR
, &info
->tty
->flags
);
795 * Clear the interrupt registers.
797 (void) serial_inp(info
, UART_RX
);
798 (void) serial_inp(info
, UART_IIR
);
799 (void) serial_inp(info
, UART_MSR
);
802 * Now, initialize the UART
804 serial_outp(info
, UART_LCR
, UART_LCR_WLEN8
); /* reset DLAB */
807 if (info
->tty
&& info
->tty
->termios
->c_cflag
& CBAUD
)
808 info
->MCR
= UART_MCR_DTR
| UART_MCR_RTS
;
810 info
->MCR
|= UART_MCR_OUT2
;
811 serial_outp(info
, UART_MCR
, info
->MCR
);
814 * Finally, enable interrupts
816 info
->IER
= UART_IER_MSI
| UART_IER_RLSI
| UART_IER_RDI
;
817 serial_outp(info
, UART_IER
, info
->IER
); /* enable interrupts */
820 * And clear the interrupt registers again for luck.
822 (void)serial_inp(info
, UART_LSR
);
823 (void)serial_inp(info
, UART_RX
);
824 (void)serial_inp(info
, UART_IIR
);
825 (void)serial_inp(info
, UART_MSR
);
828 clear_bit(TTY_IO_ERROR
, &info
->tty
->flags
);
829 info
->xmit_cnt
= info
->xmit_head
= info
->xmit_tail
= 0;
832 * Set up the tty->alt_speed kludge
835 if ((info
->flags
& ASYNC_SPD_MASK
) == ASYNC_SPD_HI
)
836 info
->tty
->alt_speed
= 57600;
837 if ((info
->flags
& ASYNC_SPD_MASK
) == ASYNC_SPD_VHI
)
838 info
->tty
->alt_speed
= 115200;
839 if ((info
->flags
& ASYNC_SPD_MASK
) == ASYNC_SPD_SHI
)
840 info
->tty
->alt_speed
= 230400;
841 if ((info
->flags
& ASYNC_SPD_MASK
) == ASYNC_SPD_WARP
)
842 info
->tty
->alt_speed
= 460800;
846 * and set the speed of the serial port
848 change_speed(info
, 0);
850 info
->flags
|= ASYNC_INITIALIZED
;
851 restore_flags(flags
);
855 restore_flags(flags
);
860 * This routine will shutdown a serial port; interrupts are disabled, and
861 * DTR is dropped if the hangup on close termio flag is on.
864 shutdown(struct su_struct
*info
)
868 if (!(info
->flags
& ASYNC_INITIALIZED
))
871 save_flags(flags
); cli(); /* Disable interrupts */
874 * clear delta_msr_wait queue to avoid mem leaks: we may free the irq
875 * here so the queue might never be waken up
877 wake_up_interruptible(&info
->delta_msr_wait
);
880 * Free the IRQ, if necessary
882 free_irq(info
->irq
, info
);
884 if (info
->xmit_buf
) {
885 free_page((unsigned long) info
->xmit_buf
);
890 serial_outp(info
, UART_IER
, 0x00); /* disable all intrs */
891 info
->MCR
&= ~UART_MCR_OUT2
;
893 /* disable break condition */
894 serial_out(info
, UART_LCR
, serial_inp(info
, UART_LCR
) & ~UART_LCR_SBC
);
896 if (!info
->tty
|| (info
->tty
->termios
->c_cflag
& HUPCL
))
897 info
->MCR
&= ~(UART_MCR_DTR
|UART_MCR_RTS
);
898 serial_outp(info
, UART_MCR
, info
->MCR
);
901 serial_outp(info
, UART_FCR
, (UART_FCR_CLEAR_RCVR
|
902 UART_FCR_CLEAR_XMIT
));
903 (void)serial_in(info
, UART_RX
); /* read data port to reset things */
906 set_bit(TTY_IO_ERROR
, &info
->tty
->flags
);
908 if (uart_config
[info
->type
].flags
& UART_STARTECH
) {
909 /* Arrange to enter sleep mode */
910 serial_outp(info
, UART_LCR
, 0xBF);
911 serial_outp(info
, UART_EFR
, UART_EFR_ECB
);
912 serial_outp(info
, UART_IER
, UART_IERX_SLEEP
);
913 serial_outp(info
, UART_LCR
, 0);
915 if (info
->type
== PORT_16750
) {
916 /* Arrange to enter sleep mode */
917 serial_outp(info
, UART_IER
, UART_IERX_SLEEP
);
919 info
->flags
&= ~ASYNC_INITIALIZED
;
920 restore_flags(flags
);
923 static __inline__
int
924 su_get_baud_rate(struct su_struct
*info
)
926 static int baud_table
[] = {
927 0, 50, 75, 110, 134, 150, 200, 300, 600, 1200, 1800, 2400,
928 4800, 9600, 19200, 38400, 57600, 115200, 230400, 460800, 0
933 return tty_get_baud_rate(info
->tty
);
935 i
= info
->cflag
& CBAUD
;
939 info
->cflag
&= ~(CBAUDEX
);
943 return baud_table
[i
];
947 * This routine is called to set the UART divisor registers to match
948 * the specified baud rate for a serial port.
951 change_speed(struct su_struct
*info
,
952 struct termios
*old_termios
)
955 unsigned int cval
, fcr
= 0;
959 if (info
->port_type
== SU_PORT_PORT
) {
960 if (!info
->tty
|| !info
->tty
->termios
)
964 info
->cflag
= info
->tty
->termios
->c_cflag
;
967 /* byte size and parity */
968 switch (info
->cflag
& CSIZE
) {
969 case CS5
: cval
= 0x00; bits
= 7; break;
970 case CS6
: cval
= 0x01; bits
= 8; break;
971 case CS7
: cval
= 0x02; bits
= 9; break;
972 case CS8
: cval
= 0x03; bits
= 10; break;
973 /* Never happens, but GCC is too dumb to figure it out */
974 default: cval
= 0x00; bits
= 7; break;
976 if (info
->cflag
& CSTOPB
) {
980 if (info
->cflag
& PARENB
) {
981 cval
|= UART_LCR_PARITY
;
984 if (!(info
->cflag
& PARODD
))
985 cval
|= UART_LCR_EPAR
;
987 if (info
->cflag
& CMSPAR
)
988 cval
|= UART_LCR_SPAR
;
991 /* Determine divisor based on baud rate */
992 baud
= su_get_baud_rate(info
);
994 ((info
->flags
& ASYNC_SPD_MASK
) == ASYNC_SPD_CUST
))
995 quot
= info
->custom_divisor
;
998 /* Special case since 134 is really 134.5 */
999 quot
= (2 * info
->baud_base
/ 269);
1001 quot
= info
->baud_base
/ baud
;
1003 /* If the quotient is zero refuse the change */
1004 if (!quot
&& old_termios
) {
1005 info
->tty
->termios
->c_cflag
&= ~CBAUD
;
1006 info
->tty
->termios
->c_cflag
|= (old_termios
->c_cflag
& CBAUD
);
1007 baud
= tty_get_baud_rate(info
->tty
);
1010 if (baud
== 38400 &&
1011 ((info
->flags
& ASYNC_SPD_MASK
) == ASYNC_SPD_CUST
))
1012 quot
= info
->custom_divisor
;
1015 /* Special case since 134 is really 134.5 */
1016 quot
= (2*info
->baud_base
/ 269);
1018 quot
= info
->baud_base
/ baud
;
1021 /* As a last resort, if the quotient is zero, default to 9600 bps */
1023 quot
= info
->baud_base
/ 9600;
1024 info
->timeout
= ((info
->xmit_fifo_size
*HZ
*bits
*quot
) / info
->baud_base
);
1025 info
->timeout
+= HZ
/50; /* Add .02 seconds of slop */
1028 if (uart_config
[info
->type
].flags
& UART_USE_FIFO
) {
1029 if ((info
->baud_base
/ quot
) < 9600)
1030 fcr
= UART_FCR_ENABLE_FIFO
| UART_FCR_TRIGGER_1
;
1032 fcr
= UART_FCR_ENABLE_FIFO
| UART_FCR_TRIGGER_8
;
1034 if (info
->type
== PORT_16750
)
1035 fcr
|= UART_FCR7_64BYTE
;
1037 /* CTS flow control flag and modem status interrupts */
1038 info
->IER
&= ~UART_IER_MSI
;
1039 if (info
->flags
& ASYNC_HARDPPS_CD
)
1040 info
->IER
|= UART_IER_MSI
;
1041 if (info
->cflag
& CRTSCTS
) {
1042 info
->flags
|= ASYNC_CTS_FLOW
;
1043 info
->IER
|= UART_IER_MSI
;
1045 info
->flags
&= ~ASYNC_CTS_FLOW
;
1046 if (info
->cflag
& CLOCAL
)
1047 info
->flags
&= ~ASYNC_CHECK_CD
;
1049 info
->flags
|= ASYNC_CHECK_CD
;
1050 info
->IER
|= UART_IER_MSI
;
1052 serial_out(info
, UART_IER
, info
->IER
);
1055 * Set up parity check flag
1058 #define RELEVANT_IFLAG(iflag) (iflag & (IGNBRK|BRKINT|IGNPAR|PARMRK|INPCK))
1060 info
->read_status_mask
= UART_LSR_OE
| UART_LSR_THRE
|
1062 if (I_INPCK(info
->tty
))
1063 info
->read_status_mask
|= UART_LSR_FE
| UART_LSR_PE
;
1064 if (I_BRKINT(info
->tty
) || I_PARMRK(info
->tty
))
1065 info
->read_status_mask
|= UART_LSR_BI
;
1068 * Characters to ignore
1070 info
->ignore_status_mask
= 0;
1071 if (I_IGNPAR(info
->tty
))
1072 info
->ignore_status_mask
|= UART_LSR_PE
| UART_LSR_FE
;
1073 if (I_IGNBRK(info
->tty
)) {
1074 info
->ignore_status_mask
|= UART_LSR_BI
;
1076 * If we're ignore parity and break indicators, ignore
1077 * overruns too. (For real raw support).
1079 if (I_IGNPAR(info
->tty
))
1080 info
->ignore_status_mask
|= UART_LSR_OE
;
1083 * !!! ignore all characters if CREAD is not set
1085 if ((info
->cflag
& CREAD
) == 0)
1086 info
->ignore_status_mask
|= UART_LSR_DR
;
1089 save_flags(flags
); cli();
1090 if (uart_config
[info
->type
].flags
& UART_STARTECH
) {
1091 serial_outp(info
, UART_LCR
, 0xBF);
1092 serial_outp(info
, UART_EFR
,
1093 (info
->cflag
& CRTSCTS
) ? UART_EFR_CTS
: 0);
1095 serial_outp(info
, UART_LCR
, cval
| UART_LCR_DLAB
); /* set DLAB */
1096 serial_outp(info
, UART_DLL
, quot
& 0xff); /* LS of divisor */
1097 serial_outp(info
, UART_DLM
, quot
>> 8); /* MS of divisor */
1098 if (info
->type
== PORT_16750
)
1099 serial_outp(info
, UART_FCR
, fcr
); /* set fcr */
1100 serial_outp(info
, UART_LCR
, cval
); /* reset DLAB */
1101 if (info
->type
!= PORT_16750
)
1102 serial_outp(info
, UART_FCR
, fcr
); /* set fcr */
1103 restore_flags(flags
);
1108 su_put_char(struct tty_struct
*tty
, unsigned char ch
)
1110 struct su_struct
*info
= (struct su_struct
*)tty
->driver_data
;
1111 unsigned long flags
;
1113 if (serial_paranoia_check(info
, tty
->device
, "su_put_char"))
1116 if (!tty
|| !info
->xmit_buf
)
1119 save_flags(flags
); cli();
1120 if (info
->xmit_cnt
>= SERIAL_XMIT_SIZE
- 1) {
1121 restore_flags(flags
);
1125 info
->xmit_buf
[info
->xmit_head
++] = ch
;
1126 info
->xmit_head
&= SERIAL_XMIT_SIZE
-1;
1128 restore_flags(flags
);
1131 static void su_put_char_kbd(unsigned char c
)
1133 struct su_struct
*info
= su_table
;
1136 if (info
->port_type
!= SU_PORT_KBD
)
1138 if (info
->port_type
!= SU_PORT_KBD
)
1142 lsr
= serial_in(info
, UART_LSR
);
1143 } while (!(lsr
& UART_LSR_THRE
));
1145 /* Send the character out. */
1146 su_outb(info
, UART_TX
, c
);
1150 su_change_mouse_baud(int baud
)
1152 struct su_struct
*info
= su_table
;
1154 if (info
->port_type
!= SU_PORT_MS
)
1156 if (info
->port_type
!= SU_PORT_MS
)
1159 info
->cflag
&= ~(CBAUDEX
| CBAUD
);
1162 info
->cflag
|= B1200
;
1165 info
->cflag
|= B2400
;
1168 info
->cflag
|= B4800
;
1171 info
->cflag
|= B9600
;
1174 printk("su_change_mouse_baud: unknown baud rate %d, "
1175 "defaulting to 1200\n", baud
);
1176 info
->cflag
|= 1200;
1179 change_speed(info
, 0);
1183 su_flush_chars(struct tty_struct
*tty
)
1185 struct su_struct
*info
= (struct su_struct
*)tty
->driver_data
;
1186 unsigned long flags
;
1188 if (serial_paranoia_check(info
, tty
->device
, "su_flush_chars"))
1191 if (info
->xmit_cnt
<= 0 || tty
->stopped
|| tty
->hw_stopped
||
1195 save_flags(flags
); cli();
1196 info
->IER
|= UART_IER_THRI
;
1197 serial_out(info
, UART_IER
, info
->IER
);
1198 restore_flags(flags
);
1202 su_write(struct tty_struct
* tty
, int from_user
,
1203 const unsigned char *buf
, int count
)
1206 struct su_struct
*info
= (struct su_struct
*)tty
->driver_data
;
1207 unsigned long flags
;
1209 if (serial_paranoia_check(info
, tty
->device
, "su_write"))
1212 if (!tty
|| !info
->xmit_buf
|| !tmp_buf
)
1220 MIN(SERIAL_XMIT_SIZE
- info
->xmit_cnt
- 1,
1221 SERIAL_XMIT_SIZE
- info
->xmit_head
));
1225 c
-= copy_from_user(tmp_buf
, buf
, c
);
1232 c
= MIN(c
, MIN(SERIAL_XMIT_SIZE
- info
->xmit_cnt
- 1,
1233 SERIAL_XMIT_SIZE
- info
->xmit_head
));
1234 memcpy(info
->xmit_buf
+ info
->xmit_head
, tmp_buf
, c
);
1235 info
->xmit_head
= ((info
->xmit_head
+ c
) &
1236 (SERIAL_XMIT_SIZE
-1));
1237 info
->xmit_cnt
+= c
;
1238 restore_flags(flags
);
1248 MIN(SERIAL_XMIT_SIZE
- info
->xmit_cnt
- 1,
1249 SERIAL_XMIT_SIZE
- info
->xmit_head
));
1251 restore_flags(flags
);
1254 memcpy(info
->xmit_buf
+ info
->xmit_head
, buf
, c
);
1255 info
->xmit_head
= ((info
->xmit_head
+ c
) &
1256 (SERIAL_XMIT_SIZE
-1));
1257 info
->xmit_cnt
+= c
;
1258 restore_flags(flags
);
1264 if (info
->xmit_cnt
&& !tty
->stopped
&& !tty
->hw_stopped
&&
1265 !(info
->IER
& UART_IER_THRI
)) {
1266 info
->IER
|= UART_IER_THRI
;
1267 serial_out(info
, UART_IER
, info
->IER
);
1273 su_write_room(struct tty_struct
*tty
)
1275 struct su_struct
*info
= (struct su_struct
*)tty
->driver_data
;
1278 if (serial_paranoia_check(info
, tty
->device
, "su_write_room"))
1280 ret
= SERIAL_XMIT_SIZE
- info
->xmit_cnt
- 1;
1287 su_chars_in_buffer(struct tty_struct
*tty
)
1289 struct su_struct
*info
= (struct su_struct
*)tty
->driver_data
;
1291 if (serial_paranoia_check(info
, tty
->device
, "su_chars_in_buffer"))
1293 return info
->xmit_cnt
;
1297 su_flush_buffer(struct tty_struct
*tty
)
1299 struct su_struct
*info
= (struct su_struct
*)tty
->driver_data
;
1300 unsigned long flags
;
1302 if (serial_paranoia_check(info
, tty
->device
, "su_flush_buffer"))
1304 save_flags(flags
); cli();
1305 info
->xmit_cnt
= info
->xmit_head
= info
->xmit_tail
= 0;
1306 restore_flags(flags
);
1307 wake_up_interruptible(&tty
->write_wait
);
1308 if ((tty
->flags
& (1 << TTY_DO_WRITE_WAKEUP
)) &&
1309 tty
->ldisc
.write_wakeup
)
1310 (tty
->ldisc
.write_wakeup
)(tty
);
1314 * This function is used to send a high-priority XON/XOFF character to
1318 su_send_xchar(struct tty_struct
*tty
, char ch
)
1320 struct su_struct
*info
= (struct su_struct
*)tty
->driver_data
;
1322 if (serial_paranoia_check(info
, tty
->device
, "su_send_char"))
1325 if (!(info
->flags
& ASYNC_INITIALIZED
))
1330 /* Make sure transmit interrupts are on */
1331 info
->IER
|= UART_IER_THRI
;
1332 serial_out(info
, UART_IER
, info
->IER
);
1337 * ------------------------------------------------------------
1340 * This routine is called by the upper-layer tty layer to signal that
1341 * incoming characters should be throttled.
1342 * ------------------------------------------------------------
1345 su_throttle(struct tty_struct
* tty
)
1347 struct su_struct
*info
= (struct su_struct
*)tty
->driver_data
;
1348 unsigned long flags
;
1349 #ifdef SERIAL_DEBUG_THROTTLE
1352 printk("throttle %s: %d....\n", tty_name(tty
, buf
),
1353 tty
->ldisc
.chars_in_buffer(tty
));
1356 if (serial_paranoia_check(info
, tty
->device
, "su_throttle"))
1360 su_send_xchar(tty
, STOP_CHAR(tty
));
1362 if (tty
->termios
->c_cflag
& CRTSCTS
)
1363 info
->MCR
&= ~UART_MCR_RTS
;
1365 save_flags(flags
); cli();
1366 serial_out(info
, UART_MCR
, info
->MCR
);
1367 restore_flags(flags
);
1371 su_unthrottle(struct tty_struct
* tty
)
1373 struct su_struct
*info
= (struct su_struct
*)tty
->driver_data
;
1374 unsigned long flags
;
1375 #ifdef SERIAL_DEBUG_THROTTLE
1378 printk("unthrottle %s: %d....\n", tty_name(tty
, buf
),
1379 tty
->ldisc
.chars_in_buffer(tty
));
1382 if (serial_paranoia_check(info
, tty
->device
, "su_unthrottle"))
1389 su_send_xchar(tty
, START_CHAR(tty
));
1391 if (tty
->termios
->c_cflag
& CRTSCTS
)
1392 info
->MCR
|= UART_MCR_RTS
;
1393 save_flags(flags
); cli();
1394 serial_out(info
, UART_MCR
, info
->MCR
);
1395 restore_flags(flags
);
1399 * ------------------------------------------------------------
1400 * su_ioctl() and friends
1401 * ------------------------------------------------------------
1405 * get_lsr_info - get line status register info
1407 * Purpose: Let user call ioctl() to get info when the UART physically
1408 * is emptied. On bus types like RS485, the transmitter must
1409 * release the bus after transmitting. This must be done when
1410 * the transmit shift register is empty, not be done when the
1411 * transmit holding register is empty. This functionality
1412 * allows an RS485 driver to be written in user space.
1415 get_lsr_info(struct su_struct
* info
, unsigned int *value
)
1417 unsigned char status
;
1418 unsigned int result
;
1419 unsigned long flags
;
1421 save_flags(flags
); cli();
1422 status
= serial_in(info
, UART_LSR
);
1423 restore_flags(flags
);
1424 result
= ((status
& UART_LSR_TEMT
) ? TIOCSER_TEMT
: 0);
1425 return put_user(result
,value
);
1430 get_modem_info(struct su_struct
* info
, unsigned int *value
)
1432 unsigned char control
, status
;
1433 unsigned int result
;
1434 unsigned long flags
;
1436 control
= info
->MCR
;
1437 save_flags(flags
); cli();
1438 status
= serial_in(info
, UART_MSR
);
1439 restore_flags(flags
);
1440 result
= ((control
& UART_MCR_RTS
) ? TIOCM_RTS
: 0)
1441 | ((control
& UART_MCR_DTR
) ? TIOCM_DTR
: 0)
1443 | ((control
& UART_MCR_OUT1
) ? TIOCM_OUT1
: 0)
1444 | ((control
& UART_MCR_OUT2
) ? TIOCM_OUT2
: 0)
1446 | ((status
& UART_MSR_DCD
) ? TIOCM_CAR
: 0)
1447 | ((status
& UART_MSR_RI
) ? TIOCM_RNG
: 0)
1448 | ((status
& UART_MSR_DSR
) ? TIOCM_DSR
: 0)
1449 | ((status
& UART_MSR_CTS
) ? TIOCM_CTS
: 0);
1450 return put_user(result
,value
);
1454 set_modem_info(struct su_struct
* info
, unsigned int cmd
, unsigned int *value
)
1458 unsigned long flags
;
1460 error
= get_user(arg
, value
);
1465 if (arg
& TIOCM_RTS
)
1466 info
->MCR
|= UART_MCR_RTS
;
1467 if (arg
& TIOCM_DTR
)
1468 info
->MCR
|= UART_MCR_DTR
;
1470 if (arg
& TIOCM_OUT1
)
1471 info
->MCR
|= UART_MCR_OUT1
;
1472 if (arg
& TIOCM_OUT2
)
1473 info
->MCR
|= UART_MCR_OUT2
;
1477 if (arg
& TIOCM_RTS
)
1478 info
->MCR
&= ~UART_MCR_RTS
;
1479 if (arg
& TIOCM_DTR
)
1480 info
->MCR
&= ~UART_MCR_DTR
;
1482 if (arg
& TIOCM_OUT1
)
1483 info
->MCR
&= ~UART_MCR_OUT1
;
1484 if (arg
& TIOCM_OUT2
)
1485 info
->MCR
&= ~UART_MCR_OUT2
;
1489 info
->MCR
= ((info
->MCR
& ~(UART_MCR_RTS
|
1495 | ((arg
& TIOCM_RTS
) ? UART_MCR_RTS
: 0)
1497 | ((arg
& TIOCM_OUT1
) ? UART_MCR_OUT1
: 0)
1498 | ((arg
& TIOCM_OUT2
) ? UART_MCR_OUT2
: 0)
1500 | ((arg
& TIOCM_DTR
) ? UART_MCR_DTR
: 0));
1505 save_flags(flags
); cli();
1506 serial_out(info
, UART_MCR
, info
->MCR
);
1507 restore_flags(flags
);
1512 * su_break() --- routine which turns the break handling on or off
1515 su_break(struct tty_struct
*tty
, int break_state
)
1517 struct su_struct
* info
= (struct su_struct
*)tty
->driver_data
;
1518 unsigned long flags
;
1520 if (serial_paranoia_check(info
, tty
->device
, "su_break"))
1525 save_flags(flags
); cli();
1526 if (break_state
== -1)
1527 serial_out(info
, UART_LCR
,
1528 serial_inp(info
, UART_LCR
) | UART_LCR_SBC
);
1530 serial_out(info
, UART_LCR
,
1531 serial_inp(info
, UART_LCR
) & ~UART_LCR_SBC
);
1532 restore_flags(flags
);
1536 su_ioctl(struct tty_struct
*tty
, struct file
* file
,
1537 unsigned int cmd
, unsigned long arg
)
1540 struct su_struct
* info
= (struct su_struct
*)tty
->driver_data
;
1541 struct async_icount cprev
, cnow
; /* kernel counter temps */
1542 struct serial_icounter_struct
*p_cuser
; /* user space */
1544 if (serial_paranoia_check(info
, tty
->device
, "su_ioctl"))
1547 if ((cmd
!= TIOCGSERIAL
) && (cmd
!= TIOCSSERIAL
) &&
1548 (cmd
!= TIOCSERCONFIG
) && (cmd
!= TIOCSERGSTRUCT
) &&
1549 (cmd
!= TIOCMIWAIT
) && (cmd
!= TIOCGICOUNT
)) {
1550 if (tty
->flags
& (1 << TTY_IO_ERROR
))
1556 return get_modem_info(info
, (unsigned int *) arg
);
1560 return set_modem_info(info
, cmd
, (unsigned int *) arg
);
1562 case TIOCSERGETLSR
: /* Get line status register */
1563 return get_lsr_info(info
, (unsigned int *) arg
);
1566 case TIOCSERGSTRUCT
:
1567 if (copy_to_user((struct async_struct
*) arg
,
1568 info
, sizeof(struct async_struct
)))
1574 * Wait for any of the 4 modem inputs (DCD,RI,DSR,CTS) to change
1575 * - mask passed in arg for lines of interest
1576 * (use |'ed TIOCM_RNG/DSR/CD/CTS for masking)
1577 * Caller should use TIOCGICOUNT to see which one it was
1581 /* note the counters on entry */
1582 cprev
= info
->icount
;
1585 interruptible_sleep_on(&info
->delta_msr_wait
);
1586 /* see if a signal did it */
1587 if (signal_pending(current
))
1588 return -ERESTARTSYS
;
1590 cnow
= info
->icount
; /* atomic copy */
1592 if (cnow
.rng
== cprev
.rng
&& cnow
.dsr
== cprev
.dsr
&&
1593 cnow
.dcd
== cprev
.dcd
&& cnow
.cts
== cprev
.cts
)
1594 return -EIO
; /* no change => error */
1595 if ( ((arg
& TIOCM_RNG
) && (cnow
.rng
!= cprev
.rng
)) ||
1596 ((arg
& TIOCM_DSR
) && (cnow
.dsr
!= cprev
.dsr
)) ||
1597 ((arg
& TIOCM_CD
) && (cnow
.dcd
!= cprev
.dcd
)) ||
1598 ((arg
& TIOCM_CTS
) && (cnow
.cts
!= cprev
.cts
)) ) {
1606 * Get counter of input serial line interrupts (DCD,RI,DSR,CTS)
1607 * Return: write counters to the user passed counter struct
1608 * NB: both 1->0 and 0->1 transitions are counted except for
1609 * RI where only 0->1 is counted.
1613 cnow
= info
->icount
;
1615 p_cuser
= (struct serial_icounter_struct
*) arg
;
1616 error
= put_user(cnow
.cts
, &p_cuser
->cts
);
1617 if (error
) return error
;
1618 error
= put_user(cnow
.dsr
, &p_cuser
->dsr
);
1619 if (error
) return error
;
1620 error
= put_user(cnow
.rng
, &p_cuser
->rng
);
1621 if (error
) return error
;
1622 error
= put_user(cnow
.dcd
, &p_cuser
->dcd
);
1623 if (error
) return error
;
1627 return -ENOIOCTLCMD
;
1629 /* return 0; */ /* Trigger warnings if fall through by a chance. */
1633 su_set_termios(struct tty_struct
*tty
, struct termios
*old_termios
)
1635 struct su_struct
*info
= (struct su_struct
*)tty
->driver_data
;
1636 unsigned long flags
;
1638 if ( (tty
->termios
->c_cflag
== old_termios
->c_cflag
)
1639 && ( RELEVANT_IFLAG(tty
->termios
->c_iflag
)
1640 == RELEVANT_IFLAG(old_termios
->c_iflag
)))
1643 change_speed(info
, old_termios
);
1645 /* Handle transition to B0 status */
1646 if ((old_termios
->c_cflag
& CBAUD
) &&
1647 !(tty
->termios
->c_cflag
& CBAUD
)) {
1648 info
->MCR
&= ~(UART_MCR_DTR
|UART_MCR_RTS
);
1649 save_flags(flags
); cli();
1650 serial_out(info
, UART_MCR
, info
->MCR
);
1651 restore_flags(flags
);
1654 /* Handle transition away from B0 status */
1655 if (!(old_termios
->c_cflag
& CBAUD
) &&
1656 (tty
->termios
->c_cflag
& CBAUD
)) {
1657 info
->MCR
|= UART_MCR_DTR
;
1658 if (!(tty
->termios
->c_cflag
& CRTSCTS
) ||
1659 !test_bit(TTY_THROTTLED
, &tty
->flags
)) {
1660 info
->MCR
|= UART_MCR_RTS
;
1662 save_flags(flags
); cli();
1663 serial_out(info
, UART_MCR
, info
->MCR
);
1664 restore_flags(flags
);
1667 /* Handle turning off CRTSCTS */
1668 if ((old_termios
->c_cflag
& CRTSCTS
) &&
1669 !(tty
->termios
->c_cflag
& CRTSCTS
)) {
1670 tty
->hw_stopped
= 0;
1676 * No need to wake up processes in open wait, since they
1677 * sample the CLOCAL flag once, and don't recheck it.
1678 * XXX It's not clear whether the current behavior is correct
1679 * or not. Hence, this may change.....
1681 if (!(old_termios
->c_cflag
& CLOCAL
) &&
1682 (tty
->termios
->c_cflag
& CLOCAL
))
1683 wake_up_interruptible(&info
->open_wait
);
1688 * ------------------------------------------------------------
1691 * This routine is called when the serial port gets closed. First, we
1692 * wait for the last remaining data to be sent. Then, we unlink its
1693 * async structure from the interrupt chain if necessary, and we free
1694 * that IRQ if nothing is left in the chain.
1695 * ------------------------------------------------------------
1698 su_close(struct tty_struct
*tty
, struct file
* filp
)
1700 struct su_struct
*info
= (struct su_struct
*)tty
->driver_data
;
1701 unsigned long flags
;
1703 if (!info
|| serial_paranoia_check(info
, tty
->device
, "su_close"))
1706 save_flags(flags
); cli();
1708 if (tty_hung_up_p(filp
)) {
1709 DBG_CNT("before DEC-hung");
1711 restore_flags(flags
);
1715 #ifdef SERIAL_DEBUG_OPEN
1716 printk("su_close ttys%d, count = %d\n", info
->line
, info
->count
);
1718 if ((tty
->count
== 1) && (info
->count
!= 1)) {
1720 * Uh, oh. tty->count is 1, which means that the tty
1721 * structure will be freed. info->count should always
1722 * be one in these conditions. If it's greater than
1723 * one, we've got real problems, since it means the
1724 * serial port won't be shutdown.
1726 printk("su_close: bad serial port count; tty->count is 1, "
1727 "info->count is %d\n", info
->count
);
1730 if (--info
->count
< 0) {
1731 printk("su_close: bad serial port count for ttys%d: %d\n",
1732 info
->line
, info
->count
);
1736 DBG_CNT("before DEC-2");
1738 restore_flags(flags
);
1741 info
->flags
|= ASYNC_CLOSING
;
1743 * Save the termios structure, since this port may have
1744 * separate termios for callout and dialin.
1746 if (info
->flags
& ASYNC_NORMAL_ACTIVE
)
1747 info
->normal_termios
= *tty
->termios
;
1748 if (info
->flags
& ASYNC_CALLOUT_ACTIVE
)
1749 info
->callout_termios
= *tty
->termios
;
1751 * Now we wait for the transmit buffer to clear; and we notify
1752 * the line discipline to only process XON/XOFF characters.
1755 if (info
->closing_wait
!= ASYNC_CLOSING_WAIT_NONE
)
1756 tty_wait_until_sent(tty
, info
->closing_wait
);
1758 * At this point we stop accepting input. To do this, we
1759 * disable the receive line status interrupts, and tell the
1760 * interrupt driver to stop checking the data ready bit in the
1761 * line status register.
1763 info
->IER
&= ~UART_IER_RLSI
;
1764 info
->read_status_mask
&= ~UART_LSR_DR
;
1765 if (info
->flags
& ASYNC_INITIALIZED
) {
1766 serial_out(info
, UART_IER
, info
->IER
);
1768 * Before we drop DTR, make sure the UART transmitter
1769 * has completely drained; this is especially
1770 * important if there is a transmit FIFO!
1772 su_wait_until_sent(tty
, info
->timeout
);
1775 if (tty
->driver
.flush_buffer
)
1776 tty
->driver
.flush_buffer(tty
);
1777 if (tty
->ldisc
.flush_buffer
)
1778 tty
->ldisc
.flush_buffer(tty
);
1782 if (info
->blocked_open
) {
1783 if (info
->close_delay
) {
1784 current
->state
= TASK_INTERRUPTIBLE
;
1785 schedule_timeout(info
->close_delay
);
1787 wake_up_interruptible(&info
->open_wait
);
1789 info
->flags
&= ~(ASYNC_NORMAL_ACTIVE
|ASYNC_CALLOUT_ACTIVE
|
1791 wake_up_interruptible(&info
->close_wait
);
1793 restore_flags(flags
);
1797 * su_wait_until_sent() --- wait until the transmitter is empty
1800 su_wait_until_sent(struct tty_struct
*tty
, int timeout
)
1802 struct su_struct
* info
= (struct su_struct
*)tty
->driver_data
;
1803 unsigned long orig_jiffies
, char_time
;
1806 if (serial_paranoia_check(info
, tty
->device
, "su_wait_until_sent"))
1809 if (info
->type
== PORT_UNKNOWN
)
1812 if (info
->xmit_fifo_size
== 0)
1813 return; /* Just in case ... */
1815 orig_jiffies
= jiffies
;
1817 * Set the check interval to be 1/5 of the estimated time to
1818 * send a single character, and make it at least 1. The check
1819 * interval should also be less than the timeout.
1821 * Note: we have to use pretty tight timings here to satisfy
1824 char_time
= (info
->timeout
- HZ
/50) / info
->xmit_fifo_size
;
1825 char_time
= char_time
/ 5;
1829 char_time
= MIN(char_time
, timeout
);
1830 #ifdef SERIAL_DEBUG_RS_WAIT_UNTIL_SENT
1831 printk("In su_wait_until_sent(%d) check=%lu...", timeout
, char_time
);
1832 printk("jiff=%lu...", jiffies
);
1834 while (!((lsr
= serial_inp(info
, UART_LSR
)) & UART_LSR_TEMT
)) {
1835 #ifdef SERIAL_DEBUG_RS_WAIT_UNTIL_SENT
1836 printk("lsr = %d (jiff=%lu)...", lsr
, jiffies
);
1838 current
->state
= TASK_INTERRUPTIBLE
;
1839 schedule_timeout(char_time
);
1840 if (signal_pending(current
))
1842 if (timeout
&& time_after(jiffies
, orig_jiffies
+ timeout
))
1845 current
->state
= TASK_RUNNING
;
1846 #ifdef SERIAL_DEBUG_RS_WAIT_UNTIL_SENT
1847 printk("lsr = %d (jiff=%lu)...done\n", lsr
, jiffies
);
1852 * su_hangup() --- called by tty_hangup() when a hangup is signaled.
1855 su_hangup(struct tty_struct
*tty
)
1857 struct su_struct
* info
= (struct su_struct
*)tty
->driver_data
;
1859 if (serial_paranoia_check(info
, tty
->device
, "su_hangup"))
1862 su_flush_buffer(tty
);
1866 info
->flags
&= ~(ASYNC_NORMAL_ACTIVE
|ASYNC_CALLOUT_ACTIVE
);
1868 wake_up_interruptible(&info
->open_wait
);
1872 * ------------------------------------------------------------
1873 * su_open() and friends
1874 * ------------------------------------------------------------
1877 block_til_ready(struct tty_struct
*tty
, struct file
* filp
,
1878 struct su_struct
*info
)
1880 DECLARE_WAITQUEUE(wait
, current
);
1882 int do_clocal
= 0, extra_count
= 0;
1883 unsigned long flags
;
1886 * If the device is in the middle of being closed, then block
1887 * until it's done, and then try again.
1889 if (tty_hung_up_p(filp
) ||
1890 (info
->flags
& ASYNC_CLOSING
)) {
1891 if (info
->flags
& ASYNC_CLOSING
)
1892 interruptible_sleep_on(&info
->close_wait
);
1893 #ifdef SERIAL_DO_RESTART
1894 return ((info
->flags
& ASYNC_HUP_NOTIFY
) ?
1895 -EAGAIN
: -ERESTARTSYS
);
1902 * If this is a callout device, then just make sure the normal
1903 * device isn't being used.
1905 if (tty
->driver
.subtype
== SERIAL_TYPE_CALLOUT
) {
1906 if (info
->flags
& ASYNC_NORMAL_ACTIVE
)
1908 if ((info
->flags
& ASYNC_CALLOUT_ACTIVE
) &&
1909 (info
->flags
& ASYNC_SESSION_LOCKOUT
) &&
1910 (info
->session
!= current
->session
))
1912 if ((info
->flags
& ASYNC_CALLOUT_ACTIVE
) &&
1913 (info
->flags
& ASYNC_PGRP_LOCKOUT
) &&
1914 (info
->pgrp
!= current
->pgrp
))
1916 info
->flags
|= ASYNC_CALLOUT_ACTIVE
;
1921 * If non-blocking mode is set, or the port is not enabled,
1922 * then make the check up front and then exit.
1924 if ((filp
->f_flags
& O_NONBLOCK
) ||
1925 (tty
->flags
& (1 << TTY_IO_ERROR
))) {
1926 if (info
->flags
& ASYNC_CALLOUT_ACTIVE
)
1928 info
->flags
|= ASYNC_NORMAL_ACTIVE
;
1932 if (info
->flags
& ASYNC_CALLOUT_ACTIVE
) {
1933 if (info
->normal_termios
.c_cflag
& CLOCAL
)
1936 if (tty
->termios
->c_cflag
& CLOCAL
)
1941 * Block waiting for the carrier detect and the line to become
1942 * free (i.e., not in use by the callout). While we are in
1943 * this loop, info->count is dropped by one, so that
1944 * su_close() knows when to free things. We restore it upon
1945 * exit, either normal or abnormal.
1948 add_wait_queue(&info
->open_wait
, &wait
);
1949 #ifdef SERIAL_DEBUG_OPEN
1950 printk("block_til_ready before block: ttys%d, count = %d\n",
1951 info
->line
, info
->count
);
1953 save_flags(flags
); cli();
1954 if (!tty_hung_up_p(filp
)) {
1958 restore_flags(flags
);
1959 info
->blocked_open
++;
1961 save_flags(flags
); cli();
1962 if (!(info
->flags
& ASYNC_CALLOUT_ACTIVE
) &&
1963 (tty
->termios
->c_cflag
& CBAUD
))
1964 serial_out(info
, UART_MCR
,
1965 serial_inp(info
, UART_MCR
) |
1966 (UART_MCR_DTR
| UART_MCR_RTS
));
1967 restore_flags(flags
);
1968 set_current_state(TASK_INTERRUPTIBLE
);
1969 if (tty_hung_up_p(filp
) ||
1970 !(info
->flags
& ASYNC_INITIALIZED
)) {
1971 #ifdef SERIAL_DO_RESTART
1972 if (info
->flags
& ASYNC_HUP_NOTIFY
)
1975 retval
= -ERESTARTSYS
;
1981 if (!(info
->flags
& ASYNC_CALLOUT_ACTIVE
) &&
1982 !(info
->flags
& ASYNC_CLOSING
) &&
1983 (do_clocal
|| (serial_in(info
, UART_MSR
) &
1986 if (signal_pending(current
)) {
1987 retval
= -ERESTARTSYS
;
1990 #ifdef SERIAL_DEBUG_OPEN
1991 printk("block_til_ready blocking: ttys%d, count = %d\n",
1992 info
->line
, info
->count
);
1996 current
->state
= TASK_RUNNING
;
1997 remove_wait_queue(&info
->open_wait
, &wait
);
2000 info
->blocked_open
--;
2001 #ifdef SERIAL_DEBUG_OPEN
2002 printk("block_til_ready after blocking: ttys%d, count = %d\n",
2003 info
->line
, info
->count
);
2007 info
->flags
|= ASYNC_NORMAL_ACTIVE
;
2012 * This routine is called whenever a serial port is opened. It
2013 * enables interrupts for a serial port, linking in its async structure into
2014 * the IRQ chain. It also performs the serial-specific
2015 * initialization for the tty structure.
2018 su_open(struct tty_struct
*tty
, struct file
* filp
)
2020 struct su_struct
*info
;
2024 line
= MINOR(tty
->device
) - tty
->driver
.minor_start
;
2025 if ((line
< 0) || (line
>= NR_PORTS
))
2027 info
= su_table
+ line
;
2029 tty
->driver_data
= info
;
2032 if (serial_paranoia_check(info
, tty
->device
, "su_open")) {
2037 #ifdef SERIAL_DEBUG_OPEN
2038 printk("su_open %s%d, count = %d\n", tty
->driver
.name
, info
->line
,
2041 info
->tty
->low_latency
= (info
->flags
& ASYNC_LOW_LATENCY
) ? 1 : 0;
2044 page
= get_free_page(GFP_KERNEL
);
2050 tmp_buf
= (unsigned char *) page
;
2054 * If the port is the middle of closing, bail out now
2056 if (tty_hung_up_p(filp
) ||
2057 (info
->flags
& ASYNC_CLOSING
)) {
2058 if (info
->flags
& ASYNC_CLOSING
)
2059 interruptible_sleep_on(&info
->close_wait
);
2060 #ifdef SERIAL_DO_RESTART
2061 return ((info
->flags
& ASYNC_HUP_NOTIFY
) ?
2062 -EAGAIN
: -ERESTARTSYS
);
2069 * Start up serial port
2071 retval
= startup(info
);
2076 retval
= block_til_ready(tty
, filp
, info
);
2078 #ifdef SERIAL_DEBUG_OPEN
2079 printk("su_open returning after block_til_ready with %d\n",
2085 if ((info
->count
== 1) &&
2086 (info
->flags
& ASYNC_SPLIT_TERMIOS
)) {
2087 if (tty
->driver
.subtype
== SERIAL_TYPE_NORMAL
)
2088 *tty
->termios
= info
->normal_termios
;
2090 *tty
->termios
= info
->callout_termios
;
2091 change_speed(info
, 0);
2093 #ifdef CONFIG_SERIAL_CONSOLE
2094 if (sercons
.cflag
&& sercons
.index
== line
) {
2095 tty
->termios
->c_cflag
= sercons
.cflag
;
2097 change_speed(info
, 0);
2100 info
->session
= current
->session
;
2101 info
->pgrp
= current
->pgrp
;
2103 #ifdef SERIAL_DEBUG_OPEN
2104 printk("su_open ttys%d successful...", info
->line
);
2110 * /proc fs routines....
2112 static __inline__
int
2113 line_info(char *buf
, struct su_struct
*info
)
2115 char stat_buf
[30], control
, status
;
2117 unsigned long flags
;
2119 ret
= sprintf(buf
, "%d: uart:%s port:%X irq:%s",
2120 info
->line
, uart_config
[info
->type
].name
,
2121 (int)info
->port
, __irq_itoa(info
->irq
));
2123 if (info
->port
== 0 || info
->type
== PORT_UNKNOWN
) {
2124 ret
+= sprintf(buf
+ret
, "\n");
2129 * Figure out the current RS-232 lines
2131 save_flags(flags
); cli();
2132 status
= serial_in(info
, UART_MSR
);
2133 control
= info
? info
->MCR
: serial_in(info
, UART_MCR
);
2134 restore_flags(flags
);
2138 if (control
& UART_MCR_RTS
)
2139 strcat(stat_buf
, "|RTS");
2140 if (status
& UART_MSR_CTS
)
2141 strcat(stat_buf
, "|CTS");
2142 if (control
& UART_MCR_DTR
)
2143 strcat(stat_buf
, "|DTR");
2144 if (status
& UART_MSR_DSR
)
2145 strcat(stat_buf
, "|DSR");
2146 if (status
& UART_MSR_DCD
)
2147 strcat(stat_buf
, "|CD");
2148 if (status
& UART_MSR_RI
)
2149 strcat(stat_buf
, "|RI");
2152 ret
+= sprintf(buf
+ret
, " baud:%d",
2153 info
->baud_base
/ info
->quot
);
2156 ret
+= sprintf(buf
+ret
, " tx:%d rx:%d",
2157 info
->icount
.tx
, info
->icount
.rx
);
2159 if (info
->icount
.frame
)
2160 ret
+= sprintf(buf
+ret
, " fe:%d", info
->icount
.frame
);
2162 if (info
->icount
.parity
)
2163 ret
+= sprintf(buf
+ret
, " pe:%d", info
->icount
.parity
);
2165 if (info
->icount
.brk
)
2166 ret
+= sprintf(buf
+ret
, " brk:%d", info
->icount
.brk
);
2168 if (info
->icount
.overrun
)
2169 ret
+= sprintf(buf
+ret
, " oe:%d", info
->icount
.overrun
);
2172 * Last thing is the RS-232 status lines
2174 ret
+= sprintf(buf
+ret
, " %s\n", stat_buf
+1);
2178 int su_read_proc(char *page
, char **start
, off_t off
, int count
,
2179 int *eof
, void *data
)
2184 len
+= sprintf(page
, "serinfo:1.0 driver:%s\n", serial_version
);
2185 for (i
= 0; i
< NR_PORTS
&& len
< 4000; i
++) {
2186 len
+= line_info(page
+ len
, &su_table
[i
]);
2187 if (len
+begin
> off
+count
)
2189 if (len
+begin
< off
) {
2196 if (off
>= len
+begin
)
2198 *start
= page
+ (begin
-off
);
2199 return ((count
< begin
+len
-off
) ? count
: begin
+len
-off
);
2203 * ---------------------------------------------------------------------
2204 * su_XXX_init() and friends
2206 * su_XXX_init() is called at boot-time to initialize the serial driver.
2207 * ---------------------------------------------------------------------
2211 * This routine prints out the appropriate serial driver version
2212 * number, and identifies which options were configured into this
2215 static __inline__
void __init
show_su_version(void)
2217 char *revision
= "$Revision: 1.28 $";
2220 version
= strchr(revision
, ' ');
2221 strcpy(serial_version
, ++version
);
2222 p
= strchr(serial_version
, ' ');
2224 printk(KERN_INFO
"%s version %s\n", serial_name
, serial_version
);
2228 * This routine is called by su_{serial|kbd_ms}_init() to initialize a specific
2229 * serial port. It determines what type of UART chip this serial port is
2230 * using: 8250, 16450, 16550, 16550A. The important question is
2231 * whether or not this UART is a 16550A, since this will determine
2232 * whether or not we can use its FIFO features.
2235 autoconfig(struct su_struct
*info
)
2237 unsigned char status1
, status2
, scratch
, scratch2
;
2238 struct linux_ebus_device
*dev
= 0;
2239 struct linux_ebus
*ebus
;
2240 #ifndef __sparc_v9__
2241 struct linux_prom_registers reg0
;
2243 unsigned long flags
;
2245 if (!info
->port_node
|| !info
->port_type
)
2249 * First we look for Ebus-bases su's
2251 for_each_ebus(ebus
) {
2252 for_each_ebusdev(dev
, ebus
) {
2253 if (dev
->prom_node
== info
->port_node
) {
2254 info
->port
= dev
->resource
[0].start
;
2255 info
->irq
= dev
->irqs
[0];
2263 * Not on Ebus, bailing.
2268 * Not on Ebus, must be OBIO.
2270 if (prom_getproperty(info
->port_node
, "reg",
2271 (char *)®0
, sizeof(reg0
)) == -1) {
2272 prom_printf("su: no \"reg\" property\n");
2275 prom_apply_obio_ranges(®0
, 1);
2276 if ((info
->port
= (unsigned long) sparc_alloc_io(reg0
.phys_addr
,
2277 0, reg0
.reg_size
, "su-regs", reg0
.which_io
, 0)) == 0) {
2278 prom_printf("su: cannot map\n");
2283 * There is no intr property on MrCoffee, so hardwire it.
2285 info
->irq
= IRQ_4M(13);
2290 #ifdef SERIAL_DEBUG_OPEN
2291 printk("Found 'su' at %016lx IRQ %s\n", info
->port
,
2292 __irq_itoa(info
->irq
));
2295 info
->magic
= SERIAL_MAGIC
;
2297 save_flags(flags
); cli();
2300 * Do a simple existence test first; if we fail this, there's
2301 * no point trying anything else.
2303 * 0x80 is used as a nonsense port to prevent against false
2304 * positives due to ISA bus float. The assumption is that
2305 * 0x80 is a non-existent port; which should be safe since
2306 * include/asm/io.h also makes this assumption.
2308 scratch
= serial_inp(info
, UART_IER
);
2309 serial_outp(info
, UART_IER
, 0);
2310 scratch2
= serial_inp(info
, UART_IER
);
2311 serial_outp(info
, UART_IER
, scratch
);
2313 restore_flags(flags
);
2314 return; /* We failed; there's nothing here */
2317 scratch
= serial_inp(info
, UART_MCR
);
2318 serial_outp(info
, UART_MCR
, UART_MCR_LOOP
| scratch
);
2319 serial_outp(info
, UART_MCR
, UART_MCR_LOOP
| 0x0A);
2320 status1
= serial_inp(info
, UART_MSR
) & 0xF0;
2321 serial_outp(info
, UART_MCR
, scratch
);
2322 if (status1
!= 0x90) {
2324 * This code fragment used to fail, now it fixed itself.
2325 * We keep the printout for a case.
2327 printk("su: loopback returned status 0x%02x\n", status1
);
2328 restore_flags(flags
);
2332 scratch2
= serial_in(info
, UART_LCR
);
2333 serial_outp(info
, UART_LCR
, 0xBF); /* set up for StarTech test */
2334 serial_outp(info
, UART_EFR
, 0); /* EFR is the same as FCR */
2335 serial_outp(info
, UART_LCR
, 0);
2336 serial_outp(info
, UART_FCR
, UART_FCR_ENABLE_FIFO
);
2337 scratch
= serial_in(info
, UART_IIR
) >> 6;
2340 info
->type
= PORT_16450
;
2343 info
->type
= PORT_UNKNOWN
;
2346 info
->type
= PORT_16550
;
2349 info
->type
= PORT_16550A
;
2352 if (info
->type
== PORT_16550A
) {
2353 /* Check for Startech UART's */
2354 serial_outp(info
, UART_LCR
, scratch2
| UART_LCR_DLAB
);
2355 if (serial_in(info
, UART_EFR
) == 0) {
2356 info
->type
= PORT_16650
;
2358 serial_outp(info
, UART_LCR
, 0xBF);
2359 if (serial_in(info
, UART_EFR
) == 0)
2360 info
->type
= PORT_16650V2
;
2363 if (info
->type
== PORT_16550A
) {
2364 /* Check for TI 16750 */
2365 serial_outp(info
, UART_LCR
, scratch2
| UART_LCR_DLAB
);
2366 serial_outp(info
, UART_FCR
,
2367 UART_FCR_ENABLE_FIFO
| UART_FCR7_64BYTE
);
2368 scratch
= serial_in(info
, UART_IIR
) >> 5;
2370 serial_outp(info
, UART_LCR
, 0);
2371 serial_outp(info
, UART_FCR
, UART_FCR_ENABLE_FIFO
);
2372 scratch
= serial_in(info
, UART_IIR
) >> 5;
2374 info
->type
= PORT_16750
;
2376 serial_outp(info
, UART_FCR
, UART_FCR_ENABLE_FIFO
);
2378 serial_outp(info
, UART_LCR
, scratch2
);
2379 if (info
->type
== PORT_16450
) {
2380 scratch
= serial_in(info
, UART_SCR
);
2381 serial_outp(info
, UART_SCR
, 0xa5);
2382 status1
= serial_in(info
, UART_SCR
);
2383 serial_outp(info
, UART_SCR
, 0x5a);
2384 status2
= serial_in(info
, UART_SCR
);
2385 serial_outp(info
, UART_SCR
, scratch
);
2387 if ((status1
!= 0xa5) || (status2
!= 0x5a))
2388 info
->type
= PORT_8250
;
2390 info
->xmit_fifo_size
= uart_config
[info
->type
].dfl_xmit_fifo_size
;
2392 if (info
->type
== PORT_UNKNOWN
) {
2393 restore_flags(flags
);
2397 sprintf(info
->name
, "su(%s)", su_typev
[info
->port_type
]);
2402 serial_outp(info
, UART_MCR
, 0x00);
2403 serial_outp(info
, UART_FCR
, (UART_FCR_CLEAR_RCVR
|UART_FCR_CLEAR_XMIT
));
2404 (void)serial_in(info
, UART_RX
);
2405 serial_outp(info
, UART_IER
, 0x00);
2407 restore_flags(flags
);
2411 * The serial driver boot-time initialization code!
2413 int __init
su_serial_init(void)
2416 struct su_struct
*info
;
2418 init_bh(SERIAL_BH
, do_serial_bh
);
2421 /* Initialize the tty_driver structure */
2423 memset(&serial_driver
, 0, sizeof(struct tty_driver
));
2424 serial_driver
.magic
= TTY_DRIVER_MAGIC
;
2425 serial_driver
.driver_name
= "su";
2426 serial_driver
.name
= "ttyS";
2427 serial_driver
.major
= TTY_MAJOR
;
2428 serial_driver
.minor_start
= 64;
2429 serial_driver
.num
= NR_PORTS
;
2430 serial_driver
.type
= TTY_DRIVER_TYPE_SERIAL
;
2431 serial_driver
.subtype
= SERIAL_TYPE_NORMAL
;
2432 serial_driver
.init_termios
= tty_std_termios
;
2433 serial_driver
.init_termios
.c_cflag
=
2434 B9600
| CS8
| CREAD
| HUPCL
| CLOCAL
;
2435 serial_driver
.flags
= TTY_DRIVER_REAL_RAW
;
2436 serial_driver
.refcount
= &serial_refcount
;
2437 serial_driver
.table
= serial_table
;
2438 serial_driver
.termios
= serial_termios
;
2439 serial_driver
.termios_locked
= serial_termios_locked
;
2441 serial_driver
.open
= su_open
;
2442 serial_driver
.close
= su_close
;
2443 serial_driver
.write
= su_write
;
2444 serial_driver
.put_char
= su_put_char
;
2445 serial_driver
.flush_chars
= su_flush_chars
;
2446 serial_driver
.write_room
= su_write_room
;
2447 serial_driver
.chars_in_buffer
= su_chars_in_buffer
;
2448 serial_driver
.flush_buffer
= su_flush_buffer
;
2449 serial_driver
.ioctl
= su_ioctl
;
2450 serial_driver
.throttle
= su_throttle
;
2451 serial_driver
.unthrottle
= su_unthrottle
;
2452 serial_driver
.send_xchar
= su_send_xchar
;
2453 serial_driver
.set_termios
= su_set_termios
;
2454 serial_driver
.stop
= su_stop
;
2455 serial_driver
.start
= su_start
;
2456 serial_driver
.hangup
= su_hangup
;
2457 serial_driver
.break_ctl
= su_break
;
2458 serial_driver
.wait_until_sent
= su_wait_until_sent
;
2459 serial_driver
.read_proc
= su_read_proc
;
2462 * The callout device is just like normal device except for
2463 * major number and the subtype code.
2465 callout_driver
= serial_driver
;
2466 callout_driver
.name
= "cua";
2467 callout_driver
.major
= TTYAUX_MAJOR
;
2468 callout_driver
.subtype
= SERIAL_TYPE_CALLOUT
;
2469 callout_driver
.read_proc
= 0;
2470 callout_driver
.proc_entry
= 0;
2472 if (tty_register_driver(&serial_driver
))
2473 panic("Couldn't register regular su\n");
2474 if (tty_register_driver(&callout_driver
))
2475 panic("Couldn't register callout su\n");
2477 for (i
= 0, info
= su_table
; i
< NR_PORTS
; i
++, info
++) {
2479 info
->type
= PORT_UNKNOWN
;
2480 info
->baud_base
= BAUD_BASE
;
2481 /* info->flags = 0; */
2482 info
->custom_divisor
= 0;
2483 info
->close_delay
= 5*HZ
/10;
2484 info
->closing_wait
= 30*HZ
;
2485 info
->callout_termios
= callout_driver
.init_termios
;
2486 info
->normal_termios
= serial_driver
.init_termios
;
2487 info
->icount
.cts
= info
->icount
.dsr
=
2488 info
->icount
.rng
= info
->icount
.dcd
= 0;
2489 info
->icount
.rx
= info
->icount
.tx
= 0;
2490 info
->icount
.frame
= info
->icount
.parity
= 0;
2491 info
->icount
.overrun
= info
->icount
.brk
= 0;
2492 info
->tqueue
.routine
= do_softint
;
2493 info
->tqueue
.data
= info
;
2494 info
->cflag
= serial_driver
.init_termios
.c_cflag
;
2495 init_waitqueue_head(&info
->open_wait
);
2496 init_waitqueue_head(&info
->close_wait
);
2497 init_waitqueue_head(&info
->delta_msr_wait
);
2500 if (info
->type
== PORT_UNKNOWN
)
2503 printk(KERN_INFO
"%s at 0x%lx (tty %d irq %s) is a %s\n",
2504 info
->name
, (long)info
->port
, i
, __irq_itoa(info
->irq
),
2505 uart_config
[info
->type
].name
);
2511 int __init
su_kbd_ms_init(void)
2514 struct su_struct
*info
;
2518 for (i
= 0, info
= su_table
; i
< 2; i
++, info
++) {
2520 info
->type
= PORT_UNKNOWN
;
2521 info
->baud_base
= BAUD_BASE
;
2523 if (info
->port_type
== SU_PORT_KBD
)
2524 info
->cflag
= B1200
| CS8
| CLOCAL
| CREAD
;
2526 info
->cflag
= B4800
| CS8
| CLOCAL
| CREAD
;
2528 init_waitqueue_head(&info
->open_wait
);
2529 init_waitqueue_head(&info
->close_wait
);
2530 init_waitqueue_head(&info
->delta_msr_wait
);
2533 if (info
->type
== PORT_UNKNOWN
)
2536 printk(KERN_INFO
"%s at 0x%lx (irq = %s) is a %s\n",
2537 info
->name
, info
->port
, __irq_itoa(info
->irq
),
2538 uart_config
[info
->type
].name
);
2541 if (info
->port_type
== SU_PORT_KBD
)
2542 keyboard_zsinit(su_put_char_kbd
);
2550 * We got several platforms which present 'su' in different parts
2551 * of device tree. 'su' may be found under obio, ebus, isa and pci.
2552 * We walk over the tree and find them wherever PROM hides them.
2554 void __init
su_probe_any(struct su_probe_scan
*t
, int sunode
)
2556 struct su_struct
*info
;
2559 if (t
->devices
>= NR_PORTS
) return;
2561 for (; sunode
!= 0; sunode
= prom_getsibling(sunode
)) {
2562 len
= prom_getproperty(sunode
, "name", t
->prop
, SU_PROPSIZE
);
2563 if (len
<= 1) continue; /* Broken PROM node */
2564 if (strncmp(t
->prop
, "su", len
) == 0 ||
2565 strncmp(t
->prop
, "serial", len
) == 0 ||
2566 strncmp(t
->prop
, "su_pnp", len
) == 0) {
2567 info
= &su_table
[t
->devices
];
2568 if (t
->kbnode
!= 0 && sunode
== t
->kbnode
) {
2569 t
->kbx
= t
->devices
;
2570 info
->port_type
= SU_PORT_KBD
;
2571 } else if (t
->msnode
!= 0 && sunode
== t
->msnode
) {
2572 t
->msx
= t
->devices
;
2573 info
->port_type
= SU_PORT_MS
;
2575 info
->port_type
= SU_PORT_PORT
;
2577 info
->port_node
= sunode
;
2580 su_probe_any(t
, prom_getchild(sunode
));
2585 int __init
su_probe (unsigned long *memory_start
)
2589 struct su_probe_scan scan
;
2592 * First, we scan the tree.
2601 * Get the nodes for keyboard and mouse from 'aliases'...
2603 node
= prom_getchild(prom_root_node
);
2604 node
= prom_searchsiblings(node
, "aliases");
2607 len
= prom_getproperty(node
, "keyboard", scan
.prop
,SU_PROPSIZE
);
2610 scan
.kbnode
= prom_finddevice(scan
.prop
);
2613 len
= prom_getproperty(node
, "mouse", scan
.prop
, SU_PROPSIZE
);
2616 scan
.msnode
= prom_finddevice(scan
.prop
);
2620 su_probe_any(&scan
, prom_getchild(prom_root_node
));
2623 * Second, we process the special case of keyboard and mouse.
2625 * Currently if we got keyboard and mouse hooked to "su" ports
2626 * we do not use any possible remaining "su" as a serial port.
2627 * Thus, we ignore values of .msx and .kbx, then compact ports.
2628 * Those who want to address this issue need to merge
2629 * su_serial_init() and su_ms_kbd_init().
2631 if (scan
.msx
!= -1 && scan
.kbx
!= -1) {
2632 su_table
[0].port_type
= SU_PORT_MS
;
2633 su_table
[0].port_node
= scan
.msnode
;
2634 su_table
[1].port_type
= SU_PORT_KBD
;
2635 su_table
[1].port_node
= scan
.kbnode
;
2637 sunserial_setinitfunc(memory_start
, su_kbd_ms_init
);
2638 rs_ops
.rs_change_mouse_baud
= su_change_mouse_baud
;
2639 sunkbd_setinitfunc(memory_start
, sun_kbd_init
);
2640 kbd_ops
.compute_shiftstate
= sun_compute_shiftstate
;
2641 kbd_ops
.setledstate
= sun_setledstate
;
2642 kbd_ops
.getledstate
= sun_getledstate
;
2643 kbd_ops
.setkeycode
= sun_setkeycode
;
2644 kbd_ops
.getkeycode
= sun_getkeycode
;
2646 sunkbd_install_keymaps(memory_start
, sun_key_maps
,
2647 sun_keymap_count
, sun_func_buf
, sun_func_table
,
2648 sun_funcbufsize
, sun_funcbufleft
,
2649 sun_accent_table
, sun_accent_table_size
);
2653 if (scan
.msx
!= -1 || scan
.kbx
!= -1) {
2654 printk("su_probe: cannot match keyboard and mouse, confused\n");
2658 if (scan
.devices
== 0)
2661 #ifdef CONFIG_SERIAL_CONSOLE
2663 * Console must be initiated after the generic initialization.
2664 * sunserial_setinitfunc inverts order, so call this before next one.
2666 sunserial_setinitfunc(memory_start
, su_serial_console_init
);
2668 sunserial_setinitfunc(memory_start
, su_serial_init
);
2673 * ------------------------------------------------------------
2674 * Serial console driver
2675 * ------------------------------------------------------------
2677 #ifdef CONFIG_SERIAL_CONSOLE
2679 #define BOTH_EMPTY (UART_LSR_TEMT | UART_LSR_THRE)
2682 * Wait for transmitter & holding register to empty
2684 static __inline__
void
2685 wait_for_xmitr(struct su_struct
*info
)
2688 unsigned int tmout
= 1000000;
2691 lsr
= su_inb(info
, UART_LSR
);
2694 } while ((lsr
& BOTH_EMPTY
) != BOTH_EMPTY
);
2698 * Print a string to the serial port trying not to disturb
2699 * any possible real use of the port...
2702 serial_console_write(struct console
*co
, const char *s
,
2705 struct su_struct
*info
;
2709 info
= su_table
+ co
->index
;
2711 * First save the IER then disable the interrupts
2713 ier
= su_inb(info
, UART_IER
);
2714 su_outb(info
, UART_IER
, 0x00);
2717 * Now, do each character
2719 for (i
= 0; i
< count
; i
++, s
++) {
2720 wait_for_xmitr(info
);
2723 * Send the character out.
2724 * If a LF, also do CR...
2726 su_outb(info
, UART_TX
, *s
);
2728 wait_for_xmitr(info
);
2729 su_outb(info
, UART_TX
, 13);
2734 * Finally, Wait for transmitter & holding register to empty
2735 * and restore the IER
2737 wait_for_xmitr(info
);
2738 su_outb(info
, UART_IER
, ier
);
2742 * Receive character from the serial port
2745 serial_console_wait_key(struct console
*co
)
2747 struct su_struct
*info
;
2752 info
= su_table
+ co
->index
;
2755 * First save the IER then disable the interrupts so
2756 * that the real driver for the port does not get the
2759 ier
= su_inb(info
, UART_IER
);
2760 su_outb(info
, UART_IER
, 0x00);
2763 lsr
= su_inb(info
, UART_LSR
);
2764 } while (!(lsr
& UART_LSR_DR
));
2765 c
= su_inb(info
, UART_RX
);
2768 * Restore the interrupts
2770 su_outb(info
, UART_IER
, ier
);
2776 serial_console_device(struct console
*c
)
2778 return MKDEV(TTY_MAJOR
, 64 + c
->index
);
2782 * Setup initial baud/bits/parity. We do two things here:
2783 * - construct a cflag setting for the first su_open()
2784 * - initialize the serial port
2785 * Return non-zero if we didn't find a serial port.
2787 static int __init
serial_console_setup(struct console
*co
, char *options
)
2789 struct su_struct
*info
;
2794 int cflag
= CREAD
| HUPCL
| CLOCAL
;
2799 baud
= simple_strtoul(options
, NULL
, 10);
2801 while(*s
>= '0' && *s
<= '9')
2803 if (*s
) parity
= *s
++;
2804 if (*s
) bits
= *s
- '0';
2808 * Now construct a cflag setting.
2857 * Divisor, bytesize and parity
2859 info
= su_table
+ co
->index
;
2860 quot
= BAUD_BASE
/ baud
;
2861 cval
= cflag
& (CSIZE
| CSTOPB
);
2862 #if defined(__powerpc__) || defined(__alpha__)
2864 #else /* !__powerpc__ && !__alpha__ */
2866 #endif /* !__powerpc__ && !__alpha__ */
2868 cval
|= UART_LCR_PARITY
;
2869 if (!(cflag
& PARODD
))
2870 cval
|= UART_LCR_EPAR
;
2873 * Disable UART interrupts, set DTR and RTS high
2876 su_outb(info
, UART_IER
, 0);
2877 su_outb(info
, UART_MCR
, UART_MCR_DTR
| UART_MCR_RTS
);
2878 su_outb(info
, UART_LCR
, cval
| UART_LCR_DLAB
); /* set DLAB */
2879 su_outb(info
, UART_DLL
, quot
& 0xff); /* LS of divisor */
2880 su_outb(info
, UART_DLM
, quot
>> 8); /* MS of divisor */
2881 su_outb(info
, UART_LCR
, cval
); /* reset DLAB */
2885 * If we read 0xff from the LSR, there is no UART here.
2887 if (su_inb(info
, UART_LSR
) == 0xff)
2893 static struct console sercons
= {
2895 serial_console_write
,
2897 serial_console_device
,
2898 serial_console_wait_key
,
2900 serial_console_setup
,
2910 int __init
su_serial_console_init(void)
2912 extern int con_is_present(void);
2914 if (con_is_present())
2916 if (serial_console
== 0)
2918 if (su_table
[0].port
== 0 || su_table
[0].port_node
== 0)
2921 register_console(&sercons
);
2925 #endif /* CONFIG_SERIAL_CONSOLE */