Input: logips2pp - fix button mapping for MX300
[pandora-kernel.git] / drivers / serial / sunhv.c
index d3a9dd7..f851f0f 100644 (file)
@@ -20,7 +20,8 @@
 
 #include <asm/hypervisor.h>
 #include <asm/spitfire.h>
-#include <asm/vdev.h>
+#include <asm/prom.h>
+#include <asm/of_device.h>
 #include <asm/irq.h>
 
 #if defined(CONFIG_MAGIC_SYSRQ)
@@ -90,6 +91,8 @@ static struct tty_struct *receive_chars(struct uart_port *port, struct pt_regs *
                        break;
 
                if (c == CON_BREAK) {
+                       if (uart_handle_break(port))
+                               continue;
                        saw_console_brk = 1;
                        c = 0;
                }
@@ -135,8 +138,12 @@ static struct tty_struct *receive_chars(struct uart_port *port, struct pt_regs *
 
 static void transmit_chars(struct uart_port *port)
 {
-       struct circ_buf *xmit = &port->info->xmit;
+       struct circ_buf *xmit;
+
+       if (!port->info)
+               return;
 
+       xmit = &port->info->xmit;
        if (uart_circ_empty(xmit) || uart_tx_stopped(port))
                return;
 
@@ -203,9 +210,6 @@ static void sunhv_stop_tx(struct uart_port *port)
 static void sunhv_start_tx(struct uart_port *port)
 {
        struct circ_buf *xmit = &port->info->xmit;
-       unsigned long flags;
-
-       spin_lock_irqsave(&port->lock, flags);
 
        while (!uart_circ_empty(xmit)) {
                long status = hypervisor_con_putchar(xmit->buf[xmit->tail]);
@@ -216,8 +220,6 @@ static void sunhv_start_tx(struct uart_port *port)
                xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE - 1);
                port->icount.tx++;
        }
-
-       spin_unlock_irqrestore(&port->lock, flags);
 }
 
 /* port->lock is not held.  */
@@ -252,7 +254,7 @@ static void sunhv_break_ctl(struct uart_port *port, int break_state)
 {
        if (break_state) {
                unsigned long flags;
-               int limit = 10000;
+               int limit = 1000000;
 
                spin_lock_irqsave(&port->lock, flags);
 
@@ -260,6 +262,7 @@ static void sunhv_break_ctl(struct uart_port *port, int break_state)
                        long status = hypervisor_con_putchar(CON_BREAK);
                        if (status == HV_EOK)
                                break;
+                       udelay(2);
                }
 
                spin_unlock_irqrestore(&port->lock, flags);
@@ -350,7 +353,6 @@ static struct uart_ops sunhv_pops = {
 static struct uart_driver sunhv_reg = {
        .owner                  = THIS_MODULE,
        .driver_name            = "serial",
-       .devfs_name             = "tts/",
        .dev_name               = "ttyS",
        .major                  = TTY_MAJOR,
 };
@@ -360,7 +362,7 @@ static struct uart_port *sunhv_port;
 static inline void sunhv_console_putchar(struct uart_port *port, char c)
 {
        unsigned long flags;
-       int limit = 10000;
+       int limit = 1000000;
 
        spin_lock_irqsave(&port->lock, flags);
 
@@ -368,6 +370,7 @@ static inline void sunhv_console_putchar(struct uart_port *port, char c)
                long status = hypervisor_con_putchar(c);
                if (status == HV_EOK)
                        break;
+               udelay(2);
        }
 
        spin_unlock_irqrestore(&port->lock, flags);
@@ -385,158 +388,139 @@ static void sunhv_console_write(struct console *con, const char *s, unsigned n)
        }
 }
 
-static int sunhv_console_setup(struct console *con, char *options)
-{
-       return 0;
-}
-
 static struct console sunhv_console = {
-       .name   =       "ttyS",
+       .name   =       "ttyHV",
        .write  =       sunhv_console_write,
        .device =       uart_console_device,
-       .setup  =       sunhv_console_setup,
        .flags  =       CON_PRINTBUFFER,
        .index  =       -1,
        .data   =       &sunhv_reg,
 };
 
-static void __init sunhv_console_init(void)
+static inline struct console *SUNHV_CONSOLE(void)
 {
        if (con_is_present())
-               return;
+               return NULL;
 
        sunhv_console.index = 0;
-       register_console(&sunhv_console);
-}
-
-static int __init hv_console_compatible(char *buf, int len)
-{
-       while (len) {
-               int this_len;
-
-               if (!strcmp(buf, "qcn"))
-                       return 1;
-
-               this_len = strlen(buf) + 1;
-
-               buf += this_len;
-               len -= this_len;
-       }
-
-       return 0;
-}
-
-static unsigned int __init get_interrupt(void)
-{
-       const char *cons_str = "console";
-       const char *compat_str = "compatible";
-       int node = prom_getchild(sun4v_vdev_root);
-       unsigned int irq;
-       char buf[64];
-       int err, len;
-
-       node = prom_searchsiblings(node, cons_str);
-       if (!node)
-               return 0;
-
-       len = prom_getproplen(node, compat_str);
-       if (len == 0 || len == -1)
-               return 0;
-
-       err = prom_getproperty(node, compat_str, buf, 64);
-       if (err == -1)
-               return 0;
-
-       if (!hv_console_compatible(buf, len))
-               return 0;
-
-       /* Ok, the this is the OBP node for the sun4v hypervisor
-        * console device.  Decode the interrupt.
-        */
-       err = prom_getproperty(node, "interrupts",
-                              (char *) &irq, sizeof(irq));
-       if (err == -1)
-               return 0;
 
-       return sun4v_build_irq(sun4v_vdev_devhandle, irq, 4, 0);
+       return &sunhv_console;
 }
 
-static u32 sunhv_irq;
-
-static int __init sunhv_init(void)
+static int __devinit hv_probe(struct of_device *op, const struct of_device_id *match)
 {
        struct uart_port *port;
-       int ret;
+       int err;
 
-       if (tlb_type != hypervisor)
+       if (op->irqs[0] == 0xffffffff)
                return -ENODEV;
 
-       sunhv_irq = get_interrupt();
-       if (!sunhv_irq)
-               return -ENODEV;
-
-       port = kmalloc(sizeof(struct uart_port), GFP_KERNEL);
+       port = kzalloc(sizeof(struct uart_port), GFP_KERNEL);
        if (unlikely(!port))
                return -ENOMEM;
 
+       sunhv_port = port;
+
        port->line = 0;
        port->ops = &sunhv_pops;
        port->type = PORT_SUNHV;
        port->uartclk = ( 29491200 / 16 ); /* arbitrary */
 
-       if (request_irq(sunhv_irq, sunhv_interrupt,
-                       SA_SHIRQ, "serial(sunhv)", port)) {
-               printk("sunhv: Cannot get IRQ %x\n", sunhv_irq);
-               kfree(port);
-               return -ENODEV;
-       }
+       port->membase = (unsigned char __iomem *) __pa(port);
+
+       port->irq = op->irqs[0];
 
-       printk("SUNHV: SUN4V virtual console, IRQ[%08x]\n",
-              sunhv_irq);
+       port->dev = &op->dev;
 
        sunhv_reg.minor = sunserial_current_minor;
        sunhv_reg.nr = 1;
-       sunhv_reg.cons = &sunhv_console;
 
-       ret = uart_register_driver(&sunhv_reg);
-       if (ret < 0) {
-               free_irq(sunhv_irq, up);
-               kfree(port);
+       err = uart_register_driver(&sunhv_reg);
+       if (err)
+               goto out_free_port;
 
-               return ret;
-       }
+       sunhv_reg.tty_driver->name_base = sunhv_reg.minor - 64;
+       sunserial_current_minor += 1;
 
-       sunhv_port = port;
+       sunhv_reg.cons = SUNHV_CONSOLE();
 
-       sunserial_current_minor += 1;
+       err = uart_add_one_port(&sunhv_reg, port);
+       if (err)
+               goto out_unregister_driver;
 
-       sunhv_console_init();
+       err = request_irq(port->irq, sunhv_interrupt, 0, "hvcons", port);
+       if (err)
+               goto out_remove_port;
 
-       uart_add_one_port(&sunhv_reg, port);
+       dev_set_drvdata(&op->dev, port);
 
        return 0;
+
+out_remove_port:
+       uart_remove_one_port(&sunhv_reg, port);
+
+out_unregister_driver:
+       sunserial_current_minor -= 1;
+       uart_unregister_driver(&sunhv_reg);
+
+out_free_port:
+       kfree(port);
+       sunhv_port = NULL;
+       return err;
 }
 
-static void __exit sunhv_exit(void)
+static int __devexit hv_remove(struct of_device *dev)
 {
-       struct uart_port *port = sunhv_port;
+       struct uart_port *port = dev_get_drvdata(&dev->dev);
 
-       BUG_ON(!port);
+       free_irq(port->irq, port);
 
        uart_remove_one_port(&sunhv_reg, port);
-       free_irq(sunhv_irq, port);
 
        sunserial_current_minor -= 1;
-
        uart_unregister_driver(&sunhv_reg);
 
-       kfree(sunhv_port);
+       kfree(port);
        sunhv_port = NULL;
+
+       dev_set_drvdata(&dev->dev, NULL);
+
+       return 0;
+}
+
+static struct of_device_id hv_match[] = {
+       {
+               .name = "console",
+               .compatible = "qcn",
+       },
+       {},
+};
+MODULE_DEVICE_TABLE(of, hv_match);
+
+static struct of_platform_driver hv_driver = {
+       .name           = "hv",
+       .match_table    = hv_match,
+       .probe          = hv_probe,
+       .remove         = __devexit_p(hv_remove),
+};
+
+static int __init sunhv_init(void)
+{
+       if (tlb_type != hypervisor)
+               return -ENODEV;
+
+       return of_register_driver(&hv_driver, &of_bus_type);
+}
+
+static void __exit sunhv_exit(void)
+{
+       of_unregister_driver(&hv_driver);
 }
 
 module_init(sunhv_init);
 module_exit(sunhv_exit);
 
 MODULE_AUTHOR("David S. Miller");
-MODULE_DESCRIPTION("SUN4V Hypervisor console driver")
+MODULE_DESCRIPTION("SUN4V Hypervisor console driver");
+MODULE_VERSION("2.0");
 MODULE_LICENSE("GPL");