2 * drivers/char/vme_scc.c: MVME147, MVME162, BVME6000 SCC serial ports
4 * Copyright 1999 Richard Hirst <richard@sleepie.demon.co.uk>
6 * Based on atari_SCC.c which was
7 * Copyright 1994-95 Roman Hodek <Roman.Hodek@informatik.uni-erlangen.de>
8 * Partially based on PC-Linux serial.c by Linus Torvalds and Theodore Ts'o
10 * This file is subject to the terms and conditions of the GNU General Public
11 * License. See the file COPYING in the main directory of this archive
16 #include <linux/module.h>
17 #include <linux/kdev_t.h>
19 #include <linux/kernel.h>
20 #include <linux/ioport.h>
21 #include <linux/interrupt.h>
22 #include <linux/errno.h>
23 #include <linux/tty.h>
24 #include <linux/tty_flip.h>
26 #include <linux/serial.h>
27 #include <linux/fcntl.h>
28 #include <linux/major.h>
29 #include <linux/delay.h>
30 #include <linux/slab.h>
31 #include <linux/miscdevice.h>
32 #include <linux/console.h>
33 #include <linux/init.h>
34 #include <asm/setup.h>
35 #include <asm/bootinfo.h>
37 #ifdef CONFIG_MVME147_SCC
38 #include <asm/mvme147hw.h>
40 #ifdef CONFIG_MVME162_SCC
41 #include <asm/mvme16xhw.h>
43 #ifdef CONFIG_BVME6000_SCC
44 #include <asm/bvme6000hw.h>
47 #include <linux/generic_serial.h>
54 #define SCC_MINOR_BASE 64
56 /* Shadows for all SCC write registers */
57 static unsigned char scc_shadow
[2][16];
59 /* Location to access for SCC register access delay */
60 static volatile unsigned char *scc_del
= NULL
;
62 /* To keep track of STATUS_REG state for detection of Ext/Status int source */
63 static unsigned char scc_last_status_reg
[2];
65 /***************************** Prototypes *****************************/
67 /* Function prototypes */
68 static void scc_disable_tx_interrupts(void * ptr
);
69 static void scc_enable_tx_interrupts(void * ptr
);
70 static void scc_disable_rx_interrupts(void * ptr
);
71 static void scc_enable_rx_interrupts(void * ptr
);
72 static int scc_get_CD(void * ptr
);
73 static void scc_shutdown_port(void * ptr
);
74 static int scc_set_real_termios(void *ptr
);
75 static void scc_hungup(void *ptr
);
76 static void scc_close(void *ptr
);
77 static int scc_chars_in_buffer(void * ptr
);
78 static int scc_open(struct tty_struct
* tty
, struct file
* filp
);
79 static int scc_ioctl(struct tty_struct
* tty
, struct file
* filp
,
80 unsigned int cmd
, unsigned long arg
);
81 static void scc_throttle(struct tty_struct
*tty
);
82 static void scc_unthrottle(struct tty_struct
*tty
);
83 static irqreturn_t
scc_tx_int(int irq
, void *data
);
84 static irqreturn_t
scc_rx_int(int irq
, void *data
);
85 static irqreturn_t
scc_stat_int(int irq
, void *data
);
86 static irqreturn_t
scc_spcond_int(int irq
, void *data
);
87 static void scc_setsignals(struct scc_port
*port
, int dtr
, int rts
);
88 static void scc_break_ctl(struct tty_struct
*tty
, int break_state
);
90 static struct tty_driver
*scc_driver
;
92 static struct scc_port scc_ports
[2];
94 /*---------------------------------------------------------------------------
95 * Interface from generic_serial.c back here
96 *--------------------------------------------------------------------------*/
98 static struct real_driver scc_real_driver
= {
99 scc_disable_tx_interrupts
,
100 scc_enable_tx_interrupts
,
101 scc_disable_rx_interrupts
,
102 scc_enable_rx_interrupts
,
105 scc_set_real_termios
,
113 static const struct tty_operations scc_ops
= {
117 .put_char
= gs_put_char
,
118 .flush_chars
= gs_flush_chars
,
119 .write_room
= gs_write_room
,
120 .chars_in_buffer
= gs_chars_in_buffer
,
121 .flush_buffer
= gs_flush_buffer
,
123 .throttle
= scc_throttle
,
124 .unthrottle
= scc_unthrottle
,
125 .set_termios
= gs_set_termios
,
129 .break_ctl
= scc_break_ctl
,
132 /*----------------------------------------------------------------------------
133 * vme_scc_init() and support functions
134 *---------------------------------------------------------------------------*/
136 static int scc_init_drivers(void)
140 scc_driver
= alloc_tty_driver(2);
143 scc_driver
->owner
= THIS_MODULE
;
144 scc_driver
->driver_name
= "scc";
145 scc_driver
->name
= "ttyS";
146 scc_driver
->major
= TTY_MAJOR
;
147 scc_driver
->minor_start
= SCC_MINOR_BASE
;
148 scc_driver
->type
= TTY_DRIVER_TYPE_SERIAL
;
149 scc_driver
->subtype
= SERIAL_TYPE_NORMAL
;
150 scc_driver
->init_termios
= tty_std_termios
;
151 scc_driver
->init_termios
.c_cflag
=
152 B9600
| CS8
| CREAD
| HUPCL
| CLOCAL
;
153 scc_driver
->init_termios
.c_ispeed
= 9600;
154 scc_driver
->init_termios
.c_ospeed
= 9600;
155 scc_driver
->flags
= TTY_DRIVER_REAL_RAW
;
156 tty_set_operations(scc_driver
, &scc_ops
);
158 if ((error
= tty_register_driver(scc_driver
))) {
159 printk(KERN_ERR
"scc: Couldn't register scc driver, error = %d\n",
161 put_tty_driver(scc_driver
);
169 /* ports[] array is indexed by line no (i.e. [0] for ttyS0, [1] for ttyS1).
172 static void scc_init_portstructs(void)
174 struct scc_port
*port
;
177 for (i
= 0; i
< 2; i
++) {
178 port
= scc_ports
+ i
;
179 port
->gs
.magic
= SCC_MAGIC
;
180 port
->gs
.close_delay
= HZ
/2;
181 port
->gs
.closing_wait
= 30 * HZ
;
182 port
->gs
.rd
= &scc_real_driver
;
183 #ifdef NEW_WRITE_LOCKING
184 port
->gs
.port_write_mutex
= MUTEX
;
186 init_waitqueue_head(&port
->gs
.open_wait
);
187 init_waitqueue_head(&port
->gs
.close_wait
);
192 #ifdef CONFIG_MVME147_SCC
193 static int mvme147_scc_init(void)
195 struct scc_port
*port
;
197 printk(KERN_INFO
"SCC: MVME147 Serial Driver\n");
199 port
= &scc_ports
[0];
200 port
->channel
= CHANNEL_A
;
201 port
->ctrlp
= (volatile unsigned char *)M147_SCC_A_ADDR
;
202 port
->datap
= port
->ctrlp
+ 1;
203 port
->port_a
= &scc_ports
[0];
204 port
->port_b
= &scc_ports
[1];
205 request_irq(MVME147_IRQ_SCCA_TX
, scc_tx_int
, IRQF_DISABLED
,
207 request_irq(MVME147_IRQ_SCCA_STAT
, scc_stat_int
, IRQF_DISABLED
,
208 "SCC-A status", port
);
209 request_irq(MVME147_IRQ_SCCA_RX
, scc_rx_int
, IRQF_DISABLED
,
211 request_irq(MVME147_IRQ_SCCA_SPCOND
, scc_spcond_int
, IRQF_DISABLED
,
212 "SCC-A special cond", port
);
214 SCC_ACCESS_INIT(port
);
216 /* disable interrupts for this channel */
217 SCCwrite(INT_AND_DMA_REG
, 0);
218 /* Set the interrupt vector */
219 SCCwrite(INT_VECTOR_REG
, MVME147_IRQ_SCC_BASE
);
220 /* Interrupt parameters: vector includes status, status low */
221 SCCwrite(MASTER_INT_CTRL
, MIC_VEC_INCL_STAT
);
222 SCCmod(MASTER_INT_CTRL
, 0xff, MIC_MASTER_INT_ENAB
);
226 port
= &scc_ports
[1];
227 port
->channel
= CHANNEL_B
;
228 port
->ctrlp
= (volatile unsigned char *)M147_SCC_B_ADDR
;
229 port
->datap
= port
->ctrlp
+ 1;
230 port
->port_a
= &scc_ports
[0];
231 port
->port_b
= &scc_ports
[1];
232 request_irq(MVME147_IRQ_SCCB_TX
, scc_tx_int
, IRQF_DISABLED
,
234 request_irq(MVME147_IRQ_SCCB_STAT
, scc_stat_int
, IRQF_DISABLED
,
235 "SCC-B status", port
);
236 request_irq(MVME147_IRQ_SCCB_RX
, scc_rx_int
, IRQF_DISABLED
,
238 request_irq(MVME147_IRQ_SCCB_SPCOND
, scc_spcond_int
, IRQF_DISABLED
,
239 "SCC-B special cond", port
);
241 SCC_ACCESS_INIT(port
);
243 /* disable interrupts for this channel */
244 SCCwrite(INT_AND_DMA_REG
, 0);
247 /* Ensure interrupts are enabled in the PCC chip */
248 m147_pcc
->serial_cntrl
=PCC_LEVEL_SERIAL
|PCC_INT_ENAB
;
250 /* Initialise the tty driver structures and register */
251 scc_init_portstructs();
259 #ifdef CONFIG_MVME162_SCC
260 static int mvme162_scc_init(void)
262 struct scc_port
*port
;
264 if (!(mvme16x_config
& MVME16x_CONFIG_GOT_SCCA
))
267 printk(KERN_INFO
"SCC: MVME162 Serial Driver\n");
269 port
= &scc_ports
[0];
270 port
->channel
= CHANNEL_A
;
271 port
->ctrlp
= (volatile unsigned char *)MVME_SCC_A_ADDR
;
272 port
->datap
= port
->ctrlp
+ 2;
273 port
->port_a
= &scc_ports
[0];
274 port
->port_b
= &scc_ports
[1];
275 request_irq(MVME162_IRQ_SCCA_TX
, scc_tx_int
, IRQF_DISABLED
,
277 request_irq(MVME162_IRQ_SCCA_STAT
, scc_stat_int
, IRQF_DISABLED
,
278 "SCC-A status", port
);
279 request_irq(MVME162_IRQ_SCCA_RX
, scc_rx_int
, IRQF_DISABLED
,
281 request_irq(MVME162_IRQ_SCCA_SPCOND
, scc_spcond_int
, IRQF_DISABLED
,
282 "SCC-A special cond", port
);
284 SCC_ACCESS_INIT(port
);
286 /* disable interrupts for this channel */
287 SCCwrite(INT_AND_DMA_REG
, 0);
288 /* Set the interrupt vector */
289 SCCwrite(INT_VECTOR_REG
, MVME162_IRQ_SCC_BASE
);
290 /* Interrupt parameters: vector includes status, status low */
291 SCCwrite(MASTER_INT_CTRL
, MIC_VEC_INCL_STAT
);
292 SCCmod(MASTER_INT_CTRL
, 0xff, MIC_MASTER_INT_ENAB
);
296 port
= &scc_ports
[1];
297 port
->channel
= CHANNEL_B
;
298 port
->ctrlp
= (volatile unsigned char *)MVME_SCC_B_ADDR
;
299 port
->datap
= port
->ctrlp
+ 2;
300 port
->port_a
= &scc_ports
[0];
301 port
->port_b
= &scc_ports
[1];
302 request_irq(MVME162_IRQ_SCCB_TX
, scc_tx_int
, IRQF_DISABLED
,
304 request_irq(MVME162_IRQ_SCCB_STAT
, scc_stat_int
, IRQF_DISABLED
,
305 "SCC-B status", port
);
306 request_irq(MVME162_IRQ_SCCB_RX
, scc_rx_int
, IRQF_DISABLED
,
308 request_irq(MVME162_IRQ_SCCB_SPCOND
, scc_spcond_int
, IRQF_DISABLED
,
309 "SCC-B special cond", port
);
312 SCC_ACCESS_INIT(port
); /* Either channel will do */
314 /* disable interrupts for this channel */
315 SCCwrite(INT_AND_DMA_REG
, 0);
318 /* Ensure interrupts are enabled in the MC2 chip */
319 *(volatile char *)0xfff4201d = 0x14;
321 /* Initialise the tty driver structures and register */
322 scc_init_portstructs();
330 #ifdef CONFIG_BVME6000_SCC
331 static int bvme6000_scc_init(void)
333 struct scc_port
*port
;
335 printk(KERN_INFO
"SCC: BVME6000 Serial Driver\n");
337 port
= &scc_ports
[0];
338 port
->channel
= CHANNEL_A
;
339 port
->ctrlp
= (volatile unsigned char *)BVME_SCC_A_ADDR
;
340 port
->datap
= port
->ctrlp
+ 4;
341 port
->port_a
= &scc_ports
[0];
342 port
->port_b
= &scc_ports
[1];
343 request_irq(BVME_IRQ_SCCA_TX
, scc_tx_int
, IRQF_DISABLED
,
345 request_irq(BVME_IRQ_SCCA_STAT
, scc_stat_int
, IRQF_DISABLED
,
346 "SCC-A status", port
);
347 request_irq(BVME_IRQ_SCCA_RX
, scc_rx_int
, IRQF_DISABLED
,
349 request_irq(BVME_IRQ_SCCA_SPCOND
, scc_spcond_int
, IRQF_DISABLED
,
350 "SCC-A special cond", port
);
352 SCC_ACCESS_INIT(port
);
354 /* disable interrupts for this channel */
355 SCCwrite(INT_AND_DMA_REG
, 0);
356 /* Set the interrupt vector */
357 SCCwrite(INT_VECTOR_REG
, BVME_IRQ_SCC_BASE
);
358 /* Interrupt parameters: vector includes status, status low */
359 SCCwrite(MASTER_INT_CTRL
, MIC_VEC_INCL_STAT
);
360 SCCmod(MASTER_INT_CTRL
, 0xff, MIC_MASTER_INT_ENAB
);
364 port
= &scc_ports
[1];
365 port
->channel
= CHANNEL_B
;
366 port
->ctrlp
= (volatile unsigned char *)BVME_SCC_B_ADDR
;
367 port
->datap
= port
->ctrlp
+ 4;
368 port
->port_a
= &scc_ports
[0];
369 port
->port_b
= &scc_ports
[1];
370 request_irq(BVME_IRQ_SCCB_TX
, scc_tx_int
, IRQF_DISABLED
,
372 request_irq(BVME_IRQ_SCCB_STAT
, scc_stat_int
, IRQF_DISABLED
,
373 "SCC-B status", port
);
374 request_irq(BVME_IRQ_SCCB_RX
, scc_rx_int
, IRQF_DISABLED
,
376 request_irq(BVME_IRQ_SCCB_SPCOND
, scc_spcond_int
, IRQF_DISABLED
,
377 "SCC-B special cond", port
);
380 SCC_ACCESS_INIT(port
); /* Either channel will do */
382 /* disable interrupts for this channel */
383 SCCwrite(INT_AND_DMA_REG
, 0);
386 /* Initialise the tty driver structures and register */
387 scc_init_portstructs();
395 static int vme_scc_init(void)
399 #ifdef CONFIG_MVME147_SCC
401 res
= mvme147_scc_init();
403 #ifdef CONFIG_MVME162_SCC
405 res
= mvme162_scc_init();
407 #ifdef CONFIG_BVME6000_SCC
408 if (MACH_IS_BVME6000
)
409 res
= bvme6000_scc_init();
414 module_init(vme_scc_init
);
417 /*---------------------------------------------------------------------------
419 *--------------------------------------------------------------------------*/
421 static irqreturn_t
scc_rx_int(int irq
, void *data
)
424 struct scc_port
*port
= data
;
425 struct tty_struct
*tty
= port
->gs
.tty
;
426 SCC_ACCESS_INIT(port
);
428 ch
= SCCread_NB(RX_DATA_REG
);
430 printk(KERN_WARNING
"scc_rx_int with NULL tty!\n");
431 SCCwrite_NB(COMMAND_REG
, CR_HIGHEST_IUS_RESET
);
434 tty_insert_flip_char(tty
, ch
, 0);
436 /* Check if another character is already ready; in that case, the
437 * spcond_int() function must be used, because this character may have an
438 * error condition that isn't signalled by the interrupt vector used!
440 if (SCCread(INT_PENDING_REG
) &
441 (port
->channel
== CHANNEL_A
? IPR_A_RX
: IPR_B_RX
)) {
442 scc_spcond_int (irq
, data
);
446 SCCwrite_NB(COMMAND_REG
, CR_HIGHEST_IUS_RESET
);
448 tty_flip_buffer_push(tty
);
453 static irqreturn_t
scc_spcond_int(int irq
, void *data
)
455 struct scc_port
*port
= data
;
456 struct tty_struct
*tty
= port
->gs
.tty
;
457 unsigned char stat
, ch
, err
;
458 int int_pending_mask
= port
->channel
== CHANNEL_A
?
460 SCC_ACCESS_INIT(port
);
463 printk(KERN_WARNING
"scc_spcond_int with NULL tty!\n");
464 SCCwrite(COMMAND_REG
, CR_ERROR_RESET
);
465 SCCwrite_NB(COMMAND_REG
, CR_HIGHEST_IUS_RESET
);
469 stat
= SCCread(SPCOND_STATUS_REG
);
470 ch
= SCCread_NB(RX_DATA_REG
);
472 if (stat
& SCSR_RX_OVERRUN
)
474 else if (stat
& SCSR_PARITY_ERR
)
476 else if (stat
& SCSR_CRC_FRAME_ERR
)
481 tty_insert_flip_char(tty
, ch
, err
);
483 /* ++TeSche: *All* errors have to be cleared manually,
484 * else the condition persists for the next chars
487 SCCwrite(COMMAND_REG
, CR_ERROR_RESET
);
489 } while(SCCread(INT_PENDING_REG
) & int_pending_mask
);
491 SCCwrite_NB(COMMAND_REG
, CR_HIGHEST_IUS_RESET
);
493 tty_flip_buffer_push(tty
);
498 static irqreturn_t
scc_tx_int(int irq
, void *data
)
500 struct scc_port
*port
= data
;
501 SCC_ACCESS_INIT(port
);
504 printk(KERN_WARNING
"scc_tx_int with NULL tty!\n");
505 SCCmod (INT_AND_DMA_REG
, ~IDR_TX_INT_ENAB
, 0);
506 SCCwrite(COMMAND_REG
, CR_TX_PENDING_RESET
);
507 SCCwrite_NB(COMMAND_REG
, CR_HIGHEST_IUS_RESET
);
510 while ((SCCread_NB(STATUS_REG
) & SR_TX_BUF_EMPTY
)) {
512 SCCwrite(TX_DATA_REG
, port
->x_char
);
515 else if ((port
->gs
.xmit_cnt
<= 0) || port
->gs
.tty
->stopped
||
516 port
->gs
.tty
->hw_stopped
)
519 SCCwrite(TX_DATA_REG
, port
->gs
.xmit_buf
[port
->gs
.xmit_tail
++]);
520 port
->gs
.xmit_tail
= port
->gs
.xmit_tail
& (SERIAL_XMIT_SIZE
-1);
521 if (--port
->gs
.xmit_cnt
<= 0)
525 if ((port
->gs
.xmit_cnt
<= 0) || port
->gs
.tty
->stopped
||
526 port
->gs
.tty
->hw_stopped
) {
527 /* disable tx interrupts */
528 SCCmod (INT_AND_DMA_REG
, ~IDR_TX_INT_ENAB
, 0);
529 SCCwrite(COMMAND_REG
, CR_TX_PENDING_RESET
); /* disable tx_int on next tx underrun? */
530 port
->gs
.flags
&= ~GS_TX_INTEN
;
532 if (port
->gs
.tty
&& port
->gs
.xmit_cnt
<= port
->gs
.wakeup_chars
)
533 tty_wakeup(port
->gs
.tty
);
535 SCCwrite_NB(COMMAND_REG
, CR_HIGHEST_IUS_RESET
);
540 static irqreturn_t
scc_stat_int(int irq
, void *data
)
542 struct scc_port
*port
= data
;
543 unsigned channel
= port
->channel
;
544 unsigned char last_sr
, sr
, changed
;
545 SCC_ACCESS_INIT(port
);
547 last_sr
= scc_last_status_reg
[channel
];
548 sr
= scc_last_status_reg
[channel
] = SCCread_NB(STATUS_REG
);
549 changed
= last_sr
^ sr
;
551 if (changed
& SR_DCD
) {
552 port
->c_dcd
= !!(sr
& SR_DCD
);
553 if (!(port
->gs
.flags
& ASYNC_CHECK_CD
))
554 ; /* Don't report DCD changes */
555 else if (port
->c_dcd
) {
556 wake_up_interruptible(&port
->gs
.open_wait
);
560 tty_hangup (port
->gs
.tty
);
563 SCCwrite(COMMAND_REG
, CR_EXTSTAT_RESET
);
564 SCCwrite_NB(COMMAND_REG
, CR_HIGHEST_IUS_RESET
);
569 /*---------------------------------------------------------------------------
570 * generic_serial.c callback funtions
571 *--------------------------------------------------------------------------*/
573 static void scc_disable_tx_interrupts(void *ptr
)
575 struct scc_port
*port
= ptr
;
577 SCC_ACCESS_INIT(port
);
579 local_irq_save(flags
);
580 SCCmod(INT_AND_DMA_REG
, ~IDR_TX_INT_ENAB
, 0);
581 port
->gs
.flags
&= ~GS_TX_INTEN
;
582 local_irq_restore(flags
);
586 static void scc_enable_tx_interrupts(void *ptr
)
588 struct scc_port
*port
= ptr
;
590 SCC_ACCESS_INIT(port
);
592 local_irq_save(flags
);
593 SCCmod(INT_AND_DMA_REG
, 0xff, IDR_TX_INT_ENAB
);
594 /* restart the transmitter */
595 scc_tx_int (0, port
);
596 local_irq_restore(flags
);
600 static void scc_disable_rx_interrupts(void *ptr
)
602 struct scc_port
*port
= ptr
;
604 SCC_ACCESS_INIT(port
);
606 local_irq_save(flags
);
607 SCCmod(INT_AND_DMA_REG
,
608 ~(IDR_RX_INT_MASK
|IDR_PARERR_AS_SPCOND
|IDR_EXTSTAT_INT_ENAB
), 0);
609 local_irq_restore(flags
);
613 static void scc_enable_rx_interrupts(void *ptr
)
615 struct scc_port
*port
= ptr
;
617 SCC_ACCESS_INIT(port
);
619 local_irq_save(flags
);
620 SCCmod(INT_AND_DMA_REG
, 0xff,
621 IDR_EXTSTAT_INT_ENAB
|IDR_PARERR_AS_SPCOND
|IDR_RX_INT_ALL
);
622 local_irq_restore(flags
);
626 static int scc_get_CD(void *ptr
)
628 struct scc_port
*port
= ptr
;
629 unsigned channel
= port
->channel
;
631 return !!(scc_last_status_reg
[channel
] & SR_DCD
);
635 static void scc_shutdown_port(void *ptr
)
637 struct scc_port
*port
= ptr
;
639 port
->gs
.flags
&= ~ GS_ACTIVE
;
640 if (port
->gs
.tty
&& port
->gs
.tty
->termios
->c_cflag
& HUPCL
) {
641 scc_setsignals (port
, 0, 0);
646 static int scc_set_real_termios (void *ptr
)
648 /* the SCC has char sizes 5,7,6,8 in that order! */
649 static int chsize_map
[4] = { 0, 2, 1, 3 };
650 unsigned cflag
, baud
, chsize
, channel
, brgval
= 0;
652 struct scc_port
*port
= ptr
;
653 SCC_ACCESS_INIT(port
);
655 if (!port
->gs
.tty
|| !port
->gs
.tty
->termios
) return 0;
657 channel
= port
->channel
;
659 if (channel
== CHANNEL_A
)
660 return 0; /* Settings controlled by boot PROM */
662 cflag
= port
->gs
.tty
->termios
->c_cflag
;
663 baud
= port
->gs
.baud
;
664 chsize
= (cflag
& CSIZE
) >> 4;
667 /* speed == 0 -> drop DTR */
668 local_irq_save(flags
);
669 SCCmod(TX_CTRL_REG
, ~TCR_DTR
, 0);
670 local_irq_restore(flags
);
673 else if ((MACH_IS_MVME16x
&& (baud
< 50 || baud
> 38400)) ||
674 (MACH_IS_MVME147
&& (baud
< 50 || baud
> 19200)) ||
675 (MACH_IS_BVME6000
&&(baud
< 50 || baud
> 76800))) {
676 printk(KERN_NOTICE
"SCC: Bad speed requested, %d\n", baud
);
681 port
->gs
.flags
&= ~ASYNC_CHECK_CD
;
683 port
->gs
.flags
|= ASYNC_CHECK_CD
;
685 #ifdef CONFIG_MVME147_SCC
687 brgval
= (M147_SCC_PCLK
+ baud
/2) / (16 * 2 * baud
) - 2;
689 #ifdef CONFIG_MVME162_SCC
691 brgval
= (MVME_SCC_PCLK
+ baud
/2) / (16 * 2 * baud
) - 2;
693 #ifdef CONFIG_BVME6000_SCC
694 if (MACH_IS_BVME6000
)
695 brgval
= (BVME_SCC_RTxC
+ baud
/2) / (16 * 2 * baud
) - 2;
697 /* Now we have all parameters and can go to set them: */
698 local_irq_save(flags
);
700 /* receiver's character size and auto-enables */
701 SCCmod(RX_CTRL_REG
, ~(RCR_CHSIZE_MASK
|RCR_AUTO_ENAB_MODE
),
702 (chsize_map
[chsize
] << 6) |
703 ((cflag
& CRTSCTS
) ? RCR_AUTO_ENAB_MODE
: 0));
704 /* parity and stop bits (both, Tx and Rx), clock mode never changes */
705 SCCmod (AUX1_CTRL_REG
,
706 ~(A1CR_PARITY_MASK
| A1CR_MODE_MASK
),
708 ? (cflag
& PARODD
? A1CR_PARITY_ODD
: A1CR_PARITY_EVEN
)
710 | (cflag
& CSTOPB
? A1CR_MODE_ASYNC_2
: A1CR_MODE_ASYNC_1
)));
711 /* sender's character size, set DTR for valid baud rate */
712 SCCmod(TX_CTRL_REG
, ~TCR_CHSIZE_MASK
, chsize_map
[chsize
] << 5 | TCR_DTR
);
713 /* clock sources never change */
714 /* disable BRG before changing the value */
715 SCCmod(DPLL_CTRL_REG
, ~DCR_BRG_ENAB
, 0);
717 SCCwrite(TIMER_LOW_REG
, brgval
& 0xff);
718 SCCwrite(TIMER_HIGH_REG
, (brgval
>> 8) & 0xff);
719 /* BRG enable, and clock source never changes */
720 SCCmod(DPLL_CTRL_REG
, 0xff, DCR_BRG_ENAB
);
722 local_irq_restore(flags
);
728 static int scc_chars_in_buffer (void *ptr
)
730 struct scc_port
*port
= ptr
;
731 SCC_ACCESS_INIT(port
);
733 return (SCCread (SPCOND_STATUS_REG
) & SCSR_ALL_SENT
) ? 0 : 1;
737 /* Comment taken from sx.c (2.4.0):
738 I haven't the foggiest why the decrement use count has to happen
739 here. The whole linux serial drivers stuff needs to be redesigned.
740 My guess is that this is a hack to minimize the impact of a bug
741 elsewhere. Thinking about it some more. (try it sometime) Try
742 running minicom on a serial port that is driven by a modularized
743 driver. Have the modem hangup. Then remove the driver module. Then
744 exit minicom. I expect an "oops". -- REW */
746 static void scc_hungup(void *ptr
)
748 scc_disable_tx_interrupts(ptr
);
749 scc_disable_rx_interrupts(ptr
);
753 static void scc_close(void *ptr
)
755 scc_disable_tx_interrupts(ptr
);
756 scc_disable_rx_interrupts(ptr
);
760 /*---------------------------------------------------------------------------
761 * Internal support functions
762 *--------------------------------------------------------------------------*/
764 static void scc_setsignals(struct scc_port
*port
, int dtr
, int rts
)
768 SCC_ACCESS_INIT(port
);
770 local_irq_save(flags
);
771 t
= SCCread(TX_CTRL_REG
);
772 if (dtr
>= 0) t
= dtr
? (t
| TCR_DTR
): (t
& ~TCR_DTR
);
773 if (rts
>= 0) t
= rts
? (t
| TCR_RTS
): (t
& ~TCR_RTS
);
774 SCCwrite(TX_CTRL_REG
, t
);
775 local_irq_restore(flags
);
779 static void scc_send_xchar(struct tty_struct
*tty
, char ch
)
781 struct scc_port
*port
= (struct scc_port
*)tty
->driver_data
;
785 scc_enable_tx_interrupts(port
);
789 /*---------------------------------------------------------------------------
790 * Driver entrypoints referenced from above
791 *--------------------------------------------------------------------------*/
793 static int scc_open (struct tty_struct
* tty
, struct file
* filp
)
795 int line
= tty
->index
;
797 struct scc_port
*port
= &scc_ports
[line
];
798 int i
, channel
= port
->channel
;
800 SCC_ACCESS_INIT(port
);
801 #if defined(CONFIG_MVME162_SCC) || defined(CONFIG_MVME147_SCC)
802 static const struct {
804 } mvme_init_tab
[] = {
805 /* Values for MVME162 and MVME147 */
806 /* no parity, 1 stop bit, async, 1:16 */
807 { AUX1_CTRL_REG
, A1CR_PARITY_NONE
|A1CR_MODE_ASYNC_1
|A1CR_CLKMODE_x16
},
808 /* parity error is special cond, ints disabled, no DMA */
809 { INT_AND_DMA_REG
, IDR_PARERR_AS_SPCOND
| IDR_RX_INT_DISAB
},
810 /* Rx 8 bits/char, no auto enable, Rx off */
811 { RX_CTRL_REG
, RCR_CHSIZE_8
},
812 /* DTR off, Tx 8 bits/char, RTS off, Tx off */
813 { TX_CTRL_REG
, TCR_CHSIZE_8
},
814 /* special features off */
815 { AUX2_CTRL_REG
, 0 },
816 { CLK_CTRL_REG
, CCR_RXCLK_BRG
| CCR_TXCLK_BRG
},
817 { DPLL_CTRL_REG
, DCR_BRG_ENAB
| DCR_BRG_USE_PCLK
},
819 { RX_CTRL_REG
, RCR_RX_ENAB
| RCR_CHSIZE_8
},
821 { TX_CTRL_REG
, TCR_TX_ENAB
| TCR_RTS
| TCR_DTR
| TCR_CHSIZE_8
},
822 /* Ext/Stat ints: DCD only */
823 { INT_CTRL_REG
, ICR_ENAB_DCD_INT
},
824 /* Reset Ext/Stat ints */
825 { COMMAND_REG
, CR_EXTSTAT_RESET
},
827 { COMMAND_REG
, CR_EXTSTAT_RESET
},
830 #if defined(CONFIG_BVME6000_SCC)
831 static const struct {
833 } bvme_init_tab
[] = {
834 /* Values for BVME6000 */
835 /* no parity, 1 stop bit, async, 1:16 */
836 { AUX1_CTRL_REG
, A1CR_PARITY_NONE
|A1CR_MODE_ASYNC_1
|A1CR_CLKMODE_x16
},
837 /* parity error is special cond, ints disabled, no DMA */
838 { INT_AND_DMA_REG
, IDR_PARERR_AS_SPCOND
| IDR_RX_INT_DISAB
},
839 /* Rx 8 bits/char, no auto enable, Rx off */
840 { RX_CTRL_REG
, RCR_CHSIZE_8
},
841 /* DTR off, Tx 8 bits/char, RTS off, Tx off */
842 { TX_CTRL_REG
, TCR_CHSIZE_8
},
843 /* special features off */
844 { AUX2_CTRL_REG
, 0 },
845 { CLK_CTRL_REG
, CCR_RTxC_XTAL
| CCR_RXCLK_BRG
| CCR_TXCLK_BRG
},
846 { DPLL_CTRL_REG
, DCR_BRG_ENAB
},
848 { RX_CTRL_REG
, RCR_RX_ENAB
| RCR_CHSIZE_8
},
850 { TX_CTRL_REG
, TCR_TX_ENAB
| TCR_RTS
| TCR_DTR
| TCR_CHSIZE_8
},
851 /* Ext/Stat ints: DCD only */
852 { INT_CTRL_REG
, ICR_ENAB_DCD_INT
},
853 /* Reset Ext/Stat ints */
854 { COMMAND_REG
, CR_EXTSTAT_RESET
},
856 { COMMAND_REG
, CR_EXTSTAT_RESET
},
859 if (!(port
->gs
.flags
& ASYNC_INITIALIZED
)) {
860 local_irq_save(flags
);
861 #if defined(CONFIG_MVME147_SCC) || defined(CONFIG_MVME162_SCC)
862 if (MACH_IS_MVME147
|| MACH_IS_MVME16x
) {
863 for (i
= 0; i
< ARRAY_SIZE(mvme_init_tab
); ++i
)
864 SCCwrite(mvme_init_tab
[i
].reg
, mvme_init_tab
[i
].val
);
867 #if defined(CONFIG_BVME6000_SCC)
868 if (MACH_IS_BVME6000
) {
869 for (i
= 0; i
< ARRAY_SIZE(bvme_init_tab
); ++i
)
870 SCCwrite(bvme_init_tab
[i
].reg
, bvme_init_tab
[i
].val
);
874 /* remember status register for detection of DCD and CTS changes */
875 scc_last_status_reg
[channel
] = SCCread(STATUS_REG
);
877 port
->c_dcd
= 0; /* Prevent initial 1->0 interrupt */
878 scc_setsignals (port
, 1,1);
879 local_irq_restore(flags
);
882 tty
->driver_data
= port
;
885 retval
= gs_init_port(&port
->gs
);
890 port
->gs
.flags
|= GS_ACTIVE
;
891 retval
= gs_block_til_ready(port
, filp
);
898 port
->c_dcd
= scc_get_CD (port
);
900 scc_enable_rx_interrupts(port
);
906 static void scc_throttle (struct tty_struct
* tty
)
908 struct scc_port
*port
= (struct scc_port
*)tty
->driver_data
;
910 SCC_ACCESS_INIT(port
);
912 if (tty
->termios
->c_cflag
& CRTSCTS
) {
913 local_irq_save(flags
);
914 SCCmod(TX_CTRL_REG
, ~TCR_RTS
, 0);
915 local_irq_restore(flags
);
918 scc_send_xchar(tty
, STOP_CHAR(tty
));
922 static void scc_unthrottle (struct tty_struct
* tty
)
924 struct scc_port
*port
= (struct scc_port
*)tty
->driver_data
;
926 SCC_ACCESS_INIT(port
);
928 if (tty
->termios
->c_cflag
& CRTSCTS
) {
929 local_irq_save(flags
);
930 SCCmod(TX_CTRL_REG
, 0xff, TCR_RTS
);
931 local_irq_restore(flags
);
934 scc_send_xchar(tty
, START_CHAR(tty
));
938 static int scc_ioctl(struct tty_struct
*tty
, struct file
*file
,
939 unsigned int cmd
, unsigned long arg
)
945 static void scc_break_ctl(struct tty_struct
*tty
, int break_state
)
947 struct scc_port
*port
= (struct scc_port
*)tty
->driver_data
;
949 SCC_ACCESS_INIT(port
);
951 local_irq_save(flags
);
952 SCCmod(TX_CTRL_REG
, ~TCR_SEND_BREAK
,
953 break_state
? TCR_SEND_BREAK
: 0);
954 local_irq_restore(flags
);
958 /*---------------------------------------------------------------------------
959 * Serial console stuff...
960 *--------------------------------------------------------------------------*/
962 #define scc_delay() do { __asm__ __volatile__ (" nop; nop"); } while (0)
964 static void scc_ch_write (char ch
)
966 volatile char *p
= NULL
;
968 #ifdef CONFIG_MVME147_SCC
970 p
= (volatile char *)M147_SCC_A_ADDR
;
972 #ifdef CONFIG_MVME162_SCC
974 p
= (volatile char *)MVME_SCC_A_ADDR
;
976 #ifdef CONFIG_BVME6000_SCC
977 if (MACH_IS_BVME6000
)
978 p
= (volatile char *)BVME_SCC_A_ADDR
;
991 /* The console must be locked when we get here. */
993 static void scc_console_write (struct console
*co
, const char *str
, unsigned count
)
997 local_irq_save(flags
);
1002 scc_ch_write ('\r');
1003 scc_ch_write (*str
++);
1005 local_irq_restore(flags
);
1008 static struct tty_driver
*scc_console_device(struct console
*c
, int *index
)
1014 static struct console sercons
= {
1016 .write
= scc_console_write
,
1017 .device
= scc_console_device
,
1018 .flags
= CON_PRINTBUFFER
,
1023 static int __init
vme_scc_console_init(void)
1025 if (vme_brdtype
== VME_TYPE_MVME147
||
1026 vme_brdtype
== VME_TYPE_MVME162
||
1027 vme_brdtype
== VME_TYPE_MVME172
||
1028 vme_brdtype
== VME_TYPE_BVME4000
||
1029 vme_brdtype
== VME_TYPE_BVME6000
)
1030 register_console(&sercons
);
1033 console_initcall(vme_scc_console_init
);