simserial.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772
  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. unsigned long flags;
  367. if (!info)
  368. return;
  369. local_irq_save(flags);
  370. if (tty_hung_up_p(filp)) {
  371. #ifdef SIMSERIAL_DEBUG
  372. printk("rs_close: hung_up\n");
  373. #endif
  374. local_irq_restore(flags);
  375. return;
  376. }
  377. #ifdef SIMSERIAL_DEBUG
  378. printk("rs_close ttys%d, count = %d\n", info->line, port->count);
  379. #endif
  380. if ((tty->count == 1) && (port->count != 1)) {
  381. /*
  382. * Uh, oh. tty->count is 1, which means that the tty
  383. * structure will be freed. port->count should always
  384. * be one in these conditions. If it's greater than
  385. * one, we've got real problems, since it means the
  386. * serial port won't be shutdown.
  387. */
  388. printk(KERN_ERR "rs_close: bad serial port count; tty->count is 1, "
  389. "port->count is %d\n", port->count);
  390. port->count = 1;
  391. }
  392. if (--port->count < 0) {
  393. printk(KERN_ERR "rs_close: bad serial port count for ttys%d: %d\n",
  394. tty->index, port->count);
  395. port->count = 0;
  396. }
  397. if (port->count) {
  398. local_irq_restore(flags);
  399. return;
  400. }
  401. port->flags |= ASYNC_CLOSING;
  402. local_irq_restore(flags);
  403. /*
  404. * Now we wait for the transmit buffer to clear; and we notify
  405. * the line discipline to only process XON/XOFF characters.
  406. */
  407. shutdown(tty, info);
  408. rs_flush_buffer(tty);
  409. tty_ldisc_flush(tty);
  410. port->tty = NULL;
  411. tty_port_close_end(port, tty);
  412. }
  413. /*
  414. * rs_hangup() --- called by tty_hangup() when a hangup is signaled.
  415. */
  416. static void rs_hangup(struct tty_struct *tty)
  417. {
  418. struct serial_state *info = tty->driver_data;
  419. struct tty_port *port = &info->port;
  420. #ifdef SIMSERIAL_DEBUG
  421. printk("rs_hangup: called\n");
  422. #endif
  423. rs_flush_buffer(tty);
  424. if (port->flags & ASYNC_CLOSING)
  425. return;
  426. shutdown(tty, info);
  427. port->count = 0;
  428. port->flags &= ~ASYNC_NORMAL_ACTIVE;
  429. port->tty = NULL;
  430. wake_up_interruptible(&port->open_wait);
  431. }
  432. static int startup(struct tty_struct *tty, struct serial_state *state)
  433. {
  434. struct tty_port *port = &state->port;
  435. unsigned long flags;
  436. int retval=0;
  437. unsigned long page;
  438. page = get_zeroed_page(GFP_KERNEL);
  439. if (!page)
  440. return -ENOMEM;
  441. local_irq_save(flags);
  442. if (port->flags & ASYNC_INITIALIZED) {
  443. free_page(page);
  444. goto errout;
  445. }
  446. if (state->xmit.buf)
  447. free_page(page);
  448. else
  449. state->xmit.buf = (unsigned char *) page;
  450. #ifdef SIMSERIAL_DEBUG
  451. printk("startup: ttys%d (irq %d)...", state->line, state->irq);
  452. #endif
  453. /*
  454. * Allocate the IRQ if necessary
  455. */
  456. if (state->irq) {
  457. retval = request_irq(state->irq, rs_interrupt_single, 0,
  458. "simserial", state);
  459. if (retval)
  460. goto errout;
  461. }
  462. clear_bit(TTY_IO_ERROR, &tty->flags);
  463. state->xmit.head = state->xmit.tail = 0;
  464. #if 0
  465. /*
  466. * Set up serial timers...
  467. */
  468. timer_table[RS_TIMER].expires = jiffies + 2*HZ/100;
  469. timer_active |= 1 << RS_TIMER;
  470. #endif
  471. /*
  472. * Set up the tty->alt_speed kludge
  473. */
  474. if ((port->flags & ASYNC_SPD_MASK) == ASYNC_SPD_HI)
  475. tty->alt_speed = 57600;
  476. if ((port->flags & ASYNC_SPD_MASK) == ASYNC_SPD_VHI)
  477. tty->alt_speed = 115200;
  478. if ((port->flags & ASYNC_SPD_MASK) == ASYNC_SPD_SHI)
  479. tty->alt_speed = 230400;
  480. if ((port->flags & ASYNC_SPD_MASK) == ASYNC_SPD_WARP)
  481. tty->alt_speed = 460800;
  482. port->flags |= ASYNC_INITIALIZED;
  483. local_irq_restore(flags);
  484. return 0;
  485. errout:
  486. local_irq_restore(flags);
  487. return retval;
  488. }
  489. /*
  490. * This routine is called whenever a serial port is opened. It
  491. * enables interrupts for a serial port, linking in its async structure into
  492. * the IRQ chain. It also performs the serial-specific
  493. * initialization for the tty structure.
  494. */
  495. static int rs_open(struct tty_struct *tty, struct file * filp)
  496. {
  497. struct serial_state *info = rs_table + tty->index;
  498. struct tty_port *port = &info->port;
  499. int retval;
  500. port->count++;
  501. port->tty = tty;
  502. tty->driver_data = info;
  503. tty->port = port;
  504. #ifdef SIMSERIAL_DEBUG
  505. printk("rs_open %s, count = %d\n", tty->name, port->count);
  506. #endif
  507. tty->low_latency = (port->flags & ASYNC_LOW_LATENCY) ? 1 : 0;
  508. /*
  509. * If the port is the middle of closing, bail out now
  510. */
  511. if (tty_hung_up_p(filp) || (port->flags & ASYNC_CLOSING)) {
  512. if (port->flags & ASYNC_CLOSING)
  513. interruptible_sleep_on(&port->close_wait);
  514. #ifdef SERIAL_DO_RESTART
  515. return ((port->flags & ASYNC_HUP_NOTIFY) ?
  516. -EAGAIN : -ERESTARTSYS);
  517. #else
  518. return -EAGAIN;
  519. #endif
  520. }
  521. /*
  522. * Start up serial port
  523. */
  524. retval = startup(tty, info);
  525. if (retval) {
  526. return retval;
  527. }
  528. /*
  529. * figure out which console to use (should be one already)
  530. */
  531. console = console_drivers;
  532. while (console) {
  533. if ((console->flags & CON_ENABLED) && console->write) break;
  534. console = console->next;
  535. }
  536. #ifdef SIMSERIAL_DEBUG
  537. printk("rs_open ttys%d successful\n", info->line);
  538. #endif
  539. return 0;
  540. }
  541. /*
  542. * /proc fs routines....
  543. */
  544. static int rs_proc_show(struct seq_file *m, void *v)
  545. {
  546. int i;
  547. seq_printf(m, "simserinfo:1.0 driver:%s\n", serial_version);
  548. for (i = 0; i < NR_PORTS; i++)
  549. seq_printf(m, "%d: uart:16550 port:3F8 irq:%d\n",
  550. i, rs_table[i].irq);
  551. return 0;
  552. }
  553. static int rs_proc_open(struct inode *inode, struct file *file)
  554. {
  555. return single_open(file, rs_proc_show, NULL);
  556. }
  557. static const struct file_operations rs_proc_fops = {
  558. .owner = THIS_MODULE,
  559. .open = rs_proc_open,
  560. .read = seq_read,
  561. .llseek = seq_lseek,
  562. .release = single_release,
  563. };
  564. /*
  565. * ---------------------------------------------------------------------
  566. * rs_init() and friends
  567. *
  568. * rs_init() is called at boot-time to initialize the serial driver.
  569. * ---------------------------------------------------------------------
  570. */
  571. /*
  572. * This routine prints out the appropriate serial driver version
  573. * number, and identifies which options were configured into this
  574. * driver.
  575. */
  576. static inline void show_serial_version(void)
  577. {
  578. printk(KERN_INFO "%s version %s with", serial_name, serial_version);
  579. printk(KERN_INFO " no serial options enabled\n");
  580. }
  581. static const struct tty_operations hp_ops = {
  582. .open = rs_open,
  583. .close = rs_close,
  584. .write = rs_write,
  585. .put_char = rs_put_char,
  586. .flush_chars = rs_flush_chars,
  587. .write_room = rs_write_room,
  588. .chars_in_buffer = rs_chars_in_buffer,
  589. .flush_buffer = rs_flush_buffer,
  590. .ioctl = rs_ioctl,
  591. .throttle = rs_throttle,
  592. .unthrottle = rs_unthrottle,
  593. .send_xchar = rs_send_xchar,
  594. .set_termios = rs_set_termios,
  595. .hangup = rs_hangup,
  596. .proc_fops = &rs_proc_fops,
  597. };
  598. static const struct tty_port_operations hp_port_ops = {
  599. };
  600. /*
  601. * The serial driver boot-time initialization code!
  602. */
  603. static int __init simrs_init(void)
  604. {
  605. struct serial_state *state;
  606. int retval;
  607. if (!ia64_platform_is("hpsim"))
  608. return -ENODEV;
  609. hp_simserial_driver = alloc_tty_driver(NR_PORTS);
  610. if (!hp_simserial_driver)
  611. return -ENOMEM;
  612. show_serial_version();
  613. /* Initialize the tty_driver structure */
  614. hp_simserial_driver->driver_name = "simserial";
  615. hp_simserial_driver->name = "ttyS";
  616. hp_simserial_driver->major = TTY_MAJOR;
  617. hp_simserial_driver->minor_start = 64;
  618. hp_simserial_driver->type = TTY_DRIVER_TYPE_SERIAL;
  619. hp_simserial_driver->subtype = SERIAL_TYPE_NORMAL;
  620. hp_simserial_driver->init_termios = tty_std_termios;
  621. hp_simserial_driver->init_termios.c_cflag =
  622. B9600 | CS8 | CREAD | HUPCL | CLOCAL;
  623. hp_simserial_driver->flags = TTY_DRIVER_REAL_RAW;
  624. tty_set_operations(hp_simserial_driver, &hp_ops);
  625. /*
  626. * Let's have a little bit of fun !
  627. */
  628. state = rs_table;
  629. tty_port_init(&state->port);
  630. state->port.ops = &hp_port_ops;
  631. state->port.close_delay = 0; /* XXX really 0? */
  632. retval = hpsim_get_irq(KEYBOARD_INTR);
  633. if (retval < 0) {
  634. printk(KERN_ERR "%s: out of interrupt vectors!\n",
  635. __func__);
  636. goto err_free_tty;
  637. }
  638. state->irq = retval;
  639. /* the port is imaginary */
  640. printk(KERN_INFO "ttyS0 at 0x03f8 (irq = %d) is a 16550\n", state->irq);
  641. retval = tty_register_driver(hp_simserial_driver);
  642. if (retval) {
  643. printk(KERN_ERR "Couldn't register simserial driver\n");
  644. goto err_free_tty;
  645. }
  646. return 0;
  647. err_free_tty:
  648. put_tty_driver(hp_simserial_driver);
  649. return retval;
  650. }
  651. #ifndef MODULE
  652. __initcall(simrs_init);
  653. #endif