2 * mcfserial.c -- serial driver for ColdFire internal UARTS.
4 * Copyright (C) 1999-2003 Greg Ungerer <gerg@snapgear.com>
5 * Copyright (c) 2000-2001 Lineo, Inc. <www.lineo.com>
6 * Copyright (C) 2001-2002 SnapGear Inc. <www.snapgear.com>
8 * Based on code from 68332serial.c which was:
10 * Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu)
11 * Copyright (C) 1998 TSHG
12 * Copyright (c) 1999 Rt-Control Inc. <jeff@uclinux.org>
15 * 08/07/2003 Daniele Bellucci <bellucda@tiscali.it>
16 * some cleanups in mcfrs_write.
20 #include <linux/module.h>
21 #include <linux/errno.h>
22 #include <linux/signal.h>
23 #include <linux/sched.h>
24 #include <linux/timer.h>
25 #include <linux/wait.h>
26 #include <linux/interrupt.h>
27 #include <linux/tty.h>
28 #include <linux/tty_flip.h>
29 #include <linux/string.h>
30 #include <linux/fcntl.h>
32 #include <linux/kernel.h>
33 #include <linux/serial.h>
34 #include <linux/serialP.h>
35 #include <linux/console.h>
36 #include <linux/init.h>
40 #include <asm/system.h>
41 #include <asm/segment.h>
42 #include <asm/semaphore.h>
43 #include <asm/bitops.h>
44 #include <asm/coldfire.h>
45 #include <asm/mcfsim.h>
46 #include <asm/mcfuart.h>
47 #include <asm/nettel.h>
48 #include <asm/uaccess.h>
49 #include "mcfserial.h"
51 struct timer_list mcfrs_timer_struct
;
54 * Default console baud rate, we use this as the default
55 * for all ports so init can just open /dev/console and
56 * keep going. Perhaps one day the cflag settings for the
57 * console can be used instead.
59 #if defined(CONFIG_ARNEWSH) || defined(CONFIG_MOTOROLA) || defined(CONFIG_senTec) || defined(CONFIG_SNEHA)
60 #define CONSOLE_BAUD_RATE 19200
61 #define DEFAULT_CBAUD B19200
64 #if defined(CONFIG_HW_FEITH)
65 #define CONSOLE_BAUD_RATE 38400
66 #define DEFAULT_CBAUD B38400
69 #ifndef CONSOLE_BAUD_RATE
70 #define CONSOLE_BAUD_RATE 9600
71 #define DEFAULT_CBAUD B9600
74 int mcfrs_console_inited
= 0;
75 int mcfrs_console_port
= -1;
76 int mcfrs_console_baud
= CONSOLE_BAUD_RATE
;
77 int mcfrs_console_cbaud
= DEFAULT_CBAUD
;
80 * Driver data structures.
82 static struct tty_driver
*mcfrs_serial_driver
;
84 /* number of characters left in xmit buffer before we ask for more */
85 #define WAKEUP_CHARS 256
89 #undef SERIAL_DEBUG_OPEN
90 #undef SERIAL_DEBUG_FLOW
92 #if defined(CONFIG_M527x) || defined(CONFIG_M528x)
93 #define IRQBASE (MCFINT_VECBASE+MCFINT_UART0)
99 * Configuration table, UARTs to look for at startup.
101 static struct mcf_serial mcfrs_table
[] = {
104 .addr
= (volatile unsigned char *) (MCF_MBAR
+MCFUART_BASE1
),
106 .flags
= ASYNC_BOOT_AUTOCONF
,
110 .addr
= (volatile unsigned char *) (MCF_MBAR
+MCFUART_BASE2
),
112 .flags
= ASYNC_BOOT_AUTOCONF
,
117 #define NR_PORTS (sizeof(mcfrs_table) / sizeof(struct mcf_serial))
120 * This is used to figure out the divisor speeds and the timeouts.
122 static int mcfrs_baud_table
[] = {
123 0, 50, 75, 110, 134, 150, 200, 300, 600, 1200, 1800, 2400, 4800,
124 9600, 19200, 38400, 57600, 115200, 230400, 460800, 0
126 #define MCFRS_BAUD_TABLE_SIZE \
127 (sizeof(mcfrs_baud_table)/sizeof(mcfrs_baud_table[0]))
130 #ifdef CONFIG_MAGIC_SYSRQ
132 * Magic system request keys. Used for debugging...
134 extern int magic_sysrq_key(int ch
);
139 * tmp_buf is used as a temporary buffer by serial_write. We need to
140 * lock it in case the copy_from_user blocks while swapping in a page,
141 * and some other program tries to do a serial write at the same time.
142 * Since the lock will only come under contention when the system is
143 * swapping and available memory is low, it makes sense to share one
144 * buffer across all the serial ports, since it significantly saves
145 * memory if large numbers of serial ports are open.
147 static unsigned char mcfrs_tmp_buf
[4096]; /* This is cheating */
148 static DECLARE_MUTEX(mcfrs_tmp_buf_sem
);
151 * Forware declarations...
153 static void mcfrs_change_speed(struct mcf_serial
*info
);
154 static void mcfrs_wait_until_sent(struct tty_struct
*tty
, int timeout
);
157 static inline int serial_paranoia_check(struct mcf_serial
*info
,
158 char *name
, const char *routine
)
160 #ifdef SERIAL_PARANOIA_CHECK
161 static const char badmagic
[] =
162 "MCFRS(warning): bad magic number for serial struct %s in %s\n";
163 static const char badinfo
[] =
164 "MCFRS(warning): null mcf_serial for %s in %s\n";
167 printk(badinfo
, name
, routine
);
170 if (info
->magic
!= SERIAL_MAGIC
) {
171 printk(badmagic
, name
, routine
);
179 * Sets or clears DTR and RTS on the requested line.
181 static void mcfrs_setsignals(struct mcf_serial
*info
, int dtr
, int rts
)
183 volatile unsigned char *uartp
;
187 printk("%s(%d): mcfrs_setsignals(info=%x,dtr=%d,rts=%d)\n",
188 __FILE__
, __LINE__
, info
, dtr
, rts
);
191 local_irq_save(flags
);
195 mcf_setppdata(MCFPP_DTR1
, (dtr
? 0 : MCFPP_DTR1
));
197 mcf_setppdata(MCFPP_DTR0
, (dtr
? 0 : MCFPP_DTR0
));
203 info
->sigs
|= TIOCM_RTS
;
204 uartp
[MCFUART_UOP1
] = MCFUART_UOP_RTS
;
206 info
->sigs
&= ~TIOCM_RTS
;
207 uartp
[MCFUART_UOP0
] = MCFUART_UOP_RTS
;
210 local_irq_restore(flags
);
215 * Gets values of serial signals.
217 static int mcfrs_getsignals(struct mcf_serial
*info
)
219 volatile unsigned char *uartp
;
222 #if defined(CONFIG_NETtel) && defined(CONFIG_M5307)
223 unsigned short ppdata
;
227 printk("%s(%d): mcfrs_getsignals(info=%x)\n", __FILE__
, __LINE__
);
230 local_irq_save(flags
);
232 sigs
= (uartp
[MCFUART_UIPR
] & MCFUART_UIPR_CTS
) ? 0 : TIOCM_CTS
;
233 sigs
|= (info
->sigs
& TIOCM_RTS
);
238 ppdata
= mcf_getppdata();
239 if (info
->line
== 0) {
240 sigs
|= (ppdata
& MCFPP_DCD0
) ? 0 : TIOCM_CD
;
241 sigs
|= (ppdata
& MCFPP_DTR0
) ? 0 : TIOCM_DTR
;
242 } else if (info
->line
== 1) {
243 sigs
|= (ppdata
& MCFPP_DCD1
) ? 0 : TIOCM_CD
;
244 sigs
|= (ppdata
& MCFPP_DTR1
) ? 0 : TIOCM_DTR
;
249 local_irq_restore(flags
);
254 * ------------------------------------------------------------
255 * mcfrs_stop() and mcfrs_start()
257 * This routines are called before setting or resetting tty->stopped.
258 * They enable or disable transmitter interrupts, as necessary.
259 * ------------------------------------------------------------
261 static void mcfrs_stop(struct tty_struct
*tty
)
263 volatile unsigned char *uartp
;
264 struct mcf_serial
*info
= (struct mcf_serial
*)tty
->driver_data
;
267 if (serial_paranoia_check(info
, tty
->name
, "mcfrs_stop"))
270 local_irq_save(flags
);
272 info
->imr
&= ~MCFUART_UIR_TXREADY
;
273 uartp
[MCFUART_UIMR
] = info
->imr
;
274 local_irq_restore(flags
);
277 static void mcfrs_start(struct tty_struct
*tty
)
279 volatile unsigned char *uartp
;
280 struct mcf_serial
*info
= (struct mcf_serial
*)tty
->driver_data
;
283 if (serial_paranoia_check(info
, tty
->name
, "mcfrs_start"))
286 local_irq_save(flags
);
287 if (info
->xmit_cnt
&& info
->xmit_buf
) {
289 info
->imr
|= MCFUART_UIR_TXREADY
;
290 uartp
[MCFUART_UIMR
] = info
->imr
;
292 local_irq_restore(flags
);
296 * ----------------------------------------------------------------------
298 * Here starts the interrupt handling routines. All of the following
299 * subroutines are declared as inline and are folded into
300 * mcfrs_interrupt(). They were separated out for readability's sake.
302 * Note: mcfrs_interrupt() is a "fast" interrupt, which means that it
303 * runs with interrupts turned off. People who may want to modify
304 * mcfrs_interrupt() should try to keep the interrupt handler as fast as
305 * possible. After you are done making modifications, it is not a bad
308 * gcc -S -DKERNEL -Wall -Wstrict-prototypes -O6 -fomit-frame-pointer serial.c
310 * and look at the resulting assemble code in serial.s.
312 * - Ted Ts'o (tytso@mit.edu), 7-Mar-93
313 * -----------------------------------------------------------------------
316 static inline void receive_chars(struct mcf_serial
*info
)
318 volatile unsigned char *uartp
;
319 struct tty_struct
*tty
= info
->tty
;
320 unsigned char status
, ch
;
327 while ((status
= uartp
[MCFUART_USR
]) & MCFUART_USR_RXREADY
) {
329 if (tty
->flip
.count
>= TTY_FLIPBUF_SIZE
)
332 ch
= uartp
[MCFUART_URB
];
335 #ifdef CONFIG_MAGIC_SYSRQ
336 if (mcfrs_console_inited
&& (info
->line
== mcfrs_console_port
)) {
337 if (magic_sysrq_key(ch
))
343 if (status
& MCFUART_USR_RXERR
) {
344 uartp
[MCFUART_UCR
] = MCFUART_UCR_CMDRESETERR
;
345 if (status
& MCFUART_USR_RXBREAK
) {
346 info
->stats
.rxbreak
++;
347 *tty
->flip
.flag_buf_ptr
++ = TTY_BREAK
;
348 } else if (status
& MCFUART_USR_RXPARITY
) {
349 info
->stats
.rxparity
++;
350 *tty
->flip
.flag_buf_ptr
++ = TTY_PARITY
;
351 } else if (status
& MCFUART_USR_RXOVERRUN
) {
352 info
->stats
.rxoverrun
++;
353 *tty
->flip
.flag_buf_ptr
++ = TTY_OVERRUN
;
354 } else if (status
& MCFUART_USR_RXFRAMING
) {
355 info
->stats
.rxframing
++;
356 *tty
->flip
.flag_buf_ptr
++ = TTY_FRAME
;
358 /* This should never happen... */
359 *tty
->flip
.flag_buf_ptr
++ = 0;
362 *tty
->flip
.flag_buf_ptr
++ = 0;
364 *tty
->flip
.char_buf_ptr
++ = ch
;
367 schedule_work(&tty
->flip
.work
);
371 static inline void transmit_chars(struct mcf_serial
*info
)
373 volatile unsigned char *uartp
;
378 /* Send special char - probably flow control */
379 uartp
[MCFUART_UTB
] = info
->x_char
;
384 if ((info
->xmit_cnt
<= 0) || info
->tty
->stopped
) {
385 info
->imr
&= ~MCFUART_UIR_TXREADY
;
386 uartp
[MCFUART_UIMR
] = info
->imr
;
390 while (uartp
[MCFUART_USR
] & MCFUART_USR_TXREADY
) {
391 uartp
[MCFUART_UTB
] = info
->xmit_buf
[info
->xmit_tail
++];
392 info
->xmit_tail
= info
->xmit_tail
& (SERIAL_XMIT_SIZE
-1);
394 if (--info
->xmit_cnt
<= 0)
398 if (info
->xmit_cnt
< WAKEUP_CHARS
)
399 schedule_work(&info
->tqueue
);
404 * This is the serial driver's generic interrupt routine
406 irqreturn_t
mcfrs_interrupt(int irq
, void *dev_id
, struct pt_regs
*regs
)
408 struct mcf_serial
*info
;
411 info
= &mcfrs_table
[(irq
- IRQBASE
)];
412 isr
= info
->addr
[MCFUART_UISR
] & info
->imr
;
414 if (isr
& MCFUART_UIR_RXREADY
)
416 if (isr
& MCFUART_UIR_TXREADY
)
417 transmit_chars(info
);
422 * -------------------------------------------------------------------
423 * Here ends the serial interrupt routines.
424 * -------------------------------------------------------------------
427 static void mcfrs_offintr(void *private)
429 struct mcf_serial
*info
= (struct mcf_serial
*) private;
430 struct tty_struct
*tty
;
440 * Change of state on a DCD line.
442 void mcfrs_modem_change(struct mcf_serial
*info
, int dcd
)
444 if (info
->count
== 0)
447 if (info
->flags
& ASYNC_CHECK_CD
) {
449 wake_up_interruptible(&info
->open_wait
);
451 schedule_work(&info
->tqueue_hangup
);
458 unsigned short mcfrs_ppstatus
;
461 * This subroutine is called when the RS_TIMER goes off. It is used
462 * to monitor the state of the DCD lines - since they have no edge
463 * sensors and interrupt generators.
465 static void mcfrs_timer(void)
467 unsigned int ppstatus
, dcdval
, i
;
469 ppstatus
= mcf_getppdata() & (MCFPP_DCD0
| MCFPP_DCD1
);
471 if (ppstatus
!= mcfrs_ppstatus
) {
472 for (i
= 0; (i
< 2); i
++) {
473 dcdval
= (i
? MCFPP_DCD1
: MCFPP_DCD0
);
474 if ((ppstatus
& dcdval
) != (mcfrs_ppstatus
& dcdval
)) {
475 mcfrs_modem_change(&mcfrs_table
[i
],
476 ((ppstatus
& dcdval
) ? 0 : 1));
480 mcfrs_ppstatus
= ppstatus
;
483 mcfrs_timer_struct
.expires
= jiffies
+ HZ
/25;
484 add_timer(&mcfrs_timer_struct
);
487 #endif /* MCFPP_DCD0 */
491 * This routine is called from the scheduler tqueue when the interrupt
492 * routine has signalled that a hangup has occurred. The path of
493 * hangup processing is:
495 * serial interrupt routine -> (scheduler tqueue) ->
496 * do_serial_hangup() -> tty->hangup() -> mcfrs_hangup()
499 static void do_serial_hangup(void *private)
501 struct mcf_serial
*info
= (struct mcf_serial
*) private;
502 struct tty_struct
*tty
;
511 static int startup(struct mcf_serial
* info
)
513 volatile unsigned char *uartp
;
516 if (info
->flags
& ASYNC_INITIALIZED
)
519 if (!info
->xmit_buf
) {
520 info
->xmit_buf
= (unsigned char *) __get_free_page(GFP_KERNEL
);
525 local_irq_save(flags
);
527 #ifdef SERIAL_DEBUG_OPEN
528 printk("starting up ttyS%d (irq %d)...\n", info
->line
, info
->irq
);
532 * Reset UART, get it into known state...
535 uartp
[MCFUART_UCR
] = MCFUART_UCR_CMDRESETRX
; /* reset RX */
536 uartp
[MCFUART_UCR
] = MCFUART_UCR_CMDRESETTX
; /* reset TX */
537 mcfrs_setsignals(info
, 1, 1);
540 clear_bit(TTY_IO_ERROR
, &info
->tty
->flags
);
541 info
->xmit_cnt
= info
->xmit_head
= info
->xmit_tail
= 0;
544 * and set the speed of the serial port
546 mcfrs_change_speed(info
);
549 * Lastly enable the UART transmitter and receiver, and
552 info
->imr
= MCFUART_UIR_RXREADY
;
553 uartp
[MCFUART_UCR
] = MCFUART_UCR_RXENABLE
| MCFUART_UCR_TXENABLE
;
554 uartp
[MCFUART_UIMR
] = info
->imr
;
556 info
->flags
|= ASYNC_INITIALIZED
;
557 local_irq_restore(flags
);
562 * This routine will shutdown a serial port; interrupts are disabled, and
563 * DTR is dropped if the hangup on close termio flag is on.
565 static void shutdown(struct mcf_serial
* info
)
567 volatile unsigned char *uartp
;
570 if (!(info
->flags
& ASYNC_INITIALIZED
))
573 #ifdef SERIAL_DEBUG_OPEN
574 printk("Shutting down serial port %d (irq %d)....\n", info
->line
,
578 local_irq_save(flags
);
581 uartp
[MCFUART_UIMR
] = 0; /* mask all interrupts */
582 uartp
[MCFUART_UCR
] = MCFUART_UCR_CMDRESETRX
; /* reset RX */
583 uartp
[MCFUART_UCR
] = MCFUART_UCR_CMDRESETTX
; /* reset TX */
585 if (!info
->tty
|| (info
->tty
->termios
->c_cflag
& HUPCL
))
586 mcfrs_setsignals(info
, 0, 0);
588 if (info
->xmit_buf
) {
589 free_page((unsigned long) info
->xmit_buf
);
594 set_bit(TTY_IO_ERROR
, &info
->tty
->flags
);
596 info
->flags
&= ~ASYNC_INITIALIZED
;
597 local_irq_restore(flags
);
602 * This routine is called to set the UART divisor registers to match
603 * the specified baud rate for a serial port.
605 static void mcfrs_change_speed(struct mcf_serial
*info
)
607 volatile unsigned char *uartp
;
608 unsigned int baudclk
, cflag
;
610 unsigned char mr1
, mr2
;
613 unsigned int fraction
;
616 if (!info
->tty
|| !info
->tty
->termios
)
618 cflag
= info
->tty
->termios
->c_cflag
;
623 printk("%s(%d): mcfrs_change_speed()\n", __FILE__
, __LINE__
);
630 info
->tty
->termios
->c_cflag
&= ~CBAUDEX
;
635 mcfrs_setsignals(info
, 0, -1);
639 /* compute the baudrate clock */
642 * For the MCF5272, also compute the baudrate fraction.
644 baudclk
= (MCF_BUSCLK
/ mcfrs_baud_table
[i
]) / 32;
645 fraction
= MCF_BUSCLK
- (baudclk
* 32 * mcfrs_baud_table
[i
]);
647 fraction
/= (32 * mcfrs_baud_table
[i
]);
649 baudclk
= ((MCF_BUSCLK
/ mcfrs_baud_table
[i
]) + 16) / 32;
652 info
->baud
= mcfrs_baud_table
[i
];
654 mr1
= MCFUART_MR1_RXIRQRDY
| MCFUART_MR1_RXERRCHAR
;
657 switch (cflag
& CSIZE
) {
658 case CS5
: mr1
|= MCFUART_MR1_CS5
; break;
659 case CS6
: mr1
|= MCFUART_MR1_CS6
; break;
660 case CS7
: mr1
|= MCFUART_MR1_CS7
; break;
662 default: mr1
|= MCFUART_MR1_CS8
; break;
665 if (cflag
& PARENB
) {
666 if (cflag
& CMSPAR
) {
668 mr1
|= MCFUART_MR1_PARITYMARK
;
670 mr1
|= MCFUART_MR1_PARITYSPACE
;
673 mr1
|= MCFUART_MR1_PARITYODD
;
675 mr1
|= MCFUART_MR1_PARITYEVEN
;
678 mr1
|= MCFUART_MR1_PARITYNONE
;
682 mr2
|= MCFUART_MR2_STOP2
;
684 mr2
|= MCFUART_MR2_STOP1
;
686 if (cflag
& CRTSCTS
) {
687 mr1
|= MCFUART_MR1_RXRTS
;
688 mr2
|= MCFUART_MR2_TXCTS
;
692 info
->flags
&= ~ASYNC_CHECK_CD
;
694 info
->flags
|= ASYNC_CHECK_CD
;
698 local_irq_save(flags
);
700 printk("%s(%d): mr1=%x mr2=%x baudclk=%x\n", __FILE__
, __LINE__
,
704 Note: pg 12-16 of MCF5206e User's Manual states that a
705 software reset should be performed prior to changing
706 UMR1,2, UCSR, UACR, bit 7
708 uartp
[MCFUART_UCR
] = MCFUART_UCR_CMDRESETRX
; /* reset RX */
709 uartp
[MCFUART_UCR
] = MCFUART_UCR_CMDRESETTX
; /* reset TX */
710 uartp
[MCFUART_UCR
] = MCFUART_UCR_CMDRESETMRPTR
; /* reset MR pointer */
711 uartp
[MCFUART_UMR
] = mr1
;
712 uartp
[MCFUART_UMR
] = mr2
;
713 uartp
[MCFUART_UBG1
] = (baudclk
& 0xff00) >> 8; /* set msb byte */
714 uartp
[MCFUART_UBG2
] = (baudclk
& 0xff); /* set lsb byte */
716 uartp
[MCFUART_UFPD
] = (fraction
& 0xf); /* set fraction */
718 uartp
[MCFUART_UCSR
] = MCFUART_UCSR_RXCLKTIMER
| MCFUART_UCSR_TXCLKTIMER
;
719 uartp
[MCFUART_UCR
] = MCFUART_UCR_RXENABLE
| MCFUART_UCR_TXENABLE
;
720 mcfrs_setsignals(info
, 1, -1);
721 local_irq_restore(flags
);
725 static void mcfrs_flush_chars(struct tty_struct
*tty
)
727 volatile unsigned char *uartp
;
728 struct mcf_serial
*info
= (struct mcf_serial
*)tty
->driver_data
;
731 if (serial_paranoia_check(info
, tty
->name
, "mcfrs_flush_chars"))
734 uartp
= (volatile unsigned char *) info
->addr
;
737 * re-enable receiver interrupt
739 local_irq_save(flags
);
740 if ((!(info
->imr
& MCFUART_UIR_RXREADY
)) &&
741 (info
->flags
& ASYNC_INITIALIZED
) ) {
742 info
->imr
|= MCFUART_UIR_RXREADY
;
743 uartp
[MCFUART_UIMR
] = info
->imr
;
745 local_irq_restore(flags
);
747 if (info
->xmit_cnt
<= 0 || tty
->stopped
|| tty
->hw_stopped
||
751 /* Enable transmitter */
752 local_irq_save(flags
);
753 info
->imr
|= MCFUART_UIR_TXREADY
;
754 uartp
[MCFUART_UIMR
] = info
->imr
;
755 local_irq_restore(flags
);
758 static int mcfrs_write(struct tty_struct
* tty
, int from_user
,
759 const unsigned char *buf
, int count
)
761 volatile unsigned char *uartp
;
762 struct mcf_serial
*info
= (struct mcf_serial
*)tty
->driver_data
;
767 printk("%s(%d): mcfrs_write(tty=%x,from_user=%d,buf=%x,count=%d)\n",
768 __FILE__
, __LINE__
, (int)tty
, from_user
, (int)buf
, count
);
771 if (serial_paranoia_check(info
, tty
->name
, "mcfrs_write"))
774 if (!tty
|| !info
->xmit_buf
)
777 local_save_flags(flags
);
780 c
= min(count
, (int) min(((int)SERIAL_XMIT_SIZE
) - info
->xmit_cnt
- 1,
781 ((int)SERIAL_XMIT_SIZE
) - info
->xmit_head
));
782 local_irq_restore(flags
);
788 down(&mcfrs_tmp_buf_sem
);
789 if (copy_from_user(mcfrs_tmp_buf
, buf
, c
))
793 c
= min(c
, (int) min(((int)SERIAL_XMIT_SIZE
) - info
->xmit_cnt
- 1,
794 ((int)SERIAL_XMIT_SIZE
) - info
->xmit_head
));
795 local_irq_restore(flags
);
796 memcpy(info
->xmit_buf
+ info
->xmit_head
, mcfrs_tmp_buf
, c
);
797 up(&mcfrs_tmp_buf_sem
);
799 memcpy(info
->xmit_buf
+ info
->xmit_head
, buf
, c
);
802 info
->xmit_head
= (info
->xmit_head
+ c
) & (SERIAL_XMIT_SIZE
-1);
804 local_irq_restore(flags
);
813 info
->imr
|= MCFUART_UIR_TXREADY
;
814 uartp
[MCFUART_UIMR
] = info
->imr
;
815 local_irq_restore(flags
);
820 static int mcfrs_write_room(struct tty_struct
*tty
)
822 struct mcf_serial
*info
= (struct mcf_serial
*)tty
->driver_data
;
825 if (serial_paranoia_check(info
, tty
->name
, "mcfrs_write_room"))
827 ret
= SERIAL_XMIT_SIZE
- info
->xmit_cnt
- 1;
833 static int mcfrs_chars_in_buffer(struct tty_struct
*tty
)
835 struct mcf_serial
*info
= (struct mcf_serial
*)tty
->driver_data
;
837 if (serial_paranoia_check(info
, tty
->name
, "mcfrs_chars_in_buffer"))
839 return info
->xmit_cnt
;
842 static void mcfrs_flush_buffer(struct tty_struct
*tty
)
844 struct mcf_serial
*info
= (struct mcf_serial
*)tty
->driver_data
;
847 if (serial_paranoia_check(info
, tty
->name
, "mcfrs_flush_buffer"))
850 local_irq_save(flags
);
851 info
->xmit_cnt
= info
->xmit_head
= info
->xmit_tail
= 0;
852 local_irq_restore(flags
);
858 * ------------------------------------------------------------
861 * This routine is called by the upper-layer tty layer to signal that
862 * incoming characters should be throttled.
863 * ------------------------------------------------------------
865 static void mcfrs_throttle(struct tty_struct
* tty
)
867 struct mcf_serial
*info
= (struct mcf_serial
*)tty
->driver_data
;
868 #ifdef SERIAL_DEBUG_THROTTLE
871 printk("throttle %s: %d....\n", _tty_name(tty
, buf
),
872 tty
->ldisc
.chars_in_buffer(tty
));
875 if (serial_paranoia_check(info
, tty
->name
, "mcfrs_throttle"))
879 info
->x_char
= STOP_CHAR(tty
);
881 /* Turn off RTS line (do this atomic) */
884 static void mcfrs_unthrottle(struct tty_struct
* tty
)
886 struct mcf_serial
*info
= (struct mcf_serial
*)tty
->driver_data
;
887 #ifdef SERIAL_DEBUG_THROTTLE
890 printk("unthrottle %s: %d....\n", _tty_name(tty
, buf
),
891 tty
->ldisc
.chars_in_buffer(tty
));
894 if (serial_paranoia_check(info
, tty
->name
, "mcfrs_unthrottle"))
901 info
->x_char
= START_CHAR(tty
);
904 /* Assert RTS line (do this atomic) */
908 * ------------------------------------------------------------
909 * mcfrs_ioctl() and friends
910 * ------------------------------------------------------------
913 static int get_serial_info(struct mcf_serial
* info
,
914 struct serial_struct
* retinfo
)
916 struct serial_struct tmp
;
920 memset(&tmp
, 0, sizeof(tmp
));
921 tmp
.type
= info
->type
;
922 tmp
.line
= info
->line
;
923 tmp
.port
= (unsigned int) info
->addr
;
925 tmp
.flags
= info
->flags
;
926 tmp
.baud_base
= info
->baud_base
;
927 tmp
.close_delay
= info
->close_delay
;
928 tmp
.closing_wait
= info
->closing_wait
;
929 tmp
.custom_divisor
= info
->custom_divisor
;
930 return copy_to_user(retinfo
,&tmp
,sizeof(*retinfo
)) ? -EFAULT
: 0;
933 static int set_serial_info(struct mcf_serial
* info
,
934 struct serial_struct
* new_info
)
936 struct serial_struct new_serial
;
937 struct mcf_serial old_info
;
942 if (copy_from_user(&new_serial
,new_info
,sizeof(new_serial
)))
946 if (!capable(CAP_SYS_ADMIN
)) {
947 if ((new_serial
.baud_base
!= info
->baud_base
) ||
948 (new_serial
.type
!= info
->type
) ||
949 (new_serial
.close_delay
!= info
->close_delay
) ||
950 ((new_serial
.flags
& ~ASYNC_USR_MASK
) !=
951 (info
->flags
& ~ASYNC_USR_MASK
)))
953 info
->flags
= ((info
->flags
& ~ASYNC_USR_MASK
) |
954 (new_serial
.flags
& ASYNC_USR_MASK
));
955 info
->custom_divisor
= new_serial
.custom_divisor
;
963 * OK, past this point, all the error checking has been done.
964 * At this point, we start making changes.....
967 info
->baud_base
= new_serial
.baud_base
;
968 info
->flags
= ((info
->flags
& ~ASYNC_FLAGS
) |
969 (new_serial
.flags
& ASYNC_FLAGS
));
970 info
->type
= new_serial
.type
;
971 info
->close_delay
= new_serial
.close_delay
;
972 info
->closing_wait
= new_serial
.closing_wait
;
975 retval
= startup(info
);
980 * get_lsr_info - get line status register info
982 * Purpose: Let user call ioctl() to get info when the UART physically
983 * is emptied. On bus types like RS485, the transmitter must
984 * release the bus after transmitting. This must be done when
985 * the transmit shift register is empty, not be done when the
986 * transmit holding register is empty. This functionality
987 * allows an RS485 driver to be written in user space.
989 static int get_lsr_info(struct mcf_serial
* info
, unsigned int *value
)
991 volatile unsigned char *uartp
;
993 unsigned char status
;
995 local_irq_save(flags
);
997 status
= (uartp
[MCFUART_USR
] & MCFUART_USR_TXEMPTY
) ? TIOCSER_TEMT
: 0;
998 local_irq_restore(flags
);
1000 return put_user(status
,value
);
1004 * This routine sends a break character out the serial port.
1006 static void send_break( struct mcf_serial
* info
, int duration
)
1008 volatile unsigned char *uartp
;
1009 unsigned long flags
;
1013 current
->state
= TASK_INTERRUPTIBLE
;
1016 local_irq_save(flags
);
1017 uartp
[MCFUART_UCR
] = MCFUART_UCR_CMDBREAKSTART
;
1018 schedule_timeout(duration
);
1019 uartp
[MCFUART_UCR
] = MCFUART_UCR_CMDBREAKSTOP
;
1020 local_irq_restore(flags
);
1023 static int mcfrs_tiocmget(struct tty_struct
*tty
, struct file
*file
)
1025 struct mcf_serial
* info
= (struct mcf_serial
*)tty
->driver_data
;
1027 if (serial_paranoia_check(info
, tty
->name
, "mcfrs_ioctl"))
1029 if (tty
->flags
& (1 << TTY_IO_ERROR
))
1032 return mcfrs_getsignals(info
);
1035 static int mcfrs_tiocmset(struct tty_struct
*tty
, struct file
*file
,
1036 unsigned int set
, unsigned int clear
)
1038 struct mcf_serial
* info
= (struct mcf_serial
*)tty
->driver_data
;
1039 int rts
= -1, dtr
= -1;
1041 if (serial_paranoia_check(info
, tty
->name
, "mcfrs_ioctl"))
1043 if (tty
->flags
& (1 << TTY_IO_ERROR
))
1046 if (set
& TIOCM_RTS
)
1048 if (set
& TIOCM_DTR
)
1050 if (clear
& TIOCM_RTS
)
1052 if (clear
& TIOCM_DTR
)
1055 mcfrs_setsignals(info
, dtr
, rts
);
1060 static int mcfrs_ioctl(struct tty_struct
*tty
, struct file
* file
,
1061 unsigned int cmd
, unsigned long arg
)
1063 struct mcf_serial
* info
= (struct mcf_serial
*)tty
->driver_data
;
1066 if (serial_paranoia_check(info
, tty
->name
, "mcfrs_ioctl"))
1069 if ((cmd
!= TIOCGSERIAL
) && (cmd
!= TIOCSSERIAL
) &&
1070 (cmd
!= TIOCSERCONFIG
) && (cmd
!= TIOCSERGWILD
) &&
1071 (cmd
!= TIOCSERSWILD
) && (cmd
!= TIOCSERGSTRUCT
)) {
1072 if (tty
->flags
& (1 << TTY_IO_ERROR
))
1077 case TCSBRK
: /* SVID version: non-zero arg --> no break */
1078 retval
= tty_check_change(tty
);
1081 tty_wait_until_sent(tty
, 0);
1083 send_break(info
, HZ
/4); /* 1/4 second */
1085 case TCSBRKP
: /* support for POSIX tcsendbreak() */
1086 retval
= tty_check_change(tty
);
1089 tty_wait_until_sent(tty
, 0);
1090 send_break(info
, arg
? arg
*(HZ
/10) : HZ
/4);
1093 error
= put_user(C_CLOCAL(tty
) ? 1 : 0,
1094 (unsigned long *) arg
);
1099 get_user(arg
, (unsigned long *) arg
);
1100 tty
->termios
->c_cflag
=
1101 ((tty
->termios
->c_cflag
& ~CLOCAL
) |
1102 (arg
? CLOCAL
: 0));
1105 error
= verify_area(VERIFY_WRITE
, (void *) arg
,
1106 sizeof(struct serial_struct
));
1109 return get_serial_info(info
,
1110 (struct serial_struct
*) arg
);
1112 return set_serial_info(info
,
1113 (struct serial_struct
*) arg
);
1114 case TIOCSERGETLSR
: /* Get line status register */
1115 error
= verify_area(VERIFY_WRITE
, (void *) arg
,
1116 sizeof(unsigned int));
1120 return get_lsr_info(info
, (unsigned int *) arg
);
1122 case TIOCSERGSTRUCT
:
1123 error
= copy_to_user((struct mcf_serial
*) arg
,
1124 info
, sizeof(struct mcf_serial
));
1132 get_user(val
, (unsigned int *) arg
);
1133 mcf_setpa(MCFPP_PA11
, (val
? 0 : MCFPP_PA11
));
1138 val
= (mcf_getpa() & MCFPP_PA11
) ? 0 : 1;
1139 put_user(val
, (unsigned int *) arg
);
1145 return -ENOIOCTLCMD
;
1150 static void mcfrs_set_termios(struct tty_struct
*tty
, struct termios
*old_termios
)
1152 struct mcf_serial
*info
= (struct mcf_serial
*)tty
->driver_data
;
1154 if (tty
->termios
->c_cflag
== old_termios
->c_cflag
)
1157 mcfrs_change_speed(info
);
1159 if ((old_termios
->c_cflag
& CRTSCTS
) &&
1160 !(tty
->termios
->c_cflag
& CRTSCTS
)) {
1161 tty
->hw_stopped
= 0;
1162 mcfrs_setsignals(info
, -1, 1);
1170 * ------------------------------------------------------------
1173 * This routine is called when the serial port gets closed. First, we
1174 * wait for the last remaining data to be sent. Then, we unlink its
1175 * S structure from the interrupt chain if necessary, and we free
1176 * that IRQ if nothing is left in the chain.
1177 * ------------------------------------------------------------
1179 static void mcfrs_close(struct tty_struct
*tty
, struct file
* filp
)
1181 volatile unsigned char *uartp
;
1182 struct mcf_serial
*info
= (struct mcf_serial
*)tty
->driver_data
;
1183 unsigned long flags
;
1185 if (!info
|| serial_paranoia_check(info
, tty
->name
, "mcfrs_close"))
1188 local_irq_save(flags
);
1190 if (tty_hung_up_p(filp
)) {
1191 local_irq_restore(flags
);
1195 #ifdef SERIAL_DEBUG_OPEN
1196 printk("mcfrs_close ttyS%d, count = %d\n", info
->line
, info
->count
);
1198 if ((tty
->count
== 1) && (info
->count
!= 1)) {
1200 * Uh, oh. tty->count is 1, which means that the tty
1201 * structure will be freed. Info->count should always
1202 * be one in these conditions. If it's greater than
1203 * one, we've got real problems, since it means the
1204 * serial port won't be shutdown.
1206 printk("MCFRS: bad serial port count; tty->count is 1, "
1207 "info->count is %d\n", info
->count
);
1210 if (--info
->count
< 0) {
1211 printk("MCFRS: bad serial port count for ttyS%d: %d\n",
1212 info
->line
, info
->count
);
1216 local_irq_restore(flags
);
1219 info
->flags
|= ASYNC_CLOSING
;
1222 * Now we wait for the transmit buffer to clear; and we notify
1223 * the line discipline to only process XON/XOFF characters.
1226 if (info
->closing_wait
!= ASYNC_CLOSING_WAIT_NONE
)
1227 tty_wait_until_sent(tty
, info
->closing_wait
);
1230 * At this point we stop accepting input. To do this, we
1231 * disable the receive line status interrupts, and tell the
1232 * interrupt driver to stop checking the data ready bit in the
1233 * line status register.
1235 info
->imr
&= ~MCFUART_UIR_RXREADY
;
1237 uartp
[MCFUART_UIMR
] = info
->imr
;
1240 /* FIXME: do we need to keep this enabled for console?? */
1241 if (mcfrs_console_inited
&& (mcfrs_console_port
== info
->line
)) {
1242 /* Do not disable the UART */ ;
1246 if (tty
->driver
->flush_buffer
)
1247 tty
->driver
->flush_buffer(tty
);
1248 tty_ldisc_flush(tty
);
1254 if (tty
->ldisc
.num
!= ldiscs
[N_TTY
].num
) {
1255 if (tty
->ldisc
.close
)
1256 (tty
->ldisc
.close
)(tty
);
1257 tty
->ldisc
= ldiscs
[N_TTY
];
1258 tty
->termios
->c_line
= N_TTY
;
1259 if (tty
->ldisc
.open
)
1260 (tty
->ldisc
.open
)(tty
);
1263 if (info
->blocked_open
) {
1264 if (info
->close_delay
) {
1265 current
->state
= TASK_INTERRUPTIBLE
;
1266 schedule_timeout(info
->close_delay
);
1268 wake_up_interruptible(&info
->open_wait
);
1270 info
->flags
&= ~(ASYNC_NORMAL_ACTIVE
|ASYNC_CLOSING
);
1271 wake_up_interruptible(&info
->close_wait
);
1272 local_irq_restore(flags
);
1276 * mcfrs_wait_until_sent() --- wait until the transmitter is empty
1279 mcfrs_wait_until_sent(struct tty_struct
*tty
, int timeout
)
1282 #define MCF5272_FIFO_SIZE 25 /* fifo size + shift reg */
1284 struct mcf_serial
* info
= (struct mcf_serial
*)tty
->driver_data
;
1285 volatile unsigned char *uartp
;
1286 unsigned long orig_jiffies
, fifo_time
, char_time
, fifo_cnt
;
1288 if (serial_paranoia_check(info
, tty
->name
, "mcfrs_wait_until_sent"))
1291 orig_jiffies
= jiffies
;
1294 * Set the check interval to be 1/5 of the approximate time
1295 * to send the entire fifo, and make it at least 1. The check
1296 * interval should also be less than the timeout.
1298 * Note: we have to use pretty tight timings here to satisfy
1301 fifo_time
= (MCF5272_FIFO_SIZE
* HZ
* 10) / info
->baud
;
1302 char_time
= fifo_time
/ 5;
1305 if (timeout
&& timeout
< char_time
)
1306 char_time
= timeout
;
1309 * Clamp the timeout period at 2 * the time to empty the
1310 * fifo. Just to be safe, set the minimum at .5 seconds.
1313 if (fifo_time
< (HZ
/2))
1315 if (!timeout
|| timeout
> fifo_time
)
1316 timeout
= fifo_time
;
1319 * Account for the number of bytes in the UART
1320 * transmitter FIFO plus any byte being shifted out.
1322 uartp
= (volatile unsigned char *) info
->addr
;
1324 fifo_cnt
= (uartp
[MCFUART_UTF
] & MCFUART_UTF_TXB
);
1325 if ((uartp
[MCFUART_USR
] & (MCFUART_USR_TXREADY
|
1326 MCFUART_USR_TXEMPTY
)) ==
1327 MCFUART_USR_TXREADY
)
1331 set_current_state(TASK_INTERRUPTIBLE
);
1332 schedule_timeout(char_time
);
1333 if (signal_pending(current
))
1335 if (timeout
&& time_after(jiffies
, orig_jiffies
+ timeout
))
1340 * For the other coldfire models, assume all data has been sent
1346 * mcfrs_hangup() --- called by tty_hangup() when a hangup is signaled.
1348 void mcfrs_hangup(struct tty_struct
*tty
)
1350 struct mcf_serial
* info
= (struct mcf_serial
*)tty
->driver_data
;
1352 if (serial_paranoia_check(info
, tty
->name
, "mcfrs_hangup"))
1355 mcfrs_flush_buffer(tty
);
1359 info
->flags
&= ~ASYNC_NORMAL_ACTIVE
;
1361 wake_up_interruptible(&info
->open_wait
);
1365 * ------------------------------------------------------------
1366 * mcfrs_open() and friends
1367 * ------------------------------------------------------------
1369 static int block_til_ready(struct tty_struct
*tty
, struct file
* filp
,
1370 struct mcf_serial
*info
)
1372 DECLARE_WAITQUEUE(wait
, current
);
1377 * If the device is in the middle of being closed, then block
1378 * until it's done, and then try again.
1380 if (info
->flags
& ASYNC_CLOSING
) {
1381 interruptible_sleep_on(&info
->close_wait
);
1382 #ifdef SERIAL_DO_RESTART
1383 if (info
->flags
& ASYNC_HUP_NOTIFY
)
1386 return -ERESTARTSYS
;
1393 * If non-blocking mode is set, or the port is not enabled,
1394 * then make the check up front and then exit.
1396 if ((filp
->f_flags
& O_NONBLOCK
) ||
1397 (tty
->flags
& (1 << TTY_IO_ERROR
))) {
1398 info
->flags
|= ASYNC_NORMAL_ACTIVE
;
1402 if (tty
->termios
->c_cflag
& CLOCAL
)
1406 * Block waiting for the carrier detect and the line to become
1407 * free (i.e., not in use by the callout). While we are in
1408 * this loop, info->count is dropped by one, so that
1409 * mcfrs_close() knows when to free things. We restore it upon
1410 * exit, either normal or abnormal.
1413 add_wait_queue(&info
->open_wait
, &wait
);
1414 #ifdef SERIAL_DEBUG_OPEN
1415 printk("block_til_ready before block: ttyS%d, count = %d\n",
1416 info
->line
, info
->count
);
1419 info
->blocked_open
++;
1421 local_irq_disable();
1422 mcfrs_setsignals(info
, 1, 1);
1424 current
->state
= TASK_INTERRUPTIBLE
;
1425 if (tty_hung_up_p(filp
) ||
1426 !(info
->flags
& ASYNC_INITIALIZED
)) {
1427 #ifdef SERIAL_DO_RESTART
1428 if (info
->flags
& ASYNC_HUP_NOTIFY
)
1431 retval
= -ERESTARTSYS
;
1437 if (!(info
->flags
& ASYNC_CLOSING
) &&
1438 (do_clocal
|| (mcfrs_getsignals(info
) & TIOCM_CD
)))
1440 if (signal_pending(current
)) {
1441 retval
= -ERESTARTSYS
;
1444 #ifdef SERIAL_DEBUG_OPEN
1445 printk("block_til_ready blocking: ttyS%d, count = %d\n",
1446 info
->line
, info
->count
);
1450 current
->state
= TASK_RUNNING
;
1451 remove_wait_queue(&info
->open_wait
, &wait
);
1452 if (!tty_hung_up_p(filp
))
1454 info
->blocked_open
--;
1455 #ifdef SERIAL_DEBUG_OPEN
1456 printk("block_til_ready after blocking: ttyS%d, count = %d\n",
1457 info
->line
, info
->count
);
1461 info
->flags
|= ASYNC_NORMAL_ACTIVE
;
1466 * This routine is called whenever a serial port is opened. It
1467 * enables interrupts for a serial port, linking in its structure into
1468 * the IRQ chain. It also performs the serial-specific
1469 * initialization for the tty structure.
1471 int mcfrs_open(struct tty_struct
*tty
, struct file
* filp
)
1473 struct mcf_serial
*info
;
1477 if ((line
< 0) || (line
>= NR_PORTS
))
1479 info
= mcfrs_table
+ line
;
1480 if (serial_paranoia_check(info
, tty
->name
, "mcfrs_open"))
1482 #ifdef SERIAL_DEBUG_OPEN
1483 printk("mcfrs_open %s, count = %d\n", tty
->name
, info
->count
);
1486 tty
->driver_data
= info
;
1490 * Start up serial port
1492 retval
= startup(info
);
1496 retval
= block_til_ready(tty
, filp
, info
);
1498 #ifdef SERIAL_DEBUG_OPEN
1499 printk("mcfrs_open returning after block_til_ready with %d\n",
1505 #ifdef SERIAL_DEBUG_OPEN
1506 printk("mcfrs_open %s successful...\n", tty
->name
);
1512 * Based on the line number set up the internal interrupt stuff.
1514 static void mcfrs_irqinit(struct mcf_serial
*info
)
1516 #if defined(CONFIG_M5272)
1517 volatile unsigned long *icrp
;
1518 volatile unsigned long *portp
;
1519 volatile unsigned char *uartp
;
1522 icrp
= (volatile unsigned long *) (MCF_MBAR
+ MCFSIM_ICR2
);
1524 switch (info
->line
) {
1532 printk("MCFRS: don't know how to handle UART %d interrupt?\n",
1537 /* Enable the output lines for the serial ports */
1538 portp
= (volatile unsigned long *) (MCF_MBAR
+ MCFSIM_PBCNT
);
1539 *portp
= (*portp
& ~0x000000ff) | 0x00000055;
1540 portp
= (volatile unsigned long *) (MCF_MBAR
+ MCFSIM_PDCNT
);
1541 *portp
= (*portp
& ~0x000003fc) | 0x000002a8;
1542 #elif defined(CONFIG_M527x) || defined(CONFIG_M528x)
1543 volatile unsigned char *icrp
, *uartp
;
1544 volatile unsigned long *imrp
;
1548 icrp
= (volatile unsigned char *) (MCF_MBAR
+ MCFICM_INTC0
+
1549 MCFINTC_ICR0
+ MCFINT_UART0
+ info
->line
);
1550 *icrp
= 0x33; /* UART0 with level 6, priority 3 */
1552 imrp
= (volatile unsigned long *) (MCF_MBAR
+ MCFICM_INTC0
+
1554 *imrp
&= ~((1 << (info
->irq
- MCFINT_VECBASE
)) | 1);
1556 volatile unsigned char *icrp
, *uartp
;
1558 switch (info
->line
) {
1560 icrp
= (volatile unsigned char *) (MCF_MBAR
+ MCFSIM_UART1ICR
);
1561 *icrp
= /*MCFSIM_ICR_AUTOVEC |*/ MCFSIM_ICR_LEVEL6
|
1563 mcf_setimr(mcf_getimr() & ~MCFSIM_IMR_UART1
);
1566 icrp
= (volatile unsigned char *) (MCF_MBAR
+ MCFSIM_UART2ICR
);
1567 *icrp
= /*MCFSIM_ICR_AUTOVEC |*/ MCFSIM_ICR_LEVEL6
|
1569 mcf_setimr(mcf_getimr() & ~MCFSIM_IMR_UART2
);
1572 printk("MCFRS: don't know how to handle UART %d interrupt?\n",
1578 uartp
[MCFUART_UIVR
] = info
->irq
;
1581 /* Clear mask, so no surprise interrupts. */
1582 uartp
[MCFUART_UIMR
] = 0;
1584 if (request_irq(info
->irq
, mcfrs_interrupt
, SA_INTERRUPT
,
1585 "ColdFire UART", NULL
)) {
1586 printk("MCFRS: Unable to attach ColdFire UART %d interrupt "
1587 "vector=%d\n", info
->line
, info
->irq
);
1594 char *mcfrs_drivername
= "ColdFire internal UART serial driver version 1.00\n";
1598 * Serial stats reporting...
1600 int mcfrs_readproc(char *page
, char **start
, off_t off
, int count
,
1601 int *eof
, void *data
)
1603 struct mcf_serial
*info
;
1607 len
= sprintf(page
, mcfrs_drivername
);
1608 for (i
= 0; (i
< NR_PORTS
); i
++) {
1609 info
= &mcfrs_table
[i
];
1610 len
+= sprintf((page
+ len
), "%d: port:%x irq=%d baud:%d ",
1611 i
, (unsigned int) info
->addr
, info
->irq
, info
->baud
);
1612 if (info
->stats
.rx
|| info
->stats
.tx
)
1613 len
+= sprintf((page
+ len
), "tx:%d rx:%d ",
1614 info
->stats
.tx
, info
->stats
.rx
);
1615 if (info
->stats
.rxframing
)
1616 len
+= sprintf((page
+ len
), "fe:%d ",
1617 info
->stats
.rxframing
);
1618 if (info
->stats
.rxparity
)
1619 len
+= sprintf((page
+ len
), "pe:%d ",
1620 info
->stats
.rxparity
);
1621 if (info
->stats
.rxbreak
)
1622 len
+= sprintf((page
+ len
), "brk:%d ",
1623 info
->stats
.rxbreak
);
1624 if (info
->stats
.rxoverrun
)
1625 len
+= sprintf((page
+ len
), "oe:%d ",
1626 info
->stats
.rxoverrun
);
1628 str
[0] = str
[1] = 0;
1629 if ((sigs
= mcfrs_getsignals(info
))) {
1630 if (sigs
& TIOCM_RTS
)
1631 strcat(str
, "|RTS");
1632 if (sigs
& TIOCM_CTS
)
1633 strcat(str
, "|CTS");
1634 if (sigs
& TIOCM_DTR
)
1635 strcat(str
, "|DTR");
1636 if (sigs
& TIOCM_CD
)
1640 len
+= sprintf((page
+ len
), "%s\n", &str
[1]);
1647 /* Finally, routines used to initialize the serial driver. */
1649 static void show_serial_version(void)
1651 printk(mcfrs_drivername
);
1654 static struct tty_operations mcfrs_ops
= {
1656 .close
= mcfrs_close
,
1657 .write
= mcfrs_write
,
1658 .flush_chars
= mcfrs_flush_chars
,
1659 .write_room
= mcfrs_write_room
,
1660 .chars_in_buffer
= mcfrs_chars_in_buffer
,
1661 .flush_buffer
= mcfrs_flush_buffer
,
1662 .ioctl
= mcfrs_ioctl
,
1663 .throttle
= mcfrs_throttle
,
1664 .unthrottle
= mcfrs_unthrottle
,
1665 .set_termios
= mcfrs_set_termios
,
1667 .start
= mcfrs_start
,
1668 .hangup
= mcfrs_hangup
,
1669 .read_proc
= mcfrs_readproc
,
1670 .wait_until_sent
= mcfrs_wait_until_sent
,
1671 .tiocmget
= mcfrs_tiocmget
,
1672 .tiocmset
= mcfrs_tiocmset
,
1675 /* mcfrs_init inits the driver */
1679 struct mcf_serial
*info
;
1680 unsigned long flags
;
1683 /* Setup base handler, and timer table. */
1685 init_timer(&mcfrs_timer_struct
);
1686 mcfrs_timer_struct
.function
= mcfrs_timer
;
1687 mcfrs_timer_struct
.data
= 0;
1688 mcfrs_timer_struct
.expires
= jiffies
+ HZ
/25;
1689 add_timer(&mcfrs_timer_struct
);
1690 mcfrs_ppstatus
= mcf_getppdata() & (MCFPP_DCD0
| MCFPP_DCD1
);
1692 mcfrs_serial_driver
= alloc_tty_driver(NR_PORTS
);
1693 if (!mcfrs_serial_driver
)
1696 show_serial_version();
1698 /* Initialize the tty_driver structure */
1699 mcfrs_serial_driver
->owner
= THIS_MODULE
;
1700 mcfrs_serial_driver
->name
= "ttyS";
1701 mcfrs_serial_driver
->devfs_name
= "ttys/";
1702 mcfrs_serial_driver
->driver_name
= "serial";
1703 mcfrs_serial_driver
->major
= TTY_MAJOR
;
1704 mcfrs_serial_driver
->minor_start
= 64;
1705 mcfrs_serial_driver
->type
= TTY_DRIVER_TYPE_SERIAL
;
1706 mcfrs_serial_driver
->subtype
= SERIAL_TYPE_NORMAL
;
1707 mcfrs_serial_driver
->init_termios
= tty_std_termios
;
1709 mcfrs_serial_driver
->init_termios
.c_cflag
=
1710 mcfrs_console_cbaud
| CS8
| CREAD
| HUPCL
| CLOCAL
;
1711 mcfrs_serial_driver
->flags
= TTY_DRIVER_REAL_RAW
;
1713 tty_set_operations(mcfrs_serial_driver
, &mcfrs_ops
);
1715 if (tty_register_driver(mcfrs_serial_driver
)) {
1716 printk("MCFRS: Couldn't register serial driver\n");
1717 put_tty_driver(mcfrs_serial_driver
);
1721 local_irq_save(flags
);
1724 * Configure all the attached serial ports.
1726 for (i
= 0, info
= mcfrs_table
; (i
< NR_PORTS
); i
++, info
++) {
1727 info
->magic
= SERIAL_MAGIC
;
1730 info
->custom_divisor
= 16;
1731 info
->close_delay
= 50;
1732 info
->closing_wait
= 3000;
1736 info
->blocked_open
= 0;
1737 INIT_WORK(&info
->tqueue
, mcfrs_offintr
, info
);
1738 INIT_WORK(&info
->tqueue_hangup
, do_serial_hangup
, info
);
1739 init_waitqueue_head(&info
->open_wait
);
1740 init_waitqueue_head(&info
->close_wait
);
1743 mcfrs_setsignals(info
, 0, 0);
1744 mcfrs_irqinit(info
);
1746 printk("ttyS%d at 0x%04x (irq = %d)", info
->line
,
1747 (unsigned int) info
->addr
, info
->irq
);
1748 printk(" is a builtin ColdFire UART\n");
1751 local_irq_restore(flags
);
1755 module_init(mcfrs_init
);
1757 /****************************************************************************/
1758 /* Serial Console */
1759 /****************************************************************************/
1762 * Quick and dirty UART initialization, for console output.
1765 void mcfrs_init_console(void)
1767 volatile unsigned char *uartp
;
1771 * Reset UART, get it into known state...
1773 uartp
= (volatile unsigned char *) (MCF_MBAR
+
1774 (mcfrs_console_port
? MCFUART_BASE2
: MCFUART_BASE1
));
1776 uartp
[MCFUART_UCR
] = MCFUART_UCR_CMDRESETRX
; /* reset RX */
1777 uartp
[MCFUART_UCR
] = MCFUART_UCR_CMDRESETTX
; /* reset TX */
1778 uartp
[MCFUART_UCR
] = MCFUART_UCR_CMDRESETMRPTR
; /* reset MR pointer */
1781 * Set port for defined baud , 8 data bits, 1 stop bit, no parity.
1783 uartp
[MCFUART_UMR
] = MCFUART_MR1_PARITYNONE
| MCFUART_MR1_CS8
;
1784 uartp
[MCFUART_UMR
] = MCFUART_MR2_STOP1
;
1786 clk
= ((MCF_BUSCLK
/ mcfrs_console_baud
) + 16) / 32; /* set baud */
1787 uartp
[MCFUART_UBG1
] = (clk
& 0xff00) >> 8; /* set msb baud */
1788 uartp
[MCFUART_UBG2
] = (clk
& 0xff); /* set lsb baud */
1790 uartp
[MCFUART_UCSR
] = MCFUART_UCSR_RXCLKTIMER
| MCFUART_UCSR_TXCLKTIMER
;
1791 uartp
[MCFUART_UCR
] = MCFUART_UCR_RXENABLE
| MCFUART_UCR_TXENABLE
;
1793 mcfrs_console_inited
++;
1799 * Setup for console. Argument comes from the boot command line.
1802 int mcfrs_console_setup(struct console
*cp
, char *arg
)
1804 int i
, n
= CONSOLE_BAUD_RATE
;
1809 if (!strncmp(cp
->name
, "ttyS", 4))
1810 mcfrs_console_port
= cp
->index
;
1811 else if (!strncmp(cp
->name
, "cua", 3))
1812 mcfrs_console_port
= cp
->index
;
1817 n
= simple_strtoul(arg
,NULL
,0);
1818 for (i
= 0; i
< MCFRS_BAUD_TABLE_SIZE
; i
++)
1819 if (mcfrs_baud_table
[i
] == n
)
1821 if (i
< MCFRS_BAUD_TABLE_SIZE
) {
1822 mcfrs_console_baud
= n
;
1823 mcfrs_console_cbaud
= 0;
1825 mcfrs_console_cbaud
|= CBAUDEX
;
1828 mcfrs_console_cbaud
|= i
;
1830 mcfrs_init_console(); /* make sure baud rate changes */
1835 static struct tty_driver
*mcfrs_console_device(struct console
*c
, int *index
)
1838 return mcfrs_serial_driver
;
1843 * Output a single character, using UART polled mode.
1844 * This is used for console output.
1847 void mcfrs_put_char(char ch
)
1849 volatile unsigned char *uartp
;
1850 unsigned long flags
;
1853 uartp
= (volatile unsigned char *) (MCF_MBAR
+
1854 (mcfrs_console_port
? MCFUART_BASE2
: MCFUART_BASE1
));
1856 local_irq_save(flags
);
1857 for (i
= 0; (i
< 0x10000); i
++) {
1858 if (uartp
[MCFUART_USR
] & MCFUART_USR_TXREADY
)
1862 uartp
[MCFUART_UTB
] = ch
;
1863 for (i
= 0; (i
< 0x10000); i
++)
1864 if (uartp
[MCFUART_USR
] & MCFUART_USR_TXEMPTY
)
1868 mcfrs_init_console(); /* try and get it back */
1869 local_irq_restore(flags
);
1876 * rs_console_write is registered for printk output.
1879 void mcfrs_console_write(struct console
*cp
, const char *p
, unsigned len
)
1881 if (!mcfrs_console_inited
)
1882 mcfrs_init_console();
1885 mcfrs_put_char('\r');
1886 mcfrs_put_char(*p
++);
1891 * declare our consoles
1894 struct console mcfrs_console
= {
1896 .write
= mcfrs_console_write
,
1897 .device
= mcfrs_console_device
,
1898 .setup
= mcfrs_console_setup
,
1899 .flags
= CON_PRINTBUFFER
,
1903 static int __init
mcfrs_console_init(void)
1905 register_console(&mcfrs_console
);
1909 console_initcall(mcfrs_console_init
);
1911 /****************************************************************************/