net: convert /proc/net/rt_acct to seq_file
[safe/jmp/linux-2.6] / drivers / serial / amba-pl010.c
index ea49aaf..429a8ae 100644 (file)
@@ -22,8 +22,6 @@
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  *
- *  $Id: amba.c,v 1.41 2002/07/28 10:03:27 rmk Exp $
- *
  * This is a generic driver for ARM AMBA-type serial ports.  They
  * have a lot of 16550-like features, but are not register compatible.
  * Note that although they do have CTS, DCD and DSR inputs, they do
@@ -48,6 +46,7 @@
 #include <linux/serial.h>
 #include <linux/amba/bus.h>
 #include <linux/amba/serial.h>
+#include <linux/clk.h>
 
 #include <asm/io.h>
 
@@ -70,6 +69,7 @@
  */
 struct uart_amba_port {
        struct uart_port        port;
+       struct clk              *clk;
        struct amba_device      *dev;
        struct amba_pl010_data  *data;
        unsigned int            old_status;
@@ -117,7 +117,7 @@ static void pl010_enable_ms(struct uart_port *port)
 
 static void pl010_rx_chars(struct uart_amba_port *uap)
 {
-       struct tty_struct *tty = uap->port.info->tty;
+       struct tty_struct *tty = uap->port.state->port.tty;
        unsigned int status, ch, flag, rsr, max_count = 256;
 
        status = readb(uap->port.membase + UART01x_FR);
@@ -165,13 +165,14 @@ static void pl010_rx_chars(struct uart_amba_port *uap)
        ignore_char:
                status = readb(uap->port.membase + UART01x_FR);
        }
+       spin_unlock(&uap->port.lock);
        tty_flip_buffer_push(tty);
-       return;
+       spin_lock(&uap->port.lock);
 }
 
 static void pl010_tx_chars(struct uart_amba_port *uap)
 {
-       struct circ_buf *xmit = &uap->port.info->xmit;
+       struct circ_buf *xmit = &uap->port.state->xmit;
        int count;
 
        if (uap->port.x_char) {
@@ -224,7 +225,7 @@ static void pl010_modem_status(struct uart_amba_port *uap)
        if (delta & UART01x_FR_CTS)
                uart_handle_cts_change(&uap->port, status & UART01x_FR_CTS);
 
-       wake_up_interruptible(&uap->port.info->delta_msr_wait);
+       wake_up_interruptible(&uap->port.state->port.delta_msr_wait);
 }
 
 static irqreturn_t pl010_int(int irq, void *dev_id)
@@ -313,11 +314,20 @@ static int pl010_startup(struct uart_port *port)
        int retval;
 
        /*
+        * Try to enable the clock producer.
+        */
+       retval = clk_enable(uap->clk);
+       if (retval)
+               goto out;
+
+       uap->port.uartclk = clk_get_rate(uap->clk);
+
+       /*
         * Allocate the IRQ
         */
        retval = request_irq(uap->port.irq, pl010_int, 0, "uart-pl010", uap);
        if (retval)
-               return retval;
+               goto clk_dis;
 
        /*
         * initialise the old status of the modem signals
@@ -331,6 +341,11 @@ static int pl010_startup(struct uart_port *port)
               uap->port.membase + UART010_CR);
 
        return 0;
+
+ clk_dis:
+       clk_disable(uap->clk);
+ out:
+       return retval;
 }
 
 static void pl010_shutdown(struct uart_port *port)
@@ -351,6 +366,11 @@ static void pl010_shutdown(struct uart_port *port)
        writel(readb(uap->port.membase + UART010_LCRH) &
                ~(UART01x_LCRH_BRK | UART01x_LCRH_FEN),
               uap->port.membase + UART010_LCRH);
+
+       /*
+        * Shut down the clock producer
+        */
+       clk_disable(uap->clk);
 }
 
 static void
@@ -492,7 +512,7 @@ static int pl010_verify_port(struct uart_port *port, struct serial_struct *ser)
        int ret = 0;
        if (ser->type != PORT_UNKNOWN && ser->type != PORT_AMBA)
                ret = -EINVAL;
-       if (ser->irq < 0 || ser->irq >= NR_IRQS)
+       if (ser->irq < 0 || ser->irq >= nr_irqs)
                ret = -EINVAL;
        if (ser->baud_base < 9600)
                ret = -EINVAL;
@@ -540,6 +560,8 @@ pl010_console_write(struct console *co, const char *s, unsigned int count)
        struct uart_amba_port *uap = amba_ports[co->index];
        unsigned int status, old_cr;
 
+       clk_enable(uap->clk);
+
        /*
         *      First save the CR then disable the interrupts
         */
@@ -557,6 +579,8 @@ pl010_console_write(struct console *co, const char *s, unsigned int count)
                barrier();
        } while (status & UART01x_FR_BUSY);
        writel(old_cr, uap->port.membase + UART010_CR);
+
+       clk_disable(uap->clk);
 }
 
 static void __init
@@ -605,6 +629,8 @@ static int __init pl010_console_setup(struct console *co, char *options)
        if (!uap)
                return -ENODEV;
 
+       uap->port.uartclk = clk_get_rate(uap->clk);
+
        if (options)
                uart_parse_options(options, &baud, &parity, &bits, &flow);
        else
@@ -639,7 +665,7 @@ static struct uart_driver amba_reg = {
        .cons                   = AMBA_CONSOLE,
 };
 
-static int pl010_probe(struct amba_device *dev, void *id)
+static int pl010_probe(struct amba_device *dev, struct amba_id *id)
 {
        struct uart_amba_port *uap;
        void __iomem *base;
@@ -660,18 +686,23 @@ static int pl010_probe(struct amba_device *dev, void *id)
                goto out;
        }
 
-       base = ioremap(dev->res.start, PAGE_SIZE);
+       base = ioremap(dev->res.start, resource_size(&dev->res));
        if (!base) {
                ret = -ENOMEM;
                goto free;
        }
 
+       uap->clk = clk_get(&dev->dev, NULL);
+       if (IS_ERR(uap->clk)) {
+               ret = PTR_ERR(uap->clk);
+               goto unmap;
+       }
+
        uap->port.dev = &dev->dev;
        uap->port.mapbase = dev->res.start;
        uap->port.membase = base;
        uap->port.iotype = UPIO_MEM;
        uap->port.irq = dev->irq[0];
-       uap->port.uartclk = 14745600;
        uap->port.fifosize = 16;
        uap->port.ops = &amba_pl010_pops;
        uap->port.flags = UPF_BOOT_AUTOCONF;
@@ -686,6 +717,8 @@ static int pl010_probe(struct amba_device *dev, void *id)
        if (ret) {
                amba_set_drvdata(dev, NULL);
                amba_ports[i] = NULL;
+               clk_put(uap->clk);
+ unmap:
                iounmap(base);
  free:
                kfree(uap);
@@ -708,6 +741,7 @@ static int pl010_remove(struct amba_device *dev)
                        amba_ports[i] = NULL;
 
        iounmap(uap->port.membase);
+       clk_put(uap->clk);
        kfree(uap);
        return 0;
 }
@@ -755,7 +789,7 @@ static int __init pl010_init(void)
 {
        int ret;
 
-       printk(KERN_INFO "Serial: AMBA driver $Revision: 1.41 $\n");
+       printk(KERN_INFO "Serial: AMBA driver\n");
 
        ret = uart_register_driver(&amba_reg);
        if (ret == 0) {
@@ -776,5 +810,5 @@ module_init(pl010_init);
 module_exit(pl010_exit);
 
 MODULE_AUTHOR("ARM Ltd/Deep Blue Solutions Ltd");
-MODULE_DESCRIPTION("ARM AMBA serial port driver $Revision: 1.41 $");
+MODULE_DESCRIPTION("ARM AMBA serial port driver");
 MODULE_LICENSE("GPL");