Blame view

drivers/serial/serial_txx9.c 31.9 KB
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
  /*
   *  drivers/serial/serial_txx9.c
   *
   * Derived from many drivers using generic_serial interface,
   * especially serial_tx3912.c by Steven J. Hill and r39xx_serial.c
   * (was in Linux/VR tree) by Jim Pick.
   *
   *  Copyright (C) 1999 Harald Koerfgen
   *  Copyright (C) 2000 Jim Pick <jim@jimpick.com>
   *  Copyright (C) 2001 Steven J. Hill (sjhill@realitydiluted.com)
   *  Copyright (C) 2000-2002 Toshiba Corporation
   *
   * This program is free software; you can redistribute it and/or modify
   * it under the terms of the GNU General Public License version 2 as
   * published by the Free Software Foundation.
   *
   *  Serial driver for TX3927/TX4927/TX4925/TX4938 internal SIO controller
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
18
   */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
19
20
21
22
23
24
25
26
27
  
  #if defined(CONFIG_SERIAL_TXX9_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ)
  #define SUPPORT_SYSRQ
  #endif
  
  #include <linux/module.h>
  #include <linux/ioport.h>
  #include <linux/init.h>
  #include <linux/console.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
28
  #include <linux/delay.h>
0970769ac   Atsushi Nemoto   [SERIAL] serial_t...
29
  #include <linux/platform_device.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
30
  #include <linux/pci.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
31
32
33
34
  #include <linux/serial_core.h>
  #include <linux/serial.h>
  
  #include <asm/io.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
35

37a6c7d00   Atsushi Nemoto   serial_txx9: Use ...
36
  static char *serial_version = "1.11";
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
37
38
39
40
41
42
43
  static char *serial_name = "TX39/49 Serial driver";
  
  #define PASS_LIMIT	256
  
  #if !defined(CONFIG_SERIAL_TXX9_STDSERIAL)
  /* "ttyS" is used for standard serial driver */
  #define TXX9_TTY_NAME "ttyTX"
07bafde35   Atsushi Nemoto   serial_txx9: Use ...
44
45
  #define TXX9_TTY_MINOR_START	196
  #define TXX9_TTY_MAJOR	204
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
46
47
48
  #else
  /* acts like standard serial driver */
  #define TXX9_TTY_NAME "ttyS"
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
49
  #define TXX9_TTY_MINOR_START	64
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
50
  #define TXX9_TTY_MAJOR	TTY_MAJOR
07bafde35   Atsushi Nemoto   serial_txx9: Use ...
51
  #endif
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
52
53
54
55
56
57
58
59
60
61
62
63
64
  
  /* flag aliases */
  #define UPF_TXX9_HAVE_CTS_LINE	UPF_BUGGY_UART
  #define UPF_TXX9_USE_SCLK	UPF_MAGIC_MULTIPLIER
  
  #ifdef CONFIG_PCI
  /* support for Toshiba TC86C001 SIO */
  #define ENABLE_SERIAL_TXX9_PCI
  #endif
  
  /*
   * Number of serial ports
   */
138c5d258   Atsushi Nemoto   [PATCH] serial: s...
65
  #define UART_NR  CONFIG_SERIAL_TXX9_NR_UARTS
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
66
67
68
  
  struct uart_txx9_port {
  	struct uart_port	port;
0970769ac   Atsushi Nemoto   [SERIAL] serial_t...
69
  	/* No additional info for now */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
  };
  
  #define TXX9_REGION_SIZE	0x24
  
  /* TXX9 Serial Registers */
  #define TXX9_SILCR	0x00
  #define TXX9_SIDICR	0x04
  #define TXX9_SIDISR	0x08
  #define TXX9_SICISR	0x0c
  #define TXX9_SIFCR	0x10
  #define TXX9_SIFLCR	0x14
  #define TXX9_SIBGR	0x18
  #define TXX9_SITFIFO	0x1c
  #define TXX9_SIRFIFO	0x20
  
  /* SILCR : Line Control */
  #define TXX9_SILCR_SCS_MASK	0x00000060
  #define TXX9_SILCR_SCS_IMCLK	0x00000000
  #define TXX9_SILCR_SCS_IMCLK_BG	0x00000020
  #define TXX9_SILCR_SCS_SCLK	0x00000040
  #define TXX9_SILCR_SCS_SCLK_BG	0x00000060
  #define TXX9_SILCR_UEPS	0x00000010
  #define TXX9_SILCR_UPEN	0x00000008
  #define TXX9_SILCR_USBL_MASK	0x00000004
  #define TXX9_SILCR_USBL_1BIT	0x00000000
  #define TXX9_SILCR_USBL_2BIT	0x00000004
  #define TXX9_SILCR_UMODE_MASK	0x00000003
  #define TXX9_SILCR_UMODE_8BIT	0x00000000
  #define TXX9_SILCR_UMODE_7BIT	0x00000001
  
  /* SIDICR : DMA/Int. Control */
  #define TXX9_SIDICR_TDE	0x00008000
  #define TXX9_SIDICR_RDE	0x00004000
  #define TXX9_SIDICR_TIE	0x00002000
  #define TXX9_SIDICR_RIE	0x00001000
  #define TXX9_SIDICR_SPIE	0x00000800
  #define TXX9_SIDICR_CTSAC	0x00000600
  #define TXX9_SIDICR_STIE_MASK	0x0000003f
  #define TXX9_SIDICR_STIE_OERS		0x00000020
  #define TXX9_SIDICR_STIE_CTSS		0x00000010
  #define TXX9_SIDICR_STIE_RBRKD	0x00000008
  #define TXX9_SIDICR_STIE_TRDY		0x00000004
  #define TXX9_SIDICR_STIE_TXALS	0x00000002
  #define TXX9_SIDICR_STIE_UBRKD	0x00000001
  
  /* SIDISR : DMA/Int. Status */
  #define TXX9_SIDISR_UBRK	0x00008000
  #define TXX9_SIDISR_UVALID	0x00004000
  #define TXX9_SIDISR_UFER	0x00002000
  #define TXX9_SIDISR_UPER	0x00001000
  #define TXX9_SIDISR_UOER	0x00000800
  #define TXX9_SIDISR_ERI	0x00000400
  #define TXX9_SIDISR_TOUT	0x00000200
  #define TXX9_SIDISR_TDIS	0x00000100
  #define TXX9_SIDISR_RDIS	0x00000080
  #define TXX9_SIDISR_STIS	0x00000040
  #define TXX9_SIDISR_RFDN_MASK	0x0000001f
  
  /* SICISR : Change Int. Status */
  #define TXX9_SICISR_OERS	0x00000020
  #define TXX9_SICISR_CTSS	0x00000010
  #define TXX9_SICISR_RBRKD	0x00000008
  #define TXX9_SICISR_TRDY	0x00000004
  #define TXX9_SICISR_TXALS	0x00000002
  #define TXX9_SICISR_UBRKD	0x00000001
  
  /* SIFCR : FIFO Control */
  #define TXX9_SIFCR_SWRST	0x00008000
  #define TXX9_SIFCR_RDIL_MASK	0x00000180
  #define TXX9_SIFCR_RDIL_1	0x00000000
  #define TXX9_SIFCR_RDIL_4	0x00000080
  #define TXX9_SIFCR_RDIL_8	0x00000100
  #define TXX9_SIFCR_RDIL_12	0x00000180
  #define TXX9_SIFCR_RDIL_MAX	0x00000180
  #define TXX9_SIFCR_TDIL_MASK	0x00000018
  #define TXX9_SIFCR_TDIL_MASK	0x00000018
  #define TXX9_SIFCR_TDIL_1	0x00000000
  #define TXX9_SIFCR_TDIL_4	0x00000001
  #define TXX9_SIFCR_TDIL_8	0x00000010
  #define TXX9_SIFCR_TDIL_MAX	0x00000010
  #define TXX9_SIFCR_TFRST	0x00000004
  #define TXX9_SIFCR_RFRST	0x00000002
  #define TXX9_SIFCR_FRSTE	0x00000001
  #define TXX9_SIO_TX_FIFO	8
  #define TXX9_SIO_RX_FIFO	16
  
  /* SIFLCR : Flow Control */
  #define TXX9_SIFLCR_RCS	0x00001000
  #define TXX9_SIFLCR_TES	0x00000800
  #define TXX9_SIFLCR_RTSSC	0x00000200
  #define TXX9_SIFLCR_RSDE	0x00000100
  #define TXX9_SIFLCR_TSDE	0x00000080
  #define TXX9_SIFLCR_RTSTL_MASK	0x0000001e
  #define TXX9_SIFLCR_RTSTL_MAX	0x0000001e
  #define TXX9_SIFLCR_TBRK	0x00000001
  
  /* SIBGR : Baudrate Control */
  #define TXX9_SIBGR_BCLK_MASK	0x00000300
  #define TXX9_SIBGR_BCLK_T0	0x00000000
  #define TXX9_SIBGR_BCLK_T2	0x00000100
  #define TXX9_SIBGR_BCLK_T4	0x00000200
  #define TXX9_SIBGR_BCLK_T6	0x00000300
  #define TXX9_SIBGR_BRD_MASK	0x000000ff
  
  static inline unsigned int sio_in(struct uart_txx9_port *up, int offset)
  {
  	switch (up->port.iotype) {
  	default:
83485f826   Atsushi Nemoto   [PATCH] serial: s...
178
  		return __raw_readl(up->port.membase + offset);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
179
180
181
182
183
184
185
186
187
188
  	case UPIO_PORT:
  		return inl(up->port.iobase + offset);
  	}
  }
  
  static inline void
  sio_out(struct uart_txx9_port *up, int offset, int value)
  {
  	switch (up->port.iotype) {
  	default:
83485f826   Atsushi Nemoto   [PATCH] serial: s...
189
  		__raw_writel(value, up->port.membase + offset);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
  		break;
  	case UPIO_PORT:
  		outl(value, up->port.iobase + offset);
  		break;
  	}
  }
  
  static inline void
  sio_mask(struct uart_txx9_port *up, int offset, unsigned int value)
  {
  	sio_out(up, offset, sio_in(up, offset) & ~value);
  }
  static inline void
  sio_set(struct uart_txx9_port *up, int offset, unsigned int value)
  {
  	sio_out(up, offset, sio_in(up, offset) | value);
  }
  
  static inline void
  sio_quot_set(struct uart_txx9_port *up, int quot)
  {
  	quot >>= 1;
  	if (quot < 256)
  		sio_out(up, TXX9_SIBGR, quot | TXX9_SIBGR_BCLK_T0);
  	else if (quot < (256 << 2))
  		sio_out(up, TXX9_SIBGR, (quot >> 2) | TXX9_SIBGR_BCLK_T2);
  	else if (quot < (256 << 4))
  		sio_out(up, TXX9_SIBGR, (quot >> 4) | TXX9_SIBGR_BCLK_T4);
  	else if (quot < (256 << 6))
  		sio_out(up, TXX9_SIBGR, (quot >> 6) | TXX9_SIBGR_BCLK_T6);
  	else
  		sio_out(up, TXX9_SIBGR, 0xff | TXX9_SIBGR_BCLK_T6);
  }
b129a8ccd   Russell King   [SERIAL] Clean up...
223
  static void serial_txx9_stop_tx(struct uart_port *port)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
224
225
  {
  	struct uart_txx9_port *up = (struct uart_txx9_port *)port;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
226
  	sio_mask(up, TXX9_SIDICR, TXX9_SIDICR_TIE);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
227
  }
b129a8ccd   Russell King   [SERIAL] Clean up...
228
  static void serial_txx9_start_tx(struct uart_port *port)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
229
230
  {
  	struct uart_txx9_port *up = (struct uart_txx9_port *)port;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
231
  	sio_set(up, TXX9_SIDICR, TXX9_SIDICR_TIE);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
232
233
234
235
236
  }
  
  static void serial_txx9_stop_rx(struct uart_port *port)
  {
  	struct uart_txx9_port *up = (struct uart_txx9_port *)port;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
237
  	up->port.read_status_mask &= ~TXX9_SIDISR_RDIS;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
238
239
240
241
242
243
  }
  
  static void serial_txx9_enable_ms(struct uart_port *port)
  {
  	/* TXX9-SIO can not control DTR... */
  }
0970769ac   Atsushi Nemoto   [SERIAL] serial_t...
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
  static void serial_txx9_initialize(struct uart_port *port)
  {
  	struct uart_txx9_port *up = (struct uart_txx9_port *)port;
  	unsigned int tmout = 10000;
  
  	sio_out(up, TXX9_SIFCR, TXX9_SIFCR_SWRST);
  	/* TX4925 BUG WORKAROUND.  Accessing SIOC register
  	 * immediately after soft reset causes bus error. */
  	mmiowb();
  	udelay(1);
  	while ((sio_in(up, TXX9_SIFCR) & TXX9_SIFCR_SWRST) && --tmout)
  		udelay(1);
  	/* TX Int by FIFO Empty, RX Int by Receiving 1 char. */
  	sio_set(up, TXX9_SIFCR,
  		TXX9_SIFCR_TDIL_MAX | TXX9_SIFCR_RDIL_1);
  	/* initial settings */
  	sio_out(up, TXX9_SILCR,
  		TXX9_SILCR_UMODE_8BIT | TXX9_SILCR_USBL_1BIT |
  		((up->port.flags & UPF_TXX9_USE_SCLK) ?
  		 TXX9_SILCR_SCS_SCLK_BG : TXX9_SILCR_SCS_IMCLK_BG));
  	sio_quot_set(up, uart_get_divisor(port, 9600));
  	sio_out(up, TXX9_SIFLCR, TXX9_SIFLCR_RTSTL_MAX /* 15 */);
  	sio_out(up, TXX9_SIDICR, 0);
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
268
  static inline void
7d12e780e   David Howells   IRQ: Maintain reg...
269
  receive_chars(struct uart_txx9_port *up, unsigned int *status)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
270
  {
1aa3692da   Alan Cox   ttydev: Fix up co...
271
  	struct tty_struct *tty = up->port.info->port.tty;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
272
273
274
275
  	unsigned char ch;
  	unsigned int disr = *status;
  	int max_count = 256;
  	char flag;
83485f826   Atsushi Nemoto   [PATCH] serial: s...
276
  	unsigned int next_ignore_status_mask;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
277
278
  
  	do {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
279
280
281
  		ch = sio_in(up, TXX9_SIRFIFO);
  		flag = TTY_NORMAL;
  		up->port.icount.rx++;
83485f826   Atsushi Nemoto   [PATCH] serial: s...
282
283
284
  		/* mask out RFDN_MASK bit added by previous overrun */
  		next_ignore_status_mask =
  			up->port.ignore_status_mask & ~TXX9_SIDISR_RFDN_MASK;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
  		if (unlikely(disr & (TXX9_SIDISR_UBRK | TXX9_SIDISR_UPER |
  				     TXX9_SIDISR_UFER | TXX9_SIDISR_UOER))) {
  			/*
  			 * For statistics only
  			 */
  			if (disr & TXX9_SIDISR_UBRK) {
  				disr &= ~(TXX9_SIDISR_UFER | TXX9_SIDISR_UPER);
  				up->port.icount.brk++;
  				/*
  				 * We do the SysRQ and SAK checking
  				 * here because otherwise the break
  				 * may get masked by ignore_status_mask
  				 * or read_status_mask.
  				 */
  				if (uart_handle_break(&up->port))
  					goto ignore_char;
  			} else if (disr & TXX9_SIDISR_UPER)
  				up->port.icount.parity++;
  			else if (disr & TXX9_SIDISR_UFER)
  				up->port.icount.frame++;
83485f826   Atsushi Nemoto   [PATCH] serial: s...
305
  			if (disr & TXX9_SIDISR_UOER) {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
306
  				up->port.icount.overrun++;
83485f826   Atsushi Nemoto   [PATCH] serial: s...
307
308
309
310
311
312
313
314
315
  				/*
  				 * The receiver read buffer still hold
  				 * a char which caused overrun.
  				 * Ignore next char by adding RFDN_MASK
  				 * to ignore_status_mask temporarily.
  				 */
  				next_ignore_status_mask |=
  					TXX9_SIDISR_RFDN_MASK;
  			}
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
316
317
318
319
320
321
322
323
324
325
326
327
328
  
  			/*
  			 * Mask off conditions which should be ingored.
  			 */
  			disr &= up->port.read_status_mask;
  
  			if (disr & TXX9_SIDISR_UBRK) {
  				flag = TTY_BREAK;
  			} else if (disr & TXX9_SIDISR_UPER)
  				flag = TTY_PARITY;
  			else if (disr & TXX9_SIDISR_UFER)
  				flag = TTY_FRAME;
  		}
7d12e780e   David Howells   IRQ: Maintain reg...
329
  		if (uart_handle_sysrq_char(&up->port, ch))
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
330
  			goto ignore_char;
05ab30146   Russell King   [PATCH] Serial: A...
331
332
  
  		uart_insert_char(&up->port, disr, TXX9_SIDISR_UOER, ch, flag);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
333
  	ignore_char:
83485f826   Atsushi Nemoto   [PATCH] serial: s...
334
  		up->port.ignore_status_mask = next_ignore_status_mask;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
335
336
  		disr = sio_in(up, TXX9_SIDISR);
  	} while (!(disr & TXX9_SIDISR_UVALID) && (max_count-- > 0));
f5ee56cc1   Ralf Baechle   [PATCH] txx9 seri...
337
  	spin_unlock(&up->port.lock);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
338
  	tty_flip_buffer_push(tty);
f5ee56cc1   Ralf Baechle   [PATCH] txx9 seri...
339
  	spin_lock(&up->port.lock);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
  	*status = disr;
  }
  
  static inline void transmit_chars(struct uart_txx9_port *up)
  {
  	struct circ_buf *xmit = &up->port.info->xmit;
  	int count;
  
  	if (up->port.x_char) {
  		sio_out(up, TXX9_SITFIFO, up->port.x_char);
  		up->port.icount.tx++;
  		up->port.x_char = 0;
  		return;
  	}
  	if (uart_circ_empty(xmit) || uart_tx_stopped(&up->port)) {
b129a8ccd   Russell King   [SERIAL] Clean up...
355
  		serial_txx9_stop_tx(&up->port);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
  		return;
  	}
  
  	count = TXX9_SIO_TX_FIFO;
  	do {
  		sio_out(up, TXX9_SITFIFO, xmit->buf[xmit->tail]);
  		xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE - 1);
  		up->port.icount.tx++;
  		if (uart_circ_empty(xmit))
  			break;
  	} while (--count > 0);
  
  	if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS)
  		uart_write_wakeup(&up->port);
  
  	if (uart_circ_empty(xmit))
b129a8ccd   Russell King   [SERIAL] Clean up...
372
  		serial_txx9_stop_tx(&up->port);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
373
  }
7d12e780e   David Howells   IRQ: Maintain reg...
374
  static irqreturn_t serial_txx9_interrupt(int irq, void *dev_id)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
  {
  	int pass_counter = 0;
  	struct uart_txx9_port *up = dev_id;
  	unsigned int status;
  
  	while (1) {
  		spin_lock(&up->port.lock);
  		status = sio_in(up, TXX9_SIDISR);
  		if (!(sio_in(up, TXX9_SIDICR) & TXX9_SIDICR_TIE))
  			status &= ~TXX9_SIDISR_TDIS;
  		if (!(status & (TXX9_SIDISR_TDIS | TXX9_SIDISR_RDIS |
  				TXX9_SIDISR_TOUT))) {
  			spin_unlock(&up->port.lock);
  			break;
  		}
  
  		if (status & TXX9_SIDISR_RDIS)
7d12e780e   David Howells   IRQ: Maintain reg...
392
  			receive_chars(up, &status);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
  		if (status & TXX9_SIDISR_TDIS)
  			transmit_chars(up);
  		/* Clear TX/RX Int. Status */
  		sio_mask(up, TXX9_SIDISR,
  			 TXX9_SIDISR_TDIS | TXX9_SIDISR_RDIS |
  			 TXX9_SIDISR_TOUT);
  		spin_unlock(&up->port.lock);
  
  		if (pass_counter++ > PASS_LIMIT)
  			break;
  	}
  
  	return pass_counter ? IRQ_HANDLED : IRQ_NONE;
  }
  
  static unsigned int serial_txx9_tx_empty(struct uart_port *port)
  {
  	struct uart_txx9_port *up = (struct uart_txx9_port *)port;
  	unsigned long flags;
  	unsigned int ret;
  
  	spin_lock_irqsave(&up->port.lock, flags);
  	ret = (sio_in(up, TXX9_SICISR) & TXX9_SICISR_TXALS) ? TIOCSER_TEMT : 0;
  	spin_unlock_irqrestore(&up->port.lock, flags);
  
  	return ret;
  }
  
  static unsigned int serial_txx9_get_mctrl(struct uart_port *port)
  {
  	struct uart_txx9_port *up = (struct uart_txx9_port *)port;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
424
  	unsigned int ret;
999999616   Atsushi Nemoto   serial_txx9: Fix ...
425
426
427
428
  	/* no modem control lines */
  	ret = TIOCM_CAR | TIOCM_DSR;
  	ret |= (sio_in(up, TXX9_SIFLCR) & TXX9_SIFLCR_RTSSC) ? 0 : TIOCM_RTS;
  	ret |= (sio_in(up, TXX9_SICISR) & TXX9_SICISR_CTSS) ? 0 : TIOCM_CTS;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
429
430
431
432
433
434
435
  
  	return ret;
  }
  
  static void serial_txx9_set_mctrl(struct uart_port *port, unsigned int mctrl)
  {
  	struct uart_txx9_port *up = (struct uart_txx9_port *)port;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
436

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
437
438
439
440
  	if (mctrl & TIOCM_RTS)
  		sio_mask(up, TXX9_SIFLCR, TXX9_SIFLCR_RTSSC);
  	else
  		sio_set(up, TXX9_SIFLCR, TXX9_SIFLCR_RTSSC);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
  }
  
  static void serial_txx9_break_ctl(struct uart_port *port, int break_state)
  {
  	struct uart_txx9_port *up = (struct uart_txx9_port *)port;
  	unsigned long flags;
  
  	spin_lock_irqsave(&up->port.lock, flags);
  	if (break_state == -1)
  		sio_set(up, TXX9_SIFLCR, TXX9_SIFLCR_TBRK);
  	else
  		sio_mask(up, TXX9_SIFLCR, TXX9_SIFLCR_TBRK);
  	spin_unlock_irqrestore(&up->port.lock, flags);
  }
  
  static int serial_txx9_startup(struct uart_port *port)
  {
  	struct uart_txx9_port *up = (struct uart_txx9_port *)port;
  	unsigned long flags;
  	int retval;
  
  	/*
  	 * Clear the FIFO buffers and disable them.
7f927fcc2   Alexey Dobriyan   [PATCH] Typo fixes
464
  	 * (they will be reenabled in set_termios())
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
465
466
467
468
469
470
471
472
473
474
475
476
477
478
  	 */
  	sio_set(up, TXX9_SIFCR,
  		TXX9_SIFCR_TFRST | TXX9_SIFCR_RFRST | TXX9_SIFCR_FRSTE);
  	/* clear reset */
  	sio_mask(up, TXX9_SIFCR,
  		 TXX9_SIFCR_TFRST | TXX9_SIFCR_RFRST | TXX9_SIFCR_FRSTE);
  	sio_out(up, TXX9_SIDICR, 0);
  
  	/*
  	 * Clear the interrupt registers.
  	 */
  	sio_out(up, TXX9_SIDISR, 0);
  
  	retval = request_irq(up->port.irq, serial_txx9_interrupt,
40663cc7f   Thomas Gleixner   [PATCH] irq-flags...
479
  			     IRQF_SHARED, "serial_txx9", up);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
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
533
534
535
536
537
538
539
  	if (retval)
  		return retval;
  
  	/*
  	 * Now, initialize the UART
  	 */
  	spin_lock_irqsave(&up->port.lock, flags);
  	serial_txx9_set_mctrl(&up->port, up->port.mctrl);
  	spin_unlock_irqrestore(&up->port.lock, flags);
  
  	/* Enable RX/TX */
  	sio_mask(up, TXX9_SIFLCR, TXX9_SIFLCR_RSDE | TXX9_SIFLCR_TSDE);
  
  	/*
  	 * Finally, enable interrupts.
  	 */
  	sio_set(up, TXX9_SIDICR, TXX9_SIDICR_RIE);
  
  	return 0;
  }
  
  static void serial_txx9_shutdown(struct uart_port *port)
  {
  	struct uart_txx9_port *up = (struct uart_txx9_port *)port;
  	unsigned long flags;
  
  	/*
  	 * Disable interrupts from this port
  	 */
  	sio_out(up, TXX9_SIDICR, 0);	/* disable all intrs */
  
  	spin_lock_irqsave(&up->port.lock, flags);
  	serial_txx9_set_mctrl(&up->port, up->port.mctrl);
  	spin_unlock_irqrestore(&up->port.lock, flags);
  
  	/*
  	 * Disable break condition
  	 */
  	sio_mask(up, TXX9_SIFLCR, TXX9_SIFLCR_TBRK);
  
  #ifdef CONFIG_SERIAL_TXX9_CONSOLE
  	if (up->port.cons && up->port.line == up->port.cons->index) {
  		free_irq(up->port.irq, up);
  		return;
  	}
  #endif
  	/* reset FIFOs */
  	sio_set(up, TXX9_SIFCR,
  		TXX9_SIFCR_TFRST | TXX9_SIFCR_RFRST | TXX9_SIFCR_FRSTE);
  	/* clear reset */
  	sio_mask(up, TXX9_SIFCR,
  		 TXX9_SIFCR_TFRST | TXX9_SIFCR_RFRST | TXX9_SIFCR_FRSTE);
  
  	/* Disable RX/TX */
  	sio_set(up, TXX9_SIFLCR, TXX9_SIFLCR_RSDE | TXX9_SIFLCR_TSDE);
  
  	free_irq(up->port.irq, up);
  }
  
  static void
606d099cd   Alan Cox   [PATCH] tty: swit...
540
541
  serial_txx9_set_termios(struct uart_port *port, struct ktermios *termios,
  		       struct ktermios *old)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
542
543
544
545
546
  {
  	struct uart_txx9_port *up = (struct uart_txx9_port *)port;
  	unsigned int cval, fcr = 0;
  	unsigned long flags;
  	unsigned int baud, quot;
999999616   Atsushi Nemoto   serial_txx9: Fix ...
547
548
549
550
551
  	/*
  	 * We don't support modem control lines.
  	 */
  	termios->c_cflag &= ~(HUPCL | CMSPAR);
  	termios->c_cflag |= CLOCAL;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
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
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
  	cval = sio_in(up, TXX9_SILCR);
  	/* byte size and parity */
  	cval &= ~TXX9_SILCR_UMODE_MASK;
  	switch (termios->c_cflag & CSIZE) {
  	case CS7:
  		cval |= TXX9_SILCR_UMODE_7BIT;
  		break;
  	default:
  	case CS5:	/* not supported */
  	case CS6:	/* not supported */
  	case CS8:
  		cval |= TXX9_SILCR_UMODE_8BIT;
  		break;
  	}
  
  	cval &= ~TXX9_SILCR_USBL_MASK;
  	if (termios->c_cflag & CSTOPB)
  		cval |= TXX9_SILCR_USBL_2BIT;
  	else
  		cval |= TXX9_SILCR_USBL_1BIT;
  	cval &= ~(TXX9_SILCR_UPEN | TXX9_SILCR_UEPS);
  	if (termios->c_cflag & PARENB)
  		cval |= TXX9_SILCR_UPEN;
  	if (!(termios->c_cflag & PARODD))
  		cval |= TXX9_SILCR_UEPS;
  
  	/*
  	 * Ask the core to calculate the divisor for us.
  	 */
  	baud = uart_get_baud_rate(port, termios, old, 0, port->uartclk/16/2);
  	quot = uart_get_divisor(port, baud);
  
  	/* Set up FIFOs */
  	/* TX Int by FIFO Empty, RX Int by Receiving 1 char. */
  	fcr = TXX9_SIFCR_TDIL_MAX | TXX9_SIFCR_RDIL_1;
  
  	/*
  	 * Ok, we're now changing the port state.  Do it with
  	 * interrupts disabled.
  	 */
  	spin_lock_irqsave(&up->port.lock, flags);
  
  	/*
  	 * Update the per-port timeout.
  	 */
  	uart_update_timeout(port, termios->c_cflag, baud);
  
  	up->port.read_status_mask = TXX9_SIDISR_UOER |
  		TXX9_SIDISR_TDIS | TXX9_SIDISR_RDIS;
  	if (termios->c_iflag & INPCK)
  		up->port.read_status_mask |= TXX9_SIDISR_UFER | TXX9_SIDISR_UPER;
  	if (termios->c_iflag & (BRKINT | PARMRK))
  		up->port.read_status_mask |= TXX9_SIDISR_UBRK;
  
  	/*
  	 * Characteres to ignore
  	 */
  	up->port.ignore_status_mask = 0;
  	if (termios->c_iflag & IGNPAR)
  		up->port.ignore_status_mask |= TXX9_SIDISR_UPER | TXX9_SIDISR_UFER;
  	if (termios->c_iflag & IGNBRK) {
  		up->port.ignore_status_mask |= TXX9_SIDISR_UBRK;
  		/*
  		 * If we're ignoring parity and break indicators,
  		 * ignore overruns too (for real raw support).
  		 */
  		if (termios->c_iflag & IGNPAR)
  			up->port.ignore_status_mask |= TXX9_SIDISR_UOER;
  	}
  
  	/*
  	 * ignore all characters if CREAD is not set
  	 */
  	if ((termios->c_cflag & CREAD) == 0)
  		up->port.ignore_status_mask |= TXX9_SIDISR_RDIS;
  
  	/* CTS flow control flag */
  	if ((termios->c_cflag & CRTSCTS) &&
  	    (up->port.flags & UPF_TXX9_HAVE_CTS_LINE)) {
  		sio_set(up, TXX9_SIFLCR,
  			TXX9_SIFLCR_RCS | TXX9_SIFLCR_TES);
  	} else {
  		sio_mask(up, TXX9_SIFLCR,
  			 TXX9_SIFLCR_RCS | TXX9_SIFLCR_TES);
  	}
  
  	sio_out(up, TXX9_SILCR, cval);
  	sio_quot_set(up, quot);
  	sio_out(up, TXX9_SIFCR, fcr);
  
  	serial_txx9_set_mctrl(&up->port, up->port.mctrl);
  	spin_unlock_irqrestore(&up->port.lock, flags);
  }
  
  static void
  serial_txx9_pm(struct uart_port *port, unsigned int state,
  	      unsigned int oldstate)
  {
23f42b7b2   Atsushi Nemoto   serial: fix seria...
650
651
652
653
654
655
656
657
658
  	/*
  	 * If oldstate was -1 this is called from
  	 * uart_configure_port().  In this case do not initialize the
  	 * port now, because the port was already initialized (for
  	 * non-console port) or should not be initialized here (for
  	 * console port).  If we initialized the port here we lose
  	 * serial console settings.
  	 */
  	if (state == 0 && oldstate != -1)
0970769ac   Atsushi Nemoto   [SERIAL] serial_t...
659
  		serial_txx9_initialize(port);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
  }
  
  static int serial_txx9_request_resource(struct uart_txx9_port *up)
  {
  	unsigned int size = TXX9_REGION_SIZE;
  	int ret = 0;
  
  	switch (up->port.iotype) {
  	default:
  		if (!up->port.mapbase)
  			break;
  
  		if (!request_mem_region(up->port.mapbase, size, "serial_txx9")) {
  			ret = -EBUSY;
  			break;
  		}
  
  		if (up->port.flags & UPF_IOREMAP) {
  			up->port.membase = ioremap(up->port.mapbase, size);
  			if (!up->port.membase) {
  				release_mem_region(up->port.mapbase, size);
  				ret = -ENOMEM;
  			}
  		}
  		break;
  
  	case UPIO_PORT:
  		if (!request_region(up->port.iobase, size, "serial_txx9"))
  			ret = -EBUSY;
  		break;
  	}
  	return ret;
  }
  
  static void serial_txx9_release_resource(struct uart_txx9_port *up)
  {
  	unsigned int size = TXX9_REGION_SIZE;
  
  	switch (up->port.iotype) {
  	default:
  		if (!up->port.mapbase)
  			break;
  
  		if (up->port.flags & UPF_IOREMAP) {
  			iounmap(up->port.membase);
  			up->port.membase = NULL;
  		}
  
  		release_mem_region(up->port.mapbase, size);
  		break;
  
  	case UPIO_PORT:
  		release_region(up->port.iobase, size);
  		break;
  	}
  }
  
  static void serial_txx9_release_port(struct uart_port *port)
  {
  	struct uart_txx9_port *up = (struct uart_txx9_port *)port;
  	serial_txx9_release_resource(up);
  }
  
  static int serial_txx9_request_port(struct uart_port *port)
  {
  	struct uart_txx9_port *up = (struct uart_txx9_port *)port;
  	return serial_txx9_request_resource(up);
  }
  
  static void serial_txx9_config_port(struct uart_port *port, int uflags)
  {
  	struct uart_txx9_port *up = (struct uart_txx9_port *)port;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
  	int ret;
  
  	/*
  	 * Find the region that we can probe for.  This in turn
  	 * tells us whether we can probe for the type of port.
  	 */
  	ret = serial_txx9_request_resource(up);
  	if (ret < 0)
  		return;
  	port->type = PORT_TXX9;
  	up->port.fifosize = TXX9_SIO_TX_FIFO;
  
  #ifdef CONFIG_SERIAL_TXX9_CONSOLE
  	if (up->port.line == up->port.cons->index)
  		return;
  #endif
0970769ac   Atsushi Nemoto   [SERIAL] serial_t...
748
  	serial_txx9_initialize(port);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
749
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
  static const char *
  serial_txx9_type(struct uart_port *port)
  {
  	return "txx9";
  }
  
  static struct uart_ops serial_txx9_pops = {
  	.tx_empty	= serial_txx9_tx_empty,
  	.set_mctrl	= serial_txx9_set_mctrl,
  	.get_mctrl	= serial_txx9_get_mctrl,
  	.stop_tx	= serial_txx9_stop_tx,
  	.start_tx	= serial_txx9_start_tx,
  	.stop_rx	= serial_txx9_stop_rx,
  	.enable_ms	= serial_txx9_enable_ms,
  	.break_ctl	= serial_txx9_break_ctl,
  	.startup	= serial_txx9_startup,
  	.shutdown	= serial_txx9_shutdown,
  	.set_termios	= serial_txx9_set_termios,
  	.pm		= serial_txx9_pm,
  	.type		= serial_txx9_type,
  	.release_port	= serial_txx9_release_port,
  	.request_port	= serial_txx9_request_port,
  	.config_port	= serial_txx9_config_port,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
773
774
775
  };
  
  static struct uart_txx9_port serial_txx9_ports[UART_NR];
0970769ac   Atsushi Nemoto   [SERIAL] serial_t...
776
777
  static void __init serial_txx9_register_ports(struct uart_driver *drv,
  					      struct device *dev)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
778
779
780
781
782
783
784
785
  {
  	int i;
  
  	for (i = 0; i < UART_NR; i++) {
  		struct uart_txx9_port *up = &serial_txx9_ports[i];
  
  		up->port.line = i;
  		up->port.ops = &serial_txx9_pops;
0970769ac   Atsushi Nemoto   [SERIAL] serial_t...
786
  		up->port.dev = dev;
83485f826   Atsushi Nemoto   [PATCH] serial: s...
787
788
  		if (up->port.iobase || up->port.mapbase)
  			uart_add_one_port(drv, &up->port);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
  	}
  }
  
  #ifdef CONFIG_SERIAL_TXX9_CONSOLE
  
  /*
   *	Wait for transmitter & holding register to empty
   */
  static inline void wait_for_xmitr(struct uart_txx9_port *up)
  {
  	unsigned int tmout = 10000;
  
  	/* Wait up to 10ms for the character(s) to be sent. */
  	while (--tmout &&
  	       !(sio_in(up, TXX9_SICISR) & TXX9_SICISR_TXALS))
  		udelay(1);
  
  	/* Wait up to 1s for flow control if necessary */
  	if (up->port.flags & UPF_CONS_FLOW) {
  		tmout = 1000000;
  		while (--tmout &&
  		       (sio_in(up, TXX9_SICISR) & TXX9_SICISR_CTSS))
  			udelay(1);
  	}
  }
d358788f3   Russell King   [SERIAL] kernel c...
814
815
816
817
818
819
820
  static void serial_txx9_console_putchar(struct uart_port *port, int ch)
  {
  	struct uart_txx9_port *up = (struct uart_txx9_port *)port;
  
  	wait_for_xmitr(up);
  	sio_out(up, TXX9_SITFIFO, ch);
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
821
822
823
824
825
826
827
828
829
830
831
  /*
   *	Print a string to the serial port trying not to disturb
   *	any possible real use of the port...
   *
   *	The console_lock must be held when we get here.
   */
  static void
  serial_txx9_console_write(struct console *co, const char *s, unsigned int count)
  {
  	struct uart_txx9_port *up = &serial_txx9_ports[co->index];
  	unsigned int ier, flcr;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
832
833
834
835
836
837
838
839
840
841
842
843
  
  	/*
  	 *	First save the UER then disable the interrupts
  	 */
  	ier = sio_in(up, TXX9_SIDICR);
  	sio_out(up, TXX9_SIDICR, 0);
  	/*
  	 *	Disable flow-control if enabled (and unnecessary)
  	 */
  	flcr = sio_in(up, TXX9_SIFLCR);
  	if (!(up->port.flags & UPF_CONS_FLOW) && (flcr & TXX9_SIFLCR_TES))
  		sio_out(up, TXX9_SIFLCR, flcr & ~TXX9_SIFLCR_TES);
d358788f3   Russell King   [SERIAL] kernel c...
844
  	uart_console_write(&up->port, s, count, serial_txx9_console_putchar);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
845
846
847
848
849
850
851
852
853
  
  	/*
  	 *	Finally, wait for transmitter to become empty
  	 *	and restore the IER
  	 */
  	wait_for_xmitr(up);
  	sio_out(up, TXX9_SIFLCR, flcr);
  	sio_out(up, TXX9_SIDICR, ier);
  }
0970769ac   Atsushi Nemoto   [SERIAL] serial_t...
854
  static int __init serial_txx9_console_setup(struct console *co, char *options)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
  {
  	struct uart_port *port;
  	struct uart_txx9_port *up;
  	int baud = 9600;
  	int bits = 8;
  	int parity = 'n';
  	int flow = 'n';
  
  	/*
  	 * Check whether an invalid uart number has been specified, and
  	 * if so, search for the first available port that does have
  	 * console support.
  	 */
  	if (co->index >= UART_NR)
  		co->index = 0;
  	up = &serial_txx9_ports[co->index];
  	port = &up->port;
  	if (!port->ops)
  		return -ENODEV;
0970769ac   Atsushi Nemoto   [SERIAL] serial_t...
874
  	serial_txx9_initialize(&up->port);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
  
  	if (options)
  		uart_parse_options(options, &baud, &parity, &bits, &flow);
  
  	return uart_set_options(port, co, baud, parity, bits, flow);
  }
  
  static struct uart_driver serial_txx9_reg;
  static struct console serial_txx9_console = {
  	.name		= TXX9_TTY_NAME,
  	.write		= serial_txx9_console_write,
  	.device		= uart_console_device,
  	.setup		= serial_txx9_console_setup,
  	.flags		= CON_PRINTBUFFER,
  	.index		= -1,
  	.data		= &serial_txx9_reg,
  };
  
  static int __init serial_txx9_console_init(void)
  {
  	register_console(&serial_txx9_console);
  	return 0;
  }
  console_initcall(serial_txx9_console_init);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
899
900
901
902
903
904
905
906
  #define SERIAL_TXX9_CONSOLE	&serial_txx9_console
  #else
  #define SERIAL_TXX9_CONSOLE	NULL
  #endif
  
  static struct uart_driver serial_txx9_reg = {
  	.owner			= THIS_MODULE,
  	.driver_name		= "serial_txx9",
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
907
908
909
910
911
912
913
914
915
916
917
918
919
920
  	.dev_name		= TXX9_TTY_NAME,
  	.major			= TXX9_TTY_MAJOR,
  	.minor			= TXX9_TTY_MINOR_START,
  	.nr			= UART_NR,
  	.cons			= SERIAL_TXX9_CONSOLE,
  };
  
  int __init early_serial_txx9_setup(struct uart_port *port)
  {
  	if (port->line >= ARRAY_SIZE(serial_txx9_ports))
  		return -ENODEV;
  
  	serial_txx9_ports[port->line].port = *port;
  	serial_txx9_ports[port->line].port.ops = &serial_txx9_pops;
37a6c7d00   Atsushi Nemoto   serial_txx9: Use ...
921
922
  	serial_txx9_ports[port->line].port.flags |=
  		UPF_BOOT_AUTOCONF | UPF_FIXED_PORT;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
923
924
  	return 0;
  }
f392ecfa1   Arjan van de Ven   [SERIAL] turn ser...
925
  static DEFINE_MUTEX(serial_txx9_mutex);
f5ee56cc1   Ralf Baechle   [PATCH] txx9 seri...
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
  
  /**
   *	serial_txx9_register_port - register a serial port
   *	@port: serial port template
   *
   *	Configure the serial port specified by the request.
   *
   *	The port is then probed and if necessary the IRQ is autodetected
   *	If this fails an error is returned.
   *
   *	On success the port is ready to use and the line number is returned.
   */
  static int __devinit serial_txx9_register_port(struct uart_port *port)
  {
  	int i;
  	struct uart_txx9_port *uart;
  	int ret = -ENOSPC;
f392ecfa1   Arjan van de Ven   [SERIAL] turn ser...
943
  	mutex_lock(&serial_txx9_mutex);
f5ee56cc1   Ralf Baechle   [PATCH] txx9 seri...
944
945
  	for (i = 0; i < UART_NR; i++) {
  		uart = &serial_txx9_ports[i];
0970769ac   Atsushi Nemoto   [SERIAL] serial_t...
946
947
  		if (uart_match_port(&uart->port, port)) {
  			uart_remove_one_port(&serial_txx9_reg, &uart->port);
f5ee56cc1   Ralf Baechle   [PATCH] txx9 seri...
948
  			break;
0970769ac   Atsushi Nemoto   [SERIAL] serial_t...
949
950
951
952
953
954
955
956
957
  		}
  	}
  	if (i == UART_NR) {
  		/* Find unused port */
  		for (i = 0; i < UART_NR; i++) {
  			uart = &serial_txx9_ports[i];
  			if (!(uart->port.iobase || uart->port.mapbase))
  				break;
  		}
f5ee56cc1   Ralf Baechle   [PATCH] txx9 seri...
958
959
  	}
  	if (i < UART_NR) {
f5ee56cc1   Ralf Baechle   [PATCH] txx9 seri...
960
961
962
963
964
  		uart->port.iobase = port->iobase;
  		uart->port.membase = port->membase;
  		uart->port.irq      = port->irq;
  		uart->port.uartclk  = port->uartclk;
  		uart->port.iotype   = port->iotype;
37a6c7d00   Atsushi Nemoto   serial_txx9: Use ...
965
966
  		uart->port.flags    = port->flags
  			| UPF_BOOT_AUTOCONF | UPF_FIXED_PORT;
f5ee56cc1   Ralf Baechle   [PATCH] txx9 seri...
967
968
969
970
971
972
973
  		uart->port.mapbase  = port->mapbase;
  		if (port->dev)
  			uart->port.dev = port->dev;
  		ret = uart_add_one_port(&serial_txx9_reg, &uart->port);
  		if (ret == 0)
  			ret = uart->port.line;
  	}
f392ecfa1   Arjan van de Ven   [SERIAL] turn ser...
974
  	mutex_unlock(&serial_txx9_mutex);
f5ee56cc1   Ralf Baechle   [PATCH] txx9 seri...
975
976
977
978
979
980
981
982
983
984
985
986
987
  	return ret;
  }
  
  /**
   *	serial_txx9_unregister_port - remove a txx9 serial port at runtime
   *	@line: serial line number
   *
   *	Remove one serial port.  This may not be called from interrupt
   *	context.  We hand the port back to the our control.
   */
  static void __devexit serial_txx9_unregister_port(int line)
  {
  	struct uart_txx9_port *uart = &serial_txx9_ports[line];
f392ecfa1   Arjan van de Ven   [SERIAL] turn ser...
988
  	mutex_lock(&serial_txx9_mutex);
f5ee56cc1   Ralf Baechle   [PATCH] txx9 seri...
989
990
991
992
993
  	uart_remove_one_port(&serial_txx9_reg, &uart->port);
  	uart->port.flags = 0;
  	uart->port.type = PORT_UNKNOWN;
  	uart->port.iobase = 0;
  	uart->port.mapbase = 0;
83485f826   Atsushi Nemoto   [PATCH] serial: s...
994
  	uart->port.membase = NULL;
f5ee56cc1   Ralf Baechle   [PATCH] txx9 seri...
995
  	uart->port.dev = NULL;
f392ecfa1   Arjan van de Ven   [SERIAL] turn ser...
996
  	mutex_unlock(&serial_txx9_mutex);
f5ee56cc1   Ralf Baechle   [PATCH] txx9 seri...
997
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
998
  /*
0970769ac   Atsushi Nemoto   [SERIAL] serial_t...
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
   * Register a set of serial devices attached to a platform device.
   */
  static int __devinit serial_txx9_probe(struct platform_device *dev)
  {
  	struct uart_port *p = dev->dev.platform_data;
  	struct uart_port port;
  	int ret, i;
  
  	memset(&port, 0, sizeof(struct uart_port));
  	for (i = 0; p && p->uartclk != 0; p++, i++) {
  		port.iobase	= p->iobase;
  		port.membase	= p->membase;
  		port.irq	= p->irq;
  		port.uartclk	= p->uartclk;
  		port.iotype	= p->iotype;
  		port.flags	= p->flags;
  		port.mapbase	= p->mapbase;
  		port.dev	= &dev->dev;
  		ret = serial_txx9_register_port(&port);
  		if (ret < 0) {
  			dev_err(&dev->dev, "unable to register port at index %d "
8433ac61a   Atsushi Nemoto   serial_txx9: use ...
1020
1021
  				"(IO%lx MEM%llx IRQ%d): %d
  ", i,
ddb437b7f   Atsushi Nemoto   serial_txx9: fix ...
1022
1023
  				p->iobase, (unsigned long long)p->mapbase,
  				p->irq, ret);
0970769ac   Atsushi Nemoto   [SERIAL] serial_t...
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
  		}
  	}
  	return 0;
  }
  
  /*
   * Remove serial ports registered against a platform device.
   */
  static int __devexit serial_txx9_remove(struct platform_device *dev)
  {
  	int i;
  
  	for (i = 0; i < UART_NR; i++) {
  		struct uart_txx9_port *up = &serial_txx9_ports[i];
  
  		if (up->port.dev == &dev->dev)
  			serial_txx9_unregister_port(i);
  	}
  	return 0;
  }
  
  #ifdef CONFIG_PM
  static int serial_txx9_suspend(struct platform_device *dev, pm_message_t state)
  {
  	int i;
  
  	for (i = 0; i < UART_NR; i++) {
  		struct uart_txx9_port *up = &serial_txx9_ports[i];
  
  		if (up->port.type != PORT_UNKNOWN && up->port.dev == &dev->dev)
  			uart_suspend_port(&serial_txx9_reg, &up->port);
  	}
  
  	return 0;
  }
  
  static int serial_txx9_resume(struct platform_device *dev)
  {
  	int i;
  
  	for (i = 0; i < UART_NR; i++) {
  		struct uart_txx9_port *up = &serial_txx9_ports[i];
  
  		if (up->port.type != PORT_UNKNOWN && up->port.dev == &dev->dev)
  			uart_resume_port(&serial_txx9_reg, &up->port);
  	}
  
  	return 0;
  }
  #endif
  
  static struct platform_driver serial_txx9_plat_driver = {
  	.probe		= serial_txx9_probe,
  	.remove		= __devexit_p(serial_txx9_remove),
  #ifdef CONFIG_PM
  	.suspend	= serial_txx9_suspend,
  	.resume		= serial_txx9_resume,
  #endif
  	.driver		= {
  		.name	= "serial_txx9",
  		.owner	= THIS_MODULE,
  	},
  };
  
  #ifdef ENABLE_SERIAL_TXX9_PCI
  /*
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
   * Probe one serial board.  Unfortunately, there is no rhyme nor reason
   * to the arrangement of serial ports on a PCI card.
   */
  static int __devinit
  pciserial_txx9_init_one(struct pci_dev *dev, const struct pci_device_id *ent)
  {
  	struct uart_port port;
  	int line;
  	int rc;
  
  	rc = pci_enable_device(dev);
  	if (rc)
  		return rc;
  
  	memset(&port, 0, sizeof(port));
  	port.ops = &serial_txx9_pops;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1106
1107
1108
1109
1110
  	port.flags |= UPF_TXX9_HAVE_CTS_LINE;
  	port.uartclk = 66670000;
  	port.irq = dev->irq;
  	port.iotype = UPIO_PORT;
  	port.iobase = pci_resource_start(dev, 1);
f5ee56cc1   Ralf Baechle   [PATCH] txx9 seri...
1111
1112
  	port.dev = &dev->dev;
  	line = serial_txx9_register_port(&port);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1113
1114
1115
  	if (line < 0) {
  		printk(KERN_WARNING "Couldn't register serial port %s: %d
  ", pci_name(dev), line);
0970769ac   Atsushi Nemoto   [SERIAL] serial_t...
1116
1117
  		pci_disable_device(dev);
  		return line;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1118
  	}
0970769ac   Atsushi Nemoto   [SERIAL] serial_t...
1119
  	pci_set_drvdata(dev, &serial_txx9_ports[line]);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1120
1121
1122
1123
1124
1125
  
  	return 0;
  }
  
  static void __devexit pciserial_txx9_remove_one(struct pci_dev *dev)
  {
0970769ac   Atsushi Nemoto   [SERIAL] serial_t...
1126
  	struct uart_txx9_port *up = pci_get_drvdata(dev);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1127
1128
  
  	pci_set_drvdata(dev, NULL);
0970769ac   Atsushi Nemoto   [SERIAL] serial_t...
1129
1130
  	if (up) {
  		serial_txx9_unregister_port(up->port.line);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1131
1132
1133
  		pci_disable_device(dev);
  	}
  }
138c5d258   Atsushi Nemoto   [PATCH] serial: s...
1134
  #ifdef CONFIG_PM
0370affee   Pavel Machek   [PATCH] fix u32 v...
1135
  static int pciserial_txx9_suspend_one(struct pci_dev *dev, pm_message_t state)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1136
  {
0970769ac   Atsushi Nemoto   [SERIAL] serial_t...
1137
  	struct uart_txx9_port *up = pci_get_drvdata(dev);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1138

0970769ac   Atsushi Nemoto   [SERIAL] serial_t...
1139
1140
  	if (up)
  		uart_suspend_port(&serial_txx9_reg, &up->port);
f5ee56cc1   Ralf Baechle   [PATCH] txx9 seri...
1141
1142
  	pci_save_state(dev);
  	pci_set_power_state(dev, pci_choose_state(dev, state));
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1143
1144
1145
1146
1147
  	return 0;
  }
  
  static int pciserial_txx9_resume_one(struct pci_dev *dev)
  {
0970769ac   Atsushi Nemoto   [SERIAL] serial_t...
1148
  	struct uart_txx9_port *up = pci_get_drvdata(dev);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1149

f5ee56cc1   Ralf Baechle   [PATCH] txx9 seri...
1150
1151
  	pci_set_power_state(dev, PCI_D0);
  	pci_restore_state(dev);
0970769ac   Atsushi Nemoto   [SERIAL] serial_t...
1152
1153
  	if (up)
  		uart_resume_port(&serial_txx9_reg, &up->port);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1154
1155
  	return 0;
  }
138c5d258   Atsushi Nemoto   [PATCH] serial: s...
1156
  #endif
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1157

138c5d258   Atsushi Nemoto   [PATCH] serial: s...
1158
1159
  static const struct pci_device_id serial_txx9_pci_tbl[] = {
  	{ PCI_DEVICE(PCI_VENDOR_ID_TOSHIBA_2, PCI_DEVICE_ID_TOSHIBA_TC86C001_MISC) },
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1160
1161
1162
1163
1164
1165
1166
  	{ 0, }
  };
  
  static struct pci_driver serial_txx9_pci_driver = {
  	.name		= "serial_txx9",
  	.probe		= pciserial_txx9_init_one,
  	.remove		= __devexit_p(pciserial_txx9_remove_one),
138c5d258   Atsushi Nemoto   [PATCH] serial: s...
1167
  #ifdef CONFIG_PM
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1168
1169
  	.suspend	= pciserial_txx9_suspend_one,
  	.resume		= pciserial_txx9_resume_one,
138c5d258   Atsushi Nemoto   [PATCH] serial: s...
1170
  #endif
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1171
1172
1173
1174
1175
  	.id_table	= serial_txx9_pci_tbl,
  };
  
  MODULE_DEVICE_TABLE(pci, serial_txx9_pci_tbl);
  #endif /* ENABLE_SERIAL_TXX9_PCI */
0970769ac   Atsushi Nemoto   [SERIAL] serial_t...
1176
  static struct platform_device *serial_txx9_plat_devs;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1177
1178
1179
1180
1181
1182
1183
1184
  static int __init serial_txx9_init(void)
  {
  	int ret;
  
   	printk(KERN_INFO "%s version %s
  ", serial_name, serial_version);
  
  	ret = uart_register_driver(&serial_txx9_reg);
0970769ac   Atsushi Nemoto   [SERIAL] serial_t...
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
  	if (ret)
  		goto out;
  
  	serial_txx9_plat_devs = platform_device_alloc("serial_txx9", -1);
  	if (!serial_txx9_plat_devs) {
  		ret = -ENOMEM;
  		goto unreg_uart_drv;
  	}
  
  	ret = platform_device_add(serial_txx9_plat_devs);
  	if (ret)
  		goto put_dev;
  
  	serial_txx9_register_ports(&serial_txx9_reg,
  				   &serial_txx9_plat_devs->dev);
  
  	ret = platform_driver_register(&serial_txx9_plat_driver);
  	if (ret)
  		goto del_dev;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1204
1205
  
  #ifdef ENABLE_SERIAL_TXX9_PCI
0970769ac   Atsushi Nemoto   [SERIAL] serial_t...
1206
  	ret = pci_register_driver(&serial_txx9_pci_driver);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1207
  #endif
0970769ac   Atsushi Nemoto   [SERIAL] serial_t...
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
  	if (ret == 0)
  		goto out;
  
   del_dev:
  	platform_device_del(serial_txx9_plat_devs);
   put_dev:
  	platform_device_put(serial_txx9_plat_devs);
   unreg_uart_drv:
  	uart_unregister_driver(&serial_txx9_reg);
   out:
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
  	return ret;
  }
  
  static void __exit serial_txx9_exit(void)
  {
  	int i;
  
  #ifdef ENABLE_SERIAL_TXX9_PCI
  	pci_unregister_driver(&serial_txx9_pci_driver);
  #endif
0970769ac   Atsushi Nemoto   [SERIAL] serial_t...
1228
1229
  	platform_driver_unregister(&serial_txx9_plat_driver);
  	platform_device_unregister(serial_txx9_plat_devs);
83485f826   Atsushi Nemoto   [PATCH] serial: s...
1230
1231
1232
1233
1234
  	for (i = 0; i < UART_NR; i++) {
  		struct uart_txx9_port *up = &serial_txx9_ports[i];
  		if (up->port.iobase || up->port.mapbase)
  			uart_remove_one_port(&serial_txx9_reg, &up->port);
  	}
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
  
  	uart_unregister_driver(&serial_txx9_reg);
  }
  
  module_init(serial_txx9_init);
  module_exit(serial_txx9_exit);
  
  MODULE_LICENSE("GPL");
  MODULE_DESCRIPTION("TX39/49 serial driver");
  
  MODULE_ALIAS_CHARDEV_MAJOR(TXX9_TTY_MAJOR);