]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blob - arch/ia64/hp/sim/simserial.c
64ab004b47634a68ef64780721364ce31725ad5b
[mirror_ubuntu-bionic-kernel.git] / arch / ia64 / hp / sim / simserial.c
1 /*
2 * Simulated Serial Driver (fake serial)
3 *
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.
9 *
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>
13 *
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
17 */
18
19 #include <linux/init.h>
20 #include <linux/errno.h>
21 #include <linux/sched.h>
22 #include <linux/tty.h>
23 #include <linux/tty_flip.h>
24 #include <linux/major.h>
25 #include <linux/fcntl.h>
26 #include <linux/mm.h>
27 #include <linux/seq_file.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>
35
36 #include <asm/irq.h>
37 #include <asm/hpsim.h>
38 #include <asm/hw_irq.h>
39 #include <asm/uaccess.h>
40
41 #include "hpsim_ssc.h"
42
43 #undef SIMSERIAL_DEBUG /* define this to get some debug information */
44
45 #define KEYBOARD_INTR 3 /* must match with simulator! */
46
47 #define NR_PORTS 1 /* only one port for now */
48
49 static char *serial_name = "SimSerial driver";
50 static char *serial_version = "0.6";
51
52 static struct serial_state rs_table[NR_PORTS];
53
54 struct tty_driver *hp_simserial_driver;
55
56 static struct console *console;
57
58 static unsigned char *tmp_buf;
59
60 extern struct console *console_drivers; /* from kernel/printk.c */
61
62 /*
63 * ------------------------------------------------------------
64 * rs_stop() and rs_start()
65 *
66 * This routines are called before setting or resetting tty->stopped.
67 * They enable or disable transmitter interrupts, as necessary.
68 * ------------------------------------------------------------
69 */
70 static void rs_stop(struct tty_struct *tty)
71 {
72 #ifdef SIMSERIAL_DEBUG
73 printk("rs_stop: tty->stopped=%d tty->hw_stopped=%d tty->flow_stopped=%d\n",
74 tty->stopped, tty->hw_stopped, tty->flow_stopped);
75 #endif
76
77 }
78
79 static void rs_start(struct tty_struct *tty)
80 {
81 #ifdef SIMSERIAL_DEBUG
82 printk("rs_start: tty->stopped=%d tty->hw_stopped=%d tty->flow_stopped=%d\n",
83 tty->stopped, tty->hw_stopped, tty->flow_stopped);
84 #endif
85 }
86
87 static void receive_chars(struct tty_struct *tty)
88 {
89 unsigned char ch;
90 static unsigned char seen_esc = 0;
91
92 while ( (ch = ia64_ssc(0, 0, 0, 0, SSC_GETCHAR)) ) {
93 if ( ch == 27 && seen_esc == 0 ) {
94 seen_esc = 1;
95 continue;
96 } else {
97 if ( seen_esc==1 && ch == 'O' ) {
98 seen_esc = 2;
99 continue;
100 } else if ( seen_esc == 2 ) {
101 if ( ch == 'P' ) /* F1 */
102 show_state();
103 #ifdef CONFIG_MAGIC_SYSRQ
104 if ( ch == 'S' ) { /* F4 */
105 do
106 ch = ia64_ssc(0, 0, 0, 0,
107 SSC_GETCHAR);
108 while (!ch);
109 handle_sysrq(ch);
110 }
111 #endif
112 seen_esc = 0;
113 continue;
114 }
115 }
116 seen_esc = 0;
117
118 if (tty_insert_flip_char(tty, ch, TTY_NORMAL) == 0)
119 break;
120 }
121 tty_flip_buffer_push(tty);
122 }
123
124 /*
125 * This is the serial driver's interrupt routine for a single port
126 */
127 static irqreturn_t rs_interrupt_single(int irq, void *dev_id)
128 {
129 struct serial_state *info = dev_id;
130
131 if (!info->tport.tty) {
132 printk(KERN_INFO "simrs_interrupt_single: info|tty=0 info=%p problem\n", info);
133 return IRQ_NONE;
134 }
135 /*
136 * pretty simple in our case, because we only get interrupts
137 * on inbound traffic
138 */
139 receive_chars(info->tport.tty);
140 return IRQ_HANDLED;
141 }
142
143 /*
144 * -------------------------------------------------------------------
145 * Here ends the serial interrupt routines.
146 * -------------------------------------------------------------------
147 */
148
149 static int rs_put_char(struct tty_struct *tty, unsigned char ch)
150 {
151 struct serial_state *info = tty->driver_data;
152 unsigned long flags;
153
154 if (!tty || !info->xmit.buf)
155 return 0;
156
157 local_irq_save(flags);
158 if (CIRC_SPACE(info->xmit.head, info->xmit.tail, SERIAL_XMIT_SIZE) == 0) {
159 local_irq_restore(flags);
160 return 0;
161 }
162 info->xmit.buf[info->xmit.head] = ch;
163 info->xmit.head = (info->xmit.head + 1) & (SERIAL_XMIT_SIZE-1);
164 local_irq_restore(flags);
165 return 1;
166 }
167
168 static void transmit_chars(struct tty_struct *tty, struct serial_state *info,
169 int *intr_done)
170 {
171 int count;
172 unsigned long flags;
173
174 local_irq_save(flags);
175
176 if (info->x_char) {
177 char c = info->x_char;
178
179 console->write(console, &c, 1);
180
181 info->icount.tx++;
182 info->x_char = 0;
183
184 goto out;
185 }
186
187 if (info->xmit.head == info->xmit.tail || tty->stopped ||
188 tty->hw_stopped) {
189 #ifdef SIMSERIAL_DEBUG
190 printk("transmit_chars: head=%d, tail=%d, stopped=%d\n",
191 info->xmit.head, info->xmit.tail, tty->stopped);
192 #endif
193 goto out;
194 }
195 /*
196 * We removed the loop and try to do it in to chunks. We need
197 * 2 operations maximum because it's a ring buffer.
198 *
199 * First from current to tail if possible.
200 * Then from the beginning of the buffer until necessary
201 */
202
203 count = min(CIRC_CNT(info->xmit.head, info->xmit.tail, SERIAL_XMIT_SIZE),
204 SERIAL_XMIT_SIZE - info->xmit.tail);
205 console->write(console, info->xmit.buf+info->xmit.tail, count);
206
207 info->xmit.tail = (info->xmit.tail+count) & (SERIAL_XMIT_SIZE-1);
208
209 /*
210 * We have more at the beginning of the buffer
211 */
212 count = CIRC_CNT(info->xmit.head, info->xmit.tail, SERIAL_XMIT_SIZE);
213 if (count) {
214 console->write(console, info->xmit.buf, count);
215 info->xmit.tail += count;
216 }
217 out:
218 local_irq_restore(flags);
219 }
220
221 static void rs_flush_chars(struct tty_struct *tty)
222 {
223 struct serial_state *info = tty->driver_data;
224
225 if (info->xmit.head == info->xmit.tail || tty->stopped || tty->hw_stopped ||
226 !info->xmit.buf)
227 return;
228
229 transmit_chars(tty, info, NULL);
230 }
231
232
233 static int rs_write(struct tty_struct * tty,
234 const unsigned char *buf, int count)
235 {
236 struct serial_state *info = tty->driver_data;
237 int c, ret = 0;
238 unsigned long flags;
239
240 if (!tty || !info->xmit.buf || !tmp_buf) return 0;
241
242 local_irq_save(flags);
243 while (1) {
244 c = CIRC_SPACE_TO_END(info->xmit.head, info->xmit.tail, SERIAL_XMIT_SIZE);
245 if (count < c)
246 c = count;
247 if (c <= 0) {
248 break;
249 }
250 memcpy(info->xmit.buf + info->xmit.head, buf, c);
251 info->xmit.head = ((info->xmit.head + c) &
252 (SERIAL_XMIT_SIZE-1));
253 buf += c;
254 count -= c;
255 ret += c;
256 }
257 local_irq_restore(flags);
258 /*
259 * Hey, we transmit directly from here in our case
260 */
261 if (CIRC_CNT(info->xmit.head, info->xmit.tail, SERIAL_XMIT_SIZE)
262 && !tty->stopped && !tty->hw_stopped) {
263 transmit_chars(tty, info, NULL);
264 }
265 return ret;
266 }
267
268 static int rs_write_room(struct tty_struct *tty)
269 {
270 struct serial_state *info = tty->driver_data;
271
272 return CIRC_SPACE(info->xmit.head, info->xmit.tail, SERIAL_XMIT_SIZE);
273 }
274
275 static int rs_chars_in_buffer(struct tty_struct *tty)
276 {
277 struct serial_state *info = tty->driver_data;
278
279 return CIRC_CNT(info->xmit.head, info->xmit.tail, SERIAL_XMIT_SIZE);
280 }
281
282 static void rs_flush_buffer(struct tty_struct *tty)
283 {
284 struct serial_state *info = tty->driver_data;
285 unsigned long flags;
286
287 local_irq_save(flags);
288 info->xmit.head = info->xmit.tail = 0;
289 local_irq_restore(flags);
290
291 tty_wakeup(tty);
292 }
293
294 /*
295 * This function is used to send a high-priority XON/XOFF character to
296 * the device
297 */
298 static void rs_send_xchar(struct tty_struct *tty, char ch)
299 {
300 struct serial_state *info = tty->driver_data;
301
302 info->x_char = ch;
303 if (ch) {
304 /*
305 * I guess we could call console->write() directly but
306 * let's do that for now.
307 */
308 transmit_chars(tty, info, NULL);
309 }
310 }
311
312 /*
313 * ------------------------------------------------------------
314 * rs_throttle()
315 *
316 * This routine is called by the upper-layer tty layer to signal that
317 * incoming characters should be throttled.
318 * ------------------------------------------------------------
319 */
320 static void rs_throttle(struct tty_struct * tty)
321 {
322 if (I_IXOFF(tty)) rs_send_xchar(tty, STOP_CHAR(tty));
323
324 printk(KERN_INFO "simrs_throttle called\n");
325 }
326
327 static void rs_unthrottle(struct tty_struct * tty)
328 {
329 struct serial_state *info = tty->driver_data;
330
331 if (I_IXOFF(tty)) {
332 if (info->x_char)
333 info->x_char = 0;
334 else
335 rs_send_xchar(tty, START_CHAR(tty));
336 }
337 printk(KERN_INFO "simrs_unthrottle called\n");
338 }
339
340
341 static int rs_ioctl(struct tty_struct *tty, unsigned int cmd, unsigned long arg)
342 {
343 if ((cmd != TIOCGSERIAL) && (cmd != TIOCSSERIAL) &&
344 (cmd != TIOCSERCONFIG) && (cmd != TIOCSERGSTRUCT) &&
345 (cmd != TIOCMIWAIT)) {
346 if (tty->flags & (1 << TTY_IO_ERROR))
347 return -EIO;
348 }
349
350 switch (cmd) {
351 case TIOCGSERIAL:
352 printk(KERN_INFO "simrs_ioctl TIOCGSERIAL called\n");
353 return 0;
354 case TIOCSSERIAL:
355 printk(KERN_INFO "simrs_ioctl TIOCSSERIAL called\n");
356 return 0;
357 case TIOCSERCONFIG:
358 printk(KERN_INFO "rs_ioctl: TIOCSERCONFIG called\n");
359 return -EINVAL;
360
361 case TIOCSERGETLSR: /* Get line status register */
362 printk(KERN_INFO "rs_ioctl: TIOCSERGETLSR called\n");
363 return -EINVAL;
364
365 case TIOCSERGSTRUCT:
366 printk(KERN_INFO "rs_ioctl: TIOCSERGSTRUCT called\n");
367 #if 0
368 if (copy_to_user((struct async_struct *) arg,
369 info, sizeof(struct async_struct)))
370 return -EFAULT;
371 #endif
372 return 0;
373
374 /*
375 * Wait for any of the 4 modem inputs (DCD,RI,DSR,CTS) to change
376 * - mask passed in arg for lines of interest
377 * (use |'ed TIOCM_RNG/DSR/CD/CTS for masking)
378 * Caller should use TIOCGICOUNT to see which one it was
379 */
380 case TIOCMIWAIT:
381 printk(KERN_INFO "rs_ioctl: TIOCMIWAIT: called\n");
382 return 0;
383 case TIOCSERGWILD:
384 case TIOCSERSWILD:
385 /* "setserial -W" is called in Debian boot */
386 printk (KERN_INFO "TIOCSER?WILD ioctl obsolete, ignored.\n");
387 return 0;
388
389 default:
390 return -ENOIOCTLCMD;
391 }
392 return 0;
393 }
394
395 #define RELEVANT_IFLAG(iflag) (iflag & (IGNBRK|BRKINT|IGNPAR|PARMRK|INPCK))
396
397 static void rs_set_termios(struct tty_struct *tty, struct ktermios *old_termios)
398 {
399 /* Handle turning off CRTSCTS */
400 if ((old_termios->c_cflag & CRTSCTS) &&
401 !(tty->termios->c_cflag & CRTSCTS)) {
402 tty->hw_stopped = 0;
403 rs_start(tty);
404 }
405 }
406 /*
407 * This routine will shutdown a serial port; interrupts are disabled, and
408 * DTR is dropped if the hangup on close termio flag is on.
409 */
410 static void shutdown(struct tty_struct *tty, struct serial_state *info)
411 {
412 unsigned long flags;
413
414 if (!(info->tport.flags & ASYNC_INITIALIZED))
415 return;
416
417 #ifdef SIMSERIAL_DEBUG
418 printk("Shutting down serial port %d (irq %d)...\n", info->line,
419 info->irq);
420 #endif
421
422 local_irq_save(flags);
423 {
424 if (info->irq)
425 free_irq(info->irq, info);
426
427 if (info->xmit.buf) {
428 free_page((unsigned long) info->xmit.buf);
429 info->xmit.buf = NULL;
430 }
431
432 set_bit(TTY_IO_ERROR, &tty->flags);
433
434 info->tport.flags &= ~ASYNC_INITIALIZED;
435 }
436 local_irq_restore(flags);
437 }
438
439 /*
440 * ------------------------------------------------------------
441 * rs_close()
442 *
443 * This routine is called when the serial port gets closed. First, we
444 * wait for the last remaining data to be sent. Then, we unlink its
445 * async structure from the interrupt chain if necessary, and we free
446 * that IRQ if nothing is left in the chain.
447 * ------------------------------------------------------------
448 */
449 static void rs_close(struct tty_struct *tty, struct file * filp)
450 {
451 struct serial_state *info = tty->driver_data;
452 unsigned long flags;
453
454 if (!info)
455 return;
456
457 local_irq_save(flags);
458 if (tty_hung_up_p(filp)) {
459 #ifdef SIMSERIAL_DEBUG
460 printk("rs_close: hung_up\n");
461 #endif
462 local_irq_restore(flags);
463 return;
464 }
465 #ifdef SIMSERIAL_DEBUG
466 printk("rs_close ttys%d, count = %d\n", info->line, info->tport.count);
467 #endif
468 if ((tty->count == 1) && (info->tport.count != 1)) {
469 /*
470 * Uh, oh. tty->count is 1, which means that the tty
471 * structure will be freed. info->tport.count should always
472 * be one in these conditions. If it's greater than
473 * one, we've got real problems, since it means the
474 * serial port won't be shutdown.
475 */
476 printk(KERN_ERR "rs_close: bad serial port count; tty->count is 1, "
477 "info->tport.count is %d\n", info->tport.count);
478 info->tport.count = 1;
479 }
480 if (--info->tport.count < 0) {
481 printk(KERN_ERR "rs_close: bad serial port count for ttys%d: %d\n",
482 info->line, info->tport.count);
483 info->tport.count = 0;
484 }
485 if (info->tport.count) {
486 local_irq_restore(flags);
487 return;
488 }
489 info->tport.flags |= ASYNC_CLOSING;
490 local_irq_restore(flags);
491
492 /*
493 * Now we wait for the transmit buffer to clear; and we notify
494 * the line discipline to only process XON/XOFF characters.
495 */
496 shutdown(tty, info);
497 rs_flush_buffer(tty);
498 tty_ldisc_flush(tty);
499 info->tport.tty = NULL;
500 if (info->tport.blocked_open) {
501 if (info->tport.close_delay)
502 schedule_timeout_interruptible(info->tport.close_delay);
503 wake_up_interruptible(&info->tport.open_wait);
504 }
505 info->tport.flags &= ~(ASYNC_NORMAL_ACTIVE|ASYNC_CLOSING);
506 wake_up_interruptible(&info->tport.close_wait);
507 }
508
509 /*
510 * rs_wait_until_sent() --- wait until the transmitter is empty
511 */
512 static void rs_wait_until_sent(struct tty_struct *tty, int timeout)
513 {
514 }
515
516
517 /*
518 * rs_hangup() --- called by tty_hangup() when a hangup is signaled.
519 */
520 static void rs_hangup(struct tty_struct *tty)
521 {
522 struct serial_state *info = tty->driver_data;
523
524 #ifdef SIMSERIAL_DEBUG
525 printk("rs_hangup: called\n");
526 #endif
527
528 rs_flush_buffer(tty);
529 if (info->tport.flags & ASYNC_CLOSING)
530 return;
531 shutdown(tty, info);
532
533 info->tport.count = 0;
534 info->tport.flags &= ~ASYNC_NORMAL_ACTIVE;
535 info->tport.tty = NULL;
536 wake_up_interruptible(&info->tport.open_wait);
537 }
538
539
540 static int startup(struct tty_struct *tty, struct serial_state *state)
541 {
542 struct tty_port *port = &state->tport;
543 unsigned long flags;
544 int retval=0;
545 unsigned long page;
546
547 page = get_zeroed_page(GFP_KERNEL);
548 if (!page)
549 return -ENOMEM;
550
551 local_irq_save(flags);
552
553 if (port->flags & ASYNC_INITIALIZED) {
554 free_page(page);
555 goto errout;
556 }
557
558 if (state->xmit.buf)
559 free_page(page);
560 else
561 state->xmit.buf = (unsigned char *) page;
562
563 #ifdef SIMSERIAL_DEBUG
564 printk("startup: ttys%d (irq %d)...", state->line, state->irq);
565 #endif
566
567 /*
568 * Allocate the IRQ if necessary
569 */
570 if (state->irq) {
571 retval = request_irq(state->irq, rs_interrupt_single, 0,
572 "simserial", state);
573 if (retval)
574 goto errout;
575 }
576
577 clear_bit(TTY_IO_ERROR, &tty->flags);
578
579 state->xmit.head = state->xmit.tail = 0;
580
581 #if 0
582 /*
583 * Set up serial timers...
584 */
585 timer_table[RS_TIMER].expires = jiffies + 2*HZ/100;
586 timer_active |= 1 << RS_TIMER;
587 #endif
588
589 /*
590 * Set up the tty->alt_speed kludge
591 */
592 if ((port->flags & ASYNC_SPD_MASK) == ASYNC_SPD_HI)
593 tty->alt_speed = 57600;
594 if ((port->flags & ASYNC_SPD_MASK) == ASYNC_SPD_VHI)
595 tty->alt_speed = 115200;
596 if ((port->flags & ASYNC_SPD_MASK) == ASYNC_SPD_SHI)
597 tty->alt_speed = 230400;
598 if ((port->flags & ASYNC_SPD_MASK) == ASYNC_SPD_WARP)
599 tty->alt_speed = 460800;
600
601 port->flags |= ASYNC_INITIALIZED;
602 local_irq_restore(flags);
603 return 0;
604
605 errout:
606 local_irq_restore(flags);
607 return retval;
608 }
609
610
611 /*
612 * This routine is called whenever a serial port is opened. It
613 * enables interrupts for a serial port, linking in its async structure into
614 * the IRQ chain. It also performs the serial-specific
615 * initialization for the tty structure.
616 */
617 static int rs_open(struct tty_struct *tty, struct file * filp)
618 {
619 struct serial_state *info = rs_table + tty->index;
620 int retval;
621 unsigned long page;
622
623 info->tport.count++;
624 info->tport.tty = tty;
625 tty->driver_data = info;
626 tty->port = &info->tport;
627
628 #ifdef SIMSERIAL_DEBUG
629 printk("rs_open %s, count = %d\n", tty->name, info->tport.count);
630 #endif
631 tty->low_latency = (info->tport.flags & ASYNC_LOW_LATENCY) ? 1 : 0;
632
633 if (!tmp_buf) {
634 page = get_zeroed_page(GFP_KERNEL);
635 if (!page)
636 return -ENOMEM;
637 if (tmp_buf)
638 free_page(page);
639 else
640 tmp_buf = (unsigned char *) page;
641 }
642
643 /*
644 * If the port is the middle of closing, bail out now
645 */
646 if (tty_hung_up_p(filp) || (info->tport.flags & ASYNC_CLOSING)) {
647 if (info->tport.flags & ASYNC_CLOSING)
648 interruptible_sleep_on(&info->tport.close_wait);
649 #ifdef SERIAL_DO_RESTART
650 return ((info->tport.flags & ASYNC_HUP_NOTIFY) ?
651 -EAGAIN : -ERESTARTSYS);
652 #else
653 return -EAGAIN;
654 #endif
655 }
656
657 /*
658 * Start up serial port
659 */
660 retval = startup(tty, info);
661 if (retval) {
662 return retval;
663 }
664
665 /*
666 * figure out which console to use (should be one already)
667 */
668 console = console_drivers;
669 while (console) {
670 if ((console->flags & CON_ENABLED) && console->write) break;
671 console = console->next;
672 }
673
674 #ifdef SIMSERIAL_DEBUG
675 printk("rs_open ttys%d successful\n", info->line);
676 #endif
677 return 0;
678 }
679
680 /*
681 * /proc fs routines....
682 */
683
684 static inline void line_info(struct seq_file *m, struct serial_state *state)
685 {
686 seq_printf(m, "%d: uart:16550 port:3F8 irq:%d\n",
687 state->line, state->irq);
688 }
689
690 static int rs_proc_show(struct seq_file *m, void *v)
691 {
692 int i;
693
694 seq_printf(m, "simserinfo:1.0 driver:%s\n", serial_version);
695 for (i = 0; i < NR_PORTS; i++)
696 line_info(m, &rs_table[i]);
697 return 0;
698 }
699
700 static int rs_proc_open(struct inode *inode, struct file *file)
701 {
702 return single_open(file, rs_proc_show, NULL);
703 }
704
705 static const struct file_operations rs_proc_fops = {
706 .owner = THIS_MODULE,
707 .open = rs_proc_open,
708 .read = seq_read,
709 .llseek = seq_lseek,
710 .release = single_release,
711 };
712
713 /*
714 * ---------------------------------------------------------------------
715 * rs_init() and friends
716 *
717 * rs_init() is called at boot-time to initialize the serial driver.
718 * ---------------------------------------------------------------------
719 */
720
721 /*
722 * This routine prints out the appropriate serial driver version
723 * number, and identifies which options were configured into this
724 * driver.
725 */
726 static inline void show_serial_version(void)
727 {
728 printk(KERN_INFO "%s version %s with", serial_name, serial_version);
729 printk(KERN_INFO " no serial options enabled\n");
730 }
731
732 static const struct tty_operations hp_ops = {
733 .open = rs_open,
734 .close = rs_close,
735 .write = rs_write,
736 .put_char = rs_put_char,
737 .flush_chars = rs_flush_chars,
738 .write_room = rs_write_room,
739 .chars_in_buffer = rs_chars_in_buffer,
740 .flush_buffer = rs_flush_buffer,
741 .ioctl = rs_ioctl,
742 .throttle = rs_throttle,
743 .unthrottle = rs_unthrottle,
744 .send_xchar = rs_send_xchar,
745 .set_termios = rs_set_termios,
746 .stop = rs_stop,
747 .start = rs_start,
748 .hangup = rs_hangup,
749 .wait_until_sent = rs_wait_until_sent,
750 .proc_fops = &rs_proc_fops,
751 };
752
753 /*
754 * The serial driver boot-time initialization code!
755 */
756 static int __init simrs_init(void)
757 {
758 struct serial_state *state;
759 int retval;
760
761 if (!ia64_platform_is("hpsim"))
762 return -ENODEV;
763
764 hp_simserial_driver = alloc_tty_driver(NR_PORTS);
765 if (!hp_simserial_driver)
766 return -ENOMEM;
767
768 show_serial_version();
769
770 /* Initialize the tty_driver structure */
771
772 hp_simserial_driver->driver_name = "simserial";
773 hp_simserial_driver->name = "ttyS";
774 hp_simserial_driver->major = TTY_MAJOR;
775 hp_simserial_driver->minor_start = 64;
776 hp_simserial_driver->type = TTY_DRIVER_TYPE_SERIAL;
777 hp_simserial_driver->subtype = SERIAL_TYPE_NORMAL;
778 hp_simserial_driver->init_termios = tty_std_termios;
779 hp_simserial_driver->init_termios.c_cflag =
780 B9600 | CS8 | CREAD | HUPCL | CLOCAL;
781 hp_simserial_driver->flags = TTY_DRIVER_REAL_RAW;
782 tty_set_operations(hp_simserial_driver, &hp_ops);
783
784 /*
785 * Let's have a little bit of fun !
786 */
787 state = rs_table;
788 tty_port_init(&state->tport);
789 state->tport.close_delay = 0; /* XXX really 0? */
790
791 retval = hpsim_get_irq(KEYBOARD_INTR);
792 if (retval < 0) {
793 printk(KERN_ERR "%s: out of interrupt vectors!\n",
794 __func__);
795 goto err_free_tty;
796 }
797
798 state->irq = retval;
799
800 /* the port is imaginary */
801 printk(KERN_INFO "ttyS%d at 0x03f8 (irq = %d) is a 16550\n",
802 state->line, state->irq);
803
804 retval = tty_register_driver(hp_simserial_driver);
805 if (retval) {
806 printk(KERN_ERR "Couldn't register simserial driver\n");
807 goto err_free_tty;
808 }
809
810 return 0;
811 err_free_tty:
812 put_tty_driver(hp_simserial_driver);
813 return retval;
814 }
815
816 #ifndef MODULE
817 __initcall(simrs_init);
818 #endif