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...");
586 schedule_task(&info
->tqueue_hangup
);
589 if (info
->flags
& ASYNC_CTS_FLOW
) {
590 if (info
->tty
->hw_stopped
) {
591 if (status
& UART_MSR_CTS
) {
592 #if (defined(SERIAL_DEBUG_INTR) || defined(SERIAL_DEBUG_FLOW))
593 printk("CTS tx start...");
595 info
->tty
->hw_stopped
= 0;
596 info
->IER
|= UART_IER_THRI
;
597 serial_out(info
, UART_IER
, info
->IER
);
598 rs_sched_event(info
, RS_EVENT_WRITE_WAKEUP
);
602 if (!(status
& UART_MSR_CTS
)) {
603 #if (defined(SERIAL_DEBUG_INTR) || defined(SERIAL_DEBUG_FLOW))
604 printk("CTS tx stop...");
606 info
->tty
->hw_stopped
= 1;
607 info
->IER
&= ~UART_IER_THRI
;
608 serial_out(info
, UART_IER
, info
->IER
);
616 * This is the serial driver's interrupt routine for a single port
618 static void rs_8xx_interrupt(void *dev_id
, struct pt_regs
*regs
)
623 volatile smc_t
*smcp
;
624 volatile scc_t
*sccp
;
626 info
= (ser_info_t
*)dev_id
;
628 idx
= PORT_NUM(info
->state
->smc_scc_num
);
629 if (info
->state
->smc_scc_num
& NUM_IS_SCC
) {
630 sccp
= &cpmp
->cp_scc
[idx
];
631 events
= sccp
->scc_scce
;
632 if (events
& SMCM_BRKE
)
633 receive_break(info
, regs
);
634 if (events
& SCCM_RX
)
635 receive_chars(info
, regs
);
636 if (events
& SCCM_TX
)
637 transmit_chars(info
, regs
);
638 sccp
->scc_scce
= events
;
641 smcp
= &cpmp
->cp_smc
[idx
];
642 events
= smcp
->smc_smce
;
643 if (events
& SMCM_BRKE
)
644 receive_break(info
, regs
);
645 if (events
& SMCM_RX
)
646 receive_chars(info
, regs
);
647 if (events
& SMCM_TX
)
648 transmit_chars(info
, regs
);
649 smcp
->smc_smce
= events
;
652 #ifdef SERIAL_DEBUG_INTR
653 printk("rs_interrupt_single(%d, %x)...",
654 info
->state
->smc_scc_num
, events
);
657 check_modem_status(info
);
659 info
->last_active
= jiffies
;
660 #ifdef SERIAL_DEBUG_INTR
667 * -------------------------------------------------------------------
668 * Here ends the serial interrupt routines.
669 * -------------------------------------------------------------------
673 * This routine is used to handle the "bottom half" processing for the
674 * serial driver, known also the "software interrupt" processing.
675 * This processing is done at the kernel interrupt level, after the
676 * rs_interrupt() has returned, BUT WITH INTERRUPTS TURNED ON. This
677 * is where time-consuming activities which can not be done in the
678 * interrupt driver proper are done; the interrupt driver schedules
679 * them using rs_sched_event(), and they get done here.
681 static void do_serial_bh(void)
683 run_task_queue(&tq_serial
);
686 static void do_softint(void *private_
)
688 ser_info_t
*info
= (ser_info_t
*) private_
;
689 struct tty_struct
*tty
;
695 if (test_and_clear_bit(RS_EVENT_WRITE_WAKEUP
, &info
->event
)) {
696 if ((tty
->flags
& (1 << TTY_DO_WRITE_WAKEUP
)) &&
697 tty
->ldisc
.write_wakeup
)
698 (tty
->ldisc
.write_wakeup
)(tty
);
699 wake_up_interruptible(&tty
->write_wait
);
704 * This routine is called from the scheduler tqueue when the interrupt
705 * routine has signalled that a hangup has occurred. The path of
706 * hangup processing is:
708 * serial interrupt routine -> (scheduler tqueue) ->
709 * do_serial_hangup() -> tty->hangup() -> rs_hangup()
712 static void do_serial_hangup(void *private_
)
714 struct async_struct
*info
= (struct async_struct
*) private_
;
715 struct tty_struct
*tty
;
722 /*static void rs_8xx_timer(void)
724 printk("rs_8xx_timer\n");
728 static int startup(ser_info_t
*info
)
733 struct serial_state
*state
= info
->state
;
734 volatile smc_t
*smcp
;
735 volatile scc_t
*sccp
;
736 volatile smc_uart_t
*up
;
737 volatile scc_uart_t
*scup
;
740 save_flags(flags
); cli();
742 if (info
->flags
& ASYNC_INITIALIZED
) {
747 if (!state
->port
|| !state
->type
) {
749 set_bit(TTY_IO_ERROR
, &info
->tty
->flags
);
754 #ifdef SERIAL_DEBUG_OPEN
755 printk("starting up ttys%d (irq %d)...", info
->line
, state
->irq
);
761 if (info
->tty
->termios
->c_cflag
& CBAUD
)
762 info
->MCR
= UART_MCR_DTR
| UART_MCR_RTS
;
766 clear_bit(TTY_IO_ERROR
, &info
->tty
->flags
);
769 * and set the speed of the serial port
773 idx
= PORT_NUM(info
->state
->smc_scc_num
);
774 if (info
->state
->smc_scc_num
& NUM_IS_SCC
) {
775 sccp
= &cpmp
->cp_scc
[idx
];
776 scup
= (scc_uart_t
*)&cpmp
->cp_dparam
[state
->port
];
777 scup
->scc_genscc
.scc_mrblr
= RX_BUF_SIZE
;
778 scup
->scc_maxidl
= RX_BUF_SIZE
;
779 sccp
->scc_sccm
|= (UART_SCCM_TX
| UART_SCCM_RX
);
780 sccp
->scc_gsmrl
|= (SCC_GSMRL_ENR
| SCC_GSMRL_ENT
);
783 smcp
= &cpmp
->cp_smc
[idx
];
785 /* Enable interrupts and I/O.
787 smcp
->smc_smcm
|= (SMCM_RX
| SMCM_TX
);
788 smcp
->smc_smcmr
|= (SMCMR_REN
| SMCMR_TEN
);
790 /* We can tune the buffer length and idle characters
791 * to take advantage of the entire incoming buffer size.
792 * If mrblr is something other than 1, maxidl has to be
793 * non-zero or we never get an interrupt. The maxidl
794 * is the number of character times we wait after reception
795 * of the last character before we decide no more characters
798 up
= (smc_uart_t
*)&cpmp
->cp_dparam
[state
->port
];
799 up
->smc_mrblr
= RX_BUF_SIZE
;
800 up
->smc_maxidl
= RX_BUF_SIZE
;
801 up
->smc_brkcr
= 1; /* number of break chars */
804 info
->flags
|= ASYNC_INITIALIZED
;
805 restore_flags(flags
);
809 restore_flags(flags
);
814 * This routine will shutdown a serial port; interrupts are disabled, and
815 * DTR is dropped if the hangup on close termio flag is on.
817 static void shutdown(ser_info_t
* info
)
820 struct serial_state
*state
;
822 volatile smc_t
*smcp
;
823 volatile scc_t
*sccp
;
825 if (!(info
->flags
& ASYNC_INITIALIZED
))
830 #ifdef SERIAL_DEBUG_OPEN
831 printk("Shutting down serial port %d (irq %d)....", info
->line
,
835 save_flags(flags
); cli(); /* Disable interrupts */
837 idx
= PORT_NUM(state
->smc_scc_num
);
838 if (state
->smc_scc_num
& NUM_IS_SCC
) {
839 sccp
= &cpmp
->cp_scc
[idx
];
840 sccp
->scc_gsmrl
&= ~(SCC_GSMRL_ENR
| SCC_GSMRL_ENT
);
841 #ifdef CONFIG_SERIAL_CONSOLE
842 /* We can't disable the transmitter if this is the
845 if ((state
- rs_table
) != CONFIG_SERIAL_CONSOLE_PORT
)
847 sccp
->scc_sccm
&= ~(UART_SCCM_TX
| UART_SCCM_RX
);
850 smcp
= &cpmp
->cp_smc
[idx
];
852 /* Disable interrupts and I/O.
854 smcp
->smc_smcm
&= ~(SMCM_RX
| SMCM_TX
);
855 #ifdef CONFIG_SERIAL_CONSOLE
856 /* We can't disable the transmitter if this is the
859 if ((state
- rs_table
) != CONFIG_SERIAL_CONSOLE_PORT
)
861 smcp
->smc_smcmr
&= ~(SMCMR_REN
| SMCMR_TEN
);
865 set_bit(TTY_IO_ERROR
, &info
->tty
->flags
);
867 info
->flags
&= ~ASYNC_INITIALIZED
;
868 restore_flags(flags
);
872 * This routine is called to set the UART divisor registers to match
873 * the specified baud rate for a serial port.
875 static void change_speed(ser_info_t
*info
)
878 unsigned cflag
, cval
, scval
, prev_mode
, new_mode
;
879 int i
, bits
, sbits
, idx
;
881 struct serial_state
*state
;
882 volatile smc_t
*smcp
;
883 volatile scc_t
*sccp
;
885 if (!info
->tty
|| !info
->tty
->termios
)
887 cflag
= info
->tty
->termios
->c_cflag
;
891 /* Character length programmed into the mode register is the
892 * sum of: 1 start bit, number of data bits, 0 or 1 parity bit,
893 * 1 or 2 stop bits, minus 1.
894 * The value 'bits' counts this for us.
899 /* byte size and parity */
900 switch (cflag
& CSIZE
) {
901 case CS5
: bits
= 5; break;
902 case CS6
: bits
= 6; break;
903 case CS7
: bits
= 7; break;
904 case CS8
: bits
= 8; break;
905 /* Never happens, but GCC is too dumb to figure it out */
906 default: bits
= 8; break;
910 if (cflag
& CSTOPB
) {
911 cval
|= SMCMR_SL
; /* Two stops */
912 scval
|= SCU_PMSR_SL
;
915 if (cflag
& PARENB
) {
917 scval
|= SCU_PMSR_PEN
;
919 if (!(cflag
& PARODD
)) {
920 cval
|= SMCMR_PM_EVEN
;
921 scval
|= (SCU_PMSR_REVP
| SCU_PMSR_TEVP
);
925 /* Determine divisor based on baud rate */
927 if (i
>= (sizeof(baud_table
)/sizeof(int)))
930 baud_rate
= baud_table
[i
];
932 info
->timeout
= (TX_BUF_SIZE
*HZ
*bits
);
933 info
->timeout
+= HZ
/50; /* Add .02 seconds of slop */
936 /* CTS flow control flag and modem status interrupts */
937 info
->IER
&= ~UART_IER_MSI
;
938 if (info
->flags
& ASYNC_HARDPPS_CD
)
939 info
->IER
|= UART_IER_MSI
;
940 if (cflag
& CRTSCTS
) {
941 info
->flags
|= ASYNC_CTS_FLOW
;
942 info
->IER
|= UART_IER_MSI
;
944 info
->flags
&= ~ASYNC_CTS_FLOW
;
946 info
->flags
&= ~ASYNC_CHECK_CD
;
948 info
->flags
|= ASYNC_CHECK_CD
;
949 info
->IER
|= UART_IER_MSI
;
951 serial_out(info
, UART_IER
, info
->IER
);
955 * Set up parity check flag
957 #define RELEVANT_IFLAG(iflag) (iflag & (IGNBRK|BRKINT|IGNPAR|PARMRK|INPCK))
959 info
->read_status_mask
= (BD_SC_EMPTY
| BD_SC_OV
);
960 if (I_INPCK(info
->tty
))
961 info
->read_status_mask
|= BD_SC_FR
| BD_SC_PR
;
962 if (I_BRKINT(info
->tty
) || I_PARMRK(info
->tty
))
963 info
->read_status_mask
|= BD_SC_BR
;
966 * Characters to ignore
968 info
->ignore_status_mask
= 0;
969 if (I_IGNPAR(info
->tty
))
970 info
->ignore_status_mask
|= BD_SC_PR
| BD_SC_FR
;
971 if (I_IGNBRK(info
->tty
)) {
972 info
->ignore_status_mask
|= BD_SC_BR
;
974 * If we're ignore parity and break indicators, ignore
975 * overruns too. (For real raw support).
977 if (I_IGNPAR(info
->tty
))
978 info
->ignore_status_mask
|= BD_SC_OV
;
981 * !!! ignore all characters if CREAD is not set
983 if ((cflag
& CREAD
) == 0)
984 info
->read_status_mask
&= ~BD_SC_EMPTY
;
985 save_flags(flags
); cli();
987 /* Start bit has not been added (so don't, because we would just
988 * subtract it later), and we need to add one for the number of
989 * stops bits (there is always at least one).
992 idx
= PORT_NUM(state
->smc_scc_num
);
993 if (state
->smc_scc_num
& NUM_IS_SCC
) {
994 sccp
= &cpmp
->cp_scc
[idx
];
995 new_mode
= (sbits
<< 12) | scval
;
996 prev_mode
= sccp
->scc_pmsr
;
997 if (!(prev_mode
& SCU_PMSR_PEN
))
998 /* If parity is disabled, mask out even/odd */
999 prev_mode
&= ~(SCU_PMSR_TPM
|SCU_PMSR_RPM
);
1000 if (prev_mode
!= new_mode
)
1001 sccp
->scc_pmsr
= new_mode
;
1004 smcp
= &cpmp
->cp_smc
[idx
];
1006 /* Set the mode register. We want to keep a copy of the
1007 * enables, because we want to put them back if they were
1010 prev_mode
= smcp
->smc_smcmr
;
1011 new_mode
= smcr_mk_clen(bits
) | cval
| SMCMR_SM_UART
;
1012 new_mode
|= (prev_mode
& (SMCMR_REN
| SMCMR_TEN
));
1013 if (!(prev_mode
& SMCMR_PEN
))
1014 /* If parity is disabled, mask out even/odd */
1015 prev_mode
&= ~SMCMR_PM_EVEN
;
1016 if (prev_mode
!= new_mode
)
1017 smcp
->smc_smcmr
= new_mode
;
1020 m8xx_cpm_setbrg((state
- rs_table
), baud_rate
);
1022 restore_flags(flags
);
1025 static void rs_8xx_put_char(struct tty_struct
*tty
, unsigned char ch
)
1027 ser_info_t
*info
= (ser_info_t
*)tty
->driver_data
;
1028 volatile cbd_t
*bdp
;
1031 if (serial_paranoia_check(info
, tty
->name
, "rs_put_char"))
1038 while (bdp
->cbd_sc
& BD_SC_READY
);
1040 cp
= info
->tx_va_base
+ ((bdp
- info
->tx_bd_base
) * TX_BUF_SIZE
);
1042 bdp
->cbd_datlen
= 1;
1043 bdp
->cbd_sc
|= BD_SC_READY
;
1047 if (bdp
->cbd_sc
& BD_SC_WRAP
)
1048 bdp
= info
->tx_bd_base
;
1052 info
->tx_cur
= (cbd_t
*)bdp
;
1056 static int rs_8xx_write(struct tty_struct
* tty
, int from_user
,
1057 const unsigned char *buf
, int count
)
1060 ser_info_t
*info
= (ser_info_t
*)tty
->driver_data
;
1061 volatile cbd_t
*bdp
;
1064 #ifdef CONFIG_KGDB_CONSOLE
1065 /* Try to let stub handle output. Returns true if it did. */
1066 if (kgdb_output_string(buf
, count
))
1070 if (serial_paranoia_check(info
, tty
->name
, "rs_write"))
1079 c
= min(count
, TX_BUF_SIZE
);
1084 if (bdp
->cbd_sc
& BD_SC_READY
) {
1085 info
->flags
|= TX_WAKEUP
;
1089 cp
= info
->tx_va_base
+ ((bdp
- info
->tx_bd_base
) * TX_BUF_SIZE
);
1091 if (copy_from_user((void *)cp
, buf
, c
)) {
1097 memcpy((void *)cp
, buf
, c
);
1100 bdp
->cbd_datlen
= c
;
1101 bdp
->cbd_sc
|= BD_SC_READY
;
1109 if (bdp
->cbd_sc
& BD_SC_WRAP
)
1110 bdp
= info
->tx_bd_base
;
1113 info
->tx_cur
= (cbd_t
*)bdp
;
1118 static int rs_8xx_write_room(struct tty_struct
*tty
)
1120 ser_info_t
*info
= (ser_info_t
*)tty
->driver_data
;
1123 if (serial_paranoia_check(info
, tty
->name
, "rs_write_room"))
1126 if ((info
->tx_cur
->cbd_sc
& BD_SC_READY
) == 0) {
1127 info
->flags
&= ~TX_WAKEUP
;
1131 info
->flags
|= TX_WAKEUP
;
1137 /* I could track this with transmit counters....maybe later.
1139 static int rs_8xx_chars_in_buffer(struct tty_struct
*tty
)
1141 ser_info_t
*info
= (ser_info_t
*)tty
->driver_data
;
1143 if (serial_paranoia_check(info
, tty
->name
, "rs_chars_in_buffer"))
1148 static void rs_8xx_flush_buffer(struct tty_struct
*tty
)
1150 ser_info_t
*info
= (ser_info_t
*)tty
->driver_data
;
1152 if (serial_paranoia_check(info
, tty
->name
, "rs_flush_buffer"))
1155 /* There is nothing to "flush", whatever we gave the CPM
1156 * is on its way out.
1158 wake_up_interruptible(&tty
->write_wait
);
1159 if ((tty
->flags
& (1 << TTY_DO_WRITE_WAKEUP
)) &&
1160 tty
->ldisc
.write_wakeup
)
1161 (tty
->ldisc
.write_wakeup
)(tty
);
1162 info
->flags
&= ~TX_WAKEUP
;
1166 * This function is used to send a high-priority XON/XOFF character to
1169 static void rs_8xx_send_xchar(struct tty_struct
*tty
, char ch
)
1171 volatile cbd_t
*bdp
;
1174 ser_info_t
*info
= (ser_info_t
*)tty
->driver_data
;
1176 if (serial_paranoia_check(info
, tty
->name
, "rs_send_char"))
1180 while (bdp
->cbd_sc
& BD_SC_READY
);
1182 cp
= info
->tx_va_base
+ ((bdp
- info
->tx_bd_base
) * TX_BUF_SIZE
);
1184 bdp
->cbd_datlen
= 1;
1185 bdp
->cbd_sc
|= BD_SC_READY
;
1189 if (bdp
->cbd_sc
& BD_SC_WRAP
)
1190 bdp
= info
->tx_bd_base
;
1194 info
->tx_cur
= (cbd_t
*)bdp
;
1198 * ------------------------------------------------------------
1201 * This routine is called by the upper-layer tty layer to signal that
1202 * incoming characters should be throttled.
1203 * ------------------------------------------------------------
1205 static void rs_8xx_throttle(struct tty_struct
* tty
)
1207 ser_info_t
*info
= (ser_info_t
*)tty
->driver_data
;
1208 #ifdef SERIAL_DEBUG_THROTTLE
1211 printk("throttle %s: %d....\n", _tty_name(tty
, buf
),
1212 tty
->ldisc
.chars_in_buffer(tty
));
1215 if (serial_paranoia_check(info
, tty
->name
, "rs_throttle"))
1219 rs_8xx_send_xchar(tty
, STOP_CHAR(tty
));
1221 #ifdef modem_control
1222 if (tty
->termios
->c_cflag
& CRTSCTS
)
1223 info
->MCR
&= ~UART_MCR_RTS
;
1226 serial_out(info
, UART_MCR
, info
->MCR
);
1231 static void rs_8xx_unthrottle(struct tty_struct
* tty
)
1233 ser_info_t
*info
= (ser_info_t
*)tty
->driver_data
;
1234 #ifdef SERIAL_DEBUG_THROTTLE
1237 printk("unthrottle %s: %d....\n", _tty_name(tty
, buf
),
1238 tty
->ldisc
.chars_in_buffer(tty
));
1241 if (serial_paranoia_check(info
, tty
->name
, "rs_unthrottle"))
1248 rs_8xx_send_xchar(tty
, START_CHAR(tty
));
1250 #ifdef modem_control
1251 if (tty
->termios
->c_cflag
& CRTSCTS
)
1252 info
->MCR
|= UART_MCR_RTS
;
1254 serial_out(info
, UART_MCR
, info
->MCR
);
1260 * ------------------------------------------------------------
1261 * rs_ioctl() and friends
1262 * ------------------------------------------------------------
1267 * get_lsr_info - get line status register info
1269 * Purpose: Let user call ioctl() to get info when the UART physically
1270 * is emptied. On bus types like RS485, the transmitter must
1271 * release the bus after transmitting. This must be done when
1272 * the transmit shift register is empty, not be done when the
1273 * transmit holding register is empty. This functionality
1274 * allows an RS485 driver to be written in user space.
1276 static int get_lsr_info(struct async_struct
* info
, unsigned int *value
)
1278 unsigned char status
;
1279 unsigned int result
;
1282 status
= serial_in(info
, UART_LSR
);
1284 result
= ((status
& UART_LSR_TEMT
) ? TIOCSER_TEMT
: 0);
1285 return put_user(result
,value
);
1289 static int get_modem_info(ser_info_t
*info
, unsigned int *value
)
1291 unsigned int result
= 0;
1292 #ifdef modem_control
1293 unsigned char control
, status
;
1295 control
= info
->MCR
;
1297 status
= serial_in(info
, UART_MSR
);
1299 result
= ((control
& UART_MCR_RTS
) ? TIOCM_RTS
: 0)
1300 | ((control
& UART_MCR_DTR
) ? TIOCM_DTR
: 0)
1302 | ((control
& UART_MCR_OUT1
) ? TIOCM_OUT1
: 0)
1303 | ((control
& UART_MCR_OUT2
) ? TIOCM_OUT2
: 0)
1305 | ((status
& UART_MSR_DCD
) ? TIOCM_CAR
: 0)
1306 | ((status
& UART_MSR_RI
) ? TIOCM_RNG
: 0)
1307 | ((status
& UART_MSR_DSR
) ? TIOCM_DSR
: 0)
1308 | ((status
& UART_MSR_CTS
) ? TIOCM_CTS
: 0);
1310 return put_user(result
,value
);
1313 static int set_modem_info(ser_info_t
*info
, unsigned int cmd
,
1314 unsigned int *value
)
1319 error
= get_user(arg
, value
);
1322 #ifdef modem_control
1325 if (arg
& TIOCM_RTS
)
1326 info
->MCR
|= UART_MCR_RTS
;
1327 if (arg
& TIOCM_DTR
)
1328 info
->MCR
|= UART_MCR_DTR
;
1330 if (arg
& TIOCM_OUT1
)
1331 info
->MCR
|= UART_MCR_OUT1
;
1332 if (arg
& TIOCM_OUT2
)
1333 info
->MCR
|= UART_MCR_OUT2
;
1337 if (arg
& TIOCM_RTS
)
1338 info
->MCR
&= ~UART_MCR_RTS
;
1339 if (arg
& TIOCM_DTR
)
1340 info
->MCR
&= ~UART_MCR_DTR
;
1342 if (arg
& TIOCM_OUT1
)
1343 info
->MCR
&= ~UART_MCR_OUT1
;
1344 if (arg
& TIOCM_OUT2
)
1345 info
->MCR
&= ~UART_MCR_OUT2
;
1349 info
->MCR
= ((info
->MCR
& ~(UART_MCR_RTS
|
1355 | ((arg
& TIOCM_RTS
) ? UART_MCR_RTS
: 0)
1357 | ((arg
& TIOCM_OUT1
) ? UART_MCR_OUT1
: 0)
1358 | ((arg
& TIOCM_OUT2
) ? UART_MCR_OUT2
: 0)
1360 | ((arg
& TIOCM_DTR
) ? UART_MCR_DTR
: 0));
1366 serial_out(info
, UART_MCR
, info
->MCR
);
1372 /* Sending a break is a two step process on the SMC/SCC. It is accomplished
1373 * by sending a STOP TRANSMIT command followed by a RESTART TRANSMIT
1374 * command. We take advantage of the begin/end functions to make this
1377 static ushort smc_chan_map
[] = {
1382 static ushort scc_chan_map
[] = {
1389 static void begin_break(ser_info_t
*info
)
1391 volatile cpm8xx_t
*cp
;
1397 idx
= PORT_NUM(info
->state
->smc_scc_num
);
1398 if (info
->state
->smc_scc_num
& NUM_IS_SCC
)
1399 chan
= scc_chan_map
[idx
];
1401 chan
= smc_chan_map
[idx
];
1402 cp
->cp_cpcr
= mk_cr_cmd(chan
, CPM_CR_STOP_TX
) | CPM_CR_FLG
;
1403 while (cp
->cp_cpcr
& CPM_CR_FLG
);
1406 static void end_break(ser_info_t
*info
)
1408 volatile cpm8xx_t
*cp
;
1414 idx
= PORT_NUM(info
->state
->smc_scc_num
);
1415 if (info
->state
->smc_scc_num
& NUM_IS_SCC
)
1416 chan
= scc_chan_map
[idx
];
1418 chan
= smc_chan_map
[idx
];
1419 cp
->cp_cpcr
= mk_cr_cmd(chan
, CPM_CR_RESTART_TX
) | CPM_CR_FLG
;
1420 while (cp
->cp_cpcr
& CPM_CR_FLG
);
1424 * This routine sends a break character out the serial port.
1426 static void send_break(ser_info_t
*info
, int duration
)
1428 current
->state
= TASK_INTERRUPTIBLE
;
1429 #ifdef SERIAL_DEBUG_SEND_BREAK
1430 printk("rs_send_break(%d) jiff=%lu...", duration
, jiffies
);
1433 schedule_timeout(duration
);
1435 #ifdef SERIAL_DEBUG_SEND_BREAK
1436 printk("done jiffies=%lu\n", jiffies
);
1441 static int rs_8xx_ioctl(struct tty_struct
*tty
, struct file
* file
,
1442 unsigned int cmd
, unsigned long arg
)
1445 ser_info_t
*info
= (ser_info_t
*)tty
->driver_data
;
1447 struct async_icount cnow
; /* kernel counter temps */
1448 struct serial_icounter_struct
*p_cuser
; /* user space */
1450 if (serial_paranoia_check(info
, tty
->name
, "rs_ioctl"))
1453 if ((cmd
!= TIOCMIWAIT
) && (cmd
!= TIOCGICOUNT
)) {
1454 if (tty
->flags
& (1 << TTY_IO_ERROR
))
1459 case TCSBRK
: /* SVID version: non-zero arg --> no break */
1460 retval
= tty_check_change(tty
);
1463 tty_wait_until_sent(tty
, 0);
1464 if (signal_pending(current
))
1467 send_break(info
, HZ
/4); /* 1/4 second */
1468 if (signal_pending(current
))
1472 case TCSBRKP
: /* support for POSIX tcsendbreak() */
1473 retval
= tty_check_change(tty
);
1476 tty_wait_until_sent(tty
, 0);
1477 if (signal_pending(current
))
1479 send_break(info
, arg
? arg
*(HZ
/10) : HZ
/4);
1480 if (signal_pending(current
))
1484 retval
= tty_check_change(tty
);
1487 tty_wait_until_sent(tty
, 0);
1491 retval
= tty_check_change(tty
);
1497 return put_user(C_CLOCAL(tty
) ? 1 : 0, (int *) arg
);
1499 error
= get_user(arg
, (unsigned int *) arg
);
1502 tty
->termios
->c_cflag
=
1503 ((tty
->termios
->c_cflag
& ~CLOCAL
) |
1504 (arg
? CLOCAL
: 0));
1507 return get_modem_info(info
, (unsigned int *) arg
);
1511 return set_modem_info(info
, cmd
, (unsigned int *) arg
);
1513 case TIOCSERGETLSR
: /* Get line status register */
1514 return get_lsr_info(info
, (unsigned int *) arg
);
1517 * Wait for any of the 4 modem inputs (DCD,RI,DSR,CTS) to change
1518 * - mask passed in arg for lines of interest
1519 * (use |'ed TIOCM_RNG/DSR/CD/CTS for masking)
1520 * Caller should use TIOCGICOUNT to see which one it was
1523 #ifdef modem_control
1525 /* note the counters on entry */
1526 cprev
= info
->state
->icount
;
1529 interruptible_sleep_on(&info
->delta_msr_wait
);
1530 /* see if a signal did it */
1531 if (signal_pending(current
))
1532 return -ERESTARTSYS
;
1534 cnow
= info
->state
->icount
; /* atomic copy */
1536 if (cnow
.rng
== cprev
.rng
&& cnow
.dsr
== cprev
.dsr
&&
1537 cnow
.dcd
== cprev
.dcd
&& cnow
.cts
== cprev
.cts
)
1538 return -EIO
; /* no change => error */
1539 if ( ((arg
& TIOCM_RNG
) && (cnow
.rng
!= cprev
.rng
)) ||
1540 ((arg
& TIOCM_DSR
) && (cnow
.dsr
!= cprev
.dsr
)) ||
1541 ((arg
& TIOCM_CD
) && (cnow
.dcd
!= cprev
.dcd
)) ||
1542 ((arg
& TIOCM_CTS
) && (cnow
.cts
!= cprev
.cts
)) ) {
1553 * Get counter of input serial line interrupts (DCD,RI,DSR,CTS)
1554 * Return: write counters to the user passed counter struct
1555 * NB: both 1->0 and 0->1 transitions are counted except for
1556 * RI where only 0->1 is counted.
1560 cnow
= info
->state
->icount
;
1562 p_cuser
= (struct serial_icounter_struct
*) arg
;
1563 error
= put_user(cnow
.cts
, &p_cuser
->cts
);
1564 if (error
) return error
;
1565 error
= put_user(cnow
.dsr
, &p_cuser
->dsr
);
1566 if (error
) return error
;
1567 error
= put_user(cnow
.rng
, &p_cuser
->rng
);
1568 if (error
) return error
;
1569 error
= put_user(cnow
.dcd
, &p_cuser
->dcd
);
1570 if (error
) return error
;
1574 return -ENOIOCTLCMD
;
1579 /* FIX UP modem control here someday......
1581 static void rs_8xx_set_termios(struct tty_struct
*tty
, struct termios
*old_termios
)
1583 ser_info_t
*info
= (ser_info_t
*)tty
->driver_data
;
1585 if ( (tty
->termios
->c_cflag
== old_termios
->c_cflag
)
1586 && ( RELEVANT_IFLAG(tty
->termios
->c_iflag
)
1587 == RELEVANT_IFLAG(old_termios
->c_iflag
)))
1592 #ifdef modem_control
1593 /* Handle transition to B0 status */
1594 if ((old_termios
->c_cflag
& CBAUD
) &&
1595 !(tty
->termios
->c_cflag
& CBAUD
)) {
1596 info
->MCR
&= ~(UART_MCR_DTR
|UART_MCR_RTS
);
1598 serial_out(info
, UART_MCR
, info
->MCR
);
1602 /* Handle transition away from B0 status */
1603 if (!(old_termios
->c_cflag
& CBAUD
) &&
1604 (tty
->termios
->c_cflag
& CBAUD
)) {
1605 info
->MCR
|= UART_MCR_DTR
;
1606 if (!tty
->hw_stopped
||
1607 !(tty
->termios
->c_cflag
& CRTSCTS
)) {
1608 info
->MCR
|= UART_MCR_RTS
;
1611 serial_out(info
, UART_MCR
, info
->MCR
);
1615 /* Handle turning off CRTSCTS */
1616 if ((old_termios
->c_cflag
& CRTSCTS
) &&
1617 !(tty
->termios
->c_cflag
& CRTSCTS
)) {
1618 tty
->hw_stopped
= 0;
1625 * No need to wake up processes in open wait, since they
1626 * sample the CLOCAL flag once, and don't recheck it.
1627 * XXX It's not clear whether the current behavior is correct
1628 * or not. Hence, this may change.....
1630 if (!(old_termios
->c_cflag
& CLOCAL
) &&
1631 (tty
->termios
->c_cflag
& CLOCAL
))
1632 wake_up_interruptible(&info
->open_wait
);
1637 * ------------------------------------------------------------
1640 * This routine is called when the serial port gets closed. First, we
1641 * wait for the last remaining data to be sent. Then, we unlink its
1642 * async structure from the interrupt chain if necessary, and we free
1643 * that IRQ if nothing is left in the chain.
1644 * ------------------------------------------------------------
1646 static void rs_8xx_close(struct tty_struct
*tty
, struct file
* filp
)
1648 ser_info_t
*info
= (ser_info_t
*)tty
->driver_data
;
1649 struct serial_state
*state
;
1650 unsigned long flags
;
1652 volatile smc_t
*smcp
;
1653 volatile scc_t
*sccp
;
1655 if (!info
|| serial_paranoia_check(info
, tty
->name
, "rs_close"))
1658 state
= info
->state
;
1660 save_flags(flags
); cli();
1662 if (tty_hung_up_p(filp
)) {
1663 DBG_CNT("before DEC-hung");
1664 restore_flags(flags
);
1668 #ifdef SERIAL_DEBUG_OPEN
1669 printk("rs_close ttys%d, count = %d\n", info
->line
, state
->count
);
1671 if ((tty
->count
== 1) && (state
->count
!= 1)) {
1673 * Uh, oh. tty->count is 1, which means that the tty
1674 * structure will be freed. state->count should always
1675 * be one in these conditions. If it's greater than
1676 * one, we've got real problems, since it means the
1677 * serial port won't be shutdown.
1679 printk("rs_close: bad serial port count; tty->count is 1, "
1680 "state->count is %d\n", state
->count
);
1683 if (--state
->count
< 0) {
1684 printk("rs_close: bad serial port count for ttys%d: %d\n",
1685 info
->line
, state
->count
);
1689 DBG_CNT("before DEC-2");
1690 restore_flags(flags
);
1693 info
->flags
|= ASYNC_CLOSING
;
1695 * Now we wait for the transmit buffer to clear; and we notify
1696 * the line discipline to only process XON/XOFF characters.
1699 if (info
->closing_wait
!= ASYNC_CLOSING_WAIT_NONE
)
1700 tty_wait_until_sent(tty
, info
->closing_wait
);
1702 * At this point we stop accepting input. To do this, we
1703 * disable the receive line status interrupts, and tell the
1704 * interrupt driver to stop checking the data ready bit in the
1705 * line status register.
1707 info
->read_status_mask
&= ~BD_SC_EMPTY
;
1708 if (info
->flags
& ASYNC_INITIALIZED
) {
1709 idx
= PORT_NUM(info
->state
->smc_scc_num
);
1710 if (info
->state
->smc_scc_num
& NUM_IS_SCC
) {
1711 sccp
= &cpmp
->cp_scc
[idx
];
1712 sccp
->scc_sccm
&= ~UART_SCCM_RX
;
1713 sccp
->scc_gsmrl
&= ~SCC_GSMRL_ENR
;
1716 smcp
= &cpmp
->cp_smc
[idx
];
1717 smcp
->smc_smcm
&= ~SMCM_RX
;
1718 smcp
->smc_smcmr
&= ~SMCMR_REN
;
1721 * Before we drop DTR, make sure the UART transmitter
1722 * has completely drained; this is especially
1723 * important if there is a transmit FIFO!
1725 rs_8xx_wait_until_sent(tty
, info
->timeout
);
1728 if (tty
->driver
->flush_buffer
)
1729 tty
->driver
->flush_buffer(tty
);
1730 if (tty
->ldisc
.flush_buffer
)
1731 tty
->ldisc
.flush_buffer(tty
);
1735 if (info
->blocked_open
) {
1736 if (info
->close_delay
) {
1737 current
->state
= TASK_INTERRUPTIBLE
;
1738 schedule_timeout(info
->close_delay
);
1740 wake_up_interruptible(&info
->open_wait
);
1742 info
->flags
&= ~(ASYNC_NORMAL_ACTIVE
|ASYNC_CLOSING
);
1743 wake_up_interruptible(&info
->close_wait
);
1744 restore_flags(flags
);
1748 * rs_wait_until_sent() --- wait until the transmitter is empty
1750 static void rs_8xx_wait_until_sent(struct tty_struct
*tty
, int timeout
)
1752 ser_info_t
*info
= (ser_info_t
*)tty
->driver_data
;
1753 unsigned long orig_jiffies
, char_time
;
1755 volatile cbd_t
*bdp
;
1757 if (serial_paranoia_check(info
, tty
->name
, "rs_wait_until_sent"))
1761 if (info
->state
->type
== PORT_UNKNOWN
)
1765 orig_jiffies
= jiffies
;
1767 * Set the check interval to be 1/5 of the estimated time to
1768 * send a single character, and make it at least 1. The check
1769 * interval should also be less than the timeout.
1771 * Note: we have to use pretty tight timings here to satisfy
1776 char_time
= min(char_time
, timeout
);
1777 #ifdef SERIAL_DEBUG_RS_WAIT_UNTIL_SENT
1778 printk("In rs_wait_until_sent(%d) check=%lu...", timeout
, char_time
);
1779 printk("jiff=%lu...", jiffies
);
1782 /* We go through the loop at least once because we can't tell
1783 * exactly when the last character exits the shifter. There can
1784 * be at least two characters waiting to be sent after the buffers
1788 #ifdef SERIAL_DEBUG_RS_WAIT_UNTIL_SENT
1789 printk("lsr = %d (jiff=%lu)...", lsr
, jiffies
);
1791 current
->state
= TASK_INTERRUPTIBLE
;
1792 /* current->dyn_prio = 0; make us low-priority */
1793 schedule_timeout(char_time
);
1794 if (signal_pending(current
))
1796 if (timeout
&& time_after(jiffies
, orig_jiffies
+ timeout
))
1799 /* The 'tx_cur' is really the next buffer to send. We
1800 * have to back up to the previous BD and wait for it
1801 * to go. This isn't perfect, because all this indicates
1802 * is the buffer is available. There are still characters
1806 if (bdp
== info
->tx_bd_base
)
1807 bdp
+= (TX_NUM_FIFO
-1);
1810 } while (bdp
->cbd_sc
& BD_SC_READY
);
1811 current
->state
= TASK_RUNNING
;
1812 #ifdef SERIAL_DEBUG_RS_WAIT_UNTIL_SENT
1813 printk("lsr = %d (jiff=%lu)...done\n", lsr
, jiffies
);
1818 * rs_hangup() --- called by tty_hangup() when a hangup is signaled.
1820 static void rs_8xx_hangup(struct tty_struct
*tty
)
1822 ser_info_t
*info
= (ser_info_t
*)tty
->driver_data
;
1823 struct serial_state
*state
= info
->state
;
1825 if (serial_paranoia_check(info
, tty
->name
, "rs_hangup"))
1828 state
= info
->state
;
1830 rs_8xx_flush_buffer(tty
);
1834 info
->flags
&= ~ASYNC_NORMAL_ACTIVE
;
1836 wake_up_interruptible(&info
->open_wait
);
1840 * ------------------------------------------------------------
1841 * rs_open() and friends
1842 * ------------------------------------------------------------
1844 static int block_til_ready(struct tty_struct
*tty
, struct file
* filp
,
1847 #ifdef DO_THIS_LATER
1848 DECLARE_WAITQUEUE(wait
, current
);
1850 struct serial_state
*state
= info
->state
;
1855 * If the device is in the middle of being closed, then block
1856 * until it's done, and then try again.
1858 if (tty_hung_up_p(filp
) ||
1859 (info
->flags
& ASYNC_CLOSING
)) {
1860 if (info
->flags
& ASYNC_CLOSING
)
1861 interruptible_sleep_on(&info
->close_wait
);
1862 #ifdef SERIAL_DO_RESTART
1863 if (info
->flags
& ASYNC_HUP_NOTIFY
)
1866 return -ERESTARTSYS
;
1873 * If non-blocking mode is set, or the port is not enabled,
1874 * then make the check up front and then exit.
1875 * If this is an SMC port, we don't have modem control to wait
1876 * for, so just get out here.
1878 if ((filp
->f_flags
& O_NONBLOCK
) ||
1879 (tty
->flags
& (1 << TTY_IO_ERROR
)) ||
1880 !(info
->state
->smc_scc_num
& NUM_IS_SCC
)) {
1881 info
->flags
|= ASYNC_NORMAL_ACTIVE
;
1885 if (tty
->termios
->c_cflag
& CLOCAL
)
1889 * Block waiting for the carrier detect and the line to become
1890 * free (i.e., not in use by the callout). While we are in
1891 * this loop, state->count is dropped by one, so that
1892 * rs_close() knows when to free things. We restore it upon
1893 * exit, either normal or abnormal.
1896 #ifdef DO_THIS_LATER
1897 add_wait_queue(&info
->open_wait
, &wait
);
1898 #ifdef SERIAL_DEBUG_OPEN
1899 printk("block_til_ready before block: ttys%d, count = %d\n",
1900 state
->line
, state
->count
);
1903 if (!tty_hung_up_p(filp
))
1906 info
->blocked_open
++;
1909 if ((tty
->termios
->c_cflag
& CBAUD
))
1910 serial_out(info
, UART_MCR
,
1911 serial_inp(info
, UART_MCR
) |
1912 (UART_MCR_DTR
| UART_MCR_RTS
));
1914 set_current_state(TASK_INTERRUPTIBLE
);
1915 if (tty_hung_up_p(filp
) ||
1916 !(info
->flags
& ASYNC_INITIALIZED
)) {
1917 #ifdef SERIAL_DO_RESTART
1918 if (info
->flags
& ASYNC_HUP_NOTIFY
)
1921 retval
= -ERESTARTSYS
;
1927 if (!(info
->flags
& ASYNC_CLOSING
) &&
1928 (do_clocal
|| (serial_in(info
, UART_MSR
) &
1931 if (signal_pending(current
)) {
1932 retval
= -ERESTARTSYS
;
1935 #ifdef SERIAL_DEBUG_OPEN
1936 printk("block_til_ready blocking: ttys%d, count = %d\n",
1937 info
->line
, state
->count
);
1941 current
->state
= TASK_RUNNING
;
1942 remove_wait_queue(&info
->open_wait
, &wait
);
1943 if (!tty_hung_up_p(filp
))
1945 info
->blocked_open
--;
1946 #ifdef SERIAL_DEBUG_OPEN
1947 printk("block_til_ready after blocking: ttys%d, count = %d\n",
1948 info
->line
, state
->count
);
1950 #endif /* DO_THIS_LATER */
1953 info
->flags
|= ASYNC_NORMAL_ACTIVE
;
1957 static int get_async_struct(int line
, ser_info_t
**ret_info
)
1959 struct serial_state
*sstate
;
1961 sstate
= rs_table
+ line
;
1964 *ret_info
= (ser_info_t
*)sstate
->info
;
1973 * This routine is called whenever a serial port is opened. It
1974 * enables interrupts for a serial port, linking in its async structure into
1975 * the IRQ chain. It also performs the serial-specific
1976 * initialization for the tty structure.
1978 static int rs_8xx_open(struct tty_struct
*tty
, struct file
* filp
)
1984 if ((line
< 0) || (line
>= NR_PORTS
))
1986 retval
= get_async_struct(line
, &info
);
1989 if (serial_paranoia_check(info
, tty
->name
, "rs_open"))
1992 #ifdef SERIAL_DEBUG_OPEN
1993 printk("rs_open %s, count = %d\n", tty
->name
, info
->state
->count
);
1995 tty
->driver_data
= info
;
1999 * Start up serial port
2001 retval
= startup(info
);
2005 retval
= block_til_ready(tty
, filp
, info
);
2007 #ifdef SERIAL_DEBUG_OPEN
2008 printk("rs_open returning after block_til_ready with %d\n",
2014 #ifdef SERIAL_DEBUG_OPEN
2015 printk("rs_open %s successful...", tty
->name
);
2021 * /proc fs routines....
2024 static inline int line_info(char *buf
, struct serial_state
*state
)
2027 struct async_struct
*info
= state
->info
, scr_info
;
2028 char stat_buf
[30], control
, status
;
2032 ret
= sprintf(buf
, "%d: uart:%s port:%X irq:%d",
2034 (state
->smc_scc_num
& NUM_IS_SCC
) ? "SCC" : "SMC",
2035 (unsigned int)(state
->port
), state
->irq
);
2037 if (!state
->port
|| (state
->type
== PORT_UNKNOWN
)) {
2038 ret
+= sprintf(buf
+ret
, "\n");
2044 * Figure out the current RS-232 lines
2047 info
= &scr_info
; /* This is just for serial_{in,out} */
2049 info
->magic
= SERIAL_MAGIC
;
2050 info
->port
= state
->port
;
2051 info
->flags
= state
->flags
;
2056 status
= serial_in(info
, UART_MSR
);
2057 control
= info
? info
->MCR
: serial_in(info
, UART_MCR
);
2062 if (control
& UART_MCR_RTS
)
2063 strcat(stat_buf
, "|RTS");
2064 if (status
& UART_MSR_CTS
)
2065 strcat(stat_buf
, "|CTS");
2066 if (control
& UART_MCR_DTR
)
2067 strcat(stat_buf
, "|DTR");
2068 if (status
& UART_MSR_DSR
)
2069 strcat(stat_buf
, "|DSR");
2070 if (status
& UART_MSR_DCD
)
2071 strcat(stat_buf
, "|CD");
2072 if (status
& UART_MSR_RI
)
2073 strcat(stat_buf
, "|RI");
2076 ret
+= sprintf(buf
+ret
, " baud:%d",
2077 state
->baud_base
/ info
->quot
);
2080 ret
+= sprintf(buf
+ret
, " tx:%d rx:%d",
2081 state
->icount
.tx
, state
->icount
.rx
);
2083 if (state
->icount
.frame
)
2084 ret
+= sprintf(buf
+ret
, " fe:%d", state
->icount
.frame
);
2086 if (state
->icount
.parity
)
2087 ret
+= sprintf(buf
+ret
, " pe:%d", state
->icount
.parity
);
2089 if (state
->icount
.brk
)
2090 ret
+= sprintf(buf
+ret
, " brk:%d", state
->icount
.brk
);
2092 if (state
->icount
.overrun
)
2093 ret
+= sprintf(buf
+ret
, " oe:%d", state
->icount
.overrun
);
2096 * Last thing is the RS-232 status lines
2098 ret
+= sprintf(buf
+ret
, " %s\n", stat_buf
+1);
2103 int rs_8xx_read_proc(char *page
, char **start
, off_t off
, int count
,
2104 int *eof
, void *data
)
2109 len
+= sprintf(page
, "serinfo:1.0 driver:%s\n", serial_version
);
2110 for (i
= 0; i
< NR_PORTS
&& len
< 4000; i
++) {
2111 len
+= line_info(page
+ len
, &rs_table
[i
]);
2112 if (len
+begin
> off
+count
)
2114 if (len
+begin
< off
) {
2121 if (off
>= len
+begin
)
2123 *start
= page
+ (begin
-off
);
2124 return ((count
< begin
+len
-off
) ? count
: begin
+len
-off
);
2128 * ---------------------------------------------------------------------
2129 * rs_init() and friends
2131 * rs_init() is called at boot-time to initialize the serial driver.
2132 * ---------------------------------------------------------------------
2136 * This routine prints out the appropriate serial driver version
2137 * number, and identifies which options were configured into this
2140 static _INLINE_
void show_serial_version(void)
2142 printk(KERN_INFO
"%s version %s\n", serial_name
, serial_version
);
2147 * The serial console driver used during boot. Note that these names
2148 * clash with those found in "serial.c", so we currently can't support
2149 * the 16xxx uarts and these at the same time. I will fix this to become
2150 * an indirect function call from tty_io.c (or something).
2153 #ifdef CONFIG_SERIAL_CONSOLE
2155 /* I need this just so I can store the virtual addresses and have
2156 * common functions for the early console printing.
2158 static ser_info_t consinfo
;
2161 * Print a string to the serial port trying not to disturb any possible
2162 * real use of the port...
2164 static void my_console_write(int idx
, const char *s
,
2167 struct serial_state
*ser
;
2170 volatile cbd_t
*bdp
, *bdbase
;
2171 volatile smc_uart_t
*up
;
2172 volatile u_char
*cp
;
2174 ser
= rs_table
+ idx
;
2176 /* If the port has been initialized for general use, we have
2177 * to use the buffer descriptors allocated there. Otherwise,
2178 * we simply use the single buffer allocated.
2180 if ((info
= (ser_info_t
*)ser
->info
) != NULL
) {
2182 bdbase
= info
->tx_bd_base
;
2185 /* Pointer to UART in parameter ram.
2187 up
= (smc_uart_t
*)&cpmp
->cp_dparam
[ser
->port
];
2189 /* Get the address of the host memory buffer.
2191 bdp
= bdbase
= (cbd_t
*)&cpmp
->cp_dpmem
[up
->smc_tbase
];
2197 * We need to gracefully shut down the transmitter, disable
2198 * interrupts, then send our bytes out.
2202 * Now, do each character. This is not as bad as it looks
2203 * since this is a holding FIFO and not a transmitting FIFO.
2204 * We could add the complexity of filling the entire transmit
2205 * buffer, but we would just wait longer between accesses......
2207 for (i
= 0; i
< count
; i
++, s
++) {
2208 /* Wait for transmitter fifo to empty.
2209 * Ready indicates output is ready, and xmt is doing
2210 * that, not that it is ready for us to send.
2212 while (bdp
->cbd_sc
& BD_SC_READY
);
2214 /* Send the character out.
2215 * If the buffer address is in the CPM DPRAM, don't
2218 if ((uint
)(bdp
->cbd_bufaddr
) > (uint
)IMAP_ADDR
)
2219 cp
= (u_char
*)(bdp
->cbd_bufaddr
);
2221 cp
= info
->tx_va_base
+ ((bdp
- info
->tx_bd_base
) * TX_BUF_SIZE
);
2224 bdp
->cbd_datlen
= 1;
2225 bdp
->cbd_sc
|= BD_SC_READY
;
2227 if (bdp
->cbd_sc
& BD_SC_WRAP
)
2232 /* if a LF, also do CR... */
2234 while (bdp
->cbd_sc
& BD_SC_READY
);
2235 cp
= info
->tx_va_base
+ ((bdp
- info
->tx_bd_base
) * TX_BUF_SIZE
);
2237 bdp
->cbd_datlen
= 1;
2238 bdp
->cbd_sc
|= BD_SC_READY
;
2240 if (bdp
->cbd_sc
& BD_SC_WRAP
) {
2250 * Finally, Wait for transmitter & holding register to empty
2251 * and restore the IER
2253 while (bdp
->cbd_sc
& BD_SC_READY
);
2256 info
->tx_cur
= (cbd_t
*)bdp
;
2259 static void serial_console_write(struct console
*c
, const char *s
,
2262 #ifdef CONFIG_KGDB_CONSOLE
2263 /* Try to let stub handle output. Returns true if it did. */
2264 if (kgdb_output_string(s
, count
))
2267 my_console_write(c
->index
, s
, count
);
2272 xmon_8xx_write(const char *s
, unsigned count
)
2274 my_console_write(0, s
, count
);
2281 putDebugChar(char ch
)
2283 my_console_write(0, &ch
, 1);
2288 * Receive character from the serial port. This only works well
2289 * before the port is initialized for real use.
2291 static int my_console_wait_key(int idx
, int xmon
, char *obuf
)
2293 struct serial_state
*ser
;
2296 volatile cbd_t
*bdp
;
2297 volatile smc_uart_t
*up
;
2300 ser
= rs_table
+ idx
;
2302 /* Pointer to UART in parameter ram.
2304 up
= (smc_uart_t
*)&cpmp
->cp_dparam
[ser
->port
];
2306 /* Get the address of the host memory buffer.
2307 * If the port has been initialized for general use, we must
2308 * use information from the port structure.
2310 if ((info
= (ser_info_t
*)ser
->info
)) {
2314 bdp
= (cbd_t
*)&cpmp
->cp_dpmem
[up
->smc_rbase
];
2319 * We need to gracefully shut down the receiver, disable
2320 * interrupts, then read the input.
2321 * XMON just wants a poll. If no character, return -1, else
2322 * return the character.
2325 while (bdp
->cbd_sc
& BD_SC_EMPTY
);
2328 if (bdp
->cbd_sc
& BD_SC_EMPTY
)
2332 /* If the buffer address is in the CPM DPRAM, don't
2335 if ((uint
)(bdp
->cbd_bufaddr
) > (uint
)IMAP_ADDR
)
2336 cp
= (u_char
*)(bdp
->cbd_bufaddr
);
2338 cp
= info
->rx_va_base
+ ((bdp
- info
->rx_bd_base
) * RX_BUF_SIZE
);
2341 i
= c
= bdp
->cbd_datlen
;
2348 bdp
->cbd_sc
|= BD_SC_EMPTY
;
2351 if (bdp
->cbd_sc
& BD_SC_WRAP
) {
2352 bdp
= info
->rx_bd_base
;
2357 info
->rx_cur
= (cbd_t
*)bdp
;
2365 xmon_8xx_read_poll(void)
2367 return(my_console_wait_key(0, 1, NULL
));
2371 xmon_8xx_read_char(void)
2373 return(my_console_wait_key(0, 0, NULL
));
2378 static char kgdb_buf
[RX_BUF_SIZE
], *kgdp
;
2379 static int kgdb_chars
;
2384 if (kgdb_chars
<= 0) {
2385 kgdb_chars
= my_console_wait_key(0, 0, kgdb_buf
);
2393 void kgdb_interruptible(int yes
)
2395 volatile smc_t
*smcp
;
2397 smcp
= &cpmp
->cp_smc
[KGDB_SER_IDX
];
2400 smcp
->smc_smcm
|= SMCM_RX
;
2402 smcp
->smc_smcm
&= ~SMCM_RX
;
2405 void kgdb_map_scc(void)
2407 struct serial_state
*ser
;
2409 volatile cbd_t
*bdp
;
2410 volatile smc_uart_t
*up
;
2412 cpmp
= (cpm8xx_t
*)&(((immap_t
*)IMAP_ADDR
)->im_cpm
);
2414 /* To avoid data cache CPM DMA coherency problems, allocate a
2415 * buffer in the CPM DPRAM. This will work until the CPM and
2416 * serial ports are initialized. At that time a memory buffer
2417 * will be allocated.
2418 * The port is already initialized from the boot procedure, all
2419 * we do here is give it a different buffer and make it a FIFO.
2424 /* Right now, assume we are using SMCs.
2426 up
= (smc_uart_t
*)&cpmp
->cp_dparam
[ser
->port
];
2428 /* Allocate space for an input FIFO, plus a few bytes for output.
2429 * Allocate bytes to maintain word alignment.
2431 mem_addr
= (uint
)(&cpmp
->cp_dpmem
[0xa00]);
2433 /* Set the physical address of the host memory buffers in
2434 * the buffer descriptors.
2436 bdp
= (cbd_t
*)&cpmp
->cp_dpmem
[up
->smc_rbase
];
2437 bdp
->cbd_bufaddr
= mem_addr
;
2439 bdp
= (cbd_t
*)&cpmp
->cp_dpmem
[up
->smc_tbase
];
2440 bdp
->cbd_bufaddr
= mem_addr
+RX_BUF_SIZE
;
2442 up
->smc_mrblr
= RX_BUF_SIZE
; /* receive buffer length */
2443 up
->smc_maxidl
= RX_BUF_SIZE
;
2447 static struct tty_driver
*serial_console_device(struct console
*c
, int *index
)
2450 return serial_driver
;
2456 static void __init
console_8xx_init(long kmem_start
, long kmem_end
)
2458 register_console(&sercons
);
2460 console_initcall(console_8xx_init
);
2463 /* Index in baud rate table of the default console baud rate.
2465 static int baud_idx
;
2467 static struct tty_operations rs_8xx_ops
= {
2468 .open
= rs_8xx_open
,
2469 .close
= rs_8xx_close
,
2470 .write
= rs_8xx_write
,
2471 .put_char
= rs_8xx_put_char
,
2472 .write_room
= rs_8xx_write_room
,
2473 .chars_in_buffer
= rs_8xx_chars_in_buffer
,
2474 .flush_buffer
= rs_8xx_flush_buffer
,
2475 .ioctl
= rs_8xx_ioctl
,
2476 .throttle
= rs_8xx_throttle
,
2477 .unthrottle
= rs_8xx_unthrottle
,
2478 .send_xchar
= rs_8xx_send_xchar
,
2479 .set_termios
= rs_8xx_set_termios
,
2480 .stop
= rs_8xx_stop
,
2481 .start
= rs_8xx_start
,
2482 .hangup
= rs_8xx_hangup
,
2483 .wait_until_sent
= rs_8xx_wait_until_sent
,
2484 .read_proc
= rs_8xx_read_proc
,
2488 * The serial driver boot-time initialization code!
2490 static int __init
rs_8xx_init(void)
2492 struct serial_state
* state
;
2494 uint mem_addr
, iobits
, dp_offset
;
2497 volatile cbd_t
*bdp
;
2498 volatile cpm8xx_t
*cp
;
2500 volatile smc_uart_t
*up
;
2501 volatile scc_t
*scp
;
2502 volatile scc_uart_t
*sup
;
2503 volatile immap_t
*immap
;
2505 serial_driver
= alloc_tty_driver(NR_PORTS
);
2509 init_bh(SERIAL_BH
, do_serial_bh
);
2511 show_serial_version();
2513 /* Initialize the tty_driver structure */
2515 serial_driver
->owner
= THIS_MODULE
;
2516 serial_driver
->driver_name
= "serial";
2517 serial_driver
->devfs_name
= "tts/";
2518 serial_driver
->name
= "ttyS";
2519 serial_driver
->major
= TTY_MAJOR
;
2520 serial_driver
->minor_start
= 64;
2521 serial_driver
->type
= TTY_DRIVER_TYPE_SERIAL
;
2522 serial_driver
->subtype
= SERIAL_TYPE_NORMAL
;
2523 serial_driver
->init_termios
= tty_std_termios
;
2524 serial_driver
->init_termios
.c_cflag
=
2525 baud_idx
| CS8
| CREAD
| HUPCL
| CLOCAL
;
2526 serial_driver
->flags
= TTY_DRIVER_REAL_RAW
;
2527 tty_set_operations(serial_driver
, &rs_8xx_ops
);
2529 if (tty_register_driver(serial_driver
))
2530 panic("Couldn't register serial driver\n");
2532 cp
= cpmp
; /* Get pointer to Communication Processor */
2533 immap
= (immap_t
*)IMAP_ADDR
; /* and to internal registers */
2536 /* Configure SCC2, SCC3, and SCC4 instead of port A parallel I/O.
2538 #ifdef CONFIG_USE_SCC_IO
2540 /* The "standard" configuration through the 860.
2542 immap
->im_ioport
.iop_papar
|= 0x00fc;
2543 immap
->im_ioport
.iop_padir
&= ~0x00fc;
2544 immap
->im_ioport
.iop_paodr
&= ~0x00fc;
2546 /* On the MBX, SCC3 is through Port D.
2548 immap
->im_ioport
.iop_papar
|= 0x000c; /* SCC2 on port A */
2549 immap
->im_ioport
.iop_padir
&= ~0x000c;
2550 immap
->im_ioport
.iop_paodr
&= ~0x000c;
2552 immap
->im_ioport
.iop_pdpar
|= 0x0030; /* SCC3 on port D */
2555 /* Since we don't yet do modem control, connect the port C pins
2556 * as general purpose I/O. This will assert CTS and CD for the
2559 immap
->im_ioport
.iop_pcdir
|= 0x03c6;
2560 immap
->im_ioport
.iop_pcpar
&= ~0x03c6;
2562 /* Connect SCC2 and SCC3 to NMSI. Connect BRG3 to SCC2 and
2565 cp
->cp_sicr
&= ~0x00ffff00;
2566 cp
->cp_sicr
|= 0x001b1200;
2569 /* Frequentis PP04 forced to RS-232 until we know better.
2570 * Port C 12 and 13 low enables RS-232 on SCC3 and SCC4.
2572 immap
->im_ioport
.iop_pcdir
|= 0x000c;
2573 immap
->im_ioport
.iop_pcpar
&= ~0x000c;
2574 immap
->im_ioport
.iop_pcdat
&= ~0x000c;
2576 /* This enables the TX driver.
2578 cp
->cp_pbpar
&= ~0x6000;
2579 cp
->cp_pbdat
&= ~0x6000;
2583 for (i
= 0, state
= rs_table
; i
< NR_PORTS
; i
++,state
++) {
2584 state
->magic
= SSTATE_MAGIC
;
2586 state
->type
= PORT_UNKNOWN
;
2587 state
->custom_divisor
= 0;
2588 state
->close_delay
= 5*HZ
/10;
2589 state
->closing_wait
= 30*HZ
;
2590 state
->icount
.cts
= state
->icount
.dsr
=
2591 state
->icount
.rng
= state
->icount
.dcd
= 0;
2592 state
->icount
.rx
= state
->icount
.tx
= 0;
2593 state
->icount
.frame
= state
->icount
.parity
= 0;
2594 state
->icount
.overrun
= state
->icount
.brk
= 0;
2595 printk(KERN_INFO
"ttyS%d at 0x%04x is a %s\n",
2596 i
, (unsigned int)(state
->port
),
2597 (state
->smc_scc_num
& NUM_IS_SCC
) ? "SCC" : "SMC");
2598 #ifdef CONFIG_SERIAL_CONSOLE
2599 /* If we just printed the message on the console port, and
2600 * we are about to initialize it for general use, we have
2601 * to wait a couple of character times for the CR/NL to
2602 * make it out of the transmit buffer.
2604 if (i
== CONFIG_SERIAL_CONSOLE_PORT
)
2607 info
= kmalloc(sizeof(ser_info_t
), GFP_KERNEL
);
2609 __clear_user(info
,sizeof(ser_info_t
));
2610 init_waitqueue_head(&info
->open_wait
);
2611 init_waitqueue_head(&info
->close_wait
);
2612 info
->magic
= SERIAL_MAGIC
;
2613 info
->flags
= state
->flags
;
2614 info
->tqueue
.routine
= do_softint
;
2615 info
->tqueue
.data
= info
;
2616 info
->tqueue_hangup
.routine
= do_serial_hangup
;
2617 info
->tqueue_hangup
.data
= info
;
2619 info
->state
= state
;
2620 state
->info
= (struct async_struct
*)info
;
2622 /* We need to allocate a transmit and receive buffer
2623 * descriptors from dual port ram, and a character
2624 * buffer area from host mem.
2626 dp_offset
= cpm_dpalloc(sizeof(cbd_t
) * RX_NUM_FIFO
, 8);
2628 /* Allocate space for FIFOs in the host memory.
2630 mem_addr
= m8xx_cpm_hostalloc(RX_NUM_FIFO
* RX_BUF_SIZE
);
2631 info
->rx_va_base
= (unsigned char *)mem_addr
;
2633 /* Set the physical address of the host memory
2634 * buffers in the buffer descriptors, and the
2635 * virtual address for us to work with.
2637 bdp
= (cbd_t
*)&cp
->cp_dpmem
[dp_offset
];
2638 info
->rx_cur
= info
->rx_bd_base
= (cbd_t
*)bdp
;
2640 for (j
=0; j
<(RX_NUM_FIFO
-1); j
++) {
2641 bdp
->cbd_bufaddr
= iopa(mem_addr
);
2642 bdp
->cbd_sc
= BD_SC_EMPTY
| BD_SC_INTRPT
;
2643 mem_addr
+= RX_BUF_SIZE
;
2646 bdp
->cbd_bufaddr
= iopa(mem_addr
);
2647 bdp
->cbd_sc
= BD_SC_WRAP
| BD_SC_EMPTY
| BD_SC_INTRPT
;
2649 idx
= PORT_NUM(info
->state
->smc_scc_num
);
2650 if (info
->state
->smc_scc_num
& NUM_IS_SCC
) {
2651 scp
= &cp
->cp_scc
[idx
];
2652 sup
= (scc_uart_t
*)&cp
->cp_dparam
[state
->port
];
2653 sup
->scc_genscc
.scc_rbase
= dp_offset
;
2656 sp
= &cp
->cp_smc
[idx
];
2657 up
= (smc_uart_t
*)&cp
->cp_dparam
[state
->port
];
2658 up
->smc_rbase
= dp_offset
;
2661 dp_offset
= cpm_dpalloc(sizeof(cbd_t
) * TX_NUM_FIFO
, 8);
2663 /* Allocate space for FIFOs in the host memory.
2665 mem_addr
= m8xx_cpm_hostalloc(TX_NUM_FIFO
* TX_BUF_SIZE
);
2666 info
->tx_va_base
= (unsigned char *)mem_addr
;
2668 /* Set the physical address of the host memory
2669 * buffers in the buffer descriptors, and the
2670 * virtual address for us to work with.
2672 bdp
= (cbd_t
*)&cp
->cp_dpmem
[dp_offset
];
2673 info
->tx_cur
= info
->tx_bd_base
= (cbd_t
*)bdp
;
2675 for (j
=0; j
<(TX_NUM_FIFO
-1); j
++) {
2676 bdp
->cbd_bufaddr
= iopa(mem_addr
);
2677 bdp
->cbd_sc
= BD_SC_INTRPT
;
2678 mem_addr
+= TX_BUF_SIZE
;
2681 bdp
->cbd_bufaddr
= iopa(mem_addr
);
2682 bdp
->cbd_sc
= (BD_SC_WRAP
| BD_SC_INTRPT
);
2684 if (info
->state
->smc_scc_num
& NUM_IS_SCC
) {
2685 sup
->scc_genscc
.scc_tbase
= dp_offset
;
2687 /* Set up the uart parameters in the
2690 sup
->scc_genscc
.scc_rfcr
= SMC_EB
;
2691 sup
->scc_genscc
.scc_tfcr
= SMC_EB
;
2693 /* Set this to 1 for now, so we get single
2694 * character interrupts. Using idle charater
2695 * time requires some additional tuning.
2697 sup
->scc_genscc
.scc_mrblr
= 1;
2698 sup
->scc_maxidl
= 0;
2704 sup
->scc_uaddr1
= 0;
2705 sup
->scc_uaddr2
= 0;
2707 sup
->scc_char1
= 0x8000;
2708 sup
->scc_char2
= 0x8000;
2709 sup
->scc_char3
= 0x8000;
2710 sup
->scc_char4
= 0x8000;
2711 sup
->scc_char5
= 0x8000;
2712 sup
->scc_char6
= 0x8000;
2713 sup
->scc_char7
= 0x8000;
2714 sup
->scc_char8
= 0x8000;
2715 sup
->scc_rccm
= 0xc0ff;
2717 /* Send the CPM an initialize command.
2719 chan
= scc_chan_map
[idx
];
2721 cp
->cp_cpcr
= mk_cr_cmd(chan
,
2722 CPM_CR_INIT_TRX
) | CPM_CR_FLG
;
2723 while (cp
->cp_cpcr
& CPM_CR_FLG
);
2725 /* Set UART mode, 8 bit, no parity, one stop.
2726 * Enable receive and transmit.
2730 (SCC_GSMRL_MODE_UART
| SCC_GSMRL_TDCR_16
| SCC_GSMRL_RDCR_16
);
2732 /* Disable all interrupts and clear all pending
2736 scp
->scc_scce
= 0xffff;
2737 scp
->scc_dsr
= 0x7e7e;
2738 scp
->scc_pmsr
= 0x3000;
2740 /* If the port is the console, enable Rx and Tx.
2742 #ifdef CONFIG_SERIAL_CONSOLE
2743 if (i
== CONFIG_SERIAL_CONSOLE_PORT
)
2744 scp
->scc_gsmrl
|= (SCC_GSMRL_ENR
| SCC_GSMRL_ENT
);
2748 /* Configure SMCs Tx/Rx instead of port B
2749 * parallel I/O. On 823/850 these are on
2752 #ifndef CONFIG_ALTSMC2
2753 iobits
= 0xc0 << (idx
* 4);
2754 cp
->cp_pbpar
|= iobits
;
2755 cp
->cp_pbdir
&= ~iobits
;
2756 cp
->cp_pbodr
&= ~iobits
;
2760 /* SMC1 on Port B, like all 8xx.
2762 cp
->cp_pbpar
|= iobits
;
2763 cp
->cp_pbdir
&= ~iobits
;
2764 cp
->cp_pbodr
&= ~iobits
;
2767 /* SMC2 is on Port A.
2769 immap
->im_ioport
.iop_papar
|= iobits
;
2770 immap
->im_ioport
.iop_padir
&= ~iobits
;
2771 immap
->im_ioport
.iop_paodr
&= ~iobits
;
2773 #endif /* CONFIG_ALTSMC2 */
2775 /* Connect the baud rate generator to the
2776 * SMC based upon index in rs_table. Also
2777 * make sure it is connected to NMSI.
2779 cp
->cp_simode
&= ~(0xffff << (idx
* 16));
2780 cp
->cp_simode
|= (i
<< ((idx
* 16) + 12));
2782 up
->smc_tbase
= dp_offset
;
2784 /* Set up the uart parameters in the
2787 up
->smc_rfcr
= SMC_EB
;
2788 up
->smc_tfcr
= SMC_EB
;
2790 /* Set this to 1 for now, so we get single
2791 * character interrupts. Using idle charater
2792 * time requires some additional tuning.
2798 /* Send the CPM an initialize command.
2800 chan
= smc_chan_map
[idx
];
2802 cp
->cp_cpcr
= mk_cr_cmd(chan
,
2803 CPM_CR_INIT_TRX
) | CPM_CR_FLG
;
2804 while (cp
->cp_cpcr
& CPM_CR_FLG
);
2806 /* Set UART mode, 8 bit, no parity, one stop.
2807 * Enable receive and transmit.
2809 sp
->smc_smcmr
= smcr_mk_clen(9) | SMCMR_SM_UART
;
2811 /* Disable all interrupts and clear all pending
2815 sp
->smc_smce
= 0xff;
2817 /* If the port is the console, enable Rx and Tx.
2819 #ifdef CONFIG_SERIAL_CONSOLE
2820 if (i
== CONFIG_SERIAL_CONSOLE_PORT
)
2821 sp
->smc_smcmr
|= SMCMR_REN
| SMCMR_TEN
;
2825 /* Install interrupt handler.
2827 cpm_install_handler(state
->irq
, rs_8xx_interrupt
, info
);
2829 /* Set up the baud rate generator.
2831 m8xx_cpm_setbrg(i
, baud_table
[baud_idx
]);
2838 module_init(rs_8xx_init
);
2840 /* This must always be called before the rs_8xx_init() function, otherwise
2841 * it blows away the port control information.
2843 static int __init
serial_console_setup(struct console
*co
, char *options
)
2845 struct serial_state
*ser
;
2846 uint mem_addr
, bidx
, idx
, dp_offset
;
2848 volatile cbd_t
*bdp
;
2849 volatile cpm8xx_t
*cp
;
2851 volatile scc_t
*scp
;
2852 volatile smc_uart_t
*up
;
2853 volatile scc_uart_t
*sup
;
2858 for (bidx
= 0; bidx
< (sizeof(baud_table
) / sizeof(int)); bidx
++)
2859 if (bd
->bi_baudrate
== baud_table
[bidx
])
2861 /* make sure we have a useful value */
2862 if (bidx
== (sizeof(baud_table
) / sizeof(int)))
2863 bidx
= 13; /* B9600 */
2865 co
->cflag
= CREAD
|CLOCAL
|bidx
|CS8
;
2868 ser
= rs_table
+ co
->index
;
2870 cp
= cpmp
; /* Get pointer to Communication Processor */
2872 idx
= PORT_NUM(ser
->smc_scc_num
);
2873 if (ser
->smc_scc_num
& NUM_IS_SCC
) {
2874 scp
= &cp
->cp_scc
[idx
];
2875 sup
= (scc_uart_t
*)&cp
->cp_dparam
[ser
->port
];
2878 sp
= &cp
->cp_smc
[idx
];
2879 up
= (smc_uart_t
*)&cpmp
->cp_dparam
[ser
->port
];
2882 /* When we get here, the CPM has been reset, so we need
2883 * to configure the port.
2884 * We need to allocate a transmit and receive buffer descriptor
2885 * from dual port ram, and a character buffer area from host mem.
2888 /* Allocate space for two FIFOs. We can't allocate from host
2889 * memory yet because vm allocator isn't initialized
2890 * during this early console init.
2892 dp_offset
= cpm_dpalloc(8, 8);
2893 mem_addr
= (uint
)(&cpmp
->cp_dpmem
[dp_offset
]);
2895 /* Allocate space for two buffer descriptors in the DP ram.
2897 dp_offset
= cpm_dpalloc(sizeof(cbd_t
) * 2, 8);
2899 /* Set the physical address of the host memory buffers in
2900 * the buffer descriptors.
2902 bdp
= (cbd_t
*)&cp
->cp_dpmem
[dp_offset
];
2903 bdp
->cbd_bufaddr
= iopa(mem_addr
);
2904 (bdp
+1)->cbd_bufaddr
= iopa(mem_addr
+4);
2906 consinfo
.rx_va_base
= mem_addr
;
2907 consinfo
.rx_bd_base
= bdp
;
2908 consinfo
.tx_va_base
= mem_addr
+ 4;
2909 consinfo
.tx_bd_base
= bdp
+1;
2911 /* For the receive, set empty and wrap.
2912 * For transmit, set wrap.
2914 bdp
->cbd_sc
= BD_SC_EMPTY
| BD_SC_WRAP
;
2915 (bdp
+1)->cbd_sc
= BD_SC_WRAP
;
2917 /* Set up the uart parameters in the parameter ram.
2919 if (ser
->smc_scc_num
& NUM_IS_SCC
) {
2921 sup
->scc_genscc
.scc_rbase
= dp_offset
;
2922 sup
->scc_genscc
.scc_tbase
= dp_offset
+ sizeof(cbd_t
);
2924 /* Set up the uart parameters in the
2927 sup
->scc_genscc
.scc_rfcr
= SMC_EB
;
2928 sup
->scc_genscc
.scc_tfcr
= SMC_EB
;
2930 /* Set this to 1 for now, so we get single
2931 * character interrupts. Using idle charater
2932 * time requires some additional tuning.
2934 sup
->scc_genscc
.scc_mrblr
= 1;
2935 sup
->scc_maxidl
= 0;
2941 sup
->scc_uaddr1
= 0;
2942 sup
->scc_uaddr2
= 0;
2944 sup
->scc_char1
= 0x8000;
2945 sup
->scc_char2
= 0x8000;
2946 sup
->scc_char3
= 0x8000;
2947 sup
->scc_char4
= 0x8000;
2948 sup
->scc_char5
= 0x8000;
2949 sup
->scc_char6
= 0x8000;
2950 sup
->scc_char7
= 0x8000;
2951 sup
->scc_char8
= 0x8000;
2952 sup
->scc_rccm
= 0xc0ff;
2954 /* Send the CPM an initialize command.
2956 chan
= scc_chan_map
[idx
];
2958 cp
->cp_cpcr
= mk_cr_cmd(chan
, CPM_CR_INIT_TRX
) | CPM_CR_FLG
;
2959 while (cp
->cp_cpcr
& CPM_CR_FLG
);
2961 /* Set UART mode, 8 bit, no parity, one stop.
2962 * Enable receive and transmit.
2966 (SCC_GSMRL_MODE_UART
| SCC_GSMRL_TDCR_16
| SCC_GSMRL_RDCR_16
);
2968 /* Disable all interrupts and clear all pending
2972 scp
->scc_scce
= 0xffff;
2973 scp
->scc_dsr
= 0x7e7e;
2974 scp
->scc_pmsr
= 0x3000;
2976 scp
->scc_gsmrl
|= (SCC_GSMRL_ENR
| SCC_GSMRL_ENT
);
2980 up
->smc_rbase
= dp_offset
; /* Base of receive buffer desc. */
2981 up
->smc_tbase
= dp_offset
+sizeof(cbd_t
); /* Base of xmt buffer desc. */
2982 up
->smc_rfcr
= SMC_EB
;
2983 up
->smc_tfcr
= SMC_EB
;
2985 /* Set this to 1 for now, so we get single character interrupts.
2987 up
->smc_mrblr
= 1; /* receive buffer length */
2988 up
->smc_maxidl
= 0; /* wait forever for next char */
2990 /* Send the CPM an initialize command.
2992 chan
= smc_chan_map
[idx
];
2993 cp
->cp_cpcr
= mk_cr_cmd(chan
, CPM_CR_INIT_TRX
) | CPM_CR_FLG
;
2995 while (cp
->cp_cpcr
& CPM_CR_FLG
);
2997 /* Set UART mode, 8 bit, no parity, one stop.
2998 * Enable receive and transmit.
3000 sp
->smc_smcmr
= smcr_mk_clen(9) | SMCMR_SM_UART
;
3002 /* And finally, enable Rx and Tx.
3004 sp
->smc_smcmr
|= SMCMR_REN
| SMCMR_TEN
;
3007 /* Set up the baud rate generator.
3009 m8xx_cpm_setbrg((ser
- rs_table
), bd
->bi_baudrate
);