dz.c 19 KB

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