2 * Simulated Serial Driver (fake serial)
4 * This driver is mostly used for bringup purposes and will go away.
5 * It has a strong dependency on the system console. All outputs
6 * are rerouted to the same facility as the one used by printk which, in our
7 * case means sys_sim.c console (goes via the simulator). The code hereafter
8 * is completely leveraged from the serial.c driver.
10 * Copyright (C) 1999-2000, 2002-2003 Hewlett-Packard Co
11 * Stephane Eranian <eranian@hpl.hp.com>
12 * David Mosberger-Tang <davidm@hpl.hp.com>
14 * 02/04/00 D. Mosberger Merged in serial.c bug fixes in rs_close().
15 * 02/25/00 D. Mosberger Synced up with 2.3.99pre-5 version of serial.c.
16 * 07/30/02 D. Mosberger Replace sti()/cli() with explicit spinlocks & local irq masking
19 #include <linux/config.h>
20 #include <linux/init.h>
21 #include <linux/errno.h>
22 #include <linux/sched.h>
23 #include <linux/tty.h>
24 #include <linux/tty_flip.h>
25 #include <linux/major.h>
26 #include <linux/fcntl.h>
28 #include <linux/slab.h>
29 #include <linux/capability.h>
30 #include <linux/console.h>
31 #include <linux/module.h>
32 #include <linux/serial.h>
33 #include <linux/serialP.h>
34 #include <linux/sysrq.h>
37 #include <asm/hw_irq.h>
38 #include <asm/uaccess.h>
41 # include <linux/kdb.h>
44 #undef SIMSERIAL_DEBUG /* define this to get some debug information */
46 #define KEYBOARD_INTR 3 /* must match with simulator! */
48 #define NR_PORTS 1 /* only one port for now */
49 #define SERIAL_INLINE 1
52 #define _INLINE_ inline
55 #define IRQ_T(info) ((info->flags & ASYNC_SHARE_IRQ) ? SA_SHIRQ : SA_INTERRUPT)
57 #define SSC_GETCHAR 21
59 extern long ia64_ssc (long, long, long, long, int);
60 extern void ia64_ssc_connect_irq (long intr
, long irq
);
62 static char *serial_name
= "SimSerial driver";
63 static char *serial_version
= "0.6";
66 * This has been extracted from asm/serial.h. We need one eventually but
67 * I don't know exactly what we're going to put in it so just fake one
70 #define BASE_BAUD ( 1843200 / 16 )
72 #define STD_COM_FLAGS (ASYNC_BOOT_AUTOCONF | ASYNC_SKIP_TEST)
75 * Most of the values here are meaningless to this particular driver.
76 * However some values must be preserved for the code (leveraged from serial.c
79 * type must not be UNKNOWN
80 * So I picked arbitrary (guess from where?) values instead
82 static struct serial_state rs_table
[NR_PORTS
]={
83 /* UART CLK PORT IRQ FLAGS */
84 { 0, BASE_BAUD
, 0x3F8, 0, STD_COM_FLAGS
,0,PORT_16550
} /* ttyS0 */
88 * Just for the fun of it !
90 static struct serial_uart_config uart_config
[] = {
95 { "16550A", 16, UART_CLEAR_FIFO
| UART_USE_FIFO
},
97 { "ST16650", 1, UART_CLEAR_FIFO
| UART_STARTECH
},
98 { "ST16650V2", 32, UART_CLEAR_FIFO
| UART_USE_FIFO
|
100 { "TI16750", 64, UART_CLEAR_FIFO
| UART_USE_FIFO
},
104 struct tty_driver
*hp_simserial_driver
;
106 static struct async_struct
*IRQ_ports
[NR_IRQS
];
108 static struct console
*console
;
110 static unsigned char *tmp_buf
;
111 static DECLARE_MUTEX(tmp_buf_sem
);
113 extern struct console
*console_drivers
; /* from kernel/printk.c */
116 * ------------------------------------------------------------
117 * rs_stop() and rs_start()
119 * This routines are called before setting or resetting tty->stopped.
120 * They enable or disable transmitter interrupts, as necessary.
121 * ------------------------------------------------------------
123 static void rs_stop(struct tty_struct
*tty
)
125 #ifdef SIMSERIAL_DEBUG
126 printk("rs_stop: tty->stopped=%d tty->hw_stopped=%d tty->flow_stopped=%d\n",
127 tty
->stopped
, tty
->hw_stopped
, tty
->flow_stopped
);
132 static void rs_start(struct tty_struct
*tty
)
134 #ifdef SIMSERIAL_DEBUG
135 printk("rs_start: tty->stopped=%d tty->hw_stopped=%d tty->flow_stopped=%d\n",
136 tty
->stopped
, tty
->hw_stopped
, tty
->flow_stopped
);
140 static void receive_chars(struct tty_struct
*tty
, struct pt_regs
*regs
)
143 static unsigned char seen_esc
= 0;
145 while ( (ch
= ia64_ssc(0, 0, 0, 0, SSC_GETCHAR
)) ) {
146 if ( ch
== 27 && seen_esc
== 0 ) {
150 if ( seen_esc
==1 && ch
== 'O' ) {
153 } else if ( seen_esc
== 2 ) {
154 if ( ch
== 'P' ) /* F1 */
156 #ifdef CONFIG_MAGIC_SYSRQ
157 if ( ch
== 'S' ) { /* F4 */
159 ch
= ia64_ssc(0, 0, 0, 0,
162 handle_sysrq(ch
, regs
, NULL
);
171 if (tty_insert_flip_char(tty
, ch
, TTY_NORMAL
) == 0)
174 tty_flip_buffer_push(tty
);
178 * This is the serial driver's interrupt routine for a single port
180 static irqreturn_t
rs_interrupt_single(int irq
, void *dev_id
, struct pt_regs
* regs
)
182 struct async_struct
* info
;
185 * I don't know exactly why they don't use the dev_id opaque data
186 * pointer instead of this extra lookup table
188 info
= IRQ_ports
[irq
];
189 if (!info
|| !info
->tty
) {
190 printk(KERN_INFO
"simrs_interrupt_single: info|tty=0 info=%p problem\n", info
);
194 * pretty simple in our case, because we only get interrupts
197 receive_chars(info
->tty
, regs
);
202 * -------------------------------------------------------------------
203 * Here ends the serial interrupt routines.
204 * -------------------------------------------------------------------
209 * not really used in our situation so keep them commented out for now
211 static DECLARE_TASK_QUEUE(tq_serial
); /* used to be at the top of the file */
212 static void do_serial_bh(void)
214 run_task_queue(&tq_serial
);
215 printk(KERN_ERR
"do_serial_bh: called\n");
219 static void do_softint(void *private_
)
221 printk(KERN_ERR
"simserial: do_softint called\n");
224 static void rs_put_char(struct tty_struct
*tty
, unsigned char ch
)
226 struct async_struct
*info
= (struct async_struct
*)tty
->driver_data
;
229 if (!tty
|| !info
->xmit
.buf
) return;
231 local_irq_save(flags
);
232 if (CIRC_SPACE(info
->xmit
.head
, info
->xmit
.tail
, SERIAL_XMIT_SIZE
) == 0) {
233 local_irq_restore(flags
);
236 info
->xmit
.buf
[info
->xmit
.head
] = ch
;
237 info
->xmit
.head
= (info
->xmit
.head
+ 1) & (SERIAL_XMIT_SIZE
-1);
238 local_irq_restore(flags
);
241 static _INLINE_
void transmit_chars(struct async_struct
*info
, int *intr_done
)
247 local_irq_save(flags
);
250 char c
= info
->x_char
;
252 console
->write(console
, &c
, 1);
254 info
->state
->icount
.tx
++;
260 if (info
->xmit
.head
== info
->xmit
.tail
|| info
->tty
->stopped
|| info
->tty
->hw_stopped
) {
261 #ifdef SIMSERIAL_DEBUG
262 printk("transmit_chars: head=%d, tail=%d, stopped=%d\n",
263 info
->xmit
.head
, info
->xmit
.tail
, info
->tty
->stopped
);
268 * We removed the loop and try to do it in to chunks. We need
269 * 2 operations maximum because it's a ring buffer.
271 * First from current to tail if possible.
272 * Then from the beginning of the buffer until necessary
275 count
= min(CIRC_CNT(info
->xmit
.head
, info
->xmit
.tail
, SERIAL_XMIT_SIZE
),
276 SERIAL_XMIT_SIZE
- info
->xmit
.tail
);
277 console
->write(console
, info
->xmit
.buf
+info
->xmit
.tail
, count
);
279 info
->xmit
.tail
= (info
->xmit
.tail
+count
) & (SERIAL_XMIT_SIZE
-1);
282 * We have more at the beginning of the buffer
284 count
= CIRC_CNT(info
->xmit
.head
, info
->xmit
.tail
, SERIAL_XMIT_SIZE
);
286 console
->write(console
, info
->xmit
.buf
, count
);
287 info
->xmit
.tail
+= count
;
290 local_irq_restore(flags
);
293 static void rs_flush_chars(struct tty_struct
*tty
)
295 struct async_struct
*info
= (struct async_struct
*)tty
->driver_data
;
297 if (info
->xmit
.head
== info
->xmit
.tail
|| tty
->stopped
|| tty
->hw_stopped
||
301 transmit_chars(info
, NULL
);
305 static int rs_write(struct tty_struct
* tty
,
306 const unsigned char *buf
, int count
)
309 struct async_struct
*info
= (struct async_struct
*)tty
->driver_data
;
312 if (!tty
|| !info
->xmit
.buf
|| !tmp_buf
) return 0;
314 local_irq_save(flags
);
316 c
= CIRC_SPACE_TO_END(info
->xmit
.head
, info
->xmit
.tail
, SERIAL_XMIT_SIZE
);
322 memcpy(info
->xmit
.buf
+ info
->xmit
.head
, buf
, c
);
323 info
->xmit
.head
= ((info
->xmit
.head
+ c
) &
324 (SERIAL_XMIT_SIZE
-1));
329 local_irq_restore(flags
);
331 * Hey, we transmit directly from here in our case
333 if (CIRC_CNT(info
->xmit
.head
, info
->xmit
.tail
, SERIAL_XMIT_SIZE
)
334 && !tty
->stopped
&& !tty
->hw_stopped
) {
335 transmit_chars(info
, NULL
);
340 static int rs_write_room(struct tty_struct
*tty
)
342 struct async_struct
*info
= (struct async_struct
*)tty
->driver_data
;
344 return CIRC_SPACE(info
->xmit
.head
, info
->xmit
.tail
, SERIAL_XMIT_SIZE
);
347 static int rs_chars_in_buffer(struct tty_struct
*tty
)
349 struct async_struct
*info
= (struct async_struct
*)tty
->driver_data
;
351 return CIRC_CNT(info
->xmit
.head
, info
->xmit
.tail
, SERIAL_XMIT_SIZE
);
354 static void rs_flush_buffer(struct tty_struct
*tty
)
356 struct async_struct
*info
= (struct async_struct
*)tty
->driver_data
;
359 local_irq_save(flags
);
360 info
->xmit
.head
= info
->xmit
.tail
= 0;
361 local_irq_restore(flags
);
363 wake_up_interruptible(&tty
->write_wait
);
365 if ((tty
->flags
& (1 << TTY_DO_WRITE_WAKEUP
)) &&
366 tty
->ldisc
.write_wakeup
)
367 (tty
->ldisc
.write_wakeup
)(tty
);
371 * This function is used to send a high-priority XON/XOFF character to
374 static void rs_send_xchar(struct tty_struct
*tty
, char ch
)
376 struct async_struct
*info
= (struct async_struct
*)tty
->driver_data
;
381 * I guess we could call console->write() directly but
382 * let's do that for now.
384 transmit_chars(info
, NULL
);
389 * ------------------------------------------------------------
392 * This routine is called by the upper-layer tty layer to signal that
393 * incoming characters should be throttled.
394 * ------------------------------------------------------------
396 static void rs_throttle(struct tty_struct
* tty
)
398 if (I_IXOFF(tty
)) rs_send_xchar(tty
, STOP_CHAR(tty
));
400 printk(KERN_INFO
"simrs_throttle called\n");
403 static void rs_unthrottle(struct tty_struct
* tty
)
405 struct async_struct
*info
= (struct async_struct
*)tty
->driver_data
;
411 rs_send_xchar(tty
, START_CHAR(tty
));
413 printk(KERN_INFO
"simrs_unthrottle called\n");
417 * rs_break() --- routine which turns the break handling on or off
419 static void rs_break(struct tty_struct
*tty
, int break_state
)
423 static int rs_ioctl(struct tty_struct
*tty
, struct file
* file
,
424 unsigned int cmd
, unsigned long arg
)
426 if ((cmd
!= TIOCGSERIAL
) && (cmd
!= TIOCSSERIAL
) &&
427 (cmd
!= TIOCSERCONFIG
) && (cmd
!= TIOCSERGSTRUCT
) &&
428 (cmd
!= TIOCMIWAIT
) && (cmd
!= TIOCGICOUNT
)) {
429 if (tty
->flags
& (1 << TTY_IO_ERROR
))
435 printk(KERN_INFO
"rs_ioctl: TIOCMGET called\n");
440 printk(KERN_INFO
"rs_ioctl: TIOCMBIS/BIC/SET called\n");
443 printk(KERN_INFO
"simrs_ioctl TIOCGSERIAL called\n");
446 printk(KERN_INFO
"simrs_ioctl TIOCSSERIAL called\n");
449 printk(KERN_INFO
"rs_ioctl: TIOCSERCONFIG called\n");
452 case TIOCSERGETLSR
: /* Get line status register */
453 printk(KERN_INFO
"rs_ioctl: TIOCSERGETLSR called\n");
457 printk(KERN_INFO
"rs_ioctl: TIOCSERGSTRUCT called\n");
459 if (copy_to_user((struct async_struct
*) arg
,
460 info
, sizeof(struct async_struct
)))
466 * Wait for any of the 4 modem inputs (DCD,RI,DSR,CTS) to change
467 * - mask passed in arg for lines of interest
468 * (use |'ed TIOCM_RNG/DSR/CD/CTS for masking)
469 * Caller should use TIOCGICOUNT to see which one it was
472 printk(KERN_INFO
"rs_ioctl: TIOCMIWAIT: called\n");
475 * Get counter of input serial line interrupts (DCD,RI,DSR,CTS)
476 * Return: write counters to the user passed counter struct
477 * NB: both 1->0 and 0->1 transitions are counted except for
478 * RI where only 0->1 is counted.
481 printk(KERN_INFO
"rs_ioctl: TIOCGICOUNT called\n");
486 /* "setserial -W" is called in Debian boot */
487 printk (KERN_INFO
"TIOCSER?WILD ioctl obsolete, ignored.\n");
496 #define RELEVANT_IFLAG(iflag) (iflag & (IGNBRK|BRKINT|IGNPAR|PARMRK|INPCK))
498 static void rs_set_termios(struct tty_struct
*tty
, struct termios
*old_termios
)
500 unsigned int cflag
= tty
->termios
->c_cflag
;
502 if ( (cflag
== old_termios
->c_cflag
)
503 && ( RELEVANT_IFLAG(tty
->termios
->c_iflag
)
504 == RELEVANT_IFLAG(old_termios
->c_iflag
)))
508 /* Handle turning off CRTSCTS */
509 if ((old_termios
->c_cflag
& CRTSCTS
) &&
510 !(tty
->termios
->c_cflag
& CRTSCTS
)) {
516 * This routine will shutdown a serial port; interrupts are disabled, and
517 * DTR is dropped if the hangup on close termio flag is on.
519 static void shutdown(struct async_struct
* info
)
522 struct serial_state
*state
;
525 if (!(info
->flags
& ASYNC_INITIALIZED
)) return;
529 #ifdef SIMSERIAL_DEBUG
530 printk("Shutting down serial port %d (irq %d)....", info
->line
,
534 local_irq_save(flags
);
537 * First unlink the serial port from the IRQ chain...
540 info
->next_port
->prev_port
= info
->prev_port
;
542 info
->prev_port
->next_port
= info
->next_port
;
544 IRQ_ports
[state
->irq
] = info
->next_port
;
547 * Free the IRQ, if necessary
549 if (state
->irq
&& (!IRQ_ports
[state
->irq
] ||
550 !IRQ_ports
[state
->irq
]->next_port
)) {
551 if (IRQ_ports
[state
->irq
]) {
552 free_irq(state
->irq
, NULL
);
553 retval
= request_irq(state
->irq
, rs_interrupt_single
,
554 IRQ_T(info
), "serial", NULL
);
557 printk(KERN_ERR
"serial shutdown: request_irq: error %d"
558 " Couldn't reacquire IRQ.\n", retval
);
560 free_irq(state
->irq
, NULL
);
563 if (info
->xmit
.buf
) {
564 free_page((unsigned long) info
->xmit
.buf
);
568 if (info
->tty
) set_bit(TTY_IO_ERROR
, &info
->tty
->flags
);
570 info
->flags
&= ~ASYNC_INITIALIZED
;
572 local_irq_restore(flags
);
576 * ------------------------------------------------------------
579 * This routine is called when the serial port gets closed. First, we
580 * wait for the last remaining data to be sent. Then, we unlink its
581 * async structure from the interrupt chain if necessary, and we free
582 * that IRQ if nothing is left in the chain.
583 * ------------------------------------------------------------
585 static void rs_close(struct tty_struct
*tty
, struct file
* filp
)
587 struct async_struct
* info
= (struct async_struct
*)tty
->driver_data
;
588 struct serial_state
*state
;
595 local_irq_save(flags
);
596 if (tty_hung_up_p(filp
)) {
597 #ifdef SIMSERIAL_DEBUG
598 printk("rs_close: hung_up\n");
600 local_irq_restore(flags
);
603 #ifdef SIMSERIAL_DEBUG
604 printk("rs_close ttys%d, count = %d\n", info
->line
, state
->count
);
606 if ((tty
->count
== 1) && (state
->count
!= 1)) {
608 * Uh, oh. tty->count is 1, which means that the tty
609 * structure will be freed. state->count should always
610 * be one in these conditions. If it's greater than
611 * one, we've got real problems, since it means the
612 * serial port won't be shutdown.
614 printk(KERN_ERR
"rs_close: bad serial port count; tty->count is 1, "
615 "state->count is %d\n", state
->count
);
618 if (--state
->count
< 0) {
619 printk(KERN_ERR
"rs_close: bad serial port count for ttys%d: %d\n",
620 info
->line
, state
->count
);
624 local_irq_restore(flags
);
627 info
->flags
|= ASYNC_CLOSING
;
628 local_irq_restore(flags
);
631 * Now we wait for the transmit buffer to clear; and we notify
632 * the line discipline to only process XON/XOFF characters.
635 if (tty
->driver
->flush_buffer
) tty
->driver
->flush_buffer(tty
);
636 if (tty
->ldisc
.flush_buffer
) tty
->ldisc
.flush_buffer(tty
);
639 if (info
->blocked_open
) {
640 if (info
->close_delay
)
641 schedule_timeout_interruptible(info
->close_delay
);
642 wake_up_interruptible(&info
->open_wait
);
644 info
->flags
&= ~(ASYNC_NORMAL_ACTIVE
|ASYNC_CLOSING
);
645 wake_up_interruptible(&info
->close_wait
);
649 * rs_wait_until_sent() --- wait until the transmitter is empty
651 static void rs_wait_until_sent(struct tty_struct
*tty
, int timeout
)
657 * rs_hangup() --- called by tty_hangup() when a hangup is signaled.
659 static void rs_hangup(struct tty_struct
*tty
)
661 struct async_struct
* info
= (struct async_struct
*)tty
->driver_data
;
662 struct serial_state
*state
= info
->state
;
664 #ifdef SIMSERIAL_DEBUG
665 printk("rs_hangup: called\n");
670 rs_flush_buffer(tty
);
671 if (info
->flags
& ASYNC_CLOSING
)
677 info
->flags
&= ~ASYNC_NORMAL_ACTIVE
;
679 wake_up_interruptible(&info
->open_wait
);
683 static int get_async_struct(int line
, struct async_struct
**ret_info
)
685 struct async_struct
*info
;
686 struct serial_state
*sstate
;
688 sstate
= rs_table
+ line
;
691 *ret_info
= sstate
->info
;
694 info
= kmalloc(sizeof(struct async_struct
), GFP_KERNEL
);
699 memset(info
, 0, sizeof(struct async_struct
));
700 init_waitqueue_head(&info
->open_wait
);
701 init_waitqueue_head(&info
->close_wait
);
702 init_waitqueue_head(&info
->delta_msr_wait
);
703 info
->magic
= SERIAL_MAGIC
;
704 info
->port
= sstate
->port
;
705 info
->flags
= sstate
->flags
;
706 info
->xmit_fifo_size
= sstate
->xmit_fifo_size
;
708 INIT_WORK(&info
->work
, do_softint
, info
);
709 info
->state
= sstate
;
712 *ret_info
= sstate
->info
;
715 *ret_info
= sstate
->info
= info
;
720 startup(struct async_struct
*info
)
724 irqreturn_t (*handler
)(int, void *, struct pt_regs
*);
725 struct serial_state
*state
= info
->state
;
728 page
= get_zeroed_page(GFP_KERNEL
);
732 local_irq_save(flags
);
734 if (info
->flags
& ASYNC_INITIALIZED
) {
739 if (!state
->port
|| !state
->type
) {
740 if (info
->tty
) set_bit(TTY_IO_ERROR
, &info
->tty
->flags
);
747 info
->xmit
.buf
= (unsigned char *) page
;
749 #ifdef SIMSERIAL_DEBUG
750 printk("startup: ttys%d (irq %d)...", info
->line
, state
->irq
);
754 * Allocate the IRQ if necessary
756 if (state
->irq
&& (!IRQ_ports
[state
->irq
] ||
757 !IRQ_ports
[state
->irq
]->next_port
)) {
758 if (IRQ_ports
[state
->irq
]) {
762 handler
= rs_interrupt_single
;
764 retval
= request_irq(state
->irq
, handler
, IRQ_T(info
), "simserial", NULL
);
766 if (capable(CAP_SYS_ADMIN
)) {
768 set_bit(TTY_IO_ERROR
,
777 * Insert serial port into IRQ chain.
780 info
->next_port
= IRQ_ports
[state
->irq
];
782 info
->next_port
->prev_port
= info
;
783 IRQ_ports
[state
->irq
] = info
;
785 if (info
->tty
) clear_bit(TTY_IO_ERROR
, &info
->tty
->flags
);
787 info
->xmit
.head
= info
->xmit
.tail
= 0;
791 * Set up serial timers...
793 timer_table
[RS_TIMER
].expires
= jiffies
+ 2*HZ
/100;
794 timer_active
|= 1 << RS_TIMER
;
798 * Set up the tty->alt_speed kludge
801 if ((info
->flags
& ASYNC_SPD_MASK
) == ASYNC_SPD_HI
)
802 info
->tty
->alt_speed
= 57600;
803 if ((info
->flags
& ASYNC_SPD_MASK
) == ASYNC_SPD_VHI
)
804 info
->tty
->alt_speed
= 115200;
805 if ((info
->flags
& ASYNC_SPD_MASK
) == ASYNC_SPD_SHI
)
806 info
->tty
->alt_speed
= 230400;
807 if ((info
->flags
& ASYNC_SPD_MASK
) == ASYNC_SPD_WARP
)
808 info
->tty
->alt_speed
= 460800;
811 info
->flags
|= ASYNC_INITIALIZED
;
812 local_irq_restore(flags
);
816 local_irq_restore(flags
);
822 * This routine is called whenever a serial port is opened. It
823 * enables interrupts for a serial port, linking in its async structure into
824 * the IRQ chain. It also performs the serial-specific
825 * initialization for the tty structure.
827 static int rs_open(struct tty_struct
*tty
, struct file
* filp
)
829 struct async_struct
*info
;
834 if ((line
< 0) || (line
>= NR_PORTS
))
836 retval
= get_async_struct(line
, &info
);
839 tty
->driver_data
= info
;
842 #ifdef SIMSERIAL_DEBUG
843 printk("rs_open %s, count = %d\n", tty
->name
, info
->state
->count
);
845 info
->tty
->low_latency
= (info
->flags
& ASYNC_LOW_LATENCY
) ? 1 : 0;
848 page
= get_zeroed_page(GFP_KERNEL
);
854 tmp_buf
= (unsigned char *) page
;
858 * If the port is the middle of closing, bail out now
860 if (tty_hung_up_p(filp
) ||
861 (info
->flags
& ASYNC_CLOSING
)) {
862 if (info
->flags
& ASYNC_CLOSING
)
863 interruptible_sleep_on(&info
->close_wait
);
864 #ifdef SERIAL_DO_RESTART
865 return ((info
->flags
& ASYNC_HUP_NOTIFY
) ?
866 -EAGAIN
: -ERESTARTSYS
);
873 * Start up serial port
875 retval
= startup(info
);
881 * figure out which console to use (should be one already)
883 console
= console_drivers
;
885 if ((console
->flags
& CON_ENABLED
) && console
->write
) break;
886 console
= console
->next
;
889 #ifdef SIMSERIAL_DEBUG
890 printk("rs_open ttys%d successful\n", info
->line
);
896 * /proc fs routines....
899 static inline int line_info(char *buf
, struct serial_state
*state
)
901 return sprintf(buf
, "%d: uart:%s port:%lX irq:%d\n",
902 state
->line
, uart_config
[state
->type
].name
,
903 state
->port
, state
->irq
);
906 static int rs_read_proc(char *page
, char **start
, off_t off
, int count
,
907 int *eof
, void *data
)
912 len
+= sprintf(page
, "simserinfo:1.0 driver:%s\n", serial_version
);
913 for (i
= 0; i
< NR_PORTS
&& len
< 4000; i
++) {
914 l
= line_info(page
+ len
, &rs_table
[i
]);
916 if (len
+begin
> off
+count
)
918 if (len
+begin
< off
) {
925 if (off
>= len
+begin
)
927 *start
= page
+ (begin
-off
);
928 return ((count
< begin
+len
-off
) ? count
: begin
+len
-off
);
932 * ---------------------------------------------------------------------
933 * rs_init() and friends
935 * rs_init() is called at boot-time to initialize the serial driver.
936 * ---------------------------------------------------------------------
940 * This routine prints out the appropriate serial driver version
941 * number, and identifies which options were configured into this
944 static inline void show_serial_version(void)
946 printk(KERN_INFO
"%s version %s with", serial_name
, serial_version
);
947 printk(KERN_INFO
" no serial options enabled\n");
950 static struct tty_operations hp_ops
= {
954 .put_char
= rs_put_char
,
955 .flush_chars
= rs_flush_chars
,
956 .write_room
= rs_write_room
,
957 .chars_in_buffer
= rs_chars_in_buffer
,
958 .flush_buffer
= rs_flush_buffer
,
960 .throttle
= rs_throttle
,
961 .unthrottle
= rs_unthrottle
,
962 .send_xchar
= rs_send_xchar
,
963 .set_termios
= rs_set_termios
,
967 .break_ctl
= rs_break
,
968 .wait_until_sent
= rs_wait_until_sent
,
969 .read_proc
= rs_read_proc
,
973 * The serial driver boot-time initialization code!
979 struct serial_state
*state
;
981 if (!ia64_platform_is("hpsim"))
984 hp_simserial_driver
= alloc_tty_driver(1);
985 if (!hp_simserial_driver
)
988 show_serial_version();
990 /* Initialize the tty_driver structure */
992 hp_simserial_driver
->owner
= THIS_MODULE
;
993 hp_simserial_driver
->driver_name
= "simserial";
994 hp_simserial_driver
->name
= "ttyS";
995 hp_simserial_driver
->major
= TTY_MAJOR
;
996 hp_simserial_driver
->minor_start
= 64;
997 hp_simserial_driver
->type
= TTY_DRIVER_TYPE_SERIAL
;
998 hp_simserial_driver
->subtype
= SERIAL_TYPE_NORMAL
;
999 hp_simserial_driver
->init_termios
= tty_std_termios
;
1000 hp_simserial_driver
->init_termios
.c_cflag
=
1001 B9600
| CS8
| CREAD
| HUPCL
| CLOCAL
;
1002 hp_simserial_driver
->flags
= TTY_DRIVER_REAL_RAW
;
1003 tty_set_operations(hp_simserial_driver
, &hp_ops
);
1006 * Let's have a little bit of fun !
1008 for (i
= 0, state
= rs_table
; i
< NR_PORTS
; i
++,state
++) {
1010 if (state
->type
== PORT_UNKNOWN
) continue;
1013 if ((rc
= assign_irq_vector(AUTO_ASSIGN
)) < 0)
1014 panic("%s: out of interrupt vectors!\n",
1017 ia64_ssc_connect_irq(KEYBOARD_INTR
, state
->irq
);
1020 printk(KERN_INFO
"ttyS%d at 0x%04lx (irq = %d) is a %s\n",
1022 state
->port
, state
->irq
,
1023 uart_config
[state
->type
].name
);
1026 if (tty_register_driver(hp_simserial_driver
))
1027 panic("Couldn't register simserial driver\n");
1033 __initcall(simrs_init
);