const: constify remaining dev_pm_ops
[safe/jmp/linux-2.6] / drivers / serial / sh-sci.c
index 4e3248d..7e3f4ff 100644 (file)
@@ -50,7 +50,6 @@
 #include <linux/list.h>
 
 #ifdef CONFIG_SUPERH
-#include <asm/clock.h>
 #include <asm/sh_bios.h>
 #endif
 
@@ -79,22 +78,18 @@ struct sci_port {
        struct timer_list       break_timer;
        int                     break_flag;
 
-#ifdef CONFIG_HAVE_CLK
        /* Interface clock */
        struct clk              *iclk;
        /* Data clock */
        struct clk              *dclk;
-#endif
+
        struct list_head        node;
 };
 
 struct sh_sci_priv {
        spinlock_t lock;
        struct list_head ports;
-
-#ifdef CONFIG_HAVE_CLK
        struct notifier_block clk_nb;
-#endif
 };
 
 /* Function prototypes */
@@ -151,38 +146,11 @@ static void sci_poll_put_char(struct uart_port *port, unsigned char c)
                status = sci_in(port, SCxSR);
        } while (!(status & SCxSR_TDxE(port)));
 
-       sci_in(port, SCxSR);            /* Dummy read */
-       sci_out(port, SCxSR, SCxSR_TDxE_CLEAR(port) & ~SCxSR_TEND(port));
        sci_out(port, SCxTDR, c);
+       sci_out(port, SCxSR, SCxSR_TDxE_CLEAR(port) & ~SCxSR_TEND(port));
 }
 #endif /* CONFIG_CONSOLE_POLL || CONFIG_SERIAL_SH_SCI_CONSOLE */
 
-#if defined(__H8300S__)
-enum { sci_disable, sci_enable };
-
-static void h8300_sci_config(struct uart_port *port, unsigned int ctrl)
-{
-       volatile unsigned char *mstpcrl = (volatile unsigned char *)MSTPCRL;
-       int ch = (port->mapbase  - SMR0) >> 3;
-       unsigned char mask = 1 << (ch+1);
-
-       if (ctrl == sci_disable)
-               *mstpcrl |= mask;
-       else
-               *mstpcrl &= ~mask;
-}
-
-static void h8300_sci_enable(struct uart_port *port)
-{
-       h8300_sci_config(port, sci_enable);
-}
-
-static void h8300_sci_disable(struct uart_port *port)
-{
-       h8300_sci_config(port, sci_disable);
-}
-#endif
-
 #if defined(__H8300H__) || defined(__H8300S__)
 static void sci_init_pins(struct uart_port *port, unsigned int cflag)
 {
@@ -273,7 +241,8 @@ static inline void sci_init_pins(struct uart_port *port, unsigned int cflag)
                __raw_writew(data, PSCR);
        }
 }
-#elif defined(CONFIG_CPU_SUBTYPE_SH7763) || \
+#elif defined(CONFIG_CPU_SUBTYPE_SH7757) || \
+      defined(CONFIG_CPU_SUBTYPE_SH7763) || \
       defined(CONFIG_CPU_SUBTYPE_SH7780) || \
       defined(CONFIG_CPU_SUBTYPE_SH7785) || \
       defined(CONFIG_CPU_SUBTYPE_SH7786) || \
@@ -361,7 +330,7 @@ static inline int sci_rxroom(struct uart_port *port)
 
 static void sci_transmit_chars(struct uart_port *port)
 {
-       struct circ_buf *xmit = &port->info->xmit;
+       struct circ_buf *xmit = &port->state->xmit;
        unsigned int stopped = uart_tx_stopped(port);
        unsigned short status;
        unsigned short ctrl;
@@ -426,7 +395,7 @@ static void sci_transmit_chars(struct uart_port *port)
 static inline void sci_receive_chars(struct uart_port *port)
 {
        struct sci_port *sci_port = to_sci_port(port);
-       struct tty_struct *tty = port->info->port.tty;
+       struct tty_struct *tty = port->state->port.tty;
        int i, count, copied = 0;
        unsigned short status;
        unsigned char flag;
@@ -546,7 +515,7 @@ static inline int sci_handle_errors(struct uart_port *port)
 {
        int copied = 0;
        unsigned short status = sci_in(port, SCxSR);
-       struct tty_struct *tty = port->info->port.tty;
+       struct tty_struct *tty = port->state->port.tty;
 
        if (status & SCxSR_ORER(port)) {
                /* overrun error */
@@ -600,7 +569,7 @@ static inline int sci_handle_errors(struct uart_port *port)
 
 static inline int sci_handle_fifo_overrun(struct uart_port *port)
 {
-       struct tty_struct *tty = port->info->port.tty;
+       struct tty_struct *tty = port->state->port.tty;
        int copied = 0;
 
        if (port->type != PORT_SCIF)
@@ -623,7 +592,7 @@ static inline int sci_handle_breaks(struct uart_port *port)
 {
        int copied = 0;
        unsigned short status = sci_in(port, SCxSR);
-       struct tty_struct *tty = port->info->port.tty;
+       struct tty_struct *tty = port->state->port.tty;
        struct sci_port *s = to_sci_port(port);
 
        if (uart_handle_break(port))
@@ -663,10 +632,11 @@ static irqreturn_t sci_rx_interrupt(int irq, void *port)
 static irqreturn_t sci_tx_interrupt(int irq, void *ptr)
 {
        struct uart_port *port = ptr;
+       unsigned long flags;
 
-       spin_lock_irq(&port->lock);
+       spin_lock_irqsave(&port->lock, flags);
        sci_transmit_chars(port);
-       spin_unlock_irq(&port->lock);
+       spin_unlock_irqrestore(&port->lock, flags);
 
        return IRQ_HANDLED;
 }
@@ -708,30 +678,30 @@ static irqreturn_t sci_br_interrupt(int irq, void *ptr)
 
 static irqreturn_t sci_mpxed_interrupt(int irq, void *ptr)
 {
-       unsigned short ssr_status, scr_status;
+       unsigned short ssr_status, scr_status, err_enabled;
        struct uart_port *port = ptr;
        irqreturn_t ret = IRQ_NONE;
 
        ssr_status = sci_in(port, SCxSR);
        scr_status = sci_in(port, SCSCR);
+       err_enabled = scr_status & (SCI_CTRL_FLAGS_REIE | SCI_CTRL_FLAGS_RIE);
 
        /* Tx Interrupt */
-       if ((ssr_status & 0x0020) && (scr_status & SCI_CTRL_FLAGS_TIE))
+       if ((ssr_status & SCxSR_TDxE(port)) && (scr_status & SCI_CTRL_FLAGS_TIE))
                ret = sci_tx_interrupt(irq, ptr);
        /* Rx Interrupt */
-       if ((ssr_status & 0x0002) && (scr_status & SCI_CTRL_FLAGS_RIE))
+       if ((ssr_status & SCxSR_RDxF(port)) && (scr_status & SCI_CTRL_FLAGS_RIE))
                ret = sci_rx_interrupt(irq, ptr);
        /* Error Interrupt */
-       if ((ssr_status & 0x0080) && (scr_status & SCI_CTRL_FLAGS_REIE))
+       if ((ssr_status & SCxSR_ERRORS(port)) && err_enabled)
                ret = sci_er_interrupt(irq, ptr);
        /* Break Interrupt */
-       if ((ssr_status & 0x0010) && (scr_status & SCI_CTRL_FLAGS_REIE))
+       if ((ssr_status & SCxSR_BRK(port)) && err_enabled)
                ret = sci_br_interrupt(irq, ptr);
 
        return ret;
 }
 
-#ifdef CONFIG_HAVE_CLK
 /*
  * Here we define a transistion notifier so that we can update all of our
  * ports' baud rate when the peripheral clock changes.
@@ -749,7 +719,6 @@ static int sci_notifier(struct notifier_block *self,
                spin_lock_irqsave(&priv->lock, flags);
                list_for_each_entry(sci_port, &priv->ports, node)
                        sci_port->port.uartclk = clk_get_rate(sci_port->dclk);
-
                spin_unlock_irqrestore(&priv->lock, flags);
        }
 
@@ -776,7 +745,6 @@ static void sci_clk_disable(struct uart_port *port)
 
        clk_disable(sci_port->dclk);
 }
-#endif
 
 static int sci_request_irq(struct sci_port *port)
 {
@@ -831,8 +799,8 @@ static void sci_free_irq(struct sci_port *port)
 
 static unsigned int sci_tx_empty(struct uart_port *port)
 {
-       /* Can't detect */
-       return TIOCSER_TEMT;
+       unsigned short status = sci_in(port, SCxSR);
+       return status & SCxSR_TEND(port) ? TIOCSER_TEMT : 0;
 }
 
 static void sci_set_mctrl(struct uart_port *port, unsigned int mctrl)
@@ -1075,21 +1043,10 @@ static void __devinit sci_init_single(struct platform_device *dev,
        sci_port->port.iotype   = UPIO_MEM;
        sci_port->port.line     = index;
        sci_port->port.fifosize = 1;
-
-#if defined(__H8300H__) || defined(__H8300S__)
-#ifdef __H8300S__
-       sci_port->enable        = h8300_sci_enable;
-       sci_port->disable       = h8300_sci_disable;
-#endif
-       sci_port->port.uartclk  = CONFIG_CPU_CLOCK;
-#elif defined(CONFIG_HAVE_CLK)
        sci_port->iclk          = p->clk ? clk_get(&dev->dev, p->clk) : NULL;
-       sci_port->dclk          = clk_get(&dev->dev, "module_clk");
+       sci_port->dclk          = clk_get(&dev->dev, "peripheral_clk");
        sci_port->enable        = sci_clk_enable;
        sci_port->disable       = sci_clk_disable;
-#else
-#error "Need a valid uartclk"
-#endif
 
        sci_port->break_timer.data = (unsigned long)sci_port;
        sci_port->break_timer.function = sci_break_timer;
@@ -1104,7 +1061,6 @@ static void __devinit sci_init_single(struct platform_device *dev,
        sci_port->type          = sci_port->port.type = p->type;
 
        memcpy(&sci_port->irqs, &p->irqs, sizeof(p->irqs));
-
 }
 
 #ifdef CONFIG_SERIAL_SH_SCI_CONSOLE
@@ -1141,7 +1097,7 @@ static void serial_console_write(struct console *co, const char *s,
        while ((sci_in(port, SCxSR) & bits) != bits)
                cpu_relax();
 
-       if (sci_port->disable);
+       if (sci_port->disable)
                sci_port->disable(port);
 }
 
@@ -1237,14 +1193,11 @@ static int sci_remove(struct platform_device *dev)
        struct sci_port *p;
        unsigned long flags;
 
-#ifdef CONFIG_HAVE_CLK
        cpufreq_unregister_notifier(&priv->clk_nb, CPUFREQ_TRANSITION_NOTIFIER);
-#endif
 
        spin_lock_irqsave(&priv->lock, flags);
        list_for_each_entry(p, &priv->ports, node)
                uart_remove_one_port(&sci_uart_driver, &p->port);
-
        spin_unlock_irqrestore(&priv->lock, flags);
 
        kfree(priv);
@@ -1305,10 +1258,8 @@ static int __devinit sci_probe(struct platform_device *dev)
        spin_lock_init(&priv->lock);
        platform_set_drvdata(dev, priv);
 
-#ifdef CONFIG_HAVE_CLK
        priv->clk_nb.notifier_call = sci_notifier;
        cpufreq_register_notifier(&priv->clk_nb, CPUFREQ_TRANSITION_NOTIFIER);
-#endif
 
        if (dev->id != -1) {
                ret = sci_probe_single(dev, dev->id, p, &sci_ports[dev->id]);
@@ -1333,44 +1284,46 @@ err_unreg:
        return ret;
 }
 
-static int sci_suspend(struct platform_device *dev, pm_message_t state)
+static int sci_suspend(struct device *dev)
 {
-       struct sh_sci_priv *priv = platform_get_drvdata(dev);
+       struct sh_sci_priv *priv = dev_get_drvdata(dev);
        struct sci_port *p;
        unsigned long flags;
 
        spin_lock_irqsave(&priv->lock, flags);
        list_for_each_entry(p, &priv->ports, node)
                uart_suspend_port(&sci_uart_driver, &p->port);
-
        spin_unlock_irqrestore(&priv->lock, flags);
 
        return 0;
 }
 
-static int sci_resume(struct platform_device *dev)
+static int sci_resume(struct device *dev)
 {
-       struct sh_sci_priv *priv = platform_get_drvdata(dev);
+       struct sh_sci_priv *priv = dev_get_drvdata(dev);
        struct sci_port *p;
        unsigned long flags;
 
        spin_lock_irqsave(&priv->lock, flags);
        list_for_each_entry(p, &priv->ports, node)
                uart_resume_port(&sci_uart_driver, &p->port);
-
        spin_unlock_irqrestore(&priv->lock, flags);
 
        return 0;
 }
 
-static struct platform_driver sci_driver = {
-       .probe          = sci_probe,
-       .remove         = __devexit_p(sci_remove),
+static const struct dev_pm_ops sci_dev_pm_ops = {
        .suspend        = sci_suspend,
        .resume         = sci_resume,
+};
+
+static struct platform_driver sci_driver = {
+       .probe          = sci_probe,
+       .remove         = sci_remove,
        .driver         = {
                .name   = "sh-sci",
                .owner  = THIS_MODULE,
+               .pm     = &sci_dev_pm_ops,
        },
 };