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/config.h>
18 #include <linux/kdev_t.h>
20 #include <linux/kernel.h>
21 #include <linux/sched.h>
22 #include <linux/ioport.h>
23 #include <linux/interrupt.h>
24 #include <linux/errno.h>
25 #include <linux/tty.h>
26 #include <linux/tty_flip.h>
28 #include <linux/serial.h>
29 #include <linux/fcntl.h>
30 #include <linux/major.h>
31 #include <linux/delay.h>
32 #include <linux/version.h>
33 #include <linux/slab.h>
34 #include <linux/miscdevice.h>
35 #include <linux/console.h>
36 #include <linux/init.h>
37 #include <asm/setup.h>
38 #include <asm/bootinfo.h>
40 #ifdef CONFIG_MVME147_SCC
41 #include <asm/mvme147hw.h>
43 #ifdef CONFIG_MVME162_SCC
44 #include <asm/mvme16xhw.h>
46 #ifdef CONFIG_BVME6000_SCC
47 #include <asm/bvme6000hw.h>
50 #include <linux/generic_serial.h>
57 #define SCC_MINOR_BASE 64
59 /* Shadows for all SCC write registers */
60 static unsigned char scc_shadow
[2][16];
62 /* Location to access for SCC register access delay */
63 static volatile unsigned char *scc_del
= NULL
;
65 /* To keep track of STATUS_REG state for detection of Ext/Status int source */
66 static unsigned char scc_last_status_reg
[2];
68 /***************************** Prototypes *****************************/
70 /* Function prototypes */
71 static void scc_disable_tx_interrupts(void * ptr
);
72 static void scc_enable_tx_interrupts(void * ptr
);
73 static void scc_disable_rx_interrupts(void * ptr
);
74 static void scc_enable_rx_interrupts(void * ptr
);
75 static int scc_get_CD(void * ptr
);
76 static void scc_shutdown_port(void * ptr
);
77 static int scc_set_real_termios(void *ptr
);
78 static void scc_hungup(void *ptr
);
79 static void scc_close(void *ptr
);
80 static int scc_chars_in_buffer(void * ptr
);
81 static int scc_open(struct tty_struct
* tty
, struct file
* filp
);
82 static int scc_ioctl(struct tty_struct
* tty
, struct file
* filp
,
83 unsigned int cmd
, unsigned long arg
);
84 static void scc_throttle(struct tty_struct
*tty
);
85 static void scc_unthrottle(struct tty_struct
*tty
);
86 static irqreturn_t
scc_tx_int(int irq
, void *data
, struct pt_regs
*fp
);
87 static irqreturn_t
scc_rx_int(int irq
, void *data
, struct pt_regs
*fp
);
88 static irqreturn_t
scc_stat_int(int irq
, void *data
, struct pt_regs
*fp
);
89 static irqreturn_t
scc_spcond_int(int irq
, void *data
, struct pt_regs
*fp
);
90 static void scc_setsignals(struct scc_port
*port
, int dtr
, int rts
);
91 static void scc_break_ctl(struct tty_struct
*tty
, int break_state
);
93 static struct tty_driver
*scc_driver
;
95 struct scc_port scc_ports
[2];
97 int scc_initialized
= 0;
99 /*---------------------------------------------------------------------------
100 * Interface from generic_serial.c back here
101 *--------------------------------------------------------------------------*/
103 static struct real_driver scc_real_driver
= {
104 scc_disable_tx_interrupts
,
105 scc_enable_tx_interrupts
,
106 scc_disable_rx_interrupts
,
107 scc_enable_rx_interrupts
,
110 scc_set_real_termios
,
118 static struct tty_operations scc_ops
= {
122 .put_char
= gs_put_char
,
123 .flush_chars
= gs_flush_chars
,
124 .write_room
= gs_write_room
,
125 .chars_in_buffer
= gs_chars_in_buffer
,
126 .flush_buffer
= gs_flush_buffer
,
128 .throttle
= scc_throttle
,
129 .unthrottle
= scc_unthrottle
,
130 .set_termios
= gs_set_termios
,
134 .break_ctl
= scc_break_ctl
,
137 /*----------------------------------------------------------------------------
138 * vme_scc_init() and support functions
139 *---------------------------------------------------------------------------*/
141 static int scc_init_drivers(void)
145 scc_driver
= alloc_tty_driver(2);
148 scc_driver
->owner
= THIS_MODULE
;
149 scc_driver
->driver_name
= "scc";
150 scc_driver
->name
= "ttyS";
151 scc_driver
->devfs_name
= "tts/";
152 scc_driver
->major
= TTY_MAJOR
;
153 scc_driver
->minor_start
= SCC_MINOR_BASE
;
154 scc_driver
->type
= TTY_DRIVER_TYPE_SERIAL
;
155 scc_driver
->subtype
= SERIAL_TYPE_NORMAL
;
156 scc_driver
->init_termios
= tty_std_termios
;
157 scc_driver
->init_termios
.c_cflag
=
158 B9600
| CS8
| CREAD
| HUPCL
| CLOCAL
;
159 scc_driver
->flags
= TTY_DRIVER_REAL_RAW
;
160 tty_set_operations(scc_driver
, &scc_ops
);
162 if ((error
= tty_register_driver(scc_driver
))) {
163 printk(KERN_ERR
"scc: Couldn't register scc driver, error = %d\n",
165 put_tty_driver(scc_driver
);
173 /* ports[] array is indexed by line no (i.e. [0] for ttyS0, [1] for ttyS1).
176 static void scc_init_portstructs(void)
178 struct scc_port
*port
;
181 for (i
= 0; i
< 2; i
++) {
182 port
= scc_ports
+ i
;
183 port
->gs
.magic
= SCC_MAGIC
;
184 port
->gs
.close_delay
= HZ
/2;
185 port
->gs
.closing_wait
= 30 * HZ
;
186 port
->gs
.rd
= &scc_real_driver
;
187 #ifdef NEW_WRITE_LOCKING
188 port
->gs
.port_write_sem
= MUTEX
;
190 init_waitqueue_head(&port
->gs
.open_wait
);
191 init_waitqueue_head(&port
->gs
.close_wait
);
196 #ifdef CONFIG_MVME147_SCC
197 static int mvme147_scc_init(void)
199 struct scc_port
*port
;
201 printk(KERN_INFO
"SCC: MVME147 Serial Driver\n");
203 port
= &scc_ports
[0];
204 port
->channel
= CHANNEL_A
;
205 port
->ctrlp
= (volatile unsigned char *)M147_SCC_A_ADDR
;
206 port
->datap
= port
->ctrlp
+ 1;
207 port
->port_a
= &scc_ports
[0];
208 port
->port_b
= &scc_ports
[1];
209 request_irq(MVME147_IRQ_SCCA_TX
, scc_tx_int
, SA_INTERRUPT
,
211 request_irq(MVME147_IRQ_SCCA_STAT
, scc_stat_int
, SA_INTERRUPT
,
212 "SCC-A status", port
);
213 request_irq(MVME147_IRQ_SCCA_RX
, scc_rx_int
, SA_INTERRUPT
,
215 request_irq(MVME147_IRQ_SCCA_SPCOND
, scc_spcond_int
, SA_INTERRUPT
,
216 "SCC-A special cond", port
);
218 SCC_ACCESS_INIT(port
);
220 /* disable interrupts for this channel */
221 SCCwrite(INT_AND_DMA_REG
, 0);
222 /* Set the interrupt vector */
223 SCCwrite(INT_VECTOR_REG
, MVME147_IRQ_SCC_BASE
);
224 /* Interrupt parameters: vector includes status, status low */
225 SCCwrite(MASTER_INT_CTRL
, MIC_VEC_INCL_STAT
);
226 SCCmod(MASTER_INT_CTRL
, 0xff, MIC_MASTER_INT_ENAB
);
230 port
= &scc_ports
[1];
231 port
->channel
= CHANNEL_B
;
232 port
->ctrlp
= (volatile unsigned char *)M147_SCC_B_ADDR
;
233 port
->datap
= port
->ctrlp
+ 1;
234 port
->port_a
= &scc_ports
[0];
235 port
->port_b
= &scc_ports
[1];
236 request_irq(MVME147_IRQ_SCCB_TX
, scc_tx_int
, SA_INTERRUPT
,
238 request_irq(MVME147_IRQ_SCCB_STAT
, scc_stat_int
, SA_INTERRUPT
,
239 "SCC-B status", port
);
240 request_irq(MVME147_IRQ_SCCB_RX
, scc_rx_int
, SA_INTERRUPT
,
242 request_irq(MVME147_IRQ_SCCB_SPCOND
, scc_spcond_int
, SA_INTERRUPT
,
243 "SCC-B special cond", port
);
245 SCC_ACCESS_INIT(port
);
247 /* disable interrupts for this channel */
248 SCCwrite(INT_AND_DMA_REG
, 0);
251 /* Ensure interrupts are enabled in the PCC chip */
252 m147_pcc
->serial_cntrl
=PCC_LEVEL_SERIAL
|PCC_INT_ENAB
;
254 /* Initialise the tty driver structures and register */
255 scc_init_portstructs();
263 #ifdef CONFIG_MVME162_SCC
264 static int mvme162_scc_init(void)
266 struct scc_port
*port
;
268 if (!(mvme16x_config
& MVME16x_CONFIG_GOT_SCCA
))
271 printk(KERN_INFO
"SCC: MVME162 Serial Driver\n");
273 port
= &scc_ports
[0];
274 port
->channel
= CHANNEL_A
;
275 port
->ctrlp
= (volatile unsigned char *)MVME_SCC_A_ADDR
;
276 port
->datap
= port
->ctrlp
+ 2;
277 port
->port_a
= &scc_ports
[0];
278 port
->port_b
= &scc_ports
[1];
279 request_irq(MVME162_IRQ_SCCA_TX
, scc_tx_int
, SA_INTERRUPT
,
281 request_irq(MVME162_IRQ_SCCA_STAT
, scc_stat_int
, SA_INTERRUPT
,
282 "SCC-A status", port
);
283 request_irq(MVME162_IRQ_SCCA_RX
, scc_rx_int
, SA_INTERRUPT
,
285 request_irq(MVME162_IRQ_SCCA_SPCOND
, scc_spcond_int
, SA_INTERRUPT
,
286 "SCC-A special cond", port
);
288 SCC_ACCESS_INIT(port
);
290 /* disable interrupts for this channel */
291 SCCwrite(INT_AND_DMA_REG
, 0);
292 /* Set the interrupt vector */
293 SCCwrite(INT_VECTOR_REG
, MVME162_IRQ_SCC_BASE
);
294 /* Interrupt parameters: vector includes status, status low */
295 SCCwrite(MASTER_INT_CTRL
, MIC_VEC_INCL_STAT
);
296 SCCmod(MASTER_INT_CTRL
, 0xff, MIC_MASTER_INT_ENAB
);
300 port
= &scc_ports
[1];
301 port
->channel
= CHANNEL_B
;
302 port
->ctrlp
= (volatile unsigned char *)MVME_SCC_B_ADDR
;
303 port
->datap
= port
->ctrlp
+ 2;
304 port
->port_a
= &scc_ports
[0];
305 port
->port_b
= &scc_ports
[1];
306 request_irq(MVME162_IRQ_SCCB_TX
, scc_tx_int
, SA_INTERRUPT
,
308 request_irq(MVME162_IRQ_SCCB_STAT
, scc_stat_int
, SA_INTERRUPT
,
309 "SCC-B status", port
);
310 request_irq(MVME162_IRQ_SCCB_RX
, scc_rx_int
, SA_INTERRUPT
,
312 request_irq(MVME162_IRQ_SCCB_SPCOND
, scc_spcond_int
, SA_INTERRUPT
,
313 "SCC-B special cond", port
);
316 SCC_ACCESS_INIT(port
); /* Either channel will do */
318 /* disable interrupts for this channel */
319 SCCwrite(INT_AND_DMA_REG
, 0);
322 /* Ensure interrupts are enabled in the MC2 chip */
323 *(volatile char *)0xfff4201d = 0x14;
325 /* Initialise the tty driver structures and register */
326 scc_init_portstructs();
334 #ifdef CONFIG_BVME6000_SCC
335 static int bvme6000_scc_init(void)
337 struct scc_port
*port
;
339 printk(KERN_INFO
"SCC: BVME6000 Serial Driver\n");
341 port
= &scc_ports
[0];
342 port
->channel
= CHANNEL_A
;
343 port
->ctrlp
= (volatile unsigned char *)BVME_SCC_A_ADDR
;
344 port
->datap
= port
->ctrlp
+ 4;
345 port
->port_a
= &scc_ports
[0];
346 port
->port_b
= &scc_ports
[1];
347 request_irq(BVME_IRQ_SCCA_TX
, scc_tx_int
, SA_INTERRUPT
,
349 request_irq(BVME_IRQ_SCCA_STAT
, scc_stat_int
, SA_INTERRUPT
,
350 "SCC-A status", port
);
351 request_irq(BVME_IRQ_SCCA_RX
, scc_rx_int
, SA_INTERRUPT
,
353 request_irq(BVME_IRQ_SCCA_SPCOND
, scc_spcond_int
, SA_INTERRUPT
,
354 "SCC-A special cond", port
);
356 SCC_ACCESS_INIT(port
);
358 /* disable interrupts for this channel */
359 SCCwrite(INT_AND_DMA_REG
, 0);
360 /* Set the interrupt vector */
361 SCCwrite(INT_VECTOR_REG
, BVME_IRQ_SCC_BASE
);
362 /* Interrupt parameters: vector includes status, status low */
363 SCCwrite(MASTER_INT_CTRL
, MIC_VEC_INCL_STAT
);
364 SCCmod(MASTER_INT_CTRL
, 0xff, MIC_MASTER_INT_ENAB
);
368 port
= &scc_ports
[1];
369 port
->channel
= CHANNEL_B
;
370 port
->ctrlp
= (volatile unsigned char *)BVME_SCC_B_ADDR
;
371 port
->datap
= port
->ctrlp
+ 4;
372 port
->port_a
= &scc_ports
[0];
373 port
->port_b
= &scc_ports
[1];
374 request_irq(BVME_IRQ_SCCB_TX
, scc_tx_int
, SA_INTERRUPT
,
376 request_irq(BVME_IRQ_SCCB_STAT
, scc_stat_int
, SA_INTERRUPT
,
377 "SCC-B status", port
);
378 request_irq(BVME_IRQ_SCCB_RX
, scc_rx_int
, SA_INTERRUPT
,
380 request_irq(BVME_IRQ_SCCB_SPCOND
, scc_spcond_int
, SA_INTERRUPT
,
381 "SCC-B special cond", port
);
384 SCC_ACCESS_INIT(port
); /* Either channel will do */
386 /* disable interrupts for this channel */
387 SCCwrite(INT_AND_DMA_REG
, 0);
390 /* Initialise the tty driver structures and register */
391 scc_init_portstructs();
399 int vme_scc_init(void)
402 static int called
= 0;
407 #ifdef CONFIG_MVME147_SCC
409 res
= mvme147_scc_init();
411 #ifdef CONFIG_MVME162_SCC
413 res
= mvme162_scc_init();
415 #ifdef CONFIG_BVME6000_SCC
416 if (MACH_IS_BVME6000
)
417 res
= bvme6000_scc_init();
423 /*---------------------------------------------------------------------------
425 *--------------------------------------------------------------------------*/
427 static irqreturn_t
scc_rx_int(int irq
, void *data
, struct pt_regs
*fp
)
430 struct scc_port
*port
= data
;
431 struct tty_struct
*tty
= port
->gs
.tty
;
432 SCC_ACCESS_INIT(port
);
434 ch
= SCCread_NB(RX_DATA_REG
);
436 printk(KERN_WARNING
"scc_rx_int with NULL tty!\n");
437 SCCwrite_NB(COMMAND_REG
, CR_HIGHEST_IUS_RESET
);
440 if (tty
->flip
.count
< TTY_FLIPBUF_SIZE
) {
441 *tty
->flip
.char_buf_ptr
= ch
;
442 *tty
->flip
.flag_buf_ptr
= 0;
443 tty
->flip
.flag_buf_ptr
++;
444 tty
->flip
.char_buf_ptr
++;
448 /* Check if another character is already ready; in that case, the
449 * spcond_int() function must be used, because this character may have an
450 * error condition that isn't signalled by the interrupt vector used!
452 if (SCCread(INT_PENDING_REG
) &
453 (port
->channel
== CHANNEL_A
? IPR_A_RX
: IPR_B_RX
)) {
454 scc_spcond_int (irq
, data
, fp
);
458 SCCwrite_NB(COMMAND_REG
, CR_HIGHEST_IUS_RESET
);
460 tty_flip_buffer_push(tty
);
465 static irqreturn_t
scc_spcond_int(int irq
, void *data
, struct pt_regs
*fp
)
467 struct scc_port
*port
= data
;
468 struct tty_struct
*tty
= port
->gs
.tty
;
469 unsigned char stat
, ch
, err
;
470 int int_pending_mask
= port
->channel
== CHANNEL_A
?
472 SCC_ACCESS_INIT(port
);
475 printk(KERN_WARNING
"scc_spcond_int with NULL tty!\n");
476 SCCwrite(COMMAND_REG
, CR_ERROR_RESET
);
477 SCCwrite_NB(COMMAND_REG
, CR_HIGHEST_IUS_RESET
);
481 stat
= SCCread(SPCOND_STATUS_REG
);
482 ch
= SCCread_NB(RX_DATA_REG
);
484 if (stat
& SCSR_RX_OVERRUN
)
486 else if (stat
& SCSR_PARITY_ERR
)
488 else if (stat
& SCSR_CRC_FRAME_ERR
)
493 if (tty
->flip
.count
< TTY_FLIPBUF_SIZE
) {
494 *tty
->flip
.char_buf_ptr
= ch
;
495 *tty
->flip
.flag_buf_ptr
= err
;
496 tty
->flip
.flag_buf_ptr
++;
497 tty
->flip
.char_buf_ptr
++;
501 /* ++TeSche: *All* errors have to be cleared manually,
502 * else the condition persists for the next chars
505 SCCwrite(COMMAND_REG
, CR_ERROR_RESET
);
507 } while(SCCread(INT_PENDING_REG
) & int_pending_mask
);
509 SCCwrite_NB(COMMAND_REG
, CR_HIGHEST_IUS_RESET
);
511 tty_flip_buffer_push(tty
);
516 static irqreturn_t
scc_tx_int(int irq
, void *data
, struct pt_regs
*fp
)
518 struct scc_port
*port
= data
;
519 SCC_ACCESS_INIT(port
);
522 printk(KERN_WARNING
"scc_tx_int with NULL tty!\n");
523 SCCmod (INT_AND_DMA_REG
, ~IDR_TX_INT_ENAB
, 0);
524 SCCwrite(COMMAND_REG
, CR_TX_PENDING_RESET
);
525 SCCwrite_NB(COMMAND_REG
, CR_HIGHEST_IUS_RESET
);
528 while ((SCCread_NB(STATUS_REG
) & SR_TX_BUF_EMPTY
)) {
530 SCCwrite(TX_DATA_REG
, port
->x_char
);
533 else if ((port
->gs
.xmit_cnt
<= 0) || port
->gs
.tty
->stopped
||
534 port
->gs
.tty
->hw_stopped
)
537 SCCwrite(TX_DATA_REG
, port
->gs
.xmit_buf
[port
->gs
.xmit_tail
++]);
538 port
->gs
.xmit_tail
= port
->gs
.xmit_tail
& (SERIAL_XMIT_SIZE
-1);
539 if (--port
->gs
.xmit_cnt
<= 0)
543 if ((port
->gs
.xmit_cnt
<= 0) || port
->gs
.tty
->stopped
||
544 port
->gs
.tty
->hw_stopped
) {
545 /* disable tx interrupts */
546 SCCmod (INT_AND_DMA_REG
, ~IDR_TX_INT_ENAB
, 0);
547 SCCwrite(COMMAND_REG
, CR_TX_PENDING_RESET
); /* disable tx_int on next tx underrun? */
548 port
->gs
.flags
&= ~GS_TX_INTEN
;
550 if (port
->gs
.tty
&& port
->gs
.xmit_cnt
<= port
->gs
.wakeup_chars
) {
551 if ((port
->gs
.tty
->flags
& (1 << TTY_DO_WRITE_WAKEUP
)) &&
552 port
->gs
.tty
->ldisc
.write_wakeup
)
553 (port
->gs
.tty
->ldisc
.write_wakeup
)(port
->gs
.tty
);
554 wake_up_interruptible(&port
->gs
.tty
->write_wait
);
557 SCCwrite_NB(COMMAND_REG
, CR_HIGHEST_IUS_RESET
);
562 static irqreturn_t
scc_stat_int(int irq
, void *data
, struct pt_regs
*fp
)
564 struct scc_port
*port
= data
;
565 unsigned channel
= port
->channel
;
566 unsigned char last_sr
, sr
, changed
;
567 SCC_ACCESS_INIT(port
);
569 last_sr
= scc_last_status_reg
[channel
];
570 sr
= scc_last_status_reg
[channel
] = SCCread_NB(STATUS_REG
);
571 changed
= last_sr
^ sr
;
573 if (changed
& SR_DCD
) {
574 port
->c_dcd
= !!(sr
& SR_DCD
);
575 if (!(port
->gs
.flags
& ASYNC_CHECK_CD
))
576 ; /* Don't report DCD changes */
577 else if (port
->c_dcd
) {
578 wake_up_interruptible(&port
->gs
.open_wait
);
582 tty_hangup (port
->gs
.tty
);
585 SCCwrite(COMMAND_REG
, CR_EXTSTAT_RESET
);
586 SCCwrite_NB(COMMAND_REG
, CR_HIGHEST_IUS_RESET
);
591 /*---------------------------------------------------------------------------
592 * generic_serial.c callback funtions
593 *--------------------------------------------------------------------------*/
595 static void scc_disable_tx_interrupts(void *ptr
)
597 struct scc_port
*port
= ptr
;
599 SCC_ACCESS_INIT(port
);
601 local_irq_save(flags
);
602 SCCmod(INT_AND_DMA_REG
, ~IDR_TX_INT_ENAB
, 0);
603 port
->gs
.flags
&= ~GS_TX_INTEN
;
604 local_irq_restore(flags
);
608 static void scc_enable_tx_interrupts(void *ptr
)
610 struct scc_port
*port
= ptr
;
612 SCC_ACCESS_INIT(port
);
614 local_irq_save(flags
);
615 SCCmod(INT_AND_DMA_REG
, 0xff, IDR_TX_INT_ENAB
);
616 /* restart the transmitter */
617 scc_tx_int (0, port
, 0);
618 local_irq_restore(flags
);
622 static void scc_disable_rx_interrupts(void *ptr
)
624 struct scc_port
*port
= ptr
;
626 SCC_ACCESS_INIT(port
);
628 local_irq_save(flags
);
629 SCCmod(INT_AND_DMA_REG
,
630 ~(IDR_RX_INT_MASK
|IDR_PARERR_AS_SPCOND
|IDR_EXTSTAT_INT_ENAB
), 0);
631 local_irq_restore(flags
);
635 static void scc_enable_rx_interrupts(void *ptr
)
637 struct scc_port
*port
= ptr
;
639 SCC_ACCESS_INIT(port
);
641 local_irq_save(flags
);
642 SCCmod(INT_AND_DMA_REG
, 0xff,
643 IDR_EXTSTAT_INT_ENAB
|IDR_PARERR_AS_SPCOND
|IDR_RX_INT_ALL
);
644 local_irq_restore(flags
);
648 static int scc_get_CD(void *ptr
)
650 struct scc_port
*port
= ptr
;
651 unsigned channel
= port
->channel
;
653 return !!(scc_last_status_reg
[channel
] & SR_DCD
);
657 static void scc_shutdown_port(void *ptr
)
659 struct scc_port
*port
= ptr
;
661 port
->gs
.flags
&= ~ GS_ACTIVE
;
662 if (port
->gs
.tty
&& port
->gs
.tty
->termios
->c_cflag
& HUPCL
) {
663 scc_setsignals (port
, 0, 0);
668 static int scc_set_real_termios (void *ptr
)
670 /* the SCC has char sizes 5,7,6,8 in that order! */
671 static int chsize_map
[4] = { 0, 2, 1, 3 };
672 unsigned cflag
, baud
, chsize
, channel
, brgval
= 0;
674 struct scc_port
*port
= ptr
;
675 SCC_ACCESS_INIT(port
);
677 if (!port
->gs
.tty
|| !port
->gs
.tty
->termios
) return 0;
679 channel
= port
->channel
;
681 if (channel
== CHANNEL_A
)
682 return 0; /* Settings controlled by boot PROM */
684 cflag
= port
->gs
.tty
->termios
->c_cflag
;
685 baud
= port
->gs
.baud
;
686 chsize
= (cflag
& CSIZE
) >> 4;
689 /* speed == 0 -> drop DTR */
690 local_irq_save(flags
);
691 SCCmod(TX_CTRL_REG
, ~TCR_DTR
, 0);
692 local_irq_restore(flags
);
695 else if ((MACH_IS_MVME16x
&& (baud
< 50 || baud
> 38400)) ||
696 (MACH_IS_MVME147
&& (baud
< 50 || baud
> 19200)) ||
697 (MACH_IS_BVME6000
&&(baud
< 50 || baud
> 76800))) {
698 printk(KERN_NOTICE
"SCC: Bad speed requested, %d\n", baud
);
703 port
->gs
.flags
&= ~ASYNC_CHECK_CD
;
705 port
->gs
.flags
|= ASYNC_CHECK_CD
;
707 #ifdef CONFIG_MVME147_SCC
709 brgval
= (M147_SCC_PCLK
+ baud
/2) / (16 * 2 * baud
) - 2;
711 #ifdef CONFIG_MVME162_SCC
713 brgval
= (MVME_SCC_PCLK
+ baud
/2) / (16 * 2 * baud
) - 2;
715 #ifdef CONFIG_BVME6000_SCC
716 if (MACH_IS_BVME6000
)
717 brgval
= (BVME_SCC_RTxC
+ baud
/2) / (16 * 2 * baud
) - 2;
719 /* Now we have all parameters and can go to set them: */
720 local_irq_save(flags
);
722 /* receiver's character size and auto-enables */
723 SCCmod(RX_CTRL_REG
, ~(RCR_CHSIZE_MASK
|RCR_AUTO_ENAB_MODE
),
724 (chsize_map
[chsize
] << 6) |
725 ((cflag
& CRTSCTS
) ? RCR_AUTO_ENAB_MODE
: 0));
726 /* parity and stop bits (both, Tx and Rx), clock mode never changes */
727 SCCmod (AUX1_CTRL_REG
,
728 ~(A1CR_PARITY_MASK
| A1CR_MODE_MASK
),
730 ? (cflag
& PARODD
? A1CR_PARITY_ODD
: A1CR_PARITY_EVEN
)
732 | (cflag
& CSTOPB
? A1CR_MODE_ASYNC_2
: A1CR_MODE_ASYNC_1
)));
733 /* sender's character size, set DTR for valid baud rate */
734 SCCmod(TX_CTRL_REG
, ~TCR_CHSIZE_MASK
, chsize_map
[chsize
] << 5 | TCR_DTR
);
735 /* clock sources never change */
736 /* disable BRG before changing the value */
737 SCCmod(DPLL_CTRL_REG
, ~DCR_BRG_ENAB
, 0);
739 SCCwrite(TIMER_LOW_REG
, brgval
& 0xff);
740 SCCwrite(TIMER_HIGH_REG
, (brgval
>> 8) & 0xff);
741 /* BRG enable, and clock source never changes */
742 SCCmod(DPLL_CTRL_REG
, 0xff, DCR_BRG_ENAB
);
744 local_irq_restore(flags
);
750 static int scc_chars_in_buffer (void *ptr
)
752 struct scc_port
*port
= ptr
;
753 SCC_ACCESS_INIT(port
);
755 return (SCCread (SPCOND_STATUS_REG
) & SCSR_ALL_SENT
) ? 0 : 1;
759 /* Comment taken from sx.c (2.4.0):
760 I haven't the foggiest why the decrement use count has to happen
761 here. The whole linux serial drivers stuff needs to be redesigned.
762 My guess is that this is a hack to minimize the impact of a bug
763 elsewhere. Thinking about it some more. (try it sometime) Try
764 running minicom on a serial port that is driven by a modularized
765 driver. Have the modem hangup. Then remove the driver module. Then
766 exit minicom. I expect an "oops". -- REW */
768 static void scc_hungup(void *ptr
)
770 scc_disable_tx_interrupts(ptr
);
771 scc_disable_rx_interrupts(ptr
);
775 static void scc_close(void *ptr
)
777 scc_disable_tx_interrupts(ptr
);
778 scc_disable_rx_interrupts(ptr
);
782 /*---------------------------------------------------------------------------
783 * Internal support functions
784 *--------------------------------------------------------------------------*/
786 static void scc_setsignals(struct scc_port
*port
, int dtr
, int rts
)
790 SCC_ACCESS_INIT(port
);
792 local_irq_save(flags
);
793 t
= SCCread(TX_CTRL_REG
);
794 if (dtr
>= 0) t
= dtr
? (t
| TCR_DTR
): (t
& ~TCR_DTR
);
795 if (rts
>= 0) t
= rts
? (t
| TCR_RTS
): (t
& ~TCR_RTS
);
796 SCCwrite(TX_CTRL_REG
, t
);
797 local_irq_restore(flags
);
801 static void scc_send_xchar(struct tty_struct
*tty
, char ch
)
803 struct scc_port
*port
= (struct scc_port
*)tty
->driver_data
;
807 scc_enable_tx_interrupts(port
);
811 /*---------------------------------------------------------------------------
812 * Driver entrypoints referenced from above
813 *--------------------------------------------------------------------------*/
815 static int scc_open (struct tty_struct
* tty
, struct file
* filp
)
817 int line
= tty
->index
;
819 struct scc_port
*port
= &scc_ports
[line
];
820 int i
, channel
= port
->channel
;
822 SCC_ACCESS_INIT(port
);
823 #if defined(CONFIG_MVME162_SCC) || defined(CONFIG_MVME147_SCC)
824 static const struct {
826 } mvme_init_tab
[] = {
827 /* Values for MVME162 and MVME147 */
828 /* no parity, 1 stop bit, async, 1:16 */
829 { AUX1_CTRL_REG
, A1CR_PARITY_NONE
|A1CR_MODE_ASYNC_1
|A1CR_CLKMODE_x16
},
830 /* parity error is special cond, ints disabled, no DMA */
831 { INT_AND_DMA_REG
, IDR_PARERR_AS_SPCOND
| IDR_RX_INT_DISAB
},
832 /* Rx 8 bits/char, no auto enable, Rx off */
833 { RX_CTRL_REG
, RCR_CHSIZE_8
},
834 /* DTR off, Tx 8 bits/char, RTS off, Tx off */
835 { TX_CTRL_REG
, TCR_CHSIZE_8
},
836 /* special features off */
837 { AUX2_CTRL_REG
, 0 },
838 { CLK_CTRL_REG
, CCR_RXCLK_BRG
| CCR_TXCLK_BRG
},
839 { DPLL_CTRL_REG
, DCR_BRG_ENAB
| DCR_BRG_USE_PCLK
},
841 { RX_CTRL_REG
, RCR_RX_ENAB
| RCR_CHSIZE_8
},
843 { TX_CTRL_REG
, TCR_TX_ENAB
| TCR_RTS
| TCR_DTR
| TCR_CHSIZE_8
},
844 /* Ext/Stat ints: DCD only */
845 { INT_CTRL_REG
, ICR_ENAB_DCD_INT
},
846 /* Reset Ext/Stat ints */
847 { COMMAND_REG
, CR_EXTSTAT_RESET
},
849 { COMMAND_REG
, CR_EXTSTAT_RESET
},
852 #if defined(CONFIG_BVME6000_SCC)
853 static const struct {
855 } bvme_init_tab
[] = {
856 /* Values for BVME6000 */
857 /* no parity, 1 stop bit, async, 1:16 */
858 { AUX1_CTRL_REG
, A1CR_PARITY_NONE
|A1CR_MODE_ASYNC_1
|A1CR_CLKMODE_x16
},
859 /* parity error is special cond, ints disabled, no DMA */
860 { INT_AND_DMA_REG
, IDR_PARERR_AS_SPCOND
| IDR_RX_INT_DISAB
},
861 /* Rx 8 bits/char, no auto enable, Rx off */
862 { RX_CTRL_REG
, RCR_CHSIZE_8
},
863 /* DTR off, Tx 8 bits/char, RTS off, Tx off */
864 { TX_CTRL_REG
, TCR_CHSIZE_8
},
865 /* special features off */
866 { AUX2_CTRL_REG
, 0 },
867 { CLK_CTRL_REG
, CCR_RTxC_XTAL
| CCR_RXCLK_BRG
| CCR_TXCLK_BRG
},
868 { DPLL_CTRL_REG
, DCR_BRG_ENAB
},
870 { RX_CTRL_REG
, RCR_RX_ENAB
| RCR_CHSIZE_8
},
872 { TX_CTRL_REG
, TCR_TX_ENAB
| TCR_RTS
| TCR_DTR
| TCR_CHSIZE_8
},
873 /* Ext/Stat ints: DCD only */
874 { INT_CTRL_REG
, ICR_ENAB_DCD_INT
},
875 /* Reset Ext/Stat ints */
876 { COMMAND_REG
, CR_EXTSTAT_RESET
},
878 { COMMAND_REG
, CR_EXTSTAT_RESET
},
881 if (!(port
->gs
.flags
& ASYNC_INITIALIZED
)) {
882 local_irq_save(flags
);
883 #if defined(CONFIG_MVME147_SCC) || defined(CONFIG_MVME162_SCC)
884 if (MACH_IS_MVME147
|| MACH_IS_MVME16x
) {
885 for (i
=0; i
<sizeof(mvme_init_tab
)/sizeof(*mvme_init_tab
); ++i
)
886 SCCwrite(mvme_init_tab
[i
].reg
, mvme_init_tab
[i
].val
);
889 #if defined(CONFIG_BVME6000_SCC)
890 if (MACH_IS_BVME6000
) {
891 for (i
=0; i
<sizeof(bvme_init_tab
)/sizeof(*bvme_init_tab
); ++i
)
892 SCCwrite(bvme_init_tab
[i
].reg
, bvme_init_tab
[i
].val
);
896 /* remember status register for detection of DCD and CTS changes */
897 scc_last_status_reg
[channel
] = SCCread(STATUS_REG
);
899 port
->c_dcd
= 0; /* Prevent initial 1->0 interrupt */
900 scc_setsignals (port
, 1,1);
901 local_irq_restore(flags
);
904 tty
->driver_data
= port
;
907 retval
= gs_init_port(&port
->gs
);
912 port
->gs
.flags
|= GS_ACTIVE
;
913 retval
= gs_block_til_ready(port
, filp
);
920 port
->c_dcd
= scc_get_CD (port
);
922 scc_enable_rx_interrupts(port
);
928 static void scc_throttle (struct tty_struct
* tty
)
930 struct scc_port
*port
= (struct scc_port
*)tty
->driver_data
;
932 SCC_ACCESS_INIT(port
);
934 if (tty
->termios
->c_cflag
& CRTSCTS
) {
935 local_irq_save(flags
);
936 SCCmod(TX_CTRL_REG
, ~TCR_RTS
, 0);
937 local_irq_restore(flags
);
940 scc_send_xchar(tty
, STOP_CHAR(tty
));
944 static void scc_unthrottle (struct tty_struct
* tty
)
946 struct scc_port
*port
= (struct scc_port
*)tty
->driver_data
;
948 SCC_ACCESS_INIT(port
);
950 if (tty
->termios
->c_cflag
& CRTSCTS
) {
951 local_irq_save(flags
);
952 SCCmod(TX_CTRL_REG
, 0xff, TCR_RTS
);
953 local_irq_restore(flags
);
956 scc_send_xchar(tty
, START_CHAR(tty
));
960 static int scc_ioctl(struct tty_struct
*tty
, struct file
*file
,
961 unsigned int cmd
, unsigned long arg
)
967 static void scc_break_ctl(struct tty_struct
*tty
, int break_state
)
969 struct scc_port
*port
= (struct scc_port
*)tty
->driver_data
;
971 SCC_ACCESS_INIT(port
);
973 local_irq_save(flags
);
974 SCCmod(TX_CTRL_REG
, ~TCR_SEND_BREAK
,
975 break_state
? TCR_SEND_BREAK
: 0);
976 local_irq_restore(flags
);
980 /*---------------------------------------------------------------------------
981 * Serial console stuff...
982 *--------------------------------------------------------------------------*/
984 #define scc_delay() do { __asm__ __volatile__ (" nop; nop"); } while (0)
986 static void scc_ch_write (char ch
)
988 volatile char *p
= NULL
;
990 #ifdef CONFIG_MVME147_SCC
992 p
= (volatile char *)M147_SCC_A_ADDR
;
994 #ifdef CONFIG_MVME162_SCC
996 p
= (volatile char *)MVME_SCC_A_ADDR
;
998 #ifdef CONFIG_BVME6000_SCC
999 if (MACH_IS_BVME6000
)
1000 p
= (volatile char *)BVME_SCC_A_ADDR
;
1013 /* The console must be locked when we get here. */
1015 static void scc_console_write (struct console
*co
, const char *str
, unsigned count
)
1017 unsigned long flags
;
1019 local_irq_save(flags
);
1024 scc_ch_write ('\r');
1025 scc_ch_write (*str
++);
1027 local_irq_restore(flags
);
1030 static struct tty_driver
*scc_console_device(struct console
*c
, int *index
)
1037 static int __init
scc_console_setup(struct console
*co
, char *options
)
1043 static struct console sercons
= {
1045 .write
= scc_console_write
,
1046 .device
= scc_console_device
,
1047 .setup
= scc_console_setup
,
1048 .flags
= CON_PRINTBUFFER
,
1053 static int __init
vme_scc_console_init(void)
1055 if (vme_brdtype
== VME_TYPE_MVME147
||
1056 vme_brdtype
== VME_TYPE_MVME162
||
1057 vme_brdtype
== VME_TYPE_MVME172
||
1058 vme_brdtype
== VME_TYPE_BVME4000
||
1059 vme_brdtype
== VME_TYPE_BVME6000
)
1060 register_console(&sercons
);
1063 console_initcall(vme_scc_console_init
);