2 * UART driver for MPC860 CPM SCC or SMC
3 * Copyright (c) 1997 Dan Malek (dmalek@jlc.net)
5 * I used the serial.c driver as the framework for this driver.
6 * Give credit to those guys.
7 * The original code was written for the MBX860 board. I tried to make
8 * it generic, but there may be some assumptions in the structures that
9 * have to be fixed later.
10 * To save porting time, I did not bother to change any object names
11 * that are not accessed outside of this file.
12 * It still needs lots of work........When it was easy, I included code
13 * to support the SCCs, but this has never been tested, nor is it complete.
14 * Only the SCCs support modem control, so that is not complete either.
17 #include <linux/config.h>
18 #include <linux/module.h>
19 #include <linux/errno.h>
20 #include <linux/signal.h>
21 #include <linux/sched.h>
22 #include <linux/timer.h>
23 #include <linux/interrupt.h>
24 #include <linux/tty.h>
25 #include <linux/tty_flip.h>
26 #include <linux/serial.h>
27 #include <linux/serialP.h>
28 #include <linux/major.h>
29 #include <linux/string.h>
30 #include <linux/fcntl.h>
31 #include <linux/ptrace.h>
33 #include <linux/slab.h>
34 #include <linux/init.h>
35 #include <linux/delay.h>
36 #include <asm/uaccess.h>
37 #include <asm/8xx_immap.h>
38 #include <asm/mpc8xx.h>
39 #include <asm/commproc.h>
40 #ifdef CONFIG_MAGIC_SYSRQ
41 #include <linux/sysrq.h>
48 #ifdef CONFIG_SERIAL_CONSOLE
49 #include <linux/console.h>
51 /* this defines the index into rs_table for the port to use
53 # ifndef CONFIG_SERIAL_CONSOLE_PORT
54 # ifdef CONFIG_SCC3_ENET
55 # ifdef CONFIG_CONS_SMC2
56 # define CONFIG_SERIAL_CONSOLE_PORT 0 /* Console on SMC2 is 1st port */
58 # error "Can't use SMC1 for console with Ethernet on SCC3"
60 # else /* ! CONFIG_SCC3_ENET */
61 # ifdef CONFIG_CONS_SMC2 /* Console on SMC2 */
62 # define CONFIG_SERIAL_CONSOLE_PORT 1
63 # else /* Console on SMC1 */
64 # define CONFIG_SERIAL_CONSOLE_PORT 0
65 # endif /* CONFIG_CONS_SMC2 */
66 # endif /* CONFIG_SCC3_ENET */
67 # endif /* CONFIG_SERIAL_CONSOLE_PORT */
68 #endif /* CONFIG_SERIAL_CONSOLE */
73 #undef CONFIG_SERIAL_CONSOLE_PORT
74 #define CONFIG_SERIAL_CONSOLE_PORT 2
77 #define TX_WAKEUP ASYNC_SHARE_IRQ
79 static char *serial_name = "CPM UART driver";
80 static char *serial_version = "0.03";
82 static DECLARE_TASK_QUEUE(tq_serial);
84 static struct tty_driver *serial_driver;
85 static int serial_console_setup(struct console *co, char *options);
87 static void serial_console_write(struct console *c, const char *s,
89 static struct tty_driver *serial_console_device(struct console *c, int *index)
91 #if defined(CONFIG_SERIAL_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ)
92 static unsigned long break_pressed; /* break, really ... */
96 * Serial driver configuration section. Here are the various options:
98 #define SERIAL_PARANOIA_CHECK
99 #define CONFIG_SERIAL_NOPAUSE_IO
100 #define SERIAL_DO_RESTART
102 /* Set of debugging defines */
104 #undef SERIAL_DEBUG_INTR
105 #undef SERIAL_DEBUG_OPEN
106 #undef SERIAL_DEBUG_FLOW
107 #undef SERIAL_DEBUG_RS_WAIT_UNTIL_SENT
109 #define _INLINE_ inline
113 /* We overload some of the items in the data structure to meet our
114 * needs. For example, the port address is the CPM parameter ram
115 * offset for the SCC or SMC. The maximum number of ports is 4 SCCs and
116 * 2 SMCs. The "hub6" field is used to indicate the channel number, with
117 * a flag indicating SCC or SMC, and the number is used as an index into
118 * the CPM parameter area for this device.
119 * The "type" field is currently set to 0, for PORT_UNKNOWN. It is
120 * not currently used. I should probably use it to indicate the port
121 * type of SMC or SCC.
122 * The SMCs do not support any modem control signals.
124 #define smc_scc_num hub6
125 #define NUM_IS_SCC ((int)0x00010000)
126 #define PORT_NUM(P) ((P) & 0x0000ffff)
128 /* The choice of serial port to use for KGDB. If the system has
129 * two ports, you can use one for console and one for KGDB (which
130 * doesn't make sense to me, but people asked for it).
132 #ifdef CONFIG_KGDB_TTYS1
133 #define KGDB_SER_IDX 1 /* SCC2/SMC2 */
135 #define KGDB_SER_IDX 0 /* SCC1/SMC1 */
138 /* Processors other than the 860 only get SMCs configured by default.
139 * Either they don't have SCCs or they are allocated somewhere else.
140 * Of course, there are now 860s without some SCCs, so we will need to
141 * address that someday.
142 * The Embedded Planet Multimedia I/O cards use TDM interfaces to the
143 * stereo codec parts, and we use SMC2 to help support that.
145 static struct serial_state rs_table[] = {
146 /* UART CLK PORT IRQ FLAGS NUM */
147 #ifndef CONFIG_SCC3_ENET /* SMC1 not usable with Ethernet on SCC3 */
148 { 0, 0, PROFF_SMC1, CPMVEC_SMC1, 0, 0 }, /* SMC1 ttyS0 */
150 #if !defined(CONFIG_USB_MPC8xx) && !defined(CONFIG_USB_CLIENT_MPC8xx)
151 # ifdef CONFIG_SMC2_UART
152 { 0, 0, PROFF_SMC2, CPMVEC_SMC2, 0, 1 }, /* SMC2 ttyS1 */
154 # ifdef CONFIG_USE_SCC_IO
155 { 0, 0, PROFF_SCC2, CPMVEC_SCC2, 0, (NUM_IS_SCC | 1) }, /* SCC2 ttyS2 */
156 { 0, 0, PROFF_SCC3, CPMVEC_SCC3, 0, (NUM_IS_SCC | 2) }, /* SCC3 ttyS3 */
158 #else /* CONFIG_USB_xxx */
159 # ifdef CONFIG_USE_SCC_IO
160 { 0, 0, PROFF_SCC3, CPMVEC_SCC3, 0, (NUM_IS_SCC | 2) }, /* SCC3 ttyS3 */
162 #endif /* CONFIG_USB_xxx */
165 #define NR_PORTS (sizeof(rs_table)/sizeof(struct serial_state))
167 /* The number of buffer descriptors and their sizes.
169 #define RX_NUM_FIFO 4
170 #define RX_BUF_SIZE 32
171 #define TX_NUM_FIFO 4
172 #define TX_BUF_SIZE 32
174 /* The async_struct in serial.h does not really give us what we
175 * need, so define our own here.
177 typedef struct serial_info {
180 struct serial_state *state;
181 struct tty_struct *tty;
182 int read_status_mask;
183 int ignore_status_mask;
186 int x_char; /* xon/xoff character */
188 unsigned short closing_wait;
189 unsigned short closing_wait2;
191 unsigned long last_active;
192 int blocked_open; /* # of blocked opens */
193 struct tq_struct tqueue;
194 struct tq_struct tqueue_hangup;
195 wait_queue_head_t open_wait;
196 wait_queue_head_t close_wait;
198 /* CPM Buffer Descriptor pointers.
205 /* Virtual addresses for the FIFOs because we can't __va() a
206 * physical address anymore.
208 unsigned char *rx_va_base;
209 unsigned char *tx_va_base;
212 static struct console sercons = {
214 .write = serial_console_write,
215 .device = serial_console_device,
216 .setup = serial_console_setup,
217 .flags = CON_PRINTBUFFER,
218 .index = CONFIG_SERIAL_CONSOLE_PORT,
221 static void change_speed(ser_info_t *info);
222 static void rs_8xx_wait_until_sent(struct tty_struct *tty, int timeout);
224 static inline int serial_paranoia_check(ser_info_t *info,
225 char *name, const char *routine)
227 #ifdef SERIAL_PARANOIA_CHECK
228 static const char *badmagic =
229 "Warning: bad magic number for serial struct (%s) in %s\n";
230 static const char *badinfo =
231 "Warning: null async_struct for (%s) in %s\n";
234 printk(badinfo, name, routine);
237 if (info->magic != SERIAL_MAGIC) {
238 printk(badmagic, name, routine);
246 * This is used to figure out the divisor speeds and the timeouts,
247 * indexed by the termio value. The generic CPM functions are responsible
248 * for setting and assigning baud rate generators for us.
250 static int baud_table[] = {
251 0, 50, 75, 110, 134, 150, 200, 300, 600, 1200, 1800, 2400, 4800,
252 9600, 19200, 38400, 57600, 115200, 230400, 460800, 0 };
256 * ------------------------------------------------------------
257 * rs_stop() and rs_start()
259 * This routines are called before setting or resetting tty->stopped.
260 * They enable or disable transmitter interrupts, as necessary.
261 * ------------------------------------------------------------
263 static void rs_8xx_stop(struct tty_struct *tty)
265 ser_info_t *info = (ser_info_t *)tty->driver_data;
268 volatile scc_t *sccp;
269 volatile smc_t *smcp;
271 if (serial_paranoia_check(info, tty->name, "rs_stop"))
274 save_flags(flags); cli();
275 idx = PORT_NUM(info->state->smc_scc_num);
276 if (info->state->smc_scc_num & NUM_IS_SCC) {
277 sccp = &cpmp->cp_scc[idx];
278 sccp->scc_sccm &= ~UART_SCCM_TX;
281 smcp = &cpmp->cp_smc[idx];
282 smcp->smc_smcm &= ~SMCM_TX;
284 restore_flags(flags);
287 static void rs_8xx_start(struct tty_struct *tty)
289 ser_info_t *info = (ser_info_t *)tty->driver_data;
292 volatile scc_t *sccp;
293 volatile smc_t *smcp;
295 if (serial_paranoia_check(info, tty->name, "rs_stop"))
298 idx = PORT_NUM(info->state->smc_scc_num);
299 save_flags(flags); cli();
300 if (info->state->smc_scc_num & NUM_IS_SCC) {
301 sccp = &cpmp->cp_scc[idx];
302 sccp->scc_sccm |= UART_SCCM_TX;
305 smcp = &cpmp->cp_smc[idx];
306 smcp->smc_smcm |= SMCM_TX;
308 restore_flags(flags);
312 * ----------------------------------------------------------------------
314 * Here starts the interrupt handling routines. All of the following
315 * subroutines are declared as inline and are folded into
316 * rs_interrupt(). They were separated out for readability's sake.
318 * Note: rs_interrupt() is a "fast" interrupt, which means that it
319 * runs with interrupts turned off. People who may want to modify
320 * rs_interrupt() should try to keep the interrupt handler as fast as
321 * possible. After you are done making modifications, it is not a bad
324 * gcc -S -DKERNEL -Wall -Wstrict-prototypes -O6 -fomit-frame-pointer serial.c
326 * and look at the resulting assemble code in serial.s.
328 * - Ted Ts'o (tytso@mit.edu), 7-Mar-93
329 * -----------------------------------------------------------------------
333 * This routine is used by the interrupt handler to schedule
334 * processing in the software interrupt portion of the driver.
336 static _INLINE_ void rs_sched_event(ser_info_t *info,
339 info->event |= 1 << event;
340 queue_task(&info->tqueue, &tq_serial);
344 static _INLINE_ void receive_chars(ser_info_t *info, struct pt_regs *regs)
346 struct tty_struct *tty = info->tty;
347 unsigned char ch, *cp;
351 struct async_icount *icount;
354 icount = &info->state->icount;
356 /* Just loop through the closed BDs and copy the characters into
361 if (bdp->cbd_sc & BD_SC_EMPTY) /* If this one is empty */
362 break; /* we are all done */
364 /* The read status mask tell us what we should do with
365 * incoming characters, especially if errors occur.
366 * One special case is the use of BD_SC_EMPTY. If
367 * this is not set, we are supposed to be ignoring
368 * inputs. In this case, just mark the buffer empty and
370 if (!(info->read_status_mask & BD_SC_EMPTY)) {
371 bdp->cbd_sc |= BD_SC_EMPTY;
373 ~(BD_SC_BR | BD_SC_FR | BD_SC_PR | BD_SC_OV);
375 if (bdp->cbd_sc & BD_SC_WRAP)
376 bdp = info->rx_bd_base;
383 /* Get the number of characters and the buffer pointer.
386 cp = info->rx_va_base + ((bdp - info->rx_bd_base) * RX_BUF_SIZE);
387 status = bdp->cbd_sc;
389 if (info->state->smc_scc_num == KGDB_SER_IDX) {
390 if (*cp == 0x03 || *cp == '$')
396 /* Check to see if there is room in the tty buffer for
397 * the characters in our BD buffer. If not, we exit
398 * now, leaving the BD with the characters. We'll pick
399 * them up again on the next receive interrupt (which could
402 if ((tty->flip.count + i) >= TTY_FLIPBUF_SIZE)
407 *tty->flip.char_buf_ptr = ch;
410 #ifdef SERIAL_DEBUG_INTR
411 printk("DR%02x:%02x...", ch, status);
413 *tty->flip.flag_buf_ptr = 0;
414 if (status & (BD_SC_BR | BD_SC_FR |
415 BD_SC_PR | BD_SC_OV)) {
417 * For statistics only
419 if (status & BD_SC_BR)
421 else if (status & BD_SC_PR)
423 else if (status & BD_SC_FR)
425 if (status & BD_SC_OV)
429 * Now check to see if character should be
430 * ignored, and mask off conditions which
432 if (status & info->ignore_status_mask) {
438 status &= info->read_status_mask;
440 if (status & (BD_SC_BR)) {
441 #ifdef SERIAL_DEBUG_INTR
442 printk("handling break....");
444 *tty->flip.flag_buf_ptr = TTY_BREAK;
445 if (info->flags & ASYNC_SAK)
447 } else if (status & BD_SC_PR)
448 *tty->flip.flag_buf_ptr = TTY_PARITY;
449 else if (status & BD_SC_FR)
450 *tty->flip.flag_buf_ptr = TTY_FRAME;
451 if (status & BD_SC_OV) {
453 * Overrun is special, since it's
454 * reported immediately, and doesn't
455 * affect the current character
457 if (tty->flip.count < TTY_FLIPBUF_SIZE) {
459 tty->flip.flag_buf_ptr++;
460 tty->flip.char_buf_ptr++;
461 *tty->flip.flag_buf_ptr =
466 #if defined(CONFIG_SERIAL_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ)
467 if (break_pressed && info->line == sercons.index) {
468 if (ch != 0 && time_before(jiffies,
469 break_pressed + HZ*5)) {
470 handle_sysrq(ch, regs, NULL);
477 if (tty->flip.count >= TTY_FLIPBUF_SIZE)
480 tty->flip.flag_buf_ptr++;
481 tty->flip.char_buf_ptr++;
485 #if defined(CONFIG_SERIAL_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ)
488 /* This BD is ready to be used again. Clear status.
491 bdp->cbd_sc |= BD_SC_EMPTY;
492 bdp->cbd_sc &= ~(BD_SC_BR | BD_SC_FR | BD_SC_PR | BD_SC_OV);
494 if (bdp->cbd_sc & BD_SC_WRAP)
495 bdp = info->rx_bd_base;
499 info->rx_cur = (cbd_t *)bdp;
501 queue_task(&tty->flip.tqueue, &tq_timer);
504 static _INLINE_ void receive_break(ser_info_t *info, struct pt_regs *regs)
506 struct tty_struct *tty = info->tty;
508 info->state->icount.brk++;
510 #if defined(CONFIG_SERIAL_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ)
511 if (info->line == sercons.index) {
512 if (!break_pressed) {
513 break_pressed = jiffies;
520 /* Check to see if there is room in the tty buffer for
521 * the break. If not, we exit now, losing the break. FIXME
523 if ((tty->flip.count + 1) >= TTY_FLIPBUF_SIZE)
525 *(tty->flip.flag_buf_ptr++) = TTY_BREAK;
526 *(tty->flip.char_buf_ptr++) = 0;
529 queue_task(&tty->flip.tqueue, &tq_timer);
532 static _INLINE_ void transmit_chars(ser_info_t *info, struct pt_regs *regs)
535 if ((info->flags & TX_WAKEUP) ||
536 (info->tty->flags & (1 << TTY_DO_WRITE_WAKEUP))) {
537 rs_sched_event(info, RS_EVENT_WRITE_WAKEUP);
540 #ifdef SERIAL_DEBUG_INTR
546 /* I need to do this for the SCCs, so it is left as a reminder.
548 static _INLINE_ void check_modem_status(struct async_struct *info)
551 struct async_icount *icount;
553 status = serial_in(info, UART_MSR);
555 if (status & UART_MSR_ANY_DELTA) {
556 icount = &info->state->icount;
557 /* update input line counters */
558 if (status & UART_MSR_TERI)
560 if (status & UART_MSR_DDSR)
562 if (status & UART_MSR_DDCD) {
564 #ifdef CONFIG_HARD_PPS
565 if ((info->flags & ASYNC_HARDPPS_CD) &&
566 (status & UART_MSR_DCD))
570 if (status & UART_MSR_DCTS)
572 wake_up_interruptible(&info->delta_msr_wait);
575 if ((info->flags & ASYNC_CHECK_CD) && (status & UART_MSR_DDCD)) {
576 #if (defined(SERIAL_DEBUG_OPEN) || defined(SERIAL_DEBUG_INTR))
577 printk("ttys%d CD now %s...", info->line,
578 (status & UART_MSR_DCD) ? "on" : "off");
580 if (status & UART_MSR_DCD)
581 wake_up_interruptible(&info->open_wait);
583 #ifdef SERIAL_DEBUG_OPEN
584 printk("scheduling hangup...");
587 if (schedule_task(&info->tqueue_hangup) == 0)
591 if (info->flags & ASYNC_CTS_FLOW) {
592 if (info->tty->hw_stopped) {
593 if (status & UART_MSR_CTS) {
594 #if (defined(SERIAL_DEBUG_INTR) || defined(SERIAL_DEBUG_FLOW))
595 printk("CTS tx start...");
597 info->tty->hw_stopped = 0;
598 info->IER |= UART_IER_THRI;
599 serial_out(info, UART_IER, info->IER);
600 rs_sched_event(info, RS_EVENT_WRITE_WAKEUP);
604 if (!(status & UART_MSR_CTS)) {
605 #if (defined(SERIAL_DEBUG_INTR) || defined(SERIAL_DEBUG_FLOW))
606 printk("CTS tx stop...");
608 info->tty->hw_stopped = 1;
609 info->IER &= ~UART_IER_THRI;
610 serial_out(info, UART_IER, info->IER);
618 * This is the serial driver's interrupt routine for a single port
620 static void rs_8xx_interrupt(void *dev_id, struct pt_regs *regs)
625 volatile smc_t *smcp;
626 volatile scc_t *sccp;
628 info = (ser_info_t *)dev_id;
630 idx = PORT_NUM(info->state->smc_scc_num);
631 if (info->state->smc_scc_num & NUM_IS_SCC) {
632 sccp = &cpmp->cp_scc[idx];
633 events = sccp->scc_scce;
634 if (events & SMCM_BRKE)
635 receive_break(info, regs);
636 if (events & SCCM_RX)
637 receive_chars(info, regs);
638 if (events & SCCM_TX)
639 transmit_chars(info, regs);
640 sccp->scc_scce = events;
643 smcp = &cpmp->cp_smc[idx];
644 events = smcp->smc_smce;
645 if (events & SMCM_BRKE)
646 receive_break(info, regs);
647 if (events & SMCM_RX)
648 receive_chars(info, regs);
649 if (events & SMCM_TX)
650 transmit_chars(info, regs);
651 smcp->smc_smce = events;
654 #ifdef SERIAL_DEBUG_INTR
655 printk("rs_interrupt_single(%d, %x)...",
656 info->state->smc_scc_num, events);
659 check_modem_status(info);
661 info->last_active = jiffies;
662 #ifdef SERIAL_DEBUG_INTR
669 * -------------------------------------------------------------------
670 * Here ends the serial interrupt routines.
671 * -------------------------------------------------------------------
675 * This routine is used to handle the "bottom half" processing for the
676 * serial driver, known also the "software interrupt" processing.
677 * This processing is done at the kernel interrupt level, after the
678 * rs_interrupt() has returned, BUT WITH INTERRUPTS TURNED ON. This
679 * is where time-consuming activities which can not be done in the
680 * interrupt driver proper are done; the interrupt driver schedules
681 * them using rs_sched_event(), and they get done here.
683 static void do_serial_bh(void)
685 run_task_queue(&tq_serial);
688 static void do_softint(void *private_)
690 ser_info_t *info = (ser_info_t *) private_;
691 struct tty_struct *tty;
697 if (test_and_clear_bit(RS_EVENT_WRITE_WAKEUP, &info->event)) {
698 if ((tty->flags & (1 << TTY_DO_WRITE_WAKEUP)) &&
699 tty->ldisc.write_wakeup)
700 (tty->ldisc.write_wakeup)(tty);
701 wake_up_interruptible(&tty->write_wait);
706 * This routine is called from the scheduler tqueue when the interrupt
707 * routine has signalled that a hangup has occurred. The path of
708 * hangup processing is:
710 * serial interrupt routine -> (scheduler tqueue) ->
711 * do_serial_hangup() -> tty->hangup() -> rs_hangup()
714 static void do_serial_hangup(void *private_)
716 struct async_struct *info = (struct async_struct *) private_;
717 struct tty_struct *tty;
725 /*static void rs_8xx_timer(void)
727 printk("rs_8xx_timer\n");
731 static int startup(ser_info_t *info)
736 struct serial_state *state= info->state;
737 volatile smc_t *smcp;
738 volatile scc_t *sccp;
739 volatile smc_uart_t *up;
740 volatile scc_uart_t *scup;
743 save_flags(flags); cli();
745 if (info->flags & ASYNC_INITIALIZED) {
750 if (!state->port || !state->type) {
752 set_bit(TTY_IO_ERROR, &info->tty->flags);
757 #ifdef SERIAL_DEBUG_OPEN
758 printk("starting up ttys%d (irq %d)...", info->line, state->irq);
764 if (info->tty->termios->c_cflag & CBAUD)
765 info->MCR = UART_MCR_DTR | UART_MCR_RTS;
769 clear_bit(TTY_IO_ERROR, &info->tty->flags);
772 * and set the speed of the serial port
776 idx = PORT_NUM(info->state->smc_scc_num);
777 if (info->state->smc_scc_num & NUM_IS_SCC) {
778 sccp = &cpmp->cp_scc[idx];
779 scup = (scc_uart_t *)&cpmp->cp_dparam[state->port];
780 scup->scc_genscc.scc_mrblr = RX_BUF_SIZE;
781 scup->scc_maxidl = RX_BUF_SIZE;
782 sccp->scc_sccm |= (UART_SCCM_TX | UART_SCCM_RX);
783 sccp->scc_gsmrl |= (SCC_GSMRL_ENR | SCC_GSMRL_ENT);
786 smcp = &cpmp->cp_smc[idx];
788 /* Enable interrupts and I/O.
790 smcp->smc_smcm |= (SMCM_RX | SMCM_TX);
791 smcp->smc_smcmr |= (SMCMR_REN | SMCMR_TEN);
793 /* We can tune the buffer length and idle characters
794 * to take advantage of the entire incoming buffer size.
795 * If mrblr is something other than 1, maxidl has to be
796 * non-zero or we never get an interrupt. The maxidl
797 * is the number of character times we wait after reception
798 * of the last character before we decide no more characters
801 up = (smc_uart_t *)&cpmp->cp_dparam[state->port];
802 up->smc_mrblr = RX_BUF_SIZE;
803 up->smc_maxidl = RX_BUF_SIZE;
804 up->smc_brkcr = 1; /* number of break chars */
807 info->flags |= ASYNC_INITIALIZED;
808 restore_flags(flags);
812 restore_flags(flags);
817 * This routine will shutdown a serial port; interrupts are disabled, and
818 * DTR is dropped if the hangup on close termio flag is on.
820 static void shutdown(ser_info_t * info)
823 struct serial_state *state;
825 volatile smc_t *smcp;
826 volatile scc_t *sccp;
828 if (!(info->flags & ASYNC_INITIALIZED))
833 #ifdef SERIAL_DEBUG_OPEN
834 printk("Shutting down serial port %d (irq %d)....", info->line,
838 save_flags(flags); cli(); /* Disable interrupts */
840 idx = PORT_NUM(state->smc_scc_num);
841 if (state->smc_scc_num & NUM_IS_SCC) {
842 sccp = &cpmp->cp_scc[idx];
843 sccp->scc_gsmrl &= ~(SCC_GSMRL_ENR | SCC_GSMRL_ENT);
844 #ifdef CONFIG_SERIAL_CONSOLE
845 /* We can't disable the transmitter if this is the
848 if ((state - rs_table) != CONFIG_SERIAL_CONSOLE_PORT)
850 sccp->scc_sccm &= ~(UART_SCCM_TX | UART_SCCM_RX);
853 smcp = &cpmp->cp_smc[idx];
855 /* Disable interrupts and I/O.
857 smcp->smc_smcm &= ~(SMCM_RX | SMCM_TX);
858 #ifdef CONFIG_SERIAL_CONSOLE
859 /* We can't disable the transmitter if this is the
862 if ((state - rs_table) != CONFIG_SERIAL_CONSOLE_PORT)
864 smcp->smc_smcmr &= ~(SMCMR_REN | SMCMR_TEN);
868 set_bit(TTY_IO_ERROR, &info->tty->flags);
870 info->flags &= ~ASYNC_INITIALIZED;
871 restore_flags(flags);
875 * This routine is called to set the UART divisor registers to match
876 * the specified baud rate for a serial port.
878 static void change_speed(ser_info_t *info)
881 unsigned cflag, cval, scval, prev_mode, new_mode;
882 int i, bits, sbits, idx;
884 struct serial_state *state;
885 volatile smc_t *smcp;
886 volatile scc_t *sccp;
888 if (!info->tty || !info->tty->termios)
890 cflag = info->tty->termios->c_cflag;
894 /* Character length programmed into the mode register is the
895 * sum of: 1 start bit, number of data bits, 0 or 1 parity bit,
896 * 1 or 2 stop bits, minus 1.
897 * The value 'bits' counts this for us.
902 /* byte size and parity */
903 switch (cflag & CSIZE) {
904 case CS5: bits = 5; break;
905 case CS6: bits = 6; break;
906 case CS7: bits = 7; break;
907 case CS8: bits = 8; break;
908 /* Never happens, but GCC is too dumb to figure it out */
909 default: bits = 8; break;
913 if (cflag & CSTOPB) {
914 cval |= SMCMR_SL; /* Two stops */
915 scval |= SCU_PMSR_SL;
918 if (cflag & PARENB) {
920 scval |= SCU_PMSR_PEN;
922 if (!(cflag & PARODD)) {
923 cval |= SMCMR_PM_EVEN;
924 scval |= (SCU_PMSR_REVP | SCU_PMSR_TEVP);
928 /* Determine divisor based on baud rate */
930 if (i >= (sizeof(baud_table)/sizeof(int)))
933 baud_rate = baud_table[i];
935 info->timeout = (TX_BUF_SIZE*HZ*bits);
936 info->timeout += HZ/50; /* Add .02 seconds of slop */
939 /* CTS flow control flag and modem status interrupts */
940 info->IER &= ~UART_IER_MSI;
941 if (info->flags & ASYNC_HARDPPS_CD)
942 info->IER |= UART_IER_MSI;
943 if (cflag & CRTSCTS) {
944 info->flags |= ASYNC_CTS_FLOW;
945 info->IER |= UART_IER_MSI;
947 info->flags &= ~ASYNC_CTS_FLOW;
949 info->flags &= ~ASYNC_CHECK_CD;
951 info->flags |= ASYNC_CHECK_CD;
952 info->IER |= UART_IER_MSI;
954 serial_out(info, UART_IER, info->IER);
958 * Set up parity check flag
960 #define RELEVANT_IFLAG(iflag) (iflag & (IGNBRK|BRKINT|IGNPAR|PARMRK|INPCK))
962 info->read_status_mask = (BD_SC_EMPTY | BD_SC_OV);
963 if (I_INPCK(info->tty))
964 info->read_status_mask |= BD_SC_FR | BD_SC_PR;
965 if (I_BRKINT(info->tty) || I_PARMRK(info->tty))
966 info->read_status_mask |= BD_SC_BR;
969 * Characters to ignore
971 info->ignore_status_mask = 0;
972 if (I_IGNPAR(info->tty))
973 info->ignore_status_mask |= BD_SC_PR | BD_SC_FR;
974 if (I_IGNBRK(info->tty)) {
975 info->ignore_status_mask |= BD_SC_BR;
977 * If we're ignore parity and break indicators, ignore
978 * overruns too. (For real raw support).
980 if (I_IGNPAR(info->tty))
981 info->ignore_status_mask |= BD_SC_OV;
984 * !!! ignore all characters if CREAD is not set
986 if ((cflag & CREAD) == 0)
987 info->read_status_mask &= ~BD_SC_EMPTY;
988 save_flags(flags); cli();
990 /* Start bit has not been added (so don't, because we would just
991 * subtract it later), and we need to add one for the number of
992 * stops bits (there is always at least one).
995 idx = PORT_NUM(state->smc_scc_num);
996 if (state->smc_scc_num & NUM_IS_SCC) {
997 sccp = &cpmp->cp_scc[idx];
998 new_mode = (sbits << 12) | scval;
999 prev_mode = sccp->scc_pmsr;
1000 if (!(prev_mode & SCU_PMSR_PEN))
1001 /* If parity is disabled, mask out even/odd */
1002 prev_mode &= ~(SCU_PMSR_TPM|SCU_PMSR_RPM);
1003 if (prev_mode != new_mode)
1004 sccp->scc_pmsr = new_mode;
1007 smcp = &cpmp->cp_smc[idx];
1009 /* Set the mode register. We want to keep a copy of the
1010 * enables, because we want to put them back if they were
1013 prev_mode = smcp->smc_smcmr;
1014 new_mode = smcr_mk_clen(bits) | cval | SMCMR_SM_UART;
1015 new_mode |= (prev_mode & (SMCMR_REN | SMCMR_TEN));
1016 if (!(prev_mode & SMCMR_PEN))
1017 /* If parity is disabled, mask out even/odd */
1018 prev_mode &= ~SMCMR_PM_EVEN;
1019 if (prev_mode != new_mode)
1020 smcp->smc_smcmr = new_mode;
1023 m8xx_cpm_setbrg((state - rs_table), baud_rate);
1025 restore_flags(flags);
1028 static void rs_8xx_put_char(struct tty_struct *tty, unsigned char ch)
1030 ser_info_t *info = (ser_info_t *)tty->driver_data;
1031 volatile cbd_t *bdp;
1034 if (serial_paranoia_check(info, tty->name, "rs_put_char"))
1041 while (bdp->cbd_sc & BD_SC_READY);
1043 cp = info->tx_va_base + ((bdp - info->tx_bd_base) * TX_BUF_SIZE);
1045 bdp->cbd_datlen = 1;
1046 bdp->cbd_sc |= BD_SC_READY;
1050 if (bdp->cbd_sc & BD_SC_WRAP)
1051 bdp = info->tx_bd_base;
1055 info->tx_cur = (cbd_t *)bdp;
1059 static int rs_8xx_write(struct tty_struct * tty, int from_user,
1060 const unsigned char *buf, int count)
1063 ser_info_t *info = (ser_info_t *)tty->driver_data;
1064 volatile cbd_t *bdp;
1067 #ifdef CONFIG_KGDB_CONSOLE
1068 /* Try to let stub handle output. Returns true if it did. */
1069 if (kgdb_output_string(buf, count))
1073 if (serial_paranoia_check(info, tty->name, "rs_write"))
1082 c = min(count, TX_BUF_SIZE);
1087 if (bdp->cbd_sc & BD_SC_READY) {
1088 info->flags |= TX_WAKEUP;
1092 cp = info->tx_va_base + ((bdp - info->tx_bd_base) * TX_BUF_SIZE);
1094 if (copy_from_user((void *)cp, buf, c)) {
1100 memcpy((void *)cp, buf, c);
1103 bdp->cbd_datlen = c;
1104 bdp->cbd_sc |= BD_SC_READY;
1112 if (bdp->cbd_sc & BD_SC_WRAP)
1113 bdp = info->tx_bd_base;
1116 info->tx_cur = (cbd_t *)bdp;
1121 static int rs_8xx_write_room(struct tty_struct *tty)
1123 ser_info_t *info = (ser_info_t *)tty->driver_data;
1126 if (serial_paranoia_check(info, tty->name, "rs_write_room"))
1129 if ((info->tx_cur->cbd_sc & BD_SC_READY) == 0) {
1130 info->flags &= ~TX_WAKEUP;
1134 info->flags |= TX_WAKEUP;
1140 /* I could track this with transmit counters....maybe later.
1142 static int rs_8xx_chars_in_buffer(struct tty_struct *tty)
1144 ser_info_t *info = (ser_info_t *)tty->driver_data;
1146 if (serial_paranoia_check(info, tty->name, "rs_chars_in_buffer"))
1151 static void rs_8xx_flush_buffer(struct tty_struct *tty)
1153 ser_info_t *info = (ser_info_t *)tty->driver_data;
1155 if (serial_paranoia_check(info, tty->name, "rs_flush_buffer"))
1158 /* There is nothing to "flush", whatever we gave the CPM
1159 * is on its way out.
1161 wake_up_interruptible(&tty->write_wait);
1162 if ((tty->flags & (1 << TTY_DO_WRITE_WAKEUP)) &&
1163 tty->ldisc.write_wakeup)
1164 (tty->ldisc.write_wakeup)(tty);
1165 info->flags &= ~TX_WAKEUP;
1169 * This function is used to send a high-priority XON/XOFF character to
1172 static void rs_8xx_send_xchar(struct tty_struct *tty, char ch)
1174 volatile cbd_t *bdp;
1177 ser_info_t *info = (ser_info_t *)tty->driver_data;
1179 if (serial_paranoia_check(info, tty->name, "rs_send_char"))
1183 while (bdp->cbd_sc & BD_SC_READY);
1185 cp = info->tx_va_base + ((bdp - info->tx_bd_base) * TX_BUF_SIZE);
1187 bdp->cbd_datlen = 1;
1188 bdp->cbd_sc |= BD_SC_READY;
1192 if (bdp->cbd_sc & BD_SC_WRAP)
1193 bdp = info->tx_bd_base;
1197 info->tx_cur = (cbd_t *)bdp;
1201 * ------------------------------------------------------------
1204 * This routine is called by the upper-layer tty layer to signal that
1205 * incoming characters should be throttled.
1206 * ------------------------------------------------------------
1208 static void rs_8xx_throttle(struct tty_struct * tty)
1210 ser_info_t *info = (ser_info_t *)tty->driver_data;
1211 #ifdef SERIAL_DEBUG_THROTTLE
1214 printk("throttle %s: %d....\n", _tty_name(tty, buf),
1215 tty->ldisc.chars_in_buffer(tty));
1218 if (serial_paranoia_check(info, tty->name, "rs_throttle"))
1222 rs_8xx_send_xchar(tty, STOP_CHAR(tty));
1224 #ifdef modem_control
1225 if (tty->termios->c_cflag & CRTSCTS)
1226 info->MCR &= ~UART_MCR_RTS;
1229 serial_out(info, UART_MCR, info->MCR);
1234 static void rs_8xx_unthrottle(struct tty_struct * tty)
1236 ser_info_t *info = (ser_info_t *)tty->driver_data;
1237 #ifdef SERIAL_DEBUG_THROTTLE
1240 printk("unthrottle %s: %d....\n", _tty_name(tty, buf),
1241 tty->ldisc.chars_in_buffer(tty));
1244 if (serial_paranoia_check(info, tty->name, "rs_unthrottle"))
1251 rs_8xx_send_xchar(tty, START_CHAR(tty));
1253 #ifdef modem_control
1254 if (tty->termios->c_cflag & CRTSCTS)
1255 info->MCR |= UART_MCR_RTS;
1257 serial_out(info, UART_MCR, info->MCR);
1263 * ------------------------------------------------------------
1264 * rs_ioctl() and friends
1265 * ------------------------------------------------------------
1270 * get_lsr_info - get line status register info
1272 * Purpose: Let user call ioctl() to get info when the UART physically
1273 * is emptied. On bus types like RS485, the transmitter must
1274 * release the bus after transmitting. This must be done when
1275 * the transmit shift register is empty, not be done when the
1276 * transmit holding register is empty. This functionality
1277 * allows an RS485 driver to be written in user space.
1279 static int get_lsr_info(struct async_struct * info, unsigned int *value)
1281 unsigned char status;
1282 unsigned int result;
1285 status = serial_in(info, UART_LSR);
1287 result = ((status & UART_LSR_TEMT) ? TIOCSER_TEMT : 0);
1288 return put_user(result,value);
1292 static int get_modem_info(ser_info_t *info, unsigned int *value)
1294 unsigned int result = 0;
1295 #ifdef modem_control
1296 unsigned char control, status;
1298 control = info->MCR;
1300 status = serial_in(info, UART_MSR);
1302 result = ((control & UART_MCR_RTS) ? TIOCM_RTS : 0)
1303 | ((control & UART_MCR_DTR) ? TIOCM_DTR : 0)
1305 | ((control & UART_MCR_OUT1) ? TIOCM_OUT1 : 0)
1306 | ((control & UART_MCR_OUT2) ? TIOCM_OUT2 : 0)
1308 | ((status & UART_MSR_DCD) ? TIOCM_CAR : 0)
1309 | ((status & UART_MSR_RI) ? TIOCM_RNG : 0)
1310 | ((status & UART_MSR_DSR) ? TIOCM_DSR : 0)
1311 | ((status & UART_MSR_CTS) ? TIOCM_CTS : 0);
1313 return put_user(result,value);
1316 static int set_modem_info(ser_info_t *info, unsigned int cmd,
1317 unsigned int *value)
1322 error = get_user(arg, value);
1325 #ifdef modem_control
1328 if (arg & TIOCM_RTS)
1329 info->MCR |= UART_MCR_RTS;
1330 if (arg & TIOCM_DTR)
1331 info->MCR |= UART_MCR_DTR;
1333 if (arg & TIOCM_OUT1)
1334 info->MCR |= UART_MCR_OUT1;
1335 if (arg & TIOCM_OUT2)
1336 info->MCR |= UART_MCR_OUT2;
1340 if (arg & TIOCM_RTS)
1341 info->MCR &= ~UART_MCR_RTS;
1342 if (arg & TIOCM_DTR)
1343 info->MCR &= ~UART_MCR_DTR;
1345 if (arg & TIOCM_OUT1)
1346 info->MCR &= ~UART_MCR_OUT1;
1347 if (arg & TIOCM_OUT2)
1348 info->MCR &= ~UART_MCR_OUT2;
1352 info->MCR = ((info->MCR & ~(UART_MCR_RTS |
1358 | ((arg & TIOCM_RTS) ? UART_MCR_RTS : 0)
1360 | ((arg & TIOCM_OUT1) ? UART_MCR_OUT1 : 0)
1361 | ((arg & TIOCM_OUT2) ? UART_MCR_OUT2 : 0)
1363 | ((arg & TIOCM_DTR) ? UART_MCR_DTR : 0));
1369 serial_out(info, UART_MCR, info->MCR);
1375 /* Sending a break is a two step process on the SMC/SCC. It is accomplished
1376 * by sending a STOP TRANSMIT command followed by a RESTART TRANSMIT
1377 * command. We take advantage of the begin/end functions to make this
1380 static ushort smc_chan_map[] = {
1385 static ushort scc_chan_map[] = {
1392 static void begin_break(ser_info_t *info)
1394 volatile cpm8xx_t *cp;
1400 idx = PORT_NUM(info->state->smc_scc_num);
1401 if (info->state->smc_scc_num & NUM_IS_SCC)
1402 chan = scc_chan_map[idx];
1404 chan = smc_chan_map[idx];
1405 cp->cp_cpcr = mk_cr_cmd(chan, CPM_CR_STOP_TX) | CPM_CR_FLG;
1406 while (cp->cp_cpcr & CPM_CR_FLG);
1409 static void end_break(ser_info_t *info)
1411 volatile cpm8xx_t *cp;
1417 idx = PORT_NUM(info->state->smc_scc_num);
1418 if (info->state->smc_scc_num & NUM_IS_SCC)
1419 chan = scc_chan_map[idx];
1421 chan = smc_chan_map[idx];
1422 cp->cp_cpcr = mk_cr_cmd(chan, CPM_CR_RESTART_TX) | CPM_CR_FLG;
1423 while (cp->cp_cpcr & CPM_CR_FLG);
1427 * This routine sends a break character out the serial port.
1429 static void send_break(ser_info_t *info, int duration)
1431 current->state = TASK_INTERRUPTIBLE;
1432 #ifdef SERIAL_DEBUG_SEND_BREAK
1433 printk("rs_send_break(%d) jiff=%lu...", duration, jiffies);
1436 schedule_timeout(duration);
1438 #ifdef SERIAL_DEBUG_SEND_BREAK
1439 printk("done jiffies=%lu\n", jiffies);
1444 static int rs_8xx_ioctl(struct tty_struct *tty, struct file * file,
1445 unsigned int cmd, unsigned long arg)
1448 ser_info_t *info = (ser_info_t *)tty->driver_data;
1450 struct async_icount cnow; /* kernel counter temps */
1451 struct serial_icounter_struct *p_cuser; /* user space */
1453 if (serial_paranoia_check(info, tty->name, "rs_ioctl"))
1456 if ((cmd != TIOCMIWAIT) && (cmd != TIOCGICOUNT)) {
1457 if (tty->flags & (1 << TTY_IO_ERROR))
1462 case TCSBRK: /* SVID version: non-zero arg --> no break */
1463 retval = tty_check_change(tty);
1466 tty_wait_until_sent(tty, 0);
1467 if (signal_pending(current))
1470 send_break(info, HZ/4); /* 1/4 second */
1471 if (signal_pending(current))
1475 case TCSBRKP: /* support for POSIX tcsendbreak() */
1476 retval = tty_check_change(tty);
1479 tty_wait_until_sent(tty, 0);
1480 if (signal_pending(current))
1482 send_break(info, arg ? arg*(HZ/10) : HZ/4);
1483 if (signal_pending(current))
1487 retval = tty_check_change(tty);
1490 tty_wait_until_sent(tty, 0);
1494 retval = tty_check_change(tty);
1500 return put_user(C_CLOCAL(tty) ? 1 : 0, (int *) arg);
1502 error = get_user(arg, (unsigned int *) arg);
1505 tty->termios->c_cflag =
1506 ((tty->termios->c_cflag & ~CLOCAL) |
1507 (arg ? CLOCAL : 0));
1510 return get_modem_info(info, (unsigned int *) arg);
1514 return set_modem_info(info, cmd, (unsigned int *) arg);
1516 case TIOCSERGETLSR: /* Get line status register */
1517 return get_lsr_info(info, (unsigned int *) arg);
1520 * Wait for any of the 4 modem inputs (DCD,RI,DSR,CTS) to change
1521 * - mask passed in arg for lines of interest
1522 * (use |'ed TIOCM_RNG/DSR/CD/CTS for masking)
1523 * Caller should use TIOCGICOUNT to see which one it was
1526 #ifdef modem_control
1528 /* note the counters on entry */
1529 cprev = info->state->icount;
1532 interruptible_sleep_on(&info->delta_msr_wait);
1533 /* see if a signal did it */
1534 if (signal_pending(current))
1535 return -ERESTARTSYS;
1537 cnow = info->state->icount; /* atomic copy */
1539 if (cnow.rng == cprev.rng && cnow.dsr == cprev.dsr &&
1540 cnow.dcd == cprev.dcd && cnow.cts == cprev.cts)
1541 return -EIO; /* no change => error */
1542 if ( ((arg & TIOCM_RNG) && (cnow.rng != cprev.rng)) ||
1543 ((arg & TIOCM_DSR) && (cnow.dsr != cprev.dsr)) ||
1544 ((arg & TIOCM_CD) && (cnow.dcd != cprev.dcd)) ||
1545 ((arg & TIOCM_CTS) && (cnow.cts != cprev.cts)) ) {
1556 * Get counter of input serial line interrupts (DCD,RI,DSR,CTS)
1557 * Return: write counters to the user passed counter struct
1558 * NB: both 1->0 and 0->1 transitions are counted except for
1559 * RI where only 0->1 is counted.
1563 cnow = info->state->icount;
1565 p_cuser = (struct serial_icounter_struct *) arg;
1566 error = put_user(cnow.cts, &p_cuser->cts);
1567 if (error) return error;
1568 error = put_user(cnow.dsr, &p_cuser->dsr);
1569 if (error) return error;
1570 error = put_user(cnow.rng, &p_cuser->rng);
1571 if (error) return error;
1572 error = put_user(cnow.dcd, &p_cuser->dcd);
1573 if (error) return error;
1577 return -ENOIOCTLCMD;
1582 /* FIX UP modem control here someday......
1584 static void rs_8xx_set_termios(struct tty_struct *tty, struct termios *old_termios)
1586 ser_info_t *info = (ser_info_t *)tty->driver_data;
1588 if ( (tty->termios->c_cflag == old_termios->c_cflag)
1589 && ( RELEVANT_IFLAG(tty->termios->c_iflag)
1590 == RELEVANT_IFLAG(old_termios->c_iflag)))
1595 #ifdef modem_control
1596 /* Handle transition to B0 status */
1597 if ((old_termios->c_cflag & CBAUD) &&
1598 !(tty->termios->c_cflag & CBAUD)) {
1599 info->MCR &= ~(UART_MCR_DTR|UART_MCR_RTS);
1601 serial_out(info, UART_MCR, info->MCR);
1605 /* Handle transition away from B0 status */
1606 if (!(old_termios->c_cflag & CBAUD) &&
1607 (tty->termios->c_cflag & CBAUD)) {
1608 info->MCR |= UART_MCR_DTR;
1609 if (!tty->hw_stopped ||
1610 !(tty->termios->c_cflag & CRTSCTS)) {
1611 info->MCR |= UART_MCR_RTS;
1614 serial_out(info, UART_MCR, info->MCR);
1618 /* Handle turning off CRTSCTS */
1619 if ((old_termios->c_cflag & CRTSCTS) &&
1620 !(tty->termios->c_cflag & CRTSCTS)) {
1621 tty->hw_stopped = 0;
1628 * No need to wake up processes in open wait, since they
1629 * sample the CLOCAL flag once, and don't recheck it.
1630 * XXX It's not clear whether the current behavior is correct
1631 * or not. Hence, this may change.....
1633 if (!(old_termios->c_cflag & CLOCAL) &&
1634 (tty->termios->c_cflag & CLOCAL))
1635 wake_up_interruptible(&info->open_wait);
1640 * ------------------------------------------------------------
1643 * This routine is called when the serial port gets closed. First, we
1644 * wait for the last remaining data to be sent. Then, we unlink its
1645 * async structure from the interrupt chain if necessary, and we free
1646 * that IRQ if nothing is left in the chain.
1647 * ------------------------------------------------------------
1649 static void rs_8xx_close(struct tty_struct *tty, struct file * filp)
1651 ser_info_t *info = (ser_info_t *)tty->driver_data;
1652 struct serial_state *state;
1653 unsigned long flags;
1655 volatile smc_t *smcp;
1656 volatile scc_t *sccp;
1658 if (!info || serial_paranoia_check(info, tty->name, "rs_close"))
1661 state = info->state;
1663 save_flags(flags); cli();
1665 if (tty_hung_up_p(filp)) {
1666 DBG_CNT("before DEC-hung");
1668 restore_flags(flags);
1672 #ifdef SERIAL_DEBUG_OPEN
1673 printk("rs_close ttys%d, count = %d\n", info->line, state->count);
1675 if ((tty->count == 1) && (state->count != 1)) {
1677 * Uh, oh. tty->count is 1, which means that the tty
1678 * structure will be freed. state->count should always
1679 * be one in these conditions. If it's greater than
1680 * one, we've got real problems, since it means the
1681 * serial port won't be shutdown.
1683 printk("rs_close: bad serial port count; tty->count is 1, "
1684 "state->count is %d\n", state->count);
1687 if (--state->count < 0) {
1688 printk("rs_close: bad serial port count for ttys%d: %d\n",
1689 info->line, state->count);
1693 DBG_CNT("before DEC-2");
1695 restore_flags(flags);
1698 info->flags |= ASYNC_CLOSING;
1700 * Now we wait for the transmit buffer to clear; and we notify
1701 * the line discipline to only process XON/XOFF characters.
1704 if (info->closing_wait != ASYNC_CLOSING_WAIT_NONE)
1705 tty_wait_until_sent(tty, info->closing_wait);
1707 * At this point we stop accepting input. To do this, we
1708 * disable the receive line status interrupts, and tell the
1709 * interrupt driver to stop checking the data ready bit in the
1710 * line status register.
1712 info->read_status_mask &= ~BD_SC_EMPTY;
1713 if (info->flags & ASYNC_INITIALIZED) {
1714 idx = PORT_NUM(info->state->smc_scc_num);
1715 if (info->state->smc_scc_num & NUM_IS_SCC) {
1716 sccp = &cpmp->cp_scc[idx];
1717 sccp->scc_sccm &= ~UART_SCCM_RX;
1718 sccp->scc_gsmrl &= ~SCC_GSMRL_ENR;
1721 smcp = &cpmp->cp_smc[idx];
1722 smcp->smc_smcm &= ~SMCM_RX;
1723 smcp->smc_smcmr &= ~SMCMR_REN;
1726 * Before we drop DTR, make sure the UART transmitter
1727 * has completely drained; this is especially
1728 * important if there is a transmit FIFO!
1730 rs_8xx_wait_until_sent(tty, info->timeout);
1733 if (tty->driver->flush_buffer)
1734 tty->driver->flush_buffer(tty);
1735 if (tty->ldisc.flush_buffer)
1736 tty->ldisc.flush_buffer(tty);
1740 if (info->blocked_open) {
1741 if (info->close_delay) {
1742 current->state = TASK_INTERRUPTIBLE;
1743 schedule_timeout(info->close_delay);
1745 wake_up_interruptible(&info->open_wait);
1747 info->flags &= ~(ASYNC_NORMAL_ACTIVE|ASYNC_CLOSING);
1748 wake_up_interruptible(&info->close_wait);
1750 restore_flags(flags);
1754 * rs_wait_until_sent() --- wait until the transmitter is empty
1756 static void rs_8xx_wait_until_sent(struct tty_struct *tty, int timeout)
1758 ser_info_t *info = (ser_info_t *)tty->driver_data;
1759 unsigned long orig_jiffies, char_time;
1761 volatile cbd_t *bdp;
1763 if (serial_paranoia_check(info, tty->name, "rs_wait_until_sent"))
1767 if (info->state->type == PORT_UNKNOWN)
1771 orig_jiffies = jiffies;
1773 * Set the check interval to be 1/5 of the estimated time to
1774 * send a single character, and make it at least 1. The check
1775 * interval should also be less than the timeout.
1777 * Note: we have to use pretty tight timings here to satisfy
1782 char_time = min(char_time, timeout);
1783 #ifdef SERIAL_DEBUG_RS_WAIT_UNTIL_SENT
1784 printk("In rs_wait_until_sent(%d) check=%lu...", timeout, char_time);
1785 printk("jiff=%lu...", jiffies);
1788 /* We go through the loop at least once because we can't tell
1789 * exactly when the last character exits the shifter. There can
1790 * be at least two characters waiting to be sent after the buffers
1794 #ifdef SERIAL_DEBUG_RS_WAIT_UNTIL_SENT
1795 printk("lsr = %d (jiff=%lu)...", lsr, jiffies);
1797 current->state = TASK_INTERRUPTIBLE;
1798 /* current->dyn_prio = 0; make us low-priority */
1799 schedule_timeout(char_time);
1800 if (signal_pending(current))
1802 if (timeout && time_after(jiffies, orig_jiffies + timeout))
1805 /* The 'tx_cur' is really the next buffer to send. We
1806 * have to back up to the previous BD and wait for it
1807 * to go. This isn't perfect, because all this indicates
1808 * is the buffer is available. There are still characters
1812 if (bdp == info->tx_bd_base)
1813 bdp += (TX_NUM_FIFO-1);
1816 } while (bdp->cbd_sc & BD_SC_READY);
1817 current->state = TASK_RUNNING;
1818 #ifdef SERIAL_DEBUG_RS_WAIT_UNTIL_SENT
1819 printk("lsr = %d (jiff=%lu)...done\n", lsr, jiffies);
1824 * rs_hangup() --- called by tty_hangup() when a hangup is signaled.
1826 static void rs_8xx_hangup(struct tty_struct *tty)
1828 ser_info_t *info = (ser_info_t *)tty->driver_data;
1829 struct serial_state *state = info->state;
1831 if (serial_paranoia_check(info, tty->name, "rs_hangup"))
1834 state = info->state;
1836 rs_8xx_flush_buffer(tty);
1840 info->flags &= ~ASYNC_NORMAL_ACTIVE;
1842 wake_up_interruptible(&info->open_wait);
1846 * ------------------------------------------------------------
1847 * rs_open() and friends
1848 * ------------------------------------------------------------
1850 static int block_til_ready(struct tty_struct *tty, struct file * filp,
1853 #ifdef DO_THIS_LATER
1854 DECLARE_WAITQUEUE(wait, current);
1856 struct serial_state *state = info->state;
1861 * If the device is in the middle of being closed, then block
1862 * until it's done, and then try again.
1864 if (tty_hung_up_p(filp) ||
1865 (info->flags & ASYNC_CLOSING)) {
1866 if (info->flags & ASYNC_CLOSING)
1867 interruptible_sleep_on(&info->close_wait);
1868 #ifdef SERIAL_DO_RESTART
1869 if (info->flags & ASYNC_HUP_NOTIFY)
1872 return -ERESTARTSYS;
1879 * If non-blocking mode is set, or the port is not enabled,
1880 * then make the check up front and then exit.
1881 * If this is an SMC port, we don't have modem control to wait
1882 * for, so just get out here.
1884 if ((filp->f_flags & O_NONBLOCK) ||
1885 (tty->flags & (1 << TTY_IO_ERROR)) ||
1886 !(info->state->smc_scc_num & NUM_IS_SCC)) {
1887 info->flags |= ASYNC_NORMAL_ACTIVE;
1891 if (tty->termios->c_cflag & CLOCAL)
1895 * Block waiting for the carrier detect and the line to become
1896 * free (i.e., not in use by the callout). While we are in
1897 * this loop, state->count is dropped by one, so that
1898 * rs_close() knows when to free things. We restore it upon
1899 * exit, either normal or abnormal.
1902 #ifdef DO_THIS_LATER
1903 add_wait_queue(&info->open_wait, &wait);
1904 #ifdef SERIAL_DEBUG_OPEN
1905 printk("block_til_ready before block: ttys%d, count = %d\n",
1906 state->line, state->count);
1909 if (!tty_hung_up_p(filp))
1912 info->blocked_open++;
1915 if ((tty->termios->c_cflag & CBAUD))
1916 serial_out(info, UART_MCR,
1917 serial_inp(info, UART_MCR) |
1918 (UART_MCR_DTR | UART_MCR_RTS));
1920 set_current_state(TASK_INTERRUPTIBLE);
1921 if (tty_hung_up_p(filp) ||
1922 !(info->flags & ASYNC_INITIALIZED)) {
1923 #ifdef SERIAL_DO_RESTART
1924 if (info->flags & ASYNC_HUP_NOTIFY)
1927 retval = -ERESTARTSYS;
1933 if (!(info->flags & ASYNC_CLOSING) &&
1934 (do_clocal || (serial_in(info, UART_MSR) &
1937 if (signal_pending(current)) {
1938 retval = -ERESTARTSYS;
1941 #ifdef SERIAL_DEBUG_OPEN
1942 printk("block_til_ready blocking: ttys%d, count = %d\n",
1943 info->line, state->count);
1947 current->state = TASK_RUNNING;
1948 remove_wait_queue(&info->open_wait, &wait);
1949 if (!tty_hung_up_p(filp))
1951 info->blocked_open--;
1952 #ifdef SERIAL_DEBUG_OPEN
1953 printk("block_til_ready after blocking: ttys%d, count = %d\n",
1954 info->line, state->count);
1956 #endif /* DO_THIS_LATER */
1959 info->flags |= ASYNC_NORMAL_ACTIVE;
1963 static int get_async_struct(int line, ser_info_t **ret_info)
1965 struct serial_state *sstate;
1967 sstate = rs_table + line;
1970 *ret_info = (ser_info_t *)sstate->info;
1979 * This routine is called whenever a serial port is opened. It
1980 * enables interrupts for a serial port, linking in its async structure into
1981 * the IRQ chain. It also performs the serial-specific
1982 * initialization for the tty structure.
1984 static int rs_8xx_open(struct tty_struct *tty, struct file * filp)
1990 if ((line < 0) || (line >= NR_PORTS))
1992 retval = get_async_struct(line, &info);
1995 if (serial_paranoia_check(info, tty->name, "rs_open"))
1998 #ifdef SERIAL_DEBUG_OPEN
1999 printk("rs_open %s, count = %d\n", tty->name, info->state->count);
2001 tty->driver_data = info;
2005 * Start up serial port
2007 retval = startup(info);
2012 retval = block_til_ready(tty, filp, info);
2014 #ifdef SERIAL_DEBUG_OPEN
2015 printk("rs_open returning after block_til_ready with %d\n",
2022 #ifdef SERIAL_DEBUG_OPEN
2023 printk("rs_open %s successful...", tty->name);
2029 * /proc fs routines....
2032 static inline int line_info(char *buf, struct serial_state *state)
2035 struct async_struct *info = state->info, scr_info;
2036 char stat_buf[30], control, status;
2040 ret = sprintf(buf, "%d: uart:%s port:%X irq:%d",
2042 (state->smc_scc_num & NUM_IS_SCC) ? "SCC" : "SMC",
2043 (unsigned int)(state->port), state->irq);
2045 if (!state->port || (state->type == PORT_UNKNOWN)) {
2046 ret += sprintf(buf+ret, "\n");
2052 * Figure out the current RS-232 lines
2055 info = &scr_info; /* This is just for serial_{in,out} */
2057 info->magic = SERIAL_MAGIC;
2058 info->port = state->port;
2059 info->flags = state->flags;
2064 status = serial_in(info, UART_MSR);
2065 control = info ? info->MCR : serial_in(info, UART_MCR);
2070 if (control & UART_MCR_RTS)
2071 strcat(stat_buf, "|RTS");
2072 if (status & UART_MSR_CTS)
2073 strcat(stat_buf, "|CTS");
2074 if (control & UART_MCR_DTR)
2075 strcat(stat_buf, "|DTR");
2076 if (status & UART_MSR_DSR)
2077 strcat(stat_buf, "|DSR");
2078 if (status & UART_MSR_DCD)
2079 strcat(stat_buf, "|CD");
2080 if (status & UART_MSR_RI)
2081 strcat(stat_buf, "|RI");
2084 ret += sprintf(buf+ret, " baud:%d",
2085 state->baud_base / info->quot);
2088 ret += sprintf(buf+ret, " tx:%d rx:%d",
2089 state->icount.tx, state->icount.rx);
2091 if (state->icount.frame)
2092 ret += sprintf(buf+ret, " fe:%d", state->icount.frame);
2094 if (state->icount.parity)
2095 ret += sprintf(buf+ret, " pe:%d", state->icount.parity);
2097 if (state->icount.brk)
2098 ret += sprintf(buf+ret, " brk:%d", state->icount.brk);
2100 if (state->icount.overrun)
2101 ret += sprintf(buf+ret, " oe:%d", state->icount.overrun);
2104 * Last thing is the RS-232 status lines
2106 ret += sprintf(buf+ret, " %s\n", stat_buf+1);
2111 int rs_8xx_read_proc(char *page, char **start, off_t off, int count,
2112 int *eof, void *data)
2117 len += sprintf(page, "serinfo:1.0 driver:%s\n", serial_version);
2118 for (i = 0; i < NR_PORTS && len < 4000; i++) {
2119 len += line_info(page + len, &rs_table[i]);
2120 if (len+begin > off+count)
2122 if (len+begin < off) {
2129 if (off >= len+begin)
2131 *start = page + (begin-off);
2132 return ((count < begin+len-off) ? count : begin+len-off);
2136 * ---------------------------------------------------------------------
2137 * rs_init() and friends
2139 * rs_init() is called at boot-time to initialize the serial driver.
2140 * ---------------------------------------------------------------------
2144 * This routine prints out the appropriate serial driver version
2145 * number, and identifies which options were configured into this
2148 static _INLINE_ void show_serial_version(void)
2150 printk(KERN_INFO "%s version %s\n", serial_name, serial_version);
2155 * The serial console driver used during boot. Note that these names
2156 * clash with those found in "serial.c", so we currently can't support
2157 * the 16xxx uarts and these at the same time. I will fix this to become
2158 * an indirect function call from tty_io.c (or something).
2161 #ifdef CONFIG_SERIAL_CONSOLE
2163 /* I need this just so I can store the virtual addresses and have
2164 * common functions for the early console printing.
2166 static ser_info_t consinfo;
2169 * Print a string to the serial port trying not to disturb any possible
2170 * real use of the port...
2172 static void my_console_write(int idx, const char *s,
2175 struct serial_state *ser;
2178 volatile cbd_t *bdp, *bdbase;
2179 volatile smc_uart_t *up;
2180 volatile u_char *cp;
2182 ser = rs_table + idx;
2184 /* If the port has been initialized for general use, we have
2185 * to use the buffer descriptors allocated there. Otherwise,
2186 * we simply use the single buffer allocated.
2188 if ((info = (ser_info_t *)ser->info) != NULL) {
2190 bdbase = info->tx_bd_base;
2193 /* Pointer to UART in parameter ram.
2195 up = (smc_uart_t *)&cpmp->cp_dparam[ser->port];
2197 /* Get the address of the host memory buffer.
2199 bdp = bdbase = (cbd_t *)&cpmp->cp_dpmem[up->smc_tbase];
2205 * We need to gracefully shut down the transmitter, disable
2206 * interrupts, then send our bytes out.
2210 * Now, do each character. This is not as bad as it looks
2211 * since this is a holding FIFO and not a transmitting FIFO.
2212 * We could add the complexity of filling the entire transmit
2213 * buffer, but we would just wait longer between accesses......
2215 for (i = 0; i < count; i++, s++) {
2216 /* Wait for transmitter fifo to empty.
2217 * Ready indicates output is ready, and xmt is doing
2218 * that, not that it is ready for us to send.
2220 while (bdp->cbd_sc & BD_SC_READY);
2222 /* Send the character out.
2223 * If the buffer address is in the CPM DPRAM, don't
2226 if ((uint)(bdp->cbd_bufaddr) > (uint)IMAP_ADDR)
2227 cp = (u_char *)(bdp->cbd_bufaddr);
2229 cp = info->tx_va_base + ((bdp - info->tx_bd_base) * TX_BUF_SIZE);
2232 bdp->cbd_datlen = 1;
2233 bdp->cbd_sc |= BD_SC_READY;
2235 if (bdp->cbd_sc & BD_SC_WRAP)
2240 /* if a LF, also do CR... */
2242 while (bdp->cbd_sc & BD_SC_READY);
2243 cp = info->tx_va_base + ((bdp - info->tx_bd_base) * TX_BUF_SIZE);
2245 bdp->cbd_datlen = 1;
2246 bdp->cbd_sc |= BD_SC_READY;
2248 if (bdp->cbd_sc & BD_SC_WRAP) {
2258 * Finally, Wait for transmitter & holding register to empty
2259 * and restore the IER
2261 while (bdp->cbd_sc & BD_SC_READY);
2264 info->tx_cur = (cbd_t *)bdp;
2267 static void serial_console_write(struct console *c, const char *s,
2270 #ifdef CONFIG_KGDB_CONSOLE
2271 /* Try to let stub handle output. Returns true if it did. */
2272 if (kgdb_output_string(s, count))
2275 my_console_write(c->index, s, count);
2280 xmon_8xx_write(const char *s, unsigned count)
2282 my_console_write(0, s, count);
2289 putDebugChar(char ch)
2291 my_console_write(0, &ch, 1);
2296 * Receive character from the serial port. This only works well
2297 * before the port is initialized for real use.
2299 static int my_console_wait_key(int idx, int xmon, char *obuf)
2301 struct serial_state *ser;
2304 volatile cbd_t *bdp;
2305 volatile smc_uart_t *up;
2308 ser = rs_table + idx;
2310 /* Pointer to UART in parameter ram.
2312 up = (smc_uart_t *)&cpmp->cp_dparam[ser->port];
2314 /* Get the address of the host memory buffer.
2315 * If the port has been initialized for general use, we must
2316 * use information from the port structure.
2318 if ((info = (ser_info_t *)ser->info)) {
2322 bdp = (cbd_t *)&cpmp->cp_dpmem[up->smc_rbase];
2327 * We need to gracefully shut down the receiver, disable
2328 * interrupts, then read the input.
2329 * XMON just wants a poll. If no character, return -1, else
2330 * return the character.
2333 while (bdp->cbd_sc & BD_SC_EMPTY);
2336 if (bdp->cbd_sc & BD_SC_EMPTY)
2340 /* If the buffer address is in the CPM DPRAM, don't
2343 if ((uint)(bdp->cbd_bufaddr) > (uint)IMAP_ADDR)
2344 cp = (u_char *)(bdp->cbd_bufaddr);
2346 cp = info->rx_va_base + ((bdp - info->rx_bd_base) * RX_BUF_SIZE);
2349 i = c = bdp->cbd_datlen;
2356 bdp->cbd_sc |= BD_SC_EMPTY;
2359 if (bdp->cbd_sc & BD_SC_WRAP) {
2360 bdp = info->rx_bd_base;
2365 info->rx_cur = (cbd_t *)bdp;
2373 xmon_8xx_read_poll(void)
2375 return(my_console_wait_key(0, 1, NULL));
2379 xmon_8xx_read_char(void)
2381 return(my_console_wait_key(0, 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(0, 0, kgdb_buf);
2401 void kgdb_interruptible(int yes)
2403 volatile smc_t *smcp;
2405 smcp = &cpmp->cp_smc[KGDB_SER_IDX];
2408 smcp->smc_smcm |= SMCM_RX;
2410 smcp->smc_smcm &= ~SMCM_RX;
2413 void kgdb_map_scc(void)
2415 struct serial_state *ser;
2417 volatile cbd_t *bdp;
2418 volatile smc_uart_t *up;
2420 cpmp = (cpm8xx_t *)&(((immap_t *)IMAP_ADDR)->im_cpm);
2422 /* To avoid data cache CPM DMA coherency problems, allocate a
2423 * buffer in the CPM DPRAM. This will work until the CPM and
2424 * serial ports are initialized. At that time a memory buffer
2425 * will be allocated.
2426 * The port is already initialized from the boot procedure, all
2427 * we do here is give it a different buffer and make it a FIFO.
2432 /* Right now, assume we are using SMCs.
2434 up = (smc_uart_t *)&cpmp->cp_dparam[ser->port];
2436 /* Allocate space for an input FIFO, plus a few bytes for output.
2437 * Allocate bytes to maintain word alignment.
2439 mem_addr = (uint)(&cpmp->cp_dpmem[0xa00]);
2441 /* Set the physical address of the host memory buffers in
2442 * the buffer descriptors.
2444 bdp = (cbd_t *)&cpmp->cp_dpmem[up->smc_rbase];
2445 bdp->cbd_bufaddr = mem_addr;
2447 bdp = (cbd_t *)&cpmp->cp_dpmem[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 void __init console_8xx_init(long kmem_start, long kmem_end)
2466 register_console(&sercons);
2468 console_initcall(console_8xx_init);
2471 /* Index in baud rate table of the default console baud rate.
2473 static int baud_idx;
2475 static struct tty_operations rs_8xx_ops = {
2476 .open = rs_8xx_open,
2477 .close = rs_8xx_close,
2478 .write = rs_8xx_write,
2479 .put_char = rs_8xx_put_char,
2480 .write_room = rs_8xx_write_room,
2481 .chars_in_buffer = rs_8xx_chars_in_buffer,
2482 .flush_buffer = rs_8xx_flush_buffer,
2483 .ioctl = rs_8xx_ioctl,
2484 .throttle = rs_8xx_throttle,
2485 .unthrottle = rs_8xx_unthrottle,
2486 .send_xchar = rs_8xx_send_xchar,
2487 .set_termios = rs_8xx_set_termios,
2488 .stop = rs_8xx_stop,
2489 .start = rs_8xx_start,
2490 .hangup = rs_8xx_hangup,
2491 .wait_until_sent = rs_8xx_wait_until_sent,
2492 .read_proc = rs_8xx_read_proc,
2496 * The serial driver boot-time initialization code!
2498 static int __init rs_8xx_init(void)
2500 struct serial_state * state;
2502 uint mem_addr, dp_addr, iobits;
2505 volatile cbd_t *bdp;
2506 volatile cpm8xx_t *cp;
2508 volatile smc_uart_t *up;
2509 volatile scc_t *scp;
2510 volatile scc_uart_t *sup;
2511 volatile immap_t *immap;
2513 serial_driver = alloc_tty_driver(NR_PORTS);
2517 init_bh(SERIAL_BH, do_serial_bh);
2519 show_serial_version();
2521 /* Initialize the tty_driver structure */
2523 serial_driver->driver_name = "serial";
2524 serial_driver->devfs_name = "tts/";
2525 serial_driver->name = "ttyS";
2526 serial_driver->major = TTY_MAJOR;
2527 serial_driver->minor_start = 64;
2528 serial_driver->type = TTY_DRIVER_TYPE_SERIAL;
2529 serial_driver->subtype = SERIAL_TYPE_NORMAL;
2530 serial_driver->init_termios = tty_std_termios;
2531 serial_driver->init_termios.c_cflag =
2532 baud_idx | CS8 | CREAD | HUPCL | CLOCAL;
2533 serial_driver->flags = TTY_DRIVER_REAL_RAW;
2534 tty_set_operations(serial_driver, &rs_8xx_ops);
2536 if (tty_register_driver(serial_driver))
2537 panic("Couldn't register serial driver\n");
2539 cp = cpmp; /* Get pointer to Communication Processor */
2540 immap = (immap_t *)IMAP_ADDR; /* and to internal registers */
2543 /* Configure SCC2, SCC3, and SCC4 instead of port A parallel I/O.
2545 #ifdef CONFIG_USE_SCC_IO
2547 /* The "standard" configuration through the 860.
2549 immap->im_ioport.iop_papar |= 0x00fc;
2550 immap->im_ioport.iop_padir &= ~0x00fc;
2551 immap->im_ioport.iop_paodr &= ~0x00fc;
2553 /* On the MBX, SCC3 is through Port D.
2555 immap->im_ioport.iop_papar |= 0x000c; /* SCC2 on port A */
2556 immap->im_ioport.iop_padir &= ~0x000c;
2557 immap->im_ioport.iop_paodr &= ~0x000c;
2559 immap->im_ioport.iop_pdpar |= 0x0030; /* SCC3 on port D */
2562 /* Since we don't yet do modem control, connect the port C pins
2563 * as general purpose I/O. This will assert CTS and CD for the
2566 immap->im_ioport.iop_pcdir |= 0x03c6;
2567 immap->im_ioport.iop_pcpar &= ~0x03c6;
2569 /* Connect SCC2 and SCC3 to NMSI. Connect BRG3 to SCC2 and
2572 cp->cp_sicr &= ~0x00ffff00;
2573 cp->cp_sicr |= 0x001b1200;
2576 /* Frequentis PP04 forced to RS-232 until we know better.
2577 * Port C 12 and 13 low enables RS-232 on SCC3 and SCC4.
2579 immap->im_ioport.iop_pcdir |= 0x000c;
2580 immap->im_ioport.iop_pcpar &= ~0x000c;
2581 immap->im_ioport.iop_pcdat &= ~0x000c;
2583 /* This enables the TX driver.
2585 cp->cp_pbpar &= ~0x6000;
2586 cp->cp_pbdat &= ~0x6000;
2590 for (i = 0, state = rs_table; i < NR_PORTS; i++,state++) {
2591 state->magic = SSTATE_MAGIC;
2593 state->type = PORT_UNKNOWN;
2594 state->custom_divisor = 0;
2595 state->close_delay = 5*HZ/10;
2596 state->closing_wait = 30*HZ;
2597 state->icount.cts = state->icount.dsr =
2598 state->icount.rng = state->icount.dcd = 0;
2599 state->icount.rx = state->icount.tx = 0;
2600 state->icount.frame = state->icount.parity = 0;
2601 state->icount.overrun = state->icount.brk = 0;
2602 printk(KERN_INFO "ttyS%02d at 0x%04x is a %s\n",
2603 i, (unsigned int)(state->port),
2604 (state->smc_scc_num & NUM_IS_SCC) ? "SCC" : "SMC");
2605 #ifdef CONFIG_SERIAL_CONSOLE
2606 /* If we just printed the message on the console port, and
2607 * we are about to initialize it for general use, we have
2608 * to wait a couple of character times for the CR/NL to
2609 * make it out of the transmit buffer.
2611 if (i == CONFIG_SERIAL_CONSOLE_PORT)
2614 info = kmalloc(sizeof(ser_info_t), GFP_KERNEL);
2616 __clear_user(info,sizeof(ser_info_t));
2617 init_waitqueue_head(&info->open_wait);
2618 init_waitqueue_head(&info->close_wait);
2619 info->magic = SERIAL_MAGIC;
2620 info->flags = state->flags;
2621 info->tqueue.routine = do_softint;
2622 info->tqueue.data = info;
2623 info->tqueue_hangup.routine = do_serial_hangup;
2624 info->tqueue_hangup.data = info;
2626 info->state = state;
2627 state->info = (struct async_struct *)info;
2629 /* We need to allocate a transmit and receive buffer
2630 * descriptors from dual port ram, and a character
2631 * buffer area from host mem.
2633 dp_addr = m8xx_cpm_dpalloc(sizeof(cbd_t) * RX_NUM_FIFO);
2635 /* Allocate space for FIFOs in the host memory.
2637 mem_addr = m8xx_cpm_hostalloc(RX_NUM_FIFO * RX_BUF_SIZE);
2638 info->rx_va_base = (unsigned char *)mem_addr;
2640 /* Set the physical address of the host memory
2641 * buffers in the buffer descriptors, and the
2642 * virtual address for us to work with.
2644 bdp = (cbd_t *)&cp->cp_dpmem[dp_addr];
2645 info->rx_cur = info->rx_bd_base = (cbd_t *)bdp;
2647 for (j=0; j<(RX_NUM_FIFO-1); j++) {
2648 bdp->cbd_bufaddr = iopa(mem_addr);
2649 bdp->cbd_sc = BD_SC_EMPTY | BD_SC_INTRPT;
2650 mem_addr += RX_BUF_SIZE;
2653 bdp->cbd_bufaddr = iopa(mem_addr);
2654 bdp->cbd_sc = BD_SC_WRAP | BD_SC_EMPTY | BD_SC_INTRPT;
2656 idx = PORT_NUM(info->state->smc_scc_num);
2657 if (info->state->smc_scc_num & NUM_IS_SCC) {
2658 scp = &cp->cp_scc[idx];
2659 sup = (scc_uart_t *)&cp->cp_dparam[state->port];
2660 sup->scc_genscc.scc_rbase = dp_addr;
2663 sp = &cp->cp_smc[idx];
2664 up = (smc_uart_t *)&cp->cp_dparam[state->port];
2665 up->smc_rbase = dp_addr;
2668 dp_addr = m8xx_cpm_dpalloc(sizeof(cbd_t) * TX_NUM_FIFO);
2670 /* Allocate space for FIFOs in the host memory.
2672 mem_addr = m8xx_cpm_hostalloc(TX_NUM_FIFO * TX_BUF_SIZE);
2673 info->tx_va_base = (unsigned char *)mem_addr;
2675 /* Set the physical address of the host memory
2676 * buffers in the buffer descriptors, and the
2677 * virtual address for us to work with.
2679 bdp = (cbd_t *)&cp->cp_dpmem[dp_addr];
2680 info->tx_cur = info->tx_bd_base = (cbd_t *)bdp;
2682 for (j=0; j<(TX_NUM_FIFO-1); j++) {
2683 bdp->cbd_bufaddr = iopa(mem_addr);
2684 bdp->cbd_sc = BD_SC_INTRPT;
2685 mem_addr += TX_BUF_SIZE;
2688 bdp->cbd_bufaddr = iopa(mem_addr);
2689 bdp->cbd_sc = (BD_SC_WRAP | BD_SC_INTRPT);
2691 if (info->state->smc_scc_num & NUM_IS_SCC) {
2692 sup->scc_genscc.scc_tbase = dp_addr;
2694 /* Set up the uart parameters in the
2697 sup->scc_genscc.scc_rfcr = SMC_EB;
2698 sup->scc_genscc.scc_tfcr = SMC_EB;
2700 /* Set this to 1 for now, so we get single
2701 * character interrupts. Using idle charater
2702 * time requires some additional tuning.
2704 sup->scc_genscc.scc_mrblr = 1;
2705 sup->scc_maxidl = 0;
2711 sup->scc_uaddr1 = 0;
2712 sup->scc_uaddr2 = 0;
2714 sup->scc_char1 = 0x8000;
2715 sup->scc_char2 = 0x8000;
2716 sup->scc_char3 = 0x8000;
2717 sup->scc_char4 = 0x8000;
2718 sup->scc_char5 = 0x8000;
2719 sup->scc_char6 = 0x8000;
2720 sup->scc_char7 = 0x8000;
2721 sup->scc_char8 = 0x8000;
2722 sup->scc_rccm = 0xc0ff;
2724 /* Send the CPM an initialize command.
2726 chan = scc_chan_map[idx];
2728 cp->cp_cpcr = mk_cr_cmd(chan,
2729 CPM_CR_INIT_TRX) | CPM_CR_FLG;
2730 while (cp->cp_cpcr & CPM_CR_FLG);
2732 /* Set UART mode, 8 bit, no parity, one stop.
2733 * Enable receive and transmit.
2737 (SCC_GSMRL_MODE_UART | SCC_GSMRL_TDCR_16 | SCC_GSMRL_RDCR_16);
2739 /* Disable all interrupts and clear all pending
2743 scp->scc_scce = 0xffff;
2744 scp->scc_dsr = 0x7e7e;
2745 scp->scc_pmsr = 0x3000;
2747 /* If the port is the console, enable Rx and Tx.
2749 #ifdef CONFIG_SERIAL_CONSOLE
2750 if (i == CONFIG_SERIAL_CONSOLE_PORT)
2751 scp->scc_gsmrl |= (SCC_GSMRL_ENR | SCC_GSMRL_ENT);
2755 /* Configure SMCs Tx/Rx instead of port B
2756 * parallel I/O. On 823/850 these are on
2759 #ifndef CONFIG_ALTSMC2
2760 iobits = 0xc0 << (idx * 4);
2761 cp->cp_pbpar |= iobits;
2762 cp->cp_pbdir &= ~iobits;
2763 cp->cp_pbodr &= ~iobits;
2767 /* SMC1 on Port B, like all 8xx.
2769 cp->cp_pbpar |= iobits;
2770 cp->cp_pbdir &= ~iobits;
2771 cp->cp_pbodr &= ~iobits;
2774 /* SMC2 is on Port A.
2776 immap->im_ioport.iop_papar |= iobits;
2777 immap->im_ioport.iop_padir &= ~iobits;
2778 immap->im_ioport.iop_paodr &= ~iobits;
2780 #endif /* CONFIG_ALTSMC2 */
2782 /* Connect the baud rate generator to the
2783 * SMC based upon index in rs_table. Also
2784 * make sure it is connected to NMSI.
2786 cp->cp_simode &= ~(0xffff << (idx * 16));
2787 cp->cp_simode |= (i << ((idx * 16) + 12));
2789 up->smc_tbase = dp_addr;
2791 /* Set up the uart parameters in the
2794 up->smc_rfcr = SMC_EB;
2795 up->smc_tfcr = SMC_EB;
2797 /* Set this to 1 for now, so we get single
2798 * character interrupts. Using idle charater
2799 * time requires some additional tuning.
2805 /* Send the CPM an initialize command.
2807 chan = smc_chan_map[idx];
2809 cp->cp_cpcr = mk_cr_cmd(chan,
2810 CPM_CR_INIT_TRX) | CPM_CR_FLG;
2811 while (cp->cp_cpcr & CPM_CR_FLG);
2813 /* Set UART mode, 8 bit, no parity, one stop.
2814 * Enable receive and transmit.
2816 sp->smc_smcmr = smcr_mk_clen(9) | SMCMR_SM_UART;
2818 /* Disable all interrupts and clear all pending
2822 sp->smc_smce = 0xff;
2824 /* If the port is the console, enable Rx and Tx.
2826 #ifdef CONFIG_SERIAL_CONSOLE
2827 if (i == CONFIG_SERIAL_CONSOLE_PORT)
2828 sp->smc_smcmr |= SMCMR_REN | SMCMR_TEN;
2832 /* Install interrupt handler.
2834 cpm_install_handler(state->irq, rs_8xx_interrupt, info);
2836 /* Set up the baud rate generator.
2838 m8xx_cpm_setbrg(i, baud_table[baud_idx]);
2845 module_init(rs_8xx_init);
2847 /* This must always be called before the rs_8xx_init() function, otherwise
2848 * it blows away the port control information.
2850 static int __init serial_console_setup(struct console *co, char *options)
2852 struct serial_state *ser;
2853 uint mem_addr, dp_addr, bidx, idx;
2855 volatile cbd_t *bdp;
2856 volatile cpm8xx_t *cp;
2858 volatile scc_t *scp;
2859 volatile smc_uart_t *up;
2860 volatile scc_uart_t *sup;
2865 for (bidx = 0; bidx < (sizeof(baud_table) / sizeof(int)); bidx++)
2866 if (bd->bi_baudrate == baud_table[bidx])
2868 /* make sure we have a useful value */
2869 if (bidx == (sizeof(baud_table) / sizeof(int)))
2870 bidx = 13; /* B9600 */
2872 co->cflag = CREAD|CLOCAL|bidx|CS8;
2875 ser = rs_table + co->index;
2877 cp = cpmp; /* Get pointer to Communication Processor */
2879 idx = PORT_NUM(ser->smc_scc_num);
2880 if (ser->smc_scc_num & NUM_IS_SCC) {
2881 scp = &cp->cp_scc[idx];
2882 sup = (scc_uart_t *)&cp->cp_dparam[ser->port];
2885 sp = &cp->cp_smc[idx];
2886 up = (smc_uart_t *)&cpmp->cp_dparam[ser->port];
2889 /* When we get here, the CPM has been reset, so we need
2890 * to configure the port.
2891 * We need to allocate a transmit and receive buffer descriptor
2892 * from dual port ram, and a character buffer area from host mem.
2895 /* Allocate space for two FIFOs. We can't allocate from host
2896 * memory yet because vm allocator isn't initialized
2897 * during this early console init.
2899 dp_addr = m8xx_cpm_dpalloc(8);
2900 mem_addr = (uint)(&cpmp->cp_dpmem[dp_addr]);
2902 /* Allocate space for two buffer descriptors in the DP ram.
2904 dp_addr = m8xx_cpm_dpalloc(sizeof(cbd_t) * 2);
2906 /* Set the physical address of the host memory buffers in
2907 * the buffer descriptors.
2909 bdp = (cbd_t *)&cp->cp_dpmem[dp_addr];
2910 bdp->cbd_bufaddr = iopa(mem_addr);
2911 (bdp+1)->cbd_bufaddr = iopa(mem_addr+4);
2913 consinfo.rx_va_base = mem_addr;
2914 consinfo.rx_bd_base = bdp;
2915 consinfo.tx_va_base = mem_addr + 4;
2916 consinfo.tx_bd_base = bdp+1;
2918 /* For the receive, set empty and wrap.
2919 * For transmit, set wrap.
2921 bdp->cbd_sc = BD_SC_EMPTY | BD_SC_WRAP;
2922 (bdp+1)->cbd_sc = BD_SC_WRAP;
2924 /* Set up the uart parameters in the parameter ram.
2926 if (ser->smc_scc_num & NUM_IS_SCC) {
2928 sup->scc_genscc.scc_rbase = dp_addr;
2929 sup->scc_genscc.scc_tbase = dp_addr + sizeof(cbd_t);
2931 /* Set up the uart parameters in the
2934 sup->scc_genscc.scc_rfcr = SMC_EB;
2935 sup->scc_genscc.scc_tfcr = SMC_EB;
2937 /* Set this to 1 for now, so we get single
2938 * character interrupts. Using idle charater
2939 * time requires some additional tuning.
2941 sup->scc_genscc.scc_mrblr = 1;
2942 sup->scc_maxidl = 0;
2948 sup->scc_uaddr1 = 0;
2949 sup->scc_uaddr2 = 0;
2951 sup->scc_char1 = 0x8000;
2952 sup->scc_char2 = 0x8000;
2953 sup->scc_char3 = 0x8000;
2954 sup->scc_char4 = 0x8000;
2955 sup->scc_char5 = 0x8000;
2956 sup->scc_char6 = 0x8000;
2957 sup->scc_char7 = 0x8000;
2958 sup->scc_char8 = 0x8000;
2959 sup->scc_rccm = 0xc0ff;
2961 /* Send the CPM an initialize command.
2963 chan = scc_chan_map[idx];
2965 cp->cp_cpcr = mk_cr_cmd(chan, CPM_CR_INIT_TRX) | CPM_CR_FLG;
2966 while (cp->cp_cpcr & CPM_CR_FLG);
2968 /* Set UART mode, 8 bit, no parity, one stop.
2969 * Enable receive and transmit.
2973 (SCC_GSMRL_MODE_UART | SCC_GSMRL_TDCR_16 | SCC_GSMRL_RDCR_16);
2975 /* Disable all interrupts and clear all pending
2979 scp->scc_scce = 0xffff;
2980 scp->scc_dsr = 0x7e7e;
2981 scp->scc_pmsr = 0x3000;
2983 scp->scc_gsmrl |= (SCC_GSMRL_ENR | SCC_GSMRL_ENT);
2987 up->smc_rbase = dp_addr; /* Base of receive buffer desc. */
2988 up->smc_tbase = dp_addr+sizeof(cbd_t); /* Base of xmt buffer desc. */
2989 up->smc_rfcr = SMC_EB;
2990 up->smc_tfcr = SMC_EB;
2992 /* Set this to 1 for now, so we get single character interrupts.
2994 up->smc_mrblr = 1; /* receive buffer length */
2995 up->smc_maxidl = 0; /* wait forever for next char */
2997 /* Send the CPM an initialize command.
2999 chan = smc_chan_map[idx];
3000 cp->cp_cpcr = mk_cr_cmd(chan, 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.
3007 sp->smc_smcmr = smcr_mk_clen(9) | SMCMR_SM_UART;
3009 /* And finally, enable Rx and Tx.
3011 sp->smc_smcmr |= SMCMR_REN | SMCMR_TEN;
3014 /* Set up the baud rate generator.
3016 m8xx_cpm_setbrg((ser - rs_table), bd->bi_baudrate);