Merge branch 'release' of git://git.kernel.org/pub/scm/linux/kernel/git/aegl/linux-2.6
[pandora-kernel.git] / drivers / serial / mux.c
index 5ff7e05..953a5ff 100644 (file)
@@ -70,7 +70,36 @@ static struct timer_list mux_timer;
 
 #define UART_PUT_CHAR(p, c) __raw_writel((c), (p)->membase + IO_DATA_REG_OFFSET)
 #define UART_GET_FIFO_CNT(p) __raw_readl((p)->membase + IO_DCOUNT_REG_OFFSET)
-#define GET_MUX_PORTS(iodc_data) ((((iodc_data)[4] & 0xf0) >> 4) * 8) + 8
+
+/**
+ * get_mux_port_count - Get the number of available ports on the Mux.
+ * @dev: The parisc device.
+ *
+ * This function is used to determine the number of ports the Mux
+ * supports.  The IODC data reports the number of ports the Mux
+ * can support, but there are cases where not all the Mux ports
+ * are connected.  This function can override the IODC and
+ * return the true port count.
+ */
+static int __init get_mux_port_count(struct parisc_device *dev)
+{
+       int status;
+       u8 iodc_data[32];
+       unsigned long bytecnt;
+
+       /* If this is the built-in Mux for the K-Class (Eole CAP/MUX),
+        * we only need to allocate resources for 1 port since the
+        * other 7 ports are not connected.
+        */
+       if(dev->id.hversion == 0x15)
+               return 1;
+
+       status = pdc_iodc_read(&bytecnt, dev->hpa.start, 0, iodc_data, 32);
+       BUG_ON(status != PDC_OK);
+
+       /* Return the number of ports specified in the iodc data. */
+       return ((((iodc_data)[4] & 0xf0) >> 4) * 8) + 8;
+}
 
 /**
  * mux_tx_empty - Check if the transmitter fifo is empty.
@@ -214,7 +243,7 @@ static void mux_write(struct uart_port *port)
 static void mux_read(struct uart_port *port)
 {
        int data;
-       struct tty_struct *tty = port->info->tty;
+       struct tty_struct *tty = port->info->port.tty;
        __u32 start_count = port->icount.rx;
 
        while(1) {
@@ -278,8 +307,8 @@ static void mux_shutdown(struct uart_port *port)
  * The Serial Mux does not support this function.
  */
 static void
-mux_set_termios(struct uart_port *port, struct termios *termios,
-               struct termios *old)
+mux_set_termios(struct uart_port *port, struct ktermios *termios,
+               struct ktermios *old)
 {
 }
 
@@ -442,18 +471,10 @@ static struct uart_ops mux_pops = {
  */
 static int __init mux_probe(struct parisc_device *dev)
 {
-       int i, status, port_count;
-       u8 iodc_data[32];
-       unsigned long bytecnt;
-
-       status = pdc_iodc_read(&bytecnt, dev->hpa.start, 0, iodc_data, 32);
-       if(status != PDC_OK) {
-               printk(KERN_ERR "Serial mux: Unable to read IODC.\n");
-               return 1;
-       }
+       int i, status;
 
-       port_count = GET_MUX_PORTS(iodc_data);
-       printk(KERN_INFO "Serial mux driver (%d ports) Revision: 0.5\n", port_count);
+       int port_count = get_mux_port_count(dev);
+       printk(KERN_INFO "Serial mux driver (%d ports) Revision: 0.6\n", port_count);
 
        dev_set_drvdata(&dev->dev, (void *)(long)port_count);
        request_mem_region(dev->hpa.start + MUX_OFFSET,
@@ -491,6 +512,7 @@ static int __init mux_probe(struct parisc_device *dev)
                 */
                port->timeout   = HZ / 50;
                spin_lock_init(&port->lock);
+
                status = uart_add_one_port(&mux_driver, port);
                BUG_ON(status);
        }
@@ -500,12 +522,9 @@ static int __init mux_probe(struct parisc_device *dev)
 
 static int __devexit mux_remove(struct parisc_device *dev)
 {
-       int i;
+       int i, j;
        int port_count = (long)dev_get_drvdata(&dev->dev);
 
-       /* Delete the Mux timer. */
-       del_timer(&mux_timer);
-
        /* Find Port 0 for this card in the mux_ports list. */
        for(i = 0; i < port_cnt; ++i) {
                if(mux_ports[i].port.mapbase == dev->hpa.start + MUX_OFFSET)
@@ -514,7 +533,7 @@ static int __devexit mux_remove(struct parisc_device *dev)
        BUG_ON(i + port_count > port_cnt);
 
        /* Release the resources associated with each port on the device. */
-       for(; i < port_count; ++i) {
+       for(j = 0; j < port_count; ++j, ++i) {
                struct uart_port *port = &mux_ports[i].port;
 
                uart_remove_one_port(&mux_driver, port);
@@ -526,13 +545,35 @@ static int __devexit mux_remove(struct parisc_device *dev)
        return 0;
 }
 
+/* Hack.  This idea was taken from the 8250_gsc.c on how to properly order
+ * the serial port detection in the proper order.   The idea is we always
+ * want the builtin mux to be detected before addin mux cards, so we
+ * specifically probe for the builtin mux cards first.
+ *
+ * This table only contains the parisc_device_id of known builtin mux
+ * devices.  All other mux cards will be detected by the generic mux_tbl.
+ */
+static struct parisc_device_id builtin_mux_tbl[] = {
+       { HPHW_A_DIRECT, HVERSION_REV_ANY_ID, 0x15, 0x0000D }, /* All K-class */
+       { HPHW_A_DIRECT, HVERSION_REV_ANY_ID, 0x44, 0x0000D }, /* E35, E45, and E55 */
+       { 0, }
+};
+
 static struct parisc_device_id mux_tbl[] = {
        { HPHW_A_DIRECT, HVERSION_REV_ANY_ID, HVERSION_ANY_ID, 0x0000D },
        { 0, }
 };
 
+MODULE_DEVICE_TABLE(parisc, builtin_mux_tbl);
 MODULE_DEVICE_TABLE(parisc, mux_tbl);
 
+static struct parisc_driver builtin_serial_mux_driver = {
+       .name =         "builtin_serial_mux",
+       .id_table =     builtin_mux_tbl,
+       .probe =        mux_probe,
+       .remove =       __devexit_p(mux_remove),
+};
+
 static struct parisc_driver serial_mux_driver = {
        .name =         "serial_mux",
        .id_table =     mux_tbl,
@@ -541,13 +582,14 @@ static struct parisc_driver serial_mux_driver = {
 };
 
 /**
- * mux_init - Serial MUX initalization procedure.
+ * mux_init - Serial MUX initialization procedure.
  *
  * Register the Serial MUX driver.
  */
 static int __init mux_init(void)
 {
-       int status = register_parisc_driver(&serial_mux_driver);
+       register_parisc_driver(&builtin_serial_mux_driver);
+       register_parisc_driver(&serial_mux_driver);
 
        if(port_cnt > 0) {
                /* Start the Mux timer */
@@ -560,7 +602,7 @@ static int __init mux_init(void)
 #endif
        }
 
-       return status;
+       return 0;
 }
 
 /**
@@ -578,6 +620,7 @@ static void __exit mux_exit(void)
 #endif
        }
 
+       unregister_parisc_driver(&builtin_serial_mux_driver);
        unregister_parisc_driver(&serial_mux_driver);
        uart_unregister_driver(&mux_driver);
 }