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 #ifndef 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, 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...");
596 if (schedule_work(&info->tqueue_hangup) == 0)
600 if (info->flags & ASYNC_CTS_FLOW) {
601 if (info->tty->hw_stopped) {
602 if (status & UART_MSR_CTS) {
603 #if (defined(SERIAL_DEBUG_INTR) || defined(SERIAL_DEBUG_FLOW))
604 printk("CTS tx start...");
606 info->tty->hw_stopped = 0;
607 info->IER |= UART_IER_THRI;
608 serial_out(info, UART_IER, info->IER);
609 rs_sched_event(info, RS_EVENT_WRITE_WAKEUP);
613 if (!(status & UART_MSR_CTS)) {
614 #if (defined(SERIAL_DEBUG_INTR) || defined(SERIAL_DEBUG_FLOW))
615 printk("CTS tx stop...");
617 info->tty->hw_stopped = 1;
618 info->IER &= ~UART_IER_THRI;
619 serial_out(info, UART_IER, info->IER);
627 * This is the serial driver's interrupt routine for a single port
629 static irqreturn_t rs_8xx_interrupt(int irq, void * dev_id, struct pt_regs * regs)
634 volatile smc_t *smcp;
635 volatile scc_t *sccp;
637 info = (ser_info_t *)dev_id;
639 if ((idx = info->state->smc_scc_num) < SCC_NUM_BASE) {
640 smcp = &immr->im_smc[idx];
641 events = smcp->smc_smce;
642 if (events & SMCM_BRKE)
643 receive_break(info, regs);
644 if (events & SMCM_RX)
645 receive_chars(info, regs);
646 if (events & SMCM_TX)
647 transmit_chars(info, regs);
648 smcp->smc_smce = events;
651 sccp = &immr->im_scc[idx - SCC_IDX_BASE];
652 events = sccp->scc_scce;
653 if (events & SMCM_BRKE)
654 receive_break(info, regs);
655 if (events & SCCM_RX)
656 receive_chars(info, regs);
657 if (events & SCCM_TX)
658 transmit_chars(info, regs);
659 sccp->scc_scce = events;
662 #ifdef SERIAL_DEBUG_INTR
663 printk("rs_interrupt_single(%d, %x)...",
664 info->state->smc_scc_num, events);
667 check_modem_status(info);
669 info->last_active = jiffies;
670 #ifdef SERIAL_DEBUG_INTR
678 * -------------------------------------------------------------------
679 * Here ends the serial interrupt routines.
680 * -------------------------------------------------------------------
684 * This routine is used to handle the "bottom half" processing for the
685 * serial driver, known also the "software interrupt" processing.
686 * This processing is done at the kernel interrupt level, after the
687 * rs_interrupt() has returned, BUT WITH INTERRUPTS TURNED ON. This
688 * is where time-consuming activities which can not be done in the
689 * interrupt driver proper are done; the interrupt driver schedules
690 * them using rs_sched_event(), and they get done here.
692 static void do_softint(void *private_)
694 ser_info_t *info = (ser_info_t *) private_;
695 struct tty_struct *tty;
701 if (test_and_clear_bit(RS_EVENT_WRITE_WAKEUP, &info->event)) {
702 if ((tty->flags & (1 << TTY_DO_WRITE_WAKEUP)) &&
703 tty->ldisc.write_wakeup)
704 (tty->ldisc.write_wakeup)(tty);
705 wake_up_interruptible(&tty->write_wait);
710 * This routine is called from the scheduler work queue when the interrupt
711 * routine has signalled that a hangup has occurred. The path of
712 * hangup processing is:
714 * serial interrupt routine -> (scheduler tqueue) ->
715 * do_serial_hangup() -> tty->hangup() -> rs_hangup()
718 static void do_serial_hangup(void *private_)
720 struct async_struct *info = (struct async_struct *) private_;
721 struct tty_struct *tty;
729 /*static void rs_8xx_timer(void)
731 printk("rs_8xx_timer\n");
735 static int startup(ser_info_t *info)
740 struct serial_state *state= info->state;
741 volatile smc_t *smcp;
742 volatile scc_t *sccp;
743 volatile smc_uart_t *up;
744 volatile scc_uart_t *scup;
747 save_flags(flags); cli();
749 if (info->flags & ASYNC_INITIALIZED) {
754 if (!state->port || !state->type) {
756 set_bit(TTY_IO_ERROR, &info->tty->flags);
761 #ifdef SERIAL_DEBUG_OPEN
762 printk("starting up ttys%d (irq %d)...", info->line, state->irq);
768 if (info->tty->termios->c_cflag & CBAUD)
769 info->MCR = UART_MCR_DTR | UART_MCR_RTS;
773 clear_bit(TTY_IO_ERROR, &info->tty->flags);
776 * and set the speed of the serial port
780 if ((idx = info->state->smc_scc_num) < SCC_NUM_BASE) {
781 smcp = &immr->im_smc[idx];
783 /* Enable interrupts and I/O.
785 smcp->smc_smcm |= (SMCM_RX | SMCM_TX);
786 smcp->smc_smcmr |= (SMCMR_REN | SMCMR_TEN);
788 /* We can tune the buffer length and idle characters
789 * to take advantage of the entire incoming buffer size.
790 * If mrblr is something other than 1, maxidl has to be
791 * non-zero or we never get an interrupt. The maxidl
792 * is the number of character times we wait after reception
793 * of the last character before we decide no more characters
796 up = (smc_uart_t *)&immr->im_dprambase[state->port];
798 up->smc_mrblr = 1; /* receive buffer length */
799 up->smc_maxidl = 0; /* wait forever for next char */
801 up->smc_mrblr = RX_BUF_SIZE;
802 up->smc_maxidl = RX_BUF_SIZE;
804 up->smc_brkcr = 1; /* number of break chars */
807 sccp = &immr->im_scc[idx - SCC_IDX_BASE];
808 scup = (scc_uart_t *)&immr->im_dprambase[state->port];
810 scup->scc_genscc.scc_mrblr = 1; /* receive buffer length */
811 scup->scc_maxidl = 0; /* wait forever for next char */
813 scup->scc_genscc.scc_mrblr = RX_BUF_SIZE;
814 scup->scc_maxidl = RX_BUF_SIZE;
817 sccp->scc_sccm |= (UART_SCCM_TX | UART_SCCM_RX);
818 sccp->scc_gsmrl |= (SCC_GSMRL_ENR | SCC_GSMRL_ENT);
821 info->flags |= ASYNC_INITIALIZED;
822 restore_flags(flags);
826 restore_flags(flags);
831 * This routine will shutdown a serial port; interrupts are disabled, and
832 * DTR is dropped if the hangup on close termio flag is on.
834 static void shutdown(ser_info_t * info)
837 struct serial_state *state;
839 volatile smc_t *smcp;
840 volatile scc_t *sccp;
842 if (!(info->flags & ASYNC_INITIALIZED))
847 #ifdef SERIAL_DEBUG_OPEN
848 printk("Shutting down serial port %d (irq %d)....", info->line,
852 save_flags(flags); cli(); /* Disable interrupts */
854 if ((idx = info->state->smc_scc_num) < SCC_NUM_BASE) {
855 smcp = &immr->im_smc[idx];
857 /* Disable interrupts and I/O.
859 smcp->smc_smcm &= ~(SMCM_RX | SMCM_TX);
860 #ifdef CONFIG_SERIAL_CONSOLE
861 /* We can't disable the transmitter if this is the
864 if (idx != CONFIG_SERIAL_CONSOLE_PORT)
866 smcp->smc_smcmr &= ~(SMCMR_REN | SMCMR_TEN);
869 sccp = &immr->im_scc[idx - SCC_IDX_BASE];
870 sccp->scc_sccm &= ~(UART_SCCM_TX | UART_SCCM_RX);
871 #ifdef CONFIG_SERIAL_CONSOLE
872 if (idx != CONFIG_SERIAL_CONSOLE_PORT)
873 sccp->scc_gsmrl &= ~(SCC_GSMRL_ENR | SCC_GSMRL_ENT);
878 set_bit(TTY_IO_ERROR, &info->tty->flags);
880 info->flags &= ~ASYNC_INITIALIZED;
881 restore_flags(flags);
885 * This routine is called to set the UART divisor registers to match
886 * the specified baud rate for a serial port.
888 static void change_speed(ser_info_t *info)
891 unsigned cflag, cval, scval, prev_mode;
892 int i, bits, sbits, idx;
894 volatile smc_t *smcp;
895 volatile scc_t *sccp;
897 if (!info->tty || !info->tty->termios)
899 cflag = info->tty->termios->c_cflag;
901 /* Character length programmed into the mode register is the
902 * sum of: 1 start bit, number of data bits, 0 or 1 parity bit,
903 * 1 or 2 stop bits, minus 1.
904 * The value 'bits' counts this for us.
909 /* byte size and parity */
910 switch (cflag & CSIZE) {
911 case CS5: bits = 5; break;
912 case CS6: bits = 6; break;
913 case CS7: bits = 7; break;
914 case CS8: bits = 8; break;
915 /* Never happens, but GCC is too dumb to figure it out */
916 default: bits = 8; break;
920 if (cflag & CSTOPB) {
921 cval |= SMCMR_SL; /* Two stops */
922 scval |= SCU_PMSR_SL;
925 if (cflag & PARENB) {
927 scval |= SCU_PMSR_PEN;
930 if (!(cflag & PARODD)) {
931 cval |= SMCMR_PM_EVEN;
932 scval |= (SCU_PMSR_REVP | SCU_PMSR_TEVP);
935 /* Determine divisor based on baud rate */
937 if (i >= (sizeof(baud_table)/sizeof(int)))
940 baud_rate = baud_table[i];
942 info->timeout = (TX_BUF_SIZE*HZ*bits);
943 info->timeout += HZ/50; /* Add .02 seconds of slop */
946 /* CTS flow control flag and modem status interrupts */
947 info->IER &= ~UART_IER_MSI;
948 if (info->flags & ASYNC_HARDPPS_CD)
949 info->IER |= UART_IER_MSI;
950 if (cflag & CRTSCTS) {
951 info->flags |= ASYNC_CTS_FLOW;
952 info->IER |= UART_IER_MSI;
954 info->flags &= ~ASYNC_CTS_FLOW;
956 info->flags &= ~ASYNC_CHECK_CD;
958 info->flags |= ASYNC_CHECK_CD;
959 info->IER |= UART_IER_MSI;
961 serial_out(info, UART_IER, info->IER);
965 * Set up parity check flag
967 #define RELEVANT_IFLAG(iflag) (iflag & (IGNBRK|BRKINT|IGNPAR|PARMRK|INPCK))
969 info->read_status_mask = (BD_SC_EMPTY | BD_SC_OV);
970 if (I_INPCK(info->tty))
971 info->read_status_mask |= BD_SC_FR | BD_SC_PR;
972 if (I_BRKINT(info->tty) || I_PARMRK(info->tty))
973 info->read_status_mask |= BD_SC_BR;
976 * Characters to ignore
978 info->ignore_status_mask = 0;
979 if (I_IGNPAR(info->tty))
980 info->ignore_status_mask |= BD_SC_PR | BD_SC_FR;
981 if (I_IGNBRK(info->tty)) {
982 info->ignore_status_mask |= BD_SC_BR;
984 * If we're ignore parity and break indicators, ignore
985 * overruns too. (For real raw support).
987 if (I_IGNPAR(info->tty))
988 info->ignore_status_mask |= BD_SC_OV;
991 * !!! ignore all characters if CREAD is not set
993 if ((cflag & CREAD) == 0)
994 info->read_status_mask &= ~BD_SC_EMPTY;
995 save_flags(flags); cli();
997 /* Start bit has not been added (so don't, because we would just
998 * subtract it later), and we need to add one for the number of
999 * stops bits (there is always at least one).
1002 if ((idx = info->state->smc_scc_num) < SCC_NUM_BASE) {
1003 smcp = &immr->im_smc[idx];
1005 /* Set the mode register. We want to keep a copy of the
1006 * enables, because we want to put them back if they were
1009 prev_mode = smcp->smc_smcmr;
1010 smcp->smc_smcmr = smcr_mk_clen(bits) | cval | SMCMR_SM_UART;
1011 smcp->smc_smcmr |= (prev_mode & (SMCMR_REN | SMCMR_TEN));
1014 sccp = &immr->im_scc[idx - SCC_IDX_BASE];
1015 sccp->scc_pmsr = (sbits << 12) | scval;
1018 m8260_cpm_setbrg(info->state->smc_scc_num, baud_rate);
1020 restore_flags(flags);
1023 static void rs_8xx_put_char(struct tty_struct *tty, unsigned char ch)
1025 ser_info_t *info = (ser_info_t *)tty->driver_data;
1026 volatile cbd_t *bdp;
1028 if (serial_paranoia_check(info, tty->name, "rs_put_char"))
1035 while (bdp->cbd_sc & BD_SC_READY);
1037 *((char *)__va(bdp->cbd_bufaddr)) = ch;
1038 bdp->cbd_datlen = 1;
1039 bdp->cbd_sc |= BD_SC_READY;
1043 if (bdp->cbd_sc & BD_SC_WRAP)
1044 bdp = info->tx_bd_base;
1048 info->tx_cur = (cbd_t *)bdp;
1052 static int rs_8xx_write(struct tty_struct * tty, int from_user,
1053 const unsigned char *buf, int count)
1056 ser_info_t *info = (ser_info_t *)tty->driver_data;
1057 volatile cbd_t *bdp;
1059 if (serial_paranoia_check(info, tty->name, "rs_write"))
1068 c = min(count, TX_BUF_SIZE);
1073 if (bdp->cbd_sc & BD_SC_READY) {
1074 info->flags |= TX_WAKEUP;
1079 if (copy_from_user(__va(bdp->cbd_bufaddr), buf, c)) {
1085 memcpy(__va(bdp->cbd_bufaddr), buf, c);
1088 bdp->cbd_datlen = c;
1089 bdp->cbd_sc |= BD_SC_READY;
1097 if (bdp->cbd_sc & BD_SC_WRAP)
1098 bdp = info->tx_bd_base;
1101 info->tx_cur = (cbd_t *)bdp;
1106 static int rs_8xx_write_room(struct tty_struct *tty)
1108 ser_info_t *info = (ser_info_t *)tty->driver_data;
1111 if (serial_paranoia_check(info, tty->name, "rs_write_room"))
1114 if ((info->tx_cur->cbd_sc & BD_SC_READY) == 0) {
1115 info->flags &= ~TX_WAKEUP;
1119 info->flags |= TX_WAKEUP;
1125 /* I could track this with transmit counters....maybe later.
1127 static int rs_8xx_chars_in_buffer(struct tty_struct *tty)
1129 ser_info_t *info = (ser_info_t *)tty->driver_data;
1131 if (serial_paranoia_check(info, tty->name, "rs_chars_in_buffer"))
1136 static void rs_8xx_flush_buffer(struct tty_struct *tty)
1138 ser_info_t *info = (ser_info_t *)tty->driver_data;
1140 if (serial_paranoia_check(info, tty->name, "rs_flush_buffer"))
1143 /* There is nothing to "flush", whatever we gave the CPM
1144 * is on its way out.
1146 wake_up_interruptible(&tty->write_wait);
1147 if ((tty->flags & (1 << TTY_DO_WRITE_WAKEUP)) &&
1148 tty->ldisc.write_wakeup)
1149 (tty->ldisc.write_wakeup)(tty);
1150 info->flags &= ~TX_WAKEUP;
1154 * This function is used to send a high-priority XON/XOFF character to
1157 static void rs_8xx_send_xchar(struct tty_struct *tty, char ch)
1159 volatile cbd_t *bdp;
1161 ser_info_t *info = (ser_info_t *)tty->driver_data;
1163 if (serial_paranoia_check(info, tty->name, "rs_send_char"))
1167 while (bdp->cbd_sc & BD_SC_READY);
1169 *((char *)__va(bdp->cbd_bufaddr)) = ch;
1170 bdp->cbd_datlen = 1;
1171 bdp->cbd_sc |= BD_SC_READY;
1175 if (bdp->cbd_sc & BD_SC_WRAP)
1176 bdp = info->tx_bd_base;
1180 info->tx_cur = (cbd_t *)bdp;
1184 * ------------------------------------------------------------
1187 * This routine is called by the upper-layer tty layer to signal that
1188 * incoming characters should be throttled.
1189 * ------------------------------------------------------------
1191 static void rs_8xx_throttle(struct tty_struct * tty)
1193 ser_info_t *info = (ser_info_t *)tty->driver_data;
1194 #ifdef SERIAL_DEBUG_THROTTLE
1197 printk("throttle %s: %d....\n", _tty_name(tty, buf),
1198 tty->ldisc.chars_in_buffer(tty));
1201 if (serial_paranoia_check(info, tty->name, "rs_throttle"))
1205 rs_8xx_send_xchar(tty, STOP_CHAR(tty));
1207 #ifdef modem_control
1208 if (tty->termios->c_cflag & CRTSCTS)
1209 info->MCR &= ~UART_MCR_RTS;
1212 serial_out(info, UART_MCR, info->MCR);
1217 static void rs_8xx_unthrottle(struct tty_struct * tty)
1219 ser_info_t *info = (ser_info_t *)tty->driver_data;
1220 #ifdef SERIAL_DEBUG_THROTTLE
1223 printk("unthrottle %s: %d....\n", _tty_name(tty, buf),
1224 tty->ldisc.chars_in_buffer(tty));
1227 if (serial_paranoia_check(info, tty->name, "rs_unthrottle"))
1234 rs_8xx_send_xchar(tty, START_CHAR(tty));
1236 #ifdef modem_control
1237 if (tty->termios->c_cflag & CRTSCTS)
1238 info->MCR |= UART_MCR_RTS;
1240 serial_out(info, UART_MCR, info->MCR);
1246 * ------------------------------------------------------------
1247 * rs_ioctl() and friends
1248 * ------------------------------------------------------------
1253 * get_lsr_info - get line status register info
1255 * Purpose: Let user call ioctl() to get info when the UART physically
1256 * is emptied. On bus types like RS485, the transmitter must
1257 * release the bus after transmitting. This must be done when
1258 * the transmit shift register is empty, not be done when the
1259 * transmit holding register is empty. This functionality
1260 * allows an RS485 driver to be written in user space.
1262 static int get_lsr_info(struct async_struct * info, unsigned int *value)
1264 unsigned char status;
1265 unsigned int result;
1268 status = serial_in(info, UART_LSR);
1270 result = ((status & UART_LSR_TEMT) ? TIOCSER_TEMT : 0);
1271 return put_user(result,value);
1275 static int get_modem_info(ser_info_t *info, unsigned int *value)
1277 unsigned int result = 0;
1278 #ifdef modem_control
1279 unsigned char control, status;
1281 control = info->MCR;
1283 status = serial_in(info, UART_MSR);
1285 result = ((control & UART_MCR_RTS) ? TIOCM_RTS : 0)
1286 | ((control & UART_MCR_DTR) ? TIOCM_DTR : 0)
1288 | ((control & UART_MCR_OUT1) ? TIOCM_OUT1 : 0)
1289 | ((control & UART_MCR_OUT2) ? TIOCM_OUT2 : 0)
1291 | ((status & UART_MSR_DCD) ? TIOCM_CAR : 0)
1292 | ((status & UART_MSR_RI) ? TIOCM_RNG : 0)
1293 | ((status & UART_MSR_DSR) ? TIOCM_DSR : 0)
1294 | ((status & UART_MSR_CTS) ? TIOCM_CTS : 0);
1296 return put_user(result,value);
1299 static int set_modem_info(ser_info_t *info, unsigned int cmd,
1300 unsigned int *value)
1305 error = get_user(arg, value);
1308 #ifdef modem_control
1311 if (arg & TIOCM_RTS)
1312 info->MCR |= UART_MCR_RTS;
1313 if (arg & TIOCM_DTR)
1314 info->MCR |= UART_MCR_DTR;
1316 if (arg & TIOCM_OUT1)
1317 info->MCR |= UART_MCR_OUT1;
1318 if (arg & TIOCM_OUT2)
1319 info->MCR |= UART_MCR_OUT2;
1323 if (arg & TIOCM_RTS)
1324 info->MCR &= ~UART_MCR_RTS;
1325 if (arg & TIOCM_DTR)
1326 info->MCR &= ~UART_MCR_DTR;
1328 if (arg & TIOCM_OUT1)
1329 info->MCR &= ~UART_MCR_OUT1;
1330 if (arg & TIOCM_OUT2)
1331 info->MCR &= ~UART_MCR_OUT2;
1335 info->MCR = ((info->MCR & ~(UART_MCR_RTS |
1341 | ((arg & TIOCM_RTS) ? UART_MCR_RTS : 0)
1343 | ((arg & TIOCM_OUT1) ? UART_MCR_OUT1 : 0)
1344 | ((arg & TIOCM_OUT2) ? UART_MCR_OUT2 : 0)
1346 | ((arg & TIOCM_DTR) ? UART_MCR_DTR : 0));
1352 serial_out(info, UART_MCR, info->MCR);
1358 /* Sending a break is a two step process on the SMC/SCC. It is accomplished
1359 * by sending a STOP TRANSMIT command followed by a RESTART TRANSMIT
1360 * command. We take advantage of the begin/end functions to make this
1363 static void begin_break(ser_info_t *info)
1365 volatile cpm8260_t *cp;
1371 if ((num = info->state->smc_scc_num) < SCC_NUM_BASE) {
1373 page = CPM_CR_SMC1_PAGE;
1374 sblock = CPM_CR_SMC1_SBLOCK;
1377 page = CPM_CR_SMC2_PAGE;
1378 sblock = CPM_CR_SMC2_SBLOCK;
1382 num -= SCC_NUM_BASE;
1385 page = CPM_CR_SCC1_PAGE;
1386 sblock = CPM_CR_SCC1_SBLOCK;
1389 page = CPM_CR_SCC2_PAGE;
1390 sblock = CPM_CR_SCC2_SBLOCK;
1393 page = CPM_CR_SCC3_PAGE;
1394 sblock = CPM_CR_SCC3_SBLOCK;
1397 page = CPM_CR_SCC4_PAGE;
1398 sblock = CPM_CR_SCC4_SBLOCK;
1403 cp->cp_cpcr = mk_cr_cmd(page, sblock, 0, CPM_CR_STOP_TX) | CPM_CR_FLG;
1404 while (cp->cp_cpcr & CPM_CR_FLG);
1407 static void end_break(ser_info_t *info)
1409 volatile cpm8260_t *cp;
1415 if ((num = info->state->smc_scc_num) < SCC_NUM_BASE) {
1417 page = CPM_CR_SMC1_PAGE;
1418 sblock = CPM_CR_SMC1_SBLOCK;
1421 page = CPM_CR_SMC2_PAGE;
1422 sblock = CPM_CR_SMC2_SBLOCK;
1426 num -= SCC_NUM_BASE;
1429 page = CPM_CR_SCC1_PAGE;
1430 sblock = CPM_CR_SCC1_SBLOCK;
1433 page = CPM_CR_SCC2_PAGE;
1434 sblock = CPM_CR_SCC2_SBLOCK;
1437 page = CPM_CR_SCC3_PAGE;
1438 sblock = CPM_CR_SCC3_SBLOCK;
1441 page = CPM_CR_SCC4_PAGE;
1442 sblock = CPM_CR_SCC4_SBLOCK;
1447 cp->cp_cpcr = mk_cr_cmd(page, sblock, 0, CPM_CR_RESTART_TX) | CPM_CR_FLG;
1448 while (cp->cp_cpcr & CPM_CR_FLG);
1452 * This routine sends a break character out the serial port.
1454 static void send_break(ser_info_t *info, int duration)
1456 current->state = TASK_INTERRUPTIBLE;
1457 #ifdef SERIAL_DEBUG_SEND_BREAK
1458 printk("rs_send_break(%d) jiff=%lu...", duration, jiffies);
1461 schedule_timeout(duration);
1463 #ifdef SERIAL_DEBUG_SEND_BREAK
1464 printk("done jiffies=%lu\n", jiffies);
1469 static int rs_8xx_ioctl(struct tty_struct *tty, struct file * file,
1470 unsigned int cmd, unsigned long arg)
1473 ser_info_t *info = (ser_info_t *)tty->driver_data;
1475 struct async_icount cnow; /* kernel counter temps */
1476 struct serial_icounter_struct *p_cuser; /* user space */
1478 if (serial_paranoia_check(info, tty->name, "rs_ioctl"))
1481 if ((cmd != TIOCMIWAIT) && (cmd != TIOCGICOUNT)) {
1482 if (tty->flags & (1 << TTY_IO_ERROR))
1487 case TCSBRK: /* SVID version: non-zero arg --> no break */
1488 retval = tty_check_change(tty);
1491 tty_wait_until_sent(tty, 0);
1492 if (signal_pending(current))
1495 send_break(info, HZ/4); /* 1/4 second */
1496 if (signal_pending(current))
1500 case TCSBRKP: /* support for POSIX tcsendbreak() */
1501 retval = tty_check_change(tty);
1504 tty_wait_until_sent(tty, 0);
1505 if (signal_pending(current))
1507 send_break(info, arg ? arg*(HZ/10) : HZ/4);
1508 if (signal_pending(current))
1512 retval = tty_check_change(tty);
1515 tty_wait_until_sent(tty, 0);
1519 retval = tty_check_change(tty);
1525 return put_user(C_CLOCAL(tty) ? 1 : 0, (int *) arg);
1527 error = get_user(arg, (unsigned int *) arg);
1530 tty->termios->c_cflag =
1531 ((tty->termios->c_cflag & ~CLOCAL) |
1532 (arg ? CLOCAL : 0));
1535 return get_modem_info(info, (unsigned int *) arg);
1539 return set_modem_info(info, cmd, (unsigned int *) arg);
1541 case TIOCSERGETLSR: /* Get line status register */
1542 return get_lsr_info(info, (unsigned int *) arg);
1545 * Wait for any of the 4 modem inputs (DCD,RI,DSR,CTS) to change
1546 * - mask passed in arg for lines of interest
1547 * (use |'ed TIOCM_RNG/DSR/CD/CTS for masking)
1548 * Caller should use TIOCGICOUNT to see which one it was
1551 #ifdef modem_control
1553 /* note the counters on entry */
1554 cprev = info->state->icount;
1557 interruptible_sleep_on(&info->delta_msr_wait);
1558 /* see if a signal did it */
1559 if (signal_pending(current))
1560 return -ERESTARTSYS;
1562 cnow = info->state->icount; /* atomic copy */
1564 if (cnow.rng == cprev.rng && cnow.dsr == cprev.dsr &&
1565 cnow.dcd == cprev.dcd && cnow.cts == cprev.cts)
1566 return -EIO; /* no change => error */
1567 if ( ((arg & TIOCM_RNG) && (cnow.rng != cprev.rng)) ||
1568 ((arg & TIOCM_DSR) && (cnow.dsr != cprev.dsr)) ||
1569 ((arg & TIOCM_CD) && (cnow.dcd != cprev.dcd)) ||
1570 ((arg & TIOCM_CTS) && (cnow.cts != cprev.cts)) ) {
1581 * Get counter of input serial line interrupts (DCD,RI,DSR,CTS)
1582 * Return: write counters to the user passed counter struct
1583 * NB: both 1->0 and 0->1 transitions are counted except for
1584 * RI where only 0->1 is counted.
1588 cnow = info->state->icount;
1590 p_cuser = (struct serial_icounter_struct *) arg;
1591 error = put_user(cnow.cts, &p_cuser->cts);
1592 if (error) return error;
1593 error = put_user(cnow.dsr, &p_cuser->dsr);
1594 if (error) return error;
1595 error = put_user(cnow.rng, &p_cuser->rng);
1596 if (error) return error;
1597 error = put_user(cnow.dcd, &p_cuser->dcd);
1598 if (error) return error;
1602 return -ENOIOCTLCMD;
1607 /* FIX UP modem control here someday......
1609 static void rs_8xx_set_termios(struct tty_struct *tty, struct termios *old_termios)
1611 ser_info_t *info = (ser_info_t *)tty->driver_data;
1613 if ( (tty->termios->c_cflag == old_termios->c_cflag)
1614 && ( RELEVANT_IFLAG(tty->termios->c_iflag)
1615 == RELEVANT_IFLAG(old_termios->c_iflag)))
1620 #ifdef modem_control
1621 /* Handle transition to B0 status */
1622 if ((old_termios->c_cflag & CBAUD) &&
1623 !(tty->termios->c_cflag & CBAUD)) {
1624 info->MCR &= ~(UART_MCR_DTR|UART_MCR_RTS);
1626 serial_out(info, UART_MCR, info->MCR);
1630 /* Handle transition away from B0 status */
1631 if (!(old_termios->c_cflag & CBAUD) &&
1632 (tty->termios->c_cflag & CBAUD)) {
1633 info->MCR |= UART_MCR_DTR;
1634 if (!tty->hw_stopped ||
1635 !(tty->termios->c_cflag & CRTSCTS)) {
1636 info->MCR |= UART_MCR_RTS;
1639 serial_out(info, UART_MCR, info->MCR);
1643 /* Handle turning off CRTSCTS */
1644 if ((old_termios->c_cflag & CRTSCTS) &&
1645 !(tty->termios->c_cflag & CRTSCTS)) {
1646 tty->hw_stopped = 0;
1653 * No need to wake up processes in open wait, since they
1654 * sample the CLOCAL flag once, and don't recheck it.
1655 * XXX It's not clear whether the current behavior is correct
1656 * or not. Hence, this may change.....
1658 if (!(old_termios->c_cflag & CLOCAL) &&
1659 (tty->termios->c_cflag & CLOCAL))
1660 wake_up_interruptible(&info->open_wait);
1665 * ------------------------------------------------------------
1668 * This routine is called when the serial port gets closed. First, we
1669 * wait for the last remaining data to be sent. Then, we unlink its
1670 * async structure from the interrupt chain if necessary, and we free
1671 * that IRQ if nothing is left in the chain.
1672 * ------------------------------------------------------------
1674 static void rs_8xx_close(struct tty_struct *tty, struct file * filp)
1676 ser_info_t *info = (ser_info_t *)tty->driver_data;
1677 struct serial_state *state;
1678 unsigned long flags;
1680 volatile smc_t *smcp;
1681 volatile scc_t *sccp;
1683 if (!info || serial_paranoia_check(info, tty->name, "rs_close"))
1686 state = info->state;
1688 save_flags(flags); cli();
1690 if (tty_hung_up_p(filp)) {
1691 DBG_CNT("before DEC-hung");
1693 restore_flags(flags);
1697 #ifdef SERIAL_DEBUG_OPEN
1698 printk("rs_close ttys%d, count = %d\n", info->line, state->count);
1700 if ((tty->count == 1) && (state->count != 1)) {
1702 * Uh, oh. tty->count is 1, which means that the tty
1703 * structure will be freed. state->count should always
1704 * be one in these conditions. If it's greater than
1705 * one, we've got real problems, since it means the
1706 * serial port won't be shutdown.
1708 printk("rs_close: bad serial port count; tty->count is 1, "
1709 "state->count is %d\n", state->count);
1712 if (--state->count < 0) {
1713 printk("rs_close: bad serial port count for ttys%d: %d\n",
1714 info->line, state->count);
1718 DBG_CNT("before DEC-2");
1720 restore_flags(flags);
1723 info->flags |= ASYNC_CLOSING;
1725 * Now we wait for the transmit buffer to clear; and we notify
1726 * the line discipline to only process XON/XOFF characters.
1729 if (info->closing_wait != ASYNC_CLOSING_WAIT_NONE)
1730 tty_wait_until_sent(tty, info->closing_wait);
1732 * At this point we stop accepting input. To do this, we
1733 * disable the receive line status interrupts, and tell the
1734 * interrupt driver to stop checking the data ready bit in the
1735 * line status register.
1737 info->read_status_mask &= ~BD_SC_EMPTY;
1738 if (info->flags & ASYNC_INITIALIZED) {
1739 if ((idx = info->state->smc_scc_num) < SCC_NUM_BASE) {
1740 smcp = &immr->im_smc[idx];
1741 smcp->smc_smcm &= ~SMCM_RX;
1742 smcp->smc_smcmr &= ~SMCMR_REN;
1745 sccp = &immr->im_scc[idx - SCC_IDX_BASE];
1746 sccp->scc_sccm &= ~UART_SCCM_RX;
1747 sccp->scc_gsmrl &= ~SCC_GSMRL_ENR;
1750 * Before we drop DTR, make sure the UART transmitter
1751 * has completely drained; this is especially
1752 * important if there is a transmit FIFO!
1754 rs_8xx_wait_until_sent(tty, info->timeout);
1757 if (tty->driver->flush_buffer)
1758 tty->driver->flush_buffer(tty);
1759 if (tty->ldisc.flush_buffer)
1760 tty->ldisc.flush_buffer(tty);
1764 if (info->blocked_open) {
1765 if (info->close_delay) {
1766 current->state = TASK_INTERRUPTIBLE;
1767 schedule_timeout(info->close_delay);
1769 wake_up_interruptible(&info->open_wait);
1771 info->flags &= ~(ASYNC_NORMAL_ACTIVE|ASYNC_CLOSING);
1772 wake_up_interruptible(&info->close_wait);
1774 restore_flags(flags);
1778 * rs_wait_until_sent() --- wait until the transmitter is empty
1780 static void rs_8xx_wait_until_sent(struct tty_struct *tty, int timeout)
1782 ser_info_t *info = (ser_info_t *)tty->driver_data;
1783 unsigned long orig_jiffies, char_time;
1785 volatile cbd_t *bdp;
1787 if (serial_paranoia_check(info, tty->name, "rs_wait_until_sent"))
1791 if (info->state->type == PORT_UNKNOWN)
1795 orig_jiffies = jiffies;
1797 * Set the check interval to be 1/5 of the estimated time to
1798 * send a single character, and make it at least 1. The check
1799 * interval should also be less than the timeout.
1801 * Note: we have to use pretty tight timings here to satisfy
1806 char_time = min(char_time, (unsigned long)timeout);
1807 #ifdef SERIAL_DEBUG_RS_WAIT_UNTIL_SENT
1808 printk("In rs_wait_until_sent(%d) check=%lu...", timeout, char_time);
1809 printk("jiff=%lu...", jiffies);
1812 /* We go through the loop at least once because we can't tell
1813 * exactly when the last character exits the shifter. There can
1814 * be at least two characters waiting to be sent after the buffers
1818 #ifdef SERIAL_DEBUG_RS_WAIT_UNTIL_SENT
1819 printk("lsr = %d (jiff=%lu)...", lsr, jiffies);
1821 current->state = TASK_INTERRUPTIBLE;
1822 /* current->dyn_prio = 0; make us low-priority */
1823 schedule_timeout(char_time);
1824 if (signal_pending(current))
1826 if (timeout && time_after(jiffies, orig_jiffies + timeout))
1829 } while (bdp->cbd_sc & BD_SC_READY);
1830 current->state = TASK_RUNNING;
1831 #ifdef SERIAL_DEBUG_RS_WAIT_UNTIL_SENT
1832 printk("lsr = %d (jiff=%lu)...done\n", lsr, jiffies);
1837 * rs_hangup() --- called by tty_hangup() when a hangup is signaled.
1839 static void rs_8xx_hangup(struct tty_struct *tty)
1841 ser_info_t *info = (ser_info_t *)tty->driver_data;
1842 struct serial_state *state = info->state;
1844 if (serial_paranoia_check(info, tty->name, "rs_hangup"))
1847 state = info->state;
1849 rs_8xx_flush_buffer(tty);
1853 info->flags &= ~ASYNC_NORMAL_ACTIVE;
1855 wake_up_interruptible(&info->open_wait);
1859 * ------------------------------------------------------------
1860 * rs_open() and friends
1861 * ------------------------------------------------------------
1863 static int block_til_ready(struct tty_struct *tty, struct file * filp,
1866 #ifdef DO_THIS_LATER
1867 DECLARE_WAITQUEUE(wait, current);
1868 struct serial_state *state = info->state;
1874 * If the device is in the middle of being closed, then block
1875 * until it's done, and then try again.
1877 if (tty_hung_up_p(filp) ||
1878 (info->flags & ASYNC_CLOSING)) {
1879 if (info->flags & ASYNC_CLOSING)
1880 interruptible_sleep_on(&info->close_wait);
1881 #ifdef SERIAL_DO_RESTART
1882 if (info->flags & ASYNC_HUP_NOTIFY)
1885 return -ERESTARTSYS;
1892 * If non-blocking mode is set, or the port is not enabled,
1893 * then make the check up front and then exit.
1894 * If this is an SMC port, we don't have modem control to wait
1895 * for, so just get out here.
1897 if ((filp->f_flags & O_NONBLOCK) ||
1898 (tty->flags & (1 << TTY_IO_ERROR)) ||
1899 (info->state->smc_scc_num < SCC_NUM_BASE)) {
1900 info->flags |= ASYNC_NORMAL_ACTIVE;
1904 if (tty->termios->c_cflag & CLOCAL)
1908 * Block waiting for the carrier detect and the line to become
1909 * free (i.e., not in use by the callout). While we are in
1910 * this loop, state->count is dropped by one, so that
1911 * rs_close() knows when to free things. We restore it upon
1912 * exit, either normal or abnormal.
1915 #ifdef DO_THIS_LATER
1916 add_wait_queue(&info->open_wait, &wait);
1917 #ifdef SERIAL_DEBUG_OPEN
1918 printk("block_til_ready before block: ttys%d, count = %d\n",
1919 state->line, state->count);
1922 if (!tty_hung_up_p(filp))
1925 info->blocked_open++;
1928 if (tty->termios->c_cflag & CBAUD)
1929 serial_out(info, UART_MCR,
1930 serial_inp(info, UART_MCR) |
1931 (UART_MCR_DTR | UART_MCR_RTS));
1933 set_current_state(TASK_INTERRUPTIBLE);
1934 if (tty_hung_up_p(filp) ||
1935 !(info->flags & ASYNC_INITIALIZED)) {
1936 #ifdef SERIAL_DO_RESTART
1937 if (info->flags & ASYNC_HUP_NOTIFY)
1940 retval = -ERESTARTSYS;
1946 if (!(info->flags & ASYNC_CLOSING) &&
1947 (do_clocal || (serial_in(info, UART_MSR) &
1950 if (signal_pending(current)) {
1951 retval = -ERESTARTSYS;
1954 #ifdef SERIAL_DEBUG_OPEN
1955 printk("block_til_ready blocking: ttys%d, count = %d\n",
1956 info->line, state->count);
1960 current->state = TASK_RUNNING;
1961 remove_wait_queue(&info->open_wait, &wait);
1962 if (!tty_hung_up_p(filp))
1964 info->blocked_open--;
1965 #ifdef SERIAL_DEBUG_OPEN
1966 printk("block_til_ready after blocking: ttys%d, count = %d\n",
1967 info->line, state->count);
1969 #endif /* DO_THIS_LATER */
1972 info->flags |= ASYNC_NORMAL_ACTIVE;
1976 static int get_async_struct(int line, ser_info_t **ret_info)
1978 struct serial_state *sstate;
1980 sstate = rs_table + line;
1983 *ret_info = (ser_info_t *)sstate->info;
1992 * This routine is called whenever a serial port is opened. It
1993 * enables interrupts for a serial port, linking in its async structure into
1994 * the IRQ chain. It also performs the serial-specific
1995 * initialization for the tty structure.
1997 static int rs_8xx_open(struct tty_struct *tty, struct file * filp)
2003 if ((line < 0) || (line >= NR_PORTS))
2005 retval = get_async_struct(line, &info);
2008 if (serial_paranoia_check(info, tty->name, "rs_open"))
2011 #ifdef SERIAL_DEBUG_OPEN
2012 printk("rs_open %s, count = %d\n", tty->name, info->state->count);
2014 tty->driver_data = info;
2018 * Start up serial port
2020 retval = startup(info);
2025 retval = block_til_ready(tty, filp, info);
2027 #ifdef SERIAL_DEBUG_OPEN
2028 printk("rs_open returning after block_til_ready with %d\n",
2034 #ifdef SERIAL_DEBUG_OPEN
2035 printk("rs_open %s successful...", line);
2041 * /proc fs routines....
2044 static inline int line_info(char *buf, struct serial_state *state)
2047 struct async_struct *info = state->info, scr_info;
2048 char stat_buf[30], control, status;
2052 ret = sprintf(buf, "%d: uart:%s port:%X irq:%d",
2054 (state->smc_scc_num < SCC_NUM_BASE) ? "SMC" : "SCC",
2055 (unsigned int)(state->port), state->irq);
2057 if (!state->port || (state->type == PORT_UNKNOWN)) {
2058 ret += sprintf(buf+ret, "\n");
2064 * Figure out the current RS-232 lines
2067 info = &scr_info; /* This is just for serial_{in,out} */
2069 info->magic = SERIAL_MAGIC;
2070 info->port = state->port;
2071 info->flags = state->flags;
2076 status = serial_in(info, UART_MSR);
2077 control = info ? info->MCR : serial_in(info, UART_MCR);
2082 if (control & UART_MCR_RTS)
2083 strcat(stat_buf, "|RTS");
2084 if (status & UART_MSR_CTS)
2085 strcat(stat_buf, "|CTS");
2086 if (control & UART_MCR_DTR)
2087 strcat(stat_buf, "|DTR");
2088 if (status & UART_MSR_DSR)
2089 strcat(stat_buf, "|DSR");
2090 if (status & UART_MSR_DCD)
2091 strcat(stat_buf, "|CD");
2092 if (status & UART_MSR_RI)
2093 strcat(stat_buf, "|RI");
2096 ret += sprintf(buf+ret, " baud:%d",
2097 state->baud_base / info->quot);
2100 ret += sprintf(buf+ret, " tx:%d rx:%d",
2101 state->icount.tx, state->icount.rx);
2103 if (state->icount.frame)
2104 ret += sprintf(buf+ret, " fe:%d", state->icount.frame);
2106 if (state->icount.parity)
2107 ret += sprintf(buf+ret, " pe:%d", state->icount.parity);
2109 if (state->icount.brk)
2110 ret += sprintf(buf+ret, " brk:%d", state->icount.brk);
2112 if (state->icount.overrun)
2113 ret += sprintf(buf+ret, " oe:%d", state->icount.overrun);
2116 * Last thing is the RS-232 status lines
2118 ret += sprintf(buf+ret, " %s\n", stat_buf+1);
2123 int rs_8xx_read_proc(char *page, char **start, off_t off, int count,
2124 int *eof, void *data)
2129 len += sprintf(page, "serinfo:1.0 driver:%s\n", serial_version);
2130 for (i = 0; i < NR_PORTS && len < 4000; i++) {
2131 len += line_info(page + len, &rs_table[i]);
2132 if (len+begin > off+count)
2134 if (len+begin < off) {
2141 if (off >= len+begin)
2143 *start = page + (begin-off);
2144 return ((count < begin+len-off) ? count : begin+len-off);
2148 * ---------------------------------------------------------------------
2149 * rs_init() and friends
2151 * rs_init() is called at boot-time to initialize the serial driver.
2152 * ---------------------------------------------------------------------
2156 * This routine prints out the appropriate serial driver version
2157 * number, and identifies which options were configured into this
2160 static _INLINE_ void show_serial_version(void)
2162 printk(KERN_INFO "%s version %s\n", serial_name, serial_version);
2167 * The serial console driver used during boot. Note that these names
2168 * clash with those found in "serial.c", so we currently can't support
2169 * the 16xxx uarts and these at the same time. I will fix this to become
2170 * an indirect function call from tty_io.c (or something).
2173 #ifdef CONFIG_SERIAL_CONSOLE
2176 * Print a string to the serial port trying not to disturb any possible
2177 * real use of the port...
2178 * These funcitons work equally well for SCC, even though they are
2179 * designed for SMC. Our only interests are the transmit/receive
2180 * buffers, which are identically mapped for either the SCC or SMC.
2182 static void my_console_write(int idx, const char *s,
2185 struct serial_state *ser;
2188 volatile cbd_t *bdp, *bdbase;
2189 volatile smc_uart_t *up;
2190 volatile u_char *cp;
2192 ser = rs_table + idx;
2194 /* If the port has been initialized for general use, we have
2195 * to use the buffer descriptors allocated there. Otherwise,
2196 * we simply use the single buffer allocated.
2198 if ((info = (ser_info_t *)ser->info) != NULL) {
2200 bdbase = info->tx_bd_base;
2203 /* Pointer to UART in parameter ram.
2205 up = (smc_uart_t *)&immr->im_dprambase[ser->port];
2207 /* Get the address of the host memory buffer.
2209 bdp = bdbase = (cbd_t *)&immr->im_dprambase[up->smc_tbase];
2213 * We need to gracefully shut down the transmitter, disable
2214 * interrupts, then send our bytes out.
2218 * Now, do each character. This is not as bad as it looks
2219 * since this is a holding FIFO and not a transmitting FIFO.
2220 * We could add the complexity of filling the entire transmit
2221 * buffer, but we would just wait longer between accesses......
2223 for (i = 0; i < count; i++, s++) {
2224 /* Wait for transmitter fifo to empty.
2225 * Ready indicates output is ready, and xmt is doing
2226 * that, not that it is ready for us to send.
2228 while (bdp->cbd_sc & BD_SC_READY);
2230 /* Send the character out.
2231 * If the buffer address is in the CPM DPRAM, don't
2234 if ((uint)(bdp->cbd_bufaddr) > (uint)IMAP_ADDR)
2235 cp = (u_char *)(bdp->cbd_bufaddr);
2237 cp = __va(bdp->cbd_bufaddr);
2240 bdp->cbd_datlen = 1;
2241 bdp->cbd_sc |= BD_SC_READY;
2243 if (bdp->cbd_sc & BD_SC_WRAP)
2248 /* if a LF, also do CR... */
2250 while (bdp->cbd_sc & BD_SC_READY);
2251 cp = __va(bdp->cbd_bufaddr);
2253 bdp->cbd_datlen = 1;
2254 bdp->cbd_sc |= BD_SC_READY;
2256 if (bdp->cbd_sc & BD_SC_WRAP) {
2266 * Finally, Wait for transmitter & holding register to empty
2267 * and restore the IER
2269 while (bdp->cbd_sc & BD_SC_READY);
2272 info->tx_cur = (cbd_t *)bdp;
2275 static void serial_console_write(struct console *c, const char *s,
2278 #if defined(CONFIG_KGDB_CONSOLE) && !defined(CONFIG_USE_SERIAL2_KGDB)
2279 /* Try to let stub handle output. Returns true if it did. */
2280 if (kgdb_output_string(s, count))
2283 my_console_write(c->index, s, count);
2288 xmon_8xx_write(const char *s, unsigned count)
2290 my_console_write(KGDB_SER_IDX, s, count);
2297 putDebugChar(char ch)
2299 my_console_write(KGDB_SER_IDX, &ch, 1);
2303 #if defined(CONFIG_XMON) || defined(CONFIG_KGDB)
2305 * Receive character from the serial port. This only works well
2306 * before the port is initialize for real use.
2308 static int my_console_wait_key(int idx, int xmon, char *obuf)
2310 struct serial_state *ser;
2313 volatile cbd_t *bdp;
2314 volatile smc_uart_t *up;
2317 ser = rs_table + idx;
2319 /* Pointer to UART in parameter ram.
2321 up = (smc_uart_t *)&immr->im_dprambase[ser->port];
2323 /* Get the address of the host memory buffer.
2324 * If the port has been initialized for general use, we must
2325 * use information from the port structure.
2327 if ((info = (ser_info_t *)ser->info))
2330 bdp = (cbd_t *)&immr->im_dprambase[up->smc_rbase];
2333 * We need to gracefully shut down the receiver, disable
2334 * interrupts, then read the input.
2335 * XMON just wants a poll. If no character, return -1, else
2336 * return the character.
2339 while (bdp->cbd_sc & BD_SC_EMPTY);
2342 if (bdp->cbd_sc & BD_SC_EMPTY)
2346 /* If the buffer address is in the CPM DPRAM, don't
2349 if ((uint)(bdp->cbd_bufaddr) > (uint)IMAP_ADDR)
2350 cp = (u_char *)(bdp->cbd_bufaddr);
2352 cp = __va(bdp->cbd_bufaddr);
2355 i = c = bdp->cbd_datlen;
2362 bdp->cbd_sc |= BD_SC_EMPTY;
2365 if (bdp->cbd_sc & BD_SC_WRAP) {
2366 bdp = info->rx_bd_base;
2371 info->rx_cur = (cbd_t *)bdp;
2376 #endif /* CONFIG_XMON || CONFIG_KGDB */
2380 xmon_8xx_read_poll(void)
2382 return(my_console_wait_key(KGDB_SER_IDX, 1, NULL));
2386 xmon_8xx_read_char(void)
2388 return(my_console_wait_key(KGDB_SER_IDX, 0, NULL));
2393 static char kgdb_buf[RX_BUF_SIZE], *kgdp;
2394 static int kgdb_chars;
2399 if (kgdb_chars <= 0) {
2400 kgdb_chars = my_console_wait_key(KGDB_SER_IDX, 0, kgdb_buf);
2408 void kgdb_interruptible(int yes)
2410 volatile smc_t *smcp;
2412 smcp = &immr->im_smc[KGDB_SER_IDX];
2415 smcp->smc_smcm |= SMCM_RX;
2417 smcp->smc_smcm &= ~SMCM_RX;
2420 void kgdb_map_scc(void)
2424 volatile cbd_t *bdp;
2425 volatile smc_uart_t *up;
2427 /* The serial port has already been initialized before
2428 * we get here. We have to assign some pointers needed by
2429 * the kernel, and grab a memory location in the CPM that will
2430 * work until the driver is really initialized.
2432 immr = (immap_t *)IMAP_ADDR;
2434 /* Right now, assume we are using SMCs.
2436 #ifdef USE_KGDB_SMC2
2437 *(ushort *)(&immr->im_dprambase[PROFF_SMC2_BASE]) = serbase = PROFF_SMC2;
2439 *(ushort *)(&immr->im_dprambase[PROFF_SMC1_BASE]) = serbase = PROFF_SMC1;
2441 up = (smc_uart_t *)&immr->im_dprambase[serbase];
2443 /* Allocate space for an input FIFO, plus a few bytes for output.
2444 * Allocate bytes to maintain word alignment.
2446 mem_addr = (uint)(&immr->im_dprambase[0x1000]);
2448 /* Set the physical address of the host memory buffers in
2449 * the buffer descriptors.
2451 bdp = (cbd_t *)&immr->im_dprambase[up->smc_rbase];
2452 bdp->cbd_bufaddr = mem_addr;
2454 bdp = (cbd_t *)&immr->im_dprambase[up->smc_tbase];
2455 bdp->cbd_bufaddr = mem_addr+RX_BUF_SIZE;
2457 up->smc_mrblr = RX_BUF_SIZE; /* receive buffer length */
2458 up->smc_maxidl = RX_BUF_SIZE;
2462 static struct tty_driver *serial_console_device(struct console *c, int *index)
2465 return serial_driver;
2471 static int __init console_8xx_init(void)
2473 register_console(&sercons);
2477 console_initcall(console_8xx_init);
2481 /* Default console baud rate as determined by the board information
2484 static int baud_idx;
2486 static struct tty_operations rs_8xx_ops = {
2487 .open = rs_8xx_open,
2488 .close = rs_8xx_close,
2489 .write = rs_8xx_write,
2490 .put_char = rs_8xx_put_char,
2491 .write_room = rs_8xx_write_room,
2492 .chars_in_buffer = rs_8xx_chars_in_buffer,
2493 .flush_buffer = rs_8xx_flush_buffer,
2494 .ioctl = rs_8xx_ioctl,
2495 .throttle = rs_8xx_throttle,
2496 .unthrottle = rs_8xx_unthrottle,
2497 .send_xchar = rs_8xx_send_xchar,
2498 .set_termios = rs_8xx_set_termios,
2499 .stop = rs_8xx_stop,
2500 .start = rs_8xx_start,
2501 .hangup = rs_8xx_hangup,
2502 .wait_until_sent = rs_8xx_wait_until_sent,
2503 .read_proc = rs_8xx_read_proc,
2507 * The serial driver boot-time initialization code!
2509 static int __init rs_8xx_init(void)
2511 struct serial_state * state;
2513 uint mem_addr, dp_addr;
2516 volatile cbd_t *bdp;
2517 volatile cpm8260_t *cp;
2519 volatile smc_uart_t *up;
2520 volatile scc_t *scp;
2521 volatile scc_uart_t *sup;
2522 volatile immap_t *immap;
2523 volatile iop8260_t *io;
2525 serial_driver = alloc_tty_driver(NR_PORTS);
2529 show_serial_version();
2531 /* Initialize the tty_driver structure */
2533 serial_driver->driver_name = "serial";
2534 serial_driver->devfs_name = "tts/";
2535 serial_driver->name = "ttyS";
2536 serial_driver->major = TTY_MAJOR;
2537 serial_driver->minor_start = 64;
2538 serial_driver->type = TTY_DRIVER_TYPE_SERIAL;
2539 serial_driver->subtype = SERIAL_TYPE_NORMAL;
2540 serial_driver->init_termios = tty_std_termios;
2541 serial_driver->init_termios.c_cflag =
2542 baud_idx | CS8 | CREAD | HUPCL | CLOCAL;
2543 serial_driver->flags = TTY_DRIVER_REAL_RAW;
2544 tty_set_operations(serial_driver, &rs_8xx_ops);
2545 if (tty_register_driver(serial_driver))
2546 panic("Couldn't register serial driver\n");
2549 cp = &immap->im_cpm;
2550 io = &immap->im_ioport;
2552 /* This should have been done long ago by the early boot code,
2553 * but do it again to make sure.
2555 *(ushort *)(&immap->im_dprambase[PROFF_SMC1_BASE]) = PROFF_SMC1;
2556 *(ushort *)(&immap->im_dprambase[PROFF_SMC2_BASE]) = PROFF_SMC2;
2558 /* Geeze, here we go....Picking I/O port bits....Lots of
2559 * choices. If you don't like mine, pick your own.
2560 * Configure SMCs Tx/Rx. SMC1 is only on Port D, SMC2 is
2561 * only on Port A. You either pick 'em, or not.
2564 io->iop_ppard |= 0x00c00000;
2565 io->iop_pdird |= 0x00400000;
2566 io->iop_pdird &= ~0x00800000;
2567 io->iop_psord &= ~0x00c00000;
2569 io->iop_ppara |= 0x00c00000;
2570 io->iop_pdira |= 0x00400000;
2571 io->iop_pdira &= ~0x00800000;
2572 io->iop_psora &= ~0x00c00000;
2575 /* Configure SCC2 and SCC3. Be careful about the fine print.
2576 * Secondary options are only available when you take away
2577 * the primary option. Unless the pins are used for something
2578 * else, SCC2 and SCC3 are on Port B.
2579 * Port B, 8 - SCC3 TxD
2580 * Port B, 12 - SCC2 TxD
2581 * Port B, 14 - SCC3 RxD
2582 * Port B, 15 - SCC2 RxD
2584 io->iop_pparb |= 0x008b0000;
2585 io->iop_pdirb |= 0x00880000;
2586 io->iop_psorb |= 0x00880000;
2587 io->iop_pdirb &= ~0x00030000;
2588 io->iop_psorb &= ~0x00030000;
2590 /* Wire BRG1 to SMC1 and BRG2 to SMC2.
2592 immap->im_cpmux.cmx_smr = 0;
2594 /* Connect SCC2 and SCC3 to NMSI. Connect BRG3 to SCC2 and
2597 immap->im_cpmux.cmx_scr &= ~0x00ffff00;
2598 immap->im_cpmux.cmx_scr |= 0x00121b00;
2600 io->iop_pparb |= 0x008b0000;
2601 io->iop_pdirb |= 0x00880000;
2602 io->iop_psorb |= 0x00880000;
2603 io->iop_pdirb &= ~0x00030000;
2604 io->iop_psorb &= ~0x00030000;
2606 /* Use Port D for SCC1 instead of other functions.
2608 io->iop_ppard |= 0x00000003;
2609 io->iop_psord &= ~0x00000001; /* Rx */
2610 io->iop_psord |= 0x00000002; /* Tx */
2611 io->iop_pdird &= ~0x00000001; /* Rx */
2612 io->iop_pdird |= 0x00000002; /* Tx */
2614 /* Connect SCC1, SCC2, SCC3 to NMSI. Connect BRG1 to SCC1,
2615 * BRG2 to SCC2, BRG3 to SCC3.
2617 immap->im_cpmux.cmx_scr &= ~0xffffff00;
2618 immap->im_cpmux.cmx_scr |= 0x00091200;
2621 for (i = 0, state = rs_table; i < NR_PORTS; i++,state++) {
2622 state->magic = SSTATE_MAGIC;
2624 state->type = PORT_UNKNOWN;
2625 state->custom_divisor = 0;
2626 state->close_delay = 5*HZ/10;
2627 state->closing_wait = 30*HZ;
2628 state->icount.cts = state->icount.dsr =
2629 state->icount.rng = state->icount.dcd = 0;
2630 state->icount.rx = state->icount.tx = 0;
2631 state->icount.frame = state->icount.parity = 0;
2632 state->icount.overrun = state->icount.brk = 0;
2633 printk (KERN_INFO "ttyS%d on %s%d at 0x%04x, BRG%d\n",
2635 (state->smc_scc_num < SCC_NUM_BASE) ? "SMC" : "SCC",
2636 PORT_NUM(state->smc_scc_num) + 1,
2637 (unsigned int)(state->port),
2638 state->smc_scc_num + 1);
2639 #ifdef CONFIG_SERIAL_CONSOLE
2640 /* If we just printed the message on the console port, and
2641 * we are about to initialize it for general use, we have
2642 * to wait a couple of character times for the CR/NL to
2643 * make it out of the transmit buffer.
2645 if (i == CONFIG_SERIAL_CONSOLE_PORT)
2648 info = kmalloc(sizeof(ser_info_t), GFP_KERNEL);
2650 /*memset(info, 0, sizeof(ser_info_t));*/
2651 __clear_user(info,sizeof(ser_info_t));
2652 init_waitqueue_head(&info->open_wait);
2653 init_waitqueue_head(&info->close_wait);
2654 info->magic = SERIAL_MAGIC;
2655 info->flags = state->flags;
2656 INIT_WORK(&info->tqueue, do_softint, info);
2657 INIT_WORK(&info->tqueue_hangup, do_serial_hangup, info);
2659 info->state = state;
2660 state->info = (struct async_struct *)info;
2662 /* We need to allocate a transmit and receive buffer
2663 * descriptors from dual port ram, and a character
2664 * buffer area from host mem.
2666 dp_addr = m8260_cpm_dpalloc(sizeof(cbd_t) * RX_NUM_FIFO, 8);
2668 /* Allocate space for FIFOs in the host memory.
2670 mem_addr = m8260_cpm_hostalloc(RX_NUM_FIFO * RX_BUF_SIZE, 1);
2672 /* Set the physical address of the host memory
2673 * buffers in the buffer descriptors, and the
2674 * virtual address for us to work with.
2676 bdp = (cbd_t *)&immap->im_dprambase[dp_addr];
2677 info->rx_cur = info->rx_bd_base = (cbd_t *)bdp;
2679 for (j=0; j<(RX_NUM_FIFO-1); j++) {
2680 bdp->cbd_bufaddr = __pa(mem_addr);
2681 bdp->cbd_sc = BD_SC_EMPTY | BD_SC_INTRPT;
2682 mem_addr += RX_BUF_SIZE;
2685 bdp->cbd_bufaddr = __pa(mem_addr);
2686 bdp->cbd_sc = BD_SC_WRAP | BD_SC_EMPTY | BD_SC_INTRPT;
2688 if ((idx = state->smc_scc_num) < SCC_NUM_BASE) {
2689 sp = &immap->im_smc[idx];
2690 up = (smc_uart_t *)&immap->im_dprambase[state->port];
2691 up->smc_rbase = dp_addr;
2694 scp = &immap->im_scc[idx - SCC_IDX_BASE];
2695 sup = (scc_uart_t *)&immap->im_dprambase[state->port];
2696 scp->scc_gsmrl &= ~(SCC_GSMRL_ENR | SCC_GSMRL_ENT);
2697 sup->scc_genscc.scc_rbase = dp_addr;
2700 dp_addr = m8260_cpm_dpalloc(sizeof(cbd_t) * TX_NUM_FIFO, 8);
2702 /* Allocate space for FIFOs in the host memory.
2704 mem_addr = m8260_cpm_hostalloc(TX_NUM_FIFO * TX_BUF_SIZE, 1);
2706 /* Set the physical address of the host memory
2707 * buffers in the buffer descriptors, and the
2708 * virtual address for us to work with.
2710 bdp = (cbd_t *)&immap->im_dprambase[dp_addr];
2711 info->tx_cur = info->tx_bd_base = (cbd_t *)bdp;
2713 for (j=0; j<(TX_NUM_FIFO-1); j++) {
2714 bdp->cbd_bufaddr = __pa(mem_addr);
2715 bdp->cbd_sc = BD_SC_INTRPT;
2716 mem_addr += TX_BUF_SIZE;
2719 bdp->cbd_bufaddr = __pa(mem_addr);
2720 bdp->cbd_sc = (BD_SC_WRAP | BD_SC_INTRPT);
2722 if (idx < SCC_NUM_BASE) {
2723 up->smc_tbase = dp_addr;
2725 /* Set up the uart parameters in the
2728 up->smc_rfcr = CPMFCR_GBL | CPMFCR_EB;
2729 up->smc_tfcr = CPMFCR_GBL | CPMFCR_EB;
2731 /* Set this to 1 for now, so we get single
2732 * character interrupts. Using idle charater
2733 * time requires some additional tuning.
2739 /* Send the CPM an initialize command.
2741 if (state->smc_scc_num == 0) {
2742 page = CPM_CR_SMC1_PAGE;
2743 sblock = CPM_CR_SMC1_SBLOCK;
2746 page = CPM_CR_SMC2_PAGE;
2747 sblock = CPM_CR_SMC2_SBLOCK;
2750 cp->cp_cpcr = mk_cr_cmd(page, sblock, 0,
2751 CPM_CR_INIT_TRX) | CPM_CR_FLG;
2752 while (cp->cp_cpcr & CPM_CR_FLG);
2754 /* Set UART mode, 8 bit, no parity, one stop.
2755 * Enable receive and transmit.
2757 sp->smc_smcmr = smcr_mk_clen(9) | SMCMR_SM_UART;
2759 /* Disable all interrupts and clear all pending
2763 sp->smc_smce = 0xff;
2766 sup->scc_genscc.scc_tbase = dp_addr;
2768 /* Set up the uart parameters in the
2771 sup->scc_genscc.scc_rfcr = CPMFCR_GBL | CPMFCR_EB;
2772 sup->scc_genscc.scc_tfcr = CPMFCR_GBL | CPMFCR_EB;
2774 /* Set this to 1 for now, so we get single
2775 * character interrupts. Using idle charater
2776 * time requires some additional tuning.
2778 sup->scc_genscc.scc_mrblr = 1;
2779 sup->scc_maxidl = 0;
2785 sup->scc_uaddr1 = 0;
2786 sup->scc_uaddr2 = 0;
2788 sup->scc_char1 = 0x8000;
2789 sup->scc_char2 = 0x8000;
2790 sup->scc_char3 = 0x8000;
2791 sup->scc_char4 = 0x8000;
2792 sup->scc_char5 = 0x8000;
2793 sup->scc_char6 = 0x8000;
2794 sup->scc_char7 = 0x8000;
2795 sup->scc_char8 = 0x8000;
2796 sup->scc_rccm = 0xc0ff;
2798 /* Send the CPM an initialize command.
2801 switch (state->smc_scc_num) {
2803 page = CPM_CR_SCC1_PAGE;
2804 sblock = CPM_CR_SCC1_SBLOCK;
2807 page = CPM_CR_SCC2_PAGE;
2808 sblock = CPM_CR_SCC2_SBLOCK;
2811 page = CPM_CR_SCC3_PAGE;
2812 sblock = CPM_CR_SCC3_SBLOCK;
2816 if (state->smc_scc_num == 2) {
2817 page = CPM_CR_SCC2_PAGE;
2818 sblock = CPM_CR_SCC2_SBLOCK;
2821 page = CPM_CR_SCC3_PAGE;
2822 sblock = CPM_CR_SCC3_SBLOCK;
2826 cp->cp_cpcr = mk_cr_cmd(page, sblock, 0,
2827 CPM_CR_INIT_TRX) | CPM_CR_FLG;
2828 while (cp->cp_cpcr & CPM_CR_FLG);
2830 /* Set UART mode, 8 bit, no parity, one stop.
2831 * Enable receive and transmit.
2835 (SCC_GSMRL_MODE_UART | SCC_GSMRL_TDCR_16 | SCC_GSMRL_RDCR_16);
2837 /* Disable all interrupts and clear all pending
2841 scp->scc_scce = 0xffff;
2842 scp->scc_dsr = 0x7e7e;
2843 scp->scc_pmsr = 0x3000;
2846 /* Install interrupt handler.
2848 request_irq(state->irq, rs_8xx_interrupt, 0, "uart", info);
2850 /* Set up the baud rate generator.
2852 m8260_cpm_setbrg(state->smc_scc_num,
2853 baud_table[baud_idx]);
2855 /* If the port is the console, enable Rx and Tx.
2857 #ifdef CONFIG_SERIAL_CONSOLE
2858 if (i == CONFIG_SERIAL_CONSOLE_PORT) {
2859 if (idx < SCC_NUM_BASE)
2860 sp->smc_smcmr |= SMCMR_REN | SMCMR_TEN;
2862 scp->scc_gsmrl |= (SCC_GSMRL_ENR | SCC_GSMRL_ENT);
2869 module_init(rs_8xx_init);
2871 /* This must always be called before the rs_8xx_init() function, otherwise
2872 * it blows away the port control information.
2874 static int __init serial_console_setup(struct console *co, char *options)
2876 struct serial_state *ser;
2877 uint mem_addr, dp_addr, bidx;
2878 volatile cbd_t *bdp;
2879 volatile cpm8260_t *cp;
2880 volatile immap_t *immap;
2883 volatile smc_uart_t *up;
2886 volatile scc_t *scp;
2887 volatile scc_uart_t *sup;
2889 volatile iop8260_t *io;
2894 for (bidx = 0; bidx < (sizeof(baud_table) / sizeof(int)); bidx++)
2895 if (bd->bi_baudrate == baud_table[bidx])
2898 co->cflag = CREAD|CLOCAL|bidx|CS8;
2901 ser = rs_table + co->index;
2904 cp = &immap->im_cpm;
2905 io = &immap->im_ioport;
2908 scp = (scc_t *)&(immap->im_scc[SCC_CONSOLE-1]);
2909 sup = (scc_uart_t *)&immap->im_dprambase[PROFF_SCC1 + ((SCC_CONSOLE-1) << 8)];
2910 scp->scc_sccm &= ~(UART_SCCM_TX | UART_SCCM_RX);
2911 scp->scc_gsmrl &= ~(SCC_GSMRL_ENR | SCC_GSMRL_ENT);
2913 /* Use Port D for SCC1 instead of other functions.
2915 io->iop_ppard |= 0x00000003;
2916 io->iop_psord &= ~0x00000001; /* Rx */
2917 io->iop_psord |= 0x00000002; /* Tx */
2918 io->iop_pdird &= ~0x00000001; /* Rx */
2919 io->iop_pdird |= 0x00000002; /* Tx */
2922 /* This should have been done long ago by the early boot code,
2923 * but do it again to make sure.
2925 *(ushort *)(&immap->im_dprambase[PROFF_SMC1_BASE]) = PROFF_SMC1;
2926 *(ushort *)(&immap->im_dprambase[PROFF_SMC2_BASE]) = PROFF_SMC2;
2928 /* Right now, assume we are using SMCs.
2930 sp = &immap->im_smc[ser->smc_scc_num];
2932 /* When we get here, the CPM has been reset, so we need
2933 * to configure the port.
2934 * We need to allocate a transmit and receive buffer descriptor
2935 * from dual port ram, and a character buffer area from host mem.
2937 up = (smc_uart_t *)&immap->im_dprambase[ser->port];
2939 /* Disable transmitter/receiver.
2941 sp->smc_smcmr &= ~(SMCMR_REN | SMCMR_TEN);
2943 /* Use Port D for SMC1 instead of other functions.
2945 io->iop_ppard |= 0x00c00000;
2946 io->iop_pdird |= 0x00400000;
2947 io->iop_pdird &= ~0x00800000;
2948 io->iop_psord &= ~0x00c00000;
2951 /* Allocate space for two buffer descriptors in the DP ram.
2953 dp_addr = m8260_cpm_dpalloc(sizeof(cbd_t) * 2, 8);
2955 /* Allocate space for two 2 byte FIFOs in the host memory.
2957 mem_addr = m8260_cpm_hostalloc(4, 1);
2959 /* Set the physical address of the host memory buffers in
2960 * the buffer descriptors.
2962 bdp = (cbd_t *)&immap->im_dprambase[dp_addr];
2963 bdp->cbd_bufaddr = __pa(mem_addr);
2964 (bdp+1)->cbd_bufaddr = __pa(mem_addr+2);
2966 /* For the receive, set empty and wrap.
2967 * For transmit, set wrap.
2969 bdp->cbd_sc = BD_SC_EMPTY | BD_SC_WRAP;
2970 (bdp+1)->cbd_sc = BD_SC_WRAP;
2972 /* Set up the uart parameters in the parameter ram.
2975 sup->scc_genscc.scc_rbase = dp_addr;
2976 sup->scc_genscc.scc_tbase = dp_addr + sizeof(cbd_t);
2978 /* Set up the uart parameters in the
2981 sup->scc_genscc.scc_rfcr = CPMFCR_GBL | CPMFCR_EB;
2982 sup->scc_genscc.scc_tfcr = CPMFCR_GBL | CPMFCR_EB;
2984 sup->scc_genscc.scc_mrblr = 1;
2985 sup->scc_maxidl = 0;
2991 sup->scc_uaddr1 = 0;
2992 sup->scc_uaddr2 = 0;
2994 sup->scc_char1 = 0x8000;
2995 sup->scc_char2 = 0x8000;
2996 sup->scc_char3 = 0x8000;
2997 sup->scc_char4 = 0x8000;
2998 sup->scc_char5 = 0x8000;
2999 sup->scc_char6 = 0x8000;
3000 sup->scc_char7 = 0x8000;
3001 sup->scc_char8 = 0x8000;
3002 sup->scc_rccm = 0xc0ff;
3004 /* Send the CPM an initialize command.
3006 cp->cp_cpcr = mk_cr_cmd(CPM_CR_SCC1_PAGE, CPM_CR_SCC1_SBLOCK, 0,
3007 CPM_CR_INIT_TRX) | CPM_CR_FLG;
3008 while (cp->cp_cpcr & CPM_CR_FLG);
3010 /* Set UART mode, 8 bit, no parity, one stop.
3011 * Enable receive and transmit.
3015 (SCC_GSMRL_MODE_UART | SCC_GSMRL_TDCR_16 | SCC_GSMRL_RDCR_16);
3017 /* Disable all interrupts and clear all pending
3021 scp->scc_scce = 0xffff;
3022 scp->scc_dsr = 0x7e7e;
3023 scp->scc_pmsr = 0x3000;
3025 /* Wire BRG1 to SCC1. The serial init will take care of
3028 immap->im_cpmux.cmx_scr = 0;
3030 /* Set up the baud rate generator.
3032 m8260_cpm_setbrg(ser->smc_scc_num, bd->bi_baudrate);
3034 scp->scc_gsmrl |= (SCC_GSMRL_ENR | SCC_GSMRL_ENT);
3036 up->smc_rbase = dp_addr; /* Base of receive buffer desc. */
3037 up->smc_tbase = dp_addr+sizeof(cbd_t); /* Base of xmt buffer desc. */
3038 up->smc_rfcr = CPMFCR_GBL | CPMFCR_EB;
3039 up->smc_tfcr = CPMFCR_GBL | CPMFCR_EB;
3041 /* Set this to 1 for now, so we get single character interrupts.
3043 up->smc_mrblr = 1; /* receive buffer length */
3044 up->smc_maxidl = 0; /* wait forever for next char */
3046 /* Send the CPM an initialize command.
3048 cp->cp_cpcr = mk_cr_cmd(CPM_CR_SMC1_PAGE, CPM_CR_SMC1_SBLOCK, 0,
3049 CPM_CR_INIT_TRX) | CPM_CR_FLG;
3050 while (cp->cp_cpcr & CPM_CR_FLG);
3052 /* Set UART mode, 8 bit, no parity, one stop.
3053 * Enable receive and transmit.
3055 sp->smc_smcmr = smcr_mk_clen(9) | SMCMR_SM_UART;
3057 /* Set up the baud rate generator.
3059 m8260_cpm_setbrg(ser->smc_scc_num, bd->bi_baudrate);
3061 /* And finally, enable Rx and Tx.
3063 sp->smc_smcmr |= SMCMR_REN | SMCMR_TEN;