Blame view

drivers/serial/dz.c 19.6 KB
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1
  /*
9399575dd   Maciej W. Rozycki   [PATCH] dz: Fixes...
2
   * dz.c: Serial port driver for DECstations equipped
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
3
4
   *       with the DZ chipset.
   *
fd8c59721   Ralf Baechle   [SERIAL] dz: Nuke...
5
6
   * Copyright (C) 1998 Olivier A. D. Lebaillif
   *
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
7
8
   * Email: olivier.lebaillif@ifrsys.com
   *
9399575dd   Maciej W. Rozycki   [PATCH] dz: Fixes...
9
10
   * Copyright (C) 2004, 2006  Maciej W. Rozycki
   *
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
11
12
13
14
15
   * [31-AUG-98] triemer
   * Changed IRQ to use Harald's dec internals interrupts.h
   * removed base_addr code - moving address assignment to setup.c
   * Changed name of dz_init to rs_init to be consistent with tc code
   * [13-NOV-98] triemer fixed code to receive characters
fd8c59721   Ralf Baechle   [SERIAL] dz: Nuke...
16
   *    after patches by harald to irq code.
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
17
18
19
20
   * [09-JAN-99] triemer minor fix for schedule - due to removal of timeout
   *            field from "current" - somewhere between 2.1.121 and 2.1.131
   Qua Jun 27 15:02:26 BRT 2001
   * [27-JUN-2001] Arnaldo Carvalho de Melo <acme@conectiva.com.br> - cleanups
fd8c59721   Ralf Baechle   [SERIAL] dz: Nuke...
21
22
23
   *
   * Parts (C) 1999 David Airlie, airlied@linux.ie
   * [07-SEP-99] Bugfixes
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
24
25
26
27
28
29
   *
   * [06-Jan-2002] Russell King <rmk@arm.linux.org.uk>
   * Converted to new serial core
   */
  
  #undef DEBUG_DZ
9399575dd   Maciej W. Rozycki   [PATCH] dz: Fixes...
30
31
32
33
34
  #if defined(CONFIG_SERIAL_DZ_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ)
  #define SUPPORT_SYSRQ
  #endif
  
  #include <linux/delay.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
35
36
37
38
  #include <linux/module.h>
  #include <linux/interrupt.h>
  #include <linux/init.h>
  #include <linux/console.h>
9399575dd   Maciej W. Rozycki   [PATCH] dz: Fixes...
39
  #include <linux/sysrq.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
40
41
42
43
44
45
46
47
48
49
50
51
52
53
  #include <linux/tty.h>
  #include <linux/tty_flip.h>
  #include <linux/serial_core.h>
  #include <linux/serial.h>
  
  #include <asm/bootinfo.h>
  #include <asm/dec/interrupts.h>
  #include <asm/dec/kn01.h>
  #include <asm/dec/kn02.h>
  #include <asm/dec/machtype.h>
  #include <asm/dec/prom.h>
  #include <asm/irq.h>
  #include <asm/system.h>
  #include <asm/uaccess.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
54
  #include "dz.h"
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
55
  static char *dz_name = "DECstation DZ serial driver version ";
9399575dd   Maciej W. Rozycki   [PATCH] dz: Fixes...
56
  static char *dz_version = "1.03";
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
57
58
59
60
61
62
63
  
  struct dz_port {
  	struct uart_port	port;
  	unsigned int		cflag;
  };
  
  static struct dz_port dz_ports[DZ_NB_PORT];
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
64
65
66
67
  /*
   * ------------------------------------------------------------
   * dz_in () and dz_out ()
   *
fd8c59721   Ralf Baechle   [SERIAL] dz: Nuke...
68
   * These routines are used to access the registers of the DZ
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
69
70
71
72
73
74
75
76
   * chip, hiding relocation differences between implementation.
   * ------------------------------------------------------------
   */
  
  static inline unsigned short dz_in(struct dz_port *dport, unsigned offset)
  {
  	volatile unsigned short *addr =
  		(volatile unsigned short *) (dport->port.membase + offset);
9399575dd   Maciej W. Rozycki   [PATCH] dz: Fixes...
77

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
78
79
80
81
82
83
84
85
  	return *addr;
  }
  
  static inline void dz_out(struct dz_port *dport, unsigned offset,
                            unsigned short value)
  {
  	volatile unsigned short *addr =
  		(volatile unsigned short *) (dport->port.membase + offset);
9399575dd   Maciej W. Rozycki   [PATCH] dz: Fixes...
86

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
87
88
89
90
91
92
93
  	*addr = value;
  }
  
  /*
   * ------------------------------------------------------------
   * rs_stop () and rs_start ()
   *
fd8c59721   Ralf Baechle   [SERIAL] dz: Nuke...
94
95
   * These routines are called before setting or resetting
   * tty->stopped. They enable or disable transmitter interrupts,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
96
97
98
   * as necessary.
   * ------------------------------------------------------------
   */
b129a8ccd   Russell King   [SERIAL] Clean up...
99
  static void dz_stop_tx(struct uart_port *uport)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
100
101
102
103
104
105
106
107
108
109
110
  {
  	struct dz_port *dport = (struct dz_port *)uport;
  	unsigned short tmp, mask = 1 << dport->port.line;
  	unsigned long flags;
  
  	spin_lock_irqsave(&dport->port.lock, flags);
  	tmp = dz_in(dport, DZ_TCR);	/* read the TX flag */
  	tmp &= ~mask;			/* clear the TX flag */
  	dz_out(dport, DZ_TCR, tmp);
  	spin_unlock_irqrestore(&dport->port.lock, flags);
  }
b129a8ccd   Russell King   [SERIAL] Clean up...
111
  static void dz_start_tx(struct uart_port *uport)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
  {
  	struct dz_port *dport = (struct dz_port *)uport;
  	unsigned short tmp, mask = 1 << dport->port.line;
  	unsigned long flags;
  
  	spin_lock_irqsave(&dport->port.lock, flags);
  	tmp = dz_in(dport, DZ_TCR);	/* read the TX flag */
  	tmp |= mask;			/* set the TX flag */
  	dz_out(dport, DZ_TCR, tmp);
  	spin_unlock_irqrestore(&dport->port.lock, flags);
  }
  
  static void dz_stop_rx(struct uart_port *uport)
  {
  	struct dz_port *dport = (struct dz_port *)uport;
  	unsigned long flags;
  
  	spin_lock_irqsave(&dport->port.lock, flags);
  	dport->cflag &= ~DZ_CREAD;
9399575dd   Maciej W. Rozycki   [PATCH] dz: Fixes...
131
  	dz_out(dport, DZ_LPR, dport->cflag | dport->port.line);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
132
133
134
135
136
137
138
139
140
141
  	spin_unlock_irqrestore(&dport->port.lock, flags);
  }
  
  static void dz_enable_ms(struct uart_port *port)
  {
  	/* nothing to do */
  }
  
  /*
   * ------------------------------------------------------------
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
142
   *
9399575dd   Maciej W. Rozycki   [PATCH] dz: Fixes...
143
144
145
146
147
   * Here start the interrupt handling routines.  All of the following
   * subroutines are declared as inline and are folded into
   * dz_interrupt.  They were separated out for readability's sake.
   *
   * Note: dz_interrupt() is a "fast" interrupt, which means that it
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
148
   * runs with interrupts turned off.  People who may want to modify
9399575dd   Maciej W. Rozycki   [PATCH] dz: Fixes...
149
   * dz_interrupt() should try to keep the interrupt handler as fast as
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
150
151
   * possible.  After you are done making modifications, it is not a bad
   * idea to do:
fd8c59721   Ralf Baechle   [SERIAL] dz: Nuke...
152
   *
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
153
154
155
156
157
158
159
160
161
162
163
164
165
166
   *	make drivers/serial/dz.s
   *
   * and look at the resulting assemble code in dz.s.
   *
   * ------------------------------------------------------------
   */
  
  /*
   * ------------------------------------------------------------
   * receive_char ()
   *
   * This routine deals with inputs from any lines.
   * ------------------------------------------------------------
   */
de320199c   Maciej W. Rozycki   [PATCH] dz: remov...
167
  static inline void dz_receive_chars(struct dz_port *dport_in)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
168
  {
9399575dd   Maciej W. Rozycki   [PATCH] dz: Fixes...
169
  	struct dz_port *dport;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
170
171
  	struct tty_struct *tty = NULL;
  	struct uart_icount *icount;
9399575dd   Maciej W. Rozycki   [PATCH] dz: Fixes...
172
173
  	int lines_rx[DZ_NB_PORT] = { [0 ... DZ_NB_PORT - 1] = 0 };
  	unsigned short status;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
174
  	unsigned char ch, flag;
9399575dd   Maciej W. Rozycki   [PATCH] dz: Fixes...
175
  	int i;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
176

9399575dd   Maciej W. Rozycki   [PATCH] dz: Fixes...
177
178
179
  	while ((status = dz_in(dport_in, DZ_RBUF)) & DZ_DVAL) {
  		dport = &dz_ports[LINE(status)];
  		tty = dport->port.info->tty;	/* point to the proper dev */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
180

9399575dd   Maciej W. Rozycki   [PATCH] dz: Fixes...
181
  		ch = UCHAR(status);		/* grab the char */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
182

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
183
  		icount = &dport->port.icount;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
184
  		icount->rx++;
9399575dd   Maciej W. Rozycki   [PATCH] dz: Fixes...
185
186
187
188
189
190
  		flag = TTY_NORMAL;
  		if (status & DZ_FERR) {		/* frame error */
  			/*
  			 * There is no separate BREAK status bit, so
  			 * treat framing errors as BREAKs for Magic SysRq
  			 * and SAK; normally, otherwise.
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
191
  			 */
9399575dd   Maciej W. Rozycki   [PATCH] dz: Fixes...
192
193
194
195
196
  			if (uart_handle_break(&dport->port))
  				continue;
  			if (dport->port.flags & UPF_SAK)
  				flag = TTY_BREAK;
  			else
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
197
  				flag = TTY_FRAME;
9399575dd   Maciej W. Rozycki   [PATCH] dz: Fixes...
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
  		} else if (status & DZ_OERR)	/* overrun error */
  			flag = TTY_OVERRUN;
  		else if (status & DZ_PERR)	/* parity error */
  			flag = TTY_PARITY;
  
  		/* keep track of the statistics */
  		switch (flag) {
  		case TTY_FRAME:
  			icount->frame++;
  			break;
  		case TTY_PARITY:
  			icount->parity++;
  			break;
  		case TTY_OVERRUN:
  			icount->overrun++;
  			break;
  		case TTY_BREAK:
  			icount->brk++;
  			break;
  		default:
  			break;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
219
  		}
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
220

de320199c   Maciej W. Rozycki   [PATCH] dz: remov...
221
  		if (uart_handle_sysrq_char(&dport->port, ch))
9399575dd   Maciej W. Rozycki   [PATCH] dz: Fixes...
222
223
224
225
226
227
228
229
230
231
232
  			continue;
  
  		if ((status & dport->port.ignore_status_mask) == 0) {
  			uart_insert_char(&dport->port,
  					 status, DZ_OERR, ch, flag);
  			lines_rx[LINE(status)] = 1;
  		}
  	}
  	for (i = 0; i < DZ_NB_PORT; i++)
  		if (lines_rx[i])
  			tty_flip_buffer_push(dz_ports[i].port.info->tty);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
233
234
235
236
237
238
239
240
241
  }
  
  /*
   * ------------------------------------------------------------
   * transmit_char ()
   *
   * This routine deals with outputs to any lines.
   * ------------------------------------------------------------
   */
9399575dd   Maciej W. Rozycki   [PATCH] dz: Fixes...
242
  static inline void dz_transmit_chars(struct dz_port *dport_in)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
243
  {
9399575dd   Maciej W. Rozycki   [PATCH] dz: Fixes...
244
245
246
  	struct dz_port *dport;
  	struct circ_buf *xmit;
  	unsigned short status;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
247
  	unsigned char tmp;
9399575dd   Maciej W. Rozycki   [PATCH] dz: Fixes...
248
249
250
251
252
  	status = dz_in(dport_in, DZ_CSR);
  	dport = &dz_ports[LINE(status)];
  	xmit = &dport->port.info->xmit;
  
  	if (dport->port.x_char) {		/* XON/XOFF chars */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
253
254
255
256
257
  		dz_out(dport, DZ_TDR, dport->port.x_char);
  		dport->port.icount.tx++;
  		dport->port.x_char = 0;
  		return;
  	}
9399575dd   Maciej W. Rozycki   [PATCH] dz: Fixes...
258
  	/* If nothing to do or stopped or hardware stopped. */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
259
  	if (uart_circ_empty(xmit) || uart_tx_stopped(&dport->port)) {
b129a8ccd   Russell King   [SERIAL] Clean up...
260
  		dz_stop_tx(&dport->port);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
261
262
263
264
  		return;
  	}
  
  	/*
9399575dd   Maciej W. Rozycki   [PATCH] dz: Fixes...
265
266
  	 * If something to do... (remember the dz has no output fifo,
  	 * so we go one char at a time) :-<
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
267
268
269
270
271
272
273
274
  	 */
  	tmp = xmit->buf[xmit->tail];
  	xmit->tail = (xmit->tail + 1) & (DZ_XMIT_SIZE - 1);
  	dz_out(dport, DZ_TDR, tmp);
  	dport->port.icount.tx++;
  
  	if (uart_circ_chars_pending(xmit) < DZ_WAKEUP_CHARS)
  		uart_write_wakeup(&dport->port);
9399575dd   Maciej W. Rozycki   [PATCH] dz: Fixes...
275
  	/* Are we are done. */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
276
  	if (uart_circ_empty(xmit))
b129a8ccd   Russell King   [SERIAL] Clean up...
277
  		dz_stop_tx(&dport->port);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
278
279
280
281
  }
  
  /*
   * ------------------------------------------------------------
9399575dd   Maciej W. Rozycki   [PATCH] dz: Fixes...
282
   * check_modem_status()
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
283
   *
9399575dd   Maciej W. Rozycki   [PATCH] dz: Fixes...
284
285
   * DS 3100 & 5100: Only valid for the MODEM line, duh!
   * DS 5000/200: Valid for the MODEM and PRINTER line.
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
286
287
288
289
   * ------------------------------------------------------------
   */
  static inline void check_modem_status(struct dz_port *dport)
  {
9399575dd   Maciej W. Rozycki   [PATCH] dz: Fixes...
290
291
292
293
294
  	/*
  	 * FIXME:
  	 * 1. No status change interrupt; use a timer.
  	 * 2. Handle the 3100/5000 as appropriate. --macro
  	 */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
295
  	unsigned short status;
9399575dd   Maciej W. Rozycki   [PATCH] dz: Fixes...
296
  	/* If not the modem line just return.  */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
  	if (dport->port.line != DZ_MODEM)
  		return;
  
  	status = dz_in(dport, DZ_MSR);
  
  	/* it's easy, since DSR2 is the only bit in the register */
  	if (status)
  		dport->port.icount.dsr++;
  }
  
  /*
   * ------------------------------------------------------------
   * dz_interrupt ()
   *
   * this is the main interrupt routine for the DZ chip.
   * It deals with the multiple ports.
   * ------------------------------------------------------------
   */
7d12e780e   David Howells   IRQ: Maintain reg...
315
  static irqreturn_t dz_interrupt(int irq, void *dev)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
316
  {
9399575dd   Maciej W. Rozycki   [PATCH] dz: Fixes...
317
  	struct dz_port *dport = (struct dz_port *)dev;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
318
319
320
  	unsigned short status;
  
  	/* get the reason why we just got an irq */
9399575dd   Maciej W. Rozycki   [PATCH] dz: Fixes...
321
  	status = dz_in(dport, DZ_CSR);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
322

9399575dd   Maciej W. Rozycki   [PATCH] dz: Fixes...
323
  	if ((status & (DZ_RDONE | DZ_RIE)) == (DZ_RDONE | DZ_RIE))
de320199c   Maciej W. Rozycki   [PATCH] dz: remov...
324
  		dz_receive_chars(dport);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
325

9399575dd   Maciej W. Rozycki   [PATCH] dz: Fixes...
326
  	if ((status & (DZ_TRDY | DZ_TIE)) == (DZ_TRDY | DZ_TIE))
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
327
  		dz_transmit_chars(dport);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
328
329
330
331
332
333
334
335
336
337
338
  	return IRQ_HANDLED;
  }
  
  /*
   * -------------------------------------------------------------------
   * Here ends the DZ interrupt routines.
   * -------------------------------------------------------------------
   */
  
  static unsigned int dz_get_mctrl(struct uart_port *uport)
  {
9399575dd   Maciej W. Rozycki   [PATCH] dz: Fixes...
339
340
341
  	/*
  	 * FIXME: Handle the 3100/5000 as appropriate. --macro
  	 */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
342
343
344
345
  	struct dz_port *dport = (struct dz_port *)uport;
  	unsigned int mctrl = TIOCM_CAR | TIOCM_DSR | TIOCM_CTS;
  
  	if (dport->port.line == DZ_MODEM) {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
346
347
348
349
350
351
352
353
354
  		if (dz_in(dport, DZ_MSR) & DZ_MODEM_DSR)
  			mctrl &= ~TIOCM_DSR;
  	}
  
  	return mctrl;
  }
  
  static void dz_set_mctrl(struct uart_port *uport, unsigned int mctrl)
  {
9399575dd   Maciej W. Rozycki   [PATCH] dz: Fixes...
355
356
357
  	/*
  	 * FIXME: Handle the 3100/5000 as appropriate. --macro
  	 */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
  	struct dz_port *dport = (struct dz_port *)uport;
  	unsigned short tmp;
  
  	if (dport->port.line == DZ_MODEM) {
  		tmp = dz_in(dport, DZ_TCR);
  		if (mctrl & TIOCM_DTR)
  			tmp &= ~DZ_MODEM_DTR;
  		else
  			tmp |= DZ_MODEM_DTR;
  		dz_out(dport, DZ_TCR, tmp);
  	}
  }
  
  /*
   * -------------------------------------------------------------------
   * startup ()
   *
   * various initialization tasks
fd8c59721   Ralf Baechle   [SERIAL] dz: Nuke...
376
   * -------------------------------------------------------------------
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
377
378
379
380
381
382
   */
  static int dz_startup(struct uart_port *uport)
  {
  	struct dz_port *dport = (struct dz_port *)uport;
  	unsigned long flags;
  	unsigned short tmp;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
383
384
385
386
387
388
389
390
391
392
393
  	spin_lock_irqsave(&dport->port.lock, flags);
  
  	/* enable the interrupt and the scanning */
  	tmp = dz_in(dport, DZ_CSR);
  	tmp |= DZ_RIE | DZ_TIE | DZ_MSE;
  	dz_out(dport, DZ_CSR, tmp);
  
  	spin_unlock_irqrestore(&dport->port.lock, flags);
  
  	return 0;
  }
fd8c59721   Ralf Baechle   [SERIAL] dz: Nuke...
394
  /*
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
395
396
397
398
399
   * -------------------------------------------------------------------
   * shutdown ()
   *
   * This routine will shutdown a serial port; interrupts are disabled, and
   * DTR is dropped if the hangup on close termio flag is on.
fd8c59721   Ralf Baechle   [SERIAL] dz: Nuke...
400
   * -------------------------------------------------------------------
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
401
402
403
   */
  static void dz_shutdown(struct uart_port *uport)
  {
b129a8ccd   Russell King   [SERIAL] Clean up...
404
  	dz_stop_tx(uport);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
405
406
407
  }
  
  /*
9399575dd   Maciej W. Rozycki   [PATCH] dz: Fixes...
408
409
   * -------------------------------------------------------------------
   * dz_tx_empty() -- get the transmitter empty status
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
410
411
412
413
414
415
   *
   * Purpose: Let user call ioctl() to get info when the UART physically
   *          is emptied.  On bus types like RS485, the transmitter must
   *          release the bus after transmitting. This must be done when
   *          the transmit shift register is empty, not be done when the
   *          transmit holding register is empty.  This functionality
fd8c59721   Ralf Baechle   [SERIAL] dz: Nuke...
416
   *          allows an RS485 driver to be written in user space.
9399575dd   Maciej W. Rozycki   [PATCH] dz: Fixes...
417
   * -------------------------------------------------------------------
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
418
419
420
421
   */
  static unsigned int dz_tx_empty(struct uart_port *uport)
  {
  	struct dz_port *dport = (struct dz_port *)uport;
9399575dd   Maciej W. Rozycki   [PATCH] dz: Fixes...
422
  	unsigned short tmp, mask = 1 << dport->port.line;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
423

9399575dd   Maciej W. Rozycki   [PATCH] dz: Fixes...
424
425
426
427
  	tmp = dz_in(dport, DZ_TCR);
  	tmp &= mask;
  
  	return tmp ? 0 : TIOCSER_TEMT;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
428
429
430
431
  }
  
  static void dz_break_ctl(struct uart_port *uport, int break_state)
  {
9399575dd   Maciej W. Rozycki   [PATCH] dz: Fixes...
432
433
434
435
  	/*
  	 * FIXME: Can't access BREAK bits in TDR easily;
  	 * reuse the code for polled TX. --macro
  	 */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
436
437
  	struct dz_port *dport = (struct dz_port *)uport;
  	unsigned long flags;
9399575dd   Maciej W. Rozycki   [PATCH] dz: Fixes...
438
  	unsigned short tmp, mask = 1 << dport->port.line;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
439
440
441
442
443
444
445
446
447
448
  
  	spin_lock_irqsave(&uport->lock, flags);
  	tmp = dz_in(dport, DZ_TCR);
  	if (break_state)
  		tmp |= mask;
  	else
  		tmp &= ~mask;
  	dz_out(dport, DZ_TCR, tmp);
  	spin_unlock_irqrestore(&uport->lock, flags);
  }
606d099cd   Alan Cox   [PATCH] tty: swit...
449
450
  static void dz_set_termios(struct uart_port *uport, struct ktermios *termios,
  			   struct ktermios *old_termios)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
  {
  	struct dz_port *dport = (struct dz_port *)uport;
  	unsigned long flags;
  	unsigned int cflag, baud;
  
  	cflag = dport->port.line;
  
  	switch (termios->c_cflag & CSIZE) {
  	case CS5:
  		cflag |= DZ_CS5;
  		break;
  	case CS6:
  		cflag |= DZ_CS6;
  		break;
  	case CS7:
  		cflag |= DZ_CS7;
  		break;
  	case CS8:
  	default:
  		cflag |= DZ_CS8;
  	}
  
  	if (termios->c_cflag & CSTOPB)
  		cflag |= DZ_CSTOPB;
  	if (termios->c_cflag & PARENB)
  		cflag |= DZ_PARENB;
  	if (termios->c_cflag & PARODD)
  		cflag |= DZ_PARODD;
  
  	baud = uart_get_baud_rate(uport, termios, old_termios, 50, 9600);
  	switch (baud) {
  	case 50:
  		cflag |= DZ_B50;
  		break;
  	case 75:
  		cflag |= DZ_B75;
  		break;
  	case 110:
  		cflag |= DZ_B110;
  		break;
  	case 134:
  		cflag |= DZ_B134;
  		break;
  	case 150:
  		cflag |= DZ_B150;
  		break;
  	case 300:
  		cflag |= DZ_B300;
  		break;
  	case 600:
  		cflag |= DZ_B600;
  		break;
  	case 1200:
  		cflag |= DZ_B1200;
  		break;
  	case 1800:
  		cflag |= DZ_B1800;
  		break;
  	case 2000:
  		cflag |= DZ_B2000;
  		break;
  	case 2400:
  		cflag |= DZ_B2400;
  		break;
  	case 3600:
  		cflag |= DZ_B3600;
  		break;
  	case 4800:
  		cflag |= DZ_B4800;
  		break;
  	case 7200:
  		cflag |= DZ_B7200;
  		break;
  	case 9600:
  	default:
  		cflag |= DZ_B9600;
  	}
  
  	if (termios->c_cflag & CREAD)
  		cflag |= DZ_RXENAB;
  
  	spin_lock_irqsave(&dport->port.lock, flags);
9399575dd   Maciej W. Rozycki   [PATCH] dz: Fixes...
533
  	dz_out(dport, DZ_LPR, cflag | dport->port.line);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
  	dport->cflag = cflag;
  
  	/* setup accept flag */
  	dport->port.read_status_mask = DZ_OERR;
  	if (termios->c_iflag & INPCK)
  		dport->port.read_status_mask |= DZ_FERR | DZ_PERR;
  
  	/* characters to ignore */
  	uport->ignore_status_mask = 0;
  	if (termios->c_iflag & IGNPAR)
  		dport->port.ignore_status_mask |= DZ_FERR | DZ_PERR;
  
  	spin_unlock_irqrestore(&dport->port.lock, flags);
  }
  
  static const char *dz_type(struct uart_port *port)
  {
  	return "DZ";
  }
  
  static void dz_release_port(struct uart_port *port)
  {
  	/* nothing to do */
  }
  
  static int dz_request_port(struct uart_port *port)
  {
  	return 0;
  }
  
  static void dz_config_port(struct uart_port *port, int flags)
  {
  	if (flags & UART_CONFIG_TYPE)
  		port->type = PORT_DZ;
  }
  
  /*
   * verify the new serial_struct (for TIOCSSERIAL).
   */
  static int dz_verify_port(struct uart_port *port, struct serial_struct *ser)
  {
  	int ret = 0;
  	if (ser->type != PORT_UNKNOWN && ser->type != PORT_DZ)
  		ret = -EINVAL;
  	if (ser->irq != port->irq)
  		ret = -EINVAL;
  	return ret;
  }
  
  static struct uart_ops dz_ops = {
  	.tx_empty	= dz_tx_empty,
  	.get_mctrl	= dz_get_mctrl,
  	.set_mctrl	= dz_set_mctrl,
  	.stop_tx	= dz_stop_tx,
  	.start_tx	= dz_start_tx,
  	.stop_rx	= dz_stop_rx,
  	.enable_ms	= dz_enable_ms,
  	.break_ctl	= dz_break_ctl,
  	.startup	= dz_startup,
  	.shutdown	= dz_shutdown,
  	.set_termios	= dz_set_termios,
  	.type		= dz_type,
  	.release_port	= dz_release_port,
  	.request_port	= dz_request_port,
  	.config_port	= dz_config_port,
  	.verify_port	= dz_verify_port,
  };
  
  static void __init dz_init_ports(void)
  {
  	static int first = 1;
  	struct dz_port *dport;
  	unsigned long base;
  	int i;
  
  	if (!first)
  		return;
  	first = 0;
  
  	if (mips_machtype == MACH_DS23100 ||
  	    mips_machtype == MACH_DS5100)
46677736b   Ralf Baechle   [SERIAL] dz: Use ...
615
  		base = CKSEG1ADDR(KN01_SLOT_BASE + KN01_DZ11);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
616
  	else
46677736b   Ralf Baechle   [SERIAL] dz: Use ...
617
  		base = CKSEG1ADDR(KN02_SLOT_BASE + KN02_DZ11);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
618
619
620
621
  
  	for (i = 0, dport = dz_ports; i < DZ_NB_PORT; i++, dport++) {
  		spin_lock_init(&dport->port.lock);
  		dport->port.membase	= (char *) base;
9399575dd   Maciej W. Rozycki   [PATCH] dz: Fixes...
622
  		dport->port.iotype	= UPIO_MEM;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
623
624
625
626
627
628
629
630
631
632
633
  		dport->port.irq		= dec_interrupt[DEC_IRQ_DZ11];
  		dport->port.line	= i;
  		dport->port.fifosize	= 1;
  		dport->port.ops		= &dz_ops;
  		dport->port.flags	= UPF_BOOT_AUTOCONF;
  	}
  }
  
  static void dz_reset(struct dz_port *dport)
  {
  	dz_out(dport, DZ_CSR, DZ_CLR);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
634
  	while (dz_in(dport, DZ_CSR) & DZ_CLR);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
635
636
637
638
639
640
641
  	iob();
  
  	/* enable scanning */
  	dz_out(dport, DZ_CSR, DZ_MSE);
  }
  
  #ifdef CONFIG_SERIAL_DZ_CONSOLE
9399575dd   Maciej W. Rozycki   [PATCH] dz: Fixes...
642
643
644
645
646
647
648
649
650
651
652
653
654
655
  /*
   * -------------------------------------------------------------------
   * dz_console_putchar() -- transmit a character
   *
   * Polled transmission.  This is tricky.  We need to mask transmit
   * interrupts so that they do not interfere, enable the transmitter
   * for the line requested and then wait till the transmit scanner
   * requests data for this line.  But it may request data for another
   * line first, in which case we have to disable its transmitter and
   * repeat waiting till our line pops up.  Only then the character may
   * be transmitted.  Finally, the state of the transmitter mask is
   * restored.  Welcome to the world of PDP-11!
   * -------------------------------------------------------------------
   */
d608ab991   Martin Michlmayr   [SERIAL] dz: Fix ...
656
  static void dz_console_putchar(struct uart_port *uport, int ch)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
657
  {
d358788f3   Russell King   [SERIAL] kernel c...
658
  	struct dz_port *dport = (struct dz_port *)uport;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
659
  	unsigned long flags;
9399575dd   Maciej W. Rozycki   [PATCH] dz: Fixes...
660
661
  	unsigned short csr, tcr, trdy, mask;
  	int loops = 10000;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
662
663
  
  	spin_lock_irqsave(&dport->port.lock, flags);
9399575dd   Maciej W. Rozycki   [PATCH] dz: Fixes...
664
665
666
667
668
669
670
671
  	csr = dz_in(dport, DZ_CSR);
  	dz_out(dport, DZ_CSR, csr & ~DZ_TIE);
  	tcr = dz_in(dport, DZ_TCR);
  	tcr |= 1 << dport->port.line;
  	mask = tcr;
  	dz_out(dport, DZ_TCR, mask);
  	iob();
  	spin_unlock_irqrestore(&dport->port.lock, flags);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
672

9399575dd   Maciej W. Rozycki   [PATCH] dz: Fixes...
673
674
675
676
677
678
679
680
681
682
683
684
  	while (loops--) {
  		trdy = dz_in(dport, DZ_CSR);
  		if (!(trdy & DZ_TRDY))
  			continue;
  		trdy = (trdy & DZ_TLINE) >> 8;
  		if (trdy == dport->port.line)
  			break;
  		mask &= ~(1 << trdy);
  		dz_out(dport, DZ_TCR, mask);
  		iob();
  		udelay(2);
  	}
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
685

9399575dd   Maciej W. Rozycki   [PATCH] dz: Fixes...
686
687
  	if (loops)				/* Cannot send otherwise. */
  		dz_out(dport, DZ_TDR, ch);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
688

9399575dd   Maciej W. Rozycki   [PATCH] dz: Fixes...
689
690
  	dz_out(dport, DZ_TCR, tcr);
  	dz_out(dport, DZ_CSR, csr);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
691
  }
d358788f3   Russell King   [SERIAL] kernel c...
692

fd8c59721   Ralf Baechle   [SERIAL] dz: Nuke...
693
  /*
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
694
695
696
697
698
   * -------------------------------------------------------------------
   * dz_console_print ()
   *
   * dz_console_print is registered for printk.
   * The console must be locked when we get here.
fd8c59721   Ralf Baechle   [SERIAL] dz: Nuke...
699
   * -------------------------------------------------------------------
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
700
   */
9399575dd   Maciej W. Rozycki   [PATCH] dz: Fixes...
701
  static void dz_console_print(struct console *co,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
702
703
704
  			     const char *str,
  			     unsigned int count)
  {
9399575dd   Maciej W. Rozycki   [PATCH] dz: Fixes...
705
  	struct dz_port *dport = &dz_ports[co->index];
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
706
707
708
  #ifdef DEBUG_DZ
  	prom_printf((char *) str);
  #endif
d358788f3   Russell King   [SERIAL] kernel c...
709
  	uart_console_write(&dport->port, str, count, dz_console_putchar);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
710
711
712
713
  }
  
  static int __init dz_console_setup(struct console *co, char *options)
  {
9399575dd   Maciej W. Rozycki   [PATCH] dz: Fixes...
714
  	struct dz_port *dport = &dz_ports[co->index];
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
715
716
717
718
  	int baud = 9600;
  	int bits = 8;
  	int parity = 'n';
  	int flow = 'n';
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
719
720
721
722
723
  
  	if (options)
  		uart_parse_options(options, &baud, &parity, &bits, &flow);
  
  	dz_reset(dport);
9399575dd   Maciej W. Rozycki   [PATCH] dz: Fixes...
724
  	return uart_set_options(&dport->port, co, baud, parity, bits, flow);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
725
  }
9399575dd   Maciej W. Rozycki   [PATCH] dz: Fixes...
726
727
  static struct uart_driver dz_reg;
  static struct console dz_sercons = {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
728
729
730
731
  	.name	= "ttyS",
  	.write	= dz_console_print,
  	.device	= uart_console_device,
  	.setup	= dz_console_setup,
9399575dd   Maciej W. Rozycki   [PATCH] dz: Fixes...
732
733
734
  	.flags	= CON_PRINTBUFFER,
  	.index	= -1,
  	.data	= &dz_reg,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
735
  };
9399575dd   Maciej W. Rozycki   [PATCH] dz: Fixes...
736
  static int __init dz_serial_console_init(void)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
737
  {
9399575dd   Maciej W. Rozycki   [PATCH] dz: Fixes...
738
739
740
741
742
743
  	if (!IOASIC) {
  		dz_init_ports();
  		register_console(&dz_sercons);
  		return 0;
  	} else
  		return -ENXIO;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
744
  }
9399575dd   Maciej W. Rozycki   [PATCH] dz: Fixes...
745
  console_initcall(dz_serial_console_init);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
746
747
748
749
750
751
752
753
  #define SERIAL_DZ_CONSOLE	&dz_sercons
  #else
  #define SERIAL_DZ_CONSOLE	NULL
  #endif /* CONFIG_SERIAL_DZ_CONSOLE */
  
  static struct uart_driver dz_reg = {
  	.owner			= THIS_MODULE,
  	.driver_name		= "serial",
9399575dd   Maciej W. Rozycki   [PATCH] dz: Fixes...
754
  	.dev_name		= "ttyS",
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
755
756
757
758
759
  	.major			= TTY_MAJOR,
  	.minor			= 64,
  	.nr			= DZ_NB_PORT,
  	.cons			= SERIAL_DZ_CONSOLE,
  };
9399575dd   Maciej W. Rozycki   [PATCH] dz: Fixes...
760
  static int __init dz_init(void)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
761
  {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
762
  	int ret, i;
9399575dd   Maciej W. Rozycki   [PATCH] dz: Fixes...
763
764
  	if (IOASIC)
  		return -ENXIO;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
765
766
767
768
  	printk("%s%s
  ", dz_name, dz_version);
  
  	dz_init_ports();
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
769
770
771
772
  #ifndef CONFIG_SERIAL_DZ_CONSOLE
  	/* reset the chip */
  	dz_reset(&dz_ports[0]);
  #endif
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
773
  	if (request_irq(dz_ports[0].port.irq, dz_interrupt,
40663cc7f   Thomas Gleixner   [PATCH] irq-flags...
774
  			IRQF_DISABLED, "DZ", &dz_ports[0]))
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
775
776
777
778
779
780
781
782
783
784
785
  		panic("Unable to register DZ interrupt");
  
  	ret = uart_register_driver(&dz_reg);
  	if (ret != 0)
  		return ret;
  
  	for (i = 0; i < DZ_NB_PORT; i++)
  		uart_add_one_port(&dz_reg, &dz_ports[i].port);
  
  	return ret;
  }
9399575dd   Maciej W. Rozycki   [PATCH] dz: Fixes...
786
  module_init(dz_init);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
787
788
  MODULE_DESCRIPTION("DECstation DZ serial driver");
  MODULE_LICENSE("GPL");