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/console.h>
30 #include <linux/module.h>
31 #include <linux/serial.h>
32 #include <linux/serialP.h>
35 #include <asm/hw_irq.h>
36 #include <asm/uaccess.h>
39 # include <linux/kdb.h>
42 #undef SIMSERIAL_DEBUG /* define this to get some debug information */
44 #define KEYBOARD_INTR 3 /* must match with simulator! */
46 #define NR_PORTS 1 /* only one port for now */
47 #define SERIAL_INLINE 1
50 #define _INLINE_ inline
54 #define MIN(a,b) ((a) < (b) ? (a) : (b))
57 #define IRQ_T(info) ((info->flags & ASYNC_SHARE_IRQ) ? SA_SHIRQ : SA_INTERRUPT)
59 #define SSC_GETCHAR 21
61 extern long ia64_ssc (long, long, long, long, int);
62 extern void ia64_ssc_connect_irq (long intr, long irq);
64 static char *serial_name = "SimSerial driver";
65 static char *serial_version = "0.6";
68 * This has been extracted from asm/serial.h. We need one eventually but
69 * I don't know exactly what we're going to put in it so just fake one
72 #define BASE_BAUD ( 1843200 / 16 )
74 #define STD_COM_FLAGS (ASYNC_BOOT_AUTOCONF | ASYNC_SKIP_TEST)
77 * Most of the values here are meaningless to this particular driver.
78 * However some values must be preserved for the code (leveraged from serial.c
81 * type must not be UNKNOWN
82 * So I picked arbitrary (guess from where?) values instead
84 static struct serial_state rs_table[NR_PORTS]={
85 /* UART CLK PORT IRQ FLAGS */
86 { 0, BASE_BAUD, 0x3F8, 0, STD_COM_FLAGS,0,PORT_16550 } /* ttyS0 */
90 * Just for the fun of it !
92 static struct serial_uart_config uart_config[] = {
97 { "16550A", 16, UART_CLEAR_FIFO | UART_USE_FIFO },
99 { "ST16650", 1, UART_CLEAR_FIFO | UART_STARTECH },
100 { "ST16650V2", 32, UART_CLEAR_FIFO | UART_USE_FIFO |
102 { "TI16750", 64, UART_CLEAR_FIFO | UART_USE_FIFO},
106 struct tty_driver hp_simserial_driver;
107 static struct tty_driver callout_driver;
108 static int serial_refcount;
110 static struct async_struct *IRQ_ports[NR_IRQS];
111 static struct tty_struct *serial_table[NR_PORTS];
112 static struct termios *serial_termios[NR_PORTS];
113 static struct termios *serial_termios_locked[NR_PORTS];
115 static struct console *console;
117 static unsigned char *tmp_buf;
118 static DECLARE_MUTEX(tmp_buf_sem);
120 extern struct console *console_drivers; /* from kernel/printk.c */
123 * ------------------------------------------------------------
124 * rs_stop() and rs_start()
126 * This routines are called before setting or resetting tty->stopped.
127 * They enable or disable transmitter interrupts, as necessary.
128 * ------------------------------------------------------------
130 static void rs_stop(struct tty_struct *tty)
132 #ifdef SIMSERIAL_DEBUG
133 printk("rs_stop: tty->stopped=%d tty->hw_stopped=%d tty->flow_stopped=%d\n",
134 tty->stopped, tty->hw_stopped, tty->flow_stopped);
139 static void rs_start(struct tty_struct *tty)
142 printk("rs_start: tty->stopped=%d tty->hw_stopped=%d tty->flow_stopped=%d\n",
143 tty->stopped, tty->hw_stopped, tty->flow_stopped);
147 static void receive_chars(struct tty_struct *tty, struct pt_regs *regs)
150 static unsigned char seen_esc = 0;
152 while ( (ch = ia64_ssc(0, 0, 0, 0, SSC_GETCHAR)) ) {
153 if ( ch == 27 && seen_esc == 0 ) {
157 if ( seen_esc==1 && ch == 'O' ) {
160 } else if ( seen_esc == 2 ) {
161 if ( ch == 'P' ) show_state(); /* F1 key */
164 kdb(KDB_REASON_KEYBOARD, 0, (kdb_eframe_t) regs);
172 if (tty->flip.count >= TTY_FLIPBUF_SIZE) break;
174 *tty->flip.char_buf_ptr = ch;
176 *tty->flip.flag_buf_ptr = 0;
178 tty->flip.flag_buf_ptr++;
179 tty->flip.char_buf_ptr++;
182 tty_flip_buffer_push(tty);
186 * This is the serial driver's interrupt routine for a single port
188 static irqreturn_t rs_interrupt_single(int irq, void *dev_id, struct pt_regs * regs)
190 struct async_struct * info;
193 * I don't know exactly why they don't use the dev_id opaque data
194 * pointer instead of this extra lookup table
196 info = IRQ_ports[irq];
197 if (!info || !info->tty) {
198 printk(KERN_INFO "simrs_interrupt_single: info|tty=0 info=%p problem\n", info);
202 * pretty simple in our case, because we only get interrupts
205 receive_chars(info->tty, regs);
210 * -------------------------------------------------------------------
211 * Here ends the serial interrupt routines.
212 * -------------------------------------------------------------------
217 * not really used in our situation so keep them commented out for now
219 static DECLARE_TASK_QUEUE(tq_serial); /* used to be at the top of the file */
220 static void do_serial_bh(void)
222 run_task_queue(&tq_serial);
223 printk(KERN_ERR "do_serial_bh: called\n");
227 static void do_softint(void *private_)
229 printk(KERN_ERR "simserial: do_softint called\n");
232 static void rs_put_char(struct tty_struct *tty, unsigned char ch)
234 struct async_struct *info = (struct async_struct *)tty->driver_data;
237 if (!tty || !info->xmit.buf) return;
239 local_irq_save(flags);
240 if (CIRC_SPACE(info->xmit.head, info->xmit.tail, SERIAL_XMIT_SIZE) == 0) {
241 local_irq_restore(flags);
244 info->xmit.buf[info->xmit.head] = ch;
245 info->xmit.head = (info->xmit.head + 1) & (SERIAL_XMIT_SIZE-1);
246 local_irq_restore(flags);
249 static _INLINE_ void transmit_chars(struct async_struct *info, int *intr_done)
255 local_irq_save(flags);
258 char c = info->x_char;
260 console->write(console, &c, 1);
262 info->state->icount.tx++;
268 if (info->xmit.head == info->xmit.tail || info->tty->stopped || info->tty->hw_stopped) {
269 #ifdef SIMSERIAL_DEBUG
270 printk("transmit_chars: head=%d, tail=%d, stopped=%d\n",
271 info->xmit.head, info->xmit.tail, info->tty->stopped);
276 * We removed the loop and try to do it in to chunks. We need
277 * 2 operations maximum because it's a ring buffer.
279 * First from current to tail if possible.
280 * Then from the beginning of the buffer until necessary
283 count = MIN(CIRC_CNT(info->xmit.head, info->xmit.tail, SERIAL_XMIT_SIZE),
284 SERIAL_XMIT_SIZE - info->xmit.tail);
285 console->write(console, info->xmit.buf+info->xmit.tail, count);
287 info->xmit.tail = (info->xmit.tail+count) & (SERIAL_XMIT_SIZE-1);
290 * We have more at the beginning of the buffer
292 count = CIRC_CNT(info->xmit.head, info->xmit.tail, SERIAL_XMIT_SIZE);
294 console->write(console, info->xmit.buf, count);
295 info->xmit.tail += count;
298 local_irq_restore(flags);
301 static void rs_flush_chars(struct tty_struct *tty)
303 struct async_struct *info = (struct async_struct *)tty->driver_data;
305 if (info->xmit.head == info->xmit.tail || tty->stopped || tty->hw_stopped ||
309 transmit_chars(info, NULL);
313 static int rs_write(struct tty_struct * tty, int from_user,
314 const unsigned char *buf, int count)
317 struct async_struct *info = (struct async_struct *)tty->driver_data;
320 if (!tty || !info->xmit.buf || !tmp_buf) return 0;
326 c = CIRC_SPACE_TO_END(info->xmit.head, info->xmit.tail, SERIAL_XMIT_SIZE);
332 c -= copy_from_user(tmp_buf, buf, c);
339 local_irq_save(flags);
341 c1 = CIRC_SPACE_TO_END(info->xmit.head, info->xmit.tail,
345 memcpy(info->xmit.buf + info->xmit.head, tmp_buf, c);
346 info->xmit.head = ((info->xmit.head + c) &
347 (SERIAL_XMIT_SIZE-1));
349 local_irq_restore(flags);
357 local_irq_save(flags);
359 c = CIRC_SPACE_TO_END(info->xmit.head, info->xmit.tail, SERIAL_XMIT_SIZE);
365 memcpy(info->xmit.buf + info->xmit.head, buf, c);
366 info->xmit.head = ((info->xmit.head + c) &
367 (SERIAL_XMIT_SIZE-1));
372 local_irq_restore(flags);
375 * Hey, we transmit directly from here in our case
377 if (CIRC_CNT(info->xmit.head, info->xmit.tail, SERIAL_XMIT_SIZE)
378 && !tty->stopped && !tty->hw_stopped) {
379 transmit_chars(info, NULL);
384 static int rs_write_room(struct tty_struct *tty)
386 struct async_struct *info = (struct async_struct *)tty->driver_data;
388 return CIRC_SPACE(info->xmit.head, info->xmit.tail, SERIAL_XMIT_SIZE);
391 static int rs_chars_in_buffer(struct tty_struct *tty)
393 struct async_struct *info = (struct async_struct *)tty->driver_data;
395 return CIRC_CNT(info->xmit.head, info->xmit.tail, SERIAL_XMIT_SIZE);
398 static void rs_flush_buffer(struct tty_struct *tty)
400 struct async_struct *info = (struct async_struct *)tty->driver_data;
403 local_irq_save(flags);
404 info->xmit.head = info->xmit.tail = 0;
405 local_irq_restore(flags);
407 wake_up_interruptible(&tty->write_wait);
409 if ((tty->flags & (1 << TTY_DO_WRITE_WAKEUP)) &&
410 tty->ldisc.write_wakeup)
411 (tty->ldisc.write_wakeup)(tty);
415 * This function is used to send a high-priority XON/XOFF character to
418 static void rs_send_xchar(struct tty_struct *tty, char ch)
420 struct async_struct *info = (struct async_struct *)tty->driver_data;
425 * I guess we could call console->write() directly but
426 * let's do that for now.
428 transmit_chars(info, NULL);
433 * ------------------------------------------------------------
436 * This routine is called by the upper-layer tty layer to signal that
437 * incoming characters should be throttled.
438 * ------------------------------------------------------------
440 static void rs_throttle(struct tty_struct * tty)
442 if (I_IXOFF(tty)) rs_send_xchar(tty, STOP_CHAR(tty));
444 printk(KERN_INFO "simrs_throttle called\n");
447 static void rs_unthrottle(struct tty_struct * tty)
449 struct async_struct *info = (struct async_struct *)tty->driver_data;
455 rs_send_xchar(tty, START_CHAR(tty));
457 printk(KERN_INFO "simrs_unthrottle called\n");
461 * rs_break() --- routine which turns the break handling on or off
463 static void rs_break(struct tty_struct *tty, int break_state)
467 static int rs_ioctl(struct tty_struct *tty, struct file * file,
468 unsigned int cmd, unsigned long arg)
470 if ((cmd != TIOCGSERIAL) && (cmd != TIOCSSERIAL) &&
471 (cmd != TIOCSERCONFIG) && (cmd != TIOCSERGSTRUCT) &&
472 (cmd != TIOCMIWAIT) && (cmd != TIOCGICOUNT)) {
473 if (tty->flags & (1 << TTY_IO_ERROR))
479 printk(KERN_INFO "rs_ioctl: TIOCMGET called\n");
484 printk(KERN_INFO "rs_ioctl: TIOCMBIS/BIC/SET called\n");
487 printk(KERN_INFO "simrs_ioctl TIOCGSERIAL called\n");
490 printk(KERN_INFO "simrs_ioctl TIOCSSERIAL called\n");
493 printk(KERN_INFO "rs_ioctl: TIOCSERCONFIG called\n");
496 case TIOCSERGETLSR: /* Get line status register */
497 printk(KERN_INFO "rs_ioctl: TIOCSERGETLSR called\n");
501 printk(KERN_INFO "rs_ioctl: TIOCSERGSTRUCT called\n");
503 if (copy_to_user((struct async_struct *) arg,
504 info, sizeof(struct async_struct)))
510 * Wait for any of the 4 modem inputs (DCD,RI,DSR,CTS) to change
511 * - mask passed in arg for lines of interest
512 * (use |'ed TIOCM_RNG/DSR/CD/CTS for masking)
513 * Caller should use TIOCGICOUNT to see which one it was
516 printk(KERN_INFO "rs_ioctl: TIOCMIWAIT: called\n");
519 * Get counter of input serial line interrupts (DCD,RI,DSR,CTS)
520 * Return: write counters to the user passed counter struct
521 * NB: both 1->0 and 0->1 transitions are counted except for
522 * RI where only 0->1 is counted.
525 printk(KERN_INFO "rs_ioctl: TIOCGICOUNT called\n");
530 /* "setserial -W" is called in Debian boot */
531 printk (KERN_INFO "TIOCSER?WILD ioctl obsolete, ignored.\n");
540 #define RELEVANT_IFLAG(iflag) (iflag & (IGNBRK|BRKINT|IGNPAR|PARMRK|INPCK))
542 static void rs_set_termios(struct tty_struct *tty, struct termios *old_termios)
544 unsigned int cflag = tty->termios->c_cflag;
546 if ( (cflag == old_termios->c_cflag)
547 && ( RELEVANT_IFLAG(tty->termios->c_iflag)
548 == RELEVANT_IFLAG(old_termios->c_iflag)))
552 /* Handle turning off CRTSCTS */
553 if ((old_termios->c_cflag & CRTSCTS) &&
554 !(tty->termios->c_cflag & CRTSCTS)) {
560 * This routine will shutdown a serial port; interrupts are disabled, and
561 * DTR is dropped if the hangup on close termio flag is on.
563 static void shutdown(struct async_struct * info)
566 struct serial_state *state;
569 if (!(info->flags & ASYNC_INITIALIZED)) return;
573 #ifdef SIMSERIAL_DEBUG
574 printk("Shutting down serial port %d (irq %d)....", info->line,
578 local_irq_save(flags);
581 * First unlink the serial port from the IRQ chain...
584 info->next_port->prev_port = info->prev_port;
586 info->prev_port->next_port = info->next_port;
588 IRQ_ports[state->irq] = info->next_port;
591 * Free the IRQ, if necessary
593 if (state->irq && (!IRQ_ports[state->irq] ||
594 !IRQ_ports[state->irq]->next_port)) {
595 if (IRQ_ports[state->irq]) {
596 free_irq(state->irq, NULL);
597 retval = request_irq(state->irq, rs_interrupt_single,
598 IRQ_T(info), "serial", NULL);
601 printk(KERN_ERR "serial shutdown: request_irq: error %d"
602 " Couldn't reacquire IRQ.\n", retval);
604 free_irq(state->irq, NULL);
607 if (info->xmit.buf) {
608 free_page((unsigned long) info->xmit.buf);
612 if (info->tty) set_bit(TTY_IO_ERROR, &info->tty->flags);
614 info->flags &= ~ASYNC_INITIALIZED;
616 local_irq_restore(flags);
620 * ------------------------------------------------------------
623 * This routine is called when the serial port gets closed. First, we
624 * wait for the last remaining data to be sent. Then, we unlink its
625 * async structure from the interrupt chain if necessary, and we free
626 * that IRQ if nothing is left in the chain.
627 * ------------------------------------------------------------
629 static void rs_close(struct tty_struct *tty, struct file * filp)
631 struct async_struct * info = (struct async_struct *)tty->driver_data;
632 struct serial_state *state;
639 local_irq_save(flags);
640 if (tty_hung_up_p(filp)) {
641 #ifdef SIMSERIAL_DEBUG
642 printk("rs_close: hung_up\n");
645 local_irq_restore(flags);
648 #ifdef SIMSERIAL_DEBUG
649 printk("rs_close ttys%d, count = %d\n", info->line, state->count);
651 if ((tty->count == 1) && (state->count != 1)) {
653 * Uh, oh. tty->count is 1, which means that the tty
654 * structure will be freed. state->count should always
655 * be one in these conditions. If it's greater than
656 * one, we've got real problems, since it means the
657 * serial port won't be shutdown.
659 printk(KERN_ERR "rs_close: bad serial port count; tty->count is 1, "
660 "state->count is %d\n", state->count);
663 if (--state->count < 0) {
664 printk(KERN_ERR "rs_close: bad serial port count for ttys%d: %d\n",
665 info->line, state->count);
670 local_irq_restore(flags);
673 info->flags |= ASYNC_CLOSING;
674 local_irq_restore(flags);
677 * Now we wait for the transmit buffer to clear; and we notify
678 * the line discipline to only process XON/XOFF characters.
681 if (tty->driver->flush_buffer) tty->driver->flush_buffer(tty);
682 if (tty->ldisc.flush_buffer) tty->ldisc.flush_buffer(tty);
685 if (info->blocked_open) {
686 if (info->close_delay) {
687 current->state = TASK_INTERRUPTIBLE;
688 schedule_timeout(info->close_delay);
690 wake_up_interruptible(&info->open_wait);
692 info->flags &= ~(ASYNC_NORMAL_ACTIVE|ASYNC_CALLOUT_ACTIVE|ASYNC_CLOSING);
693 wake_up_interruptible(&info->close_wait);
698 * rs_wait_until_sent() --- wait until the transmitter is empty
700 static void rs_wait_until_sent(struct tty_struct *tty, int timeout)
706 * rs_hangup() --- called by tty_hangup() when a hangup is signaled.
708 static void rs_hangup(struct tty_struct *tty)
710 struct async_struct * info = (struct async_struct *)tty->driver_data;
711 struct serial_state *state = info->state;
713 #ifdef SIMSERIAL_DEBUG
714 printk("rs_hangup: called\n");
719 rs_flush_buffer(tty);
720 if (info->flags & ASYNC_CLOSING)
726 info->flags &= ~(ASYNC_NORMAL_ACTIVE|ASYNC_CALLOUT_ACTIVE);
728 wake_up_interruptible(&info->open_wait);
732 static int get_async_struct(int line, struct async_struct **ret_info)
734 struct async_struct *info;
735 struct serial_state *sstate;
737 sstate = rs_table + line;
740 *ret_info = sstate->info;
743 info = kmalloc(sizeof(struct async_struct), GFP_KERNEL);
748 memset(info, 0, sizeof(struct async_struct));
749 init_waitqueue_head(&info->open_wait);
750 init_waitqueue_head(&info->close_wait);
751 init_waitqueue_head(&info->delta_msr_wait);
752 info->magic = SERIAL_MAGIC;
753 info->port = sstate->port;
754 info->flags = sstate->flags;
755 info->xmit_fifo_size = sstate->xmit_fifo_size;
757 INIT_WORK(&info->work, do_softint, info);
758 info->state = sstate;
761 *ret_info = sstate->info;
764 *ret_info = sstate->info = info;
769 startup(struct async_struct *info)
773 irqreturn_t (*handler)(int, void *, struct pt_regs *);
774 struct serial_state *state= info->state;
777 page = get_zeroed_page(GFP_KERNEL);
781 local_irq_save(flags);
783 if (info->flags & ASYNC_INITIALIZED) {
788 if (!state->port || !state->type) {
789 if (info->tty) set_bit(TTY_IO_ERROR, &info->tty->flags);
796 info->xmit.buf = (unsigned char *) page;
798 #ifdef SIMSERIAL_DEBUG
799 printk("startup: ttys%d (irq %d)...", info->line, state->irq);
803 * Allocate the IRQ if necessary
805 if (state->irq && (!IRQ_ports[state->irq] ||
806 !IRQ_ports[state->irq]->next_port)) {
807 if (IRQ_ports[state->irq]) {
811 handler = rs_interrupt_single;
813 retval = request_irq(state->irq, handler, IRQ_T(info), "simserial", NULL);
815 if (capable(CAP_SYS_ADMIN)) {
817 set_bit(TTY_IO_ERROR,
826 * Insert serial port into IRQ chain.
829 info->next_port = IRQ_ports[state->irq];
831 info->next_port->prev_port = info;
832 IRQ_ports[state->irq] = info;
834 if (info->tty) clear_bit(TTY_IO_ERROR, &info->tty->flags);
836 info->xmit.head = info->xmit.tail = 0;
840 * Set up serial timers...
842 timer_table[RS_TIMER].expires = jiffies + 2*HZ/100;
843 timer_active |= 1 << RS_TIMER;
847 * Set up the tty->alt_speed kludge
850 if ((info->flags & ASYNC_SPD_MASK) == ASYNC_SPD_HI)
851 info->tty->alt_speed = 57600;
852 if ((info->flags & ASYNC_SPD_MASK) == ASYNC_SPD_VHI)
853 info->tty->alt_speed = 115200;
854 if ((info->flags & ASYNC_SPD_MASK) == ASYNC_SPD_SHI)
855 info->tty->alt_speed = 230400;
856 if ((info->flags & ASYNC_SPD_MASK) == ASYNC_SPD_WARP)
857 info->tty->alt_speed = 460800;
860 info->flags |= ASYNC_INITIALIZED;
861 local_irq_restore(flags);
865 local_irq_restore(flags);
871 * This routine is called whenever a serial port is opened. It
872 * enables interrupts for a serial port, linking in its async structure into
873 * the IRQ chain. It also performs the serial-specific
874 * initialization for the tty structure.
876 static int rs_open(struct tty_struct *tty, struct file * filp)
878 struct async_struct *info;
884 if ((line < 0) || (line >= NR_PORTS)) {
888 retval = get_async_struct(line, &info);
893 tty->driver_data = info;
896 #ifdef SIMSERIAL_DEBUG
897 printk("rs_open %s, count = %d\n", tty->name, info->state->count);
899 info->tty->low_latency = (info->flags & ASYNC_LOW_LATENCY) ? 1 : 0;
902 page = get_zeroed_page(GFP_KERNEL);
904 /* MOD_DEC_USE_COUNT; "info->tty" will cause this? */
910 tmp_buf = (unsigned char *) page;
914 * If the port is the middle of closing, bail out now
916 if (tty_hung_up_p(filp) ||
917 (info->flags & ASYNC_CLOSING)) {
918 if (info->flags & ASYNC_CLOSING)
919 interruptible_sleep_on(&info->close_wait);
920 /* MOD_DEC_USE_COUNT; "info->tty" will cause this? */
921 #ifdef SERIAL_DO_RESTART
922 return ((info->flags & ASYNC_HUP_NOTIFY) ?
923 -EAGAIN : -ERESTARTSYS);
930 * Start up serial port
932 retval = startup(info);
934 /* MOD_DEC_USE_COUNT; "info->tty" will cause this? */
938 if ((info->state->count == 1) &&
939 (info->flags & ASYNC_SPLIT_TERMIOS)) {
940 if (tty->driver->subtype == SERIAL_TYPE_NORMAL)
941 *tty->termios = info->state->normal_termios;
943 *tty->termios = info->state->callout_termios;
947 * figure out which console to use (should be one already)
949 console = console_drivers;
951 if ((console->flags & CON_ENABLED) && console->write) break;
952 console = console->next;
955 info->session = current->session;
956 info->pgrp = current->pgrp;
958 #ifdef SIMSERIAL_DEBUG
959 printk("rs_open ttys%d successful\n", info->line);
965 * /proc fs routines....
968 static inline int line_info(char *buf, struct serial_state *state)
970 return sprintf(buf, "%d: uart:%s port:%lX irq:%d\n",
971 state->line, uart_config[state->type].name,
972 state->port, state->irq);
975 static int rs_read_proc(char *page, char **start, off_t off, int count,
976 int *eof, void *data)
981 len += sprintf(page, "simserinfo:1.0 driver:%s\n", serial_version);
982 for (i = 0; i < NR_PORTS && len < 4000; i++) {
983 l = line_info(page + len, &rs_table[i]);
985 if (len+begin > off+count)
987 if (len+begin < off) {
994 if (off >= len+begin)
996 *start = page + (begin-off);
997 return ((count < begin+len-off) ? count : begin+len-off);
1001 * ---------------------------------------------------------------------
1002 * rs_init() and friends
1004 * rs_init() is called at boot-time to initialize the serial driver.
1005 * ---------------------------------------------------------------------
1009 * This routine prints out the appropriate serial driver version
1010 * number, and identifies which options were configured into this
1013 static inline void show_serial_version(void)
1015 printk(KERN_INFO "%s version %s with", serial_name, serial_version);
1016 printk(KERN_INFO " no serial options enabled\n");
1020 * The serial driver boot-time initialization code!
1026 struct serial_state *state;
1028 show_serial_version();
1030 /* Initialize the tty_driver structure */
1032 memset(&hp_simserial_driver, 0, sizeof(struct tty_driver));
1033 hp_simserial_driver.magic = TTY_DRIVER_MAGIC;
1034 hp_simserial_driver.driver_name = "simserial";
1035 hp_simserial_driver.name = "ttyS";
1036 hp_simserial_driver.major = TTY_MAJOR;
1037 hp_simserial_driver.minor_start = 64;
1038 hp_simserial_driver.num = 1;
1039 hp_simserial_driver.type = TTY_DRIVER_TYPE_SERIAL;
1040 hp_simserial_driver.subtype = SERIAL_TYPE_NORMAL;
1041 hp_simserial_driver.init_termios = tty_std_termios;
1042 hp_simserial_driver.init_termios.c_cflag =
1043 B9600 | CS8 | CREAD | HUPCL | CLOCAL;
1044 hp_simserial_driver.flags = TTY_DRIVER_REAL_RAW;
1045 hp_simserial_driver.refcount = &serial_refcount;
1046 hp_simserial_driver.table = serial_table;
1047 hp_simserial_driver.termios = serial_termios;
1048 hp_simserial_driver.termios_locked = serial_termios_locked;
1050 hp_simserial_driver.open = rs_open;
1051 hp_simserial_driver.close = rs_close;
1052 hp_simserial_driver.write = rs_write;
1053 hp_simserial_driver.put_char = rs_put_char;
1054 hp_simserial_driver.flush_chars = rs_flush_chars;
1055 hp_simserial_driver.write_room = rs_write_room;
1056 hp_simserial_driver.chars_in_buffer = rs_chars_in_buffer;
1057 hp_simserial_driver.flush_buffer = rs_flush_buffer;
1058 hp_simserial_driver.ioctl = rs_ioctl;
1059 hp_simserial_driver.throttle = rs_throttle;
1060 hp_simserial_driver.unthrottle = rs_unthrottle;
1061 hp_simserial_driver.send_xchar = rs_send_xchar;
1062 hp_simserial_driver.set_termios = rs_set_termios;
1063 hp_simserial_driver.stop = rs_stop;
1064 hp_simserial_driver.start = rs_start;
1065 hp_simserial_driver.hangup = rs_hangup;
1066 hp_simserial_driver.break_ctl = rs_break;
1067 hp_simserial_driver.wait_until_sent = rs_wait_until_sent;
1068 hp_simserial_driver.read_proc = rs_read_proc;
1071 * Let's have a little bit of fun !
1073 for (i = 0, state = rs_table; i < NR_PORTS; i++,state++) {
1075 if (state->type == PORT_UNKNOWN) continue;
1078 state->irq = ia64_alloc_vector();
1079 ia64_ssc_connect_irq(KEYBOARD_INTR, state->irq);
1082 printk(KERN_INFO "ttyS%02d at 0x%04lx (irq = %d) is a %s\n",
1084 state->port, state->irq,
1085 uart_config[state->type].name);
1088 * The callout device is just like normal device except for
1089 * major number and the subtype code.
1091 callout_driver = hp_simserial_driver;
1092 callout_driver.name = "cua";
1093 callout_driver.major = TTYAUX_MAJOR;
1094 callout_driver.subtype = SERIAL_TYPE_CALLOUT;
1095 callout_driver.read_proc = 0;
1096 callout_driver.proc_entry = 0;
1098 if (tty_register_driver(&hp_simserial_driver))
1099 panic("Couldn't register simserial driver\n");
1101 if (tty_register_driver(&callout_driver))
1102 panic("Couldn't register callout driver\n");
1108 __initcall(simrs_init);