const: constify remaining dev_pm_ops
[safe/jmp/linux-2.6] / drivers / serial / pxa.c
index 08b08d6..56ee082 100644 (file)
@@ -24,7 +24,6 @@
  * with the serial core maintainer satisfaction to appear soon.
  */
 
-#include <linux/config.h>
 
 #if defined(CONFIG_SERIAL_PXA_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ)
 #define SUPPORT_SYSRQ
 #include <linux/circ_buf.h>
 #include <linux/delay.h>
 #include <linux/interrupt.h>
-#include <linux/device.h>
+#include <linux/platform_device.h>
 #include <linux/tty.h>
 #include <linux/tty_flip.h>
 #include <linux/serial_core.h>
-
-#include <asm/io.h>
-#include <asm/hardware.h>
-#include <asm/irq.h>
-#include <asm/arch/pxa-regs.h>
-
+#include <linux/clk.h>
+#include <linux/io.h>
 
 struct uart_pxa_port {
        struct uart_port        port;
@@ -56,7 +51,7 @@ struct uart_pxa_port {
        unsigned char           lcr;
        unsigned char           mcr;
        unsigned int            lsr_break_flag;
-       unsigned int            cken;
+       struct clk              *clk;
        char                    *name;
 };
 
@@ -80,7 +75,7 @@ static void serial_pxa_enable_ms(struct uart_port *port)
        serial_out(up, UART_IER, up->ier);
 }
 
-static void serial_pxa_stop_tx(struct uart_port *port, unsigned int tty_stop)
+static void serial_pxa_stop_tx(struct uart_port *port)
 {
        struct uart_pxa_port *up = (struct uart_pxa_port *)port;
 
@@ -99,22 +94,13 @@ static void serial_pxa_stop_rx(struct uart_port *port)
        serial_out(up, UART_IER, up->ier);
 }
 
-static inline void
-receive_chars(struct uart_pxa_port *up, int *status, struct pt_regs *regs)
+static inline void receive_chars(struct uart_pxa_port *up, int *status)
 {
-       struct tty_struct *tty = up->port.info->tty;
+       struct tty_struct *tty = up->port.state->port.tty;
        unsigned int ch, flag;
        int max_count = 256;
 
        do {
-               if (unlikely(tty->flip.count >= TTY_FLIPBUF_SIZE)) {
-                       if (tty->low_latency)
-                               tty_flip_buffer_push(tty);
-                       /*
-                        * If this failed then we will throw away the
-                        * bytes but must do so to clear interrupts
-                        */
-               }
                ch = serial_in(up, UART_RX);
                flag = TTY_NORMAL;
                up->port.icount.rx++;
@@ -162,7 +148,7 @@ receive_chars(struct uart_pxa_port *up, int *status, struct pt_regs *regs)
                                flag = TTY_FRAME;
                }
 
-               if (uart_handle_sysrq_char(&up->port, ch, regs))
+               if (uart_handle_sysrq_char(&up->port, ch))
                        goto ignore_char;
 
                uart_insert_char(&up->port, *status, UART_LSR_OE, ch, flag);
@@ -175,7 +161,7 @@ receive_chars(struct uart_pxa_port *up, int *status, struct pt_regs *regs)
 
 static void transmit_chars(struct uart_pxa_port *up)
 {
-       struct circ_buf *xmit = &up->port.info->xmit;
+       struct circ_buf *xmit = &up->port.state->xmit;
        int count;
 
        if (up->port.x_char) {
@@ -185,7 +171,7 @@ static void transmit_chars(struct uart_pxa_port *up)
                return;
        }
        if (uart_circ_empty(xmit) || uart_tx_stopped(&up->port)) {
-               serial_pxa_stop_tx(&up->port, 0);
+               serial_pxa_stop_tx(&up->port);
                return;
        }
 
@@ -203,10 +189,10 @@ static void transmit_chars(struct uart_pxa_port *up)
 
 
        if (uart_circ_empty(xmit))
-               serial_pxa_stop_tx(&up->port, 0);
+               serial_pxa_stop_tx(&up->port);
 }
 
-static void serial_pxa_start_tx(struct uart_port *port, unsigned int tty_start)
+static void serial_pxa_start_tx(struct uart_port *port)
 {
        struct uart_pxa_port *up = (struct uart_pxa_port *)port;
 
@@ -234,16 +220,15 @@ static inline void check_modem_status(struct uart_pxa_port *up)
        if (status & UART_MSR_DCTS)
                uart_handle_cts_change(&up->port, status & UART_MSR_CTS);
 
-       wake_up_interruptible(&up->port.info->delta_msr_wait);
+       wake_up_interruptible(&up->port.state->port.delta_msr_wait);
 }
 
 /*
  * This handles the interrupt from one port.
  */
-static inline irqreturn_t
-serial_pxa_irq(int irq, void *dev_id, struct pt_regs *regs)
+static inline irqreturn_t serial_pxa_irq(int irq, void *dev_id)
 {
-       struct uart_pxa_port *up = (struct uart_pxa_port *)dev_id;
+       struct uart_pxa_port *up = dev_id;
        unsigned int iir, lsr;
 
        iir = serial_in(up, UART_IIR);
@@ -251,7 +236,7 @@ serial_pxa_irq(int irq, void *dev_id, struct pt_regs *regs)
                return IRQ_NONE;
        lsr = serial_in(up, UART_LSR);
        if (lsr & UART_LSR_DR)
-               receive_chars(up, &lsr, regs);
+               receive_chars(up, &lsr);
        check_modem_status(up);
        if (lsr & UART_LSR_THRE)
                transmit_chars(up);
@@ -274,14 +259,10 @@ static unsigned int serial_pxa_tx_empty(struct uart_port *port)
 static unsigned int serial_pxa_get_mctrl(struct uart_port *port)
 {
        struct uart_pxa_port *up = (struct uart_pxa_port *)port;
-       unsigned long flags;
        unsigned char status;
        unsigned int ret;
 
-return TIOCM_CTS | TIOCM_DSR | TIOCM_CAR;
-       spin_lock_irqsave(&up->port.lock, flags);
        status = serial_in(up, UART_MSR);
-       spin_unlock_irqrestore(&up->port.lock, flags);
 
        ret = 0;
        if (status & UART_MSR_DCD)
@@ -361,7 +342,12 @@ static int serial_pxa_startup(struct uart_port *port)
        unsigned long flags;
        int retval;
 
-       up->mcr = 0;
+       if (port->line == 3) /* HWUART */
+               up->mcr |= UART_MCR_AFE;
+       else
+               up->mcr = 0;
+
+       up->port.uartclk = clk_get_rate(up->clk);
 
        /*
         * Allocate the IRQ
@@ -399,7 +385,7 @@ static int serial_pxa_startup(struct uart_port *port)
 
        /*
         * Finally, enable interrupts.  Note: Modem status interrupts
-        * are set via set_termios(), which will be occuring imminently
+        * are set via set_termios(), which will be occurring imminently
         * anyway, so we don't enable them here.
         */
        up->ier = UART_IER_RLSI | UART_IER_RDI | UART_IER_RTOIE | UART_IER_UUE;
@@ -445,13 +431,14 @@ static void serial_pxa_shutdown(struct uart_port *port)
 }
 
 static void
-serial_pxa_set_termios(struct uart_port *port, struct termios *termios,
-                      struct termios *old)
+serial_pxa_set_termios(struct uart_port *port, struct ktermios *termios,
+                      struct ktermios *old)
 {
        struct uart_pxa_port *up = (struct uart_pxa_port *)port;
        unsigned char cval, fcr = 0;
        unsigned long flags;
        unsigned int baud, quot;
+       unsigned int dll;
 
        switch (termios->c_cflag & CSIZE) {
        case CS5:
@@ -484,8 +471,10 @@ serial_pxa_set_termios(struct uart_port *port, struct termios *termios,
 
        if ((up->port.uartclk / quot) < (2400 * 16))
                fcr = UART_FCR_ENABLE_FIFO | UART_FCR_PXAR1;
-       else
+       else if ((up->port.uartclk / quot) < (230400 * 16))
                fcr = UART_FCR_ENABLE_FIFO | UART_FCR_PXAR8;
+       else
+               fcr = UART_FCR_ENABLE_FIFO | UART_FCR_PXAR32;
 
        /*
         * Ok, we're now changing the port state.  Do it with
@@ -497,12 +486,12 @@ serial_pxa_set_termios(struct uart_port *port, struct termios *termios,
         * Ensure the port will be enabled.
         * This is required especially for serial console.
         */
-       up->ier |= IER_UUE;
+       up->ier |= UART_IER_UUE;
 
        /*
         * Update the per-port timeout.
         */
-       uart_update_timeout(port, termios->c_cflag, quot);
+       uart_update_timeout(port, termios->c_cflag, baud);
 
        up->port.read_status_mask = UART_LSR_OE | UART_LSR_THRE | UART_LSR_DR;
        if (termios->c_iflag & INPCK)
@@ -541,10 +530,23 @@ serial_pxa_set_termios(struct uart_port *port, struct termios *termios,
 
        serial_out(up, UART_IER, up->ier);
 
-       serial_out(up, UART_LCR, cval | UART_LCR_DLAB);/* set DLAB */
+       if (termios->c_cflag & CRTSCTS)
+               up->mcr |= UART_MCR_AFE;
+       else
+               up->mcr &= ~UART_MCR_AFE;
+
+       serial_out(up, UART_LCR, cval | UART_LCR_DLAB); /* set DLAB */
        serial_out(up, UART_DLL, quot & 0xff);          /* LS of divisor */
+
+       /*
+        * work around Errata #75 according to Intel(R) PXA27x Processor Family
+        * Specification Update (Nov 2005)
+        */
+       dll = serial_in(up, UART_DLL);
+       WARN_ON(dll != (quot & 0xff));
+
        serial_out(up, UART_DLM, quot >> 8);            /* MS of divisor */
-       serial_out(up, UART_LCR, cval);         /* reset DLAB */
+       serial_out(up, UART_LCR, cval);                 /* reset DLAB */
        up->lcr = cval;                                 /* Save LCR */
        serial_pxa_set_mctrl(&up->port, up->port.mctrl);
        serial_out(up, UART_FCR, fcr);
@@ -556,9 +558,11 @@ serial_pxa_pm(struct uart_port *port, unsigned int state,
              unsigned int oldstate)
 {
        struct uart_pxa_port *up = (struct uart_pxa_port *)port;
-       pxa_set_cken(up->cken, !state);
+
        if (!state)
-               udelay(1);
+               clk_enable(up->clk);
+       else
+               clk_disable(up->clk);
 }
 
 static void serial_pxa_release_port(struct uart_port *port)
@@ -590,10 +594,10 @@ serial_pxa_type(struct uart_port *port)
        return up->name;
 }
 
-#ifdef CONFIG_SERIAL_PXA_CONSOLE
+static struct uart_pxa_port *serial_pxa_ports[4];
+static struct uart_driver serial_pxa_reg;
 
-extern struct uart_pxa_port serial_pxa_ports[];
-extern struct uart_driver serial_pxa_reg;
+#ifdef CONFIG_SERIAL_PXA_CONSOLE
 
 #define BOTH_EMPTY (UART_LSR_TEMT | UART_LSR_THRE)
 
@@ -625,6 +629,14 @@ static inline void wait_for_xmitr(struct uart_pxa_port *up)
        }
 }
 
+static void serial_pxa_console_putchar(struct uart_port *port, int ch)
+{
+       struct uart_pxa_port *up = (struct uart_pxa_port *)port;
+
+       wait_for_xmitr(up);
+       serial_out(up, UART_TX, ch);
+}
+
 /*
  * Print a string to the serial port trying not to disturb
  * any possible real use of the port...
@@ -634,32 +646,18 @@ static inline void wait_for_xmitr(struct uart_pxa_port *up)
 static void
 serial_pxa_console_write(struct console *co, const char *s, unsigned int count)
 {
-       struct uart_pxa_port *up = &serial_pxa_ports[co->index];
+       struct uart_pxa_port *up = serial_pxa_ports[co->index];
        unsigned int ier;
-       int i;
+
+       clk_enable(up->clk);
 
        /*
-        *      First save the UER then disable the interrupts
+        *      First save the IER then disable the interrupts
         */
        ier = serial_in(up, UART_IER);
        serial_out(up, UART_IER, UART_IER_UUE);
 
-       /*
-        *      Now, do each character
-        */
-       for (i = 0; i < count; i++, s++) {
-               wait_for_xmitr(up);
-
-               /*
-                *      Send the character out.
-                *      If a LF, also do CR...
-                */
-               serial_out(up, UART_TX, *s);
-               if (*s == 10) {
-                       wait_for_xmitr(up);
-                       serial_out(up, UART_TX, 13);
-               }
-       }
+       uart_console_write(&up->port, s, count, serial_pxa_console_putchar);
 
        /*
         *      Finally, wait for transmitter to become empty
@@ -667,6 +665,8 @@ serial_pxa_console_write(struct console *co, const char *s, unsigned int count)
         */
        wait_for_xmitr(up);
        serial_out(up, UART_IER, ier);
+
+       clk_disable(up->clk);
 }
 
 static int __init
@@ -680,7 +680,9 @@ serial_pxa_console_setup(struct console *co, char *options)
 
        if (co->index == -1 || co->index >= serial_pxa_reg.nr)
                co->index = 0;
-               up = &serial_pxa_ports[co->index];
+       up = serial_pxa_ports[co->index];
+       if (!up)
+               return -ENODEV;
 
        if (options)
                uart_parse_options(options, &baud, &parity, &bits, &flow);
@@ -698,15 +700,6 @@ static struct console serial_pxa_console = {
        .data           = &serial_pxa_reg,
 };
 
-static int __init
-serial_pxa_console_init(void)
-{
-       register_console(&serial_pxa_console);
-       return 0;
-}
-
-console_initcall(serial_pxa_console_init);
-
 #define PXA_CONSOLE    &serial_pxa_console
 #else
 #define PXA_CONSOLE    NULL
@@ -732,113 +725,129 @@ struct uart_ops serial_pxa_pops = {
        .verify_port    = serial_pxa_verify_port,
 };
 
-static struct uart_pxa_port serial_pxa_ports[] = {
-     { /* FFUART */
-       .name   = "FFUART",
-       .cken   = CKEN6_FFUART,
-       .port   = {
-               .type           = PORT_PXA,
-               .iotype         = UPIO_MEM,
-               .membase        = (void *)&FFUART,
-               .mapbase        = __PREG(FFUART),
-               .irq            = IRQ_FFUART,
-               .uartclk        = 921600 * 16,
-               .fifosize       = 64,
-               .ops            = &serial_pxa_pops,
-               .line           = 0,
-       },
-  }, { /* BTUART */
-       .name   = "BTUART",
-       .cken   = CKEN7_BTUART,
-       .port   = {
-               .type           = PORT_PXA,
-               .iotype         = UPIO_MEM,
-               .membase        = (void *)&BTUART,
-               .mapbase        = __PREG(BTUART),
-               .irq            = IRQ_BTUART,
-               .uartclk        = 921600 * 16,
-               .fifosize       = 64,
-               .ops            = &serial_pxa_pops,
-               .line           = 1,
-       },
-  }, { /* STUART */
-       .name   = "STUART",
-       .cken   = CKEN5_STUART,
-       .port   = {
-               .type           = PORT_PXA,
-               .iotype         = UPIO_MEM,
-               .membase        = (void *)&STUART,
-               .mapbase        = __PREG(STUART),
-               .irq            = IRQ_STUART,
-               .uartclk        = 921600 * 16,
-               .fifosize       = 64,
-               .ops            = &serial_pxa_pops,
-               .line           = 2,
-       },
-  }
-};
-
 static struct uart_driver serial_pxa_reg = {
        .owner          = THIS_MODULE,
        .driver_name    = "PXA serial",
-       .devfs_name     = "tts/",
        .dev_name       = "ttyS",
        .major          = TTY_MAJOR,
        .minor          = 64,
-       .nr             = ARRAY_SIZE(serial_pxa_ports),
+       .nr             = 4,
        .cons           = PXA_CONSOLE,
 };
 
-static int serial_pxa_suspend(struct device *_dev, pm_message_t state, u32 level)
+#ifdef CONFIG_PM
+static int serial_pxa_suspend(struct device *dev)
 {
-        struct uart_pxa_port *sport = dev_get_drvdata(_dev);
+        struct uart_pxa_port *sport = dev_get_drvdata(dev);
 
-        if (sport && level == SUSPEND_DISABLE)
+        if (sport)
                 uart_suspend_port(&serial_pxa_reg, &sport->port);
 
         return 0;
 }
 
-static int serial_pxa_resume(struct device *_dev, u32 level)
+static int serial_pxa_resume(struct device *dev)
 {
-        struct uart_pxa_port *sport = dev_get_drvdata(_dev);
+        struct uart_pxa_port *sport = dev_get_drvdata(dev);
 
-        if (sport && level == RESUME_ENABLE)
+        if (sport)
                 uart_resume_port(&serial_pxa_reg, &sport->port);
 
         return 0;
 }
 
-static int serial_pxa_probe(struct device *_dev)
+static const struct dev_pm_ops serial_pxa_pm_ops = {
+       .suspend        = serial_pxa_suspend,
+       .resume         = serial_pxa_resume,
+};
+#endif
+
+static int serial_pxa_probe(struct platform_device *dev)
 {
-       struct platform_device *dev = to_platform_device(_dev);
+       struct uart_pxa_port *sport;
+       struct resource *mmres, *irqres;
+       int ret;
+
+       mmres = platform_get_resource(dev, IORESOURCE_MEM, 0);
+       irqres = platform_get_resource(dev, IORESOURCE_IRQ, 0);
+       if (!mmres || !irqres)
+               return -ENODEV;
+
+       sport = kzalloc(sizeof(struct uart_pxa_port), GFP_KERNEL);
+       if (!sport)
+               return -ENOMEM;
+
+       sport->clk = clk_get(&dev->dev, NULL);
+       if (IS_ERR(sport->clk)) {
+               ret = PTR_ERR(sport->clk);
+               goto err_free;
+       }
+
+       sport->port.type = PORT_PXA;
+       sport->port.iotype = UPIO_MEM;
+       sport->port.mapbase = mmres->start;
+       sport->port.irq = irqres->start;
+       sport->port.fifosize = 64;
+       sport->port.ops = &serial_pxa_pops;
+       sport->port.line = dev->id;
+       sport->port.dev = &dev->dev;
+       sport->port.flags = UPF_IOREMAP | UPF_BOOT_AUTOCONF;
+       sport->port.uartclk = clk_get_rate(sport->clk);
+
+       switch (dev->id) {
+       case 0: sport->name = "FFUART"; break;
+       case 1: sport->name = "BTUART"; break;
+       case 2: sport->name = "STUART"; break;
+       case 3: sport->name = "HWUART"; break;
+       default:
+               sport->name = "???";
+               break;
+       }
+
+       sport->port.membase = ioremap(mmres->start, mmres->end - mmres->start + 1);
+       if (!sport->port.membase) {
+               ret = -ENOMEM;
+               goto err_clk;
+       }
+
+       serial_pxa_ports[dev->id] = sport;
+
+       uart_add_one_port(&serial_pxa_reg, &sport->port);
+       platform_set_drvdata(dev, sport);
 
-       serial_pxa_ports[dev->id].port.dev = _dev;
-       uart_add_one_port(&serial_pxa_reg, &serial_pxa_ports[dev->id].port);
-       dev_set_drvdata(_dev, &serial_pxa_ports[dev->id]);
        return 0;
+
+ err_clk:
+       clk_put(sport->clk);
+ err_free:
+       kfree(sport);
+       return ret;
 }
 
-static int serial_pxa_remove(struct device *_dev)
+static int serial_pxa_remove(struct platform_device *dev)
 {
-       struct uart_pxa_port *sport = dev_get_drvdata(_dev);
+       struct uart_pxa_port *sport = platform_get_drvdata(dev);
 
-       dev_set_drvdata(_dev, NULL);
+       platform_set_drvdata(dev, NULL);
 
-       if (sport)
-               uart_remove_one_port(&serial_pxa_reg, &sport->port);
+       uart_remove_one_port(&serial_pxa_reg, &sport->port);
+       clk_put(sport->clk);
+       kfree(sport);
 
        return 0;
 }
 
-static struct device_driver serial_pxa_driver = {
-        .name           = "pxa2xx-uart",
-        .bus            = &platform_bus_type,
+static struct platform_driver serial_pxa_driver = {
         .probe          = serial_pxa_probe,
         .remove         = serial_pxa_remove,
 
-       .suspend        = serial_pxa_suspend,
-       .resume         = serial_pxa_resume,
+       .driver         = {
+               .name   = "pxa2xx-uart",
+               .owner  = THIS_MODULE,
+#ifdef CONFIG_PM
+               .pm     = &serial_pxa_pm_ops,
+#endif
+       },
 };
 
 int __init serial_pxa_init(void)
@@ -849,7 +858,7 @@ int __init serial_pxa_init(void)
        if (ret != 0)
                return ret;
 
-       ret = driver_register(&serial_pxa_driver);
+       ret = platform_driver_register(&serial_pxa_driver);
        if (ret != 0)
                uart_unregister_driver(&serial_pxa_reg);
 
@@ -858,7 +867,7 @@ int __init serial_pxa_init(void)
 
 void __exit serial_pxa_exit(void)
 {
-        driver_unregister(&serial_pxa_driver);
+       platform_driver_unregister(&serial_pxa_driver);
        uart_unregister_driver(&serial_pxa_reg);
 }
 
@@ -866,4 +875,4 @@ module_init(serial_pxa_init);
 module_exit(serial_pxa_exit);
 
 MODULE_LICENSE("GPL");
-
+MODULE_ALIAS("platform:pxa2xx-uart");