[PATCH] libata: ata_dev_init_params() fixes
[powerpc.git] / drivers / serial / sunhv.c
index 71c70d7..f137804 100644 (file)
@@ -21,6 +21,7 @@
 #include <asm/hypervisor.h>
 #include <asm/spitfire.h>
 #include <asm/vdev.h>
+#include <asm/oplib.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);
@@ -427,7 +430,6 @@ 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;
 
@@ -449,16 +451,9 @@ static unsigned int __init get_interrupt(void)
        /* 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 sun4v_vdev_device_interrupt(node);
 }
 
-static u32 sunhv_irq;
-
 static int __init sunhv_init(void)
 {
        struct uart_port *port;
@@ -467,47 +462,65 @@ static int __init sunhv_init(void)
        if (tlb_type != hypervisor)
                return -ENODEV;
 
-       sunhv_irq = get_interrupt();
-       if (!sunhv_irq)
-               return -ENODEV;
-
        port = kmalloc(sizeof(struct uart_port), GFP_KERNEL);
        if (unlikely(!port))
                return -ENOMEM;
 
+       memset(port, 0, sizeof(struct uart_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);
+       /* 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;
        }
 
-       printk("SUNHV: SUN4V virtual console, IRQ[%08x]\n",
-              sunhv_irq);
-
        sunhv_reg.minor = sunserial_current_minor;
        sunhv_reg.nr = 1;
 
        ret = uart_register_driver(&sunhv_reg);
        if (ret < 0) {
-               free_irq(sunhv_irq, up);
+               printk(KERN_ERR "SUNHV: uart_register_driver() failed %d\n",
+                      ret);
                kfree(port);
 
                return ret;
        }
 
+       sunhv_reg.tty_driver->name_base = sunhv_reg.minor - 64;
        sunserial_current_minor += 1;
 
        sunhv_reg.cons = SUNHV_CONSOLE();
 
        sunhv_port = port;
 
-       uart_add_one_port(&sunhv_reg, port);
+       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;
+       }
+
+       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;
+       }
 
        return 0;
 }
@@ -518,9 +531,9 @@ static void __exit sunhv_exit(void)
 
        BUG_ON(!port);
 
-       uart_remove_one_port(&sunhv_reg, port);
-       free_irq(sunhv_irq, port);
+       free_irq(port->irq, port);
 
+       uart_remove_one_port(&sunhv_reg, port);
        sunserial_current_minor -= 1;
 
        uart_unregister_driver(&sunhv_reg);