dz.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820
  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. icount->rx++;
  189. /* keep track of the statistics */
  190. if (status & (DZ_OERR | DZ_FERR | DZ_PERR)) {
  191. if (status & DZ_PERR) /* parity error */
  192. icount->parity++;
  193. else if (status & DZ_FERR) /* frame error */
  194. icount->frame++;
  195. if (status & DZ_OERR) /* overrun error */
  196. icount->overrun++;
  197. /* check to see if we should ignore the character
  198. and mask off conditions that should be ignored
  199. */
  200. if (status & dport->port.ignore_status_mask) {
  201. if (++ignore > 100)
  202. break;
  203. goto ignore_char;
  204. }
  205. /* mask off the error conditions we want to ignore */
  206. tmp = status & dport->port.read_status_mask;
  207. if (tmp & DZ_PERR) {
  208. flag = TTY_PARITY;
  209. #ifdef DEBUG_DZ
  210. debug_console("PERR\n", 5);
  211. #endif
  212. } else if (tmp & DZ_FERR) {
  213. flag = TTY_FRAME;
  214. #ifdef DEBUG_DZ
  215. debug_console("FERR\n", 5);
  216. #endif
  217. }
  218. if (tmp & DZ_OERR) {
  219. #ifdef DEBUG_DZ
  220. debug_console("OERR\n", 5);
  221. #endif
  222. tty_insert_flip_char(tty, ch, flag);
  223. ch = 0;
  224. flag = TTY_OVERRUN;
  225. }
  226. }
  227. tty_insert_flip_char(tty, ch, flag);
  228. ignore_char:
  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, struct pt_regs *regs)
  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 = SERIAL_IO_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_put_char(struct dz_port *dport, unsigned char ch)
  582. {
  583. unsigned long flags;
  584. int loops = 2500;
  585. unsigned short tmp = ch;
  586. /* this code sends stuff out to serial device - spinning its
  587. wheels and waiting. */
  588. spin_lock_irqsave(&dport->port.lock, flags);
  589. /* spin our wheels */
  590. while (((dz_in(dport, DZ_CSR) & DZ_TRDY) != DZ_TRDY) && loops--)
  591. /* FIXME: cpu_relax, udelay? --rmk */
  592. ;
  593. /* Actually transmit the character. */
  594. dz_out(dport, DZ_TDR, tmp);
  595. spin_unlock_irqrestore(&dport->port.lock, flags);
  596. }
  597. /*
  598. * -------------------------------------------------------------------
  599. * dz_console_print ()
  600. *
  601. * dz_console_print is registered for printk.
  602. * The console must be locked when we get here.
  603. * -------------------------------------------------------------------
  604. */
  605. static void dz_console_print(struct console *cons,
  606. const char *str,
  607. unsigned int count)
  608. {
  609. struct dz_port *dport = &dz_ports[CONSOLE_LINE];
  610. #ifdef DEBUG_DZ
  611. prom_printf((char *) str);
  612. #endif
  613. while (count--) {
  614. if (*str == '\n')
  615. dz_console_put_char(dport, '\r');
  616. dz_console_put_char(dport, *str++);
  617. }
  618. }
  619. static int __init dz_console_setup(struct console *co, char *options)
  620. {
  621. struct dz_port *dport = &dz_ports[CONSOLE_LINE];
  622. int baud = 9600;
  623. int bits = 8;
  624. int parity = 'n';
  625. int flow = 'n';
  626. int ret;
  627. unsigned short mask, tmp;
  628. if (options)
  629. uart_parse_options(options, &baud, &parity, &bits, &flow);
  630. dz_reset(dport);
  631. ret = uart_set_options(&dport->port, co, baud, parity, bits, flow);
  632. if (ret == 0) {
  633. mask = 1 << dport->port.line;
  634. tmp = dz_in(dport, DZ_TCR); /* read the TX flag */
  635. if (!(tmp & mask)) {
  636. tmp |= mask; /* set the TX flag */
  637. dz_out(dport, DZ_TCR, tmp);
  638. }
  639. }
  640. return ret;
  641. }
  642. static struct console dz_sercons =
  643. {
  644. .name = "ttyS",
  645. .write = dz_console_print,
  646. .device = uart_console_device,
  647. .setup = dz_console_setup,
  648. .flags = CON_CONSDEV | CON_PRINTBUFFER,
  649. .index = CONSOLE_LINE,
  650. };
  651. void __init dz_serial_console_init(void)
  652. {
  653. dz_init_ports();
  654. register_console(&dz_sercons);
  655. }
  656. #define SERIAL_DZ_CONSOLE &dz_sercons
  657. #else
  658. #define SERIAL_DZ_CONSOLE NULL
  659. #endif /* CONFIG_SERIAL_DZ_CONSOLE */
  660. static struct uart_driver dz_reg = {
  661. .owner = THIS_MODULE,
  662. .driver_name = "serial",
  663. #ifdef CONFIG_DEVFS
  664. .dev_name = "tts/%d",
  665. #else
  666. .dev_name = "ttyS%d",
  667. #endif
  668. .major = TTY_MAJOR,
  669. .minor = 64,
  670. .nr = DZ_NB_PORT,
  671. .cons = SERIAL_DZ_CONSOLE,
  672. };
  673. int __init dz_init(void)
  674. {
  675. unsigned long flags;
  676. int ret, i;
  677. printk("%s%s\n", dz_name, dz_version);
  678. dz_init_ports();
  679. save_flags(flags);
  680. cli();
  681. #ifndef CONFIG_SERIAL_DZ_CONSOLE
  682. /* reset the chip */
  683. dz_reset(&dz_ports[0]);
  684. #endif
  685. /* order matters here... the trick is that flags
  686. is updated... in request_irq - to immediatedly obliterate
  687. it is unwise. */
  688. restore_flags(flags);
  689. if (request_irq(dz_ports[0].port.irq, dz_interrupt,
  690. SA_INTERRUPT, "DZ", &dz_ports[0]))
  691. panic("Unable to register DZ interrupt");
  692. ret = uart_register_driver(&dz_reg);
  693. if (ret != 0)
  694. return ret;
  695. for (i = 0; i < DZ_NB_PORT; i++)
  696. uart_add_one_port(&dz_reg, &dz_ports[i].port);
  697. return ret;
  698. }
  699. MODULE_DESCRIPTION("DECstation DZ serial driver");
  700. MODULE_LICENSE("GPL");