simserial.c 17 KB

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