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_ARNEWSH) || defined(CONFIG_MOTOROLA) || defined(CONFIG_senTec) || defined(CONFIG_SNEHA)
61 #define CONSOLE_BAUD_RATE 19200
62 #define DEFAULT_CBAUD B19200
65 #if defined(CONFIG_HW_FEITH)
66 #define CONSOLE_BAUD_RATE 38400
67 #define DEFAULT_CBAUD B38400
70 #if defined(CONFIG_MOD5272)
71 #define CONSOLE_BAUD_RATE 115200
72 #define DEFAULT_CBAUD B115200
75 #ifndef CONSOLE_BAUD_RATE
76 #define CONSOLE_BAUD_RATE 9600
77 #define DEFAULT_CBAUD B9600
80 int mcfrs_console_inited = 0;
81 int mcfrs_console_port = -1;
82 int mcfrs_console_baud = CONSOLE_BAUD_RATE;
83 int mcfrs_console_cbaud = DEFAULT_CBAUD;
86 * Driver data structures.
88 static struct tty_driver *mcfrs_serial_driver;
90 /* number of characters left in xmit buffer before we ask for more */
91 #define WAKEUP_CHARS 256
95 #undef SERIAL_DEBUG_OPEN
96 #undef SERIAL_DEBUG_FLOW
98 #if defined(CONFIG_M523x) || defined(CONFIG_M527x) || defined(CONFIG_M528x)
99 #define IRQBASE (MCFINT_VECBASE+MCFINT_UART0)
105 * Configuration table, UARTs to look for at startup.
107 static struct mcf_serial mcfrs_table[] = {
110 .addr = (volatile unsigned char *) (MCF_MBAR+MCFUART_BASE1),
112 .flags = ASYNC_BOOT_AUTOCONF,
116 .addr = (volatile unsigned char *) (MCF_MBAR+MCFUART_BASE2),
118 .flags = ASYNC_BOOT_AUTOCONF,
123 #define NR_PORTS (sizeof(mcfrs_table) / sizeof(struct mcf_serial))
126 * This is used to figure out the divisor speeds and the timeouts.
128 static int mcfrs_baud_table[] = {
129 0, 50, 75, 110, 134, 150, 200, 300, 600, 1200, 1800, 2400, 4800,
130 9600, 19200, 38400, 57600, 115200, 230400, 460800, 0
132 #define MCFRS_BAUD_TABLE_SIZE \
133 (sizeof(mcfrs_baud_table)/sizeof(mcfrs_baud_table[0]))
136 #ifdef CONFIG_MAGIC_SYSRQ
138 * Magic system request keys. Used for debugging...
140 extern int magic_sysrq_key(int ch);
145 * Forware declarations...
147 static void mcfrs_change_speed(struct mcf_serial *info);
148 static void mcfrs_wait_until_sent(struct tty_struct *tty, int timeout);
151 static inline int serial_paranoia_check(struct mcf_serial *info,
152 char *name, const char *routine)
154 #ifdef SERIAL_PARANOIA_CHECK
155 static const char badmagic[] =
156 "MCFRS(warning): bad magic number for serial struct %s in %s\n";
157 static const char badinfo[] =
158 "MCFRS(warning): null mcf_serial for %s in %s\n";
161 printk(badinfo, name, routine);
164 if (info->magic != SERIAL_MAGIC) {
165 printk(badmagic, name, routine);
173 * Sets or clears DTR and RTS on the requested line.
175 static void mcfrs_setsignals(struct mcf_serial *info, int dtr, int rts)
177 volatile unsigned char *uartp;
181 printk("%s(%d): mcfrs_setsignals(info=%x,dtr=%d,rts=%d)\n",
182 __FILE__, __LINE__, info, dtr, rts);
185 local_irq_save(flags);
189 mcf_setppdata(MCFPP_DTR1, (dtr ? 0 : MCFPP_DTR1));
191 mcf_setppdata(MCFPP_DTR0, (dtr ? 0 : MCFPP_DTR0));
197 info->sigs |= TIOCM_RTS;
198 uartp[MCFUART_UOP1] = MCFUART_UOP_RTS;
200 info->sigs &= ~TIOCM_RTS;
201 uartp[MCFUART_UOP0] = MCFUART_UOP_RTS;
204 local_irq_restore(flags);
209 * Gets values of serial signals.
211 static int mcfrs_getsignals(struct mcf_serial *info)
213 volatile unsigned char *uartp;
216 #if defined(CONFIG_NETtel) && defined(CONFIG_M5307)
217 unsigned short ppdata;
221 printk("%s(%d): mcfrs_getsignals(info=%x)\n", __FILE__, __LINE__);
224 local_irq_save(flags);
226 sigs = (uartp[MCFUART_UIPR] & MCFUART_UIPR_CTS) ? 0 : TIOCM_CTS;
227 sigs |= (info->sigs & TIOCM_RTS);
232 ppdata = mcf_getppdata();
233 if (info->line == 0) {
234 sigs |= (ppdata & MCFPP_DCD0) ? 0 : TIOCM_CD;
235 sigs |= (ppdata & MCFPP_DTR0) ? 0 : TIOCM_DTR;
236 } else if (info->line == 1) {
237 sigs |= (ppdata & MCFPP_DCD1) ? 0 : TIOCM_CD;
238 sigs |= (ppdata & MCFPP_DTR1) ? 0 : TIOCM_DTR;
243 local_irq_restore(flags);
248 * ------------------------------------------------------------
249 * mcfrs_stop() and mcfrs_start()
251 * This routines are called before setting or resetting tty->stopped.
252 * They enable or disable transmitter interrupts, as necessary.
253 * ------------------------------------------------------------
255 static void mcfrs_stop(struct tty_struct *tty)
257 volatile unsigned char *uartp;
258 struct mcf_serial *info = (struct mcf_serial *)tty->driver_data;
261 if (serial_paranoia_check(info, tty->name, "mcfrs_stop"))
264 local_irq_save(flags);
266 info->imr &= ~MCFUART_UIR_TXREADY;
267 uartp[MCFUART_UIMR] = info->imr;
268 local_irq_restore(flags);
271 static void mcfrs_start(struct tty_struct *tty)
273 volatile unsigned char *uartp;
274 struct mcf_serial *info = (struct mcf_serial *)tty->driver_data;
277 if (serial_paranoia_check(info, tty->name, "mcfrs_start"))
280 local_irq_save(flags);
281 if (info->xmit_cnt && info->xmit_buf) {
283 info->imr |= MCFUART_UIR_TXREADY;
284 uartp[MCFUART_UIMR] = info->imr;
286 local_irq_restore(flags);
290 * ----------------------------------------------------------------------
292 * Here starts the interrupt handling routines. All of the following
293 * subroutines are declared as inline and are folded into
294 * mcfrs_interrupt(). They were separated out for readability's sake.
296 * Note: mcfrs_interrupt() is a "fast" interrupt, which means that it
297 * runs with interrupts turned off. People who may want to modify
298 * mcfrs_interrupt() should try to keep the interrupt handler as fast as
299 * possible. After you are done making modifications, it is not a bad
302 * gcc -S -DKERNEL -Wall -Wstrict-prototypes -O6 -fomit-frame-pointer serial.c
304 * and look at the resulting assemble code in serial.s.
306 * - Ted Ts'o (tytso@mit.edu), 7-Mar-93
307 * -----------------------------------------------------------------------
310 static inline void receive_chars(struct mcf_serial *info)
312 volatile unsigned char *uartp;
313 struct tty_struct *tty = info->tty;
314 unsigned char status, ch;
321 while ((status = uartp[MCFUART_USR]) & MCFUART_USR_RXREADY) {
323 if (tty->flip.count >= TTY_FLIPBUF_SIZE)
326 ch = uartp[MCFUART_URB];
329 #ifdef CONFIG_MAGIC_SYSRQ
330 if (mcfrs_console_inited && (info->line == mcfrs_console_port)) {
331 if (magic_sysrq_key(ch))
337 if (status & MCFUART_USR_RXERR) {
338 uartp[MCFUART_UCR] = MCFUART_UCR_CMDRESETERR;
339 if (status & MCFUART_USR_RXBREAK) {
340 info->stats.rxbreak++;
341 *tty->flip.flag_buf_ptr++ = TTY_BREAK;
342 } else if (status & MCFUART_USR_RXPARITY) {
343 info->stats.rxparity++;
344 *tty->flip.flag_buf_ptr++ = TTY_PARITY;
345 } else if (status & MCFUART_USR_RXOVERRUN) {
346 info->stats.rxoverrun++;
347 *tty->flip.flag_buf_ptr++ = TTY_OVERRUN;
348 } else if (status & MCFUART_USR_RXFRAMING) {
349 info->stats.rxframing++;
350 *tty->flip.flag_buf_ptr++ = TTY_FRAME;
352 /* This should never happen... */
353 *tty->flip.flag_buf_ptr++ = 0;
356 *tty->flip.flag_buf_ptr++ = 0;
358 *tty->flip.char_buf_ptr++ = ch;
361 schedule_work(&tty->flip.work);
365 static inline void transmit_chars(struct mcf_serial *info)
367 volatile unsigned char *uartp;
372 /* Send special char - probably flow control */
373 uartp[MCFUART_UTB] = info->x_char;
378 if ((info->xmit_cnt <= 0) || info->tty->stopped) {
379 info->imr &= ~MCFUART_UIR_TXREADY;
380 uartp[MCFUART_UIMR] = info->imr;
384 while (uartp[MCFUART_USR] & MCFUART_USR_TXREADY) {
385 uartp[MCFUART_UTB] = info->xmit_buf[info->xmit_tail++];
386 info->xmit_tail = info->xmit_tail & (SERIAL_XMIT_SIZE-1);
388 if (--info->xmit_cnt <= 0)
392 if (info->xmit_cnt < WAKEUP_CHARS)
393 schedule_work(&info->tqueue);
398 * This is the serial driver's generic interrupt routine
400 irqreturn_t mcfrs_interrupt(int irq, void *dev_id, struct pt_regs *regs)
402 struct mcf_serial *info;
405 info = &mcfrs_table[(irq - IRQBASE)];
406 isr = info->addr[MCFUART_UISR] & info->imr;
408 if (isr & MCFUART_UIR_RXREADY)
410 if (isr & MCFUART_UIR_TXREADY)
411 transmit_chars(info);
416 * -------------------------------------------------------------------
417 * Here ends the serial interrupt routines.
418 * -------------------------------------------------------------------
421 static void mcfrs_offintr(void *private)
423 struct mcf_serial *info = (struct mcf_serial *) private;
424 struct tty_struct *tty;
434 * Change of state on a DCD line.
436 void mcfrs_modem_change(struct mcf_serial *info, int dcd)
438 if (info->count == 0)
441 if (info->flags & ASYNC_CHECK_CD) {
443 wake_up_interruptible(&info->open_wait);
445 schedule_work(&info->tqueue_hangup);
452 unsigned short mcfrs_ppstatus;
455 * This subroutine is called when the RS_TIMER goes off. It is used
456 * to monitor the state of the DCD lines - since they have no edge
457 * sensors and interrupt generators.
459 static void mcfrs_timer(void)
461 unsigned int ppstatus, dcdval, i;
463 ppstatus = mcf_getppdata() & (MCFPP_DCD0 | MCFPP_DCD1);
465 if (ppstatus != mcfrs_ppstatus) {
466 for (i = 0; (i < 2); i++) {
467 dcdval = (i ? MCFPP_DCD1 : MCFPP_DCD0);
468 if ((ppstatus & dcdval) != (mcfrs_ppstatus & dcdval)) {
469 mcfrs_modem_change(&mcfrs_table[i],
470 ((ppstatus & dcdval) ? 0 : 1));
474 mcfrs_ppstatus = ppstatus;
477 mcfrs_timer_struct.expires = jiffies + HZ/25;
478 add_timer(&mcfrs_timer_struct);
481 #endif /* MCFPP_DCD0 */
485 * This routine is called from the scheduler tqueue when the interrupt
486 * routine has signalled that a hangup has occurred. The path of
487 * hangup processing is:
489 * serial interrupt routine -> (scheduler tqueue) ->
490 * do_serial_hangup() -> tty->hangup() -> mcfrs_hangup()
493 static void do_serial_hangup(void *private)
495 struct mcf_serial *info = (struct mcf_serial *) private;
496 struct tty_struct *tty;
505 static int startup(struct mcf_serial * info)
507 volatile unsigned char *uartp;
510 if (info->flags & ASYNC_INITIALIZED)
513 if (!info->xmit_buf) {
514 info->xmit_buf = (unsigned char *) __get_free_page(GFP_KERNEL);
519 local_irq_save(flags);
521 #ifdef SERIAL_DEBUG_OPEN
522 printk("starting up ttyS%d (irq %d)...\n", info->line, info->irq);
526 * Reset UART, get it into known state...
529 uartp[MCFUART_UCR] = MCFUART_UCR_CMDRESETRX; /* reset RX */
530 uartp[MCFUART_UCR] = MCFUART_UCR_CMDRESETTX; /* reset TX */
531 mcfrs_setsignals(info, 1, 1);
534 clear_bit(TTY_IO_ERROR, &info->tty->flags);
535 info->xmit_cnt = info->xmit_head = info->xmit_tail = 0;
538 * and set the speed of the serial port
540 mcfrs_change_speed(info);
543 * Lastly enable the UART transmitter and receiver, and
546 info->imr = MCFUART_UIR_RXREADY;
547 uartp[MCFUART_UCR] = MCFUART_UCR_RXENABLE | MCFUART_UCR_TXENABLE;
548 uartp[MCFUART_UIMR] = info->imr;
550 info->flags |= ASYNC_INITIALIZED;
551 local_irq_restore(flags);
556 * This routine will shutdown a serial port; interrupts are disabled, and
557 * DTR is dropped if the hangup on close termio flag is on.
559 static void shutdown(struct mcf_serial * info)
561 volatile unsigned char *uartp;
564 if (!(info->flags & ASYNC_INITIALIZED))
567 #ifdef SERIAL_DEBUG_OPEN
568 printk("Shutting down serial port %d (irq %d)....\n", info->line,
572 local_irq_save(flags);
575 uartp[MCFUART_UIMR] = 0; /* mask all interrupts */
576 uartp[MCFUART_UCR] = MCFUART_UCR_CMDRESETRX; /* reset RX */
577 uartp[MCFUART_UCR] = MCFUART_UCR_CMDRESETTX; /* reset TX */
579 if (!info->tty || (info->tty->termios->c_cflag & HUPCL))
580 mcfrs_setsignals(info, 0, 0);
582 if (info->xmit_buf) {
583 free_page((unsigned long) info->xmit_buf);
588 set_bit(TTY_IO_ERROR, &info->tty->flags);
590 info->flags &= ~ASYNC_INITIALIZED;
591 local_irq_restore(flags);
596 * This routine is called to set the UART divisor registers to match
597 * the specified baud rate for a serial port.
599 static void mcfrs_change_speed(struct mcf_serial *info)
601 volatile unsigned char *uartp;
602 unsigned int baudclk, cflag;
604 unsigned char mr1, mr2;
607 unsigned int fraction;
610 if (!info->tty || !info->tty->termios)
612 cflag = info->tty->termios->c_cflag;
617 printk("%s(%d): mcfrs_change_speed()\n", __FILE__, __LINE__);
624 info->tty->termios->c_cflag &= ~CBAUDEX;
629 mcfrs_setsignals(info, 0, -1);
633 /* compute the baudrate clock */
636 * For the MCF5272, also compute the baudrate fraction.
638 baudclk = (MCF_BUSCLK / mcfrs_baud_table[i]) / 32;
639 fraction = MCF_BUSCLK - (baudclk * 32 * mcfrs_baud_table[i]);
641 fraction /= (32 * mcfrs_baud_table[i]);
643 baudclk = ((MCF_BUSCLK / mcfrs_baud_table[i]) + 16) / 32;
646 info->baud = mcfrs_baud_table[i];
648 mr1 = MCFUART_MR1_RXIRQRDY | MCFUART_MR1_RXERRCHAR;
651 switch (cflag & CSIZE) {
652 case CS5: mr1 |= MCFUART_MR1_CS5; break;
653 case CS6: mr1 |= MCFUART_MR1_CS6; break;
654 case CS7: mr1 |= MCFUART_MR1_CS7; break;
656 default: mr1 |= MCFUART_MR1_CS8; break;
659 if (cflag & PARENB) {
660 if (cflag & CMSPAR) {
662 mr1 |= MCFUART_MR1_PARITYMARK;
664 mr1 |= MCFUART_MR1_PARITYSPACE;
667 mr1 |= MCFUART_MR1_PARITYODD;
669 mr1 |= MCFUART_MR1_PARITYEVEN;
672 mr1 |= MCFUART_MR1_PARITYNONE;
676 mr2 |= MCFUART_MR2_STOP2;
678 mr2 |= MCFUART_MR2_STOP1;
680 if (cflag & CRTSCTS) {
681 mr1 |= MCFUART_MR1_RXRTS;
682 mr2 |= MCFUART_MR2_TXCTS;
686 info->flags &= ~ASYNC_CHECK_CD;
688 info->flags |= ASYNC_CHECK_CD;
692 local_irq_save(flags);
694 printk("%s(%d): mr1=%x mr2=%x baudclk=%x\n", __FILE__, __LINE__,
698 Note: pg 12-16 of MCF5206e User's Manual states that a
699 software reset should be performed prior to changing
700 UMR1,2, UCSR, UACR, bit 7
702 uartp[MCFUART_UCR] = MCFUART_UCR_CMDRESETRX; /* reset RX */
703 uartp[MCFUART_UCR] = MCFUART_UCR_CMDRESETTX; /* reset TX */
704 uartp[MCFUART_UCR] = MCFUART_UCR_CMDRESETMRPTR; /* reset MR pointer */
705 uartp[MCFUART_UMR] = mr1;
706 uartp[MCFUART_UMR] = mr2;
707 uartp[MCFUART_UBG1] = (baudclk & 0xff00) >> 8; /* set msb byte */
708 uartp[MCFUART_UBG2] = (baudclk & 0xff); /* set lsb byte */
710 uartp[MCFUART_UFPD] = (fraction & 0xf); /* set fraction */
712 uartp[MCFUART_UCSR] = MCFUART_UCSR_RXCLKTIMER | MCFUART_UCSR_TXCLKTIMER;
713 uartp[MCFUART_UCR] = MCFUART_UCR_RXENABLE | MCFUART_UCR_TXENABLE;
714 mcfrs_setsignals(info, 1, -1);
715 local_irq_restore(flags);
719 static void mcfrs_flush_chars(struct tty_struct *tty)
721 volatile unsigned char *uartp;
722 struct mcf_serial *info = (struct mcf_serial *)tty->driver_data;
725 if (serial_paranoia_check(info, tty->name, "mcfrs_flush_chars"))
728 uartp = (volatile unsigned char *) info->addr;
731 * re-enable receiver interrupt
733 local_irq_save(flags);
734 if ((!(info->imr & MCFUART_UIR_RXREADY)) &&
735 (info->flags & ASYNC_INITIALIZED) ) {
736 info->imr |= MCFUART_UIR_RXREADY;
737 uartp[MCFUART_UIMR] = info->imr;
739 local_irq_restore(flags);
741 if (info->xmit_cnt <= 0 || tty->stopped || tty->hw_stopped ||
745 /* Enable transmitter */
746 local_irq_save(flags);
747 info->imr |= MCFUART_UIR_TXREADY;
748 uartp[MCFUART_UIMR] = info->imr;
749 local_irq_restore(flags);
752 static int mcfrs_write(struct tty_struct * tty,
753 const unsigned char *buf, int count)
755 volatile unsigned char *uartp;
756 struct mcf_serial *info = (struct mcf_serial *)tty->driver_data;
761 printk("%s(%d): mcfrs_write(tty=%x,buf=%x,count=%d)\n",
762 __FILE__, __LINE__, (int)tty, (int)buf, count);
765 if (serial_paranoia_check(info, tty->name, "mcfrs_write"))
768 if (!tty || !info->xmit_buf)
771 local_save_flags(flags);
774 c = min(count, (int) min(((int)SERIAL_XMIT_SIZE) - info->xmit_cnt - 1,
775 ((int)SERIAL_XMIT_SIZE) - info->xmit_head));
776 local_irq_restore(flags);
781 memcpy(info->xmit_buf + info->xmit_head, buf, c);
784 info->xmit_head = (info->xmit_head + c) & (SERIAL_XMIT_SIZE-1);
786 local_irq_restore(flags);
795 info->imr |= MCFUART_UIR_TXREADY;
796 uartp[MCFUART_UIMR] = info->imr;
797 local_irq_restore(flags);
802 static int mcfrs_write_room(struct tty_struct *tty)
804 struct mcf_serial *info = (struct mcf_serial *)tty->driver_data;
807 if (serial_paranoia_check(info, tty->name, "mcfrs_write_room"))
809 ret = SERIAL_XMIT_SIZE - info->xmit_cnt - 1;
815 static int mcfrs_chars_in_buffer(struct tty_struct *tty)
817 struct mcf_serial *info = (struct mcf_serial *)tty->driver_data;
819 if (serial_paranoia_check(info, tty->name, "mcfrs_chars_in_buffer"))
821 return info->xmit_cnt;
824 static void mcfrs_flush_buffer(struct tty_struct *tty)
826 struct mcf_serial *info = (struct mcf_serial *)tty->driver_data;
829 if (serial_paranoia_check(info, tty->name, "mcfrs_flush_buffer"))
832 local_irq_save(flags);
833 info->xmit_cnt = info->xmit_head = info->xmit_tail = 0;
834 local_irq_restore(flags);
840 * ------------------------------------------------------------
843 * This routine is called by the upper-layer tty layer to signal that
844 * incoming characters should be throttled.
845 * ------------------------------------------------------------
847 static void mcfrs_throttle(struct tty_struct * tty)
849 struct mcf_serial *info = (struct mcf_serial *)tty->driver_data;
850 #ifdef SERIAL_DEBUG_THROTTLE
853 printk("throttle %s: %d....\n", _tty_name(tty, buf),
854 tty->ldisc.chars_in_buffer(tty));
857 if (serial_paranoia_check(info, tty->name, "mcfrs_throttle"))
861 info->x_char = STOP_CHAR(tty);
863 /* Turn off RTS line (do this atomic) */
866 static void mcfrs_unthrottle(struct tty_struct * tty)
868 struct mcf_serial *info = (struct mcf_serial *)tty->driver_data;
869 #ifdef SERIAL_DEBUG_THROTTLE
872 printk("unthrottle %s: %d....\n", _tty_name(tty, buf),
873 tty->ldisc.chars_in_buffer(tty));
876 if (serial_paranoia_check(info, tty->name, "mcfrs_unthrottle"))
883 info->x_char = START_CHAR(tty);
886 /* Assert RTS line (do this atomic) */
890 * ------------------------------------------------------------
891 * mcfrs_ioctl() and friends
892 * ------------------------------------------------------------
895 static int get_serial_info(struct mcf_serial * info,
896 struct serial_struct * retinfo)
898 struct serial_struct tmp;
902 memset(&tmp, 0, sizeof(tmp));
903 tmp.type = info->type;
904 tmp.line = info->line;
905 tmp.port = (unsigned int) info->addr;
907 tmp.flags = info->flags;
908 tmp.baud_base = info->baud_base;
909 tmp.close_delay = info->close_delay;
910 tmp.closing_wait = info->closing_wait;
911 tmp.custom_divisor = info->custom_divisor;
912 return copy_to_user(retinfo,&tmp,sizeof(*retinfo)) ? -EFAULT : 0;
915 static int set_serial_info(struct mcf_serial * info,
916 struct serial_struct * new_info)
918 struct serial_struct new_serial;
919 struct mcf_serial old_info;
924 if (copy_from_user(&new_serial,new_info,sizeof(new_serial)))
928 if (!capable(CAP_SYS_ADMIN)) {
929 if ((new_serial.baud_base != info->baud_base) ||
930 (new_serial.type != info->type) ||
931 (new_serial.close_delay != info->close_delay) ||
932 ((new_serial.flags & ~ASYNC_USR_MASK) !=
933 (info->flags & ~ASYNC_USR_MASK)))
935 info->flags = ((info->flags & ~ASYNC_USR_MASK) |
936 (new_serial.flags & ASYNC_USR_MASK));
937 info->custom_divisor = new_serial.custom_divisor;
945 * OK, past this point, all the error checking has been done.
946 * At this point, we start making changes.....
949 info->baud_base = new_serial.baud_base;
950 info->flags = ((info->flags & ~ASYNC_FLAGS) |
951 (new_serial.flags & ASYNC_FLAGS));
952 info->type = new_serial.type;
953 info->close_delay = new_serial.close_delay;
954 info->closing_wait = new_serial.closing_wait;
957 retval = startup(info);
962 * get_lsr_info - get line status register info
964 * Purpose: Let user call ioctl() to get info when the UART physically
965 * is emptied. On bus types like RS485, the transmitter must
966 * release the bus after transmitting. This must be done when
967 * the transmit shift register is empty, not be done when the
968 * transmit holding register is empty. This functionality
969 * allows an RS485 driver to be written in user space.
971 static int get_lsr_info(struct mcf_serial * info, unsigned int *value)
973 volatile unsigned char *uartp;
975 unsigned char status;
977 local_irq_save(flags);
979 status = (uartp[MCFUART_USR] & MCFUART_USR_TXEMPTY) ? TIOCSER_TEMT : 0;
980 local_irq_restore(flags);
982 return put_user(status,value);
986 * This routine sends a break character out the serial port.
988 static void send_break( struct mcf_serial * info, int duration)
990 volatile unsigned char *uartp;
995 set_current_state(TASK_INTERRUPTIBLE);
998 local_irq_save(flags);
999 uartp[MCFUART_UCR] = MCFUART_UCR_CMDBREAKSTART;
1000 schedule_timeout(duration);
1001 uartp[MCFUART_UCR] = MCFUART_UCR_CMDBREAKSTOP;
1002 local_irq_restore(flags);
1005 static int mcfrs_tiocmget(struct tty_struct *tty, struct file *file)
1007 struct mcf_serial * info = (struct mcf_serial *)tty->driver_data;
1009 if (serial_paranoia_check(info, tty->name, "mcfrs_ioctl"))
1011 if (tty->flags & (1 << TTY_IO_ERROR))
1014 return mcfrs_getsignals(info);
1017 static int mcfrs_tiocmset(struct tty_struct *tty, struct file *file,
1018 unsigned int set, unsigned int clear)
1020 struct mcf_serial * info = (struct mcf_serial *)tty->driver_data;
1021 int rts = -1, dtr = -1;
1023 if (serial_paranoia_check(info, tty->name, "mcfrs_ioctl"))
1025 if (tty->flags & (1 << TTY_IO_ERROR))
1028 if (set & TIOCM_RTS)
1030 if (set & TIOCM_DTR)
1032 if (clear & TIOCM_RTS)
1034 if (clear & TIOCM_DTR)
1037 mcfrs_setsignals(info, dtr, rts);
1042 static int mcfrs_ioctl(struct tty_struct *tty, struct file * file,
1043 unsigned int cmd, unsigned long arg)
1045 struct mcf_serial * info = (struct mcf_serial *)tty->driver_data;
1048 if (serial_paranoia_check(info, tty->name, "mcfrs_ioctl"))
1051 if ((cmd != TIOCGSERIAL) && (cmd != TIOCSSERIAL) &&
1052 (cmd != TIOCSERCONFIG) && (cmd != TIOCSERGWILD) &&
1053 (cmd != TIOCSERSWILD) && (cmd != TIOCSERGSTRUCT)) {
1054 if (tty->flags & (1 << TTY_IO_ERROR))
1059 case TCSBRK: /* SVID version: non-zero arg --> no break */
1060 retval = tty_check_change(tty);
1063 tty_wait_until_sent(tty, 0);
1065 send_break(info, HZ/4); /* 1/4 second */
1067 case TCSBRKP: /* support for POSIX tcsendbreak() */
1068 retval = tty_check_change(tty);
1071 tty_wait_until_sent(tty, 0);
1072 send_break(info, arg ? arg*(HZ/10) : HZ/4);
1075 error = put_user(C_CLOCAL(tty) ? 1 : 0,
1076 (unsigned long *) arg);
1081 get_user(arg, (unsigned long *) arg);
1082 tty->termios->c_cflag =
1083 ((tty->termios->c_cflag & ~CLOCAL) |
1084 (arg ? CLOCAL : 0));
1087 if (access_ok(VERIFY_WRITE, (void *) arg,
1088 sizeof(struct serial_struct)))
1089 return get_serial_info(info,
1090 (struct serial_struct *) arg);
1093 return set_serial_info(info,
1094 (struct serial_struct *) arg);
1095 case TIOCSERGETLSR: /* Get line status register */
1096 if (access_ok(VERIFY_WRITE, (void *) arg,
1097 sizeof(unsigned int)))
1098 return get_lsr_info(info, (unsigned int *) arg);
1100 case TIOCSERGSTRUCT:
1101 error = copy_to_user((struct mcf_serial *) arg,
1102 info, sizeof(struct mcf_serial));
1110 get_user(val, (unsigned int *) arg);
1111 mcf_setpa(MCFPP_PA11, (val ? 0 : MCFPP_PA11));
1116 val = (mcf_getpa() & MCFPP_PA11) ? 0 : 1;
1117 put_user(val, (unsigned int *) arg);
1123 return -ENOIOCTLCMD;
1128 static void mcfrs_set_termios(struct tty_struct *tty, struct termios *old_termios)
1130 struct mcf_serial *info = (struct mcf_serial *)tty->driver_data;
1132 if (tty->termios->c_cflag == old_termios->c_cflag)
1135 mcfrs_change_speed(info);
1137 if ((old_termios->c_cflag & CRTSCTS) &&
1138 !(tty->termios->c_cflag & CRTSCTS)) {
1139 tty->hw_stopped = 0;
1140 mcfrs_setsignals(info, -1, 1);
1148 * ------------------------------------------------------------
1151 * This routine is called when the serial port gets closed. First, we
1152 * wait for the last remaining data to be sent. Then, we unlink its
1153 * S structure from the interrupt chain if necessary, and we free
1154 * that IRQ if nothing is left in the chain.
1155 * ------------------------------------------------------------
1157 static void mcfrs_close(struct tty_struct *tty, struct file * filp)
1159 volatile unsigned char *uartp;
1160 struct mcf_serial *info = (struct mcf_serial *)tty->driver_data;
1161 unsigned long flags;
1163 if (!info || serial_paranoia_check(info, tty->name, "mcfrs_close"))
1166 local_irq_save(flags);
1168 if (tty_hung_up_p(filp)) {
1169 local_irq_restore(flags);
1173 #ifdef SERIAL_DEBUG_OPEN
1174 printk("mcfrs_close ttyS%d, count = %d\n", info->line, info->count);
1176 if ((tty->count == 1) && (info->count != 1)) {
1178 * Uh, oh. tty->count is 1, which means that the tty
1179 * structure will be freed. Info->count should always
1180 * be one in these conditions. If it's greater than
1181 * one, we've got real problems, since it means the
1182 * serial port won't be shutdown.
1184 printk("MCFRS: bad serial port count; tty->count is 1, "
1185 "info->count is %d\n", info->count);
1188 if (--info->count < 0) {
1189 printk("MCFRS: bad serial port count for ttyS%d: %d\n",
1190 info->line, info->count);
1194 local_irq_restore(flags);
1197 info->flags |= ASYNC_CLOSING;
1200 * Now we wait for the transmit buffer to clear; and we notify
1201 * the line discipline to only process XON/XOFF characters.
1204 if (info->closing_wait != ASYNC_CLOSING_WAIT_NONE)
1205 tty_wait_until_sent(tty, info->closing_wait);
1208 * At this point we stop accepting input. To do this, we
1209 * disable the receive line status interrupts, and tell the
1210 * interrupt driver to stop checking the data ready bit in the
1211 * line status register.
1213 info->imr &= ~MCFUART_UIR_RXREADY;
1215 uartp[MCFUART_UIMR] = info->imr;
1218 /* FIXME: do we need to keep this enabled for console?? */
1219 if (mcfrs_console_inited && (mcfrs_console_port == info->line)) {
1220 /* Do not disable the UART */ ;
1224 if (tty->driver->flush_buffer)
1225 tty->driver->flush_buffer(tty);
1226 tty_ldisc_flush(tty);
1232 if (tty->ldisc.num != ldiscs[N_TTY].num) {
1233 if (tty->ldisc.close)
1234 (tty->ldisc.close)(tty);
1235 tty->ldisc = ldiscs[N_TTY];
1236 tty->termios->c_line = N_TTY;
1237 if (tty->ldisc.open)
1238 (tty->ldisc.open)(tty);
1241 if (info->blocked_open) {
1242 if (info->close_delay) {
1243 msleep_interruptible(jiffies_to_msecs(info->close_delay));
1245 wake_up_interruptible(&info->open_wait);
1247 info->flags &= ~(ASYNC_NORMAL_ACTIVE|ASYNC_CLOSING);
1248 wake_up_interruptible(&info->close_wait);
1249 local_irq_restore(flags);
1253 * mcfrs_wait_until_sent() --- wait until the transmitter is empty
1256 mcfrs_wait_until_sent(struct tty_struct *tty, int timeout)
1259 #define MCF5272_FIFO_SIZE 25 /* fifo size + shift reg */
1261 struct mcf_serial * info = (struct mcf_serial *)tty->driver_data;
1262 volatile unsigned char *uartp;
1263 unsigned long orig_jiffies, fifo_time, char_time, fifo_cnt;
1265 if (serial_paranoia_check(info, tty->name, "mcfrs_wait_until_sent"))
1268 orig_jiffies = jiffies;
1271 * Set the check interval to be 1/5 of the approximate time
1272 * to send the entire fifo, and make it at least 1. The check
1273 * interval should also be less than the timeout.
1275 * Note: we have to use pretty tight timings here to satisfy
1278 fifo_time = (MCF5272_FIFO_SIZE * HZ * 10) / info->baud;
1279 char_time = fifo_time / 5;
1282 if (timeout && timeout < char_time)
1283 char_time = timeout;
1286 * Clamp the timeout period at 2 * the time to empty the
1287 * fifo. Just to be safe, set the minimum at .5 seconds.
1290 if (fifo_time < (HZ/2))
1292 if (!timeout || timeout > fifo_time)
1293 timeout = fifo_time;
1296 * Account for the number of bytes in the UART
1297 * transmitter FIFO plus any byte being shifted out.
1299 uartp = (volatile unsigned char *) info->addr;
1301 fifo_cnt = (uartp[MCFUART_UTF] & MCFUART_UTF_TXB);
1302 if ((uartp[MCFUART_USR] & (MCFUART_USR_TXREADY|
1303 MCFUART_USR_TXEMPTY)) ==
1304 MCFUART_USR_TXREADY)
1308 msleep_interruptible(jiffies_to_msecs(char_time));
1309 if (signal_pending(current))
1311 if (timeout && time_after(jiffies, orig_jiffies + timeout))
1316 * For the other coldfire models, assume all data has been sent
1322 * mcfrs_hangup() --- called by tty_hangup() when a hangup is signaled.
1324 void mcfrs_hangup(struct tty_struct *tty)
1326 struct mcf_serial * info = (struct mcf_serial *)tty->driver_data;
1328 if (serial_paranoia_check(info, tty->name, "mcfrs_hangup"))
1331 mcfrs_flush_buffer(tty);
1335 info->flags &= ~ASYNC_NORMAL_ACTIVE;
1337 wake_up_interruptible(&info->open_wait);
1341 * ------------------------------------------------------------
1342 * mcfrs_open() and friends
1343 * ------------------------------------------------------------
1345 static int block_til_ready(struct tty_struct *tty, struct file * filp,
1346 struct mcf_serial *info)
1348 DECLARE_WAITQUEUE(wait, current);
1353 * If the device is in the middle of being closed, then block
1354 * until it's done, and then try again.
1356 if (info->flags & ASYNC_CLOSING) {
1357 interruptible_sleep_on(&info->close_wait);
1358 #ifdef SERIAL_DO_RESTART
1359 if (info->flags & ASYNC_HUP_NOTIFY)
1362 return -ERESTARTSYS;
1369 * If non-blocking mode is set, or the port is not enabled,
1370 * then make the check up front and then exit.
1372 if ((filp->f_flags & O_NONBLOCK) ||
1373 (tty->flags & (1 << TTY_IO_ERROR))) {
1374 info->flags |= ASYNC_NORMAL_ACTIVE;
1378 if (tty->termios->c_cflag & CLOCAL)
1382 * Block waiting for the carrier detect and the line to become
1383 * free (i.e., not in use by the callout). While we are in
1384 * this loop, info->count is dropped by one, so that
1385 * mcfrs_close() knows when to free things. We restore it upon
1386 * exit, either normal or abnormal.
1389 add_wait_queue(&info->open_wait, &wait);
1390 #ifdef SERIAL_DEBUG_OPEN
1391 printk("block_til_ready before block: ttyS%d, count = %d\n",
1392 info->line, info->count);
1395 info->blocked_open++;
1397 local_irq_disable();
1398 mcfrs_setsignals(info, 1, 1);
1400 current->state = TASK_INTERRUPTIBLE;
1401 if (tty_hung_up_p(filp) ||
1402 !(info->flags & ASYNC_INITIALIZED)) {
1403 #ifdef SERIAL_DO_RESTART
1404 if (info->flags & ASYNC_HUP_NOTIFY)
1407 retval = -ERESTARTSYS;
1413 if (!(info->flags & ASYNC_CLOSING) &&
1414 (do_clocal || (mcfrs_getsignals(info) & TIOCM_CD)))
1416 if (signal_pending(current)) {
1417 retval = -ERESTARTSYS;
1420 #ifdef SERIAL_DEBUG_OPEN
1421 printk("block_til_ready blocking: ttyS%d, count = %d\n",
1422 info->line, info->count);
1426 current->state = TASK_RUNNING;
1427 remove_wait_queue(&info->open_wait, &wait);
1428 if (!tty_hung_up_p(filp))
1430 info->blocked_open--;
1431 #ifdef SERIAL_DEBUG_OPEN
1432 printk("block_til_ready after blocking: ttyS%d, count = %d\n",
1433 info->line, info->count);
1437 info->flags |= ASYNC_NORMAL_ACTIVE;
1442 * This routine is called whenever a serial port is opened. It
1443 * enables interrupts for a serial port, linking in its structure into
1444 * the IRQ chain. It also performs the serial-specific
1445 * initialization for the tty structure.
1447 int mcfrs_open(struct tty_struct *tty, struct file * filp)
1449 struct mcf_serial *info;
1453 if ((line < 0) || (line >= NR_PORTS))
1455 info = mcfrs_table + line;
1456 if (serial_paranoia_check(info, tty->name, "mcfrs_open"))
1458 #ifdef SERIAL_DEBUG_OPEN
1459 printk("mcfrs_open %s, count = %d\n", tty->name, info->count);
1462 tty->driver_data = info;
1466 * Start up serial port
1468 retval = startup(info);
1472 retval = block_til_ready(tty, filp, info);
1474 #ifdef SERIAL_DEBUG_OPEN
1475 printk("mcfrs_open returning after block_til_ready with %d\n",
1481 #ifdef SERIAL_DEBUG_OPEN
1482 printk("mcfrs_open %s successful...\n", tty->name);
1488 * Based on the line number set up the internal interrupt stuff.
1490 static void mcfrs_irqinit(struct mcf_serial *info)
1492 #if defined(CONFIG_M5272)
1493 volatile unsigned long *icrp;
1494 volatile unsigned long *portp;
1495 volatile unsigned char *uartp;
1498 icrp = (volatile unsigned long *) (MCF_MBAR + MCFSIM_ICR2);
1500 switch (info->line) {
1508 printk("MCFRS: don't know how to handle UART %d interrupt?\n",
1513 /* Enable the output lines for the serial ports */
1514 portp = (volatile unsigned long *) (MCF_MBAR + MCFSIM_PBCNT);
1515 *portp = (*portp & ~0x000000ff) | 0x00000055;
1516 portp = (volatile unsigned long *) (MCF_MBAR + MCFSIM_PDCNT);
1517 *portp = (*portp & ~0x000003fc) | 0x000002a8;
1518 #elif defined(CONFIG_M523x) || defined(CONFIG_M527x) || defined(CONFIG_M528x)
1519 volatile unsigned char *icrp, *uartp;
1520 volatile unsigned long *imrp;
1524 icrp = (volatile unsigned char *) (MCF_MBAR + MCFICM_INTC0 +
1525 MCFINTC_ICR0 + MCFINT_UART0 + info->line);
1526 *icrp = 0x33; /* UART0 with level 6, priority 3 */
1528 imrp = (volatile unsigned long *) (MCF_MBAR + MCFICM_INTC0 +
1530 *imrp &= ~((1 << (info->irq - MCFINT_VECBASE)) | 1);
1532 volatile unsigned char *icrp, *uartp;
1534 switch (info->line) {
1536 icrp = (volatile unsigned char *) (MCF_MBAR + MCFSIM_UART1ICR);
1537 *icrp = /*MCFSIM_ICR_AUTOVEC |*/ MCFSIM_ICR_LEVEL6 |
1539 mcf_setimr(mcf_getimr() & ~MCFSIM_IMR_UART1);
1542 icrp = (volatile unsigned char *) (MCF_MBAR + MCFSIM_UART2ICR);
1543 *icrp = /*MCFSIM_ICR_AUTOVEC |*/ MCFSIM_ICR_LEVEL6 |
1545 mcf_setimr(mcf_getimr() & ~MCFSIM_IMR_UART2);
1548 printk("MCFRS: don't know how to handle UART %d interrupt?\n",
1554 uartp[MCFUART_UIVR] = info->irq;
1557 /* Clear mask, so no surprise interrupts. */
1558 uartp[MCFUART_UIMR] = 0;
1560 if (request_irq(info->irq, mcfrs_interrupt, SA_INTERRUPT,
1561 "ColdFire UART", NULL)) {
1562 printk("MCFRS: Unable to attach ColdFire UART %d interrupt "
1563 "vector=%d\n", info->line, info->irq);
1570 char *mcfrs_drivername = "ColdFire internal UART serial driver version 1.00\n";
1574 * Serial stats reporting...
1576 int mcfrs_readproc(char *page, char **start, off_t off, int count,
1577 int *eof, void *data)
1579 struct mcf_serial *info;
1583 len = sprintf(page, mcfrs_drivername);
1584 for (i = 0; (i < NR_PORTS); i++) {
1585 info = &mcfrs_table[i];
1586 len += sprintf((page + len), "%d: port:%x irq=%d baud:%d ",
1587 i, (unsigned int) info->addr, info->irq, info->baud);
1588 if (info->stats.rx || info->stats.tx)
1589 len += sprintf((page + len), "tx:%d rx:%d ",
1590 info->stats.tx, info->stats.rx);
1591 if (info->stats.rxframing)
1592 len += sprintf((page + len), "fe:%d ",
1593 info->stats.rxframing);
1594 if (info->stats.rxparity)
1595 len += sprintf((page + len), "pe:%d ",
1596 info->stats.rxparity);
1597 if (info->stats.rxbreak)
1598 len += sprintf((page + len), "brk:%d ",
1599 info->stats.rxbreak);
1600 if (info->stats.rxoverrun)
1601 len += sprintf((page + len), "oe:%d ",
1602 info->stats.rxoverrun);
1604 str[0] = str[1] = 0;
1605 if ((sigs = mcfrs_getsignals(info))) {
1606 if (sigs & TIOCM_RTS)
1607 strcat(str, "|RTS");
1608 if (sigs & TIOCM_CTS)
1609 strcat(str, "|CTS");
1610 if (sigs & TIOCM_DTR)
1611 strcat(str, "|DTR");
1612 if (sigs & TIOCM_CD)
1616 len += sprintf((page + len), "%s\n", &str[1]);
1623 /* Finally, routines used to initialize the serial driver. */
1625 static void show_serial_version(void)
1627 printk(mcfrs_drivername);
1630 static struct tty_operations mcfrs_ops = {
1632 .close = mcfrs_close,
1633 .write = mcfrs_write,
1634 .flush_chars = mcfrs_flush_chars,
1635 .write_room = mcfrs_write_room,
1636 .chars_in_buffer = mcfrs_chars_in_buffer,
1637 .flush_buffer = mcfrs_flush_buffer,
1638 .ioctl = mcfrs_ioctl,
1639 .throttle = mcfrs_throttle,
1640 .unthrottle = mcfrs_unthrottle,
1641 .set_termios = mcfrs_set_termios,
1643 .start = mcfrs_start,
1644 .hangup = mcfrs_hangup,
1645 .read_proc = mcfrs_readproc,
1646 .wait_until_sent = mcfrs_wait_until_sent,
1647 .tiocmget = mcfrs_tiocmget,
1648 .tiocmset = mcfrs_tiocmset,
1651 /* mcfrs_init inits the driver */
1655 struct mcf_serial *info;
1656 unsigned long flags;
1659 /* Setup base handler, and timer table. */
1661 init_timer(&mcfrs_timer_struct);
1662 mcfrs_timer_struct.function = mcfrs_timer;
1663 mcfrs_timer_struct.data = 0;
1664 mcfrs_timer_struct.expires = jiffies + HZ/25;
1665 add_timer(&mcfrs_timer_struct);
1666 mcfrs_ppstatus = mcf_getppdata() & (MCFPP_DCD0 | MCFPP_DCD1);
1668 mcfrs_serial_driver = alloc_tty_driver(NR_PORTS);
1669 if (!mcfrs_serial_driver)
1672 show_serial_version();
1674 /* Initialize the tty_driver structure */
1675 mcfrs_serial_driver->owner = THIS_MODULE;
1676 mcfrs_serial_driver->name = "ttyS";
1677 mcfrs_serial_driver->devfs_name = "ttys/";
1678 mcfrs_serial_driver->driver_name = "serial";
1679 mcfrs_serial_driver->major = TTY_MAJOR;
1680 mcfrs_serial_driver->minor_start = 64;
1681 mcfrs_serial_driver->type = TTY_DRIVER_TYPE_SERIAL;
1682 mcfrs_serial_driver->subtype = SERIAL_TYPE_NORMAL;
1683 mcfrs_serial_driver->init_termios = tty_std_termios;
1685 mcfrs_serial_driver->init_termios.c_cflag =
1686 mcfrs_console_cbaud | CS8 | CREAD | HUPCL | CLOCAL;
1687 mcfrs_serial_driver->flags = TTY_DRIVER_REAL_RAW;
1689 tty_set_operations(mcfrs_serial_driver, &mcfrs_ops);
1691 if (tty_register_driver(mcfrs_serial_driver)) {
1692 printk("MCFRS: Couldn't register serial driver\n");
1693 put_tty_driver(mcfrs_serial_driver);
1697 local_irq_save(flags);
1700 * Configure all the attached serial ports.
1702 for (i = 0, info = mcfrs_table; (i < NR_PORTS); i++, info++) {
1703 info->magic = SERIAL_MAGIC;
1706 info->custom_divisor = 16;
1707 info->close_delay = 50;
1708 info->closing_wait = 3000;
1712 info->blocked_open = 0;
1713 INIT_WORK(&info->tqueue, mcfrs_offintr, info);
1714 INIT_WORK(&info->tqueue_hangup, do_serial_hangup, info);
1715 init_waitqueue_head(&info->open_wait);
1716 init_waitqueue_head(&info->close_wait);
1719 mcfrs_setsignals(info, 0, 0);
1720 mcfrs_irqinit(info);
1722 printk("ttyS%d at 0x%04x (irq = %d)", info->line,
1723 (unsigned int) info->addr, info->irq);
1724 printk(" is a builtin ColdFire UART\n");
1727 local_irq_restore(flags);
1731 module_init(mcfrs_init);
1733 /****************************************************************************/
1734 /* Serial Console */
1735 /****************************************************************************/
1738 * Quick and dirty UART initialization, for console output.
1741 void mcfrs_init_console(void)
1743 volatile unsigned char *uartp;
1747 * Reset UART, get it into known state...
1749 uartp = (volatile unsigned char *) (MCF_MBAR +
1750 (mcfrs_console_port ? MCFUART_BASE2 : MCFUART_BASE1));
1752 uartp[MCFUART_UCR] = MCFUART_UCR_CMDRESETRX; /* reset RX */
1753 uartp[MCFUART_UCR] = MCFUART_UCR_CMDRESETTX; /* reset TX */
1754 uartp[MCFUART_UCR] = MCFUART_UCR_CMDRESETMRPTR; /* reset MR pointer */
1757 * Set port for defined baud , 8 data bits, 1 stop bit, no parity.
1759 uartp[MCFUART_UMR] = MCFUART_MR1_PARITYNONE | MCFUART_MR1_CS8;
1760 uartp[MCFUART_UMR] = MCFUART_MR2_STOP1;
1762 clk = ((MCF_BUSCLK / mcfrs_console_baud) + 16) / 32; /* set baud */
1763 uartp[MCFUART_UBG1] = (clk & 0xff00) >> 8; /* set msb baud */
1764 uartp[MCFUART_UBG2] = (clk & 0xff); /* set lsb baud */
1766 uartp[MCFUART_UCSR] = MCFUART_UCSR_RXCLKTIMER | MCFUART_UCSR_TXCLKTIMER;
1767 uartp[MCFUART_UCR] = MCFUART_UCR_RXENABLE | MCFUART_UCR_TXENABLE;
1769 mcfrs_console_inited++;
1775 * Setup for console. Argument comes from the boot command line.
1778 int mcfrs_console_setup(struct console *cp, char *arg)
1780 int i, n = CONSOLE_BAUD_RATE;
1785 if (!strncmp(cp->name, "ttyS", 4))
1786 mcfrs_console_port = cp->index;
1787 else if (!strncmp(cp->name, "cua", 3))
1788 mcfrs_console_port = cp->index;
1793 n = simple_strtoul(arg,NULL,0);
1794 for (i = 0; i < MCFRS_BAUD_TABLE_SIZE; i++)
1795 if (mcfrs_baud_table[i] == n)
1797 if (i < MCFRS_BAUD_TABLE_SIZE) {
1798 mcfrs_console_baud = n;
1799 mcfrs_console_cbaud = 0;
1801 mcfrs_console_cbaud |= CBAUDEX;
1804 mcfrs_console_cbaud |= i;
1806 mcfrs_init_console(); /* make sure baud rate changes */
1811 static struct tty_driver *mcfrs_console_device(struct console *c, int *index)
1814 return mcfrs_serial_driver;
1819 * Output a single character, using UART polled mode.
1820 * This is used for console output.
1823 void mcfrs_put_char(char ch)
1825 volatile unsigned char *uartp;
1826 unsigned long flags;
1829 uartp = (volatile unsigned char *) (MCF_MBAR +
1830 (mcfrs_console_port ? MCFUART_BASE2 : MCFUART_BASE1));
1832 local_irq_save(flags);
1833 for (i = 0; (i < 0x10000); i++) {
1834 if (uartp[MCFUART_USR] & MCFUART_USR_TXREADY)
1838 uartp[MCFUART_UTB] = ch;
1839 for (i = 0; (i < 0x10000); i++)
1840 if (uartp[MCFUART_USR] & MCFUART_USR_TXEMPTY)
1844 mcfrs_init_console(); /* try and get it back */
1845 local_irq_restore(flags);
1852 * rs_console_write is registered for printk output.
1855 void mcfrs_console_write(struct console *cp, const char *p, unsigned len)
1857 if (!mcfrs_console_inited)
1858 mcfrs_init_console();
1861 mcfrs_put_char('\r');
1862 mcfrs_put_char(*p++);
1867 * declare our consoles
1870 struct console mcfrs_console = {
1872 .write = mcfrs_console_write,
1873 .device = mcfrs_console_device,
1874 .setup = mcfrs_console_setup,
1875 .flags = CON_PRINTBUFFER,
1879 static int __init mcfrs_console_init(void)
1881 register_console(&mcfrs_console);
1885 console_initcall(mcfrs_console_init);
1887 /****************************************************************************/