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.09";
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 196
74 #define TXX9_TTY_MAJOR 204
76 /* acts like standard serial driver */
77 #define TXX9_TTY_NAME "ttyS"
78 #define TXX9_TTY_MINOR_START 64
79 #define TXX9_TTY_MAJOR TTY_MAJOR
83 #define UPF_TXX9_HAVE_CTS_LINE UPF_BUGGY_UART
84 #define UPF_TXX9_USE_SCLK UPF_MAGIC_MULTIPLIER
87 /* support for Toshiba TC86C001 SIO */
88 #define ENABLE_SERIAL_TXX9_PCI
92 * Number of serial ports
94 #define UART_NR CONFIG_SERIAL_TXX9_NR_UARTS
96 #define HIGH_BITS_OFFSET ((sizeof(long)-sizeof(int))*8)
98 struct uart_txx9_port {
99 struct uart_port port;
100 /* No additional info for now */
103 #define TXX9_REGION_SIZE 0x24
105 /* TXX9 Serial Registers */
106 #define TXX9_SILCR 0x00
107 #define TXX9_SIDICR 0x04
108 #define TXX9_SIDISR 0x08
109 #define TXX9_SICISR 0x0c
110 #define TXX9_SIFCR 0x10
111 #define TXX9_SIFLCR 0x14
112 #define TXX9_SIBGR 0x18
113 #define TXX9_SITFIFO 0x1c
114 #define TXX9_SIRFIFO 0x20
116 /* SILCR : Line Control */
117 #define TXX9_SILCR_SCS_MASK 0x00000060
118 #define TXX9_SILCR_SCS_IMCLK 0x00000000
119 #define TXX9_SILCR_SCS_IMCLK_BG 0x00000020
120 #define TXX9_SILCR_SCS_SCLK 0x00000040
121 #define TXX9_SILCR_SCS_SCLK_BG 0x00000060
122 #define TXX9_SILCR_UEPS 0x00000010
123 #define TXX9_SILCR_UPEN 0x00000008
124 #define TXX9_SILCR_USBL_MASK 0x00000004
125 #define TXX9_SILCR_USBL_1BIT 0x00000000
126 #define TXX9_SILCR_USBL_2BIT 0x00000004
127 #define TXX9_SILCR_UMODE_MASK 0x00000003
128 #define TXX9_SILCR_UMODE_8BIT 0x00000000
129 #define TXX9_SILCR_UMODE_7BIT 0x00000001
131 /* SIDICR : DMA/Int. Control */
132 #define TXX9_SIDICR_TDE 0x00008000
133 #define TXX9_SIDICR_RDE 0x00004000
134 #define TXX9_SIDICR_TIE 0x00002000
135 #define TXX9_SIDICR_RIE 0x00001000
136 #define TXX9_SIDICR_SPIE 0x00000800
137 #define TXX9_SIDICR_CTSAC 0x00000600
138 #define TXX9_SIDICR_STIE_MASK 0x0000003f
139 #define TXX9_SIDICR_STIE_OERS 0x00000020
140 #define TXX9_SIDICR_STIE_CTSS 0x00000010
141 #define TXX9_SIDICR_STIE_RBRKD 0x00000008
142 #define TXX9_SIDICR_STIE_TRDY 0x00000004
143 #define TXX9_SIDICR_STIE_TXALS 0x00000002
144 #define TXX9_SIDICR_STIE_UBRKD 0x00000001
146 /* SIDISR : DMA/Int. Status */
147 #define TXX9_SIDISR_UBRK 0x00008000
148 #define TXX9_SIDISR_UVALID 0x00004000
149 #define TXX9_SIDISR_UFER 0x00002000
150 #define TXX9_SIDISR_UPER 0x00001000
151 #define TXX9_SIDISR_UOER 0x00000800
152 #define TXX9_SIDISR_ERI 0x00000400
153 #define TXX9_SIDISR_TOUT 0x00000200
154 #define TXX9_SIDISR_TDIS 0x00000100
155 #define TXX9_SIDISR_RDIS 0x00000080
156 #define TXX9_SIDISR_STIS 0x00000040
157 #define TXX9_SIDISR_RFDN_MASK 0x0000001f
159 /* SICISR : Change Int. Status */
160 #define TXX9_SICISR_OERS 0x00000020
161 #define TXX9_SICISR_CTSS 0x00000010
162 #define TXX9_SICISR_RBRKD 0x00000008
163 #define TXX9_SICISR_TRDY 0x00000004
164 #define TXX9_SICISR_TXALS 0x00000002
165 #define TXX9_SICISR_UBRKD 0x00000001
167 /* SIFCR : FIFO Control */
168 #define TXX9_SIFCR_SWRST 0x00008000
169 #define TXX9_SIFCR_RDIL_MASK 0x00000180
170 #define TXX9_SIFCR_RDIL_1 0x00000000
171 #define TXX9_SIFCR_RDIL_4 0x00000080
172 #define TXX9_SIFCR_RDIL_8 0x00000100
173 #define TXX9_SIFCR_RDIL_12 0x00000180
174 #define TXX9_SIFCR_RDIL_MAX 0x00000180
175 #define TXX9_SIFCR_TDIL_MASK 0x00000018
176 #define TXX9_SIFCR_TDIL_MASK 0x00000018
177 #define TXX9_SIFCR_TDIL_1 0x00000000
178 #define TXX9_SIFCR_TDIL_4 0x00000001
179 #define TXX9_SIFCR_TDIL_8 0x00000010
180 #define TXX9_SIFCR_TDIL_MAX 0x00000010
181 #define TXX9_SIFCR_TFRST 0x00000004
182 #define TXX9_SIFCR_RFRST 0x00000002
183 #define TXX9_SIFCR_FRSTE 0x00000001
184 #define TXX9_SIO_TX_FIFO 8
185 #define TXX9_SIO_RX_FIFO 16
187 /* SIFLCR : Flow Control */
188 #define TXX9_SIFLCR_RCS 0x00001000
189 #define TXX9_SIFLCR_TES 0x00000800
190 #define TXX9_SIFLCR_RTSSC 0x00000200
191 #define TXX9_SIFLCR_RSDE 0x00000100
192 #define TXX9_SIFLCR_TSDE 0x00000080
193 #define TXX9_SIFLCR_RTSTL_MASK 0x0000001e
194 #define TXX9_SIFLCR_RTSTL_MAX 0x0000001e
195 #define TXX9_SIFLCR_TBRK 0x00000001
197 /* SIBGR : Baudrate Control */
198 #define TXX9_SIBGR_BCLK_MASK 0x00000300
199 #define TXX9_SIBGR_BCLK_T0 0x00000000
200 #define TXX9_SIBGR_BCLK_T2 0x00000100
201 #define TXX9_SIBGR_BCLK_T4 0x00000200
202 #define TXX9_SIBGR_BCLK_T6 0x00000300
203 #define TXX9_SIBGR_BRD_MASK 0x000000ff
205 static inline unsigned int sio_in(struct uart_txx9_port *up, int offset)
207 switch (up->port.iotype) {
209 return __raw_readl(up->port.membase + offset);
211 return inl(up->port.iobase + offset);
216 sio_out(struct uart_txx9_port *up, int offset, int value)
218 switch (up->port.iotype) {
220 __raw_writel(value, up->port.membase + offset);
223 outl(value, up->port.iobase + offset);
229 sio_mask(struct uart_txx9_port *up, int offset, unsigned int value)
231 sio_out(up, offset, sio_in(up, offset) & ~value);
234 sio_set(struct uart_txx9_port *up, int offset, unsigned int value)
236 sio_out(up, offset, sio_in(up, offset) | value);
240 sio_quot_set(struct uart_txx9_port *up, int quot)
244 sio_out(up, TXX9_SIBGR, quot | TXX9_SIBGR_BCLK_T0);
245 else if (quot < (256 << 2))
246 sio_out(up, TXX9_SIBGR, (quot >> 2) | TXX9_SIBGR_BCLK_T2);
247 else if (quot < (256 << 4))
248 sio_out(up, TXX9_SIBGR, (quot >> 4) | TXX9_SIBGR_BCLK_T4);
249 else if (quot < (256 << 6))
250 sio_out(up, TXX9_SIBGR, (quot >> 6) | TXX9_SIBGR_BCLK_T6);
252 sio_out(up, TXX9_SIBGR, 0xff | TXX9_SIBGR_BCLK_T6);
255 static void serial_txx9_stop_tx(struct uart_port *port)
257 struct uart_txx9_port *up = (struct uart_txx9_port *)port;
258 sio_mask(up, TXX9_SIDICR, TXX9_SIDICR_TIE);
261 static void serial_txx9_start_tx(struct uart_port *port)
263 struct uart_txx9_port *up = (struct uart_txx9_port *)port;
264 sio_set(up, TXX9_SIDICR, TXX9_SIDICR_TIE);
267 static void serial_txx9_stop_rx(struct uart_port *port)
269 struct uart_txx9_port *up = (struct uart_txx9_port *)port;
270 up->port.read_status_mask &= ~TXX9_SIDISR_RDIS;
273 static void serial_txx9_enable_ms(struct uart_port *port)
275 /* TXX9-SIO can not control DTR... */
278 static void serial_txx9_initialize(struct uart_port *port)
280 struct uart_txx9_port *up = (struct uart_txx9_port *)port;
281 unsigned int tmout = 10000;
283 sio_out(up, TXX9_SIFCR, TXX9_SIFCR_SWRST);
284 /* TX4925 BUG WORKAROUND. Accessing SIOC register
285 * immediately after soft reset causes bus error. */
288 while ((sio_in(up, TXX9_SIFCR) & TXX9_SIFCR_SWRST) && --tmout)
290 /* TX Int by FIFO Empty, RX Int by Receiving 1 char. */
291 sio_set(up, TXX9_SIFCR,
292 TXX9_SIFCR_TDIL_MAX | TXX9_SIFCR_RDIL_1);
293 /* initial settings */
294 sio_out(up, TXX9_SILCR,
295 TXX9_SILCR_UMODE_8BIT | TXX9_SILCR_USBL_1BIT |
296 ((up->port.flags & UPF_TXX9_USE_SCLK) ?
297 TXX9_SILCR_SCS_SCLK_BG : TXX9_SILCR_SCS_IMCLK_BG));
298 sio_quot_set(up, uart_get_divisor(port, 9600));
299 sio_out(up, TXX9_SIFLCR, TXX9_SIFLCR_RTSTL_MAX /* 15 */);
300 sio_out(up, TXX9_SIDICR, 0);
304 receive_chars(struct uart_txx9_port *up, unsigned int *status)
306 struct tty_struct *tty = up->port.info->tty;
308 unsigned int disr = *status;
311 unsigned int next_ignore_status_mask;
314 ch = sio_in(up, TXX9_SIRFIFO);
316 up->port.icount.rx++;
318 /* mask out RFDN_MASK bit added by previous overrun */
319 next_ignore_status_mask =
320 up->port.ignore_status_mask & ~TXX9_SIDISR_RFDN_MASK;
321 if (unlikely(disr & (TXX9_SIDISR_UBRK | TXX9_SIDISR_UPER |
322 TXX9_SIDISR_UFER | TXX9_SIDISR_UOER))) {
324 * For statistics only
326 if (disr & TXX9_SIDISR_UBRK) {
327 disr &= ~(TXX9_SIDISR_UFER | TXX9_SIDISR_UPER);
328 up->port.icount.brk++;
330 * We do the SysRQ and SAK checking
331 * here because otherwise the break
332 * may get masked by ignore_status_mask
333 * or read_status_mask.
335 if (uart_handle_break(&up->port))
337 } else if (disr & TXX9_SIDISR_UPER)
338 up->port.icount.parity++;
339 else if (disr & TXX9_SIDISR_UFER)
340 up->port.icount.frame++;
341 if (disr & TXX9_SIDISR_UOER) {
342 up->port.icount.overrun++;
344 * The receiver read buffer still hold
345 * a char which caused overrun.
346 * Ignore next char by adding RFDN_MASK
347 * to ignore_status_mask temporarily.
349 next_ignore_status_mask |=
350 TXX9_SIDISR_RFDN_MASK;
354 * Mask off conditions which should be ingored.
356 disr &= up->port.read_status_mask;
358 if (disr & TXX9_SIDISR_UBRK) {
360 } else if (disr & TXX9_SIDISR_UPER)
362 else if (disr & TXX9_SIDISR_UFER)
365 if (uart_handle_sysrq_char(&up->port, ch))
368 uart_insert_char(&up->port, disr, TXX9_SIDISR_UOER, ch, flag);
371 up->port.ignore_status_mask = next_ignore_status_mask;
372 disr = sio_in(up, TXX9_SIDISR);
373 } while (!(disr & TXX9_SIDISR_UVALID) && (max_count-- > 0));
374 spin_unlock(&up->port.lock);
375 tty_flip_buffer_push(tty);
376 spin_lock(&up->port.lock);
380 static inline void transmit_chars(struct uart_txx9_port *up)
382 struct circ_buf *xmit = &up->port.info->xmit;
385 if (up->port.x_char) {
386 sio_out(up, TXX9_SITFIFO, up->port.x_char);
387 up->port.icount.tx++;
391 if (uart_circ_empty(xmit) || uart_tx_stopped(&up->port)) {
392 serial_txx9_stop_tx(&up->port);
396 count = TXX9_SIO_TX_FIFO;
398 sio_out(up, TXX9_SITFIFO, xmit->buf[xmit->tail]);
399 xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE - 1);
400 up->port.icount.tx++;
401 if (uart_circ_empty(xmit))
403 } while (--count > 0);
405 if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS)
406 uart_write_wakeup(&up->port);
408 if (uart_circ_empty(xmit))
409 serial_txx9_stop_tx(&up->port);
412 static irqreturn_t serial_txx9_interrupt(int irq, void *dev_id)
414 int pass_counter = 0;
415 struct uart_txx9_port *up = dev_id;
419 spin_lock(&up->port.lock);
420 status = sio_in(up, TXX9_SIDISR);
421 if (!(sio_in(up, TXX9_SIDICR) & TXX9_SIDICR_TIE))
422 status &= ~TXX9_SIDISR_TDIS;
423 if (!(status & (TXX9_SIDISR_TDIS | TXX9_SIDISR_RDIS |
424 TXX9_SIDISR_TOUT))) {
425 spin_unlock(&up->port.lock);
429 if (status & TXX9_SIDISR_RDIS)
430 receive_chars(up, &status);
431 if (status & TXX9_SIDISR_TDIS)
433 /* Clear TX/RX Int. Status */
434 sio_mask(up, TXX9_SIDISR,
435 TXX9_SIDISR_TDIS | TXX9_SIDISR_RDIS |
437 spin_unlock(&up->port.lock);
439 if (pass_counter++ > PASS_LIMIT)
443 return pass_counter ? IRQ_HANDLED : IRQ_NONE;
446 static unsigned int serial_txx9_tx_empty(struct uart_port *port)
448 struct uart_txx9_port *up = (struct uart_txx9_port *)port;
452 spin_lock_irqsave(&up->port.lock, flags);
453 ret = (sio_in(up, TXX9_SICISR) & TXX9_SICISR_TXALS) ? TIOCSER_TEMT : 0;
454 spin_unlock_irqrestore(&up->port.lock, flags);
459 static unsigned int serial_txx9_get_mctrl(struct uart_port *port)
461 struct uart_txx9_port *up = (struct uart_txx9_port *)port;
464 ret = ((sio_in(up, TXX9_SIFLCR) & TXX9_SIFLCR_RTSSC) ? 0 : TIOCM_RTS)
465 | ((sio_in(up, TXX9_SICISR) & TXX9_SICISR_CTSS) ? 0 : TIOCM_CTS);
470 static void serial_txx9_set_mctrl(struct uart_port *port, unsigned int mctrl)
472 struct uart_txx9_port *up = (struct uart_txx9_port *)port;
474 if (mctrl & TIOCM_RTS)
475 sio_mask(up, TXX9_SIFLCR, TXX9_SIFLCR_RTSSC);
477 sio_set(up, TXX9_SIFLCR, TXX9_SIFLCR_RTSSC);
480 static void serial_txx9_break_ctl(struct uart_port *port, int break_state)
482 struct uart_txx9_port *up = (struct uart_txx9_port *)port;
485 spin_lock_irqsave(&up->port.lock, flags);
486 if (break_state == -1)
487 sio_set(up, TXX9_SIFLCR, TXX9_SIFLCR_TBRK);
489 sio_mask(up, TXX9_SIFLCR, TXX9_SIFLCR_TBRK);
490 spin_unlock_irqrestore(&up->port.lock, flags);
493 static int serial_txx9_startup(struct uart_port *port)
495 struct uart_txx9_port *up = (struct uart_txx9_port *)port;
500 * Clear the FIFO buffers and disable them.
501 * (they will be reenabled in set_termios())
503 sio_set(up, TXX9_SIFCR,
504 TXX9_SIFCR_TFRST | TXX9_SIFCR_RFRST | TXX9_SIFCR_FRSTE);
506 sio_mask(up, TXX9_SIFCR,
507 TXX9_SIFCR_TFRST | TXX9_SIFCR_RFRST | TXX9_SIFCR_FRSTE);
508 sio_out(up, TXX9_SIDICR, 0);
511 * Clear the interrupt registers.
513 sio_out(up, TXX9_SIDISR, 0);
515 retval = request_irq(up->port.irq, serial_txx9_interrupt,
516 IRQF_SHARED, "serial_txx9", up);
521 * Now, initialize the UART
523 spin_lock_irqsave(&up->port.lock, flags);
524 serial_txx9_set_mctrl(&up->port, up->port.mctrl);
525 spin_unlock_irqrestore(&up->port.lock, flags);
528 sio_mask(up, TXX9_SIFLCR, TXX9_SIFLCR_RSDE | TXX9_SIFLCR_TSDE);
531 * Finally, enable interrupts.
533 sio_set(up, TXX9_SIDICR, TXX9_SIDICR_RIE);
538 static void serial_txx9_shutdown(struct uart_port *port)
540 struct uart_txx9_port *up = (struct uart_txx9_port *)port;
544 * Disable interrupts from this port
546 sio_out(up, TXX9_SIDICR, 0); /* disable all intrs */
548 spin_lock_irqsave(&up->port.lock, flags);
549 serial_txx9_set_mctrl(&up->port, up->port.mctrl);
550 spin_unlock_irqrestore(&up->port.lock, flags);
553 * Disable break condition
555 sio_mask(up, TXX9_SIFLCR, TXX9_SIFLCR_TBRK);
557 #ifdef CONFIG_SERIAL_TXX9_CONSOLE
558 if (up->port.cons && up->port.line == up->port.cons->index) {
559 free_irq(up->port.irq, up);
564 sio_set(up, TXX9_SIFCR,
565 TXX9_SIFCR_TFRST | TXX9_SIFCR_RFRST | TXX9_SIFCR_FRSTE);
567 sio_mask(up, TXX9_SIFCR,
568 TXX9_SIFCR_TFRST | TXX9_SIFCR_RFRST | TXX9_SIFCR_FRSTE);
571 sio_set(up, TXX9_SIFLCR, TXX9_SIFLCR_RSDE | TXX9_SIFLCR_TSDE);
573 free_irq(up->port.irq, up);
577 serial_txx9_set_termios(struct uart_port *port, struct ktermios *termios,
578 struct ktermios *old)
580 struct uart_txx9_port *up = (struct uart_txx9_port *)port;
581 unsigned int cval, fcr = 0;
583 unsigned int baud, quot;
585 cval = sio_in(up, TXX9_SILCR);
586 /* byte size and parity */
587 cval &= ~TXX9_SILCR_UMODE_MASK;
588 switch (termios->c_cflag & CSIZE) {
590 cval |= TXX9_SILCR_UMODE_7BIT;
593 case CS5: /* not supported */
594 case CS6: /* not supported */
596 cval |= TXX9_SILCR_UMODE_8BIT;
600 cval &= ~TXX9_SILCR_USBL_MASK;
601 if (termios->c_cflag & CSTOPB)
602 cval |= TXX9_SILCR_USBL_2BIT;
604 cval |= TXX9_SILCR_USBL_1BIT;
605 cval &= ~(TXX9_SILCR_UPEN | TXX9_SILCR_UEPS);
606 if (termios->c_cflag & PARENB)
607 cval |= TXX9_SILCR_UPEN;
608 if (!(termios->c_cflag & PARODD))
609 cval |= TXX9_SILCR_UEPS;
612 * Ask the core to calculate the divisor for us.
614 baud = uart_get_baud_rate(port, termios, old, 0, port->uartclk/16/2);
615 quot = uart_get_divisor(port, baud);
618 /* TX Int by FIFO Empty, RX Int by Receiving 1 char. */
619 fcr = TXX9_SIFCR_TDIL_MAX | TXX9_SIFCR_RDIL_1;
622 * Ok, we're now changing the port state. Do it with
623 * interrupts disabled.
625 spin_lock_irqsave(&up->port.lock, flags);
628 * Update the per-port timeout.
630 uart_update_timeout(port, termios->c_cflag, baud);
632 up->port.read_status_mask = TXX9_SIDISR_UOER |
633 TXX9_SIDISR_TDIS | TXX9_SIDISR_RDIS;
634 if (termios->c_iflag & INPCK)
635 up->port.read_status_mask |= TXX9_SIDISR_UFER | TXX9_SIDISR_UPER;
636 if (termios->c_iflag & (BRKINT | PARMRK))
637 up->port.read_status_mask |= TXX9_SIDISR_UBRK;
640 * Characteres to ignore
642 up->port.ignore_status_mask = 0;
643 if (termios->c_iflag & IGNPAR)
644 up->port.ignore_status_mask |= TXX9_SIDISR_UPER | TXX9_SIDISR_UFER;
645 if (termios->c_iflag & IGNBRK) {
646 up->port.ignore_status_mask |= TXX9_SIDISR_UBRK;
648 * If we're ignoring parity and break indicators,
649 * ignore overruns too (for real raw support).
651 if (termios->c_iflag & IGNPAR)
652 up->port.ignore_status_mask |= TXX9_SIDISR_UOER;
656 * ignore all characters if CREAD is not set
658 if ((termios->c_cflag & CREAD) == 0)
659 up->port.ignore_status_mask |= TXX9_SIDISR_RDIS;
661 /* CTS flow control flag */
662 if ((termios->c_cflag & CRTSCTS) &&
663 (up->port.flags & UPF_TXX9_HAVE_CTS_LINE)) {
664 sio_set(up, TXX9_SIFLCR,
665 TXX9_SIFLCR_RCS | TXX9_SIFLCR_TES);
667 sio_mask(up, TXX9_SIFLCR,
668 TXX9_SIFLCR_RCS | TXX9_SIFLCR_TES);
671 sio_out(up, TXX9_SILCR, cval);
672 sio_quot_set(up, quot);
673 sio_out(up, TXX9_SIFCR, fcr);
675 serial_txx9_set_mctrl(&up->port, up->port.mctrl);
676 spin_unlock_irqrestore(&up->port.lock, flags);
680 serial_txx9_pm(struct uart_port *port, unsigned int state,
681 unsigned int oldstate)
684 serial_txx9_initialize(port);
687 static int serial_txx9_request_resource(struct uart_txx9_port *up)
689 unsigned int size = TXX9_REGION_SIZE;
692 switch (up->port.iotype) {
694 if (!up->port.mapbase)
697 if (!request_mem_region(up->port.mapbase, size, "serial_txx9")) {
702 if (up->port.flags & UPF_IOREMAP) {
703 up->port.membase = ioremap(up->port.mapbase, size);
704 if (!up->port.membase) {
705 release_mem_region(up->port.mapbase, size);
712 if (!request_region(up->port.iobase, size, "serial_txx9"))
719 static void serial_txx9_release_resource(struct uart_txx9_port *up)
721 unsigned int size = TXX9_REGION_SIZE;
723 switch (up->port.iotype) {
725 if (!up->port.mapbase)
728 if (up->port.flags & UPF_IOREMAP) {
729 iounmap(up->port.membase);
730 up->port.membase = NULL;
733 release_mem_region(up->port.mapbase, size);
737 release_region(up->port.iobase, size);
742 static void serial_txx9_release_port(struct uart_port *port)
744 struct uart_txx9_port *up = (struct uart_txx9_port *)port;
745 serial_txx9_release_resource(up);
748 static int serial_txx9_request_port(struct uart_port *port)
750 struct uart_txx9_port *up = (struct uart_txx9_port *)port;
751 return serial_txx9_request_resource(up);
754 static void serial_txx9_config_port(struct uart_port *port, int uflags)
756 struct uart_txx9_port *up = (struct uart_txx9_port *)port;
760 * Find the region that we can probe for. This in turn
761 * tells us whether we can probe for the type of port.
763 ret = serial_txx9_request_resource(up);
766 port->type = PORT_TXX9;
767 up->port.fifosize = TXX9_SIO_TX_FIFO;
769 #ifdef CONFIG_SERIAL_TXX9_CONSOLE
770 if (up->port.line == up->port.cons->index)
773 serial_txx9_initialize(port);
777 serial_txx9_verify_port(struct uart_port *port, struct serial_struct *ser)
779 unsigned long new_port = ser->port;
780 if (HIGH_BITS_OFFSET)
781 new_port += (unsigned long)ser->port_high << HIGH_BITS_OFFSET;
782 if (ser->type != port->type ||
783 ser->irq != port->irq ||
784 ser->io_type != port->iotype ||
785 new_port != port->iobase ||
786 (unsigned long)ser->iomem_base != port->mapbase)
792 serial_txx9_type(struct uart_port *port)
797 static struct uart_ops serial_txx9_pops = {
798 .tx_empty = serial_txx9_tx_empty,
799 .set_mctrl = serial_txx9_set_mctrl,
800 .get_mctrl = serial_txx9_get_mctrl,
801 .stop_tx = serial_txx9_stop_tx,
802 .start_tx = serial_txx9_start_tx,
803 .stop_rx = serial_txx9_stop_rx,
804 .enable_ms = serial_txx9_enable_ms,
805 .break_ctl = serial_txx9_break_ctl,
806 .startup = serial_txx9_startup,
807 .shutdown = serial_txx9_shutdown,
808 .set_termios = serial_txx9_set_termios,
809 .pm = serial_txx9_pm,
810 .type = serial_txx9_type,
811 .release_port = serial_txx9_release_port,
812 .request_port = serial_txx9_request_port,
813 .config_port = serial_txx9_config_port,
814 .verify_port = serial_txx9_verify_port,
817 static struct uart_txx9_port serial_txx9_ports[UART_NR];
819 static void __init serial_txx9_register_ports(struct uart_driver *drv,
824 for (i = 0; i < UART_NR; i++) {
825 struct uart_txx9_port *up = &serial_txx9_ports[i];
828 up->port.ops = &serial_txx9_pops;
830 if (up->port.iobase || up->port.mapbase)
831 uart_add_one_port(drv, &up->port);
835 #ifdef CONFIG_SERIAL_TXX9_CONSOLE
838 * Wait for transmitter & holding register to empty
840 static inline void wait_for_xmitr(struct uart_txx9_port *up)
842 unsigned int tmout = 10000;
844 /* Wait up to 10ms for the character(s) to be sent. */
846 !(sio_in(up, TXX9_SICISR) & TXX9_SICISR_TXALS))
849 /* Wait up to 1s for flow control if necessary */
850 if (up->port.flags & UPF_CONS_FLOW) {
853 (sio_in(up, TXX9_SICISR) & TXX9_SICISR_CTSS))
858 static void serial_txx9_console_putchar(struct uart_port *port, int ch)
860 struct uart_txx9_port *up = (struct uart_txx9_port *)port;
863 sio_out(up, TXX9_SITFIFO, ch);
867 * Print a string to the serial port trying not to disturb
868 * any possible real use of the port...
870 * The console_lock must be held when we get here.
873 serial_txx9_console_write(struct console *co, const char *s, unsigned int count)
875 struct uart_txx9_port *up = &serial_txx9_ports[co->index];
876 unsigned int ier, flcr;
879 * First save the UER then disable the interrupts
881 ier = sio_in(up, TXX9_SIDICR);
882 sio_out(up, TXX9_SIDICR, 0);
884 * Disable flow-control if enabled (and unnecessary)
886 flcr = sio_in(up, TXX9_SIFLCR);
887 if (!(up->port.flags & UPF_CONS_FLOW) && (flcr & TXX9_SIFLCR_TES))
888 sio_out(up, TXX9_SIFLCR, flcr & ~TXX9_SIFLCR_TES);
890 uart_console_write(&up->port, s, count, serial_txx9_console_putchar);
893 * Finally, wait for transmitter to become empty
894 * and restore the IER
897 sio_out(up, TXX9_SIFLCR, flcr);
898 sio_out(up, TXX9_SIDICR, ier);
901 static int __init serial_txx9_console_setup(struct console *co, char *options)
903 struct uart_port *port;
904 struct uart_txx9_port *up;
911 * Check whether an invalid uart number has been specified, and
912 * if so, search for the first available port that does have
915 if (co->index >= UART_NR)
917 up = &serial_txx9_ports[co->index];
922 serial_txx9_initialize(&up->port);
925 uart_parse_options(options, &baud, &parity, &bits, &flow);
927 return uart_set_options(port, co, baud, parity, bits, flow);
930 static struct uart_driver serial_txx9_reg;
931 static struct console serial_txx9_console = {
932 .name = TXX9_TTY_NAME,
933 .write = serial_txx9_console_write,
934 .device = uart_console_device,
935 .setup = serial_txx9_console_setup,
936 .flags = CON_PRINTBUFFER,
938 .data = &serial_txx9_reg,
941 static int __init serial_txx9_console_init(void)
943 register_console(&serial_txx9_console);
946 console_initcall(serial_txx9_console_init);
948 #define SERIAL_TXX9_CONSOLE &serial_txx9_console
950 #define SERIAL_TXX9_CONSOLE NULL
953 static struct uart_driver serial_txx9_reg = {
954 .owner = THIS_MODULE,
955 .driver_name = "serial_txx9",
956 .dev_name = TXX9_TTY_NAME,
957 .major = TXX9_TTY_MAJOR,
958 .minor = TXX9_TTY_MINOR_START,
960 .cons = SERIAL_TXX9_CONSOLE,
963 int __init early_serial_txx9_setup(struct uart_port *port)
965 if (port->line >= ARRAY_SIZE(serial_txx9_ports))
968 serial_txx9_ports[port->line].port = *port;
969 serial_txx9_ports[port->line].port.ops = &serial_txx9_pops;
970 serial_txx9_ports[port->line].port.flags |= UPF_BOOT_AUTOCONF;
974 static DEFINE_MUTEX(serial_txx9_mutex);
977 * serial_txx9_register_port - register a serial port
978 * @port: serial port template
980 * Configure the serial port specified by the request.
982 * The port is then probed and if necessary the IRQ is autodetected
983 * If this fails an error is returned.
985 * On success the port is ready to use and the line number is returned.
987 static int __devinit serial_txx9_register_port(struct uart_port *port)
990 struct uart_txx9_port *uart;
993 mutex_lock(&serial_txx9_mutex);
994 for (i = 0; i < UART_NR; i++) {
995 uart = &serial_txx9_ports[i];
996 if (uart_match_port(&uart->port, port)) {
997 uart_remove_one_port(&serial_txx9_reg, &uart->port);
1002 /* Find unused port */
1003 for (i = 0; i < UART_NR; i++) {
1004 uart = &serial_txx9_ports[i];
1005 if (!(uart->port.iobase || uart->port.mapbase))
1010 uart->port.iobase = port->iobase;
1011 uart->port.membase = port->membase;
1012 uart->port.irq = port->irq;
1013 uart->port.uartclk = port->uartclk;
1014 uart->port.iotype = port->iotype;
1015 uart->port.flags = port->flags | UPF_BOOT_AUTOCONF;
1016 uart->port.mapbase = port->mapbase;
1018 uart->port.dev = port->dev;
1019 ret = uart_add_one_port(&serial_txx9_reg, &uart->port);
1021 ret = uart->port.line;
1023 mutex_unlock(&serial_txx9_mutex);
1028 * serial_txx9_unregister_port - remove a txx9 serial port at runtime
1029 * @line: serial line number
1031 * Remove one serial port. This may not be called from interrupt
1032 * context. We hand the port back to the our control.
1034 static void __devexit serial_txx9_unregister_port(int line)
1036 struct uart_txx9_port *uart = &serial_txx9_ports[line];
1038 mutex_lock(&serial_txx9_mutex);
1039 uart_remove_one_port(&serial_txx9_reg, &uart->port);
1040 uart->port.flags = 0;
1041 uart->port.type = PORT_UNKNOWN;
1042 uart->port.iobase = 0;
1043 uart->port.mapbase = 0;
1044 uart->port.membase = NULL;
1045 uart->port.dev = NULL;
1046 mutex_unlock(&serial_txx9_mutex);
1050 * Register a set of serial devices attached to a platform device.
1052 static int __devinit serial_txx9_probe(struct platform_device *dev)
1054 struct uart_port *p = dev->dev.platform_data;
1055 struct uart_port port;
1058 memset(&port, 0, sizeof(struct uart_port));
1059 for (i = 0; p && p->uartclk != 0; p++, i++) {
1060 port.iobase = p->iobase;
1061 port.membase = p->membase;
1063 port.uartclk = p->uartclk;
1064 port.iotype = p->iotype;
1065 port.flags = p->flags;
1066 port.mapbase = p->mapbase;
1067 port.dev = &dev->dev;
1068 ret = serial_txx9_register_port(&port);
1070 dev_err(&dev->dev, "unable to register port at index %d "
1071 "(IO%x MEM%lx IRQ%d): %d\n", i,
1072 p->iobase, p->mapbase, p->irq, ret);
1079 * Remove serial ports registered against a platform device.
1081 static int __devexit serial_txx9_remove(struct platform_device *dev)
1085 for (i = 0; i < UART_NR; i++) {
1086 struct uart_txx9_port *up = &serial_txx9_ports[i];
1088 if (up->port.dev == &dev->dev)
1089 serial_txx9_unregister_port(i);
1095 static int serial_txx9_suspend(struct platform_device *dev, pm_message_t state)
1099 for (i = 0; i < UART_NR; i++) {
1100 struct uart_txx9_port *up = &serial_txx9_ports[i];
1102 if (up->port.type != PORT_UNKNOWN && up->port.dev == &dev->dev)
1103 uart_suspend_port(&serial_txx9_reg, &up->port);
1109 static int serial_txx9_resume(struct platform_device *dev)
1113 for (i = 0; i < UART_NR; i++) {
1114 struct uart_txx9_port *up = &serial_txx9_ports[i];
1116 if (up->port.type != PORT_UNKNOWN && up->port.dev == &dev->dev)
1117 uart_resume_port(&serial_txx9_reg, &up->port);
1124 static struct platform_driver serial_txx9_plat_driver = {
1125 .probe = serial_txx9_probe,
1126 .remove = __devexit_p(serial_txx9_remove),
1128 .suspend = serial_txx9_suspend,
1129 .resume = serial_txx9_resume,
1132 .name = "serial_txx9",
1133 .owner = THIS_MODULE,
1137 #ifdef ENABLE_SERIAL_TXX9_PCI
1139 * Probe one serial board. Unfortunately, there is no rhyme nor reason
1140 * to the arrangement of serial ports on a PCI card.
1142 static int __devinit
1143 pciserial_txx9_init_one(struct pci_dev *dev, const struct pci_device_id *ent)
1145 struct uart_port port;
1149 rc = pci_enable_device(dev);
1153 memset(&port, 0, sizeof(port));
1154 port.ops = &serial_txx9_pops;
1155 port.flags |= UPF_TXX9_HAVE_CTS_LINE;
1156 port.uartclk = 66670000;
1157 port.irq = dev->irq;
1158 port.iotype = UPIO_PORT;
1159 port.iobase = pci_resource_start(dev, 1);
1160 port.dev = &dev->dev;
1161 line = serial_txx9_register_port(&port);
1163 printk(KERN_WARNING "Couldn't register serial port %s: %d\n", pci_name(dev), line);
1164 pci_disable_device(dev);
1167 pci_set_drvdata(dev, &serial_txx9_ports[line]);
1172 static void __devexit pciserial_txx9_remove_one(struct pci_dev *dev)
1174 struct uart_txx9_port *up = pci_get_drvdata(dev);
1176 pci_set_drvdata(dev, NULL);
1179 serial_txx9_unregister_port(up->port.line);
1180 pci_disable_device(dev);
1185 static int pciserial_txx9_suspend_one(struct pci_dev *dev, pm_message_t state)
1187 struct uart_txx9_port *up = pci_get_drvdata(dev);
1190 uart_suspend_port(&serial_txx9_reg, &up->port);
1191 pci_save_state(dev);
1192 pci_set_power_state(dev, pci_choose_state(dev, state));
1196 static int pciserial_txx9_resume_one(struct pci_dev *dev)
1198 struct uart_txx9_port *up = pci_get_drvdata(dev);
1200 pci_set_power_state(dev, PCI_D0);
1201 pci_restore_state(dev);
1203 uart_resume_port(&serial_txx9_reg, &up->port);
1208 static const struct pci_device_id serial_txx9_pci_tbl[] = {
1209 { PCI_DEVICE(PCI_VENDOR_ID_TOSHIBA_2, PCI_DEVICE_ID_TOSHIBA_TC86C001_MISC) },
1213 static struct pci_driver serial_txx9_pci_driver = {
1214 .name = "serial_txx9",
1215 .probe = pciserial_txx9_init_one,
1216 .remove = __devexit_p(pciserial_txx9_remove_one),
1218 .suspend = pciserial_txx9_suspend_one,
1219 .resume = pciserial_txx9_resume_one,
1221 .id_table = serial_txx9_pci_tbl,
1224 MODULE_DEVICE_TABLE(pci, serial_txx9_pci_tbl);
1225 #endif /* ENABLE_SERIAL_TXX9_PCI */
1227 static struct platform_device *serial_txx9_plat_devs;
1229 static int __init serial_txx9_init(void)
1233 printk(KERN_INFO "%s version %s\n", serial_name, serial_version);
1235 ret = uart_register_driver(&serial_txx9_reg);
1239 serial_txx9_plat_devs = platform_device_alloc("serial_txx9", -1);
1240 if (!serial_txx9_plat_devs) {
1242 goto unreg_uart_drv;
1245 ret = platform_device_add(serial_txx9_plat_devs);
1249 serial_txx9_register_ports(&serial_txx9_reg,
1250 &serial_txx9_plat_devs->dev);
1252 ret = platform_driver_register(&serial_txx9_plat_driver);
1256 #ifdef ENABLE_SERIAL_TXX9_PCI
1257 ret = pci_register_driver(&serial_txx9_pci_driver);
1263 platform_device_del(serial_txx9_plat_devs);
1265 platform_device_put(serial_txx9_plat_devs);
1267 uart_unregister_driver(&serial_txx9_reg);
1272 static void __exit serial_txx9_exit(void)
1276 #ifdef ENABLE_SERIAL_TXX9_PCI
1277 pci_unregister_driver(&serial_txx9_pci_driver);
1279 platform_driver_unregister(&serial_txx9_plat_driver);
1280 platform_device_unregister(serial_txx9_plat_devs);
1281 for (i = 0; i < UART_NR; i++) {
1282 struct uart_txx9_port *up = &serial_txx9_ports[i];
1283 if (up->port.iobase || up->port.mapbase)
1284 uart_remove_one_port(&serial_txx9_reg, &up->port);
1287 uart_unregister_driver(&serial_txx9_reg);
1290 module_init(serial_txx9_init);
1291 module_exit(serial_txx9_exit);
1293 MODULE_LICENSE("GPL");
1294 MODULE_DESCRIPTION("TX39/49 serial driver");
1296 MODULE_ALIAS_CHARDEV_MAJOR(TXX9_TTY_MAJOR);