]> git.karo-electronics.de Git - karo-tx-linux.git/blobdiff - drivers/tty/serial/8250/8250_dw.c
Merge remote-tracking branch 'clk/clk-next'
[karo-tx-linux.git] / drivers / tty / serial / 8250 / 8250_dw.c
index d69d0984484f0f7ca851e61e822c0d2054747867..a5d319e4aae65dad90f64bafd33c2ad02bed7034 100644 (file)
@@ -63,6 +63,9 @@ struct dw8250_data {
        struct clk              *pclk;
        struct reset_control    *rst;
        struct uart_8250_dma    dma;
+
+       unsigned int            skip_autocfg:1;
+       unsigned int            uart_16550_compatible:1;
 };
 
 #define BYT_PRV_CLK                    0x800
@@ -224,10 +227,6 @@ static void dw8250_set_termios(struct uart_port *p, struct ktermios *termios,
        if (IS_ERR(d->clk) || !old)
                goto out;
 
-       /* Not requesting clock rates below 1.8432Mhz */
-       if (baud < 115200)
-               baud = 115200;
-
        clk_disable_unprepare(d->clk);
        rate = clk_round_rate(d->clk, baud * 16);
        ret = clk_set_rate(d->clk, rate);
@@ -244,24 +243,77 @@ out:
        serial8250_do_set_termios(p, termios, old);
 }
 
-static bool dw8250_dma_filter(struct dma_chan *chan, void *param)
+/*
+ * dw8250_fallback_dma_filter will prevent the UART from getting just any free
+ * channel on platforms that have DMA engines, but don't have any channels
+ * assigned to the UART.
+ *
+ * REVISIT: This is a work around for limitation in the DMA Engine API. Once the
+ * core problem is fixed, this function is no longer needed.
+ */
+static bool dw8250_fallback_dma_filter(struct dma_chan *chan, void *param)
 {
        return false;
 }
 
-static void dw8250_setup_port(struct uart_8250_port *up)
+static bool dw8250_idma_filter(struct dma_chan *chan, void *param)
+{
+       return param == chan->device->dev->parent;
+}
+
+static void dw8250_quirks(struct uart_port *p, struct dw8250_data *data)
+{
+       if (p->dev->of_node) {
+               struct device_node *np = p->dev->of_node;
+               int id;
+
+               /* get index of serial line, if found in DT aliases */
+               id = of_alias_get_id(np, "serial");
+               if (id >= 0)
+                       p->line = id;
+#ifdef CONFIG_64BIT
+               if (of_device_is_compatible(np, "cavium,octeon-3860-uart")) {
+                       p->serial_in = dw8250_serial_inq;
+                       p->serial_out = dw8250_serial_outq;
+                       p->flags = UPF_SKIP_TEST | UPF_SHARE_IRQ | UPF_FIXED_TYPE;
+                       p->type = PORT_OCTEON;
+                       data->usr_reg = 0x27;
+                       data->skip_autocfg = true;
+               }
+#endif
+       } else if (has_acpi_companion(p->dev)) {
+               p->iotype = UPIO_MEM32;
+               p->regshift = 2;
+               p->serial_in = dw8250_serial_in32;
+               p->set_termios = dw8250_set_termios;
+               /* So far none of there implement the Busy Functionality */
+               data->uart_16550_compatible = true;
+       }
+
+       /* Platforms with iDMA */
+       if (platform_get_resource_byname(to_platform_device(p->dev),
+                                        IORESOURCE_MEM, "lpss_priv")) {
+               p->set_termios = dw8250_set_termios;
+               data->dma.rx_param = p->dev->parent;
+               data->dma.tx_param = p->dev->parent;
+               data->dma.fn = dw8250_idma_filter;
+       }
+}
+
+static void dw8250_setup_port(struct uart_port *p)
 {
-       struct uart_port        *p = &up->port;
-       u32                     reg = readl(p->membase + DW_UART_UCV);
+       struct uart_8250_port *up = up_to_u8250p(p);
+       u32 reg;
 
        /*
         * If the Component Version Register returns zero, we know that
         * ADDITIONAL_FEATURES are not enabled. No need to go any further.
         */
+       reg = readl(p->membase + DW_UART_UCV);
        if (!reg)
                return;
 
-       dev_dbg_ratelimited(p->dev, "Designware UART version %c.%c%c\n",
+       dev_dbg(p->dev, "Designware UART version %c.%c%c\n",
                (reg >> 24) & 0xff, (reg >> 16) & 0xff, (reg >> 8) & 0xff);
 
        reg = readl(p->membase + DW_UART_CPR);
@@ -273,7 +325,6 @@ static void dw8250_setup_port(struct uart_8250_port *up)
                p->type = PORT_16550A;
                p->flags |= UPF_FIXED_TYPE;
                p->fifosize = DW_UART_CPR_FIFO_SIZE(reg);
-               up->tx_loadsz = p->fifosize;
                up->capabilities = UART_CAP_FIFO;
        }
 
@@ -281,70 +332,6 @@ static void dw8250_setup_port(struct uart_8250_port *up)
                up->capabilities |= UART_CAP_AFE;
 }
 
-static int dw8250_probe_of(struct uart_port *p,
-                          struct dw8250_data *data)
-{
-       struct device_node      *np = p->dev->of_node;
-       struct uart_8250_port *up = up_to_u8250p(p);
-       bool has_ucv = true;
-       int id;
-
-#ifdef CONFIG_64BIT
-       if (of_device_is_compatible(np, "cavium,octeon-3860-uart")) {
-               p->serial_in = dw8250_serial_inq;
-               p->serial_out = dw8250_serial_outq;
-               p->flags = UPF_SKIP_TEST | UPF_SHARE_IRQ | UPF_FIXED_TYPE;
-               p->type = PORT_OCTEON;
-               data->usr_reg = 0x27;
-               has_ucv = false;
-       }
-#endif
-       if (has_ucv)
-               dw8250_setup_port(up);
-
-       /* get index of serial line, if found in DT aliases */
-       id = of_alias_get_id(np, "serial");
-       if (id >= 0)
-               p->line = id;
-
-       return 0;
-}
-
-static bool dw8250_idma_filter(struct dma_chan *chan, void *param)
-{
-       struct device *dev = param;
-
-       if (dev != chan->device->dev->parent)
-               return false;
-
-       return true;
-}
-
-static int dw8250_probe_acpi(struct uart_8250_port *up,
-                            struct dw8250_data *data)
-{
-       struct uart_port *p = &up->port;
-
-       dw8250_setup_port(up);
-
-       p->iotype = UPIO_MEM32;
-       p->serial_in = dw8250_serial_in32;
-       p->serial_out = dw8250_serial_out32;
-       p->regshift = 2;
-
-       /* Platforms with iDMA */
-       if (platform_get_resource_byname(to_platform_device(up->port.dev),
-                                        IORESOURCE_MEM, "lpss_priv")) {
-               data->dma.rx_param = up->port.dev->parent;
-               data->dma.tx_param = up->port.dev->parent;
-               data->dma.fn = dw8250_idma_filter;
-       }
-
-       up->port.set_termios = dw8250_set_termios;
-
-       return 0;
-}
-
 static int dw8250_probe(struct platform_device *pdev)
 {
        struct uart_8250_port uart = {};
@@ -372,7 +359,7 @@ static int dw8250_probe(struct platform_device *pdev)
        p->handle_irq   = dw8250_handle_irq;
        p->pm           = dw8250_do_pm;
        p->type         = PORT_8250;
-       p->flags        = UPF_SHARE_IRQ | UPF_BOOT_AUTOCONF | UPF_FIXED_PORT;
+       p->flags        = UPF_SHARE_IRQ | UPF_FIXED_PORT;
        p->dev          = &pdev->dev;
        p->iotype       = UPIO_MEM;
        p->serial_in    = dw8250_serial_in;
@@ -386,9 +373,13 @@ static int dw8250_probe(struct platform_device *pdev)
        if (!data)
                return -ENOMEM;
 
+       data->dma.fn = dw8250_fallback_dma_filter;
        data->usr_reg = DW_UART_USR;
        p->private_data = data;
 
+       data->uart_16550_compatible = device_property_read_bool(p->dev,
+                                               "snps,uart-16550-compatible");
+
        err = device_property_read_u32(p->dev, "reg-shift", &val);
        if (!err)
                p->regshift = val;
@@ -469,23 +460,17 @@ static int dw8250_probe(struct platform_device *pdev)
        if (!IS_ERR(data->rst))
                reset_control_deassert(data->rst);
 
-       data->dma.rx_param = data;
-       data->dma.tx_param = data;
-       data->dma.fn = dw8250_dma_filter;
+       dw8250_quirks(p, data);
 
-       if (pdev->dev.of_node) {
-               err = dw8250_probe_of(p, data);
-               if (err)
-                       goto err_reset;
-       } else if (ACPI_HANDLE(&pdev->dev)) {
-               err = dw8250_probe_acpi(&uart, data);
-               if (err)
-                       goto err_reset;
-       } else {
-               err = -ENODEV;
-               goto err_reset;
+       /* If the Busy Functionality is not implemented, don't handle it */
+       if (data->uart_16550_compatible) {
+               p->serial_out = NULL;
+               p->handle_irq = NULL;
        }
 
+       if (!data->skip_autocfg)
+               dw8250_setup_port(p);
+
        /* If we have a valid fifosize, try hooking up DMA */
        if (p->fifosize) {
                data->dma.rxconf.src_maxburst = p->fifosize / 4;