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/miscdevice.h>
31 #include <linux/console.h>
32 #include <linux/init.h>
33 #include <asm/setup.h>
34 #include <asm/bootinfo.h>
36 #ifdef CONFIG_MVME147_SCC
37 #include <asm/mvme147hw.h>
39 #ifdef CONFIG_MVME162_SCC
40 #include <asm/mvme16xhw.h>
42 #ifdef CONFIG_BVME6000_SCC
43 #include <asm/bvme6000hw.h>
46 #include <linux/generic_serial.h>
53 #define SCC_MINOR_BASE 64
55 /* Shadows for all SCC write registers */
56 static unsigned char scc_shadow[2][16];
58 /* Location to access for SCC register access delay */
59 static volatile unsigned char *scc_del = NULL;
61 /* To keep track of STATUS_REG state for detection of Ext/Status int source */
62 static unsigned char scc_last_status_reg[2];
64 /***************************** Prototypes *****************************/
66 /* Function prototypes */
67 static void scc_disable_tx_interrupts(void * ptr);
68 static void scc_enable_tx_interrupts(void * ptr);
69 static void scc_disable_rx_interrupts(void * ptr);
70 static void scc_enable_rx_interrupts(void * ptr);
71 static int scc_carrier_raised(struct tty_port *port);
72 static void scc_shutdown_port(void * ptr);
73 static int scc_set_real_termios(void *ptr);
74 static void scc_hungup(void *ptr);
75 static void scc_close(void *ptr);
76 static int scc_chars_in_buffer(void * ptr);
77 static int scc_open(struct tty_struct * tty, struct file * filp);
78 static int scc_ioctl(struct tty_struct * tty, struct file * filp,
79 unsigned int cmd, unsigned long arg);
80 static void scc_throttle(struct tty_struct *tty);
81 static void scc_unthrottle(struct tty_struct *tty);
82 static irqreturn_t scc_tx_int(int irq, void *data);
83 static irqreturn_t scc_rx_int(int irq, void *data);
84 static irqreturn_t scc_stat_int(int irq, void *data);
85 static irqreturn_t scc_spcond_int(int irq, void *data);
86 static void scc_setsignals(struct scc_port *port, int dtr, int rts);
87 static int scc_break_ctl(struct tty_struct *tty, int break_state);
89 static struct tty_driver *scc_driver;
91 static struct scc_port scc_ports[2];
93 /*---------------------------------------------------------------------------
94 * Interface from generic_serial.c back here
95 *--------------------------------------------------------------------------*/
97 static struct real_driver scc_real_driver = {
98 scc_disable_tx_interrupts,
99 scc_enable_tx_interrupts,
100 scc_disable_rx_interrupts,
101 scc_enable_rx_interrupts,
103 scc_set_real_termios,
111 static const struct tty_operations scc_ops = {
115 .put_char = gs_put_char,
116 .flush_chars = gs_flush_chars,
117 .write_room = gs_write_room,
118 .chars_in_buffer = gs_chars_in_buffer,
119 .flush_buffer = gs_flush_buffer,
121 .throttle = scc_throttle,
122 .unthrottle = scc_unthrottle,
123 .set_termios = gs_set_termios,
127 .break_ctl = scc_break_ctl,
130 static const struct tty_port_operations scc_port_ops = {
131 .carrier_raised = scc_carrier_raised,
134 /*----------------------------------------------------------------------------
135 * vme_scc_init() and support functions
136 *---------------------------------------------------------------------------*/
138 static int __init scc_init_drivers(void)
142 scc_driver = alloc_tty_driver(2);
145 scc_driver->owner = THIS_MODULE;
146 scc_driver->driver_name = "scc";
147 scc_driver->name = "ttyS";
148 scc_driver->major = TTY_MAJOR;
149 scc_driver->minor_start = SCC_MINOR_BASE;
150 scc_driver->type = TTY_DRIVER_TYPE_SERIAL;
151 scc_driver->subtype = SERIAL_TYPE_NORMAL;
152 scc_driver->init_termios = tty_std_termios;
153 scc_driver->init_termios.c_cflag =
154 B9600 | CS8 | CREAD | HUPCL | CLOCAL;
155 scc_driver->init_termios.c_ispeed = 9600;
156 scc_driver->init_termios.c_ospeed = 9600;
157 scc_driver->flags = TTY_DRIVER_REAL_RAW;
158 tty_set_operations(scc_driver, &scc_ops);
160 if ((error = tty_register_driver(scc_driver))) {
161 printk(KERN_ERR "scc: Couldn't register scc driver, error = %d\n",
163 put_tty_driver(scc_driver);
171 /* ports[] array is indexed by line no (i.e. [0] for ttyS0, [1] for ttyS1).
174 static void __init scc_init_portstructs(void)
176 struct scc_port *port;
179 for (i = 0; i < 2; i++) {
180 port = scc_ports + i;
181 tty_port_init(&port->gs.port);
182 port->gs.port.ops = &scc_port_ops;
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_mutex = MUTEX;
190 init_waitqueue_head(&port->gs.port.open_wait);
191 init_waitqueue_head(&port->gs.port.close_wait);
196 #ifdef CONFIG_MVME147_SCC
197 static int __init mvme147_scc_init(void)
199 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 error = request_irq(MVME147_IRQ_SCCA_TX, scc_tx_int, IRQF_DISABLED,
214 error = request_irq(MVME147_IRQ_SCCA_STAT, scc_stat_int, IRQF_DISABLED,
215 "SCC-A status", port);
218 error = request_irq(MVME147_IRQ_SCCA_RX, scc_rx_int, IRQF_DISABLED,
221 goto fail_free_a_stat;
222 error = request_irq(MVME147_IRQ_SCCA_SPCOND, scc_spcond_int,
223 IRQF_DISABLED, "SCC-A special cond", port);
228 SCC_ACCESS_INIT(port);
230 /* disable interrupts for this channel */
231 SCCwrite(INT_AND_DMA_REG, 0);
232 /* Set the interrupt vector */
233 SCCwrite(INT_VECTOR_REG, MVME147_IRQ_SCC_BASE);
234 /* Interrupt parameters: vector includes status, status low */
235 SCCwrite(MASTER_INT_CTRL, MIC_VEC_INCL_STAT);
236 SCCmod(MASTER_INT_CTRL, 0xff, MIC_MASTER_INT_ENAB);
240 port = &scc_ports[1];
241 port->channel = CHANNEL_B;
242 port->ctrlp = (volatile unsigned char *)M147_SCC_B_ADDR;
243 port->datap = port->ctrlp + 1;
244 port->port_a = &scc_ports[0];
245 port->port_b = &scc_ports[1];
246 error = request_irq(MVME147_IRQ_SCCB_TX, scc_tx_int, IRQF_DISABLED,
249 goto fail_free_a_spcond;
250 error = request_irq(MVME147_IRQ_SCCB_STAT, scc_stat_int, IRQF_DISABLED,
251 "SCC-B status", port);
254 error = request_irq(MVME147_IRQ_SCCB_RX, scc_rx_int, IRQF_DISABLED,
257 goto fail_free_b_stat;
258 error = request_irq(MVME147_IRQ_SCCB_SPCOND, scc_spcond_int,
259 IRQF_DISABLED, "SCC-B special cond", port);
264 SCC_ACCESS_INIT(port);
266 /* disable interrupts for this channel */
267 SCCwrite(INT_AND_DMA_REG, 0);
270 /* Ensure interrupts are enabled in the PCC chip */
271 m147_pcc->serial_cntrl=PCC_LEVEL_SERIAL|PCC_INT_ENAB;
273 /* Initialise the tty driver structures and register */
274 scc_init_portstructs();
280 free_irq(MVME147_IRQ_SCCB_RX, port);
282 free_irq(MVME147_IRQ_SCCB_STAT, port);
284 free_irq(MVME147_IRQ_SCCB_TX, port);
286 free_irq(MVME147_IRQ_SCCA_SPCOND, port);
288 free_irq(MVME147_IRQ_SCCA_RX, port);
290 free_irq(MVME147_IRQ_SCCA_STAT, port);
292 free_irq(MVME147_IRQ_SCCA_TX, port);
299 #ifdef CONFIG_MVME162_SCC
300 static int __init mvme162_scc_init(void)
302 struct scc_port *port;
305 if (!(mvme16x_config & MVME16x_CONFIG_GOT_SCCA))
308 printk(KERN_INFO "SCC: MVME162 Serial Driver\n");
310 port = &scc_ports[0];
311 port->channel = CHANNEL_A;
312 port->ctrlp = (volatile unsigned char *)MVME_SCC_A_ADDR;
313 port->datap = port->ctrlp + 2;
314 port->port_a = &scc_ports[0];
315 port->port_b = &scc_ports[1];
316 error = request_irq(MVME162_IRQ_SCCA_TX, scc_tx_int, IRQF_DISABLED,
320 error = request_irq(MVME162_IRQ_SCCA_STAT, scc_stat_int, IRQF_DISABLED,
321 "SCC-A status", port);
324 error = request_irq(MVME162_IRQ_SCCA_RX, scc_rx_int, IRQF_DISABLED,
327 goto fail_free_a_stat;
328 error = request_irq(MVME162_IRQ_SCCA_SPCOND, scc_spcond_int,
329 IRQF_DISABLED, "SCC-A special cond", port);
334 SCC_ACCESS_INIT(port);
336 /* disable interrupts for this channel */
337 SCCwrite(INT_AND_DMA_REG, 0);
338 /* Set the interrupt vector */
339 SCCwrite(INT_VECTOR_REG, MVME162_IRQ_SCC_BASE);
340 /* Interrupt parameters: vector includes status, status low */
341 SCCwrite(MASTER_INT_CTRL, MIC_VEC_INCL_STAT);
342 SCCmod(MASTER_INT_CTRL, 0xff, MIC_MASTER_INT_ENAB);
346 port = &scc_ports[1];
347 port->channel = CHANNEL_B;
348 port->ctrlp = (volatile unsigned char *)MVME_SCC_B_ADDR;
349 port->datap = port->ctrlp + 2;
350 port->port_a = &scc_ports[0];
351 port->port_b = &scc_ports[1];
352 error = request_irq(MVME162_IRQ_SCCB_TX, scc_tx_int, IRQF_DISABLED,
355 goto fail_free_a_spcond;
356 error = request_irq(MVME162_IRQ_SCCB_STAT, scc_stat_int, IRQF_DISABLED,
357 "SCC-B status", port);
360 error = request_irq(MVME162_IRQ_SCCB_RX, scc_rx_int, IRQF_DISABLED,
363 goto fail_free_b_stat;
364 error = request_irq(MVME162_IRQ_SCCB_SPCOND, scc_spcond_int,
365 IRQF_DISABLED, "SCC-B special cond", port);
370 SCC_ACCESS_INIT(port); /* Either channel will do */
372 /* disable interrupts for this channel */
373 SCCwrite(INT_AND_DMA_REG, 0);
376 /* Ensure interrupts are enabled in the MC2 chip */
377 *(volatile char *)0xfff4201d = 0x14;
379 /* Initialise the tty driver structures and register */
380 scc_init_portstructs();
386 free_irq(MVME162_IRQ_SCCB_RX, port);
388 free_irq(MVME162_IRQ_SCCB_STAT, port);
390 free_irq(MVME162_IRQ_SCCB_TX, port);
392 free_irq(MVME162_IRQ_SCCA_SPCOND, port);
394 free_irq(MVME162_IRQ_SCCA_RX, port);
396 free_irq(MVME162_IRQ_SCCA_STAT, port);
398 free_irq(MVME162_IRQ_SCCA_TX, port);
405 #ifdef CONFIG_BVME6000_SCC
406 static int __init bvme6000_scc_init(void)
408 struct scc_port *port;
411 printk(KERN_INFO "SCC: BVME6000 Serial Driver\n");
413 port = &scc_ports[0];
414 port->channel = CHANNEL_A;
415 port->ctrlp = (volatile unsigned char *)BVME_SCC_A_ADDR;
416 port->datap = port->ctrlp + 4;
417 port->port_a = &scc_ports[0];
418 port->port_b = &scc_ports[1];
419 error = request_irq(BVME_IRQ_SCCA_TX, scc_tx_int, IRQF_DISABLED,
423 error = request_irq(BVME_IRQ_SCCA_STAT, scc_stat_int, IRQF_DISABLED,
424 "SCC-A status", port);
427 error = request_irq(BVME_IRQ_SCCA_RX, scc_rx_int, IRQF_DISABLED,
430 goto fail_free_a_stat;
431 error = request_irq(BVME_IRQ_SCCA_SPCOND, scc_spcond_int,
432 IRQF_DISABLED, "SCC-A special cond", port);
437 SCC_ACCESS_INIT(port);
439 /* disable interrupts for this channel */
440 SCCwrite(INT_AND_DMA_REG, 0);
441 /* Set the interrupt vector */
442 SCCwrite(INT_VECTOR_REG, BVME_IRQ_SCC_BASE);
443 /* Interrupt parameters: vector includes status, status low */
444 SCCwrite(MASTER_INT_CTRL, MIC_VEC_INCL_STAT);
445 SCCmod(MASTER_INT_CTRL, 0xff, MIC_MASTER_INT_ENAB);
449 port = &scc_ports[1];
450 port->channel = CHANNEL_B;
451 port->ctrlp = (volatile unsigned char *)BVME_SCC_B_ADDR;
452 port->datap = port->ctrlp + 4;
453 port->port_a = &scc_ports[0];
454 port->port_b = &scc_ports[1];
455 error = request_irq(BVME_IRQ_SCCB_TX, scc_tx_int, IRQF_DISABLED,
458 goto fail_free_a_spcond;
459 error = request_irq(BVME_IRQ_SCCB_STAT, scc_stat_int, IRQF_DISABLED,
460 "SCC-B status", port);
463 error = request_irq(BVME_IRQ_SCCB_RX, scc_rx_int, IRQF_DISABLED,
466 goto fail_free_b_stat;
467 error = request_irq(BVME_IRQ_SCCB_SPCOND, scc_spcond_int,
468 IRQF_DISABLED, "SCC-B special cond", port);
473 SCC_ACCESS_INIT(port); /* Either channel will do */
475 /* disable interrupts for this channel */
476 SCCwrite(INT_AND_DMA_REG, 0);
479 /* Initialise the tty driver structures and register */
480 scc_init_portstructs();
486 free_irq(BVME_IRQ_SCCA_STAT, port);
488 free_irq(BVME_IRQ_SCCA_RX, port);
490 free_irq(BVME_IRQ_SCCA_SPCOND, port);
492 free_irq(BVME_IRQ_SCCB_TX, port);
494 free_irq(BVME_IRQ_SCCB_STAT, port);
496 free_irq(BVME_IRQ_SCCB_RX, port);
498 free_irq(BVME_IRQ_SCCB_SPCOND, port);
505 static int __init vme_scc_init(void)
509 #ifdef CONFIG_MVME147_SCC
511 res = mvme147_scc_init();
513 #ifdef CONFIG_MVME162_SCC
515 res = mvme162_scc_init();
517 #ifdef CONFIG_BVME6000_SCC
518 if (MACH_IS_BVME6000)
519 res = bvme6000_scc_init();
524 module_init(vme_scc_init);
527 /*---------------------------------------------------------------------------
529 *--------------------------------------------------------------------------*/
531 static irqreturn_t scc_rx_int(int irq, void *data)
534 struct scc_port *port = data;
535 struct tty_struct *tty = port->gs.port.tty;
536 SCC_ACCESS_INIT(port);
538 ch = SCCread_NB(RX_DATA_REG);
540 printk(KERN_WARNING "scc_rx_int with NULL tty!\n");
541 SCCwrite_NB(COMMAND_REG, CR_HIGHEST_IUS_RESET);
544 tty_insert_flip_char(tty, ch, 0);
546 /* Check if another character is already ready; in that case, the
547 * spcond_int() function must be used, because this character may have an
548 * error condition that isn't signalled by the interrupt vector used!
550 if (SCCread(INT_PENDING_REG) &
551 (port->channel == CHANNEL_A ? IPR_A_RX : IPR_B_RX)) {
552 scc_spcond_int (irq, data);
556 SCCwrite_NB(COMMAND_REG, CR_HIGHEST_IUS_RESET);
558 tty_flip_buffer_push(tty);
563 static irqreturn_t scc_spcond_int(int irq, void *data)
565 struct scc_port *port = data;
566 struct tty_struct *tty = port->gs.port.tty;
567 unsigned char stat, ch, err;
568 int int_pending_mask = port->channel == CHANNEL_A ?
570 SCC_ACCESS_INIT(port);
573 printk(KERN_WARNING "scc_spcond_int with NULL tty!\n");
574 SCCwrite(COMMAND_REG, CR_ERROR_RESET);
575 SCCwrite_NB(COMMAND_REG, CR_HIGHEST_IUS_RESET);
579 stat = SCCread(SPCOND_STATUS_REG);
580 ch = SCCread_NB(RX_DATA_REG);
582 if (stat & SCSR_RX_OVERRUN)
584 else if (stat & SCSR_PARITY_ERR)
586 else if (stat & SCSR_CRC_FRAME_ERR)
591 tty_insert_flip_char(tty, ch, err);
593 /* ++TeSche: *All* errors have to be cleared manually,
594 * else the condition persists for the next chars
597 SCCwrite(COMMAND_REG, CR_ERROR_RESET);
599 } while(SCCread(INT_PENDING_REG) & int_pending_mask);
601 SCCwrite_NB(COMMAND_REG, CR_HIGHEST_IUS_RESET);
603 tty_flip_buffer_push(tty);
608 static irqreturn_t scc_tx_int(int irq, void *data)
610 struct scc_port *port = data;
611 SCC_ACCESS_INIT(port);
613 if (!port->gs.port.tty) {
614 printk(KERN_WARNING "scc_tx_int with NULL tty!\n");
615 SCCmod (INT_AND_DMA_REG, ~IDR_TX_INT_ENAB, 0);
616 SCCwrite(COMMAND_REG, CR_TX_PENDING_RESET);
617 SCCwrite_NB(COMMAND_REG, CR_HIGHEST_IUS_RESET);
620 while ((SCCread_NB(STATUS_REG) & SR_TX_BUF_EMPTY)) {
622 SCCwrite(TX_DATA_REG, port->x_char);
625 else if ((port->gs.xmit_cnt <= 0) ||
626 port->gs.port.tty->stopped ||
627 port->gs.port.tty->hw_stopped)
630 SCCwrite(TX_DATA_REG, port->gs.xmit_buf[port->gs.xmit_tail++]);
631 port->gs.xmit_tail = port->gs.xmit_tail & (SERIAL_XMIT_SIZE-1);
632 if (--port->gs.xmit_cnt <= 0)
636 if ((port->gs.xmit_cnt <= 0) || port->gs.port.tty->stopped ||
637 port->gs.port.tty->hw_stopped) {
638 /* disable tx interrupts */
639 SCCmod (INT_AND_DMA_REG, ~IDR_TX_INT_ENAB, 0);
640 SCCwrite(COMMAND_REG, CR_TX_PENDING_RESET); /* disable tx_int on next tx underrun? */
641 port->gs.port.flags &= ~GS_TX_INTEN;
643 if (port->gs.port.tty && port->gs.xmit_cnt <= port->gs.wakeup_chars)
644 tty_wakeup(port->gs.port.tty);
646 SCCwrite_NB(COMMAND_REG, CR_HIGHEST_IUS_RESET);
651 static irqreturn_t scc_stat_int(int irq, void *data)
653 struct scc_port *port = data;
654 unsigned channel = port->channel;
655 unsigned char last_sr, sr, changed;
656 SCC_ACCESS_INIT(port);
658 last_sr = scc_last_status_reg[channel];
659 sr = scc_last_status_reg[channel] = SCCread_NB(STATUS_REG);
660 changed = last_sr ^ sr;
662 if (changed & SR_DCD) {
663 port->c_dcd = !!(sr & SR_DCD);
664 if (!(port->gs.port.flags & ASYNC_CHECK_CD))
665 ; /* Don't report DCD changes */
666 else if (port->c_dcd) {
667 wake_up_interruptible(&port->gs.port.open_wait);
670 if (port->gs.port.tty)
671 tty_hangup (port->gs.port.tty);
674 SCCwrite(COMMAND_REG, CR_EXTSTAT_RESET);
675 SCCwrite_NB(COMMAND_REG, CR_HIGHEST_IUS_RESET);
680 /*---------------------------------------------------------------------------
681 * generic_serial.c callback funtions
682 *--------------------------------------------------------------------------*/
684 static void scc_disable_tx_interrupts(void *ptr)
686 struct scc_port *port = ptr;
688 SCC_ACCESS_INIT(port);
690 local_irq_save(flags);
691 SCCmod(INT_AND_DMA_REG, ~IDR_TX_INT_ENAB, 0);
692 port->gs.port.flags &= ~GS_TX_INTEN;
693 local_irq_restore(flags);
697 static void scc_enable_tx_interrupts(void *ptr)
699 struct scc_port *port = ptr;
701 SCC_ACCESS_INIT(port);
703 local_irq_save(flags);
704 SCCmod(INT_AND_DMA_REG, 0xff, IDR_TX_INT_ENAB);
705 /* restart the transmitter */
706 scc_tx_int (0, port);
707 local_irq_restore(flags);
711 static void scc_disable_rx_interrupts(void *ptr)
713 struct scc_port *port = ptr;
715 SCC_ACCESS_INIT(port);
717 local_irq_save(flags);
718 SCCmod(INT_AND_DMA_REG,
719 ~(IDR_RX_INT_MASK|IDR_PARERR_AS_SPCOND|IDR_EXTSTAT_INT_ENAB), 0);
720 local_irq_restore(flags);
724 static void scc_enable_rx_interrupts(void *ptr)
726 struct scc_port *port = ptr;
728 SCC_ACCESS_INIT(port);
730 local_irq_save(flags);
731 SCCmod(INT_AND_DMA_REG, 0xff,
732 IDR_EXTSTAT_INT_ENAB|IDR_PARERR_AS_SPCOND|IDR_RX_INT_ALL);
733 local_irq_restore(flags);
737 static int scc_carrier_raised(struct tty_port *port)
739 struct scc_port *sc = container_of(port, struct scc_port, gs.port);
740 unsigned channel = sc->channel;
742 return !!(scc_last_status_reg[channel] & SR_DCD);
746 static void scc_shutdown_port(void *ptr)
748 struct scc_port *port = ptr;
750 port->gs.port.flags &= ~ GS_ACTIVE;
751 if (port->gs.port.tty && (port->gs.port.tty->termios->c_cflag & HUPCL)) {
752 scc_setsignals (port, 0, 0);
757 static int scc_set_real_termios (void *ptr)
759 /* the SCC has char sizes 5,7,6,8 in that order! */
760 static int chsize_map[4] = { 0, 2, 1, 3 };
761 unsigned cflag, baud, chsize, channel, brgval = 0;
763 struct scc_port *port = ptr;
764 SCC_ACCESS_INIT(port);
766 if (!port->gs.port.tty || !port->gs.port.tty->termios) return 0;
768 channel = port->channel;
770 if (channel == CHANNEL_A)
771 return 0; /* Settings controlled by boot PROM */
773 cflag = port->gs.port.tty->termios->c_cflag;
774 baud = port->gs.baud;
775 chsize = (cflag & CSIZE) >> 4;
778 /* speed == 0 -> drop DTR */
779 local_irq_save(flags);
780 SCCmod(TX_CTRL_REG, ~TCR_DTR, 0);
781 local_irq_restore(flags);
784 else if ((MACH_IS_MVME16x && (baud < 50 || baud > 38400)) ||
785 (MACH_IS_MVME147 && (baud < 50 || baud > 19200)) ||
786 (MACH_IS_BVME6000 &&(baud < 50 || baud > 76800))) {
787 printk(KERN_NOTICE "SCC: Bad speed requested, %d\n", baud);
792 port->gs.port.flags &= ~ASYNC_CHECK_CD;
794 port->gs.port.flags |= ASYNC_CHECK_CD;
796 #ifdef CONFIG_MVME147_SCC
798 brgval = (M147_SCC_PCLK + baud/2) / (16 * 2 * baud) - 2;
800 #ifdef CONFIG_MVME162_SCC
802 brgval = (MVME_SCC_PCLK + baud/2) / (16 * 2 * baud) - 2;
804 #ifdef CONFIG_BVME6000_SCC
805 if (MACH_IS_BVME6000)
806 brgval = (BVME_SCC_RTxC + baud/2) / (16 * 2 * baud) - 2;
808 /* Now we have all parameters and can go to set them: */
809 local_irq_save(flags);
811 /* receiver's character size and auto-enables */
812 SCCmod(RX_CTRL_REG, ~(RCR_CHSIZE_MASK|RCR_AUTO_ENAB_MODE),
813 (chsize_map[chsize] << 6) |
814 ((cflag & CRTSCTS) ? RCR_AUTO_ENAB_MODE : 0));
815 /* parity and stop bits (both, Tx and Rx), clock mode never changes */
816 SCCmod (AUX1_CTRL_REG,
817 ~(A1CR_PARITY_MASK | A1CR_MODE_MASK),
819 ? (cflag & PARODD ? A1CR_PARITY_ODD : A1CR_PARITY_EVEN)
821 | (cflag & CSTOPB ? A1CR_MODE_ASYNC_2 : A1CR_MODE_ASYNC_1)));
822 /* sender's character size, set DTR for valid baud rate */
823 SCCmod(TX_CTRL_REG, ~TCR_CHSIZE_MASK, chsize_map[chsize] << 5 | TCR_DTR);
824 /* clock sources never change */
825 /* disable BRG before changing the value */
826 SCCmod(DPLL_CTRL_REG, ~DCR_BRG_ENAB, 0);
828 SCCwrite(TIMER_LOW_REG, brgval & 0xff);
829 SCCwrite(TIMER_HIGH_REG, (brgval >> 8) & 0xff);
830 /* BRG enable, and clock source never changes */
831 SCCmod(DPLL_CTRL_REG, 0xff, DCR_BRG_ENAB);
833 local_irq_restore(flags);
839 static int scc_chars_in_buffer (void *ptr)
841 struct scc_port *port = ptr;
842 SCC_ACCESS_INIT(port);
844 return (SCCread (SPCOND_STATUS_REG) & SCSR_ALL_SENT) ? 0 : 1;
848 /* Comment taken from sx.c (2.4.0):
849 I haven't the foggiest why the decrement use count has to happen
850 here. The whole linux serial drivers stuff needs to be redesigned.
851 My guess is that this is a hack to minimize the impact of a bug
852 elsewhere. Thinking about it some more. (try it sometime) Try
853 running minicom on a serial port that is driven by a modularized
854 driver. Have the modem hangup. Then remove the driver module. Then
855 exit minicom. I expect an "oops". -- REW */
857 static void scc_hungup(void *ptr)
859 scc_disable_tx_interrupts(ptr);
860 scc_disable_rx_interrupts(ptr);
864 static void scc_close(void *ptr)
866 scc_disable_tx_interrupts(ptr);
867 scc_disable_rx_interrupts(ptr);
871 /*---------------------------------------------------------------------------
872 * Internal support functions
873 *--------------------------------------------------------------------------*/
875 static void scc_setsignals(struct scc_port *port, int dtr, int rts)
879 SCC_ACCESS_INIT(port);
881 local_irq_save(flags);
882 t = SCCread(TX_CTRL_REG);
883 if (dtr >= 0) t = dtr? (t | TCR_DTR): (t & ~TCR_DTR);
884 if (rts >= 0) t = rts? (t | TCR_RTS): (t & ~TCR_RTS);
885 SCCwrite(TX_CTRL_REG, t);
886 local_irq_restore(flags);
890 static void scc_send_xchar(struct tty_struct *tty, char ch)
892 struct scc_port *port = tty->driver_data;
896 scc_enable_tx_interrupts(port);
900 /*---------------------------------------------------------------------------
901 * Driver entrypoints referenced from above
902 *--------------------------------------------------------------------------*/
904 static int scc_open (struct tty_struct * tty, struct file * filp)
906 int line = tty->index;
908 struct scc_port *port = &scc_ports[line];
909 int i, channel = port->channel;
911 SCC_ACCESS_INIT(port);
912 #if defined(CONFIG_MVME162_SCC) || defined(CONFIG_MVME147_SCC)
913 static const struct {
915 } mvme_init_tab[] = {
916 /* Values for MVME162 and MVME147 */
917 /* no parity, 1 stop bit, async, 1:16 */
918 { AUX1_CTRL_REG, A1CR_PARITY_NONE|A1CR_MODE_ASYNC_1|A1CR_CLKMODE_x16 },
919 /* parity error is special cond, ints disabled, no DMA */
920 { INT_AND_DMA_REG, IDR_PARERR_AS_SPCOND | IDR_RX_INT_DISAB },
921 /* Rx 8 bits/char, no auto enable, Rx off */
922 { RX_CTRL_REG, RCR_CHSIZE_8 },
923 /* DTR off, Tx 8 bits/char, RTS off, Tx off */
924 { TX_CTRL_REG, TCR_CHSIZE_8 },
925 /* special features off */
926 { AUX2_CTRL_REG, 0 },
927 { CLK_CTRL_REG, CCR_RXCLK_BRG | CCR_TXCLK_BRG },
928 { DPLL_CTRL_REG, DCR_BRG_ENAB | DCR_BRG_USE_PCLK },
930 { RX_CTRL_REG, RCR_RX_ENAB | RCR_CHSIZE_8 },
932 { TX_CTRL_REG, TCR_TX_ENAB | TCR_RTS | TCR_DTR | TCR_CHSIZE_8 },
933 /* Ext/Stat ints: DCD only */
934 { INT_CTRL_REG, ICR_ENAB_DCD_INT },
935 /* Reset Ext/Stat ints */
936 { COMMAND_REG, CR_EXTSTAT_RESET },
938 { COMMAND_REG, CR_EXTSTAT_RESET },
941 #if defined(CONFIG_BVME6000_SCC)
942 static const struct {
944 } bvme_init_tab[] = {
945 /* Values for BVME6000 */
946 /* no parity, 1 stop bit, async, 1:16 */
947 { AUX1_CTRL_REG, A1CR_PARITY_NONE|A1CR_MODE_ASYNC_1|A1CR_CLKMODE_x16 },
948 /* parity error is special cond, ints disabled, no DMA */
949 { INT_AND_DMA_REG, IDR_PARERR_AS_SPCOND | IDR_RX_INT_DISAB },
950 /* Rx 8 bits/char, no auto enable, Rx off */
951 { RX_CTRL_REG, RCR_CHSIZE_8 },
952 /* DTR off, Tx 8 bits/char, RTS off, Tx off */
953 { TX_CTRL_REG, TCR_CHSIZE_8 },
954 /* special features off */
955 { AUX2_CTRL_REG, 0 },
956 { CLK_CTRL_REG, CCR_RTxC_XTAL | CCR_RXCLK_BRG | CCR_TXCLK_BRG },
957 { DPLL_CTRL_REG, DCR_BRG_ENAB },
959 { RX_CTRL_REG, RCR_RX_ENAB | RCR_CHSIZE_8 },
961 { TX_CTRL_REG, TCR_TX_ENAB | TCR_RTS | TCR_DTR | TCR_CHSIZE_8 },
962 /* Ext/Stat ints: DCD only */
963 { INT_CTRL_REG, ICR_ENAB_DCD_INT },
964 /* Reset Ext/Stat ints */
965 { COMMAND_REG, CR_EXTSTAT_RESET },
967 { COMMAND_REG, CR_EXTSTAT_RESET },
970 if (!(port->gs.port.flags & ASYNC_INITIALIZED)) {
971 local_irq_save(flags);
972 #if defined(CONFIG_MVME147_SCC) || defined(CONFIG_MVME162_SCC)
973 if (MACH_IS_MVME147 || MACH_IS_MVME16x) {
974 for (i = 0; i < ARRAY_SIZE(mvme_init_tab); ++i)
975 SCCwrite(mvme_init_tab[i].reg, mvme_init_tab[i].val);
978 #if defined(CONFIG_BVME6000_SCC)
979 if (MACH_IS_BVME6000) {
980 for (i = 0; i < ARRAY_SIZE(bvme_init_tab); ++i)
981 SCCwrite(bvme_init_tab[i].reg, bvme_init_tab[i].val);
985 /* remember status register for detection of DCD and CTS changes */
986 scc_last_status_reg[channel] = SCCread(STATUS_REG);
988 port->c_dcd = 0; /* Prevent initial 1->0 interrupt */
989 scc_setsignals (port, 1,1);
990 local_irq_restore(flags);
993 tty->driver_data = port;
994 port->gs.port.tty = tty;
995 port->gs.port.count++;
996 retval = gs_init_port(&port->gs);
998 port->gs.port.count--;
1001 port->gs.port.flags |= GS_ACTIVE;
1002 retval = gs_block_til_ready(port, filp);
1005 port->gs.port.count--;
1009 port->c_dcd = tty_port_carrier_raised(&port->gs.port);
1011 scc_enable_rx_interrupts(port);
1017 static void scc_throttle (struct tty_struct * tty)
1019 struct scc_port *port = tty->driver_data;
1020 unsigned long flags;
1021 SCC_ACCESS_INIT(port);
1023 if (tty->termios->c_cflag & CRTSCTS) {
1024 local_irq_save(flags);
1025 SCCmod(TX_CTRL_REG, ~TCR_RTS, 0);
1026 local_irq_restore(flags);
1029 scc_send_xchar(tty, STOP_CHAR(tty));
1033 static void scc_unthrottle (struct tty_struct * tty)
1035 struct scc_port *port = tty->driver_data;
1036 unsigned long flags;
1037 SCC_ACCESS_INIT(port);
1039 if (tty->termios->c_cflag & CRTSCTS) {
1040 local_irq_save(flags);
1041 SCCmod(TX_CTRL_REG, 0xff, TCR_RTS);
1042 local_irq_restore(flags);
1045 scc_send_xchar(tty, START_CHAR(tty));
1049 static int scc_ioctl(struct tty_struct *tty, struct file *file,
1050 unsigned int cmd, unsigned long arg)
1052 return -ENOIOCTLCMD;
1056 static int scc_break_ctl(struct tty_struct *tty, int break_state)
1058 struct scc_port *port = tty->driver_data;
1059 unsigned long flags;
1060 SCC_ACCESS_INIT(port);
1062 local_irq_save(flags);
1063 SCCmod(TX_CTRL_REG, ~TCR_SEND_BREAK,
1064 break_state ? TCR_SEND_BREAK : 0);
1065 local_irq_restore(flags);
1070 /*---------------------------------------------------------------------------
1071 * Serial console stuff...
1072 *--------------------------------------------------------------------------*/
1074 #define scc_delay() do { __asm__ __volatile__ (" nop; nop"); } while (0)
1076 static void scc_ch_write (char ch)
1078 volatile char *p = NULL;
1080 #ifdef CONFIG_MVME147_SCC
1081 if (MACH_IS_MVME147)
1082 p = (volatile char *)M147_SCC_A_ADDR;
1084 #ifdef CONFIG_MVME162_SCC
1085 if (MACH_IS_MVME16x)
1086 p = (volatile char *)MVME_SCC_A_ADDR;
1088 #ifdef CONFIG_BVME6000_SCC
1089 if (MACH_IS_BVME6000)
1090 p = (volatile char *)BVME_SCC_A_ADDR;
1103 /* The console must be locked when we get here. */
1105 static void scc_console_write (struct console *co, const char *str, unsigned count)
1107 unsigned long flags;
1109 local_irq_save(flags);
1114 scc_ch_write ('\r');
1115 scc_ch_write (*str++);
1117 local_irq_restore(flags);
1120 static struct tty_driver *scc_console_device(struct console *c, int *index)
1126 static struct console sercons = {
1128 .write = scc_console_write,
1129 .device = scc_console_device,
1130 .flags = CON_PRINTBUFFER,
1135 static int __init vme_scc_console_init(void)
1137 if (vme_brdtype == VME_TYPE_MVME147 ||
1138 vme_brdtype == VME_TYPE_MVME162 ||
1139 vme_brdtype == VME_TYPE_MVME172 ||
1140 vme_brdtype == VME_TYPE_BVME4000 ||
1141 vme_brdtype == VME_TYPE_BVME6000)
1142 register_console(&sercons);
1145 console_initcall(vme_scc_console_init);