2 * mcfserial.c -- serial driver for ColdFire internal UARTS.
4 * Copyright (C) 1999-2003 Greg Ungerer <gerg@snapgear.com>
5 * Copyright (c) 2000-2001 Lineo, Inc. <www.lineo.com>
6 * Copyright (C) 2001-2002 SnapGear Inc. <www.snapgear.com>
8 * Based on code from 68332serial.c which was:
10 * Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu)
11 * Copyright (C) 1998 TSHG
12 * Copyright (c) 1999 Rt-Control Inc. <jeff@uclinux.org>
15 * 08/07/2003 Daniele Bellucci <bellucda@tiscali.it>
16 * some cleanups in mcfrs_write.
20 #include <linux/module.h>
21 #include <linux/errno.h>
22 #include <linux/signal.h>
23 #include <linux/sched.h>
24 #include <linux/timer.h>
25 #include <linux/wait.h>
26 #include <linux/interrupt.h>
27 #include <linux/tty.h>
28 #include <linux/tty_flip.h>
29 #include <linux/string.h>
30 #include <linux/fcntl.h>
32 #include <linux/kernel.h>
33 #include <linux/serial.h>
34 #include <linux/serialP.h>
35 #include <linux/console.h>
36 #include <linux/init.h>
40 #include <asm/system.h>
41 #include <asm/segment.h>
42 #include <asm/semaphore.h>
43 #include <asm/bitops.h>
44 #include <asm/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)
61 #define CONSOLE_BAUD_RATE 19200
62 #define DEFAULT_CBAUD B19200
65 #ifndef CONSOLE_BAUD_RATE
66 #define CONSOLE_BAUD_RATE 9600
67 #define DEFAULT_CBAUD B9600
70 int mcfrs_console_inited = 0;
71 int mcfrs_console_port = -1;
72 int mcfrs_console_baud = CONSOLE_BAUD_RATE;
73 int mcfrs_console_cbaud = DEFAULT_CBAUD;
76 * Driver data structures.
78 static struct tty_driver *mcfrs_serial_driver;
80 /* number of characters left in xmit buffer before we ask for more */
81 #define WAKEUP_CHARS 256
85 #undef SERIAL_DEBUG_OPEN
86 #undef SERIAL_DEBUG_FLOW
95 * Configuration table, UARTs to look for at startup.
97 static struct mcf_serial mcfrs_table[] = {
100 .addr = (volatile unsigned char *) (MCF_MBAR+MCFUART_BASE1),
102 .flags = ASYNC_BOOT_AUTOCONF,
106 .addr = (volatile unsigned char *) (MCF_MBAR+MCFUART_BASE2),
108 .flags = ASYNC_BOOT_AUTOCONF,
113 #define NR_PORTS (sizeof(mcfrs_table) / sizeof(struct mcf_serial))
116 * This is used to figure out the divisor speeds and the timeouts.
118 static int mcfrs_baud_table[] = {
119 0, 50, 75, 110, 134, 150, 200, 300, 600, 1200, 1800, 2400, 4800,
120 9600, 19200, 38400, 57600, 115200, 230400, 460800, 0
122 #define MCFRS_BAUD_TABLE_SIZE \
123 (sizeof(mcfrs_baud_table)/sizeof(mcfrs_baud_table[0]))
126 #ifdef CONFIG_MAGIC_SYSRQ
128 * Magic system request keys. Used for debugging...
130 extern int magic_sysrq_key(int ch);
135 * tmp_buf is used as a temporary buffer by serial_write. We need to
136 * lock it in case the copy_from_user blocks while swapping in a page,
137 * and some other program tries to do a serial write at the same time.
138 * Since the lock will only come under contention when the system is
139 * swapping and available memory is low, it makes sense to share one
140 * buffer across all the serial ports, since it significantly saves
141 * memory if large numbers of serial ports are open.
143 static unsigned char mcfrs_tmp_buf[4096]; /* This is cheating */
144 static DECLARE_MUTEX(mcfrs_tmp_buf_sem);
147 * Forware declarations...
149 static void mcfrs_change_speed(struct mcf_serial *info);
150 static void mcfrs_wait_until_sent(struct tty_struct *tty, int timeout);
153 static inline int serial_paranoia_check(struct mcf_serial *info,
154 char *name, const char *routine)
156 #ifdef SERIAL_PARANOIA_CHECK
157 static const char badmagic[] =
158 "MCFRS(warning): bad magic number for serial struct %s in %s\n";
159 static const char badinfo[] =
160 "MCFRS(warning): null mcf_serial for %s in %s\n";
163 printk(badinfo, name, routine);
166 if (info->magic != SERIAL_MAGIC) {
167 printk(badmagic, name, routine);
175 * Sets or clears DTR and RTS on the requested line.
177 static void mcfrs_setsignals(struct mcf_serial *info, int dtr, int rts)
179 volatile unsigned char *uartp;
183 printk("%s(%d): mcfrs_setsignals(info=%x,dtr=%d,rts=%d)\n",
184 __FILE__, __LINE__, info, dtr, rts);
187 local_irq_save(flags);
191 mcf_setppdata(MCFPP_DTR1, (dtr ? 0 : MCFPP_DTR1));
193 mcf_setppdata(MCFPP_DTR0, (dtr ? 0 : MCFPP_DTR0));
199 info->sigs |= TIOCM_RTS;
200 uartp[MCFUART_UOP1] = MCFUART_UOP_RTS;
202 info->sigs &= ~TIOCM_RTS;
203 uartp[MCFUART_UOP0] = MCFUART_UOP_RTS;
206 local_irq_restore(flags);
211 * Gets values of serial signals.
213 static int mcfrs_getsignals(struct mcf_serial *info)
215 volatile unsigned char *uartp;
218 #if defined(CONFIG_NETtel) && defined(CONFIG_M5307)
219 unsigned short ppdata;
223 printk("%s(%d): mcfrs_getsignals(info=%x)\n", __FILE__, __LINE__);
226 local_irq_save(flags);
228 sigs = (uartp[MCFUART_UIPR] & MCFUART_UIPR_CTS) ? 0 : TIOCM_CTS;
229 sigs |= (info->sigs & TIOCM_RTS);
234 ppdata = mcf_getppdata();
235 if (info->line == 0) {
236 sigs |= (ppdata & MCFPP_DCD0) ? 0 : TIOCM_CD;
237 sigs |= (ppdata & MCFPP_DTR0) ? 0 : TIOCM_DTR;
238 } else if (info->line == 1) {
239 sigs |= (ppdata & MCFPP_DCD1) ? 0 : TIOCM_CD;
240 sigs |= (ppdata & MCFPP_DTR1) ? 0 : TIOCM_DTR;
245 local_irq_restore(flags);
250 * ------------------------------------------------------------
251 * mcfrs_stop() and mcfrs_start()
253 * This routines are called before setting or resetting tty->stopped.
254 * They enable or disable transmitter interrupts, as necessary.
255 * ------------------------------------------------------------
257 static void mcfrs_stop(struct tty_struct *tty)
259 volatile unsigned char *uartp;
260 struct mcf_serial *info = (struct mcf_serial *)tty->driver_data;
263 if (serial_paranoia_check(info, tty->name, "mcfrs_stop"))
266 local_irq_save(flags);
268 info->imr &= ~MCFUART_UIR_TXREADY;
269 uartp[MCFUART_UIMR] = info->imr;
270 local_irq_restore(flags);
273 static void mcfrs_start(struct tty_struct *tty)
275 volatile unsigned char *uartp;
276 struct mcf_serial *info = (struct mcf_serial *)tty->driver_data;
279 if (serial_paranoia_check(info, tty->name, "mcfrs_start"))
282 local_irq_save(flags);
283 if (info->xmit_cnt && info->xmit_buf) {
285 info->imr |= MCFUART_UIR_TXREADY;
286 uartp[MCFUART_UIMR] = info->imr;
288 local_irq_restore(flags);
292 * ----------------------------------------------------------------------
294 * Here starts the interrupt handling routines. All of the following
295 * subroutines are declared as inline and are folded into
296 * mcfrs_interrupt(). They were separated out for readability's sake.
298 * Note: mcfrs_interrupt() is a "fast" interrupt, which means that it
299 * runs with interrupts turned off. People who may want to modify
300 * mcfrs_interrupt() should try to keep the interrupt handler as fast as
301 * possible. After you are done making modifications, it is not a bad
304 * gcc -S -DKERNEL -Wall -Wstrict-prototypes -O6 -fomit-frame-pointer serial.c
306 * and look at the resulting assemble code in serial.s.
308 * - Ted Ts'o (tytso@mit.edu), 7-Mar-93
309 * -----------------------------------------------------------------------
312 static inline void receive_chars(struct mcf_serial *info)
314 volatile unsigned char *uartp;
315 struct tty_struct *tty = info->tty;
316 unsigned char status, ch;
323 while ((status = uartp[MCFUART_USR]) & MCFUART_USR_RXREADY) {
325 if (tty->flip.count >= TTY_FLIPBUF_SIZE)
328 ch = uartp[MCFUART_URB];
331 #ifdef CONFIG_MAGIC_SYSRQ
332 if (mcfrs_console_inited && (info->line == mcfrs_console_port)) {
333 if (magic_sysrq_key(ch))
339 if (status & MCFUART_USR_RXERR)
340 uartp[MCFUART_UCR] = MCFUART_UCR_CMDRESETERR;
341 if (status & MCFUART_USR_RXBREAK) {
342 info->stats.rxbreak++;
343 *tty->flip.flag_buf_ptr++ = TTY_BREAK;
344 } else if (status & MCFUART_USR_RXPARITY) {
345 info->stats.rxparity++;
346 *tty->flip.flag_buf_ptr++ = TTY_PARITY;
347 } else if (status & MCFUART_USR_RXOVERRUN) {
348 info->stats.rxoverrun++;
349 *tty->flip.flag_buf_ptr++ = TTY_OVERRUN;
350 } else if (status & MCFUART_USR_RXFRAMING) {
351 info->stats.rxframing++;
352 *tty->flip.flag_buf_ptr++ = TTY_FRAME;
354 *tty->flip.flag_buf_ptr++ = 0;
356 *tty->flip.char_buf_ptr++ = ch;
359 schedule_work(&tty->flip.work);
363 static inline void transmit_chars(struct mcf_serial *info)
365 volatile unsigned char *uartp;
370 /* Send special char - probably flow control */
371 uartp[MCFUART_UTB] = info->x_char;
376 if ((info->xmit_cnt <= 0) || info->tty->stopped) {
377 info->imr &= ~MCFUART_UIR_TXREADY;
378 uartp[MCFUART_UIMR] = info->imr;
382 while (uartp[MCFUART_USR] & MCFUART_USR_TXREADY) {
383 uartp[MCFUART_UTB] = info->xmit_buf[info->xmit_tail++];
384 info->xmit_tail = info->xmit_tail & (SERIAL_XMIT_SIZE-1);
386 if (--info->xmit_cnt <= 0)
390 if (info->xmit_cnt < WAKEUP_CHARS)
391 schedule_work(&info->tqueue);
396 * This is the serial driver's generic interrupt routine
398 irqreturn_t mcfrs_interrupt(int irq, void *dev_id, struct pt_regs *regs)
400 struct mcf_serial *info;
403 info = &mcfrs_table[(irq - IRQBASE)];
404 isr = info->addr[MCFUART_UISR] & info->imr;
406 if (isr & MCFUART_UIR_RXREADY)
408 if (isr & MCFUART_UIR_TXREADY)
409 transmit_chars(info);
414 * -------------------------------------------------------------------
415 * Here ends the serial interrupt routines.
416 * -------------------------------------------------------------------
419 static void mcfrs_offintr(void *private)
421 struct mcf_serial *info = (struct mcf_serial *) private;
422 struct tty_struct *tty;
432 * Change of state on a DCD line.
434 void mcfrs_modem_change(struct mcf_serial *info, int dcd)
436 if (info->count == 0)
439 if (info->flags & ASYNC_CHECK_CD) {
441 wake_up_interruptible(&info->open_wait);
443 schedule_work(&info->tqueue_hangup);
450 unsigned short mcfrs_ppstatus;
453 * This subroutine is called when the RS_TIMER goes off. It is used
454 * to monitor the state of the DCD lines - since they have no edge
455 * sensors and interrupt generators.
457 static void mcfrs_timer(void)
459 unsigned int ppstatus, dcdval, i;
461 ppstatus = mcf_getppdata() & (MCFPP_DCD0 | MCFPP_DCD1);
463 if (ppstatus != mcfrs_ppstatus) {
464 for (i = 0; (i < 2); i++) {
465 dcdval = (i ? MCFPP_DCD1 : MCFPP_DCD0);
466 if ((ppstatus & dcdval) != (mcfrs_ppstatus & dcdval)) {
467 mcfrs_modem_change(&mcfrs_table[i],
468 ((ppstatus & dcdval) ? 0 : 1));
472 mcfrs_ppstatus = ppstatus;
475 mcfrs_timer_struct.expires = jiffies + HZ/25;
476 add_timer(&mcfrs_timer_struct);
479 #endif /* MCFPP_DCD0 */
483 * This routine is called from the scheduler tqueue when the interrupt
484 * routine has signalled that a hangup has occurred. The path of
485 * hangup processing is:
487 * serial interrupt routine -> (scheduler tqueue) ->
488 * do_serial_hangup() -> tty->hangup() -> mcfrs_hangup()
491 static void do_serial_hangup(void *private)
493 struct mcf_serial *info = (struct mcf_serial *) private;
494 struct tty_struct *tty;
503 static int startup(struct mcf_serial * info)
505 volatile unsigned char *uartp;
508 if (info->flags & ASYNC_INITIALIZED)
511 if (!info->xmit_buf) {
512 info->xmit_buf = (unsigned char *) __get_free_page(GFP_KERNEL);
517 local_irq_save(flags);
519 #ifdef SERIAL_DEBUG_OPEN
520 printk("starting up ttyS%d (irq %d)...\n", info->line, info->irq);
524 * Reset UART, get it into known state...
527 uartp[MCFUART_UCR] = MCFUART_UCR_CMDRESETRX; /* reset RX */
528 uartp[MCFUART_UCR] = MCFUART_UCR_CMDRESETTX; /* reset TX */
529 mcfrs_setsignals(info, 1, 1);
532 clear_bit(TTY_IO_ERROR, &info->tty->flags);
533 info->xmit_cnt = info->xmit_head = info->xmit_tail = 0;
536 * and set the speed of the serial port
538 mcfrs_change_speed(info);
541 * Lastly enable the UART transmitter and receiver, and
544 info->imr = MCFUART_UIR_RXREADY;
545 uartp[MCFUART_UCR] = MCFUART_UCR_RXENABLE | MCFUART_UCR_TXENABLE;
546 uartp[MCFUART_UIMR] = info->imr;
548 info->flags |= ASYNC_INITIALIZED;
549 local_irq_restore(flags);
554 * This routine will shutdown a serial port; interrupts are disabled, and
555 * DTR is dropped if the hangup on close termio flag is on.
557 static void shutdown(struct mcf_serial * info)
559 volatile unsigned char *uartp;
562 if (!(info->flags & ASYNC_INITIALIZED))
565 #ifdef SERIAL_DEBUG_OPEN
566 printk("Shutting down serial port %d (irq %d)....\n", info->line,
570 local_irq_save(flags);
573 uartp[MCFUART_UIMR] = 0; /* mask all interrupts */
574 uartp[MCFUART_UCR] = MCFUART_UCR_CMDRESETRX; /* reset RX */
575 uartp[MCFUART_UCR] = MCFUART_UCR_CMDRESETTX; /* reset TX */
577 if (!info->tty || (info->tty->termios->c_cflag & HUPCL))
578 mcfrs_setsignals(info, 0, 0);
580 if (info->xmit_buf) {
581 free_page((unsigned long) info->xmit_buf);
586 set_bit(TTY_IO_ERROR, &info->tty->flags);
588 info->flags &= ~ASYNC_INITIALIZED;
589 local_irq_restore(flags);
594 * This routine is called to set the UART divisor registers to match
595 * the specified baud rate for a serial port.
597 static void mcfrs_change_speed(struct mcf_serial *info)
599 volatile unsigned char *uartp;
600 unsigned int baudclk, cflag;
602 unsigned char mr1, mr2;
605 unsigned int fraction;
608 if (!info->tty || !info->tty->termios)
610 cflag = info->tty->termios->c_cflag;
615 printk("%s(%d): mcfrs_change_speed()\n", __FILE__, __LINE__);
622 info->tty->termios->c_cflag &= ~CBAUDEX;
627 mcfrs_setsignals(info, 0, -1);
631 /* compute the baudrate clock */
634 * For the MCF5272, also compute the baudrate fraction.
636 baudclk = (MCF_BUSCLK / mcfrs_baud_table[i]) / 32;
637 fraction = MCF_BUSCLK - (baudclk * 32 * mcfrs_baud_table[i]);
639 fraction /= (32 * mcfrs_baud_table[i]);
641 baudclk = ((MCF_BUSCLK / mcfrs_baud_table[i]) + 16) / 32;
644 info->baud = mcfrs_baud_table[i];
646 mr1 = MCFUART_MR1_RXIRQRDY | MCFUART_MR1_RXERRCHAR;
649 switch (cflag & CSIZE) {
650 case CS5: mr1 |= MCFUART_MR1_CS5; break;
651 case CS6: mr1 |= MCFUART_MR1_CS6; break;
652 case CS7: mr1 |= MCFUART_MR1_CS7; break;
654 default: mr1 |= MCFUART_MR1_CS8; break;
657 if (cflag & PARENB) {
658 if (cflag & CMSPAR) {
660 mr1 |= MCFUART_MR1_PARITYMARK;
662 mr1 |= MCFUART_MR1_PARITYSPACE;
665 mr1 |= MCFUART_MR1_PARITYODD;
667 mr1 |= MCFUART_MR1_PARITYEVEN;
670 mr1 |= MCFUART_MR1_PARITYNONE;
674 mr2 |= MCFUART_MR2_STOP2;
676 mr2 |= MCFUART_MR2_STOP1;
678 if (cflag & CRTSCTS) {
679 mr1 |= MCFUART_MR1_RXRTS;
680 mr2 |= MCFUART_MR2_TXCTS;
684 info->flags &= ~ASYNC_CHECK_CD;
686 info->flags |= ASYNC_CHECK_CD;
690 local_irq_save(flags);
692 printk("%s(%d): mr1=%x mr2=%x baudclk=%x\n", __FILE__, __LINE__,
696 Note: pg 12-16 of MCF5206e User's Manual states that a
697 software reset should be performed prior to changing
698 UMR1,2, UCSR, UACR, bit 7
700 uartp[MCFUART_UCR] = MCFUART_UCR_CMDRESETRX; /* reset RX */
701 uartp[MCFUART_UCR] = MCFUART_UCR_CMDRESETTX; /* reset TX */
702 uartp[MCFUART_UCR] = MCFUART_UCR_CMDRESETMRPTR; /* reset MR pointer */
703 uartp[MCFUART_UMR] = mr1;
704 uartp[MCFUART_UMR] = mr2;
705 uartp[MCFUART_UBG1] = (baudclk & 0xff00) >> 8; /* set msb byte */
706 uartp[MCFUART_UBG2] = (baudclk & 0xff); /* set lsb byte */
708 uartp[MCFUART_UFPD] = (fraction & 0xf); /* set fraction */
710 uartp[MCFUART_UCSR] = MCFUART_UCSR_RXCLKTIMER | MCFUART_UCSR_TXCLKTIMER;
711 uartp[MCFUART_UCR] = MCFUART_UCR_RXENABLE | MCFUART_UCR_TXENABLE;
712 mcfrs_setsignals(info, 1, -1);
713 local_irq_restore(flags);
717 static void mcfrs_flush_chars(struct tty_struct *tty)
719 volatile unsigned char *uartp;
720 struct mcf_serial *info = (struct mcf_serial *)tty->driver_data;
723 if (serial_paranoia_check(info, tty->name, "mcfrs_flush_chars"))
726 if (info->xmit_cnt <= 0 || tty->stopped || tty->hw_stopped ||
730 /* Enable transmitter */
731 local_irq_save(flags);
733 info->imr |= MCFUART_UIR_TXREADY;
734 uartp[MCFUART_UIMR] = info->imr;
735 local_irq_restore(flags);
738 static int mcfrs_write(struct tty_struct * tty, int from_user,
739 const unsigned char *buf, int count)
741 volatile unsigned char *uartp;
742 struct mcf_serial *info = (struct mcf_serial *)tty->driver_data;
747 printk("%s(%d): mcfrs_write(tty=%x,from_user=%d,buf=%x,count=%d)\n",
748 __FILE__, __LINE__, (int)tty, from_user, (int)buf, count);
751 if (serial_paranoia_check(info, tty->name, "mcfrs_write"))
754 if (!tty || !info->xmit_buf)
757 local_save_flags(flags);
760 c = min(count, (int) min(((int)SERIAL_XMIT_SIZE) - info->xmit_cnt - 1,
761 ((int)SERIAL_XMIT_SIZE) - info->xmit_head));
762 local_irq_restore(flags);
768 down(&mcfrs_tmp_buf_sem);
769 if (copy_from_user(mcfrs_tmp_buf, buf, c))
773 c = min(c, (int) min(((int)SERIAL_XMIT_SIZE) - info->xmit_cnt - 1,
774 ((int)SERIAL_XMIT_SIZE) - info->xmit_head));
775 local_irq_restore(flags);
776 memcpy(info->xmit_buf + info->xmit_head, mcfrs_tmp_buf, c);
777 up(&mcfrs_tmp_buf_sem);
779 memcpy(info->xmit_buf + info->xmit_head, buf, c);
782 info->xmit_head = (info->xmit_head + c) & (SERIAL_XMIT_SIZE-1);
784 local_irq_restore(flags);
793 info->imr |= MCFUART_UIR_TXREADY;
794 uartp[MCFUART_UIMR] = info->imr;
795 local_irq_restore(flags);
800 static int mcfrs_write_room(struct tty_struct *tty)
802 struct mcf_serial *info = (struct mcf_serial *)tty->driver_data;
805 if (serial_paranoia_check(info, tty->name, "mcfrs_write_room"))
807 ret = SERIAL_XMIT_SIZE - info->xmit_cnt - 1;
813 static int mcfrs_chars_in_buffer(struct tty_struct *tty)
815 struct mcf_serial *info = (struct mcf_serial *)tty->driver_data;
817 if (serial_paranoia_check(info, tty->name, "mcfrs_chars_in_buffer"))
819 return info->xmit_cnt;
822 static void mcfrs_flush_buffer(struct tty_struct *tty)
824 struct mcf_serial *info = (struct mcf_serial *)tty->driver_data;
827 if (serial_paranoia_check(info, tty->name, "mcfrs_flush_buffer"))
830 local_irq_save(flags);
831 info->xmit_cnt = info->xmit_head = info->xmit_tail = 0;
832 local_irq_restore(flags);
838 * ------------------------------------------------------------
841 * This routine is called by the upper-layer tty layer to signal that
842 * incoming characters should be throttled.
843 * ------------------------------------------------------------
845 static void mcfrs_throttle(struct tty_struct * tty)
847 struct mcf_serial *info = (struct mcf_serial *)tty->driver_data;
848 #ifdef SERIAL_DEBUG_THROTTLE
851 printk("throttle %s: %d....\n", _tty_name(tty, buf),
852 tty->ldisc.chars_in_buffer(tty));
855 if (serial_paranoia_check(info, tty->name, "mcfrs_throttle"))
859 info->x_char = STOP_CHAR(tty);
861 /* Turn off RTS line (do this atomic) */
864 static void mcfrs_unthrottle(struct tty_struct * tty)
866 struct mcf_serial *info = (struct mcf_serial *)tty->driver_data;
867 #ifdef SERIAL_DEBUG_THROTTLE
870 printk("unthrottle %s: %d....\n", _tty_name(tty, buf),
871 tty->ldisc.chars_in_buffer(tty));
874 if (serial_paranoia_check(info, tty->name, "mcfrs_unthrottle"))
881 info->x_char = START_CHAR(tty);
884 /* Assert RTS line (do this atomic) */
888 * ------------------------------------------------------------
889 * mcfrs_ioctl() and friends
890 * ------------------------------------------------------------
893 static int get_serial_info(struct mcf_serial * info,
894 struct serial_struct * retinfo)
896 struct serial_struct tmp;
900 memset(&tmp, 0, sizeof(tmp));
901 tmp.type = info->type;
902 tmp.line = info->line;
903 tmp.port = (unsigned int) info->addr;
905 tmp.flags = info->flags;
906 tmp.baud_base = info->baud_base;
907 tmp.close_delay = info->close_delay;
908 tmp.closing_wait = info->closing_wait;
909 tmp.custom_divisor = info->custom_divisor;
910 return copy_to_user(retinfo,&tmp,sizeof(*retinfo)) ? -EFAULT : 0;
913 static int set_serial_info(struct mcf_serial * info,
914 struct serial_struct * new_info)
916 struct serial_struct new_serial;
917 struct mcf_serial old_info;
922 if (copy_from_user(&new_serial,new_info,sizeof(new_serial)))
926 if (!capable(CAP_SYS_ADMIN)) {
927 if ((new_serial.baud_base != info->baud_base) ||
928 (new_serial.type != info->type) ||
929 (new_serial.close_delay != info->close_delay) ||
930 ((new_serial.flags & ~ASYNC_USR_MASK) !=
931 (info->flags & ~ASYNC_USR_MASK)))
933 info->flags = ((info->flags & ~ASYNC_USR_MASK) |
934 (new_serial.flags & ASYNC_USR_MASK));
935 info->custom_divisor = new_serial.custom_divisor;
943 * OK, past this point, all the error checking has been done.
944 * At this point, we start making changes.....
947 info->baud_base = new_serial.baud_base;
948 info->flags = ((info->flags & ~ASYNC_FLAGS) |
949 (new_serial.flags & ASYNC_FLAGS));
950 info->type = new_serial.type;
951 info->close_delay = new_serial.close_delay;
952 info->closing_wait = new_serial.closing_wait;
955 retval = startup(info);
960 * get_lsr_info - get line status register info
962 * Purpose: Let user call ioctl() to get info when the UART physically
963 * is emptied. On bus types like RS485, the transmitter must
964 * release the bus after transmitting. This must be done when
965 * the transmit shift register is empty, not be done when the
966 * transmit holding register is empty. This functionality
967 * allows an RS485 driver to be written in user space.
969 static int get_lsr_info(struct mcf_serial * info, unsigned int *value)
971 volatile unsigned char *uartp;
973 unsigned char status;
975 local_irq_save(flags);
977 status = (uartp[MCFUART_USR] & MCFUART_USR_TXEMPTY) ? TIOCSER_TEMT : 0;
978 local_irq_restore(flags);
980 return put_user(status,value);
984 * This routine sends a break character out the serial port.
986 static void send_break( struct mcf_serial * info, int duration)
988 volatile unsigned char *uartp;
993 current->state = TASK_INTERRUPTIBLE;
996 local_irq_save(flags);
997 uartp[MCFUART_UCR] = MCFUART_UCR_CMDBREAKSTART;
998 schedule_timeout(jiffies + duration);
999 uartp[MCFUART_UCR] = MCFUART_UCR_CMDBREAKSTOP;
1000 local_irq_restore(flags);
1003 static int mcfrs_tiocmget(struct tty_struct *tty, struct file *file)
1005 struct mcf_serial * info = (struct mcf_serial *)tty->driver_data;
1007 if (serial_paranoia_check(info, tty->name, "mcfrs_ioctl"))
1009 if (tty->flags & (1 << TTY_IO_ERROR))
1012 return mcfrs_getsignals(info);
1015 static int mcfrs_tiocmset(struct tty_struct *tty, struct file *file,
1016 unsigned int set, unsigned int clear)
1018 struct mcf_serial * info = (struct mcf_serial *)tty->driver_data;
1019 int rts = -1, dtr = -1;
1021 if (serial_paranoia_check(info, tty->name, "mcfrs_ioctl"))
1023 if (tty->flags & (1 << TTY_IO_ERROR))
1026 if (set & TIOCM_RTS)
1028 if (set & TIOCM_DTR)
1030 if (clear & TIOCM_RTS)
1032 if (clear & TIOCM_DTR)
1035 mcfrs_setsignals(info, dtr, rts);
1040 static int mcfrs_ioctl(struct tty_struct *tty, struct file * file,
1041 unsigned int cmd, unsigned long arg)
1043 struct mcf_serial * info = (struct mcf_serial *)tty->driver_data;
1046 if (serial_paranoia_check(info, tty->name, "mcfrs_ioctl"))
1049 if ((cmd != TIOCGSERIAL) && (cmd != TIOCSSERIAL) &&
1050 (cmd != TIOCSERCONFIG) && (cmd != TIOCSERGWILD) &&
1051 (cmd != TIOCSERSWILD) && (cmd != TIOCSERGSTRUCT)) {
1052 if (tty->flags & (1 << TTY_IO_ERROR))
1057 case TCSBRK: /* SVID version: non-zero arg --> no break */
1058 retval = tty_check_change(tty);
1061 tty_wait_until_sent(tty, 0);
1063 send_break(info, HZ/4); /* 1/4 second */
1065 case TCSBRKP: /* support for POSIX tcsendbreak() */
1066 retval = tty_check_change(tty);
1069 tty_wait_until_sent(tty, 0);
1070 send_break(info, arg ? arg*(HZ/10) : HZ/4);
1073 error = put_user(C_CLOCAL(tty) ? 1 : 0,
1074 (unsigned long *) arg);
1079 get_user(arg, (unsigned long *) arg);
1080 tty->termios->c_cflag =
1081 ((tty->termios->c_cflag & ~CLOCAL) |
1082 (arg ? CLOCAL : 0));
1085 error = verify_area(VERIFY_WRITE, (void *) arg,
1086 sizeof(struct serial_struct));
1089 return get_serial_info(info,
1090 (struct serial_struct *) arg);
1092 return set_serial_info(info,
1093 (struct serial_struct *) arg);
1094 case TIOCSERGETLSR: /* Get line status register */
1095 error = verify_area(VERIFY_WRITE, (void *) arg,
1096 sizeof(unsigned int));
1100 return get_lsr_info(info, (unsigned int *) arg);
1102 case TIOCSERGSTRUCT:
1103 error = copy_to_user((struct mcf_serial *) arg,
1104 info, sizeof(struct mcf_serial));
1112 get_user(val, (unsigned int *) arg);
1113 mcf_setpa(MCFPP_PA11, (val ? 0 : MCFPP_PA11));
1118 val = (mcf_getpa() & MCFPP_PA11) ? 0 : 1;
1119 put_user(val, (unsigned int *) arg);
1125 return -ENOIOCTLCMD;
1130 static void mcfrs_set_termios(struct tty_struct *tty, struct termios *old_termios)
1132 struct mcf_serial *info = (struct mcf_serial *)tty->driver_data;
1134 if (tty->termios->c_cflag == old_termios->c_cflag)
1137 mcfrs_change_speed(info);
1139 if ((old_termios->c_cflag & CRTSCTS) &&
1140 !(tty->termios->c_cflag & CRTSCTS)) {
1141 tty->hw_stopped = 0;
1142 mcfrs_setsignals(info, -1, 1);
1150 * ------------------------------------------------------------
1153 * This routine is called when the serial port gets closed. First, we
1154 * wait for the last remaining data to be sent. Then, we unlink its
1155 * S structure from the interrupt chain if necessary, and we free
1156 * that IRQ if nothing is left in the chain.
1157 * ------------------------------------------------------------
1159 static void mcfrs_close(struct tty_struct *tty, struct file * filp)
1161 volatile unsigned char *uartp;
1162 struct mcf_serial *info = (struct mcf_serial *)tty->driver_data;
1163 unsigned long flags;
1165 if (!info || serial_paranoia_check(info, tty->name, "mcfrs_close"))
1168 local_irq_save(flags);
1170 if (tty_hung_up_p(filp)) {
1171 local_irq_restore(flags);
1175 #ifdef SERIAL_DEBUG_OPEN
1176 printk("mcfrs_close ttyS%d, count = %d\n", info->line, info->count);
1178 if ((tty->count == 1) && (info->count != 1)) {
1180 * Uh, oh. tty->count is 1, which means that the tty
1181 * structure will be freed. Info->count should always
1182 * be one in these conditions. If it's greater than
1183 * one, we've got real problems, since it means the
1184 * serial port won't be shutdown.
1186 printk("MCFRS: bad serial port count; tty->count is 1, "
1187 "info->count is %d\n", info->count);
1190 if (--info->count < 0) {
1191 printk("MCFRS: bad serial port count for ttyS%d: %d\n",
1192 info->line, info->count);
1196 local_irq_restore(flags);
1199 info->flags |= ASYNC_CLOSING;
1202 * Now we wait for the transmit buffer to clear; and we notify
1203 * the line discipline to only process XON/XOFF characters.
1206 if (info->closing_wait != ASYNC_CLOSING_WAIT_NONE)
1207 tty_wait_until_sent(tty, info->closing_wait);
1210 * At this point we stop accepting input. To do this, we
1211 * disable the receive line status interrupts, and tell the
1212 * interrupt driver to stop checking the data ready bit in the
1213 * line status register.
1215 info->imr &= ~MCFUART_UIR_RXREADY;
1217 uartp[MCFUART_UIMR] = info->imr;
1220 /* FIXME: do we need to keep this enabled for console?? */
1221 if (mcfrs_console_inited && (mcfrs_console_port == info->line)) {
1222 /* Do not disable the UART */ ;
1226 if (tty->driver->flush_buffer)
1227 tty->driver->flush_buffer(tty);
1228 tty_ldisc_flush(tty);
1234 if (tty->ldisc.num != ldiscs[N_TTY].num) {
1235 if (tty->ldisc.close)
1236 (tty->ldisc.close)(tty);
1237 tty->ldisc = ldiscs[N_TTY];
1238 tty->termios->c_line = N_TTY;
1239 if (tty->ldisc.open)
1240 (tty->ldisc.open)(tty);
1243 if (info->blocked_open) {
1244 if (info->close_delay) {
1245 current->state = TASK_INTERRUPTIBLE;
1246 schedule_timeout(info->close_delay);
1248 wake_up_interruptible(&info->open_wait);
1250 info->flags &= ~(ASYNC_NORMAL_ACTIVE|ASYNC_CLOSING);
1251 wake_up_interruptible(&info->close_wait);
1252 local_irq_restore(flags);
1256 * mcfrs_wait_until_sent() --- wait until the transmitter is empty
1259 mcfrs_wait_until_sent(struct tty_struct *tty, int timeout)
1262 #define MCF5272_FIFO_SIZE 25 /* fifo size + shift reg */
1264 struct mcf_serial * info = (struct mcf_serial *)tty->driver_data;
1265 volatile unsigned char *uartp;
1266 unsigned long orig_jiffies, fifo_time, char_time, fifo_cnt;
1268 if (serial_paranoia_check(info, tty->name, "mcfrs_wait_until_sent"))
1271 orig_jiffies = jiffies;
1274 * Set the check interval to be 1/5 of the approximate time
1275 * to send the entire fifo, and make it at least 1. The check
1276 * interval should also be less than the timeout.
1278 * Note: we have to use pretty tight timings here to satisfy
1281 fifo_time = (MCF5272_FIFO_SIZE * HZ * 10) / info->baud;
1282 char_time = fifo_time / 5;
1285 if (timeout && timeout < char_time)
1286 char_time = timeout;
1289 * Clamp the timeout period at 2 * the time to empty the
1290 * fifo. Just to be safe, set the minimum at .5 seconds.
1293 if (fifo_time < (HZ/2))
1295 if (!timeout || timeout > fifo_time)
1296 timeout = fifo_time;
1299 * Account for the number of bytes in the UART
1300 * transmitter FIFO plus any byte being shifted out.
1302 uartp = (volatile unsigned char *) info->addr;
1304 fifo_cnt = (uartp[MCFUART_UTF] & MCFUART_UTF_TXB);
1305 if ((uartp[MCFUART_USR] & (MCFUART_USR_TXREADY|
1306 MCFUART_USR_TXEMPTY)) ==
1307 MCFUART_USR_TXREADY)
1311 set_current_state(TASK_INTERRUPTIBLE);
1312 schedule_timeout(char_time);
1313 if (signal_pending(current))
1315 if (timeout && time_after(jiffies, orig_jiffies + timeout))
1320 * For the other coldfire models, assume all data has been sent
1326 * mcfrs_hangup() --- called by tty_hangup() when a hangup is signaled.
1328 void mcfrs_hangup(struct tty_struct *tty)
1330 struct mcf_serial * info = (struct mcf_serial *)tty->driver_data;
1332 if (serial_paranoia_check(info, tty->name, "mcfrs_hangup"))
1335 mcfrs_flush_buffer(tty);
1339 info->flags &= ~ASYNC_NORMAL_ACTIVE;
1341 wake_up_interruptible(&info->open_wait);
1345 * ------------------------------------------------------------
1346 * mcfrs_open() and friends
1347 * ------------------------------------------------------------
1349 static int block_til_ready(struct tty_struct *tty, struct file * filp,
1350 struct mcf_serial *info)
1352 DECLARE_WAITQUEUE(wait, current);
1357 * If the device is in the middle of being closed, then block
1358 * until it's done, and then try again.
1360 if (info->flags & ASYNC_CLOSING) {
1361 interruptible_sleep_on(&info->close_wait);
1362 #ifdef SERIAL_DO_RESTART
1363 if (info->flags & ASYNC_HUP_NOTIFY)
1366 return -ERESTARTSYS;
1373 * If non-blocking mode is set, or the port is not enabled,
1374 * then make the check up front and then exit.
1376 if ((filp->f_flags & O_NONBLOCK) ||
1377 (tty->flags & (1 << TTY_IO_ERROR))) {
1378 info->flags |= ASYNC_NORMAL_ACTIVE;
1382 if (tty->termios->c_cflag & CLOCAL)
1386 * Block waiting for the carrier detect and the line to become
1387 * free (i.e., not in use by the callout). While we are in
1388 * this loop, info->count is dropped by one, so that
1389 * mcfrs_close() knows when to free things. We restore it upon
1390 * exit, either normal or abnormal.
1393 add_wait_queue(&info->open_wait, &wait);
1394 #ifdef SERIAL_DEBUG_OPEN
1395 printk("block_til_ready before block: ttyS%d, count = %d\n",
1396 info->line, info->count);
1399 info->blocked_open++;
1401 local_irq_disable();
1402 mcfrs_setsignals(info, 1, 1);
1404 current->state = TASK_INTERRUPTIBLE;
1405 if (tty_hung_up_p(filp) ||
1406 !(info->flags & ASYNC_INITIALIZED)) {
1407 #ifdef SERIAL_DO_RESTART
1408 if (info->flags & ASYNC_HUP_NOTIFY)
1411 retval = -ERESTARTSYS;
1417 if (!(info->flags & ASYNC_CLOSING) &&
1418 (do_clocal || (mcfrs_getsignals(info) & TIOCM_CD)))
1420 if (signal_pending(current)) {
1421 retval = -ERESTARTSYS;
1424 #ifdef SERIAL_DEBUG_OPEN
1425 printk("block_til_ready blocking: ttyS%d, count = %d\n",
1426 info->line, info->count);
1430 current->state = TASK_RUNNING;
1431 remove_wait_queue(&info->open_wait, &wait);
1432 if (!tty_hung_up_p(filp))
1434 info->blocked_open--;
1435 #ifdef SERIAL_DEBUG_OPEN
1436 printk("block_til_ready after blocking: ttyS%d, count = %d\n",
1437 info->line, info->count);
1441 info->flags |= ASYNC_NORMAL_ACTIVE;
1446 * This routine is called whenever a serial port is opened. It
1447 * enables interrupts for a serial port, linking in its structure into
1448 * the IRQ chain. It also performs the serial-specific
1449 * initialization for the tty structure.
1451 int mcfrs_open(struct tty_struct *tty, struct file * filp)
1453 struct mcf_serial *info;
1457 if ((line < 0) || (line >= NR_PORTS))
1459 info = mcfrs_table + line;
1460 if (serial_paranoia_check(info, tty->name, "mcfrs_open"))
1462 #ifdef SERIAL_DEBUG_OPEN
1463 printk("mcfrs_open %s, count = %d\n", tty->name, info->count);
1466 tty->driver_data = info;
1470 * Start up serial port
1472 retval = startup(info);
1476 retval = block_til_ready(tty, filp, info);
1478 #ifdef SERIAL_DEBUG_OPEN
1479 printk("mcfrs_open returning after block_til_ready with %d\n",
1485 #ifdef SERIAL_DEBUG_OPEN
1486 printk("mcfrs_open %s successful...\n", tty->name);
1492 * Based on the line number set up the internal interrupt stuff.
1494 static void mcfrs_irqinit(struct mcf_serial *info)
1496 #if defined(CONFIG_M5272)
1497 volatile unsigned long *icrp;
1498 volatile unsigned long *portp;
1499 volatile unsigned char *uartp;
1502 icrp = (volatile unsigned long *) (MCF_MBAR + MCFSIM_ICR2);
1504 switch (info->line) {
1512 printk("MCFRS: don't know how to handle UART %d interrupt?\n",
1517 /* Enable the output lines for the serial ports */
1518 portp = (volatile unsigned long *) (MCF_MBAR + MCFSIM_PBCNT);
1519 *portp = (*portp & ~0x000000ff) | 0x00000055;
1520 portp = (volatile unsigned long *) (MCF_MBAR + MCFSIM_PDCNT);
1521 *portp = (*portp & ~0x000003fc) | 0x000002a8;
1522 #elif defined(CONFIG_M5282)
1523 volatile unsigned char *icrp, *uartp;
1524 volatile unsigned long *imrp;
1528 icrp = (volatile unsigned char *) (MCF_MBAR + MCFICM_INTC0 +
1529 MCFINTC_ICR0 + MCFINT_UART0 + info->line);
1530 *icrp = 0x33; /* UART0 with level 6, priority 3 */
1532 imrp = (volatile unsigned long *) (MCF_MBAR + MCFICM_INTC0 +
1534 *imrp &= ~((1 << (info->irq - 64)) | 1);
1536 volatile unsigned char *icrp, *uartp;
1538 switch (info->line) {
1540 icrp = (volatile unsigned char *) (MCF_MBAR + MCFSIM_UART1ICR);
1541 *icrp = /*MCFSIM_ICR_AUTOVEC |*/ MCFSIM_ICR_LEVEL6 |
1543 mcf_setimr(mcf_getimr() & ~MCFSIM_IMR_UART1);
1546 icrp = (volatile unsigned char *) (MCF_MBAR + MCFSIM_UART2ICR);
1547 *icrp = /*MCFSIM_ICR_AUTOVEC |*/ MCFSIM_ICR_LEVEL6 |
1549 mcf_setimr(mcf_getimr() & ~MCFSIM_IMR_UART2);
1552 printk("MCFRS: don't know how to handle UART %d interrupt?\n",
1558 uartp[MCFUART_UIVR] = info->irq;
1561 /* Clear mask, so no surprise interrupts. */
1562 uartp[MCFUART_UIMR] = 0;
1564 if (request_irq(info->irq, mcfrs_interrupt, SA_INTERRUPT,
1565 "ColdFire UART", NULL)) {
1566 printk("MCFRS: Unable to attach ColdFire UART %d interrupt "
1567 "vector=%d\n", info->line, info->irq);
1574 char *mcfrs_drivername = "ColdFire internal UART serial driver version 1.00\n";
1578 * Serial stats reporting...
1580 int mcfrs_readproc(char *page, char **start, off_t off, int count,
1581 int *eof, void *data)
1583 struct mcf_serial *info;
1587 len = sprintf(page, mcfrs_drivername);
1588 for (i = 0; (i < NR_PORTS); i++) {
1589 info = &mcfrs_table[i];
1590 len += sprintf((page + len), "%d: port:%x irq=%d baud:%d ",
1591 i, (unsigned int) info->addr, info->irq, info->baud);
1592 if (info->stats.rx || info->stats.tx)
1593 len += sprintf((page + len), "tx:%d rx:%d ",
1594 info->stats.tx, info->stats.rx);
1595 if (info->stats.rxframing)
1596 len += sprintf((page + len), "fe:%d ",
1597 info->stats.rxframing);
1598 if (info->stats.rxparity)
1599 len += sprintf((page + len), "pe:%d ",
1600 info->stats.rxparity);
1601 if (info->stats.rxbreak)
1602 len += sprintf((page + len), "brk:%d ",
1603 info->stats.rxbreak);
1604 if (info->stats.rxoverrun)
1605 len += sprintf((page + len), "oe:%d ",
1606 info->stats.rxoverrun);
1608 str[0] = str[1] = 0;
1609 if ((sigs = mcfrs_getsignals(info))) {
1610 if (sigs & TIOCM_RTS)
1611 strcat(str, "|RTS");
1612 if (sigs & TIOCM_CTS)
1613 strcat(str, "|CTS");
1614 if (sigs & TIOCM_DTR)
1615 strcat(str, "|DTR");
1616 if (sigs & TIOCM_CD)
1620 len += sprintf((page + len), "%s\n", &str[1]);
1627 /* Finally, routines used to initialize the serial driver. */
1629 static void show_serial_version(void)
1631 printk(mcfrs_drivername);
1634 static struct tty_operations mcfrs_ops = {
1636 .close = mcfrs_close,
1637 .write = mcfrs_write,
1638 .flush_chars = mcfrs_flush_chars,
1639 .write_room = mcfrs_write_room,
1640 .chars_in_buffer = mcfrs_chars_in_buffer,
1641 .flush_buffer = mcfrs_flush_buffer,
1642 .ioctl = mcfrs_ioctl,
1643 .throttle = mcfrs_throttle,
1644 .unthrottle = mcfrs_unthrottle,
1645 .set_termios = mcfrs_set_termios,
1647 .start = mcfrs_start,
1648 .hangup = mcfrs_hangup,
1649 .read_proc = mcfrs_readproc,
1650 .wait_until_sent = mcfrs_wait_until_sent,
1651 .tiocmget = mcfrs_tiocmget,
1652 .tiocmset = mcfrs_tiocmset,
1655 /* mcfrs_init inits the driver */
1659 struct mcf_serial *info;
1660 unsigned long flags;
1663 /* Setup base handler, and timer table. */
1665 init_timer(&mcfrs_timer_struct);
1666 mcfrs_timer_struct.function = mcfrs_timer;
1667 mcfrs_timer_struct.data = 0;
1668 mcfrs_timer_struct.expires = jiffies + HZ/25;
1669 add_timer(&mcfrs_timer_struct);
1670 mcfrs_ppstatus = mcf_getppdata() & (MCFPP_DCD0 | MCFPP_DCD1);
1672 mcfrs_serial_driver = alloc_tty_driver(NR_PORTS);
1673 if (!mcfrs_serial_driver)
1676 show_serial_version();
1678 /* Initialize the tty_driver structure */
1679 mcfrs_serial_driver->owner = THIS_MODULE;
1680 mcfrs_serial_driver->name = "ttyS";
1681 mcfrs_serial_driver->devfs_name = "ttys/";
1682 mcfrs_serial_driver->driver_name = "serial";
1683 mcfrs_serial_driver->major = TTY_MAJOR;
1684 mcfrs_serial_driver->minor_start = 64;
1685 mcfrs_serial_driver->type = TTY_DRIVER_TYPE_SERIAL;
1686 mcfrs_serial_driver->subtype = SERIAL_TYPE_NORMAL;
1687 mcfrs_serial_driver->init_termios = tty_std_termios;
1689 mcfrs_serial_driver->init_termios.c_cflag =
1690 mcfrs_console_cbaud | CS8 | CREAD | HUPCL | CLOCAL;
1691 mcfrs_serial_driver->flags = TTY_DRIVER_REAL_RAW;
1693 tty_set_operations(mcfrs_serial_driver, &mcfrs_ops);
1695 if (tty_register_driver(mcfrs_serial_driver)) {
1696 printk("MCFRS: Couldn't register serial driver\n");
1697 put_tty_driver(mcfrs_serial_driver);
1701 local_irq_save(flags);
1704 * Configure all the attached serial ports.
1706 for (i = 0, info = mcfrs_table; (i < NR_PORTS); i++, info++) {
1707 info->magic = SERIAL_MAGIC;
1710 info->custom_divisor = 16;
1711 info->close_delay = 50;
1712 info->closing_wait = 3000;
1716 info->blocked_open = 0;
1717 INIT_WORK(&info->tqueue, mcfrs_offintr, info);
1718 INIT_WORK(&info->tqueue_hangup, do_serial_hangup, info);
1719 init_waitqueue_head(&info->open_wait);
1720 init_waitqueue_head(&info->close_wait);
1723 mcfrs_setsignals(info, 0, 0);
1724 mcfrs_irqinit(info);
1726 printk("ttyS%d at 0x%04x (irq = %d)", info->line,
1727 (unsigned int) info->addr, info->irq);
1728 printk(" is a builtin ColdFire UART\n");
1731 local_irq_restore(flags);
1735 module_init(mcfrs_init);
1737 /****************************************************************************/
1738 /* Serial Console */
1739 /****************************************************************************/
1742 * Quick and dirty UART initialization, for console output.
1745 void mcfrs_init_console(void)
1747 volatile unsigned char *uartp;
1751 * Reset UART, get it into known state...
1753 uartp = (volatile unsigned char *) (MCF_MBAR +
1754 (mcfrs_console_port ? MCFUART_BASE2 : MCFUART_BASE1));
1756 uartp[MCFUART_UCR] = MCFUART_UCR_CMDRESETRX; /* reset RX */
1757 uartp[MCFUART_UCR] = MCFUART_UCR_CMDRESETTX; /* reset TX */
1758 uartp[MCFUART_UCR] = MCFUART_UCR_CMDRESETMRPTR; /* reset MR pointer */
1761 * Set port for defined baud , 8 data bits, 1 stop bit, no parity.
1763 uartp[MCFUART_UMR] = MCFUART_MR1_PARITYNONE | MCFUART_MR1_CS8;
1764 uartp[MCFUART_UMR] = MCFUART_MR2_STOP1;
1766 clk = ((MCF_BUSCLK / mcfrs_console_baud) + 16) / 32; /* set baud */
1767 uartp[MCFUART_UBG1] = (clk & 0xff00) >> 8; /* set msb baud */
1768 uartp[MCFUART_UBG2] = (clk & 0xff); /* set lsb baud */
1770 uartp[MCFUART_UCSR] = MCFUART_UCSR_RXCLKTIMER | MCFUART_UCSR_TXCLKTIMER;
1771 uartp[MCFUART_UCR] = MCFUART_UCR_RXENABLE | MCFUART_UCR_TXENABLE;
1773 mcfrs_console_inited++;
1779 * Setup for console. Argument comes from the boot command line.
1782 int mcfrs_console_setup(struct console *cp, char *arg)
1784 int i, n = CONSOLE_BAUD_RATE;
1789 if (!strncmp(cp->name, "ttyS", 4))
1790 mcfrs_console_port = cp->index;
1791 else if (!strncmp(cp->name, "cua", 3))
1792 mcfrs_console_port = cp->index;
1797 n = simple_strtoul(arg,NULL,0);
1798 for (i = 0; i < MCFRS_BAUD_TABLE_SIZE; i++)
1799 if (mcfrs_baud_table[i] == n)
1801 if (i < MCFRS_BAUD_TABLE_SIZE) {
1802 mcfrs_console_baud = n;
1803 mcfrs_console_cbaud = 0;
1805 mcfrs_console_cbaud |= CBAUDEX;
1808 mcfrs_console_cbaud |= i;
1810 mcfrs_init_console(); /* make sure baud rate changes */
1815 static struct tty_driver *mcfrs_console_device(struct console *c, int *index)
1818 return mcfrs_serial_driver;
1823 * Output a single character, using UART polled mode.
1824 * This is used for console output.
1827 void mcfrs_put_char(char ch)
1829 volatile unsigned char *uartp;
1830 unsigned long flags;
1833 uartp = (volatile unsigned char *) (MCF_MBAR +
1834 (mcfrs_console_port ? MCFUART_BASE2 : MCFUART_BASE1));
1836 local_irq_save(flags);
1837 for (i = 0; (i < 0x10000); i++) {
1838 if (uartp[MCFUART_USR] & MCFUART_USR_TXREADY)
1842 uartp[MCFUART_UTB] = ch;
1843 for (i = 0; (i < 0x10000); i++)
1844 if (uartp[MCFUART_USR] & MCFUART_USR_TXEMPTY)
1848 mcfrs_init_console(); /* try and get it back */
1849 local_irq_restore(flags);
1856 * rs_console_write is registered for printk output.
1859 void mcfrs_console_write(struct console *cp, const char *p, unsigned len)
1861 if (!mcfrs_console_inited)
1862 mcfrs_init_console();
1865 mcfrs_put_char('\r');
1866 mcfrs_put_char(*p++);
1871 * declare our consoles
1874 struct console mcfrs_console = {
1876 .write = mcfrs_console_write,
1877 .device = mcfrs_console_device,
1878 .setup = mcfrs_console_setup,
1879 .flags = CON_PRINTBUFFER,
1883 static int __init mcfrs_console_init(void)
1885 register_console(&mcfrs_console);
1889 console_initcall(mcfrs_console_init);
1891 /****************************************************************************/