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_carrier_raised(struct tty_port *port);
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,
104 scc_set_real_termios,
112 static const struct tty_operations scc_ops = {
116 .put_char = gs_put_char,
117 .flush_chars = gs_flush_chars,
118 .write_room = gs_write_room,
119 .chars_in_buffer = gs_chars_in_buffer,
120 .flush_buffer = gs_flush_buffer,
122 .throttle = scc_throttle,
123 .unthrottle = scc_unthrottle,
124 .set_termios = gs_set_termios,
128 .break_ctl = scc_break_ctl,
131 static const struct tty_port_operations scc_port_ops = {
132 .carrier_raised = scc_carrier_raised,
135 /*----------------------------------------------------------------------------
136 * vme_scc_init() and support functions
137 *---------------------------------------------------------------------------*/
139 static int scc_init_drivers(void)
143 scc_driver = alloc_tty_driver(2);
146 scc_driver->owner = THIS_MODULE;
147 scc_driver->driver_name = "scc";
148 scc_driver->name = "ttyS";
149 scc_driver->major = TTY_MAJOR;
150 scc_driver->minor_start = SCC_MINOR_BASE;
151 scc_driver->type = TTY_DRIVER_TYPE_SERIAL;
152 scc_driver->subtype = SERIAL_TYPE_NORMAL;
153 scc_driver->init_termios = tty_std_termios;
154 scc_driver->init_termios.c_cflag =
155 B9600 | CS8 | CREAD | HUPCL | CLOCAL;
156 scc_driver->init_termios.c_ispeed = 9600;
157 scc_driver->init_termios.c_ospeed = 9600;
158 scc_driver->flags = TTY_DRIVER_REAL_RAW;
159 tty_set_operations(scc_driver, &scc_ops);
161 if ((error = tty_register_driver(scc_driver))) {
162 printk(KERN_ERR "scc: Couldn't register scc driver, error = %d\n",
164 put_tty_driver(scc_driver);
172 /* ports[] array is indexed by line no (i.e. [0] for ttyS0, [1] for ttyS1).
175 static void scc_init_portstructs(void)
177 struct scc_port *port;
180 for (i = 0; i < 2; i++) {
181 port = scc_ports + i;
182 tty_port_init(&port->gs.port);
183 port->gs.port.ops = &scc_port_ops;
184 port->gs.magic = SCC_MAGIC;
185 port->gs.close_delay = HZ/2;
186 port->gs.closing_wait = 30 * HZ;
187 port->gs.rd = &scc_real_driver;
188 #ifdef NEW_WRITE_LOCKING
189 port->gs.port_write_mutex = MUTEX;
191 init_waitqueue_head(&port->gs.port.open_wait);
192 init_waitqueue_head(&port->gs.port.close_wait);
197 #ifdef CONFIG_MVME147_SCC
198 static int mvme147_scc_init(void)
200 struct scc_port *port;
202 printk(KERN_INFO "SCC: MVME147 Serial Driver\n");
204 port = &scc_ports[0];
205 port->channel = CHANNEL_A;
206 port->ctrlp = (volatile unsigned char *)M147_SCC_A_ADDR;
207 port->datap = port->ctrlp + 1;
208 port->port_a = &scc_ports[0];
209 port->port_b = &scc_ports[1];
210 request_irq(MVME147_IRQ_SCCA_TX, scc_tx_int, IRQF_DISABLED,
212 request_irq(MVME147_IRQ_SCCA_STAT, scc_stat_int, IRQF_DISABLED,
213 "SCC-A status", port);
214 request_irq(MVME147_IRQ_SCCA_RX, scc_rx_int, IRQF_DISABLED,
216 request_irq(MVME147_IRQ_SCCA_SPCOND, scc_spcond_int, IRQF_DISABLED,
217 "SCC-A special cond", port);
219 SCC_ACCESS_INIT(port);
221 /* disable interrupts for this channel */
222 SCCwrite(INT_AND_DMA_REG, 0);
223 /* Set the interrupt vector */
224 SCCwrite(INT_VECTOR_REG, MVME147_IRQ_SCC_BASE);
225 /* Interrupt parameters: vector includes status, status low */
226 SCCwrite(MASTER_INT_CTRL, MIC_VEC_INCL_STAT);
227 SCCmod(MASTER_INT_CTRL, 0xff, MIC_MASTER_INT_ENAB);
231 port = &scc_ports[1];
232 port->channel = CHANNEL_B;
233 port->ctrlp = (volatile unsigned char *)M147_SCC_B_ADDR;
234 port->datap = port->ctrlp + 1;
235 port->port_a = &scc_ports[0];
236 port->port_b = &scc_ports[1];
237 request_irq(MVME147_IRQ_SCCB_TX, scc_tx_int, IRQF_DISABLED,
239 request_irq(MVME147_IRQ_SCCB_STAT, scc_stat_int, IRQF_DISABLED,
240 "SCC-B status", port);
241 request_irq(MVME147_IRQ_SCCB_RX, scc_rx_int, IRQF_DISABLED,
243 request_irq(MVME147_IRQ_SCCB_SPCOND, scc_spcond_int, IRQF_DISABLED,
244 "SCC-B special cond", port);
246 SCC_ACCESS_INIT(port);
248 /* disable interrupts for this channel */
249 SCCwrite(INT_AND_DMA_REG, 0);
252 /* Ensure interrupts are enabled in the PCC chip */
253 m147_pcc->serial_cntrl=PCC_LEVEL_SERIAL|PCC_INT_ENAB;
255 /* Initialise the tty driver structures and register */
256 scc_init_portstructs();
264 #ifdef CONFIG_MVME162_SCC
265 static int mvme162_scc_init(void)
267 struct scc_port *port;
269 if (!(mvme16x_config & MVME16x_CONFIG_GOT_SCCA))
272 printk(KERN_INFO "SCC: MVME162 Serial Driver\n");
274 port = &scc_ports[0];
275 port->channel = CHANNEL_A;
276 port->ctrlp = (volatile unsigned char *)MVME_SCC_A_ADDR;
277 port->datap = port->ctrlp + 2;
278 port->port_a = &scc_ports[0];
279 port->port_b = &scc_ports[1];
280 request_irq(MVME162_IRQ_SCCA_TX, scc_tx_int, IRQF_DISABLED,
282 request_irq(MVME162_IRQ_SCCA_STAT, scc_stat_int, IRQF_DISABLED,
283 "SCC-A status", port);
284 request_irq(MVME162_IRQ_SCCA_RX, scc_rx_int, IRQF_DISABLED,
286 request_irq(MVME162_IRQ_SCCA_SPCOND, scc_spcond_int, IRQF_DISABLED,
287 "SCC-A special cond", port);
289 SCC_ACCESS_INIT(port);
291 /* disable interrupts for this channel */
292 SCCwrite(INT_AND_DMA_REG, 0);
293 /* Set the interrupt vector */
294 SCCwrite(INT_VECTOR_REG, MVME162_IRQ_SCC_BASE);
295 /* Interrupt parameters: vector includes status, status low */
296 SCCwrite(MASTER_INT_CTRL, MIC_VEC_INCL_STAT);
297 SCCmod(MASTER_INT_CTRL, 0xff, MIC_MASTER_INT_ENAB);
301 port = &scc_ports[1];
302 port->channel = CHANNEL_B;
303 port->ctrlp = (volatile unsigned char *)MVME_SCC_B_ADDR;
304 port->datap = port->ctrlp + 2;
305 port->port_a = &scc_ports[0];
306 port->port_b = &scc_ports[1];
307 request_irq(MVME162_IRQ_SCCB_TX, scc_tx_int, IRQF_DISABLED,
309 request_irq(MVME162_IRQ_SCCB_STAT, scc_stat_int, IRQF_DISABLED,
310 "SCC-B status", port);
311 request_irq(MVME162_IRQ_SCCB_RX, scc_rx_int, IRQF_DISABLED,
313 request_irq(MVME162_IRQ_SCCB_SPCOND, scc_spcond_int, IRQF_DISABLED,
314 "SCC-B special cond", port);
317 SCC_ACCESS_INIT(port); /* Either channel will do */
319 /* disable interrupts for this channel */
320 SCCwrite(INT_AND_DMA_REG, 0);
323 /* Ensure interrupts are enabled in the MC2 chip */
324 *(volatile char *)0xfff4201d = 0x14;
326 /* Initialise the tty driver structures and register */
327 scc_init_portstructs();
335 #ifdef CONFIG_BVME6000_SCC
336 static int bvme6000_scc_init(void)
338 struct scc_port *port;
340 printk(KERN_INFO "SCC: BVME6000 Serial Driver\n");
342 port = &scc_ports[0];
343 port->channel = CHANNEL_A;
344 port->ctrlp = (volatile unsigned char *)BVME_SCC_A_ADDR;
345 port->datap = port->ctrlp + 4;
346 port->port_a = &scc_ports[0];
347 port->port_b = &scc_ports[1];
348 request_irq(BVME_IRQ_SCCA_TX, scc_tx_int, IRQF_DISABLED,
350 request_irq(BVME_IRQ_SCCA_STAT, scc_stat_int, IRQF_DISABLED,
351 "SCC-A status", port);
352 request_irq(BVME_IRQ_SCCA_RX, scc_rx_int, IRQF_DISABLED,
354 request_irq(BVME_IRQ_SCCA_SPCOND, scc_spcond_int, IRQF_DISABLED,
355 "SCC-A special cond", port);
357 SCC_ACCESS_INIT(port);
359 /* disable interrupts for this channel */
360 SCCwrite(INT_AND_DMA_REG, 0);
361 /* Set the interrupt vector */
362 SCCwrite(INT_VECTOR_REG, BVME_IRQ_SCC_BASE);
363 /* Interrupt parameters: vector includes status, status low */
364 SCCwrite(MASTER_INT_CTRL, MIC_VEC_INCL_STAT);
365 SCCmod(MASTER_INT_CTRL, 0xff, MIC_MASTER_INT_ENAB);
369 port = &scc_ports[1];
370 port->channel = CHANNEL_B;
371 port->ctrlp = (volatile unsigned char *)BVME_SCC_B_ADDR;
372 port->datap = port->ctrlp + 4;
373 port->port_a = &scc_ports[0];
374 port->port_b = &scc_ports[1];
375 request_irq(BVME_IRQ_SCCB_TX, scc_tx_int, IRQF_DISABLED,
377 request_irq(BVME_IRQ_SCCB_STAT, scc_stat_int, IRQF_DISABLED,
378 "SCC-B status", port);
379 request_irq(BVME_IRQ_SCCB_RX, scc_rx_int, IRQF_DISABLED,
381 request_irq(BVME_IRQ_SCCB_SPCOND, scc_spcond_int, IRQF_DISABLED,
382 "SCC-B special cond", port);
385 SCC_ACCESS_INIT(port); /* Either channel will do */
387 /* disable interrupts for this channel */
388 SCCwrite(INT_AND_DMA_REG, 0);
391 /* Initialise the tty driver structures and register */
392 scc_init_portstructs();
400 static int vme_scc_init(void)
404 #ifdef CONFIG_MVME147_SCC
406 res = mvme147_scc_init();
408 #ifdef CONFIG_MVME162_SCC
410 res = mvme162_scc_init();
412 #ifdef CONFIG_BVME6000_SCC
413 if (MACH_IS_BVME6000)
414 res = bvme6000_scc_init();
419 module_init(vme_scc_init);
422 /*---------------------------------------------------------------------------
424 *--------------------------------------------------------------------------*/
426 static irqreturn_t scc_rx_int(int irq, void *data)
429 struct scc_port *port = data;
430 struct tty_struct *tty = port->gs.port.tty;
431 SCC_ACCESS_INIT(port);
433 ch = SCCread_NB(RX_DATA_REG);
435 printk(KERN_WARNING "scc_rx_int with NULL tty!\n");
436 SCCwrite_NB(COMMAND_REG, CR_HIGHEST_IUS_RESET);
439 tty_insert_flip_char(tty, ch, 0);
441 /* Check if another character is already ready; in that case, the
442 * spcond_int() function must be used, because this character may have an
443 * error condition that isn't signalled by the interrupt vector used!
445 if (SCCread(INT_PENDING_REG) &
446 (port->channel == CHANNEL_A ? IPR_A_RX : IPR_B_RX)) {
447 scc_spcond_int (irq, data);
451 SCCwrite_NB(COMMAND_REG, CR_HIGHEST_IUS_RESET);
453 tty_flip_buffer_push(tty);
458 static irqreturn_t scc_spcond_int(int irq, void *data)
460 struct scc_port *port = data;
461 struct tty_struct *tty = port->gs.port.tty;
462 unsigned char stat, ch, err;
463 int int_pending_mask = port->channel == CHANNEL_A ?
465 SCC_ACCESS_INIT(port);
468 printk(KERN_WARNING "scc_spcond_int with NULL tty!\n");
469 SCCwrite(COMMAND_REG, CR_ERROR_RESET);
470 SCCwrite_NB(COMMAND_REG, CR_HIGHEST_IUS_RESET);
474 stat = SCCread(SPCOND_STATUS_REG);
475 ch = SCCread_NB(RX_DATA_REG);
477 if (stat & SCSR_RX_OVERRUN)
479 else if (stat & SCSR_PARITY_ERR)
481 else if (stat & SCSR_CRC_FRAME_ERR)
486 tty_insert_flip_char(tty, ch, err);
488 /* ++TeSche: *All* errors have to be cleared manually,
489 * else the condition persists for the next chars
492 SCCwrite(COMMAND_REG, CR_ERROR_RESET);
494 } while(SCCread(INT_PENDING_REG) & int_pending_mask);
496 SCCwrite_NB(COMMAND_REG, CR_HIGHEST_IUS_RESET);
498 tty_flip_buffer_push(tty);
503 static irqreturn_t scc_tx_int(int irq, void *data)
505 struct scc_port *port = data;
506 SCC_ACCESS_INIT(port);
508 if (!port->gs.port.tty) {
509 printk(KERN_WARNING "scc_tx_int with NULL tty!\n");
510 SCCmod (INT_AND_DMA_REG, ~IDR_TX_INT_ENAB, 0);
511 SCCwrite(COMMAND_REG, CR_TX_PENDING_RESET);
512 SCCwrite_NB(COMMAND_REG, CR_HIGHEST_IUS_RESET);
515 while ((SCCread_NB(STATUS_REG) & SR_TX_BUF_EMPTY)) {
517 SCCwrite(TX_DATA_REG, port->x_char);
520 else if ((port->gs.xmit_cnt <= 0) ||
521 port->gs.port.tty->stopped ||
522 port->gs.port.tty->hw_stopped)
525 SCCwrite(TX_DATA_REG, port->gs.xmit_buf[port->gs.xmit_tail++]);
526 port->gs.xmit_tail = port->gs.xmit_tail & (SERIAL_XMIT_SIZE-1);
527 if (--port->gs.xmit_cnt <= 0)
531 if ((port->gs.xmit_cnt <= 0) || port->gs.port.tty->stopped ||
532 port->gs.port.tty->hw_stopped) {
533 /* disable tx interrupts */
534 SCCmod (INT_AND_DMA_REG, ~IDR_TX_INT_ENAB, 0);
535 SCCwrite(COMMAND_REG, CR_TX_PENDING_RESET); /* disable tx_int on next tx underrun? */
536 port->gs.port.flags &= ~GS_TX_INTEN;
538 if (port->gs.port.tty && port->gs.xmit_cnt <= port->gs.wakeup_chars)
539 tty_wakeup(port->gs.port.tty);
541 SCCwrite_NB(COMMAND_REG, CR_HIGHEST_IUS_RESET);
546 static irqreturn_t scc_stat_int(int irq, void *data)
548 struct scc_port *port = data;
549 unsigned channel = port->channel;
550 unsigned char last_sr, sr, changed;
551 SCC_ACCESS_INIT(port);
553 last_sr = scc_last_status_reg[channel];
554 sr = scc_last_status_reg[channel] = SCCread_NB(STATUS_REG);
555 changed = last_sr ^ sr;
557 if (changed & SR_DCD) {
558 port->c_dcd = !!(sr & SR_DCD);
559 if (!(port->gs.port.flags & ASYNC_CHECK_CD))
560 ; /* Don't report DCD changes */
561 else if (port->c_dcd) {
562 wake_up_interruptible(&port->gs.port.open_wait);
565 if (port->gs.port.tty)
566 tty_hangup (port->gs.port.tty);
569 SCCwrite(COMMAND_REG, CR_EXTSTAT_RESET);
570 SCCwrite_NB(COMMAND_REG, CR_HIGHEST_IUS_RESET);
575 /*---------------------------------------------------------------------------
576 * generic_serial.c callback funtions
577 *--------------------------------------------------------------------------*/
579 static void scc_disable_tx_interrupts(void *ptr)
581 struct scc_port *port = ptr;
583 SCC_ACCESS_INIT(port);
585 local_irq_save(flags);
586 SCCmod(INT_AND_DMA_REG, ~IDR_TX_INT_ENAB, 0);
587 port->gs.port.flags &= ~GS_TX_INTEN;
588 local_irq_restore(flags);
592 static void scc_enable_tx_interrupts(void *ptr)
594 struct scc_port *port = ptr;
596 SCC_ACCESS_INIT(port);
598 local_irq_save(flags);
599 SCCmod(INT_AND_DMA_REG, 0xff, IDR_TX_INT_ENAB);
600 /* restart the transmitter */
601 scc_tx_int (0, port);
602 local_irq_restore(flags);
606 static void scc_disable_rx_interrupts(void *ptr)
608 struct scc_port *port = ptr;
610 SCC_ACCESS_INIT(port);
612 local_irq_save(flags);
613 SCCmod(INT_AND_DMA_REG,
614 ~(IDR_RX_INT_MASK|IDR_PARERR_AS_SPCOND|IDR_EXTSTAT_INT_ENAB), 0);
615 local_irq_restore(flags);
619 static void scc_enable_rx_interrupts(void *ptr)
621 struct scc_port *port = ptr;
623 SCC_ACCESS_INIT(port);
625 local_irq_save(flags);
626 SCCmod(INT_AND_DMA_REG, 0xff,
627 IDR_EXTSTAT_INT_ENAB|IDR_PARERR_AS_SPCOND|IDR_RX_INT_ALL);
628 local_irq_restore(flags);
632 static int scc_carrier_raised(struct tty_port *port)
634 struct scc_port *sc = container_of(port, struct scc_port, gs.port);
635 unsigned channel = sc->channel;
637 return !!(scc_last_status_reg[channel] & SR_DCD);
641 static void scc_shutdown_port(void *ptr)
643 struct scc_port *port = ptr;
645 port->gs.port.flags &= ~ GS_ACTIVE;
646 if (port->gs.port.tty && (port->gs.port.tty->termios->c_cflag & HUPCL)) {
647 scc_setsignals (port, 0, 0);
652 static int scc_set_real_termios (void *ptr)
654 /* the SCC has char sizes 5,7,6,8 in that order! */
655 static int chsize_map[4] = { 0, 2, 1, 3 };
656 unsigned cflag, baud, chsize, channel, brgval = 0;
658 struct scc_port *port = ptr;
659 SCC_ACCESS_INIT(port);
661 if (!port->gs.port.tty || !port->gs.port.tty->termios) return 0;
663 channel = port->channel;
665 if (channel == CHANNEL_A)
666 return 0; /* Settings controlled by boot PROM */
668 cflag = port->gs.port.tty->termios->c_cflag;
669 baud = port->gs.baud;
670 chsize = (cflag & CSIZE) >> 4;
673 /* speed == 0 -> drop DTR */
674 local_irq_save(flags);
675 SCCmod(TX_CTRL_REG, ~TCR_DTR, 0);
676 local_irq_restore(flags);
679 else if ((MACH_IS_MVME16x && (baud < 50 || baud > 38400)) ||
680 (MACH_IS_MVME147 && (baud < 50 || baud > 19200)) ||
681 (MACH_IS_BVME6000 &&(baud < 50 || baud > 76800))) {
682 printk(KERN_NOTICE "SCC: Bad speed requested, %d\n", baud);
687 port->gs.port.flags &= ~ASYNC_CHECK_CD;
689 port->gs.port.flags |= ASYNC_CHECK_CD;
691 #ifdef CONFIG_MVME147_SCC
693 brgval = (M147_SCC_PCLK + baud/2) / (16 * 2 * baud) - 2;
695 #ifdef CONFIG_MVME162_SCC
697 brgval = (MVME_SCC_PCLK + baud/2) / (16 * 2 * baud) - 2;
699 #ifdef CONFIG_BVME6000_SCC
700 if (MACH_IS_BVME6000)
701 brgval = (BVME_SCC_RTxC + baud/2) / (16 * 2 * baud) - 2;
703 /* Now we have all parameters and can go to set them: */
704 local_irq_save(flags);
706 /* receiver's character size and auto-enables */
707 SCCmod(RX_CTRL_REG, ~(RCR_CHSIZE_MASK|RCR_AUTO_ENAB_MODE),
708 (chsize_map[chsize] << 6) |
709 ((cflag & CRTSCTS) ? RCR_AUTO_ENAB_MODE : 0));
710 /* parity and stop bits (both, Tx and Rx), clock mode never changes */
711 SCCmod (AUX1_CTRL_REG,
712 ~(A1CR_PARITY_MASK | A1CR_MODE_MASK),
714 ? (cflag & PARODD ? A1CR_PARITY_ODD : A1CR_PARITY_EVEN)
716 | (cflag & CSTOPB ? A1CR_MODE_ASYNC_2 : A1CR_MODE_ASYNC_1)));
717 /* sender's character size, set DTR for valid baud rate */
718 SCCmod(TX_CTRL_REG, ~TCR_CHSIZE_MASK, chsize_map[chsize] << 5 | TCR_DTR);
719 /* clock sources never change */
720 /* disable BRG before changing the value */
721 SCCmod(DPLL_CTRL_REG, ~DCR_BRG_ENAB, 0);
723 SCCwrite(TIMER_LOW_REG, brgval & 0xff);
724 SCCwrite(TIMER_HIGH_REG, (brgval >> 8) & 0xff);
725 /* BRG enable, and clock source never changes */
726 SCCmod(DPLL_CTRL_REG, 0xff, DCR_BRG_ENAB);
728 local_irq_restore(flags);
734 static int scc_chars_in_buffer (void *ptr)
736 struct scc_port *port = ptr;
737 SCC_ACCESS_INIT(port);
739 return (SCCread (SPCOND_STATUS_REG) & SCSR_ALL_SENT) ? 0 : 1;
743 /* Comment taken from sx.c (2.4.0):
744 I haven't the foggiest why the decrement use count has to happen
745 here. The whole linux serial drivers stuff needs to be redesigned.
746 My guess is that this is a hack to minimize the impact of a bug
747 elsewhere. Thinking about it some more. (try it sometime) Try
748 running minicom on a serial port that is driven by a modularized
749 driver. Have the modem hangup. Then remove the driver module. Then
750 exit minicom. I expect an "oops". -- REW */
752 static void scc_hungup(void *ptr)
754 scc_disable_tx_interrupts(ptr);
755 scc_disable_rx_interrupts(ptr);
759 static void scc_close(void *ptr)
761 scc_disable_tx_interrupts(ptr);
762 scc_disable_rx_interrupts(ptr);
766 /*---------------------------------------------------------------------------
767 * Internal support functions
768 *--------------------------------------------------------------------------*/
770 static void scc_setsignals(struct scc_port *port, int dtr, int rts)
774 SCC_ACCESS_INIT(port);
776 local_irq_save(flags);
777 t = SCCread(TX_CTRL_REG);
778 if (dtr >= 0) t = dtr? (t | TCR_DTR): (t & ~TCR_DTR);
779 if (rts >= 0) t = rts? (t | TCR_RTS): (t & ~TCR_RTS);
780 SCCwrite(TX_CTRL_REG, t);
781 local_irq_restore(flags);
785 static void scc_send_xchar(struct tty_struct *tty, char ch)
787 struct scc_port *port = tty->driver_data;
791 scc_enable_tx_interrupts(port);
795 /*---------------------------------------------------------------------------
796 * Driver entrypoints referenced from above
797 *--------------------------------------------------------------------------*/
799 static int scc_open (struct tty_struct * tty, struct file * filp)
801 int line = tty->index;
803 struct scc_port *port = &scc_ports[line];
804 int i, channel = port->channel;
806 SCC_ACCESS_INIT(port);
807 #if defined(CONFIG_MVME162_SCC) || defined(CONFIG_MVME147_SCC)
808 static const struct {
810 } mvme_init_tab[] = {
811 /* Values for MVME162 and MVME147 */
812 /* no parity, 1 stop bit, async, 1:16 */
813 { AUX1_CTRL_REG, A1CR_PARITY_NONE|A1CR_MODE_ASYNC_1|A1CR_CLKMODE_x16 },
814 /* parity error is special cond, ints disabled, no DMA */
815 { INT_AND_DMA_REG, IDR_PARERR_AS_SPCOND | IDR_RX_INT_DISAB },
816 /* Rx 8 bits/char, no auto enable, Rx off */
817 { RX_CTRL_REG, RCR_CHSIZE_8 },
818 /* DTR off, Tx 8 bits/char, RTS off, Tx off */
819 { TX_CTRL_REG, TCR_CHSIZE_8 },
820 /* special features off */
821 { AUX2_CTRL_REG, 0 },
822 { CLK_CTRL_REG, CCR_RXCLK_BRG | CCR_TXCLK_BRG },
823 { DPLL_CTRL_REG, DCR_BRG_ENAB | DCR_BRG_USE_PCLK },
825 { RX_CTRL_REG, RCR_RX_ENAB | RCR_CHSIZE_8 },
827 { TX_CTRL_REG, TCR_TX_ENAB | TCR_RTS | TCR_DTR | TCR_CHSIZE_8 },
828 /* Ext/Stat ints: DCD only */
829 { INT_CTRL_REG, ICR_ENAB_DCD_INT },
830 /* Reset Ext/Stat ints */
831 { COMMAND_REG, CR_EXTSTAT_RESET },
833 { COMMAND_REG, CR_EXTSTAT_RESET },
836 #if defined(CONFIG_BVME6000_SCC)
837 static const struct {
839 } bvme_init_tab[] = {
840 /* Values for BVME6000 */
841 /* no parity, 1 stop bit, async, 1:16 */
842 { AUX1_CTRL_REG, A1CR_PARITY_NONE|A1CR_MODE_ASYNC_1|A1CR_CLKMODE_x16 },
843 /* parity error is special cond, ints disabled, no DMA */
844 { INT_AND_DMA_REG, IDR_PARERR_AS_SPCOND | IDR_RX_INT_DISAB },
845 /* Rx 8 bits/char, no auto enable, Rx off */
846 { RX_CTRL_REG, RCR_CHSIZE_8 },
847 /* DTR off, Tx 8 bits/char, RTS off, Tx off */
848 { TX_CTRL_REG, TCR_CHSIZE_8 },
849 /* special features off */
850 { AUX2_CTRL_REG, 0 },
851 { CLK_CTRL_REG, CCR_RTxC_XTAL | CCR_RXCLK_BRG | CCR_TXCLK_BRG },
852 { DPLL_CTRL_REG, DCR_BRG_ENAB },
854 { RX_CTRL_REG, RCR_RX_ENAB | RCR_CHSIZE_8 },
856 { TX_CTRL_REG, TCR_TX_ENAB | TCR_RTS | TCR_DTR | TCR_CHSIZE_8 },
857 /* Ext/Stat ints: DCD only */
858 { INT_CTRL_REG, ICR_ENAB_DCD_INT },
859 /* Reset Ext/Stat ints */
860 { COMMAND_REG, CR_EXTSTAT_RESET },
862 { COMMAND_REG, CR_EXTSTAT_RESET },
865 if (!(port->gs.port.flags & ASYNC_INITIALIZED)) {
866 local_irq_save(flags);
867 #if defined(CONFIG_MVME147_SCC) || defined(CONFIG_MVME162_SCC)
868 if (MACH_IS_MVME147 || MACH_IS_MVME16x) {
869 for (i = 0; i < ARRAY_SIZE(mvme_init_tab); ++i)
870 SCCwrite(mvme_init_tab[i].reg, mvme_init_tab[i].val);
873 #if defined(CONFIG_BVME6000_SCC)
874 if (MACH_IS_BVME6000) {
875 for (i = 0; i < ARRAY_SIZE(bvme_init_tab); ++i)
876 SCCwrite(bvme_init_tab[i].reg, bvme_init_tab[i].val);
880 /* remember status register for detection of DCD and CTS changes */
881 scc_last_status_reg[channel] = SCCread(STATUS_REG);
883 port->c_dcd = 0; /* Prevent initial 1->0 interrupt */
884 scc_setsignals (port, 1,1);
885 local_irq_restore(flags);
888 tty->driver_data = port;
889 port->gs.port.tty = tty;
890 port->gs.port.count++;
891 retval = gs_init_port(&port->gs);
893 port->gs.port.count--;
896 port->gs.port.flags |= GS_ACTIVE;
897 retval = gs_block_til_ready(port, filp);
900 port->gs.port.count--;
904 port->c_dcd = tty_port_carrier_raised(&port->gs.port);
906 scc_enable_rx_interrupts(port);
912 static void scc_throttle (struct tty_struct * tty)
914 struct scc_port *port = tty->driver_data;
916 SCC_ACCESS_INIT(port);
918 if (tty->termios->c_cflag & CRTSCTS) {
919 local_irq_save(flags);
920 SCCmod(TX_CTRL_REG, ~TCR_RTS, 0);
921 local_irq_restore(flags);
924 scc_send_xchar(tty, STOP_CHAR(tty));
928 static void scc_unthrottle (struct tty_struct * tty)
930 struct scc_port *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, 0xff, TCR_RTS);
937 local_irq_restore(flags);
940 scc_send_xchar(tty, START_CHAR(tty));
944 static int scc_ioctl(struct tty_struct *tty, struct file *file,
945 unsigned int cmd, unsigned long arg)
951 static int scc_break_ctl(struct tty_struct *tty, int break_state)
953 struct scc_port *port = tty->driver_data;
955 SCC_ACCESS_INIT(port);
957 local_irq_save(flags);
958 SCCmod(TX_CTRL_REG, ~TCR_SEND_BREAK,
959 break_state ? TCR_SEND_BREAK : 0);
960 local_irq_restore(flags);
965 /*---------------------------------------------------------------------------
966 * Serial console stuff...
967 *--------------------------------------------------------------------------*/
969 #define scc_delay() do { __asm__ __volatile__ (" nop; nop"); } while (0)
971 static void scc_ch_write (char ch)
973 volatile char *p = NULL;
975 #ifdef CONFIG_MVME147_SCC
977 p = (volatile char *)M147_SCC_A_ADDR;
979 #ifdef CONFIG_MVME162_SCC
981 p = (volatile char *)MVME_SCC_A_ADDR;
983 #ifdef CONFIG_BVME6000_SCC
984 if (MACH_IS_BVME6000)
985 p = (volatile char *)BVME_SCC_A_ADDR;
998 /* The console must be locked when we get here. */
1000 static void scc_console_write (struct console *co, const char *str, unsigned count)
1002 unsigned long flags;
1004 local_irq_save(flags);
1009 scc_ch_write ('\r');
1010 scc_ch_write (*str++);
1012 local_irq_restore(flags);
1015 static struct tty_driver *scc_console_device(struct console *c, int *index)
1021 static struct console sercons = {
1023 .write = scc_console_write,
1024 .device = scc_console_device,
1025 .flags = CON_PRINTBUFFER,
1030 static int __init vme_scc_console_init(void)
1032 if (vme_brdtype == VME_TYPE_MVME147 ||
1033 vme_brdtype == VME_TYPE_MVME162 ||
1034 vme_brdtype == VME_TYPE_MVME172 ||
1035 vme_brdtype == VME_TYPE_BVME4000 ||
1036 vme_brdtype == VME_TYPE_BVME6000)
1037 register_console(&sercons);
1040 console_initcall(vme_scc_console_init);