dz.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819
  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. ;
  230. } while (status & DZ_DVAL);
  231. if (tty)
  232. tty_flip_buffer_push(tty);
  233. }
  234. /*
  235. * ------------------------------------------------------------
  236. * transmit_char ()
  237. *
  238. * This routine deals with outputs to any lines.
  239. * ------------------------------------------------------------
  240. */
  241. static inline void dz_transmit_chars(struct dz_port *dport)
  242. {
  243. struct circ_buf *xmit = &dport->port.info->xmit;
  244. unsigned char tmp;
  245. if (dport->port.x_char) { /* XON/XOFF chars */
  246. dz_out(dport, DZ_TDR, dport->port.x_char);
  247. dport->port.icount.tx++;
  248. dport->port.x_char = 0;
  249. return;
  250. }
  251. /* if nothing to do or stopped or hardware stopped */
  252. if (uart_circ_empty(xmit) || uart_tx_stopped(&dport->port)) {
  253. dz_stop_tx(&dport->port);
  254. return;
  255. }
  256. /*
  257. * if something to do ... (rember the dz has no output fifo so we go
  258. * one char at a time :-<
  259. */
  260. tmp = xmit->buf[xmit->tail];
  261. xmit->tail = (xmit->tail + 1) & (DZ_XMIT_SIZE - 1);
  262. dz_out(dport, DZ_TDR, tmp);
  263. dport->port.icount.tx++;
  264. if (uart_circ_chars_pending(xmit) < DZ_WAKEUP_CHARS)
  265. uart_write_wakeup(&dport->port);
  266. /* Are we done */
  267. if (uart_circ_empty(xmit))
  268. dz_stop_tx(&dport->port);
  269. }
  270. /*
  271. * ------------------------------------------------------------
  272. * check_modem_status ()
  273. *
  274. * Only valid for the MODEM line duh !
  275. * ------------------------------------------------------------
  276. */
  277. static inline void check_modem_status(struct dz_port *dport)
  278. {
  279. unsigned short status;
  280. /* if not ne modem line just return */
  281. if (dport->port.line != DZ_MODEM)
  282. return;
  283. status = dz_in(dport, DZ_MSR);
  284. /* it's easy, since DSR2 is the only bit in the register */
  285. if (status)
  286. dport->port.icount.dsr++;
  287. }
  288. /*
  289. * ------------------------------------------------------------
  290. * dz_interrupt ()
  291. *
  292. * this is the main interrupt routine for the DZ chip.
  293. * It deals with the multiple ports.
  294. * ------------------------------------------------------------
  295. */
  296. static irqreturn_t dz_interrupt(int irq, void *dev, struct pt_regs *regs)
  297. {
  298. struct dz_port *dport;
  299. unsigned short status;
  300. /* get the reason why we just got an irq */
  301. status = dz_in((struct dz_port *)dev, DZ_CSR);
  302. dport = &dz_ports[LINE(status)];
  303. if (status & DZ_RDONE)
  304. dz_receive_chars(dport);
  305. if (status & DZ_TRDY)
  306. dz_transmit_chars(dport);
  307. /* FIXME: what about check modem status??? --rmk */
  308. return IRQ_HANDLED;
  309. }
  310. /*
  311. * -------------------------------------------------------------------
  312. * Here ends the DZ interrupt routines.
  313. * -------------------------------------------------------------------
  314. */
  315. static unsigned int dz_get_mctrl(struct uart_port *uport)
  316. {
  317. struct dz_port *dport = (struct dz_port *)uport;
  318. unsigned int mctrl = TIOCM_CAR | TIOCM_DSR | TIOCM_CTS;
  319. if (dport->port.line == DZ_MODEM) {
  320. /*
  321. * CHECKME: This is a guess from the other code... --rmk
  322. */
  323. if (dz_in(dport, DZ_MSR) & DZ_MODEM_DSR)
  324. mctrl &= ~TIOCM_DSR;
  325. }
  326. return mctrl;
  327. }
  328. static void dz_set_mctrl(struct uart_port *uport, unsigned int mctrl)
  329. {
  330. struct dz_port *dport = (struct dz_port *)uport;
  331. unsigned short tmp;
  332. if (dport->port.line == DZ_MODEM) {
  333. tmp = dz_in(dport, DZ_TCR);
  334. if (mctrl & TIOCM_DTR)
  335. tmp &= ~DZ_MODEM_DTR;
  336. else
  337. tmp |= DZ_MODEM_DTR;
  338. dz_out(dport, DZ_TCR, tmp);
  339. }
  340. }
  341. /*
  342. * -------------------------------------------------------------------
  343. * startup ()
  344. *
  345. * various initialization tasks
  346. * -------------------------------------------------------------------
  347. */
  348. static int dz_startup(struct uart_port *uport)
  349. {
  350. struct dz_port *dport = (struct dz_port *)uport;
  351. unsigned long flags;
  352. unsigned short tmp;
  353. /* The dz lines for the mouse/keyboard must be
  354. * opened using their respective drivers.
  355. */
  356. if ((dport->port.line == DZ_KEYBOARD) ||
  357. (dport->port.line == DZ_MOUSE))
  358. return -ENODEV;
  359. spin_lock_irqsave(&dport->port.lock, flags);
  360. /* enable the interrupt and the scanning */
  361. tmp = dz_in(dport, DZ_CSR);
  362. tmp |= DZ_RIE | DZ_TIE | DZ_MSE;
  363. dz_out(dport, DZ_CSR, tmp);
  364. spin_unlock_irqrestore(&dport->port.lock, flags);
  365. return 0;
  366. }
  367. /*
  368. * -------------------------------------------------------------------
  369. * shutdown ()
  370. *
  371. * This routine will shutdown a serial port; interrupts are disabled, and
  372. * DTR is dropped if the hangup on close termio flag is on.
  373. * -------------------------------------------------------------------
  374. */
  375. static void dz_shutdown(struct uart_port *uport)
  376. {
  377. dz_stop_tx(uport);
  378. }
  379. /*
  380. * get_lsr_info - get line status register info
  381. *
  382. * Purpose: Let user call ioctl() to get info when the UART physically
  383. * is emptied. On bus types like RS485, the transmitter must
  384. * release the bus after transmitting. This must be done when
  385. * the transmit shift register is empty, not be done when the
  386. * transmit holding register is empty. This functionality
  387. * allows an RS485 driver to be written in user space.
  388. */
  389. static unsigned int dz_tx_empty(struct uart_port *uport)
  390. {
  391. struct dz_port *dport = (struct dz_port *)uport;
  392. unsigned short status = dz_in(dport, DZ_LPR);
  393. /* FIXME: this appears to be obviously broken --rmk. */
  394. return status ? TIOCSER_TEMT : 0;
  395. }
  396. static void dz_break_ctl(struct uart_port *uport, int break_state)
  397. {
  398. struct dz_port *dport = (struct dz_port *)uport;
  399. unsigned long flags;
  400. unsigned short tmp, mask = 1 << uport->line;
  401. spin_lock_irqsave(&uport->lock, flags);
  402. tmp = dz_in(dport, DZ_TCR);
  403. if (break_state)
  404. tmp |= mask;
  405. else
  406. tmp &= ~mask;
  407. dz_out(dport, DZ_TCR, tmp);
  408. spin_unlock_irqrestore(&uport->lock, flags);
  409. }
  410. static void dz_set_termios(struct uart_port *uport, struct termios *termios,
  411. struct termios *old_termios)
  412. {
  413. struct dz_port *dport = (struct dz_port *)uport;
  414. unsigned long flags;
  415. unsigned int cflag, baud;
  416. cflag = dport->port.line;
  417. switch (termios->c_cflag & CSIZE) {
  418. case CS5:
  419. cflag |= DZ_CS5;
  420. break;
  421. case CS6:
  422. cflag |= DZ_CS6;
  423. break;
  424. case CS7:
  425. cflag |= DZ_CS7;
  426. break;
  427. case CS8:
  428. default:
  429. cflag |= DZ_CS8;
  430. }
  431. if (termios->c_cflag & CSTOPB)
  432. cflag |= DZ_CSTOPB;
  433. if (termios->c_cflag & PARENB)
  434. cflag |= DZ_PARENB;
  435. if (termios->c_cflag & PARODD)
  436. cflag |= DZ_PARODD;
  437. baud = uart_get_baud_rate(uport, termios, old_termios, 50, 9600);
  438. switch (baud) {
  439. case 50:
  440. cflag |= DZ_B50;
  441. break;
  442. case 75:
  443. cflag |= DZ_B75;
  444. break;
  445. case 110:
  446. cflag |= DZ_B110;
  447. break;
  448. case 134:
  449. cflag |= DZ_B134;
  450. break;
  451. case 150:
  452. cflag |= DZ_B150;
  453. break;
  454. case 300:
  455. cflag |= DZ_B300;
  456. break;
  457. case 600:
  458. cflag |= DZ_B600;
  459. break;
  460. case 1200:
  461. cflag |= DZ_B1200;
  462. break;
  463. case 1800:
  464. cflag |= DZ_B1800;
  465. break;
  466. case 2000:
  467. cflag |= DZ_B2000;
  468. break;
  469. case 2400:
  470. cflag |= DZ_B2400;
  471. break;
  472. case 3600:
  473. cflag |= DZ_B3600;
  474. break;
  475. case 4800:
  476. cflag |= DZ_B4800;
  477. break;
  478. case 7200:
  479. cflag |= DZ_B7200;
  480. break;
  481. case 9600:
  482. default:
  483. cflag |= DZ_B9600;
  484. }
  485. if (termios->c_cflag & CREAD)
  486. cflag |= DZ_RXENAB;
  487. spin_lock_irqsave(&dport->port.lock, flags);
  488. dz_out(dport, DZ_LPR, cflag);
  489. dport->cflag = cflag;
  490. /* setup accept flag */
  491. dport->port.read_status_mask = DZ_OERR;
  492. if (termios->c_iflag & INPCK)
  493. dport->port.read_status_mask |= DZ_FERR | DZ_PERR;
  494. /* characters to ignore */
  495. uport->ignore_status_mask = 0;
  496. if (termios->c_iflag & IGNPAR)
  497. dport->port.ignore_status_mask |= DZ_FERR | DZ_PERR;
  498. spin_unlock_irqrestore(&dport->port.lock, flags);
  499. }
  500. static const char *dz_type(struct uart_port *port)
  501. {
  502. return "DZ";
  503. }
  504. static void dz_release_port(struct uart_port *port)
  505. {
  506. /* nothing to do */
  507. }
  508. static int dz_request_port(struct uart_port *port)
  509. {
  510. return 0;
  511. }
  512. static void dz_config_port(struct uart_port *port, int flags)
  513. {
  514. if (flags & UART_CONFIG_TYPE)
  515. port->type = PORT_DZ;
  516. }
  517. /*
  518. * verify the new serial_struct (for TIOCSSERIAL).
  519. */
  520. static int dz_verify_port(struct uart_port *port, struct serial_struct *ser)
  521. {
  522. int ret = 0;
  523. if (ser->type != PORT_UNKNOWN && ser->type != PORT_DZ)
  524. ret = -EINVAL;
  525. if (ser->irq != port->irq)
  526. ret = -EINVAL;
  527. return ret;
  528. }
  529. static struct uart_ops dz_ops = {
  530. .tx_empty = dz_tx_empty,
  531. .get_mctrl = dz_get_mctrl,
  532. .set_mctrl = dz_set_mctrl,
  533. .stop_tx = dz_stop_tx,
  534. .start_tx = dz_start_tx,
  535. .stop_rx = dz_stop_rx,
  536. .enable_ms = dz_enable_ms,
  537. .break_ctl = dz_break_ctl,
  538. .startup = dz_startup,
  539. .shutdown = dz_shutdown,
  540. .set_termios = dz_set_termios,
  541. .type = dz_type,
  542. .release_port = dz_release_port,
  543. .request_port = dz_request_port,
  544. .config_port = dz_config_port,
  545. .verify_port = dz_verify_port,
  546. };
  547. static void __init dz_init_ports(void)
  548. {
  549. static int first = 1;
  550. struct dz_port *dport;
  551. unsigned long base;
  552. int i;
  553. if (!first)
  554. return;
  555. first = 0;
  556. if (mips_machtype == MACH_DS23100 ||
  557. mips_machtype == MACH_DS5100)
  558. base = CKSEG1ADDR(KN01_SLOT_BASE + KN01_DZ11);
  559. else
  560. base = CKSEG1ADDR(KN02_SLOT_BASE + KN02_DZ11);
  561. for (i = 0, dport = dz_ports; i < DZ_NB_PORT; i++, dport++) {
  562. spin_lock_init(&dport->port.lock);
  563. dport->port.membase = (char *) base;
  564. dport->port.iotype = UPIO_PORT;
  565. dport->port.irq = dec_interrupt[DEC_IRQ_DZ11];
  566. dport->port.line = i;
  567. dport->port.fifosize = 1;
  568. dport->port.ops = &dz_ops;
  569. dport->port.flags = UPF_BOOT_AUTOCONF;
  570. }
  571. }
  572. static void dz_reset(struct dz_port *dport)
  573. {
  574. dz_out(dport, DZ_CSR, DZ_CLR);
  575. while (dz_in(dport, DZ_CSR) & DZ_CLR);
  576. /* FIXME: cpu_relax? */
  577. iob();
  578. /* enable scanning */
  579. dz_out(dport, DZ_CSR, DZ_MSE);
  580. }
  581. #ifdef CONFIG_SERIAL_DZ_CONSOLE
  582. static void dz_console_putchar(struct uart_port *port, int ch)
  583. {
  584. struct dz_port *dport = (struct dz_port *)uport;
  585. unsigned long flags;
  586. int loops = 2500;
  587. unsigned short tmp = (unsigned char)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. uart_console_write(&dport->port, str, count, dz_console_putchar);
  616. }
  617. static int __init dz_console_setup(struct console *co, char *options)
  618. {
  619. struct dz_port *dport = &dz_ports[CONSOLE_LINE];
  620. int baud = 9600;
  621. int bits = 8;
  622. int parity = 'n';
  623. int flow = 'n';
  624. int ret;
  625. unsigned short mask, tmp;
  626. if (options)
  627. uart_parse_options(options, &baud, &parity, &bits, &flow);
  628. dz_reset(dport);
  629. ret = uart_set_options(&dport->port, co, baud, parity, bits, flow);
  630. if (ret == 0) {
  631. mask = 1 << dport->port.line;
  632. tmp = dz_in(dport, DZ_TCR); /* read the TX flag */
  633. if (!(tmp & mask)) {
  634. tmp |= mask; /* set the TX flag */
  635. dz_out(dport, DZ_TCR, tmp);
  636. }
  637. }
  638. return ret;
  639. }
  640. static struct console dz_sercons =
  641. {
  642. .name = "ttyS",
  643. .write = dz_console_print,
  644. .device = uart_console_device,
  645. .setup = dz_console_setup,
  646. .flags = CON_CONSDEV | CON_PRINTBUFFER,
  647. .index = CONSOLE_LINE,
  648. };
  649. void __init dz_serial_console_init(void)
  650. {
  651. dz_init_ports();
  652. register_console(&dz_sercons);
  653. }
  654. #define SERIAL_DZ_CONSOLE &dz_sercons
  655. #else
  656. #define SERIAL_DZ_CONSOLE NULL
  657. #endif /* CONFIG_SERIAL_DZ_CONSOLE */
  658. static struct uart_driver dz_reg = {
  659. .owner = THIS_MODULE,
  660. .driver_name = "serial",
  661. #ifdef CONFIG_DEVFS
  662. .dev_name = "tts/%d",
  663. #else
  664. .dev_name = "ttyS%d",
  665. #endif
  666. .major = TTY_MAJOR,
  667. .minor = 64,
  668. .nr = DZ_NB_PORT,
  669. .cons = SERIAL_DZ_CONSOLE,
  670. };
  671. int __init dz_init(void)
  672. {
  673. unsigned long flags;
  674. int ret, i;
  675. printk("%s%s\n", dz_name, dz_version);
  676. dz_init_ports();
  677. save_flags(flags);
  678. cli();
  679. #ifndef CONFIG_SERIAL_DZ_CONSOLE
  680. /* reset the chip */
  681. dz_reset(&dz_ports[0]);
  682. #endif
  683. /* order matters here... the trick is that flags
  684. is updated... in request_irq - to immediatedly obliterate
  685. it is unwise. */
  686. restore_flags(flags);
  687. if (request_irq(dz_ports[0].port.irq, dz_interrupt,
  688. SA_INTERRUPT, "DZ", &dz_ports[0]))
  689. panic("Unable to register DZ interrupt");
  690. ret = uart_register_driver(&dz_reg);
  691. if (ret != 0)
  692. return ret;
  693. for (i = 0; i < DZ_NB_PORT; i++)
  694. uart_add_one_port(&dz_reg, &dz_ports[i].port);
  695. return ret;
  696. }
  697. MODULE_DESCRIPTION("DECstation DZ serial driver");
  698. MODULE_LICENSE("GPL");