Cyclades: Avoid label defined but not used warning
[cascardo/linux.git] / drivers / char / cyclades.c
index 0600111..d15234c 100644 (file)
  *
  * Initially written by Randolph Bentson <bentson@grieg.seaslug.org>.
  * Modified and maintained by Marcio Saito <marcio@cyclades.com>.
- * Currently maintained by Cyclades team <async@cyclades.com>.
  *
- * For Technical support and installation problems, please send e-mail
- * to support@cyclades.com.
+ * Copyright (C) 2007 Jiri Slaby <jirislaby@gmail.com>
  *
  * Much of the design and some of the code came from serial.c
  * which was copyright (C) 1991, 1992  Linus Torvalds.  It was
  * extensively rewritten by Theodore Ts'o, 8/16/92 -- 9/14/92,
  * and then fixed as suggested by Michael K. Johnson 12/12/92.
+ * Converted to pci probing and cleaned up by Jiri Slaby.
  *
  * This version supports shared IRQ's (only for PCI boards).
  *
  *
  */
 
-#define CY_VERSION     "2.4"
+#define CY_VERSION     "2.5"
 
 /* If you need to install more boards than NR_CARDS, change the constant
    in the definition below. No other change is necessary to support up to
 #include <linux/delay.h>
 #include <linux/spinlock.h>
 #include <linux/bitops.h>
+#include <linux/firmware.h>
 
 #include <asm/system.h>
 #include <asm/io.h>
 static void cy_throttle(struct tty_struct *tty);
 static void cy_send_xchar(struct tty_struct *tty, char ch);
 
-#define IS_CYC_Z(card) ((card).num_chips == -1)
+#define IS_CYC_Z(card) ((card).num_chips == (unsigned int)-1)
 
 #define Z_FPGA_CHECK(card) \
        ((readl(&((struct RUNTIME_9060 __iomem *) \
@@ -681,6 +681,44 @@ static void cy_send_xchar(struct tty_struct *tty, char ch);
 
 #define STD_COM_FLAGS (0)
 
+/* firmware stuff */
+#define ZL_MAX_BLOCKS  16
+#define DRIVER_VERSION 0x02010203
+#define RAM_SIZE 0x80000
+
+#define Z_FPGA_LOADED(X)       ((readl(&(X)->init_ctrl) & (1<<17)) != 0)
+
+enum zblock_type {
+       ZBLOCK_PRG = 0,
+       ZBLOCK_FPGA = 1
+};
+
+struct zfile_header {
+       char name[64];
+       char date[32];
+       char aux[32];
+       u32 n_config;
+       u32 config_offset;
+       u32 n_blocks;
+       u32 block_offset;
+       u32 reserved[9];
+} __attribute__ ((packed));
+
+struct zfile_config {
+       char name[64];
+       u32 mailbox;
+       u32 function;
+       u32 n_blocks;
+       u32 block_list[ZL_MAX_BLOCKS];
+} __attribute__ ((packed));
+
+struct zfile_block {
+       u32 type;
+       u32 file_offset;
+       u32 ram_offset;
+       u32 size;
+} __attribute__ ((packed));
+
 static struct tty_driver *cy_serial_driver;
 
 #ifdef CONFIG_ISA
@@ -859,71 +897,6 @@ static inline int serial_paranoia_check(struct cyclades_port *info,
        return 0;
 }                              /* serial_paranoia_check */
 
-/*
- * This routine is used by the interrupt handler to schedule
- * processing in the software interrupt portion of the driver
- * (also known as the "bottom half").  This can be called any
- * number of times for any channel without harm.
- */
-static inline void cy_sched_event(struct cyclades_port *info, int event)
-{
-       info->event |= 1 << event; /* remember what kind of event and who */
-       schedule_work(&info->tqueue);
-}                              /* cy_sched_event */
-
-/*
- * This routine is used to handle the "bottom half" processing for the
- * serial driver, known also the "software interrupt" processing.
- * This processing is done at the kernel interrupt level, after the
- * cy#/_interrupt() has returned, BUT WITH INTERRUPTS TURNED ON.  This
- * is where time-consuming activities which can not be done in the
- * interrupt driver proper are done; the interrupt driver schedules
- * them using cy_sched_event(), and they get done here.
- *
- * This is done through one level of indirection--the task queue.
- * When a hardware interrupt service routine wants service by the
- * driver's bottom half, it enqueues the appropriate tq_struct (one
- * per port) to the keventd work queue and sets a request flag
- * that the work queue be processed.
- *
- * Although this may seem unwieldy, it gives the system a way to
- * pass an argument (in this case the pointer to the cyclades_port
- * structure) to the bottom half of the driver.  Previous kernels
- * had to poll every port to see if that port needed servicing.
- */
-static void
-do_softint(struct work_struct *work)
-{
-       struct cyclades_port *info =
-               container_of(work, struct cyclades_port, tqueue);
-       struct tty_struct    *tty;
-
-       tty = info->tty;
-       if (!tty)
-               return;
-
-       if (test_and_clear_bit(Cy_EVENT_HANGUP, &info->event)) {
-               tty_hangup(info->tty);
-               wake_up_interruptible(&info->open_wait);
-                       info->flags &= ~ASYNC_NORMAL_ACTIVE;
-       }
-       if (test_and_clear_bit(Cy_EVENT_OPEN_WAKEUP, &info->event))
-               wake_up_interruptible(&info->open_wait);
-#ifdef CONFIG_CYZ_INTR
-       if (test_and_clear_bit(Cy_EVENT_Z_RX_FULL, &info->event) &&
-                       !timer_pending(&cyz_rx_full_timer[info->line]))
-               mod_timer(&cyz_rx_full_timer[info->line], jiffies + 1);
-#endif
-       if (test_and_clear_bit(Cy_EVENT_DELTA_WAKEUP, &info->event))
-               wake_up_interruptible(&info->delta_msr_wait);
-       tty_wakeup(tty);
-#ifdef Z_WAKE
-       if (test_and_clear_bit(Cy_EVENT_SHUTDOWN_WAKEUP, &info->event))
-               complete(&info->shutdown_wait);
-#endif
-} /* do_softint */
-
-
 /***********************************************************/
 /********* Start of block of Cyclom-Y specific code ********/
 
@@ -1007,381 +980,332 @@ static unsigned detect_isa_irq(void __iomem * address)
 }
 #endif                         /* CONFIG_ISA */
 
-static void cyy_intr_chip(struct cyclades_card *cinfo, int chip,
-                       void __iomem * base_addr, int status, int index)
+static void cyy_chip_rx(struct cyclades_card *cinfo, int chip,
+               void __iomem *base_addr)
 {
        struct cyclades_port *info;
        struct tty_struct *tty;
-       int char_count;
-       int j, len, mdm_change, mdm_status, outch;
-       int save_xir, channel, save_car;
-       char data;
+       int len, index = cinfo->bus_index;
+       u8 save_xir, channel, save_car, data, char_count;
 
-       if (status & CySRReceive) {     /* reception interrupt */
 #ifdef CY_DEBUG_INTERRUPTS
-               printk(KERN_DEBUG "cyy_interrupt: rcvd intr, chip %d\n", chip);
+       printk(KERN_DEBUG "cyy_interrupt: rcvd intr, chip %d\n", chip);
 #endif
-               /* determine the channel & change to that context */
-               spin_lock(&cinfo->card_lock);
-               save_xir = (u_char) readb(base_addr + (CyRIR << index));
-               channel = (u_short) (save_xir & CyIRChannel);
-               info = &cinfo->ports[channel + chip * 4];
-               save_car = readb(base_addr + (CyCAR << index));
-               cy_writeb(base_addr + (CyCAR << index), save_xir);
-
-               /* if there is nowhere to put the data, discard it */
-               if (info->tty == NULL) {
-                       j = (readb(base_addr + (CyRIVR << index)) &
-                               CyIVRMask);
-                       if (j == CyIVRRxEx) {   /* exception */
+       /* determine the channel & change to that context */
+       save_xir = readb(base_addr + (CyRIR << index));
+       channel = save_xir & CyIRChannel;
+       info = &cinfo->ports[channel + chip * 4];
+       save_car = readb(base_addr + (CyCAR << index));
+       cy_writeb(base_addr + (CyCAR << index), save_xir);
+
+       /* if there is nowhere to put the data, discard it */
+       if (info->tty == NULL) {
+               if ((readb(base_addr + (CyRIVR << index)) & CyIVRMask) ==
+                               CyIVRRxEx) {    /* exception */
+                       data = readb(base_addr + (CyRDSR << index));
+               } else {        /* normal character reception */
+                       char_count = readb(base_addr + (CyRDCR << index));
+                       while (char_count--)
                                data = readb(base_addr + (CyRDSR << index));
-                       } else {        /* normal character reception */
-                               char_count = readb(base_addr +
-                                               (CyRDCR << index));
-                               while (char_count--) {
-                                       data = readb(base_addr +
-                                               (CyRDSR << index));
-                               }
-                       }
-               } else {        /* there is an open port for this data */
-                       tty = info->tty;
-                       j = (readb(base_addr + (CyRIVR << index)) &
-                                       CyIVRMask);
-                       if (j == CyIVRRxEx) {   /* exception */
-                               data = readb(base_addr + (CyRDSR << index));
-
-                               /* For statistics only */
-                               if (data & CyBREAK)
-                                       info->icount.brk++;
-                               else if (data & CyFRAME)
-                                       info->icount.frame++;
-                               else if (data & CyPARITY)
-                                       info->icount.parity++;
-                               else if (data & CyOVERRUN)
-                                       info->icount.overrun++;
-
-                               if (data & info->ignore_status_mask) {
+               }
+               goto end;
+       }
+       /* there is an open port for this data */
+       tty = info->tty;
+       if ((readb(base_addr + (CyRIVR << index)) & CyIVRMask) ==
+                       CyIVRRxEx) {    /* exception */
+               data = readb(base_addr + (CyRDSR << index));
+
+               /* For statistics only */
+               if (data & CyBREAK)
+                       info->icount.brk++;
+               else if (data & CyFRAME)
+                       info->icount.frame++;
+               else if (data & CyPARITY)
+                       info->icount.parity++;
+               else if (data & CyOVERRUN)
+                       info->icount.overrun++;
+
+               if (data & info->ignore_status_mask) {
+                       info->icount.rx++;
+                       return;
+               }
+               if (tty_buffer_request_room(tty, 1)) {
+                       if (data & info->read_status_mask) {
+                               if (data & CyBREAK) {
+                                       tty_insert_flip_char(tty,
+                                               readb(base_addr + (CyRDSR <<
+                                                       index)), TTY_BREAK);
+                                       info->icount.rx++;
+                                       if (info->flags & ASYNC_SAK)
+                                               do_SAK(tty);
+                               } else if (data & CyFRAME) {
+                                       tty_insert_flip_char( tty,
+                                               readb(base_addr + (CyRDSR <<
+                                                       index)), TTY_FRAME);
+                                       info->icount.rx++;
+                                       info->idle_stats.frame_errs++;
+                               } else if (data & CyPARITY) {
+                                       /* Pieces of seven... */
+                                       tty_insert_flip_char(tty,
+                                               readb(base_addr + (CyRDSR <<
+                                                       index)), TTY_PARITY);
+                                       info->icount.rx++;
+                                       info->idle_stats.parity_errs++;
+                               } else if (data & CyOVERRUN) {
+                                       tty_insert_flip_char(tty, 0,
+                                                       TTY_OVERRUN);
+                                       info->icount.rx++;
+                                       /* If the flip buffer itself is
+                                          overflowing, we still lose
+                                          the next incoming character.
+                                        */
+                                       tty_insert_flip_char(tty,
+                                               readb(base_addr + (CyRDSR <<
+                                                       index)), TTY_FRAME);
                                        info->icount.rx++;
-                                       return;
-                               }
-                               if (tty_buffer_request_room(tty, 1)) {
-                                       if (data & info->read_status_mask) {
-                                               if (data & CyBREAK) {
-                                                       tty_insert_flip_char(
-                                                               tty,
-                                                               readb(
-                                                               base_addr +
-                                                               (CyRDSR <<
-                                                                       index)),
-                                                               TTY_BREAK);
-                                                       info->icount.rx++;
-                                                       if (info->flags &
-                                                           ASYNC_SAK) {
-                                                               do_SAK(tty);
-                                                       }
-                                               } else if (data & CyFRAME) {
-                                                       tty_insert_flip_char(
-                                                               tty,
-                                                               readb(
-                                                               base_addr +
-                                                               (CyRDSR <<
-                                                                       index)),
-                                                               TTY_FRAME);
-                                                       info->icount.rx++;
-                                                       info->idle_stats.
-                                                               frame_errs++;
-                                               } else if (data & CyPARITY) {
-                                                       /* Pieces of seven... */
-                                                       tty_insert_flip_char(
-                                                               tty,
-                                                               readb(
-                                                               base_addr +
-                                                               (CyRDSR <<
-                                                                       index)),
-                                                               TTY_PARITY);
-                                                       info->icount.rx++;
-                                                       info->idle_stats.
-                                                               parity_errs++;
-                                               } else if (data & CyOVERRUN) {
-                                                       tty_insert_flip_char(
-                                                               tty, 0,
-                                                               TTY_OVERRUN);
-                                                       info->icount.rx++;
-                                               /* If the flip buffer itself is
-                                                  overflowing, we still lose
-                                                  the next incoming character.
-                                                */
-                                                       tty_insert_flip_char(
-                                                               tty,
-                                                               readb(
-                                                               base_addr +
-                                                               (CyRDSR <<
-                                                                       index)),
-                                                               TTY_FRAME);
-                                                       info->icount.rx++;
-                                                       info->idle_stats.
-                                                               overruns++;
-                                       /* These two conditions may imply */
-                                       /* a normal read should be done. */
-                                       /* }else if(data & CyTIMEOUT){ */
-                                       /* }else if(data & CySPECHAR){ */
-                                               } else {
-                                                       tty_insert_flip_char(
-                                                               tty, 0,
-                                                               TTY_NORMAL);
-                                                       info->icount.rx++;
-                                               }
-                                       } else {
-                                               tty_insert_flip_char(tty, 0,
-                                                               TTY_NORMAL);
-                                               info->icount.rx++;
-                                       }
-                               } else {
-                                       /* there was a software buffer
-                                          overrun and nothing could be
-                                          done about it!!! */
-                                       info->icount.buf_overrun++;
                                        info->idle_stats.overruns++;
+                               /* These two conditions may imply */
+                               /* a normal read should be done. */
+                               /* } else if(data & CyTIMEOUT) { */
+                               /* } else if(data & CySPECHAR) { */
+                               } else {
+                                       tty_insert_flip_char(tty, 0,
+                                                       TTY_NORMAL);
+                                       info->icount.rx++;
                                }
-                       } else {        /* normal character reception */
-                               /* load # chars available from the chip */
-                               char_count = readb(base_addr +
-                                               (CyRDCR << index));
+                       } else {
+                               tty_insert_flip_char(tty, 0, TTY_NORMAL);
+                               info->icount.rx++;
+                       }
+               } else {
+                       /* there was a software buffer overrun and nothing
+                        * could be done about it!!! */
+                       info->icount.buf_overrun++;
+                       info->idle_stats.overruns++;
+               }
+       } else {        /* normal character reception */
+               /* load # chars available from the chip */
+               char_count = readb(base_addr + (CyRDCR << index));
 
 #ifdef CY_ENABLE_MONITORING
-                               ++info->mon.int_count;
-                               info->mon.char_count += char_count;
-                               if (char_count > info->mon.char_max)
-                                       info->mon.char_max = char_count;
-                               info->mon.char_last = char_count;
+               ++info->mon.int_count;
+               info->mon.char_count += char_count;
+               if (char_count > info->mon.char_max)
+                       info->mon.char_max = char_count;
+               info->mon.char_last = char_count;
 #endif
-                               len = tty_buffer_request_room(tty, char_count);
-                               while (len--) {
-                                       data = readb(base_addr +
-                                                       (CyRDSR << index));
-                                       tty_insert_flip_char(tty, data,
-                                                       TTY_NORMAL);
-                                       info->idle_stats.recv_bytes++;
-                                       info->icount.rx++;
+               len = tty_buffer_request_room(tty, char_count);
+               while (len--) {
+                       data = readb(base_addr + (CyRDSR << index));
+                       tty_insert_flip_char(tty, data, TTY_NORMAL);
+                       info->idle_stats.recv_bytes++;
+                       info->icount.rx++;
 #ifdef CY_16Y_HACK
-                                       udelay(10L);
+                       udelay(10L);
 #endif
-                               }
-                               info->idle_stats.recv_idle = jiffies;
-                       }
-                       tty_schedule_flip(tty);
                }
-               /* end of service */
-               cy_writeb(base_addr + (CyRIR << index), (save_xir & 0x3f));
-               cy_writeb(base_addr + (CyCAR << index), (save_car));
-               spin_unlock(&cinfo->card_lock);
+               info->idle_stats.recv_idle = jiffies;
        }
+       tty_schedule_flip(tty);
+end:
+       /* end of service */
+       cy_writeb(base_addr + (CyRIR << index), save_xir & 0x3f);
+       cy_writeb(base_addr + (CyCAR << index), save_car);
+}
+
+static void cyy_chip_tx(struct cyclades_card *cinfo, unsigned int chip,
+               void __iomem *base_addr)
+{
+       struct cyclades_port *info;
+       int char_count, index = cinfo->bus_index;
+       u8 save_xir, channel, save_car, outch;
 
-       if (status & CySRTransmit) {    /* transmission interrupt */
-               /* Since we only get here when the transmit buffer
-                  is empty, we know we can always stuff a dozen
-                  characters. */
+       /* Since we only get here when the transmit buffer
+          is empty, we know we can always stuff a dozen
+          characters. */
 #ifdef CY_DEBUG_INTERRUPTS
-               printk(KERN_DEBUG "cyy_interrupt: xmit intr, chip %d\n", chip);
+       printk(KERN_DEBUG "cyy_interrupt: xmit intr, chip %d\n", chip);
 #endif
 
-               /* determine the channel & change to that context */
-               spin_lock(&cinfo->card_lock);
-               save_xir = (u_char) readb(base_addr + (CyTIR << index));
-               channel = (u_short) (save_xir & CyIRChannel);
-               save_car = readb(base_addr + (CyCAR << index));
-               cy_writeb(base_addr + (CyCAR << index), save_xir);
+       /* determine the channel & change to that context */
+       save_xir = readb(base_addr + (CyTIR << index));
+       channel = save_xir & CyIRChannel;
+       save_car = readb(base_addr + (CyCAR << index));
+       cy_writeb(base_addr + (CyCAR << index), save_xir);
 
-               /* validate the port# (as configured and open) */
-               if (channel + chip * 4 >= cinfo->nports) {
-                       cy_writeb(base_addr + (CySRER << index),
-                                 readb(base_addr + (CySRER << index)) &
-                                 ~CyTxRdy);
-                       goto txend;
-               }
-               info = &cinfo->ports[channel + chip * 4];
-               if (info->tty == NULL) {
-                       cy_writeb(base_addr + (CySRER << index),
-                                 readb(base_addr + (CySRER << index)) &
-                                 ~CyTxRdy);
-                       goto txdone;
-               }
+       /* validate the port# (as configured and open) */
+       if (channel + chip * 4 >= cinfo->nports) {
+               cy_writeb(base_addr + (CySRER << index),
+                         readb(base_addr + (CySRER << index)) & ~CyTxRdy);
+               goto end;
+       }
+       info = &cinfo->ports[channel + chip * 4];
+       if (info->tty == NULL) {
+               cy_writeb(base_addr + (CySRER << index),
+                         readb(base_addr + (CySRER << index)) & ~CyTxRdy);
+               goto end;
+       }
 
-               /* load the on-chip space for outbound data */
-               char_count = info->xmit_fifo_size;
+       /* load the on-chip space for outbound data */
+       char_count = info->xmit_fifo_size;
 
-               if (info->x_char) {     /* send special char */
-                       outch = info->x_char;
-                       cy_writeb(base_addr + (CyTDR << index), outch);
-                       char_count--;
-                       info->icount.tx++;
-                       info->x_char = 0;
-               }
+       if (info->x_char) {     /* send special char */
+               outch = info->x_char;
+               cy_writeb(base_addr + (CyTDR << index), outch);
+               char_count--;
+               info->icount.tx++;
+               info->x_char = 0;
+       }
 
-               if (info->breakon || info->breakoff) {
-                       if (info->breakon) {
-                               cy_writeb(base_addr + (CyTDR << index), 0);
-                               cy_writeb(base_addr + (CyTDR << index), 0x81);
-                               info->breakon = 0;
-                               char_count -= 2;
-                       }
-                       if (info->breakoff) {
-                               cy_writeb(base_addr + (CyTDR << index), 0);
-                               cy_writeb(base_addr + (CyTDR << index), 0x83);
-                               info->breakoff = 0;
-                               char_count -= 2;
-                       }
+       if (info->breakon || info->breakoff) {
+               if (info->breakon) {
+                       cy_writeb(base_addr + (CyTDR << index), 0);
+                       cy_writeb(base_addr + (CyTDR << index), 0x81);
+                       info->breakon = 0;
+                       char_count -= 2;
+               }
+               if (info->breakoff) {
+                       cy_writeb(base_addr + (CyTDR << index), 0);
+                       cy_writeb(base_addr + (CyTDR << index), 0x83);
+                       info->breakoff = 0;
+                       char_count -= 2;
                }
+       }
 
-               while (char_count-- > 0) {
-                       if (!info->xmit_cnt) {
-                               if (readb(base_addr + (CySRER << index)) &
-                                               CyTxMpty) {
-                                       cy_writeb(base_addr + (CySRER << index),
-                                               readb(base_addr +
-                                                       (CySRER << index)) &
+       while (char_count-- > 0) {
+               if (!info->xmit_cnt) {
+                       if (readb(base_addr + (CySRER << index)) & CyTxMpty) {
+                               cy_writeb(base_addr + (CySRER << index),
+                                       readb(base_addr + (CySRER << index)) &
                                                ~CyTxMpty);
-                               } else {
-                                       cy_writeb(base_addr + (CySRER << index),
-                                               (readb(base_addr +
-                                                       (CySRER << index)) &
+                       } else {
+                               cy_writeb(base_addr + (CySRER << index),
+                                       (readb(base_addr + (CySRER << index)) &
                                                ~CyTxRdy) | CyTxMpty);
-                               }
-                               goto txdone;
                        }
-                       if (info->xmit_buf == NULL) {
-                               cy_writeb(base_addr + (CySRER << index),
-                                       readb(base_addr + (CySRER << index)) &
+                       goto done;
+               }
+               if (info->xmit_buf == NULL) {
+                       cy_writeb(base_addr + (CySRER << index),
+                               readb(base_addr + (CySRER << index)) &
                                        ~CyTxRdy);
-                               goto txdone;
-                       }
-                       if (info->tty->stopped || info->tty->hw_stopped) {
-                               cy_writeb(base_addr + (CySRER << index),
-                                       readb(base_addr + (CySRER << index)) &
+                       goto done;
+               }
+               if (info->tty->stopped || info->tty->hw_stopped) {
+                       cy_writeb(base_addr + (CySRER << index),
+                               readb(base_addr + (CySRER << index)) &
                                        ~CyTxRdy);
-                               goto txdone;
-                       }
-                       /* Because the Embedded Transmit Commands have
-                          been enabled, we must check to see if the
-                          escape character, NULL, is being sent.  If it
-                          is, we must ensure that there is room for it
-                          to be doubled in the output stream.  Therefore
-                          we no longer advance the pointer when the
-                          character is fetched, but rather wait until
-                          after the check for a NULL output character.
-                          This is necessary because there may not be
-                          room for the two chars needed to send a NULL.)
-                        */
-                       outch = info->xmit_buf[info->xmit_tail];
-                       if (outch) {
+                       goto done;
+               }
+               /* Because the Embedded Transmit Commands have been enabled,
+                * we must check to see if the escape character, NULL, is being
+                * sent. If it is, we must ensure that there is room for it to
+                * be doubled in the output stream.  Therefore we no longer
+                * advance the pointer when the character is fetched, but
+                * rather wait until after the check for a NULL output
+                * character. This is necessary because there may not be room
+                * for the two chars needed to send a NULL.)
+                */
+               outch = info->xmit_buf[info->xmit_tail];
+               if (outch) {
+                       info->xmit_cnt--;
+                       info->xmit_tail = (info->xmit_tail + 1) &
+                                       (SERIAL_XMIT_SIZE - 1);
+                       cy_writeb(base_addr + (CyTDR << index), outch);
+                       info->icount.tx++;
+               } else {
+                       if (char_count > 1) {
                                info->xmit_cnt--;
                                info->xmit_tail = (info->xmit_tail + 1) &
-                                               (SERIAL_XMIT_SIZE - 1);
+                                       (SERIAL_XMIT_SIZE - 1);
                                cy_writeb(base_addr + (CyTDR << index), outch);
+                               cy_writeb(base_addr + (CyTDR << index), 0);
                                info->icount.tx++;
-                       } else {
-                               if (char_count > 1) {
-                                       info->xmit_cnt--;
-                                       info->xmit_tail = (info->xmit_tail + 1)&
-                                               (SERIAL_XMIT_SIZE - 1);
-                                       cy_writeb(base_addr + (CyTDR << index),
-                                               outch);
-                                       cy_writeb(base_addr + (CyTDR << index),
-                                               0);
-                                       info->icount.tx++;
-                                       char_count--;
-                               }
+                               char_count--;
                        }
                }
-
-txdone:
-               if (info->xmit_cnt < WAKEUP_CHARS) {
-                       cy_sched_event(info, Cy_EVENT_WRITE_WAKEUP);
-               }
-txend:
-               /* end of service */
-               cy_writeb(base_addr + (CyTIR << index), (save_xir & 0x3f));
-               cy_writeb(base_addr + (CyCAR << index), (save_car));
-               spin_unlock(&cinfo->card_lock);
        }
 
-       if (status & CySRModem) {       /* modem interrupt */
+done:
+       tty_wakeup(info->tty);
+end:
+       /* end of service */
+       cy_writeb(base_addr + (CyTIR << index), save_xir & 0x3f);
+       cy_writeb(base_addr + (CyCAR << index), save_car);
+}
 
-               /* determine the channel & change to that context */
-               spin_lock(&cinfo->card_lock);
-               save_xir = (u_char) readb(base_addr + (CyMIR << index));
-               channel = (u_short) (save_xir & CyIRChannel);
-               info = &cinfo->ports[channel + chip * 4];
-               save_car = readb(base_addr + (CyCAR << index));
-               cy_writeb(base_addr + (CyCAR << index), save_xir);
+static void cyy_chip_modem(struct cyclades_card *cinfo, int chip,
+               void __iomem *base_addr)
+{
+       struct cyclades_port *info;
+       int index = cinfo->bus_index;
+       u8 save_xir, channel, save_car, mdm_change, mdm_status;
 
-               mdm_change = readb(base_addr + (CyMISR << index));
-               mdm_status = readb(base_addr + (CyMSVR1 << index));
+       /* determine the channel & change to that context */
+       save_xir = readb(base_addr + (CyMIR << index));
+       channel = save_xir & CyIRChannel;
+       info = &cinfo->ports[channel + chip * 4];
+       save_car = readb(base_addr + (CyCAR << index));
+       cy_writeb(base_addr + (CyCAR << index), save_xir);
 
-               if (info->tty) {
-                       if (mdm_change & CyANY_DELTA) {
-                               /* For statistics only */
-                               if (mdm_change & CyDCD)
-                                       info->icount.dcd++;
-                               if (mdm_change & CyCTS)
-                                       info->icount.cts++;
-                               if (mdm_change & CyDSR)
-                                       info->icount.dsr++;
-                               if (mdm_change & CyRI)
-                                       info->icount.rng++;
-
-                               cy_sched_event(info, Cy_EVENT_DELTA_WAKEUP);
-                       }
+       mdm_change = readb(base_addr + (CyMISR << index));
+       mdm_status = readb(base_addr + (CyMSVR1 << index));
 
-                       if ((mdm_change & CyDCD) &&
-                                       (info->flags & ASYNC_CHECK_CD)) {
-                               if (mdm_status & CyDCD) {
-                                       cy_sched_event(info,
-                                                       Cy_EVENT_OPEN_WAKEUP);
-                               } else {
-                                       cy_sched_event(info, Cy_EVENT_HANGUP);
-                               }
-                       }
-                       if ((mdm_change & CyCTS) &&
-                                       (info->flags & ASYNC_CTS_FLOW)) {
-                               if (info->tty->hw_stopped) {
-                                       if (mdm_status & CyCTS) {
-                                               /* cy_start isn't used
-                                                  because... !!! */
-                                               info->tty->hw_stopped = 0;
-                                               cy_writeb(base_addr +
-                                                       (CySRER << index),
-                                                       readb(base_addr +
-                                                               (CySRER <<
-                                                                       index))|
-                                                       CyTxRdy);
-                                               cy_sched_event(info,
-                                                       Cy_EVENT_WRITE_WAKEUP);
-                                       }
-                               } else {
-                                       if (!(mdm_status & CyCTS)) {
-                                               /* cy_stop isn't used
-                                                  because ... !!! */
-                                               info->tty->hw_stopped = 1;
-                                               cy_writeb(base_addr +
-                                                       (CySRER << index),
-                                                       readb(base_addr +
-                                                               (CySRER <<
-                                                               index)) &
-                                                       ~CyTxRdy);
-                                       }
-                               }
+       if (!info->tty)
+               goto end;
+
+       if (mdm_change & CyANY_DELTA) {
+               /* For statistics only */
+               if (mdm_change & CyDCD)
+                       info->icount.dcd++;
+               if (mdm_change & CyCTS)
+                       info->icount.cts++;
+               if (mdm_change & CyDSR)
+                       info->icount.dsr++;
+               if (mdm_change & CyRI)
+                       info->icount.rng++;
+
+               wake_up_interruptible(&info->delta_msr_wait);
+       }
+
+       if ((mdm_change & CyDCD) && (info->flags & ASYNC_CHECK_CD)) {
+               if (!(mdm_status & CyDCD)) {
+                       tty_hangup(info->tty);
+                       info->flags &= ~ASYNC_NORMAL_ACTIVE;
+               }
+               wake_up_interruptible(&info->open_wait);
+       }
+       if ((mdm_change & CyCTS) && (info->flags & ASYNC_CTS_FLOW)) {
+               if (info->tty->hw_stopped) {
+                       if (mdm_status & CyCTS) {
+                               /* cy_start isn't used
+                                  because... !!! */
+                               info->tty->hw_stopped = 0;
+                               cy_writeb(base_addr + (CySRER << index),
+                                       readb(base_addr + (CySRER << index)) |
+                                               CyTxRdy);
+                               tty_wakeup(info->tty);
                        }
-/*                     if (mdm_change & CyDSR) {
+               } else {
+                       if (!(mdm_status & CyCTS)) {
+                               /* cy_stop isn't used
+                                  because ... !!! */
+                               info->tty->hw_stopped = 1;
+                               cy_writeb(base_addr + (CySRER << index),
+                                       readb(base_addr + (CySRER << index)) &
+                                               ~CyTxRdy);
                        }
-                       if (mdm_change & CyRI) {
-                       }*/
                }
-               /* end of service */
-               cy_writeb(base_addr + (CyMIR << index), (save_xir & 0x3f));
-               cy_writeb(base_addr + (CyCAR << index), save_car);
-               spin_unlock(&cinfo->card_lock);
        }
+/*     if (mdm_change & CyDSR) {
+       }
+       if (mdm_change & CyRI) {
+       }*/
+end:
+       /* end of service */
+       cy_writeb(base_addr + (CyMIR << index), save_xir & 0x3f);
+       cy_writeb(base_addr + (CyCAR << index), save_car);
 }
 
 /* The real interrupt service routine is called
@@ -1393,10 +1317,8 @@ static irqreturn_t cyy_interrupt(int irq, void *dev_id)
        int status;
        struct cyclades_card *cinfo = dev_id;
        void __iomem *base_addr, *card_base_addr;
-       int chip;
+       unsigned int chip, too_many, had_work;
        int index;
-       int too_many;
-       int had_work;
 
        if (unlikely(cinfo == NULL)) {
 #ifdef CY_DEBUG_INTERRUPTS
@@ -1431,11 +1353,16 @@ static irqreturn_t cyy_interrupt(int irq, void *dev_id)
                           chips to be checked in a round-robin fashion (after
                           draining each of a bunch (1000) of characters).
                         */
-                               if (1000 < too_many++) {
+                               if (1000 < too_many++)
                                        break;
-                               }
-                               cyy_intr_chip(cinfo, chip, base_addr, status,
-                                               index);
+                               spin_lock(&cinfo->card_lock);
+                               if (status & CySRReceive) /* rx intr */
+                                       cyy_chip_rx(cinfo, chip, base_addr);
+                               if (status & CySRTransmit) /* tx intr */
+                                       cyy_chip_tx(cinfo, chip, base_addr);
+                               if (status & CySRModem) /* modem intr */
+                                       cyy_chip_modem(cinfo, chip, base_addr);
+                               spin_unlock(&cinfo->card_lock);
                        }
                }
        } while (had_work);
@@ -1490,7 +1417,7 @@ cyz_issue_cmd(struct cyclades_card *cinfo,
        struct ZFW_CTRL __iomem *zfw_ctrl;
        struct BOARD_CTRL __iomem *board_ctrl;
        __u32 __iomem *pci_doorbell;
-       int index;
+       unsigned int index;
 
        firm_id = cinfo->base_addr + ID_ADDRESS;
        if (!ISZLOADED(*cinfo)) {
@@ -1515,13 +1442,12 @@ cyz_issue_cmd(struct cyclades_card *cinfo,
        return 0;
 }                              /* cyz_issue_cmd */
 
-static void
-cyz_handle_rx(struct cyclades_port *info, struct CH_CTRL __iomem *ch_ctrl,
+static void cyz_handle_rx(struct cyclades_port *info,
                struct BUF_CTRL __iomem *buf_ctrl)
 {
        struct cyclades_card *cinfo = info->card;
        struct tty_struct *tty = info->tty;
-       int char_count;
+       unsigned int char_count;
        int len;
 #ifdef BLOCKMOVE
        unsigned char *buf;
@@ -1594,9 +1520,11 @@ cyz_handle_rx(struct cyclades_port *info, struct CH_CTRL __iomem *ch_ctrl,
                                char_count = rx_put - rx_get;
                        else
                                char_count = rx_put - rx_get + rx_bufsize;
-                       if (char_count >= (int)readl(&buf_ctrl->rx_threshold)) {
-                               cy_sched_event(info, Cy_EVENT_Z_RX_FULL);
-                       }
+                       if (char_count >= readl(&buf_ctrl->rx_threshold) &&
+                                       !timer_pending(&cyz_rx_full_timer[
+                                                       info->line]))
+                               mod_timer(&cyz_rx_full_timer[info->line],
+                                               jiffies + 1);
 #endif
                        info->idle_stats.recv_idle = jiffies;
                        tty_schedule_flip(tty);
@@ -1606,14 +1534,13 @@ cyz_handle_rx(struct cyclades_port *info, struct CH_CTRL __iomem *ch_ctrl,
        }
 }
 
-static void
-cyz_handle_tx(struct cyclades_port *info, struct CH_CTRL __iomem *ch_ctrl,
+static void cyz_handle_tx(struct cyclades_port *info,
                struct BUF_CTRL __iomem *buf_ctrl)
 {
        struct cyclades_card *cinfo = info->card;
        struct tty_struct *tty = info->tty;
-       char data;
-       int char_count;
+       u8 data;
+       unsigned int char_count;
 #ifdef BLOCKMOVE
        int small_count;
 #endif
@@ -1678,9 +1605,7 @@ cyz_handle_tx(struct cyclades_port *info, struct CH_CTRL __iomem *ch_ctrl,
                }
 #endif
 ztxdone:
-               if (info->xmit_cnt < WAKEUP_CHARS) {
-                       cy_sched_event(info, Cy_EVENT_WRITE_WAKEUP);
-               }
+               tty_wakeup(tty);
                /* Update tx_put */
                cy_writel(&buf_ctrl->tx_put, tx_put);
        }
@@ -1742,10 +1667,11 @@ static void cyz_handle_cmd(struct cyclades_card *cinfo)
                                if ((fw_ver > 241 ? ((u_long) param) :
                                                readl(&ch_ctrl->rs_status)) &
                                                C_RS_DCD) {
-                                       cy_sched_event(info,
-                                                       Cy_EVENT_OPEN_WAKEUP);
+                                       wake_up_interruptible(&info->open_wait);
                                } else {
-                                       cy_sched_event(info, Cy_EVENT_HANGUP);
+                                       tty_hangup(info->tty);
+                                       wake_up_interruptible(&info->open_wait);
+                                       info->flags &= ~ASYNC_NORMAL_ACTIVE;
                                }
                        }
                        break;
@@ -1763,7 +1689,7 @@ static void cyz_handle_cmd(struct cyclades_card *cinfo)
                        break;
 #ifdef Z_WAKE
                case C_CM_IOCTLW:
-                       cy_sched_event(info, Cy_EVENT_SHUTDOWN_WAKEUP);
+                       complete(&info->shutdown_wait);
                        break;
 #endif
 #ifdef CONFIG_CYZ_INTR
@@ -1775,7 +1701,7 @@ static void cyz_handle_cmd(struct cyclades_card *cinfo)
                        printk(KERN_DEBUG "cyz_interrupt: rcvd intr, card %d, "
                                        "port %ld\n", info->card, channel);
 #endif
-                       cyz_handle_rx(info, ch_ctrl, buf_ctrl);
+                       cyz_handle_rx(info, buf_ctrl);
                        break;
                case C_CM_TXBEMPTY:
                case C_CM_TXLOWWM:
@@ -1785,7 +1711,7 @@ static void cyz_handle_cmd(struct cyclades_card *cinfo)
                        printk(KERN_DEBUG "cyz_interrupt: xmit intr, card %d, "
                                        "port %ld\n", info->card, channel);
 #endif
-                       cyz_handle_tx(info, ch_ctrl, buf_ctrl);
+                       cyz_handle_tx(info, buf_ctrl);
                        break;
 #endif                         /* CONFIG_CYZ_INTR */
                case C_CM_FATAL:
@@ -1795,7 +1721,7 @@ static void cyz_handle_cmd(struct cyclades_card *cinfo)
                        break;
                }
                if (delta_count)
-                       cy_sched_event(info, Cy_EVENT_DELTA_WAKEUP);
+                       wake_up_interruptible(&info->delta_msr_wait);
                if (special_count)
                        tty_schedule_flip(tty);
        }
@@ -1851,13 +1777,12 @@ static void cyz_poll(unsigned long arg)
        struct cyclades_card *cinfo;
        struct cyclades_port *info;
        struct tty_struct *tty;
-       static struct FIRM_ID *firm_id;
-       static struct ZFW_CTRL *zfw_ctrl;
-       static struct BOARD_CTRL *board_ctrl;
-       static struct CH_CTRL *ch_ctrl;
-       static struct BUF_CTRL *buf_ctrl;
+       struct FIRM_ID __iomem *firm_id;
+       struct ZFW_CTRL __iomem *zfw_ctrl;
+       struct BOARD_CTRL __iomem *board_ctrl;
+       struct BUF_CTRL __iomem *buf_ctrl;
        unsigned long expires = jiffies + HZ;
-       int card, port;
+       unsigned int port, card;
 
        for (card = 0; card < NR_CARDS; card++) {
                cinfo = &cy_card[card];
@@ -1884,12 +1809,11 @@ static void cyz_poll(unsigned long arg)
                for (port = 0; port < cinfo->nports; port++) {
                        info = &cinfo->ports[port];
                        tty = info->tty;
-                       ch_ctrl = &(zfw_ctrl->ch_ctrl[port]);
                        buf_ctrl = &(zfw_ctrl->buf_ctrl[port]);
 
                        if (!info->throttle)
-                               cyz_handle_rx(info, ch_ctrl, buf_ctrl);
-                       cyz_handle_tx(info, ch_ctrl, buf_ctrl);
+                               cyz_handle_rx(info, buf_ctrl);
+                       cyz_handle_tx(info, buf_ctrl);
                }
                /* poll every 'cyz_polling_cycle' period */
                expires = jiffies + cyz_polling_cycle;
@@ -1999,7 +1923,6 @@ static int startup(struct cyclades_port *info)
                struct ZFW_CTRL __iomem *zfw_ctrl;
                struct BOARD_CTRL __iomem *board_ctrl;
                struct CH_CTRL __iomem *ch_ctrl;
-               int retval;
 
                base_addr = card->base_addr;
 
@@ -2371,7 +2294,6 @@ block_til_ready(struct tty_struct *tty, struct file *filp,
                struct ZFW_CTRL __iomem *zfw_ctrl;
                struct BOARD_CTRL __iomem *board_ctrl;
                struct CH_CTRL __iomem *ch_ctrl;
-               int retval;
 
                base_addr = cinfo->base_addr;
                firm_id = base_addr + ID_ADDRESS;
@@ -2454,11 +2376,11 @@ block_til_ready(struct tty_struct *tty, struct file *filp,
 static int cy_open(struct tty_struct *tty, struct file *filp)
 {
        struct cyclades_port *info;
-       unsigned int i;
-       int retval, line;
+       unsigned int i, line;
+       int retval;
 
        line = tty->index;
-       if ((line < 0) || (NR_PORTS <= line)) {
+       if ((tty->index < 0) || (NR_PORTS <= line)) {
                return -ENODEV;
        }
        for (i = 0; i < NR_CARDS; i++)
@@ -2775,7 +2697,6 @@ static void cy_close(struct tty_struct *tty, struct file *filp)
        spin_lock_irqsave(&card->card_lock, flags);
 
        tty->closing = 0;
-       info->event = 0;
        info->tty = NULL;
        if (info->blocked_open) {
                spin_unlock_irqrestore(&card->card_lock, flags);
@@ -4127,10 +4048,6 @@ static void cy_set_termios(struct tty_struct *tty, struct ktermios *old_termios)
        printk(KERN_DEBUG "cyc:cy_set_termios ttyC%d\n", info->line);
 #endif
 
-       if (tty->termios->c_cflag == old_termios->c_cflag &&
-                       (tty->termios->c_iflag & (IXON | IXANY)) ==
-                       (old_termios->c_iflag & (IXON | IXANY)))
-               return;
        set_line_char(info);
 
        if ((old_termios->c_cflag & CRTSCTS) &&
@@ -4411,7 +4328,6 @@ static void cy_hangup(struct tty_struct *tty)
 
        cy_flush_buffer(tty);
        shutdown(info);
-       info->event = 0;
        info->count = 0;
 #ifdef CY_DEBUG_COUNT
        printk(KERN_DEBUG "cyc:cy_hangup (%d): setting count to 0\n",
@@ -4433,10 +4349,10 @@ static void cy_hangup(struct tty_struct *tty)
 static int __devinit cy_init_card(struct cyclades_card *cinfo)
 {
        struct cyclades_port *info;
-       u32 mailbox;
-       unsigned int nports;
+       u32 uninitialized_var(mailbox);
+       unsigned int nports, port;
        unsigned short chip_number;
-       int index, port;
+       int uninitialized_var(index);
 
        spin_lock_init(&cinfo->card_lock);
 
@@ -4469,7 +4385,6 @@ static int __devinit cy_init_card(struct cyclades_card *cinfo)
                info->closing_wait = CLOSING_WAIT_DELAY;
                info->close_delay = 5 * HZ / 10;
 
-               INIT_WORK(&info->tqueue, do_softint);
                init_waitqueue_head(&info->open_wait);
                init_waitqueue_head(&info->close_wait);
                init_completion(&info->shutdown_wait);
@@ -4739,17 +4654,295 @@ static int __init cy_detect_isa(void)
 }                              /* cy_detect_isa */
 
 #ifdef CONFIG_PCI
-static void __devinit plx_init(void __iomem * addr, __u32 initctl)
+static inline int __devinit cyc_isfwstr(const char *str, unsigned int size)
+{
+       unsigned int a;
+
+       for (a = 0; a < size && *str; a++, str++)
+               if (*str & 0x80)
+                       return -EINVAL;
+
+       for (; a < size; a++, str++)
+               if (*str)
+                       return -EINVAL;
+
+       return 0;
+}
+
+static inline void __devinit cyz_fpga_copy(void __iomem *fpga, u8 *data,
+               unsigned int size)
+{
+       for (; size > 0; size--) {
+               cy_writel(fpga, *data++);
+               udelay(10);
+       }
+}
+
+static void __devinit plx_init(struct pci_dev *pdev, int irq,
+               struct RUNTIME_9060 __iomem *addr)
 {
        /* Reset PLX */
-       cy_writel(addr + initctl, readl(addr + initctl) | 0x40000000);
+       cy_writel(&addr->init_ctrl, readl(&addr->init_ctrl) | 0x40000000);
        udelay(100L);
-       cy_writel(addr + initctl, readl(addr + initctl) & ~0x40000000);
+       cy_writel(&addr->init_ctrl, readl(&addr->init_ctrl) & ~0x40000000);
 
        /* Reload Config. Registers from EEPROM */
-       cy_writel(addr + initctl, readl(addr + initctl) | 0x20000000);
+       cy_writel(&addr->init_ctrl, readl(&addr->init_ctrl) | 0x20000000);
        udelay(100L);
-       cy_writel(addr + initctl, readl(addr + initctl) & ~0x20000000);
+       cy_writel(&addr->init_ctrl, readl(&addr->init_ctrl) & ~0x20000000);
+
+       /* For some yet unknown reason, once the PLX9060 reloads the EEPROM,
+        * the IRQ is lost and, thus, we have to re-write it to the PCI config.
+        * registers. This will remain here until we find a permanent fix.
+        */
+       pci_write_config_byte(pdev, PCI_INTERRUPT_LINE, irq);
+}
+
+static int __devinit __cyz_load_fw(const struct firmware *fw,
+               const char *name, const u32 mailbox, void __iomem *base,
+               void __iomem *fpga)
+{
+       void *ptr = fw->data;
+       struct zfile_header *h = ptr;
+       struct zfile_config *c, *cs;
+       struct zfile_block *b, *bs;
+       unsigned int a, tmp, len = fw->size;
+#define BAD_FW KERN_ERR "Bad firmware: "
+       if (len < sizeof(*h)) {
+               printk(BAD_FW "too short: %u<%zu\n", len, sizeof(*h));
+               return -EINVAL;
+       }
+
+       cs = ptr + h->config_offset;
+       bs = ptr + h->block_offset;
+
+       if ((void *)(cs + h->n_config) > ptr + len ||
+                       (void *)(bs + h->n_blocks) > ptr + len) {
+               printk(BAD_FW "too short");
+               return  -EINVAL;
+       }
+
+       if (cyc_isfwstr(h->name, sizeof(h->name)) ||
+                       cyc_isfwstr(h->date, sizeof(h->date))) {
+               printk(BAD_FW "bad formatted header string\n");
+               return -EINVAL;
+       }
+
+       if (strncmp(name, h->name, sizeof(h->name))) {
+               printk(BAD_FW "bad name '%s' (expected '%s')\n", h->name, name);
+               return -EINVAL;
+       }
+
+       tmp = 0;
+       for (c = cs; c < cs + h->n_config; c++) {
+               for (a = 0; a < c->n_blocks; a++)
+                       if (c->block_list[a] > h->n_blocks) {
+                               printk(BAD_FW "bad block ref number in cfgs\n");
+                               return -EINVAL;
+                       }
+               if (c->mailbox == mailbox && c->function == 0) /* 0 is normal */
+                       tmp++;
+       }
+       if (!tmp) {
+               printk(BAD_FW "nothing appropriate\n");
+               return -EINVAL;
+       }
+
+       for (b = bs; b < bs + h->n_blocks; b++)
+               if (b->file_offset + b->size > len) {
+                       printk(BAD_FW "bad block data offset\n");
+                       return -EINVAL;
+               }
+
+       /* everything is OK, let's seek'n'load it */
+       for (c = cs; c < cs + h->n_config; c++)
+               if (c->mailbox == mailbox && c->function == 0)
+                       break;
+
+       for (a = 0; a < c->n_blocks; a++) {
+               b = &bs[c->block_list[a]];
+               if (b->type == ZBLOCK_FPGA) {
+                       if (fpga != NULL)
+                               cyz_fpga_copy(fpga, ptr + b->file_offset,
+                                               b->size);
+               } else {
+                       if (base != NULL)
+                               memcpy_toio(base + b->ram_offset,
+                                              ptr + b->file_offset, b->size);
+               }
+       }
+#undef BAD_FW
+       return 0;
+}
+
+static int __devinit cyz_load_fw(struct pci_dev *pdev, void __iomem *base_addr,
+               struct RUNTIME_9060 __iomem *ctl_addr, int irq)
+{
+       const struct firmware *fw;
+       struct FIRM_ID __iomem *fid = base_addr + ID_ADDRESS;
+       struct CUSTOM_REG __iomem *cust = base_addr;
+       struct ZFW_CTRL __iomem *pt_zfwctrl;
+       void __iomem *tmp;
+       u32 mailbox, status;
+       unsigned int i;
+       int retval;
+
+       retval = request_firmware(&fw, "cyzfirm.bin", &pdev->dev);
+       if (retval) {
+               dev_err(&pdev->dev, "can't get firmware\n");
+               goto err;
+       }
+
+       /* Check whether the firmware is already loaded and running. If
+          positive, skip this board */
+       if (Z_FPGA_LOADED(ctl_addr) && readl(&fid->signature) == ZFIRM_ID) {
+               u32 cntval = readl(base_addr + 0x190);
+
+               udelay(100);
+               if (cntval != readl(base_addr + 0x190)) {
+                       /* FW counter is working, FW is running */
+                       dev_dbg(&pdev->dev, "Cyclades-Z FW already loaded. "
+                                       "Skipping board.\n");
+                       retval = 0;
+                       goto err_rel;
+               }
+       }
+
+       /* start boot */
+       cy_writel(&ctl_addr->intr_ctrl_stat, readl(&ctl_addr->intr_ctrl_stat) &
+                       ~0x00030800UL);
+
+       mailbox = readl(&ctl_addr->mail_box_0);
+
+       if (mailbox == 0 || Z_FPGA_LOADED(ctl_addr)) {
+               /* stops CPU and set window to beginning of RAM */
+               cy_writel(&ctl_addr->loc_addr_base, WIN_CREG);
+               cy_writel(&cust->cpu_stop, 0);
+               cy_writel(&ctl_addr->loc_addr_base, WIN_RAM);
+               udelay(100);
+       }
+
+       plx_init(pdev, irq, ctl_addr);
+
+       if (mailbox != 0) {
+               /* load FPGA */
+               retval = __cyz_load_fw(fw, "Cyclom-Z", mailbox, NULL,
+                               base_addr);
+               if (retval)
+                       goto err_rel;
+               if (!Z_FPGA_LOADED(ctl_addr)) {
+                       dev_err(&pdev->dev, "fw upload successful, but fw is "
+                                       "not loaded\n");
+                       goto err_rel;
+               }
+       }
+
+       /* stops CPU and set window to beginning of RAM */
+       cy_writel(&ctl_addr->loc_addr_base, WIN_CREG);
+       cy_writel(&cust->cpu_stop, 0);
+       cy_writel(&ctl_addr->loc_addr_base, WIN_RAM);
+       udelay(100);
+
+       /* clear memory */
+       for (tmp = base_addr; tmp < base_addr + RAM_SIZE; tmp++)
+               cy_writeb(tmp, 255);
+       if (mailbox != 0) {
+               /* set window to last 512K of RAM */
+               cy_writel(&ctl_addr->loc_addr_base, WIN_RAM + RAM_SIZE);
+               //sleep(1);
+               for (tmp = base_addr; tmp < base_addr + RAM_SIZE; tmp++)
+                       cy_writeb(tmp, 255);
+               /* set window to beginning of RAM */
+               cy_writel(&ctl_addr->loc_addr_base, WIN_RAM);
+               //sleep(1);
+       }
+
+       retval = __cyz_load_fw(fw, "Cyclom-Z", mailbox, base_addr, NULL);
+       release_firmware(fw);
+       if (retval)
+               goto err;
+
+       /* finish boot and start boards */
+       cy_writel(&ctl_addr->loc_addr_base, WIN_CREG);
+       cy_writel(&cust->cpu_start, 0);
+       cy_writel(&ctl_addr->loc_addr_base, WIN_RAM);
+       i = 0;
+       while ((status = readl(&fid->signature)) != ZFIRM_ID && i++ < 40)
+               msleep(100);
+       if (status != ZFIRM_ID) {
+               if (status == ZFIRM_HLT) {
+                       dev_err(&pdev->dev, "you need an external power supply "
+                               "for this number of ports. Firmware halted and "
+                               "board reset.\n");
+                       retval = -EIO;
+                       goto err;
+               }
+               dev_warn(&pdev->dev, "fid->signature = 0x%x... Waiting "
+                               "some more time\n", status);
+               while ((status = readl(&fid->signature)) != ZFIRM_ID &&
+                               i++ < 200)
+                       msleep(100);
+               if (status != ZFIRM_ID) {
+                       dev_err(&pdev->dev, "Board not started in 20 seconds! "
+                                       "Giving up. (fid->signature = 0x%x)\n",
+                                       status);
+                       dev_info(&pdev->dev, "*** Warning ***: if you are "
+                               "upgrading the FW, please power cycle the "
+                               "system before loading the new FW to the "
+                               "Cyclades-Z.\n");
+
+                       if (Z_FPGA_LOADED(ctl_addr))
+                               plx_init(pdev, irq, ctl_addr);
+
+                       retval = -EIO;
+                       goto err;
+               }
+               dev_dbg(&pdev->dev, "Firmware started after %d seconds.\n",
+                               i / 10);
+       }
+       pt_zfwctrl = base_addr + readl(&fid->zfwctrl_addr);
+
+       dev_dbg(&pdev->dev, "fid=> %p, zfwctrl_addr=> %x, npt_zfwctrl=> %p\n",
+                       base_addr + ID_ADDRESS, readl(&fid->zfwctrl_addr),
+                       base_addr + readl(&fid->zfwctrl_addr));
+
+       dev_info(&pdev->dev, "Cyclades-Z FW loaded: version = %x, ports = %u\n",
+               readl(&pt_zfwctrl->board_ctrl.fw_version),
+               readl(&pt_zfwctrl->board_ctrl.n_channel));
+
+       if (readl(&pt_zfwctrl->board_ctrl.n_channel) == 0) {
+               dev_warn(&pdev->dev, "no Cyclades-Z ports were found. Please "
+                       "check the connection between the Z host card and the "
+                       "serial expanders.\n");
+
+               if (Z_FPGA_LOADED(ctl_addr))
+                       plx_init(pdev, irq, ctl_addr);
+
+               dev_info(&pdev->dev, "Null number of ports detected. Board "
+                               "reset.\n");
+               retval = 0;
+               goto err;
+       }
+
+       cy_writel(&pt_zfwctrl->board_ctrl.op_system, C_OS_LINUX);
+       cy_writel(&pt_zfwctrl->board_ctrl.dr_version, DRIVER_VERSION);
+
+       /*
+          Early firmware failed to start looking for commands.
+          This enables firmware interrupts for those commands.
+        */
+       cy_writel(&ctl_addr->intr_ctrl_stat, readl(&ctl_addr->intr_ctrl_stat) |
+                       (1 << 17));
+       cy_writel(&ctl_addr->intr_ctrl_stat, readl(&ctl_addr->intr_ctrl_stat) |
+                       0x00030800UL);
+
+       plx_init(pdev, irq, ctl_addr);
+
+       return 0;
+err_rel:
+       release_firmware(fw);
+err:
+       return retval;
 }
 
 static int __devinit cy_pci_probe(struct pci_dev *pdev,
@@ -4831,16 +5024,9 @@ static int __devinit cy_pci_probe(struct pci_dev *pdev,
                }
 
                /* Disable interrupts on the PLX before resetting it */
-               cy_writew(addr0 + 0x68,
-                       readw(addr0 + 0x68) & ~0x0900);
+               cy_writew(addr0 + 0x68, readw(addr0 + 0x68) & ~0x0900);
 
-               plx_init(addr0, 0x6c);
-               /* For some yet unknown reason, once the PLX9060 reloads
-                  the EEPROM, the IRQ is lost and, thus, we have to
-                  re-write it to the PCI config. registers.
-                  This will remain here until we find a permanent
-                  fix. */
-               pci_write_config_byte(pdev, PCI_INTERRUPT_LINE, irq);
+               plx_init(pdev, irq, addr0);
 
                mailbox = (u32)readl(&ctl_addr->mail_box_0);
 
@@ -4881,6 +5067,9 @@ static int __devinit cy_pci_probe(struct pci_dev *pdev,
                        if ((mailbox == ZO_V1) || (mailbox == ZO_V2))
                                cy_writel(addr2 + ID_ADDRESS, 0L);
 
+                       retval = cyz_load_fw(pdev, addr2, addr0, irq);
+                       if (retval)
+                               goto err_unmap;
                        /* This must be a Cyclades-8Zo/PCI.  The extendable
                           version will have a different device_id and will
                           be allocated its maximum number of ports. */
@@ -4929,7 +5118,7 @@ static int __devinit cy_pci_probe(struct pci_dev *pdev,
                        }
                }
 #endif                         /* CONFIG_CYZ_INTR */
-               cy_card[card_no].num_chips = -1;
+               cy_card[card_no].num_chips = (unsigned int)-1;
        }
 
        /* set cy_card */
@@ -4957,15 +5146,7 @@ static int __devinit cy_pci_probe(struct pci_dev *pdev,
                case PLX_9060:
                case PLX_9080:
                default:        /* Old boards, use PLX_9060 */
-
-                       plx_init(addr0, 0x6c);
-               /* For some yet unknown reason, once the PLX9060 reloads
-                  the EEPROM, the IRQ is lost and, thus, we have to
-                  re-write it to the PCI config. registers.
-                  This will remain here until we find a permanent
-                  fix. */
-                       pci_write_config_byte(pdev, PCI_INTERRUPT_LINE, irq);
-
+                       plx_init(pdev, irq, addr0);
                        cy_writew(addr0 + 0x68, readw(addr0 + 0x68) | 0x0900);
                        break;
                }
@@ -5181,13 +5362,13 @@ static int __init cy_init(void)
 #ifdef CONFIG_PCI
        /* look for pci boards */
        retval = pci_register_driver(&cy_pci_driver);
-       if (retval && !nboards)
-               goto err_unr;
+       if (retval && !nboards) {
+               tty_unregister_driver(cy_serial_driver);
+               goto err_frtty;
+       }
 #endif
 
        return 0;
-err_unr:
-       tty_unregister_driver(cy_serial_driver);
 err_frtty:
        put_tty_driver(cy_serial_driver);
 err:
@@ -5197,7 +5378,7 @@ err:
 static void __exit cy_cleanup_module(void)
 {
        struct cyclades_card *card;
-       int i, e1;
+       unsigned int i, e1;
 
 #ifndef CONFIG_CYZ_INTR
        del_timer_sync(&cyz_timerlist);
@@ -5225,8 +5406,7 @@ static void __exit cy_cleanup_module(void)
 #endif /* CONFIG_CYZ_INTR */
                                )
                                free_irq(card->irq, card);
-                       for (e1 = card->first_line;
-                                       e1 < card->first_line +
+                       for (e1 = card->first_line; e1 < card->first_line +
                                        card->nports; e1++)
                                tty_unregister_device(cy_serial_driver, e1);
                        kfree(card->ports);
@@ -5240,3 +5420,4 @@ module_init(cy_init);
 module_exit(cy_cleanup_module);
 
 MODULE_LICENSE("GPL");
+MODULE_VERSION(CY_VERSION);