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/slab.h>
 
  33 #include <linux/miscdevice.h>
 
  34 #include <linux/console.h>
 
  35 #include <linux/init.h>
 
  36 #include <asm/setup.h>
 
  37 #include <asm/bootinfo.h>
 
  39 #ifdef CONFIG_MVME147_SCC
 
  40 #include <asm/mvme147hw.h>
 
  42 #ifdef CONFIG_MVME162_SCC
 
  43 #include <asm/mvme16xhw.h>
 
  45 #ifdef CONFIG_BVME6000_SCC
 
  46 #include <asm/bvme6000hw.h>
 
  49 #include <linux/generic_serial.h>
 
  56 #define SCC_MINOR_BASE  64
 
  58 /* Shadows for all SCC write registers */
 
  59 static unsigned char scc_shadow[2][16];
 
  61 /* Location to access for SCC register access delay */
 
  62 static volatile unsigned char *scc_del = NULL;
 
  64 /* To keep track of STATUS_REG state for detection of Ext/Status int source */
 
  65 static unsigned char scc_last_status_reg[2];
 
  67 /***************************** Prototypes *****************************/
 
  69 /* Function prototypes */
 
  70 static void scc_disable_tx_interrupts(void * ptr);
 
  71 static void scc_enable_tx_interrupts(void * ptr);
 
  72 static void scc_disable_rx_interrupts(void * ptr);
 
  73 static void scc_enable_rx_interrupts(void * ptr);
 
  74 static int  scc_get_CD(void * ptr);
 
  75 static void scc_shutdown_port(void * ptr);
 
  76 static int scc_set_real_termios(void  *ptr);
 
  77 static void scc_hungup(void  *ptr);
 
  78 static void scc_close(void  *ptr);
 
  79 static int scc_chars_in_buffer(void * ptr);
 
  80 static int scc_open(struct tty_struct * tty, struct file * filp);
 
  81 static int scc_ioctl(struct tty_struct * tty, struct file * filp,
 
  82                      unsigned int cmd, unsigned long arg);
 
  83 static void scc_throttle(struct tty_struct *tty);
 
  84 static void scc_unthrottle(struct tty_struct *tty);
 
  85 static irqreturn_t scc_tx_int(int irq, void *data, struct pt_regs *fp);
 
  86 static irqreturn_t scc_rx_int(int irq, void *data, struct pt_regs *fp);
 
  87 static irqreturn_t scc_stat_int(int irq, void *data, struct pt_regs *fp);
 
  88 static irqreturn_t scc_spcond_int(int irq, void *data, struct pt_regs *fp);
 
  89 static void scc_setsignals(struct scc_port *port, int dtr, int rts);
 
  90 static void scc_break_ctl(struct tty_struct *tty, int break_state);
 
  92 static struct tty_driver *scc_driver;
 
  94 struct scc_port scc_ports[2];
 
  96 int scc_initialized = 0;
 
  98 /*---------------------------------------------------------------------------
 
  99  * Interface from generic_serial.c back here
 
 100  *--------------------------------------------------------------------------*/
 
 102 static struct real_driver scc_real_driver = {
 
 103         scc_disable_tx_interrupts,
 
 104         scc_enable_tx_interrupts,
 
 105         scc_disable_rx_interrupts,
 
 106         scc_enable_rx_interrupts,
 
 109         scc_set_real_termios,
 
 117 static struct tty_operations scc_ops = {
 
 121         .put_char = gs_put_char,
 
 122         .flush_chars = gs_flush_chars,
 
 123         .write_room = gs_write_room,
 
 124         .chars_in_buffer = gs_chars_in_buffer,
 
 125         .flush_buffer = gs_flush_buffer,
 
 127         .throttle = scc_throttle,
 
 128         .unthrottle = scc_unthrottle,
 
 129         .set_termios = gs_set_termios,
 
 133         .break_ctl = scc_break_ctl,
 
 136 /*----------------------------------------------------------------------------
 
 137  * vme_scc_init() and support functions
 
 138  *---------------------------------------------------------------------------*/
 
 140 static int scc_init_drivers(void)
 
 144         scc_driver = alloc_tty_driver(2);
 
 147         scc_driver->owner = THIS_MODULE;
 
 148         scc_driver->driver_name = "scc";
 
 149         scc_driver->name = "ttyS";
 
 150         scc_driver->devfs_name = "tts/";
 
 151         scc_driver->major = TTY_MAJOR;
 
 152         scc_driver->minor_start = SCC_MINOR_BASE;
 
 153         scc_driver->type = TTY_DRIVER_TYPE_SERIAL;
 
 154         scc_driver->subtype = SERIAL_TYPE_NORMAL;
 
 155         scc_driver->init_termios = tty_std_termios;
 
 156         scc_driver->init_termios.c_cflag =
 
 157           B9600 | CS8 | CREAD | HUPCL | CLOCAL;
 
 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                 port->gs.magic = SCC_MAGIC;
 
 183                 port->gs.close_delay = HZ/2;
 
 184                 port->gs.closing_wait = 30 * HZ;
 
 185                 port->gs.rd = &scc_real_driver;
 
 186 #ifdef NEW_WRITE_LOCKING
 
 187                 port->gs.port_write_mutex = MUTEX;
 
 189                 init_waitqueue_head(&port->gs.open_wait);
 
 190                 init_waitqueue_head(&port->gs.close_wait);
 
 195 #ifdef CONFIG_MVME147_SCC
 
 196 static int mvme147_scc_init(void)
 
 198         struct scc_port *port;
 
 200         printk(KERN_INFO "SCC: MVME147 Serial Driver\n");
 
 202         port = &scc_ports[0];
 
 203         port->channel = CHANNEL_A;
 
 204         port->ctrlp = (volatile unsigned char *)M147_SCC_A_ADDR;
 
 205         port->datap = port->ctrlp + 1;
 
 206         port->port_a = &scc_ports[0];
 
 207         port->port_b = &scc_ports[1];
 
 208         request_irq(MVME147_IRQ_SCCA_TX, scc_tx_int, SA_INTERRUPT,
 
 210         request_irq(MVME147_IRQ_SCCA_STAT, scc_stat_int, SA_INTERRUPT,
 
 211                             "SCC-A status", port);
 
 212         request_irq(MVME147_IRQ_SCCA_RX, scc_rx_int, SA_INTERRUPT,
 
 214         request_irq(MVME147_IRQ_SCCA_SPCOND, scc_spcond_int, SA_INTERRUPT,
 
 215                             "SCC-A special cond", port);
 
 217                 SCC_ACCESS_INIT(port);
 
 219                 /* disable interrupts for this channel */
 
 220                 SCCwrite(INT_AND_DMA_REG, 0);
 
 221                 /* Set the interrupt vector */
 
 222                 SCCwrite(INT_VECTOR_REG, MVME147_IRQ_SCC_BASE);
 
 223                 /* Interrupt parameters: vector includes status, status low */
 
 224                 SCCwrite(MASTER_INT_CTRL, MIC_VEC_INCL_STAT);
 
 225                 SCCmod(MASTER_INT_CTRL, 0xff, MIC_MASTER_INT_ENAB);
 
 229         port = &scc_ports[1];
 
 230         port->channel = CHANNEL_B;
 
 231         port->ctrlp = (volatile unsigned char *)M147_SCC_B_ADDR;
 
 232         port->datap = port->ctrlp + 1;
 
 233         port->port_a = &scc_ports[0];
 
 234         port->port_b = &scc_ports[1];
 
 235         request_irq(MVME147_IRQ_SCCB_TX, scc_tx_int, SA_INTERRUPT,
 
 237         request_irq(MVME147_IRQ_SCCB_STAT, scc_stat_int, SA_INTERRUPT,
 
 238                             "SCC-B status", port);
 
 239         request_irq(MVME147_IRQ_SCCB_RX, scc_rx_int, SA_INTERRUPT,
 
 241         request_irq(MVME147_IRQ_SCCB_SPCOND, scc_spcond_int, SA_INTERRUPT,
 
 242                             "SCC-B special cond", port);
 
 244                 SCC_ACCESS_INIT(port);
 
 246                 /* disable interrupts for this channel */
 
 247                 SCCwrite(INT_AND_DMA_REG, 0);
 
 250         /* Ensure interrupts are enabled in the PCC chip */
 
 251         m147_pcc->serial_cntrl=PCC_LEVEL_SERIAL|PCC_INT_ENAB;
 
 253         /* Initialise the tty driver structures and register */
 
 254         scc_init_portstructs();
 
 262 #ifdef CONFIG_MVME162_SCC
 
 263 static int mvme162_scc_init(void)
 
 265         struct scc_port *port;
 
 267         if (!(mvme16x_config & MVME16x_CONFIG_GOT_SCCA))
 
 270         printk(KERN_INFO "SCC: MVME162 Serial Driver\n");
 
 272         port = &scc_ports[0];
 
 273         port->channel = CHANNEL_A;
 
 274         port->ctrlp = (volatile unsigned char *)MVME_SCC_A_ADDR;
 
 275         port->datap = port->ctrlp + 2;
 
 276         port->port_a = &scc_ports[0];
 
 277         port->port_b = &scc_ports[1];
 
 278         request_irq(MVME162_IRQ_SCCA_TX, scc_tx_int, SA_INTERRUPT,
 
 280         request_irq(MVME162_IRQ_SCCA_STAT, scc_stat_int, SA_INTERRUPT,
 
 281                             "SCC-A status", port);
 
 282         request_irq(MVME162_IRQ_SCCA_RX, scc_rx_int, SA_INTERRUPT,
 
 284         request_irq(MVME162_IRQ_SCCA_SPCOND, scc_spcond_int, SA_INTERRUPT,
 
 285                             "SCC-A special cond", port);
 
 287                 SCC_ACCESS_INIT(port);
 
 289                 /* disable interrupts for this channel */
 
 290                 SCCwrite(INT_AND_DMA_REG, 0);
 
 291                 /* Set the interrupt vector */
 
 292                 SCCwrite(INT_VECTOR_REG, MVME162_IRQ_SCC_BASE);
 
 293                 /* Interrupt parameters: vector includes status, status low */
 
 294                 SCCwrite(MASTER_INT_CTRL, MIC_VEC_INCL_STAT);
 
 295                 SCCmod(MASTER_INT_CTRL, 0xff, MIC_MASTER_INT_ENAB);
 
 299         port = &scc_ports[1];
 
 300         port->channel = CHANNEL_B;
 
 301         port->ctrlp = (volatile unsigned char *)MVME_SCC_B_ADDR;
 
 302         port->datap = port->ctrlp + 2;
 
 303         port->port_a = &scc_ports[0];
 
 304         port->port_b = &scc_ports[1];
 
 305         request_irq(MVME162_IRQ_SCCB_TX, scc_tx_int, SA_INTERRUPT,
 
 307         request_irq(MVME162_IRQ_SCCB_STAT, scc_stat_int, SA_INTERRUPT,
 
 308                             "SCC-B status", port);
 
 309         request_irq(MVME162_IRQ_SCCB_RX, scc_rx_int, SA_INTERRUPT,
 
 311         request_irq(MVME162_IRQ_SCCB_SPCOND, scc_spcond_int, SA_INTERRUPT,
 
 312                             "SCC-B special cond", port);
 
 315                 SCC_ACCESS_INIT(port);  /* Either channel will do */
 
 317                 /* disable interrupts for this channel */
 
 318                 SCCwrite(INT_AND_DMA_REG, 0);
 
 321         /* Ensure interrupts are enabled in the MC2 chip */
 
 322         *(volatile char *)0xfff4201d = 0x14;
 
 324         /* Initialise the tty driver structures and register */
 
 325         scc_init_portstructs();
 
 333 #ifdef CONFIG_BVME6000_SCC
 
 334 static int bvme6000_scc_init(void)
 
 336         struct scc_port *port;
 
 338         printk(KERN_INFO "SCC: BVME6000 Serial Driver\n");
 
 340         port = &scc_ports[0];
 
 341         port->channel = CHANNEL_A;
 
 342         port->ctrlp = (volatile unsigned char *)BVME_SCC_A_ADDR;
 
 343         port->datap = port->ctrlp + 4;
 
 344         port->port_a = &scc_ports[0];
 
 345         port->port_b = &scc_ports[1];
 
 346         request_irq(BVME_IRQ_SCCA_TX, scc_tx_int, SA_INTERRUPT,
 
 348         request_irq(BVME_IRQ_SCCA_STAT, scc_stat_int, SA_INTERRUPT,
 
 349                             "SCC-A status", port);
 
 350         request_irq(BVME_IRQ_SCCA_RX, scc_rx_int, SA_INTERRUPT,
 
 352         request_irq(BVME_IRQ_SCCA_SPCOND, scc_spcond_int, SA_INTERRUPT,
 
 353                             "SCC-A special cond", port);
 
 355                 SCC_ACCESS_INIT(port);
 
 357                 /* disable interrupts for this channel */
 
 358                 SCCwrite(INT_AND_DMA_REG, 0);
 
 359                 /* Set the interrupt vector */
 
 360                 SCCwrite(INT_VECTOR_REG, BVME_IRQ_SCC_BASE);
 
 361                 /* Interrupt parameters: vector includes status, status low */
 
 362                 SCCwrite(MASTER_INT_CTRL, MIC_VEC_INCL_STAT);
 
 363                 SCCmod(MASTER_INT_CTRL, 0xff, MIC_MASTER_INT_ENAB);
 
 367         port = &scc_ports[1];
 
 368         port->channel = CHANNEL_B;
 
 369         port->ctrlp = (volatile unsigned char *)BVME_SCC_B_ADDR;
 
 370         port->datap = port->ctrlp + 4;
 
 371         port->port_a = &scc_ports[0];
 
 372         port->port_b = &scc_ports[1];
 
 373         request_irq(BVME_IRQ_SCCB_TX, scc_tx_int, SA_INTERRUPT,
 
 375         request_irq(BVME_IRQ_SCCB_STAT, scc_stat_int, SA_INTERRUPT,
 
 376                             "SCC-B status", port);
 
 377         request_irq(BVME_IRQ_SCCB_RX, scc_rx_int, SA_INTERRUPT,
 
 379         request_irq(BVME_IRQ_SCCB_SPCOND, scc_spcond_int, SA_INTERRUPT,
 
 380                             "SCC-B special cond", port);
 
 383                 SCC_ACCESS_INIT(port);  /* Either channel will do */
 
 385                 /* disable interrupts for this channel */
 
 386                 SCCwrite(INT_AND_DMA_REG, 0);
 
 389         /* Initialise the tty driver structures and register */
 
 390         scc_init_portstructs();
 
 398 static int vme_scc_init(void)
 
 402 #ifdef CONFIG_MVME147_SCC
 
 404                 res = mvme147_scc_init();
 
 406 #ifdef CONFIG_MVME162_SCC
 
 408                 res = mvme162_scc_init();
 
 410 #ifdef CONFIG_BVME6000_SCC
 
 411         if (MACH_IS_BVME6000)
 
 412                 res = bvme6000_scc_init();
 
 417 module_init(vme_scc_init);
 
 420 /*---------------------------------------------------------------------------
 
 422  *--------------------------------------------------------------------------*/
 
 424 static irqreturn_t scc_rx_int(int irq, void *data, struct pt_regs *fp)
 
 427         struct scc_port *port = data;
 
 428         struct tty_struct *tty = port->gs.tty;
 
 429         SCC_ACCESS_INIT(port);
 
 431         ch = SCCread_NB(RX_DATA_REG);
 
 433                 printk(KERN_WARNING "scc_rx_int with NULL tty!\n");
 
 434                 SCCwrite_NB(COMMAND_REG, CR_HIGHEST_IUS_RESET);
 
 437         tty_insert_flip_char(tty, ch, 0);
 
 439         /* Check if another character is already ready; in that case, the
 
 440          * spcond_int() function must be used, because this character may have an
 
 441          * error condition that isn't signalled by the interrupt vector used!
 
 443         if (SCCread(INT_PENDING_REG) &
 
 444             (port->channel == CHANNEL_A ? IPR_A_RX : IPR_B_RX)) {
 
 445                 scc_spcond_int (irq, data, fp);
 
 449         SCCwrite_NB(COMMAND_REG, CR_HIGHEST_IUS_RESET);
 
 451         tty_flip_buffer_push(tty);
 
 456 static irqreturn_t scc_spcond_int(int irq, void *data, struct pt_regs *fp)
 
 458         struct scc_port *port = data;
 
 459         struct tty_struct *tty = port->gs.tty;
 
 460         unsigned char   stat, ch, err;
 
 461         int             int_pending_mask = port->channel == CHANNEL_A ?
 
 463         SCC_ACCESS_INIT(port);
 
 466                 printk(KERN_WARNING "scc_spcond_int with NULL tty!\n");
 
 467                 SCCwrite(COMMAND_REG, CR_ERROR_RESET);
 
 468                 SCCwrite_NB(COMMAND_REG, CR_HIGHEST_IUS_RESET);
 
 472                 stat = SCCread(SPCOND_STATUS_REG);
 
 473                 ch = SCCread_NB(RX_DATA_REG);
 
 475                 if (stat & SCSR_RX_OVERRUN)
 
 477                 else if (stat & SCSR_PARITY_ERR)
 
 479                 else if (stat & SCSR_CRC_FRAME_ERR)
 
 484                 tty_insert_flip_char(tty, ch, err);
 
 486                 /* ++TeSche: *All* errors have to be cleared manually,
 
 487                  * else the condition persists for the next chars
 
 490                   SCCwrite(COMMAND_REG, CR_ERROR_RESET);
 
 492         } while(SCCread(INT_PENDING_REG) & int_pending_mask);
 
 494         SCCwrite_NB(COMMAND_REG, CR_HIGHEST_IUS_RESET);
 
 496         tty_flip_buffer_push(tty);
 
 501 static irqreturn_t scc_tx_int(int irq, void *data, struct pt_regs *fp)
 
 503         struct scc_port *port = data;
 
 504         SCC_ACCESS_INIT(port);
 
 507                 printk(KERN_WARNING "scc_tx_int with NULL tty!\n");
 
 508                 SCCmod (INT_AND_DMA_REG, ~IDR_TX_INT_ENAB, 0);
 
 509                 SCCwrite(COMMAND_REG, CR_TX_PENDING_RESET);
 
 510                 SCCwrite_NB(COMMAND_REG, CR_HIGHEST_IUS_RESET);
 
 513         while ((SCCread_NB(STATUS_REG) & SR_TX_BUF_EMPTY)) {
 
 515                         SCCwrite(TX_DATA_REG, port->x_char);
 
 518                 else if ((port->gs.xmit_cnt <= 0) || port->gs.tty->stopped ||
 
 519                                 port->gs.tty->hw_stopped)
 
 522                         SCCwrite(TX_DATA_REG, port->gs.xmit_buf[port->gs.xmit_tail++]);
 
 523                         port->gs.xmit_tail = port->gs.xmit_tail & (SERIAL_XMIT_SIZE-1);
 
 524                         if (--port->gs.xmit_cnt <= 0)
 
 528         if ((port->gs.xmit_cnt <= 0) || port->gs.tty->stopped ||
 
 529                         port->gs.tty->hw_stopped) {
 
 530                 /* disable tx interrupts */
 
 531                 SCCmod (INT_AND_DMA_REG, ~IDR_TX_INT_ENAB, 0);
 
 532                 SCCwrite(COMMAND_REG, CR_TX_PENDING_RESET);   /* disable tx_int on next tx underrun? */
 
 533                 port->gs.flags &= ~GS_TX_INTEN;
 
 535         if (port->gs.tty && port->gs.xmit_cnt <= port->gs.wakeup_chars)
 
 536                 tty_wakeup(port->gs.tty);
 
 538         SCCwrite_NB(COMMAND_REG, CR_HIGHEST_IUS_RESET);
 
 543 static irqreturn_t scc_stat_int(int irq, void *data, struct pt_regs *fp)
 
 545         struct scc_port *port = data;
 
 546         unsigned channel = port->channel;
 
 547         unsigned char   last_sr, sr, changed;
 
 548         SCC_ACCESS_INIT(port);
 
 550         last_sr = scc_last_status_reg[channel];
 
 551         sr = scc_last_status_reg[channel] = SCCread_NB(STATUS_REG);
 
 552         changed = last_sr ^ sr;
 
 554         if (changed & SR_DCD) {
 
 555                 port->c_dcd = !!(sr & SR_DCD);
 
 556                 if (!(port->gs.flags & ASYNC_CHECK_CD))
 
 557                         ;       /* Don't report DCD changes */
 
 558                 else if (port->c_dcd) {
 
 559                         wake_up_interruptible(&port->gs.open_wait);
 
 563                                 tty_hangup (port->gs.tty);
 
 566         SCCwrite(COMMAND_REG, CR_EXTSTAT_RESET);
 
 567         SCCwrite_NB(COMMAND_REG, CR_HIGHEST_IUS_RESET);
 
 572 /*---------------------------------------------------------------------------
 
 573  * generic_serial.c callback funtions
 
 574  *--------------------------------------------------------------------------*/
 
 576 static void scc_disable_tx_interrupts(void *ptr)
 
 578         struct scc_port *port = ptr;
 
 580         SCC_ACCESS_INIT(port);
 
 582         local_irq_save(flags);
 
 583         SCCmod(INT_AND_DMA_REG, ~IDR_TX_INT_ENAB, 0);
 
 584         port->gs.flags &= ~GS_TX_INTEN;
 
 585         local_irq_restore(flags);
 
 589 static void scc_enable_tx_interrupts(void *ptr)
 
 591         struct scc_port *port = ptr;
 
 593         SCC_ACCESS_INIT(port);
 
 595         local_irq_save(flags);
 
 596         SCCmod(INT_AND_DMA_REG, 0xff, IDR_TX_INT_ENAB);
 
 597         /* restart the transmitter */
 
 598         scc_tx_int (0, port, 0);
 
 599         local_irq_restore(flags);
 
 603 static void scc_disable_rx_interrupts(void *ptr)
 
 605         struct scc_port *port = ptr;
 
 607         SCC_ACCESS_INIT(port);
 
 609         local_irq_save(flags);
 
 610         SCCmod(INT_AND_DMA_REG,
 
 611             ~(IDR_RX_INT_MASK|IDR_PARERR_AS_SPCOND|IDR_EXTSTAT_INT_ENAB), 0);
 
 612         local_irq_restore(flags);
 
 616 static void scc_enable_rx_interrupts(void *ptr)
 
 618         struct scc_port *port = ptr;
 
 620         SCC_ACCESS_INIT(port);
 
 622         local_irq_save(flags);
 
 623         SCCmod(INT_AND_DMA_REG, 0xff,
 
 624                 IDR_EXTSTAT_INT_ENAB|IDR_PARERR_AS_SPCOND|IDR_RX_INT_ALL);
 
 625         local_irq_restore(flags);
 
 629 static int scc_get_CD(void *ptr)
 
 631         struct scc_port *port = ptr;
 
 632         unsigned channel = port->channel;
 
 634         return !!(scc_last_status_reg[channel] & SR_DCD);
 
 638 static void scc_shutdown_port(void *ptr)
 
 640         struct scc_port *port = ptr;
 
 642         port->gs.flags &= ~ GS_ACTIVE;
 
 643         if (port->gs.tty && port->gs.tty->termios->c_cflag & HUPCL) {
 
 644                 scc_setsignals (port, 0, 0);
 
 649 static int scc_set_real_termios (void *ptr)
 
 651         /* the SCC has char sizes 5,7,6,8 in that order! */
 
 652         static int chsize_map[4] = { 0, 2, 1, 3 };
 
 653         unsigned cflag, baud, chsize, channel, brgval = 0;
 
 655         struct scc_port *port = ptr;
 
 656         SCC_ACCESS_INIT(port);
 
 658         if (!port->gs.tty || !port->gs.tty->termios) return 0;
 
 660         channel = port->channel;
 
 662         if (channel == CHANNEL_A)
 
 663                 return 0;               /* Settings controlled by boot PROM */
 
 665         cflag  = port->gs.tty->termios->c_cflag;
 
 666         baud = port->gs.baud;
 
 667         chsize = (cflag & CSIZE) >> 4;
 
 670                 /* speed == 0 -> drop DTR */
 
 671                 local_irq_save(flags);
 
 672                 SCCmod(TX_CTRL_REG, ~TCR_DTR, 0);
 
 673                 local_irq_restore(flags);
 
 676         else if ((MACH_IS_MVME16x && (baud < 50 || baud > 38400)) ||
 
 677                  (MACH_IS_MVME147 && (baud < 50 || baud > 19200)) ||
 
 678                  (MACH_IS_BVME6000 &&(baud < 50 || baud > 76800))) {
 
 679                 printk(KERN_NOTICE "SCC: Bad speed requested, %d\n", baud);
 
 684                 port->gs.flags &= ~ASYNC_CHECK_CD;
 
 686                 port->gs.flags |= ASYNC_CHECK_CD;
 
 688 #ifdef CONFIG_MVME147_SCC
 
 690                 brgval = (M147_SCC_PCLK + baud/2) / (16 * 2 * baud) - 2;
 
 692 #ifdef CONFIG_MVME162_SCC
 
 694                 brgval = (MVME_SCC_PCLK + baud/2) / (16 * 2 * baud) - 2;
 
 696 #ifdef CONFIG_BVME6000_SCC
 
 697         if (MACH_IS_BVME6000)
 
 698                 brgval = (BVME_SCC_RTxC + baud/2) / (16 * 2 * baud) - 2;
 
 700         /* Now we have all parameters and can go to set them: */
 
 701         local_irq_save(flags);
 
 703         /* receiver's character size and auto-enables */
 
 704         SCCmod(RX_CTRL_REG, ~(RCR_CHSIZE_MASK|RCR_AUTO_ENAB_MODE),
 
 705                         (chsize_map[chsize] << 6) |
 
 706                         ((cflag & CRTSCTS) ? RCR_AUTO_ENAB_MODE : 0));
 
 707         /* parity and stop bits (both, Tx and Rx), clock mode never changes */
 
 708         SCCmod (AUX1_CTRL_REG,
 
 709                 ~(A1CR_PARITY_MASK | A1CR_MODE_MASK),
 
 711                   ? (cflag & PARODD ? A1CR_PARITY_ODD : A1CR_PARITY_EVEN)
 
 713                  | (cflag & CSTOPB ? A1CR_MODE_ASYNC_2 : A1CR_MODE_ASYNC_1)));
 
 714         /* sender's character size, set DTR for valid baud rate */
 
 715         SCCmod(TX_CTRL_REG, ~TCR_CHSIZE_MASK, chsize_map[chsize] << 5 | TCR_DTR);
 
 716         /* clock sources never change */
 
 717         /* disable BRG before changing the value */
 
 718         SCCmod(DPLL_CTRL_REG, ~DCR_BRG_ENAB, 0);
 
 720         SCCwrite(TIMER_LOW_REG, brgval & 0xff);
 
 721         SCCwrite(TIMER_HIGH_REG, (brgval >> 8) & 0xff);
 
 722         /* BRG enable, and clock source never changes */
 
 723         SCCmod(DPLL_CTRL_REG, 0xff, DCR_BRG_ENAB);
 
 725         local_irq_restore(flags);
 
 731 static int scc_chars_in_buffer (void *ptr)
 
 733         struct scc_port *port = ptr;
 
 734         SCC_ACCESS_INIT(port);
 
 736         return (SCCread (SPCOND_STATUS_REG) & SCSR_ALL_SENT) ? 0  : 1;
 
 740 /* Comment taken from sx.c (2.4.0):
 
 741    I haven't the foggiest why the decrement use count has to happen
 
 742    here. The whole linux serial drivers stuff needs to be redesigned.
 
 743    My guess is that this is a hack to minimize the impact of a bug
 
 744    elsewhere. Thinking about it some more. (try it sometime) Try
 
 745    running minicom on a serial port that is driven by a modularized
 
 746    driver. Have the modem hangup. Then remove the driver module. Then
 
 747    exit minicom.  I expect an "oops".  -- REW */
 
 749 static void scc_hungup(void *ptr)
 
 751         scc_disable_tx_interrupts(ptr);
 
 752         scc_disable_rx_interrupts(ptr);
 
 756 static void scc_close(void *ptr)
 
 758         scc_disable_tx_interrupts(ptr);
 
 759         scc_disable_rx_interrupts(ptr);
 
 763 /*---------------------------------------------------------------------------
 
 764  * Internal support functions
 
 765  *--------------------------------------------------------------------------*/
 
 767 static void scc_setsignals(struct scc_port *port, int dtr, int rts)
 
 771         SCC_ACCESS_INIT(port);
 
 773         local_irq_save(flags);
 
 774         t = SCCread(TX_CTRL_REG);
 
 775         if (dtr >= 0) t = dtr? (t | TCR_DTR): (t & ~TCR_DTR);
 
 776         if (rts >= 0) t = rts? (t | TCR_RTS): (t & ~TCR_RTS);
 
 777         SCCwrite(TX_CTRL_REG, t);
 
 778         local_irq_restore(flags);
 
 782 static void scc_send_xchar(struct tty_struct *tty, char ch)
 
 784         struct scc_port *port = (struct scc_port *)tty->driver_data;
 
 788                 scc_enable_tx_interrupts(port);
 
 792 /*---------------------------------------------------------------------------
 
 793  * Driver entrypoints referenced from above
 
 794  *--------------------------------------------------------------------------*/
 
 796 static int scc_open (struct tty_struct * tty, struct file * filp)
 
 798         int line = tty->index;
 
 800         struct scc_port *port = &scc_ports[line];
 
 801         int i, channel = port->channel;
 
 803         SCC_ACCESS_INIT(port);
 
 804 #if defined(CONFIG_MVME162_SCC) || defined(CONFIG_MVME147_SCC)
 
 805         static const struct {
 
 807         } mvme_init_tab[] = {
 
 808                 /* Values for MVME162 and MVME147 */
 
 809                 /* no parity, 1 stop bit, async, 1:16 */
 
 810                 { AUX1_CTRL_REG, A1CR_PARITY_NONE|A1CR_MODE_ASYNC_1|A1CR_CLKMODE_x16 },
 
 811                 /* parity error is special cond, ints disabled, no DMA */
 
 812                 { INT_AND_DMA_REG, IDR_PARERR_AS_SPCOND | IDR_RX_INT_DISAB },
 
 813                 /* Rx 8 bits/char, no auto enable, Rx off */
 
 814                 { RX_CTRL_REG, RCR_CHSIZE_8 },
 
 815                 /* DTR off, Tx 8 bits/char, RTS off, Tx off */
 
 816                 { TX_CTRL_REG, TCR_CHSIZE_8 },
 
 817                 /* special features off */
 
 818                 { AUX2_CTRL_REG, 0 },
 
 819                 { CLK_CTRL_REG, CCR_RXCLK_BRG | CCR_TXCLK_BRG },
 
 820                 { DPLL_CTRL_REG, DCR_BRG_ENAB | DCR_BRG_USE_PCLK },
 
 822                 { RX_CTRL_REG, RCR_RX_ENAB | RCR_CHSIZE_8 },
 
 824                 { TX_CTRL_REG, TCR_TX_ENAB | TCR_RTS | TCR_DTR | TCR_CHSIZE_8 },
 
 825                 /* Ext/Stat ints: DCD only */
 
 826                 { INT_CTRL_REG, ICR_ENAB_DCD_INT },
 
 827                 /* Reset Ext/Stat ints */
 
 828                 { COMMAND_REG, CR_EXTSTAT_RESET },
 
 830                 { COMMAND_REG, CR_EXTSTAT_RESET },
 
 833 #if defined(CONFIG_BVME6000_SCC)
 
 834         static const struct {
 
 836         } bvme_init_tab[] = {
 
 837                 /* Values for BVME6000 */
 
 838                 /* no parity, 1 stop bit, async, 1:16 */
 
 839                 { AUX1_CTRL_REG, A1CR_PARITY_NONE|A1CR_MODE_ASYNC_1|A1CR_CLKMODE_x16 },
 
 840                 /* parity error is special cond, ints disabled, no DMA */
 
 841                 { INT_AND_DMA_REG, IDR_PARERR_AS_SPCOND | IDR_RX_INT_DISAB },
 
 842                 /* Rx 8 bits/char, no auto enable, Rx off */
 
 843                 { RX_CTRL_REG, RCR_CHSIZE_8 },
 
 844                 /* DTR off, Tx 8 bits/char, RTS off, Tx off */
 
 845                 { TX_CTRL_REG, TCR_CHSIZE_8 },
 
 846                 /* special features off */
 
 847                 { AUX2_CTRL_REG, 0 },
 
 848                 { CLK_CTRL_REG, CCR_RTxC_XTAL | CCR_RXCLK_BRG | CCR_TXCLK_BRG },
 
 849                 { DPLL_CTRL_REG, DCR_BRG_ENAB },
 
 851                 { RX_CTRL_REG, RCR_RX_ENAB | RCR_CHSIZE_8 },
 
 853                 { TX_CTRL_REG, TCR_TX_ENAB | TCR_RTS | TCR_DTR | TCR_CHSIZE_8 },
 
 854                 /* Ext/Stat ints: DCD only */
 
 855                 { INT_CTRL_REG, ICR_ENAB_DCD_INT },
 
 856                 /* Reset Ext/Stat ints */
 
 857                 { COMMAND_REG, CR_EXTSTAT_RESET },
 
 859                 { COMMAND_REG, CR_EXTSTAT_RESET },
 
 862         if (!(port->gs.flags & ASYNC_INITIALIZED)) {
 
 863                 local_irq_save(flags);
 
 864 #if defined(CONFIG_MVME147_SCC) || defined(CONFIG_MVME162_SCC)
 
 865                 if (MACH_IS_MVME147 || MACH_IS_MVME16x) {
 
 866                         for (i = 0; i < ARRAY_SIZE(mvme_init_tab); ++i)
 
 867                                 SCCwrite(mvme_init_tab[i].reg, mvme_init_tab[i].val);
 
 870 #if defined(CONFIG_BVME6000_SCC)
 
 871                 if (MACH_IS_BVME6000) {
 
 872                         for (i = 0; i < ARRAY_SIZE(bvme_init_tab); ++i)
 
 873                                 SCCwrite(bvme_init_tab[i].reg, bvme_init_tab[i].val);
 
 877                 /* remember status register for detection of DCD and CTS changes */
 
 878                 scc_last_status_reg[channel] = SCCread(STATUS_REG);
 
 880                 port->c_dcd = 0;        /* Prevent initial 1->0 interrupt */
 
 881                 scc_setsignals (port, 1,1);
 
 882                 local_irq_restore(flags);
 
 885         tty->driver_data = port;
 
 888         retval = gs_init_port(&port->gs);
 
 893         port->gs.flags |= GS_ACTIVE;
 
 894         retval = gs_block_til_ready(port, filp);
 
 901         port->c_dcd = scc_get_CD (port);
 
 903         scc_enable_rx_interrupts(port);
 
 909 static void scc_throttle (struct tty_struct * tty)
 
 911         struct scc_port *port = (struct scc_port *)tty->driver_data;
 
 913         SCC_ACCESS_INIT(port);
 
 915         if (tty->termios->c_cflag & CRTSCTS) {
 
 916                 local_irq_save(flags);
 
 917                 SCCmod(TX_CTRL_REG, ~TCR_RTS, 0);
 
 918                 local_irq_restore(flags);
 
 921                 scc_send_xchar(tty, STOP_CHAR(tty));
 
 925 static void scc_unthrottle (struct tty_struct * tty)
 
 927         struct scc_port *port = (struct scc_port *)tty->driver_data;
 
 929         SCC_ACCESS_INIT(port);
 
 931         if (tty->termios->c_cflag & CRTSCTS) {
 
 932                 local_irq_save(flags);
 
 933                 SCCmod(TX_CTRL_REG, 0xff, TCR_RTS);
 
 934                 local_irq_restore(flags);
 
 937                 scc_send_xchar(tty, START_CHAR(tty));
 
 941 static int scc_ioctl(struct tty_struct *tty, struct file *file,
 
 942                      unsigned int cmd, unsigned long arg)
 
 948 static void scc_break_ctl(struct tty_struct *tty, int break_state)
 
 950         struct scc_port *port = (struct scc_port *)tty->driver_data;
 
 952         SCC_ACCESS_INIT(port);
 
 954         local_irq_save(flags);
 
 955         SCCmod(TX_CTRL_REG, ~TCR_SEND_BREAK, 
 
 956                         break_state ? TCR_SEND_BREAK : 0);
 
 957         local_irq_restore(flags);
 
 961 /*---------------------------------------------------------------------------
 
 962  * Serial console stuff...
 
 963  *--------------------------------------------------------------------------*/
 
 965 #define scc_delay() do { __asm__ __volatile__ (" nop; nop"); } while (0)
 
 967 static void scc_ch_write (char ch)
 
 969         volatile char *p = NULL;
 
 971 #ifdef CONFIG_MVME147_SCC
 
 973                 p = (volatile char *)M147_SCC_A_ADDR;
 
 975 #ifdef CONFIG_MVME162_SCC
 
 977                 p = (volatile char *)MVME_SCC_A_ADDR;
 
 979 #ifdef CONFIG_BVME6000_SCC
 
 980         if (MACH_IS_BVME6000)
 
 981                 p = (volatile char *)BVME_SCC_A_ADDR;
 
 994 /* The console must be locked when we get here. */
 
 996 static void scc_console_write (struct console *co, const char *str, unsigned count)
 
1000         local_irq_save(flags);
 
1005                         scc_ch_write ('\r');
 
1006                 scc_ch_write (*str++);
 
1008         local_irq_restore(flags);
 
1011 static struct tty_driver *scc_console_device(struct console *c, int *index)
 
1018 static int __init scc_console_setup(struct console *co, char *options)
 
1024 static struct console sercons = {
 
1026         .write          = scc_console_write,
 
1027         .device         = scc_console_device,
 
1028         .setup          = scc_console_setup,
 
1029         .flags          = CON_PRINTBUFFER,
 
1034 static int __init vme_scc_console_init(void)
 
1036         if (vme_brdtype == VME_TYPE_MVME147 ||
 
1037                         vme_brdtype == VME_TYPE_MVME162 ||
 
1038                         vme_brdtype == VME_TYPE_MVME172 ||
 
1039                         vme_brdtype == VME_TYPE_BVME4000 ||
 
1040                         vme_brdtype == VME_TYPE_BVME6000)
 
1041                 register_console(&sercons);
 
1044 console_initcall(vme_scc_console_init);