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>
37 #include <linux/bitops.h>
38 #include <linux/delay.h>
42 #include <asm/system.h>
43 #include <asm/segment.h>
44 #include <asm/semaphore.h>
45 #include <asm/delay.h>
46 #include <asm/coldfire.h>
47 #include <asm/mcfsim.h>
48 #include <asm/mcfuart.h>
49 #include <asm/nettel.h>
50 #include <asm/uaccess.h>
51 #include "mcfserial.h"
53 struct timer_list mcfrs_timer_struct
;
56 * Default console baud rate, we use this as the default
57 * for all ports so init can just open /dev/console and
58 * keep going. Perhaps one day the cflag settings for the
59 * console can be used instead.
61 #if defined(CONFIG_ARNEWSH) || defined(CONFIG_MOTOROLA) || defined(CONFIG_senTec) || defined(CONFIG_SNEHA)
62 #define CONSOLE_BAUD_RATE 19200
63 #define DEFAULT_CBAUD B19200
66 #if defined(CONFIG_HW_FEITH)
67 #define CONSOLE_BAUD_RATE 38400
68 #define DEFAULT_CBAUD B38400
71 #ifndef CONSOLE_BAUD_RATE
72 #define CONSOLE_BAUD_RATE 9600
73 #define DEFAULT_CBAUD B9600
76 int mcfrs_console_inited
= 0;
77 int mcfrs_console_port
= -1;
78 int mcfrs_console_baud
= CONSOLE_BAUD_RATE
;
79 int mcfrs_console_cbaud
= DEFAULT_CBAUD
;
82 * Driver data structures.
84 static struct tty_driver
*mcfrs_serial_driver
;
86 /* number of characters left in xmit buffer before we ask for more */
87 #define WAKEUP_CHARS 256
91 #undef SERIAL_DEBUG_OPEN
92 #undef SERIAL_DEBUG_FLOW
94 #if defined(CONFIG_M527x) || defined(CONFIG_M528x)
95 #define IRQBASE (MCFINT_VECBASE+MCFINT_UART0)
101 * Configuration table, UARTs to look for at startup.
103 static struct mcf_serial mcfrs_table
[] = {
106 .addr
= (volatile unsigned char *) (MCF_MBAR
+MCFUART_BASE1
),
108 .flags
= ASYNC_BOOT_AUTOCONF
,
112 .addr
= (volatile unsigned char *) (MCF_MBAR
+MCFUART_BASE2
),
114 .flags
= ASYNC_BOOT_AUTOCONF
,
119 #define NR_PORTS (sizeof(mcfrs_table) / sizeof(struct mcf_serial))
122 * This is used to figure out the divisor speeds and the timeouts.
124 static int mcfrs_baud_table
[] = {
125 0, 50, 75, 110, 134, 150, 200, 300, 600, 1200, 1800, 2400, 4800,
126 9600, 19200, 38400, 57600, 115200, 230400, 460800, 0
128 #define MCFRS_BAUD_TABLE_SIZE \
129 (sizeof(mcfrs_baud_table)/sizeof(mcfrs_baud_table[0]))
132 #ifdef CONFIG_MAGIC_SYSRQ
134 * Magic system request keys. Used for debugging...
136 extern int magic_sysrq_key(int ch
);
141 * Forware declarations...
143 static void mcfrs_change_speed(struct mcf_serial
*info
);
144 static void mcfrs_wait_until_sent(struct tty_struct
*tty
, int timeout
);
147 static inline int serial_paranoia_check(struct mcf_serial
*info
,
148 char *name
, const char *routine
)
150 #ifdef SERIAL_PARANOIA_CHECK
151 static const char badmagic
[] =
152 "MCFRS(warning): bad magic number for serial struct %s in %s\n";
153 static const char badinfo
[] =
154 "MCFRS(warning): null mcf_serial for %s in %s\n";
157 printk(badinfo
, name
, routine
);
160 if (info
->magic
!= SERIAL_MAGIC
) {
161 printk(badmagic
, name
, routine
);
169 * Sets or clears DTR and RTS on the requested line.
171 static void mcfrs_setsignals(struct mcf_serial
*info
, int dtr
, int rts
)
173 volatile unsigned char *uartp
;
177 printk("%s(%d): mcfrs_setsignals(info=%x,dtr=%d,rts=%d)\n",
178 __FILE__
, __LINE__
, info
, dtr
, rts
);
181 local_irq_save(flags
);
185 mcf_setppdata(MCFPP_DTR1
, (dtr
? 0 : MCFPP_DTR1
));
187 mcf_setppdata(MCFPP_DTR0
, (dtr
? 0 : MCFPP_DTR0
));
193 info
->sigs
|= TIOCM_RTS
;
194 uartp
[MCFUART_UOP1
] = MCFUART_UOP_RTS
;
196 info
->sigs
&= ~TIOCM_RTS
;
197 uartp
[MCFUART_UOP0
] = MCFUART_UOP_RTS
;
200 local_irq_restore(flags
);
205 * Gets values of serial signals.
207 static int mcfrs_getsignals(struct mcf_serial
*info
)
209 volatile unsigned char *uartp
;
212 #if defined(CONFIG_NETtel) && defined(CONFIG_M5307)
213 unsigned short ppdata
;
217 printk("%s(%d): mcfrs_getsignals(info=%x)\n", __FILE__
, __LINE__
);
220 local_irq_save(flags
);
222 sigs
= (uartp
[MCFUART_UIPR
] & MCFUART_UIPR_CTS
) ? 0 : TIOCM_CTS
;
223 sigs
|= (info
->sigs
& TIOCM_RTS
);
228 ppdata
= mcf_getppdata();
229 if (info
->line
== 0) {
230 sigs
|= (ppdata
& MCFPP_DCD0
) ? 0 : TIOCM_CD
;
231 sigs
|= (ppdata
& MCFPP_DTR0
) ? 0 : TIOCM_DTR
;
232 } else if (info
->line
== 1) {
233 sigs
|= (ppdata
& MCFPP_DCD1
) ? 0 : TIOCM_CD
;
234 sigs
|= (ppdata
& MCFPP_DTR1
) ? 0 : TIOCM_DTR
;
239 local_irq_restore(flags
);
244 * ------------------------------------------------------------
245 * mcfrs_stop() and mcfrs_start()
247 * This routines are called before setting or resetting tty->stopped.
248 * They enable or disable transmitter interrupts, as necessary.
249 * ------------------------------------------------------------
251 static void mcfrs_stop(struct tty_struct
*tty
)
253 volatile unsigned char *uartp
;
254 struct mcf_serial
*info
= (struct mcf_serial
*)tty
->driver_data
;
257 if (serial_paranoia_check(info
, tty
->name
, "mcfrs_stop"))
260 local_irq_save(flags
);
262 info
->imr
&= ~MCFUART_UIR_TXREADY
;
263 uartp
[MCFUART_UIMR
] = info
->imr
;
264 local_irq_restore(flags
);
267 static void mcfrs_start(struct tty_struct
*tty
)
269 volatile unsigned char *uartp
;
270 struct mcf_serial
*info
= (struct mcf_serial
*)tty
->driver_data
;
273 if (serial_paranoia_check(info
, tty
->name
, "mcfrs_start"))
276 local_irq_save(flags
);
277 if (info
->xmit_cnt
&& info
->xmit_buf
) {
279 info
->imr
|= MCFUART_UIR_TXREADY
;
280 uartp
[MCFUART_UIMR
] = info
->imr
;
282 local_irq_restore(flags
);
286 * ----------------------------------------------------------------------
288 * Here starts the interrupt handling routines. All of the following
289 * subroutines are declared as inline and are folded into
290 * mcfrs_interrupt(). They were separated out for readability's sake.
292 * Note: mcfrs_interrupt() is a "fast" interrupt, which means that it
293 * runs with interrupts turned off. People who may want to modify
294 * mcfrs_interrupt() should try to keep the interrupt handler as fast as
295 * possible. After you are done making modifications, it is not a bad
298 * gcc -S -DKERNEL -Wall -Wstrict-prototypes -O6 -fomit-frame-pointer serial.c
300 * and look at the resulting assemble code in serial.s.
302 * - Ted Ts'o (tytso@mit.edu), 7-Mar-93
303 * -----------------------------------------------------------------------
306 static inline void receive_chars(struct mcf_serial
*info
)
308 volatile unsigned char *uartp
;
309 struct tty_struct
*tty
= info
->tty
;
310 unsigned char status
, ch
;
317 while ((status
= uartp
[MCFUART_USR
]) & MCFUART_USR_RXREADY
) {
319 if (tty
->flip
.count
>= TTY_FLIPBUF_SIZE
)
322 ch
= uartp
[MCFUART_URB
];
325 #ifdef CONFIG_MAGIC_SYSRQ
326 if (mcfrs_console_inited
&& (info
->line
== mcfrs_console_port
)) {
327 if (magic_sysrq_key(ch
))
333 if (status
& MCFUART_USR_RXERR
) {
334 uartp
[MCFUART_UCR
] = MCFUART_UCR_CMDRESETERR
;
335 if (status
& MCFUART_USR_RXBREAK
) {
336 info
->stats
.rxbreak
++;
337 *tty
->flip
.flag_buf_ptr
++ = TTY_BREAK
;
338 } else if (status
& MCFUART_USR_RXPARITY
) {
339 info
->stats
.rxparity
++;
340 *tty
->flip
.flag_buf_ptr
++ = TTY_PARITY
;
341 } else if (status
& MCFUART_USR_RXOVERRUN
) {
342 info
->stats
.rxoverrun
++;
343 *tty
->flip
.flag_buf_ptr
++ = TTY_OVERRUN
;
344 } else if (status
& MCFUART_USR_RXFRAMING
) {
345 info
->stats
.rxframing
++;
346 *tty
->flip
.flag_buf_ptr
++ = TTY_FRAME
;
348 /* This should never happen... */
349 *tty
->flip
.flag_buf_ptr
++ = 0;
352 *tty
->flip
.flag_buf_ptr
++ = 0;
354 *tty
->flip
.char_buf_ptr
++ = ch
;
357 schedule_work(&tty
->flip
.work
);
361 static inline void transmit_chars(struct mcf_serial
*info
)
363 volatile unsigned char *uartp
;
368 /* Send special char - probably flow control */
369 uartp
[MCFUART_UTB
] = info
->x_char
;
374 if ((info
->xmit_cnt
<= 0) || info
->tty
->stopped
) {
375 info
->imr
&= ~MCFUART_UIR_TXREADY
;
376 uartp
[MCFUART_UIMR
] = info
->imr
;
380 while (uartp
[MCFUART_USR
] & MCFUART_USR_TXREADY
) {
381 uartp
[MCFUART_UTB
] = info
->xmit_buf
[info
->xmit_tail
++];
382 info
->xmit_tail
= info
->xmit_tail
& (SERIAL_XMIT_SIZE
-1);
384 if (--info
->xmit_cnt
<= 0)
388 if (info
->xmit_cnt
< WAKEUP_CHARS
)
389 schedule_work(&info
->tqueue
);
394 * This is the serial driver's generic interrupt routine
396 irqreturn_t
mcfrs_interrupt(int irq
, void *dev_id
, struct pt_regs
*regs
)
398 struct mcf_serial
*info
;
401 info
= &mcfrs_table
[(irq
- IRQBASE
)];
402 isr
= info
->addr
[MCFUART_UISR
] & info
->imr
;
404 if (isr
& MCFUART_UIR_RXREADY
)
406 if (isr
& MCFUART_UIR_TXREADY
)
407 transmit_chars(info
);
412 * -------------------------------------------------------------------
413 * Here ends the serial interrupt routines.
414 * -------------------------------------------------------------------
417 static void mcfrs_offintr(void *private)
419 struct mcf_serial
*info
= (struct mcf_serial
*) private;
420 struct tty_struct
*tty
;
430 * Change of state on a DCD line.
432 void mcfrs_modem_change(struct mcf_serial
*info
, int dcd
)
434 if (info
->count
== 0)
437 if (info
->flags
& ASYNC_CHECK_CD
) {
439 wake_up_interruptible(&info
->open_wait
);
441 schedule_work(&info
->tqueue_hangup
);
448 unsigned short mcfrs_ppstatus
;
451 * This subroutine is called when the RS_TIMER goes off. It is used
452 * to monitor the state of the DCD lines - since they have no edge
453 * sensors and interrupt generators.
455 static void mcfrs_timer(void)
457 unsigned int ppstatus
, dcdval
, i
;
459 ppstatus
= mcf_getppdata() & (MCFPP_DCD0
| MCFPP_DCD1
);
461 if (ppstatus
!= mcfrs_ppstatus
) {
462 for (i
= 0; (i
< 2); i
++) {
463 dcdval
= (i
? MCFPP_DCD1
: MCFPP_DCD0
);
464 if ((ppstatus
& dcdval
) != (mcfrs_ppstatus
& dcdval
)) {
465 mcfrs_modem_change(&mcfrs_table
[i
],
466 ((ppstatus
& dcdval
) ? 0 : 1));
470 mcfrs_ppstatus
= ppstatus
;
473 mcfrs_timer_struct
.expires
= jiffies
+ HZ
/25;
474 add_timer(&mcfrs_timer_struct
);
477 #endif /* MCFPP_DCD0 */
481 * This routine is called from the scheduler tqueue when the interrupt
482 * routine has signalled that a hangup has occurred. The path of
483 * hangup processing is:
485 * serial interrupt routine -> (scheduler tqueue) ->
486 * do_serial_hangup() -> tty->hangup() -> mcfrs_hangup()
489 static void do_serial_hangup(void *private)
491 struct mcf_serial
*info
= (struct mcf_serial
*) private;
492 struct tty_struct
*tty
;
501 static int startup(struct mcf_serial
* info
)
503 volatile unsigned char *uartp
;
506 if (info
->flags
& ASYNC_INITIALIZED
)
509 if (!info
->xmit_buf
) {
510 info
->xmit_buf
= (unsigned char *) __get_free_page(GFP_KERNEL
);
515 local_irq_save(flags
);
517 #ifdef SERIAL_DEBUG_OPEN
518 printk("starting up ttyS%d (irq %d)...\n", info
->line
, info
->irq
);
522 * Reset UART, get it into known state...
525 uartp
[MCFUART_UCR
] = MCFUART_UCR_CMDRESETRX
; /* reset RX */
526 uartp
[MCFUART_UCR
] = MCFUART_UCR_CMDRESETTX
; /* reset TX */
527 mcfrs_setsignals(info
, 1, 1);
530 clear_bit(TTY_IO_ERROR
, &info
->tty
->flags
);
531 info
->xmit_cnt
= info
->xmit_head
= info
->xmit_tail
= 0;
534 * and set the speed of the serial port
536 mcfrs_change_speed(info
);
539 * Lastly enable the UART transmitter and receiver, and
542 info
->imr
= MCFUART_UIR_RXREADY
;
543 uartp
[MCFUART_UCR
] = MCFUART_UCR_RXENABLE
| MCFUART_UCR_TXENABLE
;
544 uartp
[MCFUART_UIMR
] = info
->imr
;
546 info
->flags
|= ASYNC_INITIALIZED
;
547 local_irq_restore(flags
);
552 * This routine will shutdown a serial port; interrupts are disabled, and
553 * DTR is dropped if the hangup on close termio flag is on.
555 static void shutdown(struct mcf_serial
* info
)
557 volatile unsigned char *uartp
;
560 if (!(info
->flags
& ASYNC_INITIALIZED
))
563 #ifdef SERIAL_DEBUG_OPEN
564 printk("Shutting down serial port %d (irq %d)....\n", info
->line
,
568 local_irq_save(flags
);
571 uartp
[MCFUART_UIMR
] = 0; /* mask all interrupts */
572 uartp
[MCFUART_UCR
] = MCFUART_UCR_CMDRESETRX
; /* reset RX */
573 uartp
[MCFUART_UCR
] = MCFUART_UCR_CMDRESETTX
; /* reset TX */
575 if (!info
->tty
|| (info
->tty
->termios
->c_cflag
& HUPCL
))
576 mcfrs_setsignals(info
, 0, 0);
578 if (info
->xmit_buf
) {
579 free_page((unsigned long) info
->xmit_buf
);
584 set_bit(TTY_IO_ERROR
, &info
->tty
->flags
);
586 info
->flags
&= ~ASYNC_INITIALIZED
;
587 local_irq_restore(flags
);
592 * This routine is called to set the UART divisor registers to match
593 * the specified baud rate for a serial port.
595 static void mcfrs_change_speed(struct mcf_serial
*info
)
597 volatile unsigned char *uartp
;
598 unsigned int baudclk
, cflag
;
600 unsigned char mr1
, mr2
;
603 unsigned int fraction
;
606 if (!info
->tty
|| !info
->tty
->termios
)
608 cflag
= info
->tty
->termios
->c_cflag
;
613 printk("%s(%d): mcfrs_change_speed()\n", __FILE__
, __LINE__
);
620 info
->tty
->termios
->c_cflag
&= ~CBAUDEX
;
625 mcfrs_setsignals(info
, 0, -1);
629 /* compute the baudrate clock */
632 * For the MCF5272, also compute the baudrate fraction.
634 baudclk
= (MCF_BUSCLK
/ mcfrs_baud_table
[i
]) / 32;
635 fraction
= MCF_BUSCLK
- (baudclk
* 32 * mcfrs_baud_table
[i
]);
637 fraction
/= (32 * mcfrs_baud_table
[i
]);
639 baudclk
= ((MCF_BUSCLK
/ mcfrs_baud_table
[i
]) + 16) / 32;
642 info
->baud
= mcfrs_baud_table
[i
];
644 mr1
= MCFUART_MR1_RXIRQRDY
| MCFUART_MR1_RXERRCHAR
;
647 switch (cflag
& CSIZE
) {
648 case CS5
: mr1
|= MCFUART_MR1_CS5
; break;
649 case CS6
: mr1
|= MCFUART_MR1_CS6
; break;
650 case CS7
: mr1
|= MCFUART_MR1_CS7
; break;
652 default: mr1
|= MCFUART_MR1_CS8
; break;
655 if (cflag
& PARENB
) {
656 if (cflag
& CMSPAR
) {
658 mr1
|= MCFUART_MR1_PARITYMARK
;
660 mr1
|= MCFUART_MR1_PARITYSPACE
;
663 mr1
|= MCFUART_MR1_PARITYODD
;
665 mr1
|= MCFUART_MR1_PARITYEVEN
;
668 mr1
|= MCFUART_MR1_PARITYNONE
;
672 mr2
|= MCFUART_MR2_STOP2
;
674 mr2
|= MCFUART_MR2_STOP1
;
676 if (cflag
& CRTSCTS
) {
677 mr1
|= MCFUART_MR1_RXRTS
;
678 mr2
|= MCFUART_MR2_TXCTS
;
682 info
->flags
&= ~ASYNC_CHECK_CD
;
684 info
->flags
|= ASYNC_CHECK_CD
;
688 local_irq_save(flags
);
690 printk("%s(%d): mr1=%x mr2=%x baudclk=%x\n", __FILE__
, __LINE__
,
694 Note: pg 12-16 of MCF5206e User's Manual states that a
695 software reset should be performed prior to changing
696 UMR1,2, UCSR, UACR, bit 7
698 uartp
[MCFUART_UCR
] = MCFUART_UCR_CMDRESETRX
; /* reset RX */
699 uartp
[MCFUART_UCR
] = MCFUART_UCR_CMDRESETTX
; /* reset TX */
700 uartp
[MCFUART_UCR
] = MCFUART_UCR_CMDRESETMRPTR
; /* reset MR pointer */
701 uartp
[MCFUART_UMR
] = mr1
;
702 uartp
[MCFUART_UMR
] = mr2
;
703 uartp
[MCFUART_UBG1
] = (baudclk
& 0xff00) >> 8; /* set msb byte */
704 uartp
[MCFUART_UBG2
] = (baudclk
& 0xff); /* set lsb byte */
706 uartp
[MCFUART_UFPD
] = (fraction
& 0xf); /* set fraction */
708 uartp
[MCFUART_UCSR
] = MCFUART_UCSR_RXCLKTIMER
| MCFUART_UCSR_TXCLKTIMER
;
709 uartp
[MCFUART_UCR
] = MCFUART_UCR_RXENABLE
| MCFUART_UCR_TXENABLE
;
710 mcfrs_setsignals(info
, 1, -1);
711 local_irq_restore(flags
);
715 static void mcfrs_flush_chars(struct tty_struct
*tty
)
717 volatile unsigned char *uartp
;
718 struct mcf_serial
*info
= (struct mcf_serial
*)tty
->driver_data
;
721 if (serial_paranoia_check(info
, tty
->name
, "mcfrs_flush_chars"))
724 uartp
= (volatile unsigned char *) info
->addr
;
727 * re-enable receiver interrupt
729 local_irq_save(flags
);
730 if ((!(info
->imr
& MCFUART_UIR_RXREADY
)) &&
731 (info
->flags
& ASYNC_INITIALIZED
) ) {
732 info
->imr
|= MCFUART_UIR_RXREADY
;
733 uartp
[MCFUART_UIMR
] = info
->imr
;
735 local_irq_restore(flags
);
737 if (info
->xmit_cnt
<= 0 || tty
->stopped
|| tty
->hw_stopped
||
741 /* Enable transmitter */
742 local_irq_save(flags
);
743 info
->imr
|= MCFUART_UIR_TXREADY
;
744 uartp
[MCFUART_UIMR
] = info
->imr
;
745 local_irq_restore(flags
);
748 static int mcfrs_write(struct tty_struct
* tty
,
749 const unsigned char *buf
, int count
)
751 volatile unsigned char *uartp
;
752 struct mcf_serial
*info
= (struct mcf_serial
*)tty
->driver_data
;
757 printk("%s(%d): mcfrs_write(tty=%x,buf=%x,count=%d)\n",
758 __FILE__
, __LINE__
, (int)tty
, (int)buf
, count
);
761 if (serial_paranoia_check(info
, tty
->name
, "mcfrs_write"))
764 if (!tty
|| !info
->xmit_buf
)
767 local_save_flags(flags
);
770 c
= min(count
, (int) min(((int)SERIAL_XMIT_SIZE
) - info
->xmit_cnt
- 1,
771 ((int)SERIAL_XMIT_SIZE
) - info
->xmit_head
));
772 local_irq_restore(flags
);
777 memcpy(info
->xmit_buf
+ info
->xmit_head
, buf
, c
);
780 info
->xmit_head
= (info
->xmit_head
+ c
) & (SERIAL_XMIT_SIZE
-1);
782 local_irq_restore(flags
);
791 info
->imr
|= MCFUART_UIR_TXREADY
;
792 uartp
[MCFUART_UIMR
] = info
->imr
;
793 local_irq_restore(flags
);
798 static int mcfrs_write_room(struct tty_struct
*tty
)
800 struct mcf_serial
*info
= (struct mcf_serial
*)tty
->driver_data
;
803 if (serial_paranoia_check(info
, tty
->name
, "mcfrs_write_room"))
805 ret
= SERIAL_XMIT_SIZE
- info
->xmit_cnt
- 1;
811 static int mcfrs_chars_in_buffer(struct tty_struct
*tty
)
813 struct mcf_serial
*info
= (struct mcf_serial
*)tty
->driver_data
;
815 if (serial_paranoia_check(info
, tty
->name
, "mcfrs_chars_in_buffer"))
817 return info
->xmit_cnt
;
820 static void mcfrs_flush_buffer(struct tty_struct
*tty
)
822 struct mcf_serial
*info
= (struct mcf_serial
*)tty
->driver_data
;
825 if (serial_paranoia_check(info
, tty
->name
, "mcfrs_flush_buffer"))
828 local_irq_save(flags
);
829 info
->xmit_cnt
= info
->xmit_head
= info
->xmit_tail
= 0;
830 local_irq_restore(flags
);
836 * ------------------------------------------------------------
839 * This routine is called by the upper-layer tty layer to signal that
840 * incoming characters should be throttled.
841 * ------------------------------------------------------------
843 static void mcfrs_throttle(struct tty_struct
* tty
)
845 struct mcf_serial
*info
= (struct mcf_serial
*)tty
->driver_data
;
846 #ifdef SERIAL_DEBUG_THROTTLE
849 printk("throttle %s: %d....\n", _tty_name(tty
, buf
),
850 tty
->ldisc
.chars_in_buffer(tty
));
853 if (serial_paranoia_check(info
, tty
->name
, "mcfrs_throttle"))
857 info
->x_char
= STOP_CHAR(tty
);
859 /* Turn off RTS line (do this atomic) */
862 static void mcfrs_unthrottle(struct tty_struct
* tty
)
864 struct mcf_serial
*info
= (struct mcf_serial
*)tty
->driver_data
;
865 #ifdef SERIAL_DEBUG_THROTTLE
868 printk("unthrottle %s: %d....\n", _tty_name(tty
, buf
),
869 tty
->ldisc
.chars_in_buffer(tty
));
872 if (serial_paranoia_check(info
, tty
->name
, "mcfrs_unthrottle"))
879 info
->x_char
= START_CHAR(tty
);
882 /* Assert RTS line (do this atomic) */
886 * ------------------------------------------------------------
887 * mcfrs_ioctl() and friends
888 * ------------------------------------------------------------
891 static int get_serial_info(struct mcf_serial
* info
,
892 struct serial_struct
* retinfo
)
894 struct serial_struct tmp
;
898 memset(&tmp
, 0, sizeof(tmp
));
899 tmp
.type
= info
->type
;
900 tmp
.line
= info
->line
;
901 tmp
.port
= (unsigned int) info
->addr
;
903 tmp
.flags
= info
->flags
;
904 tmp
.baud_base
= info
->baud_base
;
905 tmp
.close_delay
= info
->close_delay
;
906 tmp
.closing_wait
= info
->closing_wait
;
907 tmp
.custom_divisor
= info
->custom_divisor
;
908 return copy_to_user(retinfo
,&tmp
,sizeof(*retinfo
)) ? -EFAULT
: 0;
911 static int set_serial_info(struct mcf_serial
* info
,
912 struct serial_struct
* new_info
)
914 struct serial_struct new_serial
;
915 struct mcf_serial old_info
;
920 if (copy_from_user(&new_serial
,new_info
,sizeof(new_serial
)))
924 if (!capable(CAP_SYS_ADMIN
)) {
925 if ((new_serial
.baud_base
!= info
->baud_base
) ||
926 (new_serial
.type
!= info
->type
) ||
927 (new_serial
.close_delay
!= info
->close_delay
) ||
928 ((new_serial
.flags
& ~ASYNC_USR_MASK
) !=
929 (info
->flags
& ~ASYNC_USR_MASK
)))
931 info
->flags
= ((info
->flags
& ~ASYNC_USR_MASK
) |
932 (new_serial
.flags
& ASYNC_USR_MASK
));
933 info
->custom_divisor
= new_serial
.custom_divisor
;
941 * OK, past this point, all the error checking has been done.
942 * At this point, we start making changes.....
945 info
->baud_base
= new_serial
.baud_base
;
946 info
->flags
= ((info
->flags
& ~ASYNC_FLAGS
) |
947 (new_serial
.flags
& ASYNC_FLAGS
));
948 info
->type
= new_serial
.type
;
949 info
->close_delay
= new_serial
.close_delay
;
950 info
->closing_wait
= new_serial
.closing_wait
;
953 retval
= startup(info
);
958 * get_lsr_info - get line status register info
960 * Purpose: Let user call ioctl() to get info when the UART physically
961 * is emptied. On bus types like RS485, the transmitter must
962 * release the bus after transmitting. This must be done when
963 * the transmit shift register is empty, not be done when the
964 * transmit holding register is empty. This functionality
965 * allows an RS485 driver to be written in user space.
967 static int get_lsr_info(struct mcf_serial
* info
, unsigned int *value
)
969 volatile unsigned char *uartp
;
971 unsigned char status
;
973 local_irq_save(flags
);
975 status
= (uartp
[MCFUART_USR
] & MCFUART_USR_TXEMPTY
) ? TIOCSER_TEMT
: 0;
976 local_irq_restore(flags
);
978 return put_user(status
,value
);
982 * This routine sends a break character out the serial port.
984 static void send_break( struct mcf_serial
* info
, int duration
)
986 volatile unsigned char *uartp
;
991 set_current_state(TASK_INTERRUPTIBLE
);
994 local_irq_save(flags
);
995 uartp
[MCFUART_UCR
] = MCFUART_UCR_CMDBREAKSTART
;
996 schedule_timeout(duration
);
997 uartp
[MCFUART_UCR
] = MCFUART_UCR_CMDBREAKSTOP
;
998 local_irq_restore(flags
);
1001 static int mcfrs_tiocmget(struct tty_struct
*tty
, struct file
*file
)
1003 struct mcf_serial
* info
= (struct mcf_serial
*)tty
->driver_data
;
1005 if (serial_paranoia_check(info
, tty
->name
, "mcfrs_ioctl"))
1007 if (tty
->flags
& (1 << TTY_IO_ERROR
))
1010 return mcfrs_getsignals(info
);
1013 static int mcfrs_tiocmset(struct tty_struct
*tty
, struct file
*file
,
1014 unsigned int set
, unsigned int clear
)
1016 struct mcf_serial
* info
= (struct mcf_serial
*)tty
->driver_data
;
1017 int rts
= -1, dtr
= -1;
1019 if (serial_paranoia_check(info
, tty
->name
, "mcfrs_ioctl"))
1021 if (tty
->flags
& (1 << TTY_IO_ERROR
))
1024 if (set
& TIOCM_RTS
)
1026 if (set
& TIOCM_DTR
)
1028 if (clear
& TIOCM_RTS
)
1030 if (clear
& TIOCM_DTR
)
1033 mcfrs_setsignals(info
, dtr
, rts
);
1038 static int mcfrs_ioctl(struct tty_struct
*tty
, struct file
* file
,
1039 unsigned int cmd
, unsigned long arg
)
1041 struct mcf_serial
* info
= (struct mcf_serial
*)tty
->driver_data
;
1044 if (serial_paranoia_check(info
, tty
->name
, "mcfrs_ioctl"))
1047 if ((cmd
!= TIOCGSERIAL
) && (cmd
!= TIOCSSERIAL
) &&
1048 (cmd
!= TIOCSERCONFIG
) && (cmd
!= TIOCSERGWILD
) &&
1049 (cmd
!= TIOCSERSWILD
) && (cmd
!= TIOCSERGSTRUCT
)) {
1050 if (tty
->flags
& (1 << TTY_IO_ERROR
))
1055 case TCSBRK
: /* SVID version: non-zero arg --> no break */
1056 retval
= tty_check_change(tty
);
1059 tty_wait_until_sent(tty
, 0);
1061 send_break(info
, HZ
/4); /* 1/4 second */
1063 case TCSBRKP
: /* support for POSIX tcsendbreak() */
1064 retval
= tty_check_change(tty
);
1067 tty_wait_until_sent(tty
, 0);
1068 send_break(info
, arg
? arg
*(HZ
/10) : HZ
/4);
1071 error
= put_user(C_CLOCAL(tty
) ? 1 : 0,
1072 (unsigned long *) arg
);
1077 get_user(arg
, (unsigned long *) arg
);
1078 tty
->termios
->c_cflag
=
1079 ((tty
->termios
->c_cflag
& ~CLOCAL
) |
1080 (arg
? CLOCAL
: 0));
1083 if (access_ok(VERIFY_WRITE
, (void *) arg
,
1084 sizeof(struct serial_struct
)))
1085 return get_serial_info(info
,
1086 (struct serial_struct
*) arg
);
1089 return set_serial_info(info
,
1090 (struct serial_struct
*) arg
);
1091 case TIOCSERGETLSR
: /* Get line status register */
1092 if (access_ok(VERIFY_WRITE
, (void *) arg
,
1093 sizeof(unsigned int)))
1094 return get_lsr_info(info
, (unsigned int *) arg
);
1096 case TIOCSERGSTRUCT
:
1097 error
= copy_to_user((struct mcf_serial
*) arg
,
1098 info
, sizeof(struct mcf_serial
));
1106 get_user(val
, (unsigned int *) arg
);
1107 mcf_setpa(MCFPP_PA11
, (val
? 0 : MCFPP_PA11
));
1112 val
= (mcf_getpa() & MCFPP_PA11
) ? 0 : 1;
1113 put_user(val
, (unsigned int *) arg
);
1119 return -ENOIOCTLCMD
;
1124 static void mcfrs_set_termios(struct tty_struct
*tty
, struct termios
*old_termios
)
1126 struct mcf_serial
*info
= (struct mcf_serial
*)tty
->driver_data
;
1128 if (tty
->termios
->c_cflag
== old_termios
->c_cflag
)
1131 mcfrs_change_speed(info
);
1133 if ((old_termios
->c_cflag
& CRTSCTS
) &&
1134 !(tty
->termios
->c_cflag
& CRTSCTS
)) {
1135 tty
->hw_stopped
= 0;
1136 mcfrs_setsignals(info
, -1, 1);
1144 * ------------------------------------------------------------
1147 * This routine is called when the serial port gets closed. First, we
1148 * wait for the last remaining data to be sent. Then, we unlink its
1149 * S structure from the interrupt chain if necessary, and we free
1150 * that IRQ if nothing is left in the chain.
1151 * ------------------------------------------------------------
1153 static void mcfrs_close(struct tty_struct
*tty
, struct file
* filp
)
1155 volatile unsigned char *uartp
;
1156 struct mcf_serial
*info
= (struct mcf_serial
*)tty
->driver_data
;
1157 unsigned long flags
;
1159 if (!info
|| serial_paranoia_check(info
, tty
->name
, "mcfrs_close"))
1162 local_irq_save(flags
);
1164 if (tty_hung_up_p(filp
)) {
1165 local_irq_restore(flags
);
1169 #ifdef SERIAL_DEBUG_OPEN
1170 printk("mcfrs_close ttyS%d, count = %d\n", info
->line
, info
->count
);
1172 if ((tty
->count
== 1) && (info
->count
!= 1)) {
1174 * Uh, oh. tty->count is 1, which means that the tty
1175 * structure will be freed. Info->count should always
1176 * be one in these conditions. If it's greater than
1177 * one, we've got real problems, since it means the
1178 * serial port won't be shutdown.
1180 printk("MCFRS: bad serial port count; tty->count is 1, "
1181 "info->count is %d\n", info
->count
);
1184 if (--info
->count
< 0) {
1185 printk("MCFRS: bad serial port count for ttyS%d: %d\n",
1186 info
->line
, info
->count
);
1190 local_irq_restore(flags
);
1193 info
->flags
|= ASYNC_CLOSING
;
1196 * Now we wait for the transmit buffer to clear; and we notify
1197 * the line discipline to only process XON/XOFF characters.
1200 if (info
->closing_wait
!= ASYNC_CLOSING_WAIT_NONE
)
1201 tty_wait_until_sent(tty
, info
->closing_wait
);
1204 * At this point we stop accepting input. To do this, we
1205 * disable the receive line status interrupts, and tell the
1206 * interrupt driver to stop checking the data ready bit in the
1207 * line status register.
1209 info
->imr
&= ~MCFUART_UIR_RXREADY
;
1211 uartp
[MCFUART_UIMR
] = info
->imr
;
1214 /* FIXME: do we need to keep this enabled for console?? */
1215 if (mcfrs_console_inited
&& (mcfrs_console_port
== info
->line
)) {
1216 /* Do not disable the UART */ ;
1220 if (tty
->driver
->flush_buffer
)
1221 tty
->driver
->flush_buffer(tty
);
1222 tty_ldisc_flush(tty
);
1228 if (tty
->ldisc
.num
!= ldiscs
[N_TTY
].num
) {
1229 if (tty
->ldisc
.close
)
1230 (tty
->ldisc
.close
)(tty
);
1231 tty
->ldisc
= ldiscs
[N_TTY
];
1232 tty
->termios
->c_line
= N_TTY
;
1233 if (tty
->ldisc
.open
)
1234 (tty
->ldisc
.open
)(tty
);
1237 if (info
->blocked_open
) {
1238 if (info
->close_delay
) {
1239 msleep_interruptible(jiffies_to_msecs(info
->close_delay
));
1241 wake_up_interruptible(&info
->open_wait
);
1243 info
->flags
&= ~(ASYNC_NORMAL_ACTIVE
|ASYNC_CLOSING
);
1244 wake_up_interruptible(&info
->close_wait
);
1245 local_irq_restore(flags
);
1249 * mcfrs_wait_until_sent() --- wait until the transmitter is empty
1252 mcfrs_wait_until_sent(struct tty_struct
*tty
, int timeout
)
1255 #define MCF5272_FIFO_SIZE 25 /* fifo size + shift reg */
1257 struct mcf_serial
* info
= (struct mcf_serial
*)tty
->driver_data
;
1258 volatile unsigned char *uartp
;
1259 unsigned long orig_jiffies
, fifo_time
, char_time
, fifo_cnt
;
1261 if (serial_paranoia_check(info
, tty
->name
, "mcfrs_wait_until_sent"))
1264 orig_jiffies
= jiffies
;
1267 * Set the check interval to be 1/5 of the approximate time
1268 * to send the entire fifo, and make it at least 1. The check
1269 * interval should also be less than the timeout.
1271 * Note: we have to use pretty tight timings here to satisfy
1274 fifo_time
= (MCF5272_FIFO_SIZE
* HZ
* 10) / info
->baud
;
1275 char_time
= fifo_time
/ 5;
1278 if (timeout
&& timeout
< char_time
)
1279 char_time
= timeout
;
1282 * Clamp the timeout period at 2 * the time to empty the
1283 * fifo. Just to be safe, set the minimum at .5 seconds.
1286 if (fifo_time
< (HZ
/2))
1288 if (!timeout
|| timeout
> fifo_time
)
1289 timeout
= fifo_time
;
1292 * Account for the number of bytes in the UART
1293 * transmitter FIFO plus any byte being shifted out.
1295 uartp
= (volatile unsigned char *) info
->addr
;
1297 fifo_cnt
= (uartp
[MCFUART_UTF
] & MCFUART_UTF_TXB
);
1298 if ((uartp
[MCFUART_USR
] & (MCFUART_USR_TXREADY
|
1299 MCFUART_USR_TXEMPTY
)) ==
1300 MCFUART_USR_TXREADY
)
1304 msleep_interruptible(jiffies_to_msecs(char_time
));
1305 if (signal_pending(current
))
1307 if (timeout
&& time_after(jiffies
, orig_jiffies
+ timeout
))
1312 * For the other coldfire models, assume all data has been sent
1318 * mcfrs_hangup() --- called by tty_hangup() when a hangup is signaled.
1320 void mcfrs_hangup(struct tty_struct
*tty
)
1322 struct mcf_serial
* info
= (struct mcf_serial
*)tty
->driver_data
;
1324 if (serial_paranoia_check(info
, tty
->name
, "mcfrs_hangup"))
1327 mcfrs_flush_buffer(tty
);
1331 info
->flags
&= ~ASYNC_NORMAL_ACTIVE
;
1333 wake_up_interruptible(&info
->open_wait
);
1337 * ------------------------------------------------------------
1338 * mcfrs_open() and friends
1339 * ------------------------------------------------------------
1341 static int block_til_ready(struct tty_struct
*tty
, struct file
* filp
,
1342 struct mcf_serial
*info
)
1344 DECLARE_WAITQUEUE(wait
, current
);
1349 * If the device is in the middle of being closed, then block
1350 * until it's done, and then try again.
1352 if (info
->flags
& ASYNC_CLOSING
) {
1353 interruptible_sleep_on(&info
->close_wait
);
1354 #ifdef SERIAL_DO_RESTART
1355 if (info
->flags
& ASYNC_HUP_NOTIFY
)
1358 return -ERESTARTSYS
;
1365 * If non-blocking mode is set, or the port is not enabled,
1366 * then make the check up front and then exit.
1368 if ((filp
->f_flags
& O_NONBLOCK
) ||
1369 (tty
->flags
& (1 << TTY_IO_ERROR
))) {
1370 info
->flags
|= ASYNC_NORMAL_ACTIVE
;
1374 if (tty
->termios
->c_cflag
& CLOCAL
)
1378 * Block waiting for the carrier detect and the line to become
1379 * free (i.e., not in use by the callout). While we are in
1380 * this loop, info->count is dropped by one, so that
1381 * mcfrs_close() knows when to free things. We restore it upon
1382 * exit, either normal or abnormal.
1385 add_wait_queue(&info
->open_wait
, &wait
);
1386 #ifdef SERIAL_DEBUG_OPEN
1387 printk("block_til_ready before block: ttyS%d, count = %d\n",
1388 info
->line
, info
->count
);
1391 info
->blocked_open
++;
1393 local_irq_disable();
1394 mcfrs_setsignals(info
, 1, 1);
1396 current
->state
= TASK_INTERRUPTIBLE
;
1397 if (tty_hung_up_p(filp
) ||
1398 !(info
->flags
& ASYNC_INITIALIZED
)) {
1399 #ifdef SERIAL_DO_RESTART
1400 if (info
->flags
& ASYNC_HUP_NOTIFY
)
1403 retval
= -ERESTARTSYS
;
1409 if (!(info
->flags
& ASYNC_CLOSING
) &&
1410 (do_clocal
|| (mcfrs_getsignals(info
) & TIOCM_CD
)))
1412 if (signal_pending(current
)) {
1413 retval
= -ERESTARTSYS
;
1416 #ifdef SERIAL_DEBUG_OPEN
1417 printk("block_til_ready blocking: ttyS%d, count = %d\n",
1418 info
->line
, info
->count
);
1422 current
->state
= TASK_RUNNING
;
1423 remove_wait_queue(&info
->open_wait
, &wait
);
1424 if (!tty_hung_up_p(filp
))
1426 info
->blocked_open
--;
1427 #ifdef SERIAL_DEBUG_OPEN
1428 printk("block_til_ready after blocking: ttyS%d, count = %d\n",
1429 info
->line
, info
->count
);
1433 info
->flags
|= ASYNC_NORMAL_ACTIVE
;
1438 * This routine is called whenever a serial port is opened. It
1439 * enables interrupts for a serial port, linking in its structure into
1440 * the IRQ chain. It also performs the serial-specific
1441 * initialization for the tty structure.
1443 int mcfrs_open(struct tty_struct
*tty
, struct file
* filp
)
1445 struct mcf_serial
*info
;
1449 if ((line
< 0) || (line
>= NR_PORTS
))
1451 info
= mcfrs_table
+ line
;
1452 if (serial_paranoia_check(info
, tty
->name
, "mcfrs_open"))
1454 #ifdef SERIAL_DEBUG_OPEN
1455 printk("mcfrs_open %s, count = %d\n", tty
->name
, info
->count
);
1458 tty
->driver_data
= info
;
1462 * Start up serial port
1464 retval
= startup(info
);
1468 retval
= block_til_ready(tty
, filp
, info
);
1470 #ifdef SERIAL_DEBUG_OPEN
1471 printk("mcfrs_open returning after block_til_ready with %d\n",
1477 #ifdef SERIAL_DEBUG_OPEN
1478 printk("mcfrs_open %s successful...\n", tty
->name
);
1484 * Based on the line number set up the internal interrupt stuff.
1486 static void mcfrs_irqinit(struct mcf_serial
*info
)
1488 #if defined(CONFIG_M5272)
1489 volatile unsigned long *icrp
;
1490 volatile unsigned long *portp
;
1491 volatile unsigned char *uartp
;
1494 icrp
= (volatile unsigned long *) (MCF_MBAR
+ MCFSIM_ICR2
);
1496 switch (info
->line
) {
1504 printk("MCFRS: don't know how to handle UART %d interrupt?\n",
1509 /* Enable the output lines for the serial ports */
1510 portp
= (volatile unsigned long *) (MCF_MBAR
+ MCFSIM_PBCNT
);
1511 *portp
= (*portp
& ~0x000000ff) | 0x00000055;
1512 portp
= (volatile unsigned long *) (MCF_MBAR
+ MCFSIM_PDCNT
);
1513 *portp
= (*portp
& ~0x000003fc) | 0x000002a8;
1514 #elif defined(CONFIG_M527x) || defined(CONFIG_M528x)
1515 volatile unsigned char *icrp
, *uartp
;
1516 volatile unsigned long *imrp
;
1520 icrp
= (volatile unsigned char *) (MCF_MBAR
+ MCFICM_INTC0
+
1521 MCFINTC_ICR0
+ MCFINT_UART0
+ info
->line
);
1522 *icrp
= 0x33; /* UART0 with level 6, priority 3 */
1524 imrp
= (volatile unsigned long *) (MCF_MBAR
+ MCFICM_INTC0
+
1526 *imrp
&= ~((1 << (info
->irq
- MCFINT_VECBASE
)) | 1);
1528 volatile unsigned char *icrp
, *uartp
;
1530 switch (info
->line
) {
1532 icrp
= (volatile unsigned char *) (MCF_MBAR
+ MCFSIM_UART1ICR
);
1533 *icrp
= /*MCFSIM_ICR_AUTOVEC |*/ MCFSIM_ICR_LEVEL6
|
1535 mcf_setimr(mcf_getimr() & ~MCFSIM_IMR_UART1
);
1538 icrp
= (volatile unsigned char *) (MCF_MBAR
+ MCFSIM_UART2ICR
);
1539 *icrp
= /*MCFSIM_ICR_AUTOVEC |*/ MCFSIM_ICR_LEVEL6
|
1541 mcf_setimr(mcf_getimr() & ~MCFSIM_IMR_UART2
);
1544 printk("MCFRS: don't know how to handle UART %d interrupt?\n",
1550 uartp
[MCFUART_UIVR
] = info
->irq
;
1553 /* Clear mask, so no surprise interrupts. */
1554 uartp
[MCFUART_UIMR
] = 0;
1556 if (request_irq(info
->irq
, mcfrs_interrupt
, SA_INTERRUPT
,
1557 "ColdFire UART", NULL
)) {
1558 printk("MCFRS: Unable to attach ColdFire UART %d interrupt "
1559 "vector=%d\n", info
->line
, info
->irq
);
1566 char *mcfrs_drivername
= "ColdFire internal UART serial driver version 1.00\n";
1570 * Serial stats reporting...
1572 int mcfrs_readproc(char *page
, char **start
, off_t off
, int count
,
1573 int *eof
, void *data
)
1575 struct mcf_serial
*info
;
1579 len
= sprintf(page
, mcfrs_drivername
);
1580 for (i
= 0; (i
< NR_PORTS
); i
++) {
1581 info
= &mcfrs_table
[i
];
1582 len
+= sprintf((page
+ len
), "%d: port:%x irq=%d baud:%d ",
1583 i
, (unsigned int) info
->addr
, info
->irq
, info
->baud
);
1584 if (info
->stats
.rx
|| info
->stats
.tx
)
1585 len
+= sprintf((page
+ len
), "tx:%d rx:%d ",
1586 info
->stats
.tx
, info
->stats
.rx
);
1587 if (info
->stats
.rxframing
)
1588 len
+= sprintf((page
+ len
), "fe:%d ",
1589 info
->stats
.rxframing
);
1590 if (info
->stats
.rxparity
)
1591 len
+= sprintf((page
+ len
), "pe:%d ",
1592 info
->stats
.rxparity
);
1593 if (info
->stats
.rxbreak
)
1594 len
+= sprintf((page
+ len
), "brk:%d ",
1595 info
->stats
.rxbreak
);
1596 if (info
->stats
.rxoverrun
)
1597 len
+= sprintf((page
+ len
), "oe:%d ",
1598 info
->stats
.rxoverrun
);
1600 str
[0] = str
[1] = 0;
1601 if ((sigs
= mcfrs_getsignals(info
))) {
1602 if (sigs
& TIOCM_RTS
)
1603 strcat(str
, "|RTS");
1604 if (sigs
& TIOCM_CTS
)
1605 strcat(str
, "|CTS");
1606 if (sigs
& TIOCM_DTR
)
1607 strcat(str
, "|DTR");
1608 if (sigs
& TIOCM_CD
)
1612 len
+= sprintf((page
+ len
), "%s\n", &str
[1]);
1619 /* Finally, routines used to initialize the serial driver. */
1621 static void show_serial_version(void)
1623 printk(mcfrs_drivername
);
1626 static struct tty_operations mcfrs_ops
= {
1628 .close
= mcfrs_close
,
1629 .write
= mcfrs_write
,
1630 .flush_chars
= mcfrs_flush_chars
,
1631 .write_room
= mcfrs_write_room
,
1632 .chars_in_buffer
= mcfrs_chars_in_buffer
,
1633 .flush_buffer
= mcfrs_flush_buffer
,
1634 .ioctl
= mcfrs_ioctl
,
1635 .throttle
= mcfrs_throttle
,
1636 .unthrottle
= mcfrs_unthrottle
,
1637 .set_termios
= mcfrs_set_termios
,
1639 .start
= mcfrs_start
,
1640 .hangup
= mcfrs_hangup
,
1641 .read_proc
= mcfrs_readproc
,
1642 .wait_until_sent
= mcfrs_wait_until_sent
,
1643 .tiocmget
= mcfrs_tiocmget
,
1644 .tiocmset
= mcfrs_tiocmset
,
1647 /* mcfrs_init inits the driver */
1651 struct mcf_serial
*info
;
1652 unsigned long flags
;
1655 /* Setup base handler, and timer table. */
1657 init_timer(&mcfrs_timer_struct
);
1658 mcfrs_timer_struct
.function
= mcfrs_timer
;
1659 mcfrs_timer_struct
.data
= 0;
1660 mcfrs_timer_struct
.expires
= jiffies
+ HZ
/25;
1661 add_timer(&mcfrs_timer_struct
);
1662 mcfrs_ppstatus
= mcf_getppdata() & (MCFPP_DCD0
| MCFPP_DCD1
);
1664 mcfrs_serial_driver
= alloc_tty_driver(NR_PORTS
);
1665 if (!mcfrs_serial_driver
)
1668 show_serial_version();
1670 /* Initialize the tty_driver structure */
1671 mcfrs_serial_driver
->owner
= THIS_MODULE
;
1672 mcfrs_serial_driver
->name
= "ttyS";
1673 mcfrs_serial_driver
->devfs_name
= "ttys/";
1674 mcfrs_serial_driver
->driver_name
= "serial";
1675 mcfrs_serial_driver
->major
= TTY_MAJOR
;
1676 mcfrs_serial_driver
->minor_start
= 64;
1677 mcfrs_serial_driver
->type
= TTY_DRIVER_TYPE_SERIAL
;
1678 mcfrs_serial_driver
->subtype
= SERIAL_TYPE_NORMAL
;
1679 mcfrs_serial_driver
->init_termios
= tty_std_termios
;
1681 mcfrs_serial_driver
->init_termios
.c_cflag
=
1682 mcfrs_console_cbaud
| CS8
| CREAD
| HUPCL
| CLOCAL
;
1683 mcfrs_serial_driver
->flags
= TTY_DRIVER_REAL_RAW
;
1685 tty_set_operations(mcfrs_serial_driver
, &mcfrs_ops
);
1687 if (tty_register_driver(mcfrs_serial_driver
)) {
1688 printk("MCFRS: Couldn't register serial driver\n");
1689 put_tty_driver(mcfrs_serial_driver
);
1693 local_irq_save(flags
);
1696 * Configure all the attached serial ports.
1698 for (i
= 0, info
= mcfrs_table
; (i
< NR_PORTS
); i
++, info
++) {
1699 info
->magic
= SERIAL_MAGIC
;
1702 info
->custom_divisor
= 16;
1703 info
->close_delay
= 50;
1704 info
->closing_wait
= 3000;
1708 info
->blocked_open
= 0;
1709 INIT_WORK(&info
->tqueue
, mcfrs_offintr
, info
);
1710 INIT_WORK(&info
->tqueue_hangup
, do_serial_hangup
, info
);
1711 init_waitqueue_head(&info
->open_wait
);
1712 init_waitqueue_head(&info
->close_wait
);
1715 mcfrs_setsignals(info
, 0, 0);
1716 mcfrs_irqinit(info
);
1718 printk("ttyS%d at 0x%04x (irq = %d)", info
->line
,
1719 (unsigned int) info
->addr
, info
->irq
);
1720 printk(" is a builtin ColdFire UART\n");
1723 local_irq_restore(flags
);
1727 module_init(mcfrs_init
);
1729 /****************************************************************************/
1730 /* Serial Console */
1731 /****************************************************************************/
1734 * Quick and dirty UART initialization, for console output.
1737 void mcfrs_init_console(void)
1739 volatile unsigned char *uartp
;
1743 * Reset UART, get it into known state...
1745 uartp
= (volatile unsigned char *) (MCF_MBAR
+
1746 (mcfrs_console_port
? MCFUART_BASE2
: MCFUART_BASE1
));
1748 uartp
[MCFUART_UCR
] = MCFUART_UCR_CMDRESETRX
; /* reset RX */
1749 uartp
[MCFUART_UCR
] = MCFUART_UCR_CMDRESETTX
; /* reset TX */
1750 uartp
[MCFUART_UCR
] = MCFUART_UCR_CMDRESETMRPTR
; /* reset MR pointer */
1753 * Set port for defined baud , 8 data bits, 1 stop bit, no parity.
1755 uartp
[MCFUART_UMR
] = MCFUART_MR1_PARITYNONE
| MCFUART_MR1_CS8
;
1756 uartp
[MCFUART_UMR
] = MCFUART_MR2_STOP1
;
1758 clk
= ((MCF_BUSCLK
/ mcfrs_console_baud
) + 16) / 32; /* set baud */
1759 uartp
[MCFUART_UBG1
] = (clk
& 0xff00) >> 8; /* set msb baud */
1760 uartp
[MCFUART_UBG2
] = (clk
& 0xff); /* set lsb baud */
1762 uartp
[MCFUART_UCSR
] = MCFUART_UCSR_RXCLKTIMER
| MCFUART_UCSR_TXCLKTIMER
;
1763 uartp
[MCFUART_UCR
] = MCFUART_UCR_RXENABLE
| MCFUART_UCR_TXENABLE
;
1765 mcfrs_console_inited
++;
1771 * Setup for console. Argument comes from the boot command line.
1774 int mcfrs_console_setup(struct console
*cp
, char *arg
)
1776 int i
, n
= CONSOLE_BAUD_RATE
;
1781 if (!strncmp(cp
->name
, "ttyS", 4))
1782 mcfrs_console_port
= cp
->index
;
1783 else if (!strncmp(cp
->name
, "cua", 3))
1784 mcfrs_console_port
= cp
->index
;
1789 n
= simple_strtoul(arg
,NULL
,0);
1790 for (i
= 0; i
< MCFRS_BAUD_TABLE_SIZE
; i
++)
1791 if (mcfrs_baud_table
[i
] == n
)
1793 if (i
< MCFRS_BAUD_TABLE_SIZE
) {
1794 mcfrs_console_baud
= n
;
1795 mcfrs_console_cbaud
= 0;
1797 mcfrs_console_cbaud
|= CBAUDEX
;
1800 mcfrs_console_cbaud
|= i
;
1802 mcfrs_init_console(); /* make sure baud rate changes */
1807 static struct tty_driver
*mcfrs_console_device(struct console
*c
, int *index
)
1810 return mcfrs_serial_driver
;
1815 * Output a single character, using UART polled mode.
1816 * This is used for console output.
1819 void mcfrs_put_char(char ch
)
1821 volatile unsigned char *uartp
;
1822 unsigned long flags
;
1825 uartp
= (volatile unsigned char *) (MCF_MBAR
+
1826 (mcfrs_console_port
? MCFUART_BASE2
: MCFUART_BASE1
));
1828 local_irq_save(flags
);
1829 for (i
= 0; (i
< 0x10000); i
++) {
1830 if (uartp
[MCFUART_USR
] & MCFUART_USR_TXREADY
)
1834 uartp
[MCFUART_UTB
] = ch
;
1835 for (i
= 0; (i
< 0x10000); i
++)
1836 if (uartp
[MCFUART_USR
] & MCFUART_USR_TXEMPTY
)
1840 mcfrs_init_console(); /* try and get it back */
1841 local_irq_restore(flags
);
1848 * rs_console_write is registered for printk output.
1851 void mcfrs_console_write(struct console
*cp
, const char *p
, unsigned len
)
1853 if (!mcfrs_console_inited
)
1854 mcfrs_init_console();
1857 mcfrs_put_char('\r');
1858 mcfrs_put_char(*p
++);
1863 * declare our consoles
1866 struct console mcfrs_console
= {
1868 .write
= mcfrs_console_write
,
1869 .device
= mcfrs_console_device
,
1870 .setup
= mcfrs_console_setup
,
1871 .flags
= CON_PRINTBUFFER
,
1875 static int __init
mcfrs_console_init(void)
1877 register_console(&mcfrs_console
);
1881 console_initcall(mcfrs_console_init
);
1883 /****************************************************************************/