2 * drivers/serial/serial_txx9.c
4 * Derived from many drivers using generic_serial interface,
5 * especially serial_tx3912.c by Steven J. Hill and r39xx_serial.c
6 * (was in Linux/VR tree) by Jim Pick.
8 * Copyright (C) 1999 Harald Koerfgen
9 * Copyright (C) 2000 Jim Pick <jim@jimpick.com>
10 * Copyright (C) 2001 Steven J. Hill (sjhill@realitydiluted.com)
11 * Copyright (C) 2000-2002 Toshiba Corporation
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License version 2 as
15 * published by the Free Software Foundation.
17 * Serial driver for TX3927/TX4927/TX4925/TX4938 internal SIO controller
20 * 0.30 Initial revision. (Renamed from serial_txx927.c)
21 * 0.31 Use save_flags instead of local_irq_save.
23 * 0.33 Switch TXX9_TTY_NAME by CONFIG_SERIAL_TXX9_STDSERIAL.
24 * Support TIOCSERGETLSR.
25 * 0.34 Support slow baudrate.
26 * 0.40 Merge codes from mainstream kernel (2.4.22).
27 * 0.41 Fix console checking in rs_shutdown_port().
28 * Disable flow-control in serial_console_write().
29 * 0.42 Fix minor compiler warning.
30 * 1.00 Kernel 2.6. Converted to new serial core (based on 8250.c).
31 * 1.01 Set fifosize to make tx_empry called properly.
32 * Use standard uart_get_divisor.
33 * 1.02 Cleanup. (import 8250.c changes)
34 * 1.03 Fix low-latency mode. (import 8250.c changes)
35 * 1.04 Remove usage of deprecated functions, cleanup.
36 * 1.05 More strict check in verify_port. Cleanup.
37 * 1.06 Do not insert a char caused previous overrun.
38 * Fix some spin_locks.
39 * Do not call uart_add_one_port for absent ports.
40 * 1.07 Use CONFIG_SERIAL_TXX9_NR_UARTS. Cleanup.
41 * 1.08 Use platform_device.
42 * Fix and cleanup suspend/resume/initialization codes.
45 #if defined(CONFIG_SERIAL_TXX9_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ)
49 #include <linux/module.h>
50 #include <linux/ioport.h>
51 #include <linux/init.h>
52 #include <linux/console.h>
53 #include <linux/sysrq.h>
54 #include <linux/delay.h>
55 #include <linux/platform_device.h>
56 #include <linux/pci.h>
57 #include <linux/tty.h>
58 #include <linux/tty_flip.h>
59 #include <linux/serial_core.h>
60 #include <linux/serial.h>
61 #include <linux/mutex.h>
65 static char *serial_version
= "1.08";
66 static char *serial_name
= "TX39/49 Serial driver";
68 #define PASS_LIMIT 256
70 #if !defined(CONFIG_SERIAL_TXX9_STDSERIAL)
71 /* "ttyS" is used for standard serial driver */
72 #define TXX9_TTY_NAME "ttyTX"
73 #define TXX9_TTY_MINOR_START (64 + 64) /* ttyTX0(128), ttyTX1(129) */
75 /* acts like standard serial driver */
76 #define TXX9_TTY_NAME "ttyS"
77 #define TXX9_TTY_MINOR_START 64
79 #define TXX9_TTY_MAJOR TTY_MAJOR
82 #define UPF_TXX9_HAVE_CTS_LINE UPF_BUGGY_UART
83 #define UPF_TXX9_USE_SCLK UPF_MAGIC_MULTIPLIER
86 /* support for Toshiba TC86C001 SIO */
87 #define ENABLE_SERIAL_TXX9_PCI
91 * Number of serial ports
93 #define UART_NR CONFIG_SERIAL_TXX9_NR_UARTS
95 #define HIGH_BITS_OFFSET ((sizeof(long)-sizeof(int))*8)
97 struct uart_txx9_port
{
98 struct uart_port port
;
99 /* No additional info for now */
102 #define TXX9_REGION_SIZE 0x24
104 /* TXX9 Serial Registers */
105 #define TXX9_SILCR 0x00
106 #define TXX9_SIDICR 0x04
107 #define TXX9_SIDISR 0x08
108 #define TXX9_SICISR 0x0c
109 #define TXX9_SIFCR 0x10
110 #define TXX9_SIFLCR 0x14
111 #define TXX9_SIBGR 0x18
112 #define TXX9_SITFIFO 0x1c
113 #define TXX9_SIRFIFO 0x20
115 /* SILCR : Line Control */
116 #define TXX9_SILCR_SCS_MASK 0x00000060
117 #define TXX9_SILCR_SCS_IMCLK 0x00000000
118 #define TXX9_SILCR_SCS_IMCLK_BG 0x00000020
119 #define TXX9_SILCR_SCS_SCLK 0x00000040
120 #define TXX9_SILCR_SCS_SCLK_BG 0x00000060
121 #define TXX9_SILCR_UEPS 0x00000010
122 #define TXX9_SILCR_UPEN 0x00000008
123 #define TXX9_SILCR_USBL_MASK 0x00000004
124 #define TXX9_SILCR_USBL_1BIT 0x00000000
125 #define TXX9_SILCR_USBL_2BIT 0x00000004
126 #define TXX9_SILCR_UMODE_MASK 0x00000003
127 #define TXX9_SILCR_UMODE_8BIT 0x00000000
128 #define TXX9_SILCR_UMODE_7BIT 0x00000001
130 /* SIDICR : DMA/Int. Control */
131 #define TXX9_SIDICR_TDE 0x00008000
132 #define TXX9_SIDICR_RDE 0x00004000
133 #define TXX9_SIDICR_TIE 0x00002000
134 #define TXX9_SIDICR_RIE 0x00001000
135 #define TXX9_SIDICR_SPIE 0x00000800
136 #define TXX9_SIDICR_CTSAC 0x00000600
137 #define TXX9_SIDICR_STIE_MASK 0x0000003f
138 #define TXX9_SIDICR_STIE_OERS 0x00000020
139 #define TXX9_SIDICR_STIE_CTSS 0x00000010
140 #define TXX9_SIDICR_STIE_RBRKD 0x00000008
141 #define TXX9_SIDICR_STIE_TRDY 0x00000004
142 #define TXX9_SIDICR_STIE_TXALS 0x00000002
143 #define TXX9_SIDICR_STIE_UBRKD 0x00000001
145 /* SIDISR : DMA/Int. Status */
146 #define TXX9_SIDISR_UBRK 0x00008000
147 #define TXX9_SIDISR_UVALID 0x00004000
148 #define TXX9_SIDISR_UFER 0x00002000
149 #define TXX9_SIDISR_UPER 0x00001000
150 #define TXX9_SIDISR_UOER 0x00000800
151 #define TXX9_SIDISR_ERI 0x00000400
152 #define TXX9_SIDISR_TOUT 0x00000200
153 #define TXX9_SIDISR_TDIS 0x00000100
154 #define TXX9_SIDISR_RDIS 0x00000080
155 #define TXX9_SIDISR_STIS 0x00000040
156 #define TXX9_SIDISR_RFDN_MASK 0x0000001f
158 /* SICISR : Change Int. Status */
159 #define TXX9_SICISR_OERS 0x00000020
160 #define TXX9_SICISR_CTSS 0x00000010
161 #define TXX9_SICISR_RBRKD 0x00000008
162 #define TXX9_SICISR_TRDY 0x00000004
163 #define TXX9_SICISR_TXALS 0x00000002
164 #define TXX9_SICISR_UBRKD 0x00000001
166 /* SIFCR : FIFO Control */
167 #define TXX9_SIFCR_SWRST 0x00008000
168 #define TXX9_SIFCR_RDIL_MASK 0x00000180
169 #define TXX9_SIFCR_RDIL_1 0x00000000
170 #define TXX9_SIFCR_RDIL_4 0x00000080
171 #define TXX9_SIFCR_RDIL_8 0x00000100
172 #define TXX9_SIFCR_RDIL_12 0x00000180
173 #define TXX9_SIFCR_RDIL_MAX 0x00000180
174 #define TXX9_SIFCR_TDIL_MASK 0x00000018
175 #define TXX9_SIFCR_TDIL_MASK 0x00000018
176 #define TXX9_SIFCR_TDIL_1 0x00000000
177 #define TXX9_SIFCR_TDIL_4 0x00000001
178 #define TXX9_SIFCR_TDIL_8 0x00000010
179 #define TXX9_SIFCR_TDIL_MAX 0x00000010
180 #define TXX9_SIFCR_TFRST 0x00000004
181 #define TXX9_SIFCR_RFRST 0x00000002
182 #define TXX9_SIFCR_FRSTE 0x00000001
183 #define TXX9_SIO_TX_FIFO 8
184 #define TXX9_SIO_RX_FIFO 16
186 /* SIFLCR : Flow Control */
187 #define TXX9_SIFLCR_RCS 0x00001000
188 #define TXX9_SIFLCR_TES 0x00000800
189 #define TXX9_SIFLCR_RTSSC 0x00000200
190 #define TXX9_SIFLCR_RSDE 0x00000100
191 #define TXX9_SIFLCR_TSDE 0x00000080
192 #define TXX9_SIFLCR_RTSTL_MASK 0x0000001e
193 #define TXX9_SIFLCR_RTSTL_MAX 0x0000001e
194 #define TXX9_SIFLCR_TBRK 0x00000001
196 /* SIBGR : Baudrate Control */
197 #define TXX9_SIBGR_BCLK_MASK 0x00000300
198 #define TXX9_SIBGR_BCLK_T0 0x00000000
199 #define TXX9_SIBGR_BCLK_T2 0x00000100
200 #define TXX9_SIBGR_BCLK_T4 0x00000200
201 #define TXX9_SIBGR_BCLK_T6 0x00000300
202 #define TXX9_SIBGR_BRD_MASK 0x000000ff
204 static inline unsigned int sio_in(struct uart_txx9_port
*up
, int offset
)
206 switch (up
->port
.iotype
) {
208 return __raw_readl(up
->port
.membase
+ offset
);
210 return inl(up
->port
.iobase
+ offset
);
215 sio_out(struct uart_txx9_port
*up
, int offset
, int value
)
217 switch (up
->port
.iotype
) {
219 __raw_writel(value
, up
->port
.membase
+ offset
);
222 outl(value
, up
->port
.iobase
+ offset
);
228 sio_mask(struct uart_txx9_port
*up
, int offset
, unsigned int value
)
230 sio_out(up
, offset
, sio_in(up
, offset
) & ~value
);
233 sio_set(struct uart_txx9_port
*up
, int offset
, unsigned int value
)
235 sio_out(up
, offset
, sio_in(up
, offset
) | value
);
239 sio_quot_set(struct uart_txx9_port
*up
, int quot
)
243 sio_out(up
, TXX9_SIBGR
, quot
| TXX9_SIBGR_BCLK_T0
);
244 else if (quot
< (256 << 2))
245 sio_out(up
, TXX9_SIBGR
, (quot
>> 2) | TXX9_SIBGR_BCLK_T2
);
246 else if (quot
< (256 << 4))
247 sio_out(up
, TXX9_SIBGR
, (quot
>> 4) | TXX9_SIBGR_BCLK_T4
);
248 else if (quot
< (256 << 6))
249 sio_out(up
, TXX9_SIBGR
, (quot
>> 6) | TXX9_SIBGR_BCLK_T6
);
251 sio_out(up
, TXX9_SIBGR
, 0xff | TXX9_SIBGR_BCLK_T6
);
254 static void serial_txx9_stop_tx(struct uart_port
*port
)
256 struct uart_txx9_port
*up
= (struct uart_txx9_port
*)port
;
257 sio_mask(up
, TXX9_SIDICR
, TXX9_SIDICR_TIE
);
260 static void serial_txx9_start_tx(struct uart_port
*port
)
262 struct uart_txx9_port
*up
= (struct uart_txx9_port
*)port
;
263 sio_set(up
, TXX9_SIDICR
, TXX9_SIDICR_TIE
);
266 static void serial_txx9_stop_rx(struct uart_port
*port
)
268 struct uart_txx9_port
*up
= (struct uart_txx9_port
*)port
;
269 up
->port
.read_status_mask
&= ~TXX9_SIDISR_RDIS
;
272 static void serial_txx9_enable_ms(struct uart_port
*port
)
274 /* TXX9-SIO can not control DTR... */
277 static void serial_txx9_initialize(struct uart_port
*port
)
279 struct uart_txx9_port
*up
= (struct uart_txx9_port
*)port
;
280 unsigned int tmout
= 10000;
282 sio_out(up
, TXX9_SIFCR
, TXX9_SIFCR_SWRST
);
283 /* TX4925 BUG WORKAROUND. Accessing SIOC register
284 * immediately after soft reset causes bus error. */
287 while ((sio_in(up
, TXX9_SIFCR
) & TXX9_SIFCR_SWRST
) && --tmout
)
289 /* TX Int by FIFO Empty, RX Int by Receiving 1 char. */
290 sio_set(up
, TXX9_SIFCR
,
291 TXX9_SIFCR_TDIL_MAX
| TXX9_SIFCR_RDIL_1
);
292 /* initial settings */
293 sio_out(up
, TXX9_SILCR
,
294 TXX9_SILCR_UMODE_8BIT
| TXX9_SILCR_USBL_1BIT
|
295 ((up
->port
.flags
& UPF_TXX9_USE_SCLK
) ?
296 TXX9_SILCR_SCS_SCLK_BG
: TXX9_SILCR_SCS_IMCLK_BG
));
297 sio_quot_set(up
, uart_get_divisor(port
, 9600));
298 sio_out(up
, TXX9_SIFLCR
, TXX9_SIFLCR_RTSTL_MAX
/* 15 */);
299 sio_out(up
, TXX9_SIDICR
, 0);
303 receive_chars(struct uart_txx9_port
*up
, unsigned int *status
)
305 struct tty_struct
*tty
= up
->port
.info
->tty
;
307 unsigned int disr
= *status
;
310 unsigned int next_ignore_status_mask
;
313 ch
= sio_in(up
, TXX9_SIRFIFO
);
315 up
->port
.icount
.rx
++;
317 /* mask out RFDN_MASK bit added by previous overrun */
318 next_ignore_status_mask
=
319 up
->port
.ignore_status_mask
& ~TXX9_SIDISR_RFDN_MASK
;
320 if (unlikely(disr
& (TXX9_SIDISR_UBRK
| TXX9_SIDISR_UPER
|
321 TXX9_SIDISR_UFER
| TXX9_SIDISR_UOER
))) {
323 * For statistics only
325 if (disr
& TXX9_SIDISR_UBRK
) {
326 disr
&= ~(TXX9_SIDISR_UFER
| TXX9_SIDISR_UPER
);
327 up
->port
.icount
.brk
++;
329 * We do the SysRQ and SAK checking
330 * here because otherwise the break
331 * may get masked by ignore_status_mask
332 * or read_status_mask.
334 if (uart_handle_break(&up
->port
))
336 } else if (disr
& TXX9_SIDISR_UPER
)
337 up
->port
.icount
.parity
++;
338 else if (disr
& TXX9_SIDISR_UFER
)
339 up
->port
.icount
.frame
++;
340 if (disr
& TXX9_SIDISR_UOER
) {
341 up
->port
.icount
.overrun
++;
343 * The receiver read buffer still hold
344 * a char which caused overrun.
345 * Ignore next char by adding RFDN_MASK
346 * to ignore_status_mask temporarily.
348 next_ignore_status_mask
|=
349 TXX9_SIDISR_RFDN_MASK
;
353 * Mask off conditions which should be ingored.
355 disr
&= up
->port
.read_status_mask
;
357 if (disr
& TXX9_SIDISR_UBRK
) {
359 } else if (disr
& TXX9_SIDISR_UPER
)
361 else if (disr
& TXX9_SIDISR_UFER
)
364 if (uart_handle_sysrq_char(&up
->port
, ch
))
367 uart_insert_char(&up
->port
, disr
, TXX9_SIDISR_UOER
, ch
, flag
);
370 up
->port
.ignore_status_mask
= next_ignore_status_mask
;
371 disr
= sio_in(up
, TXX9_SIDISR
);
372 } while (!(disr
& TXX9_SIDISR_UVALID
) && (max_count
-- > 0));
373 spin_unlock(&up
->port
.lock
);
374 tty_flip_buffer_push(tty
);
375 spin_lock(&up
->port
.lock
);
379 static inline void transmit_chars(struct uart_txx9_port
*up
)
381 struct circ_buf
*xmit
= &up
->port
.info
->xmit
;
384 if (up
->port
.x_char
) {
385 sio_out(up
, TXX9_SITFIFO
, up
->port
.x_char
);
386 up
->port
.icount
.tx
++;
390 if (uart_circ_empty(xmit
) || uart_tx_stopped(&up
->port
)) {
391 serial_txx9_stop_tx(&up
->port
);
395 count
= TXX9_SIO_TX_FIFO
;
397 sio_out(up
, TXX9_SITFIFO
, xmit
->buf
[xmit
->tail
]);
398 xmit
->tail
= (xmit
->tail
+ 1) & (UART_XMIT_SIZE
- 1);
399 up
->port
.icount
.tx
++;
400 if (uart_circ_empty(xmit
))
402 } while (--count
> 0);
404 if (uart_circ_chars_pending(xmit
) < WAKEUP_CHARS
)
405 uart_write_wakeup(&up
->port
);
407 if (uart_circ_empty(xmit
))
408 serial_txx9_stop_tx(&up
->port
);
411 static irqreturn_t
serial_txx9_interrupt(int irq
, void *dev_id
)
413 int pass_counter
= 0;
414 struct uart_txx9_port
*up
= dev_id
;
418 spin_lock(&up
->port
.lock
);
419 status
= sio_in(up
, TXX9_SIDISR
);
420 if (!(sio_in(up
, TXX9_SIDICR
) & TXX9_SIDICR_TIE
))
421 status
&= ~TXX9_SIDISR_TDIS
;
422 if (!(status
& (TXX9_SIDISR_TDIS
| TXX9_SIDISR_RDIS
|
423 TXX9_SIDISR_TOUT
))) {
424 spin_unlock(&up
->port
.lock
);
428 if (status
& TXX9_SIDISR_RDIS
)
429 receive_chars(up
, &status
);
430 if (status
& TXX9_SIDISR_TDIS
)
432 /* Clear TX/RX Int. Status */
433 sio_mask(up
, TXX9_SIDISR
,
434 TXX9_SIDISR_TDIS
| TXX9_SIDISR_RDIS
|
436 spin_unlock(&up
->port
.lock
);
438 if (pass_counter
++ > PASS_LIMIT
)
442 return pass_counter
? IRQ_HANDLED
: IRQ_NONE
;
445 static unsigned int serial_txx9_tx_empty(struct uart_port
*port
)
447 struct uart_txx9_port
*up
= (struct uart_txx9_port
*)port
;
451 spin_lock_irqsave(&up
->port
.lock
, flags
);
452 ret
= (sio_in(up
, TXX9_SICISR
) & TXX9_SICISR_TXALS
) ? TIOCSER_TEMT
: 0;
453 spin_unlock_irqrestore(&up
->port
.lock
, flags
);
458 static unsigned int serial_txx9_get_mctrl(struct uart_port
*port
)
460 struct uart_txx9_port
*up
= (struct uart_txx9_port
*)port
;
463 ret
= ((sio_in(up
, TXX9_SIFLCR
) & TXX9_SIFLCR_RTSSC
) ? 0 : TIOCM_RTS
)
464 | ((sio_in(up
, TXX9_SICISR
) & TXX9_SICISR_CTSS
) ? 0 : TIOCM_CTS
);
469 static void serial_txx9_set_mctrl(struct uart_port
*port
, unsigned int mctrl
)
471 struct uart_txx9_port
*up
= (struct uart_txx9_port
*)port
;
473 if (mctrl
& TIOCM_RTS
)
474 sio_mask(up
, TXX9_SIFLCR
, TXX9_SIFLCR_RTSSC
);
476 sio_set(up
, TXX9_SIFLCR
, TXX9_SIFLCR_RTSSC
);
479 static void serial_txx9_break_ctl(struct uart_port
*port
, int break_state
)
481 struct uart_txx9_port
*up
= (struct uart_txx9_port
*)port
;
484 spin_lock_irqsave(&up
->port
.lock
, flags
);
485 if (break_state
== -1)
486 sio_set(up
, TXX9_SIFLCR
, TXX9_SIFLCR_TBRK
);
488 sio_mask(up
, TXX9_SIFLCR
, TXX9_SIFLCR_TBRK
);
489 spin_unlock_irqrestore(&up
->port
.lock
, flags
);
492 static int serial_txx9_startup(struct uart_port
*port
)
494 struct uart_txx9_port
*up
= (struct uart_txx9_port
*)port
;
499 * Clear the FIFO buffers and disable them.
500 * (they will be reenabled in set_termios())
502 sio_set(up
, TXX9_SIFCR
,
503 TXX9_SIFCR_TFRST
| TXX9_SIFCR_RFRST
| TXX9_SIFCR_FRSTE
);
505 sio_mask(up
, TXX9_SIFCR
,
506 TXX9_SIFCR_TFRST
| TXX9_SIFCR_RFRST
| TXX9_SIFCR_FRSTE
);
507 sio_out(up
, TXX9_SIDICR
, 0);
510 * Clear the interrupt registers.
512 sio_out(up
, TXX9_SIDISR
, 0);
514 retval
= request_irq(up
->port
.irq
, serial_txx9_interrupt
,
515 IRQF_SHARED
, "serial_txx9", up
);
520 * Now, initialize the UART
522 spin_lock_irqsave(&up
->port
.lock
, flags
);
523 serial_txx9_set_mctrl(&up
->port
, up
->port
.mctrl
);
524 spin_unlock_irqrestore(&up
->port
.lock
, flags
);
527 sio_mask(up
, TXX9_SIFLCR
, TXX9_SIFLCR_RSDE
| TXX9_SIFLCR_TSDE
);
530 * Finally, enable interrupts.
532 sio_set(up
, TXX9_SIDICR
, TXX9_SIDICR_RIE
);
537 static void serial_txx9_shutdown(struct uart_port
*port
)
539 struct uart_txx9_port
*up
= (struct uart_txx9_port
*)port
;
543 * Disable interrupts from this port
545 sio_out(up
, TXX9_SIDICR
, 0); /* disable all intrs */
547 spin_lock_irqsave(&up
->port
.lock
, flags
);
548 serial_txx9_set_mctrl(&up
->port
, up
->port
.mctrl
);
549 spin_unlock_irqrestore(&up
->port
.lock
, flags
);
552 * Disable break condition
554 sio_mask(up
, TXX9_SIFLCR
, TXX9_SIFLCR_TBRK
);
556 #ifdef CONFIG_SERIAL_TXX9_CONSOLE
557 if (up
->port
.cons
&& up
->port
.line
== up
->port
.cons
->index
) {
558 free_irq(up
->port
.irq
, up
);
563 sio_set(up
, TXX9_SIFCR
,
564 TXX9_SIFCR_TFRST
| TXX9_SIFCR_RFRST
| TXX9_SIFCR_FRSTE
);
566 sio_mask(up
, TXX9_SIFCR
,
567 TXX9_SIFCR_TFRST
| TXX9_SIFCR_RFRST
| TXX9_SIFCR_FRSTE
);
570 sio_set(up
, TXX9_SIFLCR
, TXX9_SIFLCR_RSDE
| TXX9_SIFLCR_TSDE
);
572 free_irq(up
->port
.irq
, up
);
576 serial_txx9_set_termios(struct uart_port
*port
, struct ktermios
*termios
,
577 struct ktermios
*old
)
579 struct uart_txx9_port
*up
= (struct uart_txx9_port
*)port
;
580 unsigned int cval
, fcr
= 0;
582 unsigned int baud
, quot
;
584 cval
= sio_in(up
, TXX9_SILCR
);
585 /* byte size and parity */
586 cval
&= ~TXX9_SILCR_UMODE_MASK
;
587 switch (termios
->c_cflag
& CSIZE
) {
589 cval
|= TXX9_SILCR_UMODE_7BIT
;
592 case CS5
: /* not supported */
593 case CS6
: /* not supported */
595 cval
|= TXX9_SILCR_UMODE_8BIT
;
599 cval
&= ~TXX9_SILCR_USBL_MASK
;
600 if (termios
->c_cflag
& CSTOPB
)
601 cval
|= TXX9_SILCR_USBL_2BIT
;
603 cval
|= TXX9_SILCR_USBL_1BIT
;
604 cval
&= ~(TXX9_SILCR_UPEN
| TXX9_SILCR_UEPS
);
605 if (termios
->c_cflag
& PARENB
)
606 cval
|= TXX9_SILCR_UPEN
;
607 if (!(termios
->c_cflag
& PARODD
))
608 cval
|= TXX9_SILCR_UEPS
;
611 * Ask the core to calculate the divisor for us.
613 baud
= uart_get_baud_rate(port
, termios
, old
, 0, port
->uartclk
/16/2);
614 quot
= uart_get_divisor(port
, baud
);
617 /* TX Int by FIFO Empty, RX Int by Receiving 1 char. */
618 fcr
= TXX9_SIFCR_TDIL_MAX
| TXX9_SIFCR_RDIL_1
;
621 * Ok, we're now changing the port state. Do it with
622 * interrupts disabled.
624 spin_lock_irqsave(&up
->port
.lock
, flags
);
627 * Update the per-port timeout.
629 uart_update_timeout(port
, termios
->c_cflag
, baud
);
631 up
->port
.read_status_mask
= TXX9_SIDISR_UOER
|
632 TXX9_SIDISR_TDIS
| TXX9_SIDISR_RDIS
;
633 if (termios
->c_iflag
& INPCK
)
634 up
->port
.read_status_mask
|= TXX9_SIDISR_UFER
| TXX9_SIDISR_UPER
;
635 if (termios
->c_iflag
& (BRKINT
| PARMRK
))
636 up
->port
.read_status_mask
|= TXX9_SIDISR_UBRK
;
639 * Characteres to ignore
641 up
->port
.ignore_status_mask
= 0;
642 if (termios
->c_iflag
& IGNPAR
)
643 up
->port
.ignore_status_mask
|= TXX9_SIDISR_UPER
| TXX9_SIDISR_UFER
;
644 if (termios
->c_iflag
& IGNBRK
) {
645 up
->port
.ignore_status_mask
|= TXX9_SIDISR_UBRK
;
647 * If we're ignoring parity and break indicators,
648 * ignore overruns too (for real raw support).
650 if (termios
->c_iflag
& IGNPAR
)
651 up
->port
.ignore_status_mask
|= TXX9_SIDISR_UOER
;
655 * ignore all characters if CREAD is not set
657 if ((termios
->c_cflag
& CREAD
) == 0)
658 up
->port
.ignore_status_mask
|= TXX9_SIDISR_RDIS
;
660 /* CTS flow control flag */
661 if ((termios
->c_cflag
& CRTSCTS
) &&
662 (up
->port
.flags
& UPF_TXX9_HAVE_CTS_LINE
)) {
663 sio_set(up
, TXX9_SIFLCR
,
664 TXX9_SIFLCR_RCS
| TXX9_SIFLCR_TES
);
666 sio_mask(up
, TXX9_SIFLCR
,
667 TXX9_SIFLCR_RCS
| TXX9_SIFLCR_TES
);
670 sio_out(up
, TXX9_SILCR
, cval
);
671 sio_quot_set(up
, quot
);
672 sio_out(up
, TXX9_SIFCR
, fcr
);
674 serial_txx9_set_mctrl(&up
->port
, up
->port
.mctrl
);
675 spin_unlock_irqrestore(&up
->port
.lock
, flags
);
679 serial_txx9_pm(struct uart_port
*port
, unsigned int state
,
680 unsigned int oldstate
)
683 serial_txx9_initialize(port
);
686 static int serial_txx9_request_resource(struct uart_txx9_port
*up
)
688 unsigned int size
= TXX9_REGION_SIZE
;
691 switch (up
->port
.iotype
) {
693 if (!up
->port
.mapbase
)
696 if (!request_mem_region(up
->port
.mapbase
, size
, "serial_txx9")) {
701 if (up
->port
.flags
& UPF_IOREMAP
) {
702 up
->port
.membase
= ioremap(up
->port
.mapbase
, size
);
703 if (!up
->port
.membase
) {
704 release_mem_region(up
->port
.mapbase
, size
);
711 if (!request_region(up
->port
.iobase
, size
, "serial_txx9"))
718 static void serial_txx9_release_resource(struct uart_txx9_port
*up
)
720 unsigned int size
= TXX9_REGION_SIZE
;
722 switch (up
->port
.iotype
) {
724 if (!up
->port
.mapbase
)
727 if (up
->port
.flags
& UPF_IOREMAP
) {
728 iounmap(up
->port
.membase
);
729 up
->port
.membase
= NULL
;
732 release_mem_region(up
->port
.mapbase
, size
);
736 release_region(up
->port
.iobase
, size
);
741 static void serial_txx9_release_port(struct uart_port
*port
)
743 struct uart_txx9_port
*up
= (struct uart_txx9_port
*)port
;
744 serial_txx9_release_resource(up
);
747 static int serial_txx9_request_port(struct uart_port
*port
)
749 struct uart_txx9_port
*up
= (struct uart_txx9_port
*)port
;
750 return serial_txx9_request_resource(up
);
753 static void serial_txx9_config_port(struct uart_port
*port
, int uflags
)
755 struct uart_txx9_port
*up
= (struct uart_txx9_port
*)port
;
759 * Find the region that we can probe for. This in turn
760 * tells us whether we can probe for the type of port.
762 ret
= serial_txx9_request_resource(up
);
765 port
->type
= PORT_TXX9
;
766 up
->port
.fifosize
= TXX9_SIO_TX_FIFO
;
768 #ifdef CONFIG_SERIAL_TXX9_CONSOLE
769 if (up
->port
.line
== up
->port
.cons
->index
)
772 serial_txx9_initialize(port
);
776 serial_txx9_verify_port(struct uart_port
*port
, struct serial_struct
*ser
)
778 unsigned long new_port
= ser
->port
;
779 if (HIGH_BITS_OFFSET
)
780 new_port
+= (unsigned long)ser
->port_high
<< HIGH_BITS_OFFSET
;
781 if (ser
->type
!= port
->type
||
782 ser
->irq
!= port
->irq
||
783 ser
->io_type
!= port
->iotype
||
784 new_port
!= port
->iobase
||
785 (unsigned long)ser
->iomem_base
!= port
->mapbase
)
791 serial_txx9_type(struct uart_port
*port
)
796 static struct uart_ops serial_txx9_pops
= {
797 .tx_empty
= serial_txx9_tx_empty
,
798 .set_mctrl
= serial_txx9_set_mctrl
,
799 .get_mctrl
= serial_txx9_get_mctrl
,
800 .stop_tx
= serial_txx9_stop_tx
,
801 .start_tx
= serial_txx9_start_tx
,
802 .stop_rx
= serial_txx9_stop_rx
,
803 .enable_ms
= serial_txx9_enable_ms
,
804 .break_ctl
= serial_txx9_break_ctl
,
805 .startup
= serial_txx9_startup
,
806 .shutdown
= serial_txx9_shutdown
,
807 .set_termios
= serial_txx9_set_termios
,
808 .pm
= serial_txx9_pm
,
809 .type
= serial_txx9_type
,
810 .release_port
= serial_txx9_release_port
,
811 .request_port
= serial_txx9_request_port
,
812 .config_port
= serial_txx9_config_port
,
813 .verify_port
= serial_txx9_verify_port
,
816 static struct uart_txx9_port serial_txx9_ports
[UART_NR
];
818 static void __init
serial_txx9_register_ports(struct uart_driver
*drv
,
823 for (i
= 0; i
< UART_NR
; i
++) {
824 struct uart_txx9_port
*up
= &serial_txx9_ports
[i
];
827 up
->port
.ops
= &serial_txx9_pops
;
829 if (up
->port
.iobase
|| up
->port
.mapbase
)
830 uart_add_one_port(drv
, &up
->port
);
834 #ifdef CONFIG_SERIAL_TXX9_CONSOLE
837 * Wait for transmitter & holding register to empty
839 static inline void wait_for_xmitr(struct uart_txx9_port
*up
)
841 unsigned int tmout
= 10000;
843 /* Wait up to 10ms for the character(s) to be sent. */
845 !(sio_in(up
, TXX9_SICISR
) & TXX9_SICISR_TXALS
))
848 /* Wait up to 1s for flow control if necessary */
849 if (up
->port
.flags
& UPF_CONS_FLOW
) {
852 (sio_in(up
, TXX9_SICISR
) & TXX9_SICISR_CTSS
))
857 static void serial_txx9_console_putchar(struct uart_port
*port
, int ch
)
859 struct uart_txx9_port
*up
= (struct uart_txx9_port
*)port
;
862 sio_out(up
, TXX9_SITFIFO
, ch
);
866 * Print a string to the serial port trying not to disturb
867 * any possible real use of the port...
869 * The console_lock must be held when we get here.
872 serial_txx9_console_write(struct console
*co
, const char *s
, unsigned int count
)
874 struct uart_txx9_port
*up
= &serial_txx9_ports
[co
->index
];
875 unsigned int ier
, flcr
;
878 * First save the UER then disable the interrupts
880 ier
= sio_in(up
, TXX9_SIDICR
);
881 sio_out(up
, TXX9_SIDICR
, 0);
883 * Disable flow-control if enabled (and unnecessary)
885 flcr
= sio_in(up
, TXX9_SIFLCR
);
886 if (!(up
->port
.flags
& UPF_CONS_FLOW
) && (flcr
& TXX9_SIFLCR_TES
))
887 sio_out(up
, TXX9_SIFLCR
, flcr
& ~TXX9_SIFLCR_TES
);
889 uart_console_write(&up
->port
, s
, count
, serial_txx9_console_putchar
);
892 * Finally, wait for transmitter to become empty
893 * and restore the IER
896 sio_out(up
, TXX9_SIFLCR
, flcr
);
897 sio_out(up
, TXX9_SIDICR
, ier
);
900 static int __init
serial_txx9_console_setup(struct console
*co
, char *options
)
902 struct uart_port
*port
;
903 struct uart_txx9_port
*up
;
910 * Check whether an invalid uart number has been specified, and
911 * if so, search for the first available port that does have
914 if (co
->index
>= UART_NR
)
916 up
= &serial_txx9_ports
[co
->index
];
921 serial_txx9_initialize(&up
->port
);
924 uart_parse_options(options
, &baud
, &parity
, &bits
, &flow
);
926 return uart_set_options(port
, co
, baud
, parity
, bits
, flow
);
929 static struct uart_driver serial_txx9_reg
;
930 static struct console serial_txx9_console
= {
931 .name
= TXX9_TTY_NAME
,
932 .write
= serial_txx9_console_write
,
933 .device
= uart_console_device
,
934 .setup
= serial_txx9_console_setup
,
935 .flags
= CON_PRINTBUFFER
,
937 .data
= &serial_txx9_reg
,
940 static int __init
serial_txx9_console_init(void)
942 register_console(&serial_txx9_console
);
945 console_initcall(serial_txx9_console_init
);
947 #define SERIAL_TXX9_CONSOLE &serial_txx9_console
949 #define SERIAL_TXX9_CONSOLE NULL
952 static struct uart_driver serial_txx9_reg
= {
953 .owner
= THIS_MODULE
,
954 .driver_name
= "serial_txx9",
955 .dev_name
= TXX9_TTY_NAME
,
956 .major
= TXX9_TTY_MAJOR
,
957 .minor
= TXX9_TTY_MINOR_START
,
959 .cons
= SERIAL_TXX9_CONSOLE
,
962 int __init
early_serial_txx9_setup(struct uart_port
*port
)
964 if (port
->line
>= ARRAY_SIZE(serial_txx9_ports
))
967 serial_txx9_ports
[port
->line
].port
= *port
;
968 serial_txx9_ports
[port
->line
].port
.ops
= &serial_txx9_pops
;
969 serial_txx9_ports
[port
->line
].port
.flags
|= UPF_BOOT_AUTOCONF
;
973 static DEFINE_MUTEX(serial_txx9_mutex
);
976 * serial_txx9_register_port - register a serial port
977 * @port: serial port template
979 * Configure the serial port specified by the request.
981 * The port is then probed and if necessary the IRQ is autodetected
982 * If this fails an error is returned.
984 * On success the port is ready to use and the line number is returned.
986 static int __devinit
serial_txx9_register_port(struct uart_port
*port
)
989 struct uart_txx9_port
*uart
;
992 mutex_lock(&serial_txx9_mutex
);
993 for (i
= 0; i
< UART_NR
; i
++) {
994 uart
= &serial_txx9_ports
[i
];
995 if (uart_match_port(&uart
->port
, port
)) {
996 uart_remove_one_port(&serial_txx9_reg
, &uart
->port
);
1001 /* Find unused port */
1002 for (i
= 0; i
< UART_NR
; i
++) {
1003 uart
= &serial_txx9_ports
[i
];
1004 if (!(uart
->port
.iobase
|| uart
->port
.mapbase
))
1009 uart
->port
.iobase
= port
->iobase
;
1010 uart
->port
.membase
= port
->membase
;
1011 uart
->port
.irq
= port
->irq
;
1012 uart
->port
.uartclk
= port
->uartclk
;
1013 uart
->port
.iotype
= port
->iotype
;
1014 uart
->port
.flags
= port
->flags
| UPF_BOOT_AUTOCONF
;
1015 uart
->port
.mapbase
= port
->mapbase
;
1017 uart
->port
.dev
= port
->dev
;
1018 ret
= uart_add_one_port(&serial_txx9_reg
, &uart
->port
);
1020 ret
= uart
->port
.line
;
1022 mutex_unlock(&serial_txx9_mutex
);
1027 * serial_txx9_unregister_port - remove a txx9 serial port at runtime
1028 * @line: serial line number
1030 * Remove one serial port. This may not be called from interrupt
1031 * context. We hand the port back to the our control.
1033 static void __devexit
serial_txx9_unregister_port(int line
)
1035 struct uart_txx9_port
*uart
= &serial_txx9_ports
[line
];
1037 mutex_lock(&serial_txx9_mutex
);
1038 uart_remove_one_port(&serial_txx9_reg
, &uart
->port
);
1039 uart
->port
.flags
= 0;
1040 uart
->port
.type
= PORT_UNKNOWN
;
1041 uart
->port
.iobase
= 0;
1042 uart
->port
.mapbase
= 0;
1043 uart
->port
.membase
= NULL
;
1044 uart
->port
.dev
= NULL
;
1045 mutex_unlock(&serial_txx9_mutex
);
1049 * Register a set of serial devices attached to a platform device.
1051 static int __devinit
serial_txx9_probe(struct platform_device
*dev
)
1053 struct uart_port
*p
= dev
->dev
.platform_data
;
1054 struct uart_port port
;
1057 memset(&port
, 0, sizeof(struct uart_port
));
1058 for (i
= 0; p
&& p
->uartclk
!= 0; p
++, i
++) {
1059 port
.iobase
= p
->iobase
;
1060 port
.membase
= p
->membase
;
1062 port
.uartclk
= p
->uartclk
;
1063 port
.iotype
= p
->iotype
;
1064 port
.flags
= p
->flags
;
1065 port
.mapbase
= p
->mapbase
;
1066 port
.dev
= &dev
->dev
;
1067 ret
= serial_txx9_register_port(&port
);
1069 dev_err(&dev
->dev
, "unable to register port at index %d "
1070 "(IO%x MEM%lx IRQ%d): %d\n", i
,
1071 p
->iobase
, p
->mapbase
, p
->irq
, ret
);
1078 * Remove serial ports registered against a platform device.
1080 static int __devexit
serial_txx9_remove(struct platform_device
*dev
)
1084 for (i
= 0; i
< UART_NR
; i
++) {
1085 struct uart_txx9_port
*up
= &serial_txx9_ports
[i
];
1087 if (up
->port
.dev
== &dev
->dev
)
1088 serial_txx9_unregister_port(i
);
1094 static int serial_txx9_suspend(struct platform_device
*dev
, pm_message_t state
)
1098 for (i
= 0; i
< UART_NR
; i
++) {
1099 struct uart_txx9_port
*up
= &serial_txx9_ports
[i
];
1101 if (up
->port
.type
!= PORT_UNKNOWN
&& up
->port
.dev
== &dev
->dev
)
1102 uart_suspend_port(&serial_txx9_reg
, &up
->port
);
1108 static int serial_txx9_resume(struct platform_device
*dev
)
1112 for (i
= 0; i
< UART_NR
; i
++) {
1113 struct uart_txx9_port
*up
= &serial_txx9_ports
[i
];
1115 if (up
->port
.type
!= PORT_UNKNOWN
&& up
->port
.dev
== &dev
->dev
)
1116 uart_resume_port(&serial_txx9_reg
, &up
->port
);
1123 static struct platform_driver serial_txx9_plat_driver
= {
1124 .probe
= serial_txx9_probe
,
1125 .remove
= __devexit_p(serial_txx9_remove
),
1127 .suspend
= serial_txx9_suspend
,
1128 .resume
= serial_txx9_resume
,
1131 .name
= "serial_txx9",
1132 .owner
= THIS_MODULE
,
1136 #ifdef ENABLE_SERIAL_TXX9_PCI
1138 * Probe one serial board. Unfortunately, there is no rhyme nor reason
1139 * to the arrangement of serial ports on a PCI card.
1141 static int __devinit
1142 pciserial_txx9_init_one(struct pci_dev
*dev
, const struct pci_device_id
*ent
)
1144 struct uart_port port
;
1148 rc
= pci_enable_device(dev
);
1152 memset(&port
, 0, sizeof(port
));
1153 port
.ops
= &serial_txx9_pops
;
1154 port
.flags
|= UPF_TXX9_HAVE_CTS_LINE
;
1155 port
.uartclk
= 66670000;
1156 port
.irq
= dev
->irq
;
1157 port
.iotype
= UPIO_PORT
;
1158 port
.iobase
= pci_resource_start(dev
, 1);
1159 port
.dev
= &dev
->dev
;
1160 line
= serial_txx9_register_port(&port
);
1162 printk(KERN_WARNING
"Couldn't register serial port %s: %d\n", pci_name(dev
), line
);
1163 pci_disable_device(dev
);
1166 pci_set_drvdata(dev
, &serial_txx9_ports
[line
]);
1171 static void __devexit
pciserial_txx9_remove_one(struct pci_dev
*dev
)
1173 struct uart_txx9_port
*up
= pci_get_drvdata(dev
);
1175 pci_set_drvdata(dev
, NULL
);
1178 serial_txx9_unregister_port(up
->port
.line
);
1179 pci_disable_device(dev
);
1184 static int pciserial_txx9_suspend_one(struct pci_dev
*dev
, pm_message_t state
)
1186 struct uart_txx9_port
*up
= pci_get_drvdata(dev
);
1189 uart_suspend_port(&serial_txx9_reg
, &up
->port
);
1190 pci_save_state(dev
);
1191 pci_set_power_state(dev
, pci_choose_state(dev
, state
));
1195 static int pciserial_txx9_resume_one(struct pci_dev
*dev
)
1197 struct uart_txx9_port
*up
= pci_get_drvdata(dev
);
1199 pci_set_power_state(dev
, PCI_D0
);
1200 pci_restore_state(dev
);
1202 uart_resume_port(&serial_txx9_reg
, &up
->port
);
1207 static const struct pci_device_id serial_txx9_pci_tbl
[] = {
1208 { PCI_DEVICE(PCI_VENDOR_ID_TOSHIBA_2
, PCI_DEVICE_ID_TOSHIBA_TC86C001_MISC
) },
1212 static struct pci_driver serial_txx9_pci_driver
= {
1213 .name
= "serial_txx9",
1214 .probe
= pciserial_txx9_init_one
,
1215 .remove
= __devexit_p(pciserial_txx9_remove_one
),
1217 .suspend
= pciserial_txx9_suspend_one
,
1218 .resume
= pciserial_txx9_resume_one
,
1220 .id_table
= serial_txx9_pci_tbl
,
1223 MODULE_DEVICE_TABLE(pci
, serial_txx9_pci_tbl
);
1224 #endif /* ENABLE_SERIAL_TXX9_PCI */
1226 static struct platform_device
*serial_txx9_plat_devs
;
1228 static int __init
serial_txx9_init(void)
1232 printk(KERN_INFO
"%s version %s\n", serial_name
, serial_version
);
1234 ret
= uart_register_driver(&serial_txx9_reg
);
1238 serial_txx9_plat_devs
= platform_device_alloc("serial_txx9", -1);
1239 if (!serial_txx9_plat_devs
) {
1241 goto unreg_uart_drv
;
1244 ret
= platform_device_add(serial_txx9_plat_devs
);
1248 serial_txx9_register_ports(&serial_txx9_reg
,
1249 &serial_txx9_plat_devs
->dev
);
1251 ret
= platform_driver_register(&serial_txx9_plat_driver
);
1255 #ifdef ENABLE_SERIAL_TXX9_PCI
1256 ret
= pci_register_driver(&serial_txx9_pci_driver
);
1262 platform_device_del(serial_txx9_plat_devs
);
1264 platform_device_put(serial_txx9_plat_devs
);
1266 uart_unregister_driver(&serial_txx9_reg
);
1271 static void __exit
serial_txx9_exit(void)
1275 #ifdef ENABLE_SERIAL_TXX9_PCI
1276 pci_unregister_driver(&serial_txx9_pci_driver
);
1278 platform_driver_unregister(&serial_txx9_plat_driver
);
1279 platform_device_unregister(serial_txx9_plat_devs
);
1280 for (i
= 0; i
< UART_NR
; i
++) {
1281 struct uart_txx9_port
*up
= &serial_txx9_ports
[i
];
1282 if (up
->port
.iobase
|| up
->port
.mapbase
)
1283 uart_remove_one_port(&serial_txx9_reg
, &up
->port
);
1286 uart_unregister_driver(&serial_txx9_reg
);
1289 module_init(serial_txx9_init
);
1290 module_exit(serial_txx9_exit
);
1292 MODULE_LICENSE("GPL");
1293 MODULE_DESCRIPTION("TX39/49 serial driver");
1295 MODULE_ALIAS_CHARDEV_MAJOR(TXX9_TTY_MAJOR
);