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/semaphore.h>
44 #include <asm/delay.h>
45 #include <asm/coldfire.h>
46 #include <asm/mcfsim.h>
47 #include <asm/mcfuart.h>
48 #include <asm/nettel.h>
49 #include <asm/uaccess.h>
50 #include "mcfserial.h"
52 struct timer_list mcfrs_timer_struct
;
55 * Default console baud rate, we use this as the default
56 * for all ports so init can just open /dev/console and
57 * keep going. Perhaps one day the cflag settings for the
58 * console can be used instead.
60 #if defined(CONFIG_HW_FEITH)
61 #define CONSOLE_BAUD_RATE 38400
62 #define DEFAULT_CBAUD B38400
63 #elif defined(CONFIG_MOD5272) || defined(CONFIG_M5208EVB) || defined(CONFIG_M5329EVB)
64 #define CONSOLE_BAUD_RATE 115200
65 #define DEFAULT_CBAUD B115200
66 #elif defined(CONFIG_ARNEWSH) || defined(CONFIG_FREESCALE) || \
67 defined(CONFIG_senTec) || defined(CONFIG_SNEHA) || defined(CONFIG_AVNET)
68 #define CONSOLE_BAUD_RATE 19200
69 #define DEFAULT_CBAUD B19200
72 #ifndef CONSOLE_BAUD_RATE
73 #define CONSOLE_BAUD_RATE 9600
74 #define DEFAULT_CBAUD B9600
77 int mcfrs_console_inited
= 0;
78 int mcfrs_console_port
= -1;
79 int mcfrs_console_baud
= CONSOLE_BAUD_RATE
;
80 int mcfrs_console_cbaud
= DEFAULT_CBAUD
;
83 * Driver data structures.
85 static struct tty_driver
*mcfrs_serial_driver
;
87 /* number of characters left in xmit buffer before we ask for more */
88 #define WAKEUP_CHARS 256
92 #undef SERIAL_DEBUG_OPEN
93 #undef SERIAL_DEBUG_FLOW
95 #if defined(CONFIG_M523x) || defined(CONFIG_M527x) || defined(CONFIG_M528x) || \
96 defined(CONFIG_M520x) || defined(CONFIG_M532x)
97 #define IRQBASE (MCFINT_VECBASE+MCFINT_UART0)
103 * Configuration table, UARTs to look for at startup.
105 static struct mcf_serial mcfrs_table
[] = {
108 .addr
= (volatile unsigned char *) (MCF_MBAR
+MCFUART_BASE1
),
110 .flags
= ASYNC_BOOT_AUTOCONF
,
114 .addr
= (volatile unsigned char *) (MCF_MBAR
+MCFUART_BASE2
),
116 .flags
= ASYNC_BOOT_AUTOCONF
,
121 #define NR_PORTS (sizeof(mcfrs_table) / sizeof(struct mcf_serial))
124 * This is used to figure out the divisor speeds and the timeouts.
126 static int mcfrs_baud_table
[] = {
127 0, 50, 75, 110, 134, 150, 200, 300, 600, 1200, 1800, 2400, 4800,
128 9600, 19200, 38400, 57600, 115200, 230400, 460800, 0
130 #define MCFRS_BAUD_TABLE_SIZE \
131 (sizeof(mcfrs_baud_table)/sizeof(mcfrs_baud_table[0]))
134 #ifdef CONFIG_MAGIC_SYSRQ
136 * Magic system request keys. Used for debugging...
138 extern int magic_sysrq_key(int ch
);
143 * Forware declarations...
145 static void mcfrs_change_speed(struct mcf_serial
*info
);
146 static void mcfrs_wait_until_sent(struct tty_struct
*tty
, int timeout
);
149 static inline int serial_paranoia_check(struct mcf_serial
*info
,
150 char *name
, const char *routine
)
152 #ifdef SERIAL_PARANOIA_CHECK
153 static const char badmagic
[] =
154 "MCFRS(warning): bad magic number for serial struct %s in %s\n";
155 static const char badinfo
[] =
156 "MCFRS(warning): null mcf_serial for %s in %s\n";
159 printk(badinfo
, name
, routine
);
162 if (info
->magic
!= SERIAL_MAGIC
) {
163 printk(badmagic
, name
, routine
);
171 * Sets or clears DTR and RTS on the requested line.
173 static void mcfrs_setsignals(struct mcf_serial
*info
, int dtr
, int rts
)
175 volatile unsigned char *uartp
;
179 printk("%s(%d): mcfrs_setsignals(info=%x,dtr=%d,rts=%d)\n",
180 __FILE__
, __LINE__
, info
, dtr
, rts
);
183 local_irq_save(flags
);
187 mcf_setppdata(MCFPP_DTR1
, (dtr
? 0 : MCFPP_DTR1
));
189 mcf_setppdata(MCFPP_DTR0
, (dtr
? 0 : MCFPP_DTR0
));
195 info
->sigs
|= TIOCM_RTS
;
196 uartp
[MCFUART_UOP1
] = MCFUART_UOP_RTS
;
198 info
->sigs
&= ~TIOCM_RTS
;
199 uartp
[MCFUART_UOP0
] = MCFUART_UOP_RTS
;
202 local_irq_restore(flags
);
207 * Gets values of serial signals.
209 static int mcfrs_getsignals(struct mcf_serial
*info
)
211 volatile unsigned char *uartp
;
214 #if defined(CONFIG_NETtel) && defined(CONFIG_M5307)
215 unsigned short ppdata
;
219 printk("%s(%d): mcfrs_getsignals(info=%x)\n", __FILE__
, __LINE__
);
222 local_irq_save(flags
);
224 sigs
= (uartp
[MCFUART_UIPR
] & MCFUART_UIPR_CTS
) ? 0 : TIOCM_CTS
;
225 sigs
|= (info
->sigs
& TIOCM_RTS
);
230 ppdata
= mcf_getppdata();
231 if (info
->line
== 0) {
232 sigs
|= (ppdata
& MCFPP_DCD0
) ? 0 : TIOCM_CD
;
233 sigs
|= (ppdata
& MCFPP_DTR0
) ? 0 : TIOCM_DTR
;
234 } else if (info
->line
== 1) {
235 sigs
|= (ppdata
& MCFPP_DCD1
) ? 0 : TIOCM_CD
;
236 sigs
|= (ppdata
& MCFPP_DTR1
) ? 0 : TIOCM_DTR
;
241 local_irq_restore(flags
);
246 * ------------------------------------------------------------
247 * mcfrs_stop() and mcfrs_start()
249 * This routines are called before setting or resetting tty->stopped.
250 * They enable or disable transmitter interrupts, as necessary.
251 * ------------------------------------------------------------
253 static void mcfrs_stop(struct tty_struct
*tty
)
255 volatile unsigned char *uartp
;
256 struct mcf_serial
*info
= (struct mcf_serial
*)tty
->driver_data
;
259 if (serial_paranoia_check(info
, tty
->name
, "mcfrs_stop"))
262 local_irq_save(flags
);
264 info
->imr
&= ~MCFUART_UIR_TXREADY
;
265 uartp
[MCFUART_UIMR
] = info
->imr
;
266 local_irq_restore(flags
);
269 static void mcfrs_start(struct tty_struct
*tty
)
271 volatile unsigned char *uartp
;
272 struct mcf_serial
*info
= (struct mcf_serial
*)tty
->driver_data
;
275 if (serial_paranoia_check(info
, tty
->name
, "mcfrs_start"))
278 local_irq_save(flags
);
279 if (info
->xmit_cnt
&& info
->xmit_buf
) {
281 info
->imr
|= MCFUART_UIR_TXREADY
;
282 uartp
[MCFUART_UIMR
] = info
->imr
;
284 local_irq_restore(flags
);
288 * ----------------------------------------------------------------------
290 * Here starts the interrupt handling routines. All of the following
291 * subroutines are declared as inline and are folded into
292 * mcfrs_interrupt(). They were separated out for readability's sake.
294 * Note: mcfrs_interrupt() is a "fast" interrupt, which means that it
295 * runs with interrupts turned off. People who may want to modify
296 * mcfrs_interrupt() should try to keep the interrupt handler as fast as
297 * possible. After you are done making modifications, it is not a bad
300 * gcc -S -DKERNEL -Wall -Wstrict-prototypes -O6 -fomit-frame-pointer serial.c
302 * and look at the resulting assemble code in serial.s.
304 * - Ted Ts'o (tytso@mit.edu), 7-Mar-93
305 * -----------------------------------------------------------------------
308 static inline void receive_chars(struct mcf_serial
*info
)
310 volatile unsigned char *uartp
;
311 struct tty_struct
*tty
= info
->tty
;
312 unsigned char status
, ch
, flag
;
319 while ((status
= uartp
[MCFUART_USR
]) & MCFUART_USR_RXREADY
) {
320 ch
= uartp
[MCFUART_URB
];
323 #ifdef CONFIG_MAGIC_SYSRQ
324 if (mcfrs_console_inited
&& (info
->line
== mcfrs_console_port
)) {
325 if (magic_sysrq_key(ch
))
331 if (status
& MCFUART_USR_RXERR
) {
332 uartp
[MCFUART_UCR
] = MCFUART_UCR_CMDRESETERR
;
333 if (status
& MCFUART_USR_RXBREAK
) {
334 info
->stats
.rxbreak
++;
336 } else if (status
& MCFUART_USR_RXPARITY
) {
337 info
->stats
.rxparity
++;
339 } else if (status
& MCFUART_USR_RXOVERRUN
) {
340 info
->stats
.rxoverrun
++;
342 } else if (status
& MCFUART_USR_RXFRAMING
) {
343 info
->stats
.rxframing
++;
347 tty_insert_flip_char(tty
, ch
, flag
);
349 tty_schedule_flip(tty
);
353 static inline void transmit_chars(struct mcf_serial
*info
)
355 volatile unsigned char *uartp
;
360 /* Send special char - probably flow control */
361 uartp
[MCFUART_UTB
] = info
->x_char
;
366 if ((info
->xmit_cnt
<= 0) || info
->tty
->stopped
) {
367 info
->imr
&= ~MCFUART_UIR_TXREADY
;
368 uartp
[MCFUART_UIMR
] = info
->imr
;
372 while (uartp
[MCFUART_USR
] & MCFUART_USR_TXREADY
) {
373 uartp
[MCFUART_UTB
] = info
->xmit_buf
[info
->xmit_tail
++];
374 info
->xmit_tail
= info
->xmit_tail
& (SERIAL_XMIT_SIZE
-1);
376 if (--info
->xmit_cnt
<= 0)
380 if (info
->xmit_cnt
< WAKEUP_CHARS
)
381 schedule_work(&info
->tqueue
);
386 * This is the serial driver's generic interrupt routine
388 irqreturn_t
mcfrs_interrupt(int irq
, void *dev_id
, struct pt_regs
*regs
)
390 struct mcf_serial
*info
;
393 info
= &mcfrs_table
[(irq
- IRQBASE
)];
394 isr
= info
->addr
[MCFUART_UISR
] & info
->imr
;
396 if (isr
& MCFUART_UIR_RXREADY
)
398 if (isr
& MCFUART_UIR_TXREADY
)
399 transmit_chars(info
);
404 * -------------------------------------------------------------------
405 * Here ends the serial interrupt routines.
406 * -------------------------------------------------------------------
409 static void mcfrs_offintr(void *private)
411 struct mcf_serial
*info
= (struct mcf_serial
*) private;
412 struct tty_struct
*tty
;
422 * Change of state on a DCD line.
424 void mcfrs_modem_change(struct mcf_serial
*info
, int dcd
)
426 if (info
->count
== 0)
429 if (info
->flags
& ASYNC_CHECK_CD
) {
431 wake_up_interruptible(&info
->open_wait
);
433 schedule_work(&info
->tqueue_hangup
);
440 unsigned short mcfrs_ppstatus
;
443 * This subroutine is called when the RS_TIMER goes off. It is used
444 * to monitor the state of the DCD lines - since they have no edge
445 * sensors and interrupt generators.
447 static void mcfrs_timer(void)
449 unsigned int ppstatus
, dcdval
, i
;
451 ppstatus
= mcf_getppdata() & (MCFPP_DCD0
| MCFPP_DCD1
);
453 if (ppstatus
!= mcfrs_ppstatus
) {
454 for (i
= 0; (i
< 2); i
++) {
455 dcdval
= (i
? MCFPP_DCD1
: MCFPP_DCD0
);
456 if ((ppstatus
& dcdval
) != (mcfrs_ppstatus
& dcdval
)) {
457 mcfrs_modem_change(&mcfrs_table
[i
],
458 ((ppstatus
& dcdval
) ? 0 : 1));
462 mcfrs_ppstatus
= ppstatus
;
465 mcfrs_timer_struct
.expires
= jiffies
+ HZ
/25;
466 add_timer(&mcfrs_timer_struct
);
469 #endif /* MCFPP_DCD0 */
473 * This routine is called from the scheduler tqueue when the interrupt
474 * routine has signalled that a hangup has occurred. The path of
475 * hangup processing is:
477 * serial interrupt routine -> (scheduler tqueue) ->
478 * do_serial_hangup() -> tty->hangup() -> mcfrs_hangup()
481 static void do_serial_hangup(void *private)
483 struct mcf_serial
*info
= (struct mcf_serial
*) private;
484 struct tty_struct
*tty
;
493 static int startup(struct mcf_serial
* info
)
495 volatile unsigned char *uartp
;
498 if (info
->flags
& ASYNC_INITIALIZED
)
501 if (!info
->xmit_buf
) {
502 info
->xmit_buf
= (unsigned char *) __get_free_page(GFP_KERNEL
);
507 local_irq_save(flags
);
509 #ifdef SERIAL_DEBUG_OPEN
510 printk("starting up ttyS%d (irq %d)...\n", info
->line
, info
->irq
);
514 * Reset UART, get it into known state...
517 uartp
[MCFUART_UCR
] = MCFUART_UCR_CMDRESETRX
; /* reset RX */
518 uartp
[MCFUART_UCR
] = MCFUART_UCR_CMDRESETTX
; /* reset TX */
519 mcfrs_setsignals(info
, 1, 1);
522 clear_bit(TTY_IO_ERROR
, &info
->tty
->flags
);
523 info
->xmit_cnt
= info
->xmit_head
= info
->xmit_tail
= 0;
526 * and set the speed of the serial port
528 mcfrs_change_speed(info
);
531 * Lastly enable the UART transmitter and receiver, and
534 info
->imr
= MCFUART_UIR_RXREADY
;
535 uartp
[MCFUART_UCR
] = MCFUART_UCR_RXENABLE
| MCFUART_UCR_TXENABLE
;
536 uartp
[MCFUART_UIMR
] = info
->imr
;
538 info
->flags
|= ASYNC_INITIALIZED
;
539 local_irq_restore(flags
);
544 * This routine will shutdown a serial port; interrupts are disabled, and
545 * DTR is dropped if the hangup on close termio flag is on.
547 static void shutdown(struct mcf_serial
* info
)
549 volatile unsigned char *uartp
;
552 if (!(info
->flags
& ASYNC_INITIALIZED
))
555 #ifdef SERIAL_DEBUG_OPEN
556 printk("Shutting down serial port %d (irq %d)....\n", info
->line
,
560 local_irq_save(flags
);
563 uartp
[MCFUART_UIMR
] = 0; /* mask all interrupts */
564 uartp
[MCFUART_UCR
] = MCFUART_UCR_CMDRESETRX
; /* reset RX */
565 uartp
[MCFUART_UCR
] = MCFUART_UCR_CMDRESETTX
; /* reset TX */
567 if (!info
->tty
|| (info
->tty
->termios
->c_cflag
& HUPCL
))
568 mcfrs_setsignals(info
, 0, 0);
570 if (info
->xmit_buf
) {
571 free_page((unsigned long) info
->xmit_buf
);
576 set_bit(TTY_IO_ERROR
, &info
->tty
->flags
);
578 info
->flags
&= ~ASYNC_INITIALIZED
;
579 local_irq_restore(flags
);
584 * This routine is called to set the UART divisor registers to match
585 * the specified baud rate for a serial port.
587 static void mcfrs_change_speed(struct mcf_serial
*info
)
589 volatile unsigned char *uartp
;
590 unsigned int baudclk
, cflag
;
592 unsigned char mr1
, mr2
;
595 unsigned int fraction
;
598 if (!info
->tty
|| !info
->tty
->termios
)
600 cflag
= info
->tty
->termios
->c_cflag
;
605 printk("%s(%d): mcfrs_change_speed()\n", __FILE__
, __LINE__
);
612 info
->tty
->termios
->c_cflag
&= ~CBAUDEX
;
617 mcfrs_setsignals(info
, 0, -1);
621 /* compute the baudrate clock */
624 * For the MCF5272, also compute the baudrate fraction.
626 baudclk
= (MCF_BUSCLK
/ mcfrs_baud_table
[i
]) / 32;
627 fraction
= MCF_BUSCLK
- (baudclk
* 32 * mcfrs_baud_table
[i
]);
629 fraction
/= (32 * mcfrs_baud_table
[i
]);
631 baudclk
= ((MCF_BUSCLK
/ mcfrs_baud_table
[i
]) + 16) / 32;
634 info
->baud
= mcfrs_baud_table
[i
];
636 mr1
= MCFUART_MR1_RXIRQRDY
| MCFUART_MR1_RXERRCHAR
;
639 switch (cflag
& CSIZE
) {
640 case CS5
: mr1
|= MCFUART_MR1_CS5
; break;
641 case CS6
: mr1
|= MCFUART_MR1_CS6
; break;
642 case CS7
: mr1
|= MCFUART_MR1_CS7
; break;
644 default: mr1
|= MCFUART_MR1_CS8
; break;
647 if (cflag
& PARENB
) {
648 if (cflag
& CMSPAR
) {
650 mr1
|= MCFUART_MR1_PARITYMARK
;
652 mr1
|= MCFUART_MR1_PARITYSPACE
;
655 mr1
|= MCFUART_MR1_PARITYODD
;
657 mr1
|= MCFUART_MR1_PARITYEVEN
;
660 mr1
|= MCFUART_MR1_PARITYNONE
;
664 mr2
|= MCFUART_MR2_STOP2
;
666 mr2
|= MCFUART_MR2_STOP1
;
668 if (cflag
& CRTSCTS
) {
669 mr1
|= MCFUART_MR1_RXRTS
;
670 mr2
|= MCFUART_MR2_TXCTS
;
674 info
->flags
&= ~ASYNC_CHECK_CD
;
676 info
->flags
|= ASYNC_CHECK_CD
;
680 local_irq_save(flags
);
682 printk("%s(%d): mr1=%x mr2=%x baudclk=%x\n", __FILE__
, __LINE__
,
686 Note: pg 12-16 of MCF5206e User's Manual states that a
687 software reset should be performed prior to changing
688 UMR1,2, UCSR, UACR, bit 7
690 uartp
[MCFUART_UCR
] = MCFUART_UCR_CMDRESETRX
; /* reset RX */
691 uartp
[MCFUART_UCR
] = MCFUART_UCR_CMDRESETTX
; /* reset TX */
692 uartp
[MCFUART_UCR
] = MCFUART_UCR_CMDRESETMRPTR
; /* reset MR pointer */
693 uartp
[MCFUART_UMR
] = mr1
;
694 uartp
[MCFUART_UMR
] = mr2
;
695 uartp
[MCFUART_UBG1
] = (baudclk
& 0xff00) >> 8; /* set msb byte */
696 uartp
[MCFUART_UBG2
] = (baudclk
& 0xff); /* set lsb byte */
698 uartp
[MCFUART_UFPD
] = (fraction
& 0xf); /* set fraction */
700 uartp
[MCFUART_UCSR
] = MCFUART_UCSR_RXCLKTIMER
| MCFUART_UCSR_TXCLKTIMER
;
701 uartp
[MCFUART_UCR
] = MCFUART_UCR_RXENABLE
| MCFUART_UCR_TXENABLE
;
702 mcfrs_setsignals(info
, 1, -1);
703 local_irq_restore(flags
);
707 static void mcfrs_flush_chars(struct tty_struct
*tty
)
709 volatile unsigned char *uartp
;
710 struct mcf_serial
*info
= (struct mcf_serial
*)tty
->driver_data
;
713 if (serial_paranoia_check(info
, tty
->name
, "mcfrs_flush_chars"))
716 uartp
= (volatile unsigned char *) info
->addr
;
719 * re-enable receiver interrupt
721 local_irq_save(flags
);
722 if ((!(info
->imr
& MCFUART_UIR_RXREADY
)) &&
723 (info
->flags
& ASYNC_INITIALIZED
) ) {
724 info
->imr
|= MCFUART_UIR_RXREADY
;
725 uartp
[MCFUART_UIMR
] = info
->imr
;
727 local_irq_restore(flags
);
729 if (info
->xmit_cnt
<= 0 || tty
->stopped
|| tty
->hw_stopped
||
733 /* Enable transmitter */
734 local_irq_save(flags
);
735 info
->imr
|= MCFUART_UIR_TXREADY
;
736 uartp
[MCFUART_UIMR
] = info
->imr
;
737 local_irq_restore(flags
);
740 static int mcfrs_write(struct tty_struct
* tty
,
741 const unsigned char *buf
, int count
)
743 volatile unsigned char *uartp
;
744 struct mcf_serial
*info
= (struct mcf_serial
*)tty
->driver_data
;
749 printk("%s(%d): mcfrs_write(tty=%x,buf=%x,count=%d)\n",
750 __FILE__
, __LINE__
, (int)tty
, (int)buf
, count
);
753 if (serial_paranoia_check(info
, tty
->name
, "mcfrs_write"))
756 if (!tty
|| !info
->xmit_buf
)
759 local_save_flags(flags
);
762 c
= min(count
, (int) min(((int)SERIAL_XMIT_SIZE
) - info
->xmit_cnt
- 1,
763 ((int)SERIAL_XMIT_SIZE
) - info
->xmit_head
));
764 local_irq_restore(flags
);
769 memcpy(info
->xmit_buf
+ info
->xmit_head
, buf
, c
);
772 info
->xmit_head
= (info
->xmit_head
+ c
) & (SERIAL_XMIT_SIZE
-1);
774 local_irq_restore(flags
);
783 info
->imr
|= MCFUART_UIR_TXREADY
;
784 uartp
[MCFUART_UIMR
] = info
->imr
;
785 local_irq_restore(flags
);
790 static int mcfrs_write_room(struct tty_struct
*tty
)
792 struct mcf_serial
*info
= (struct mcf_serial
*)tty
->driver_data
;
795 if (serial_paranoia_check(info
, tty
->name
, "mcfrs_write_room"))
797 ret
= SERIAL_XMIT_SIZE
- info
->xmit_cnt
- 1;
803 static int mcfrs_chars_in_buffer(struct tty_struct
*tty
)
805 struct mcf_serial
*info
= (struct mcf_serial
*)tty
->driver_data
;
807 if (serial_paranoia_check(info
, tty
->name
, "mcfrs_chars_in_buffer"))
809 return info
->xmit_cnt
;
812 static void mcfrs_flush_buffer(struct tty_struct
*tty
)
814 struct mcf_serial
*info
= (struct mcf_serial
*)tty
->driver_data
;
817 if (serial_paranoia_check(info
, tty
->name
, "mcfrs_flush_buffer"))
820 local_irq_save(flags
);
821 info
->xmit_cnt
= info
->xmit_head
= info
->xmit_tail
= 0;
822 local_irq_restore(flags
);
828 * ------------------------------------------------------------
831 * This routine is called by the upper-layer tty layer to signal that
832 * incoming characters should be throttled.
833 * ------------------------------------------------------------
835 static void mcfrs_throttle(struct tty_struct
* tty
)
837 struct mcf_serial
*info
= (struct mcf_serial
*)tty
->driver_data
;
838 #ifdef SERIAL_DEBUG_THROTTLE
841 printk("throttle %s: %d....\n", _tty_name(tty
, buf
),
842 tty
->ldisc
.chars_in_buffer(tty
));
845 if (serial_paranoia_check(info
, tty
->name
, "mcfrs_throttle"))
849 info
->x_char
= STOP_CHAR(tty
);
851 /* Turn off RTS line (do this atomic) */
854 static void mcfrs_unthrottle(struct tty_struct
* tty
)
856 struct mcf_serial
*info
= (struct mcf_serial
*)tty
->driver_data
;
857 #ifdef SERIAL_DEBUG_THROTTLE
860 printk("unthrottle %s: %d....\n", _tty_name(tty
, buf
),
861 tty
->ldisc
.chars_in_buffer(tty
));
864 if (serial_paranoia_check(info
, tty
->name
, "mcfrs_unthrottle"))
871 info
->x_char
= START_CHAR(tty
);
874 /* Assert RTS line (do this atomic) */
878 * ------------------------------------------------------------
879 * mcfrs_ioctl() and friends
880 * ------------------------------------------------------------
883 static int get_serial_info(struct mcf_serial
* info
,
884 struct serial_struct
* retinfo
)
886 struct serial_struct tmp
;
890 memset(&tmp
, 0, sizeof(tmp
));
891 tmp
.type
= info
->type
;
892 tmp
.line
= info
->line
;
893 tmp
.port
= (unsigned int) info
->addr
;
895 tmp
.flags
= info
->flags
;
896 tmp
.baud_base
= info
->baud_base
;
897 tmp
.close_delay
= info
->close_delay
;
898 tmp
.closing_wait
= info
->closing_wait
;
899 tmp
.custom_divisor
= info
->custom_divisor
;
900 return copy_to_user(retinfo
,&tmp
,sizeof(*retinfo
)) ? -EFAULT
: 0;
903 static int set_serial_info(struct mcf_serial
* info
,
904 struct serial_struct
* new_info
)
906 struct serial_struct new_serial
;
907 struct mcf_serial old_info
;
912 if (copy_from_user(&new_serial
,new_info
,sizeof(new_serial
)))
916 if (!capable(CAP_SYS_ADMIN
)) {
917 if ((new_serial
.baud_base
!= info
->baud_base
) ||
918 (new_serial
.type
!= info
->type
) ||
919 (new_serial
.close_delay
!= info
->close_delay
) ||
920 ((new_serial
.flags
& ~ASYNC_USR_MASK
) !=
921 (info
->flags
& ~ASYNC_USR_MASK
)))
923 info
->flags
= ((info
->flags
& ~ASYNC_USR_MASK
) |
924 (new_serial
.flags
& ASYNC_USR_MASK
));
925 info
->custom_divisor
= new_serial
.custom_divisor
;
933 * OK, past this point, all the error checking has been done.
934 * At this point, we start making changes.....
937 info
->baud_base
= new_serial
.baud_base
;
938 info
->flags
= ((info
->flags
& ~ASYNC_FLAGS
) |
939 (new_serial
.flags
& ASYNC_FLAGS
));
940 info
->type
= new_serial
.type
;
941 info
->close_delay
= new_serial
.close_delay
;
942 info
->closing_wait
= new_serial
.closing_wait
;
945 retval
= startup(info
);
950 * get_lsr_info - get line status register info
952 * Purpose: Let user call ioctl() to get info when the UART physically
953 * is emptied. On bus types like RS485, the transmitter must
954 * release the bus after transmitting. This must be done when
955 * the transmit shift register is empty, not be done when the
956 * transmit holding register is empty. This functionality
957 * allows an RS485 driver to be written in user space.
959 static int get_lsr_info(struct mcf_serial
* info
, unsigned int *value
)
961 volatile unsigned char *uartp
;
963 unsigned char status
;
965 local_irq_save(flags
);
967 status
= (uartp
[MCFUART_USR
] & MCFUART_USR_TXEMPTY
) ? TIOCSER_TEMT
: 0;
968 local_irq_restore(flags
);
970 return put_user(status
,value
);
974 * This routine sends a break character out the serial port.
976 static void send_break( struct mcf_serial
* info
, int duration
)
978 volatile unsigned char *uartp
;
983 set_current_state(TASK_INTERRUPTIBLE
);
986 local_irq_save(flags
);
987 uartp
[MCFUART_UCR
] = MCFUART_UCR_CMDBREAKSTART
;
988 schedule_timeout(duration
);
989 uartp
[MCFUART_UCR
] = MCFUART_UCR_CMDBREAKSTOP
;
990 local_irq_restore(flags
);
993 static int mcfrs_tiocmget(struct tty_struct
*tty
, struct file
*file
)
995 struct mcf_serial
* info
= (struct mcf_serial
*)tty
->driver_data
;
997 if (serial_paranoia_check(info
, tty
->name
, "mcfrs_ioctl"))
999 if (tty
->flags
& (1 << TTY_IO_ERROR
))
1002 return mcfrs_getsignals(info
);
1005 static int mcfrs_tiocmset(struct tty_struct
*tty
, struct file
*file
,
1006 unsigned int set
, unsigned int clear
)
1008 struct mcf_serial
* info
= (struct mcf_serial
*)tty
->driver_data
;
1009 int rts
= -1, dtr
= -1;
1011 if (serial_paranoia_check(info
, tty
->name
, "mcfrs_ioctl"))
1013 if (tty
->flags
& (1 << TTY_IO_ERROR
))
1016 if (set
& TIOCM_RTS
)
1018 if (set
& TIOCM_DTR
)
1020 if (clear
& TIOCM_RTS
)
1022 if (clear
& TIOCM_DTR
)
1025 mcfrs_setsignals(info
, dtr
, rts
);
1030 static int mcfrs_ioctl(struct tty_struct
*tty
, struct file
* file
,
1031 unsigned int cmd
, unsigned long arg
)
1033 struct mcf_serial
* info
= (struct mcf_serial
*)tty
->driver_data
;
1036 if (serial_paranoia_check(info
, tty
->name
, "mcfrs_ioctl"))
1039 if ((cmd
!= TIOCGSERIAL
) && (cmd
!= TIOCSSERIAL
) &&
1040 (cmd
!= TIOCSERCONFIG
) && (cmd
!= TIOCSERGWILD
) &&
1041 (cmd
!= TIOCSERSWILD
) && (cmd
!= TIOCSERGSTRUCT
)) {
1042 if (tty
->flags
& (1 << TTY_IO_ERROR
))
1047 case TCSBRK
: /* SVID version: non-zero arg --> no break */
1048 retval
= tty_check_change(tty
);
1051 tty_wait_until_sent(tty
, 0);
1053 send_break(info
, HZ
/4); /* 1/4 second */
1055 case TCSBRKP
: /* support for POSIX tcsendbreak() */
1056 retval
= tty_check_change(tty
);
1059 tty_wait_until_sent(tty
, 0);
1060 send_break(info
, arg
? arg
*(HZ
/10) : HZ
/4);
1063 error
= put_user(C_CLOCAL(tty
) ? 1 : 0,
1064 (unsigned long *) arg
);
1069 get_user(arg
, (unsigned long *) arg
);
1070 tty
->termios
->c_cflag
=
1071 ((tty
->termios
->c_cflag
& ~CLOCAL
) |
1072 (arg
? CLOCAL
: 0));
1075 if (access_ok(VERIFY_WRITE
, (void *) arg
,
1076 sizeof(struct serial_struct
)))
1077 return get_serial_info(info
,
1078 (struct serial_struct
*) arg
);
1081 return set_serial_info(info
,
1082 (struct serial_struct
*) arg
);
1083 case TIOCSERGETLSR
: /* Get line status register */
1084 if (access_ok(VERIFY_WRITE
, (void *) arg
,
1085 sizeof(unsigned int)))
1086 return get_lsr_info(info
, (unsigned int *) arg
);
1088 case TIOCSERGSTRUCT
:
1089 error
= copy_to_user((struct mcf_serial
*) arg
,
1090 info
, sizeof(struct mcf_serial
));
1098 get_user(val
, (unsigned int *) arg
);
1099 mcf_setpa(MCFPP_PA11
, (val
? 0 : MCFPP_PA11
));
1104 val
= (mcf_getpa() & MCFPP_PA11
) ? 0 : 1;
1105 put_user(val
, (unsigned int *) arg
);
1111 return -ENOIOCTLCMD
;
1116 static void mcfrs_set_termios(struct tty_struct
*tty
, struct termios
*old_termios
)
1118 struct mcf_serial
*info
= (struct mcf_serial
*)tty
->driver_data
;
1120 if (tty
->termios
->c_cflag
== old_termios
->c_cflag
)
1123 mcfrs_change_speed(info
);
1125 if ((old_termios
->c_cflag
& CRTSCTS
) &&
1126 !(tty
->termios
->c_cflag
& CRTSCTS
)) {
1127 tty
->hw_stopped
= 0;
1128 mcfrs_setsignals(info
, -1, 1);
1136 * ------------------------------------------------------------
1139 * This routine is called when the serial port gets closed. First, we
1140 * wait for the last remaining data to be sent. Then, we unlink its
1141 * S structure from the interrupt chain if necessary, and we free
1142 * that IRQ if nothing is left in the chain.
1143 * ------------------------------------------------------------
1145 static void mcfrs_close(struct tty_struct
*tty
, struct file
* filp
)
1147 volatile unsigned char *uartp
;
1148 struct mcf_serial
*info
= (struct mcf_serial
*)tty
->driver_data
;
1149 unsigned long flags
;
1151 if (!info
|| serial_paranoia_check(info
, tty
->name
, "mcfrs_close"))
1154 local_irq_save(flags
);
1156 if (tty_hung_up_p(filp
)) {
1157 local_irq_restore(flags
);
1161 #ifdef SERIAL_DEBUG_OPEN
1162 printk("mcfrs_close ttyS%d, count = %d\n", info
->line
, info
->count
);
1164 if ((tty
->count
== 1) && (info
->count
!= 1)) {
1166 * Uh, oh. tty->count is 1, which means that the tty
1167 * structure will be freed. Info->count should always
1168 * be one in these conditions. If it's greater than
1169 * one, we've got real problems, since it means the
1170 * serial port won't be shutdown.
1172 printk("MCFRS: bad serial port count; tty->count is 1, "
1173 "info->count is %d\n", info
->count
);
1176 if (--info
->count
< 0) {
1177 printk("MCFRS: bad serial port count for ttyS%d: %d\n",
1178 info
->line
, info
->count
);
1182 local_irq_restore(flags
);
1185 info
->flags
|= ASYNC_CLOSING
;
1188 * Now we wait for the transmit buffer to clear; and we notify
1189 * the line discipline to only process XON/XOFF characters.
1192 if (info
->closing_wait
!= ASYNC_CLOSING_WAIT_NONE
)
1193 tty_wait_until_sent(tty
, info
->closing_wait
);
1196 * At this point we stop accepting input. To do this, we
1197 * disable the receive line status interrupts, and tell the
1198 * interrupt driver to stop checking the data ready bit in the
1199 * line status register.
1201 info
->imr
&= ~MCFUART_UIR_RXREADY
;
1203 uartp
[MCFUART_UIMR
] = info
->imr
;
1206 /* FIXME: do we need to keep this enabled for console?? */
1207 if (mcfrs_console_inited
&& (mcfrs_console_port
== info
->line
)) {
1208 /* Do not disable the UART */ ;
1212 if (tty
->driver
->flush_buffer
)
1213 tty
->driver
->flush_buffer(tty
);
1214 tty_ldisc_flush(tty
);
1220 if (tty
->ldisc
.num
!= ldiscs
[N_TTY
].num
) {
1221 if (tty
->ldisc
.close
)
1222 (tty
->ldisc
.close
)(tty
);
1223 tty
->ldisc
= ldiscs
[N_TTY
];
1224 tty
->termios
->c_line
= N_TTY
;
1225 if (tty
->ldisc
.open
)
1226 (tty
->ldisc
.open
)(tty
);
1229 if (info
->blocked_open
) {
1230 if (info
->close_delay
) {
1231 msleep_interruptible(jiffies_to_msecs(info
->close_delay
));
1233 wake_up_interruptible(&info
->open_wait
);
1235 info
->flags
&= ~(ASYNC_NORMAL_ACTIVE
|ASYNC_CLOSING
);
1236 wake_up_interruptible(&info
->close_wait
);
1237 local_irq_restore(flags
);
1241 * mcfrs_wait_until_sent() --- wait until the transmitter is empty
1244 mcfrs_wait_until_sent(struct tty_struct
*tty
, int timeout
)
1247 #define MCF5272_FIFO_SIZE 25 /* fifo size + shift reg */
1249 struct mcf_serial
* info
= (struct mcf_serial
*)tty
->driver_data
;
1250 volatile unsigned char *uartp
;
1251 unsigned long orig_jiffies
, fifo_time
, char_time
, fifo_cnt
;
1253 if (serial_paranoia_check(info
, tty
->name
, "mcfrs_wait_until_sent"))
1256 orig_jiffies
= jiffies
;
1259 * Set the check interval to be 1/5 of the approximate time
1260 * to send the entire fifo, and make it at least 1. The check
1261 * interval should also be less than the timeout.
1263 * Note: we have to use pretty tight timings here to satisfy
1266 fifo_time
= (MCF5272_FIFO_SIZE
* HZ
* 10) / info
->baud
;
1267 char_time
= fifo_time
/ 5;
1270 if (timeout
&& timeout
< char_time
)
1271 char_time
= timeout
;
1274 * Clamp the timeout period at 2 * the time to empty the
1275 * fifo. Just to be safe, set the minimum at .5 seconds.
1278 if (fifo_time
< (HZ
/2))
1280 if (!timeout
|| timeout
> fifo_time
)
1281 timeout
= fifo_time
;
1284 * Account for the number of bytes in the UART
1285 * transmitter FIFO plus any byte being shifted out.
1287 uartp
= (volatile unsigned char *) info
->addr
;
1289 fifo_cnt
= (uartp
[MCFUART_UTF
] & MCFUART_UTF_TXB
);
1290 if ((uartp
[MCFUART_USR
] & (MCFUART_USR_TXREADY
|
1291 MCFUART_USR_TXEMPTY
)) ==
1292 MCFUART_USR_TXREADY
)
1296 msleep_interruptible(jiffies_to_msecs(char_time
));
1297 if (signal_pending(current
))
1299 if (timeout
&& time_after(jiffies
, orig_jiffies
+ timeout
))
1304 * For the other coldfire models, assume all data has been sent
1310 * mcfrs_hangup() --- called by tty_hangup() when a hangup is signaled.
1312 void mcfrs_hangup(struct tty_struct
*tty
)
1314 struct mcf_serial
* info
= (struct mcf_serial
*)tty
->driver_data
;
1316 if (serial_paranoia_check(info
, tty
->name
, "mcfrs_hangup"))
1319 mcfrs_flush_buffer(tty
);
1323 info
->flags
&= ~ASYNC_NORMAL_ACTIVE
;
1325 wake_up_interruptible(&info
->open_wait
);
1329 * ------------------------------------------------------------
1330 * mcfrs_open() and friends
1331 * ------------------------------------------------------------
1333 static int block_til_ready(struct tty_struct
*tty
, struct file
* filp
,
1334 struct mcf_serial
*info
)
1336 DECLARE_WAITQUEUE(wait
, current
);
1341 * If the device is in the middle of being closed, then block
1342 * until it's done, and then try again.
1344 if (info
->flags
& ASYNC_CLOSING
) {
1345 interruptible_sleep_on(&info
->close_wait
);
1346 #ifdef SERIAL_DO_RESTART
1347 if (info
->flags
& ASYNC_HUP_NOTIFY
)
1350 return -ERESTARTSYS
;
1357 * If non-blocking mode is set, or the port is not enabled,
1358 * then make the check up front and then exit.
1360 if ((filp
->f_flags
& O_NONBLOCK
) ||
1361 (tty
->flags
& (1 << TTY_IO_ERROR
))) {
1362 info
->flags
|= ASYNC_NORMAL_ACTIVE
;
1366 if (tty
->termios
->c_cflag
& CLOCAL
)
1370 * Block waiting for the carrier detect and the line to become
1371 * free (i.e., not in use by the callout). While we are in
1372 * this loop, info->count is dropped by one, so that
1373 * mcfrs_close() knows when to free things. We restore it upon
1374 * exit, either normal or abnormal.
1377 add_wait_queue(&info
->open_wait
, &wait
);
1378 #ifdef SERIAL_DEBUG_OPEN
1379 printk("block_til_ready before block: ttyS%d, count = %d\n",
1380 info
->line
, info
->count
);
1383 info
->blocked_open
++;
1385 local_irq_disable();
1386 mcfrs_setsignals(info
, 1, 1);
1388 current
->state
= TASK_INTERRUPTIBLE
;
1389 if (tty_hung_up_p(filp
) ||
1390 !(info
->flags
& ASYNC_INITIALIZED
)) {
1391 #ifdef SERIAL_DO_RESTART
1392 if (info
->flags
& ASYNC_HUP_NOTIFY
)
1395 retval
= -ERESTARTSYS
;
1401 if (!(info
->flags
& ASYNC_CLOSING
) &&
1402 (do_clocal
|| (mcfrs_getsignals(info
) & TIOCM_CD
)))
1404 if (signal_pending(current
)) {
1405 retval
= -ERESTARTSYS
;
1408 #ifdef SERIAL_DEBUG_OPEN
1409 printk("block_til_ready blocking: ttyS%d, count = %d\n",
1410 info
->line
, info
->count
);
1414 current
->state
= TASK_RUNNING
;
1415 remove_wait_queue(&info
->open_wait
, &wait
);
1416 if (!tty_hung_up_p(filp
))
1418 info
->blocked_open
--;
1419 #ifdef SERIAL_DEBUG_OPEN
1420 printk("block_til_ready after blocking: ttyS%d, count = %d\n",
1421 info
->line
, info
->count
);
1425 info
->flags
|= ASYNC_NORMAL_ACTIVE
;
1430 * This routine is called whenever a serial port is opened. It
1431 * enables interrupts for a serial port, linking in its structure into
1432 * the IRQ chain. It also performs the serial-specific
1433 * initialization for the tty structure.
1435 int mcfrs_open(struct tty_struct
*tty
, struct file
* filp
)
1437 struct mcf_serial
*info
;
1441 if ((line
< 0) || (line
>= NR_PORTS
))
1443 info
= mcfrs_table
+ line
;
1444 if (serial_paranoia_check(info
, tty
->name
, "mcfrs_open"))
1446 #ifdef SERIAL_DEBUG_OPEN
1447 printk("mcfrs_open %s, count = %d\n", tty
->name
, info
->count
);
1450 tty
->driver_data
= info
;
1454 * Start up serial port
1456 retval
= startup(info
);
1460 retval
= block_til_ready(tty
, filp
, info
);
1462 #ifdef SERIAL_DEBUG_OPEN
1463 printk("mcfrs_open returning after block_til_ready with %d\n",
1469 #ifdef SERIAL_DEBUG_OPEN
1470 printk("mcfrs_open %s successful...\n", tty
->name
);
1476 * Based on the line number set up the internal interrupt stuff.
1478 static void mcfrs_irqinit(struct mcf_serial
*info
)
1480 #if defined(CONFIG_M5272)
1481 volatile unsigned long *icrp
;
1482 volatile unsigned long *portp
;
1483 volatile unsigned char *uartp
;
1486 icrp
= (volatile unsigned long *) (MCF_MBAR
+ MCFSIM_ICR2
);
1488 switch (info
->line
) {
1496 printk("MCFRS: don't know how to handle UART %d interrupt?\n",
1501 /* Enable the output lines for the serial ports */
1502 portp
= (volatile unsigned long *) (MCF_MBAR
+ MCFSIM_PBCNT
);
1503 *portp
= (*portp
& ~0x000000ff) | 0x00000055;
1504 portp
= (volatile unsigned long *) (MCF_MBAR
+ MCFSIM_PDCNT
);
1505 *portp
= (*portp
& ~0x000003fc) | 0x000002a8;
1506 #elif defined(CONFIG_M523x) || defined(CONFIG_M527x) || defined(CONFIG_M528x)
1507 volatile unsigned char *icrp
, *uartp
;
1508 volatile unsigned long *imrp
;
1512 icrp
= (volatile unsigned char *) (MCF_MBAR
+ MCFICM_INTC0
+
1513 MCFINTC_ICR0
+ MCFINT_UART0
+ info
->line
);
1514 *icrp
= 0x30 + info
->line
; /* level 6, line based priority */
1516 imrp
= (volatile unsigned long *) (MCF_MBAR
+ MCFICM_INTC0
+
1518 *imrp
&= ~((1 << (info
->irq
- MCFINT_VECBASE
)) | 1);
1519 #elif defined(CONFIG_M520x)
1520 volatile unsigned char *icrp
, *uartp
;
1521 volatile unsigned long *imrp
;
1525 icrp
= (volatile unsigned char *) (MCF_MBAR
+ MCFICM_INTC0
+
1526 MCFINTC_ICR0
+ MCFINT_UART0
+ info
->line
);
1529 imrp
= (volatile unsigned long *) (MCF_MBAR
+ MCFICM_INTC0
+
1531 *imrp
&= ~((1 << (info
->irq
- MCFINT_VECBASE
)) | 1);
1532 if (info
->line
< 2) {
1533 unsigned short *uart_par
;
1534 uart_par
= (unsigned short *)(MCF_IPSBAR
+ MCF_GPIO_PAR_UART
);
1535 if (info
->line
== 0)
1536 *uart_par
|= MCF_GPIO_PAR_UART_PAR_UTXD0
1537 | MCF_GPIO_PAR_UART_PAR_URXD0
;
1538 else if (info
->line
== 1)
1539 *uart_par
|= MCF_GPIO_PAR_UART_PAR_UTXD1
1540 | MCF_GPIO_PAR_UART_PAR_URXD1
;
1541 } else if (info
->line
== 2) {
1542 unsigned char *feci2c_par
;
1543 feci2c_par
= (unsigned char *)(MCF_IPSBAR
+ MCF_GPIO_PAR_FECI2C
);
1544 *feci2c_par
&= ~0x0F;
1545 *feci2c_par
|= MCF_GPIO_PAR_FECI2C_PAR_SCL_UTXD2
1546 | MCF_GPIO_PAR_FECI2C_PAR_SDA_URXD2
;
1548 #elif defined(CONFIG_M532x)
1549 volatile unsigned char *uartp
;
1551 switch (info
->line
) {
1553 MCF_INTC0_ICR26
= 0x3;
1554 MCF_INTC0_CIMR
= 26;
1555 /* GPIO initialization */
1556 MCF_GPIO_PAR_UART
|= 0x000F;
1559 MCF_INTC0_ICR27
= 0x3;
1560 MCF_INTC0_CIMR
= 27;
1561 /* GPIO initialization */
1562 MCF_GPIO_PAR_UART
|= 0x0FF0;
1565 MCF_INTC0_ICR28
= 0x3;
1566 MCF_INTC0_CIMR
= 28;
1567 /* GPIOs also must be initalized, depends on board */
1571 volatile unsigned char *icrp
, *uartp
;
1573 switch (info
->line
) {
1575 icrp
= (volatile unsigned char *) (MCF_MBAR
+ MCFSIM_UART1ICR
);
1576 *icrp
= /*MCFSIM_ICR_AUTOVEC |*/ MCFSIM_ICR_LEVEL6
|
1578 mcf_setimr(mcf_getimr() & ~MCFSIM_IMR_UART1
);
1581 icrp
= (volatile unsigned char *) (MCF_MBAR
+ MCFSIM_UART2ICR
);
1582 *icrp
= /*MCFSIM_ICR_AUTOVEC |*/ MCFSIM_ICR_LEVEL6
|
1584 mcf_setimr(mcf_getimr() & ~MCFSIM_IMR_UART2
);
1587 printk("MCFRS: don't know how to handle UART %d interrupt?\n",
1593 uartp
[MCFUART_UIVR
] = info
->irq
;
1596 /* Clear mask, so no surprise interrupts. */
1597 uartp
[MCFUART_UIMR
] = 0;
1599 if (request_irq(info
->irq
, mcfrs_interrupt
, SA_INTERRUPT
,
1600 "ColdFire UART", NULL
)) {
1601 printk("MCFRS: Unable to attach ColdFire UART %d interrupt "
1602 "vector=%d\n", info
->line
, info
->irq
);
1609 char *mcfrs_drivername
= "ColdFire internal UART serial driver version 1.00\n";
1613 * Serial stats reporting...
1615 int mcfrs_readproc(char *page
, char **start
, off_t off
, int count
,
1616 int *eof
, void *data
)
1618 struct mcf_serial
*info
;
1622 len
= sprintf(page
, mcfrs_drivername
);
1623 for (i
= 0; (i
< NR_PORTS
); i
++) {
1624 info
= &mcfrs_table
[i
];
1625 len
+= sprintf((page
+ len
), "%d: port:%x irq=%d baud:%d ",
1626 i
, (unsigned int) info
->addr
, info
->irq
, info
->baud
);
1627 if (info
->stats
.rx
|| info
->stats
.tx
)
1628 len
+= sprintf((page
+ len
), "tx:%d rx:%d ",
1629 info
->stats
.tx
, info
->stats
.rx
);
1630 if (info
->stats
.rxframing
)
1631 len
+= sprintf((page
+ len
), "fe:%d ",
1632 info
->stats
.rxframing
);
1633 if (info
->stats
.rxparity
)
1634 len
+= sprintf((page
+ len
), "pe:%d ",
1635 info
->stats
.rxparity
);
1636 if (info
->stats
.rxbreak
)
1637 len
+= sprintf((page
+ len
), "brk:%d ",
1638 info
->stats
.rxbreak
);
1639 if (info
->stats
.rxoverrun
)
1640 len
+= sprintf((page
+ len
), "oe:%d ",
1641 info
->stats
.rxoverrun
);
1643 str
[0] = str
[1] = 0;
1644 if ((sigs
= mcfrs_getsignals(info
))) {
1645 if (sigs
& TIOCM_RTS
)
1646 strcat(str
, "|RTS");
1647 if (sigs
& TIOCM_CTS
)
1648 strcat(str
, "|CTS");
1649 if (sigs
& TIOCM_DTR
)
1650 strcat(str
, "|DTR");
1651 if (sigs
& TIOCM_CD
)
1655 len
+= sprintf((page
+ len
), "%s\n", &str
[1]);
1662 /* Finally, routines used to initialize the serial driver. */
1664 static void show_serial_version(void)
1666 printk(mcfrs_drivername
);
1669 static struct tty_operations mcfrs_ops
= {
1671 .close
= mcfrs_close
,
1672 .write
= mcfrs_write
,
1673 .flush_chars
= mcfrs_flush_chars
,
1674 .write_room
= mcfrs_write_room
,
1675 .chars_in_buffer
= mcfrs_chars_in_buffer
,
1676 .flush_buffer
= mcfrs_flush_buffer
,
1677 .ioctl
= mcfrs_ioctl
,
1678 .throttle
= mcfrs_throttle
,
1679 .unthrottle
= mcfrs_unthrottle
,
1680 .set_termios
= mcfrs_set_termios
,
1682 .start
= mcfrs_start
,
1683 .hangup
= mcfrs_hangup
,
1684 .read_proc
= mcfrs_readproc
,
1685 .wait_until_sent
= mcfrs_wait_until_sent
,
1686 .tiocmget
= mcfrs_tiocmget
,
1687 .tiocmset
= mcfrs_tiocmset
,
1690 /* mcfrs_init inits the driver */
1694 struct mcf_serial
*info
;
1695 unsigned long flags
;
1698 /* Setup base handler, and timer table. */
1700 init_timer(&mcfrs_timer_struct
);
1701 mcfrs_timer_struct
.function
= mcfrs_timer
;
1702 mcfrs_timer_struct
.data
= 0;
1703 mcfrs_timer_struct
.expires
= jiffies
+ HZ
/25;
1704 add_timer(&mcfrs_timer_struct
);
1705 mcfrs_ppstatus
= mcf_getppdata() & (MCFPP_DCD0
| MCFPP_DCD1
);
1707 mcfrs_serial_driver
= alloc_tty_driver(NR_PORTS
);
1708 if (!mcfrs_serial_driver
)
1711 show_serial_version();
1713 /* Initialize the tty_driver structure */
1714 mcfrs_serial_driver
->owner
= THIS_MODULE
;
1715 mcfrs_serial_driver
->name
= "ttyS";
1716 mcfrs_serial_driver
->driver_name
= "serial";
1717 mcfrs_serial_driver
->major
= TTY_MAJOR
;
1718 mcfrs_serial_driver
->minor_start
= 64;
1719 mcfrs_serial_driver
->type
= TTY_DRIVER_TYPE_SERIAL
;
1720 mcfrs_serial_driver
->subtype
= SERIAL_TYPE_NORMAL
;
1721 mcfrs_serial_driver
->init_termios
= tty_std_termios
;
1723 mcfrs_serial_driver
->init_termios
.c_cflag
=
1724 mcfrs_console_cbaud
| CS8
| CREAD
| HUPCL
| CLOCAL
;
1725 mcfrs_serial_driver
->flags
= TTY_DRIVER_REAL_RAW
;
1727 tty_set_operations(mcfrs_serial_driver
, &mcfrs_ops
);
1729 if (tty_register_driver(mcfrs_serial_driver
)) {
1730 printk("MCFRS: Couldn't register serial driver\n");
1731 put_tty_driver(mcfrs_serial_driver
);
1735 local_irq_save(flags
);
1738 * Configure all the attached serial ports.
1740 for (i
= 0, info
= mcfrs_table
; (i
< NR_PORTS
); i
++, info
++) {
1741 info
->magic
= SERIAL_MAGIC
;
1744 info
->custom_divisor
= 16;
1745 info
->close_delay
= 50;
1746 info
->closing_wait
= 3000;
1750 info
->blocked_open
= 0;
1751 INIT_WORK(&info
->tqueue
, mcfrs_offintr
, info
);
1752 INIT_WORK(&info
->tqueue_hangup
, do_serial_hangup
, info
);
1753 init_waitqueue_head(&info
->open_wait
);
1754 init_waitqueue_head(&info
->close_wait
);
1757 mcfrs_setsignals(info
, 0, 0);
1758 mcfrs_irqinit(info
);
1760 printk("ttyS%d at 0x%04x (irq = %d)", info
->line
,
1761 (unsigned int) info
->addr
, info
->irq
);
1762 printk(" is a builtin ColdFire UART\n");
1765 local_irq_restore(flags
);
1769 module_init(mcfrs_init
);
1771 /****************************************************************************/
1772 /* Serial Console */
1773 /****************************************************************************/
1776 * Quick and dirty UART initialization, for console output.
1779 void mcfrs_init_console(void)
1781 volatile unsigned char *uartp
;
1785 * Reset UART, get it into known state...
1787 uartp
= (volatile unsigned char *) (MCF_MBAR
+
1788 (mcfrs_console_port
? MCFUART_BASE2
: MCFUART_BASE1
));
1790 uartp
[MCFUART_UCR
] = MCFUART_UCR_CMDRESETRX
; /* reset RX */
1791 uartp
[MCFUART_UCR
] = MCFUART_UCR_CMDRESETTX
; /* reset TX */
1792 uartp
[MCFUART_UCR
] = MCFUART_UCR_CMDRESETMRPTR
; /* reset MR pointer */
1795 * Set port for defined baud , 8 data bits, 1 stop bit, no parity.
1797 uartp
[MCFUART_UMR
] = MCFUART_MR1_PARITYNONE
| MCFUART_MR1_CS8
;
1798 uartp
[MCFUART_UMR
] = MCFUART_MR2_STOP1
;
1800 clk
= ((MCF_BUSCLK
/ mcfrs_console_baud
) + 16) / 32; /* set baud */
1801 uartp
[MCFUART_UBG1
] = (clk
& 0xff00) >> 8; /* set msb baud */
1802 uartp
[MCFUART_UBG2
] = (clk
& 0xff); /* set lsb baud */
1804 uartp
[MCFUART_UCSR
] = MCFUART_UCSR_RXCLKTIMER
| MCFUART_UCSR_TXCLKTIMER
;
1805 uartp
[MCFUART_UCR
] = MCFUART_UCR_RXENABLE
| MCFUART_UCR_TXENABLE
;
1807 mcfrs_console_inited
++;
1813 * Setup for console. Argument comes from the boot command line.
1816 int mcfrs_console_setup(struct console
*cp
, char *arg
)
1818 int i
, n
= CONSOLE_BAUD_RATE
;
1823 if (!strncmp(cp
->name
, "ttyS", 4))
1824 mcfrs_console_port
= cp
->index
;
1825 else if (!strncmp(cp
->name
, "cua", 3))
1826 mcfrs_console_port
= cp
->index
;
1831 n
= simple_strtoul(arg
,NULL
,0);
1832 for (i
= 0; i
< MCFRS_BAUD_TABLE_SIZE
; i
++)
1833 if (mcfrs_baud_table
[i
] == n
)
1835 if (i
< MCFRS_BAUD_TABLE_SIZE
) {
1836 mcfrs_console_baud
= n
;
1837 mcfrs_console_cbaud
= 0;
1839 mcfrs_console_cbaud
|= CBAUDEX
;
1842 mcfrs_console_cbaud
|= i
;
1844 mcfrs_init_console(); /* make sure baud rate changes */
1849 static struct tty_driver
*mcfrs_console_device(struct console
*c
, int *index
)
1852 return mcfrs_serial_driver
;
1857 * Output a single character, using UART polled mode.
1858 * This is used for console output.
1861 void mcfrs_put_char(char ch
)
1863 volatile unsigned char *uartp
;
1864 unsigned long flags
;
1867 uartp
= (volatile unsigned char *) (MCF_MBAR
+
1868 (mcfrs_console_port
? MCFUART_BASE2
: MCFUART_BASE1
));
1870 local_irq_save(flags
);
1871 for (i
= 0; (i
< 0x10000); i
++) {
1872 if (uartp
[MCFUART_USR
] & MCFUART_USR_TXREADY
)
1876 uartp
[MCFUART_UTB
] = ch
;
1877 for (i
= 0; (i
< 0x10000); i
++)
1878 if (uartp
[MCFUART_USR
] & MCFUART_USR_TXEMPTY
)
1882 mcfrs_init_console(); /* try and get it back */
1883 local_irq_restore(flags
);
1890 * rs_console_write is registered for printk output.
1893 void mcfrs_console_write(struct console
*cp
, const char *p
, unsigned len
)
1895 if (!mcfrs_console_inited
)
1896 mcfrs_init_console();
1899 mcfrs_put_char('\r');
1900 mcfrs_put_char(*p
++);
1905 * declare our consoles
1908 struct console mcfrs_console
= {
1910 .write
= mcfrs_console_write
,
1911 .device
= mcfrs_console_device
,
1912 .setup
= mcfrs_console_setup
,
1913 .flags
= CON_PRINTBUFFER
,
1917 static int __init
mcfrs_console_init(void)
1919 register_console(&mcfrs_console
);
1923 console_initcall(mcfrs_console_init
);
1925 /****************************************************************************/