2 * mcfserial.c -- serial driver for ColdFire internal UARTS.
4 * Copyright (C) 1999-2003 Greg Ungerer <gerg@snapgear.com>
5 * Copyright (c) 2000-2001 Lineo, Inc. <www.lineo.com>
6 * Copyright (C) 2001-2002 SnapGear Inc. <www.snapgear.com>
8 * Based on code from 68332serial.c which was:
10 * Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu)
11 * Copyright (C) 1998 TSHG
12 * Copyright (c) 1999 Rt-Control Inc. <jeff@uclinux.org>
15 * 08/07/2003 Daniele Bellucci <bellucda@tiscali.it>
16 * some cleanups in mcfrs_write.
20 #include <linux/module.h>
21 #include <linux/errno.h>
22 #include <linux/signal.h>
23 #include <linux/sched.h>
24 #include <linux/timer.h>
25 #include <linux/wait.h>
26 #include <linux/interrupt.h>
27 #include <linux/tty.h>
28 #include <linux/tty_flip.h>
29 #include <linux/string.h>
30 #include <linux/fcntl.h>
32 #include <linux/kernel.h>
33 #include <linux/serial.h>
34 #include <linux/serialP.h>
35 #include <linux/console.h>
36 #include <linux/init.h>
37 #include <linux/bitops.h>
38 #include <linux/delay.h>
42 #include <asm/system.h>
43 #include <asm/segment.h>
44 #include <asm/semaphore.h>
45 #include <asm/delay.h>
46 #include <asm/coldfire.h>
47 #include <asm/mcfsim.h>
48 #include <asm/mcfuart.h>
49 #include <asm/nettel.h>
50 #include <asm/uaccess.h>
51 #include "mcfserial.h"
53 struct timer_list mcfrs_timer_struct;
56 * Default console baud rate, we use this as the default
57 * for all ports so init can just open /dev/console and
58 * keep going. Perhaps one day the cflag settings for the
59 * console can be used instead.
61 #if defined(CONFIG_ARNEWSH) || defined(CONFIG_MOTOROLA) || defined(CONFIG_senTec) || defined(CONFIG_SNEHA)
62 #define CONSOLE_BAUD_RATE 19200
63 #define DEFAULT_CBAUD B19200
66 #if defined(CONFIG_HW_FEITH)
67 #define CONSOLE_BAUD_RATE 38400
68 #define DEFAULT_CBAUD B38400
71 #ifndef CONSOLE_BAUD_RATE
72 #define CONSOLE_BAUD_RATE 9600
73 #define DEFAULT_CBAUD B9600
76 int mcfrs_console_inited = 0;
77 int mcfrs_console_port = -1;
78 int mcfrs_console_baud = CONSOLE_BAUD_RATE;
79 int mcfrs_console_cbaud = DEFAULT_CBAUD;
82 * Driver data structures.
84 static struct tty_driver *mcfrs_serial_driver;
86 /* number of characters left in xmit buffer before we ask for more */
87 #define WAKEUP_CHARS 256
91 #undef SERIAL_DEBUG_OPEN
92 #undef SERIAL_DEBUG_FLOW
94 #if defined(CONFIG_M527x) || defined(CONFIG_M528x)
95 #define IRQBASE (MCFINT_VECBASE+MCFINT_UART0)
101 * Configuration table, UARTs to look for at startup.
103 static struct mcf_serial mcfrs_table[] = {
106 .addr = (volatile unsigned char *) (MCF_MBAR+MCFUART_BASE1),
108 .flags = ASYNC_BOOT_AUTOCONF,
112 .addr = (volatile unsigned char *) (MCF_MBAR+MCFUART_BASE2),
114 .flags = ASYNC_BOOT_AUTOCONF,
119 #define NR_PORTS (sizeof(mcfrs_table) / sizeof(struct mcf_serial))
122 * This is used to figure out the divisor speeds and the timeouts.
124 static int mcfrs_baud_table[] = {
125 0, 50, 75, 110, 134, 150, 200, 300, 600, 1200, 1800, 2400, 4800,
126 9600, 19200, 38400, 57600, 115200, 230400, 460800, 0
128 #define MCFRS_BAUD_TABLE_SIZE \
129 (sizeof(mcfrs_baud_table)/sizeof(mcfrs_baud_table[0]))
132 #ifdef CONFIG_MAGIC_SYSRQ
134 * Magic system request keys. Used for debugging...
136 extern int magic_sysrq_key(int ch);
141 * tmp_buf is used as a temporary buffer by serial_write. We need to
142 * lock it in case the copy_from_user blocks while swapping in a page,
143 * and some other program tries to do a serial write at the same time.
144 * Since the lock will only come under contention when the system is
145 * swapping and available memory is low, it makes sense to share one
146 * buffer across all the serial ports, since it significantly saves
147 * memory if large numbers of serial ports are open.
149 static unsigned char mcfrs_tmp_buf[4096]; /* This is cheating */
150 static DECLARE_MUTEX(mcfrs_tmp_buf_sem);
153 * Forware declarations...
155 static void mcfrs_change_speed(struct mcf_serial *info);
156 static void mcfrs_wait_until_sent(struct tty_struct *tty, int timeout);
159 static inline int serial_paranoia_check(struct mcf_serial *info,
160 char *name, const char *routine)
162 #ifdef SERIAL_PARANOIA_CHECK
163 static const char badmagic[] =
164 "MCFRS(warning): bad magic number for serial struct %s in %s\n";
165 static const char badinfo[] =
166 "MCFRS(warning): null mcf_serial for %s in %s\n";
169 printk(badinfo, name, routine);
172 if (info->magic != SERIAL_MAGIC) {
173 printk(badmagic, name, routine);
181 * Sets or clears DTR and RTS on the requested line.
183 static void mcfrs_setsignals(struct mcf_serial *info, int dtr, int rts)
185 volatile unsigned char *uartp;
189 printk("%s(%d): mcfrs_setsignals(info=%x,dtr=%d,rts=%d)\n",
190 __FILE__, __LINE__, info, dtr, rts);
193 local_irq_save(flags);
197 mcf_setppdata(MCFPP_DTR1, (dtr ? 0 : MCFPP_DTR1));
199 mcf_setppdata(MCFPP_DTR0, (dtr ? 0 : MCFPP_DTR0));
205 info->sigs |= TIOCM_RTS;
206 uartp[MCFUART_UOP1] = MCFUART_UOP_RTS;
208 info->sigs &= ~TIOCM_RTS;
209 uartp[MCFUART_UOP0] = MCFUART_UOP_RTS;
212 local_irq_restore(flags);
217 * Gets values of serial signals.
219 static int mcfrs_getsignals(struct mcf_serial *info)
221 volatile unsigned char *uartp;
224 #if defined(CONFIG_NETtel) && defined(CONFIG_M5307)
225 unsigned short ppdata;
229 printk("%s(%d): mcfrs_getsignals(info=%x)\n", __FILE__, __LINE__);
232 local_irq_save(flags);
234 sigs = (uartp[MCFUART_UIPR] & MCFUART_UIPR_CTS) ? 0 : TIOCM_CTS;
235 sigs |= (info->sigs & TIOCM_RTS);
240 ppdata = mcf_getppdata();
241 if (info->line == 0) {
242 sigs |= (ppdata & MCFPP_DCD0) ? 0 : TIOCM_CD;
243 sigs |= (ppdata & MCFPP_DTR0) ? 0 : TIOCM_DTR;
244 } else if (info->line == 1) {
245 sigs |= (ppdata & MCFPP_DCD1) ? 0 : TIOCM_CD;
246 sigs |= (ppdata & MCFPP_DTR1) ? 0 : TIOCM_DTR;
251 local_irq_restore(flags);
256 * ------------------------------------------------------------
257 * mcfrs_stop() and mcfrs_start()
259 * This routines are called before setting or resetting tty->stopped.
260 * They enable or disable transmitter interrupts, as necessary.
261 * ------------------------------------------------------------
263 static void mcfrs_stop(struct tty_struct *tty)
265 volatile unsigned char *uartp;
266 struct mcf_serial *info = (struct mcf_serial *)tty->driver_data;
269 if (serial_paranoia_check(info, tty->name, "mcfrs_stop"))
272 local_irq_save(flags);
274 info->imr &= ~MCFUART_UIR_TXREADY;
275 uartp[MCFUART_UIMR] = info->imr;
276 local_irq_restore(flags);
279 static void mcfrs_start(struct tty_struct *tty)
281 volatile unsigned char *uartp;
282 struct mcf_serial *info = (struct mcf_serial *)tty->driver_data;
285 if (serial_paranoia_check(info, tty->name, "mcfrs_start"))
288 local_irq_save(flags);
289 if (info->xmit_cnt && info->xmit_buf) {
291 info->imr |= MCFUART_UIR_TXREADY;
292 uartp[MCFUART_UIMR] = info->imr;
294 local_irq_restore(flags);
298 * ----------------------------------------------------------------------
300 * Here starts the interrupt handling routines. All of the following
301 * subroutines are declared as inline and are folded into
302 * mcfrs_interrupt(). They were separated out for readability's sake.
304 * Note: mcfrs_interrupt() is a "fast" interrupt, which means that it
305 * runs with interrupts turned off. People who may want to modify
306 * mcfrs_interrupt() should try to keep the interrupt handler as fast as
307 * possible. After you are done making modifications, it is not a bad
310 * gcc -S -DKERNEL -Wall -Wstrict-prototypes -O6 -fomit-frame-pointer serial.c
312 * and look at the resulting assemble code in serial.s.
314 * - Ted Ts'o (tytso@mit.edu), 7-Mar-93
315 * -----------------------------------------------------------------------
318 static inline void receive_chars(struct mcf_serial *info)
320 volatile unsigned char *uartp;
321 struct tty_struct *tty = info->tty;
322 unsigned char status, ch;
329 while ((status = uartp[MCFUART_USR]) & MCFUART_USR_RXREADY) {
331 if (tty->flip.count >= TTY_FLIPBUF_SIZE)
334 ch = uartp[MCFUART_URB];
337 #ifdef CONFIG_MAGIC_SYSRQ
338 if (mcfrs_console_inited && (info->line == mcfrs_console_port)) {
339 if (magic_sysrq_key(ch))
345 if (status & MCFUART_USR_RXERR) {
346 uartp[MCFUART_UCR] = MCFUART_UCR_CMDRESETERR;
347 if (status & MCFUART_USR_RXBREAK) {
348 info->stats.rxbreak++;
349 *tty->flip.flag_buf_ptr++ = TTY_BREAK;
350 } else if (status & MCFUART_USR_RXPARITY) {
351 info->stats.rxparity++;
352 *tty->flip.flag_buf_ptr++ = TTY_PARITY;
353 } else if (status & MCFUART_USR_RXOVERRUN) {
354 info->stats.rxoverrun++;
355 *tty->flip.flag_buf_ptr++ = TTY_OVERRUN;
356 } else if (status & MCFUART_USR_RXFRAMING) {
357 info->stats.rxframing++;
358 *tty->flip.flag_buf_ptr++ = TTY_FRAME;
360 /* This should never happen... */
361 *tty->flip.flag_buf_ptr++ = 0;
364 *tty->flip.flag_buf_ptr++ = 0;
366 *tty->flip.char_buf_ptr++ = ch;
369 schedule_work(&tty->flip.work);
373 static inline void transmit_chars(struct mcf_serial *info)
375 volatile unsigned char *uartp;
380 /* Send special char - probably flow control */
381 uartp[MCFUART_UTB] = info->x_char;
386 if ((info->xmit_cnt <= 0) || info->tty->stopped) {
387 info->imr &= ~MCFUART_UIR_TXREADY;
388 uartp[MCFUART_UIMR] = info->imr;
392 while (uartp[MCFUART_USR] & MCFUART_USR_TXREADY) {
393 uartp[MCFUART_UTB] = info->xmit_buf[info->xmit_tail++];
394 info->xmit_tail = info->xmit_tail & (SERIAL_XMIT_SIZE-1);
396 if (--info->xmit_cnt <= 0)
400 if (info->xmit_cnt < WAKEUP_CHARS)
401 schedule_work(&info->tqueue);
406 * This is the serial driver's generic interrupt routine
408 irqreturn_t mcfrs_interrupt(int irq, void *dev_id, struct pt_regs *regs)
410 struct mcf_serial *info;
413 info = &mcfrs_table[(irq - IRQBASE)];
414 isr = info->addr[MCFUART_UISR] & info->imr;
416 if (isr & MCFUART_UIR_RXREADY)
418 if (isr & MCFUART_UIR_TXREADY)
419 transmit_chars(info);
424 * -------------------------------------------------------------------
425 * Here ends the serial interrupt routines.
426 * -------------------------------------------------------------------
429 static void mcfrs_offintr(void *private)
431 struct mcf_serial *info = (struct mcf_serial *) private;
432 struct tty_struct *tty;
442 * Change of state on a DCD line.
444 void mcfrs_modem_change(struct mcf_serial *info, int dcd)
446 if (info->count == 0)
449 if (info->flags & ASYNC_CHECK_CD) {
451 wake_up_interruptible(&info->open_wait);
453 schedule_work(&info->tqueue_hangup);
460 unsigned short mcfrs_ppstatus;
463 * This subroutine is called when the RS_TIMER goes off. It is used
464 * to monitor the state of the DCD lines - since they have no edge
465 * sensors and interrupt generators.
467 static void mcfrs_timer(void)
469 unsigned int ppstatus, dcdval, i;
471 ppstatus = mcf_getppdata() & (MCFPP_DCD0 | MCFPP_DCD1);
473 if (ppstatus != mcfrs_ppstatus) {
474 for (i = 0; (i < 2); i++) {
475 dcdval = (i ? MCFPP_DCD1 : MCFPP_DCD0);
476 if ((ppstatus & dcdval) != (mcfrs_ppstatus & dcdval)) {
477 mcfrs_modem_change(&mcfrs_table[i],
478 ((ppstatus & dcdval) ? 0 : 1));
482 mcfrs_ppstatus = ppstatus;
485 mcfrs_timer_struct.expires = jiffies + HZ/25;
486 add_timer(&mcfrs_timer_struct);
489 #endif /* MCFPP_DCD0 */
493 * This routine is called from the scheduler tqueue when the interrupt
494 * routine has signalled that a hangup has occurred. The path of
495 * hangup processing is:
497 * serial interrupt routine -> (scheduler tqueue) ->
498 * do_serial_hangup() -> tty->hangup() -> mcfrs_hangup()
501 static void do_serial_hangup(void *private)
503 struct mcf_serial *info = (struct mcf_serial *) private;
504 struct tty_struct *tty;
513 static int startup(struct mcf_serial * info)
515 volatile unsigned char *uartp;
518 if (info->flags & ASYNC_INITIALIZED)
521 if (!info->xmit_buf) {
522 info->xmit_buf = (unsigned char *) __get_free_page(GFP_KERNEL);
527 local_irq_save(flags);
529 #ifdef SERIAL_DEBUG_OPEN
530 printk("starting up ttyS%d (irq %d)...\n", info->line, info->irq);
534 * Reset UART, get it into known state...
537 uartp[MCFUART_UCR] = MCFUART_UCR_CMDRESETRX; /* reset RX */
538 uartp[MCFUART_UCR] = MCFUART_UCR_CMDRESETTX; /* reset TX */
539 mcfrs_setsignals(info, 1, 1);
542 clear_bit(TTY_IO_ERROR, &info->tty->flags);
543 info->xmit_cnt = info->xmit_head = info->xmit_tail = 0;
546 * and set the speed of the serial port
548 mcfrs_change_speed(info);
551 * Lastly enable the UART transmitter and receiver, and
554 info->imr = MCFUART_UIR_RXREADY;
555 uartp[MCFUART_UCR] = MCFUART_UCR_RXENABLE | MCFUART_UCR_TXENABLE;
556 uartp[MCFUART_UIMR] = info->imr;
558 info->flags |= ASYNC_INITIALIZED;
559 local_irq_restore(flags);
564 * This routine will shutdown a serial port; interrupts are disabled, and
565 * DTR is dropped if the hangup on close termio flag is on.
567 static void shutdown(struct mcf_serial * info)
569 volatile unsigned char *uartp;
572 if (!(info->flags & ASYNC_INITIALIZED))
575 #ifdef SERIAL_DEBUG_OPEN
576 printk("Shutting down serial port %d (irq %d)....\n", info->line,
580 local_irq_save(flags);
583 uartp[MCFUART_UIMR] = 0; /* mask all interrupts */
584 uartp[MCFUART_UCR] = MCFUART_UCR_CMDRESETRX; /* reset RX */
585 uartp[MCFUART_UCR] = MCFUART_UCR_CMDRESETTX; /* reset TX */
587 if (!info->tty || (info->tty->termios->c_cflag & HUPCL))
588 mcfrs_setsignals(info, 0, 0);
590 if (info->xmit_buf) {
591 free_page((unsigned long) info->xmit_buf);
596 set_bit(TTY_IO_ERROR, &info->tty->flags);
598 info->flags &= ~ASYNC_INITIALIZED;
599 local_irq_restore(flags);
604 * This routine is called to set the UART divisor registers to match
605 * the specified baud rate for a serial port.
607 static void mcfrs_change_speed(struct mcf_serial *info)
609 volatile unsigned char *uartp;
610 unsigned int baudclk, cflag;
612 unsigned char mr1, mr2;
615 unsigned int fraction;
618 if (!info->tty || !info->tty->termios)
620 cflag = info->tty->termios->c_cflag;
625 printk("%s(%d): mcfrs_change_speed()\n", __FILE__, __LINE__);
632 info->tty->termios->c_cflag &= ~CBAUDEX;
637 mcfrs_setsignals(info, 0, -1);
641 /* compute the baudrate clock */
644 * For the MCF5272, also compute the baudrate fraction.
646 baudclk = (MCF_BUSCLK / mcfrs_baud_table[i]) / 32;
647 fraction = MCF_BUSCLK - (baudclk * 32 * mcfrs_baud_table[i]);
649 fraction /= (32 * mcfrs_baud_table[i]);
651 baudclk = ((MCF_BUSCLK / mcfrs_baud_table[i]) + 16) / 32;
654 info->baud = mcfrs_baud_table[i];
656 mr1 = MCFUART_MR1_RXIRQRDY | MCFUART_MR1_RXERRCHAR;
659 switch (cflag & CSIZE) {
660 case CS5: mr1 |= MCFUART_MR1_CS5; break;
661 case CS6: mr1 |= MCFUART_MR1_CS6; break;
662 case CS7: mr1 |= MCFUART_MR1_CS7; break;
664 default: mr1 |= MCFUART_MR1_CS8; break;
667 if (cflag & PARENB) {
668 if (cflag & CMSPAR) {
670 mr1 |= MCFUART_MR1_PARITYMARK;
672 mr1 |= MCFUART_MR1_PARITYSPACE;
675 mr1 |= MCFUART_MR1_PARITYODD;
677 mr1 |= MCFUART_MR1_PARITYEVEN;
680 mr1 |= MCFUART_MR1_PARITYNONE;
684 mr2 |= MCFUART_MR2_STOP2;
686 mr2 |= MCFUART_MR2_STOP1;
688 if (cflag & CRTSCTS) {
689 mr1 |= MCFUART_MR1_RXRTS;
690 mr2 |= MCFUART_MR2_TXCTS;
694 info->flags &= ~ASYNC_CHECK_CD;
696 info->flags |= ASYNC_CHECK_CD;
700 local_irq_save(flags);
702 printk("%s(%d): mr1=%x mr2=%x baudclk=%x\n", __FILE__, __LINE__,
706 Note: pg 12-16 of MCF5206e User's Manual states that a
707 software reset should be performed prior to changing
708 UMR1,2, UCSR, UACR, bit 7
710 uartp[MCFUART_UCR] = MCFUART_UCR_CMDRESETRX; /* reset RX */
711 uartp[MCFUART_UCR] = MCFUART_UCR_CMDRESETTX; /* reset TX */
712 uartp[MCFUART_UCR] = MCFUART_UCR_CMDRESETMRPTR; /* reset MR pointer */
713 uartp[MCFUART_UMR] = mr1;
714 uartp[MCFUART_UMR] = mr2;
715 uartp[MCFUART_UBG1] = (baudclk & 0xff00) >> 8; /* set msb byte */
716 uartp[MCFUART_UBG2] = (baudclk & 0xff); /* set lsb byte */
718 uartp[MCFUART_UFPD] = (fraction & 0xf); /* set fraction */
720 uartp[MCFUART_UCSR] = MCFUART_UCSR_RXCLKTIMER | MCFUART_UCSR_TXCLKTIMER;
721 uartp[MCFUART_UCR] = MCFUART_UCR_RXENABLE | MCFUART_UCR_TXENABLE;
722 mcfrs_setsignals(info, 1, -1);
723 local_irq_restore(flags);
727 static void mcfrs_flush_chars(struct tty_struct *tty)
729 volatile unsigned char *uartp;
730 struct mcf_serial *info = (struct mcf_serial *)tty->driver_data;
733 if (serial_paranoia_check(info, tty->name, "mcfrs_flush_chars"))
736 uartp = (volatile unsigned char *) info->addr;
739 * re-enable receiver interrupt
741 local_irq_save(flags);
742 if ((!(info->imr & MCFUART_UIR_RXREADY)) &&
743 (info->flags & ASYNC_INITIALIZED) ) {
744 info->imr |= MCFUART_UIR_RXREADY;
745 uartp[MCFUART_UIMR] = info->imr;
747 local_irq_restore(flags);
749 if (info->xmit_cnt <= 0 || tty->stopped || tty->hw_stopped ||
753 /* Enable transmitter */
754 local_irq_save(flags);
755 info->imr |= MCFUART_UIR_TXREADY;
756 uartp[MCFUART_UIMR] = info->imr;
757 local_irq_restore(flags);
760 static int mcfrs_write(struct tty_struct * tty,
761 const unsigned char *buf, int count)
763 volatile unsigned char *uartp;
764 struct mcf_serial *info = (struct mcf_serial *)tty->driver_data;
769 printk("%s(%d): mcfrs_write(tty=%x,buf=%x,count=%d)\n",
770 __FILE__, __LINE__, (int)tty, (int)buf, count);
773 if (serial_paranoia_check(info, tty->name, "mcfrs_write"))
776 if (!tty || !info->xmit_buf)
779 local_save_flags(flags);
782 c = min(count, (int) min(((int)SERIAL_XMIT_SIZE) - info->xmit_cnt - 1,
783 ((int)SERIAL_XMIT_SIZE) - info->xmit_head));
784 local_irq_restore(flags);
789 memcpy(info->xmit_buf + info->xmit_head, buf, c);
792 info->xmit_head = (info->xmit_head + c) & (SERIAL_XMIT_SIZE-1);
794 local_irq_restore(flags);
803 info->imr |= MCFUART_UIR_TXREADY;
804 uartp[MCFUART_UIMR] = info->imr;
805 local_irq_restore(flags);
810 static int mcfrs_write_room(struct tty_struct *tty)
812 struct mcf_serial *info = (struct mcf_serial *)tty->driver_data;
815 if (serial_paranoia_check(info, tty->name, "mcfrs_write_room"))
817 ret = SERIAL_XMIT_SIZE - info->xmit_cnt - 1;
823 static int mcfrs_chars_in_buffer(struct tty_struct *tty)
825 struct mcf_serial *info = (struct mcf_serial *)tty->driver_data;
827 if (serial_paranoia_check(info, tty->name, "mcfrs_chars_in_buffer"))
829 return info->xmit_cnt;
832 static void mcfrs_flush_buffer(struct tty_struct *tty)
834 struct mcf_serial *info = (struct mcf_serial *)tty->driver_data;
837 if (serial_paranoia_check(info, tty->name, "mcfrs_flush_buffer"))
840 local_irq_save(flags);
841 info->xmit_cnt = info->xmit_head = info->xmit_tail = 0;
842 local_irq_restore(flags);
848 * ------------------------------------------------------------
851 * This routine is called by the upper-layer tty layer to signal that
852 * incoming characters should be throttled.
853 * ------------------------------------------------------------
855 static void mcfrs_throttle(struct tty_struct * tty)
857 struct mcf_serial *info = (struct mcf_serial *)tty->driver_data;
858 #ifdef SERIAL_DEBUG_THROTTLE
861 printk("throttle %s: %d....\n", _tty_name(tty, buf),
862 tty->ldisc.chars_in_buffer(tty));
865 if (serial_paranoia_check(info, tty->name, "mcfrs_throttle"))
869 info->x_char = STOP_CHAR(tty);
871 /* Turn off RTS line (do this atomic) */
874 static void mcfrs_unthrottle(struct tty_struct * tty)
876 struct mcf_serial *info = (struct mcf_serial *)tty->driver_data;
877 #ifdef SERIAL_DEBUG_THROTTLE
880 printk("unthrottle %s: %d....\n", _tty_name(tty, buf),
881 tty->ldisc.chars_in_buffer(tty));
884 if (serial_paranoia_check(info, tty->name, "mcfrs_unthrottle"))
891 info->x_char = START_CHAR(tty);
894 /* Assert RTS line (do this atomic) */
898 * ------------------------------------------------------------
899 * mcfrs_ioctl() and friends
900 * ------------------------------------------------------------
903 static int get_serial_info(struct mcf_serial * info,
904 struct serial_struct * retinfo)
906 struct serial_struct tmp;
910 memset(&tmp, 0, sizeof(tmp));
911 tmp.type = info->type;
912 tmp.line = info->line;
913 tmp.port = (unsigned int) info->addr;
915 tmp.flags = info->flags;
916 tmp.baud_base = info->baud_base;
917 tmp.close_delay = info->close_delay;
918 tmp.closing_wait = info->closing_wait;
919 tmp.custom_divisor = info->custom_divisor;
920 return copy_to_user(retinfo,&tmp,sizeof(*retinfo)) ? -EFAULT : 0;
923 static int set_serial_info(struct mcf_serial * info,
924 struct serial_struct * new_info)
926 struct serial_struct new_serial;
927 struct mcf_serial old_info;
932 if (copy_from_user(&new_serial,new_info,sizeof(new_serial)))
936 if (!capable(CAP_SYS_ADMIN)) {
937 if ((new_serial.baud_base != info->baud_base) ||
938 (new_serial.type != info->type) ||
939 (new_serial.close_delay != info->close_delay) ||
940 ((new_serial.flags & ~ASYNC_USR_MASK) !=
941 (info->flags & ~ASYNC_USR_MASK)))
943 info->flags = ((info->flags & ~ASYNC_USR_MASK) |
944 (new_serial.flags & ASYNC_USR_MASK));
945 info->custom_divisor = new_serial.custom_divisor;
953 * OK, past this point, all the error checking has been done.
954 * At this point, we start making changes.....
957 info->baud_base = new_serial.baud_base;
958 info->flags = ((info->flags & ~ASYNC_FLAGS) |
959 (new_serial.flags & ASYNC_FLAGS));
960 info->type = new_serial.type;
961 info->close_delay = new_serial.close_delay;
962 info->closing_wait = new_serial.closing_wait;
965 retval = startup(info);
970 * get_lsr_info - get line status register info
972 * Purpose: Let user call ioctl() to get info when the UART physically
973 * is emptied. On bus types like RS485, the transmitter must
974 * release the bus after transmitting. This must be done when
975 * the transmit shift register is empty, not be done when the
976 * transmit holding register is empty. This functionality
977 * allows an RS485 driver to be written in user space.
979 static int get_lsr_info(struct mcf_serial * info, unsigned int *value)
981 volatile unsigned char *uartp;
983 unsigned char status;
985 local_irq_save(flags);
987 status = (uartp[MCFUART_USR] & MCFUART_USR_TXEMPTY) ? TIOCSER_TEMT : 0;
988 local_irq_restore(flags);
990 return put_user(status,value);
994 * This routine sends a break character out the serial port.
996 static void send_break( struct mcf_serial * info, int duration)
998 volatile unsigned char *uartp;
1003 set_current_state(TASK_INTERRUPTIBLE);
1006 local_irq_save(flags);
1007 uartp[MCFUART_UCR] = MCFUART_UCR_CMDBREAKSTART;
1008 schedule_timeout(duration);
1009 uartp[MCFUART_UCR] = MCFUART_UCR_CMDBREAKSTOP;
1010 local_irq_restore(flags);
1013 static int mcfrs_tiocmget(struct tty_struct *tty, struct file *file)
1015 struct mcf_serial * info = (struct mcf_serial *)tty->driver_data;
1017 if (serial_paranoia_check(info, tty->name, "mcfrs_ioctl"))
1019 if (tty->flags & (1 << TTY_IO_ERROR))
1022 return mcfrs_getsignals(info);
1025 static int mcfrs_tiocmset(struct tty_struct *tty, struct file *file,
1026 unsigned int set, unsigned int clear)
1028 struct mcf_serial * info = (struct mcf_serial *)tty->driver_data;
1029 int rts = -1, dtr = -1;
1031 if (serial_paranoia_check(info, tty->name, "mcfrs_ioctl"))
1033 if (tty->flags & (1 << TTY_IO_ERROR))
1036 if (set & TIOCM_RTS)
1038 if (set & TIOCM_DTR)
1040 if (clear & TIOCM_RTS)
1042 if (clear & TIOCM_DTR)
1045 mcfrs_setsignals(info, dtr, rts);
1050 static int mcfrs_ioctl(struct tty_struct *tty, struct file * file,
1051 unsigned int cmd, unsigned long arg)
1053 struct mcf_serial * info = (struct mcf_serial *)tty->driver_data;
1056 if (serial_paranoia_check(info, tty->name, "mcfrs_ioctl"))
1059 if ((cmd != TIOCGSERIAL) && (cmd != TIOCSSERIAL) &&
1060 (cmd != TIOCSERCONFIG) && (cmd != TIOCSERGWILD) &&
1061 (cmd != TIOCSERSWILD) && (cmd != TIOCSERGSTRUCT)) {
1062 if (tty->flags & (1 << TTY_IO_ERROR))
1067 case TCSBRK: /* SVID version: non-zero arg --> no break */
1068 retval = tty_check_change(tty);
1071 tty_wait_until_sent(tty, 0);
1073 send_break(info, HZ/4); /* 1/4 second */
1075 case TCSBRKP: /* support for POSIX tcsendbreak() */
1076 retval = tty_check_change(tty);
1079 tty_wait_until_sent(tty, 0);
1080 send_break(info, arg ? arg*(HZ/10) : HZ/4);
1083 error = put_user(C_CLOCAL(tty) ? 1 : 0,
1084 (unsigned long *) arg);
1089 get_user(arg, (unsigned long *) arg);
1090 tty->termios->c_cflag =
1091 ((tty->termios->c_cflag & ~CLOCAL) |
1092 (arg ? CLOCAL : 0));
1095 error = verify_area(VERIFY_WRITE, (void *) arg,
1096 sizeof(struct serial_struct));
1099 return get_serial_info(info,
1100 (struct serial_struct *) arg);
1102 return set_serial_info(info,
1103 (struct serial_struct *) arg);
1104 case TIOCSERGETLSR: /* Get line status register */
1105 error = verify_area(VERIFY_WRITE, (void *) arg,
1106 sizeof(unsigned int));
1110 return get_lsr_info(info, (unsigned int *) arg);
1112 case TIOCSERGSTRUCT:
1113 error = copy_to_user((struct mcf_serial *) arg,
1114 info, sizeof(struct mcf_serial));
1122 get_user(val, (unsigned int *) arg);
1123 mcf_setpa(MCFPP_PA11, (val ? 0 : MCFPP_PA11));
1128 val = (mcf_getpa() & MCFPP_PA11) ? 0 : 1;
1129 put_user(val, (unsigned int *) arg);
1135 return -ENOIOCTLCMD;
1140 static void mcfrs_set_termios(struct tty_struct *tty, struct termios *old_termios)
1142 struct mcf_serial *info = (struct mcf_serial *)tty->driver_data;
1144 if (tty->termios->c_cflag == old_termios->c_cflag)
1147 mcfrs_change_speed(info);
1149 if ((old_termios->c_cflag & CRTSCTS) &&
1150 !(tty->termios->c_cflag & CRTSCTS)) {
1151 tty->hw_stopped = 0;
1152 mcfrs_setsignals(info, -1, 1);
1160 * ------------------------------------------------------------
1163 * This routine is called when the serial port gets closed. First, we
1164 * wait for the last remaining data to be sent. Then, we unlink its
1165 * S structure from the interrupt chain if necessary, and we free
1166 * that IRQ if nothing is left in the chain.
1167 * ------------------------------------------------------------
1169 static void mcfrs_close(struct tty_struct *tty, struct file * filp)
1171 volatile unsigned char *uartp;
1172 struct mcf_serial *info = (struct mcf_serial *)tty->driver_data;
1173 unsigned long flags;
1175 if (!info || serial_paranoia_check(info, tty->name, "mcfrs_close"))
1178 local_irq_save(flags);
1180 if (tty_hung_up_p(filp)) {
1181 local_irq_restore(flags);
1185 #ifdef SERIAL_DEBUG_OPEN
1186 printk("mcfrs_close ttyS%d, count = %d\n", info->line, info->count);
1188 if ((tty->count == 1) && (info->count != 1)) {
1190 * Uh, oh. tty->count is 1, which means that the tty
1191 * structure will be freed. Info->count should always
1192 * be one in these conditions. If it's greater than
1193 * one, we've got real problems, since it means the
1194 * serial port won't be shutdown.
1196 printk("MCFRS: bad serial port count; tty->count is 1, "
1197 "info->count is %d\n", info->count);
1200 if (--info->count < 0) {
1201 printk("MCFRS: bad serial port count for ttyS%d: %d\n",
1202 info->line, info->count);
1206 local_irq_restore(flags);
1209 info->flags |= ASYNC_CLOSING;
1212 * Now we wait for the transmit buffer to clear; and we notify
1213 * the line discipline to only process XON/XOFF characters.
1216 if (info->closing_wait != ASYNC_CLOSING_WAIT_NONE)
1217 tty_wait_until_sent(tty, info->closing_wait);
1220 * At this point we stop accepting input. To do this, we
1221 * disable the receive line status interrupts, and tell the
1222 * interrupt driver to stop checking the data ready bit in the
1223 * line status register.
1225 info->imr &= ~MCFUART_UIR_RXREADY;
1227 uartp[MCFUART_UIMR] = info->imr;
1230 /* FIXME: do we need to keep this enabled for console?? */
1231 if (mcfrs_console_inited && (mcfrs_console_port == info->line)) {
1232 /* Do not disable the UART */ ;
1236 if (tty->driver->flush_buffer)
1237 tty->driver->flush_buffer(tty);
1238 tty_ldisc_flush(tty);
1244 if (tty->ldisc.num != ldiscs[N_TTY].num) {
1245 if (tty->ldisc.close)
1246 (tty->ldisc.close)(tty);
1247 tty->ldisc = ldiscs[N_TTY];
1248 tty->termios->c_line = N_TTY;
1249 if (tty->ldisc.open)
1250 (tty->ldisc.open)(tty);
1253 if (info->blocked_open) {
1254 if (info->close_delay) {
1255 msleep_interruptible(jiffies_to_msecs(info->close_delay));
1257 wake_up_interruptible(&info->open_wait);
1259 info->flags &= ~(ASYNC_NORMAL_ACTIVE|ASYNC_CLOSING);
1260 wake_up_interruptible(&info->close_wait);
1261 local_irq_restore(flags);
1265 * mcfrs_wait_until_sent() --- wait until the transmitter is empty
1268 mcfrs_wait_until_sent(struct tty_struct *tty, int timeout)
1271 #define MCF5272_FIFO_SIZE 25 /* fifo size + shift reg */
1273 struct mcf_serial * info = (struct mcf_serial *)tty->driver_data;
1274 volatile unsigned char *uartp;
1275 unsigned long orig_jiffies, fifo_time, char_time, fifo_cnt;
1277 if (serial_paranoia_check(info, tty->name, "mcfrs_wait_until_sent"))
1280 orig_jiffies = jiffies;
1283 * Set the check interval to be 1/5 of the approximate time
1284 * to send the entire fifo, and make it at least 1. The check
1285 * interval should also be less than the timeout.
1287 * Note: we have to use pretty tight timings here to satisfy
1290 fifo_time = (MCF5272_FIFO_SIZE * HZ * 10) / info->baud;
1291 char_time = fifo_time / 5;
1294 if (timeout && timeout < char_time)
1295 char_time = timeout;
1298 * Clamp the timeout period at 2 * the time to empty the
1299 * fifo. Just to be safe, set the minimum at .5 seconds.
1302 if (fifo_time < (HZ/2))
1304 if (!timeout || timeout > fifo_time)
1305 timeout = fifo_time;
1308 * Account for the number of bytes in the UART
1309 * transmitter FIFO plus any byte being shifted out.
1311 uartp = (volatile unsigned char *) info->addr;
1313 fifo_cnt = (uartp[MCFUART_UTF] & MCFUART_UTF_TXB);
1314 if ((uartp[MCFUART_USR] & (MCFUART_USR_TXREADY|
1315 MCFUART_USR_TXEMPTY)) ==
1316 MCFUART_USR_TXREADY)
1320 msleep_interruptible(jiffies_to_msecs(char_time));
1321 if (signal_pending(current))
1323 if (timeout && time_after(jiffies, orig_jiffies + timeout))
1328 * For the other coldfire models, assume all data has been sent
1334 * mcfrs_hangup() --- called by tty_hangup() when a hangup is signaled.
1336 void mcfrs_hangup(struct tty_struct *tty)
1338 struct mcf_serial * info = (struct mcf_serial *)tty->driver_data;
1340 if (serial_paranoia_check(info, tty->name, "mcfrs_hangup"))
1343 mcfrs_flush_buffer(tty);
1347 info->flags &= ~ASYNC_NORMAL_ACTIVE;
1349 wake_up_interruptible(&info->open_wait);
1353 * ------------------------------------------------------------
1354 * mcfrs_open() and friends
1355 * ------------------------------------------------------------
1357 static int block_til_ready(struct tty_struct *tty, struct file * filp,
1358 struct mcf_serial *info)
1360 DECLARE_WAITQUEUE(wait, current);
1365 * If the device is in the middle of being closed, then block
1366 * until it's done, and then try again.
1368 if (info->flags & ASYNC_CLOSING) {
1369 interruptible_sleep_on(&info->close_wait);
1370 #ifdef SERIAL_DO_RESTART
1371 if (info->flags & ASYNC_HUP_NOTIFY)
1374 return -ERESTARTSYS;
1381 * If non-blocking mode is set, or the port is not enabled,
1382 * then make the check up front and then exit.
1384 if ((filp->f_flags & O_NONBLOCK) ||
1385 (tty->flags & (1 << TTY_IO_ERROR))) {
1386 info->flags |= ASYNC_NORMAL_ACTIVE;
1390 if (tty->termios->c_cflag & CLOCAL)
1394 * Block waiting for the carrier detect and the line to become
1395 * free (i.e., not in use by the callout). While we are in
1396 * this loop, info->count is dropped by one, so that
1397 * mcfrs_close() knows when to free things. We restore it upon
1398 * exit, either normal or abnormal.
1401 add_wait_queue(&info->open_wait, &wait);
1402 #ifdef SERIAL_DEBUG_OPEN
1403 printk("block_til_ready before block: ttyS%d, count = %d\n",
1404 info->line, info->count);
1407 info->blocked_open++;
1409 local_irq_disable();
1410 mcfrs_setsignals(info, 1, 1);
1412 current->state = TASK_INTERRUPTIBLE;
1413 if (tty_hung_up_p(filp) ||
1414 !(info->flags & ASYNC_INITIALIZED)) {
1415 #ifdef SERIAL_DO_RESTART
1416 if (info->flags & ASYNC_HUP_NOTIFY)
1419 retval = -ERESTARTSYS;
1425 if (!(info->flags & ASYNC_CLOSING) &&
1426 (do_clocal || (mcfrs_getsignals(info) & TIOCM_CD)))
1428 if (signal_pending(current)) {
1429 retval = -ERESTARTSYS;
1432 #ifdef SERIAL_DEBUG_OPEN
1433 printk("block_til_ready blocking: ttyS%d, count = %d\n",
1434 info->line, info->count);
1438 current->state = TASK_RUNNING;
1439 remove_wait_queue(&info->open_wait, &wait);
1440 if (!tty_hung_up_p(filp))
1442 info->blocked_open--;
1443 #ifdef SERIAL_DEBUG_OPEN
1444 printk("block_til_ready after blocking: ttyS%d, count = %d\n",
1445 info->line, info->count);
1449 info->flags |= ASYNC_NORMAL_ACTIVE;
1454 * This routine is called whenever a serial port is opened. It
1455 * enables interrupts for a serial port, linking in its structure into
1456 * the IRQ chain. It also performs the serial-specific
1457 * initialization for the tty structure.
1459 int mcfrs_open(struct tty_struct *tty, struct file * filp)
1461 struct mcf_serial *info;
1465 if ((line < 0) || (line >= NR_PORTS))
1467 info = mcfrs_table + line;
1468 if (serial_paranoia_check(info, tty->name, "mcfrs_open"))
1470 #ifdef SERIAL_DEBUG_OPEN
1471 printk("mcfrs_open %s, count = %d\n", tty->name, info->count);
1474 tty->driver_data = info;
1478 * Start up serial port
1480 retval = startup(info);
1484 retval = block_til_ready(tty, filp, info);
1486 #ifdef SERIAL_DEBUG_OPEN
1487 printk("mcfrs_open returning after block_til_ready with %d\n",
1493 #ifdef SERIAL_DEBUG_OPEN
1494 printk("mcfrs_open %s successful...\n", tty->name);
1500 * Based on the line number set up the internal interrupt stuff.
1502 static void mcfrs_irqinit(struct mcf_serial *info)
1504 #if defined(CONFIG_M5272)
1505 volatile unsigned long *icrp;
1506 volatile unsigned long *portp;
1507 volatile unsigned char *uartp;
1510 icrp = (volatile unsigned long *) (MCF_MBAR + MCFSIM_ICR2);
1512 switch (info->line) {
1520 printk("MCFRS: don't know how to handle UART %d interrupt?\n",
1525 /* Enable the output lines for the serial ports */
1526 portp = (volatile unsigned long *) (MCF_MBAR + MCFSIM_PBCNT);
1527 *portp = (*portp & ~0x000000ff) | 0x00000055;
1528 portp = (volatile unsigned long *) (MCF_MBAR + MCFSIM_PDCNT);
1529 *portp = (*portp & ~0x000003fc) | 0x000002a8;
1530 #elif defined(CONFIG_M527x) || defined(CONFIG_M528x)
1531 volatile unsigned char *icrp, *uartp;
1532 volatile unsigned long *imrp;
1536 icrp = (volatile unsigned char *) (MCF_MBAR + MCFICM_INTC0 +
1537 MCFINTC_ICR0 + MCFINT_UART0 + info->line);
1538 *icrp = 0x33; /* UART0 with level 6, priority 3 */
1540 imrp = (volatile unsigned long *) (MCF_MBAR + MCFICM_INTC0 +
1542 *imrp &= ~((1 << (info->irq - MCFINT_VECBASE)) | 1);
1544 volatile unsigned char *icrp, *uartp;
1546 switch (info->line) {
1548 icrp = (volatile unsigned char *) (MCF_MBAR + MCFSIM_UART1ICR);
1549 *icrp = /*MCFSIM_ICR_AUTOVEC |*/ MCFSIM_ICR_LEVEL6 |
1551 mcf_setimr(mcf_getimr() & ~MCFSIM_IMR_UART1);
1554 icrp = (volatile unsigned char *) (MCF_MBAR + MCFSIM_UART2ICR);
1555 *icrp = /*MCFSIM_ICR_AUTOVEC |*/ MCFSIM_ICR_LEVEL6 |
1557 mcf_setimr(mcf_getimr() & ~MCFSIM_IMR_UART2);
1560 printk("MCFRS: don't know how to handle UART %d interrupt?\n",
1566 uartp[MCFUART_UIVR] = info->irq;
1569 /* Clear mask, so no surprise interrupts. */
1570 uartp[MCFUART_UIMR] = 0;
1572 if (request_irq(info->irq, mcfrs_interrupt, SA_INTERRUPT,
1573 "ColdFire UART", NULL)) {
1574 printk("MCFRS: Unable to attach ColdFire UART %d interrupt "
1575 "vector=%d\n", info->line, info->irq);
1582 char *mcfrs_drivername = "ColdFire internal UART serial driver version 1.00\n";
1586 * Serial stats reporting...
1588 int mcfrs_readproc(char *page, char **start, off_t off, int count,
1589 int *eof, void *data)
1591 struct mcf_serial *info;
1595 len = sprintf(page, mcfrs_drivername);
1596 for (i = 0; (i < NR_PORTS); i++) {
1597 info = &mcfrs_table[i];
1598 len += sprintf((page + len), "%d: port:%x irq=%d baud:%d ",
1599 i, (unsigned int) info->addr, info->irq, info->baud);
1600 if (info->stats.rx || info->stats.tx)
1601 len += sprintf((page + len), "tx:%d rx:%d ",
1602 info->stats.tx, info->stats.rx);
1603 if (info->stats.rxframing)
1604 len += sprintf((page + len), "fe:%d ",
1605 info->stats.rxframing);
1606 if (info->stats.rxparity)
1607 len += sprintf((page + len), "pe:%d ",
1608 info->stats.rxparity);
1609 if (info->stats.rxbreak)
1610 len += sprintf((page + len), "brk:%d ",
1611 info->stats.rxbreak);
1612 if (info->stats.rxoverrun)
1613 len += sprintf((page + len), "oe:%d ",
1614 info->stats.rxoverrun);
1616 str[0] = str[1] = 0;
1617 if ((sigs = mcfrs_getsignals(info))) {
1618 if (sigs & TIOCM_RTS)
1619 strcat(str, "|RTS");
1620 if (sigs & TIOCM_CTS)
1621 strcat(str, "|CTS");
1622 if (sigs & TIOCM_DTR)
1623 strcat(str, "|DTR");
1624 if (sigs & TIOCM_CD)
1628 len += sprintf((page + len), "%s\n", &str[1]);
1635 /* Finally, routines used to initialize the serial driver. */
1637 static void show_serial_version(void)
1639 printk(mcfrs_drivername);
1642 static struct tty_operations mcfrs_ops = {
1644 .close = mcfrs_close,
1645 .write = mcfrs_write,
1646 .flush_chars = mcfrs_flush_chars,
1647 .write_room = mcfrs_write_room,
1648 .chars_in_buffer = mcfrs_chars_in_buffer,
1649 .flush_buffer = mcfrs_flush_buffer,
1650 .ioctl = mcfrs_ioctl,
1651 .throttle = mcfrs_throttle,
1652 .unthrottle = mcfrs_unthrottle,
1653 .set_termios = mcfrs_set_termios,
1655 .start = mcfrs_start,
1656 .hangup = mcfrs_hangup,
1657 .read_proc = mcfrs_readproc,
1658 .wait_until_sent = mcfrs_wait_until_sent,
1659 .tiocmget = mcfrs_tiocmget,
1660 .tiocmset = mcfrs_tiocmset,
1663 /* mcfrs_init inits the driver */
1667 struct mcf_serial *info;
1668 unsigned long flags;
1671 /* Setup base handler, and timer table. */
1673 init_timer(&mcfrs_timer_struct);
1674 mcfrs_timer_struct.function = mcfrs_timer;
1675 mcfrs_timer_struct.data = 0;
1676 mcfrs_timer_struct.expires = jiffies + HZ/25;
1677 add_timer(&mcfrs_timer_struct);
1678 mcfrs_ppstatus = mcf_getppdata() & (MCFPP_DCD0 | MCFPP_DCD1);
1680 mcfrs_serial_driver = alloc_tty_driver(NR_PORTS);
1681 if (!mcfrs_serial_driver)
1684 show_serial_version();
1686 /* Initialize the tty_driver structure */
1687 mcfrs_serial_driver->owner = THIS_MODULE;
1688 mcfrs_serial_driver->name = "ttyS";
1689 mcfrs_serial_driver->devfs_name = "ttys/";
1690 mcfrs_serial_driver->driver_name = "serial";
1691 mcfrs_serial_driver->major = TTY_MAJOR;
1692 mcfrs_serial_driver->minor_start = 64;
1693 mcfrs_serial_driver->type = TTY_DRIVER_TYPE_SERIAL;
1694 mcfrs_serial_driver->subtype = SERIAL_TYPE_NORMAL;
1695 mcfrs_serial_driver->init_termios = tty_std_termios;
1697 mcfrs_serial_driver->init_termios.c_cflag =
1698 mcfrs_console_cbaud | CS8 | CREAD | HUPCL | CLOCAL;
1699 mcfrs_serial_driver->flags = TTY_DRIVER_REAL_RAW;
1701 tty_set_operations(mcfrs_serial_driver, &mcfrs_ops);
1703 if (tty_register_driver(mcfrs_serial_driver)) {
1704 printk("MCFRS: Couldn't register serial driver\n");
1705 put_tty_driver(mcfrs_serial_driver);
1709 local_irq_save(flags);
1712 * Configure all the attached serial ports.
1714 for (i = 0, info = mcfrs_table; (i < NR_PORTS); i++, info++) {
1715 info->magic = SERIAL_MAGIC;
1718 info->custom_divisor = 16;
1719 info->close_delay = 50;
1720 info->closing_wait = 3000;
1724 info->blocked_open = 0;
1725 INIT_WORK(&info->tqueue, mcfrs_offintr, info);
1726 INIT_WORK(&info->tqueue_hangup, do_serial_hangup, info);
1727 init_waitqueue_head(&info->open_wait);
1728 init_waitqueue_head(&info->close_wait);
1731 mcfrs_setsignals(info, 0, 0);
1732 mcfrs_irqinit(info);
1734 printk("ttyS%d at 0x%04x (irq = %d)", info->line,
1735 (unsigned int) info->addr, info->irq);
1736 printk(" is a builtin ColdFire UART\n");
1739 local_irq_restore(flags);
1743 module_init(mcfrs_init);
1745 /****************************************************************************/
1746 /* Serial Console */
1747 /****************************************************************************/
1750 * Quick and dirty UART initialization, for console output.
1753 void mcfrs_init_console(void)
1755 volatile unsigned char *uartp;
1759 * Reset UART, get it into known state...
1761 uartp = (volatile unsigned char *) (MCF_MBAR +
1762 (mcfrs_console_port ? MCFUART_BASE2 : MCFUART_BASE1));
1764 uartp[MCFUART_UCR] = MCFUART_UCR_CMDRESETRX; /* reset RX */
1765 uartp[MCFUART_UCR] = MCFUART_UCR_CMDRESETTX; /* reset TX */
1766 uartp[MCFUART_UCR] = MCFUART_UCR_CMDRESETMRPTR; /* reset MR pointer */
1769 * Set port for defined baud , 8 data bits, 1 stop bit, no parity.
1771 uartp[MCFUART_UMR] = MCFUART_MR1_PARITYNONE | MCFUART_MR1_CS8;
1772 uartp[MCFUART_UMR] = MCFUART_MR2_STOP1;
1774 clk = ((MCF_BUSCLK / mcfrs_console_baud) + 16) / 32; /* set baud */
1775 uartp[MCFUART_UBG1] = (clk & 0xff00) >> 8; /* set msb baud */
1776 uartp[MCFUART_UBG2] = (clk & 0xff); /* set lsb baud */
1778 uartp[MCFUART_UCSR] = MCFUART_UCSR_RXCLKTIMER | MCFUART_UCSR_TXCLKTIMER;
1779 uartp[MCFUART_UCR] = MCFUART_UCR_RXENABLE | MCFUART_UCR_TXENABLE;
1781 mcfrs_console_inited++;
1787 * Setup for console. Argument comes from the boot command line.
1790 int mcfrs_console_setup(struct console *cp, char *arg)
1792 int i, n = CONSOLE_BAUD_RATE;
1797 if (!strncmp(cp->name, "ttyS", 4))
1798 mcfrs_console_port = cp->index;
1799 else if (!strncmp(cp->name, "cua", 3))
1800 mcfrs_console_port = cp->index;
1805 n = simple_strtoul(arg,NULL,0);
1806 for (i = 0; i < MCFRS_BAUD_TABLE_SIZE; i++)
1807 if (mcfrs_baud_table[i] == n)
1809 if (i < MCFRS_BAUD_TABLE_SIZE) {
1810 mcfrs_console_baud = n;
1811 mcfrs_console_cbaud = 0;
1813 mcfrs_console_cbaud |= CBAUDEX;
1816 mcfrs_console_cbaud |= i;
1818 mcfrs_init_console(); /* make sure baud rate changes */
1823 static struct tty_driver *mcfrs_console_device(struct console *c, int *index)
1826 return mcfrs_serial_driver;
1831 * Output a single character, using UART polled mode.
1832 * This is used for console output.
1835 void mcfrs_put_char(char ch)
1837 volatile unsigned char *uartp;
1838 unsigned long flags;
1841 uartp = (volatile unsigned char *) (MCF_MBAR +
1842 (mcfrs_console_port ? MCFUART_BASE2 : MCFUART_BASE1));
1844 local_irq_save(flags);
1845 for (i = 0; (i < 0x10000); i++) {
1846 if (uartp[MCFUART_USR] & MCFUART_USR_TXREADY)
1850 uartp[MCFUART_UTB] = ch;
1851 for (i = 0; (i < 0x10000); i++)
1852 if (uartp[MCFUART_USR] & MCFUART_USR_TXEMPTY)
1856 mcfrs_init_console(); /* try and get it back */
1857 local_irq_restore(flags);
1864 * rs_console_write is registered for printk output.
1867 void mcfrs_console_write(struct console *cp, const char *p, unsigned len)
1869 if (!mcfrs_console_inited)
1870 mcfrs_init_console();
1873 mcfrs_put_char('\r');
1874 mcfrs_put_char(*p++);
1879 * declare our consoles
1882 struct console mcfrs_console = {
1884 .write = mcfrs_console_write,
1885 .device = mcfrs_console_device,
1886 .setup = mcfrs_console_setup,
1887 .flags = CON_PRINTBUFFER,
1891 static int __init mcfrs_console_init(void)
1893 register_console(&mcfrs_console);
1897 console_initcall(mcfrs_console_init);
1899 /****************************************************************************/