dz.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822
  1. /*
  2. * dz.c: Serial port driver for DECStations equiped
  3. * with the DZ chipset.
  4. *
  5. * Copyright (C) 1998 Olivier A. D. Lebaillif
  6. *
  7. * Email: olivier.lebaillif@ifrsys.com
  8. *
  9. * [31-AUG-98] triemer
  10. * Changed IRQ to use Harald's dec internals interrupts.h
  11. * removed base_addr code - moving address assignment to setup.c
  12. * Changed name of dz_init to rs_init to be consistent with tc code
  13. * [13-NOV-98] triemer fixed code to receive characters
  14. * after patches by harald to irq code.
  15. * [09-JAN-99] triemer minor fix for schedule - due to removal of timeout
  16. * field from "current" - somewhere between 2.1.121 and 2.1.131
  17. Qua Jun 27 15:02:26 BRT 2001
  18. * [27-JUN-2001] Arnaldo Carvalho de Melo <acme@conectiva.com.br> - cleanups
  19. *
  20. * Parts (C) 1999 David Airlie, airlied@linux.ie
  21. * [07-SEP-99] Bugfixes
  22. *
  23. * [06-Jan-2002] Russell King <rmk@arm.linux.org.uk>
  24. * Converted to new serial core
  25. */
  26. #undef DEBUG_DZ
  27. #include <linux/config.h>
  28. #include <linux/module.h>
  29. #include <linux/interrupt.h>
  30. #include <linux/init.h>
  31. #include <linux/console.h>
  32. #include <linux/tty.h>
  33. #include <linux/tty_flip.h>
  34. #include <linux/serial_core.h>
  35. #include <linux/serial.h>
  36. #include <asm/bootinfo.h>
  37. #include <asm/dec/interrupts.h>
  38. #include <asm/dec/kn01.h>
  39. #include <asm/dec/kn02.h>
  40. #include <asm/dec/machtype.h>
  41. #include <asm/dec/prom.h>
  42. #include <asm/irq.h>
  43. #include <asm/system.h>
  44. #include <asm/uaccess.h>
  45. #define CONSOLE_LINE (3) /* for definition of struct console */
  46. #include "dz.h"
  47. #define DZ_INTR_DEBUG 1
  48. static char *dz_name = "DECstation DZ serial driver version ";
  49. static char *dz_version = "1.02";
  50. struct dz_port {
  51. struct uart_port port;
  52. unsigned int cflag;
  53. };
  54. static struct dz_port dz_ports[DZ_NB_PORT];
  55. #ifdef DEBUG_DZ
  56. /*
  57. * debugging code to send out chars via prom
  58. */
  59. static void debug_console(const char *s, int count)
  60. {
  61. unsigned i;
  62. for (i = 0; i < count; i++) {
  63. if (*s == 10)
  64. prom_printf("%c", 13);
  65. prom_printf("%c", *s++);
  66. }
  67. }
  68. #endif
  69. /*
  70. * ------------------------------------------------------------
  71. * dz_in () and dz_out ()
  72. *
  73. * These routines are used to access the registers of the DZ
  74. * chip, hiding relocation differences between implementation.
  75. * ------------------------------------------------------------
  76. */
  77. static inline unsigned short dz_in(struct dz_port *dport, unsigned offset)
  78. {
  79. volatile unsigned short *addr =
  80. (volatile unsigned short *) (dport->port.membase + offset);
  81. return *addr;
  82. }
  83. static inline void dz_out(struct dz_port *dport, unsigned offset,
  84. unsigned short value)
  85. {
  86. volatile unsigned short *addr =
  87. (volatile unsigned short *) (dport->port.membase + offset);
  88. *addr = value;
  89. }
  90. /*
  91. * ------------------------------------------------------------
  92. * rs_stop () and rs_start ()
  93. *
  94. * These routines are called before setting or resetting
  95. * tty->stopped. They enable or disable transmitter interrupts,
  96. * as necessary.
  97. * ------------------------------------------------------------
  98. */
  99. static void dz_stop_tx(struct uart_port *uport)
  100. {
  101. struct dz_port *dport = (struct dz_port *)uport;
  102. unsigned short tmp, mask = 1 << dport->port.line;
  103. unsigned long flags;
  104. spin_lock_irqsave(&dport->port.lock, flags);
  105. tmp = dz_in(dport, DZ_TCR); /* read the TX flag */
  106. tmp &= ~mask; /* clear the TX flag */
  107. dz_out(dport, DZ_TCR, tmp);
  108. spin_unlock_irqrestore(&dport->port.lock, flags);
  109. }
  110. static void dz_start_tx(struct uart_port *uport)
  111. {
  112. struct dz_port *dport = (struct dz_port *)uport;
  113. unsigned short tmp, mask = 1 << dport->port.line;
  114. unsigned long flags;
  115. spin_lock_irqsave(&dport->port.lock, flags);
  116. tmp = dz_in(dport, DZ_TCR); /* read the TX flag */
  117. tmp |= mask; /* set the TX flag */
  118. dz_out(dport, DZ_TCR, tmp);
  119. spin_unlock_irqrestore(&dport->port.lock, flags);
  120. }
  121. static void dz_stop_rx(struct uart_port *uport)
  122. {
  123. struct dz_port *dport = (struct dz_port *)uport;
  124. unsigned long flags;
  125. spin_lock_irqsave(&dport->port.lock, flags);
  126. dport->cflag &= ~DZ_CREAD;
  127. dz_out(dport, DZ_LPR, dport->cflag);
  128. spin_unlock_irqrestore(&dport->port.lock, flags);
  129. }
  130. static void dz_enable_ms(struct uart_port *port)
  131. {
  132. /* nothing to do */
  133. }
  134. /*
  135. * ------------------------------------------------------------
  136. * Here starts the interrupt handling routines. All of the
  137. * following subroutines are declared as inline and are folded
  138. * into dz_interrupt. They were separated out for readability's
  139. * sake.
  140. *
  141. * Note: rs_interrupt() is a "fast" interrupt, which means that it
  142. * runs with interrupts turned off. People who may want to modify
  143. * rs_interrupt() should try to keep the interrupt handler as fast as
  144. * possible. After you are done making modifications, it is not a bad
  145. * idea to do:
  146. *
  147. * make drivers/serial/dz.s
  148. *
  149. * and look at the resulting assemble code in dz.s.
  150. *
  151. * ------------------------------------------------------------
  152. */
  153. /*
  154. * ------------------------------------------------------------
  155. * receive_char ()
  156. *
  157. * This routine deals with inputs from any lines.
  158. * ------------------------------------------------------------
  159. */
  160. static inline void dz_receive_chars(struct dz_port *dport)
  161. {
  162. struct tty_struct *tty = NULL;
  163. struct uart_icount *icount;
  164. int ignore = 0;
  165. unsigned short status, tmp;
  166. unsigned char ch, flag;
  167. /* this code is going to be a problem...
  168. the call to tty_flip_buffer is going to need
  169. to be rethought...
  170. */
  171. do {
  172. status = dz_in(dport, DZ_RBUF);
  173. /* punt so we don't get duplicate characters */
  174. if (!(status & DZ_DVAL))
  175. goto ignore_char;
  176. ch = UCHAR(status); /* grab the char */
  177. flag = TTY_NORMAL;
  178. #if 0
  179. if (info->is_console) {
  180. if (ch == 0)
  181. return; /* it's a break ... */
  182. }
  183. #endif
  184. tty = dport->port.info->tty;/* now tty points to the proper dev */
  185. icount = &dport->port.icount;
  186. if (!tty)
  187. break;
  188. if (tty->flip.count >= TTY_FLIPBUF_SIZE)
  189. break;
  190. icount->rx++;
  191. /* keep track of the statistics */
  192. if (status & (DZ_OERR | DZ_FERR | DZ_PERR)) {
  193. if (status & DZ_PERR) /* parity error */
  194. icount->parity++;
  195. else if (status & DZ_FERR) /* frame error */
  196. icount->frame++;
  197. if (status & DZ_OERR) /* overrun error */
  198. icount->overrun++;
  199. /* check to see if we should ignore the character
  200. and mask off conditions that should be ignored
  201. */
  202. if (status & dport->port.ignore_status_mask) {
  203. if (++ignore > 100)
  204. break;
  205. goto ignore_char;
  206. }
  207. /* mask off the error conditions we want to ignore */
  208. tmp = status & dport->port.read_status_mask;
  209. if (tmp & DZ_PERR) {
  210. flag = TTY_PARITY;
  211. #ifdef DEBUG_DZ
  212. debug_console("PERR\n", 5);
  213. #endif
  214. } else if (tmp & DZ_FERR) {
  215. flag = TTY_FRAME;
  216. #ifdef DEBUG_DZ
  217. debug_console("FERR\n", 5);
  218. #endif
  219. }
  220. if (tmp & DZ_OERR) {
  221. #ifdef DEBUG_DZ
  222. debug_console("OERR\n", 5);
  223. #endif
  224. tty_insert_flip_char(tty, ch, flag);
  225. ch = 0;
  226. flag = TTY_OVERRUN;
  227. }
  228. }
  229. tty_insert_flip_char(tty, ch, flag);
  230. ignore_char:
  231. } while (status & DZ_DVAL);
  232. if (tty)
  233. tty_flip_buffer_push(tty);
  234. }
  235. /*
  236. * ------------------------------------------------------------
  237. * transmit_char ()
  238. *
  239. * This routine deals with outputs to any lines.
  240. * ------------------------------------------------------------
  241. */
  242. static inline void dz_transmit_chars(struct dz_port *dport)
  243. {
  244. struct circ_buf *xmit = &dport->port.info->xmit;
  245. unsigned char tmp;
  246. if (dport->port.x_char) { /* XON/XOFF chars */
  247. dz_out(dport, DZ_TDR, dport->port.x_char);
  248. dport->port.icount.tx++;
  249. dport->port.x_char = 0;
  250. return;
  251. }
  252. /* if nothing to do or stopped or hardware stopped */
  253. if (uart_circ_empty(xmit) || uart_tx_stopped(&dport->port)) {
  254. dz_stop_tx(&dport->port);
  255. return;
  256. }
  257. /*
  258. * if something to do ... (rember the dz has no output fifo so we go
  259. * one char at a time :-<
  260. */
  261. tmp = xmit->buf[xmit->tail];
  262. xmit->tail = (xmit->tail + 1) & (DZ_XMIT_SIZE - 1);
  263. dz_out(dport, DZ_TDR, tmp);
  264. dport->port.icount.tx++;
  265. if (uart_circ_chars_pending(xmit) < DZ_WAKEUP_CHARS)
  266. uart_write_wakeup(&dport->port);
  267. /* Are we done */
  268. if (uart_circ_empty(xmit))
  269. dz_stop_tx(&dport->port);
  270. }
  271. /*
  272. * ------------------------------------------------------------
  273. * check_modem_status ()
  274. *
  275. * Only valid for the MODEM line duh !
  276. * ------------------------------------------------------------
  277. */
  278. static inline void check_modem_status(struct dz_port *dport)
  279. {
  280. unsigned short status;
  281. /* if not ne modem line just return */
  282. if (dport->port.line != DZ_MODEM)
  283. return;
  284. status = dz_in(dport, DZ_MSR);
  285. /* it's easy, since DSR2 is the only bit in the register */
  286. if (status)
  287. dport->port.icount.dsr++;
  288. }
  289. /*
  290. * ------------------------------------------------------------
  291. * dz_interrupt ()
  292. *
  293. * this is the main interrupt routine for the DZ chip.
  294. * It deals with the multiple ports.
  295. * ------------------------------------------------------------
  296. */
  297. static irqreturn_t dz_interrupt(int irq, void *dev, struct pt_regs *regs)
  298. {
  299. struct dz_port *dport;
  300. unsigned short status;
  301. /* get the reason why we just got an irq */
  302. status = dz_in((struct dz_port *)dev, DZ_CSR);
  303. dport = &dz_ports[LINE(status)];
  304. if (status & DZ_RDONE)
  305. dz_receive_chars(dport);
  306. if (status & DZ_TRDY)
  307. dz_transmit_chars(dport);
  308. /* FIXME: what about check modem status??? --rmk */
  309. return IRQ_HANDLED;
  310. }
  311. /*
  312. * -------------------------------------------------------------------
  313. * Here ends the DZ interrupt routines.
  314. * -------------------------------------------------------------------
  315. */
  316. static unsigned int dz_get_mctrl(struct uart_port *uport)
  317. {
  318. struct dz_port *dport = (struct dz_port *)uport;
  319. unsigned int mctrl = TIOCM_CAR | TIOCM_DSR | TIOCM_CTS;
  320. if (dport->port.line == DZ_MODEM) {
  321. /*
  322. * CHECKME: This is a guess from the other code... --rmk
  323. */
  324. if (dz_in(dport, DZ_MSR) & DZ_MODEM_DSR)
  325. mctrl &= ~TIOCM_DSR;
  326. }
  327. return mctrl;
  328. }
  329. static void dz_set_mctrl(struct uart_port *uport, unsigned int mctrl)
  330. {
  331. struct dz_port *dport = (struct dz_port *)uport;
  332. unsigned short tmp;
  333. if (dport->port.line == DZ_MODEM) {
  334. tmp = dz_in(dport, DZ_TCR);
  335. if (mctrl & TIOCM_DTR)
  336. tmp &= ~DZ_MODEM_DTR;
  337. else
  338. tmp |= DZ_MODEM_DTR;
  339. dz_out(dport, DZ_TCR, tmp);
  340. }
  341. }
  342. /*
  343. * -------------------------------------------------------------------
  344. * startup ()
  345. *
  346. * various initialization tasks
  347. * -------------------------------------------------------------------
  348. */
  349. static int dz_startup(struct uart_port *uport)
  350. {
  351. struct dz_port *dport = (struct dz_port *)uport;
  352. unsigned long flags;
  353. unsigned short tmp;
  354. /* The dz lines for the mouse/keyboard must be
  355. * opened using their respective drivers.
  356. */
  357. if ((dport->port.line == DZ_KEYBOARD) ||
  358. (dport->port.line == DZ_MOUSE))
  359. return -ENODEV;
  360. spin_lock_irqsave(&dport->port.lock, flags);
  361. /* enable the interrupt and the scanning */
  362. tmp = dz_in(dport, DZ_CSR);
  363. tmp |= DZ_RIE | DZ_TIE | DZ_MSE;
  364. dz_out(dport, DZ_CSR, tmp);
  365. spin_unlock_irqrestore(&dport->port.lock, flags);
  366. return 0;
  367. }
  368. /*
  369. * -------------------------------------------------------------------
  370. * shutdown ()
  371. *
  372. * This routine will shutdown a serial port; interrupts are disabled, and
  373. * DTR is dropped if the hangup on close termio flag is on.
  374. * -------------------------------------------------------------------
  375. */
  376. static void dz_shutdown(struct uart_port *uport)
  377. {
  378. dz_stop_tx(uport);
  379. }
  380. /*
  381. * get_lsr_info - get line status register info
  382. *
  383. * Purpose: Let user call ioctl() to get info when the UART physically
  384. * is emptied. On bus types like RS485, the transmitter must
  385. * release the bus after transmitting. This must be done when
  386. * the transmit shift register is empty, not be done when the
  387. * transmit holding register is empty. This functionality
  388. * allows an RS485 driver to be written in user space.
  389. */
  390. static unsigned int dz_tx_empty(struct uart_port *uport)
  391. {
  392. struct dz_port *dport = (struct dz_port *)uport;
  393. unsigned short status = dz_in(dport, DZ_LPR);
  394. /* FIXME: this appears to be obviously broken --rmk. */
  395. return status ? TIOCSER_TEMT : 0;
  396. }
  397. static void dz_break_ctl(struct uart_port *uport, int break_state)
  398. {
  399. struct dz_port *dport = (struct dz_port *)uport;
  400. unsigned long flags;
  401. unsigned short tmp, mask = 1 << uport->line;
  402. spin_lock_irqsave(&uport->lock, flags);
  403. tmp = dz_in(dport, DZ_TCR);
  404. if (break_state)
  405. tmp |= mask;
  406. else
  407. tmp &= ~mask;
  408. dz_out(dport, DZ_TCR, tmp);
  409. spin_unlock_irqrestore(&uport->lock, flags);
  410. }
  411. static void dz_set_termios(struct uart_port *uport, struct termios *termios,
  412. struct termios *old_termios)
  413. {
  414. struct dz_port *dport = (struct dz_port *)uport;
  415. unsigned long flags;
  416. unsigned int cflag, baud;
  417. cflag = dport->port.line;
  418. switch (termios->c_cflag & CSIZE) {
  419. case CS5:
  420. cflag |= DZ_CS5;
  421. break;
  422. case CS6:
  423. cflag |= DZ_CS6;
  424. break;
  425. case CS7:
  426. cflag |= DZ_CS7;
  427. break;
  428. case CS8:
  429. default:
  430. cflag |= DZ_CS8;
  431. }
  432. if (termios->c_cflag & CSTOPB)
  433. cflag |= DZ_CSTOPB;
  434. if (termios->c_cflag & PARENB)
  435. cflag |= DZ_PARENB;
  436. if (termios->c_cflag & PARODD)
  437. cflag |= DZ_PARODD;
  438. baud = uart_get_baud_rate(uport, termios, old_termios, 50, 9600);
  439. switch (baud) {
  440. case 50:
  441. cflag |= DZ_B50;
  442. break;
  443. case 75:
  444. cflag |= DZ_B75;
  445. break;
  446. case 110:
  447. cflag |= DZ_B110;
  448. break;
  449. case 134:
  450. cflag |= DZ_B134;
  451. break;
  452. case 150:
  453. cflag |= DZ_B150;
  454. break;
  455. case 300:
  456. cflag |= DZ_B300;
  457. break;
  458. case 600:
  459. cflag |= DZ_B600;
  460. break;
  461. case 1200:
  462. cflag |= DZ_B1200;
  463. break;
  464. case 1800:
  465. cflag |= DZ_B1800;
  466. break;
  467. case 2000:
  468. cflag |= DZ_B2000;
  469. break;
  470. case 2400:
  471. cflag |= DZ_B2400;
  472. break;
  473. case 3600:
  474. cflag |= DZ_B3600;
  475. break;
  476. case 4800:
  477. cflag |= DZ_B4800;
  478. break;
  479. case 7200:
  480. cflag |= DZ_B7200;
  481. break;
  482. case 9600:
  483. default:
  484. cflag |= DZ_B9600;
  485. }
  486. if (termios->c_cflag & CREAD)
  487. cflag |= DZ_RXENAB;
  488. spin_lock_irqsave(&dport->port.lock, flags);
  489. dz_out(dport, DZ_LPR, cflag);
  490. dport->cflag = cflag;
  491. /* setup accept flag */
  492. dport->port.read_status_mask = DZ_OERR;
  493. if (termios->c_iflag & INPCK)
  494. dport->port.read_status_mask |= DZ_FERR | DZ_PERR;
  495. /* characters to ignore */
  496. uport->ignore_status_mask = 0;
  497. if (termios->c_iflag & IGNPAR)
  498. dport->port.ignore_status_mask |= DZ_FERR | DZ_PERR;
  499. spin_unlock_irqrestore(&dport->port.lock, flags);
  500. }
  501. static const char *dz_type(struct uart_port *port)
  502. {
  503. return "DZ";
  504. }
  505. static void dz_release_port(struct uart_port *port)
  506. {
  507. /* nothing to do */
  508. }
  509. static int dz_request_port(struct uart_port *port)
  510. {
  511. return 0;
  512. }
  513. static void dz_config_port(struct uart_port *port, int flags)
  514. {
  515. if (flags & UART_CONFIG_TYPE)
  516. port->type = PORT_DZ;
  517. }
  518. /*
  519. * verify the new serial_struct (for TIOCSSERIAL).
  520. */
  521. static int dz_verify_port(struct uart_port *port, struct serial_struct *ser)
  522. {
  523. int ret = 0;
  524. if (ser->type != PORT_UNKNOWN && ser->type != PORT_DZ)
  525. ret = -EINVAL;
  526. if (ser->irq != port->irq)
  527. ret = -EINVAL;
  528. return ret;
  529. }
  530. static struct uart_ops dz_ops = {
  531. .tx_empty = dz_tx_empty,
  532. .get_mctrl = dz_get_mctrl,
  533. .set_mctrl = dz_set_mctrl,
  534. .stop_tx = dz_stop_tx,
  535. .start_tx = dz_start_tx,
  536. .stop_rx = dz_stop_rx,
  537. .enable_ms = dz_enable_ms,
  538. .break_ctl = dz_break_ctl,
  539. .startup = dz_startup,
  540. .shutdown = dz_shutdown,
  541. .set_termios = dz_set_termios,
  542. .type = dz_type,
  543. .release_port = dz_release_port,
  544. .request_port = dz_request_port,
  545. .config_port = dz_config_port,
  546. .verify_port = dz_verify_port,
  547. };
  548. static void __init dz_init_ports(void)
  549. {
  550. static int first = 1;
  551. struct dz_port *dport;
  552. unsigned long base;
  553. int i;
  554. if (!first)
  555. return;
  556. first = 0;
  557. if (mips_machtype == MACH_DS23100 ||
  558. mips_machtype == MACH_DS5100)
  559. base = (unsigned long) KN01_DZ11_BASE;
  560. else
  561. base = (unsigned long) KN02_DZ11_BASE;
  562. for (i = 0, dport = dz_ports; i < DZ_NB_PORT; i++, dport++) {
  563. spin_lock_init(&dport->port.lock);
  564. dport->port.membase = (char *) base;
  565. dport->port.iotype = SERIAL_IO_PORT;
  566. dport->port.irq = dec_interrupt[DEC_IRQ_DZ11];
  567. dport->port.line = i;
  568. dport->port.fifosize = 1;
  569. dport->port.ops = &dz_ops;
  570. dport->port.flags = UPF_BOOT_AUTOCONF;
  571. }
  572. }
  573. static void dz_reset(struct dz_port *dport)
  574. {
  575. dz_out(dport, DZ_CSR, DZ_CLR);
  576. while (dz_in(dport, DZ_CSR) & DZ_CLR);
  577. /* FIXME: cpu_relax? */
  578. iob();
  579. /* enable scanning */
  580. dz_out(dport, DZ_CSR, DZ_MSE);
  581. }
  582. #ifdef CONFIG_SERIAL_DZ_CONSOLE
  583. static void dz_console_put_char(struct dz_port *dport, unsigned char ch)
  584. {
  585. unsigned long flags;
  586. int loops = 2500;
  587. unsigned short tmp = ch;
  588. /* this code sends stuff out to serial device - spinning its
  589. wheels and waiting. */
  590. spin_lock_irqsave(&dport->port.lock, flags);
  591. /* spin our wheels */
  592. while (((dz_in(dport, DZ_CSR) & DZ_TRDY) != DZ_TRDY) && loops--)
  593. /* FIXME: cpu_relax, udelay? --rmk */
  594. ;
  595. /* Actually transmit the character. */
  596. dz_out(dport, DZ_TDR, tmp);
  597. spin_unlock_irqrestore(&dport->port.lock, flags);
  598. }
  599. /*
  600. * -------------------------------------------------------------------
  601. * dz_console_print ()
  602. *
  603. * dz_console_print is registered for printk.
  604. * The console must be locked when we get here.
  605. * -------------------------------------------------------------------
  606. */
  607. static void dz_console_print(struct console *cons,
  608. const char *str,
  609. unsigned int count)
  610. {
  611. struct dz_port *dport = &dz_ports[CONSOLE_LINE];
  612. #ifdef DEBUG_DZ
  613. prom_printf((char *) str);
  614. #endif
  615. while (count--) {
  616. if (*str == '\n')
  617. dz_console_put_char(dport, '\r');
  618. dz_console_put_char(dport, *str++);
  619. }
  620. }
  621. static int __init dz_console_setup(struct console *co, char *options)
  622. {
  623. struct dz_port *dport = &dz_ports[CONSOLE_LINE];
  624. int baud = 9600;
  625. int bits = 8;
  626. int parity = 'n';
  627. int flow = 'n';
  628. int ret;
  629. unsigned short mask, tmp;
  630. if (options)
  631. uart_parse_options(options, &baud, &parity, &bits, &flow);
  632. dz_reset(dport);
  633. ret = uart_set_options(&dport->port, co, baud, parity, bits, flow);
  634. if (ret == 0) {
  635. mask = 1 << dport->port.line;
  636. tmp = dz_in(dport, DZ_TCR); /* read the TX flag */
  637. if (!(tmp & mask)) {
  638. tmp |= mask; /* set the TX flag */
  639. dz_out(dport, DZ_TCR, tmp);
  640. }
  641. }
  642. return ret;
  643. }
  644. static struct console dz_sercons =
  645. {
  646. .name = "ttyS",
  647. .write = dz_console_print,
  648. .device = uart_console_device,
  649. .setup = dz_console_setup,
  650. .flags = CON_CONSDEV | CON_PRINTBUFFER,
  651. .index = CONSOLE_LINE,
  652. };
  653. void __init dz_serial_console_init(void)
  654. {
  655. dz_init_ports();
  656. register_console(&dz_sercons);
  657. }
  658. #define SERIAL_DZ_CONSOLE &dz_sercons
  659. #else
  660. #define SERIAL_DZ_CONSOLE NULL
  661. #endif /* CONFIG_SERIAL_DZ_CONSOLE */
  662. static struct uart_driver dz_reg = {
  663. .owner = THIS_MODULE,
  664. .driver_name = "serial",
  665. #ifdef CONFIG_DEVFS
  666. .dev_name = "tts/%d",
  667. #else
  668. .dev_name = "ttyS%d",
  669. #endif
  670. .major = TTY_MAJOR,
  671. .minor = 64,
  672. .nr = DZ_NB_PORT,
  673. .cons = SERIAL_DZ_CONSOLE,
  674. };
  675. int __init dz_init(void)
  676. {
  677. unsigned long flags;
  678. int ret, i;
  679. printk("%s%s\n", dz_name, dz_version);
  680. dz_init_ports();
  681. save_flags(flags);
  682. cli();
  683. #ifndef CONFIG_SERIAL_DZ_CONSOLE
  684. /* reset the chip */
  685. dz_reset(&dz_ports[0]);
  686. #endif
  687. /* order matters here... the trick is that flags
  688. is updated... in request_irq - to immediatedly obliterate
  689. it is unwise. */
  690. restore_flags(flags);
  691. if (request_irq(dz_ports[0].port.irq, dz_interrupt,
  692. SA_INTERRUPT, "DZ", &dz_ports[0]))
  693. panic("Unable to register DZ interrupt");
  694. ret = uart_register_driver(&dz_reg);
  695. if (ret != 0)
  696. return ret;
  697. for (i = 0; i < DZ_NB_PORT; i++)
  698. uart_add_one_port(&dz_reg, &dz_ports[i].port);
  699. return ret;
  700. }
  701. MODULE_DESCRIPTION("DECstation DZ serial driver");
  702. MODULE_LICENSE("GPL");