2 * UART driver for 68360 CPM SCC or SMC
3 * Copyright (c) 2000 D. Jeff Dionne <jeff@uclinux.org>,
4 * Copyright (c) 2000 Michael Leslie <mleslie@lineo.ca>
5 * Copyright (c) 1997 Dan Malek <dmalek@jlc.net>
7 * I used the serial.c driver as the framework for this driver.
8 * Give credit to those guys.
9 * The original code was written for the MBX860 board. I tried to make
10 * it generic, but there may be some assumptions in the structures that
11 * have to be fixed later.
12 * To save porting time, I did not bother to change any object names
13 * that are not accessed outside of this file.
14 * It still needs lots of work........When it was easy, I included code
15 * to support the SCCs, but this has never been tested, nor is it complete.
16 * Only the SCCs support modem control, so that is not complete either.
18 * This module exports the following rs232 io functions:
20 * int rs_360_init(void);
23 #include <linux/module.h>
24 #include <linux/errno.h>
25 #include <linux/signal.h>
26 #include <linux/sched.h>
27 #include <linux/timer.h>
28 #include <linux/interrupt.h>
29 #include <linux/tty.h>
30 #include <linux/tty_flip.h>
31 #include <linux/serial.h>
32 #include <linux/serialP.h>
33 #include <linux/major.h>
34 #include <linux/string.h>
35 #include <linux/fcntl.h>
36 #include <linux/ptrace.h>
38 #include <linux/init.h>
39 #include <linux/delay.h>
41 #include <asm/m68360.h>
42 #include <asm/commproc.h>
46 extern void breakpoint(void);
47 extern void set_debug_traps(void);
48 extern int kgdb_output_string (const char* s
, unsigned int count
);
52 /* #ifdef CONFIG_SERIAL_CONSOLE */ /* This seems to be a post 2.0 thing - mles */
53 #include <linux/console.h>
54 #include <linux/jiffies.h>
56 /* this defines the index into rs_table for the port to use
58 #ifndef CONFIG_SERIAL_CONSOLE_PORT
59 #define CONFIG_SERIAL_CONSOLE_PORT 1 /* ie SMC2 - note USE_SMC2 must be defined */
65 #define TX_WAKEUP ASYNC_SHARE_IRQ
67 static char *serial_name
= "CPM UART driver";
68 static char *serial_version
= "0.03";
70 static struct tty_driver
*serial_driver
;
71 int serial_console_setup(struct console
*co
, char *options
);
74 * Serial driver configuration section. Here are the various options:
76 #define SERIAL_PARANOIA_CHECK
77 #define CONFIG_SERIAL_NOPAUSE_IO
78 #define SERIAL_DO_RESTART
80 /* Set of debugging defines */
82 #undef SERIAL_DEBUG_INTR
83 #undef SERIAL_DEBUG_OPEN
84 #undef SERIAL_DEBUG_FLOW
85 #undef SERIAL_DEBUG_RS_WAIT_UNTIL_SENT
87 #define _INLINE_ inline
91 /* We overload some of the items in the data structure to meet our
92 * needs. For example, the port address is the CPM parameter ram
93 * offset for the SCC or SMC. The maximum number of ports is 4 SCCs and
94 * 2 SMCs. The "hub6" field is used to indicate the channel number, with
95 * a flag indicating SCC or SMC, and the number is used as an index into
96 * the CPM parameter area for this device.
97 * The "type" field is currently set to 0, for PORT_UNKNOWN. It is
98 * not currently used. I should probably use it to indicate the port
100 * The SMCs do not support any modem control signals.
102 #define smc_scc_num hub6
103 #define NUM_IS_SCC ((int)0x00010000)
104 #define PORT_NUM(P) ((P) & 0x0000ffff)
107 #if defined(CONFIG_UCQUICC)
109 volatile extern void *_periph_base
;
111 * mode bits for are on pins
117 #define SIPEX_MODE(n,m) ((m & 0x0f)<<(16+4*(n-1)))
119 static uint sipex_mode_bits
= 0x00000000;
123 /* There is no `serial_state' defined back here in 2.0.
124 * Try to get by with serial_struct
126 /* #define serial_state serial_struct */
128 /* 2.4 -> 2.0 portability problem: async_icount in 2.4 has a few
133 #define SSTATE_MAGIC 0x5302
137 /* SMC2 is sometimes used for low performance TDM interfaces. Define
138 * this as 1 if you want SMC2 as a serial port UART managed by this driver.
139 * Define this as 0 if you wish to use SMC2 for something else.
145 /* Processors other than the 860 only get SMCs configured by default.
146 * Either they don't have SCCs or they are allocated somewhere else.
147 * Of course, there are now 860s without some SCCs, so we will need to
148 * address that someday.
149 * The Embedded Planet Multimedia I/O cards use TDM interfaces to the
150 * stereo codec parts, and we use SMC2 to help support that.
152 static struct serial_state rs_table
[] = {
153 /* type line PORT IRQ FLAGS smc_scc_num (F.K.A. hub6) */
154 { 0, 0, PRSLOT_SMC1
, CPMVEC_SMC1
, 0, 0 } /* SMC1 ttyS0 */
156 ,{ 0, 0, PRSLOT_SMC2
, CPMVEC_SMC2
, 0, 1 } /* SMC2 ttyS1 */
159 #if defined(CONFIG_SERIAL_68360_SCC)
160 ,{ 0, 0, PRSLOT_SCC2
, CPMVEC_SCC2
, 0, (NUM_IS_SCC
| 1) } /* SCC2 ttyS2 */
161 ,{ 0, 0, PRSLOT_SCC3
, CPMVEC_SCC3
, 0, (NUM_IS_SCC
| 2) } /* SCC3 ttyS3 */
162 ,{ 0, 0, PRSLOT_SCC4
, CPMVEC_SCC4
, 0, (NUM_IS_SCC
| 3) } /* SCC4 ttyS4 */
166 #define NR_PORTS (sizeof(rs_table)/sizeof(struct serial_state))
168 /* The number of buffer descriptors and their sizes.
170 #define RX_NUM_FIFO 4
171 #define RX_BUF_SIZE 32
172 #define TX_NUM_FIFO 4
173 #define TX_BUF_SIZE 32
175 #define CONSOLE_NUM_FIFO 2
176 #define CONSOLE_BUF_SIZE 4
178 char *console_fifos
[CONSOLE_NUM_FIFO
* CONSOLE_BUF_SIZE
];
180 /* The async_struct in serial.h does not really give us what we
181 * need, so define our own here.
183 typedef struct serial_info
{
187 struct serial_state
*state
;
188 /* struct serial_struct *state; */
189 /* struct async_struct *state; */
191 struct tty_struct
*tty
;
192 int read_status_mask
;
193 int ignore_status_mask
;
196 int x_char
; /* xon/xoff character */
198 unsigned short closing_wait
;
199 unsigned short closing_wait2
;
201 unsigned long last_active
;
202 int blocked_open
; /* # of blocked opens */
203 struct work_struct tqueue
;
204 struct work_struct tqueue_hangup
;
205 wait_queue_head_t open_wait
;
206 wait_queue_head_t close_wait
;
209 /* CPM Buffer Descriptor pointers.
211 QUICC_BD
*rx_bd_base
;
213 QUICC_BD
*tx_bd_base
;
218 /* since kmalloc_init() does not get called until much after this initialization: */
219 static ser_info_t quicc_ser_info
[NR_PORTS
];
220 static char rx_buf_pool
[NR_PORTS
* RX_NUM_FIFO
* RX_BUF_SIZE
];
221 static char tx_buf_pool
[NR_PORTS
* TX_NUM_FIFO
* TX_BUF_SIZE
];
223 static void change_speed(ser_info_t
*info
);
224 static void rs_360_wait_until_sent(struct tty_struct
*tty
, int timeout
);
226 static inline int serial_paranoia_check(ser_info_t
*info
,
227 char *name
, const char *routine
)
229 #ifdef SERIAL_PARANOIA_CHECK
230 static const char *badmagic
=
231 "Warning: bad magic number for serial struct (%s) in %s\n";
232 static const char *badinfo
=
233 "Warning: null async_struct for (%s) in %s\n";
236 printk(badinfo
, name
, routine
);
239 if (info
->magic
!= SERIAL_MAGIC
) {
240 printk(badmagic
, name
, routine
);
248 * This is used to figure out the divisor speeds and the timeouts,
249 * indexed by the termio value. The generic CPM functions are responsible
250 * for setting and assigning baud rate generators for us.
252 static int baud_table
[] = {
253 0, 50, 75, 110, 134, 150, 200, 300, 600, 1200, 1800, 2400, 4800,
254 9600, 19200, 38400, 57600, 115200, 230400, 460800, 0 };
256 /* This sucks. There is a better way: */
257 #if defined(CONFIG_CONSOLE_9600)
258 #define CONSOLE_BAUDRATE 9600
259 #elif defined(CONFIG_CONSOLE_19200)
260 #define CONSOLE_BAUDRATE 19200
261 #elif defined(CONFIG_CONSOLE_115200)
262 #define CONSOLE_BAUDRATE 115200
264 #warning "console baud rate undefined"
265 #define CONSOLE_BAUDRATE 9600
269 * ------------------------------------------------------------
270 * rs_stop() and rs_start()
272 * This routines are called before setting or resetting tty->stopped.
273 * They enable or disable transmitter interrupts, as necessary.
274 * ------------------------------------------------------------
276 static void rs_360_stop(struct tty_struct
*tty
)
278 ser_info_t
*info
= (ser_info_t
*)tty
->driver_data
;
281 volatile struct scc_regs
*sccp
;
282 volatile struct smc_regs
*smcp
;
284 if (serial_paranoia_check(info
, tty
->name
, "rs_stop"))
287 local_irq_save(flags
);
288 idx
= PORT_NUM(info
->state
->smc_scc_num
);
289 if (info
->state
->smc_scc_num
& NUM_IS_SCC
) {
290 sccp
= &pquicc
->scc_regs
[idx
];
291 sccp
->scc_sccm
&= ~UART_SCCM_TX
;
293 /* smcp = &cpmp->cp_smc[idx]; */
294 smcp
= &pquicc
->smc_regs
[idx
];
295 smcp
->smc_smcm
&= ~SMCM_TX
;
297 local_irq_restore(flags
);
301 static void rs_360_start(struct tty_struct
*tty
)
303 ser_info_t
*info
= (ser_info_t
*)tty
->driver_data
;
306 volatile struct scc_regs
*sccp
;
307 volatile struct smc_regs
*smcp
;
309 if (serial_paranoia_check(info
, tty
->name
, "rs_stop"))
312 local_irq_save(flags
);
313 idx
= PORT_NUM(info
->state
->smc_scc_num
);
314 if (info
->state
->smc_scc_num
& NUM_IS_SCC
) {
315 sccp
= &pquicc
->scc_regs
[idx
];
316 sccp
->scc_sccm
|= UART_SCCM_TX
;
318 smcp
= &pquicc
->smc_regs
[idx
];
319 smcp
->smc_smcm
|= SMCM_TX
;
321 local_irq_restore(flags
);
325 * ----------------------------------------------------------------------
327 * Here starts the interrupt handling routines. All of the following
328 * subroutines are declared as inline and are folded into
329 * rs_interrupt(). They were separated out for readability's sake.
331 * Note: rs_interrupt() is a "fast" interrupt, which means that it
332 * runs with interrupts turned off. People who may want to modify
333 * rs_interrupt() should try to keep the interrupt handler as fast as
334 * possible. After you are done making modifications, it is not a bad
337 * gcc -S -DKERNEL -Wall -Wstrict-prototypes -O6 -fomit-frame-pointer serial.c
339 * and look at the resulting assemble code in serial.s.
341 * - Ted Ts'o (tytso@mit.edu), 7-Mar-93
342 * -----------------------------------------------------------------------
345 static _INLINE_
void receive_chars(ser_info_t
*info
)
347 struct tty_struct
*tty
= info
->port
.tty
;
348 unsigned char ch
, flag
, *cp
;
352 struct async_icount
*icount
;
353 /* struct async_icount_24 *icount; */
354 volatile QUICC_BD
*bdp
;
356 icount
= &info
->state
->icount
;
358 /* Just loop through the closed BDs and copy the characters into
363 if (bdp
->status
& BD_SC_EMPTY
) /* If this one is empty */
364 break; /* we are all done */
366 /* The read status mask tell us what we should do with
367 * incoming characters, especially if errors occur.
368 * One special case is the use of BD_SC_EMPTY. If
369 * this is not set, we are supposed to be ignoring
370 * inputs. In this case, just mark the buffer empty and
373 if (!(info
->read_status_mask
& BD_SC_EMPTY
)) {
374 bdp
->status
|= BD_SC_EMPTY
;
376 ~(BD_SC_BR
| BD_SC_FR
| BD_SC_PR
| BD_SC_OV
);
378 if (bdp
->status
& BD_SC_WRAP
)
379 bdp
= info
->rx_bd_base
;
385 /* Get the number of characters and the buffer pointer.
388 /* cp = (unsigned char *)__va(bdp->buf); */
389 cp
= (char *)bdp
->buf
;
390 status
= bdp
->status
;
396 #ifdef SERIAL_DEBUG_INTR
397 printk("DR%02x:%02x...", ch
, status
);
401 if (status
& (BD_SC_BR
| BD_SC_FR
|
402 BD_SC_PR
| BD_SC_OV
)) {
404 * For statistics only
406 if (status
& BD_SC_BR
)
408 else if (status
& BD_SC_PR
)
410 else if (status
& BD_SC_FR
)
412 if (status
& BD_SC_OV
)
416 * Now check to see if character should be
417 * ignored, and mask off conditions which
419 if (status & info->ignore_status_mask) {
425 status
&= info
->read_status_mask
;
427 if (status
& (BD_SC_BR
)) {
428 #ifdef SERIAL_DEBUG_INTR
429 printk("handling break....");
431 *tty
->flip
.flag_buf_ptr
= TTY_BREAK
;
432 if (info
->flags
& ASYNC_SAK
)
434 } else if (status
& BD_SC_PR
)
436 else if (status
& BD_SC_FR
)
439 tty_insert_flip_char(tty
, ch
, flag
);
440 if (status
& BD_SC_OV
)
442 * Overrun is special, since it's
443 * reported immediately, and doesn't
444 * affect the current character
446 tty_insert_flip_char(tty
, 0, TTY_OVERRUN
);
449 /* This BD is ready to be used again. Clear status.
452 bdp
->status
|= BD_SC_EMPTY
;
453 bdp
->status
&= ~(BD_SC_BR
| BD_SC_FR
| BD_SC_PR
| BD_SC_OV
);
455 if (bdp
->status
& BD_SC_WRAP
)
456 bdp
= info
->rx_bd_base
;
461 info
->rx_cur
= (QUICC_BD
*)bdp
;
463 tty_schedule_flip(tty
);
466 static _INLINE_
void receive_break(ser_info_t
*info
)
468 struct tty_struct
*tty
= info
->port
.tty
;
470 info
->state
->icount
.brk
++;
471 tty_insert_flip_char(tty
, 0, TTY_BREAK
);
472 tty_schedule_flip(tty
);
475 static _INLINE_
void transmit_chars(ser_info_t
*info
)
478 if ((info
->flags
& TX_WAKEUP
) ||
479 (info
->port
.tty
->flags
& (1 << TTY_DO_WRITE_WAKEUP
))) {
480 schedule_work(&info
->tqueue
);
483 #ifdef SERIAL_DEBUG_INTR
489 /* I need to do this for the SCCs, so it is left as a reminder.
491 static _INLINE_
void check_modem_status(struct async_struct
*info
)
494 /* struct async_icount *icount; */
495 struct async_icount_24
*icount
;
497 status
= serial_in(info
, UART_MSR
);
499 if (status
& UART_MSR_ANY_DELTA
) {
500 icount
= &info
->state
->icount
;
501 /* update input line counters */
502 if (status
& UART_MSR_TERI
)
504 if (status
& UART_MSR_DDSR
)
506 if (status
& UART_MSR_DDCD
) {
508 #ifdef CONFIG_HARD_PPS
509 if ((info
->flags
& ASYNC_HARDPPS_CD
) &&
510 (status
& UART_MSR_DCD
))
514 if (status
& UART_MSR_DCTS
)
516 wake_up_interruptible(&info
->delta_msr_wait
);
519 if ((info
->flags
& ASYNC_CHECK_CD
) && (status
& UART_MSR_DDCD
)) {
520 #if (defined(SERIAL_DEBUG_OPEN) || defined(SERIAL_DEBUG_INTR))
521 printk("ttys%d CD now %s...", info
->line
,
522 (status
& UART_MSR_DCD
) ? "on" : "off");
524 if (status
& UART_MSR_DCD
)
525 wake_up_interruptible(&info
->open_wait
);
527 #ifdef SERIAL_DEBUG_OPEN
528 printk("scheduling hangup...");
530 queue_task(&info
->tqueue_hangup
,
534 if (info
->flags
& ASYNC_CTS_FLOW
) {
535 if (info
->port
.tty
->hw_stopped
) {
536 if (status
& UART_MSR_CTS
) {
537 #if (defined(SERIAL_DEBUG_INTR) || defined(SERIAL_DEBUG_FLOW))
538 printk("CTS tx start...");
540 info
->port
.tty
->hw_stopped
= 0;
541 info
->IER
|= UART_IER_THRI
;
542 serial_out(info
, UART_IER
, info
->IER
);
543 rs_sched_event(info
, RS_EVENT_WRITE_WAKEUP
);
547 if (!(status
& UART_MSR_CTS
)) {
548 #if (defined(SERIAL_DEBUG_INTR) || defined(SERIAL_DEBUG_FLOW))
549 printk("CTS tx stop...");
551 info
->port
.tty
->hw_stopped
= 1;
552 info
->IER
&= ~UART_IER_THRI
;
553 serial_out(info
, UART_IER
, info
->IER
);
561 * This is the serial driver's interrupt routine for a single port
563 /* static void rs_360_interrupt(void *dev_id) */ /* until and if we start servicing irqs here */
564 static void rs_360_interrupt(int vec
, void *dev_id
)
569 volatile struct smc_regs
*smcp
;
570 volatile struct scc_regs
*sccp
;
574 idx
= PORT_NUM(info
->state
->smc_scc_num
);
575 if (info
->state
->smc_scc_num
& NUM_IS_SCC
) {
576 sccp
= &pquicc
->scc_regs
[idx
];
577 events
= sccp
->scc_scce
;
578 if (events
& SCCM_RX
)
580 if (events
& SCCM_TX
)
581 transmit_chars(info
);
582 sccp
->scc_scce
= events
;
584 smcp
= &pquicc
->smc_regs
[idx
];
585 events
= smcp
->smc_smce
;
586 if (events
& SMCM_BRKE
)
588 if (events
& SMCM_RX
)
590 if (events
& SMCM_TX
)
591 transmit_chars(info
);
592 smcp
->smc_smce
= events
;
595 #ifdef SERIAL_DEBUG_INTR
596 printk("rs_interrupt_single(%d, %x)...",
597 info
->state
->smc_scc_num
, events
);
600 check_modem_status(info
);
602 info
->last_active
= jiffies
;
603 #ifdef SERIAL_DEBUG_INTR
610 * -------------------------------------------------------------------
611 * Here ends the serial interrupt routines.
612 * -------------------------------------------------------------------
616 static void do_softint(void *private_
)
618 ser_info_t
*info
= (ser_info_t
*) private_
;
619 struct tty_struct
*tty
;
621 tty
= info
->port
.tty
;
625 if (test_and_clear_bit(RS_EVENT_WRITE_WAKEUP
, &info
->event
))
631 * This routine is called from the scheduler tqueue when the interrupt
632 * routine has signalled that a hangup has occurred. The path of
633 * hangup processing is:
635 * serial interrupt routine -> (scheduler tqueue) ->
636 * do_serial_hangup() -> tty->hangup() -> rs_hangup()
639 static void do_serial_hangup(void *private_
)
641 struct async_struct
*info
= (struct async_struct
*) private_
;
642 struct tty_struct
*tty
;
644 tty
= info
->port
.tty
;
652 static int startup(ser_info_t
*info
)
657 /*struct serial_state *state = info->state;*/
658 volatile struct smc_regs
*smcp
;
659 volatile struct scc_regs
*sccp
;
660 volatile struct smc_uart_pram
*up
;
661 volatile struct uart_pram
*scup
;
664 local_irq_save(flags
);
666 if (info
->flags
& ASYNC_INITIALIZED
) {
671 if (!state
->port
|| !state
->type
) {
673 set_bit(TTY_IO_ERROR
, &info
->port
.tty
->flags
);
678 #ifdef SERIAL_DEBUG_OPEN
679 printk("starting up ttys%d (irq %d)...", info
->line
, state
->irq
);
685 if (info
->port
.tty
->termios
->c_cflag
& CBAUD
)
686 info
->MCR
= UART_MCR_DTR
| UART_MCR_RTS
;
690 clear_bit(TTY_IO_ERROR
, &info
->port
.tty
->flags
);
693 * and set the speed of the serial port
697 idx
= PORT_NUM(info
->state
->smc_scc_num
);
698 if (info
->state
->smc_scc_num
& NUM_IS_SCC
) {
699 sccp
= &pquicc
->scc_regs
[idx
];
700 scup
= &pquicc
->pram
[info
->state
->port
].scc
.pscc
.u
;
702 scup
->mrblr
= RX_BUF_SIZE
;
703 scup
->max_idl
= RX_BUF_SIZE
;
705 sccp
->scc_sccm
|= (UART_SCCM_TX
| UART_SCCM_RX
);
706 sccp
->scc_gsmr
.w
.low
|= (SCC_GSMRL_ENR
| SCC_GSMRL_ENT
);
709 smcp
= &pquicc
->smc_regs
[idx
];
711 /* Enable interrupts and I/O.
713 smcp
->smc_smcm
|= (SMCM_RX
| SMCM_TX
);
714 smcp
->smc_smcmr
|= (SMCMR_REN
| SMCMR_TEN
);
716 /* We can tune the buffer length and idle characters
717 * to take advantage of the entire incoming buffer size.
718 * If mrblr is something other than 1, maxidl has to be
719 * non-zero or we never get an interrupt. The maxidl
720 * is the number of character times we wait after reception
721 * of the last character before we decide no more characters
724 /* up = (smc_uart_t *)&pquicc->cp_dparam[state->port]; */
725 /* holy unionized structures, Batman: */
726 up
= &pquicc
->pram
[info
->state
->port
].scc
.pothers
.idma_smc
.psmc
.u
;
728 up
->mrblr
= RX_BUF_SIZE
;
729 up
->max_idl
= RX_BUF_SIZE
;
731 up
->brkcr
= 1; /* number of break chars */
734 info
->flags
|= ASYNC_INITIALIZED
;
735 local_irq_restore(flags
);
739 local_irq_restore(flags
);
744 * This routine will shutdown a serial port; interrupts are disabled, and
745 * DTR is dropped if the hangup on close termio flag is on.
747 static void shutdown(ser_info_t
*info
)
750 struct serial_state
*state
;
752 volatile struct smc_regs
*smcp
;
753 volatile struct scc_regs
*sccp
;
755 if (!(info
->flags
& ASYNC_INITIALIZED
))
760 #ifdef SERIAL_DEBUG_OPEN
761 printk("Shutting down serial port %d (irq %d)....", info
->line
,
765 local_irq_save(flags
);
767 idx
= PORT_NUM(state
->smc_scc_num
);
768 if (state
->smc_scc_num
& NUM_IS_SCC
) {
769 sccp
= &pquicc
->scc_regs
[idx
];
770 sccp
->scc_gsmr
.w
.low
&= ~(SCC_GSMRL_ENR
| SCC_GSMRL_ENT
);
771 #ifdef CONFIG_SERIAL_CONSOLE
772 /* We can't disable the transmitter if this is the
775 if ((state
- rs_table
) != CONFIG_SERIAL_CONSOLE_PORT
)
777 sccp
->scc_sccm
&= ~(UART_SCCM_TX
| UART_SCCM_RX
);
779 smcp
= &pquicc
->smc_regs
[idx
];
781 /* Disable interrupts and I/O.
783 smcp
->smc_smcm
&= ~(SMCM_RX
| SMCM_TX
);
784 #ifdef CONFIG_SERIAL_CONSOLE
785 /* We can't disable the transmitter if this is the
788 if ((state
- rs_table
) != CONFIG_SERIAL_CONSOLE_PORT
)
790 smcp
->smc_smcmr
&= ~(SMCMR_REN
| SMCMR_TEN
);
794 set_bit(TTY_IO_ERROR
, &info
->port
.tty
->flags
);
796 info
->flags
&= ~ASYNC_INITIALIZED
;
797 local_irq_restore(flags
);
801 * This routine is called to set the UART divisor registers to match
802 * the specified baud rate for a serial port.
804 static void change_speed(ser_info_t
*info
)
807 unsigned cflag
, cval
, scval
, prev_mode
;
808 int i
, bits
, sbits
, idx
;
810 struct serial_state
*state
;
811 volatile struct smc_regs
*smcp
;
812 volatile struct scc_regs
*sccp
;
814 if (!info
->port
.tty
|| !info
->port
.tty
->termios
)
816 cflag
= info
->port
.tty
->termios
->c_cflag
;
820 /* Character length programmed into the mode register is the
821 * sum of: 1 start bit, number of data bits, 0 or 1 parity bit,
822 * 1 or 2 stop bits, minus 1.
823 * The value 'bits' counts this for us.
828 /* byte size and parity */
829 switch (cflag
& CSIZE
) {
830 case CS5
: bits
= 5; break;
831 case CS6
: bits
= 6; break;
832 case CS7
: bits
= 7; break;
833 case CS8
: bits
= 8; break;
834 /* Never happens, but GCC is too dumb to figure it out */
835 default: bits
= 8; break;
839 if (cflag
& CSTOPB
) {
840 cval
|= SMCMR_SL
; /* Two stops */
841 scval
|= SCU_PMSR_SL
;
844 if (cflag
& PARENB
) {
846 scval
|= SCU_PMSR_PEN
;
849 if (!(cflag
& PARODD
)) {
850 cval
|= SMCMR_PM_EVEN
;
851 scval
|= (SCU_PMSR_REVP
| SCU_PMSR_TEVP
);
854 /* Determine divisor based on baud rate */
856 if (i
>= (sizeof(baud_table
)/sizeof(int)))
859 baud_rate
= baud_table
[i
];
861 info
->timeout
= (TX_BUF_SIZE
*HZ
*bits
);
862 info
->timeout
+= HZ
/50; /* Add .02 seconds of slop */
865 /* CTS flow control flag and modem status interrupts */
866 info
->IER
&= ~UART_IER_MSI
;
867 if (info
->flags
& ASYNC_HARDPPS_CD
)
868 info
->IER
|= UART_IER_MSI
;
869 if (cflag
& CRTSCTS
) {
870 info
->flags
|= ASYNC_CTS_FLOW
;
871 info
->IER
|= UART_IER_MSI
;
873 info
->flags
&= ~ASYNC_CTS_FLOW
;
875 info
->flags
&= ~ASYNC_CHECK_CD
;
877 info
->flags
|= ASYNC_CHECK_CD
;
878 info
->IER
|= UART_IER_MSI
;
880 serial_out(info
, UART_IER
, info
->IER
);
884 * Set up parity check flag
886 info
->read_status_mask
= (BD_SC_EMPTY
| BD_SC_OV
);
887 if (I_INPCK(info
->port
.tty
))
888 info
->read_status_mask
|= BD_SC_FR
| BD_SC_PR
;
889 if (I_BRKINT(info
->port
.tty
) || I_PARMRK(info
->port
.tty
))
890 info
->read_status_mask
|= BD_SC_BR
;
893 * Characters to ignore
895 info
->ignore_status_mask
= 0;
896 if (I_IGNPAR(info
->port
.tty
))
897 info
->ignore_status_mask
|= BD_SC_PR
| BD_SC_FR
;
898 if (I_IGNBRK(info
->port
.tty
)) {
899 info
->ignore_status_mask
|= BD_SC_BR
;
901 * If we're ignore parity and break indicators, ignore
902 * overruns too. (For real raw support).
904 if (I_IGNPAR(info
->port
.tty
))
905 info
->ignore_status_mask
|= BD_SC_OV
;
908 * !!! ignore all characters if CREAD is not set
910 if ((cflag
& CREAD
) == 0)
911 info
->read_status_mask
&= ~BD_SC_EMPTY
;
912 local_irq_save(flags
);
914 /* Start bit has not been added (so don't, because we would just
915 * subtract it later), and we need to add one for the number of
916 * stops bits (there is always at least one).
919 idx
= PORT_NUM(state
->smc_scc_num
);
920 if (state
->smc_scc_num
& NUM_IS_SCC
) {
921 sccp
= &pquicc
->scc_regs
[idx
];
922 sccp
->scc_psmr
= (sbits
<< 12) | scval
;
924 smcp
= &pquicc
->smc_regs
[idx
];
926 /* Set the mode register. We want to keep a copy of the
927 * enables, because we want to put them back if they were
930 prev_mode
= smcp
->smc_smcmr
;
931 smcp
->smc_smcmr
= smcr_mk_clen(bits
) | cval
| SMCMR_SM_UART
;
932 smcp
->smc_smcmr
|= (prev_mode
& (SMCMR_REN
| SMCMR_TEN
));
935 m360_cpm_setbrg((state
- rs_table
), baud_rate
);
937 local_irq_restore(flags
);
940 static void rs_360_put_char(struct tty_struct
*tty
, unsigned char ch
)
942 ser_info_t
*info
= (ser_info_t
*)tty
->driver_data
;
943 volatile QUICC_BD
*bdp
;
945 if (serial_paranoia_check(info
, tty
->name
, "rs_put_char"))
952 while (bdp
->status
& BD_SC_READY
);
954 /* *((char *)__va(bdp->buf)) = ch; */
955 *((char *)bdp
->buf
) = ch
;
957 bdp
->status
|= BD_SC_READY
;
961 if (bdp
->status
& BD_SC_WRAP
)
962 bdp
= info
->tx_bd_base
;
966 info
->tx_cur
= (QUICC_BD
*)bdp
;
971 static int rs_360_write(struct tty_struct
* tty
,
972 const unsigned char *buf
, int count
)
975 ser_info_t
*info
= (ser_info_t
*)tty
->driver_data
;
976 volatile QUICC_BD
*bdp
;
979 /* Try to let stub handle output. Returns true if it did. */
980 if (kgdb_output_string(buf
, count
))
984 if (serial_paranoia_check(info
, tty
->name
, "rs_write"))
993 c
= min(count
, TX_BUF_SIZE
);
998 if (bdp
->status
& BD_SC_READY
) {
999 info
->flags
|= TX_WAKEUP
;
1003 /* memcpy(__va(bdp->buf), buf, c); */
1004 memcpy((void *)bdp
->buf
, buf
, c
);
1007 bdp
->status
|= BD_SC_READY
;
1015 if (bdp
->status
& BD_SC_WRAP
)
1016 bdp
= info
->tx_bd_base
;
1019 info
->tx_cur
= (QUICC_BD
*)bdp
;
1024 static int rs_360_write_room(struct tty_struct
*tty
)
1026 ser_info_t
*info
= (ser_info_t
*)tty
->driver_data
;
1029 if (serial_paranoia_check(info
, tty
->name
, "rs_write_room"))
1032 if ((info
->tx_cur
->status
& BD_SC_READY
) == 0) {
1033 info
->flags
&= ~TX_WAKEUP
;
1037 info
->flags
|= TX_WAKEUP
;
1043 /* I could track this with transmit counters....maybe later.
1045 static int rs_360_chars_in_buffer(struct tty_struct
*tty
)
1047 ser_info_t
*info
= (ser_info_t
*)tty
->driver_data
;
1049 if (serial_paranoia_check(info
, tty
->name
, "rs_chars_in_buffer"))
1054 static void rs_360_flush_buffer(struct tty_struct
*tty
)
1056 ser_info_t
*info
= (ser_info_t
*)tty
->driver_data
;
1058 if (serial_paranoia_check(info
, tty
->name
, "rs_flush_buffer"))
1061 /* There is nothing to "flush", whatever we gave the CPM
1062 * is on its way out.
1065 info
->flags
&= ~TX_WAKEUP
;
1069 * This function is used to send a high-priority XON/XOFF character to
1072 static void rs_360_send_xchar(struct tty_struct
*tty
, char ch
)
1074 volatile QUICC_BD
*bdp
;
1076 ser_info_t
*info
= (ser_info_t
*)tty
->driver_data
;
1078 if (serial_paranoia_check(info
, tty
->name
, "rs_send_char"))
1082 while (bdp
->status
& BD_SC_READY
);
1084 /* *((char *)__va(bdp->buf)) = ch; */
1085 *((char *)bdp
->buf
) = ch
;
1087 bdp
->status
|= BD_SC_READY
;
1091 if (bdp
->status
& BD_SC_WRAP
)
1092 bdp
= info
->tx_bd_base
;
1096 info
->tx_cur
= (QUICC_BD
*)bdp
;
1100 * ------------------------------------------------------------
1103 * This routine is called by the upper-layer tty layer to signal that
1104 * incoming characters should be throttled.
1105 * ------------------------------------------------------------
1107 static void rs_360_throttle(struct tty_struct
* tty
)
1109 ser_info_t
*info
= (ser_info_t
*)tty
->driver_data
;
1110 #ifdef SERIAL_DEBUG_THROTTLE
1113 printk("throttle %s: %d....\n", _tty_name(tty
, buf
),
1114 tty
->ldisc
.chars_in_buffer(tty
));
1117 if (serial_paranoia_check(info
, tty
->name
, "rs_throttle"))
1121 rs_360_send_xchar(tty
, STOP_CHAR(tty
));
1123 #ifdef modem_control
1124 if (tty
->termios
->c_cflag
& CRTSCTS
)
1125 info
->MCR
&= ~UART_MCR_RTS
;
1127 local_irq_disable();
1128 serial_out(info
, UART_MCR
, info
->MCR
);
1133 static void rs_360_unthrottle(struct tty_struct
* tty
)
1135 ser_info_t
*info
= (ser_info_t
*)tty
->driver_data
;
1136 #ifdef SERIAL_DEBUG_THROTTLE
1139 printk("unthrottle %s: %d....\n", _tty_name(tty
, buf
),
1140 tty
->ldisc
.chars_in_buffer(tty
));
1143 if (serial_paranoia_check(info
, tty
->name
, "rs_unthrottle"))
1150 rs_360_send_xchar(tty
, START_CHAR(tty
));
1152 #ifdef modem_control
1153 if (tty
->termios
->c_cflag
& CRTSCTS
)
1154 info
->MCR
|= UART_MCR_RTS
;
1155 local_irq_disable();
1156 serial_out(info
, UART_MCR
, info
->MCR
);
1162 * ------------------------------------------------------------
1163 * rs_ioctl() and friends
1164 * ------------------------------------------------------------
1169 * get_lsr_info - get line status register info
1171 * Purpose: Let user call ioctl() to get info when the UART physically
1172 * is emptied. On bus types like RS485, the transmitter must
1173 * release the bus after transmitting. This must be done when
1174 * the transmit shift register is empty, not be done when the
1175 * transmit holding register is empty. This functionality
1176 * allows an RS485 driver to be written in user space.
1178 static int get_lsr_info(struct async_struct
* info
, unsigned int *value
)
1180 unsigned char status
;
1181 unsigned int result
;
1183 local_irq_disable();
1184 status
= serial_in(info
, UART_LSR
);
1186 result
= ((status
& UART_LSR_TEMT
) ? TIOCSER_TEMT
: 0);
1187 return put_user(result
,value
);
1191 static int rs_360_tiocmget(struct tty_struct
*tty
, struct file
*file
)
1193 ser_info_t
*info
= (ser_info_t
*)tty
->driver_data
;
1194 unsigned int result
= 0;
1195 #ifdef modem_control
1196 unsigned char control
, status
;
1198 if (serial_paranoia_check(info
, tty
->name
, __func__
))
1201 if (tty
->flags
& (1 << TTY_IO_ERROR
))
1204 control
= info
->MCR
;
1205 local_irq_disable();
1206 status
= serial_in(info
, UART_MSR
);
1208 result
= ((control
& UART_MCR_RTS
) ? TIOCM_RTS
: 0)
1209 | ((control
& UART_MCR_DTR
) ? TIOCM_DTR
: 0)
1211 | ((control
& UART_MCR_OUT1
) ? TIOCM_OUT1
: 0)
1212 | ((control
& UART_MCR_OUT2
) ? TIOCM_OUT2
: 0)
1214 | ((status
& UART_MSR_DCD
) ? TIOCM_CAR
: 0)
1215 | ((status
& UART_MSR_RI
) ? TIOCM_RNG
: 0)
1216 | ((status
& UART_MSR_DSR
) ? TIOCM_DSR
: 0)
1217 | ((status
& UART_MSR_CTS
) ? TIOCM_CTS
: 0);
1222 static int rs_360_tiocmset(struct tty_struct
*tty
, struct file
*file
,
1223 unsigned int set
, unsigned int clear
)
1225 #ifdef modem_control
1226 ser_info_t
*info
= (ser_info_t
*)tty
->driver_data
;
1229 if (serial_paranoia_check(info
, tty
->name
, __func__
))
1232 if (tty
->flags
& (1 << TTY_IO_ERROR
))
1234 if (set
& TIOCM_RTS
)
1235 info
->mcr
|= UART_MCR_RTS
;
1236 if (set
& TIOCM_DTR
)
1237 info
->mcr
|= UART_MCR_DTR
;
1238 if (clear
& TIOCM_RTS
)
1239 info
->MCR
&= ~UART_MCR_RTS
;
1240 if (clear
& TIOCM_DTR
)
1241 info
->MCR
&= ~UART_MCR_DTR
;
1244 if (set
& TIOCM_OUT1
)
1245 info
->MCR
|= UART_MCR_OUT1
;
1246 if (set
& TIOCM_OUT2
)
1247 info
->MCR
|= UART_MCR_OUT2
;
1248 if (clear
& TIOCM_OUT1
)
1249 info
->MCR
&= ~UART_MCR_OUT1
;
1250 if (clear
& TIOCM_OUT2
)
1251 info
->MCR
&= ~UART_MCR_OUT2
;
1254 local_irq_disable();
1255 serial_out(info
, UART_MCR
, info
->MCR
);
1261 /* Sending a break is a two step process on the SMC/SCC. It is accomplished
1262 * by sending a STOP TRANSMIT command followed by a RESTART TRANSMIT
1263 * command. We take advantage of the begin/end functions to make this
1266 static ushort smc_chan_map
[] = {
1271 static ushort scc_chan_map
[] = {
1278 static void begin_break(ser_info_t
*info
)
1286 idx
= PORT_NUM(info
->state
->smc_scc_num
);
1287 if (info
->state
->smc_scc_num
& NUM_IS_SCC
)
1288 chan
= scc_chan_map
[idx
];
1290 chan
= smc_chan_map
[idx
];
1292 cp
->cp_cr
= mk_cr_cmd(chan
, CPM_CR_STOP_TX
) | CPM_CR_FLG
;
1293 while (cp
->cp_cr
& CPM_CR_FLG
);
1296 static void end_break(ser_info_t
*info
)
1304 idx
= PORT_NUM(info
->state
->smc_scc_num
);
1305 if (info
->state
->smc_scc_num
& NUM_IS_SCC
)
1306 chan
= scc_chan_map
[idx
];
1308 chan
= smc_chan_map
[idx
];
1310 cp
->cp_cr
= mk_cr_cmd(chan
, CPM_CR_RESTART_TX
) | CPM_CR_FLG
;
1311 while (cp
->cp_cr
& CPM_CR_FLG
);
1315 * This routine sends a break character out the serial port.
1317 static void send_break(ser_info_t
*info
, unsigned int duration
)
1319 #ifdef SERIAL_DEBUG_SEND_BREAK
1320 printk("rs_send_break(%d) jiff=%lu...", duration
, jiffies
);
1323 msleep_interruptible(duration
);
1325 #ifdef SERIAL_DEBUG_SEND_BREAK
1326 printk("done jiffies=%lu\n", jiffies
);
1331 static int rs_360_ioctl(struct tty_struct
*tty
, struct file
* file
,
1332 unsigned int cmd
, unsigned long arg
)
1335 ser_info_t
*info
= (ser_info_t
*)tty
->driver_data
;
1337 struct async_icount cnow
;
1338 /* struct async_icount_24 cnow;*/ /* kernel counter temps */
1339 struct serial_icounter_struct
*p_cuser
; /* user space */
1341 if (serial_paranoia_check(info
, tty
->name
, "rs_ioctl"))
1344 if ((cmd
!= TIOCMIWAIT
) && (cmd
!= TIOCGICOUNT
)) {
1345 if (tty
->flags
& (1 << TTY_IO_ERROR
))
1350 case TCSBRK
: /* SVID version: non-zero arg --> no break */
1351 retval
= tty_check_change(tty
);
1354 tty_wait_until_sent(tty
, 0);
1355 if (signal_pending(current
))
1358 send_break(info
, 250); /* 1/4 second */
1359 if (signal_pending(current
))
1363 case TCSBRKP
: /* support for POSIX tcsendbreak() */
1364 retval
= tty_check_change(tty
);
1367 tty_wait_until_sent(tty
, 0);
1368 if (signal_pending(current
))
1370 send_break(info
, arg
? arg
*100 : 250);
1371 if (signal_pending(current
))
1375 retval
= tty_check_change(tty
);
1378 tty_wait_until_sent(tty
, 0);
1382 retval
= tty_check_change(tty
);
1388 case TIOCSERGETLSR
: /* Get line status register */
1389 return get_lsr_info(info
, (unsigned int *) arg
);
1392 * Wait for any of the 4 modem inputs (DCD,RI,DSR,CTS) to change
1393 * - mask passed in arg for lines of interest
1394 * (use |'ed TIOCM_RNG/DSR/CD/CTS for masking)
1395 * Caller should use TIOCGICOUNT to see which one it was
1398 #ifdef modem_control
1399 local_irq_disable();
1400 /* note the counters on entry */
1401 cprev
= info
->state
->icount
;
1404 interruptible_sleep_on(&info
->delta_msr_wait
);
1405 /* see if a signal did it */
1406 if (signal_pending(current
))
1407 return -ERESTARTSYS
;
1408 local_irq_disable();
1409 cnow
= info
->state
->icount
; /* atomic copy */
1411 if (cnow
.rng
== cprev
.rng
&& cnow
.dsr
== cprev
.dsr
&&
1412 cnow
.dcd
== cprev
.dcd
&& cnow
.cts
== cprev
.cts
)
1413 return -EIO
; /* no change => error */
1414 if ( ((arg
& TIOCM_RNG
) && (cnow
.rng
!= cprev
.rng
)) ||
1415 ((arg
& TIOCM_DSR
) && (cnow
.dsr
!= cprev
.dsr
)) ||
1416 ((arg
& TIOCM_CD
) && (cnow
.dcd
!= cprev
.dcd
)) ||
1417 ((arg
& TIOCM_CTS
) && (cnow
.cts
!= cprev
.cts
)) ) {
1428 * Get counter of input serial line interrupts (DCD,RI,DSR,CTS)
1429 * Return: write counters to the user passed counter struct
1430 * NB: both 1->0 and 0->1 transitions are counted except for
1431 * RI where only 0->1 is counted.
1434 local_irq_disable();
1435 cnow
= info
->state
->icount
;
1437 p_cuser
= (struct serial_icounter_struct
*) arg
;
1438 /* error = put_user(cnow.cts, &p_cuser->cts); */
1439 /* if (error) return error; */
1440 /* error = put_user(cnow.dsr, &p_cuser->dsr); */
1441 /* if (error) return error; */
1442 /* error = put_user(cnow.rng, &p_cuser->rng); */
1443 /* if (error) return error; */
1444 /* error = put_user(cnow.dcd, &p_cuser->dcd); */
1445 /* if (error) return error; */
1447 put_user(cnow
.cts
, &p_cuser
->cts
);
1448 put_user(cnow
.dsr
, &p_cuser
->dsr
);
1449 put_user(cnow
.rng
, &p_cuser
->rng
);
1450 put_user(cnow
.dcd
, &p_cuser
->dcd
);
1454 return -ENOIOCTLCMD
;
1459 /* FIX UP modem control here someday......
1461 static void rs_360_set_termios(struct tty_struct
*tty
, struct ktermios
*old_termios
)
1463 ser_info_t
*info
= (ser_info_t
*)tty
->driver_data
;
1467 #ifdef modem_control
1468 /* Handle transition to B0 status */
1469 if ((old_termios
->c_cflag
& CBAUD
) &&
1470 !(tty
->termios
->c_cflag
& CBAUD
)) {
1471 info
->MCR
&= ~(UART_MCR_DTR
|UART_MCR_RTS
);
1472 local_irq_disable();
1473 serial_out(info
, UART_MCR
, info
->MCR
);
1477 /* Handle transition away from B0 status */
1478 if (!(old_termios
->c_cflag
& CBAUD
) &&
1479 (tty
->termios
->c_cflag
& CBAUD
)) {
1480 info
->MCR
|= UART_MCR_DTR
;
1481 if (!tty
->hw_stopped
||
1482 !(tty
->termios
->c_cflag
& CRTSCTS
)) {
1483 info
->MCR
|= UART_MCR_RTS
;
1485 local_irq_disable();
1486 serial_out(info
, UART_MCR
, info
->MCR
);
1490 /* Handle turning off CRTSCTS */
1491 if ((old_termios
->c_cflag
& CRTSCTS
) &&
1492 !(tty
->termios
->c_cflag
& CRTSCTS
)) {
1493 tty
->hw_stopped
= 0;
1501 * ------------------------------------------------------------
1504 * This routine is called when the serial port gets closed. First, we
1505 * wait for the last remaining data to be sent. Then, we unlink its
1506 * async structure from the interrupt chain if necessary, and we free
1507 * that IRQ if nothing is left in the chain.
1508 * ------------------------------------------------------------
1510 static void rs_360_close(struct tty_struct
*tty
, struct file
* filp
)
1512 ser_info_t
*info
= (ser_info_t
*)tty
->driver_data
;
1513 /* struct async_state *state; */
1514 struct serial_state
*state
;
1515 unsigned long flags
;
1517 volatile struct smc_regs
*smcp
;
1518 volatile struct scc_regs
*sccp
;
1520 if (!info
|| serial_paranoia_check(info
, tty
->name
, "rs_close"))
1523 state
= info
->state
;
1525 local_irq_save(flags
);
1527 if (tty_hung_up_p(filp
)) {
1528 DBG_CNT("before DEC-hung");
1529 local_irq_restore(flags
);
1533 #ifdef SERIAL_DEBUG_OPEN
1534 printk("rs_close ttys%d, count = %d\n", info
->line
, state
->count
);
1536 if ((tty
->count
== 1) && (state
->count
!= 1)) {
1538 * Uh, oh. tty->count is 1, which means that the tty
1539 * structure will be freed. state->count should always
1540 * be one in these conditions. If it's greater than
1541 * one, we've got real problems, since it means the
1542 * serial port won't be shutdown.
1544 printk("rs_close: bad serial port count; tty->count is 1, "
1545 "state->count is %d\n", state
->count
);
1548 if (--state
->count
< 0) {
1549 printk("rs_close: bad serial port count for ttys%d: %d\n",
1550 info
->line
, state
->count
);
1554 DBG_CNT("before DEC-2");
1555 local_irq_restore(flags
);
1558 info
->flags
|= ASYNC_CLOSING
;
1560 * Now we wait for the transmit buffer to clear; and we notify
1561 * the line discipline to only process XON/XOFF characters.
1564 if (info
->closing_wait
!= ASYNC_CLOSING_WAIT_NONE
)
1565 tty_wait_until_sent(tty
, info
->closing_wait
);
1567 * At this point we stop accepting input. To do this, we
1568 * disable the receive line status interrupts, and tell the
1569 * interrupt driver to stop checking the data ready bit in the
1570 * line status register.
1572 info
->read_status_mask
&= ~BD_SC_EMPTY
;
1573 if (info
->flags
& ASYNC_INITIALIZED
) {
1575 idx
= PORT_NUM(info
->state
->smc_scc_num
);
1576 if (info
->state
->smc_scc_num
& NUM_IS_SCC
) {
1577 sccp
= &pquicc
->scc_regs
[idx
];
1578 sccp
->scc_sccm
&= ~UART_SCCM_RX
;
1579 sccp
->scc_gsmr
.w
.low
&= ~SCC_GSMRL_ENR
;
1581 smcp
= &pquicc
->smc_regs
[idx
];
1582 smcp
->smc_smcm
&= ~SMCM_RX
;
1583 smcp
->smc_smcmr
&= ~SMCMR_REN
;
1586 * Before we drop DTR, make sure the UART transmitter
1587 * has completely drained; this is especially
1588 * important if there is a transmit FIFO!
1590 rs_360_wait_until_sent(tty
, info
->timeout
);
1593 rs_360_flush_buffer(tty
);
1594 tty_ldisc_flush(tty
);
1597 info
->port
.tty
= NULL
;
1598 if (info
->blocked_open
) {
1599 if (info
->close_delay
) {
1600 msleep_interruptible(jiffies_to_msecs(info
->close_delay
));
1602 wake_up_interruptible(&info
->open_wait
);
1604 info
->flags
&= ~(ASYNC_NORMAL_ACTIVE
|ASYNC_CLOSING
);
1605 wake_up_interruptible(&info
->close_wait
);
1606 local_irq_restore(flags
);
1610 * rs_wait_until_sent() --- wait until the transmitter is empty
1612 static void rs_360_wait_until_sent(struct tty_struct
*tty
, int timeout
)
1614 ser_info_t
*info
= (ser_info_t
*)tty
->driver_data
;
1615 unsigned long orig_jiffies
, char_time
;
1617 volatile QUICC_BD
*bdp
;
1619 if (serial_paranoia_check(info
, tty
->name
, "rs_wait_until_sent"))
1623 if (info
->state
->type
== PORT_UNKNOWN
)
1627 orig_jiffies
= jiffies
;
1629 * Set the check interval to be 1/5 of the estimated time to
1630 * send a single character, and make it at least 1. The check
1631 * interval should also be less than the timeout.
1633 * Note: we have to use pretty tight timings here to satisfy
1638 char_time
= min(char_time
, (unsigned long)timeout
);
1639 #ifdef SERIAL_DEBUG_RS_WAIT_UNTIL_SENT
1640 printk("In rs_wait_until_sent(%d) check=%lu...", timeout
, char_time
);
1641 printk("jiff=%lu...", jiffies
);
1644 /* We go through the loop at least once because we can't tell
1645 * exactly when the last character exits the shifter. There can
1646 * be at least two characters waiting to be sent after the buffers
1650 #ifdef SERIAL_DEBUG_RS_WAIT_UNTIL_SENT
1651 printk("lsr = %d (jiff=%lu)...", lsr
, jiffies
);
1653 /* current->counter = 0; make us low-priority */
1654 msleep_interruptible(jiffies_to_msecs(char_time
));
1655 if (signal_pending(current
))
1657 if (timeout
&& (time_after(jiffies
, orig_jiffies
+ timeout
)))
1659 /* The 'tx_cur' is really the next buffer to send. We
1660 * have to back up to the previous BD and wait for it
1661 * to go. This isn't perfect, because all this indicates
1662 * is the buffer is available. There are still characters
1666 if (bdp
== info
->tx_bd_base
)
1667 bdp
+= (TX_NUM_FIFO
-1);
1670 } while (bdp
->status
& BD_SC_READY
);
1671 current
->state
= TASK_RUNNING
;
1672 #ifdef SERIAL_DEBUG_RS_WAIT_UNTIL_SENT
1673 printk("lsr = %d (jiff=%lu)...done\n", lsr
, jiffies
);
1678 * rs_hangup() --- called by tty_hangup() when a hangup is signaled.
1680 static void rs_360_hangup(struct tty_struct
*tty
)
1682 ser_info_t
*info
= (ser_info_t
*)tty
->driver_data
;
1683 struct serial_state
*state
= info
->state
;
1685 if (serial_paranoia_check(info
, tty
->name
, "rs_hangup"))
1688 state
= info
->state
;
1690 rs_360_flush_buffer(tty
);
1694 info
->flags
&= ~ASYNC_NORMAL_ACTIVE
;
1695 info
->port
.tty
= NULL
;
1696 wake_up_interruptible(&info
->open_wait
);
1700 * ------------------------------------------------------------
1701 * rs_open() and friends
1702 * ------------------------------------------------------------
1704 static int block_til_ready(struct tty_struct
*tty
, struct file
* filp
,
1707 #ifdef DO_THIS_LATER
1708 DECLARE_WAITQUEUE(wait
, current
);
1710 struct serial_state
*state
= info
->state
;
1715 * If the device is in the middle of being closed, then block
1716 * until it's done, and then try again.
1718 if (tty_hung_up_p(filp
) ||
1719 (info
->flags
& ASYNC_CLOSING
)) {
1720 if (info
->flags
& ASYNC_CLOSING
)
1721 interruptible_sleep_on(&info
->close_wait
);
1722 #ifdef SERIAL_DO_RESTART
1723 if (info
->flags
& ASYNC_HUP_NOTIFY
)
1726 return -ERESTARTSYS
;
1733 * If non-blocking mode is set, or the port is not enabled,
1734 * then make the check up front and then exit.
1735 * If this is an SMC port, we don't have modem control to wait
1736 * for, so just get out here.
1738 if ((filp
->f_flags
& O_NONBLOCK
) ||
1739 (tty
->flags
& (1 << TTY_IO_ERROR
)) ||
1740 !(info
->state
->smc_scc_num
& NUM_IS_SCC
)) {
1741 info
->flags
|= ASYNC_NORMAL_ACTIVE
;
1745 if (tty
->termios
->c_cflag
& CLOCAL
)
1749 * Block waiting for the carrier detect and the line to become
1750 * free (i.e., not in use by the callout). While we are in
1751 * this loop, state->count is dropped by one, so that
1752 * rs_close() knows when to free things. We restore it upon
1753 * exit, either normal or abnormal.
1756 #ifdef DO_THIS_LATER
1757 add_wait_queue(&info
->open_wait
, &wait
);
1758 #ifdef SERIAL_DEBUG_OPEN
1759 printk("block_til_ready before block: ttys%d, count = %d\n",
1760 state
->line
, state
->count
);
1762 local_irq_disable();
1763 if (!tty_hung_up_p(filp
))
1766 info
->blocked_open
++;
1768 local_irq_disable();
1769 if (tty
->termios
->c_cflag
& CBAUD
)
1770 serial_out(info
, UART_MCR
,
1771 serial_inp(info
, UART_MCR
) |
1772 (UART_MCR_DTR
| UART_MCR_RTS
));
1774 set_current_state(TASK_INTERRUPTIBLE
);
1775 if (tty_hung_up_p(filp
) ||
1776 !(info
->flags
& ASYNC_INITIALIZED
)) {
1777 #ifdef SERIAL_DO_RESTART
1778 if (info
->flags
& ASYNC_HUP_NOTIFY
)
1781 retval
= -ERESTARTSYS
;
1787 if (!(info
->flags
& ASYNC_CLOSING
) &&
1788 (do_clocal
|| (serial_in(info
, UART_MSR
) &
1791 if (signal_pending(current
)) {
1792 retval
= -ERESTARTSYS
;
1795 #ifdef SERIAL_DEBUG_OPEN
1796 printk("block_til_ready blocking: ttys%d, count = %d\n",
1797 info
->line
, state
->count
);
1803 current
->state
= TASK_RUNNING
;
1804 remove_wait_queue(&info
->open_wait
, &wait
);
1805 if (!tty_hung_up_p(filp
))
1807 info
->blocked_open
--;
1808 #ifdef SERIAL_DEBUG_OPEN
1809 printk("block_til_ready after blocking: ttys%d, count = %d\n",
1810 info
->line
, state
->count
);
1812 #endif /* DO_THIS_LATER */
1815 info
->flags
|= ASYNC_NORMAL_ACTIVE
;
1819 static int get_async_struct(int line
, ser_info_t
**ret_info
)
1821 struct serial_state
*sstate
;
1823 sstate
= rs_table
+ line
;
1826 *ret_info
= (ser_info_t
*)sstate
->info
;
1835 * This routine is called whenever a serial port is opened. It
1836 * enables interrupts for a serial port, linking in its async structure into
1837 * the IRQ chain. It also performs the serial-specific
1838 * initialization for the tty structure.
1840 static int rs_360_open(struct tty_struct
*tty
, struct file
* filp
)
1846 if ((line
< 0) || (line
>= NR_PORTS
))
1848 retval
= get_async_struct(line
, &info
);
1851 if (serial_paranoia_check(info
, tty
->name
, "rs_open"))
1854 #ifdef SERIAL_DEBUG_OPEN
1855 printk("rs_open %s, count = %d\n", tty
->name
, info
->state
->count
);
1857 tty
->driver_data
= info
;
1858 info
->port
.tty
= tty
;
1861 * Start up serial port
1863 retval
= startup(info
);
1867 retval
= block_til_ready(tty
, filp
, info
);
1869 #ifdef SERIAL_DEBUG_OPEN
1870 printk("rs_open returning after block_til_ready with %d\n",
1876 #ifdef SERIAL_DEBUG_OPEN
1877 printk("rs_open %s successful...", tty
->name
);
1883 * /proc fs routines....
1886 static inline int line_info(char *buf
, struct serial_state
*state
)
1889 struct async_struct
*info
= state
->info
, scr_info
;
1890 char stat_buf
[30], control
, status
;
1894 ret
= sprintf(buf
, "%d: uart:%s port:%X irq:%d",
1896 (state
->smc_scc_num
& NUM_IS_SCC
) ? "SCC" : "SMC",
1897 (unsigned int)(state
->port
), state
->irq
);
1899 if (!state
->port
|| (state
->type
== PORT_UNKNOWN
)) {
1900 ret
+= sprintf(buf
+ret
, "\n");
1906 * Figure out the current RS-232 lines
1909 info
= &scr_info
; /* This is just for serial_{in,out} */
1911 info
->magic
= SERIAL_MAGIC
;
1912 info
->port
= state
->port
;
1913 info
->flags
= state
->flags
;
1915 info
->port
.tty
= NULL
;
1917 local_irq_disable();
1918 status
= serial_in(info
, UART_MSR
);
1919 control
= info
? info
->MCR
: serial_in(info
, UART_MCR
);
1924 if (control
& UART_MCR_RTS
)
1925 strcat(stat_buf
, "|RTS");
1926 if (status
& UART_MSR_CTS
)
1927 strcat(stat_buf
, "|CTS");
1928 if (control
& UART_MCR_DTR
)
1929 strcat(stat_buf
, "|DTR");
1930 if (status
& UART_MSR_DSR
)
1931 strcat(stat_buf
, "|DSR");
1932 if (status
& UART_MSR_DCD
)
1933 strcat(stat_buf
, "|CD");
1934 if (status
& UART_MSR_RI
)
1935 strcat(stat_buf
, "|RI");
1938 ret
+= sprintf(buf
+ret
, " baud:%d",
1939 state
->baud_base
/ info
->quot
);
1942 ret
+= sprintf(buf
+ret
, " tx:%d rx:%d",
1943 state
->icount
.tx
, state
->icount
.rx
);
1945 if (state
->icount
.frame
)
1946 ret
+= sprintf(buf
+ret
, " fe:%d", state
->icount
.frame
);
1948 if (state
->icount
.parity
)
1949 ret
+= sprintf(buf
+ret
, " pe:%d", state
->icount
.parity
);
1951 if (state
->icount
.brk
)
1952 ret
+= sprintf(buf
+ret
, " brk:%d", state
->icount
.brk
);
1954 if (state
->icount
.overrun
)
1955 ret
+= sprintf(buf
+ret
, " oe:%d", state
->icount
.overrun
);
1958 * Last thing is the RS-232 status lines
1960 ret
+= sprintf(buf
+ret
, " %s\n", stat_buf
+1);
1965 int rs_360_read_proc(char *page
, char **start
, off_t off
, int count
,
1966 int *eof
, void *data
)
1971 len
+= sprintf(page
, "serinfo:1.0 driver:%s\n", serial_version
);
1972 for (i
= 0; i
< NR_PORTS
&& len
< 4000; i
++) {
1973 len
+= line_info(page
+ len
, &rs_table
[i
]);
1974 if (len
+begin
> off
+count
)
1976 if (len
+begin
< off
) {
1983 if (off
>= len
+begin
)
1985 *start
= page
+ (begin
-off
);
1986 return ((count
< begin
+len
-off
) ? count
: begin
+len
-off
);
1990 * ---------------------------------------------------------------------
1991 * rs_init() and friends
1993 * rs_init() is called at boot-time to initialize the serial driver.
1994 * ---------------------------------------------------------------------
1998 * This routine prints out the appropriate serial driver version
1999 * number, and identifies which options were configured into this
2002 static _INLINE_
void show_serial_version(void)
2004 printk(KERN_INFO
"%s version %s\n", serial_name
, serial_version
);
2009 * The serial console driver used during boot. Note that these names
2010 * clash with those found in "serial.c", so we currently can't support
2011 * the 16xxx uarts and these at the same time. I will fix this to become
2012 * an indirect function call from tty_io.c (or something).
2015 #ifdef CONFIG_SERIAL_CONSOLE
2018 * Print a string to the serial port trying not to disturb any possible
2019 * real use of the port...
2021 static void my_console_write(int idx
, const char *s
,
2024 struct serial_state
*ser
;
2027 QUICC_BD
*bdp
, *bdbase
;
2028 volatile struct smc_uart_pram
*up
;
2029 volatile u_char
*cp
;
2031 ser
= rs_table
+ idx
;
2034 /* If the port has been initialized for general use, we have
2035 * to use the buffer descriptors allocated there. Otherwise,
2036 * we simply use the single buffer allocated.
2038 if ((info
= (ser_info_t
*)ser
->info
) != NULL
) {
2040 bdbase
= info
->tx_bd_base
;
2043 /* Pointer to UART in parameter ram.
2045 /* up = (smc_uart_t *)&cpmp->cp_dparam[ser->port]; */
2046 up
= &pquicc
->pram
[ser
->port
].scc
.pothers
.idma_smc
.psmc
.u
;
2048 /* Get the address of the host memory buffer.
2050 bdp
= bdbase
= (QUICC_BD
*)((uint
)pquicc
+ (uint
)up
->tbase
);
2054 * We need to gracefully shut down the transmitter, disable
2055 * interrupts, then send our bytes out.
2059 * Now, do each character. This is not as bad as it looks
2060 * since this is a holding FIFO and not a transmitting FIFO.
2061 * We could add the complexity of filling the entire transmit
2062 * buffer, but we would just wait longer between accesses......
2064 for (i
= 0; i
< count
; i
++, s
++) {
2065 /* Wait for transmitter fifo to empty.
2066 * Ready indicates output is ready, and xmt is doing
2067 * that, not that it is ready for us to send.
2069 while (bdp
->status
& BD_SC_READY
);
2071 /* Send the character out.
2077 bdp
->status
|= BD_SC_READY
;
2079 if (bdp
->status
& BD_SC_WRAP
)
2084 /* if a LF, also do CR... */
2086 while (bdp
->status
& BD_SC_READY
);
2087 /* cp = __va(bdp->buf); */
2091 bdp
->status
|= BD_SC_READY
;
2093 if (bdp
->status
& BD_SC_WRAP
) {
2103 * Finally, Wait for transmitter & holding register to empty
2104 * and restore the IER
2106 while (bdp
->status
& BD_SC_READY
);
2109 info
->tx_cur
= (QUICC_BD
*)bdp
;
2112 static void serial_console_write(struct console
*c
, const char *s
,
2116 /* Try to let stub handle output. Returns true if it did. */
2117 if (kgdb_output_string(s
, count
))
2120 my_console_write(c
->index
, s
, count
);
2125 /*void console_print_68360(const char *p)
2130 for (i=0;cp[i]!=0;i++);
2132 serial_console_write (p, i);
2134 //Comment this if you want to have a strict interrupt-driven output
2147 xmon_360_write(const char *s
, unsigned count
)
2149 my_console_write(0, s
, count
);
2156 putDebugChar(char ch
)
2158 my_console_write(0, &ch
, 1);
2163 * Receive character from the serial port. This only works well
2164 * before the port is initialized for real use.
2166 static int my_console_wait_key(int idx
, int xmon
, char *obuf
)
2168 struct serial_state
*ser
;
2172 volatile struct smc_uart_pram
*up
;
2175 ser
= rs_table
+ idx
;
2177 /* Get the address of the host memory buffer.
2178 * If the port has been initialized for general use, we must
2179 * use information from the port structure.
2181 if ((info
= (ser_info_t
*)ser
->info
))
2184 /* bdp = (QUICC_BD *)&cpmp->cp_dpmem[up->smc_rbase]; */
2185 bdp
= (QUICC_BD
*)((uint
)pquicc
+ (uint
)up
->tbase
);
2187 /* Pointer to UART in parameter ram.
2189 /* up = (smc_uart_t *)&cpmp->cp_dparam[ser->port]; */
2190 up
= &pquicc
->pram
[info
->state
->port
].scc
.pothers
.idma_smc
.psmc
.u
;
2193 * We need to gracefully shut down the receiver, disable
2194 * interrupts, then read the input.
2195 * XMON just wants a poll. If no character, return -1, else
2196 * return the character.
2199 while (bdp
->status
& BD_SC_EMPTY
);
2202 if (bdp
->status
& BD_SC_EMPTY
)
2206 cp
= (char *)bdp
->buf
;
2209 i
= c
= bdp
->length
;
2216 bdp
->status
|= BD_SC_EMPTY
;
2219 if (bdp
->status
& BD_SC_WRAP
) {
2220 bdp
= info
->rx_bd_base
;
2225 info
->rx_cur
= (QUICC_BD
*)bdp
;
2231 static int serial_console_wait_key(struct console
*co
)
2233 return(my_console_wait_key(co
->index
, 0, NULL
));
2238 xmon_360_read_poll(void)
2240 return(my_console_wait_key(0, 1, NULL
));
2244 xmon_360_read_char(void)
2246 return(my_console_wait_key(0, 0, NULL
));
2251 static char kgdb_buf
[RX_BUF_SIZE
], *kgdp
;
2252 static int kgdb_chars
;
2257 if (kgdb_chars
<= 0) {
2258 kgdb_chars
= my_console_wait_key(0, 0, kgdb_buf
);
2266 void kgdb_interruptible(int state
)
2269 void kgdb_map_scc(void)
2271 struct serial_state
*ser
;
2273 volatile QUICC_BD
*bdp
;
2274 volatile smc_uart_t
*up
;
2276 cpmp
= (cpm360_t
*)&(((immap_t
*)IMAP_ADDR
)->im_cpm
);
2278 /* To avoid data cache CPM DMA coherency problems, allocate a
2279 * buffer in the CPM DPRAM. This will work until the CPM and
2280 * serial ports are initialized. At that time a memory buffer
2281 * will be allocated.
2282 * The port is already initialized from the boot procedure, all
2283 * we do here is give it a different buffer and make it a FIFO.
2288 /* Right now, assume we are using SMCs.
2290 up
= (smc_uart_t
*)&cpmp
->cp_dparam
[ser
->port
];
2292 /* Allocate space for an input FIFO, plus a few bytes for output.
2293 * Allocate bytes to maintain word alignment.
2295 mem_addr
= (uint
)(&cpmp
->cp_dpmem
[0x1000]);
2297 /* Set the physical address of the host memory buffers in
2298 * the buffer descriptors.
2300 bdp
= (QUICC_BD
*)&cpmp
->cp_dpmem
[up
->smc_rbase
];
2301 bdp
->buf
= mem_addr
;
2303 bdp
= (QUICC_BD
*)&cpmp
->cp_dpmem
[up
->smc_tbase
];
2304 bdp
->buf
= mem_addr
+RX_BUF_SIZE
;
2306 up
->smc_mrblr
= RX_BUF_SIZE
; /* receive buffer length */
2307 up
->smc_maxidl
= RX_BUF_SIZE
;
2311 static struct tty_struct
*serial_console_device(struct console
*c
, int *index
)
2314 return serial_driver
;
2318 struct console sercons
= {
2320 .write
= serial_console_write
,
2321 .device
= serial_console_device
,
2322 .wait_key
= serial_console_wait_key
,
2323 .setup
= serial_console_setup
,
2324 .flags
= CON_PRINTBUFFER
,
2325 .index
= CONFIG_SERIAL_CONSOLE_PORT
,
2333 long console_360_init(long kmem_start
, long kmem_end
)
2335 register_console(&sercons
);
2336 /*register_console (console_print_68360); - 2.0.38 only required a write
2337 function pointer. */
2343 /* Index in baud rate table of the default console baud rate.
2345 static int baud_idx
;
2347 static const struct tty_operations rs_360_ops
= {
2348 .owner
= THIS_MODULE
,
2349 .open
= rs_360_open
,
2350 .close
= rs_360_close
,
2351 .write
= rs_360_write
,
2352 .put_char
= rs_360_put_char
,
2353 .write_room
= rs_360_write_room
,
2354 .chars_in_buffer
= rs_360_chars_in_buffer
,
2355 .flush_buffer
= rs_360_flush_buffer
,
2356 .ioctl
= rs_360_ioctl
,
2357 .throttle
= rs_360_throttle
,
2358 .unthrottle
= rs_360_unthrottle
,
2359 /* .send_xchar = rs_360_send_xchar, */
2360 .set_termios
= rs_360_set_termios
,
2361 .stop
= rs_360_stop
,
2362 .start
= rs_360_start
,
2363 .hangup
= rs_360_hangup
,
2364 /* .wait_until_sent = rs_360_wait_until_sent, */
2365 /* .read_proc = rs_360_read_proc, */
2366 .tiocmget
= rs_360_tiocmget
,
2367 .tiocmset
= rs_360_tiocmset
,
2370 static int __init
rs_360_init(void)
2372 struct serial_state
* state
;
2375 uint dp_addr
, iobits
;
2380 volatile struct smc_regs
*sp
;
2381 volatile struct smc_uart_pram
*up
;
2382 volatile struct scc_regs
*scp
;
2383 volatile struct uart_pram
*sup
;
2384 /* volatile immap_t *immap; */
2386 serial_driver
= alloc_tty_driver(NR_PORTS
);
2390 show_serial_version();
2392 serial_driver
->name
= "ttyS";
2393 serial_driver
->major
= TTY_MAJOR
;
2394 serial_driver
->minor_start
= 64;
2395 serial_driver
->type
= TTY_DRIVER_TYPE_SERIAL
;
2396 serial_driver
->subtype
= SERIAL_TYPE_NORMAL
;
2397 serial_driver
->init_termios
= tty_std_termios
;
2398 serial_driver
->init_termios
.c_cflag
=
2399 baud_idx
| CS8
| CREAD
| HUPCL
| CLOCAL
;
2400 serial_driver
->flags
= TTY_DRIVER_REAL_RAW
;
2401 tty_set_operations(serial_driver
, &rs_360_ops
);
2403 if (tty_register_driver(serial_driver
))
2404 panic("Couldn't register serial driver\n");
2406 cp
= pquicc
; /* Get pointer to Communication Processor */
2407 /* immap = (immap_t *)IMAP_ADDR; */ /* and to internal registers */
2410 /* Configure SCC2, SCC3, and SCC4 instead of port A parallel I/O.
2412 /* The "standard" configuration through the 860.
2414 /* immap->im_ioport.iop_papar |= 0x00fc; */
2415 /* immap->im_ioport.iop_padir &= ~0x00fc; */
2416 /* immap->im_ioport.iop_paodr &= ~0x00fc; */
2417 cp
->pio_papar
|= 0x00fc;
2418 cp
->pio_padir
&= ~0x00fc;
2419 /* cp->pio_paodr &= ~0x00fc; */
2422 /* Since we don't yet do modem control, connect the port C pins
2423 * as general purpose I/O. This will assert CTS and CD for the
2426 /* immap->im_ioport.iop_pcdir |= 0x03c6; */
2427 /* immap->im_ioport.iop_pcpar &= ~0x03c6; */
2429 /* cp->pio_pcdir |= 0x03c6; */
2430 /* cp->pio_pcpar &= ~0x03c6; */
2434 /* Connect SCC2 and SCC3 to NMSI. Connect BRG3 to SCC2 and
2437 cp
->si_sicr
&= ~0x00ffff00;
2438 cp
->si_sicr
|= 0x001b1200;
2441 /* Frequentis PP04 forced to RS-232 until we know better.
2442 * Port C 12 and 13 low enables RS-232 on SCC3 and SCC4.
2444 immap
->im_ioport
.iop_pcdir
|= 0x000c;
2445 immap
->im_ioport
.iop_pcpar
&= ~0x000c;
2446 immap
->im_ioport
.iop_pcdat
&= ~0x000c;
2448 /* This enables the TX driver.
2450 cp
->cp_pbpar
&= ~0x6000;
2451 cp
->cp_pbdat
&= ~0x6000;
2454 for (i
= 0, state
= rs_table
; i
< NR_PORTS
; i
++,state
++) {
2455 state
->magic
= SSTATE_MAGIC
;
2457 state
->type
= PORT_UNKNOWN
;
2458 state
->custom_divisor
= 0;
2459 state
->close_delay
= 5*HZ
/10;
2460 state
->closing_wait
= 30*HZ
;
2461 state
->icount
.cts
= state
->icount
.dsr
=
2462 state
->icount
.rng
= state
->icount
.dcd
= 0;
2463 state
->icount
.rx
= state
->icount
.tx
= 0;
2464 state
->icount
.frame
= state
->icount
.parity
= 0;
2465 state
->icount
.overrun
= state
->icount
.brk
= 0;
2466 printk(KERN_INFO
"ttyS%d at irq 0x%02x is an %s\n",
2467 i
, (unsigned int)(state
->irq
),
2468 (state
->smc_scc_num
& NUM_IS_SCC
) ? "SCC" : "SMC");
2470 #ifdef CONFIG_SERIAL_CONSOLE
2471 /* If we just printed the message on the console port, and
2472 * we are about to initialize it for general use, we have
2473 * to wait a couple of character times for the CR/NL to
2474 * make it out of the transmit buffer.
2476 if (i
== CONFIG_SERIAL_CONSOLE_PORT
)
2480 /* idx = PORT_NUM(info->state->smc_scc_num); */
2481 /* if (info->state->smc_scc_num & NUM_IS_SCC) */
2482 /* chan = scc_chan_map[idx]; */
2484 /* chan = smc_chan_map[idx]; */
2486 /* cp->cp_cr = mk_cr_cmd(chan, CPM_CR_STOP_TX) | CPM_CR_FLG; */
2487 /* while (cp->cp_cr & CPM_CR_FLG); */
2490 /* info = kmalloc(sizeof(ser_info_t), GFP_KERNEL); */
2491 info
= &quicc_ser_info
[i
];
2493 memset (info
, 0, sizeof(ser_info_t
));
2494 info
->magic
= SERIAL_MAGIC
;
2496 info
->flags
= state
->flags
;
2497 INIT_WORK(&info
->tqueue
, do_softint
, info
);
2498 INIT_WORK(&info
->tqueue_hangup
, do_serial_hangup
, info
);
2499 init_waitqueue_head(&info
->open_wait
);
2500 init_waitqueue_head(&info
->close_wait
);
2501 info
->state
= state
;
2502 state
->info
= (struct async_struct
*)info
;
2504 /* We need to allocate a transmit and receive buffer
2505 * descriptors from dual port ram, and a character
2506 * buffer area from host mem.
2508 dp_addr
= m360_cpm_dpalloc(sizeof(QUICC_BD
) * RX_NUM_FIFO
);
2510 /* Allocate space for FIFOs in the host memory.
2511 * (for now this is from a static array of buffers :(
2513 /* mem_addr = m360_cpm_hostalloc(RX_NUM_FIFO * RX_BUF_SIZE); */
2514 /* mem_addr = kmalloc (RX_NUM_FIFO * RX_BUF_SIZE, GFP_BUFFER); */
2515 mem_addr
= &rx_buf_pool
[i
* RX_NUM_FIFO
* RX_BUF_SIZE
];
2517 /* Set the physical address of the host memory
2518 * buffers in the buffer descriptors, and the
2519 * virtual address for us to work with.
2521 bdp
= (QUICC_BD
*)((uint
)pquicc
+ dp_addr
);
2522 info
->rx_cur
= info
->rx_bd_base
= bdp
;
2524 /* initialize rx buffer descriptors */
2525 for (j
=0; j
<(RX_NUM_FIFO
-1); j
++) {
2526 bdp
->buf
= &rx_buf_pool
[(i
* RX_NUM_FIFO
+ j
) * RX_BUF_SIZE
];
2527 bdp
->status
= BD_SC_EMPTY
| BD_SC_INTRPT
;
2528 mem_addr
+= RX_BUF_SIZE
;
2531 bdp
->buf
= &rx_buf_pool
[(i
* RX_NUM_FIFO
+ j
) * RX_BUF_SIZE
];
2532 bdp
->status
= BD_SC_WRAP
| BD_SC_EMPTY
| BD_SC_INTRPT
;
2535 idx
= PORT_NUM(info
->state
->smc_scc_num
);
2536 if (info
->state
->smc_scc_num
& NUM_IS_SCC
) {
2538 #if defined(CONFIG_UCQUICC)
2539 /* set the transceiver mode to RS232 */
2540 sipex_mode_bits
&= ~(uint
)SIPEX_MODE(idx
,0x0f); /* clear current mode */
2541 sipex_mode_bits
|= (uint
)SIPEX_MODE(idx
,0x02);
2542 *(uint
*)_periph_base
= sipex_mode_bits
;
2543 /* printk ("sipex bits = 0x%08x\n", sipex_mode_bits); */
2547 dp_addr
= m360_cpm_dpalloc(sizeof(QUICC_BD
) * TX_NUM_FIFO
);
2549 /* Allocate space for FIFOs in the host memory.
2551 /* mem_addr = m360_cpm_hostalloc(TX_NUM_FIFO * TX_BUF_SIZE); */
2552 /* mem_addr = kmalloc (TX_NUM_FIFO * TX_BUF_SIZE, GFP_BUFFER); */
2553 mem_addr
= &tx_buf_pool
[i
* TX_NUM_FIFO
* TX_BUF_SIZE
];
2555 /* Set the physical address of the host memory
2556 * buffers in the buffer descriptors, and the
2557 * virtual address for us to work with.
2559 /* bdp = (QUICC_BD *)&cp->cp_dpmem[dp_addr]; */
2560 bdp
= (QUICC_BD
*)((uint
)pquicc
+ dp_addr
);
2561 info
->tx_cur
= info
->tx_bd_base
= (QUICC_BD
*)bdp
;
2563 /* initialize tx buffer descriptors */
2564 for (j
=0; j
<(TX_NUM_FIFO
-1); j
++) {
2565 bdp
->buf
= &tx_buf_pool
[(i
* TX_NUM_FIFO
+ j
) * TX_BUF_SIZE
];
2566 bdp
->status
= BD_SC_INTRPT
;
2567 mem_addr
+= TX_BUF_SIZE
;
2570 bdp
->buf
= &tx_buf_pool
[(i
* TX_NUM_FIFO
+ j
) * TX_BUF_SIZE
];
2571 bdp
->status
= (BD_SC_WRAP
| BD_SC_INTRPT
);
2573 if (info
->state
->smc_scc_num
& NUM_IS_SCC
) {
2574 scp
= &pquicc
->scc_regs
[idx
];
2575 sup
= &pquicc
->pram
[info
->state
->port
].scc
.pscc
.u
;
2576 sup
->rbase
= dp_addr
;
2577 sup
->tbase
= dp_addr
;
2579 /* Set up the uart parameters in the
2585 /* Set this to 1 for now, so we get single
2586 * character interrupts. Using idle character
2587 * time requires some additional tuning.
2602 sup
->cc
[i
] = 0x8000;
2606 /* Send the CPM an initialize command.
2608 chan
= scc_chan_map
[idx
];
2610 /* execute the INIT RX & TX PARAMS command for this channel. */
2611 cp
->cp_cr
= mk_cr_cmd(chan
, CPM_CR_INIT_TRX
) | CPM_CR_FLG
;
2612 while (cp
->cp_cr
& CPM_CR_FLG
);
2614 /* Set UART mode, 8 bit, no parity, one stop.
2615 * Enable receive and transmit.
2617 scp
->scc_gsmr
.w
.high
= 0;
2618 scp
->scc_gsmr
.w
.low
=
2619 (SCC_GSMRL_MODE_UART
| SCC_GSMRL_TDCR_16
| SCC_GSMRL_RDCR_16
);
2621 /* Disable all interrupts and clear all pending
2625 scp
->scc_scce
= 0xffff;
2626 scp
->scc_dsr
= 0x7e7e;
2627 scp
->scc_psmr
= 0x3000;
2629 /* If the port is the console, enable Rx and Tx.
2631 #ifdef CONFIG_SERIAL_CONSOLE
2632 if (i
== CONFIG_SERIAL_CONSOLE_PORT
)
2633 scp
->scc_gsmr
.w
.low
|= (SCC_GSMRL_ENR
| SCC_GSMRL_ENT
);
2637 /* Configure SMCs Tx/Rx instead of port B
2640 up
= &pquicc
->pram
[info
->state
->port
].scc
.pothers
.idma_smc
.psmc
.u
;
2641 up
->rbase
= dp_addr
;
2643 iobits
= 0xc0 << (idx
* 4);
2644 cp
->pip_pbpar
|= iobits
;
2645 cp
->pip_pbdir
&= ~iobits
;
2646 cp
->pip_pbodr
&= ~iobits
;
2649 /* Connect the baud rate generator to the
2650 * SMC based upon index in rs_table. Also
2651 * make sure it is connected to NMSI.
2653 cp
->si_simode
&= ~(0xffff << (idx
* 16));
2654 cp
->si_simode
|= (i
<< ((idx
* 16) + 12));
2656 up
->tbase
= dp_addr
;
2658 /* Set up the uart parameters in the
2664 /* Set this to 1 for now, so we get single
2665 * character interrupts. Using idle character
2666 * time requires some additional tuning.
2672 /* Send the CPM an initialize command.
2674 chan
= smc_chan_map
[idx
];
2676 cp
->cp_cr
= mk_cr_cmd(chan
,
2677 CPM_CR_INIT_TRX
) | CPM_CR_FLG
;
2678 #ifdef CONFIG_SERIAL_CONSOLE
2679 if (i
== CONFIG_SERIAL_CONSOLE_PORT
)
2682 while (cp
->cp_cr
& CPM_CR_FLG
);
2684 /* Set UART mode, 8 bit, no parity, one stop.
2685 * Enable receive and transmit.
2687 sp
= &cp
->smc_regs
[idx
];
2688 sp
->smc_smcmr
= smcr_mk_clen(9) | SMCMR_SM_UART
;
2690 /* Disable all interrupts and clear all pending
2694 sp
->smc_smce
= 0xff;
2696 /* If the port is the console, enable Rx and Tx.
2698 #ifdef CONFIG_SERIAL_CONSOLE
2699 if (i
== CONFIG_SERIAL_CONSOLE_PORT
)
2700 sp
->smc_smcmr
|= SMCMR_REN
| SMCMR_TEN
;
2704 /* Install interrupt handler.
2706 /* cpm_install_handler(IRQ_MACHSPEC | state->irq, rs_360_interrupt, info); */
2707 /*request_irq(IRQ_MACHSPEC | state->irq, rs_360_interrupt, */
2708 request_irq(state
->irq
, rs_360_interrupt
,
2709 IRQ_FLG_LOCK
, "ttyS", (void *)info
);
2711 /* Set up the baud rate generator.
2713 m360_cpm_setbrg(i
, baud_table
[baud_idx
]);
2720 module_init(rs_360_init
);
2722 /* This must always be called before the rs_360_init() function, otherwise
2723 * it blows away the port control information.
2725 //static int __init serial_console_setup( struct console *co, char *options)
2726 int serial_console_setup( struct console
*co
, char *options
)
2728 struct serial_state
*ser
;
2729 uint mem_addr
, dp_addr
, bidx
, idx
, iobits
;
2733 volatile struct smc_regs
*sp
;
2734 volatile struct scc_regs
*scp
;
2735 volatile struct smc_uart_pram
*up
;
2736 volatile struct uart_pram
*sup
;
2739 * add something to the 68k bootloader to store a desired initial console baud rate */
2741 /* bd_t *bd; */ /* a board info struct used by EPPC-bug */
2742 /* bd = (bd_t *)__res; */
2744 for (bidx
= 0; bidx
< (sizeof(baud_table
) / sizeof(int)); bidx
++)
2745 /* if (bd->bi_baudrate == baud_table[bidx]) */
2746 if (CONSOLE_BAUDRATE
== baud_table
[bidx
])
2749 /* co->cflag = CREAD|CLOCAL|bidx|CS8; */
2752 ser
= rs_table
+ CONFIG_SERIAL_CONSOLE_PORT
;
2754 cp
= pquicc
; /* Get pointer to Communication Processor */
2756 idx
= PORT_NUM(ser
->smc_scc_num
);
2757 if (ser
->smc_scc_num
& NUM_IS_SCC
) {
2759 /* TODO: need to set up SCC pin assignment etc. here */
2763 iobits
= 0xc0 << (idx
* 4);
2764 cp
->pip_pbpar
|= iobits
;
2765 cp
->pip_pbdir
&= ~iobits
;
2766 cp
->pip_pbodr
&= ~iobits
;
2768 /* Connect the baud rate generator to the
2769 * SMC based upon index in rs_table. Also
2770 * make sure it is connected to NMSI.
2772 cp
->si_simode
&= ~(0xffff << (idx
* 16));
2773 cp
->si_simode
|= (idx
<< ((idx
* 16) + 12));
2776 /* When we get here, the CPM has been reset, so we need
2777 * to configure the port.
2778 * We need to allocate a transmit and receive buffer descriptor
2779 * from dual port ram, and a character buffer area from host mem.
2782 /* Allocate space for two buffer descriptors in the DP ram.
2784 dp_addr
= m360_cpm_dpalloc(sizeof(QUICC_BD
) * CONSOLE_NUM_FIFO
);
2786 /* Allocate space for two 2 byte FIFOs in the host memory.
2788 /* mem_addr = m360_cpm_hostalloc(8); */
2789 mem_addr
= (uint
)console_fifos
;
2792 /* Set the physical address of the host memory buffers in
2793 * the buffer descriptors.
2795 /* bdp = (QUICC_BD *)&cp->cp_dpmem[dp_addr]; */
2796 bdp
= (QUICC_BD
*)((uint
)pquicc
+ dp_addr
);
2797 bdp
->buf
= (char *)mem_addr
;
2798 (bdp
+1)->buf
= (char *)(mem_addr
+4);
2800 /* For the receive, set empty and wrap.
2801 * For transmit, set wrap.
2803 bdp
->status
= BD_SC_EMPTY
| BD_SC_WRAP
;
2804 (bdp
+1)->status
= BD_SC_WRAP
;
2806 /* Set up the uart parameters in the parameter ram.
2808 if (ser
->smc_scc_num
& NUM_IS_SCC
) {
2809 scp
= &cp
->scc_regs
[idx
];
2810 /* sup = (scc_uart_t *)&cp->cp_dparam[ser->port]; */
2811 sup
= &pquicc
->pram
[ser
->port
].scc
.pscc
.u
;
2813 sup
->rbase
= dp_addr
;
2814 sup
->tbase
= dp_addr
+ sizeof(QUICC_BD
);
2816 /* Set up the uart parameters in the
2822 /* Set this to 1 for now, so we get single
2823 * character interrupts. Using idle character
2824 * time requires some additional tuning.
2839 sup
->cc
[i
] = 0x8000;
2843 /* Send the CPM an initialize command.
2845 chan
= scc_chan_map
[idx
];
2847 cp
->cp_cr
= mk_cr_cmd(chan
, CPM_CR_INIT_TRX
) | CPM_CR_FLG
;
2848 while (cp
->cp_cr
& CPM_CR_FLG
);
2850 /* Set UART mode, 8 bit, no parity, one stop.
2851 * Enable receive and transmit.
2853 scp
->scc_gsmr
.w
.high
= 0;
2854 scp
->scc_gsmr
.w
.low
=
2855 (SCC_GSMRL_MODE_UART
| SCC_GSMRL_TDCR_16
| SCC_GSMRL_RDCR_16
);
2857 /* Disable all interrupts and clear all pending
2861 scp
->scc_scce
= 0xffff;
2862 scp
->scc_dsr
= 0x7e7e;
2863 scp
->scc_psmr
= 0x3000;
2865 scp
->scc_gsmr
.w
.low
|= (SCC_GSMRL_ENR
| SCC_GSMRL_ENT
);
2869 /* up = (smc_uart_t *)&cp->cp_dparam[ser->port]; */
2870 up
= &pquicc
->pram
[ser
->port
].scc
.pothers
.idma_smc
.psmc
.u
;
2872 up
->rbase
= dp_addr
; /* Base of receive buffer desc. */
2873 up
->tbase
= dp_addr
+sizeof(QUICC_BD
); /* Base of xmt buffer desc. */
2877 /* Set this to 1 for now, so we get single character interrupts.
2879 up
->mrblr
= 1; /* receive buffer length */
2880 up
->max_idl
= 0; /* wait forever for next char */
2882 /* Send the CPM an initialize command.
2884 chan
= smc_chan_map
[idx
];
2885 cp
->cp_cr
= mk_cr_cmd(chan
, CPM_CR_INIT_TRX
) | CPM_CR_FLG
;
2886 while (cp
->cp_cr
& CPM_CR_FLG
);
2888 /* Set UART mode, 8 bit, no parity, one stop.
2889 * Enable receive and transmit.
2891 sp
= &cp
->smc_regs
[idx
];
2892 sp
->smc_smcmr
= smcr_mk_clen(9) | SMCMR_SM_UART
;
2894 /* And finally, enable Rx and Tx.
2896 sp
->smc_smcmr
|= SMCMR_REN
| SMCMR_TEN
;
2899 /* Set up the baud rate generator.
2901 /* m360_cpm_setbrg((ser - rs_table), bd->bi_baudrate); */
2902 m360_cpm_setbrg((ser
- rs_table
), CONSOLE_BAUDRATE
);