2 * Derived from many drivers using generic_serial interface,
3 * especially serial_tx3912.c by Steven J. Hill and r39xx_serial.c
4 * (was in Linux/VR tree) by Jim Pick.
6 * Copyright (C) 1999 Harald Koerfgen
7 * Copyright (C) 2000 Jim Pick <jim@jimpick.com>
8 * Copyright (C) 2001 Steven J. Hill (sjhill@realitydiluted.com)
9 * Copyright (C) 2000-2002 Toshiba Corporation
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License version 2 as
13 * published by the Free Software Foundation.
15 * Serial driver for TX3927/TX4927/TX4925/TX4938 internal SIO controller
18 #if defined(CONFIG_SERIAL_TXX9_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ)
22 #include <linux/module.h>
23 #include <linux/ioport.h>
24 #include <linux/init.h>
25 #include <linux/console.h>
26 #include <linux/delay.h>
27 #include <linux/platform_device.h>
28 #include <linux/pci.h>
29 #include <linux/serial_core.h>
30 #include <linux/serial.h>
31 #include <linux/tty.h>
32 #include <linux/tty_flip.h>
36 static char *serial_version
= "1.11";
37 static char *serial_name
= "TX39/49 Serial driver";
39 #define PASS_LIMIT 256
41 #if !defined(CONFIG_SERIAL_TXX9_STDSERIAL)
42 /* "ttyS" is used for standard serial driver */
43 #define TXX9_TTY_NAME "ttyTX"
44 #define TXX9_TTY_MINOR_START 196
45 #define TXX9_TTY_MAJOR 204
47 /* acts like standard serial driver */
48 #define TXX9_TTY_NAME "ttyS"
49 #define TXX9_TTY_MINOR_START 64
50 #define TXX9_TTY_MAJOR TTY_MAJOR
54 #define UPF_TXX9_HAVE_CTS_LINE UPF_BUGGY_UART
55 #define UPF_TXX9_USE_SCLK UPF_MAGIC_MULTIPLIER
58 /* support for Toshiba TC86C001 SIO */
59 #define ENABLE_SERIAL_TXX9_PCI
63 * Number of serial ports
65 #define UART_NR CONFIG_SERIAL_TXX9_NR_UARTS
67 struct uart_txx9_port
{
68 struct uart_port port
;
69 /* No additional info for now */
72 #define TXX9_REGION_SIZE 0x24
74 /* TXX9 Serial Registers */
75 #define TXX9_SILCR 0x00
76 #define TXX9_SIDICR 0x04
77 #define TXX9_SIDISR 0x08
78 #define TXX9_SICISR 0x0c
79 #define TXX9_SIFCR 0x10
80 #define TXX9_SIFLCR 0x14
81 #define TXX9_SIBGR 0x18
82 #define TXX9_SITFIFO 0x1c
83 #define TXX9_SIRFIFO 0x20
85 /* SILCR : Line Control */
86 #define TXX9_SILCR_SCS_MASK 0x00000060
87 #define TXX9_SILCR_SCS_IMCLK 0x00000000
88 #define TXX9_SILCR_SCS_IMCLK_BG 0x00000020
89 #define TXX9_SILCR_SCS_SCLK 0x00000040
90 #define TXX9_SILCR_SCS_SCLK_BG 0x00000060
91 #define TXX9_SILCR_UEPS 0x00000010
92 #define TXX9_SILCR_UPEN 0x00000008
93 #define TXX9_SILCR_USBL_MASK 0x00000004
94 #define TXX9_SILCR_USBL_1BIT 0x00000000
95 #define TXX9_SILCR_USBL_2BIT 0x00000004
96 #define TXX9_SILCR_UMODE_MASK 0x00000003
97 #define TXX9_SILCR_UMODE_8BIT 0x00000000
98 #define TXX9_SILCR_UMODE_7BIT 0x00000001
100 /* SIDICR : DMA/Int. Control */
101 #define TXX9_SIDICR_TDE 0x00008000
102 #define TXX9_SIDICR_RDE 0x00004000
103 #define TXX9_SIDICR_TIE 0x00002000
104 #define TXX9_SIDICR_RIE 0x00001000
105 #define TXX9_SIDICR_SPIE 0x00000800
106 #define TXX9_SIDICR_CTSAC 0x00000600
107 #define TXX9_SIDICR_STIE_MASK 0x0000003f
108 #define TXX9_SIDICR_STIE_OERS 0x00000020
109 #define TXX9_SIDICR_STIE_CTSS 0x00000010
110 #define TXX9_SIDICR_STIE_RBRKD 0x00000008
111 #define TXX9_SIDICR_STIE_TRDY 0x00000004
112 #define TXX9_SIDICR_STIE_TXALS 0x00000002
113 #define TXX9_SIDICR_STIE_UBRKD 0x00000001
115 /* SIDISR : DMA/Int. Status */
116 #define TXX9_SIDISR_UBRK 0x00008000
117 #define TXX9_SIDISR_UVALID 0x00004000
118 #define TXX9_SIDISR_UFER 0x00002000
119 #define TXX9_SIDISR_UPER 0x00001000
120 #define TXX9_SIDISR_UOER 0x00000800
121 #define TXX9_SIDISR_ERI 0x00000400
122 #define TXX9_SIDISR_TOUT 0x00000200
123 #define TXX9_SIDISR_TDIS 0x00000100
124 #define TXX9_SIDISR_RDIS 0x00000080
125 #define TXX9_SIDISR_STIS 0x00000040
126 #define TXX9_SIDISR_RFDN_MASK 0x0000001f
128 /* SICISR : Change Int. Status */
129 #define TXX9_SICISR_OERS 0x00000020
130 #define TXX9_SICISR_CTSS 0x00000010
131 #define TXX9_SICISR_RBRKD 0x00000008
132 #define TXX9_SICISR_TRDY 0x00000004
133 #define TXX9_SICISR_TXALS 0x00000002
134 #define TXX9_SICISR_UBRKD 0x00000001
136 /* SIFCR : FIFO Control */
137 #define TXX9_SIFCR_SWRST 0x00008000
138 #define TXX9_SIFCR_RDIL_MASK 0x00000180
139 #define TXX9_SIFCR_RDIL_1 0x00000000
140 #define TXX9_SIFCR_RDIL_4 0x00000080
141 #define TXX9_SIFCR_RDIL_8 0x00000100
142 #define TXX9_SIFCR_RDIL_12 0x00000180
143 #define TXX9_SIFCR_RDIL_MAX 0x00000180
144 #define TXX9_SIFCR_TDIL_MASK 0x00000018
145 #define TXX9_SIFCR_TDIL_MASK 0x00000018
146 #define TXX9_SIFCR_TDIL_1 0x00000000
147 #define TXX9_SIFCR_TDIL_4 0x00000001
148 #define TXX9_SIFCR_TDIL_8 0x00000010
149 #define TXX9_SIFCR_TDIL_MAX 0x00000010
150 #define TXX9_SIFCR_TFRST 0x00000004
151 #define TXX9_SIFCR_RFRST 0x00000002
152 #define TXX9_SIFCR_FRSTE 0x00000001
153 #define TXX9_SIO_TX_FIFO 8
154 #define TXX9_SIO_RX_FIFO 16
156 /* SIFLCR : Flow Control */
157 #define TXX9_SIFLCR_RCS 0x00001000
158 #define TXX9_SIFLCR_TES 0x00000800
159 #define TXX9_SIFLCR_RTSSC 0x00000200
160 #define TXX9_SIFLCR_RSDE 0x00000100
161 #define TXX9_SIFLCR_TSDE 0x00000080
162 #define TXX9_SIFLCR_RTSTL_MASK 0x0000001e
163 #define TXX9_SIFLCR_RTSTL_MAX 0x0000001e
164 #define TXX9_SIFLCR_TBRK 0x00000001
166 /* SIBGR : Baudrate Control */
167 #define TXX9_SIBGR_BCLK_MASK 0x00000300
168 #define TXX9_SIBGR_BCLK_T0 0x00000000
169 #define TXX9_SIBGR_BCLK_T2 0x00000100
170 #define TXX9_SIBGR_BCLK_T4 0x00000200
171 #define TXX9_SIBGR_BCLK_T6 0x00000300
172 #define TXX9_SIBGR_BRD_MASK 0x000000ff
174 static inline unsigned int sio_in(struct uart_txx9_port
*up
, int offset
)
176 switch (up
->port
.iotype
) {
178 return __raw_readl(up
->port
.membase
+ offset
);
180 return inl(up
->port
.iobase
+ offset
);
185 sio_out(struct uart_txx9_port
*up
, int offset
, int value
)
187 switch (up
->port
.iotype
) {
189 __raw_writel(value
, up
->port
.membase
+ offset
);
192 outl(value
, up
->port
.iobase
+ offset
);
198 sio_mask(struct uart_txx9_port
*up
, int offset
, unsigned int value
)
200 sio_out(up
, offset
, sio_in(up
, offset
) & ~value
);
203 sio_set(struct uart_txx9_port
*up
, int offset
, unsigned int value
)
205 sio_out(up
, offset
, sio_in(up
, offset
) | value
);
209 sio_quot_set(struct uart_txx9_port
*up
, int quot
)
213 sio_out(up
, TXX9_SIBGR
, quot
| TXX9_SIBGR_BCLK_T0
);
214 else if (quot
< (256 << 2))
215 sio_out(up
, TXX9_SIBGR
, (quot
>> 2) | TXX9_SIBGR_BCLK_T2
);
216 else if (quot
< (256 << 4))
217 sio_out(up
, TXX9_SIBGR
, (quot
>> 4) | TXX9_SIBGR_BCLK_T4
);
218 else if (quot
< (256 << 6))
219 sio_out(up
, TXX9_SIBGR
, (quot
>> 6) | TXX9_SIBGR_BCLK_T6
);
221 sio_out(up
, TXX9_SIBGR
, 0xff | TXX9_SIBGR_BCLK_T6
);
224 static struct uart_txx9_port
*to_uart_txx9_port(struct uart_port
*port
)
226 return container_of(port
, struct uart_txx9_port
, port
);
229 static void serial_txx9_stop_tx(struct uart_port
*port
)
231 struct uart_txx9_port
*up
= to_uart_txx9_port(port
);
232 sio_mask(up
, TXX9_SIDICR
, TXX9_SIDICR_TIE
);
235 static void serial_txx9_start_tx(struct uart_port
*port
)
237 struct uart_txx9_port
*up
= to_uart_txx9_port(port
);
238 sio_set(up
, TXX9_SIDICR
, TXX9_SIDICR_TIE
);
241 static void serial_txx9_stop_rx(struct uart_port
*port
)
243 struct uart_txx9_port
*up
= to_uart_txx9_port(port
);
244 up
->port
.read_status_mask
&= ~TXX9_SIDISR_RDIS
;
247 static void serial_txx9_enable_ms(struct uart_port
*port
)
249 /* TXX9-SIO can not control DTR... */
252 static void serial_txx9_initialize(struct uart_port
*port
)
254 struct uart_txx9_port
*up
= to_uart_txx9_port(port
);
255 unsigned int tmout
= 10000;
257 sio_out(up
, TXX9_SIFCR
, TXX9_SIFCR_SWRST
);
258 /* TX4925 BUG WORKAROUND. Accessing SIOC register
259 * immediately after soft reset causes bus error. */
262 while ((sio_in(up
, TXX9_SIFCR
) & TXX9_SIFCR_SWRST
) && --tmout
)
264 /* TX Int by FIFO Empty, RX Int by Receiving 1 char. */
265 sio_set(up
, TXX9_SIFCR
,
266 TXX9_SIFCR_TDIL_MAX
| TXX9_SIFCR_RDIL_1
);
267 /* initial settings */
268 sio_out(up
, TXX9_SILCR
,
269 TXX9_SILCR_UMODE_8BIT
| TXX9_SILCR_USBL_1BIT
|
270 ((up
->port
.flags
& UPF_TXX9_USE_SCLK
) ?
271 TXX9_SILCR_SCS_SCLK_BG
: TXX9_SILCR_SCS_IMCLK_BG
));
272 sio_quot_set(up
, uart_get_divisor(port
, 9600));
273 sio_out(up
, TXX9_SIFLCR
, TXX9_SIFLCR_RTSTL_MAX
/* 15 */);
274 sio_out(up
, TXX9_SIDICR
, 0);
278 receive_chars(struct uart_txx9_port
*up
, unsigned int *status
)
281 unsigned int disr
= *status
;
284 unsigned int next_ignore_status_mask
;
287 ch
= sio_in(up
, TXX9_SIRFIFO
);
289 up
->port
.icount
.rx
++;
291 /* mask out RFDN_MASK bit added by previous overrun */
292 next_ignore_status_mask
=
293 up
->port
.ignore_status_mask
& ~TXX9_SIDISR_RFDN_MASK
;
294 if (unlikely(disr
& (TXX9_SIDISR_UBRK
| TXX9_SIDISR_UPER
|
295 TXX9_SIDISR_UFER
| TXX9_SIDISR_UOER
))) {
297 * For statistics only
299 if (disr
& TXX9_SIDISR_UBRK
) {
300 disr
&= ~(TXX9_SIDISR_UFER
| TXX9_SIDISR_UPER
);
301 up
->port
.icount
.brk
++;
303 * We do the SysRQ and SAK checking
304 * here because otherwise the break
305 * may get masked by ignore_status_mask
306 * or read_status_mask.
308 if (uart_handle_break(&up
->port
))
310 } else if (disr
& TXX9_SIDISR_UPER
)
311 up
->port
.icount
.parity
++;
312 else if (disr
& TXX9_SIDISR_UFER
)
313 up
->port
.icount
.frame
++;
314 if (disr
& TXX9_SIDISR_UOER
) {
315 up
->port
.icount
.overrun
++;
317 * The receiver read buffer still hold
318 * a char which caused overrun.
319 * Ignore next char by adding RFDN_MASK
320 * to ignore_status_mask temporarily.
322 next_ignore_status_mask
|=
323 TXX9_SIDISR_RFDN_MASK
;
327 * Mask off conditions which should be ingored.
329 disr
&= up
->port
.read_status_mask
;
331 if (disr
& TXX9_SIDISR_UBRK
) {
333 } else if (disr
& TXX9_SIDISR_UPER
)
335 else if (disr
& TXX9_SIDISR_UFER
)
338 if (uart_handle_sysrq_char(&up
->port
, ch
))
341 uart_insert_char(&up
->port
, disr
, TXX9_SIDISR_UOER
, ch
, flag
);
344 up
->port
.ignore_status_mask
= next_ignore_status_mask
;
345 disr
= sio_in(up
, TXX9_SIDISR
);
346 } while (!(disr
& TXX9_SIDISR_UVALID
) && (max_count
-- > 0));
347 spin_unlock(&up
->port
.lock
);
348 tty_flip_buffer_push(&up
->port
.state
->port
);
349 spin_lock(&up
->port
.lock
);
353 static inline void transmit_chars(struct uart_txx9_port
*up
)
355 struct circ_buf
*xmit
= &up
->port
.state
->xmit
;
358 if (up
->port
.x_char
) {
359 sio_out(up
, TXX9_SITFIFO
, up
->port
.x_char
);
360 up
->port
.icount
.tx
++;
364 if (uart_circ_empty(xmit
) || uart_tx_stopped(&up
->port
)) {
365 serial_txx9_stop_tx(&up
->port
);
369 count
= TXX9_SIO_TX_FIFO
;
371 sio_out(up
, TXX9_SITFIFO
, xmit
->buf
[xmit
->tail
]);
372 xmit
->tail
= (xmit
->tail
+ 1) & (UART_XMIT_SIZE
- 1);
373 up
->port
.icount
.tx
++;
374 if (uart_circ_empty(xmit
))
376 } while (--count
> 0);
378 if (uart_circ_chars_pending(xmit
) < WAKEUP_CHARS
)
379 uart_write_wakeup(&up
->port
);
381 if (uart_circ_empty(xmit
))
382 serial_txx9_stop_tx(&up
->port
);
385 static irqreturn_t
serial_txx9_interrupt(int irq
, void *dev_id
)
387 int pass_counter
= 0;
388 struct uart_txx9_port
*up
= dev_id
;
392 spin_lock(&up
->port
.lock
);
393 status
= sio_in(up
, TXX9_SIDISR
);
394 if (!(sio_in(up
, TXX9_SIDICR
) & TXX9_SIDICR_TIE
))
395 status
&= ~TXX9_SIDISR_TDIS
;
396 if (!(status
& (TXX9_SIDISR_TDIS
| TXX9_SIDISR_RDIS
|
397 TXX9_SIDISR_TOUT
))) {
398 spin_unlock(&up
->port
.lock
);
402 if (status
& TXX9_SIDISR_RDIS
)
403 receive_chars(up
, &status
);
404 if (status
& TXX9_SIDISR_TDIS
)
406 /* Clear TX/RX Int. Status */
407 sio_mask(up
, TXX9_SIDISR
,
408 TXX9_SIDISR_TDIS
| TXX9_SIDISR_RDIS
|
410 spin_unlock(&up
->port
.lock
);
412 if (pass_counter
++ > PASS_LIMIT
)
416 return pass_counter
? IRQ_HANDLED
: IRQ_NONE
;
419 static unsigned int serial_txx9_tx_empty(struct uart_port
*port
)
421 struct uart_txx9_port
*up
= to_uart_txx9_port(port
);
425 spin_lock_irqsave(&up
->port
.lock
, flags
);
426 ret
= (sio_in(up
, TXX9_SICISR
) & TXX9_SICISR_TXALS
) ? TIOCSER_TEMT
: 0;
427 spin_unlock_irqrestore(&up
->port
.lock
, flags
);
432 static unsigned int serial_txx9_get_mctrl(struct uart_port
*port
)
434 struct uart_txx9_port
*up
= to_uart_txx9_port(port
);
437 /* no modem control lines */
438 ret
= TIOCM_CAR
| TIOCM_DSR
;
439 ret
|= (sio_in(up
, TXX9_SIFLCR
) & TXX9_SIFLCR_RTSSC
) ? 0 : TIOCM_RTS
;
440 ret
|= (sio_in(up
, TXX9_SICISR
) & TXX9_SICISR_CTSS
) ? 0 : TIOCM_CTS
;
445 static void serial_txx9_set_mctrl(struct uart_port
*port
, unsigned int mctrl
)
447 struct uart_txx9_port
*up
= to_uart_txx9_port(port
);
449 if (mctrl
& TIOCM_RTS
)
450 sio_mask(up
, TXX9_SIFLCR
, TXX9_SIFLCR_RTSSC
);
452 sio_set(up
, TXX9_SIFLCR
, TXX9_SIFLCR_RTSSC
);
455 static void serial_txx9_break_ctl(struct uart_port
*port
, int break_state
)
457 struct uart_txx9_port
*up
= to_uart_txx9_port(port
);
460 spin_lock_irqsave(&up
->port
.lock
, flags
);
461 if (break_state
== -1)
462 sio_set(up
, TXX9_SIFLCR
, TXX9_SIFLCR_TBRK
);
464 sio_mask(up
, TXX9_SIFLCR
, TXX9_SIFLCR_TBRK
);
465 spin_unlock_irqrestore(&up
->port
.lock
, flags
);
468 #if defined(CONFIG_SERIAL_TXX9_CONSOLE) || defined(CONFIG_CONSOLE_POLL)
470 * Wait for transmitter & holding register to empty
472 static void wait_for_xmitr(struct uart_txx9_port
*up
)
474 unsigned int tmout
= 10000;
476 /* Wait up to 10ms for the character(s) to be sent. */
478 !(sio_in(up
, TXX9_SICISR
) & TXX9_SICISR_TXALS
))
481 /* Wait up to 1s for flow control if necessary */
482 if (up
->port
.flags
& UPF_CONS_FLOW
) {
485 (sio_in(up
, TXX9_SICISR
) & TXX9_SICISR_CTSS
))
491 #ifdef CONFIG_CONSOLE_POLL
493 * Console polling routines for writing and reading from the uart while
494 * in an interrupt or debug context.
497 static int serial_txx9_get_poll_char(struct uart_port
*port
)
501 struct uart_txx9_port
*up
= to_uart_txx9_port(port
);
504 * First save the IER then disable the interrupts
506 ier
= sio_in(up
, TXX9_SIDICR
);
507 sio_out(up
, TXX9_SIDICR
, 0);
509 while (sio_in(up
, TXX9_SIDISR
) & TXX9_SIDISR_UVALID
)
512 c
= sio_in(up
, TXX9_SIRFIFO
);
515 * Finally, clear RX interrupt status
516 * and restore the IER
518 sio_mask(up
, TXX9_SIDISR
, TXX9_SIDISR_RDIS
);
519 sio_out(up
, TXX9_SIDICR
, ier
);
524 static void serial_txx9_put_poll_char(struct uart_port
*port
, unsigned char c
)
527 struct uart_txx9_port
*up
= to_uart_txx9_port(port
);
530 * First save the IER then disable the interrupts
532 ier
= sio_in(up
, TXX9_SIDICR
);
533 sio_out(up
, TXX9_SIDICR
, 0);
537 * Send the character out.
538 * If a LF, also do CR...
540 sio_out(up
, TXX9_SITFIFO
, c
);
543 sio_out(up
, TXX9_SITFIFO
, 13);
547 * Finally, wait for transmitter to become empty
548 * and restore the IER
551 sio_out(up
, TXX9_SIDICR
, ier
);
554 #endif /* CONFIG_CONSOLE_POLL */
556 static int serial_txx9_startup(struct uart_port
*port
)
558 struct uart_txx9_port
*up
= to_uart_txx9_port(port
);
563 * Clear the FIFO buffers and disable them.
564 * (they will be reenabled in set_termios())
566 sio_set(up
, TXX9_SIFCR
,
567 TXX9_SIFCR_TFRST
| TXX9_SIFCR_RFRST
| TXX9_SIFCR_FRSTE
);
569 sio_mask(up
, TXX9_SIFCR
,
570 TXX9_SIFCR_TFRST
| TXX9_SIFCR_RFRST
| TXX9_SIFCR_FRSTE
);
571 sio_out(up
, TXX9_SIDICR
, 0);
574 * Clear the interrupt registers.
576 sio_out(up
, TXX9_SIDISR
, 0);
578 retval
= request_irq(up
->port
.irq
, serial_txx9_interrupt
,
579 IRQF_SHARED
, "serial_txx9", up
);
584 * Now, initialize the UART
586 spin_lock_irqsave(&up
->port
.lock
, flags
);
587 serial_txx9_set_mctrl(&up
->port
, up
->port
.mctrl
);
588 spin_unlock_irqrestore(&up
->port
.lock
, flags
);
591 sio_mask(up
, TXX9_SIFLCR
, TXX9_SIFLCR_RSDE
| TXX9_SIFLCR_TSDE
);
594 * Finally, enable interrupts.
596 sio_set(up
, TXX9_SIDICR
, TXX9_SIDICR_RIE
);
601 static void serial_txx9_shutdown(struct uart_port
*port
)
603 struct uart_txx9_port
*up
= to_uart_txx9_port(port
);
607 * Disable interrupts from this port
609 sio_out(up
, TXX9_SIDICR
, 0); /* disable all intrs */
611 spin_lock_irqsave(&up
->port
.lock
, flags
);
612 serial_txx9_set_mctrl(&up
->port
, up
->port
.mctrl
);
613 spin_unlock_irqrestore(&up
->port
.lock
, flags
);
616 * Disable break condition
618 sio_mask(up
, TXX9_SIFLCR
, TXX9_SIFLCR_TBRK
);
620 #ifdef CONFIG_SERIAL_TXX9_CONSOLE
621 if (up
->port
.cons
&& up
->port
.line
== up
->port
.cons
->index
) {
622 free_irq(up
->port
.irq
, up
);
627 sio_set(up
, TXX9_SIFCR
,
628 TXX9_SIFCR_TFRST
| TXX9_SIFCR_RFRST
| TXX9_SIFCR_FRSTE
);
630 sio_mask(up
, TXX9_SIFCR
,
631 TXX9_SIFCR_TFRST
| TXX9_SIFCR_RFRST
| TXX9_SIFCR_FRSTE
);
634 sio_set(up
, TXX9_SIFLCR
, TXX9_SIFLCR_RSDE
| TXX9_SIFLCR_TSDE
);
636 free_irq(up
->port
.irq
, up
);
640 serial_txx9_set_termios(struct uart_port
*port
, struct ktermios
*termios
,
641 struct ktermios
*old
)
643 struct uart_txx9_port
*up
= to_uart_txx9_port(port
);
644 unsigned int cval
, fcr
= 0;
646 unsigned int baud
, quot
;
649 * We don't support modem control lines.
651 termios
->c_cflag
&= ~(HUPCL
| CMSPAR
);
652 termios
->c_cflag
|= CLOCAL
;
654 cval
= sio_in(up
, TXX9_SILCR
);
655 /* byte size and parity */
656 cval
&= ~TXX9_SILCR_UMODE_MASK
;
657 switch (termios
->c_cflag
& CSIZE
) {
659 cval
|= TXX9_SILCR_UMODE_7BIT
;
662 case CS5
: /* not supported */
663 case CS6
: /* not supported */
665 cval
|= TXX9_SILCR_UMODE_8BIT
;
669 cval
&= ~TXX9_SILCR_USBL_MASK
;
670 if (termios
->c_cflag
& CSTOPB
)
671 cval
|= TXX9_SILCR_USBL_2BIT
;
673 cval
|= TXX9_SILCR_USBL_1BIT
;
674 cval
&= ~(TXX9_SILCR_UPEN
| TXX9_SILCR_UEPS
);
675 if (termios
->c_cflag
& PARENB
)
676 cval
|= TXX9_SILCR_UPEN
;
677 if (!(termios
->c_cflag
& PARODD
))
678 cval
|= TXX9_SILCR_UEPS
;
681 * Ask the core to calculate the divisor for us.
683 baud
= uart_get_baud_rate(port
, termios
, old
, 0, port
->uartclk
/16/2);
684 quot
= uart_get_divisor(port
, baud
);
687 /* TX Int by FIFO Empty, RX Int by Receiving 1 char. */
688 fcr
= TXX9_SIFCR_TDIL_MAX
| TXX9_SIFCR_RDIL_1
;
691 * Ok, we're now changing the port state. Do it with
692 * interrupts disabled.
694 spin_lock_irqsave(&up
->port
.lock
, flags
);
697 * Update the per-port timeout.
699 uart_update_timeout(port
, termios
->c_cflag
, baud
);
701 up
->port
.read_status_mask
= TXX9_SIDISR_UOER
|
702 TXX9_SIDISR_TDIS
| TXX9_SIDISR_RDIS
;
703 if (termios
->c_iflag
& INPCK
)
704 up
->port
.read_status_mask
|= TXX9_SIDISR_UFER
| TXX9_SIDISR_UPER
;
705 if (termios
->c_iflag
& (IGNBRK
| BRKINT
| PARMRK
))
706 up
->port
.read_status_mask
|= TXX9_SIDISR_UBRK
;
709 * Characteres to ignore
711 up
->port
.ignore_status_mask
= 0;
712 if (termios
->c_iflag
& IGNPAR
)
713 up
->port
.ignore_status_mask
|= TXX9_SIDISR_UPER
| TXX9_SIDISR_UFER
;
714 if (termios
->c_iflag
& IGNBRK
) {
715 up
->port
.ignore_status_mask
|= TXX9_SIDISR_UBRK
;
717 * If we're ignoring parity and break indicators,
718 * ignore overruns too (for real raw support).
720 if (termios
->c_iflag
& IGNPAR
)
721 up
->port
.ignore_status_mask
|= TXX9_SIDISR_UOER
;
725 * ignore all characters if CREAD is not set
727 if ((termios
->c_cflag
& CREAD
) == 0)
728 up
->port
.ignore_status_mask
|= TXX9_SIDISR_RDIS
;
730 /* CTS flow control flag */
731 if ((termios
->c_cflag
& CRTSCTS
) &&
732 (up
->port
.flags
& UPF_TXX9_HAVE_CTS_LINE
)) {
733 sio_set(up
, TXX9_SIFLCR
,
734 TXX9_SIFLCR_RCS
| TXX9_SIFLCR_TES
);
736 sio_mask(up
, TXX9_SIFLCR
,
737 TXX9_SIFLCR_RCS
| TXX9_SIFLCR_TES
);
740 sio_out(up
, TXX9_SILCR
, cval
);
741 sio_quot_set(up
, quot
);
742 sio_out(up
, TXX9_SIFCR
, fcr
);
744 serial_txx9_set_mctrl(&up
->port
, up
->port
.mctrl
);
745 spin_unlock_irqrestore(&up
->port
.lock
, flags
);
749 serial_txx9_pm(struct uart_port
*port
, unsigned int state
,
750 unsigned int oldstate
)
753 * If oldstate was -1 this is called from
754 * uart_configure_port(). In this case do not initialize the
755 * port now, because the port was already initialized (for
756 * non-console port) or should not be initialized here (for
757 * console port). If we initialized the port here we lose
758 * serial console settings.
760 if (state
== 0 && oldstate
!= -1)
761 serial_txx9_initialize(port
);
764 static int serial_txx9_request_resource(struct uart_txx9_port
*up
)
766 unsigned int size
= TXX9_REGION_SIZE
;
769 switch (up
->port
.iotype
) {
771 if (!up
->port
.mapbase
)
774 if (!request_mem_region(up
->port
.mapbase
, size
, "serial_txx9")) {
779 if (up
->port
.flags
& UPF_IOREMAP
) {
780 up
->port
.membase
= ioremap(up
->port
.mapbase
, size
);
781 if (!up
->port
.membase
) {
782 release_mem_region(up
->port
.mapbase
, size
);
789 if (!request_region(up
->port
.iobase
, size
, "serial_txx9"))
796 static void serial_txx9_release_resource(struct uart_txx9_port
*up
)
798 unsigned int size
= TXX9_REGION_SIZE
;
800 switch (up
->port
.iotype
) {
802 if (!up
->port
.mapbase
)
805 if (up
->port
.flags
& UPF_IOREMAP
) {
806 iounmap(up
->port
.membase
);
807 up
->port
.membase
= NULL
;
810 release_mem_region(up
->port
.mapbase
, size
);
814 release_region(up
->port
.iobase
, size
);
819 static void serial_txx9_release_port(struct uart_port
*port
)
821 struct uart_txx9_port
*up
= to_uart_txx9_port(port
);
822 serial_txx9_release_resource(up
);
825 static int serial_txx9_request_port(struct uart_port
*port
)
827 struct uart_txx9_port
*up
= to_uart_txx9_port(port
);
828 return serial_txx9_request_resource(up
);
831 static void serial_txx9_config_port(struct uart_port
*port
, int uflags
)
833 struct uart_txx9_port
*up
= to_uart_txx9_port(port
);
837 * Find the region that we can probe for. This in turn
838 * tells us whether we can probe for the type of port.
840 ret
= serial_txx9_request_resource(up
);
843 port
->type
= PORT_TXX9
;
844 up
->port
.fifosize
= TXX9_SIO_TX_FIFO
;
846 #ifdef CONFIG_SERIAL_TXX9_CONSOLE
847 if (up
->port
.line
== up
->port
.cons
->index
)
850 serial_txx9_initialize(port
);
854 serial_txx9_type(struct uart_port
*port
)
859 static struct uart_ops serial_txx9_pops
= {
860 .tx_empty
= serial_txx9_tx_empty
,
861 .set_mctrl
= serial_txx9_set_mctrl
,
862 .get_mctrl
= serial_txx9_get_mctrl
,
863 .stop_tx
= serial_txx9_stop_tx
,
864 .start_tx
= serial_txx9_start_tx
,
865 .stop_rx
= serial_txx9_stop_rx
,
866 .enable_ms
= serial_txx9_enable_ms
,
867 .break_ctl
= serial_txx9_break_ctl
,
868 .startup
= serial_txx9_startup
,
869 .shutdown
= serial_txx9_shutdown
,
870 .set_termios
= serial_txx9_set_termios
,
871 .pm
= serial_txx9_pm
,
872 .type
= serial_txx9_type
,
873 .release_port
= serial_txx9_release_port
,
874 .request_port
= serial_txx9_request_port
,
875 .config_port
= serial_txx9_config_port
,
876 #ifdef CONFIG_CONSOLE_POLL
877 .poll_get_char
= serial_txx9_get_poll_char
,
878 .poll_put_char
= serial_txx9_put_poll_char
,
882 static struct uart_txx9_port serial_txx9_ports
[UART_NR
];
884 static void __init
serial_txx9_register_ports(struct uart_driver
*drv
,
889 for (i
= 0; i
< UART_NR
; i
++) {
890 struct uart_txx9_port
*up
= &serial_txx9_ports
[i
];
893 up
->port
.ops
= &serial_txx9_pops
;
895 if (up
->port
.iobase
|| up
->port
.mapbase
)
896 uart_add_one_port(drv
, &up
->port
);
900 #ifdef CONFIG_SERIAL_TXX9_CONSOLE
902 static void serial_txx9_console_putchar(struct uart_port
*port
, int ch
)
904 struct uart_txx9_port
*up
= to_uart_txx9_port(port
);
907 sio_out(up
, TXX9_SITFIFO
, ch
);
911 * Print a string to the serial port trying not to disturb
912 * any possible real use of the port...
914 * The console_lock must be held when we get here.
917 serial_txx9_console_write(struct console
*co
, const char *s
, unsigned int count
)
919 struct uart_txx9_port
*up
= &serial_txx9_ports
[co
->index
];
920 unsigned int ier
, flcr
;
923 * First save the UER then disable the interrupts
925 ier
= sio_in(up
, TXX9_SIDICR
);
926 sio_out(up
, TXX9_SIDICR
, 0);
928 * Disable flow-control if enabled (and unnecessary)
930 flcr
= sio_in(up
, TXX9_SIFLCR
);
931 if (!(up
->port
.flags
& UPF_CONS_FLOW
) && (flcr
& TXX9_SIFLCR_TES
))
932 sio_out(up
, TXX9_SIFLCR
, flcr
& ~TXX9_SIFLCR_TES
);
934 uart_console_write(&up
->port
, s
, count
, serial_txx9_console_putchar
);
937 * Finally, wait for transmitter to become empty
938 * and restore the IER
941 sio_out(up
, TXX9_SIFLCR
, flcr
);
942 sio_out(up
, TXX9_SIDICR
, ier
);
945 static int __init
serial_txx9_console_setup(struct console
*co
, char *options
)
947 struct uart_port
*port
;
948 struct uart_txx9_port
*up
;
955 * Check whether an invalid uart number has been specified, and
956 * if so, search for the first available port that does have
959 if (co
->index
>= UART_NR
)
961 up
= &serial_txx9_ports
[co
->index
];
966 serial_txx9_initialize(&up
->port
);
969 uart_parse_options(options
, &baud
, &parity
, &bits
, &flow
);
971 return uart_set_options(port
, co
, baud
, parity
, bits
, flow
);
974 static struct uart_driver serial_txx9_reg
;
975 static struct console serial_txx9_console
= {
976 .name
= TXX9_TTY_NAME
,
977 .write
= serial_txx9_console_write
,
978 .device
= uart_console_device
,
979 .setup
= serial_txx9_console_setup
,
980 .flags
= CON_PRINTBUFFER
,
982 .data
= &serial_txx9_reg
,
985 static int __init
serial_txx9_console_init(void)
987 register_console(&serial_txx9_console
);
990 console_initcall(serial_txx9_console_init
);
992 #define SERIAL_TXX9_CONSOLE &serial_txx9_console
994 #define SERIAL_TXX9_CONSOLE NULL
997 static struct uart_driver serial_txx9_reg
= {
998 .owner
= THIS_MODULE
,
999 .driver_name
= "serial_txx9",
1000 .dev_name
= TXX9_TTY_NAME
,
1001 .major
= TXX9_TTY_MAJOR
,
1002 .minor
= TXX9_TTY_MINOR_START
,
1004 .cons
= SERIAL_TXX9_CONSOLE
,
1007 int __init
early_serial_txx9_setup(struct uart_port
*port
)
1009 if (port
->line
>= ARRAY_SIZE(serial_txx9_ports
))
1012 serial_txx9_ports
[port
->line
].port
= *port
;
1013 serial_txx9_ports
[port
->line
].port
.ops
= &serial_txx9_pops
;
1014 serial_txx9_ports
[port
->line
].port
.flags
|=
1015 UPF_BOOT_AUTOCONF
| UPF_FIXED_PORT
;
1019 static DEFINE_MUTEX(serial_txx9_mutex
);
1022 * serial_txx9_register_port - register a serial port
1023 * @port: serial port template
1025 * Configure the serial port specified by the request.
1027 * The port is then probed and if necessary the IRQ is autodetected
1028 * If this fails an error is returned.
1030 * On success the port is ready to use and the line number is returned.
1032 static int serial_txx9_register_port(struct uart_port
*port
)
1035 struct uart_txx9_port
*uart
;
1038 mutex_lock(&serial_txx9_mutex
);
1039 for (i
= 0; i
< UART_NR
; i
++) {
1040 uart
= &serial_txx9_ports
[i
];
1041 if (uart_match_port(&uart
->port
, port
)) {
1042 uart_remove_one_port(&serial_txx9_reg
, &uart
->port
);
1047 /* Find unused port */
1048 for (i
= 0; i
< UART_NR
; i
++) {
1049 uart
= &serial_txx9_ports
[i
];
1050 if (!(uart
->port
.iobase
|| uart
->port
.mapbase
))
1055 uart
->port
.iobase
= port
->iobase
;
1056 uart
->port
.membase
= port
->membase
;
1057 uart
->port
.irq
= port
->irq
;
1058 uart
->port
.uartclk
= port
->uartclk
;
1059 uart
->port
.iotype
= port
->iotype
;
1060 uart
->port
.flags
= port
->flags
1061 | UPF_BOOT_AUTOCONF
| UPF_FIXED_PORT
;
1062 uart
->port
.mapbase
= port
->mapbase
;
1064 uart
->port
.dev
= port
->dev
;
1065 ret
= uart_add_one_port(&serial_txx9_reg
, &uart
->port
);
1067 ret
= uart
->port
.line
;
1069 mutex_unlock(&serial_txx9_mutex
);
1074 * serial_txx9_unregister_port - remove a txx9 serial port at runtime
1075 * @line: serial line number
1077 * Remove one serial port. This may not be called from interrupt
1078 * context. We hand the port back to the our control.
1080 static void serial_txx9_unregister_port(int line
)
1082 struct uart_txx9_port
*uart
= &serial_txx9_ports
[line
];
1084 mutex_lock(&serial_txx9_mutex
);
1085 uart_remove_one_port(&serial_txx9_reg
, &uart
->port
);
1086 uart
->port
.flags
= 0;
1087 uart
->port
.type
= PORT_UNKNOWN
;
1088 uart
->port
.iobase
= 0;
1089 uart
->port
.mapbase
= 0;
1090 uart
->port
.membase
= NULL
;
1091 uart
->port
.dev
= NULL
;
1092 mutex_unlock(&serial_txx9_mutex
);
1096 * Register a set of serial devices attached to a platform device.
1098 static int serial_txx9_probe(struct platform_device
*dev
)
1100 struct uart_port
*p
= dev_get_platdata(&dev
->dev
);
1101 struct uart_port port
;
1104 memset(&port
, 0, sizeof(struct uart_port
));
1105 for (i
= 0; p
&& p
->uartclk
!= 0; p
++, i
++) {
1106 port
.iobase
= p
->iobase
;
1107 port
.membase
= p
->membase
;
1109 port
.uartclk
= p
->uartclk
;
1110 port
.iotype
= p
->iotype
;
1111 port
.flags
= p
->flags
;
1112 port
.mapbase
= p
->mapbase
;
1113 port
.dev
= &dev
->dev
;
1114 ret
= serial_txx9_register_port(&port
);
1116 dev_err(&dev
->dev
, "unable to register port at index %d "
1117 "(IO%lx MEM%llx IRQ%d): %d\n", i
,
1118 p
->iobase
, (unsigned long long)p
->mapbase
,
1126 * Remove serial ports registered against a platform device.
1128 static int serial_txx9_remove(struct platform_device
*dev
)
1132 for (i
= 0; i
< UART_NR
; i
++) {
1133 struct uart_txx9_port
*up
= &serial_txx9_ports
[i
];
1135 if (up
->port
.dev
== &dev
->dev
)
1136 serial_txx9_unregister_port(i
);
1142 static int serial_txx9_suspend(struct platform_device
*dev
, pm_message_t state
)
1146 for (i
= 0; i
< UART_NR
; i
++) {
1147 struct uart_txx9_port
*up
= &serial_txx9_ports
[i
];
1149 if (up
->port
.type
!= PORT_UNKNOWN
&& up
->port
.dev
== &dev
->dev
)
1150 uart_suspend_port(&serial_txx9_reg
, &up
->port
);
1156 static int serial_txx9_resume(struct platform_device
*dev
)
1160 for (i
= 0; i
< UART_NR
; i
++) {
1161 struct uart_txx9_port
*up
= &serial_txx9_ports
[i
];
1163 if (up
->port
.type
!= PORT_UNKNOWN
&& up
->port
.dev
== &dev
->dev
)
1164 uart_resume_port(&serial_txx9_reg
, &up
->port
);
1171 static struct platform_driver serial_txx9_plat_driver
= {
1172 .probe
= serial_txx9_probe
,
1173 .remove
= serial_txx9_remove
,
1175 .suspend
= serial_txx9_suspend
,
1176 .resume
= serial_txx9_resume
,
1179 .name
= "serial_txx9",
1180 .owner
= THIS_MODULE
,
1184 #ifdef ENABLE_SERIAL_TXX9_PCI
1186 * Probe one serial board. Unfortunately, there is no rhyme nor reason
1187 * to the arrangement of serial ports on a PCI card.
1190 pciserial_txx9_init_one(struct pci_dev
*dev
, const struct pci_device_id
*ent
)
1192 struct uart_port port
;
1196 rc
= pci_enable_device(dev
);
1200 memset(&port
, 0, sizeof(port
));
1201 port
.ops
= &serial_txx9_pops
;
1202 port
.flags
|= UPF_TXX9_HAVE_CTS_LINE
;
1203 port
.uartclk
= 66670000;
1204 port
.irq
= dev
->irq
;
1205 port
.iotype
= UPIO_PORT
;
1206 port
.iobase
= pci_resource_start(dev
, 1);
1207 port
.dev
= &dev
->dev
;
1208 line
= serial_txx9_register_port(&port
);
1210 printk(KERN_WARNING
"Couldn't register serial port %s: %d\n", pci_name(dev
), line
);
1211 pci_disable_device(dev
);
1214 pci_set_drvdata(dev
, &serial_txx9_ports
[line
]);
1219 static void pciserial_txx9_remove_one(struct pci_dev
*dev
)
1221 struct uart_txx9_port
*up
= pci_get_drvdata(dev
);
1223 pci_set_drvdata(dev
, NULL
);
1226 serial_txx9_unregister_port(up
->port
.line
);
1227 pci_disable_device(dev
);
1232 static int pciserial_txx9_suspend_one(struct pci_dev
*dev
, pm_message_t state
)
1234 struct uart_txx9_port
*up
= pci_get_drvdata(dev
);
1237 uart_suspend_port(&serial_txx9_reg
, &up
->port
);
1238 pci_save_state(dev
);
1239 pci_set_power_state(dev
, pci_choose_state(dev
, state
));
1243 static int pciserial_txx9_resume_one(struct pci_dev
*dev
)
1245 struct uart_txx9_port
*up
= pci_get_drvdata(dev
);
1247 pci_set_power_state(dev
, PCI_D0
);
1248 pci_restore_state(dev
);
1250 uart_resume_port(&serial_txx9_reg
, &up
->port
);
1255 static const struct pci_device_id serial_txx9_pci_tbl
[] = {
1256 { PCI_DEVICE(PCI_VENDOR_ID_TOSHIBA_2
, PCI_DEVICE_ID_TOSHIBA_TC86C001_MISC
) },
1260 static struct pci_driver serial_txx9_pci_driver
= {
1261 .name
= "serial_txx9",
1262 .probe
= pciserial_txx9_init_one
,
1263 .remove
= pciserial_txx9_remove_one
,
1265 .suspend
= pciserial_txx9_suspend_one
,
1266 .resume
= pciserial_txx9_resume_one
,
1268 .id_table
= serial_txx9_pci_tbl
,
1271 MODULE_DEVICE_TABLE(pci
, serial_txx9_pci_tbl
);
1272 #endif /* ENABLE_SERIAL_TXX9_PCI */
1274 static struct platform_device
*serial_txx9_plat_devs
;
1276 static int __init
serial_txx9_init(void)
1280 printk(KERN_INFO
"%s version %s\n", serial_name
, serial_version
);
1282 ret
= uart_register_driver(&serial_txx9_reg
);
1286 serial_txx9_plat_devs
= platform_device_alloc("serial_txx9", -1);
1287 if (!serial_txx9_plat_devs
) {
1289 goto unreg_uart_drv
;
1292 ret
= platform_device_add(serial_txx9_plat_devs
);
1296 serial_txx9_register_ports(&serial_txx9_reg
,
1297 &serial_txx9_plat_devs
->dev
);
1299 ret
= platform_driver_register(&serial_txx9_plat_driver
);
1303 #ifdef ENABLE_SERIAL_TXX9_PCI
1304 ret
= pci_register_driver(&serial_txx9_pci_driver
);
1310 platform_device_del(serial_txx9_plat_devs
);
1312 platform_device_put(serial_txx9_plat_devs
);
1314 uart_unregister_driver(&serial_txx9_reg
);
1319 static void __exit
serial_txx9_exit(void)
1323 #ifdef ENABLE_SERIAL_TXX9_PCI
1324 pci_unregister_driver(&serial_txx9_pci_driver
);
1326 platform_driver_unregister(&serial_txx9_plat_driver
);
1327 platform_device_unregister(serial_txx9_plat_devs
);
1328 for (i
= 0; i
< UART_NR
; i
++) {
1329 struct uart_txx9_port
*up
= &serial_txx9_ports
[i
];
1330 if (up
->port
.iobase
|| up
->port
.mapbase
)
1331 uart_remove_one_port(&serial_txx9_reg
, &up
->port
);
1334 uart_unregister_driver(&serial_txx9_reg
);
1337 module_init(serial_txx9_init
);
1338 module_exit(serial_txx9_exit
);
1340 MODULE_LICENSE("GPL");
1341 MODULE_DESCRIPTION("TX39/49 serial driver");
1343 MODULE_ALIAS_CHARDEV_MAJOR(TXX9_TTY_MAJOR
);