simserial.c 17 KB

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