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/tqueue.h>
33 #include <linux/version.h>
34 #include <linux/slab.h>
35 #include <linux/miscdevice.h>
36 #include <linux/console.h>
37 #include <linux/init.h>
38 #include <asm/setup.h>
39 #include <asm/bootinfo.h>
41 #ifdef CONFIG_MVME147_SCC
42 #include <asm/mvme147hw.h>
44 #ifdef CONFIG_MVME162_SCC
45 #include <asm/mvme16xhw.h>
47 #ifdef CONFIG_BVME6000_SCC
48 #include <asm/bvme6000hw.h>
51 #include <linux/generic_serial.h>
58 #define SCC_MINOR_BASE 64
60 /* Shadows for all SCC write registers */
61 static unsigned char scc_shadow[2][16];
63 /* Location to access for SCC register access delay */
64 static volatile unsigned char *scc_del = NULL;
66 /* To keep track of STATUS_REG state for detection of Ext/Status int source */
67 static unsigned char scc_last_status_reg[2];
69 /***************************** Prototypes *****************************/
71 /* Function prototypes */
72 static void scc_disable_tx_interrupts(void * ptr);
73 static void scc_enable_tx_interrupts(void * ptr);
74 static void scc_disable_rx_interrupts(void * ptr);
75 static void scc_enable_rx_interrupts(void * ptr);
76 static int scc_get_CD(void * ptr);
77 static void scc_shutdown_port(void * ptr);
78 static int scc_set_real_termios(void *ptr);
79 static void scc_hungup(void *ptr);
80 static void scc_close(void *ptr);
81 static int scc_chars_in_buffer(void * ptr);
82 static int scc_open(struct tty_struct * tty, struct file * filp);
83 static int scc_ioctl(struct tty_struct * tty, struct file * filp,
84 unsigned int cmd, unsigned long arg);
85 static void scc_throttle(struct tty_struct *tty);
86 static void scc_unthrottle(struct tty_struct *tty);
87 static void scc_tx_int(int irq, void *data, struct pt_regs *fp);
88 static void scc_rx_int(int irq, void *data, struct pt_regs *fp);
89 static void scc_stat_int(int irq, void *data, struct pt_regs *fp);
90 static void scc_spcond_int(int irq, void *data, struct pt_regs *fp);
91 static void scc_setsignals(struct scc_port *port, int dtr, int rts);
92 static void scc_break_ctl(struct tty_struct *tty, int break_state);
94 static struct tty_driver scc_driver, scc_callout_driver;
96 static struct tty_struct *scc_table[2] = { NULL, };
97 static struct termios * scc_termios[2];
98 static struct termios * scc_termios_locked[2];
99 struct scc_port scc_ports[2];
102 int scc_initialized = 0;
104 /*---------------------------------------------------------------------------
105 * Interface from generic_serial.c back here
106 *--------------------------------------------------------------------------*/
108 static struct real_driver scc_real_driver = {
109 scc_disable_tx_interrupts,
110 scc_enable_tx_interrupts,
111 scc_disable_rx_interrupts,
112 scc_enable_rx_interrupts,
115 scc_set_real_termios,
123 /*----------------------------------------------------------------------------
124 * vme_scc_init() and support functions
125 *---------------------------------------------------------------------------*/
127 static int scc_init_drivers(void)
131 memset(&scc_driver, 0, sizeof(scc_driver));
132 scc_driver.magic = TTY_DRIVER_MAGIC;
133 scc_driver.driver_name = "scc";
134 #ifdef CONFIG_DEVFS_FS
135 scc_driver.name = "tts/%d";
137 scc_driver.name = "ttyS";
139 scc_driver.major = TTY_MAJOR;
140 scc_driver.minor_start = SCC_MINOR_BASE;
142 scc_driver.type = TTY_DRIVER_TYPE_SERIAL;
143 scc_driver.subtype = SERIAL_TYPE_NORMAL;
144 scc_driver.init_termios = tty_std_termios;
145 scc_driver.init_termios.c_cflag =
146 B9600 | CS8 | CREAD | HUPCL | CLOCAL;
147 scc_driver.flags = TTY_DRIVER_REAL_RAW;
148 scc_driver.refcount = &scc_refcount;
149 scc_driver.table = scc_table;
150 scc_driver.termios = scc_termios;
151 scc_driver.termios_locked = scc_termios_locked;
153 scc_driver.open = scc_open;
154 scc_driver.close = gs_close;
155 scc_driver.write = gs_write;
156 scc_driver.put_char = gs_put_char;
157 scc_driver.flush_chars = gs_flush_chars;
158 scc_driver.write_room = gs_write_room;
159 scc_driver.chars_in_buffer = gs_chars_in_buffer;
160 scc_driver.flush_buffer = gs_flush_buffer;
161 scc_driver.ioctl = scc_ioctl;
162 scc_driver.throttle = scc_throttle;
163 scc_driver.unthrottle = scc_unthrottle;
164 scc_driver.set_termios = gs_set_termios;
165 scc_driver.stop = gs_stop;
166 scc_driver.start = gs_start;
167 scc_driver.hangup = gs_hangup;
168 scc_driver.break_ctl = scc_break_ctl;
170 scc_callout_driver = scc_driver;
171 #ifdef CONFIG_DEVFS_FS
172 scc_callout_driver.name = "cua/%d";
174 scc_callout_driver.name = "cua";
176 scc_callout_driver.major = TTYAUX_MAJOR;
177 scc_callout_driver.subtype = SERIAL_TYPE_CALLOUT;
179 if ((error = tty_register_driver(&scc_driver))) {
180 printk(KERN_ERR "scc: Couldn't register scc driver, error = %d\n",
184 if ((error = tty_register_driver(&scc_callout_driver))) {
185 tty_unregister_driver(&scc_driver);
186 printk(KERN_ERR "scc: Couldn't register scc callout driver, error = %d\n",
195 /* ports[] array is indexed by line no (i.e. [0] for ttyS0, [1] for ttyS1).
198 static void scc_init_portstructs(void)
200 struct scc_port *port;
203 for (i = 0; i < 2; i++) {
204 port = scc_ports + i;
205 port->gs.callout_termios = tty_std_termios;
206 port->gs.normal_termios = tty_std_termios;
207 port->gs.magic = SCC_MAGIC;
208 port->gs.close_delay = HZ/2;
209 port->gs.closing_wait = 30 * HZ;
210 port->gs.rd = &scc_real_driver;
211 #ifdef NEW_WRITE_LOCKING
212 port->gs.port_write_sem = MUTEX;
214 init_waitqueue_head(&port->gs.open_wait);
215 init_waitqueue_head(&port->gs.close_wait);
220 #ifdef CONFIG_MVME147_SCC
221 static int mvme147_scc_init(void)
223 struct scc_port *port;
225 printk(KERN_INFO "SCC: MVME147 Serial Driver\n");
227 port = &scc_ports[0];
228 port->channel = CHANNEL_A;
229 port->ctrlp = (volatile unsigned char *)M147_SCC_A_ADDR;
230 port->datap = port->ctrlp + 1;
231 port->port_a = &scc_ports[0];
232 port->port_b = &scc_ports[1];
233 request_irq(MVME147_IRQ_SCCA_TX, scc_tx_int, SA_INTERRUPT,
235 request_irq(MVME147_IRQ_SCCA_STAT, scc_stat_int, SA_INTERRUPT,
236 "SCC-A status", port);
237 request_irq(MVME147_IRQ_SCCA_RX, scc_rx_int, SA_INTERRUPT,
239 request_irq(MVME147_IRQ_SCCA_SPCOND, scc_spcond_int, SA_INTERRUPT,
240 "SCC-A special cond", port);
242 SCC_ACCESS_INIT(port);
244 /* disable interrupts for this channel */
245 SCCwrite(INT_AND_DMA_REG, 0);
246 /* Set the interrupt vector */
247 SCCwrite(INT_VECTOR_REG, MVME147_IRQ_SCC_BASE);
248 /* Interrupt parameters: vector includes status, status low */
249 SCCwrite(MASTER_INT_CTRL, MIC_VEC_INCL_STAT);
250 SCCmod(MASTER_INT_CTRL, 0xff, MIC_MASTER_INT_ENAB);
254 port = &scc_ports[1];
255 port->channel = CHANNEL_B;
256 port->ctrlp = (volatile unsigned char *)M147_SCC_B_ADDR;
257 port->datap = port->ctrlp + 1;
258 port->port_a = &scc_ports[0];
259 port->port_b = &scc_ports[1];
260 request_irq(MVME147_IRQ_SCCB_TX, scc_tx_int, SA_INTERRUPT,
262 request_irq(MVME147_IRQ_SCCB_STAT, scc_stat_int, SA_INTERRUPT,
263 "SCC-B status", port);
264 request_irq(MVME147_IRQ_SCCB_RX, scc_rx_int, SA_INTERRUPT,
266 request_irq(MVME147_IRQ_SCCB_SPCOND, scc_spcond_int, SA_INTERRUPT,
267 "SCC-B special cond", port);
269 SCC_ACCESS_INIT(port);
271 /* disable interrupts for this channel */
272 SCCwrite(INT_AND_DMA_REG, 0);
275 /* Ensure interrupts are enabled in the PCC chip */
276 m147_pcc->serial_cntrl=PCC_LEVEL_SERIAL|PCC_INT_ENAB;
278 /* Initialise the tty driver structures and register */
279 scc_init_portstructs();
287 #ifdef CONFIG_MVME162_SCC
288 static int mvme162_scc_init(void)
290 struct scc_port *port;
292 if (!(mvme16x_config & MVME16x_CONFIG_GOT_SCCA))
295 printk(KERN_INFO "SCC: MVME162 Serial Driver\n");
297 port = &scc_ports[0];
298 port->channel = CHANNEL_A;
299 port->ctrlp = (volatile unsigned char *)MVME_SCC_A_ADDR;
300 port->datap = port->ctrlp + 2;
301 port->port_a = &scc_ports[0];
302 port->port_b = &scc_ports[1];
303 request_irq(MVME162_IRQ_SCCA_TX, scc_tx_int, SA_INTERRUPT,
305 request_irq(MVME162_IRQ_SCCA_STAT, scc_stat_int, SA_INTERRUPT,
306 "SCC-A status", port);
307 request_irq(MVME162_IRQ_SCCA_RX, scc_rx_int, SA_INTERRUPT,
309 request_irq(MVME162_IRQ_SCCA_SPCOND, scc_spcond_int, SA_INTERRUPT,
310 "SCC-A special cond", port);
312 SCC_ACCESS_INIT(port);
314 /* disable interrupts for this channel */
315 SCCwrite(INT_AND_DMA_REG, 0);
316 /* Set the interrupt vector */
317 SCCwrite(INT_VECTOR_REG, MVME162_IRQ_SCC_BASE);
318 /* Interrupt parameters: vector includes status, status low */
319 SCCwrite(MASTER_INT_CTRL, MIC_VEC_INCL_STAT);
320 SCCmod(MASTER_INT_CTRL, 0xff, MIC_MASTER_INT_ENAB);
324 port = &scc_ports[1];
325 port->channel = CHANNEL_B;
326 port->ctrlp = (volatile unsigned char *)MVME_SCC_B_ADDR;
327 port->datap = port->ctrlp + 2;
328 port->port_a = &scc_ports[0];
329 port->port_b = &scc_ports[1];
330 request_irq(MVME162_IRQ_SCCB_TX, scc_tx_int, SA_INTERRUPT,
332 request_irq(MVME162_IRQ_SCCB_STAT, scc_stat_int, SA_INTERRUPT,
333 "SCC-B status", port);
334 request_irq(MVME162_IRQ_SCCB_RX, scc_rx_int, SA_INTERRUPT,
336 request_irq(MVME162_IRQ_SCCB_SPCOND, scc_spcond_int, SA_INTERRUPT,
337 "SCC-B special cond", port);
340 SCC_ACCESS_INIT(port); /* Either channel will do */
342 /* disable interrupts for this channel */
343 SCCwrite(INT_AND_DMA_REG, 0);
346 /* Ensure interrupts are enabled in the MC2 chip */
347 *(volatile char *)0xfff4201d = 0x14;
349 /* Initialise the tty driver structures and register */
350 scc_init_portstructs();
358 #ifdef CONFIG_BVME6000_SCC
359 static int bvme6000_scc_init(void)
361 struct scc_port *port;
363 printk(KERN_INFO "SCC: BVME6000 Serial Driver\n");
365 port = &scc_ports[0];
366 port->channel = CHANNEL_A;
367 port->ctrlp = (volatile unsigned char *)BVME_SCC_A_ADDR;
368 port->datap = port->ctrlp + 4;
369 port->port_a = &scc_ports[0];
370 port->port_b = &scc_ports[1];
371 request_irq(BVME_IRQ_SCCA_TX, scc_tx_int, SA_INTERRUPT,
373 request_irq(BVME_IRQ_SCCA_STAT, scc_stat_int, SA_INTERRUPT,
374 "SCC-A status", port);
375 request_irq(BVME_IRQ_SCCA_RX, scc_rx_int, SA_INTERRUPT,
377 request_irq(BVME_IRQ_SCCA_SPCOND, scc_spcond_int, SA_INTERRUPT,
378 "SCC-A special cond", port);
380 SCC_ACCESS_INIT(port);
382 /* disable interrupts for this channel */
383 SCCwrite(INT_AND_DMA_REG, 0);
384 /* Set the interrupt vector */
385 SCCwrite(INT_VECTOR_REG, BVME_IRQ_SCC_BASE);
386 /* Interrupt parameters: vector includes status, status low */
387 SCCwrite(MASTER_INT_CTRL, MIC_VEC_INCL_STAT);
388 SCCmod(MASTER_INT_CTRL, 0xff, MIC_MASTER_INT_ENAB);
392 port = &scc_ports[1];
393 port->channel = CHANNEL_B;
394 port->ctrlp = (volatile unsigned char *)BVME_SCC_B_ADDR;
395 port->datap = port->ctrlp + 4;
396 port->port_a = &scc_ports[0];
397 port->port_b = &scc_ports[1];
398 request_irq(BVME_IRQ_SCCB_TX, scc_tx_int, SA_INTERRUPT,
400 request_irq(BVME_IRQ_SCCB_STAT, scc_stat_int, SA_INTERRUPT,
401 "SCC-B status", port);
402 request_irq(BVME_IRQ_SCCB_RX, scc_rx_int, SA_INTERRUPT,
404 request_irq(BVME_IRQ_SCCB_SPCOND, scc_spcond_int, SA_INTERRUPT,
405 "SCC-B special cond", port);
408 SCC_ACCESS_INIT(port); /* Either channel will do */
410 /* disable interrupts for this channel */
411 SCCwrite(INT_AND_DMA_REG, 0);
414 /* Initialise the tty driver structures and register */
415 scc_init_portstructs();
423 int vme_scc_init(void)
426 static int called = 0;
431 #ifdef CONFIG_MVME147_SCC
433 res = mvme147_scc_init();
435 #ifdef CONFIG_MVME162_SCC
437 res = mvme162_scc_init();
439 #ifdef CONFIG_BVME6000_SCC
440 if (MACH_IS_BVME6000)
441 res = bvme6000_scc_init();
447 /*---------------------------------------------------------------------------
449 *--------------------------------------------------------------------------*/
451 static void scc_rx_int(int irq, void *data, struct pt_regs *fp)
454 struct scc_port *port = data;
455 struct tty_struct *tty = port->gs.tty;
456 SCC_ACCESS_INIT(port);
458 ch = SCCread_NB(RX_DATA_REG);
460 printk(KERN_WARNING "scc_rx_int with NULL tty!\n");
461 SCCwrite_NB(COMMAND_REG, CR_HIGHEST_IUS_RESET);
464 if (tty->flip.count < TTY_FLIPBUF_SIZE) {
465 *tty->flip.char_buf_ptr = ch;
466 *tty->flip.flag_buf_ptr = 0;
467 tty->flip.flag_buf_ptr++;
468 tty->flip.char_buf_ptr++;
472 /* Check if another character is already ready; in that case, the
473 * spcond_int() function must be used, because this character may have an
474 * error condition that isn't signalled by the interrupt vector used!
476 if (SCCread(INT_PENDING_REG) &
477 (port->channel == CHANNEL_A ? IPR_A_RX : IPR_B_RX)) {
478 scc_spcond_int (irq, data, fp);
482 SCCwrite_NB(COMMAND_REG, CR_HIGHEST_IUS_RESET);
484 tty_flip_buffer_push(tty);
488 static void scc_spcond_int(int irq, void *data, struct pt_regs *fp)
490 struct scc_port *port = data;
491 struct tty_struct *tty = port->gs.tty;
492 unsigned char stat, ch, err;
493 int int_pending_mask = port->channel == CHANNEL_A ?
495 SCC_ACCESS_INIT(port);
498 printk(KERN_WARNING "scc_spcond_int with NULL tty!\n");
499 SCCwrite(COMMAND_REG, CR_ERROR_RESET);
500 SCCwrite_NB(COMMAND_REG, CR_HIGHEST_IUS_RESET);
504 stat = SCCread(SPCOND_STATUS_REG);
505 ch = SCCread_NB(RX_DATA_REG);
507 if (stat & SCSR_RX_OVERRUN)
509 else if (stat & SCSR_PARITY_ERR)
511 else if (stat & SCSR_CRC_FRAME_ERR)
516 if (tty->flip.count < TTY_FLIPBUF_SIZE) {
517 *tty->flip.char_buf_ptr = ch;
518 *tty->flip.flag_buf_ptr = err;
519 tty->flip.flag_buf_ptr++;
520 tty->flip.char_buf_ptr++;
524 /* ++TeSche: *All* errors have to be cleared manually,
525 * else the condition persists for the next chars
528 SCCwrite(COMMAND_REG, CR_ERROR_RESET);
530 } while(SCCread(INT_PENDING_REG) & int_pending_mask);
532 SCCwrite_NB(COMMAND_REG, CR_HIGHEST_IUS_RESET);
534 tty_flip_buffer_push(tty);
538 static void scc_tx_int(int irq, void *data, struct pt_regs *fp)
540 struct scc_port *port = data;
541 SCC_ACCESS_INIT(port);
544 printk(KERN_WARNING "scc_tx_int with NULL tty!\n");
545 SCCmod (INT_AND_DMA_REG, ~IDR_TX_INT_ENAB, 0);
546 SCCwrite(COMMAND_REG, CR_TX_PENDING_RESET);
547 SCCwrite_NB(COMMAND_REG, CR_HIGHEST_IUS_RESET);
550 while ((SCCread_NB(STATUS_REG) & SR_TX_BUF_EMPTY)) {
552 SCCwrite(TX_DATA_REG, port->x_char);
555 else if ((port->gs.xmit_cnt <= 0) || port->gs.tty->stopped ||
556 port->gs.tty->hw_stopped)
559 SCCwrite(TX_DATA_REG, port->gs.xmit_buf[port->gs.xmit_tail++]);
560 port->gs.xmit_tail = port->gs.xmit_tail & (SERIAL_XMIT_SIZE-1);
561 if (--port->gs.xmit_cnt <= 0)
565 if ((port->gs.xmit_cnt <= 0) || port->gs.tty->stopped ||
566 port->gs.tty->hw_stopped) {
567 /* disable tx interrupts */
568 SCCmod (INT_AND_DMA_REG, ~IDR_TX_INT_ENAB, 0);
569 SCCwrite(COMMAND_REG, CR_TX_PENDING_RESET); /* disable tx_int on next tx underrun? */
570 port->gs.flags &= ~GS_TX_INTEN;
572 if (port->gs.tty && port->gs.xmit_cnt <= port->gs.wakeup_chars) {
573 if ((port->gs.tty->flags & (1 << TTY_DO_WRITE_WAKEUP)) &&
574 port->gs.tty->ldisc.write_wakeup)
575 (port->gs.tty->ldisc.write_wakeup)(port->gs.tty);
576 wake_up_interruptible(&port->gs.tty->write_wait);
579 SCCwrite_NB(COMMAND_REG, CR_HIGHEST_IUS_RESET);
583 static void scc_stat_int(int irq, void *data, struct pt_regs *fp)
585 struct scc_port *port = data;
586 unsigned channel = port->channel;
587 unsigned char last_sr, sr, changed;
588 SCC_ACCESS_INIT(port);
590 last_sr = scc_last_status_reg[channel];
591 sr = scc_last_status_reg[channel] = SCCread_NB(STATUS_REG);
592 changed = last_sr ^ sr;
594 if (changed & SR_DCD) {
595 port->c_dcd = !!(sr & SR_DCD);
596 if (!(port->gs.flags & ASYNC_CHECK_CD))
597 ; /* Don't report DCD changes */
598 else if (port->c_dcd) {
599 if (~(port->gs.flags & ASYNC_NORMAL_ACTIVE) ||
600 ~(port->gs.flags & ASYNC_CALLOUT_ACTIVE)) {
601 /* Are we blocking in open?*/
602 wake_up_interruptible(&port->gs.open_wait);
606 if (!((port->gs.flags & ASYNC_CALLOUT_ACTIVE) &&
607 (port->gs.flags & ASYNC_CALLOUT_NOHUP))) {
609 tty_hangup (port->gs.tty);
613 SCCwrite(COMMAND_REG, CR_EXTSTAT_RESET);
614 SCCwrite_NB(COMMAND_REG, CR_HIGHEST_IUS_RESET);
618 /*---------------------------------------------------------------------------
619 * generic_serial.c callback funtions
620 *--------------------------------------------------------------------------*/
622 static void scc_disable_tx_interrupts(void *ptr)
624 struct scc_port *port = ptr;
626 SCC_ACCESS_INIT(port);
630 SCCmod(INT_AND_DMA_REG, ~IDR_TX_INT_ENAB, 0);
631 port->gs.flags &= ~GS_TX_INTEN;
632 restore_flags(flags);
636 static void scc_enable_tx_interrupts(void *ptr)
638 struct scc_port *port = ptr;
640 SCC_ACCESS_INIT(port);
644 SCCmod(INT_AND_DMA_REG, 0xff, IDR_TX_INT_ENAB);
645 /* restart the transmitter */
646 scc_tx_int (0, port, 0);
647 restore_flags(flags);
651 static void scc_disable_rx_interrupts(void *ptr)
653 struct scc_port *port = ptr;
655 SCC_ACCESS_INIT(port);
659 SCCmod(INT_AND_DMA_REG,
660 ~(IDR_RX_INT_MASK|IDR_PARERR_AS_SPCOND|IDR_EXTSTAT_INT_ENAB), 0);
661 restore_flags(flags);
665 static void scc_enable_rx_interrupts(void *ptr)
667 struct scc_port *port = ptr;
669 SCC_ACCESS_INIT(port);
673 SCCmod(INT_AND_DMA_REG, 0xff,
674 IDR_EXTSTAT_INT_ENAB|IDR_PARERR_AS_SPCOND|IDR_RX_INT_ALL);
675 restore_flags(flags);
679 static int scc_get_CD(void *ptr)
681 struct scc_port *port = ptr;
682 unsigned channel = port->channel;
684 return !!(scc_last_status_reg[channel] & SR_DCD);
688 static void scc_shutdown_port(void *ptr)
690 struct scc_port *port = ptr;
692 port->gs.flags &= ~ GS_ACTIVE;
693 if (port->gs.tty && port->gs.tty->termios->c_cflag & HUPCL) {
694 scc_setsignals (port, 0, 0);
699 static int scc_set_real_termios (void *ptr)
701 /* the SCC has char sizes 5,7,6,8 in that order! */
702 static int chsize_map[4] = { 0, 2, 1, 3 };
703 unsigned cflag, baud, chsize, channel, brgval = 0;
705 struct scc_port *port = ptr;
706 SCC_ACCESS_INIT(port);
708 if (!port->gs.tty || !port->gs.tty->termios) return 0;
710 channel = port->channel;
712 if (channel == CHANNEL_A)
713 return 0; /* Settings controlled by boot PROM */
715 cflag = port->gs.tty->termios->c_cflag;
716 baud = port->gs.baud;
717 chsize = (cflag & CSIZE) >> 4;
720 /* speed == 0 -> drop DTR */
723 SCCmod(TX_CTRL_REG, ~TCR_DTR, 0);
724 restore_flags(flags);
727 else if ((MACH_IS_MVME16x && (baud < 50 || baud > 38400)) ||
728 (MACH_IS_MVME147 && (baud < 50 || baud > 19200)) ||
729 (MACH_IS_BVME6000 &&(baud < 50 || baud > 76800))) {
730 printk(KERN_NOTICE "SCC: Bad speed requested, %d\n", baud);
735 port->gs.flags &= ~ASYNC_CHECK_CD;
737 port->gs.flags |= ASYNC_CHECK_CD;
739 #ifdef CONFIG_MVME147_SCC
741 brgval = (M147_SCC_PCLK + baud/2) / (16 * 2 * baud) - 2;
743 #ifdef CONFIG_MVME162_SCC
745 brgval = (MVME_SCC_PCLK + baud/2) / (16 * 2 * baud) - 2;
747 #ifdef CONFIG_BVME6000_SCC
748 if (MACH_IS_BVME6000)
749 brgval = (BVME_SCC_RTxC + baud/2) / (16 * 2 * baud) - 2;
751 /* Now we have all parameters and can go to set them: */
755 /* receiver's character size and auto-enables */
756 SCCmod(RX_CTRL_REG, ~(RCR_CHSIZE_MASK|RCR_AUTO_ENAB_MODE),
757 (chsize_map[chsize] << 6) |
758 ((cflag & CRTSCTS) ? RCR_AUTO_ENAB_MODE : 0));
759 /* parity and stop bits (both, Tx and Rx), clock mode never changes */
760 SCCmod (AUX1_CTRL_REG,
761 ~(A1CR_PARITY_MASK | A1CR_MODE_MASK),
763 ? (cflag & PARODD ? A1CR_PARITY_ODD : A1CR_PARITY_EVEN)
765 | (cflag & CSTOPB ? A1CR_MODE_ASYNC_2 : A1CR_MODE_ASYNC_1)));
766 /* sender's character size, set DTR for valid baud rate */
767 SCCmod(TX_CTRL_REG, ~TCR_CHSIZE_MASK, chsize_map[chsize] << 5 | TCR_DTR);
768 /* clock sources never change */
769 /* disable BRG before changing the value */
770 SCCmod(DPLL_CTRL_REG, ~DCR_BRG_ENAB, 0);
772 SCCwrite(TIMER_LOW_REG, brgval & 0xff);
773 SCCwrite(TIMER_HIGH_REG, (brgval >> 8) & 0xff);
774 /* BRG enable, and clock source never changes */
775 SCCmod(DPLL_CTRL_REG, 0xff, DCR_BRG_ENAB);
777 restore_flags(flags);
783 static int scc_chars_in_buffer (void *ptr)
785 struct scc_port *port = ptr;
786 SCC_ACCESS_INIT(port);
788 return (SCCread (SPCOND_STATUS_REG) & SCSR_ALL_SENT) ? 0 : 1;
792 /* Comment taken from sx.c (2.4.0):
793 I haven't the foggiest why the decrement use count has to happen
794 here. The whole linux serial drivers stuff needs to be redesigned.
795 My guess is that this is a hack to minimize the impact of a bug
796 elsewhere. Thinking about it some more. (try it sometime) Try
797 running minicom on a serial port that is driven by a modularized
798 driver. Have the modem hangup. Then remove the driver module. Then
799 exit minicom. I expect an "oops". -- REW */
801 static void scc_hungup(void *ptr)
803 scc_disable_tx_interrupts(ptr);
804 scc_disable_rx_interrupts(ptr);
809 static void scc_close(void *ptr)
811 scc_disable_tx_interrupts(ptr);
812 scc_disable_rx_interrupts(ptr);
817 /*---------------------------------------------------------------------------
818 * Internal support functions
819 *--------------------------------------------------------------------------*/
821 static void scc_setsignals(struct scc_port *port, int dtr, int rts)
825 SCC_ACCESS_INIT(port);
829 t = SCCread(TX_CTRL_REG);
830 if (dtr >= 0) t = dtr? (t | TCR_DTR): (t & ~TCR_DTR);
831 if (rts >= 0) t = rts? (t | TCR_RTS): (t & ~TCR_RTS);
832 SCCwrite(TX_CTRL_REG, t);
833 restore_flags(flags);
837 static void scc_send_xchar(struct tty_struct *tty, char ch)
839 struct scc_port *port = (struct scc_port *)tty->driver_data;
843 scc_enable_tx_interrupts(port);
847 /*---------------------------------------------------------------------------
848 * Driver entrypoints referenced from above
849 *--------------------------------------------------------------------------*/
851 static int scc_open (struct tty_struct * tty, struct file * filp)
853 int line = MINOR(tty->device) - SCC_MINOR_BASE;
855 struct scc_port *port = &scc_ports[line];
856 int i, channel = port->channel;
858 SCC_ACCESS_INIT(port);
859 #if defined(CONFIG_MVME162_SCC) || defined(CONFIG_MVME147_SCC)
860 static const struct {
862 } mvme_init_tab[] = {
863 /* Values for MVME162 and MVME147 */
864 /* no parity, 1 stop bit, async, 1:16 */
865 { AUX1_CTRL_REG, A1CR_PARITY_NONE|A1CR_MODE_ASYNC_1|A1CR_CLKMODE_x16 },
866 /* parity error is special cond, ints disabled, no DMA */
867 { INT_AND_DMA_REG, IDR_PARERR_AS_SPCOND | IDR_RX_INT_DISAB },
868 /* Rx 8 bits/char, no auto enable, Rx off */
869 { RX_CTRL_REG, RCR_CHSIZE_8 },
870 /* DTR off, Tx 8 bits/char, RTS off, Tx off */
871 { TX_CTRL_REG, TCR_CHSIZE_8 },
872 /* special features off */
873 { AUX2_CTRL_REG, 0 },
874 { CLK_CTRL_REG, CCR_RXCLK_BRG | CCR_TXCLK_BRG },
875 { DPLL_CTRL_REG, DCR_BRG_ENAB | DCR_BRG_USE_PCLK },
877 { RX_CTRL_REG, RCR_RX_ENAB | RCR_CHSIZE_8 },
879 { TX_CTRL_REG, TCR_TX_ENAB | TCR_RTS | TCR_DTR | TCR_CHSIZE_8 },
880 /* Ext/Stat ints: DCD only */
881 { INT_CTRL_REG, ICR_ENAB_DCD_INT },
882 /* Reset Ext/Stat ints */
883 { COMMAND_REG, CR_EXTSTAT_RESET },
885 { COMMAND_REG, CR_EXTSTAT_RESET },
888 #if defined(CONFIG_BVME6000_SCC)
889 static const struct {
891 } bvme_init_tab[] = {
892 /* Values for BVME6000 */
893 /* no parity, 1 stop bit, async, 1:16 */
894 { AUX1_CTRL_REG, A1CR_PARITY_NONE|A1CR_MODE_ASYNC_1|A1CR_CLKMODE_x16 },
895 /* parity error is special cond, ints disabled, no DMA */
896 { INT_AND_DMA_REG, IDR_PARERR_AS_SPCOND | IDR_RX_INT_DISAB },
897 /* Rx 8 bits/char, no auto enable, Rx off */
898 { RX_CTRL_REG, RCR_CHSIZE_8 },
899 /* DTR off, Tx 8 bits/char, RTS off, Tx off */
900 { TX_CTRL_REG, TCR_CHSIZE_8 },
901 /* special features off */
902 { AUX2_CTRL_REG, 0 },
903 { CLK_CTRL_REG, CCR_RTxC_XTAL | CCR_RXCLK_BRG | CCR_TXCLK_BRG },
904 { DPLL_CTRL_REG, DCR_BRG_ENAB },
906 { RX_CTRL_REG, RCR_RX_ENAB | RCR_CHSIZE_8 },
908 { TX_CTRL_REG, TCR_TX_ENAB | TCR_RTS | TCR_DTR | TCR_CHSIZE_8 },
909 /* Ext/Stat ints: DCD only */
910 { INT_CTRL_REG, ICR_ENAB_DCD_INT },
911 /* Reset Ext/Stat ints */
912 { COMMAND_REG, CR_EXTSTAT_RESET },
914 { COMMAND_REG, CR_EXTSTAT_RESET },
917 if (!(port->gs.flags & ASYNC_INITIALIZED)) {
920 #if defined(CONFIG_MVME147_SCC) || defined(CONFIG_MVME162_SCC)
921 if (MACH_IS_MVME147 || MACH_IS_MVME16x) {
922 for (i=0; i<sizeof(mvme_init_tab)/sizeof(*mvme_init_tab); ++i)
923 SCCwrite(mvme_init_tab[i].reg, mvme_init_tab[i].val);
926 #if defined(CONFIG_BVME6000_SCC)
927 if (MACH_IS_BVME6000) {
928 for (i=0; i<sizeof(bvme_init_tab)/sizeof(*bvme_init_tab); ++i)
929 SCCwrite(bvme_init_tab[i].reg, bvme_init_tab[i].val);
933 /* remember status register for detection of DCD and CTS changes */
934 scc_last_status_reg[channel] = SCCread(STATUS_REG);
936 port->c_dcd = 0; /* Prevent initial 1->0 interrupt */
937 scc_setsignals (port, 1,1);
938 restore_flags(flags);
941 tty->driver_data = port;
944 retval = gs_init_port(&port->gs);
949 port->gs.flags |= GS_ACTIVE;
950 if (port->gs.count == 1) {
953 retval = gs_block_til_ready(port, filp);
961 if ((port->gs.count == 1) && (port->gs.flags & ASYNC_SPLIT_TERMIOS)) {
962 if (tty->driver.subtype == SERIAL_TYPE_NORMAL)
963 *tty->termios = port->gs.normal_termios;
965 *tty->termios = port->gs.callout_termios;
966 scc_set_real_termios (port);
969 port->gs.session = current->session;
970 port->gs.pgrp = current->pgrp;
971 port->c_dcd = scc_get_CD (port);
973 scc_enable_rx_interrupts(port);
979 static void scc_throttle (struct tty_struct * tty)
981 struct scc_port *port = (struct scc_port *)tty->driver_data;
983 SCC_ACCESS_INIT(port);
985 if (tty->termios->c_cflag & CRTSCTS) {
988 SCCmod(TX_CTRL_REG, ~TCR_RTS, 0);
989 restore_flags(flags);
992 scc_send_xchar(tty, STOP_CHAR(tty));
996 static void scc_unthrottle (struct tty_struct * tty)
998 struct scc_port *port = (struct scc_port *)tty->driver_data;
1000 SCC_ACCESS_INIT(port);
1002 if (tty->termios->c_cflag & CRTSCTS) {
1005 SCCmod(TX_CTRL_REG, 0xff, TCR_RTS);
1006 restore_flags(flags);
1009 scc_send_xchar(tty, START_CHAR(tty));
1013 static int scc_ioctl(struct tty_struct *tty, struct file *file,
1014 unsigned int cmd, unsigned long arg)
1016 return -ENOIOCTLCMD;
1020 static void scc_break_ctl(struct tty_struct *tty, int break_state)
1022 struct scc_port *port = (struct scc_port *)tty->driver_data;
1023 unsigned long flags;
1024 SCC_ACCESS_INIT(port);
1028 SCCmod(TX_CTRL_REG, ~TCR_SEND_BREAK,
1029 break_state ? TCR_SEND_BREAK : 0);
1030 restore_flags(flags);
1034 /*---------------------------------------------------------------------------
1035 * Serial console stuff...
1036 *--------------------------------------------------------------------------*/
1038 #define scc_delay() do { __asm__ __volatile__ (" nop; nop"); } while (0)
1040 static void scc_ch_write (char ch)
1042 volatile char *p = NULL;
1044 #ifdef CONFIG_MVME147_SCC
1045 if (MACH_IS_MVME147)
1046 p = (volatile char *)M147_SCC_A_ADDR;
1048 #ifdef CONFIG_MVME162_SCC
1049 if (MACH_IS_MVME16x)
1050 p = (volatile char *)MVME_SCC_A_ADDR;
1052 #ifdef CONFIG_BVME6000_SCC
1053 if (MACH_IS_BVME6000)
1054 p = (volatile char *)BVME_SCC_A_ADDR;
1067 /* The console must be locked when we get here. */
1069 static void scc_console_write (struct console *co, const char *str, unsigned count)
1071 unsigned long flags;
1079 scc_ch_write ('\r');
1080 scc_ch_write (*str++);
1082 restore_flags(flags);
1085 static kdev_t scc_console_device(struct console *c)
1087 return MKDEV(TTY_MAJOR, SCC_MINOR_BASE + c->index);
1091 static int __init scc_console_setup(struct console *co, char *options)
1097 static struct console sercons = {
1099 write: scc_console_write,
1100 device: scc_console_device,
1101 setup: scc_console_setup,
1102 flags: CON_PRINTBUFFER,
1107 void __init vme_scc_console_init(void)
1109 if (vme_brdtype == VME_TYPE_MVME147 ||
1110 vme_brdtype == VME_TYPE_MVME162 ||
1111 vme_brdtype == VME_TYPE_MVME172 ||
1112 vme_brdtype == VME_TYPE_BVME4000 ||
1113 vme_brdtype == VME_TYPE_BVME6000)
1114 register_console(&sercons);