blob: 0dddd68b20d27de2dd4e5a8802e4931e954f493b [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Maciej W. Rozycki93995752006-12-06 20:38:59 -08002 * dz.c: Serial port driver for DECstations equipped
Linus Torvalds1da177e2005-04-16 15:20:36 -07003 * with the DZ chipset.
4 *
Ralf Baechlefd8c5972005-11-12 21:59:59 +00005 * Copyright (C) 1998 Olivier A. D. Lebaillif
6 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07007 * Email: olivier.lebaillif@ifrsys.com
8 *
Maciej W. Rozycki87cff7f2008-02-07 00:15:09 -08009 * Copyright (C) 2004, 2006, 2007 Maciej W. Rozycki
Maciej W. Rozycki93995752006-12-06 20:38:59 -080010 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070011 * [31-AUG-98] triemer
12 * Changed IRQ to use Harald's dec internals interrupts.h
13 * removed base_addr code - moving address assignment to setup.c
14 * Changed name of dz_init to rs_init to be consistent with tc code
15 * [13-NOV-98] triemer fixed code to receive characters
Ralf Baechlefd8c5972005-11-12 21:59:59 +000016 * after patches by harald to irq code.
Linus Torvalds1da177e2005-04-16 15:20:36 -070017 * [09-JAN-99] triemer minor fix for schedule - due to removal of timeout
18 * field from "current" - somewhere between 2.1.121 and 2.1.131
19 Qua Jun 27 15:02:26 BRT 2001
20 * [27-JUN-2001] Arnaldo Carvalho de Melo <acme@conectiva.com.br> - cleanups
Ralf Baechlefd8c5972005-11-12 21:59:59 +000021 *
22 * Parts (C) 1999 David Airlie, airlied@linux.ie
23 * [07-SEP-99] Bugfixes
Linus Torvalds1da177e2005-04-16 15:20:36 -070024 *
25 * [06-Jan-2002] Russell King <rmk@arm.linux.org.uk>
26 * Converted to new serial core
27 */
28
29#undef DEBUG_DZ
30
Maciej W. Rozycki93995752006-12-06 20:38:59 -080031#if defined(CONFIG_SERIAL_DZ_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ)
32#define SUPPORT_SYSRQ
33#endif
34
Maciej W. Rozycki87cff7f2008-02-07 00:15:09 -080035#include <linux/bitops.h>
36#include <linux/compiler.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070037#include <linux/console.h>
Maciej W. Rozycki87cff7f2008-02-07 00:15:09 -080038#include <linux/delay.h>
39#include <linux/errno.h>
40#include <linux/init.h>
41#include <linux/interrupt.h>
Maciej W. Rozyckie6ee5122008-02-07 00:15:15 -080042#include <linux/ioport.h>
Maciej W. Rozycki87cff7f2008-02-07 00:15:09 -080043#include <linux/kernel.h>
44#include <linux/major.h>
45#include <linux/module.h>
46#include <linux/serial.h>
47#include <linux/serial_core.h>
Maciej W. Rozycki93995752006-12-06 20:38:59 -080048#include <linux/sysrq.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070049#include <linux/tty.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070050
Maciej W. Rozyckie6ee5122008-02-07 00:15:15 -080051#include <asm/atomic.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070052#include <asm/bootinfo.h>
Maciej W. Rozyckie6ee5122008-02-07 00:15:15 -080053#include <asm/io.h>
Maciej W. Rozycki87cff7f2008-02-07 00:15:09 -080054#include <asm/system.h>
55
Linus Torvalds1da177e2005-04-16 15:20:36 -070056#include <asm/dec/interrupts.h>
57#include <asm/dec/kn01.h>
58#include <asm/dec/kn02.h>
59#include <asm/dec/machtype.h>
60#include <asm/dec/prom.h>
Maciej W. Rozyckie6ee5122008-02-07 00:15:15 -080061#include <asm/dec/system.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070062
Linus Torvalds1da177e2005-04-16 15:20:36 -070063#include "dz.h"
64
Maciej W. Rozyckie6ee5122008-02-07 00:15:15 -080065
66MODULE_DESCRIPTION("DECstation DZ serial driver");
67MODULE_LICENSE("GPL");
68
69
70static char dz_name[] __initdata = "DECstation DZ serial driver version ";
71static char dz_version[] __initdata = "1.04";
Linus Torvalds1da177e2005-04-16 15:20:36 -070072
73struct dz_port {
Maciej W. Rozyckie6ee5122008-02-07 00:15:15 -080074 struct dz_mux *mux;
Linus Torvalds1da177e2005-04-16 15:20:36 -070075 struct uart_port port;
76 unsigned int cflag;
77};
78
Maciej W. Rozyckie6ee5122008-02-07 00:15:15 -080079struct dz_mux {
80 struct dz_port dport[DZ_NB_PORT];
81 atomic_t map_guard;
82 atomic_t irq_guard;
83 int initialised;
84};
85
86static struct dz_mux dz_mux;
Linus Torvalds1da177e2005-04-16 15:20:36 -070087
Maciej W. Rozyckif5519ca2008-02-07 00:15:15 -080088static inline struct dz_port *to_dport(struct uart_port *uport)
89{
90 return container_of(uport, struct dz_port, port);
91}
92
Linus Torvalds1da177e2005-04-16 15:20:36 -070093/*
94 * ------------------------------------------------------------
95 * dz_in () and dz_out ()
96 *
Ralf Baechlefd8c5972005-11-12 21:59:59 +000097 * These routines are used to access the registers of the DZ
Linus Torvalds1da177e2005-04-16 15:20:36 -070098 * chip, hiding relocation differences between implementation.
99 * ------------------------------------------------------------
100 */
101
Maciej W. Rozyckie6ee5122008-02-07 00:15:15 -0800102static u16 dz_in(struct dz_port *dport, unsigned offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103{
Maciej W. Rozyckie6ee5122008-02-07 00:15:15 -0800104 void __iomem *addr = dport->port.membase + offset;
Maciej W. Rozycki93995752006-12-06 20:38:59 -0800105
Maciej W. Rozyckie6ee5122008-02-07 00:15:15 -0800106 return readw(addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107}
108
Maciej W. Rozyckie6ee5122008-02-07 00:15:15 -0800109static void dz_out(struct dz_port *dport, unsigned offset, u16 value)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110{
Maciej W. Rozyckie6ee5122008-02-07 00:15:15 -0800111 void __iomem *addr = dport->port.membase + offset;
Maciej W. Rozycki93995752006-12-06 20:38:59 -0800112
Maciej W. Rozyckie6ee5122008-02-07 00:15:15 -0800113 writew(value, addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114}
115
116/*
117 * ------------------------------------------------------------
118 * rs_stop () and rs_start ()
119 *
Ralf Baechlefd8c5972005-11-12 21:59:59 +0000120 * These routines are called before setting or resetting
121 * tty->stopped. They enable or disable transmitter interrupts,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122 * as necessary.
123 * ------------------------------------------------------------
124 */
125
Russell Kingb129a8c2005-08-31 10:12:14 +0100126static void dz_stop_tx(struct uart_port *uport)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127{
Maciej W. Rozyckif5519ca2008-02-07 00:15:15 -0800128 struct dz_port *dport = to_dport(uport);
Maciej W. Rozyckie6ee5122008-02-07 00:15:15 -0800129 u16 tmp, mask = 1 << dport->port.line;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131 tmp = dz_in(dport, DZ_TCR); /* read the TX flag */
132 tmp &= ~mask; /* clear the TX flag */
133 dz_out(dport, DZ_TCR, tmp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134}
135
Russell Kingb129a8c2005-08-31 10:12:14 +0100136static void dz_start_tx(struct uart_port *uport)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137{
Maciej W. Rozyckif5519ca2008-02-07 00:15:15 -0800138 struct dz_port *dport = to_dport(uport);
Maciej W. Rozyckie6ee5122008-02-07 00:15:15 -0800139 u16 tmp, mask = 1 << dport->port.line;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141 tmp = dz_in(dport, DZ_TCR); /* read the TX flag */
142 tmp |= mask; /* set the TX flag */
143 dz_out(dport, DZ_TCR, tmp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144}
145
146static void dz_stop_rx(struct uart_port *uport)
147{
Maciej W. Rozyckif5519ca2008-02-07 00:15:15 -0800148 struct dz_port *dport = to_dport(uport);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149
Maciej W. Rozyckiff11d072008-02-07 00:15:14 -0800150 dport->cflag &= ~DZ_RXENAB;
151 dz_out(dport, DZ_LPR, dport->cflag);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152}
153
Maciej W. Rozyckie6ee5122008-02-07 00:15:15 -0800154static void dz_enable_ms(struct uart_port *uport)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155{
156 /* nothing to do */
157}
158
159/*
160 * ------------------------------------------------------------
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161 *
Maciej W. Rozycki93995752006-12-06 20:38:59 -0800162 * Here start the interrupt handling routines. All of the following
163 * subroutines are declared as inline and are folded into
164 * dz_interrupt. They were separated out for readability's sake.
165 *
166 * Note: dz_interrupt() is a "fast" interrupt, which means that it
Linus Torvalds1da177e2005-04-16 15:20:36 -0700167 * runs with interrupts turned off. People who may want to modify
Maciej W. Rozycki93995752006-12-06 20:38:59 -0800168 * dz_interrupt() should try to keep the interrupt handler as fast as
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169 * possible. After you are done making modifications, it is not a bad
170 * idea to do:
Ralf Baechlefd8c5972005-11-12 21:59:59 +0000171 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172 * make drivers/serial/dz.s
173 *
174 * and look at the resulting assemble code in dz.s.
175 *
176 * ------------------------------------------------------------
177 */
178
179/*
180 * ------------------------------------------------------------
181 * receive_char ()
182 *
183 * This routine deals with inputs from any lines.
184 * ------------------------------------------------------------
185 */
Maciej W. Rozyckie6ee5122008-02-07 00:15:15 -0800186static inline void dz_receive_chars(struct dz_mux *mux)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700187{
Maciej W. Rozycki54c0f372008-02-07 00:15:12 -0800188 struct uart_port *uport;
Maciej W. Rozyckie6ee5122008-02-07 00:15:15 -0800189 struct dz_port *dport = &mux->dport[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700190 struct tty_struct *tty = NULL;
191 struct uart_icount *icount;
Maciej W. Rozycki93995752006-12-06 20:38:59 -0800192 int lines_rx[DZ_NB_PORT] = { [0 ... DZ_NB_PORT - 1] = 0 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193 unsigned char ch, flag;
Maciej W. Rozyckie6ee5122008-02-07 00:15:15 -0800194 u16 status;
Maciej W. Rozycki93995752006-12-06 20:38:59 -0800195 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700196
Maciej W. Rozyckie6ee5122008-02-07 00:15:15 -0800197 while ((status = dz_in(dport, DZ_RBUF)) & DZ_DVAL) {
198 dport = &mux->dport[LINE(status)];
Maciej W. Rozycki54c0f372008-02-07 00:15:12 -0800199 uport = &dport->port;
200 tty = uport->info->tty; /* point to the proper dev */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201
Maciej W. Rozycki93995752006-12-06 20:38:59 -0800202 ch = UCHAR(status); /* grab the char */
Maciej W. Rozycki54c0f372008-02-07 00:15:12 -0800203 flag = TTY_NORMAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204
Maciej W. Rozycki54c0f372008-02-07 00:15:12 -0800205 icount = &uport->icount;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206 icount->rx++;
207
Maciej W. Rozycki54c0f372008-02-07 00:15:12 -0800208 if (unlikely(status & (DZ_OERR | DZ_FERR | DZ_PERR))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209
Maciej W. Rozycki54c0f372008-02-07 00:15:12 -0800210 /*
211 * There is no separate BREAK status bit, so treat
212 * null characters with framing errors as BREAKs;
213 * normally, otherwise. For this move the Framing
214 * Error bit to a simulated BREAK bit.
215 */
216 if (!ch) {
217 status |= (status & DZ_FERR) >>
218 (ffs(DZ_FERR) - ffs(DZ_BREAK));
219 status &= ~DZ_FERR;
220 }
221
222 /* Handle SysRq/SAK & keep track of the statistics. */
223 if (status & DZ_BREAK) {
224 icount->brk++;
225 if (uart_handle_break(uport))
226 continue;
227 } else if (status & DZ_FERR)
228 icount->frame++;
229 else if (status & DZ_PERR)
230 icount->parity++;
231 if (status & DZ_OERR)
232 icount->overrun++;
233
234 status &= uport->read_status_mask;
235 if (status & DZ_BREAK)
236 flag = TTY_BREAK;
237 else if (status & DZ_FERR)
238 flag = TTY_FRAME;
239 else if (status & DZ_PERR)
240 flag = TTY_PARITY;
241
Maciej W. Rozycki93995752006-12-06 20:38:59 -0800242 }
243
Maciej W. Rozycki54c0f372008-02-07 00:15:12 -0800244 if (uart_handle_sysrq_char(uport, ch))
Maciej W. Rozycki93995752006-12-06 20:38:59 -0800245 continue;
246
Maciej W. Rozycki54c0f372008-02-07 00:15:12 -0800247 uart_insert_char(uport, status, DZ_OERR, ch, flag);
248 lines_rx[LINE(status)] = 1;
Maciej W. Rozycki93995752006-12-06 20:38:59 -0800249 }
250 for (i = 0; i < DZ_NB_PORT; i++)
251 if (lines_rx[i])
Maciej W. Rozyckie6ee5122008-02-07 00:15:15 -0800252 tty_flip_buffer_push(mux->dport[i].port.info->tty);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253}
254
255/*
256 * ------------------------------------------------------------
257 * transmit_char ()
258 *
259 * This routine deals with outputs to any lines.
260 * ------------------------------------------------------------
261 */
Maciej W. Rozyckie6ee5122008-02-07 00:15:15 -0800262static inline void dz_transmit_chars(struct dz_mux *mux)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263{
Maciej W. Rozyckie6ee5122008-02-07 00:15:15 -0800264 struct dz_port *dport = &mux->dport[0];
Maciej W. Rozycki93995752006-12-06 20:38:59 -0800265 struct circ_buf *xmit;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266 unsigned char tmp;
Maciej W. Rozyckie6ee5122008-02-07 00:15:15 -0800267 u16 status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268
Maciej W. Rozyckie6ee5122008-02-07 00:15:15 -0800269 status = dz_in(dport, DZ_CSR);
270 dport = &mux->dport[LINE(status)];
Maciej W. Rozycki93995752006-12-06 20:38:59 -0800271 xmit = &dport->port.info->xmit;
272
273 if (dport->port.x_char) { /* XON/XOFF chars */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274 dz_out(dport, DZ_TDR, dport->port.x_char);
275 dport->port.icount.tx++;
276 dport->port.x_char = 0;
277 return;
278 }
Maciej W. Rozycki93995752006-12-06 20:38:59 -0800279 /* If nothing to do or stopped or hardware stopped. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280 if (uart_circ_empty(xmit) || uart_tx_stopped(&dport->port)) {
Maciej W. Rozycki43d46ab2008-02-07 00:15:11 -0800281 spin_lock(&dport->port.lock);
Russell Kingb129a8c2005-08-31 10:12:14 +0100282 dz_stop_tx(&dport->port);
Maciej W. Rozycki43d46ab2008-02-07 00:15:11 -0800283 spin_unlock(&dport->port.lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284 return;
285 }
286
287 /*
Maciej W. Rozycki93995752006-12-06 20:38:59 -0800288 * If something to do... (remember the dz has no output fifo,
289 * so we go one char at a time) :-<
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290 */
291 tmp = xmit->buf[xmit->tail];
292 xmit->tail = (xmit->tail + 1) & (DZ_XMIT_SIZE - 1);
293 dz_out(dport, DZ_TDR, tmp);
294 dport->port.icount.tx++;
295
296 if (uart_circ_chars_pending(xmit) < DZ_WAKEUP_CHARS)
297 uart_write_wakeup(&dport->port);
298
Maciej W. Rozycki93995752006-12-06 20:38:59 -0800299 /* Are we are done. */
Maciej W. Rozycki43d46ab2008-02-07 00:15:11 -0800300 if (uart_circ_empty(xmit)) {
301 spin_lock(&dport->port.lock);
Russell Kingb129a8c2005-08-31 10:12:14 +0100302 dz_stop_tx(&dport->port);
Maciej W. Rozycki43d46ab2008-02-07 00:15:11 -0800303 spin_unlock(&dport->port.lock);
304 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700305}
306
307/*
308 * ------------------------------------------------------------
Maciej W. Rozycki93995752006-12-06 20:38:59 -0800309 * check_modem_status()
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310 *
Maciej W. Rozycki93995752006-12-06 20:38:59 -0800311 * DS 3100 & 5100: Only valid for the MODEM line, duh!
312 * DS 5000/200: Valid for the MODEM and PRINTER line.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700313 * ------------------------------------------------------------
314 */
315static inline void check_modem_status(struct dz_port *dport)
316{
Maciej W. Rozycki93995752006-12-06 20:38:59 -0800317 /*
318 * FIXME:
319 * 1. No status change interrupt; use a timer.
320 * 2. Handle the 3100/5000 as appropriate. --macro
321 */
Maciej W. Rozyckie6ee5122008-02-07 00:15:15 -0800322 u16 status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700323
Maciej W. Rozycki93995752006-12-06 20:38:59 -0800324 /* If not the modem line just return. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700325 if (dport->port.line != DZ_MODEM)
326 return;
327
328 status = dz_in(dport, DZ_MSR);
329
330 /* it's easy, since DSR2 is the only bit in the register */
331 if (status)
332 dport->port.icount.dsr++;
333}
334
335/*
336 * ------------------------------------------------------------
337 * dz_interrupt ()
338 *
339 * this is the main interrupt routine for the DZ chip.
340 * It deals with the multiple ports.
341 * ------------------------------------------------------------
342 */
Maciej W. Rozyckie6ee5122008-02-07 00:15:15 -0800343static irqreturn_t dz_interrupt(int irq, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344{
Maciej W. Rozyckie6ee5122008-02-07 00:15:15 -0800345 struct dz_mux *mux = dev_id;
346 struct dz_port *dport = &mux->dport[0];
347 u16 status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700348
349 /* get the reason why we just got an irq */
Maciej W. Rozycki93995752006-12-06 20:38:59 -0800350 status = dz_in(dport, DZ_CSR);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351
Maciej W. Rozycki93995752006-12-06 20:38:59 -0800352 if ((status & (DZ_RDONE | DZ_RIE)) == (DZ_RDONE | DZ_RIE))
Maciej W. Rozyckie6ee5122008-02-07 00:15:15 -0800353 dz_receive_chars(mux);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354
Maciej W. Rozycki93995752006-12-06 20:38:59 -0800355 if ((status & (DZ_TRDY | DZ_TIE)) == (DZ_TRDY | DZ_TIE))
Maciej W. Rozyckie6ee5122008-02-07 00:15:15 -0800356 dz_transmit_chars(mux);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700357
Linus Torvalds1da177e2005-04-16 15:20:36 -0700358 return IRQ_HANDLED;
359}
360
361/*
362 * -------------------------------------------------------------------
363 * Here ends the DZ interrupt routines.
364 * -------------------------------------------------------------------
365 */
366
367static unsigned int dz_get_mctrl(struct uart_port *uport)
368{
Maciej W. Rozycki93995752006-12-06 20:38:59 -0800369 /*
370 * FIXME: Handle the 3100/5000 as appropriate. --macro
371 */
Maciej W. Rozyckif5519ca2008-02-07 00:15:15 -0800372 struct dz_port *dport = to_dport(uport);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373 unsigned int mctrl = TIOCM_CAR | TIOCM_DSR | TIOCM_CTS;
374
375 if (dport->port.line == DZ_MODEM) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376 if (dz_in(dport, DZ_MSR) & DZ_MODEM_DSR)
377 mctrl &= ~TIOCM_DSR;
378 }
379
380 return mctrl;
381}
382
383static void dz_set_mctrl(struct uart_port *uport, unsigned int mctrl)
384{
Maciej W. Rozycki93995752006-12-06 20:38:59 -0800385 /*
386 * FIXME: Handle the 3100/5000 as appropriate. --macro
387 */
Maciej W. Rozyckif5519ca2008-02-07 00:15:15 -0800388 struct dz_port *dport = to_dport(uport);
Maciej W. Rozyckie6ee5122008-02-07 00:15:15 -0800389 u16 tmp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390
391 if (dport->port.line == DZ_MODEM) {
392 tmp = dz_in(dport, DZ_TCR);
393 if (mctrl & TIOCM_DTR)
394 tmp &= ~DZ_MODEM_DTR;
395 else
396 tmp |= DZ_MODEM_DTR;
397 dz_out(dport, DZ_TCR, tmp);
398 }
399}
400
401/*
402 * -------------------------------------------------------------------
403 * startup ()
404 *
405 * various initialization tasks
Ralf Baechlefd8c5972005-11-12 21:59:59 +0000406 * -------------------------------------------------------------------
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407 */
408static int dz_startup(struct uart_port *uport)
409{
Maciej W. Rozyckif5519ca2008-02-07 00:15:15 -0800410 struct dz_port *dport = to_dport(uport);
Maciej W. Rozyckie6ee5122008-02-07 00:15:15 -0800411 struct dz_mux *mux = dport->mux;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412 unsigned long flags;
Maciej W. Rozyckie6ee5122008-02-07 00:15:15 -0800413 int irq_guard;
414 int ret;
415 u16 tmp;
416
417 irq_guard = atomic_add_return(1, &mux->irq_guard);
418 if (irq_guard != 1)
419 return 0;
420
421 ret = request_irq(dport->port.irq, dz_interrupt,
422 IRQF_SHARED, "dz", mux);
423 if (ret) {
424 atomic_add(-1, &mux->irq_guard);
425 printk(KERN_ERR "dz: Cannot get IRQ %d!\n", dport->port.irq);
426 return ret;
427 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700428
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429 spin_lock_irqsave(&dport->port.lock, flags);
430
Maciej W. Rozyckie6ee5122008-02-07 00:15:15 -0800431 /* Enable interrupts. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700432 tmp = dz_in(dport, DZ_CSR);
Maciej W. Rozyckie6ee5122008-02-07 00:15:15 -0800433 tmp |= DZ_RIE | DZ_TIE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700434 dz_out(dport, DZ_CSR, tmp);
435
436 spin_unlock_irqrestore(&dport->port.lock, flags);
437
438 return 0;
439}
440
Ralf Baechlefd8c5972005-11-12 21:59:59 +0000441/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700442 * -------------------------------------------------------------------
443 * shutdown ()
444 *
445 * This routine will shutdown a serial port; interrupts are disabled, and
446 * DTR is dropped if the hangup on close termio flag is on.
Ralf Baechlefd8c5972005-11-12 21:59:59 +0000447 * -------------------------------------------------------------------
Linus Torvalds1da177e2005-04-16 15:20:36 -0700448 */
449static void dz_shutdown(struct uart_port *uport)
450{
Maciej W. Rozyckif5519ca2008-02-07 00:15:15 -0800451 struct dz_port *dport = to_dport(uport);
Maciej W. Rozyckie6ee5122008-02-07 00:15:15 -0800452 struct dz_mux *mux = dport->mux;
Maciej W. Rozycki43d46ab2008-02-07 00:15:11 -0800453 unsigned long flags;
Maciej W. Rozyckie6ee5122008-02-07 00:15:15 -0800454 int irq_guard;
455 u16 tmp;
Maciej W. Rozycki43d46ab2008-02-07 00:15:11 -0800456
457 spin_lock_irqsave(&dport->port.lock, flags);
458 dz_stop_tx(&dport->port);
459 spin_unlock_irqrestore(&dport->port.lock, flags);
Maciej W. Rozyckie6ee5122008-02-07 00:15:15 -0800460
461 irq_guard = atomic_add_return(-1, &mux->irq_guard);
462 if (!irq_guard) {
463 /* Disable interrupts. */
464 tmp = dz_in(dport, DZ_CSR);
465 tmp &= ~(DZ_RIE | DZ_TIE);
466 dz_out(dport, DZ_CSR, tmp);
467
468 free_irq(dport->port.irq, mux);
469 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700470}
471
472/*
Maciej W. Rozycki93995752006-12-06 20:38:59 -0800473 * -------------------------------------------------------------------
474 * dz_tx_empty() -- get the transmitter empty status
Linus Torvalds1da177e2005-04-16 15:20:36 -0700475 *
476 * Purpose: Let user call ioctl() to get info when the UART physically
477 * is emptied. On bus types like RS485, the transmitter must
478 * release the bus after transmitting. This must be done when
479 * the transmit shift register is empty, not be done when the
480 * transmit holding register is empty. This functionality
Ralf Baechlefd8c5972005-11-12 21:59:59 +0000481 * allows an RS485 driver to be written in user space.
Maciej W. Rozycki93995752006-12-06 20:38:59 -0800482 * -------------------------------------------------------------------
Linus Torvalds1da177e2005-04-16 15:20:36 -0700483 */
484static unsigned int dz_tx_empty(struct uart_port *uport)
485{
Maciej W. Rozyckif5519ca2008-02-07 00:15:15 -0800486 struct dz_port *dport = to_dport(uport);
Maciej W. Rozycki93995752006-12-06 20:38:59 -0800487 unsigned short tmp, mask = 1 << dport->port.line;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700488
Maciej W. Rozycki93995752006-12-06 20:38:59 -0800489 tmp = dz_in(dport, DZ_TCR);
490 tmp &= mask;
491
492 return tmp ? 0 : TIOCSER_TEMT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700493}
494
495static void dz_break_ctl(struct uart_port *uport, int break_state)
496{
Maciej W. Rozycki93995752006-12-06 20:38:59 -0800497 /*
498 * FIXME: Can't access BREAK bits in TDR easily;
499 * reuse the code for polled TX. --macro
500 */
Maciej W. Rozyckif5519ca2008-02-07 00:15:15 -0800501 struct dz_port *dport = to_dport(uport);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700502 unsigned long flags;
Maciej W. Rozycki93995752006-12-06 20:38:59 -0800503 unsigned short tmp, mask = 1 << dport->port.line;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700504
505 spin_lock_irqsave(&uport->lock, flags);
506 tmp = dz_in(dport, DZ_TCR);
507 if (break_state)
508 tmp |= mask;
509 else
510 tmp &= ~mask;
511 dz_out(dport, DZ_TCR, tmp);
512 spin_unlock_irqrestore(&uport->lock, flags);
513}
514
Maciej W. Rozyckiff11d072008-02-07 00:15:14 -0800515static int dz_encode_baud_rate(unsigned int baud)
516{
517 switch (baud) {
518 case 50:
519 return DZ_B50;
520 case 75:
521 return DZ_B75;
522 case 110:
523 return DZ_B110;
524 case 134:
525 return DZ_B134;
526 case 150:
527 return DZ_B150;
528 case 300:
529 return DZ_B300;
530 case 600:
531 return DZ_B600;
532 case 1200:
533 return DZ_B1200;
534 case 1800:
535 return DZ_B1800;
536 case 2000:
537 return DZ_B2000;
538 case 2400:
539 return DZ_B2400;
540 case 3600:
541 return DZ_B3600;
542 case 4800:
543 return DZ_B4800;
544 case 7200:
545 return DZ_B7200;
546 case 9600:
547 return DZ_B9600;
548 default:
549 return -1;
550 }
551}
552
Maciej W. Rozyckie6ee5122008-02-07 00:15:15 -0800553
554static void dz_reset(struct dz_port *dport)
555{
556 struct dz_mux *mux = dport->mux;
557
558 if (mux->initialised)
559 return;
560
561 dz_out(dport, DZ_CSR, DZ_CLR);
562 while (dz_in(dport, DZ_CSR) & DZ_CLR);
563 iob();
564
565 /* Enable scanning. */
566 dz_out(dport, DZ_CSR, DZ_MSE);
567
568 mux->initialised = 1;
569}
570
Alan Cox606d0992006-12-08 02:38:45 -0800571static void dz_set_termios(struct uart_port *uport, struct ktermios *termios,
572 struct ktermios *old_termios)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700573{
Maciej W. Rozyckif5519ca2008-02-07 00:15:15 -0800574 struct dz_port *dport = to_dport(uport);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700575 unsigned long flags;
576 unsigned int cflag, baud;
Maciej W. Rozyckiff11d072008-02-07 00:15:14 -0800577 int bflag;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700578
579 cflag = dport->port.line;
580
581 switch (termios->c_cflag & CSIZE) {
582 case CS5:
583 cflag |= DZ_CS5;
584 break;
585 case CS6:
586 cflag |= DZ_CS6;
587 break;
588 case CS7:
589 cflag |= DZ_CS7;
590 break;
591 case CS8:
592 default:
593 cflag |= DZ_CS8;
594 }
595
596 if (termios->c_cflag & CSTOPB)
597 cflag |= DZ_CSTOPB;
598 if (termios->c_cflag & PARENB)
599 cflag |= DZ_PARENB;
600 if (termios->c_cflag & PARODD)
601 cflag |= DZ_PARODD;
602
603 baud = uart_get_baud_rate(uport, termios, old_termios, 50, 9600);
Maciej W. Rozyckiff11d072008-02-07 00:15:14 -0800604 bflag = dz_encode_baud_rate(baud);
605 if (bflag < 0) { /* Try to keep unchanged. */
606 baud = uart_get_baud_rate(uport, old_termios, NULL, 50, 9600);
607 bflag = dz_encode_baud_rate(baud);
608 if (bflag < 0) { /* Resort to 9600. */
609 baud = 9600;
610 bflag = DZ_B9600;
611 }
612 tty_termios_encode_baud_rate(termios, baud, baud);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700613 }
Maciej W. Rozyckiff11d072008-02-07 00:15:14 -0800614 cflag |= bflag;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700615
616 if (termios->c_cflag & CREAD)
617 cflag |= DZ_RXENAB;
618
619 spin_lock_irqsave(&dport->port.lock, flags);
620
Maciej W. Rozyckiff11d072008-02-07 00:15:14 -0800621 uart_update_timeout(uport, termios->c_cflag, baud);
622
623 dz_out(dport, DZ_LPR, cflag);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700624 dport->cflag = cflag;
625
626 /* setup accept flag */
627 dport->port.read_status_mask = DZ_OERR;
628 if (termios->c_iflag & INPCK)
629 dport->port.read_status_mask |= DZ_FERR | DZ_PERR;
Maciej W. Rozycki54c0f372008-02-07 00:15:12 -0800630 if (termios->c_iflag & (BRKINT | PARMRK))
631 dport->port.read_status_mask |= DZ_BREAK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700632
633 /* characters to ignore */
634 uport->ignore_status_mask = 0;
Maciej W. Rozycki54c0f372008-02-07 00:15:12 -0800635 if ((termios->c_iflag & (IGNPAR | IGNBRK)) == (IGNPAR | IGNBRK))
636 dport->port.ignore_status_mask |= DZ_OERR;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700637 if (termios->c_iflag & IGNPAR)
638 dport->port.ignore_status_mask |= DZ_FERR | DZ_PERR;
Maciej W. Rozycki54c0f372008-02-07 00:15:12 -0800639 if (termios->c_iflag & IGNBRK)
640 dport->port.ignore_status_mask |= DZ_BREAK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700641
642 spin_unlock_irqrestore(&dport->port.lock, flags);
643}
644
Maciej W. Rozyckie6ee5122008-02-07 00:15:15 -0800645static const char *dz_type(struct uart_port *uport)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700646{
647 return "DZ";
648}
649
Maciej W. Rozyckie6ee5122008-02-07 00:15:15 -0800650static void dz_release_port(struct uart_port *uport)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700651{
Maciej W. Rozyckie6ee5122008-02-07 00:15:15 -0800652 struct dz_mux *mux = to_dport(uport)->mux;
653 int map_guard;
654
655 iounmap(uport->membase);
656 uport->membase = NULL;
657
658 map_guard = atomic_add_return(-1, &mux->map_guard);
659 if (!map_guard)
660 release_mem_region(uport->mapbase, dec_kn_slot_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700661}
662
Maciej W. Rozyckie6ee5122008-02-07 00:15:15 -0800663static int dz_map_port(struct uart_port *uport)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700664{
Maciej W. Rozyckie6ee5122008-02-07 00:15:15 -0800665 if (!uport->membase)
666 uport->membase = ioremap_nocache(uport->mapbase,
667 dec_kn_slot_size);
668 if (!uport->membase) {
669 printk(KERN_ERR "dz: Cannot map MMIO\n");
670 return -ENOMEM;
671 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700672 return 0;
673}
674
Maciej W. Rozyckie6ee5122008-02-07 00:15:15 -0800675static int dz_request_port(struct uart_port *uport)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700676{
Maciej W. Rozyckie6ee5122008-02-07 00:15:15 -0800677 struct dz_mux *mux = to_dport(uport)->mux;
678 int map_guard;
679 int ret;
680
681 map_guard = atomic_add_return(1, &mux->map_guard);
682 if (map_guard == 1) {
683 if (!request_mem_region(uport->mapbase, dec_kn_slot_size,
684 "dz")) {
685 atomic_add(-1, &mux->map_guard);
686 printk(KERN_ERR
687 "dz: Unable to reserve MMIO resource\n");
688 return -EBUSY;
689 }
690 }
691 ret = dz_map_port(uport);
692 if (ret) {
693 map_guard = atomic_add_return(-1, &mux->map_guard);
694 if (!map_guard)
695 release_mem_region(uport->mapbase, dec_kn_slot_size);
696 return ret;
697 }
698 return 0;
699}
700
701static void dz_config_port(struct uart_port *uport, int flags)
702{
703 struct dz_port *dport = to_dport(uport);
704
705 if (flags & UART_CONFIG_TYPE) {
706 if (dz_request_port(uport))
707 return;
708
709 uport->type = PORT_DZ;
710
711 dz_reset(dport);
712 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700713}
714
715/*
Maciej W. Rozyckie6ee5122008-02-07 00:15:15 -0800716 * Verify the new serial_struct (for TIOCSSERIAL).
Linus Torvalds1da177e2005-04-16 15:20:36 -0700717 */
Maciej W. Rozyckie6ee5122008-02-07 00:15:15 -0800718static int dz_verify_port(struct uart_port *uport, struct serial_struct *ser)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700719{
720 int ret = 0;
Maciej W. Rozyckie6ee5122008-02-07 00:15:15 -0800721
Linus Torvalds1da177e2005-04-16 15:20:36 -0700722 if (ser->type != PORT_UNKNOWN && ser->type != PORT_DZ)
723 ret = -EINVAL;
Maciej W. Rozyckie6ee5122008-02-07 00:15:15 -0800724 if (ser->irq != uport->irq)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700725 ret = -EINVAL;
726 return ret;
727}
728
729static struct uart_ops dz_ops = {
730 .tx_empty = dz_tx_empty,
731 .get_mctrl = dz_get_mctrl,
732 .set_mctrl = dz_set_mctrl,
733 .stop_tx = dz_stop_tx,
734 .start_tx = dz_start_tx,
735 .stop_rx = dz_stop_rx,
736 .enable_ms = dz_enable_ms,
737 .break_ctl = dz_break_ctl,
738 .startup = dz_startup,
739 .shutdown = dz_shutdown,
740 .set_termios = dz_set_termios,
741 .type = dz_type,
742 .release_port = dz_release_port,
743 .request_port = dz_request_port,
744 .config_port = dz_config_port,
745 .verify_port = dz_verify_port,
746};
747
748static void __init dz_init_ports(void)
749{
750 static int first = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700751 unsigned long base;
Maciej W. Rozyckie6ee5122008-02-07 00:15:15 -0800752 int line;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700753
754 if (!first)
755 return;
756 first = 0;
757
Maciej W. Rozyckie6ee5122008-02-07 00:15:15 -0800758 if (mips_machtype == MACH_DS23100 || mips_machtype == MACH_DS5100)
759 base = dec_kn_slot_base + KN01_DZ11;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700760 else
Maciej W. Rozyckie6ee5122008-02-07 00:15:15 -0800761 base = dec_kn_slot_base + KN02_DZ11;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700762
Maciej W. Rozyckie6ee5122008-02-07 00:15:15 -0800763 for (line = 0; line < DZ_NB_PORT; line++) {
764 struct dz_port *dport = &dz_mux.dport[line];
765 struct uart_port *uport = &dport->port;
766
767 dport->mux = &dz_mux;
768
769 uport->irq = dec_interrupt[DEC_IRQ_DZ11];
770 uport->fifosize = 1;
771 uport->iotype = UPIO_MEM;
772 uport->flags = UPF_BOOT_AUTOCONF;
773 uport->ops = &dz_ops;
774 uport->line = line;
775 uport->mapbase = base;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700776 }
777}
778
Linus Torvalds1da177e2005-04-16 15:20:36 -0700779#ifdef CONFIG_SERIAL_DZ_CONSOLE
Maciej W. Rozycki93995752006-12-06 20:38:59 -0800780/*
781 * -------------------------------------------------------------------
782 * dz_console_putchar() -- transmit a character
783 *
784 * Polled transmission. This is tricky. We need to mask transmit
785 * interrupts so that they do not interfere, enable the transmitter
786 * for the line requested and then wait till the transmit scanner
787 * requests data for this line. But it may request data for another
788 * line first, in which case we have to disable its transmitter and
789 * repeat waiting till our line pops up. Only then the character may
790 * be transmitted. Finally, the state of the transmitter mask is
791 * restored. Welcome to the world of PDP-11!
792 * -------------------------------------------------------------------
793 */
Martin Michlmayrd608ab92006-06-26 18:18:11 +0200794static void dz_console_putchar(struct uart_port *uport, int ch)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700795{
Maciej W. Rozyckif5519ca2008-02-07 00:15:15 -0800796 struct dz_port *dport = to_dport(uport);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700797 unsigned long flags;
Maciej W. Rozycki93995752006-12-06 20:38:59 -0800798 unsigned short csr, tcr, trdy, mask;
799 int loops = 10000;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700800
801 spin_lock_irqsave(&dport->port.lock, flags);
Maciej W. Rozycki93995752006-12-06 20:38:59 -0800802 csr = dz_in(dport, DZ_CSR);
803 dz_out(dport, DZ_CSR, csr & ~DZ_TIE);
804 tcr = dz_in(dport, DZ_TCR);
805 tcr |= 1 << dport->port.line;
806 mask = tcr;
807 dz_out(dport, DZ_TCR, mask);
808 iob();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700809 spin_unlock_irqrestore(&dport->port.lock, flags);
Maciej W. Rozycki93995752006-12-06 20:38:59 -0800810
Maciej W. Rozyckidbab8122008-02-07 00:15:07 -0800811 do {
Maciej W. Rozycki93995752006-12-06 20:38:59 -0800812 trdy = dz_in(dport, DZ_CSR);
813 if (!(trdy & DZ_TRDY))
814 continue;
815 trdy = (trdy & DZ_TLINE) >> 8;
816 if (trdy == dport->port.line)
817 break;
818 mask &= ~(1 << trdy);
819 dz_out(dport, DZ_TCR, mask);
820 iob();
821 udelay(2);
Roel Kluin1ecf0d02008-04-28 02:11:50 -0700822 } while (--loops);
Maciej W. Rozycki93995752006-12-06 20:38:59 -0800823
824 if (loops) /* Cannot send otherwise. */
825 dz_out(dport, DZ_TDR, ch);
826
827 dz_out(dport, DZ_TCR, tcr);
828 dz_out(dport, DZ_CSR, csr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700829}
Russell Kingd3587882006-03-20 20:00:09 +0000830
Ralf Baechlefd8c5972005-11-12 21:59:59 +0000831/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700832 * -------------------------------------------------------------------
833 * dz_console_print ()
834 *
835 * dz_console_print is registered for printk.
836 * The console must be locked when we get here.
Ralf Baechlefd8c5972005-11-12 21:59:59 +0000837 * -------------------------------------------------------------------
Linus Torvalds1da177e2005-04-16 15:20:36 -0700838 */
Maciej W. Rozycki93995752006-12-06 20:38:59 -0800839static void dz_console_print(struct console *co,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700840 const char *str,
841 unsigned int count)
842{
Maciej W. Rozyckie6ee5122008-02-07 00:15:15 -0800843 struct dz_port *dport = &dz_mux.dport[co->index];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700844#ifdef DEBUG_DZ
845 prom_printf((char *) str);
846#endif
Russell Kingd3587882006-03-20 20:00:09 +0000847 uart_console_write(&dport->port, str, count, dz_console_putchar);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700848}
849
850static int __init dz_console_setup(struct console *co, char *options)
851{
Maciej W. Rozyckie6ee5122008-02-07 00:15:15 -0800852 struct dz_port *dport = &dz_mux.dport[co->index];
853 struct uart_port *uport = &dport->port;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700854 int baud = 9600;
855 int bits = 8;
856 int parity = 'n';
857 int flow = 'n';
Maciej W. Rozyckie6ee5122008-02-07 00:15:15 -0800858 int ret;
859
860 ret = dz_map_port(uport);
861 if (ret)
862 return ret;
863
864 dz_reset(dport);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700865
866 if (options)
867 uart_parse_options(options, &baud, &parity, &bits, &flow);
868
Maciej W. Rozycki93995752006-12-06 20:38:59 -0800869 return uart_set_options(&dport->port, co, baud, parity, bits, flow);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700870}
871
Maciej W. Rozycki93995752006-12-06 20:38:59 -0800872static struct uart_driver dz_reg;
Maciej W. Rozycki6d83c062008-02-07 00:15:10 -0800873static struct console dz_console = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700874 .name = "ttyS",
875 .write = dz_console_print,
876 .device = uart_console_device,
877 .setup = dz_console_setup,
Maciej W. Rozycki93995752006-12-06 20:38:59 -0800878 .flags = CON_PRINTBUFFER,
879 .index = -1,
880 .data = &dz_reg,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700881};
882
Maciej W. Rozycki93995752006-12-06 20:38:59 -0800883static int __init dz_serial_console_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700884{
Maciej W. Rozycki93995752006-12-06 20:38:59 -0800885 if (!IOASIC) {
886 dz_init_ports();
Maciej W. Rozycki6d83c062008-02-07 00:15:10 -0800887 register_console(&dz_console);
Maciej W. Rozycki93995752006-12-06 20:38:59 -0800888 return 0;
889 } else
890 return -ENXIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700891}
892
Maciej W. Rozycki93995752006-12-06 20:38:59 -0800893console_initcall(dz_serial_console_init);
894
Maciej W. Rozycki6d83c062008-02-07 00:15:10 -0800895#define SERIAL_DZ_CONSOLE &dz_console
Linus Torvalds1da177e2005-04-16 15:20:36 -0700896#else
897#define SERIAL_DZ_CONSOLE NULL
898#endif /* CONFIG_SERIAL_DZ_CONSOLE */
899
900static struct uart_driver dz_reg = {
901 .owner = THIS_MODULE,
902 .driver_name = "serial",
Maciej W. Rozycki93995752006-12-06 20:38:59 -0800903 .dev_name = "ttyS",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700904 .major = TTY_MAJOR,
905 .minor = 64,
906 .nr = DZ_NB_PORT,
907 .cons = SERIAL_DZ_CONSOLE,
908};
909
Maciej W. Rozycki93995752006-12-06 20:38:59 -0800910static int __init dz_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700911{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700912 int ret, i;
913
Maciej W. Rozycki93995752006-12-06 20:38:59 -0800914 if (IOASIC)
915 return -ENXIO;
916
Linus Torvalds1da177e2005-04-16 15:20:36 -0700917 printk("%s%s\n", dz_name, dz_version);
918
919 dz_init_ports();
920
Linus Torvalds1da177e2005-04-16 15:20:36 -0700921 ret = uart_register_driver(&dz_reg);
Maciej W. Rozyckie6ee5122008-02-07 00:15:15 -0800922 if (ret)
923 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700924
925 for (i = 0; i < DZ_NB_PORT; i++)
Maciej W. Rozyckie6ee5122008-02-07 00:15:15 -0800926 uart_add_one_port(&dz_reg, &dz_mux.dport[i].port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700927
Maciej W. Rozyckie6ee5122008-02-07 00:15:15 -0800928 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700929}
930
Maciej W. Rozycki93995752006-12-06 20:38:59 -0800931module_init(dz_init);