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 int 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.port.open_wait);
187 init_waitqueue_head(&port->gs.port.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.port.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.port.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);
503 if (!port->gs.port.tty) {
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) ||
516 port->gs.port.tty->stopped ||
517 port->gs.port.tty->hw_stopped)
520 SCCwrite(TX_DATA_REG, port->gs.xmit_buf[port->gs.xmit_tail++]);
521 port->gs.xmit_tail = port->gs.xmit_tail & (SERIAL_XMIT_SIZE-1);
522 if (--port->gs.xmit_cnt <= 0)
526 if ((port->gs.xmit_cnt <= 0) || port->gs.port.tty->stopped ||
527 port->gs.port.tty->hw_stopped) {
528 /* disable tx interrupts */
529 SCCmod (INT_AND_DMA_REG, ~IDR_TX_INT_ENAB, 0);
530 SCCwrite(COMMAND_REG, CR_TX_PENDING_RESET); /* disable tx_int on next tx underrun? */
531 port->gs.port.flags &= ~GS_TX_INTEN;
533 if (port->gs.port.tty && port->gs.xmit_cnt <= port->gs.wakeup_chars)
534 tty_wakeup(port->gs.port.tty);
536 SCCwrite_NB(COMMAND_REG, CR_HIGHEST_IUS_RESET);
541 static irqreturn_t scc_stat_int(int irq, void *data)
543 struct scc_port *port = data;
544 unsigned channel = port->channel;
545 unsigned char last_sr, sr, changed;
546 SCC_ACCESS_INIT(port);
548 last_sr = scc_last_status_reg[channel];
549 sr = scc_last_status_reg[channel] = SCCread_NB(STATUS_REG);
550 changed = last_sr ^ sr;
552 if (changed & SR_DCD) {
553 port->c_dcd = !!(sr & SR_DCD);
554 if (!(port->gs.port.flags & ASYNC_CHECK_CD))
555 ; /* Don't report DCD changes */
556 else if (port->c_dcd) {
557 wake_up_interruptible(&port->gs.port.open_wait);
560 if (port->gs.port.tty)
561 tty_hangup (port->gs.port.tty);
564 SCCwrite(COMMAND_REG, CR_EXTSTAT_RESET);
565 SCCwrite_NB(COMMAND_REG, CR_HIGHEST_IUS_RESET);
570 /*---------------------------------------------------------------------------
571 * generic_serial.c callback funtions
572 *--------------------------------------------------------------------------*/
574 static void scc_disable_tx_interrupts(void *ptr)
576 struct scc_port *port = ptr;
578 SCC_ACCESS_INIT(port);
580 local_irq_save(flags);
581 SCCmod(INT_AND_DMA_REG, ~IDR_TX_INT_ENAB, 0);
582 port->gs.port.flags &= ~GS_TX_INTEN;
583 local_irq_restore(flags);
587 static void scc_enable_tx_interrupts(void *ptr)
589 struct scc_port *port = ptr;
591 SCC_ACCESS_INIT(port);
593 local_irq_save(flags);
594 SCCmod(INT_AND_DMA_REG, 0xff, IDR_TX_INT_ENAB);
595 /* restart the transmitter */
596 scc_tx_int (0, port);
597 local_irq_restore(flags);
601 static void scc_disable_rx_interrupts(void *ptr)
603 struct scc_port *port = ptr;
605 SCC_ACCESS_INIT(port);
607 local_irq_save(flags);
608 SCCmod(INT_AND_DMA_REG,
609 ~(IDR_RX_INT_MASK|IDR_PARERR_AS_SPCOND|IDR_EXTSTAT_INT_ENAB), 0);
610 local_irq_restore(flags);
614 static void scc_enable_rx_interrupts(void *ptr)
616 struct scc_port *port = ptr;
618 SCC_ACCESS_INIT(port);
620 local_irq_save(flags);
621 SCCmod(INT_AND_DMA_REG, 0xff,
622 IDR_EXTSTAT_INT_ENAB|IDR_PARERR_AS_SPCOND|IDR_RX_INT_ALL);
623 local_irq_restore(flags);
627 static int scc_get_CD(void *ptr)
629 struct scc_port *port = ptr;
630 unsigned channel = port->channel;
632 return !!(scc_last_status_reg[channel] & SR_DCD);
636 static void scc_shutdown_port(void *ptr)
638 struct scc_port *port = ptr;
640 port->gs.port.flags &= ~ GS_ACTIVE;
641 if (port->gs.port.tty && port->gs.port.tty->termios->c_cflag & HUPCL) {
642 scc_setsignals (port, 0, 0);
647 static int scc_set_real_termios (void *ptr)
649 /* the SCC has char sizes 5,7,6,8 in that order! */
650 static int chsize_map[4] = { 0, 2, 1, 3 };
651 unsigned cflag, baud, chsize, channel, brgval = 0;
653 struct scc_port *port = ptr;
654 SCC_ACCESS_INIT(port);
656 if (!port->gs.port.tty || !port->gs.port.tty->termios) return 0;
658 channel = port->channel;
660 if (channel == CHANNEL_A)
661 return 0; /* Settings controlled by boot PROM */
663 cflag = port->gs.port.tty->termios->c_cflag;
664 baud = port->gs.baud;
665 chsize = (cflag & CSIZE) >> 4;
668 /* speed == 0 -> drop DTR */
669 local_irq_save(flags);
670 SCCmod(TX_CTRL_REG, ~TCR_DTR, 0);
671 local_irq_restore(flags);
674 else if ((MACH_IS_MVME16x && (baud < 50 || baud > 38400)) ||
675 (MACH_IS_MVME147 && (baud < 50 || baud > 19200)) ||
676 (MACH_IS_BVME6000 &&(baud < 50 || baud > 76800))) {
677 printk(KERN_NOTICE "SCC: Bad speed requested, %d\n", baud);
682 port->gs.port.flags &= ~ASYNC_CHECK_CD;
684 port->gs.port.flags |= ASYNC_CHECK_CD;
686 #ifdef CONFIG_MVME147_SCC
688 brgval = (M147_SCC_PCLK + baud/2) / (16 * 2 * baud) - 2;
690 #ifdef CONFIG_MVME162_SCC
692 brgval = (MVME_SCC_PCLK + baud/2) / (16 * 2 * baud) - 2;
694 #ifdef CONFIG_BVME6000_SCC
695 if (MACH_IS_BVME6000)
696 brgval = (BVME_SCC_RTxC + baud/2) / (16 * 2 * baud) - 2;
698 /* Now we have all parameters and can go to set them: */
699 local_irq_save(flags);
701 /* receiver's character size and auto-enables */
702 SCCmod(RX_CTRL_REG, ~(RCR_CHSIZE_MASK|RCR_AUTO_ENAB_MODE),
703 (chsize_map[chsize] << 6) |
704 ((cflag & CRTSCTS) ? RCR_AUTO_ENAB_MODE : 0));
705 /* parity and stop bits (both, Tx and Rx), clock mode never changes */
706 SCCmod (AUX1_CTRL_REG,
707 ~(A1CR_PARITY_MASK | A1CR_MODE_MASK),
709 ? (cflag & PARODD ? A1CR_PARITY_ODD : A1CR_PARITY_EVEN)
711 | (cflag & CSTOPB ? A1CR_MODE_ASYNC_2 : A1CR_MODE_ASYNC_1)));
712 /* sender's character size, set DTR for valid baud rate */
713 SCCmod(TX_CTRL_REG, ~TCR_CHSIZE_MASK, chsize_map[chsize] << 5 | TCR_DTR);
714 /* clock sources never change */
715 /* disable BRG before changing the value */
716 SCCmod(DPLL_CTRL_REG, ~DCR_BRG_ENAB, 0);
718 SCCwrite(TIMER_LOW_REG, brgval & 0xff);
719 SCCwrite(TIMER_HIGH_REG, (brgval >> 8) & 0xff);
720 /* BRG enable, and clock source never changes */
721 SCCmod(DPLL_CTRL_REG, 0xff, DCR_BRG_ENAB);
723 local_irq_restore(flags);
729 static int scc_chars_in_buffer (void *ptr)
731 struct scc_port *port = ptr;
732 SCC_ACCESS_INIT(port);
734 return (SCCread (SPCOND_STATUS_REG) & SCSR_ALL_SENT) ? 0 : 1;
738 /* Comment taken from sx.c (2.4.0):
739 I haven't the foggiest why the decrement use count has to happen
740 here. The whole linux serial drivers stuff needs to be redesigned.
741 My guess is that this is a hack to minimize the impact of a bug
742 elsewhere. Thinking about it some more. (try it sometime) Try
743 running minicom on a serial port that is driven by a modularized
744 driver. Have the modem hangup. Then remove the driver module. Then
745 exit minicom. I expect an "oops". -- REW */
747 static void scc_hungup(void *ptr)
749 scc_disable_tx_interrupts(ptr);
750 scc_disable_rx_interrupts(ptr);
754 static void scc_close(void *ptr)
756 scc_disable_tx_interrupts(ptr);
757 scc_disable_rx_interrupts(ptr);
761 /*---------------------------------------------------------------------------
762 * Internal support functions
763 *--------------------------------------------------------------------------*/
765 static void scc_setsignals(struct scc_port *port, int dtr, int rts)
769 SCC_ACCESS_INIT(port);
771 local_irq_save(flags);
772 t = SCCread(TX_CTRL_REG);
773 if (dtr >= 0) t = dtr? (t | TCR_DTR): (t & ~TCR_DTR);
774 if (rts >= 0) t = rts? (t | TCR_RTS): (t & ~TCR_RTS);
775 SCCwrite(TX_CTRL_REG, t);
776 local_irq_restore(flags);
780 static void scc_send_xchar(struct tty_struct *tty, char ch)
782 struct scc_port *port = (struct scc_port *)tty->driver_data;
786 scc_enable_tx_interrupts(port);
790 /*---------------------------------------------------------------------------
791 * Driver entrypoints referenced from above
792 *--------------------------------------------------------------------------*/
794 static int scc_open (struct tty_struct * tty, struct file * filp)
796 int line = tty->index;
798 struct scc_port *port = &scc_ports[line];
799 int i, channel = port->channel;
801 SCC_ACCESS_INIT(port);
802 #if defined(CONFIG_MVME162_SCC) || defined(CONFIG_MVME147_SCC)
803 static const struct {
805 } mvme_init_tab[] = {
806 /* Values for MVME162 and MVME147 */
807 /* no parity, 1 stop bit, async, 1:16 */
808 { AUX1_CTRL_REG, A1CR_PARITY_NONE|A1CR_MODE_ASYNC_1|A1CR_CLKMODE_x16 },
809 /* parity error is special cond, ints disabled, no DMA */
810 { INT_AND_DMA_REG, IDR_PARERR_AS_SPCOND | IDR_RX_INT_DISAB },
811 /* Rx 8 bits/char, no auto enable, Rx off */
812 { RX_CTRL_REG, RCR_CHSIZE_8 },
813 /* DTR off, Tx 8 bits/char, RTS off, Tx off */
814 { TX_CTRL_REG, TCR_CHSIZE_8 },
815 /* special features off */
816 { AUX2_CTRL_REG, 0 },
817 { CLK_CTRL_REG, CCR_RXCLK_BRG | CCR_TXCLK_BRG },
818 { DPLL_CTRL_REG, DCR_BRG_ENAB | DCR_BRG_USE_PCLK },
820 { RX_CTRL_REG, RCR_RX_ENAB | RCR_CHSIZE_8 },
822 { TX_CTRL_REG, TCR_TX_ENAB | TCR_RTS | TCR_DTR | TCR_CHSIZE_8 },
823 /* Ext/Stat ints: DCD only */
824 { INT_CTRL_REG, ICR_ENAB_DCD_INT },
825 /* Reset Ext/Stat ints */
826 { COMMAND_REG, CR_EXTSTAT_RESET },
828 { COMMAND_REG, CR_EXTSTAT_RESET },
831 #if defined(CONFIG_BVME6000_SCC)
832 static const struct {
834 } bvme_init_tab[] = {
835 /* Values for BVME6000 */
836 /* no parity, 1 stop bit, async, 1:16 */
837 { AUX1_CTRL_REG, A1CR_PARITY_NONE|A1CR_MODE_ASYNC_1|A1CR_CLKMODE_x16 },
838 /* parity error is special cond, ints disabled, no DMA */
839 { INT_AND_DMA_REG, IDR_PARERR_AS_SPCOND | IDR_RX_INT_DISAB },
840 /* Rx 8 bits/char, no auto enable, Rx off */
841 { RX_CTRL_REG, RCR_CHSIZE_8 },
842 /* DTR off, Tx 8 bits/char, RTS off, Tx off */
843 { TX_CTRL_REG, TCR_CHSIZE_8 },
844 /* special features off */
845 { AUX2_CTRL_REG, 0 },
846 { CLK_CTRL_REG, CCR_RTxC_XTAL | CCR_RXCLK_BRG | CCR_TXCLK_BRG },
847 { DPLL_CTRL_REG, DCR_BRG_ENAB },
849 { RX_CTRL_REG, RCR_RX_ENAB | RCR_CHSIZE_8 },
851 { TX_CTRL_REG, TCR_TX_ENAB | TCR_RTS | TCR_DTR | TCR_CHSIZE_8 },
852 /* Ext/Stat ints: DCD only */
853 { INT_CTRL_REG, ICR_ENAB_DCD_INT },
854 /* Reset Ext/Stat ints */
855 { COMMAND_REG, CR_EXTSTAT_RESET },
857 { COMMAND_REG, CR_EXTSTAT_RESET },
860 if (!(port->gs.port.flags & ASYNC_INITIALIZED)) {
861 local_irq_save(flags);
862 #if defined(CONFIG_MVME147_SCC) || defined(CONFIG_MVME162_SCC)
863 if (MACH_IS_MVME147 || MACH_IS_MVME16x) {
864 for (i = 0; i < ARRAY_SIZE(mvme_init_tab); ++i)
865 SCCwrite(mvme_init_tab[i].reg, mvme_init_tab[i].val);
868 #if defined(CONFIG_BVME6000_SCC)
869 if (MACH_IS_BVME6000) {
870 for (i = 0; i < ARRAY_SIZE(bvme_init_tab); ++i)
871 SCCwrite(bvme_init_tab[i].reg, bvme_init_tab[i].val);
875 /* remember status register for detection of DCD and CTS changes */
876 scc_last_status_reg[channel] = SCCread(STATUS_REG);
878 port->c_dcd = 0; /* Prevent initial 1->0 interrupt */
879 scc_setsignals (port, 1,1);
880 local_irq_restore(flags);
883 tty->driver_data = port;
884 port->gs.port.tty = tty;
885 port->gs.port.count++;
886 retval = gs_init_port(&port->gs);
888 port->gs.port.count--;
891 port->gs.port.flags |= GS_ACTIVE;
892 retval = gs_block_til_ready(port, filp);
895 port->gs.port.count--;
899 port->c_dcd = scc_get_CD (port);
901 scc_enable_rx_interrupts(port);
907 static void scc_throttle (struct tty_struct * tty)
909 struct scc_port *port = (struct scc_port *)tty->driver_data;
911 SCC_ACCESS_INIT(port);
913 if (tty->termios->c_cflag & CRTSCTS) {
914 local_irq_save(flags);
915 SCCmod(TX_CTRL_REG, ~TCR_RTS, 0);
916 local_irq_restore(flags);
919 scc_send_xchar(tty, STOP_CHAR(tty));
923 static void scc_unthrottle (struct tty_struct * tty)
925 struct scc_port *port = (struct scc_port *)tty->driver_data;
927 SCC_ACCESS_INIT(port);
929 if (tty->termios->c_cflag & CRTSCTS) {
930 local_irq_save(flags);
931 SCCmod(TX_CTRL_REG, 0xff, TCR_RTS);
932 local_irq_restore(flags);
935 scc_send_xchar(tty, START_CHAR(tty));
939 static int scc_ioctl(struct tty_struct *tty, struct file *file,
940 unsigned int cmd, unsigned long arg)
946 static int scc_break_ctl(struct tty_struct *tty, int break_state)
948 struct scc_port *port = (struct scc_port *)tty->driver_data;
950 SCC_ACCESS_INIT(port);
952 local_irq_save(flags);
953 SCCmod(TX_CTRL_REG, ~TCR_SEND_BREAK,
954 break_state ? TCR_SEND_BREAK : 0);
955 local_irq_restore(flags);
960 /*---------------------------------------------------------------------------
961 * Serial console stuff...
962 *--------------------------------------------------------------------------*/
964 #define scc_delay() do { __asm__ __volatile__ (" nop; nop"); } while (0)
966 static void scc_ch_write (char ch)
968 volatile char *p = NULL;
970 #ifdef CONFIG_MVME147_SCC
972 p = (volatile char *)M147_SCC_A_ADDR;
974 #ifdef CONFIG_MVME162_SCC
976 p = (volatile char *)MVME_SCC_A_ADDR;
978 #ifdef CONFIG_BVME6000_SCC
979 if (MACH_IS_BVME6000)
980 p = (volatile char *)BVME_SCC_A_ADDR;
993 /* The console must be locked when we get here. */
995 static void scc_console_write (struct console *co, const char *str, unsigned count)
999 local_irq_save(flags);
1004 scc_ch_write ('\r');
1005 scc_ch_write (*str++);
1007 local_irq_restore(flags);
1010 static struct tty_driver *scc_console_device(struct console *c, int *index)
1016 static struct console sercons = {
1018 .write = scc_console_write,
1019 .device = scc_console_device,
1020 .flags = CON_PRINTBUFFER,
1025 static int __init vme_scc_console_init(void)
1027 if (vme_brdtype == VME_TYPE_MVME147 ||
1028 vme_brdtype == VME_TYPE_MVME162 ||
1029 vme_brdtype == VME_TYPE_MVME172 ||
1030 vme_brdtype == VME_TYPE_BVME4000 ||
1031 vme_brdtype == VME_TYPE_BVME6000)
1032 register_console(&sercons);
1035 console_initcall(vme_scc_console_init);