Merge branch 'drm-patches' of git://git.kernel.org/pub/scm/linux/kernel/git/airlied...
[pandora-kernel.git] / drivers / serial / sunhv.c
index f137804..40d4856 100644 (file)
@@ -20,8 +20,8 @@
 
 #include <asm/hypervisor.h>
 #include <asm/spitfire.h>
-#include <asm/vdev.h>
-#include <asm/oplib.h>
+#include <asm/prom.h>
+#include <asm/of_device.h>
 #include <asm/irq.h>
 
 #if defined(CONFIG_MAGIC_SYSRQ)
@@ -73,7 +73,7 @@ static inline long hypervisor_con_putchar(long ch)
 
 static int hung_up = 0;
 
-static struct tty_struct *receive_chars(struct uart_port *port, struct pt_regs *regs)
+static struct tty_struct *receive_chars(struct uart_port *port)
 {
        struct tty_struct *tty = NULL;
        int saw_console_brk = 0;
@@ -106,7 +106,7 @@ static struct tty_struct *receive_chars(struct uart_port *port, struct pt_regs *
                }
 
                if (tty == NULL) {
-                       uart_handle_sysrq_char(port, c, regs);
+                       uart_handle_sysrq_char(port, c);
                        continue;
                }
 
@@ -119,7 +119,7 @@ static struct tty_struct *receive_chars(struct uart_port *port, struct pt_regs *
                        flag = TTY_BREAK;
                }
 
-               if (uart_handle_sysrq_char(port, c, regs))
+               if (uart_handle_sysrq_char(port, c))
                        continue;
 
                if ((port->ignore_status_mask & IGNORE_ALL) ||
@@ -161,14 +161,14 @@ static void transmit_chars(struct uart_port *port)
                uart_write_wakeup(port);
 }
 
-static irqreturn_t sunhv_interrupt(int irq, void *dev_id, struct pt_regs *regs)
+static irqreturn_t sunhv_interrupt(int irq, void *dev_id)
 {
        struct uart_port *port = dev_id;
        struct tty_struct *tty;
        unsigned long flags;
 
        spin_lock_irqsave(&port->lock, flags);
-       tty = receive_chars(port, regs);
+       tty = receive_chars(port);
        transmit_chars(port);
        spin_unlock_irqrestore(&port->lock, flags);
 
@@ -281,8 +281,8 @@ static void sunhv_shutdown(struct uart_port *port)
 }
 
 /* port->lock is not held.  */
-static void sunhv_set_termios(struct uart_port *port, struct termios *termios,
-                             struct termios *old)
+static void sunhv_set_termios(struct uart_port *port, struct ktermios *termios,
+                             struct ktermios *old)
 {
        unsigned int baud = uart_get_baud_rate(port, termios, old, 0, 4000000);
        unsigned int quot = uart_get_divisor(port, baud);
@@ -353,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,
 };
@@ -408,143 +407,120 @@ static inline struct console *SUNHV_CONSOLE(void)
        return &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);
-       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.
-        */
-       return sun4v_vdev_device_interrupt(node);
-}
-
-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;
 
-       port = kmalloc(sizeof(struct uart_port), GFP_KERNEL);
+       port = kzalloc(sizeof(struct uart_port), GFP_KERNEL);
        if (unlikely(!port))
                return -ENOMEM;
 
-       memset(port, 0, sizeof(struct uart_port));
+       sunhv_port = port;
 
        port->line = 0;
        port->ops = &sunhv_pops;
        port->type = PORT_SUNHV;
        port->uartclk = ( 29491200 / 16 ); /* arbitrary */
 
-       /* Set this just to make uart_configure_port() happy.  */
        port->membase = (unsigned char __iomem *) __pa(port);
 
-       port->irq = get_interrupt();
-       if (!port->irq) {
-               kfree(port);
-               return -ENODEV;
-       }
+       port->irq = op->irqs[0];
+
+       port->dev = &op->dev;
 
        sunhv_reg.minor = sunserial_current_minor;
        sunhv_reg.nr = 1;
 
-       ret = uart_register_driver(&sunhv_reg);
-       if (ret < 0) {
-               printk(KERN_ERR "SUNHV: uart_register_driver() failed %d\n",
-                      ret);
-               kfree(port);
-
-               return ret;
-       }
+       err = uart_register_driver(&sunhv_reg);
+       if (err)
+               goto out_free_port;
 
        sunhv_reg.tty_driver->name_base = sunhv_reg.minor - 64;
        sunserial_current_minor += 1;
 
        sunhv_reg.cons = SUNHV_CONSOLE();
 
-       sunhv_port = port;
+       err = uart_add_one_port(&sunhv_reg, port);
+       if (err)
+               goto out_unregister_driver;
 
-       ret = uart_add_one_port(&sunhv_reg, port);
-       if (ret < 0) {
-               printk(KERN_ERR "SUNHV: uart_add_one_port() failed %d\n", ret);
-               sunserial_current_minor -= 1;
-               uart_unregister_driver(&sunhv_reg);
-               kfree(port);
-               sunhv_port = NULL;
-               return -ENODEV;
-       }
+       err = request_irq(port->irq, sunhv_interrupt, 0, "hvcons", port);
+       if (err)
+               goto out_remove_port;
 
-       if (request_irq(port->irq, sunhv_interrupt,
-                       SA_SHIRQ, "serial(sunhv)", port)) {
-               printk(KERN_ERR "sunhv: Cannot register IRQ\n");
-               uart_remove_one_port(&sunhv_reg, port);
-               sunserial_current_minor -= 1;
-               uart_unregister_driver(&sunhv_reg);
-               kfree(port);
-               sunhv_port = NULL;
-               return -ENODEV;
-       }
+       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;
-
-       BUG_ON(!port);
+       struct uart_port *port = dev_get_drvdata(&dev->dev);
 
        free_irq(port->irq, port);
 
        uart_remove_one_port(&sunhv_reg, port);
-       sunserial_current_minor -= 1;
 
+       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");