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;
428 if ((tty->flags & (1 << TTY_DO_WRITE_WAKEUP)) &&
429 tty->ldisc.write_wakeup)
430 (tty->ldisc.write_wakeup)(tty);
431 wake_up_interruptible(&tty->write_wait);
436 * Change of state on a DCD line.
438 void mcfrs_modem_change(struct mcf_serial *info, int dcd)
440 if (info->count == 0)
443 if (info->flags & ASYNC_CHECK_CD) {
445 wake_up_interruptible(&info->open_wait);
447 schedule_work(&info->tqueue_hangup);
454 unsigned short mcfrs_ppstatus;
457 * This subroutine is called when the RS_TIMER goes off. It is used
458 * to monitor the state of the DCD lines - since they have no edge
459 * sensors and interrupt generators.
461 static void mcfrs_timer(void)
463 unsigned int ppstatus, dcdval, i;
465 ppstatus = mcf_getppdata() & (MCFPP_DCD0 | MCFPP_DCD1);
467 if (ppstatus != mcfrs_ppstatus) {
468 for (i = 0; (i < 2); i++) {
469 dcdval = (i ? MCFPP_DCD1 : MCFPP_DCD0);
470 if ((ppstatus & dcdval) != (mcfrs_ppstatus & dcdval)) {
471 mcfrs_modem_change(&mcfrs_table[i],
472 ((ppstatus & dcdval) ? 0 : 1));
476 mcfrs_ppstatus = ppstatus;
479 mcfrs_timer_struct.expires = jiffies + HZ/25;
480 add_timer(&mcfrs_timer_struct);
483 #endif /* MCFPP_DCD0 */
487 * This routine is called from the scheduler tqueue when the interrupt
488 * routine has signalled that a hangup has occurred. The path of
489 * hangup processing is:
491 * serial interrupt routine -> (scheduler tqueue) ->
492 * do_serial_hangup() -> tty->hangup() -> mcfrs_hangup()
495 static void do_serial_hangup(void *private)
497 struct mcf_serial *info = (struct mcf_serial *) private;
498 struct tty_struct *tty;
507 static int startup(struct mcf_serial * info)
509 volatile unsigned char *uartp;
512 if (info->flags & ASYNC_INITIALIZED)
515 if (!info->xmit_buf) {
516 info->xmit_buf = (unsigned char *) __get_free_page(GFP_KERNEL);
521 local_irq_save(flags);
523 #ifdef SERIAL_DEBUG_OPEN
524 printk("starting up ttyS%d (irq %d)...\n", info->line, info->irq);
528 * Reset UART, get it into known state...
531 uartp[MCFUART_UCR] = MCFUART_UCR_CMDRESETRX; /* reset RX */
532 uartp[MCFUART_UCR] = MCFUART_UCR_CMDRESETTX; /* reset TX */
533 mcfrs_setsignals(info, 1, 1);
536 clear_bit(TTY_IO_ERROR, &info->tty->flags);
537 info->xmit_cnt = info->xmit_head = info->xmit_tail = 0;
540 * and set the speed of the serial port
542 mcfrs_change_speed(info);
545 * Lastly enable the UART transmitter and receiver, and
548 info->imr = MCFUART_UIR_RXREADY;
549 uartp[MCFUART_UCR] = MCFUART_UCR_RXENABLE | MCFUART_UCR_TXENABLE;
550 uartp[MCFUART_UIMR] = info->imr;
552 info->flags |= ASYNC_INITIALIZED;
553 local_irq_restore(flags);
558 * This routine will shutdown a serial port; interrupts are disabled, and
559 * DTR is dropped if the hangup on close termio flag is on.
561 static void shutdown(struct mcf_serial * info)
563 volatile unsigned char *uartp;
566 if (!(info->flags & ASYNC_INITIALIZED))
569 #ifdef SERIAL_DEBUG_OPEN
570 printk("Shutting down serial port %d (irq %d)....\n", info->line,
574 local_irq_save(flags);
577 uartp[MCFUART_UIMR] = 0; /* mask all interrupts */
578 uartp[MCFUART_UCR] = MCFUART_UCR_CMDRESETRX; /* reset RX */
579 uartp[MCFUART_UCR] = MCFUART_UCR_CMDRESETTX; /* reset TX */
581 if (!info->tty || (info->tty->termios->c_cflag & HUPCL))
582 mcfrs_setsignals(info, 0, 0);
584 if (info->xmit_buf) {
585 free_page((unsigned long) info->xmit_buf);
590 set_bit(TTY_IO_ERROR, &info->tty->flags);
592 info->flags &= ~ASYNC_INITIALIZED;
593 local_irq_restore(flags);
598 * This routine is called to set the UART divisor registers to match
599 * the specified baud rate for a serial port.
601 static void mcfrs_change_speed(struct mcf_serial *info)
603 volatile unsigned char *uartp;
604 unsigned int baudclk, cflag;
606 unsigned char mr1, mr2;
609 unsigned int fraction;
612 if (!info->tty || !info->tty->termios)
614 cflag = info->tty->termios->c_cflag;
619 printk("%s(%d): mcfrs_change_speed()\n", __FILE__, __LINE__);
626 info->tty->termios->c_cflag &= ~CBAUDEX;
631 mcfrs_setsignals(info, 0, -1);
635 /* compute the baudrate clock */
638 * For the MCF5272, also compute the baudrate fraction.
640 baudclk = (MCF_BUSCLK / mcfrs_baud_table[i]) / 32;
641 fraction = MCF_BUSCLK - (baudclk * 32 * mcfrs_baud_table[i]);
643 fraction /= (32 * mcfrs_baud_table[i]);
645 baudclk = ((MCF_BUSCLK / mcfrs_baud_table[i]) + 16) / 32;
648 info->baud = mcfrs_baud_table[i];
650 mr1 = MCFUART_MR1_RXIRQRDY | MCFUART_MR1_RXERRCHAR;
653 switch (cflag & CSIZE) {
654 case CS5: mr1 |= MCFUART_MR1_CS5; break;
655 case CS6: mr1 |= MCFUART_MR1_CS6; break;
656 case CS7: mr1 |= MCFUART_MR1_CS7; break;
658 default: mr1 |= MCFUART_MR1_CS8; break;
661 if (cflag & PARENB) {
662 if (cflag & CMSPAR) {
664 mr1 |= MCFUART_MR1_PARITYMARK;
666 mr1 |= MCFUART_MR1_PARITYSPACE;
669 mr1 |= MCFUART_MR1_PARITYODD;
671 mr1 |= MCFUART_MR1_PARITYEVEN;
674 mr1 |= MCFUART_MR1_PARITYNONE;
678 mr2 |= MCFUART_MR2_STOP2;
680 mr2 |= MCFUART_MR2_STOP1;
682 if (cflag & CRTSCTS) {
683 mr1 |= MCFUART_MR1_RXRTS;
684 mr2 |= MCFUART_MR2_TXCTS;
688 info->flags &= ~ASYNC_CHECK_CD;
690 info->flags |= ASYNC_CHECK_CD;
694 local_irq_save(flags);
696 printk("%s(%d): mr1=%x mr2=%x baudclk=%x\n", __FILE__, __LINE__,
700 Note: pg 12-16 of MCF5206e User's Manual states that a
701 software reset should be performed prior to changing
702 UMR1,2, UCSR, UACR, bit 7
704 uartp[MCFUART_UCR] = MCFUART_UCR_CMDRESETRX; /* reset RX */
705 uartp[MCFUART_UCR] = MCFUART_UCR_CMDRESETTX; /* reset TX */
706 uartp[MCFUART_UCR] = MCFUART_UCR_CMDRESETMRPTR; /* reset MR pointer */
707 uartp[MCFUART_UMR] = mr1;
708 uartp[MCFUART_UMR] = mr2;
709 uartp[MCFUART_UBG1] = (baudclk & 0xff00) >> 8; /* set msb byte */
710 uartp[MCFUART_UBG2] = (baudclk & 0xff); /* set lsb byte */
712 uartp[MCFUART_UFPD] = (fraction & 0xf); /* set fraction */
714 uartp[MCFUART_UCSR] = MCFUART_UCSR_RXCLKTIMER | MCFUART_UCSR_TXCLKTIMER;
715 uartp[MCFUART_UCR] = MCFUART_UCR_RXENABLE | MCFUART_UCR_TXENABLE;
716 mcfrs_setsignals(info, 1, -1);
717 local_irq_restore(flags);
721 static void mcfrs_flush_chars(struct tty_struct *tty)
723 volatile unsigned char *uartp;
724 struct mcf_serial *info = (struct mcf_serial *)tty->driver_data;
727 if (serial_paranoia_check(info, tty->name, "mcfrs_flush_chars"))
730 if (info->xmit_cnt <= 0 || tty->stopped || tty->hw_stopped ||
734 /* Enable transmitter */
735 local_irq_save(flags);
737 info->imr |= MCFUART_UIR_TXREADY;
738 uartp[MCFUART_UIMR] = info->imr;
739 local_irq_restore(flags);
742 static int mcfrs_write(struct tty_struct * tty, int from_user,
743 const unsigned char *buf, int count)
745 volatile unsigned char *uartp;
746 struct mcf_serial *info = (struct mcf_serial *)tty->driver_data;
751 printk("%s(%d): mcfrs_write(tty=%x,from_user=%d,buf=%x,count=%d)\n",
752 __FILE__, __LINE__, (int)tty, from_user, (int)buf, count);
755 if (serial_paranoia_check(info, tty->name, "mcfrs_write"))
758 if (!tty || !info->xmit_buf)
761 local_save_flags(flags);
764 c = min(count, (int) min(((int)SERIAL_XMIT_SIZE) - info->xmit_cnt - 1,
765 ((int)SERIAL_XMIT_SIZE) - info->xmit_head));
766 local_irq_restore(flags);
772 down(&mcfrs_tmp_buf_sem);
773 if (copy_from_user(mcfrs_tmp_buf, buf, c))
777 c = min(c, (int) min(((int)SERIAL_XMIT_SIZE) - info->xmit_cnt - 1,
778 ((int)SERIAL_XMIT_SIZE) - info->xmit_head));
779 local_irq_restore(flags);
780 memcpy(info->xmit_buf + info->xmit_head, mcfrs_tmp_buf, c);
781 up(&mcfrs_tmp_buf_sem);
783 memcpy(info->xmit_buf + info->xmit_head, buf, c);
786 info->xmit_head = (info->xmit_head + c) & (SERIAL_XMIT_SIZE-1);
788 local_irq_restore(flags);
797 info->imr |= MCFUART_UIR_TXREADY;
798 uartp[MCFUART_UIMR] = info->imr;
799 local_irq_restore(flags);
804 static int mcfrs_write_room(struct tty_struct *tty)
806 struct mcf_serial *info = (struct mcf_serial *)tty->driver_data;
809 if (serial_paranoia_check(info, tty->name, "mcfrs_write_room"))
811 ret = SERIAL_XMIT_SIZE - info->xmit_cnt - 1;
817 static int mcfrs_chars_in_buffer(struct tty_struct *tty)
819 struct mcf_serial *info = (struct mcf_serial *)tty->driver_data;
821 if (serial_paranoia_check(info, tty->name, "mcfrs_chars_in_buffer"))
823 return info->xmit_cnt;
826 static void mcfrs_flush_buffer(struct tty_struct *tty)
828 struct mcf_serial *info = (struct mcf_serial *)tty->driver_data;
831 if (serial_paranoia_check(info, tty->name, "mcfrs_flush_buffer"))
834 local_irq_save(flags);
835 info->xmit_cnt = info->xmit_head = info->xmit_tail = 0;
836 local_irq_restore(flags);
838 wake_up_interruptible(&tty->write_wait);
839 if ((tty->flags & (1 << TTY_DO_WRITE_WAKEUP)) &&
840 tty->ldisc.write_wakeup)
841 (tty->ldisc.write_wakeup)(tty);
845 * ------------------------------------------------------------
848 * This routine is called by the upper-layer tty layer to signal that
849 * incoming characters should be throttled.
850 * ------------------------------------------------------------
852 static void mcfrs_throttle(struct tty_struct * tty)
854 struct mcf_serial *info = (struct mcf_serial *)tty->driver_data;
855 #ifdef SERIAL_DEBUG_THROTTLE
858 printk("throttle %s: %d....\n", _tty_name(tty, buf),
859 tty->ldisc.chars_in_buffer(tty));
862 if (serial_paranoia_check(info, tty->name, "mcfrs_throttle"))
866 info->x_char = STOP_CHAR(tty);
868 /* Turn off RTS line (do this atomic) */
871 static void mcfrs_unthrottle(struct tty_struct * tty)
873 struct mcf_serial *info = (struct mcf_serial *)tty->driver_data;
874 #ifdef SERIAL_DEBUG_THROTTLE
877 printk("unthrottle %s: %d....\n", _tty_name(tty, buf),
878 tty->ldisc.chars_in_buffer(tty));
881 if (serial_paranoia_check(info, tty->name, "mcfrs_unthrottle"))
888 info->x_char = START_CHAR(tty);
891 /* Assert RTS line (do this atomic) */
895 * ------------------------------------------------------------
896 * mcfrs_ioctl() and friends
897 * ------------------------------------------------------------
900 static int get_serial_info(struct mcf_serial * info,
901 struct serial_struct * retinfo)
903 struct serial_struct tmp;
907 memset(&tmp, 0, sizeof(tmp));
908 tmp.type = info->type;
909 tmp.line = info->line;
910 tmp.port = (unsigned int) info->addr;
912 tmp.flags = info->flags;
913 tmp.baud_base = info->baud_base;
914 tmp.close_delay = info->close_delay;
915 tmp.closing_wait = info->closing_wait;
916 tmp.custom_divisor = info->custom_divisor;
917 return copy_to_user(retinfo,&tmp,sizeof(*retinfo)) ? -EFAULT : 0;
920 static int set_serial_info(struct mcf_serial * info,
921 struct serial_struct * new_info)
923 struct serial_struct new_serial;
924 struct mcf_serial old_info;
929 if (copy_from_user(&new_serial,new_info,sizeof(new_serial)))
933 if (!capable(CAP_SYS_ADMIN)) {
934 if ((new_serial.baud_base != info->baud_base) ||
935 (new_serial.type != info->type) ||
936 (new_serial.close_delay != info->close_delay) ||
937 ((new_serial.flags & ~ASYNC_USR_MASK) !=
938 (info->flags & ~ASYNC_USR_MASK)))
940 info->flags = ((info->flags & ~ASYNC_USR_MASK) |
941 (new_serial.flags & ASYNC_USR_MASK));
942 info->custom_divisor = new_serial.custom_divisor;
950 * OK, past this point, all the error checking has been done.
951 * At this point, we start making changes.....
954 info->baud_base = new_serial.baud_base;
955 info->flags = ((info->flags & ~ASYNC_FLAGS) |
956 (new_serial.flags & ASYNC_FLAGS));
957 info->type = new_serial.type;
958 info->close_delay = new_serial.close_delay;
959 info->closing_wait = new_serial.closing_wait;
962 retval = startup(info);
967 * get_lsr_info - get line status register info
969 * Purpose: Let user call ioctl() to get info when the UART physically
970 * is emptied. On bus types like RS485, the transmitter must
971 * release the bus after transmitting. This must be done when
972 * the transmit shift register is empty, not be done when the
973 * transmit holding register is empty. This functionality
974 * allows an RS485 driver to be written in user space.
976 static int get_lsr_info(struct mcf_serial * info, unsigned int *value)
978 volatile unsigned char *uartp;
980 unsigned char status;
982 local_irq_save(flags);
984 status = (uartp[MCFUART_USR] & MCFUART_USR_TXEMPTY) ? TIOCSER_TEMT : 0;
985 local_irq_restore(flags);
987 return put_user(status,value);
991 * This routine sends a break character out the serial port.
993 static void send_break( struct mcf_serial * info, int duration)
995 volatile unsigned char *uartp;
1000 current->state = TASK_INTERRUPTIBLE;
1003 local_irq_save(flags);
1004 uartp[MCFUART_UCR] = MCFUART_UCR_CMDBREAKSTART;
1005 schedule_timeout(jiffies + duration);
1006 uartp[MCFUART_UCR] = MCFUART_UCR_CMDBREAKSTOP;
1007 local_irq_restore(flags);
1010 static int mcfrs_tiocmget(struct tty_struct *tty, struct file *file)
1012 struct mcf_serial * info = (struct mcf_serial *)tty->driver_data;
1014 if (serial_paranoia_check(info, tty->name, "mcfrs_ioctl"))
1016 if (tty->flags & (1 << TTY_IO_ERROR))
1019 return mcfrs_getsignals(info);
1022 static int mcfrs_tiocmset(struct tty_struct *tty, struct file *file,
1023 unsigned int set, unsigned int clear)
1025 struct mcf_serial * info = (struct mcf_serial *)tty->driver_data;
1026 int rts = -1, dtr = -1;
1028 if (serial_paranoia_check(info, tty->name, "mcfrs_ioctl"))
1030 if (tty->flags & (1 << TTY_IO_ERROR))
1033 if (set & TIOCM_RTS)
1035 if (set & TIOCM_DTR)
1037 if (clear & TIOCM_RTS)
1039 if (clear & TIOCM_DTR)
1042 mcfrs_setsignals(info, dtr, rts);
1047 static int mcfrs_ioctl(struct tty_struct *tty, struct file * file,
1048 unsigned int cmd, unsigned long arg)
1050 struct mcf_serial * info = (struct mcf_serial *)tty->driver_data;
1053 if (serial_paranoia_check(info, tty->name, "mcfrs_ioctl"))
1056 if ((cmd != TIOCGSERIAL) && (cmd != TIOCSSERIAL) &&
1057 (cmd != TIOCSERCONFIG) && (cmd != TIOCSERGWILD) &&
1058 (cmd != TIOCSERSWILD) && (cmd != TIOCSERGSTRUCT)) {
1059 if (tty->flags & (1 << TTY_IO_ERROR))
1064 case TCSBRK: /* SVID version: non-zero arg --> no break */
1065 retval = tty_check_change(tty);
1068 tty_wait_until_sent(tty, 0);
1070 send_break(info, HZ/4); /* 1/4 second */
1072 case TCSBRKP: /* support for POSIX tcsendbreak() */
1073 retval = tty_check_change(tty);
1076 tty_wait_until_sent(tty, 0);
1077 send_break(info, arg ? arg*(HZ/10) : HZ/4);
1080 error = put_user(C_CLOCAL(tty) ? 1 : 0,
1081 (unsigned long *) arg);
1086 get_user(arg, (unsigned long *) arg);
1087 tty->termios->c_cflag =
1088 ((tty->termios->c_cflag & ~CLOCAL) |
1089 (arg ? CLOCAL : 0));
1092 error = verify_area(VERIFY_WRITE, (void *) arg,
1093 sizeof(struct serial_struct));
1096 return get_serial_info(info,
1097 (struct serial_struct *) arg);
1099 return set_serial_info(info,
1100 (struct serial_struct *) arg);
1101 case TIOCSERGETLSR: /* Get line status register */
1102 error = verify_area(VERIFY_WRITE, (void *) arg,
1103 sizeof(unsigned int));
1107 return get_lsr_info(info, (unsigned int *) arg);
1109 case TIOCSERGSTRUCT:
1110 error = copy_to_user((struct mcf_serial *) arg,
1111 info, sizeof(struct mcf_serial));
1119 get_user(val, (unsigned int *) arg);
1120 mcf_setpa(MCFPP_PA11, (val ? 0 : MCFPP_PA11));
1125 val = (mcf_getpa() & MCFPP_PA11) ? 0 : 1;
1126 put_user(val, (unsigned int *) arg);
1132 return -ENOIOCTLCMD;
1137 static void mcfrs_set_termios(struct tty_struct *tty, struct termios *old_termios)
1139 struct mcf_serial *info = (struct mcf_serial *)tty->driver_data;
1141 if (tty->termios->c_cflag == old_termios->c_cflag)
1144 mcfrs_change_speed(info);
1146 if ((old_termios->c_cflag & CRTSCTS) &&
1147 !(tty->termios->c_cflag & CRTSCTS)) {
1148 tty->hw_stopped = 0;
1149 mcfrs_setsignals(info, -1, 1);
1157 * ------------------------------------------------------------
1160 * This routine is called when the serial port gets closed. First, we
1161 * wait for the last remaining data to be sent. Then, we unlink its
1162 * S structure from the interrupt chain if necessary, and we free
1163 * that IRQ if nothing is left in the chain.
1164 * ------------------------------------------------------------
1166 static void mcfrs_close(struct tty_struct *tty, struct file * filp)
1168 volatile unsigned char *uartp;
1169 struct mcf_serial *info = (struct mcf_serial *)tty->driver_data;
1170 unsigned long flags;
1172 if (!info || serial_paranoia_check(info, tty->name, "mcfrs_close"))
1175 local_irq_save(flags);
1177 if (tty_hung_up_p(filp)) {
1178 local_irq_restore(flags);
1182 #ifdef SERIAL_DEBUG_OPEN
1183 printk("mcfrs_close ttyS%d, count = %d\n", info->line, info->count);
1185 if ((tty->count == 1) && (info->count != 1)) {
1187 * Uh, oh. tty->count is 1, which means that the tty
1188 * structure will be freed. Info->count should always
1189 * be one in these conditions. If it's greater than
1190 * one, we've got real problems, since it means the
1191 * serial port won't be shutdown.
1193 printk("MCFRS: bad serial port count; tty->count is 1, "
1194 "info->count is %d\n", info->count);
1197 if (--info->count < 0) {
1198 printk("MCFRS: bad serial port count for ttyS%d: %d\n",
1199 info->line, info->count);
1203 local_irq_restore(flags);
1206 info->flags |= ASYNC_CLOSING;
1209 * Now we wait for the transmit buffer to clear; and we notify
1210 * the line discipline to only process XON/XOFF characters.
1213 if (info->closing_wait != ASYNC_CLOSING_WAIT_NONE)
1214 tty_wait_until_sent(tty, info->closing_wait);
1217 * At this point we stop accepting input. To do this, we
1218 * disable the receive line status interrupts, and tell the
1219 * interrupt driver to stop checking the data ready bit in the
1220 * line status register.
1222 info->imr &= ~MCFUART_UIR_RXREADY;
1224 uartp[MCFUART_UIMR] = info->imr;
1227 /* FIXME: do we need to keep this enabled for console?? */
1228 if (mcfrs_console_inited && (mcfrs_console_port == info->line)) {
1229 /* Do not disable the UART */ ;
1233 if (tty->driver->flush_buffer)
1234 tty->driver->flush_buffer(tty);
1235 if (tty->ldisc.flush_buffer)
1236 tty->ldisc.flush_buffer(tty);
1240 if (tty->ldisc.num != ldiscs[N_TTY].num) {
1241 if (tty->ldisc.close)
1242 (tty->ldisc.close)(tty);
1243 tty->ldisc = ldiscs[N_TTY];
1244 tty->termios->c_line = N_TTY;
1245 if (tty->ldisc.open)
1246 (tty->ldisc.open)(tty);
1248 if (info->blocked_open) {
1249 if (info->close_delay) {
1250 current->state = TASK_INTERRUPTIBLE;
1251 schedule_timeout(info->close_delay);
1253 wake_up_interruptible(&info->open_wait);
1255 info->flags &= ~(ASYNC_NORMAL_ACTIVE|ASYNC_CLOSING);
1256 wake_up_interruptible(&info->close_wait);
1257 local_irq_restore(flags);
1261 * mcfrs_wait_until_sent() --- wait until the transmitter is empty
1264 mcfrs_wait_until_sent(struct tty_struct *tty, int timeout)
1267 #define MCF5272_FIFO_SIZE 25 /* fifo size + shift reg */
1269 struct mcf_serial * info = (struct mcf_serial *)tty->driver_data;
1270 volatile unsigned char *uartp;
1271 unsigned long orig_jiffies, fifo_time, char_time, fifo_cnt;
1273 if (serial_paranoia_check(info, tty->name, "mcfrs_wait_until_sent"))
1276 orig_jiffies = jiffies;
1279 * Set the check interval to be 1/5 of the approximate time
1280 * to send the entire fifo, and make it at least 1. The check
1281 * interval should also be less than the timeout.
1283 * Note: we have to use pretty tight timings here to satisfy
1286 fifo_time = (MCF5272_FIFO_SIZE * HZ * 10) / info->baud;
1287 char_time = fifo_time / 5;
1290 if (timeout && timeout < char_time)
1291 char_time = timeout;
1294 * Clamp the timeout period at 2 * the time to empty the
1295 * fifo. Just to be safe, set the minimum at .5 seconds.
1298 if (fifo_time < (HZ/2))
1300 if (!timeout || timeout > fifo_time)
1301 timeout = fifo_time;
1304 * Account for the number of bytes in the UART
1305 * transmitter FIFO plus any byte being shifted out.
1307 uartp = (volatile unsigned char *) info->addr;
1309 fifo_cnt = (uartp[MCFUART_UTF] & MCFUART_UTF_TXB);
1310 if ((uartp[MCFUART_USR] & (MCFUART_USR_TXREADY|
1311 MCFUART_USR_TXEMPTY)) ==
1312 MCFUART_USR_TXREADY)
1316 set_current_state(TASK_INTERRUPTIBLE);
1317 schedule_timeout(char_time);
1318 if (signal_pending(current))
1320 if (timeout && time_after(jiffies, orig_jiffies + timeout))
1325 * For the other coldfire models, assume all data has been sent
1331 * mcfrs_hangup() --- called by tty_hangup() when a hangup is signaled.
1333 void mcfrs_hangup(struct tty_struct *tty)
1335 struct mcf_serial * info = (struct mcf_serial *)tty->driver_data;
1337 if (serial_paranoia_check(info, tty->name, "mcfrs_hangup"))
1340 mcfrs_flush_buffer(tty);
1344 info->flags &= ~ASYNC_NORMAL_ACTIVE;
1346 wake_up_interruptible(&info->open_wait);
1350 * ------------------------------------------------------------
1351 * mcfrs_open() and friends
1352 * ------------------------------------------------------------
1354 static int block_til_ready(struct tty_struct *tty, struct file * filp,
1355 struct mcf_serial *info)
1357 DECLARE_WAITQUEUE(wait, current);
1362 * If the device is in the middle of being closed, then block
1363 * until it's done, and then try again.
1365 if (info->flags & ASYNC_CLOSING) {
1366 interruptible_sleep_on(&info->close_wait);
1367 #ifdef SERIAL_DO_RESTART
1368 if (info->flags & ASYNC_HUP_NOTIFY)
1371 return -ERESTARTSYS;
1378 * If non-blocking mode is set, or the port is not enabled,
1379 * then make the check up front and then exit.
1381 if ((filp->f_flags & O_NONBLOCK) ||
1382 (tty->flags & (1 << TTY_IO_ERROR))) {
1383 info->flags |= ASYNC_NORMAL_ACTIVE;
1387 if (tty->termios->c_cflag & CLOCAL)
1391 * Block waiting for the carrier detect and the line to become
1392 * free (i.e., not in use by the callout). While we are in
1393 * this loop, info->count is dropped by one, so that
1394 * mcfrs_close() knows when to free things. We restore it upon
1395 * exit, either normal or abnormal.
1398 add_wait_queue(&info->open_wait, &wait);
1399 #ifdef SERIAL_DEBUG_OPEN
1400 printk("block_til_ready before block: ttyS%d, count = %d\n",
1401 info->line, info->count);
1404 info->blocked_open++;
1406 local_irq_disable();
1407 mcfrs_setsignals(info, 1, 1);
1409 current->state = TASK_INTERRUPTIBLE;
1410 if (tty_hung_up_p(filp) ||
1411 !(info->flags & ASYNC_INITIALIZED)) {
1412 #ifdef SERIAL_DO_RESTART
1413 if (info->flags & ASYNC_HUP_NOTIFY)
1416 retval = -ERESTARTSYS;
1422 if (!(info->flags & ASYNC_CLOSING) &&
1423 (do_clocal || (mcfrs_getsignals(info) & TIOCM_CD)))
1425 if (signal_pending(current)) {
1426 retval = -ERESTARTSYS;
1429 #ifdef SERIAL_DEBUG_OPEN
1430 printk("block_til_ready blocking: ttyS%d, count = %d\n",
1431 info->line, info->count);
1435 current->state = TASK_RUNNING;
1436 remove_wait_queue(&info->open_wait, &wait);
1437 if (!tty_hung_up_p(filp))
1439 info->blocked_open--;
1440 #ifdef SERIAL_DEBUG_OPEN
1441 printk("block_til_ready after blocking: ttyS%d, count = %d\n",
1442 info->line, info->count);
1446 info->flags |= ASYNC_NORMAL_ACTIVE;
1451 * This routine is called whenever a serial port is opened. It
1452 * enables interrupts for a serial port, linking in its structure into
1453 * the IRQ chain. It also performs the serial-specific
1454 * initialization for the tty structure.
1456 int mcfrs_open(struct tty_struct *tty, struct file * filp)
1458 struct mcf_serial *info;
1462 if ((line < 0) || (line >= NR_PORTS))
1464 info = mcfrs_table + line;
1465 if (serial_paranoia_check(info, tty->name, "mcfrs_open"))
1467 #ifdef SERIAL_DEBUG_OPEN
1468 printk("mcfrs_open %s, count = %d\n", tty->name, info->count);
1471 tty->driver_data = info;
1475 * Start up serial port
1477 retval = startup(info);
1481 retval = block_til_ready(tty, filp, info);
1483 #ifdef SERIAL_DEBUG_OPEN
1484 printk("mcfrs_open returning after block_til_ready with %d\n",
1490 #ifdef SERIAL_DEBUG_OPEN
1491 printk("mcfrs_open %s successful...\n", tty->name);
1497 * Based on the line number set up the internal interrupt stuff.
1499 static void mcfrs_irqinit(struct mcf_serial *info)
1501 #if defined(CONFIG_M5272)
1502 volatile unsigned long *icrp;
1503 volatile unsigned long *portp;
1504 volatile unsigned char *uartp;
1507 icrp = (volatile unsigned long *) (MCF_MBAR + MCFSIM_ICR2);
1509 switch (info->line) {
1517 printk("MCFRS: don't know how to handle UART %d interrupt?\n",
1522 /* Enable the output lines for the serial ports */
1523 portp = (volatile unsigned long *) (MCF_MBAR + MCFSIM_PBCNT);
1524 *portp = (*portp & ~0x000000ff) | 0x00000055;
1525 portp = (volatile unsigned long *) (MCF_MBAR + MCFSIM_PDCNT);
1526 *portp = (*portp & ~0x000003fc) | 0x000002a8;
1527 #elif defined(CONFIG_M5282)
1528 volatile unsigned char *icrp, *uartp;
1529 volatile unsigned long *imrp;
1533 icrp = (volatile unsigned char *) (MCF_MBAR + MCFICM_INTC0 +
1534 MCFINTC_ICR0 + MCFINT_UART0 + info->line);
1535 *icrp = 0x33; /* UART0 with level 6, priority 3 */
1537 imrp = (volatile unsigned long *) (MCF_MBAR + MCFICM_INTC0 +
1539 *imrp &= ~((1 << (info->irq - 64)) | 1);
1541 volatile unsigned char *icrp, *uartp;
1543 switch (info->line) {
1545 icrp = (volatile unsigned char *) (MCF_MBAR + MCFSIM_UART1ICR);
1546 *icrp = /*MCFSIM_ICR_AUTOVEC |*/ MCFSIM_ICR_LEVEL6 |
1548 mcf_setimr(mcf_getimr() & ~MCFSIM_IMR_UART1);
1551 icrp = (volatile unsigned char *) (MCF_MBAR + MCFSIM_UART2ICR);
1552 *icrp = /*MCFSIM_ICR_AUTOVEC |*/ MCFSIM_ICR_LEVEL6 |
1554 mcf_setimr(mcf_getimr() & ~MCFSIM_IMR_UART2);
1557 printk("MCFRS: don't know how to handle UART %d interrupt?\n",
1563 uartp[MCFUART_UIVR] = info->irq;
1566 /* Clear mask, so no surprise interrupts. */
1567 uartp[MCFUART_UIMR] = 0;
1569 if (request_irq(info->irq, mcfrs_interrupt, SA_INTERRUPT,
1570 "ColdFire UART", NULL)) {
1571 printk("MCFRS: Unable to attach ColdFire UART %d interrupt "
1572 "vector=%d\n", info->line, info->irq);
1579 char *mcfrs_drivername = "ColdFire internal UART serial driver version 1.00\n";
1583 * Serial stats reporting...
1585 int mcfrs_readproc(char *page, char **start, off_t off, int count,
1586 int *eof, void *data)
1588 struct mcf_serial *info;
1592 len = sprintf(page, mcfrs_drivername);
1593 for (i = 0; (i < NR_PORTS); i++) {
1594 info = &mcfrs_table[i];
1595 len += sprintf((page + len), "%d: port:%x irq=%d baud:%d ",
1596 i, (unsigned int) info->addr, info->irq, info->baud);
1597 if (info->stats.rx || info->stats.tx)
1598 len += sprintf((page + len), "tx:%d rx:%d ",
1599 info->stats.tx, info->stats.rx);
1600 if (info->stats.rxframing)
1601 len += sprintf((page + len), "fe:%d ",
1602 info->stats.rxframing);
1603 if (info->stats.rxparity)
1604 len += sprintf((page + len), "pe:%d ",
1605 info->stats.rxparity);
1606 if (info->stats.rxbreak)
1607 len += sprintf((page + len), "brk:%d ",
1608 info->stats.rxbreak);
1609 if (info->stats.rxoverrun)
1610 len += sprintf((page + len), "oe:%d ",
1611 info->stats.rxoverrun);
1613 str[0] = str[1] = 0;
1614 if ((sigs = mcfrs_getsignals(info))) {
1615 if (sigs & TIOCM_RTS)
1616 strcat(str, "|RTS");
1617 if (sigs & TIOCM_CTS)
1618 strcat(str, "|CTS");
1619 if (sigs & TIOCM_DTR)
1620 strcat(str, "|DTR");
1621 if (sigs & TIOCM_CD)
1625 len += sprintf((page + len), "%s\n", &str[1]);
1632 /* Finally, routines used to initialize the serial driver. */
1634 static void show_serial_version(void)
1636 printk(mcfrs_drivername);
1639 static struct tty_operations mcfrs_ops = {
1641 .close = mcfrs_close,
1642 .write = mcfrs_write,
1643 .flush_chars = mcfrs_flush_chars,
1644 .write_room = mcfrs_write_room,
1645 .chars_in_buffer = mcfrs_chars_in_buffer,
1646 .flush_buffer = mcfrs_flush_buffer,
1647 .ioctl = mcfrs_ioctl,
1648 .throttle = mcfrs_throttle,
1649 .unthrottle = mcfrs_unthrottle,
1650 .set_termios = mcfrs_set_termios,
1652 .start = mcfrs_start,
1653 .hangup = mcfrs_hangup,
1654 .read_proc = mcfrs_readproc,
1655 .wait_until_sent = mcfrs_wait_until_sent,
1656 .tiocmget = mcfrs_tiocmget,
1657 .tiocmset = mcfrs_tiocmset,
1660 /* mcfrs_init inits the driver */
1664 struct mcf_serial *info;
1665 unsigned long flags;
1668 /* Setup base handler, and timer table. */
1670 init_timer(&mcfrs_timer_struct);
1671 mcfrs_timer_struct.function = mcfrs_timer;
1672 mcfrs_timer_struct.data = 0;
1673 mcfrs_timer_struct.expires = jiffies + HZ/25;
1674 add_timer(&mcfrs_timer_struct);
1675 mcfrs_ppstatus = mcf_getppdata() & (MCFPP_DCD0 | MCFPP_DCD1);
1677 mcfrs_serial_driver = alloc_tty_driver(NR_PORTS);
1678 if (!mcfrs_serial_driver)
1681 show_serial_version();
1683 /* Initialize the tty_driver structure */
1684 mcfrs_serial_driver->owner = THIS_MODULE;
1685 mcfrs_serial_driver->name = "ttyS";
1686 mcfrs_serial_driver->devfs_name = "ttys/";
1687 mcfrs_serial_driver->driver_name = "serial";
1688 mcfrs_serial_driver->major = TTY_MAJOR;
1689 mcfrs_serial_driver->minor_start = 64;
1690 mcfrs_serial_driver->type = TTY_DRIVER_TYPE_SERIAL;
1691 mcfrs_serial_driver->subtype = SERIAL_TYPE_NORMAL;
1692 mcfrs_serial_driver->init_termios = tty_std_termios;
1694 mcfrs_serial_driver->init_termios.c_cflag =
1695 mcfrs_console_cbaud | CS8 | CREAD | HUPCL | CLOCAL;
1696 mcfrs_serial_driver->flags = TTY_DRIVER_REAL_RAW;
1698 tty_set_operations(mcfrs_serial_driver, &mcfrs_ops);
1700 if (tty_register_driver(mcfrs_serial_driver)) {
1701 printk("MCFRS: Couldn't register serial driver\n");
1702 put_tty_driver(mcfrs_serial_driver);
1706 local_irq_save(flags);
1709 * Configure all the attached serial ports.
1711 for (i = 0, info = mcfrs_table; (i < NR_PORTS); i++, info++) {
1712 info->magic = SERIAL_MAGIC;
1715 info->custom_divisor = 16;
1716 info->close_delay = 50;
1717 info->closing_wait = 3000;
1721 info->blocked_open = 0;
1722 INIT_WORK(&info->tqueue, mcfrs_offintr, info);
1723 INIT_WORK(&info->tqueue_hangup, do_serial_hangup, info);
1724 init_waitqueue_head(&info->open_wait);
1725 init_waitqueue_head(&info->close_wait);
1728 mcfrs_setsignals(info, 0, 0);
1729 mcfrs_irqinit(info);
1731 printk("ttyS%d at 0x%04x (irq = %d)", info->line,
1732 (unsigned int) info->addr, info->irq);
1733 printk(" is a builtin ColdFire UART\n");
1736 local_irq_restore(flags);
1740 module_init(mcfrs_init);
1742 /****************************************************************************/
1743 /* Serial Console */
1744 /****************************************************************************/
1747 * Quick and dirty UART initialization, for console output.
1750 void mcfrs_init_console(void)
1752 volatile unsigned char *uartp;
1756 * Reset UART, get it into known state...
1758 uartp = (volatile unsigned char *) (MCF_MBAR +
1759 (mcfrs_console_port ? MCFUART_BASE2 : MCFUART_BASE1));
1761 uartp[MCFUART_UCR] = MCFUART_UCR_CMDRESETRX; /* reset RX */
1762 uartp[MCFUART_UCR] = MCFUART_UCR_CMDRESETTX; /* reset TX */
1763 uartp[MCFUART_UCR] = MCFUART_UCR_CMDRESETMRPTR; /* reset MR pointer */
1766 * Set port for defined baud , 8 data bits, 1 stop bit, no parity.
1768 uartp[MCFUART_UMR] = MCFUART_MR1_PARITYNONE | MCFUART_MR1_CS8;
1769 uartp[MCFUART_UMR] = MCFUART_MR2_STOP1;
1771 clk = ((MCF_BUSCLK / mcfrs_console_baud) + 16) / 32; /* set baud */
1772 uartp[MCFUART_UBG1] = (clk & 0xff00) >> 8; /* set msb baud */
1773 uartp[MCFUART_UBG2] = (clk & 0xff); /* set lsb baud */
1775 uartp[MCFUART_UCSR] = MCFUART_UCSR_RXCLKTIMER | MCFUART_UCSR_TXCLKTIMER;
1776 uartp[MCFUART_UCR] = MCFUART_UCR_RXENABLE | MCFUART_UCR_TXENABLE;
1778 mcfrs_console_inited++;
1784 * Setup for console. Argument comes from the boot command line.
1787 int mcfrs_console_setup(struct console *cp, char *arg)
1789 int i, n = CONSOLE_BAUD_RATE;
1794 if (!strncmp(cp->name, "ttyS", 4))
1795 mcfrs_console_port = cp->index;
1796 else if (!strncmp(cp->name, "cua", 3))
1797 mcfrs_console_port = cp->index;
1802 n = simple_strtoul(arg,NULL,0);
1803 for (i = 0; i < MCFRS_BAUD_TABLE_SIZE; i++)
1804 if (mcfrs_baud_table[i] == n)
1806 if (i < MCFRS_BAUD_TABLE_SIZE) {
1807 mcfrs_console_baud = n;
1808 mcfrs_console_cbaud = 0;
1810 mcfrs_console_cbaud |= CBAUDEX;
1813 mcfrs_console_cbaud |= i;
1815 mcfrs_init_console(); /* make sure baud rate changes */
1820 static struct tty_driver *mcfrs_console_device(struct console *c, int *index)
1823 return mcfrs_serial_driver;
1828 * Output a single character, using UART polled mode.
1829 * This is used for console output.
1832 void mcfrs_put_char(char ch)
1834 volatile unsigned char *uartp;
1835 unsigned long flags;
1838 uartp = (volatile unsigned char *) (MCF_MBAR +
1839 (mcfrs_console_port ? MCFUART_BASE2 : MCFUART_BASE1));
1841 local_irq_save(flags);
1842 for (i = 0; (i < 0x10000); i++) {
1843 if (uartp[MCFUART_USR] & MCFUART_USR_TXREADY)
1847 uartp[MCFUART_UTB] = ch;
1848 for (i = 0; (i < 0x10000); i++)
1849 if (uartp[MCFUART_USR] & MCFUART_USR_TXEMPTY)
1853 mcfrs_init_console(); /* try and get it back */
1854 local_irq_restore(flags);
1861 * rs_console_write is registered for printk output.
1864 void mcfrs_console_write(struct console *cp, const char *p, unsigned len)
1866 if (!mcfrs_console_inited)
1867 mcfrs_init_console();
1870 mcfrs_put_char('\r');
1871 mcfrs_put_char(*p++);
1876 * declare our consoles
1879 struct console mcfrs_console = {
1881 .write = mcfrs_console_write,
1882 .device = mcfrs_console_device,
1883 .setup = mcfrs_console_setup,
1884 .flags = CON_PRINTBUFFER,
1888 static int __init mcfrs_console_init(void)
1890 register_console(&mcfrs_console);
1894 console_initcall(mcfrs_console_init);
1896 /****************************************************************************/