1 /* $Id: su.c,v 1.19 1999/05/12 11:15:14 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 * Coypright (C) 1998 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);
96 * serial.c saves memory when it allocates async_info upon first open.
97 * We have parts of state structure together because we do call startup
98 * for keyboard and mouse.
104 int type
; /* Hardware type: e.g. 16550 */
118 unsigned short close_delay
;
119 unsigned short closing_wait
; /* time to wait before closing */
121 struct tty_struct
*tty
;
122 int read_status_mask
;
123 int ignore_status_mask
;
126 int x_char
; /* xon/xoff character */
127 int IER
; /* Interrupt Enable Register */
128 int MCR
; /* Modem control register */
130 int blocked_open
; /* # of blocked opens */
131 long session
; /* Session of opening process */
132 long pgrp
; /* pgrp of opening process */
133 unsigned char *xmit_buf
;
137 struct tq_struct tqueue
;
138 wait_queue_head_t open_wait
;
139 wait_queue_head_t close_wait
;
140 wait_queue_head_t delta_msr_wait
;
143 struct async_icount icount
;
144 struct termios normal_termios
, callout_termios
;
145 unsigned long last_active
; /* For async_struct, to be */
148 static char *serial_name
= "PCIO serial driver";
149 static char serial_version
[16];
151 static DECLARE_TASK_QUEUE(tq_serial
);
153 static struct tty_driver serial_driver
, callout_driver
;
154 static int serial_refcount
;
156 /* number of characters left in xmit buffer before we ask for more */
157 #define WAKEUP_CHARS 256
159 static void autoconfig(struct su_struct
*info
);
160 static void change_speed(struct su_struct
*info
, struct termios
*old
);
161 static void su_wait_until_sent(struct tty_struct
*tty
, int timeout
);
164 * Here we define the default xmit fifo size used for each type of
167 static struct serial_uart_config uart_config
[] = {
172 { "16550A", 16, UART_CLEAR_FIFO
| UART_USE_FIFO
},
174 { "ST16650", 1, UART_CLEAR_FIFO
|UART_STARTECH
},
175 { "ST16650V2", 32, UART_CLEAR_FIFO
| UART_USE_FIFO
|
177 { "TI16750", 64, UART_CLEAR_FIFO
| UART_USE_FIFO
},
184 static struct su_struct su_table
[NR_PORTS
];
185 static struct tty_struct
*serial_table
[NR_PORTS
];
186 static struct termios
*serial_termios
[NR_PORTS
];
187 static struct termios
*serial_termios_locked
[NR_PORTS
];
190 #define MIN(a,b) ((a) < (b) ? (a) : (b))
194 * tmp_buf is used as a temporary buffer by serial_write. We need to
195 * lock it in case the copy_from_user blocks while swapping in a page,
196 * and some other program tries to do a serial write at the same time.
197 * Since the lock will only come under contention when the system is
198 * swapping and available memory is low, it makes sense to share one
199 * buffer across all the serial ports, since it significantly saves
200 * memory if large numbers of serial ports are open.
202 static unsigned char *tmp_buf
;
203 static DECLARE_MUTEX(tmp_buf_sem
);
205 static inline int serial_paranoia_check(struct su_struct
*info
,
206 kdev_t device
, const char *routine
)
208 #ifdef SERIAL_PARANOIA_CHECK
209 static const char *badmagic
=
210 "Warning: bad magic number for serial struct (%s) in %s\n";
211 static const char *badinfo
=
212 "Warning: null su_struct for (%s) in %s\n";
215 printk(badinfo
, kdevname(device
), routine
);
218 if (info
->magic
!= SERIAL_MAGIC
) {
219 printk(badmagic
, kdevname(device
), routine
);
229 unsigned int su_inb(struct su_struct
*info
, unsigned long offset
)
231 return inb(info
->port
+ offset
);
235 su_outb(struct su_struct
*info
, unsigned long offset
, int value
)
237 outb(value
, info
->port
+ offset
);
243 unsigned int su_inb(struct su_struct
*info
, unsigned long offset
)
245 return (unsigned int)(*(volatile unsigned char *)(info
->port
+ offset
));
249 su_outb(struct su_struct
*info
, unsigned long offset
, int value
)
252 * MrCoffee has weird schematics: IRQ4 & P10(?) pins of SuperIO are
253 * connected with a gate then go to SlavIO. When IRQ4 goes tristated
254 * gate outputs a logical one. Since we use level triggered interrupts
255 * we have lockup and watchdog reset. We cannot mask IRQ because
256 * keyboard shares IRQ with us (Word has it as Bob Smelik's design).
257 * This problem is similar to what Alpha people suffer, see serial.c.
259 if (offset
== UART_MCR
) value
|= UART_MCR_OUT2
;
260 *(volatile unsigned char *)(info
->port
+ offset
) = value
;
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
->kbd_node
) {
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
->kbd_node
|| info
->ms_node
) {
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
->kbd_node
&& !info
->ms_node
) {
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
->kbd_node
)
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
;
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 current
->counter
= 0; /* make us low-priority */
1840 schedule_timeout(char_time
);
1841 if (signal_pending(current
))
1843 if (timeout
&& time_after(jiffies
, orig_jiffies
+ timeout
))
1846 current
->state
= TASK_RUNNING
;
1847 #ifdef SERIAL_DEBUG_RS_WAIT_UNTIL_SENT
1848 printk("lsr = %d (jiff=%lu)...done\n", lsr
, jiffies
);
1853 * su_hangup() --- called by tty_hangup() when a hangup is signaled.
1856 su_hangup(struct tty_struct
*tty
)
1858 struct su_struct
* info
= (struct su_struct
*)tty
->driver_data
;
1860 if (serial_paranoia_check(info
, tty
->device
, "su_hangup"))
1863 su_flush_buffer(tty
);
1867 info
->flags
&= ~(ASYNC_NORMAL_ACTIVE
|ASYNC_CALLOUT_ACTIVE
);
1869 wake_up_interruptible(&info
->open_wait
);
1873 * ------------------------------------------------------------
1874 * su_open() and friends
1875 * ------------------------------------------------------------
1878 block_til_ready(struct tty_struct
*tty
, struct file
* filp
,
1879 struct su_struct
*info
)
1881 DECLARE_WAITQUEUE(wait
, current
);
1883 int do_clocal
= 0, extra_count
= 0;
1884 unsigned long flags
;
1887 * If the device is in the middle of being closed, then block
1888 * until it's done, and then try again.
1890 if (tty_hung_up_p(filp
) ||
1891 (info
->flags
& ASYNC_CLOSING
)) {
1892 if (info
->flags
& ASYNC_CLOSING
)
1893 interruptible_sleep_on(&info
->close_wait
);
1894 #ifdef SERIAL_DO_RESTART
1895 return ((info
->flags
& ASYNC_HUP_NOTIFY
) ?
1896 -EAGAIN
: -ERESTARTSYS
);
1903 * If this is a callout device, then just make sure the normal
1904 * device isn't being used.
1906 if (tty
->driver
.subtype
== SERIAL_TYPE_CALLOUT
) {
1907 if (info
->flags
& ASYNC_NORMAL_ACTIVE
)
1909 if ((info
->flags
& ASYNC_CALLOUT_ACTIVE
) &&
1910 (info
->flags
& ASYNC_SESSION_LOCKOUT
) &&
1911 (info
->session
!= current
->session
))
1913 if ((info
->flags
& ASYNC_CALLOUT_ACTIVE
) &&
1914 (info
->flags
& ASYNC_PGRP_LOCKOUT
) &&
1915 (info
->pgrp
!= current
->pgrp
))
1917 info
->flags
|= ASYNC_CALLOUT_ACTIVE
;
1922 * If non-blocking mode is set, or the port is not enabled,
1923 * then make the check up front and then exit.
1925 if ((filp
->f_flags
& O_NONBLOCK
) ||
1926 (tty
->flags
& (1 << TTY_IO_ERROR
))) {
1927 if (info
->flags
& ASYNC_CALLOUT_ACTIVE
)
1929 info
->flags
|= ASYNC_NORMAL_ACTIVE
;
1933 if (info
->flags
& ASYNC_CALLOUT_ACTIVE
) {
1934 if (info
->normal_termios
.c_cflag
& CLOCAL
)
1937 if (tty
->termios
->c_cflag
& CLOCAL
)
1942 * Block waiting for the carrier detect and the line to become
1943 * free (i.e., not in use by the callout). While we are in
1944 * this loop, info->count is dropped by one, so that
1945 * su_close() knows when to free things. We restore it upon
1946 * exit, either normal or abnormal.
1949 add_wait_queue(&info
->open_wait
, &wait
);
1950 #ifdef SERIAL_DEBUG_OPEN
1951 printk("block_til_ready before block: ttys%d, count = %d\n",
1952 info
->line
, info
->count
);
1954 save_flags(flags
); cli();
1955 if (!tty_hung_up_p(filp
)) {
1959 restore_flags(flags
);
1960 info
->blocked_open
++;
1962 save_flags(flags
); cli();
1963 if (!(info
->flags
& ASYNC_CALLOUT_ACTIVE
) &&
1964 (tty
->termios
->c_cflag
& CBAUD
))
1965 serial_out(info
, UART_MCR
,
1966 serial_inp(info
, UART_MCR
) |
1967 (UART_MCR_DTR
| UART_MCR_RTS
));
1968 restore_flags(flags
);
1969 current
->state
= TASK_INTERRUPTIBLE
;
1970 if (tty_hung_up_p(filp
) ||
1971 !(info
->flags
& ASYNC_INITIALIZED
)) {
1972 #ifdef SERIAL_DO_RESTART
1973 if (info
->flags
& ASYNC_HUP_NOTIFY
)
1976 retval
= -ERESTARTSYS
;
1982 if (!(info
->flags
& ASYNC_CALLOUT_ACTIVE
) &&
1983 !(info
->flags
& ASYNC_CLOSING
) &&
1984 (do_clocal
|| (serial_in(info
, UART_MSR
) &
1987 if (signal_pending(current
)) {
1988 retval
= -ERESTARTSYS
;
1991 #ifdef SERIAL_DEBUG_OPEN
1992 printk("block_til_ready blocking: ttys%d, count = %d\n",
1993 info
->line
, info
->count
);
1997 current
->state
= TASK_RUNNING
;
1998 remove_wait_queue(&info
->open_wait
, &wait
);
2001 info
->blocked_open
--;
2002 #ifdef SERIAL_DEBUG_OPEN
2003 printk("block_til_ready after blocking: ttys%d, count = %d\n",
2004 info
->line
, info
->count
);
2008 info
->flags
|= ASYNC_NORMAL_ACTIVE
;
2013 * This routine is called whenever a serial port is opened. It
2014 * enables interrupts for a serial port, linking in its async structure into
2015 * the IRQ chain. It also performs the serial-specific
2016 * initialization for the tty structure.
2019 su_open(struct tty_struct
*tty
, struct file
* filp
)
2021 struct su_struct
*info
;
2025 line
= MINOR(tty
->device
) - tty
->driver
.minor_start
;
2026 if ((line
< 0) || (line
>= NR_PORTS
))
2028 info
= su_table
+ line
;
2030 tty
->driver_data
= info
;
2033 if (serial_paranoia_check(info
, tty
->device
, "su_open")) {
2038 #ifdef SERIAL_DEBUG_OPEN
2039 printk("su_open %s%d, count = %d\n", tty
->driver
.name
, info
->line
,
2042 info
->tty
->low_latency
= (info
->flags
& ASYNC_LOW_LATENCY
) ? 1 : 0;
2045 page
= get_free_page(GFP_KERNEL
);
2051 tmp_buf
= (unsigned char *) page
;
2055 * If the port is the middle of closing, bail out now
2057 if (tty_hung_up_p(filp
) ||
2058 (info
->flags
& ASYNC_CLOSING
)) {
2059 if (info
->flags
& ASYNC_CLOSING
)
2060 interruptible_sleep_on(&info
->close_wait
);
2061 #ifdef SERIAL_DO_RESTART
2062 return ((info
->flags
& ASYNC_HUP_NOTIFY
) ?
2063 -EAGAIN
: -ERESTARTSYS
);
2070 * Start up serial port
2072 retval
= startup(info
);
2077 retval
= block_til_ready(tty
, filp
, info
);
2079 #ifdef SERIAL_DEBUG_OPEN
2080 printk("su_open returning after block_til_ready with %d\n",
2086 if ((info
->count
== 1) &&
2087 (info
->flags
& ASYNC_SPLIT_TERMIOS
)) {
2088 if (tty
->driver
.subtype
== SERIAL_TYPE_NORMAL
)
2089 *tty
->termios
= info
->normal_termios
;
2091 *tty
->termios
= info
->callout_termios
;
2092 change_speed(info
, 0);
2094 #ifdef CONFIG_SERIAL_CONSOLE
2095 if (sercons
.cflag
&& sercons
.index
== line
) {
2096 tty
->termios
->c_cflag
= sercons
.cflag
;
2098 change_speed(info
, 0);
2101 info
->session
= current
->session
;
2102 info
->pgrp
= current
->pgrp
;
2104 #ifdef SERIAL_DEBUG_OPEN
2105 printk("su_open ttys%d successful...", info
->line
);
2111 * /proc fs routines....
2113 static __inline__
int
2114 line_info(char *buf
, struct su_struct
*info
)
2116 char stat_buf
[30], control
, status
;
2118 unsigned long flags
;
2120 ret
= sprintf(buf
, "%d: uart:%s port:%X irq:%s",
2121 info
->line
, uart_config
[info
->type
].name
,
2122 (int)info
->port
, __irq_itoa(info
->irq
));
2124 if (info
->port
== 0 || info
->type
== PORT_UNKNOWN
) {
2125 ret
+= sprintf(buf
+ret
, "\n");
2130 * Figure out the current RS-232 lines
2132 save_flags(flags
); cli();
2133 status
= serial_in(info
, UART_MSR
);
2134 control
= info
? info
->MCR
: serial_in(info
, UART_MCR
);
2135 restore_flags(flags
);
2139 if (control
& UART_MCR_RTS
)
2140 strcat(stat_buf
, "|RTS");
2141 if (status
& UART_MSR_CTS
)
2142 strcat(stat_buf
, "|CTS");
2143 if (control
& UART_MCR_DTR
)
2144 strcat(stat_buf
, "|DTR");
2145 if (status
& UART_MSR_DSR
)
2146 strcat(stat_buf
, "|DSR");
2147 if (status
& UART_MSR_DCD
)
2148 strcat(stat_buf
, "|CD");
2149 if (status
& UART_MSR_RI
)
2150 strcat(stat_buf
, "|RI");
2153 ret
+= sprintf(buf
+ret
, " baud:%d",
2154 info
->baud_base
/ info
->quot
);
2157 ret
+= sprintf(buf
+ret
, " tx:%d rx:%d",
2158 info
->icount
.tx
, info
->icount
.rx
);
2160 if (info
->icount
.frame
)
2161 ret
+= sprintf(buf
+ret
, " fe:%d", info
->icount
.frame
);
2163 if (info
->icount
.parity
)
2164 ret
+= sprintf(buf
+ret
, " pe:%d", info
->icount
.parity
);
2166 if (info
->icount
.brk
)
2167 ret
+= sprintf(buf
+ret
, " brk:%d", info
->icount
.brk
);
2169 if (info
->icount
.overrun
)
2170 ret
+= sprintf(buf
+ret
, " oe:%d", info
->icount
.overrun
);
2173 * Last thing is the RS-232 status lines
2175 ret
+= sprintf(buf
+ret
, " %s\n", stat_buf
+1);
2179 int su_read_proc(char *page
, char **start
, off_t off
, int count
,
2180 int *eof
, void *data
)
2185 len
+= sprintf(page
, "serinfo:1.0 driver:%s\n", serial_version
);
2186 for (i
= 0; i
< NR_PORTS
&& len
< 4000; i
++) {
2187 len
+= line_info(page
+ len
, &su_table
[i
]);
2188 if (len
+begin
> off
+count
)
2190 if (len
+begin
< off
) {
2197 if (off
>= len
+begin
)
2199 *start
= page
+ (begin
-off
);
2200 return ((count
< begin
+len
-off
) ? count
: begin
+len
-off
);
2204 * ---------------------------------------------------------------------
2205 * su_init() and friends
2207 * su_init() is called at boot-time to initialize the serial driver.
2208 * ---------------------------------------------------------------------
2212 * This routine prints out the appropriate serial driver version
2213 * number, and identifies which options were configured into this
2216 __initfunc(static __inline__
void show_su_version(void))
2218 char *revision
= "$Revision: 1.19 $";
2221 version
= strchr(revision
, ' ');
2222 strcpy(serial_version
, ++version
);
2223 p
= strchr(serial_version
, ' ');
2225 printk(KERN_INFO
"%s version %s\n", serial_name
, serial_version
);
2229 * This routine is called by su_init() to initialize a specific serial
2230 * port. It determines what type of UART chip this serial port is
2231 * using: 8250, 16450, 16550, 16550A. The important question is
2232 * whether or not this UART is a 16550A, since this will determine
2233 * whether or not we can use its FIFO features.
2236 autoconfig(struct su_struct
*info
)
2238 unsigned char status1
, status2
, scratch
, scratch2
;
2240 struct linux_ebus_device
*dev
= 0;
2241 struct linux_ebus
*ebus
;
2243 struct linux_prom_registers reg0
;
2245 unsigned long flags
;
2248 for_each_ebus(ebus
) {
2249 for_each_ebusdev(dev
, ebus
) {
2250 if (!strncmp(dev
->prom_name
, "su", 2)) {
2251 if (dev
->prom_node
== info
->kbd_node
)
2253 if (dev
->prom_node
== info
->ms_node
)
2262 info
->port
= dev
->base_address
[0];
2263 if (check_region(info
->port
, 8))
2266 info
->irq
= dev
->irqs
[0];
2268 if (!info
->port_node
)
2271 if (prom_getproperty(info
->port_node
, "reg",
2272 (char *)®0
, sizeof(reg0
)) == -1) {
2273 prom_printf("su: no \"reg\" property\n");
2276 prom_apply_obio_ranges(®0
, 1);
2277 if ((info
->port
= (unsigned long) sparc_alloc_io(reg0
.phys_addr
,
2278 0, reg0
.reg_size
, "su-regs", reg0
.which_io
, 0)) == 0) {
2279 prom_printf("su: cannot map\n");
2283 * There is no intr property on MrCoffee, so hardwire it. Krups?
2285 info
->irq
= IRQ_4M(13);
2288 #ifdef DEBUG_SERIAL_OPEN
2289 printk("Found 'su' at %016lx IRQ %s\n", dev
->base_address
[0],
2290 __irq_itoa(dev
->irqs
[0]));
2293 info
->magic
= SERIAL_MAGIC
;
2295 save_flags(flags
); cli();
2298 * Do a simple existence test first; if we fail this, there's
2299 * no point trying anything else.
2301 * 0x80 is used as a nonsense port to prevent against false
2302 * positives due to ISA bus float. The assumption is that
2303 * 0x80 is a non-existent port; which should be safe since
2304 * include/asm/io.h also makes this assumption.
2306 scratch
= serial_inp(info
, UART_IER
);
2307 serial_outp(info
, UART_IER
, 0);
2308 scratch2
= serial_inp(info
, UART_IER
);
2309 serial_outp(info
, UART_IER
, scratch
);
2311 restore_flags(flags
);
2312 return; /* We failed; there's nothing here */
2315 #if 0 /* P3: This does not work on MrCoffee. OUT2 is 0x80 - should work... */
2316 scratch
= serial_inp(info
, UART_MCR
);
2317 serial_outp(info
, UART_MCR
, UART_MCR_LOOP
| scratch
);
2318 serial_outp(info
, UART_MCR
, UART_MCR_LOOP
| 0x0A);
2319 status1
= serial_inp(info
, UART_MSR
) & 0xF0;
2320 serial_outp(info
, UART_MCR
, scratch
);
2321 if (status1
!= 0x90) {
2322 restore_flags(flags
);
2327 scratch2
= serial_in(info
, UART_LCR
);
2328 serial_outp(info
, UART_LCR
, 0xBF); /* set up for StarTech test */
2329 serial_outp(info
, UART_EFR
, 0); /* EFR is the same as FCR */
2330 serial_outp(info
, UART_LCR
, 0);
2331 serial_outp(info
, UART_FCR
, UART_FCR_ENABLE_FIFO
);
2332 scratch
= serial_in(info
, UART_IIR
) >> 6;
2335 info
->type
= PORT_16450
;
2338 info
->type
= PORT_UNKNOWN
;
2341 info
->type
= PORT_16550
;
2344 info
->type
= PORT_16550A
;
2347 if (info
->type
== PORT_16550A
) {
2348 /* Check for Startech UART's */
2349 serial_outp(info
, UART_LCR
, scratch2
| UART_LCR_DLAB
);
2350 if (serial_in(info
, UART_EFR
) == 0) {
2351 info
->type
= PORT_16650
;
2353 serial_outp(info
, UART_LCR
, 0xBF);
2354 if (serial_in(info
, UART_EFR
) == 0)
2355 info
->type
= PORT_16650V2
;
2358 if (info
->type
== PORT_16550A
) {
2359 /* Check for TI 16750 */
2360 serial_outp(info
, UART_LCR
, scratch2
| UART_LCR_DLAB
);
2361 serial_outp(info
, UART_FCR
,
2362 UART_FCR_ENABLE_FIFO
| UART_FCR7_64BYTE
);
2363 scratch
= serial_in(info
, UART_IIR
) >> 5;
2365 serial_outp(info
, UART_LCR
, 0);
2366 serial_outp(info
, UART_FCR
, UART_FCR_ENABLE_FIFO
);
2367 scratch
= serial_in(info
, UART_IIR
) >> 5;
2369 info
->type
= PORT_16750
;
2371 serial_outp(info
, UART_FCR
, UART_FCR_ENABLE_FIFO
);
2373 serial_outp(info
, UART_LCR
, scratch2
);
2374 if (info
->type
== PORT_16450
) {
2375 scratch
= serial_in(info
, UART_SCR
);
2376 serial_outp(info
, UART_SCR
, 0xa5);
2377 status1
= serial_in(info
, UART_SCR
);
2378 serial_outp(info
, UART_SCR
, 0x5a);
2379 status2
= serial_in(info
, UART_SCR
);
2380 serial_outp(info
, UART_SCR
, scratch
);
2382 if ((status1
!= 0xa5) || (status2
!= 0x5a))
2383 info
->type
= PORT_8250
;
2385 info
->xmit_fifo_size
= uart_config
[info
->type
].dfl_xmit_fifo_size
;
2387 if (info
->type
== PORT_UNKNOWN
) {
2388 restore_flags(flags
);
2392 if (info
->kbd_node
|| info
->ms_node
)
2393 sprintf(info
->name
, "su(%s)", info
->ms_node
? "mouse" : "kbd");
2395 strcpy(info
->name
, "su(serial)");
2398 request_region(info
->port
, 8, info
->name
);
2404 serial_outp(info
, UART_MCR
, 0x00);
2405 serial_outp(info
, UART_FCR
, (UART_FCR_CLEAR_RCVR
|UART_FCR_CLEAR_XMIT
));
2406 (void)serial_in(info
, UART_RX
);
2407 serial_outp(info
, UART_IER
, 0x00);
2409 restore_flags(flags
);
2413 * The serial driver boot-time initialization code!
2415 __initfunc(int su_serial_init(void))
2418 struct su_struct
*info
;
2420 init_bh(SERIAL_BH
, do_serial_bh
);
2423 /* Initialize the tty_driver structure */
2425 memset(&serial_driver
, 0, sizeof(struct tty_driver
));
2426 serial_driver
.magic
= TTY_DRIVER_MAGIC
;
2427 serial_driver
.driver_name
= "su";
2428 serial_driver
.name
= "ttyS";
2429 serial_driver
.major
= TTY_MAJOR
;
2430 serial_driver
.minor_start
= 64;
2431 serial_driver
.num
= NR_PORTS
;
2432 serial_driver
.type
= TTY_DRIVER_TYPE_SERIAL
;
2433 serial_driver
.subtype
= SERIAL_TYPE_NORMAL
;
2434 serial_driver
.init_termios
= tty_std_termios
;
2435 serial_driver
.init_termios
.c_cflag
=
2436 B9600
| CS8
| CREAD
| HUPCL
| CLOCAL
;
2437 serial_driver
.flags
= TTY_DRIVER_REAL_RAW
;
2438 serial_driver
.refcount
= &serial_refcount
;
2439 serial_driver
.table
= serial_table
;
2440 serial_driver
.termios
= serial_termios
;
2441 serial_driver
.termios_locked
= serial_termios_locked
;
2443 serial_driver
.open
= su_open
;
2444 serial_driver
.close
= su_close
;
2445 serial_driver
.write
= su_write
;
2446 serial_driver
.put_char
= su_put_char
;
2447 serial_driver
.flush_chars
= su_flush_chars
;
2448 serial_driver
.write_room
= su_write_room
;
2449 serial_driver
.chars_in_buffer
= su_chars_in_buffer
;
2450 serial_driver
.flush_buffer
= su_flush_buffer
;
2451 serial_driver
.ioctl
= su_ioctl
;
2452 serial_driver
.throttle
= su_throttle
;
2453 serial_driver
.unthrottle
= su_unthrottle
;
2454 serial_driver
.send_xchar
= su_send_xchar
;
2455 serial_driver
.set_termios
= su_set_termios
;
2456 serial_driver
.stop
= su_stop
;
2457 serial_driver
.start
= su_start
;
2458 serial_driver
.hangup
= su_hangup
;
2459 serial_driver
.break_ctl
= su_break
;
2460 serial_driver
.wait_until_sent
= su_wait_until_sent
;
2461 serial_driver
.read_proc
= su_read_proc
;
2464 * The callout device is just like normal device except for
2465 * major number and the subtype code.
2467 callout_driver
= serial_driver
;
2468 callout_driver
.name
= "cua";
2469 callout_driver
.major
= TTYAUX_MAJOR
;
2470 callout_driver
.subtype
= SERIAL_TYPE_CALLOUT
;
2471 callout_driver
.read_proc
= 0;
2472 callout_driver
.proc_entry
= 0;
2474 if (tty_register_driver(&serial_driver
))
2475 panic("Couldn't register regular su\n");
2476 if (tty_register_driver(&callout_driver
))
2477 panic("Couldn't register callout su\n");
2479 for (i
= 0, info
= su_table
; i
< NR_PORTS
; i
++, info
++) {
2481 info
->type
= PORT_UNKNOWN
;
2482 info
->baud_base
= BAUD_BASE
;
2483 /* info->flags = 0; */
2484 info
->custom_divisor
= 0;
2485 info
->close_delay
= 5*HZ
/10;
2486 info
->closing_wait
= 30*HZ
;
2487 info
->callout_termios
= callout_driver
.init_termios
;
2488 info
->normal_termios
= serial_driver
.init_termios
;
2489 info
->icount
.cts
= info
->icount
.dsr
=
2490 info
->icount
.rng
= info
->icount
.dcd
= 0;
2491 info
->icount
.rx
= info
->icount
.tx
= 0;
2492 info
->icount
.frame
= info
->icount
.parity
= 0;
2493 info
->icount
.overrun
= info
->icount
.brk
= 0;
2494 info
->tqueue
.routine
= do_softint
;
2495 info
->tqueue
.data
= info
;
2496 info
->cflag
= serial_driver
.init_termios
.c_cflag
;
2499 if (info
->type
== PORT_UNKNOWN
)
2502 printk(KERN_INFO
"%s at %16lx (irq = %s) is a %s\n",
2503 info
->name
, info
->port
, __irq_itoa(info
->irq
),
2504 uart_config
[info
->type
].name
);
2510 __initfunc(int su_kbd_ms_init(void))
2513 struct su_struct
*info
;
2517 for (i
= 0, info
= su_table
; i
< 2; i
++, info
++) {
2519 info
->type
= PORT_UNKNOWN
;
2520 info
->baud_base
= BAUD_BASE
;
2523 info
->cflag
= B1200
| CS8
| CLOCAL
| CREAD
;
2525 info
->cflag
= B4800
| CS8
| CLOCAL
| CREAD
;
2528 if (info
->type
== PORT_UNKNOWN
)
2531 printk(KERN_INFO
"%s at %16lx (irq = %s) is a %s\n",
2532 info
->name
, info
->port
, __irq_itoa(info
->irq
),
2533 uart_config
[info
->type
].name
);
2537 keyboard_zsinit(su_put_char_kbd
);
2544 __initfunc(int su_probe (unsigned long *memory_start
))
2546 struct su_struct
*info
= su_table
;
2547 int node
, enode
, tnode
, sunode
;
2548 int kbnode
= 0, msnode
= 0;
2554 * Find su on MrCoffee. We return OK code if find any.
2555 * Then su_init finds every one and initializes them.
2556 * We do this early because MrCoffee got no aliases.
2558 node
= prom_getchild(prom_root_node
);
2559 if ((node
= prom_searchsiblings(node
, "obio")) != 0) {
2560 if ((sunode
= prom_getchild(node
)) != 0) {
2561 if ((sunode
= prom_searchsiblings(sunode
, "su")) != 0) {
2562 info
->port_node
= sunode
;
2563 #ifdef CONFIG_SERIAL_CONSOLE
2565 * Console must be initiated after the generic
2567 * sunserial_setinitfunc inverts order, so
2568 * call this before next one.
2570 sunserial_setinitfunc(memory_start
,
2571 su_serial_console_init
);
2573 sunserial_setinitfunc(memory_start
,
2581 * Get the nodes for keyboard and mouse from 'aliases'...
2583 node
= prom_getchild(prom_root_node
);
2584 node
= prom_searchsiblings(node
, "aliases");
2588 len
= prom_getproperty(node
, "keyboard", prop
, sizeof(prop
));
2591 kbnode
= prom_finddevice(prop
);
2596 len
= prom_getproperty(node
, "mouse", prop
, sizeof(prop
));
2599 msnode
= prom_finddevice(prop
);
2605 * Find matching EBus nodes...
2607 node
= prom_getchild(prom_root_node
);
2608 if ((node
= prom_searchsiblings(node
, "pci")) == 0) {
2609 return -ENODEV
; /* Plain sparc */
2613 * Check for SUNW,sabre on Ultra 5/10/AXi.
2615 len
= prom_getproperty(node
, "model", prop
, sizeof(prop
));
2616 if ((len
> 0) && !strncmp(prop
, "SUNW,sabre", len
)) {
2617 node
= prom_getchild(node
);
2618 node
= prom_searchsiblings(node
, "pci");
2622 * For each PCI bus...
2625 enode
= prom_getchild(node
);
2626 enode
= prom_searchsiblings(enode
, "ebus");
2629 * For each EBus on this PCI...
2632 sunode
= prom_getchild(enode
);
2633 tnode
= prom_searchsiblings(sunode
, "su");
2635 tnode
= prom_searchsiblings(sunode
, "su_pnp");
2639 * For each 'su' on this EBus...
2645 if (sunode
== kbnode
) {
2646 info
->kbd_node
= sunode
;
2650 if (sunode
== msnode
) {
2651 info
->ms_node
= sunode
;
2657 * Found everything we need?
2662 sunode
= prom_getsibling(sunode
);
2663 tnode
= prom_searchsiblings(sunode
, "su");
2665 tnode
= prom_searchsiblings(sunode
,
2669 enode
= prom_getsibling(enode
);
2670 enode
= prom_searchsiblings(enode
, "ebus");
2672 node
= prom_getsibling(node
);
2673 node
= prom_searchsiblings(node
, "pci");
2678 sunserial_setinitfunc(memory_start
, su_kbd_ms_init
);
2679 rs_ops
.rs_change_mouse_baud
= su_change_mouse_baud
;
2680 sunkbd_setinitfunc(memory_start
, sun_kbd_init
);
2681 kbd_ops
.compute_shiftstate
= sun_compute_shiftstate
;
2682 kbd_ops
.setledstate
= sun_setledstate
;
2683 kbd_ops
.getledstate
= sun_getledstate
;
2684 kbd_ops
.setkeycode
= sun_setkeycode
;
2685 kbd_ops
.getkeycode
= sun_getkeycode
;
2687 sunkbd_install_keymaps(memory_start
, sun_key_maps
, sun_keymap_count
,
2688 sun_func_buf
, sun_func_table
,
2689 sun_funcbufsize
, sun_funcbufleft
,
2690 sun_accent_table
, sun_accent_table_size
);
2696 * ------------------------------------------------------------
2697 * Serial console driver
2698 * ------------------------------------------------------------
2700 #ifdef CONFIG_SERIAL_CONSOLE
2702 #define BOTH_EMPTY (UART_LSR_TEMT | UART_LSR_THRE)
2705 * Wait for transmitter & holding register to empty
2707 static __inline__
void
2708 wait_for_xmitr(struct su_struct
*info
)
2711 unsigned int tmout
= 1000000;
2714 lsr
= su_inb(info
, UART_LSR
);
2717 } while ((lsr
& BOTH_EMPTY
) != BOTH_EMPTY
);
2721 * Print a string to the serial port trying not to disturb
2722 * any possible real use of the port...
2725 serial_console_write(struct console
*co
, const char *s
,
2728 struct su_struct
*info
;
2732 info
= su_table
+ co
->index
;
2734 * First save the IER then disable the interrupts
2736 ier
= su_inb(info
, UART_IER
);
2737 su_outb(info
, UART_IER
, 0x00);
2740 * Now, do each character
2742 for (i
= 0; i
< count
; i
++, s
++) {
2743 wait_for_xmitr(info
);
2746 * Send the character out.
2747 * If a LF, also do CR...
2749 su_outb(info
, UART_TX
, *s
);
2751 wait_for_xmitr(info
);
2752 su_outb(info
, UART_TX
, 13);
2757 * Finally, Wait for transmitter & holding register to empty
2758 * and restore the IER
2760 wait_for_xmitr(info
);
2761 su_outb(info
, UART_IER
, ier
);
2765 * Receive character from the serial port
2768 serial_console_wait_key(struct console
*co
)
2770 struct su_struct
*info
;
2775 info
= su_table
+ co
->index
;
2778 * First save the IER then disable the interrupts so
2779 * that the real driver for the port does not get the
2782 ier
= su_inb(info
, UART_IER
);
2783 su_outb(info
, UART_IER
, 0x00);
2786 lsr
= su_inb(info
, UART_LSR
);
2787 } while (!(lsr
& UART_LSR_DR
));
2788 c
= su_inb(info
, UART_RX
);
2791 * Restore the interrupts
2793 su_outb(info
, UART_IER
, ier
);
2799 serial_console_device(struct console
*c
)
2801 return MKDEV(TTY_MAJOR
, 64 + c
->index
);
2805 * Setup initial baud/bits/parity. We do two things here:
2806 * - construct a cflag setting for the first su_open()
2807 * - initialize the serial port
2808 * Return non-zero if we didn't find a serial port.
2810 __initfunc(static int serial_console_setup(struct console
*co
, char *options
))
2812 struct su_struct
*info
;
2817 int cflag
= CREAD
| HUPCL
| CLOCAL
;
2822 baud
= simple_strtoul(options
, NULL
, 10);
2824 while(*s
>= '0' && *s
<= '9')
2826 if (*s
) parity
= *s
++;
2827 if (*s
) bits
= *s
- '0';
2831 * Now construct a cflag setting.
2880 * Divisor, bytesize and parity
2882 info
= su_table
+ co
->index
;
2883 quot
= BAUD_BASE
/ baud
;
2884 cval
= cflag
& (CSIZE
| CSTOPB
);
2885 #if defined(__powerpc__) || defined(__alpha__)
2887 #else /* !__powerpc__ && !__alpha__ */
2889 #endif /* !__powerpc__ && !__alpha__ */
2891 cval
|= UART_LCR_PARITY
;
2892 if (!(cflag
& PARODD
))
2893 cval
|= UART_LCR_EPAR
;
2896 * Disable UART interrupts, set DTR and RTS high
2899 su_outb(info
, UART_IER
, 0);
2900 su_outb(info
, UART_MCR
, UART_MCR_DTR
| UART_MCR_RTS
);
2901 su_outb(info
, UART_LCR
, cval
| UART_LCR_DLAB
); /* set DLAB */
2902 su_outb(info
, UART_DLL
, quot
& 0xff); /* LS of divisor */
2903 su_outb(info
, UART_DLM
, quot
>> 8); /* MS of divisor */
2904 su_outb(info
, UART_LCR
, cval
); /* reset DLAB */
2908 * If we read 0xff from the LSR, there is no UART here.
2910 if (su_inb(info
, UART_LSR
) == 0xff)
2916 static struct console sercons
= {
2918 serial_console_write
,
2920 serial_console_device
,
2921 serial_console_wait_key
,
2923 serial_console_setup
,
2933 __initfunc(int su_serial_console_init(void))
2935 extern int con_is_present(void);
2937 if (con_is_present())
2939 if (serial_console
== 0)
2941 if (su_table
[0].port
== 0 || su_table
[0].port_node
== 0)
2944 register_console(&sercons
);
2948 #endif /* CONFIG_SERIAL_CONSOLE */