serial: sh-sci: Don't check IRQ in verify port operation
[firefly-linux-kernel-4.4.55.git] / drivers / tty / serial / sh-sci.c
index 537750261aaa2fe5a5e2de8fdb3e6ee0adf8fe4d..b3d0e00ecedfb44de362d412006387bf4a9a5771 100644 (file)
 
 #undef DEBUG
 
-#include <linux/module.h>
+#include <linux/clk.h>
+#include <linux/console.h>
+#include <linux/ctype.h>
+#include <linux/cpufreq.h>
+#include <linux/delay.h>
+#include <linux/dmaengine.h>
+#include <linux/dma-mapping.h>
+#include <linux/err.h>
 #include <linux/errno.h>
-#include <linux/sh_dma.h>
-#include <linux/timer.h>
+#include <linux/gpio.h>
+#include <linux/init.h>
 #include <linux/interrupt.h>
-#include <linux/tty.h>
-#include <linux/tty_flip.h>
-#include <linux/serial.h>
-#include <linux/major.h>
-#include <linux/string.h>
-#include <linux/sysrq.h>
 #include <linux/ioport.h>
+#include <linux/major.h>
+#include <linux/module.h>
 #include <linux/mm.h>
-#include <linux/init.h>
-#include <linux/delay.h>
-#include <linux/console.h>
-#include <linux/platform_device.h>
-#include <linux/serial_sci.h>
 #include <linux/notifier.h>
+#include <linux/platform_device.h>
 #include <linux/pm_runtime.h>
-#include <linux/cpufreq.h>
-#include <linux/clk.h>
-#include <linux/ctype.h>
-#include <linux/err.h>
-#include <linux/dmaengine.h>
-#include <linux/dma-mapping.h>
 #include <linux/scatterlist.h>
+#include <linux/serial.h>
+#include <linux/serial_sci.h>
+#include <linux/sh_dma.h>
 #include <linux/slab.h>
-#include <linux/gpio.h>
+#include <linux/string.h>
+#include <linux/sysrq.h>
+#include <linux/timer.h>
+#include <linux/tty.h>
+#include <linux/tty_flip.h>
 
 #ifdef CONFIG_SUPERH
 #include <asm/sh_bios.h>
@@ -421,9 +421,9 @@ static void sci_port_enable(struct sci_port *sci_port)
 
        pm_runtime_get_sync(sci_port->port.dev);
 
-       clk_enable(sci_port->iclk);
+       clk_prepare_enable(sci_port->iclk);
        sci_port->port.uartclk = clk_get_rate(sci_port->iclk);
-       clk_enable(sci_port->fclk);
+       clk_prepare_enable(sci_port->fclk);
 }
 
 static void sci_port_disable(struct sci_port *sci_port)
@@ -431,8 +431,16 @@ static void sci_port_disable(struct sci_port *sci_port)
        if (!sci_port->port.dev)
                return;
 
-       clk_disable(sci_port->fclk);
-       clk_disable(sci_port->iclk);
+       /* Cancel the break timer to ensure that the timer handler will not try
+        * to access the hardware with clocks and power disabled. Reset the
+        * break flag to make the break debouncing state machine ready for the
+        * next break.
+        */
+       del_timer_sync(&sci_port->break_timer);
+       sci_port->break_flag = 0;
+
+       clk_disable_unprepare(sci_port->fclk);
+       clk_disable_unprepare(sci_port->iclk);
 
        pm_runtime_put_sync(sci_port->port.dev);
 }
@@ -557,7 +565,7 @@ static inline int sci_rxd_in(struct uart_port *port)
                return 1;
 
        /* Cast for ARM damage */
-       return !!__raw_readb((void __iomem *)s->cfg->port_reg);
+       return !!__raw_readb((void __iomem *)(uintptr_t)s->cfg->port_reg);
 }
 
 /* ********************************************************************** *
@@ -733,8 +741,6 @@ static void sci_break_timer(unsigned long data)
 {
        struct sci_port *port = (struct sci_port *)data;
 
-       sci_port_enable(port);
-
        if (sci_rxd_in(&port->port) == 0) {
                port->break_flag = 1;
                sci_schedule_break_timer(port);
@@ -744,8 +750,6 @@ static void sci_break_timer(unsigned long data)
                sci_schedule_break_timer(port);
        } else
                port->break_flag = 0;
-
-       sci_port_disable(port);
 }
 
 static int sci_handle_errors(struct uart_port *port)
@@ -1309,7 +1313,7 @@ static int sci_dma_rx_push(struct sci_port *s, size_t count)
        }
 
        if (room < count)
-               dev_warn(port->dev, "Rx overrun: dropping %u bytes\n",
+               dev_warn(port->dev, "Rx overrun: dropping %zu bytes\n",
                         count - room);
        if (!room)
                return room;
@@ -1433,7 +1437,7 @@ static void work_fn_rx(struct work_struct *work)
        desc = s->desc_rx[new];
 
        if (dma_async_is_tx_complete(s->chan_rx, s->active_rx, NULL, NULL) !=
-           DMA_SUCCESS) {
+           DMA_COMPLETE) {
                /* Handle incomplete DMA receive */
                struct dma_chan *chan = s->chan_rx;
                struct shdma_desc *sh_desc = container_of(desc,
@@ -1442,7 +1446,7 @@ static void work_fn_rx(struct work_struct *work)
                int count;
 
                chan->device->device_control(chan, DMA_TERMINATE_ALL, 0);
-               dev_dbg(port->dev, "Read %u bytes with cookie %d\n",
+               dev_dbg(port->dev, "Read %zu bytes with cookie %d\n",
                        sh_desc->partial, sh_desc->cookie);
 
                spin_lock_irqsave(&port->lock, flags);
@@ -1691,16 +1695,17 @@ static void sci_request_dma(struct uart_port *port)
                s->chan_tx = chan;
                sg_init_table(&s->sg_tx, 1);
                /* UART circular tx buffer is an aligned page. */
-               BUG_ON((int)port->state->xmit.buf & ~PAGE_MASK);
+               BUG_ON((uintptr_t)port->state->xmit.buf & ~PAGE_MASK);
                sg_set_page(&s->sg_tx, virt_to_page(port->state->xmit.buf),
-                           UART_XMIT_SIZE, (int)port->state->xmit.buf & ~PAGE_MASK);
+                           UART_XMIT_SIZE,
+                           (uintptr_t)port->state->xmit.buf & ~PAGE_MASK);
                nent = dma_map_sg(port->dev, &s->sg_tx, 1, DMA_TO_DEVICE);
                if (!nent)
                        sci_tx_dma_release(s, false);
                else
-                       dev_dbg(port->dev, "%s: mapped %d@%p to %x\n", __func__,
-                               sg_dma_len(&s->sg_tx),
-                               port->state->xmit.buf, sg_dma_address(&s->sg_tx));
+                       dev_dbg(port->dev, "%s: mapped %d@%p to %pad\n", __func__,
+                               sg_dma_len(&s->sg_tx), port->state->xmit.buf,
+                               &sg_dma_address(&s->sg_tx));
 
                s->sg_len_tx = nent;
 
@@ -1740,7 +1745,7 @@ static void sci_request_dma(struct uart_port *port)
 
                        sg_init_table(sg, 1);
                        sg_set_page(sg, virt_to_page(buf[i]), s->buf_len_rx,
-                                   (int)buf[i] & ~PAGE_MASK);
+                                   (uintptr_t)buf[i] & ~PAGE_MASK);
                        sg_dma_address(sg) = dma[i];
                }
 
@@ -1813,15 +1818,13 @@ static unsigned int sci_scbrr_calc(unsigned int algo_id, unsigned int bps,
 {
        switch (algo_id) {
        case SCBRR_ALGO_1:
-               return ((freq + 16 * bps) / (16 * bps) - 1);
+               return freq / (16 * bps);
        case SCBRR_ALGO_2:
-               return ((freq + 16 * bps) / (32 * bps) - 1);
+               return DIV_ROUND_CLOSEST(freq, 32 * bps) - 1;
        case SCBRR_ALGO_3:
-               return (((freq * 2) + 16 * bps) / (16 * bps) - 1);
+               return freq / (8 * bps);
        case SCBRR_ALGO_4:
-               return (((freq * 2) + 16 * bps) / (32 * bps) - 1);
-       case SCBRR_ALGO_5:
-               return (((freq * 1000 / 32) / bps) - 1);
+               return DIV_ROUND_CLOSEST(freq, 16 * bps) - 1;
        }
 
        /* Warn, but use a safe default */
@@ -2115,10 +2118,6 @@ static void sci_config_port(struct uart_port *port, int flags)
 
 static int sci_verify_port(struct uart_port *port, struct serial_struct *ser)
 {
-       struct sci_port *s = to_sci_port(port);
-
-       if (ser->irq != s->cfg->irqs[SCIx_TXI_IRQ] || ser->irq > nr_irqs)
-               return -EINVAL;
        if (ser->baud_base < 2400)
                /* No paper tape reader for Mitch.. */
                return -EINVAL;
@@ -2245,7 +2244,7 @@ static int sci_init_single(struct platform_device *dev,
 
        port->mapbase           = p->mapbase;
        port->type              = p->type;
-       port->flags             = p->flags;
+       port->flags             = UPF_FIXED_PORT | p->flags;
        port->regshift          = p->regshift;
 
        /*