2 * UART driver for MPC8260 CPM SCC or SMC
3 * Copyright (c) 1999 Dan Malek (dmalek@jlc.net)
4 * Copyright (c) 2000 MontaVista Software, Inc. (source@mvista.com)
6 * Copyright (c) 2002 Allen Curtis, Ones and Zeros, Inc. (acurtis@onz.com)
8 * Fix the console driver to be registered with initcalls and some minor fixup
9 * for 2.6.2, by Petter Larsen, moreCom as (petter.larsen@morecom.no) and
10 * Miguel Valero, AxxessIT ASA (miguel.valero@axxessit.no)
12 * I used the 8xx uart.c driver as the framework for this driver.
13 * The original code was written for the EST8260 board. I tried to make
14 * it generic, but there may be some assumptions in the structures that
15 * have to be fixed later.
17 * The 8xx and 8260 are similar, but not identical. Over time we
18 * could probably merge these two drivers.
19 * To save porting time, I did not bother to change any object names
20 * that are not accessed outside of this file.
21 * It still needs lots of work........When it was easy, I included code
22 * to support the SCCs.
23 * Only the SCCs support modem control, so that is not complete either.
26 #include <linux/config.h>
27 #include <linux/module.h>
28 #include <linux/errno.h>
29 #include <linux/signal.h>
30 #include <linux/sched.h>
31 #include <linux/timer.h>
32 #include <linux/workqueue.h>
33 #include <linux/interrupt.h>
34 #include <linux/tty.h>
35 #include <linux/tty_flip.h>
36 #include <linux/serial.h>
37 #include <linux/serialP.h>
38 #include <linux/major.h>
39 #include <linux/string.h>
40 #include <linux/fcntl.h>
41 #include <linux/ptrace.h>
43 #include <linux/slab.h>
44 #include <linux/init.h>
45 #include <linux/delay.h>
46 #include <asm/uaccess.h>
47 #include <asm/immap_8260.h>
48 #include <asm/mpc8260.h>
49 #include <asm/cpm_8260.h>
52 #ifdef CONFIG_MAGIC_SYSRQ
53 #include <linux/sysrq.h>
56 #ifdef CONFIG_SERIAL_CONSOLE
57 #include <linux/console.h>
59 /* SCC Console configuration. Not quite finished. The SCC_CONSOLE
60 * should be the number of the SCC to use, but only SCC1 will
63 #ifdef CONFIG_SCC_CONSOLE
67 /* this defines the index into rs_table for the port to use
69 #ifndef CONFIG_SERIAL_CONSOLE_PORT
70 #define CONFIG_SERIAL_CONSOLE_PORT 0
73 #define CONFIG_SERIAL_CONSOLE_PORT 0
75 #define TX_WAKEUP ASYNC_SHARE_IRQ
77 static char *serial_name = "CPM UART driver";
78 static char *serial_version = "0.02";
80 static struct tty_driver *serial_driver;
81 static int __init serial_console_setup( struct console *co, char *options);
82 static void serial_console_write(struct console *c, const char *s,
85 static struct tty_driver *serial_console_device(struct console *c, int *index);
87 #if defined(CONFIG_SERIAL_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ)
88 static unsigned long break_pressed; /* break, really ... */
92 * Serial driver configuration section. Here are the various options:
94 #define SERIAL_PARANOIA_CHECK
95 #define CONFIG_SERIAL_NOPAUSE_IO
96 #define SERIAL_DO_RESTART
98 /* Set of debugging defines */
100 #undef SERIAL_DEBUG_INTR
101 #undef SERIAL_DEBUG_OPEN
102 #undef SERIAL_DEBUG_FLOW
103 #undef SERIAL_DEBUG_RS_WAIT_UNTIL_SENT
105 #define _INLINE_ inline
109 /* We overload some of the items in the data structure to meet our
110 * needs. For example, the port address is the CPM parameter ram
111 * offset for the SCC or SMC. The maximum number of ports is 4 SCCs and
112 * 2 SMCs. The "hub6" field is used to indicate the channel number, with
113 * 0 and 1 indicating the SMCs and 2, 3, 4, and 5 are the SCCs.
114 * Since these ports are so versatile, I don't yet have a strategy for
115 * their management. For example, SCC1 is used for Ethernet. Right
116 * now, just don't put them in the table. Of course, right now I just
117 * want the SMC to work as a uart :-)..
118 * The "type" field is currently set to 0, for PORT_UNKNOWN. It is
119 * not currently used. I should probably use it to indicate the port
120 * type of CMS or SCC.
121 * The SMCs do not support any modem control signals.
123 #define smc_scc_num hub6
125 /* The choice of serial port to use for KGDB. If the system has
126 * two ports, you can use one for console and one for KGDB (which
127 * doesn't make sense to me, but people asked for it).
129 #ifdef CONFIG_KGDB_TTYS1
130 #define KGDB_SER_IDX 1 /* SCC2/SMC2 */
132 #define KGDB_SER_IDX 0 /* SCC1/SMC1 */
137 /* SMC2 is sometimes used for low performance TDM interfaces. Define
138 * this as 1 if you want SMC2 as a serial port UART managed by this driver.
139 * Define this as 0 if you wish to use SMC2 for something else.
143 /* Define SCC to ttySx mapping.
145 #define SCC_NUM_BASE (USE_SMC2 + 1) /* SCC base tty "number" */
147 /* Define which SCC is the first one to use for a serial port. These
148 * are 0-based numbers, i.e. this assumes the first SCC (SCC1) is used
149 * for Ethernet, and the first available SCC for serial UART is SCC2.
150 * NOTE: IF YOU CHANGE THIS, you have to change the PROFF_xxx and
151 * interrupt vectors in the table below to match.
153 #define SCC_IDX_BASE 1 /* table index */
155 static struct serial_state rs_table[] = {
156 /* UART CLK PORT IRQ FLAGS NUM */
157 { 0, 0, PROFF_SMC1, SIU_INT_SMC1, 0, 0 }, /* SMC1 ttyS0 */
159 { 0, 0, PROFF_SMC2, SIU_INT_SMC2, 0, 1 }, /* SMC2 ttyS1 */
161 #ifndef CONFIG_SCC1_ENET
162 { 0, 0, PROFF_SCC1, SIU_INT_SCC1, 0, SCC_NUM_BASE}, /* SCC1 ttyS2 */
164 #if !defined(CONFIG_SBC82xx) && !defined(CONFIG_SCC2_ENET)
165 { 0, 0, PROFF_SCC2, SIU_INT_SCC2, 0, SCC_NUM_BASE + 1}, /* SCC2 ttyS3 */
169 #else /* SCC_CONSOLE */
170 #define SCC_NUM_BASE 0 /* SCC base tty "number" */
171 #define SCC_IDX_BASE 0 /* table index */
172 static struct serial_state rs_table[] = {
173 /* UART CLK PORT IRQ FLAGS NUM */
174 { 0, 0, PROFF_SCC1, SIU_INT_SCC1, 0, SCC_NUM_BASE}, /* SCC1 ttyS2 */
175 { 0, 0, PROFF_SCC2, SIU_INT_SCC2, 0, SCC_NUM_BASE + 1}, /* SCC2 ttyS3 */
177 #endif /* SCC_CONSOLE */
179 #define PORT_NUM(P) (((P) < (SCC_NUM_BASE)) ? (P) : (P)-(SCC_NUM_BASE))
181 #define NR_PORTS (sizeof(rs_table)/sizeof(struct serial_state))
183 /* The number of buffer descriptors and their sizes.
185 #define RX_NUM_FIFO 4
186 #define RX_BUF_SIZE 32
187 #define TX_NUM_FIFO 4
188 #define TX_BUF_SIZE 32
190 /* The async_struct in serial.h does not really give us what we
191 * need, so define our own here.
193 typedef struct serial_info {
196 struct serial_state *state;
197 struct tty_struct *tty;
198 int read_status_mask;
199 int ignore_status_mask;
202 int x_char; /* xon/xoff character */
204 unsigned short closing_wait;
205 unsigned short closing_wait2;
207 unsigned long last_active;
208 int blocked_open; /* # of blocked opens */
209 struct work_struct tqueue;
210 struct work_struct tqueue_hangup;
211 wait_queue_head_t open_wait;
212 wait_queue_head_t close_wait;
214 /* CPM Buffer Descriptor pointers.
222 static struct console sercons = {
224 .write = serial_console_write,
225 .device = serial_console_device,
226 .setup = serial_console_setup,
227 .flags = CON_PRINTBUFFER,
228 .index = CONFIG_SERIAL_CONSOLE_PORT,
231 static void change_speed(ser_info_t *info);
232 static void rs_8xx_wait_until_sent(struct tty_struct *tty, int timeout);
234 static inline int serial_paranoia_check(ser_info_t *info,
235 char *name, const char *routine)
237 #ifdef SERIAL_PARANOIA_CHECK
238 static const char *badmagic =
239 "Warning: bad magic number for serial struct (%s) in %s\n";
240 static const char *badinfo =
241 "Warning: null async_struct for (%s) in %s\n";
244 printk(badinfo, name, routine);
247 if (info->magic != SERIAL_MAGIC) {
248 printk(badmagic, name, routine);
256 * This is used to figure out the divisor speeds and the timeouts,
257 * indexed by the termio value. The generic CPM functions are responsible
258 * for setting and assigning baud rate generators for us.
260 static int baud_table[] = {
261 0, 50, 75, 110, 134, 150, 200, 300, 600, 1200, 1800, 2400, 4800,
262 9600, 19200, 38400, 57600, 115200, 230400, 460800, 0 };
266 * ------------------------------------------------------------
267 * rs_stop() and rs_start()
269 * This routines are called before setting or resetting tty->stopped.
270 * They enable or disable transmitter interrupts, as necessary.
271 * ------------------------------------------------------------
273 static void rs_8xx_stop(struct tty_struct *tty)
275 ser_info_t *info = (ser_info_t *)tty->driver_data;
278 volatile scc_t *sccp;
279 volatile smc_t *smcp;
281 if (serial_paranoia_check(info, tty->name, "rs_stop"))
284 save_flags(flags); cli();
285 if ((idx = info->state->smc_scc_num) < SCC_NUM_BASE) {
286 smcp = &immr->im_smc[idx];
287 smcp->smc_smcm &= ~SMCM_TX;
290 sccp = &immr->im_scc[idx - SCC_IDX_BASE];
291 sccp->scc_sccm &= ~UART_SCCM_TX;
293 restore_flags(flags);
296 static void rs_8xx_start(struct tty_struct *tty)
298 ser_info_t *info = (ser_info_t *)tty->driver_data;
301 volatile scc_t *sccp;
302 volatile smc_t *smcp;
304 if (serial_paranoia_check(info, tty->name, "rs_stop"))
307 save_flags(flags); cli();
308 if ((idx = info->state->smc_scc_num) < SCC_NUM_BASE) {
309 smcp = &immr->im_smc[idx];
310 smcp->smc_smcm |= SMCM_TX;
313 sccp = &immr->im_scc[idx - SCC_IDX_BASE];
314 sccp->scc_sccm |= UART_SCCM_TX;
316 restore_flags(flags);
320 * ----------------------------------------------------------------------
322 * Here starts the interrupt handling routines. All of the following
323 * subroutines are declared as inline and are folded into
324 * rs_interrupt(). They were separated out for readability's sake.
326 * Note: rs_interrupt() is a "fast" interrupt, which means that it
327 * runs with interrupts turned off. People who may want to modify
328 * rs_interrupt() should try to keep the interrupt handler as fast as
329 * possible. After you are done making modifications, it is not a bad
332 * gcc -S -DKERNEL -Wall -Wstrict-prototypes -O6 -fomit-frame-pointer serial.c
334 * and look at the resulting assemble code in serial.s.
336 * - Ted Ts'o (tytso@mit.edu), 7-Mar-93
337 * -----------------------------------------------------------------------
341 * This routine is used by the interrupt handler to schedule
342 * processing in the software interrupt portion of the driver.
344 static _INLINE_ void rs_sched_event(ser_info_t *info,
347 info->event |= 1 << event;
348 schedule_work(&info->tqueue);
351 static _INLINE_ void receive_chars(ser_info_t *info, struct pt_regs *regs)
353 struct tty_struct *tty = info->tty;
354 unsigned char ch, *cp;
358 struct async_icount *icount;
361 icount = &info->state->icount;
363 /* Just loop through the closed BDs and copy the characters into
368 if (bdp->cbd_sc & BD_SC_EMPTY) /* If this one is empty */
369 break; /* we are all done */
371 /* The read status mask tell us what we should do with
372 * incoming characters, especially if errors occur.
373 * One special case is the use of BD_SC_EMPTY. If
374 * this is not set, we are supposed to be ignoring
375 * inputs. In this case, just mark the buffer empty and
377 if (!(info->read_status_mask & BD_SC_EMPTY)) {
378 bdp->cbd_sc |= BD_SC_EMPTY;
380 ~(BD_SC_BR | BD_SC_FR | BD_SC_PR | BD_SC_OV);
382 if (bdp->cbd_sc & BD_SC_WRAP)
383 bdp = info->rx_bd_base;
390 /* Get the number of characters and the buffer pointer.
393 cp = (unsigned char *)__va(bdp->cbd_bufaddr);
394 status = bdp->cbd_sc;
396 if (info->state->smc_scc_num == KGDB_SER_IDX) {
397 if (*cp == 0x03 || *cp == '$')
403 /* Check to see if there is room in the tty buffer for
404 * the characters in our BD buffer. If not, we exit
405 * now, leaving the BD with the characters. We'll pick
406 * them up again on the next receive interrupt (which could
409 if ((tty->flip.count + i) >= TTY_FLIPBUF_SIZE)
414 *tty->flip.char_buf_ptr = ch;
417 #ifdef SERIAL_DEBUG_INTR
418 printk("DR%02x:%02x...", ch, *status);
420 *tty->flip.flag_buf_ptr = 0;
421 if (status & (BD_SC_BR | BD_SC_FR |
422 BD_SC_PR | BD_SC_OV)) {
424 * For statistics only
426 if (status & BD_SC_BR)
428 else if (status & BD_SC_PR)
430 else if (status & BD_SC_FR)
432 if (status & BD_SC_OV)
436 * Now check to see if character should be
437 * ignored, and mask off conditions which
439 if (status & info->ignore_status_mask) {
445 status &= info->read_status_mask;
447 if (status & (BD_SC_BR)) {
448 #ifdef SERIAL_DEBUG_INTR
449 printk("handling break....");
451 *tty->flip.flag_buf_ptr = TTY_BREAK;
452 if (info->flags & ASYNC_SAK)
454 } else if (status & BD_SC_PR)
455 *tty->flip.flag_buf_ptr = TTY_PARITY;
456 else if (status & BD_SC_FR)
457 *tty->flip.flag_buf_ptr = TTY_FRAME;
458 if (status & BD_SC_OV) {
460 * Overrun is special, since it's
461 * reported immediately, and doesn't
462 * affect the current character
464 if (tty->flip.count < TTY_FLIPBUF_SIZE) {
466 tty->flip.flag_buf_ptr++;
467 tty->flip.char_buf_ptr++;
468 *tty->flip.flag_buf_ptr =
474 #if defined(CONFIG_SERIAL_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ)
475 if (break_pressed && info->line == sercons.index) {
476 if (ch != 0 && time_before(jiffies,
477 break_pressed + HZ*5)) {
478 handle_sysrq(ch, regs, NULL);
486 if (tty->flip.count >= TTY_FLIPBUF_SIZE)
489 tty->flip.flag_buf_ptr++;
490 tty->flip.char_buf_ptr++;
494 #if defined(CONFIG_SERIAL_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ)
498 /* This BD is ready to be used again. Clear status.
501 bdp->cbd_sc |= BD_SC_EMPTY;
502 bdp->cbd_sc &= ~(BD_SC_BR | BD_SC_FR | BD_SC_PR | BD_SC_OV);
504 if (bdp->cbd_sc & BD_SC_WRAP)
505 bdp = info->rx_bd_base;
510 info->rx_cur = (cbd_t *)bdp;
512 schedule_delayed_work(&tty->flip.work, 1);
515 static _INLINE_ void receive_break(ser_info_t *info, struct pt_regs *regs)
517 struct tty_struct *tty = info->tty;
519 info->state->icount.brk++;
521 #if defined(CONFIG_SERIAL_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ)
522 if (info->line == sercons.index) {
523 if (!break_pressed) {
524 break_pressed = jiffies;
531 /* Check to see if there is room in the tty buffer for
532 * the break. If not, we exit now, losing the break. FIXME
534 if ((tty->flip.count + 1) >= TTY_FLIPBUF_SIZE)
536 *(tty->flip.flag_buf_ptr++) = TTY_BREAK;
537 *(tty->flip.char_buf_ptr++) = 0;
542 static _INLINE_ void transmit_chars(ser_info_t *info, struct pt_regs *regs)
545 if (info->flags & TX_WAKEUP) {
546 rs_sched_event(info, RS_EVENT_WRITE_WAKEUP);
549 #ifdef SERIAL_DEBUG_INTR
555 /* I need to do this for the SCCs, so it is left as a reminder.
557 static _INLINE_ void check_modem_status(struct async_struct *info)
560 struct async_icount *icount;
562 status = serial_in(info, UART_MSR);
564 if (status & UART_MSR_ANY_DELTA) {
565 icount = &info->state->icount;
566 /* update input line counters */
567 if (status & UART_MSR_TERI)
569 if (status & UART_MSR_DDSR)
571 if (status & UART_MSR_DDCD) {
573 #ifdef CONFIG_HARD_PPS
574 if ((info->flags & ASYNC_HARDPPS_CD) &&
575 (status & UART_MSR_DCD))
579 if (status & UART_MSR_DCTS)
581 wake_up_interruptible(&info->delta_msr_wait);
584 if ((info->flags & ASYNC_CHECK_CD) && (status & UART_MSR_DDCD)) {
585 #if (defined(SERIAL_DEBUG_OPEN) || defined(SERIAL_DEBUG_INTR))
586 printk("ttys%d CD now %s...", info->line,
587 (status & UART_MSR_DCD) ? "on" : "off");
589 if (status & UART_MSR_DCD)
590 wake_up_interruptible(&info->open_wait);
592 #ifdef SERIAL_DEBUG_OPEN
593 printk("scheduling hangup...");
595 schedule_work(&info->tqueue_hangup);
598 if (info->flags & ASYNC_CTS_FLOW) {
599 if (info->tty->hw_stopped) {
600 if (status & UART_MSR_CTS) {
601 #if (defined(SERIAL_DEBUG_INTR) || defined(SERIAL_DEBUG_FLOW))
602 printk("CTS tx start...");
604 info->tty->hw_stopped = 0;
605 info->IER |= UART_IER_THRI;
606 serial_out(info, UART_IER, info->IER);
607 rs_sched_event(info, RS_EVENT_WRITE_WAKEUP);
611 if (!(status & UART_MSR_CTS)) {
612 #if (defined(SERIAL_DEBUG_INTR) || defined(SERIAL_DEBUG_FLOW))
613 printk("CTS tx stop...");
615 info->tty->hw_stopped = 1;
616 info->IER &= ~UART_IER_THRI;
617 serial_out(info, UART_IER, info->IER);
625 * This is the serial driver's interrupt routine for a single port
627 static irqreturn_t rs_8xx_interrupt(int irq, void * dev_id, struct pt_regs * regs)
632 volatile smc_t *smcp;
633 volatile scc_t *sccp;
635 info = (ser_info_t *)dev_id;
637 if ((idx = info->state->smc_scc_num) < SCC_NUM_BASE) {
638 smcp = &immr->im_smc[idx];
639 events = smcp->smc_smce;
640 if (events & SMCM_BRKE)
641 receive_break(info, regs);
642 if (events & SMCM_RX)
643 receive_chars(info, regs);
644 if (events & SMCM_TX)
645 transmit_chars(info, regs);
646 smcp->smc_smce = events;
649 sccp = &immr->im_scc[idx - SCC_IDX_BASE];
650 events = sccp->scc_scce;
651 if (events & SMCM_BRKE)
652 receive_break(info, regs);
653 if (events & SCCM_RX)
654 receive_chars(info, regs);
655 if (events & SCCM_TX)
656 transmit_chars(info, regs);
657 sccp->scc_scce = events;
660 #ifdef SERIAL_DEBUG_INTR
661 printk("rs_interrupt_single(%d, %x)...",
662 info->state->smc_scc_num, events);
665 check_modem_status(info);
667 info->last_active = jiffies;
668 #ifdef SERIAL_DEBUG_INTR
676 * -------------------------------------------------------------------
677 * Here ends the serial interrupt routines.
678 * -------------------------------------------------------------------
682 * This routine is used to handle the "bottom half" processing for the
683 * serial driver, known also the "software interrupt" processing.
684 * This processing is done at the kernel interrupt level, after the
685 * rs_interrupt() has returned, BUT WITH INTERRUPTS TURNED ON. This
686 * is where time-consuming activities which can not be done in the
687 * interrupt driver proper are done; the interrupt driver schedules
688 * them using rs_sched_event(), and they get done here.
690 static void do_softint(void *private_)
692 ser_info_t *info = (ser_info_t *) private_;
693 struct tty_struct *tty;
699 if (test_and_clear_bit(RS_EVENT_WRITE_WAKEUP, &info->event)) {
700 if ((tty->flags & (1 << TTY_DO_WRITE_WAKEUP)) &&
701 tty->ldisc.write_wakeup)
702 (tty->ldisc.write_wakeup)(tty);
703 wake_up_interruptible(&tty->write_wait);
708 * This routine is called from the scheduler work queue when the interrupt
709 * routine has signalled that a hangup has occurred. The path of
710 * hangup processing is:
712 * serial interrupt routine -> (scheduler tqueue) ->
713 * do_serial_hangup() -> tty->hangup() -> rs_hangup()
716 static void do_serial_hangup(void *private_)
718 struct async_struct *info = (struct async_struct *) private_;
719 struct tty_struct *tty;
726 /*static void rs_8xx_timer(void)
728 printk("rs_8xx_timer\n");
732 static int startup(ser_info_t *info)
737 struct serial_state *state= info->state;
738 volatile smc_t *smcp;
739 volatile scc_t *sccp;
740 volatile smc_uart_t *up;
741 volatile scc_uart_t *scup;
744 save_flags(flags); cli();
746 if (info->flags & ASYNC_INITIALIZED) {
751 if (!state->port || !state->type) {
753 set_bit(TTY_IO_ERROR, &info->tty->flags);
758 #ifdef SERIAL_DEBUG_OPEN
759 printk("starting up ttys%d (irq %d)...", info->line, state->irq);
765 if (info->tty->termios->c_cflag & CBAUD)
766 info->MCR = UART_MCR_DTR | UART_MCR_RTS;
770 clear_bit(TTY_IO_ERROR, &info->tty->flags);
773 * and set the speed of the serial port
777 if ((idx = info->state->smc_scc_num) < SCC_NUM_BASE) {
778 smcp = &immr->im_smc[idx];
780 /* Enable interrupts and I/O.
782 smcp->smc_smcm |= (SMCM_RX | SMCM_TX);
783 smcp->smc_smcmr |= (SMCMR_REN | SMCMR_TEN);
785 /* We can tune the buffer length and idle characters
786 * to take advantage of the entire incoming buffer size.
787 * If mrblr is something other than 1, maxidl has to be
788 * non-zero or we never get an interrupt. The maxidl
789 * is the number of character times we wait after reception
790 * of the last character before we decide no more characters
793 up = (smc_uart_t *)&immr->im_dprambase[state->port];
795 up->smc_mrblr = 1; /* receive buffer length */
796 up->smc_maxidl = 0; /* wait forever for next char */
798 up->smc_mrblr = RX_BUF_SIZE;
799 up->smc_maxidl = RX_BUF_SIZE;
801 up->smc_brkcr = 1; /* number of break chars */
804 sccp = &immr->im_scc[idx - SCC_IDX_BASE];
805 scup = (scc_uart_t *)&immr->im_dprambase[state->port];
807 scup->scc_genscc.scc_mrblr = 1; /* receive buffer length */
808 scup->scc_maxidl = 0; /* wait forever for next char */
810 scup->scc_genscc.scc_mrblr = RX_BUF_SIZE;
811 scup->scc_maxidl = RX_BUF_SIZE;
814 sccp->scc_sccm |= (UART_SCCM_TX | UART_SCCM_RX);
815 sccp->scc_gsmrl |= (SCC_GSMRL_ENR | SCC_GSMRL_ENT);
818 info->flags |= ASYNC_INITIALIZED;
819 restore_flags(flags);
823 restore_flags(flags);
828 * This routine will shutdown a serial port; interrupts are disabled, and
829 * DTR is dropped if the hangup on close termio flag is on.
831 static void shutdown(ser_info_t * info)
834 struct serial_state *state;
836 volatile smc_t *smcp;
837 volatile scc_t *sccp;
839 if (!(info->flags & ASYNC_INITIALIZED))
844 #ifdef SERIAL_DEBUG_OPEN
845 printk("Shutting down serial port %d (irq %d)....", info->line,
849 save_flags(flags); cli(); /* Disable interrupts */
851 if ((idx = info->state->smc_scc_num) < SCC_NUM_BASE) {
852 smcp = &immr->im_smc[idx];
854 /* Disable interrupts and I/O.
856 smcp->smc_smcm &= ~(SMCM_RX | SMCM_TX);
857 #ifdef CONFIG_SERIAL_CONSOLE
858 /* We can't disable the transmitter if this is the
861 if (idx != CONFIG_SERIAL_CONSOLE_PORT)
863 smcp->smc_smcmr &= ~(SMCMR_REN | SMCMR_TEN);
866 sccp = &immr->im_scc[idx - SCC_IDX_BASE];
867 sccp->scc_sccm &= ~(UART_SCCM_TX | UART_SCCM_RX);
868 #ifdef CONFIG_SERIAL_CONSOLE
869 if (idx != CONFIG_SERIAL_CONSOLE_PORT)
870 sccp->scc_gsmrl &= ~(SCC_GSMRL_ENR | SCC_GSMRL_ENT);
875 set_bit(TTY_IO_ERROR, &info->tty->flags);
877 info->flags &= ~ASYNC_INITIALIZED;
878 restore_flags(flags);
882 * This routine is called to set the UART divisor registers to match
883 * the specified baud rate for a serial port.
885 static void change_speed(ser_info_t *info)
888 unsigned cflag, cval, scval, prev_mode;
889 int i, bits, sbits, idx;
891 volatile smc_t *smcp;
892 volatile scc_t *sccp;
894 if (!info->tty || !info->tty->termios)
896 cflag = info->tty->termios->c_cflag;
898 /* Character length programmed into the mode register is the
899 * sum of: 1 start bit, number of data bits, 0 or 1 parity bit,
900 * 1 or 2 stop bits, minus 1.
901 * The value 'bits' counts this for us.
906 /* byte size and parity */
907 switch (cflag & CSIZE) {
908 case CS5: bits = 5; break;
909 case CS6: bits = 6; break;
910 case CS7: bits = 7; break;
911 case CS8: bits = 8; break;
912 /* Never happens, but GCC is too dumb to figure it out */
913 default: bits = 8; break;
917 if (cflag & CSTOPB) {
918 cval |= SMCMR_SL; /* Two stops */
919 scval |= SCU_PMSR_SL;
922 if (cflag & PARENB) {
924 scval |= SCU_PMSR_PEN;
927 if (!(cflag & PARODD)) {
928 cval |= SMCMR_PM_EVEN;
929 scval |= (SCU_PMSR_REVP | SCU_PMSR_TEVP);
932 /* Determine divisor based on baud rate */
934 if (i >= (sizeof(baud_table)/sizeof(int)))
937 baud_rate = baud_table[i];
939 info->timeout = (TX_BUF_SIZE*HZ*bits);
940 info->timeout += HZ/50; /* Add .02 seconds of slop */
943 /* CTS flow control flag and modem status interrupts */
944 info->IER &= ~UART_IER_MSI;
945 if (info->flags & ASYNC_HARDPPS_CD)
946 info->IER |= UART_IER_MSI;
947 if (cflag & CRTSCTS) {
948 info->flags |= ASYNC_CTS_FLOW;
949 info->IER |= UART_IER_MSI;
951 info->flags &= ~ASYNC_CTS_FLOW;
953 info->flags &= ~ASYNC_CHECK_CD;
955 info->flags |= ASYNC_CHECK_CD;
956 info->IER |= UART_IER_MSI;
958 serial_out(info, UART_IER, info->IER);
962 * Set up parity check flag
964 #define RELEVANT_IFLAG(iflag) (iflag & (IGNBRK|BRKINT|IGNPAR|PARMRK|INPCK))
966 info->read_status_mask = (BD_SC_EMPTY | BD_SC_OV);
967 if (I_INPCK(info->tty))
968 info->read_status_mask |= BD_SC_FR | BD_SC_PR;
969 if (I_BRKINT(info->tty) || I_PARMRK(info->tty))
970 info->read_status_mask |= BD_SC_BR;
973 * Characters to ignore
975 info->ignore_status_mask = 0;
976 if (I_IGNPAR(info->tty))
977 info->ignore_status_mask |= BD_SC_PR | BD_SC_FR;
978 if (I_IGNBRK(info->tty)) {
979 info->ignore_status_mask |= BD_SC_BR;
981 * If we're ignore parity and break indicators, ignore
982 * overruns too. (For real raw support).
984 if (I_IGNPAR(info->tty))
985 info->ignore_status_mask |= BD_SC_OV;
988 * !!! ignore all characters if CREAD is not set
990 if ((cflag & CREAD) == 0)
991 info->read_status_mask &= ~BD_SC_EMPTY;
992 save_flags(flags); cli();
994 /* Start bit has not been added (so don't, because we would just
995 * subtract it later), and we need to add one for the number of
996 * stops bits (there is always at least one).
999 if ((idx = info->state->smc_scc_num) < SCC_NUM_BASE) {
1000 smcp = &immr->im_smc[idx];
1002 /* Set the mode register. We want to keep a copy of the
1003 * enables, because we want to put them back if they were
1006 prev_mode = smcp->smc_smcmr;
1007 smcp->smc_smcmr = smcr_mk_clen(bits) | cval | SMCMR_SM_UART;
1008 smcp->smc_smcmr |= (prev_mode & (SMCMR_REN | SMCMR_TEN));
1011 sccp = &immr->im_scc[idx - SCC_IDX_BASE];
1012 sccp->scc_pmsr = (sbits << 12) | scval;
1015 m8260_cpm_setbrg(info->state->smc_scc_num, baud_rate);
1017 restore_flags(flags);
1020 static void rs_8xx_put_char(struct tty_struct *tty, unsigned char ch)
1022 ser_info_t *info = (ser_info_t *)tty->driver_data;
1023 volatile cbd_t *bdp;
1025 if (serial_paranoia_check(info, tty->name, "rs_put_char"))
1032 while (bdp->cbd_sc & BD_SC_READY);
1034 *((char *)__va(bdp->cbd_bufaddr)) = ch;
1035 bdp->cbd_datlen = 1;
1036 bdp->cbd_sc |= BD_SC_READY;
1040 if (bdp->cbd_sc & BD_SC_WRAP)
1041 bdp = info->tx_bd_base;
1045 info->tx_cur = (cbd_t *)bdp;
1049 static int rs_8xx_write(struct tty_struct * tty, int from_user,
1050 const unsigned char *buf, int count)
1053 ser_info_t *info = (ser_info_t *)tty->driver_data;
1054 volatile cbd_t *bdp;
1056 if (serial_paranoia_check(info, tty->name, "rs_write"))
1065 c = min(count, TX_BUF_SIZE);
1070 if (bdp->cbd_sc & BD_SC_READY) {
1071 info->flags |= TX_WAKEUP;
1076 if (copy_from_user(__va(bdp->cbd_bufaddr), buf, c)) {
1082 memcpy(__va(bdp->cbd_bufaddr), buf, c);
1085 bdp->cbd_datlen = c;
1086 bdp->cbd_sc |= BD_SC_READY;
1094 if (bdp->cbd_sc & BD_SC_WRAP)
1095 bdp = info->tx_bd_base;
1098 info->tx_cur = (cbd_t *)bdp;
1103 static int rs_8xx_write_room(struct tty_struct *tty)
1105 ser_info_t *info = (ser_info_t *)tty->driver_data;
1108 if (serial_paranoia_check(info, tty->name, "rs_write_room"))
1111 if ((info->tx_cur->cbd_sc & BD_SC_READY) == 0) {
1112 info->flags &= ~TX_WAKEUP;
1116 info->flags |= TX_WAKEUP;
1122 /* I could track this with transmit counters....maybe later.
1124 static int rs_8xx_chars_in_buffer(struct tty_struct *tty)
1126 ser_info_t *info = (ser_info_t *)tty->driver_data;
1128 if (serial_paranoia_check(info, tty->name, "rs_chars_in_buffer"))
1133 static void rs_8xx_flush_buffer(struct tty_struct *tty)
1135 ser_info_t *info = (ser_info_t *)tty->driver_data;
1137 if (serial_paranoia_check(info, tty->name, "rs_flush_buffer"))
1140 /* There is nothing to "flush", whatever we gave the CPM
1141 * is on its way out.
1143 wake_up_interruptible(&tty->write_wait);
1144 if ((tty->flags & (1 << TTY_DO_WRITE_WAKEUP)) &&
1145 tty->ldisc.write_wakeup)
1146 (tty->ldisc.write_wakeup)(tty);
1147 info->flags &= ~TX_WAKEUP;
1151 * This function is used to send a high-priority XON/XOFF character to
1154 static void rs_8xx_send_xchar(struct tty_struct *tty, char ch)
1156 volatile cbd_t *bdp;
1158 ser_info_t *info = (ser_info_t *)tty->driver_data;
1160 if (serial_paranoia_check(info, tty->name, "rs_send_char"))
1164 while (bdp->cbd_sc & BD_SC_READY);
1166 *((char *)__va(bdp->cbd_bufaddr)) = ch;
1167 bdp->cbd_datlen = 1;
1168 bdp->cbd_sc |= BD_SC_READY;
1172 if (bdp->cbd_sc & BD_SC_WRAP)
1173 bdp = info->tx_bd_base;
1177 info->tx_cur = (cbd_t *)bdp;
1181 * ------------------------------------------------------------
1184 * This routine is called by the upper-layer tty layer to signal that
1185 * incoming characters should be throttled.
1186 * ------------------------------------------------------------
1188 static void rs_8xx_throttle(struct tty_struct * tty)
1190 ser_info_t *info = (ser_info_t *)tty->driver_data;
1191 #ifdef SERIAL_DEBUG_THROTTLE
1194 printk("throttle %s: %d....\n", _tty_name(tty, buf),
1195 tty->ldisc.chars_in_buffer(tty));
1198 if (serial_paranoia_check(info, tty->name, "rs_throttle"))
1202 rs_8xx_send_xchar(tty, STOP_CHAR(tty));
1204 #ifdef modem_control
1205 if (tty->termios->c_cflag & CRTSCTS)
1206 info->MCR &= ~UART_MCR_RTS;
1209 serial_out(info, UART_MCR, info->MCR);
1214 static void rs_8xx_unthrottle(struct tty_struct * tty)
1216 ser_info_t *info = (ser_info_t *)tty->driver_data;
1217 #ifdef SERIAL_DEBUG_THROTTLE
1220 printk("unthrottle %s: %d....\n", _tty_name(tty, buf),
1221 tty->ldisc.chars_in_buffer(tty));
1224 if (serial_paranoia_check(info, tty->name, "rs_unthrottle"))
1231 rs_8xx_send_xchar(tty, START_CHAR(tty));
1233 #ifdef modem_control
1234 if (tty->termios->c_cflag & CRTSCTS)
1235 info->MCR |= UART_MCR_RTS;
1237 serial_out(info, UART_MCR, info->MCR);
1243 * ------------------------------------------------------------
1244 * rs_ioctl() and friends
1245 * ------------------------------------------------------------
1250 * get_lsr_info - get line status register info
1252 * Purpose: Let user call ioctl() to get info when the UART physically
1253 * is emptied. On bus types like RS485, the transmitter must
1254 * release the bus after transmitting. This must be done when
1255 * the transmit shift register is empty, not be done when the
1256 * transmit holding register is empty. This functionality
1257 * allows an RS485 driver to be written in user space.
1259 static int get_lsr_info(struct async_struct * info, unsigned int *value)
1261 unsigned char status;
1262 unsigned int result;
1265 status = serial_in(info, UART_LSR);
1267 result = ((status & UART_LSR_TEMT) ? TIOCSER_TEMT : 0);
1268 return put_user(result,value);
1272 static int get_modem_info(ser_info_t *info, unsigned int *value)
1274 unsigned int result = 0;
1275 #ifdef modem_control
1276 unsigned char control, status;
1278 control = info->MCR;
1280 status = serial_in(info, UART_MSR);
1282 result = ((control & UART_MCR_RTS) ? TIOCM_RTS : 0)
1283 | ((control & UART_MCR_DTR) ? TIOCM_DTR : 0)
1285 | ((control & UART_MCR_OUT1) ? TIOCM_OUT1 : 0)
1286 | ((control & UART_MCR_OUT2) ? TIOCM_OUT2 : 0)
1288 | ((status & UART_MSR_DCD) ? TIOCM_CAR : 0)
1289 | ((status & UART_MSR_RI) ? TIOCM_RNG : 0)
1290 | ((status & UART_MSR_DSR) ? TIOCM_DSR : 0)
1291 | ((status & UART_MSR_CTS) ? TIOCM_CTS : 0);
1293 return put_user(result,value);
1296 static int set_modem_info(ser_info_t *info, unsigned int cmd,
1297 unsigned int *value)
1302 error = get_user(arg, value);
1305 #ifdef modem_control
1308 if (arg & TIOCM_RTS)
1309 info->MCR |= UART_MCR_RTS;
1310 if (arg & TIOCM_DTR)
1311 info->MCR |= UART_MCR_DTR;
1313 if (arg & TIOCM_OUT1)
1314 info->MCR |= UART_MCR_OUT1;
1315 if (arg & TIOCM_OUT2)
1316 info->MCR |= UART_MCR_OUT2;
1320 if (arg & TIOCM_RTS)
1321 info->MCR &= ~UART_MCR_RTS;
1322 if (arg & TIOCM_DTR)
1323 info->MCR &= ~UART_MCR_DTR;
1325 if (arg & TIOCM_OUT1)
1326 info->MCR &= ~UART_MCR_OUT1;
1327 if (arg & TIOCM_OUT2)
1328 info->MCR &= ~UART_MCR_OUT2;
1332 info->MCR = ((info->MCR & ~(UART_MCR_RTS |
1338 | ((arg & TIOCM_RTS) ? UART_MCR_RTS : 0)
1340 | ((arg & TIOCM_OUT1) ? UART_MCR_OUT1 : 0)
1341 | ((arg & TIOCM_OUT2) ? UART_MCR_OUT2 : 0)
1343 | ((arg & TIOCM_DTR) ? UART_MCR_DTR : 0));
1349 serial_out(info, UART_MCR, info->MCR);
1355 /* Sending a break is a two step process on the SMC/SCC. It is accomplished
1356 * by sending a STOP TRANSMIT command followed by a RESTART TRANSMIT
1357 * command. We take advantage of the begin/end functions to make this
1360 static void begin_break(ser_info_t *info)
1362 volatile cpm8260_t *cp;
1368 if ((num = info->state->smc_scc_num) < SCC_NUM_BASE) {
1370 page = CPM_CR_SMC1_PAGE;
1371 sblock = CPM_CR_SMC1_SBLOCK;
1374 page = CPM_CR_SMC2_PAGE;
1375 sblock = CPM_CR_SMC2_SBLOCK;
1379 num -= SCC_NUM_BASE;
1382 page = CPM_CR_SCC1_PAGE;
1383 sblock = CPM_CR_SCC1_SBLOCK;
1386 page = CPM_CR_SCC2_PAGE;
1387 sblock = CPM_CR_SCC2_SBLOCK;
1390 page = CPM_CR_SCC3_PAGE;
1391 sblock = CPM_CR_SCC3_SBLOCK;
1394 page = CPM_CR_SCC4_PAGE;
1395 sblock = CPM_CR_SCC4_SBLOCK;
1400 cp->cp_cpcr = mk_cr_cmd(page, sblock, 0, CPM_CR_STOP_TX) | CPM_CR_FLG;
1401 while (cp->cp_cpcr & CPM_CR_FLG);
1404 static void end_break(ser_info_t *info)
1406 volatile cpm8260_t *cp;
1412 if ((num = info->state->smc_scc_num) < SCC_NUM_BASE) {
1414 page = CPM_CR_SMC1_PAGE;
1415 sblock = CPM_CR_SMC1_SBLOCK;
1418 page = CPM_CR_SMC2_PAGE;
1419 sblock = CPM_CR_SMC2_SBLOCK;
1423 num -= SCC_NUM_BASE;
1426 page = CPM_CR_SCC1_PAGE;
1427 sblock = CPM_CR_SCC1_SBLOCK;
1430 page = CPM_CR_SCC2_PAGE;
1431 sblock = CPM_CR_SCC2_SBLOCK;
1434 page = CPM_CR_SCC3_PAGE;
1435 sblock = CPM_CR_SCC3_SBLOCK;
1438 page = CPM_CR_SCC4_PAGE;
1439 sblock = CPM_CR_SCC4_SBLOCK;
1444 cp->cp_cpcr = mk_cr_cmd(page, sblock, 0, CPM_CR_RESTART_TX) | CPM_CR_FLG;
1445 while (cp->cp_cpcr & CPM_CR_FLG);
1449 * This routine sends a break character out the serial port.
1451 static void send_break(ser_info_t *info, int duration)
1453 current->state = TASK_INTERRUPTIBLE;
1454 #ifdef SERIAL_DEBUG_SEND_BREAK
1455 printk("rs_send_break(%d) jiff=%lu...", duration, jiffies);
1458 schedule_timeout(duration);
1460 #ifdef SERIAL_DEBUG_SEND_BREAK
1461 printk("done jiffies=%lu\n", jiffies);
1466 static int rs_8xx_ioctl(struct tty_struct *tty, struct file * file,
1467 unsigned int cmd, unsigned long arg)
1470 ser_info_t *info = (ser_info_t *)tty->driver_data;
1472 struct async_icount cnow; /* kernel counter temps */
1473 struct serial_icounter_struct *p_cuser; /* user space */
1475 if (serial_paranoia_check(info, tty->name, "rs_ioctl"))
1478 if ((cmd != TIOCMIWAIT) && (cmd != TIOCGICOUNT)) {
1479 if (tty->flags & (1 << TTY_IO_ERROR))
1484 case TCSBRK: /* SVID version: non-zero arg --> no break */
1485 retval = tty_check_change(tty);
1488 tty_wait_until_sent(tty, 0);
1489 if (signal_pending(current))
1492 send_break(info, HZ/4); /* 1/4 second */
1493 if (signal_pending(current))
1497 case TCSBRKP: /* support for POSIX tcsendbreak() */
1498 retval = tty_check_change(tty);
1501 tty_wait_until_sent(tty, 0);
1502 if (signal_pending(current))
1504 send_break(info, arg ? arg*(HZ/10) : HZ/4);
1505 if (signal_pending(current))
1509 retval = tty_check_change(tty);
1512 tty_wait_until_sent(tty, 0);
1516 retval = tty_check_change(tty);
1522 return put_user(C_CLOCAL(tty) ? 1 : 0, (int *) arg);
1524 error = get_user(arg, (unsigned int *) arg);
1527 tty->termios->c_cflag =
1528 ((tty->termios->c_cflag & ~CLOCAL) |
1529 (arg ? CLOCAL : 0));
1532 return get_modem_info(info, (unsigned int *) arg);
1536 return set_modem_info(info, cmd, (unsigned int *) arg);
1538 case TIOCSERGETLSR: /* Get line status register */
1539 return get_lsr_info(info, (unsigned int *) arg);
1542 * Wait for any of the 4 modem inputs (DCD,RI,DSR,CTS) to change
1543 * - mask passed in arg for lines of interest
1544 * (use |'ed TIOCM_RNG/DSR/CD/CTS for masking)
1545 * Caller should use TIOCGICOUNT to see which one it was
1548 #ifdef modem_control
1550 /* note the counters on entry */
1551 cprev = info->state->icount;
1554 interruptible_sleep_on(&info->delta_msr_wait);
1555 /* see if a signal did it */
1556 if (signal_pending(current))
1557 return -ERESTARTSYS;
1559 cnow = info->state->icount; /* atomic copy */
1561 if (cnow.rng == cprev.rng && cnow.dsr == cprev.dsr &&
1562 cnow.dcd == cprev.dcd && cnow.cts == cprev.cts)
1563 return -EIO; /* no change => error */
1564 if ( ((arg & TIOCM_RNG) && (cnow.rng != cprev.rng)) ||
1565 ((arg & TIOCM_DSR) && (cnow.dsr != cprev.dsr)) ||
1566 ((arg & TIOCM_CD) && (cnow.dcd != cprev.dcd)) ||
1567 ((arg & TIOCM_CTS) && (cnow.cts != cprev.cts)) ) {
1578 * Get counter of input serial line interrupts (DCD,RI,DSR,CTS)
1579 * Return: write counters to the user passed counter struct
1580 * NB: both 1->0 and 0->1 transitions are counted except for
1581 * RI where only 0->1 is counted.
1585 cnow = info->state->icount;
1587 p_cuser = (struct serial_icounter_struct *) arg;
1588 error = put_user(cnow.cts, &p_cuser->cts);
1589 if (error) return error;
1590 error = put_user(cnow.dsr, &p_cuser->dsr);
1591 if (error) return error;
1592 error = put_user(cnow.rng, &p_cuser->rng);
1593 if (error) return error;
1594 error = put_user(cnow.dcd, &p_cuser->dcd);
1595 if (error) return error;
1599 return -ENOIOCTLCMD;
1604 /* FIX UP modem control here someday......
1606 static void rs_8xx_set_termios(struct tty_struct *tty, struct termios *old_termios)
1608 ser_info_t *info = (ser_info_t *)tty->driver_data;
1610 if ( (tty->termios->c_cflag == old_termios->c_cflag)
1611 && ( RELEVANT_IFLAG(tty->termios->c_iflag)
1612 == RELEVANT_IFLAG(old_termios->c_iflag)))
1617 #ifdef modem_control
1618 /* Handle transition to B0 status */
1619 if ((old_termios->c_cflag & CBAUD) &&
1620 !(tty->termios->c_cflag & CBAUD)) {
1621 info->MCR &= ~(UART_MCR_DTR|UART_MCR_RTS);
1623 serial_out(info, UART_MCR, info->MCR);
1627 /* Handle transition away from B0 status */
1628 if (!(old_termios->c_cflag & CBAUD) &&
1629 (tty->termios->c_cflag & CBAUD)) {
1630 info->MCR |= UART_MCR_DTR;
1631 if (!tty->hw_stopped ||
1632 !(tty->termios->c_cflag & CRTSCTS)) {
1633 info->MCR |= UART_MCR_RTS;
1636 serial_out(info, UART_MCR, info->MCR);
1640 /* Handle turning off CRTSCTS */
1641 if ((old_termios->c_cflag & CRTSCTS) &&
1642 !(tty->termios->c_cflag & CRTSCTS)) {
1643 tty->hw_stopped = 0;
1650 * No need to wake up processes in open wait, since they
1651 * sample the CLOCAL flag once, and don't recheck it.
1652 * XXX It's not clear whether the current behavior is correct
1653 * or not. Hence, this may change.....
1655 if (!(old_termios->c_cflag & CLOCAL) &&
1656 (tty->termios->c_cflag & CLOCAL))
1657 wake_up_interruptible(&info->open_wait);
1662 * ------------------------------------------------------------
1665 * This routine is called when the serial port gets closed. First, we
1666 * wait for the last remaining data to be sent. Then, we unlink its
1667 * async structure from the interrupt chain if necessary, and we free
1668 * that IRQ if nothing is left in the chain.
1669 * ------------------------------------------------------------
1671 static void rs_8xx_close(struct tty_struct *tty, struct file * filp)
1673 ser_info_t *info = (ser_info_t *)tty->driver_data;
1674 struct serial_state *state;
1675 unsigned long flags;
1677 volatile smc_t *smcp;
1678 volatile scc_t *sccp;
1680 if (!info || serial_paranoia_check(info, tty->name, "rs_close"))
1683 state = info->state;
1685 save_flags(flags); cli();
1687 if (tty_hung_up_p(filp)) {
1688 DBG_CNT("before DEC-hung");
1689 restore_flags(flags);
1693 #ifdef SERIAL_DEBUG_OPEN
1694 printk("rs_close ttys%d, count = %d\n", info->line, state->count);
1696 if ((tty->count == 1) && (state->count != 1)) {
1698 * Uh, oh. tty->count is 1, which means that the tty
1699 * structure will be freed. state->count should always
1700 * be one in these conditions. If it's greater than
1701 * one, we've got real problems, since it means the
1702 * serial port won't be shutdown.
1704 printk("rs_close: bad serial port count; tty->count is 1, "
1705 "state->count is %d\n", state->count);
1708 if (--state->count < 0) {
1709 printk("rs_close: bad serial port count for ttys%d: %d\n",
1710 info->line, state->count);
1714 DBG_CNT("before DEC-2");
1715 restore_flags(flags);
1718 info->flags |= ASYNC_CLOSING;
1720 * Now we wait for the transmit buffer to clear; and we notify
1721 * the line discipline to only process XON/XOFF characters.
1724 if (info->closing_wait != ASYNC_CLOSING_WAIT_NONE)
1725 tty_wait_until_sent(tty, info->closing_wait);
1727 * At this point we stop accepting input. To do this, we
1728 * disable the receive line status interrupts, and tell the
1729 * interrupt driver to stop checking the data ready bit in the
1730 * line status register.
1732 info->read_status_mask &= ~BD_SC_EMPTY;
1733 if (info->flags & ASYNC_INITIALIZED) {
1734 if ((idx = info->state->smc_scc_num) < SCC_NUM_BASE) {
1735 smcp = &immr->im_smc[idx];
1736 smcp->smc_smcm &= ~SMCM_RX;
1737 smcp->smc_smcmr &= ~SMCMR_REN;
1740 sccp = &immr->im_scc[idx - SCC_IDX_BASE];
1741 sccp->scc_sccm &= ~UART_SCCM_RX;
1742 sccp->scc_gsmrl &= ~SCC_GSMRL_ENR;
1745 * Before we drop DTR, make sure the UART transmitter
1746 * has completely drained; this is especially
1747 * important if there is a transmit FIFO!
1749 rs_8xx_wait_until_sent(tty, info->timeout);
1752 if (tty->driver->flush_buffer)
1753 tty->driver->flush_buffer(tty);
1754 if (tty->ldisc.flush_buffer)
1755 tty->ldisc.flush_buffer(tty);
1759 if (info->blocked_open) {
1760 if (info->close_delay) {
1761 current->state = TASK_INTERRUPTIBLE;
1762 schedule_timeout(info->close_delay);
1764 wake_up_interruptible(&info->open_wait);
1766 info->flags &= ~(ASYNC_NORMAL_ACTIVE|ASYNC_CLOSING);
1767 wake_up_interruptible(&info->close_wait);
1768 restore_flags(flags);
1772 * rs_wait_until_sent() --- wait until the transmitter is empty
1774 static void rs_8xx_wait_until_sent(struct tty_struct *tty, int timeout)
1776 ser_info_t *info = (ser_info_t *)tty->driver_data;
1777 unsigned long orig_jiffies, char_time;
1779 volatile cbd_t *bdp;
1781 if (serial_paranoia_check(info, tty->name, "rs_wait_until_sent"))
1785 if (info->state->type == PORT_UNKNOWN)
1789 orig_jiffies = jiffies;
1791 * Set the check interval to be 1/5 of the estimated time to
1792 * send a single character, and make it at least 1. The check
1793 * interval should also be less than the timeout.
1795 * Note: we have to use pretty tight timings here to satisfy
1800 char_time = min(char_time, (unsigned long)timeout);
1801 #ifdef SERIAL_DEBUG_RS_WAIT_UNTIL_SENT
1802 printk("In rs_wait_until_sent(%d) check=%lu...", timeout, char_time);
1803 printk("jiff=%lu...", jiffies);
1806 /* We go through the loop at least once because we can't tell
1807 * exactly when the last character exits the shifter. There can
1808 * be at least two characters waiting to be sent after the buffers
1812 #ifdef SERIAL_DEBUG_RS_WAIT_UNTIL_SENT
1813 printk("lsr = %d (jiff=%lu)...", lsr, jiffies);
1815 current->state = TASK_INTERRUPTIBLE;
1816 /* current->dyn_prio = 0; make us low-priority */
1817 schedule_timeout(char_time);
1818 if (signal_pending(current))
1820 if (timeout && time_after(jiffies, orig_jiffies + timeout))
1823 } while (bdp->cbd_sc & BD_SC_READY);
1824 current->state = TASK_RUNNING;
1825 #ifdef SERIAL_DEBUG_RS_WAIT_UNTIL_SENT
1826 printk("lsr = %d (jiff=%lu)...done\n", lsr, jiffies);
1831 * rs_hangup() --- called by tty_hangup() when a hangup is signaled.
1833 static void rs_8xx_hangup(struct tty_struct *tty)
1835 ser_info_t *info = (ser_info_t *)tty->driver_data;
1836 struct serial_state *state = info->state;
1838 if (serial_paranoia_check(info, tty->name, "rs_hangup"))
1841 state = info->state;
1843 rs_8xx_flush_buffer(tty);
1847 info->flags &= ~ASYNC_NORMAL_ACTIVE;
1849 wake_up_interruptible(&info->open_wait);
1853 * ------------------------------------------------------------
1854 * rs_open() and friends
1855 * ------------------------------------------------------------
1857 static int block_til_ready(struct tty_struct *tty, struct file * filp,
1860 #ifdef DO_THIS_LATER
1861 DECLARE_WAITQUEUE(wait, current);
1862 struct serial_state *state = info->state;
1868 * If the device is in the middle of being closed, then block
1869 * until it's done, and then try again.
1871 if (tty_hung_up_p(filp) ||
1872 (info->flags & ASYNC_CLOSING)) {
1873 if (info->flags & ASYNC_CLOSING)
1874 interruptible_sleep_on(&info->close_wait);
1875 #ifdef SERIAL_DO_RESTART
1876 if (info->flags & ASYNC_HUP_NOTIFY)
1879 return -ERESTARTSYS;
1886 * If non-blocking mode is set, or the port is not enabled,
1887 * then make the check up front and then exit.
1888 * If this is an SMC port, we don't have modem control to wait
1889 * for, so just get out here.
1891 if ((filp->f_flags & O_NONBLOCK) ||
1892 (tty->flags & (1 << TTY_IO_ERROR)) ||
1893 (info->state->smc_scc_num < SCC_NUM_BASE)) {
1894 info->flags |= ASYNC_NORMAL_ACTIVE;
1898 if (tty->termios->c_cflag & CLOCAL)
1902 * Block waiting for the carrier detect and the line to become
1903 * free (i.e., not in use by the callout). While we are in
1904 * this loop, state->count is dropped by one, so that
1905 * rs_close() knows when to free things. We restore it upon
1906 * exit, either normal or abnormal.
1909 #ifdef DO_THIS_LATER
1910 add_wait_queue(&info->open_wait, &wait);
1911 #ifdef SERIAL_DEBUG_OPEN
1912 printk("block_til_ready before block: ttys%d, count = %d\n",
1913 state->line, state->count);
1916 if (!tty_hung_up_p(filp))
1919 info->blocked_open++;
1922 if (tty->termios->c_cflag & CBAUD)
1923 serial_out(info, UART_MCR,
1924 serial_inp(info, UART_MCR) |
1925 (UART_MCR_DTR | UART_MCR_RTS));
1927 set_current_state(TASK_INTERRUPTIBLE);
1928 if (tty_hung_up_p(filp) ||
1929 !(info->flags & ASYNC_INITIALIZED)) {
1930 #ifdef SERIAL_DO_RESTART
1931 if (info->flags & ASYNC_HUP_NOTIFY)
1934 retval = -ERESTARTSYS;
1940 if (!(info->flags & ASYNC_CLOSING) &&
1941 (do_clocal || (serial_in(info, UART_MSR) &
1944 if (signal_pending(current)) {
1945 retval = -ERESTARTSYS;
1948 #ifdef SERIAL_DEBUG_OPEN
1949 printk("block_til_ready blocking: ttys%d, count = %d\n",
1950 info->line, state->count);
1954 current->state = TASK_RUNNING;
1955 remove_wait_queue(&info->open_wait, &wait);
1956 if (!tty_hung_up_p(filp))
1958 info->blocked_open--;
1959 #ifdef SERIAL_DEBUG_OPEN
1960 printk("block_til_ready after blocking: ttys%d, count = %d\n",
1961 info->line, state->count);
1963 #endif /* DO_THIS_LATER */
1966 info->flags |= ASYNC_NORMAL_ACTIVE;
1970 static int get_async_struct(int line, ser_info_t **ret_info)
1972 struct serial_state *sstate;
1974 sstate = rs_table + line;
1977 *ret_info = (ser_info_t *)sstate->info;
1986 * This routine is called whenever a serial port is opened. It
1987 * enables interrupts for a serial port, linking in its async structure into
1988 * the IRQ chain. It also performs the serial-specific
1989 * initialization for the tty structure.
1991 static int rs_8xx_open(struct tty_struct *tty, struct file * filp)
1997 if ((line < 0) || (line >= NR_PORTS))
1999 retval = get_async_struct(line, &info);
2002 if (serial_paranoia_check(info, tty->name, "rs_open"))
2005 #ifdef SERIAL_DEBUG_OPEN
2006 printk("rs_open %s, count = %d\n", tty->name, info->state->count);
2008 tty->driver_data = info;
2012 * Start up serial port
2014 retval = startup(info);
2018 retval = block_til_ready(tty, filp, info);
2020 #ifdef SERIAL_DEBUG_OPEN
2021 printk("rs_open returning after block_til_ready with %d\n",
2027 #ifdef SERIAL_DEBUG_OPEN
2028 printk("rs_open %s successful...", line);
2034 * /proc fs routines....
2037 static inline int line_info(char *buf, struct serial_state *state)
2040 struct async_struct *info = state->info, scr_info;
2041 char stat_buf[30], control, status;
2045 ret = sprintf(buf, "%d: uart:%s port:%X irq:%d",
2047 (state->smc_scc_num < SCC_NUM_BASE) ? "SMC" : "SCC",
2048 (unsigned int)(state->port), state->irq);
2050 if (!state->port || (state->type == PORT_UNKNOWN)) {
2051 ret += sprintf(buf+ret, "\n");
2057 * Figure out the current RS-232 lines
2060 info = &scr_info; /* This is just for serial_{in,out} */
2062 info->magic = SERIAL_MAGIC;
2063 info->port = state->port;
2064 info->flags = state->flags;
2069 status = serial_in(info, UART_MSR);
2070 control = info ? info->MCR : serial_in(info, UART_MCR);
2075 if (control & UART_MCR_RTS)
2076 strcat(stat_buf, "|RTS");
2077 if (status & UART_MSR_CTS)
2078 strcat(stat_buf, "|CTS");
2079 if (control & UART_MCR_DTR)
2080 strcat(stat_buf, "|DTR");
2081 if (status & UART_MSR_DSR)
2082 strcat(stat_buf, "|DSR");
2083 if (status & UART_MSR_DCD)
2084 strcat(stat_buf, "|CD");
2085 if (status & UART_MSR_RI)
2086 strcat(stat_buf, "|RI");
2089 ret += sprintf(buf+ret, " baud:%d",
2090 state->baud_base / info->quot);
2093 ret += sprintf(buf+ret, " tx:%d rx:%d",
2094 state->icount.tx, state->icount.rx);
2096 if (state->icount.frame)
2097 ret += sprintf(buf+ret, " fe:%d", state->icount.frame);
2099 if (state->icount.parity)
2100 ret += sprintf(buf+ret, " pe:%d", state->icount.parity);
2102 if (state->icount.brk)
2103 ret += sprintf(buf+ret, " brk:%d", state->icount.brk);
2105 if (state->icount.overrun)
2106 ret += sprintf(buf+ret, " oe:%d", state->icount.overrun);
2109 * Last thing is the RS-232 status lines
2111 ret += sprintf(buf+ret, " %s\n", stat_buf+1);
2116 int rs_8xx_read_proc(char *page, char **start, off_t off, int count,
2117 int *eof, void *data)
2122 len += sprintf(page, "serinfo:1.0 driver:%s\n", serial_version);
2123 for (i = 0; i < NR_PORTS && len < 4000; i++) {
2124 len += line_info(page + len, &rs_table[i]);
2125 if (len+begin > off+count)
2127 if (len+begin < off) {
2134 if (off >= len+begin)
2136 *start = page + (begin-off);
2137 return ((count < begin+len-off) ? count : begin+len-off);
2141 * ---------------------------------------------------------------------
2142 * rs_init() and friends
2144 * rs_init() is called at boot-time to initialize the serial driver.
2145 * ---------------------------------------------------------------------
2149 * This routine prints out the appropriate serial driver version
2150 * number, and identifies which options were configured into this
2153 static _INLINE_ void show_serial_version(void)
2155 printk(KERN_INFO "%s version %s\n", serial_name, serial_version);
2160 * The serial console driver used during boot. Note that these names
2161 * clash with those found in "serial.c", so we currently can't support
2162 * the 16xxx uarts and these at the same time. I will fix this to become
2163 * an indirect function call from tty_io.c (or something).
2166 #ifdef CONFIG_SERIAL_CONSOLE
2169 * Print a string to the serial port trying not to disturb any possible
2170 * real use of the port...
2171 * These funcitons work equally well for SCC, even though they are
2172 * designed for SMC. Our only interests are the transmit/receive
2173 * buffers, which are identically mapped for either the SCC or SMC.
2175 static void my_console_write(int idx, const char *s,
2178 struct serial_state *ser;
2181 volatile cbd_t *bdp, *bdbase;
2182 volatile smc_uart_t *up;
2183 volatile u_char *cp;
2185 ser = rs_table + idx;
2187 /* If the port has been initialized for general use, we have
2188 * to use the buffer descriptors allocated there. Otherwise,
2189 * we simply use the single buffer allocated.
2191 if ((info = (ser_info_t *)ser->info) != NULL) {
2193 bdbase = info->tx_bd_base;
2196 /* Pointer to UART in parameter ram.
2198 up = (smc_uart_t *)&immr->im_dprambase[ser->port];
2200 /* Get the address of the host memory buffer.
2202 bdp = bdbase = (cbd_t *)&immr->im_dprambase[up->smc_tbase];
2206 * We need to gracefully shut down the transmitter, disable
2207 * interrupts, then send our bytes out.
2211 * Now, do each character. This is not as bad as it looks
2212 * since this is a holding FIFO and not a transmitting FIFO.
2213 * We could add the complexity of filling the entire transmit
2214 * buffer, but we would just wait longer between accesses......
2216 for (i = 0; i < count; i++, s++) {
2217 /* Wait for transmitter fifo to empty.
2218 * Ready indicates output is ready, and xmt is doing
2219 * that, not that it is ready for us to send.
2221 while (bdp->cbd_sc & BD_SC_READY);
2223 /* Send the character out.
2224 * If the buffer address is in the CPM DPRAM, don't
2227 if ((uint)(bdp->cbd_bufaddr) > (uint)IMAP_ADDR)
2228 cp = (u_char *)(bdp->cbd_bufaddr);
2230 cp = __va(bdp->cbd_bufaddr);
2233 bdp->cbd_datlen = 1;
2234 bdp->cbd_sc |= BD_SC_READY;
2236 if (bdp->cbd_sc & BD_SC_WRAP)
2241 /* if a LF, also do CR... */
2243 while (bdp->cbd_sc & BD_SC_READY);
2244 cp = __va(bdp->cbd_bufaddr);
2246 bdp->cbd_datlen = 1;
2247 bdp->cbd_sc |= BD_SC_READY;
2249 if (bdp->cbd_sc & BD_SC_WRAP) {
2259 * Finally, Wait for transmitter & holding register to empty
2260 * and restore the IER
2262 while (bdp->cbd_sc & BD_SC_READY);
2265 info->tx_cur = (cbd_t *)bdp;
2268 static void serial_console_write(struct console *c, const char *s,
2271 #if defined(CONFIG_KGDB_CONSOLE) && !defined(CONFIG_USE_SERIAL2_KGDB)
2272 /* Try to let stub handle output. Returns true if it did. */
2273 if (kgdb_output_string(s, count))
2276 my_console_write(c->index, s, count);
2281 xmon_8xx_write(const char *s, unsigned count)
2283 my_console_write(KGDB_SER_IDX, s, count);
2290 putDebugChar(char ch)
2292 my_console_write(KGDB_SER_IDX, &ch, 1);
2296 #if defined(CONFIG_XMON) || defined(CONFIG_KGDB)
2298 * Receive character from the serial port. This only works well
2299 * before the port is initialize for real use.
2301 static int my_console_wait_key(int idx, int xmon, char *obuf)
2303 struct serial_state *ser;
2306 volatile cbd_t *bdp;
2307 volatile smc_uart_t *up;
2310 ser = rs_table + idx;
2312 /* Pointer to UART in parameter ram.
2314 up = (smc_uart_t *)&immr->im_dprambase[ser->port];
2316 /* Get the address of the host memory buffer.
2317 * If the port has been initialized for general use, we must
2318 * use information from the port structure.
2320 if ((info = (ser_info_t *)ser->info))
2323 bdp = (cbd_t *)&immr->im_dprambase[up->smc_rbase];
2326 * We need to gracefully shut down the receiver, disable
2327 * interrupts, then read the input.
2328 * XMON just wants a poll. If no character, return -1, else
2329 * return the character.
2332 while (bdp->cbd_sc & BD_SC_EMPTY);
2335 if (bdp->cbd_sc & BD_SC_EMPTY)
2339 /* If the buffer address is in the CPM DPRAM, don't
2342 if ((uint)(bdp->cbd_bufaddr) > (uint)IMAP_ADDR)
2343 cp = (u_char *)(bdp->cbd_bufaddr);
2345 cp = __va(bdp->cbd_bufaddr);
2348 i = c = bdp->cbd_datlen;
2355 bdp->cbd_sc |= BD_SC_EMPTY;
2358 if (bdp->cbd_sc & BD_SC_WRAP) {
2359 bdp = info->rx_bd_base;
2364 info->rx_cur = (cbd_t *)bdp;
2369 #endif /* CONFIG_XMON || CONFIG_KGDB */
2373 xmon_8xx_read_poll(void)
2375 return(my_console_wait_key(KGDB_SER_IDX, 1, NULL));
2379 xmon_8xx_read_char(void)
2381 return(my_console_wait_key(KGDB_SER_IDX, 0, NULL));
2386 static char kgdb_buf[RX_BUF_SIZE], *kgdp;
2387 static int kgdb_chars;
2392 if (kgdb_chars <= 0) {
2393 kgdb_chars = my_console_wait_key(KGDB_SER_IDX, 0, kgdb_buf);
2401 void kgdb_interruptible(int yes)
2403 volatile smc_t *smcp;
2405 smcp = &immr->im_smc[KGDB_SER_IDX];
2408 smcp->smc_smcm |= SMCM_RX;
2410 smcp->smc_smcm &= ~SMCM_RX;
2413 void kgdb_map_scc(void)
2417 volatile cbd_t *bdp;
2418 volatile smc_uart_t *up;
2420 /* The serial port has already been initialized before
2421 * we get here. We have to assign some pointers needed by
2422 * the kernel, and grab a memory location in the CPM that will
2423 * work until the driver is really initialized.
2425 immr = (immap_t *)IMAP_ADDR;
2427 /* Right now, assume we are using SMCs.
2429 #ifdef USE_KGDB_SMC2
2430 *(ushort *)(&immr->im_dprambase[PROFF_SMC2_BASE]) = serbase = PROFF_SMC2;
2432 *(ushort *)(&immr->im_dprambase[PROFF_SMC1_BASE]) = serbase = PROFF_SMC1;
2434 up = (smc_uart_t *)&immr->im_dprambase[serbase];
2436 /* Allocate space for an input FIFO, plus a few bytes for output.
2437 * Allocate bytes to maintain word alignment.
2439 mem_addr = (uint)(&immr->im_dprambase[0x1000]);
2441 /* Set the physical address of the host memory buffers in
2442 * the buffer descriptors.
2444 bdp = (cbd_t *)&immr->im_dprambase[up->smc_rbase];
2445 bdp->cbd_bufaddr = mem_addr;
2447 bdp = (cbd_t *)&immr->im_dprambase[up->smc_tbase];
2448 bdp->cbd_bufaddr = mem_addr+RX_BUF_SIZE;
2450 up->smc_mrblr = RX_BUF_SIZE; /* receive buffer length */
2451 up->smc_maxidl = RX_BUF_SIZE;
2455 static struct tty_driver *serial_console_device(struct console *c, int *index)
2458 return serial_driver;
2464 static int __init console_8xx_init(void)
2466 register_console(&sercons);
2470 console_initcall(console_8xx_init);
2474 /* Default console baud rate as determined by the board information
2477 static int baud_idx;
2479 static struct tty_operations rs_8xx_ops = {
2480 .open = rs_8xx_open,
2481 .close = rs_8xx_close,
2482 .write = rs_8xx_write,
2483 .put_char = rs_8xx_put_char,
2484 .write_room = rs_8xx_write_room,
2485 .chars_in_buffer = rs_8xx_chars_in_buffer,
2486 .flush_buffer = rs_8xx_flush_buffer,
2487 .ioctl = rs_8xx_ioctl,
2488 .throttle = rs_8xx_throttle,
2489 .unthrottle = rs_8xx_unthrottle,
2490 .send_xchar = rs_8xx_send_xchar,
2491 .set_termios = rs_8xx_set_termios,
2492 .stop = rs_8xx_stop,
2493 .start = rs_8xx_start,
2494 .hangup = rs_8xx_hangup,
2495 .wait_until_sent = rs_8xx_wait_until_sent,
2496 .read_proc = rs_8xx_read_proc,
2500 * The serial driver boot-time initialization code!
2502 static int __init rs_8xx_init(void)
2504 struct serial_state * state;
2506 uint mem_addr, dp_addr;
2509 volatile cbd_t *bdp;
2510 volatile cpm8260_t *cp;
2512 volatile smc_uart_t *up;
2513 volatile scc_t *scp;
2514 volatile scc_uart_t *sup;
2515 volatile immap_t *immap;
2516 volatile iop8260_t *io;
2518 serial_driver = alloc_tty_driver(NR_PORTS);
2522 show_serial_version();
2524 /* Initialize the tty_driver structure */
2526 serial_driver->owner = THIS_MODULE;
2527 serial_driver->driver_name = "serial";
2528 serial_driver->devfs_name = "tts/";
2529 serial_driver->name = "ttyS";
2530 serial_driver->major = TTY_MAJOR;
2531 serial_driver->minor_start = 64;
2532 serial_driver->type = TTY_DRIVER_TYPE_SERIAL;
2533 serial_driver->subtype = SERIAL_TYPE_NORMAL;
2534 serial_driver->init_termios = tty_std_termios;
2535 serial_driver->init_termios.c_cflag =
2536 baud_idx | CS8 | CREAD | HUPCL | CLOCAL;
2537 serial_driver->flags = TTY_DRIVER_REAL_RAW;
2538 tty_set_operations(serial_driver, &rs_8xx_ops);
2539 if (tty_register_driver(serial_driver))
2540 panic("Couldn't register serial driver\n");
2543 cp = &immap->im_cpm;
2544 io = &immap->im_ioport;
2546 /* This should have been done long ago by the early boot code,
2547 * but do it again to make sure.
2549 *(ushort *)(&immap->im_dprambase[PROFF_SMC1_BASE]) = PROFF_SMC1;
2550 *(ushort *)(&immap->im_dprambase[PROFF_SMC2_BASE]) = PROFF_SMC2;
2552 /* Geeze, here we go....Picking I/O port bits....Lots of
2553 * choices. If you don't like mine, pick your own.
2554 * Configure SMCs Tx/Rx. SMC1 is only on Port D, SMC2 is
2555 * only on Port A. You either pick 'em, or not.
2558 io->iop_ppard |= 0x00c00000;
2559 io->iop_pdird |= 0x00400000;
2560 io->iop_pdird &= ~0x00800000;
2561 io->iop_psord &= ~0x00c00000;
2563 io->iop_ppara |= 0x00c00000;
2564 io->iop_pdira |= 0x00400000;
2565 io->iop_pdira &= ~0x00800000;
2566 io->iop_psora &= ~0x00c00000;
2569 /* Configure SCC2 and SCC3. Be careful about the fine print.
2570 * Secondary options are only available when you take away
2571 * the primary option. Unless the pins are used for something
2572 * else, SCC2 and SCC3 are on Port B.
2573 * Port B, 8 - SCC3 TxD
2574 * Port B, 12 - SCC2 TxD
2575 * Port B, 14 - SCC3 RxD
2576 * Port B, 15 - SCC2 RxD
2578 io->iop_pparb |= 0x008b0000;
2579 io->iop_pdirb |= 0x00880000;
2580 io->iop_psorb |= 0x00880000;
2581 io->iop_pdirb &= ~0x00030000;
2582 io->iop_psorb &= ~0x00030000;
2584 /* Wire BRG1 to SMC1 and BRG2 to SMC2.
2586 immap->im_cpmux.cmx_smr = 0;
2588 /* Connect SCC2 and SCC3 to NMSI. Connect BRG3 to SCC2 and
2591 immap->im_cpmux.cmx_scr &= ~0x00ffff00;
2592 immap->im_cpmux.cmx_scr |= 0x00121b00;
2594 io->iop_pparb |= 0x008b0000;
2595 io->iop_pdirb |= 0x00880000;
2596 io->iop_psorb |= 0x00880000;
2597 io->iop_pdirb &= ~0x00030000;
2598 io->iop_psorb &= ~0x00030000;
2600 /* Use Port D for SCC1 instead of other functions.
2602 io->iop_ppard |= 0x00000003;
2603 io->iop_psord &= ~0x00000001; /* Rx */
2604 io->iop_psord |= 0x00000002; /* Tx */
2605 io->iop_pdird &= ~0x00000001; /* Rx */
2606 io->iop_pdird |= 0x00000002; /* Tx */
2608 /* Connect SCC1, SCC2, SCC3 to NMSI. Connect BRG1 to SCC1,
2609 * BRG2 to SCC2, BRG3 to SCC3.
2611 immap->im_cpmux.cmx_scr &= ~0xffffff00;
2612 immap->im_cpmux.cmx_scr |= 0x00091200;
2615 for (i = 0, state = rs_table; i < NR_PORTS; i++,state++) {
2616 state->magic = SSTATE_MAGIC;
2618 state->type = PORT_UNKNOWN;
2619 state->custom_divisor = 0;
2620 state->close_delay = 5*HZ/10;
2621 state->closing_wait = 30*HZ;
2622 state->icount.cts = state->icount.dsr =
2623 state->icount.rng = state->icount.dcd = 0;
2624 state->icount.rx = state->icount.tx = 0;
2625 state->icount.frame = state->icount.parity = 0;
2626 state->icount.overrun = state->icount.brk = 0;
2627 printk (KERN_INFO "ttyS%d on %s%d at 0x%04x, BRG%d\n",
2629 (state->smc_scc_num < SCC_NUM_BASE) ? "SMC" : "SCC",
2630 PORT_NUM(state->smc_scc_num) + 1,
2631 (unsigned int)(state->port),
2632 state->smc_scc_num + 1);
2633 #ifdef CONFIG_SERIAL_CONSOLE
2634 /* If we just printed the message on the console port, and
2635 * we are about to initialize it for general use, we have
2636 * to wait a couple of character times for the CR/NL to
2637 * make it out of the transmit buffer.
2639 if (i == CONFIG_SERIAL_CONSOLE_PORT)
2642 info = kmalloc(sizeof(ser_info_t), GFP_KERNEL);
2644 /*memset(info, 0, sizeof(ser_info_t));*/
2645 __clear_user(info,sizeof(ser_info_t));
2646 init_waitqueue_head(&info->open_wait);
2647 init_waitqueue_head(&info->close_wait);
2648 info->magic = SERIAL_MAGIC;
2649 info->flags = state->flags;
2650 INIT_WORK(&info->tqueue, do_softint, info);
2651 INIT_WORK(&info->tqueue_hangup, do_serial_hangup, info);
2653 info->state = state;
2654 state->info = (struct async_struct *)info;
2656 /* We need to allocate a transmit and receive buffer
2657 * descriptors from dual port ram, and a character
2658 * buffer area from host mem.
2660 dp_addr = m8260_cpm_dpalloc(sizeof(cbd_t) * RX_NUM_FIFO, 8);
2662 /* Allocate space for FIFOs in the host memory.
2664 mem_addr = m8260_cpm_hostalloc(RX_NUM_FIFO * RX_BUF_SIZE, 1);
2666 /* Set the physical address of the host memory
2667 * buffers in the buffer descriptors, and the
2668 * virtual address for us to work with.
2670 bdp = (cbd_t *)&immap->im_dprambase[dp_addr];
2671 info->rx_cur = info->rx_bd_base = (cbd_t *)bdp;
2673 for (j=0; j<(RX_NUM_FIFO-1); j++) {
2674 bdp->cbd_bufaddr = __pa(mem_addr);
2675 bdp->cbd_sc = BD_SC_EMPTY | BD_SC_INTRPT;
2676 mem_addr += RX_BUF_SIZE;
2679 bdp->cbd_bufaddr = __pa(mem_addr);
2680 bdp->cbd_sc = BD_SC_WRAP | BD_SC_EMPTY | BD_SC_INTRPT;
2682 if ((idx = state->smc_scc_num) < SCC_NUM_BASE) {
2683 sp = &immap->im_smc[idx];
2684 up = (smc_uart_t *)&immap->im_dprambase[state->port];
2685 up->smc_rbase = dp_addr;
2688 scp = &immap->im_scc[idx - SCC_IDX_BASE];
2689 sup = (scc_uart_t *)&immap->im_dprambase[state->port];
2690 scp->scc_gsmrl &= ~(SCC_GSMRL_ENR | SCC_GSMRL_ENT);
2691 sup->scc_genscc.scc_rbase = dp_addr;
2694 dp_addr = m8260_cpm_dpalloc(sizeof(cbd_t) * TX_NUM_FIFO, 8);
2696 /* Allocate space for FIFOs in the host memory.
2698 mem_addr = m8260_cpm_hostalloc(TX_NUM_FIFO * TX_BUF_SIZE, 1);
2700 /* Set the physical address of the host memory
2701 * buffers in the buffer descriptors, and the
2702 * virtual address for us to work with.
2704 bdp = (cbd_t *)&immap->im_dprambase[dp_addr];
2705 info->tx_cur = info->tx_bd_base = (cbd_t *)bdp;
2707 for (j=0; j<(TX_NUM_FIFO-1); j++) {
2708 bdp->cbd_bufaddr = __pa(mem_addr);
2709 bdp->cbd_sc = BD_SC_INTRPT;
2710 mem_addr += TX_BUF_SIZE;
2713 bdp->cbd_bufaddr = __pa(mem_addr);
2714 bdp->cbd_sc = (BD_SC_WRAP | BD_SC_INTRPT);
2716 if (idx < SCC_NUM_BASE) {
2717 up->smc_tbase = dp_addr;
2719 /* Set up the uart parameters in the
2722 up->smc_rfcr = CPMFCR_GBL | CPMFCR_EB;
2723 up->smc_tfcr = CPMFCR_GBL | CPMFCR_EB;
2725 /* Set this to 1 for now, so we get single
2726 * character interrupts. Using idle charater
2727 * time requires some additional tuning.
2733 /* Send the CPM an initialize command.
2735 if (state->smc_scc_num == 0) {
2736 page = CPM_CR_SMC1_PAGE;
2737 sblock = CPM_CR_SMC1_SBLOCK;
2740 page = CPM_CR_SMC2_PAGE;
2741 sblock = CPM_CR_SMC2_SBLOCK;
2744 cp->cp_cpcr = mk_cr_cmd(page, sblock, 0,
2745 CPM_CR_INIT_TRX) | CPM_CR_FLG;
2746 while (cp->cp_cpcr & CPM_CR_FLG);
2748 /* Set UART mode, 8 bit, no parity, one stop.
2749 * Enable receive and transmit.
2751 sp->smc_smcmr = smcr_mk_clen(9) | SMCMR_SM_UART;
2753 /* Disable all interrupts and clear all pending
2757 sp->smc_smce = 0xff;
2760 sup->scc_genscc.scc_tbase = dp_addr;
2762 /* Set up the uart parameters in the
2765 sup->scc_genscc.scc_rfcr = CPMFCR_GBL | CPMFCR_EB;
2766 sup->scc_genscc.scc_tfcr = CPMFCR_GBL | CPMFCR_EB;
2768 /* Set this to 1 for now, so we get single
2769 * character interrupts. Using idle charater
2770 * time requires some additional tuning.
2772 sup->scc_genscc.scc_mrblr = 1;
2773 sup->scc_maxidl = 0;
2779 sup->scc_uaddr1 = 0;
2780 sup->scc_uaddr2 = 0;
2782 sup->scc_char1 = 0x8000;
2783 sup->scc_char2 = 0x8000;
2784 sup->scc_char3 = 0x8000;
2785 sup->scc_char4 = 0x8000;
2786 sup->scc_char5 = 0x8000;
2787 sup->scc_char6 = 0x8000;
2788 sup->scc_char7 = 0x8000;
2789 sup->scc_char8 = 0x8000;
2790 sup->scc_rccm = 0xc0ff;
2792 /* Send the CPM an initialize command.
2795 switch (state->smc_scc_num) {
2797 page = CPM_CR_SCC1_PAGE;
2798 sblock = CPM_CR_SCC1_SBLOCK;
2801 page = CPM_CR_SCC2_PAGE;
2802 sblock = CPM_CR_SCC2_SBLOCK;
2805 page = CPM_CR_SCC3_PAGE;
2806 sblock = CPM_CR_SCC3_SBLOCK;
2810 if (state->smc_scc_num == 2) {
2811 page = CPM_CR_SCC2_PAGE;
2812 sblock = CPM_CR_SCC2_SBLOCK;
2815 page = CPM_CR_SCC3_PAGE;
2816 sblock = CPM_CR_SCC3_SBLOCK;
2820 cp->cp_cpcr = mk_cr_cmd(page, sblock, 0,
2821 CPM_CR_INIT_TRX) | CPM_CR_FLG;
2822 while (cp->cp_cpcr & CPM_CR_FLG);
2824 /* Set UART mode, 8 bit, no parity, one stop.
2825 * Enable receive and transmit.
2829 (SCC_GSMRL_MODE_UART | SCC_GSMRL_TDCR_16 | SCC_GSMRL_RDCR_16);
2831 /* Disable all interrupts and clear all pending
2835 scp->scc_scce = 0xffff;
2836 scp->scc_dsr = 0x7e7e;
2837 scp->scc_pmsr = 0x3000;
2840 /* Install interrupt handler.
2842 request_irq(state->irq, rs_8xx_interrupt, 0, "uart", info);
2844 /* Set up the baud rate generator.
2846 m8260_cpm_setbrg(state->smc_scc_num,
2847 baud_table[baud_idx]);
2849 /* If the port is the console, enable Rx and Tx.
2851 #ifdef CONFIG_SERIAL_CONSOLE
2852 if (i == CONFIG_SERIAL_CONSOLE_PORT) {
2853 if (idx < SCC_NUM_BASE)
2854 sp->smc_smcmr |= SMCMR_REN | SMCMR_TEN;
2856 scp->scc_gsmrl |= (SCC_GSMRL_ENR | SCC_GSMRL_ENT);
2863 module_init(rs_8xx_init);
2865 /* This must always be called before the rs_8xx_init() function, otherwise
2866 * it blows away the port control information.
2868 static int __init serial_console_setup(struct console *co, char *options)
2870 struct serial_state *ser;
2871 uint mem_addr, dp_addr, bidx;
2872 volatile cbd_t *bdp;
2873 volatile cpm8260_t *cp;
2874 volatile immap_t *immap;
2877 volatile smc_uart_t *up;
2880 volatile scc_t *scp;
2881 volatile scc_uart_t *sup;
2883 volatile iop8260_t *io;
2888 for (bidx = 0; bidx < (sizeof(baud_table) / sizeof(int)); bidx++)
2889 if (bd->bi_baudrate == baud_table[bidx])
2892 co->cflag = CREAD|CLOCAL|bidx|CS8;
2895 ser = rs_table + co->index;
2898 cp = &immap->im_cpm;
2899 io = &immap->im_ioport;
2902 scp = (scc_t *)&(immap->im_scc[SCC_CONSOLE-1]);
2903 sup = (scc_uart_t *)&immap->im_dprambase[PROFF_SCC1 + ((SCC_CONSOLE-1) << 8)];
2904 scp->scc_sccm &= ~(UART_SCCM_TX | UART_SCCM_RX);
2905 scp->scc_gsmrl &= ~(SCC_GSMRL_ENR | SCC_GSMRL_ENT);
2907 /* Use Port D for SCC1 instead of other functions.
2909 io->iop_ppard |= 0x00000003;
2910 io->iop_psord &= ~0x00000001; /* Rx */
2911 io->iop_psord |= 0x00000002; /* Tx */
2912 io->iop_pdird &= ~0x00000001; /* Rx */
2913 io->iop_pdird |= 0x00000002; /* Tx */
2916 /* This should have been done long ago by the early boot code,
2917 * but do it again to make sure.
2919 *(ushort *)(&immap->im_dprambase[PROFF_SMC1_BASE]) = PROFF_SMC1;
2920 *(ushort *)(&immap->im_dprambase[PROFF_SMC2_BASE]) = PROFF_SMC2;
2922 /* Right now, assume we are using SMCs.
2924 sp = &immap->im_smc[ser->smc_scc_num];
2926 /* When we get here, the CPM has been reset, so we need
2927 * to configure the port.
2928 * We need to allocate a transmit and receive buffer descriptor
2929 * from dual port ram, and a character buffer area from host mem.
2931 up = (smc_uart_t *)&immap->im_dprambase[ser->port];
2933 /* Disable transmitter/receiver.
2935 sp->smc_smcmr &= ~(SMCMR_REN | SMCMR_TEN);
2937 /* Use Port D for SMC1 instead of other functions.
2939 io->iop_ppard |= 0x00c00000;
2940 io->iop_pdird |= 0x00400000;
2941 io->iop_pdird &= ~0x00800000;
2942 io->iop_psord &= ~0x00c00000;
2945 /* Allocate space for two buffer descriptors in the DP ram.
2947 dp_addr = m8260_cpm_dpalloc(sizeof(cbd_t) * 2, 8);
2949 /* Allocate space for two 2 byte FIFOs in the host memory.
2951 mem_addr = m8260_cpm_hostalloc(4, 1);
2953 /* Set the physical address of the host memory buffers in
2954 * the buffer descriptors.
2956 bdp = (cbd_t *)&immap->im_dprambase[dp_addr];
2957 bdp->cbd_bufaddr = __pa(mem_addr);
2958 (bdp+1)->cbd_bufaddr = __pa(mem_addr+2);
2960 /* For the receive, set empty and wrap.
2961 * For transmit, set wrap.
2963 bdp->cbd_sc = BD_SC_EMPTY | BD_SC_WRAP;
2964 (bdp+1)->cbd_sc = BD_SC_WRAP;
2966 /* Set up the uart parameters in the parameter ram.
2969 sup->scc_genscc.scc_rbase = dp_addr;
2970 sup->scc_genscc.scc_tbase = dp_addr + sizeof(cbd_t);
2972 /* Set up the uart parameters in the
2975 sup->scc_genscc.scc_rfcr = CPMFCR_GBL | CPMFCR_EB;
2976 sup->scc_genscc.scc_tfcr = CPMFCR_GBL | CPMFCR_EB;
2978 sup->scc_genscc.scc_mrblr = 1;
2979 sup->scc_maxidl = 0;
2985 sup->scc_uaddr1 = 0;
2986 sup->scc_uaddr2 = 0;
2988 sup->scc_char1 = 0x8000;
2989 sup->scc_char2 = 0x8000;
2990 sup->scc_char3 = 0x8000;
2991 sup->scc_char4 = 0x8000;
2992 sup->scc_char5 = 0x8000;
2993 sup->scc_char6 = 0x8000;
2994 sup->scc_char7 = 0x8000;
2995 sup->scc_char8 = 0x8000;
2996 sup->scc_rccm = 0xc0ff;
2998 /* Send the CPM an initialize command.
3000 cp->cp_cpcr = mk_cr_cmd(CPM_CR_SCC1_PAGE, CPM_CR_SCC1_SBLOCK, 0,
3001 CPM_CR_INIT_TRX) | CPM_CR_FLG;
3002 while (cp->cp_cpcr & CPM_CR_FLG);
3004 /* Set UART mode, 8 bit, no parity, one stop.
3005 * Enable receive and transmit.
3009 (SCC_GSMRL_MODE_UART | SCC_GSMRL_TDCR_16 | SCC_GSMRL_RDCR_16);
3011 /* Disable all interrupts and clear all pending
3015 scp->scc_scce = 0xffff;
3016 scp->scc_dsr = 0x7e7e;
3017 scp->scc_pmsr = 0x3000;
3019 /* Wire BRG1 to SCC1. The serial init will take care of
3022 immap->im_cpmux.cmx_scr = 0;
3024 /* Set up the baud rate generator.
3026 m8260_cpm_setbrg(ser->smc_scc_num, bd->bi_baudrate);
3028 scp->scc_gsmrl |= (SCC_GSMRL_ENR | SCC_GSMRL_ENT);
3030 up->smc_rbase = dp_addr; /* Base of receive buffer desc. */
3031 up->smc_tbase = dp_addr+sizeof(cbd_t); /* Base of xmt buffer desc. */
3032 up->smc_rfcr = CPMFCR_GBL | CPMFCR_EB;
3033 up->smc_tfcr = CPMFCR_GBL | CPMFCR_EB;
3035 /* Set this to 1 for now, so we get single character interrupts.
3037 up->smc_mrblr = 1; /* receive buffer length */
3038 up->smc_maxidl = 0; /* wait forever for next char */
3040 /* Send the CPM an initialize command.
3042 cp->cp_cpcr = mk_cr_cmd(CPM_CR_SMC1_PAGE, CPM_CR_SMC1_SBLOCK, 0,
3043 CPM_CR_INIT_TRX) | CPM_CR_FLG;
3044 while (cp->cp_cpcr & CPM_CR_FLG);
3046 /* Set UART mode, 8 bit, no parity, one stop.
3047 * Enable receive and transmit.
3049 sp->smc_smcmr = smcr_mk_clen(9) | SMCMR_SM_UART;
3051 /* Set up the baud rate generator.
3053 m8260_cpm_setbrg(ser->smc_scc_num, bd->bi_baudrate);
3055 /* And finally, enable Rx and Tx.
3057 sp->smc_smcmr |= SMCMR_REN | SMCMR_TEN;