Merge remote-tracking branch 'tty/tty-next'
authorStephen Rothwell <sfr@canb.auug.org.au>
Tue, 13 Sep 2016 02:39:35 +0000 (12:39 +1000)
committerStephen Rothwell <sfr@canb.auug.org.au>
Tue, 13 Sep 2016 02:39:35 +0000 (12:39 +1000)
48 files changed:
drivers/dma/dw/core.c
drivers/dma/dw/regs.h
drivers/dma/hsu/hsu.c
drivers/dma/hsu/pci.c
drivers/dma/imx-sdma.c
drivers/tty/serial/8250/8250.h
drivers/tty/serial/8250/8250_core.c
drivers/tty/serial/8250/8250_dma.c
drivers/tty/serial/8250/8250_dw.c
drivers/tty/serial/8250/8250_lpss.c [new file with mode: 0644]
drivers/tty/serial/8250/8250_mid.c
drivers/tty/serial/8250/8250_mtk.c
drivers/tty/serial/8250/8250_pci.c
drivers/tty/serial/8250/8250_port.c
drivers/tty/serial/8250/Kconfig
drivers/tty/serial/8250/Makefile
drivers/tty/serial/altera_jtaguart.c
drivers/tty/serial/altera_uart.c
drivers/tty/serial/amba-pl011.c
drivers/tty/serial/arc_uart.c
drivers/tty/serial/atmel_serial.c
drivers/tty/serial/bcm63xx_uart.c
drivers/tty/serial/earlycon-arm-semihost.c
drivers/tty/serial/earlycon.c
drivers/tty/serial/fsl_lpuart.c
drivers/tty/serial/imx.c
drivers/tty/serial/jsm/jsm_tty.c
drivers/tty/serial/max3100.c
drivers/tty/serial/men_z135_uart.c
drivers/tty/serial/mxs-auart.c
drivers/tty/serial/pch_uart.c
drivers/tty/serial/samsung.c
drivers/tty/serial/samsung.h
drivers/tty/serial/sc16is7xx.c
drivers/tty/serial/serial_core.c
drivers/tty/serial/sh-sci.c
drivers/tty/serial/st-asc.c
drivers/tty/serial/timbuart.c
drivers/tty/serial/uartlite.c
drivers/tty/serial/vt8500_serial.c
drivers/tty/serial/xilinx_uartps.c
include/linux/amba/bus.h
include/linux/amba/serial.h
include/linux/atmel_serial.h
include/linux/dma/dw.h
include/linux/dma/hsu.h
include/linux/platform_data/dma-dw.h
include/linux/serial_core.h

index 12eedd45719399734b48e7b6b08cfa658c0698a9..c2c0a613cb7aab53ac5f8e85c6c7441ecc7ef3fc 100644 (file)
@@ -46,9 +46,9 @@
                u8 _dmsize = _is_slave ? _sconfig->dst_maxburst :       \
                        DW_DMA_MSIZE_16;                        \
                u8 _dms = (_dwc->direction == DMA_MEM_TO_DEV) ?         \
-                       _dwc->p_master : _dwc->m_master;                \
+                       _dwc->dws.p_master : _dwc->dws.m_master;        \
                u8 _sms = (_dwc->direction == DMA_DEV_TO_MEM) ?         \
-                       _dwc->p_master : _dwc->m_master;                \
+                       _dwc->dws.p_master : _dwc->dws.m_master;        \
                                                                \
                (DWC_CTLL_DST_MSIZE(_dmsize)                    \
                 | DWC_CTLL_SRC_MSIZE(_smsize)                  \
@@ -143,12 +143,16 @@ static void dwc_initialize(struct dw_dma_chan *dwc)
        struct dw_dma *dw = to_dw_dma(dwc->chan.device);
        u32 cfghi = DWC_CFGH_FIFO_MODE;
        u32 cfglo = DWC_CFGL_CH_PRIOR(dwc->priority);
+       bool hs_polarity = dwc->dws.hs_polarity;
 
        if (test_bit(DW_DMA_IS_INITIALIZED, &dwc->flags))
                return;
 
-       cfghi |= DWC_CFGH_DST_PER(dwc->dst_id);
-       cfghi |= DWC_CFGH_SRC_PER(dwc->src_id);
+       cfghi |= DWC_CFGH_DST_PER(dwc->dws.dst_id);
+       cfghi |= DWC_CFGH_SRC_PER(dwc->dws.src_id);
+
+       /* Set polarity of handshake interface */
+       cfglo |= hs_polarity ? DWC_CFGL_HS_DST_POL | DWC_CFGL_HS_SRC_POL : 0;
 
        channel_writel(dwc, CFG_LO, cfglo);
        channel_writel(dwc, CFG_HI, cfghi);
@@ -209,7 +213,7 @@ static inline void dwc_do_single_block(struct dw_dma_chan *dwc,
 static void dwc_dostart(struct dw_dma_chan *dwc, struct dw_desc *first)
 {
        struct dw_dma   *dw = to_dw_dma(dwc->chan.device);
-       u8              lms = DWC_LLP_LMS(dwc->m_master);
+       u8              lms = DWC_LLP_LMS(dwc->dws.m_master);
        unsigned long   was_soft_llp;
 
        /* ASSERT:  channel is idle */
@@ -660,7 +664,7 @@ dwc_prep_dma_memcpy(struct dma_chan *chan, dma_addr_t dest, dma_addr_t src,
        struct dw_desc          *prev;
        size_t                  xfer_count;
        size_t                  offset;
-       u8                      m_master = dwc->m_master;
+       u8                      m_master = dwc->dws.m_master;
        unsigned int            src_width;
        unsigned int            dst_width;
        unsigned int            data_width = dw->pdata->data_width[m_master];
@@ -738,7 +742,7 @@ dwc_prep_slave_sg(struct dma_chan *chan, struct scatterlist *sgl,
        struct dw_desc          *prev;
        struct dw_desc          *first;
        u32                     ctllo;
-       u8                      m_master = dwc->m_master;
+       u8                      m_master = dwc->dws.m_master;
        u8                      lms = DWC_LLP_LMS(m_master);
        dma_addr_t              reg;
        unsigned int            reg_width;
@@ -893,12 +897,7 @@ bool dw_dma_filter(struct dma_chan *chan, void *param)
                return false;
 
        /* We have to copy data since dws can be temporary storage */
-
-       dwc->src_id = dws->src_id;
-       dwc->dst_id = dws->dst_id;
-
-       dwc->m_master = dws->m_master;
-       dwc->p_master = dws->p_master;
+       memcpy(&dwc->dws, dws, sizeof(struct dw_dma_slave));
 
        return true;
 }
@@ -1165,11 +1164,7 @@ static void dwc_free_chan_resources(struct dma_chan *chan)
        spin_lock_irqsave(&dwc->lock, flags);
 
        /* Clear custom channel configuration */
-       dwc->src_id = 0;
-       dwc->dst_id = 0;
-
-       dwc->m_master = 0;
-       dwc->p_master = 0;
+       memset(&dwc->dws, 0, sizeof(struct dw_dma_slave));
 
        clear_bit(DW_DMA_IS_INITIALIZED, &dwc->flags);
 
@@ -1262,7 +1257,7 @@ struct dw_cyclic_desc *dw_dma_cyclic_prep(struct dma_chan *chan,
        struct dw_cyclic_desc           *retval = NULL;
        struct dw_desc                  *desc;
        struct dw_desc                  *last = NULL;
-       u8                              lms = DWC_LLP_LMS(dwc->m_master);
+       u8                              lms = DWC_LLP_LMS(dwc->dws.m_master);
        unsigned long                   was_cyclic;
        unsigned int                    reg_width;
        unsigned int                    periods;
@@ -1574,11 +1569,7 @@ int dw_dma_probe(struct dw_dma_chip *chip)
                                (dwc_params >> DWC_PARAMS_MBLK_EN & 0x1) == 0;
                } else {
                        dwc->block_size = pdata->block_size;
-
-                       /* Check if channel supports multi block transfer */
-                       channel_writel(dwc, LLP, DWC_LLP_LOC(0xffffffff));
-                       dwc->nollp = DWC_LLP_LOC(channel_readl(dwc, LLP)) == 0;
-                       channel_writel(dwc, LLP, 0);
+                       dwc->nollp = pdata->is_nollp;
                }
        }
 
index 4b7bd783404663a5953cf457430d4348d5aeeee9..f65dd104479fabcfd2842893325b13f11023fac7 100644 (file)
@@ -245,10 +245,7 @@ struct dw_dma_chan {
        bool                    nollp;
 
        /* custom slave configuration */
-       u8                      src_id;
-       u8                      dst_id;
-       u8                      m_master;
-       u8                      p_master;
+       struct dw_dma_slave     dws;
 
        /* configuration passed via .device_config */
        struct dma_slave_config dma_sconfig;
index c5f21efd6090ee35b2cbad7e4ceeb59a391ecc8a..29d04ca71d52ed05e47435a869fd7826ae93aa08 100644 (file)
@@ -200,10 +200,9 @@ EXPORT_SYMBOL_GPL(hsu_dma_get_status);
  *      is not a normal timeout interrupt, ie. hsu_dma_get_status() returned 0.
  *
  *      Return:
- *      IRQ_NONE for invalid channel number, IRQ_HANDLED otherwise.
+ *      0 for invalid channel number, 1 otherwise.
  */
-irqreturn_t hsu_dma_do_irq(struct hsu_dma_chip *chip, unsigned short nr,
-                          u32 status)
+int hsu_dma_do_irq(struct hsu_dma_chip *chip, unsigned short nr, u32 status)
 {
        struct hsu_dma_chan *hsuc;
        struct hsu_dma_desc *desc;
@@ -211,7 +210,7 @@ irqreturn_t hsu_dma_do_irq(struct hsu_dma_chip *chip, unsigned short nr,
 
        /* Sanity check */
        if (nr >= chip->hsu->nr_channels)
-               return IRQ_NONE;
+               return 0;
 
        hsuc = &chip->hsu->chan[nr];
 
@@ -230,7 +229,7 @@ irqreturn_t hsu_dma_do_irq(struct hsu_dma_chip *chip, unsigned short nr,
        }
        spin_unlock_irqrestore(&hsuc->vchan.lock, flags);
 
-       return IRQ_HANDLED;
+       return 1;
 }
 EXPORT_SYMBOL_GPL(hsu_dma_do_irq);
 
index 9916058531d93945a4534145ffdee75d4f6be6e2..b51639f045edaf2fbdfb618eef375abe37186e36 100644 (file)
@@ -29,7 +29,7 @@ static irqreturn_t hsu_pci_irq(int irq, void *dev)
        u32 dmaisr;
        u32 status;
        unsigned short i;
-       irqreturn_t ret = IRQ_NONE;
+       int ret = 0;
        int err;
 
        dmaisr = readl(chip->regs + HSU_PCI_DMAISR);
@@ -37,14 +37,14 @@ static irqreturn_t hsu_pci_irq(int irq, void *dev)
                if (dmaisr & 0x1) {
                        err = hsu_dma_get_status(chip, i, &status);
                        if (err > 0)
-                               ret |= IRQ_HANDLED;
+                               ret |= 1;
                        else if (err == 0)
                                ret |= hsu_dma_do_irq(chip, i, status);
                }
                dmaisr >>= 1;
        }
 
-       return ret;
+       return IRQ_RETVAL(ret);
 }
 
 static int hsu_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)
index a6bffbc47ee2e6d7ca3649de7f37af38fb9d7e0d..b9629b2bfc050b3c6cd4db691da49f99c7d85232 100644 (file)
@@ -670,14 +670,11 @@ static void sdma_event_disable(struct sdma_channel *sdmac, unsigned int event)
        writel_relaxed(val, sdma->regs + chnenbl);
 }
 
-static void sdma_handle_channel_loop(struct sdma_channel *sdmac)
-{
-       dmaengine_desc_get_callback_invoke(&sdmac->desc, NULL);
-}
-
 static void sdma_update_channel_loop(struct sdma_channel *sdmac)
 {
        struct sdma_buffer_descriptor *bd;
+       int error = 0;
+       enum dma_status old_status = sdmac->status;
 
        /*
         * loop mode. Iterate over descriptors, re-setup them and
@@ -689,17 +686,41 @@ static void sdma_update_channel_loop(struct sdma_channel *sdmac)
                if (bd->mode.status & BD_DONE)
                        break;
 
-               if (bd->mode.status & BD_RROR)
+               if (bd->mode.status & BD_RROR) {
+                       bd->mode.status &= ~BD_RROR;
                        sdmac->status = DMA_ERROR;
+                       error = -EIO;
+               }
 
+              /*
+               * We use bd->mode.count to calculate the residue, since contains
+               * the number of bytes present in the current buffer descriptor.
+               */
+
+               sdmac->chn_real_count = bd->mode.count;
                bd->mode.status |= BD_DONE;
+               bd->mode.count = sdmac->period_len;
+
+               /*
+                * The callback is called from the interrupt context in order
+                * to reduce latency and to avoid the risk of altering the
+                * SDMA transaction status by the time the client tasklet is
+                * executed.
+                */
+
+               dmaengine_desc_get_callback_invoke(&sdmac->desc, NULL);
+
                sdmac->buf_tail++;
                sdmac->buf_tail %= sdmac->num_bd;
+
+               if (error)
+                       sdmac->status = old_status;
        }
 }
 
-static void mxc_sdma_handle_channel_normal(struct sdma_channel *sdmac)
+static void mxc_sdma_handle_channel_normal(unsigned long data)
 {
+       struct sdma_channel *sdmac = (struct sdma_channel *) data;
        struct sdma_buffer_descriptor *bd;
        int i, error = 0;
 
@@ -726,16 +747,6 @@ static void mxc_sdma_handle_channel_normal(struct sdma_channel *sdmac)
        dmaengine_desc_get_callback_invoke(&sdmac->desc, NULL);
 }
 
-static void sdma_tasklet(unsigned long data)
-{
-       struct sdma_channel *sdmac = (struct sdma_channel *) data;
-
-       if (sdmac->flags & IMX_DMA_SG_LOOP)
-               sdma_handle_channel_loop(sdmac);
-       else
-               mxc_sdma_handle_channel_normal(sdmac);
-}
-
 static irqreturn_t sdma_int_handler(int irq, void *dev_id)
 {
        struct sdma_engine *sdma = dev_id;
@@ -752,8 +763,8 @@ static irqreturn_t sdma_int_handler(int irq, void *dev_id)
 
                if (sdmac->flags & IMX_DMA_SG_LOOP)
                        sdma_update_channel_loop(sdmac);
-
-               tasklet_schedule(&sdmac->tasklet);
+               else
+                       tasklet_schedule(&sdmac->tasklet);
 
                __clear_bit(channel, &stat);
        }
@@ -1374,7 +1385,8 @@ static enum dma_status sdma_tx_status(struct dma_chan *chan,
        u32 residue;
 
        if (sdmac->flags & IMX_DMA_SG_LOOP)
-               residue = (sdmac->num_bd - sdmac->buf_tail) * sdmac->period_len;
+               residue = (sdmac->num_bd - sdmac->buf_tail) *
+                          sdmac->period_len - sdmac->chn_real_count;
        else
                residue = sdmac->chn_count - sdmac->chn_real_count;
 
@@ -1757,7 +1769,7 @@ static int sdma_probe(struct platform_device *pdev)
                dma_cookie_init(&sdmac->chan);
                sdmac->channel = i;
 
-               tasklet_init(&sdmac->tasklet, sdma_tasklet,
+               tasklet_init(&sdmac->tasklet, mxc_sdma_handle_channel_normal,
                             (unsigned long) sdmac);
                /*
                 * Add the channel to the DMAC list. Do not add channel 0 though
index 1a16feac9a36070715bbe26974661b823e3c08ab..a697a8585ddc346a72de6e30cdb77785a5688e71 100644 (file)
@@ -31,6 +31,11 @@ struct uart_8250_dma {
        struct dma_chan         *rxchan;
        struct dma_chan         *txchan;
 
+       /* Device address base for DMA operations */
+       phys_addr_t             rx_dma_addr;
+       phys_addr_t             tx_dma_addr;
+
+       /* DMA address of the buffer in memory */
        dma_addr_t              rx_addr;
        dma_addr_t              tx_addr;
 
index dcf43f66404f12d2bd290a30adfe494dd056162e..240a361b674fe72ce657067e5303156b7add6a6f 100644 (file)
@@ -639,7 +639,7 @@ static int univ8250_console_match(struct console *co, char *name, int idx,
 {
        char match[] = "uart";  /* 8250-specific earlycon name */
        unsigned char iotype;
-       unsigned long addr;
+       resource_size_t addr;
        int i;
 
        if (strncmp(name, match, 4) != 0)
index 3590d012001f8cf5a10bc8a385ac163abe6b5672..fdbddbc6375da50932d3ce156d4bc2643de67b20 100644 (file)
@@ -142,7 +142,7 @@ void serial8250_rx_dma_flush(struct uart_8250_port *p)
        if (dma->rx_running) {
                dmaengine_pause(dma->rxchan);
                __dma_rx_complete(p);
-               dmaengine_terminate_all(dma->rxchan);
+               dmaengine_terminate_async(dma->rxchan);
        }
 }
 EXPORT_SYMBOL_GPL(serial8250_rx_dma_flush);
@@ -150,6 +150,10 @@ EXPORT_SYMBOL_GPL(serial8250_rx_dma_flush);
 int serial8250_request_dma(struct uart_8250_port *p)
 {
        struct uart_8250_dma    *dma = p->dma;
+       phys_addr_t rx_dma_addr = dma->rx_dma_addr ?
+                                 dma->rx_dma_addr : p->port.mapbase;
+       phys_addr_t tx_dma_addr = dma->tx_dma_addr ?
+                                 dma->tx_dma_addr : p->port.mapbase;
        dma_cap_mask_t          mask;
        struct dma_slave_caps   caps;
        int                     ret;
@@ -157,11 +161,11 @@ int serial8250_request_dma(struct uart_8250_port *p)
        /* Default slave configuration parameters */
        dma->rxconf.direction           = DMA_DEV_TO_MEM;
        dma->rxconf.src_addr_width      = DMA_SLAVE_BUSWIDTH_1_BYTE;
-       dma->rxconf.src_addr            = p->port.mapbase + UART_RX;
+       dma->rxconf.src_addr            = rx_dma_addr + UART_RX;
 
        dma->txconf.direction           = DMA_MEM_TO_DEV;
        dma->txconf.dst_addr_width      = DMA_SLAVE_BUSWIDTH_1_BYTE;
-       dma->txconf.dst_addr            = p->port.mapbase + UART_TX;
+       dma->txconf.dst_addr            = tx_dma_addr + UART_TX;
 
        dma_cap_zero(mask);
        dma_cap_set(DMA_SLAVE, mask);
@@ -247,14 +251,14 @@ void serial8250_release_dma(struct uart_8250_port *p)
                return;
 
        /* Release RX resources */
-       dmaengine_terminate_all(dma->rxchan);
+       dmaengine_terminate_sync(dma->rxchan);
        dma_free_coherent(dma->rxchan->device->dev, dma->rx_size, dma->rx_buf,
                          dma->rx_addr);
        dma_release_channel(dma->rxchan);
        dma->rxchan = NULL;
 
        /* Release TX resources */
-       dmaengine_terminate_all(dma->txchan);
+       dmaengine_terminate_sync(dma->txchan);
        dma_unmap_single(dma->txchan->device->dev, dma->tx_addr,
                         UART_XMIT_SIZE, DMA_TO_DEVICE);
        dma_release_channel(dma->txchan);
index 5c0c123565ad8077cfbed0b9bd4b178006588dcb..459d726f9d59bc709a889163964f775866e7adb4 100644 (file)
@@ -365,18 +365,19 @@ static int dw8250_probe(struct platform_device *pdev)
        struct resource *regs = platform_get_resource(pdev, IORESOURCE_MEM, 0);
        int irq = platform_get_irq(pdev, 0);
        struct uart_port *p = &uart.port;
+       struct device *dev = &pdev->dev;
        struct dw8250_data *data;
        int err;
        u32 val;
 
        if (!regs) {
-               dev_err(&pdev->dev, "no registers defined\n");
+               dev_err(dev, "no registers defined\n");
                return -EINVAL;
        }
 
        if (irq < 0) {
                if (irq != -EPROBE_DEFER)
-                       dev_err(&pdev->dev, "cannot get irq\n");
+                       dev_err(dev, "cannot get irq\n");
                return irq;
        }
 
@@ -387,16 +388,16 @@ static int dw8250_probe(struct platform_device *pdev)
        p->pm           = dw8250_do_pm;
        p->type         = PORT_8250;
        p->flags        = UPF_SHARE_IRQ | UPF_FIXED_PORT;
-       p->dev          = &pdev->dev;
+       p->dev          = dev;
        p->iotype       = UPIO_MEM;
        p->serial_in    = dw8250_serial_in;
        p->serial_out   = dw8250_serial_out;
 
-       p->membase = devm_ioremap(&pdev->dev, regs->start, resource_size(regs));
+       p->membase = devm_ioremap(dev, regs->start, resource_size(regs));
        if (!p->membase)
                return -ENOMEM;
 
-       data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL);
+       data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL);
        if (!data)
                return -ENOMEM;
 
@@ -404,57 +405,57 @@ static int dw8250_probe(struct platform_device *pdev)
        data->usr_reg = DW_UART_USR;
        p->private_data = data;
 
-       data->uart_16550_compatible = device_property_read_bool(p->dev,
+       data->uart_16550_compatible = device_property_read_bool(dev,
                                                "snps,uart-16550-compatible");
 
-       err = device_property_read_u32(p->dev, "reg-shift", &val);
+       err = device_property_read_u32(dev, "reg-shift", &val);
        if (!err)
                p->regshift = val;
 
-       err = device_property_read_u32(p->dev, "reg-io-width", &val);
+       err = device_property_read_u32(dev, "reg-io-width", &val);
        if (!err && val == 4) {
                p->iotype = UPIO_MEM32;
                p->serial_in = dw8250_serial_in32;
                p->serial_out = dw8250_serial_out32;
        }
 
-       if (device_property_read_bool(p->dev, "dcd-override")) {
+       if (device_property_read_bool(dev, "dcd-override")) {
                /* Always report DCD as active */
                data->msr_mask_on |= UART_MSR_DCD;
                data->msr_mask_off |= UART_MSR_DDCD;
        }
 
-       if (device_property_read_bool(p->dev, "dsr-override")) {
+       if (device_property_read_bool(dev, "dsr-override")) {
                /* Always report DSR as active */
                data->msr_mask_on |= UART_MSR_DSR;
                data->msr_mask_off |= UART_MSR_DDSR;
        }
 
-       if (device_property_read_bool(p->dev, "cts-override")) {
+       if (device_property_read_bool(dev, "cts-override")) {
                /* Always report CTS as active */
                data->msr_mask_on |= UART_MSR_CTS;
                data->msr_mask_off |= UART_MSR_DCTS;
        }
 
-       if (device_property_read_bool(p->dev, "ri-override")) {
+       if (device_property_read_bool(dev, "ri-override")) {
                /* Always report Ring indicator as inactive */
                data->msr_mask_off |= UART_MSR_RI;
                data->msr_mask_off |= UART_MSR_TERI;
        }
 
        /* Always ask for fixed clock rate from a property. */
-       device_property_read_u32(p->dev, "clock-frequency", &p->uartclk);
+       device_property_read_u32(dev, "clock-frequency", &p->uartclk);
 
        /* If there is separate baudclk, get the rate from it. */
-       data->clk = devm_clk_get(&pdev->dev, "baudclk");
+       data->clk = devm_clk_get(dev, "baudclk");
        if (IS_ERR(data->clk) && PTR_ERR(data->clk) != -EPROBE_DEFER)
-               data->clk = devm_clk_get(&pdev->dev, NULL);
+               data->clk = devm_clk_get(dev, NULL);
        if (IS_ERR(data->clk) && PTR_ERR(data->clk) == -EPROBE_DEFER)
                return -EPROBE_DEFER;
        if (!IS_ERR_OR_NULL(data->clk)) {
                err = clk_prepare_enable(data->clk);
                if (err)
-                       dev_warn(&pdev->dev, "could not enable optional baudclk: %d\n",
+                       dev_warn(dev, "could not enable optional baudclk: %d\n",
                                 err);
                else
                        p->uartclk = clk_get_rate(data->clk);
@@ -462,24 +463,24 @@ static int dw8250_probe(struct platform_device *pdev)
 
        /* If no clock rate is defined, fail. */
        if (!p->uartclk) {
-               dev_err(&pdev->dev, "clock rate not defined\n");
+               dev_err(dev, "clock rate not defined\n");
                return -EINVAL;
        }
 
-       data->pclk = devm_clk_get(&pdev->dev, "apb_pclk");
-       if (IS_ERR(data->clk) && PTR_ERR(data->clk) == -EPROBE_DEFER) {
+       data->pclk = devm_clk_get(dev, "apb_pclk");
+       if (IS_ERR(data->pclk) && PTR_ERR(data->pclk) == -EPROBE_DEFER) {
                err = -EPROBE_DEFER;
                goto err_clk;
        }
        if (!IS_ERR(data->pclk)) {
                err = clk_prepare_enable(data->pclk);
                if (err) {
-                       dev_err(&pdev->dev, "could not enable apb_pclk\n");
+                       dev_err(dev, "could not enable apb_pclk\n");
                        goto err_clk;
                }
        }
 
-       data->rst = devm_reset_control_get_optional(&pdev->dev, NULL);
+       data->rst = devm_reset_control_get_optional(dev, NULL);
        if (IS_ERR(data->rst) && PTR_ERR(data->rst) == -EPROBE_DEFER) {
                err = -EPROBE_DEFER;
                goto err_pclk;
@@ -511,8 +512,8 @@ static int dw8250_probe(struct platform_device *pdev)
 
        platform_set_drvdata(pdev, data);
 
-       pm_runtime_set_active(&pdev->dev);
-       pm_runtime_enable(&pdev->dev);
+       pm_runtime_set_active(dev);
+       pm_runtime_enable(dev);
 
        return 0;
 
@@ -624,6 +625,7 @@ static const struct acpi_device_id dw8250_acpi_match[] = {
        { "APMC0D08", 0},
        { "AMD0020", 0 },
        { "AMDI0020", 0 },
+       { "HISI0031", 0 },
        { },
 };
 MODULE_DEVICE_TABLE(acpi, dw8250_acpi_match);
diff --git a/drivers/tty/serial/8250/8250_lpss.c b/drivers/tty/serial/8250/8250_lpss.c
new file mode 100644 (file)
index 0000000..886fcf3
--- /dev/null
@@ -0,0 +1,378 @@
+/*
+ * 8250_lpss.c - Driver for UART on Intel Braswell and various other Intel SoCs
+ *
+ * Copyright (C) 2016 Intel Corporation
+ * Author: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#include <linux/bitops.h>
+#include <linux/module.h>
+#include <linux/pci.h>
+#include <linux/rational.h>
+
+#include <linux/dmaengine.h>
+#include <linux/dma/dw.h>
+
+#include "8250.h"
+
+#define PCI_DEVICE_ID_INTEL_QRK_UARTx  0x0936
+
+#define PCI_DEVICE_ID_INTEL_BYT_UART1  0x0f0a
+#define PCI_DEVICE_ID_INTEL_BYT_UART2  0x0f0c
+
+#define PCI_DEVICE_ID_INTEL_BSW_UART1  0x228a
+#define PCI_DEVICE_ID_INTEL_BSW_UART2  0x228c
+
+#define PCI_DEVICE_ID_INTEL_BDW_UART1  0x9ce3
+#define PCI_DEVICE_ID_INTEL_BDW_UART2  0x9ce4
+
+/* Intel LPSS specific registers */
+
+#define BYT_PRV_CLK                    0x800
+#define BYT_PRV_CLK_EN                 BIT(0)
+#define BYT_PRV_CLK_M_VAL_SHIFT                1
+#define BYT_PRV_CLK_N_VAL_SHIFT                16
+#define BYT_PRV_CLK_UPDATE             BIT(31)
+
+#define BYT_TX_OVF_INT                 0x820
+#define BYT_TX_OVF_INT_MASK            BIT(1)
+
+struct lpss8250;
+
+struct lpss8250_board {
+       unsigned long freq;
+       unsigned int base_baud;
+       int (*setup)(struct lpss8250 *, struct uart_port *p);
+       void (*exit)(struct lpss8250 *);
+};
+
+struct lpss8250 {
+       int line;
+       struct lpss8250_board *board;
+
+       /* DMA parameters */
+       struct uart_8250_dma dma;
+       struct dw_dma_chip dma_chip;
+       struct dw_dma_slave dma_param;
+       u8 dma_maxburst;
+};
+
+static void byt_set_termios(struct uart_port *p, struct ktermios *termios,
+                           struct ktermios *old)
+{
+       unsigned int baud = tty_termios_baud_rate(termios);
+       struct lpss8250 *lpss = p->private_data;
+       unsigned long fref = lpss->board->freq, fuart = baud * 16;
+       unsigned long w = BIT(15) - 1;
+       unsigned long m, n;
+       u32 reg;
+
+       /* Gracefully handle the B0 case: fall back to B9600 */
+       fuart = fuart ? fuart : 9600 * 16;
+
+       /* Get Fuart closer to Fref */
+       fuart *= rounddown_pow_of_two(fref / fuart);
+
+       /*
+        * For baud rates 0.5M, 1M, 1.5M, 2M, 2.5M, 3M, 3.5M and 4M the
+        * dividers must be adjusted.
+        *
+        * uartclk = (m / n) * 100 MHz, where m <= n
+        */
+       rational_best_approximation(fuart, fref, w, w, &m, &n);
+       p->uartclk = fuart;
+
+       /* Reset the clock */
+       reg = (m << BYT_PRV_CLK_M_VAL_SHIFT) | (n << BYT_PRV_CLK_N_VAL_SHIFT);
+       writel(reg, p->membase + BYT_PRV_CLK);
+       reg |= BYT_PRV_CLK_EN | BYT_PRV_CLK_UPDATE;
+       writel(reg, p->membase + BYT_PRV_CLK);
+
+       p->status &= ~UPSTAT_AUTOCTS;
+       if (termios->c_cflag & CRTSCTS)
+               p->status |= UPSTAT_AUTOCTS;
+
+       serial8250_do_set_termios(p, termios, old);
+}
+
+static unsigned int byt_get_mctrl(struct uart_port *port)
+{
+       unsigned int ret = serial8250_do_get_mctrl(port);
+
+       /* Force DCD and DSR signals to permanently be reported as active */
+       ret |= TIOCM_CAR | TIOCM_DSR;
+
+       return ret;
+}
+
+static int byt_serial_setup(struct lpss8250 *lpss, struct uart_port *port)
+{
+       struct dw_dma_slave *param = &lpss->dma_param;
+       struct uart_8250_port *up = up_to_u8250p(port);
+       struct pci_dev *pdev = to_pci_dev(port->dev);
+       unsigned int dma_devfn = PCI_DEVFN(PCI_SLOT(pdev->devfn), 0);
+       struct pci_dev *dma_dev = pci_get_slot(pdev->bus, dma_devfn);
+
+       switch (pdev->device) {
+       case PCI_DEVICE_ID_INTEL_BYT_UART1:
+       case PCI_DEVICE_ID_INTEL_BSW_UART1:
+       case PCI_DEVICE_ID_INTEL_BDW_UART1:
+               param->src_id = 3;
+               param->dst_id = 2;
+               break;
+       case PCI_DEVICE_ID_INTEL_BYT_UART2:
+       case PCI_DEVICE_ID_INTEL_BSW_UART2:
+       case PCI_DEVICE_ID_INTEL_BDW_UART2:
+               param->src_id = 5;
+               param->dst_id = 4;
+               break;
+       default:
+               return -EINVAL;
+       }
+
+       param->dma_dev = &dma_dev->dev;
+       param->m_master = 0;
+       param->p_master = 1;
+
+       /* TODO: Detect FIFO size automaticaly for DesignWare 8250 */
+       port->fifosize = 64;
+       up->tx_loadsz = 64;
+
+       lpss->dma_maxburst = 16;
+
+       port->set_termios = byt_set_termios;
+       port->get_mctrl = byt_get_mctrl;
+
+       /* Disable TX counter interrupts */
+       writel(BYT_TX_OVF_INT_MASK, port->membase + BYT_TX_OVF_INT);
+
+       return 0;
+}
+
+#ifdef CONFIG_SERIAL_8250_DMA
+static const struct dw_dma_platform_data qrk_serial_dma_pdata = {
+       .nr_channels = 2,
+       .is_private = true,
+       .is_nollp = true,
+       .chan_allocation_order = CHAN_ALLOCATION_ASCENDING,
+       .chan_priority = CHAN_PRIORITY_ASCENDING,
+       .block_size = 4095,
+       .nr_masters = 1,
+       .data_width = {4},
+};
+
+static void qrk_serial_setup_dma(struct lpss8250 *lpss, struct uart_port *port)
+{
+       struct uart_8250_dma *dma = &lpss->dma;
+       struct dw_dma_chip *chip = &lpss->dma_chip;
+       struct dw_dma_slave *param = &lpss->dma_param;
+       struct pci_dev *pdev = to_pci_dev(port->dev);
+       int ret;
+
+       chip->dev = &pdev->dev;
+       chip->irq = pdev->irq;
+       chip->regs = pci_ioremap_bar(pdev, 1);
+       chip->pdata = &qrk_serial_dma_pdata;
+
+       /* Falling back to PIO mode if DMA probing fails */
+       ret = dw_dma_probe(chip);
+       if (ret)
+               return;
+
+       /* Special DMA address for UART */
+       dma->rx_dma_addr = 0xfffff000;
+       dma->tx_dma_addr = 0xfffff000;
+
+       param->dma_dev = &pdev->dev;
+       param->src_id = 0;
+       param->dst_id = 1;
+       param->hs_polarity = true;
+
+       lpss->dma_maxburst = 8;
+}
+
+static void qrk_serial_exit_dma(struct lpss8250 *lpss)
+{
+       struct dw_dma_slave *param = &lpss->dma_param;
+
+       if (!param->dma_dev)
+               return;
+       dw_dma_remove(&lpss->dma_chip);
+}
+#else  /* CONFIG_SERIAL_8250_DMA */
+static void qrk_serial_setup_dma(struct lpss8250 *lpss, struct uart_port *port) {}
+static void qrk_serial_exit_dma(struct lpss8250 *lpss) {}
+#endif /* !CONFIG_SERIAL_8250_DMA */
+
+static int qrk_serial_setup(struct lpss8250 *lpss, struct uart_port *port)
+{
+       struct pci_dev *pdev = to_pci_dev(port->dev);
+       int ret;
+
+       ret = pci_alloc_irq_vectors(pdev, 1, 1, 0);
+       if (ret < 0)
+               return ret;
+
+       port->irq = pci_irq_vector(pdev, 0);
+
+       qrk_serial_setup_dma(lpss, port);
+       return 0;
+}
+
+static void qrk_serial_exit(struct lpss8250 *lpss)
+{
+       qrk_serial_exit_dma(lpss);
+}
+
+static bool lpss8250_dma_filter(struct dma_chan *chan, void *param)
+{
+       struct dw_dma_slave *dws = param;
+
+       if (dws->dma_dev != chan->device->dev)
+               return false;
+
+       chan->private = dws;
+       return true;
+}
+
+static int lpss8250_dma_setup(struct lpss8250 *lpss, struct uart_8250_port *port)
+{
+       struct uart_8250_dma *dma = &lpss->dma;
+       struct dw_dma_slave *rx_param, *tx_param;
+       struct device *dev = port->port.dev;
+
+       if (!lpss->dma_param.dma_dev)
+               return 0;
+
+       rx_param = devm_kzalloc(dev, sizeof(*rx_param), GFP_KERNEL);
+       if (!rx_param)
+               return -ENOMEM;
+
+       tx_param = devm_kzalloc(dev, sizeof(*tx_param), GFP_KERNEL);
+       if (!tx_param)
+               return -ENOMEM;
+
+       *rx_param = lpss->dma_param;
+       dma->rxconf.src_maxburst = lpss->dma_maxburst;
+
+       *tx_param = lpss->dma_param;
+       dma->txconf.dst_maxburst = lpss->dma_maxburst;
+
+       dma->fn = lpss8250_dma_filter;
+       dma->rx_param = rx_param;
+       dma->tx_param = tx_param;
+
+       port->dma = dma;
+       return 0;
+}
+
+static int lpss8250_probe(struct pci_dev *pdev, const struct pci_device_id *id)
+{
+       struct uart_8250_port uart;
+       struct lpss8250 *lpss;
+       int ret;
+
+       ret = pcim_enable_device(pdev);
+       if (ret)
+               return ret;
+
+       pci_set_master(pdev);
+
+       lpss = devm_kzalloc(&pdev->dev, sizeof(*lpss), GFP_KERNEL);
+       if (!lpss)
+               return -ENOMEM;
+
+       lpss->board = (struct lpss8250_board *)id->driver_data;
+
+       memset(&uart, 0, sizeof(struct uart_8250_port));
+
+       uart.port.dev = &pdev->dev;
+       uart.port.irq = pdev->irq;
+       uart.port.private_data = lpss;
+       uart.port.type = PORT_16550A;
+       uart.port.iotype = UPIO_MEM;
+       uart.port.regshift = 2;
+       uart.port.uartclk = lpss->board->base_baud * 16;
+       uart.port.flags = UPF_SHARE_IRQ | UPF_FIXED_PORT | UPF_FIXED_TYPE;
+       uart.capabilities = UART_CAP_FIFO | UART_CAP_AFE;
+       uart.port.mapbase = pci_resource_start(pdev, 0);
+       uart.port.membase = pcim_iomap(pdev, 0, 0);
+       if (!uart.port.membase)
+               return -ENOMEM;
+
+       ret = lpss->board->setup(lpss, &uart.port);
+       if (ret)
+               return ret;
+
+       ret = lpss8250_dma_setup(lpss, &uart);
+       if (ret)
+               goto err_exit;
+
+       ret = serial8250_register_8250_port(&uart);
+       if (ret < 0)
+               goto err_exit;
+
+       lpss->line = ret;
+
+       pci_set_drvdata(pdev, lpss);
+       return 0;
+
+err_exit:
+       if (lpss->board->exit)
+               lpss->board->exit(lpss);
+       return ret;
+}
+
+static void lpss8250_remove(struct pci_dev *pdev)
+{
+       struct lpss8250 *lpss = pci_get_drvdata(pdev);
+
+       if (lpss->board->exit)
+               lpss->board->exit(lpss);
+
+       serial8250_unregister_port(lpss->line);
+}
+
+static const struct lpss8250_board byt_board = {
+       .freq = 100000000,
+       .base_baud = 2764800,
+       .setup = byt_serial_setup,
+};
+
+static const struct lpss8250_board qrk_board = {
+       .freq = 44236800,
+       .base_baud = 2764800,
+       .setup = qrk_serial_setup,
+       .exit = qrk_serial_exit,
+};
+
+#define LPSS_DEVICE(id, board) { PCI_VDEVICE(INTEL, id), (kernel_ulong_t)&board }
+
+static const struct pci_device_id pci_ids[] = {
+       LPSS_DEVICE(PCI_DEVICE_ID_INTEL_QRK_UARTx, qrk_board),
+       LPSS_DEVICE(PCI_DEVICE_ID_INTEL_BYT_UART1, byt_board),
+       LPSS_DEVICE(PCI_DEVICE_ID_INTEL_BYT_UART2, byt_board),
+       LPSS_DEVICE(PCI_DEVICE_ID_INTEL_BSW_UART1, byt_board),
+       LPSS_DEVICE(PCI_DEVICE_ID_INTEL_BSW_UART2, byt_board),
+       LPSS_DEVICE(PCI_DEVICE_ID_INTEL_BDW_UART1, byt_board),
+       LPSS_DEVICE(PCI_DEVICE_ID_INTEL_BDW_UART2, byt_board),
+       { },
+};
+MODULE_DEVICE_TABLE(pci, pci_ids);
+
+static struct pci_driver lpss8250_pci_driver = {
+       .name           = "8250_lpss",
+       .id_table       = pci_ids,
+       .probe          = lpss8250_probe,
+       .remove         = lpss8250_remove,
+};
+
+module_pci_driver(lpss8250_pci_driver);
+
+MODULE_AUTHOR("Intel Corporation");
+MODULE_LICENSE("GPL v2");
+MODULE_DESCRIPTION("Intel LPSS UART driver");
index 20c5db2f426406a50fc41ef90f2e268deac18f72..39c2324484ddf05edf9d241ec7f0d7b5ec4fd40c 100644 (file)
@@ -99,27 +99,27 @@ static int dnv_handle_irq(struct uart_port *p)
        struct uart_8250_port *up = up_to_u8250p(p);
        unsigned int fisr = serial_port_in(p, INTEL_MID_UART_DNV_FISR);
        u32 status;
-       int ret = IRQ_NONE;
+       int ret = 0;
        int err;
 
        if (fisr & BIT(2)) {
                err = hsu_dma_get_status(&mid->dma_chip, 1, &status);
                if (err > 0) {
                        serial8250_rx_dma_flush(up);
-                       ret |= IRQ_HANDLED;
+                       ret |= 1;
                } else if (err == 0)
                        ret |= hsu_dma_do_irq(&mid->dma_chip, 1, status);
        }
        if (fisr & BIT(1)) {
                err = hsu_dma_get_status(&mid->dma_chip, 0, &status);
                if (err > 0)
-                       ret |= IRQ_HANDLED;
+                       ret |= 1;
                else if (err == 0)
                        ret |= hsu_dma_do_irq(&mid->dma_chip, 0, status);
        }
        if (fisr & BIT(0))
                ret |= serial8250_handle_irq(p, serial_port_in(p, UART_IIR));
-       return ret;
+       return IRQ_RETVAL(ret);
 }
 
 #define DNV_DMA_CHAN_OFFSET 0x80
index 3611ec9bb4fa27407cc50f157321f8e4ed1708fd..ce0cc471bfc3c6cb6b314327705e62e4634fa471 100644 (file)
@@ -62,7 +62,7 @@ mtk8250_set_termios(struct uart_port *port, struct ktermios *termios,
         */
        baud = uart_get_baud_rate(port, termios, old,
                                  port->uartclk / 16 / 0xffff,
-                                 port->uartclk / 16);
+                                 port->uartclk);
 
        if (baud <= 115200) {
                serial_port_out(port, UART_MTK_HIGHS, 0x0);
@@ -76,10 +76,6 @@ mtk8250_set_termios(struct uart_port *port, struct ktermios *termios,
                quot = DIV_ROUND_UP(port->uartclk, 4 * baud);
        } else {
                serial_port_out(port, UART_MTK_HIGHS, 0x3);
-
-               /* Set to highest baudrate supported */
-               if (baud >= 1152000)
-                       baud = 921600;
                quot = DIV_ROUND_UP(port->uartclk, 256 * baud);
        }
 
index bc51b32b2774e961627d7778c43d8ddf591249b4..4ea8b51dd5d3748856843e340ef6676bb9d809c0 100644 (file)
 #include <linux/serial_core.h>
 #include <linux/8250_pci.h>
 #include <linux/bitops.h>
-#include <linux/rational.h>
 
 #include <asm/byteorder.h>
 #include <asm/io.h>
 
-#include <linux/dmaengine.h>
-#include <linux/platform_data/dma-dw.h>
-
 #include "8250.h"
 
 /*
@@ -1349,160 +1345,6 @@ ce4100_serial_setup(struct serial_private *priv,
        return ret;
 }
 
-#define PCI_DEVICE_ID_INTEL_BYT_UART1  0x0f0a
-#define PCI_DEVICE_ID_INTEL_BYT_UART2  0x0f0c
-
-#define PCI_DEVICE_ID_INTEL_BSW_UART1  0x228a
-#define PCI_DEVICE_ID_INTEL_BSW_UART2  0x228c
-
-#define PCI_DEVICE_ID_INTEL_BDW_UART1  0x9ce3
-#define PCI_DEVICE_ID_INTEL_BDW_UART2  0x9ce4
-
-#define BYT_PRV_CLK                    0x800
-#define BYT_PRV_CLK_EN                 (1 << 0)
-#define BYT_PRV_CLK_M_VAL_SHIFT                1
-#define BYT_PRV_CLK_N_VAL_SHIFT                16
-#define BYT_PRV_CLK_UPDATE             (1 << 31)
-
-#define BYT_TX_OVF_INT                 0x820
-#define BYT_TX_OVF_INT_MASK            (1 << 1)
-
-static void
-byt_set_termios(struct uart_port *p, struct ktermios *termios,
-               struct ktermios *old)
-{
-       unsigned int baud = tty_termios_baud_rate(termios);
-       unsigned long fref = 100000000, fuart = baud * 16;
-       unsigned long w = BIT(15) - 1;
-       unsigned long m, n;
-       u32 reg;
-
-       /* Gracefully handle the B0 case: fall back to B9600 */
-       fuart = fuart ? fuart : 9600 * 16;
-
-       /* Get Fuart closer to Fref */
-       fuart *= rounddown_pow_of_two(fref / fuart);
-
-       /*
-        * For baud rates 0.5M, 1M, 1.5M, 2M, 2.5M, 3M, 3.5M and 4M the
-        * dividers must be adjusted.
-        *
-        * uartclk = (m / n) * 100 MHz, where m <= n
-        */
-       rational_best_approximation(fuart, fref, w, w, &m, &n);
-       p->uartclk = fuart;
-
-       /* Reset the clock */
-       reg = (m << BYT_PRV_CLK_M_VAL_SHIFT) | (n << BYT_PRV_CLK_N_VAL_SHIFT);
-       writel(reg, p->membase + BYT_PRV_CLK);
-       reg |= BYT_PRV_CLK_EN | BYT_PRV_CLK_UPDATE;
-       writel(reg, p->membase + BYT_PRV_CLK);
-
-       p->status &= ~UPSTAT_AUTOCTS;
-       if (termios->c_cflag & CRTSCTS)
-               p->status |= UPSTAT_AUTOCTS;
-
-       serial8250_do_set_termios(p, termios, old);
-}
-
-static bool byt_dma_filter(struct dma_chan *chan, void *param)
-{
-       struct dw_dma_slave *dws = param;
-
-       if (dws->dma_dev != chan->device->dev)
-               return false;
-
-       chan->private = dws;
-       return true;
-}
-
-static unsigned int
-byt_get_mctrl(struct uart_port *port)
-{
-       unsigned int ret = serial8250_do_get_mctrl(port);
-
-       /* Force DCD and DSR signals to permanently be reported as active. */
-       ret |= TIOCM_CAR | TIOCM_DSR;
-
-       return ret;
-}
-
-static int
-byt_serial_setup(struct serial_private *priv,
-                const struct pciserial_board *board,
-                struct uart_8250_port *port, int idx)
-{
-       struct pci_dev *pdev = priv->dev;
-       struct device *dev = port->port.dev;
-       struct uart_8250_dma *dma;
-       struct dw_dma_slave *tx_param, *rx_param;
-       struct pci_dev *dma_dev;
-       int ret;
-
-       dma = devm_kzalloc(dev, sizeof(*dma), GFP_KERNEL);
-       if (!dma)
-               return -ENOMEM;
-
-       tx_param = devm_kzalloc(dev, sizeof(*tx_param), GFP_KERNEL);
-       if (!tx_param)
-               return -ENOMEM;
-
-       rx_param = devm_kzalloc(dev, sizeof(*rx_param), GFP_KERNEL);
-       if (!rx_param)
-               return -ENOMEM;
-
-       switch (pdev->device) {
-       case PCI_DEVICE_ID_INTEL_BYT_UART1:
-       case PCI_DEVICE_ID_INTEL_BSW_UART1:
-       case PCI_DEVICE_ID_INTEL_BDW_UART1:
-               rx_param->src_id = 3;
-               tx_param->dst_id = 2;
-               break;
-       case PCI_DEVICE_ID_INTEL_BYT_UART2:
-       case PCI_DEVICE_ID_INTEL_BSW_UART2:
-       case PCI_DEVICE_ID_INTEL_BDW_UART2:
-               rx_param->src_id = 5;
-               tx_param->dst_id = 4;
-               break;
-       default:
-               return -EINVAL;
-       }
-
-       rx_param->m_master = 0;
-       rx_param->p_master = 1;
-
-       dma->rxconf.src_maxburst = 16;
-
-       tx_param->m_master = 0;
-       tx_param->p_master = 1;
-
-       dma->txconf.dst_maxburst = 16;
-
-       dma_dev = pci_get_slot(pdev->bus, PCI_DEVFN(PCI_SLOT(pdev->devfn), 0));
-       rx_param->dma_dev = &dma_dev->dev;
-       tx_param->dma_dev = &dma_dev->dev;
-
-       dma->fn = byt_dma_filter;
-       dma->rx_param = rx_param;
-       dma->tx_param = tx_param;
-
-       ret = pci_default_setup(priv, board, port, idx);
-       port->port.iotype = UPIO_MEM;
-       port->port.type = PORT_16550A;
-       port->port.flags = (port->port.flags | UPF_FIXED_PORT | UPF_FIXED_TYPE);
-       port->port.set_termios = byt_set_termios;
-       port->port.get_mctrl = byt_get_mctrl;
-       port->port.fifosize = 64;
-       port->tx_loadsz = 64;
-       port->dma = dma;
-       port->capabilities = UART_CAP_FIFO | UART_CAP_AFE;
-
-       /* Disable Tx counter interrupts */
-       writel(BYT_TX_OVF_INT_MASK, port->port.membase + BYT_TX_OVF_INT);
-
-       return ret;
-}
-
 static int
 pci_omegapci_setup(struct serial_private *priv,
                      const struct pciserial_board *board,
@@ -1934,7 +1776,6 @@ pci_wch_ch38x_setup(struct serial_private *priv,
 #define PCI_DEVICE_ID_COMMTECH_4222PCIE        0x0022
 #define PCI_DEVICE_ID_BROADCOM_TRUMANAGE 0x160a
 #define PCI_DEVICE_ID_AMCC_ADDIDATA_APCI7800 0x818e
-#define PCI_DEVICE_ID_INTEL_QRK_UART   0x0936
 
 #define PCI_VENDOR_ID_SUNIX            0x1fd4
 #define PCI_DEVICE_ID_SUNIX_1999       0x1999
@@ -2078,48 +1919,6 @@ static struct pci_serial_quirk pci_serial_quirks[] __refdata = {
                .subdevice      = PCI_ANY_ID,
                .setup          = kt_serial_setup,
        },
-       {
-               .vendor         = PCI_VENDOR_ID_INTEL,
-               .device         = PCI_DEVICE_ID_INTEL_BYT_UART1,
-               .subvendor      = PCI_ANY_ID,
-               .subdevice      = PCI_ANY_ID,
-               .setup          = byt_serial_setup,
-       },
-       {
-               .vendor         = PCI_VENDOR_ID_INTEL,
-               .device         = PCI_DEVICE_ID_INTEL_BYT_UART2,
-               .subvendor      = PCI_ANY_ID,
-               .subdevice      = PCI_ANY_ID,
-               .setup          = byt_serial_setup,
-       },
-       {
-               .vendor         = PCI_VENDOR_ID_INTEL,
-               .device         = PCI_DEVICE_ID_INTEL_BSW_UART1,
-               .subvendor      = PCI_ANY_ID,
-               .subdevice      = PCI_ANY_ID,
-               .setup          = byt_serial_setup,
-       },
-       {
-               .vendor         = PCI_VENDOR_ID_INTEL,
-               .device         = PCI_DEVICE_ID_INTEL_BSW_UART2,
-               .subvendor      = PCI_ANY_ID,
-               .subdevice      = PCI_ANY_ID,
-               .setup          = byt_serial_setup,
-       },
-       {
-               .vendor         = PCI_VENDOR_ID_INTEL,
-               .device         = PCI_DEVICE_ID_INTEL_BDW_UART1,
-               .subvendor      = PCI_ANY_ID,
-               .subdevice      = PCI_ANY_ID,
-               .setup          = byt_serial_setup,
-       },
-       {
-               .vendor         = PCI_VENDOR_ID_INTEL,
-               .device         = PCI_DEVICE_ID_INTEL_BDW_UART2,
-               .subvendor      = PCI_ANY_ID,
-               .subdevice      = PCI_ANY_ID,
-               .setup          = byt_serial_setup,
-       },
        /*
         * ITE
         */
@@ -2992,8 +2791,6 @@ enum pci_board_num_t {
        pbn_ADDIDATA_PCIe_4_3906250,
        pbn_ADDIDATA_PCIe_8_3906250,
        pbn_ce4100_1_115200,
-       pbn_byt,
-       pbn_qrk,
        pbn_omegapci,
        pbn_NETMOS9900_2s_115200,
        pbn_brcm_trumanage,
@@ -3769,18 +3566,6 @@ static struct pciserial_board pci_boards[] = {
                .base_baud      = 921600,
                .reg_shift      = 2,
        },
-       [pbn_byt] = {
-               .flags          = FL_BASE0,
-               .num_ports      = 1,
-               .base_baud      = 2764800,
-               .reg_shift      = 2,
-       },
-       [pbn_qrk] = {
-               .flags          = FL_BASE0,
-               .num_ports      = 1,
-               .base_baud      = 2764800,
-               .reg_shift      = 2,
-       },
        [pbn_omegapci] = {
                .flags          = FL_BASE0,
                .num_ports      = 8,
@@ -3892,6 +3677,15 @@ static const struct pci_device_id blacklist[] = {
        { PCI_VDEVICE(INTEL, 0x081d), },
        { PCI_VDEVICE(INTEL, 0x1191), },
        { PCI_VDEVICE(INTEL, 0x19d8), },
+
+       /* Intel platforms with DesignWare UART */
+       { PCI_VDEVICE(INTEL, 0x0936), },
+       { PCI_VDEVICE(INTEL, 0x0f0a), },
+       { PCI_VDEVICE(INTEL, 0x0f0c), },
+       { PCI_VDEVICE(INTEL, 0x228a), },
+       { PCI_VDEVICE(INTEL, 0x228c), },
+       { PCI_VDEVICE(INTEL, 0x9ce3), },
+       { PCI_VDEVICE(INTEL, 0x9ce4), },
 };
 
 /*
@@ -5659,40 +5453,7 @@ static struct pci_device_id serial_pci_tbl[] = {
        {       PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_CE4100_UART,
                PCI_ANY_ID,  PCI_ANY_ID, 0, 0,
                pbn_ce4100_1_115200 },
-       /* Intel BayTrail */
-       {       PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_BYT_UART1,
-               PCI_ANY_ID,  PCI_ANY_ID,
-               PCI_CLASS_COMMUNICATION_SERIAL << 8, 0xff0000,
-               pbn_byt },
-       {       PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_BYT_UART2,
-               PCI_ANY_ID,  PCI_ANY_ID,
-               PCI_CLASS_COMMUNICATION_SERIAL << 8, 0xff0000,
-               pbn_byt },
-       {       PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_BSW_UART1,
-               PCI_ANY_ID,  PCI_ANY_ID,
-               PCI_CLASS_COMMUNICATION_SERIAL << 8, 0xff0000,
-               pbn_byt },
-       {       PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_BSW_UART2,
-               PCI_ANY_ID,  PCI_ANY_ID,
-               PCI_CLASS_COMMUNICATION_SERIAL << 8, 0xff0000,
-               pbn_byt },
-
-       /* Intel Broadwell */
-       {       PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_BDW_UART1,
-               PCI_ANY_ID,  PCI_ANY_ID,
-               PCI_CLASS_COMMUNICATION_SERIAL << 8, 0xff0000,
-               pbn_byt },
-       {       PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_BDW_UART2,
-               PCI_ANY_ID,  PCI_ANY_ID,
-               PCI_CLASS_COMMUNICATION_SERIAL << 8, 0xff0000,
-               pbn_byt },
 
-       /*
-        * Intel Quark x1000
-        */
-       {       PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_QRK_UART,
-               PCI_ANY_ID, PCI_ANY_ID, 0, 0,
-               pbn_qrk },
        /*
         * Cronyx Omega PCI
         */
index bdfa659b9606a93360fd6e978a6b9c89d9a3e251..ae3a10462b2ab58d6f0a1502b28a7cd54dc85f33 100644 (file)
@@ -178,7 +178,7 @@ static const struct serial8250_config uart_config[] = {
                .fifo_size      = 16,
                .tx_loadsz      = 16,
                .fcr            = UART_FCR_ENABLE_FIFO | UART_FCR_R_TRIG_00,
-               .flags          = UART_CAP_FIFO | UART_CAP_AFE,
+               .flags          = UART_CAP_FIFO /* | UART_CAP_AFE */,
        },
        [PORT_U6_16550A] = {
                .name           = "U6_16550A",
@@ -585,11 +585,11 @@ EXPORT_SYMBOL_GPL(serial8250_rpm_put);
  */
 int serial8250_em485_init(struct uart_8250_port *p)
 {
-       if (p->em485 != NULL)
+       if (p->em485)
                return 0;
 
        p->em485 = kmalloc(sizeof(struct uart_8250_em485), GFP_ATOMIC);
-       if (p->em485 == NULL)
+       if (!p->em485)
                return -ENOMEM;
 
        setup_timer(&p->em485->stop_tx_timer,
@@ -619,7 +619,7 @@ EXPORT_SYMBOL_GPL(serial8250_em485_init);
  */
 void serial8250_em485_destroy(struct uart_8250_port *p)
 {
-       if (p->em485 == NULL)
+       if (!p->em485)
                return;
 
        del_timer(&p->em485->start_tx_timer);
@@ -1402,10 +1402,8 @@ static void serial8250_stop_rx(struct uart_port *port)
 
 static void __do_stop_tx_rs485(struct uart_8250_port *p)
 {
-       if (!p->em485)
-               return;
-
        serial8250_em485_rts_after_send(p);
+
        /*
         * Empty the RX FIFO, we are not interested in anything
         * received during the half-duplex transmission.
@@ -1414,12 +1412,8 @@ static void __do_stop_tx_rs485(struct uart_8250_port *p)
        if (!(p->port.rs485.flags & SER_RS485_RX_DURING_TX)) {
                serial8250_clear_fifos(p);
 
-               serial8250_rpm_get(p);
-
                p->ier |= UART_IER_RLSI | UART_IER_RDI;
                serial_port_out(&p->port, UART_IER, p->ier);
-
-               serial8250_rpm_put(p);
        }
 }
 
@@ -1429,6 +1423,7 @@ static void serial8250_em485_handle_stop_tx(unsigned long arg)
        struct uart_8250_em485 *em485 = p->em485;
        unsigned long flags;
 
+       serial8250_rpm_get(p);
        spin_lock_irqsave(&p->port.lock, flags);
        if (em485 &&
            em485->active_timer == &em485->stop_tx_timer) {
@@ -1436,15 +1431,13 @@ static void serial8250_em485_handle_stop_tx(unsigned long arg)
                em485->active_timer = NULL;
        }
        spin_unlock_irqrestore(&p->port.lock, flags);
+       serial8250_rpm_put(p);
 }
 
 static void __stop_tx_rs485(struct uart_8250_port *p)
 {
        struct uart_8250_em485 *em485 = p->em485;
 
-       if (!em485)
-               return;
-
        /*
         * __do_stop_tx_rs485 is going to set RTS according to config
         * AND flush RX FIFO if required.
@@ -1475,7 +1468,7 @@ static inline void __stop_tx(struct uart_8250_port *p)
                unsigned char lsr = serial_in(p, UART_LSR);
                /*
                 * To provide required timeing and allow FIFO transfer,
-                * __stop_tx_rs485 must be called only when both FIFO and
+                * __stop_tx_rs485() must be called only when both FIFO and
                 * shift register are empty. It is for device driver to enable
                 * interrupt on TEMT.
                 */
@@ -1484,9 +1477,10 @@ static inline void __stop_tx(struct uart_8250_port *p)
 
                del_timer(&em485->start_tx_timer);
                em485->active_timer = NULL;
+
+               __stop_tx_rs485(p);
        }
        __do_stop_tx(p);
-       __stop_tx_rs485(p);
 }
 
 static void serial8250_stop_tx(struct uart_port *port)
@@ -2499,8 +2493,6 @@ static unsigned int serial8250_get_baud_rate(struct uart_port *port,
                                             struct ktermios *termios,
                                             struct ktermios *old)
 {
-       unsigned int tolerance = port->uartclk / 100;
-
        /*
         * Ask the core to calculate the divisor for us.
         * Allow 1% tolerance at the upper limit so uart clks marginally
@@ -2509,7 +2501,7 @@ static unsigned int serial8250_get_baud_rate(struct uart_port *port,
         */
        return uart_get_baud_rate(port, termios, old,
                                  port->uartclk / 16 / 0xffff,
-                                 (port->uartclk + tolerance) / 16);
+                                 port->uartclk);
 }
 
 void
@@ -2546,12 +2538,9 @@ serial8250_do_set_termios(struct uart_port *port, struct ktermios *termios,
        /*
         * MCR-based auto flow control.  When AFE is enabled, RTS will be
         * deasserted when the receive FIFO contains more characters than
-        * the trigger, or the MCR RTS bit is cleared.  In the case where
-        * the remote UART is not using CTS auto flow control, we must
-        * have sufficient FIFO entries for the latency of the remote
-        * UART to respond.  IOW, at least 32 bytes of FIFO.
+        * the trigger, or the MCR RTS bit is cleared.
         */
-       if (up->capabilities & UART_CAP_AFE && port->fifosize >= 32) {
+       if (up->capabilities & UART_CAP_AFE) {
                up->mcr &= ~UART_MCR_AFE;
                if (termios->c_cflag & CRTSCTS)
                        up->mcr |= UART_MCR_AFE;
index 7c6f7afca5ddeed7b25fa6272246fc539bf31b04..899834776b36001809f9ec0429b0d1208d48502d 100644 (file)
@@ -120,7 +120,6 @@ config SERIAL_8250_PCI
        tristate "8250/16550 PCI device support" if EXPERT
        depends on SERIAL_8250 && PCI
        default SERIAL_8250
-       select RATIONAL
        help
          This builds standard PCI serial support. You may be able to
          disable this feature if you only need legacy serial support.
@@ -402,6 +401,21 @@ config SERIAL_8250_INGENIC
          If you have a system using an Ingenic SoC and wish to make use of
          its UARTs, say Y to this option. If unsure, say N.
 
+config SERIAL_8250_LPSS
+       tristate "Support for serial ports on Intel LPSS platforms" if EXPERT
+       default SERIAL_8250
+       depends on SERIAL_8250 && PCI
+       depends on X86 || COMPILE_TEST
+       select DW_DMAC_CORE if SERIAL_8250_DMA
+       select DW_DMAC_PCI if (SERIAL_8250_DMA && X86_INTEL_LPSS)
+       select RATIONAL
+       help
+         Selecting this option will enable handling of the extra features
+         present on the UART found on various Intel platforms such as:
+           - Intel Baytrail SoC
+           - Intel Braswell SoC
+           - Intel Quark X1000 SoC
+
 config SERIAL_8250_MID
        tristate "Support for serial ports on Intel MID platforms" if EXPERT
        default SERIAL_8250
index 367d403d28d54b2efda39b4b214a8a3d66171dfc..276c6fb6033795a4f451840fadc4a282c8d3f5dc 100644 (file)
@@ -28,6 +28,7 @@ obj-$(CONFIG_SERIAL_8250_LPC18XX)     += 8250_lpc18xx.o
 obj-$(CONFIG_SERIAL_8250_MT6577)       += 8250_mtk.o
 obj-$(CONFIG_SERIAL_8250_UNIPHIER)     += 8250_uniphier.o
 obj-$(CONFIG_SERIAL_8250_INGENIC)      += 8250_ingenic.o
+obj-$(CONFIG_SERIAL_8250_LPSS)         += 8250_lpss.o
 obj-$(CONFIG_SERIAL_8250_MID)          += 8250_mid.o
 obj-$(CONFIG_SERIAL_8250_MOXA)         += 8250_moxa.o
 obj-$(CONFIG_SERIAL_OF_PLATFORM)       += 8250_of.o
index 32df2a0cb0606a12110f869fdee725057095fcca..e409d7dac7abfd5800a5b9a56d013cb569ca26f1 100644 (file)
@@ -280,7 +280,7 @@ static int altera_jtaguart_verify_port(struct uart_port *port,
 /*
  *     Define the basic serial functions we support.
  */
-static struct uart_ops altera_jtaguart_ops = {
+static const struct uart_ops altera_jtaguart_ops = {
        .tx_empty       = altera_jtaguart_tx_empty,
        .get_mctrl      = altera_jtaguart_get_mctrl,
        .set_mctrl      = altera_jtaguart_set_mctrl,
index 61b607f2488e36761069e0e58a9bd2cf74661100..820a74208696bf57b275542ef810663c6ea175b7 100644 (file)
@@ -404,7 +404,7 @@ static void altera_uart_poll_put_char(struct uart_port *port, unsigned char c)
 /*
  *     Define the basic serial functions we support.
  */
-static struct uart_ops altera_uart_ops = {
+static const struct uart_ops altera_uart_ops = {
        .tx_empty       = altera_uart_tx_empty,
        .get_mctrl      = altera_uart_get_mctrl,
        .set_mctrl      = altera_uart_set_mctrl,
index 8a9e213387a79fcc335caad27520a68edf03f446..0b78b04e895efd1a366eb66c518a01c276605427 100644 (file)
@@ -93,6 +93,10 @@ static u16 pl011_std_offsets[REG_ARRAY_SIZE] = {
 struct vendor_data {
        const u16               *reg_offset;
        unsigned int            ifls;
+       unsigned int            fr_busy;
+       unsigned int            fr_dsr;
+       unsigned int            fr_cts;
+       unsigned int            fr_ri;
        bool                    access_32b;
        bool                    oversampling;
        bool                    dma_threshold;
@@ -111,6 +115,10 @@ static unsigned int get_fifosize_arm(struct amba_device *dev)
 static struct vendor_data vendor_arm = {
        .reg_offset             = pl011_std_offsets,
        .ifls                   = UART011_IFLS_RX4_8|UART011_IFLS_TX4_8,
+       .fr_busy                = UART01x_FR_BUSY,
+       .fr_dsr                 = UART01x_FR_DSR,
+       .fr_cts                 = UART01x_FR_CTS,
+       .fr_ri                  = UART011_FR_RI,
        .oversampling           = false,
        .dma_threshold          = false,
        .cts_event_workaround   = false,
@@ -121,6 +129,10 @@ static struct vendor_data vendor_arm = {
 
 static struct vendor_data vendor_sbsa = {
        .reg_offset             = pl011_std_offsets,
+       .fr_busy                = UART01x_FR_BUSY,
+       .fr_dsr                 = UART01x_FR_DSR,
+       .fr_cts                 = UART01x_FR_CTS,
+       .fr_ri                  = UART011_FR_RI,
        .access_32b             = true,
        .oversampling           = false,
        .dma_threshold          = false,
@@ -164,6 +176,10 @@ static unsigned int get_fifosize_st(struct amba_device *dev)
 static struct vendor_data vendor_st = {
        .reg_offset             = pl011_st_offsets,
        .ifls                   = UART011_IFLS_RX_HALF|UART011_IFLS_TX_HALF,
+       .fr_busy                = UART01x_FR_BUSY,
+       .fr_dsr                 = UART01x_FR_DSR,
+       .fr_cts                 = UART01x_FR_CTS,
+       .fr_ri                  = UART011_FR_RI,
        .oversampling           = true,
        .dma_threshold          = true,
        .cts_event_workaround   = true,
@@ -188,11 +204,20 @@ static const u16 pl011_zte_offsets[REG_ARRAY_SIZE] = {
        [REG_DMACR] = ZX_UART011_DMACR,
 };
 
-static struct vendor_data vendor_zte __maybe_unused = {
+static unsigned int get_fifosize_zte(struct amba_device *dev)
+{
+       return 16;
+}
+
+static struct vendor_data vendor_zte = {
        .reg_offset             = pl011_zte_offsets,
        .access_32b             = true,
        .ifls                   = UART011_IFLS_RX4_8|UART011_IFLS_TX4_8,
-       .get_fifosize           = get_fifosize_arm,
+       .fr_busy                = ZX_UART01x_FR_BUSY,
+       .fr_dsr                 = ZX_UART01x_FR_DSR,
+       .fr_cts                 = ZX_UART01x_FR_CTS,
+       .fr_ri                  = ZX_UART011_FR_RI,
+       .get_fifosize           = get_fifosize_zte,
 };
 
 /* Deals with DMA transactions */
@@ -1167,7 +1192,7 @@ static void pl011_dma_shutdown(struct uart_amba_port *uap)
                return;
 
        /* Disable RX and TX DMA */
-       while (pl011_read(uap, REG_FR) & UART01x_FR_BUSY)
+       while (pl011_read(uap, REG_FR) & uap->vendor->fr_busy)
                cpu_relax();
 
        spin_lock_irq(&uap->port.lock);
@@ -1416,11 +1441,12 @@ static void pl011_modem_status(struct uart_amba_port *uap)
        if (delta & UART01x_FR_DCD)
                uart_handle_dcd_change(&uap->port, status & UART01x_FR_DCD);
 
-       if (delta & UART01x_FR_DSR)
+       if (delta & uap->vendor->fr_dsr)
                uap->port.icount.dsr++;
 
-       if (delta & UART01x_FR_CTS)
-               uart_handle_cts_change(&uap->port, status & UART01x_FR_CTS);
+       if (delta & uap->vendor->fr_cts)
+               uart_handle_cts_change(&uap->port,
+                                      status & uap->vendor->fr_cts);
 
        wake_up_interruptible(&uap->port.state->port.delta_msr_wait);
 }
@@ -1493,7 +1519,8 @@ static unsigned int pl011_tx_empty(struct uart_port *port)
        struct uart_amba_port *uap =
            container_of(port, struct uart_amba_port, port);
        unsigned int status = pl011_read(uap, REG_FR);
-       return status & (UART01x_FR_BUSY|UART01x_FR_TXFF) ? 0 : TIOCSER_TEMT;
+       return status & (uap->vendor->fr_busy | UART01x_FR_TXFF) ?
+                                                       0 : TIOCSER_TEMT;
 }
 
 static unsigned int pl011_get_mctrl(struct uart_port *port)
@@ -1508,9 +1535,9 @@ static unsigned int pl011_get_mctrl(struct uart_port *port)
                result |= tiocmbit
 
        TIOCMBIT(UART01x_FR_DCD, TIOCM_CAR);
-       TIOCMBIT(UART01x_FR_DSR, TIOCM_DSR);
-       TIOCMBIT(UART01x_FR_CTS, TIOCM_CTS);
-       TIOCMBIT(UART011_FR_RI, TIOCM_RNG);
+       TIOCMBIT(uap->vendor->fr_dsr, TIOCM_DSR);
+       TIOCMBIT(uap->vendor->fr_cts, TIOCM_CTS);
+       TIOCMBIT(uap->vendor->fr_ri, TIOCM_RNG);
 #undef TIOCMBIT
        return result;
 }
@@ -2191,7 +2218,7 @@ pl011_console_write(struct console *co, const char *s, unsigned int count)
         *      Finally, wait for transmitter to become empty
         *      and restore the TCR
         */
-       while (pl011_read(uap, REG_FR) & UART01x_FR_BUSY)
+       while (pl011_read(uap, REG_FR) & uap->vendor->fr_busy)
                cpu_relax();
        if (!uap->vendor->always_enabled)
                pl011_write(old_cr, uap, REG_CR);
@@ -2303,13 +2330,16 @@ static struct console amba_console = {
 
 static void pl011_putc(struct uart_port *port, int c)
 {
+       struct uart_amba_port *uap =
+               container_of(port, struct uart_amba_port, port);
+
        while (readl(port->membase + UART01x_FR) & UART01x_FR_TXFF)
                cpu_relax();
        if (port->iotype == UPIO_MEM32)
                writel(c, port->membase + UART01x_DR);
        else
                writeb(c, port->membase + UART01x_DR);
-       while (readl(port->membase + UART01x_FR) & UART01x_FR_BUSY)
+       while (readl(port->membase + UART01x_FR) & uap->vendor->fr_busy)
                cpu_relax();
 }
 
@@ -2622,6 +2652,11 @@ static struct amba_id pl011_ids[] = {
                .mask   = 0x00ffffff,
                .data   = &vendor_st,
        },
+       {
+               .id     = AMBA_LINUX_ID(0x00, 0x1, 0xffe),
+               .mask   = 0x00ffffff,
+               .data   = &vendor_zte,
+       },
        { 0, 0 },
 };
 
index 3a1de5c87cb430111bddcb8733884667528e1366..5ac06fcaa9c606408496215c6a782e9e25c03916 100644 (file)
@@ -464,7 +464,7 @@ static int arc_serial_poll_getchar(struct uart_port *port)
 }
 #endif
 
-static struct uart_ops arc_serial_pops = {
+static const struct uart_ops arc_serial_pops = {
        .tx_empty       = arc_serial_tx_empty,
        .set_mctrl      = arc_serial_set_mctrl,
        .get_mctrl      = arc_serial_get_mctrl,
index 2eaa18ddef6171640729bf8a770363331f5edaa3..72064b5e4f36d9b7fe279b13f32f613b7c13861d 100644 (file)
@@ -166,6 +166,7 @@ struct atmel_uart_port {
        u32                     rts_low;
        bool                    ms_irq_enabled;
        u32                     rtor;   /* address of receiver timeout register if it exists */
+       bool                    has_frac_baudrate;
        bool                    has_hw_timer;
        struct timer_list       uart_timer;
 
@@ -1634,8 +1635,8 @@ static void atmel_init_property(struct atmel_uart_port *atmel_port,
 
        if (np) {
                /* DMA/PDC usage specification */
-               if (of_get_property(np, "atmel,use-dma-rx", NULL)) {
-                       if (of_get_property(np, "dmas", NULL)) {
+               if (of_property_read_bool(np, "atmel,use-dma-rx")) {
+                       if (of_property_read_bool(np, "dmas")) {
                                atmel_port->use_dma_rx  = true;
                                atmel_port->use_pdc_rx  = false;
                        } else {
@@ -1647,8 +1648,8 @@ static void atmel_init_property(struct atmel_uart_port *atmel_port,
                        atmel_port->use_pdc_rx  = false;
                }
 
-               if (of_get_property(np, "atmel,use-dma-tx", NULL)) {
-                       if (of_get_property(np, "dmas", NULL)) {
+               if (of_property_read_bool(np, "atmel,use-dma-tx")) {
+                       if (of_property_read_bool(np, "dmas")) {
                                atmel_port->use_dma_tx  = true;
                                atmel_port->use_pdc_tx  = false;
                        } else {
@@ -1745,6 +1746,11 @@ static void atmel_get_ip_name(struct uart_port *port)
        dbgu_uart = 0x44424755; /* DBGU */
        new_uart = 0x55415254;  /* UART */
 
+       /*
+        * Only USART devices from at91sam9260 SOC implement fractional
+        * baudrate.
+        */
+       atmel_port->has_frac_baudrate = false;
        atmel_port->has_hw_timer = false;
 
        if (name == new_uart) {
@@ -1753,6 +1759,7 @@ static void atmel_get_ip_name(struct uart_port *port)
                atmel_port->rtor = ATMEL_UA_RTOR;
        } else if (name == usart) {
                dev_dbg(port->dev, "Usart\n");
+               atmel_port->has_frac_baudrate = true;
                atmel_port->has_hw_timer = true;
                atmel_port->rtor = ATMEL_US_RTOR;
        } else if (name == dbgu_uart) {
@@ -1764,6 +1771,7 @@ static void atmel_get_ip_name(struct uart_port *port)
                case 0x302:
                case 0x10213:
                        dev_dbg(port->dev, "This version is usart\n");
+                       atmel_port->has_frac_baudrate = true;
                        atmel_port->has_hw_timer = true;
                        atmel_port->rtor = ATMEL_US_RTOR;
                        break;
@@ -2025,8 +2033,9 @@ static void atmel_serial_pm(struct uart_port *port, unsigned int state,
 static void atmel_set_termios(struct uart_port *port, struct ktermios *termios,
                              struct ktermios *old)
 {
+       struct atmel_uart_port *atmel_port = to_atmel_uart_port(port);
        unsigned long flags;
-       unsigned int old_mode, mode, imr, quot, baud;
+       unsigned int old_mode, mode, imr, quot, baud, div, cd, fp = 0;
 
        /* save the current mode register */
        mode = old_mode = atmel_uart_readl(port, ATMEL_US_MR);
@@ -2036,12 +2045,6 @@ static void atmel_set_termios(struct uart_port *port, struct ktermios *termios,
                  ATMEL_US_PAR | ATMEL_US_USMODE);
 
        baud = uart_get_baud_rate(port, termios, old, 0, port->uartclk / 16);
-       quot = uart_get_divisor(port, baud);
-
-       if (quot > 65535) {     /* BRGR is 16-bit, so switch to slower clock */
-               quot /= 8;
-               mode |= ATMEL_US_USCLKS_MCK_DIV8;
-       }
 
        /* byte size */
        switch (termios->c_cflag & CSIZE) {
@@ -2160,7 +2163,29 @@ static void atmel_set_termios(struct uart_port *port, struct ktermios *termios,
                atmel_uart_writel(port, ATMEL_US_CR, rts_state);
        }
 
-       /* set the baud rate */
+       /*
+        * Set the baud rate:
+        * Fractional baudrate allows to setup output frequency more
+        * accurately. This feature is enabled only when using normal mode.
+        * baudrate = selected clock / (8 * (2 - OVER) * (CD + FP / 8))
+        * Currently, OVER is always set to 0 so we get
+        * baudrate = selected clock (16 * (CD + FP / 8))
+        */
+       if (atmel_port->has_frac_baudrate &&
+           (mode & ATMEL_US_USMODE) == ATMEL_US_USMODE_NORMAL) {
+               div = DIV_ROUND_CLOSEST(port->uartclk, baud);
+               cd = div / 16;
+               fp = DIV_ROUND_CLOSEST(div % 16, 2);
+       } else {
+               cd = uart_get_divisor(port, baud);
+       }
+
+       if (cd > 65535) {       /* BRGR is 16-bit, so switch to slower clock */
+               cd /= 8;
+               mode |= ATMEL_US_USCLKS_MCK_DIV8;
+       }
+       quot = cd | fp << ATMEL_US_FP_OFFSET;
+
        atmel_uart_writel(port, ATMEL_US_BRGR, quot);
        atmel_uart_writel(port, ATMEL_US_CR, ATMEL_US_RSTSTA | ATMEL_US_RSTRX);
        atmel_uart_writel(port, ATMEL_US_CR, ATMEL_US_TXEN | ATMEL_US_RXEN);
@@ -2292,7 +2317,7 @@ static void atmel_poll_put_char(struct uart_port *port, unsigned char ch)
 }
 #endif
 
-static struct uart_ops atmel_pops = {
+static const struct uart_ops atmel_pops = {
        .tx_empty       = atmel_tx_empty,
        .set_mctrl      = atmel_set_mctrl,
        .get_mctrl      = atmel_get_mctrl,
index 5108fab953aadf665dfb8dc6d8efab9d69781556..583c9a0c7eccd439b3c457c6c9c767976c49deda 100644 (file)
@@ -631,7 +631,7 @@ static int bcm_uart_verify_port(struct uart_port *port,
 }
 
 /* serial core callbacks */
-static struct uart_ops bcm_uart_ops = {
+static const struct uart_ops bcm_uart_ops = {
        .tx_empty       = bcm_uart_tx_empty,
        .get_mctrl      = bcm_uart_get_mctrl,
        .set_mctrl      = bcm_uart_set_mctrl,
index 383db10fbb499a058e62284cf8b3f4483415b875..6bbeb699777cea4a7ef4cfecaf51f6d627656b82 100644 (file)
@@ -53,7 +53,8 @@ static void smh_write(struct console *con, const char *s, unsigned n)
        uart_console_write(&dev->port, s, n, smh_putc);
 }
 
-int __init early_smh_setup(struct earlycon_device *device, const char *opt)
+static int
+__init early_smh_setup(struct earlycon_device *device, const char *opt)
 {
        device->con->write = smh_write;
        return 0;
index 067783f0523c5a8a69a63e1333a7d010c1d203f6..3940280afa9c84e3a9fa551763d0e477d418adc1 100644 (file)
@@ -38,7 +38,7 @@ static struct earlycon_device early_console_dev = {
        .con = &early_con,
 };
 
-static void __iomem * __init earlycon_map(unsigned long paddr, size_t size)
+static void __iomem * __init earlycon_map(resource_size_t paddr, size_t size)
 {
        void __iomem *base;
 #ifdef CONFIG_FIX_EARLYCON_MEM
@@ -49,8 +49,7 @@ static void __iomem * __init earlycon_map(unsigned long paddr, size_t size)
        base = ioremap(paddr, size);
 #endif
        if (!base)
-               pr_err("%s: Couldn't map 0x%llx\n", __func__,
-                      (unsigned long long)paddr);
+               pr_err("%s: Couldn't map %pa\n", __func__, &paddr);
 
        return base;
 }
@@ -92,7 +91,7 @@ static int __init parse_options(struct earlycon_device *device, char *options)
 {
        struct uart_port *port = &device->port;
        int length;
-       unsigned long addr;
+       resource_size_t addr;
 
        if (uart_parse_earlycon(options, &port->iotype, &addr, &options))
                return -EINVAL;
index 7f95f782a48561e5ef466230c1a54dc8cf17455d..b21f3e54171439d3204a9f7f6216ea1a3815ad79 100644 (file)
 #define UARTWATER_TXWATER_OFF  0
 #define UARTWATER_RXWATER_OFF  16
 
-#define FSL_UART_RX_DMA_BUFFER_SIZE    64
+/* Rx DMA timeout in ms, which is used to calculate Rx ring buffer size */
+#define DMA_RX_TIMEOUT         (10)
 
 #define DRIVER_NAME    "fsl-lpuart"
 #define DEV_NAME       "ttyLP"
@@ -243,18 +244,18 @@ struct lpuart_port {
        struct dma_chan         *dma_rx_chan;
        struct dma_async_tx_descriptor  *dma_tx_desc;
        struct dma_async_tx_descriptor  *dma_rx_desc;
-       dma_addr_t              dma_tx_buf_bus;
-       dma_addr_t              dma_rx_buf_bus;
        dma_cookie_t            dma_tx_cookie;
        dma_cookie_t            dma_rx_cookie;
-       unsigned char           *dma_tx_buf_virt;
-       unsigned char           *dma_rx_buf_virt;
        unsigned int            dma_tx_bytes;
        unsigned int            dma_rx_bytes;
-       int                     dma_tx_in_progress;
-       int                     dma_rx_in_progress;
+       bool                    dma_tx_in_progress;
        unsigned int            dma_rx_timeout;
        struct timer_list       lpuart_timer;
+       struct scatterlist      rx_sgl, tx_sgl[2];
+       struct circ_buf         rx_ring;
+       int                     rx_dma_rng_buf_len;
+       unsigned int            dma_tx_nents;
+       wait_queue_head_t       dma_wait;
 };
 
 static const struct of_device_id lpuart_dt_ids[] = {
@@ -270,7 +271,6 @@ MODULE_DEVICE_TABLE(of, lpuart_dt_ids);
 
 /* Forward declare this for the dma callbacks*/
 static void lpuart_dma_tx_complete(void *arg);
-static void lpuart_dma_rx_complete(void *arg);
 
 static u32 lpuart32_read(void __iomem *addr)
 {
@@ -316,141 +316,103 @@ static void lpuart32_stop_rx(struct uart_port *port)
        lpuart32_write(temp & ~UARTCTRL_RE, port->membase + UARTCTRL);
 }
 
-static void lpuart_copy_rx_to_tty(struct lpuart_port *sport,
-               struct tty_port *tty, int count)
+static void lpuart_dma_tx(struct lpuart_port *sport)
 {
-       int copied;
-
-       sport->port.icount.rx += count;
+       struct circ_buf *xmit = &sport->port.state->xmit;
+       struct scatterlist *sgl = sport->tx_sgl;
+       struct device *dev = sport->port.dev;
+       int ret;
 
-       if (!tty) {
-               dev_err(sport->port.dev, "No tty port\n");
+       if (sport->dma_tx_in_progress)
                return;
-       }
 
-       dma_sync_single_for_cpu(sport->port.dev, sport->dma_rx_buf_bus,
-                       FSL_UART_RX_DMA_BUFFER_SIZE, DMA_FROM_DEVICE);
-       copied = tty_insert_flip_string(tty,
-                       ((unsigned char *)(sport->dma_rx_buf_virt)), count);
+       sport->dma_tx_bytes = uart_circ_chars_pending(xmit);
 
-       if (copied != count) {
-               WARN_ON(1);
-               dev_err(sport->port.dev, "RxData copy to tty layer failed\n");
+       if (xmit->tail < xmit->head) {
+               sport->dma_tx_nents = 1;
+               sg_init_one(sgl, xmit->buf + xmit->tail, sport->dma_tx_bytes);
+       } else {
+               sport->dma_tx_nents = 2;
+               sg_init_table(sgl, 2);
+               sg_set_buf(sgl, xmit->buf + xmit->tail,
+                               UART_XMIT_SIZE - xmit->tail);
+               sg_set_buf(sgl + 1, xmit->buf, xmit->head);
        }
 
-       dma_sync_single_for_device(sport->port.dev, sport->dma_rx_buf_bus,
-                       FSL_UART_RX_DMA_BUFFER_SIZE, DMA_TO_DEVICE);
-}
-
-static void lpuart_pio_tx(struct lpuart_port *sport)
-{
-       struct circ_buf *xmit = &sport->port.state->xmit;
-       unsigned long flags;
-
-       spin_lock_irqsave(&sport->port.lock, flags);
-
-       while (!uart_circ_empty(xmit) &&
-               readb(sport->port.membase + UARTTCFIFO) < sport->txfifo_size) {
-               writeb(xmit->buf[xmit->tail], sport->port.membase + UARTDR);
-               xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE - 1);
-               sport->port.icount.tx++;
+       ret = dma_map_sg(dev, sgl, sport->dma_tx_nents, DMA_TO_DEVICE);
+       if (!ret) {
+               dev_err(dev, "DMA mapping error for TX.\n");
+               return;
        }
 
-       if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS)
-               uart_write_wakeup(&sport->port);
-
-       if (uart_circ_empty(xmit))
-               writeb(readb(sport->port.membase + UARTCR5) | UARTCR5_TDMAS,
-                       sport->port.membase + UARTCR5);
-
-       spin_unlock_irqrestore(&sport->port.lock, flags);
-}
-
-static int lpuart_dma_tx(struct lpuart_port *sport, unsigned long count)
-{
-       struct circ_buf *xmit = &sport->port.state->xmit;
-       dma_addr_t tx_bus_addr;
-
-       dma_sync_single_for_device(sport->port.dev, sport->dma_tx_buf_bus,
-                               UART_XMIT_SIZE, DMA_TO_DEVICE);
-       sport->dma_tx_bytes = count & ~(sport->txfifo_size - 1);
-       tx_bus_addr = sport->dma_tx_buf_bus + xmit->tail;
-       sport->dma_tx_desc = dmaengine_prep_slave_single(sport->dma_tx_chan,
-                                       tx_bus_addr, sport->dma_tx_bytes,
+       sport->dma_tx_desc = dmaengine_prep_slave_sg(sport->dma_tx_chan, sgl,
+                                       sport->dma_tx_nents,
                                        DMA_MEM_TO_DEV, DMA_PREP_INTERRUPT);
-
        if (!sport->dma_tx_desc) {
-               dev_err(sport->port.dev, "Not able to get desc for tx\n");
-               return -EIO;
+               dma_unmap_sg(dev, sgl, sport->dma_tx_nents, DMA_TO_DEVICE);
+               dev_err(dev, "Cannot prepare TX slave DMA!\n");
+               return;
        }
 
        sport->dma_tx_desc->callback = lpuart_dma_tx_complete;
        sport->dma_tx_desc->callback_param = sport;
-       sport->dma_tx_in_progress = 1;
+       sport->dma_tx_in_progress = true;
        sport->dma_tx_cookie = dmaengine_submit(sport->dma_tx_desc);
        dma_async_issue_pending(sport->dma_tx_chan);
 
-       return 0;
-}
-
-static void lpuart_prepare_tx(struct lpuart_port *sport)
-{
-       struct circ_buf *xmit = &sport->port.state->xmit;
-       unsigned long count =  CIRC_CNT_TO_END(xmit->head,
-                                       xmit->tail, UART_XMIT_SIZE);
-
-       if (!count)
-               return;
-
-       if (count < sport->txfifo_size)
-               writeb(readb(sport->port.membase + UARTCR5) & ~UARTCR5_TDMAS,
-                               sport->port.membase + UARTCR5);
-       else {
-               writeb(readb(sport->port.membase + UARTCR5) | UARTCR5_TDMAS,
-                               sport->port.membase + UARTCR5);
-               lpuart_dma_tx(sport, count);
-       }
 }
 
 static void lpuart_dma_tx_complete(void *arg)
 {
        struct lpuart_port *sport = arg;
+       struct scatterlist *sgl = &sport->tx_sgl[0];
        struct circ_buf *xmit = &sport->port.state->xmit;
        unsigned long flags;
 
-       async_tx_ack(sport->dma_tx_desc);
-
        spin_lock_irqsave(&sport->port.lock, flags);
 
+       dma_unmap_sg(sport->port.dev, sgl, sport->dma_tx_nents, DMA_TO_DEVICE);
+
        xmit->tail = (xmit->tail + sport->dma_tx_bytes) & (UART_XMIT_SIZE - 1);
-       sport->dma_tx_in_progress = 0;
+
+       sport->port.icount.tx += sport->dma_tx_bytes;
+       sport->dma_tx_in_progress = false;
+       spin_unlock_irqrestore(&sport->port.lock, flags);
 
        if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS)
                uart_write_wakeup(&sport->port);
 
-       lpuart_prepare_tx(sport);
+       if (waitqueue_active(&sport->dma_wait)) {
+               wake_up(&sport->dma_wait);
+               return;
+       }
+
+       spin_lock_irqsave(&sport->port.lock, flags);
+
+       if (!uart_circ_empty(xmit) && !uart_tx_stopped(&sport->port))
+               lpuart_dma_tx(sport);
 
        spin_unlock_irqrestore(&sport->port.lock, flags);
 }
 
-static int lpuart_dma_rx(struct lpuart_port *sport)
+static int lpuart_dma_tx_request(struct uart_port *port)
 {
-       dma_sync_single_for_device(sport->port.dev, sport->dma_rx_buf_bus,
-                       FSL_UART_RX_DMA_BUFFER_SIZE, DMA_TO_DEVICE);
-       sport->dma_rx_desc = dmaengine_prep_slave_single(sport->dma_rx_chan,
-                       sport->dma_rx_buf_bus, FSL_UART_RX_DMA_BUFFER_SIZE,
-                       DMA_DEV_TO_MEM, DMA_PREP_INTERRUPT);
+       struct lpuart_port *sport = container_of(port,
+                                       struct lpuart_port, port);
+       struct dma_slave_config dma_tx_sconfig = {};
+       int ret;
 
-       if (!sport->dma_rx_desc) {
-               dev_err(sport->port.dev, "Not able to get desc for rx\n");
-               return -EIO;
-       }
+       dma_tx_sconfig.dst_addr = sport->port.mapbase + UARTDR;
+       dma_tx_sconfig.dst_addr_width = DMA_SLAVE_BUSWIDTH_1_BYTE;
+       dma_tx_sconfig.dst_maxburst = 1;
+       dma_tx_sconfig.direction = DMA_MEM_TO_DEV;
+       ret = dmaengine_slave_config(sport->dma_tx_chan, &dma_tx_sconfig);
 
-       sport->dma_rx_desc->callback = lpuart_dma_rx_complete;
-       sport->dma_rx_desc->callback_param = sport;
-       sport->dma_rx_in_progress = 1;
-       sport->dma_rx_cookie = dmaengine_submit(sport->dma_rx_desc);
-       dma_async_issue_pending(sport->dma_rx_chan);
+       if (ret) {
+               dev_err(sport->port.dev,
+                               "DMA slave config failed, err = %d\n", ret);
+               return ret;
+       }
 
        return 0;
 }
@@ -458,75 +420,17 @@ static int lpuart_dma_rx(struct lpuart_port *sport)
 static void lpuart_flush_buffer(struct uart_port *port)
 {
        struct lpuart_port *sport = container_of(port, struct lpuart_port, port);
+
        if (sport->lpuart_dma_tx_use) {
+               if (sport->dma_tx_in_progress) {
+                       dma_unmap_sg(sport->port.dev, &sport->tx_sgl[0],
+                               sport->dma_tx_nents, DMA_TO_DEVICE);
+                       sport->dma_tx_in_progress = false;
+               }
                dmaengine_terminate_all(sport->dma_tx_chan);
-               sport->dma_tx_in_progress = 0;
        }
 }
 
-static void lpuart_dma_rx_complete(void *arg)
-{
-       struct lpuart_port *sport = arg;
-       struct tty_port *port = &sport->port.state->port;
-       unsigned long flags;
-
-       async_tx_ack(sport->dma_rx_desc);
-       mod_timer(&sport->lpuart_timer, jiffies + sport->dma_rx_timeout);
-
-       spin_lock_irqsave(&sport->port.lock, flags);
-
-       sport->dma_rx_in_progress = 0;
-       lpuart_copy_rx_to_tty(sport, port, FSL_UART_RX_DMA_BUFFER_SIZE);
-       tty_flip_buffer_push(port);
-       lpuart_dma_rx(sport);
-
-       spin_unlock_irqrestore(&sport->port.lock, flags);
-}
-
-static void lpuart_timer_func(unsigned long data)
-{
-       struct lpuart_port *sport = (struct lpuart_port *)data;
-       struct tty_port *port = &sport->port.state->port;
-       struct dma_tx_state state;
-       unsigned long flags;
-       unsigned char temp;
-       int count;
-
-       del_timer(&sport->lpuart_timer);
-       dmaengine_pause(sport->dma_rx_chan);
-       dmaengine_tx_status(sport->dma_rx_chan, sport->dma_rx_cookie, &state);
-       dmaengine_terminate_all(sport->dma_rx_chan);
-       count = FSL_UART_RX_DMA_BUFFER_SIZE - state.residue;
-       async_tx_ack(sport->dma_rx_desc);
-
-       spin_lock_irqsave(&sport->port.lock, flags);
-
-       sport->dma_rx_in_progress = 0;
-       lpuart_copy_rx_to_tty(sport, port, count);
-       tty_flip_buffer_push(port);
-       temp = readb(sport->port.membase + UARTCR5);
-       writeb(temp & ~UARTCR5_RDMAS, sport->port.membase + UARTCR5);
-
-       spin_unlock_irqrestore(&sport->port.lock, flags);
-}
-
-static inline void lpuart_prepare_rx(struct lpuart_port *sport)
-{
-       unsigned long flags;
-       unsigned char temp;
-
-       spin_lock_irqsave(&sport->port.lock, flags);
-
-       sport->lpuart_timer.expires = jiffies + sport->dma_rx_timeout;
-       add_timer(&sport->lpuart_timer);
-
-       lpuart_dma_rx(sport);
-       temp = readb(sport->port.membase + UARTCR5);
-       writeb(temp | UARTCR5_RDMAS, sport->port.membase + UARTCR5);
-
-       spin_unlock_irqrestore(&sport->port.lock, flags);
-}
-
 static inline void lpuart_transmit_buffer(struct lpuart_port *sport)
 {
        struct circ_buf *xmit = &sport->port.state->xmit;
@@ -580,8 +484,8 @@ static void lpuart_start_tx(struct uart_port *port)
        writeb(temp | UARTCR2_TIE, port->membase + UARTCR2);
 
        if (sport->lpuart_dma_tx_use) {
-               if (!uart_circ_empty(xmit) && !sport->dma_tx_in_progress)
-                       lpuart_prepare_tx(sport);
+               if (!uart_circ_empty(xmit) && !uart_tx_stopped(port))
+                       lpuart_dma_tx(sport);
        } else {
                if (readb(port->membase + UARTSR1) & UARTSR1_TDRE)
                        lpuart_transmit_buffer(sport);
@@ -600,6 +504,29 @@ static void lpuart32_start_tx(struct uart_port *port)
                lpuart32_transmit_buffer(sport);
 }
 
+/* return TIOCSER_TEMT when transmitter is not busy */
+static unsigned int lpuart_tx_empty(struct uart_port *port)
+{
+       struct lpuart_port *sport = container_of(port,
+                       struct lpuart_port, port);
+       unsigned char sr1 = readb(port->membase + UARTSR1);
+       unsigned char sfifo = readb(port->membase + UARTSFIFO);
+
+       if (sport->dma_tx_in_progress)
+               return 0;
+
+       if (sr1 & UARTSR1_TC && sfifo & UARTSFIFO_TXEMPT)
+               return TIOCSER_TEMT;
+
+       return 0;
+}
+
+static unsigned int lpuart32_tx_empty(struct uart_port *port)
+{
+       return (lpuart32_read(port->membase + UARTSTAT) & UARTSTAT_TC) ?
+               TIOCSER_TEMT : 0;
+}
+
 static irqreturn_t lpuart_txint(int irq, void *dev_id)
 {
        struct lpuart_port *sport = dev_id;
@@ -766,23 +693,15 @@ out:
 static irqreturn_t lpuart_int(int irq, void *dev_id)
 {
        struct lpuart_port *sport = dev_id;
-       unsigned char sts, crdma;
+       unsigned char sts;
 
        sts = readb(sport->port.membase + UARTSR1);
-       crdma = readb(sport->port.membase + UARTCR5);
 
-       if (sts & UARTSR1_RDRF && !(crdma & UARTCR5_RDMAS)) {
-               if (sport->lpuart_dma_rx_use)
-                       lpuart_prepare_rx(sport);
-               else
-                       lpuart_rxint(irq, dev_id);
-       }
-       if (sts & UARTSR1_TDRE && !(crdma & UARTCR5_TDMAS)) {
-               if (sport->lpuart_dma_tx_use)
-                       lpuart_pio_tx(sport);
-               else
-                       lpuart_txint(irq, dev_id);
-       }
+       if (sts & UARTSR1_RDRF)
+               lpuart_rxint(irq, dev_id);
+
+       if (sts & UARTSR1_TDRE)
+               lpuart_txint(irq, dev_id);
 
        return IRQ_HANDLED;
 }
@@ -807,17 +726,241 @@ static irqreturn_t lpuart32_int(int irq, void *dev_id)
        return IRQ_HANDLED;
 }
 
-/* return TIOCSER_TEMT when transmitter is not busy */
-static unsigned int lpuart_tx_empty(struct uart_port *port)
+static void lpuart_copy_rx_to_tty(struct lpuart_port *sport)
 {
-       return (readb(port->membase + UARTSR1) & UARTSR1_TC) ?
-               TIOCSER_TEMT : 0;
+       struct tty_port *port = &sport->port.state->port;
+       struct dma_tx_state state;
+       enum dma_status dmastat;
+       struct circ_buf *ring = &sport->rx_ring;
+       unsigned long flags;
+       int count = 0;
+       unsigned char sr;
+
+       sr = readb(sport->port.membase + UARTSR1);
+
+       if (sr & (UARTSR1_PE | UARTSR1_FE)) {
+               /* Read DR to clear the error flags */
+               readb(sport->port.membase + UARTDR);
+
+               if (sr & UARTSR1_PE)
+                   sport->port.icount.parity++;
+               else if (sr & UARTSR1_FE)
+                   sport->port.icount.frame++;
+       }
+
+       async_tx_ack(sport->dma_rx_desc);
+
+       spin_lock_irqsave(&sport->port.lock, flags);
+
+       dmastat = dmaengine_tx_status(sport->dma_rx_chan,
+                               sport->dma_rx_cookie,
+                               &state);
+
+       if (dmastat == DMA_ERROR) {
+               dev_err(sport->port.dev, "Rx DMA transfer failed!\n");
+               spin_unlock_irqrestore(&sport->port.lock, flags);
+               return;
+       }
+
+       /* CPU claims ownership of RX DMA buffer */
+       dma_sync_sg_for_cpu(sport->port.dev, &sport->rx_sgl, 1, DMA_FROM_DEVICE);
+
+       /*
+        * ring->head points to the end of data already written by the DMA.
+        * ring->tail points to the beginning of data to be read by the
+        * framework.
+        * The current transfer size should not be larger than the dma buffer
+        * length.
+        */
+       ring->head = sport->rx_sgl.length - state.residue;
+       BUG_ON(ring->head > sport->rx_sgl.length);
+       /*
+        * At this point ring->head may point to the first byte right after the
+        * last byte of the dma buffer:
+        * 0 <= ring->head <= sport->rx_sgl.length
+        *
+        * However ring->tail must always points inside the dma buffer:
+        * 0 <= ring->tail <= sport->rx_sgl.length - 1
+        *
+        * Since we use a ring buffer, we have to handle the case
+        * where head is lower than tail. In such a case, we first read from
+        * tail to the end of the buffer then reset tail.
+        */
+       if (ring->head < ring->tail) {
+               count = sport->rx_sgl.length - ring->tail;
+
+               tty_insert_flip_string(port, ring->buf + ring->tail, count);
+               ring->tail = 0;
+               sport->port.icount.rx += count;
+       }
+
+       /* Finally we read data from tail to head */
+       if (ring->tail < ring->head) {
+               count = ring->head - ring->tail;
+               tty_insert_flip_string(port, ring->buf + ring->tail, count);
+               /* Wrap ring->head if needed */
+               if (ring->head >= sport->rx_sgl.length)
+                       ring->head = 0;
+               ring->tail = ring->head;
+               sport->port.icount.rx += count;
+       }
+
+       dma_sync_sg_for_device(sport->port.dev, &sport->rx_sgl, 1,
+                              DMA_FROM_DEVICE);
+
+       spin_unlock_irqrestore(&sport->port.lock, flags);
+
+       tty_flip_buffer_push(port);
+       mod_timer(&sport->lpuart_timer, jiffies + sport->dma_rx_timeout);
 }
 
-static unsigned int lpuart32_tx_empty(struct uart_port *port)
+static void lpuart_dma_rx_complete(void *arg)
 {
-       return (lpuart32_read(port->membase + UARTSTAT) & UARTSTAT_TC) ?
-               TIOCSER_TEMT : 0;
+       struct lpuart_port *sport = arg;
+
+       lpuart_copy_rx_to_tty(sport);
+}
+
+static void lpuart_timer_func(unsigned long data)
+{
+       struct lpuart_port *sport = (struct lpuart_port *)data;
+
+       lpuart_copy_rx_to_tty(sport);
+}
+
+static inline int lpuart_start_rx_dma(struct lpuart_port *sport)
+{
+       struct dma_slave_config dma_rx_sconfig = {};
+       struct circ_buf *ring = &sport->rx_ring;
+       int ret, nent;
+       int bits, baud;
+       struct tty_struct *tty = tty_port_tty_get(&sport->port.state->port);
+       struct ktermios *termios = &tty->termios;
+
+       baud = tty_get_baud_rate(tty);
+
+       bits = (termios->c_cflag & CSIZE) == CS7 ? 9 : 10;
+       if (termios->c_cflag & PARENB)
+               bits++;
+
+       /*
+        * Calculate length of one DMA buffer size to keep latency below
+        * 10ms at any baud rate.
+        */
+       sport->rx_dma_rng_buf_len = (DMA_RX_TIMEOUT * baud /  bits / 1000) * 2;
+       sport->rx_dma_rng_buf_len = (1 << (fls(sport->rx_dma_rng_buf_len) - 1));
+       if (sport->rx_dma_rng_buf_len < 16)
+               sport->rx_dma_rng_buf_len = 16;
+
+       ring->buf = kmalloc(sport->rx_dma_rng_buf_len, GFP_KERNEL);
+       if (!ring->buf) {
+               dev_err(sport->port.dev, "Ring buf alloc failed\n");
+               return -ENOMEM;
+       }
+
+       sg_init_one(&sport->rx_sgl, ring->buf, sport->rx_dma_rng_buf_len);
+       sg_set_buf(&sport->rx_sgl, ring->buf, sport->rx_dma_rng_buf_len);
+       nent = dma_map_sg(sport->port.dev, &sport->rx_sgl, 1, DMA_FROM_DEVICE);
+
+       if (!nent) {
+               dev_err(sport->port.dev, "DMA Rx mapping error\n");
+               return -EINVAL;
+       }
+
+       dma_rx_sconfig.src_addr = sport->port.mapbase + UARTDR;
+       dma_rx_sconfig.src_addr_width = DMA_SLAVE_BUSWIDTH_1_BYTE;
+       dma_rx_sconfig.src_maxburst = 1;
+       dma_rx_sconfig.direction = DMA_DEV_TO_MEM;
+       ret = dmaengine_slave_config(sport->dma_rx_chan, &dma_rx_sconfig);
+
+       if (ret < 0) {
+               dev_err(sport->port.dev,
+                               "DMA Rx slave config failed, err = %d\n", ret);
+               return ret;
+       }
+
+       sport->dma_rx_desc = dmaengine_prep_dma_cyclic(sport->dma_rx_chan,
+                                sg_dma_address(&sport->rx_sgl),
+                                sport->rx_sgl.length,
+                                sport->rx_sgl.length / 2,
+                                DMA_DEV_TO_MEM,
+                                DMA_PREP_INTERRUPT);
+       if (!sport->dma_rx_desc) {
+               dev_err(sport->port.dev, "Cannot prepare cyclic DMA\n");
+               return -EFAULT;
+       }
+
+       sport->dma_rx_desc->callback = lpuart_dma_rx_complete;
+       sport->dma_rx_desc->callback_param = sport;
+       sport->dma_rx_cookie = dmaengine_submit(sport->dma_rx_desc);
+       dma_async_issue_pending(sport->dma_rx_chan);
+
+       writeb(readb(sport->port.membase + UARTCR5) | UARTCR5_RDMAS,
+                               sport->port.membase + UARTCR5);
+
+       return 0;
+}
+
+static void lpuart_dma_rx_free(struct uart_port *port)
+{
+       struct lpuart_port *sport = container_of(port,
+                                       struct lpuart_port, port);
+
+       if (sport->dma_rx_chan)
+               dmaengine_terminate_all(sport->dma_rx_chan);
+
+       dma_unmap_sg(sport->port.dev, &sport->rx_sgl, 1, DMA_FROM_DEVICE);
+       kfree(sport->rx_ring.buf);
+       sport->rx_ring.tail = 0;
+       sport->rx_ring.head = 0;
+       sport->dma_rx_desc = NULL;
+       sport->dma_rx_cookie = -EINVAL;
+}
+
+static int lpuart_config_rs485(struct uart_port *port,
+                       struct serial_rs485 *rs485)
+{
+       struct lpuart_port *sport = container_of(port,
+                       struct lpuart_port, port);
+
+       u8 modem = readb(sport->port.membase + UARTMODEM) &
+               ~(UARTMODEM_TXRTSPOL | UARTMODEM_TXRTSE);
+       writeb(modem, sport->port.membase + UARTMODEM);
+
+       if (rs485->flags & SER_RS485_ENABLED) {
+               /* Enable auto RS-485 RTS mode */
+               modem |= UARTMODEM_TXRTSE;
+
+               /*
+                * RTS needs to be logic HIGH either during transer _or_ after
+                * transfer, other variants are not supported by the hardware.
+                */
+
+               if (!(rs485->flags & (SER_RS485_RTS_ON_SEND |
+                               SER_RS485_RTS_AFTER_SEND)))
+                       rs485->flags |= SER_RS485_RTS_ON_SEND;
+
+               if (rs485->flags & SER_RS485_RTS_ON_SEND &&
+                               rs485->flags & SER_RS485_RTS_AFTER_SEND)
+                       rs485->flags &= ~SER_RS485_RTS_AFTER_SEND;
+
+               /*
+                * The hardware defaults to RTS logic HIGH while transfer.
+                * Switch polarity in case RTS shall be logic HIGH
+                * after transfer.
+                * Note: UART is assumed to be active high.
+                */
+               if (rs485->flags & SER_RS485_RTS_ON_SEND)
+                       modem &= ~UARTMODEM_TXRTSPOL;
+               else if (rs485->flags & SER_RS485_RTS_AFTER_SEND)
+                       modem |= UARTMODEM_TXRTSPOL;
+       }
+
+       /* Store the new configuration */
+       sport->port.rs485 = *rs485;
+
+       writeb(modem, sport->port.membase + UARTMODEM);
+       return 0;
 }
 
 static unsigned int lpuart_get_mctrl(struct uart_port *port)
@@ -853,17 +996,22 @@ static unsigned int lpuart32_get_mctrl(struct uart_port *port)
 static void lpuart_set_mctrl(struct uart_port *port, unsigned int mctrl)
 {
        unsigned char temp;
+       struct lpuart_port *sport = container_of(port,
+                               struct lpuart_port, port);
 
-       temp = readb(port->membase + UARTMODEM) &
+       /* Make sure RXRTSE bit is not set when RS485 is enabled */
+       if (!(sport->port.rs485.flags & SER_RS485_ENABLED)) {
+               temp = readb(sport->port.membase + UARTMODEM) &
                        ~(UARTMODEM_RXRTSE | UARTMODEM_TXCTSE);
 
-       if (mctrl & TIOCM_RTS)
-               temp |= UARTMODEM_RXRTSE;
+               if (mctrl & TIOCM_RTS)
+                       temp |= UARTMODEM_RXRTSE;
 
-       if (mctrl & TIOCM_CTS)
-               temp |= UARTMODEM_TXCTSE;
+               if (mctrl & TIOCM_CTS)
+                       temp |= UARTMODEM_TXCTSE;
 
-       writeb(temp, port->membase + UARTMODEM);
+               writeb(temp, port->membase + UARTMODEM);
+       }
 }
 
 static void lpuart32_set_mctrl(struct uart_port *port, unsigned int mctrl)
@@ -921,13 +1069,16 @@ static void lpuart_setup_watermark(struct lpuart_port *sport)
        writeb(val | UARTPFIFO_TXFE | UARTPFIFO_RXFE,
                        sport->port.membase + UARTPFIFO);
 
-       /* explicitly clear RDRF */
-       readb(sport->port.membase + UARTSR1);
-
        /* flush Tx and Rx FIFO */
        writeb(UARTCFIFO_TXFLUSH | UARTCFIFO_RXFLUSH,
                        sport->port.membase + UARTCFIFO);
 
+       /* explicitly clear RDRF */
+       if (readb(sport->port.membase + UARTSR1) & UARTSR1_RDRF) {
+               readb(sport->port.membase + UARTDR);
+               writeb(UARTSFIFO_RXUF, sport->port.membase + UARTSFIFO);
+       }
+
        writeb(0, sport->port.membase + UARTTWFIFO);
        writeb(1, sport->port.membase + UARTRWFIFO);
 
@@ -960,110 +1111,12 @@ static void lpuart32_setup_watermark(struct lpuart_port *sport)
        lpuart32_write(ctrl_saved, sport->port.membase + UARTCTRL);
 }
 
-static int lpuart_dma_tx_request(struct uart_port *port)
-{
-       struct lpuart_port *sport = container_of(port,
-                                       struct lpuart_port, port);
-       struct dma_slave_config dma_tx_sconfig;
-       dma_addr_t dma_bus;
-       unsigned char *dma_buf;
-       int ret;
-
-       dma_bus = dma_map_single(sport->dma_tx_chan->device->dev,
-                               sport->port.state->xmit.buf,
-                               UART_XMIT_SIZE, DMA_TO_DEVICE);
-
-       if (dma_mapping_error(sport->dma_tx_chan->device->dev, dma_bus)) {
-               dev_err(sport->port.dev, "dma_map_single tx failed\n");
-               return -ENOMEM;
-       }
-
-       dma_buf = sport->port.state->xmit.buf;
-       dma_tx_sconfig.dst_addr = sport->port.mapbase + UARTDR;
-       dma_tx_sconfig.dst_addr_width = DMA_SLAVE_BUSWIDTH_1_BYTE;
-       dma_tx_sconfig.dst_maxburst = sport->txfifo_size;
-       dma_tx_sconfig.direction = DMA_MEM_TO_DEV;
-       ret = dmaengine_slave_config(sport->dma_tx_chan, &dma_tx_sconfig);
-
-       if (ret < 0) {
-               dev_err(sport->port.dev,
-                               "Dma slave config failed, err = %d\n", ret);
-               return ret;
-       }
-
-       sport->dma_tx_buf_virt = dma_buf;
-       sport->dma_tx_buf_bus = dma_bus;
-       sport->dma_tx_in_progress = 0;
-
-       return 0;
-}
-
-static int lpuart_dma_rx_request(struct uart_port *port)
+static void rx_dma_timer_init(struct lpuart_port *sport)
 {
-       struct lpuart_port *sport = container_of(port,
-                                       struct lpuart_port, port);
-       struct dma_slave_config dma_rx_sconfig;
-       dma_addr_t dma_bus;
-       unsigned char *dma_buf;
-       int ret;
-
-       dma_buf = devm_kzalloc(sport->port.dev,
-                               FSL_UART_RX_DMA_BUFFER_SIZE, GFP_KERNEL);
-
-       if (!dma_buf) {
-               dev_err(sport->port.dev, "Dma rx alloc failed\n");
-               return -ENOMEM;
-       }
-
-       dma_bus = dma_map_single(sport->dma_rx_chan->device->dev, dma_buf,
-                               FSL_UART_RX_DMA_BUFFER_SIZE, DMA_FROM_DEVICE);
-
-       if (dma_mapping_error(sport->dma_rx_chan->device->dev, dma_bus)) {
-               dev_err(sport->port.dev, "dma_map_single rx failed\n");
-               return -ENOMEM;
-       }
-
-       dma_rx_sconfig.src_addr = sport->port.mapbase + UARTDR;
-       dma_rx_sconfig.src_addr_width = DMA_SLAVE_BUSWIDTH_1_BYTE;
-       dma_rx_sconfig.src_maxburst = 1;
-       dma_rx_sconfig.direction = DMA_DEV_TO_MEM;
-       ret = dmaengine_slave_config(sport->dma_rx_chan, &dma_rx_sconfig);
-
-       if (ret < 0) {
-               dev_err(sport->port.dev,
-                               "Dma slave config failed, err = %d\n", ret);
-               return ret;
-       }
-
-       sport->dma_rx_buf_virt = dma_buf;
-       sport->dma_rx_buf_bus = dma_bus;
-       sport->dma_rx_in_progress = 0;
-
-       return 0;
-}
-
-static void lpuart_dma_tx_free(struct uart_port *port)
-{
-       struct lpuart_port *sport = container_of(port,
-                                       struct lpuart_port, port);
-
-       dma_unmap_single(sport->port.dev, sport->dma_tx_buf_bus,
-                       UART_XMIT_SIZE, DMA_TO_DEVICE);
-
-       sport->dma_tx_buf_bus = 0;
-       sport->dma_tx_buf_virt = NULL;
-}
-
-static void lpuart_dma_rx_free(struct uart_port *port)
-{
-       struct lpuart_port *sport = container_of(port,
-                                       struct lpuart_port, port);
-
-       dma_unmap_single(sport->port.dev, sport->dma_rx_buf_bus,
-                       FSL_UART_RX_DMA_BUFFER_SIZE, DMA_FROM_DEVICE);
-
-       sport->dma_rx_buf_bus = 0;
-       sport->dma_rx_buf_virt = NULL;
+               setup_timer(&sport->lpuart_timer, lpuart_timer_func,
+                               (unsigned long)sport);
+               sport->lpuart_timer.expires = jiffies + sport->dma_rx_timeout;
+               add_timer(&sport->lpuart_timer);
 }
 
 static int lpuart_startup(struct uart_port *port)
@@ -1084,22 +1137,6 @@ static int lpuart_startup(struct uart_port *port)
        sport->rxfifo_size = 0x1 << (((temp >> UARTPFIFO_RXSIZE_OFF) &
                UARTPFIFO_FIFOSIZE_MASK) + 1);
 
-       if (sport->dma_rx_chan && !lpuart_dma_rx_request(port)) {
-               sport->lpuart_dma_rx_use = true;
-               setup_timer(&sport->lpuart_timer, lpuart_timer_func,
-                           (unsigned long)sport);
-       } else
-               sport->lpuart_dma_rx_use = false;
-
-
-       if (sport->dma_tx_chan && !lpuart_dma_tx_request(port)) {
-               sport->lpuart_dma_tx_use = true;
-               temp = readb(port->membase + UARTCR5);
-               temp &= ~UARTCR5_RDMAS;
-               writeb(temp | UARTCR5_TDMAS, port->membase + UARTCR5);
-       } else
-               sport->lpuart_dma_tx_use = false;
-
        ret = devm_request_irq(port->dev, port->irq, lpuart_int, 0,
                                DRIVER_NAME, sport);
        if (ret)
@@ -1113,7 +1150,29 @@ static int lpuart_startup(struct uart_port *port)
        temp |= (UARTCR2_RIE | UARTCR2_TIE | UARTCR2_RE | UARTCR2_TE);
        writeb(temp, sport->port.membase + UARTCR2);
 
+       if (sport->dma_rx_chan && !lpuart_start_rx_dma(sport)) {
+               /* set Rx DMA timeout */
+               sport->dma_rx_timeout = msecs_to_jiffies(DMA_RX_TIMEOUT);
+               if (!sport->dma_rx_timeout)
+                    sport->dma_rx_timeout = 1;
+
+               sport->lpuart_dma_rx_use = true;
+               rx_dma_timer_init(sport);
+       } else {
+               sport->lpuart_dma_rx_use = false;
+       }
+
+       if (sport->dma_tx_chan && !lpuart_dma_tx_request(port)) {
+               init_waitqueue_head(&sport->dma_wait);
+               sport->lpuart_dma_tx_use = true;
+               temp = readb(port->membase + UARTCR5);
+               writeb(temp | UARTCR5_TDMAS, port->membase + UARTCR5);
+       } else {
+               sport->lpuart_dma_tx_use = false;
+       }
+
        spin_unlock_irqrestore(&sport->port.lock, flags);
+
        return 0;
 }
 
@@ -1170,12 +1229,19 @@ static void lpuart_shutdown(struct uart_port *port)
        devm_free_irq(port->dev, port->irq, sport);
 
        if (sport->lpuart_dma_rx_use) {
-               lpuart_dma_rx_free(&sport->port);
                del_timer_sync(&sport->lpuart_timer);
+               lpuart_dma_rx_free(&sport->port);
        }
 
-       if (sport->lpuart_dma_tx_use)
-               lpuart_dma_tx_free(&sport->port);
+       if (sport->lpuart_dma_tx_use) {
+               if (wait_event_interruptible(sport->dma_wait,
+                       !sport->dma_tx_in_progress) != false) {
+                       sport->dma_tx_in_progress = false;
+                       dmaengine_terminate_all(sport->dma_tx_chan);
+               }
+
+               lpuart_stop_tx(port);
+       }
 }
 
 static void lpuart32_shutdown(struct uart_port *port)
@@ -1203,13 +1269,14 @@ lpuart_set_termios(struct uart_port *port, struct ktermios *termios,
 {
        struct lpuart_port *sport = container_of(port, struct lpuart_port, port);
        unsigned long flags;
-       unsigned char cr1, old_cr1, old_cr2, cr4, bdh, modem;
+       unsigned char cr1, old_cr1, old_cr2, cr3, cr4, bdh, modem;
        unsigned int  baud;
        unsigned int old_csize = old ? old->c_cflag & CSIZE : CS8;
        unsigned int sbr, brfa;
 
        cr1 = old_cr1 = readb(sport->port.membase + UARTCR1);
        old_cr2 = readb(sport->port.membase + UARTCR2);
+       cr3 = readb(sport->port.membase + UARTCR3);
        cr4 = readb(sport->port.membase + UARTCR4);
        bdh = readb(sport->port.membase + UARTBDH);
        modem = readb(sport->port.membase + UARTMODEM);
@@ -1240,6 +1307,13 @@ lpuart_set_termios(struct uart_port *port, struct ktermios *termios,
                cr1 |= UARTCR1_M;
        }
 
+       /*
+        * When auto RS-485 RTS mode is enabled,
+        * hardware flow control need to be disabled.
+        */
+       if (sport->port.rs485.flags & SER_RS485_ENABLED)
+               termios->c_cflag &= ~CRTSCTS;
+
        if (termios->c_cflag & CRTSCTS) {
                modem |= (UARTMODEM_RXRTSE | UARTMODEM_TXCTSE);
        } else {
@@ -1257,7 +1331,10 @@ lpuart_set_termios(struct uart_port *port, struct ktermios *termios,
        if ((termios->c_cflag & PARENB)) {
                if (termios->c_cflag & CMSPAR) {
                        cr1 &= ~UARTCR1_PE;
-                       cr1 |= UARTCR1_M;
+                       if (termios->c_cflag & PARODD)
+                               cr3 |= UARTCR3_T8;
+                       else
+                               cr3 &= ~UARTCR3_T8;
                } else {
                        cr1 |= UARTCR1_PE;
                        if ((termios->c_cflag & CSIZE) == CS8)
@@ -1297,17 +1374,6 @@ lpuart_set_termios(struct uart_port *port, struct ktermios *termios,
        /* update the per-port timeout */
        uart_update_timeout(port, termios->c_cflag, baud);
 
-       if (sport->lpuart_dma_rx_use) {
-               /* Calculate delay for 1.5 DMA buffers */
-               sport->dma_rx_timeout = (sport->port.timeout - HZ / 50) *
-                                       FSL_UART_RX_DMA_BUFFER_SIZE * 3 /
-                                       sport->rxfifo_size / 2;
-               dev_dbg(port->dev, "DMA Rx t-out %ums, tty t-out %u jiffies\n",
-                       sport->dma_rx_timeout * 1000 / HZ, sport->port.timeout);
-               if (sport->dma_rx_timeout < msecs_to_jiffies(20))
-                       sport->dma_rx_timeout = msecs_to_jiffies(20);
-       }
-
        /* wait transmit engin complete */
        while (!(readb(sport->port.membase + UARTSR1) & UARTSR1_TC))
                barrier();
@@ -1325,12 +1391,31 @@ lpuart_set_termios(struct uart_port *port, struct ktermios *termios,
        writeb(cr4 | brfa, sport->port.membase + UARTCR4);
        writeb(bdh, sport->port.membase + UARTBDH);
        writeb(sbr & 0xFF, sport->port.membase + UARTBDL);
+       writeb(cr3, sport->port.membase + UARTCR3);
        writeb(cr1, sport->port.membase + UARTCR1);
        writeb(modem, sport->port.membase + UARTMODEM);
 
        /* restore control register */
        writeb(old_cr2, sport->port.membase + UARTCR2);
 
+       /*
+        * If new baud rate is set, we will also need to update the Ring buffer
+        * length according to the selected baud rate and restart Rx DMA path.
+        */
+       if (old) {
+               if (sport->lpuart_dma_rx_use) {
+                       del_timer_sync(&sport->lpuart_timer);
+                       lpuart_dma_rx_free(&sport->port);
+               }
+
+               if (sport->dma_rx_chan && !lpuart_start_rx_dma(sport)) {
+                       sport->lpuart_dma_rx_use = true;
+                       rx_dma_timer_init(sport);
+               } else {
+                       sport->lpuart_dma_rx_use = false;
+               }
+       }
+
        spin_unlock_irqrestore(&sport->port.lock, flags);
 }
 
@@ -1494,7 +1579,7 @@ static int lpuart_verify_port(struct uart_port *port, struct serial_struct *ser)
        return ret;
 }
 
-static struct uart_ops lpuart_pops = {
+static const struct uart_ops lpuart_pops = {
        .tx_empty       = lpuart_tx_empty,
        .set_mctrl      = lpuart_set_mctrl,
        .get_mctrl      = lpuart_get_mctrl,
@@ -1513,7 +1598,7 @@ static struct uart_ops lpuart_pops = {
        .flush_buffer   = lpuart_flush_buffer,
 };
 
-static struct uart_ops lpuart32_pops = {
+static const struct uart_ops lpuart32_pops = {
        .tx_empty       = lpuart32_tx_empty,
        .set_mctrl      = lpuart32_set_mctrl,
        .get_mctrl      = lpuart32_get_mctrl,
@@ -1843,6 +1928,8 @@ static int lpuart_probe(struct platform_device *pdev)
                sport->port.ops = &lpuart_pops;
        sport->port.flags = UPF_BOOT_AUTOCONF;
 
+       sport->port.rs485_config = lpuart_config_rs485;
+
        sport->clk = devm_clk_get(&pdev->dev, "ipg");
        if (IS_ERR(sport->clk)) {
                ret = PTR_ERR(sport->clk);
@@ -1883,6 +1970,12 @@ static int lpuart_probe(struct platform_device *pdev)
                dev_info(sport->port.dev, "DMA rx channel request failed, "
                                "operating without rx DMA\n");
 
+       if (of_property_read_bool(np, "linux,rs485-enabled-at-boot-time")) {
+               sport->port.rs485.flags |= SER_RS485_ENABLED;
+               sport->port.rs485.flags |= SER_RS485_RTS_ON_SEND;
+               writeb(UARTMODEM_TXRTSE, sport->port.membase + UARTMODEM);
+       }
+
        return 0;
 }
 
@@ -1923,6 +2016,32 @@ static int lpuart_suspend(struct device *dev)
 
        uart_suspend_port(&lpuart_reg, &sport->port);
 
+       if (sport->lpuart_dma_rx_use) {
+               /*
+                * EDMA driver during suspend will forcefully release any
+                * non-idle DMA channels. If port wakeup is enabled or if port
+                * is console port or 'no_console_suspend' is set the Rx DMA
+                * cannot resume as as expected, hence gracefully release the
+                * Rx DMA path before suspend and start Rx DMA path on resume.
+                */
+               if (sport->port.irq_wake) {
+                       del_timer_sync(&sport->lpuart_timer);
+                       lpuart_dma_rx_free(&sport->port);
+               }
+
+               /* Disable Rx DMA to use UART port as wakeup source */
+               writeb(readb(sport->port.membase + UARTCR5) & ~UARTCR5_RDMAS,
+                                       sport->port.membase + UARTCR5);
+       }
+
+       if (sport->lpuart_dma_tx_use) {
+               sport->dma_tx_in_progress = false;
+               dmaengine_terminate_all(sport->dma_tx_chan);
+       }
+
+       if (sport->port.suspended && !sport->port.irq_wake)
+               clk_disable_unprepare(sport->clk);
+
        return 0;
 }
 
@@ -1931,6 +2050,9 @@ static int lpuart_resume(struct device *dev)
        struct lpuart_port *sport = dev_get_drvdata(dev);
        unsigned long temp;
 
+       if (sport->port.suspended && !sport->port.irq_wake)
+               clk_prepare_enable(sport->clk);
+
        if (sport->lpuart32) {
                lpuart32_setup_watermark(sport);
                temp = lpuart32_read(sport->port.membase + UARTCTRL);
@@ -1944,6 +2066,26 @@ static int lpuart_resume(struct device *dev)
                writeb(temp, sport->port.membase + UARTCR2);
        }
 
+       if (sport->lpuart_dma_rx_use) {
+               if (sport->port.irq_wake) {
+                       if (!lpuart_start_rx_dma(sport)) {
+                               sport->lpuart_dma_rx_use = true;
+                               rx_dma_timer_init(sport);
+                       } else {
+                               sport->lpuart_dma_rx_use = false;
+                       }
+               }
+       }
+
+       if (sport->dma_tx_chan && !lpuart_dma_tx_request(&sport->port)) {
+                       init_waitqueue_head(&sport->dma_wait);
+                       sport->lpuart_dma_tx_use = true;
+                       writeb(readb(sport->port.membase + UARTCR5) |
+                               UARTCR5_TDMAS, sport->port.membase + UARTCR5);
+       } else {
+               sport->lpuart_dma_tx_use = false;
+       }
+
        uart_resume_port(&lpuart_reg, &sport->port);
 
        return 0;
index 0df2b1c091aea5860a0b42240e49c2acd72f9ca3..782b0e524e1461fe72a71282928dd44ab145ea84 100644 (file)
 enum imx_uart_type {
        IMX1_UART,
        IMX21_UART,
+       IMX53_UART,
        IMX6Q_UART,
 };
 
@@ -222,6 +223,9 @@ struct imx_port {
        struct dma_chan         *dma_chan_rx, *dma_chan_tx;
        struct scatterlist      rx_sgl, tx_sgl[2];
        void                    *rx_buf;
+       struct circ_buf         rx_ring;
+       unsigned int            rx_periods;
+       dma_cookie_t            rx_cookie;
        unsigned int            tx_bytes;
        unsigned int            dma_tx_nents;
        wait_queue_head_t       dma_wait;
@@ -244,6 +248,10 @@ static struct imx_uart_data imx_uart_devdata[] = {
                .uts_reg = IMX21_UTS,
                .devtype = IMX21_UART,
        },
+       [IMX53_UART] = {
+               .uts_reg = IMX21_UTS,
+               .devtype = IMX53_UART,
+       },
        [IMX6Q_UART] = {
                .uts_reg = IMX21_UTS,
                .devtype = IMX6Q_UART,
@@ -257,6 +265,9 @@ static const struct platform_device_id imx_uart_devtype[] = {
        }, {
                .name = "imx21-uart",
                .driver_data = (kernel_ulong_t) &imx_uart_devdata[IMX21_UART],
+       }, {
+               .name = "imx53-uart",
+               .driver_data = (kernel_ulong_t) &imx_uart_devdata[IMX53_UART],
        }, {
                .name = "imx6q-uart",
                .driver_data = (kernel_ulong_t) &imx_uart_devdata[IMX6Q_UART],
@@ -268,6 +279,7 @@ MODULE_DEVICE_TABLE(platform, imx_uart_devtype);
 
 static const struct of_device_id imx_uart_dt_ids[] = {
        { .compatible = "fsl,imx6q-uart", .data = &imx_uart_devdata[IMX6Q_UART], },
+       { .compatible = "fsl,imx53-uart", .data = &imx_uart_devdata[IMX53_UART], },
        { .compatible = "fsl,imx1-uart", .data = &imx_uart_devdata[IMX1_UART], },
        { .compatible = "fsl,imx21-uart", .data = &imx_uart_devdata[IMX21_UART], },
        { /* sentinel */ }
@@ -289,6 +301,11 @@ static inline int is_imx21_uart(struct imx_port *sport)
        return sport->devdata->devtype == IMX21_UART;
 }
 
+static inline int is_imx53_uart(struct imx_port *sport)
+{
+       return sport->devdata->devtype == IMX53_UART;
+}
+
 static inline int is_imx6q_uart(struct imx_port *sport)
 {
        return sport->devdata->devtype == IMX6Q_UART;
@@ -701,6 +718,7 @@ out:
        return IRQ_HANDLED;
 }
 
+static void clear_rx_errors(struct imx_port *sport);
 static int start_rx_dma(struct imx_port *sport);
 /*
  * If the RXFIFO is filled with some data, and then we
@@ -726,6 +744,11 @@ static void imx_dma_rxint(struct imx_port *sport)
                temp &= ~(UCR2_ATEN);
                writel(temp, sport->port.membase + UCR2);
 
+               /* disable the rx errors interrupts */
+               temp = readl(sport->port.membase + UCR4);
+               temp &= ~UCR4_OREN;
+               writel(temp, sport->port.membase + UCR4);
+
                /* tell the DMA to receive the data. */
                start_rx_dma(sport);
        }
@@ -932,30 +955,6 @@ static void imx_timeout(unsigned long data)
 }
 
 #define RX_BUF_SIZE    (PAGE_SIZE)
-static void imx_rx_dma_done(struct imx_port *sport)
-{
-       unsigned long temp;
-       unsigned long flags;
-
-       spin_lock_irqsave(&sport->port.lock, flags);
-
-       /* re-enable interrupts to get notified when new symbols are incoming */
-       temp = readl(sport->port.membase + UCR1);
-       temp |= UCR1_RRDYEN;
-       writel(temp, sport->port.membase + UCR1);
-
-       temp = readl(sport->port.membase + UCR2);
-       temp |= UCR2_ATEN;
-       writel(temp, sport->port.membase + UCR2);
-
-       sport->dma_is_rxing = 0;
-
-       /* Is the shutdown waiting for us? */
-       if (waitqueue_active(&sport->dma_wait))
-               wake_up(&sport->dma_wait);
-
-       spin_unlock_irqrestore(&sport->port.lock, flags);
-}
 
 /*
  * There are two kinds of RX DMA interrupts(such as in the MX6Q):
@@ -972,43 +971,76 @@ static void dma_rx_callback(void *data)
        struct scatterlist *sgl = &sport->rx_sgl;
        struct tty_port *port = &sport->port.state->port;
        struct dma_tx_state state;
+       struct circ_buf *rx_ring = &sport->rx_ring;
        enum dma_status status;
-       unsigned int count;
-
-       /* unmap it first */
-       dma_unmap_sg(sport->port.dev, sgl, 1, DMA_FROM_DEVICE);
+       unsigned int w_bytes = 0;
+       unsigned int r_bytes;
+       unsigned int bd_size;
 
        status = dmaengine_tx_status(chan, (dma_cookie_t)0, &state);
-       count = RX_BUF_SIZE - state.residue;
 
-       dev_dbg(sport->port.dev, "We get %d bytes.\n", count);
+       if (status == DMA_ERROR) {
+               dev_err(sport->port.dev, "DMA transaction error.\n");
+               clear_rx_errors(sport);
+               return;
+       }
+
+       if (!(sport->port.ignore_status_mask & URXD_DUMMY_READ)) {
+
+               /*
+                * The state-residue variable represents the empty space
+                * relative to the entire buffer. Taking this in consideration
+                * the head is always calculated base on the buffer total
+                * length - DMA transaction residue. The UART script from the
+                * SDMA firmware will jump to the next buffer descriptor,
+                * once a DMA transaction if finalized (IMX53 RM - A.4.1.2.4).
+                * Taking this in consideration the tail is always at the
+                * beginning of the buffer descriptor that contains the head.
+                */
+
+               /* Calculate the head */
+               rx_ring->head = sg_dma_len(sgl) - state.residue;
 
-       if (count) {
-               if (!(sport->port.ignore_status_mask & URXD_DUMMY_READ)) {
-                       int bytes = tty_insert_flip_string(port, sport->rx_buf,
-                                       count);
+               /* Calculate the tail. */
+               bd_size = sg_dma_len(sgl) / sport->rx_periods;
+               rx_ring->tail = ((rx_ring->head-1) / bd_size) * bd_size;
 
-                       if (bytes != count)
+               if (rx_ring->head <= sg_dma_len(sgl) &&
+                   rx_ring->head > rx_ring->tail) {
+
+                       /* Move data from tail to head */
+                       r_bytes = rx_ring->head - rx_ring->tail;
+
+                       /* CPU claims ownership of RX DMA buffer */
+                       dma_sync_sg_for_cpu(sport->port.dev, sgl, 1,
+                               DMA_FROM_DEVICE);
+
+                       w_bytes = tty_insert_flip_string(port,
+                               sport->rx_buf + rx_ring->tail, r_bytes);
+
+                       /* UART retrieves ownership of RX DMA buffer */
+                       dma_sync_sg_for_device(sport->port.dev, sgl, 1,
+                               DMA_FROM_DEVICE);
+
+                       if (w_bytes != r_bytes)
                                sport->port.icount.buf_overrun++;
+
+                       sport->port.icount.rx += w_bytes;
+               } else  {
+                       WARN_ON(rx_ring->head > sg_dma_len(sgl));
+                       WARN_ON(rx_ring->head <= rx_ring->tail);
                }
-               tty_flip_buffer_push(port);
-               sport->port.icount.rx += count;
        }
 
-       /*
-        * Restart RX DMA directly if more data is available in order to skip
-        * the roundtrip through the IRQ handler. If there is some data already
-        * in the FIFO, DMA needs to be restarted soon anyways.
-        *
-        * Otherwise stop the DMA and reactivate FIFO IRQs to restart DMA once
-        * data starts to arrive again.
-        */
-       if (readl(sport->port.membase + USR2) & USR2_RDR)
-               start_rx_dma(sport);
-       else
-               imx_rx_dma_done(sport);
+       if (w_bytes) {
+               tty_flip_buffer_push(port);
+               dev_dbg(sport->port.dev, "We get %d bytes.\n", w_bytes);
+       }
 }
 
+/* RX DMA buffer periods */
+#define RX_DMA_PERIODS 4
+
 static int start_rx_dma(struct imx_port *sport)
 {
        struct scatterlist *sgl = &sport->rx_sgl;
@@ -1017,14 +1049,21 @@ static int start_rx_dma(struct imx_port *sport)
        struct dma_async_tx_descriptor *desc;
        int ret;
 
+       sport->rx_ring.head = 0;
+       sport->rx_ring.tail = 0;
+       sport->rx_periods = RX_DMA_PERIODS;
+
        sg_init_one(sgl, sport->rx_buf, RX_BUF_SIZE);
        ret = dma_map_sg(dev, sgl, 1, DMA_FROM_DEVICE);
        if (ret == 0) {
                dev_err(dev, "DMA mapping error for RX.\n");
                return -EINVAL;
        }
-       desc = dmaengine_prep_slave_sg(chan, sgl, 1, DMA_DEV_TO_MEM,
-                                       DMA_PREP_INTERRUPT);
+
+       desc = dmaengine_prep_dma_cyclic(chan, sg_dma_address(sgl),
+               sg_dma_len(sgl), sg_dma_len(sgl) / sport->rx_periods,
+               DMA_DEV_TO_MEM, DMA_PREP_INTERRUPT);
+
        if (!desc) {
                dma_unmap_sg(dev, sgl, 1, DMA_FROM_DEVICE);
                dev_err(dev, "We cannot prepare for the RX slave dma!\n");
@@ -1034,11 +1073,36 @@ static int start_rx_dma(struct imx_port *sport)
        desc->callback_param = sport;
 
        dev_dbg(dev, "RX: prepare for the DMA.\n");
-       dmaengine_submit(desc);
+       sport->rx_cookie = dmaengine_submit(desc);
        dma_async_issue_pending(chan);
        return 0;
 }
 
+static void clear_rx_errors(struct imx_port *sport)
+{
+       unsigned int status_usr1, status_usr2;
+
+       status_usr1 = readl(sport->port.membase + USR1);
+       status_usr2 = readl(sport->port.membase + USR2);
+
+       if (status_usr2 & USR2_BRCD) {
+               sport->port.icount.brk++;
+               writel(USR2_BRCD, sport->port.membase + USR2);
+       } else if (status_usr1 & USR1_FRAMERR) {
+               sport->port.icount.frame++;
+               writel(USR1_FRAMERR, sport->port.membase + USR1);
+       } else if (status_usr1 & USR1_PARITYERR) {
+               sport->port.icount.parity++;
+               writel(USR1_PARITYERR, sport->port.membase + USR1);
+       }
+
+       if (status_usr2 & USR2_ORE) {
+               sport->port.icount.overrun++;
+               writel(USR2_ORE, sport->port.membase + USR2);
+       }
+
+}
+
 #define TXTL_DEFAULT 2 /* reset default */
 #define RXTL_DEFAULT 1 /* reset default */
 #define TXTL_DMA 8 /* DMA burst setting */
@@ -1058,14 +1122,16 @@ static void imx_setup_ufcr(struct imx_port *sport,
 static void imx_uart_dma_exit(struct imx_port *sport)
 {
        if (sport->dma_chan_rx) {
+               dmaengine_terminate_all(sport->dma_chan_rx);
                dma_release_channel(sport->dma_chan_rx);
                sport->dma_chan_rx = NULL;
-
+               sport->rx_cookie = -EINVAL;
                kfree(sport->rx_buf);
                sport->rx_buf = NULL;
        }
 
        if (sport->dma_chan_tx) {
+               dmaengine_terminate_all(sport->dma_chan_tx);
                dma_release_channel(sport->dma_chan_tx);
                sport->dma_chan_tx = NULL;
        }
@@ -1103,6 +1169,7 @@ static int imx_uart_dma_init(struct imx_port *sport)
                ret = -ENOMEM;
                goto err;
        }
+       sport->rx_ring.buf = sport->rx_buf;
 
        /* Prepare for TX : */
        sport->dma_chan_tx = dma_request_slave_channel(dev, "tx");
@@ -1201,8 +1268,7 @@ static int imx_startup(struct uart_port *port)
        writel(temp & ~UCR4_DREN, sport->port.membase + UCR4);
 
        /* Can we enable the DMA support? */
-       if (is_imx6q_uart(sport) && !uart_console(port) &&
-           !sport->dma_is_inited)
+       if (!uart_console(port) && !sport->dma_is_inited)
                imx_uart_dma_init(sport);
 
        spin_lock_irqsave(&sport->port.lock, flags);
@@ -1283,17 +1349,11 @@ static void imx_shutdown(struct uart_port *port)
        unsigned long flags;
 
        if (sport->dma_is_enabled) {
-               int ret;
+               sport->dma_is_rxing = 0;
+               sport->dma_is_txing = 0;
+               dmaengine_terminate_all(sport->dma_chan_tx);
+               dmaengine_terminate_all(sport->dma_chan_rx);
 
-               /* We have to wait for the DMA to finish. */
-               ret = wait_event_interruptible(sport->dma_wait,
-                       !sport->dma_is_rxing && !sport->dma_is_txing);
-               if (ret != 0) {
-                       sport->dma_is_rxing = 0;
-                       sport->dma_is_txing = 0;
-                       dmaengine_terminate_all(sport->dma_chan_tx);
-                       dmaengine_terminate_all(sport->dma_chan_rx);
-               }
                spin_lock_irqsave(&sport->port.lock, flags);
                imx_stop_tx(port);
                imx_stop_rx(port);
@@ -1690,7 +1750,7 @@ static int imx_rs485_config(struct uart_port *port,
        return 0;
 }
 
-static struct uart_ops imx_pops = {
+static const struct uart_ops imx_pops = {
        .tx_empty       = imx_tx_empty,
        .set_mctrl      = imx_set_mctrl,
        .get_mctrl      = imx_get_mctrl,
index c5ddfe542451f55d90f9e0b240c30668b188ef68..ec7d8383900fc742b9bc889c964809eb005ca2b3 100644 (file)
@@ -346,7 +346,7 @@ static void jsm_config_port(struct uart_port *port, int flags)
        port->type = PORT_JSM;
 }
 
-static struct uart_ops jsm_ops = {
+static const struct uart_ops jsm_ops = {
        .tx_empty       = jsm_tty_tx_empty,
        .set_mctrl      = jsm_tty_set_mctrl,
        .get_mctrl      = jsm_tty_get_mctrl,
index 5c4c280b3207a612ab810dae798dfdec87d8c7ae..ace82645b1237928d5b87bd118f5c10852566265 100644 (file)
@@ -712,7 +712,7 @@ static void max3100_break_ctl(struct uart_port *port, int break_state)
        dev_dbg(&s->spi->dev, "%s\n", __func__);
 }
 
-static struct uart_ops max3100_ops = {
+static const struct uart_ops max3100_ops = {
        .tx_empty       = max3100_tx_empty,
        .set_mctrl      = max3100_set_mctrl,
        .get_mctrl      = max3100_get_mctrl,
index a44290e9b5a8b0eff5304321e4b77affc93ae477..e72ea61c70db150a586cba83a810efc33b1627aa 100644 (file)
@@ -775,7 +775,7 @@ static int men_z135_verify_port(struct uart_port *port,
        return -EINVAL;
 }
 
-static struct uart_ops men_z135_ops = {
+static const struct uart_ops men_z135_ops = {
        .tx_empty = men_z135_tx_empty,
        .set_mctrl = men_z135_set_mctrl,
        .get_mctrl = men_z135_get_mctrl,
index eb54e5c77ead0bc637a1a03d1fbd447628e0c916..2f04ec2b5691aef1d74d8b09b3f50f0feaffeb21 100644 (file)
@@ -1317,7 +1317,7 @@ static void mxs_auart_break_ctl(struct uart_port *u, int ctl)
                mxs_clr(AUART_LINECTRL_BRK, s, REG_LINECTRL);
 }
 
-static struct uart_ops mxs_auart_ops = {
+static const struct uart_ops mxs_auart_ops = {
        .tx_empty       = mxs_auart_tx_empty,
        .start_tx       = mxs_auart_start_tx,
        .stop_tx        = mxs_auart_stop_tx,
index ea4ffc2ebb2fe9366da26d58b960b0c81e46553c..b5874d1e26b61f54df2197200168963d4c3807df 100644 (file)
@@ -1603,7 +1603,7 @@ static void pch_uart_put_poll_char(struct uart_port *port,
 }
 #endif /* CONFIG_CONSOLE_POLL */
 
-static struct uart_ops pch_uart_ops = {
+static const struct uart_ops pch_uart_ops = {
        .tx_empty = pch_uart_tx_empty,
        .set_mctrl = pch_uart_set_mctrl,
        .get_mctrl = pch_uart_get_mctrl,
index ae2095a66708e0b06bf05bfe38d4a0901b158d3d..f44615fa474de233748b4f72133b8bf3fc272bf5 100644 (file)
@@ -1577,7 +1577,7 @@ static void s3c24xx_serial_resetport(struct uart_port *port,
 }
 
 
-#ifdef CONFIG_CPU_FREQ
+#ifdef CONFIG_ARM_S3C24XX_CPUFREQ
 
 static int s3c24xx_serial_cpufreq_transition(struct notifier_block *nb,
                                             unsigned long val, void *data)
index 2ae4fcee181458ce008c499b266e1e7ecd3d614f..a04acef1cb20f0f80cf18d08be3a6fbba409b946 100644 (file)
@@ -102,7 +102,7 @@ struct s3c24xx_uart_port {
 
        struct s3c24xx_uart_dma         *dma;
 
-#ifdef CONFIG_CPU_FREQ
+#ifdef CONFIG_ARM_S3C24XX_CPUFREQ
        struct notifier_block           freq_transition;
 #endif
 };
index f36e6df2fa90b7b7c2995cf88f00f7ccd34e7a80..a9d94f7cf683d54ecdb6b5e7b4e7c1a8cfa3f241 100644 (file)
@@ -1205,6 +1205,10 @@ static int sc16is7xx_probe(struct device *dev,
        }
 #endif
 
+       /* reset device, purging any pending irq / data */
+       regmap_write(s->regmap, SC16IS7XX_IOCONTROL_REG << SC16IS7XX_REG_SHIFT,
+                       SC16IS7XX_IOCONTROL_SRESET_BIT);
+
        for (i = 0; i < devtype->nr_uart; ++i) {
                s->p[i].line            = i;
                /* Initialize port data */
@@ -1234,6 +1238,22 @@ static int sc16is7xx_probe(struct device *dev,
                init_kthread_work(&s->p[i].reg_work, sc16is7xx_reg_proc);
                /* Register port */
                uart_add_one_port(&sc16is7xx_uart, &s->p[i].port);
+
+               /* Enable EFR */
+               sc16is7xx_port_write(&s->p[i].port, SC16IS7XX_LCR_REG,
+                                    SC16IS7XX_LCR_CONF_MODE_B);
+
+               regcache_cache_bypass(s->regmap, true);
+
+               /* Enable write access to enhanced features */
+               sc16is7xx_port_write(&s->p[i].port, SC16IS7XX_EFR_REG,
+                                    SC16IS7XX_EFR_ENABLE_BIT);
+
+               regcache_cache_bypass(s->regmap, false);
+
+               /* Restore access to general registers */
+               sc16is7xx_port_write(&s->p[i].port, SC16IS7XX_LCR_REG, 0x00);
+
                /* Go to suspend mode */
                sc16is7xx_power(&s->p[i].port, 0);
        }
index 9fc15335c8c59b70c93e8e6a1026b32da59359e5..240d3e7a548c66ce7a1897e35a1ea8d6d14a7243 100644 (file)
@@ -235,18 +235,9 @@ static int uart_startup(struct tty_struct *tty, struct uart_state *state,
        if (tty_port_initialized(port))
                return 0;
 
-       /*
-        * Set the TTY IO error marker - we will only clear this
-        * once we have successfully opened the port.
-        */
-       set_bit(TTY_IO_ERROR, &tty->flags);
-
        retval = uart_port_startup(tty, state, init_hw);
-       if (!retval) {
-               tty_port_set_initialized(port, 1);
-               clear_bit(TTY_IO_ERROR, &tty->flags);
-       } else if (retval > 0)
-               retval = 0;
+       if (retval)
+               set_bit(TTY_IO_ERROR, &tty->flags);
 
        return retval;
 }
@@ -972,8 +963,11 @@ static int uart_set_info(struct tty_struct *tty, struct tty_port *port,
                        }
                        uart_change_speed(tty, state, NULL);
                }
-       } else
+       } else {
                retval = uart_startup(tty, state, 1);
+               if (retval > 0)
+                       retval = 0;
+       }
  exit:
        return retval;
 }
@@ -1139,6 +1133,8 @@ static int uart_do_autoconfig(struct tty_struct *tty,struct uart_state *state)
                uport->ops->config_port(uport, flags);
 
                ret = uart_startup(tty, state, 1);
+               if (ret > 0)
+                       ret = 0;
        }
 out:
        mutex_unlock(&port->mutex);
@@ -1465,7 +1461,6 @@ static void uart_close(struct tty_struct *tty, struct file *filp)
 {
        struct uart_state *state = tty->driver_data;
        struct tty_port *port;
-       struct uart_port *uport;
 
        if (!state) {
                struct uart_driver *drv = tty->driver->driver_state;
@@ -1481,56 +1476,36 @@ static void uart_close(struct tty_struct *tty, struct file *filp)
        port = &state->port;
        pr_debug("uart_close(%d) called\n", tty->index);
 
-       if (tty_port_close_start(port, tty, filp) == 0)
-               return;
+       tty_port_close(tty->port, tty, filp);
+}
 
-       mutex_lock(&port->mutex);
-       uport = uart_port_check(state);
+static void uart_tty_port_shutdown(struct tty_port *port)
+{
+       struct uart_state *state = container_of(port, struct uart_state, port);
+       struct uart_port *uport = uart_port_check(state);
 
+       spin_lock_irq(&uport->lock);
        /*
         * At this point, we stop accepting input.  To do this, we
         * disable the receive line status interrupts.
         */
-       if (tty_port_initialized(port) &&
-           !WARN(!uport, "detached port still initialized!\n")) {
-               spin_lock_irq(&uport->lock);
-               uport->ops->stop_rx(uport);
-               spin_unlock_irq(&uport->lock);
-               /*
-                * Before we drop DTR, make sure the UART transmitter
-                * has completely drained; this is especially
-                * important if there is a transmit FIFO!
-                */
-               uart_wait_until_sent(tty, uport->timeout);
-       }
+       WARN(!uport, "detached port still initialized!\n");
 
-       uart_shutdown(tty, state);
-       tty_port_tty_set(port, NULL);
+       uport->ops->stop_rx(uport);
 
-       spin_lock_irq(&port->lock);
+       spin_unlock_irq(&uport->lock);
 
-       if (port->blocked_open) {
-               spin_unlock_irq(&port->lock);
-               if (port->close_delay)
-                       msleep_interruptible(jiffies_to_msecs(port->close_delay));
-               spin_lock_irq(&port->lock);
-       } else if (uport && !uart_console(uport)) {
-               spin_unlock_irq(&port->lock);
-               uart_change_pm(state, UART_PM_STATE_OFF);
-               spin_lock_irq(&port->lock);
-       }
-       spin_unlock_irq(&port->lock);
-       tty_port_set_active(port, 0);
+       uart_port_shutdown(port);
 
        /*
-        * Wake up anyone trying to open this port.
+        * It's possible for shutdown to be called after suspend if we get
+        * a DCD drop (hangup) at just the right time.  Clear suspended bit so
+        * we don't try to resume a port that has been shutdown.
         */
-       wake_up_interruptible(&port->open_wait);
+       tty_port_set_suspended(port, 0);
 
-       mutex_unlock(&port->mutex);
+       uart_change_pm(state, UART_PM_STATE_OFF);
 
-       tty_ldisc_flush(tty);
-       tty->closing = 0;
 }
 
 static void uart_wait_until_sent(struct tty_struct *tty, int timeout)
@@ -1711,52 +1686,31 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
        struct uart_driver *drv = tty->driver->driver_state;
        int retval, line = tty->index;
        struct uart_state *state = drv->state + line;
-       struct tty_port *port = &state->port;
-       struct uart_port *uport;
 
-       pr_debug("uart_open(%d) called\n", line);
+       tty->driver_data = state;
 
-       spin_lock_irq(&port->lock);
-       ++port->count;
-       spin_unlock_irq(&port->lock);
+       retval = tty_port_open(&state->port, tty, filp);
+       if (retval > 0)
+               retval = 0;
 
-       /*
-        * We take the semaphore here to guarantee that we won't be re-entered
-        * while allocating the state structure, or while we request any IRQs
-        * that the driver may need.  This also has the nice side-effect that
-        * it delays the action of uart_hangup, so we can guarantee that
-        * state->port.tty will always contain something reasonable.
-        */
-       if (mutex_lock_interruptible(&port->mutex)) {
-               retval = -ERESTARTSYS;
-               goto end;
-       }
+       return retval;
+}
+
+static int uart_port_activate(struct tty_port *port, struct tty_struct *tty)
+{
+       struct uart_state *state = container_of(port, struct uart_state, port);
+       struct uart_port *uport;
 
        uport = uart_port_check(state);
-       if (!uport || uport->flags & UPF_DEAD) {
-               retval = -ENXIO;
-               goto err_unlock;
-       }
+       if (!uport || uport->flags & UPF_DEAD)
+               return -ENXIO;
 
-       tty->driver_data = state;
-       uport->state = state;
        port->low_latency = (uport->flags & UPF_LOW_LATENCY) ? 1 : 0;
-       tty_port_tty_set(port, tty);
 
        /*
         * Start up the serial port.
         */
-       retval = uart_startup(tty, state, 0);
-
-       /*
-        * If we succeeded, wait until the port is ready.
-        */
-err_unlock:
-       mutex_unlock(&port->mutex);
-       if (retval == 0)
-               retval = tty_port_block_til_ready(port, tty, filp);
-end:
-       return retval;
+       return uart_startup(tty, state, 0);
 }
 
 static const char *uart_type(struct uart_port *port)
@@ -1938,11 +1892,14 @@ uart_get_console(struct uart_port *ports, int nr, struct console *co)
  *        console=<name>,0x<addr>,<options>
  *     is also accepted; the returned @iotype will be UPIO_MEM.
  *
- *     Returns 0 on success or -EINVAL on failure
+ *     Returns 0 on success, -EINVAL or -ERANGE on failure
  */
-int uart_parse_earlycon(char *p, unsigned char *iotype, unsigned long *addr,
+int uart_parse_earlycon(char *p, unsigned char *iotype, resource_size_t *addr,
                        char **options)
 {
+       int ret;
+       unsigned long long tmp;
+
        if (strncmp(p, "mmio,", 5) == 0) {
                *iotype = UPIO_MEM;
                p += 5;
@@ -1968,7 +1925,10 @@ int uart_parse_earlycon(char *p, unsigned char *iotype, unsigned long *addr,
                return -EINVAL;
        }
 
-       *addr = simple_strtoul(p, NULL, 0);
+       ret = kstrtoull(p, 0, &tmp);
+       if (ret)
+               return ret;
+       *addr = tmp;
        p = strchr(p, ',');
        if (p)
                p++;
@@ -2470,6 +2430,8 @@ static const struct tty_operations uart_ops = {
 static const struct tty_port_operations uart_port_ops = {
        .carrier_raised = uart_carrier_raised,
        .dtr_rts        = uart_dtr_rts,
+       .activate       = uart_port_activate,
+       .shutdown       = uart_tty_port_shutdown,
 };
 
 /**
@@ -2786,6 +2748,8 @@ int uart_add_one_port(struct uart_driver *drv, struct uart_port *uport)
        uport->cons = drv->cons;
        uport->minor = drv->tty_driver->minor_start + uport->line;
 
+       port->console = uart_console(uport);
+
        /*
         * If this port is a console, then the spinlock is already
         * initialised.
index d86eee38aae6eba5953f0d7e4e5b2021bc6ee9f8..4b26252c288597a569d4740bc490f56e499bfcfa 100644 (file)
@@ -2533,7 +2533,7 @@ static int sci_verify_port(struct uart_port *port, struct serial_struct *ser)
        return 0;
 }
 
-static struct uart_ops sci_uart_ops = {
+static const struct uart_ops sci_uart_ops = {
        .tx_empty       = sci_tx_empty,
        .set_mctrl      = sci_set_mctrl,
        .get_mctrl      = sci_get_mctrl,
index 2d78cb3627aef9da5e0593d0da38810fc09977c5..379e5bd37df947013b71440333bc0d268936b5aa 100644 (file)
@@ -639,7 +639,7 @@ static void asc_put_poll_char(struct uart_port *port, unsigned char c)
 
 /*---------------------------------------------------------------------*/
 
-static struct uart_ops asc_uart_ops = {
+static const struct uart_ops asc_uart_ops = {
        .tx_empty       = asc_tx_empty,
        .set_mctrl      = asc_set_mctrl,
        .get_mctrl      = asc_get_mctrl,
index 512c162634a37d382fb78b269ec419e9fea52cf7..5da7fe40e391afae83ddba0ccdab44bc30909e32 100644 (file)
@@ -394,7 +394,7 @@ static int timbuart_verify_port(struct uart_port *port,
        return -EINVAL;
 }
 
-static struct uart_ops timbuart_ops = {
+static const struct uart_ops timbuart_ops = {
        .tx_empty = timbuart_tx_empty,
        .set_mctrl = timbuart_set_mctrl,
        .get_mctrl = timbuart_get_mctrl,
index 05089b6c2f3047942af17b9b5a4d5bc10d56028a..817bb0d3f326ed982631c135ddd5f7a4b170b7a5 100644 (file)
@@ -387,7 +387,7 @@ static void ulite_put_poll_char(struct uart_port *port, unsigned char ch)
 }
 #endif
 
-static struct uart_ops ulite_ops = {
+static const struct uart_ops ulite_ops = {
        .tx_empty       = ulite_tx_empty,
        .set_mctrl      = ulite_set_mctrl,
        .get_mctrl      = ulite_get_mctrl,
index 23cfc5e16b45b5200f9c29e5f12b6da3c73e4e62..6b85adce0ac9d13b4d2dece11a5e694db7899159 100644 (file)
@@ -118,7 +118,7 @@ struct vt8500_port {
  * have been allocated as we can't use pdev->id in
  * devicetree
  */
-static unsigned long vt8500_ports_in_use;
+static DECLARE_BITMAP(vt8500_ports_in_use, VT8500_MAX_PORTS);
 
 static inline void vt8500_write(struct uart_port *port, unsigned int val,
                             unsigned int off)
@@ -663,15 +663,15 @@ static int vt8500_serial_probe(struct platform_device *pdev)
 
        if (port < 0) {
                /* calculate the port id */
-               port = find_first_zero_bit(&vt8500_ports_in_use,
-                                       sizeof(vt8500_ports_in_use));
+               port = find_first_zero_bit(vt8500_ports_in_use,
+                                          VT8500_MAX_PORTS);
        }
 
        if (port >= VT8500_MAX_PORTS)
                return -ENODEV;
 
        /* reserve the port id */
-       if (test_and_set_bit(port, &vt8500_ports_in_use)) {
+       if (test_and_set_bit(port, vt8500_ports_in_use)) {
                /* port already in use - shouldn't really happen */
                return -EBUSY;
        }
index 9ca1a4d1b66a1e02186a438af498a4ac2ec5ea29..11a2b36e14bbb3a4688d06456c88d813c4f9b005 100644 (file)
@@ -993,7 +993,7 @@ static void cdns_uart_pm(struct uart_port *port, unsigned int state,
        }
 }
 
-static struct uart_ops cdns_uart_ops = {
+static const struct uart_ops cdns_uart_ops = {
        .set_mctrl      = cdns_uart_set_mctrl,
        .get_mctrl      = cdns_uart_get_mctrl,
        .start_tx       = cdns_uart_start_tx,
index 3d8dcdd1aeae902ad2f587e2f2f875a77ef985f7..d143c13bed26db54824255111343f9a3d45781eb 100644 (file)
@@ -53,8 +53,14 @@ enum amba_vendor {
        AMBA_VENDOR_ST = 0x80,
        AMBA_VENDOR_QCOM = 0x51,
        AMBA_VENDOR_LSI = 0xb6,
+       AMBA_VENDOR_LINUX = 0xfe,       /* This value is not official */
 };
 
+/* This is used to generate pseudo-ID for AMBA device */
+#define AMBA_LINUX_ID(conf, rev, part) \
+       (((conf) & 0xff) << 24 | ((rev) & 0xf) << 20 | \
+       AMBA_VENDOR_LINUX << 12 | ((part) & 0xfff))
+
 extern struct bus_type amba_bustype;
 
 #define to_amba_device(d)      container_of(d, struct amba_device, dev)
index d76a19ba2cffa68f1a2a0b0c830b8e562ab6eb13..ad0965e21a5e7610e1778d36eb3ee9a66739c44e 100644 (file)
 #define UART01x_FR_CTS                 0x001
 #define UART01x_FR_TMSK                (UART01x_FR_TXFF + UART01x_FR_BUSY)
 
+/*
+ * Some bits of Flag Register on ZTE device have different position from
+ * standard ones.
+ */
+#define ZX_UART01x_FR_BUSY     0x100
+#define ZX_UART01x_FR_DSR      0x008
+#define ZX_UART01x_FR_CTS      0x002
+#define ZX_UART011_FR_RI       0x001
+
 #define UART011_CR_CTSEN       0x8000  /* CTS hardware flow control */
 #define UART011_CR_RTSEN       0x4000  /* RTS hardware flow control */
 #define UART011_CR_OUT2                0x2000  /* OUT2 */
index 5a4d664af87a7a8034943827ad806b9043559c52..f8e452aa48d7769b1d4dd7646f4947ce2a821136 100644 (file)
 
 #define ATMEL_US_BRGR          0x20    /* Baud Rate Generator Register */
 #define        ATMEL_US_CD             GENMASK(15, 0)  /* Clock Divider */
+#define ATMEL_US_FP_OFFSET     16      /* Fractional Part */
 
 #define ATMEL_US_RTOR          0x24    /* Receiver Time-out Register for USART */
 #define ATMEL_UA_RTOR          0x28    /* Receiver Time-out Register for UART */
index f2e538aaddadc55d43c5463375c4de36ab37bc83..ccfd0c3777df20d2bd9c6cd1518673643369c1ad 100644 (file)
@@ -40,8 +40,13 @@ struct dw_dma_chip {
 };
 
 /* Export to the platform drivers */
+#if IS_ENABLED(CONFIG_DW_DMAC_CORE)
 int dw_dma_probe(struct dw_dma_chip *chip);
 int dw_dma_remove(struct dw_dma_chip *chip);
+#else
+static inline int dw_dma_probe(struct dw_dma_chip *chip) { return -ENODEV; }
+static inline int dw_dma_remove(struct dw_dma_chip *chip) { return 0; }
+#endif /* CONFIG_DW_DMAC_CORE */
 
 /* DMA API extensions */
 struct dw_desc;
index aaff68efba5dab20f33dfcbb102469e4f564cc33..197eec63e5019ba13fc4821389373a5f74f16802 100644 (file)
@@ -41,8 +41,7 @@ struct hsu_dma_chip {
 /* Export to the internal users */
 int hsu_dma_get_status(struct hsu_dma_chip *chip, unsigned short nr,
                       u32 *status);
-irqreturn_t hsu_dma_do_irq(struct hsu_dma_chip *chip, unsigned short nr,
-                          u32 status);
+int hsu_dma_do_irq(struct hsu_dma_chip *chip, unsigned short nr, u32 status);
 
 /* Export to the platform drivers */
 int hsu_dma_probe(struct hsu_dma_chip *chip);
@@ -53,10 +52,10 @@ static inline int hsu_dma_get_status(struct hsu_dma_chip *chip,
 {
        return 0;
 }
-static inline irqreturn_t hsu_dma_do_irq(struct hsu_dma_chip *chip,
-                                        unsigned short nr, u32 status)
+static inline int hsu_dma_do_irq(struct hsu_dma_chip *chip, unsigned short nr,
+                                u32 status)
 {
-       return IRQ_NONE;
+       return 0;
 }
 static inline int hsu_dma_probe(struct hsu_dma_chip *chip) { return -ENODEV; }
 static inline int hsu_dma_remove(struct hsu_dma_chip *chip) { return 0; }
index d15d8ba8cc240c7b846936692b604c0e2488f177..5f0e11e7354cdbb28e09668ba75686fdcc524e9e 100644 (file)
@@ -23,6 +23,7 @@
  * @dst_id:    dst request line
  * @m_master:  memory master for transfers on allocated channel
  * @p_master:  peripheral master for transfers on allocated channel
+ * @hs_polarity:set active low polarity of handshake interface
  */
 struct dw_dma_slave {
        struct device           *dma_dev;
@@ -30,6 +31,7 @@ struct dw_dma_slave {
        u8                      dst_id;
        u8                      m_master;
        u8                      p_master;
+       bool                    hs_polarity;
 };
 
 /**
@@ -38,6 +40,7 @@ struct dw_dma_slave {
  * @is_private: The device channels should be marked as private and not for
  *     by the general purpose DMA channel allocator.
  * @is_memcpy: The device channels do support memory-to-memory transfers.
+ * @is_nollp: The device channels does not support multi block transfers.
  * @chan_allocation_order: Allocate channels starting from 0 or 7
  * @chan_priority: Set channel priority increasing from 0 to 7 or 7 to 0.
  * @block_size: Maximum block size supported by the controller
@@ -49,6 +52,7 @@ struct dw_dma_platform_data {
        unsigned int    nr_channels;
        bool            is_private;
        bool            is_memcpy;
+       bool            is_nollp;
 #define CHAN_ALLOCATION_ASCENDING      0       /* zero to seven */
 #define CHAN_ALLOCATION_DESCENDING     1       /* seven to zero */
        unsigned char   chan_allocation_order;
index 2f44e20136545162d15ee9a39c2eae38352580d1..cdba6f144f72bda13b3a0b6e8e97ac5da939b863 100644 (file)
@@ -374,7 +374,7 @@ extern int of_setup_earlycon(const struct earlycon_id *match,
 
 struct uart_port *uart_get_console(struct uart_port *ports, int nr,
                                   struct console *c);
-int uart_parse_earlycon(char *p, unsigned char *iotype, unsigned long *addr,
+int uart_parse_earlycon(char *p, unsigned char *iotype, resource_size_t *addr,
                        char **options);
 void uart_parse_options(char *options, int *baud, int *parity, int *bits,
                        int *flow);
This page took 0.084069 seconds and 5 git commands to generate.